d5ecf2742b26da1163a54aeb0e0d311a51f5e521
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 /* Fill templating stuff */
38 $smarty= get_smarty();
39 $display= "";
41 foreach($this->attributes as $s_attr){
42 $smarty->assign($s_attr,$this->$s_attr);
43 }
45 if($this->use_existing){
47 if(isset($_POST['dialogissubmitted'])){
48 $this->regex=$_POST['regexHot'];
49 $this->depselect = $_POST['depselectHot'];
50 }
52 if((isset($_GET['search']))&&(!empty($_GET['search']))){
53 $this->regex=$_GET['search']."*";
54 $this->regex=preg_replace("/\*\*/","*",$this->regex);
55 }
57 $this->deplist=array_flip($this->config->departments);
59 $this->hotplugDevices = $this->getHotplugs();
60 $smarty->assign("regexHot" ,$this->regex);
61 $smarty->assign("deplistHot" ,$this->deplist);
62 $smarty->assign("depselectHot",$this->depselect);
63 $smarty->assign("apply", apply_filter());
64 $smarty->assign("alphabet", generate_alphabet());
65 $smarty->assign("search_image", get_template_path('images/search.png'));
66 $smarty->assign("tree_image", get_template_path('images/tree.png'));
67 $smarty->assign("infoimage", get_template_path('images/info.png'));
68 $smarty->assign("launchimage", get_template_path('images/launch.png'));
69 $smarty->assign("deplist", $this->config->idepartments);
72 $smarty->assign("hotplugDevices",$this->hotplugDevices);
73 $smarty->assign("hotplugDeviceKeys",array_flip($this->hotplugDevices));
74 $display.= $smarty->fetch(get_template_path('hotplugDialog.tpl', TRUE,dirname(__FILE__)));
75 }else{
76 $display.= $smarty->fetch(get_template_path('hotplugDialogNew.tpl', TRUE,dirname(__FILE__)));
77 }
78 return($display);
79 }
81 function remove_from_parent()
82 {
83 /* This cannot be removed... */
84 }
87 /* Save data to object */
88 function save_object()
89 {
90 if(isset($_POST['dialogissubmitted'])){
91 foreach($this->attributes as $s_attr){
92 if(isset($_POST[$s_attr])){
93 $this->$s_attr = $_POST[$s_attr];
94 }else{
95 $this->$s_attr = false;
96 }
97 }
98 plugin::save_object();
99 }
100 }
103 /* Check supplied data */
104 function check()
105 {
106 $message= array();
107 if(!$this->use_existing){
108 if((empty($this->HOT_name))||(preg_match("/[^a-z0-9 ]/i",$this->HOT_name))){
109 $message[]=_("Please specify a valid name. Only 0-9 a-Z is allowed.");
110 }
111 if((empty($this->HOT_description))||(preg_match("/[^a-z0-9!\"?.,;:-_\(\) ]/i",$this->HOT_description))){
112 $message[]=_("Invalid character in description. Please specify a valid description.");
113 }
114 if((empty($this->HOT_id))||(preg_match("/[\|]/i",$this->HOT_id))){
115 $message[]=_("Please specify a valid id.");
116 }
118 $ldap = $this->config->get_ldap_link();
119 $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->HOT_name."*))");
120 if($ldap->count()){
121 $message[]=_("An Entry with this name already exists.");
122 }
124 }else{
125 if((!isset($_POST['hotplugName']))||(empty($_POST['hotplugName']))){
126 $message[] = _("Please select an entry or press cancel.");
127 }
128 }
130 return ($message);
131 }
134 /* Save to LDAP */
135 function save()
136 {
137 /* return generated entry from input fields*/
138 if(!$this->use_existing){
139 $a_return=array();
140 $a_return['name']= $this->HOT_name;
141 $a_return['description']= $this->HOT_description;
142 $a_return['id']= $this->HOT_id;
143 return($a_return);
144 }else{
145 //return selected entry from select box
146 $entry = $this->hotplugDeviceList[$_POST['hotplugName']];
147 return $entry;
148 }
149 }
151 function getHotplugs(){
152 $ldap= $this->config->get_ldap_link();
153 $ldap->cd($this->depselect);
155 $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->regex."))",array("gotoHotplugDevice"));
157 $a_return = array();
158 $this->hotplugDeviceList = array();
159 while($attr = $ldap->fetch()){
160 if(isset($attr['gotoHotplugDevice'])){
161 unset($attr['gotoHotplugDevice']['count']);
162 foreach($attr['gotoHotplugDevice'] as $device){
163 $tmp =$tmp2= array();
164 $tmp = split("\|",$device);
166 if(preg_match("/^".str_replace("*","",$this->regex).".*/i",$tmp[0])){
167 $a_return[$tmp[0]]= $tmp[0]." [".$tmp[1]."] ".$tmp[2];
169 $tmp2['name'] = $tmp[0];
170 $tmp2['description'] = $tmp[1];
171 $tmp2['id'] = $tmp[2];
173 $this->hotplugDeviceList[$tmp[0]]=$tmp2;
174 }
175 }
176 }
177 }
178 return($a_return);
179 }
181 }
183 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
184 ?>