Code

Updated sudo stuff
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 3 Apr 2008 10:32:10 +0000 (10:32 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 3 Apr 2008 10:32:10 +0000 (10:32 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10134 594d385d-05f5-0310-b6e9-bd551577e9d8

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

index 2bf27f8234157e9387d1e5b1439f13ea023e2d91..838dc138d2c58ecc28be678eb1cdba03ef95b0a0 100644 (file)
@@ -156,6 +156,10 @@ class sudo_options 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;
@@ -169,8 +173,6 @@ class sudo_options extends plugin
         /* Append values */
         if(!isset($this->sudoOption[$opt])){
           $this->sudoOption[$opt] = $option;
-        }else{
-          $this->sudoOption[$opt]['VALUE'][] = $value;
         }
       }
     }
@@ -185,6 +187,19 @@ class sudo_options extends plugin
       Handle Posts 
      *****/
     foreach($_POST as $name => $value){
+
+      if(preg_match("/^negListOption_/",$name)){
+        $opt = preg_replace("/^negListOption_/","",$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);
@@ -227,11 +242,10 @@ class sudo_options extends plugin
         break;
       }
 
+      /*****
+        Remove options
+       *****/
       if(preg_match("/^delOption_/",$name)){
-
-        /*****
-          Remove options
-         *****/
         $opt = preg_replace("/^delOption_/","",$name);
         $opt = preg_replace("/_[^_]*$/","",$opt);
         if(isset($this->sudoOption[$opt])){
@@ -239,6 +253,24 @@ class sudo_options extends plugin
         }
         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);
+
+        if(isset($this->sudoOption[$opt][$id])){
+          unset($this->sudoOption[$opt][$id]);
+        }
+        if(!count($this->sudoOption[$opt])){
+          unset($this->sudoOption[$opt]);
+        }
+        break;
+      }
     }
 
  
@@ -262,11 +294,25 @@ class sudo_options extends plugin
 
     if(isset($_POST['add_option']) && isset($_POST['option'])){
       $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  = array($this->options[$opt]['DEFAULT']);
         $option = array("NAME" => $opt, "VALUE" => $val , "NEGATE" => FALSE);
-        $this->sudoOption[$opt] = $option;
+
+        if($type == "LISTS"){
+          $this->sudoOption[$opt][] = $option;
+        }else{
+          $this->sudoOption[$opt] = $option;
+        }
+      }
+
+      if(isset($this->options[$opt]) && isset($this->sudoOption[$opt]) && $this->options[$opt]['TYPE'] == "LISTS"){
+        $type = $this->options[$opt]['TYPE'];
+        $val  = array($this->options[$opt]['DEFAULT']);
+        $option = array("NAME" => $opt, "VALUE" => $val , "NEGATE" => FALSE);
+        $this->sudoOption[$opt][] = $option;
       }
     }
 
@@ -309,6 +355,18 @@ class sudo_options extends plugin
           }
         }
       }
+
+      /****
+        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'][0] = $val;
+          }
+        } 
+      }
     }
   }
 
@@ -321,6 +379,23 @@ class sudo_options extends plugin
     foreach($this->sudoOption as $name => $opt){
 
       $type   = $this->options[$name]['TYPE'];
+
+      if($type=="LISTS"){
+        foreach($this->sudoOption[$name] as $entry_key => $entry){
+          $val =  $entry['VALUE'][0];
+          if(empty($val)){
+            $option = $name;
+          }else{
+            $option = $name."=".$val;
+          }
+          if($entry['NEGATE']){
+            $option = "!".$option;
+          }
+          $this->attrs['sudoOption'][] = $option;
+        }
+        continue;
+      }
+
       $neg    = $opt['NEGATE'];
       $value  = $opt['VALUE'][0];
       $option = "";
index c1dbe46da84f24553fb2f8d4ae92d9691f50ce71..832e8b69212faed480d0b0a63e0e33d5235b30b7 100644 (file)
@@ -1,7 +1,7 @@
 
 <select name='option'>
 {foreach from=$options item=item key=key}
- {if !isset($sudoOption.$key)}
+ {if !isset($sudoOption.$key) || ($sudoOption.$key && $item.TYPE == "LISTS")}
  <option value='{$key}'>{$item.NAME} ({$map[$item.TYPE]})</option>
  {/if}
 {/foreach}
 
 <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.0}" 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;">
@@ -60,8 +83,6 @@
        id="option_value__{$key}" 
         {if $item.VALUE.0 == "FALSE" ||  $item.VALUE.0 == "TRUE"} disabled {/if}>
    </select> 
-  {else}
-   {$options[$item.NAME].TYPE} 
   {/if}
   </td>
   <td style='width: 40px;'>
@@ -69,6 +90,7 @@
    <input type='image' src='images/edittrash.png'  name='delOption_{$key}' class='center'>
   </td>
  </tr>
+ {/if}
 {/foreach}
 </table>