Code

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