'doList',
'new' => 'doNew',
'cancel' => 'doBack',
'insert' => 'doInsert',
'edit' => 'doEdit',
'update' => 'doUpdate',
'del' => 'doDelete',
'assign_nrds_id'=>'doAssignNrdsId',
'assign_manualy_nrds_id'=>'doAssignManualyNrdsId',
'clear_nrds_id' =>'doClearNrdsId',
'export_search' =>'doExportSearch',
'saveSearch' => 'doSaveSearch',
'deleteSearch' => 'doDeleteSearch',
'getSavedSearch' => 'doGetSavedSearch',
);
protected function _getNrdsIdAssignLinks()
{
return ' '
. ''
. 'Click to assign a NRDS Number'
. ' | '
. ''
. 'Click to assign Non MNCAR NRDS Number'
. ' | '
. ''
. 'Clear NRDS Number';
}
function _bindFormFields($form)
{
$this->Doc->addItemProp('JSs', 'js/admin_member_form.js');
$this->Doc->addItemProp('initFuncsEx', array('name'=>'initLocationForm', 'params'=>array(
$form->_attributes['id'],
intval($this->DBObj->getData('id_company')),
)));
$form->addElement('hidden', 'redirect_url');
$form->addElement('hidden', 'id_individual', $this->DBObj->id_individual);
// GENERAL LOCATION INFORMATION
$form->addElement('header', 'header_general_location_information', 'GENERAL LOCATION INFORMATION');
$form->addElement('select', 'status', 'Location Status', array('normal'=>'Normal', 'deleted'=>'Deteled'));
$form->addElement('hidden', 'id_company');
$form->addElement('static', 'company_special_element', 'Company', '
'.$this->DBObj->getData('company_name').'
(click here to change company)
set
');
if ($this->DBObj->id) {
$form->addElement(
'extended_text',
'nrds_id',
'NRDS ID',
array('class'=>'inp_nrds_id', 'size'=>15, 'readonly'=>'readonly'),
'',
$this->_getNrdsIdAssignLinks()
);
} else {
$form->addElement(
'static',
'nrds_not_available',
'NRDS ID',
'The ability to assign NRDS ID will be available once the location is successfully saved'
);
}
$form->addElement('extended_text', 'name', 'Location Name', null, null, '
Hint: Use the Street Address if no location name has been otherwised specified.
');
$form->addElement('select', 'id_type', 'Location Type', $this->DBObj->getDLocationType4Select());
$phoneFormat = ' Format: (xxx) xxx-xxxx';
$form->addElement('extended_text', 'phone', 'Location Phone Number', null, null, $phoneFormat);
$form->addElement('extended_text', 'fax', 'Location Fax Number', null, null, $phoneFormat);
$form->addElement('extended_text', 'website', 'Location Web Site', null, 'http://');
$form->addElement('text', 'contact_name', 'Office Contact Name');
$form->addElement('extended_text', 'contact_phone', 'Office Contact Phone #', null, null, $phoneFormat);
$form->addElement('advcheckbox', 'large_company', 'Large Company', '', null, array('n','y'));
$form->addElement('select', 'market_id', 'MNCAR Market', (array)$this->DBObj->getDMarket4Select());
$this->formAddPhoneRule($form, array('phone', 'fax', 'contact_phone'));
// LOCATION PHYSICAL ADDRESS
$form->addElement('header', 'header_location_physical_address', 'LOCATION PHYSICAL ADDRESS');
$form->addElement('text', 'physical_address', 'Street Address');
$gAddress = array();
$gAddress[] = $form->createElement('text', 'physical_city', 'City ', array('size'=>25, 'class'=>'city'));
$gAddress[] = $form->createElement('select', 'physical_state', 'State ', array(''=>'') + (array)$this->DBObj->getDState4Select());
$gAddress[] = $form->createElement('text', 'physical_zip', 'Zip Code ', array('size'=>25, 'class'=>'zip'));
$form->addGroup($gAddress, 'gPhysicalAddress', 'City, State, Zip Code', ' ', false);
// LOCATION MAILING ADDRESS
$form->addElement('header', 'header_location_mailing_address', 'LOCATION MAILING ADDRESS');
$form->addElement('advcheckbox', 'mailing_as_physical', null, 'Tick if the mailing address is the same as the physical address', null, array('n','y'));
$form->addElement('text', 'mailing_address', 'Street Address');
$gAddress = array();
$gAddress[] = $form->createElement('text', 'mailing_city', 'City ', array('size'=>25, 'class'=>'city'));
$gAddress[] = $form->createElement('select', 'mailing_state', 'State ', array(''=>'') + (array)$this->DBObj->getDState4Select());
$gAddress[] = $form->createElement('text', 'mailing_zip', 'Zip Code ', array('size'=>25, 'class'=>'zip'));
$form->addGroup($gAddress, 'gMailingAddress', 'City, State, Zip Code', ' ', false);
// EXCHANGE MEMBERSHIP INFORMATION
$form->addElement('header', 'header_exchange_membership_information', 'EXCHANGE MEMBERSHIP INFORMATION');
$form->addElement('select', 'allow_mcpe_access', 'Allow MCPE Access', array('n'=>'No', 'y'=>'Yes'));
$form->addElement('select', 'id_mcpe_access_type', 'MCPE Access Type', (array)$this->DBObj->getDMCPEAccessType4Select());
$form->addElement('extended_select', 'id_current_mcpe_status', 'Current MCPE Status',
array(0 => 'No Status') + (array)$this->DBObj->getDMemberStatus4Select(), null,
array('after'=>' Date of last status change: '.$this->DBObj->getData('mcpe_status_date'))
);
$form->addElement('advcheckbox', 'raw_datafeeds', 'Raw Data Feeds', '', null, array('n','y'));
$form->addElement('advcheckbox', 'data_feeds_office', 'Data Feeds - Office', '', null, array('n','y'));
$form->addElement('advcheckbox', 'data_feeds_individual', 'Data Feeds - Individual', '', null, array('n','y'));
$form->addElement('advcheckbox', 'templates', 'Templates', '', null, array('n','y'));
// KEY INDIVIDUAL SETTINGS
$form->addElement('header', 'header_key_individual_settings', 'KEY INDIVIDUAL SETTINGS');
$form->addElement('select', 'id_designated_realtor', 'Designated Realtor', (array)$this->DBObj->getRealtors4Select() + array(0=>'Other'));
$form->addElement('text', 'dr_name', 'DR Name');
$form->addElement('text', 'dr_email', 'DR Email');
$form->addElement('text', 'dr_phone', 'DR Phone');
$form->addElement('advmultiselect', 'ids_individual', array('Individuals With Permission to save
html email templates', 'No Pemission Given', 'Those With Permission'), $this->DBObj->getIndividuals4Select(), array('style'=>'width:250px'));
// LOCATION NOTES
$form->addElement('header', 'header_location_notes', 'LOCATION NOTES');
$form->addElement('textarea', 'note', null, array('cols'=>5, 'style'=>'width:100%'));
$form->addRuleRequired(array('name'));
$form->addFormRule(array($this, 'validForm'));
return $form;
}
function validForm($data)
{
$err = array();
$nrdsId = ctype_digit($data['nrds_id']) ? $data['nrds_id'] : 0;
if ($nrdsId) {
if (!$this->DBObj->isNRDSUniqueApplied($nrdsId, $this->DBObj->id)) {
$err['nrds_id'] = 'The NRDS ID must be unique';
} elseif (!empty($data['id_company'])
&& !$this->DBObj->isFreeNrdsAtCompany($nrdsId, $data['id_company'])) {
$err['nrds_id'] = MemberGrid::MSG_ERR_NRDS_NOT_UNIQUE_AT_COMPANY;
}
}
if (
intval($data['nrds_id'])
&& (
!$this->DBObj->isNRDSUniqueApplied($data['nrds_id'], $this->DBObj->id)
/*|| !$this->DBObj->isUnique('nrds_id', $data['nrds_id'])*/
)
){
$err['nrds_id'] = 'The NRDS ID must be unique';
}
return (empty($err))?true:$err;
}
function _getNewForm()
{
$form = $this->_getBaseForm();
$form = $this->_bindFormFields($form);
$form->removeElements('id_html_individual', 'id_realtor', 'header_key_individual_settings', 'pay_member');
$this->setFormTitle($form, 'Add '.$this->DBObj->itemName);
$form->addElement('hidden', 'action', 'insert') ;
return $form;
}
function doNew()
{
$this->DBObj->initFromDB();
$data = $this->DBObj->getData();
$form = $this->_getNewForm();
$form->setDefaults($data);
$this->renderForm($form);
}
function _getEditForm()
{
$form = parent::_getEditForm();
$data = $this->DBObj->getData();
$id = $form->createElement('static', 'location_id', 'Location ID', $data['id']);
$form->insertElementAfter($id, 'header_general_location_information');
$changed = &$form->createElement('static', 'changed', 'Last Updated');
$form->insertElementBefore($changed, 'id_company');
$added = &$form->createElement('static', 'added', 'Date Created');
$form->insertElementBefore($added, 'id_company');
if ($this->DBObj->getData('id_pay_member') && $this->DBObj->getData('pay_member')) {
$pay_member_html = ''
. $this->DBObj->getData('pay_member')
. '';
$pay_member = $form->createElement('static', 'pay_member_html', 'Billing Person', $pay_member_html);
} else {
$pay_member = $form->createElement('text', 'pay_member', 'Billing Person');
}
$form->insertElementBefore($pay_member, 'name');
$static_individual_cnt = $form->createElement('static', 'static_individual_cnt', '# of individuals within this location',
''.(int)$this->DBObj->getData('individual_cnt').''
.' | Click to add an individual'
);
$form->insertElementAfter($static_individual_cnt, 'nrds_id');
return $form;
}
function doEdit()
{
$this->DBObj->initFromDB();
$data = $this->DBObj->getData();
$form = $this->_getEditForm();
$form->setDefaults($data);
$this->renderForm($form);
}
function doInsert()
{
$form = $this->_getNewForm();
if ($form->validate()){
$this->DBObj->initFromForm($form );
$this->DBObj->insert();
$this->initTabRedirect();
if (empty($this->DBObj->_data['redirect_url'])) {
Session::setData(CURR_PAGE_FULL, 'msg', $this->DBObj->itemName.' added');
}
$this->doBack();
}else {
$this->renderForm($form);
}
return true;
}
function doUpdate()
{
$form = $this->_getEditForm();
if ($form->validate()){
$this->DBObj->initFromForm($form);
$this->DBObj->update();
$this->initTabRedirect();
if (empty($this->DBObj->_data['redirect_url'])) {
Session::setData(CURR_PAGE_FULL, 'msg', $this->DBObj->itemName.' updated');
}
$this->doBack();
}else {
$this->renderForm($form);
}
return true;
}
function renderForm(&$form)
{
$linkItem = array(
'tpl' => 'center_link.tpl',
'link' => Constant::get('BASE_URL').'/'.CURR_PAGE.'?action=cancel'.(($this->DBObj->id_individual)?'&id_individual='.$this->DBObj->id_individual:''),
'title' => '<< Back to list'
);
$this->Doc->addContent($linkItem);
$this->addTabHeader();
$form->exec();
$this->addTabFooter();
}
function getBackUrl()
{
$url = Session::getData(CURR_PAGE, 'query_string');
if (empty($url)) {
$url = BASE_URL.'/admin/location';
}
return $url;
}
function getTabs()
{
$tabs = array();
$tabs[] = array('alias'=>'admin/member?action=edit&id='.$this->DBObj->id_individual, 'title'=>'Individual Information');
$tabs[] = array('alias'=>'#', 'title'=>'Location Information', 'current'=>1);
$tabs[] = array('alias'=>'admin/member?action=edit_company&id='.$this->DBObj->id_individual, 'title'=>'Company Information');
return $tabs;
}
function addTabHeader()
{
if (!$this->DBObj->id_individual) {
return;
}
$item = array();
$item['tpl'] = 'Member/tab_header.tpl';
$item['tabs'] = $this->getTabs();
$this->Doc->addContent($item);
}
function addTabFooter()
{
if (!$this->DBObj->id_individual) {
return;
}
$item = array();
$item['tpl'] = 'Member/tab_footer.tpl';
$this->Doc->addContent($item);
}
function initTabRedirect()
{
if (!empty($this->DBObj->_data['redirect_url'])) {
$this->setBackUrl($this->DBObj->_data['redirect_url']);
} else {
$url = BASE_URL.'/'.CURR_PAGE_FULL.'?action=edit&id='.$this->DBObj->id;
if ($this->DBObj->id_individual) {
$url .= '&id_individual='.$this->DBObj->id_individual;
}
$this->setBackUrl($url);
}
}
function getFilterForm()
{
require_once('app/Member/Grid/Grid.php');
$form = MemberGrid::getFilterForm();
if(null == $form->getElementValue('search_type')) {
$form->getElement('search_type')->setValue('location');
}
return $form;
}
function _doListBind(&$DB_List)
{
// $DB_List->insertColLast('record_type', array(
// 'title'=>'Type of record',
// 'order_by'=>'record_type',
// 'width'=>60,
// 'tpl'=>DB_LIST_CELL_TEXT,
// 'params'=>array('record_type_title'),
// ));
$DB_List->insertColLast('individual_cnt', array(
'title'=>'# of Members',
'order_by'=>'individual_cnt',
'width'=>60,
'tpl'=>'Location/List/cells/link_members_cnt.tpl',
'url'=>BASE_URL.'/admin/member',
'params'=>array('id'),
));
if ($this->DBObj->filter['search_type']=='company') {
$DB_List->insertColLast('location_cnt', array(
'title'=>'# of Locations',
'order_by'=>'location_cnt',
'width'=>60,
'tpl'=>'Location/List/cells/link_location_cnt.tpl',
'url'=>BASE_URL.'/admin/location',
'params'=>array('id'),
));
}
$DB_List->insertColLast('nrds_id', array(
'title'=>'NRDS ID',
'order_by'=>'nrds_id',
'width'=>55,
'tpl'=>DB_LIST_CELL_TEXT,
'params'=>array('nrds_id'),
));
$DB_List->insertColLast('name', array(
'title'=>($this->DBObj->filter['search_type']=='company'?'Company':'Location').' name',
'order_by'=>'name',
'width'=>($this->DBObj->filter['search_type']=='company'?605:230),
'tpl'=>BASE_PATH.'/tpl/Location/List/cells/link.tpl',
'location_url'=>'admin/location?action=edit&id=',
'company_url'=>'admin/company?action=edit&id=',
'params'=>array('id','name'),
));
if ($this->DBObj->filter['search_type']!='company') {
$DB_List->insertColLast('company_name', array(
'title'=>'Company Name',
'order_by'=>'company_name',
'width'=>100,
'tpl'=>DB_LIST_CELL_TEXT,
'params'=>array('company_name'),
));
$DB_List->insertColLast('physical_city', array(
'title'=>'City',
'order_by'=>'physical_city',
'width'=>75,
'tpl'=>DB_LIST_CELL_TEXT,
'params'=>array('physical_city'),
));
$DB_List->insertColLast('address', array(
'title'=>'Address',
'order_by'=>'address',
'width'=>180,
'tpl'=>DB_LIST_CELL_TEXT,
'params'=>array('address'),
));
}
$DB_List->insertColLast('type', array(
'title'=>($this->DBObj->filter['search_type']=='company'?'Company':'Location').' Type',
'order_by'=>'type',
'width'=>65,
'tpl'=>DB_LIST_CELL_TEXT,
'params'=>array('type'),
));
$DB_List->insertColLast('options', array(
'title'=>'Options',
'width'=>80,
'tpl'=>BASE_PATH.'/tpl/Location/List/cells/options.tpl',
'params'=>array('id'),
));
$DB_List->def_order_by=name;
$DB_List->bind();
return true;
}
function addLink() {
require_once('app/Member/Grid/Grid.php');
return MemberGrid::addLink();
}
function getFilterForm4List($request = null)
{
if (null == $request) {
$request = $_REQUEST;
}
$filterForm = $this->getFilterForm();
if (isset($request['id_company']) && intval($request['id_company'])) {
$companyData = $this->DBObj->getCompanyById(intval($request['id_company']));
$filterForm->getElement('id_company')->addOption($companyData['name'], intval($request['id_company']));
$filterForm->getElement('search_type')->setValue('location');
} else {
$filterForm->removeElement('id_company');
}
$filterForm->removeElement('id_location');
return $filterForm;
}
function doList()
{
$this->addLink();
$savedSearchForm = MemberGrid::getSavedSearchForm();
$savedSearchForm->exec();
$filterForm = $this->getFilterForm4List();
$this->DBObj->filter = $filterForm->exportValues();
$filterForm->exec();
$this->DBObj->setFilter($filterForm->getElementValue('query'));
$this->_saveBackUrl();
require_once('class/DB/List/List.php');
$DB_List = new DB_List($this->Doc, $this->DBObj, $this->functionalFields);
$DB_List->urlVarNames = array_keys($this->DBObj->filter);
$DB_List->urlVarNames[] = 'ipp';
$this->_doListBind($DB_List);
$this->setIpp($DB_List);
$DB_List->exec();
return true;
}
function doAssignNrdsIdAjax()
{
$res = $this->DBObj->assignNrdsId($_REQUEST['record_type']);
$this->displayJSON($res);
}
function doAssignManualyNrdsIdAjax()
{
$res = $this->DBObj->assignManualyNrdsId($_REQUEST['record_type'], $_REQUEST['nrds_id']);
$this->displayJSON($res);
}
function doClearNrdsIdAjax()
{
if ($this->DBObj->id) {
$res = $this->DBObj->clearNrdsId();
} else {
$res = array('id'=>'');
}
$this->displayJSON($res);
}
function doExportSearch()
{
$filterForm = $this->getFilterForm4List();
$this->DBObj->filter = $filterForm->exportValues();
$this->DBObj->setFilter($filterForm->getElementValue('query'));
require_once('class/DB/List/List.php');
$DB_List = new DB_List($this->Doc, $this->DBObj, $this->functionalFields);
$this->_doListBind($DB_List);
$opt = array();
$opt['order_by'] = $DB_List->getOrderBy();
$res = $this->DBObj->_getRes4Grid($this->DBObj->_getWhat4Grid($opt), $opt);
if (PEAR::isError($res)) {
if (DEBUG) {
vdie('MemberGrid->doExportSearch error', $res->getUserInfo(), null, debug_backtrace());
} else {
sendDeveloperEmail($res->getUserInfo());
return;
}
}
$this->outSearchResultsCSV($res);
}
function outSearchResultsCSV(&$res)
{
$fields = array(
// 'record_type_title' => 'Record Type',
'id' => 'Record ID',
'individual_cnt' => '# of Members',
'nrds_id' => 'NRDS ID',
// 'name' => 'Company or Location name',
// 'type' => 'Company or Location type',
'status' => 'Location Status',
'changed' => 'Last Updated',
'added' => 'Date Created',
'location_company_id' => 'Company ID',
'location_company' => 'Company Name',
'phone' => 'Location Phone Number',
'fax' => 'Location Fax Number',
'website' => 'Web Site',
'contact_name' => 'Office Contact Name',
'contact_phone' => 'Office Contact Phone #',
'physical_address' => 'Physical Street Address',
'physical_city' => 'Physical City',
'physical_state' => 'Physical State',
'physical_zip' => 'Physical Zip',
'mailing_address' => 'Mailing Street Address',
'mailing_city' => 'Mailing City',
'mailing_state' => 'Mailing State',
'mailing_zip' => 'Mailing Zip',
'allow_mcpe_access' => 'Allow MCPE Access',
'mcpe_access_type' => 'MCPE Access Type',
'current_mcpe_status' => 'Current MCPE Status',
'mcpe_status_date' => 'Current MCPE Status Change Date',
'raw_datafeeds' => 'Raw Data Feeds',
'data_feeds_office' => 'Data Feeds - Office',
'data_feeds_individual' => 'Data Feeds - Individual',
'templates' => 'Templates ',
'designated_realtor_full_name' => 'Designated Realtor',
'template_individuals' => 'Individuals With Permission to save html email templates',
'note' => 'Notes',
);
require_once 'Structures/DataGrid/Renderer/CSV.php';
$csv = new Structures_DataGrid_Renderer_CSV();
$csv->setStreaming(true);
$row = $res->fetchRow();
if (!$row) {
Session::setData($this->_getPage4SaveMessage(), 'msg', 'No data for export');
$this->doBack();
return;
}
header ("Content-type: text/comma-separated-values");
header('Content-disposition: attachment; filename=search_results.csv');
echo $csv->_recordToCsv(array_values($fields));
echo $csv->_recordToCsv($this->prepareRow($row, $fields));
while (($row = $res->fetchRow())) {
echo $csv->_recordToCsv($this->prepareRow($row, $fields));
}
exit;
}
function prepareRow($row, $fields)
{
$templateIndividuals = $this->DBObj->getTemplateIndividuals($row['id']);
if (is_array($templateIndividuals) && !empty($templateIndividuals)) {
$row['template_individuals'] = implode(', ', $templateIndividuals);
}
$row['note'] = str_replace(array("\r", "\n"), ' ', $row['note']);
$out = array();
foreach ($fields as $k=>$v) {
$out[$k] = @$row[$k];
}
foreach (array('allow_mcpe_access', 'data_feeds_office', 'data_feeds_individual', 'raw_datafeeds', 'templates') as $field ) {
$out[$field] = ('y' == $out[$field]) ? 'Yes' : 'No';
}
return $out;
}
}
?>