forked from mateusznitka/protocolsmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook.php
406 lines (315 loc) · 12.5 KB
/
hook.php
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<?php
function plugin_protocolsmanager_redefine_menus($menu) {
global $DB;
if (empty($menu)) {
return $menu;
}
if(isset($_SESSION['glpiID'])){
$id = $_SESSION['glpiID'];
$query = "SELECT COUNT(id) as field_count FROM `glpi_plugin_protocolsmanager_receipt`
where profile_id = " . $id . " AND confirmed = 0";
$query2 = 'SELECT * FROM `glpi_plugin_protocolsmanager_settings` WHERE id = 1';
$result = $DB->request($query)->current();
$result2 = $DB->request($query2)->current();
if($result['field_count'] > 0 && $result2['protocols_save_on']){
$menu['protocols'] = [
'default' => '/plugins/protocolsmanager/front/protocols.form.php',
'title' => __('Sign protocol','protocolsmanager'),
'content' => [false],
'icon' => 'ti ti-alert-circle'
];
}
}
if($result2['show_own_assets']){
$menu['myAssets'] = [
'default' => '/plugins/protocolsmanager/front/myAssets.form.php',
'title' => __('My assets','protocolsmanager'),
'content' => [false],
'icon' => 'ti ti-alert-circle'
];
}
return $menu;
}
function plugin_protocolsmanager_install() {
global $DB, $CFG_GLPI;
$version = plugin_version_protocolsmanager();
$migration = new Migration($version['version']);
if (!countElementsInTable('glpi_crontasks', ['name' => 'PluginProtocolsmanagerReminder'])) {
Crontask::Register('PluginProtocolsmanagerReminder', 'PluginProtocolsmanagerReminder', DAY_TIMESTAMP, [
'param' => '',
'mode' => CronTask::MODE_EXTERNAL
]);
}
if (!$DB->tableExists("glpi_plugin_protocolsmanager_mails_templates")) {
$query = "CREATE TABLE glpi_plugin_protocolsmanager_mails_templates (
id int(11) NOT NULL auto_increment,
template_name varchar(255),
template_title TEXT,
template_body TEXT,
PRIMARY KEY (id)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->query($query) or die($DB->error());
}
if (!$DB->tableExists("glpi_plugin_protocolsmanager_settings")) {
$query = "CREATE TABLE glpi_plugin_protocolsmanager_settings (
id int(11) NOT NULL auto_increment,
protocols_save_on int(2),
mail_confirm_on int(2),
reminder_on int(2),
first_emial_reminder varchar(255),
second_emial_reminder varchar(255),
how_often_remind int(11),
show_own_assets int(1),
user_fields varchar(255),
PRIMARY KEY (id)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->query($query) or die($DB->error());
$query2 = "INSERT INTO `glpi_plugin_protocolsmanager_settings`(
`id`,
`protocols_save_on`,
`mail_confirm_on`,
`reminder_on`,
`first_emial_reminder`,
`second_emial_reminder`,
`how_often_remind`,
`show_own_assets`,
`user_fields`)
VALUES (1,0,0,0,null,null,0,0,'')";
$DB->queryOrDie($query2, $DB->error());
}
if (!$DB->tableExists("glpi_plugin_protocolsmanager_receipt")) {
$query = "CREATE TABLE glpi_plugin_protocolsmanager_receipt (
id int(11) NOT NULL auto_increment,
profile_id int(11),
confirmed int(11),
protocol_id int(11),
modified datetime,
PRIMARY KEY (id)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->query($query) or die($DB->error());
}
if (!$DB->tableExists("glpi_plugin_protocolsmanager_confirm")) {
$query = "CREATE TABLE glpi_plugin_protocolsmanager_confirm (
id int(11) NOT NULL auto_increment,
id_user int(11),
id_protocol int(11),
code_confirm int(11),
modified datetime,
PRIMARY KEY (id)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->query($query) or die($DB->error());
}
if (!$DB->tableExists("glpi_plugin_protocolsmanager_profiles")) {
$query = "CREATE TABLE glpi_plugin_protocolsmanager_profiles (
id int(11) NOT NULL auto_increment,
profile_id int(11),
plugin_conf char(1) collate utf8_unicode_ci default NULL,
tab_access char(1) collate utf8_unicode_ci default NULL,
make_access char(1) collate utf8_unicode_ci default NULL,
delete_access char(1) collate utf8_unicode_ci default NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->query($query) or die($DB->error());
$id = $_SESSION['glpiactiveprofile']['id'];
$query = "INSERT INTO glpi_plugin_protocolsmanager_profiles (profile_id, plugin_conf, tab_access, make_access, delete_access) VALUES ('$id','w', 'w', 'w', 'w')";
$DB->query($query) or die($DB->error());
}
//update profiles table if updating from 0.8
if (!$DB->FieldExists('glpi_plugin_protocolsmanager_profiles', 'plugin_conf')) {
$query = "DROP TABLE glpi_plugin_protocolsmanager_profiles";
$DB->query($query) or die($DB->error());
$query = "CREATE TABLE glpi_plugin_protocolsmanager_profiles (
id int(11) NOT NULL auto_increment,
profile_id int(11),
plugin_conf char(1) collate utf8_unicode_ci default NULL,
tab_access char(1) collate utf8_unicode_ci default NULL,
make_access char(1) collate utf8_unicode_ci default NULL,
delete_access char(1) collate utf8_unicode_ci default NULL,
my_assets char(1) collate utf8_unicode_ci default NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->query($query) or die($DB->error());
$id = $_SESSION['glpiactiveprofile']['id'];
$query = "INSERT INTO glpi_plugin_protocolsmanager_profiles (profile_id, plugin_conf, tab_access, make_access, delete_access, my_assets) VALUES ('$id','w', 'w', 'w', 'w', 'w')";
$DB->query($query) or die($DB->error());
}
if (!$DB->tableExists('glpi_plugin_protocolsmanager_config')) {
$query = "CREATE TABLE glpi_plugin_protocolsmanager_config (
id INT(11) NOT NULL auto_increment,
name VARCHAR(255),
title varchar(255),
font varchar(255),
fontsize varchar(255),
logo varchar(255),
content text,
footer text,
city varchar(255),
serial_mode int(2),
column1 varchar(255),
column2 varchar(255),
orientation varchar(10),
breakword int(2),
email_mode int(2),
upper_content text,
email_template int(2),
author_name varchar(255),
author_state int(2),
PRIMARY KEY (id)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, $DB->error());
$query2 = "INSERT INTO glpi_plugin_protocolsmanager_config (
name, title, font, fontsize, content, footer, city, serial_mode, orientation, breakword, email_mode, author_name, author_state)
VALUES ('Equipment report',
'Certificate of delivery of {owner}',
'Roboto',
'9',
'User: \n I have read the terms of use of IT equipment in the Example Company.',
'Example Company \n Example Street 21 \n 01-234 Example City',
'Example city',
1,
'Portrait',
1,
2,
'Test Division',
1)";
$DB->queryOrDie($query2, $DB->error());
}
//update config table if upgrading from 1.0
if (!$DB->FieldExists('glpi_plugin_protocolsmanager_config', 'orientation')) {
$query = "ALTER TABLE glpi_plugin_protocolsmanager_config
ADD serial_mode int(2)
AFTER city,
ADD column1 varchar(255)
AFTER serial_mode,
ADD column2 varchar(255)
AFTER column1,
ADD orientation varchar(10)
AFTER column2";
$DB->queryOrDie($query, $DB->error());
}
//update config table if upgrading from 1.1.2
if (!$DB->FieldExists('glpi_plugin_protocolsmanager_config', 'fontsize')) {
$query = "ALTER TABLE glpi_plugin_protocolsmanager_config
ADD fontsize varchar(255)
AFTER font,
ADD breakword int(2)
AFTER fontsize";
$DB->queryOrDie($query, $DB->error());
$query = "UPDATE glpi_plugin_protocolsmanager_config
SET serial_mode=1, orientation='p', fontsize='9', breakword=1";
$DB->queryOrDie($query, $DB->error());
}
//update config table if upgrading from 1.2
if (!$DB->FieldExists('glpi_plugin_protocolsmanager_config', 'email_mode')) {
$query = "ALTER TABLE glpi_plugin_protocolsmanager_config
ADD email_mode int(2)
AFTER breakword,
ADD email_template int(2)
AFTER email_mode";
$DB->queryOrDie($query, $DB->error());
$query = "UPDATE glpi_plugin_protocolsmanager_config
SET email_mode=2";
$DB->queryOrDie($query, $DB->error());
}
//update config table if upgrading from 1.3
if (!$DB->FieldExists('glpi_plugin_protocolsmanager_config', 'upper_content')) {
$query = "ALTER TABLE glpi_plugin_protocolsmanager_config
ADD upper_content text
AFTER email_mode";
$DB->queryOrDie($query, $DB->error());
}
//update email_content field
if ($DB->FieldExists('glpi_plugin_protocolsmanager_emailconfig', 'email_content')) {
$query = "ALTER TABLE glpi_plugin_protocolsmanager_emailconfig MODIFY COLUMN email_content TEXT";
$DB->queryOrDie($query, $DB->error());
}
//add new column glpi_plugin_protocolsmanager_settings
if (($DB->tableExists('glpi_plugin_protocolsmanager_emailconfig')) &&
!$DB->FieldExists('glpi_plugin_protocolsmanager_settings', 'show_own_assets')) {
$query = "ALTER TABLE glpi_plugin_protocolsmanager_settings ADD COLUMN show_own_assets int(1)";
$query2 = "UPDATE glpi_plugin_protocolsmanager_settings SET show_own_assets = 0 WHERE id=1";
$DB->queryOrDie($query, $DB->error());
$DB->queryOrDie($query2, $DB->error());
}
//add another new column glpi_plugin_protocolsmanager_settings user_fields
if (($DB->tableExists('glpi_plugin_protocolsmanager_emailconfig')) &&
!$DB->FieldExists('glpi_plugin_protocolsmanager_settings', 'user_fields')) {
$query = "ALTER TABLE glpi_plugin_protocolsmanager_settings ADD COLUMN user_fields varchar(255)";
$query2 = "UPDATE glpi_plugin_protocolsmanager_settings SET user_fields = '' WHERE id=1";
$DB->queryOrDie($query, $DB->error());
$DB->queryOrDie($query2, $DB->error());
}
//add new column glpi_plugin_protocolsmanager_profiles - my_assets
if (($DB->tableExists('glpi_plugin_protocolsmanager_profiles')) &&
!$DB->FieldExists('glpi_plugin_protocolsmanager_profiles', 'my_assets')) {
$query = "ALTER TABLE glpi_plugin_protocolsmanager_profiles ADD COLUMN my_assets char(1) collate utf8_unicode_ci default NULL";
$DB->queryOrDie($query, $DB->error());
}
//add new column glpi_plugin_protocolsmanager_profiles - sign_protocol_form
if (($DB->tableExists('glpi_plugin_protocolsmanager_profiles')) &&
!$DB->FieldExists('glpi_plugin_protocolsmanager_profiles', 'sign_protocol_form')) {
$query = "ALTER TABLE glpi_plugin_protocolsmanager_profiles ADD COLUMN sign_protocol_form char(1) collate utf8_unicode_ci default NULL";
$DB->queryOrDie($query, $DB->error());
}
if (!$DB->tableExists('glpi_plugin_protocolsmanager_emailconfig')) {
$query = "CREATE TABLE glpi_plugin_protocolsmanager_emailconfig (
id INT(11) NOT NULL auto_increment,
tname varchar(255),
send_user int(2),
email_content text,
email_subject varchar(255),
email_footer varchar(255),
recipients varchar(255),
PRIMARY KEY (id)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, $DB->error());
}
if($DB->tableExists('glpi_plugin_protocolsmanager_emailconfig'))
{
$query3 = "INSERT INTO glpi_plugin_protocolsmanager_emailconfig (
tname, send_user, email_content, email_subject, recipients)
VALUES ('Email default',
2,
'Testmail',
'Testmail',
'Testmail')";
$DB->queryOrDie($query3, $DB->error());
}
if (!$DB->tableExists('glpi_plugin_protocolsmanager_protocols')) {
$query = "CREATE TABLE glpi_plugin_protocolsmanager_protocols (
id INT(11) NOT NULL auto_increment,
name VARCHAR(255),
user_id int(11),
gen_date datetime,
author varchar(255),
document_id int(11),
document_type varchar(255),
PRIMARY KEY (id)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, $DB->error());
}
if ($DB->tableExists('glpi_plugin_protocolsmanager_config')) {
return true;
}
if ($DB->tableExists('glpi_plugin_protocolsmanager_protocols')) {
return true;
}
//execute the whole migration
$migration->executeMigration();
return true;
}
function plugin_protocolsmanager_uninstall() {
global $DB;
$tables = array("glpi_plugin_protocolsmanager_protocols",
"glpi_plugin_protocolsmanager_config",
"glpi_plugin_protocolsmanager_profiles",
"glpi_plugin_protocolsmanager_emailconfig",
"glpi_plugin_protocolsmanager_receipt",
"glpi_plugin_protocolsmanager_settings",
"glpi_plugin_protocolsmanager_confirm"
);
foreach($tables as $table)
{$DB->query("DROP TABLE IF EXISTS `$table`;");}
return true;
}
?>