'doView',
'verify' => 'doVerify',
'new' => 'doNew',
'insert' => 'doInsert',
);
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->activationCode = $_REQUEST['activation_code'];
$data = $this->DBObj->getMemberByActivationCode($this->activationCode);
if (!is_array($data) || empty($data)) {
$this->Doc->addContent(array('tpl'=>'msg_error.tpl', 'text'=>'Invalid Activation Code'));
return;
}
$this->DBObj->memberData = $data;
$this->DBObj->id = intval($data['id']);
$this->initAction();
if (method_exists($this, $this->actionMethod)) {
$function = $this->actionMethod;
$this->$function();
} else {
exit;
}
}
function doView()
{
$this->DBObj->initFromDB();
$form = $this->getFrom4Step2();
$data = $this->DBObj->getData();
$data['id_email_area'] = $this->DBObj->getEmailAreaIdsFromDB($this->DBObj->tableNameDB.'2EmailArea', $data['id']);
$data['id_email_type'] = $this->DBObj->getIdsFromDB($this->DBObj->tableNameDB.'2EmailType', $this->DBObj->db->tblDEmailType, 'id_email_type', $data['id']);
$data['id_email_specialty'] = $this->DBObj->getIdsFromDB($this->DBObj->tableNameDB.'2EmailSpecialty', $this->DBObj->db->tblDSpecialty, 'id_specialty', $data['id']);
$form->setDefaults($data);
$this->renderFormStep2($form);
}
function renderFormStep2($form)
{
$form->return_form_arr = true;
$item = array();
$item['form'] = $form->exec();
$elHTML = &$item['form']['sections'][0]['elements'][0]['elements'][0]['html'];
$elHTML = '
Broadcast email categories have changed. Please review the options below and update your settings
'.$elHTML;
$item['member'] = $this->DBObj->getData();
$item['tpl'] = 'Member/Activation/account-information.tpl';
$this->Doc->addContent($item);
}
function doNew()
{
$form = $this->_getNewForm();
$this->renderForm($form);
$this->Doc->content['DOC']['title'] = 'Choose Your Password';
}
function setFormTitle(&$form, $title)
{
return false;
}
function getFrom4Step2()
{
$form = $this->_getBaseForm();
$form = $this->_bindFormFieldsStep2($form);
$form->addElement('hidden', 'action', 'verify');
return $form;
}
function _bindFormFieldsStep2($form)
{
if ($this->DBObj->memberData['allow_mcpe_access'] == 'y') {
$this->formAddSectionBroadcastEmailPreferences($form);
$form->removeElement('gSpecificSenders');
}
$form->addElement('hidden', 'activation_code', $this->DBObj->getData('activation_code'));
$form->setCancelType('');
$form->setSubmitTitle('Continue Activation');
return $form;
}
function _bindFormFields($form)
{
$form->addElement('hidden', 'activation_code', $this->activationCode);
$form->addElement('password', 'password', 'Choose a password');
$form->addElement('password', 'confirm_password', 'Re-type the password');
$form->setConstants(array('password' => '', 'confirm_password' => ''));
$form->addRuleRequired(array('password', 'confirm_password'));
$form->addElement('radio', 'agree', null, 'I agree', 'y');
$form->addElement('radio', 'agree', null, 'I do not agree', 'n');
$form->addRule('agree', 'Agree is required', 'required');
$form->addRule('agree', 'Agree is required', 'required', null, 'client');
$form->addFormRule(array($this, 'validForm'));
return $form;
}
function renderForm(&$form)
{
$this->Doc->content['ITEMS'] = array();
$form->return_form_arr = true;
$form->setRendType(FORM_RENDERER_ARRAY_SMARTY);
$form->setTpl(SiteMap::getPath('Member/tpl/Activation/choose_password.tpl'));
$form->setSubmitTitle('FINISH ACTIVATION OF MY ACCOUNT');
$form->setCancelType('');
$item = $form->exec();
require_once('app/Settings/Settings.php');
$item['legal_agreement'] = Settings::get('legal_agreement');
$this->Doc->addContent($item);
}
function validForm($data)
{
$err = array();
if ($data['password'] != $data['confirm_password']) {
$err['password'] = 'Passwords entries do not match';
}
if ($data['agree'] != 'y') {
$err['agree'] = 'In order to take advantage of the sites new features, you must agree to the terms in the user agreement.';
}
return (empty($err))?true:$err;
}
function doInsert()
{
$form = $this->_getNewForm();
if ($form->validate()) {
require_once('class/HTTP.php');
$this->DBObj->initFromForm($form);
$this->DBObj->_initTable();
$this->DBObj->table->update(array('password'=>$this->DBObj->getData('password'), 'activation_code'=>null, 'is_accepted_legal_agreement'=>'y'), 'id='.intval($this->DBObj->id));
$this->DBObj->initFromDB();
$this->sendEmail($this->DBObj->getData());
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.'/account');
}
$msg = 'Use MY ACCOUNT to view and update your profile, view your CE credit history,
customize your MNCAR homepage, and more!';
$this->Doc->MemberAuth->setSessionData($msg, 'my_account_tip');
$ret = $this->Doc->MemberAuth->login(array(
'member_login'=>$this->DBObj->getData($this->DBObj->login_field),
'member_password'=>$this->DBObj->getData($this->DBObj->pass_field),
));
skHTTP::redirect(BASE_URL.'/'.SiteMap::getAliasByItemType('Member/Login').'?member_login='.$this->DBObj->getData($this->DBObj->login_field));
} else {
$this->renderForm($form);
}
return true;
}
function sendEmail($data)
{
require_once('class/Const.php');
Constant::set('DEBUG', false);
$this->Doc->assign('item', $data);
$this->Doc->setMainTpl('Member/Activation/thanks_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 Account Activation Complete');
$mail->setHeader('X-Mailer', 'HTML Mime mail class');
$mail->send(array($data['email']));
}
function doVerify()
{
$form = $this->getFrom4Step2();
if ($form->validate()){
if ($this->DBObj->memberData['allow_mcpe_access'] == 'y') {
$this->DBObj->initFromForm4Step2($form);
$this->DBObj->updateProfile();
}
$activation_code = strval(@$_REQUEST['activation_code']);
$ret = $this->DBObj->verifyAccountInformation($activation_code);
if (is_string($ret)) {
$this->Doc->addContent(array('tpl'=>'msg_error.tpl', 'text'=>$ret));
return;
}
require_once('class/HTTP.php');
skHTTP::redirect(BASE_URL.'/'.CURR_PAGE.'?action=new&activation_code='.$ret['activation_code']);
} else {
$this->renderFormStep2($form);
}
}
}