Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-glpi-git / install / update_0681_07.php @ b67d8923

Historique | Voir | Annoter | Télécharger (70,6 ko)

1
<?php
2

    
3

    
4
/*
5
 * @version $Id: update_0681_07.php 7763 2009-01-06 18:44:50Z moyo $
6
 -------------------------------------------------------------------------
7
 GLPI - Gestionnaire Libre de Parc Informatique
8
 Copyright (C) 2003-2009 by the INDEPNET Development Team.
9

10
 http://indepnet.net/   http://glpi-project.org
11
 -------------------------------------------------------------------------
12

13
 LICENSE
14

15
 This file is part of GLPI.
16

17
 GLPI is free software; you can redistribute it and/or modify
18
 it under the terms of the GNU General Public License as published by
19
 the Free Software Foundation; either version 2 of the License, or
20
 (at your option) any later version.
21

22
 GLPI is distributed in the hope that it will be useful,
23
 but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 GNU General Public License for more details.
26

27
 You should have received a copy of the GNU General Public License
28
 along with GLPI; if not, write to the Free Software
29
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30
 --------------------------------------------------------------------------
31
 */
32

    
33
// ----------------------------------------------------------------------
34
// Original Author of file:
35
// Purpose of file:
36
// ----------------------------------------------------------------------
37

    
38
/// Update from 0.68.1 to 0.7
39
function update0681to07() {
40
        global $DB, $CFG_GLPI, $LANG, $LINK_ID_TABLE;
41

    
42
        @mysql_query("SET NAMES 'latin1'",$DB->dbh);
43

    
44
        // Improve user table :
45
        if (!isIndex("glpi_users", "firstname")) {
46
                $query = "ALTER TABLE `glpi_users` ADD INDEX ( `firstname` )";
47
                $DB->query($query) or die("0.7 alter users add index on firstname " . $LANG["update"][90] . $DB->error());
48
        }
49
        if (!isIndex("glpi_users", "realname")) {
50
                $query = "ALTER TABLE `glpi_users` ADD INDEX ( `realname` )";
51
                $DB->query($query) or die("0.7 alter users add index on realname " . $LANG["update"][90] . $DB->error());
52
        }
53
        // Decimal problem
54
        if (FieldExists("glpi_infocoms", "value")) {
55
                $query = "ALTER TABLE `glpi_infocoms` CHANGE `value` `value` DECIMAL( 20, 4 ) NOT NULL DEFAULT '0';";
56
                $DB->query($query) or die("0.7 alter value in glpi_infocoms " . $LANG["update"][90] . $DB->error());
57
        }
58
        if (FieldExists("glpi_infocoms", "warranty_value")) {
59
                $query = "ALTER TABLE `glpi_infocoms` CHANGE warranty_value warranty_value DECIMAL( 20, 4 ) NOT NULL DEFAULT '0';";
60
                $DB->query($query) or die("0.7 alter warranty_value in glpi_infocoms " . $LANG["update"][90] . $DB->error());
61
        }
62
        if (FieldExists("glpi_tracking", "cost_time")) {
63
                $query = "ALTER TABLE `glpi_tracking` CHANGE cost_time cost_time DECIMAL( 20, 4 ) NOT NULL DEFAULT '0';";
64
                $DB->query($query) or die("0.7 alter cost_time in glpi_tracking " . $LANG["update"][90] . $DB->error());
65
        }
66
        if (FieldExists("glpi_tracking", "cost_fixed")) {
67
                $query = "ALTER TABLE `glpi_tracking` CHANGE cost_fixed cost_fixed DECIMAL( 20, 4 ) NOT NULL DEFAULT '0';";
68
                $DB->query($query) or die("0.7 alter cost_fixed in glpi_tracking " . $LANG["update"][90] . $DB->error());
69
        }
70
        if (FieldExists("glpi_tracking", "cost_material")) {
71
                $query = "ALTER TABLE `glpi_tracking` CHANGE cost_material cost_material DECIMAL( 20, 4 ) NOT NULL DEFAULT '0';";
72
                $DB->query($query) or die("0.7 alter cost_material in glpi_tracking " . $LANG["update"][90] . $DB->error());
73
        }
74
        if (!FieldExists("glpi_config", "decimal_number")) {
75
                $query = "ALTER TABLE `glpi_config` ADD `decimal_number` INT DEFAULT '2';";
76
                $DB->query($query) or die("0.7 add decimal_number in glpi_config " . $LANG["update"][90] . $DB->error());
77
        }
78
        $CFG_GLPI["decimal_number"] = 2;
79

    
80
        if (!FieldExists("glpi_config", "cas_logout")) {
81
                $query = "ALTER TABLE `glpi_config` ADD `cas_logout` VARCHAR( 255 ) NULL AFTER `cas_uri`;";
82
                $DB->query($query) or die("0.7 add cas_logout in glpi_config " . $LANG["update"][90] . $DB->error());
83
        }
84

    
85
        if (!isIndex("glpi_computer_device", "specificity")) {
86
                $query = "ALTER TABLE `glpi_computer_device` ADD INDEX ( `specificity` )";
87
                $DB->query($query) or die("0.7 add index specificity in glpi_computer_device " . $LANG["update"][90] . $DB->error());
88
        }
89

    
90
        if (!FieldExists("glpi_docs", "comments")) {
91
                $query = "ALTER TABLE `glpi_docs` CHANGE `comment` `comments` TEXT DEFAULT NULL ";
92
                $DB->query($query) or die("0.7 alter docs.comment to be comments" . $LANG["update"][90] . $DB->error());
93

    
94
        }
95
        // Update polish langage file
96
        $query = "UPDATE glpi_users SET language='pl_PL' WHERE language='po_PO'";
97
        $DB->query($query) or die("0.7 update polish lang file " . $LANG["update"][90] . $DB->error());
98

    
99
        // Add show_group_hardware
100
        if (!FieldExists("glpi_profiles", "show_group_hardware")) {
101
                $query = "ALTER TABLE `glpi_profiles` ADD `show_group_hardware` CHAR( 1 ) NULL DEFAULT '0';";
102
                $DB->query($query) or die("0.7 alter glpi_profiles add show_group_hardware" . $LANG["update"][90] . $DB->error());
103
                $query = "UPDATE glpi_profiles SET `show_group_hardware`=`show_group_ticket`";
104
                $DB->query($query) or die("0.7 alter glpi_profiles add show_group_hardware" . $LANG["update"][90] . $DB->error());
105
        }
106

    
107
        // Clean doc association
108
        if (FieldExists("glpi_doc_device", "is_template")) {
109
                $query = "ALTER TABLE `glpi_doc_device` DROP `is_template`";
110
                $DB->query($query) or die("0.7 delete is_template from glpi_doc_device" . $LANG["update"][90] . $DB->error());
111
        }
112

    
113
        // Clean contract association
114
        if (FieldExists("glpi_contract_device", "is_template")) {
115
                $query = "ALTER TABLE `glpi_contract_device` DROP `is_template`";
116
                $DB->query($query) or die("0.7 delete is_template from glpi_contract_device" . $LANG["update"][90] . $DB->error());
117
        }
118
         
119

    
120

    
121
        //// ENTITY MANAGEMENT
122

    
123
        if (!TableExists("glpi_entities")) {
124
                $query = "CREATE TABLE `glpi_entities` (
125
                                        `ID` int(11) NOT NULL auto_increment,
126
                                        `name` varchar(255) NOT NULL,
127
                                        `parentID` int(11) NOT NULL default '0',
128
                                        `completename` text NOT NULL,
129
                                        `comments` text,
130
                                        `level` int(11) default NULL,
131
                                        PRIMARY KEY  (`ID`),
132
                                        UNIQUE KEY `name` (`name`,`parentID`),
133
                                        KEY `parentID` (`parentID`)
134
                        ) ENGINE=MyISAM;";
135
                $DB->query($query) or die("0.7 create glpi_entities " . $LANG["update"][90] . $DB->error());
136
        }
137

    
138
        if (!TableExists("glpi_entities_data")) {
139
                $query = "CREATE TABLE `glpi_entities_data` (
140
                                                                                `ID` int(11) NOT NULL auto_increment,
141
                                                                                `FK_entities` int(11) NOT NULL default '0',
142
                                                                                `address` text,
143
                                                                                `postcode` varchar(255) default NULL,
144
                                                                                `town` varchar(255) default NULL,
145
                                                                                `state` varchar(255) default NULL,
146
                                                                                `country` varchar(255) default NULL,
147
                                                                                `website` varchar(200) default NULL,
148
                                                                                `phonenumber` varchar(200) default NULL,
149
                                                                                `fax` varchar(255) default NULL,
150
                                                                                `email` varchar(255) default NULL,
151
                                                                                `notes` longtext,
152
                                                                                PRIMARY KEY  (`ID`),
153
                                                                                UNIQUE KEY `FK_entities` (`FK_entities`)
154
                                                                                ) ENGINE=MyISAM ;";
155

    
156
                $DB->query($query) or die("0.7 create glpi_entities_data " . $LANG["update"][90] . $DB->error());
157
        }
158

    
159
        // Add default profile to all users without any profile
160
        $query="SELECT ID FROM glpi_profiles WHERE is_default='1'";
161
        if ($result=$DB->query($query)){
162
                if ($DB->numrows($result)>0){
163
                        $IDprof=$DB->result($result,0,0);
164
                        $query="SELECT glpi_users.ID 
165
                                FROM glpi_users LEFT JOIN glpi_users_profiles ON (glpi_users_profiles.FK_users = glpi_users.ID )
166
                                WHERE glpi_users_profiles.ID IS NULL";
167
                        if ($result=$DB->query($query)){
168
                                if ($DB->numrows($result)>0){
169
                                        while ($data=$DB->fetch_assoc($result)){
170
                                                $query="INSERT INTO glpi_users_profiles (`FK_users` ,`FK_profiles`) VALUES ('".$data['ID']."','$IDprof') ";
171
                                                $DB->query($query);
172
                                        }
173
                                }
174
                        }
175
                        
176
                }
177
        }
178

    
179

    
180

    
181
        if (!FieldExists("glpi_users_profiles", "FK_entities")) {
182
                // Clean Datas
183
                $query = "DELETE FROM glpi_users_profiles WHERE FK_users='0'";
184
                $DB->query($query) or die("0.7 clean datas of glpi_users_profiles " . $LANG["update"][90] . $DB->error());
185

    
186
                $query = " ALTER TABLE `glpi_users_profiles` ADD `FK_entities` INT NOT NULL DEFAULT '0',
187
                                                ADD `recursive` SMALLINT NOT NULL DEFAULT '1',
188
                                                ADD `dynamic` SMALLINT NOT NULL DEFAULT '0' ";
189
                $DB->query($query) or die("0.7 alter glpi_users_profiles " . $LANG["update"][90] . $DB->error());
190
        }
191
        // Correct for clean active field for beta users
192
        if (FieldExists("glpi_users_profiles", "active")) {
193
                $query = "ALTER TABLE `glpi_users_profiles` DROP `active` ";
194
                $DB->query($query) or die("0.7 clean active field for beta of glpi_users_profiles " . $LANG["update"][90] . $DB->error());
195
        }
196
        if (!FieldExists("glpi_users", "active")) {
197
                $query = "ALTER TABLE `glpi_users` ADD `active` INT(2) NOT NULL DEFAULT '1' ";
198
                $DB->query($query) or die("0.7 add active field for beta of glpi_users " . $LANG["update"][90] . $DB->error());
199
                if (!isIndex("glpi_users", "active")) {
200
                        $query = "ALTER TABLE `glpi_users` ADD INDEX (`active`);";
201
                        $DB->query($query) or die("0.7 add index active in glpi_users " . $LANG["update"][90] . $DB->error());
202
                }
203
        }
204

    
205
        // Add entity tags to tables
206
        $tables = array (
207
                "glpi_cartridges_type",
208
                "glpi_computers",
209
                "glpi_consumables_type",
210
                "glpi_contacts",
211
                "glpi_contracts",
212
                "glpi_docs",
213
                "glpi_dropdown_locations",
214
                "glpi_dropdown_netpoint",
215
                "glpi_enterprises",
216
                "glpi_groups",
217
                "glpi_monitors",
218
                "glpi_networking",
219
                "glpi_peripherals",
220
                "glpi_phones",
221
                "glpi_printers",
222
                "glpi_reminder",
223
                "glpi_software",
224
                "glpi_tracking"
225
        );
