/**
 * 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/ 
 *
 * @link http://www.agileco.com/
 * @copyright 2004-2008 Agileco, LLC.
 * @license http://www.agileco.com/agilebill/license1-4.txt
 * @author Tony Landis <*****@*****.**> 
 * @package AgileBill
 * @version 1.4.93
 */
function CORE_database_search_form($VAR, $construct, $type)
{
    global $C_translate, $smarty;
    # set the field list for this method:
    $arr = $construct->method[$type];
    # loop through the field list to create the order_by list
    $field_list = '';
    $i = 0;
    while (list($key, $value) = each($arr)) {
        $field_list["{$i}"]['translate'] = $C_translate->translate('field_' . $value, $construct->module, "");
        $field_list["{$i}"]['field'] = $value;
        $i++;
    }
    # define the field list as a Smarty accessible array
    $smarty->assign($construct->module, $field_list);
    # define the default ORDER BY field
    $smarty->assign($construct->module . '_order_by', $construct->order_by);
    # define the default LIMIT count
    $smarty->assign($construct->module . '_limit', $construct->limit);
    # define the recent search menu & javascript
    include_once PATH_CORE . 'search.inc.php';
    $search = new CORE_search();
    # build the RECENT SEARCH menu & JS
    $search->build_recent($construct->module);
    # send the RECENT SEARCH menu to Smarty
    $smarty->assign($construct->module . "_recent_menu", $search->recent_menu);
    # send the finished RECENT SEARCH JavaScript to Smarty
    $smarty->assign($construct->module . "_recent_js", $search->recent_js);
    # build the SAVED SEARCH menu & JS
    $search->build_saved($construct->module);
    # send the SAVED SEARCH menu to Smarty
    $smarty->assign($construct->module . "_saved_menu", $search->saved_menu);
    # send the finished SAVED SEARCH JavaScript to Smarty
    $smarty->assign($construct->module . "_saved_js", $search->saved_js);
}
示例#2
0
 function search($VAR)
 {
     ### Read the contents of the /plugins/affiliate directory:
     $count = 0;
     chdir(PATH_PLUGINS . 'import');
     $dir = opendir(PATH_PLUGINS . 'import');
     while ($file_name = readdir($dir)) {
         if ($file_name != '..' && $file_name != '.' && !preg_match("/^_/", $file_name) && preg_match("/.php\$/i", $file_name)) {
             $count++;
         }
     }
     # define the DB vars as a Smarty accessible block
     global $smarty;
     # create the search record:
     if ($count > 0) {
         # create the search record
         include_once PATH_CORE . 'search.inc.php';
         $search = new CORE_search();
         $arr['module'] = $this->module;
         $arr['sql'] = '';
         $arr['limit'] = '999';
         $arr['order_by'] = 'name';
         $arr['results'] = $count;
         $search->add($arr);
         # define the search id and other parameters for Smarty
         $smarty->assign('search_id', $search->id);
         # page:
         $smarty->assign('page', '1');
         # limit:
         $smarty->assign('limit', '999');
         # order_by:
         $smarty->assign('order_by', 'name');
         # define the result count
         $smarty->assign('results', $count);
     }
 }
