php8
[web.mtrack] / MTrackWeb / Milestone.php
1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
3
4 require_once 'MTrackWeb.php';
5
6
7 class MTrackWeb_Milestone extends MTrackWeb
8 {
9     var $id; // 0 = new
10     var $issue;
11     var $preview;
12     var $error;
13     var $editable;
14     var $tid = 0; // or the MD5 rep.
15     
16       
17     function get($pi= 0)
18     {
19     
20         if (!isset($_REQUEST['ajax_body'])) {
21             return;
22         }
23         $this->masterTemplate = 'milestone.html';
24         $this->id = $pi ?  $pi: (isset($_GET['id']) ? $_GET['id'] : 0);
25         $this->id  = (int) $this->id;
26         
27         if (empty($this->id)) { // new!!
28             return;
29         }
30         $m = DB_DataObject::factory('mtrack_milestone');
31         if (!$m->get($this->id) || $m->project_id != $this->currentProject()) {
32             $this->jerr("invalid milestone id");
33         }
34
35         $this->milestone = $m;
36     }
37     
38     function post($pi)
39     {
40         $m = DB_DataObject::factory('mtrack_milestone');
41         if (!empty($pi)) {
42             if (!$m->get($pi) || $m->project_id != $this->currentProject()) {
43                 $this->jerr("invalid milestone id");
44             }
45             $old = clone($m);
46         }
47         
48         $m->setFrom($_POST);
49         // alwasy for force this..
50         $m->project_id = $this->currentProject();
51         
52         // before we insert / update... - check perms..
53         
54         
55         // - we probably need finer grained control here..
56         // - we are piggy backing of issue permission at present..
57         
58         if (!$m->id && !$this->hasPerm('MTrack.Issue','A')) {
59             $this->jerr('Permission denied = no rights to create milestones', array('noperm' => true));
60             //return HTML_FlexyFramework::run('Noperm');
61         }
62         
63         
64         if ($m->id &&   !$this->hasPerm('MTrack.Issue','E')   ) {
65             $this->jerr('Permission denied = no rights to edit milestones', array('noperm' => true));
66             return HTML_FlexyFramework::run('Noperm');
67         }
68         
69         if ($m->id) {
70             $m->update($old);
71         } else {
72             $m->insert();
73         }
74         $this->jok("added");
75         
76          
77         
78         
79         
80     }
81 }