bf243fffd9f74cab7fd526c062b6d3ef988292c9
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.");
110 }
111 if((empty($this->HOT_description))||(preg_match("/[^a-z0-9!\"?.,;:-_\(\) ]/i",$this->HOT_description))){
112 $message[]=_("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 }
117 }else{
118 if((!isset($_POST['hotplugName']))||(empty($_POST['hotplugName']))){
119 $message[] = _("Please select an entry or press cancel.");
120 }
121 }
123 return ($message);
124 }
127 /* Save to LDAP */
128 function save()
129 {
130 /* return generated entry from input fields*/
131 if(!$this->use_existing){
132 $a_return=array();
133 $a_return['name']= $this->HOT_name;
134 $a_return['description']= $this->HOT_description;
135 $a_return['id']= $this->HOT_id;
136 return($a_return);
137 }else{
138 //return selected entry from select box
139 $entry = $this->hotplugDeviceList[$_POST['hotplugName']];
140 return $entry;
141 }
142 }
144 function getHotplugs(){
145 $ldap= $this->config->get_ldap_link();
146 $ldap->cd($this->depselect);
148 $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->regex."))",array("gotoHotplugDevice"));
150 $a_return = array();
151 $this->hotplugDeviceList = array();
152 while($attr = $ldap->fetch()){
153 if(isset($attr['gotoHotplugDevice'])){
154 unset($attr['gotoHotplugDevice']['count']);
155 foreach($attr['gotoHotplugDevice'] as $device){
156 $tmp =$tmp2= array();
157 $tmp = split("\|",$device);
159 if(preg_match("/^".str_replace("*","",$this->regex).".*/i",$tmp[0])){
160 $a_return[$tmp[0]]= $tmp[0]." [".$tmp[1]."] ".$tmp[2];
162 $tmp2['name'] = $tmp[0];
163 $tmp2['description'] = $tmp[1];
164 $tmp2['id'] = $tmp[2];
166 $this->hotplugDeviceList[$tmp[0]]=$tmp2;
167 }
168 }
169 }
170 }
171 return($a_return);
172 }
174 }
176 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
177 ?>