示例#3
0
 function search_show($VAR)
 {
     $this->charge_construct();
     $type = "search";
     $this->method["{$type}"] = explode(",", $this->method["{$type}"]);
     # set the field list for this method:
     $arr = $this->method[$type];
     $field_list = '';
     $i = 0;
     while (list($key, $value) = each($arr)) {
         if ($i == 0) {
             $field_var = $this->table . '_' . $value;
             $field_list .= AGILE_DB_PREFIX . "charge" . "." . $value;
             // determine if this record is linked to another table/field
             if ($this->field[$value]["asso_table"] != "") {
                 $this->linked[] = array('field' => $value, 'link_table' => $this->field[$value]["asso_table"], 'link_field' => $this->field[$value]["asso_field"]);
             }
         } else {
             $field_var = $this->table . '_' . $value;
             $field_list .= "," . AGILE_DB_PREFIX . "charge" . "." . $value;
             // determine if this record is linked to another table/field
             if ($this->field[$value]["asso_table"] != "") {
                 $this->linked[] = array('field' => $value, 'link_table' => $this->field[$value]["asso_table"], 'link_field' => $this->field[$value]["asso_field"]);
             }
         }
         $i++;
     }
     # 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!';
         # translate... # alert
         if (isset($this->trigger["{$type}"])) {
             include_once PATH_CORE . 'trigger.inc.php';
             $trigger = new CORE_trigger();
             $trigger->trigger($this->trigger["{$type}"], 0, $VAR);
         }
     }
     # 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 ' . $this->order_by;
         $smarty_order = $search->order_by;
     }
     # determine the sort order
     if (isset($VAR['desc'])) {
         $order_by .= ' DESC';
         $smarty_sort = 'desc=';
     } else {
         if (isset($VAR['asc'])) {
             $order_by .= ' ASC';
             $smarty_sort = 'asc=';
         } else {
             if (!eregi('date', $smarty_order)) {
                 $order_by .= ' ASC';
                 $smarty_sort = 'asc=';
             } else {
                 $order_by .= ' DESC';
                 $smarty_sort = 'desc=';
             }
         }
     }
     # 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 = " . $db->qstr(DEFAULT_SITE);
     $q .= $order_by;
     //////////////////
     # echo "<BR> $q <BR>";
     $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);
     # error reporting
     if ($result === false) {
         global $C_debug;
         $C_debug->error('charge.inc.php', 'search', $db->ErrorMsg());
         if (isset($this->trigger["{$type}"])) {
             include_once PATH_CORE . 'trigger.inc.php';
             $trigger = new CORE_trigger();
             $trigger->trigger($this->trigger["{$type}"], 0, $VAR);
         }
         return;
     }
     # put the results into a smarty accessable array
     $i = 0;
     $class_name = TRUE;
     while (!$result->EOF) {
         $smart[$i] = $result->fields;
         if ($class_name) {
             $smart[$i]['_C'] = 'row1';
             $class_name = FALSE;
         } else {
             $smart[$i]['_C'] = 'row2';
             $class_name = TRUE;
         }
         $result->MoveNext();
         $i++;
     }
     # get any linked fields
     if ($i > 0) {
         $db_join = new CORE_database();
         $this->result = $db_join->join_fields($smart, $this->linked);
     } else {
         $this->result = $smart;
     }
     # get the result count:
     $results = $result->RecordCount();
     # define the DB vars as a Smarty accessible block
     global $smarty;
     # define the results
     $smarty->assign($this->table, $this->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);
     # get the total pages for this search:
     if (empty($search->limit)) {
         $this->pages = 1;
     } else {
         $this->pages = intval($search->results / $search->limit);
     }
     if ($search->results % $search->limit) {
         $this->pages++;
     }
     # total pages
     $smarty->assign('pages', $this->pages);
     # current page
     $smarty->assign('page', $current_page);
     $page_arr = '';
     for ($i = 0; $i <= $this->pages; $i++) {
         if ($this->page != $i) {
             $page_arr[] = $i;
         }
     }
     # page array for menu
     $smarty->assign('page_arr', $page_arr);
 }
/**
 * 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/ 
 *
 * @link http://www.agileco.com/
 * @copyright 2004-2008 Agileco, LLC.
 * @license http://www.agileco.com/agilebill/license1-4.txt
 * @author Tony Landis <*****@*****.**> 
 * @package AgileBill
 * @version 1.4.93
 */
