Code

updatedimport
[gosa.git] / gosa-plugins / goto / addons / goto / class_gotomasses.inc
index 6d467d55e34e9b117b7250e2a682b6057eaeb1f4..ce00d1e933577301547fc7a029cfb9ad56295512 100644 (file)
@@ -40,11 +40,13 @@ class gotomasses extends plugin
   var $event_tags     = array();
 
   var $sort_by  = "Schedule";
-  var $sort_dir = "down";
+  var $sort_dir = "up";
   var $entries  = array();
   var $range    = 25;
   var $start    = 0;
 
+  var $recently_removed = array();
+
   function gotomasses(&$config, $dn= NULL)
   {
     /* Include config object */
@@ -57,6 +59,20 @@ class gotomasses extends plugin
     foreach($this->events['SCHEDULED'] as $evt){
       $this->event_tags[] = $evt['s_Queued_Action'];
     }
+
+    /* Load filter settings */
+    if(!session::is_set("gotomasses_filter")){
+      $gotomasses_filter = 
+        array(
+            "range" => $this->range,
+            "sort_by" => $this->sort_by,
+            "sort_dir" => $this->sort_dir);
+      session::set("gotomasses_filter",$gotomasses_filter);
+    }
+    $gotomasses_filter = session::get("gotomasses_filter");
+    foreach(array("range","sort_by","sort_dir") as $attr) {
+      $this->$attr = $gotomasses_filter[$attr];
+    }
   }
 
 
@@ -80,6 +96,7 @@ class gotomasses extends plugin
         "/^prio_down_/"   => "prio_down",
 
         "/^edit_task_/"             =>  "edit",
+        "/^log_view_/"              =>  "logview",
         "/^remove_task_/"           =>  "remove",
         "/^new_task_/"              =>  "new_task");;
 
@@ -106,6 +123,19 @@ class gotomasses extends plugin
     }
 
 
+    /************
+     * Import CSV file  
+     ************/
+    
+    if($s_action == "import_file"){
+      $this->dialog = new goto_import_file($this->config,$this);
+    }
+  
+    if(isset($_POST['import_abort'])){
+      $this->dialog = FALSE;
+    }
+
+
     /************
      * Handle Priority modifications  
      ************/
@@ -172,6 +202,21 @@ class gotomasses extends plugin
       }
     }
 
+    
+    /************
+     * LOG VIEW
+     ************/
+
+    if($s_action == "logview"){  
+      $id =  $s_entry;
+      $type = FALSE;
+      if(isset($this->entries[$id])){
+        $event = $this->entries[$s_entry];
+        $this->dialog = new goto_log_view($this->config,"",$event,$this);
+      }
+    }
+
+
     /************
      * REMOVE 
      ************/
@@ -194,7 +239,6 @@ class gotomasses extends plugin
         if(count($ids)){
           $ret = $this->o_queue->ids_exist($ids);
           $ret = $this->o_queue->get_entries_by_id($ret);
-
           $tmp = "";
           foreach($ret as $task){
 
@@ -300,14 +344,15 @@ class gotomasses extends plugin
     }
     if($this->acl_is_removeable()){
       $s.= "..|---|\n";
+      $s.= "..|<img src='images/lists/import.png' alt='' border='0' class='center'>&nbsp;"._("Import")."|import_file\n";
       $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>&nbsp;"._("Remove")."|remove_multiple\n";
     }
     if(preg_match("/w/",$this->getacl(""))){
       $s.= "..|---|\n";
-      $s.= "..|<img src='images/status_start.png' alt='' border='0' class='center'>&nbsp;"._("Resume")."|resume_all\n";
-      $s.= "..|<img src='images/status_pause.png' alt='' border='0' class='center'>&nbsp;"._("Pause")."|pause_all\n";
-      $s.= "..|<img src='images/small_error.png'  alt='' border='0' class='center'>&nbsp;"._("Abort")."|abort_process_all\n";
-      $s.= "..|<img src='images/rocket.png'       alt='' border='0' class='center'>&nbsp;"._("Execute")."|execute_process_all\n";
+      $s.= "..|<img alt='"._("Resume")."' src='images/status_start.png' border='0' class='center'>&nbsp;"._("Resume")."|resume_all\n";
+      $s.= "..|<img alt='"._("Pause")."' src='images/status_pause.png' border='0' class='center'>&nbsp;"._("Pause")."|pause_all\n";
+      $s.= "..|<img alt='"._("Abort")."' src='images/small_error.png'  border='0' class='center'>&nbsp;"._("Abort")."|abort_process_all\n";
+      $s.= "..|<img alt='"._("Execute")."' src='images/rocket.png'       border='0' class='center'>&nbsp;"._("Execute")."|execute_process_all\n";
     }
 
     $divlist->SetDropDownHeaderMenu($s);
@@ -336,11 +381,11 @@ class gotomasses extends plugin
     $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=TaskID'>"._("Task").$sort_img_2."</a>",
                                       "attach"=>"style='width:120px;'"));
     $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=Schedule'>"._("Schedule").$sort_img_3."</a>",
