11
var $is_connected = 0;
16
var $deviceMappingGOsaGlpi;
17
var $deviceMappingTableNameID;
19
function glpiDB($server,$user,$pwd,$db){
20
$this->server = $server;
22
$this->password = $pwd;
25
$this->handle = @mysql_connect($this->server,$this->user,$this->password);
28
$this->is_connected = true;
29
$this->SelectDB($this->db);
31
$this->deviceMappingGOsaGlpi = array(
32
"glpi_device_case" => "case",
33
"glpi_device_control" => "control",
34
"glpi_device_drive" => "drive",
35
"glpi_device_gfxcard" => "gfxcard",
36
"glpi_device_hdd" => "hdd",
37
"glpi_device_iface" => "iface",
38
"glpi_device_moboard" => "moboard",
39
"glpi_device_pci" => "pci",
40
"glpi_device_power" => "power",
41
"glpi_device_processor" => "processor",
42
"glpi_device_ram" => "ram",
43
"glpi_monitors" => "monitor",
44
"glpi_device_sndcard" => "sndcard");
46
$this->deviceMappingTableNameID = array( "moboard" => 1,
64
if($this->is_connected){
65
mysql_select_db($this->db,$this->handle);
70
/* This functions checks if the selected computer/network
71
device is already available in the db
73
function is_account($dn)
75
if(!$this->is_connected){
76
$this->lasterror ="Can't query anything, if we aren't connected.";
79
$qry = "SELECT * FROM glpi_computers WHERE name='".$dn."';";
80
$res = $this->query($qry);
89
/* this function queries everything
93
if(!$this->is_connected){
94
$this->lasterror ="Can't query anything, if we aren't connected.";
98
$res = mysql_query($qry,$this->handle);
100
while($rs = @mysql_fetch_array($res,MYSQL_ASSOC)){
108
Returns all defined system types
110
function getSystemTypes()
112
if($this->is_connected){
114
$tmp = ($this->query("SELECT * FROM glpi_type_computers;"));
116
$ret[$t['ID']]=$t['name'];
121
echo "not connected";
129
function updateSystemType($name,$id)
131
if($this->is_connected){
132
$tmp = $this->query("SELECT * FROM glpi_type_computers WHERE ID=".$id.";");
134
return($this->query("UPDATE glpi_type_computers SET name='".$name."' WHERE ID=".$id.";"));
136
echo "can't update not existing entry";
140
echo "not connected";
146
Add one entry to the system types
148
function addSystemType($name)
150
if($this->is_connected){
151
$tmp = $this->query("SELECT * FROM glpi_type_computers WHERE name='".$name."';");
153
echo "such an entry already exists";
156
return($this->query("INSERT INTO glpi_type_computers (name) VALUES ('".$name."');"));
159
echo "not connected";
165
Remove one entry from the system types (specified by ID=$id)
167
function removeSystemType($id)
169
if($this->is_connected){
170
$tmp = $this->query("SELECT * FROM glpi_type_computers WHERE ID=".$id.";");
172
return($this->query("DELETE FROM glpi_type_computers WHERE ID=".$id.";"));
174
echo "can't remove not existing entry";
178
echo "not connected";
183
/* System type is used */
184
function is_systemTypeUsed($ID){
185
if($this->is_connected){
187
$qry="SELECT name,type FROM glpi_computers WHERE type=".$ID." LIMIT 3;";
188
$res = $this->query($qry);
189
foreach($res as $val){
190
$ret[$val['name']] = $val['name'];
194
echo "not connected";
201
Returns all defined manufacturers
203
function getEnterprises()
205
if($this->is_connected){
207
$tmp = $this->query("SELECT * FROM glpi_enterprises ORDER BY name;");
209
$ret[$t['ID']]=$t['name'];
214
echo "not connected";
220
Returns single manufacturer
222
function getEnterprise($id)
224
if($this->is_connected){
226
$tmp = $this->query("SELECT * FROM glpi_enterprises WHERE ID=".$id.";");
229
echo "not connected";
235
Updates already existing manufacturer
237
function updateEnterprise($array,$id)
239
if(!is_array($array)){
240
echo "updateEnterprisesType: first paraeter must be an array";
241
}elseif($this->is_connected){
242
$tmp = $this->query("SELECT * FROM glpi_enterprises WHERE ID='".$id."';");
244
$atr = array("ID","name","type","address","website","phonenumber","comments","deleted","fax","email");
247
foreach($atr as $at){
248
if(isset($array[$at])){
249
$v .= " ".$at."='".$array[$at]."', ";
253
echo "updateEnterprisesType: no attributes given ";
256
$v = preg_replace("/, $/","",$v);
257
return($this->query("UPDATE glpi_enterprises SET ".$v." WHERE ID='".$id."';"));
260
echo "can't update not existing entry";
264
echo "not connected";
272
function addEnterprise($array)
274
if(!is_array($array)){
275
echo "addUser: first paraeter must be an array";
276
}elseif($this->is_connected){
277
$atr = array("ID","name","type","address","website","phonenumber","comments","deleted","fax","email");
280
foreach($atr as $at){
281
if(isset($array[$at])){
283
$v .= "'".$array[$at]."', ";
287
echo "addUser: no attributes given ";
290
$a = preg_replace("/, $/","",$a);
291
$v = preg_replace("/, $/","",$v);
292
return($this->query("INSERT INTO glpi_enterprises (".$a.") VALUES (".$v.");"));
296
echo "not connected";
305
function removeEnterprise($id)
307
if($this->is_connected){
308
$tmp = $this->query("SELECT * FROM glpi_enterprises WHERE ID=".$id.";");
310
return($this->query("DELETE FROM glpi_enterprises WHERE ID=".$id.";"));
312
echo "can't remove not existing entry";
316
echo "not connected";
324
function getOSTypes($keys = false)
326
if($this->is_connected){
328
$tmp=($this->query("SELECT * FROM glpi_dropdown_os ORDER by name;"));
332
$ret[$t['name']]=$t['ID'];
336
$ret[$t['ID']]=$t['name'];
342
echo "not connected";
347
/* Operating system is used ? */
348
function is_osUsed($ID){
349
if($this->is_connected){
351
$qry="SELECT name,type FROM glpi_computers WHERE os=".$ID." LIMIT 3;";
352
$res = $this->query($qry);
353
foreach($res as $val){
354
$ret[$val['name']] = $val['name'];
358
echo "not connected";
365
Add a new operating system to the dropdown menus
367
function addOS($name)
369
if($this->is_connected){
370
$tmp = $this->query("SELECT * FROM glpi_dropdown_os WHERE name='".$name."';");
372
echo "such an entry already exists";
375
return($this->query("INSERT INTO glpi_dropdown_os (name) VALUES ('".$name."');"));
378
echo "not connected";
386
function removeOS_byID($id)
388
if($this->is_connected){
389
$tmp = $this->query("SELECT * FROM glpi_dropdown_os WHERE ID=".$id.";");
390
if(is_array($tmp[0])){
391
return($this->query("DELETE FROM glpi_dropdown_os WHERE ID=".$id.";"));
393
echo "can't remove not existing entry";
397
echo "not connected";
403
Update existing OS entry
405
function updateOS($name,$id)
407
if($this->is_connected){
408
$tmp = $this->query("SELECT * FROM glpi_dropdown_os WHERE ID=".$id.";");
410
return($this->query("UPDATE glpi_dropdown_os SET name='".$name."' WHERE ID=".$id.";"));
412
echo "can't update not existing entry";
416
echo "not connected";
421
/* This returns all available glpi users
425
if($this->is_connected){
427
$tmp = ($this->query("SELECT * FROM glpi_users"));
428
foreach($tmp as $user){
429
$ret[$user['ID']]=$user['name'];
434
echo "not connected";
439
/* this function adds a new glpi user
441
function addUser($array,$dn)
443
if(!is_array($array)){
444
echo "addUser: first paraeter must be an array";
445
}elseif($this->is_connected){
447
$atr = array("name","phone","email");
450
foreach($atr as $at){
451
if(isset($array[$at])){
453
$v .= "'".$array[$at]."', ";
457
echo "addUser: no attributes given ";
460
$a = preg_replace("/, $/","",$a);
461
$v = preg_replace("/, $/","",$v);
462
return($this->query("INSERT INTO glpi_users (".$a.") VALUES (".$v.");"));
466
echo "not connected";
472
/* This function updates a glpi user
475
function updateUser($array,$dn)
477
if(!is_array($array)){
478
echo "updateUser: first paraeter must be an array";
479
}elseif($this->is_connected){
480
$tmp = $this->query("SELECT * FROM glpi_users WHERE name='".$dn."';");
483
$atr = array("name","phone","email");
485
foreach($atr as $at){
486
if(isset($array[$at])){
487
$v .= " ".$at."='".$array[$at]."', ";
491
echo "UpdateUser: no attributes given ";
494
$v = preg_replace("/, $/","",$v);
495
return($this->query("UPDATE glpi_users SET ".$v." WHERE name='".$dn."';"));
498
echo "can't update not existing entry";
502
echo "not connected";
508
/* This function returns all available data
511
function getComputerInformations($name)
513
if($this->is_connected){
514
$ret = $this->query("SELECT * FROM glpi_computers WHERE name='".$name."';");
517
echo "not connected";
522
/* This fucntions updates an already existing entry
524
function updateComputerInformations($array,$name)
526
if(!is_array($array)){
527
echo "updateComputerInformations: first paraeter must be an array";
528
}elseif($this->is_connected){
529
$tmp = $this->query("SELECT * FROM glpi_computers WHERE name='".$name."';");
532
$atr = array( "ID","name","serial","otherserial","contact","contact_num",
533
"tech_num","comments","date_mod","os","location","domain","network",
534
"model","type","is_template","tplname","FK_glpi_enterprise","deleted");
536
foreach($atr as $at){
537
if(isset($array[$at])){
538
$v .= " ".$at."='".$array[$at]."', ";
542
echo "updateComputerInformations: no attributes given ";
545
$v = preg_replace("/, $/","",$v);
546
return($this->query("UPDATE glpi_computers SET ".$v." WHERE name='".$name."';"));
549
echo "can't update not existing entry";
553
echo "not connected";
559
/* This function adds a new inventory device (computer phone etc)
561
function addComputerInformations($array)
563
if(!is_array($array)){
564
echo "updateComputerInformations: first paraeter must be an array";
565
}elseif($this->is_connected){
566
$atr = array( "ID","name","serial","otherserial","contact","contact_num",
567
"tech_num","comments","date_mod","os","location","domain","network",
568
"model","type","is_template","tplname","FK_glpi_enterprise","deleted");
571
foreach($atr as $at){
572
if(isset($array[$at])){
574
$v .= "'".$array[$at]."', ";
578
echo "updateComputerInformations: no attributes given ";
581
$a = preg_replace("/, $/","",$a);
582
$v = preg_replace("/, $/","",$v);
583
return($this->query("INSERT INTO glpi_computers (".$a.") VALUES (".$v.");"));
587
echo "not connected";
593
/* this functions checks if the given Device
596
function deviceExists($attr)
598
$deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
599
if($this->is_connected){
600
$arr = array_flip($deviceMappingGOsaGlpi);
602
$tbl_name = $arr[$attr['device_type']];
603
if(!isset($attr['ID'])){
606
$qry = "SELECT * FROM ".$tbl_name." WHERE ID=".$attr['ID'].";";
607
$res = $this->query($qry);
608
if(count($res) != 0){
613
echo "not connected";
621
/* Check if given device is used by some accounts
622
* (helpfull to avoid removement of used devices)
624
function is_deviceUsed($item)
626
$deviceMappingGOsaGlpi = array_flip($this->deviceMappingGOsaGlpi);
627
$deviceMappingTableNameID = $this->deviceMappingTableNameID;
628
if($this->is_connected){
629
$tablename = $deviceMappingGOsaGlpi[$item['device_type']];
630
$type = $item['device_type'];
634
if($type=="monitor"){
635
$str = "SELECT c.name FROM glpi_connect_wire as w, glpi_computers as c WHERE w.end1=".$item['ID']." AND w.end2 = c.ID AND w.type=4;";
637
$str = "SELECT c.name FROM glpi_computer_device as d, glpi_computers as c WHERE d.FK_computers=c.ID AND FK_device=".$item['ID']." AND device_type=".$deviceMappingTableNameID[$type]." ;";
640
$res = $this->query($str);
642
foreach($res as $val){
643
$ret[$val['name']] = $val['name'];
646
return($ret);//count($this->query($str)));
648
echo "not connected";
655
/* This functions deletes a specified entry
656
* from our device tables
658
function deleteDevice($attr)
660
$deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
661
if($this->is_connected){
662
$arr = array_flip($deviceMappingGOsaGlpi);
664
$device_type = $attr['device_type'];
665
unset($attr['device_type']);
667
$tbl_name = $arr[$device_type];
669
$this->query("DELETE FROM ".$tbl_name." WHERE ID=".$attr['ID'].";");
671
echo "not connected";
676
/* This funtions updated an already existing device
678
function updateDevices($attr)
680
$deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
681
if($this->is_connected){
682
$arr = array_flip($deviceMappingGOsaGlpi);
684
$device_type = $attr['device_type'];
685
unset($attr['device_type']);
687
$tbl_name = $arr[$device_type];
689
$str = "UPDATE ".$tbl_name." SET ";
690
foreach($attr as $name => $value){
691
$str.=$name."='".$value."', ";
693
$str = preg_replace("/, $/","",$str);
694
$str .= " WHERE ID=".$attr['ID'].";";
697
echo "not connected";
702
/* Returns all possible RAM types
703
* like SDRAM , DIMM .....
705
function getRAMTypes()
707
if($this->is_connected){
709
$tmp = ($this->query("SELECT * FROM glpi_dropdown_ram_type;"));
711
$ret[$t['ID']]=$t['name'];
715
echo "not connected";
720
/* Returns all possible HDD connection types
723
function getGlpiDeviceControlTypes()
725
if($this->is_connected){
727
$tmp = ($this->query("SELECT * FROM glpi_dropdown_hdd_type;"));
729
$ret[$t['ID']]=$t['name'];
733
echo "not connected";
738
/* Returns all possible gfx card connection types
739
* like PCI-X PCI AGP ....
741
function getGlpiGfxControlTypes()
743
if($this->is_connected){
745
$tmp = ($this->query("SELECT * FROM glpi_dropdown_hdd_type;"));
747
$ret[$t['ID']]=$t['name'];
751
echo "not connected";
757
Adds a new single device to our db
759
function addDevice($attr)
761
$deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
762
if($this->is_connected){
763
$arr = array_flip($deviceMappingGOsaGlpi);
765
$device_type = $attr['device_type'];
766
unset($attr['device_type']);
768
$tbl_name = $arr[$device_type];
771
foreach($attr as $name => $value){
773
$v .= "'".$value."', ";
776
echo "addDevice: no attributes given ";
779
$a = preg_replace("/, $/","",$a);
780
$v = preg_replace("/, $/","",$v);
781
return($this->query("INSERT INTO ".$tbl_name." (".$a.") VALUES (".$v.");"));
785
echo "not connected";
790
/* Return all available devices
792
function getDevices()
794
$deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
795
if($this->is_connected){
796
$arr = $deviceMappingGOsaGlpi;
799
foreach($arr as $glpi => $gosa){
800
$qry = "SELECT * FROM ".$glpi.";";
801
$ret = $this->query($qry);
802
foreach($ret as $id => $entry){
803
$entry['device_type'] = $gosa;
805
if(isset($entry['designation'])){
806
$res[$entry['designation']."-".$gosa] = $entry;
808
$res[$entry['name']."-".$gosa] = $entry;
814
echo "not connected";
819
/* This function returns all used devices
821
function getUsedDevices($computerID)
823
$deviceMappingGOsaGlpi = array_flip($this->deviceMappingGOsaGlpi);
824
$deviceMappingTableNameID = $this->deviceMappingTableNameID;
826
if($this->is_connected){
827
$qry = "SELECT * FROM glpi_computer_device WHERE FK_computers=".$computerID.";";
828
$res = $this->query($qry);
831
foreach($deviceMappingGOsaGlpi as $GOsa => $glpi){
832
$ret[$GOsa] = array();
835
$tbls = array_flip($deviceMappingTableNameID);
837
foreach($res as $device){
838
$devtype = $tbls[$device['device_type']];
839
$tbl_name = $deviceMappingGOsaGlpi[$devtype];
840
$qry = ("SELECT * FROM ".$tbl_name." WHERE ID=".$device['FK_device'].";");
841
$res2 = $this->query($qry);
843
$ret[$devtype][$res2[0]['designation']]=$res2[0];
846
$qry = "SELECT * FROM glpi_connect_wire WHERE type=4 AND end2=".$computerID.";";
847
$res2 = $this->query($qry);
848
foreach($res2 as $monitor){
849
$qry = "SELECT * FROM glpi_monitors WHERE ID=".$monitor['end1'].";";
850
$res3 = $this->query($qry);
851
foreach($res3 as $moni){
852
$ret['monitor'][$moni['name']]=$moni;
861
echo "not connected";
866
/* This function removes all given devices from a computer, specified by $id
867
In the next step all devices specified by devices will be added.
869
function addDevicesToComputer($devices, $id)
871
$deviceMappingGOsaGlpi = array_flip($this->deviceMappingGOsaGlpi);
872
$deviceMappingTableNameID = $this->deviceMappingTableNameID;
874
if(($id == "" )||(!is_numeric($id))){
877
if($this->is_connected){
878
$qry = "DELETE FROM glpi_computer_device WHERE FK_computers=".$id.";";
881
foreach($devices as $type => $entries){
882
foreach($entries as $entry){
883
if($type=="monitor"){
884
$str = "INSERT INTO glpi_connect_wire (end1,end2,type)
885
VALUES (".$entry['ID'].",".$id.",4);";
887
$str = "INSERT INTO glpi_computer_device (device_type,FK_device,FK_computers)
888
VALUES (".$deviceMappingTableNameID[$type].",".$entry['ID'].",".$id.");";
896
echo "not connected";
902
function removeComputerInformations($name)
904
if($this->is_connected){
905
$tmp = $this->query("SELECT * FROM glpi_computers WHERE name='".$name."';");
908
$this->query("DELETE FROM glpi_connect_wire WHERE end2=".$id.";");
909
$this->query("DELETE FROM glpi_computer_device WHERE FK_computers=".$id.";");
910
return($this->query("DELETE FROM glpi_computers WHERE ID=".$id.";"));
912
echo "can't remove not existing entry";
916
echo "not connected";
921
function is_connected()
923
return($this->is_connected);
926
function addAttachmentsToComputer($attr,$id)
928
if(($id == "" )||(!is_numeric($id))){
931
if($this->is_connected){
932
$qry = "DELETE FROM glpi_doc_device WHERE (FK_device=".$id.") AND (device_type=1);";
935
foreach($attr as $aid => $entry){
936
$str = "INSERT INTO glpi_doc_device (FK_doc,FK_device,device_type,is_template)
942
echo "not connected";
947
function getAssignAttachments($id)
950
if($this->is_connected){
951
$qry= "SELECT * FROM glpi_doc_device WHERE (device_type=1) AND (FK_device=".$id.");";
952
$ret = $this->query($qry);
955
echo "not connected";
960
function deleteAttachment($id)
962
if($this->is_connected){
963
$qry = "DELETE FROM glpi_docs WHERE ID=".$id."";
966
echo "not connected";
971
function getAttachments()
974
if($this->is_connected){
975
$qry = "SELECT * FROM glpi_docs WHERE name!='';";
976
$re = $this->query($qry);
978
foreach($re as $entry){
979
$ret[$entry['ID']]=$entry;
984
echo "not connected";
989
function saveAttachments($attrs,$id = -1)
991
if($this->is_connected){
992
$atr = array("name","filename","rubrique","mime","date_mod","comment","deleted","link");
994
foreach($atr as $at){
995
if(isset($attrs[$at])){
996
$tmp[$at] = $attrs[$at];
1005
$str = "INSERT INTO glpi_docs ";
1008
foreach($tmp as $name => $value){
1009
$namen .= $name.", ";
1010
if(is_numeric($value)){
1011
$values .= $value.", ";
1013
$values .= "'".$value."', ";
1016
$values = preg_replace("/, $/","",$values);
1017
$namen = preg_replace("/, $/","",$namen);
1018
$str .= "(".$namen.") VALUES (".$values.");";
1020
$str = "UPDATE glpi_docs SET ";
1021
foreach($tmp as $name => $value){
1023
if(is_numeric($value)){
1024
$str .= $value.", ";
1026
$str .= "'".$value."', ";
1029
$str = preg_replace("/, $/","",$str);
1030
$str .= " WHERE ID=".$id.";";
1035
echo "not connected";
1041
/* Check if given attachment id is used in any Device
1042
( - avoid removing of used attachments)
1044
function is_attachmentUsed($id)
1046
if($this->is_connected){
1048
$qry = "SELECT t.name FROM glpi_computers as t, glpi_doc_device WHERE t.ID = glpi_doc_device.FK_device AND FK_doc =".$id." LIMIT 3;";
1049
$res = $this->query($qry);
1050
foreach($res as $val){
1051
$ret[$val['name']] = $val['name'];
1055
echo "not connected";
1063
function getMonitors()
1065
if($this->is_connected){
1066
$qry= "SELECT * FROM glpi_monitors;";
1067
return($this->query($qry));
1070
echo "not connected";
1075
function updatedMonitor()
1077
if($this->is_connected){
1078
// $qry= "SELECT * FROM glpi_monitors;";
1079
// return($this->query($qry));
1082
echo "not connected";
1087
function addMonitor()
1089
if($this->is_connected){
1090
// $qry= "SELECT * FROM glpi_monitors;";
1091
// return($this->query($qry));
1094
echo "not connected";
1099
function removeMonitor($id)
1101
if($this->is_connected){
1102
$qry= "DELETE FROM glpi_monitors WHERE ID=".$id.";";
1105
echo "not connected";
1110
function getMonitorTypes()
1112
if($this->is_connected){
1113
$qry= "SELECT * FROM glpi_type_monitors;";
1114
return($this->query($qry));
1117
echo "not connected";
1122
function getLocationTypes()
1124
if($this->is_connected){
1125
$qry= "SELECT * FROM glpi_dropdown_locations;";
1126
return($this->query($qry));
1129
echo "not connected";
1134
function getStateTypes()
1136
if($this->is_connected){
1137
$qry= "SELECT * FROM glpi_dropdown_state;";
1138
return($this->query($qry));
1140
echo "not connected";
1146
/* Printer functions
1149
/* is printer type used ?
1151
function is_printerTypeUsed($id)
1153
if($this->is_connected){
1154
$qry = "SELECT * FROM glpi_printers WHERE type=".$id.";";
1155
$res = $this->query( $qry);
1157
foreach($res as $entry){
1158
$ret[$entry['ID']] = $entry['name'];
1162
echo "not connected";
1167
/* This functions checks if the selected computer/network
1168
device is already available in the db
1170
function is_printer_account($dn)
1172
if(!$this->is_connected){
1173
$this->lasterror ="Can't query anything, if we aren't connected.";
1176
$qry = "SELECT * FROM glpi_printers WHERE name='".$dn."';";
1177
$res = $this->query($qry);
1186
/* This function returns all available data
1189
function getPrinterInformations($name)
1191
if($this->is_connected){
1192
$ret = $this->query("SELECT * FROM glpi_printers WHERE name='".$name."';");
1195
echo "not connected";
1200
/* Get Printer attachments
1202
function getAssignPrinterAttachments($id)
1205
if($this->is_connected){
1206
$qry= "SELECT * FROM glpi_doc_device WHERE (device_type=3) AND (FK_device=".$id.");";
1207
$ret = $this->query($qry);
1210
echo "not connected";
1216
Returns all defined printer types
1218
function getPrinterTypes()
1220
if($this->is_connected){
1222
$tmp = ($this->query("SELECT * FROM glpi_type_printers ORDER BY name; "));
1223
foreach($tmp as $t){
1224
$ret[$t['ID']]=$t['name'];
1228
echo "not connected";
1233
/* Add pritner types
1234
Add one entry to the printer types
1236
function addPrinterType($name)
1238
if($this->is_connected){
1239
$tmp = $this->query("SELECT * FROM glpi_type_printers WHERE name='".$name."';");
1241
//echo "such an entry already exists";
1244
return($this->query("INSERT INTO glpi_type_printers (name) VALUES ('".$name."');"));
1247
echo "not connected";
1252
/* remove printer types
1253
Remove one entry from the printer types (specified by ID=$id)
1255
function removePrinterType($id)
1257
if($this->is_connected){
1258
$tmp = $this->query("SELECT * FROM glpi_type_printers WHERE ID=".$id.";");
1260
return($this->query("DELETE FROM glpi_type_printers WHERE ID=".$id.";"));
1262
echo "can't remove not existing entry";
1266
echo "not connected";
1271
/* Update printer types
1272
Update a printer type
1274
function updatePrinterType($name,$id)
1277
if($this->is_connected){
1278
$tmp = $this->query("SELECT * FROM glpi_type_printers WHERE ID=".$id.";");
1280
return($this->query("UPDATE glpi_type_printers SET name='".$name."' WHERE ID=".$id.";"));
1282
echo "can't update not existing entry";
1286
echo "not connected";
1292
/* This fucntions updates an already existing entry
1294
function updatePrinterInformations($array,$name)
1296
if(!is_array($array)){
1297
echo "updatePrinterInformations: first paraeter must be an array";
1298
}elseif($this->is_connected){
1299
$tmp = $this->query("SELECT * FROM glpi_printers WHERE name='".$name."';");
1302
$atr = array( "ID","name","serial","otherserial","contact","contact_num",
1303
"tech_num","comments","date_mod","location","domain","network","ramSize","flags_serial","flags_par","flags_usb",
1304
"model","type","is_template","tplname","FK_glpi_enterprise","deleted");
1306
foreach($atr as $at){
1307
if(isset($array[$at])){
1308
$v .= " ".$at."='".$array[$at]."', ";
1312
echo "updateSystemInformations: no attributes given ";
1315
$v = preg_replace("/, $/","",$v);
1316
return($this->query("UPDATE glpi_printers SET ".$v." WHERE name='".$name."';"));
1319
echo "can't update not existing entry";
1323
echo "not connected";
1329
/* This function adds a new inventory settings for printers
1331
function addPrinterInformations($array)
1333
if(!is_array($array)){
1334
echo "updateComputerInformations: first paraeter must be an array";
1335
}elseif($this->is_connected){
1336
$atr = array( "ID","name","serial","otherserial","contact","contact_num",
1337
"tech_num","comments","date_mod","os","location","domain","network","ramSize","flags_serial","flags_par","flags_usb",
1338
"model","type","is_template","tplname","FK_glpi_enterprise","deleted");
1341
foreach($atr as $at){
1342
if(isset($array[$at])){
1344
$v .= "'".$array[$at]."', ";
1348
echo "updateComputerInformations: no attributes given ";
1351
$a = preg_replace("/, $/","",$a);
1352
$v = preg_replace("/, $/","",$v);
1353
return($this->query("INSERT INTO glpi_printers (".$a.") VALUES (".$v.");"));
1357
echo "not connected";
1362
/* add atachment to given printer */
1363
function addAttachmentsToPrinter($attr,$id)
1365
if(($id == "" )||(!is_numeric($id))){
1368
if($this->is_connected){
1369
$qry = "DELETE FROM glpi_doc_device WHERE (FK_device=".$id.") AND (device_type=3);";
1372
foreach($attr as $aid => $entry){
1373
$str = "INSERT INTO glpi_doc_device (FK_doc,FK_device,device_type,is_template)
1379
echo "not connected";
1384
function removePrinterInformations($name)
1386
if($this->is_connected){
1387
$tmp = $this->query("SELECT * FROM glpi_printers WHERE name='".$name."';");
1389
$id = $tmp[0]['ID'];
1390
// $this->query("DELETE FROM glpi_connect_wire WHERE end2=".$id.";");
1391
$this->query("DELETE FROM glpi_doc_device WHERE FK_device=".$id." AND device_type=3;");
1392
return($this->query("DELETE FROM glpi_printers WHERE ID=".$id.";"));
1394
echo "can't remove not existing entry";
1398
echo "not connected";
1406
/* return all assigned cartridges */
1407
function getUsedCartridges($printerID)
1409
if($this->is_connected){
1412
c.date_use as date_use,
1416
c.FK_glpi_printers as FK_glpi_printers,
1419
glpi_dropdown_cartridge_type as d,
1420
glpi_cartridges as c,
1421
glpi_cartridges_type as t
1422
WHERE c.FK_glpi_cartridges_type = t.ID
1424
AND c.FK_glpi_printers = ".$printerID.";";
1425
$res = $this->query($qry);
1426
foreach($res as $entry){
1427
$ret[$entry['ID']] = $entry;
1431
echo "not connected";
1436
/* return all assigned cartridges */
1437
function getAvailableCartridgeTypes($printerTypeID)
1439
if($this->is_connected){
1443
ct.ID as cartridgeID,
1444
ct.name as cartridgeName,
1445
pt.ID as printerTypeID,
1446
pt.name as printerTypeName,
1447
ct.type as cartridgeTypeID,
1448
dt.name as cartridgeTypeName
1450
glpi_type_printers as pt,
1451
glpi_cartridges_type as ct,
1452
glpi_dropdown_cartridge_type as dt,
1453
glpi_cartridges_assoc as ac
1455
ac.FK_glpi_type_printer = pt.ID
1456
AND ac.FK_glpi_cartridges_type = ct.ID
1458
AND pt.ID=".$printerTypeID.";";
1459
$res = $this->query($qry);
1460
foreach($res as $entry){
1461
$ret[$entry['cartridgeID']] = $entry;
1465
echo "not connected";
1470
function removeCartridgeFromPrinter($cartridgeID)
1472
if($this->is_connected){
1473
$qry = "DELETE FROM glpi_cartridges WHERE ID=".$cartridgeID.";";
1474
return($this->query($qry));
1476
echo "not connected";
1481
function addCartridgeFromPrinter($printerID,$cartridgeID)
1483
if($this->is_connected){
1485
glpi_cartridges (FK_glpi_cartridges_type,FK_glpi_printers,date_in,date_use)
1487
(".$cartridgeID.",".$printerID.",'".date("Y-m-d")."','".date("Y-m-d")."');";
1488
return($this->query($qry));
1490
echo "not connected";
1495
function is_cartridgeTypeUsed($id){
1496
if($this->is_connected){
1497
$qry = "SELECT p.ID,p.name as name FROM glpi_cartridges as c,glpi_printers as p WHERE p.ID=c.FK_glpi_printers AND c.FK_glpi_cartridges_type=".$id.";";
1498
$res = $this->query($qry);
1500
foreach($res as $entry){
1501
$ret[$entry['ID']] = $entry['name'];
1505
echo "not connected";
1510
function getCartridgeTypeInformations($id = "all"){
1511
if($this->is_connected){
1514
$qry = "SELECT * FROM glpi_cartridges_type WHERE ID = ".$id.";";
1516
$qry = "SELECT * FROM glpi_cartridges_type;";
1519
$res = ($this->query($qry));
1520
foreach($res as $entry){
1521
$ret[$entry['ID']] = $entry;
1526
echo "not connected";
1531
function getCartridgeTypes(){
1532
if($this->is_connected){
1534
$qry = "SELECT * FROM glpi_dropdown_cartridge_type;";
1535
$res = ($this->query($qry));
1536
foreach($res as $entry){
1537
$ret[$entry['ID']] = $entry['name'];
1542
echo "not connected";
1549
/* check if given manufacturer ID ist still in use.
1550
The problem is, that nearly every table uses manufacturers ....
1552
function is_manufacturerUsed($id)
1554
if($this->is_connected){
1556
foreach($this->deviceMappingGOsaGlpi as $entry => $table){
1559
$tables[] ="glpi_computers";
1560
$tables[] ="glpi_cartridges_type";
1563
foreach($tables as $tbl){
1564
if($i <= 0 ) continue;
1565
$qry = "SELECT * FROM ".$tbl." WHERE FK_glpi_enterprise = ".$id.";";
1566
$res = $this->query($qry);
1567
foreach($res as $entry){
1568
if($i <= 0 ) continue;
1569
if(isset($entry['designation'])){
1570
$entry['name'] = $entry['designation'];
1573
$ret[] = $entry['name'];
1578
echo "not connected";
1584
Updates already existing manufacturer
1586
function Add_UpdateCatrigdeType($array,$array_printer_types)
1588
if(!is_array($array)){
1589
echo "Add_UpdateCatrigdeType: first paraeter must be an array";
1590
}elseif($this->is_connected){
1593
$atr = array("name","ref","location","type","FK_glpi_enterprise","tech_num","deleted","comments","alarm");
1595
/* Entry was edited */
1597
$qry = "DELETE FROM glpi_cartridges_assoc WHERE FK_glpi_cartridges_type=".$array['ID'].";";
1600
foreach($atr as $at){
1601
if(isset($array[$at])){
1602
$v .= " ".$at."='".$array[$at]."', ";
1606
echo "Add_UpdateCatrigdeType: no attributes given ";
1609
$v = preg_replace("/, $/","",$v);
1610
$qry = "UPDATE glpi_cartridges_type SET ".$v." WHERE ID='".$array['ID']."';";
1615
/* skip if name is in use*/
1616
$qry = "SELECT * FROM glpi_cartridges_type WHERE name='".$array['name']."';";
1617
if(count($this->query($qry))){
1621
$str = "INSERT INTO glpi_cartridges_type ";
1624
foreach($array as $name => $value){
1625
$namen .= $name.", ";
1626
if(is_numeric($value)){
1627
$values .= $value.", ";
1629
$values .= "'".$value."', ";
1632
$values = preg_replace("/, $/","",$values);
1633
$namen = preg_replace("/, $/","",$namen);
1634
$str .= "(".$namen.") VALUES (".$values.");";
1636
$IDs = $this->query("SELECT ID FROM glpi_cartridges_type WHERE name='".$array['name']."';");
1637
if(count($IDs) > 1){
1638
echo "internal db error";
1641
$array['ID'] = $IDs[0]['ID'];
1644
foreach($array_printer_types as $id){
1645
$qry = "INSERT INTO glpi_cartridges_assoc
1646
(FK_glpi_cartridges_type,FK_glpi_type_printer)
1648
(".$array['ID'].",".$id.")";
1653
echo "not connected";
1658
function getSupportedPrinterTypeIDsForCartridge($cid)
1660
if($this->is_connected){
1662
$qry = "SELECT FK_glpi_type_printer FROM glpi_cartridges_assoc WHERE FK_glpi_cartridges_type = ".$cid.";";
1663
$res = $this->query($qry);
1665
foreach($res as $entry => $value){
1666
$ret[$value['FK_glpi_type_printer']] = $value['FK_glpi_type_printer'];
1670
echo "not connected";
1675
function removeCartridgeType($id){
1676
if($this->is_connected){
1677
$qry = "DELETE FROM glpi_cartridges_assoc WHERE FK_glpi_cartridges_type=".$id.";";
1679
$qry = "DELETE FROM glpi_cartridges_type WHERE ID=".$id.";";
1680
return($this->query($qry));
1682
echo "not connected";
1687
function getCartridgesWhichUseThisType($id)
1689
if($this->is_connected){
1690
$qry = "SELECT * FROM glpi_cartridges WHERE FK_glpi_cartridges_type=".$id.";";
1691
$ret = $this->query($qry);
1694
echo "not connected";
1700
/* Add pritner types
1701
Add one entry to the cartridgeType types
1703
function addCartridgeDropdownType($name)
1705
if($this->is_connected){
1706
$tmp = $this->query("SELECT * FROM glpi_dropdown_cartridge_type WHERE name='".$name."';");
1708
//echo "such an entry already exists";
1711
return($this->query("INSERT INTO glpi_dropdown_cartridge_type (name) VALUES ('".$name."');"));
1714
echo "not connected";
1719
/* remove cartridgeType types
1720
Remove one entry from the cartridgeType types (specified by ID=$id)
1722
function removeCartridgeDropdownType($id)
1724
if($this->is_connected){
1725
$tmp = $this->query("SELECT * FROM glpi_dropdown_cartridge_type WHERE ID=".$id.";");
1727
return($this->query("DELETE FROM glpi_dropdown_cartridge_type WHERE ID=".$id.";"));
1729
echo "can't remove not existing entry";
1733
echo "not connected";
1738
/* Update cartridgeType
1739
Update a cartridgeType
1741
function updateCartridgeDropdownType($name,$id)
1744
if($this->is_connected){
1745
$tmp = $this->query("SELECT * FROM glpi_dropdown_cartridge_type WHERE ID=".$id.";");
1747
return($this->query("UPDATE glpi_dropdown_cartridge_type SET name='".$name."' WHERE ID=".$id.";"));
1749
echo "can't update not existing entry";
1753
echo "not connected";
1758
function getUsedDropdownTypes($id=false)
1760
if($this->is_connected){
1762
$qry = "SELECT distinct(type) FROM glpi_cartridges_type WHERE type = ".$id.";";
1764
$qry = "SELECT distinct(type) FROM glpi_cartridges_type;";
1766
return($this->query($qry));
1768
echo "not connected";
1774
//$s = new glpiDB("vserver-01","glpi","tester","glpi");
1775
//print_r($s->query("SELECT * FROM glpi_computers"));
1776
//$s->getComputerInformations("1 OR (c.ID<10000)");