Code

Updated trunk, introduced gosa-core
[gosa.git] / plugins / admin / systems / services / glpi / class_glpiPrinterAccount.inc
1 <?php
3 class glpiPrinterAccount 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","ramSize","flags_serial","flags_par","flags_usb",
13       "tech_num","comments","date_mod","location","domain","network","contact_num","serial","otherserial",
14       "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 $FK_glpi_enterprise = 0;     // Manufacturer id
19   var $tech_num           = "";    // Technical responsible person
20   var $contact_num        = "";    // Contact person
21   
22   var $comments           = "";    // Comment
23   
24   var $type               = 0;     // printer type id
25   var $serial             = "";   
26   var $otherserial        = "";  
27   var $ramSize            = 0;
28   var $flags_serial       = false;
29   var $flags_par          = false;
30   var $flags_usb          = false;
32   var $date_mod           = "";    // Modification timestamp
33   
34   var $location           = 0;     // Not used yet
35   var $domain             = 0;     // ? Set to 0
36   var $network            = 0;     // ? Set to 0 
38   var $is_template        = 0;     // Used as template ?
39   var $contact            = "";    // Empty
40   var $deleted            = "N";   // Deleted entries should have this set to Y
42   var $rename             = false;
43   var $select_type        ;
45   var $editManufacturer   = false;
47   /* Not necessary, cause we use mysql databse */
48   var $objectclasses= array("whatever");
50   /* Used to remember if this was an account (simply: is this an edited entry) */
51   var $initially_was_account = false;
53   /* Remember current dialog */
54   var $edit_type            = false;
55   var $edit_os              = false;
57   var $data;
58   var $handle = NULL;               // Glpi class handle used to query database
60   var $cur_dialog = NULL;           // This contains the sub dialog handle
62   var $orig_dn;                     // To check if dn, has changed 
63   var $ui;                          // Some GOsa specific user informations 
64   
65   var $usedDevices      = array();  // Which devices are currently selected 
66   var $usedAttachments  = array();  // Used Attachments 
67   var $usedCartridges   = array();  // Used Cartridges
69   var $view_logged      = FALSE;
71   /* Contructor 
72      Sets default values and checks if we already have an existing glpi account
73    */
74   function glpiPrinterAccount (&$config, $dn= NULL, $parent= NULL)
75   {
76     plugin::plugin ($config, $dn, $parent);
77     $this->ui= get_userinfo();
79     $this->is_account = false;
81     /* Abort class construction, if no db is defined */
82     if(!isset($this->config->data['SERVERS']['GLPI'])){
83       return;
84     }
86     // Get informations about databse connection
87     $this->data = $this->config->data['SERVERS']['GLPI'];
89     // Abort if mysql extension is missing 
90     if(!is_callable("mysql_connect")){
91       return;
92     }
94     // Create handle of glpi class, and check if database connection is established 
95     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
97     if(!$this->handle->is_connected){
98       return;
99     } 
101     // If this dn is already used in database, then get all informations for this entry 
102     if($this->handle->is_printer_account($this->dn)){
103       $this->is_account = true;
104       $tmp = ($this->handle->getPrinterInformations($this->dn));
106       foreach(array("tech_num","FK_glpi_enterprise","type","comments","contact_num","flags_serial","flags_par","flags_usb","ramSize") as $attr){
107         $this->$attr = $tmp[0][$attr];
108       }
109       
110       $atts = $this->handle->getAssignPrinterAttachments($tmp[0]['ID']);
111       foreach($atts as $attachment){
112         $this->usedAttachments[$attachment['FK_doc']]=$attachment['FK_doc']; 
113       }
115       $cart= $this->handle->getUsedCartridges($tmp[0]['ID']);
116       foreach($cart as $key => $cartridge){
117         $this->usedCartridges[$key]=$cartridge; 
118         $this->usedCartridges[$key]['status']="exists"; 
119       }
122     }else{
123       $this->is_account = false;
124     }
126     /* set defaults */
127     $this->name                 = $this->dn;
128     $this->orig_dn              = $this->dn;
129     $this->initially_was_account = $this->is_account;
130   }
132   function execute()
133   {
134     /* Call parent execute */
135     plugin::execute();
137     if($this->is_account && !$this->view_logged){
138       $this->view_logged = TRUE;
139       new log("view","printer/".get_class($this),$this->dn);
140     }
142     /* Fill templating stuff */
143     $smarty= get_smarty();
144     $display= "";
146     $smarty->assign("CartridgesACL",$this->getacl("Cartridges"));
148     /*  Assign smarty defaults 
149         To avoid undefined indexes, if there is an error with the glpi db
150      */ 
151     foreach(array("PrinterTypeKeys","PrinterTypes","ManufacturerKeys","Manufacturers",
152                   "Attachments","AttachmentKeys","CartridgeKeys","Cartridges") as $attr){
153       $smarty->assign($attr,array());
154     }
155     foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","comments","flags_serial","flags_par","flags_usb","AttachmentsDiv") as $attr){
156       $smarty->assign($attr,"");
157     }
159     /* Assign acls */
160     $tmp = $this->plInfo();
161     foreach($tmp['plProvidedAcls'] as $name => $translation){
162       $smarty->assign($name."ACL",$this->getacl($name));
163     }
165     /* Check if there is a glpi database server defined 
166       */
167     if(!isset($this->config->data['SERVERS']['GLPI'])){
168       print_red(_("There is no server with valid glpi database service."));
169       return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
170     }
172     $this->data = $this->config->data['SERVERS']['GLPI'];
174     /* Check if we can call mysql_connect 
175        If we can't, there is no the mysql-php extension
176      */
177     if(!is_callable("mysql_connect")){
178       print_red(_("Can't connect to glpi database, the php-mysql extension is missing."));
179       return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
180     }
182     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
184     /*  If handle == false, abort
185         Seems that the server, username and or password is wrong
186      */
187     if(!$this->handle->is_connected){
188       print_red(_("Can't connect to glpi database, check configuration twice."));
189       return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
190     } 
192     /*  All checks are ok
193         Lets handle Posts, templates etc below ...
194      */
195     
196     $users = $this->handle->getUsers();
197     $ldap= $this->config->get_ldap_link();
199     
200     /*  ##########################################################################
201      *  Some tab management   
202      */
204     /* Do we need to flip is_account state? */
205     if(isset($_POST['modify_state'])){
206       if($this->is_account && $this->acl_is_removeable()){
207         $this->is_account= FALSE;
208       }elseif(!$this->is_account && $this->acl_is_createable()){
209         $this->is_account= TRUE;
210       }
211     }
213     /* Show tab dialog headers */
214     if ($this->is_account){
215       $display= $this->show_disable_header(_("Remove inventory"),
216           _("This server has inventory features enabled. You can disable them by clicking below."));
217     } else {
218       $display= $this->show_enable_header(_("Add inventory"),
219           _("This server has inventory features disabled. You can enable them by clicking below."));
220       return ($display);
221     }
223     
224     /*  ##########################################################################
225      *  Printer type management 
226      *  Dialog 
227      */
229     /* Rename was requested */
230     if(isset($_POST['Rename_PType_OK']) && $this->acl_is_writeable("type")){
231       $tmp = $this->handle->getPrinterTypes();
232       $allok = true;
233       foreach($tmp as $id => $name){
234         if(trim($name) == trim($_POST['string'])){
235           $allok = false;
236         }
237       }
238       if($allok){
239         $this->handle->updatePrinterType($_POST['string'],$this->select_type);
240         $this->rename = false;
241       }else{
242         print_red(sprintf(_("Can't rename given printer type to '%s', because this type name already exists."),$_POST['string']));
243       }
244     }
246     /* abort rename 
247      */
248     if(isset($_POST['Rename_Cancel'])){
249       $this->rename = false;
250     }
252     /* Printer type management
253      */
254     if(isset($_POST['edit_type']) && $this->acl_is_writeable("type")){
255       $this->dialog = true;
256       $this->edit_type=true;
257     }
259     /* This closes the printer type editing dialog
260      */
261     if(isset($_POST['close_edit_type'])){
262       $this->edit_type=false;
263       $this->dialog = false;
264     }
266     /* This appends a new printer to our sytem types
267      */
268     if((isset($_POST['add_type']))&&(!empty($_POST['type_string'])) && $this->acl_is_writeable("type")){
269     
270       $tmp = $this->handle->getPrinterTypes();
271       $allok = true;
272       foreach($tmp as $id => $name){
273         if(trim($name) == trim($_POST['type_string'])){
274           $allok = false;
275         }
276       }
277       if($allok){
278         $this->handle->addPrinterType($_POST['type_string']);  
279       }else{
280         print_red(sprintf(_("Can't rename given printer type to '%s', because this type name already exists."),$_POST['type_string']));
281       }
282     }
284     /* Remove selected type from our printer types list
285      */
286     if((isset($_POST['del_type']))&&(!empty($_POST['select_type'])) && $this->acl_is_writeable("type")){
287       $tmp = $this->handle->is_printerTypeUsed($_POST['select_type']);
288       if(count($tmp)){
289         $str = "";
290         foreach($tmp as $id => $name){
291           $str .= $name.", ";
292         }
293         $str = preg_replace("/, $/","",$str); 
294         print_red(sprintf(_("Can't delete printer type, it is still in use by '%s'."),$str));
295       }else{
296         $this->handle->removePrinterType($_POST['select_type']);  
297       }
298     }
300     /* Rename selected printer type to given string
301      */
302     if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))||($this->rename) && $this->acl_is_writeable("type")){
303       $this->rename = true;
305       $smarty->assign("Method","rename");
307       $tmp = $this->handle->getPrinterTypes();
309       if(isset($_POST['select_type'])){
310         $this->select_type = $_POST['select_type'];
311       }  
312       $smarty->assign("string",$tmp[$this->select_type]);
313       if(isset($_POST['string'])){
314         $smarty->assign("string",$_POST['string']);
315       }
317       $display= $smarty->fetch(get_template_path('glpi_edit_printer_type.tpl', TRUE));
318       return($display);
319     }  
321     /* Someone wants to edit the printer types ... 
322        So, lets open a new dialog which provides some buttons to edit the types
323      */
324     if($this->edit_type){
325       $smarty->assign("Method","edit");
326       $smarty->assign("PrinterTypes",            $this->handle->getPrinterTypes());
327       $smarty->assign("PrinterTypeKeys",         array_flip($this->handle->getPrinterTypes()));
328       $display= $smarty->fetch(get_template_path('glpi_edit_printer_type.tpl', TRUE));
329       return($display);
330     }
333     /*  ##########################################################################
334      *  Edit manufacturers 
335      *  Dialog 
336      */
338     /* Open dialog which allows to edit the manufacturers
339      */
340     if(isset($_POST['edit_manufacturer']) && $this->acl_is_writeable("FK_glpi_enterprise")){
341       $this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
342       $this->dialog = true;
343       $this->editManufacturer =true;
344     }
346     /* Close manufacturer editing dialog
347      */
348     if((isset($_POST['close_edit_manufacturer']))&&($this->editManufacturer)){
349       $this->dialog = false;
350       $this->cur_dialog = false;
351       $this->editManufacturer=false;
352     }
355     /*  ##########################################################################
356      *  Technical responsible person
357      *  Contact person 
358      *  Dialog 
359      */
361     /* Show dialog to select a new contact person
362      * Select a contact person
363      */
364     if(isset($_POST['SelectContactPerson']) && $this->acl_is_writeable("contact_num")){
365       $this->addUser = "contact";
366       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
367     }
369     /* Selecte technical responsible person
370      */
371     if(isset($_POST['SelectTechPerson']) && $this->acl_is_writeable("tech_num")){
372       $this->addUser ="tech";
373       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
374     }
376     /* Abort user selection
377      */
378     $smarty->assign("AbortSelectUser","SelectUserCancel");
379     if(isset($_POST['SelectUserCancel'])){
380       $this->dialog = false;
381       $this->addUser ="";
382       $this->cur_dialog = false;
383     }
385     /* Technical responsible/contact person selected */
386     if(isset($_GET['act'])&&($_GET['act']=="user_tech_num")){
388       /* Get posted id */
389       $id = base64_decode($_GET['id']);
391       /* Check if user is already created in glpi database */
392       if(!in_array($id,$users)){
394         /* If this user doesn't exists in glpi db, we must create him */
395         $ldap->cat($id, array('cn', 'mail', 'telephoneNumber'));
396         $atr = $ldap->fetch();
397         $tmp = array();
398         $use = array( "cn"              =>"name",
399             "mail"            =>"email",
400             "telephoneNumber" =>"phone");
402         /* Create array */
403         foreach($use as $gosa => $glpi){
404           if(isset($atr[$gosa])){
405             $tmp[$glpi]= $atr[$gosa][0];
406           }
407         }
409         /* Add this user */
410         $this->handle->addUser($tmp,$id);
411       }
413       /* Re-read users */
414       $users = ($this->handle->getUsers());
416       /* Get user */
417       $tmp = array_flip($users);
418       $id=$tmp[$id];
420       /* Use user id, close dialog */
421       if($this->addUser == "tech"){
422         $this->tech_num = $id;
423       }else{
424         $this->contact_num = $id;
425       }
426       $this->cur_dialog   = false;
427       $this->dialog= false;
428     }
431     /*  ##########################################################################
432      *  Handle attachments 
433      */
434     
435     /* Attachment pool was closed with use
436      */
437     if(isset($_POST['UseAttachment']) && $this->acl_is_writeable("Attachments")){
438       if(count($this->cur_dialog->check())){
439         foreach($this->cur_dialog->check() as $msg){
440           print_red($msg);
441         }
442       }else{
443         $this->cur_dialog->save_object();
444         $this->usedAttachments = $this->cur_dialog->save();
445         $this->cur_dialog = false;
446         $this->edit_type = false; 
447       }
448     }
449    
450     /* Attachment pool was closed with abort
451      */ 
452     if(isset($_POST['AbortAttachment'])){
453       $this->cur_dialog = false;
454       $this->edit_type = false; 
455     }
457     /* Open Attachment pool to add/edit Attachments
458      */
459     if(isset($_POST['AddAttachment']) && $this->acl_is_writeable("Attachments")){
460       $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
461       $this->dialog = true;
462     }
463     
464     /* Remove Attachment from this tab 
465      */
466     $once = true;
467     foreach($_POST as $name => $value){
468       if((preg_match("/^delAttachment_/",$name))&&($once) && $this->acl_is_writeable("Attachments")){
469         $once= false;
470         $name = preg_replace("/^delAttachment_/","",$name);
471         $entry = preg_replace("/_.*$/","",$name);
472         if(isset($this->usedAttachments[$entry])){
473           unset($this->usedAttachments[$entry]);
474         }
475       }
476     }
477     if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments'])) && $this->acl_is_writeable("Attachments")){
478       if(isset($this->usedAttachments[$_POST['Attachments']])){
479         unset($this->usedAttachments[$_POST['Attachments']]);
480       }
481     }
483     /*  ##########################################################################
484      *  Printer Cartridge handling 
485      */
487     /* Abort cartridge select dialog
488      */
489     if(isset($_POST['SelectCartridgeCancel'])){
490       $this->cur_dialog = false;
491       $this->edit_type = false; 
492     }
494     /* Get selected cartridges and add them to our list 
495      */ 
496     if(isset($_POST['SelectCartridgeSave'])){
497       $this->cur_dialog->save_object();
498       $carts = $this->cur_dialog->save();
499       foreach($carts as $cart){
500         $cart['status'] = "new";
501         $this->usedCartridges[] = $cart;
502       }
503       $this->cur_dialog = false;
504       $this->edit_type = false; 
505     }
507     /* Remove cartridge  
508      */
509     if((isset($_POST['RemoveCartridge']))&&(isset($_POST['Cartridges'])) && $this->acl_is_writeable("ManageCartridges")){
511       foreach($_POST['Cartridges'] as $cartID){
513         if(isset($this->usedCartridges[$cartID])){
514           if($this->usedCartridges[$cartID]['status'] == "exists"){
515             $this->usedCartridges[$cartID]['status'] = "deleted";
516           }else{
517             unset($this->usedCartridges[$cartID]);
518           }
519         }
520       }
521     }
523     /* Open Attachment pool to add/edit Attachments
524      */
525     if(isset($_POST['AddCartridge']) && $this->acl_is_writeable("ManageCartridges")){
526       $this->cur_dialog = new glpiPrinterCartridges($this->config,$this->dn,$this->type);
527       $this->dialog = true;
528     }
531     /*  ##########################################################################
532      *  Draw Dialogs
533      */
534     /* if( cur_dialog != false || cur_dialog != NULL) 
535      * There is a dialog which wants to be displayed 
536      */
537     if($this->cur_dialog && is_object($this->cur_dialog)){
538       $this->cur_dialog->save_object();
539       $this->dialog=true;
540       $this->cur_dialog->parent = &$this;
541       return($this->cur_dialog->execute());
542     }else{
543       $this->dialog= false;
544     }
547     /*  ##########################################################################
548      *  Assign listbox / checkbox .... values to smarty  
549      */
550     /* Assign smarty defaults */ 
551     foreach(array("PrinterTypes","PrinterTypeKeys","Manufacturers","TechnicalResponsibles","Attachments","Cartridges") as $attr){
552       $smarty->assign($attr,array());
553     }
555     /* Assign some vars to smarty 
556      */
557     foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","flags_serial","flags_par","flags_usb") as $attr){
558       $smarty->assign($attr,"");
559     }
561     $smarty->assign("comments",               $this->comments);
562     $smarty->assign("flags_serial",            $this->flags_serial);
563     $smarty->assign("flags_par",               $this->flags_par);
564     $smarty->assign("flags_usb",               $this->flags_usb);
566     /* Assign system types 
567      */
568     $smarty->assign("PrinterTypes",           $this->handle->getPrinterTypes());
569     $smarty->assign("PrinterTypeKeys",        array_flip($this->handle->getPrinterTypes()));
570     $smarty->assign("type",                   $this->type);
572     /* Append manufacturers
573      */
574     $smarty->assign("ManufacturerKeys",       array_flip($this->handle->getEnterprises()));
575     $smarty->assign("Manufacturers",          $this->handle->getEnterprises());
576     $smarty->assign("FK_glpi_enterprise",     $this->FK_glpi_enterprise);
578     /* Assign used Attachments
579     */
581     $divlist = new divSelectBox("glpiAttachmentsList");
582     $divlist-> SetHeight(120);
583     $atts = $this->getUsedAttachments(true);
584     $downlink = "<a href='get_attachment.php?id=%s' target='_blank'>%s</a>";
585     $del_link = "<input type='image' src='images/edittrash.png' name='delAttachment_%s'>";
586     foreach($atts as $id => $attachment){
587       $divlist->AddEntry
588           (
589         array(
590             array("string"=>$attachment['name']),
591             array("string"=>$attachment['mime']),
592             array("string"=>sprintf($downlink,$id,$attachment['filename'])),
593             array("string"=>sprintf($del_link,$attachment['ID']),"attach"=>"style='border-right:0px;'"),
594              )
595           );
596     }
598     $smarty->assign("AttachmentsDiv"          ,$divlist->DrawList());
599     $smarty->assign("Attachments",            $this->getUsedAttachments());
600     $smarty->assign("AttachmentKeys",         array_flip($this->getUsedAttachments()));
602     /* Assign Cartridges 
603      */
604     $smarty->assign("Cartridges",            $this->getUsedCartridges());
605     $smarty->assign("CartridgeKeys",         $this->getUsedCartridges(true));
607     /*  ##########################################################################
608      *  Assign contact and technical responsible person 
609      */
610     if(isset($users[$this->contact_num])){
611       $ldap->cat($users[$this->contact_num], array('givenName', 'sn', 'uid'));
612       $tr = $ldap->fetch();
613       $str = "";
614       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
615       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
616       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
617       $smarty->assign("contact_num",               $str);
618     }else{
619       $smarty->assign("contact_num",               _("N/A"));
620     }
622     /* Handle tech person 
623        Assign name ... to smarty, if set
624      */ 
625     if(isset($users[$this->tech_num])){
626       $ldap->cat($users[$this->tech_num], array('givenName', 'sn', 'uid'));
627       $tr = $ldap->fetch();
628       $str = "";
629       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
630       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
631       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
632       $smarty->assign("tech_num",               $str);
633     }else{
634       $smarty->assign("tech_num",               _("N/A"));
635     }
637     /* If theres a cartridge selected, you can't change the printer type.
638      */ 
639     $disp = true;
641     foreach($this->usedCartridges as $cart){
642       if($cart['status'] != "deleted"){
643         $disp = false;
644       }
645     }
646     if($disp==false){
647       $smarty->assign("typeACL", $this->getacl("type",true));
648     }
650     $display.= $smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE));
651     return($display);
652   }
654   function remove_from_parent()
655   {
656     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
657     if($this->initially_was_account){
658       $this->handle->removePrinterInformations($this->dn);
659       new log("remove","printer/".get_class($this),$this->dn); 
660     }
661   }
664   /* Save data to object */
665   function save_object()
666   {
667     if(isset($_POST['glpiPrinterFlagsPosted'])){
668       plugin::save_object();
669       foreach($this->attributes as $attrs){
670         if(isset($_POST[$attrs])){
671           $this->$attrs = $_POST[$attrs];
672         }
673       }
675       if(isset($_POST['FK_glpi_enterprise']) && $this->acl_is_writeable("FKglpienterprise")){
676         $this->FK_glpi_enterprise = $_POST['FK_glpi_enterprise'];
677       }
679       foreach(array("flags_serial","flags_par","flags_usb") as $checkboxes){
680         if($this->acl_is_writeable($checkboxes)){
681           if(isset($_POST[$checkboxes])){
682             $this->$checkboxes = 1;
683           }else{
684             $this->$checkboxes = 0;
685           }
686         }
687       }
688     }
690   }
693   /* Check supplied data */
694   function check()
695   {
696     /* Call common method to give check the hook */
697     $message= plugin::check();
699     //    if($this->TechnicalResponsible == ""){
700     //      $message[] = _("Please select a technical responsible person for this entry.");
701     //    }
703     return ($message);
704   }
706   /* Save to LDAP */
707   function save()
708   {
709     if($this->is_account){
710         $attrs = array();
711       $this->date_mod = date("Y-m-d H:i:s");
712       foreach($this->attributes as $attr){
713         $attrs[$attr] = $this->$attr;
714       }
715       $attrs['name'] = $this->dn;
716       unset($attrs['ID']);
717       $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
718       if($this->initially_was_account&&$this->is_account){
719         $this->handle->updatePrinterInformations($attrs,$this->dn);
720         new log("modify","printer/".get_class($this),$this->dn); 
721       }elseif($this->is_account){
722         $this->handle->addPrinterInformations($attrs,$this->dn);
723         new log("create","printer/".get_class($this),$this->dn); 
724       }
725       $tmp = $this->handle->getPrinterInformations($this->dn);
726       $this->handle->addAttachmentsToPrinter($this->usedAttachments,$tmp[0]['ID']);
728       foreach($this->usedCartridges as $cart){
729         if($cart['status'] == "deleted"){
730           $this->handle->removeCartridgeFromPrinter($cart['ID']);
731         }elseif($cart['status'] == "new"){
732           $this->handle->addCartridgeFromPrinter($tmp[0]['ID'],$cart['type_ID']);
733         }
734       }
735     }
736   }
738   /* Return used attachments */
739   function getUsedAttachments($divlist = false)
740   {
741     $atts =$this->handle->getAttachments();
742     $ret = array();
743     foreach($atts as $entry){
744       if(in_array($entry['ID'],$this->usedAttachments)){
745         if($divlist){
746           $ret[$entry['ID']] = $entry;
747         }else{
748           $cm ="";
749           if(isset($entry['comment'])){
750             $cm=" [".$entry['comment']."]";
751           }
752           if(isset($entry['mime'])){
753             $cm.=" -".$entry['mime']."";
754           }
756           $ret[$entry['ID']]= $entry['name'].$cm;
757         }
758       }
759     }
760     return($ret);
761   }
763   function getUsedCartridges($flip = false)
764   {
765     $ret = array();
766     foreach($this->usedCartridges as $key => $value){
767       if($value['status'] == "deleted") continue;
768       if($flip){
769         $ret[$key] = $key;    
770       }else{
771         $ret[$key] = $value['name']." [".$value['type_name']."] "._("since")." :".$value['date_use'];
772       }
773     }
774     return($ret);
775   }  
777      /* Return plugin informations for acl handling */
778   static function plInfo()
779   {
780     return (array(
781           "plShortName"   => _("Glpi"),
782           "plDescription" => _("Printer inventory extension"),
783           "plSelfModify"  => FALSE,
784           "plDepends"     => array(),
785           "plPriority"    => 10,
786           "plSection"     => array("administration"),
787           "plCategory"    => array("printer"),
789           "plProvidedAcls"=> array(
790             "flags_serial"         => _("Supports serial interface"),
791             "flags_par"            => _("Supports parallel interface"),
792             "flags_usb"            => _("Supports usb interface"),
793             "tech_num"             => _("Technical responsible"),
794             "comments"             => _("Comments"),
795             "location"             => _("Location"),
796             "contact_num"          => _("Contact person"),
797             "type"                 => _("Type"),
798             "FKglpienterprise"   => _("Manufacturer"),
800             "Attachments"          => _("Attachments"),
801         
802             "ManageCartridges"            => _("Cartridge settings"))
803           ));
804   }
806 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
807 ?>