226
        // "glpi_kbitems","glpi_dropdown_kbcategories", -> easier to manage
227
        // "glpi_followups" -> always link to tracking ?
228
        // "glpi_licenses" -> always link to software ? 
229
        // "glpi_infocoms" -> always link to item ? PB on reports stats ?
230
        // "glpi_links" -> global items easier to manage
231
        // "glpi_reservation_item", "glpi_state_item" -> always link to item ? but info maybe needed
232
        foreach ($tables as $tbl) {
233
                if (!FieldExists($tbl, "FK_entities")) {
234
                        $query = "ALTER TABLE `" . $tbl . "` ADD `FK_entities` INT NOT NULL DEFAULT '0' AFTER `ID`";
235
                        $DB->query($query) or die("0.7 add FK_entities in $tbl " . $LANG["update"][90] . $DB->error());
236
                }
237

    
238
                if (!isIndex($tbl, "FK_entities")) {
239
                        $query = "ALTER TABLE `" . $tbl . "` ADD INDEX (`FK_entities`)";
240
                        $DB->query($query) or die("0.7 add index FK_entities in $tbl " . $LANG["update"][90] . $DB->error());
241
                }
242
        }
243

    
244
        // Regenerate Indexes :
245
        $tables = array (
246
                "glpi_dropdown_locations"
247
        );
248
        foreach ($tables as $tbl) {
249
                if (isIndex($tbl, "name")) {
250
                        $query = "ALTER TABLE `$tbl` DROP INDEX `name`;";
251
                        $DB->query($query) or die("0.7 drop index name in $tbl " . $LANG["update"][90] . $DB->error());
252
                }
253
                if (isIndex($tbl, "parentID_2")) {
254
                        $query = "ALTER TABLE `$tbl` DROP INDEX `parentID_2`;";
255
                        $DB->query($query) or die("0.7 drop index name in $tbl " . $LANG["update"][90] . $DB->error());
256
                }
257
                $query = "ALTER TABLE `$tbl` ADD UNIQUE(`name`,`parentID`,`FK_entities`);";
258
                $DB->query($query) or die("0.7 add index name in $tbl " . $LANG["update"][90] . $DB->error());
259

    
260
        }
261

    
262
        if (isIndex("glpi_users_profiles", "FK_users_profiles")) {
263
                $query = "ALTER TABLE `glpi_users_profiles` DROP INDEX `FK_users_profiles`;";
264
                $DB->query($query) or die("0.7 drop index FK_users_profiles in glpi_users_profiles " . $LANG["update"][90] . $DB->error());
265
        }
266

    
267
        if (!isIndex("glpi_users_profiles", "FK_entities")) {
268
                $query = "ALTER TABLE `glpi_users_profiles` ADD INDEX (`FK_entities`);";
269
                $DB->query($query) or die("0.7 add index FK_entities in glpi_users_profiles " . $LANG["update"][90] . $DB->error());
270
        }
271

    
272
        if (!isIndex("glpi_users_profiles", "recursive")) {
273
                $query = "ALTER TABLE `glpi_users_profiles` ADD INDEX (`recursive`);";
274
                $DB->query($query) or die("0.7 add index recursive in glpi_users_profiles " . $LANG["update"][90] . $DB->error());
275
        }
276

    
277
        //// MULTIAUTH MANAGEMENT
278

    
279
        if (!TableExists("glpi_auth_ldap")) {
280
                $query = "CREATE TABLE `glpi_auth_ldap` (
281
                                                                         `ID` int(11) NOT NULL auto_increment,
282
                                                                         `name` varchar(255) NOT NULL,
283
                                                                         `ldap_host` varchar(255) default NULL,
284
                                                                        `ldap_basedn` varchar(255) default NULL,
285
                                                                        `ldap_rootdn` varchar(255) default NULL,
286
                                                                        `ldap_pass` varchar(255) default NULL,
287
                                                                        `ldap_port` varchar(255) NOT NULL default '389',
288
                                                                        `ldap_condition` varchar(255) default NULL,
289
                                                                        `ldap_login` varchar(255) NOT NULL default 'uid',        
290
                                                                        `ldap_use_tls` varchar(255) NOT NULL default '0',
291
                                                                        `ldap_field_group` varchar(255) default NULL,
292
                                                                        `ldap_group_condition` varchar(255) default NULL,
293
                                                                        `ldap_search_for_groups` int NOT NULL default '0',
294
                                                                        `ldap_field_group_member` varchar(255) default NULL,
295
                                                                        `ldap_field_email` varchar(255) default NULL,
296
                                                                        `ldap_field_realname` varchar(255) default NULL,
297
                                                                        `ldap_field_firstname` varchar(255) default NULL,
298
                                                                        `ldap_field_phone` varchar(255) default NULL,
299
                                                                        `ldap_field_phone2` varchar(255) default NULL,
300
                                                                        `ldap_field_mobile` varchar(255) default NULL,
301
                                                                        `ldap_field_comments` TEXT default NULL,                
302
                                                                        PRIMARY KEY  (`ID`)
303
                                                                ) ENGINE=MyISAM;";
304
                $DB->query($query) or die("0.7 create glpi_auth_ldap " . $LANG["update"][90] . $DB->error());
305

    
306
                $query = "select * from glpi_config WHERE ID=1";
307
                $result = $DB->query($query);
308
                $config = $DB->fetch_array($result);
309

    
310
                if (!empty ($config["ldap_host"])) {
311

    
312
                        //Transfer ldap informations into the new table
313
                        
314
                        $query = "INSERT INTO `glpi_auth_ldap` VALUES 
315
                        (NULL, '" . $config["ldap_host"] . "', '" . $config["ldap_host"] . "', '" . $config["ldap_basedn"] . "', '" . $config["ldap_rootdn"] . "', '" . $config["ldap_pass"] . "', " . $config["ldap_port"] . ", '" . $config["ldap_condition"] . "', '" . $config["ldap_login"] . "', '" . $config["ldap_use_tls"] . "', '" . $config["ldap_field_group"] . "',
316
                        '" . $config["ldap_condition"] . "', " . $config["ldap_search_for_groups"] . ", '" . $config["ldap_field_group_member"] . "',
317
                        '" . $config["ldap_field_email"] . "', '" . $config["ldap_field_realname"] . "', '" . $config["ldap_field_firstname"] . "',
318
                        '" . $config["ldap_field_phone"] . "', '" . $config["ldap_field_phone2"] . "', '" . $config["ldap_field_mobile"] . "',NULL);";
319
                        $DB->query($query) or die("0.7 transfert of ldap parameters into glpi_auth_ldap " . $LANG["update"][90] . $DB->error());
320
                }
321

    
322
                $query = "ALTER TABLE `glpi_config`
323
                                                                        DROP `ldap_field_email`,
324
                                                                        DROP `ldap_port`,
325
                                                                        DROP `ldap_host`,
326
                                                                        DROP `ldap_basedn`,
327
                                                                        DROP `ldap_rootdn`,
328
                                                                        DROP `ldap_pass`,
329
                                                                        DROP `ldap_field_location`,
330
                                                                        DROP `ldap_field_realname`,
331
                                                                        DROP `ldap_field_firstname`,
332
                                                                        DROP `ldap_field_phone`,
333
                                                                        DROP `ldap_field_phone2`,
334
                                                                        DROP `ldap_field_mobile`,
335
                                                                        DROP `ldap_condition`,
336
                                                                        DROP `ldap_login`,
337
                                                                        DROP `ldap_use_tls`,
338
                                                                        DROP `ldap_field_group`,
339
                                                                        DROP `ldap_group_condition`,
340
                                                                        DROP `ldap_search_for_groups`,
341
                                                                        DROP `ldap_field_group_member`;";
342
                $DB->query($query) or die("0.7 drop ldap fields from glpi_config " . $LANG["update"][90] . $DB->error());
343

    
344
        }
345
        if (!FieldExists("glpi_users", "id_auth")) {
346
                $query = "ALTER TABLE glpi_users ADD `id_auth` INT NOT NULL DEFAULT '-1',
347
                                                                                ADD `auth_method` INT NOT NULL DEFAULT '-1',
348
                                                                                ADD `last_login` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
349
                                                                                ADD `date_mod` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'";
350
                $DB->query($query) or die("0.7 add auth_method & id_method in glpi_users " . $LANG["update"][90] . $DB->error());
351
        }
352

    
353
        if (!TableExists("glpi_auth_mail")) {
354
                $query = "CREATE TABLE `glpi_auth_mail` (
355
                                                                                `ID` int(11) NOT NULL auto_increment,
356
                                                                                `name` varchar(255) NOT NULL,
357
                                                                                `imap_auth_server` varchar(200) default NULL,
358
                                                                                `imap_host` varchar(200) default NULL,
359
                                                                                PRIMARY KEY  (`ID`)
360
                                                                                ) ENGINE=MyISAM ;";
361

    
362
                $DB->query($query) or die("0.7 create glpi_auth_mail " . $LANG["update"][90] . $DB->error());
363

    
364
                $query = "select * from glpi_config WHERE ID=1";
365
                $result = $DB->query($query);
366
                $config = $DB->fetch_array($result);
367

    
368
                if (!empty ($config["imap_host"])) {
369

    
370
                        //Transfer ldap informations into the new table
371
                        $query = "INSERT INTO `glpi_auth_mail` VALUES 
372
                                                                                                        (NULL, '" . $config["imap_host"] . "', '" . $config["imap_auth_server"] . "', '" . $config["imap_host"] . "');";
373
                        $DB->query($query) or die("0.7 transfert of mail parameters into glpi_auth_mail " . $LANG["update"][90] . $DB->error());
374

    
375
                }
376

    
377
                $query = "ALTER TABLE `glpi_config`
378
                                                                                  DROP `imap_auth_server`,
379
                                                                                  DROP `imap_host`";
380
                $DB->query($query) or die("0.7 drop mail fields from glpi_config " . $LANG["update"][90] . $DB->error());
381

    
382
        }
383

    
384
        // Clean state_item -> add a field from tables
385
        if (TableExists("glpi_state_item")) {
386
                $state_type = array (
387
                        SOFTWARE_TYPE,
388
                        COMPUTER_TYPE,
389
                        PRINTER_TYPE,
390
                        MONITOR_TYPE,
391
                        PERIPHERAL_TYPE,
392
                        NETWORKING_TYPE,
393
                        PHONE_TYPE
394
                );
395
                foreach ($state_type as $type) {
396
                        $table = $LINK_ID_TABLE[$type];
397
                        if (!FieldExists($table, "state")) {
398
                                $query = "ALTER TABLE `$table` ADD `state` INT NOT NULL DEFAULT '0';";
399
                                $DB->query($query) or die("0.7 add state field to $table " . $LANG["update"][90] . $DB->error());
400
                                $query2 = "SELECT * FROM glpi_state_item WHERE device_type='$type'";
401
                                $result = $DB->query($query2);
402
                                if ($DB->numrows($result)) {
403
                                        while ($data = $DB->fetch_array($result)) {
404
                                                $query3 = "UPDATE $table SET state='" . $data["state"] . "' WHERE ID ='" . $data["id_device"] . "'";
405
                                                $DB->query($query3) or die("0.7 update state field value to $table " . $LANG["update"][90] . $DB->error());
406
                                        }
407
                                }
408
                        }
409
                }
410
                $query = "DROP TABLE `glpi_state_item` ";
411
                $DB->query($query) or die("0.7 drop table state_item " . $LANG["update"][90] . $DB->error());
412
                $query = "INSERT INTO `glpi_display` (`type`, `num`, `rank`, `FK_users`) VALUES (22, 31, 1, 0);";
413
                $DB->query($query) or die("0.7 add default search for states " . $LANG["update"][90] . $DB->error());
414
                // Add for reservation
415
                $query = "INSERT INTO `glpi_display` (`type`, `num`, `rank`, `FK_users`) VALUES ( 29, 4, 1, 0);";
416
                $DB->query($query) or die("0.7 add defaul search for reservation " . $LANG["update"][90] . $DB->error());
417
                $query = "INSERT INTO `glpi_display` (`type`, `num`, `rank`, `FK_users`) VALUES ( 29, 3, 2, 0);";
418
                $DB->query($query) or die("0.7 add defaul search for reservation " . $LANG["update"][90] . $DB->error());
419
        }
