1 <?php
2 3 4 5 6 7 8 9 10 11 12 13
14 class ReportAdmin extends LeftAndMain {
15
16 static $url_segment = 'reports';
17
18 static $url_rule = '/$Action/$ID';
19
20 static = 'Reports';
21
22 static $template_path = null;
23
24 public function init() {
25 parent::init();
26
27 Requirements::javascript(CMS_DIR . '/javascript/ReportAdmin_left.js');
28 Requirements::javascript(CMS_DIR . '/javascript/ReportAdmin_right.js');
29
30 Requirements::css(CMS_DIR . '/css/ReportAdmin.css');
31
32
33 HtmlEditorConfig::get('cms')->setOption('ContentCSS', project() . '/css/editor.css');
34 HtmlEditorConfig::get('cms')->setOption('Lang', i18n::get_tinymce_lang());
35
36
37 Requirements::block(SAPPHIRE_DIR . '/javascript/HtmlEditorField.js');
38 }
39
40 41 42 43 44 45 46 47 48
49 function canView($member = null) {
50 if(!$member && $member !== FALSE) $member = Member::currentUser();
51
52 if(!parent::canView($member)) return false;
53
54 $hasViewableSubclasses = false;
55 foreach($this->Reports() as $report) {
56 if($report->canView($member)) return true;
57 }
58
59 return false;
60 }
61
62 63 64 65 66 67
68 public function Reports() {
69 $output = new DataObjectSet();
70 foreach(SS_Report::get_reports('ReportAdmin') as $report) {
71 if($report->canView()) $output->push($report);
72 }
73 return $output;
74 }
75
76 77 78 79 80
81 public function show($request) {
82 $params = $request->allParams();
83
84 return $this->showWithEditForm($params, $this->reportEditFormFor($params['ID']));
85 }
86
87 88 89 90 91 92 93
94 protected function showWithEditForm($params, $editForm) {
95 if(isset($params['ID'])) Session::set('currentReport', $params['ID']);
96 if(isset($params['OtherID'])) Session::set('currentOtherID', $params['OtherID']);
97
98 if(Director::is_ajax()) {
99 SSViewer::setOption('rewriteHashlinks', false);
100
101 $result = $this->customise(array(
102 'EditForm' => $editForm
103 ))->renderWith($this->getTemplatesWithSuffix('_right'));
104
105 return $this->getLastFormIn($result);
106 }
107
108 return array();
109 }
110
111 112 113 114 115 116 117
118 public function EditForm() {
119
120 $id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : ($this->getRequest()->latestParam('Action') == 'EditForm') ? Session::get('currentReport') : null;
121
122 if($id) {
123 foreach($this->Reports() as $report) {
124 if($id == $report->ID()) return $this->reportEditFormFor($id);
125 }
126 }
127 return false;
128 }
129
130 131 132 133 134
135 public function CurrentReport() {
136 $id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : ($this->getRequest()->latestParam('Action') == 'EditForm') ? Session::get('currentReport') : null;
137
138 if($id) {
139 foreach($this->Reports() as $report) {
140 if($id == $report->ID()) return $report;
141 }
142 }
143 return false;
144 }
145
146 147 148 149 150 151 152 153 154 155 156
157 public function reportEditFormFor($id) {
158 $page = false;
159 $fields = new FieldSet();
160 $actions = new FieldSet();
161
162 $reports = SS_Report::get_reports('ReportAdmin');
163 $obj = $reports[$id];
164
165 if($obj) $fields = $obj->getCMSFields();
166 if($obj) $actions = $obj->getCMSActions();
167
168 $idField = new HiddenField('ID');
169 $idField->setValue($id);
170 $fields->push($idField);
171
172 $form = new Form($this, 'EditForm', $fields, $actions);
173
174 $form->loadDataFrom($_REQUEST);
175
176
177 $filteredCriteria = array_merge($_GET, $_POST);
178 foreach(array('ID','url','ajax','ctf','update','action_updatereport','SecurityID') as $notAParam) {
179 unset($filteredCriteria[$notAParam]);
180 }
181
182 $formLink = $this->Link() . '/EditForm';
183 if($filteredCriteria) $formLink .= '?' . http_build_query($filteredCriteria);
184 $form->setFormAction($formLink);
185 $form->setTemplate('ReportAdminForm');
186
187 return $form;
188 }
189
190 191 192 193 194 195 196 197 198 199 200
201 public static function has_reports() {
202 return sizeof(SS_Report::get_reports('ReportAdmin')) > 0;
203 }
204
205 public function updatereport() {
206 FormResponse::load_form($this->EditForm()->forTemplate());
207 return FormResponse::respond();
208 }
209 }
210
211
212
213
214
215 ?>
216
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-