Code

Fixed list handling
[gosa.git] / plugins / addons / gotomasses / class_gotomasses.inc
index 8b32876efd6969dfddb06ef190e8289d8179bb5e..1dc2d9fc08ce739ee5e329f988d54173bed3d388 100644 (file)
@@ -18,14 +18,20 @@ class gotomasses extends plugin
   var $current =false;
   var $dialog = FALSE;
   var $ids_to_remove = array();
+  var $divlist = NULL;
 
-  function gotomasses($config, $dn= NULL)
+  function gotomasses(&$config, $dn= NULL)
   {
+    /* Include config object */
+    $this->config= &$config;
+
     /* Define source file */
     $this->data_file = CONFIG_DIR."/gotomasses_machines";
-  
-    /* Include config object */
-    $this->config= $config;
+    $file = $this->config->search("gotomasses", "STORAGE_FILE",array('menu'));
+    if(!empty($file)){
+      $this->data_file = $file;
+    }
+    $this->divlist = new divListMasses($this->config,$this);
     $this->load_gotomasses_data();
   }
 
@@ -67,9 +73,13 @@ class gotomasses extends plugin
       }else{
         $this->ids_to_remove = $this->list_get_selected_items();
         $tmp = "";
-        foreach($this->ids_to_remove as $id){
-          $task = $this->tasks[$id];
-          $tmp.= "\n".$this->target_to_string($task);
+        foreach($this->ids_to_remove as $key => $id){
+          if(isset($this->tasks[$id])){
+            $task = $this->tasks[$id];
+            $tmp.= "\n".$this->target_to_string($task);
+          }else{
+            unset($this->ids_to_remove[$key]);
+          }
         }
         $smarty->assign("multiple", TRUE); 
         $smarty->assign("info",sprintf(_("Your are about to delete the following tasks: %s"),"<pre>".$tmp."</pre>"));
@@ -166,72 +176,9 @@ class gotomasses extends plugin
      * Handle Divlist 
      ************/
 
-    $plug = $_GET['plug'];
-    $divlist = new MultiSelectWindow($this->config,"GotoMasses","gotomassses");
-    $divlist->SetSummary(_("List of system deployment tasks"));
-    $divlist->SetHeadpageMode();
-    $divlist->EnableCloseButton(FALSE);
-    $divlist->EnableSaveButton(FALSE);
-    $divlist->SetInformation(_("This menu allows you to add, remove and change the properties of system deployment tasks."));
-    /* Display add button if allowed */ 
-    $header = "<div style='padding:5px'>";
-    if($this->acl_is_createable()){ 
-      $header .= "<input type='image' src='images/gotomasses_new_task.png' name='new_task' class='center'>&nbsp;";
-    }
-
-    /* Display add button if allowed */ 
-    if($this->acl_is_removeable()){ 
-      $header .= "<input type='image' src='images/edittrash.png' name='remove_multiple_task' class='center'>&nbsp;";
-    }
-    $header .= "</div>";
-
-    /* Get Permissions */ 
-    $ui = get_userinfo();
-    $acls = $this->getacl("");
-    foreach($ui->get_module_departments("gotomasses") as $dep){
-      $acls .= $ui->get_category_permissions($dep,"gotomasses");
-    }
-    /* Create divlist */
-    $divlist->SetListHeader($header);
- /* Toggle all selected / deselected */
-    $chk = "<input type='checkbox' id='select_all' name='select_all'
-               onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
-
-    /* set Page header */
-    $divlist->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
-
-    $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:80px;'"));
-    $divlist->AddHeader(array("string"=>_("Action"),
-                                      "attach"=>"style='border-right:0px;width:40px;'"));
-
-    /* Create edit link */
-    $edit_link = "<div style='width:100%;overflow:hidden;'><nobr><a href='?plug=".$_GET['plug']."&act=edit&id=%key%'>%str%</nobr></div>";
-  
-    if(!empty($acls)){
-      foreach($this->tasks as $key => $task){
-        $action = "<input type='image' src='images/edit.png' name='edit_task_".$key."' class='center' alt='"._("Edit")."'>";
-        if($this->acl_is_removeable()){
-          $action.= "<input type='image' src='images/edittrash.png' name='remove_task_".$key."' class='center' alt='"._("Reomve")."'>";
-        }
-        /* Create each field */
-        $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
-                        "attach" => "style='width:20px;'");
-
-        $field1 = array("string" => preg_replace(array("/%key%/","/%str%/"),array($key,$this->target_to_string($task)),$edit_link));
-        $field2 = array("string" => $this->time_to_string($task),"attach" => "style='width:100px;'");
-        $field3 = array("string" => $this->action_to_string($task),"attach" => "style='width:80px;'");
-        $field4 = array("string" => $action,"attach" => "style='text-align:right;width:40px;border-right:0px;'");
-        $divlist->AddElement(array($field0,$field1,$field2,$field3,$field4));
-      }
-    }
-    return($divlist->Draw());
+    $this->divlist->execute();
+    $this->divlist->SetEntries($this->tasks); 
+    return($this->divlist->Draw());
   }
 
   
@@ -316,7 +263,7 @@ class gotomasses extends plugin
       $row    = preg_replace('/  */umi'," ",$row);
       $parts  = split(" ",$row);
 
-      if(count($parts) != 8){
+      if(count($parts) != 10){
         print_red(_("Entry broken, skipped."));
       }else{
 
@@ -328,11 +275,16 @@ class gotomasses extends plugin
         $entry['Weekday'] = $parts[4];  
         $entry['Action']  = $parts[5];  
         $entry['OGroup']  = $parts[6];  
+        $entry['Zone']    = $parts[7];  
+        $entry['Section'] = $parts[8];  
         if($entry['Action'] == "initial_install"){
-          $tmp2 = split(";",$parts[7]);
+          $tmp2 = split(";",$parts[9]);
           foreach($tmp2 as $target){
             $tmp = split(",",$target);
-            $entry['Initial_Target'][]  = array("MAC" => $tmp[0],"IP"=>$tmp[1],"NAME" => $tmp[2]);
+            $entry['Initial_Target'][]  = array(
+                          "MAC"     => $tmp[0],
+                          "IP"      => $tmp[1],
+                          "NAME"    => $tmp[2]);
           }
           $entry['Target']  = array();
         }else{
@@ -348,7 +300,7 @@ class gotomasses extends plugin
 
   function save_gotomasses_data()
   {
-    $str = "#GOsa generated file, please just modify if you realy know what you do.";
+    $str = "#GOsa generated file, please just modify if you really know what you do.";
     foreach($this->tasks as $task){
       $str .= "\n#".trim($task['Comment']);
       $str .= "\n";
@@ -363,9 +315,11 @@ class gotomasses extends plugin
       }
       $str .= str_pad($task['Action'] ,5," ")." ";
       $str .= str_pad($task['OGroup'] ,5," ")." ";
+      $str .= str_pad($task['Zone']   ,5," ")." ";
+      $str .= str_pad($task['Section'],5," ")." ";
       if($task['Action'] == "initial_install"){
         foreach($task['Initial_Target'] as $target){
-          $str .= $target['MAC'].",".$target['IP'].",".$target['NAME'].";";
+          $str .= trim($target['MAC']).",".trim($target['IP']).",".trim($target['NAME']).";";
         }
       }else{
         foreach($task['Target'] as $target){
@@ -398,6 +352,7 @@ class gotomasses extends plugin
 
   function save_object()
   {
+    $this->divlist->save_object();
   }