masterTemplate = 'ticket.html'; $this->id = $pi ? $pi: (isset($_GET['id']) ? $_GET['id'] : 0); $this->id = (int) $this->id; $this->loadIssue(); $this->initEditForm(); } function loadIssue( ) { // -- load issue.. we should share this code with ticketedit really.. //DB_DataObject::debugLevel(1); $this->issue = DB_DataObject::factory('mtrack_ticket'); $this->issue->autoJoin(); if (!$this->id || !$this->issue->get($this->id)) { $this->jerr("no such ticket"); } if ($this->issue->project_id != $this->currentProject()) { $this->jerr("not in current project"); } //$this->issue->augmentFormFields($this->fieldset()); $this->preview = false; $this->error = array(); if (!$this->id && !$this->hasPerm('MTrack.Issue','A')) { return HTML_FlexyFramework::run('Noperm'); } if ($this->id && ( !$this->hasPerm('MTrack.Issue','S') )) { $this->jerr('no permission'); } $this->editable = !$this->hasPerm('MTrack.Issue','E') ; //$this->issue->milestoneURL = $this->baseURL.'/Milestone'; // fix me later.. $this->showEditBar = false; if ($this->editable && $this->id && !$this->preview) { $this->showEditBar = true; } $this->issue->images = $this->issue->images(); } function post() // handle the post... { $this->id = empty($_POST['id']) ? 0 : $_POST['id']; $this->loadIssue(); $old = clone($this->issue); // $this->preview = isset($_POST['preview']) ? true : false; if (!$this->hasPerm('MTrack.Issue','E') ) { $this->jerr("permission denied"); } $comment = empty($_POST['comment']) ? '' : $_POST['comment']; // $CS = MTrackChangeset::begin("ticket:X", $comment); $act= explode('_', $_POST['status'] , 2); //var_dump($act);exit; // input type='radio' id='none' name='status' value='{issue.status}' checked='checked'> //
// // switch ($act[0]) { case 'accept': // will be applied to the issue further down $this->issue->owner_id = $this->authUser->id; if ($this->issue->status_name == 'new') { $d = DB_DataObject::factory('core_enum'); $d->etype = 'ticketstate'; $d->name = 'open'; // assigned? $d->find(true); $this->issue->status = $d->id; } break; case 'resolution': //$this->issue->resolution = $_POST['resolution']; $this->issue->resolution_id = $act[1]; $d = DB_DataObject::factory('core_enum'); $d->etype = 'ticketstate'; $d->name = 'closed'; // assigned? $d->find(true); $this->issue->status = $d->id; //$this->issue->close(); //$_POST['estimated'] = $this->issue->estimated; break; case 'change': $this->issue->status = $act[1]; break; // default leave - stays tehe same.. } // things that we should not allow.. foreach(array( 'estimated', 'effort', 'owner_id', ) as $k) { if (isset($_POST[$k])) { $this->issue->setFrom(array($k => $_POST[$k])); } } // $this->issue->addEffort( // empty($_POST['spent']) ? 0 : $_POST['spent'], // empty($_POST['estimate']) ? 0 : $_POST['estimate'] //); // we should really use begin/commit to determin if something has changed.. // and produce an error.. $CS = DB_DataObject::factory('mtrack_change'); $CS->begin($this->issue, empty($_POST['comment']) ? '' : $_POST['comment']); //if (!empty($_POST['comment'])) { // create a comment CS.. //} $CS->add($this->issue, $old); $this->issue->updated = $CS->id; $this->issue->update($old); if (!empty($_FILES['attachments'])) { foreach ($_FILES['attachments']['name'] as $fileid => $name) { $i = DB_DataObject::factory('Images'); $i->object($this->issue); $i->ontable = $this->issue->tableName(); $i->onid = $this->issue->id; $i->created_by = $this->authUser->id; $i->mimetype = $_FILES['attachments']["type"][$fileid]; $i->createFrom($_FILES['attachments']['tmp_name'][$fileid],$_FILES['attachments']['name'][$fileid]); // MTrackAttachment::add("ticket:{$this->issue->tid}", // $_FILES['attachments']['tmp_name'][$fileid], // $_FILES['attachments']['name'][$fileid], // $CS // ); //} } } /* if (!count($this->error) && $this->id != 'new') { require_once 'MTrack/Attachment.php'; MTrackAttachment::process_delete("ticket:{$this->issue->tid}", $CS); } */ $notify_query = " (ontable='mtrack_ticket' and onid = {$this->issue->id}) OR (ontable='Projects' and onid = {$this->issue->project_id}) "; $w = DB_DataObject::factory('core_watch'); $w->ensureNotify( 'mtrack_ticket' , $this->issue->id, $this->authUser->id, $notify_query ); $w->ensureNotify( 'mtrack_ticket' , $this->issue->id, $this->issue->owner_id, $notify_query ); $w->ensureNotify( 'mtrack_ticket' , $this->issue->id, $this->issue->developer_id, $notify_query ); //DB_DataObject::debugLevel(1); // who to notify.. // who to notify.. -- originall did not send to issuer.. // we should probably make this configurable.. $w->notify( 'mtrack_ticket' , $this->issue->id, $notify_query /* " ( $notify_query ) AND (person_id != {$this->authUser->id}) " */ ); // if the owner has changed.. then we should add them to the watch list... // MTrackWatch::watch_object('ticket', $this->issue->tid, $this->issue->owner); $this->jok("OK"); } function initEditForm($params = array()) { require_once 'HTML/Template/Flexy/Element.php'; require_once 'HTML/Template/Flexy/Factory.php'; $this->elements = array(); // FIX ME - need to determine who the owner is.. // for a new issue it's the person who created it. // later on it's an assignement??? // DB_DataObject::debugLevel(1); $pd = DB_DataObject::factory('ProjectDirectory'); $pd->project_id = $this->currentProject(); $pd->whereAdd("ProjectDirectory.role != ''"); $pd->joinAdd(DB_DataObject::factory('core_person'), 'LEFT'); $pd->selectAdd(); $pd->selectAdd("distinct(Person.id) as id , CONCAT(Person.name , '<', Person.email , '>') as name"); $pd->groupBy('Person.id, Person.name'); $pd->orderBy('Person.name'); $users = $pd->fetchAll('id', 'name'); //$users = array(); $this->elements['owner_id'] = new HTML_Template_Flexy_Element('select'); $this->elements['owner_id']->setOptions($users); // keywords -- in toArray... // milestone foreach(array( 'resolution', 'ticketstate' ) as $c) { $d = DB_DataObject::factory('core_enum'); $d->etype = $c; $d->orderBy('seqid ASC, name ASC'); if (!$d->count()) { $d->createBaseEntries(); } $this->{$c} = $d->fetchAll('id','name'); } // unset($ST['closed']); // unset($ST[$this->issue->status]); // $this->change_status = empty($ST) ? array() : array_keys($ST); // admin can only change to 'fixed'? $this->elements = HTML_Template_Flexy_Factory::fromArray($this->issue->toArray(), $this->elements); } function eq($a,$b) { return $a == $b; } }