Code

Added Create FAi installation cd patch
[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, $parent= NULL)
68   {
69     plugin::plugin ($config, $dn, $parent);
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     }
135     foreach(array("type","FK_glpi_enterprise","os","tech_num","comments","contact_num","AttachmentsDiv") as $attr){
136       $smarty->assign($attr,"");
137     }
139     $tmp = $this->plInfo();
140     foreach($tmp['plProvidedAcls'] as $name => $translation) {
141       $smarty->assign($name."ACL",$this->getacl($name));
142     }
144     /* Check if there is a glpi database server defined 
145       */
146     if(!isset($this->config->data['SERVERS']['GLPI'])){
147       print_red(_("There is no server with valid glpi database service."));
148       return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
149     }
151     $this->data = $this->config->data['SERVERS']['GLPI'];
153     /* Check if we can call mysql_connect 
154        If we can't, there is no the mysql-php extension
155      */
156     if(!is_callable("mysql_connect")){
157       print_red(_("Can't connect to glpi database, the php-mysql extension is missing."));
158       return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
159     }
161     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
163     /*  If handle == false, abort
164         Seems that the server, username and or password is wrong
165      */
166     if(!$this->handle->is_connected){
167       print_red(_("Can't connect to glpi database, check configuration twice."));
168       return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
169     } 
171     /*  All checks are ok
172         Lets handle Posts, templates etc below ...
173      */
174     
175     $users = $this->handle->getUsers();
176     $ldap= $this->config->get_ldap_link();
177  
178     /* Check for Trading button Post
179      */
180     if(isset($_POST['Trading'])){
181       print_red(_("This feature is not implemented yet."));
182     }
184     /* Check for Software button Post
185      */
186     if(isset($_POST['Software'])){
187       print_red(_("This feature is not implemented yet."));
188     }
190     /* Check for Contract button Post
191      */
192     if(isset($_POST['Contracts'])){
193       print_red(_("This feature is not implemented yet."));
194     }
195  
196     /* Add Device was requested, open new dialog
197      */
198     if((isset($_POST['AddDevice'])) && ($this->acl_is_writeable("Devices"))){
199       $this->dialog =true;
200       $this->cur_dialog = new glpiDeviceManagement($this->config,$this->dn,$this->usedDevices);
201     }
203     /* Attachment pool was closed with use
204      */
205     if(isset($_POST['UseAttachment']) && ($this->acl_is_writeable("Attachments"))){
206       if(count($this->cur_dialog->check())){
207         foreach($this->cur_dialog->check() as $msg){
208           print_red($msg);
209         }
210       }else{
211         $this->cur_dialog->save_object();
212         $this->usedAttachments = $this->cur_dialog->save();
213         $this->cur_dialog = false;
214         $this->edit_type = false; 
215       }
216     }
217    
218     /* Attachment pool was closed with abort
219      */ 
220     if(isset($_POST['AbortAttachment'])){
221       $this->cur_dialog = false;
222       $this->edit_type = false; 
223     }
225     /* Open Attachment pool to add/edit Attachments
226      */
227     if(isset($_POST['AddAttachment']) && ($this->acl_is_writeable("Attachments"))){
228       $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
229       $this->dialog = true;
230     }
231     
232     /* Remove Attachment fro this tab 
233      */
234     $once = true;
235     foreach($_POST as $name => $value){
236       if((preg_match("/^delAttachment_/",$name))&&($once) && $this->acl_is_writeable("Attachments")){
237         $once= false;
238         $name = preg_replace("/^delAttachment_/","",$name);
239         $entry = preg_replace("/_.*$/","",$name);
240         if(isset($this->usedAttachments[$entry])){
241           unset($this->usedAttachments[$entry]);
242         }
243       }
244     }
245     if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments'])) && ($this->acl_is_writeable("Attachments"))){
246       foreach($_POST['Attachments'] as $entry){
247         if(isset($this->usedAttachments[$entry])){
248           unset($this->usedAttachments[$entry]);
249         }
250       }
251     }
253     /* We have selected some devices and pressed use button 
254      */
255     if(isset($_POST['SelectDeviceSave']) && $this->acl_is_writeable("Devices")){
256       $this->cur_dialog->save_object();
257       $this->usedDevices= ($this->cur_dialog->getSelected());
258       $this->cur_dialog = false;
259       $this->dialog = false;
260       $this->edit_type=false;
261     }
263     /* Aborted Device selction 
264      */
265     if(isset($_POST['SelectDeviceCancel']) && ($this->acl_is_writeable("Devices"))){
266       $this->dialog = false;
267       $this->cur_dialog = false;
268       $this->edit_type=false;
269     }
271     /* System type management
272      */
273     if(isset($_POST['edit_type']) && $this->acl_is_writeable("type")){
274       $this->dialog = true;
275       $this->edit_type=true;
276     }
278     /* This closes the system type editing dialog
279      */
280     if(isset($_POST['close_edit_type']) && ($this->acl_is_writeable("type"))){
281       $this->edit_type=false;
282       $this->dialog = false;
283     }
285     if(isset($_POST['Rename_Cancel'])){
286       $this->renameTypeDialog = false;
287       $this->renameOSDialog = false;
288     }
290     /* This appends a new system to our sytem types
291      */
292     if((isset($_POST['add_type']))&&(!empty($_POST['type_string'])) && $this->acl_is_writeable("type")){
293       $attr = $this->handle->getSystemTypes();
294       if(in_array(trim($_POST['type_string']),$attr)){
295         print_red(_("Adding new sytem type failed, this system type name is already used.")) ;
296       }else{
297         $this->handle->addSystemType(trim($_POST['type_string']));  
298       }
299     }
301     /* Remove selected type from our system types list
302      */
303     if((isset($_POST['del_type']))&&(!empty($_POST['select_type'])) && $this->acl_is_writeable("type")){
304       $tmp = $this->handle->is_systemTypeUsed($_POST['select_type']);
305       if(count($tmp)){
306         $names = "";
307         foreach($tmp as $name){
308           $names .= ", ".$name;
309         }
310         $names = preg_replace("/^, /","",$names); 
311         $names = trim($names);
312         if(count($tmp) == 3){
313           $names .= " ...";
314         }
315         print_red(sprintf(_("You can't delete this system type, it is still in use by these system(s) '%s'"),$names));
316       }else{
317         $this->handle->removeSystemType($_POST['select_type']); 
318       } 
319     }
321     /* Rename selected system type to given string
322      */
323     if(isset($_POST['Rename_type_OK'])){
324       $attr = $this->handle->getSystemTypes();
325       if(in_array(trim($_POST['string']),$attr)){
326         print_red(_("Rename failed, this system type name is already used.")) ;
327       }else{
328         $this->renameTypeDialog = false;
329         $this->handle->updateSystemType($_POST['string'],trim($this->select_type));
330       }
331     }
332     
333   
334     if((isset($_POST['rename_type'])&&(!empty($_POST['select_type'])))||($this->renameTypeDialog)){
335       if(isset($_POST['select_type'])){
336         $this->select_type = $_POST['select_type'];
337       }
338       $this->renameTypeDialog = true;
339       $tmp = $this->handle->getSystemTypes();
340        
341       $smarty->assign("string",$tmp[$this->select_type]);
342       if(isset($_POST['string'])){
343         $smarty->assign("string",$_POST['string']);
344       }
345       $smarty->assign("Method","rename");
346       $display= $smarty->fetch(get_template_path('glpi_edit_type.tpl', TRUE));
347       return($display);
348     }
350     
352     /* Someone wants to edit the system types ... 
353        So, lets open a new dialog which provides some buttons to edit the types
354      */
355     if($this->edit_type){
356       $smarty->assign("Method","edit");
357       $smarty->assign("SystemTypes",            $this->handle->getSystemTypes());
358       $smarty->assign("SystemTypeKeys",         array_flip($this->handle->getSystemTypes()));
359       $display= $smarty->fetch(get_template_path('glpi_edit_type.tpl', TRUE));
360       return($display);
361     }
363     /* System os management
364      */
365     if(isset($_POST['edit_os']) && $this->acl_is_writeable("os")){
366       $this->dialog = true;
367       $this->edit_os=true;
368     }
370     /* Close Operating system dialog
371      */
372     if(isset($_POST['close_edit_os'])){
373       $this->edit_os=false;
374       $this->dialog = false;
375     }
377     /* Add new os to the db
378      */
379     if((isset($_POST['add_os']))&&(!empty($_POST['is_string']))  && $this->acl_is_writeable("os")){
380       $attr = $this->handle->getOSTypes();
381       if(in_array(trim($_POST['is_string']),$attr)){
382         print_red(_("Adding new operating system failed, specifed name is already used.")) ;
383       }else{
384         $this->handle->addOS(trim($_POST['is_string']));  
385       }
386     }
388     /* Delete selected os from list and db
389      */
390     if((isset($_POST['del_os']))&&(!empty($_POST['select_os']))  && $this->acl_is_writeable("os")){
391       $tmp = $this->handle->is_osUsed($_POST['select_os']);
392   
393       if(count($tmp)){
395         $names = "";
396         foreach($tmp as $name){
397           $names .= ", ".$name;
398         }
399         $names = preg_replace("/^, /","",$names);
400         $names = trim($names);
401         if(count($tmp) == 3){
402           $names .= " ...";
403         }
404         print_red(sprintf(_("You can't delete this operating system, it is still in use by these system(s) '%s'"),$names));
406       }else{
407         $this->handle->removeOS_byID($_POST['select_os']);  
408       }
409     }
411     /* Rename selected os to given string
412      */
413     if(isset($_POST['Rename_os_OK'])  && $this->acl_is_writeable("os")){
414       $attr = $this->handle->getOSTypes();
415       if(in_array(trim($_POST['string']),$attr)){
416         print_red(_("Updating operating system failed, specifed name is already used.")) ;
417       }else{
418         $this->handle->updateOS($_POST['string'],$this->select_type);
419         $this->renameOSDialog = false;
420       }
421     }
422     if((isset($_POST['rename_os'])&&(!empty($_POST['select_os'])))||($this->renameOSDialog)){
423       if(isset($_POST['select_os'])){
424         $this->select_type = $_POST['select_os'];
425       }
426       $this->renameOSDialog = true;
427       $tmp = $this->handle->getOSTypes();
428        
429       $smarty->assign("string",$tmp[$this->select_type]);
430       if(isset($_POST['string'])){
431         $smarty->assign("string",$_POST['string']);
432       }
433       $smarty->assign("Method","rename");
434       $display= $smarty->fetch(get_template_path('glpi_edit_os.tpl', TRUE));
435       return($display);
436     }
438     /* Open dialog to edit os types 
439      */
440     if($this->edit_os){
441       $smarty->assign("Method","edit");
442       $smarty->assign("OSs",            $this->handle->getOSTypes());
443       $smarty->assign("OSKeys",         array_flip($this->handle->getOSTypes()));
444       $display= $smarty->fetch(get_template_path('glpi_edit_os.tpl', TRUE));
445       return($display);
446     }
450     /* Show dialog to select a new contact person
451      * Select a contact person
452      */
453     if(isset($_POST['SelectContactPerson']) && $this->acl_is_writeable("contact_num")){
454       $this->addUser = "contact";
455       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
456       $this->cur_dialog->set_acl_category(preg_replace("/\//","",$this->acl_category));
457       $this->cur_dialog->set_acl_base($this->dn);
459     }
461     /* Open dialog which allows to edit the manufacturers
462      */
463     if(isset($_POST['edit_manufacturer']) && $this->acl_is_writeable("FK_glpi_enterprise")){
464       $this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
465       $this->dialog = true;
466     }
468     /* Close manufacturer editing dialog
469      */
470     if(isset($_POST['close_edit_manufacturer'])){
471       $this->dialog = false;
472       $this->cur_dialog = false;
473     }
475     /* Abort user selection
476      */
477     $smarty->assign("AbortSelectUser","SelectUserCancel");
478     if(isset($_POST['SelectUserCancel'])){
479       $this->dialog = false;
480       $this->addUser ="";
481       $this->cur_dialog = false;
482     }
484     /* Selecte technical responsible person
485      */
486     if(isset($_POST['SelectTechPerson']) && $this->acl_is_writeable("tech_num")){
487       $this->addUser ="tech";
488       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
489       $this->cur_dialog->set_acl_category(preg_replace("/\//","",$this->acl_category));
490       $this->cur_dialog->set_acl_base($this->dn);
491     }
493     /* Technical responsible person selected*/
494     if(isset($_GET['act'])&&($_GET['act']=="user_tech_num")&&(strlen($_GET['id']) > 100)){
495       print_red(sprintf(_("Could not add the given user, the users dn is too long, only 100 characters are allowed here.")));
497     }elseif(isset($_GET['act'])&&($_GET['act']=="user_tech_num") && strlen($_GET['id'])){
500       /* Get posted id */
501       $id = base64_decode($_GET['id']);
503       /* Check if user is already created in glpi database */
504       if(!in_array($id,$users)){
506         /* If this user doesn't exists in glpi db, we must create him */
507         $ldap->cat($id, array('cn', 'mail', 'telephoneNumber'));
508         $atr = $ldap->fetch();
509         $tmp = array();
510         $use = array( "cn"              =>"name",
511             "mail"            =>"email",
512             "telephoneNumber" =>"phone");
514         /* Create array */
515         foreach($use as $gosa => $glpi){
516           if(isset($atr[$gosa])){
517             $tmp[$glpi]= $atr[$gosa][0];
518           }
519         }
521         /* Add this user */
522         $this->handle->addUser($tmp,$id);
523       }
525       /* Re-read users */
526       $users = ($this->handle->getUsers());
528       /* Get user */
529       $tmp = array_flip($users);
530       $id=$tmp[$id];
532       /* Use user id, close dialog */
533       if($this->addUser == "tech"){
534         $this->tech_num = $id;
535       }else{
536         $this->contact_num = $id;
537       }
538       $this->cur_dialog   = false;
539       $this->dialog= false;
540     }
542     /* if( cur_dialog != false || cur_dialog != NULL) 
543      * There is a dialog which wants to be displayed 
544      */
545     if($this->cur_dialog){
546       $this->cur_dialog->save_object();
547       $this->dialog=true;
548       $this->cur_dialog->parent = &$this;
549       return($this->cur_dialog->execute());
550     }else{
551       $this->dialog= false;
552     }
554     /* Assign smarty defaults */ 
555     foreach(array("SystemTypes","SystemTypeKeys","Manufacturers","OSs","TechnicalResponsibles","InstalledDevices","Attachments") as $attr){
556       $smarty->assign($attr,array());
557     }
559     /* Assign some vars to smarty 
560      */
561     foreach(array("type","FK_glpi_enterprise","os","tech_num","contact_num","Attachments","InstalledDevices") as $attr){
562       $smarty->assign($attr,"");
563     }
565     /* Do we need to flip is_account state? */
566     if(isset($_POST['modify_state'])){
567       if($this->is_account && $this->acl_is_removeable()){
568         $this->is_account= FALSE;
569       }elseif(!$this->is_account && $this->acl_is_createable()){
570         $this->is_account= TRUE;
571       }
572     }
574     /* Show tab dialog headers */
575     if ($this->is_account){
576       $display= $this->show_disable_header(_("Remove inventory"),
577           _("This device has inventory informations enabled. You can disable them by clicking below."));
578     } else {
579       $display= $this->show_enable_header(_("Add inventory"),
580           _("This device has inventory informations disabled. You can enable them by clicking below."));
581       return ($display);
582     }
584     /* Assign system types 
585      */
586     $smarty->assign("SystemTypeKeys",         array_flip($this->handle->getSystemTypes()));
587     $smarty->assign("SystemTypes",            $this->handle->getSystemTypes());
588     $smarty->assign("type",                   $this->type);
590     /* Assign os types
591      */
592     $smarty->assign("OSKeys",                 array_flip($this->handle->getOSTypes()));
593     $smarty->assign("OSs",                    $this->handle->getOSTypes());
594     $smarty->assign("os",                     $this->os);
596     /* Dispaly installed devices */
597     $smarty->assign("InstalledDevices"        ,$this->getDevices());
598     $smarty->assign("InstalledDeviceKeys"     ,array_flip($this->getDevices()));
600     /* Append manufacturers
601      */
602     $smarty->assign("ManufacturerKeys",       array_flip($this->handle->getEnterprises()));
603     $smarty->assign("Manufacturers",          $this->handle->getEnterprises());
604     $smarty->assign("FK_glpi_enterprise",     $this->FK_glpi_enterprise);
606     /* Assign used Attachments
607     */
609     $divlist = new divSelectBox("glpiAttachmentsList");
610     $divlist-> SetHeight(130); 
611     $atts = $this->getUsedAttachments(true);
612     $downlink = "<a href='get_attachment.php?id=%s' target='_blank'>%s</a>";
613     $del_link = "<input type='image' src='images/edittrash.png' name='delAttachment_%s'>";
614     foreach($atts as $id => $attachment){
615       $divlist->AddEntry
616           (
617         array(
618             array("string"=>$attachment['name']),
619             array("string"=>$attachment['mime']),
620             array("string"=>sprintf($downlink,$id,$attachment['filename'])),
621             array("string"=>sprintf($del_link,$attachment['ID']),"attach"=>"style='border-right:0px;'"),
622              )
623           );
624     }
626     $smarty->assign("AttachmentsDiv"          ,$divlist->DrawList());
627     /* Handle contact person 
628        Assign name ... to smarty, if set
629      */ 
630     if(isset($users[$this->contact_num])){
631       $ldap->cat($users[$this->contact_num], array('givenName', 'sn', 'uid'));
632       $tr = $ldap->fetch();
633       $str = "";
634       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
635       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
636       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
637       $smarty->assign("contact_num",               $str);
638     }else{
639       $smarty->assign("contact_num",               _("N/A"));
640     }
642     /* Handle tech person 
643        Assign name ... to smarty, if set
644      */ 
645     if(isset($users[$this->tech_num])){
646       $tr = $ldap->cat($users[$this->tech_num], array('givenName', 'sn', 'uid'));
647       $tr = $ldap->fetch();
648       $str = "";
649       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
650       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
651       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
652       $smarty->assign("tech_num",               $str);
653     }else{
654       $smarty->assign("tech_num",               _("N/A"));
655     }
656     $smarty->assign("comments",               $this->comments);
658     $display.= $smarty->fetch(get_template_path('glpi.tpl', TRUE));
659     return($display);
660   }
662   function remove_from_parent()
663   {
664     /* Cancel if there's nothing to do here */
665     if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){
666       return;
667     }
668     if(function_exists("mysql_pconnect")){
669       $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
670       if($this->initialy_was_account){
671         $this->handle->removeComputerInformations($this->dn); 
672       }
673     }else{
674       print_red(_("Can't remove glpi account, while mysql extension is missing."));
675     }
676   
677   }
679   function getDevices(){
680     $ret = array();
681     foreach($this->usedDevices as $type => $entries){
682       foreach($entries as $ent){
683         if(isset($ent['designation'])){
684           $ret[] = $ent['designation']." [".$type."]";
685         }else{
686           $ret[] = $ent['name']." [".$type."]";
687         }
688       }
689     }
690     return($ret); 
691   }
694   /* Save data to object */
695   function save_object()
696   {
697     if(!isset($_POST['glpi_tpl_posted'])) {
698       return ;
699     }
700     plugin::save_object();
701   }
704   /* Check supplied data */
705   function check()
706   {
707     /* Call common method to give check the hook */
708     $message= plugin::check();
710     //    if($this->TechnicalResponsible == ""){
711     //      $message[] = _("Please select a technical responsible person for this entry.");
712     //    }
714     return ($message);
715   }
717   /* Save to LDAP */
718   function save()
719   {
720     if($this->is_account){
721         $attrs = array();
722       $this->date_mod = date("Y-m-d H:i:s");
723       foreach($this->attributes as $attr){
724         $attrs[$attr] = $this->$attr;
725       }
726       $attrs['name'] = $this->dn;
727       unset($attrs['ID']);
728       $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
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   }
766    /* Return plugin informations for acl handling */
767   function plInfo()
768   {
769     return (array(
770           "plShortName"   => _("Glpi"),
771           "plDescription" => _("Inventory extension"),
772           "plSelfModify"  => FALSE,
773           "plDepends"     => array(),
774           "plPriority"    => 20,
775           "plSection"     => array("administration"),
776           "plCategory"    => array("workstation","terminal","component","server","phone") ,
777           "plProvidedAcls"=> array(
778           
779             "tech_num"            => _("Technical responsible"),
780             "comments"            => _("Comment"),
781             "os"                  => _("Operating system"),
782             "location"            => _("Location"),
783             "contact_num"         => _("Contact person"),
784             "model"               => _("Model"),
785             "type"                => _("Type"),
786             "FK_glpi_enterprise"  => _("Manufacturer"),
787             "Attachments"         => _("Attachments"),
788             "Devices"             => _("Peripheral devices"))
789           ));
790   }
791   
795 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
796 ?>