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 var $search_cat = "";
25 function selectUserToPrinterDialog ($config, $dn= NULL,$type=false )
26 {
27 plugin::plugin ($config, $dn);
28 $this->depselect = $this->config->current['BASE'];
30 switch($type){
31 case "AddUser" :
32 $this->searchObjects = "(objectClass=gosaAccount)(!(uid=*$))";
33 $this->searchAttrs = array("cn","uid");
34 $this->searchAppend = "uid";
35 $this->baseAddition = get_people_ou();
36 $this->search_cat = "users";
37 ;break;
38 case "AddGroup" :
39 $this->searchObjects = "(objectClass=posixGroup)";
40 $this->searchAttrs = array("cn","description");
41 $this->searchAppend = "cn";
42 $this->baseAddition = get_groups_ou();
43 $this->search_cat = "groups";
44 ;break;
45 case "AddAdminUser" :
46 $this->searchObjects = "(objectClass=gosaAccount)(!(uid=*$))";
47 $this->searchAttrs = array("cn","uid");
48 $this->searchAppend = "uid";
49 $this->baseAddition = get_people_ou();
50 $this->search_cat = "users";
51 ;break;
52 case "AddAdminGroup" :
53 $this->searchObjects = "(objectClass=posixGroup)";
54 $this->searchAttrs = array("cn","description");
55 $this->searchAppend = "cn";
56 $this->baseAddition = get_groups_ou();
57 $this->search_cat = "groups";
58 ;break;
59 }
60 $this->type = $type;
62 }
64 function execute()
65 {
66 /* Call parent execute */
67 plugin::execute();
69 /* Fill templating stuff */
70 $smarty= get_smarty();
71 $display= "";
73 if(isset($_POST['dialogissubmitted'])){
74 $this->regex=$_POST['regexPrinter'];
75 $this->depselect = $_POST['depselectPrinter'];
76 }
78 if((isset($_GET['search']))&&(!empty($_GET['search']))){
79 $this->regex=$_GET['search']."*";
80 $this->regex=preg_replace("/\*\*/","*",$this->regex);
81 }
83 $tmp_printers= $this->getPrinter();
84 natcasesort($tmp_printers);
85 $smarty->assign("regexPrinter" , $this->regex);
86 $smarty->assign("deplistPrinter" , $this->config->idepartments);//deplist);
87 $smarty->assign("depselectPrinter" , $this->depselect);
88 $smarty->assign("gotoPrinters" , $tmp_printers);
89 $smarty->assign("gotoPrinterKeys" , array_flip($tmp_printers));
90 $smarty->assign("apply" , apply_filter());
91 $smarty->assign("alphabet" , generate_alphabet());
92 $smarty->assign("search_image" , get_template_path('images/search.png'));
93 $smarty->assign("tree_image" , get_template_path('images/tree.png'));
94 $smarty->assign("infoimage" , get_template_path('images/info.png'));
95 $smarty->assign("launchimage" , get_template_path('images/small_filter.png'));
96 $smarty->assign("deplist" , $this->config->idepartments);
98 $display.= $smarty->fetch(get_template_path('selectUserToPrinterDialog.tpl', TRUE,dirname(__FILE__)));
99 return($display);
100 }
102 function check(){
103 /* Call common method to give check the hook */
104 $message= plugin::check();
106 if(empty($_POST['gotoPrinter'])){
107 $message[] = _("Please select a printer or press cancel.");
108 }
109 return $message;
110 }
112 /* Save to LDAP */
113 function save()
114 {
115 $a_return['type']=$this->type;
117 foreach($_POST['gotoPrinter'] as $name){
118 $data = $this->getPrinter(true);
119 $a_return[$name]= $data[$name];
120 }
121 return($a_return);
122 }
124 /* This function generates the Printerlist
125 * All printers are returned that match regex and and depselect
126 */
127 function getPrinter($detailed = false)
128 {
129 $a_return=array();
131 $filter = "(&".$this->searchObjects."(cn=".$this->regex."))";
132 $base = $this->baseAddition.$this->depselect;
133 $attrs = $this->searchAttrs;
134 $cat = $this->search_cat;
136 $res = get_list($filter,$cat,$base,$attrs);
137 foreach($res as $printer){
138 if(($detailed ==true)){
139 if(isset($printer[$this->searchAppend])){
140 $a_return[$printer[$this->searchAppend][0]] = $printer;
141 }
142 }else{
143 if(isset($printer[$this->searchAppend])){
144 if(isset($printer['description'][0])){
145 $a_return[$printer[$this->searchAppend][0]] = $printer['cn'][0]." - ".$printer['description'][0];
146 }else{
147 $a_return[$printer[$this->searchAppend][0]] = $printer['cn'][0];
148 }
149 }
150 }
151 }
152 return($a_return);
153 }
154 }
156 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
157 ?>