420

    
421
        // Add ticket_tco for hardwares
422
        $tco_tbl = array (
423
                COMPUTER_TYPE,
424
                NETWORKING_TYPE,
425
                PRINTER_TYPE,
426
                MONITOR_TYPE,
427
                PERIPHERAL_TYPE,
428
                SOFTWARE_TYPE,
429
                PHONE_TYPE
430
        );
431
        include (GLPI_ROOT . "/inc/tracking.function.php");
432

    
433
        foreach ($tco_tbl as $type) {
434
                $table = $LINK_ID_TABLE[$type];
435
                if (!FieldExists($table, "ticket_tco")) {
436
                        $query = "ALTER TABLE `$table` ADD `ticket_tco` DECIMAL( 20, 4 ) DEFAULT '0.0000';";
437
                        $DB->query($query) or die("0.7 alter $table add ticket_tco" . $LANG["update"][90] . $DB->error());
438
                        // Update values
439
                        $query = "SELECT DISTINCT device_type, computer 
440
                                                                                                        FROM glpi_tracking 
441
                                                                                                        WHERE device_type = '$type' AND (cost_time>0 
442
                                                                                                                OR cost_fixed>0
443
                                                                                                                OR cost_material>0)";
444
                        $result = $DB->query($query) or die("0.7 update ticket_tco" . $LANG["update"][90] . $DB->error());
445
                        if ($DB->numrows($result)) {
446
                                while ($data = $DB->fetch_array($result)) {
447
                                        $query2 = "UPDATE $table SET ticket_tco='" . computeTicketTco($type, $data["computer"]) . "' 
448
                                                                                                                                                                        WHERE ID='" . $data["computer"] . "';";
449
                                        $DB->query($query2) or die("0.7 update ticket_tco" . $LANG["update"][90] . $DB->error());
450
                                }
451
                        }
452
                }
453
        }
454
        if (!FieldExists("glpi_software", "helpdesk_visible")) {
455
                $query = "ALTER TABLE glpi_software ADD `helpdesk_visible` INT NOT NULL default '1'";
456
                $DB->query($query) or die("0.7 add helpdesk_visible in glpi_software " . $LANG["update"][90] . $DB->error());
457
        }
458

    
459
        if (!TableExists("glpi_dropdown_manufacturer")) {
460

    
461
                $query = "CREATE TABLE `glpi_dropdown_manufacturer` (
462
                                                                `ID` int(11) NOT NULL auto_increment,
463
                                                                `name` varchar(255) NOT NULL,
464
                                                                `comments` text,
465
                                                                PRIMARY KEY  (`ID`),
466
                                                                KEY `name` (`name`)
467
                                                                ) ENGINE=MyISAM ;";
468
                $DB->query($query) or die("0.7 add dropdown_manufacturer table " . $LANG["update"][90] . $DB->error());
469
        }
470
        if (countElementsInTable("glpi_dropdown_manufacturer")==0){
471

    
472
                // Fill table
473
                $query = "SELECT * FROM glpi_enterprises ORDER BY ID";
474
                if ($result = $DB->query($query)) {
475
                        if ($DB->numrows($result)) {
476
                                while ($data = $DB->fetch_assoc($result)) {
477
                                        $data = addslashes_deep($data);
478
                                        
479
                                        $comments = "";
480
                                        if (!empty ($data['address'])) {
481
                                                if (!empty ($comments))
482
                                                        $comments .= "\n";
483
                                                $comments .= $LANG["financial"][44] . ":\n";
484
                                                $comments .= $data['address'];
485
                                        }
486
                                        if (!empty ($data['postcode']) || !empty ($data['town'])) {
487
                                                if (!empty ($comments))
488
                                                        $comments .= $LANG["financial"][44] . ":\n";
489
                                                $comments .= $data['postcode'] . " " . $data['town'];
490
                                        }
491
                                        if (!empty ($data['state']) || !empty ($data['country'])) {
492
                                                if (!empty ($comments))
493
                                                        $comments .= $LANG["financial"][44] . ":\n";
494
                                                $comments .= $data['country'] . " " . $data['state'];
495
                                        }
496
                                        if (!empty ($data['website'])) {
497
                                                if (!empty ($comments))
498
                                                        $comments .= "\n";
499
                                                $comments .= $LANG["financial"][45] . ": ";
500
                                                $comments .= $data['website'];
501
                                        }
502
                                        if (!empty ($data['phonenumber'])) {
503
                                                if (!empty ($comments))
504
                                                        $comments .= "\n";
505
                                                $comments .= $LANG["help"][35] . ": ";
506
                                                $comments .= $data['phonenumber'];
507
                                        }
508
                                        if (!empty ($data['fax'])) {
509
                                                if (!empty ($comments))
510
                                                        $comments .= "\n";
511
                                                $comments .= $LANG["financial"][30] . ": ";
512
                                                $comments .= $data['fax'];
513
                                        }
514
                                        if (!empty ($data['email'])) {
515
                                                if (!empty ($comments))
516
                                                        $comments .= "\n";
517
                                                $comments .= $LANG["setup"][14] . ": ";
518
                                                $comments .= $data['email'];
519
                                        }
520
                                        if (!empty ($data['comments'])) {
521
                                                if (!empty ($comments))
522
                                                        $comments .= "\n";
523
                                                $comments .= $data['comments'];
524
                                        }
525
                                        if (!empty ($data['notes'])) {
526
                                                if (!empty ($comments))
527
                                                        $comments .= "\n";
528
                                                $comments .= $data['notes'];
529
                                        }
530

    
531
                                        $query2 = "INSERT INTO `glpi_dropdown_manufacturer` (ID,name,comments) VALUES ('" . $data['ID'] . "','" . $data['name'] . "','".$comments."')";
532
                                        $DB->query($query2) or die("0.7 add manufacturer item " . $LANG["update"][90] . $DB->error());
533
                                }
534
                        }
535
                }
536
        }
537

    
538
        if (isIndex("glpi_ocs_link", "ocs_id_2")) {
539
                $query = "ALTER TABLE `glpi_ocs_link` DROP INDEX `ocs_id_2` ";
540
                $DB->query($query) or die("0.7 alter ocs_link clean index ocs_id  " . $LANG["update"][90] . $DB->error());
541
        }
542

    
543
        if (isIndex("glpi_ocs_link", "ocs_id")) {
544
                $query = "ALTER TABLE `glpi_ocs_link` DROP INDEX `ocs_id` ";
545
                $DB->query($query) or die("0.7 alter ocs_link clean index ocs_id  " . $LANG["update"][90] . $DB->error());
546
        }
547

    
548
         
549
        if (!FieldExists("glpi_ocs_link", "ocs_server_id")) {
550
                $query = "ALTER TABLE glpi_ocs_link ADD `ocs_server_id` int(11) NOT NULL";
551
                $DB->query($query) or die("0.7 add ocs_server_id in glpi_ocs_link " . $LANG["update"][90] . $DB->error());
552
                $query = "update glpi_ocs_link set ocs_server_id=1";
553
                $DB->query($query) or die("0.7 update ocs_server_id=1 in glpi_ocs_link " . $LANG["update"][90] . $DB->error());
554
        }
555

    
556
        if (!isIndex("glpi_ocs_link", "ocs_server_id")) {
557
        // Clean duplicates
558
                $query="SELECT COUNT(*) as CPT, ocs_id FROM glpi_ocs_link GROUP BY ocs_id HAVING CPT >1"; 
559
                if ($result=$DB->query($query)){ 
560
                        if ($DB->numrows($result)>0){
561
                                while ($data=$DB->fetch_array($result)){ 
562
                                        // Skip first
563
                                        $query="SELECT ID FROM glpi_ocs_link WHERE ocs_id = '".$data['ocs_id']."' ORDER BY last_update DESC LIMIT 1,99999";
564
                                        if ($result2=$DB->query($query)){ 
565
                                                if ($DB->numrows($result2)){
566
                                                        while ($data2=$DB->fetch_array($result2)){ 
567
                                                                $query="DELETE FROM glpi_ocs_link WHERE ID ='".$data2['ID']."'"; 
568
                                                                $DB->query($query) or die("0.7 clean to update ocs_server_id=1 in glpi_ocs_link " . $LANG["update"][90] . $DB->error());
569
                                                        }
570
                                                }
571
                                        }
572
                                }
573
                        }
574
                }
575
                
576
                
577
                
578
                $query = "ALTER TABLE `glpi_ocs_link` ADD UNIQUE `ocs_server_id` (`ocs_server_id` ,`ocs_id`);";
579
                $DB->query($query) or die("0.7 alter ocs_link add index ocs_server_id " . $LANG["update"][90] . $DB->error());
580
        }
581

    
582
        if (!isIndex("glpi_ocs_link", "`ocs_deviceid`")) {        
583
                $query = "ALTER TABLE `glpi_ocs_link` ADD INDEX ( `ocs_deviceid` )";
584
                $DB->query($query) or die("0.7 alter ocs_link add index ocs_deviceid " . $LANG["update"][90] . $DB->error());
585
        }
586

    
587
        if (!FieldExists("glpi_ocs_config", "tplname")) {
588
                $query = "ALTER TABLE glpi_ocs_config ADD `name` varchar(200) default NULL AFTER `ID`, ADD `is_template` enum('0','1') NOT NULL default '0', ADD `tplname` varchar(200) default NULL, ADD `date_mod` datetime default NULL";
589
                $DB->query($query) or die("0.7 add name, is_template, tplname, date_mod in glpi_ocs_link " . $LANG["update"][90] . $DB->error());
590
                $query = "update glpi_ocs_config set name=ocs_db_host";
591
                $DB->query($query) or die("0.7 add name in glpi_ocs_config " . $LANG["update"][90] . $DB->error());
592
        }
593

    
594
        if (!FieldExists("glpi_ocs_config", "import_registry")) {
595
                $query = "ALTER TABLE glpi_ocs_config ADD `import_registry` INT NOT NULL default '0' AFTER `import_device_modems`";
596
                $DB->query($query) or die("0.7 add import_registry in glpi_ocs_config " . $LANG["update"][90] . $DB->error());
597
        }
598
        if (FieldExists("glpi_ocs_config", "import_tag_field")) {
599
                $query = "ALTER TABLE glpi_ocs_config DROP `import_tag_field`;";
600
                $DB->query($query) or die("0.7 drop import_tag_field in glpi_ocs_config " . $LANG["update"][90] . $DB->error());
601
        }
602

    
603
        if (!FieldExists("glpi_ocs_config", "import_software_licensetype")) {
604
                $query = "ALTER TABLE glpi_ocs_config ADD `import_software_licensetype` VARCHAR(255) DEFAULT 'global' AFTER `import_software`";
605
                $DB->query($query) or die("0.7 add import_software_licensetype in glpi_ocs_config " . $LANG["update"][90] . $DB->error());
606
        }
607

    
608
        if (!FieldExists("glpi_ocs_config", "import_software_buy")) {
609
                $query = "ALTER TABLE glpi_ocs_config ADD `import_software_buy` INT NOT NULL DEFAULT '1' AFTER `import_software`";
610
                $DB->query($query) or die("0.7 add import_software_buy in glpi_ocs_config " . $LANG["update"][90] . $DB->error());
611
        }
612

    
613
        if (!TableExists("glpi_registry")) {
614
                $query = "CREATE TABLE  `glpi_registry` (
615
                                                                                 `ID` int(10) NOT NULL auto_increment,
616
                                                                                 `computer_id` int(10) NOT NULL DEFAULT '0',
617
                                                                                 `registry_hive` varchar(45) NOT NULL,
618
                                                                                 `registry_path` varchar(255) NOT NULL,
619
                                                                                 `registry_value` varchar(255) NOT NULL,
620
                                                                                 PRIMARY KEY  (`ID`),
621
                                                                                KEY `computer_id` (`computer_id`)
622
                                                                                ) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;";
623
                $DB->query($query) or die("0.7 add glpi_registry table " . $LANG["update"][90] . $DB->error());
624

    
625
        }
626

    
627
        if (!FieldExists("glpi_ocs_link", "import_ip")) {
628
                $query = "ALTER TABLE `glpi_ocs_link` ADD COLUMN `import_ip` LONGTEXT";
629
                $DB->query($query) or die("0.7 add import_ip in glpi_ocs_link" . $LANG["update"][90] . $DB->error());
630
        }
631

    
632

    
633
        //// Enum clean
