Code

Fixed connectivity acls
[gosa.git] / plugins / personal / environment / class_hotplugDialog.inc
1 <?php
3 class hotplugDialog 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("HOT_name","HOT_description","HOT_id","HOT_produkt","HOT_vendor");
13   var $objectclasses        = array("whatever");
14   var $use_existing         = false;  
16   var $HOT_name                 = "";
17   var $HOT_description          = "";
18   var $HOT_id                   = "";
19   var $HOT_produkt              = "";
20   var $HOT_vendor               = "";
22   var $hotplugDevices           = ""; 
23   var $hotplugDeviceList        = array(); 
24   var $regex                    = "*";
25   var $depselect                = "/";
26   var $deplist                  = "/";
27   var $skipThese                = array();
29   function hotplugDialog ($config, $dn= NULL,$use_existing=false ,$skipThese = array())
30   {
31     $this->use_existing = $use_existing;
32     $this->skipThese    = $skipThese;
33     plugin::plugin ($config, $dn);
34     $this->depselect = $this->config->current['BASE'];
35   }
37   function execute()
38   {
39         /* Call parent execute */
40         plugin::execute();
42     /* Fill templating stuff */
43     $smarty= get_smarty();
44     $display= "";
46     foreach($this->attributes as $s_attr){
47       $smarty->assign($s_attr,$this->$s_attr);
48     }
50     if($this->use_existing){
52       if(isset($_POST['dialogissubmitted'])){
53         $this->regex=$_POST['regexHot'];
54         $this->depselect = $_POST['depselectHot'];
55       }
57       if((isset($_GET['search']))&&(!empty($_GET['search']))){
58         $this->regex=$_GET['search']."*";
59         $this->regex=preg_replace("/\*\*/","*",$this->regex);
60       }
62       $this->deplist=$this->config->idepartments;
64       $this->hotplugDevices = $this->getHotplugs();
65       $smarty->assign("regexHot"    ,$this->regex);
66       $smarty->assign("deplistHot"  ,$this->deplist);
67       $smarty->assign("depselectHot",$this->depselect);
68       $smarty->assign("apply", apply_filter());
69       $smarty->assign("alphabet", generate_alphabet());
70       $smarty->assign("search_image", get_template_path('images/search.png'));
71       $smarty->assign("tree_image", get_template_path('images/tree.png'));
72       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
73       $smarty->assign("deplist", $this->config->idepartments);
76       $smarty->assign("hotplugDevices",$this->hotplugDevices);
77       $smarty->assign("hotplugDeviceKeys",array_flip($this->hotplugDevices));
78       $display.= $smarty->fetch(get_template_path('hotplugDialog.tpl', TRUE,dirname(__FILE__)));
79     }else{
80       $display.= $smarty->fetch(get_template_path('hotplugDialogNew.tpl', TRUE,dirname(__FILE__)));
81     }
82     return($display);
83   }
85   function remove_from_parent()
86   {
87     /* This cannot be removed... */
88   }
91   /* Save data to object */
92   function save_object()
93   {
94     if(isset($_POST['dialogissubmitted'])){
95       foreach($this->attributes as $s_attr){
96         if(isset($_POST[$s_attr])){
97           $this->$s_attr = stripslashes($_POST[$s_attr]);
98         }else{
99           $this->$s_attr = false;
100         }
101       }
102       plugin::save_object();
103     }
104   }
107   /* Check supplied data */
108   function check()
109   {
110     /* Call common method to give check the hook */
111     $message= plugin::check();
113     if(!$this->use_existing){
114       if((empty($this->HOT_name))||(preg_match("/[^a-z0-9]/i",$this->HOT_name))){
115         $message[]=_("Please specify a valid name. Only 0-9 a-Z is allowed.");
116       }
117       if((empty($this->HOT_description))||(preg_match("/[^a-z0-9!\"?.,;:-_\(\) ]/i",$this->HOT_description))){
118         $message[]=_("Invalid character in description. Please specify a valid description.");
119       }
120       if((empty($this->HOT_id))||(preg_match("/[\|]/i",$this->HOT_id))){
121         $message[]=_("Please specify a valid id.");
122       }
123       if((empty($this->HOT_vendor))||(preg_match("/[\|]/i",$this->HOT_vendor))){
124         $message[]=_("Please specify a valid id.");
125       }
126       if((empty($this->HOT_produkt))||(preg_match("/[\|]/i",$this->HOT_produkt))){
127         $message[]=_("Please specify a valid id.");
128       }
130     $ldap = $this->config->get_ldap_link();
131     $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->HOT_name."*))",array("gotoHotplugDevice"));
132     if($ldap->count()){
133       $message[]=_("An Entry with this name already exists.");
134     }
136     }else{
137       if((!isset($_POST['hotplugName']))||(empty($_POST['hotplugName']))){
138         $message[] = _("Please select an entry or press cancel.");
139       }
140     }
142     return ($message);
143   }
146   /* Save to LDAP */
147   function save()
148   {
149     /* return generated entry from input fields*/
150     if(!$this->use_existing){
151       $a_return=array();
152       $a_return[$this->HOT_name]['name']        = $this->HOT_name; 
153       $a_return[$this->HOT_name]['description'] = $this->HOT_description; 
154       $a_return[$this->HOT_name]['id']          = $this->HOT_id;
155       $a_return[$this->HOT_name]['produkt']     = $this->HOT_produkt;
156       $a_return[$this->HOT_name]['vendor']      = $this->HOT_vendor;
157       return($a_return); 
158     }else{
159       $entries = array();
160       foreach($_POST['hotplugName'] as $name){
161         $entries[$name] = $this->hotplugDeviceList[$name];
162       }
163       return $entries;
164     }
165   }
167   function getHotplugs(){
168     $ldap= $this->config->get_ldap_link();
169     $ldap->cd($this->depselect);
171     $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->regex."))",array("gotoHotplugDevice")); 
173     $a_return = array();  
174     $this->hotplugDeviceList = array();
175     while($attr = $ldap->fetch()){
176       if(isset($attr['gotoHotplugDevice'])){
177         unset($attr['gotoHotplugDevice']['count']);
178         foreach($attr['gotoHotplugDevice'] as $device){
179           $tmp =$tmp2= array();
180           $tmp = split("\|",$device);
181           
182           if(preg_match("/^".str_replace("*","",$this->regex).".*/i",$tmp[0])){
183   
184             if(in_array($tmp[0],$this->skipThese)) continue;
186             $a_return[$tmp[0]]= $tmp[0]." [".$tmp[1]."] ".$tmp[2];
187             
188             $tmp2['name']         = $tmp[0];
189             $tmp2['description']  = $tmp[1];
190             $tmp2['id']           = $tmp[2];
192             /* Produkt ID */
193             if(!isset($tmp[3])){
194               $tmp[3] = "";
195             }
196             /* Vendor ID */
197             if(!isset($tmp[4])){
198               $tmp[4] = "";
199             }
201             $tmp2['produkt']      = $tmp[3];
202             $tmp2['vendor']       = $tmp[4];
204             $this->hotplugDeviceList[$tmp[0]]=$tmp2;
205           }
206         }
207       }
208     }
209   return($a_return);
210   }
214 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
215 ?>