1 <?php
4 class glpiDB{
6 var $user ="";
7 var $password ="";
8 var $server ="";
9 var $db ="";
11 var $is_connected = 0;
12 var $handle = NULL;
14 var $lasterror ="";
16 var $deviceMappingGOsaGlpi;
17 var $deviceMappingTableNameID;
19 function glpiDB($server,$user,$pwd,$db){
20 $this->server = $server;
21 $this->user = $user;
22 $this->password = $pwd;
23 $this->db = $db;
25 $this->handle = @mysql_connect($this->server,$this->user,$this->password);
27 if($this->handle){
28 $this->is_connected = true;
29 $this->SelectDB($this->db);
30 }
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,
47 "processor" => 2,
48 "ram" => 3,
49 "hdd" => 4,
50 "iface" => 5,
51 "drive" => 6,
52 "control" => 7,
53 "gfxcard" => 8,
54 "sndcard" => 9,
55 "pci" => 10,
56 "case" => 11,
57 "power" => 12);
60 }
62 function SelectDB()
63 {
64 if($this->is_connected){
65 mysql_select_db($this->db,$this->handle);
66 }
67 }
70 /* This functions checks if the selected computer/network
71 device is already available in the db
72 */
73 function is_account($dn)
74 {
75 if(!$this->is_connected){
76 $this->lasterror ="Can't query anything, if we aren't connected.";
77 return(false);
78 }else{
79 $qry = "SELECT * FROM glpi_computers WHERE name='".$dn."';";
80 $res = $this->query($qry);
81 if(count($res)==0){
82 return(false);
83 }else{
84 return(true);
85 }
86 }
87 }
89 /* this function queries everything
90 */
91 function query($qry)
92 {
93 if(!$this->is_connected){
94 $this->lasterror ="Can't query anything, if we aren't connected.";
95 return(false);
96 }else{
97 $ret =array();
98 $res = mysql_query($qry,$this->handle);
100 while($rs = @mysql_fetch_array($res,MYSQL_ASSOC)){
101 $ret[]=$rs;
102 }
103 return($ret);
104 }
105 }
107 /* System types
108 Returns all defined system types
109 */
110 function getSystemTypes()
111 {
112 if($this->is_connected){
113 $ret = array();
114 $tmp = ($this->query("SELECT * FROM glpi_type_computers;"));
115 foreach($tmp as $t){
116 $ret[$t['ID']]=$t['name'];
117 }
118 return($ret);
119 }else{
120 echo "not connected";
121 return(false);
122 }
123 }
125 /* System types
126 Update a system type
127 */
128 function updateSystemType($name,$id)
129 {
131 if($this->is_connected){
132 $tmp = $this->query("SELECT * FROM glpi_type_computers WHERE ID=".$id.";");
133 if(isset($tmp[0])){
134 return($this->query("UPDATE glpi_type_computers SET name='".$name."' WHERE ID=".$id.";"));
135 }else{
136 echo "can't update not existing entry";
137 return(false);
138 }
139 }else{
140 echo "not connected";
141 return(false);
142 }
143 }
145 /* System types
146 Add one entry to the system types
147 */
148 function addSystemType($name)
149 {
150 if($this->is_connected){
151 $tmp = $this->query("SELECT * FROM glpi_type_computers WHERE name='".$name."';");
152 if(isset($tmp[0])){
153 echo "such an entry already exists";
154 return(false);
155 }else{
156 return($this->query("INSERT INTO glpi_type_computers (name) VALUES ('".$name."');"));
157 }
158 }else{
159 echo "not connected";
160 return(false);
161 }
162 }
164 /* System types
165 Remove one entry from the system types (specified by ID=$id)
166 */
167 function removeSystemType($id)
168 {
169 if($this->is_connected){
170 $tmp = $this->query("SELECT * FROM glpi_type_computers WHERE ID=".$id.";");
171 if(isset($tmp[0])){
172 return($this->query("DELETE FROM glpi_type_computers WHERE ID=".$id.";"));
173 }else{
174 echo "can't remove not existing entry";
175 return(false);
176 }
177 }else{
178 echo "not connected";
179 return(false);
180 }
181 }
183 /* Manufacturer
184 Returns all defined manufacturers
185 */
186 function getEnterprises()
187 {
188 if($this->is_connected){
189 $ret = array();
190 $tmp = $this->query("SELECT * FROM glpi_enterprises;");
191 foreach($tmp as $t){
192 $ret[$t['ID']]=$t['name'];
193 }
194 return($ret);
195 }else{
196 echo "not connected";
197 return(false);
198 }
199 }
201 /* Manufacturer
202 Returns single manufacturer
203 */
204 function getEnterprise($id)
205 {
206 if($this->is_connected){
207 $ret = array();
208 $tmp = $this->query("SELECT * FROM glpi_enterprises WHERE ID=".$id.";");
209 return($tmp);
210 }else{
211 echo "not connected";
212 return(false);
213 }
214 }
216 /* Manufacturer
217 Updates already existing manufacturer
218 */
219 function updateEnterprise($array,$id)
220 {
221 if(!is_array($array)){
222 echo "updateEnterprisesType: first paraeter must be an array";
223 }elseif($this->is_connected){
224 $tmp = $this->query("SELECT * FROM glpi_enterprises WHERE ID='".$id."';");
225 if(isset($tmp[0])){
226 $atr = array("ID","name","type","address","website","phonenumber","comments","deleted","fax","email");
228 $v = "";
229 foreach($atr as $at){
230 if(isset($array[$at])){
231 $v .= " ".$at."='".$array[$at]."', ";
232 }
233 }
234 if(empty($v)){
235 echo "updateEnterprisesType: no attributes given ";
236 return(false);
237 }else{
238 $v = preg_replace("/, $/","",$v);
239 return($this->query("UPDATE glpi_enterprises SET ".$v." WHERE ID='".$id."';"));
240 }
241 }else{
242 echo "can't update not existing entry";
243 return(false);
244 }
245 }else{
246 echo "not connected";
247 return(false);
248 }
249 }
251 /* Manufacturer
252 Add new manufacturer
253 */
254 function addEnterprise($array)
255 {
256 if(!is_array($array)){
257 echo "addUser: first paraeter must be an array";
258 }elseif($this->is_connected){
259 $atr = array("ID","name","type","address","website","phonenumber","comments","deleted","fax","email");
260 $v = "";
261 $a = "";
262 foreach($atr as $at){
263 if(isset($array[$at])){
264 $a .= $at.", ";
265 $v .= "'".$array[$at]."', ";
266 }
267 }
268 if(empty($v)){
269 echo "addUser: no attributes given ";
270 return(false);
271 }else{
272 $a = preg_replace("/, $/","",$a);
273 $v = preg_replace("/, $/","",$v);
274 return($this->query("INSERT INTO glpi_enterprises (".$a.") VALUES (".$v.");"));
275 }
277 }else{
278 echo "not connected";
279 return(false);
280 }
282 }
284 /* Manufacturer
285 remove manufacturer
286 */
287 function removeEnterprise($id)
288 {
289 if($this->is_connected){
290 $tmp = $this->query("SELECT * FROM glpi_enterprises WHERE ID=".$id.";");
291 if(isset($tmp[0])){
292 return($this->query("DELETE FROM glpi_enterprises WHERE ID=".$id.";"));
293 }else{
294 echo "can't remove not existing entry";
295 return(false);
296 }
297 }else{
298 echo "not connected";
299 return(false);
300 }
301 }
303 /* Operating systems
304 Returns all OSs
305 */
306 function getOSTypes()
307 {
308 if($this->is_connected){
309 $ret = array();
310 $tmp=($this->query("SELECT * FROM glpi_dropdown_os;"));
312 foreach($tmp as $t){
313 $ret[$t['ID']]=$t['name'];
314 }
316 return($ret);
318 }else{
319 echo "not connected";
320 return(false);
321 }
322 }
324 /* Operating systems
325 Add a new operating system to the dropdown menus
326 */
327 function addOS($name)
328 {
329 if($this->is_connected){
330 $tmp = $this->query("SELECT * FROM glpi_dropdown_os WHERE name='".$name."';");
331 if(isset($tmp[0])){
332 echo "such an entry already exists";
333 return(false);
334 }else{
335 return($this->query("INSERT INTO glpi_dropdown_os (name) VALUES ('".$name."');"));
336 }
337 }else{
338 echo "not connected";
339 return(false);
340 }
341 }
343 /* Operating systems
344 remove one OS entry
345 */
346 function removeOS_byID($id)
347 {
348 if($this->is_connected){
349 $tmp = $this->query("SELECT * FROM glpi_dropdown_os WHERE ID=".$id.";");
350 if(is_array($tmp[0])){
351 return($this->query("DELETE FROM glpi_dropdown_os WHERE ID=".$id.";"));
352 }else{
353 echo "can't remove not existing entry";
354 return(false);
355 }
356 }else{
357 echo "not connected";
358 return(false);
359 }
360 }
362 /* Operating systems
363 Update existing OS entry
364 */
365 function updateOS($name,$id)
366 {
368 if($this->is_connected){
369 $tmp = $this->query("SELECT * FROM glpi_dropdown_os WHERE ID=".$id.";");
370 if(isset($tmp[0])){
371 return($this->query("UPDATE glpi_dropdown_os SET name='".$name."' WHERE ID=".$id.";"));
372 }else{
373 echo "can't update not existing entry";
374 return(false);
375 }
376 }else{
377 echo "not connected";
378 return(false);
379 }
380 }
382 /* This returns all available glpi users
383 */
384 function getUsers()
385 {
386 if($this->is_connected){
387 $ret = array();
388 $tmp = ($this->query("SELECT * FROM glpi_users"));
389 foreach($tmp as $user){
390 $ret[$user['ID']]=$user['name'];
391 }
392 return($ret);
394 }else{
395 echo "not connected";
396 return(false);
397 }
398 }
400 /* this function adds a new glpi user
401 */
402 function addUser($array,$dn)
403 {
404 if(!is_array($array)){
405 echo "addUser: first paraeter must be an array";
406 }elseif($this->is_connected){
407 $array['name']=$dn;
408 $atr = array("name","phone","email");
409 $v = "";
410 $a = "";
411 foreach($atr as $at){
412 if(isset($array[$at])){
413 $a .= $at.", ";
414 $v .= "'".$array[$at]."', ";
415 }
416 }
417 if(empty($v)){
418 echo "addUser: no attributes given ";
419 return(false);
420 }else{
421 $a = preg_replace("/, $/","",$a);
422 $v = preg_replace("/, $/","",$v);
423 return($this->query("INSERT INTO glpi_users (".$a.") VALUES (".$v.");"));
424 }
426 }else{
427 echo "not connected";
428 return(false);
429 }
431 }
433 /* This function updates a glpi user
434 with the given data
435 */
436 function updateUser($array,$dn)
437 {
438 if(!is_array($array)){
439 echo "updateUser: first paraeter must be an array";
440 }elseif($this->is_connected){
441 $tmp = $this->query("SELECT * FROM glpi_users WHERE name='".$dn."';");
442 if(isset($tmp[0])){
444 $atr = array("name","phone","email");
445 $v = "";
446 foreach($atr as $at){
447 if(isset($array[$at])){
448 $v .= " ".$at."='".$array[$at]."', ";
449 }
450 }
451 if(empty($v)){
452 echo "UpdateUser: no attributes given ";
453 return(false);
454 }else{
455 $v = preg_replace("/, $/","",$v);
456 return($this->query("UPDATE glpi_users SET ".$v." WHERE name='".$dn."';"));
457 }
458 }else{
459 echo "can't update not existing entry";
460 return(false);
461 }
462 }else{
463 echo "not connected";
464 return(false);
465 }
467 }
469 /* This function returns all available data
470 from a specified dn
471 */
472 function getComputerInformations($name)
473 {
474 if($this->is_connected){
475 $ret = $this->query("SELECT * FROM glpi_computers WHERE name='".$name."';");
476 return($ret);
477 }else{
478 echo "not connected";
479 return(false);
480 }
481 }
483 /* This fucntions updates an already existing entry
484 */
485 function updateComputerInformations($array,$name)
486 {
487 if(!is_array($array)){
488 echo "updateComputerInformations: first paraeter must be an array";
489 }elseif($this->is_connected){
490 $tmp = $this->query("SELECT * FROM glpi_computers WHERE name='".$name."';");
491 if(isset($tmp[0])){
493 $atr = array( "ID","name","serial","otherserial","contact","contact_num",
494 "tech_num","comments","date_mod","os","location","domain","network",
495 "model","type","is_template","tplname","FK_glpi_enterprise","deleted");
496 $v = "";
497 foreach($atr as $at){
498 if(isset($array[$at])){
499 $v .= " ".$at."='".$array[$at]."', ";
500 }
501 }
502 if(empty($v)){
503 echo "updateComputerInformations: no attributes given ";
504 return(false);
505 }else{
506 $v = preg_replace("/, $/","",$v);
507 return($this->query("UPDATE glpi_computers SET ".$v." WHERE name='".$name."';"));
508 }
509 }else{
510 echo "can't update not existing entry";
511 return(false);
512 }
513 }else{
514 echo "not connected";
515 return(false);
516 }
518 }
520 /* This function adds a new inventory device (computer phone etc)
521 */
522 function addComputerInformations($array)
523 {
524 if(!is_array($array)){
525 echo "updateComputerInformations: first paraeter must be an array";
526 }elseif($this->is_connected){
527 $atr = array( "ID","name","serial","otherserial","contact","contact_num",
528 "tech_num","comments","date_mod","os","location","domain","network",
529 "model","type","is_template","tplname","FK_glpi_enterprise","deleted");
530 $v = "";
531 $a = "";
532 foreach($atr as $at){
533 if(isset($array[$at])){
534 $a .= $at.", ";
535 $v .= "'".$array[$at]."', ";
536 }
537 }
538 if(empty($v)){
539 echo "updateComputerInformations: no attributes given ";
540 return(false);
541 }else{
542 $a = preg_replace("/, $/","",$a);
543 $v = preg_replace("/, $/","",$v);
544 return($this->query("INSERT INTO glpi_computers (".$a.") VALUES (".$v.");"));
545 }
547 }else{
548 echo "not connected";
549 return(false);
550 }
552 }
554 /* this functions checks if the given Device
555 * already exists
556 */
557 function deviceExists($attr)
558 {
559 $deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
560 if($this->is_connected){
561 $arr = array_flip($deviceMappingGOsaGlpi);
563 $tbl_name = $arr[$attr['device_type']];
564 if(!isset($attr['ID'])){
565 return(false);
566 }else{
567 $qry = "SELECT * FROM ".$tbl_name." WHERE ID=".$attr['ID'].";";
568 $res = $this->query($qry);
569 if(count($res) != 0){
570 return(true);
571 }
572 }
573 }else{
574 echo "not connected";
575 return(false);
576 }
578 return(false);
579 }
581 /* This functions deletes a specified entry
582 * from our device tables
583 */
584 function deleteDevice($attr)
585 {
586 $deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
587 if($this->is_connected){
588 $arr = array_flip($deviceMappingGOsaGlpi);
590 $device_type = $attr['device_type'];
591 unset($attr['device_type']);
593 $tbl_name = $arr[$device_type];
595 $this->query("DELETE FROM ".$tbl_name." WHERE ID=".$attr['ID'].";");
596 }else{
597 echo "not connected";
598 return(false);
599 }
600 }
602 /* This funtions updated an already existing device
603 */
604 function updateDevices($attr)
605 {
606 $deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
607 if($this->is_connected){
608 $arr = array_flip($deviceMappingGOsaGlpi);
610 $device_type = $attr['device_type'];
611 unset($attr['device_type']);
613 $tbl_name = $arr[$device_type];
615 $str = "UPDATE ".$tbl_name." SET ";
616 foreach($attr as $name => $value){
617 $str.=$name."='".$value."', ";
618 }
619 $str = preg_replace("/, $/","",$str);
620 $str .= " WHERE ID=".$attr['ID'].";";
621 $this->query($str);
622 }else{
623 echo "not connected";
624 return(false);
625 }
626 }
628 /* Returns all possible RAM types
629 * like SDRAM , DIMM .....
630 */
631 function getRAMTypes()
632 {
633 if($this->is_connected){
634 $ret = array();
635 $tmp = ($this->query("SELECT * FROM glpi_dropdown_ram_type;"));
636 foreach($tmp as $t){
637 $ret[$t['ID']]=$t['name'];
638 }
639 return($ret);
640 }else{
641 echo "not connected";
642 return(false);
643 }
644 }
646 /* Returns all possible HDD connection types
647 * like IDE SCSI ...
648 */
649 function getGlpiDeviceControlTypes()
650 {
651 if($this->is_connected){
652 $ret = array();
653 $tmp = ($this->query("SELECT * FROM glpi_dropdown_hdd_type;"));
654 foreach($tmp as $t){
655 $ret[$t['ID']]=$t['name'];
656 }
657 return($ret);
658 }else{
659 echo "not connected";
660 return(false);
661 }
662 }
664 /* Returns all possible gfx card connection types
665 * like PCI-X PCI AGP ....
666 */
667 function getGlpiGfxControlTypes()
668 {
669 if($this->is_connected){
670 $ret = array();
671 $tmp = ($this->query("SELECT * FROM glpi_dropdown_hdd_type;"));
672 foreach($tmp as $t){
673 $ret[$t['ID']]=$t['name'];
674 }
675 return($ret);
676 }else{
677 echo "not connected";
678 return(false);
679 }
680 }
682 /* Devices
683 Adds a new single device to our db
684 */
685 function addDevice($attr)
686 {
687 $deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
688 if($this->is_connected){
689 $arr = array_flip($deviceMappingGOsaGlpi);
691 $device_type = $attr['device_type'];
692 unset($attr['device_type']);
694 $tbl_name = $arr[$device_type];
695 $v = "";
696 $a = "";
697 foreach($attr as $name => $value){
698 $a .= $name.", ";
699 $v .= "'".$value."', ";
700 }
701 if(empty($v)){
702 echo "addDevice: no attributes given ";
703 return(false);
704 }else{
705 $a = preg_replace("/, $/","",$a);
706 $v = preg_replace("/, $/","",$v);
707 return($this->query("INSERT INTO ".$tbl_name." (".$a.") VALUES (".$v.");"));
708 }
710 }else{
711 echo "not connected";
712 return(false);
713 }
714 }
716 /* Return all available devices
717 */
718 function getDevices()
719 {
720 $deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
721 if($this->is_connected){
722 $arr = $deviceMappingGOsaGlpi;
724 $res = array();
725 foreach($arr as $glpi => $gosa){
726 $qry = "SELECT * FROM ".$glpi.";";
727 $ret = $this->query($qry);
728 foreach($ret as $id => $entry){
729 $entry['device_type'] = $gosa;
731 if(isset($entry['designation'])){
732 $res[$entry['designation']."-".$gosa] = $entry;
733 }else{
734 $res[$entry['name']."-".$gosa] = $entry;
735 }
736 }
737 }
738 return($res);
739 }else{
740 echo "not connected";
741 return(false);
742 }
743 }
745 /* This function returns all used devices
746 */
747 function getUsedDevices($computerID)
748 {
749 $deviceMappingGOsaGlpi = array_flip($this->deviceMappingGOsaGlpi);
750 $deviceMappingTableNameID = $this->deviceMappingTableNameID;
752 if($this->is_connected){
753 $qry = "SELECT * FROM glpi_computer_device WHERE FK_computers=".$computerID.";";
754 $res = $this->query($qry);
756 $ret = array();
757 foreach($deviceMappingGOsaGlpi as $GOsa => $glpi){
758 $ret[$GOsa] = array();
759 }
761 $tbls = array_flip($deviceMappingTableNameID);
763 foreach($res as $device){
764 $devtype = $tbls[$device['device_type']];
765 $tbl_name = $deviceMappingGOsaGlpi[$devtype];
766 $qry = ("SELECT * FROM ".$tbl_name." WHERE ID=".$device['FK_device'].";");
767 $res2 = $this->query($qry);
768 if(count($res2)!=0){
769 $ret[$devtype][$res2[0]['designation']]=$res2[0];
770 }
772 $qry = "SELECT * FROM glpi_connect_wire WHERE type=4 AND end2=".$computerID.";";
773 $res2 = $this->query($qry);
774 foreach($res2 as $monitor){
775 $qry = "SELECT * FROM glpi_monitors WHERE ID=".$monitor['end1'].";";
776 $res3 = $this->query($qry);
777 foreach($res3 as $moni){
778 $ret['monitor'][$moni['name']]=$moni;
779 }
780 }
784 }
785 return($ret);
786 }else{
787 echo "not connected";
788 return(false);
789 }
790 }
792 /* This function removes all given devices from a computer, specified by $id
793 In the next step all devices specified by devices will be added.
794 */
795 function addDevicesToComputer($devices, $id)
796 {
797 $deviceMappingGOsaGlpi = array_flip($this->deviceMappingGOsaGlpi);
798 $deviceMappingTableNameID = $this->deviceMappingTableNameID;
800 if(($id == "" )||(!is_numeric($id))){
801 return (false);
802 }
803 if($this->is_connected){
804 $qry = "DELETE FROM glpi_computer_device WHERE FK_computers=".$id.";";
805 $this->query($qry);
807 foreach($devices as $type => $entries){
808 foreach($entries as $entry){
809 if($type=="monitor"){
810 $str = "INSERT INTO glpi_connect_wire (end1,end2,type)
811 VALUES (".$entry['ID'].",".$id.",4);";
812 }else{
813 $str = "INSERT INTO glpi_computer_device (device_type,FK_device,FK_computers)
814 VALUES (".$deviceMappingTableNameID[$type].",".$entry['ID'].",".$id.");";
815 }
816 $this->query($str);
817 }
818 }
821 }else{
822 echo "not connected";
823 return(false);
824 }
826 }
828 function removeComputerInformations($id)
829 {
830 /*
831 if($this->is_connected){
832 $tmp = $this->query("SELECT * FROM glpi_computers WHERE ID=".$id.";");
833 if(isset($tmp[0])){
834 return($this->query("DELETE FROM glpi_computers WHERE ID=".$id.";"));
835 }else{
836 echo "can't remove not existing entry";
837 return(false);
838 }
839 }else{
840 echo "not connected";
841 return(false);
842 }
843 */
844 }
846 function is_connected()
847 {
848 return($this->is_connected);
849 }
851 function addAttachmentsToComputer($attr,$id)
852 {
853 if(($id == "" )||(!is_numeric($id))){
854 return (false);
855 }
856 if($this->is_connected){
857 $qry = "DELETE FROM glpi_doc_device WHERE (FK_device=".$id.") AND (device_type=1);";
858 $this->query($qry);
860 foreach($attr as $aid => $entry){
861 $str = "INSERT INTO glpi_doc_device (FK_doc,FK_device,device_type,is_template)
862 VALUES
863 ($aid,$id,1,'0');";
864 $this->query($str);
865 }
866 }else{
867 echo "not connected";
868 return(false);
869 }
870 }
872 function getAssignAttachments($id)
873 {
875 if($this->is_connected){
876 $qry= "SELECT * FROM glpi_doc_device WHERE (device_type=1) AND (FK_device=".$id.");";
877 $ret = $this->query($qry);
878 return($ret);
879 }else{
880 echo "not connected";
881 return(false);
882 }
883 }
885 function deleteAttachment($id)
886 {
887 if($this->is_connected){
888 $qry = "DELETE FROM glpi_docs WHERE ID=".$id."";
889 $this->query($qry);
890 }else{
891 echo "not connected";
892 return(false);
893 }
894 }
896 function getAttachments()
897 {
898 if($this->is_connected){
899 $qry = "SELECT * FROM glpi_docs WHERE name!='';";
900 $ret = $this->query($qry);
901 return($ret);
902 }else{
903 echo "not connected";
904 return(false);
905 }
906 }
908 function saveAttachments($attrs,$id = -1)
909 {
910 if($this->is_connected){
911 $atr = array("name","filename","rubrique","mime","date_mod","comment","deleted","link");
912 $tmp = array();
913 foreach($atr as $at){
914 if(isset($attrs[$at])){
915 $tmp[$at] = $attrs[$at];
916 }
917 }
918 if(count($tmp)==0){
919 return(false);
920 }else{
922 // Add
923 if($id == -1){
924 $str = "INSERT INTO glpi_docs ";
925 $namen = "";
926 $values= "";
927 foreach($tmp as $name => $value){
928 $namen .= $name.", ";
929 if(is_numeric($value)){
930 $values .= $value.", ";
931 }else{
932 $values .= "'".$value."', ";
933 }
934 }
935 $values = preg_replace("/, $/","",$values);
936 $namen = preg_replace("/, $/","",$namen);
937 $str .= "(".$namen.") VALUES (".$values.");";
938 print $str;
939 }else{
940 $str = "UPDATE glpi_docs SET ";
941 foreach($tmp as $name => $value){
942 $str .= $name."= ";
943 if(is_numeric($value)){
944 $str .= $value.", ";
945 }else{
946 $str .= "'".$value."', ";
947 }
948 }
949 $str = preg_replace("/, $/","",$str);
950 $str .= " WHERE ID=".$id.";";
951 }
952 $this->query($str);
953 }
954 }else{
955 echo "not connected";
956 return(false);
957 }
958 }
961 /* Monitor handling
962 */
963 function getMonitors()
964 {
965 if($this->is_connected){
966 $qry= "SELECT * FROM glpi_monitors;";
967 return($this->query($qry));
969 }else{
970 echo "not connected";
971 return(false);
972 }
973 }
975 function updatedMonitor()
976 {
977 if($this->is_connected){
978 // $qry= "SELECT * FROM glpi_monitors;";
979 // return($this->query($qry));
981 }else{
982 echo "not connected";
983 return(false);
984 }
985 }
987 function addMonitor()
988 {
989 if($this->is_connected){
990 // $qry= "SELECT * FROM glpi_monitors;";
991 // return($this->query($qry));
993 }else{
994 echo "not connected";
995 return(false);
996 }
997 }
999 function removeMonitor($id)
1000 {
1001 if($this->is_connected){
1002 $qry= "DELETE FROM glpi_monitors WHERE ID=".$id.";";
1003 $this->query($qry);
1004 }else{
1005 echo "not connected";
1006 return(false);
1007 }
1008 }
1010 function getMonitorTypes()
1011 {
1012 if($this->is_connected){
1013 $qry= "SELECT * FROM glpi_type_monitors;";
1014 return($this->query($qry));
1016 }else{
1017 echo "not connected";
1018 return(false);
1019 }
1020 }
1022 function getLocationTypes()
1023 {
1024 if($this->is_connected){
1025 $qry= "SELECT * FROM glpi_dropdown_locations;";
1026 return($this->query($qry));
1028 }else{
1029 echo "not connected";
1030 return(false);
1031 }
1032 }
1034 function getStateTypes()
1035 {
1036 if($this->is_connected){
1037 $qry= "SELECT * FROM glpi_dropdown_state;";
1038 return($this->query($qry));
1039 }else{
1040 echo "not connected";
1041 return(false);
1042 }
1043 }
1045 }
1046 //$s = new glpiDB("vserver-01","glpi","tester","glpi");
1047 //print_r($s->query("SELECT * FROM glpi_computers"));
1048 //$s->getComputerInformations("1 OR (c.ID<10000)");
1049 ?>