def_order_by = 'id_type, sorter'; $DB_List->insertColLast('type', array( 'title'=>'Type', 'order_by'=>'type', 'width'=>70, 'tpl'=>DB_LIST_CELL_TEXT, 'params'=>array('type'), )); $DB_List->insertColLast('company', array( 'title'=>'Company', 'order_by'=>'company', 'width'=>220, 'tpl'=>DB_LIST_CELL_TEXT, 'params'=>array('company'), )); $DB_List->insertColLast('contact', array( 'title'=>'Contact', 'order_by'=>'contact', 'width'=>170, 'tpl'=>DB_LIST_CELL_TEXT, 'params'=>array('contact'), )); $DB_List->insertColLast('statictics', array( 'title'=>'Statistics', 'width'=>250, 'tpl'=>SiteMap::getPath('Sponsor/tpl/List/cells/statistics.tpl'), 'params'=>array('yearFilter', 'monthCount', 'totalCount'), )); $DB_List->insertColLast('active', array( 'title'=>'Active', 'order_by'=>'active', 'width'=>80, 'values'=> array('y'=>'Yes', 'n'=>'No'), 'tpl' => DB_LIST_CELL_LINK_ENUM, 'url' => BASE_URL.'/'.CURR_PAGE.'/?action=chopt&opt=active&id=', 'params'=> array('active', 'id') )); $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'), )); $DB_List->bind(); return true; } function addLink() { $link = BASE_URL . '/' . CURR_PAGE; $addLink = array( 'tpl' => 'center_link.tpl', 'link_list' => array( array('title' => 'Click here to add a new '.$this->DBObj->itemName, 'link' => $link . '?action=new'), array('title' => 'Click here to reorder '.$this->DBObj->itemsName, 'link' => $link . '?action=reorder'), ), ); $this->Doc->addContent($addLink); } function formCreateAdvcheckboxList(&$form, $name, $list) { if (!is_array($list) || empty($list)) { return false; } $elList = array(); foreach ($list as $id => $title) { $elList[$id] = $form->createElement('advcheckbox', $name.'['.$id.']', '', $title, null, array('0', $id)); } return $elList; } function _bindFormFields(Form $form) { $form->addElement('select', 'id_type', 'Type', $this->DBObj->getDSponsorType4Select()); $elList = $this->formCreateAdvcheckboxList($form, 'id_sponsor_area_type', $this->DBObj->getDSponsorAreaType4Select()); $form->addGroup($elList, 'gSponsorAreaType', 'Markets', ' ', false); $form->addElement('advcheckbox', 'active', 'Active', null, null, array('n', 'y')); $form->addElement('text', 'company', 'Company'); $form->addElement('text', 'contact', 'Contact'); $img = &$form->createElement('img_db', 'img', 'Image', null, ''); $img->titles['last'] = '
Note:
- Banner image size must be ' . AD_BANNER_WIDTH . 'x' . AD_BANNER_HEIGHT . ' pixels
'; $img->titles['last'] .= '
- Logo image size must be equal or less ' . SPONSOR_BANNER_WIDTH . 'x' . SPONSOR_BANNER_HEIGHT . ' pixels
'; $form->addElement($img); $form->addElement( 'extended_text', 'url', 'Email Address or URL', null, null, '
Example: http://google.com
' . '
Example 2: username@gmail.com
' ); $form->addRuleRequired(array('company', 'url')); $form->addFormRule(array($this, 'validForm')); return $form; } function validForm($data) { $errors = array(); if (!empty($_FILES['img']['tmp_name']['file'])) { if (strncmp($_FILES['img']['type']['file'], 'image', 5) != 0) { $errors['img'] = 'File format is wrong'; } else { list ($width, $height) = getimagesize($_FILES['img']['tmp_name']['file']); if ($data['id_type'] == 1 && ($width > SPONSOR_BANNER_WIDTH || $height > SPONSOR_BANNER_HEIGHT)) { $errors['img'] = 'Logo image size must be equal or less ' . SPONSOR_BANNER_WIDTH . 'x' . SPONSOR_BANNER_HEIGHT . ' pixels'; } elseif ($data['id_type'] == 2 && ($width != AD_BANNER_WIDTH || $height != AD_BANNER_HEIGHT)) { $errors['img'] = 'Banner image size must be ' . AD_BANNER_WIDTH . 'x' . AD_BANNER_HEIGHT . ' pixels'; } } } if (true !== ($_errors = $this->_isValidEmailOrUrl($data['url']))) { $errors['url'] = $_errors; } return empty($errors) ? true : $errors; } function _isValidEmailOrUrl($value) { if (!empty($value)) { if ($this->DBObj->isUrl($value)) { require_once('Qs/Validate/Url.php'); $validator = new Qs_Validate_Url(); } else { require_once('Zend/Validate/EmailAddress.php'); $validator = new Zend_Validate_EmailAddress(); } if (!$validator->isValid($value)) { return implode(' - ', $validator->getMessages()); } } return true; } function _getNewForm() { $form = $this->_getBaseForm(); $form = $this->_bindFormFields($form); $form->addRule('img', 'Image is required', 'uploadedfile'); $this->setFormTitle($form, 'Add '.$this->DBObj->itemName); $form->addElement('hidden', 'action', 'insert') ; return $form; } function doNew() { $form = $this->_getNewForm(); $data = array( 'active'=>'y' ); $form->setDefaults($data); $form->exec(); } function doEdit() { $this->DBObj->initFromDB(); $form = $this->_getEditForm(); $form->setDefaults($this->DBObj->getData()); $form->exec(); } function _getReorderForm() { $form=$this->_getBaseForm(); $list=array(); $list4Grid=$this->DBObj->getList4Grid(array('order_by'=>'sorter', 'addonWhere'=>'AND id_type=1')); foreach ($list4Grid['list'] as $val) { $list[$val['id']] = (strlen($val[$this->fldReorderTitle])>$this->reorderTitleSize)?substr($val[$this->fldReorderTitle], 0, $this->reorderTitleSize-3).'...':$val[$this->fldReorderTitle]; } $orderList = Form::createElement('select_edit', 'order_list', false, $list); $orderList->updateAttributes(array('size' => $this->reorderListSize)); $orderList->delAction('add'); $orderList->delAction('del'); $orderList->delAction('edit'); $form->addElement($orderList); $form->addElement('hidden', 'id_parent', $this->DBObj->id_parent); return $form; } function getFilterForm() { require_once 'class/Form/Form.class.php'; $form = new Form($this->Doc, 'form_search_sponsor', 'get', '', '_self', array('class'=>'form form_search_sponsor')); $form->tpl = SiteMap::getPath('Sponsor/tpl/filter.tpl'); $form->setRendType(FORM_RENDERER_ARRAY_SMARTY); $form->addElement('select', 'id_type', 'Type', array('all'=>'All Types')+$this->DBObj->getDSponsorType4Select()); $form->addElement('select', 'active', 'Active', array('all'=>'All', 'y'=>'Yes', 'n'=>'No')); $years = range(date('Y'), 2008); $form->addElement('select', 'year', 'Year', array('0'=>'All Years') + array_combine($years, $years)); $form->addElement('text', 'query', 'Search For', array('style'=>'width:350px;')); $form->addElement('submit', 'submit', 'Search', array( 'class' => 'btn') ); $form->addElement('button', 'cancel', 'Cancel', array( 'class' => 'btn' , 'onclick' => "document.location.href='".Constant::get('BASE_URL').'/'.CURR_PAGE."'" )); $form->setDefaults(array('year' => date('Y'))); return $form; } function doList() { $this->addLink(); $filterForm = $this->getFilterForm(); $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); $DB_List->exec(); return true; } }