1 <?php
3 class selectUserToPrinterDialog extends plugin
4 {
5 /* attribute list for save action */
6 var $ignore_account = TRUE;
7 var $attributes = array();
8 var $objectclasses = array("whatever");
9 var $regex = "*";
10 var $subtree = FALSE;
11 var $depselect = "/";
12 var $deplist = "/";
14 var $searchObjects = "";
15 var $searchAttrs = "";
16 var $searchAppend = "";
17 var $baseAddition = "";
18 var $type = "";
19 var $search_cat = "";
21 function selectUserToPrinterDialog (&$config, $dn= NULL,$type=false )
22 {
23 plugin::plugin ($config, $dn);
24 $this->depselect = $this->config->current['BASE'];
26 switch($type){
27 case "AddUser" :
28 $this->searchObjects = "(objectClass=gosaAccount)(!(uid=*$))";
29 $this->searchAttrs = array("cn","uid");
30 $this->searchAppend = "uid";
31 $this->baseAddition = get_people_ou();
32 $this->search_cat = "users";
33 ;break;
34 case "AddGroup" :
35 $this->searchObjects = "(objectClass=posixGroup)";
36 $this->searchAttrs = array("cn","description");
37 $this->searchAppend = "cn";
38 $this->baseAddition = get_groups_ou();
39 $this->search_cat = "groups";
40 ;break;
41 case "AddAdminUser" :
42 $this->searchObjects = "(objectClass=gosaAccount)(!(uid=*$))";
43 $this->searchAttrs = array("cn","uid");
44 $this->searchAppend = "uid";
45 $this->baseAddition = get_people_ou();
46 $this->search_cat = "users";
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 $this->search_cat = "groups";
54 ;break;
55 }
56 $this->type = $type;
58 }
60 function execute()
61 {
62 /* Call parent execute */
63 plugin::execute();
65 /* Fill templating stuff */
66 $smarty= get_smarty();
67 $display= "";
69 if(isset($_POST['dialogissubmitted'])){
70 $this->regex=$_POST['regexPrinter'];
71 $this->depselect = $_POST['depselectPrinter'];
72 }
73 $this->subtree= isset($_POST['SubSearch']);
75 if((isset($_GET['search']))&&(!empty($_GET['search']))){
76 $this->regex=$_GET['search']."*";
77 $this->regex=preg_replace("/\*\*/","*",$this->regex);
78 }
81 /* Get all departments within this subtree */
82 $base = $this->config->current['BASE'];
83 $deps_res[] = array("dn"=>$this->config->current['BASE']);
84 $deps_res= array_merge($deps_res,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", array("users","groups"), $this->config->current['BASE'],
85 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
87 /* Load possible departments */
88 $ui = get_userinfo();
90 /* Allowed user departments */
91 $udeps = $ui->get_module_departments("users");
93 /* Allowed groups department */
94 $gdeps = $ui->get_module_departments("groups");
96 /* Combine both arrays */
97 $tdeps = array_unique(array_merge($udeps,$gdeps));
99 /* Create usable departments array */
100 $ids = $this->config->idepartments;
101 $deps = array();
102 foreach($deps_res as $dep){
103 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
104 $value = $ids[$dep['dn']];
105 $deps[$dep['dn']] = $value;
106 }
107 }
108 if(!isset($deps[$this->depselect])){
109 $this->depselect = key($deps);
110 }
113 $tmp_printers= $this->getPrinter();
114 natcasesort($tmp_printers);
115 $smarty->assign("regexPrinter" , $this->regex);
116 $smarty->assign("deplistPrinter" , $deps);;//deplist);
117 $smarty->assign("depselectPrinter" , $this->depselect);
118 $smarty->assign("gotoPrinters" , array_values($tmp_printers));
119 $smarty->assign("gotoPrinterKeys" , array_keys($tmp_printers));
120 $smarty->assign("apply" , apply_filter());
121 $smarty->assign("alphabet" , generate_alphabet());
122 $smarty->assign("search_image" , get_template_path('images/lists/search.png'));
123 $smarty->assign("tree_image" , get_template_path('images/lists/search-subtree.png'));
124 $smarty->assign("infoimage" , get_template_path('images/info.png'));
125 $smarty->assign("launchimage" , get_template_path('images/lists/action.png'));
126 $smarty->assign("deplist" , $deps);
127 $smarty->assign("subtree", $this->subtree?"checked":"");
129 $display.= $smarty->fetch(get_template_path('selectUserToPrinterDialog.tpl', TRUE,dirname(__FILE__)));
130 return($display);
131 }
133 function check(){
134 /* Call common method to give check the hook */
135 $message= plugin::check();
137 if(empty($_POST['gotoPrinter'])){
138 $message[] = _("Please select a printer or press cancel.");
139 }
140 return $message;
141 }
143 /* Save to LDAP */
144 function save()
145 {
146 $a_return['type']=$this->type;
148 foreach($_POST['gotoPrinter'] as $name){
149 $data = $this->getPrinter(true);
150 $a_return[$name]= $data[$name];
151 }
152 return($a_return);
153 }
155 /* This function generates the Printerlist
156 * All printers are returned that match regex and and depselect
157 */
158 function getPrinter($detailed = false)
159 {
160 $a_return=array();
162 $filter = "(&".$this->searchObjects."(cn=".$this->regex."))";
163 $base = $this->baseAddition.$this->depselect;
164 $attrs = $this->searchAttrs;
165 $cat = $this->search_cat;
167 if ($this->subtree){
168 $res= get_list($filter,$cat,$this->depselect,$attrs, GL_SUBSEARCH);
169 } else {
170 $res= get_list($filter,$cat,$base,$attrs);
171 }
172 foreach($res as $printer){
173 if(($detailed ==true)){
174 if(isset($printer[$this->searchAppend])){
175 $a_return[$printer[$this->searchAppend][0]] = $printer;
176 }
177 }else{
178 if(isset($printer[$this->searchAppend])){
179 if(isset($printer['description'][0])){
180 $a_return[$printer[$this->searchAppend][0]] = $printer['cn'][0]." - ".$printer['description'][0];
181 }else{
182 $a_return[$printer[$this->searchAppend][0]] = $printer['cn'][0];
183 }
184 }
185 }
186 }
187 return($a_return);
188 }
189 }
191 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
192 ?>