Code

2fd7c342e8683fc6b07c81755409c3cb1f16f650
[gosa.git] / trunk / 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();
12   var $subtree                  = FALSE;
14   function hotplugDialog (&$config,$skipThese = array())
15   {
16     $this->skipThese  = $skipThese;
17     $this->config     = $config;
18     $this->depselect   = session::get('CurrentMainBase');
19   }
21   function execute()
22   {
23     /* Call parent execute */
24     plugin::execute();
26     /* Fill templating stuff */
27     $smarty= get_smarty();
28     $display= "";
30     if(isset($_POST['dialogissubmitted'])){
31       $this->regex=$_POST['regexHot'];
32       $this->depselect = $_POST['depselectHot'];
33     }
35     $this->subtree = isset($_POST['SubSearch']);
37     if((isset($_GET['search']))&&(!empty($_GET['search']))){
38       $this->regex=$_GET['search']."*";
39       $this->regex=preg_replace("/\*\*/","*",$this->regex);
40     }
42     $this->deplist=$this->config->idepartments;
44     $this->hotplugDevices = $this->getHotplugs();
45     $smarty->assign("regexHot"    ,$this->regex);
46     $smarty->assign("deplistHot"  ,$this->deplist);
47     $smarty->assign("depselectHot",$this->depselect);
48     $smarty->assign("apply", apply_filter());
49     $smarty->assign("alphabet", generate_alphabet());
50     $smarty->assign("search_image", get_template_path('images/lists/search.png'));
51     $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
52     $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
53     $smarty->assign("deplist", $this->config->idepartments);
54     $smarty->assign("subtree", $this->subtree?"checked":"");
57     $smarty->assign("hotplugDevices",$this->hotplugDevices);
58     $smarty->assign("hotplugDeviceKeys",array_flip($this->hotplugDevices));
59     $display.= $smarty->fetch(get_template_path('hotplugDialog.tpl', TRUE,dirname(__FILE__)));
60     return($display);
61   }
63   function check(){
64     /* Call common method to give check the hook */
65     $message= plugin::check();
67     if(empty($_POST['hotplugName'])){
68       $message[] = _("Please select a hotplug device!");
69     }
70     return $message;
71   }
74   /* Save to LDAP */
75   function save()
76   {
77     $entries = array();
78     foreach($_POST['hotplugName'] as $name){
79       $entries[$name] = $this->hotplugDeviceList[$name];
80     }
82     return $entries;
83   }
85   function getHotplugs()
86   {
87     $filter = "(&(objectClass=gotoDevice)(|(cn=".$this->regex.")(description=".$this->regex.")))";
88     $base = get_ou('deviceRDN').$this->depselect;
89     $attrs = array("gotoHotplugDevice", "cn", "dn");
90     $cat = "devices";
92     if ($this->subtree) {
93       $res = get_list($filter, $cat, $this->depselect, $attrs, GL_SUBSEARCH);
94     } else {
95       $res = get_list($filter, $cat, $base, $attrs);
96     }
98     $a_return = array();  
99     $this->hotplugDeviceList = array();
100     foreach ($res as $device) {
102       if(isset($device['gotoHotplugDevice'][0])){
104         $hot_plug = $device['gotoHotplugDevice'][0];
105         $tmp      = preg_split("/\|/",$hot_plug);
106         $tmp2     = array();
107           
108         if(in_array($device['cn'][0],$this->skipThese)){
109           continue;
110         }
112         $tmp2['name']         = $device['cn'][0];
113         $tmp2['description']  = $tmp[0];
114         $tmp2['id']           = $tmp[1];
115         $tmp2['produkt']      = $tmp[2];
116         $tmp2['vendor']       = $tmp[3];
117         $tmp2['dn']           = $device['dn'];
119         $a_return[$device['cn'][0]]= $device['cn'][0]." [".$tmp[0]."] ".$tmp[1];
121         $this->hotplugDeviceList[$device['cn'][0]]=$tmp2;
122       }
123     }
124     uksort($a_return,"strnatcasecmp");
125     return($a_return);
126   }
129 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
130 ?>