Code

Added saving and loading of postalCode / street. Closes #1138.
[gosa.git] / gosa-core / plugins / personal / generic / class_user.inc
index 9d3f500a9cd07ed3b87b191e3d0d94744e1d9d9c..f6de8cfad0f850a579116e6a91127c0270ed2d4f 100644 (file)
@@ -116,7 +116,7 @@ class user extends plugin
   var $attributes= array("sn", "givenName", "uid", "personalTitle", "academicTitle",
       "homePostalAddress", "homePhone", "labeledURI", "ou", "o", "dateOfBirth", "gender","preferredLanguage",
       "departmentNumber", "employeeNumber", "employeeType", "l", "st","jpegPhoto",
-      "roomNumber", "telephoneNumber", "mobile", "pager", "cn", "userPKCS12",
+      "roomNumber", "telephoneNumber", "mobile", "pager", "cn", "userPKCS12", "street", "postalCode",
       "postalAddress", "facsimileTelephoneNumber", "userSMIMECertificate", "gosaLoginRestriction", "manager");
 
   var $objectclasses= array("top", "person", "organizationalPerson", "inetOrgPerson",
@@ -580,7 +580,7 @@ class user extends plugin
 
     /* Prepare password hashes */
     if ($this->pw_storage == ""){
-      $this->pw_storage= $this->config->get_cfg_value("hash");
+      $this->pw_storage= $this->config->get_cfg_value("passwordDefaultHash");
     }
 
     $temp= passwordMethod::get_available_methods();
@@ -796,7 +796,8 @@ class user extends plugin
       plugin::save_object ();
 
       /* Refresh base */
-      if ($this->acl_is_moveable($this->base)){
+      if ($this->acl_is_moveable($this->base) || 
+            ($this->dn == "new" && $this->acl_is_createable($this->base))){
         if (!$this->baseSelector->update()) {
           msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
         }
@@ -986,72 +987,57 @@ class user extends plugin
     /* Special handling for attribute jpegPhote needed, scale image via
        image magick to 147x200 pixels and inject resulting data. */
     if ($this->jpegPhoto == "*removed*"){
-    
-      /* Reset attribute to avoid writing *removed* as value */    
-      $this->attrs["jpegPhoto"] = array();
-
-    } else {
-
-      /* Fallback if there's no image magick inside PHP */
-      if (!function_exists("imagick_blob2image")){
-        /* Get temporary file name for conversation */
-        $fname = tempnam (TEMP_DIR, "GOsa");
-  
-        /* Open file and write out photoData */
-        $fp = fopen ($fname, "w");
-        fwrite ($fp, $this->photoData);
-        fclose ($fp);
-
-        /* Build conversation query. Filename is generated automatically, so
-           we do not need any special security checks. Exec command and save
-           output. For PHP safe mode, you'll need a configuration which respects
-           image magick as executable... */
-        $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
-        @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
-            $query, "Execute");
-  
-        /* Read data written by convert */
-        $output= "";
-        $sh= popen($query, 'r');
-        while (!feof($sh)){
-          $output.= fread($sh, 4096);
-        }
-        pclose($sh);
-
-        unlink($fname);
 
-        /* Save attribute */
-        $this->attrs["jpegPhoto"] = $output;
+        /* Reset attribute to avoid writing *removed* as value */    
+        $this->attrs["jpegPhoto"] = array();
 
-      } else {
-
-        /* Load the new uploaded Photo */
-        if(!$handle  =  imagick_blob2image($this->photoData))  {
-          new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image");
-        }
+    } else {
 
-        /* Resizing image to 147x200 and blur */
-        if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){
-          new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image");
-        }
+       if(class_exists('Imagick')){
+
+            $im = new Imagick();
+            $im->readImageBlob($this->photoData);
+            $im->setImageOpacity(1.0);
+            $im->resizeImage(147,200,Imagick::FILTER_UNDEFINED,0.5,TRUE);
+            $im->setCompressionQuality(90);
+            $im->setImageFormat('jpeg');
+            $this->attrs["jpegPhoto"] = $im->getImageBlob();
+
+        }elseif(exec('convert')){
+
+            /* Get temporary file name for conversation */
+            $fname = tempnam (TEMP_DIR, "GOsa");
+
+            /* Open file and write out photoData */
+            $fp = fopen ($fname, "w");
+            fwrite ($fp, $this->photoData);
+            fclose ($fp);
+
+            /* Build conversation query. Filename is generated automatically, so
+               we do not need any special security checks. Exec command and save
+               output. For PHP safe mode, you'll need a configuration which respects
+               image magick as executable... */
+            $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -";
+            @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
+                    $query, "Execute");
+
+            /* Read data written by convert */
+            $output= "";
+            $sh= popen($query, 'r');
+            while (!feof($sh)){
+                $output.= fread($sh, 4096);
+            }
+            pclose($sh);
 
-        /* Converting image to JPEG */
-        if(!imagick_convert($handle,"JPEG")) {
-          new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg");
-        }
+            unlink($fname);
 
-        /* Creating binary Code for the Image */
-        if(!$dump = imagick_image2blob($handle)){
-          new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image");
+            /* Save attribute */
+            $this->attrs["jpegPhoto"] = $output;
+        }else{
+            msg_dialog::display(_("Error"), 
+                    _("Cannot save user picture, GOsa requires the package 'imagemagick' or 'php5-imagick' to be installed!"), 
+                    ERROR_DIALOG);
         }
-
-        /* Sending Image */
-        $output=  $dump;
-
-        /* Save attribute */
-        $this->attrs["jpegPhoto"] = $output;
-      }
-
     }
 
     /* This only gets called when user is renaming himself */
@@ -1504,6 +1490,7 @@ class user extends plugin
 
     /* Get base */
     $this->base= preg_replace('/^[^,]+,'.preg_quote(get_people_ou(), '/').'/i', '', $dn);
+    $this->baseSelector->setBase($this->base);
 
     if($this->governmentmode){
 
@@ -1538,13 +1525,18 @@ class user extends plugin
       $this->givenName= $this->parent->givenName;
     }
 
-    if ($this->dateOfBirth) {
+
+    /* Generate dateOfBirth entry */
+    if (isset ($this->attrs['dateOfBirth'])){
       /* This entry is ISO 8601 conform */
-      list($year, $month, $day)= explode("-", $this->dateOfBirth, 3);
-    
+      list($year, $month, $day)= explode("-", $this->attrs['dateOfBirth'][0], 3);
+
       #TODO: use $lang to convert date
       $this->dateOfBirth= "$day.$month.$year";
+    } else {
+      $this->dateOfBirth= "";
     }
+
   }