2008-11-26 22:50:40 +00:00
|
|
|
<?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
|
2009-08-03 04:10:16 +00:00
|
|
|
*
|
|
|
|
* 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
|
2008-11-26 22:50:40 +00:00
|
|
|
*
|
|
|
|
* @link http://www.agileco.com/
|
|
|
|
* @copyright 2004-2008 Agileco, LLC.
|
|
|
|
* @license http://www.agileco.com/agilebill/license1-4.txt
|
2009-08-03 04:10:16 +00:00
|
|
|
* @author Tony Landis <tony@agileco.com>
|
2008-11-26 22:50:40 +00:00
|
|
|
* @package AgileBill
|
2009-08-03 04:10:16 +00:00
|
|
|
* @subpackage Core
|
2008-11-26 22:50:40 +00:00
|
|
|
*/
|
2009-08-03 04:10:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2008-11-26 22:50:40 +00:00
|
|
|
$db = &DB();
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
$result = $db->Execute(sqlSelect($db,$construct->table,implode(',',$construct->method[$type]),array('id'=>$VAR['id']),$construct->order_by));
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# 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);
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
2009-08-03 04:10:16 +00:00
|
|
|
|
|
|
|
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;
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# 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;
|
|
|
|
|
|
|
|
# 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 = $result->fields;
|
|
|
|
|
2008-11-26 22:50:40 +00:00
|
|
|
$result->MoveNext();
|
2009-08-03 04:10:16 +00:00
|
|
|
$ei = count($construct->custom_EXP);
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
} else {
|
|
|
|
$smart = $result->fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Define the results
|
|
|
|
global $smarty;
|
|
|
|
$smarty->assign('record',$smart);
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
if (isset($construct->trigger[$type])) {
|
|
|
|
include_once(PATH_CORE.'trigger.inc.php');
|
|
|
|
$trigger = new CORE_trigger;
|
|
|
|
|
|
|
|
$trigger->trigger($construct->trigger[$type],1,$VAR);
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
2009-08-03 04:10:16 +00:00
|
|
|
|
|
|
|
# Return the retrieved records
|
|
|
|
return $smart;
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
2009-08-03 04:10:16 +00:00
|
|
|
?>
|