Code

Fixed gotomasses
[gosa.git] / gosa-plugins / goto / addons / goto / class_gotomasses.inc
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     = "System deployment";
27   var $plDescription  = "This does something";
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();
66  
67     /************
68      * Handle posts 
69      ************/
70     
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     }
101     
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      ************/
149   
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"))){
203               $this->ids_to_remove[] = $task['ID'];
204               if(isset($this->events['QUEUED'][$task['HEADERTAG']])){
205                 $evt_name = $this->events['QUEUED'][$task['HEADERTAG']];
206                 $evt = $this->events['BY_CLASS'][$evt_name];
207                 $tmp.= "\n".$task['ID']." - ".$evt['s_Menu_Name']."&nbsp;".$task['MACADDRESS'];
208               }else{
209                 $tmp.= "\n".$task['ID']." - ".$task['HEADERTAG']."&nbsp;".$task['MACADDRESS'];
210               }
211             }
212           }
213           $smarty->assign("multiple", TRUE); 
214           $smarty->assign("info",msgPool::deleteInfo("<pre>".$tmp."</pre>"));
215           $this->current = $s_entry;
216           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
217         }
218       }
219     }
221     /* Remove specified tasks */
222     if(count($this->ids_to_remove) && isset($_POST['delete_multiple_confirm'])){
224       /* Reboot hosts with not yet startet installations and timestamps in the past 
225        */
226       timezone::get_default_timezone();
227       foreach($this->ids_to_remove as $id){
228         $entry = $this->o_queue->get_entries_by_id(array($id));
229         if(isset($entry['ANSWER1'])){
230           $entry = $entry['ANSWER1'];
231           if( $entry['STATUS'] == "waiting" && 
232               $entry['HEADERTAG'] == "trigger_action_reinstall"){
233             $evt = new DaemonEvent_reinstall($this->config,$entry);
234             if($evt->get_timestamp(FALSE)  < time()){
235               $r_evt = new DaemonEvent_localboot($this->config);
236               $r_evt->add_targets(array($entry['MACADDRESS']));
237               $r_evt->set_type(TRIGGERED_EVENT);
238               $this->o_queue->append($r_evt);
239             }
240           }
241         }
242       }
244       $this->o_queue->remove_entries($this->ids_to_remove);
245       $this->save();
246     }
248     /* Remove aborted */
249     if(isset($_POST['delete_cancel'])){
250       $this->ids_to_remove = array();;
251     }
254     /************
255      * EDIT 
256      ************/
258     /* Close dialog */
259     if(isset($_POST['save_event_dialog'])){
260       if(is_object($this->dialog)){
261         $this->dialog->save_object();
262         if(!$this->o_queue->append($this->dialog)){
263           msg_dialog::display(_("Service infrastructure"),msgPool::siError($this->o_queue->get_error()),ERROR_DIALOG);
264         }else{
265           $this->dialog = FALSE; 
266           $this->current = -1;
267         } 
268       }
269     }
272     /* Close dialog */
273     if(isset($_POST['abort_event_dialog'])){
274       $this->dialog = FALSE;
275       $this->current = -1;
276     }
278     /* Display dialogs if currently opened */
279     if(is_object($this->dialog)){
280       $this->dialog->save_object();
281       return($this->dialog->execute());
282     }
284     /************
285      * Handle Divlist 
286      ************/
288     $divlist = new MultiSelectWindow($this->config,"gotoMasses",array("gotomasses"));
289     $divlist->SetInformation(_("This menu allows you to remove and change the properties of GOsa tasks."));
290     $divlist->SetSummary(_("List of queued jobs"));
291     $divlist->EnableCloseButton(FALSE);
292     $divlist->EnableSaveButton(FALSE);
293     $divlist->SetHeadpageMode();
294     $s = ".|"._("Actions")."|\n";
295     $s.= "..|<img src='images/list_new.png' alt='' border='0' class='center'>&nbsp;"._("Create")."\n";
297     foreach($this->events['SCHEDULED'] as $name =>  $event){
298       $s.= "...|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|add_event_".$name."\n";
299     }
300     if($this->acl_is_removeable()){
301       $s.= "..|---|\n";
302       $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>&nbsp;"._("Remove")."|remove_multiple\n";
303     }
304     if(preg_match("/w/",$this->getacl(""))){
305       $s.= "..|---|\n";
306       $s.= "..|<img src='images/status_start.png' alt='' border='0' class='center'>&nbsp;"._("Resume")."|resume_all\n";
307       $s.= "..|<img src='images/status_pause.png' alt='' border='0' class='center'>&nbsp;"._("Pause")."|pause_all\n";
308       $s.= "..|<img src='images/small_error.png'  alt='' border='0' class='center'>&nbsp;"._("Abort")."|abort_process_all\n";
309       $s.= "..|<img src='images/rocket.png'       alt='' border='0' class='center'>&nbsp;"._("Execute")."|execute_process_all\n";
310     }
312     $divlist->SetDropDownHeaderMenu($s);
314     if($this->sort_dir == "up"){
315       $sort_img = "<img src='images/sort_up.png' alt='/\' border=0>";
316     }else{
317       $sort_img = "<img src='images/sort_down.png' alt='\/' border=0>";
318     }
320     if($this->sort_by == "TargetName"){ $sort_img_1 = $sort_img; } else { $sort_img_1 = "" ;}
321     if($this->sort_by == "TaskID"){ $sort_img_2 = $sort_img; } else { $sort_img_2 = "" ;}
322     if($this->sort_by == "Schedule"){ $sort_img_3 = $sort_img; } else { $sort_img_3 = "" ;}
323     if($this->sort_by == "Action"){ $sort_img_4 = $sort_img; } else { $sort_img_4 = "" ;}
325     /* Create divlist */
326     $divlist->SetListHeader("<input type='image' src='images/list_reload.png' title='"._("Reload")."'>");
328     $plug  = $_GET['plug'];
329     $chk = "<input type='checkbox' id='select_all' name='select_all'
330                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
332     /* set Page header */
333     $divlist->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
334     $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=TargetName'>"._("Target").$sort_img_1."</a>"));
335     $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=TaskID'>"._("Task").$sort_img_2."</a>",
336                                       "attach"=>"style='width:120px;'"));
337     $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=Schedule'>"._("Schedule").$sort_img_3."</a>",
338                                       "attach"=>"style='width:100px;'"));
339     $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=Action'>"._("Status").$sort_img_4."</a>",
340                                       "attach"=>"style='width:80px;'"));
341     $divlist->AddHeader(array("string"=>_("Action"),
342                                       "attach"=>"style='border-right:0px;width:120px;'"));
345     /* Reload the list of entries */
346     $this->reload();
348     foreach($this->entries as $key => $task){
350       $prio_actions="";
351       $action = "";
353       /* If WAITING add priority action
354        */  
355       if(in_array($task['STATUS'],array("waiting"))){
356         $prio_actions.= "<input class='center' type='image' src='images/prio_increase.png' 
357           title='"._("Move up in execution queue")."' name='prio_up_".$key."'>&nbsp;";
358         $prio_actions.= "<input class='center' type='image' src='images/prio_decrease.png' 
359           title='"._("Move down in execution queue")."' name='prio_down_".$key."'>&nbsp;";
360       }
361     
362       /* If WAITING add pause action
363        */  
364       if(in_array($task['STATUS'],array("waiting"))){
365         $prio_actions.= "<input class='center' type='image' src='images/status_pause.png' 
366           title='"._("Pause job")."' name='pause_".$key."'>&nbsp;";
367       }
369       /* If PAUSED add resume action
370        */  
371       if(in_array($task['STATUS'],array("paused"))){
372         $prio_actions.= "<input class='center' type='image' src='images/status_start.png' 
373           title='"._("Resume job")."' name='resume_".$key."'>&nbsp;";
374       }
376       /* If PROCESSING add abort action
377        */  
378       if(in_array($task['STATUS'],array("processing"))){
379         $prio_actions.= "<input class='center' type='image' src='images/small_error.png' 
380           title='"._("Abort execution")."' name='abort_process_".$key."'>";
381       }
383       /* If PAUSED or WAITING add execution action
384        */  
385       if(in_array($task['STATUS'],array("paused","waiting"))){
386         $prio_actions.= "<input class='center' type='image' src='images/rocket.png' 
387           title='"._("Force execution now!")."' name='execute_process_".$key."'>&nbsp;";
388       }
390       /* If PAUSED or WAITING add edit action
391        */  
392       if(in_array($task['STATUS'],array("waiting"))){
393         $action.= "<input type='image' src='images/edit.png' name='edit_task_".$key."' 
394           class='center' alt='"._("Edit")."'>";
395       }
397       /* If WAITING or ERROR add remove action
398        */  
399       if( $this->acl_is_removeable() && in_array($task['STATUS'],array("waiting","error"))){
400         $action.= "<input type='image' src='images/edittrash.png' name='remove_task_".$key."' 
401           class='center' alt='"._("Remove")."'>";
402       }
404       $color = "";
405       $display = $task['MACADDRESS'];
406       $display2= $task['HEADERTAG'];
407      
408       /* Check if this event exists as Daemon class 
409        * In this case, display a more accurate entry.
410        */ 
411       if(isset($this->events['QUEUED'][$task['HEADERTAG']])){
412         $evt_name   = $this->events['QUEUED'][$task['HEADERTAG']];
413         $event_type = $this->events['BY_CLASS'][$evt_name];
414         $display2   = $event_type['s_Menu_Name'];
416         if(strlen($display2) > 20){
417           $display2 = substr($display2,0,18)."...";
418         }
420         if(isset($event_type['ListImage']) && !empty($event_type['ListImage'])){
421           $display2 = $event_type['ListImage']."&nbsp;".$display2;
422         }
423       } 
425       $status = $task['STATUS'];
426   
427       if($status == "waiting"){
428         $status = "<img class='center' src='images/clock.png' alt=''>&nbsp;"._("Waiting");
429       }
430       if($status == "error"){
431         $status = "<img class='center' src='images/false.png' alt=''>&nbsp;"._("Error");
432       }
434       /* Special handling for all entries that have 
435           STATUS == "processing" && PROGRESS == NUMERIC
436        */
437       if($status == "processing" && isset($task['PROGRESS'])){
438         $percent = $task['PROGRESS'];
440         /* Show activation? */
441         if ($percent == "goto-activation"){
442           $status = "<img class='center' src='images/status_stopped.png' alt=''>&nbsp;"._("Locked");
444         /* Show hardware detect? */
445         } elseif ($percent == "goto-hardware-detection") {
446           $status = "<img class='center' src='images/hardware.png' alt=''>&nbsp;"._("Detection");
448         /* Real percent */
449         } else {
450           $status = "<img src='progress.php?x=80&amp;y=13&amp;p=".$percent."' alt='".$percent."&nbsp;%'>";
451         }
452       }
454       /* Create each field */
455       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$task['ID']."' name='item_selected_".$key."'>" ,
456                       "attach" => "style='width:20px;".$color."'");
457       $field1 = array("string" => $display,
458                       "attach" => "style='".$color."'");
459       $field1a= array("string" => $display2,
460                       "attach" => "style='".$color.";width:120px;'");
461       $field2 = array("string" => date("d.m.Y H:i:s",strtotime($task['TIMESTAMP'])),"attach" => "style='".$color.";width:100px;'");
462       $field3 = array("string" => $status,"attach" => "style='".$color.";width:80px;'");
463       $field4 = array("string" => $prio_actions.$action,"attach" => "style='".$color.";text-align:right;width:120px;border-right:0px;'");
464       $divlist->AddElement(array($field0,$field1,$field1a,$field2,$field3,$field4));
465     }
467     $smarty = get_smarty();
468     $smarty->assign("events",$this->events);
469     $smarty->assign("start",$this->start);
470     $smarty->assign("start_real", ($this->start + 1));
471     $smarty->assign("ranges", array("10" => "10",
472                                     "20" => "20",
473                                     "25" => "25",
474                                     "50" => "50",
475                                     "100"=> "100",
476                                     "200"=> "200",
477                                     "9999" => "*"));
479     $count = $this->o_queue->number_of_queued_entries();
480     if(!$count) $count = $this->range;
481     $divlist->SetListFooter(range_selector($count, $this->start, $this->range,"range"));
482     $smarty->assign("range",$this->range);
483     $smarty->assign("div",$divlist->Draw());
484     return($smarty->fetch (get_template_path('gotomasses.tpl', TRUE, dirname(__FILE__))));
485   }
488   /*! \brief  Move an entry up or down in the queue, by updating its execution timestamp  
489       @param  $id     Integer  The ID of the entry which should be updated.
490       @param  $type   String   "up" / "down"
491       @return boolean TRUE in case of success else FALSE
492   */
493   public function update_priority($id,$type = "up")
494   {
495     if($type == "up"){
496       $tmp = $this->o_queue->get_queued_entries($this->event_tags,-1,-1,"timestamp DESC");
497     }else{
498       $tmp = $this->o_queue->get_queued_entries($this->event_tags,-1,-1,"timestamp ASC");
499     }
500     $last = array();
501     foreach($tmp as $entry){
502       if($entry['ID'] == $id){
503         if(count($last)){
504           $time = strtotime($last['TIMESTAMP']);
505           if($type == "up"){
506             $time ++;
507           }else{
508             $time --;
509           }
510           $time_str = date("YmdHis",$time); 
511           return($this->o_queue->update_entries(array($id),array("timestamp" => $time_str)));
512         }else{
513           return(FALSE);
514         }
515       }
516       $last = $entry;
517     }
518     return(FALSE);
519   }
522   /*! \brief  Resumes to status 'waiting'.
523    *  @return Boolean TRUE in case of success, else FALSE. 
524    */
525   private function resume_queue_entries($ids)
526   {
527     if(!count($ids)){
528       return;
529     }
531     /* Entries are resumed by setting the status to 
532      *  'waiting'
533      */
534     $data = array("status"    => "waiting");
535   
536     /* Check if given ids are valid and check if the status
537      *  allows resuming.
538      */
539     $update_ids = array();
540     foreach($this->o_queue->get_entries_by_id($ids) as $entry){
541       if(isset($entry['STATUS']) && preg_match("/paused/",$entry['STATUS'])){
542         $update_ids[] = $entry['ID'];
543       }
544     }
546     /* Tell the daemon that we have entries to update.
547      */
548     if(count($update_ids)){
549       if(!$this->o_queue->update_entries($update_ids,$data)){
550         msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
551         return(FALSE);
552       }
553     }
554     return(TRUE);
555   }
558   /*! \brief  Force queue job to be done as far as possible.
559    *  @return Boolean TRUE in case of success, else FALSE.
560    */
561   private function execute_queue_entries($ids)
562   {
563     if(!count($ids)){
564       return;
565     }
567     /* Execution is forced by updating the status to 
568      *  waiting and setting the timestamp to current time.
569      */
570     $data = array(  "timestamp" => date("YmdHis",time()), 
571                     "status"    => "waiting");
573     /* Only allow execution of paused or waiting entries 
574      */
575     $update_ids = array();
576     foreach($this->o_queue->get_entries_by_id($ids) as $entry){
577       if(in_array($entry['STATUS'],array("paused","waiting"))){
578         $update_ids[] = $entry['ID'];
579       }
580     }
582     /* Tell the daemon that we want to update some entries
583      */
584     if(count($update_ids)){
585       if(!$this->o_queue->update_entries($update_ids,$data)){
586         msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entries.")) , ERROR_DIALOG);
587         return(FALSE);
588       }
589     }
590     return(TRUE);
591   }
594   /*! \brief  Force queue job to be done as far as possible.
595    *  @return Boolean TRUE in case of success, else FALSE.
596    */
597   private function abort_queue_entries($ids)
598   {
599     if(!count($ids)){
600       return;
601     }
603     /* Entries are paused by setting the status to
604      *  something different from 'waiting'.
605      * We simply use 'paused'.
606      */
607     $data = array("status"    => "paused");
609     /* Detect if the ids we got are valid and
610      *  check if the status allows pausing.
611      */
612     $update_ids = array();
613     foreach($this->o_queue->get_entries_by_id($ids) as $entry){
614       if(isset($entry['STATUS']) && preg_match("/processing/",$entry['STATUS'])){
615         if(isset($entry['MACADDRESS'])){
616           $update_ids[] = $entry['MACADDRESS'];
617         }else{
618           trigger_error("No mac address found in event.");
619         }
620       }
621     }
623     if(class_available("DaemonEvent_faireboot")){
624       $tmp = new DaemonEvent_faireboot($this->config);
625       $tmp->add_targets($update_ids);
626       $tmp->set_type(TRIGGERED_EVENT);
627       if(!$this->o_queue->append($tmp)){
628         msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
629         return(FALSE);
630       }
631     }else{
632       msg_dialog::display(_("Error"),
633           sprintf(_("The job could not be aborted, the required class '%s' was not found."),
634             "DaemonEvent_faireboot") , ERROR_DIALOG);
635     }
636   }
639   /*! \brief Pauses the specified queue entry from execution.
640    *  @return Boolean TRUE in case of success, else FALSE. 
641    */
642   private function pause_queue_entries($ids)
643   {
644     if(!count($ids)){
645       return;
646     }
648     /* Entries are paused by setting the status to 
649      *  something different from 'waiting'.
650      * We simply use 'paused'.
651      */   
652     $data = array("status"    => "paused");
654     /* Detect if the ids we got are valid and
655      *  check if the status allows pausing.
656      */ 
657     $update_ids = array();
658     foreach($this->o_queue->get_entries_by_id($ids) as $entry){
659       if(isset($entry['STATUS']) && preg_match("/waiting/",$entry['STATUS'])){
660         $update_ids[] = $entry['ID'];
661       }
662     }
664     /* Tell the daemon that we want to update some entries
665      */
666     if(count($update_ids)){
667       if(!$this->o_queue->update_entries($update_ids,$data)){
668         msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
669         return(FALSE);
670       }
671     }
672     return(TRUE);
673   }
676   /*! \brief  Request list of queued jobs.
677    *  @return Returns an array of all queued jobs.
678    */
679   function reload()
680   {
682     /* Sort map   html-post-name => daemon-col-name
683      */
684     $map = array(
685         "QueuePosition" => "id",
686         "Action"        => "status",
687         "TaskID"        => "headertag",
688         "TargetName"    => "macaddress",
689         "Schedule"      => "timestamp");
691     /* Create sort header 
692      */
693     if(!isset($map[$this->sort_by])){
694       $sort = "id DESC";
695     }else{
696       $sort   = $map[$this->sort_by]; 
697       if($this->sort_dir == "up"){
698         $sort.= " ASC";
699       }else{
700         $sort.= " DESC";
701       }
702     }
703      
704     /* Get entries. */ 
705     $start  = $this->start; 
706     $stop   = $this->range;
707     $entries = $this->o_queue->get_queued_entries($this->event_tags,$start,$stop,$sort);
708     if ($this->o_queue->is_error()){
709       msg_dialog::display(_("Error"), sprintf(_("Cannot load queue entries: %s"), "<br><br>".$this->o_queue->get_error()), ERROR_DIALOG);
710     }
712     /* Assign entries by id.
713      */
714     $this->entries = array();
715     foreach($entries as $entry){
716       $this->entries[$entry['ID']]= $entry;
717     }
718   }
721   /*! \brief  Handle post jobs, like sorting.
722    */
723   function save_object()
724   {
725     /* Check for sorting changes 
726      */
727     $sort_vals = array("Action","QueuePosition","TargetName","Schedule","TaskID");
728     if(isset($_GET['sort']) && in_array($_GET['sort'],$sort_vals)){
729       $sort = $_GET['sort'];
730       if($this->sort_by == $sort){
731         if($this->sort_dir == "up"){
732           $this->sort_dir = "down";
733         }else{
734           $this->sort_dir = "up";
735         }
736       }
737       $this->sort_by = $sort;
738     }
740     /* Range selection used? */
741     if(isset($_POST['range']) && is_numeric($_POST['range'])){
742       $this->range = $_POST['range'];
743     }
744     
745     /* Page changed. */
746     if(isset($_GET['start'])){
747       $start = $_GET['start'];
748       if(is_numeric($start) || $start == 0){
749         $this->start = $start;
750       }
751     }
753     /* Check start stop and reset if necessary */
754     $count = $this->o_queue->number_of_queued_entries();
755     if($this->start >= $count){
756       $this->start = $count -1;
757     }
758     if($this->start < 0){
759       $this->start = 0;
760     }
761   }
764   function save()
765   {
766     // We do not save anything here.
767   }
770   /*! \brief  Return a list of all selected items.
771     @return Array   Returns an array containing all selected item ids.
772    */
773   function list_get_selected_items()
774   {
775     $ids = array();
776     foreach($_POST as $name => $value){
777       if(preg_match("/^item_selected_[0-9]*$/",$name)){
778         $id   = preg_replace("/^item_selected_/","",$name);
779         $ids[$id] = $id;
780       }
781     }
782     return($ids);
783   }
786   static function plInfo()
787   {
788     return (array(
789           "plShortName"   => _("System mass deployment"),
790           "plDescription" => _("Provide a mechanism to automatically activate a set of systems"),
791           "plSelfModify"  => FALSE,
792           "plDepends"     => array(),
793           "plPriority"    => 0,
794           "plSection"     => array("addon"),
795           "plCategory"    => array("gotomasses" => array("objectClass" => "none", "description" => _("System mass deployment"))),
796           "plProvidedAcls" => array("Comment"   => _("Description")) 
797           ));
798   }
800 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
801 ?>