Code

b7089ea23366cb5e1c119780f8e715c2e3ac4244
[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 error"), _("You have no permission to delete this entry!"), 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         if(count($ids)){
193           $ret = $this->o_queue->ids_exist($ids);
194           $ret = $this->o_queue->get_entries_by_id($ret);
196           $tmp = "";
197           foreach($ret as $task){
199             /* Only remove WAITING or ERROR entries */
200             if(in_array($task['STATUS'],array("waiting","error"))){
201               $this->ids_to_remove[] = $task['ID'];
202               if(isset($this->events['QUEUED'][$task['HEADERTAG']])){
203                 $evt_name = $this->events['QUEUED'][$task['HEADERTAG']];
204                 $evt = $this->events['BY_CLASS'][$evt_name];
205                 $tmp.= "\n".$task['ID']." - ".$evt['s_Menu_Name']."&nbsp;".$task['MACADDRESS'];
206               }else{
207                 $tmp.= "\n".$task['ID']." - ".$task['HEADERTAG']."&nbsp;".$task['MACADDRESS'];
208               }
209             }
210           }
211           $smarty->assign("multiple", TRUE); 
212           $smarty->assign("info",sprintf(_("You are about to remove the following actions from the GOsa support Daemon: %s"),"<pre>".$tmp."</pre>"));
213           $this->current = $s_entry;
214           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
215         }
216       }
217     }
219     /* Remove specified tasks */
220     if(count($this->ids_to_remove) && isset($_POST['delete_multiple_confirm'])){
221       $this->o_queue->remove_entries($this->ids_to_remove);
222       $this->save();
223     }
225     /* Remove aborted */
226     if(isset($_POST['delete_cancel'])){
227       $this->ids_to_remove = array();;
228     }
231     /************
232      * EDIT 
233      ************/
235     /* Close dialog */
236     if(isset($_POST['save_event_dialog'])){
237       if(is_object($this->dialog)){
238         $this->dialog->save_object();
239         if(!$this->o_queue->append($this->dialog)){
240           msg_dialog::display(_("Daemon"),sprintf(_("Something went wrong while talking to the daemon: %s."),
241                 $this->o_queue->get_error()),ERROR_DIALOG);
242         }else{
243           $this->dialog = FALSE; 
244           $this->current = -1;
245         } 
246       }
247     }
250     /* Close dialog */
251     if(isset($_POST['abort_event_dialog'])){
252       $this->dialog = FALSE;
253       $this->current = -1;
254     }
256     /* Display dialogs if currently opened */
257     if(is_object($this->dialog)){
258       $this->dialog->save_object();
259       return($this->dialog->execute());
260     }
262     /************
263      * Handle Divlist 
264      ************/
266     $divlist = new MultiSelectWindow($this->config,"gotoMasses",array("gotomasses"));
267     $divlist->SetInformation(_("This menu allows you to remove and change the properties of GOsa tasks."));
268     $divlist->SetSummary(_("List of queued jobs"));
269     $divlist->EnableCloseButton(FALSE);
270     $divlist->EnableSaveButton(FALSE);
271     $divlist->SetHeadpageMode();
272     $s = ".|"._("Actions")."|\n";
273     $s.= "..|<img src='images/list_new.png' alt='' border='0' class='center'>&nbsp;"._("Create")."\n";
275     foreach($this->events['SCHEDULED'] as $name =>  $event){
276       $s.= "...|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|add_event_".$name."\n";
277     }
278     if($this->acl_is_removeable()){
279       $s.= "..|---|\n";
280       $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>&nbsp;"._("Remove")."|remove_multiple\n";
281     }
282     if(preg_match("/w/",$this->getacl(""))){
283       $s.= "..|---|\n";
284       $s.= "..|<img src='images/status_start.png' alt='' border='0' class='center'>&nbsp;"._("Resume")."|resume_all\n";
285       $s.= "..|<img src='images/status_pause.png' alt='' border='0' class='center'>&nbsp;"._("Pause")."|pause_all\n";
286       $s.= "..|<img src='images/small_error.png'  alt='' border='0' class='center'>&nbsp;"._("Abort")."|abort_process_all\n";
287       $s.= "..|<img src='images/rocket.png'       alt='' border='0' class='center'>&nbsp;"._("Execute")."|execute_process_all\n";
288     }
290     $divlist->SetDropDownHeaderMenu($s);
292     if($this->sort_dir == "up"){
293       $sort_img = "<img src='images/sort_up.png' alt='/\' border=0>";
294     }else{
295       $sort_img = "<img src='images/sort_down.png' alt='\/' border=0>";
296     }
298     if($this->sort_by == "TargetName"){ $sort_img_1 = $sort_img; } else { $sort_img_1 = "" ;}
299     if($this->sort_by == "TaskID"){ $sort_img_2 = $sort_img; } else { $sort_img_2 = "" ;}
300     if($this->sort_by == "Schedule"){ $sort_img_3 = $sort_img; } else { $sort_img_3 = "" ;}
301     if($this->sort_by == "Action"){ $sort_img_4 = $sort_img; } else { $sort_img_4 = "" ;}
303     /* Create divlist */
304     $divlist->SetListHeader("<input type='image' src='images/list_reload.png' title='"._("Reload")."'>");
306     $plug  = $_GET['plug'];
307     $chk = "<input type='checkbox' id='select_all' name='select_all'
308                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
310     /* set Page header */
311     $divlist->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
312     $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=TargetName'>"._("Target").$sort_img_1."</a>"));
313     $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=TaskID'>"._("Task").$sort_img_2."</a>",
314                                       "attach"=>"style='width:120px;'"));
315     $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=Schedule'>"._("Schedule").$sort_img_3."</a>",
316                                       "attach"=>"style='width:100px;'"));
317     $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=Action'>"._("Status").$sort_img_4."</a>",
318                                       "attach"=>"style='width:80px;'"));
319     $divlist->AddHeader(array("string"=>_("Action"),
320                                       "attach"=>"style='border-right:0px;width:120px;'"));
323     /* Reload the list of entries */
324     $this->reload();
326     foreach($this->entries as $key => $task){
328       $prio_actions="";
329       $action = "";
331       /* If WAITING add priority action
332        */  
333       if(in_array($task['STATUS'],array("waiting"))){
334         $prio_actions.= "<input class='center' type='image' src='images/prio_increase.png' 
335           title='"._("Move up in execution queue")."' name='prio_up_".$key."'>&nbsp;";
336         $prio_actions.= "<input class='center' type='image' src='images/prio_decrease.png' 
337           title='"._("Move down in execution queue")."' name='prio_down_".$key."'>&nbsp;";
338       }
339     
340       /* If WAITING add pause action
341        */  
342       if(in_array($task['STATUS'],array("waiting"))){
343         $prio_actions.= "<input class='center' type='image' src='images/status_pause.png' 
344           title='"._("Pause job")."' name='pause_".$key."'>&nbsp;";
345       }
347       /* If PAUSED add resume action
348        */  
349       if(in_array($task['STATUS'],array("paused"))){
350         $prio_actions.= "<input class='center' type='image' src='images/status_start.png' 
351           title='"._("Resume job")."' name='resume_".$key."'>&nbsp;";
352       }
354       /* If PROCESSING add abort action
355        */  
356       if(in_array($task['STATUS'],array("processing"))){
357         $prio_actions.= "<input class='center' type='image' src='images/small_error.png' 
358           title='"._("Abort execution")."' name='abort_process_".$key."'>";
359       }
361       /* If PAUSED or WAITING add execution action
362        */  
363       if(in_array($task['STATUS'],array("paused","waiting"))){
364         $prio_actions.= "<input class='center' type='image' src='images/rocket.png' 
365           title='"._("Force execution now!")."' name='execute_process_".$key."'>&nbsp;";
366       }
368       /* If PAUSED or WAITING add edit action
369        */  
370       if(in_array($task['STATUS'],array("waiting"))){
371         $action.= "<input type='image' src='images/edit.png' name='edit_task_".$key."' 
372           class='center' alt='"._("Edit")."'>";
373       }
375       /* If WAITING or ERROR add remove action
376        */  
377       if( $this->acl_is_removeable() && in_array($task['STATUS'],array("waiting","error"))){
378         $action.= "<input type='image' src='images/edittrash.png' name='remove_task_".$key."' 
379           class='center' alt='"._("Remove")."'>";
380       }
382       $color = "";
383       $display = $task['MACADDRESS'];
384       $display2= $task['HEADERTAG'];
385      
386       /* Check if this event exists as Daemon class 
387        * In this case, display a more accurate entry.
388        */ 
389       if(isset($this->events['QUEUED'][$task['HEADERTAG']])){
390         $evt_name   = $this->events['QUEUED'][$task['HEADERTAG']];
391         $event_type = $this->events['BY_CLASS'][$evt_name];
392         $display2   = $event_type['s_Menu_Name'];
394         if(strlen($display2) > 20){
395           $display2 = substr($display2,0,18)."...";
396         }
398         if(isset($event_type['ListImage']) && !empty($event_type['ListImage'])){
399           $display2 = $event_type['ListImage']."&nbsp;".$display2;
400         }
401       } 
403       $status = $task['STATUS'];
404   
405       if($status == "waiting"){
406         $status = "<img class='center' src='images/clock.png' alt=''>&nbsp;"._("Waiting");
407       }
408       if($status == "error"){
409         $status = "<img class='center' src='images/false.png' alt=''>&nbsp;"._("Error");
410       }
412       /* Special handling for all entries that have 
413           STATUS == "processing" && PROGRESS == NUMERIC
414        */
415       if($status == "processing" && isset($task['PROGRESS'])){
416         $percent = $task['PROGRESS'];
417         $status = "<img src='progress.php?x=80&amp;y=13&amp;p=".$percent."' alt='".$percent."&nbsp;%'>";
418       }
421       /* Create each field */
422       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$task['ID']."' name='item_selected_".$key."'>" ,
423                       "attach" => "style='width:20px;".$color."'");
424       $field1 = array("string" => $display,
425                       "attach" => "style='".$color."'");
426       $field1a= array("string" => $display2,
427                       "attach" => "style='".$color.";width:120px;'");
428       $field2 = array("string" => date("d.m.Y H:i:s",strtotime($task['TIMESTAMP'])),"attach" => "style='".$color.";width:100px;'");
429       $field3 = array("string" => $status,"attach" => "style='".$color.";width:80px;'");
430       $field4 = array("string" => $prio_actions.$action,"attach" => "style='".$color.";text-align:right;width:120px;border-right:0px;'");
431       $divlist->AddElement(array($field0,$field1,$field1a,$field2,$field3,$field4));
432     }
434     $smarty = get_smarty();
435     $smarty->assign("events",$this->events);
436     $smarty->assign("start",$this->start);
437     $smarty->assign("start_real", ($this->start + 1));
438     $smarty->assign("ranges", array("10" => "10",
439                                     "20" => "20",
440                                     "25" => "25",
441                                     "50" => "50",
442                                     "100"=> "100",
443                                     "200"=> "200",
444                                     "9999" => "*"));
446     $count = $this->o_queue->number_of_queued_entries();
447     $smarty->assign("range_selector", range_selector($count, $this->start, $this->range,"range"));
448     $smarty->assign("range",$this->range);
449     $smarty->assign("div",$divlist->Draw());
450     return($smarty->fetch (get_template_path('gotomasses.tpl', TRUE, dirname(__FILE__))));
451   }
454   /*! \brief  Move an entry up or down in the queue, by updating its execution timestamp  
455       @param  $id     Integer  The ID of the entry which should be updated.
456       @param  $type   String   "up" / "down"
457       @return boolean TRUE in case of success else FALSE
458   */
459   public function update_priority($id,$type = "up")
460   {
461     if($type == "up"){
462       $tmp = $this->o_queue->get_queued_entries($this->event_tags,-1,-1,"timestamp DESC");
463     }else{
464       $tmp = $this->o_queue->get_queued_entries($this->event_tags,-1,-1,"timestamp ASC");
465     }
466     $last = array();
467     foreach($tmp as $entry){
468       if($entry['ID'] == $id){
469         if(count($last)){
470           $time = strtotime($last['TIMESTAMP']);
471           if($type == "up"){
472             $time ++;
473           }else{
474             $time --;
475           }
476           $time_str = date("YmdHis",$time); 
477           return($this->o_queue->update_entries(array($id),array("timestamp" => $time_str)));
478         }else{
479           return(FALSE);
480         }
481       }
482       $last = $entry;
483     }
484     return(FALSE);
485   }
488   /*! \brief  Resumes to status 'waiting'.
489    *  @return Boolean TRUE in case of success, else FALSE. 
490    */
491   private function resume_queue_entries($ids)
492   {
493     if(!count($ids)){
494       return;
495     }
497     /* Entries are resumed by setting the status to 
498      *  'waiting'
499      */
500     $data = array("status"    => "waiting");
501   
502     /* Check if given ids are valid and check if the status
503      *  allows resuming.
504      */
505     $update_ids = array();
506     foreach($this->o_queue->get_entries_by_id($ids) as $entry){
507       if(isset($entry['STATUS']) && preg_match("/paused/",$entry['STATUS'])){
508         $update_ids[] = $entry['ID'];
509       }
510     }
512     /* Tell the daemon that we have entries to update.
513      */
514     if(count($update_ids)){
515       if(!$this->o_queue->update_entries($update_ids,$data)){
516         msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
517         return(FALSE);
518       }
519     }
520     return(TRUE);
521   }
524   /*! \brief  Force queue job to be done as far as possible.
525    *  @return Boolean TRUE in case of success, else FALSE.
526    */
527   private function execute_queue_entries($ids)
528   {
529     if(!count($ids)){
530       return;
531     }
533     /* Execution is forced by updating the status to 
534      *  waiting and setting the timestamp to current time.
535      */
536     $data = array(  "timestamp" => date("YmdHis",time()), 
537                     "status"    => "waiting");
539     /* Only allow execution of paused or waiting entries 
540      */
541     $update_ids = array();
542     foreach($this->o_queue->get_entries_by_id($ids) as $entry){
543       if(in_array($entry['STATUS'],array("paused","waiting"))){
544         $update_ids[] = $entry['ID'];
545       }
546     }
548     /* Tell the daemon that we want to update some entries
549      */
550     if(count($update_ids)){
551       if(!$this->o_queue->update_entries($update_ids,$data)){
552         msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entries.")) , ERROR_DIALOG);
553         return(FALSE);
554       }
555     }
556     return(TRUE);
557   }
560   /*! \brief  Force queue job to be done as far as possible.
561    *  @return Boolean TRUE in case of success, else FALSE.
562    */
563   private function abort_queue_entries($ids)
564   {
565     if(!count($ids)){
566       return;
567     }
569     /* Entries are paused by setting the status to
570      *  something different from 'waiting'.
571      * We simply use 'paused'.
572      */
573     $data = array("status"    => "paused");
575     /* Detect if the ids we got are valid and
576      *  check if the status allows pausing.
577      */
578     $update_ids = array();
579     foreach($this->o_queue->get_entries_by_id($ids) as $entry){
580       if(isset($entry['STATUS']) && preg_match("/processing/",$entry['STATUS'])){
581         if(isset($entry['MACADDRESS'])){
582           $update_ids[] = $entry['MACADDRESS'];
583         }else{
584           trigger_error("No mac address found in event.");
585         }
586       }
587     }
589     if(class_available("DaemonEvent_faireboot")){
590       $tmp = new DaemonEvent_faireboot($this->config);
591       $tmp->add_targets($update_ids);
592       if(!$this->o_queue->append($tmp)){
593         msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
594         return(FALSE);
595       }
596     }else{
597       msg_dialog::display(_("Error"),
598           sprintf(_("The Job could not be aborted, the '%s' event class was not found."),
599             "DaemonEvent_faireboot") , ERROR_DIALOG);
600     }
601   }
604   /*! \brief Pauses the specified queue entry from execution.
605    *  @return Boolean TRUE in case of success, else FALSE. 
606    */
607   private function pause_queue_entries($ids)
608   {
609     if(!count($ids)){
610       return;
611     }
613     /* Entries are paused by setting the status to 
614      *  something different from 'waiting'.
615      * We simply use 'paused'.
616      */   
617     $data = array("status"    => "paused");
619     /* Detect if the ids we got are valid and
620      *  check if the status allows pausing.
621      */ 
622     $update_ids = array();
623     foreach($this->o_queue->get_entries_by_id($ids) as $entry){
624       if(isset($entry['STATUS']) && preg_match("/waiting/",$entry['STATUS'])){
625         $update_ids[] = $entry['ID'];
626       }
627     }
629     /* Tell the daemon that we want to update some entries
630      */
631     if(count($update_ids)){
632       if(!$this->o_queue->update_entries($update_ids,$data)){
633         msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
634         return(FALSE);
635       }
636     }
637     return(TRUE);
638   }
641   /*! \brief  Request list of queued jobs.
642    *  @return Returns an array of all queued jobs.
643    */
644   function reload()
645   {
647     /* Sort map   html-post-name => daemon-col-name
648      */
649     $map = array(
650         "QueuePosition" => "id",
651         "Action"        => "status",
652         "TaskID"        => "headertag",
653         "TargetName"    => "macaddress",
654         "Schedule"      => "timestamp");
656     /* Create sort header 
657      */
658     if(!isset($map[$this->sort_by])){
659       $sort = "id DESC";
660     }else{
661       $sort   = $map[$this->sort_by]; 
662       if($this->sort_dir == "up"){
663         $sort.= " ASC";
664       }else{
665         $sort.= " DESC";
666       }
667     }
668      
669     /* Get entries. */ 
670     $start  = $this->start; 
671     $stop   = $this->range;
672     $entries = $this->o_queue->get_queued_entries($this->event_tags,$start,$stop,$sort);
673     if ($this->o_queue->is_error()){
674       msg_dialog::display(_("Error"), sprintf(_("Cannot load queue entries: %s"), "<br><br>".$this->o_queue->get_error()), ERROR_DIALOG);
675     }
677     /* Assign entries by id.
678      */
679     $this->entries = array();
680     foreach($entries as $entry){
681       $this->entries[$entry['ID']]= $entry;
682     }
683   }
686   /*! \brief  Handle post jobs, like sorting.
687    */
688   function save_object()
689   {
690     /* Check for sorting changes 
691      */
692     $sort_vals = array("Action","QueuePosition","TargetName","Schedule","TaskID");
693     if(isset($_GET['sort']) && in_array($_GET['sort'],$sort_vals)){
694       $sort = $_GET['sort'];
695       if($this->sort_by == $sort){
696         if($this->sort_dir == "up"){
697           $this->sort_dir = "down";
698         }else{
699           $this->sort_dir = "up";
700         }
701       }
702       $this->sort_by = $sort;
703     }
705     /* Range selection used? */
706     if(isset($_POST['range']) && is_numeric($_POST['range'])){
707       $this->range = $_POST['range'];
708     }
709     
710     /* Page changed. */
711     if(isset($_GET['start'])){
712       $start = $_GET['start'];
713       if(is_numeric($start) || $start == 0){
714         $this->start = $start;
715       }
716     }
718     /* Check start stop and reset if necessary */
719     $count = $this->o_queue->number_of_queued_entries();
720     if($this->start >= $count){
721       $this->start = $count -1;
722     }
723     if($this->start < 0){
724       $this->start = 0;
725     }
726   }
729   function save()
730   {
731     // We do not save anything here.
732   }
735   /*! \brief  Return a list of all selected items.
736     @return Array   Returns an array containing all selected item ids.
737    */
738   function list_get_selected_items()
739   {
740     $ids = array();
741     foreach($_POST as $name => $value){
742       if(preg_match("/^item_selected_[0-9]*$/",$name)){
743         $id   = preg_replace("/^item_selected_/","",$name);
744         $ids[$id] = $id;
745       }
746     }
747     return($ids);
748   }
751   static function plInfo()
752   {
753     return (array(
754           "plShortName"   => _("System mass deployment"),
755           "plDescription" => _("Provide a mechanism to automatically activate a set of systems"),
756           "plSelfModify"  => FALSE,
757           "plDepends"     => array(),
758           "plPriority"    => 0,
759           "plSection"     => array("addon"),
760           "plCategory"    => array("gotomasses" => array("objectClass" => "none", "description" => _("System mass deployment"))),
761           "plProvidedAcls" => array("Comment"   => _("Description")) 
762           ));
763   }
765 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
766 ?>