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");
41 $rep = DB_DataObject::factory('mtrack_report');
42 $rep->get($pi); // eventually GET..
47 // select boxes for quickly changing stuff..
50 foreach(array( 'classification', 'priority', 'severity', 'resolution' ) as $c) {
51 $d = DB_DataObject::factory('core_enum');
53 $d->orderBy('seqid ASC, name ASC');
55 $d->createBaseEntries();
58 $ar = $d->fetchAll('id','name');
60 $ar = array_merge( array(0 => '-- Select --'),$ar);
62 $this->elements[$c.'_id'] = new HTML_Template_Flexy_Element('select');
63 $this->elements[$c.'_id']->setOptions($ar);
67 // DB_DataObject::debugLevel(1);
68 ///$rep = MTrack_Report::loadBySummary($pi);
69 ///MTrackACL::requireAllRights("report:" . $rep->rid, $edit ? 'modify' : 'read');
71 if (!empty($_GET['format']) && $pi) {
72 // targeted report format; omit decoration <<< ??? tab delimited only at present?
74 $params['format'] = isset($params['format']) ? $_GET['format'] : 'html' ;
75 $format = $params['format'];
77 unset($params['format']);
80 header('Content-Type: text/plain');
83 echo $rep->render( $params, $format);
87 $this->title = "Create Report";
89 $this->title = $this->edit ?
90 ('{' . $rep->id . '} ' . $rep->summary . " (edit)") :
91 '{' . $rep->id . '} ' . $rep->summary;
94 // $this->canModify = MTrackACL::hasAllRights("report:" . $rep->rid, 'modify');
103 // the ajax version...
104 // just returns data which can be rendered using the jtemplate code..
107 if (!isset($_REQUEST['ajax_body'])) {
110 $this->id = $pi ? $pi: (isset($_GET['id']) ? $_GET['id'] : 0);
111 $this->id = $this->id == 'new' ? 0 : $this->id;
112 $this->id = (int) $this->id;
117 // only support id???
118 $rep = DB_DataObject::factory('mtrack_report');
120 $rep->get($pi); // eventually GET..
122 $this->jdata($rep->renderToJSON(), false,
123 array('report' => $rep->toArray())
145 MTrackACL::requireAllRights('Reports', 'create');
146 $rep = new MTrack_Report;
148 // only support id???
150 $rep = DB_DataObject::factory('mtrack_report');
152 MTrackACL::requireAllRights("report:" . $rep->rid, 'modify');
155 $rep->summary = $_POST['name'];
156 $rep->description = $_POST['description'];
157 $rep->query = $_POST['query'];
158 if (isset($_POST['cancel'])) {
159 header("Location: {$this->baseURL}/Reports");
162 // in theory... everything else is a 'save'...
164 $cs = DB_DataObject::Factory('mtrack_change');
165 $cs->begin( "report:" . $rep->summary, $_POST['comment']);
168 return $this->get($pi);
169 } catch (Exception $e) {
170 $this->message = $e->getMessage();
172 return $this->get($pi);