123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519 |
- <?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;
- }
- ?>
|