Code

Additional multiple edit checkin.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 19 Oct 2007 11:48:15 +0000 (11:48 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 19 Oct 2007 11:48:15 +0000 (11:48 +0000)
Not working.

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

include/class_multi_plug.inc
include/class_plugin.inc
plugins/admin/users/class_userManagement.inc
plugins/admin/users/tabs_user.inc
plugins/personal/generic/class_user.inc
plugins/personal/generic/multiple_generic.tpl

index 021bb287d161a8feae4754e3354503c4d817ab7e..e8a16cc751ebe65d6917f688dda17a63fef2b268 100644 (file)
@@ -8,14 +8,15 @@ class multi_plug
   /* Dummy handler which collects the data */
   private $o_tab     = NULL;  
 
-  private $a_dns    = array();
-  private $o_config = NULL;
+  public $dn    = array();
+  public $config = NULL;
   private $s_class  = "";
+  public $current = "";
 
   public function __construct($config,$class,$tab,$dns)
   {
-    $this->a_dns = $dns;
-    $this->o_config = $config;
+    $this->dn = $dns;
+    $this->config = $config;
     $this->s_class = $class;
     $this->o_tab = new $class($config,$tab,"new");
 
@@ -28,6 +29,11 @@ class multi_plug
     }
   }
 
+  public function execute()
+  {
+    return($this->o_tab->execute());
+  }
+
   public function entries_locked()
   {
     return(FALSE);
@@ -35,7 +41,7 @@ class multi_plug
 
   public function display_lock_message()
   {
-    return("");
+    return("sdf");
   }
 
   public function lock_entries($uid)
@@ -45,16 +51,65 @@ class multi_plug
 
   public function multiple_available()
   {
-    return(TRUE);
+    return($this->o_tab->multiple_support_available());
   }
 
   public function set_active_tab($str)
   {
+    $this->current = $str;
   }
 
   public function get_object_info()
   {
-    return("Oi");
+    return("Oi -----");
+  }
+
+  public function save_object()
+  {
+    $this->o_tab->save_object(); 
+  }
+
+  public function check()
+  {
+    $this->populate_values();
+    $messages = $this->o_tab->check();
+    foreach($this->a_handles as $key => $obj){
+      $msgs = $obj->check();
+      foreach($msgs as $msg){
+        $messages[] = $msg;
+      }
+    }
+    return($messages);
+  }
+
+  public function password_change_needed()
+  {
+    return(FALSE);
+  }
+
+  public function populate_values()
+  {
+
+    if($this->multiple_available() && is_array($this->a_handles)){
+      foreach($this->o_tab->by_object as $name => $obj){
+        $values = $this->o_tab->by_object[$name]->get_multi_edit_values();
+        foreach($values as $a_name => $a_value){
+          foreach($this->a_handles as $i_id => $o_handle){
+            $o_handle->by_object[$name]->$a_name = $a_value;
+          }
+        }
+      }
+    }
+  }
+
+  public function save()
+  {
+    if($this->multiple_available() && is_array($this->a_handles)){
+      $this->populate_values();
+      foreach($this->a_handles as $i_id => $o_handle){
+        $o_handle->save();
+      }
+    }
   }
 }
 
index 4d753e7cc9af7aadb84123d5da8b77d83cd21f24..58cec70eea89b1dc07b20aae2db6382120a67c79 100644 (file)
@@ -124,6 +124,7 @@ class plugin
 
   /* This aviable indicates, that we are currently in multiple edit handle */
   var $multiple_support_active = FALSE; 
+  var $selected_edit_values = array();
 
   /*! \brief plugin constructor
 
@@ -279,6 +280,16 @@ class plugin
   /* Save data to object */
   function save_object()
   {
+    if($this->multiple_support_active){
+      foreach($this->attributes as $attr){
+        if(isset($_POST["use_".$attr])){
+          $this->selected_edit_values[$attr] = TRUE;
+        }else{
+          $this->selected_edit_values[$attr] = FALSE;
+        }
+      }
+    }
+
     /* Save values to object */
     foreach ($this->attributes as $val){
       if ($this->acl_is_writeable($val) && isset ($_POST["$val"])){
@@ -1628,6 +1639,25 @@ class plugin
       }
     }
   }
