'doList', 'cancel' => 'doBack', 'new' => 'doNew', 'insert' => 'doInsert', 'edit' => 'doEdit', 'update' => 'doUpdate', 'del' => 'doDelete', 'export_xls' => 'doExportXls', ); protected $_filterForm; function ContactPersonView($options) { $this->_options = $options; } function exec($Doc) { $this->DBObj = SiteMap::getObj('Contact/Person/Obj.php', isset($_REQUEST['id']) ? $_REQUEST['id'] : null); if (intval($this->_options['_restAlias'])) { $this->DBObj->setFilter(array('id_group' => intval($this->_options['_restAlias']))); } $this->Doc = $Doc; parent::exec(); } function _doListBind(&$DB_List) { if (!$this->DBObj->getFilter('id_group')) { $DB_List->insertColLast( 'group_title', array( 'title' => 'Group', 'order_by' => 'group_title', 'tpl' => DB_LIST_CELL_LINK, 'url' => BASE_URL . '/' . CURR_PAGE . '/', 'params' => array('id', 'group_title') ) ); } $DB_List->insertColLast( 'first_name', array( 'title' => 'First Name', 'order_by' => 'first_name', 'tpl' => DB_LIST_CELL_TEXT, 'params' => array('first_name') ) ); $DB_List->insertColLast( 'last_name', array( 'title' => 'Last Name', 'order_by' => 'last_name', 'tpl' => DB_LIST_CELL_TEXT, 'params' => array('last_name') ) ); $DB_List->insertColLast( 'email', array( 'title' => 'Email', 'order_by' => 'email', 'tpl' => DB_LIST_CELL_EMAIL, 'params' => array('email') ) ); $DB_List->insertColLast( 'options', array( 'title' => 'Options', 'tpl' => DB_LIST_CELL_EDIT_DEL, 'edit_link' => BASE_URL . '/' . CURR_PAGE . '?action=edit&id=', 'del_link' => BASE_URL . '/' . CURR_PAGE . '?action=del&id=', 'params' => array('id') ) ); return true; } function _bindFormFields($form) { $form->addElement('text', 'first_name', 'First Name'); $form->addElement('text', 'last_name', 'Last Name'); $form->addElement('text', 'phone', 'Phone', array('id' => 'contact_person_phone')); $form->addElement('text', 'email', 'Email'); $joined_on = $form->createElement('calendar', 'joined_on', 'Joined On'); $joined_on->_options['minYear'] = 2002; $joined_on->_options['maxYear'] = 2020; $joined_on->_options['addEmptyOption'] = true; $form->addElement($joined_on); $form->addElement('text', 'address', 'Address'); $form->addElement('text', 'city', 'City'); $form->addElement('select', 'state', 'State', array('' => 'Select One') + (array)$this->DBObj->getState4Select('title')); $form->addElement('text', 'zip', 'Zip'); $birthday = $form->createElement('calendar', 'birthday', 'Birthday'); $birthday->_options['minYear'] = 1950; $birthday->_options['maxYear'] = date('Y'); $birthday->_options['addEmptyOption'] = true; $form->addElement($birthday); $groups = &$form->addElement( 'advmultiselect', 'groups', array('Groups', '
Available
', '
Selected
'), $this->DBObj->getContactGroup4Select('title'), array('style' => 'width:240px') ); $form->addRuleRequired(array('first_name', 'last_name', 'email')); $form->addRule('groups', 'Groups are required', 'required'); $form->addRule('groups', 'Groups are required', 'required', null, 'client'); $form->addRuleEx(array('phone'), ' is in wrong format', 'regex', '/^\(\d{3}\)\s\d{3}-\d{4}(?:\sext\.\s\d{1,6})?$/'); $form->addRuleEx('email', ' is in wrong format', 'email'); $form->addFormRule(array($this, 'validateForm')); return $form; } function validateForm($data) { $errors = array(); if (!$this->DBObj->isUnique('email', $data['email'])) { $errors['email'] = 'Email must be unique'; } return empty($errors) ? true : $errors; } function addLink() { $link = BASE_URL . '/' . CURR_PAGE; $link_list = array(); if ($this->DBObj->itemsName) { $link_list[] = array( 'title' => 'Manage Groups', 'class' => 'page_title', 'link' => BASE_URL . '/admin/contact' ); $link_list[] = array('title' => 'Manage ' . $this->DBObj->itemsName . ''); } $link_list[] = array('title' => 'Add New ' . $this->DBObj->itemName, 'link' => $link . '?action=new'); if ($this->DBObj->getFilter('id_group')) { $link_list[] = array( 'title' => 'View All ' . $this->DBObj->itemsName, 'link' => BASE_URL . '/' . CURR_PAGE_FINAL ); } $filterForm = $this->getFilterForm(); $exportQuery = $filterForm->exportValues(); $exportQuery['action'] = 'export_xls'; $link_list[] = array('title' => 'Export to XLS ', 'link' => $link . '?' . http_build_query($exportQuery)); $addLink = array( 'tpl' => 'center_link.tpl', 'link_list' => $link_list, ); $this->Doc->addContent($addLink); return true; } function _getNewForm() { $form = $this->_getBaseForm(); $form = $this->_bindFormFields($form); $data = array( 'groups' => array($this->DBObj->getFilter('id_group')), 'joined_on' => date('Y-m-d') ); $form->setDefaults($data); $this->setFormTitle($form, 'Add '.$this->DBObj->itemName); $form->addElement('hidden', 'action', 'insert') ; return $form; } function renderForm(&$form) { $form->exec(); $this->Doc->addItemProp('JSs', 'js/lib/form-element-phone.js'); $this->Doc->addItemProp('initFuncs', "function(){Qs_Form_Element_Phone.init('contact_person_phone', {})}"); } function doExportXls() { $filterForm = $this->getFilterForm(); $this->setFilter($filterForm->exportValues()); $data = $this->DBObj->getList4Grid(); header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT"); header ("Cache-Control: no-cache, must-revalidate"); header ("Pragma: no-cache"); header ("Content-type: application/x-msexcel"); header ("Content-Disposition: attachment; filename=\"Export.xls\"" ); header ("Content-Description: PHP/INTERBASE Generated Data" ); echo '' . '' . '' . '' . '' . '
' . ' '; $rowFirst = true; $columns = array( 'group_title' => 'Group', 'first_name' => 'First Name', 'last_name' => 'Last Name', 'email' => 'Email', 'phone' => 'phone', 'joined_on' => 'Joined On', 'address' => 'Address', 'city' => 'City', 'state' => 'State', 'zip' => 'Zip', 'birthday' => 'Birthday', ); //vdie($data['list']); foreach ($data['list'] as $key => $row) { $row = str_replace(array("\n", "\r"), ' ', $row); if ($rowFirst){ echo $this->getExelRow($columns); $rowFirst = false; } echo $this->getExelRow($row, $columns); } echo '
'; exit; } function getExelRow($_array, $fields = false) { $array = array(); if (false !== $fields) { $names = array_keys($fields); foreach ($names as $name) { if (array_key_exists($name, $_array)) { $array[$name] = strval($_array[$name]); } } } else { $array = $_array; } return ' '.implode('', $array)." \n"; } function setFilter($formFilter) { $filter = $this->DBObj->getFilter(); if (!empty($filter)) { $filter = array_merge($filter, $formFilter); } else { $filter = $formFilter; } $this->DBObj->setFilter($filter); } function doList() { $this->_saveBackUrl(); $this->addLink(); $filterForm = $this->getFilterForm(); $filterForm->exec(); $this->setFilter($filterForm->exportValues()); require_once('class/DB/List/List.php'); $DB_List = new DB_List($this->Doc, $this->DBObj, $this->functionalFields); $this->_doListBind($DB_List); $DB_List->exec(); return true; } function getFilterForm() { if (null === $this->_filterForm) { $this->_filterForm = parent::getFilterForm(); } return $this->_filterForm; } }