Code

Fixed template loading
[gosa.git] / gosa-plugins / goto / addons / goto / class_gotomasses.inc
index 941617d06b461ecee485992ceefd1bcbd0610b90..dcc2e935057ad4a9b1638ce469b7335977cb3ec3 100644 (file)
@@ -23,8 +23,8 @@
 class gotomasses extends plugin
 {
   /* Definitions */
-  var $plHeadline     = "System deployment";
-  var $plDescription  = "This does something";
+  var $plHeadline     = "Deployment status";
+  var $plDescription  = "System deployment status";
 
   /* attribute list for save action */
   var $attributes= array();
@@ -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 
      ************/
@@ -180,7 +225,7 @@ class gotomasses extends plugin
     if($s_action == "remove_multiple" || $s_action == "remove"){
 
       if(!$this->acl_is_removeable()){
-        msg_dialog::display(_("Permission error"), _("You have no permission to delete this entry!"), ERROR_DIALOG);
+        msg_dialog::display(_("Permission"), msgPool::permDelete(), ERROR_DIALOG);
       }else{
 
         if($s_action == "remove"){
@@ -189,15 +234,17 @@ class gotomasses extends plugin
           $ids = $this->list_get_selected_items();
         }
 
+        $this->ids_to_remove = array();
+
         if(count($ids)){
           $ret = $this->o_queue->ids_exist($ids);
           $ret = $this->o_queue->get_entries_by_id($ret);
-
           $tmp = "";
           foreach($ret as $task){
 
             /* Only remove WAITING or ERROR entries */
-            if(in_array($task['STATUS'],array("waiting","error"))){
+            if(in_array($task['STATUS'],array("waiting","error","processed")) || 
+               ($task['STATUS'] == "processing" && !preg_match("/install/",$task['HEADERTAG'])) ){
               $this->ids_to_remove[] = $task['ID'];
               if(isset($this->events['QUEUED'][$task['HEADERTAG']])){
                 $evt_name = $this->events['QUEUED'][$task['HEADERTAG']];
@@ -209,7 +256,7 @@ class gotomasses extends plugin
             }
           }
           $smarty->assign("multiple", TRUE); 
-          $smarty->assign("info",sprintf(_("You are about to remove the following actions from the GOsa support Daemon: %s"),"<pre>".$tmp."</pre>"));
+          $smarty->assign("info",msgPool::deleteInfo("<pre>".$tmp."</pre>"));
           $this->current = $s_entry;
           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
         }
@@ -218,6 +265,27 @@ class gotomasses extends plugin
 
     /* Remove specified tasks */
     if(count($this->ids_to_remove) && isset($_POST['delete_multiple_confirm'])){
+
+      /* Reboot hosts with not yet startet installations and timestamps in the past 
+       */
+      timezone::get_default_timezone();
+      foreach($this->ids_to_remove as $id){
+        $entry = $this->o_queue->get_entries_by_id(array($id));
+        if(isset($entry['ANSWER1'])){
+          $entry = $entry['ANSWER1'];
+          if( $entry['STATUS'] == "waiting" && 
+              $entry['HEADERTAG'] == "trigger_action_reinstall"){
+            $evt = new DaemonEvent_reinstall($this->config,$entry);
+            if($evt->get_timestamp(FALSE)  < time()){
+              $r_evt = new DaemonEvent_localboot($this->config);
+              $r_evt->add_targets(array($entry['MACADDRESS']));
+              $r_evt->set_type(TRIGGERED_EVENT);
+              $this->o_queue->append($r_evt);
+            }
+          }
+        }
+      }
+
       $this->o_queue->remove_entries($this->ids_to_remove);
       $this->save();
     }
@@ -237,8 +305,7 @@ class gotomasses extends plugin
       if(is_object($this->dialog)){
         $this->dialog->save_object();
         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);
+          msg_dialog::display(_("Service infrastructure"),msgPool::siError($this->o_queue->get_error()),ERROR_DIALOG);
         }else{
           $this->dialog = FALSE; 
           $this->current = -1;
@@ -270,29 +337,30 @@ class gotomasses extends plugin
     $divlist->EnableSaveButton(FALSE);
     $divlist->SetHeadpageMode();
     $s = ".|"._("Actions")."|\n";
-    $s.= "..|<img src='images/list_new.png' alt='' border='0' class='center'>&nbsp;"._("Create")."\n";
+    $s.= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>&nbsp;"._("Create")."\n";
 
     foreach($this->events['SCHEDULED'] as $name =>  $event){
       $s.= "...|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|add_event_".$name."\n";
     }
     if($this->acl_is_removeable()){
       $s.= "..|---|\n";
-      $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>&nbsp;"._("Remove")."|remove_multiple\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);
 
     if($this->sort_dir == "up"){
-      $sort_img = "<img src='images/sort_up.png' alt='/\' border=0>";
+      $sort_img = "<img src='images/lists/sort-up.png' alt='/\' border=0>";
     }else{
-      $sort_img = "<img src='images/sort_down.png' alt='\/' border=0>";
+      $sort_img = "<img src='images/lists/sort-down.png' alt='\/' border=0>";
     }
 
     if($this->sort_by == "TargetName"){ $sort_img_1 = $sort_img; } else { $sort_img_1 = "" ;}
@@ -301,7 +369,7 @@ class gotomasses extends plugin
     if($this->sort_by == "Action"){ $sort_img_4 = $sort_img; } else { $sort_img_4 = "" ;}
 
     /* Create divlist */
-    $divlist->SetListHeader("<input type='image' src='images/list_reload.png' title='"._("Reload")."'>");
+    $divlist->SetListHeader("<input type='image' src='images/lists/reload.png' title='"._("Reload")."'>");
 
     $plug  = $_GET['plug'];
     $chk = "<input type='checkbox' id='select_all' name='select_all'
@@ -313,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 */
@@ -328,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
@@ -351,36 +420,54 @@ class gotomasses extends plugin
           title='"._("Resume job")."' name='resume_".$key."'>&nbsp;";
       }
 
-      /* If PROCESSING add abort action
-       */  
-      if(in_array($task['STATUS'],array("processing"))){
-        $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='"._("Log view")."'>&nbsp;";
       }
 
       /* If PAUSED or WAITING add edit action
        */  
       if(in_array($task['STATUS'],array("waiting"))){
-        $action.= "<input type='image' src='images/edit.png' name='edit_task_".$key."' 
-          class='center' alt='"._("Edit")."'>";
+        $action.= "<input type='image' src='images/lists/edit.png' name='edit_task_".$key."' 
+          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"))){
-        $action.= "<input type='image' src='images/edittrash.png' name='remove_task_".$key."' 
-          class='center' alt='"._("Remove")."'>";
+      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' 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' title='"._("Remove")."' alt='"._("Remove")."'>";
       }
 
+      /* Create entry display name and tooltip */
       $color = "";
       $display = $task['MACADDRESS'];
+      $tooltip = "";
+      if(isset($task['PLAINNAME']) && !preg_match("/none/i",$task['PLAINNAME'])){
+        $display = $task['PLAINNAME'];
+        $tooltip = " title='".$task['MACADDRESS']."' ";
+      }
       $display2= $task['HEADERTAG'];
      
       /* Check if this event exists as Daemon class 
@@ -408,26 +495,45 @@ class gotomasses extends plugin
       if($status == "error"){
         $status = "<img class='center' src='images/false.png' alt=''>&nbsp;"._("Error");
       }
+      if($status == "processed"){
+        $status = "<img class='center' src='images/true.png' alt=''>&nbsp;"._("Processed");
+      }
 
       /* Special handling for all entries that have 
           STATUS == "processing" && PROGRESS == NUMERIC
        */
       if($status == "processing" && isset($task['PROGRESS'])){
         $percent = $task['PROGRESS'];
-        $status = "<img src='progress.php?x=80&amp;y=13&amp;p=".$percent."' alt='".$percent."&nbsp;%'>";
-      }
 
+        /* Show activation? */
+        if ($percent == "goto-activation"){
+          $status = "<img class='center' src='images/lists/off.png' alt=''>&nbsp;"._("Locked");
+
+        /* Show hardware detect? */
+        } elseif ($percent == "goto-hardware-detection") {
+          $status = "<img class='center' src='images/hardware.png' alt=''>&nbsp;"._("Detection");
+
+        /* Real percent */
+        } else {
+         if (preg_match('/install/', $task['HEADERTAG'])){
+            $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"));
+          }
+        }
+      }
 
       /* Create each field */
       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$task['ID']."' name='item_selected_".$key."'>" ,
                       "attach" => "style='width:20px;".$color."'");
       $field1 = array("string" => $display,
-                      "attach" => "style='".$color."'");
+                      "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));
     }
 
@@ -443,8 +549,9 @@ class gotomasses extends plugin
                                     "200"=> "200",
                                     "9999" => "*"));
 
