forked from mateusznitka/protocolsmanager
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhook.php
197 lines (155 loc) · 5.7 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
<?php
function plugin_protocolsmanager_install() {
global $DB;
$version = plugin_version_protocolsmanager();
$migration = new Migration($version['version']);
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());
}
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)";
$query4 = "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 2',
'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());
$DB->queryOrDie($query4, $DB->error());
}
/**
* UPDATES CONFIG TABLE FOR SCALABILITY
*/
//update config table if upgrading before 1.5.0
if (!$DB->FieldExists('glpi_plugin_protocolsmanager_config', 'author_name')) {
$query = "ALTER TABLE glpi_plugin_protocolsmanager_config
ADD author_name varchar(255)
AFTER email_template";
$DB->queryOrDie($query, $DB->error());
}
if (!$DB->FieldExists('glpi_plugin_protocolsmanager_config', 'author_state')) {
$query = "ALTER TABLE glpi_plugin_protocolsmanager_config
ADD author_state int(2)
AFTER author_name";
$DB->queryOrDie($query, $DB->error());
}
//update config table if upgrading before 1.5.2
if (!$DB->FieldExists('glpi_plugin_protocolsmanager_config', 'title')) {
$query = "ALTER TABLE glpi_plugin_protocolsmanager_config
ADD title varchar(255)
AFTER name";
$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");
foreach($tables as $table)
{$DB->query("DROP TABLE IF EXISTS `$table`;");}
return true;
}
?>