c8ee0da14df776a58b75ee5e2974e5e133214f0a
1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class gotomasses extends plugin
24 {
25 /* Definitions */
26 var $plHeadline = "Deployment status";
27 var $plDescription = "System deployment status";
29 /* attribute list for save action */
30 var $attributes= array();
31 var $objectclasses= array();
33 /* Queue tasks */
34 var $current = FALSE;
35 var $dialog = FALSE;
36 var $ids_to_remove = array();
37 var $divlist = NULL;
39 var $events = array();
40 var $event_tags = array();
42 var $sort_by = "Schedule";
43 var $sort_dir = "down";
44 var $entries = array();
45 var $range = 25;
46 var $start = 0;
48 function gotomasses(&$config, $dn= NULL)
49 {
50 /* Include config object */
51 $this->config= &$config;
52 $this->o_queue = new gosaSupportDaemon(TRUE,5);
53 $this->events = DaemonEvent::get_event_types( SYSTEM_EVENT);
55 /* Get tags that will be used in queue searches */
56 $this->event_tags = array("none");
57 foreach($this->events['SCHEDULED'] as $evt){
58 $this->event_tags[] = $evt['s_Queued_Action'];
59 }
60 }
63 function execute()
64 {
65 $smarty = get_smarty();
67 /************
68 * Handle posts
69 ************/
71 $s_entry = $s_action = "";
72 $arr = array(
74 "/^pause_/" => "pause",
75 "/^resume_/" => "resume",
76 "/^execute_process_/" => "execute_process",
77 "/^abort_process_/" => "abort_process",
79 "/^prio_up_/" => "prio_up",
80 "/^prio_down_/" => "prio_down",
82 "/^edit_task_/" => "edit",
83 "/^remove_task_/" => "remove",
84 "/^new_task_/" => "new_task");;
87 foreach($arr as $regex => $action){
88 foreach($_POST as $name => $value){
89 if(preg_match($regex,$name)){
90 $s_action = $action;
91 $s_entry = preg_replace($regex,"",$name);
92 $s_entry = preg_replace("/_(x|y)$/","",$s_entry);
93 }
94 }
95 }
97 /* Menu actions */
98 if(isset($_POST['menu_action']) && !empty($_POST['menu_action'])){
99 $s_action = $_POST['menu_action'];
100 }
102 /* Edit posted from list link */
103 if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id']) && isset($this->tasks[$_GET['id']])){
104 $s_action = "edit";
105 $s_entry = $_GET['id'];
106 }
109 /************
110 * Handle Priority modifications
111 ************/
113 if(preg_match("/^prio_/",$s_action)){
114 switch($s_action){
115 case 'prio_down' : $this->update_priority($s_entry,"down");break;
116 case 'prio_up' : $this->update_priority($s_entry,"up");break;
117 }
118 }
120 /************
121 * Handle pause/resume/execute modifications
122 ************/
124 if(preg_match("/^resume/",$s_action) ||
125 preg_match("/^pause/",$s_action) ||
126 preg_match("/^abort_process/",$s_action) ||
127 preg_match("/^execute_process/",$s_action)){
129 switch($s_action){
130 case 'resume' : $this->resume_queue_entries (array($s_entry));break;
131 case 'pause' : $this->pause_queue_entries (array($s_entry));break;
132 case 'execute_process': $this->execute_queue_entries (array($s_entry));break;
133 case 'abort_process' : $this->abort_queue_entries (array($s_entry));break;
134 case 'resume_all' : $this->resume_queue_entries ($this->list_get_selected_items());break;
135 case 'pause_all' : $this->pause_queue_entries ($this->list_get_selected_items());break;
136 case 'execute_process_all': $this->execute_queue_entries ($this->list_get_selected_items());break;
137 case 'abort_process_all' : $this->abort_queue_entries ($this->list_get_selected_items());break;
139 default : trigger_error("Undefined action setting used (".$s_action.").");
140 }
141 if($this->o_queue->is_error()){
142 msg_dialog::display(_("Error"), $this->o_queue->get_error(), ERROR_DIALOG);
143 }
144 }
146 /************
147 * ADD
148 ************/
150 if(preg_match("/^add_event_/",$s_action)){
151 $type = preg_replace("/^add_event_/","",$s_action);
152 if(isset($this->events['BY_CLASS'][$type])){
153 $e_data = $this->events['BY_CLASS'][$type];
154 $this->dialog = new $e_data['CLASS_NAME']($this->config);
155 }
156 }
158 /************
159 * EDIT
160 ************/
162 if($s_action == "edit"){
163 $id = $s_entry;
164 $type = FALSE;
165 if(isset($this->entries[$id])){
166 $event = $this->entries[$s_entry];
167 if($event['STATUS'] == "waiting" && isset($this->events['QUEUED'][$event['HEADERTAG']])){
168 $evt_name = $this->events['QUEUED'][$event['HEADERTAG']];
169 $type = $this->events['BY_CLASS'][$evt_name];
170 $this->dialog = new $type['CLASS_NAME']($this->config,$event);
171 }
172 }
173 }
175 /************
176 * REMOVE
177 ************/
179 /* Remove multiple */
180 if($s_action == "remove_multiple" || $s_action == "remove"){
182 if(!$this->acl_is_removeable()){
183 msg_dialog::display(_("Permission"), msgPool::permDelete(), ERROR_DIALOG);
184 }else{
186 if($s_action == "remove"){
187 $ids = array($s_entry);
188 }else{
189 $ids = $this->list_get_selected_items();
190 }
192 $this->ids_to_remove = array();
194 if(count($ids)){
195 $ret = $this->o_queue->ids_exist($ids);
196 $ret = $this->o_queue->get_entries_by_id($ret);
198 $tmp = "";
199 foreach($ret as $task){
201 /* Only remove WAITING or ERROR entries */
202 if(in_array($task['STATUS'],array("waiting","error","processed")) ||
203 ($task['STATUS'] == "processing" && !preg_match("/install/",$task['HEADERTAG'])) ){
204 $this->ids_to_remove[] = $task['ID'];
205 if(isset($this->events['QUEUED'][$task['HEADERTAG']])){
206 $evt_name = $this->events['QUEUED'][$task['HEADERTAG']];
207 $evt = $this->events['BY_CLASS'][$evt_name];
208 $tmp.= "\n".$task['ID']." - ".$evt['s_Menu_Name']." ".$task['MACADDRESS'];
209 }else{
210 $tmp.= "\n".$task['ID']." - ".$task['HEADERTAG']." ".$task['MACADDRESS'];
211 }
212 }
213 }
214 $smarty->assign("multiple", TRUE);
215 $smarty->assign("info",msgPool::deleteInfo("<pre>".$tmp."</pre>"));
216 $this->current = $s_entry;
217 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
218 }
219 }
220 }
222 /* Remove specified tasks */
223 if(count($this->ids_to_remove) && isset($_POST['delete_multiple_confirm'])){
225 /* Reboot hosts with not yet startet installations and timestamps in the past
226 */
227 timezone::get_default_timezone();
228 foreach($this->ids_to_remove as $id){
229 $entry = $this->o_queue->get_entries_by_id(array($id));
230 if(isset($entry['ANSWER1'])){
231 $entry = $entry['ANSWER1'];
232 if( $entry['STATUS'] == "waiting" &&
233 $entry['HEADERTAG'] == "trigger_action_reinstall"){
234 $evt = new DaemonEvent_reinstall($this->config,$entry);
235 if($evt->get_timestamp(FALSE) < time()){
236 $r_evt = new DaemonEvent_localboot($this->config);
237 $r_evt->add_targets(array($entry['MACADDRESS']));
238 $r_evt->set_type(TRIGGERED_EVENT);
239 $this->o_queue->append($r_evt);
240 }
241 }
242 }
243 }
245 $this->o_queue->remove_entries($this->ids_to_remove);
246 $this->save();
247 }
249 /* Remove aborted */
250 if(isset($_POST['delete_cancel'])){
251 $this->ids_to_remove = array();;
252 }
255 /************
256 * EDIT
257 ************/
259 /* Close dialog */
260 if(isset($_POST['save_event_dialog'])){
261 if(is_object($this->dialog)){
262 $this->dialog->save_object();
263 if(!$this->o_queue->append($this->dialog)){
264 msg_dialog::display(_("Service infrastructure"),msgPool::siError($this->o_queue->get_error()),ERROR_DIALOG);
265 }else{
266 $this->dialog = FALSE;
267 $this->current = -1;
268 }
269 }
270 }
273 /* Close dialog */
274 if(isset($_POST['abort_event_dialog'])){
275 $this->dialog = FALSE;
276 $this->current = -1;
277 }
279 /* Display dialogs if currently opened */
280 if(is_object($this->dialog)){
281 $this->dialog->save_object();
282 return($this->dialog->execute());
283 }
285 /************
286 * Handle Divlist
287 ************/
289 $divlist = new MultiSelectWindow($this->config,"gotoMasses",array("gotomasses"));
290 $divlist->SetInformation(_("This menu allows you to remove and change the properties of GOsa tasks."));
291 $divlist->SetSummary(_("List of queued jobs"));
292 $divlist->EnableCloseButton(FALSE);
293 $divlist->EnableSaveButton(FALSE);
294 $divlist->SetHeadpageMode();
295 $s = ".|"._("Actions")."|\n";
296 $s.= "..|<img src='images/list_new.png' alt='' border='0' class='center'> "._("Create")."\n";
298 foreach($this->events['SCHEDULED'] as $name => $event){
299 $s.= "...|".$event['MenuImage']." ".$event['s_Menu_Name']."|add_event_".$name."\n";
300 }
301 if($this->acl_is_removeable()){
302 $s.= "..|---|\n";
303 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'> "._("Remove")."|remove_multiple\n";
304 }
305 if(preg_match("/w/",$this->getacl(""))){
306 $s.= "..|---|\n";
307 $s.= "..|<img src='images/status_start.png' alt='' border='0' class='center'> "._("Resume")."|resume_all\n";
308 $s.= "..|<img src='images/status_pause.png' alt='' border='0' class='center'> "._("Pause")."|pause_all\n";
309 $s.= "..|<img src='images/small_error.png' alt='' border='0' class='center'> "._("Abort")."|abort_process_all\n";
310 $s.= "..|<img src='images/rocket.png' alt='' border='0' class='center'> "._("Execute")."|execute_process_all\n";
311 }
313 $divlist->SetDropDownHeaderMenu($s);
315 if($this->sort_dir == "up"){
316 $sort_img = "<img src='images/sort_up.png' alt='/\' border=0>";
317 }else{
318 $sort_img = "<img src='images/sort_down.png' alt='\/' border=0>";
319 }
321 if($this->sort_by == "TargetName"){ $sort_img_1 = $sort_img; } else { $sort_img_1 = "" ;}
322 if($this->sort_by == "TaskID"){ $sort_img_2 = $sort_img; } else { $sort_img_2 = "" ;}
323 if($this->sort_by == "Schedule"){ $sort_img_3 = $sort_img; } else { $sort_img_3 = "" ;}
324 if($this->sort_by == "Action"){ $sort_img_4 = $sort_img; } else { $sort_img_4 = "" ;}
326 /* Create divlist */
327 $divlist->SetListHeader("<input type='image' src='images/list_reload.png' title='"._("Reload")."'>");
329 $plug = $_GET['plug'];
330 $chk = "<input type='checkbox' id='select_all' name='select_all'
331 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
333 /* set Page header */
334 $divlist->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
335 $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&sort=TargetName'>"._("Target").$sort_img_1."</a>"));
336 $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&sort=TaskID'>"._("Task").$sort_img_2."</a>",
337 "attach"=>"style='width:120px;'"));
338 $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&sort=Schedule'>"._("Schedule").$sort_img_3."</a>",
339 "attach"=>"style='width:100px;'"));
340 $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&sort=Action'>"._("Status").$sort_img_4."</a>",
341 "attach"=>"style='width:80px;'"));
342 $divlist->AddHeader(array("string"=>_("Action"),
343 "attach"=>"style='border-right:0px;width:120px;'"));
346 /* Reload the list of entries */
347 $this->reload();
349 foreach($this->entries as $key => $task){
351 $prio_actions="";
352 $action = "";
354 /* If WAITING add priority action
355 */
356 if(in_array($task['STATUS'],array("waiting"))){
357 $prio_actions.= "<input class='center' type='image' src='images/prio_increase.png'
358 title='"._("Move up in execution queue")."' name='prio_up_".$key."'> ";
359 $prio_actions.= "<input class='center' type='image' src='images/prio_decrease.png'
360 title='"._("Move down in execution queue")."' name='prio_down_".$key."'> ";
361 }
363 /* If WAITING add pause action
364 */
365 if(in_array($task['STATUS'],array("waiting"))){
366 $prio_actions.= "<input class='center' type='image' src='images/status_pause.png'
367 title='"._("Pause job")."' name='pause_".$key."'> ";
368 }
370 /* If PAUSED add resume action
371 */
372 if(in_array($task['STATUS'],array("paused"))){
373 $prio_actions.= "<input class='center' type='image' src='images/status_start.png'
374 title='"._("Resume job")."' name='resume_".$key."'> ";
375 }
377 /* If PROCESSING add abort action
378 */
379 if(in_array($task['STATUS'],array("processing")) && preg_match("/install/",$task['HEADERTAG'])){
380 $prio_actions.= "<input class='center' type='image' src='images/small_error.png'
381 title='"._("Abort execution")."' name='abort_process_".$key."'>";
382 }
384 /* If PAUSED or WAITING add execution action
385 */
386 if(in_array($task['STATUS'],array("paused","waiting"))){
387 $prio_actions.= "<input class='center' type='image' src='images/rocket.png'
388 title='"._("Force execution now!")."' name='execute_process_".$key."'> ";
389 }
391 /* If PAUSED or WAITING add edit action
392 */
393 if(in_array($task['STATUS'],array("waiting"))){
394 $action.= "<input type='image' src='images/edit.png' name='edit_task_".$key."'
395 class='center' alt='"._("Edit")."'>";
396 }
398 /* If WAITING or ERROR add remove action
399 */
400 if( $this->acl_is_removeable() && in_array($task['STATUS'],array("waiting","error","processed"))){
401 $action.= "<input type='image' src='images/edittrash.png' name='remove_task_".$key."'
402 class='center' alt='"._("Remove")."'>";
403 }
404 if(in_array($task['STATUS'],array("processing")) && !preg_match("/install/",$task['HEADERTAG'])){
405 $action.= "<input type='image' src='images/edittrash.png' name='remove_task_".$key."'
406 class='center' alt='"._("Remove")."'>";
407 }
409 /* Create entry display name and tooltip */
410 $color = "";
411 $display = $task['MACADDRESS'];
412 $tooltip = "";
413 if(isset($task['TARGETTAG'])){
414 $display = $task['TARGETTAG'];
415 $tooltip = " title='".$task['MACADDRESS']."' ";
416 }
417 $display2= $task['HEADERTAG'];
419 /* Check if this event exists as Daemon class
420 * In this case, display a more accurate entry.
421 */
422 if(isset($this->events['QUEUED'][$task['HEADERTAG']])){
423 $evt_name = $this->events['QUEUED'][$task['HEADERTAG']];
424 $event_type = $this->events['BY_CLASS'][$evt_name];
425 $display2 = $event_type['s_Menu_Name'];
427 if(strlen($display2) > 20){
428 $display2 = substr($display2,0,18)."...";
429 }
431 if(isset($event_type['ListImage']) && !empty($event_type['ListImage'])){
432 $display2 = $event_type['ListImage']." ".$display2;
433 }
434 }
436 $status = $task['STATUS'];
438 if($status == "waiting"){
439 $status = "<img class='center' src='images/clock.png' alt=''> "._("Waiting");
440 }
441 if($status == "error"){
442 $status = "<img class='center' src='images/false.png' alt=''> "._("Error");
443 }
444 if($status == "processed"){
445 $status = "<img class='center' src='images/true.png' alt=''> "._("Processed");
446 }
448 /* Special handling for all entries that have
449 STATUS == "processing" && PROGRESS == NUMERIC
450 */
451 if($status == "processing" && isset($task['PROGRESS'])){
452 $percent = $task['PROGRESS'];
454 /* Show activation? */
455 if ($percent == "goto-activation"){
456 $status = "<img class='center' src='images/status_stopped.png' alt=''> "._("Locked");
458 /* Show hardware detect? */
459 } elseif ($percent == "goto-hardware-detection") {
460 $status = "<img class='center' src='images/hardware.png' alt=''> "._("Detection");
462 /* Real percent */
463 } else {
464 $status = "<img src='progress.php?x=80&y=13&p=".$percent."' alt='".$percent." %'>";
465 }
466 }
468 /* Create each field */
469 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$task['ID']."' name='item_selected_".$key."'>" ,
470 "attach" => "style='width:20px;".$color."'");
471 $field1 = array("string" => $display,
472 "attach" => $tooltip."style='".$color."'");
473 $field1a= array("string" => $display2,
474 "attach" => "style='".$color.";width:120px;'");
475 $field2 = array("string" => date("d.m.Y H:i:s",strtotime($task['TIMESTAMP'])),"attach" => "style='".$color.";width:100px;'");
476 $field3 = array("string" => $status,"attach" => "style='".$color.";width:80px;'");
477 $field4 = array("string" => $prio_actions.$action,"attach" => "style='".$color.";text-align:right;width:120px;border-right:0px;'");
478 $divlist->AddElement(array($field0,$field1,$field1a,$field2,$field3,$field4));
479 }
481 $smarty = get_smarty();
482 $smarty->assign("events",$this->events);
483 $smarty->assign("start",$this->start);
484 $smarty->assign("start_real", ($this->start + 1));
485 $smarty->assign("ranges", array("10" => "10",
486 "20" => "20",
487 "25" => "25",
488 "50" => "50",
489 "100"=> "100",
490 "200"=> "200",
491 "9999" => "*"));
493 $count = $this->o_queue->number_of_queued_entries();
494 if(!$count) $count = $this->range;
495 $divlist->SetListFooter(range_selector($count, $this->start, $this->range,"range"));
496 $smarty->assign("range",$this->range);
497 $smarty->assign("div",$divlist->Draw());
498 return($smarty->fetch (get_template_path('gotomasses.tpl', TRUE, dirname(__FILE__))));
499 }
502 /*! \brief Move an entry up or down in the queue, by updating its execution timestamp
503 @param $id Integer The ID of the entry which should be updated.
504 @param $type String "up" / "down"
505 @return boolean TRUE in case of success else FALSE
506 */
507 public function update_priority($id,$type = "up")
508 {
509 if($type == "up"){
510 $tmp = $this->o_queue->get_queued_entries($this->event_tags,-1,-1,"timestamp DESC");
511 }else{
512 $tmp = $this->o_queue->get_queued_entries($this->event_tags,-1,-1,"timestamp ASC");
513 }
514 $last = array();
515 foreach($tmp as $entry){
516 if($entry['ID'] == $id){
517 if(count($last)){
518 $time = strtotime($last['TIMESTAMP']);
519 if($type == "up"){
520 $time ++;
521 }else{
522 $time --;
523 }
524 $time_str = date("YmdHis",$time);
525 return($this->o_queue->update_entries(array($id),array("timestamp" => $time_str)));
526 }else{
527 return(FALSE);
528 }
529 }
530 $last = $entry;
531 }
532 return(FALSE);
533 }
536 /*! \brief Resumes to status 'waiting'.
537 * @return Boolean TRUE in case of success, else FALSE.
538 */
539 private function resume_queue_entries($ids)
540 {
541 if(!count($ids)){
542 return;
543 }
545 /* Entries are resumed by setting the status to
546 * 'waiting'
547 */
548 $data = array("status" => "waiting");
550 /* Check if given ids are valid and check if the status
551 * allows resuming.
552 */
553 $update_ids = array();
554 foreach($this->o_queue->get_entries_by_id($ids) as $entry){
555 if(isset($entry['STATUS']) && preg_match("/paused/",$entry['STATUS'])){
556 $update_ids[] = $entry['ID'];
557 }
558 }
560 /* Tell the daemon that we have entries to update.
561 */
562 if(count($update_ids)){
563 if(!$this->o_queue->update_entries($update_ids,$data)){
564 msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
565 return(FALSE);
566 }
567 }
568 return(TRUE);
569 }
572 /*! \brief Force queue job to be done as far as possible.
573 * @return Boolean TRUE in case of success, else FALSE.
574 */
575 private function execute_queue_entries($ids)
576 {
577 if(!count($ids)){
578 return;
579 }
581 /* Execution is forced by updating the status to
582 * waiting and setting the timestamp to current time.
583 */
584 $data = array( "timestamp" => date("YmdHis",time()),
585 "status" => "waiting");
587 /* Only allow execution of paused or waiting entries
588 */
589 $update_ids = array();
590 foreach($this->o_queue->get_entries_by_id($ids) as $entry){
591 if(in_array($entry['STATUS'],array("paused","waiting"))){
592 $update_ids[] = $entry['ID'];
593 }
594 }
596 /* Tell the daemon that we want to update some entries
597 */
598 if(count($update_ids)){
599 if(!$this->o_queue->update_entries($update_ids,$data)){
600 msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entries.")) , ERROR_DIALOG);
601 return(FALSE);
602 }
603 }
604 return(TRUE);
605 }
608 /*! \brief Force queue job to be done as far as possible.
609 * @return Boolean TRUE in case of success, else FALSE.
610 */
611 private function abort_queue_entries($ids)
612 {
613 if(!count($ids)){
614 return;
615 }
617 /* Entries are paused by setting the status to
618 * something different from 'waiting'.
619 * We simply use 'paused'.
620 */
621 $data = array("status" => "paused");
623 /* Detect if the ids we got are valid and
624 * check if the status allows pausing.
625 */
626 $update_ids = array();
627 foreach($this->o_queue->get_entries_by_id($ids) as $entry){
628 if(isset($entry['STATUS']) && preg_match("/processing/",$entry['STATUS'])){
629 if(isset($entry['MACADDRESS'])){
630 $update_ids[] = $entry['MACADDRESS'];
631 }else{
632 trigger_error("No mac address found in event.");
633 }
634 }
635 }
637 if(class_available("DaemonEvent_faireboot")){
638 $tmp = new DaemonEvent_faireboot($this->config);
639 $tmp->add_targets($update_ids);
640 $tmp->set_type(TRIGGERED_EVENT);
641 if(!$this->o_queue->append($tmp)){
642 msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
643 return(FALSE);
644 }
645 }else{
646 msg_dialog::display(_("Error"),
647 sprintf(_("The job could not be aborted, the required class '%s' was not found."),
648 "DaemonEvent_faireboot") , ERROR_DIALOG);
649 }
650 }
653 /*! \brief Pauses the specified queue entry from execution.
654 * @return Boolean TRUE in case of success, else FALSE.
655 */
656 private function pause_queue_entries($ids)
657 {
658 if(!count($ids)){
659 return;
660 }
662 /* Entries are paused by setting the status to
663 * something different from 'waiting'.
664 * We simply use 'paused'.
665 */
666 $data = array("status" => "paused");
668 /* Detect if the ids we got are valid and
669 * check if the status allows pausing.
670 */
671 $update_ids = array();
672 foreach($this->o_queue->get_entries_by_id($ids) as $entry){
673 if(isset($entry['STATUS']) && preg_match("/waiting/",$entry['STATUS'])){
674 $update_ids[] = $entry['ID'];
675 }
676 }
678 /* Tell the daemon that we want to update some entries
679 */
680 if(count($update_ids)){
681 if(!$this->o_queue->update_entries($update_ids,$data)){
682 msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
683 return(FALSE);
684 }
685 }
686 return(TRUE);
687 }
690 /*! \brief Request list of queued jobs.
691 * @return Returns an array of all queued jobs.
692 */
693 function reload()
694 {
696 /* Sort map html-post-name => daemon-col-name
697 */
698 $map = array(
699 "QueuePosition" => "id",
700 "Action" => "status",
701 "TaskID" => "headertag",
702 "TargetName" => "macaddress",
703 "Schedule" => "timestamp");
705 /* Create sort header
706 */
707 if(!isset($map[$this->sort_by])){
708 $sort = "id DESC";
709 }else{
710 $sort = $map[$this->sort_by];
711 if($this->sort_dir == "up"){
712 $sort.= " ASC";
713 }else{
714 $sort.= " DESC";
715 }
716 }
718 /* Get entries. */
719 $start = $this->start;
720 $stop = $this->range;
721 $entries = $this->o_queue->get_queued_entries($this->event_tags,$start,$stop,$sort);
722 if ($this->o_queue->is_error()){
723 msg_dialog::display(_("Error"), sprintf(_("Cannot load queue entries: %s"), "<br><br>".$this->o_queue->get_error()), ERROR_DIALOG);
724 }
726 /* Assign entries by id.
727 */
728 $this->entries = array();
729 foreach($entries as $entry){
730 $this->entries[$entry['ID']]= $entry;
731 }
732 }
735 /*! \brief Handle post jobs, like sorting.
736 */
737 function save_object()
738 {
739 /* Check for sorting changes
740 */
741 $sort_vals = array("Action","QueuePosition","TargetName","Schedule","TaskID");
742 if(isset($_GET['sort']) && in_array($_GET['sort'],$sort_vals)){
743 $sort = $_GET['sort'];
744 if($this->sort_by == $sort){
745 if($this->sort_dir == "up"){
746 $this->sort_dir = "down";
747 }else{
748 $this->sort_dir = "up";
749 }
750 }
751 $this->sort_by = $sort;
752 }
754 /* Range selection used? */
755 if(isset($_POST['range']) && is_numeric($_POST['range'])){
756 $this->range = $_POST['range'];
757 }
759 /* Page changed. */
760 if(isset($_GET['start'])){
761 $start = $_GET['start'];
762 if(is_numeric($start) || $start == 0){
763 $this->start = $start;
764 }
765 }
767 /* Check start stop and reset if necessary */
768 $count = $this->o_queue->number_of_queued_entries();
769 if($this->start >= $count){
770 $this->start = $count -1;
771 }
772 if($this->start < 0){
773 $this->start = 0;
774 }
775 }
778 function save()
779 {
780 // We do not save anything here.
781 }
784 /*! \brief Return a list of all selected items.
785 @return Array Returns an array containing all selected item ids.
786 */
787 function list_get_selected_items()
788 {
789 $ids = array();
790 foreach($_POST as $name => $value){
791 if(preg_match("/^item_selected_[0-9]*$/",$name)){
792 $id = preg_replace("/^item_selected_/","",$name);
793 $ids[$id] = $id;
794 }
795 }
796 return($ids);
797 }
800 static function plInfo()
801 {
802 return (array(
803 "plShortName" => _("System mass deployment"),
804 "plDescription" => _("Provide a mechanism to automatically activate a set of systems"),
805 "plSelfModify" => FALSE,
806 "plDepends" => array(),
807 "plPriority" => 0,
808 "plSection" => array("addon"),
809 "plCategory" => array("gotomasses" => array("objectClass" => "none", "description" => _("System mass deployment"))),
810 "plProvidedAcls" => array("Comment" => _("Description"))
811 ));
812 }
813 }
814 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
815 ?>