634
        // Enum 0-1
635
        $enum01 = array ();
636
        $template_tables = array (
637
                "glpi_computers",
638
                "glpi_networking",
639
                "glpi_printers",
640
                "glpi_monitors",
641
                "glpi_peripherals",
642
                "glpi_software",
643
                "glpi_phones",
644
                "glpi_ocs_config"
645
        );
646

    
647
        foreach ($template_tables as $table) {
648
                if (!isset ($enum01[$table])) {
649
                        $enum01[$table] = array ();
650
                }
651
                $enum01[$table][] = "is_template";
652
        }
653
        $enum01["glpi_config"][] = "auto_assign";
654
        $enum01["glpi_config"][] = "public_faq";
655
        $enum01["glpi_config"][] = "url_in_mail";
656
        $enum01["glpi_profiles"][] = "is_default";
657

    
658
        $enum01["glpi_monitors"][] = "is_global";
659
        $enum01["glpi_peripherals"][] = "is_global";
660
        $enum01["glpi_phones"][] = "is_global";
661
        $enum01["glpi_printers"][] = "is_global";
662
        $enum01["glpi_reminder"][] = "rv";
663
        $enum01["glpi_contract_device"][] = "is_template";
664
        $enum01["glpi_doc_device"][] = "is_template";
665

    
666
        foreach ($enum01 as $table => $fields) {
667
                foreach ($fields as $key => $field) {
668
                        if (FieldExists($table, $field)) {
669

    
670
                                $query = "ALTER TABLE `$table` ADD `tmp_convert_enum` SMALLINT NOT NULL DEFAULT '0' AFTER `$field` ";
671
                                $DB->query($query) or die("0.7 alter $table add new field tmp_convert_enum " . $LANG["update"][90] . $DB->error());
672

    
673
                                $query = "UPDATE `$table` SET tmp_convert_enum='1' WHERE $field='1';";
674
                                $DB->query($query) or die("0.7 update $table to set correct values to alod enum01 $field " . $LANG["update"][90] . $DB->error());
675
                                $query = "UPDATE `$table` SET tmp_convert_enum='0' WHERE $field='0';";
676
                                $DB->query($query) or die("0.7 update $table to set correct values to alod enum01 $field " . $LANG["update"][90] . $DB->error());
677

    
678
                                $query = "ALTER TABLE `$table` DROP `$field` ";
679
                                $DB->query($query) or die("0.7 alter $table drop tmp enum field " . $LANG["update"][90] . $DB->error());
680

    
681
                                $query = "ALTER TABLE `$table` CHANGE `tmp_convert_enum` `$field` SMALLINT NOT NULL DEFAULT '0'";
682
                                $DB->query($query) or die("0.7 alter $table move enum $field to tmp field " . $LANG["update"][90] . $DB->error());
683

    
684
                                if ($table != "glpi_config" && $table != "glpi_profiles") {
685
                                        $query = "ALTER TABLE `$table` ADD KEY (`$field`)";
686
                                        $DB->query($query) or die("0.7 alter $table add deleted key " . $LANG["update"][90] . $DB->error());
687
                                }
688
                        }
689
                }
690
        }
691

    
692
        $enumYN["N"]["glpi_contracts"][] = "monday"; // N
693
        $enumYN["N"]["glpi_contracts"][] = "saturday"; // N
694
        $enumYN["Y"]["glpi_device_drive"][] = "is_writer"; // Y 
695
        $enumYN["N"]["glpi_device_control"][] = "raid"; // Y -> N
696
        $enumYN["Y"]["glpi_device_power"][] = "atx"; // Y
697
        $enumYN["N"]["glpi_licenses"][] = "oem"; // N
698
        $enumYN["Y"]["glpi_licenses"][] = "buy"; // Y
699
        $enumYN["N"]["glpi_software"][] = "is_update"; // N
700
        $enumYN["Y"]["glpi_type_docs"][] = "upload"; // Y
701

    
702
        $deleted_tables = array (
703
                "glpi_computers",
704
                "glpi_networking",
705
                "glpi_printers",
706
                "glpi_monitors",
707
                "glpi_peripherals",
708
                "glpi_software",
709
                "glpi_cartridges_type",
710
                "glpi_contracts",
711
                "glpi_contacts",
712
                "glpi_enterprises",
713
                "glpi_docs",
714
                "glpi_phones",
715
                "glpi_consumables_type"
716
        );
717

    
718
        foreach ($deleted_tables as $table) {
719
                if (!isset ($enum01[$table])) {
720
                        $enum01[$table] = array ();
721
                }
722
                $enumYN["N"][$table][] = "deleted";
723
        }
724

    
725
        foreach ($enumYN as $default => $tmptbl)
726
                foreach ($tmptbl as $table => $fields) {
727
                        foreach ($fields as $key => $field) {
728
                                if (FieldExists($table, $field)) {
729

    
730
                                        $newdef = 0;
731
                                        if ($default == "Y") {
732
                                                $newdef = 1;
733
                                        }
734

    
735
                                        $query = "ALTER TABLE `$table` ADD `tmp_convert_enum` SMALLINT NOT NULL DEFAULT '$newdef' AFTER `$field` ";
736
                                        $DB->query($query) or die("0.7 alter $table add new field tmp_convert_enum " . $LANG["update"][90] . $DB->error());
737

    
738
                                        $query = "UPDATE `$table` SET tmp_convert_enum='1' WHERE $field='Y';";
739
                                        $DB->query($query) or die("0.7 update $table to set correct values to alod enum01 $field " . $LANG["update"][90] . $DB->error());
740
                                        $query = "UPDATE `$table` SET tmp_convert_enum='0' WHERE $field='N';";
741
                                        $DB->query($query) or die("0.7 update $table to set correct values to alod enum01 $field " . $LANG["update"][90] . $DB->error());
742

    
743
                                        $query = "ALTER TABLE `$table` DROP `$field` ";
744
                                        $DB->query($query) or die("0.7 alter $table drop tmp enum field " . $LANG["update"][90] . $DB->error());
745

    
746
                                        $query = "ALTER TABLE `$table` CHANGE `tmp_convert_enum` `$field` SMALLINT NOT NULL DEFAULT '$newdef'";
747
                                        $DB->query($query) or die("0.7 alter $table move enum $field to tmp field " . $LANG["update"][90] . $DB->error());
748

    
749
                                        if ($field == "deleted" || $table == "glpi_licenses" || $table == "glpi_software" || $table == "glpi_type_docs") {
750
                                                $query = "ALTER TABLE `$table` ADD KEY (`$field`)";
751
                                                $DB->query($query) or die("0.7 alter $table add deleted key " . $LANG["update"][90] . $DB->error());
752
                                        }
753
                                }
754
                        }
755
                }
756

    
757
        if (FieldExists("glpi_tracking", "is_group")) {
758
                $query = "ALTER TABLE glpi_tracking DROP `is_group`";
759
                $DB->query($query) or die("0.7 drop is_group from tracking " . $LANG["update"][90] . $DB->error());
760
        }
761

    
762
        $enumYesNo["glpi_kbitems"][] = "faq";
763
        $enumYesNo["glpi_tracking"][] = "emailupdates";
764
        $enumYesNo["glpi_users"][] = "tracking_order";
765

    
766
        foreach ($enumYesNo as $table => $fields) {
767
                foreach ($fields as $key => $field) {
768
                        if (FieldExists($table, $field)) {
769

    
770
                                $query = "ALTER TABLE `$table` ADD `tmp_convert_enum` SMALLINT NOT NULL DEFAULT '0' AFTER `$field` ";
771
                                $DB->query($query) or die("0.7 alter $table add new field tmp_convert_enum " . $LANG["update"][90] . $DB->error());
772

    
773
                                $query = "UPDATE `$table` SET tmp_convert_enum='1' WHERE $field='yes';";
774
                                $DB->query($query) or die("0.7 update $table to set correct values to alod enum01 $field " . $LANG["update"][90] . $DB->error());
775
                                $query = "UPDATE `$table` SET tmp_convert_enum='0' WHERE $field='no';";
776
                                $DB->query($query) or die("0.7 update $table to set correct values to alod enum01 $field " . $LANG["update"][90] . $DB->error());
777

    
778
                                $query = "ALTER TABLE `$table` DROP `$field` ";
779
                                $DB->query($query) or die("0.7 alter $table drop tmp enum field " . $LANG["update"][90] . $DB->error());
780

    
781
                                $query = "ALTER TABLE `$table` CHANGE `tmp_convert_enum` `$field` SMALLINT NOT NULL DEFAULT '0'";
782
                                $DB->query($query) or die("0.7 alter $table move enum $field to tmp field " . $LANG["update"][90] . $DB->error());
783

    
784
                                if ($table == "glpi_kbitems") {
785
                                        $query = "ALTER TABLE `$table` ADD KEY (`$field`)";
786
                                        $DB->query($query) or die("0.7 alter $table add deleted key " . $LANG["update"][90] . $DB->error());
787
                                }
788
                        }
789
                }
790
        }
791
        // Reste enum : glpi_tracking.status et glpi_device_gfxcard.interface
792
        if (FieldExists("glpi_tracking", "status")) {
793
                $query = "ALTER TABLE `glpi_tracking` CHANGE `status` `status` VARCHAR( 255 ) DEFAULT 'new'";
794
                $DB->query($query) or die("0.7 alter status from tracking " . $LANG["update"][90] . $DB->error());
795
        }
796

    
797
        if (FieldExists("glpi_device_gfxcard", "interface")) {
798
                $query = "ALTER TABLE `glpi_device_gfxcard` CHANGE `interface` `interface` VARCHAR( 255 ) NULL DEFAULT 'PCI-X'";
799
                $DB->query($query) or die("0.7 alter interface from glpi_device_gfxcard " . $LANG["update"][90] . $DB->error());
800
        }
801

    
802
        if (!TableExists("glpi_rules_actions")) {
803
                $query = "CREATE TABLE `glpi_rules_actions` (
804
                                                  `ID` int(11) NOT NULL auto_increment,
805
                                                  `FK_rules` int(11) NOT NULL DEFAULT '0',
806
                                                  `action_type` varchar(255) NOT NULL,
807
                                                  `field` varchar(255) NOT NULL,
808
                                                  `value` varchar(255) NOT NULL,
809
                                                  PRIMARY KEY  (`ID`),
810
                                                  KEY `FK_rules` (`FK_rules`)
811
                                                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
812
                                                ";
813
                $DB->query($query) or die("0.7 add table glpi_rules_descriptions" . $LANG["update"][90] . $DB->error());
814

    
815
        }
816

    
817
        if (!TableExists("glpi_rules_criterias")) {
818
                $query = "CREATE TABLE `glpi_rules_criterias` (
819
                                  `ID` int(11) NOT NULL auto_increment,
820
                                  `FK_rules` int(11) NOT NULL DEFAULT '0',
821
                                  `criteria` varchar(255) NOT NULL,
822
                                  `condition` smallint(4) NOT NULL DEFAULT '0',
823
                                  `pattern` varchar(255) NOT NULL,
824
                                  PRIMARY KEY  (`ID`),
825
                                KEY `FK_rules` (`FK_rules`)
826
                                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;";
827
                $DB->query($query) or die("0.7 add table glpi_rules_criterias" . $LANG["update"][90] . $DB->error());
828

    
829
        }
830

    
831
        if (!TableExists("glpi_rules_descriptions")) {
832
                $query = "CREATE TABLE `glpi_rules_descriptions` (
833
                  `ID` int(11) NOT NULL auto_increment,
834
                  `FK_entities` int(11) NOT NULL default '-1',
835
                  `rule_type` smallint(4) NOT NULL DEFAULT '0',
836
                  `ranking` int(11) NOT NULL DEFAULT '0',
837
                  `name` varchar(255) NOT NULL,
838
                  `description` text NOT NULL,
839
                  `match` varchar(255) NOT NULL,
840
                  PRIMARY KEY  (`ID`)
841
                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;";
842
                $DB->query($query) or die("0.7 add table glpi_rules_actions" . $LANG["update"][90] . $DB->error());
843

    
844
        }
845

    
846
        if (!FieldExists("glpi_config", "use_cache")) {
847
                $query = "ALTER TABLE `glpi_config` ADD `use_cache` SMALLINT NOT NULL DEFAULT '1' AFTER `debug` ;";
848
                $DB->query($query) or die("0.7 alter config add use_cache " . $LANG["update"][90] . $DB->error());
849
        }
