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,301 +1,319 @@
<?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 Modules:Import
*/
class import
{
# Open the constructor for this mod
function import()
{
# name of this module:
$this->module = "import";
/**
* The main AgileBill Import Class
*
* @package AgileBill
* @subpackage Modules:Import
*/
class import extends OSB_module {
protected $actions = array();
/**
* Test remote database connectivity
*/
protected function test() {
global $C_debug,$VAR;
# location of the construct XML file:
$this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
# Connect to the remote DB
$dbr = &NewADOConnection($this->type);
$dbr->Connect($this->host,$this->user,$this->pass,$this->db);
# open the construct file for parsing
$C_xml = new CORE_xml;
$construct = $C_xml->xml_to_array($this->xml_construct);
if (! empty($dbr->_errorMsg))
$C_debug->alert(sprintf('Failed: %s',$dbr->_errorMsg));
else
$this->pre_test();
$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"];
# Return to main import page
printf("<script type='text/javascript' language=javascript>setTimeout('document.location=\'?_page=import:import&plugin=%s\'',1500);</script>",$VAR['plugin']);
}
### Store import id
function import_transaction($plugin, $action, $ab_table, $ab_id, $remote_table, $remote_id, &$db)
{
# Check that this record has not already been imported:
$sql = "SELECT id FROM ".AGILE_DB_PREFIX."import WHERE
plugin = ".$db->qstr($plugin)." AND
action = ".$db->qstr($action)." AND
ab_table = ".$db->qstr($ab_table)." AND
ab_id = ".$db->qstr($ab_id)." AND
remote_table= ".$db->qstr($remote_table). " AND
remote_id = ".$db->qstr($remote_id)." AND
site_id = ".DEFAULT_SITE;
$rs = $db->Execute($sql);
/**
* Record pre-setup tests
*/
protected function pre_test() {
global $C_debug,$VAR;
# check results
if($rs === false || $rs->RecordCount() > 0) {
$C_debug->alert('Marked Done!');
$db = &DB();
# Insert the import record
$this->import_transaction($this->plugin,$VAR['action'],null,null,null,null,$db);
# Return to main import page
printf("<script type='text/javascript' language=javascript>setTimeout('document.location=\'?_page=import:import&plugin=%s\'',1500);</script>",$VAR['plugin']);
}
# Store import id
protected function import_transaction($plugin,$action,$ab_table,$ab_id,$remote_table,$remote_id,&$db) {
# Check that this record has not already been imported:
$sql = sqlSelect($db,'import','id',
sprintf('plugin = %s AND action = %s AND ab_table = %s AND ab_id = %s AND remote_table = %s AND remote_id = %s',
$db->qstr($plugin),
$db->qstr($action),
$db->qstr($ab_table),
$db->qstr($ab_id),
$db->qstr($remote_table),
$db->qstr($remote_id)
));
$rs = $db->Execute($sql);
# Check results
if ($rs === false || $rs->RecordCount() > 0) {
$db->FailTrans();
return false;
}
# Insert the record
$id = $db->GenID(AGILE_DB_PREFIX.'import_id');
$sql = "INSERT INTO ".AGILE_DB_PREFIX."import SET
id = $id,
date_orig = ".time().",
plugin = ".$db->qstr($plugin).",
action = ".$db->qstr($action).",
ab_table = ".$db->qstr($ab_table).",
ab_id = ".$db->qstr($ab_id).",
remote_table= ".$db->qstr($remote_table). ",
remote_id = ".$db->qstr($remote_id).",
site_id = ".DEFAULT_SITE;
$rs = $db->Execute($sql);
$update = array(
'date_orig'=>time(),
'plugin'=>$plugin,
'action'=>$action,
'ab_table'=>$ab_table,
'ab_id'=>$ab_id,
'remote_table'=>$remote_table,
'remote_id'=>$remote_id);
$db->Execute(sqlInsert($db,'import',$update));
return true;
}
}
### Do an action for a specific plugin:
function do_action ($VAR)
{
# Do an action for a specific plugin:
public function do_action($VAR) {
# Load the plugin
if(!is_file($file = PATH_PLUGINS . 'import/'.@$VAR['plugin'].'.php'))
return false;
if (! is_file($file = sprintf('%simport/%s.php',PATH_PLUGINS,$VAR['plugin'])))
return false;
# New instance
include_once($file);
$import_plugin = new import_plugin;
$import_plugin = new import_plugin;
# Call the required method
call_user_func (array($import_plugin, @$VAR['action']), $VAR, $import_plugin);
# Call the required method
call_user_func(array($import_plugin,$VAR['action']),$VAR,$import_plugin);
}
### Do an action for a specific plugin:
function undo_action ($VAR)
{
# Do an action for a specific plugin:
public function undo_action($VAR) {
$db = &DB();
# Make sure this action is done...
$sql = "SELECT * FROM ".AGILE_DB_PREFIX."import WHERE
plugin = ".$db->qstr($VAR['plugin'])." AND
action = ".$db->qstr($VAR['action'])." AND
site_id = ".DEFAULT_SITE;
$rs = $db->Execute($sql);
if($rs->RecordCount() == 0) {
$rs = $db->Execute(sqlSelect($db,'import','ab_table,ab_id',sprintf('plugin=::%s:: AND action=::%s::',$VAR['plugin'],$VAR['action'])));
if ($rs->RecordCount() == 0) {
echo 'There is nothing to undo!';
return;
}
while(!$rs->EOF)
{
$table = $rs->fields['ab_table'];
$id = $rs->fields['ab_id'];
$q = "DELETE FROM ".AGILE_DB_PREFIX."$table WHERE
id = $id AND
site_id = ".DEFAULT_SITE;
$db->Execute($q);
$rs->MoveNext();
}
# delete the selected action:
$sql = "DELETE FROM ".AGILE_DB_PREFIX."import WHERE
plugin = ".$db->qstr($VAR['plugin'])." AND
action = ".$db->qstr($VAR['action'])." AND
site_id = ".DEFAULT_SITE;
$rs = $db->Execute($sql);
while (! $rs->EOF) {
if (trim($rs->fields['ab_table']) && trim($rs->fields['ab_id']))
$db->Execute(sqlDelete($db,$rs->fields['ab_table'],sprintf('id=%s',$rs->fields['ab_id'])));
$rs->MoveNext();
}
# Delete the selected action
$db->Execute(sqlDelete($db,'import',sprintf('plugin=::%s:: AND action=::%s::',$VAR['plugin'],$VAR['action'])));
}
/**
* View import plugins
*/
public function view($VAR) {
# Load the plugin
if (! is_file($file = sprintf('%simport/%s.php',PATH_PLUGINS,$VAR['plugin'])))
return false;
##############################
## VIEW ##
##############################
function view($VAR)
{
$db = &DB();
if(!is_file($file = PATH_PLUGINS . 'import/'.@$VAR['plugin'].'.php'))
return false;
include_once($file);
$import_plugin = new import_plugin;
# Loop through each action to determine its availibility status
# Loop through each action to determine its availibility status
$actions = $import_plugin->actions;
$done = false;
for($i=0; $i<count($actions); $i++) {
# are the dependencies met?
$depn = $actions[$i]['depn'];
if(is_array($depn)) {
for($ii=0; $ii<count($depn); $ii++) {
if(empty($done["{$depn[$ii]}"])) {
$actions[$i]['status'] = 'pending';
$done = false;
for ($i=0; $i<count($actions); $i++) {
# Are the dependencies met?
$depn = $actions[$i]['depn'];
if (is_array($depn)) {
for ($ii=0; $ii<count($depn); $ii++) {
if (empty($done[$depn[$ii]])) {
$actions[$i]['status'] = 'pending';
break;
}
}
if($actions[$i]['status'] != 'pending')
if ($actions[$i]['status'] != 'pending')
$actions[$i]['status'] = 'ready';
} else {
$actions[$i]['status'] = 'ready';
}
}
# passed dependencies, check if it has been run already or not:
if($actions[$i]['status'] == 'ready') {
$sql = "SELECT id FROM ".AGILE_DB_PREFIX."import WHERE
plugin = ".$db->qstr($import_plugin->name)." AND
action = ".$db->qstr($actions[$i]['name'])." AND
site_id = ".DEFAULT_SITE;
$rs = $db->Execute($sql);
if($rs->RecordCount() > 0) {
# Passed dependencies, check if it has been run already or not:
if ($actions[$i]['status'] == 'ready') {
$rs = $db->Execute(sqlSelect($db,'import','id',sprintf('plugin=::%s:: AND action=::%s::',$import_plugin->name,$actions[$i]['name'])));
if ($rs->RecordCount() > 0) {
$actions[$i]['status'] = 'done';
$actions[$i]['records'] = $rs->RecordCount();
$done["{$actions[$i]['name']}"] = true;
}
}
}
global $smarty;
$smarty->assign('name', $import_plugin->name);
$smarty->assign('instructions', $import_plugin->instructions);
$smarty->assign('import', $actions);
}
##############################
## SEARCH ##
##############################
function search($VAR)
{
### Read the contents of the /plugins/affiliate directory:
$count = 0;
chdir(PATH_PLUGINS . 'import');
$dir = opendir(PATH_PLUGINS . 'import');
while ($file_name = readdir($dir)) {
if($file_name != '..' && $file_name != '.' && !eregi("^_", $file_name) && eregi(".php$", $file_name)) {
$count++;
$actions[$i]['records'] = $rs->RecordCount();
$done[$actions[$i]['name']] = true;
}
}
}
# define the DB vars as a Smarty accessible block
global $smarty;
$smarty->assign('name',$import_plugin->name);
$smarty->assign('instructions',$import_plugin->instructions);
$smarty->assign('import',$actions);
}
/**
* Search for available plugs
*
* @uses CORE_search
*/
public function search($VAR) {
# Read the contents of the directory
$count = 0;
$dir = opendir(PATH_PLUGINS.'import');
while ($file_name = readdir($dir))
if (! in_array($file_name,array('.','..')) && ! preg_match('/^_/',$file_name) && preg_match('/.php$/',$file_name))
$count++;
# Define the DB vars as a Smarty accessible block
global $smarty;
# create the search record:
if($count > 0)
{
if ($count > 0) {
# create the search record
include_once(PATH_CORE . 'search.inc.php');
include_once(PATH_CORE.'search.inc.php');
$search = new CORE_search;
$arr['module'] = $this->module;
$arr['sql'] = '';
$arr['limit'] = '999';
$arr['order_by']= 'name';
$arr['module'] = $this->module;
$arr['sql'] = '';
$arr['limit'] = '999';
$arr['order_by'] = 'name';
$arr['results'] = $count;
$search->add($arr);
# define the search id and other parameters for Smarty
$smarty->assign('search_id', $search->id);
$smarty->assign('search_id',$search->id);
# page:
$smarty->assign('page', '1');
# page
$smarty->assign('page','1');
# limit:
$smarty->assign('limit', '999');
# limit
$smarty->assign('limit','999');
# order_by:
$smarty->assign('order_by', 'name');
# order_by
$smarty->assign('order_by','name');
# define the result count
$smarty->assign('results', $count);
$smarty->assign('results',$count);
}
}
##############################
## SEARCH SHOW ##
##############################
function search_show($VAR)
{
### Read the contents of the /plugins/db_mapping directory:
/**
* Show search results
*/
public function search_show($VAR) {
# Read the contents of the directory
$count = 0;
chdir(PATH_PLUGINS . 'import');
$dir = opendir(PATH_PLUGINS . 'import');
$dir = opendir(PATH_PLUGINS.'import');
while ($file_name = readdir($dir)) {
if($file_name != '..' && $file_name != '.' && !eregi("^_", $file_name) && eregi(".php$", $file_name) ) {
$result[$count]['name'] = eregi_replace('.php', '', $file_name);
$result[$count]['id'] = $count;
if (! in_array($file_name,array('.','..')) && ! preg_match('/^_/',$file_name) && preg_match('/.php$/',$file_name)) {
$result[$count]['name'] = preg_replace('/.php$/','',$file_name);
$result[$count]['id'] = $count;
$count++;
}
}
}
$class_name = TRUE;
for ($i=0; $i<count($result); $i++)
{
$smart[$i] = $result[$i];
if($class_name)
{
$class_name = true;
for ($i=0; $i<count($result); $i++) {
$smart[$i] = $result[$i];
if ($class_name) {
$smart[$i]['_C'] = 'row1';
$class_name = FALSE;
$class_name = false;
} else {
$smart[$i]['_C'] = 'row2';
$class_name = TRUE;
}
}
$class_name = true;
}
}
# define the DB vars as a Smarty accessible block
# Define the DB vars as a Smarty accessible block
global $smarty;
# define the results
$smarty->assign($this->table, $smart);
$smarty->assign('page', $VAR['page']);
$smarty->assign('order', $smarty_order);
$smarty->assign('sort', $smarty_sort);
$smarty->assign('limit', $search->limit);
$smarty->assign('search_show',$smart);
$smarty->assign('page',$VAR['page']);
$smarty->assign('order',$smarty_order);
$smarty->assign('sort',$smarty_sort);
$smarty->assign('limit',$search->limit);
$smarty->assign('search_id',$search->id);
$smarty->assign('results', $count);
$smarty->assign('results',$count);
# total pages
$smarty->assign('pages', 1);
$smarty->assign('pages',1);
# current page
$smarty->assign('page', 1);
$page_arr = '';
$smarty->assign('page',1);
# page array for menu
$smarty->assign('page_arr', $page_arr);
}
$smarty->assign('page_arr','');
}
/**
* Read a plugin map file, for some default values
*
* @uses CORE_xml;
*/
protected function read_map() {
# If there is a map file, open it
$pmap = array();
if (file_exists($mapfile = sprintf('%simport/%s_map.xml',PATH_PLUGINS,$this->plugin))) {
$C_xml = new CORE_xml;
$map = $C_xml->xml_to_array($mapfile);
if (isset($map['map']))
foreach ($map['map'] as $index => $details)
foreach ($map['map'][$index] as $values) {
$a = $values['id'];
unset($values['id']);
$pmap[$index][$a] = $values;
}
}
return $pmap;
}
}
?>
?>

View File

@@ -1,65 +1,90 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<construct>
<!-- Module name -->
<module>import</module>
<!-- Module supporting database table -->
<table>import</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>plugin</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>
<!-- define the module name -->
<module>import</module>
<!-- Database indexes -->
<index>
</index>
<!-- define the module table name -->
<table>import</table>
<!-- Database fields -->
<field>
<!-- Record ID -->
<id>
<index>1</index>
<type>I8</type>
<unique>1</unique>
</id>
<!-- Site ID -->
<site_id>
<index>1</index>
<type>I4</type>
</site_id>
<!-- Date record created -->
<date_orig>
<convert>date-now</convert>
<type>I8</type>
</date_orig>
<plugin>
<type>C(32)</type>
</plugin>
<action>
<type>C(32)</type>
</action>
<remote_table>
<type>C(32)</type>
</remote_table>
<ab_table>
<type>C(32)</type>
</ab_table>
<remote_id>
<type>I8</type>
</remote_id>
<ab_id>
<type>I8</type>
</ab_id>
</field>
<!-- define the module dependancy(s) -->
<dependancy></dependancy>
<!-- Methods for this class, and the fields they have access to, if applicable -->
<method>
<add>id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id</add>
<update>id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id</update>
<delete>id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id</delete>
<view>id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id</view>
<search>id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id</search>
</method>
<!-- define the DB cache in seconds -->
<cache>0</cache>
<!-- Method triggers -->
<trigger></trigger>
<!-- define the default order_by field for SQL queries -->
<order_by>plugin</order_by>
<!-- Template page display titles -->
<title>
<view>Import</view>
</title>
<!-- define the methods -->
<limit>35</limit>
<!-- define the fields -->
<field>
<id>
<type>I8</type>
<unique>1</unique>
</id>
<site_id>
<type>I4</type>
</site_id>
<date_orig>
<type>I8</type>
</date_orig>
<plugin>
<type>C(32)</type>
</plugin>
<action>
<type>C(32)</type>
</action>
<remote_table>
<type>C(32)</type>
</remote_table>
<ab_table>
<type>C(32)</type>
</ab_table>
<remote_id>
<type>I8</type>
</remote_id>
<ab_id>
<type>I8</type>
</ab_id>
</field>
<!-- define all the methods for this class, and the fields they have access to, if applicable. -->
<method>
<add>id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id</add>
<update>id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id</update>
<delete>id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id</delete>
<view>id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id</view>
<search>id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id</search>
</method>
<!-- define the method triggers -->
<trigger>0</trigger>
</construct>
<!-- Template helpers -->
<tpl>
<search_show>
<plugin>
<field>none</field>
<translate>plugin</translate>
<width>90px</width>
</plugin>
<blank>
<width>10px</width>
</blank>
</search_show>
</tpl>
</construct>

View File

@@ -1,43 +1,47 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<install>
<!-- Tree Menu Module Properties -->
<module_properties>
<!-- MODULE Dependancy, this module wont be installed if the dependant modules dont exist -->
<dependancy></dependancy>
<!-- Translated display to use on the tree -->
<display>Import</display>
<!-- Display a module in the menu tree -->
<menu_display>1</menu_display>
<!-- MODULE Name -->
<name>import</name>
<!-- MODULE Notes, these notes show up in the modules table, as a description of the module -->
<notes><![CDATA[Import data from other applications</notes>]]></notes>
<!-- MODULE Parent, the parent node in the tree -->
<parent>setup</parent>
<!-- SUB Modules to install with this one -->
<sub_modules></sub_modules>
<!-- MODULE Type (core|base), core modules cannot be deleted, unrecognised types are ignored. -->
<type>base</type>
</module_properties>
<!-- Define the main module properties -->
<module_properties>
<name>import</name>
<parent>setup</parent>
<notes></notes>
<menu_display>1</menu_display>
<dependancy></dependancy>
<sub_modules></sub_modules>
</module_properties>
<!-- Define any SQL inserts for this module -->
<sql_inserts>
<module_method>
<do_action>
<name>do_action</name>
</do_action>
<undo_action>
<name>undo_action</name>
</undo_action>
<view>
<name>view</name>
<page>core:search&amp;module=%%&amp;_escape=1</page>
<menu_display></menu_display>
</view>
<search>
<name>search</name>
<page>core:search&amp;module=%%&amp;_escape=1</page>
<menu_display>1</menu_display>
</search>
<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>
<search>
<display>List</display>
<menu_display>1</menu_display>
<name>search</name>
<notes><![CDATA[List records]]></notes>
<page><![CDATA[core:search&module=%%]]></page>
</search>
<search_show>
<name>search_show</name>
<notes><![CDATA[Show the results of a search]]></notes>
</search_show>
<view>
<name>view</name>
<notes><![CDATA[View a record]]></notes>
</view>
<do_action>
<name>do_action</name>
</do_action>
<undo_action>
<name>undo_action</name>
</undo_action>
</module_method>
</install>