forked from pluginsGLPI/pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtickettask.class.php
More file actions
171 lines (149 loc) · 6.34 KB
/
tickettask.class.php
File metadata and controls
171 lines (149 loc) · 6.34 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/**
* -------------------------------------------------------------------------
* LICENSE
*
* This file is part of PDF plugin for GLPI.
*
* PDF is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PDF 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Reports. If not, see <http://www.gnu.org/licenses/>.
*
* @author Nelly Mahu-Lasson, Remi Collet, Teclib
* @copyright Copyright (c) 2009-2022 PDF plugin team
* @license AGPL License 3.0 or (at your option) any later version
* @link https://github.com/pluginsGLPI/pdf/
* @link http://www.glpi-project.org/
* @package pdf
* @since 2009
* http://www.gnu.org/licenses/agpl-3.0-standalone.html
* --------------------------------------------------------------------------
*/
class PluginPdfTicketTask extends PluginPdfCommon
{
public static $rightname = 'plugin_pdf';
public function __construct(CommonGLPI $obj = null)
{
$this->obj = ($obj ? $obj : new TicketTask());
}
public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $job, $private)
{
global $DB;
$dbu = new DbUtils();
$ID = $job->getField('id');
//////////////Tasks///////////
$query = ['FROM' => 'glpi_tickettasks',
'WHERE' => ['tickets_id' => $ID],
'ORDER' => 'date DESC'];
if (!$private) {
// Don't show private'
$query['WHERE']['is_private'] = 0;
} elseif (!Session::haveRight('task', TicketTask::SEEPRIVATE)) {
// No right, only show connected user private one
$query['WHERE']['OR'] = ['is_private' => 0,
'users_id' => Session::getLoginUserID(),
'users_id_tech' => Session::getLoginUserID()];
}
$result = $DB->request($query);
$number = count($result);
$pdf->setColumnsSize(100);
$title = '<b>' . TicketTask::getTypeName($number) . '</b>';
if (!$number) {
$pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display')));
} else {
if ($number > $_SESSION['glpilist_limit']) {
$title = sprintf(__('%1$s (%2$s)'), $title, $_SESSION['glpilist_limit'] . '/' . $number);
} else {
$title = sprintf(__('%1$s: %2$s'), $title, $number);
}
$pdf->displayTitle($title);
$pdf->setColumnsSize(20, 20, 20, 20, 20);
$pdf->displayTitle(
'<i>' . __('Type'),
__('Date'),
__('Duration'),
__('Writer'),
__('Planning') . '</i>',
);
foreach ($result as $data) {
$actiontime = Html::timestampToString($data['actiontime'], false);
$planification = '';
if (isset($data['state'])) {
$planification = sprintf(
__('%1$s: %2$s'),
_x('item', 'State'),
Planning::getState($data['state']),
);
}
if (!empty($data['begin'])) {
$planification .= '<br>' . sprintf(
__('%1$s: %2$s'),
__('Begin'),
Html::convDateTime($data['begin']),
);
$planification .= '<br>' . sprintf(
__('%1$s: %2$s'),
__('End'),
Html::convDateTime($data['end']),
);
}
if ($data['users_id_tech'] > 0) {
$planification .= '<br>' . sprintf(
__('%1$s: %2$s'),
__('By user', 'pdf'),
$dbu->getUserName($data['users_id_tech']),
);
}
if ($data['groups_id_tech'] > 0) {
$planification .= '<br>' . sprintf(
__('%1$s: %2$s'),
__('By group', 'pdf'),
Dropdown::getDropdownName(
'glpi_groups',
$data['groups_id_tech'],
),
);
}
if ($data['taskcategories_id']) {
$lib = Dropdown::getDropdownName('glpi_taskcategories', $data['taskcategories_id']);
} else {
$lib = '';
}
if ($data['is_private']) {
$lib = sprintf(__('%1$s (%2$s)'), $lib, __('Private'));
}
$pdf->displayLine(
'</b>' . Toolbox::stripTags($lib),
Html::convDateTime($data['date']),
Html::timestampToString($data['actiontime'], 0),
Toolbox::stripTags($dbu->getUserName($data['users_id'])),
$planification,
);
$content = Glpi\Toolbox\Sanitizer::unsanitize(Html::entity_decode_deep($data['content']));
$content = preg_replace('#data:image/[^;]+;base64,#', '@', $content);
preg_match_all('/<img [^>]*src=[\'"]([^\'"]*docid=([0-9]*))[^>]*>/', $content, $res, PREG_SET_ORDER);
foreach ($res as $img) {
$docimg = new Document();
$docimg->getFromDB($img[2]);
$path = '<img src="file://' . GLPI_DOC_DIR . '/' . $docimg->fields['filepath'] . '"/>';
$content = str_replace($img[0], $path, $content);
}
$pdf->displayText(
"<b><i>" . sprintf(__('%1$s: %2$s') . "</i></b>", __('Description'), ''),
$content,
1,
);
}
}
$pdf->displaySpace();
}
}