Code

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