'doList', 'cancel' => 'doBack', 'view' => 'doView', 'v-card' => 'doVCard', ); function initAction() { if (empty($this->action) && isset($_REQUEST['action'])) { $this->action = $_REQUEST['action']; } } function exec() { $this->initAction(); if ( !key_exists($this->action, $this->actions) ){ if ($this->defaultAction) { $this->action = $this->defaultAction; } else { $actionNames = array_keys($this->actions); $this->action = $actionNames[0]; } } $function = $this->actions[$this->action]; if ($this->isXmlHttpRequest()) { $function .= 'Ajax'; } if (method_exists($this, $function)) { $this->$function(); } else { exit; } } function _doListBind(DB_List &$DB_List) { $DB_List->def_order_by = 'last_name'; $DB_List->insertColLast('name', array( 'title'=>'Name', 'width'=>170, 'tpl'=>'Member/Find/List/cells/name.tpl', 'params'=>array('name'), )); $DB_List->insertColLast('company', array( 'title'=>'Company', 'width'=>250, 'tpl'=>'Member/Find/List/cells/company.tpl', 'params'=>array('company_name'), )); $DB_List->insertColLast('contact_information', array( 'title'=>'Phone Number', 'width'=>115, 'tpl'=>DB_LIST_CELL_TEXT_CENTER, 'params'=>array('primary_phone'), )); $DB_List->insertColLast( 'v-card', array( 'title' => 'vCard', 'width' => 115, 'tpl' => 'Member/Find/List/cells/v-card.tpl', 'params' => array('id'), ) ); $DB_List->bind(); return true; } function getFilterForm() { require_once 'class/Form/Form.class.php'; $form = new Form($this->Doc, 'form_search_member', 'get', '', '_self', array('class'=>'form form_search_member')); $form->tpl = SiteMap::getPath('Member/tpl/Find/filter.tpl'); $form->setRendType(FORM_RENDERER_ARRAY_SMARTY); $form->addElement('text', 'first_name', 'First Name'); $form->addElement('text', 'last_name', 'Last Name'); $form->addElement('text', 'company_name', 'Company Name'); $form->addElement('select', 'id_specialty_info', 'Specialty', array('all'=>'Any Specialty')+$this->DBObj->getDSpecialty4Select('sorter', "info = 'y'")); $form->addElement('select', 'id_area_info', 'Area', array('all'=>'Any Market')+$this->DBObj->getDArea4Select('sorter', "info = 'y'")); $form->addElement('submit', 'submit', 'Search Database', array( 'class' => 'btn') ); $form->addElement('button', 'cancel', 'Clear Entries', array( 'class' => 'btn' , 'onclick' => "document.location.href='".Constant::get('BASE_URL').'/'.CURR_PAGE."'" )); return $form; } function renderForm(&$form) { $form->exec(); } function addLink() { return false; } function doList() { $this->addLink(); $filterForm = $this->getFilterForm(); $this->DBObj->filter = $filterForm->exportValues(); $filterForm->exec(); if (!isset($_REQUEST['submit'])) { return false; } $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); $DB_List->exec(); $this->Doc->addItemProp('JSs','js/jquery.cluetip.js'); $this->Doc->addItemProp('CSSs','css/jquery.cluetip.css'); $this->Doc->addItemProp('JSs','js/jquery.dimensions-1.2.js'); $this->Doc->addItemProp('initFuncs','addtooltips'); return true; } function doView() { $this->DBObj->initFromDB(); $item = $this->DBObj->getData(); if (empty($item)) { $this->Doc->display404(); return $this; } $title = $item['first_name'] . ' ' . $item['last_name']; $description = $item['first_name'] . ' ' . $item['last_name']; if ($item['company_name']) { $title .= ', ' . $item['company_name']; $description .= ' of ' . $item['company_name']; } if ($item['city'] && $item['state']) { $title .= ', ' . $item['city'] . ' ' . $item['state']; $description .= ' in ' . $item['city'] . ' ' . $item['state']; } $description .= ' is a broker with the Minnesota Commercial Association of Realtors (MNCAR)'; $this->Doc->setTitle($title); $this->Doc->setDescription($description); $this->Doc->content['ITEMS'] = array(); $item['tpl'] = 'Member/Find/view.tpl'; $item['back_url'] = $this->getBackUrl(); $this->Doc->addContent($item); return $this; } function doVCard() { $this->DBObj->initFromDB(); if (null === ($member = $this->DBObj->getData())) { $this->Doc->display404(); return; } $this->displayVCard($member); } function displayVCard(array $member) { $vCard = array( 'FN;CHARSET=utf-8' => $member['full_name'], 'N;CHARSET=utf-8' => $member['last_name'] . ';' . $member['middle_initial'] . ($member['middle_initial'] ? ';' : '') . $member['first_name'], 'ORG;CHARSET=utf-8' => $member['company_name'], ); if (!empty($member['company_website'])) { $vCard['URL;TYPE=WORK'] = (0 !== strpos($member['company_website'], 'http://') ? 'http://' : '') . $member['company_website']; } $vCard['EMAIL;TYPE=INTERNET'] = $member['email']; if ($member['img']) { $file = WWW_PATH . FILE_DB_FS_DIR . '/' . $member['img']; if (file_exists($file)) { $size = getimagesize($file); if ($size['mime']) { $type = strtoupper(str_replace('image/', '', $size['mime'])); $vCard['PHOTO;TYPE=' . $type . ';ENCODING=BASE64'] = base64_encode(file_get_contents($file)); } } } require_once('Qs/Dom.php'); $bio = trim(str_replace(array("\r", "\n"), array('', '\n'), Qs_Dom::htmlToText($member['bio']))); if (!empty($bio)) { $vCard['NOTE;CHARSET=utf-8'] = $bio; } $phoneMap = array( 'primary_phone' => '', 'secondary_phone' => '' ); foreach ($phoneMap as $field => $part) { if (empty($member[$field])) { continue; } $typeParts = array(); if (!empty($part)) { $typeParts[] = $part; } if (false !== ($type = $this->_getVCardPhoneType($member[$field . '_title']))) { $typeParts[] = $type; } $typeParts[] = 'VOICE'; $vCard['TEL;TYPE=' . implode(';', $typeParts)] = $member[$field]; } if (!empty($member['fax'])) { $vCard['TEL;TYPE=WORK;FAX'] = $member['fax']; } if ($member['location_physical_address']) { $vCard['ADR;TYPE=WORK;PREF;CHARSET=utf-8'] = ';;' . $member['location_physical_address'] . ';' . $member['location_physical_city'] . ';' . $member['location_physical_state'] . ';' . $member['location_physical_zip']; } $eol = "\r\n"; $text = 'BEGIN:VCARD' . $eol . 'VERSION:3.0' . $eol; foreach ($vCard as $field => $value) { $text .= $field . ':' . $value . $eol; } $text .= 'END:VCARD'; $fileName = $member['first_name'] . '-' . $member['last_name'] . '.vcf'; $changedDate = date('D, d F Y H:i:s O', strtotime($member['changed'])); header('Last-Modified: ' . $changedDate); header('Content-Disposition: attachment; filename="' . str_replace('"', '\"', $fileName) . '"; ' . 'modification-date="' . $changedDate . '";'); header('Content-Type: text/x-vcard'); echo $text; exit; } function _getVCardPhoneType($title) { if (false !== stripos($title, 'office')) { return 'WORK'; } if (false !== stripos($title, 'mobile')) { return 'CELL'; } if (false !== stripos($title, 'home')) { return 'HOME'; } return false; } }