850

    
851
        if (TableExists("glpi_rules_descriptions")) {
852
                //If no rule exists, then create a default one
853
                $query = "SELECT ID from glpi_rules_descriptions";
854
                $result = $DB->query($query);
855
                if ($DB->numrows($result) ==0)
856
                {
857
                        //Insert rule to affect machines in the Root entity
858
                        $query ="INSERT INTO `glpi_rules_descriptions` (`FK_entities`, `rule_type`, `ranking`, `name`, `description`, `match`) VALUES (-1, 0, 0, 'Root', '', 'AND');";
859
                        $DB->query($query) or die("0.7 add default ocs affectation rule" . $LANG["update"][90] . $DB->error());
860
                
861
                        $query = "SELECT ID from glpi_rules_descriptions WHERE name='Root' AND rule_type=".RULE_OCS_AFFECT_COMPUTER;
862
                        $result = $DB->query($query);
863
                        //Get the defaut rule's ID
864
                        $datas = $DB->fetch_array($result);
865
        
866
                        $query="INSERT INTO `glpi_rules_criterias` (`FK_rules`, `criteria`, `condition`, `pattern`) VALUES (".$datas["ID"].", 'TAG', 0, '*');";
867
                        $DB->query($query) or die("0.7 add default ocs criterias" . $LANG["update"][90] . $DB->error());
868
        
869
                        $query="INSERT INTO `glpi_rules_actions` (`FK_rules`, `action_type`, `field`, `value`) VALUES (".$datas["ID"].", 'assign', 'FK_entities', '0');";
870
                        $DB->query($query) or die("0.7 add default ocs actions" . $LANG["update"][90] . $DB->error());
871

    
872
                        //Insert rule to affect users from LDAP to the root entity
873
                        $query ="INSERT INTO `glpi_rules_descriptions` (`FK_entities`, `rule_type`, `ranking`, `name`, `description`, `match`) VALUES (-1, ".RULE_AFFECT_RIGHTS.", 1, 'Root', '', 'OR');";
874
                        $DB->query($query) or die("0.7 add default right affectation rule" . $LANG["update"][90] . $DB->error());
875

    
876
                        $query = "SELECT ID from glpi_rules_descriptions WHERE name='Root' AND rule_type=".RULE_AFFECT_RIGHTS;
877
                        $result = $DB->query($query);
878
                        //Get the defaut rule's ID
879
                        $datas = $DB->fetch_array($result);
880
        
881
                        //Criterias
882
                        $query="INSERT INTO `glpi_rules_criterias` (`FK_rules`, `criteria`, `condition`, `pattern`) VALUES (".$datas["ID"].", 'uid', 0, '*');";
883
                        $DB->query($query) or die("0.7 add default right criterias" . $LANG["update"][90] . $DB->error());
884

    
885
                        $query="INSERT INTO `glpi_rules_criterias` (`FK_rules`, `criteria`, `condition`, `pattern`) VALUES (".$datas["ID"].", 'samaccountname', 0, '*');";
886
                        $DB->query($query) or die("0.7 add default right criterias" . $LANG["update"][90] . $DB->error());
887

    
888
                        $query="INSERT INTO `glpi_rules_criterias` (`FK_rules`, `criteria`, `condition`, `pattern`) VALUES (".$datas["ID"].", 'MAIL_EMAIL', 0, '*');";
889
                        $DB->query($query) or die("0.7 add default right criterias" . $LANG["update"][90] . $DB->error());
890
        
891
                        //Action
892
                        $query="INSERT INTO `glpi_rules_actions` (`FK_rules`, `action_type`, `field`, `value`) VALUES (".$datas["ID"].", 'assign', 'FK_entities', '0');";
893
                        $DB->query($query) or die("0.7 add default right actions" . $LANG["update"][90] . $DB->error());
894

    
895
                }
896
        }
897
        
898
        if (!TableExists("glpi_ocs_admin_link")){
899
                        $query = "CREATE TABLE `glpi_ocs_admin_link` (
900
                          `ID` int(10) unsigned NOT NULL auto_increment,
901
                          `glpi_column` varchar(255) NULL,
902
                          `ocs_column` varchar(255) NULL,
903
                          `ocs_server_id` int(11) NOT NULL,
904
                          PRIMARY KEY  (`ID`)
905
                        ) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;";
906
                        $DB->query($query) or die("0.7 add table glpi_ocs_admin_link" . $LANG["update"][90] . $DB->error());
907
        }
908

    
909
        // Add title to tracking
910
        if (!FieldExists("glpi_tracking", "name")) {
911
                $query = "ALTER TABLE `glpi_tracking` ADD `name` varchar(255) NULL AFTER `FK_entities`";
912
                $DB->query($query) or die("0.7 alter tracking add name" . $LANG["update"][90] . $DB->error());
913
                $query="UPDATE glpi_tracking SET name=SUBSTRING(REPLACE(contents,'\n',' '),1,50);";
914
                $DB->query($query) or die("0.7 update title of glpi_tracking" . $LANG["update"][90] . $DB->error());
915
        }
916
        if (FieldExists("glpi_reminder", "title")) {
917
                $query = "ALTER TABLE `glpi_reminder` CHANGE `title` `title` VARCHAR( 255 ) NULL DEFAULT NULL ";
918
                $DB->query($query) or die("0.7 alter title in glpi_reminder" . $LANG["update"][90] . $DB->error());
919
        }
920

    
921
        if (!TableExists("glpi_rules_ldap_parameters")){
922
                        $query = "CREATE TABLE `glpi_rules_ldap_parameters` (
923
                          `ID` int(11) NOT NULL auto_increment,
924
                            `name` varchar(255) NOT NULL,
925
                            `value` varchar(255) NOT NULL,
926
                            `rule_type` smallint(6) NOT NULL default '1',
927
                             PRIMARY KEY  (`ID`)
928
                          ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;";
929
                        $DB->query($query) or die("0.7 add table glpi_rules_ldap_parameters" . $LANG["update"][90] . $DB->error());
930
        
931
                $query = "INSERT INTO `glpi_rules_ldap_parameters` (`ID`, `name`, `value`, `rule_type`) VALUES 
932
                                        (1, '(LDAP)Organization', 'o', 1),
933
                                        (2, '(LDAP)Common Name', 'cn', 1),
934
                                        (3, '(LDAP)Department Number', 'departmentnumber', 1),
935
                                        (4, '(LDAP)Email', 'mail', 1),
936
                                        (5, 'Object Class', 'objectclass', 1),                
937
                                        (6, '(LDAP)User ID', 'uid', 1),
938
                                        (7, '(LDAP)Telephone Number', 'phone', 1),
939
                                        (8, '(LDAP)Employee Number', 'employeenumber', 1),
940
                                        (9, '(LDAP)Manager', 'manager', 1),
941
                                        (10, '(LDAP)DistinguishedName', 'dn', 1),
942
                                        (11, '(AD)DistinguishedName', 'distinguishedname', 1),
943
                                        (12, '(AD)User ID', 'samaccountname', 1);";
944
                                        
945
                $DB->query($query) or die("0.7 add standard values to glpi_rules_ldap_parameters " . $LANG["update"][90] . $DB->error());
946
        
947
        }
948

    
949
        if (!FieldExists("glpi_config", "helpdeskhelp_url")) {
950
                $query = "ALTER TABLE `glpi_config` ADD `helpdeskhelp_url` VARCHAR( 255 ) NULL DEFAULT NULL ";
951
                $DB->query($query) or die("0.7 add helpdeskhelp_url in glpi_config" . $LANG["update"][90] . $DB->error());
952
        }        
953
        if (!FieldExists("glpi_config", "centralhelp_url")) {
954
                $query = "ALTER TABLE `glpi_config` ADD `centralhelp_url` VARCHAR( 255 ) NULL DEFAULT NULL ";
955
                $DB->query($query) or die("0.7 add centralhelp_url in glpi_config" . $LANG["update"][90] . $DB->error());
956
        }        
957

    
958
        if (!FieldExists("glpi_config", "default_rubdoc_tracking")) {
959
                $query = "ALTER TABLE `glpi_config` ADD `default_rubdoc_tracking` int(11) default '0' ";
960
                $DB->query($query) or die("0.7 add default_rubdoc_tracking in glpi_config" . $LANG["update"][90] . $DB->error());
961
        }        
962

    
963
        if (!FieldExists("glpi_users", "deleted")) {
964
                $query = "ALTER TABLE `glpi_users` ADD `deleted` SMALLINT NOT NULL DEFAULT 0 ";
965
                $DB->query($query) or die("0.7 add deleted in glpi_users" . $LANG["update"][90] . $DB->error());
966
                $query = "ALTER TABLE `glpi_users` ADD KEY (`deleted`)";
967
                $DB->query($query) or die("0.7 add key deleted in glpi_users" . $LANG["update"][90] . $DB->error());
968
        }        
969

    
970
        if (!FieldExists("glpi_reservation_item", "active")) {
971
                $query = "ALTER TABLE `glpi_reservation_item` ADD `active` smallint(6) NOT NULL default '1' ";
972
                $DB->query($query) or die("0.7 add active in glpi_reservation_item" . $LANG["update"][90] . $DB->error());
973
        }
974

    
975
        if (!FieldExists("glpi_tracking_planning", "state")) {
976
                $query = "ALTER TABLE `glpi_tracking_planning` ADD `state` smallint(6) NOT NULL default '1' ";
977
                $DB->query($query) or die("0.7 add state in glpi_tracking_planning" . $LANG["update"][90] . $DB->error());
978
                $query="UPDATE `glpi_tracking_planning` SET state='2' WHERE end < NOW()";
979
                $DB->query($query) or die("0.7 update values of state in glpi_tracking_planning" . $LANG["update"][90] . $DB->error());
980
        }
981

    
982
        if (!FieldExists("glpi_reminder", "state")) {
983
                $query = "ALTER TABLE `glpi_reminder` ADD `state` smallint(6) NOT NULL default '0' ";
984
                $DB->query($query) or die("0.7 add state in glpi_reminder" . $LANG["update"][90] . $DB->error());
985
        }
986

    
987

    
988
        if (!FieldExists("glpi_tracking", "recipient")) {
989
                $query = "ALTER TABLE `glpi_tracking` ADD `recipient` INT NOT NULL DEFAULT '0' AFTER `author` ";
990
                $DB->query($query) or die("0.7 add recipient in glpi_tracking" . $LANG["update"][90] . $DB->error());
991
                $query = "UPDATE `glpi_tracking` SET recipient = author";
992
                $DB->query($query) or die("0.7 update recipient in glpi_tracking" . $LANG["update"][90] . $DB->error());
993
                
994
        }
995
        if (!isIndex("glpi_tracking","recipient")){
996
                $query="ALTER TABLE `glpi_tracking` ADD INDEX ( `recipient` ) ";
997
                $DB->query($query) or die("0.7 add recipient index in glpi_tracking" . $LANG["update"][90] . $DB->error());
998
        }
999
        
1000
        if (!FieldExists("glpi_ocs_config", "deconnection_behavior")) {
1001
                $query = "ALTER TABLE `glpi_ocs_config` ADD COLUMN `deconnection_behavior` VARCHAR(45)";
1002
                $DB->query($query) or die("0.7 add state in glpi_reminder" . $LANG["update"][90] . $DB->error());
1003
        }
1004

    
1005
        // Rights
1006
        if (!FieldExists("glpi_profiles", "search_config_global")) {
1007
                $query = "ALTER TABLE `glpi_profiles` ADD COLUMN `search_config_global` char(1) default NULL AFTER `search_config`";
1008
                $DB->query($query) or die("0.7 add search_config_global in glpi_profiles" . $LANG["update"][90] . $DB->error());
1009
                $query = "UPDATE `glpi_profiles` SET `search_config_global` = search_config";
1010
                $DB->query($query) or die("0.7 update search_config_global values in glpi_profiles" . $LANG["update"][90] . $DB->error());
1011
                $query = "UPDATE `glpi_profiles` SET `search_config` = 'w' WHERE interface='central'";
1012
                $DB->query($query) or die("0.7 update search_confi values in glpi_profiles" . $LANG["update"][90] . $DB->error());
1013
        }        
