'doView', 'insert' => 'doSendBroadcastEmail', ); 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'; } } function exec(&$Doc) { $this->Doc = &$Doc; $this->DBObj = SiteMap::getObj('Member/Activation/Activation.php'); $this->initAction(); if (method_exists($this, $this->actionMethod)) { $function = $this->actionMethod; $this->$function(); } else { exit; } } function doView() { $form = $this->_getNewForm(); $this->renderForm($form); $this->_saveBackUrl(); } function renderForm($form) { $form->return_form_arr = true; $item = $form->exec(); $item['report'] = $this->DBObj->getBroadcastActivationReport(); $this->Doc->addContent($item); } function _bindFormFields($form) { $form->addElement('radio', 'send_to', '', 'Send To All Members', 'all'); $form->addElement('radio', 'send_to', '', 'Send To Custom Members', 'custom'); $form->addElement('checkbox', 'force', '', 'Force sending all not activated'); $form->addElement('textarea', 'custom_emails', '', array('cols'=>'80', 'rows'=>'10')); $form->setRendType(FORM_RENDERER_ARRAY_SMARTY); $form->setTpl(BASE_PATH.'/tpl/Member/Activation/broadcast_view.tpl'); $form->addFormRule(array($this, 'validForm')); return $form; } function validForm($data) { $err = array(); if ($data['send_to'] == 'custom') { $emails = preg_replace('/[\r\n]+/',' ', $data['custom_emails']); $emails = split('[, ;]', $emails); $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/'; foreach ($emails as $k => $v) { if (!strlen(trim($v, ',; '))) unset($emails[$k]); } if (empty($emails)) { $err['custom_emails'] = 'Email list is required'; } else { $emails = array_unique($emails); $errEmails = array(); foreach ($emails as $k => $email) { if (!preg_match($regex, $email)) { $errEmails[] = $email; } } if (count($errEmails)) { $err['custom_emails'] = 'Wrong email address (' . implode(', ', $errEmails) . ')'; } } } return (empty($err))?true:$err; } function doSendBroadcastEmail() { $form = $this->_getNewForm(); if ($form->validate()) { $data = $form->exportValues(); if ($data['send_to'] == 'all') { $this->DBObj->sendBroadcastEmail($this->Doc, isset($_REQUEST['force'])); } else { $emails = $this->parseEmails($data['custom_emails']); $this->DBObj->sendBroadcast2CustomEmails($this->Doc, isset($_REQUEST['force']), $emails); } $this->doBack(); } $this->renderForm($form); } function parseEmails($emails) { $emails = preg_replace('/[\r\n]+/',' ', $emails); $emails = split('[, ;]', $emails); foreach ($emails as $k => $v) { if (!strlen(trim($v, ',; '))) unset($emails[$k]); } return $emails; } }