+
+  
+  function get_multi_edit_values()
+  {
+    $ret = array();
+    foreach($this->selected_edit_values as $attr => $active){
+      if($active){
+        $ret[$attr] = $this->$attr;
+      }
+    }
+    return($ret);
+  }
+
+  function set_multi_edit_value()
+  {
+
+  }
+
 }
+
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
index af39e5f4832c272da215f8715cb6b9b4a01c2cc0..966d77718f9155118309b7f0fdfc31bda8b6ef1f 100644 (file)
@@ -826,7 +826,6 @@ class userManagement extends plugin
       $display= $this->usertab->execute();
 
       /* Don't show buttons if tab dialog requests this */
-      if(isset($this->usertab->by_object)){
       
         $dia = FALSE;
         if(isset($this->usertab->by_object[$this->usertab->current]->dialog)){
@@ -844,7 +843,6 @@ class userManagement extends plugin
           $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
           $display.= "</p>";
         }
-      }
       return ($display);
     }
     
index 97c60aa1ba896d661ac94578dc66de51980fdff9..37101bc6326763b31a6820a8f476b83315af021a 100644 (file)
@@ -93,30 +93,30 @@ class usertabs extends tabs
 
   function save($ignore_account= FALSE)
   {
-    if(!$this->multiple_entries){
+    /* Check for new 'dn', in order to propagate the
+       'dn' to all plugins */
+    $baseobject= $this->by_object['user'];
 
-      /* Check for new 'dn', in order to propagate the
-         'dn' to all plugins */
-      $baseobject= $this->by_object['user'];
+    if ($this->dn != 'new'){
 
-      if ($this->dn != 'new'){
+      $new_dn= $baseobject->new_dn;
 
-        $new_dn= $baseobject->new_dn;
-        if (strtolower($this->dn) != strtolower($new_dn)){
+      echo $new_dn;
 
-          /* Udpate acls */
-          $baseobject->update_acls($this->dn,$new_dn);
-          $baseobject->move($this->dn, $new_dn);
-          $this->by_object['user']= $baseobject;
+      if (strtolower($this->dn) != strtolower($new_dn)){
 
-          /* Did we change ourselves? Update ui object. */
-          change_ui_dn($this->dn, $new_dn);
-        }
-      }
+        /* Udpate acls */
+        $baseobject->update_acls($this->dn,$new_dn);
+    #    $baseobject->move($this->dn, $new_dn);
+        $this->by_object['user']= $baseobject;
 
-      $this->dn= $baseobject->new_dn;
+        /* Did we change ourselves? Update ui object. */
+        change_ui_dn($this->dn, $new_dn);
+      }
     }
 
+    $this->dn= $baseobject->new_dn;
+
     return tabs::save();
   }
 
index 4a31c21f44572e5a1d46c6a9f2460033e2e73903..4828be7bf004e3ec57287a6ca5f5904201d4163d 100644 (file)
@@ -106,9 +106,10 @@ class user extends plugin
       "postalCode");
 
   var $multiple_support = TRUE;
-  var $multiple_handle  = FALSE;
-  var $attrs_to_update  = array();
+  var $multiple_support_active  = FALSE;
+  var $selected_edit_values  = array();
   var $multiple_user_handles  = array();
+
   /* constructor, if 'dn' is set, the node loads the given
      'dn' from LDAP */
   function user (&$config, $dn= NULL)
@@ -120,12 +121,6 @@ class user extends plugin
       $this->attributes=array_merge($this->attributes,$this->govattrs);
     }
 
-    if(is_array($dn)){
-      $this->dn = $dn;
-      $this->multiple_handle = TRUE;
-      return($this->construct_multiple());
-    }
-
     /* Load base attributes */
     plugin::plugin ($config, $dn);
 
@@ -222,103 +217,11 @@ class user extends plugin
     if (isset ($this->attrs['gender'])){
       $this->gender= strtoupper($this->attrs['gender'][0]);
     }
-  
     $this->orig_base = $this->base;
   }
 
 
