1 <?php
3 class selectPrinterDialog 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 $AlreadyAssigned = array();
15 var $regex = "*";
16 var $depselect = "/";
17 var $deplist = array("/");
18 var $module = array("printer");
19 var $ui = NULL;
21 function selectPrinterDialog ($config, $dn= NULL,$alreadyused=array() )
22 {
23 $this->AlreadyAssigned = $alreadyused;
24 plugin::plugin ($config, $dn);
26 /* Get all departments within this subtree */
27 $base = $this->config->current['BASE'];
28 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
29 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
31 $tmp =array();
32 foreach($deps as $dep){
33 $tmp[$dep['dn']] = $dep;
34 }
35 $deps = $tmp;
37 /* Load possible departments */
38 $this->ui= get_userinfo();
39 $department = array();
40 foreach($this->module as $module){
42 $d = $this->ui->get_module_departments($module);
43 foreach($d as $department){
44 $departments[$department] = $department;
45 }
46 }
47 $ids = $this->config->idepartments;
48 $this->deplist = array();
49 foreach($deps as $dep){
50 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $departments)){
51 $this->deplist[$dep['dn']] = $ids[$dep['dn']];
52 }
53 }
55 $this->depselect = key($this->deplist);
56 }
58 function execute()
59 {
60 /* Call parent execute */
61 plugin::execute();
63 /* Fill templating stuff */
64 $smarty= get_smarty();
65 $display= "";
67 if(isset($_POST['dialogissubmitted'])){
68 foreach(array('regexPrinter' => 'regex','depselectPrinter'=>'depselect') as $attr => $name){
69 if(isset($_POST[$attr])){
70 $this->$name =$_POST[$attr];
71 }
72 }
73 }
75 if((isset($_GET['search']))&&(!empty($_GET['search']))){
76 $this->regex=$_GET['search']."*";
77 $this->regex=preg_replace("/\*\*/","*",$this->regex);
78 }
80 $smarty->assign("regexPrinter" ,$this->regex);
81 $smarty->assign("deplistPrinter" ,$this->deplist);
82 $smarty->assign("depselectPrinter",$this->depselect);
83 $smarty->assign("gotoPrinters",$this->getPrinter());
84 $smarty->assign("gotoPrinterKeys",array_flip($this->getPrinter()));
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('selectPrinterDialog.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 return($_POST['gotoPrinter']);
111 }
113 /* This function generates the Printerlist
114 * All printers are returned that match regex and and depselect
115 */
116 function getPrinter($detailed = false)
117 {
118 $a_return=array();
121 $filter = "(&(objectClass=gotoPrinter)(cn=".$this->regex."))";
122 $module = $this->module;
123 $base = $this->depselect;
124 $attrs = array("cn","description");
125 $res = get_list($filter,$module,$base,$attrs);
127 foreach($res as $printer) {
129 $acl = $this->ui->get_permissions($printer['dn'],"printer","gotoUserPrinter");
130 if(!preg_match("/w/",$acl)){
131 continue;
132 }
134 if(isset($this->AlreadyAssigned[$printer['cn'][0]])) continue;
136 if($detailed ==true){
137 $a_return[$printer['cn'][0]] = $printer;
138 }else{
139 if(isset($printer['description'][0])){
140 $a_return[$printer['cn'][0]] = $printer['cn'][0]." - ".$printer['description'][0];
141 }else{
142 $a_return[$printer['cn'][0]] = $printer['cn'][0];
143 }
144 }
145 }
146 return($a_return);
147 }
148 }
154 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
155 ?>