Code

Updated gotomasses
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 20 Aug 2007 08:50:12 +0000 (08:50 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 20 Aug 2007 08:50:12 +0000 (08:50 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7069 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/addons/gotomasses/class_goto_task.inc
plugins/addons/gotomasses/class_gotomasses.inc
plugins/addons/gotomasses/contents.tpl
plugins/addons/gotomasses/main.inc

index 87af0b6e2ba4ed118c6227ff908c2ca2170d5d68..246dd91e0f74973d5e9754d1704a32af96320c43 100644 (file)
@@ -16,7 +16,7 @@ class goto_task extends plugin
   var $Weekday  = "*";
   var $Action   = "install";
   var $Comment  = "";
-  var $Taret    = array();
+  var $Target   = array();
 
   var $Actions  = array();
   var $OGroup   = "";
index 216e9966531a9612f7fb37643c8959b116ec2bf3..9bca37ddcc17a516fb39e49f25b5d4541d4e82d0 100644 (file)
@@ -10,23 +10,23 @@ class gotomasses extends plugin
   var $attributes= array();
   var $objectclasses= array();
 
-  /* Source file that contains the csv data */
-  var $file_to_read = "Undefined"; #Set in constructor 
+  /* Source file that contains the gotomasses data */
+  var $data_file = "Undefined"; #Set in constructor 
 
   /* Queue tasks */
   var $tasks = array();
   var $current =false;
-  var $dialog = NULL;
+  var $dialog = FALSE;
 
   function gotomasses($config, $dn= NULL)
   {
     /* Define source file */
-    $this->file_to_read = CONFIG_DIR."/gotomasses_machines";
+    $this->data_file = CONFIG_DIR."/gotomasses_machines";
   
     /* Include config object */
     $this->config= $config;
 
-    $this->load_csv_data();
+    $this->load_gotomasses_data();
   }
 
 
@@ -38,7 +38,7 @@ class gotomasses extends plugin
      ************/
 
     $s_entry = $s_action = "";
-    $arr = array("/^edit_/"=>"edit","/^remove_/"=>"remove");
+    $arr = array("/^edit_task_/"=>"edit","/^remove_task_/"=>"remove","/^new_task_/"=>"new_task");
     foreach($arr as $regex => $action){
       foreach($_POST as $name => $value){
         if(preg_match($regex,$name)){
@@ -64,14 +64,21 @@ class gotomasses extends plugin
       $this->dialog = new goto_task($this->config,$this,$entry);
       $this->current = $s_entry;
     }
+
+    /* New entry */
+    if($s_action== "new_task"){
+      $this->dialog = new goto_task($this->config,$this);
+      $this->current = -1;
+    }
   
     /* Close dialog */
     if(isset($_POST['close_goto_task'])){
-      $this->dialog = NULL;
+      $this->dialog = FALSE;
+      $this->current = -1;
     }
 
     /* Close dialog */
-    if(isset($_POST['save_goto_task'])){
+    if(isset($_POST['save_goto_task']) && is_object($this->dialog)){
       $this->dialog->save_object();
       $msgs = $this->dialog->check();
       if(count($msgs)){
@@ -79,8 +86,13 @@ class gotomasses extends plugin
           print_red($msg);  
         }
       }else{
-        $this->tasks[$this->current] = $this->dialog->save();
-        $this->dialog = NULL;
+        if(isset($this->tasks[$this->current]) && $this->current != -1){
+          $this->tasks[$this->current] = $this->dialog->save();
+        }else{
+          $this->tasks[] = $this->dialog->save();
+        }
+        $this->dialog = FALSE;
+        $this->current = -1;
       }
     }
  
@@ -97,34 +109,40 @@ class gotomasses extends plugin
 
     $smarty = get_smarty();
     $plug = $_GET['plug'];
-    $divlist = new divlist("gotomasses");
-    $divlist->SetWidth("100%");
-    $divlist->SetHeader(array(  array("string"=>"<a href='?plug=".$plug."&amp;sort=object'>"._("Target")."</a>"),
-                                array("string"=>"<a href='?plug=".$plug."&amp;sort=schedule'>"._("Schedule")."</a>",
-                                      "attach"=>"style='width:150px;'"),
-                                array("string"=>"<a href='?plug=".$plug."&amp;sort=action'>"._("Type")."</a>",
-                                      "attach"=>"style='width:50px;'"),
-                                array("string"=>_("Action"),
-                                      "attach"=>"style='border-right:0px;width:50px;'")));
-
-   
+    $divlist = new MultiSelectWindow($this->config,"GotoMasses","gotomassses");
+    $divlist->SetSummary(_("Gotomasses tasks"));
+    $divlist->SetHeadpageMode();
+    $divlist->EnableCloseButton(FALSE);
+    $divlist->EnableSaveButton(FALSE);
+    $divlist->SetInformation(_("This menu allows you to add, remove and change the properties of gotomasses tasks."));
+    
+    $header = "<div style='padding:5px'>
+                <input type='image' src='images/gotomasses_new_task.png' name='new_task' class='center'>
+               </div>";
+  
+    $divlist->SetListHeader($header);
+    $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=object'>"._("Target")."</a>"));
+    $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=schedule'>"._("Schedule")."</a>",
+                                      "attach"=>"style='width:100px;'"));
+    $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&amp;sort=action'>"._("Type")."</a>",
+                                      "attach"=>"style='width:60px;'"));
+    $divlist->AddHeader(array("string"=>_("Action"),
+                                      "attach"=>"style='border-right:0px;width:40px;'"));
     foreach($this->tasks as $key => $task){
   
-      $action = "<input type='image' src='images/edit.png' name='edit_".$key."' class='center' alt='"._("Edit")."'>";
-      $action.= "<input type='image' src='images/edittrash.png' name='remove_".$key."' class='center' alt='"._("Reomve")."'>";
+      $action = "<input type='image' src='images/edit.png' name='edit_task_".$key."' class='center' alt='"._("Edit")."'>";
+      $action.= "<input type='image' src='images/edittrash.png' name='remove_task_".$key."' class='center' alt='"._("Reomve")."'>";
 
-      $field1 = array("string" => $this->target_to_string($task));
-      $field2 = array("string" => $this->time_to_string($task));
-      $field3 = array("string" => $this->action_to_string($task));
-      $field4 = array("string" => $action,"attach" => "style='border-right:0px;'");
+      $field1 = array("string" => "<div style='width:100%;overflow:hidden;'><nobr>".$this->target_to_string($task)."</nobr></div>");
+      $field2 = array("string" => $this->time_to_string($task),"attach" => "style='width:100px;'");
+      $field3 = array("string" => $this->action_to_string($task),"attach" => "style='width:60px;'");
+      $field4 = array("string" => $action,"attach" => "style='width:40px;border-right:0px;'");
       
  
-      $divlist->AddEntry(array($field1,$field2,$field3,$field4));
+      $divlist->AddElement(array($field1,$field2,$field3,$field4));
     }
  