-  function construct_multiple()
-  {
-    /* Configuration is fine, allways */
-    $this->multiple_user_handles = array();
-    foreach($this->dn as $dn){
-      $this->multiple_user_handles[] = new user($this->config,$dn);
-    } 
-  }
-
-  function save_object_multiple()
-  {
-    foreach(array("pw_storage","base","edit_cert") as $attr){
-      if(isset($_POST["use_".$attr])){
-        $this->attrs_to_update[$attr] = TRUE;
-      }else{
-        $this->attrs_to_update[$attr] = FALSE;
-      }
-    }
-    foreach($this->attributes as $attr){
-      if(isset($_POST["use_".$attr])){
-        $this->attrs_to_update[$attr] = TRUE;
-      }else{
-        $this->attrs_to_update[$attr] = FALSE;
-      }
-    } 
-  }
-  
-  function execute_multiple()
-  {
-    $smarty =get_smarty(); 
-    $u_attrs = array();
-    $d_attrs = array();
-    foreach($this->attributes as $attr){
-      foreach($this->multiple_user_handles as $class){
-        if(!isset($u_attrs[$attr]) && !empty($class->$attr)){
-          $u_attrs[$attr] = $class->$attr;
-        }elseif(isset($u_attrs[$attr]) && !empty($class->$attr)){
-          $d_attrs[$attr] = TRUE;
-        }
-      }
-    }
-    $language= array_merge(array(0 => "&nbsp;") ,get_languages(TRUE));
-    $smarty->assign("preferredLanguage_list", $language);
-    @$smarty->assign("bases", $this->allowedBasesToMoveTo());
-    $smarty->assign("base_select",      $this->base);
-
-    /* Save government mode attributes */
-    if (isset($this->config->current['GOVERNMENTMODE']) &&
-        preg_match('/true/i', $this->config->current['GOVERNMENTMODE'])){
-      $smarty->assign("governmentmode", "true");
-      $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
-          "internet,ivbv", "internet,testa", "internet,ivbv,testa");
-      $smarty->assign("ivbbmodes", $ivbbmodes);
-      foreach ($this->govattrs as $val){
-        $smarty->assign("$val", $this->$val);
-        $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !isset($_SESSION['edit']))));
-      }
-    } else {
-      $smarty->assign("governmentmode", "false");
-    }
-
-    $temp= passwordMethod::get_available_methods();
-    $hashes = $temp['name'];
-    $test= new $temp[$this->pw_storage]($this->config);
-    $is_configurable= $test->is_configurable();
-    $smarty->assign("pwmode", $hashes);
-    $smarty->assign("pwmode_select", $this->pw_storage);
-    $smarty->assign("pw_configurable", $is_configurable);
-
-    foreach($this->attributes as $attr){
-#      if(!isset($u_attrs[$attr])){
-#        $u_attrs[$attr] = "empty";
-#      }
-      
-      if(isset($this->attrs_to_update[$attr]) && $this->attrs_to_update[$attr] == TRUE){
-        $smarty->assign("use_".$attr,TRUE);
-      }else{
-        $smarty->assign("use_".$attr,FALSE);
-      }
-      $smarty->assign($attr,$this->$attr);
-    }
-    foreach(array("pw_storage","base","edit_cert") as $attr){
-      if(isset($this->attrs_to_update[$attr]) && $this->attrs_to_update[$attr] == TRUE){
-        $smarty->assign("use_".$attr,TRUE);
-      }else{
-        $smarty->assign("use_".$attr,FALSE);
-      }
-    }
-
-
-    return($smarty->fetch (get_template_path('multiple_generic.tpl', TRUE, dirname(__FILE__))));
-  }
 
 
   /* execute generates the html output for this node */
@@ -327,7 +230,7 @@ class user extends plugin
     /* Call parent execute */
     plugin::execute();
 
-    if($this->multiple_handle){
+    if($this->multiple_support_active){
       return($this->execute_multiple());
     }
     /* Log view */
@@ -815,6 +718,7 @@ class user extends plugin
 
       $this->set_acl_base('dummy,'.$this->base);
     }
+    echo $this->base."<br>" ;
   }
 
   function rebind($ldap, $referral)
@@ -832,27 +736,9 @@ class user extends plugin
   }
 
   
