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();
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'];
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 = $this->authUser->id;
124 if ($this->issue->status_name == 'new') {
125 $d = DB_DataObject::factory('core_enum');
126 $d->etype = 'status';
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 = 'status';
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', 'comment'
158 $this->issue->setFrom($_POST);
160 $kw = $this->issue->getKeywords();
161 $kill = array_values($kw);
162 foreach (preg_split('/[ \t,]+/', $_POST['keywords']) as $w) {
166 $x = array_search($w, $kw);
168 $k = MTrackKeyword::loadByWord($w);
170 $k = new MTrackKeyword;
174 $this->issue->assocKeyword($k);
176 $w = array_search($w, $kill);
182 foreach ($kill as $w) {
183 $this->issue->dissocKeyword($w);
186 $ms = $this->issue->getMilestones();
188 if (isset($_POST['milestone']) && is_array($_POST['milestone'])) {
189 foreach ($_POST['milestone'] as $mid) {
190 $this->issue->assocMilestone($mid);
194 foreach ($kill as $mid) {
195 $this->issue->dissocMilestone($mid);
198 $ms = $this->issue->getComponents();
200 if (isset($_POST['component']) && is_array($_POST['component'])) {
201 foreach ($_POST['component'] as $mid) {
202 $this->issue->assocComponent($mid);
206 foreach ($kill as $mid) {
207 $this->issue->dissocComponent($mid);
210 if (!empty($_POST['comment'])) {
211 $this->issue->addComment($_POST['comment']);
214 $this->issue->addEffort(
215 empty($_POST['spent']) ? 0 : $_POST['spent'],
216 empty($_POST['estimate']) ? 0 : $_POST['estimate']
219 if (!count($this->error)) {
221 $this->issue->save($CS);
223 // make sure everyone is watching it!!!!
224 if($this->issue->owner && $this->issue->tid) {
225 // make sure owner is tracking it...
226 MTrackWatch::watch_object('ticket', $this->issue->tid, $this->issue->owner);
229 if ($this->id == 'new') {
230 MTrackWatch::watch_object('ticket', $this->issue->tid, MTrackAuth::whoami());
234 $CS->setObject("ticket:" . $this->issue->tid);
235 } catch (Exception $e) {
236 $this->error[] = $e->getMessage();
240 if (!count($this->error)) {
241 if (!empty($_FILES['attachments'])) {
242 require_once 'MTrack/Attachment.php';
243 foreach ($_FILES['attachments']['name'] as $fileid => $name) {
245 MTrackAttachment::add("ticket:{$this->issue->tid}",
246 $_FILES['attachments']['tmp_name'][$fileid],
247 $_FILES['attachments']['name'][$fileid],
253 if (!count($this->error) && $this->id != 'new') {
254 require_once 'MTrack/Attachment.php';
255 MTrackAttachment::process_delete("ticket:{$this->issue->tid}", $CS);
258 if (isset($_POST['apply']) && !count($this->error)) {
260 header("Location: {$this->baseURL}/Ticket/{$this->issue->nsident}");
266 function initEditForm($params = array())
268 require_once 'HTML/Template/Flexy/Element.php';
269 require_once 'HTML/Template/Flexy/Factory.php';
270 $this->elements = array();
274 // FIX ME - need to determine who the owner is..
275 // for a new issue it's the person who created it.
276 // later on it's an assignement???
280 $this->elements['owner'] = new HTML_Template_Flexy_Element('select');
281 $this->elements['owner']->setOptions($users);
285 // keywords -- in toArray...
290 foreach(array( 'resolution', 'ticketstate' ) as $c) {
291 $d = DB_DataObject::factory('core_enum');
293 $d->orderBy('seqid ASC, name ASC');
295 $d->createBaseEntries();
298 $this->{$c} = $d->fetchAll('id','name');
304 // unset($ST['closed']);
305 // unset($ST[$this->issue->status]);
307 // $this->change_status = empty($ST) ? array() : array_keys($ST);
309 // admin can only change to 'fixed'?
311 $this->elements = HTML_Template_Flexy_Factory::fromArray($this->issue->toArray(), $this->elements);