1014
        if (!FieldExists("glpi_profiles", "entity")) {
1015
                $query = "ALTER TABLE `glpi_profiles` ADD COLUMN `entity` char(1) default NULL AFTER `group`";
1016
                $DB->query($query) or die("0.7 add entity in glpi_profiles" . $LANG["update"][90] . $DB->error());
1017
                $query = "UPDATE `glpi_profiles` SET `entity` = config";
1018
                $DB->query($query) or die("0.7 update entity values in glpi_profiles" . $LANG["update"][90] . $DB->error());
1019
        }
1020
        if (!FieldExists("glpi_profiles", "entity_dropdown")) {
1021
                $query = "ALTER TABLE `glpi_profiles` ADD COLUMN `entity_dropdown` char(1) default NULL AFTER `dropdown`";
1022
                $DB->query($query) or die("0.7 add entity_dropdown in glpi_profiles" . $LANG["update"][90] . $DB->error());
1023
                $query = "UPDATE `glpi_profiles` SET `entity_dropdown` = dropdown";
1024
                $DB->query($query) or die("0.7 update entity_dropdown values in glpi_profiles" . $LANG["update"][90] . $DB->error());
1025
        }
1026
        if (!FieldExists("glpi_profiles", "sync_ocsng")) {
1027
                $query = "ALTER TABLE `glpi_profiles` ADD COLUMN `sync_ocsng` char(1) default NULL AFTER `ocsng`";
1028
                $DB->query($query) or die("0.7 add sync_ocsng in glpi_profiles" . $LANG["update"][90] . $DB->error());
1029
                $query = "UPDATE `glpi_profiles` SET `sync_ocsng` = ocsng";
1030
                $DB->query($query) or die("0.7 update sync_ocsng values in glpi_profiles" . $LANG["update"][90] . $DB->error());
1031
        }
1032
        if (!FieldExists("glpi_profiles", "view_ocsng")) {
1033
                $query = "ALTER TABLE `glpi_profiles` ADD COLUMN `view_ocsng` char(1) default NULL AFTER `ocsng`";
1034
                $DB->query($query) or die("0.7 add view_ocsng in glpi_profiles" . $LANG["update"][90] . $DB->error());
1035
                $query = "UPDATE `glpi_profiles` SET `view_ocsng` = 'r' WHERE interface='central'";
1036
                $DB->query($query) or die("0.7 update view_ocsng values in glpi_profiles" . $LANG["update"][90] . $DB->error());
1037
        }
1038
        if (!FieldExists("glpi_profiles", "rule_ldap")) {
1039
                $query = "ALTER TABLE `glpi_profiles` ADD COLUMN `rule_ldap` char(1) default NULL AFTER `config`";
1040
                $DB->query($query) or die("0.7 add rule_ldap in glpi_profiles" . $LANG["update"][90] . $DB->error());
1041
                $query = "UPDATE `glpi_profiles` SET `rule_ldap` = config";
1042
                $DB->query($query) or die("0.7 update rule_ldap values in glpi_profiles" . $LANG["update"][90] . $DB->error());
1043
        }
1044
        if (!FieldExists("glpi_profiles", "rule_ocs")) {
1045
                $query = "ALTER TABLE `glpi_profiles` ADD COLUMN `rule_ocs` char(1) default NULL AFTER `config`";
1046
                $DB->query($query) or die("0.7 add rule_ocs in glpi_profiles" . $LANG["update"][90] . $DB->error());
1047
                $query = "UPDATE `glpi_profiles` SET `rule_ocs` = config";
1048
                $DB->query($query) or die("0.7 update rule_ocs values in glpi_profiles" . $LANG["update"][90] . $DB->error());
1049
        }
1050
        if (!FieldExists("glpi_profiles", "rule_tracking")) {
1051
                $query = "ALTER TABLE `glpi_profiles` ADD COLUMN `rule_tracking` char(1) default NULL AFTER `config`";
1052
                $DB->query($query) or die("0.7 add rule_tracking in glpi_profiles" . $LANG["update"][90] . $DB->error());
1053
                $query = "UPDATE `glpi_profiles` SET `rule_tracking` = config";
1054
                $DB->query($query) or die("0.7 update rule_tracking values in glpi_profiles" . $LANG["update"][90] . $DB->error());
1055
        }
1056
        if (!FieldExists("glpi_profiles", "update_followups")) {
1057
                $query = "ALTER TABLE `glpi_profiles` ADD COLUMN `update_followups` char(1) default NULL AFTER `observe_ticket`";
1058
                $DB->query($query) or die("0.7 add update_followups in glpi_profiles" . $LANG["update"][90] . $DB->error());
1059
                $query = "UPDATE `glpi_profiles` SET `update_followups` = show_full_ticket";
1060
                $DB->query($query) or die("0.7 update update_followups values in glpi_profiles" . $LANG["update"][90] . $DB->error());
1061
        }
1062

    
1063
        //Software version's modifications
1064
        //First add the version field to the licenses table        
1065
        if (!FieldExists("glpi_licenses", "version")) {
1066
                $query = "ALTER TABLE `glpi_licenses` ADD COLUMN `version` varchar(255) default NULL AFTER `sID`";
1067
                $DB->query($query) or die("0.7 add version in glpi_licenses" . $LANG["update"][90] . $DB->error());
1068

    
1069
                $sql = "SELECT ID, version FROM glpi_software";
1070
                $result = $DB->query($sql);
1071
                if ($DB->numrows($result)>0)
1072
                {
1073
                        while ($soft = $DB->fetch_array($result))
1074
                        {
1075
                                $sql = "UPDATE glpi_licenses SET version='".$soft["version"]."' WHERE sID=".$soft["ID"]; 
1076
                                $DB->query($sql);
1077
                        }
1078
                }
1079

    
1080
        }
1081
        
1082
        
1083
        if (FieldExists("glpi_software", "version")) {
1084
                $query = "ALTER TABLE `glpi_software` DROP `version`";
1085
                $DB->query($query) or die("0.7 delete version in glpi_software" . $LANG["update"][90] . $DB->error());
1086
        }
1087

    
1088
        // CLean multiple free / global licenses 
1089
        
1090
        $query=        "SELECT count(*) as CPT, glpi_licenses.*
1091
        FROM `glpi_licenses`
1092
        WHERE `serial` = 'global' OR `serial` = 'free'
1093
        GROUP BY sID, serial, expire, buy
1094
        HAVING CPT > 1";
1095
        $result=$DB->query($query) or die("0.7 check multiple free global licenses " . $LANG["update"][90] . $DB->error());
1096
        if ($DB->numrows($result)){
1097
                while ($data=$DB->fetch_array($result)){
1098
                        // Get licenses AND installations
1099
                        $expire_search="";
1100
                        if ($data['expire']=="")
1101
                                $expire_search=" AND glpi_licenses.expire IS NULL";
1102
                        else $expire_search=" AND glpi_licenses.expire = '".$data['expire']."'";
1103

    
1104
                        $query="SELECT glpi_licenses.ID FROM glpi_licenses 
1105
                                WHERE serial ='".$data['serial']."' AND sID ='".$data['sID']."' $expire_search AND buy ='".$data['buy']."'";
1106
                        $result2=$DB->query($query);
1107
                        if ($DB->numrows($result2)){
1108
                                $licIDs=array();
1109
                                while ($data2=$DB->fetch_array($result2)){
1110
                                        $licIDs[]=$data2['ID'];
1111
                                }
1112
                                if (count($licIDs)>1){
1113
                                        $refID=array_pop($licIDs);
1114
                                        $query="UPDATE glpi_inst_software SET license = '$refID' WHERE license IN (";
1115
                                        $first=true;
1116
                                        foreach ($licIDs as $id){
1117
                                                if ($first) $first=false;
1118
                                                else $query.=",";
1119
                                                $query.=$id;
1120
                                                $query_del="DELETE FROM glpi_licenses WHERE ID = $id";
1121
                                                $DB->query($query_del);
1122
                                        }
1123
                                        $query.=")";
1124
                                        $DB->query($query);
1125
                                }
1126
                        }
1127
                }
1128
        }
1129
        
1130
        // Clean multiple reservation item
1131
        $query=        "SELECT count(*) as CPT, glpi_reservation_item.*
1132
        FROM `glpi_reservation_item`
1133
        GROUP BY device_type, id_device
1134
        HAVING CPT > 1";
1135
        $result=$DB->query($query) or die("0.7 check multiple free global licenses " . $LANG["update"][90] . $DB->error());
1136
        if ($DB->numrows($result)){
1137
                while ($data=$DB->fetch_array($result)){
1138
                        $refID=$data['ID'];
1139
                        // Get duplicates
1140
                        $query2="SELECT * FROM `glpi_reservation_item` WHERE device_type='".$data['device_type']."' AND id_device='".$data['id_device']."' AND ID <> '$refID'";
1141
                        $result2=$DB->query($query2);
1142
                        if ($DB->numrows($result2)){
1143
                                while ($data2=$DB->fetch_array($result2)){
1144
                                        // Update réservations
1145
                                        $query="UPDATE glpi_reservation_resa SET id_item='$refID' WHERE id_item='".$data2['ID']."'";
1146
                                        $DB->query($query);
1147
                                        // Delete Reservation Item 
1148
                                        $query="DELETE FROM `glpi_reservation_item` WHERE ID = '".$data2['ID']."'";
1149
                                        $DB->query($query);
1150
                                }
1151
                        }
1152
                        
1153
                }
1154
        }
1155

    
1156
        if (!FieldExists("glpi_networking_ports", "netmask")) {
1157
                $query = "ALTER TABLE `glpi_networking_ports` ADD COLUMN `netmask` VARCHAR( 255 ) NULL DEFAULT NULL";
1158
                $DB->query($query) or die("0.7 add netmask in glpi_networking_ports" . $LANG["update"][90] . $DB->error());
1159
        }
1160

    
1161
        if (!FieldExists("glpi_networking_ports", "gateway")) {
1162
                $query = "ALTER TABLE `glpi_networking_ports` ADD COLUMN `gateway` VARCHAR( 255 ) NULL DEFAULT NULL";
1163
                $DB->query($query) or die("0.7 add gateway in glpi_networking_ports" . $LANG["update"][90] . $DB->error());
1164
        }
1165
        if (!FieldExists("glpi_networking_ports", "subnet")) {
1166
                $query = "ALTER TABLE `glpi_networking_ports` ADD COLUMN subnet VARCHAR( 255 ) NULL DEFAULT NULL";
1167
                $DB->query($query) or die("0.7 add subnet in glpi_networking_ports" . $LANG["update"][90] . $DB->error());
1168
        }
1169
        if (FieldExists("glpi_networking_ports", "name")) {
1170
                $query = "ALTER TABLE `glpi_networking_ports` CHANGE `name` `name` VARCHAR( 255 ) NULL DEFAULT NULL ,
1171
                                CHANGE `ifaddr` `ifaddr` VARCHAR( 255 ) NULL DEFAULT NULL ,
1172
                                CHANGE `ifmac` `ifmac` VARCHAR( 255 ) NULL DEFAULT NULL ";
1173
                $DB->query($query) or die("0.7 alter networking_ports fields" . $LANG["update"][90] . $DB->error());
1174
        }
1175
        // mailgate
1176
        if (!TableExists("glpi_mailgate")) {
1177
                $query = "CREATE TABLE `glpi_mailgate` (
1178
                `ID` int(11) NOT NULL auto_increment,
1179
                `name` varchar(255) collate utf8_unicode_ci default NULL,
1180
                `FK_entities` int(11) NOT NULL default '0',
1181
                `host` varchar(255) collate utf8_unicode_ci NOT NULL,
1182
                `login` varchar(255) collate utf8_unicode_ci NOT NULL,
1183
                `password` varchar(255) collate utf8_unicode_ci NOT NULL,
1184
                PRIMARY KEY  (`ID`)
1185
                ) ENGINE=MyISAM ;";
1186
                $DB->query($query) or die("0.7 add glpi_mailgate" . $LANG["update"][90] . $DB->error());
1187
                $query = "INSERT INTO `glpi_display` ( `type`, `num`, `rank`, `FK_users`) VALUES (35, 80, 1, 0);";
1188
                $DB->query($query) or die("0.7 add glpi_mailgate display values" . $LANG["update"][90] . $DB->error());
1189
        }
