Code

Fixed baseSelectDialog parameters
[gosa.git] / plugins / personal / generic / class_user.inc
index 8de21f7e6bdea9449806a6e73c45d4e2ce689432..ec56ed885bf14dc326de4d57bcc74ce677f5445f 100644 (file)
@@ -42,10 +42,10 @@ class user extends plugin
   var $l= "";
   var $st= "";
   var $postalAddress= "";
-  var $dob= "0";
+  var $dateOfBirth;
   var $use_dob= "0";
-  var $gender= "0";
-  var $preferredLanguage= "";
+  var $gender="0";
+  var $preferredLanguage="0";
 
   var $jpegPhoto= "*removed*";
   var $photoData= "";
@@ -76,6 +76,8 @@ class user extends plugin
   var $role= "";
   var $publicVisible= "";
 
+  var $dialog;
+
   /* variables to trigger password changes */
   var $pw_storage= "crypt";
   var $last_pw_storage= "unset";
@@ -83,7 +85,7 @@ class user extends plugin
 
   /* attribute list for save action */
   var $attributes= array("sn", "givenName", "uid", "personalTitle", "academicTitle",
-      "homePostalAddress", "homePhone", "labeledURI", "o", "ou", "dob", "gender","preferredLanguage",
+      "homePostalAddress", "homePhone", "labeledURI", "o", "ou", "dateOfBirth", "gender","preferredLanguage",
       "departmentNumber", "employeeNumber", "employeeType", "l", "st",
       "roomNumber", "telephoneNumber", "mobile", "pager", "cn", "userPKCS12",
       "postalAddress", "facsimileTelephoneNumber", "userSMIMECertificate");
@@ -103,27 +105,30 @@ class user extends plugin
      'dn' from LDAP */
   function user ($config, $dn= NULL)
   {
-    /* Configuration is fine, allways */
     $this->config= $config;
+    /* Configuration is fine, allways */
+    if ($this->config->current['GOVERNMENTMODE']){
+      $this->attributes=array_merge($this->attributes,$this->govattrs);
+    }
 
     /* Load base attributes */
     plugin::plugin ($config, $dn);
 
-    /* Load government mode attributes */
     if ($this->config->current['GOVERNMENTMODE']){
+      /* Fix public visible attribute if unset */
+      if (!isset($this->attrs['publicVisible'])){
+        $this->publicVisible == "nein";
+      }
+    }
 
+    /* Load government mode attributes */
+    if ($this->config->current['GOVERNMENTMODE']){
       /* Copy all attributs */
       foreach ($this->govattrs as $val){
         if (isset($this->attrs["$val"][0])){
           $this->$val= $this->attrs["$val"][0];
         }
       }
-
-      /* Fix public visible attribute if unset */
-      if (!isset($this->attrs['publicVisible'])){
-        $this->publicVisible == "nein";
-      }
-
     }
 
     /* Create me for new accounts */
@@ -182,12 +187,12 @@ class user extends plugin
       $this->last_pw_storage= $this->pw_storage;
     }
 
