Code

Fixed self edit mode
[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 $AlreadyAssigned      = array();  
15   var $regex                = "*";
16   var $depselect            = "/";
17   var $deplist              = "/";
19   function selectPrinterDialog ($config, $dn= NULL,$alreadyused=array() )
20   {
21     $this->AlreadyAssigned = $alreadyused;
22     plugin::plugin ($config, $dn);
23     $this->depselect = $this->config->current['BASE'];
24   }
26   function execute()
27   {
28     /* Call parent execute */
29     plugin::execute();
31     /* Fill templating stuff */
32     $smarty= get_smarty();
33     $display= "";
35     if(isset($_POST['dialogissubmitted'])){
36       $this->regex=$_POST['regexPrinter'];
37       $this->depselect = $_POST['depselectPrinter'];
38     }
40     if((isset($_GET['search']))&&(!empty($_GET['search']))){
41       $this->regex=$_GET['search']."*";
42       $this->regex=preg_replace("/\*\*/","*",$this->regex);
43     }
45     $this->deplist=$this->config->idepartments;
47     $smarty->assign("regexPrinter"    ,$this->regex);
48     $smarty->assign("deplistPrinter"  ,$this->deplist);
49     $smarty->assign("depselectPrinter",$this->depselect);
50     $smarty->assign("gotoPrinters",$this->getPrinter());
51     $smarty->assign("gotoPrinterKeys",array_flip($this->getPrinter()));
52     $smarty->assign("apply", apply_filter());
53     $smarty->assign("alphabet", generate_alphabet());
54     $smarty->assign("search_image", get_template_path('images/search.png'));
55     $smarty->assign("tree_image", get_template_path('images/tree.png'));
56     $smarty->assign("infoimage", get_template_path('images/info.png'));
57     $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
58     $smarty->assign("deplist", $this->config->idepartments);
60     $display.= $smarty->fetch(get_template_path('selectPrinterDialog.tpl', TRUE,dirname(__FILE__)));
61     return($display);
62   }
64   function check(){
65     /* Call common method to give check the hook */
66     $message= plugin::check();
68     if(empty($_POST['gotoPrinter'])){
69       $message[] = _("Please select a printer or press cancel.");
70     }
71     return $message;
72   }
74   /* Save to LDAP */
75   function save()
76   {
77     return($_POST['gotoPrinter']);
78   }
80   /* This function generates the Printerlist
81    * All printers are returned that match regex and and depselect
82    */
83   function getPrinter($detailed = false)
84   {
85     $a_return=array();
86     $ldap = $this->config->get_ldap_link();
87     $ldap->cd($this->depselect);
88     $ldap->search("(&(objectClass=gotoPrinter)(cn=".$this->regex."))",array("*"));
89     while($printer = $ldap->fetch()){
91       if(isset($this->AlreadyAssigned[$printer['cn'][0]])) continue;
93       if($detailed ==true){
94         $a_return[$printer['cn'][0]] = $printer;
95       }else{
96         if(isset($printer['description'][0])){
97           $a_return[$printer['cn'][0]] = $printer['cn'][0]." - ".$printer['description'][0];  
98         }else{
99           $a_return[$printer['cn'][0]] = $printer['cn'][0];  
100         }
101       }
102     }
103     return($a_return);
104   }
111 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
112 ?>