1190

    
1191
        if (!FieldExists("glpi_computers", "os_license_number")) {
1192
                $query = "ALTER TABLE `glpi_computers` ADD COLUMN `os_license_number` VARCHAR( 255 ) NULL DEFAULT NULL AFTER os_sp;";
1193
                $DB->query($query) or die("0.7 alter glpi_computers field" . $LANG["computers"][10] . $DB->error());
1194
        }
1195

    
1196
        if (!FieldExists("glpi_computers", "os_license_id")) {
1197
                $query = "ALTER TABLE `glpi_computers` ADD COLUMN `os_license_id` VARCHAR( 255 ) NULL DEFAULT NULL AFTER os_license_number;";
1198
                $DB->query($query) or die("0.7 alter glpi_computers field" . $LANG["computers"][10] . $DB->error());
1199
        }
1200

    
1201
        if (!FieldExists("glpi_ocs_config", "import_os_serial")) {
1202
                $query = "ALTER TABLE `glpi_ocs_config` ADD `import_os_serial` INT( 2 ) NULL AFTER `import_registry` ;";
1203
                $DB->query($query) or die("0.7 alter glpi_computers field import_ocs_serial " . $DB->error());
1204
        }
1205

    
1206
        if (!FieldExists("glpi_auth_ldap", "use_dn")) {
1207
                $query = "ALTER TABLE `glpi_auth_ldap` ADD `use_dn` INT( 1 ) NOT NULL DEFAULT '1';";
1208
                $DB->query($query) or die("0.7 alter glpi_computers field use_dn " . $DB->error());
1209
        }
1210

    
1211
        if (!FieldExists("glpi_config", "monitors_management_restrict")) {
1212
                $query = "ALTER TABLE `glpi_config` ADD `monitors_management_restrict` INT( 1 ) NOT NULL DEFAULT '2';";
1213
                $DB->query($query) or die("0.7 alter glpi_computers field monitors_management_restrict " . $DB->error());
1214
        }
1215

    
1216
        if (!FieldExists("glpi_config", "phones_management_restrict")) {
1217
                $query = "ALTER TABLE `glpi_config` ADD `phones_management_restrict` INT( 1 ) NOT NULL DEFAULT '2';";
1218
                $DB->query($query) or die("0.7 alter glpi_computers field phones_management_restrict " . $DB->error());
1219
        }
1220

    
1221
        if (!FieldExists("glpi_config", "peripherals_management_restrict")) {
1222
                $query = "ALTER TABLE `glpi_config` ADD `peripherals_management_restrict` INT( 1 ) NOT NULL DEFAULT '2';";
1223
                $DB->query($query) or die("0.7 alter glpi_computers field peripherals_management_restrict " . $DB->error());
1224
        }
1225
        
1226
        if (!FieldExists("glpi_config", "printers_management_restrict")) {
1227
                $query = "ALTER TABLE `glpi_config` ADD `printers_management_restrict` INT( 1 ) NOT NULL DEFAULT '2';";
1228
                $DB->query($query) or die("0.7 alter glpi_computers field printers_management_restrict " . $DB->error());
1229
        }
1230

    
1231
        if (!FieldExists("glpi_config", "licenses_management_restrict")) {
1232
                $query = "ALTER TABLE `glpi_config` ADD `licenses_management_restrict` INT( 1 ) NOT NULL DEFAULT '2';";
1233
                $DB->query($query) or die("0.7 alter glpi_computers field licenses_management_restrict " . $DB->error());
1234
        }
1235

    
1236
        if (!FieldExists("glpi_config", "license_deglobalisation")) {
1237
                $query = "ALTER TABLE `glpi_config` ADD `license_deglobalisation` INT( 1 ) NOT NULL DEFAULT '1';";
1238
                $DB->query($query) or die("0.7 alter glpi_computers field license_deglobalisation " . $DB->error());
1239
        }
1240

    
1241
        if (!FieldExists("glpi_registry", "registry_ocs_name")) {
1242
                $query = "ALTER TABLE `glpi_registry` ADD COLUMN `registry_ocs_name` char(255) NOT NULL default ''";
1243
                $DB->query($query) or die("0.7 add registry_ocs_name in glpi_registry" . $LANG["update"][90] . $DB->error());
1244
        }
1245

    
1246
        if (!FieldExists("glpi_config", "use_errorlog")) {
1247
                $query = "ALTER TABLE `glpi_config` ADD COLUMN `use_errorlog` INT( 1 ) NOT NULL default 0";
1248
                $DB->query($query) or die("0.7 add use_errorlog in glpi_config" . $LANG["update"][90] . $DB->error());
1249
        }
1250

    
1251
        if (!FieldExists("glpi_config", "glpi_timezone")) {
1252
                $query = "ALTER TABLE `glpi_config` ADD COLUMN `glpi_timezone` VARCHAR( 4 ) NOT NULL default 0";
1253
                $DB->query($query) or die("0.7 add glpi_timezone in glpi_config" . $LANG["update"][90] . $DB->error());
1254
        }
1255

    
1256
        if (!FieldExists("glpi_auth_ldap", "timezone")) {
1257
                $query = "ALTER TABLE `glpi_auth_ldap` ADD COLUMN `timezone` VARCHAR( 4 ) NOT NULL default 0";
1258
                $DB->query($query) or die("0.7 add timezone in glpi_auth_ldap" . $LANG["update"][90] . $DB->error());
1259
        }
1260

    
1261
        if (!FieldExists("glpi_ocs_config","glpi_link_enabled"))
1262
        {
1263
                $query="ALTER TABLE `glpi_ocs_config` ADD COLUMN `glpi_link_enabled` int(1) NOT NULL,
1264
                ADD COLUMN `link_ip` int(1) NOT NULL,
1265
                ADD COLUMN `link_name` int(1) NOT NULL,
1266
                ADD COLUMN `link_mac_address` int(1) NOT NULL,
1267
                  ADD COLUMN `link_serial` int(1) NOT NULL,
1268
                  ADD COLUMN `link_if_status` int(11) NOT NULL default '0'";
1269
                  $DB->query($query) or die("0.7 add glpi_link fields in glpi_ocs_config" . $LANG["update"][90] . $DB->error());
1270
        }
1271
        $intnull=array("glpi_alerts" => array("device_type","FK_device","type"),
1272
                "glpi_cartridges_type"=>array("tech_num"),
1273
                "glpi_computers"=>array("FK_users","FK_groups"),
1274
                "glpi_consumables_type"=>array("tech_num"),
1275
                "glpi_contacts"=>array("type"),
1276
                "glpi_device_case"=>array("type"),
1277
                "glpi_device_control"=>array("interface"),
1278
                "glpi_device_drive"=>array("interface"),
1279
                "glpi_dropdown_kbcategories"=>array("level"),
1280
                "glpi_dropdown_locations"=>array("level"),
1281
                "glpi_dropdown_tracking_category"=>array("level"),
1282
                "glpi_entities"=>array("level"),
1283
                "glpi_infocoms"=>array("FK_enterprise","budget"),
1284
                "glpi_monitors"=>array("type","model","FK_users","FK_groups"),
1285
                "glpi_networking"=>array("type","model","firmware","FK_users","FK_groups"),
1286
                "glpi_networking_ports"=>array("iface","netpoint"),
1287
                "glpi_ocs_link"=>array("ocs_server_id"),
1288
                "glpi_peripherals"=>array("model","FK_users","FK_groups"),
1289
                "glpi_phones"=>array("model","FK_users","FK_groups"),
1290
                "glpi_printers"=>array("type","model","FK_users","FK_groups"),
1291
                "glpi_software"=>array("location","platform","FK_users","FK_groups"),
1292
                "glpi_tracking"=>array("computer"),
1293
                "glpi_users_groups"=>array("FK_users","FK_groups"),
1294
                );
1295

    
1296
        foreach ($intnull as $table => $fields){
1297
                foreach ($fields as $field){
1298
                        if (FieldExists($table, $field)) {
1299
                                $query = "UPDATE `$table` SET `$field`=0 WHERE $field IS NULL;";
1300
                                $DB->query($query) or die("0.7 update datas in $table for NULL values " . $DB->error());
1301
                                $query = "ALTER TABLE `$table` CHANGE `$field` `$field` INT NOT NULL DEFAULT '0'";
1302
                                $DB->query($query) or die("0.7 alter $field in $table" . $DB->error());
1303
                        } else {
1304
                                // Error field does not exists : correct it
1305
                                $query = "ALTER TABLE `$table` ADD COLUMN `$field` INT NOT NULL DEFAULT '0'";
1306
                                $DB->query($query) or die("0.7 add $field in $table" . $DB->error());
1307
                        }
1308
                }
1309
        }
1310
        // Clean history
1311
        $query = "DELETE FROM `glpi_history` WHERE `linked_action`=0 AND `device_internal_type`=0 AND `old_value`=`new_value` AND `old_value` IS NOT NULL AND `old_value`!='';";
1312
        $DB->query($query) or die("0.7 clean glpi_history " . $DB->error());
1313

    
1314
        $query = "DELETE FROM `glpi_display` WHERE `type`=".USER_TYPE." AND (`num`=4 );";
1315
        $DB->query($query) or die("0.7 clean glpi_display for glpi_users " . $DB->error());
1316

    
1317
        // Add fields to block auto updates on linked items
1318
        if (!FieldExists("glpi_config", "autoupdate_link_contact")) {
1319
                $query = "ALTER TABLE `glpi_config` ADD COLUMN `autoupdate_link_contact` smallint(6) NOT NULL default '1'";
1320
                $DB->query($query) or die("0.7 add autoupdate_link_contact in glpi_config" . $LANG["update"][90] . $DB->error());
1321
        }
1322
        if (!FieldExists("glpi_config", "autoupdate_link_user")) {
1323
                $query = "ALTER TABLE `glpi_config` ADD COLUMN `autoupdate_link_user` smallint(6) NOT NULL default '1'";
1324
                $DB->query($query) or die("0.7 add autoupdate_link_user in glpi_config" . $LANG["update"][90] . $DB->error());
1325
        }
1326
        if (!FieldExists("glpi_config", "autoupdate_link_group")) {
1327
                $query = "ALTER TABLE `glpi_config` ADD COLUMN `autoupdate_link_group` smallint(6) NOT NULL default '1'";
1328
                $DB->query($query) or die("0.7 add autoupdate_link_group in glpi_config" . $LANG["update"][90] . $DB->error());
1329
        }
1330
        if (!FieldExists("glpi_config", "autoupdate_link_location")) {
1331
                $query = "ALTER TABLE `glpi_config` ADD COLUMN `autoupdate_link_location` smallint(6) NOT NULL default '1'";
1332
                $DB->query($query) or die("0.7 add autoupdate_link_location in glpi_config" . $LANG["update"][90] . $DB->error());
1333
        }
1334

    
1335
        // Flat dropdowntree
1336
        if (!FieldExists("glpi_config", "flat_dropdowntree")) {
1337
                $query = "ALTER TABLE `glpi_config` ADD COLUMN `flat_dropdowntree` smallint(6) NOT NULL default '0'";
1338
                $DB->query($query) or die("0.7 add flat_dropdowntree in glpi_config" . $LANG["update"][90] . $DB->error());
1339
        }
1340
        if (FieldExists("glpi_config", "mailing_signature")) {
1341
                $query = "ALTER TABLE `glpi_config` CHANGE `mailing_signature` `mailing_signature` TEXT NULL ";
1342
                $DB->query($query) or die("0.7 alter mailing signature in glpi_config" . $LANG["update"][90] . $DB->error());
1343
        }
1344

    
1345
//Software categories
1346
        if (!TableExists("glpi_dropdown_software_category"))
1347
        {
1348
                $query="CREATE TABLE `glpi_dropdown_software_category` (
1349
                          `ID` int(11) NOT NULL auto_increment,
1350
                        `name` varchar(255) default NULL,
1351
                          `comments` text,
1352
                          PRIMARY KEY  (`ID`)
1353
                        ) ENGINE=MyISAM ";
1354
                $DB->query($query) or die("0.7 add table glpi_dropdown_software_category" . $LANG["update"][90] . $DB->error());        
1355
        }
1356
        if (!FieldExists("glpi_profiles", "rule_softwarecategories")) {
1357
                $query = "ALTER TABLE `glpi_profiles` ADD COLUMN `rule_softwarecategories` char(1) default NULL AFTER `rule_ldap`";
1358
                $DB->query($query) or die("0.7 add rule_softwarecategories in glpi_profiles" . $LANG["update"][90] . $DB->error());
1359
                $query = "UPDATE `glpi_profiles` SET `rule_softwarecategories` = config";
1360
                $DB->query($query) or die("0.7 update rule_softwarecategories values in glpi_profiles" . $LANG["update"][90] . $DB->error());
1361
        }