-  function multiple_save()
-  {
-    foreach($this->multiple_user_handles as $handle){
-      foreach($this->attributes as $attr){
-        if(isset($this->attrs_to_update[$attr]) && $this->attrs_to_update[$attr] == TRUE){
-          $handle->$attr = $this->$attr;         
-        }
-      }
-      $handle->save();
-    }
-  }
-
-
-
   /* Save data to LDAP, depending on is_account we save or delete */
   function save()
   {
-    if($this->multiple_handle){
-      return($this->multiple_save());
-    }
     /* Only force save of changes .... 
        If this attributes aren't changed, avoid saving.
      */
@@ -1170,48 +1056,52 @@ class user extends plugin
       $this->set_acl_base($this->base);
     }
 
-    /* must: sn, givenName, uid */
-    if ($this->sn == "" && ($this->acl_is_writeable("sn",(!is_object($this->parent) && !isset($_SESSION['edit'])) || ($this->is_new)))){
-      $message[]= _("The required field 'Name' is not set.");
-    }
 
-    /* UID already used? */
-    $ldap= $this->config->get_ldap_link();
-    $ldap->cd($this->config->current['BASE']);
-    $ldap->search("(uid=$this->uid)", array("uid"));
-    $ldap->fetch();
-    if ($ldap->count() != 0 && $this->dn == 'new'){
-      $message[]= _("There's already a person with this 'Login' in the database.");
-    }
+    if(!$this->multiple_support_active){
 
-    /* In template mode, the uid and givenName are autogenerated... */
-    if (!$this->is_template){
-      if ($this->givenName == "" && $this->acl_is_writeable("givenName",(!is_object($this->parent) && !isset($_SESSION['edit'])))){
-        $message[]= _("The required field 'Given name' is not set.");
+      /* must: sn, givenName, uid */
+      if ($this->sn == "" && ($this->acl_is_writeable("sn",(!is_object($this->parent) && !isset($_SESSION['edit'])) || ($this->is_new)))){
+        $message[]= _("The required field 'Name' is not set.");
       }
-      if ($this->uid == "" && $this->acl_is_writeable("uid",(!is_object($this->parent) && !isset($_SESSION['edit'])))){
-        $message[]= _("The required field 'Login' is not set.");
+
+      /* UID already used? */
+      $ldap= $this->config->get_ldap_link();
+      $ldap->cd($this->config->current['BASE']);
+      $ldap->search("(uid=$this->uid)", array("uid"));
+      $ldap->fetch();
+      if ($ldap->count() != 0 && $this->dn == 'new'){
+        $message[]= _("There's already a person with this 'Login' in the database.");
       }
-      if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){
-        $ldap->cat($this->new_dn);
-        if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
-          $message[]= _("There's already a person with this 'Name'/'Given name' combination in the database.");
+
+      /* In template mode, the uid and givenName are autogenerated... */
+      if (!$this->is_template){
+        if ($this->givenName == "" && $this->acl_is_writeable("givenName",(!is_object($this->parent) && !isset($_SESSION['edit'])))){
+          $message[]= _("The required field 'Given name' is not set.");
+        }
+        if ($this->uid == "" && $this->acl_is_writeable("uid",(!is_object($this->parent) && !isset($_SESSION['edit'])))){
+          $message[]= _("The required field 'Login' is not set.");
+        }
+        if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){
+          $ldap->cat($this->new_dn);
+          if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){
+            $message[]= _("There's already a person with this 'Name'/'Given name' combination in the database.");
+          }
         }
       }
-    }
 
-    /* Check for valid input */
-    if ($this->is_modified && !is_uid($this->uid)){
-      $message[]= _("The field 'Login' contains invalid characters. Lowercase, numbers and dashes are allowed.");
-    }
-    if (!is_url($this->labeledURI)){
-      $message[]= _("The field 'Homepage' contains an invalid URL definition.");
-    }
-    if (preg_match ("/[\\\\]/", $this->sn)){
-      $message[]= _("The field 'Name' contains invalid characters.");
-    }
-    if (preg_match ("/[\\\\]/", $this->givenName)){
-      $message[]= _("The field 'Given name' contains invalid characters.");
+      /* Check for valid input */
+      if ($this->is_modified && !is_uid($this->uid)){
+        $message[]= _("The field 'Login' contains invalid characters. Lowercase, numbers and dashes are allowed.");
+      }
+      if (!is_url($this->labeledURI)){
+        $message[]= _("The field 'Homepage' contains an invalid URL definition.");
+      }
+      if (preg_match ("/[\\\\]/", $this->sn)){
+        $message[]= _("The field 'Name' contains invalid characters.");
+      }
+      if (preg_match ("/[\\\\]/", $this->givenName)){
+        $message[]= _("The field 'Given name' contains invalid characters.");
+      }
     }
 
     /* Check phone numbers */
@@ -1243,8 +1133,7 @@ class user extends plugin
   /* Indicate whether a password change is needed or not */
   function password_change_needed()
   {
-    
-    return (!$this->multiple_handle && $this->pw_storage != $this->last_pw_storage);
+    return($this->pw_storage != $this->last_pw_storage);
   }
 
 
@@ -1529,9 +1418,85 @@ class user extends plugin
         $ret["plProvidedAcls"][$attr] = $desc;
       }
     }