-                                      "attach"=>"style='width:100px;'"));
+                                      "attach"=>"style='width:140px;'"));
     $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=Action'>"._("Status").$sort_img_4."</a>",
                                       "attach"=>"style='width:80px;'"));
     $divlist->AddHeader(array("string"=>_("Action"),
-                                      "attach"=>"style='border-right:0px;width:120px;'"));
+                                      "attach"=>"style='border-right:0px;width:140px;'"));
 
 
     /* Reload the list of entries */
@@ -351,13 +396,14 @@ class gotomasses extends plugin
       $prio_actions="";
       $action = "";
 
+
       /* If WAITING add priority action
        */  
       if(in_array($task['STATUS'],array("waiting"))){
         $prio_actions.= "<input class='center' type='image' src='images/prio_increase.png' 
-          title='"._("Move up in execution queue")."' name='prio_up_".$key."'>&nbsp;";
+          title='"._("Move up")."' name='prio_up_".$key."'>&nbsp;";
         $prio_actions.= "<input class='center' type='image' src='images/prio_decrease.png' 
-          title='"._("Move down in execution queue")."' name='prio_down_".$key."'>&nbsp;";
+          title='"._("Move down")."' name='prio_down_".$key."'>&nbsp;";
       }
     
       /* If WAITING add pause action
@@ -374,44 +420,52 @@ class gotomasses extends plugin
           title='"._("Resume job")."' name='resume_".$key."'>&nbsp;";
       }
 
-      /* If PROCESSING add abort action
-       */  
-      if(in_array($task['STATUS'],array("processing")) && preg_match("/install/",$task['HEADERTAG'])){
-        $prio_actions.= "<input class='center' type='image' src='images/small_error.png' 
-          title='"._("Abort execution")."' name='abort_process_".$key."'>";
-      }
-
       /* If PAUSED or WAITING add execution action
        */  
       if(in_array($task['STATUS'],array("paused","waiting"))){
         $prio_actions.= "<input class='center' type='image' src='images/rocket.png' 
-          title='"._("Force execution now!")."' name='execute_process_".$key."'>&nbsp;";
+          title='"._("Execute now")."' name='execute_process_".$key."'>&nbsp;";
+      }
+
+      /* Add logview button, currently ever.
+       */  
+      if(TRUE){
+        $action .= "<input type='image' src='images/fai_hook.png' name='log_view_".$key."' 
+          class='center' title='"._("View logs")."' alt='"._("View logs")."'>&nbsp;";
       }
 
       /* If PAUSED or WAITING add edit action
        */  
       if(in_array($task['STATUS'],array("waiting"))){
         $action.= "<input type='image' src='images/lists/edit.png' name='edit_task_".$key."' 
-          class='center' alt='"._("Edit")."'>";
+          class='center' title='"._("Edit")."' alt='"._("Edit")."'>";
+      }
+
+      /* If PROCESSING add abort action
+       */  
+      if(in_array($task['STATUS'],array("processing")) && preg_match("/install/",$task['HEADERTAG'])){
+        $action.= "<img src='images/empty.png' alt=''>";
+        $action.= "<input class='center' type='image' src='images/small_error.png' 
+          title='"._("Abort job")."' name='abort_process_".$key."'>";
       }
 
       /* If WAITING or ERROR add remove action
        */  
       if( $this->acl_is_removeable() && in_array($task['STATUS'],array("waiting","error","processed"))){
         $action.= "<input type='image' src='images/lists/trash.png' name='remove_task_".$key."' 
-          class='center' alt='"._("Remove")."'>";
+          class='center' title='"._("Remove")."' alt='"._("Remove")."'>";
       }
       if(in_array($task['STATUS'],array("processing")) && !preg_match("/install/",$task['HEADERTAG'])){
         $action.= "<input type='image' src='images/lists/trash.png' name='remove_task_".$key."' 
-          class='center' alt='"._("Remove")."'>";
+          class='center' title='"._("Remove")."' alt='"._("Remove")."'>";
       }
 
       /* Create entry display name and tooltip */
       $color = "";
       $display = $task['MACADDRESS'];
       $tooltip = "";
