Code

Updated multiple edit
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 12 Dec 2007 10:54:56 +0000 (10:54 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 12 Dec 2007 10:54:56 +0000 (10:54 +0000)
-Added plugin array 'multi_attr' and 'multi_attr_all' which contain user attribute values.
-Added simple multi edit to posix.

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

include/class_multi_plug.inc
include/class_plugin.inc
plugins/personal/generic/class_user.inc
plugins/personal/posix/class_posixAccount.inc
plugins/personal/posix/generic.tpl

index 98cbf6688f365166b15b10dbeda50328c2cf811e..b74f963dc6fc787fba60ab9f2edc0e653fe350d0 100644 (file)
@@ -128,22 +128,31 @@ class multi_plug
   private function detect_multiple_used_attributes()
   {
     $attrs = array();
-    restore_error_handler();
+    $all   = array();
     $first = $this->o_tab->current;
     foreach($this->a_handles as $handle){
       if(count($attrs) == 0){
         $attrs = $handle->by_object[$first]->attrs;
       }else{
-
         foreach($attrs as $key => $attr){
           if(!isset($handle->by_object[$first]->attrs[$key]) || !($attr === $handle->by_object[$first]->attrs[$key])){
             unset($attrs[$key]);
           }
+          if(!is_numeric($key)){
+            if(!isset($all[$key])){
+              $all[$key] = $attr; 
+            }elseif(isset($attr['count'])){
+              for($i = 0; $i < $attr['count'] ; $i ++){
+                $all[$key][] = $attr[$i];
+              }
+              $all[$key] = array_unique($all[$key]);
+            }
+          }
         }
       }
     }
     foreach($this->o_tab->by_object as $name => $obj){
-      $this->o_tab->by_object[$name]->init_multiple_support($attrs);
+      $this->o_tab->by_object[$name]->init_multiple_support($attrs,$all);
     }
   }
 
index 5a209ab39642c4b9565b795d76291913be349837..da0a6c4d1e6001f4fc9189e5e5a4ad95612d6904 100644 (file)
@@ -123,7 +123,9 @@ class plugin
   var $CSN_check_active = FALSE;
 
   /* This variable indicates that this class can handle multiple dns at once. */
-  var $multiple_support = FALSE; 
+  var $multiple_support = FALSE;
+  var $multi_attrs      = array();
+  var $multi_attrs_all  = array(); 
 
   /* This aviable indicates, that we are currently in multiple edit handle */
   var $multiple_support_active = FALSE; 
@@ -1694,16 +1696,17 @@ class plugin
    *          Update plugin attributes with given array of attribtues.
    *  @param  array   Array with attributes that must be updated.
    */
-  function init_multiple_support($attrs)
+  function init_multiple_support($attrs,$all)
   {
     $ldap= $this->config->get_ldap_link();
-    $this->attrs= $attrs;
+    $this->multi_attrs    = $attrs;
+    $this->multi_attrs_all= $all;
 
     /* Copy needed attributes */
     foreach ($this->attributes as $val){
-      $found= array_key_ics($val, $this->attrs);
+      $found= array_key_ics($val, $this->multi_attrs);
       if ($found != ""){
-        $this->$val= $this->attrs["$found"][0];
+        $this->$val= $this->multi_attrs["$found"][0];
       }
     }
   }
@@ -1749,9 +1752,14 @@ class plugin
     }
 
     /* Save values to object */