-
     return($ret);
   }
+
+
+
+
+
+
+
+
+  function get_values_to_update()
+  {
+    $ret = plugin::get_multi_edit_values();
+    return($ret); 
+  }
+
+
+  function save_object_multiple()
+  {
+    foreach(array("pw_storage","base","edit_cert") as $attr){
+      if(isset($_POST["use_".$attr])){
+        $this->selected_edit_values[$attr] = TRUE;
+      }else{
+        $this->selected_edit_values[$attr] = FALSE;
+      }
+    }
+  }
+
+
+  function execute_multiple()
+  {
+    $smarty =get_smarty(); 
+    $language= array_merge(array(0 => "&nbsp;") ,get_languages(TRUE));
+    $smarty->assign("preferredLanguage_list", $language);
+    @$smarty->assign("bases", $this->allowedBasesToMoveTo());
+    $smarty->assign("base_select",      $this->base);
+
+    /* Save government mode attributes */
+    if (isset($this->config->current['GOVERNMENTMODE']) &&
+        preg_match('/true/i', $this->config->current['GOVERNMENTMODE'])){
+      $smarty->assign("governmentmode", "true");
+      $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet",
+          "internet,ivbv", "internet,testa", "internet,ivbv,testa");
+      $smarty->assign("ivbbmodes", $ivbbmodes);
+      foreach ($this->govattrs as $val){
+        $smarty->assign("$val", $this->$val);
+        $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !isset($_SESSION['edit']))));
+      }
+    } else {
+      $smarty->assign("governmentmode", "false");
+    }
+
+    $temp= passwordMethod::get_available_methods();
+    $hashes = $temp['name'];
+    $test= new $temp[$this->pw_storage]($this->config);
+    $is_configurable= $test->is_configurable();
+    $smarty->assign("pwmode", $hashes);
+    $smarty->assign("pwmode_select", $this->pw_storage);
+    $smarty->assign("pw_configurable", $is_configurable);
+
+    foreach($this->attributes as $attr){
+      if(isset($this->selected_edit_values[$attr]) && $this->selected_edit_values[$attr] == TRUE){
+        $smarty->assign("use_".$attr,TRUE);
+      }else{
+        $smarty->assign("use_".$attr,FALSE);
+      }
+      $smarty->assign($attr,$this->$attr);
+    }
+    foreach(array("pw_storage","base","edit_cert") as $attr){
+      if(isset($this->selected_edit_values[$attr]) && $this->selected_edit_values[$attr] == TRUE){
+        $smarty->assign("use_".$attr,TRUE);
+      }else{
+        $smarty->assign("use_".$attr,FALSE);
+      }
+    }
+    return($smarty->fetch (get_template_path('multiple_generic.tpl', TRUE, dirname(__FILE__))));
+  }
+
+
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
index a9c3143fe5e05bf3396de5e154e772e81148bdcb..f77fdb9cd0ed33fbafbf0501d5356c4cae18253e 100644 (file)
@@ -98,6 +98,7 @@
       </div>
      </td>
     </tr>
+<!--
     <tr>
      <td>
       <label for="pw_storage">
       </select>
      </td>
     </tr>
+-->
     <tr>
      <td>
       <label for="edit_cert">