-    $smarty->assign("divlist" , $divlist->DrawList());
-    $smarty->assign("contents_modified" , TRUE );
-    return ($smarty->fetch (get_template_path('contents.tpl', TRUE)));
+    return($divlist->Draw());
   }
 
   
@@ -157,19 +175,19 @@ class gotomasses extends plugin
   }
 
   
-  function load_csv_data()
+  function load_gotomasses_data()
   {
     $ui = get_userinfo();
 
     
-    if(!file_exists($this->file_to_read) || !is_readable($this->file_to_read)){
-      print_red(sprintf(_("Can't locate or read csv storage file '%s'."),$this->file_to_read));
+    if(!file_exists($this->data_file) || !is_readable($this->data_file)){
+      print_red(sprintf(_("Can't locate or read gotomasses storage file '%s'."),$this->data_file));
       return(FALSE);
     }
 
-    $fp = @fopen($this->file_to_read,"r");
+    $fp = @fopen($this->data_file,"r");
     if(!$fp){
-      print_red(sprintf(_("Can't read csv storage file '%s'."),$this->file_to_read));
+      print_red(sprintf(_("Can't read gotomasses storage file '%s'."),$this->data_file));
       return(FALSE);
     }
 
@@ -224,8 +242,44 @@ class gotomasses extends plugin
   }
 
 
-  function save_csv_data()
+  function save_gotomasses_data()
   {
+    $str = "#GOsa generated file, please just modify if you realy know what you do.";
+  
+    foreach($this->tasks as $task){
+      $str .= "\n#".trim($task['Comment']);
+
+      $str .= "\n";
+      $str .= str_pad($task['Minute'] ,5," ")." ";
+      $str .= str_pad($task['Hour']   ,5," ")." ";
+      $str .= str_pad($task['Day']    ,5," ")." ";
+      $str .= str_pad($task['Month']  ,5," ")." ";
+      $str .= str_pad($task['Weekday'],5," ")." ";
+      $str .= str_pad($task['Action'] ,5," ")." ";
+      $str .= str_pad($task['OGroup'] ,5," ")." ";
+    
+      foreach($task['Target'] as $target){
+        $str .= $target.",";
+      }
+      $str = preg_replace("/,$/","",$str);
+    }
+
+    $ui = get_userinfo();
+
+    if(!file_exists($this->data_file) || !is_writeable($this->data_file)){
+      print_red(sprintf(_("Can't locate or write gotomasses storage file '%s'."),$this->data_file));
+      return(FALSE);
+    }
+
+    $fp = @fopen($this->data_file,"w");
+    if(!$fp){
+      print_red(sprintf(_("Can't read gotomasses storage file '%s'."),$this->data_file));
+      return(FALSE);
+    }
+
+    $str .= "\n";
+    fwrite($fp,$str);
+    fclose($fp);
   }
 
 
@@ -249,6 +303,12 @@ class gotomasses extends plugin
     return($ret); 
   }
 
