Code

Removed CLI
[gosa.git] / gosa-plugins / goto / personal / environment / class_selectPrinterDialog.inc
1 <?php
3 class selectPrinterDialog 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 $AlreadyAssigned      = array();  
10   var $regex                = "*";
11   var $depselect            = "/";
12   var $deplist              = array("/");
13   var $module               = array("printer");
14   var $ui                   = NULL;
15   var $subtreesearch        = FALSE;
17   function selectPrinterDialog (&$config, $dn= NULL,$alreadyused=array() )
18   {
19     $this->AlreadyAssigned = $alreadyused;
20     plugin::plugin ($config, $dn);
22     /* Get all departments within this subtree */
23     $base = $this->config->current['BASE'];
25     /* Add base */
26     $tmp = array();
27     $tmp[] = array("dn"=>$this->config->current['BASE']);
28     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
29                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
31     $deps = array();
32     foreach($tmp as $tm){
33       $deps[$tm['dn']] = $tm['dn'];
34     }
37     /* Load possible departments */
38     $ui= get_userinfo();
39     $this->ui = $ui;
40     $tdeps= $ui->get_module_departments("users");
41     $ids = $this->config->idepartments;
42     $first = "";
43     $found = FALSE;
44     $res = array();
45     foreach($ids as $dep => $name){
46       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
47         $res[$dep] = $ids[$dep]; //$tdeps[$dep];
48       }
49     }
50     $this->deplist = $res;
51     $this->depselect = key($res);
52   }
54   function execute()
55   {
56     /* Call parent execute */
57     plugin::execute();
59     /* Fill templating stuff */
60     $smarty= get_smarty();
61     $display= "";
63     if(isset($_POST['dialogissubmitted'])){
64       foreach(array('regexPrinter' => 'regex','depselectPrinter'=>'depselect') as $attr => $name){
65         if(isset($_POST[$attr])){
66           $this->$name      =$_POST[$attr];
67         }
68       }
69     }
71     if(isset($_POST['subtrees'])){
72       $this->subtreesearch= TRUE;
73     } else {
74       $this->subtreesearch= FALSE;
75     }
77     if((isset($_GET['search']))&&(!empty($_GET['search']))){
78       $this->regex=$_GET['search']."*";
79       $this->regex=preg_replace("/\*\*/","*",$this->regex);
80     }
82     $printer_list = $this->getPrinter(); 
84     $smarty->assign("regexPrinter"    ,$this->regex);
85     $smarty->assign("deplistPrinter"  ,$this->deplist);
86     $smarty->assign("depselectPrinter",$this->depselect);
87     $smarty->assign("gotoPrinters",$printer_list);
88     $smarty->assign("gotoPrinterKeys",array_flip($printer_list));
89     $smarty->assign("apply", apply_filter());
90     $smarty->assign("alphabet", generate_alphabet());
91     $smarty->assign("subtrees", $this->subtreesearch?"checked":"");
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('selectPrinterDialog.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     return($_POST['gotoPrinter']);
116   }
118   /* This function generates the Printerlist
119    * All printers are returned that match regex and and depselect
120    */
121   function getPrinter($detailed = false)
122   {
123     $a_return=array();
126     $filter = "(&(objectClass=gotoPrinter)(cn=".$this->regex."))";
127     $module = $this->module;
128     $base   = $this->depselect;
129     $attrs  = array("cn","description");
131     if ($this->subtreesearch){
132       $res    = get_list($filter,$module,$base,$attrs, GL_SIZELIMIT | GL_SUBSEARCH);
133     } else {
134       $base= get_ou('printerou').$base;
135       $res    = get_list($filter,$module,$base,$attrs, GL_SIZELIMIT );
136     }
138     foreach($res as $printer)  {
140       $acl = $this->ui->get_permissions($printer['dn'],"printer/printgeneric","gotoUserPrinter");
142       if(!preg_match("/w/",$acl)){
143         continue;
144       }
146       if(isset($this->AlreadyAssigned[$printer['cn'][0]])) continue;
148       if($detailed ==true){
149         $a_return[$printer['cn'][0]] = $printer;
150       }else{
151         if(isset($printer['description'][0])){
152           $a_return[$printer['cn'][0]] = $printer['cn'][0]." - ".$printer['description'][0];  
153         }else{
154           $a_return[$printer['cn'][0]] = $printer['cn'][0];  
155         }
156       }
157     }
158     return($a_return);
159   }
166 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
167 ?>