Code

Updated goto
[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",sprintf(_("You are about to remove the following actions from the GOsa support Daemon: %s"),"<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'] == "wating" && 
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(_("Daemon"),sprintf(_("Something went wrong while talking to the daemon: %s."),
264                 $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'>&nbsp;"._("Create")."\n";
298     foreach($this->events['SCHEDULED'] as $name =>  $event){
299       $s.= "...|".$event['MenuImage']."&nbsp;".$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'>&nbsp;"._("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'>&nbsp;"._("Resume")."|resume_all\n";
308       $s.= "..|<img src='images/status_pause.png' alt='' border='0' class='center'>&nbsp;"._("Pause")."|pause_all\n";
309       $s.= "..|<img src='images/small_error.png'  alt='' border='0' class='center'>&nbsp;"._("Abort")."|abort_process_all\n";
310       $s.= "..|<img src='images/rocket.png'       alt='' border='0' class='center'>&nbsp;"._("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."&amp;sort=TargetName'>"._("Target").$sort_img_1."</a>"));
336     $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=TaskID'>"._("Task").$sort_img_2."</a>",
337                                       "attach"=>"style='width:120px;'"));
338     $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=Schedule'>"._("Schedule").$sort_img_3."</a>",
339                                       "attach"=>"style='width:100px;'"));
340     $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;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."'>&nbsp;";
359         $prio_actions.= "<input class='center' type='image' src='images/prio_decrease.png' 
360           title='"._("Move down in execution queue")."' name='prio_down_".$key."'>&nbsp;";
361       }
362     
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."'>&nbsp;";
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."'>&nbsp;";
375       }
377       /* If PROCESSING add abort action
378        */  
379       if(in_array($task['STATUS'],array("processing"))){
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."'>&nbsp;";
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"))){
401         $action.= "<input type='image' src='images/edittrash.png' name='remove_task_".$key."' 
402           class='center' alt='"._("Remove")."'>";
403       }
405       $color = "";
406       $display = $task['MACADDRESS'];
407       $display2= $task['HEADERTAG'];
408      
409       /* Check if this event exists as Daemon class 
410        * In this case, display a more accurate entry.
411        */ 
412       if(isset($this->events['QUEUED'][$task['HEADERTAG']])){
413         $evt_name   = $this->events['QUEUED'][$task['HEADERTAG']];
414         $event_type = $this->events['BY_CLASS'][$evt_name];
415         $display2   = $event_type['s_Menu_Name'];
417         if(strlen($display2) > 20){
418           $display2 = substr($display2,0,18)."...";
419         }
421         if(isset($event_type['ListImage']) && !empty($event_type['ListImage'])){
422           $display2 = $event_type['ListImage']."&nbsp;".$display2;
423         }
424       } 
426       $status = $task['STATUS'];
427   
428       if($status == "waiting"){
429         $status = "<img class='center' src='images/clock.png' alt=''>&nbsp;"._("Waiting");
430       }
431       if($status == "error"){
432         $status = "<img class='center' src='images/false.png' alt=''>&nbsp;"._("Error");
433       }
435       /* Special handling for all entries that have 
436           STATUS == "processing" && PROGRESS == NUMERIC
437        */
438       if($status == "processing" && isset($task['PROGRESS'])){
439         $percent = $task['PROGRESS'];
440         $status = "<img src='progress.php?x=80&amp;y=13&amp;p=".$percent."' alt='".$percent."&nbsp;%'>";
441       }
444       /* Create each field */
445       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$task['ID']."' name='item_selected_".$key."'>" ,
446                       "attach" => "style='width:20px;".$color."'");
447       $field1 = array("string" => $display,
448                       "attach" => "style='".$color."'");
449       $field1a= array("string" => $display2,
450                       "attach" => "style='".$color.";width:120px;'");
451       $field2 = array("string" => date("d.m.Y H:i:s",strtotime($task['TIMESTAMP'])),"attach" => "style='".$color.";width:100px;'");
452       $field3 = array("string" => $status,"attach" => "style='".$color.";width:80px;'");
453       $field4 = array("string" => $prio_actions.$action,"attach" => "style='".$color.";text-align:right;width:120px;border-right:0px;'");
454       $divlist->AddElement(array($field0,$field1,$field1a,$field2,$field3,$field4));
455     }
457     $smarty = get_smarty();
458     $smarty->assign("events",$this->events);
459     $smarty->assign("start",$this->start);
460     $smarty->assign("start_real", ($this->start + 1));
461     $smarty->assign("ranges", array("10" => "10",
462                                     "20" => "20",
463                                     "25" => "25",
464                                     "50" => "50",
465                                     "100"=> "100",
466                                     "200"=> "200",
467                                     "9999" => "*"));
469     $count = $this->o_queue->number_of_queued_entries();
470     $divlist->SetListFooter(range_selector($count, $this->start, $this->range,"range"));
471     $smarty->assign("range",$this->range);
472     $smarty->assign("div",$divlist->Draw());
473     return($smarty->fetch (get_template_path('gotomasses.tpl', TRUE, dirname(__FILE__))));
474   }
477   /*! \brief  Move an entry up or down in the queue, by updating its execution timestamp  
478       @param  $id     Integer  The ID of the entry which should be updated.
479       @param  $type   String   "up" / "down"
480       @return boolean TRUE in case of success else FALSE
481   */
482   public function update_priority($id,$type = "up")
483   {
484     if($type == "up"){
485       $tmp = $this->o_queue->get_queued_entries($this->event_tags,-1,-1,"timestamp DESC");
486     }else{
487       $tmp = $this->o_queue->get_queued_entries($this->event_tags,-1,-1,"timestamp ASC");
488     }
489     $last = array();
490     foreach($tmp as $entry){
491       if($entry['ID'] == $id){
492         if(count($last)){
493           $time = strtotime($last['TIMESTAMP']);
494           if($type == "up"){
495             $time ++;
496           }else{
497             $time --;
498           }
499           $time_str = date("YmdHis",$time); 
500           return($this->o_queue->update_entries(array($id),array("timestamp" => $time_str)));
501         }else{
502           return(FALSE);
503         }
504       }
505       $last = $entry;
506     }
507     return(FALSE);
508   }
511   /*! \brief  Resumes to status 'waiting'.
512    *  @return Boolean TRUE in case of success, else FALSE. 
513    */
514   private function resume_queue_entries($ids)
515   {
516     if(!count($ids)){
517       return;
518     }
520     /* Entries are resumed by setting the status to 
521      *  'waiting'
522      */
523     $data = array("status"    => "waiting");
524   
525     /* Check if given ids are valid and check if the status
526      *  allows resuming.
527      */
528     $update_ids = array();
529     foreach($this->o_queue->get_entries_by_id($ids) as $entry){
530       if(isset($entry['STATUS']) && preg_match("/paused/",$entry['STATUS'])){
531         $update_ids[] = $entry['ID'];
532       }
533     }
535     /* Tell the daemon that we have entries to update.
536      */
537     if(count($update_ids)){
538       if(!$this->o_queue->update_entries($update_ids,$data)){
539         msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
540         return(FALSE);
541       }
542     }
543     return(TRUE);
544   }
547   /*! \brief  Force queue job to be done as far as possible.
548    *  @return Boolean TRUE in case of success, else FALSE.
549    */
550   private function execute_queue_entries($ids)
551   {
552     if(!count($ids)){
553       return;
554     }
556     /* Execution is forced by updating the status to 
557      *  waiting and setting the timestamp to current time.
558      */
559     $data = array(  "timestamp" => date("YmdHis",time()), 
560                     "status"    => "waiting");
562     /* Only allow execution of paused or waiting entries 
563      */
564     $update_ids = array();
565     foreach($this->o_queue->get_entries_by_id($ids) as $entry){
566       if(in_array($entry['STATUS'],array("paused","waiting"))){
567         $update_ids[] = $entry['ID'];
568       }
569     }
571     /* Tell the daemon that we want to update some entries
572      */
573     if(count($update_ids)){
574       if(!$this->o_queue->update_entries($update_ids,$data)){
575         msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entries.")) , ERROR_DIALOG);
576         return(FALSE);
577       }
578     }
579     return(TRUE);
580   }
583   /*! \brief  Force queue job to be done as far as possible.
584    *  @return Boolean TRUE in case of success, else FALSE.
585    */
586   private function abort_queue_entries($ids)
587   {
588     if(!count($ids)){
589       return;
590     }
592     /* Entries are paused by setting the status to
593      *  something different from 'waiting'.
594      * We simply use 'paused'.
595      */
596     $data = array("status"    => "paused");
598     /* Detect if the ids we got are valid and
599      *  check if the status allows pausing.
600      */
601     $update_ids = array();
602     foreach($this->o_queue->get_entries_by_id($ids) as $entry){
603       if(isset($entry['STATUS']) && preg_match("/processing/",$entry['STATUS'])){
604         if(isset($entry['MACADDRESS'])){
605           $update_ids[] = $entry['MACADDRESS'];
606         }else{
607           trigger_error("No mac address found in event.");
608         }
609       }
610     }
612     if(class_available("DaemonEvent_faireboot")){
613       $tmp = new DaemonEvent_faireboot($this->config);
614       $tmp->add_targets($update_ids);
615       $tmp->set_type(TRIGGERED_EVENT);
616       if(!$this->o_queue->append($tmp)){
617         msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
618         return(FALSE);
619       }
620     }else{
621       msg_dialog::display(_("Error"),
622           sprintf(_("The job could not be aborted, the required class '%s' was not found."),
623             "DaemonEvent_faireboot") , ERROR_DIALOG);
624     }
625   }
628   /*! \brief Pauses the specified queue entry from execution.
629    *  @return Boolean TRUE in case of success, else FALSE. 
630    */
631   private function pause_queue_entries($ids)
632   {
633     if(!count($ids)){
634       return;
635     }
637     /* Entries are paused by setting the status to 
638      *  something different from 'waiting'.
639      * We simply use 'paused'.
640      */   
641     $data = array("status"    => "paused");
643     /* Detect if the ids we got are valid and
644      *  check if the status allows pausing.
645      */ 
646     $update_ids = array();
647     foreach($this->o_queue->get_entries_by_id($ids) as $entry){
648       if(isset($entry['STATUS']) && preg_match("/waiting/",$entry['STATUS'])){
649         $update_ids[] = $entry['ID'];
650       }
651     }
653     /* Tell the daemon that we want to update some entries
654      */
655     if(count($update_ids)){
656       if(!$this->o_queue->update_entries($update_ids,$data)){
657         msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
658         return(FALSE);
659       }
660     }
661     return(TRUE);
662   }
665   /*! \brief  Request list of queued jobs.
666    *  @return Returns an array of all queued jobs.
667    */
668   function reload()
669   {
671     /* Sort map   html-post-name => daemon-col-name
672      */
673     $map = array(
674         "QueuePosition" => "id",
675         "Action"        => "status",
676         "TaskID"        => "headertag",
677         "TargetName"    => "macaddress",
678         "Schedule"      => "timestamp");
680     /* Create sort header 
681      */
682     if(!isset($map[$this->sort_by])){
683       $sort = "id DESC";
684     }else{
685       $sort   = $map[$this->sort_by]; 
686       if($this->sort_dir == "up"){
687         $sort.= " ASC";
688       }else{
689         $sort.= " DESC";
690       }
691     }
692      
693     /* Get entries. */ 
694     $start  = $this->start; 
695     $stop   = $this->range;
696     $entries = $this->o_queue->get_queued_entries($this->event_tags,$start,$stop,$sort);
697     if ($this->o_queue->is_error()){
698       msg_dialog::display(_("Error"), sprintf(_("Cannot load queue entries: %s"), "<br><br>".$this->o_queue->get_error()), ERROR_DIALOG);
699     }
701     /* Assign entries by id.
702      */
703     $this->entries = array();
704     foreach($entries as $entry){
705       $this->entries[$entry['ID']]= $entry;
706     }
707   }
710   /*! \brief  Handle post jobs, like sorting.
711    */
712   function save_object()
713   {
714     /* Check for sorting changes 
715      */
716     $sort_vals = array("Action","QueuePosition","TargetName","Schedule","TaskID");
717     if(isset($_GET['sort']) && in_array($_GET['sort'],$sort_vals)){
718       $sort = $_GET['sort'];
719       if($this->sort_by == $sort){
720         if($this->sort_dir == "up"){
721           $this->sort_dir = "down";
722         }else{
723           $this->sort_dir = "up";
724         }
725       }
726       $this->sort_by = $sort;
727     }
729     /* Range selection used? */
730     if(isset($_POST['range']) && is_numeric($_POST['range'])){
731       $this->range = $_POST['range'];
732     }
733     
734     /* Page changed. */
735     if(isset($_GET['start'])){
736       $start = $_GET['start'];
737       if(is_numeric($start) || $start == 0){
738         $this->start = $start;
739       }
740     }
742     /* Check start stop and reset if necessary */
743     $count = $this->o_queue->number_of_queued_entries();
744     if($this->start >= $count){
745       $this->start = $count -1;
746     }
747     if($this->start < 0){
748       $this->start = 0;
749     }
750   }
753   function save()
754   {
755     // We do not save anything here.
756   }
759   /*! \brief  Return a list of all selected items.
760     @return Array   Returns an array containing all selected item ids.
761    */
762   function list_get_selected_items()
763   {
764     $ids = array();
765     foreach($_POST as $name => $value){
766       if(preg_match("/^item_selected_[0-9]*$/",$name)){
767         $id   = preg_replace("/^item_selected_/","",$name);
768         $ids[$id] = $id;
769       }
770     }
771     return($ids);
772   }
775   static function plInfo()
776   {
777     return (array(
778           "plShortName"   => _("System mass deployment"),
779           "plDescription" => _("Provide a mechanism to automatically activate a set of systems"),
780           "plSelfModify"  => FALSE,
781           "plDepends"     => array(),
782           "plPriority"    => 0,
783           "plSection"     => array("addon"),
784           "plCategory"    => array("gotomasses" => array("objectClass" => "none", "description" => _("System mass deployment"))),
785           "plProvidedAcls" => array("Comment"   => _("Description")) 
786           ));
787   }
789 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
790 ?>