MTrackWeb/Report.php
[web.mtrack] / MTrackWeb / Report.php
1 <?php # vim:ts=4:sw=4:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
3
4
5 require_once 'MTrackWeb.php';
6  
7 class MTrackWeb_Report extends MTrackWeb
8 {
9     
10     function getAuth() 
11     {
12         parent::getAuth();
13        
14         return true;
15     }
16     
17     function get($pi=0)
18     {
19        
20        
21         if (!isset($_REQUEST['ajax_body'])) {
22             return;
23         }
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;
28         
29        
30         $pi = (int) $pi;
31         $this->edit = !empty($_REQUEST['edit']);
32         
33         
34         
35         
36         
37         if ($this->edit && !$pi) {
38             throw new Exception("no editing yet");
39         }
40         // only support id???
41         if ($pi) {
42             $rep = DB_DataObject::factory('mtrack_report');
43             // we do not have any reports yet... - so we have a dummy one..
44             //$rep->get($pi);
45             //MTrackACL::requireAllRights("report:" . $rep->rid, $this->edit ? 'modify' : 'read');
46         }
47     
48         
49     
50     
51     
52         ///$rep = MTrack_Report::loadBySummary($pi);
53         ///MTrackACL::requireAllRights("report:" . $rep->rid, $edit ? 'modify' : 'read');
54
55         if ($pi) {
56           // targeted report format; omit decoration <<< ??? tab delimited only at present?
57             $params = $_GET;
58             $params['format'] = isset($params['format']) ? $_GET['format'] : '' ;
59             $format = $params['format'];
60             
61             unset($params['format']);
62             switch ($format) {
63                 case 'tab':
64                     header('Content-Type: text/plain');
65                     break;
66             }
67             echo $rep->renderReport($rep->query, $params, $format);
68             exit;
69         }
70         
71         die("not yet");
72         $this->title = "Create Report";
73         if ($pi) {
74             $this->title = $this->edit ? 
75                 ('{' . $rep->rid . '} ' . $rep->summary . " (edit)") : 
76                 '{' . $rep->rid . '} ' . $rep->summary;
77         }
78         $this->canModify = MTrackACL::hasAllRights("report:" . $rep->rid, 'modify');
79         $this->rep = $rep;
80         
81          
82
83     }
84     
85     function post($pi=0)
86     {
87         die("not yet");
88         $pi = (int) $pi;
89         if (!$pi) {
90             MTrackACL::requireAllRights('Reports', 'create');
91             $rep = new MTrack_Report;
92         }
93         // only support id???
94         if ($pi) {
95             $rep = DB_DataObject::factory('mtrack_report');
96             $rep->get($pi);
97             MTrackACL::requireAllRights("report:" . $rep->rid, 'modify');
98         }
99         
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");
105             exit;
106         }
107         // in theory... everything else is a 'save'...
108         try {
109             $cs = DB_DataObject::Factory('mtrack_change');
110             $cs->begin( "report:" . $rep->summary, $_POST['comment']);
111             $rep->save($cs);
112             $cs->commit();
113             return $this->get($pi);
114         } catch (Exception $e) {
115             $this->message = $e->getMessage();
116         }
117         return $this->get($pi);
118         
119         
120     }
121         
122         
123         
124  
125 }