'doNew',
'preview' => 'doPreview',
'list' => 'doList',
'cancel' => 'doBack',
'insert' => 'doInsert',
'edit' => 'doEdit',
'update' => 'doUpdate',
'save_company_template' => 'doSaveLocationTemplate',
'save_as_company_template' => 'doSaveAsLocationTemplate',
'load_company_template' => 'doLoadLocationTemplate',
'del_company_template' => 'doDeleteLocationTemplate',
'test' => 'doTest',
'choose_recipients' => 'doChooseRecipients',
'save_recipients' => 'doSaveRecipients',
'send' => 'doSend',
'done' => 'doDone',
'show_legal_agreement' => 'doShowLegalAgreement',
'start_send' => 'doStartSend',
'get_report' => 'doGetReport',
'get_img_size' => 'doGetImageSize'
);
var $moneyFields = array('property_size'=>'Size');
var $adminEnd = false;
var $sendServerPort = BROADCAST_SERVER_PORT;
var $sendServerIp = '127.0.0.1';
function initAction()
{
// Check For Legal Agreement
//if ($this->DBObj->memberData['is_accepted_broadcast_legal_agreement'] == 'n') {
// $this->action = 'show_legal_agreement';
//}
// END Check For Legal Agreement
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('BroadcastEmail/BroadcastEmail.php', $_REQUEST['id']);
$this->DBObj->memberData = $this->Doc->MemberAuth->getData();
$this->initAction();
if (in_array($this->action, array('choose_recipients', 'save_recipients', 'send', 'done', 'start_send'))
&& !$this->hasAccess2ChooseRecipients()
) {
$this->Doc->showMessageAccessDeny();
return false;
}
if (method_exists($this, $this->actionMethod)) {
$function = $this->actionMethod;
$this->$function();
} else {
exit;
}
}
function _getBaseForm($method = 'post')
{
require_once 'class/Form/Form.class.php';
$form = new Form($this->Doc, 'form_'.strtolower(get_class($this->DBObj)), $method, '', '_self', array('class'=>'form form_'.strtolower(get_class($this->DBObj))));
return $form;
}
function _bindFormFields($form)
{
$form->setAttribute('onsubmit', 'try { var myValidator = validate_broadcast_form; } catch(e) { return true; } return myValidator(this);');
$elList = $this->formCreateRadioboxList($form, 'id_type', $this->DBObj->getDEmailType4Select());
$form->addGroup($elList, 'broadcast_type', '', '', false);
/*$specialtyList = $this->DBObj->getDSpecialty4Select('sorter', "profile = 'y'");
$elList = $this->formCreateRadioboxList($form, 'id_specialty', $specialtyList);
$form->addGroup($elList, 'subjectRadiogroup2', '', '
', false);*/
$types = $this->DBObj->getDEmailSubType4Select();
$elList = $this->formCreateRadioboxList($form, 'listing_type', $types);
$form->addGroup($elList, 'listing_type', '', '', false);
$form->addElement('advcheckbox', 'listing_investment', '',
'Check here to list this as an investment opportunity in the archive', array(), array('n', 'y'));
$elList = $this->formCreateCheckboxList($form, 'requirements_type', $types);
$form->addGroup($elList, 'requirements_type', '', '', false);
$form->addElement('advcheckbox', 'requirements_investment', '',
'Check here to list this as an investment opportunity in the archive', array(), array('n', 'y'));
$groups = $this->DBObj->getDEmailGroupType4Select();
$elList = $this->formCreateCheckboxList($form, 'group_type', array_slice($groups, 0, 4, true));
$form->addGroup($elList, 'group_type_1', '', '', false);
$elList = $this->formCreateCheckboxList($form, 'group_type', array_slice($groups, 4, 4, true));
$form->addGroup($elList, 'group_type_2', '', '', false);
$elList = $this->formCreateCheckboxList($form, 'group_type', array_slice($groups, 8, null, true));
$form->addGroup($elList, 'group_type_3', '', '', false);
$locations = $this->DBObj->getDPropertyLocation4Select();
$elList = $this->formCreateRadioboxList($form, 'location_id', array_slice($locations, 0, 7, true));
$form->addGroup($elList, 'location_1', '', '', false);
$elList = $this->formCreateRadioboxList($form, 'location_id', array_slice($locations, 7, null, true));
$form->addGroup($elList, 'location_2', '', '', false);
$primaryUse = $this->DBObj->db->queryAll("SELECT id, title, `type` as class FROM mn_DPrimaryUse ORDER BY sorter");
$elList = $this->formCreateRadioboxList($form, 'primary_use_id', array_slice($primaryUse, 0, 5, true));
$form->addGroup($elList, 'primary_use_1', '', '', false);
$elList = $this->formCreateRadioboxList($form, 'primary_use_id', array_slice($primaryUse, 5, null, true));
$form->addGroup($elList, 'primary_use_2', '', '', false);
$form->addElement('radio', 'market_group', '', 'Twin Cities Market', 'twin_cities');
$form->addElement('radio', 'market_group', '', 'Out of Metro Markets', 'out_of_metro');
$form->addElement('select', 'market_subgroup', '', array(''=>'Choose An Intended Use') + (array)$this->DBObj->getDSpecialty4Select('sorter', "is_subcategory = 'y'"));
$form->addElement('text', 'property_size_min', 'Size', array('style'=>'width:129px;'));
$form->addElement('text', 'property_size_max', 'Size', array('style'=>'width:129px; margin:0 0 0 1px'));
$form->addElement('advcheckbox', 'use_range', '', 'Check this box to enter a size range', array('id'=>'use_range'), array('n', 'y'));
$elList = $this->formCreateRadioboxList($form, 'property_unit', array('sf'=>'square feet', 'acres'=>'acres'));
$form->addGroup($elList, 'gPropertyUnit', '', '', false);
$form->addElement('text', 'additional_text', 'Additional Text', array('style'=>'width:500px;'));
$form->addElement('text', 'subject', 'Subject', array('readonly'=>'readonly', 'class'=>'subject inp_width', 'style'=>'width:500px', 'size'=>'155'));
$form->addElement('file_db', 'attachment', 'Attachment');
if ($this->adminEnd) {
$FCKFilesPath = $this->DBObj->getEmailFckFilesPath($this->DBObj->id);
} else {
$FCKFilesPath = $this->DBObj->getIndividualFckFilesPath();
}
$body = &$form->createElement('html_editor_basic_img', 'body', 'Message Body', null, null, $FCKFilesPath);
$body->width = ($this->Doc->content['DOC']['handler'] == 'SiteDoc')?880:615;
$body->height = 550;
$form->addElement($body);
$tplList = $this->DBObj->getLocationTemplate4Select('title', 'id_parent='.intval($this->DBObj->memberData['id_location']));
if ($this->DBObj->isAccess4TemplateManagment($this->DBObj->memberData['id']) || !empty($tplList)) {
$form->addElement('select', 'id_location_msg_template', '', array(''=>'Use a broker template > Choose One') + $tplList);
}
$form->addElement('advcheckbox', 'signature_info_enabled', '', 'Include Following Signature Information', null, array('n','y'));
$form->addElement('textarea', 'signature_info', null, array('rows'=>5, 'style'=>'width:100%;'));
$this->Doc->addItemProp('JSs', 'js/broadcast_email_form.js');
$this->Doc->addItemProp('initFuncsEx', array('name'=>'initBroadcastEmailFormStep1', 'params'=>array(
$form->_attributes['id'],
)));
$form->addFormRule(array($this, 'validForm'));
return $form;
}
function validForm($data)
{
$this->fixMoneyFields($data);
$err = array();
if (empty($data['subject'])) {
$err['subject'] = 'Subject is required';
}
if ($data['id_type'] != 3 && empty($data['property_size_min'])) {
$err['property_size_min'] = 'Size is required';
}
if (empty($data['body'])) {
$err['body'] = 'Message Body is required';
}
$regex_numeric = "/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/";
foreach ($this->moneyFields as $name=>$title) {
if (!empty($data[$name]) && !preg_match($regex_numeric, $data[$name])) {
$err[$name] = $title.' is in wrong format';
}
}
if (is_uploaded_file($_FILES['attachment']['tmp_name']['file']) && intval($_FILES['attachment']['size']['file']) > 1572864) {
$err['attachment'] = 'File is too large';
}
$this->DBObj->initMarketsFromArray($data);
if ($data['id_type'] == 1 && $data['market_group'] == 'twin_cities') {
$markets = current($data['id_area']);
if (empty($markets)) {
$err['market_group'] = 'Please check at least one of the checkboxes for Twin Cities Market';
}
}
return (empty($err)) ? true : $err;
}
function doNew()
{
$form = $this->_getNewForm();
$areaListByType = $this->DBObj->getDAreaByType();
$data = array(
'id_type'=>'1',
'location_id'=>0,
'primary_use_id'=>0,
'listing_type'=>0,
'requirements_type' => array(),
'group_type' => array(),
'property_unit' => 'sf',
'listing_investment' => 'n',
'signature_info_enabled' => 'y',
'signature_info' => $this->DBObj->memberData['email_signature'],
'market_group' => 'twin_cities',
'id_area' => array(4=>key($areaListByType[4]['items'])),
);
/*
$areaListByType = $this->DBObj->getDAreaByType();
foreach ($areaListByType as $id_type => $type) {
foreach ($type['items'] as $id_area => $title) {
$data['id_area'][$id_type][$id_area] = $id_area;
}
}*/
$this->DBObj->deleteNotCompletedEmails();
$data['id_individual'] = $this->DBObj->memberData['id'];
$id = $this->DBObj->insert($data);
require_once('class/HTTP.php');
skHTTP::redirect(BASE_URL.'/'.CURR_PAGE_FULL.'?action=edit&id='.$id);
//$form->setDefaults($data);
//$this->renderForm($form);
}
function checkAccess()
{
$err = array();
if (!$this->DBObj->isEmailOwner()) {
$err[] = 'Invalid email identifier';
}
if (empty($err)) {
return true;
}
$this->Doc->addContent(array('tpl'=>'msg_error.tpl', 'text'=>implode('
', $err)));
return false;
}
function doEdit()
{
$this->DBObj->initFromDB();
if(!$this->DBObj->isCompleted()) {
if (!$this->checkAccess()) {
return false;
}
$form = $this->_getEditForm();
$form->setDefaults($this->DBObj->getData());
$this->renderForm($form);
} else {
require_once('class/HTTP.php');
skHTTP::redirect(BASE_URL.'/'.CURR_PAGE_FULL);
}
}
function doInsert()
{
$form = $this->_getNewForm();
if ($form->validate()){
$this->DBObj->initFromForm($form );
$this->fixMoneyFields($this->DBObj->_data);
$id = $this->DBObj->insert();
require_once('class/HTTP.php');
skHTTP::redirect(BASE_URL.'/'.CURR_PAGE_FULL.'?action=preview&id='.$id);
}else {
$this->renderForm($form);
}
return true;
}
function doUpdate()
{
$form = $this->_getEditForm();
if ($form->validate()){
$this->DBObj->initFromForm($form);
$this->fixMoneyFields($this->DBObj->_data);
$this->DBObj->update();
require_once('class/HTTP.php');
skHTTP::redirect(BASE_URL.'/'.CURR_PAGE_FULL.'?action=preview&id='.$this->DBObj->id);
}else {
$this->renderForm($form);
}
return true;
}
function renderForm($form)
{
$form->setTpl(SiteMap::getPath('BroadcastEmail/tpl/form_step1.tpl'));
$form->setRendType(FORM_RENDERER_ARRAY_SMARTY);
$form->return_form_arr = true;
$item = $form->exec();
$item['tabs'] = $this->getTabMenu();
$item['allow_manage_template'] = $this->DBObj->isAccess4TemplateManagment($this->DBObj->memberData['id']);
//vdie($item);
$this->Doc->addContent($item);
}
function formCreateRadioboxList(&$form, $name, $list)
{
if (!is_array($list) || empty($list)) {
return false;
}
$elList = array();
foreach ($list as $id => $title) {
$elList[$id.'_open'] = $form->createElement('static', $name . '_open', '', '
' ); $separators[] = ''; $elList = array_merge($elList, $this->formCreateRadioboxList($form, $elName, $list)); $separators = array_merge($separators, $this->getSeparators4Table($list, $cntCol)); $separators[] = ''; $elList[] = $form->createElement('static', 'static_'.$elName, '', ' |