+    $this->multi_boxes = array();
     foreach ($this->attributes as $val){
       if ($this->acl_is_writeable($val) && isset ($_POST["$val"])){
 
+        if(isset($_POST["use_".$val])){
+          $this->multi_boxes[] = $val;
+        }
+
         /* Check for modifications */
         if (get_magic_quotes_gpc()) {
           $data= stripcslashes($_POST["$val"]);
index 80fd1d59f76ea0ad399f24af4d90ff0a184d094b..57414ef0ca59bf90f1b9d957e6b8a0ae811d5f31 100644 (file)
@@ -107,9 +107,6 @@ class user extends plugin
       "postalCode");
 
   var $multiple_support = TRUE;
-  var $multiple_user_handles  = array();
-
-  var $multi_boxes = array();
 
   /* constructor, if 'dn' is set, the node loads the given
      'dn' from LDAP */
@@ -1513,12 +1510,6 @@ class user extends plugin
     }
 
     if(isset($_POST['user_mulitple_edit'])){
-      $this->multi_boxes = array();
-      foreach($this->attributes as $val){
-        if(isset($_POST["use_".$val])){
-          $this->multi_boxes[] = $val;
-        }
-      }
       foreach(array("base","pw_storage","edit_picture") as $val){
         if(isset($_POST["use_".$val])){
           $this->multi_boxes[] = $val;
index 1453f4570c3ad2020f87db02d831035a89af9f79..e1a5412c9adba153911a6030fb7232617a1e8a4d 100644 (file)
@@ -79,6 +79,7 @@ class posixAccount extends plugin
   var $objectclasses= array("posixAccount", "shadowAccount");
 
   var $uid= "";
+  var $multiple_support = TRUE;
 
   /* constructor, if 'dn' is set, the node loads the given
      'dn' from LDAP */
@@ -237,7 +238,11 @@ class posixAccount extends plugin
       $_SESSION['CurrentMainBase']= validate($_POST['depselect']);
     }
 
-    if(!$isCopyPaste){
+    if($this->multiple_support_active){
+      $this->is_account = TRUE;
+    }
+
+    if(!$isCopyPaste && ! $this->multiple_support_active){
 
       /* Do we need to flip is_account state? */
       if(isset($_POST['modify_state'])){
@@ -535,8 +540,23 @@ class posixAccount extends plugin
 
     $smarty->assign("force_idsACL", $this->getacl("uidNumber",$SkipWrite).$this->getacl("gidNumber",$SkipWrite));
 
+    foreach(array("primaryGroup") as $val){
+      if(in_array($val,$this->multi_boxes)){
+        $smarty->assign("use_".$val,TRUE);
+      }else{
+        $smarty->assign("use_".$val,FALSE);
+      }
+    }
+
+
     /* Load attributes and acl's */
     foreach($this->attributes as $val){
+      if(in_array($val,$this->multi_boxes)){
+        $smarty->assign("use_".$val,TRUE);
+      }else{
+        $smarty->assign("use_".$val,FALSE);
+      }
+
       if(($_SESSION["js"])&&(($val=="uidNumber")||($val=="gidNumber")))
       {
         $smarty->assign("$val"."ACL",$this->getacl($val,$SkipWrite));
@@ -585,6 +605,7 @@ class posixAccount extends plugin
     $smarty->assign("workstations", $this->accessTo);
 
     $smarty->assign("apply", apply_filter());
+    $smarty->assign("multiple_support" , $this->multiple_support_active);
     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
     return($display);
   }
@@ -1345,6 +1366,12 @@ class posixAccount extends plugin
   }
 
 
+  function multiple_execute()
+  {
+    return($this->execute());
+  }
+
+
   static function plInfo()
   {
     return (array(
@@ -1372,6 +1399,34 @@ class posixAccount extends plugin
             "trustModel"          =>  _("System trust model")))
             );
   }
+
+  function get_multi_edit_values()
+  {
+    $ret = plugin::get_multi_edit_values();
+    return($ret);
+  }
+
+
+  function multiple_save_object()
+  {
+    if(isset($_POST['posix_mulitple_edit'])){
+      plugin::multiple_save_object();
+      foreach(array("primaryGroup") as $val){
+        if(isset($_POST["use_".$val])){
+          $this->multi_boxes[] = $val;
+        }
+      }
+
+      /* Save primary group settings */
+      if($this->acl_is_writeable("primaryGroup") && isset($_POST['primaryGroup'])){
+        $data= $_POST['primaryGroup'];
+        if ($this->primaryGroup != $data){
+          $this->is_modified= TRUE;
+        }
+        $this->primaryGroup= $_POST['primaryGroup'];
+      }
+    }
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
index 65d5ba7e02b6a7c39506a895df73195fb8cdafdb..c9dc98d4779b4123e678e306c9ccd0411dffaa73 100644 (file)
@@ -6,42 +6,47 @@
     <tr>
      <td><label for="homeDirectory">{t}Home directory{/t}</label>{$must}</td>
      <td>
-       {render acl=$homeDirectoryACL}
+{render acl=$homeDirectoryACL checkbox=$multiple_support checked=$use_homeDirectory}
       <input id="homeDirectory" name="homeDirectory" size=40 maxlength=120 value="{$homeDirectory}">
-       {/render}
+{/render}
      </td>
     </tr>
     <tr>
      <td><label for="loginShell">{t}Shell{/t}</label></td>
      <td>
-       {render acl=$loginShellACL}
+{render acl=$loginShellACL checkbox=$multiple_support checked=$use_loginShell}
       <select id="loginShell" size="1" name="loginShell">
        {html_options values=$shells output=$shells selected=$loginShell}
       </select> 
-       {/render}
+{/render}
      </td>
     </tr>
     <tr>
      <td><label for="">{t}Primary group{/t}</label></td>
      <td>
-       {render acl=$gidNumberACL}
+{render acl=$gidNumberACL checkbox=$multiple_support checked=$use_primaryGroup}
       <select id="primaryGroup" size="1" name="primaryGroup">
        {html_options options=$secondaryGroups selected=$primaryGroup}
       </select> 
-       {/render}
+{/render}
      </td>
     </tr>
+{if !$multiple_support}
     <tr>
      <td>{t}Status{/t}</td>
      <td>{$status}</td>
     </tr>
+{/if}
    </table>
+
+{if !$multiple_support}
+
    <table summary="">
     <tr>
      <td>
-       {render acl=$force_idsACL}
+{render acl=$force_idsACL}
       <input id="force_ids" type=checkbox name="force_ids" value="1" {$force_ids} onclick="changeState('uidNumber'); changeState('gidNumber');">
-       {/render}
+{/render}
                                        </td>
                                        <td>
       <label for="force_ids">{t}Force UID/GID{/t}</label>
@@ -51,9 +56,9 @@
                                                <label for="uidNumber">{t}UID{/t}</label>
                                        </td>
                                        <td>
-       {render acl=$uidNumberACL}
+{render acl=$uidNumberACL}
                                                <input id="uidNumber" name="uidNumber" size=9 maxlength=9 {$forceMode} value="{$uidNumber}">
-       {/render}
+{/render}
                                        </td>
                                </tr>
                                <tr>
                                                <label for="gidNumber">{t}GID{/t}</label>
                                        </td>
      <td>
-       {render acl=$gidNumberACL}
+{render acl=$gidNumberACL}
                                                <input id="gidNumber" name="gidNumber" size=9 maxlength=9 {$forceMode} value="{$gidNumber}">
-       {/render}
+{/render}
                                        </td>
                                </tr>
    </table>
+{/if}
   </td>
   <td style="border-left:1px solid #A0A0A0">
     &nbsp;
     <b style="color:red">{t}(Warning: more than 16 groups are not supported by NFS!){/t}</b>
     <br>
    {/if}
-       {render acl=$groupMembershipACL}
+{render acl=$groupMembershipACL}
    <select style="width:100%; height:130px;" name="group_list[]" size=16 multiple >
+{if !$multiple_support}
     {html_options options=$groupMembership}
+{else}
+
+       
+{/if}
    </select>
-       {/render}
+{/render}
    <br>
-       {render acl=$groupMembershipACL}
+{render acl=$groupMembershipACL}
    <input type=submit value="{t}Add{/t}" name="edit_groupmembership" >&nbsp;
-       {/render}
-       {render acl=$groupMembershipACL}
+{/render}
+{render acl=$groupMembershipACL}
    <input type=submit value="{t}Delete{/t}" name="delete_groupmembership" >
-       {/render}
+{/render}
   </td>
  </tr>
 </table>
   <td style="vertical-align:top;">
    <h2><img alt="" class="center" align="middle" src="images/closedlock.png" /> {t}System trust{/t}</h2>
     {t}Trust mode{/t}&nbsp;
-       {render acl=$trustmodeACL}
+{render acl=$trustmodeACL}
        <select name="trustmode" id="trustmode" size=1 onchange="changeSelectState('trustmode', 'wslist'); changeSelectState('trustmode', 'add_ws'); changeSelectState('trustmode', 'del_ws');">
       {html_options options=$trustmodes selected=$trustmode}
     </select>
-       {/render}
-       {render acl=$trustmodeACL}
+{/render}
+{render acl=$trustmodeACL}
    <select style="width:100%" id="wslist" name="workstation_list[]" size=8 multiple {$trusthide}>
     {html_options values=$workstations output=$workstations}
        {if $emptyArrAccess}
                <option disabled>&nbsp;</option>
        {/if}
    </select>
-       {/render}
+{/render}
    <br>
-       {render acl=$trustmodeACL}
+{render acl=$trustmodeACL}
    <input type="submit" id="add_ws" value="{t}Add{/t}" name="add_ws" {$trusthide}>&nbsp;
-       {/render}
-       {render acl=$trustmodeACL}
+{/render}
+{render acl=$trustmodeACL}
    <input type="submit" id="del_ws" value="{t}Delete{/t}" name="delete_ws" {$trusthide}>
-       {/render}
+{/render}
   </td>
  </tr>
 </table>
+{if $multiple_support}
+       <input type="hidden" name="posix_mulitple_edit" value="1">
+{/if}
 
 <input type="hidden" name="posixTab" value="posixTab">