1 <?php
3 class gotomasses extends plugin
4 {
5 /* Definitions */
6 var $plHeadline = "System deployment";
7 var $plDescription = "This does something";
9 /* attribute list for save action */
10 var $attributes= array();
11 var $objectclasses= array();
13 /* Queue tasks */
14 var $current = FALSE;
15 var $dialog = FALSE;
16 var $ids_to_remove = array();
17 var $divlist = NULL;
19 var $sort_by = "QueuePosition";
20 var $sort_dir = "up";
22 function gotomasses(&$config, $dn= NULL)
23 {
24 /* Include config object */
25 $this->config= &$config;
26 $this->divlist = new divListMasses($this->config,$this);
27 $this->o_queue = new gosaSupportDaemon("10.3.67.111","20082","secret-gosa-password",FALSE,2);
28 }
31 function execute()
32 {
33 $smarty = get_smarty();
35 /************
36 * Handle posts
37 ************/
39 $s_entry = $s_action = "";
40 $arr = array(
41 "/^prio_top_/" => "prio_top",
42 "/^prio_increase_/" => "prio_increase",
43 "/^prio_decrease_/" => "prio_decrease",
44 "/^prio_bottom_/" => "prio_bottom",
46 "/^multiple_prio_top_/" => "mprio_top",
47 "/^multiple_prio_increase_/" => "mprio_increase",
48 "/^multiple_prio_decrease_/" => "mprio_decrease",
49 "/^multiple_prio_bottom_/" => "mprio_bottom",
51 "/^edit_task_/" => "edit",
52 "/^remove_task_/" => "remove",
53 "/^new_task_/" => "new_task",
54 "/^remove_multiple_task_/" => "remove_multiple");
56 foreach($arr as $regex => $action){
57 foreach($_POST as $name => $value){
58 if(preg_match($regex,$name)){
59 $s_action = $action;
60 $s_entry = preg_replace($regex,"",$name);
61 $s_entry = preg_replace("/_(x|y)$/","",$s_entry);
62 }
63 }
64 }
66 /* Edit posted from list link */
67 if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id']) && isset($this->tasks[$_GET['id']])){
68 $s_action = "edit";
69 $s_entry = $_GET['id'];
70 }
72 /************
73 * REMOVE
74 ************/
76 if(preg_match("/^mprio_/",$s_action) || preg_match("/^prio_/",$s_action)){
78 switch($s_action){
79 case 'mprio_top' : foreach($this->list_get_selected_items() as $id ){
80 $this->o_queue->max_entry_priority($id);
81 }
82 break;
83 case 'mprio_increase' : foreach($this->list_get_selected_items() as $id ){
84 $this->o_queue->increase_entry_priority($id);
85 }
86 break;
87 case 'mprio_decrease' : foreach($this->list_get_selected_items() as $id ){
88 $this->o_queue->decrease_entry_priority($id);
89 }
90 break;
91 case 'mprio_bottom' : foreach($this->list_get_selected_items() as $id ){
92 $this->o_queue->min_entry_priority($id);
93 }
94 break;
95 case 'prio_top' : $this->o_queue->max_entry_priority($s_entry);break;
96 case 'prio_increase' : $this->o_queue->increase_entry_priority($s_entry);break;
97 case 'prio_decrease' : $this->o_queue->decrease_entry_priority($s_entry);break;
98 case 'prio_bottom' : $this->o_queue->min_entry_priority($s_entry);break;
99 default : trigger_error("Undefined priority setting used.");
100 }
101 if($this->o_queue->is_error()){
102 print_red($this->o_queue->get_error());
103 }
104 }
106 /************
107 * REMOVE
108 ************/
110 /* Remove multiple */
111 if($s_action == "remove_multiple" || $s_action == "remove"){
113 if(!$this->acl_is_removeable()){
114 print_red(_("You are not allowed to remove a task."));
115 }else{
117 if($s_action == "remove"){
118 $ids = array($s_entry);
119 }else{
120 $ids = $this->list_get_selected_items();
121 }
124 $this->ids_to_remove = $ids;
125 $tmp = "";
126 foreach($this->ids_to_remove as $key => $id){
127 if($this->o_queue->id_exists($id)){
128 $task = $this->o_queue->get_entry($id);
129 $tmp.= "\n".$task['ROWID'];
130 }else{
131 unset($this->ids_to_remove[$key]);
132 }
133 }
134 $smarty->assign("multiple", TRUE);
135 $smarty->assign("info",sprintf(_("Your are about to delete the following tasks: %s"),"<pre>".$tmp."</pre>"));
136 $this->current = $s_entry;
137 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
138 }
139 }
141 /* Remove specified tasks */
142 if(count($this->ids_to_remove) && isset($_POST['delete_multiple_confirm'])){
143 foreach($this->ids_to_remove as $id){
144 if($this->o_queue->id_exists($id)){
145 $this->o_queue->remove_entry($id);
146 }
147 }
148 $this->save();
149 }
151 /* Remove aborted */
152 if(isset($_POST['delete_cancel'])){
153 $this->ids_to_remove = array();;
154 }
157 # /************
158 # * EDIT
159 # ************/
160 #
161 # /* Edit selected entry */
162 # if($s_action == "edit"){
163 # $entry = $this->o_queue->get_entry($s_entry);
164 # if($entry){
165 # $this->dialog = new goto_task($this->config,$this,$entry);
166 # $this->current = $s_entry;
167 # }
168 # }
169 #
170 # /* New entry */
171 # if($s_action== "new_task" && $this->acl_is_createable()){
172 # $this->dialog = new goto_task($this->config,$this);
173 # $this->current = -1;
174 # }
175 #
176 # /* Close dialog */
177 # if(isset($_POST['close_goto_task'])){
178 # $this->dialog = FALSE;
179 # $this->current = -1;
180 # }
181 #
182 # /* Close dialog */
183 # if((isset($_POST['save_goto_task']) || isset($_POST['apply_goto_task'])) && is_object($this->dialog) ){
184 # $this->dialog->save_object();
185 # $msgs = $this->dialog->check();
186 # if(count($msgs)){
187 # foreach($msgs as $msg){
188 # print_red($msg);
189 # }
190 # }else{
191 #
192 # if($this->o_queue->id_exists($this->current)){
193 # $this->o_queue->update_entry($this->current,$this->dialog->save());
194 # }else{
195 # $tmp = $this->dialog->save();
196 # $tmp2= array();
197 # $targets =$tmp['Target'];
198 # foreach($targets as $target){
199 # $tmp['Target'] = array($target);
200 # $tmp2[] = $tmp;
201 # }
202 # if(!$this->o_queue->add_multiple($tmp2)){
203 # print_red($this->o_queue->get_error());
204 # }
205 # }
206 # if(!isset($_POST['apply_goto_task'])){
207 # $this->dialog = FALSE;
208 # $this->current = -1;
209 # }
210 # $this->save();
211 # }
212 # }
213 #
214 # /* Display dialogs if currently opened */
215 # if(is_object($this->dialog)){
216 # $this->dialog->save_object();
217 # return($this->dialog->execute());
218 # }
220 /************
221 * Handle Divlist
222 ************/
224 $this->divlist->execute();
225 $this->divlist->SetEntries($this->get_queue_entries());
226 return($this->divlist->Draw());
227 }
230 /*! \brief Request list of queued jobs.
231 * @return Returns an array of all queued jobs.
232 */
233 function get_queue_entries()
234 {
235 if(!$this->o_queue->load()){
236 print_red(sprintf(_("An error occurred while requesting queue entries. Error was '%s'."),$this->o_queue->get_error()));
237 return(array());
238 }
239 $tasks = array();
240 $ret = array();
241 while($entry = $this->o_queue->fetch()){
242 $task = $entry['ROWID'];
243 $entry['Queue_Position'] = $task;
244 $ret[]= $entry;
245 }
246 return($ret);
247 }
250 /*! \brief Handle post jobs, like sorting.
251 */
252 function save_object()
253 {
254 $this->divlist->save_object();
255 $sort_vals = array("Action","QueuePosition","TargetName","Schedule","TaskID");
256 if(isset($_GET['sort']) && in_array($_GET['sort'],$sort_vals)){
257 $sort = $_GET['sort'];
258 if($this->sort_by == $sort){
259 if($this->sort_dir == "up"){
260 $this->sort_dir = "down";
261 }else{
262 $this->sort_dir = "up";
263 }
264 }
265 $this->sort_by = $sort;
266 }
267 }
270 /* Return list of object groups */
271 function get_object_groups()
272 {
273 $ret = array();
274 $ldap = $this->config->get_ldap_link();
275 $ldap->cd($this->config->current['BASE']);
276 $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("cn"));
277 while($attrs = $ldap->fetch()){
278 $ret[$attrs['cn'][0]] = $attrs['cn'][0];
279 }
280 return($ret);
281 }
284 function save()
285 {
286 // We do not save anything here.
287 }
290 /*! \brief Return a list of all selected items.
291 @return Array Returns an array containing all selected item ids.
292 */
293 function list_get_selected_items()
294 {
295 $ids = array();
296 foreach($_POST as $name => $value){
297 if(preg_match("/^item_selected_[0-9]*$/",$name)){
298 $id = preg_replace("/^item_selected_/","",$name);
299 $ids[$id] = $id;
300 }
301 }
302 return($ids);
303 }
306 function get_actions()
307 {
308 /* Prepare list of available actions */
309 $actions = array(
310 "Dummy." => "!!!!!!!! Update",
311 "reboot" => _("Reboot"),
312 "localboot" => _("Localboot"),
313 "halt" => _("Halt system"),
314 "initial_install" => _("Initial installation"),
315 "update" => _("Update"),
316 "reinstall" => _("(Re)Install"),
317 "rescan" => _("Rescan"),
318 "wake" => _("Wake"),
319 "memcheck" => _("Memory check"));
320 return($actions);
321 }
324 static function plInfo()
325 {
326 return (array(
327 "plShortName" => _("System mass deployment"),
328 "plDescription" => _("Provide a mechanism to automatically activate a set of systems"),
329 "plSelfModify" => FALSE,
330 "plDepends" => array(),
331 "plPriority" => 0,
332 "plSection" => array("addon"),
333 "plCategory" => array("gotomasses" => array("objectClass" => "none", "description" => _("System mass deployment"))),
334 "plProvidedAcls" => array("Comment" => _("Description"),
335 "Action" => _("Action"),
336 "Day" => _("Day"),
337 "Minute" => _("Minute"),
338 "Hour" => _("Hour"),
339 "Month" => _("Month"),
340 "Weekday" => _("Week day"),
341 "Target" => _("Target"))
342 ));
343 }
344 }
345 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
346 ?>