1362
        if (!FieldExists("glpi_software", "category")) {
1363
                $query = "ALTER TABLE `glpi_software` ADD `category` INT( 11 ) NOT NULL DEFAULT '0';";
1364
                $DB->query($query) or die("0.7 alter category in glpi_software" . $LANG["update"][90] . $DB->error());
1365
        }
1366

    
1367
        if (!FieldExists("glpi_ocs_config", "import_monitor_comments")) {
1368
                $query = "ALTER TABLE `glpi_ocs_config` ADD `import_monitor_comments` INT( 2 ) NOT NULL DEFAULT '0' AFTER `import_ip`";
1369
                $DB->query($query) or die("0.7 alter import_monitor_comments in glpi_ocs_config" . $LANG["update"][90] . $DB->error());
1370
        }
1371
        
1372
        if (!FieldExists("glpi_ocs_config", "import_software_comments")) {
1373
                $query = "ALTER TABLE `glpi_ocs_config` ADD `import_software_comments` INT NOT NULL DEFAULT '0' AFTER `import_monitor_comments`";
1374
                $DB->query($query) or die("0.7 alter import_software_comments in glpi_ocs_config" . $LANG["update"][90] . $DB->error());
1375
        }
1376

    
1377
        if (FieldExists("glpi_device_gfxcard", "ram")) {
1378
                //Update gfxcard memory management
1379
                $query = "UPDATE glpi_device_gfxcard SET specif_default=ram";
1380
                $DB->query($query) or die("0.7 glpi_device_gfxcard" . $LANG["update"][90] . $DB->error());
1381
                
1382
                $query="ALTER TABLE `glpi_device_gfxcard` DROP `ram`";
1383
                $DB->query($query) or die("0.7 delete 'ram' field from glpi_device_gfxcard" . $LANG["update"][90] . $DB->error());
1384
        }
1385

    
1386
        if (FieldExists("glpi_config", "list_limit")) {
1387
                //Update gfxcard memory management
1388
                $query = "ALTER TABLE `glpi_config` CHANGE `list_limit` `list_limit` INT NULL DEFAULT '20'";
1389
                $DB->query($query) or die("0.7 alter list_limit in config" . $LANG["update"][90] . $DB->error());
1390
        }
1391
        if (!FieldExists("glpi_config", "list_limit_max")) {
1392
                //Update gfxcard memory management
1393
                $query = "ALTER TABLE `glpi_config` ADD `list_limit_max` INT NOT NULL DEFAULT '50' AFTER `list_limit` ;";
1394
                $DB->query($query) or die("0.7 add list_limit_max in config" . $LANG["update"][90] . $DB->error());
1395
        }
1396

    
1397
        if (!FieldExists("glpi_users", "list_limit")) {
1398
                //Update gfxcard memory management
1399
                $query = "ALTER TABLE `glpi_users` ADD `list_limit` INT NOT NULL DEFAULT '20' AFTER `language` ;";
1400
                $DB->query($query) or die("0.7 add list_limit_max in users" . $LANG["update"][90] . $DB->error());
1401
        }
1402

    
1403
        if (!FieldExists("glpi_config", "autoname_entity")) {
1404
                $query = "ALTER TABLE `glpi_config` ADD `autoname_entity` smallint(6) NOT NULL default '1' ";
1405
                $DB->query($query) or die("0.7 add autoname_entity in glpi_config" . $LANG["update"][90] . $DB->error());
1406
        }
1407

    
1408
        if (!FieldExists("glpi_profiles", "rule_tracking")) {
1409
                $query = "ALTER TABLE `glpi_profiles` ADD COLUMN `rule_tracking` char(1) default NULL AFTER `config`";
1410
                $DB->query($query) or die("0.7 add rule_tracking in glpi_profiles" . $LANG["update"][90] . $DB->error());
1411
                $query = "UPDATE `glpi_profiles` SET `rule_tracking` = config";
1412
                $DB->query($query) or die("0.7 update rule_tracking values in glpi_profiles" . $LANG["update"][90] . $DB->error());
1413
        }
1414

    
1415
        if (FieldExists("glpi_profiles", "show_ticket")) {
1416
                $query = "ALTER TABLE `glpi_profiles` CHANGE `show_ticket` `show_all_ticket` CHAR( 1 ) DEFAULT NULL ";
1417
                $DB->query($query) or die("0.7 rename show_ticket to show_all_ticket in glpi_profiles" . $LANG["update"][90] . $DB->error());
1418
        }
1419

    
1420
        if (!FieldExists("glpi_profiles", "show_assign_ticket")) {
1421
                $query = "ALTER TABLE `glpi_profiles` ADD COLUMN `show_assign_ticket` char(1) default NULL AFTER `show_all_ticket`";
1422
                $DB->query($query) or die("0.7 add show_assign_ticket in glpi_profiles" . $LANG["update"][90] . $DB->error());
1423
                $query = "UPDATE `glpi_profiles` SET `show_assign_ticket` = show_all_ticket";
1424
                $DB->query($query) or die("0.7 update show_assign_ticket values in glpi_profiles" . $LANG["update"][90] . $DB->error());
1425
        }
1426

    
1427

    
1428
        if (!FieldExists("glpi_tracking", "assign_group")) {
1429
                $query = "ALTER TABLE `glpi_tracking` ADD `assign_group` INT NOT NULL DEFAULT '0' AFTER `assign_ent` ;";
1430
                $DB->query($query) or die("0.7 add assign_group in tracking" . $LANG["update"][90] . $DB->error());
1431
                $query = "ALTER TABLE `glpi_tracking` ADD INDEX ( `assign_group` ) ;";
1432
                $DB->query($query) or die("0.7 add index on assign_group in tracking" . $LANG["update"][90] . $DB->error());
1433
        }
1434

    
1435
        if (!FieldExists("glpi_config", "expand_soft_categorized")) {
1436
                $query = "ALTER TABLE `glpi_config` ADD `expand_soft_categorized` int(1) NOT NULL DEFAULT '1';";
1437
                $DB->query($query) or die("0.7 add expand_soft_categorized in glpi_config" . $LANG["update"][90] . $DB->error());
1438
        }
1439
        if (!FieldExists("glpi_config", "expand_soft_not_categorized")) {
1440
                $query = "ALTER TABLE `glpi_config` ADD `expand_soft_not_categorized` int(1) NOT NULL DEFAULT '1';";
1441
                $DB->query($query) or die("0.7 add expand_soft_not_categorized in glpi_config" . $LANG["update"][90] . $DB->error());
1442
        }
1443

    
1444
        // Clean history
1445
        $query = "SELECT DISTINCT device_type FROM glpi_history";
1446
        if ($result = $DB->query($query)){
1447
                if ($DB->numrows($result)>0){
1448
                        while ($data = $DB->fetch_array($result)){
1449
                                $query2=" DELETE FROM glpi_history WHERE glpi_history.device_type='".$data['device_type']."' AND
1450
                                        glpi_history.FK_glpi_device NOT IN (SELECT ID FROM ".$LINK_ID_TABLE[$data['device_type']].")";
1451
                                $DB->query($query2);
1452
                        }
1453
                }
1454
        }
1455

    
1456
        if (!TableExists("glpi_transfers")) {
1457
                $query="CREATE TABLE `glpi_transfers` (
1458
                `ID` int(11) NOT NULL auto_increment,
1459
                `name` varchar(255) NOT NULL,
1460
                `keep_tickets` tinyint(4) NOT NULL default '0',
1461
                `keep_networklinks` tinyint(4) NOT NULL default '0',
1462
                `keep_reservations` tinyint(4) NOT NULL default '0',
1463
                `keep_history` tinyint(4) NOT NULL default '0',
1464
                `keep_devices` tinyint(4) NOT NULL default '0',
1465
                `keep_infocoms` tinyint(4) NOT NULL default '0',
1466
                `keep_dc_monitor` tinyint(4) NOT NULL default '0',
1467
                `clean_dc_monitor` tinyint(4) NOT NULL default '0',
1468
                `keep_dc_phone` tinyint(4) NOT NULL default '0',
1469
                `clean_dc_phone` tinyint(4) NOT NULL default '0',
1470
                `keep_dc_peripheral` tinyint(4) NOT NULL default '0',
1471
                `clean_dc_peripheral` tinyint(4) NOT NULL default '0',
1472
                `keep_dc_printer` tinyint(4) NOT NULL default '0',
1473
                `clean_dc_printer` tinyint(4) NOT NULL default '0',
1474
                `keep_enterprises` tinyint(4) NOT NULL default '0',
1475
                `clean_enterprises` tinyint(4) NOT NULL default '0',
1476
                `keep_contacts` tinyint(4) NOT NULL default '0',
1477
                `clean_contacts` tinyint(4) NOT NULL default '0',
1478
                `keep_contracts` tinyint(4) NOT NULL default '0',
1479
                `clean_contracts` tinyint(4) NOT NULL default '0',
1480
                `keep_softwares` tinyint(4) NOT NULL default '0',
1481
                `clean_softwares` tinyint(4) NOT NULL default '0',
1482
                `keep_documents` tinyint(4) NOT NULL default '0',
1483
                `clean_documents` tinyint(4) NOT NULL default '0',
1484
                `keep_cartridges_type` tinyint(4) NOT NULL default '0',
1485
                `clean_cartridges_type` tinyint(4) NOT NULL default '0',
1486
                `keep_cartridges` tinyint(4) NOT NULL default '0',
1487
                `keep_consumables` tinyint(4) NOT NULL default '0',
1488
                PRIMARY KEY  (`ID`)
1489
                ) ENGINE=MyISAM ;";
1490
                $DB->query($query) or die("0.7 add glpi_transfers " . $LANG["update"][90] . $DB->error());
1491
                $query="INSERT INTO glpi_transfers VALUES ('1','complete','2','2','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1');
1492
";
1493
                $DB->query($query) or die("0.7 insert transfer default values" . $LANG["update"][90] . $DB->error());
1494
        }
1495

    
1496
        if (!FieldExists("glpi_profiles", "transfer")) {
1497
                $query = "ALTER TABLE `glpi_profiles` ADD COLUMN `transfer` char(1) default NULL AFTER `entity`";
1498
                $DB->query($query) or die("0.7 add transfer in glpi_profiles" . $LANG["update"][90] . $DB->error());
1499
                $query = "UPDATE `glpi_profiles` SET `transfer` = entity";
1500
                $DB->query($query) or die("0.7 update transfer values in glpi_profiles" . $LANG["update"][90] . $DB->error());
1501
        }
1502

    
1503
        // Need for update from SVN version
1504
        if (!FieldExists("glpi_users", "location")) {
1505
                $query = "ALTER TABLE `glpi_users` ADD `location` int(11) NOT NULL DEFAULT 0;";
1506
                $DB->query($query) or die("0.7 add location in users if not present for compatibility " . $LANG["update"][90] . $DB->error());
1507
        }
1508

    
1509
        if (!FieldExists("glpi_ocs_config", "ocs_url")) {
1510
                $query = "ALTER TABLE `glpi_ocs_config` ADD `ocs_url` VARCHAR( 255 ) NOT NULL ;";
1511
                $DB->query($query) or die("0.7 add ocs_url in glpi_ocs_config if not present for compatibility " . $LANG["update"][90] . $DB->error());
1512
        }
1513

    
1514
        if (!FieldExists("glpi_ocs_link", "ocs_agent_version")) {
1515
                $query = "ALTER TABLE `glpi_ocs_link` ADD `ocs_agent_version` VARCHAR( 255 ) default NULL ;";
1516
                $DB->query($query) or die("0.7 add ocs_agent_version in glpi_ocs_link if not present for compatibility " . $LANG["update"][90] . $DB->error());
1517
        }
1518
        if (!isIndex("glpi_history", "date_mod")) {
1519
                $query = "ALTER TABLE `glpi_history` ADD INDEX ( `date_mod` )";
1520
                $DB->query($query) or die("0.7 alter history add index on date_mod " . $LANG["update"][90] . $DB->error());
1521
        }
1522

    
1523
} // fin 0.7 #####################################################################################
1524
?>
Redmine Appliance - Powered by TurnKey Linux