diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 33c00af16a2..5c0dede1bbc 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -443,6 +443,7 @@ class Contact extends CommonObject // Mis a jour contact $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET"; $sql.= " birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null"); + $sql.= ", photo = ".($this->photo? "'".$this->photo."'" : "null"); if ($user) $sql .= ", fk_user_modif=".$user->id; $sql.= " WHERE rowid=".$this->db->escape($id); diff --git a/htdocs/contact/perso.php b/htdocs/contact/perso.php index 8bebb6f0cfb..89b8be57e35 100644 --- a/htdocs/contact/perso.php +++ b/htdocs/contact/perso.php @@ -50,11 +50,71 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact $object->birthday = dol_mktime(0,0,0,$_POST["birthdaymonth"],$_POST["birthdayday"],$_POST["birthdayyear"]); $object->birthday_alert = $_POST["birthday_alert"]; + if (GETPOST('deletephoto')) $object->photo=''; + elseif (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']); + $result = $object->update_perso($id, $user); if ($result > 0) { $object->old_name=''; $object->old_firstname=''; + // Logo/Photo save + $dir= $conf->societe->dir_output.'/contact/' . get_exdir($object->id,2,0,1,$object,'contact').'/photos'; + + $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']); + if ($file_OK) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + if (GETPOST('deletephoto')) + { + require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; + $fileimg=$conf->societe->dir_output.'/contact/'.get_exdir($object->id,2,0,1,$object,'contact').'/photos/'.$object->photo; + $dirthumbs=$conf->societe->dir_output.'/contact/'.get_exdir($object->id,2,0,1,$object,'contact').'/photos/thumbs'; + dol_delete_file($fileimg); + dol_delete_dir_recursive($dirthumbs); + } + + if (image_format_supported($_FILES['photo']['name']) > 0) + { + dol_mkdir($dir); + + if (@is_dir($dir)) + { + $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']); + if (! dol_move_uploaded_file($_FILES['photo']['tmp_name'],$newfile,1,0,$_FILES['photo']['error']) > 0) + { + setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors'); + } + else + { + // Create small thumbs for company (Ratio is near 16/9) + // Used on logon for example + $imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality); + + // Create mini thumbs for company (Ratio is near 16/9) + // Used on menu or for setup page for example + $imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality); + } + } + } + else + { + setEventMessages("ErrorBadImageFormat", null, 'errors'); + } + } + else + { + switch($_FILES['photo']['error']) + { + case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini + case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form + $errors[] = "ErrorFileSizeTooLarge"; + break; + case 3: //uploaded file was only partially uploaded + $errors[] = "ErrorFilePartiallyUploaded"; + break; + } + } } else { @@ -98,6 +158,20 @@ if ($action == 'edit') // Ref print '
| '.$langs->trans("Delete").' |
| '.$langs->trans("PhotoFile").' |