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 Search Class
|
|
|
|
*
|
|
|
|
* @package AgileBill
|
|
|
|
* @subpackage Core
|
|
|
|
*/
|
|
|
|
class CORE_search {
|
|
|
|
public $recent_js;
|
|
|
|
public $recent_menu;
|
|
|
|
public $saved_js;
|
|
|
|
public $saved_menu;
|
2008-11-26 22:50:40 +00:00
|
|
|
|
|
|
|
/**
|
2009-08-03 04:10:16 +00:00
|
|
|
* 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();
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Determine the search id:
|
|
|
|
$this->id = $db->GenID(AGILE_DB_PREFIX.'search_id');
|
|
|
|
|
|
|
|
# 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));
|
|
|
|
|
|
|
|
# Error reporting
|
|
|
|
if ($result === false) {
|
2008-11-26 22:50:40 +00:00
|
|
|
global $C_debug;
|
2009-08-03 04:10:16 +00:00
|
|
|
|
|
|
|
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-03 04:10:16 +00:00
|
|
|
* 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
|
2008-11-26 22:50:40 +00:00
|
|
|
$db = &DB();
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
$result = $db->Execute(sqlSelect($db,'search','*',sprintf('id=%s',$id)));
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Error reporting
|
|
|
|
if ($result === false) {
|
|
|
|
global $C_debug;
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
|
|
|
|
}
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# 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);
|
2008-11-26 22:50:40 +00:00
|
|
|
# echo "<BR> this search has expired! Refreshing.... <BR>";
|
2009-08-03 04:10:16 +00:00
|
|
|
$this->results = $result->fields['results'];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
# Use the existing result count
|
|
|
|
$this->results = $result->fields['results'];
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
2009-08-03 04:10:16 +00:00
|
|
|
|
2008-11-26 22:50:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-03 04:10:16 +00:00
|
|
|
* 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
|
2008-11-26 22:50:40 +00:00
|
|
|
*/
|
2009-08-03 04:10:16 +00:00
|
|
|
private function refresh($id) {
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-03 04:10:16 +00:00
|
|
|
* 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
|
2008-11-26 22:50:40 +00:00
|
|
|
$db = &DB();
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Determine the search id:
|
2008-11-26 22:50:40 +00:00
|
|
|
$this->id = $db->GenID('search_saved');
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
$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));
|
|
|
|
|
|
|
|
# Error reporting
|
|
|
|
if ($result === false) {
|
2008-11-26 22:50:40 +00:00
|
|
|
global $C_debug;
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
|
|
|
|
}
|
|
|
|
}
|
2008-11-26 22:50:40 +00:00
|
|
|
|
|
|
|
/**
|
2009-08-03 04:10:16 +00:00
|
|
|
* 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
|
2008-11-26 22:50:40 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(isset($this->arr)) unset ($this->arr);
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Get the recent searches
|
2008-11-26 22:50:40 +00:00
|
|
|
$db = &DB();
|
|
|
|
$q = "SELECT id, date_orig, date_expire, full_sql, order_by, limit_no
|
|
|
|
FROM " . AGILE_DB_PREFIX . "search
|
|
|
|
WHERE
|
|
|
|
session_id = '" . SESS . "'
|
|
|
|
OR
|
|
|
|
account_id = '" . SESS_ACCOUNT . "'
|
|
|
|
AND
|
|
|
|
module = '$module'
|
|
|
|
AND
|
|
|
|
date_expire >= '" . time() . "'
|
|
|
|
AND
|
|
|
|
site_id = '" . DEFAULT_SITE . "'";
|
|
|
|
$result = $db->Execute($q);
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Error reporting
|
2008-11-26 22:50:40 +00:00
|
|
|
if ($result === false)
|
|
|
|
{
|
|
|
|
global $C_debug;
|
2009-08-03 04:10:16 +00:00
|
|
|
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$results = $result->RecordCount();
|
|
|
|
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
while (!$result->EOF) {
|
2009-08-03 04:10:16 +00:00
|
|
|
# Get the fields for this loop
|
2008-11-26 22:50:40 +00:00
|
|
|
$sql = $result->fields['full_sql'];
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Remove the WHERE
|
2008-11-26 22:50:40 +00:00
|
|
|
$sql = trim($sql);
|
|
|
|
$sql = eregi_replace("WHERE","",$sql);
|
|
|
|
$sql = eregi_replace("AND$","",$sql);
|
|
|
|
$sql = trim($sql);
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Replace any sql statements before we split the string
|
2008-11-26 22:50:40 +00:00
|
|
|
$sql = ereg_replace(" = ","===",$sql);
|
|
|
|
$sql = ereg_replace(" LIKE ","===",$sql);
|
|
|
|
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Determine the number of fields
|
2008-11-26 22:50:40 +00:00
|
|
|
|
|
|
|
$ii=0;
|
|
|
|
if(ereg(" AND ", $sql))
|
|
|
|
{
|
2009-03-28 05:20:19 +00:00
|
|
|
$sql = explode(" AND ",$sql);
|
2008-11-26 22:50:40 +00:00
|
|
|
$this_fields = count($sql);
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Loop
|
2008-11-26 22:50:40 +00:00
|
|
|
for($count=0; $count < $this_fields; $count++)
|
|
|
|
{
|
2009-08-03 04:10:16 +00:00
|
|
|
# Do each field
|
2009-03-28 05:20:19 +00:00
|
|
|
$sqls = explode("==",$sql[$count]);
|
2008-11-26 22:50:40 +00:00
|
|
|
$field[$count][name] = $sqls[0];
|
|
|
|
$field[$count][value] = ereg_replace("'","",$sqls[1]);
|
|
|
|
$field[$count][value] = ereg_replace("=","",$field[$count][value]);
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Check that the name & value are both set...
|
2008-11-26 22:50:40 +00:00
|
|
|
if($field[$count][value] != '' && $field[$count][name] != '')
|
|
|
|
{
|
|
|
|
if(!isset($this->arr[$i][$ii][limit]))
|
|
|
|
{
|
|
|
|
$this->arr[$i][$ii][search] = $result->fields['id'];
|
|
|
|
$this->arr[$i][$ii][limit] = $result->fields['limit_no'];
|
|
|
|
$this->arr[$i][$ii][order] = $result->fields['order_by'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->arr[$i][$ii][0] = $field[$count][name];
|
|
|
|
$this->arr[$i][$ii][1] = $field[$count][value];
|
|
|
|
|
|
|
|
# echo "<BR><BR>Field/Name: " . $this->arr[$i][$ii][0] . " -> " . $this->arr[$i][$ii][1];
|
|
|
|
$ii++;
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Set the menu up for Smarty
|
2008-11-26 22:50:40 +00:00
|
|
|
$this->recent_menu[$i] = $result->fields;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-03 04:10:16 +00:00
|
|
|
# Field count
|
2008-11-26 22:50:40 +00:00
|
|
|
$this_fields = 1;
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Do this one field
|
2009-03-28 05:20:19 +00:00
|
|
|
$sqls = explode("==",$sql);
|
2008-11-26 22:50:40 +00:00
|
|
|
$field[name] = $sqls[0];
|
|
|
|
$field[value] = ereg_replace("'","",$sqls[1]);
|
|
|
|
$field[value] = ereg_replace("=","",$field[value]);
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Check that the name & value are both set...
|
2008-11-26 22:50:40 +00:00
|
|
|
if($field[value] != '' && $field[name] != '')
|
|
|
|
{
|
|
|
|
if(!isset($this->arr[$i][$ii][limit]))
|
|
|
|
{
|
|
|
|
$this->arr[$i][$ii][search] = $result->fields['id'];
|
|
|
|
$this->arr[$i][$ii][limit] = $result->fields['limit_no'];
|
|
|
|
$this->arr[$i][$ii][order] = $result->fields['order_by'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->arr[$i][$ii][0] = $field[name];
|
|
|
|
$this->arr[$i][$ii][1] = $field[value];
|
|
|
|
|
|
|
|
# echo "<BR><BR>Field/Name: " . $field[name] . " -> " . $field[value];
|
|
|
|
$ii++;
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Set the menu up for Smarty
|
2008-11-26 22:50:40 +00:00
|
|
|
$this->recent_menu[$i] = $result->fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Continue loop
|
2008-11-26 22:50:40 +00:00
|
|
|
$result->MoveNext();
|
|
|
|
if ($ii > 0) $i++;
|
|
|
|
}
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Finish the JS:
|
2008-11-26 22:50:40 +00:00
|
|
|
if($i > 0 && $ii > 0)
|
|
|
|
{
|
2009-08-03 04:10:16 +00:00
|
|
|
# Build the JavaScript
|
2008-11-26 22:50:40 +00:00
|
|
|
$this->recent_js = '
|
2009-08-03 04:10:16 +00:00
|
|
|
<script language="JavaScript">
|
2008-11-26 22:50:40 +00:00
|
|
|
|
|
|
|
// SEARCH FORM CONTROLLER
|
|
|
|
function fill_search_recent(mod,fields,field_count,limit,order,s,c)
|
|
|
|
{
|
|
|
|
document.search.reset();
|
|
|
|
var id = document.search_recent.search_id.selectedIndex;
|
|
|
|
if(id == 0) return "";
|
2009-08-03 04:10:16 +00:00
|
|
|
var idx = document.search_recent.search_id.options[id].value;
|
2008-11-26 22:50:40 +00:00
|
|
|
for(loop=0; loop <= c; loop++)
|
|
|
|
{
|
2009-08-03 04:10:16 +00:00
|
|
|
if(s[loop] == idx)
|
2008-11-26 22:50:40 +00:00
|
|
|
{
|
|
|
|
var i = loop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
document.search.limit.value = limit[i];
|
2009-08-03 04:10:16 +00:00
|
|
|
document.search.order_by.value = order[i];
|
2008-11-26 22:50:40 +00:00
|
|
|
for(loop=0; loop < field_count[i]; loop++)
|
|
|
|
{
|
|
|
|
var fill = "document.search." + mod + "_" + fields[i][loop][0] + ".value = fields[i][loop][1];"
|
|
|
|
eval(fill);
|
2009-08-03 04:10:16 +00:00
|
|
|
}
|
|
|
|
}';
|
2008-11-26 22:50:40 +00:00
|
|
|
|
|
|
|
$this->recent_js .= "
|
|
|
|
var mod = '$module';
|
|
|
|
var c = $i;
|
|
|
|
var fields = new Array($i);
|
|
|
|
var limit = new Array($i);
|
|
|
|
var order = new Array($i);
|
|
|
|
var field_count = new Array($i);
|
|
|
|
var s = new Array($i);
|
|
|
|
";
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Loop through the searches
|
2008-11-26 22:50:40 +00:00
|
|
|
for ($ix = 0; $ix <= count($this->arr); $ix++)
|
|
|
|
{
|
2009-08-03 04:10:16 +00:00
|
|
|
# Loop through the fields
|
2008-11-26 22:50:40 +00:00
|
|
|
for ($iix = 0; $iix <= count($this->arr[$ix]); $iix++)
|
|
|
|
{
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Check that the name/value is set...
|
2008-11-26 22:50:40 +00:00
|
|
|
if( $this->arr[$ix][$iix][0] != "" && $this->arr[$ix][$iix][1] != "")
|
|
|
|
{
|
|
|
|
$count = count($this->arr[$ix]);
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Setup the arrays:
|
2008-11-26 22:50:40 +00:00
|
|
|
if($iix==0)
|
|
|
|
{
|
|
|
|
$this->recent_js .= "
|
|
|
|
s[$ix] = '" . $this->arr[$ix][$iix][search] . "';
|
|
|
|
limit[$ix] = '" . $this->arr[$ix][$iix][limit] . "';
|
|
|
|
order[$ix] = '" . $this->arr[$ix][$iix][order] . "';
|
|
|
|
field_count[$ix]= '" . $count . "';
|
|
|
|
fields[$ix] = new Array(field_count[$ix]);
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Set the field settings
|
2008-11-26 22:50:40 +00:00
|
|
|
$this->recent_js .=
|
|
|
|
"
|
|
|
|
fields[$ix][$iix] = new Array(2);
|
|
|
|
fields[$ix][$iix][0] = '" . $this->arr[$ix][$iix][0] . "';
|
|
|
|
fields[$ix][$iix][1] = '" . $this->arr[$ix][$iix][1] . "';
|
|
|
|
";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Finish the js
|
2008-11-26 22:50:40 +00:00
|
|
|
$this->recent_js .= "
|
|
|
|
</script>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->recent_js = FALSE;
|
|
|
|
}
|
2009-08-03 04:10:16 +00:00
|
|
|
} # End of functino
|
2008-11-26 22:50:40 +00:00
|
|
|
|
|
|
|
/**
|
2009-08-03 04:10:16 +00:00
|
|
|
* 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
|
2008-11-26 22:50:40 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(isset($this->arr)) unset ($this->arr);
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Get the saved searches
|
|
|
|
# Get the recent searches
|
2008-11-26 22:50:40 +00:00
|
|
|
$db1 = &DB();
|
|
|
|
$q = "SELECT id, search_id, name
|
|
|
|
FROM " . AGILE_DB_PREFIX . "search_saved
|
|
|
|
WHERE
|
|
|
|
session_id = '" . SESS . "'
|
|
|
|
OR
|
|
|
|
account_id = '" . SESS_ACCOUNT . "'
|
|
|
|
AND
|
|
|
|
module = '$module'
|
|
|
|
AND
|
|
|
|
site_id = '" . DEFAULT_SITE . "'
|
|
|
|
ORDER BY name ASC";
|
|
|
|
$result1 = $db1->Execute($q);
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Error reporting
|
2008-11-26 22:50:40 +00:00
|
|
|
if ($result1 === false)
|
|
|
|
{
|
|
|
|
global $C_debug;
|
|
|
|
$C_debug->sql_error($db1->ErrorMsg());
|
|
|
|
}
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
$i=0;
|
|
|
|
while (!$result1->EOF)
|
|
|
|
{
|
|
|
|
# Get the information for this search
|
2008-11-26 22:50:40 +00:00
|
|
|
$db = &DB();
|
|
|
|
$q = "SELECT id, full_sql, order_by, limit_no
|
|
|
|
FROM " . AGILE_DB_PREFIX . "search
|
|
|
|
WHERE
|
|
|
|
id = '" . $result1->fields['search_id'] . "'
|
|
|
|
AND
|
|
|
|
site_id = '" . DEFAULT_SITE . "'";
|
|
|
|
$result = $db->Execute($q);
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Error reporting
|
2008-11-26 22:50:40 +00:00
|
|
|
if ($result === false)
|
|
|
|
{
|
|
|
|
global $C_debug;
|
2009-08-03 04:10:16 +00:00
|
|
|
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Get the fields for this loop
|
2008-11-26 22:50:40 +00:00
|
|
|
$sql = $result->fields['full_sql'];
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Remove the WHERE
|
2008-11-26 22:50:40 +00:00
|
|
|
$sql = trim($sql);
|
|
|
|
$sql = eregi_replace("WHERE","",$sql);
|
|
|
|
$sql = eregi_replace("AND$","",$sql);
|
|
|
|
$sql = trim($sql);
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Replace any sql statements before we split the string
|
2008-11-26 22:50:40 +00:00
|
|
|
$sql = ereg_replace(" = ","===",$sql);
|
|
|
|
$sql = ereg_replace(" LIKE ","===",$sql);
|
|
|
|
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Determine the number of fields
|
2008-11-26 22:50:40 +00:00
|
|
|
|
|
|
|
$ii=0;
|
|
|
|
if(ereg(" AND ", $sql))
|
|
|
|
{
|
2009-03-28 05:20:19 +00:00
|
|
|
$sql = explode(" AND ",$sql);
|
2008-11-26 22:50:40 +00:00
|
|
|
$this_fields = count($sql);
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Loop
|
2008-11-26 22:50:40 +00:00
|
|
|
for($count=0; $count < $this_fields; $count++)
|
|
|
|
{
|
2009-08-03 04:10:16 +00:00
|
|
|
# Do each field
|
2009-03-28 05:20:19 +00:00
|
|
|
$sqls = explode("==",$sql[$count]);
|
2008-11-26 22:50:40 +00:00
|
|
|
$field[$count][name] = $sqls[0];
|
|
|
|
$field[$count][value] = ereg_replace("'","",$sqls[1]);
|
|
|
|
$field[$count][value] = ereg_replace("=","",$field[$count][value]);
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Check that the name & value are both set...
|
2008-11-26 22:50:40 +00:00
|
|
|
if($field[$count][value] != '' && $field[$count][name] != '')
|
|
|
|
{
|
|
|
|
if(!isset($this->arr[$i][$ii][limit]))
|
|
|
|
{
|
|
|
|
$this->arr[$i][$ii][search] = $result->fields['id'];
|
|
|
|
$this->arr[$i][$ii][limit] = $result->fields['limit_no'];
|
|
|
|
$this->arr[$i][$ii][order] = $result->fields['order_by'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->arr[$i][$ii][0] = $field[$count][name];
|
|
|
|
$this->arr[$i][$ii][1] = $field[$count][value];
|
|
|
|
|
|
|
|
# echo "<BR><BR>Field/Name: " . $this->arr[$i][$ii][0] . " -> " . $this->arr[$i][$ii][1];
|
|
|
|
$ii++;
|
|
|
|
$this->saved_menu[$i] = $result->fields;
|
|
|
|
$this->saved_menu[$i]["name"] = $result1->fields["name"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-03 04:10:16 +00:00
|
|
|
# Field count
|
2008-11-26 22:50:40 +00:00
|
|
|
$this_fields = 1;
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Do this one field
|
2009-03-28 05:20:19 +00:00
|
|
|
$sqls = explode("==",$sql);
|
2008-11-26 22:50:40 +00:00
|
|
|
$field[name] = $sqls[0];
|
|
|
|
$field[value] = ereg_replace("'","",$sqls[1]);
|
|
|
|
$field[value] = ereg_replace("=","",$field[value]);
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Check that the name & value are both set...
|
2008-11-26 22:50:40 +00:00
|
|
|
if($field[value] != '' && $field[name] != '')
|
|
|
|
{
|
|
|
|
if(!isset($this->arr[$i][$ii][limit]))
|
|
|
|
{
|
|
|
|
$this->arr[$i][$ii][search] = $result->fields['id'];
|
|
|
|
$this->arr[$i][$ii][limit] = $result->fields['limit_no'];
|
|
|
|
$this->arr[$i][$ii][order] = $result->fields['order_by'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->arr[$i][$ii][0] = $field[name];
|
|
|
|
$this->arr[$i][$ii][1] = $field[value];
|
|
|
|
|
|
|
|
# echo "<BR><BR>Field/Name: " . $field[name] . " -> " . $field[value];
|
|
|
|
$ii++;
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Set the menu up for Smarty
|
2008-11-26 22:50:40 +00:00
|
|
|
$this->saved_menu[$i] = $result->fields;
|
|
|
|
$this->saved_menu[$i]["name"] = $result1->fields["name"];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2009-08-03 04:10:16 +00:00
|
|
|
$result1->MoveNext();
|
|
|
|
if ($ii > 0) $i++;
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Finish the JS:
|
2008-11-26 22:50:40 +00:00
|
|
|
if($i > 0 && $ii > 0)
|
|
|
|
{
|
2009-08-03 04:10:16 +00:00
|
|
|
# Build the JavaScript
|
2008-11-26 22:50:40 +00:00
|
|
|
$this->saved_js = '
|
2009-08-03 04:10:16 +00:00
|
|
|
<script language="JavaScript">
|
2008-11-26 22:50:40 +00:00
|
|
|
|
|
|
|
// SEARCH FORM CONTROLLER
|
|
|
|
function fill_search_saved(s_mod,s_fields,s_field_count,s_limit,s_order,s_s,s_c)
|
|
|
|
{
|
|
|
|
document.search.reset();
|
|
|
|
var id = document.search_saved.search_id.selectedIndex;
|
|
|
|
if(id == 0) return "";
|
2009-08-03 04:10:16 +00:00
|
|
|
var idx = document.search_saved.search_id.options[id].value;
|
2008-11-26 22:50:40 +00:00
|
|
|
for(loop=0; loop <= s_c; loop++)
|
|
|
|
{
|
2009-08-03 04:10:16 +00:00
|
|
|
if(s_s[loop] == idx)
|
2008-11-26 22:50:40 +00:00
|
|
|
{
|
2009-08-03 04:10:16 +00:00
|
|
|
var i = loop;
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
document.search.limit.value = s_limit[i];
|
2009-08-03 04:10:16 +00:00
|
|
|
document.search.order_by.value = s_order[i];
|
2008-11-26 22:50:40 +00:00
|
|
|
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);
|
|
|
|
}
|
2009-08-03 04:10:16 +00:00
|
|
|
}';
|
2008-11-26 22:50:40 +00:00
|
|
|
|
|
|
|
$this->saved_js .= "
|
|
|
|
var s_mod = '$module';
|
|
|
|
var s_c = $i;
|
|
|
|
var s_fields = new Array($i);
|
|
|
|
var s_limit = new Array($i);
|
|
|
|
var s_order = new Array($i);
|
|
|
|
var s_field_count = new Array($i);
|
|
|
|
var s_s = new Array($i);
|
|
|
|
";
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Loop through the searches
|
2008-11-26 22:50:40 +00:00
|
|
|
for ($ix = 0; $ix <= count($this->arr); $ix++)
|
|
|
|
{
|
2009-08-03 04:10:16 +00:00
|
|
|
# Loop through the fields
|
2008-11-26 22:50:40 +00:00
|
|
|
for ($iix = 0; $iix <= count($this->arr[$ix]); $iix++)
|
|
|
|
{
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Check that the name/value is set...
|
2008-11-26 22:50:40 +00:00
|
|
|
if( $this->arr[$ix][$iix][0] != "" && $this->arr[$ix][$iix][1] != "")
|
|
|
|
{
|
|
|
|
$count = count($this->arr[$ix]);
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Setup the arrays:
|
2008-11-26 22:50:40 +00:00
|
|
|
if($iix==0)
|
|
|
|
{
|
|
|
|
$this->saved_js .= "
|
|
|
|
s_s[$ix] = '" . $this->arr[$ix][$iix][search] . "';
|
|
|
|
s_limit[$ix] = '" . $this->arr[$ix][$iix][limit] . "';
|
|
|
|
s_order[$ix] = '" . $this->arr[$ix][$iix][order] . "';
|
|
|
|
s_field_count[$ix]= '" . $count . "';
|
|
|
|
s_fields[$ix] = new Array(s_field_count[$ix]);
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Set the field settings
|
2008-11-26 22:50:40 +00:00
|
|
|
$this->saved_js .=
|
|
|
|
"
|
|
|
|
s_fields[$ix][$iix] = new Array(2);
|
|
|
|
s_fields[$ix][$iix][0] = '" . $this->arr[$ix][$iix][0] . "';
|
|
|
|
s_fields[$ix][$iix][1] = '" . $this->arr[$ix][$iix][1] . "';
|
|
|
|
";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Finish the js
|
2008-11-26 22:50:40 +00:00
|
|
|
$this->saved_js .= "
|
|
|
|
</script>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->saved_js = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-03 04:10:16 +00:00
|
|
|
?>
|