+  
+  function save()
+  {
+    $this->save_gotomasses_data();
+  }
+
 
   function get_actions()
   {
index 97eeea1b5bf783471ec43ee8e6fcb821a3b6adab..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,19 +0,0 @@
-<h2>
-       <img class="center" alt="" src="images/fai_script.png" align="middle" title="{t}Objects{/t}">&nbsp;
-       {t}List of scheduled tasts{/t}
-</h2>
-<table width="100%" summary="" style="border:1px solid #B0B0B0; " cellspacing=0 cellpadding=0>
-       <tr>
-               <td>
-                       {$divlist}
-               </td>
-       </tr>
-</table>
-
-
-<input type='hidden' name='gotomasses' value='1'>
-
-<!-- Display a warning if the content was modified, but not saved yet -->
-{if !$contents_modified}
-       <input type='hidden' name='ignore' value='1'>
-{/if}
index 3ce99f860836c05153576fe56817b7fd3335e193..d564f1620a719c265dbdafcce47dae70ed122d61 100644 (file)
@@ -21,7 +21,7 @@
 if (!$remove_lock){
 
        /* Create gotomasses object on demand */
-       if (!isset($_SESSION['gotomasses']) || (isset($_GET['reset']) && $_GET['reset'] == 1)){
+       if (!isset($_SESSION['gotomasses']) || (isset($_GET['reset']) && $_GET['reset'] == 1) || isset($_POST['reload_gotomass_data'])){
                $_SESSION['gotomasses']= new gotomasses ($config);
                $_SESSION['gotomasses']->set_acl_category("gotomasses");
 
@@ -42,11 +42,11 @@ if (!$remove_lock){
 
        /* Execute formular */
        $display= $gotomasses->save_object();
+       if(isset($_POST['save_gotomass_changes'])){
+               $gotomasses->save();
+       }
        $display= $gotomasses->execute ();
 
-/* Ignore plugin changes is handled by the gotomasses class itself */
-#      $display.= "<input type=\"hidden\" name=\"ignore\">\n";
-
        /* Page header*/
        $display= print_header(get_template_path('images/system.png'), _("System mass deployment")).$display;