Code

Fixed broken tags
[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;
128   }
130   function execute()
131   {
132     /* Call parent execute */
133     plugin::execute();
135     /* Fill templating stuff */
136     $smarty= get_smarty();
137     $display= "";
139     $smarty->assign("CartridgesACL",$this->getacl("Cartridges"));
141     /*  Assign smarty defaults 
142         To avoid undefined indexes, if there is an error with the glpi db
143      */ 
144     foreach(array("PrinterTypeKeys","PrinterTypes","ManufacturerKeys","Manufacturers",
145                   "Attachments","AttachmentKeys","CartridgeKeys","Cartridges") as $attr){
146       $smarty->assign($attr,array());
147     }
148     foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","comments","flags_serial","flags_par","flags_usb","AttachmentsDiv") as $attr){
149       $smarty->assign($attr,"");
150     }
152     /* Assign acls */
153     $tmp = $this->plInfo();
154     foreach($tmp['plProvidedAcls'] as $name => $translation){
155       $smarty->assign($name."ACL",$this->getacl($name));
156     }
158     /* Check if there is a glpi database server defined 
159       */
160     if(!isset($this->config->data['SERVERS']['GLPI'])){
161       print_red(_("There is no server with valid glpi database service."));
162       return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
163     }
165     $this->data = $this->config->data['SERVERS']['GLPI'];
167     /* Check if we can call mysql_connect 
168        If we can't, there is no the mysql-php extension
169      */
170     if(!is_callable("mysql_connect")){
171       print_red(_("Can't connect to glpi database, the php-mysql extension is missing."));
172       return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
173     }
175     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
177     /*  If handle == false, abort
178         Seems that the server, username and or password is wrong
179      */
180     if(!$this->handle->is_connected){
181       print_red(_("Can't connect to glpi database, check configuration twice."));
182       return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
183     } 
185     /*  All checks are ok
186         Lets handle Posts, templates etc below ...
187      */
188     
189     $users = $this->handle->getUsers();
190     $ldap= $this->config->get_ldap_link();
192     
193     /*  ##########################################################################
194      *  Some tab management   
195      */
197     /* Do we need to flip is_account state? */
198     if(isset($_POST['modify_state'])){
199       if($this->is_account && $this->acl_is_removeable()){
200         $this->is_account= FALSE;
201       }elseif(!$this->is_account && $this->acl_is_createable()){
202         $this->is_account= TRUE;
203       }
204     }
206     /* Show tab dialog headers */
207     if ($this->is_account){
208       $display= $this->show_disable_header(_("Remove inventory"),
209           _("This server has inventory features enabled. You can disable them by clicking below."));
210     } else {
211       $display= $this->show_enable_header(_("Add inventory"),
212           _("This server has inventory features disabled. You can enable them by clicking below."));
213       return ($display);
214     }
216     
217     /*  ##########################################################################
218      *  Printer type management 
219      *  Dialog 
220      */
222     /* Rename was requested */
223     if(isset($_POST['Rename_PType_OK']) && $this->acl_is_writeable("type")){
224       $tmp = $this->handle->getPrinterTypes();
225       $allok = true;
226       foreach($tmp as $id => $name){
227         if(trim($name) == trim($_POST['string'])){
228           $allok = false;
229         }
230       }
231       if($allok){
232         $this->handle->updatePrinterType($_POST['string'],$this->select_type);
233         $this->rename = false;
234       }else{
235         print_red(sprintf(_("Can't rename given printer type to '%s', because this type name already exists."),$_POST['string']));
236       }
237     }
239     /* abort rename 
240      */
241     if(isset($_POST['Rename_Cancel'])){
242       $this->rename = false;
243     }
245     /* Printer type management
246      */
247     if(isset($_POST['edit_type']) && $this->acl_is_writeable("type")){
248       $this->dialog = true;
249       $this->edit_type=true;
250     }
252     /* This closes the printer type editing dialog
253      */
254     if(isset($_POST['close_edit_type'])){
255       $this->edit_type=false;
256       $this->dialog = false;
257     }
259     /* This appends a new printer to our sytem types
260      */
261     if((isset($_POST['add_type']))&&(!empty($_POST['type_string'])) && $this->acl_is_writeable("type")){
262     
263       $tmp = $this->handle->getPrinterTypes();
264       $allok = true;
265       foreach($tmp as $id => $name){
266         if(trim($name) == trim($_POST['type_string'])){
267           $allok = false;
268         }
269       }
270       if($allok){
271         $this->handle->addPrinterType($_POST['type_string']);  
272       }else{
273         print_red(sprintf(_("Can't rename given printer type to '%s', because this type name already exists."),$_POST['type_string']));
274       }
275     }
277     /* Remove selected type from our printer types list
278      */
279     if((isset($_POST['del_type']))&&(!empty($_POST['select_type'])) && $this->acl_is_writeable("type")){
280       $tmp = $this->handle->is_printerTypeUsed($_POST['select_type']);
281       if(count($tmp)){
282         $str = "";
283         foreach($tmp as $id => $name){
284           $str .= $name.", ";
285         }
286         $str = preg_replace("/, $/","",$str); 
287         print_red(sprintf(_("Can't delete printer type, it is still in use by '%s'."),$str));
288       }else{
289         $this->handle->removePrinterType($_POST['select_type']);  
290       }
291     }
293     /* Rename selected printer type to given string
294      */
295     if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))||($this->rename) && $this->acl_is_writeable("type")){
296       $this->rename = true;
298       $smarty->assign("Method","rename");
300       $tmp = $this->handle->getPrinterTypes();
302       if(isset($_POST['select_type'])){
303         $this->select_type = $_POST['select_type'];
304       }  
305       $smarty->assign("string",$tmp[$this->select_type]);
306       if(isset($_POST['string'])){
307         $smarty->assign("string",$_POST['string']);
308       }
310       $display= $smarty->fetch(get_template_path('glpi_edit_printer_type.tpl', TRUE));
311       return($display);
312     }  
314     /* Someone wants to edit the printer types ... 
315        So, lets open a new dialog which provides some buttons to edit the types
316      */
317     if($this->edit_type){
318       $smarty->assign("Method","edit");
319       $smarty->assign("PrinterTypes",            $this->handle->getPrinterTypes());
320       $smarty->assign("PrinterTypeKeys",         array_flip($this->handle->getPrinterTypes()));
321       $display= $smarty->fetch(get_template_path('glpi_edit_printer_type.tpl', TRUE));
322       return($display);
323     }
326     /*  ##########################################################################
327      *  Edit manufacturers 
328      *  Dialog 
329      */
331     /* Open dialog which allows to edit the manufacturers
332      */
333     if(isset($_POST['edit_manufacturer']) && $this->acl_is_writeable("FK_glpi_enterprise")){
334       $this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
335       $this->dialog = true;
336       $this->editManufacturer =true;
337     }
339     /* Close manufacturer editing dialog
340      */
341     if((isset($_POST['close_edit_manufacturer']))&&($this->editManufacturer)){
342       $this->dialog = false;
343       $this->cur_dialog = false;
344       $this->editManufacturer=false;
345     }
348     /*  ##########################################################################
349      *  Technical responsible person
350      *  Contact person 
351      *  Dialog 
352      */
354     /* Show dialog to select a new contact person
355      * Select a contact person
356      */
357     if(isset($_POST['SelectContactPerson']) && $this->acl_is_writeable("contact_num")){
358       $this->addUser = "contact";
359       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
360     }
362     /* Selecte technical responsible person
363      */
364     if(isset($_POST['SelectTechPerson']) && $this->acl_is_writeable("tech_num")){
365       $this->addUser ="tech";
366       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
367     }
369     /* Abort user selection
370      */
371     $smarty->assign("AbortSelectUser","SelectUserCancel");
372     if(isset($_POST['SelectUserCancel'])){
373       $this->dialog = false;
374       $this->addUser ="";
375       $this->cur_dialog = false;
376     }
378     /* Technical responsible/contact person selected */
379     if(isset($_GET['act'])&&($_GET['act']=="user_tech_num")){
381       /* Get posted id */
382       $id = base64_decode($_GET['id']);
384       /* Check if user is already created in glpi database */
385       if(!in_array($id,$users)){
387         /* If this user doesn't exists in glpi db, we must create him */
388         $ldap->cat($id, array('cn', 'mail', 'telephoneNumber'));
389         $atr = $ldap->fetch();
390         $tmp = array();
391         $use = array( "cn"              =>"name",
392             "mail"            =>"email",
393             "telephoneNumber" =>"phone");
395         /* Create array */
396         foreach($use as $gosa => $glpi){
397           if(isset($atr[$gosa])){
398             $tmp[$glpi]= $atr[$gosa][0];
399           }
400         }
402         /* Add this user */
403         $this->handle->addUser($tmp,$id);
404       }
406       /* Re-read users */
407       $users = ($this->handle->getUsers());
409       /* Get user */
410       $tmp = array_flip($users);
411       $id=$tmp[$id];
413       /* Use user id, close dialog */
414       if($this->addUser == "tech"){
415         $this->tech_num = $id;
416       }else{
417         $this->contact_num = $id;
418       }
419       $this->cur_dialog   = false;
420       $this->dialog= false;
421     }
424     /*  ##########################################################################
425      *  Handle attachments 
426      */
427     
428     /* Attachment pool was closed with use
429      */
430     if(isset($_POST['UseAttachment']) && $this->acl_is_writeable("Attachments")){
431       if(count($this->cur_dialog->check())){
432         foreach($this->cur_dialog->check() as $msg){
433           print_red($msg);
434         }
435       }else{
436         $this->cur_dialog->save_object();
437         $this->usedAttachments = $this->cur_dialog->save();
438         $this->cur_dialog = false;
439         $this->edit_type = false; 
440       }
441     }
442    
443     /* Attachment pool was closed with abort
444      */ 
445     if(isset($_POST['AbortAttachment'])){
446       $this->cur_dialog = false;
447       $this->edit_type = false; 
448     }
450     /* Open Attachment pool to add/edit Attachments
451      */
452     if(isset($_POST['AddAttachment']) && $this->acl_is_writeable("Attachments")){
453       $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
454       $this->dialog = true;
455     }
456     
457     /* Remove Attachment from this tab 
458      */
459     $once = true;
460     foreach($_POST as $name => $value){
461       if((preg_match("/^delAttachment_/",$name))&&($once) && $this->acl_is_writeable("Attachments")){
462         $once= false;
463         $name = preg_replace("/^delAttachment_/","",$name);
464         $entry = preg_replace("/_.*$/","",$name);
465         if(isset($this->usedAttachments[$entry])){
466           unset($this->usedAttachments[$entry]);
467         }
468       }
469     }
470     if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments'])) && $this->acl_is_writeable("Attachments")){
471       if(isset($this->usedAttachments[$_POST['Attachments']])){
472         unset($this->usedAttachments[$_POST['Attachments']]);
473       }
474     }
476     /*  ##########################################################################
477      *  Printer Cartridge handling 
478      */
480     /* Abort cartridge select dialog
481      */
482     if(isset($_POST['SelectCartridgeCancel'])){
483       $this->cur_dialog = false;
484       $this->edit_type = false; 
485     }
487     /* Get selected cartridges and add them to our list 
488      */ 
489     if(isset($_POST['SelectCartridgeSave'])){
490       $this->cur_dialog->save_object();
491       $carts = $this->cur_dialog->save();
492       foreach($carts as $cart){
493         $cart['status'] = "new";
494         $this->usedCartridges[] = $cart;
495       }
496       $this->cur_dialog = false;
497       $this->edit_type = false; 
498     }
500     /* Remove cartridge  
501      */
502     if((isset($_POST['RemoveCartridge']))&&(isset($_POST['Cartridges'])) && $this->acl_is_writeable("ManageCartridges")){
504       foreach($_POST['Cartridges'] as $cartID){
506         if(isset($this->usedCartridges[$cartID])){
507           if($this->usedCartridges[$cartID]['status'] == "exists"){
508             $this->usedCartridges[$cartID]['status'] = "deleted";
509           }else{
510             unset($this->usedCartridges[$cartID]);
511           }
512         }
513       }
514     }
516     /* Open Attachment pool to add/edit Attachments
517      */
518     if(isset($_POST['AddCartridge']) && $this->acl_is_writeable("ManageCartridges")){
519       $this->cur_dialog = new glpiPrinterCartridges($this->config,$this->dn,$this->type);
520       $this->dialog = true;
521     }
524     /*  ##########################################################################
525      *  Draw Dialogs
526      */
527     /* if( cur_dialog != false || cur_dialog != NULL) 
528      * There is a dialog which wants to be displayed 
529      */
530     if($this->cur_dialog){
531       $this->cur_dialog->save_object();
532       $this->dialog=true;
533       $this->cur_dialog->parent = &$this;
534       return($this->cur_dialog->execute());
535     }else{
536       $this->dialog= false;
537     }
540     /*  ##########################################################################
541      *  Assign listbox / checkbox .... values to smarty  
542      */
543     /* Assign smarty defaults */ 
544     foreach(array("PrinterTypes","PrinterTypeKeys","Manufacturers","TechnicalResponsibles","Attachments","Cartridges") as $attr){
545       $smarty->assign($attr,array());
546     }
548     /* Assign some vars to smarty 
549      */
550     foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","flags_serial","flags_par","flags_usb") as $attr){
551       $smarty->assign($attr,"");
552     }
554     $smarty->assign("comments",               $this->comments);
555     $smarty->assign("flags_serial",            $this->flags_serial);
556     $smarty->assign("flags_par",               $this->flags_par);
557     $smarty->assign("flags_usb",               $this->flags_usb);
559     /* Assign system types 
560      */
561     $smarty->assign("PrinterTypes",           $this->handle->getPrinterTypes());
562     $smarty->assign("PrinterTypeKeys",        array_flip($this->handle->getPrinterTypes()));
563     $smarty->assign("type",                   $this->type);
565     /* Append manufacturers
566      */
567     $smarty->assign("ManufacturerKeys",       array_flip($this->handle->getEnterprises()));
568     $smarty->assign("Manufacturers",          $this->handle->getEnterprises());
569     $smarty->assign("FK_glpi_enterprise",     $this->FK_glpi_enterprise);
571     /* Assign used Attachments
572     */
574     $divlist = new divSelectBox("glpiAttachmentsList");
575     $divlist-> SetHeight(120);
576     $atts = $this->getUsedAttachments(true);
577     $downlink = "<a href='get_attachment.php?id=%s' target='_blank'>%s</a>";
578     $del_link = "<input type='image' src='images/edittrash.png' name='delAttachment_%s'>";
579     foreach($atts as $id => $attachment){
580       $divlist->AddEntry
581           (
582         array(
583             array("string"=>$attachment['name']),
584             array("string"=>$attachment['mime']),
585             array("string"=>sprintf($downlink,$id,$attachment['filename'])),
586             array("string"=>sprintf($del_link,$attachment['ID']),"attach"=>"style='border-right:0px;'"),
587              )
588           );
589     }
591     $smarty->assign("AttachmentsDiv"          ,$divlist->DrawList());
592     $smarty->assign("Attachments",            $this->getUsedAttachments());
593     $smarty->assign("AttachmentKeys",         array_flip($this->getUsedAttachments()));
595     /* Assign Cartridges 
596      */
597     $smarty->assign("Cartridges",            $this->getUsedCartridges());
598     $smarty->assign("CartridgeKeys",         $this->getUsedCartridges(true));
600     /*  ##########################################################################
601      *  Assign contact and technical responsible person 
602      */
603     if(isset($users[$this->contact_num])){
604       $ldap->cat($users[$this->contact_num], array('givenName', 'sn', 'uid'));
605       $tr = $ldap->fetch();
606       $str = "";
607       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
608       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
609       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
610       $smarty->assign("contact_num",               $str);
611     }else{
612       $smarty->assign("contact_num",               _("N/A"));
613     }
615     /* Handle tech person 
616        Assign name ... to smarty, if set
617      */ 
618     if(isset($users[$this->tech_num])){
619       $ldap->cat($users[$this->tech_num], array('givenName', 'sn', 'uid'));
620       $tr = $ldap->fetch();
621       $str = "";
622       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
623       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
624       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
625       $smarty->assign("tech_num",               $str);
626     }else{
627       $smarty->assign("tech_num",               _("N/A"));
628     }
630     /* If theres a cartridge selected, you can't change the printer type.
631      */ 
632     $disp = true;
634     foreach($this->usedCartridges as $cart){
635       if($cart['status'] != "deleted"){
636         $disp = false;
637       }
638     }
639     if($disp==false){
640       $smarty->assign("typeACL", $this->getacl("type",true));
641     }
643     $display.= $smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE));
644     return($display);
645   }
647   function remove_from_parent()
648   {
649     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
650     if($this->initially_was_account){
651       $this->handle->removePrinterInformations($this->dn); 
652     }
653   }
656   /* Save data to object */
657   function save_object()
658   {
659     if(isset($_POST['glpiPrinterFlagsPosted'])){
660       plugin::save_object();
661       foreach($this->attributes as $attrs){
662         if(isset($_POST[$attrs])){
663           $this->$attrs = $_POST[$attrs];
664         }
665       }
667       foreach(array("flags_serial","flags_par","flags_usb") as $checkboxes){
668         if($this->acl_is_writeable($checkboxes)){
669           if(isset($_POST[$checkboxes])){
670             $this->$checkboxes = 1;
671           }else{
672             $this->$checkboxes = 0;
673           }
674         }
675       }
676     }
678   }
681   /* Check supplied data */
682   function check()
683   {
684     /* Call common method to give check the hook */
685     $message= plugin::check();
687     //    if($this->TechnicalResponsible == ""){
688     //      $message[] = _("Please select a technical responsible person for this entry.");
689     //    }
691     return ($message);
692   }
694   /* Save to LDAP */
695   function save()
696   {
697     if($this->is_account){
698         $attrs = array();
699       $this->date_mod = date("Y-m-d H:i:s");
700       foreach($this->attributes as $attr){
701         $attrs[$attr] = $this->$attr;
702       }
703       $attrs['name'] = $this->dn;
704       unset($attrs['ID']);
705       $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
706       if($this->initially_was_account&&$this->is_account){
707         $this->handle->updatePrinterInformations($attrs,$this->dn);
708       }elseif($this->is_account){
709         $this->handle->addPrinterInformations($attrs,$this->dn);
710       }
711       $tmp = $this->handle->getPrinterInformations($this->dn);
712       $this->handle->addAttachmentsToPrinter($this->usedAttachments,$tmp[0]['ID']);
714       foreach($this->usedCartridges as $cart){
715         if($cart['status'] == "deleted"){
716           $this->handle->removeCartridgeFromPrinter($cart['ID']);
717         }elseif($cart['status'] == "new"){
718           $this->handle->addCartridgeFromPrinter($tmp[0]['ID'],$cart['type_ID']);
719         }
720       }
721     }
722   }
724   /* Return used attachments */
725   function getUsedAttachments($divlist = false)
726   {
727     $atts =$this->handle->getAttachments();
728     $ret = array();
729     foreach($atts as $entry){
730       if(in_array($entry['ID'],$this->usedAttachments)){
731         if($divlist){
732           $ret[$entry['ID']] = $entry;
733         }else{
734           $cm ="";
735           if(isset($entry['comment'])){
736             $cm=" [".$entry['comment']."]";
737           }
738           if(isset($entry['mime'])){
739             $cm.=" -".$entry['mime']."";
740           }
742           $ret[$entry['ID']]= $entry['name'].$cm;
743         }
744       }
745     }
746     return($ret);
747   }
749   function getUsedCartridges($flip = false)
750   {
751     $ret = array();
752     foreach($this->usedCartridges as $key => $value){
753       if($value['status'] == "deleted") continue;
754       if($flip){
755         $ret[$key] = $key;    
756       }else{
757         $ret[$key] = $value['name']." [".$value['type_name']."] "._("since")." :".$value['date_use'];
758       }
759     }
760     return($ret);
761   }  
763      /* Return plugin informations for acl handling */
764   function plInfo()
765   {
766     return (array(
767           "plShortName"   => _("Glpi"),
768           "plDescription" => _("Printer inventory extension"),
769           "plSelfModify"  => FALSE,
770           "plDepends"     => array(),
771           "plPriority"    => 0,
772           "plSection"     => array("administration"),
773           "plCategory"    => array("printer"),
775           "plProvidedAcls"=> array(
776             "flags_serial"         => _("Supports serial interface"),
777             "flags_par"            => _("Supports parallel interface"),
778             "flags_usb"            => _("Supports usb interface"),
779             "tech_num"             => _("Technical responsible"),
780             "comments"             => _("Comments"),
781             "location"             => _("Location"),
782             "contact_num"          => _("Contact person"),
783             "type"                 => _("Type"),
784             "FK_glpi_enterprise"   => _("Manufacturer"),
786             "Attachments"          => _("Attachments"),
787         
788             "ManageCartridges"            => _("Cartridge settings"))
789           ));
790   }
792 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
793 ?>