Code

Added execute methods
[gosa.git] / plugins / personal / environment / class_selectPrinterDialog.inc
1 <?php
3 class selectPrinterDialog 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       = TRUE;
12   var $attributes           = array();
13   var $objectclasses        = array("whatever");
14   var $use_existing         = false;  
15   var $regex                = "*";
16   var $depselect            = "/";
17   var $deplist              = "/";
19   function selectPrinterDialog ($config, $dn= NULL,$use_existing=false )
20   {
21     $this->use_existing = $use_existing;
22     plugin::plugin ($config, $dn);
23     $this->depselect = $this->config->current['BASE'];
24   }
26   function execute()
27   {
28         /* Call parent execute */
29         plugin::execute();
30     /* Fill templating stuff */
31     $smarty= get_smarty();
32     $display= "";
34     if(isset($_POST['dialogissubmitted'])){
35       $this->regex=$_POST['regexPrinter'];
36       $this->depselect = $_POST['depselectPrinter'];
37     }
39     if((isset($_GET['search']))&&(!empty($_GET['search']))){
40       $this->regex=$_GET['search']."*";
41       $this->regex=preg_replace("/\*\*/","*",$this->regex);
42     }
44     $this->deplist=array_flip($this->config->departments);
46     $smarty->assign("regexPrinter"    ,$this->regex);
47     $smarty->assign("deplistPrinter"  ,$this->deplist);
48     $smarty->assign("depselectPrinter",$this->depselect);
49     $smarty->assign("gotoPrinters",$this->getPrinter());
50     $smarty->assign("gotoPrinterKeys",array_flip($this->getPrinter()));
51     $smarty->assign("apply", apply_filter());
52     $smarty->assign("alphabet", generate_alphabet());
53     $smarty->assign("search_image", get_template_path('images/search.png'));
54     $smarty->assign("tree_image", get_template_path('images/tree.png'));
55     $smarty->assign("infoimage", get_template_path('images/info.png'));
56     $smarty->assign("launchimage", get_template_path('images/launch.png'));
57     $smarty->assign("deplist", $this->config->idepartments);
59     $display.= $smarty->fetch(get_template_path('selectPrinterDialog.tpl', TRUE,dirname(__FILE__)));
60     return($display);
61   }
63   function check(){
64     $message=array();
65     if(empty($_POST['gotoPrinter'])){
66       $message[] = _("Please select a printer or press cancel.");
67     }
68     return $message;
69   }
71   /* Save to LDAP */
72   function save()
73   {
74     return($_POST['gotoPrinter']);
75   }
77   /* This function generates the Printerlist
78    * All printers are returned that match regex and and depselect
79    */
80   function getPrinter($detailed = false)
81   {
82     $a_return=array();
83     $ldap = $this->config->get_ldap_link();
84     $ldap->cd($this->depselect);
85     $ldap->search("(&(objectClass=gotoPrinter)(cn=".$this->regex."))",array("*"));
86     while($printer = $ldap->fetch()){
87       if($detailed ==true){
88         $a_return[$printer['cn'][0]] = $printer;
89       }else{
90         if(isset($printer['description'][0])){
91           $a_return[$printer['cn'][0]] = $printer['cn'][0]." - ".$printer['description'][0];  
92         }else{
93           $a_return[$printer['cn'][0]] = $printer['cn'][0];  
94         }
95       }
96     }
97     return($a_return);
98   }
99 }
105 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
106 ?>