Code

Updated sudo plugin.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 4 Apr 2008 07:10:33 +0000 (07:10 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 4 Apr 2008 07:10:33 +0000 (07:10 +0000)
-Simplified object handling-

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10187 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/admin/sudo/class_sudoOptions.inc
gosa-core/plugins/admin/sudo/options.tpl

index 4b7c531da14795c1f99975ec5c612225ca015b22..d24c82e1f176962057fe2dc860468c69e1959242 100644 (file)
@@ -156,10 +156,6 @@ class sudoOption extends plugin
           }
         }
 
-        if($this->options[$opt]['TYPE'] == "LISTS"){
-           $this->sudoOption[$opt][] = $option;
-        }
-
         /* Special handling for BOOLEAN values */
         if(in_array($this->options[$opt]['TYPE'],array("BOOLEAN"))){
           $option['NEGATE'] = FALSE;
@@ -172,7 +168,7 @@ class sudoOption extends plugin
 
         /* Append values */
         if(!isset($this->sudoOption[$opt])){
-          $this->sudoOption[$opt] = $option;
+          $this->sudoOption[$opt][] = $option;
         }
       }
     }
@@ -188,23 +184,15 @@ class sudoOption extends plugin
      *****/
     foreach($_POST as $name => $value){
 
-      if(preg_match("/^negListOption_/",$name)){
-        $opt = preg_replace("/^negListOption_/","",$name);
+      if(preg_match("/^negOption_/",$name)){
+
+        $opt = preg_replace("/^negOption_/","",$name);
         $opt = preg_replace("/_[^_]*$/","",$opt);
         $id  = preg_replace("/^.*_([0-9])*$/","\\1",$opt);
         $opt = preg_replace("/_[0-9]*$/","",$opt);
 
         if(isset($this->sudoOption[$opt][$id])){
-          $this->sudoOption[$opt][$id]['NEGATE'] = !$this->sudoOption[$opt][$id]['NEGATE']; 
-        }
-        break;
-      }
-
-      if(preg_match("/^negOption_/",$name)){
-        $opt = preg_replace("/^negOption_/","",$name);
-        $opt = preg_replace("/_[^_]*$/","",$opt);
-        if(isset($this->sudoOption[$opt])){
-          $val = $this->sudoOption[$opt]["VALUE"];
+          $val = $this->sudoOption[$opt][$id]["VALUE"];
 
           /*****
             Negate STRING_BOOL && BOOL_INTEGER
@@ -212,12 +200,12 @@ class sudoOption 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"] = "FALSE";
+                $this->sudoOption[$opt][$id]["VALUE"] = "FALSE";
               }else{
-                $this->sudoOption[$opt]["VALUE"] = "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']; 
             }
           }
 
@@ -225,7 +213,7 @@ class sudoOption extends plugin
             Negate STRING / INTEGER
            *****/
           if(in_array($this->options[$opt]['TYPE'],array('STRING','INTEGER'))){
-            $this->sudoOption[$opt]['NEGATE'] = !$this->sudoOption[$opt]['NEGATE']; 
+            $this->sudoOption[$opt][$id]['NEGATE'] = !$this->sudoOption[$opt][$id]['NEGATE']; 
           }
 
           /*****
@@ -233,9 +221,9 @@ class sudoOption extends plugin
            *****/
           if(in_array($this->options[$opt]['TYPE'],array('BOOLEAN'))){
             if($val == "TRUE"){
-              $this->sudoOption[$opt]["VALUE"] = "FALSE";
+              $this->sudoOption[$opt][$id]["VALUE"] = "FALSE";
             }else{
-              $this->sudoOption[$opt]["VALUE"] = "TRUE";
+              $this->sudoOption[$opt][$id]["VALUE"] = "TRUE";
             }
           }
         }
@@ -245,21 +233,9 @@ class sudoOption extends plugin
       /*****
         Remove options
        *****/
-      if(preg_match("/^delOption_/",$name)){
+      if(preg_match("/^delOption/",$name)){
         $opt = preg_replace("/^delOption_/","",$name);
         $opt = preg_replace("/_[^_]*$/","",$opt);
-        if(isset($this->sudoOption[$opt])){
-          unset($this->sudoOption[$opt]);
-        }
-        break;
-      }
-
-      /*****
-        Remove LISTS options
-       *****/
-      if(preg_match("/^delListOption/",$name)){
-        $opt = preg_replace("/^delListOption_/","",$name);
-        $opt = preg_replace("/_[^_]*$/","",$opt);
         $id  = preg_replace("/^.*_([0-9])*$/","\\1",$opt);
         $opt = preg_replace("/_[0-9]*$/","",$opt);
 
@@ -296,17 +272,7 @@ class sudoOption extends plugin
       $opt = get_post("option");
 
       /* Append attribute only once, lists are handled below */
-      if(isset($this->options[$opt]) && !isset($this->sudoOption[$opt])){
-        $type = $this->options[$opt]['TYPE'];
-        $val  = $this->options[$opt]['DEFAULT'];
-        $option = array("NAME" => $opt, "VALUE" => $val , "NEGATE" => FALSE);
-
-        if($type == "LISTS"){
-          $this->sudoOption[$opt][] = $option;
-        }else{
-          $this->sudoOption[$opt] = $option;
-        }
-      }elseif(isset($this->options[$opt]) && isset($this->sudoOption[$opt]) && $this->options[$opt]['TYPE'] == "LISTS"){
+      if(isset($this->options[$opt])){
         $type = $this->options[$opt]['TYPE'];
         $val  = $this->options[$opt]['DEFAULT'];
         $option = array("NAME" => $opt, "VALUE" => $val , "NEGATE" => FALSE);
@@ -314,56 +280,58 @@ class sudoOption extends plugin
       }
     }
 
-    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"] = 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"] = 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'] = $sel;
-            $this->sudoOption[$name]['NEGATE'] = FALSE;
-          }else{
-            $this->sudoOption[$name]['VALUE'] = $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;
-          }
-        } 
+        /****
+          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;
+            }
+          } 
+        }
       }
     }
   }
@@ -374,63 +342,42 @@ class sudoOption extends plugin
     plugin::save(); 
 
     $this->attrs['sudoOption'] = array();
-    foreach($this->sudoOption as $name => $opt){
+    foreach($this->sudoOption as $name => $opts){
+      foreach($opts as $id => $opt){
 
-      $type   = $this->options[$name]['TYPE'];
+        $type   = $this->options[$name]['TYPE'];
+        $neg    = $opt['NEGATE'];
+        $value  = $opt['VALUE'];
+        $option = "";
 
-      if($type=="LISTS"){
-        foreach($this->sudoOption[$name] as $entry_key => $entry){
-          $val =  $entry["VALUE"];
+        /****
+          Save LISTS 
+         ****/
+        if($type=="LISTS"){
           if(empty($val)){
             $option = $name;
           }else{
             $option = $name."=".$val;
           }
-          if($entry['NEGATE']){
+          if($neg){
             $option = "!".$option;
           }
-          $this->attrs['sudoOption'][] = $option;
         }
-        continue;
-      }
 
-      $neg    = $opt['NEGATE'];
-      $value  = $opt["VALUE"];
-      $option = "";
-
-      /****
-        Save BOOLEAN
-       ****/
-      if(in_array($type,array("BOOLEAN"))){ 
-        $option = $name;
-        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;
+        /****
+          Save BOOLEAN
+         ****/
+        if(in_array($type,array("BOOLEAN"))){ 
+          $option = $name;
+          if($value == "FALSE"){
+            $option = "!".$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{
+        /****
+          Save STRING / INTEGER
+         ****/
+        if(in_array($type,array("STRING","INTEGER"))){ 
           if(!empty($value)){
             $option = $name."=".$value;
           }else{
@@ -440,9 +387,29 @@ class sudoOption extends plugin
             $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();
index d339ef78ce5cf37b1a53b5ff8a67d0b9da96633f..80ed89694a245733bd6936b9831a8c0ca59e4a07 100644 (file)
 
 <table>
 {foreach from=$sudoOption item=item key=key}
-
- <!--  Special handling for lists
-  -->
- {if $options[$key].TYPE == "LISTS"}
   {foreach from=$item item=entry key=entry_key} 
-   <tr> 
-    <td>{$key} - <b>{t}List{/t}</b></td>
-    <td style="width:20px;">
-     {if $entry.NEGATE}
-      <img src='images/negate.png' alt="!">
-     {/if}
-    </td>
-    <td><input type='text' value="{$entry.VALUE}" name="list_value__{$key}_{$entry_key}"></td>
-    <td>
-     <input type='image' src='images/negate.png'     name='negListOption_{$key}_{$entry_key}' class='center'>
-     <input type='image' src='images/edittrash.png'  name='delListOption_{$key}_{$entry_key}' class='center'>
-    </td>      
-   </tr>
-  {/foreach}
- {else}
-
- <!-- Default values flat values/single value 
-  -->
  <tr>
   <td>{$key}</td>
   <td style="width:20px;">
-   {if $item.NEGATE}
+   {if $entry.NEGATE}
     <img src='images/negate.png' alt="!">
    {/if}
   </td>
   <td>
 
-  {if $options[$item.NAME].TYPE == "STRING"}
+  {if $options[$entry.NAME].TYPE == "STRING"}
    <!-- STRING  
     -->
-   <input type='text' name='option_value__{$key}' value="{$item.VALUE}" style='width:280px;'> 
-  {elseif $options[$item.NAME].TYPE == "INTEGER"}
+   <input type='text' name='option_value__{$key}_{$entry_key}' value="{$entry.VALUE}" style='width:280px;'> 
+  {elseif $options[$entry.NAME].TYPE == "LISTS"}
+    <input type='text' value="{$entry.VALUE}" name="list_value__{$key}_{$entry_key}"></td>
+  {elseif $options[$entry.NAME].TYPE == "INTEGER"}
    <!-- INTEGER  
     -->
-   <input type='text' name='option_value__{$key}' value="{$item.VALUE}" style='width:280px;'>
-  {elseif $options[$item.NAME].TYPE == "BOOLEAN"}
+   <input type='text' name='option_value__{$key}_{$entry_key}' value="{$entry.VALUE}" style='width:280px;'>
+  {elseif $options[$entry.NAME].TYPE == "BOOLEAN"}
    <!-- BOOLEAN  
     -->
-   <select name="option_value__{$key}">
-    <option {if $item.VALUE == "FALSE"} selected {/if}value="FALSE">FALSE</option>
-    <option {if $item.VALUE == "TRUE"} selected {/if}value="TRUE">TRUE</option>
+   <select name="option_value__{$key}_{$entry_key}">
+    <option {if $entry.VALUE == "FALSE"} selected {/if}value="FALSE">FALSE</option>
+    <option {if $entry.VALUE == "TRUE"} selected {/if}value="TRUE">TRUE</option>
    </select>
-  {elseif $options[$item.NAME].TYPE == "BOOL_INTEGER"}
+  {elseif $options[$entry.NAME].TYPE == "BOOL_INTEGER"}
    <!-- BOOLEAN_INTEGER 
     -->
-   <select name="option_selection__{$key}" id="option_selection__{$key}"
-       onChange="toggle_bool_fields('option_selection__{$key}','option_value__{$key}');">
-    <option {if $item.VALUE == "FALSE"} selected {/if}value="FALSE">FALSE</option>
-    <option {if $item.VALUE == "TRUE"} selected {/if}value="TRUE">TRUE</option>
-    <option {if $item.VALUE != "TRUE" && $item.VALUE != "FALSE"} selected {/if}
+   <select name="option_selection__{$key}_{$entry_key}" id="option_selection__{$key}_{$entry_key}"
+       onChange="toggle_bool_fields('option_selection__{$key}_{$entry_key}','option_value__{$key}_{$entry_key}');">
+    <option {if $entry.VALUE == "FALSE"} selected {/if}value="FALSE">FALSE</option>
+    <option {if $entry.VALUE == "TRUE"} selected {/if}value="TRUE">TRUE</option>
+    <option {if $entry.VALUE != "TRUE" && $entry.VALUE != "FALSE"} selected {/if}
        value="STRING">STRING</option>
-    <input type='text' value="{$item.VALUE}" style='width:280px;' name='option_value__{$key}'
-       id="option_value__{$key}"
-        {if $item.VALUE == "FALSE" ||  $item.VALUE == "TRUE"} disabled {/if}>
+    <input type='text' value="{$entry.VALUE}" style='width:280px;' name='option_value__{$key}_{$entry_key}'
+       id="option_value__{$key}_{$entry_key}"
+        {if $entry.VALUE == "FALSE" ||  $entry.VALUE == "TRUE"} disabled {/if}>
    </select> 
-  {elseif $options[$item.NAME].TYPE == "STRING_BOOL"}
+  {elseif $options[$entry.NAME].TYPE == "STRING_BOOL"}
    <!-- STRING_BOOLEAN 
     -->
-   <select name="option_selection__{$key}" id="option_selection__{$key}"
-       onChange="toggle_bool_fields('option_selection__{$key}','option_value__{$key}');">
-    <option {if $item.VALUE == "FALSE"} selected {/if}value="FALSE">FALSE</option>
-    <option {if $item.VALUE == "TRUE"} selected {/if}value="TRUE">TRUE</option>
-    <option {if $item.VALUE != "TRUE" && $item.VALUE != "FALSE"} selected {/if}
+   <select name="option_selection__{$key}_{$entry_key}" id="option_selection__{$key}_{$entry_key}"
+       onChange="toggle_bool_fields('option_selection__{$key}_{$entry_key}','option_value__{$key}_{$entry_key}');">
+    <option {if $entry.VALUE == "FALSE"} selected {/if}value="FALSE">FALSE</option>
+    <option {if $entry.VALUE == "TRUE"} selected {/if}value="TRUE">TRUE</option>
+    <option {if $entry.VALUE != "TRUE" && $entry.VALUE != "FALSE"} selected {/if}
        value="STRING">STRING</option>
-    <input type='text' value="{$item.VALUE}" style='width:280px;' name='option_value__{$key}'
-       id="option_value__{$key}" 
-        {if $item.VALUE == "FALSE" ||  $item.VALUE == "TRUE"} disabled {/if}>
+    <input type='text' value="{$entry.VALUE}" style='width:280px;' name='option_value__{$key}_{$entry_key}'
+       id="option_value__{$key}_{$entry_key}
+        {if $entry.VALUE == "FALSE" ||  $entry.VALUE == "TRUE"} disabled {/if}>
    </select> 
   {/if}
   </td>
   <td style='width: 40px;'>
-   <input type='image' src='images/negate.png'     name='negOption_{$key}' class='center'>
-   <input type='image' src='images/edittrash.png'  name='delOption_{$key}' class='center'>
+   <input type='image' src='images/negate.png'     name='negOption_{$key}_{$entry_key}' class='center'>
+   <input type='image' src='images/edittrash.png'  name='delOption_{$key}_{$entry_key}' class='center'>
   </td>
  </tr>
{/if}
 {/foreach}
 {/foreach}
 </table>