array('flv'), 'video_mp4' => array('mp4'), 'video_wmv' => array('wmv'), 'audio_mp3' => array('mp3'), 'audio_mp4' => array('mp4'), 'audio_wma' => array('wma'), 'document' => array('pdf', 'doc', 'docx', 'ppt'), 'additional_image' => array('jpg', 'jpeg', 'gif'), ); function Announcement_Grid(&$Doc, &$DBObj) { $this->DB_Grid($Doc, $DBObj); $this->actions['show_on_home'] = 'doShowOnHome'; $this->actions['reorder'] = 'doReorderForm'; $this->actions['reorder_save'] = 'doReorderSave'; $this->actions['reorder_home'] = 'doReorderHomeForm'; $this->actions['reorder_home_save'] = 'doReorderHomeSave'; } function _getNewForm($hidden = array()) { $form = parent::_getNewForm(); $form->addElement('hidden', 'event_image'); return $form; } function doNew() { $data = array(); $hidden = $this->_prepareDefaults($data); $form = $this->_getNewForm($hidden); $form = $this->_bindFormRules($form); $form->setDefaults($data); $form->exec(); $this->Doc->addContent(array('tpl' => 'text.tpl', 'text' => '')); } function _prepareDefaults(&$data) { $hidden = array(); if (empty($data['id_category'])) { $data['id_category'] = (int) $_REQUEST['id_category']; } if (empty($data['id_event'])) { $data['id_event'] = (int) $_REQUEST['id_event']; if ($data['id_event'] != 0) { $eventObj = SiteMap::getObj('Event/Event.php'); $event = $eventObj->getFromDB($data['id_event']); if (!empty($event)) { $data['title'] = $event['name']; $data['brief'] = trim($event['name'] . '.
' . date('j M Y \a\t H:ia', strtotime($event['eventdate'])) . '.
' . $event['address']); $data['description'] = $event['description']; $data['image'] = $event['image']; $data['event_image'] = $event['image']; } } } if ($data['id_event'] != 0) { // зроблено для того щоб івенти які не попадають в межі +3 і -3 місяці попали в селект $this->DBObj->getEvents($data['id_event']); } return $hidden; } function doEdit() { $this->DBObj->initFromDB(); $data = $this->DBObj->getData(); $this->_prepareDefaults($data); $form = $this->_getEditForm(); $form = $this->_bindFormRules($form, null, null, 'edit'); $form->setDefaults($data); $form->exec(); $this->Doc->addContent(array('tpl' => 'text.tpl', 'text' => '')); } function _bindFormRules($form, $id_category = null, $id_type = null, $action = '') { $form->addRuleRequired(array('title', 'alias')); $form->addRuleRequired(array('brief', 'description'), 'server'); if (null === $id_category || $id_category == 3) { // Event $form->addRuleRequired(array('id_event'), 'server'); } if (null === $id_type || in_array(1, $id_type)) { // Video $form->addRuleRequired(array('video_flv'), 'server'); } if (null === $id_type || in_array(2, $id_type)) { // Audio $form->addRuleRequired(array('audio_mp3'), 'server'); } if (null === $id_type || in_array(3, $id_type)) { // Poll $form->addRuleRequired(array('id_poll'), 'server'); } if (null === $id_type || in_array(4, $id_type)) { // Document (PDF, Word, PowerPoint) $form->addRuleRequired(array('document'), 'server'); } if (null === $id_type || in_array(5, $id_type)) { // Image (JPG, GIF) $form->addRuleRequired(array('additional_image'), 'server'); } return $form; } function _bindFormFields($form) { $form->addElement('text', 'title', 'Post Headline', array('onblur' => 'announce_TitleBlur();')); $form->addElement('text', 'alias', 'Post Alias', array('onblur' => 'announce_TitleBlur();')); $form->addElement('select', 'id_category', 'Post Category', $this->DBObj->getCategories(), array('id' => 'id_category', 'onchange' => 'announce_ChangeCategory();')); $events = array('' => 'Select Event ->') + $this->DBObj->getEvents(); $form->addElement('select', 'id_event', 'Event', $events); $form->addElement('extended_html_editor_basic', 'brief', 'Post Introduction', null, null, array('postfix' => '
It is reccomended that you keep the text in this section very brief. (Suggested maximum limit is 50 words)
This field is meant to act as an inviting invitation for a user to make a click to a page with the full content.
')); $description = $form->addElement('extended_html_editor', 'description', 'Post Description', null, null, array('postfix' => '')); $description->width = 805; $form->addElement('advcheckbox', 'show_on_home', ' ', 'Include on Home Page', array('id' => 'show_on_home'), array('n', 'y')); $image = $form->addElement('img_db', 'image', 'Post Image', '', 'Delete image'); $image->titles['last'] = 'Preferred image size 80 x 60 pixes.'; $form->addElement('header', 'id_type_header', 'Additional Options'); foreach ($this->DBObj->getTypes() as $idType => $typeTitle) { $form->addElement('checkbox', 'id_type[' . $idType . ']', ' ', $typeTitle, array('id' => 'id_type_' . $idType, 'onclick' => 'announce_ChangeType();'))->updateAttributes(array('value' => $idType)); switch ($idType) { case '1': $form->addElement('extended_text', 'video_flv', 'Post Video (.flv)', array('id' => 'video_flv', 'style' => 'width: 700px;'), '', ''); $form->addElement('extended_text', 'video_mp4', 'Post Video (.mp4)', array('id' => 'video_mp4', 'style' => 'width: 700px;'), '', ''); $form->addElement('extended_text', 'video_wmv', 'Post Video (.wmv)', array('id' => 'video_wmv', 'style' => 'width: 700px;'), '', ''); break; case '2': $form->addElement('text', 'speakers', 'Speaker(s)'); $form->addElement('extended_text', 'audio_mp3', 'Post Audio (.mp3)', array('id' => 'audio_mp3', 'style' => 'width: 700px;'), '', ''); $form->addElement('extended_text', 'audio_mp4', 'Post Audio (.mp4)', array('id' => 'audio_mp4', 'style' => 'width: 700px;'), '', ''); $form->addElement('extended_text', 'audio_wma', 'Post Audio (.wma)', array('id' => 'audio_wma', 'style' => 'width: 700px;'), '', ''); break; case '3': $polls = array('' => 'Select Poll ->') + $this->DBObj->getPolls(); $form->addElement('select', 'id_poll', 'Post Poll', $polls); break; case '4': $form->addElement('extended_text', 'document', 'Post Document', array('id' => 'document', 'style' => 'width: 700px;'), '', ''); break; case '5': $form->addElement('extended_text', 'additional_image', 'Additional Image', array('id' => 'additional_image', 'style' => 'width: 700px;'), '', ''); break; } } $form->addFormRule(array(&$this, 'validateForm')); return $form; } function validateForm($data, $files) { $error = array(); //$image = $_FILES['image']; //if ($image['error']['field'] == 0 && is_uploaded_file($image['tmp_name']['file'])) { // list($w, $h,,$t,) = getimagesize($image['tmp_name']['file']); // if ($w != 80 || $h != 60) { // $error['image'] = 'Wrong image size. File size must be 80 x 60 pixes.'; // } //} foreach ($this->_alloed_types as $file => $ext) { if ($data[$file] != '') { if (!is_file($data[$file])) { $error[$file] = 'File is not exists'; } else { $path_parts = pathinfo($data[$file]); if (!in_array(strtolower($path_parts['extension']), $ext)) { $error[$file] = 'File type is wrong'; } } } } $alias = $this->DBObj->prepareAlias($data['alias']); if (empty($alias)) { $error['alias'] = 'Alias is wrong'; } return (!empty($error) ? $error : true); } function _doListBind(&$DB_List) { $DB_List->urlVarNames[] = 'search'; $DB_List->def_order_by = 'changed DESC'; //$DB_List->def_order_by = 'sorter'; $DB_List->insertColLast('sorter',array( 'title' => '#', 'order_by' => 'sorter', 'width' => '40', 'tpl' => DB_LIST_CELL_SORTER, 'params' => array('sorter') )); $DB_List->insertColLast('image', array( 'title' => 'Image', 'order_by' => '', 'width' => '105', 'imgW' => '100', 'imgH' => '100', 'no_img_url' => '', 'tpl' => BASE_PATH . '/app/Announcement/tpl/announcement_image.tpl', 'center' => true, 'params' => array('image', 'id_category', 'id_type') )); $DB_List->insertColLast('changed', array( 'title' => 'Date Modified', 'order_by' => 'changed', 'width' => '100', 'tpl' => DB_LIST_CELL_DATE, 'date_format' => '%b %e, %Y', 'params' => array('changed') )); $DB_List->insertColLast('title', array( 'title' => 'Headline', 'order_by' => 'title', 'width' => '300', 'tpl' => BASE_PATH . '/app/Announcement/tpl/headline.tpl', 'params' => array('title', 'brief') )); //$DB_List->insertColLast('comments_total', array( // 'title' => 'Comments', // 'order_by' => 'comments_total', // 'width' => '100', // 'tpl' => BASE_PATH . '/app/Announcement/tpl/comments.tpl', // 'comments_url' => BASE_URL . '/' . CURR_PAGE . '/reply?id_announcement=', // 'params' => array(), //)); $DB_List->insertColLast('show_on_home', array( 'title' => 'Show On Home Page', 'order_by' => 'show_on_home', 'width' => '140', 'tpl' => BASE_PATH . '/app/Announcement/tpl/show_on_home.tpl', 'url' => BASE_URL . '/' . CURR_PAGE . '?action=show_on_home', 'params' => array('show_on_home', 'id', 'id_category') )); $DB_List->insertColLast('options', array( 'title' => 'Options', 'width' => '80', 'tpl' => DB_LIST_CELL_EDIT_DEL, 'edit_link' => Constant::get('BASE_URL').'/'.CURR_PAGE.'?action=edit&id=', 'del_link' => Constant::get('BASE_URL').'/'.CURR_PAGE.'?action=del&id=', 'params' => array('id', 'title') )); $DB_List->bind(); return true; } function addLink() { $link = BASE_URL . '/' . CURR_PAGE; $addLink = array( 'tpl' => 'center_link.tpl', 'link_list' => array( array('title' => 'Choose a ' . $this->DBObj->itemName . ' to edit'), array('title' => 'Add a New ' . $this->DBObj->itemName, 'link' => $link . '?action=new'), array('title' => 'Reorder Posts on Home Page', 'link' => $link . '?action=reorder_home'), array('title' => 'Reorder Posts', 'link' => $link . '?action=reorder'), ), ); $this->Doc->addContent($addLink); return true; } function doInsert() { // зроблено для того щоб івенти які не попадають в межі +3 і -3 місяці попали в селект $id_event = (int) $_REQUEST['id_event']; if ($id_event) { $this->DBObj->getEvents($id_event); } $form = $this->_getNewForm(); $values = $form->exportValues(); if (!is_array($values['id_type'])) { $values['id_type'] = array(); } $form = $this->_bindFormRules($form, $values['id_category'], $values['id_type'], 'new'); if ($form->validate()) { $this->DBObj->initFromForm($form); $this->DBObj->insert(); Session::setData(CURR_PAGE, 'msg', $this->DBObj->itemName . ' added'); $this->doBack(); } else { $form = $this->_bindFormRules($form, null, null, 'new'); $form->exec(); $this->Doc->addContent(array('tpl' => 'text.tpl', 'text' => '')); } return true; } function doUpdate() { // зроблено для того щоб івенти які не попадають в межі +3 і -3 місяці попали в селект $id_event = (int) $_REQUEST['id_event']; if ($id_event) { $this->DBObj->getEvents($id_event); } $form = $this->_getEditForm(); $values = $form->exportValues(); if (!is_array($values['id_type'])) { $values['id_type'] = array(); } $form = $this->_bindFormRules($form, $values['id_category'], $values['id_type'], 'edit'); if ($form->validate()) { $this->DBObj->initFromForm($form); /*if($this->DBObj->_data['video_flv']) { $sExt = substr($this->DBObj->_data['video_flv'],strrpos($this->DBObj->_data['video_flv'],'.')); $sNaewFileName = 'userfile/Root/Video/announcement_video_flv_'.$this->DBObj->id.$sExt; rename($this->DBObj->_data['video_flv'],$sNaewFileName); $this->DBObj->_data['video_flv'] = $sNaewFileName; }*/ $this->DBObj->update(); Session::setData(CURR_PAGE, 'msg', $this->DBObj->itemName . ' updated'); $this->doBack(); } else { $form = $this->_bindFormRules($form, null, null, 'edit'); $form->exec(); $this->Doc->addContent(array('tpl' => 'text.tpl', 'text' => '')); } return true; } function getFilterForm() { $form = $this->_getBaseForm('get'); $form->tpl = 'tpl/Announcement/filter.tpl'; $form->setRendType(FORM_RENDERER_ARRAY_SMARTY); $form->addElement('text', 'search[query]'); $form->addElement('select', 'search[id_category]', null, array('' => 'All') + $this->DBObj->getCategories(), array('onchange' => 'this.form.submit();')); $form->addElement('submit', 'submit_btn', 'Search', array('class' => 'btn')); $form->addElement('button', 'cancel_btn', 'Cancel', array('class' => 'btn', 'onclick' => "document.location.href='" . Constant::get('BASE_URL') . '/' . CURR_PAGE . "'")); return $form; } function doList() { $filterFrom = $this->getFilterForm(); $filter = $filterFrom->exportValues(); $this->DBObj->setFilter($filter['search']); $filterFrom->exec(); parent::doList(); } function _getReorderFrom() { $form = $this->_getBaseForm(); $list = array(); $list4Grid = $this->DBObj->getList4Grid(array('order_by' => 'sorter')); foreach ($list4Grid['list'] as $val) { $list[$val['id']] = $val['title']; } $orderList = Form::createElement('select_edit', 'order_list', false, $list, array('style' => 'width:600px;')); $orderList->delAction('add'); $orderList->delAction('del'); $orderList->delAction('edit'); $form->addElement($orderList); return $form; } function doReorderForm() { $form = $this->_getReorderFrom(); $form->setTitle('Reorder Posts'); $form->addElement('hidden', 'action', 'reorder_save'); $form->exec(); } function doReorderSave() { $form = $this->_getReorderFrom(); $this->DBObj->reorder($form->getElementValue('order_list')); $this->doBack(); } function _getReorderHomeFrom() { $form = $this->_getBaseForm(); $categories = $this->DBObj->getCategories(false, true); $form->addElement( 'select', 'id_category', null, $categories, array('id' => 'id_category', 'style' => 'width:600px;') ); $id_category = $form->exportValue('id_category'); if (!$id_category) { $id_category = reset(array_keys($categories)); } $this->DBObj->setFilter(array('id_category' => $id_category)); $list = array(); $list4Grid = $this->DBObj->getList4Grid(array('order_by' => 'home_sorter', 'addonWhere' => " and show_on_home = 'y'")); foreach ($list4Grid['list'] as $val) { $list[$val['id']] = $val['title']; } $orderList = Form::createElement('select_edit', 'order_list', false, $list, array('style' => 'width:600px;')); $orderList->delAction('add'); $orderList->delAction('del'); $orderList->delAction('edit'); $form->addElement($orderList); return $form; } function doReorderHomeForm() { $form = $this->_getReorderHomeFrom(); $form->setTitle('Reorder Posts on Home Page'); $form->addElement('hidden', 'action'); $form->setConstants(array('action' => 'reorder_home_save')); $form->exec(); $this->Doc->addItemProp('initFuncs', 'announce_ReorderHomeInit'); } function doReorderHomeSave() { $form = $this->_getReorderHomeFrom(); $this->DBObj->reorder($form->getElementValue('order_list'), 'home_sorter'); $this->doBack(); } function doShowOnHome() { $this->DBObj->initFromArray(array('show_on_home' => ($_REQUEST['show_on_home'] == 'y' ? 'y' : 'n'))); $this->DBObj->update(); return true; } function doShowOnHomeAjax() { $this->doShowOnHome(); $status = $this->DBObj->getFromDB($this->DBObj->id, 'show_on_home'); header('Content-Type: text/html'); echo $status; exit(); } }