Changes to AgileBill
This commit is contained in:
@@ -1,75 +1,72 @@
|
||||
<?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_search_show($VAR, &$construct, $type)
|
||||
{
|
||||
|
||||
# set the field list for this method:
|
||||
/**
|
||||
* The main AgileBill CORE Database SEARCH_SHOW Method
|
||||
*
|
||||
* @uses CORE_search
|
||||
* @uses CORE_trigger
|
||||
*/
|
||||
|
||||
function CORE_database_search_show($VAR, &$construct, $type) {
|
||||
# Set the field list for this method:
|
||||
$arr = $construct->method[$type];
|
||||
$field_list = '';
|
||||
$construct->linked = array();
|
||||
|
||||
$i=0;
|
||||
while (list ($key, $value) = each ($arr))
|
||||
{
|
||||
if($i == 0)
|
||||
{
|
||||
$field_var = $construct->table . '_' . $value;
|
||||
$field_list .= AGILE_DB_PREFIX . $construct->table . "." . $value;
|
||||
while (list($key,$value) = each($arr)) {
|
||||
$field_var = sprintf('%s_%s',$construct->table,$value);
|
||||
|
||||
// determine if this record is linked to another table/field
|
||||
if($construct->field[$value]["asso_table"] != "")
|
||||
{
|
||||
$construct->linked[] = array('field' => $value, 'link_table' => $construct->field[$value]["asso_table"], 'link_field' => $construct->field[$value]["asso_field"]);
|
||||
}
|
||||
}
|
||||
if ($i == 0)
|
||||
$field_list .= sprintf('%s%s.%s',AGILE_DB_PREFIX,$construct->table,$value);
|
||||
else
|
||||
{
|
||||
$field_var = $construct->table . '_' . $value;
|
||||
$field_list .= "," . AGILE_DB_PREFIX . $construct->table . "." . $value;
|
||||
$field_list .= sprintf(',%s%s.%s',AGILE_DB_PREFIX,$construct->table,$value);
|
||||
|
||||
# Determine if this record is linked to another table/field
|
||||
if ($construct->field[$value]['asso_table'] != '')
|
||||
array_push($construct->linked,array('field'=>$value,'link_table'=>$construct->field[$value]['asso_table'],'link_field'=>$construct->field[$value]['asso_field']));
|
||||
|
||||
// determine if this record is linked to another table/field
|
||||
if($construct->field[$value]["asso_table"] != "")
|
||||
{
|
||||
$construct->linked[] = array('field' => $value, 'link_table' => $construct->field[$value]["asso_table"], 'link_field' => $construct->field[$value]["asso_field"]);
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
# get the search details:
|
||||
if(isset($VAR['search_id']))
|
||||
{
|
||||
include_once(PATH_CORE . 'search.inc.php');
|
||||
# Get the search details:
|
||||
if (isset($VAR['search_id'])) {
|
||||
include_once(PATH_CORE.'search.inc.php');
|
||||
$search = new CORE_search;
|
||||
$search->get($VAR['search_id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
# invalid search!
|
||||
echo '<BR> The search terms submitted were invalid!<BR>'; # translate... # alert
|
||||
|
||||
if(isset($construct->trigger["$type"]))
|
||||
{
|
||||
include_once(PATH_CORE . 'trigger.inc.php');
|
||||
$trigger = new CORE_trigger;
|
||||
$trigger->trigger($construct->trigger["$type"], 0, $VAR);
|
||||
$search->get($VAR['search_id']);
|
||||
|
||||
} else {
|
||||
# Invalid search!
|
||||
echo '<br/>The search terms submitted were invalid!<br/>';
|
||||
|
||||
if (isset($construct->trigger[$type])) {
|
||||
include_once(PATH_CORE.'trigger.inc.php');
|
||||
$trigger = new CORE_trigger;
|
||||
|
||||
$trigger->trigger($construct->trigger[$type],0,$VAR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,176 +74,179 @@ function CORE_database_search_show($VAR, &$construct, $type)
|
||||
if ($search->session != SESS && $search->account != SESS_ACCOUNT) {
|
||||
global $C_debug;
|
||||
$C_debug->alert('You are not authorized to view this search!');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
# get the sort order details:
|
||||
if(isset($VAR['order_by']) && $VAR['order_by'] != "")
|
||||
{
|
||||
$order_by = ' ORDER BY ' . $VAR['order_by'];
|
||||
$smarty_order = $VAR['order_by'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$order_by = ' ORDER BY ' . $construct->order_by;
|
||||
$smarty_order = $search->order_by;
|
||||
# Get the sort order details:
|
||||
if (isset($VAR['order_by']) && $VAR['order_by'] != '') {
|
||||
$order_by = sprintf(' ORDER BY %s',$VAR['order_by']);
|
||||
|
||||
$smarty_order = $VAR['order_by'];
|
||||
|
||||
} else {
|
||||
$order_by = sprintf(' ORDER BY %s',$construct->order_by);
|
||||
$smarty_order = $search->order_by;
|
||||
}
|
||||
|
||||
|
||||
# determine the sort order
|
||||
if(isset($VAR['desc'])) {
|
||||
# Determine the sort order
|
||||
if (isset($VAR['desc'])) {
|
||||
$order_by .= ' DESC';
|
||||
$smarty_sort = 'desc=';
|
||||
} else if(isset($VAR['asc'])) {
|
||||
|
||||
} elseif (isset($VAR['asc'])) {
|
||||
$order_by .= ' ASC';
|
||||
$smarty_sort = 'asc=';
|
||||
|
||||
} else {
|
||||
if (!eregi('date',$smarty_order)) {
|
||||
if (! preg_match('/date/',$smarty_order)) {
|
||||
$order_by .= ' ASC';
|
||||
$smarty_sort = 'asc=';
|
||||
} else {
|
||||
|
||||
} else {
|
||||
$order_by .= ' DESC';
|
||||
$smarty_sort = 'desc=';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Generate the full query
|
||||
$db = &DB();
|
||||
|
||||
# generate the full query
|
||||
$db = &DB();
|
||||
$q = eregi_replace("%%fieldList%%", $field_list, $search->sql);
|
||||
$q = eregi_replace("%%tableList%%", AGILE_DB_PREFIX.$construct->table, $q);
|
||||
$q = eregi_replace("%%whereList%%", "", $q);
|
||||
$q .= " site_id = '" . DEFAULT_SITE . "'";
|
||||
$q = str_replace('%%fieldList%%',$field_list,$search->sql);
|
||||
$q = str_replace('%%tableList%%',AGILE_DB_PREFIX.$construct->table,$q);
|
||||
$q = str_replace('%%whereList%%','',$q);
|
||||
|
||||
$q .= sprintf(' %s.site_id = %s',AGILE_DB_PREFIX.$construct->table,DEFAULT_SITE);
|
||||
$q .= $order_by;
|
||||
|
||||
///////////////////////
|
||||
# Determine the offset & limit
|
||||
$current_page = 1;
|
||||
$offset = -1;
|
||||
|
||||
# determine the offset & limit
|
||||
$current_page=1;
|
||||
$offset=-1;
|
||||
if (!empty($VAR['page'])) $current_page = $VAR['page'];
|
||||
if (empty($search->limit)) $search->limit=25;
|
||||
if($current_page>1) $offset = (($current_page * $search->limit) - $search->limit);
|
||||
$result = $db->SelectLimit($q, $search->limit, $offset);
|
||||
if (! empty($VAR['page']))
|
||||
$current_page = $VAR['page'];
|
||||
if (empty($search->limit))
|
||||
$search->limit=25;
|
||||
|
||||
# error reporting
|
||||
if ($result === false)
|
||||
{
|
||||
if ($current_page>1)
|
||||
$offset = (($current_page*$search->limit)-$search->limit);
|
||||
|
||||
$result = $db->SelectLimit($q,$search->limit,$offset);
|
||||
|
||||
# Error reporting
|
||||
if ($result === false) {
|
||||
global $C_debug;
|
||||
$C_debug->error('database.inc.php','search', $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;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# Run any custom validation on this result for this module
|
||||
$i = 0;
|
||||
$class_name = true;
|
||||
if (isset($construct->custom_EXP)) {
|
||||
while (! $result->EOF) {
|
||||
for ($ei=0; $ei<count($construct->custom_EXP); $ei++) {
|
||||
$field = $construct->custom_EXP[$ei]['field'];
|
||||
$value = $construct->custom_EXP[$ei]['value'];
|
||||
|
||||
### Put the results into a smarty accessable array
|
||||
### Run any custom validation on this result for
|
||||
### this module
|
||||
if(isset($construct->custom_EXP))
|
||||
{
|
||||
$i=0;
|
||||
$class_name = TRUE;
|
||||
$results = 0;
|
||||
while(!$result->EOF)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if ($result->fields[$field] == $value) {
|
||||
$smart[$i] = $result->fields;
|
||||
|
||||
if($class_name)
|
||||
{
|
||||
if ($class_name) {
|
||||
$smart[$i]['_C'] = 'row1';
|
||||
$class_name = FALSE;
|
||||
$class_name = false;
|
||||
} else {
|
||||
$smart[$i]['_C'] = 'row2';
|
||||
$class_name = TRUE;
|
||||
}
|
||||
$i++;
|
||||
$class_name = true;
|
||||
}
|
||||
|
||||
$i++;
|
||||
$ei = count($construct->custom_EXP);
|
||||
$results++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result->MoveNext();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$i=0;
|
||||
$class_name = TRUE;
|
||||
while (!$result->EOF) {
|
||||
|
||||
} else {
|
||||
while (! $result->EOF) {
|
||||
$smart[$i] = $result->fields;
|
||||
|
||||
if($class_name)
|
||||
{
|
||||
if ($class_name) {
|
||||
$smart[$i]['_C'] = 'row1';
|
||||
$class_name = FALSE;
|
||||
$class_name = false;
|
||||
} else {
|
||||
$smart[$i]['_C'] = 'row2';
|
||||
$class_name = TRUE;
|
||||
$class_name = true;
|
||||
}
|
||||
|
||||
$result->MoveNext();
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
# get any linked fields
|
||||
if($i > 0) {
|
||||
# Get any linked fields
|
||||
if ($i > 0) {
|
||||
$db_join = new CORE_database;
|
||||
$construct->result = $db_join->join_fields($smart, $construct->linked);
|
||||
|
||||
} else {
|
||||
$construct->result = $smart;
|
||||
}
|
||||
}
|
||||
|
||||
# get the result count:
|
||||
# Get the result count:
|
||||
$results = $result->RecordCount();
|
||||
|
||||
# define the DB vars as a Smarty accessible block
|
||||
global $smarty;
|
||||
|
||||
# define the results
|
||||
$smarty->assign($construct->table, $construct->result);
|
||||
$smarty->assign('page', $VAR['page']);
|
||||
$smarty->assign('order', $smarty_order);
|
||||
$smarty->assign('sort', $smarty_sort);
|
||||
$smarty->assign('limit', $search->limit);
|
||||
$smarty->assign('search_show',$construct->result);
|
||||
$smarty->assign('page',$VAR['page']);
|
||||
$smarty->assign('order',$smarty_order);
|
||||
$smarty->assign('sort',$smarty_sort);
|
||||
$smarty->assign('limit',$search->limit);
|
||||
$smarty->assign('search_id',$search->id);
|
||||
$smarty->assign('results', $search->results);
|
||||
$smarty->assign('results',$search->results);
|
||||
|
||||
# get the total pages for this search:
|
||||
if (empty($search->limit))
|
||||
$construct->pages = 1;
|
||||
else
|
||||
$construct->pages = intval($search->results / $search->limit);
|
||||
if ($search->results % $search->limit) $construct->pages++;
|
||||
|
||||
# total pages
|
||||
$smarty->assign('pages', $construct->pages);
|
||||
if ($search->results % $search->limit)
|
||||
$construct->pages++;
|
||||
|
||||
# current page
|
||||
$smarty->assign('page', $current_page);
|
||||
$page_arr = '';
|
||||
for($i=0; $i <= $construct->pages; $i++)
|
||||
if ($construct->page != $i) $page_arr[] = $i;
|
||||
# Total pages
|
||||
$smarty->assign('pages',$construct->pages);
|
||||
|
||||
# page array for menu
|
||||
$smarty->assign('page_arr', $page_arr);
|
||||
# Current page
|
||||
$smarty->assign('page',$current_page);
|
||||
|
||||
if(isset($construct->trigger["$type"]))
|
||||
{
|
||||
include_once(PATH_CORE . 'trigger.inc.php');
|
||||
$trigger = new CORE_trigger;
|
||||
$trigger->trigger($construct->trigger["$type"], 1, $VAR);
|
||||
}
|
||||
return $construct->result;
|
||||
$page_arr = array();
|
||||
for ($i=0; $i<=$construct->pages; $i++)
|
||||
if ($construct->page != $i)
|
||||
array_push($page_arr,$i);
|
||||
|
||||
# Page array for menu
|
||||
$smarty->assign('page_arr',$page_arr);
|
||||
|
||||
if(isset($construct->trigger[$type])) {
|
||||
include_once(PATH_CORE.'trigger.inc.php');
|
||||
$trigger = new CORE_trigger;
|
||||
|
||||
$trigger->trigger($construct->trigger[$type],1,$VAR);
|
||||
}
|
||||
|
||||
return $construct->result;
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
Reference in New Issue
Block a user