function check($domain, $tld, $tld_array) { // check the domain validity: if (!preg_match('/^[a-zA-Z0-9\\-]{1,}$/i', $domain)) { return false; } if (preg_match('/[-]{2,}/', $domain)) { return false; } if (preg_match('/^[-]{1,}/', $domain)) { return false; } if (preg_match('/[-]{1,}$/', $domain)) { return false; } $db =& DB(); $dbm = new CORE_database(); $sql = $dbm->sql_select('service', 'id', "domain_name = ::{$domain}:: AND domain_tld = ::{$tld}::", "", $db); $rs = $db->Execute($sql); if ($rs == false || $rs->RecordCount() > 0) { return false; } else { return true; } }
function update($VAR) { $type = "update"; $this->method["{$type}"] = explode(",", $this->method["{$type}"]); $db = new CORE_database(); $rs = $db->update($VAR, $this, $type); }
function search_show($VAR) { $this->construct(); $type = "search"; $this->method["{$type}"] = explode(",", $this->method["{$type}"]); $db = new CORE_database(); $db->search_show($VAR, $this, $type); }
function search_form($VAR) { $type = "search"; $this->method["{$type}"] = split(",", $this->method["{$type}"]); $db = new CORE_database(); $db->search_form($VAR, $this, $type); }
function check($domain,$tld,$tld_array) { // check the domain validity: if(!eregi('^[a-zA-Z0-9\-]{1,}$', $domain)) return false; if(eregi('[-]{2,}', $domain)) return false; if(eregi('^[-]{1,}', $domain)) return false; if(eregi('[-]{1,}$', $domain)) return false; $db = &DB(); $dbm = new CORE_database; $sql = $dbm->sql_select('service', 'id', "domain_name = ::$domain:: AND domain_tld = ::$tld::","", $db); $rs = $db->Execute($sql); if($rs == false || $rs->RecordCount() > 0) return false; else return true; }
function user_search_show($VAR) { # Lock the user only for his billing_records: if (!SESS_LOGGED) { return false; } $this->construct(); $type = "search"; $this->method["{$type}"] = explode(",", $this->method["{$type}"]); $db = new CORE_database(); $db->search_show($VAR, $this, $type); }
function search_show($VAR) { $this->newsletter_construct(); $type = "search"; $this->method["{$type}"] = split(",", $this->method["{$type}"]); $db = new CORE_database(); $db->search_show($VAR, $this, $type); }
function search_show($VAR) { $this->static_page_category_construct(); $type = "search"; $this->method["{$type}"] = split(",", $this->method["{$type}"]); $db = new CORE_database(); $db->search_show($VAR, $this, $type); }
function accounts() { global $VAR, $C_debug; $p = AGILE_DB_PREFIX; $s = DEFAULT_SITE; ### Connect to the remote Db; $dbr =& NewADOConnection($this->type); $dbr->Connect($this->host, $this->user, $this->pass, $this->db); ### Determine the offset for the account if (empty($VAR['offset'])) { $VAR['offset'] = 0; } @($offset = $VAR['offset'] . "," . $this->select_limit); # select each account from remote db $sql = "SELECT * FROM client_info "; $rs = $dbr->SelectLimit($sql, $offset); if ($rs === false) { $C_debug->alert("Query to the table 'client_info' failed!"); return false; } if ($rs->RecordCount() == 0) { $C_debug->alert("No more records to process!"); echo "<script language=javascript>setTimeout('document.location=\\'?_page=import:import&plugin={$VAR['plugin']}\\'', 1500); </script>"; return; } ### Get the default checkout plugin id: $db =& DB(); $sql = "SELECT id FROM {$p}checkout WHERE\n\t\t\t\tsite_id = {$s} AND\n\t\t\t\tcheckout_plugin = '{$this->gateway}'"; $ch = $db->Execute($sql); $checkout_plugin_id = $ch->fields['id']; $msg = "Processing " . $rs->RecordCount() . " Records...<BR>"; # loop through each remote account while (!$rs->EOF) { $msg .= "<BR>Processing account: {$rs->fields['client_fname']} {$rs->fields['client_lname']}"; # start a new transaction for the insert: $db =& DB(); $db->StartTrans(); # Get a local account id $id = $db->GenID($p . 'account_id'); ## Get the country: $country = $rs->fields['client_country']; $db =& DB(); $dbm = new CORE_database(); $rscountry = $db->Execute($dbm->sql_select('country', 'id', "two_code = {$country}", '', &$db)); if ($rscountry && $rscountry->RecordCount() == 1) { $country = $rscountry->fields['id']; } else { $country = DEFAULT_COUNTRY; } if (empty($rs->fields['client_username'])) { $username = $rs->fields['client_email']; } else { $username = $rs->fields['client_username']; } # Insert the account $sql = "INSERT INTO {$p}account SET\n\t\t\t\t\tid \t\t\t= {$id},\n\t\t\t\t\tsite_id\t\t= {$s},\n\t\t\t\t\tdate_orig\t= " . $db->qstr($rs->fields['client_stamp']) . ",\n\t\t\t\t\tdate_last\t= " . time() . ",\n\t\t\t\t\tlanguage_id\t= " . $db->qstr(DEFAULT_LANGUAGE) . ",\n\t\t\t\t\tcurrency_id\t= " . DEFAULT_CURRENCY . ",\n\t\t\t\t\ttheme_id\t= " . $db->qstr(DEFAULT_THEME) . ",\n\t\t\t\t\tusername\t= " . $db->qstr($username) . ",\n\t\t\t\t\tpassword\t= " . $db->qstr($rs->fields['client_password']) . ",\n\t\t\t\t\tmisc\t\t= " . $db->qstr("Phone: " . $rs->fields['client_phone1'] . "\r\nPhone #2: " . $rs->fields['client_phone2'] . "\r\n" . $rs->fields['client_comments']) . ",\n\t\t\t\t\tstatus\t\t= 1,\n\t\t\t\t\tcountry_id\t= {$country},\n\t\t\t\t\tfirst_name\t= " . $db->qstr($rs->fields['client_fname']) . ",\n\t\t\t\t\tlast_name\t= " . $db->qstr($rs->fields['client_lname']) . ",\n\t\t\t\t\tcompany\t\t= " . $db->qstr($rs->fields['client_company']) . ",\n\t\t\t\t\taddress1\t= " . $db->qstr($rs->fields['client_address']) . ",\n\t\t\t\t\taddress2\t= " . $db->qstr($rs->fields['client_address_2']) . ",\n\t\t\t\t\tcity\t\t= " . $db->qstr($rs->fields['client_city']) . ",\n\t\t\t\t\tstate\t\t= " . $db->qstr($rs->fields['client_state']) . ",\n\t\t\t\t\tzip\t\t\t= " . $db->qstr($rs->fields['client_zip']) . ",\n\t\t\t\t\temail\t\t= " . $db->qstr($rs->fields['client_email']) . ",\n\t\t\t\t\temail_type\t= 0"; $db->Execute($sql); # Insert the import record $this->import_transaction($this->plugin, $VAR['action'], 'account', $id, 'client_info', $rs->fields['client_id'], &$db); # If cc details exist, import an account_billing record: if (!empty($rs->fields['billing_cc_type']) && !empty($rs->fields['billing_cc_exp'])) { # Get a local account_billing id $bill_id = $db->GenID($p . 'account_billing_id'); $type = split("-", $rs->fields['billing_cc_type']); $exp = split("/", $rs->fields['billing_cc_exp']); # the modernbill encryption method is unknown, so we have no way to decrypt the cc details # we will create a blank CC record that the user or admin can manually update... $sql = "INSERT INTO {$p}account_billing SET\n\t\t\t\t\t\tid \t\t\t\t\t= {$bill_id},\n\t\t\t\t\t\tsite_id\t\t\t\t= {$s}, \n\t\t\t\t\t\taccount_id\t\t\t= {$id},\n\t\t\t\t\t\tcheckout_plugin_id \t= {$checkout_plugin_id},\n\t\t\t\t\t\tcard_type\t\t\t= " . $db->qstr(strtolower($type[0])) . ", \n\t\t\t\t\t\tcard_num4\t\t\t= " . $db->qstr($type[1]) . ", \n\t\t\t\t\t\tcard_exp_month\t\t= " . $db->qstr($exp[0]) . ", \n\t\t\t\t\t\tcard_exp_year\t\t= " . $db->qstr($exp[1]); $db->Execute($sql); # Insert the import record $this->import_transaction($this->plugin, $VAR['action'], 'account_billing', $bill_id, 'client_info', $rs->fields['client_id'], &$db); } # Complete the transaction $db->CompleteTrans(); $rs->MoveNext(); } $C_debug->alert($msg); $offset = $VAR['offset'] + $this->select_limit; echo "<script language=javascript> \n\t\t\t setTimeout('document.location=\\'?_page=core:blank&offset={$offset}&action={$VAR['action']}&plugin={$VAR['plugin']}&do[]=import:do_action\\'', 1200);\n\t\t\t </script>"; }
/** * 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; }
function delete($VAR) { $this->construct(); $db = new CORE_database(); $db->mass_delete($VAR, $this, ""); }
function update($VAR) { if ($VAR['setup_currency_id'] != DEFAULT_CURRENCY) { $curr = true; } else { $curr = false; } # make sure the index.php file is not included at the end: if (!empty($VAR['setup_ssl_url'])) { $VAR['setup_ssl_url'] = eregi_replace('index.php', '', $VAR['setup_ssl_url']); } if (!empty($VAR['setup_nonssl_url'])) { $VAR['setup_nonssl_url'] = eregi_replace('index.php', '', $VAR['setup_nonssl_url']); } # Validate trailing slash is on the end of the URL: if (!empty($VAR['setup_ssl_url']) && !ereg('/$', $VAR['setup_ssl_url'])) { $VAR['setup_ssl_url'] .= '/'; } # Validate trailing slash is on the end of the URL: if (!empty($VAR['setup_nonssl_url']) && !ereg('/$', $VAR['setup_nonssl_url'])) { $VAR['setup_nonssl_url'] .= '/'; } $type = "update"; $this->method["{$type}"] = explode(",", $this->method["{$type}"]); $db = new CORE_database(); $rs = $db->update($VAR, $this, $type); if ($rs && $curr) { /* Start: Update all sessions & accounts */ $db =& DB(); $sql = "UPDATE " . AGILE_DB_PREFIX . "session \n\t\t\t\t\tSET\n\t\t\t\t\tcurrency_id = " . $db->qstr($VAR['setup_currency_id']) . "\n\t\t\t\t\tWHERE\n\t\t\t\t\tsite_id \t= " . $db->qstr(DEFAULT_SITE) . " AND\n\t\t\t\t\tcurrency_id != " . $db->qstr($VAR['setup_currency_id']); $rs = $db->Execute($sql); $sql = "UPDATE " . AGILE_DB_PREFIX . "account \n\t\t\t\t\tSET\n\t\t\t\t\tcurrency_id = " . $db->qstr($VAR['setup_currency_id']) . "\n\t\t\t\t\tWHERE\n\t\t\t\t\tsite_id \t= " . $db->qstr(DEFAULT_SITE) . " AND\n\t\t\t\t\tcurrency_id != " . $db->qstr($VAR['setup_currency_id']); $rs = $db->Execute($sql); /* End: SQL Insert Statement */ } # Clear out the cache entry if (defined("AGILE_CORE_CACHE_DIR") && AGILE_CORE_CACHE_DIR != '') { $tfile = AGILE_CORE_CACHE_DIR . "core-setup"; if (file_exists($tfile)) { unlink(AGILE_CORE_CACHE_DIR . "core-setup"); } } }
function update($VAR) { global $VAR; ### Check that user is logged in: if (SESS_LOGGED != '1') { echo "Sorry, you must be logged in!"; } /* check for sub account */ $issubaccount = false; if (!empty($VAR['account_id']) && $VAR['account_id'] != SESS_ACCOUNT) { if ($this->isParentAccount($VAR['account_id'])) { $VAR['id'] = $VAR['account_id']; global $smarty; $issubaccount = true; } else { return false; } } else { $VAR['id'] = SESS_ACCOUNT; $VAR['account_id'] = SESS_ACCOUNT; } $VAR['account_date_last'] = time(); // validate the tax_id require_once PATH_MODULES . 'tax/tax.inc.php'; $taxObj = new tax(); $tax_arr = @$VAR['account_tax_id']; if (is_array($tax_arr)) { foreach ($tax_arr as $country_id => $tax_id) { if ($country_id == $VAR['cid']) { $exempt = @$VAR["account_tax_id_exempt"][$country_id]; if (!($txRs = $taxObj->TaxIdsValidate($country_id, $tax_id, $exempt))) { $this->validated = false; global $C_translate; $this->val_error[] = array('field' => 'account_tax_id', 'field_trans' => $taxObj->errField, 'error' => $C_translate->translate('validate_general', "", "")); } if ($exempt) { $VAR['account_tax_id'] = false; } else { $VAR['account_tax_id'] = $tax_id; } } } } #################################################################### ### Get required static_Vars and validate them... return an array ### w/ ALL errors... #################################################################### require_once PATH_CORE . 'static_var.inc.php'; $static_var = new CORE_static_var(); if (!isset($this->val_error)) { $this->val_error = false; } $all_error = $static_var->validate_form('account', $this->val_error); if ($all_error != false && gettype($all_error) == 'array') { $this->validated = false; } else { $this->validated = true; } #################################################################### # If validation was failed, skip the db insert & # set the errors & origonal fields as Smarty objects, # and change the page to be loaded. #################################################################### if (!$this->validated) { global $smarty; # set the errors as a Smarty Object $smarty->assign('form_validation', $all_error); # set the page to be loaded if (!defined("FORCE_PAGE")) { define('FORCE_PAGE', $VAR['_page_current']); } return; } ### Change password $password_changed = false; if (isset($VAR['account_password']) && $VAR['account_password'] != "") { if (isset($VAR['confirm_password']) && $VAR['account_password'] == $VAR['confirm_password']) { $password = $VAR['account_password']; unset($VAR['account_password']); @($VAR["account_password"] = $password); ### Alert: the password has been changed! global $C_debug, $C_translate; $C_debug->alert($C_translate->translate('password_changed', 'account', '')); $password_changed = true; /* check if new password is ok */ global $C_list; if ($C_list->is_installed('account_password_history')) { include_once PATH_MODULES . 'account_password_history/account_password_history.inc.php'; $accountHistory = new account_password_history(); if (!$accountHistory->getIsPasswordOk(SESS_ACCOUNT, $VAR['account_password'], false)) { $C_debug->alert("The password you have selected has been used recently and cannot be used again at this time for security purposes."); unset($VAR["account_password"]); $password_changed = false; } } } else { ### ERROR: The passwords provided do not match! global $C_debug, $C_translate; $C_debug->alert($C_translate->translate('password_change_match', 'account', '')); unset($VAR["account_password"]); } } else { unset($VAR["account_password"]); } ### Change theme if (isset($VAR['tid']) && $VAR['tid'] != "") { @($VAR["account_theme_id"] = $VAR['tid']); } ### Change Language if (isset($VAR['lid']) && $VAR['lid'] != "") { @($VAR["account_language_id"] = $VAR['lid']); } ### Change country if (isset($VAR['cid']) && $VAR['cid'] != "") { @($VAR["account_country_id"] = $VAR['cid']); } ### Change currency if (isset($VAR['cyid']) && $VAR['cyid'] != "") { @($VAR["account_currency_id"] = $VAR['cyid']); } ### Get the old username ( for db mapping ) $db =& DB(); $sql = 'SELECT username FROM ' . AGILE_DB_PREFIX . 'account WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND id = ' . $db->qstr(SESS_ACCOUNT); $result = $db->Execute($sql); if ($result->RecordCount() > 0) { $old_username = $result->fields['username']; } ### Update the record $this->account_construct(); $type = "update"; $this->method["{$type}"] = split(",", $this->method["{$type}"]); $db = new CORE_database(); $db->update($VAR, $this, $type); /* password logging class */ if ($password_changed && is_object($accountHistory)) { $accountHistory->setNewPassword(SESS_ACCOUNT, $VAR['account_password'], false); } ### Update the static vars: $static_var->update($VAR, 'account', SESS_ACCOUNT); ### Do any db_mapping global $C_list; if ($C_list->is_installed('db_mapping')) { include_once PATH_MODULES . 'db_mapping/db_mapping.inc.php'; $db_map = new db_mapping(); if (!empty($password)) { $db_map->plaintext_password = $password; } else { $db_map->plaintext_password = false; } $db_map->account_edit(SESS_ACCOUNT, $old_username); } /* update groups for subaccount */ if ($issubaccount) { $db =& DB(); $db->Execute(sqlDelete($db, "account_group", "group_id>2 and \n\t\t\t\t(service_id is null or service_id=0 or service_id='') \n\t\t\t\tand account_id=" . $db->qstr($VAR['account_id']))); if (!empty($VAR['groups'])) { global $C_auth; foreach ($VAR['groups'] as $gid => $val) { if ($gid == $val && $C_auth->auth_group_by_id($gid)) { $fields = array('account_id' => $VAR['account_id'], 'group_id' => $gid, 'active' => 1, 'date_orig' => time()); $db->Execute(sqlInsert($db, "account_group", $fields)); } } } } }
function this_search_show($VAR, $construct, $type) { global $VAR; # Get the list of parents for this group $this->group_parent_list($VAR['module_method_group_id']); # generate the full query $q = "SELECT * FROM\n\t\t\t " . AGILE_DB_PREFIX . "module_method\n\t\t\t WHERE\n\t\t\t module_id = " . $VAR['module_method_module_id']; $db =& DB(); $result = $db->Execute($q); # put the results into a smarty accessable array $i = 0; $class_name = TRUE; while (!$result->EOF) { $smart[$i] = $result->fields; $method_id = $smart[$i]['id']; ## Get the auth status for this method & group $q1 = 'SELECT id FROM ' . AGILE_DB_PREFIX . 'group_method WHERE method_id = ' . $smart[$i]['id'] . ' AND group_id = ' . $VAR['module_method_group_id']; $db1 =& DB(); $resulta = $db1->Execute($q1); #echo "<BR> $q1"; ## authorized by current group if ($resulta->RecordCount() >= 1) { #echo "<BR>1 - This group matches!"; $smart[$i]['checked'] = '1'; } else { # get the parent group id(s) for this group $match = false; for ($ii = 0; $ii < count($this->group); $ii++) { if ($match == false && $this->group[$ii] != $VAR['module_method_group_id']) { $q2 = 'SELECT id FROM ' . AGILE_DB_PREFIX . 'group_method WHERE method_id = ' . $method_id . ' AND group_id = ' . $this->group[$ii]; $db2 =& DB(); $resultb = $db2->Execute($q2); #echo "<BR> $q2"; if ($resultb->RecordCount() >= 1) { $match = true; } } } ## authorized by parent if ($match) { #echo "<BR>2 - This Parent Matches!"; $smart[$i]['checked'] = '2'; } else { ## not authorized #echo "<BR>3 - NO matches"; $smart[$i]['checked'] = '3'; } } if ($class_name) { $smart[$i]['_C'] = 'row2'; $class_name = FALSE; } else { $smart[$i]['_C'] = 'row1'; $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($construct->table, $this->result); $smarty->assign('page', $VAR['page']); $smarty->assign('order', 1111); $smarty->assign('sort', 1111); $smarty->assign('limit', 1111); $smarty->assign('search_id', 1111); $smarty->assign('results', $results); # get the total pages for this search: $this->pages = 1; 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); }
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; }
/** * Validate A Product * * @param array $VAR * @param int $product_id * @param int $account_id * @return bool */ function validate_product($VAR, $product_id, $account_id) { global $C_translate, $C_debug, $C_auth; $db =& DB(); # can user add inactive items if ($C_auth->auth_method_by_name('invoice', 'add')) { $active = ''; } else { $active = " AND active=1 "; } # validate that product exists $result = $db->Execute(sqlSelect($db, "product", "*", "id=::{$product_id}:: {$active}")); if ($result->RecordCount() == 0) { $C_debug->alert($C_translate->translate('err_no_prod', 'cart', '')); return false; } # check that product is not already in cart if ($result->fields['cart_multiple'] != "1" && empty($VAR['service_id'])) { $rs = $db->Execute(sqlSelect($db, "cart", "id", "product_id=::{$product_id}:: AND session_id=::{$this->session_id}::")); if ($rs->RecordCount() > 0) { $C_debug->alert($C_translate->translate('err_prod_already', 'cart', '')); return false; } } # Validate groups: $groups = unserialize($result->fields['group_avail']); $auth = false; for ($ii = 0; $ii < count($groups); $ii++) { if ($C_auth->auth_group_by_id($groups[$ii])) { $auth = true; break; } } if (!$auth) { return false; } # Validate any required products: if (!empty($result->fields["assoc_req_prod"])) { $reqarr = unserialize($result->fields["assoc_req_prod"]); } else { $reqarr = false; } $reqtype = $result->fields["assoc_req_prod_type"]; $assoc = true; if (is_array($reqarr) && !empty($reqarr[0])) { /* if($reqtype == 0 && is_array($reqarr)) { # ALL are required for($i=0; $i<count($reqarr); $i++) if(!$this->assoc_prod($reqarr[$i])) { $assoc = false; # Add the required product: $this->product_req_add($reqarr[$i]); } } elseif ($reqtype == 1 && is_array($reqarr)) { # ONE is required $assoc = false; for($i=0; $i<count($reqarr); $i++) { if($this->assoc_prod($reqarr[$i])) { $assoc = true; $i = count( $reqarr ); } else { # add the required product: $this->product_req_add($reqarr[$i]); } } }*/ if (!SESS_LOGGED) { $C_debug->alert($C_translate->translate('err_assoc_login', 'cart', '')); return false; } $items = '<br>'; foreach ($reqarr as $prod_id) { $prodrs = $db->Execute(sqlSelect($db, "product_translate", "*", "product_id={$prod_id} AND language_id = ::" . SESS_LANGUAGE . "::")); if ($prodrs && $prodrs->RecordCount()) { $items .= "- <b><a href=\"?_page=product:details&id={$prod_id}\">{$prodrs->fields['name']}</a></b><br>"; } } $C_translate->value("cart", "items", $items); $msg = $C_translate->translate('err_assoc_req', 'cart', ''); if ($reqtype == 0) { $C_debug->alert($msg . " " . $C_translate->translate('assoc_all', 'cart', '')); } else { $C_debug->alert($msg . " " . $C_translate->translate('assoc_one', 'cart', '')); } return false; } # Product Plugin Level Validation $product = $result; if (!empty($product->fields['prod_plugin']) && !empty($product->fields['prod_plugin_data'])) { $prodplgfile = PATH_PLUGINS . 'product/' . $product->fields['prod_plugin_file'] . '.php'; if (is_file($prodplgfile)) { include_once PATH_PLUGINS . 'product/' . $product->fields['prod_plugin_file'] . '.php'; eval('$prodplg = new plgn_prov_' . $product->fields['prod_plugin_file'] . ';'); if (is_object($prodplg)) { if (is_callable(array($prodplg, 'validate_cart'))) { $result = $prodplg->validate_cart($VAR, $product); if ($result === true) { } else { $C_debug->alert($result); return false; } } } } } # Service upgrade if (!empty($VAR['service_id'])) { # validate account logged in if (SESS_LOGGED == false) { return false; } $dbm = new CORE_database(); # validate account owns service, service is modifyable, active, not canceled, and exists $rs = $db->Execute($sql = $dbm->sql_select("service", "*", "recur_modify = 1 AND active = 1 AND ( suspend_billing IS NULL OR suspend_billing = 0 ) AND account_id = " . SESS_ACCOUNT . " AND id = {$VAR['service_id']}", "", $db)); if ($rs === false || $rs->RecordCount() == 0) { return false; } # validate selected product_id is in allowed modify array for selected service if (empty($rs->fields['product_id'])) { return false; } $product_id = $rs->fields['product_id']; $prod = $db->Execute($dbm->sql_select("product", "*", "id = {$product_id}", "", $db)); if ($prod === false || $prod->RecordCount() == 0) { return false; } $arr = unserialize($prod->fields['modify_product_arr']); if (!is_array($arr) || count($arr) == 0 || empty($arr[0])) { return false; } $do = false; foreach ($arr as $pid) { if ($pid == $VAR['product_id']) { $do = true; break; } } if (!$do) { return false; } # make sure this service is not in the cart $sql = 'DELETE FROM ' . AGILE_DB_PREFIX . 'cart WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND service_id = ' . $db->qstr($VAR['service_id']); $rs = $db->Execute($sql); # make sure this service has no outstanding invoices: $p = AGILE_DB_PREFIX; $sql = "SELECT DISTINCT {$p}invoice.id, {$p}invoice_item.id\n\t \t\tFROM {$p}invoice,{$p}invoice_item\n\t \t\tWHERE {$p}invoice.site_id = " . DEFAULT_SITE . " AND {$p}invoice_item.site_id = " . DEFAULT_SITE . " \n\t \t\tAND {$p}invoice_item.service_id = " . $db->qstr($VAR['service_id']) . " \n\t \t\tAND {$p}invoice_item.invoice_id = {$p}invoice.id AND {$p}invoice.billing_status != 1"; $rs = $db->Execute($sql); if ($rs->RecordCount() > 0) { echo "Invoice(s) in unpaid status for selected service ID {$VAR['service_id']}, cannot upgrade"; return false; } } return true; }
function search_show($VAR) { $type = "search"; $this->method["{$type}"] = explode(",", $this->method["{$type}"]); $db = new CORE_database(); $smart = $db->search_show($VAR, $this, $type); for ($i = 0; $i < count($smart); $i++) { # Get the stats for each advertisement: $budget = $smart[$i]['budget']; # Invoices referred $inv = $this->referred_invoices($smart[$i]['id']); $smart[$i]['invoices_referred'] = $inv[0]; $smart[$i]['invoices_revenue'] = $inv[1]; @($smart[$i]['invoice_avg'] = $inv[1] / $inv[0]); # total impressions & clicks: $impressions_total = 0; $clicks_total = 0; for ($ii = 1; $ii <= 12; $ii++) { $impressions_total += $smart[$i]["served" . $ii]; $clicks_total += $smart[$i]["clicked" . $ii]; if (empty($smart[$i]["served" . $ii]) && empty($smart[$i]["served" . $ii]) && empty($smart[$i]["served" . $ii])) { $smart[$i]["show" . $ii] = false; } else { $smart[$i]["show" . $ii] = true; } } $smart[$i]['impressions_total'] = $impressions_total; $smart[$i]['clicks_total'] = $clicks_total; # Impr. percentage, Clicks percentage, CTR $ctr_count = 0; $ctr_amt = 0; for ($ii = 1; $ii <= 12; $ii++) { # CTR if ($smart[$i]["show" . $ii]) { $ctr = $smart[$i]["clicked" . $ii] / $smart[$i]["served" . $ii] * 100; if ($ctr < 0) { $smart[$i]['ctr' . $ii] = round($ctr) . '%'; } else { $smart[$i]['ctr' . $ii] = round($ctr, 1) . '%'; } $ctr_count++; $ctr_amt += $ctr; } else { $smart[$i]['ctr' . $ii] = "0%"; $ctr_count++; } } # CTR Avg: if ($ctr_count > 0) { $smart[$i]['ctr_avg'] = round($ctr_amt / $ctr_count, 2) . '%'; } else { $smart[$i]['ctr_avg'] = "0%"; } # CPC Avg: if ($clicks_total > 0) { $cpc_avg = $budget / $clicks_total; if ($cpc_avg < 0.1) { $smart[$i]['cpc_avg'] = round($cpc_avg, 3); } else { $smart[$i]['cpc_avg'] = round($cpc_avg, 2); } } else { $smart[$i]['cpc_avg'] = 0; } # CPI Avg: if ($impressions_total > 0) { $cpi_avg = $budget / $impressions_total; if ($cpi_avg < 0.1) { $smart[$i]['cpi_avg'] = round($cpi_avg, 3); } else { $smart[$i]['cpi_avg'] = round($cpi_avg, 2); } } else { $smart[$i]['cpi_avg'] = 0; } # Cost per Conversion: if ($inv[0] > 0 && $budget > 0) { $smart[$i]['conversion_cost'] = round($budget / $inv[0], 2); } else { $smart[$i]['conversion_cost'] = 0; } # ROI if ($inv[0] > 0 && $budget > 0) { $smart[$i]['roi'] = round($inv[1] / $budget * 100) . '%'; } else { $smart[$i]['roi'] = '---'; } } global $smarty; $smarty->assign('campaign', $smart); }
function accounts() { global $VAR, $C_debug; $p = AGILE_DB_PREFIX; $s = DEFAULT_SITE; ### Connect to the remote Db; $dbr =& NewADOConnection($this->type); $dbr->Connect($this->host, $this->user, $this->pass, $this->db); ### Determine the offset for the account if (empty($VAR['offset'])) { $VAR['offset'] = 0; } @($offset = $VAR['offset'] . "," . $this->select_limit); # select each account from remote db $sql = "SELECT customers.*, \n\t\t\t\t\tauthorization.password as password \n\t\t\t\tFROM \n\t\t\t\t\tcustomers,authorization \n\t\t\t\tWHERE\n\t\t\t\t\tcustomers.email = authorization.email "; $rs = $dbr->SelectLimit($sql, $offset); if ($rs === false) { $C_debug->alert("Query to the table 'customers' failed!"); return false; } if ($rs->RecordCount() == 0) { $C_debug->alert("No more records to process!"); echo "<script language=javascript>setTimeout('document.location=\\'?_page=import:import&plugin={$VAR['plugin']}\\'', 1500); </script>"; return; } ### Get the default checkout plugin id: $db =& DB(); $sql = "SELECT id FROM {$p}checkout WHERE\n\t\t\t\tsite_id = {$s} AND\n\t\t\t\tcheckout_plugin = '{$this->gateway}'"; $ch = $db->Execute($sql); $checkout_plugin_id = $ch->fields['id']; $msg = "Processing " . $rs->RecordCount() . " Records...<BR>"; # loop through each remote account while (!$rs->EOF) { $msg .= "<BR>Processing account: {$rs->fields['email']}..."; # start a new transaction for the insert: $db =& DB(); $db->StartTrans(); # Get a local account id $id = $db->GenID($p . 'account_id'); # Get orig date if (!empty($rs->fields['last_access'])) { $dat = explode(' ', $rs->fields['last_access']); $date = explode('-', $dat[0]); $min = explode(':', $dat[1]); $date_orig = mktime($min[0], $min[1], $min[2], $date[1], $date[2], $date[0]); } else { $date_orig = time(); } ## Get the country: $country = $rs->fields['country']; $db =& DB(); $dbm = new CORE_database(); $rscountry = $db->Execute($dbm->sql_select('country', 'id', 'name = {}', '', &$db)); if ($rscountry && $rscountry->RecordCount() == 1) { $country = $rscountry->fields['id']; } else { $country = DEFAULT_COUNTRY; } # Insert the account $sql = "INSERT INTO {$p}account SET\n\t\t\t\t\tid \t\t\t= {$id},\n\t\t\t\t\tsite_id\t\t= {$s},\n\t\t\t\t\tdate_orig\t= {$date_orig},\n\t\t\t\t\tdate_last\t= " . time() . ",\n\t\t\t\t\tlanguage_id\t= " . $db->qstr(DEFAULT_LANGUAGE) . ",\n\t\t\t\t\tcurrency_id\t= " . DEFAULT_CURRENCY . ",\n\t\t\t\t\ttheme_id\t= " . $db->qstr(DEFAULT_THEME) . ",\n\t\t\t\t\tusername\t= " . $db->qstr($rs->fields['email']) . ",\n\t\t\t\t\tpassword\t= " . $db->qstr(md5(@$rs->fields['password'])) . ",\n\t\t\t\t\tstatus\t\t= 1,\n\t\t\t\t\tcountry_id\t= {$country},\n\t\t\t\t\tfirst_name\t= " . $db->qstr($rs->fields['first_name']) . ",\n\t\t\t\t\tlast_name\t= " . $db->qstr($rs->fields['last_name']) . ",\n\t\t\t\t\tcompany\t\t= " . $db->qstr($rs->fields['company']) . ",\n\t\t\t\t\taddress1\t= " . $db->qstr($rs->fields['address1']) . ",\n\t\t\t\t\taddress2\t= " . $db->qstr($rs->fields['address2']) . ",\n\t\t\t\t\tcity\t\t= " . $db->qstr($rs->fields['city']) . ",\n\t\t\t\t\tstate\t\t= " . $db->qstr($rs->fields['region']) . ",\n\t\t\t\t\tzip\t\t\t= " . $db->qstr($rs->fields['code']) . ",\n\t\t\t\t\temail\t\t= " . $db->qstr($rs->fields['email']) . ",\n\t\t\t\t\temail_type\t= 0"; $db->Execute($sql); # Insert the import record $this->import_transaction($this->plugin, $VAR['action'], 'account', $id, 'customers', $rs->fields['email'], &$db); # If cc details exist, import an account_billing record: if (!empty($rs->fields['cc_number']) && !empty($rs->fields['cc_expiry'])) { # Get a local account_billing id $bill_id = $db->GenID($p . 'account_billing_id'); # the whois.cart encryption method is secret, so we have no way to decrypt the cc details # we will create a blank CC record that the user or admin can manually update... $sql = "INSERT INTO {$p}account_billing SET\n\t\t\t\t\t\tid \t\t\t\t\t= {$bill_id},\n\t\t\t\t\t\tsite_id\t\t\t\t= {$s}, \n\t\t\t\t\t\taccount_id\t\t\t= {$id},\n\t\t\t\t\t\tcheckout_plugin_id \t= {$checkout_plugin_id},\n\t\t\t\t\t\tcard_type\t\t\t= 'visa', \n\t\t\t\t\t\tcard_num4\t\t\t= '0000',\n\t\t\t\t\t\tcard_exp_month\t\t= 0,\n\t\t\t\t\t\tcard_exp_year\t\t= 0"; $db->Execute($sql); # Insert the import record $this->import_transaction($this->plugin, $VAR['action'], 'account_billing', $bill_id, 'customers', $rs->fields['email'], &$db); } # Complete the transaction $db->CompleteTrans(); $rs->MoveNext(); } $C_debug->alert($msg); $offset = $VAR['offset'] + $this->select_limit; echo "<script language=javascript> \n\t\t\t setTimeout('document.location=\\'?_page=core:blank&offset={$offset}&action={$VAR['action']}&plugin={$VAR['plugin']}&do[]=import:do_action\\'', 1200);\n\t\t\t </script>"; }
function search_show($VAR) { if (SESS_LOGGED) { include_once PATH_MODULES . "voip/voip.inc.php"; $db =& DB(); $v = new voip(); $fdids = $v->get_fax_dids(SESS_ACCOUNT); #echo "<pre>".print_r($fdids,true)."</pre>"; if (is_array($fdids)) { foreach ($fdids as $did) { $sql = "UPDATE " . AGILE_DB_PREFIX . "voip_fax SET \n\t\t\t\t\t\taccount_id\t\t= " . $db->qstr(SESS_ACCOUNT) . ", \n\t\t\t\t\t\tsite_id\t\t\t= " . $db->qstr(DEFAULT_SITE) . " \n\t\t\t\t\t\tWHERE dst = " . $db->qstr($did); $db->Execute($sql); #echo "did=$did ".$sql."<br>"; } } unset($db); } $type = "search"; $this->method["{$type}"] = split(",", $this->method["{$type}"]); $db = new CORE_database(); $db->search_show($VAR, $this, $type); }
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); }
/** USER SEARCH SHOW */ function user_search_show($VAR) { if (!SESS_LOGGED) { return false; } $this->invoice_construct(); $type = "search"; $this->method["{$type}"] = explode(",", $this->method["{$type}"]); $db = new CORE_database(); $db->search_show($VAR, $this, $type); }
function user_view($VAR) { # Check that the correct account owns this billing record $dbx =& DB(); $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'account_billing WHERE id = ' . $dbx->qstr(@$VAR['id']) . ' AND account_id = ' . $dbx->qstr(SESS_ACCOUNT) . ' AND site_id = ' . $dbx->qstr(DEFAULT_SITE); $rs = $dbx->Execute($sql); if (@$rs->RecordCount() == 0) { return false; } $this->construct(); $type = "view"; $this->method["{$type}"] = explode(",", $this->method["{$type}"]); $db = new CORE_database(); $db->view($VAR, $this, $type); }
function search_show($VAR) { $this->discount_construct(); $type = "search"; $this->method["{$type}"] = split(",", $this->method["{$type}"]); $dbc = new CORE_database(); $smart = $dbc->search_show($VAR, $this, $type); $db =& DB(); for ($i = 0; $i < count($smart); $i++) { $smart[$i]['savings'] = 0; $smart[$i]['orders'] = 0; $smart[$i]['revenue'] = 0; $rs = $db->Execute($sql = sqlSelect($db, array("invoice", "invoice_item_discount"), "SUM(A.total_amt) as sum", "B.invoice_id=A.id AND A.billing_status=1 AND B.discount=::{$smart[$i]['name']}::", "", "", "DISTINCT")); if ($rs && $rs->RecordCount()) { $smart[$i]['revenue'] = $rs->fields['sum']; } $rs = $db->Execute(sqlSelect($db, 'invoice_item_discount', 'invoice_id,amount', "discount=::{$smart[$i]['name']}::")); if ($rs && $rs->RecordCount() > 0) { while (!$rs->EOF) { $smart[$i]['savings'] += $rs->fields['amount']; if (empty($invoices[$rs->fields['invoice_id']])) { $smart[$i]['orders']++; $invoices[$rs->fields['invoice_id']] = true; } $rs->MoveNext(); } } } global $smarty; $smarty->clear_assign('discount'); $smarty->assign('discount', $smart); }