Code

Updated logging
[gosa.git] / plugins / admin / systems / 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   /* Contructor 
70      Sets default values and checks if we already have an existing glpi account
71    */
72   function glpiPrinterAccount ($config, $dn= NULL, $parent= NULL)
73   {
74     plugin::plugin ($config, $dn, $parent);
75     $this->ui= get_userinfo();
77     $this->is_account = false;
79     /* Abort class construction, if no db is defined */
80     if(!isset($this->config->data['SERVERS']['GLPI'])){
81       return;
82     }
84     // Get informations about databse connection
85     $this->data = $this->config->data['SERVERS']['GLPI'];
87     // Abort if mysql extension is missing 
88     if(!is_callable("mysql_connect")){
89       return;
90     }
92     // Create handle of glpi class, and check if database connection is established 
93     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
95     if(!$this->handle->is_connected){
96       return;
97     } 
99     // If this dn is already used in database, then get all informations for this entry 
100     if($this->handle->is_printer_account($this->dn)){
101       $this->is_account = true;
102       $tmp = ($this->handle->getPrinterInformations($this->dn));
104       foreach(array("tech_num","FK_glpi_enterprise","type","comments","contact_num","flags_serial","flags_par","flags_usb","ramSize") as $attr){
105         $this->$attr = $tmp[0][$attr];
106       }
107       
108       $atts = $this->handle->getAssignPrinterAttachments($tmp[0]['ID']);
109       foreach($atts as $attachment){
110         $this->usedAttachments[$attachment['FK_doc']]=$attachment['FK_doc']; 
111       }
113       $cart= $this->handle->getUsedCartridges($tmp[0]['ID']);
114       foreach($cart as $key => $cartridge){
115         $this->usedCartridges[$key]=$cartridge; 
116         $this->usedCartridges[$key]['status']="exists"; 
117       }
120     }else{
121       $this->is_account = false;
122     }
124     /* set defaults */
125     $this->name                 = $this->dn;
126     $this->orig_dn              = $this->dn;
127     $this->initially_was_account = $this->is_account;
129     if($this->is_account){
130       @log::log("view","printer/".get_class($this),$this->dn); 
131     }
132   }
134   function execute()
135   {
136     /* Call parent execute */
137     plugin::execute();
139     /* Fill templating stuff */
140     $smarty= get_smarty();
141     $display= "";
143     $smarty->assign("CartridgesACL",$this->getacl("Cartridges"));
145     /*  Assign smarty defaults 
146         To avoid undefined indexes, if there is an error with the glpi db
147      */ 
148     foreach(array("PrinterTypeKeys","PrinterTypes","ManufacturerKeys","Manufacturers",
149                   "Attachments","AttachmentKeys","CartridgeKeys","Cartridges") as $attr){
150       $smarty->assign($attr,array());
151     }
152     foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","comments","flags_serial","flags_par","flags_usb","AttachmentsDiv") as $attr){
153       $smarty->assign($attr,"");
154     }
156     /* Assign acls */
157     $tmp = $this->plInfo();
158     foreach($tmp['plProvidedAcls'] as $name => $translation){
159       $smarty->assign($name."ACL",$this->getacl($name));
160     }
162     /* Check if there is a glpi database server defined 
163       */
164     if(!isset($this->config->data['SERVERS']['GLPI'])){
165       print_red(_("There is no server with valid glpi database service."));
166       return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
167     }
169     $this->data = $this->config->data['SERVERS']['GLPI'];
171     /* Check if we can call mysql_connect 
172        If we can't, there is no the mysql-php extension
173      */
174     if(!is_callable("mysql_connect")){
175       print_red(_("Can't connect to glpi database, the php-mysql extension is missing."));
176       return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
177     }
179     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
181     /*  If handle == false, abort
182         Seems that the server, username and or password is wrong
183      */
184     if(!$this->handle->is_connected){
185       print_red(_("Can't connect to glpi database, check configuration twice."));
186       return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
187     } 
189     /*  All checks are ok
190         Lets handle Posts, templates etc below ...
191      */
192     
193     $users = $this->handle->getUsers();
194     $ldap= $this->config->get_ldap_link();
196     
197     /*  ##########################################################################
198      *  Some tab management   
199      */
201     /* Do we need to flip is_account state? */
202     if(isset($_POST['modify_state'])){
203       if($this->is_account && $this->acl_is_removeable()){
204         $this->is_account= FALSE;
205       }elseif(!$this->is_account && $this->acl_is_createable()){
206         $this->is_account= TRUE;
207       }
208     }
210     /* Show tab dialog headers */
211     if ($this->is_account){
212       $display= $this->show_disable_header(_("Remove inventory"),
213           _("This server has inventory features enabled. You can disable them by clicking below."));
214     } else {
215       $display= $this->show_enable_header(_("Add inventory"),
216           _("This server has inventory features disabled. You can enable them by clicking below."));
217       return ($display);
218     }
220     
221     /*  ##########################################################################
222      *  Printer type management 
223      *  Dialog 
224      */
226     /* Rename was requested */
227     if(isset($_POST['Rename_PType_OK']) && $this->acl_is_writeable("type")){
228       $tmp = $this->handle->getPrinterTypes();
229       $allok = true;
230       foreach($tmp as $id => $name){
231         if(trim($name) == trim($_POST['string'])){
232           $allok = false;
233         }
234       }
235       if($allok){
236         $this->handle->updatePrinterType($_POST['string'],$this->select_type);
237         $this->rename = false;
238       }else{
239         print_red(sprintf(_("Can't rename given printer type to '%s', because this type name already exists."),$_POST['string']));
240       }
241     }
243     /* abort rename 
244      */
245     if(isset($_POST['Rename_Cancel'])){
246       $this->rename = false;
247     }
249     /* Printer type management
250      */
251     if(isset($_POST['edit_type']) && $this->acl_is_writeable("type")){
252       $this->dialog = true;
253       $this->edit_type=true;
254     }
256     /* This closes the printer type editing dialog
257      */
258     if(isset($_POST['close_edit_type'])){
259       $this->edit_type=false;
260       $this->dialog = false;
261     }
263     /* This appends a new printer to our sytem types
264      */
265     if((isset($_POST['add_type']))&&(!empty($_POST['type_string'])) && $this->acl_is_writeable("type")){
266     
267       $tmp = $this->handle->getPrinterTypes();
268       $allok = true;
269       foreach($tmp as $id => $name){
270         if(trim($name) == trim($_POST['type_string'])){
271           $allok = false;
272         }
273       }
274       if($allok){
275         $this->handle->addPrinterType($_POST['type_string']);  
276       }else{
277         print_red(sprintf(_("Can't rename given printer type to '%s', because this type name already exists."),$_POST['type_string']));
278       }
279     }
281     /* Remove selected type from our printer types list
282      */
283     if((isset($_POST['del_type']))&&(!empty($_POST['select_type'])) && $this->acl_is_writeable("type")){
284       $tmp = $this->handle->is_printerTypeUsed($_POST['select_type']);
285       if(count($tmp)){
286         $str = "";
287         foreach($tmp as $id => $name){
288           $str .= $name.", ";
289         }
290         $str = preg_replace("/, $/","",$str); 
291         print_red(sprintf(_("Can't delete printer type, it is still in use by '%s'."),$str));
292       }else{
293         $this->handle->removePrinterType($_POST['select_type']);  
294       }
295     }
297     /* Rename selected printer type to given string
298      */
299     if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))||($this->rename) && $this->acl_is_writeable("type")){
300       $this->rename = true;
302       $smarty->assign("Method","rename");
304       $tmp = $this->handle->getPrinterTypes();
306       if(isset($_POST['select_type'])){
307         $this->select_type = $_POST['select_type'];
308       }  
309       $smarty->assign("string",$tmp[$this->select_type]);
310       if(isset($_POST['string'])){
311         $smarty->assign("string",$_POST['string']);
312       }
314       $display= $smarty->fetch(get_template_path('glpi_edit_printer_type.tpl', TRUE));
315       return($display);
316     }  
318     /* Someone wants to edit the printer types ... 
319        So, lets open a new dialog which provides some buttons to edit the types
320      */
321     if($this->edit_type){
322       $smarty->assign("Method","edit");
323       $smarty->assign("PrinterTypes",            $this->handle->getPrinterTypes());
324       $smarty->assign("PrinterTypeKeys",         array_flip($this->handle->getPrinterTypes()));
325       $display= $smarty->fetch(get_template_path('glpi_edit_printer_type.tpl', TRUE));
326       return($display);
327     }
330     /*  ##########################################################################
331      *  Edit manufacturers 
332      *  Dialog 
333      */
335     /* Open dialog which allows to edit the manufacturers
336      */
337     if(isset($_POST['edit_manufacturer']) && $this->acl_is_writeable("FK_glpi_enterprise")){
338       $this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
339       $this->dialog = true;
340       $this->editManufacturer =true;
341     }
343     /* Close manufacturer editing dialog
344      */
345     if((isset($_POST['close_edit_manufacturer']))&&($this->editManufacturer)){
346       $this->dialog = false;
347       $this->cur_dialog = false;
348       $this->editManufacturer=false;
349     }
352     /*  ##########################################################################
353      *  Technical responsible person
354      *  Contact person 
355      *  Dialog 
356      */
358     /* Show dialog to select a new contact person
359      * Select a contact person
360      */
361     if(isset($_POST['SelectContactPerson']) && $this->acl_is_writeable("contact_num")){
362       $this->addUser = "contact";
363       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
364     }
366     /* Selecte technical responsible person
367      */
368     if(isset($_POST['SelectTechPerson']) && $this->acl_is_writeable("tech_num")){
369       $this->addUser ="tech";
370       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
371     }
373     /* Abort user selection
374      */
375     $smarty->assign("AbortSelectUser","SelectUserCancel");
376     if(isset($_POST['SelectUserCancel'])){
377       $this->dialog = false;
378       $this->addUser ="";
379       $this->cur_dialog = false;
380     }
382     /* Technical responsible/contact person selected */
383     if(isset($_GET['act'])&&($_GET['act']=="user_tech_num")){
385       /* Get posted id */
386       $id = base64_decode($_GET['id']);
388       /* Check if user is already created in glpi database */
389       if(!in_array($id,$users)){
391         /* If this user doesn't exists in glpi db, we must create him */
392         $ldap->cat($id, array('cn', 'mail', 'telephoneNumber'));
393         $atr = $ldap->fetch();
394         $tmp = array();
395         $use = array( "cn"              =>"name",
396             "mail"            =>"email",
397             "telephoneNumber" =>"phone");
399         /* Create array */
400         foreach($use as $gosa => $glpi){
401           if(isset($atr[$gosa])){
402             $tmp[$glpi]= $atr[$gosa][0];
403           }
404         }
406         /* Add this user */
407         $this->handle->addUser($tmp,$id);
408       }
410       /* Re-read users */
411       $users = ($this->handle->getUsers());
413       /* Get user */
414       $tmp = array_flip($users);
415       $id=$tmp[$id];
417       /* Use user id, close dialog */
418       if($this->addUser == "tech"){
419         $this->tech_num = $id;
420       }else{
421         $this->contact_num = $id;
422       }
423       $this->cur_dialog   = false;
424       $this->dialog= false;
425     }
428     /*  ##########################################################################
429      *  Handle attachments 
430      */
431     
432     /* Attachment pool was closed with use
433      */
434     if(isset($_POST['UseAttachment']) && $this->acl_is_writeable("Attachments")){
435       if(count($this->cur_dialog->check())){
436         foreach($this->cur_dialog->check() as $msg){
437           print_red($msg);
438         }
439       }else{
440         $this->cur_dialog->save_object();
441         $this->usedAttachments = $this->cur_dialog->save();
442         $this->cur_dialog = false;
443         $this->edit_type = false; 
444       }
445     }
446    
447     /* Attachment pool was closed with abort
448      */ 
449     if(isset($_POST['AbortAttachment'])){
450       $this->cur_dialog = false;
451       $this->edit_type = false; 
452     }
454     /* Open Attachment pool to add/edit Attachments
455      */
456     if(isset($_POST['AddAttachment']) && $this->acl_is_writeable("Attachments")){
457       $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
458       $this->dialog = true;
459     }
460     
461     /* Remove Attachment from this tab 
462      */
463     $once = true;
464     foreach($_POST as $name => $value){
465       if((preg_match("/^delAttachment_/",$name))&&($once) && $this->acl_is_writeable("Attachments")){
466         $once= false;
467         $name = preg_replace("/^delAttachment_/","",$name);
468         $entry = preg_replace("/_.*$/","",$name);
469         if(isset($this->usedAttachments[$entry])){
470           unset($this->usedAttachments[$entry]);
471         }
472       }
473     }
474     if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments'])) && $this->acl_is_writeable("Attachments")){
475       if(isset($this->usedAttachments[$_POST['Attachments']])){
476         unset($this->usedAttachments[$_POST['Attachments']]);
477       }
478     }
480     /*  ##########################################################################
481      *  Printer Cartridge handling 
482      */
484     /* Abort cartridge select dialog
485      */
486     if(isset($_POST['SelectCartridgeCancel'])){
487       $this->cur_dialog = false;
488       $this->edit_type = false; 
489     }
491     /* Get selected cartridges and add them to our list 
492      */ 
493     if(isset($_POST['SelectCartridgeSave'])){
494       $this->cur_dialog->save_object();
495       $carts = $this->cur_dialog->save();
496       foreach($carts as $cart){
497         $cart['status'] = "new";
498         $this->usedCartridges[] = $cart;
499       }
500       $this->cur_dialog = false;
501       $this->edit_type = false; 
502     }
504     /* Remove cartridge  
505      */
506     if((isset($_POST['RemoveCartridge']))&&(isset($_POST['Cartridges'])) && $this->acl_is_writeable("ManageCartridges")){
508       foreach($_POST['Cartridges'] as $cartID){
510         if(isset($this->usedCartridges[$cartID])){
511           if($this->usedCartridges[$cartID]['status'] == "exists"){
512             $this->usedCartridges[$cartID]['status'] = "deleted";
513           }else{
514             unset($this->usedCartridges[$cartID]);
515           }
516         }
517       }
518     }
520     /* Open Attachment pool to add/edit Attachments
521      */
522     if(isset($_POST['AddCartridge']) && $this->acl_is_writeable("ManageCartridges")){
523       $this->cur_dialog = new glpiPrinterCartridges($this->config,$this->dn,$this->type);
524       $this->dialog = true;
525     }
528     /*  ##########################################################################
529      *  Draw Dialogs
530      */
531     /* if( cur_dialog != false || cur_dialog != NULL) 
532      * There is a dialog which wants to be displayed 
533      */
534     if($this->cur_dialog){
535       $this->cur_dialog->save_object();
536       $this->dialog=true;
537       $this->cur_dialog->parent = &$this;
538       return($this->cur_dialog->execute());
539     }else{
540       $this->dialog= false;
541     }
544     /*  ##########################################################################
545      *  Assign listbox / checkbox .... values to smarty  
546      */
547     /* Assign smarty defaults */ 
548     foreach(array("PrinterTypes","PrinterTypeKeys","Manufacturers","TechnicalResponsibles","Attachments","Cartridges") as $attr){
549       $smarty->assign($attr,array());
550     }
552     /* Assign some vars to smarty 
553      */
554     foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","flags_serial","flags_par","flags_usb") as $attr){
555       $smarty->assign($attr,"");
556     }
558     $smarty->assign("comments",               $this->comments);
559     $smarty->assign("flags_serial",            $this->flags_serial);
560     $smarty->assign("flags_par",               $this->flags_par);
561     $smarty->assign("flags_usb",               $this->flags_usb);
563     /* Assign system types 
564      */
565     $smarty->assign("PrinterTypes",           $this->handle->getPrinterTypes());
566     $smarty->assign("PrinterTypeKeys",        array_flip($this->handle->getPrinterTypes()));
567     $smarty->assign("type",                   $this->type);
569     /* Append manufacturers
570      */
571     $smarty->assign("ManufacturerKeys",       array_flip($this->handle->getEnterprises()));
572     $smarty->assign("Manufacturers",          $this->handle->getEnterprises());
573     $smarty->assign("FK_glpi_enterprise",     $this->FK_glpi_enterprise);
575     /* Assign used Attachments
576     */
578     $divlist = new divSelectBox("glpiAttachmentsList");
579     $divlist-> SetHeight(120);
580     $atts = $this->getUsedAttachments(true);
581     $downlink = "<a href='get_attachment.php?id=%s' target='_blank'>%s</a>";
582     $del_link = "<input type='image' src='images/edittrash.png' name='delAttachment_%s'>";
583     foreach($atts as $id => $attachment){
584       $divlist->AddEntry
585           (
586         array(
587             array("string"=>$attachment['name']),
588             array("string"=>$attachment['mime']),
589             array("string"=>sprintf($downlink,$id,$attachment['filename'])),
590             array("string"=>sprintf($del_link,$attachment['ID']),"attach"=>"style='border-right:0px;'"),
591              )
592           );
593     }
595     $smarty->assign("AttachmentsDiv"          ,$divlist->DrawList());
596     $smarty->assign("Attachments",            $this->getUsedAttachments());
597     $smarty->assign("AttachmentKeys",         array_flip($this->getUsedAttachments()));
599     /* Assign Cartridges 
600      */
601     $smarty->assign("Cartridges",            $this->getUsedCartridges());
602     $smarty->assign("CartridgeKeys",         $this->getUsedCartridges(true));
604     /*  ##########################################################################
605      *  Assign contact and technical responsible person 
606      */
607     if(isset($users[$this->contact_num])){
608       $ldap->cat($users[$this->contact_num], array('givenName', 'sn', 'uid'));
609       $tr = $ldap->fetch();
610       $str = "";
611       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
612       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
613       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
614       $smarty->assign("contact_num",               $str);
615     }else{
616       $smarty->assign("contact_num",               _("N/A"));
617     }
619     /* Handle tech person 
620        Assign name ... to smarty, if set
621      */ 
622     if(isset($users[$this->tech_num])){
623       $ldap->cat($users[$this->tech_num], array('givenName', 'sn', 'uid'));
624       $tr = $ldap->fetch();
625       $str = "";
626       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
627       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
628       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
629       $smarty->assign("tech_num",               $str);
630     }else{
631       $smarty->assign("tech_num",               _("N/A"));
632     }
634     /* If theres a cartridge selected, you can't change the printer type.
635      */ 
636     $disp = true;
638     foreach($this->usedCartridges as $cart){
639       if($cart['status'] != "deleted"){
640         $disp = false;
641       }
642     }
643     if($disp==false){
644       $smarty->assign("typeACL", $this->getacl("type",true));
645     }
647     $display.= $smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE));
648     return($display);
649   }
651   function remove_from_parent()
652   {
653     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
654     if($this->initially_was_account){
655       $this->handle->removePrinterInformations($this->dn);
656       @log::log("remove","printer/".get_class($this),$this->dn); 
657     }
658   }
661   /* Save data to object */
662   function save_object()
663   {
664     if(isset($_POST['glpiPrinterFlagsPosted'])){
665       plugin::save_object();
666       foreach($this->attributes as $attrs){
667         if(isset($_POST[$attrs])){
668           $this->$attrs = $_POST[$attrs];
669         }
670       }
672       if(isset($_POST['FK_glpi_enterprise']) && $this->acl_is_writeable("FKglpienterprise")){
673         $this->FK_glpi_enterprise = $_POST['FK_glpi_enterprise'];
674       }
676       foreach(array("flags_serial","flags_par","flags_usb") as $checkboxes){
677         if($this->acl_is_writeable($checkboxes)){
678           if(isset($_POST[$checkboxes])){
679             $this->$checkboxes = 1;
680           }else{
681             $this->$checkboxes = 0;
682           }
683         }
684       }
685     }
687   }
690   /* Check supplied data */
691   function check()
692   {
693     /* Call common method to give check the hook */
694     $message= plugin::check();
696     //    if($this->TechnicalResponsible == ""){
697     //      $message[] = _("Please select a technical responsible person for this entry.");
698     //    }
700     return ($message);
701   }
703   /* Save to LDAP */
704   function save()
705   {
706     if($this->is_account){
707         $attrs = array();
708       $this->date_mod = date("Y-m-d H:i:s");
709       foreach($this->attributes as $attr){
710         $attrs[$attr] = $this->$attr;
711       }
712       $attrs['name'] = $this->dn;
713       unset($attrs['ID']);
714       $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
715       if($this->initially_was_account&&$this->is_account){
716         $this->handle->updatePrinterInformations($attrs,$this->dn);
717         @log::log("modify","printer/".get_class($this),$this->dn); 
718       }elseif($this->is_account){
719         $this->handle->addPrinterInformations($attrs,$this->dn);
720         @log::log("create","printer/".get_class($this),$this->dn); 
721       }
722       $tmp = $this->handle->getPrinterInformations($this->dn);
723       $this->handle->addAttachmentsToPrinter($this->usedAttachments,$tmp[0]['ID']);
725       foreach($this->usedCartridges as $cart){
726         if($cart['status'] == "deleted"){
727           $this->handle->removeCartridgeFromPrinter($cart['ID']);
728         }elseif($cart['status'] == "new"){
729           $this->handle->addCartridgeFromPrinter($tmp[0]['ID'],$cart['type_ID']);
730         }
731       }
732     }
733   }
735   /* Return used attachments */
736   function getUsedAttachments($divlist = false)
737   {
738     $atts =$this->handle->getAttachments();
739     $ret = array();
740     foreach($atts as $entry){
741       if(in_array($entry['ID'],$this->usedAttachments)){
742         if($divlist){
743           $ret[$entry['ID']] = $entry;
744         }else{
745           $cm ="";
746           if(isset($entry['comment'])){
747             $cm=" [".$entry['comment']."]";
748           }
749           if(isset($entry['mime'])){
750             $cm.=" -".$entry['mime']."";
751           }
753           $ret[$entry['ID']]= $entry['name'].$cm;
754         }
755       }
756     }
757     return($ret);
758   }
760   function getUsedCartridges($flip = false)
761   {
762     $ret = array();
763     foreach($this->usedCartridges as $key => $value){
764       if($value['status'] == "deleted") continue;
765       if($flip){
766         $ret[$key] = $key;    
767       }else{
768         $ret[$key] = $value['name']." [".$value['type_name']."] "._("since")." :".$value['date_use'];
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" => _("Printer inventory extension"),
780           "plSelfModify"  => FALSE,
781           "plDepends"     => array(),
782           "plPriority"    => 10,
783           "plSection"     => array("administration"),
784           "plCategory"    => array("printer"),
786           "plProvidedAcls"=> array(
787             "flags_serial"         => _("Supports serial interface"),
788             "flags_par"            => _("Supports parallel interface"),
789             "flags_usb"            => _("Supports usb interface"),
790             "tech_num"             => _("Technical responsible"),
791             "comments"             => _("Comments"),
792             "location"             => _("Location"),
793             "contact_num"          => _("Contact person"),
794             "type"                 => _("Type"),
795             "FKglpienterprise"   => _("Manufacturer"),
797             "Attachments"          => _("Attachments"),
798         
799             "ManageCartridges"            => _("Cartridge settings"))
800           ));
801   }
803 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
804 ?>