setOption('ContentCSS', project() . '/css/editor.css'); HtmlEditorConfig::get('cms')->setOption('Lang', i18n::get_tinymce_lang()); // Always block the HtmlEditorField.js otherwise it will be sent with an ajax request Requirements::block(SAPPHIRE_DIR . '/javascript/HtmlEditorField.js'); } /** * Does the parent permission checks, but also * makes sure that instantiatable subclasses of * {@link Report} exist. By default, the CMS doesn't * include any Reports, so there's no point in showing * * @param Member $member * @return boolean */ function canView($member = null) { if(!$member && $member !== FALSE) $member = Member::currentUser(); if(!parent::canView($member)) return false; $hasViewableSubclasses = false; foreach($this->Reports() as $report) { if($report->canView($member)) return true; } return false; } /** * Return a DataObjectSet of SS_Report subclasses * that are available for use. * * @return DataObjectSet */ public function Reports() { return new DataObjectSet(SSReport::get_reports('ReportAdmin')); } /** * Show a report based on the URL query string. * * @param SS_HTTPRequest $request The HTTP request object */ public function show($request) { $params = $request->allParams(); return $this->showWithEditForm($params, $this->reportEditFormFor($params['ID'])); } /** * @TODO What does this do? * * @param unknown_type $params * @param unknown_type $editForm * @return unknown */ protected function showWithEditForm($params, $editForm) { if(isset($params['ID'])) Session::set('currentPage', $params['ID']); if(isset($params['OtherID'])) Session::set('currentOtherID', $params['OtherID']); if(Director::is_ajax()) { SSViewer::setOption('rewriteHashlinks', false); $result = $this->customise(array( 'EditForm' => $editForm ))->renderWith($this->getTemplatesWithSuffix('_right')); return $this->getLastFormIn($result); } return array(); } /** * For the current report that the user is viewing, * return a Form instance with the fields for that * report. * * @return Form */ public function EditForm() { $id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : Session::get('currentPage'); if($id) { foreach($this->Reports() as $report) { if($id == $report->ID()) return $this->reportEditFormFor($id); } } return false; } /** * Return a Form instance with fields for the * particular report currently viewed. * * @TODO Dealing with multiple data types for the * $id parameter is confusing. Ideally, it should * deal with only one. * * @param id|string $id The ID of the report, or class name * @return Form */ public function reportEditFormFor($id) { $page = false; $fields = new FieldSet(); $actions = new FieldSet(); if(is_numeric($id)) $page = DataObject::get_by_id('SiteTree', $id); $reportClass = is_object($page) ? 'SS_Report_' . $page->ClassName : $id; $obj = new $reportClass(); if($obj) $fields = $obj->getCMSFields(); if($obj) $actions = $obj->getCMSActions(); $idField = new HiddenField('ID'); $idField->setValue($id); $fields->push($idField); $form = new Form($this, 'EditForm', $fields, $actions); $form->loadDataFrom($_REQUEST); // Include search criteria in the form action so that pagination works $filteredCriteria = array_merge($_GET, $_POST); foreach(array('ID','url','ajax','ctf','update','action_updatereport','SecurityID') as $notAParam) { unset($filteredCriteria[$notAParam]); } $form->setFormAction($this->Link() . '/EditForm?' . http_build_query($filteredCriteria)); $form->setTemplate('ReportAdminForm'); return $form; } /** * Determine if we have reports and need * to display the "Reports" main menu item * in the CMS. * * The test for an existance of a report * is done by checking for a subclass of * "SS_Report" that exists. * * @return boolean */ public static function has_reports() { return sizeof(SSReport::get_reports('ReportAdmin')) > 0; } public function updatereport() { FormResponse::load_form($this->EditForm()->forTemplate()); return FormResponse::respond(); } } ?>