'Add New %itemName%', self::HEADER_EDIT => 'Edit %itemName%', self::HEADER_REORDER => 'Reorder %itemsName%', ); protected $_actions = array('list', 'new', 'insert', 'edit', 'update', 'cancel', 'summary', 'archive', 'clear', 'delete', 'deleteFile', 'showInstructions', 'forceStatus', 'rejectFileForm', 'rejectFile'); protected $_hasFilter = true; protected function _init() { $this->_messageTemplates[self::MSG_DATA_UNAVAILABLE] = '%itemName% is not available'; return parent::_init(); } protected function _initAction() { parent::_initAction(); if ($this->_action === 'list' && ($schoolId = Qs_Request::getGetValue('schoolId'))) { if (($schoolName = $this->_getDataObj()->getSchoolName($schoolId))) { $this->_getDataObj()->setSchoolId($schoolId); $this->doc->setHeader('Reports of "' . $schoolName . '"'); } else { $this->_doc->display404(); } } return $this; } protected function _callAction() { if (method_exists($this, $this->_actionMethod)) { $this->_setHeader(); } return parent::_callAction(); } public static function refreshReportAccessFile() { $adminAuth = App_Admin_Auth::getInstance(); $userAuth = App_User_Auth::getInstance(); $adminLogged = $adminAuth->isLoggedIn(); $userLogged = $userAuth->isLoggedIn(); if ($adminLogged || $userLogged) { if (($adminLogged && $adminAuth->getData('reportsAccess') === 'y') || ($userLogged && $userAuth->getData('viewAllReports') === 'y') ) { App_Report_AdminView::createReportsAccessDir(); } else { App_Report_AdminView::removeReportAccessDir(); } } if ($userAuth->isLoggedIn()) { if ($userAuth->getData('reportsAccess') === 'y') { App_Report_View::createReportsSymlinks(); } } } static public function createReportsAccessDir() { file_put_contents(BASE_PATH . '/tmp/' . App_Report_AdminObj::REPORT_ADMIN_ACCESS_PATH . '/' . session_id(), ''); return true; } public static function removeReportAccessDir() { $filePath = BASE_PATH . '/tmp/' . App_Report_AdminObj::REPORT_ADMIN_ACCESS_PATH . '/' . session_id(); if (file_exists($filePath)) { unlink($filePath); } return true; } protected function _doShowInstructions() { $item = array( 'text' => App_Settings_Obj::get('reportInstructions'), 'tpl' => Qs_Sitemap::getTemplate('_sys/ViewController/text.tpl') ); $this->_addItem($item); } protected function _doEdit() { $form = $this->_getEditForm(); $this->dataObj->initData(); if (null == $this->_getDataObj()->getData()) { $this->_setBackError(self::MSG_DATA_UNAVAILABLE); $this->_doBack(); } $data = $this->_getData4Form(); $form->setDefaults($data); $this->_renderMainForm($form); return $this; } protected function _doUpdate() { if (null === $this->_getDataObj()->getData()) { $this->_setBackError(self::MSG_DATA_UNAVAILABLE); $this->_doBack(); } return parent::_doUpdate(); } protected function _doDelete() { if (null === $this->_getDataObj()->getData()) { $this->_setBackError(self::MSG_DATA_UNAVAILABLE); $this->_doBack(); } parent::_doDelete(); } protected function _doChangeOption() { if (null === $this->_getDataObj()->getData()) { $this->_setBackError(self::MSG_DATA_UNAVAILABLE); $this->_doBack(); } parent::_doChangeOption(); } protected function _getDefaultLinks() { if ($this->_getDataObj()->getSchoolId()) { return array(); } $links = parent::_getDefaultLinks(); if ($this->_getDataObj()->hasUserReports()) { $links[] = array( 'title' => 'Download All Reports', 'url' => $this->url(array('action' => 'archive')) ); } $links[] = array('title' => 'View Summary Table', 'url' => $this->_getSummaryUrl(), 'options' => array('delimiter' => '')); $links[] = array('title' => 'Clear All Reports', 'attribs' => array('class' => 'fright', 'style' => 'color: red;'), 'url' => $this->url(array('action' => 'clear'))); return $links; } protected function _bindFormFields(Qs_Form $form) { $form->addElement( 'select', 'dueDateMonth', array( 'label' => '', 'multiOptions' => array('' => 'Select Month') + App_Report_AdminObj::getMonthList(), ) ); $dayOptions = array(); if (($month = $this->_getData('dueDateMonth'))) { $dayOptions = App_Report_AdminObj::getDayList($month); } $form->addElement( 'select', 'dueDateDay', array( 'label' => '', 'multiOptions' => array('' => 'Select Day') + $dayOptions, ) ); if (empty($dayOptions)) { $form->getElement('dueDateDay')->setAttrib('disabled', 'disabled'); } $form->addDisplayGroup(array('dueDateMonth', 'dueDateDay'), 'dueDateGroup', array('legend' => 'Date Due')); $form->addElement( 'text', 'section', array( 'label' => 'Section', 'maxlength' => 64, 'required' => true ) ); $form->addElement( 'text', 'topic', array( 'label' => 'Topic', 'maxlength' => 64, 'required' => true ) ); $form->addElement( 'textarea', 'description', array( 'label' => 'Description', 'rows' => 5, ) ); $form->addElement( 'multiCheckbox', 'excludeSchoolId', array( 'label' => 'Not Required for Schools', 'multiOptions' => $this->_getDataObj()->getSchools4Select(), ) ); return $this; } /** * @param Qs_Form $form * * @return $this */ protected function _renderMainForm($form) { $this->_renderForm($form, 'form.tpl'); $options = array( 'formId' => $form->getId(), 'monthDayCount' => array(), ); foreach (array_keys(App_Report_AdminObj::getMonthList()) as $num) { $options['monthDayCount'][$num] = App_Report_AdminObj::getMonthDayCount($num); } $this->_doc->addScript('js/app/report/admin/form.js'); $this->_doc->addInitObject('app.report.admin.Form', array($options)); return $this; } protected function _addFilterItem() { if ($this->_getDataObj()->getSchoolId()) { $this->_addBackLinkItem(); } return parent::_addFilterItem(); } /** * @param Qs_Form $form * * @return $this */ protected function _bindFilterFields($form) { parent::_bindFilterFields($form); $form->addElement( 'select', 'schoolId', array( 'label' => '', 'multiOptions' => array('' => 'All Schools') + $this->_getDataObj()->getSchools4Select(), ) ); return $this; } protected function _addListItem($list = null, $template = 'list.tpl') { App_Report_View::initTips(); $list = $list ? $list : $this->_getList(); if (($schoolId = $this->_getDataObj()->getSchoolId())) { $this->_addLegendHeaderItem(); $list->userReportDeleteUrl = $this->url(array('action' => 'deleteFile')); $list->userReportRejectUrl = $this->url(array('action' => 'rejectFile')); $list->schoolId = $schoolId; $params = array( 'containerId' => 'report-grid', 'requestUrl' => $this->url(), ); $this->_doc->addStylesheet('css/jquery.fancybox.css'); $this->_doc->addScript('js/jquery.fancybox.js'); $this->_doc->addScript('js/app/report/admin/list.js'); $this->_doc->addInitObject('app.report.admin.List', array($params)); } else { $list->reportDetailUrl = Qs_SiteMap::findFirst(null, array('type' => 'Report_AdminDetail'), null, 'url'); } return parent::_addListItem($list, $template); } protected function _addBackLinkItem() { $item = array( 'backUrl' => Qs_SiteMap::findFirst(null, array('type' => 'Report_Admin'), null, 'url'), 'tpl' => Qs_SiteMap::getTemplate('Report/Admin/back-link.tpl') ); $this->_additem($item); return $this; } protected function _addLegendHeaderItem() { $item = array( 'tpl' => Qs_SiteMap::getTemplate('Report/legend-header.tpl'), 'statistics' => $this->_getDataObj()->getStatusStatistics($this->_getDataObj()->getSchoolId()), ); $this->_additem($item); return $this; } /** * @param Qs_ViewController_List $list * * @return $this */ protected function _bindListColumns($list) { $list->addColumn( 'dueDate', 'dueDate', array('title' => 'Date Due', 'orderBy' => 'dueIdx', 'defaultText' => '-', 'attribs' => array('class' => 'text-center')) ); $list->addColumn( 'text', 'section', array('title' => 'Section', 'orderBy' => 'section', 'attribs' => array('class' => 'text-center')) ); $list->addColumn( 'text', 'topic', array('title' => 'Topic', 'orderBy' => 'topic') ); $list->addColumn( 'text', 'description', array('title' => 'Description', 'defaultText' => '-') ); if ($this->_getDataObj()->getSchoolId()) { $list->addColumn( 'schoolReports', 'reports', array('title' => 'Reports' , 'attribs' => array('class' => 'report-th')) ); } else { $list->addColumn( 'schoolCount', 'schoolCount', array('title' => 'Schools' , 'attribs' => array('class' => 'report-th')) ); $list->addColumn( 'options', 'options', array('attribs' => array('class' => 'option-th')) ); } return $this; } protected function _getSummaryUrl() { return ($url = Qs_SiteMap::findFirstLocal(null, array('type' => 'Report_Summary_'), null, 'url')); } protected function _doSummary() { exit('method' . __METHOD__ . ' is not implemented'); } protected function _doArchive() { $archiveView = new App_Report_Archive_View(); $archiveView->setDoc($this->_doc); $archiveView->actionArchive(); } public static function delTree($dir) { $files = array_diff(scandir($dir), array('.','..')); foreach ($files as $file) { (is_dir("$dir/$file")) ? self::delTree("$dir/$file") : unlink("$dir/$file"); } return rmdir($dir); } protected function _doClear() { if ('confirm' == Qs_Request::getPostValue('confirm')) { $this->_deleteAllReports(); $this->_setBackMessage('Reports were successfully deleted.'); $this->_doBack(); return $this; } $form = $this->_getClearConfirmationForm(); $this->_renderMainForm($form); return $this; } protected function _doCLearAjax() { $form = $this->_getClearConfirmationForm(); $this->_validateAjax($form); } protected function _getClearConfirmationForm() { $form = $this->_getBaseForm(); $form->addElement('hidden', 'action', array('value' => 'clear')); $form->addElement('hidden', 'confirm', array('value' => 'confirm')); $smarty = $this->_doc->getSmarty(); $smarty->assign( 'downloadUrl', Qs_SiteMap::findFirst(null, array('type' => 'Report_Admin'), null, 'url') . '?action=archive' ); $text = $smarty->fetch('Report/Admin/confirmClear.tpl'); $form->addElement( 'static', 'confirmText', array( 'label' => 'Attention!', 'value' => $text, ) ); $form->addElement('submit', 'btnSubmit', array( 'label' => 'Confirm', 'attribs' => array('class' => 'btn'), 'decorators' => array('ViewHelper') ) ); $form->btnSubmit->getDecorator('ViewHelper')->setAdditionalHtmlAfterElement('  '); $btnCancel = new Zend_Form_Element_Button('btnCancel', array( 'label' => 'Cancel', 'attribs' => array( 'class' => 'btn', 'onclick' => "document.location = '{$form->getCancelUrl()}';" ), 'decorators' => array('ViewHelper') ) ); $form->addElement($btnCancel); $decorators = array('FormElements'); $decorators[] = array('decorator' => 'HtmlTag', 'options' => array('tag' => 'div')); $decorators[] = 'Fieldset'; $decorators[] = 'DtDdWrapper'; $form->addDisplayGroup(array('btnSubmit', 'btnCancel'), 'submitGroup', array('decorators' => $decorators)); return $form; } protected function _deleteAllReports() { $userReports = $this->_getDataObj()->getUserReports(); $path = WWW_PATH . '/' . App_Report_AbstractObj::REPORT_PATH; $fileTransferAdapter = new Qs_File_Transfer_Adapter_Db(); $fileTransferAdapter->setDefaultDestination($path); foreach ($userReports as $fileName) { $fileTransferAdapter->delete($fileName, $path); } $this->_getDataObj()->clearUserReportTable(); return $this; } protected function _renderListRow(array $filter) { $this->_doc->setGroupName('ITEMS'); $this->_getDataObj()->setSchoolId($filter['schoolId']); $this->_getDataObj()->setFilter(array('id' => $filter['reportId'])); $this->_addListItem(); return $this->_doc->fetch(Qs_Sitemap::getTemplate('Doc/clean.tpl')); } }