Code

3e29356213fe48645eb94f6400a0ef26e34893f4
[gosa.git] / plugins / personal / environment / class_selectPrinterDialog.inc
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;
20   var $subtreesearch        = FALSE;
22   function selectPrinterDialog ($config, $dn= NULL,$alreadyused=array() )
23   {
24     $this->AlreadyAssigned = $alreadyused;
25     plugin::plugin ($config, $dn);
27     /* Get all departments within this subtree */
28     $base = $this->config->current['BASE'];
30     /* Add base */
31     $tmp = array();
32     $tmp[] = array("dn"=>$this->config->current['BASE']);
33     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
34                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
36     $deps = array();
37     foreach($tmp as $tm){
38       $deps[$tm['dn']] = $tm['dn'];
39     }
42     /* Load possible departments */
43     $ui= get_userinfo();
44     $this->ui = $ui;
45     $tdeps= $ui->get_module_departments("users");
46     $ids = $this->config->idepartments;
47     $first = "";
48     $found = FALSE;
49     $res = array();
50     foreach($ids as $dep => $name){
51       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
52         $res[$dep] = $ids[$dep]; //$tdeps[$dep];
53       }
54     }
55     $this->deplist = $res;
56     $this->depselect = key($res);
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       foreach(array('regexPrinter' => 'regex','depselectPrinter'=>'depselect') as $attr => $name){
70         if(isset($_POST[$attr])){
71           $this->$name      =$_POST[$attr];
72         }
73       }
74     }
76     if(isset($_POST['subtrees'])){
77       $this->subtreesearch= TRUE;
78     } else {
79       $this->subtreesearch= FALSE;
80     }
82     if((isset($_GET['search']))&&(!empty($_GET['search']))){
83       $this->regex=$_GET['search']."*";
84       $this->regex=preg_replace("/\*\*/","*",$this->regex);
85     }
87     $smarty->assign("regexPrinter"    ,$this->regex);
88     $smarty->assign("deplistPrinter"  ,$this->deplist);
89     $smarty->assign("depselectPrinter",$this->depselect);
90     $smarty->assign("gotoPrinters",$this->getPrinter());
91     $smarty->assign("gotoPrinterKeys",array_flip($this->getPrinter()));
92     $smarty->assign("apply", apply_filter());
93     $smarty->assign("alphabet", generate_alphabet());
94     $smarty->assign("subtrees", $this->subtreesearch?"checked":"");
95     $smarty->assign("search_image", get_template_path('images/search.png'));
96     $smarty->assign("tree_image", get_template_path('images/tree.png'));
97     $smarty->assign("infoimage", get_template_path('images/info.png'));
98     $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
99     $smarty->assign("deplist", $this->config->idepartments);
101     $display.= $smarty->fetch(get_template_path('selectPrinterDialog.tpl', TRUE,dirname(__FILE__)));
102     return($display);
103   }
105   function check(){
106     /* Call common method to give check the hook */
107     $message= plugin::check();
109     if(empty($_POST['gotoPrinter'])){
110       $message[] = _("Please select a printer or press cancel.");
111     }
112     return $message;
113   }
115   /* Save to LDAP */
116   function save()
117   {
118     return($_POST['gotoPrinter']);
119   }
121   /* This function generates the Printerlist
122    * All printers are returned that match regex and and depselect
123    */
124   function getPrinter($detailed = false)
125   {
126     $a_return=array();
129     $filter = "(&(objectClass=gotoPrinter)(cn=".$this->regex."))";
130     $module = $this->module;
131     $base   = $this->depselect;
132     $attrs  = array("cn","description");
133     if ($this->subtreesearch){
134       $res    = get_list($filter,$module,$base,$attrs, GL_SIZELIMIT, GL_SUBSEARCH);
135     } else {
136       $base= "ou=printers,ou=systems,".$base;
137       $res    = get_list($filter,$module,$base,$attrs, GL_SIZELIMIT);
138     }
140     foreach($res as $printer)  {
142       $acl = $this->ui->get_permissions($printer['dn'],"printer/printgeneric","gotoUserPrinter");
144       if(!preg_match("/w/",$acl)){
145         continue;
146       }
148       if(isset($this->AlreadyAssigned[$printer['cn'][0]])) continue;
150       if($detailed ==true){
151         $a_return[$printer['cn'][0]] = $printer;
152       }else{
153         if(isset($printer['description'][0])){
154           $a_return[$printer['cn'][0]] = $printer['cn'][0]." - ".$printer['description'][0];  
155         }else{
156           $a_return[$printer['cn'][0]] = $printer['cn'][0];  
157         }
158       }
159     }
160     return($a_return);
161   }
168 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
169 ?>