Code

Removed ability to store spaces in the USB stick names
[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");
13   var $objectclasses        = array("whatever");
14   var $use_existing         = false;  
16   var $HOT_name                 = "";
17   var $HOT_description          = "";
18   var $HOT_id                   = "";
20   var $hotplugDevices           = ""; 
21   var $hotplugDeviceList        = array(); 
22   var $regex                    = "*";
23   var $depselect                = "/";
24   var $deplist                  = "/";
28   function hotplugDialog ($config, $dn= NULL,$use_existing=false )
29   {
30     $this->use_existing = $use_existing;
31     plugin::plugin ($config, $dn);
32     $this->depselect = $this->config->current['BASE'];
33   }
35   function execute()
36   {
37         /* Call parent execute */
38         plugin::execute();
40     /* Fill templating stuff */
41     $smarty= get_smarty();
42     $display= "";
44     foreach($this->attributes as $s_attr){
45       $smarty->assign($s_attr,$this->$s_attr);
46     }
48     if($this->use_existing){
50       if(isset($_POST['dialogissubmitted'])){
51         $this->regex=$_POST['regexHot'];
52         $this->depselect = $_POST['depselectHot'];
53       }
55       if((isset($_GET['search']))&&(!empty($_GET['search']))){
56         $this->regex=$_GET['search']."*";
57         $this->regex=preg_replace("/\*\*/","*",$this->regex);
58       }
60       $this->deplist=$this->config->idepartments;
62       $this->hotplugDevices = $this->getHotplugs();
63       $smarty->assign("regexHot"    ,$this->regex);
64       $smarty->assign("deplistHot"  ,$this->deplist);
65       $smarty->assign("depselectHot",$this->depselect);
66       $smarty->assign("apply", apply_filter());
67       $smarty->assign("alphabet", generate_alphabet());
68       $smarty->assign("search_image", get_template_path('images/search.png'));
69       $smarty->assign("tree_image", get_template_path('images/tree.png'));
70       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
71       $smarty->assign("deplist", $this->config->idepartments);
74       $smarty->assign("hotplugDevices",$this->hotplugDevices);
75       $smarty->assign("hotplugDeviceKeys",array_flip($this->hotplugDevices));
76       $display.= $smarty->fetch(get_template_path('hotplugDialog.tpl', TRUE,dirname(__FILE__)));
77     }else{
78       $display.= $smarty->fetch(get_template_path('hotplugDialogNew.tpl', TRUE,dirname(__FILE__)));
79     }
80     return($display);
81   }
83   function remove_from_parent()
84   {
85     /* This cannot be removed... */
86   }
89   /* Save data to object */
90   function save_object()
91   {
92     if(isset($_POST['dialogissubmitted'])){
93       foreach($this->attributes as $s_attr){
94         if(isset($_POST[$s_attr])){
95           $this->$s_attr = $_POST[$s_attr];
96         }else{
97           $this->$s_attr = false;
98         }
99       }
100       plugin::save_object();
101     }
102   }
105   /* Check supplied data */
106   function check()
107   {
108     /* Call common method to give check the hook */
109     $message= plugin::check();
111     if(!$this->use_existing){
112       if((empty($this->HOT_name))||(preg_match("/[^a-z0-9]/i",$this->HOT_name))){
113         $message[]=_("Please specify a valid name. Only 0-9 a-Z is allowed.");
114       }
115       if((empty($this->HOT_description))||(preg_match("/[^a-z0-9!\"?.,;:-_\(\) ]/i",$this->HOT_description))){
116         $message[]=_("Invalid character in description. Please specify a valid description.");
117       }
118       if((empty($this->HOT_id))||(preg_match("/[\|]/i",$this->HOT_id))){
119         $message[]=_("Please specify a valid id.");
120       }
122     $ldap = $this->config->get_ldap_link();
123     $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->HOT_name."*))",array("gotoHotplugDevice"));
124     if($ldap->count()){
125       $message[]=_("An Entry with this name already exists.");
126     }
128     }else{
129       if((!isset($_POST['hotplugName']))||(empty($_POST['hotplugName']))){
130         $message[] = _("Please select an entry or press cancel.");
131       }
132     }
134     return ($message);
135   }
138   /* Save to LDAP */
139   function save()
140   {
141     /* return generated entry from input fields*/
142     if(!$this->use_existing){
143       $a_return=array();
144       $a_return[$this->HOT_name]['name']= $this->HOT_name; 
145       $a_return[$this->HOT_name]['description']= $this->HOT_description; 
146       $a_return[$this->HOT_name]['id']= $this->HOT_id;
147       return($a_return); 
148     }else{
149       $entries = array();
150       foreach($_POST['hotplugName'] as $name){
151         $entries[$name] = $this->hotplugDeviceList[$name];
152       }
153       return $entries;
154     }
155   }
157   function getHotplugs(){
158     $ldap= $this->config->get_ldap_link();
159     $ldap->cd($this->depselect);
161     $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->regex."))",array("gotoHotplugDevice")); 
163     $a_return = array();  
164     $this->hotplugDeviceList = array();
165     while($attr = $ldap->fetch()){
166       if(isset($attr['gotoHotplugDevice'])){
167         unset($attr['gotoHotplugDevice']['count']);
168         foreach($attr['gotoHotplugDevice'] as $device){
169           $tmp =$tmp2= array();
170           $tmp = split("\|",$device);
171           
172           if(preg_match("/^".str_replace("*","",$this->regex).".*/i",$tmp[0])){
173             $a_return[$tmp[0]]= $tmp[0]." [".$tmp[1]."] ".$tmp[2];
174             
175             $tmp2['name']         = $tmp[0];
176             $tmp2['description'] = $tmp[1];
177             $tmp2['id']           = $tmp[2];
179             $this->hotplugDeviceList[$tmp[0]]=$tmp2;
180           }
181         }
182       }
183     }
184   return($a_return);
185   }
189 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
190 ?>