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 = "/";
29 function hotplugDialog ($config, $dn= NULL,$use_existing=false )
30 {
31 $this->use_existing = $use_existing;
32 plugin::plugin ($config, $dn);
33 $this->depselect = $this->config->current['BASE'];
34 }
36 function execute()
37 {
38 /* Call parent execute */
39 plugin::execute();
41 /* Fill templating stuff */
42 $smarty= get_smarty();
43 $display= "";
45 foreach($this->attributes as $s_attr){
46 $smarty->assign($s_attr,$this->$s_attr);
47 }
49 if($this->use_existing){
51 if(isset($_POST['dialogissubmitted'])){
52 $this->regex=$_POST['regexHot'];
53 $this->depselect = $_POST['depselectHot'];
54 }
56 if((isset($_GET['search']))&&(!empty($_GET['search']))){
57 $this->regex=$_GET['search']."*";
58 $this->regex=preg_replace("/\*\*/","*",$this->regex);
59 }
61 $this->deplist=$this->config->idepartments;
63 $this->hotplugDevices = $this->getHotplugs();
64 $smarty->assign("regexHot" ,$this->regex);
65 $smarty->assign("deplistHot" ,$this->deplist);
66 $smarty->assign("depselectHot",$this->depselect);
67 $smarty->assign("apply", apply_filter());
68 $smarty->assign("alphabet", generate_alphabet());
69 $smarty->assign("search_image", get_template_path('images/search.png'));
70 $smarty->assign("tree_image", get_template_path('images/tree.png'));
71 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
72 $smarty->assign("deplist", $this->config->idepartments);
75 $smarty->assign("hotplugDevices",$this->hotplugDevices);
76 $smarty->assign("hotplugDeviceKeys",array_flip($this->hotplugDevices));
77 $display.= $smarty->fetch(get_template_path('hotplugDialog.tpl', TRUE,dirname(__FILE__)));
78 }else{
79 $display.= $smarty->fetch(get_template_path('hotplugDialogNew.tpl', TRUE,dirname(__FILE__)));
80 }
81 return($display);
82 }
84 function remove_from_parent()
85 {
86 /* This cannot be removed... */
87 }
90 /* Save data to object */
91 function save_object()
92 {
93 if(isset($_POST['dialogissubmitted'])){
94 foreach($this->attributes as $s_attr){
95 if(isset($_POST[$s_attr])){
96 $this->$s_attr = $_POST[$s_attr];
97 }else{
98 $this->$s_attr = false;
99 }
100 }
101 plugin::save_object();
102 }
103 }
106 /* Check supplied data */
107 function check()
108 {
109 /* Call common method to give check the hook */
110 $message= plugin::check();
112 if(!$this->use_existing){
113 if((empty($this->HOT_name))||(preg_match("/[^a-z0-9]/i",$this->HOT_name))){
114 $message[]=_("Please specify a valid name. Only 0-9 a-Z is allowed.");
115 }
116 if((empty($this->HOT_description))||(preg_match("/[^a-z0-9!\"?.,;:-_\(\) ]/i",$this->HOT_description))){
117 $message[]=_("Invalid character in description. Please specify a valid description.");
118 }
119 if((empty($this->HOT_id))||(preg_match("/[\|]/i",$this->HOT_id))){
120 $message[]=_("Please specify a valid id.");
121 }
122 if((empty($this->HOT_vendor))||(preg_match("/[\|]/i",$this->HOT_vendor))){
123 $message[]=_("Please specify a valid id.");
124 }
125 if((empty($this->HOT_produkt))||(preg_match("/[\|]/i",$this->HOT_produkt))){
126 $message[]=_("Please specify a valid id.");
127 }
129 $ldap = $this->config->get_ldap_link();
130 $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->HOT_name."*))",array("gotoHotplugDevice"));
131 if($ldap->count()){
132 $message[]=_("An Entry with this name already exists.");
133 }
135 }else{
136 if((!isset($_POST['hotplugName']))||(empty($_POST['hotplugName']))){
137 $message[] = _("Please select an entry or press cancel.");
138 }
139 }
141 return ($message);
142 }
145 /* Save to LDAP */
146 function save()
147 {
148 /* return generated entry from input fields*/
149 if(!$this->use_existing){
150 $a_return=array();
151 $a_return[$this->HOT_name]['name'] = $this->HOT_name;
152 $a_return[$this->HOT_name]['description'] = $this->HOT_description;
153 $a_return[$this->HOT_name]['id'] = $this->HOT_id;
154 $a_return[$this->HOT_name]['produkt'] = $this->HOT_produkt;
155 $a_return[$this->HOT_name]['vendor'] = $this->HOT_vendor;
156 return($a_return);
157 }else{
158 $entries = array();
159 foreach($_POST['hotplugName'] as $name){
160 $entries[$name] = $this->hotplugDeviceList[$name];
161 }
162 return $entries;
163 }
164 }
166 function getHotplugs(){
167 $ldap= $this->config->get_ldap_link();
168 $ldap->cd($this->depselect);
170 $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->regex."))",array("gotoHotplugDevice"));
172 $a_return = array();
173 $this->hotplugDeviceList = array();
174 while($attr = $ldap->fetch()){
175 if(isset($attr['gotoHotplugDevice'])){
176 unset($attr['gotoHotplugDevice']['count']);
177 foreach($attr['gotoHotplugDevice'] as $device){
178 $tmp =$tmp2= array();
179 $tmp = split("\|",$device);
181 if(preg_match("/^".str_replace("*","",$this->regex).".*/i",$tmp[0])){
182 $a_return[$tmp[0]]= $tmp[0]." [".$tmp[1]."] ".$tmp[2];
184 $tmp2['name'] = $tmp[0];
185 $tmp2['description'] = $tmp[1];
186 $tmp2['id'] = $tmp[2];
188 /* Produkt ID */
189 if(!isset($tmp[3])){
190 $tmp[3] = "";
191 }
192 /* Vendor ID */
193 if(!isset($tmp[4])){
194 $tmp[4] = "";
195 }
197 $tmp2['produkt'] = $tmp[3];
198 $tmp2['vendor'] = $tmp[4];
200 $this->hotplugDeviceList[$tmp[0]]=$tmp2;
201 }
202 }
203 }
204 }
205 return($a_return);
206 }
208 }
210 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
211 ?>