* @copyright 2009 Deon George * @link http://osb.leenooks.net * * @link http://www.agileco.com/ * @copyright 2004-2008 Agileco, LLC. * @license http://www.agileco.com/agilebill/license1-4.txt * @author Tony Landis * @package AgileBill * @subpackage Module:Staff */ /** * The main AgileBill Staff Class * * @package AgileBill * @subpackage Module:Staff */ class staff extends OSB_module { /** * EMAIL ONE STAFF MEMBER */ 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']; # Nothing to do if ($s > 0) { } elseif($d > 0) { # Verify the specified department && get the associated account: $db = &DB(); $dept = $db->Execute(sqlSelect($db,'staff_department','default_staff_id')); 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(); $staff = $db->Execute(sqlSelect($db,'staff','account_id')); 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']; $account = $db->Execute(sqlSelect($db,'account','email,first_name,last_name')); 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(); $rs = $db->Execute(sqlSelect($db,'static_relation','static_var_id')); $var_id = $rs->fields['static_var_id']; $rs = $db->Execute(sqlSelect($db,'static_var','name')); $name = $rs->fields['name']; $ul = str_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(); $setup_email = $db->Execute(sqlSelect($db,'setup_email','*')); $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(); } } ?>