function add($VAR) { $type = "add"; $this->method["{$type}"] = explode(",", $this->method["{$type}"]); $db = new CORE_database(); $group_id = $db->add($VAR, $this, $type); # add the new group to the account_group table: $db =& DB(); $record_id = $db->GenID(AGILE_DB_PREFIX . 'account_group_id'); $sql = "INSERT INTO " . AGILE_DB_PREFIX . "account_group SET\n\t\t\t\tid\t\t\t= " . $db->qstr($record_id) . ",\n\t\t\t\tsite_id \t= " . $db->qstr(DEFAULT_SITE) . ", \n\t\t\t\tdate_orig\t= " . $db->qstr(time()) . ",\n\t\t\t\tdate_expire = " . $db->qstr('0') . ",\n\t\t\t\tgroup_id\t= " . $db->qstr($group_id) . ",\n\t\t\t\taccount_id\t= " . $db->qstr(SESS_ACCOUNT) . ",\n\t\t\t\tactive\t\t= " . $db->qstr(1); $result = $db->Execute($sql); if ($result === false) { global $C_debug; $C_debug->error('list.inc.php', 'select_groups', $db->ErrorMsg()); return; } # update the current user's authentication so the newly added group appears # as available to them global $C_auth; $C_auth->auth_update(); return; }
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 $C_list, $C_debug; if (!$this->checkLimits()) { return false; } // check account limits // validate the tax_id global $VAR; require_once PATH_MODULES . 'tax/tax.inc.php'; $taxObj = new tax(); $tax_arr = @$VAR['account_admin_tax_id']; if (is_array($tax_arr)) { foreach ($tax_arr as $country_id => $tax_id) { if ($country_id == $VAR['account_admin_country_id']) { $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_admin_tax_id', 'field_trans' => $taxObj->errField, 'error' => $C_translate->translate('validate_general', "", "")); } if ($exempt) { $VAR['account_admin_tax_id'] = false; } else { $VAR['account_admin_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; } ### 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($VAR['account_admin_id']); $result = $db->Execute($sql); if ($result->RecordCount() > 0) { $old_username = $result->fields['username']; } ### Update the password: $update_password = false; if (!empty($VAR['_password'])) { $VAR['account_admin_password'] = $VAR['_password']; /* check if new password is ok */ 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($VAR['account_admin_id'], $VAR['account_admin_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_admin_password']); } else { $update_password = true; } } } ### Update the record $type = "update"; $this->method["{$type}"] = explode(",", $this->method["{$type}"]); $db = new CORE_database(); $ok = $db->update($VAR, $this, $type); if ($ok) { /* password logging class */ if ($update_password && is_object($accountHistory)) { $accountHistory->setNewPassword($VAR['account_admin_id'], $VAR["account_admin_password"], false); } ### Update the static vars: $static_var->update($VAR, 'account', $VAR['account_admin_id']); ### Do any db_mapping if ($C_list->is_installed('db_mapping')) { include_once PATH_MODULES . 'db_mapping/db_mapping.inc.php'; $db_map = new db_mapping(); if (!empty($VAR['account_admin_password'])) { $db_map->plaintext_password = $VAR['account_admin_password']; } else { $db_map->plaintext_password = false; } $db_map->account_edit($VAR['account_admin_id'], $old_username); } // remove login lock if ($VAR['account_admin_status']) { $db =& DB(); $delrs = $db->Execute($sql = sqlDelete($db, "login_lock", "account_id={$VAR['account_admin_id']}")); $delrs = $db->Execute($sql = sqlDelete($db, "login_log", "account_id={$VAR['account_admin_id']} AND status=0")); } return true; } }
function add($VAR) { # defaults for 'recurring' product if ($VAR["product_price_type"] == "1") { $VAR['product_price_recurr_default'] = "1"; $VAR['product_price_recurr_type'] = "0"; $VAR['product_price_recurr_week'] = "1"; $VAR['product_price_recurr_weekday'] = "1"; # Set default recurring prices: (monthly only) $db =& DB(); $sql = 'SELECT id FROM ' . AGILE_DB_PREFIX . 'group WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND pricing = ' . $db->qstr('1'); $rs = $db->Execute($sql); while (!$rs->EOF) { $i = $rs->fields['id']; $recur_price[0][$i]['price_base'] = ''; $recur_price[0][$i]['price_setup'] = ''; @($recur_price[1][$i]['price_base'] = $VAR['product_price_base']); @($recur_price[1][$i]['price_setup'] = $VAR['product_price_setup']); $recur_price[2][$i]['price_base'] = ''; $recur_price[2][$i]['price_setup'] = ''; $recur_price[3][$i]['price_base'] = ''; $recur_price[3][$i]['price_setup'] = ''; $recur_price[4][$i]['price_base'] = ''; $recur_price[4][$i]['price_setup'] = ''; $recur_price[5][$i]['price_base'] = ''; $recur_price[5][$i]['price_setup'] = ''; $rs->MoveNext(); } $recur_price[0]['show'] = "0"; $recur_price[1]['show'] = "1"; $recur_price[2]['show'] = "0"; $recur_price[3]['show'] = "0"; $recur_price[4]['show'] = "0"; $recur_price[5]['show'] = "0"; @($VAR['product_price_group'] = $recur_price); } # Defaults for product groups: $VAR['product_group_avail'] = array('0'); $this->product_construct(); $type = "add"; $this->method["{$type}"] = explode(",", $this->method["{$type}"]); $db = new CORE_database(); $result = $db->add($VAR, $this, $type); # Create a translate record for this product: if ($result) { $db =& DB(); $id = $db->GenID(AGILE_DB_PREFIX . 'product_translate_id'); $sql = 'INSERT INTO ' . AGILE_DB_PREFIX . 'product_translate SET site_id = ' . $db->qstr(DEFAULT_SITE) . ', id = ' . $db->qstr($id) . ', product_id = ' . $db->qstr($result) . ', language_id = ' . $db->qstr(DEFAULT_LANGUAGE) . ', name = ' . $db->qstr(@$VAR["translate_name"]) . ', description_short = ' . $db->qstr(@$VAR["translate_description_short"]) . ', description_full = ' . $db->qstr(@$VAR["translate_description_full"]); $db->Execute($sql); } }
function add($VAR) { $type = "add"; $this->method["{$type}"] = split(",", $this->method["{$type}"]); $db = new CORE_database(); $id = $db->add($VAR, $this, $type); if ($id && !empty($VAR['faq_question'])) { # Insert translation $db =& DB(); $idx = $db->GenID(AGILE_DB_PREFIX . 'faq_translate_id'); $sql = "INSERT INTO\t" . AGILE_DB_PREFIX . "faq_translate\n\t\t\t\t\tSET\n\t\t\t\t\tsite_id = " . DEFAULT_SITE . ",\n\t\t\t\t\tid = {$idx},\n\t\t\t\t\tfaq_id = {$id},\n\t\t\t\t\tdate_orig = " . time() . ",\n\t\t\t\t\tdate_last = " . time() . ",\n\t\t\t\t\tlanguage_id = '" . DEFAULT_LANGUAGE . "',\n\t\t\t\t\tanswer = " . $db->qstr(@$VAR['faq_answer']) . ",\n\t\t\t\t\tquestion = " . $db->qstr(@$VAR['faq_question']); $db->Execute($sql); } }
function delete($VAR) { $this->associated_DELETE[] = array('table' => 'invoice_commission', 'field' => 'affiliate_commission_id'); $db = new CORE_database(); $db->mass_delete($VAR, $this, ""); # Delete all associated discounts: if (isset($VAR['id'])) { $id = $VAR['id']; for ($i = 0; $i < count($id); $i++) { if ($id[$i] != '') { $q = '%Affiliate Commission ID ' . $id[$i] . '%'; $db =& DB(); $sql = "DELETE FROM " . AGILE_DB_PREFIX . "discount WHERE\n\t\t\t\t\t\t notes LIKE " . $db->qstr($q) . " AND\n\t\t\t\t\t\t site_id = " . $db->qstr(DEFAULT_SITE); $result = $db->Execute($sql); } } } else { $id = $VAR['delete_id']; $q = '%Affiliate Commission ID ' . $id . '%'; $db =& DB(); $sql = "DELETE FROM " . AGILE_DB_PREFIX . "discount WHERE\n\t\t\t\tnotes LIKE " . $db->qstr($q) . " AND\n\t\t\t\tsite_id = " . $db->qstr(DEFAULT_SITE); $result = $db->Execute($sql); } }
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 add($VAR) { global $C_translate, $C_debug; $VAR['htaccess_dir_htaccess'] = '# Error!'; $this->validated = true; ### Change the path... if (isset($VAR['htaccess_dir_path']) && $VAR['htaccess_dir_path'] != '') { # trim whitspaces $VAR['htaccess_dir_path'] = trim($VAR['htaccess_dir_path']); # replace all forward slashes with back slashes $VAR['htaccess_dir_path'] = ereg_replace('\\\\', '/', $VAR['htaccess_dir_path']); # add the final trailing slash if missing if (!ereg('[/]$', $VAR['htaccess_dir_path'])) { $VAR['htaccess_dir_path'] = $VAR['htaccess_dir_path'] . '/'; } } if (isset($VAR['htaccess_dir_path']) && $VAR['htaccess_dir_path'] != '') { ################################################################ ### VERIFY LOCAL PATH & WRITABILITY! @($filename = $VAR['htaccess_dir_path'] . '.htaccess'); @($id = $VAR['htaccess_dir_htaccess_id']); $db =& DB(); $sql = 'SELECT name FROM ' . AGILE_DB_PREFIX . 'htaccess WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND id = ' . $db->qstr($id); $result = $db->Execute($sql); @($name = $result->fields['name']); ### Check path $path = $VAR['htaccess_dir_path']; if (is_dir($path)) { ### Check if is writable! if (!is_writable($path)) { ## Path not writable! $this->validated = false; $this->val_error[] = array('field' => 'none', 'field_trans' => $C_translate->translate('error', 'core', ""), 'error' => $C_translate->translate('path_auth', 'htaccess_dir', "")); } } else { ### Path broken! $this->validated = false; $this->val_error[] = array('field' => 'none', 'field_trans' => $C_translate->translate('error', 'core', ""), 'error' => $C_translate->translate('path_broke', 'htaccess_dir', "")); } } #################################################################### ### 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', $this->val_error); # set the page to be loaded if (!defined("FORCE_PAGE")) { define('FORCE_PAGE', $VAR['_page_current']); } return; } #################################################################### ### Create the record/verify fields $type = "add"; $this->method["{$type}"] = explode(",", $this->method["{$type}"]); $db = new CORE_database(); $dir_id = $db->add($VAR, $this, $type); #################################################################### ### Create the .htaccess file if (isset($dir_id) && $dir_id > 0) { ### GENERATE THE EXCLUDE LIST $exclude_list = $this->exclude_list(); ### GENERATE THE .HTACCESS FILE $nl = "\n"; $data = $this->htaccess_extra . 'RewriteEngine on' . $nl; if (empty($VAR['htaccess_dir_recursive'])) { $data .= 'RewriteRule ^(.*)/.*$ - [L]' . $nl; } $data .= 'RewriteRule ' . $exclude_list . '$ htaccess_index.php?_HTACCESS_ID=' . $id . '&_HTACCESS_DIR_ID=' . $dir_id; ### Update the db record $db =& DB(); $sql = "UPDATE " . AGILE_DB_PREFIX . "htaccess_dir SET\n\t\t\t\t htaccess = " . $db->qstr($data) . " WHERE\n\t\t\t\t id = " . $db->qstr($dir_id) . " AND\n\t\t\t\t site_id = " . $db->qstr(DEFAULT_SITE); $result = $db->Execute($sql); ### WRITE THE LOCAL .HTACCESS FILE $fp = fopen($filename, "w+"); fwrite($fp, $data); fclose($fp); ### WRITE THE htaccess_index.php FILE $php_filename = $VAR['htaccess_dir_path'] . 'htaccess_index.php'; $data = $this->create_php(); $fp = fopen($php_filename, "w+"); fwrite($fp, $data); fclose($fp); } }
function view($VAR) { global $smarty; $this->construct(); $type = "view"; $this->method["{$type}"] = split(",", $this->method["{$type}"]); $db = new CORE_database(); $db->view($VAR, $this, $type); ### Define the group mapping.... $id = @$VAR['id']; ### Get the variables for this map plugin: $db =& DB(); $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'db_mapping WHERE id = ' . $db->qstr(@$VAR["id"]) . ' AND site_id = ' . $db->qstr(DEFAULT_SITE); $result = $db->Execute($sql); ### error reporting: if ($result === false) { global $C_debug; $C_debug->error('db_mapping.inc.php', 'view', $db->ErrorMsg()); return; } $file = $result->fields['map_file']; $group_map = $result->fields['group_map']; if ($group_map != '') { $group_map = unserialize($group_map); } else { $group_map = array(); } if ($file != '') { include_once PATH_PLUGINS . 'db_mapping/' . $file . '.php'; eval('$_MAP = new map_' . strtoupper($file) . ';'); ### If this map type is 'db' groups based: if ($_MAP->map['group_type'] == 'db' || $_MAP->map['group_type'] == 'db-status') { ### Connect to the DB & get the groups: $dbm = new db_mapping(); $db = $dbm->DB_connect($id, 'false'); eval('@$db_prefix = DB2_PREFIX' . strtoupper($file) . ';'); $sql = "SELECT * FROM " . $db_prefix . "" . $_MAP->map['group_map']['table'] . "\n\t\t\t\t\t\t\t ORDER BY " . $_MAP->map['group_map']['name']; $db2 = $db->Execute($sql); if ($db2 === false) { global $C_debug; $C_debug->error('db_mapping.inc.php', 'view', $db->ErrorMsg()); $smarty->assign('db_mapping_result', $db->ErrorMsg()); return; } ### get the remote groups... if ($db2->RecordCount() > 0) { $i = 0; while (!$db2->EOF) { $smart[$i]['id'] = $db2->fields[$_MAP->map['group_map']['id']]; $smart[$i]['name'] = $db2->fields[$_MAP->map['group_map']['name']]; $db2->MoveNext(); $i++; } ### Get the local groups: $db =& DB(); $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'group WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' ORDER BY name'; $groups = $db->Execute($sql); if ($groups === false) { global $C_debug; $C_debug->error('db_mapping.inc.php', 'view', $db->ErrorMsg()); return; } if ($groups->RecordCount() > 0) { $i = 0; while (!$groups->EOF) { $id = $groups->fields['id']; $smartgr[$i]['id'] = $groups->fields['id']; $smartgr[$i]['name'] = $groups->fields['name']; for ($ii = 0; $ii < count($smart); $ii++) { $rid = $smart[$ii]['id']; $name = $smart[$ii]['name']; $checked = false; if (isset($group_map[$id][$rid]) && $group_map[$id][$rid] != false) { $checked = true; } $smartgr[$i]['remote'][$ii]['id'] = $rid; $smartgr[$i]['remote'][$ii]['name'] = $name; $smartgr[$i]['remote'][$ii]['check'] = $checked; } $groups->MoveNext(); $i++; } ### Define smarty vars $smarty->assign('db_mapping_result', false); $smarty->assign('db_mapping_template', 'db_mapping:group_map_' . $_MAP->map['group_type']); $smarty->assign('db_mapping_groups', $smartgr); } else { global $C_translate; $message = $C_translate->translate('no_local_groups', 'db_mapping', ''); $smarty->assign('db_mapping_result', $message); } } else { global $C_translate; $message = $C_translate->translate('no_remote_groups', 'db_mapping', ''); $smarty->assign('db_mapping_result', $message); } } elseif ($_MAP->map['group_type'] == 'status') { ### This is at 'status' based database map ### Get the local groups: $db =& DB(); $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'group WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' ORDER BY name'; $groups = $db->Execute($sql); ### error reporting: if ($groups === false) { global $C_debug; $C_debug->error('db_mapping.inc.php', 'view', $db->ErrorMsg()); return; } if ($groups->RecordCount() > 0) { $i = 0; while (!$groups->EOF) { $id = $groups->fields['id']; $smart[$i]['id'] = $groups->fields['id']; $smart[$i]['name'] = $groups->fields['name']; @($smart[$i]['value'] = $group_map[$id]); $groups->MoveNext(); $i++; } } ### Assign the smarty vars: $smarty->assign('db_mapping_result', false); $smarty->assign('db_mapping_template', 'db_mapping:group_map_status'); $smarty->assign('db_mapping_groups', $smart); } else { ### No group mapping for this database map global $C_translate; $message = $C_translate->translate('no_group_mapping', 'db_mapping', ''); $smarty->assign('db_mapping_result', $message); } } else { global $C_translate; $message = $C_translate->translate('file_error', 'db_mapping', ''); $smarty->assign('db_mapping_result', $message); } }
function update($VAR) { $type = "update"; $this->method["{$type}"] = explode(",", $this->method["{$type}"]); $db = new CORE_database(); $db->update($VAR, $this, $type); # update the voip_sip table fields $db =& DB(); $rs = $db->Execute(sqlSelect($db, "voip_did", "did", "id=::" . $VAR['id'] . "::")); #echo "<pre>".print_r($VAR,true)."</pre>"; $f[0]['username'] = $VAR['sip_username']; $f[1]['secret'] = $VAR['sip_secret']; $f[2]['qualify'] = $VAR['sip_qualify']; $f[3]['mailbox'] = $VAR['sip_mailbox']; $f[4]['incominglimit'] = $VAR['sip_incominglimit']; $f[5]['dtmfmode'] = $VAR['sip_dtmfmode']; $f[6]['canreinvite'] = $VAR['sip_canreinvite']; $f[7]['callerid'] = $VAR['sip_callerid']; $f[8]['nat'] = $VAR['sip_nat']; for ($i = 0; $i < 9; $i++) { #echo "<pre>".print_r($f[$i],true)."</pre>"; $k = key($f[$i]); $v = $f[$i][$k]; if (empty($v)) { $sql = "DELETE FROM " . AGILE_DB_PREFIX . "voip_sip WHERE sip=" . $db->qstr($rs->fields['did']) . " and keyword=" . $db->qstr($k) . " and site_id=" . DEFAULT_SITE; } else { $rs2 = $db->Execute(sqlSelect($db, "voip_sip", "id", "sip=::" . $rs->fields['did'] . ":: AND keyword=::" . $k . "::")); if ($rs2 && $rs2->fields[0] > 0) { $sql = "UPDATE " . AGILE_DB_PREFIX . "voip_sip SET data=" . $db->qstr($v) . " WHERE sip=" . $db->qstr($rs->fields['did']) . " and keyword=" . $db->qstr($k) . " and site_id=" . DEFAULT_SITE; } else { $flds['data'] = $v; $flds['keyword'] = $k; $flds['sip'] = $rs->fields['did']; $sql = sqlInsert($db, "voip_sip", $flds); # $sql = "INSERT INTO ".AGILE_DB_PREFIX."voip_sip SET data=".$db->qstr($v)." WHERE sip=".$db->qstr($rs->fields['did'])." and keyword=".$db->qstr($k)." and site_id=".DEFAULT_SITE; } } if (!$db->Execute($sql)) { echo $db->ErrorMsg(); } } }