Code

Added Inherit all button to Workstation Servive - testing.
[gosa.git] / plugins / admin / systems / class_glpiPrinterAccount.inc
1 <?php
3 class glpiPrinterAccount extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account= FALSE;
7   var $attributes= array("ID","name","contact","ramSize","flags_serial","flags_par","flags_usb",
8       "tech_num","comments","date_mod","location","domain","network","contact_num","serial","otherserial",
9       "type","is_template","FK_glpi_enterprise","deleted");
11   var $ID                 ;       // Is set if this entry is edited 
12   var $name               = "";    // This should be the dn of this entry 
13   var $FK_glpi_enterprise = 0;     // Manufacturer id
14   var $tech_num           = "";    // Technical responsible person
15   var $contact_num        = "";    // Contact person
16   
17   var $comments           = "";    // Comment
18   
19   var $type               = 0;     // printer type id
20   var $serial             = "";   
21   var $otherserial        = "";  
22   var $ramSize            = 0;
23   var $flags_serial       = false;
24   var $flags_par          = false;
25   var $flags_usb          = false;
27   var $date_mod           = "";    // Modification timestamp
28   
29   var $location           = 0;     // Not used yet
30   var $domain             = 0;     // ? Set to 0
31   var $network            = 0;     // ? Set to 0 
33   var $is_template        = 0;     // Used as template ?
34   var $contact            = "";    // Empty
35   var $deleted            = "N";   // Deleted entries should have this set to Y
37   var $rename             = false;
38   var $select_type        ;
40   var $editManufacturer   = false;
42   /* Not necessary, cause we use mysql databse */
43   var $objectclasses= array("whatever");
45   /* Used to remember if this was an account (simply: is this an edited entry) */
46   var $initially_was_account = false;
48   /* Remember current dialog */
49   var $edit_type            = false;
50   var $edit_os              = false;
52   var $data;
53   var $handle = NULL;               // Glpi class handle used to query database
55   var $cur_dialog = NULL;           // This contains the sub dialog handle
57   var $orig_dn;                     // To check if dn, has changed 
58   var $ui;                          // Some GOsa specific user informations 
59   
60   var $usedDevices      = array();  // Which devices are currently selected 
61   var $usedAttachments  = array();  // Used Attachments 
62   var $usedCartridges   = array();  // Used Cartridges
64   /* Contructor 
65      Sets default values and checks if we already have an existing glpi account
66    */
67   function glpiPrinterAccount ($config, $dn= NULL, $parent= NULL)
68   {
69     plugin::plugin ($config, $dn, $parent);
70     $this->ui= get_userinfo();
72     $this->is_account = false;
74     /* Abort class construction, if no db is defined */
75     if(!isset($this->config->data['SERVERS']['GLPI'])){
76       return;
77     }
79     // Get informations about databse connection
80     $this->data = $this->config->data['SERVERS']['GLPI'];
82     // Abort if mysql extension is missing 
83     if(!is_callable("mysql_connect")){
84       return;
85     }
87     // Create handle of glpi class, and check if database connection is established 
88     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
90     if(!$this->handle->is_connected){
91       return;
92     } 
94     // If this dn is already used in database, then get all informations for this entry 
95     if($this->handle->is_printer_account($this->dn)){
96       $this->is_account = true;
97       $tmp = ($this->handle->getPrinterInformations($this->dn));
99       foreach(array("tech_num","FK_glpi_enterprise","type","comments","contact_num","flags_serial","flags_par","flags_usb","ramSize") as $attr){
100         $this->$attr = $tmp[0][$attr];
101       }
102       
103       $atts = $this->handle->getAssignPrinterAttachments($tmp[0]['ID']);
104       foreach($atts as $attachment){
105         $this->usedAttachments[$attachment['FK_doc']]=$attachment['FK_doc']; 
106       }
108       $cart= $this->handle->getUsedCartridges($tmp[0]['ID']);
109       foreach($cart as $key => $cartridge){
110         $this->usedCartridges[$key]=$cartridge; 
111         $this->usedCartridges[$key]['status']="exists"; 
112       }
115     }else{
116       $this->is_account = false;
117     }
119     /* set defaults */
120     $this->name                 = $this->dn;
121     $this->orig_dn              = $this->dn;
122     $this->initially_was_account = $this->is_account;
123   }
125   function execute()
126   {
127     /* Call parent execute */
128     plugin::execute();
130     /* Fill templating stuff */
131     $smarty= get_smarty();
132     $display= "";
134     $smarty->assign("CartridgesACL",chkacl($this->acl,"Cartridges"));
136     /*  Assign smarty defaults 
137         To avoid undefined indexes, if there is an error with the glpi db
138      */ 
139     foreach(array("PrinterTypeKeys","PrinterTypes","ManufacturerKeys","Manufacturers","Attachments","AttachmentKeys","CartridgeKeys","Cartridges") as $attr){
140       $smarty->assign($attr,array());
141       $smarty->assign($attr."ACL"," disabled ");
142     }
143     foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","comments","flags_serial","flags_par","flags_usb","AttachmentsDiv") as $attr){
144       $smarty->assign($attr,"");
145       $smarty->assign($attr."ACL"," disabled ");
146     }
148     /* Check if there is a glpi database server defined 
149       */
150     if(!isset($this->config->data['SERVERS']['GLPI'])){
151       print_red(_("There is no server with valid glpi database service."));
152       return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
153     }
155     $this->data = $this->config->data['SERVERS']['GLPI'];
157     /* Check if we can call mysql_connect 
158        If we can't, there is no the mysql-php extension
159      */
160     if(!is_callable("mysql_connect")){
161       print_red(_("Can't connect to glpi database, the php-mysql extension is missing."));
162       return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
163     }
165     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
167     /*  If handle == false, abort
168         Seems that the server, username and or password is wrong
169      */
170     if(!$this->handle->is_connected){
171       print_red(_("Can't connect to glpi database, check configuration twice."));
172       return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
173     } 
175     /*  All checks are ok
176         Lets handle Posts, templates etc below ...
177      */
178     
179     $users = $this->handle->getUsers();
180     $ldap= $this->config->get_ldap_link();
182     
183     /*  ##########################################################################
184      *  Some tab management   
185      */
187     /* Do we need to flip is_account state? */
188     if (isset($_POST['modify_state'])){
190       /* Only change account state if allowed */
191       if($this->is_account && $this->acl == "#all#"){
192         $this->is_account= !$this->is_account;
193         $this->is_modified = true;
194       }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){
195         $this->is_account= !$this->is_account;
196         $this->is_modified = true;
197       }
198     }
201     /* Show tab dialog headers */
202     if ($this->is_account){
203       $display= $this->show_header(_("Remove inventory"),
204           _("This server has inventory features enabled. You can disable them by clicking below."));
205     } else {
206       $display= $this->show_header(_("Add inventory"),
207           _("This server has inventory features disabled. You can enable them by clicking below."));
208       return ($display);
209     }
211     
212     /*  ##########################################################################
213      *  Printer type management 
214      *  Dialog 
215      */
217     /* Rename was requested */
218     if(isset($_POST['Rename_PType_OK']) && chkacl($this->acl,"type") == ""){
219       $tmp = $this->handle->getPrinterTypes();
220       $allok = true;
221       foreach($tmp as $id => $name){
222         if(trim($name) == trim($_POST['string'])){
223           $allok = false;
224         }
225       }
226       if($allok){
227         $this->handle->updatePrinterType($_POST['string'],$this->select_type);
228         $this->rename = false;
229       }else{
230         print_red(sprintf(_("Can't rename given printer type to '%s', because this type name already exists."),$_POST['string']));
231       }
232     }
234     /* abort rename 
235      */
236     if(isset($_POST['Rename_Cancel'])){
237       $this->rename = false;
238     }
240     /* Printer type management
241      */
242     if(isset($_POST['edit_type']) && chkacl($this->acl,"type") == ""){
243       $this->dialog = true;
244       $this->edit_type=true;
245     }
247     /* This closes the printer type editing dialog
248      */
249     if(isset($_POST['close_edit_type'])){
250       $this->edit_type=false;
251       $this->dialog = false;
252     }
254     /* This appends a new printer to our sytem types
255      */
256     if((isset($_POST['add_type']))&&(!empty($_POST['type_string'])) && chkacl($this->acl,"type") == ""){
257     
258       $tmp = $this->handle->getPrinterTypes();
259       $allok = true;
260       foreach($tmp as $id => $name){
261         if(trim($name) == trim($_POST['type_string'])){
262           $allok = false;
263         }
264       }
265       if($allok){
266         $this->handle->addPrinterType($_POST['type_string']);  
267       }else{
268         print_red(sprintf(_("Can't rename given printer type to '%s', because this type name already exists."),$_POST['type_string']));
269       }
270     }
272     /* Remove selected type from our printer types list
273      */
274     if((isset($_POST['del_type']))&&(!empty($_POST['select_type'])) && chkacl($this->acl,"type") == ""){
275       $tmp = $this->handle->is_printerTypeUsed($_POST['select_type']);
276       if(count($tmp)){
277         $str = "";
278         foreach($tmp as $id => $name){
279           $str .= $name.", ";
280         }
281         $str = preg_replace("/, $/","",$str); 
282         print_red(sprintf(_("Can't delete printer type, it is still in use by '%s'."),$str));
283       }else{
284         $this->handle->removePrinterType($_POST['select_type']);  
285       }
286     }
288     /* Rename selected printer type to given string
289      */
290     if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))||($this->rename) && chkacl($this->acl,"type") == ""){
291       $this->rename = true;
293       $smarty->assign("Method","rename");
295       $tmp = $this->handle->getPrinterTypes();
297       if(isset($_POST['select_type'])){
298         $this->select_type = $_POST['select_type'];
299       }  
300       $smarty->assign("string",$tmp[$this->select_type]);
301       if(isset($_POST['string'])){
302         $smarty->assign("string",$_POST['string']);
303       }
305       $display= $smarty->fetch(get_template_path('glpi_edit_printer_type.tpl', TRUE));
306       return($display);
307     }  
309     /* Someone wants to edit the printer types ... 
310        So, lets open a new dialog which provides some buttons to edit the types
311      */
312     if($this->edit_type){
313       $smarty->assign("Method","edit");
314       $smarty->assign("PrinterTypes",            $this->handle->getPrinterTypes());
315       $smarty->assign("PrinterTypeKeys",         array_flip($this->handle->getPrinterTypes()));
316       $display= $smarty->fetch(get_template_path('glpi_edit_printer_type.tpl', TRUE));
317       return($display);
318     }
321     /*  ##########################################################################
322      *  Edit manufacturers 
323      *  Dialog 
324      */
326     /* Open dialog which allows to edit the manufacturers
327      */
328     if(isset($_POST['edit_manufacturer']) && chkacl($this->acl,"manufacturer") == ""){
329       $this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
330       $this->dialog = true;
331       $this->editManufacturer =true;
332     }
334     /* Close manufacturer editing dialog
335      */
336     if((isset($_POST['close_edit_manufacturer']))&&($this->editManufacturer) && chkacl($this->acl,"manufacturer") == ""){
337       $this->dialog = false;
338       $this->cur_dialog = false;
339       $this->editManufacturer=false;
340     }
343     /*  ##########################################################################
344      *  Technical responsible person
345      *  Contact person 
346      *  Dialog 
347      */
349     /* Show dialog to select a new contact person
350      * Select a contact person
351      */
352     if(isset($_POST['SelectContactPerson']) && chkacl($this->acl,"user_tech_num") == ""){
353       $this->addUser = "contact";
354       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
355     }
357     /* Selecte technical responsible person
358      */
359     if(isset($_POST['SelectTechPerson']) && chkacl($this->acl,"user_tech_num") == ""){
360       $this->addUser ="tech";
361       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
362     }
364     /* Abort user selection
365      */
366     $smarty->assign("AbortSelectUser","SelectUserCancel");
367     if(isset($_POST['SelectUserCancel'])){
368       $this->dialog = false;
369       $this->addUser ="";
370       $this->cur_dialog = false;
371     }
373     /* Technical responsible/contact person selected */
374     if(isset($_GET['act'])&&($_GET['act']=="user_tech_num") && chkacl($this->acl,"user_tech_num") == ""){
376       /* Get posted id */
377       $id = base64_decode($_GET['id']);
379       /* Check if user is already created in glpi database */
380       if(!in_array($id,$users)){
382         /* If this user doesn't exists in glpi db, we must create him */
383         $ldap->cat($id, array('cn', 'mail', 'telephoneNumber'));
384         $atr = $ldap->fetch();
385         $tmp = array();
386         $use = array( "cn"              =>"name",
387             "mail"            =>"email",
388             "telephoneNumber" =>"phone");
390         /* Create array */
391         foreach($use as $gosa => $glpi){
392           if(isset($atr[$gosa])){
393             $tmp[$glpi]= $atr[$gosa][0];
394           }
395         }
397         /* Add this user */
398         $this->handle->addUser($tmp,$id);
399       }
401       /* Re-read users */
402       $users = ($this->handle->getUsers());
404       /* Get user */
405       $tmp = array_flip($users);
406       $id=$tmp[$id];
408       /* Use user id, close dialog */
409       if($this->addUser == "tech"){
410         $this->tech_num = $id;
411       }else{
412         $this->contact_num = $id;
413       }
414       $this->cur_dialog   = false;
415       $this->dialog= false;
416     }
419     /*  ##########################################################################
420      *  Handle attachments 
421      */
422     
423     /* Attachment pool was closed with use
424      */
425     if(isset($_POST['UseAttachment']) && chkacl($this->acl,"useAttachments") == ""){
426       if(count($this->cur_dialog->check())){
427         foreach($this->cur_dialog->check() as $msg){
428           print_red($msg);
429         }
430       }else{
431         $this->cur_dialog->save_object();
432         $this->usedAttachments = $this->cur_dialog->save();
433         $this->cur_dialog = false;
434         $this->edit_type = false; 
435       }
436     }
437    
438     /* Attachment pool was closed with abort
439      */ 
440     if(isset($_POST['AbortAttachment'])){
441       $this->cur_dialog = false;
442       $this->edit_type = false; 
443     }
445     /* Open Attachment pool to add/edit Attachments
446      */
447     if(isset($_POST['AddAttachment']) && chkacl($this->acl,"useAttachments") == ""){
448       $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
449       $this->dialog = true;
450     }
451     
452     /* Remove Attachment from this tab 
453      */
454     $once = true;
455     foreach($_POST as $name => $value){
456       if((preg_match("/^delAttachment_/",$name))&&($once) && chkacl($this->acl,"useAttachments") == ""){
457         $once= false;
458         $name = preg_replace("/^delAttachment_/","",$name);
459         $entry = preg_replace("/_.*$/","",$name);
460         if(isset($this->usedAttachments[$entry])){
461           unset($this->usedAttachments[$entry]);
462         }
463       }
464     }
465     if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments'])) && chkacl($this->acl,"useAttachments") == ""){
466       if(isset($this->usedAttachments[$_POST['Attachments']])){
467         unset($this->usedAttachments[$_POST['Attachments']]);
468       }
469     }
471     /*  ##########################################################################
472      *  Printer Cartridge handling 
473      */
475     /* Abort cartridge select dialog
476      */
477     if(isset($_POST['SelectCartridgeCancel'])){
478       $this->cur_dialog = false;
479       $this->edit_type = false; 
480     }
482     /* Get selected cartridges and add them to our list 
483      */ 
484     if(isset($_POST['SelectCartridgeSave'])){
485       $this->cur_dialog->save_object();
486       $carts = $this->cur_dialog->save();
487       foreach($carts as $cart){
488         $cart['status'] = "new";
489         $this->usedCartridges[] = $cart;
490       }
491       $this->cur_dialog = false;
492       $this->edit_type = false; 
493     }
495     /* Remove cartridge  
496      */
497     if((isset($_POST['RemoveCartridge']))&&(isset($_POST['Cartridges'])) && chkacl($this->acl,"cartridges") == ""){
499       foreach($_POST['Cartridges'] as $cartID){
501         if(isset($this->usedCartridges[$cartID])){
502           if($this->usedCartridges[$cartID]['status'] == "exists"){
503             $this->usedCartridges[$cartID]['status'] = "deleted";
504           }else{
505             unset($this->usedCartridges[$cartID]);
506           }
507         }
508       }
509     }
511     /* Open Attachment pool to add/edit Attachments
512      */
513     if(isset($_POST['AddCartridge']) && chkacl($this->acl,"cartridges") == ""){
514       $this->cur_dialog = new glpiPrinterCartridges($this->config,$this->dn,$this->type);
515       $this->dialog = true;
516     }
519     /*  ##########################################################################
520      *  Draw Dialogs
521      */
522     /* if( cur_dialog != false || cur_dialog != NULL) 
523      * There is a dialog which wants to be displayed 
524      */
525     if($this->cur_dialog){
526       $this->cur_dialog->save_object();
527       $this->dialog=true;
528       $this->cur_dialog->parent = &$this;
529       return($this->cur_dialog->execute());
530     }else{
531       $this->dialog= false;
532     }
535     /*  ##########################################################################
536      *  Assign listbox / checkbox .... values to smarty  
537      */
538     /* Assign smarty defaults */ 
539     foreach(array("PrinterTypes","PrinterTypeKeys","Manufacturers","TechnicalResponsibles","Attachments","Cartridges") as $attr){
540       $smarty->assign($attr,array());
541       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
542     }
544     /* Assign some vars to smarty 
545      */
546     foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","flags_serial","flags_par","flags_usb") as $attr){
547       $smarty->assign($attr,"");
548       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
549     }
552     /* Assign ACLs to smarty*/
553     foreach($this->attributes as $attr){
554       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
555     }
557     $smarty->assign("comments",               $this->comments);
558     $smarty->assign("flags_serial",            $this->flags_serial);
559     $smarty->assign("flags_par",               $this->flags_par);
560     $smarty->assign("flags_usb",               $this->flags_usb);
562     /* Assign system types 
563      */
564     $smarty->assign("PrinterTypes",           $this->handle->getPrinterTypes());
565     $smarty->assign("PrinterTypeKeys",        array_flip($this->handle->getPrinterTypes()));
566     $smarty->assign("type",                   $this->type);
568     /* Append manufacturers
569      */
570     $smarty->assign("ManufacturerKeys",       array_flip($this->handle->getEnterprises()));
571     $smarty->assign("Manufacturers",          $this->handle->getEnterprises());
572     $smarty->assign("FK_glpi_enterprise",     $this->FK_glpi_enterprise);
574     /* Assign used Attachments
575     */
577     $divlist = new divSelectBox("glpiAttachmentsList");
578     $divlist-> SetHeight(120);
579     $atts = $this->getUsedAttachments(true);
580     $downlink = "<a href='get_attachment.php?id=%s' target='_blank'>%s</a>";
581     $del_link = "<input type='image' src='images/edittrash.png' name='delAttachment_%s'>";
582     foreach($atts as $id => $attachment){
583       $divlist->AddEntry
584           (
585         array(
586             array("string"=>$attachment['name']),
587             array("string"=>$attachment['mime']),
588             array("string"=>sprintf($downlink,$id,$attachment['filename'])),
589             array("string"=>sprintf($del_link,$attachment['ID']),"attach"=>"style='border-right:0px;'"),
590              )
591           );
592     }
594     $smarty->assign("AttachmentsDiv"          ,$divlist->DrawList());
595     $smarty->assign("Attachments",            $this->getUsedAttachments());
596     $smarty->assign("AttachmentKeys",         array_flip($this->getUsedAttachments()));
598     /* Assign Cartridges 
599      */
600     $smarty->assign("Cartridges",            $this->getUsedCartridges());
601     $smarty->assign("CartridgeKeys",         $this->getUsedCartridges(true));
603     /*  ##########################################################################
604      *  Assign contact and technical responsible person 
605      */
606     if(isset($users[$this->contact_num])){
607       $ldap->cat($users[$this->contact_num], array('givenName', 'sn', 'uid'));
608       $tr = $ldap->fetch();
609       $str = "";
610       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
611       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
612       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
613       $smarty->assign("contact_num",               $str);
614     }else{
615       $smarty->assign("contact_num",               _("N/A"));
616     }
618     /* Handle tech person 
619        Assign name ... to smarty, if set
620      */ 
621     if(isset($users[$this->tech_num])){
622       $ldap->cat($users[$this->tech_num], array('givenName', 'sn', 'uid'));
623       $tr = $ldap->fetch();
624       $str = "";
625       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
626       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
627       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
628       $smarty->assign("tech_num",               $str);
629     }else{
630       $smarty->assign("tech_num",               _("N/A"));
631     }
633     /* If theres a cartridge selected, you can't change the printer type.
634      */ 
635     $disp = true;
637     foreach($this->usedCartridges as $cart){
638       if($cart['status'] != "deleted"){
639         $disp = false;
640       }
641     }
642     if($disp==false){
643       $smarty->assign("typeACL","disabled");
644     }
646     $display.= $smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE));
647     return($display);
648   }
650   function remove_from_parent()
651   {
652     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
653     if($this->initially_was_account){
654       $this->handle->removePrinterInformations($this->dn); 
655     }
656   }
659   /* Save data to object */
660   function save_object()
661   {
662     if(isset($_POST['glpiPrinterFlagsPosted'])){
663       plugin::save_object();
665       foreach(array("flags_serial","flags_par","flags_usb") as $checkboxes){
666         if(chkacl($this->acl,$checkboxes) == ""){
667           if(isset($_POST[$checkboxes])){
668             $this->$checkboxes = 1;
669           }else{
670             $this->$checkboxes = 0;
671           }
672         }
673       }
674     }
676   }
679   /* Check supplied data */
680   function check()
681   {
682     /* Call common method to give check the hook */
683     $message= plugin::check();
685     //    if($this->TechnicalResponsible == ""){
686     //      $message[] = _("Please select a technical responsible person for this entry.");
687     //    }
689     return ($message);
690   }
692   /* Save to LDAP */
693   function save()
694   {
695     if($this->is_account){
696         $attrs = array();
697       $this->date_mod = date("Y-m-d H:i:s");
698       foreach($this->attributes as $attr){
699         $attrs[$attr] = $this->$attr;
700       }
701       $attrs['name'] = $this->dn;
702       unset($attrs['ID']);
703       $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
704       if($this->initially_was_account&&$this->is_account){
705         $this->handle->updatePrinterInformations($attrs,$this->dn);
706       }elseif($this->is_account){
707         $this->handle->addPrinterInformations($attrs,$this->dn);
708       }
709       $tmp = $this->handle->getPrinterInformations($this->dn);
710       $this->handle->addAttachmentsToPrinter($this->usedAttachments,$tmp[0]['ID']);
712       foreach($this->usedCartridges as $cart){
713         if($cart['status'] == "deleted"){
714           $this->handle->removeCartridgeFromPrinter($cart['ID']);
715         }elseif($cart['status'] == "new"){
716           $this->handle->addCartridgeFromPrinter($tmp[0]['ID'],$cart['type_ID']);
717         }
718       }
719     }
720   }
722   /* Return used attachments */
723   function getUsedAttachments($divlist = false)
724   {
725     $atts =$this->handle->getAttachments();
726     $ret = array();
727     foreach($atts as $entry){
728       if(in_array($entry['ID'],$this->usedAttachments)){
729         if($divlist){
730           $ret[$entry['ID']] = $entry;
731         }else{
732           $cm ="";
733           if(isset($entry['comment'])){
734             $cm=" [".$entry['comment']."]";
735           }
736           if(isset($entry['mime'])){
737             $cm.=" -".$entry['mime']."";
738           }
740           $ret[$entry['ID']]= $entry['name'].$cm;
741         }
742       }
743     }
744     return($ret);
745   }
747   function getUsedCartridges($flip = false)
748   {
749     $ret = array();
750     foreach($this->usedCartridges as $key => $value){
751       if($value['status'] == "deleted") continue;
752       if($flip){
753         $ret[$key] = $key;    
754       }else{
755         $ret[$key] = $value['name']." [".$value['type_name']."] "._("since")." :".$value['date_use'];
756       }
757     }
758     return($ret);
759   }  
763 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
764 ?>