Code

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