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

Commit c414c04

Browse files
committed
change column name for searchOption
1 parent e3e4ec0 commit c414c04

5 files changed

Lines changed: 101 additions & 38 deletions

File tree

ajax/ajax.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@
196196

197197
case 'LinkIssueGlpiToIssueMantis':
198198

199-
$id_ticket = $_POST['idTicket'];
199+
$id_ticket = $_POST['items_id'];
200200
$id_mantis_issue = $_POST['idMantis'];
201-
$itemType = $_POST['itemType'];
201+
$itemType = $_POST['itemtype'];
202202

203203
$ws = new PluginMantisMantisws();
204204
$ws->initializeConnection();
@@ -225,7 +225,7 @@
225225
if($res){
226226
$mantis->add($_POST);
227227

228-
$id_ticket = $_POST['idTicket'];
228+
$id_ticket = $_POST['items_id'];
229229
$ticket = new Ticket();
230230
$ticket->getFromDB($id_ticket);
231231

@@ -241,10 +241,10 @@
241241
$t->getFromDB($link_ticket['tickets_id']);
242242

243243
$mantis1 = new PluginMantisMantis();
244-
$post['idTicket'] = $t->fields['id'];
244+
$post['items_id'] = $t->fields['id'];
245245
$post['idMantis'] = $id_mantis_issue;
246246
$post['dateEscalade'] = $_POST['dateEscalade'];
247-
$post['itemType'] = $_POST['itemType'];
247+
$post['itemtype'] = $_POST['itemType'];
248248
$post['user'] = $_POST['user'];
249249

250250
$id_mantis[] = $mantis1->add($post);
@@ -255,7 +255,7 @@
255255
if($conf->fields['status_after_escalation'] != 0){
256256
$res = $ticket->update(array('id' => $ticket->fields['id'], 'status' =>$conf->fields['status_after_escalation']));
257257

258-
if($_POST['linkedTicket'] == 'true'){
258+
if($_POST['linkedTicket'] == 'true' && $_POST['itemType'] == 'Ticket'){
259259
$tickets = Ticket_Ticket::getLinkedTicketsTo($id_ticket);
260260

261261
foreach ($tickets as $link_ticket){

hook.php

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,24 @@ function plugin_mantis_install() {
5656
if (!TableExists("glpi_plugin_mantis_mantis")) {
5757
$query = "CREATE TABLE glpi_plugin_mantis_mantis (
5858
id int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
59-
idTicket int(11) NOT NULL,
59+
items_id int(11) NOT NULL,
6060
idMantis int(11) NOT NULL,
6161
dateEscalade date NOT NULL,
62-
itemType varchar NOT NULL,
62+
itemtype varchar NOT NULL,
6363
user int(11) NOT NULL)";
6464
$DB->query($query) or die($DB->error());
6565
}else{
6666
$mig = new Migration(200);
6767
$table = 'glpi_plugin_mantis_mantis';
6868
$mig->addField($table, 'itemType', 'string');
6969
$mig->executeMigration();
70+
71+
$mig = new Migration(201);
72+
$table = 'glpi_plugin_mantis_mantis';
73+
$mig->addField($table, 'itemType', 'string');
74+
$mig->changeField('glpi_plugin_mantis_mantis','itemType','itemtype','string' ,array());
75+
$mig->changeField('glpi_plugin_mantis_mantis','idTicket','items_id','integer' ,array());
76+
$mig->executeMigration();
7077
}
7178

7279

@@ -152,3 +159,59 @@ function plugin_mantis_uninstall() {
152159
return true;
153160
}
154161

162+
// Define Additionnal search options for types (other than the plugin ones)
163+
function plugin_mantis_getAddSearchOptions($itemtype) {
164+
165+
$sopt = array();
166+
if ($itemtype == 'Ticket' ) {
167+
168+
$sopt['common'] = "MantisBT";
169+
170+
$sopt[78963]['table'] = 'glpi_plugin_mantis_mantis';
171+
$sopt[78963]['field'] = 'idMantis';
172+
$sopt[78963]['searchtype'] = 'equals';
173+
$sopt[78963]['nosearch'] = true;
174+
$sopt[78963]['datatype'] = 'bool';
175+
$sopt[78963]['name'] = __('ticket linked to mantis','mantis');
176+
$sopt[78963]['joinparams'] = array('jointype' => "itemtype_item");
177+
178+
}else if ( $itemtype == 'Problem'){
179+
$sopt['common'] = "MantisBT";
180+
181+
$sopt[78964]['table'] = 'glpi_plugin_mantis_mantis';
182+
$sopt[78964]['field'] = 'id';
183+
$sopt[78964]['searchtype'] = 'equals';
184+
$sopt[78964]['nosearch'] = true;
185+
$sopt[78964]['datatype'] = 'bool';
186+
$sopt[78964]['name'] = __('problem linked to mantis','mantis');
187+
$sopt[78964]['joinparams'] = array('jointype' => "itemtype_item");
188+
}
189+
return $sopt;
190+
}
191+
192+
193+
194+
195+
196+
function plugin_mantis_giveItem($type,$ID,$data,$num) {
197+
198+
$searchopt = &Search::getOptions($type);
199+
$table = $searchopt[$ID]["table"];
200+
$field = $searchopt[$ID]["field"];
201+
202+
203+
switch ($table.'.'.$field) {
204+
case "glpi_plugin_mantis_mantis.idMantis" :
205+
return Dropdown::getYesNo($data["ITEM_$num"]);
206+
break;
207+
208+
}
209+
210+
return "";
211+
}
212+
213+
214+
215+
216+
217+

inc/issue.class.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function __construct() { }
6969
public function addInfoToIssueMantis($idTicket, $idMantis) {
7070

7171
global $DB;
72-
$itemType = $_POST['itemType'];
72+
$itemType = $_POST['itemtype'];
7373

7474
$ws = new PluginMantisMantisws();
7575
$ws->initializeConnection();
@@ -333,11 +333,11 @@ public function linkisuetoProjectMantis() {
333333
} else {
334334

335335
//creation d'un lien glpi -> mantis
336-
$post['idTicket'] = $idTicket;
336+
$post['items_id'] = $idTicket;
337337
$post['idMantis'] = $idIssueCreate;
338338
$post['dateEscalade'] = $date;
339339
$post['user'] = $idUser;
340-
$post['itemType'] = $itemType;
340+
$post['itemtype'] = $itemType;
341341

342342
$res= $mantis->add($post);
343343
$id_mantis[] = $res;
@@ -361,11 +361,11 @@ public function linkisuetoProjectMantis() {
361361
$t->getFromDB($link_ticket['tickets_id']);
362362

363363
$mantis1 = new PluginMantisMantis();
364-
$post['idTicket'] = $t->fields['id'];
364+
$post['items_id'] = $t->fields['id'];
365365
$post['idMantis'] = $idIssueCreate;
366366
$post['dateEscalade'] = $date;
367367
$post['user'] = $idUser;
368-
$post['itemType'] = $itemType;
368+
$post['itemtype'] = $itemType;
369369

370370
$id_mantis[] = $mantis1->add($post);
371371
unset($post);

inc/mantis.class.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,19 @@ static function updateAttachment(){
106106
//on parcours les items linké
107107
while ($row = $res->fetch_assoc()) {
108108

109-
$itemType = $row['itemType'];
109+
$itemType = $row['itemtype'];
110110

111111
//on créer l'objet Ticket
112112
$item = new $itemType();
113-
$item->getFromDB($row['idTicket']);
113+
$item->getFromDB($row['items_id']);
114114

115115
if($item->fields['status'] == 5 || $item->fields['status'] == 6){
116-
Toolbox::logInFile("mantis", "CRON MANTIS : ".$itemType." ".$itemType." ".$row['idTicket']." is already solve or closed. ");
116+
Toolbox::logInFile("mantis", "CRON MANTIS : ".$itemType." ".$itemType." ".$row['items_id']." is already solve or closed. ");
117117
}else{
118-
Toolbox::logInFile("mantis", "CRON MANTIS : Checking ".$itemType." ticket ".$row['idTicket'].". ");
118+
Toolbox::logInFile("mantis", "CRON MANTIS : Checking ".$itemType." ticket ".$row['items_id'].". ");
119119

120120
//on recupere les lien entre le ticket glpi et les ticket mantis
121-
$list_link = self::getLinkBetweenItemGlpiAndTicketMantis($row['idTicket'],$itemType);
121+
$list_link = self::getLinkBetweenItemGlpiAndTicketMantis($row['items_id'],$itemType);
122122

123123
//pour chaque lien glpi -> mantis
124124
while ($line = $list_link->fetch_assoc()){
@@ -129,7 +129,7 @@ static function updateAttachment(){
129129
$attachmentsMantisBT = $issue->attachments;
130130

131131
//on recupere les document de l'item
132-
$documents = self::getDocumentFromItem($row['idTicket'],$itemType);
132+
$documents = self::getDocumentFromItem($row['items_id'],$itemType);
133133

134134
//pour chaque document
135135
foreach($documents as $doc){
@@ -197,21 +197,21 @@ static function updateTicket() {
197197

198198
while ($row = $res->fetch_assoc()) {
199199

200-
$itemType = $row['itemType'];
200+
$itemType = $row['itemtype'];
201201
$item = new $itemType();
202-
$item->getFromDB($row['idTicket']);
202+
$item->getFromDB($row['items_id']);
203203

204-
Toolbox::logInFile("mantis", "CRON MANTIS : Checking Glpi ".$itemType." ".$row['idTicket'].". ");
204+
Toolbox::logInFile("mantis", "CRON MANTIS : Checking Glpi ".$itemType." ".$row['items_id'].". ");
205205

206206
//si le ticket est deja resolus ou clos
207207
if($item->fields['status'] == 5 || $item->fields['status'] == 6){
208208

209-
Toolbox::logInFile("mantis", "CRON MANTIS : Glpi ".$itemType." ".$row['idTicket']." is already solve or closed. ");
209+
Toolbox::logInFile("mantis", "CRON MANTIS : Glpi ".$itemType." ".$row['items_id']." is already solve or closed. ");
210210

211211
}else{
212212

213213
//on recupere tout les tickets mantis lié
214-
$list_link = self::getLinkBetweenItemGlpiAndTicketMantis($row['idTicket'],$itemType);
214+
$list_link = self::getLinkBetweenItemGlpiAndTicketMantis($row['items_id'],$itemType);
215215

216216
$list_ticket_mantis = array();
217217
while ($line = $list_link->fetch_assoc()){
@@ -230,7 +230,7 @@ static function updateTicket() {
230230
$item->fields['solvedate'] = date("Y-m-d");
231231
$item->fields['solution'] = $info_solved;
232232
$item->update($item->fields);
233-
Toolbox::logInFile("mantis", "CRON MANTIS : Update glpi ".$row['idTicket']." status in BDD");
233+
Toolbox::logInFile("mantis", "CRON MANTIS : Update glpi ".$row['items_id']." status in BDD");
234234

235235
}else{
236236
Toolbox::logInFile("mantis", "CRON MANTIS : All status MantisBT have not the same as status choice by user -> ".$etat_mantis.". ");
@@ -336,9 +336,9 @@ private static function getAllSameStatusChoiceByUser($list_ticket_mantis,$status
336336
*/
337337
private static function getItemWhichIsLinked() {
338338
global $DB;
339-
return $DB->query("SELECT `glpi_plugin_mantis_mantis`.`idTicket`,`glpi_plugin_mantis_mantis`.`itemType`
339+
return $DB->query("SELECT `glpi_plugin_mantis_mantis`.`items_id`,`glpi_plugin_mantis_mantis`.`itemtype`
340340
FROM `glpi_plugin_mantis_mantis`
341-
GROUP BY `glpi_plugin_mantis_mantis`.`idTicket`,`glpi_plugin_mantis_mantis`.`itemType`");
341+
GROUP BY `glpi_plugin_mantis_mantis`.`items_id`,`glpi_plugin_mantis_mantis`.`itemtype`");
342342
}
343343

344344

@@ -352,7 +352,7 @@ private static function getLinkBetweenItemGlpiAndTicketMantis($idItem,$itemType)
352352
global $DB;
353353
return $DB->query("SELECT `glpi_plugin_mantis_mantis`.*
354354
FROM `glpi_plugin_mantis_mantis` WHERE `glpi_plugin_mantis_mantis`
355-
.`idTicket` = '" . Toolbox::cleanInteger($idItem)."' and `glpi_plugin_mantis_mantis`.`itemType` = '".$itemType."'");
355+
.`items_id` = '" . Toolbox::cleanInteger($idItem)."' and `glpi_plugin_mantis_mantis`.`itemtype` = '".$itemType."'");
356356
}
357357

358358

@@ -889,7 +889,7 @@ private function getFormForDisplayInfo($item,$itemType) {
889889

890890
Ajax::createModalWindow('popupToDelete' . $row['id'],
891891
$CFG_GLPI['root_doc'].'/plugins/mantis/front/mantis.form.php?action=deleteIssue&id=' .
892-
$row['id'] . '&idTicket=' . $row['idTicket'] . '&idMantis=' . $row['idMantis'].'&itemType='.$itemType,
892+
$row['id'] . '&idTicket=' . $row['items_id'] . '&idMantis=' . $row['idMantis'].'&itemType='.$itemType,
893893
array('title' => __("Delete", "mantis"),'width' => 550,'height' => $height));
894894

895895
if (!$issue) {
@@ -956,9 +956,9 @@ private function getFormForDisplayInfo($item,$itemType) {
956956
* @return true if succeed else false
957957
*/
958958
public function IfExistLink($idItem, $id_mantis,$itemType) {
959-
return $this->getFromDBByQuery($this->getTable() . " WHERE `" . "`.`idTicket` = '" .
959+
return $this->getFromDBByQuery($this->getTable() . " WHERE `" . "`.`items_id` = '" .
960960
Toolbox::cleanInteger($idItem) . "' AND `" . "`.`idMantis` = '" .
961-
Toolbox::cleanInteger($id_mantis) . "' AND `" . "`.`itemType` = '" .$itemType . "'");
961+
Toolbox::cleanInteger($id_mantis) . "' AND `" . "`.`itemtype` = '" .$itemType . "'");
962962
}
963963

964964
/**
@@ -971,8 +971,8 @@ public function getLinkBetweenGlpiAndMantis($item,$itemType){
971971
global $DB;
972972
return $DB->query("SELECT `glpi_plugin_mantis_mantis`.*
973973
FROM `glpi_plugin_mantis_mantis` WHERE `glpi_plugin_mantis_mantis`
974-
.`idTicket` = '" . Toolbox::cleanInteger($item->getField('id')) . "'
975-
and `glpi_plugin_mantis_mantis`.`itemType` = '".$itemType."' order by `glpi_plugin_mantis_mantis`.`dateEscalade`");
974+
.`items_id` = '" . Toolbox::cleanInteger($item->getField('id')) . "'
975+
and `glpi_plugin_mantis_mantis`.`itemtype` = '".$itemType."' order by `glpi_plugin_mantis_mantis`.`dateEscalade`");
976976
}
977977

978978
/**

scripts/scriptMantis.js.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,15 @@ function linkIssueglpiToIssueMantis() {
283283
type: "POST", // methode de transmission des données au fichier php
284284
url: "{$root_ajax}", // url du fichier php
285285
data: "action=LinkIssueGlpiToIssueMantis&" +
286-
"idTicket=" + idTicket + "&" +
286+
"items_id=" + idTicket + "&" +
287287
"idMantis=" + idMantisIssue + "&" +
288288
"followAttachment=" + followAttachment + "&" +
289289
"followFollow=" + followFollow + "&" +
290290
"followTask=" + followTask + "&" +
291291
"glpiField=" + glpiField + "&" +
292292
"glpiUrl=" + glpiUrl + "&" +
293293
"linkedTicket=" + linkedTicket + "&" +
294-
"itemType=" + itemType + "&" +
294+
"itemtype=" + itemType + "&" +
295295
"followTitle=" + followTitle + "&" +
296296
"followDescription=" + followDescription + "&" +
297297
"followCategorie=" + followCategorie + "&" +
@@ -652,7 +652,7 @@ function deleteLinkGlpiMantis(id, idticket, idMantis, deleteAll) {
652652
data: "action=deleteLinkMantis&" +
653653
"id=" + id + "&" +
654654
"idMantis=" + idMantis + "&" +
655-
"idTicket=" + idticket,// données à transmettre
655+
"items_id=" + idticket,// données à transmettre
656656
success: function (msg) { // si l'appel a bien fonctionné
657657
658658
if (msg == true) {
@@ -698,7 +698,7 @@ function delLinkAndOrIssue(id, idMantis, idTicket) {
698698
data: "action=deleteIssueMantisAndLink&" +
699699
"id=" + id + "&" +
700700
"idMantis=" + idMantis + "&" +
701-
"idTicket=" + idTicket,// données à transmettre
701+
"items_id=" + idTicket,// données à transmettre
702702
success: function (msg) { // si l'appel a bien fonctionné
703703
704704
if (msg == true) {
@@ -729,7 +729,7 @@ function delLinkAndOrIssue(id, idMantis, idTicket) {
729729
data: "action=deleteLinkMantis&" +
730730
"id=" + id + "&" +
731731
"idMantis=" + idMantis + "&" +
732-
"idTicket=" + idTicket,// données à transmettre
732+
"items_id=" + idTicket,// données à transmettre
733733
success: function (msg) { // si l'appel a bien fonctionné
734734
735735
if (msg == true) {

0 commit comments

Comments
 (0)