-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathcloneandlink_ticket.js.php
More file actions
97 lines (81 loc) · 3.17 KB
/
cloneandlink_ticket.js.php
File metadata and controls
97 lines (81 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* -------------------------------------------------------------------------
* Escalade plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Escalade.
*
* Escalade is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Escalade is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Escalade. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2015-2023 by Escalade plugin team.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/escalade
* -------------------------------------------------------------------------
*/
//change mimetype
header("Content-type: application/javascript");
//not executed in self-service interface & right verification
if (
$_SESSION['glpiactiveprofile']['interface'] == "central"
&& Session::haveRight("ticket", CREATE)
&& Session::haveRight("ticket", UPDATE)
) {
$locale_cloneandlink = __s("Clone and link", "escalade");
$locale_linkedtickets = _sn('Linked ticket', 'Linked tickets', 2);
$JS = <<<JAVASCRIPT
var plugin_url = CFG_GLPI.root_doc + '/plugins/escalade';
addCloneLink = function() {
//only in edit form
if (getUrlParameter('id') == undefined) {
return;
}
//delay the execution (ajax requestcomplete event fired before dom loading)
setTimeout( function () {
if ($("#cloneandlink_ticket").length > 0) { return; }
var duplicate_html = "<button id='cloneandlink_ticket' class='btn btn-sm btn-ghost-secondary ms-auto'" +
"title='{$locale_cloneandlink}'><i class='ti ti-copy me-1'></i>" + '{$locale_cloneandlink}' +
"</button>";
$("#linked_tickets-heading .accordion-button")
.append(duplicate_html);
addOnclick();
}, 100);
}
addOnclick = function() {
//onclick event on new buttons
$('#cloneandlink_ticket').on('click', function() {
var tickets_id = getUrlParameter('id');
$.ajax({
url: plugin_url+'/ajax/cloneandlink_ticket.php',
data: { 'tickets_id': tickets_id },
success: function(response, opts) {
var res = JSON.parse(response);
if (res.success == false) {
return false;
}
var url_newticket = 'ticket.form.php?id='+res.newID;
//change to on new ticket created
window.location.href = url_newticket;
}
});
});
}
$(document).on('glpi.tab.loaded', function() {
addCloneLink();
});
JAVASCRIPT;
echo $JS;
}