'doNew', 'insert' => 'doInsert', 'thanks' => 'doThanks', 'send_error'=> 'doSendError', ); var $concat_form_title = false; function exec(&$Doc) { $this->Doc = &$Doc; $this->DBObj = SiteMap::getObj('SupportAccount/SupportAccount.php'); $this->initAction(); $this->callAction(); } protected function initAction() { if (empty($this->action)) { if (isset($_REQUEST['action']) && !empty($_REQUEST['action'])) { $this->action= $_REQUEST['action']; } else { $this->action = $this->defaultAction; } } if (key_exists($this->action, $this->actions)){ $this->actionMethod = $this->actions[$this->action]; } else { $this->action = key($this->actions); $this->actionMethod = current($this->actions); } if ($this->isXmlHttpRequest()) { $this->actionMethod .= 'Ajax'; } } protected function callAction() { if (method_exists($this, $this->actionMethod)) { $this->{$this->actionMethod}(); } } function _bindFormFields($form) { if (!$this->Doc->SupportAccountAuth->isLogged()) { $gName = array(); $gName[] = $form->createElement('text', 'first_name', '*First Name ', array('size'=>25, 'class'=>'first_name')); $gName[] = $form->createElement('text', 'middle_initial', 'Middle Initial ', array('size'=>1, 'maxlength'=>1, 'class'=>'middle_initial')); $gName[] = $form->createElement('text', 'last_name', '*Last Name ', array('size'=>25, 'class'=>'last_name')); $form->addGroup($gName, 'gName', 'Your Name', ' ', false); $form->addGroupRule('gName', array( 'first_name'=>array( array('First Name is required', 'required'), array('First Name is required', 'required', null, 'client'), ), 'last_name'=>array( array('Last Name is required', 'required'), array('Last Name is required', 'required', null, 'client'), ) )); /* $phoneFormat = ' Format: (xxx) xxx-xxxx'; $this->formAddTitledPhone($form, 'primary_phone', 'Primary Phone #'); $this->formAddTitledPhone($form, 'secondary_phone', 'Secondary Phone #'); $form->addElement('extended_text', 'fax', 'Direct Fax Number', array('class'=>'titled_phone', 'onblur'=>'hidehint(this);', 'onfocus'=>'showhint(this);', 'onkeyup'=>"formatPhone(this);"), null, $phoneFormat); $this->formAddPhoneRule($form, array('fax')); */ $form->addElement('text', 'email', 'Your Email Address', array('class'=>'inp_email', 'size'=>80)); $form->addRuleRequired(array('email')); $form->addRule('email', 'Your Email Address is in wrong format', 'email'); $form->addRule('email', 'Your Email Address is in wrong format', 'email', null, 'client'); } //$form->addElement('header', 'header_member_request', 'MEMBER EMAIL'); $form->addElement('text', 'request_email', 'Member Email Address', array('class'=>'inp_email', 'size'=>80)); $form->addRuleRequired(array('request_email')); if (!$this->Doc->SupportAccountAuth->isLogged()) { require_once('class/Session.php'); $id_session = Session::getId(); if (defined('SESSION_DONOT_HANDLE')) { session_write_close(); } require_once 'HTML/QuickForm/CAPTCHA/Image.php'; session_id($id_session); session_start(); $options = array( 'width' => 100, 'height' => 50, 'callback' => BASE_URL.'/qfcaptcha_image.php?var=contimg&sid='.$id_session, 'sessionVar' => 'contimg', 'imageOptions' => array( 'font_size' => 20, 'text_color' => '#003300', 'lines_color' => '#003300', 'background_color' => '#DCDAD3', 'font_path' => WWW_PATH.'/fonts', 'font_file' => 'Action Man Shaded Italic.ttf' )); $captcha_question =& $form->addElement('CAPTCHA_Image', 'captcha_question', 'Image', $options); $form->addElement('extended_text', 'captcha', 'Image Code', array('maxlength'=>4, 'style'=>'width:95px;'), 'To verify this is not a spam attempt, please enter the image code you see above in the text box below
'); $form->addRule('captcha', 'Image Code is required', 'required', null, 'client'); $form->addRule('captcha', 'The code you\'ve entered doesn\'t match the image.', 'CAPTCHA', $captcha_question); $form->applyFilter('captcha', 'strtolower'); if (defined('SESSION_DONOT_HANDLE')) { session_write_close(); } } $form->addFormRule(array($this, 'validForm')); return $form; } function doNew() { $form = $this->_getNewForm(); $this->renderForm($form); $this->setBackUrl(BASE_URL.'/'.CURR_PAGE.'?action=thanks'); } function validForm($data) { $err = array(); $requestMember = $this->DBObj->getMemberByEmail($data['request_email']); if (!is_array($requestMember) || empty($requestMember) || $requestMember['is_support_account'] == 'y'){ $err['request_email'] = 'There is no member with such email. Please enter another email.'; return $err; } if ($this->Doc->SupportAccountAuth->isLogged()) { $ids_member = (array)$this->Doc->SupportAccountAuth->getData('ids_member'); if (intval($requestMember['id']) && array_key_exists(intval($requestMember['id']), $ids_member)) { $err['request_email'] = $ids_member[$requestMember['id']].' already authorized'; } } return (empty($err))?true:$err; } function formAddTitledPhone(&$form, $elName, $label, $phoneFormat = ' Format: (xxx) xxx-xxxx', $regex = "/^\(\d{3}\)\s*\d{3}\s*-\s*\d{4}(\s.*)?$/") { return MemberGrid::formAddTitledPhone($form, $elName, $label, $phoneFormat, $regex); } function setFormTitle() { return false; } function renderForm(&$form) { $form->setCancelType(''); $form->setSubmitTitle('Send Request'); $form->exec(); } function doInsert() { $form = $this->_getNewForm(); if ($form->validate()) { $this->DBObj->initFromForm($form); $requestMemberData = $this->DBObj->getMemberByEmail($this->DBObj->_data['request_email']); $supportAccountData = $this->Doc->SupportAccountAuth->getData(); if ($this->Doc->SupportAccountAuth->isLogged()) { $this->DBObj->_data = array_merge($this->DBObj->_data, $supportAccountData); $this->DBObj->_data['id_support_account'] = $supportAccountData['id']; unset($this->DBObj->_data['added'], $this->DBObj->_data['changed'], $this->DBObj->_data['access_code']); } $this->DBObj->_data['id_requested_member'] = $requestMemberData['id']; $this->DBObj->insert(); $this->DBObj->initFromDB(); $data = $this->DBObj->getData(); $ret = $this->sendRequestEmail2Member($data, $data['request_email']); if (!$ret) { $this->setBackUrl(BASE_URL.'/'.CURR_PAGE.'?action=send_error'); } $this->doBack(); } else { $this->renderForm($form); } return true; } function doThanks() { $this->Doc->addContent(array('tpl'=>'SupportAccount/Request/thanks.tpl')); } function doSendError() { $this->Doc->addContent(array('tpl'=>'msg_error.tpl', 'text'=>'Email Send Error')); } function sendRequestEmail2Member($data, $email) { require_once('class/Const.php'); Constant::set('DEBUG', false); $this->Doc->assign('item', $data); $this->Doc->setMainTpl('SupportAccount/Request/email.tpl'); $html = $this->Doc->fetch(); require_once ('lib/htmlMimeMail/htmlMimeMail.php'); $mail = new htmlMimeMail(); $mail->setHtml($html); require_once('app/Settings/Settings.php'); $mail->setFrom(Settings::get('admin_email_from')); $mail->setSubject('MNCAR.ORG. Request Support Account'); $mail->setHeader('X-Mailer', 'HTML Mime mail class'); return $mail->send(array($email)); } }