'doNew', 'insert' => 'doInsert', 'thanks' => 'doThanks', 'send_error'=> 'doSendError', ); var $concat_form_title = false; function exec(&$Doc) { $this->Doc = &$Doc; $this->DBObj = SiteMap::getObj('Member/SupportRequest/SupportRequest.php'); if (!$this->Doc->SupportAccountAuth->isLogged()) { $this->initAction(); $this->callAction(); } else { $this->Doc->addContent(array('tpl'=>'msg_error.tpl', 'text'=>'You can not send support invitation.')); } } 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) { $form->addElement('text', 'support_email', 'Support Person Email', array('class'=>'inp_email', 'size'=>80)); $form->addRuleRequired(array('support_email')); $form->addRule('support_email', 'Support Person Email is in wrong format', 'email'); $form->addRule('support_email', 'Support Person Email is in wrong format', 'email', null, 'client'); $form->addFormRule(array($this, 'validForm')); return $form; } function validForm($data) { $err = array(); $memberData = $this->DBObj->getMemberbyEmail($data['support_email']); if (is_array($memberData) && !empty($memberData)) { if ($memberData['is_support_account'] != 'y') { $err['support_email'] = 'This account is not a Support Member account. You cannot invite members, which are not Support Members.'; } else if ($this->DBObj->isAlreadyAssigned($this->Doc->MemberAuth->getData('id'), $data['support_email'])) { $err['support_email'] = 'This person already supports your account'; } } return (empty($err)) ? true : $err; } function setFormTitle() { return false; } function renderForm(&$form) { $form->setCancelType(''); $form->_requiredNote = ''; $form->setSubmitTitle('Send Invitation'); $form->exec(); } function doInsert() { $form = $this->_getNewForm(); if ($form->validate()) { $this->DBObj->initFromForm($form); $supportAccount = $this->DBObj->getMemberByEmail($this->DBObj->getData('support_email')); $this->DBObj->_data['id_member'] = $this->Doc->MemberAuth->getData('id'); if (!is_array($supportAccount) || empty($supportAccount)) { $this->DBObj->_data['access_code'] = $this->DBObj->getUniqueAccessCode(); } else { $this->DBObj->_data['id_support_account'] = $supportAccount['id']; } $this->DBObj->insert(); $this->DBObj->initFromDB(); $data = $this->DBObj->getData(); if (is_array($supportAccount) && !empty($supportAccount)) { $ret = $this->sendEmail( $data, $this->Doc->MemberAuth->getData(), $data['support_email'], 'MNCAR.ORG. Support Invitation', 'email2registered.tpl' ); } else { $ret = $this->sendEmail( $data, $this->Doc->MemberAuth->getData(), $data['support_email'], 'MNCAR.ORG. Support Invitation', 'email2unregistered.tpl' ); } if (!$ret) { $this->setBackUrl(BASE_URL.'/'.CURR_PAGE.'?action=send_error'); } $this->setBackUrl(BASE_URL.'/'.CURR_PAGE.'?action=thanks'); $this->doBack(); } else { $this->renderForm($form); } return true; } function sendEmail($request, $member, $email, $subject, $tpl) { require_once('class/Const.php'); Constant::set('DEBUG', false); $this->Doc->assign('request', $request); $this->Doc->assign('member', $member); $this->Doc->setMainTpl('Member/SupportRequest/'.$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($subject); $mail->setHeader('X-Mailer', 'HTML Mime mail class'); return $mail->send(array($email)); } function doThanks() { $this->Doc->addContent(array('tpl'=>'Member/SupportRequest/thanks.tpl')); } function doSendError() { $this->Doc->addContent(array('tpl'=>'msg_error.tpl', 'text'=>'Email Send Error')); } }