-    /* Generate dob entry */
+    /* Generate dateOfBirth entry */
     if (isset ($this->attrs['dateOfBirth'])){
       /* This entry is ISO 8601 conform */
       list($year, $month, $day)= split("-", $this->attrs['dateOfBirth'][0], 3);
     
-      $this->dob=array( 'mon'=> $month,"mday"=> $day,"year"=> $year);
+      $this->dateOfBirth=array( 'mon'=> $month,"mday"=> $day,"year"=> $year);
       $this->use_dob= "1";
     } else {
       $this->use_dob= "0";
@@ -196,26 +201,26 @@ class user extends plugin
     /* Put gender attribute to upper case */
     if (isset ($this->attrs['gender'])){
       $this->gender= strtoupper($this->attrs['gender'][0]);
-    }  
+    }
   }
 
 
   /* execute generates the html output for this node */
   function execute()
   {
-       /* Call parent execute */
-       plugin::execute();
+    /* Call parent execute */
+    plugin::execute();
 
     $smarty= get_smarty();
 
     /* Fill calendar */
-    if ($this->dob == "0"){
+    if ($this->dateOfBirth == "0"){
       $date= getdate();
     } else {
-      if(is_array($this->dob)){
-        $date = $this->dob;
+      if(is_array($this->dateOfBirth)){
+        $date = $this->dateOfBirth;
       }else{
-        $date = getdate($this->dob);
+        $date = getdate($this->dateOfBirth);
       } 
     }
 
@@ -252,7 +257,9 @@ class user extends plugin
     $smarty->assign("gender_list", $sex);
 
     /* 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"));
+    $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"));
     $smarty->assign("preferredLanguage_list", $language);
 
     /* Get random number for pictures */
@@ -266,6 +273,31 @@ class user extends plugin
       return;
     }
 
+    /* Base select dialog */
+    $once = true;
+    foreach($_POST as $name => $value){
+      if(preg_match("/^chooseBase/",$name) && $once){
+        $once = false;
+        $this->dialog = new baseSelectDialog($this->config,$this,$this->allowedBasesToMoveTo());
+        $this->dialog->setCurrentBase($this->base);
+      }
+    }
+
+    /* Dialog handling */
+    if(is_object($this->dialog)){
+      /* Must be called before save_object */
+      $this->dialog->save_object();
+   
+      if($this->dialog->isClosed()){
+        $this->dialog = false;
+      }elseif($this->dialog->isSelected()){
+        $this->base = $this->dialog->isSelected();
+        $this->dialog= false;
+      }else{
+        return($this->dialog->execute());
+      }
+    }
+
     /* Want picture edit dialog? */
     if (isset($_POST['edit_picture'])){
       /* Save values for later recovery, in case some presses
@@ -318,7 +350,7 @@ class user extends plugin
       $this->dialog= FALSE;
     }
 
-    /* Toggle dob information */
+    /* Toggle dateOfBirth information */
     if (isset($_POST['set_dob'])){
       $this->use_dob= ($this->use_dob == "0")?"1":"0";
     }
@@ -439,7 +471,7 @@ class user extends plugin
     /* Show us the edit screen */
     @$smarty->assign("bases", $this->allowedBasesToMoveTo());
 #  $smarty->assign("bases", $this->config->idepartments);
-    $smarty->assign("base_select", $this->base);
+    $smarty->assign("base_select",      $this->base);
     $smarty->assign("selectmode",       chkacl($this->acl, "create"));
     $smarty->assign("certificatesACL",  chkacl($this->acl, "certificates"));
     $smarty->assign("jpegPhotoACL",     chkacl($this->acl, "jpegPhoto"));
@@ -449,7 +481,7 @@ class user extends plugin
       $this->pw_storage= $this->config->current['HASH'];
     }
 
-    $temp   = passwordMethod::get_available_methods();
+    $temp   = @passwordMethod::get_available_methods();
     $hashes = $temp['name'];
     
     $smarty->assign("pwmode", $hashes);
@@ -511,6 +543,7 @@ class user extends plugin
   {
     $ldap= $this->config->get_ldap_link();
     $ldap->rmdir ($this->dn);
+    show_ldap_error($ldap->get_error(), _("Removing generic user account failed"));
 
     /* Delete references to groups */
     $ldap->cd ($this->config->current['BASE']);
@@ -594,6 +627,16 @@ class user extends plugin
   /* Save data to LDAP, depending on is_account we save or delete */
   function save()
   {
+    /* Only force save of changes .... 
+       If this attributes aren't changed, avoid saving.
+     */
+    if ($this->use_dob == "1"){
+      $this->dateOfBirth= date("Y-m-d", $this->dateOfBirth);
+    }
+    if($this->gender=="0") $this->gender ="";
+    if($this->preferredLanguage=="0") $this->preferredLanguage ="";
+    
     /* First use parents methods to do some basic fillup in $this->attrs */
     plugin::save ();
 
@@ -601,7 +644,7 @@ class user extends plugin
     $tmp= array();
     foreach ($this->attrs['objectClass'] as $key => $set){
       $found= false;
-      foreach (array("ivbbEntry", "gosaUserTemplate") as $val){
+      foreach (array("ivbbentry", "gosaUserTemplate") as $val){
         if (preg_match ("/^$set$/i", $val)){
           $found= true;
           break;
@@ -623,7 +666,7 @@ class user extends plugin
 
     /* Hard coded government mode? */
     if ($this->config->current['GOVERNMENTMODE'] != 'false'){
-      $this->attrs['objectClass'][]= "ivbbEntry";
+      $this->attrs['objectClass'][]= "ivbbentry";
 
       /* Copy standard attributes */
       foreach ($this->govattrs as $val){
@@ -655,24 +698,22 @@ class user extends plugin
       $remove_userCertificate= true;
     }
 
-    /* Special handling for dob value */
-    if ($this->use_dob == "1"){
-      $this->attrs["dob"]= date("Y-m-d", $this->dob);
-    } else {
+    /* Special handling for dateOfBirth value */
+    if ($this->use_dob != "1"){
       if ($this->new) {
-        unset($this->attrs["dob"]);
+        unset($this->attrs["dateOfBirth"]);
       } else {
-        $this->attrs["dob"]= array();
+        $this->attrs["dateOfBirth"]= array();
       }
     }
-    if ($this->gender == "0"){
+    if (!$this->gender){
       if ($this->new) {
         unset($this->attrs["gender"]);
       } else {
         $this->attrs["gender"]= array();
       }
     }
-      if ($this->preferredLanguage == "0"){
+    if (!$this->preferredLanguage){
       if ($this->new) {
         unset($this->attrs["preferredLanguage"]);
       } else {
@@ -770,7 +811,7 @@ class user extends plugin
 
     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
        new entries. So do a check first... */
-    $ldap->cat ($this->dn);
+    $ldap->cat ($this->dn, array('dn'));
     if ($ldap->fetch()){
       $mode= "modify";
     } else {
@@ -788,9 +829,10 @@ class user extends plugin
         $this->attributes, "Save via $mode");
 
     /* Finally write data with selected 'mode' */
+    $this->cleanup();
     $ldap->cd ($this->dn);
     $ldap->$mode ($this->attrs);
-    if (show_ldap_error($ldap->get_error())){
+    if (show_ldap_error($ldap->get_error(), _("Saving generic user account failed"))){
       return (1);
     }
 
@@ -882,6 +924,9 @@ class user extends plugin
       $this->handle_post_events("modify");
     }
 
+    /* Fix tagging if needed */
+    $this->handle_object_tagging();
+
     return (0);
   }
 
@@ -889,15 +934,12 @@ class user extends plugin
   /* Check formular input */
   function check()
   {
-    $message= array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
 
     /* Assemble cn */
     $this->cn= $this->givenName." ".$this->sn;
 
-    if(preg_match("/[^a-z0-9]/",$this->uid)){
-      $message[]=_("Invalid characters in uid.") ;
-    }
-
     /* 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;
@@ -965,9 +1007,6 @@ class user extends plugin
     }
 
     /* Check phone numbers */
-    if (!is_phone_nr($this->homePhone)){
-      $message[]= _("The field 'Phone' contains an invalid phone number.");
-    }
     if (!is_phone_nr($this->telephoneNumber)){
       $message[]= _("The field 'Phone' contains an invalid phone number.");
     }
@@ -1160,13 +1199,17 @@ class user extends plugin
       $ldap->search("(&(objectClass=posixGroup)(memberUid=".$_SESSION['ui']->username."))",array("gosaSubtreeACL"));
        
       while($attrs = $ldap->fetch()){
-        foreach($attrs['gosaSubtreeACL'] as $attr){
-          if((preg_match("/:user#/",$attr))||(preg_match("/:all/",$attr))){
-            $s =  preg_replace("/^.*ou=groups,/","",$attrs['dn']);
-
-            foreach($this->config->idepartments as $key => $dep) {
-              if(preg_match("/".$s."/i",$key)){
-                $allowed[$key] = $dep;
+    
+        if(isset($attrs['gosaSubtreeACL'])){
+        
+          foreach($attrs['gosaSubtreeACL'] as $attr){
+            if((preg_match("/:user#/",$attr))||(preg_match("/:all/",$attr))){
+              $s =  preg_replace("/^.*ou=groups,/","",$attrs['dn']);
+
+              foreach($this->config->idepartments as $key => $dep) {
+                if(preg_match("/".$s."/i",$key)){
+                  $allowed[$key] = $dep;
+                }
               }
             }
           }
@@ -1188,10 +1231,59 @@ class user extends plugin
   } 
 
 
+  function getCopyDialog()
+  {
+    $str = "";
+
+    $_SESSION['binary'] = $this->photoData; 
+    $_SESSION['binarytype']= "image/jpeg";
+
+    /* Get random number for pictures */
+    srand((double)microtime()*1000000); 
+    $rand = rand(0, 10000);
+
+    $smarty = get_smarty();
+
+    $smarty->assign("passwordTodo","clear");
 
+    if(isset($_POST['passwordTodo'])){
+      $smarty->assign("passwordTodo",$_POST['passwordTodo']);
+    }
+
+    $smarty->assign("sn",       $this->sn);
+    $smarty->assign("givenName",$this->givenName);
+    $smarty->assign("uid",      $this->uid);
+    $smarty->assign("rand",     $rand);
+    $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
+
+
+    $ret = array();
+    $ret['string'] = $str;
+    $ret['status'] = "";  
+    return($ret);
+  }
+
+  function saveCopyDialog()
+  {
 
+    if((isset($_FILES['picture_file']['tmp_name'])) && ($_FILES['picture_file']['size'] > 0)){
+      $this->set_picture($_FILES['picture_file']['tmp_name']);
+    }
 
+    /* Remove picture? */
+    if (isset($_POST['picture_remove'])){
+      $this->jpegPhoto= "*removed*";
+      $this->set_picture ("./images/default.jpg");
+      $this->is_modified= TRUE;
+    }
 
+    $attrs = array("uid","givenName","sn");
+    foreach($attrs as $attr){
+      if(isset($_POST[$attr])){
+        $this->$attr = $_POST[$attr];
+      }
+    } 
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: