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,226 +1,200 @@
<?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_update($VAR, &$construct, $type)
{
/**
* The main AgileBill CORE Database UPDATE Method
*
* @uses CORE_validate
* @uses CORE_trigger
*/
function CORE_database_update($VAR,$construct,$type) {
global $C_translate;
# set the field list for this method:
$arr = $construct->method["$type"];
# Temp during code rework
if (! is_array($construct->val_error))
$construct->val_error = array();
# define the validation class
include_once(PATH_CORE . 'validate.inc.php');
$validate = new CORE_validate;
# Set the field list for this method
$arr = $construct->method[$type];
$construct->validated = true;
# Define the validation class
include_once(PATH_CORE.'validate.inc.php');
$validate = new CORE_validate($VAR,$construct->module);
$construct->validated = true;
# define this record id
$id = $VAR[$construct->module . '_id'];
# Quick Validation to see if we have too many variables.
foreach ($VAR as $field_name => $value)
if (preg_match("/^{$construct->module}_/",$field_name))
if (! in_array(preg_replace("/^{$construct->module}_/",'',$field_name),$arr))
array_push($construct->val_error,array(
'field'=>sprintf('%s_%s',$construct->table,$field_name),
'field_trans'=>$field_name,
'error'=>sprintf('WARNING: Variable passed to %s but it will be ignored.',__METHOD__),
'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
));
####################################################################
# loop through the field list to validate the required fields
####################################################################
# Define this record id
$id = $VAR[$construct->module.'_id'];
while (list ($key, $value) = each ($arr))
{
# get the field value
$field_var = $construct->module . '_' . $value;
$field_name = $value;
$construct->validate = true;
# Perform each field validation
while (list($key,$field_name) = each($arr)) {
# Get the field value
$field_var = sprintf('%s_%s',$construct->module,$field_name);
####################################################################
# perform any field validation...
####################################################################
# check if the conversion type required is not one ignored on updates:
# Check if the conversion type required is not one ignored on updates
$ignore_con = false;
$ignore_convert = Array('sha', 'md5','rc5','crypt');
for ($ic=0; $ic < count($ignore_convert); $ic++)
{
if (isset($construct->field["$value"]["convert"]))
if ($construct->field["$value"]["convert"] == $ignore_convert[$ic]) $ignore_con = true;
}
$ignore_convert = array('sha','md5','rc5','crypt');
for ($ic=0; $ic<count($ignore_convert); $ic++)
if (isset($construct->field[$field_name]['convert']))
if ($construct->field[$field_name]['convert'] == $ignore_convert[$ic])
$ignore_con = true;
if(!$ignore_con)
{
if (! $ignore_con) {
# check if this value is unique
if(isset($construct->field["$value"]["unique"]))
{
if(isset($VAR["$field_var"]))
{
if(!$validate->validate_unique($construct->table, $field_name, $id, $VAR["$field_var"]))
{
$construct->validated = false;
$construct->val_error[] = array('field' => $construct->module . '_' . $field_name,
'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""), # translate
'error' => $C_translate->translate('validate_unique',"", ""));
}
}
if (isset($construct->field[$field_name]['unique']) && isset($VAR[$field_var])) {
if (! $validate->validate_unique($construct->table,$field_name,$id,$VAR[$field_var])) {
$construct->validated = false;
array_push($construct->val_error,array(
'field'=>sprintf('%s_%s',$construct->module,$field_name),
'field_trans'=>$C_translate->translate('field_'.$field_name,$construct->module,''),
'error'=>$C_translate->translate('validate_unique','',''),
'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
));
}
}
# check if the submitted value meets the specifed requirements
if(isset($construct->field["$value"]["validate"]))
{
if(isset($VAR["$field_var"]))
{
if($VAR["$field_var"] != '')
{
if(!$validate->validate($field_name, $construct->field["$value"], $VAR["$field_var"], $construct->field["$value"]["validate"]))
{
$construct->validated = false;
$construct->val_error[] = array('field' => $construct->module . '_' . $field_name,
'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""),
'error' => $validate->error["$field_name"] );
}
}
else
{
# Check if the submitted value meets the specifed requirements
if (isset($construct->field[$field_name]['validate'])) {
if (isset($VAR[$field_var]) && ($VAR[$field_var] != '')) {
if (! $validate->validate($field_name,$construct->field[$field_name],$VAR[$field_var],$construct->field[$field_name]['validate'])) {
$construct->validated = false;
$construct->val_error[] = array('field' => $construct->module . '_' . $field_name,
'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""),
'error' => $C_translate->translate('validate_any',"", ""));
array_push($construct->val_error,array(
'field'=>sprintf('%s_%s',$construct->module,$field_name),
'field_trans'=>$C_translate->translate('field_'.$field_name,$construct->module,''),
'error'=>$validate->error[$field_name],
'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
));
}
}
else
{
} else {
$construct->validated = false;
$construct->val_error[] = array('field' => $construct->module. '_' . $field_name,
'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""),
'error' => $C_translate->translate('validate_any',"", ""));
array_push($construct->val_error,array(
'field'=>sprintf('%s_%s',$construct->module,$field_name),
'field_trans'=>$C_translate->translate('field_'.$field_name,$construct->module,''),
'error'=>$C_translate->translate('validate_any','',''),
'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
));
}
}
}
}
/* If validation has failed, skip the db insert & set the errors & original fields as Smarty objects,
and change the page to be loaded.*/
if (! $construct->validated) {
global $smarty;
# Set the errors as a Smarty Object
$smarty->assign('form_validation',$construct->val_error);
# Change the page to be loaded
$VAR['_page'] = $construct->module.':view';
####################################################################
# If validation was failed, skip the db insert &
# set the errors & origonal fields as Smarty objects,
# and change the page to be loaded.
####################################################################
# Define any triggers
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
if(!$construct->validated)
{
global $smarty;
# set the errors as a Smarty Object
$smarty->assign('form_validation', $construct->val_error);
# change the page to be loaded
global $VAR;
$VAR['_page'] = $construct->module . ':view';
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 0, $VAR);
$trigger->trigger($construct->trigger[$type],0,$VAR);
}
# strip slashes
# Strip slashes
global $C_vars;
$C_vars->strip_slashes_all();
return false;
}
else
{
return false;
} else {
# Begin the new database class
$db = &DB();
$field_list = '';
$i = 0;
# Loop through the field list to create the sql queries
$field_list = array();
reset($arr);
while (list ($key, $value) = each ($arr))
{
# get the field value
$field_var = $construct->module . '_' . $value;
$field_name = $value;
while (list($key,$field_name) = each($arr)) {
# Get the field value
$field_var = sprintf('%s_%s',$construct->module,$field_name);
if(isset($VAR["$field_var"]) && $VAR["$field_var"] != 'IGNORE-ARRAY-VALUE')
{
# check if html allowed:
if(@$construct->field["$value"]["html"] != 1 && !is_array($VAR["$field_var"]))
$insert_value = htmlspecialchars($VAR["$field_var"]);
if (isset($VAR[$field_var]) && $VAR[$field_var] != 'IGNORE-ARRAY-VALUE') {
# Check if HTML allowed
if (@$construct->field[$field_name]['html'] != 1 && ! is_array($VAR[$field_var]))
$insert_value = htmlspecialchars($VAR[$field_var]);
else
$insert_value = $VAR["$field_var"];
$insert_value = $VAR[$field_var];
# perform data conversions
if(isset($construct->field["$value"]["convert"] ))
$insert_value = $validate->convert($field_name, $insert_value, $construct->field["$value"]["convert"]);
# Perform data conversions
if (isset($construct->field[$field_name]['convert']) && trim($construct->field[$field_name]['convert']))
$insert_value = $validate->convert($field_name,$insert_value,$construct->field[$field_name]['convert']);
if($i == 0)
$field_list .= $value . "=" . $db->qstr($insert_value, get_magic_quotes_gpc());
else
$field_list .= ", " . $value . "=" . $db->qstr($insert_value, get_magic_quotes_gpc());
$i++;
}
elseif ( @$construct->field["$value"]["convert"] == "array" && @$VAR["$field_var"] != 'IGNORE-ARRAY-VALUE')
{
# Handle blank array string...
$insert_value = serialize(Array(""));
if($i == 0)
$field_list .= $value . "=" . $db->qstr($insert_value, get_magic_quotes_gpc());
else
$field_list .= ", " . $value . "=" . $db->qstr($insert_value, get_magic_quotes_gpc());
$i++;
}
$field_list[$field_name] = $insert_value;
} elseif (@$construct->field[$field_name]['convert'] == 'array' && @$VAR[$field_var] != 'IGNORE-ARRAY-VALUE')
# Handle blank array string
$field_list[$field_name] = serialize(array());
}
# generate the full query
$q = "UPDATE " . AGILE_DB_PREFIX . "$construct->table SET
$field_list
WHERE
id = ". $db->qstr($id) ."
AND
site_id = " . $db->qstr(DEFAULT_SITE);
# execute the query
$db = &DB();
$result = $db->Execute($q);
# Execute the query
$result = $db->Execute(sqlUpdate($db,$construct->table,$field_list,array('id'=>$id)));
# echo "<PRE>$q</PRE>";
# error reporting
if ($result === false)
{
# Error reporting
if ($result === false) {
global $C_debug;
$C_debug->error('database.inc.php','update', $db->ErrorMsg());
$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);
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],0,$VAR);
}
return false;
return false;
}
else
{
if(isset($construct->trigger["$type"]))
{
include_once(PATH_CORE . 'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger["$type"], 1, $VAR);
}
return true;
# Define any triggers
if (isset($construct->trigger[$type])) {
include_once(PATH_CORE.'trigger.inc.php');
$trigger = new CORE_trigger;
$trigger->trigger($construct->trigger[$type],1,$VAR);
}
}
return true;
}
}
?>
?>