get2($pi); } if (!isset($_REQUEST['ajax_body'])) { return; } $this->masterTemplate = 'report.html'; $this->id = $pi ? $pi: (isset($_GET['id']) ? $_GET['id'] : 0); $this->id = $this->id == 'new' ? 0 : $this->id; $this->id = (int) $this->id; $pi = (int) $pi; $this->edit = !empty($_REQUEST['edit']); if ($this->edit || !$pi) { throw new Exception("no editing yet"); } // only support id??? $rep = DB_DataObject::factory('mtrack_report'); $rep->get($pi); // eventually GET.. // select boxes for quickly changing stuff.. foreach(array( 'classification', 'priority', 'severity', 'resolution' ) as $c) { $d = DB_DataObject::factory('core_enum'); $d->etype = $c; $d->orderBy('seqid ASC, name ASC'); if (!$d->count()) { $d->createBaseEntries(); } $ar = $d->fetchAll('id','name'); if (!$this->id) { $ar = array_merge( array(0 => '-- Select --'),$ar); } $this->elements[$c.'_id'] = new HTML_Template_Flexy_Element('select'); $this->elements[$c.'_id']->setOptions($ar); } // DB_DataObject::debugLevel(1); ///$rep = MTrack_Report::loadBySummary($pi); ///MTrackACL::requireAllRights("report:" . $rep->rid, $edit ? 'modify' : 'read'); if (!empty($_GET['format']) && $pi) { // targeted report format; omit decoration <<< ??? tab delimited only at present? $params = $_GET; $params['format'] = isset($params['format']) ? $_GET['format'] : 'html' ; $format = $params['format']; unset($params['format']); switch ($format) { case 'tab': header('Content-Type: text/plain'); break; } echo $rep->render( $params, $format); exit; } /* $this->title = "Create Report"; if ($pi) { $this->title = $this->edit ? ('{' . $rep->id . '} ' . $rep->summary . " (edit)") : '{' . $rep->id . '} ' . $rep->summary; } */ // $this->canModify = MTrackACL::hasAllRights("report:" . $rep->rid, 'modify'); $this->rep = $rep; } function get2($pi) { // the ajax version... // just returns data which can be rendered using the jtemplate code.. $this->id = $pi ? $pi: (isset($_GET['id']) ? $_GET['id'] : 0); $this->id = $this->id == 'new' ? 0 : $this->id; $this->id = (int) $this->id; $pi = (int) $pi; // only support id??? $rep = DB_DataObject::factory('mtrack_report'); $rep->get($pi); // eventually GET.. $this->jdata($rep->renderToJSON(), false, array('report' => $rep->toArray()) ); $this->rep = $rep; } function post($pi=0) { die("not yet"); $pi = (int) $pi; if (!$pi) { MTrackACL::requireAllRights('Reports', 'create'); $rep = new MTrack_Report; } // only support id??? if ($pi) { $rep = DB_DataObject::factory('mtrack_report'); $rep->get($pi); MTrackACL::requireAllRights("report:" . $rep->rid, 'modify'); } $rep->summary = $_POST['name']; $rep->description = $_POST['description']; $rep->query = $_POST['query']; if (isset($_POST['cancel'])) { header("Location: {$this->baseURL}/Reports"); exit; } // in theory... everything else is a 'save'... try { // this does not match api!?? $cs = DB_DataObject::Factory('mtrack_change'); $cs->beginChange( "report:" . $rep->summary, $_POST['comment']); $rep->save($cs); $cs->commit(); return $this->get($pi); } catch (Exception $e) { $this->message = $e->getMessage(); } return $this->get($pi); } }