1 <?php # vim:ts=4:sw=4:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
5 require_once 'MTrackWeb.php';
7 class MTrackWeb_Report extends MTrackWeb
21 if (!isset($_REQUEST['ajax_body'])) {
24 $this->masterTemplate = 'report.html';
25 $this->id = $pi ? $pi: (isset($_GET['id']) ? $_GET['id'] : 0);
26 $this->id = $this->id == 'new' ? 0 : $this->id;
27 $this->id = (int) $this->id;
31 $this->edit = !empty($_REQUEST['edit']);
37 if ($this->edit && !$pi) {
38 throw new Exception("no editing yet");
42 $rep = DB_DataObject::factory('mtrack_report');
43 // we do not have any reports yet... - so we have a dummy one..
45 //MTrackACL::requireAllRights("report:" . $rep->rid, $this->edit ? 'modify' : 'read');
52 ///$rep = MTrack_Report::loadBySummary($pi);
53 ///MTrackACL::requireAllRights("report:" . $rep->rid, $edit ? 'modify' : 'read');
56 // targeted report format; omit decoration <<< ??? tab delimited only at present?
58 $params['format'] = isset($params['format']) ? $_GET['format'] : '' ;
59 $format = $params['format'];
61 unset($params['format']);
64 header('Content-Type: text/plain');
67 echo $rep->renderReport($rep->query, $params, $format);
72 $this->title = "Create Report";
74 $this->title = $this->edit ?
75 ('{' . $rep->rid . '} ' . $rep->summary . " (edit)") :
76 '{' . $rep->rid . '} ' . $rep->summary;
78 $this->canModify = MTrackACL::hasAllRights("report:" . $rep->rid, 'modify');
90 MTrackACL::requireAllRights('Reports', 'create');
91 $rep = new MTrack_Report;
95 $rep = DB_DataObject::factory('mtrack_report');
97 MTrackACL::requireAllRights("report:" . $rep->rid, 'modify');
100 $rep->summary = $_POST['name'];
101 $rep->description = $_POST['description'];
102 $rep->query = $_POST['query'];
103 if (isset($_POST['cancel'])) {
104 header("Location: {$this->baseURL}/Reports");
107 // in theory... everything else is a 'save'...
109 $cs = DB_DataObject::Factory('mtrack_change');
110 $cs->begin( "report:" . $rep->summary, $_POST['comment']);
113 return $this->get($pi);
114 } catch (Exception $e) {
115 $this->message = $e->getMessage();
117 return $this->get($pi);