Code

Updated workstation - Startup
[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   var $view_logged = FALSE;
43   
44   /* Not necessary, cause we use mysql databse */
45   var $objectclasses= array("whatever");
47   /* Used to remember if this was an account (simply: is this an edited entry) */
48   var $initially_was_account = false;
50   /* Remember current dialog */
51   var $edit_type            = false;
52   var $edit_os              = false;
54   var $data;
55   var $handle = NULL;               // Glpi class handle used to query database
57   var $cur_dialog = NULL;           // This contains the sub dialog handle
59   var $orig_dn;                     // To check if dn, has changed 
60   var $ui;                          // Some GOsa specific user informations 
61   
62   var $usedDevices      = array();  // Which devices are currently selected 
63   var $usedAttachments  = array();  // Used Attachments 
65   /* Contructor 
66      Sets default values and checks if we already have an existing glpi account
67    */
68   function glpiAccount (&$config, $dn= NULL, $parent= NULL)
69   {
70     plugin::plugin ($config, $dn, $parent);
71     $this->ui= get_userinfo();
73     /* Abort class construction, if no db is defined */
74     if(!isset($this->config->data['SERVERS']['GLPI'])){
75       return;
76     }
78     // Get informations about databse connection
79     $this->data = $this->config->data['SERVERS']['GLPI'];
81     // Abort if mysql extension is missing 
82     if(!is_callable("mysql_connect")){
83       return;
84     }
86     // Create handle of glpi class, and check if database connection is established 
87     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
89     if(!$this->handle->is_connected){
90       return;
91     } 
93     // If this dn is already used in database, then get all informations for this entry 
94     if($this->handle->is_account($this->dn)){
95       $this->is_account = true;
96       $tmp = ($this->handle->getComputerInformations($this->dn));
98       foreach(array("tech_num","os","FK_glpi_enterprise","type","comments","contact_num") as $attr){
99         $this->$attr = $tmp[0][$attr];
100       }
101       $this->usedDevices = $this->handle->getUsedDevices($tmp[0]['ID']);
102       $atts = $this->handle->getAssignAttachments($tmp[0]['ID']);
103       foreach($atts as $attachment){
104         
105         $this->usedAttachments[$attachment['FK_doc']]=$attachment['FK_doc']; 
106       }
107     }else{
108       $this->is_account = false;
109     }
111     /* set defaults */
112     $this->name                 = $this->dn;
113     $this->orig_dn              = $this->dn;
114     $this->initially_was_account = $this->is_account;
115   }
117   function execute()
118   {
119     /* Call parent execute */
120     plugin::execute();
122     if($this->is_account && !$this->view_logged){
123       $this->view_logged = TRUE;
124       new log("view","all/".get_class($this),$this->dn);
125     }
127     /* Fill templating stuff */
128     $smarty= get_smarty();
129     $display= "";
131     /*  Assign smarty defaults 
132         To avoid undefined indexes, if there is an error with the glpi db
133      */ 
134     foreach(array("SystemTypes","SystemTypeKeys","Manufacturers",
135                   "OSs","TechnicalResponsibles","InstalledDevices","Attachments","AttachmentKeys",
136                   "OSKeys","OSs","ManufacturerKeys","InstalledDeviceKeys") as $attr){
137       $smarty->assign($attr,array());
138     }
139     foreach(array("type","FK_glpi_enterprise","os","tech_num","comments","contact_num","AttachmentsDiv") as $attr){
140       $smarty->assign($attr,"");
141     }
143     $tmp = $this->plInfo();
144     foreach($tmp['plProvidedAcls'] as $name => $translation) {
145       $smarty->assign($name."ACL",$this->getacl($name));
146     }
148     /* Check if there is a glpi database server defined 
149       */
150     if(!isset($this->config->data['SERVERS']['GLPI'])){
151       print_red(_("There is no server with valid glpi database service."));
152       return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
153     }
155     $this->data = $this->config->data['SERVERS']['GLPI'];
157     /* Check if we can call mysql_connect 
158        If we can't, there is no the mysql-php extension
159      */
160     if(!is_callable("mysql_connect")){
161       print_red(_("Can't connect to glpi database, the php-mysql extension is missing."));
162       return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
163     }
165     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
167     /*  If handle == false, abort
168         Seems that the server, username and or password is wrong
169      */
170     if(!$this->handle->is_connected){
171       print_red(_("Can't connect to glpi database, check configuration twice."));
172       return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
173     } 
175     /*  All checks are ok
176         Lets handle Posts, templates etc below ...
177      */
178     
179     $users = $this->handle->getUsers();
180     $ldap= $this->config->get_ldap_link();
181  
182     /* Check for Trading button Post
183      */
184     if(isset($_POST['Trading'])){
185       print_red(_("This feature is not implemented yet."));
186     }
188     /* Check for Software button Post
189      */
190     if(isset($_POST['Software'])){
191       print_red(_("This feature is not implemented yet."));
192     }
194     /* Check for Contract button Post
195      */
196     if(isset($_POST['Contracts'])){
197       print_red(_("This feature is not implemented yet."));
198     }
199  
200     /* Add Device was requested, open new dialog
201      */
202     if((isset($_POST['AddDevice'])) && ($this->acl_is_writeable("Devices"))){
203       $this->dialog =true;
204       $this->cur_dialog = new glpiDeviceManagement($this->config,$this->dn,$this->usedDevices);
205     }
207     /* Attachment pool was closed with use
208      */
209     if(isset($_POST['UseAttachment']) && ($this->acl_is_writeable("Attachments"))){
210       if(count($this->cur_dialog->check())){
211         foreach($this->cur_dialog->check() as $msg){
212           print_red($msg);
213         }
214       }else{
215         $this->cur_dialog->save_object();
216         $this->usedAttachments = $this->cur_dialog->save();
217         $this->cur_dialog = false;
218         $this->edit_type = false; 
219       }
220     }
221    
222     /* Attachment pool was closed with abort
223      */ 
224     if(isset($_POST['AbortAttachment'])){
225       $this->cur_dialog = false;
226       $this->edit_type = false; 
227     }
229     /* Open Attachment pool to add/edit Attachments
230      */
231     if(isset($_POST['AddAttachment']) && ($this->acl_is_writeable("Attachments"))){
232       $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
233       $this->dialog = true;
234     }
235     
236     /* Remove Attachment fro this tab 
237      */
238     $once = true;
239     foreach($_POST as $name => $value){
240       if((preg_match("/^delAttachment_/",$name))&&($once) && $this->acl_is_writeable("Attachments")){
241         $once= false;
242         $name = preg_replace("/^delAttachment_/","",$name);
243         $entry = preg_replace("/_.*$/","",$name);
244         if(isset($this->usedAttachments[$entry])){
245           unset($this->usedAttachments[$entry]);
246         }
247       }
248     }
249     if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments'])) && ($this->acl_is_writeable("Attachments"))){
250       foreach($_POST['Attachments'] as $entry){
251         if(isset($this->usedAttachments[$entry])){
252           unset($this->usedAttachments[$entry]);
253         }
254       }
255     }
257     /* We have selected some devices and pressed use button 
258      */
259     if(isset($_POST['SelectDeviceSave']) && $this->acl_is_writeable("Devices")){
260       $this->cur_dialog->save_object();
261       $this->usedDevices= ($this->cur_dialog->getSelected());
262       $this->cur_dialog = false;
263       $this->dialog = false;
264       $this->edit_type=false;
265     }
267     /* Aborted Device selction 
268      */
269     if(isset($_POST['SelectDeviceCancel']) && ($this->acl_is_writeable("Devices"))){
270       $this->dialog = false;
271       $this->cur_dialog = false;
272       $this->edit_type=false;
273     }
275     /* System type management
276      */
277     if(isset($_POST['edit_type']) && $this->acl_is_writeable("type")){
278       $this->dialog = true;
279       $this->edit_type=true;
280     }
282     /* This closes the system type editing dialog
283      */
284     if(isset($_POST['close_edit_type']) && ($this->acl_is_writeable("type"))){
285       $this->edit_type=false;
286       $this->dialog = false;
287     }
289     if(isset($_POST['Rename_Cancel'])){
290       $this->renameTypeDialog = false;
291       $this->renameOSDialog = false;
292     }
294     /* This appends a new system to our sytem types
295      */
296     if((isset($_POST['add_type']))&&(!empty($_POST['type_string'])) && $this->acl_is_writeable("type")){
297       $attr = $this->handle->getSystemTypes();
298       if(in_array(trim($_POST['type_string']),$attr)){
299         print_red(_("Adding new sytem type failed, this system type name is already used.")) ;
300       }else{
301         $this->handle->addSystemType(trim($_POST['type_string']));  
302       }
303     }
305     /* Remove selected type from our system types list
306      */
307     if((isset($_POST['del_type']))&&(!empty($_POST['select_type'])) && $this->acl_is_writeable("type")){
308       $tmp = $this->handle->is_systemTypeUsed($_POST['select_type']);
309       if(count($tmp)){
310         $names = "";
311         foreach($tmp as $name){
312           $names .= ", ".$name;
313         }
314         $names = preg_replace("/^, /","",$names); 
315         $names = trim($names);
316         if(count($tmp) == 3){
317           $names .= " ...";
318         }
319         print_red(sprintf(_("You can't delete this system type, it is still in use by these system(s) '%s'"),$names));
320       }else{
321         $this->handle->removeSystemType($_POST['select_type']); 
322       } 
323     }
325     /* Rename selected system type to given string
326      */
327     if(isset($_POST['Rename_type_OK'])){
328       $attr = $this->handle->getSystemTypes();
329       if(in_array(trim($_POST['string']),$attr)){
330         print_red(_("Rename failed, this system type name is already used.")) ;
331       }else{
332         $this->renameTypeDialog = false;
333         $this->handle->updateSystemType($_POST['string'],trim($this->select_type));
334       }
335     }
336     
337   
338     if((isset($_POST['rename_type'])&&(!empty($_POST['select_type'])))||($this->renameTypeDialog)){
339       if(isset($_POST['select_type'])){
340         $this->select_type = $_POST['select_type'];
341       }
342       $this->renameTypeDialog = true;
343       $tmp = $this->handle->getSystemTypes();
344        
345       $smarty->assign("string",$tmp[$this->select_type]);
346       if(isset($_POST['string'])){
347         $smarty->assign("string",$_POST['string']);
348       }
349       $smarty->assign("Method","rename");
350       $display= $smarty->fetch(get_template_path('glpi_edit_type.tpl', TRUE));
351       return($display);
352     }
354     
356     /* Someone wants to edit the system types ... 
357        So, lets open a new dialog which provides some buttons to edit the types
358      */
359     if($this->edit_type){
360       $smarty->assign("Method","edit");
361       $smarty->assign("SystemTypes",            $this->handle->getSystemTypes());
362       $smarty->assign("SystemTypeKeys",         array_flip($this->handle->getSystemTypes()));
363       $display= $smarty->fetch(get_template_path('glpi_edit_type.tpl', TRUE));
364       return($display);
365     }
367     /* System os management
368      */
369     if(isset($_POST['edit_os']) && $this->acl_is_writeable("os")){
370       $this->dialog = true;
371       $this->edit_os=true;
372     }
374     /* Close Operating system dialog
375      */
376     if(isset($_POST['close_edit_os'])){
377       $this->edit_os=false;
378       $this->dialog = false;
379     }
381     /* Add new os to the db
382      */
383     if((isset($_POST['add_os']))&&(!empty($_POST['is_string']))  && $this->acl_is_writeable("os")){
384       $attr = $this->handle->getOSTypes();
385       if(in_array(trim($_POST['is_string']),$attr)){
386         print_red(_("Adding new operating system failed, specifed name is already used.")) ;
387       }else{
388         $this->handle->addOS(trim($_POST['is_string']));  
389       }
390     }
392     /* Delete selected os from list and db
393      */
394     if((isset($_POST['del_os']))&&(!empty($_POST['select_os']))  && $this->acl_is_writeable("os")){
395       $tmp = $this->handle->is_osUsed($_POST['select_os']);
396   
397       if(count($tmp)){
399         $names = "";
400         foreach($tmp as $name){
401           $names .= ", ".$name;
402         }
403         $names = preg_replace("/^, /","",$names);
404         $names = trim($names);
405         if(count($tmp) == 3){
406           $names .= " ...";
407         }
408         print_red(sprintf(_("You can't delete this operating system, it is still in use by these system(s) '%s'"),$names));
410       }else{
411         $this->handle->removeOS_byID($_POST['select_os']);  
412       }
413     }
415     /* Rename selected os to given string
416      */
417     if(isset($_POST['Rename_os_OK'])  && $this->acl_is_writeable("os")){
418       $attr = $this->handle->getOSTypes();
419       if(in_array(trim($_POST['string']),$attr)){
420         print_red(_("Updating operating system failed, specifed name is already used.")) ;
421       }else{
422         $this->handle->updateOS($_POST['string'],$this->select_type);
423         $this->renameOSDialog = false;
424       }
425     }
426     if((isset($_POST['rename_os'])&&(!empty($_POST['select_os'])))||($this->renameOSDialog)){
427       if(isset($_POST['select_os'])){
428         $this->select_type = $_POST['select_os'];
429       }
430       $this->renameOSDialog = true;
431       $tmp = $this->handle->getOSTypes();
432        
433       $smarty->assign("string",$tmp[$this->select_type]);
434       if(isset($_POST['string'])){
435         $smarty->assign("string",$_POST['string']);
436       }
437       $smarty->assign("Method","rename");
438       $display= $smarty->fetch(get_template_path('glpi_edit_os.tpl', TRUE));
439       return($display);
440     }
442     /* Open dialog to edit os types 
443      */
444     if($this->edit_os){
445       $smarty->assign("Method","edit");
446       $smarty->assign("OSs",            $this->handle->getOSTypes());
447       $smarty->assign("OSKeys",         array_flip($this->handle->getOSTypes()));
448       $display= $smarty->fetch(get_template_path('glpi_edit_os.tpl', TRUE));
449       return($display);
450     }
454     /* Show dialog to select a new contact person
455      * Select a contact person
456      */
457     if(isset($_POST['SelectContactPerson']) && $this->acl_is_writeable("contact_num")){
458       $this->addUser = "contact";
459       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
460       $this->cur_dialog->set_acl_category(preg_replace("/\//","",$this->acl_category));
461       $this->cur_dialog->set_acl_base($this->dn);
463     }
465     /* Open dialog which allows to edit the manufacturers
466      */
467     if(isset($_POST['edit_manufacturer']) && $this->acl_is_writeable("FK_glpi_enterprise")){
468       $this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
469       $this->dialog = true;
470     }
472     /* Close manufacturer editing dialog
473      */
474     if(isset($_POST['close_edit_manufacturer'])){
475       $this->dialog = false;
476       $this->cur_dialog = false;
477     }
479     /* Abort user selection
480      */
481     $smarty->assign("AbortSelectUser","SelectUserCancel");
482     if(isset($_POST['SelectUserCancel'])){
483       $this->dialog = false;
484       $this->addUser ="";
485       $this->cur_dialog = false;
486     }
488     /* Selecte technical responsible person
489      */
490     if(isset($_POST['SelectTechPerson']) && $this->acl_is_writeable("tech_num")){
491       $this->addUser ="tech";
492       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
493       $this->cur_dialog->set_acl_category(preg_replace("/\//","",$this->acl_category));
494       $this->cur_dialog->set_acl_base($this->dn);
495     }
497     /* Technical responsible person selected*/
498     if(isset($_GET['act'])&&($_GET['act']=="user_tech_num")&&(strlen($_GET['id']) > 100)){
499       print_red(sprintf(_("Could not add the given user, the users dn is too long, only 100 characters are allowed here.")));
501     }elseif(isset($_GET['act'])&&($_GET['act']=="user_tech_num") && strlen($_GET['id'])){
504       /* Get posted id */
505       $id = base64_decode($_GET['id']);
507       /* Check if user is already created in glpi database */
508       if(!in_array($id,$users)){
510         /* If this user doesn't exists in glpi db, we must create him */
511         $ldap->cat($id, array('cn', 'mail', 'telephoneNumber'));
512         $atr = $ldap->fetch();
513         $tmp = array();
514         $use = array( "cn"              =>"name",
515             "mail"            =>"email",
516             "telephoneNumber" =>"phone");
518         /* Create array */
519         foreach($use as $gosa => $glpi){
520           if(isset($atr[$gosa])){
521             $tmp[$glpi]= $atr[$gosa][0];
522           }
523         }
525         /* Add this user */
526         $this->handle->addUser($tmp,$id);
527       }
529       /* Re-read users */
530       $users = ($this->handle->getUsers());
532       /* Get user */
533       $tmp = array_flip($users);
534       $id=$tmp[$id];
536       /* Use user id, close dialog */
537       if($this->addUser == "tech"){
538         $this->tech_num = $id;
539       }else{
540         $this->contact_num = $id;
541       }
542       $this->cur_dialog   = false;
543       $this->dialog= false;
544     }
546     /* if( cur_dialog != false || cur_dialog != NULL) 
547      * There is a dialog which wants to be displayed 
548      */
549     if(isset($this->cur_dialog) && is_object($this->cur_dialog)){
550       $this->cur_dialog->save_object();
551       $this->dialog=true;
552       $this->cur_dialog->parent = &$this;
553       return($this->cur_dialog->execute());
554     }else{
555       $this->dialog= false;
556     }
558     /* Assign smarty defaults */ 
559     foreach(array("SystemTypes","SystemTypeKeys","Manufacturers","OSs","TechnicalResponsibles","InstalledDevices","Attachments") as $attr){
560       $smarty->assign($attr,array());
561     }
563     /* Assign some vars to smarty 
564      */
565     foreach(array("type","FK_glpi_enterprise","os","tech_num","contact_num","Attachments","InstalledDevices") as $attr){
566       $smarty->assign($attr,"");
567     }
569     /* Do we need to flip is_account state? */
570     if(isset($_POST['modify_state'])){
571       if($this->is_account && $this->acl_is_removeable()){
572         $this->is_account= FALSE;
573       }elseif(!$this->is_account && $this->acl_is_createable()){
574         $this->is_account= TRUE;
575       }
576     }
578     /* Show tab dialog headers */
579     if ($this->is_account){
580       $display= $this->show_disable_header(_("Remove inventory"),
581           _("This device has inventory informations enabled. You can disable them by clicking below."));
582     } else {
583       $display= $this->show_enable_header(_("Add inventory"),
584           _("This device has inventory informations disabled. You can enable them by clicking below."));
585       return ($display);
586     }
588     /* Assign system types 
589      */
590     $smarty->assign("SystemTypeKeys",         array_flip($this->handle->getSystemTypes()));
591     $smarty->assign("SystemTypes",            $this->handle->getSystemTypes());
592     $smarty->assign("type",                   $this->type);
594     /* Assign os types
595      */
596     $smarty->assign("OSKeys",                 array_flip($this->handle->getOSTypes()));
597     $smarty->assign("OSs",                    $this->handle->getOSTypes());
598     $smarty->assign("os",                     $this->os);
600     /* Dispaly installed devices */
601     $smarty->assign("InstalledDevices"        ,$this->getDevices());
602     $smarty->assign("InstalledDeviceKeys"     ,array_flip($this->getDevices()));
604     /* Append manufacturers
605      */
606     $smarty->assign("ManufacturerKeys",       array_flip($this->handle->getEnterprises()));
607     $smarty->assign("Manufacturers",          $this->handle->getEnterprises());
608     $smarty->assign("FK_glpi_enterprise",     $this->FK_glpi_enterprise);
610     /* Assign used Attachments
611     */
613     $divlist = new divSelectBox("glpiAttachmentsList");
614     $divlist-> SetHeight(130); 
615     $atts = $this->getUsedAttachments(true);
616     $downlink = "<a href='get_attachment.php?id=%s' target='_blank'>%s</a>";
617     $del_link = "<input type='image' src='images/edittrash.png' name='delAttachment_%s'>";
618     foreach($atts as $id => $attachment){
619       $divlist->AddEntry
620           (
621         array(
622             array("string"=>$attachment['name']),
623             array("string"=>$attachment['mime']),
624             array("string"=>sprintf($downlink,$id,$attachment['filename'])),
625             array("string"=>sprintf($del_link,$attachment['ID']),"attach"=>"style='border-right:0px;'"),
626              )
627           );
628     }
630     $smarty->assign("AttachmentsDiv"          ,$divlist->DrawList());
631     /* Handle contact person 
632        Assign name ... to smarty, if set
633      */ 
634     if(isset($users[$this->contact_num])){
635       $ldap->cat($users[$this->contact_num], array('givenName', 'sn', 'uid'));
636       $tr = $ldap->fetch();
637       $str = "";
638       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
639       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
640       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
641       $smarty->assign("contact_num",               $str);
642     }else{
643       $smarty->assign("contact_num",               _("N/A"));
644     }
646     /* Handle tech person 
647        Assign name ... to smarty, if set
648      */ 
649     if(isset($users[$this->tech_num])){
650       $tr = $ldap->cat($users[$this->tech_num], array('givenName', 'sn', 'uid'));
651       $tr = $ldap->fetch();
652       $str = "";
653       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
654       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
655       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
656       $smarty->assign("tech_num",               $str);
657     }else{
658       $smarty->assign("tech_num",               _("N/A"));
659     }
660     $smarty->assign("comments",               $this->comments);
662     $display.= $smarty->fetch(get_template_path('glpi.tpl', TRUE));
663     return($display);
664   }
666   function remove_from_parent()
667   {
668     /* Cancel if there's nothing to do here */
669     if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){
670       return;
671     }
672     if(function_exists("mysql_pconnect")){
673       $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
674       if($this->initially_was_account){
675         $this->handle->removeComputerInformations($this->dn); 
676         new log("remove","undefined/".get_class($this),$this->dn);
677       }
678     }else{
679       print_red(_("Can't remove glpi account, while mysql extension is missing."));
680       new log("remove","undefined/".get_class($this),$this->dn,array(),_("Can't remove glpi account, while mysql extension is missing."));
681     }
682   
683   }
685   function getDevices(){
686     $ret = array();
687     foreach($this->usedDevices as $type => $entries){
688       foreach($entries as $ent){
689         if(isset($ent['designation'])){
690           $ret[] = $ent['designation']." [".$type."]";
691         }else{
692           $ret[] = $ent['name']." [".$type."]";
693         }
694       }
695     }
696     return($ret); 
697   }
700   /* Save data to object */
701   function save_object()
702   {
703     if(!isset($_POST['glpi_tpl_posted'])) {
704       return ;
705     }
706     plugin::save_object();
707   }
710   /* Check supplied data */
711   function check()
712   {
713     /* Call common method to give check the hook */
714     $message= plugin::check();
716     //    if($this->TechnicalResponsible == ""){
717     //      $message[] = _("Please select a technical responsible person for this entry.");
718     //    }
720     return ($message);
721   }
724   /* Save to LDAP */
725   function save()
726   {
727     if($this->is_account){
728         $attrs = array();
729       $this->date_mod = date("Y-m-d H:i:s");
730       foreach($this->attributes as $attr){
731         $attrs[$attr] = $this->$attr;
732       }
733       $attrs['name'] = $this->dn;
734       unset($attrs['ID']);
735       $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
737       /* check if we have to update, add */
738       if($this->initially_was_account&&$this->is_account){
739         $this->handle->updateComputerInformations($attrs,$this->orig_dn);
740         new log("modify","undefined/".get_class($this),$this->dn);
741       }elseif($this->is_account){
742         $this->handle->addComputerInformations($attrs,$this->dn);
743         new log("create","undefined/".get_class($this),$this->dn);
744       }
745       $tmp = $this->handle->getComputerInformations($this->dn);
746       $this->handle->addDevicesToComputer($this->usedDevices,$tmp[0]['ID']);
747     }
748   }
751   /* Return used attachments */
752   function getUsedAttachments($divlist = false)
753   {
754     $atts =$this->handle->getAttachments();
755     $ret = array();
756     foreach($atts as $entry){
757       if(in_array($entry['ID'],$this->usedAttachments)){
758         if($divlist){
759           $ret[$entry['ID']] = $entry;
760         }else{
761           $cm ="";
762           if(isset($entry['comment'])){
763             $cm=" [".$entry['comment']."]";
764           }
765           if(isset($entry['mime'])){
766             $cm.=" -".$entry['mime']."";
767           }
769           $ret[$entry['ID']]= $entry['name'].$cm;
770         }
771       }
772     }
773     return($ret);
774   }
776    /* Return plugin informations for acl handling */
777   function plInfo()
778   {
779     return (array(
780           "plShortName"   => _("Glpi"),
781           "plDescription" => _("Inventory extension"),
782           "plSelfModify"  => FALSE,
783           "plDepends"     => array(),
784           "plPriority"    => 20,
785           "plSection"     => array("administration"),
786           "plCategory"    => array("workstation","terminal","component","server","phone") ,
787           "plProvidedAcls"=> array(
788           
789             "tech_num"            => _("Technical responsible"),
790             "comments"            => _("Comment"),
791             "os"                  => _("Operating system"),
792             "location"            => _("Location"),
793             "contact_num"         => _("Contact person"),
794             "model"               => _("Model"),
795             "type"                => _("Type"),
796             "FK_glpi_enterprise"  => _("Manufacturer"),
797             "Attachments"         => _("Attachments"),
798             "Devices"             => _("Peripheral devices"))
799           ));
800   }
801   
805 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
806 ?>