Code

Updated gotomasses
[gosa.git] / gosa-plugins / goto / addons / gotomasses / class_gotomasses.inc
index 5ac236d78553aa97ecaaca8e9aaee26e02c8a170..4d609392cc4473cd82ea269c2d9fcc07500e0c1d 100644 (file)
@@ -17,6 +17,7 @@ class gotomasses extends plugin
   var $divlist        = NULL;
 
   var $events         = array();
+  var $event_tags     = array();
 
   var $sort_by  = "Schedule";
   var $sort_dir = "down";
@@ -29,7 +30,14 @@ class gotomasses extends plugin
     /* Include config object */
     $this->config= &$config;
     $this->o_queue = new gosaSupportDaemon(TRUE,10);
-    $this->events  = DaemonEvent::get_event_types();
+    $this->events  = DaemonEvent::get_event_types( USER_EVENT | SYSTEM_EVENT);
+
+    /* Get tags that will be used in queue searches */
+    foreach($this->events['BY_CLASS'] as $evt){
+      if(isset($evt['s_Queued_Action'])){
+        $this->event_tags[] = $evt['s_Queued_Action'];
+      }
+    }
   }
 
 
@@ -209,33 +217,13 @@ class gotomasses extends plugin
     if(isset($_POST['save_event_dialog'])){
       if(is_object($this->dialog)){
         $this->dialog->save_object();
-        if($this->dialog->is_new()){
-          $header     = $this->dialog->get_schedule_action();
-          $targets    = $this->dialog->get_targets();
-          $data       = $this->dialog->save();
-
-          foreach($targets as $target){
-            $data['macaddress'] =  $target;
-            $this->o_queue->send_data($header,$target,$data,TRUE);
-            if($this->o_queue->is_error()){
-              msg_dialog::display(_("Daemon"),sprintf(_("Something went wrong while talking to the daemon: %s."),
-                    $this->o_queue->get_error()),ERROR_DIALOG);
-            }else{
-              $this->dialog = FALSE; 
-              $this->current = -1;
-            } 
-          }
+        if(!$this->o_queue->append($this->dialog)){
+          msg_dialog::display(_("Daemon"),sprintf(_("Something went wrong while talking to the daemon: %s."),
+                $this->o_queue->get_error()),ERROR_DIALOG);
         }else{
-          $id                 = $this->dialog->get_id();
-          $data               = $this->dialog->save();
-          if($this->o_queue->update_entries(array($id),$data)){
-            $this->dialog = FALSE;
-            $this->current = -1;
-          }else{
-            msg_dialog::display(_("Daemon"),sprintf(_("Something went wrong while talking to the daemon: %s."),
-              $this->o_queue->get_error()),ERROR_DIALOG);
-          }
-        }
+          $this->dialog = FALSE; 
+          $this->current = -1;
+        } 
       }
     }
 
@@ -381,12 +369,24 @@ class gotomasses extends plugin
       if(isset($this->events['BY_QUEUED_ACTION'][$task['HEADERTAG']]['s_Menu_Name'])){
         $event_type = $this->events['BY_QUEUED_ACTION'][$task['HEADERTAG']];
         $display2= $event_type['s_Menu_Name'];
+
+        if(strlen($display2) > 20){
+          $display2 = substr($display2,0,18)."...";
+        }
+
         if(isset($event_type['ListImage']) && !empty($event_type['ListImage'])){
           $display2 = $event_type['ListImage']." ".$display2;
         }
       } 
 
       $status = $task['STATUS'];
+  
+      if($status == "waiting"){
+        $status = "<img class='center' src='images/clock.png' alt=''>&nbsp;"._("Waiting");
+      }
+      if($status == "error"){
+        $status = "<img class='center' src='images/false.png' alt=''>&nbsp;"._("Error");
+      }
 
       /* Special handling for all entries that have 
           STATUS == "processing" && PROGRESS == NUMERIC
@@ -438,9 +438,9 @@ class gotomasses extends plugin
   public function update_priority($id,$type = "up")
   {
     if($type == "up"){
-      $tmp = $this->o_queue->get_queued_entries(-1,-1,"timestamp DESC");
+      $tmp = $this->o_queue->get_queued_entries($this->event_tags,-1,-1,"timestamp DESC");
     }else{
-      $tmp = $this->o_queue->get_queued_entries(-1,-1,"timestamp ASC");
+      $tmp = $this->o_queue->get_queued_entries($this->event_tags,-1,-1,"timestamp ASC");
     }
     $last = array();
     foreach($tmp as $entry){
@@ -544,8 +544,39 @@ class gotomasses extends plugin
     if(!count($ids)){
       return;
     }
-    print_red(_("Not implemented, currently."));
-    return(TRUE);
+
+    /* Entries are paused by setting the status to
+     *  something different from 'waiting'.
+     * We simply use 'paused'.
+     */
+    $data = array("status"    => "paused");
+
+    /* Detect if the ids we got are valid and
+     *  check if the status allows pausing.
+     */
+    $update_ids = array();
+    foreach($this->o_queue->get_entries_by_id($ids) as $entry){
+      if(isset($entry['STATUS']) && preg_match("/processing/",$entry['STATUS'])){
+        if(isset($entry['MACADDRESS'])){
+          $update_ids[] = $entry['MACADDRESS'];
+        }else{
+          trigger_error("No mac address found in event.");
+        }
+      }
+    }
+
+    if(class_available("DaemonEvent_faireboot")){
+      $tmp = new DaemonEvent_faireboot($this->config);
+      $tmp->add_targets($update_ids);
+      if(!$this->o_queue->append($tmp)){
+        msg_dialog::display(_("Error"), sprintf(_("Could not update queue entry: %s"),$id) , ERROR_DIALOG);
+        return(FALSE);
+      }
+    }else{
+      msg_dialog::display(_("Error"),
+          sprintf(_("The Job could not be aborted, the '%s' event class was not found."),
+            "DaemonEvent_faireboot") , ERROR_DIALOG);
+    }
   }
 
 
@@ -617,7 +648,7 @@ class gotomasses extends plugin
     /* Get entries. */ 
     $start  = $this->start; 
     $stop   = $this->range;
-    $entries = $this->o_queue->get_queued_entries($start,$stop,$sort);
+    $entries = $this->o_queue->get_queued_entries($this->event_tags,$start,$stop,$sort);
     if ($this->o_queue->is_error()){
       msg_dialog::display(_("Error"), sprintf(_("Cannot load queue entries: %s"), "<br><br>".$this->o_queue->get_error()), ERROR_DIALOG);
     }