Code

Re-run translations
[gosa.git] / gosa-core / plugins / admin / sudo / class_sudoOptions.inc
index 2bf27f8234157e9387d1e5b1439f13ea023e2d91..b9954a50378420366cee8404d3b8a6a01de68947 100644 (file)
@@ -20,7 +20,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-class sudo_options extends plugin
+class sudoOption extends plugin
 {
   /* Group attributes */
   var $sudoOption = array();
@@ -30,7 +30,7 @@ class sudo_options extends plugin
   
   var $options = array();
 
-  function sudo_options(&$config, $dn= NULL)
+  function sudoOption(&$config, $dn= NULL)
   {
     plugin::plugin ($config, $dn);
 
@@ -138,7 +138,7 @@ class sudo_options extends plugin
         /* Create internal sudoOption object */
         $option = array();
         $option['NAME']   = $opt;
-        $option['VALUE']  = array($value);
+        $option['VALUE']  = $value;
         $option['NEGATE'] = $negation;
 
         /*  Special handling for mixed flag types. 
@@ -149,9 +149,9 @@ class sudo_options extends plugin
           if(empty($value)){
             $option['NEGATE'] = FALSE;
             if($negation){
-              $option['VALUE'] = array(0 => "FALSE");
+              $option['VALUE'] = "FALSE";
             }else{
-              $option['VALUE'] = array(0 => "TRUE");
+              $option['VALUE'] = "TRUE";
             }
           }
         }
@@ -160,17 +160,15 @@ class sudo_options extends plugin
         if(in_array($this->options[$opt]['TYPE'],array("BOOLEAN"))){
           $option['NEGATE'] = FALSE;
           if($negation){
-            $option['VALUE'] = array(0 => "FALSE");
+            $option['VALUE'] = "FALSE";
           }else{
-            $option['VALUE'] = array(0 => "TRUE");
+            $option['VALUE'] = "TRUE";
           }
         }
 
         /* Append values */
         if(!isset($this->sudoOption[$opt])){
-          $this->sudoOption[$opt] = $option;
-        }else{
-          $this->sudoOption[$opt]['VALUE'][] = $value;
+          $this->sudoOption[$opt][] = $option;
         }
       }
     }