-    $count = $this->o_queue->number_of_queued_entries();
-    $smarty->assign("range_selector", range_selector($count, $this->start, $this->range,"range"));
+    $count = $this->o_queue->number_of_queued_entries($this->event_tags);
+    if(!$count) $count = $this->range;
+    $divlist->SetListFooter(range_selector($count, $this->start, $this->range,"range"));
     $smarty->assign("range",$this->range);
     $smarty->assign("div",$divlist->Draw());
     return($smarty->fetch (get_template_path('gotomasses.tpl', TRUE, dirname(__FILE__))));
@@ -590,13 +697,15 @@ 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);
       }
     }else{
       msg_dialog::display(_("Error"),
-          sprintf(_("The Job could not be aborted, the '%s' event class was not found."),
+          sprintf(_("The job could not be aborted, the required class '%s' was not found."),
             "DaemonEvent_faireboot") , ERROR_DIALOG);
     }
   }
@@ -678,9 +787,16 @@ class gotomasses extends plugin
     /* Assign entries by id.
      */
     $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();
   }
 
 
@@ -707,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'];
@@ -717,7 +840,7 @@ class gotomasses extends plugin
     }
 
     /* Check start stop and reset if necessary */
-    $count = $this->o_queue->number_of_queued_entries();
+    $count = $this->o_queue->number_of_queued_entries($this->event_tags);
     if($this->start >= $count){
       $this->start = $count -1;
     }