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
20 if (isset($_REQUEST['ajax_body2'])) {
21 return $this->get2($pi);
23 if (!isset($_REQUEST['ajax_body'])) {
26 $this->masterTemplate = 'report.html';
27 $this->id = $pi ? $pi: (isset($_GET['id']) ? $_GET['id'] : 0);
28 $this->id = $this->id == 'new' ? 0 : $this->id;
29 $this->id = (int) $this->id;
33 $this->edit = !empty($_REQUEST['edit']);
39 if ($this->edit || !$pi) {
40 throw new Exception("no editing yet");
43 $rep = DB_DataObject::factory('mtrack_report');
44 $rep->get($pi); // eventually GET..
49 // select boxes for quickly changing stuff..
52 foreach(array( 'classification', 'priority', 'severity', 'resolution' ) as $c) {
53 $d = DB_DataObject::factory('core_enum');
55 $d->orderBy('seqid ASC, name ASC');
57 $d->createBaseEntries();
60 $ar = $d->fetchAll('id','name');
62 $ar = array_merge( array(0 => '-- Select --'),$ar);
64 $this->elements[$c.'_id'] = new HTML_Template_Flexy_Element('select');
65 $this->elements[$c.'_id']->setOptions($ar);
69 // DB_DataObject::debugLevel(1);
70 ///$rep = MTrack_Report::loadBySummary($pi);
71 ///MTrackACL::requireAllRights("report:" . $rep->rid, $edit ? 'modify' : 'read');
73 if (!empty($_GET['format']) && $pi) {
74 // targeted report format; omit decoration <<< ??? tab delimited only at present?
76 $params['format'] = isset($params['format']) ? $_GET['format'] : 'html' ;
77 $format = $params['format'];
79 unset($params['format']);
82 header('Content-Type: text/plain');
85 echo $rep->render( $params, $format);
89 $this->title = "Create Report";
91 $this->title = $this->edit ?
92 ('{' . $rep->id . '} ' . $rep->summary . " (edit)") :
93 '{' . $rep->id . '} ' . $rep->summary;
96 // $this->canModify = MTrackACL::hasAllRights("report:" . $rep->rid, 'modify');
105 // the ajax version...
106 // just returns data which can be rendered using the jtemplate code..
109 $this->id = $pi ? $pi: (isset($_GET['id']) ? $_GET['id'] : 0);
110 $this->id = $this->id == 'new' ? 0 : $this->id;
111 $this->id = (int) $this->id;
116 // only support id???
117 $rep = DB_DataObject::factory('mtrack_report');
119 $rep->get($pi); // eventually GET..
121 $this->jdata($rep->renderToJSON(), false,
122 array('report' => $rep->toArray())
137 MTrackACL::requireAllRights('Reports', 'create');
138 $rep = new MTrack_Report;
140 // only support id???
142 $rep = DB_DataObject::factory('mtrack_report');
144 MTrackACL::requireAllRights("report:" . $rep->rid, 'modify');
147 $rep->summary = $_POST['name'];
148 $rep->description = $_POST['description'];
149 $rep->query = $_POST['query'];
150 if (isset($_POST['cancel'])) {
151 header("Location: {$this->baseURL}/Reports");
154 // in theory... everything else is a 'save'...
156 $cs = DB_DataObject::Factory('mtrack_change');
157 $cs->begin( "report:" . $rep->summary, $_POST['comment']);
160 return $this->get($pi);
161 } catch (Exception $e) {
162 $this->message = $e->getMessage();
164 return $this->get($pi);