function CORE_database_search($VAR, &$construct, $type)
{
    $db =& DB();
    include_once PATH_CORE . 'validate.inc.php';
    $validate = new CORE_validate();
    # set the search criteria array
    $arr = $VAR;
    # loop through the submitted field_names to get the WHERE statement
    $where_list = '';
    $i = 0;
    while (list($key, $value) = each($arr)) {
        if ($i == 0) {
            if ($value != '') {
                $pat = "^" . $construct->module . "_";
                if (preg_match('/' . $pat . '/i', $key)) {
                    $field = preg_replace('/' . $pat . '/i', "", $key);
                    if (preg_match('/%/', $value)) {
                        # do any data conversion for this field (date, encrypt, etc...)
                        if (isset($construct->field["{$field}"]["convert"])) {
                            $value = $validate->convert($field, $value, $construct->field["{$field}"]["convert"]);
                        }
                        $where_list .= " WHERE " . $field . " LIKE " . $db->qstr($value, get_magic_quotes_gpc());
                        $i++;
                    } else {
                        # check if array
                        if (is_array($value)) {
                            for ($i_arr = 0; $i_arr < count($value); $i_arr++) {
                                if ($value["{$i_arr}"] != '') {
                                    # determine any field options (=, >, <, etc...)
                                    $f_opt = '=';
                                    $pat_field = $construct->module . '_' . $field;
                                    $VAR['field_option']["{$pat_field}"]["{$i_arr}"];
                                    if (isset($VAR['field_option']["{$pat_field}"]["{$i_arr}"])) {
                                        $f_opt = $VAR['field_option']["{$pat_field}"]["{$i_arr}"];
                                        # error checking, safety precaution
                                        if ($f_opt != '=' && $f_opt != '>' && $f_opt != '<' && $f_opt != '>=' && $f_opt != '<=' && $f_opt != '!=') {
                                            $f_opt = '=';
                                        }
                                    }
                                    # do any data conversion for this field (date, encrypt, etc...)
                                    if (isset($construct->field["{$field}"]["convert"])) {
                                        $value["{$i_arr}"] = $validate->convert($field, $value["{$i_arr}"], $construct->field["{$field}"]["convert"]);
                                    }
                                    if ($i_arr == 0) {
                                        $where_list .= " WHERE " . $field . " {$f_opt} " . $db->qstr($value["{$i_arr}"], get_magic_quotes_gpc());
                                        $i++;
                                    } else {
                                        $where_list .= " AND " . $field . " {$f_opt} " . $db->qstr($value["{$i_arr}"], get_magic_quotes_gpc());
                                        $i++;
                                    }
                                }
                            }
                        } else {
                            $where_list .= " WHERE " . $field . " = " . $db->qstr($value, get_magic_quotes_gpc());
                            $i++;
                        }
                    }
                }
            }
        } else {
            if ($value != '') {
                $pat = "^" . $construct->module . "_";
                if (preg_match('/' . $pat . '/', $key)) {
                    $field = preg_replace('/' . $pat . '/i', "", $key);
                    if (preg_match('/%/', $value)) {
                        # do any data conversion for this field (date, encrypt, etc...)
                        if (isset($construct->field["{$field}"]["convert"])) {
                            $value = $validate->convert($field, $value, $construct->field["{$field}"]["convert"]);
                        }
                        $where_list .= " AND " . $field . " LIKE " . $db->qstr($value, get_magic_quotes_gpc());
                        $i++;
                    } else {
                        # check if array
                        if (is_array($value)) {
                            for ($i_arr = 0; $i_arr < count($value); $i_arr++) {
                                if ($value["{$i_arr}"] != '') {
                                    # determine any field options (=, >, <, etc...)
                                    $f_opt = '=';
                                    $pat_field = $construct->module . '_' . $field;
                                    if (isset($VAR['field_option']["{$pat_field}"]["{$i_arr}"])) {
                                        $f_opt = $VAR['field_option']["{$pat_field}"]["{$i_arr}"];
                                        # error checking, safety precaution
                                        if ($f_opt != '=' && $f_opt != '>' && $f_opt != '<' && $f_opt != '>=' && $f_opt != '<=' && $f_opt != '!=') {
                                            $f_opt = '=';
                                        }
                                    }
                                    # do any data conversion for this field (date, encrypt, etc...)
                                    if (isset($construct->field["{$field}"]["convert"])) {
                                        $value["{$i_arr}"] = $validate->convert($field, $value["{$i_arr}"], $construct->field["{$field}"]["convert"]);
                                    }
                                    $where_list .= " AND " . $field . " {$f_opt} " . $db->qstr($value["{$i_arr}"], get_magic_quotes_gpc());
                                    $i++;
                                }
                            }
                        } else {
                            $where_list .= " AND " . $field . " = " . $db->qstr($value, get_magic_quotes_gpc());
                            $i++;
                        }
                    }
                }
            }
        }
    }
    #### finalize the WHERE statement
    if ($where_list == '') {
        $where_list .= ' WHERE ';
    } else {
        $where_list .= ' AND ';
    }
    # get limit type
    if (isset($VAR['limit'])) {
        $limit = $VAR['limit'];
    } else {
        $limit = $construct->limit;
    }
    # get order by
    if (isset($VAR['order_by'])) {
        $order_by = $VAR['order_by'];
    } else {
        $order_by = $construct->order_by;
    }
    ### Get any addition fields to select:
    if (isset($construct->custom_EXP)) {
        for ($ei = 0; $ei < count($construct->custom_EXP); $ei++) {
            if ($ei == 0) {
                $field_list = "," . $construct->custom_EXP[$ei]['field'];
            }
        }
    }
    # generate the full query
    $q = "SELECT id" . $field_list . " FROM\n\t\t " . AGILE_DB_PREFIX . "{$construct->table}\n\t\t {$where_list}\n\t\t site_id = '" . DEFAULT_SITE . "'";
    $q_save = "SELECT %%fieldList%% FROM %%tableList%% " . $where_list . " %%whereList%% ";
    $result = $db->Execute($q);
    //////////////// DEBUG ////
    #echo "<PRE>$q</PRE>";
    #exit;
    # error reporting
    if ($result === false) {
        global $C_debug;
        $C_debug->error('database.inc.php', 'search', $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);
        }
        return;
    }
    # get the result count:
    $results = $result->RecordCount();
    # get the first record id:
    if ($results == 1) {
        $record_id = $result->fields['id'];
    }
    ### Run any custom validation on this result for
    ### this module
    if (isset($construct->custom_EXP)) {
        $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) {
                    //$result->MoveNext();
                    $ei = count($construct->custom_EXP);
                    $results++;
                }
            }
            $result->MoveNext();
        }
    }
    # define the DB vars as a Smarty accessible block
    global $smarty;
    # Create the definition for fast-forwarding to a single record:
    if ($results == 1 && !isset($construct->fast_forward)) {
        $smarty->assign('record_id', $record_id);
    }
    # create the search record:
    if ($results > 0) {
        # create the search record
        include_once PATH_CORE . 'search.inc.php';
        $search = new CORE_search();
        $arr['module'] = $construct->module;
        $arr['sql'] = $q_save;
        $arr['limit'] = $limit;
        $arr['order_by'] = $order_by;
        $arr['results'] = $results;
        $search->add($arr);
        # define the search id and other parameters for Smarty
        $smarty->assign('search_id', $search->id);
        # page:
        $smarty->assign('page', '1');
        # limit:
        $smarty->assign('limit', $limit);
        # order_by:
        $smarty->assign('order_by', $order_by);
    }
    # define the result count
    $smarty->assign('results', $results);
    if (isset($construct->trigger["{$type}"])) {
        include_once PATH_CORE . 'trigger.inc.php';
        $trigger = new CORE_trigger();
        $trigger->trigger($construct->trigger["{$type}"], 1, $VAR);
    }
}
/**
 * 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/ 
 *
 * @link http://www.agileco.com/
 * @copyright 2004-2008 Agileco, LLC.
 * @license http://www.agileco.com/agilebill/license1-4.txt
 * @author Tony Landis <*****@*****.**> 
 * @package AgileBill
 * @version 1.4.93
 */
