fee4b846ec1583d512819c29d662e62c141492fe
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 }
34 function execute()
35 {
36 /* Fill templating stuff */
37 $smarty= get_smarty();
38 $display= "";
40 foreach($this->attributes as $s_attr){
41 $smarty->assign($s_attr,$this->$s_attr);
42 }
44 if($this->use_existing){
46 if(isset($_POST['dialogissubmitted'])){
47 $this->regex=$_POST['regexHot'];
48 $this->depselect = $_POST['depselectHot'];
49 }
51 if((isset($_GET['search']))&&(!empty($_GET['search']))){
52 $this->regex=$_GET['search']."*";
53 $this->regex=preg_replace("/\*\*/","*",$this->regex);
54 }
56 $this->deplist=array_flip($this->config->departments);
58 $this->hotplugDevices = $this->getHotplugs();
59 $smarty->assign("regexHot" ,$this->regex);
60 $smarty->assign("deplistHot" ,$this->deplist);
61 $smarty->assign("depselectHot",$this->depselect);
62 $smarty->assign("apply", apply_filter());
63 $smarty->assign("alphabet", generate_alphabet());
64 $smarty->assign("search_image", get_template_path('images/search.png'));
65 $smarty->assign("tree_image", get_template_path('images/tree.png'));
66 $smarty->assign("infoimage", get_template_path('images/info.png'));
67 $smarty->assign("launchimage", get_template_path('images/launch.png'));
68 $smarty->assign("deplist", $this->config->idepartments);
71 $smarty->assign("hotplugDevices",$this->hotplugDevices);
72 $smarty->assign("hotplugDeviceKeys",array_flip($this->hotplugDevices));
73 $display.= $smarty->fetch(get_template_path('hotplugDialog.tpl', TRUE,dirname(__FILE__)));
74 }else{
75 $display.= $smarty->fetch(get_template_path('hotplugDialogNew.tpl', TRUE,dirname(__FILE__)));
76 }
77 return($display);
78 }
80 function remove_from_parent()
81 {
82 /* This cannot be removed... */
83 }
86 /* Save data to object */
87 function save_object()
88 {
89 if(isset($_POST['dialogissubmitted'])){
90 foreach($this->attributes as $s_attr){
91 if(isset($_POST[$s_attr])){
92 $this->$s_attr = $_POST[$s_attr];
93 }else{
94 $this->$s_attr = false;
95 }
96 }
97 plugin::save_object();
98 }
99 }
102 /* Check supplied data */
103 function check()
104 {
105 $message= array();
106 if(!$this->use_existing){
107 if((empty($this->HOT_name))||(preg_match("/[^a-z0-9]/i",$this->HOT_name))){
108 $message[]=_("Please specify a valid name.");
109 }
110 if((empty($this->HOT_description))||(preg_match("/[^a-z0-9!\"?.,;:-_\(\) ]/i",$this->HOT_description))){
111 $message[]=_("Please specify a valid description.");
112 }
113 if((empty($this->HOT_id))){
114 $message[]=_("Please specify a valid id.");
115 }
116 }else{
117 if((!isset($_POST['hotplugName']))||(empty($_POST['hotplugName']))){
118 $message[] = _("Please select an entry or press cancel.");
119 }
120 }
122 return ($message);
123 }
126 /* Save to LDAP */
127 function save()
128 {
129 /* return generated entry from input fields*/
130 if(!$this->use_existing){
131 $a_return=array();
132 $a_return['name']= $this->HOT_name;
133 $a_return['description']= $this->HOT_description;
134 $a_return['id']= $this->HOT_id;
135 return($a_return);
136 }else{
137 //return selected entry from select box
138 $entry = $this->hotplugDeviceList[$_POST['hotplugName']];
139 return $entry;
140 }
141 }
143 function getHotplugs(){
144 $ldap= $this->config->get_ldap_link();
145 $ldap->cd($this->depselect);
147 $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->regex."))",array("gotoHotplugDevice"));
149 $a_return = array();
150 $this->hotplugDeviceList = array();
151 while($attr = $ldap->fetch()){
152 if(isset($attr['gotoHotplugDevice'])){
153 unset($attr['gotoHotplugDevice']['count']);
154 foreach($attr['gotoHotplugDevice'] as $device){
155 $tmp =$tmp2= array();
156 $tmp = split("\|",$device);
158 if(preg_match("/^".str_replace("*","",$this->regex).".*/i",$tmp[0])){
159 $a_return[$tmp[0]]= $tmp[0]." [".$tmp[1]."] ".$tmp[2];
161 $tmp2['name'] = $tmp[0];
162 $tmp2['description'] = $tmp[1];
163 $tmp2['id'] = $tmp[2];
165 $this->hotplugDeviceList[$tmp[0]]=$tmp2;
166 }
167 }
168 }
169 }
170 return($a_return);
171 }
173 }
175 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
176 ?>