Code

* Created "old" branch and moved stuff
[gosa.git] / branches / old / 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("printer");
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(); 
83                 asort($printer_list);
85     $smarty->assign("regexPrinter"    ,$this->regex);
86     $smarty->assign("deplistPrinter"  ,$this->deplist);
87     $smarty->assign("depselectPrinter",$this->depselect);
88     $smarty->assign("gotoPrinters",$printer_list);
89     $smarty->assign("gotoPrinterKeys",array_flip($printer_list));
90     $smarty->assign("apply", apply_filter());
91     $smarty->assign("alphabet", generate_alphabet());
92     $smarty->assign("subtrees", $this->subtreesearch?"checked":"");
93     $smarty->assign("search_image", get_template_path('images/lists/search.png'));
94     $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
95     $smarty->assign("infoimage", get_template_path('images/info.png'));
96     $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
97     $smarty->assign("deplist", $this->config->idepartments);
99     $display.= $smarty->fetch(get_template_path('selectPrinterDialog.tpl', TRUE,dirname(__FILE__)));
100     return($display);
101   }
103   function check(){
104     /* Call common method to give check the hook */
105     $message= plugin::check();
107     if(empty($_POST['gotoPrinter'])){
108       $message[] = _("Please select a printer!");
109     }
110     return $message;
111   }
113   /* Save to LDAP */
114   function save()
115   {
116     return($_POST['gotoPrinter']);
117   }
119   /* This function generates the Printerlist
120    * All printers are returned that match regex and and depselect
121    */
122   function getPrinter($detailed = false)
123   {
124     $a_return=array();
127     $filter = "(&(objectClass=gotoPrinter)(cn=".$this->regex."))";
128     $module = $this->module;
129     $base   = $this->depselect;
130     $attrs  = array("cn","description");
132     if ($this->subtreesearch){
133       $res    = get_list($filter,$module,$base,$attrs, GL_SIZELIMIT | GL_SUBSEARCH);
134     } else {
135       $base= get_ou('printerou').$base;
136       $res    = get_list($filter,$module,$base,$attrs, GL_SIZELIMIT );
137     }
139     foreach($res as $printer)  {
140       $acl = $this->ui->get_permissions($printer['dn'],"printer/printgeneric","gotoUserPrinter");;
141       if(!preg_match("/w/",$acl)){
142         continue;
143       }
144       if(isset($this->AlreadyAssigned[$printer['cn'][0]])) continue;
145       if($detailed ==true){
146         $a_return[$printer['cn'][0]] = $printer;
147       }else{
148         if(isset($printer['description'][0])){
149           $a_return[$printer['cn'][0]] = $printer['cn'][0]." - ".$printer['description'][0];  
150         }else{
151           $a_return[$printer['cn'][0]] = $printer['cn'][0];  
152         }
153       }
154     }
155     return($a_return);
156   }
159 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
160 ?>