@@ -185,11 +183,16 @@ class sudo_options extends plugin
       Handle Posts 
      *****/
     foreach($_POST as $name => $value){
+
       if(preg_match("/^negOption_/",$name)){
+
         $opt = preg_replace("/^negOption_/","",$name);
         $opt = preg_replace("/_[^_]*$/","",$opt);
-        if(isset($this->sudoOption[$opt])){
-          $val = $this->sudoOption[$opt]['VALUE'][0];
+        $id  = preg_replace("/^.*_([0-9])*$/","\\1",$opt);
+        $opt = preg_replace("/_[0-9]*$/","",$opt);
+
+        if(isset($this->sudoOption[$opt][$id])){
+          $val = $this->sudoOption[$opt][$id]["VALUE"];
 
           /*****
             Negate STRING_BOOL && BOOL_INTEGER
@@ -197,20 +200,20 @@ class sudo_options extends plugin
           if(in_array($this->options[$opt]['TYPE'],array('STRING_BOOL','BOOL_INTEGER'))){
             if(in_array($val, array("TRUE","FALSE"))){
               if($val == "TRUE"){
-                $this->sudoOption[$opt]['VALUE'][0] = "FALSE";
+                $this->sudoOption[$opt][$id]["VALUE"] = "FALSE";
               }else{
-                $this->sudoOption[$opt]['VALUE'][0] = "TRUE";
+                $this->sudoOption[$opt][$id]["VALUE"] = "TRUE";
               }
             }else{
-               $this->sudoOption[$opt]['NEGATE'] = !$this->sudoOption[$opt]['NEGATE']; 
+               $this->sudoOption[$opt][$id]['NEGATE'] = !$this->sudoOption[$opt][$id]['NEGATE']; 
             }
           }
 
           /*****
             Negate STRING / INTEGER
            *****/
-          if(in_array($this->options[$opt]['TYPE'],array('STRING','INTEGER'))){
-            $this->sudoOption[$opt]['NEGATE'] = !$this->sudoOption[$opt]['NEGATE']; 
+          if(in_array($this->options[$opt]['TYPE'],array('STRING','INTEGER','LISTS'))){
+            $this->sudoOption[$opt][$id]['NEGATE'] = !$this->sudoOption[$opt][$id]['NEGATE']; 
           }
 
           /*****
@@ -218,23 +221,28 @@ class sudo_options extends plugin
            *****/
           if(in_array($this->options[$opt]['TYPE'],array('BOOLEAN'))){
             if($val == "TRUE"){
-              $this->sudoOption[$opt]['VALUE'][0] = "FALSE";
+              $this->sudoOption[$opt][$id]["VALUE"] = "FALSE";
             }else{
-              $this->sudoOption[$opt]['VALUE'][0] = "TRUE";
+              $this->sudoOption[$opt][$id]["VALUE"] = "TRUE";
             }
           }
         }
         break;
       }
 
-      if(preg_match("/^delOption_/",$name)){
-
-        /*****
-          Remove options
-         *****/
+      /*****
+        Remove options
+       *****/
+      if(preg_match("/^delOption/",$name)){
         $opt = preg_replace("/^delOption_/","",$name);
         $opt = preg_replace("/_[^_]*$/","",$opt);
-        if(isset($this->sudoOption[$opt])){
+        $id  = preg_replace("/^.*_([0-9])*$/","\\1",$opt);
+        $opt = preg_replace("/_[0-9]*$/","",$opt);
+
+        if(isset($this->sudoOption[$opt][$id])){
+          unset($this->sudoOption[$opt][$id]);
+        }
+        if(!count($this->sudoOption[$opt])){
           unset($this->sudoOption[$opt]);
         }
         break;
@@ -262,52 +270,68 @@ class sudo_options extends plugin
 
     if(isset($_POST['add_option']) && isset($_POST['option'])){
       $opt = get_post("option");
-      if(isset($this->options[$opt]) && !isset($this->sudoOption[$opt])){
+
+      /* Append attribute only once, lists are handled below */
+      if(isset($this->options[$opt])){
         $type = $this->options[$opt]['TYPE'];
-        $val  = array($this->options[$opt]['DEFAULT']);
+        $val  = $this->options[$opt]['DEFAULT'];
         $option = array("NAME" => $opt, "VALUE" => $val , "NEGATE" => FALSE);
-        $this->sudoOption[$opt] = $option;
+        $this->sudoOption[$opt][] = $option;
       }
     }
 
-    foreach($this->sudoOption as $name => $opt){
+    foreach($this->sudoOption as $name => $opts){
+      foreach($opts as $id => $opt){
 
-      /****
-        Get posted value for BOOLEAN
-       ****/
-      if(in_array($this->options[$name]['TYPE'],array("BOOLEAN"))){
-        if(isset($_POST['option_value__'.$name])){
-          $this->sudoOption[$name]['VALUE'][0] = get_post('option_value__'.$name);
+        /****
+          Get posted value for BOOLEAN
+         ****/
+        if(in_array($this->options[$name]['TYPE'],array("BOOLEAN"))){
+          if(isset($_POST['option_value__'.$name.'_'.$id])){
+            $this->sudoOption[$name][$id]["VALUE"] = get_post('option_value__'.$name.'_'.$id);
+          }
         }
-      }
 
-      /****
-        Get posted value for STRING / INTEGER
-       ****/
-      if(in_array($this->options[$name]['TYPE'],array("STRING","INTEGER"))){
-        if(isset($_POST['option_value__'.$name])){
-          $this->sudoOption[$name]['VALUE'][0] = get_post('option_value__'.$name);
+        /****
+          Get posted value for STRING / INTEGER
+         ****/
+        if(in_array($this->options[$name]['TYPE'],array("STRING","INTEGER"))){
+          if(isset($_POST['option_value__'.$name.'_'.$id])){
+            $this->sudoOption[$name][$id]["VALUE"] = get_post('option_value__'.$name.'_'.$id);
+          }
         }
-      }
 
-      /****
-        Get posted value for STRING_BOOL / BOOL_INTEGER
-       ****/
-      if(in_array($this->options[$name]['TYPE'],array("BOOL_INTEGER","STRING_BOOL"))){
-        if(isset($_POST['option_selection__'.$name])){
-          $sel = get_post('option_selection__'.$name);
-          $val = "";
-          if(isset($_POST['option_value__'.$name])){
-            $val = get_post('option_value__'.$name);
-          }
+        /****
+          Get posted value for STRING_BOOL / BOOL_INTEGER
+         ****/
+        if(in_array($this->options[$name]['TYPE'],array("BOOL_INTEGER","STRING_BOOL"))){
+          if(isset($_POST['option_selection__'.$name.'_'.$id])){
+            $sel = get_post('option_selection__'.$name.'_'.$id);
+            $val = "";
+            if(isset($_POST['option_value__'.$name.'_'.$id])){
+              $val = get_post('option_value__'.$name.'_'.$id);
+            }
 
-          if($sel == "FALSE" || $sel == "TRUE"){
-            $this->sudoOption[$name]['VALUE'] = array($sel);
-            $this->sudoOption[$name]['NEGATE'] = FALSE;
-          }else{
-            $this->sudoOption[$name]['VALUE'] = array($val);
+            if($sel == "FALSE" || $sel == "TRUE"){
+              $this->sudoOption[$name][$id]['VALUE'] = $sel;
+              $this->sudoOption[$name][$id]['NEGATE'] = FALSE;
+            }else{
+              $this->sudoOption[$name][$id]['VALUE'] = $val;
+            }
           }
         }
+
+        /****
+          Get posted value for LISTS
+         ****/
+        if(in_array($this->options[$name]['TYPE'],array("LISTS"))){
+          foreach($this->sudoOption[$name] as $entry_key => $entry){
+            if(isset($_POST['list_value__'.$name.'_'.$entry_key])){
+              $val = get_post('list_value__'.$name.'_'.$entry_key);
+              $this->sudoOption[$name][$entry_key]["VALUE"] = $val;
+            }
+          } 
+        }
       }
     }
   }
@@ -318,50 +342,74 @@ class sudo_options extends plugin
     plugin::save(); 
 
     $this->attrs['sudoOption'] = array();
-    foreach($this->sudoOption as $name => $opt){
-
-      $type   = $this->options[$name]['TYPE'];
-      $neg    = $opt['NEGATE'];
-      $value  = $opt['VALUE'][0];
-      $option = "";
-
-      /****
-        Save BOOLEAN
-       ****/
-      if(in_array($type,array("BOOLEAN"))){ 
-        $option = $name;
-        if($value == "FALSE"){
-          $option = "!".$option;
-        }
-      }
+    foreach($this->sudoOption as $name => $opts){
+      foreach($opts as $id => $opt){
+
+        $type   = $this->options[$name]['TYPE'];
+        $neg    = $opt['NEGATE'];
+        $value  = $opt['VALUE'];
+        $option = "";
 
-      /****
-        Save STRING / INTEGER
-       ****/
-      if(in_array($type,array("STRING","INTEGER"))){ 
-        $option = $name."=".$value;
-        if($neg){
-          $option = "!".$option;
+        /****
+          Save LISTS 
+         ****/
+        if($type=="LISTS"){
+          if(empty($value)){
+            $option = $name;
+          }else{
+            $option = $name."=".$value;
+          }
+          if($neg){
+            $option = "!".$option;
+          }
         }
-      }
 
-      /****
-        Save STRING_BOOL / BOOL_INTEGER
-       ****/
-      if(in_array($type,array("STRING_BOOL","BOOL_INTEGER"))){
-        if($value == "FALSE"){
-          $option = "!".$name;
-        }elseif($value == "TRUE"){
+        /****
+          Save BOOLEAN
+         ****/
+        if(in_array($type,array("BOOLEAN"))){ 
           $option = $name;
-        }else{
-          $option = $name."=".$value;
+          if($value == "FALSE"){
+            $option = "!".$option;
+          }
+        }
+
+        /****
+          Save STRING / INTEGER
+         ****/
+        if(in_array($type,array("STRING","INTEGER"))){ 
+          if(!empty($value)){
+            $option = $name."=".$value;
+          }else{
+            $option = $name; 
+          }
           if($neg){
             $option = "!".$option;
           }
         }
-      }
 
-      $this->attrs['sudoOption'][] = $option;
+        /****
+          Save STRING_BOOL / BOOL_INTEGER
+         ****/
+        if(in_array($type,array("STRING_BOOL","BOOL_INTEGER"))){
+          if($value == "FALSE"){
+            $option = "!".$name;
+          }elseif($value == "TRUE"){
+            $option = $name;
+          }else{
+            if(!empty($value)){
+              $option = $name."=".$value;
+            }else{
+              $option = $name; 
+            }
+            if($neg){
+              $option = "!".$option;
+            }
+          }
+        }
+
+        $this->attrs['sudoOption'][] = $option;
+      }
     }
     $this->cleanup();
     $ldap = $this->config->get_ldap_link();