function contact($VAR) { global $C_translate, $C_debug, $C_vars; ## Validate the required vars (account_id, message, subject) if (@$VAR['mail_email'] != "" && @$VAR['mail_name'] != "" && @$VAR['mail_subject'] != "" && @$VAR['mail_message'] != "") { include_once PATH_CORE . 'validate.inc.php'; $validate = new CORE_validate(); if (!$validate->validate_email($VAR['mail_email'], '')) { $C_debug->alert($C_translate->translate('validate_email', '', '')); $C_vars->strip_slashes_all(); return; } @($s = $VAR['mail_staff_id']); @($d = $VAR['mail_department_id']); if ($s > 0) { ## Nothing to do } else { if ($d > 0) { ## Verify the specified department && get the associated account: $db =& DB(); $sql = 'SELECT default_staff_id FROM ' . AGILE_DB_PREFIX . 'staff_department WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND id = ' . $db->qstr($d); $dept = $db->Execute($sql); if ($dept->RecordCount() == 0) { $C_debug->alert($C_translate->translate('error_dept_non_exist', 'staff', '')); $C_vars->strip_slashes_all(); return; } $s = $dept->fields['default_staff_id']; } else { ## staff/dept not specified $C_debug->alert($C_translate->translate('error_staff_dept', 'staff', '')); $C_vars->strip_slashes_all(); return; } } ## Verify the specified staff account && get the associated account: $db =& DB(); $sql = 'SELECT account_id FROM ' . AGILE_DB_PREFIX . 'staff WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND id = ' . $db->qstr($s); $staff = $db->Execute($sql); if ($staff->RecordCount() == 0) { $C_debug->alert($C_translate->translate('error_staff_non_exist', 'staff', '')); $C_vars->strip_slashes_all(); return; } $account_id = $staff->fields['account_id']; $sql = 'SELECT email,first_name,last_name FROM ' . AGILE_DB_PREFIX . 'account WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND id = ' . $db->qstr($account_id); $account = $db->Execute($sql); if ($account->RecordCount() == 0) { $C_debug->alert($C_translate->translate('error_staff_non_exist', 'staff', '')); $C_vars->strip_slashes_all(); return; } ### Validate any static vars, if defined $this->validated = true; if (!empty($VAR['static_relation'])) { 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('staff', $this->val_error); if ($all_error != false && gettype($all_error) == 'array') { $this->validated = false; } else { $this->validated = true; # Get the fields and values and append to the message text... while (list($id, $value) = each($VAR['static_relation'])) { if (!empty($value) && !empty($id)) { # Get the name: $db =& DB(); $sql = "SELECT static_var_id FROM " . AGILE_DB_PREFIX . "static_relation WHERE\n\t\t\t\t\t\t\t\t id \t\t= " . $db->qstr($id) . " AND\n\t\t\t\t\t\t\t\t site_id \t= " . $db->qstr(DEFAULT_SITE); $rs = $db->Execute($sql); $var_id = $rs->fields['static_var_id']; $sql = "SELECT name FROM " . AGILE_DB_PREFIX . "static_var WHERE\n\t\t\t\t\t\t\t\t id \t\t= " . $db->qstr($var_id) . " AND\n\t\t\t\t\t\t\t\t site_id \t= " . $db->qstr(DEFAULT_SITE); $rs = $db->Execute($sql); $name = $rs->fields['name']; $ul = preg_replace("/\\./", "-", $name); $VAR['mail_message'] .= "\r\n\r\n"; $VAR['mail_message'] .= "{$ul}"; $VAR['mail_message'] .= "\r\n"; $VAR['mail_message'] .= "{$name}"; $VAR['mail_message'] .= "\r\n"; $VAR['mail_message'] .= "{$ul}"; $VAR['mail_message'] .= "\r\n"; $VAR['mail_message'] .= "{$value}"; } } } } 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']); } global $C_vars; $C_vars->strip_slashes_all(); return; } ################################################################ ## OK to send the email: $E['from_html'] = true; $E['from_name'] = $VAR['mail_name']; $E['from_email'] = $VAR['mail_email']; $db =& DB(); $q = "SELECT * FROM " . AGILE_DB_PREFIX . "setup_email WHERE\n\t\t\t\t\tsite_id = " . $db->qstr(DEFAULT_SITE) . " AND\n\t\t\t\t\tid = " . $db->qstr(DEFAULT_SETUP_EMAIL); $setup_email = $db->Execute($q); $E['priority'] = $VAR['mail_priority']; $E['html'] = '0'; $E['subject'] = $VAR['mail_subject']; $E['body_text'] = $VAR['mail_message']; $E['to_email'] = $account->fields['email']; $E['to_name'] = $account->fields['first_name']; if ($setup_email->fields['type'] == 0) { $type = 0; } else { $type = 1; $E['server'] = $setup_email->fields['server']; $E['account'] = $setup_email->fields['username']; $E['password'] = $setup_email->fields['password']; } if ($setup_email->fields['cc_list'] != '') { $E['cc_list'] = explode(',', $setup_email->fields['cc_list']); } if ($setup_email->fields['bcc_list'] != '') { $E['bcc_list'] = explode(',', $setup_email->fields['bcc_list']); } ### Call the mail() or smtp() function to send require_once PATH_CORE . 'email.inc.php'; $email = new CORE_email(); if ($type == 0) { $email->PHP_Mail($E); } else { $email->SMTP_Mail($E); } } else { ## Error message: $C_debug->alert($C_translate->translate('error_req_fields', 'staff', '')); $C_vars->strip_slashes_all(); return; } ## Success message: $C_debug->alert($C_translate->translate('mail_sent', 'staff', '')); # Stripslashes $C_vars->strip_slashes_all(); }
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 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 user_add($VAR) { $this->construct(); global $C_debug, $C_translate, $C_vars, $smarty; ### Strip Slashes global $VAR; $C_vars->strip_slashes_all(); #################################################################### ### Check that the required fields are set: ### ticket_department_id, ticket_subject, ticket_body #################################################################### $fields = array('priority', 'department_id', 'subject', 'body'); for ($i = 0; $i < count($fields); $i++) { $field = $fields[$i]; $field_name = $this->table . '_' . $field; if (!isset($VAR["{$field_name}"]) || trim($VAR["{$field_name}"]) == "") { $this->val_error[] = array('field' => $this->table . '_' . $field, 'field_trans' => $C_translate->translate('field_' . $field, $this->module, ""), 'error' => $C_translate->translate('validate_any', "", "")); } } #################################################################### ### 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($this->module, $this->val_error); if ($all_error != false && gettype($all_error) == 'array') { $this->validated = false; } else { $this->validated = true; } ### Validate e-mail if (!SESS_LOGGED) { include_once PATH_CORE . 'validate.inc.php'; $C_validate = new CORE_validate(); if (empty($VAR['ticket_email'])) { $this->validated = false; $smarty->assign('ticket_email', true); $all_error[] = array('field' => 'ticket_email', 'field_trans' => $C_translate->translate('field_email', "ticket", ""), 'error' => $C_translate->translate('validate_any', "", "")); } elseif (!$C_validate->validate_email(@$VAR['ticket_email'], false)) { $this->validated = false; $smarty->assign('ticket_email', true); $all_error[] = array('field' => 'ticket_email', 'field_trans' => $C_translate->translate('field_email', "ticket", ""), 'error' => $C_translate->translate('validate_email', "", "")); } $this->email = $VAR['ticket_email']; } else { # Get the e-mail addy from the user's account $db =& DB(); $sql = 'SELECT email FROM ' . AGILE_DB_PREFIX . 'account WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND id = ' . $db->qstr(SESS_ACCOUNT); $result = $db->Execute($sql); $VAR['ticket_email'] = $result->fields['email']; $this->email = $result->fields['email']; } ################################################################### ### Check that the user is authorized for this department $db =& DB(); $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'ticket_department WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND id = ' . $db->qstr($VAR['ticket_department_id']) . ' AND status = ' . $db->qstr('1'); $result = $db->Execute($sql); if ($result->RecordCount() == 0) { ################################################################### ### ERROR: The selected department is inactive or invalid $C_debug->alert($C_translate->translate('department_invalid', 'ticket', '')); return false; } global $C_auth; $i = 0; $dept_auth = false; while (!$result->EOF) { $arr = unserialize($result->fields['group_id']); if (!SESS_LOGGED) { ### Check if the specified department is authorized for the 'All Users' group (0): for ($i = 0; $i < count($arr); $i++) { if ($arr[$i] == '0') { $dept_auth = true; } } if (!$dept_auth) { $C_debug->alert($C_translate->translate('login_required', '', '')); return false; } } else { for ($i = 0; $i < count($arr); $i++) { if ($C_auth->auth_group_by_id($arr[$i])) { $dept_auth = true; } } } $result->MoveNext(); } if (!$dept_auth) { ################################################################### ### ERROR: The current user does not have access to the selected department! $C_debug->alert($C_translate->translate('department_not_auth', 'ticket', '')); return false; } else { #################################################################### # 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']); } global $C_vars; $C_vars->strip_slashes_all(); return; } ################################################################### ### Assemble the SQL & Insert the ticket $db =& DB(); $id = $db->GenID(AGILE_DB_PREFIX . 'ticket_id'); $sql = 'INSERT INTO ' . AGILE_DB_PREFIX . 'ticket SET site_id = ' . $db->qstr(DEFAULT_SITE) . ', id = ' . $db->qstr($id) . ', date_orig = ' . $db->qstr(time()) . ', date_last = ' . $db->qstr(time()) . ', date_expire = ' . $db->qstr(time() + 86400 * 7) . ', account_id = ' . $db->qstr(SESS_ACCOUNT) . ', department_id=' . $db->qstr($VAR['ticket_department_id']) . ', status = ' . $db->qstr(0) . ', last_reply = 0, priority = ' . $db->qstr($VAR['ticket_priority']) . ', subject = ' . $db->qstr($VAR['ticket_subject']) . ', email = ' . $db->qstr($VAR['ticket_email']) . ', body = ' . $db->qstr(htmlspecialchars($VAR['ticket_body'])); $result = $db->Execute($sql); # error reporting: if ($result === false) { global $C_debug; $C_debug->error('ticket.inc.php', 'user_add', $db->ErrorMsg()); return false; } ################################################################### ### Insert the static vars... $static_var->add($VAR, $this->module, $id); ################################################################### ### Mail the user the new_ticket email template require_once PATH_MODULES . 'email_template/email_template.inc.php'; $VAR['email'] = trim($this->email); $VAR['key'] = $this->key($this->email); $my = new email_template(); $my->send('ticket_user_add', $this->email, $id, '', ''); unset($VAR['key']); unset($VAR['email']); ################################################################### ### Get any staff members who should be mailed $db =& DB(); $sql = 'SELECT id,account_id,department_avail FROM ' . AGILE_DB_PREFIX . 'staff WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND notify_new = ' . $db->qstr("1"); $result = $db->Execute($sql); if ($result->RecordCount() > 0) { while (!$result->EOF) { @($avail = unserialize($result->fields['department_avail'])); for ($i = 0; $i < count($avail); $i++) { if ($avail[$i] == $VAR['ticket_department_id']) { ################################################################### ### Mail staff members the new_ticket email template $my = new email_template(); $my->send('ticket_user_add_staff', $result->fields['account_id'], $id, $avail[$i], 'sql3'); $i = count($avail); } } $result->MoveNext(); } } } global $C_debug, $C_translate; $C_debug->alert($C_translate->translate('user_add_success', 'ticket', '')); }
function update($VAR) { #################################################################### ### 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('affiliate', $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; } # special handling for the affiliate data array if (isset($VAR['affiliate_plugin_data']) && is_array($VAR['affiliate_plugin_data'])) { while (list($key, $val) = each($VAR['affiliate_plugin_data'])) { if (get_magic_quotes_gpc()) { $VAR['affiliate_plugin_data']["{$key}"] = htmlentities(stripcslashes($val), ENT_QUOTES); } } } $type = "update"; $this->method["{$type}"] = explode(",", $this->method["{$type}"]); $db = new CORE_database(); $db->update($VAR, $this, $type); ### Update the static vars: $static_var->update($VAR, 'affiliate', $VAR['affiliate_id']); }