Code

Fixed typo
[gosa.git] / gosa-plugins / goto / personal / environment / class_hotplugDialog.inc
1 <?php
3 class hotplugDialog extends plugin
4 {
5   /* attribute list for save action */
6   var $hotplugDevices           = ""; 
7   var $hotplugDeviceList        = array(); 
8   var $regex                    = "*";
9   var $depselect                = "/";
10   var $deplist                  = "/";
11   var $skipThese                = array();
13   function hotplugDialog (&$config,$skipThese = array())
14   {
15     $this->skipThese  = $skipThese;
16     $this->config     = $config;
17     $this->depselect   = session::get('CurrentMainBase');
18   }
20   function execute()
21   {
22     /* Call parent execute */
23     plugin::execute();
25     /* Fill templating stuff */
26     $smarty= get_smarty();
27     $display= "";
29     if(isset($_POST['dialogissubmitted'])){
30       $this->regex=$_POST['regexHot'];
31       $this->depselect = $_POST['depselectHot'];
32     }
34     if((isset($_GET['search']))&&(!empty($_GET['search']))){
35       $this->regex=$_GET['search']."*";
36       $this->regex=preg_replace("/\*\*/","*",$this->regex);
37     }
39     $this->deplist=$this->config->idepartments;
41     $this->hotplugDevices = $this->getHotplugs();
42     $smarty->assign("regexHot"    ,$this->regex);
43     $smarty->assign("deplistHot"  ,$this->deplist);
44     $smarty->assign("depselectHot",$this->depselect);
45     $smarty->assign("apply", apply_filter());
46     $smarty->assign("alphabet", generate_alphabet());
47     $smarty->assign("search_image", get_template_path('images/search.png'));
48     $smarty->assign("tree_image", get_template_path('images/tree.png'));
49     $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
50     $smarty->assign("deplist", $this->config->idepartments);
53     $smarty->assign("hotplugDevices",$this->hotplugDevices);
54     $smarty->assign("hotplugDeviceKeys",array_flip($this->hotplugDevices));
55     $display.= $smarty->fetch(get_template_path('hotplugDialog.tpl', TRUE,dirname(__FILE__)));
56     return($display);
57   }
59   function check(){
60     /* Call common method to give check the hook */
61     $message= plugin::check();
63     if(empty($_POST['hotplugName'])){
64       $message[] = _("Please select a hotplug device!");
65     }
66     return $message;
67   }
70   /* Save to LDAP */
71   function save()
72   {
73     $entries = array();
74     foreach($_POST['hotplugName'] as $name){
75       $entries[$name] = $this->hotplugDeviceList[$name];
76     }
78     return $entries;
79   }
81   function getHotplugs()
82   {
83     $ldap= $this->config->get_ldap_link();
84     $ldap->cd(get_ou('deviceou').$this->depselect);
85     $ldap->search("(&(objectClass=gotoDevice)(|(cn=".$this->regex.")(description=".$this->regex.")))",array("gotoHotplugDevice","cn","dn")); 
87     $a_return = array();  
88     $this->hotplugDeviceList = array();
89     while($attr = $ldap->fetch()){
91       if(isset($attr['gotoHotplugDevice'][0])){
93         $hot_plug = $attr['gotoHotplugDevice'][0];
94         $tmp      = preg_split("/\|/",$hot_plug);
95         $tmp2     = array();
96           
97         if(in_array($attr['cn'][0],$this->skipThese)){
98           continue;
99         }
101         $tmp2['name']         = $attr['cn'][0];
102         $tmp2['description']  = $tmp[0];
103         $tmp2['id']           = $tmp[1];
104         $tmp2['produkt']      = $tmp[2];
105         $tmp2['vendor']       = $tmp[3];
106         $tmp2['dn']           = $attr['dn'];
108         $a_return[$attr['cn'][0]]= $attr['cn'][0]." [".$tmp[0]."] ".$tmp[1];
110         $this->hotplugDeviceList[$attr['cn'][0]]=$tmp2;
111       }
112     }
113     return($a_return);
114   }
117 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
118 ?>