Code

Added chinese to the list of language selections
[gosa.git] / plugins / personal / generic / class_user.inc
index 4117aee961f59e0ffd72c776bfef3880ad82830a..8c1b16b0eeb529d01a4c6888c22484421080458e 100644 (file)
@@ -16,14 +16,11 @@ class user extends plugin
   var $plHeadline= "Generic";
   var $plDescription= "This does something";
 
-  /* CLI vars */
-  var $cli_summary= "Handling of GOsa's user base object";
-  var $cli_description= "Some longer text\nfor help";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /* Plugin specific values */
   var $base= "";
+  var $orig_base= "";
   var $cn= "";
+  var $new_dn= "";
   var $personalTitle= "";
   var $academicTitle= "";
   var $homePostalAddress= "";
@@ -85,7 +82,7 @@ class user extends plugin
 
   /* attribute list for save action */
   var $attributes= array("sn", "givenName", "uid", "personalTitle", "academicTitle",
-      "homePostalAddress", "homePhone", "labeledURI", "o", "ou", "dateOfBirth", "gender","preferredLanguage",
+      "homePostalAddress", "homePhone", "labeledURI", "ou", "o", "dateOfBirth", "gender","preferredLanguage",
       "departmentNumber", "employeeNumber", "employeeType", "l", "st","jpegPhoto",
       "roomNumber", "telephoneNumber", "mobile", "pager", "cn", "userPKCS12",
       "postalAddress", "facsimileTelephoneNumber", "userSMIMECertificate");
@@ -202,6 +199,8 @@ class user extends plugin
     if (isset ($this->attrs['gender'])){
       $this->gender= strtoupper($this->attrs['gender'][0]);
     }
+
+    $this->orig_base = $this->base;
   }
 
 
@@ -219,7 +218,12 @@ class user extends plugin
     } else {
       if(is_array($this->dateOfBirth)){
         $date = $this->dateOfBirth;
-      }else{
+  
+        // Trigger on dates like 1985-04-01, getdate only understands timestamps
+      } else if (!empty($this->dateOfBirth) && !is_numeric($this->dateOfBirth)){
+        $date= getdate(strtotime($this->dateOfBirth));
+
+      } else {
         $date = getdate($this->dateOfBirth);
       } 
     }
@@ -259,7 +263,8 @@ class user extends plugin
     /* Assign prefered langage */
     $language= array(0 => " ", "fr_FR" => ("fr_FR"), "en_EN" => ("en_EN"), 
                                     "de_DE" => ("de_DE"), "it_IT" => ("it_IT"), 
-                                    "nl_NL" => ("nl_NL"), "ru_RU" => ("ru_RU"));
+                                    "nl_NL" => ("nl_NL"), "ru_RU" => ("ru_RU"),
+                                    "zh_CN" => ("zh_CN"));
     $smarty->assign("preferredLanguage_list", $language);
 
     /* Get random number for pictures */
@@ -650,7 +655,8 @@ class user extends plugin
       /* Save base and pw_storage, since these are no LDAP attributes */
       if (isset($_POST['base'])){
         foreach(array("base", "pw_storage") as $val){
-          if(isset($_POST[$val])){
+
+          if(isset($_POST[$val]) && chkacl ($this->acl, "$val") == ""){
             $data= validate($_POST[$val]);
             if ($data != $this->$val){
               $this->is_modified= TRUE;
@@ -844,23 +850,16 @@ class user extends plugin
       $this->attrs["jpegPhoto"] = array();
     }
 
-    /* Build new dn */
-    if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
-      $new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
-    } else {
-      $new_dn= 'cn='.$this->cn.','.get_people_ou().$this->base;
-    }
-
     /* This only gets called when user is renaming himself */
     $ldap= $this->config->get_ldap_link();
-    if ($this->dn != $new_dn){
+    if ($this->dn != $this->new_dn){
 
       /* Write entry on new 'dn' */
-      $this->move($this->dn, $new_dn);
+      $this->move($this->dn, $this->new_dn);
 
       /* Happen to use the new one */
-      change_ui_dn($this->dn, $new_dn);
-      $this->dn= $new_dn;
+      change_ui_dn($this->dn, $this->new_dn);
+      $this->dn= $this->new_dn;
     }
 
 
@@ -947,7 +946,7 @@ class user extends plugin
 
         /* Ok. User exists. Remove him/her when pw_storage has
            changed to be NOT kerberos. */
-        if ($this->pw_storage != "kerberos"){
+        if ($this->pw_storage != $this->config->current['KRBSASL']){
           $ret= kadm5_delete_principal ( $handle, $principal);
 
           if ($ret === FALSE){
@@ -957,8 +956,8 @@ class user extends plugin
 
       } else {
 
-        /* User doesn't exists, create it when pw_storage is kerberos. */
-        if ($this->pw_storage == "kerberos"){
+        /* User doesn't exists, create it when pw_storage is kerberos or SASL. */
+        if ($this->pw_storage == "kerberos" || $this->pw_storage == "sasl" ){
           $ret= kadm5_create_principal ( $handle, $principal);
 
           if ($ret === FALSE){
@@ -993,21 +992,34 @@ class user extends plugin
     $message= plugin::check();
 
     /* Assemble cn */
-    $this->cn= $this->givenName." ".$this->sn;
+    $pt= "";
+    if(isset($this->config->current['INCLUDE_PERSONAL_TITLE']) && preg_match("/true/i",$this->config->current['INCLUDE_PERSONAL_TITLE'])){
+      if(!empty($this->personalTitle)){
+        $pt = $this->personalTitle." ";
+      }
+    }
+    
+    $this->cn= $pt.$this->givenName." ".$this->sn;
 
     /* Permissions for that base? */
     if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
-      $new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
+      $this->new_dn= 'uid='.$this->uid.','.get_people_ou().$this->base;
     } else {
-      $new_dn= 'cn='.$this->cn.','.get_people_ou().$this->base;
+      /* Don't touch dn, if cn hasn't changed */
+      if (isset($this->saved_attributes['cn']) && $this->saved_attributes['cn'] == $this->cn &&
+          $this->orig_base == $this->base){
+        $this->new_dn= $this->dn;
+      } else {
+        $this->new_dn= $this->create_unique_dn('cn', get_people_ou().$this->base);
+      }
     }
 
     $ui= get_userinfo();
-    $acl= get_permissions ($new_dn, $ui->subtreeACL);
-    $acl= get_module_permission($acl, "user", $new_dn);
+    $acl= get_permissions ($this->new_dn, $ui->subtreeACL);
+    $acl= get_module_permission($acl, "user", $this->new_dn);
     if ($this->dn == "new" && chkacl($acl, "create") != ""){
       $message[]= _("You have no permissions to create a user on this 'Base'.");
-    } elseif ($this->dn != $new_dn && $this->dn != "new"){
+    } elseif ($this->dn != $this->new_dn && $this->dn != "new"){
       $acl= get_permissions ($this->dn, $ui->subtreeACL);
       $acl= get_module_permission($acl, "user", $this->dn);
       if (chkacl($acl, "create") != ""){
@@ -1038,10 +1050,8 @@ class user extends plugin
         $message[]= _("The required field 'Login' is not set.");
       }
       if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){
-        $ldap->cd($this->config->current['BASE']);
-        $ldap->search("(cn=".$this->cn.")", array("uid"));
-        $ldap->fetch();
-        if ($ldap->count() != 0 && $this->dn != $new_dn && $this->dn == 'new'){
+        $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.");
         }
       }