final move of files
[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     var $template = 'report.html';
10  
11     function getAuth() 
12     {
13         parent::getAuth();
14         require_once 'MTrack/ACL.php';
15         MTrackACL::requireAllRights('Reports', 'read');
16         return true;
17     }
18     
19     function get($pi=0)
20     {
21         $pi = (int) $pi;
22         $this->edit = !empty($_REQUEST['edit']);
23         
24         if ($this->edit && !$pi) {
25             MTrackACL::requireAllRights('Reports', 'create');
26             $rep = new MTrack_Report;
27         }
28         // only support id???
29         if ($pi) {
30             $rep = MTrack_Report::loadByID($pi);
31             MTrackACL::requireAllRights("report:" . $rep->rid, $this->edit ? 'modify' : 'read');
32         }
33     
34         ///$rep = MTrack_Report::loadBySummary($pi);
35         ///MTrackACL::requireAllRights("report:" . $rep->rid, $edit ? 'modify' : 'read');
36
37         if (isset($_GET['format'])) {
38           // targeted report format; omit decoration <<< ??? tab delimited only at present?
39             $params = $_GET;
40             unset($params['format']);
41             switch ($_GET['format']) {
42                 case 'tab':
43                     header('Content-Type: text/plain');
44                     break;
45             }
46             echo $rep->renderReport($rep->query, $params, $_GET['format']);
47             exit;
48         }
49         
50         $this->title = "Create Report";
51         if ($pi) {
52             $this->title = $this->edit ? 
53                 ('{' . $rep->rid . '} ' . $rep->summary . " (edit)") : 
54                 '{' . $rep->rid . '} ' . $rep->summary;
55         }
56         $this->canModify = MTrackACL::hasAllRights("report:" . $rep->rid, 'modify');
57         $this->rep = $rep;
58         
59         MTrack_Report::$link = $this->link;
60
61     }
62     
63     function post($pi=0)
64     {
65         $pi = (int) $pi;
66         if (!$pi) {
67             MTrackACL::requireAllRights('Reports', 'create');
68             $rep = new MTrack_Report;
69         }
70         // only support id???
71         if ($pi) {
72             $rep = MTrack_Report::loadByID($pi);
73             MTrackACL::requireAllRights("report:" . $rep->rid, 'modify');
74         }
75         $rep->summary = $_POST['name'];
76         $rep->description = $_POST['description'];
77         $rep->query = $_POST['query'];
78         if (isset($_POST['cancel'])) {
79             header("Location: {$this->baseURL}/Reports");
80             exit;
81         }
82         // in theory... everything else is a 'save'...
83         try {
84             $cs = MTrackChangeset::begin(
85                       "report:" . $rep->summary, $_POST['comment']);
86             $rep->save($cs);
87             $cs->commit();
88             return $this->get($pi);
89         } catch (Exception $e) {
90             $this->message = $e->getMessage();
91         }
92         return $this->get($pi);
93         
94         
95     }
96         
97         
98         
99  
100 }