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,141 +1,105 @@
<?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 Core
*/
function CORE_database_mass_delete($VAR, &$construct, $type)
{
/**
* The main AgileBill CORE Database MASS DELETE Method
*
* @uses CORE_trigger
*/
function CORE_database_mass_delete($VAR,$construct,$type) {
global $C_auth,$C_debug;
$db = &DB();
# set the id
$id = $construct->table . '_id';
# generate the list of ID's
$id_list = '';
$ii=0;
if (isset($VAR['delete_id']))
$ids = explode(',',preg_replace('/,$/','',$VAR['delete_id']));
elseif (isset($VAR['id']))
$ids = explode(',',preg_replace('/,$/','',$VAR['id']));
if(isset($VAR["delete_id"]))
{
$id = explode(',',$VAR["delete_id"]);
}
elseif (isset($VAR["id"]))
{
$id = explode(',',$VAR["id"]);
}
for($i=0; $i<count($id); $i++)
{
if($id[$i] != '')
{
if($i == 0)
{
$id_list .= " id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
$ii++;
}
else
{
$id_list .= " OR id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
$ii++;
}
}
}
if($ii>0)
{
# generate the full query
$q = "DELETE FROM
".AGILE_DB_PREFIX."$construct->table
WHERE
$id_list
AND
site_id = '" . DEFAULT_SITE . "'";
# execute the query
$result = $db->Execute($q);
# error reporting
if ($result === false)
{
global $C_debug;
$C_debug->error('database.inc.php','mass_delete', $db->ErrorMsg());
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 0, $VAR);
}
# Check and see if the user is authorised to delete this records
foreach ($ids as $i => $id) {
$groups = $db->Execute(sqlSelect($db,'account_group','group_id',array('account_id'=>$id),'group_id'));
$group = array();
while (! $groups->EOF) {
array_push($group,$groups->fields['group_id']);
$groups->MoveNext();
}
else
{
# Verify the user has access to view this account
foreach ($group as $gid) {
if (! $C_auth->auth_group_by_id($gid)) {
unset($ids[$i]);
break;
}
}
}
# Nothing to delete
if (! count($ids))
return false;
### Delete any associated records:
if(isset($construct->associated_DELETE))
{
# Execute the query
$result = $db->Execute(sqlDelete($db,$construct->table,array('id'=>$ids)));
for($ii=0; $ii<count($construct->associated_DELETE); $ii++)
{
$id_list = '';
for($i=0; $i<count($id); $i++)
{
if($id[$i] != '')
{
if($i == 0)
{
$id_list .= $construct->associated_DELETE[$ii]["field"] ." = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
}
else
{
$id_list .= " OR " . $construct->associated_DELETE[$ii]["field"] . " = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
}
}
}
# Error reporting
if ($result === false) {
$C_debug->error(__FILE__,__METHOD__, $db->ErrorMsg());
# generate the full query
$q = "DELETE FROM
".AGILE_DB_PREFIX."". $construct->associated_DELETE[$ii]["table"] . "
WHERE
$id_list
AND
site_id = '" . DEFAULT_SITE . "'";
# execute the query
$result = $db->Execute($q);
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],0,$VAR);
}
} else {
# Delete any associated records
if (isset($construct->associated_DELETE) && is_array($construct->associated_DELETE) && count($construct->associated_DELETE)) {
foreach ($construct->associated_DELETE as $assoc) {
$db->Execute(sqlDelete($db,$assoc['table'],array($assoc['field']=>$ids)));
# Alert delete message
if (! defined('AJAX')) {
global $C_translate;
$C_translate->value['CORE']['module_name'] = $C_translate->translate('name',$construct->module,'');
$message = $C_translate->translate('alert_delete_ids','CORE','');
$message = str_replace('%%module_name%%','', $message);
$C_debug->alert($message);
}
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],1,$VAR);
}
}
# Alert delete message
if(!defined('AJAX')) {
global $C_debug, $C_translate;
$C_translate->value["CORE"]["module_name"] = $C_translate->translate('name',$construct->module,"");
$message = $C_translate->translate('alert_delete_ids',"CORE","");
$message = ereg_replace('%%module_name%%','', $message);
$C_debug->alert($message);
}
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 1, $VAR);
}
}
}
}
?>
return $result;
}
?>