Code

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