diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 4174ad16a06..2db5523c5bd 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -35,6 +35,7 @@ require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; @@ -277,12 +278,72 @@ if (empty($reshook)) $action = 'edit'; } + if (! $error) { $contactid=GETPOST("contactid",'int'); $object->fetch($contactid); + // Photo save + $dir = $conf->societe->dir_output."/contact/".$object->id."/photos"; + $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']); + if ($file_OK) + { + if (GETPOST('deletephoto')) + { + $fileimg=$dir.'/'.$object->photo; + $dirthumbs=$dir.'/thumbs'; + dol_delete_file($fileimg); + dol_delete_dir_recursive($dirthumbs); + $object->photo = ''; + } + + if (image_format_supported($_FILES['photo']['name']) > 0) + { + dol_mkdir($dir); + + if (@is_dir($dir)) + { + $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']); + $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1); + + if (! $result > 0) + { + $errors[] = "ErrorFailedToSaveFile"; + } + else + { + $object->photo = dol_sanitizeFileName($_FILES['photo']['name']); + // 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 + { + $errors[] = "ErrorBadImageFormat"; + } + } + 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; + } + } + $object->oldcopy = clone$object; $object->old_lastname = GETPOST("old_lastname"); @@ -699,7 +760,7 @@ else print ''."\n"; } - print '
'; + print ''; print ''; print ''; print ''; @@ -906,6 +967,23 @@ else else print $langs->trans("NoDolibarrAccess"); print ''; + // Photo + print ''; + print ''.fieldLabel('Photo','photoinput').''; + print ''; + if ($object->photo) { + print $form->showphoto('contact',$object); + print "
\n"; + } + print ''; + if ($object->photo) print ''; + //print ''; + print ''; + print '
'.$langs->trans("Delete").'

'.$langs->trans("PhotoFile").'
'; + + print ''; + print ''; + print ''; print dol_fiche_end(); @@ -973,12 +1051,12 @@ else // Name print ''.$langs->trans("Lastname").' / '.$langs->trans("Label").''.$object->lastname.''; - print ''.$langs->trans("Firstname").''.$object->firstname.''; + print ''.$langs->trans("Firstname").''.$object->firstname.''; // Company if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) { - print ''.$langs->trans("ThirdParty").''; + print ''.$langs->trans("ThirdParty").''; if ($object->socid > 0) { $objsoc->fetch($object->socid); @@ -988,30 +1066,44 @@ else { print $langs->trans("ContactNotLinkedToCompany"); } - print ''; + print ''; } + // Photo + if ($object->photo) + { + print ''; + print $form->showphoto('contact',$object); + print ''; + } else { + print ''; + print ' '; + print ''; + } + + print ''; + // Civility - print ''.$langs->trans("UserTitle").''; + print ''.$langs->trans("UserTitle").''; print $object->getCivilityLabel(); print ''; // Role - print ''.$langs->trans("PostOrFunction").''.$object->poste.''; + print ''.$langs->trans("PostOrFunction").''.$object->poste.''; // Address - print ''.$langs->trans("Address").''; + print ''.$langs->trans("Address").''; dol_print_address($object->address,'gmap','contact',$object->id); print ''; // Zip/Town - print ''.$langs->trans("Zip").' / '.$langs->trans("Town").''; + print ''.$langs->trans("Zip").' / '.$langs->trans("Town").''; print $object->zip; if ($object->zip) print ' '; print $object->town.''; // Country - print ''.$langs->trans("Country").''; + print ''.$langs->trans("Country").''; $img=picto_from_langcode($object->country_code); if ($img) print $img.' '; print $object->country; @@ -1020,7 +1112,7 @@ else // State if (empty($conf->global->SOCIETE_DISABLE_STATE)) { - print ''.$langs->trans('State').''.$object->state.''; + print ''.$langs->trans('State').''.$object->state.''; } // Phone diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 0f9f74a6dbc..33864376ac3 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -73,6 +73,7 @@ class Contact extends CommonObject var $code; var $email; var $skype; + var $photo; var $jabberid; var $phone_pro; var $phone_perso; @@ -240,6 +241,7 @@ class Contact extends CommonObject $this->phone_mobile=trim($this->phone_mobile); $this->jabberid=trim($this->jabberid); $this->skype=trim($this->skype); + $this->photo=trim($this->photo); $this->fax=trim($this->fax); $this->zip=(empty($this->zip)?'':$this->zip); $this->town=(empty($this->town)?'':$this->town); @@ -264,6 +266,7 @@ class Contact extends CommonObject $sql .= ", fax='".$this->db->escape($this->fax)."'"; $sql .= ", email='".$this->db->escape($this->email)."'"; $sql .= ", skype='".$this->db->escape($this->skype)."'"; + $sql .= ", photo='".$this->db->escape($this->photo)."'"; $sql .= ", note_private = ".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null"); $sql .= ", note_public = ".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null"); $sql .= ", phone = ".(isset($this->phone_pro)?"'".$this->db->escape($this->phone_pro)."'":"null"); @@ -392,7 +395,7 @@ class Contact extends CommonObject if ($this->phone_perso && ! empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso; if ($this->phone_mobile && ! empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile; if ($this->fax && ! empty($conf->global->LDAP_CONTACT_FIELD_FAX)) $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax; - if ($this->skype && ! empty($conf->global->LDAP_CONTACT_FIELD_SKYPE)) $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype; + if ($this->skype && ! empty($conf->global->LDAP_CONTACT_FIELD_SKYPE)) $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype; if ($this->note_private && ! empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = $this->note_private; if ($this->email && ! empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email; @@ -518,6 +521,7 @@ class Contact extends CommonObject $sql.= " c.fk_departement,"; $sql.= " c.birthday,"; $sql.= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email, c.jabberid, c.skype,"; + $sql.= " c.photo,"; $sql.= " c.priv, c.note_private, c.note_public, c.default_lang, c.no_email, c.canvas,"; $sql.= " c.import_key,"; $sql.= " co.label as country, co.code as country_code,"; @@ -573,6 +577,7 @@ class Contact extends CommonObject $this->email = $obj->email; $this->jabberid = $obj->jabberid; $this->skype = $obj->skype; + $this->photo = $obj->photo; $this->priv = $obj->priv; $this->mail = $obj->email; @@ -909,12 +914,12 @@ class Contact extends CommonObject $label = '' . $langs->trans("ShowContact") . ''; $label.= '
' . $langs->trans("Name") . ': '.$this->getFullName($langs); //if ($this->civility_id) $label.= '
' . $langs->trans("Civility") . ': '.$this->civility_id; // TODO Translate cibilty_id code - $label.= '
' . $langs->trans("Poste") . ': '.$this->poste; - $label.= '
' . $langs->trans("EMail") . ': '.$this->email; + if (! empty($this->poste)) $label.= '
' . $langs->trans("Poste") . ': '.$this->poste; + if (! empty($this->email)) $label.= '
' . $langs->trans("EMail") . ': '.$this->email; $phonelist=array(); if ($this->phone_pro) $phonelist[]=$this->phone_pro; if ($this->phone_mobile) $phonelist[]=$this->phone_mobile; - if ($this->phone_pesro) $phonelist[]=$this->phone_perso; + if ($this->phone_perso) $phonelist[]=$this->phone_perso; $label.= '
' . $langs->trans("Phone") . ': '.join(', ',$phonelist); $label.= '
' . $langs->trans("Address") . ': '.dol_format_address($this, 1, ' ', $langs); diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 40d68bec667..8d69e58bad3 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5155,6 +5155,11 @@ class Form $smallfile=preg_replace('/(\.png|\.gif|\.jpg|\.jpeg|\.bmp)/i','_small\\1',$smallfile); if ($object->logo) $file=$id.'/logos/thumbs/'.$smallfile; } + if ($modulepart=='contact') + { + $dir=$conf->societe->multidir_output[$entity].'/contact'; + $file=$id.'/photos/'.$object->photo; + } else if ($modulepart=='userphoto') { $dir=$conf->user->dir_output; diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index f9b6bbf8b61..2f49b37f716 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1926,6 +1926,16 @@ function dol_check_secure_access_document($modulepart,$original_file,$entity,$fu $sqlprotectagainstexternals = "SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX."societe WHERE rowid='".$db->escape($refname)."' AND entity IN (".getEntity('societe', 1).")"; } + // Wrapping for contact + else if ($modulepart == 'contact') + { + if ($fuser->rights->societe->lire) + { + $accessallowed=1; + } + $original_file=$conf->societe->multidir_output[$entity].'/contact/'.$original_file; + } + // Wrapping for invoices else if ($modulepart == 'facture' || $modulepart == 'invoice') { diff --git a/htdocs/install/mysql/migration/3.8.0-3.9.0.sql b/htdocs/install/mysql/migration/3.8.0-3.9.0.sql index 8bda380c0dd..d8b6ce12ea4 100755 --- a/htdocs/install/mysql/migration/3.8.0-3.9.0.sql +++ b/htdocs/install/mysql/migration/3.8.0-3.9.0.sql @@ -52,5 +52,6 @@ ALTER TABLE llx_payment_salary CHANGE COLUMN fk_user_creat fk_user_author intege ALTER TABLE llx_adherent ADD COLUMN pass_crypted varchar(128) after pass; +ALTER TABLE llx_paiement ADD COLUMN ref varchar(30) NOT NULL AFTER rowid; -ALTER TABLE llx_paiement ADD COLUMN ref varchar(30) NOT NULL AFTER rowid; \ No newline at end of file +ALTER TABLE llx_socpeople ADD COLUMN photo varchar(255) AFTER skype; diff --git a/htdocs/install/mysql/tables/llx_socpeople.sql b/htdocs/install/mysql/tables/llx_socpeople.sql index 4b99598a3b9..b9aad05b956 100644 --- a/htdocs/install/mysql/tables/llx_socpeople.sql +++ b/htdocs/install/mysql/tables/llx_socpeople.sql @@ -43,6 +43,7 @@ create table llx_socpeople email varchar(255), jabberid varchar(255), skype varchar(255), + photo varchar(255), no_email smallint NOT NULL DEFAULT 0, priv smallint NOT NULL DEFAULT 0, fk_user_creat integer DEFAULT 0, -- user qui a creel'enregistrement