Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 9db7728

Browse files
committed
manage escalation to mantisBT with Glpi problem
1 parent ab890a1 commit 9db7728

7 files changed

Lines changed: 424 additions & 407 deletions

File tree

ajax/ajax.php

Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -108,46 +108,30 @@
108108
case 'getTicketAttachment':
109109

110110
$id_ticket = $_POST['idTicket'];
111+
$itemType = $_POST['itemType'];
111112

112-
$conf = new PluginMantisConfig();
113-
$conf->getFromDB(1);
114-
115-
$ticket = new Ticket();
113+
$ticket = new $itemType();
116114
$ticket->getFromDB($id_ticket);
117115

118-
if($conf->fields['doc_categorie'] == 0){
119-
$where = " tickets_id =".$id_ticket;
120-
}else{
121-
$where = " tickets_id =".$id_ticket." and documentcategories_id = ".$conf->fields['doc_categorie'];
122-
}
123-
124-
$output .= getOutPutForticket($ticket,$where);
125-
126-
127-
$tickets = Ticket_Ticket::getLinkedTicketsTo($id_ticket);
128-
129-
if(count($tickets)){
130-
$output .= "<br/><DL><DT><STRONG>".__('If you fowllow linked tickets','mantis')."</STRONG><br>";
131-
foreach ($tickets as $link_ticket){
116+
$output .= getOutPutForticket($ticket,$itemType);
132117

133-
$ticketLink = new Ticket();
134-
$ticketLink->getFromDB($link_ticket['tickets_id']);
118+
if($itemType != 'Problem'){
119+
$tickets = Ticket_Ticket::getLinkedTicketsTo($id_ticket);
135120

136-
if($conf->fields['doc_categorie'] == 0){
137-
$where = " tickets_id =".$link_ticket['tickets_id'];
138-
}else{
139-
$where = " tickets_id =".$link_ticket['tickets_id']." and documentcategories_id = ".$conf->fields['doc_categorie'];
140-
}
141-
142-
$output .= getOutPutForticket($ticketLink,$where);
143-
144-
}
145-
}else{
146-
$output .= "<DL><DT><STRONG>".__('No tickets linked','mantis');
147-
}
121+
if(count($tickets)){
122+
$output .= "<br/><DL><DT><STRONG>".__('If you fowllow linked tickets','mantis')."</STRONG><br>";
123+
foreach ($tickets as $link_ticket){
124+
$ticketLink = new Ticket();
125+
$ticketLink->getFromDB($link_ticket['tickets_id']);
126+
$output .= getOutPutForticket($ticketLink,$itemType);
127+
}
128+
}else{
129+
$output .= "<DL><DT><STRONG>".__('No tickets linked','mantis');
130+
}
131+
}
148132

149133
if($output == ""){
150-
echo __('No documents attached','mantis');
134+
echo "<STRONG>".__('No documents attached','mantis')."<STRONG/>";
151135
}else{
152136
echo $output;
153137
}
@@ -174,8 +158,9 @@
174158

175159
case 'getProjectName':
176160

177-
$id_ticket = $_POST['idTicket'];
161+
$idItem = $_POST['idTicket'];
178162
$id_mantis_issue = $_POST['idMantis'];
163+
$itemType = $_POST['itemType'];
179164

