Code

039f40b7377438d7f48e42f7c96378b43dfd1117
[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();
39     /* Fill templating stuff */
40     $smarty= get_smarty();
41     $display= "";
43     foreach($this->attributes as $s_attr){
44       $smarty->assign($s_attr,$this->$s_attr);
45     }
47     if($this->use_existing){
49       if(isset($_POST['dialogissubmitted'])){
50         $this->regex=$_POST['regexHot'];
51         $this->depselect = $_POST['depselectHot'];
52       }
54       if((isset($_GET['search']))&&(!empty($_GET['search']))){
55         $this->regex=$_GET['search']."*";
56         $this->regex=preg_replace("/\*\*/","*",$this->regex);
57       }
59       $this->deplist=array_flip($this->config->departments);
61       $this->hotplugDevices = $this->getHotplugs();
62       $smarty->assign("regexHot"    ,$this->regex);
63       $smarty->assign("deplistHot"  ,$this->deplist);
64       $smarty->assign("depselectHot",$this->depselect);
65       $smarty->assign("apply", apply_filter());
66       $smarty->assign("alphabet", generate_alphabet());
67       $smarty->assign("search_image", get_template_path('images/search.png'));
68       $smarty->assign("tree_image", get_template_path('images/tree.png'));
69       $smarty->assign("infoimage", get_template_path('images/info.png'));
70       $smarty->assign("launchimage", get_template_path('images/launch.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     $message= array();
109     if(!$this->use_existing){
110       if((empty($this->HOT_name))||(preg_match("/[^a-z0-9 ]/i",$this->HOT_name))){
111         $message[]=_("Please specify a valid name. Only 0-9 a-Z is allowed.");
112       }
113       if((empty($this->HOT_description))||(preg_match("/[^a-z0-9!\"?.,;:-_\(\) ]/i",$this->HOT_description))){
114         $message[]=_("Invalid character in description. Please specify a valid description.");
115       }
116       if((empty($this->HOT_id))||(preg_match("/[\|]/i",$this->HOT_id))){
117         $message[]=_("Please specify a valid id.");
118       }
120     $ldap = $this->config->get_ldap_link();
121     $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->HOT_name."*))");
122     if($ldap->count()){
123       $message[]=_("An Entry with this name already exists.");
124     }
126     }else{
127       if((!isset($_POST['hotplugName']))||(empty($_POST['hotplugName']))){
128         $message[] = _("Please select an entry or press cancel.");
129       }
130     }
132     return ($message);
133   }
136   /* Save to LDAP */
137   function save()
138   {
139     /* return generated entry from input fields*/
140     if(!$this->use_existing){
141       $a_return=array();
142       $a_return['name']= $this->HOT_name; 
143       $a_return['description']= $this->HOT_description; 
144       $a_return['id']= $this->HOT_id;
145       return($a_return); 
146     }else{
147       //return selected entry from select box
148       $entry = $this->hotplugDeviceList[$_POST['hotplugName']];
149       return $entry;
150     }
151   }
153   function getHotplugs(){
154     $ldap= $this->config->get_ldap_link();
155     $ldap->cd($this->depselect);
157     $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->regex."))",array("gotoHotplugDevice")); 
159     $a_return = array();  
160     $this->hotplugDeviceList = array();
161     while($attr = $ldap->fetch()){
162       if(isset($attr['gotoHotplugDevice'])){
163         unset($attr['gotoHotplugDevice']['count']);
164         foreach($attr['gotoHotplugDevice'] as $device){
165           $tmp =$tmp2= array();
166           $tmp = split("\|",$device);
167           
168           if(preg_match("/^".str_replace("*","",$this->regex).".*/i",$tmp[0])){
169             $a_return[$tmp[0]]= $tmp[0]." [".$tmp[1]."] ".$tmp[2];
170             
171             $tmp2['name']         = $tmp[0];
172             $tmp2['description'] = $tmp[1];
173             $tmp2['id']           = $tmp[2];
175             $this->hotplugDeviceList[$tmp[0]]=$tmp2;
176           }
177         }
178       }
179     }
180   return($a_return);
181   }
185 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
186 ?>