Code

Skip action if nothing is selected.
[gosa.git] / gosa-core / plugins / addons / gotomasses / class_gotomasses.inc
index 67898bb9b3454ed1d74a5961839c31a051d05b1c..87753c53fb942758a89211b9becf80f40146c3aa 100644 (file)
@@ -102,19 +102,20 @@ class gotomasses extends plugin
         }else{
           $ids = $this->list_get_selected_items();
         }
-
-        $this->ids_to_remove = $ids;
-        $ret = $this->o_queue->ids_exist($this->ids_to_remove);
-        $ret = $this->o_queue->get_entries_by_id($ret);
-
-        $tmp = "";
-        foreach($ret as $task){
-          $tmp.= "\n".$task['ID']." - ".$task['HEADERTAG']." ".$task['MACADDRESS'];
+        if(count($ids)){
+          $this->ids_to_remove = $ids;
+          $ret = $this->o_queue->ids_exist($this->ids_to_remove);
+          $ret = $this->o_queue->get_entries_by_id($ret);
+
+          $tmp = "";
+          foreach($ret as $task){
+            $tmp.= "\n".$task['ID']." - ".$task['HEADERTAG']." ".$task['MACADDRESS'];
+          }
+          $smarty->assign("multiple", TRUE); 
+          $smarty->assign("info",sprintf(_("Your are about to delete the following tasks: %s"),"<pre>".$tmp."</pre>"));
+          $this->current = $s_entry;
+          return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
         }
-        $smarty->assign("multiple", TRUE); 
-        $smarty->assign("info",sprintf(_("Your are about to delete the following tasks: %s"),"<pre>".$tmp."</pre>"));
-        $this->current = $s_entry;
-        return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
       }
     }
 
@@ -226,6 +227,10 @@ class gotomasses extends plugin
    */
   private function start_queue_entries($ids)
   {
+    if(!count($ids)){
+      return;
+    }
+  
     $data = array("timestamp" => date("YmdHis"),
                   "status"    => "-");
     if(!$this->o_queue->update_entries($ids,$data)){
@@ -241,6 +246,9 @@ class gotomasses extends plugin
    */
   private function stop_queue_entries($ids)
   {
+    if(!count($ids)){
+      return;
+    }
     $data = array("timestamp" => "20490101010101",
                   "status"    => "Stoppped");
     if(!$this->o_queue->update_entries($ids,$data)){
@@ -256,38 +264,38 @@ class gotomasses extends plugin
    */
   function get_queued_entries()
   {
-    $start  = $this->range * $this->start; 
-    $stop   = $start + $this->range; 
-    $entries = $this->o_queue->get_queued_entries($start,$stop);
+    $map = array(
+        "QueuePosition" => "id",
+        "Action"        => "status",
+        "TaskID"        => "headertag",
+        "TargetName"    => "macaddress",
+        "Schedule"      => "timestamp");
+
+    if(!isset($map[$this->sort_by])){
+      $sort = "id DESC";
+    }else{
+      $sort   = $map[$this->sort_by]; 
+      if($this->sort_dir == "up"){
+        $sort.= " ASC";
+      }else{
+        $sort.= " DESC";
+      }
+    }
+      
+    $start  = $this->start; 
+    $stop   = $this->range;
+    $entries = $this->o_queue->get_queued_entries($start,$stop,$sort);
     if(!is_array($entries) || !isset($entries['XML']) || !is_array($entries['XML'])){
       msg_dialog::display(_("Error"), sprintf(_("Cannot load queue entries: %s"), "<br><br>".$this->o_queue->get_error()), ERROR_DIALOG);
       return(array());
     }
 
-    $tasks = array();
     $ret = array();
     foreach($entries['XML'] as $entry){
       $task = $entry['ID']; 
       $ret[]= $entry;
     }
-    $map = array("QueuePosition" => "ID",
-        "Action"        => "STATUS",
-        "TaskID"        => "HEADERTAG",
-        "TargetName"    => "MACADDRESS",
-        "Schedule"      => "TIMESTAMP");
-    $sort_tmp = array();
-    foreach($ret as $entry_id => $entry){
-      $sort_tmp[$entry_id] = $entry[$map[$this->sort_by]];
-    } 
-    natcasesort($sort_tmp);
-    $return = array();
-    foreach($sort_tmp as $entry_id => $value){
-      $return[] = $ret[$entry_id];
-    } 
-    if($this->sort_dir != "up"){
-      $return = array_reverse($return);
-    } 
-    return($return);
+    return($ret);
   }
 
 
@@ -313,10 +321,19 @@ class gotomasses extends plugin
     }
     if(isset($_GET['start'])){
       $start = $_GET['start'];
-      if(is_numeric($start) && $start > 0){
+      if(is_numeric($start) || $start == 0){
         $this->start = $start;
       }
     }
+
+    /* Check start stop and reset if necessary */
+    $count = $this->o_queue->number_of_queued_entries();
+    if($this->start >= $count){
+      $this->start = $count -1;
+    }
+    if($this->start < 0){
+      $this->start = 0;
+    }
   }