|
@@ -0,0 +1,519 @@
|
|
|
+<?php
|
|
|
+global $_,$conf;
|
|
|
+switch($_['action']){
|
|
|
+ /** ISSUEREPORT **/
|
|
|
+ //Récuperation d'une liste de issuereport
|
|
|
+ case 'issue_issuereport_search':
|
|
|
+ Action::write(function(&$response){
|
|
|
+ global $myUser,$_;
|
|
|
+ User::check_access('issue','read');
|
|
|
+ require_once(__DIR__.SLASH.'IssueReport.class.php');
|
|
|
+ require_once(__DIR__.SLASH.'IssueEvent.class.php');
|
|
|
+ require_once(__DIR__.SLASH.'IssueReportTag.class.php');
|
|
|
+
|
|
|
+ $allTags = IssueReportTag::tags();
|
|
|
+ $query = 'SELECT DISTINCT {{table}}.id, {{table}}.*,(SELECT ie.content FROM '.IssueEvent::tableName().' ie WHERE ie.type=? AND ie.issue={{table}}.id ORDER BY id ASC LIMIT 1) as comment,(SELECT COUNT(ie2.id) FROM '.IssueEvent::tableName().' ie2 WHERE ie2.type=? AND ie2.issue={{table}}.id) as comments FROM {{table}} LEFT JOIN '.IssueReportTag::tableName().' t ON t.report={{table}}.id WHERE 1';
|
|
|
+ $data = array(IssueEvent::TYPE_COMMENT,IssueEvent::TYPE_COMMENT);
|
|
|
+
|
|
|
+ //Recherche simple
|
|
|
+ if(!empty($_['filters']['keyword'])){
|
|
|
+ $query .= ' AND {{table}}.label LIKE ?';
|
|
|
+ $data[] = '%'.$_['filters']['keyword'].'%';
|
|
|
+ }
|
|
|
+
|
|
|
+ $tags = array_filter(explode(',',$_['tags']));
|
|
|
+ if(count($tags)!=0){
|
|
|
+ $query .= ' AND t.tag IN ("'.implode('","',$tags).'")';
|
|
|
+ }
|
|
|
+
|
|
|
+ //Recherche avancée
|
|
|
+ if(isset($_['filters']['advanced'])) filter_secure_query($_['filters']['advanced'],array('from','comment','{{table}}.creator','{{table}}.created','browser','ip','state'),$query,$data);
|
|
|
+ $query .= ' ORDER BY {{table}}.id desc ';
|
|
|
+
|
|
|
+ //Pagination
|
|
|
+ $response['pagination'] = IssueReport::paginate(20,(!empty($_['page'])?$_['page']:0),$query,$data);
|
|
|
+
|
|
|
+ foreach(IssueReport::staticQuery($query,$data) as $row){
|
|
|
+ //$row = $issueReport->toArray(true);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $row['state'] = IssueReport::states($row['state']);
|
|
|
+ $row['relativefrom'] = str_replace(ROOT_URL,'',$row['from']);
|
|
|
+ $row['date'] = date('d-m-Y',$row['created']);
|
|
|
+ $row['hour'] = date('H:i',$row['created']);
|
|
|
+ $row['osIcon'] = 'fas fa-question-circle';
|
|
|
+ $row['browserIcon'] = 'fas fa-question-circle';
|
|
|
+
|
|
|
+ $row['comments'] = $row['comments']==1 ? false: $row['comments'];
|
|
|
+
|
|
|
+ $row['excerpt'] = isset($row['comment']) ? truncate(strip_tags($row['comment']),150) : 'Aucun commentaire';
|
|
|
+
|
|
|
+ if(strlen($row['os'])>=3 && substr(strtolower($row['os']),0,3) == 'win') $row['osIcon'] = 'fab fa-windows text-primary';
|
|
|
+ if(strlen($row['os'])>=5 && substr(strtolower($row['os']),0,5) == 'linux') $row['osIcon'] = 'fab fa-linux text-danger';
|
|
|
+ if(strlen($row['os'])>=3 && substr(strtolower($row['os']),0,3) == 'mac') $row['osIcon'] = 'fab fa-apple text-secondary';
|
|
|
+
|
|
|
+ switch($row['browser']){
|
|
|
+ case 'firefox': $row['browserIcon'] = 'fab fa-firefox text-warning'; break;
|
|
|
+ case 'ie': $row['browserIcon'] = 'fab fa-internet-explorer text-danger'; break;
|
|
|
+ case 'edge': $row['browserIcon'] = 'fab fa-edge text-primary'; break;
|
|
|
+ case 'chrome': $row['browserIcon'] = 'fab fa-chrome text-success'; break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $row['tags'] = array();
|
|
|
+ foreach(IssueReportTag::loadAll(array('report'=>$row['id'])) as $tag){
|
|
|
+ if(!isset($allTags[$tag->tag])) continue;
|
|
|
+ $row['tags'][] = $allTags[$tag->tag];
|
|
|
+ }
|
|
|
+ $response['rows'][] = $row;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'issue_add_document':
|
|
|
+ Action::write(function(&$response){
|
|
|
+ global $myUser,$_;
|
|
|
+ if(!$myUser->connected()) throw new Exception("Vous devez être connecté",401);
|
|
|
+ require_once(__DIR__.SLASH.'IssueReport.class.php');
|
|
|
+ require_once(__DIR__.SLASH.'IssueEvent.class.php');
|
|
|
+
|
|
|
+ $report = IssueReport::provide();
|
|
|
+ $report->save();
|
|
|
+
|
|
|
+ foreach ($_['files'] as $file) {
|
|
|
+ $name = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? utf8_decode($file['name']) : $file['name'];
|
|
|
+ $row = File::move(File::temp().$file['path'],'issue'.SLASH.'screens'.SLASH.$report->id.SLASH.$name);
|
|
|
+ $row['url'] = 'action.php?action=issue_download_document&event='.$event->id.'&path='.base64_encode($file['name']);
|
|
|
+ $row['oldPath'] = $file['path'];
|
|
|
+ $response['files'][] = $row;
|
|
|
+ }
|
|
|
+ $response['id'] = $report->id;
|
|
|
+ });
|
|
|
+ break;
|
|
|
+
|
|
|
+ //Téléchargement des documents
|
|
|
+ case 'issue_download_document':
|
|
|
+ global $myUser,$_;
|
|
|
+ if(!$myUser->connected()) throw new Exception("Vous devez être connecté",401);
|
|
|
+
|
|
|
+ require_once(__DIR__.SLASH.'IssueEvent.class.php');
|
|
|
+
|
|
|
+ $event = IssueEvent::getById($_['event']);
|
|
|
+ $path = str_replace(array('..','/','\\'),'',base64_decode($_['path']));
|
|
|
+ $path = $event->dir().SLASH.$path;
|
|
|
+ File::downloadFile($path);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'issue_issuereport_meta_save':
|
|
|
+ Action::write(function(&$response){
|
|
|
+ global $myUser,$_,$conf;
|
|
|
+ require_once(__DIR__.SLASH.'IssueReport.class.php');
|
|
|
+ require_once(__DIR__.SLASH.'IssueEvent.class.php');
|
|
|
+ require_once(__DIR__.SLASH.'IssueReportTag.class.php');
|
|
|
+ if(!array_key_exists($_['state'], IssueReport::states())) throw new Exception("L'état du ticket est invalide");
|
|
|
+
|
|
|
+ User::check_access('issue','edit');
|
|
|
+
|
|
|
+ $item = IssueReport::provide();
|
|
|
+ $oldItem = clone $item;
|
|
|
+
|
|
|
+ $item->state = $_['state'];
|
|
|
+ if(!empty($_['assign'])) $item->assign = $_['assign'];
|
|
|
+ $item->save();
|
|
|
+
|
|
|
+
|
|
|
+ //Maj des tags
|
|
|
+ $existingTags = IssueReportTag::loadAll(array('report'=>$item->id));
|
|
|
+ $tags = explode(',',$_['tags']);
|
|
|
+
|
|
|
+ $tagsAction = false;
|
|
|
+ $similarTags = array();
|
|
|
+ foreach ($existingTags as $existingTag) {
|
|
|
+ if(in_array($existingTag->tag, $tags)){
|
|
|
+ $similarTags[] = $existingTag->tag;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ IssueReportTag::deleteById($existingTag->id);
|
|
|
+ //var_dump($existingTag->tag);
|
|
|
+ $tagsAction = array('action'=>'deleted','tag'=>IssueReportTag::tags($existingTag->tag));
|
|
|
+ }
|
|
|
+ foreach ($tags as $tag) {
|
|
|
+ if(in_array($tag, $similarTags)) continue;
|
|
|
+ $newTag = new IssueReportTag();
|
|
|
+ $newTag->tag = $tag;
|
|
|
+ $newTag->report = $item->id;
|
|
|
+ $newTag->save();
|
|
|
+ $tagsAction = array('action'=>'added','tag'=>IssueReportTag::tags($tag));
|
|
|
+ }
|
|
|
+
|
|
|
+ if($tagsAction!=false){
|
|
|
+ $event = new IssueEvent();
|
|
|
+ $event->type = IssueEvent::TYPE_TAG;
|
|
|
+ $event->issue = $item->id;
|
|
|
+ $event->content = json_encode($tagsAction);
|
|
|
+ $event->save();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //Si l'assignation a changée on envoi une notification
|
|
|
+ if($oldItem->assign != $item->assign){
|
|
|
+
|
|
|
+ $event = new IssueEvent();
|
|
|
+ $event->type = IssueEvent::TYPE_ASSIGNATION;
|
|
|
+ $event->issue = $item->id;
|
|
|
+ $event->content = json_encode(array(
|
|
|
+ 'assigned' => $item->assign
|
|
|
+ ));
|
|
|
+ $event->save();
|
|
|
+
|
|
|
+ if($item->assign != $myUser->login){
|
|
|
+ Plugin::callHook("emit_notification", array(array(
|
|
|
+ 'label' => '['.PROGRAM_NAME.' - '.PROGRAM_UID.'] Le Ticket #'.$item->id.' vous a été assigné',
|
|
|
+ 'html' => "Le ticket <a href='".ROOT_URL."/index.php?module=issue&page=sheet.report&id=".$item->id."'>#".$item->id."</a> vous a été assigné par ".(!empty($myUser->fullName())?$myUser->fullName():$myUser->login)." le ".date('d-m-Y à H:i').".
|
|
|
+ <br>Bonne chance :).",
|
|
|
+ 'type' => "issue",
|
|
|
+ 'meta' => array('link' => ROOT_URL.'/index.php?module=issue&page=sheet.report&id='.$item->id),
|
|
|
+ 'recipients' => array($item->assign)
|
|
|
+ )));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //Si l'etat a changé on envois une notification
|
|
|
+ if($oldItem->state != $item->state){
|
|
|
+ switch ($item->state) {
|
|
|
+ case 'closed':
|
|
|
+ $infos = array(
|
|
|
+ 'label' => "Votre Ticket #".$item->id." est résolu",
|
|
|
+ 'html' => "Le ticket d'erreur <a href='".ROOT_URL."/index.php?module=issue&page=sheet.report&id=".$item->id."'>#".$item->id."</a> a été marqué comme résolu par ".(!empty($myUser->fullName())?$myUser->fullName():$myUser->login).' le '.date('d-m-Y à H:i').'.
|
|
|
+ <br>Il est possible que la résolution de cette erreur ne soit mise en production que dans quelques jours.',
|
|
|
+ 'type' => "notice",
|
|
|
+ 'meta' => array('link' => ROOT_URL.'/index.php?module=issue&page=sheet.report&id='.$item->id),
|
|
|
+ 'recipients' => array($item->creator)
|
|
|
+ );
|
|
|
+ break;
|
|
|
+ case 'open':
|
|
|
+ $infos = array(
|
|
|
+ 'label' => "Votre Ticket #".$item->id." a été ré-ouvert",
|
|
|
+ 'html' => "Le ticket d'erreur <a href='".ROOT_URL."/index.php?module=issue&page=sheet.report&id=".$item->id."'>#".$item->id."</a> a été ré-ouvert par ".(!empty($myUser->fullName())?$myUser->fullName():$myUser->login).' le '.date('d-m-Y à H:i').'.
|
|
|
+ <br>Il est possible que la résolution de cette erreur ne soit mise en production que dans quelques jours.',
|
|
|
+ 'type' => "notice",
|
|
|
+ 'meta' => array('link' => ROOT_URL.'/index.php?module=issue&page=sheet.report&id='.$item->id),
|
|
|
+ 'recipients' => array($item->creator)
|
|
|
+ );
|
|
|
+ break;
|
|
|
+ case 'canceled':
|
|
|
+ $infos = array(
|
|
|
+ 'label' => "Votre Ticket #".$item->id." a été annulé",
|
|
|
+ 'html' => "Le ticket d'erreur <a href='".ROOT_URL."/index.php?module=issue&page=sheet.report&id=".$item->id."'>#".$item->id."</a> a été annulé ".(!empty($myUser->fullName())?$myUser->fullName():$myUser->login).' le '.date('d-m-Y à H:i').'.
|
|
|
+ <br>Il est possible que ce ticket soit un doublon ou que son contenu soit innaproprié.',
|
|
|
+ 'type' => "notice",
|
|
|
+ 'meta' => array('link' => ROOT_URL.'/index.php?module=issue&page=sheet.report&id='.$item->id),
|
|
|
+ 'recipients' => array($item->creator)
|
|
|
+ );
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ # code...
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ $event = new IssueEvent();
|
|
|
+ $event->type = IssueEvent::TYPE_STATE;
|
|
|
+ $event->issue = $item->id;
|
|
|
+ $event->content = json_encode(array(
|
|
|
+ 'old' => $oldItem->state,
|
|
|
+ 'new' => $item->state
|
|
|
+ ));
|
|
|
+ $event->save();
|
|
|
+ Plugin::callHook("emit_notification", array($infos));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+ break;
|
|
|
+
|
|
|
+ //Ajout ou modification d'élément issuereport
|
|
|
+ case 'issue_issuereport_save':
|
|
|
+ Action::write(function(&$response){
|
|
|
+ global $myUser,$_,$conf;
|
|
|
+ require_once(__DIR__.SLASH.'IssueReport.class.php');
|
|
|
+ require_once(__DIR__.SLASH.'IssueEvent.class.php');
|
|
|
+ require_once(__DIR__.SLASH.'IssueReportTag.class.php');
|
|
|
+ if(!$myUser->connected()) throw new Exception("Vous devez être connecté pour laisser un rapport d'erreur",401);
|
|
|
+ $item = IssueReport::provide();
|
|
|
+ if(!$myUser->can('issue','edit') && is_numeric($item->id) && $item->id!=0) throw new Exception("Permissions insuffisantes",403);
|
|
|
+
|
|
|
+ $tags = array_filter(explode(',',$_['tags']));
|
|
|
+ if(count($tags)==0) throw new Exception("Merci de sélectionner au moins une catégorie");
|
|
|
+ if(!isset($_['issue-comment']) || empty($_['issue-comment'])) throw new Exception("Merci de commenter votre ticket");
|
|
|
+
|
|
|
+
|
|
|
+ $item->browser = $_['browser'];
|
|
|
+ $item->browserVersion = $_['browserVersion'];
|
|
|
+ $item->online = $_['online'];
|
|
|
+ $item->os = $_['os'];
|
|
|
+ $item->state = 'open';
|
|
|
+ $item->from = $_['from'];
|
|
|
+ $item->width = $_['width'];
|
|
|
+ $item->height = $_['height'];
|
|
|
+ $item->history = $_['history'];
|
|
|
+ $item->ip = ip();
|
|
|
+ $item->save();
|
|
|
+
|
|
|
+
|
|
|
+ $firstEvent = new IssueEvent();
|
|
|
+ $firstEvent->created = $item->created;
|
|
|
+ $firstEvent->updated = $item->updated;
|
|
|
+ $firstEvent->creator = $item->creator;
|
|
|
+ $firstEvent->updater = $item->updater;
|
|
|
+ $firstEvent->type = IssueEvent::TYPE_COMMENT;
|
|
|
+ $firstEvent->content = $_['issue-comment'];
|
|
|
+ $firstEvent->issue = $item->id;
|
|
|
+ $firstEvent->save();
|
|
|
+
|
|
|
+ $response['item'] = $item->toArray();
|
|
|
+
|
|
|
+ IssueReportTag::delete(array('report'=>$item->id));
|
|
|
+ foreach ($tags as $tag) {
|
|
|
+ $reportTag = new IssueReportTag();
|
|
|
+ $reportTag->tag = $tag;
|
|
|
+ $reportTag->report = $item->id;
|
|
|
+ $reportTag->save();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!empty($_['screenshot'])){
|
|
|
+ $screenshot = str_replace('data:image/png;base64,', '', $_['screenshot']);
|
|
|
+ $screenshot = str_replace(' ', '+', $screenshot);
|
|
|
+ $stream = base64_decode($screenshot);
|
|
|
+
|
|
|
+ $attachmentFolder = $firstEvent->dir();
|
|
|
+ if(!file_exists($attachmentFolder)) mkdir($attachmentFolder,0755,true);
|
|
|
+ $screenPath = $attachmentFolder.SLASH.'screenshot.jpg';
|
|
|
+ file_put_contents($screenPath, $stream);
|
|
|
+ }
|
|
|
+
|
|
|
+ //Ajout des fichiers joints
|
|
|
+ if(!empty($_['document_temporary'])){
|
|
|
+ $files = json_decode($_['document_temporary'],true);
|
|
|
+
|
|
|
+ $attachmentFolderRelative = $firstEvent->dir(true);
|
|
|
+ $attachmentFolder = $firstEvent->dir();
|
|
|
+ if(!file_exists($attachmentFolder)) mkdir($attachmentFolder,0755,true);
|
|
|
+
|
|
|
+ foreach($files as $file){
|
|
|
+ $from = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? File::temp().utf8_decode($file['path']) : File::temp().$file['path'];
|
|
|
+ $to = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? utf8_decode($file['name']) : $file['name'];
|
|
|
+ File::move($from, $attachmentFolderRelative.SLASH.$to);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $item->toArray();
|
|
|
+ $data['comment'] = html_entity_decode($firstEvent->content);
|
|
|
+ $data['url'] = ROOT_URL.'/index.php?module=issue&page=sheet.report&id='.$data['id'];
|
|
|
+
|
|
|
+ if(!empty($conf->get('issue_report_mails'))){
|
|
|
+
|
|
|
+
|
|
|
+ $path = __DIR__.SLASH.'mail.template.php';
|
|
|
+ if(!file_exists($path)) return;
|
|
|
+ $stream = file_get_contents($path);
|
|
|
+
|
|
|
+ $recipients = array();
|
|
|
+ foreach (explode(',', $conf->get('issue_report_mails')) as $recipient) {
|
|
|
+ if(is_numeric($recipient)){
|
|
|
+ foreach(UserFirmRank::loadAll(array('rank'=>$recipient)) as $ufr)
|
|
|
+ $recipients[] = $ufr->user;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $recipients[] = $recipient;
|
|
|
+ }
|
|
|
+ // Émission d'une notification pour les devs
|
|
|
+ Plugin::callHook("emit_notification", array(array(
|
|
|
+ 'label' => '['.PROGRAM_NAME.' - '.PROGRAM_UID.'] Ticket #'.$item->id.' ouvert',
|
|
|
+ 'html' => template($stream,$data),
|
|
|
+ 'type' => "issue",
|
|
|
+ 'meta' => array('link' => $data['url']),
|
|
|
+ 'recipients' => $recipients
|
|
|
+ )));
|
|
|
+ }
|
|
|
+
|
|
|
+ // Émission d'une notification pour l'auteur du ticket
|
|
|
+ Plugin::callHook("emit_notification", array(array(
|
|
|
+ 'label' => "Votre Ticket #".$item->id." a été envoyé",
|
|
|
+ 'html' => "Le ticket <a href='".ROOT_URL."/index.php?module=issue&page=sheet.report&id=".$item->id."'>#".$item->id."</a> a été créé et sera pris en compte par nos techniciens, vous pouvez consulter
|
|
|
+ son avancement en <a href='".ROOT_URL."/index.php?module=issue&page=sheet.report&id=".$item->id."'>cliquant ici</a>",
|
|
|
+ 'type' => "notice",
|
|
|
+ 'meta' => array('link' => $data['url']),
|
|
|
+ 'recipients' => array($item->creator)
|
|
|
+ )));
|
|
|
+
|
|
|
+ Log::put('Déclaration d\'un rapport d\'erreur #'.$item->toText(), 'Issue');
|
|
|
+ });
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'issue_screenshot_download':
|
|
|
+ global $myUser,$_;
|
|
|
+ if(!$myUser->connected()) throw new Exception("Vous devez être connecté",401);
|
|
|
+ try {
|
|
|
+ require_once(__DIR__.SLASH.'IssueEvent.class.php');
|
|
|
+ $event = IssueEvent::getById($_['id']);
|
|
|
+ File::downloadFile($event->dir().SLASH.'screenshot.jpg');
|
|
|
+ } catch(Exception $e) {
|
|
|
+ File::downloadFile(__ROOT__.'img/default-image.png');
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ //Suppression d'élement issuereport
|
|
|
+ case 'issue_issuereport_delete':
|
|
|
+ Action::write(function(&$response){
|
|
|
+ global $myUser,$_;
|
|
|
+ User::check_access('issue','configure');
|
|
|
+ require_once(__DIR__.SLASH.'IssueReport.class.php');
|
|
|
+ require_once(__DIR__.SLASH.'IssueEvent.class.php');
|
|
|
+
|
|
|
+ $issue = IssueReport::provide();
|
|
|
+ $issue->remove();
|
|
|
+
|
|
|
+ });
|
|
|
+ break;
|
|
|
+
|
|
|
+ //Sauvegarde des configurations de issue
|
|
|
+ case 'issue_setting_save':
|
|
|
+ Action::write(function(&$response){
|
|
|
+ global $myUser,$_,$conf;
|
|
|
+ User::check_access('issue','configure');
|
|
|
+ foreach(Configuration::setting('issue') as $key=>$value){
|
|
|
+ if(!is_array($value)) continue;
|
|
|
+ $allowed[] = $key;
|
|
|
+ }
|
|
|
+ foreach ($_['fields'] as $key => $value)
|
|
|
+ if(in_array($key, $allowed)) $conf->put($key,$value);
|
|
|
+ });
|
|
|
+ break;
|
|
|
+
|
|
|
+
|
|
|
+ /** EVENT **/
|
|
|
+ //Récuperation d'une liste de issueevent
|
|
|
+ case 'issue_issue_event_search':
|
|
|
+ Action::write(function(&$response){
|
|
|
+ global $myUser,$_;
|
|
|
+ User::check_access('issue','read');
|
|
|
+ require_once(__DIR__.SLASH.'IssueEvent.class.php');
|
|
|
+ require_once(__DIR__.SLASH.'IssueReport.class.php');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $events = IssueEvent::loadAll(array('issue'=>$_['issue']),array('id ASC'));
|
|
|
+
|
|
|
+ foreach($events as $i=>$event){
|
|
|
+
|
|
|
+ $row = $event->toArray();
|
|
|
+ $creator = User::byLogin($event->creator);
|
|
|
+ $row['creator'] = $creator->toArray();
|
|
|
+ $row['avatar'] = $creator->getAvatar();
|
|
|
+ $row['fullName'] = $creator->fullName();
|
|
|
+ $row['createdRelative'] = relative_time($event->created);
|
|
|
+
|
|
|
+ switch($event->type){
|
|
|
+ case 'comment':
|
|
|
+
|
|
|
+ $row['classes'] = $i == 0 ? 'issue-first-comment' : '';
|
|
|
+ $row['files'] = array();
|
|
|
+ foreach (glob($event->dir().SLASH.'*') as $key => $value){
|
|
|
+ $file = array();
|
|
|
+ $file['extension'] = getExt($value);
|
|
|
+ $file['label'] = mt_basename($value);
|
|
|
+ $file['labelExcerpt'] = truncate($file['label'],35);
|
|
|
+ $file['type'] = in_array($file['extension'], array('jpg','png','jpeg','bmp','gif','svg')) ? 'image' : 'file';
|
|
|
+ $file['url'] = 'action.php?action=issue_download_document&event='.$event->id.'&path='.base64_encode(basename($value));
|
|
|
+ $file['icon'] = getExtIcon($file['extension']);
|
|
|
+ $row['files'][] = $file;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($creator->login == $myUser->login || $myUser->can('issue','configure')) $row['classes'] .=' editable';
|
|
|
+ $row['comment'] = empty($event->content) ? 'Pas de commentaires': html_entity_decode($event->content);
|
|
|
+ $row['hasfiles'] = count($row['files']) > 0 ? true : false;
|
|
|
+
|
|
|
+ break;
|
|
|
+ case IssueEvent::TYPE_STATE:
|
|
|
+ $infos = json_decode($row['content'],true);
|
|
|
+ $row['oldstate'] = IssueReport::states($infos['old']);
|
|
|
+ $row['state'] = IssueReport::states($infos['new']);
|
|
|
+ break;
|
|
|
+ case IssueEvent::TYPE_TAG:
|
|
|
+ $infos = json_decode($row['content'],true);
|
|
|
+
|
|
|
+ $row['action'] = $infos['action'] == 'added' ? 'ajouté' :'supprimé';
|
|
|
+ $row['tag'] = $infos['tag'];
|
|
|
+ break;
|
|
|
+ case IssueEvent::TYPE_ASSIGNATION:
|
|
|
+ $infos = json_decode($row['content'],true);
|
|
|
+ $assigned = User::byLogin($infos['assigned']);
|
|
|
+ $row['assigned'] = array(
|
|
|
+ 'fullName' => $assigned->fullName(),
|
|
|
+ 'avatar' => $assigned->getAvatar()
|
|
|
+ );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $response['rows'][] = $row;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+ break;
|
|
|
+
|
|
|
+ //Ajout ou modification d'élément issueevent
|
|
|
+ case 'issue_issue_event_save':
|
|
|
+ Action::write(function(&$response){
|
|
|
+ global $myUser,$_;
|
|
|
+ User::check_access('issue','edit');
|
|
|
+ require_once(__DIR__.SLASH.'IssueEvent.class.php');
|
|
|
+ $item = IssueEvent::provide();
|
|
|
+ $item->type = IssueEvent::TYPE_COMMENT;
|
|
|
+ $item->content = $_['content'];
|
|
|
+ $item->issue = $_['issue'];
|
|
|
+ $item->save();
|
|
|
+ });
|
|
|
+ break;
|
|
|
+
|
|
|
+ //Récuperation ou edition d'élément issueevent
|
|
|
+ case 'issue_issue_event_edit':
|
|
|
+ Action::write(function(&$response){
|
|
|
+ global $myUser,$_;
|
|
|
+ User::check_access('issue','edit');
|
|
|
+ require_once(__DIR__.SLASH.'IssueEvent.class.php');
|
|
|
+ require_once(__DIR__.SLASH.'IssueReport.class.php');
|
|
|
+ $response = IssueEvent::getById($_['id'],1);
|
|
|
+ });
|
|
|
+ break;
|
|
|
+
|
|
|
+ //Suppression d'élement issueevent
|
|
|
+ case 'issue_issue_event_delete':
|
|
|
+ Action::write(function(&$response){
|
|
|
+ global $myUser,$_;
|
|
|
+ User::check_access('issue','delete');
|
|
|
+ require_once(__DIR__.SLASH.'IssueReport.class.php');
|
|
|
+ require_once(__DIR__.SLASH.'IssueEvent.class.php');
|
|
|
+
|
|
|
+ $event = IssueEvent::getById($_['id'],1);
|
|
|
+ $issue = $event->join('issue');
|
|
|
+
|
|
|
+ if($issue->creator != $myUser->login && !$myUser->can('issue','configure')) throw new Exception("Permission refusée");
|
|
|
+
|
|
|
+
|
|
|
+ $event->remove();
|
|
|
+
|
|
|
+ if(IssueEvent::rowCount(array('issue'=>$issue->id)) == 0){
|
|
|
+ $issue->remove(false);
|
|
|
+ $response['redirect'] = 'setting.php?section=global.report';
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+ break;
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+?>
|