-      if(isset($task['TARGETTAG'])){
-        $display = $task['TARGETTAG'];
+      if(isset($task['PLAINNAME']) && !preg_match("/none/i",$task['PLAINNAME'])){
+        $display = $task['PLAINNAME'];
         $tooltip = " title='".$task['MACADDRESS']."' ";
       }
       $display2= $task['HEADERTAG'];
@@ -462,7 +516,8 @@ class gotomasses extends plugin
         /* Real percent */
         } else {
          if (preg_match('/install/', $task['HEADERTAG'])){
-            $status = "<img src='progress.php?x=80&amp;y=13&amp;p=".$percent."' alt='".$percent."&nbsp;%'>";
+            $status = "<img src='progress.php?x=80&y=13&p=".$task['PROGRESS']."' alt=''
+                          id='progress_".preg_replace("/:/","_",$task['MACADDRESS'])."'>";
           } else {
             $status = preg_replace('/ /', '&nbsp;', _("in progress"));
           }
@@ -476,9 +531,9 @@ class gotomasses extends plugin
                       "attach" => $tooltip."style='".$color."'");
       $field1a= array("string" => $display2,
                       "attach" => "style='".$color.";width:120px;'");
-      $field2 = array("string" => date("d.m.Y H:i:s",strtotime($task['TIMESTAMP'])),"attach" => "style='".$color.";width:100px;'");
+      $field2 = array("string" => date("d.m.Y H:i:s",strtotime($task['TIMESTAMP'])),"attach" => "style='".$color.";width:140px;'");
       $field3 = array("string" => $status,"attach" => "style='".$color.";width:80px;'");
-      $field4 = array("string" => $prio_actions.$action,"attach" => "style='".$color.";text-align:right;width:120px;border-right:0px;'");
+      $field4 = array("string" => $prio_actions.$action,"attach" => "style='".$color.";text-align:right;width:140px;border-right:0px;'");
       $divlist->AddElement(array($field0,$field1,$field1a,$field2,$field3,$field4));
     }
 
@@ -642,6 +697,8 @@ class gotomasses extends plugin
       $tmp = new DaemonEvent_faireboot($this->config);
       $tmp->add_targets($update_ids);
       $tmp->set_type(TRIGGERED_EVENT);
+      $this->recently_removed = $update_ids;
+      
       if(!$this->o_queue->append($tmp)){
         msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
         return(FALSE);
@@ -732,8 +789,14 @@ class gotomasses extends plugin
     $this->entries = array();
     
     foreach($entries as $entry){
+    
+      /* Skip entries which will be removed within the next seconds */
+      if(isset($entry['MACADDRESS']) && in_array($entry['MACADDRESS'],$this->recently_removed)){
+        continue;
+      }
       $this->entries[$entry['ID']]= $entry;
     }
+    $this->recently_removed = array();
   }
 
 
@@ -760,7 +823,14 @@ class gotomasses extends plugin
     if(isset($_POST['range']) && is_numeric($_POST['range'])){
       $this->range = $_POST['range'];
     }
-    
+  
+    /* Save filter settings */ 
+    $gotomasses_filter = session::get("gotomasses_filter");
+    foreach(array("range","sort_by","sort_dir") as $attr){
+      $gotomasses_filter[$attr] = $this->$attr;
+    }
+    session::set("gotomasses_filter",$gotomasses_filter);
     /* Page changed. */
     if(isset($_GET['start'])){
       $start = $_GET['start'];