function CORE_database_search_show($VAR, &$construct, $type)
{
    # set the field list for this method:
    $arr = $construct->method[$type];
    $field_list = '';
    $i = 0;
    while (list($key, $value) = each($arr)) {
        if ($i == 0) {
            $field_var = $construct->table . '_' . $value;
            $field_list .= AGILE_DB_PREFIX . $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"]);
            }
        } else {
            $field_var = $construct->table . '_' . $value;
            $field_list .= "," . AGILE_DB_PREFIX . $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"]);
            }
        }
        $i++;
    }
    # 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);
        }
    }
    # Check that this search has not been taken over by another account
    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;
    }
    # determine the sort order
    if (isset($VAR['desc'])) {
        $order_by .= ' DESC';
        $smarty_sort = 'desc=';
    } else {
        if (isset($VAR['asc'])) {
            $order_by .= ' ASC';
            $smarty_sort = 'asc=';
        } else {
            if (!preg_match('/date/i', $smarty_order)) {
                $order_by .= ' ASC';
                $smarty_sort = 'asc=';
            } else {
                $order_by .= ' DESC';
                $smarty_sort = 'desc=';
            }
        }
    }
    # generate the full query
    $db =& DB();
    $q = preg_replace("/%%fieldList%%/i", $field_list, $search->sql);
    $q = preg_replace("/%%tableList%%/i", AGILE_DB_PREFIX . $construct->table, $q);
    $q = preg_replace("/%%whereList%%/i", "", $q);
    $q .= " site_id = '" . DEFAULT_SITE . "'";
    $q .= $order_by;
    ///////////////////////
    # 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);
    # error reporting
    if ($result === false) {
        global $C_debug;
        $C_debug->error('database.inc.php', 'search', $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);
        }
        return;
    }
    ### 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) {
                    $smart[$i] = $result->fields;
                    if ($class_name) {
                        $smart[$i]['_C'] = 'row1';
                        $class_name = FALSE;
                    } else {
                        $smart[$i]['_C'] = 'row2';
                        $class_name = TRUE;
                    }
                    $i++;
                    $ei = count($construct->custom_EXP);
                    $results++;
                }
            }
            $result->MoveNext();
        }
    } else {
        $i = 0;
        $class_name = TRUE;
        while (!$result->EOF) {
            $smart[$i] = $result->fields;
            if ($class_name) {
                $smart[$i]['_C'] = 'row1';
                $class_name = FALSE;
            } else {
                $smart[$i]['_C'] = 'row2';
                $class_name = TRUE;
            }
            $result->MoveNext();
            $i++;
        }
    }
    # 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:
    $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_id', $search->id);
    $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);
    # current page
    $smarty->assign('page', $current_page);
    $page_arr = '';
    for ($i = 0; $i <= $construct->pages; $i++) {
        if ($construct->page != $i) {
            $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;
}
示例#6
0
 function search_xml($VAR, $construct, $type)
 {
     /************** BEGIN STANDARD EXPORT SEARCH CODE *********************/
     # set the field list for this method:
     $arr = $construct->method["{$type}"];
     # loop through the field list to create the sql queries
     $arr = $construct->method[$type];
     $field_list = '';
     $i = 0;
     while (list($key, $value) = each($arr)) {
         if ($i == 0) {
             $field_var = $construct->table . '_' . $value;
             $field_list .= AGILE_DB_PREFIX . $construct->table . '.' . $value;
             // determine if this record is linked to another table/field
             if ($construct->field[$value]["asso_table"] != "") {
                 $this->linked[] = array('field' => $value, 'link_table' => $construct->field[$value]["asso_table"], 'link_field' => $construct->field[$value]["asso_field"]);
             }
         } else {
             $field_var = $construct->table . '_' . $value;
             $field_list .= "," . AGILE_DB_PREFIX . $construct->table . "." . $value;
             // determine if this record is linked to another table/field
             if ($construct->field[$value]["asso_table"] != "") {
                 $this->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';
         $search = new CORE_search();
         $search->get($VAR['search_id']);
     } else {
         echo '<BR> The search terms submitted were invalid!';
     }
     # get the sort order details:
     if (isset($VAR['order_by']) && $VAR['order_by'] != "") {
         $order_by = ' ORDER BY ' . AGILE_DB_PREFIX . $construct->table . '.' . $VAR['order_by'];
         $smarty_order = $VAR['order_by'];
     } else {
         $order_by = ' ORDER BY ' . AGILE_DB_PREFIX . $construct->table . '.' . $construct->order_by;
         $smarty_order = $search->order_by;
     }
     # format saved search string
     $sql = explode(" WHERE ", $search->sql);
     # generate the full query
     $q = preg_replace("/%%fieldList%%/i", $field_list, $search->sql);
     $q = preg_replace("/%%tableList%%/i", AGILE_DB_PREFIX . $construct->table, $q);
     $q = preg_replace("/%%whereList%%/i", "", $q);
     $q .= " " . AGILE_DB_PREFIX . $construct->table . ".site_id = '" . DEFAULT_SITE . "'";
     $q .= $order_by;
     $db =& DB();
     $result = $db->Execute($q);
     # error reporting
     if ($result === false) {
         global $C_debug;
         $C_debug->error('core:export.inc.php', 'search_xml', $db->ErrorMsg() . '<br><br>' . $q);
         echo "An SQL error has occured!";
         return;
     }
     # put the results into an array
     $i = 0;
     $class_name = TRUE;
     $results = '';
     while (!$result->EOF) {
         $results[$i] = $result->fields;
         $result->MoveNext();
         $i++;
     }
     # get any linked fields
     if ($i > 0) {
         $this->result = $results;
         $db_join = new CORE_database();
         $this->result = $db_join->join_fields($results, $this->linked);
     } else {
         $this->result = $results;
     }
     /************** END STANDARD EXPORT SEARCH CODE *********************/
     # create the xml processing instruction
     # header("Content-type: text/xml");
     $filename = 'XML_Export.xml';
     # determine what action to take:
     if ($VAR["type"] == "display") {
         header('Content-type: application/x-xml');
         header("Content-Disposition: inline; filename={$filename}");
     } else {
         if ($VAR["type"] == "download") {
             header("Content-Disposition: attachment; filename={$filename}");
         }
     }
     $_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
     $_xml .= "<results>\r\n";
     # loop through the resulsts and display as PDF
     $row = 0;
     for ($ii = 0; $ii < count($this->result); $ii++) {
         $_xml .= "\t<" . $construct->table . ">\r\n";
         # get the data for each cell:
         reset($arr);
         $column = 0;
         while (list($key, $value) = each($arr)) {
             if ($construct->field["{$value}"][convert] == 'date' || $construct->field["{$value}"][convert] == 'time' || $construct->field["{$value}"][convert] == 'date-now' || $construct->field["{$value}"][convert] == 'date-time') {
                 $date = date(UNIX_DATE_FORMAT, $this->result["{$ii}"]["{$value}"]);
                 $data = htmlspecialchars($date, 0, 'ISO8859-1');
                 //$data = test;
             } else {
                 $data = htmlspecialchars($this->result["{$ii}"]["{$value}"], 0, 'ISO8859-1');
             }
             $_xml .= "\t\t<{$value}>" . $data . "</{$value}>\r\n";
         }
         # Next record
         $_xml .= "\t</" . $construct->table . ">\r\n";
     }
     $_xml .= "</results>\r\n";
     echo $_xml;
     exit;
 }