Changes to AgileBill
This commit is contained in:
@@ -1,170 +1,111 @@
|
||||
<?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_view($VAR, &$construct, $type)
|
||||
{
|
||||
|
||||
/**
|
||||
* The main AgileBill CORE Database VIEW Method
|
||||
*
|
||||
* This function should only return 1 record.
|
||||
*
|
||||
* @uses CORE_trigger
|
||||
* @uses CORE_static_var
|
||||
*/
|
||||
|
||||
function CORE_database_view($VAR,$construct,$type) {
|
||||
require_once(PATH_CORE.'static_var.inc.php');
|
||||
|
||||
# Some Validaiton
|
||||
if (! isset($VAR['id']))
|
||||
return;
|
||||
|
||||
# If we have more than 1 entry, then return. Javascript should bring us back with 1 entry to view.
|
||||
if (count(explode(',',preg_replace('/,$/','',$VAR['id']))) > 1)
|
||||
return;
|
||||
|
||||
# Set our db.
|
||||
$db = &DB();
|
||||
|
||||
# set the field list for this method:
|
||||
$arr = $construct->method[$type];
|
||||
$result = $db->Execute(sqlSelect($db,$construct->table,implode(',',$construct->method[$type]),array('id'=>$VAR['id']),$construct->order_by));
|
||||
|
||||
# loop through the field list to create the sql queries
|
||||
$field_list = '';
|
||||
$i=0;
|
||||
while (list ($key, $value) = each ($arr))
|
||||
{
|
||||
if($i == 0)
|
||||
{
|
||||
$field_var = $construct->table . '_' . $value;
|
||||
$field_list .= $value;
|
||||
# Error reporting
|
||||
if ($result === false) {
|
||||
global $C_debug;
|
||||
|
||||
$C_debug->error(__FILE__,__METHOD__,$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);
|
||||
}
|
||||
else
|
||||
{
|
||||
$field_var = $construct->table . '_' . $value;
|
||||
$field_list .= "," . $value;
|
||||
}
|
||||
$i++;
|
||||
|
||||
return;
|
||||
|
||||
# No results:
|
||||
} elseif (! $result->RecordCount()) {
|
||||
global $C_debug;
|
||||
$C_debug->error(__FILE__,__METHOD__,'The selected record does not exist any longer, or your account is not authorized to view it');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(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])." ";
|
||||
$ii++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$id_list .= " OR id = " .$db->qstr($id[$i]). " ";
|
||||
$ii++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
# Get the static vars
|
||||
$static_var = new CORE_static_var;
|
||||
$arr = $static_var->update_form($construct->module,'update',$result->fields['id']);
|
||||
if (is_array($arr))
|
||||
$smart['static_var'] = $arr;
|
||||
|
||||
if($ii>0)
|
||||
{
|
||||
# generate the full query
|
||||
$q = "SELECT
|
||||
$field_list
|
||||
FROM
|
||||
".AGILE_DB_PREFIX."$construct->table
|
||||
WHERE
|
||||
$id_list
|
||||
AND site_id = '" . DEFAULT_SITE . "'
|
||||
ORDER BY $construct->order_by ";
|
||||
# Run any custom validation on this result for this module
|
||||
if (isset($construct->custom_EXP)) {
|
||||
for ($ei=0; $ei<count($construct->custom_EXP); $ei++) {
|
||||
$field = $construct->custom_EXP[$ei]['field'];
|
||||
$value = $construct->custom_EXP[$ei]['value'];
|
||||
|
||||
$result = $db->Execute($q);
|
||||
if ($result->fields[$field] == $value) {
|
||||
$smart = $result->fields;
|
||||
|
||||
///////////////////////
|
||||
# echo $q;
|
||||
# echo "<BR>" . $db->ErrorMsg();
|
||||
|
||||
# error reporting
|
||||
if ($result === false)
|
||||
{
|
||||
global $C_debug;
|
||||
$C_debug->error('database.inc.php','view', $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);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
# put the results into a smarty accessable array
|
||||
$i=0;
|
||||
$class_name = TRUE;
|
||||
while (!$result->EOF)
|
||||
{
|
||||
### Run any custom validation on this result for
|
||||
### this module
|
||||
if(isset($construct->custom_EXP))
|
||||
{
|
||||
for($ei=0; $ei<count($construct->custom_EXP); $ei++)
|
||||
{
|
||||
$field = $construct->custom_EXP[$ei]["field"];
|
||||
$value = $construct->custom_EXP[$ei]["value"];
|
||||
if($result->fields["$field"] == $value)
|
||||
{
|
||||
$smart[$i] = $result->fields;
|
||||
if($class_name)
|
||||
{
|
||||
$smart[$i]["i"] = $i;
|
||||
} else {
|
||||
$smart[$i]["i"] = $i;
|
||||
}
|
||||
$result->MoveNext();
|
||||
$ei = count($construct->custom_EXP);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$result->MoveNext();
|
||||
}
|
||||
else
|
||||
{
|
||||
$smart[$i] = $result->fields;
|
||||
if($class_name)
|
||||
{
|
||||
$smart[$i]["i"] = $i;
|
||||
} else {
|
||||
$smart[$i]["i"] = $i;
|
||||
}
|
||||
$result->MoveNext();
|
||||
$i++;
|
||||
$ei = count($construct->custom_EXP);
|
||||
}
|
||||
}
|
||||
|
||||
# get the result count:
|
||||
$results = $i;
|
||||
|
||||
### No results:
|
||||
if($i == 0)
|
||||
{
|
||||
global $C_debug;
|
||||
$C_debug->error("CORE:database.inc.php", "view()", "The selected record does not
|
||||
exist any longer, or your account is not authorized to view it");
|
||||
return;
|
||||
}
|
||||
|
||||
# define the results
|
||||
global $smarty;
|
||||
$smarty->assign($construct->table, $smart);
|
||||
$smarty->assign('results', $search->results);
|
||||
|
||||
if(isset($construct->trigger["$type"]))
|
||||
{
|
||||
include_once(PATH_CORE . 'trigger.inc.php');
|
||||
$trigger = new CORE_trigger;
|
||||
$trigger->trigger($construct->trigger["$type"], 1, $VAR);
|
||||
}
|
||||
|
||||
return $smart;
|
||||
} else {
|
||||
$smart = $result->fields;
|
||||
}
|
||||
|
||||
# Define the results
|
||||
global $smarty;
|
||||
$smarty->assign('record',$smart);
|
||||
|
||||
if (isset($construct->trigger[$type])) {
|
||||
include_once(PATH_CORE.'trigger.inc.php');
|
||||
$trigger = new CORE_trigger;
|
||||
|
||||
$trigger->trigger($construct->trigger[$type],1,$VAR);
|
||||
}
|
||||
|
||||
# Return the retrieved records
|
||||
return $smart;
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
Reference in New Issue
Block a user