246dd91e0f74973d5e9754d1704a32af96320c43
1 <?php
3 class goto_task extends plugin
4 {
5 /* Definitions */
6 var $plHeadline = "System mass deployment";
7 var $plDescription = "This does something";
9 var $parent = NULL;
10 var $Expert = FALSE;
12 var $Minute = "*";
13 var $Hour = "*";
14 var $Day = "*";
15 var $Month = "*";
16 var $Weekday = "*";
17 var $Action = "install";
18 var $Comment = "";
19 var $Target = array();
21 var $Actions = array();
22 var $OGroup = "";
23 var $OGroups = array();
24 var $attributes = array("OGroup","Minute","Hour","Day","Month","Weekday","Action","Comment","Target");
27 function goto_task($config,$parent,$data = array())
28 {
29 /* Set parent object */
30 $this->parent = $parent;
32 /* Intialize plugin */
33 $this->config = $config;
34 if(count($data)){
36 $tmp = $this->get_array_values();
37 foreach($this->attributes as $attr){
38 if(!isset($data[$attr])){
39 trigger_error("Missing parameter: '".$attr."' for goto_task contruction.");
40 }else{
41 $this->$attr = $data[$attr];
43 /* Check if given value will be selectable via dropdown menus, else enable expert mode */
44 if(in_array($attr, array("Minute","Hour","Day","Month","Weekday")) && !isset($tmp[$attr][$data[$attr]])){
45 $this->Expert = TRUE;
46 }
47 }
48 }
49 }
51 /* Create ogroup select list */
52 $this->OGroups = array("keep_current" => "["._("Keep current")."]",
53 "unset_membership" => "["._("Quit group membership")."]");
54 $this->OGroups = array_merge($this->OGroups,$this->parent->get_object_groups());
56 /* Prepare list of available actions */
57 $this->Actions = $this->parent->get_actions();
58 }
61 function execute()
62 {
63 /********
64 * Handle Posts
65 ********/
67 /* Handle Target options */
68 foreach($_POST as $name => $value){
69 if(preg_match("/^remove_/",$name)){
70 $value = preg_replace("/^remove_([0-9]*)_(x|y)$/i","\\1",$name);
71 if(isset($this->Target[$value])){
72 unset($this->Target[$value]);
73 }
74 }
75 }
77 /* Add target */
78 if(isset($_POST['add_target']) && !empty($_POST['target_text'])){
79 $target = get_post("target_text");
80 if($this->is_valid_target($target) && !in_array($target,$this->Target)){
81 $this->Target[] = $target;
82 }
83 }
86 /********
87 * Add target from list
88 ********/
90 /* If add from list is was requsted, display this list */
91 if(isset($_POST['add_from_list'])){
92 $this->dialog = new target_list($this->config,$this->Target);
93 }
95 /* Save selected objects as target */
96 if(isset($_POST['SaveMultiSelectWindow'])){
97 $this->dialog->save_object();
98 $ret = $this->dialog->save();
99 foreach($ret as $entry){
100 $this->Target[] = $entry['cn'][0];
101 }
102 $this->dialog = NULL;
103 }
105 /* Cancel object listing */
106 if(isset($_POST['CloseMultiSelectWindow'])){
107 $this->dialog = NULL;
108 }
110 /* Display object Listing */
111 if($this->dialog){
112 $this->dialog->save_object();
113 return($this->dialog->execute());
114 }
117 /********
118 * Display this plugin
119 ********/
121 $divlist = new divlist("goto_task");
122 $divlist->SetWidth("100%");
123 $divlist->SetHeight("160");
124 $divlist->SetEntriesPerPage(0);
126 $divlist->SetHeader(array(
127 array("string" => "Target"),
128 array("string" => "Actions" , "attach" => "style='width:40px;'")));
130 $acl_target = $this->parent->getacl("Target");
131 foreach($this->Target as $key => $target){
133 $field1 = array("string" => $target);
134 if(preg_match("/w/i",$acl_target)){
135 $field2 = array("string" => "<input type='image' src='images/edittrash.png' name='remove_".$key."'>" ,
136 "attach" => "style='width:44px;'");
137 }else{
138 $field2 = array("string" => "",
139 "attach" => "style='width:44px;'");
140 }
142 $divlist->AddEntry(array($field1,$field2));
143 }
145 $smarty = get_smarty();
147 foreach($this->attributes as $attr){
148 $smarty->assign($attr."ACL", $this->parent->getacl($attr));
149 $smarty->assign($attr,$this->$attr);
150 }
152 $tmp = $this->get_array_values();
153 $smarty->assign("Minutes" , $tmp['Minute']);
154 $smarty->assign("Hours" , $tmp['Hour']);
155 $smarty->assign("Days" , $tmp['Day']);
156 $smarty->assign("Months" , $tmp['Month']);
157 $smarty->assign("Weekdays", $tmp['Weekday']);
159 $smarty->assign("OGroups" , $this->OGroups);
160 $smarty->assign("Expert" , $this->Expert);
162 $smarty->assign("Actions" , $this->Actions);
163 $smarty->assign("Target_list" , $divlist->DrawList());
164 return ($smarty->fetch (get_template_path('goto_task.tpl', TRUE)));
165 }
168 /* Map acl function, to be able to use plugin::save_object() */
169 function acl_is_writeable($str)
170 {
171 return($this->parent->acl_is_writeable($str));
172 }
175 function save_object()
176 {
177 if(isset($_POST['goto_task_posted'])){
178 plugin::save_object();
180 if(isset($_POST['ToggleExpertMode'])){
181 $this->Expert = !$this->Expert;
182 }
183 }
184 }
187 /* Check if given target is vald.
188 * It must either be a valid MAC address or an existing object group
189 */
190 function is_valid_target($str)
191 {
192 if(is_mac($str)){
193 return(TRUE);
194 }else{
195 $ldap = $this->config->get_ldap_link();
196 $ldap->cd($this->config->current['BASE']);
197 $ldap->search("(&(objectClassgosaGroupOfNames)(cn=".$str."))",array("cn"));
198 if($ldap->count()){
199 return(TRUE);
200 }
201 }
202 }
204 function save()
205 {
206 $tmp = array();
207 foreach($this->attributes as $attr){
208 $tmp[$attr] = $this->$attr;
209 }
210 return($tmp);
211 }
214 /* Return values for listboxes.
215 */
216 function get_array_values()
217 {
218 $ret = array();
220 /* Create minute array */
221 $Minute = array( "*" => "*",
222 "*/1" => "*/1",
223 "*/3" => "*/3",
224 "*/5" => "*/5",
225 "*/10" => "*/10",
226 "*/15" => "*/15",
227 "*/30" => "*/30",
228 "*/45" => "*/45",
229 "*/60" => "*/60");
230 for($i = 0; $i < 60 ; $i ++){
231 $Minute[$i] = $i;
232 }
234 /* Create hour array */
235 $Hour = array( "*" => "*");
236 for($i = 1 ; $i < 24 ; $i ++ ){
237 $Hour["*/".$i] = "*/".$i;
238 }
239 for($i = 0 ; $i < 24 ; $i ++ ){
240 $Hour[$i] = $i;
241 }
243 /* Create hour array */
244 $Day = array( "*" => "*");
245 for($i = 1 ; $i < 32 ; $i ++ ){
246 $Day["*/".$i] = "*/".$i;
247 }
248 for($i = 1 ; $i < 32 ; $i ++ ){
249 $Day[$i] = $i;
250 }
252 /* Create month array */
253 $Month = array( "*" => "*");
254 for($i = 1 ; $i <= 12 ; $i ++ ){
255 $Month["*/".$i] = "*/".$i;
256 }
257 for($i = 1 ; $i <= 12 ; $i ++ ){
258 $Month[$i] = $i;
259 }
261 /* Create week day array */
262 $Weekday = array( "*" => "*");
263 for($i = 1 ; $i <= 7 ; $i ++ ){
264 $Weekday["*/".$i] = "*/".$i;
265 }
266 for($i = 0 ; $i <= 7 ; $i ++ ){
267 $Weekday[$i] = $i;
268 }
270 foreach(array("Minute","Weekday","Hour","Day","Month") as $var){
271 $ret[$var] = $$var;
272 }
273 return($ret);
274 }
275 }
276 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
277 ?>