Changes to AgileBill

This commit is contained in:
Deon George
2009-08-03 14:10:16 +10:00
parent 0a22cfe22c
commit 27aee719b0
1051 changed files with 219109 additions and 117219 deletions

View File

@@ -1,99 +1,74 @@
<?php
/**
* AgileBill - Open Billing Software
*
* This body of work is free software; you can redistribute it and/or
* modify it under the terms of the Open AgileBill License
* License as published at http://www.agileco.com/agilebill/license1-4.txt
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* Originally authored by Tony Landis, AgileBill LLC
*
* Recent modifications by Deon George
*
* @author Deon George <deonATleenooksDOTnet>
* @copyright 2009 Deon George
* @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
* @author Tony Landis <tony@agileco.com>
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @version 1.4.93
* @subpackage Module:Task
*/
class task
{
# Open the constructor for this mod
function task()
{
# name of this module:
$this->module = "task";
# location of the construct XML file:
$this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
# open the construct file for parsing
$C_xml = new CORE_xml;
$construct = $C_xml->xml_to_array($this->xml_construct);
$this->method = $construct["construct"]["method"];
$this->trigger = $construct["construct"]["trigger"];
$this->field = $construct["construct"]["field"];
$this->table = $construct["construct"]["table"];
$this->module = $construct["construct"]["module"];
$this->cache = $construct["construct"]["cache"];
$this->order_by = $construct["construct"]["order_by"];
$this->limit = $construct["construct"]["limit"];
}
##############################
## RUN ALL DUE TASKS ##
##############################
function run_all()
{
# ensure that tasks complete and dont hang on
# running=1
set_time_limit(2 * 60 * 60);
/**
* The main AgileBill Task Class
*
* @package AgileBill
* @subpackage Module:Task
*/
class task extends OSB_module {
/**
* Run all scheduled tasks
*/
public function run_all() {
# Ensure that tasks complete and dont hang on running=1
set_time_limit(2*60*60);
# Loop through the tasks:
global $VAR;
$db = &DB();
$sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'task WHERE
site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
( running = 0 OR running IS NULL )';
$result = $db->Execute($sql);
if($result->RecordCount() > 0)
{
include_once(PATH_INCLUDES . 'cron/cron.inc.php');
$db = &DB();
$result = $db->Execute(sqlSelect($db,'task','*','(running=0 OR running IS NULL) AND status=1'));
if ($result && $result->RecordCount() > 0) {
include_once(PATH_INCLUDES.'cron/cron.inc.php');
$cron = new cron;
while(!$result->EOF)
{
while (! $result->EOF) {
$_r = false;
$_s = (int) $result->fields['date_start'];
$_e = (int) $result->fields['date_expire'];
$_l = (int) $result->fields['date_last'];
$_c = $result->fields['int_min'] . " ";
$_c .= $result->fields['int_hour'] . " ";
$_c .= $result->fields['int_month_day'] . " ";
$_c .= $result->fields['int_month'] . " ";
$_c .= $result->fields['int_week_day'];
$_l = (int) $result->fields['date_run'];
$_c = sprintf('%s %s %s %s %s',
$result->fields['int_min'],
$result->fields['int_hour'],
$result->fields['int_month_day'],
$result->fields['int_month'],
$result->fields['int_week_day']);
$_n = (int) time();
if(!$_l > 0) $_l = $_n-86400*365;
if (! $_l > 0)
$_l = $_n-86400*365;
# Verify it has not expired:
if ($_s <= $_n || $_s == "" || $_s == "0")
{
if ($_s <= $_n || $_s == '' || $_s == '0') {
# Verify it is past the start date:
if ($_e >= $_n || $_e == "" || $_e == "0")
{
if ($_e >= $_n || $_e == '' || $_e == '0') {
# Verify that it is time to run:
if($cron->due($_l, $_n, $_c))
{
if ($cron->due($_l,$_n,$_c)) {
# Run the task:
$this->id = $result->fields['id'];
$this->run($VAR, $this);
$this->run($VAR);
}
}
}
@@ -102,206 +77,105 @@ class task
}
}
/**
* Run a task
*
* @uses task_log
*/
public function run($VAR) {
global $VAR,$C_auth,$_ENV,$_SERVER,$_COOKIE,$C_list;
##############################
## RUN ##
##############################
function run($VAR)
{
# check auth: (windows)
global $VAR, $C_auth, $_ENV, $_SERVER, $_COOKIE;
$noauth = false;
$debug_out = false;
if (!empty($_ENV['S']) ||
@$_ENV['SESSIONNAME'] == "Console" ||
@$_SERVER['SESSIONNAME'] == "Console" ||
@$_SERVER['CLIENTNAME'] == "Console" ||
@empty($_COOKIE))
{
if (isset($_ENV['S']) ||
(isset($_ENV['SESSIONNAME']) && $_ENV['SESSIONNAME'] == 'Console') ||
(isset($_SERVER['SESSIONNAME']) && $_SERVER['SESSIONNAME'] == 'Console') ||
(isset($_SERVER['CLIENTNAME']) && $_SERVER['CLIENTNAME'] == 'Console') ||
empty($_COOKIE)) {
$debug_out = true;
$noauth = true;
} elseif($C_auth->auth_method_by_name('task','run')) {
$noauth = true;
} else {
$noauth = false;
}
if (isset($this->id))
$id = $this->id;
elseif ( isset ($VAR['id']))
$id = $VAR['id'];
else return;
$id = $this->id;
elseif (isset($VAR['id']))
$id = $VAR['id'];
else
return;
###############################
# Get task details
$db = &DB();
$sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'task WHERE
site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
id = ' . $db->qstr($id);
$result = $db->Execute($sql);
if($result->RecordCount() == 0) return;
$db = &DB();
$result = $db->Execute(sqlSelect($db,'task','*',array('id'=>$id)));
if (! $result || $result->RecordCount() == 0)
return;
$type = $result->fields['type'];
$cmd = $result->fields['command'];
$log = $result->fields['log'];
#################################
# Flip Run Toggle
$sql = 'UPDATE ' . AGILE_DB_PREFIX . 'task SET
running = 1 WHERE
site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
id = ' . $db->qstr("$id");
$db->Execute($sql);
# Record task running
$db->Execute(sqlUpdate($db,'task',array('running'=>1),array('id'=>$id)));
###############################
# Run task
if ( $type == 0 )
{
### Internal function:
global $C_method;
$arr = explode(":",$cmd);
switch ($type) {
case 0:
# Internal function:
global $C_method;
$arr = explode(":",$cmd);
if($noauth) {
# run from console, no auth req
$C_method->exe_noauth($arr[0],$arr[1]);
#if($debug_out)
# echo $cmd."<BR>";
}
else
{
# run from web, auth required
$C_method->exe($arr[0],$arr[1]);
}
if ($noauth) {
# run from console, no auth req
$C_method->exe_noauth($arr[0],$arr[1]);
} else {
# run from web, auth required
$C_method->exe($arr[0],$arr[1]);
}
if($C_method->result)
if ($C_method->result)
$result = 1;
else
$result = 0;
@$message = $C_method->error;
break;
case 1:
$message = `$cmd`;
$result = 1;
else
$result = 0;
@$message = $C_method->error;
}
elseif ( $type == 1)
{
### System command
$message = `$cmd`;
$result = 1;
break;
default:
printf('ERROR: Unknown task type [%s]',$type);
}
###############################
# Update last run date & flip run toggle
$sql = 'UPDATE ' . AGILE_DB_PREFIX . 'task SET
running = 0,
date_last = ' . $db->qstr(time()) . '
WHERE
site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
id = ' . $db->qstr("$id");
$db->Execute($sql);
$db->Execute(sqlUpdate($db,'task',array('running'=>0,'date_run'=>time()),array('id'=>$id)));
###############################
# Store task log if required
/*
if($log == '1')
{
$idx = $db->GenID(AGILE_DB_PREFIX . "" . 'task_log_id');
$sql = 'INSERT INTO ' . AGILE_DB_PREFIX . 'task_log SET
site_id = ' . $db->qstr(DEFAULT_SITE) . ',
id = ' . $db->qstr($idx) . ',
task_id = ' . $db->qstr($id) . ',
result = ' . $db->qstr(@$result) . ',
message = ' . $db->qstr(@$message) . ',
date_orig= ' . $db->qstr(time());
$result = $db->Execute($sql);
if ($log && $C_list->is_installed('task_log')) {
include_once(PATH_MODULES.'task_log/task_log.inc.php');
$tl = new task_log;
$VAR['task_log_task_id'] = $id;
$VAR['task_log_result'] = $result;
$VAR['task_log_message'] = $message;
if (! isset($VAR['_page_current']))
$VAR['_page_current'] = '';
$result = $tl->add($VAR);
}
*/
###############################
# If admin, print success message
if ( DEFAULT_ADMIN_THEME == SESS_THEME )
{
global $C_translate, $C_debug;
#$C_debug->alert ( $C_translate->translate('true','','') );
if (DEFAULT_ADMIN_THEME == SESS_THEME) {
global $C_translate,$C_debug;
$C_debug->alert($C_translate->translate('true','',''));
}
}
##############################
## ADD ##
##############################
function add($VAR)
{
$type = "add";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->add($VAR, $this, $type);
}
##############################
## VIEW ##
##############################
function view($VAR)
{
$type = "view";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->view($VAR, $this, $type);
}
##############################
## UPDATE ##
##############################
function update($VAR)
{
$type = "update";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->update($VAR, $this, $type);
}
##############################
## DELETE ##
##############################
function delete($VAR)
{
$db = new CORE_database;
$db->mass_delete($VAR, $this, "");
}
##############################
## SEARCH FORM ##
##############################
function search_form($VAR)
{
$type = "search";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->search_form($VAR, $this, $type);
}
##############################
## SEARCH ##
##############################
function search($VAR)
{
$type = "search";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->search($VAR, $this, $type);
}
##############################
## SEARCH SHOW ##
##############################
function search_show($VAR)
{
$type = "search";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->search_show($VAR, $this, $type);
}
}
?>
?>

View File

@@ -1,108 +1,185 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<construct>
<!-- define the module name -->
<module>task</module>
<!-- define the module table name -->
<table>task</table>
<!-- define the module dependancy(s) -->
<dependancy/>
<!-- define the DB cache in seconds -->
<cache>0</cache>
<!-- define the default order_by field for SQL queries -->
<order_by>name</order_by>
<!-- define the methods -->
<limit>25</limit>
<!-- define database indexes -->
<index>
<start>date_start</start>
<expire>date_expire</expire>
</index>
<!-- define the fields -->
<field>
<id>
<type>I4</type>
<unique>1</unique>
<index>1</index>
</id>
<site_id>
<type>I4</type>
<index>1</index>
</site_id>
<date_start>
<type>I8</type>
<convert>date-time</convert>
</date_start>
<date_expire>
<type>I8</type>
<convert>date-time</convert>
</date_expire>
<date_last>
<type>I8</type>
<convert>date</convert>
</date_last>
<name>
<type>C(32)</type>
<min_len>3</min_len>
<max_len>32</max_len>
<validate>any</validate>
</name>
<description>
<type>C(255)</type>
</description>
<log>
<type>L</type>
</log>
<type>
<type>I4</type>
</type>
<command>
<type>C(128)</type>
<min_len>2</min_len>
<max_len>128</max_len>
<validate>any</validate>
</command>
<int_min>
<type>C(32)</type>
<min_len>1</min_len>
<max_len>32</max_len>
<validate>any</validate>
</int_min>
<int_hour>
<type>C(32)</type>
<min_len>1</min_len>
<max_len>32</max_len>
<validate>any</validate>
</int_hour>
<int_month>
<type>C(32)</type>
<min_len>1</min_len>
<max_len>32</max_len>
<validate>any</validate>
</int_month>
<int_month_day>
<type>C(32)</type>
<min_len>1</min_len>
<max_len>32</max_len>
<validate>any</validate>
</int_month_day>
<int_week_day>
<type>C(32)</type>
<min_len>1</min_len>
<max_len>32</max_len>
<validate>any</validate>
</int_week_day>
<running>
<type>L</type>
</running>
</field>
<!-- define all the methods for this class, and the fields they have access to, if applicable. -->
<method>
<add>id,site_id,date_start,date_expire,date_last,name,description,log,type,command,int_min,int_hour,int_month_day,int_month,int_week_day,running</add>
<update>id,site_id,date_start,date_expire,date_last,name,description,log,type,command,int_min,int_hour,int_month_day,int_month,int_week_day,running</update>
<delete>id,site_id,date_start,date_expire,date_last,name,description,log,type,command,int_min,int_hour,int_month_day,int_month,int_week_day,running</delete>
<view>id,site_id,date_start,date_expire,date_last,name,description,log,type,command,int_min,int_hour,int_month_day,int_month,int_week_day,running</view>
<search>id,site_id,date_start,date_expire,date_last,name,description,log,type,command,int_min,int_hour,int_month_day,int_month,int_week_day,running</search>
</method>
<!-- define the method triggers -->
<trigger>0</trigger>
<!-- Module name -->
<module>task</module>
<!-- Module supporting database table -->
<table>task</table>
<!-- Module dependancy(s) (module wont install if these modules are not yet installed) -->
<dependancy></dependancy>
<!-- DB cache in seconds -->
<cache>0</cache>
<!-- Default order_by field for SQL queries -->
<order_by>name</order_by>
<!-- Default SQL limit for SQL queries -->
<limit>25</limit>
<!-- Schema version (used to determine if the schema has change during upgrades) -->
<version>1</version>
<!-- Database indexes -->
<index>
<start>date_start</start>
<expire>date_expire</expire>
</index>
<!-- Database fields -->
<field>
<!-- Record ID -->
<id>
<index>1</index>
<type>I4</type>
<unique>1</unique>
</id>
<!-- Site ID -->
<site_id>
<index>1</index>
<type>I4</type>
</site_id>
<!-- Date record created -->
<date_orig>
<display>Date Created</display>
<type>I8</type>
</date_orig>
<!-- Date record updated -->
<date_last>
<convert>date-now</convert>
<display>Date Updated</display>
<type>I8</type>
</date_last>
<!-- Date last run -->
<date_run>
<convert>date-now</convert>
<display>Date Last Run</display>
<type>I8</type>
</date_run>
<!-- Record active (BOOL)-->
<status>
<display>Active</display>
<type>I4</type>
</status>
<date_start>
<display>Date Start</display>
<type>I8</type>
<convert>date-time</convert>
</date_start>
<date_expire>
<display>Date Expire</display>
<type>I8</type>
<convert>date-time</convert>
</date_expire>
<name>
<display>Name</display>
<type>C(32)</type>
<min_len>3</min_len>
<max_len>32</max_len>
<validate>any</validate>
</name>
<description>
<display>Description</display>
<type>C(255)</type>
</description>
<!-- Log Task: (BOOL) -->
<log>
<display>Log</display>
<type>L</type>
</log>
<!-- Task type: 0=INTERNAL(run method), 1=EXTERNAL(run CMD) -->
<type>
<display>Type</display>
<type>I4</type>
</type>
<command>
<display>Command</display>
<type>C(128)</type>
<min_len>2</min_len>
<max_len>128</max_len>
<validate>any</validate>
</command>
<int_min>
<display>Minute</display>
<type>C(32)</type>
<min_len>1</min_len>
<max_len>32</max_len>
<validate>any</validate>
</int_min>
<int_hour>
<display>Hour</display>
<type>C(32)</type>
<min_len>1</min_len>
<max_len>32</max_len>
<validate>any</validate>
</int_hour>
<int_month>
<display>Month</display>
<type>C(32)</type>
<min_len>1</min_len>
<max_len>32</max_len>
<validate>any</validate>
</int_month>
<int_month_day>
<display>Day</display>
<type>C(32)</type>
<min_len>1</min_len>
<max_len>32</max_len>
<validate>any</validate>
</int_month_day>
<int_week_day>
<display>Week Day</display>
<type>C(32)</type>
<min_len>1</min_len>
<max_len>32</max_len>
<validate>any</validate>
</int_week_day>
<!-- Task is currently running: 1=RUNNING, 0|NULL=NOT RUNNING -->
<running>
<type>L</type>
</running>
</field>
<!-- Methods for this class, and the fields they have access to, if applicable. -->
<method>
<add>date_start,date_expire,date_last,name,description,log,type,command,int_min,int_hour,int_month_day,int_month,int_week_day</add>
<update>id,site_id,status,date_start,date_expire,date_last,name,description,log,type,command,int_min,int_hour,int_month_day,int_month,int_week_day,running</update>
<delete>id,site_id,date_start,date_expire,date_last,name,description,log,type,command,int_min,int_hour,int_month_day,int_month,int_week_day,running</delete>
<view>id,site_id,status,date_start,date_expire,date_last,name,description,log,type,command,int_min,int_hour,int_month_day,int_month,int_week_day,running</view>
<search>id,site_id,status,date_start,date_expire,date_last,name,description,log,type,command,int_min,int_hour,int_month_day,int_month,int_week_day,running</search>
</method>
<!-- Method triggers -->
<trigger></trigger>
<!-- Template page display titles -->
<title>
<add>Add Task</add>
<view>Task</view>
</title>
<!-- Template helpers -->
<tpl>
<search_show>
<checkbox>
<field>id</field>
<type>checkbox</type>
<width>25px</width>
</checkbox>
<name>
<field>name</field>
</name>
<date_last>
<field>date_last</field>
<type>date</type>
</date_last>
<date_run>
<field>date_run</field>
<type>date</type>
</date_run>
<command>
<field>command</field>
</command>
<icon>
<field>status</field>
<type>bool_icon</type>
<width>20px</width>
</icon>
</search_show>
</tpl>
</construct>

View File

@@ -1,36 +1,61 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<install>
<!-- Tree Menu Module Properties -->
<module_properties>
<name>task</name>
<parent>setup</parent>
<notes><![CDATA[This module allows you to automate various tasks]]></notes>
<!-- MODULE Dependancy, this module wont be installed if the dependant modules dont exist -->
<dependancy></dependancy>
<!-- Translated display to use on the tree -->
<display>Task</display>
<!-- Display a module in the menu tree -->
<menu_display>1</menu_display>
<!-- MODULE Name -->
<name>task</name>
<!-- MODULE Notes, these notes show up in the modules table, as a description of the module -->
<notes><![CDATA[This module allows you to automate various tasks]]></notes>
<!-- MODULE Parent, the parent node in the tree -->
<parent>setup</parent>
<!-- MODULE Type (core|base), core modules cannot be deleted, unrecognised types are ignored. -->
<type>base</type>
</module_properties>
<sql_inserts>
<module_method>
<search>
<name>search</name>
</search>
<run>
<name>run</name>
</run>
<view>
<name>view</name>
<page><![CDATA[core:search&module=%%&_escape=1&_next_page_one=view]]></page>
<menu_display>1</menu_display>
</view>
<add>
<name>add</name>
<menu_display>1</menu_display>
</add>
<delete>
<name>delete</name>
</delete>
<update>
<name>update</name>
</update>
<search_show>
<name>search_show</name>
</search_show>
</module_method>
</sql_inserts>
</install>
<!-- Tree Menu & Module Methods to load, they will be assigned the group permissions on install time, as selected by the user. -->
<module_method>
<add>
<display>Add</display>
<menu_display>1</menu_display>
<name>add</name>
<notes><![CDATA[Add records]]></notes>
</add>
<delete>
<name>delete</name>
<notes><![CDATA[Delete records]]></notes>
</delete>
<search>
<display>List</display>
<menu_display>1</menu_display>
<name>search</name>
<notes><![CDATA[List records]]></notes>
<page><![CDATA[core:search&module=%%&_next_page_one=view]]></page>
</search>
<search_form>
<name>search_form</name>
<notes><![CDATA[Search for records]]></notes>
</search_form>
<search_show>
<name>search_show</name>
<notes><![CDATA[Show the results of a search]]></notes>
</search_show>
<update>
<name>update</name>
<notes><![CDATA[Update a record]]></notes>
</update>
<view>
<name>view</name>
<notes><![CDATA[View a record]]></notes>
</view>
<run>
<name>run</name>
<notes><![CDATA[Run a task]]></notes>
</run>
</module_method>
</install>

View File

@@ -131,22 +131,6 @@
<int_month_day>*</int_month_day>
<int_week_day>*</int_week_day>
</task>
<task>
<id>58</id>
<site_id>1</site_id>
<date_start>0</date_start>
<date_expire>0</date_expire>
<date_last>1112256262</date_last>
<name>Ticket Piping</name>
<description>Grabs new e-mails for any of the ticket departments configured for email piping.</description>
<type>0</type>
<command>ticket:piping</command>
<int_min>0-59/5</int_min>
<int_hour>*</int_hour>
<int_month>*</int_month>
<int_month_day>*</int_month_day>
<int_week_day>*</int_week_day>
</task>
<task>
<id>59</id>
<site_id>1</site_id>
@@ -171,16 +155,16 @@
<date_expire>0</date_expire>
<date_last>1132899627</date_last>
<name>Invoice Delivery</name>
<description>Delivers the invoices via email and/or writes the invoices to the export directory.</description>
<description>Delivers the invoices via email.</description>
<type>0</type>
<command>invoice:delivery_task</command>
<command>invoice:task_email_invoices</command>
<int_min>0</int_min>
<int_hour>*</int_hour>
<int_month>*</int_month>
<int_month_day>*</int_month_day>
<int_week_day>*</int_week_day>
<running>0</running>
</task>
</task>
<task>
<id>61</id>
<site_id>1</site_id>
@@ -265,7 +249,7 @@
<int_month_day>*</int_month_day>
<int_week_day>*</int_week_day>
<running>0</running>
</task>
</task>
<task>
<id>66</id>
<site_id>1</site_id>
@@ -282,7 +266,7 @@
<int_month_day>*</int_month_day>
<int_week_day>*</int_week_day>
<running>0</running>
</task>
</task>
<task_id>
<id>67</id>
<site_id>1</site_id>