180165
$ws = new PluginMantisMantisws();
181166
$ws->initializeConnection();
@@ -184,12 +169,10 @@
184169
echo "ERROR :". __("MantisBT issue does not exist","mantis");
185170
} else {
186171

187-
188-
189172
$mantis = new PluginMantisMantis();
190173
//on verifie si un lien est deja creé
191-
if ($mantis->IfExistLink($id_ticket, $id_mantis_issue)) {
192-
echo "ERROR :". __("This Glpi ticket is already linked to this MantisBT ticket","mantis");
174+
if ($mantis->IfExistLink($idItem, $id_mantis_issue,$itemType)) {
175+
echo "ERROR :". __("This Glpi ".$itemType." is already linked to this MantisBT ticket","mantis");
193176
} else {
194177

195178
$result = $ws->getIssueById($id_mantis_issue);
@@ -200,9 +183,6 @@
200183

201184
break;
202185

203-
204-
205-
206186
case 'getCustomFieldByProjectname':
207187

208188
$ws = new PluginMantisMantisws();
@@ -215,7 +195,8 @@
215195
case 'LinkIssueGlpiToIssueMantis':
216196

217197
$id_ticket = $_POST['idTicket'];
218-
$id_mantis_issue = $_POST['idMantis'];
198+
$id_mantis_issue = $_POST['idMantis'];
199+
$itemType = $_POST['itemType'];
219200
$ws = new PluginMantisMantisws();
220201
$ws->initializeConnection();
221202

@@ -225,8 +206,8 @@
225206
} else {
226207
$mantis = new PluginMantisMantis();
227208
//on verifie si un lien est deja creé
228-
if ($mantis->IfExistLink($id_ticket, $id_mantis_issue)) {
229-
echo __("This Glpi ticket is already linked to this MantisBT ticket","mantis");
209+
if ($mantis->IfExistLink($id_ticket, $id_mantis_issue,$itemType)) {
210+
echo __("This Glpi ".$itemType." is already linked to this MantisBT ticket","mantis");
230211
} else {
231212

232213
$issue = new PluginMantisIssue();
@@ -254,6 +235,7 @@
254235
$post['idTicket'] = $t->fields['id'];
255236
$post['idMantis'] = $id_mantis_issue;
256237
$post['dateEscalade'] = $_POST['dateEscalade'];
238+
$post['itemType'] = $_POST['itemType'];
257239
$post['user'] = $_POST['user'];
258240

259241
$id_mantis[] = $mantis1->add($post);
@@ -329,17 +311,31 @@
329311
}
330312

331313

332-
function getOutPutForticket($ticket , $where){
314+
function getOutPutForticket($ticket , $itemType){
333315

316+
global $DB;
317+
$conf = new PluginMantisConfig();
318+
$conf->getFromDB(1);
334319

335-
$doc = new Document();
336-
$docs = $doc->find($where);
337-
$output = "";
338-
if(count($docs)){
320+
if($conf->fields['doc_categorie'] == 0){
321+
$res = $DB->query("SELECT `glpi_documents_items`.*
322+
FROM `glpi_documents_items` WHERE `glpi_documents_items`.`itemtype` = '".$itemType."'
323+
AND `glpi_documents_items`.`items_id` = '" . Toolbox::cleanInteger($ticket->fields['id']) . "'");
324+
}else{
325+
$res = $DB->query("SELECT `glpi_documents_items`.*
326+
FROM `glpi_documents_items` ,`glpi_documents` WHERE `glpi_documents`.`id` =`glpi_documents_items`.`documents_id` and `glpi_documents`.`documentcategories_id` = '".Toolbox::cleanInteger($conf->fields['doc_categorie'])."' and`glpi_documents_items`.`itemtype` = '".$itemType."'
327+
AND `glpi_documents_items`.`items_id` = '" . Toolbox::cleanInteger($ticket->fields['id']) . "'");
328+
}
339329

340-
$output .= "<DL><DT><STRONG>Ticket -> ".$ticket->fields['id']."</STRONG><br>";
341-
foreach($docs as $d){
342-
$output .= "<DD>Document -> ".$d['filename']."<br>";
330+
331+
332+
$output = "";
333+
if ($res->num_rows > 0) {
334+
$output .= "<DL><DT><STRONG>".$itemType." -> ".$ticket->fields['id']."</STRONG><br>";
335+
while ($row = $res->fetch_assoc()) {
336+
$doc = new Document();
337+
$doc->getFromDB($row["documents_id"]);
338+
$output .= "<DD>".$doc->getDownloadLink('',strlen($doc->fields['filename']))."<br>";
343339
}
344340
$output .= "</DL>";
345341
}else{

front/mantis.form.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@
4747
if (isset($_GET['action']) && $_GET['action'] == 'linkToIssue') {
4848

4949
Html::popHeader('Mantis', $_SERVER['PHP_SELF']);
50-
$mantis->getFormForLinkGlpiTicketToMantisTicket($_GET['idTicket']);
50+
$mantis->getFormForLinkGlpiTicketToMantisTicket($_GET['idTicket'],$_GET['itemType']);
5151
Html::popFooter();
5252

5353
} else if (isset($_GET['action']) && $_GET['action'] == 'linkToProject') {
5454

5555
Html::popHeader('Mantis', $_SERVER['PHP_SELF']);
56-
$mantis->getFormForLinkGlpiTicketToMantisProject($_GET['idTicket']);
56+
$mantis->getFormForLinkGlpiTicketToMantisProject($_GET['idTicket'],$_GET['itemType']);
5757
Html::popFooter();
5858

5959
}else if (isset($_GET['action']) && $_GET['action'] == 'deleteIssue'){
@@ -63,6 +63,6 @@
6363
$id_ticket = $_GET['idTicket'];
6464
$id_mantis = $_GET['idMantis'];
6565

66-
$mantis->getFormToDelLinkOrIssue($id_link, $id_ticket, $id_mantis);
66+
$mantis->getFormToDelLinkOrIssue($id_link, $id_ticket, $id_mantis,$_GET['itemType']);
6767
Html::popFooter();
6868
}

hook.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ function plugin_mantis_install() {
6161
dateEscalade date NOT NULL,
6262
user int(11) NOT NULL)";
6363
$DB->query($query) or die($DB->error());
64+
}else{
65+
$mig = new Migration();
66+
$table = 'glpi_plugin_mantis_mantis';
67+
$mig->addField($table, 'itemType', 'string');
68+
$mig->executeMigration();
6469
}
6570

6671

@@ -110,6 +115,8 @@ function plugin_mantis_install() {
110115
$mig->addField($table, 'status_after_escalation', 'integer');
111116
$mig->addField($table, 'show_option_delete', 'integer',array('value' => 0));
112117
$mig->addField($table, 'doc_categorie', 'integer',array('value' => 0));
118+
119+
$mig->addField($table, 'itemType', 'string');
113120
$mig->executeMigration();
114121
}
115122

0 commit comments

Comments
 (0)