1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
4 //require_once 'MTrack/Captcha.php';
7 require_once 'MTrackWeb.php';
8 class MTrackWeb_Ticket extends MTrackWeb
15 var $tid = 0; // or the MD5 rep.
22 //require_once 'MTrack/ACL.php';
23 // MTrackACL::requireAllRights('Browser', 'read');
31 if (!isset($_REQUEST['ajax_body'])) {
34 $this->masterTemplate = 'ticket.html';
35 $this->id = $pi ? $pi: (isset($_GET['id']) ? $_GET['id'] : 0);
36 $this->id = (int) $this->id;
38 $this->initEditForm();
45 // -- load issue.. we should share this code with ticketedit really..
46 //DB_DataObject::debugLevel(1);
47 $this->issue = DB_DataObject::factory('mtrack_ticket');
48 $this->issue->autoJoin();
49 if (!$this->id || !$this->issue->get($this->id)) {
50 $this->jerr("no such ticket");
53 if ($this->issue->project_id != $this->currentProject()) {
54 $this->jerr("not in current project");
61 //$this->issue->augmentFormFields($this->fieldset());
64 $this->preview = false;
65 $this->error = array();
68 if (!$this->id && !$this->hasPerm('MTrack.Issue','A')) {
69 return HTML_FlexyFramework::run('Noperm');
72 if ($this->id && ( !$this->hasPerm('MTrack.Issue','S') )) {
73 $this->jerr('no permission');
76 $this->editable = !$this->hasPerm('MTrack.Issue','E') ;
78 //$this->issue->milestoneURL = $this->baseURL.'/Milestone'; // fix me later..
80 $this->showEditBar = false;
82 if ($this->editable && $this->id && !$this->preview) {
83 $this->showEditBar = true;
91 function post() // handle the post...
94 $this->id = empty($_POST['id']) ? 0 : $_POST['id'];
96 $old = clone($this->issue);
98 // $this->preview = isset($_POST['preview']) ? true : false;
99 if (!$this->hasPerm('MTrack.Issue','E') ) {
100 $this->jerr("permission denied");
104 $comment = empty($_POST['comment']) ? '' : $_POST['comment'];
107 // $CS = MTrackChangeset::begin("ticket:X", $comment);
110 $act= explode('_', $_POST['status'] , 2);
111 //var_dump($act);exit;
112 // input type='radio' id='none' name='status' value='{issue.status}' checked='checked'>
113 // <label for='accept'>Assign this ticket to <b style="color:red">ME</b></label><br>
114 // <input type='radio' id='ticketstate_{cid}' name='status' value='change_{cid}' flexy:ignore="yes">
115 // <input type='radio' id='resolution_{cid}' name='status' value='resolution_{cid}' flexy:ignore="yes">
122 // will be applied to the issue further down
123 $this->issue->owner_id = $this->authUser->id;
124 if ($this->issue->status_name == 'new') {
125 $d = DB_DataObject::factory('core_enum');
126 $d->etype = 'ticketstate';
127 $d->name = 'open'; // assigned?
129 $this->issue->status = $d->id;
135 //$this->issue->resolution = $_POST['resolution'];
136 $this->issue->resolution_id = $act[1];
137 $d = DB_DataObject::factory('core_enum');
138 $d->etype = 'ticketstate';
139 $d->name = 'closed'; // assigned?
141 $this->issue->status = $d->id;
142 //$this->issue->close();
143 //$_POST['estimated'] = $this->issue->estimated;
147 $this->issue->status = $act[1];
150 // default leave - stays tehe same..
153 // things that we should not allow..
155 'estimated', 'effort', 'owner_id',
157 if (isset($_POST[$k])) {
158 $this->issue->setFrom(array($k => $_POST[$k]));
162 // $this->issue->addEffort(
163 // empty($_POST['spent']) ? 0 : $_POST['spent'],
164 // empty($_POST['estimate']) ? 0 : $_POST['estimate']
167 // we should really use begin/commit to determin if something has changed..
168 // and produce an error..
171 $CS = DB_DataObject::factory('mtrack_change');
172 $CS->begin($this->issue, empty($_POST['comment']) ? '' : $_POST['comment']);
175 //if (!empty($_POST['comment'])) {
176 // create a comment CS..
179 $CS->add($this->issue, $old);
180 $this->issue->updated = $CS->id;
181 $this->issue->update($old);
184 (ontable='mtrack_ticket' and onid = {$this->issue->id})
186 (ontable='Projects' and onid = {$this->issue->project_id})
189 $w->ensureNotify( 'mtrack_ticket' ,
195 $w->ensureNotify( 'mtrack_ticket' ,
197 $this->issue->owner_id,
201 $w->ensureNotify( 'mtrack_ticket' ,
203 $this->issue->developer_id,
206 //DB_DataObject::debugLevel(1);
208 $w = DB_DataObject::factory('core_watch');
209 $w->notify( 'mtrack_ticket' , $this->issue->id,
212 (person_id != {$this->authUser->id}) "
217 // if the owner has changed.. then we should add them to the watch list...
219 // MTrackWatch::watch_object('ticket', $this->issue->tid, $this->issue->owner);
221 if (!count($this->error)) {
222 if (!empty($_FILES['attachments'])) {
223 require_once 'MTrack/Attachment.php';
224 foreach ($_FILES['attachments']['name'] as $fileid => $name) {
226 MTrackAttachment::add("ticket:{$this->issue->tid}",
227 $_FILES['attachments']['tmp_name'][$fileid],
228 $_FILES['attachments']['name'][$fileid],
234 if (!count($this->error) && $this->id != 'new') {
235 require_once 'MTrack/Attachment.php';
236 MTrackAttachment::process_delete("ticket:{$this->issue->tid}", $CS);
244 function initEditForm($params = array())
246 require_once 'HTML/Template/Flexy/Element.php';
247 require_once 'HTML/Template/Flexy/Factory.php';
248 $this->elements = array();
252 // FIX ME - need to determine who the owner is..
253 // for a new issue it's the person who created it.
254 // later on it's an assignement???
255 // DB_DataObject::debugLevel(1);
256 $pd = DB_DataObject::factory('ProjectDirectory');
257 $pd->project_id = $this->currentProject();
258 $pd->whereAdd("ProjectDirectory.role != ''");
259 $pd->joinAdd(DB_DataObject::factory('Person'), 'LEFT');
261 $pd->selectAdd("distinct(Person.id) as id , CONCAT(Person.name , '<', Person.email , '>') as name");
262 $pd->groupBy('Person.id, Person.name');
263 $pd->orderBy('Person.name');
264 $users = $pd->fetchAll('id', 'name');
269 $this->elements['owner_id'] = new HTML_Template_Flexy_Element('select');
270 $this->elements['owner_id']->setOptions($users);
274 // keywords -- in toArray...
279 foreach(array( 'resolution', 'ticketstate' ) as $c) {
280 $d = DB_DataObject::factory('core_enum');
282 $d->orderBy('seqid ASC, name ASC');
284 $d->createBaseEntries();
287 $this->{$c} = $d->fetchAll('id','name');
293 // unset($ST['closed']);
294 // unset($ST[$this->issue->status]);
296 // $this->change_status = empty($ST) ? array() : array_keys($ST);
298 // admin can only change to 'fixed'?
300 $this->elements = HTML_Template_Flexy_Factory::fromArray($this->issue->toArray(), $this->elements);