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,213 +1,182 @@
<?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
*/
class CORE_search
{
var $recent_js;
var $recent_menu;
var $saved_js;
var $saved_menu;
/**
* The main AgileBill Search Class
*
* @package AgileBill
* @subpackage Core
*/
class CORE_search {
public $recent_js;
public $recent_menu;
public $saved_js;
public $saved_menu;
/**
* Create a new search record.
*
* @return void
* @since Version 1.0
* @param array Contains the elements of the search query
*/
* Create a new search record.
*
* @param array Contains the elements of the search query
* @return void
* @since Version 1.0
*/
public function add($arr) {
$db = &DB();
function add($arr)
{
$db = &DB();
# determine the search id:
$this->id = $db->GenID(AGILE_DB_PREFIX . 'search_id');
# Determine the search id:
$this->id = $db->GenID(AGILE_DB_PREFIX.'search_id');
# safely store the SQL Query:
$sql = $db->qstr($arr['sql']);
# Create the search record
$result = $db->Execute(sqlInsert($db,'search',array(
'session_id'=>SESS,
'account_id'=>SESS_ACCOUNT,
'module'=>$arr['module'],
'date_orig'=>time(),
'date_expire'=>(time()+(SEARCH_EXPIRE*60)),
'full_sql'=>$arr['sql'],
'order_by'=>$arr['order_by'],
'limit_no'=>$arr['limit'],
'results'=>$arr['results']
),$this->id));
# set the time when this record expires
$date_expire = (time() + (SEARCH_EXPIRE*60));
# create the search record
$q = "INSERT INTO " . AGILE_DB_PREFIX . "search SET
id = '" . $this->id . "',
site_id = '" . DEFAULT_SITE . "',
session_id = '" . SESS . "',
account_id = '" . SESS_ACCOUNT . "',
module = '" . $arr['module'] . "',
date_orig = '" . time() . "',
date_expire = '" . $date_expire . "',
full_sql = $sql,
order_by = '" . $arr['order_by'] . "',
limit_no = '" . $arr['limit'] . "',
results = '" . $arr['results'] . "'";
$result = $db->Execute($q);
# error reporting
if ($result === false)
{
# Error reporting
if ($result === false) {
global $C_debug;
$C_debug->error('search.inc.php','add', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
}
/**
* Retrieves a specific search record, and sets the values to the object.
*
* @return void
* @since Version 1.0
* @todo Complete the search refresh feature
* @param int Contians the Search Id to be retrieved
*/
function get($id)
{
# get the details for this search
* Retrieves a specific search record, and sets the values to the object.
*
* @param int Contians the Search Id to be retrieved
* @return void
* @since Version 1.0
* @todo Complete the search refresh feature
*/
public function get($id) {
# Get the details for this search
$db = &DB();
$q = "SELECT *
FROM " . AGILE_DB_PREFIX . "search
WHERE
id = '" . $id . "'
AND
site_id = '" . DEFAULT_SITE . "'";
$result = $db->Execute($q);
# error reporting
if ($result === false)
{
$result = $db->Execute(sqlSelect($db,'search','*',sprintf('id=%s',$id)));
# Error reporting
if ($result === false) {
global $C_debug;
$C_debug->error('search.inc.php','get', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
# get the search values
$this->id = $id;
$this->account = $result->fields['account_id'];
$this->session = $result->fields['session_id'];
$this->date_orig = $result->fields['date_orig'];
$this->date_expire = $result->fields['date_expire'];
$this->sql = $result->fields['full_sql'];
$this->order_by = $result->fields['order_by'];
$this->limit = $result->fields['limit_no'];
# Get the search values
$this->id = $id;
$this->account = $result->fields['account_id'];
$this->session = $result->fields['session_id'];
$this->date_orig = $result->fields['date_orig'];
$this->date_expire = $result->fields['date_expire'];
$this->sql = $result->fields['full_sql'];
$this->order_by = $result->fields['order_by'];
$this->limit = $result->fields['limit_no'];
# check if this search has expired:
if($this->date_expire <= time())
{
# refresh the search
# $this->results = $this->refresh($id);
# Check if this search has expired:
if($this->date_expire <= time()) {
# Refresh the search
# $this->results = $this->refresh($id);
# echo "<BR> this search has expired! Refreshing.... <BR>";
$this->results = $result->fields['results'];
}
else
{
# use the existing result count
$this->results = $result->fields['results'];
$this->results = $result->fields['results'];
} else {
# Use the existing result count
$this->results = $result->fields['results'];
}
return;
}
/**
* Refreshes the result count of a specific search and stores the new results in the search record,
* and returns the new search result count.
*
* @return int Contains the new search results count
* @since Version 1.0
* @todo Complete the search refresh code
* @param int Contians the Search Id to be refreshed
* @return int The new search results count
* Refreshes the result count of a specific search and stores the new results in the search record,
* and returns the new search result count.
*
* @param int Contians the Search Id to be refreshed
* @return int Contains the new search results count
* @since Version 1.0
* @todo Complete the search refresh code
* @return int The new search results count
*/
function refresh($id)
{
private function refresh($id) {
}
/**
* Saves the current search for later retreival.
*
* @return void
* @since Version 1.0
* @todo Add some error checking for previously used nicknames, identical searches, etc.
* @param int Contians the Search Id to be saved
* @param string Contains the name of the Module this search was for
* @param string Contains search nickname to remember this search as
*/
function save($search_id,$module,$name)
{
# save the search
* Saves the current search for later retreival.
*
* @param string Contains search nickname to remember this search as
* @return void
* @since Version 1.0
* @todo Add some error checking for previously used nicknames, identical searches, etc.
* @param int Contians the Search Id to be saved
* @param string Contains the name of the Module this search was for
*/
public function save($search_id,$module,$name) {
# Save the search
$db = &DB();
# determine the search id:
# Determine the search id:
$this->id = $db->GenID('search_saved');
$n = $db->qstr($name);
$result = $db->Execute(sqlInsert($db,'search_saved',array(
'search_id'=>$search_id,
'account_id'=>SESS_ACCOUNT,
'session_id'=>SESS,
'date_orig'=>time(),
'date_last'=>time(),
'date_expire'=>'',
'module'=>$module,
'name'=>$name
),$this->id));
# generate the insert statement
$q = "INSERT INTO " . AGILE_DB_PREFIX . "search_saved SET
id = '$this->id',
site_id = '" . DEFAULT_SITE . "',
search_id = '$search_id',
account_id = '" . SESS_ACCOUNT . "',
session_id = '" . SESS . "',
date_orig = '" . time() . "',
date_last = '" . time() . "',
date_expire = '',
module = '$module',
name = $n";
$result = $db->Execute($q);
# error reporting
if ($result === false)
{
# Error reporting
if ($result === false) {
global $C_debug;
$C_debug->error('search.inc.php','refresh', $db->ErrorMsg());
}
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
}
/**
* Build the recent search menu and JavaScript
*
* @return void
* @since Version 1.0
* @param string Contains the name of the Module to find recent searches for
*/
function build_recent($module)
{
# disable for now
* Build the recent search menu and JavaScript
*
* @param string Contains the name of the Module to find recent searches for
* @return void
* @since Version 1.0
*/
function build_recent($module) {
# Disable for now
return 0;
if(isset($this->arr)) unset ($this->arr);
# get the recent searches
# Get the recent searches
$db = &DB();
$q = "SELECT id, date_orig, date_expire, full_sql, order_by, limit_no
FROM " . AGILE_DB_PREFIX . "search
@@ -223,11 +192,11 @@ class CORE_search
site_id = '" . DEFAULT_SITE . "'";
$result = $db->Execute($q);
# error reporting
# Error reporting
if ($result === false)
{
global $C_debug;
$C_debug->error('search.inc.php','build_recent', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
$results = $result->RecordCount();
@@ -235,21 +204,21 @@ class CORE_search
$i = 0;
while (!$result->EOF) {
# get the fields for this loop
# Get the fields for this loop
$sql = $result->fields['full_sql'];
# remove the WHERE
# Remove the WHERE
$sql = trim($sql);
$sql = eregi_replace("WHERE","",$sql);
$sql = eregi_replace("AND$","",$sql);
$sql = trim($sql);
# replace any sql statements before we split the string
# Replace any sql statements before we split the string
$sql = ereg_replace(" = ","===",$sql);
$sql = ereg_replace(" LIKE ","===",$sql);
# determine the number of fields
# Determine the number of fields
$ii=0;
if(ereg(" AND ", $sql))
@@ -257,16 +226,16 @@ class CORE_search
$sql = explode(" AND ",$sql);
$this_fields = count($sql);
# loop
# Loop
for($count=0; $count < $this_fields; $count++)
{
# do each field
# Do each field
$sqls = explode("==",$sql[$count]);
$field[$count][name] = $sqls[0];
$field[$count][value] = ereg_replace("'","",$sqls[1]);
$field[$count][value] = ereg_replace("=","",$field[$count][value]);
# check that the name & value are both set...
# Check that the name & value are both set...
if($field[$count][value] != '' && $field[$count][name] != '')
{
if(!isset($this->arr[$i][$ii][limit]))
@@ -282,23 +251,23 @@ class CORE_search
# echo "<BR><BR>Field/Name: " . $this->arr[$i][$ii][0] . " -> " . $this->arr[$i][$ii][1];
$ii++;
# set the menu up for Smarty
# Set the menu up for Smarty
$this->recent_menu[$i] = $result->fields;
}
}
}
else
{
# field count
# Field count
$this_fields = 1;
# do this one field
# Do this one field
$sqls = explode("==",$sql);
$field[name] = $sqls[0];
$field[value] = ereg_replace("'","",$sqls[1]);
$field[value] = ereg_replace("=","",$field[value]);
# check that the name & value are both set...
# Check that the name & value are both set...
if($field[value] != '' && $field[name] != '')
{
if(!isset($this->arr[$i][$ii][limit]))
@@ -314,24 +283,24 @@ class CORE_search
# echo "<BR><BR>Field/Name: " . $field[name] . " -> " . $field[value];
$ii++;
# set the menu up for Smarty
# Set the menu up for Smarty
$this->recent_menu[$i] = $result->fields;
}
}
# continue loop
# Continue loop
$result->MoveNext();
if ($ii > 0) $i++;
}
# finish the JS:
# Finish the JS:
if($i > 0 && $ii > 0)
{
# build the JavaScript
# Build the JavaScript
$this->recent_js = '
<script language="JavaScript">
<script language="JavaScript">
// SEARCH FORM CONTROLLER
function fill_search_recent(mod,fields,field_count,limit,order,s,c)
@@ -339,22 +308,22 @@ class CORE_search
document.search.reset();
var id = document.search_recent.search_id.selectedIndex;
if(id == 0) return "";
var idx = document.search_recent.search_id.options[id].value;
var idx = document.search_recent.search_id.options[id].value;
for(loop=0; loop <= c; loop++)
{
if(s[loop] == idx)
if(s[loop] == idx)
{
var i = loop;
}
}
document.search.limit.value = limit[i];
document.search.order_by.value = order[i];
document.search.order_by.value = order[i];
for(loop=0; loop < field_count[i]; loop++)
{
var fill = "document.search." + mod + "_" + fields[i][loop][0] + ".value = fields[i][loop][1];"
eval(fill);
}
}';
}
}';
$this->recent_js .= "
var mod = '$module';
@@ -366,19 +335,19 @@ class CORE_search
var s = new Array($i);
";
# loop through the searches
# Loop through the searches
for ($ix = 0; $ix <= count($this->arr); $ix++)
{
# loop through the fields
# Loop through the fields
for ($iix = 0; $iix <= count($this->arr[$ix]); $iix++)
{
# check that the name/value is set...
# Check that the name/value is set...
if( $this->arr[$ix][$iix][0] != "" && $this->arr[$ix][$iix][1] != "")
{
$count = count($this->arr[$ix]);
# setup the arrays:
# Setup the arrays:
if($iix==0)
{
$this->recent_js .= "
@@ -390,7 +359,7 @@ class CORE_search
";
}
# set the field settings
# Set the field settings
$this->recent_js .=
"
fields[$ix][$iix] = new Array(2);
@@ -401,7 +370,7 @@ class CORE_search
}
}
# finish the js
# Finish the js
$this->recent_js .= "
</script>
";
@@ -410,28 +379,23 @@ class CORE_search
{
$this->recent_js = FALSE;
}
} # end of functino
} # End of functino
/**
* Build the saved search menu and JavaScript
*
* @return void
* @since Version 1.0
* @param string Contains the name of the Module to find saved searches for
*/
function build_saved($module)
{
# disable for now
* Build the saved search menu and JavaScript
*
* @param string Contains the name of the Module to find saved searches for
* @return void
* @since Version 1.0
*/
function build_saved($module) {
# Disable for now
return 0;
if(isset($this->arr)) unset ($this->arr);
# get the saved searches
# get the recent searches
# Get the saved searches
# Get the recent searches
$db1 = &DB();
$q = "SELECT id, search_id, name
FROM " . AGILE_DB_PREFIX . "search_saved
@@ -446,17 +410,17 @@ class CORE_search
ORDER BY name ASC";
$result1 = $db1->Execute($q);
# error reporting
# Error reporting
if ($result1 === false)
{
global $C_debug;
$C_debug->sql_error($db1->ErrorMsg());
}
$i=0;
while (!$result1->EOF)
{
# get the information for this search
$i=0;
while (!$result1->EOF)
{
# Get the information for this search
$db = &DB();
$q = "SELECT id, full_sql, order_by, limit_no
FROM " . AGILE_DB_PREFIX . "search
@@ -466,28 +430,28 @@ class CORE_search
site_id = '" . DEFAULT_SITE . "'";
$result = $db->Execute($q);
# error reporting
# Error reporting
if ($result === false)
{
global $C_debug;
$C_debug->error('search.inc.php','build_saved', $db->ErrorMsg());
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
# get the fields for this loop
# Get the fields for this loop
$sql = $result->fields['full_sql'];
# remove the WHERE
# Remove the WHERE
$sql = trim($sql);
$sql = eregi_replace("WHERE","",$sql);
$sql = eregi_replace("AND$","",$sql);
$sql = trim($sql);
# replace any sql statements before we split the string
# Replace any sql statements before we split the string
$sql = ereg_replace(" = ","===",$sql);
$sql = ereg_replace(" LIKE ","===",$sql);
# determine the number of fields
# Determine the number of fields
$ii=0;
if(ereg(" AND ", $sql))
@@ -495,16 +459,16 @@ class CORE_search
$sql = explode(" AND ",$sql);
$this_fields = count($sql);
# loop
# Loop
for($count=0; $count < $this_fields; $count++)
{
# do each field
# Do each field
$sqls = explode("==",$sql[$count]);
$field[$count][name] = $sqls[0];
$field[$count][value] = ereg_replace("'","",$sqls[1]);
$field[$count][value] = ereg_replace("=","",$field[$count][value]);
# check that the name & value are both set...
# Check that the name & value are both set...
if($field[$count][value] != '' && $field[$count][name] != '')
{
if(!isset($this->arr[$i][$ii][limit]))
@@ -526,16 +490,16 @@ class CORE_search
}
else
{
# field count
# Field count
$this_fields = 1;
# do this one field
# Do this one field
$sqls = explode("==",$sql);
$field[name] = $sqls[0];
$field[value] = ereg_replace("'","",$sqls[1]);
$field[value] = ereg_replace("=","",$field[value]);
# check that the name & value are both set...
# Check that the name & value are both set...
if($field[value] != '' && $field[name] != '')
{
if(!isset($this->arr[$i][$ii][limit]))
@@ -551,25 +515,25 @@ class CORE_search
# echo "<BR><BR>Field/Name: " . $field[name] . " -> " . $field[value];
$ii++;
# set the menu up for Smarty
# Set the menu up for Smarty
$this->saved_menu[$i] = $result->fields;
$this->saved_menu[$i]["name"] = $result1->fields["name"];
}
}
$result1->MoveNext();
if ($ii > 0) $i++;
$result1->MoveNext();
if ($ii > 0) $i++;
}
# finish the JS:
# Finish the JS:
if($i > 0 && $ii > 0)
{
# build the JavaScript
# Build the JavaScript
$this->saved_js = '
<script language="JavaScript">
<script language="JavaScript">
// SEARCH FORM CONTROLLER
function fill_search_saved(s_mod,s_fields,s_field_count,s_limit,s_order,s_s,s_c)
@@ -577,22 +541,22 @@ class CORE_search
document.search.reset();
var id = document.search_saved.search_id.selectedIndex;
if(id == 0) return "";
var idx = document.search_saved.search_id.options[id].value;
var idx = document.search_saved.search_id.options[id].value;
for(loop=0; loop <= s_c; loop++)
{
if(s_s[loop] == idx)
if(s_s[loop] == idx)
{
var i = loop;
var i = loop;
}
}
document.search.limit.value = s_limit[i];
document.search.order_by.value = s_order[i];
document.search.order_by.value = s_order[i];
for(loop=0; loop < s_field_count[i]; loop++)
{
var fill = "document.search." + s_mod + "_" + s_fields[i][loop][0] + ".value = s_fields[i][loop][1];"
eval(fill);
}
}';
}';
$this->saved_js .= "
var s_mod = '$module';
@@ -604,19 +568,19 @@ class CORE_search
var s_s = new Array($i);
";
# loop through the searches
# Loop through the searches
for ($ix = 0; $ix <= count($this->arr); $ix++)
{
# loop through the fields
# Loop through the fields
for ($iix = 0; $iix <= count($this->arr[$ix]); $iix++)
{
# check that the name/value is set...
# Check that the name/value is set...
if( $this->arr[$ix][$iix][0] != "" && $this->arr[$ix][$iix][1] != "")
{
$count = count($this->arr[$ix]);
# setup the arrays:
# Setup the arrays:
if($iix==0)
{
$this->saved_js .= "
@@ -628,7 +592,7 @@ class CORE_search
";
}
# set the field settings
# Set the field settings
$this->saved_js .=
"
s_fields[$ix][$iix] = new Array(2);
@@ -639,7 +603,7 @@ class CORE_search
}
}
# finish the js
# Finish the js
$this->saved_js .= "
</script>
";
@@ -650,4 +614,4 @@ class CORE_search
}
}
}
?>
?>