Code

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