Code

Fixed layout
[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     $smarty->assign("regexPrinter"        , $this->regex);
80     $smarty->assign("deplistPrinter"      , $this->config->idepartments);//deplist);
81     $smarty->assign("depselectPrinter"    , $this->depselect);
82     $smarty->assign("gotoPrinters"        , $tmp_printers);
83     $smarty->assign("gotoPrinterKeys"     , array_flip($tmp_printers));
84     $smarty->assign("apply"               , apply_filter());
85     $smarty->assign("alphabet"            , generate_alphabet());
86     $smarty->assign("search_image"        , get_template_path('images/search.png'));
87     $smarty->assign("tree_image"          , get_template_path('images/tree.png'));
88     $smarty->assign("infoimage"           , get_template_path('images/info.png'));
89     $smarty->assign("launchimage"         , get_template_path('images/small_filter.png'));
90     $smarty->assign("deplist"             , $this->config->idepartments);
92     $display.= $smarty->fetch(get_template_path('selectUserToPrinterDialog.tpl', TRUE,dirname(__FILE__)));
93     return($display);
94   }
96   function check(){
97     /* Call common method to give check the hook */
98     $message= plugin::check();
100     if(empty($_POST['gotoPrinter'])){
101       $message[] = _("Please select a printer or press cancel.");
102     }
103     return $message;
104   }
106   /* Save to LDAP */
107   function save()
108   {
109     $a_return['type']=$this->type;
110     
111     foreach($_POST['gotoPrinter'] as $name){
112       $data = $this->getPrinter(true);
113       $a_return[$name]= $data[$name];
114     }
115     return($a_return);
116   }
118   /* This function generates the Printerlist
119    * All printers are returned that match regex and and depselect
120    */
121   function getPrinter($detailed = false)
122   {
123     $a_return=array();
124     $ldap = $this->config->get_ldap_link();
125     $ldap->cd($this->depselect);
126     #$ldap->search("(&".$this->searchObjects."(cn=".$this->regex."))", $this->depselect, $this->searchAttrs);
127     $ldap->ls("(&".$this->searchObjects."(cn=".$this->regex."))", $this->baseAddition.$this->depselect, $this->searchAttrs);
128     while($printer = $ldap->fetch()){
129       if(($detailed ==true)){
130         if(isset($printer[$this->searchAppend])){
131           $a_return[$printer[$this->searchAppend][0]] = $printer;
132         }
133       }else{
134         if(isset($printer[$this->searchAppend])){
135           if(isset($printer['description'][0])){
136             $a_return[$printer[$this->searchAppend][0]] = $printer['cn'][0]." - ".$printer['description'][0]; 
137           }else{
138             $a_return[$printer[$this->searchAppend][0]] = $printer['cn'][0];
139           }
140         }
141       }
142     }
143     return($a_return);
144   }
147 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
148 ?>