'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->access_code = $_GET['access_code']; // $_GET['access_code'] - значення брати з $_GET масиву, тому що в $_COOKIE лежить змінна з такою ж назвою
$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 _getBaseForm($method = 'post')
{
require_once 'class/Form/Form.class.php';
$action = Constant::get('BASE_URL').'/'.CURR_PAGE_FULL.'?access_code='.$this->access_code;
$form = new Form($this->Doc, 'form_'.strtolower(get_class($this->DBObj)), $method, $action, '_self', array('class'=>'form form_'.strtolower(get_class($this->DBObj))));
return $form;
}
function _bindFormFields($form)
{
//$form->addElement('header', 'header_personal_information', 'PERSONAL INFORMATION');
$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', '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', 'Email Address', array('class'=>'inp_email', 'size'=>80));
$form->addRuleRequired(array('email'));
$form->addRule('email', 'Email Address (Web Site Login) is in wrong format', 'email');
$form->addRule('email', 'Email Address (Web Site Login) is in wrong format', 'email', null, 'client');
$form->addElement('password', 'password', 'Web Site Password', array('class'=>'inp_password'));
$form->addElement('password', 'confirm_password', 'Confirm Password', array('class'=>'inp_password'));
$form->setConstants(array('password' => '', 'confirm_password' => ''));
$form->addFormRule(array($this, 'validForm'));
return $form;
}
function validForm($data)
{
$err = array();
if (!$this->DBObj->isUniqueMemberEmail($data['email'])){
$err['email'] = 'Email must be unique';
}
if ($data['password'] != $data['confirm_password']) {
$err['password'] = 'Web Site Password and Confirm password entries do not match';
}
return (empty($err))?true:$err;
}
function _getNewForm()
{
$form = $this->_getBaseForm();
$form = $this->_bindFormFields($form);
$form->addElement('hidden', 'action', 'insert') ;
$form->addRuleRequired(array('password', 'confirm_password'));
return $form;
}
function doNew()
{
$data = $this->DBObj->getFromDBByAccessCode($this->access_code);
if (!is_array($data) || empty($data)) {
$this->Doc->addContent(array('tpl'=>'msg_error.tpl', 'text'=>'Invalid Access Code'));
return;
}
$form = $this->_getNewForm();
$form->setDefaults($data);
$this->renderForm($form);
$this->setBackUrl(BASE_URL.'/'.CURR_PAGE.'?action=thanks');
}
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('Submit');
$form->exec();
}
function doInsert()
{
$data = $this->DBObj->getFromDBByAccessCode($this->access_code);
if (!is_array($data) || empty($data)) {
$this->Doc->addContent(array('tpl'=>'msg_error.tpl', 'text'=>'Invalid Access Code'));
return;
}
$form = $this->_getNewForm();
if ($form->validate()) {
$this->DBObj->initFromForm($form);
$this->DBObj->_data['id_location']=$this->DBObj->db->queryOne('SELECT id_location FROM mn_Member WHERE id='.(int)$data['id_requested_member']);
// vdie('reg',$data,$this->DBObj->_data);
$id = $this->DBObj->register();
$requestMemberData = $this->DBObj->getMemberByEmail($data['request_email']);
$updateData = array(
'id_support_account' => $requestMemberData['id'],
'access_code' => null
);
$this->DBObj->_initTable();
$ret = $this->DBObj->table->update($updateData, 'id='.intval($data['id']));
if (true !== ($error = $this->DBObj->assignMember($id, $requestMemberData['id']))) {
//
}
require_once('class/Session.php');
$url = Session::getData($this->Doc->MemberAuth->ses_arr_name, 'login_to');
if (empty($url)) {
Session::setData($this->Doc->MemberAuth->ses_arr_name, 'login_to', BASE_URL);
}
$this->sendEmail($data, $data['email'], 'MNCAR.ORG. Support Account Registration Complete', 'email_registration_complete.tpl');
$ret = $this->Doc->MemberAuth->login(array(
'member_login'=>$this->DBObj->getData('email'),
'member_password'=>$this->DBObj->getData('password'),
));
} else {
$this->renderForm($form);
}
return true;
}
function doThanks()
{
$this->Doc->addContent(array('tpl'=>'SupportAccount/Registration/thanks.tpl'));
}
function doSendError()
{
$this->Doc->addContent(array('tpl'=>'msg_error.tpl', 'text'=>'Email Send Error'));
}
function sendEmail($data, $email, $subject, $tpl)
{
require_once('class/Const.php');
Constant::set('DEBUG', false);
$this->Doc->assign('item', $data);
$this->Doc->setMainTpl('SupportAccount/Registration/'.$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));
}
}