066b7de85efd574399d0f7a3b9f559645cfc69f8
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
22 var $comments = ""; // Comment
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
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
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 }
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",chkacl($this->acl,"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","Attachments","AttachmentKeys","CartridgeKeys","Cartridges") as $attr){
145 $smarty->assign($attr,array());
146 $smarty->assign($attr."ACL"," disabled ");
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 $smarty->assign($attr."ACL"," disabled ");
151 }
153 /* Check if there is a glpi database server defined
154 */
155 if(!isset($this->config->data['SERVERS']['GLPI'])){
156 print_red(_("There is no server with valid glpi database service."));
157 return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
158 }
160 $this->data = $this->config->data['SERVERS']['GLPI'];
162 /* Check if we can call mysql_connect
163 If we can't, there is no the mysql-php extension
164 */
165 if(!is_callable("mysql_connect")){
166 print_red(_("Can't connect to glpi database, the php-mysql extension is missing."));
167 return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
168 }
170 $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
172 /* If handle == false, abort
173 Seems that the server, username and or password is wrong
174 */
175 if(!$this->handle->is_connected){
176 print_red(_("Can't connect to glpi database, check configuration twice."));
177 return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
178 }
180 /* All checks are ok
181 Lets handle Posts, templates etc below ...
182 */
184 $users = $this->handle->getUsers();
185 $ldap= $this->config->get_ldap_link();
188 /* ##########################################################################
189 * Some tab management
190 */
192 /* Do we need to flip is_account state? */
193 if (isset($_POST['modify_state'])){
195 /* Only change account state if allowed */
196 if($this->is_account && $this->acl == "#all#"){
197 $this->is_account= !$this->is_account;
198 $this->is_modified = true;
199 }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){
200 $this->is_account= !$this->is_account;
201 $this->is_modified = true;
202 }
203 }
206 /* Show tab dialog headers */
207 if ($this->is_account){
208 $display= $this->show_header(_("Remove inventory"),
209 _("This server has inventory features enabled. You can disable them by clicking below."));
210 } else {
211 $display= $this->show_header(_("Add inventory"),
212 _("This server has inventory features disabled. You can enable them by clicking below."));
213 return ($display);
214 }
217 /* ##########################################################################
218 * Printer type management
219 * Dialog
220 */
222 /* Rename was requested */
223 if(isset($_POST['Rename_PType_OK']) && chkacl($this->acl,"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']) && chkacl($this->acl,"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'])) && chkacl($this->acl,"type") == ""){
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'])) && chkacl($this->acl,"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) && chkacl($this->acl,"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']) && chkacl($this->acl,"manufacturer") == ""){
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) && chkacl($this->acl,"manufacturer") == ""){
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']) && chkacl($this->acl,"user_tech_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']) && chkacl($this->acl,"user_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") && chkacl($this->acl,"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 */
428 /* Attachment pool was closed with use
429 */
430 if(isset($_POST['UseAttachment']) && chkacl($this->acl,"useAttachments") == ""){
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 }
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']) && chkacl($this->acl,"useAttachments") == ""){
453 $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
454 $this->dialog = true;
455 }
457 /* Remove Attachment from this tab
458 */
459 $once = true;
460 foreach($_POST as $name => $value){
461 if((preg_match("/^delAttachment_/",$name))&&($once) && chkacl($this->acl,"useAttachments") == ""){
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'])) && chkacl($this->acl,"useAttachments") == ""){
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'])) && chkacl($this->acl,"cartridges") == ""){
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']) && chkacl($this->acl,"cartridges") == ""){
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 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
547 }
549 /* Assign some vars to smarty
550 */
551 foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","flags_serial","flags_par","flags_usb") as $attr){
552 $smarty->assign($attr,"");
553 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
554 }
557 /* Assign ACLs to smarty*/
558 foreach($this->attributes as $attr){
559 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
560 }
562 $smarty->assign("comments", $this->comments);
563 $smarty->assign("flags_serial", $this->flags_serial);
564 $smarty->assign("flags_par", $this->flags_par);
565 $smarty->assign("flags_usb", $this->flags_usb);
567 /* Assign system types
568 */
569 $smarty->assign("PrinterTypes", $this->handle->getPrinterTypes());
570 $smarty->assign("PrinterTypeKeys", array_flip($this->handle->getPrinterTypes()));
571 $smarty->assign("type", $this->type);
573 /* Append manufacturers
574 */
575 $smarty->assign("ManufacturerKeys", array_flip($this->handle->getEnterprises()));
576 $smarty->assign("Manufacturers", $this->handle->getEnterprises());
577 $smarty->assign("FK_glpi_enterprise", $this->FK_glpi_enterprise);
579 /* Assign used Attachments
580 */
582 $divlist = new divSelectBox("glpiAttachmentsList");
583 $divlist-> SetHeight(120);
584 $atts = $this->getUsedAttachments(true);
585 $downlink = "<a href='get_attachment.php?id=%s' target='_blank'>%s</a>";
586 $del_link = "<input type='image' src='images/edittrash.png' name='delAttachment_%s'>";
587 foreach($atts as $id => $attachment){
588 $divlist->AddEntry
589 (
590 array(
591 array("string"=>$attachment['name']),
592 array("string"=>$attachment['mime']),
593 array("string"=>sprintf($downlink,$id,$attachment['filename'])),
594 array("string"=>sprintf($del_link,$attachment['ID']),"attach"=>"style='border-right:0px;'"),
595 )
596 );
597 }
599 $smarty->assign("AttachmentsDiv" ,$divlist->DrawList());
600 $smarty->assign("Attachments", $this->getUsedAttachments());
601 $smarty->assign("AttachmentKeys", array_flip($this->getUsedAttachments()));
603 /* Assign Cartridges
604 */
605 $smarty->assign("Cartridges", $this->getUsedCartridges());
606 $smarty->assign("CartridgeKeys", $this->getUsedCartridges(true));
608 /* ##########################################################################
609 * Assign contact and technical responsible person
610 */
611 if(isset($users[$this->contact_num])){
612 $ldap->cat($users[$this->contact_num], array('givenName', 'sn', 'uid'));
613 $tr = $ldap->fetch();
614 $str = "";
615 if(isset($tr['givenName'][0])){ $str .= $tr['givenName'][0]." "; }
616 if(isset($tr['sn'][0])) { $str .= $tr['sn'][0]." "; }
617 if(isset($tr['uid'][0])){ $str .= "[".$tr['uid'][0]."]"; }
618 $smarty->assign("contact_num", $str);
619 }else{
620 $smarty->assign("contact_num", _("N/A"));
621 }
623 /* Handle tech person
624 Assign name ... to smarty, if set
625 */
626 if(isset($users[$this->tech_num])){
627 $ldap->cat($users[$this->tech_num], array('givenName', 'sn', 'uid'));
628 $tr = $ldap->fetch();
629 $str = "";
630 if(isset($tr['givenName'][0])){ $str .= $tr['givenName'][0]." "; }
631 if(isset($tr['sn'][0])) { $str .= $tr['sn'][0]." "; }
632 if(isset($tr['uid'][0])){ $str .= "[".$tr['uid'][0]."]"; }
633 $smarty->assign("tech_num", $str);
634 }else{
635 $smarty->assign("tech_num", _("N/A"));
636 }
638 /* If theres a cartridge selected, you can't change the printer type.
639 */
640 $disp = true;
642 foreach($this->usedCartridges as $cart){
643 if($cart['status'] != "deleted"){
644 $disp = false;
645 }
646 }
647 if($disp==false){
648 $smarty->assign("typeACL","disabled");
649 }
651 $display.= $smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE));
652 return($display);
653 }
655 function remove_from_parent()
656 {
657 $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
658 if($this->initially_was_account){
659 $this->handle->removePrinterInformations($this->dn);
660 }
661 }
664 /* Save data to object */
665 function save_object()
666 {
667 if(isset($_POST['glpiPrinterFlagsPosted'])){
668 plugin::save_object();
670 foreach(array("flags_serial","flags_par","flags_usb") as $checkboxes){
671 if(chkacl($this->acl,$checkboxes) == ""){
672 if(isset($_POST[$checkboxes])){
673 $this->$checkboxes = 1;
674 }else{
675 $this->$checkboxes = 0;
676 }
677 }
678 }
679 }
681 }
684 /* Check supplied data */
685 function check()
686 {
687 /* Call common method to give check the hook */
688 $message= plugin::check();
690 // if($this->TechnicalResponsible == ""){
691 // $message[] = _("Please select a technical responsible person for this entry.");
692 // }
694 return ($message);
695 }
697 /* Save to LDAP */
698 function save()
699 {
700 if($this->is_account){
701 $attrs = array();
702 $this->date_mod = date("Y-m-d H:i:s");
703 foreach($this->attributes as $attr){
704 $attrs[$attr] = $this->$attr;
705 }
706 $attrs['name'] = $this->dn;
707 unset($attrs['ID']);
708 $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
709 if($this->initially_was_account&&$this->is_account){
710 $this->handle->updatePrinterInformations($attrs,$this->dn);
711 }elseif($this->is_account){
712 $this->handle->addPrinterInformations($attrs,$this->dn);
713 }
714 $tmp = $this->handle->getPrinterInformations($this->dn);
715 $this->handle->addAttachmentsToPrinter($this->usedAttachments,$tmp[0]['ID']);
717 foreach($this->usedCartridges as $cart){
718 if($cart['status'] == "deleted"){
719 $this->handle->removeCartridgeFromPrinter($cart['ID']);
720 }elseif($cart['status'] == "new"){
721 $this->handle->addCartridgeFromPrinter($tmp[0]['ID'],$cart['type_ID']);
722 }
723 }
724 }
725 }
727 /* Return used attachments */
728 function getUsedAttachments($divlist = false)
729 {
730 $atts =$this->handle->getAttachments();
731 $ret = array();
732 foreach($atts as $entry){
733 if(in_array($entry['ID'],$this->usedAttachments)){
734 if($divlist){
735 $ret[$entry['ID']] = $entry;
736 }else{
737 $cm ="";
738 if(isset($entry['comment'])){
739 $cm=" [".$entry['comment']."]";
740 }
741 if(isset($entry['mime'])){
742 $cm.=" -".$entry['mime']."";
743 }
745 $ret[$entry['ID']]= $entry['name'].$cm;
746 }
747 }
748 }
749 return($ret);
750 }
752 function getUsedCartridges($flip = false)
753 {
754 $ret = array();
755 foreach($this->usedCartridges as $key => $value){
756 if($value['status'] == "deleted") continue;
757 if($flip){
758 $ret[$key] = $key;
759 }else{
760 $ret[$key] = $value['name']." [".$value['type_name']."] "._("since")." :".$value['date_use'];
761 }
762 }
763 return($ret);
764 }
766 }
768 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
769 ?>