Code

Replaced "mofify" in handle_post_events(mofify) with "modify".
[gosa.git] / plugins / admin / systems / class_selectUserToPrinterDialog.inc
1 <?php
3 class selectUserToPrinterDialog 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 $regex                = "*";
15   var $depselect            = "/";
16   var $deplist              = "/";
18   var $searchObjects        = "";
19   var $searchAttrs          = "";
20   var $searchAppend         = "";
21   var $baseAddition         = "";
22   var $type                 = "";
23   
24   function selectUserToPrinterDialog ($config, $dn= NULL,$type=false )
25   {
26     plugin::plugin ($config, $dn);
27     $this->depselect = $this->config->current['BASE'];
29     switch($type){
30       case "AddUser" : 
31         $this->searchObjects = "(objectClass=gosaAccount)(!(uid=*$))";
32         $this->searchAttrs   = array("cn","uid");
33         $this->searchAppend  = "uid"; 
34         $this->baseAddition  = get_people_ou(); 
35           ;break;
36       case "AddGroup" :
37         $this->searchObjects = "(objectClass=posixGroup)";
38         $this->searchAttrs   = array("cn","description");
39         $this->searchAppend  = "cn"; 
40         $this->baseAddition  = get_groups_ou(); 
41           ;break;
42       case "AddAdminUser" : 
43         $this->searchObjects = "(objectClass=gosaAccount)(!(uid=*$))";
44         $this->searchAttrs   = array("cn","uid");
45         $this->searchAppend  = "uid"; 
46         $this->baseAddition  = get_people_ou(); 
47           ;break;
48       case "AddAdminGroup" :
49         $this->searchObjects = "(objectClass=posixGroup)";
50         $this->searchAttrs   = array("cn","description");
51         $this->searchAppend  = "cn"; 
52         $this->baseAddition  = get_groups_ou(); 
53           ;break;
54     }
55     $this->type = $type;
57   }
59   function execute()
60   {
61         /* Call parent execute */
62         plugin::execute();
64     /* Fill templating stuff */
65     $smarty= get_smarty();
66     $display= "";
68     if(isset($_POST['dialogissubmitted'])){
69       $this->regex=$_POST['regexPrinter'];
70       $this->depselect = $_POST['depselectPrinter'];
71     }
73     if((isset($_GET['search']))&&(!empty($_GET['search']))){
74       $this->regex=$_GET['search']."*";
75       $this->regex=preg_replace("/\*\*/","*",$this->regex);
76     }
78     $tmp_printers= $this->getPrinter();
79     natcasesort($tmp_printers);
80     $smarty->assign("regexPrinter"        , $this->regex);
81     $smarty->assign("deplistPrinter"      , $this->config->idepartments);//deplist);
82     $smarty->assign("depselectPrinter"    , $this->depselect);
83     $smarty->assign("gotoPrinters"        , $tmp_printers);
84     $smarty->assign("gotoPrinterKeys"     , array_flip($tmp_printers));
85     $smarty->assign("apply"               , apply_filter());
86     $smarty->assign("alphabet"            , generate_alphabet());
87     $smarty->assign("search_image"        , get_template_path('images/search.png'));
88     $smarty->assign("tree_image"          , get_template_path('images/tree.png'));
89     $smarty->assign("infoimage"           , get_template_path('images/info.png'));
90     $smarty->assign("launchimage"         , get_template_path('images/small_filter.png'));
91     $smarty->assign("deplist"             , $this->config->idepartments);
93     $display.= $smarty->fetch(get_template_path('selectUserToPrinterDialog.tpl', TRUE,dirname(__FILE__)));
94     return($display);
95   }
97   function check(){
98     /* Call common method to give check the hook */
99     $message= plugin::check();
101     if(empty($_POST['gotoPrinter'])){
102       $message[] = _("Please select a printer or press cancel.");
103     }
104     return $message;
105   }
107   /* Save to LDAP */
108   function save()
109   {
110     $a_return['type']=$this->type;
111     
112     foreach($_POST['gotoPrinter'] as $name){
113       $data = $this->getPrinter(true);
114       $a_return[$name]= $data[$name];
115     }
116     return($a_return);
117   }
119   /* This function generates the Printerlist
120    * All printers are returned that match regex and and depselect
121    */
122   function getPrinter($detailed = false)
123   {
124     $a_return=array();
125     $ldap = $this->config->get_ldap_link();
126     $ldap->cd($this->depselect);
127     #$ldap->search("(&".$this->searchObjects."(cn=".$this->regex."))", $this->depselect, $this->searchAttrs);
128     $ldap->ls("(&".$this->searchObjects."(cn=".$this->regex."))", $this->baseAddition.$this->depselect, $this->searchAttrs);
129     while($printer = $ldap->fetch()){
130       if(($detailed ==true)){
131         if(isset($printer[$this->searchAppend])){
132           $a_return[$printer[$this->searchAppend][0]] = $printer;
133         }
134       }else{
135         if(isset($printer[$this->searchAppend])){
136           if(isset($printer['description'][0])){
137             $a_return[$printer[$this->searchAppend][0]] = $printer['cn'][0]." - ".$printer['description'][0]; 
138           }else{
139             $a_return[$printer[$this->searchAppend][0]] = $printer['cn'][0];
140           }
141         }
142       }
143     }
144     return($a_return);
145   }
148 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
149 ?>