2007-07-19 12:40:05 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
2008-10-01 11:54:39 +02:00
|
|
|
* Reports section of the CMS.
|
|
|
|
*
|
|
|
|
* @TODO If reports need to subclass Report in order
|
|
|
|
* to show, then why don't we have an abstract Report
|
|
|
|
* class around?'
|
|
|
|
*
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package cms
|
|
|
|
* @subpackage reports
|
|
|
|
*/
|
2007-07-19 12:40:05 +02:00
|
|
|
class ReportAdmin extends LeftAndMain {
|
|
|
|
|
|
|
|
static $template_path = null; // defaults to (project)/templates/email
|
|
|
|
|
|
|
|
public function init() {
|
|
|
|
parent::init();
|
2008-10-01 11:54:39 +02:00
|
|
|
|
|
|
|
// @TODO determine what is not necessary to include here
|
2007-07-19 12:40:05 +02:00
|
|
|
Requirements::javascript(MCE_ROOT . "tiny_mce_src.js");
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63175 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-28 15:12:20 +02:00
|
|
|
Requirements::javascript(THIRDPARTY_DIR . "/tiny_mce_improvements.js");
|
2008-10-01 11:54:39 +02:00
|
|
|
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63175 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-28 15:12:20 +02:00
|
|
|
Requirements::javascript(THIRDPARTY_DIR . "/hover.js");
|
|
|
|
Requirements::javascript(THIRDPARTY_DIR . "/scriptaculous/controls.js");
|
2007-07-19 12:40:05 +02:00
|
|
|
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63175 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-28 15:12:20 +02:00
|
|
|
Requirements::javascript(CMS_DIR . "/javascript/SecurityAdmin.js");
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2008-10-01 11:54:39 +02:00
|
|
|
Requirements::javascript(CMS_DIR . "/javascript/LeftAndMain_left.js");
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63175 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-28 15:12:20 +02:00
|
|
|
Requirements::javascript(CMS_DIR . "/javascript/LeftAndMain_right.js");
|
2008-10-01 11:54:39 +02:00
|
|
|
Requirements::javascript(CMS_DIR . "/javascript/CMSMain_left.js");
|
|
|
|
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63175 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-28 15:12:20 +02:00
|
|
|
Requirements::javascript(CMS_DIR . "/javascript/ReportAdmin_left.js");
|
|
|
|
Requirements::javascript(CMS_DIR . "/javascript/ReportAdmin_right.js");
|
2007-07-19 12:40:05 +02:00
|
|
|
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63175 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-28 15:12:20 +02:00
|
|
|
Requirements::css(CMS_DIR . "/css/ReportAdmin.css");
|
2007-09-27 22:56:55 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
// TODO Find a better solution to integrate optional Requirements in a specific order
|
|
|
|
if(Director::fileExists("ecommerce/css/DataReportCMSMain.css")) {
|
|
|
|
Requirements::css("ecommerce/css/DataReportCMSMain.css");
|
|
|
|
}
|
|
|
|
if(Director::fileExists("ecommerce/css/DataReportCMSMain.css")) {
|
|
|
|
Requirements::javascript("ecommerce/javascript/DataReport.js");
|
|
|
|
}
|
|
|
|
if(Director::fileExists(project() . "/css/DataReportCMSMain.css")) {
|
|
|
|
Requirements::css(project() . "/css/DataReportCMSMain.css");
|
|
|
|
}
|
|
|
|
if(Director::fileExists(project() . "/css/DataReportCMSMain.css")) {
|
|
|
|
Requirements::javascript(project() . "/javascript/DataReport.js");
|
|
|
|
}
|
2008-10-01 11:54:39 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
// We don't want this showing up in every ajax-response, it should always be present in a CMS-environment
|
|
|
|
if(!Director::is_ajax()) {
|
|
|
|
Requirements::javascriptTemplate("cms/javascript/tinymce.template.js", array(
|
|
|
|
"ContentCSS" => project() . "/css/editor.css",
|
|
|
|
"BaseURL" => Director::absoluteBaseURL(),
|
2007-10-08 01:48:05 +02:00
|
|
|
"Lang" => i18n::get_tinymce_lang()
|
2007-07-19 12:40:05 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Link($action = null) {
|
|
|
|
return "admin/reports/$action";
|
|
|
|
}
|
|
|
|
|
2008-10-01 06:49:08 +02:00
|
|
|
/**
|
|
|
|
* Return a DataObjectSet of Report subclasses
|
|
|
|
* that are available for use.
|
|
|
|
*
|
|
|
|
* @return DataObjectSet
|
|
|
|
*/
|
|
|
|
public function Reports() {
|
|
|
|
$processedReports = array();
|
|
|
|
$subClasses = ClassInfo::subclassesFor('Report');
|
|
|
|
|
|
|
|
if($subClasses) {
|
|
|
|
foreach($subClasses as $subClass) {
|
|
|
|
if($subClass != 'Report') $processedReports[] = new $subClass();
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2008-10-01 11:54:39 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$reports = new DataObjectSet($processedReports);
|
2008-10-01 06:49:08 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return $reports;
|
|
|
|
}
|
|
|
|
|
2008-10-01 06:49:08 +02:00
|
|
|
/**
|
|
|
|
* Show a report based on the URL query string.
|
|
|
|
*
|
|
|
|
* @param HTTPRequest $request The HTTP request object
|
|
|
|
*/
|
|
|
|
public function show($request) {
|
|
|
|
$params = $request->allParams();
|
|
|
|
|
|
|
|
return $this->showWithEditForm($params, $this->reportEditFormFor($params['ID']));
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
2008-10-01 06:49:08 +02:00
|
|
|
/**
|
|
|
|
* @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']);
|
|
|
|
|
2008-03-11 01:39:15 +01:00
|
|
|
if(Director::is_ajax()) {
|
2007-07-19 12:40:05 +02:00
|
|
|
SSViewer::setOption('rewriteHashlinks', false);
|
2008-10-01 06:49:08 +02:00
|
|
|
|
2008-10-01 11:56:55 +02:00
|
|
|
$result = $this->customise(array(
|
|
|
|
'EditForm' => $editForm
|
|
|
|
))->renderWith($this->getTemplatesWithSuffix('_right'));
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return $this->getLastFormIn($result);
|
2008-10-01 06:52:10 +02:00
|
|
|
} else {
|
|
|
|
return array();
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2008-10-01 06:49:08 +02:00
|
|
|
}
|
2008-10-01 11:54:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For the current report that the user is viewing,
|
|
|
|
* return a Form instance with the fields for that
|
|
|
|
* report.
|
|
|
|
*
|
|
|
|
* @return Form
|
|
|
|
*/
|
|
|
|
public function EditForm() {
|
2008-10-01 06:49:08 +02:00
|
|
|
$ids = array();
|
2008-10-01 11:54:39 +02:00
|
|
|
$id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : Session::get('currentPage');
|
2008-10-01 06:49:08 +02:00
|
|
|
$subClasses = ClassInfo::subclassesFor('Report');
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2008-10-01 06:49:08 +02:00
|
|
|
if($subClasses) {
|
|
|
|
foreach($subClasses as $subClass) {
|
|
|
|
if($subClass != 'Report') {
|
|
|
|
$obj = new $subClass();
|
|
|
|
$ids[] = $obj->getOwnerID();
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
2008-10-01 11:54:39 +02:00
|
|
|
|
2008-10-01 06:49:08 +02:00
|
|
|
if($id && in_array($id, $ids)) return $this->reportEditFormFor($id);
|
|
|
|
else return false;
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2008-10-01 11:54:39 +02:00
|
|
|
|
2008-10-01 06:49:08 +02:00
|
|
|
/**
|
|
|
|
* 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) ? 'Report_' . $page->ClassName : $id;
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2008-10-01 11:54:39 +02:00
|
|
|
$obj = new $reportClass();
|
|
|
|
if($obj) $fields = $obj->getCMSFields();
|
2008-10-01 06:49:08 +02:00
|
|
|
|
|
|
|
$idField = new HiddenField('ID');
|
2007-07-19 12:40:05 +02:00
|
|
|
$idField->setValue($id);
|
2008-10-01 06:49:08 +02:00
|
|
|
$fields->push($idField);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2008-10-01 06:49:08 +02:00
|
|
|
$form = new Form($this, 'EditForm', $fields, $actions);
|
2008-10-01 11:54:39 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return $form;
|
|
|
|
}
|
2008-04-05 05:43:58 +02:00
|
|
|
|
|
|
|
/**
|
2008-10-01 06:49:08 +02:00
|
|
|
* 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
|
|
|
|
* "Report" that exists.
|
2008-04-05 05:43:58 +02:00
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function has_reports() {
|
2008-10-01 06:49:08 +02:00
|
|
|
$subClasses = ClassInfo::subclassesFor('Report');
|
|
|
|
|
|
|
|
if($subClasses) {
|
|
|
|
foreach($subClasses as $subClass) {
|
|
|
|
if($subClass != 'Report') {
|
|
|
|
return true;
|
|
|
|
}
|
2008-04-05 05:43:58 +02:00
|
|
|
}
|
|
|
|
}
|
2008-10-01 06:49:08 +02:00
|
|
|
|
2008-04-05 05:43:58 +02:00
|
|
|
return false;
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
2008-10-01 11:54:39 +02:00
|
|
|
?>
|