'doView',
'deactivate' => 'doDeactivate',
'cancel' => 'doBack',
'update' => 'doUpdate',
'renderHowUsed' => 'doRenderHowUsed',
'remove_my_account_tip' => 'doRemoveMyAccountTip',
'close_access_tip' => 'doCloseAccessTip',
'touch' => 'doTouch',
);
/**
* @var SiteDoc
*/
public $Doc;
/**
* @var App_Member_MyAccount_Obj
*/
public $DBObj;
protected $_pages = array(
'mncarExchange' => 'cdx-auto-login-request',
'ceCredits' => array('Member/CECreditHistory/Show', 'list'),
'learningCenter' => array('HTMLBlock/Show', 'exchange/training_materials_overview.php'),
'broadcastEmail' => array('BroadcastEmail'),
'mncarFocus' => array('HTMLBlock/Show', 'account/focus-monthly-e-newsletter-settings.html'),
'annualReport' => array('HTMLBlock/Show', 'resource.html/annual_market_reports.html'),
'notableTransactions' => array('HTMLBlock/Show', 'resource/notabletransactions'),
);
var $linkTextLength = 55;
var $_noteSentRequest = ' [Sent Request]';
var $_btnRequestValue = 'Request Access to Pay All Location Exchange Dues Online';
function exec($Doc)
{
$this->Doc = $Doc;
$member = $this->Doc->MemberAuth->getData();
$this->DBObj = new App_Member_MyAccount_Obj($member['id']);
$this->DBObj->memberData = $member;
$this->setBackUrl(BASE_URL.'/'.CURR_PAGE);
parent::exec();
}
public function doView()
{
$member = $this->Doc->MemberAuth->getData();
$item = array('tpl' => 'Member/MyAccount/view.tpl');
$this->_pages['updateAccount'] = CURR_PAGE . '#profile';
foreach ($this->_pages as $name => $options) {
if (is_string($options)) {
$item[$name . 'Url'] = $options;
} else if (is_array($options) && call_user_func_array(array($this->Doc, 'checkAcces2DocItem'), $options)) {
$item[$name . 'Url'] = call_user_func_array('SMGetAliasByItem', $options);
}
}
if ($this->Doc->checkAcces2DocItem('BroadcastEmail/Repository/Show')) {
if ($member['show_repository'] == 'y') {
$item['broadcastEmail'] = $this->DBObj->getBroadcastEmail();
}
}
$this->DBObj->initFromDB();
$data = $this->DBObj->getData();
$this->_initData4Form($data);
$form = $this->_getEditForm();
$form->setDefaults($data);
$item['editForm'] = $this->_renderEditForm($form);
if (null != $this->DBObj->getData('nrds_id')) {
$item['isAccessToRediNetLogin'] = true;
$item['rediNetLoginUrl'] = 'redi-net-login-request';
}
$this->Doc->addItem($item);
}
protected function _renderEditForm(Form $form)
{
$form->return_form_arr = true;
$form->setTpl(SiteMap::getPath('Member/tpl/profile.tpl'));
$form->setCancelType('');
$form->setButtonGroupCallback(array($this, 'bindFormButtons'));
$this->Doc->addItemProp('CSSs', 'css/jquery.fancybox.css');
$this->Doc->addItemProp('JSs', 'js/jquery.fancybox.js');
$this->Doc->addItemProp('JSs', 'js/lib/form.js');
$this->Doc->addInitFunction('$("#link-profile-how-used").fancybox');
$this->Doc->addItemProp('JSs', 'js/format_phone.js');
return $form->exec();
}
/**
* @param $form Form
* @return Form
*/
function _bindFormFields($form)
{
$this->Doc->addItemProp('JSs', 'js/member_profile_form.js');
$this->Doc->addItemProp('initFuncsEx', array('name'=>'initMemberProfileForm', 'params'=>array($form->_attributes['id'])));
//CONTACT INFORMATION
$form->addElement('header', 'header_contact_information', 'CONTACT INFORMATION');
$form->addElement('text', 'first_name', 'First Name ', array('size'=>25, 'class'=>'first_name'));
$form->addElement(
'extended_text',
'middle_initial',
'Middle Initial ',
array('size'=>1, 'maxlength'=>1, 'class'=>'middle_initial'),
'',
'(Change My Name)'
);
$form->addElement('text', 'last_name', 'Last Name ', array('size'=>25, 'class'=>'last_name'));
foreach (array('first_name', 'middle_initial', 'last_name') as $name) {
$form->getElement($name)->freeze();
}
$form->addRuleRequired(array('first_name', 'last_name'));
$this->formAddTitledPhone($form, 'primary_phone', 'Primary Phone #');
$this->formAddTitledPhone($form, 'secondary_phone', 'Secondary Phone #');
$form->addElement('extended_text', 'fax', 'Fax', array('class'=>'titled_phone', 'onblur'=>'hidehint(this);', 'onfocus'=>'showhint(this);', 'onkeyup'=>"formatPhone(this);"), null, ' Format: (xxx) xxx-xxxx');
//$linkChangeCompany = ' Change My Company';
$linkChangeCompany = ' (Change My Company)';
$linkChangeLocation = ' (Change My Office Location)';
$form->addElement('extended_text', 'company_name', 'Company Name', null, null, $linkChangeCompany)->freeze();
$form->addElement('extended_text', 'location_name', 'Location', null, null, $linkChangeLocation)->freeze();
$this->formAddPhoneRule($form, array('fax'));
$form->addElement('text', 'designations', 'Designations');
$this->_bindFormBirthDate($form);
$this->_bindFormIndustryExperience($form);
$form->addElement('text', 're_license_number', 'RE License');
$form->addElement('text', 'address', 'Home Address');
$this->_bindFormCityStateZip($form);
$form->addElement('img_db', 'img', 'Profile Picture');
/*/MNCAR BILLING PREFERENCES
$this->formAddSectionBillingPreferencesHeader($form);
$groupBilling = array();
$this->formAddSectionBillingPreferencesFields($form, $groupBilling);
$form->addGroup($groupBilling, 'gBilling', '', '
', false);
$memberData = $this->Doc->MemberAuth->getData();
if ('y' == $memberData['allow_mcpe_access'] && $memberData['id_location']) {
if ($memberData['location_id_pay_member'] == $memberData['id']) {
$form->addElement(
'extended_button',
'btn_want_pay',
'Cancel Exchange Invoice Access',
array('onclick' => 'return cancelExchangeInvoiceAccess(this)'),
'',
$this->_noteRequestApproved
);
$form->addElement('hidden', 'want_pay');
} else {
$attribs = array('onclick' => 'return wantPayOnClick(this)');
if ('y' == $memberData['want_pay']) {
$attribs['disabled'] = 'disabled';
$attribs['class'] = 'btn_disabled';
}
$form->addElement(
'extended_button',
'btn_want_pay',
$this->_btnRequestValue,
$attribs,
'',
('y' == $memberData['want_pay']) ? $this->_noteSentRequest : ''
);
}
$form->addElement('hidden', 'want_pay');
}
*/
// BROADCAST EMAIL PREFERENCES
if ($this->DBObj->isMCPEAccess()) {
$this->formAddSectionBroadcastEmailPreferences($form);
}
// YOUR BIO FOR YOUR ONLINE PROFILE
if ($this->DBObj->isAllowedBio()) {
$form->addElement('header', 'header_bio', 'YOUR ONLINE BIO');
$bio = &$form->createElement('html_editor_basic', 'bio');
$bio->width = 675;
$form->addElement($bio);
if ($this->DBObj->isAllowedBioCategories()) {
$this->formAddSectionBioCategories($form);
$this->formAddSectionProfileCategories($form);
$_header = $form->getElement('header_member_profile_categories');
$_header->setValue('YOUR MEMBER PROFILE CATEGORIES');
}
if ($this->DBObj->isAllowedTypeOfBusiness()) {
$this->formAddSectionTypeOfBusiness($form);
}
}
// MY MNCAR SETTINGS
$form->addElement('header', 'header_my_mncar_settings', 'MY MNCAR SETTINGS');
$form->addElement(
'extended_text',
'email',
'Email Address (Web Site Login)',
array('class'=>'inp_email', 'size' => 80),
'',
'(Change My Email Address)'
)->freeze();
$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('extended_password', 'password', 'Web Site Password', array('class'=>'inp_password'), null, '');
$this->Doc->addContent(array('tpl'=>'text.tpl', 'text'=>"
"));
$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->isUnique('email', $data['email'])){
$err['email'] = 'This email address (' . $data['email'] . ') is already in use by one of our site '
. 'members, please enter another one. ';
};
if (isset($_REQUEST['ch_passwd'])) {
if (empty($data['password'])) {
$err['password'] = 'Web Site Password is required';
} elseif($data['password'] != $data['confirm_password']) {
$err['password'] = 'Web Site Password and Confirm password entries do not match';
}
}
if (true !== ($_errors = $this->_validateFormSpecificEmails($data))) {
$err = array_merge($err, $_errors);
}
return (empty($err)?true:$err);
}
/**
* @param $form Form
* @return void
*/
public function bindFormButtons($form)
{
$elements = array();
$elements[] = $form->createElement('submit', 'btnSubmit', 'Save');
$elements[] = $form->createElement(
'button',
'btnSubmit',
'Save with No Changes',
array(
'id' => 'btn-save-with-no-changes',
'onclick' => 'document.location=\'' . $this->url(array('action' => 'touch')). '\''
)
);
$form->addGroup($elements, 'submit_grp', '', '
');
}
function _doSendMailWantPayRequest($item)
{
$subject = 'Request to Pay Exchange Dues Online';
$from = $item['last_name'] . ' ' . $item['first_name'];
if ($item['middle_initial']) {
$from .= ' ' . $item['middle_initial'] . '.';
}
require_once('app/Settings/Settings.php');
$from .= ' <' . $item['email'] . '>';
$to = Settings::getAdminEmails('billing_email');
$to = array_unique($to);
require_once('lib/htmlMimeMail/htmlMimeMail.php');
$mail = new htmlMimeMail();
$this->Doc->assign('item', $item);
Constant::set('DEBUG', false);
$html = $this->Doc->fetch(SiteMap::getPath('Member/tpl/Profile/email-want-pay-request.tpl'));
$mail->setSubject($subject);
$mail->setFrom($from);
$mail->setHtml($html);
foreach ($to as $email) {
$mail->send(array($email));
}
}
function doUpdate()
{
$this->DBObj->initFromDB();
$oldData = $this->DBObj->getData();
$form = $this->_getEditForm();
if ($form->validate()){
$this->DBObj->initFromForm($form);
$this->DBObj->update();
$this->DBObj->initFromDB();
$currentData = $this->DBObj->getData();
if (false !== ($diffEx = $this->dataChanged($oldData, $currentData))) {
$this->sendMailDataChanged($currentData, $diffEx);
}
Session::setData(CURR_PAGE, 'msg', $this->DBObj->itemName.' updated');
$this->doBack();
}else {
$this->renderForm($form);
}
return true;
}
function renderForm(&$form)
{
$item = $this->_renderEditForm($form);
$this->Doc->addItem($item);
}
function dataChanged($oldData, $currentData)
{
function array_add_key_prefix($array, $prefix)
{
$ret = array();
foreach ($array as $k=>$v) {
$ret[$prefix.$k] = $v;
}
return $ret;
}
function array_remove_key_prefix($array, $prefix)
{
$ret = array();
foreach ($array as $k=>$v) {
$ret[str_replace($prefix, '', $k)] = $v;
}
return $ret;
}
unset($currentData['changed'], $oldData['changed']);
$oldData['id_email_area'] = array_add_key_prefix($oldData['id_email_area'], '_');
$currentData['id_email_area'] = array_add_key_prefix($currentData['id_email_area'], '_');
$diff = array_diff_recursive($currentData, $oldData);
$diffInv = array_diff_recursive($oldData, $currentData);
$diffMerged = array_merge_recursive($diff, $diffInv);
if (!empty($diffMerged['id_email_area'])) {
$diffMerged['id_email_area'] = array_remove_key_prefix($diffMerged['id_email_area'], '_');
}
$oldData['id_email_area'] = array_remove_key_prefix($oldData['id_email_area'], '_');
$currentData['id_email_area'] = array_remove_key_prefix($currentData['id_email_area'], '_');
if (empty($diffMerged)) {
return false;
}
if (isset($diffMerged['primary_phone_title']) || isset($diffMerged['primary_phone'])) {
$diffMerged['primary_phone'] = $this->getTitledPhone($oldData, 'primary_phone');
}
if (isset($diffMerged['secondary_phone_title']) || isset($diffMerged['secondary_phone'])) {
$diffMerged['secondary_phone'] = $this->getTitledPhone($oldData, 'secondary_phone');
}
$diffEx = array();
$title = array(
'first_name' => 'First Name',
'middle_initial' => 'Middle Initial',
'last_name' => 'Last Name',
'primary_phone' => 'Primary Phone #',
'secondary_phone' => 'Secondary Phone #',
'fax' => 'Fax',
'img' => 'Profile Picture',
'bio' => 'Bio',
'id_area_info' => 'BIO CATEGORIES: Market Area of Specialty',
'id_specialty_info' => 'BIO CATEGORIES: Real Estate Specialty',
'id_area' => 'MEMBER PROFILE CATEGORIES: Market Area of Specialty',
'id_specialty' => 'MEMBER PROFILE CATEGORIES: Real Estate Specialty',
'id_line_of_work' => 'MEMBER PROFILE CATEGORIES: Line of work',
'other_line_of_work' => 'MEMBER PROFILE CATEGORIES: Line of work - Other',
'email' => 'Email Address (Web Site Login)',
'password' => 'Web Site Password',
'id_email_type' => 'BROADCAST EMAIL PREFERENCES: Type',
'id_email_specialty' => 'BROADCAST EMAIL PREFERENCES: Specialty',
'id_email_area' => 'BROADCAST EMAIL PREFERENCES: Area',
'specific_senders' => 'list of specific senders',
'billing_send_paper_copy' => 'Invoicing Options',
'want_pay' => 'Pay Exchange Dues Online',
're_license_number' => 'RE License',
'industry_experience' => 'Industry Experience (Years)',
'designations' => 'Designations',
'birth_date' => 'Birthdate',
'address' => 'Home Address',
'city' => 'City',
'state' => 'State',
'zip' => 'Zip',
);
foreach ($title as $name => $_title) {
if (array_key_exists($name, $diffMerged)) {
if ( in_array($name, array('primary_phone', 'secondary_phone'))) {
if (!isset($diffEx[$name]['old_value'])) {
$diffEx[$name] = array('title'=>$title[$name]);
$diffEx[$name]['old_value'] = $this->getTitledPhone($oldData, $name);
$diffEx[$name]['new_value'] = $this->getTitledPhone($currentData, $name);
}
} elseif (in_array($name, array('id_area_info', 'id_specialty_info', 'id_area', 'id_specialty', 'id_line_of_work', 'id_email_type', 'id_email_specialty'))) {
$diffEx[$name] = array('title'=>$title[$name]);
$diffEx[$name]['old_value'] = $this->getListOfCheckboxes($oldData[$name], $name);
$diffEx[$name]['new_value'] = $this->getListOfCheckboxes($currentData[$name], $name);
} elseif ($name == 'bio') {
$diffEx[$name] = array('title'=>$title[$name]);
$diffEx[$name]['old_value'] = $oldData[$name];
$diffEx[$name]['new_value'] = $currentData[$name];
} elseif ($name == 'want_pay') {
$diffEx[$name] = array('title'=>$title[$name]);
$values = array(
'y' => '[X]',
'n' => '[ ]'
);
$diffEx[$name]['old_value'] = $values[$oldData[$name]];
$diffEx[$name]['new_value'] = $values[$currentData[$name]];
} elseif ($name == 'billing_send_paper_copy') {
$diffEx[$name] = array('title'=>$title[$name]);
$values = array(
'y' => 'Standard Invoicing - paper invoice sent by mail',
'n' => 'Green Invoicing - electronic invoice sent by email with no paper copy'
);
$diffEx[$name]['old_value'] = $values[$oldData[$name]];
$diffEx[$name]['new_value'] = $values[$currentData[$name]];
} elseif ($name == 'id_email_area') {
$diffEx[$name] = array('title'=>$title[$name]);
$areaListByType = $this->DBObj->getDAreaByType();
foreach ($diffMerged[$name] as $id_type => $ids_area) {
$diffEx[$name]['items'][$id_type]['title'] = $areaListByType[$id_type]['title'];
$titleList = array_intersect_key($areaListByType[$id_type]['items'], $oldData[$name][$id_type]);
$diffEx[$name]['items'][$id_type]['old_value'] = implode(', ', $titleList);
$titleList = array_intersect_key($areaListByType[$id_type]['items'], $currentData[$name][$id_type]);
$diffEx[$name]['items'][$id_type]['new_value'] = implode(', ', $titleList);
}
} elseif ($name == 'birth_date') {
$diffEx[$name] = array('title' => $title[$name]);
$diffEx[$name]['old_value'] = htmlspecialchars(date('M/d', strtotime($oldData[$name])));
$diffEx[$name]['new_value'] = htmlspecialchars(date('M/d', strtotime($currentData[$name])));
} else {
$diffEx[$name] = array('title'=>$title[$name]);
$diffEx[$name]['old_value'] = htmlspecialchars($oldData[$name]);
$diffEx[$name]['new_value'] = htmlspecialchars($currentData[$name]);
}
}
}
return $diffEx;
}
function getTitledPhone($data, $name)
{
if (empty($data[$name]) && empty($data[$name.'_title'])) {
return '';
}
if ($data[$name.'_title'] == ' ') {
return 'Other: '.$data[$name];
}
if (empty($data[$name.'_title'])) {
return $data[$name];
}
return $data[$name.'_title'].': '.$data[$name];
}
function getListOfCheckboxes($list, $name)
{
switch($name){
case 'id_area_info' : $_list = $this->DBObj->getDArea4Select('sorter', "info = 'y'"); break;
case 'id_specialty_info' : $_list = $this->DBObj->getDSpecialty4Select('sorter', "info = 'y'"); break;
case 'id_area' : $_list = $this->DBObj->getDArea4Select('sorter', "profile = 'y'"); break;
case 'id_specialty' : $_list = $this->DBObj->getDSpecialty4Select('sorter', "profile = 'y'"); break;
case 'id_line_of_work' : $_list = $this->DBObj->getDLineOfWork4Select(); break;
case 'id_email_type' : $_list = $this->DBObj->getDEmailType4Select(); break;
case 'id_email_specialty' : $_list = $this->DBObj->getDSpecialty4Select('sorter', "broadcast = 'y'");break;
default: $_list = array();
}
$diff = array_diff_key($_list, $list);
$titles = array_diff_key($_list, $diff);
return implode(', ', $titles);
}
function sendMailDataChanged($currentData, $diff)
{
require_once('class/Const.php');
Constant::set('DEBUG', false);
$this->Doc->assign('member', $currentData);
$this->Doc->assign('diff', $diff);
$this->Doc->setMainTpl('Member/email2admin_data_changed.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. Member Profile Changed');
$mail->setHeader('X-Mailer', 'HTML Mime mail class');
return $mail->send(array(Settings::get('admin_email')));
}
function doDeactivate()
{
$id_individual = (int)$this->Doc->MemberAuth->getData('id');
$this->DBObj->deactivate($id_individual);
$this->Doc->MemberAuth->logout();
}
function doRemoveMyAccountTipAjax()
{
$this->Doc->MemberAuth->setSessionData(null, 'my_account_tip');
$data = array('success' => true);
$this->displayJSON($data);
}
function doCloseAccessTipAjax()
{
$this->DBObj->_initTable();
$id_member = (int)$this->Doc->MemberAuth->getData('id');
$this->DBObj->table->update(array('show_access_tip' => 'n'), 'id=' . $id_member);
$data = array('success' => true);
$this->displayJSON($data);
}
function doWantPayAjax()
{
$this->DBObj->updateRow(array('want_pay' => 'y'));
$this->_doSendMailWantPayRequest($this->DBObj->memberData);
$responce = array(
'success' => true,
'message' => 'Your request was succesfully sent to MNCAR staff',
'after' => $this->_noteSentRequest
);
$this->displayJSON($responce);
}
function doCancelExchengeInvoiceAccessAjax()
{
$this->DBObj->initFromDB();
$data = $this->DBObj->getData();
$this->DBObj->updateRow(array('want_pay' => 'n'));
if ($data['id_location'] && $data['id'] == $data['location_id_pay_member']) {
$this->DBObj->tableLocation->update(array('id_pay_member' => null), 'id=' . intval($data['id_location']));
}
$responce = array(
'success' => true,
'message' => 'Exchange Invoice Access was successfully canceled',
'value' => $this->_btnRequestValue
);
$this->displayJSON($responce);
}
function doRenderHowUsed()
{
die();
}
function doRenderHowUsedAjax()
{
Constant::set('DEBUG', false);
$this->Doc->assign('item', array('text' => Settings::get('profile_how_used')));
die($this->Doc->fetch('Member/Profile/how-used.tpl'));
}
function doTouch()
{
$this->DBObj->touch();
$this->setBackMessage('Profile change date has been updated');
$this->doBack();
}
}