Code

Fixed glpi errors if servers is renamed
[gosa.git] / plugins / admin / systems / class_glpiAccount.inc
1 <?php
3 class glpiAccount extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary= "Manage server basic objects";
7   var $cli_description= "Some longer text\nfor help";
8   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* attribute list for save action */
11   var $ignore_account= FALSE;
12   var $attributes= array("ID","name","contact",
13       "tech_num","comments","date_mod","os","location","domain","network","contact_num",
14       "model","type","is_template","FK_glpi_enterprise","deleted");
16   var $ID                 ;       // Is set if this entry is edited 
17   var $name               = "";    // This should be the dn of this entry 
18   var $contact            = "";    // Empty
19     
20   var $comments           = "";    // Comment
21   
22   var $contact_num        = "";    // Contact person
23   var $tech_num           = "";    // Technical responsible person
24   
25   var $addUser            = "";    // This is used to remember if a dialog was opened for tech_num or contact_num 
27   var $date_mod           = "";    // Modification timestamp
28   var $os                 = 0;     // Operating system
29   var $location           = 0;     // Not used yet
30   var $domain             = 0;     // ? Set to 0
31   var $network            = 0;     // ? Set to 0 
33   var $model              = 0;     // ? Can't remember this, it isn't used in GOsa 
34   var $type               = 0;     // System type id
35   var $is_template        = 0;     // Used as template ?
36   var $FK_glpi_enterprise = 0;     // Manufacturer id
37   var $deleted            = "N";   // Deleted entries should have this set to Y
39   var $renameTypeDialog   = false;
40   var $renameOSDialog     = false;
41   var $select_type        ;
42   
43   /* Not necessary, cause we use mysql databse */
44   var $objectclasses= array("whatever");
46   /* Used to remember if this was an account (simply: is this an edited entry) */
47   var $initialy_was_account = false;
49   /* Remember current dialog */
50   var $edit_type            = false;
51   var $edit_os              = false;
53   var $data;
54   var $handle = NULL;               // Glpi class handle used to query database
56   var $cur_dialog = NULL;           // This contains the sub dialog handle
58   var $orig_dn;                     // To check if dn, has changed 
59   var $ui;                          // Some GOsa specific user informations 
60   
61   var $usedDevices      = array();  // Which devices are currently selected 
62   var $usedAttachments  = array();  // Used Attachments 
64   /* Contructor 
65      Sets default values and checks if we already have an existing glpi account
66    */
67   function glpiAccount ($config, $dn= NULL)
68   {
69     plugin::plugin ($config, $dn);
70     $this->ui= get_userinfo();
72     /* Abort class construction, if no db is defined */
73     if(!isset($this->config->data['SERVERS']['GLPI'])){
74       return;
75     }
77     // Get informations about databse connection
78     $this->data = $this->config->data['SERVERS']['GLPI'];
80     // Abort if mysql extension is missing 
81     if(!is_callable("mysql_connect")){
82       return;
83     }
85     // Create handle of glpi class, and check if database connection is established 
86     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
88     if(!$this->handle->is_connected){
89       return;
90     } 
92     // If this dn is already used in database, then get all informations for this entry 
93     if($this->handle->is_account($this->dn)){
94       $this->is_account = true;
95       $tmp = ($this->handle->getComputerInformations($this->dn));
97       foreach(array("tech_num","os","FK_glpi_enterprise","type","comments","contact_num") as $attr){
98         $this->$attr = $tmp[0][$attr];
99       }
100       $this->usedDevices = $this->handle->getUsedDevices($tmp[0]['ID']);
101       $atts = $this->handle->getAssignAttachments($tmp[0]['ID']);
102       foreach($atts as $attachment){
103         
104         $this->usedAttachments[$attachment['FK_doc']]=$attachment['FK_doc']; 
105       }
106     }else{
107       $this->is_account = false;
108     }
110     /* set defaults */
111     $this->name                 = $this->dn;
112     $this->orig_dn              = $this->dn;
113     $this->initialy_was_account = $this->is_account;
116   }
118   function execute()
119   {
120     /* Call parent execute */
121     plugin::execute();
123     /* Fill templating stuff */
124     $smarty= get_smarty();
125     $display= "";
127     /*  Assign smarty defaults 
128         To avoid undefined indexes, if there is an error with the glpi db
129      */ 
130     foreach(array("SystemTypes","SystemTypeKeys","Manufacturers",
131                   "OSs","TechnicalResponsibles","InstalledDevices","Attachments","AttachmentKeys",
132                   "OSKeys","OSs","ManufacturerKeys","InstalledDeviceKeys") as $attr){
133       $smarty->assign($attr,array());
134       $smarty->assign($attr."ACL"," disabled ");
135     }
136     foreach(array("type","FK_glpi_enterprise","os","tech_num","comments","contact_num","AttachmentsDiv") as $attr){
137       $smarty->assign($attr,"");
138       $smarty->assign($attr."ACL"," disabled ");
139     }
141     /* Check if there is a glpi database server defined 
142       */
143     if(!isset($this->config->data['SERVERS']['GLPI'])){
144       print_red(_("There is no server with valid glpi database service."));
145       return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
146     }
148     $this->data = $this->config->data['SERVERS']['GLPI'];
150     /* Check if we can call mysql_connect 
151        If we can't, there is no the mysql-php extension
152      */
153     if(!is_callable("mysql_connect")){
154       print_red(_("Can't connect to glpi database, the php-mysql extension is missing."));
155       return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
156     }
158     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
160     /*  If handle == false, abort
161         Seems that the server, username and or password is wrong
162      */
163     if(!$this->handle->is_connected){
164       print_red(_("Can't connect to glpi database, check configuration twice."));
165       return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
166     } 
168     /*  All checks are ok
169         Lets handle Posts, templates etc below ...
170      */
171     
172     $users = $this->handle->getUsers();
173     $ldap= $this->config->get_ldap_link();
174  
175     /* Check for Trading button Post
176      */
177     if(isset($_POST['Trading'])){
178       print_red(_("This feature is not implemented yet."));
179     }
181     /* Check for Software button Post
182      */
183     if(isset($_POST['Software'])){
184       print_red(_("This feature is not implemented yet."));
185     }
187     /* Check for Contract button Post
188      */
189     if(isset($_POST['Contracts'])){
190       print_red(_("This feature is not implemented yet."));
191     }
192  
193     /* Add Device was requested, open new dialog
194      */
195     if(isset($_POST['AddDevice'])){
196       $this->dialog =true;
197       $this->cur_dialog = new glpiDeviceManagement($this->config,$this->dn,$this->usedDevices);
198     }
200     /* Attachment pool was closed with use
201      */
202     if(isset($_POST['UseAttachment'])){
203       if(count($this->cur_dialog->check())){
204         foreach($this->cur_dialog->check() as $msg){
205           print_red($msg);
206         }
207       }else{
208         $this->cur_dialog->save_object();
209         $this->usedAttachments = $this->cur_dialog->save();
210         $this->cur_dialog = false;
211         $this->edit_type = false; 
212       }
213     }
214    
215     /* Attachment pool was closed with abort
216      */ 
217     if(isset($_POST['AbortAttachment'])){
218       $this->cur_dialog = false;
219       $this->edit_type = false; 
220     }
222     /* Open Attachment pool to add/edit Attachments
223      */
224     if(isset($_POST['AddAttachment'])){
225       $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
226       $this->dialog = true;
227     }
228     
229     /* Remove Attachment fro this tab 
230      */
231     $once = true;
232     foreach($_POST as $name => $value){
233       if((preg_match("/^delAttachment_/",$name))&&($once)){
234         $once= false;
235         $name = preg_replace("/^delAttachment_/","",$name);
236         $entry = preg_replace("/_.*$/","",$name);
237         if(isset($this->usedAttachments[$entry])){
238           unset($this->usedAttachments[$entry]);
239         }
240       }
241     }
242     if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments']))){
243       foreach($_POST['Attachments'] as $entry){
244         if(isset($this->usedAttachments[$entry])){
245           unset($this->usedAttachments[$entry]);
246         }
247       }
248     }
250     /* We have selected some devices and pressed use button 
251      */
252     if(isset($_POST['SelectDeviceSave'])){
253       $this->cur_dialog->save_object();
254       $this->usedDevices= ($this->cur_dialog->getSelected());
255       $this->cur_dialog = false;
256       $this->dialog = false;
257       $this->edit_type=false;
258     }
260     /* Aborted Device selction 
261      */
262     if(isset($_POST['SelectDeviceCancel'])){
263       $this->dialog = false;
264       $this->cur_dialog = false;
265       $this->edit_type=false;
266     }
268     /* System type management
269      */
270     if(isset($_POST['edit_type'])){
271       $this->dialog = true;
272       $this->edit_type=true;
273     }
275     /* This closes the system type editing dialog
276      */
277     if(isset($_POST['close_edit_type'])){
278       $this->edit_type=false;
279       $this->dialog = false;
280     }
282     if(isset($_POST['Rename_Cancel'])){
283       $this->renameTypeDialog = false;
284       $this->renameOSDialog = false;
285     }
287     /* This appends a new system to our sytem types
288      */
289     if((isset($_POST['add_type']))&&(!empty($_POST['type_string']))){
290       $attr = $this->handle->getSystemTypes();
291       if(in_array(trim($_POST['type_string']),$attr)){
292         print_red(_("Adding new sytem type failed, this system type name is already used.")) ;
293       }else{
294         $this->handle->addSystemType(trim($_POST['type_string']));  
295       }
296     }
298     /* Remove selected type from our system types list
299      */
300     if((isset($_POST['del_type']))&&(!empty($_POST['select_type']))){
301       $tmp = $this->handle->is_systemTypeUsed($_POST['select_type']);
302       if(count($tmp)){
303         $names = "";
304         foreach($tmp as $name){
305           $names .= ", ".$name;
306         }
307         $names = preg_replace("/^, /","",$names); 
308         $names = trim($names);
309         if(count($tmp) == 3){
310           $names .= " ...";
311         }
312         print_red(sprintf(_("You can't delete this system type, it is still in use by these system(s) '%s'"),$names));
313       }else{
314         $this->handle->removeSystemType($_POST['select_type']); 
315       } 
316     }
318     /* Rename selected system type to given string
319      */
320     if(isset($_POST['Rename_type_OK'])){
321       $attr = $this->handle->getSystemTypes();
322       if(in_array(trim($_POST['string']),$attr)){
323         print_red(_("Rename failed, this system type name is already used.")) ;
324       }else{
325         $this->renameTypeDialog = false;
326         $this->handle->updateSystemType($_POST['string'],trim($this->select_type));
327       }
328     }
329     
330   
331     if((isset($_POST['rename_type'])&&(!empty($_POST['select_type'])))||($this->renameTypeDialog)){
332       if(isset($_POST['select_type'])){
333         $this->select_type = $_POST['select_type'];
334       }
335       $this->renameTypeDialog = true;
336       $tmp = $this->handle->getSystemTypes();
337        
338       $smarty->assign("string",$tmp[$this->select_type]);
339       if(isset($_POST['string'])){
340         $smarty->assign("string",$_POST['string']);
341       }
342       $smarty->assign("Method","rename");
343       $display= $smarty->fetch(get_template_path('glpi_edit_type.tpl', TRUE));
344       return($display);
345     }
347     
349     /* Someone wants to edit the system types ... 
350        So, lets open a new dialog which provides some buttons to edit the types
351      */
352     if($this->edit_type){
353       $smarty->assign("Method","edit");
354       $smarty->assign("SystemTypes",            $this->handle->getSystemTypes());
355       $smarty->assign("SystemTypeKeys",         array_flip($this->handle->getSystemTypes()));
356       $display= $smarty->fetch(get_template_path('glpi_edit_type.tpl', TRUE));
357       return($display);
358     }
360     /* System os management
361      */
362     if(isset($_POST['edit_os'])){
363       $this->dialog = true;
364       $this->edit_os=true;
365     }
367     /* Close Operating system dialog
368      */
369     if(isset($_POST['close_edit_os'])){
370       $this->edit_os=false;
371       $this->dialog = false;
372     }
374     /* Add new os to the db
375      */
376     if((isset($_POST['add_os']))&&(!empty($_POST['is_string']))){
377       $attr = $this->handle->getOSTypes();
378       if(in_array(trim($_POST['is_string']),$attr)){
379         print_red(_("Adding new operating system failed, specifed name is already used.")) ;
380       }else{
381         $this->handle->addOS(trim($_POST['is_string']));  
382       }
383     }
385     /* Delete selected os from list and db
386      */
387     if((isset($_POST['del_os']))&&(!empty($_POST['select_os']))){
388       $tmp = $this->handle->is_osUsed($_POST['select_os']);
389   
390       if(count($tmp)){
392         $names = "";
393         foreach($tmp as $name){
394           $names .= ", ".$name;
395         }
396         $names = preg_replace("/^, /","",$names);
397         $names = trim($names);
398         if(count($tmp) == 3){
399           $names .= " ...";
400         }
401         print_red(sprintf(_("You can't delete this operating system, it is still in use by these system(s) '%s'"),$names));
403       }else{
404         $this->handle->removeOS_byID($_POST['select_os']);  
405       }
406     }
408     /* Rename selected os to given string
409      */
410     if(isset($_POST['Rename_os_OK'])){
411       $attr = $this->handle->getOSTypes();
412       if(in_array(trim($_POST['string']),$attr)){
413         print_red(_("Updating operating system failed, specifed name is already used.")) ;
414       }else{
415         $this->handle->updateOS($_POST['string'],$this->select_type);
416         $this->renameOSDialog = false;
417       }
418     }
419     if((isset($_POST['rename_os'])&&(!empty($_POST['select_os'])))||($this->renameOSDialog)){
420       if(isset($_POST['select_os'])){
421         $this->select_type = $_POST['select_os'];
422       }
423       $this->renameOSDialog = true;
424       $tmp = $this->handle->getOSTypes();
425        
426       $smarty->assign("string",$tmp[$this->select_type]);
427       if(isset($_POST['string'])){
428         $smarty->assign("string",$_POST['string']);
429       }
430       $smarty->assign("Method","rename");
431       $display= $smarty->fetch(get_template_path('glpi_edit_os.tpl', TRUE));
432       return($display);
433     }
435     /* Open dialog to edit os types 
436      */
437     if($this->edit_os){
438       $smarty->assign("Method","edit");
439       $smarty->assign("OSs",            $this->handle->getOSTypes());
440       $smarty->assign("OSKeys",         array_flip($this->handle->getOSTypes()));
441       $display= $smarty->fetch(get_template_path('glpi_edit_os.tpl', TRUE));
442       return($display);
443     }
447     /* Show dialog to select a new contact person
448      * Select a contact person
449      */
450     if(isset($_POST['SelectContactPerson'])){
451       $this->addUser = "contact";
452       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
453     }
455     /* Open dialog which allows to edit the manufacturers
456      */
457     if(isset($_POST['edit_manufacturer'])){
458       $this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
459       $this->dialog = true;
460     }
462     /* Close manufacturer editing dialog
463      */
464     if(isset($_POST['close_edit_manufacturer'])){
465       $this->dialog = false;
466       $this->cur_dialog = false;
467     }
469     /* Abort user selection
470      */
471     $smarty->assign("AbortSelectUser","SelectUserCancel");
472     if(isset($_POST['SelectUserCancel'])){
473       $this->dialog = false;
474       $this->addUser ="";
475       $this->cur_dialog = false;
476     }
478     /* Selecte technical responsible person
479      */
480     if(isset($_POST['SelectTechPerson'])){
481       $this->addUser ="tech";
482       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
483     }
485     /* Technical responsible person selected*/
486     if(isset($_GET['act'])&&($_GET['act']=="user_tech_num")){
488       /* Get posted id */
489       $id = base64_decode($_GET['id']);
491       /* Check if user is already created in glpi database */
492       if(!in_array($id,$users)){
494         /* If this user doesn't exists in glpi db, we must create him */
495         $ldap->cat($id, array('cn', 'mail', 'telephoneNumber'));
496         $atr = $ldap->fetch();
497         $tmp = array();
498         $use = array( "cn"              =>"name",
499             "mail"            =>"email",
500             "telephoneNumber" =>"phone");
502         /* Create array */
503         foreach($use as $gosa => $glpi){
504           if(isset($atr[$gosa])){
505             $tmp[$glpi]= $atr[$gosa][0];
506           }
507         }
509         /* Add this user */
510         $this->handle->addUser($tmp,$id);
511       }
513       /* Re-read users */
514       $users = ($this->handle->getUsers());
516       /* Get user */
517       $tmp = array_flip($users);
518       $id=$tmp[$id];
520       /* Use user id, close dialog */
521       if($this->addUser == "tech"){
522         $this->tech_num = $id;
523       }else{
524         $this->contact_num = $id;
525       }
526       $this->cur_dialog   = false;
527       $this->dialog= false;
528     }
530     /* if( cur_dialog != false || cur_dialog != NULL) 
531      * There is a dialog which wants to be displayed 
532      */
533     if($this->cur_dialog){
534       $this->cur_dialog->save_object();
535       $this->dialog=true;
536       $this->cur_dialog->parent = &$this;
537       return($this->cur_dialog->execute());
538     }else{
539       $this->dialog= false;
540     }
542     /* Assign smarty defaults */ 
543     foreach(array("SystemTypes","SystemTypeKeys","Manufacturers","OSs","TechnicalResponsibles","InstalledDevices","Attachments") as $attr){
544       $smarty->assign($attr,array());
545     }
547     foreach($this->attributes as $attr){
548       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
549     }
551     /* Assign some vars to smarty 
552      */
553     foreach(array("type","FK_glpi_enterprise","os","tech_num","contact_num","Attachments","InstalledDevices") as $attr){
554       $smarty->assign($attr,"");
555       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
556     }
558     /* Do we need to flip is_account state? */
559     if (isset($_POST['modify_state'])){
560       $this->is_account= !$this->is_account;
561     }
563     /* Show tab dialog headers */
564     if ($this->is_account){
565       $display= $this->show_header(_("Remove inventory"),
566           _("This device has inventory informations enabled. You can disable them by clicking below."));
567     } else {
568       $display= $this->show_header(_("Add inventory"),
569           _("This device has inventory informations disabled. You can enable them by clicking below."));
570       return ($display);
571     }
573     /* Assign ACLs to smarty*/
574     foreach($this->attributes as $attr){
575       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
576     }
578     /* Assign system types 
579      */
580     $smarty->assign("SystemTypeKeys",         array_flip($this->handle->getSystemTypes()));
581     $smarty->assign("SystemTypes",            $this->handle->getSystemTypes());
582     $smarty->assign("type",                   $this->type);
584     /* Assign os types
585      */
586     $smarty->assign("OSKeys",                 array_flip($this->handle->getOSTypes()));
587     $smarty->assign("OSs",                    $this->handle->getOSTypes());
588     $smarty->assign("os",                     $this->os);
590     /* Dispaly installed devices */
591     $smarty->assign("InstalledDevices"        ,$this->getDevices());
592     $smarty->assign("InstalledDeviceKeys"     ,array_flip($this->getDevices()));
594     /* Append manufacturers
595      */
596     $smarty->assign("ManufacturerKeys",       array_flip($this->handle->getEnterprises()));
597     $smarty->assign("Manufacturers",          $this->handle->getEnterprises());
598     $smarty->assign("FK_glpi_enterprise",     $this->FK_glpi_enterprise);
600     /* Assign used Attachments
601     */
603     $divlist = new divSelectBox("glpiAttachmentsList");
604     $divlist-> SetHeight(130); 
605     $atts = $this->getUsedAttachments(true);
606     $downlink = "<a href='get_attachment.php?id=%s' target='_blank'>%s</a>";
607     $del_link = "<input type='image' src='images/edittrash.png' name='delAttachment_%s'>";
608     foreach($atts as $id => $attachment){
609       $divlist->AddEntry
610           (
611         array(
612             array("string"=>$attachment['name']),
613             array("string"=>$attachment['mime']),
614             array("string"=>sprintf($downlink,$id,$attachment['filename'])),
615             array("string"=>sprintf($del_link,$attachment['ID']),"attach"=>"style='border-right:0px;'"),
616              )
617           );
618     }
620     $smarty->assign("AttachmentsDiv"          ,$divlist->DrawList());
621     /* Handle contact person 
622        Assign name ... to smarty, if set
623      */ 
624     if(isset($users[$this->contact_num])){
625       $ldap->cat($users[$this->contact_num], array('givenName', 'sn', 'uid'));
626       $tr = $ldap->fetch();
627       $str = "";
628       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
629       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
630       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
631       $smarty->assign("contact_num",               $str);
632     }else{
633       $smarty->assign("contact_num",               _("N/A"));
634     }
636     /* Handle tech person 
637        Assign name ... to smarty, if set
638      */ 
639     if(isset($users[$this->tech_num])){
640       $tr = $ldap->cat($users[$this->tech_num], array('givenName', 'sn', 'uid'));
641       $tr = $ldap->fetch();
642       $str = "";
643       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
644       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
645       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
646       $smarty->assign("tech_num",               $str);
647     }else{
648       $smarty->assign("tech_num",               _("N/A"));
649     }
650     $smarty->assign("comments",               $this->comments);
652     $display.= $smarty->fetch(get_template_path('glpi.tpl', TRUE));
653     return($display);
654   }
656   function remove_from_parent()
657   {
658     if(!$this->initialy_was_account){
659       return;
660     }
661     if(function_exists("mysql_pconnect")){
662       $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
663       if($this->initialy_was_account){
664         $this->handle->removeComputerInformations($this->dn); 
665       }
666     }else{
667       print_red(_("Can't remove glpi account, while mysql extension is missing."));
668     }
669   
670   }
672   function getDevices(){
673     $ret = array();
674     foreach($this->usedDevices as $type => $entries){
675       foreach($entries as $ent){
676         if(isset($ent['designation'])){
677           $ret[] = $ent['designation']." [".$type."]";
678         }else{
679           $ret[] = $ent['name']." [".$type."]";
680         }
681       }
682     }
683     return($ret); 
684   }
687   /* Save data to object */
688   function save_object()
689   {
690     if(!isset($_POST['glpi_tpl_posted'])) {
691       return ;
692     }
693     plugin::save_object();
694     foreach($this->attributes as $attrs){
695       if(isset($_POST[$attrs])){
696         $this->$attrs = $_POST[$attrs];
697       }
698     }
699   }
702   /* Check supplied data */
703   function check()
704   {
705     /* Call common method to give check the hook */
706     $message= plugin::check();
708     //    if($this->TechnicalResponsible == ""){
709     //      $message[] = _("Please select a technical responsible person for this entry.");
710     //    }
712     return ($message);
713   }
715   /* Save to LDAP */
716   function save()
717   {
718     if($this->is_account){
719         $attrs = array();
720       $this->date_mod = date("Y-m-d H:i:s");
721       foreach($this->attributes as $attr){
722         $attrs[$attr] = $this->$attr;
723       }
724       $attrs['name'] = $this->dn;
725       unset($attrs['ID']);
726       $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
728       print_a($attrs);
730       /* check if we have to update, add */
731       if($this->initialy_was_account&&$this->is_account){
732         $this->handle->updateComputerInformations($attrs,$this->orig_dn);
733       }elseif($this->is_account){
734         $this->handle->addComputerInformations($attrs,$this->dn);
735       }
736       $tmp = $this->handle->getComputerInformations($this->dn);
737       $this->handle->addDevicesToComputer($this->usedDevices,$tmp[0]['ID']);
738     }
739   }
741   /* Return used attachments */
742   function getUsedAttachments($divlist = false)
743   {
744     $atts =$this->handle->getAttachments();
745     $ret = array();
746     foreach($atts as $entry){
747       if(in_array($entry['ID'],$this->usedAttachments)){
748         if($divlist){
749           $ret[$entry['ID']] = $entry;
750         }else{
751           $cm ="";
752           if(isset($entry['comment'])){
753             $cm=" [".$entry['comment']."]";
754           }
755           if(isset($entry['mime'])){
756             $cm.=" -".$entry['mime']."";
757           }
759           $ret[$entry['ID']]= $entry['name'].$cm;
760         }
761       }
762     }
763     return($ret);
764   }
765   
769 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
770 ?>