2006-02-25 00:16:35 +01:00
< ? php
2018-09-09 09:36:12 +02:00
/* Copyright ( C ) 2004 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2019-10-22 15:21:41 +02:00
* Copyright ( C ) 2004 - 2019 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-09-09 09:36:12 +02:00
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2017 Regis Houssin < regis . houssin @ inodbox . com >
2018-09-09 09:36:12 +02:00
* Copyright ( C ) 2007 Franky Van Liedekerke < franky . van . liedekerke @ telenet . be >
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2019-01-28 21:39:22 +01:00
* Copyright ( C ) 2013 - 2016 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2018-09-09 09:36:12 +02:00
* Copyright ( C ) 2014 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
2021-03-18 22:29:08 +01:00
* Copyright ( C ) 2018 - 2021 Frédéric France < frederic . france @ netlogic . fr >
2019-01-02 08:37:26 +01:00
* Copyright ( C ) 2019 Josep Lluís Amador < joseplluis @ lliuretic . cat >
2020-04-27 17:35:14 +02:00
* Copyright ( C ) 2020 Open - Dsi < support @ open - dsi . fr >
2006-02-25 00:16:35 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2006-02-25 00:16:35 +01:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2006-02-25 00:16:35 +01:00
*/
/**
2014-09-18 21:18:25 +02:00
* \file htdocs / contact / card . php
2008-08-06 15:15:59 +02:00
* \ingroup societe
2011-01-05 18:43:58 +01:00
* \brief Card of a contact
2008-08-06 15:15:59 +02:00
*/
2006-02-25 00:16:35 +01:00
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php' ;
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' ;
2013-07-10 12:28:28 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php' ;
2015-10-04 17:25:46 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php' ;
2022-04-22 13:47:58 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php' ;
2012-09-19 17:53:09 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2013-04-09 17:18:07 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2019-01-02 08:37:26 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php' ;
2013-07-10 12:28:28 +02:00
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
2019-01-02 08:37:26 +01:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2018-05-26 20:32:23 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'companies' , 'users' , 'other' , 'commercial' ));
2006-02-25 00:16:35 +01:00
2019-11-13 19:35:02 +01:00
$mesg = '' ; $error = 0 ; $errors = array ();
2011-04-06 16:26:43 +02:00
2019-11-13 19:35:02 +01:00
$action = ( GETPOST ( 'action' , 'alpha' ) ? GETPOST ( 'action' , 'alpha' ) : 'view' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
$backtopage = GETPOST ( 'backtopage' , 'alpha' );
2021-01-22 13:17:27 +01:00
$cancel = GETPOST ( 'cancel' , 'alpha' );
2019-11-13 19:35:02 +01:00
$id = GETPOST ( 'id' , 'int' );
2020-11-05 20:30:09 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2009-11-29 17:36:01 +01:00
2011-06-30 15:25:32 +02:00
$object = new Contact ( $db );
2012-09-19 17:53:09 +02:00
$extrafields = new ExtraFields ( $db );
2011-06-30 15:25:32 +02:00
2013-04-01 19:43:26 +02:00
// fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2013-04-01 19:43:26 +02:00
2019-09-14 11:26:31 +02:00
$socialnetworks = getArrayOfSocialNetworks ();
2010-11-03 12:39:40 +01:00
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
2011-09-13 14:00:37 +02:00
$object -> getCanvas ( $id );
2019-11-13 19:35:02 +01:00
$objcanvas = null ;
$canvas = ( ! empty ( $object -> canvas ) ? $object -> canvas : GETPOST ( " canvas " ));
2021-02-23 21:16:15 +01:00
if ( ! empty ( $canvas )) {
2020-09-07 10:18:17 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/canvas.class.php' ;
$objcanvas = new Canvas ( $db , $action );
$objcanvas -> getCanvas ( 'contact' , 'contactcard' , $canvas );
2010-11-03 12:39:40 +01:00
}
2006-03-11 15:18:37 +01:00
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2020-04-10 10:59:32 +02:00
$hookmanager -> initHooks ( array ( 'contactcard' , 'globalcard' ));
2011-07-01 00:38:06 +02:00
2021-02-23 21:16:15 +01:00
if ( $id > 0 ) {
$object -> fetch ( $id );
}
2019-10-27 12:04:01 +01:00
2021-02-23 21:16:15 +01:00
if ( ! ( $object -> id > 0 ) && $action == 'view' ) {
2019-10-27 12:04:01 +01:00
$langs -> load ( " errors " );
print ( $langs -> trans ( 'ErrorRecordNotFound' ));
exit ;
}
2006-03-11 15:18:37 +01:00
2021-05-26 17:45:45 +02:00
$triggermodname = 'CONTACT_MODIFY' ;
$permissiontoadd = $user -> rights -> societe -> contact -> creer ;
// Security check
if ( $user -> socid ) {
$socid = $user -> socid ;
}
$result = restrictedArea ( $user , 'contact' , $id , 'socpeople&societe' , '' , '' , 'rowid' , 0 ); // If we create a contact with no company (shared contacts), no check on write permission
2008-02-25 17:30:43 +01:00
/*
2009-11-28 08:30:45 +01:00
* Actions
*/
2007-02-26 00:08:25 +01:00
2020-04-10 10:59:32 +02:00
$parameters = array ( 'id' => $id , 'objcanvas' => $objcanvas );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-23 21:16:15 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2011-07-01 00:38:06 +02:00
2021-02-23 21:16:15 +01:00
if ( empty ( $reshook )) {
2021-09-01 20:10:56 +02:00
$backurlforlist = DOL_URL_ROOT . '/contact/list.php' ;
if ( empty ( $backtopage ) || ( $cancel && empty ( $id ))) {
if ( empty ( $backtopage ) || ( $cancel && strpos ( $backtopage , '__ID__' ))) {
if ( empty ( $id ) && (( $action != 'add' && $action != 'create' ) || $cancel )) {
$backtopage = $backurlforlist ;
} else {
$backtopage = DOL_URL_ROOT . '/contact/card.php?id=' . (( ! empty ( $id ) && $id > 0 ) ? $id : '__ID__' );
}
}
}
if ( $cancel ) {
if ( ! empty ( $backtopageforcancel )) {
header ( " Location: " . $backtopageforcancel );
exit ;
} elseif ( ! empty ( $backtopage )) {
header ( " Location: " . $backtopage );
exit ;
}
$action = '' ;
2020-09-07 10:18:17 +02:00
}
2011-07-04 10:00:52 +02:00
// Creation utilisateur depuis contact
2021-02-23 21:16:15 +01:00
if ( $action == 'confirm_create_user' && $confirm == 'yes' && $user -> rights -> user -> user -> creer ) {
2020-09-07 10:18:17 +02:00
// Recuperation contact actuel
$result = $object -> fetch ( $id );
2021-02-23 21:16:15 +01:00
if ( $result > 0 ) {
2020-09-07 10:18:17 +02:00
$db -> begin ();
// Creation user
$nuser = new User ( $db );
$result = $nuser -> create_from_contact ( $object , GETPOST ( " login " )); // Do not use GETPOST(alpha)
2021-02-23 21:16:15 +01:00
if ( $result > 0 ) {
2020-09-07 10:18:17 +02:00
$result2 = $nuser -> setPassword ( $user , GETPOST ( " password " ), 0 , 0 , 1 ); // Do not use GETPOST(alpha)
2021-02-23 21:16:15 +01:00
if ( $result2 ) {
2020-09-07 10:18:17 +02:00
$db -> commit ();
} else {
$error = $nuser -> error ; $errors = $nuser -> errors ;
$db -> rollback ();
}
} else {
$error = $nuser -> error ; $errors = $nuser -> errors ;
$db -> rollback ();
}
} else {
$error = $object -> error ; $errors = $object -> errors ;
}
}
2013-09-25 19:58:22 +02:00
2011-03-26 19:34:41 +01:00
2018-01-10 12:38:12 +01:00
// Confirmation desactivation
2021-05-26 17:45:45 +02:00
if ( $action == 'disable' && ! empty ( $permissiontoadd )) {
2018-01-10 12:38:12 +01:00
$object -> fetch ( $id );
2021-02-23 21:16:15 +01:00
if ( $object -> setstatus ( 0 ) < 0 ) {
2018-01-10 12:38:12 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2018-01-10 12:38:12 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . '?id=' . $id );
exit ;
}
}
2013-07-10 12:28:28 +02:00
2018-01-10 12:38:12 +01:00
// Confirmation activation
2021-05-26 17:45:45 +02:00
if ( $action == 'enable' && ! empty ( $permissiontoadd )) {
2018-01-10 12:38:12 +01:00
$object -> fetch ( $id );
2021-02-23 21:16:15 +01:00
if ( $object -> setstatus ( 1 ) < 0 ) {
2018-01-10 12:38:12 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2018-01-10 12:38:12 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . '?id=' . $id );
exit ;
}
}
2013-09-25 19:58:22 +02:00
2018-01-10 12:38:12 +01:00
// Add contact
2021-05-26 17:45:45 +02:00
if ( $action == 'add' && ! empty ( $permissiontoadd )) {
2018-01-10 12:38:12 +01:00
$db -> begin ();
2011-06-30 00:29:50 +02:00
2021-02-23 21:16:15 +01:00
if ( $canvas ) {
$object -> canvas = $canvas ;
}
2011-03-26 19:34:41 +01:00
2020-09-07 10:18:17 +02:00
$object -> entity = ( GETPOSTISSET ( 'entity' ) ? GETPOST ( 'entity' , 'int' ) : $conf -> entity );
2020-09-08 21:27:28 +02:00
$object -> socid = GETPOST ( " socid " , 'int' );
2020-11-05 20:30:09 +01:00
$object -> lastname = ( string ) GETPOST ( " lastname " , 'alpha' );
$object -> firstname = ( string ) GETPOST ( " firstname " , 'alpha' );
$object -> civility_code = ( string ) GETPOST ( " civility_code " , 'alpha' );
$object -> poste = ( string ) GETPOST ( " poste " , 'alpha' );
$object -> address = ( string ) GETPOST ( " address " , 'alpha' );
$object -> zip = ( string ) GETPOST ( " zipcode " , 'alpha' );
$object -> town = ( string ) GETPOST ( " town " , 'alpha' );
$object -> country_id = ( int ) GETPOST ( " country_id " , 'int' );
2020-11-05 20:31:42 +01:00
$object -> state_id = ( int ) GETPOST ( " state_id " , 'int' );
2020-09-07 10:18:17 +02:00
//$object->jabberid = GETPOST("jabberid", 'alpha');
//$object->skype = GETPOST("skype", 'alpha');
//$object->twitter = GETPOST("twitter", 'alpha');
//$object->facebook = GETPOST("facebook", 'alpha');
//$object->linkedin = GETPOST("linkedin", 'alpha');
$object -> socialnetworks = array ();
if ( ! empty ( $conf -> socialnetworks -> enabled )) {
foreach ( $socialnetworks as $key => $value ) {
if ( GETPOSTISSET ( $key ) && GETPOST ( $key , 'alphanohtml' ) != '' ) {
2020-11-05 20:30:09 +01:00
$object -> socialnetworks [ $key ] = ( string ) GETPOST ( $key , 'alphanohtml' );
2020-09-07 10:18:17 +02:00
}
}
}
2021-01-07 17:23:02 +01:00
$object -> email = ( string ) GETPOST ( 'email' , 'custom' , 0 , FILTER_SANITIZE_EMAIL );
2020-09-07 10:18:17 +02:00
$object -> no_email = GETPOST ( " no_email " , " int " );
2020-11-05 20:30:09 +01:00
$object -> phone_pro = ( string ) GETPOST ( " phone_pro " , 'alpha' );
$object -> phone_perso = ( string ) GETPOST ( " phone_perso " , 'alpha' );
$object -> phone_mobile = ( string ) GETPOST ( " phone_mobile " , 'alpha' );
$object -> fax = ( string ) GETPOST ( " fax " , 'alpha' );
2020-09-07 10:18:17 +02:00
$object -> priv = GETPOST ( " priv " , 'int' );
2020-11-05 20:30:09 +01:00
$object -> note_public = ( string ) GETPOST ( " note_public " , 'restricthtml' );
$object -> note_private = ( string ) GETPOST ( " note_private " , 'restricthtml' );
2020-09-07 10:18:17 +02:00
$object -> roles = GETPOST ( " roles " , 'array' );
2020-11-05 20:30:09 +01:00
$object -> statut = 1 ; //Default status to Actif
2020-09-07 10:18:17 +02:00
// Note: Correct date should be completed with location to have exact GM time of birth.
$object -> birthday = dol_mktime ( 0 , 0 , 0 , GETPOST ( " birthdaymonth " , 'int' ), GETPOST ( " birthdayday " , 'int' ), GETPOST ( " birthdayyear " , 'int' ));
$object -> birthday_alert = GETPOST ( " birthday_alert " , 'alpha' );
2022-04-22 13:47:58 +02:00
//Default language
$object -> default_lang = GETPOST ( 'default_lang' );
2020-09-07 10:18:17 +02:00
// Fill array 'array_options' with data from add form
2019-10-06 14:41:52 +02:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object );
2021-02-23 21:16:15 +01:00
if ( $ret < 0 ) {
2015-05-25 17:36:36 +02:00
$error ++ ;
$action = 'create' ;
}
2015-06-05 15:41:27 +02:00
2021-09-01 22:37:15 +02:00
if ( ! empty ( $conf -> mailing -> enabled ) && $conf -> global -> MAILING_CONTACT_DEFAULT_BULK_STATUS == 2 && $object -> no_email == - 1 && ! empty ( $object -> email )) {
2020-11-05 20:30:09 +01:00
$error ++ ;
2021-01-07 17:23:02 +01:00
$errors [] = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " No_Email " ));
2020-09-07 10:18:17 +02:00
$action = 'create' ;
}
2021-02-23 21:16:15 +01:00
if ( ! empty ( $object -> email ) && ! isValidEMail ( $object -> email )) {
2021-01-07 17:23:02 +01:00
$langs -> load ( " errors " );
$error ++ ;
$errors [] = $langs -> trans ( " ErrorBadEMail " , GETPOST ( 'email' , 'alpha' ));
$action = 'create' ;
}
if ( empty ( $object -> lastname )) {
$error ++ ;
$errors [] = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Lastname " ) . ' / ' . $langs -> transnoentities ( " Label " ));
$action = 'create' ;
}
if ( empty ( $error )) {
2020-09-07 10:18:17 +02:00
$id = $object -> create ( $user );
2021-01-07 17:23:02 +01:00
if ( $id <= 0 ) {
2020-11-05 20:30:09 +01:00
$error ++ ;
$errors = array_merge ( $errors , ( $object -> error ? array ( $object -> error ) : $object -> errors ));
2020-09-07 10:18:17 +02:00
$action = 'create' ;
2021-01-07 17:23:02 +01:00
}
}
2019-10-22 15:21:41 +02:00
2021-01-07 17:23:02 +01:00
if ( empty ( $error )) {
// Categories association
$contcats = GETPOST ( 'contcats' , 'array' );
2021-06-14 15:37:02 +02:00
if ( count ( $contcats ) > 0 ) {
2021-01-07 17:23:02 +01:00
$result = $object -> setCategories ( $contcats );
if ( $result <= 0 ) {
$error ++ ;
$errors = array_merge ( $errors , ( $object -> error ? array ( $object -> error ) : $object -> errors ));
$action = 'create' ;
2019-10-22 15:21:41 +02:00
}
2015-06-11 14:50:11 +02:00
}
2020-09-07 10:18:17 +02:00
}
2021-01-07 17:23:02 +01:00
if ( empty ( $error ) && ! empty ( $conf -> mailing -> enabled ) && ! empty ( $object -> email )) {
// Add mass emailing flag into table mailing_unsubscribe
2021-06-14 15:37:02 +02:00
$result = $object -> setNoEmail ( $object -> no_email );
if ( $result < 0 ) {
2021-01-07 17:23:02 +01:00
$error ++ ;
$errors = array_merge ( $errors , ( $object -> error ? array ( $object -> error ) : $object -> errors ));
$action = 'create' ;
}
}
2021-02-23 21:16:15 +01:00
if ( empty ( $error ) && $id > 0 ) {
2020-09-07 10:18:17 +02:00
$db -> commit ();
2021-02-23 21:16:15 +01:00
if ( ! empty ( $backtopage )) {
2021-10-23 10:32:50 +02:00
$url = str_replace ( '__ID__' , $id , $backtopage );
2021-02-23 21:16:15 +01:00
} else {
$url = 'card.php?id=' . $id ;
}
2020-09-07 10:18:17 +02:00
header ( " Location: " . $url );
exit ;
} else {
$db -> rollback ();
}
}
2021-02-23 21:16:15 +01:00
if ( $action == 'confirm_delete' && $confirm == 'yes' && $user -> rights -> societe -> contact -> supprimer ) {
2020-09-07 10:18:17 +02:00
$result = $object -> fetch ( $id );
2019-10-12 22:08:11 +02:00
$object -> oldcopy = clone $object ;
2011-06-30 15:25:32 +02:00
2020-11-05 20:30:09 +01:00
$object -> old_lastname = ( string ) GETPOST ( " old_lastname " , 'alpha' );
$object -> old_firstname = ( string ) GETPOST ( " old_firstname " , 'alpha' );
2020-09-07 10:18:17 +02:00
2021-06-14 15:37:02 +02:00
$result = $object -> delete (); // TODO Add $user as first param
2020-11-05 20:30:09 +01:00
if ( $result > 0 ) {
2022-05-19 10:54:35 +02:00
setEventMessages ( " RecordDeleted " , null , 'mesgs' );
if ( $backurlforlist ) {
header ( " Location: " . $backurlforlist );
2020-09-07 10:18:17 +02:00
exit ;
} else {
header ( " Location: " . DOL_URL_ROOT . '/contact/list.php' );
exit ;
}
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
2021-05-26 17:45:45 +02:00
if ( $action == 'update' && empty ( $cancel ) && ! empty ( $permissiontoadd )) {
2021-02-23 21:16:15 +01:00
if ( ! GETPOST ( " lastname " , 'alpha' )) {
2020-09-07 10:18:17 +02:00
$error ++ ; $errors = array ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Name " ) . ' / ' . $langs -> transnoentities ( " Label " )));
$action = 'edit' ;
}
2011-06-30 15:25:32 +02:00
2021-09-01 22:37:15 +02:00
if ( ! empty ( $conf -> mailing -> enabled ) && $conf -> global -> MAILING_CONTACT_DEFAULT_BULK_STATUS == 2 && GETPOST ( " no_email " , " int " ) == - 1 && ! empty ( GETPOST ( 'email' , 'custom' , 0 , FILTER_SANITIZE_EMAIL ))) {
2021-01-07 17:23:02 +01:00
$error ++ ;
$errors [] = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " No_Email " ));
$action = 'edit' ;
}
2021-02-23 21:16:15 +01:00
if ( ! empty ( GETPOST ( 'email' , 'custom' , 0 , FILTER_SANITIZE_EMAIL )) && ! isValidEMail ( GETPOST ( 'email' , 'custom' , 0 , FILTER_SANITIZE_EMAIL ))) {
2021-01-07 17:23:02 +01:00
$langs -> load ( " errors " );
$error ++ ;
$errors [] = $langs -> trans ( " ErrorBadEMail " , GETPOST ( 'email' , 'alpha' ));
$action = 'edit' ;
}
2021-02-23 21:16:15 +01:00
if ( ! $error ) {
2019-11-13 19:35:02 +01:00
$contactid = GETPOST ( " contactid " , 'int' );
2018-01-10 12:52:30 +01:00
$object -> fetch ( $contactid );
2021-01-22 13:17:27 +01:00
$object -> fetchRoles ( $contactid );
2015-10-04 17:25:46 +02:00
2018-01-10 12:52:30 +01:00
// Photo save
$dir = $conf -> societe -> multidir_output [ $object -> entity ] . " /contact/ " . $object -> id . " /photos " ;
2020-09-07 10:18:17 +02:00
$file_OK = is_uploaded_file ( $_FILES [ 'photo' ][ 'tmp_name' ]);
2021-02-23 21:16:15 +01:00
if ( GETPOST ( 'deletephoto' ) && $object -> photo ) {
2020-09-07 10:18:17 +02:00
$fileimg = $dir . '/' . $object -> photo ;
$dirthumbs = $dir . '/thumbs' ;
dol_delete_file ( $fileimg );
dol_delete_dir_recursive ( $dirthumbs );
$object -> photo = '' ;
}
2021-02-23 21:16:15 +01:00
if ( $file_OK ) {
if ( image_format_supported ( $_FILES [ 'photo' ][ 'name' ]) > 0 ) {
2020-09-07 10:18:17 +02:00
dol_mkdir ( $dir );
2021-02-23 21:16:15 +01:00
if ( @ is_dir ( $dir )) {
2020-09-07 10:18:17 +02:00
$newfile = $dir . '/' . dol_sanitizeFileName ( $_FILES [ 'photo' ][ 'name' ]);
$result = dol_move_uploaded_file ( $_FILES [ 'photo' ][ 'tmp_name' ], $newfile , 1 );
2022-08-12 15:54:50 +02:00
if ( ! ( $result > 0 )) {
2020-09-07 10:18:17 +02:00
$errors [] = " ErrorFailedToSaveFile " ;
} else {
$object -> photo = dol_sanitizeFileName ( $_FILES [ 'photo' ][ 'name' ]);
// Create thumbs
$object -> addThumbs ( $newfile );
}
}
} else {
$errors [] = " ErrorBadImageFormat " ;
}
} else {
2021-02-23 21:16:15 +01:00
switch ( $_FILES [ 'photo' ][ 'error' ]) {
2020-09-07 10:18:17 +02:00
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 ;
}
}
2015-10-04 17:25:46 +02:00
2016-02-18 15:18:47 +01:00
$object -> oldcopy = clone $object ;
2011-06-30 15:25:32 +02:00
2020-11-05 20:30:09 +01:00
$object -> old_lastname = ( string ) GETPOST ( " old_lastname " , 'alpha' );
$object -> old_firstname = ( string ) GETPOST ( " old_firstname " , 'alpha' );
2019-01-27 11:55:16 +01:00
2020-09-07 10:18:17 +02:00
$object -> socid = GETPOST ( " socid " , 'int' );
2020-11-05 20:30:09 +01:00
$object -> lastname = ( string ) GETPOST ( " lastname " , 'alpha' );
$object -> firstname = ( string ) GETPOST ( " firstname " , 'alpha' );
$object -> civility_code = ( string ) GETPOST ( " civility_code " , 'alpha' );
$object -> poste = ( string ) GETPOST ( " poste " , 'alpha' );
$object -> address = ( string ) GETPOST ( " address " , 'alpha' );
$object -> zip = ( string ) GETPOST ( " zipcode " , 'alpha' );
$object -> town = ( string ) GETPOST ( " town " , 'alpha' );
$object -> state_id = GETPOST ( " state_id " , 'int' );
$object -> country_id = GETPOST ( " country_id " , 'int' );
2021-01-07 17:23:02 +01:00
$object -> email = ( string ) GETPOST ( 'email' , 'custom' , 0 , FILTER_SANITIZE_EMAIL );
2020-09-07 10:18:17 +02:00
$object -> no_email = GETPOST ( " no_email " , " int " );
//$object->jabberid = GETPOST("jabberid", 'alpha');
//$object->skype = GETPOST("skype", 'alpha');
//$object->twitter = GETPOST("twitter", 'alpha');
//$object->facebook = GETPOST("facebook", 'alpha');
//$object->linkedin = GETPOST("linkedin", 'alpha');
2020-06-04 00:30:17 +02:00
$object -> socialnetworks = array ();
2020-09-07 10:18:17 +02:00
if ( ! empty ( $conf -> socialnetworks -> enabled )) {
foreach ( $socialnetworks as $key => $value ) {
if ( GETPOSTISSET ( $key ) && GETPOST ( $key , 'alphanohtml' ) != '' ) {
2020-11-05 20:30:09 +01:00
$object -> socialnetworks [ $key ] = ( string ) GETPOST ( $key , 'alphanohtml' );
2020-09-07 10:18:17 +02:00
}
}
}
2020-11-05 20:30:09 +01:00
$object -> phone_pro = ( string ) GETPOST ( " phone_pro " , 'alpha' );
$object -> phone_perso = ( string ) GETPOST ( " phone_perso " , 'alpha' );
$object -> phone_mobile = ( string ) GETPOST ( " phone_mobile " , 'alpha' );
$object -> fax = ( string ) GETPOST ( " fax " , 'alpha' );
$object -> priv = ( string ) GETPOST ( " priv " , 'int' );
$object -> note_public = ( string ) GETPOST ( " note_public " , 'restricthtml' );
$object -> note_private = ( string ) GETPOST ( " note_private " , 'restricthtml' );
2021-01-22 13:17:27 +01:00
2021-06-14 15:37:02 +02:00
$object -> roles = GETPOST ( " roles " , 'array' ); // Note GETPOSTISSET("role") is null when combo is empty
2020-09-07 10:18:17 +02:00
2022-04-22 13:47:58 +02:00
//Default language
$object -> default_lang = GETPOST ( 'default_lang' );
2020-09-07 10:18:17 +02:00
// Fill array 'array_options' with data from add form
2021-12-06 11:19:12 +01:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object , '@GETPOSTISSET' );
2021-02-23 21:16:15 +01:00
if ( $ret < 0 ) {
$error ++ ;
}
2012-09-17 01:39:30 +02:00
2021-02-23 21:16:15 +01:00
if ( ! $error ) {
2020-09-07 10:18:17 +02:00
$result = $object -> update ( $contactid , $user );
if ( $result > 0 ) {
// Categories association
$categories = GETPOST ( 'contcats' , 'array' );
$object -> setCategories ( $categories );
// Update mass emailing flag into table mailing_unsubscribe
2021-02-23 21:16:15 +01:00
if ( GETPOSTISSET ( 'no_email' ) && $object -> email ) {
2021-01-07 17:23:02 +01:00
$no_email = GETPOST ( 'no_email' , 'int' );
2021-06-14 15:37:02 +02:00
$result = $object -> setNoEmail ( $no_email );
if ( $result < 0 ) {
2021-01-07 17:23:02 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$action = 'edit' ;
2020-09-07 10:18:17 +02:00
}
}
$action = 'view' ;
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$action = 'edit' ;
}
2019-01-02 08:37:26 +01:00
}
2020-09-07 10:18:17 +02:00
}
2021-02-23 21:16:15 +01:00
if ( ! $error && empty ( $errors )) {
if ( ! empty ( $backtopage )) {
header ( " Location: " . $backtopage );
exit ;
}
2020-09-07 10:18:17 +02:00
}
}
2021-05-26 17:45:45 +02:00
if ( $action == 'setprospectcontactlevel' && ! empty ( $permissiontoadd )) {
2020-04-27 17:35:14 +02:00
$object -> fetch ( $id );
2020-04-27 17:48:05 +02:00
$object -> fk_prospectlevel = GETPOST ( 'prospect_contact_level_id' , 'alpha' );
$result = $object -> update ( $object -> id , $user );
2021-02-23 21:16:15 +01:00
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2020-04-27 17:35:14 +02:00
}
// set communication status
2021-05-26 17:45:45 +02:00
if ( $action == 'setstcomm' && ! empty ( $permissiontoadd )) {
2020-04-27 17:35:14 +02:00
$object -> fetch ( $id );
2020-04-27 17:48:05 +02:00
$object -> stcomm_id = dol_getIdFromCode ( $db , GETPOST ( 'stcomm' , 'alpha' ), 'c_stcommcontact' );
$result = $object -> update ( $object -> id , $user );
2021-02-23 21:16:15 +01:00
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2020-04-27 17:35:14 +02:00
}
2021-05-26 17:45:45 +02:00
// Update extrafields
if ( $action == " update_extras " && ! empty ( $permissiontoadd )) {
$object -> fetch ( GETPOST ( 'id' , 'int' ));
$attributekey = GETPOST ( 'attribute' , 'alpha' );
$attributekeylong = 'options_' . $attributekey ;
if ( GETPOSTISSET ( $attributekeylong . 'day' ) && GETPOSTISSET ( $attributekeylong . 'month' ) && GETPOSTISSET ( $attributekeylong . 'year' )) {
// This is properties of a date
$object -> array_options [ 'options_' . $attributekey ] = dol_mktime ( GETPOST ( $attributekeylong . 'hour' , 'int' ), GETPOST ( $attributekeylong . 'min' , 'int' ), GETPOST ( $attributekeylong . 'sec' , 'int' ), GETPOST ( $attributekeylong . 'month' , 'int' ), GETPOST ( $attributekeylong . 'day' , 'int' ), GETPOST ( $attributekeylong . 'year' , 'int' ));
//var_dump(dol_print_date($object->array_options['options_'.$attributekey]));exit;
} else {
$object -> array_options [ 'options_' . $attributekey ] = GETPOST ( $attributekeylong , 'alpha' );
}
$result = $object -> insertExtraFields ( empty ( $triggermodname ) ? '' : $triggermodname , $user );
if ( $result > 0 ) {
setEventMessages ( $langs -> trans ( 'RecordSaved' ), null , 'mesgs' );
$action = 'view' ;
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$action = 'edit_extras' ;
}
}
2022-03-24 17:34:50 +01:00
// Update extrafields
if ( $action == 'update_extras' && ! empty ( $user -> rights -> societe -> contact -> creer )) {
$object -> oldcopy = dol_clone ( $object );
// Fill array 'array_options' with data from update form
$ret = $extrafields -> setOptionalsFromPost ( null , $object , GETPOST ( 'attribute' , 'restricthtml' ));
if ( $ret < 0 ) {
$error ++ ;
}
if ( ! $error ) {
$result = $object -> insertExtraFields ( 'CONTACT_MODIFY' );
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
}
if ( $error ) {
$action = 'edit_extras' ;
}
}
2020-09-07 10:18:17 +02:00
// Actions to send emails
2019-12-02 09:38:16 +01:00
$triggersendname = 'CONTACT_SENTBYMAIL' ;
2019-11-13 19:35:02 +01:00
$paramname = 'id' ;
$mode = 'emailfromcontact' ;
2018-11-06 16:40:39 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php' ;
2006-03-11 15:55:13 +01:00
}
2006-02-25 00:16:35 +01:00
/*
2009-11-28 08:30:45 +01:00
* View
*/
2006-02-25 00:16:35 +01:00
2022-01-09 20:43:26 +01:00
$form = new Form ( $db );
2022-05-24 21:41:53 +02:00
$formadmin = new FormAdmin ( $db );
2022-01-09 20:43:26 +01:00
$formcompany = new FormCompany ( $db );
2012-09-17 01:39:30 +02:00
2019-11-13 19:35:02 +01:00
$title = ( ! empty ( $conf -> global -> SOCIETE_ADDRESSES_MANAGEMENT ) ? $langs -> trans ( " Contacts " ) : $langs -> trans ( " ContactsAddresses " ));
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> global -> MAIN_HTML_TITLE ) && preg_match ( '/contactnameonly/' , $conf -> global -> MAIN_HTML_TITLE ) && $object -> lastname ) {
$title = $object -> lastname ;
}
2019-11-13 19:35:02 +01:00
$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas' ;
2015-10-15 14:13:31 +02:00
llxHeader ( '' , $title , $help_url );
2006-04-01 17:01:01 +02:00
2019-11-13 19:35:02 +01:00
$countrynotdefined = $langs -> trans ( " ErrorSetACountryFirst " ) . ' (' . $langs -> trans ( " SeeAbove " ) . ')' ;
2010-06-06 16:30:28 +02:00
2021-10-23 19:22:41 +02:00
$objsoc = new Societe ( $db );
2021-02-23 21:16:15 +01:00
if ( $socid > 0 ) {
2020-09-07 10:18:17 +02:00
$objsoc -> fetch ( $socid );
2006-02-25 00:16:35 +01:00
}
2021-02-23 21:16:15 +01:00
if ( is_object ( $objcanvas ) && $objcanvas -> displayCanvasExists ( $action )) {
2020-09-07 10:18:17 +02:00
// -----------------------------------------
// When used with CANVAS
// -----------------------------------------
2021-02-23 21:16:15 +01:00
if ( empty ( $object -> error ) && $id ) {
$object = new Contact ( $db );
$result = $object -> fetch ( $id );
if ( $result <= 0 ) {
dol_print_error ( '' , $object -> error );
}
}
$objcanvas -> assign_values ( $action , $object -> id , $object -> ref ); // Set value for templates
2020-09-07 10:18:17 +02:00
$objcanvas -> display_canvas ( $action ); // Show template
2020-05-21 15:05:19 +02:00
} else {
2020-09-07 10:18:17 +02:00
// -----------------------------------------
// When used in standard mode
// -----------------------------------------
// Confirm deleting contact
2021-02-23 21:16:15 +01:00
if ( $user -> rights -> societe -> contact -> supprimer ) {
if ( $action == 'delete' ) {
2020-09-07 10:18:17 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $id . ( $backtopage ? '&backtopage=' . $backtopage : '' ), $langs -> trans ( " DeleteContact " ), $langs -> trans ( " ConfirmDeleteContact " ), " confirm_delete " , '' , 0 , 1 );
}
}
/*
2021-02-23 21:16:15 +01:00
* Onglets
*/
2020-09-07 10:18:17 +02:00
$head = array ();
2021-02-23 21:16:15 +01:00
if ( $id > 0 ) {
2020-09-07 10:18:17 +02:00
// Si edition contact deja existant
$object = new Contact ( $db );
$res = $object -> fetch ( $id , $user );
if ( $res < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
$object -> fetchRoles ();
// Show tabs
$head = contact_prepare_head ( $object );
$title = ( ! empty ( $conf -> global -> SOCIETE_ADDRESSES_MANAGEMENT ) ? $langs -> trans ( " Contacts " ) : $langs -> trans ( " ContactsAddresses " ));
}
2021-02-23 21:16:15 +01:00
if ( $user -> rights -> societe -> contact -> creer ) {
2022-07-11 00:05:50 +02:00
if ( $action == 'create' ) {
2020-09-07 10:18:17 +02:00
/*
2021-02-23 21:16:15 +01:00
* Fiche en mode creation
*/
2020-09-07 10:18:17 +02:00
$object -> canvas = $canvas ;
2011-09-24 22:50:57 +02:00
2022-04-07 16:05:55 +02:00
$object -> state_id = GETPOST ( " state_id " , " int " );
2011-03-26 19:34:41 +01:00
2020-09-07 10:18:17 +02:00
// We set country_id, country_code and label for the selected country
2021-03-25 16:59:47 +01:00
$object -> country_id = GETPOST ( " country_id " ) ? GETPOST ( " country_id " , " int " ) : ( empty ( $objsoc -> country_id ) ? $mysoc -> country_id : $objsoc -> country_id );
2021-02-23 21:16:15 +01:00
if ( $object -> country_id ) {
2020-09-07 10:18:17 +02:00
$tmparray = getCountry ( $object -> country_id , 'all' );
$object -> country_code = $tmparray [ 'code' ];
$object -> country = $tmparray [ 'label' ];
}
2012-03-18 19:23:01 +01:00
2022-05-23 11:56:39 +02:00
$title = ( ! empty ( $conf -> global -> SOCIETE_ADDRESSES_MANAGEMENT ) ? $langs -> trans ( " NewContact " ) : $langs -> trans ( " NewContactAddress " ));
2020-09-07 10:18:17 +02:00
$linkback = '' ;
print load_fiche_titre ( $title , $linkback , 'address' );
2011-03-26 19:34:41 +01:00
2020-09-07 10:18:17 +02:00
// Show errors
dol_htmloutput_errors ( is_numeric ( $error ) ? '' : $error , $errors );
2011-03-26 19:34:41 +01:00
2021-02-23 21:16:15 +01:00
if ( $conf -> use_javascript_ajax ) {
2021-11-29 15:09:18 +01:00
print " \n " . '<script type="text/javascript">' . " \n " ;
2012-09-28 14:56:47 +02:00
print ' jQuery ( document ) . ready ( function () {
2011-12-29 18:07:41 +01:00
jQuery ( " #selectcountry_id " ) . change ( function () {
2010-11-03 12:39:40 +01:00
document . formsoc . action . value = " create " ;
document . formsoc . submit ();
2012-09-28 14:56:47 +02:00
});
2012-10-06 19:25:25 +02:00
2012-09-28 14:27:16 +02:00
$ ( " #copyaddressfromsoc " ) . click ( function () {
2013-02-12 10:33:10 +01:00
$ ( \ 'textarea[name="address"]\').val("' . dol_escape_js ( $objsoc -> address ) . ' " );
2012-12-11 10:59:03 +01:00
$ ( \ 'input[name="zipcode"]\').val("' . dol_escape_js ( $objsoc -> zip ) . ' " );
$ ( \ 'input[name="town"]\').val("' . dol_escape_js ( $objsoc -> town ) . ' " );
2016-02-03 02:06:12 +01:00
console . log ( " Set state_id to '.dol_escape_js( $objsoc->state_id ).' " );
$ ( \ 'select[name="state_id"]\').val("' . dol_escape_js ( $objsoc -> state_id ) . ' " ).trigger( " change " );
/* set country at end because it will trigger page refresh */
console . log ( " Set country id to '.dol_escape_js( $objsoc->country_id ).' " );
$ ( \ 'select[name="country_id"]\').val("' . dol_escape_js ( $objsoc -> country_id ) . ' " ).trigger( " change " ); /* trigger required to update select2 components */
});
2012-09-28 14:27:16 +02:00
}) ' . " \n " ;
2012-09-28 14:56:47 +02:00
print '</script>' . " \n " ;
2020-09-07 10:18:17 +02:00
}
2010-11-19 22:24:48 +01:00
2020-09-07 10:18:17 +02:00
print '<form method="post" name="formsoc" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="action" value="add">' ;
print '<input type="hidden" name="backtopage" value="' . $backtopage . '">' ;
2019-11-13 19:35:02 +01:00
if ( ! empty ( $objsoc )) {
2018-01-10 12:38:12 +01:00
print '<input type="hidden" name="entity" value="' . $objsoc -> entity . '">' ;
2020-09-07 10:18:17 +02:00
}
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'card' , '' , 0 , '' );
2020-09-07 10:18:17 +02:00
print '<table class="border centpercent">' ;
// Name
print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">' . $langs -> trans ( " Lastname " ) . ' / ' . $langs -> trans ( " Label " ) . '</label></td>' ;
print '<td colspan="3"><input name="lastname" id="lastname" type="text" class="maxwidth100onsmartphone" maxlength="80" value="' . dol_escape_htmltag ( GETPOST ( " lastname " , 'alpha' ) ? GETPOST ( " lastname " , 'alpha' ) : $object -> lastname ) . '" autofocus="autofocus"></td>' ;
print '</tr>' ;
print '<tr>' ;
print '<td><label for="firstname">' ;
print $form -> textwithpicto ( $langs -> trans ( " Firstname " ), $langs -> trans ( " KeepEmptyIfGenericAddress " )) . '</label></td>' ;
print '<td colspan="3"><input name="firstname" id="firstname"type="text" class="maxwidth100onsmartphone" maxlength="80" value="' . dol_escape_htmltag ( GETPOST ( " firstname " , 'alpha' ) ? GETPOST ( " firstname " , 'alpha' ) : $object -> firstname ) . '"></td>' ;
print '</tr>' ;
// Company
2021-02-23 21:16:15 +01:00
if ( empty ( $conf -> global -> SOCIETE_DISABLE_CONTACTS )) {
if ( $socid > 0 ) {
2020-09-07 10:18:17 +02:00
print '<tr><td><label for="socid">' . $langs -> trans ( " ThirdParty " ) . '</label></td>' ;
print '<td colspan="3" class="maxwidthonsmartphone">' ;
print $objsoc -> getNomUrl ( 1 , 'contact' );
print '</td>' ;
print '<input type="hidden" name="socid" id="socid" value="' . $objsoc -> id . '">' ;
print '</td></tr>' ;
} else {
print '<tr><td><label for="socid">' . $langs -> trans ( " ThirdParty " ) . '</label></td><td colspan="3" class="maxwidthonsmartphone">' ;
2022-04-07 16:05:55 +02:00
print img_picto ( '' , 'company' ) . $form -> select_company ( $socid , 'socid' , '' , 'SelectThirdParty' , 0 , 0 , null , 0 , 'minwidth300 maxwidth500 widthcentpercentminusxx' );
2020-09-07 10:18:17 +02:00
print '</td></tr>' ;
}
}
// Civility
print '<tr><td><label for="civility_code">' . $langs -> trans ( " UserTitle " ) . '</label></td><td colspan="3">' ;
print $formcompany -> select_civility ( GETPOSTISSET ( " civility_code " ) ? GETPOST ( " civility_code " , 'alpha' ) : $object -> civility_code , 'civility_code' );
print '</td></tr>' ;
2021-01-27 19:31:30 +01:00
// Job position
2020-09-07 10:18:17 +02:00
print '<tr><td><label for="title">' . $langs -> trans ( " PostOrFunction " ) . '</label></td>' ;
2021-01-27 19:31:30 +01:00
print '<td colspan="3"><input name="poste" id="title" type="text" class="minwidth100" maxlength="255" value="' . dol_escape_htmltag ( GETPOSTISSET ( " poste " ) ? GETPOST ( " poste " , 'alphanohtml' ) : $object -> poste ) . '"></td>' ;
2020-09-07 10:18:17 +02:00
$colspan = 3 ;
2021-02-23 21:16:15 +01:00
if ( $conf -> use_javascript_ajax && $socid > 0 ) {
$colspan = 2 ;
}
2020-09-07 10:18:17 +02:00
// Address
2021-09-02 18:48:46 +02:00
if ((( isset ( $objsoc -> typent_code ) && $objsoc -> typent_code == 'TE_PRIVATE' ) || ! empty ( $conf -> global -> CONTACT_USE_COMPANY_ADDRESS )) && dol_strlen ( trim ( $object -> address )) == 0 ) {
2021-02-23 21:16:15 +01:00
$object -> address = $objsoc -> address ; // Predefined with third party
}
2020-09-07 10:18:17 +02:00
print '<tr><td><label for="address">' . $langs -> trans ( " Address " ) . '</label></td>' ;
print '<td colspan="' . $colspan . '"><textarea class="flat quatrevingtpercent" name="address" id="address" rows="' . ROWS_2 . '">' . ( GETPOST ( " address " , 'alpha' ) ? GETPOST ( " address " , 'alpha' ) : $object -> address ) . '</textarea></td>' ;
2021-02-23 21:16:15 +01:00
if ( $conf -> use_javascript_ajax && $socid > 0 ) {
2020-09-07 10:18:17 +02:00
$rowspan = 3 ;
2021-02-23 21:16:15 +01:00
if ( empty ( $conf -> global -> SOCIETE_DISABLE_STATE )) {
$rowspan ++ ;
}
2020-09-07 10:18:17 +02:00
print '<td class="valignmiddle center" rowspan="' . $rowspan . '">' ;
print '<a href="#" id="copyaddressfromsoc">' . $langs -> trans ( 'CopyAddressFromSoc' ) . '</a>' ;
print '</td>' ;
}
print '</tr>' ;
// Zip / Town
2021-09-02 18:48:46 +02:00
if ((( isset ( $objsoc -> typent_code ) && $objsoc -> typent_code == 'TE_PRIVATE' ) || ! empty ( $conf -> global -> CONTACT_USE_COMPANY_ADDRESS )) && dol_strlen ( trim ( $object -> zip )) == 0 ) {
2021-02-23 21:16:15 +01:00
$object -> zip = $objsoc -> zip ; // Predefined with third party
}
2021-09-02 18:48:46 +02:00
if ((( isset ( $objsoc -> typent_code ) && $objsoc -> typent_code == 'TE_PRIVATE' ) || ! empty ( $conf -> global -> CONTACT_USE_COMPANY_ADDRESS )) && dol_strlen ( trim ( $object -> town )) == 0 ) {
2021-02-23 21:16:15 +01:00
$object -> town = $objsoc -> town ; // Predefined with third party
}
2020-09-07 10:18:17 +02:00
print '<tr><td><label for="zipcode">' . $langs -> trans ( " Zip " ) . '</label> / <label for="town">' . $langs -> trans ( " Town " ) . '</label></td><td colspan="' . $colspan . '" class="maxwidthonsmartphone">' ;
print $formcompany -> select_ziptown (( GETPOST ( " zipcode " , 'alpha' ) ? GETPOST ( " zipcode " , 'alpha' ) : $object -> zip ), 'zipcode' , array ( 'town' , 'selectcountry_id' , 'state_id' ), 6 ) . ' ' ;
print $formcompany -> select_ziptown (( GETPOST ( " town " , 'alpha' ) ? GETPOST ( " town " , 'alpha' ) : $object -> town ), 'town' , array ( 'zipcode' , 'selectcountry_id' , 'state_id' ));
print '</td></tr>' ;
// Country
print '<tr><td><label for="selectcountry_id">' . $langs -> trans ( " Country " ) . '</label></td><td colspan="' . $colspan . '" class="maxwidthonsmartphone">' ;
print img_picto ( '' , 'globe-americas' , 'class="paddingrightonly"' );
print $form -> select_country (( GETPOST ( " country_id " , 'alpha' ) ? GETPOST ( " country_id " , 'alpha' ) : $object -> country_id ), 'country_id' );
2021-02-23 21:16:15 +01:00
if ( $user -> admin ) {
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2020-09-07 10:18:17 +02:00
print '</td></tr>' ;
// State
2021-02-23 21:16:15 +01:00
if ( empty ( $conf -> global -> SOCIETE_DISABLE_STATE )) {
if ( ! empty ( $conf -> global -> MAIN_SHOW_REGION_IN_STATE_SELECT ) && ( $conf -> global -> MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf -> global -> MAIN_SHOW_REGION_IN_STATE_SELECT == 2 )) {
2020-09-07 10:18:17 +02:00
print '<tr><td><label for="state_id">' . $langs -> trans ( 'Region-State' ) . '</label></td><td colspan="' . $colspan . '" class="maxwidthonsmartphone">' ;
} else {
print '<tr><td><label for="state_id">' . $langs -> trans ( 'State' ) . '</label></td><td colspan="' . $colspan . '" class="maxwidthonsmartphone">' ;
}
2021-02-23 21:16:15 +01:00
if ( $object -> country_id ) {
2021-07-04 19:23:04 +02:00
print img_picto ( '' , 'state' , 'class="pictofixedwidth"' );
2020-09-07 10:18:17 +02:00
print $formcompany -> select_state ( GETPOST ( " state_id " , 'alpha' ) ? GETPOST ( " state_id " , 'alpha' ) : $object -> state_id , $object -> country_code , 'state_id' );
} else {
print $countrynotdefined ;
}
print '</td></tr>' ;
}
2021-09-02 18:48:46 +02:00
if ((( isset ( $objsoc -> typent_code ) && $objsoc -> typent_code == 'TE_PRIVATE' ) || ! empty ( $conf -> global -> CONTACT_USE_COMPANY_ADDRESS )) && dol_strlen ( trim ( $object -> phone_pro )) == 0 ) {
2021-02-23 21:16:15 +01:00
$object -> phone_pro = $objsoc -> phone ; // Predefined with third party
}
2021-09-02 18:48:46 +02:00
if ((( isset ( $objsoc -> typent_code ) && $objsoc -> typent_code == 'TE_PRIVATE' ) || ! empty ( $conf -> global -> CONTACT_USE_COMPANY_ADDRESS )) && dol_strlen ( trim ( $object -> fax )) == 0 ) {
2021-02-23 21:16:15 +01:00
$object -> fax = $objsoc -> fax ; // Predefined with third party
}
2020-09-07 10:18:17 +02:00
// Phone / Fax
print '<tr><td>' . $form -> editfieldkey ( 'PhonePro' , 'phone_pro' , '' , $object , 0 ) . '</td>' ;
print '<td>' ;
print img_picto ( '' , 'object_phoning' );
print '<input type="text" name="phone_pro" id="phone_pro" class="maxwidth200" value="' . ( GETPOSTISSET ( 'phone_pro' ) ? GETPOST ( 'phone_pro' , 'alpha' ) : $object -> phone_pro ) . '"></td>' ;
2021-02-23 21:16:15 +01:00
if ( $conf -> browser -> layout == 'phone' ) {
print '</tr><tr>' ;
}
2020-09-07 10:18:17 +02:00
print '<td>' . $form -> editfieldkey ( 'PhonePerso' , 'phone_perso' , '' , $object , 0 ) . '</td>' ;
print '<td>' ;
print img_picto ( '' , 'object_phoning' );
print '<input type="text" name="phone_perso" id="phone_perso" class="maxwidth200" value="' . ( GETPOSTISSET ( 'phone_perso' ) ? GETPOST ( 'phone_perso' , 'alpha' ) : $object -> phone_perso ) . '"></td></tr>' ;
print '<tr><td>' . $form -> editfieldkey ( 'PhoneMobile' , 'phone_mobile' , '' , $object , 0 ) . '</td>' ;
print '<td>' ;
print img_picto ( '' , 'object_phoning_mobile' );
print '<input type="text" name="phone_mobile" id="phone_mobile" class="maxwidth200" value="' . ( GETPOSTISSET ( 'phone_mobile' ) ? GETPOST ( 'phone_mobile' , 'alpha' ) : $object -> phone_mobile ) . '"></td>' ;
2021-02-23 21:16:15 +01:00
if ( $conf -> browser -> layout == 'phone' ) {
print '</tr><tr>' ;
}
2020-09-07 10:18:17 +02:00
print '<td>' . $form -> editfieldkey ( 'Fax' , 'fax' , '' , $object , 0 ) . '</td>' ;
print '<td>' ;
print img_picto ( '' , 'object_phoning_fax' );
print '<input type="text" name="fax" id="fax" class="maxwidth200" value="' . ( GETPOSTISSET ( 'fax' ) ? GETPOST ( 'fax' , 'alpha' ) : $object -> fax ) . '"></td>' ;
print '</tr>' ;
2021-09-02 18:48:46 +02:00
if ((( isset ( $objsoc -> typent_code ) && $objsoc -> typent_code == 'TE_PRIVATE' ) || ! empty ( $conf -> global -> CONTACT_USE_COMPANY_ADDRESS )) && dol_strlen ( trim ( $object -> email )) == 0 ) {
2021-02-23 21:16:15 +01:00
$object -> email = $objsoc -> email ; // Predefined with third party
}
2020-09-07 10:18:17 +02:00
// Email
print '<tr><td>' . $form -> editfieldkey ( 'EMail' , 'email' , '' , $object , 0 , 'string' , '' ) . '</td>' ;
print '<td>' ;
print img_picto ( '' , 'object_email' );
print '<input type="text" name="email" id="email" value="' . ( GETPOSTISSET ( 'email' ) ? GETPOST ( 'email' , 'alpha' ) : $object -> email ) . '"></td>' ;
print '</tr>' ;
2021-03-09 17:01:20 +01:00
// Unsubscribe
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> mailing -> enabled )) {
2021-09-01 22:37:15 +02:00
if ( $conf -> use_javascript_ajax && $conf -> global -> MAILING_CONTACT_DEFAULT_BULK_STATUS == 2 ) {
2021-11-29 15:09:18 +01:00
print " \n " . '<script type="text/javascript">' . " \n " ;
2021-01-07 17:23:02 +01:00
print ' $ ( document ) . ready ( function () {
$ ( " #email " ) . keyup ( function () {
if ( $ ( this ) . val () != " " ) {
$ ( " .noemail " ) . addClass ( " fieldrequired " );
} else {
$ ( " .noemail " ) . removeClass ( " fieldrequired " );
}
});
}) ' . " \n " ;
print '</script>' . " \n " ;
}
2021-02-23 21:16:15 +01:00
if ( ! GETPOSTISSET ( " no_email " ) && ! empty ( $object -> email )) {
2021-06-14 15:37:02 +02:00
$result = $object -> getNoEmail ();
if ( $result < 0 ) {
2021-01-07 17:23:02 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2020-09-07 10:18:17 +02:00
}
}
print '<tr>' ;
2021-01-07 17:23:02 +01:00
print '<td class="noemail"><label for="no_email">' . $langs -> trans ( " No_Email " ) . '</label></td>' ;
2021-10-26 13:52:00 +02:00
print '<td>' ;
print $form -> selectyesno ( 'no_email' , ( GETPOSTISSET ( " no_email " ) ? GETPOST ( " no_email " , 'int' ) : $conf -> global -> MAILING_CONTACT_DEFAULT_BULK_STATUS ), 1 , false , ( $conf -> global -> MAILING_CONTACT_DEFAULT_BULK_STATUS == 2 ));
print '</td>' ;
2020-09-07 10:18:17 +02:00
print '</tr>' ;
}
2021-01-07 17:23:02 +01:00
2019-11-20 13:31:38 +01:00
2020-09-07 10:18:17 +02:00
if ( ! empty ( $conf -> socialnetworks -> enabled )) {
foreach ( $socialnetworks as $key => $value ) {
if ( $value [ 'active' ]) {
print '<tr>' ;
print '<td><label for="' . $value [ 'label' ] . '">' . $form -> editfieldkey ( $value [ 'label' ], $key , '' , $object , 0 ) . '</label></td>' ;
print '<td colspan="3">' ;
2021-03-09 17:01:20 +01:00
if ( ! empty ( $value [ 'icon' ])) {
print '<span class="fa ' . $value [ 'icon' ] . '"></span>' ;
}
2022-05-11 15:06:11 +02:00
print '<input type="text" name="' . $key . '" id="' . $key . '" class="minwidth100" maxlength="80" value="' . dol_escape_htmltag ( GETPOSTISSET ( $key ) ? GETPOST ( $key , 'alphanohtml' ) : ( ! empty ( $object -> socialnetworks [ $key ]) ? $object -> socialnetworks [ $key ] : " " )) . '">' ;
2020-09-07 10:18:17 +02:00
print '</td>' ;
print '</tr>' ;
} elseif ( ! empty ( $object -> socialnetworks [ $key ])) {
print '<input type="hidden" name="' . $key . '" value="' . $object -> socialnetworks [ $key ] . '">' ;
}
}
}
// Visibility
print '<tr><td><label for="priv">' . $langs -> trans ( " ContactVisibility " ) . '</label></td><td colspan="3">' ;
$selectarray = array ( '0' => $langs -> trans ( " ContactPublic " ), '1' => $langs -> trans ( " ContactPrivate " ));
print $form -> selectarray ( 'priv' , $selectarray , ( GETPOST ( " priv " , 'alpha' ) ? GETPOST ( " priv " , 'alpha' ) : $object -> priv ), 0 );
print '</td></tr>' ;
2011-03-26 19:34:41 +01:00
2022-04-22 13:47:58 +02:00
//Default language
2022-05-25 09:12:59 +02:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS )) {
2022-04-22 13:47:58 +02:00
print '<tr><td>' . $form -> editfieldkey ( 'DefaultLang' , 'default_lang' , '' , $object , 0 ) . '</td><td colspan="3" class="maxwidthonsmartphone">' . " \n " ;
2022-08-20 13:09:28 +02:00
print img_picto ( '' , 'language' , 'class="pictofixedwidth"' ) . $formadmin -> select_language ( GETPOST ( 'default_lang' , 'alpha' ) ? GETPOST ( 'default_lang' , 'alpha' ) : ( $object -> default_lang ? $object -> default_lang : '' ), 'default_lang' , 0 , 0 , 1 , 0 , 0 , 'maxwidth200onsmartphone' );
2022-04-22 13:47:58 +02:00
print '</td>' ;
print '</tr>' ;
}
2015-06-11 14:50:11 +02:00
// Categories
2019-11-13 19:35:02 +01:00
if ( ! empty ( $conf -> categorie -> enabled ) && ! empty ( $user -> rights -> categorie -> lire )) {
print '<tr><td>' . $form -> editfieldkey ( 'Categories' , 'contcats' , '' , $object , 0 ) . '</td><td colspan="3">' ;
2018-10-27 17:45:29 +02:00
$cate_arbo = $form -> select_all_categories ( Categorie :: TYPE_CONTACT , null , 'parent' , null , null , 1 );
2021-01-03 18:42:45 +01:00
print img_picto ( '' , 'category' ) . $form -> multiselectarray ( 'contcats' , $cate_arbo , GETPOST ( 'contcats' , 'array' ), null , null , null , null , '90%' );
2015-06-11 14:50:11 +02:00
print " </td></tr> " ;
}
2020-09-07 10:18:17 +02:00
// Contact by default
if ( ! empty ( $socid )) {
print '<tr><td>' . $langs -> trans ( " ContactByDefaultFor " ) . '</td>' ;
print '<td colspan="3">' ;
$contactType = $object -> listeTypeContacts ( 'external' , '' , 1 );
2021-02-22 15:54:24 +01:00
print $form -> multiselectarray ( 'roles' , $contactType , array (), 0 , 0 , 'minwidth500' );
2020-09-07 10:18:17 +02:00
print '</td></tr>' ;
}
// Other attributes
2021-12-06 16:55:51 +01:00
$parameters = array ( 'socid' => $socid , 'objsoc' => $objsoc , 'colspan' => ' colspan="3"' , 'cols' => 3 , 'colspanvalue' => 3 );
2021-05-26 17:45:45 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php' ;
2020-09-07 10:18:17 +02:00
print " </table><br> " ;
2010-11-19 22:24:48 +01:00
2017-03-24 17:32:38 +01:00
print '<hr style="margin-bottom: 20px">' ;
2017-06-07 16:44:04 +02:00
2020-09-07 10:18:17 +02:00
// Add personnal information
print load_fiche_titre ( '<div class="comboperso">' . $langs -> trans ( " PersonalInformations " ) . '</div>' , '' , '' );
print '<table class="border centpercent">' ;
// Date To Birth
2020-09-16 00:47:44 +02:00
print '<tr><td><label for="birthday">' . $langs -> trans ( " DateOfBirth " ) . '</label></td><td>' ;
2020-09-07 10:18:17 +02:00
$form = new Form ( $db );
2021-02-23 21:16:15 +01:00
if ( $object -> birthday ) {
2020-09-07 10:18:17 +02:00
print $form -> selectDate ( $object -> birthday , 'birthday' , 0 , 0 , 0 , " perso " , 1 , 0 );
} else {
print $form -> selectDate ( '' , 'birthday' , 0 , 0 , 1 , " perso " , 1 , 0 );
}
print '</td>' ;
print '<td><label for="birthday_alert">' . $langs -> trans ( " Alert " ) . '</label>: ' ;
2021-09-02 18:48:46 +02:00
if ( ! empty ( $object -> birthday_alert )) {
2020-09-07 10:18:17 +02:00
print '<input type="checkbox" name="birthday_alert" id="birthday_alert" checked>' ;
} else {
print '<input type="checkbox" name="birthday_alert" id="birthday_alert">' ;
}
print '</td>' ;
print '</tr>' ;
print " </table> " ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2020-09-07 10:18:17 +02:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ( " Add " );
2020-09-07 10:18:17 +02:00
print " </form> " ;
2020-11-22 13:23:56 +01:00
} elseif ( $action == 'edit' && ! empty ( $id )) {
2020-09-07 10:18:17 +02:00
/*
2021-02-23 21:16:15 +01:00
* Fiche en mode edition
*/
2011-03-26 19:34:41 +01:00
2020-09-07 10:18:17 +02:00
// We set country_id, and country_code label of the chosen country
2021-02-23 21:16:15 +01:00
if ( GETPOSTISSET ( " country_id " ) || $object -> country_id ) {
2020-09-07 10:18:17 +02:00
$tmparray = getCountry ( $object -> country_id , 'all' );
$object -> country_code = $tmparray [ 'code' ];
$object -> country = $tmparray [ 'label' ];
}
2012-10-06 19:25:25 +02:00
2012-09-28 14:56:47 +02:00
$objsoc = new Societe ( $db );
$objsoc -> fetch ( $object -> socid );
2011-03-26 19:34:41 +01:00
2019-05-31 11:53:30 +02:00
// Show errors
2019-11-13 19:35:02 +01:00
dol_htmloutput_errors ( is_numeric ( $error ) ? '' : $error , $errors );
2011-03-26 19:34:41 +01:00
2021-02-23 21:16:15 +01:00
if ( $conf -> use_javascript_ajax ) {
2021-11-29 15:09:18 +01:00
print " \n " . '<script type="text/javascript">' . " \n " ;
2012-09-28 14:56:47 +02:00
print ' jQuery ( document ) . ready ( function () {
2011-12-29 18:07:41 +01:00
jQuery ( " #selectcountry_id " ) . change ( function () {
2012-09-28 14:58:47 +02:00
document . formsoc . action . value = " edit " ;
2010-11-03 12:39:40 +01:00
document . formsoc . submit ();
});
2012-10-06 19:25:25 +02:00
2012-09-28 14:56:47 +02:00
$ ( " #copyaddressfromsoc " ) . click ( function () {
2016-02-03 02:06:12 +01:00
$ ( \ 'textarea[name="address"]\').val("' . dol_escape_js ( $objsoc -> address ) . ' " );
2013-03-01 18:41:41 +01:00
$ ( \ 'input[name="zipcode"]\').val("' . dol_escape_js ( $objsoc -> zip ) . ' " );
$ ( \ 'input[name="town"]\').val("' . dol_escape_js ( $objsoc -> town ) . ' " );
2016-02-03 02:06:12 +01:00
console . log ( " Set state_id to '.dol_escape_js( $objsoc->state_id ).' " );
$ ( \ 'select[name="state_id"]\').val("' . dol_escape_js ( $objsoc -> state_id ) . ' " ).trigger( " change " );
/* set country at end because it will trigger page refresh */
console . log ( " Set country id to '.dol_escape_js( $objsoc->country_id ).' " );
$ ( \ 'select[name="country_id"]\').val("' . dol_escape_js ( $objsoc -> country_id ) . ' " ).trigger( " change " ); /* trigger required to update select2 components */
2012-10-06 19:25:25 +02:00
});
2012-09-28 14:56:47 +02:00
}) ' . " \n " ;
print '</script>' . " \n " ;
2020-09-07 10:18:17 +02:00
}
print '<form enctype="multipart/form-data" method="post" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $id . '" name="formsoc">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="id" value="' . $id . '">' ;
print '<input type="hidden" name="action" value="update">' ;
print '<input type="hidden" name="contactid" value="' . $object -> id . '">' ;
print '<input type="hidden" name="old_lastname" value="' . $object -> lastname . '">' ;
print '<input type="hidden" name="old_firstname" value="' . $object -> firstname . '">' ;
2021-02-23 21:16:15 +01:00
if ( ! empty ( $backtopage )) {
print '<input type="hidden" name="backtopage" value="' . $backtopage . '">' ;
}
2020-09-07 10:18:17 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'card' , $title , 0 , 'contact' );
2020-09-07 10:18:17 +02:00
print '<table class="border centpercent">' ;
// Ref/ID
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> global -> MAIN_SHOW_TECHNICAL_ID )) {
2020-09-07 10:18:17 +02:00
print '<tr><td>' . $langs -> trans ( " ID " ) . '</td><td colspan="3">' ;
print $object -> ref ;
print '</td></tr>' ;
2021-02-23 21:16:15 +01:00
}
2020-09-07 10:18:17 +02:00
// Lastname
print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">' . $langs -> trans ( " Lastname " ) . ' / ' . $langs -> trans ( " Label " ) . '</label></td>' ;
print '<td colspan="3"><input name="lastname" id="lastname" type="text" class="minwidth200" maxlength="80" value="' . ( GETPOSTISSET ( " lastname " ) ? GETPOST ( " lastname " ) : $object -> lastname ) . '" autofocus="autofocus"></td>' ;
print '</tr>' ;
print '<tr>' ;
// Firstname
print '<td><label for="firstname">' . $langs -> trans ( " Firstname " ) . '</label></td>' ;
print '<td colspan="3"><input name="firstname" id="firstname" type="text" class="minwidth200" maxlength="80" value="' . ( GETPOSTISSET ( " firstname " ) ? GETPOST ( " firstname " ) : $object -> firstname ) . '"></td>' ;
print '</tr>' ;
// Company
2021-02-23 21:16:15 +01:00
if ( empty ( $conf -> global -> SOCIETE_DISABLE_CONTACTS )) {
2020-09-07 10:18:17 +02:00
print '<tr><td><label for="socid">' . $langs -> trans ( " ThirdParty " ) . '</label></td>' ;
print '<td colspan="3" class="maxwidthonsmartphone">' ;
2021-01-03 18:42:45 +01:00
print img_picto ( '' , 'company' ) . $form -> select_company ( GETPOST ( 'socid' , 'int' ) ? GETPOST ( 'socid' , 'int' ) : ( $object -> socid ? $object -> socid : - 1 ), 'socid' , '' , $langs -> trans ( " SelectThirdParty " ));
2020-09-07 10:18:17 +02:00
print '</td>' ;
print '</tr>' ;
}
// Civility
print '<tr><td><label for="civility_code">' . $langs -> trans ( " UserTitle " ) . '</label></td><td colspan="3">' ;
print $formcompany -> select_civility ( GETPOSTISSET ( " civility_code " ) ? GETPOST ( " civility_code " , " aZ09 " ) : $object -> civility_code , 'civility_code' );
print '</td></tr>' ;
2021-01-27 19:31:30 +01:00
// Job position
2020-09-07 10:18:17 +02:00
print '<tr><td><label for="title">' . $langs -> trans ( " PostOrFunction " ) . '</label></td>' ;
2021-01-27 19:31:30 +01:00
print '<td colspan="3"><input name="poste" id="title" type="text" class="minwidth100" maxlength="255" value="' . dol_escape_htmltag ( GETPOSTISSET ( " poste " ) ? GETPOST ( " poste " , 'alphanohtml' ) : $object -> poste ) . '"></td></tr>' ;
2020-09-07 10:18:17 +02:00
// Address
print '<tr><td><label for="address">' . $langs -> trans ( " Address " ) . '</label></td>' ;
print '<td colspan="3">' ;
print '<div class="paddingrightonly valignmiddle inline-block quatrevingtpercent">' ;
2022-06-13 10:44:20 +02:00
print '<textarea class="flat minwidth200 centpercent" name="address" id="address">' . ( GETPOSTISSET ( " address " ) ? GETPOST ( " address " , 'alphanohtml' ) : $object -> address ) . '</textarea>' ;
2020-09-07 10:18:17 +02:00
print '</div><div class="paddingrightonly valignmiddle inline-block">' ;
2021-02-23 21:16:15 +01:00
if ( $conf -> use_javascript_ajax ) {
print '<a href="#" id="copyaddressfromsoc">' . $langs -> trans ( 'CopyAddressFromSoc' ) . '</a><br>' ;
}
2020-09-07 10:18:17 +02:00
print '</div>' ;
print '</td>' ;
// Zip / Town
print '<tr><td><label for="zipcode">' . $langs -> trans ( " Zip " ) . '</label> / <label for="town">' . $langs -> trans ( " Town " ) . '</label></td><td colspan="3" class="maxwidthonsmartphone">' ;
print $formcompany -> select_ziptown (( GETPOSTISSET ( " zipcode " ) ? GETPOST ( " zipcode " ) : $object -> zip ), 'zipcode' , array ( 'town' , 'selectcountry_id' , 'state_id' ), 6 ) . ' ' ;
print $formcompany -> select_ziptown (( GETPOSTISSET ( " town " ) ? GETPOST ( " town " ) : $object -> town ), 'town' , array ( 'zipcode' , 'selectcountry_id' , 'state_id' ));
print '</td></tr>' ;
// Country
print '<tr><td><label for="selectcountry_id">' . $langs -> trans ( " Country " ) . '</label></td><td colspan="3" class="maxwidthonsmartphone">' ;
print img_picto ( '' , 'globe-americas' , 'class="paddingrightonly"' );
print $form -> select_country ( GETPOSTISSET ( " country_id " ) ? GETPOST ( " country_id " ) : $object -> country_id , 'country_id' );
2021-02-23 21:16:15 +01:00
if ( $user -> admin ) {
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2020-09-07 10:18:17 +02:00
print '</td></tr>' ;
// State
2021-02-23 21:16:15 +01:00
if ( empty ( $conf -> global -> SOCIETE_DISABLE_STATE )) {
if ( ! empty ( $conf -> global -> MAIN_SHOW_REGION_IN_STATE_SELECT ) && ( $conf -> global -> MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf -> global -> MAIN_SHOW_REGION_IN_STATE_SELECT == 2 )) {
2020-09-07 10:18:17 +02:00
print '<tr><td><label for="state_id">' . $langs -> trans ( 'Region-State' ) . '</label></td><td colspan="3" class="maxwidthonsmartphone">' ;
} else {
print '<tr><td><label for="state_id">' . $langs -> trans ( 'State' ) . '</label></td><td colspan="3" class="maxwidthonsmartphone">' ;
}
2021-07-04 19:23:04 +02:00
print img_picto ( '' , 'state' , 'class="pictofixedwidth"' );
2020-09-07 10:18:17 +02:00
print $formcompany -> select_state ( GETPOSTISSET ( 'state_id' ) ? GETPOST ( 'state_id' , 'alpha' ) : $object -> state_id , $object -> country_code , 'state_id' );
print '</td></tr>' ;
}
// Phone
print '<tr><td>' . $form -> editfieldkey ( 'PhonePro' , 'phone_pro' , GETPOST ( 'phone_pro' , 'alpha' ), $object , 0 ) . '</td>' ;
print '<td>' ;
print img_picto ( '' , 'object_phoning' );
print '<input type="text" name="phone_pro" id="phone_pro" class="maxwidth200" maxlength="80" value="' . ( GETPOSTISSET ( 'phone_pro' ) ? GETPOST ( 'phone_pro' , 'alpha' ) : $object -> phone_pro ) . '"></td>' ;
print '<td>' . $form -> editfieldkey ( 'PhonePerso' , 'fax' , GETPOST ( 'phone_perso' , 'alpha' ), $object , 0 ) . '</td>' ;
print '<td>' ;
print img_picto ( '' , 'object_phoning' );
print '<input type="text" name="phone_perso" id="phone_perso" class="maxwidth200" maxlength="80" value="' . ( GETPOSTISSET ( 'phone_perso' ) ? GETPOST ( 'phone_perso' , 'alpha' ) : $object -> phone_perso ) . '"></td></tr>' ;
print '<tr><td>' . $form -> editfieldkey ( 'PhoneMobile' , 'phone_mobile' , GETPOST ( 'phone_mobile' , 'alpha' ), $object , 0 , 'string' , '' ) . '</td>' ;
print '<td>' ;
print img_picto ( '' , 'object_phoning_mobile' );
print '<input type="text" name="phone_mobile" id="phone_mobile" class="maxwidth200" maxlength="80" value="' . ( GETPOSTISSET ( 'phone_mobile' ) ? GETPOST ( 'phone_mobile' , 'alpha' ) : $object -> phone_mobile ) . '"></td>' ;
print '<td>' . $form -> editfieldkey ( 'Fax' , 'fax' , GETPOST ( 'fax' , 'alpha' ), $object , 0 ) . '</td>' ;
print '<td>' ;
print img_picto ( '' , 'object_phoning_fax' );
print '<input type="text" name="fax" id="fax" class="maxwidth200" maxlength="80" value="' . ( GETPOSTISSET ( 'phone_fax' ) ? GETPOST ( 'phone_fax' , 'alpha' ) : $object -> fax ) . '"></td></tr>' ;
// EMail
print '<tr><td>' . $form -> editfieldkey ( 'EMail' , 'email' , GETPOST ( 'email' , 'alpha' ), $object , 0 , 'string' , '' , ( ! empty ( $conf -> global -> SOCIETE_EMAIL_MANDATORY ))) . '</td>' ;
print '<td>' ;
print img_picto ( '' , 'object_email' );
print '<input type="text" name="email" id="email" class="maxwidth100onsmartphone quatrevingtpercent" value="' . ( GETPOSTISSET ( 'email' ) ? GETPOST ( 'email' , 'alpha' ) : $object -> email ) . '"></td>' ;
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> mailing -> enabled )) {
2020-09-07 10:18:17 +02:00
$langs -> load ( " mails " );
print '<td class="nowrap">' . $langs -> trans ( " NbOfEMailingsSend " ) . '</td>' ;
print '<td>' . $object -> getNbOfEMailings () . '</td>' ;
} else {
2019-10-17 16:59:26 +02:00
print '<td colspan="2"></td>' ;
2020-09-07 10:18:17 +02:00
}
print '</tr>' ;
// Unsubscribe
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> mailing -> enabled )) {
2021-09-01 22:37:15 +02:00
if ( $conf -> use_javascript_ajax && isset ( $conf -> global -> MAILING_CONTACT_DEFAULT_BULK_STATUS ) && $conf -> global -> MAILING_CONTACT_DEFAULT_BULK_STATUS == 2 ) {
2021-11-29 15:09:18 +01:00
print " \n " . '<script type="text/javascript">' . " \n " ;
2021-01-12 10:01:32 +01:00
print '
jQuery ( document ) . ready ( function () {
function init_check_no_email ( input ) {
if ( input . val () != " " ) {
$ ( " .noemail " ) . addClass ( " fieldrequired " );
} else {
$ ( " .noemail " ) . removeClass ( " fieldrequired " );
}
}
$ ( " #email " ) . keyup ( function () {
init_check_no_email ( $ ( this ));
});
init_check_no_email ( $ ( " #email " ));
}) ' . " \n " ;
2021-01-07 17:23:02 +01:00
print '</script>' . " \n " ;
}
2021-02-23 21:16:15 +01:00
if ( ! GETPOSTISSET ( " no_email " ) && ! empty ( $object -> email )) {
2021-06-14 15:37:02 +02:00
$result = $object -> getNoEmail ();
if ( $result < 0 ) {
2021-01-07 17:23:02 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2020-09-07 10:18:17 +02:00
}
}
2021-01-07 17:23:02 +01:00
print '<tr>' ;
print '<td class="noemail"><label for="no_email">' . $langs -> trans ( " No_Email " ) . '</label></td>' ;
2021-10-26 13:52:00 +02:00
print '<td>' ;
2021-09-01 22:37:15 +02:00
$useempty = ( isset ( $conf -> global -> MAILING_CONTACT_DEFAULT_BULK_STATUS ) && ( $conf -> global -> MAILING_CONTACT_DEFAULT_BULK_STATUS == 2 ));
2021-10-26 13:52:00 +02:00
print $form -> selectyesno ( 'no_email' , ( GETPOSTISSET ( " no_email " ) ? GETPOST ( " no_email " , 'int' ) : $object -> no_email ), 1 , false , $useempty );
print '</td>' ;
2021-01-07 17:23:02 +01:00
print '</tr>' ;
2012-08-26 20:28:19 +02:00
}
2020-09-07 10:18:17 +02:00
if ( ! empty ( $conf -> socialnetworks -> enabled )) {
foreach ( $socialnetworks as $key => $value ) {
if ( $value [ 'active' ]) {
print '<tr>' ;
print '<td><label for="' . $value [ 'label' ] . '">' . $form -> editfieldkey ( $value [ 'label' ], $key , '' , $object , 0 ) . '</label></td>' ;
print '<td colspan="3">' ;
2021-03-09 17:01:20 +01:00
if ( ! empty ( $value [ 'icon' ])) {
print '<span class="fa ' . $value [ 'icon' ] . '"></span>' ;
}
2021-03-18 22:29:08 +01:00
print '<input type="text" name="' . $key . '" id="' . $key . '" class="minwidth100" maxlength="80" value="' . dol_escape_htmltag ( GETPOSTISSET ( $key ) ? GETPOST ( $key , 'alphanohtml' ) : ( empty ( $object -> socialnetworks [ $key ]) ? '' : $object -> socialnetworks [ $key ])) . '">' ;
2020-09-07 10:18:17 +02:00
print '</td>' ;
print '</tr>' ;
} elseif ( ! empty ( $object -> socialnetworks [ $key ])) {
print '<input type="hidden" name="' . $key . '" value="' . $object -> socialnetworks [ $key ] . '">' ;
}
}
}
// Visibility
print '<tr><td><label for="priv">' . $langs -> trans ( " ContactVisibility " ) . '</label></td><td colspan="3">' ;
$selectarray = array ( '0' => $langs -> trans ( " ContactPublic " ), '1' => $langs -> trans ( " ContactPrivate " ));
print $form -> selectarray ( 'priv' , $selectarray , $object -> priv , 0 );
print '</td></tr>' ;
2022-04-22 13:47:58 +02:00
//Default language
2022-05-25 09:12:59 +02:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS )) {
2022-04-22 13:47:58 +02:00
print '<tr><td>' . $form -> editfieldkey ( 'DefaultLang' , 'default_lang' , '' , $object , 0 ) . '</td><td colspan="3" class="maxwidthonsmartphone">' . " \n " ;
2022-08-20 13:09:28 +02:00
print img_picto ( '' , 'language' , 'class="pictofixedwidth"' ) . $formadmin -> select_language ( GETPOST ( 'default_lang' , 'alpha' ) ? GETPOST ( 'default_lang' , 'alpha' ) : ( $object -> default_lang ? $object -> default_lang : '' ), 'default_lang' , 0 , 0 , 1 , 0 , 0 , 'maxwidth200onsmartphone' );
2022-04-22 13:47:58 +02:00
print '</td>' ;
print '</tr>' ;
}
2020-09-07 10:18:17 +02:00
// Note Public
print '<tr><td class="tdtop"><label for="note_public">' . $langs -> trans ( " NotePublic " ) . '</label></td><td colspan="3">' ;
2020-11-30 14:54:44 +01:00
$doleditor = new DolEditor ( 'note_public' , $object -> note_public , '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , empty ( $conf -> global -> FCKEDITOR_ENABLE_NOTE_PUBLIC ) ? 0 : 1 , ROWS_3 , '90%' );
2020-09-07 10:18:17 +02:00
print $doleditor -> Create ( 1 );
print '</td></tr>' ;
// Note Private
print '<tr><td class="tdtop"><label for="note_private">' . $langs -> trans ( " NotePrivate " ) . '</label></td><td colspan="3">' ;
2020-11-30 14:54:44 +01:00
$doleditor = new DolEditor ( 'note_private' , $object -> note_private , '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , empty ( $conf -> global -> FCKEDITOR_ENABLE_NOTE_PRIVATE ) ? 0 : 1 , ROWS_3 , '90%' );
2020-09-07 10:18:17 +02:00
print $doleditor -> Create ( 1 );
print '</td></tr>' ;
// Status
print '<tr><td>' . $langs -> trans ( " Status " ) . '</td>' ;
print '<td colspan="3">' ;
print $object -> getLibStatut ( 4 );
print '</td></tr>' ;
2013-07-10 12:28:28 +02:00
2015-06-11 14:50:11 +02:00
// Categories
2018-10-27 17:45:29 +02:00
if ( ! empty ( $conf -> categorie -> enabled ) && ! empty ( $user -> rights -> categorie -> lire )) {
2022-07-20 16:35:51 +02:00
$arrayselected = array ();
2019-11-13 19:35:02 +01:00
print '<tr><td>' . $form -> editfieldkey ( 'Categories' , 'contcats' , '' , $object , 0 ) . '</td>' ;
2015-06-11 14:50:11 +02:00
print '<td colspan="3">' ;
2018-10-27 17:45:29 +02:00
$cate_arbo = $form -> select_all_categories ( Categorie :: TYPE_CONTACT , null , null , null , null , 1 );
$c = new Categorie ( $db );
$cats = $c -> containing ( $object -> id , 'contact' );
2015-06-11 14:50:11 +02:00
foreach ( $cats as $cat ) {
$arrayselected [] = $cat -> id ;
}
2021-01-03 18:42:45 +01:00
print img_picto ( '' , 'category' ) . $form -> multiselectarray ( 'contcats' , $cate_arbo , $arrayselected , '' , 0 , '' , 0 , '90%' );
2015-06-11 14:50:11 +02:00
print " </td></tr> " ;
}
2019-10-07 15:42:37 +02:00
// Contact by default
2020-09-07 10:18:17 +02:00
if ( ! empty ( $object -> socid )) {
print '<tr><td>' . $langs -> trans ( " ContactByDefaultFor " ) . '</td>' ;
print '<td colspan="3">' ;
print $formcompany -> showRoles ( " roles " , $object , 'edit' , $object -> roles );
print '</td></tr>' ;
}
// Other attributes
2021-12-06 16:55:51 +01:00
$parameters = array ( 'colspan' => ' colspan="3"' , 'cols' => '3' , 'colspanvalue' => '3' );
2021-05-26 17:45:45 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php' ;
2020-09-07 10:18:17 +02:00
$object -> load_ref_elements ();
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> commande -> enabled )) {
2020-09-07 10:18:17 +02:00
print '<tr><td>' . $langs -> trans ( " ContactForOrders " ) . '</td><td colspan="3">' ;
2021-09-06 12:56:33 +02:00
print $object -> ref_commande ? $object -> ref_commande : ( '<span class="opacitymedium">' . $langs -> trans ( " NoContactForAnyOrder " ) . '</span>' );
2020-09-07 10:18:17 +02:00
print '</td></tr>' ;
}
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> propal -> enabled )) {
2020-09-07 10:18:17 +02:00
print '<tr><td>' . $langs -> trans ( " ContactForProposals " ) . '</td><td colspan="3">' ;
2021-09-06 12:56:33 +02:00
print $object -> ref_propal ? $object -> ref_propal : ( '<span class="opacitymedium">' . $langs -> trans ( " NoContactForAnyProposal " ) . '</span>' );
2020-09-07 10:18:17 +02:00
print '</td></tr>' ;
}
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> contrat -> enabled )) {
2020-09-07 10:18:17 +02:00
print '<tr><td>' . $langs -> trans ( " ContactForContracts " ) . '</td><td colspan="3">' ;
2021-09-06 12:56:33 +02:00
print $object -> ref_contrat ? $object -> ref_contrat : ( '<span class="opacitymedium">' . $langs -> trans ( " NoContactForAnyContract " ) . '</span>' );
2020-09-07 10:18:17 +02:00
print '</td></tr>' ;
}
2022-06-11 09:46:28 +02:00
if ( isModEnabled ( 'facture' )) {
2020-09-07 10:18:17 +02:00
print '<tr><td>' . $langs -> trans ( " ContactForInvoices " ) . '</td><td colspan="3">' ;
2021-09-06 12:56:33 +02:00
print $object -> ref_facturation ? $object -> ref_facturation : ( '<span class="opacitymedium">' . $langs -> trans ( " NoContactForAnyInvoice " ) . '</span>' );
2020-09-07 10:18:17 +02:00
print '</td></tr>' ;
}
// Login Dolibarr
print '<tr><td>' . $langs -> trans ( " DolibarrLogin " ) . '</td><td colspan="3">' ;
2021-02-23 21:16:15 +01:00
if ( $object -> user_id ) {
2020-09-07 10:18:17 +02:00
$dolibarr_user = new User ( $db );
$result = $dolibarr_user -> fetch ( $object -> user_id );
print $dolibarr_user -> getLoginUrl ( 1 );
2021-02-23 21:16:15 +01:00
} else {
2021-09-06 12:56:33 +02:00
print '<span class="opacitymedium">' . $langs -> trans ( " NoDolibarrAccess " ) . '</span>' ;
2021-02-23 21:16:15 +01:00
}
2020-09-07 10:18:17 +02:00
print '</td></tr>' ;
// Photo
print '<tr>' ;
print '<td>' . $langs -> trans ( " PhotoFile " ) . '</td>' ;
print '<td colspan="3">' ;
if ( $object -> photo ) {
print $form -> showphoto ( 'contact' , $object );
print " <br> \n " ;
}
print '<table class="nobordernopadding">' ;
2021-02-23 21:16:15 +01:00
if ( $object -> photo ) {
print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> ' . $langs -> trans ( " Delete " ) . '<br><br></td></tr>' ;
}
2020-09-07 10:18:17 +02:00
//print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
2022-06-19 19:02:16 +02:00
print '<tr><td>' ;
$maxfilesizearray = getMaxFileSizeArray ();
$maxmin = $maxfilesizearray [ 'maxmin' ];
if ( $maxmin > 0 ) {
2022-06-20 02:23:37 +02:00
print '<input type="hidden" name="MAX_FILE_SIZE" value="' . ( $maxmin * 1024 ) . '">' ; // MAX_FILE_SIZE must precede the field type=file
2022-06-19 19:02:16 +02:00
}
print '<input type="file" class="flat" name="photo" id="photoinput">' ;
print '</td></tr>' ;
2020-09-07 10:18:17 +02:00
print '</table>' ;
print '</td>' ;
print '</tr>' ;
print '</table>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2020-09-07 10:18:17 +02:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ();
2020-09-07 10:18:17 +02:00
print " </form> " ;
}
}
2020-10-31 14:32:18 +01:00
// Select mail models is same action as presend
if ( GETPOST ( 'modelselected' , 'alpha' )) {
$action = 'presend' ;
}
2022-07-18 11:51:28 +02:00
// View mode
2021-02-23 21:16:15 +01:00
if ( ! empty ( $id ) && $action != 'edit' && $action != 'create' ) {
2020-10-31 14:32:18 +01:00
$objsoc = new Societe ( $db );
2020-09-07 10:18:17 +02:00
// Show errors
dol_htmloutput_errors ( is_numeric ( $error ) ? '' : $error , $errors );
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'card' , $title , - 1 , 'contact' );
2020-09-07 10:18:17 +02:00
2021-02-23 21:16:15 +01:00
if ( $action == 'create_user' ) {
2020-09-07 10:18:17 +02:00
// Full firstname and lastname separated with a dot : firstname.lastname
include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
$login = dol_buildlogin ( $object -> lastname , $object -> firstname );
$generated_password = '' ;
2021-02-23 21:16:15 +01:00
if ( ! $ldap_sid ) { // TODO ldap_sid ?
2020-09-07 10:18:17 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php' ;
$generated_password = getRandomPassword ( false );
}
$password = $generated_password ;
// Create a form array
$formquestion = array (
array ( 'label' => $langs -> trans ( " LoginToCreate " ), 'type' => 'text' , 'name' => 'login' , 'value' => $login ),
array ( 'label' => $langs -> trans ( " Password " ), 'type' => 'text' , 'name' => 'password' , 'value' => $password ),
//array('label' => $form->textwithpicto($langs->trans("Type"),$langs->trans("InternalExternalDesc")), 'type' => 'select', 'name' => 'intern', 'default' => 1, 'values' => array(0=>$langs->trans('Internal'),1=>$langs->trans('External')))
);
$text = $langs -> trans ( " ConfirmCreateContact " ) . '<br>' ;
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> societe -> enabled )) {
if ( $object -> socid > 0 ) {
$text .= $langs -> trans ( " UserWillBeExternalUser " );
} else {
$text .= $langs -> trans ( " UserWillBeInternalUser " );
}
2020-09-07 10:18:17 +02:00
}
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id , $langs -> trans ( " CreateDolibarrLogin " ), $text , " confirm_create_user " , $formquestion , 'yes' );
}
$linkback = '<a href="' . DOL_URL_ROOT . '/contact/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2022-01-09 20:43:26 +01:00
$morehtmlref = '<a href="' . DOL_URL_ROOT . '/contact/vcard.php?id=' . $object -> id . '" class="refid">' ;
$morehtmlref .= img_picto ( $langs -> trans ( " Download " ) . ' ' . $langs -> trans ( " VCard " ), 'vcard.png' , 'class="valignmiddle marginleftonly paddingrightonly"' );
$morehtmlref .= '</a>' ;
$morehtmlref .= '<div class="refidno">' ;
2021-02-23 21:16:15 +01:00
if ( empty ( $conf -> global -> SOCIETE_DISABLE_CONTACTS )) {
2020-09-07 10:18:17 +02:00
$objsoc -> fetch ( $object -> socid );
// Thirdparty
$morehtmlref .= $langs -> trans ( 'ThirdParty' ) . ' : ' ;
2021-02-23 21:16:15 +01:00
if ( $objsoc -> id > 0 ) {
$morehtmlref .= $objsoc -> getNomUrl ( 1 , 'contact' );
} else {
2021-09-21 16:53:29 +02:00
$morehtmlref .= '<span class="opacitymedium">' . $langs -> trans ( " ContactNotLinkedToCompany " ) . '</span>' ;
2021-02-23 21:16:15 +01:00
}
2020-09-07 10:18:17 +02:00
}
$morehtmlref .= '</div>' ;
dol_banner_tab ( $object , 'id' , $linkback , 1 , 'rowid' , 'ref' , $morehtmlref );
print '<div class="fichecenter">' ;
print '<div class="fichehalfleft">' ;
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border tableforfield" width="100%">' ;
// Civility
print '<tr><td class="titlefield">' . $langs -> trans ( " UserTitle " ) . '</td><td>' ;
print $object -> getCivilityLabel ();
print '</td></tr>' ;
// Job / position
print '<tr><td>' . $langs -> trans ( " PostOrFunction " ) . '</td><td>' . $object -> poste . '</td></tr>' ;
// Email
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> mailing -> enabled )) {
2020-09-07 10:18:17 +02:00
$langs -> load ( " mails " );
print '<tr><td>' . $langs -> trans ( " NbOfEMailingsSend " ) . '</td>' ;
print '<td><a href="' . DOL_URL_ROOT . '/comm/mailing/list.php?filteremail=' . urlencode ( $object -> email ) . '">' . $object -> getNbOfEMailings () . '</a></td></tr>' ;
}
// Unsubscribe opt-out
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> mailing -> enabled )) {
2021-06-14 15:37:02 +02:00
$result = $object -> getNoEmail ();
if ( $result < 0 ) {
2021-01-07 17:23:02 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2020-09-07 10:18:17 +02:00
}
2021-10-26 13:52:00 +02:00
print '<tr><td>' . $langs -> trans ( " No_Email " ) . '</td><td>' ;
if ( $object -> email ) {
print yn ( $object -> no_email );
} else {
print '<span class="opacitymedium">' . $langs -> trans ( " EMailNotDefined " ) . '</span>' ;
}
print '</td></tr>' ;
2020-09-07 10:18:17 +02:00
}
2022-04-22 13:47:58 +02:00
// Default language
2022-05-25 09:12:59 +02:00
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS )) {
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
print '<tr><td>' . $langs -> trans ( " DefaultLang " ) . '</td><td>' ;
//$s=picto_from_langcode($object->default_lang);
//print ($s?$s.' ':'');
$langs -> load ( " languages " );
2022-08-20 13:09:28 +02:00
$labellang = ( $object -> default_lang ? $langs -> trans ( 'Language_' . $object -> default_lang ) : '' );
print picto_from_langcode ( $object -> default_lang , 'class="paddingrightonly saturatemedium opacitylow"' );
2022-05-25 09:12:59 +02:00
print $labellang ;
print '</td></tr>' ;
}
2020-09-07 10:18:17 +02:00
print '<tr><td>' . $langs -> trans ( " ContactVisibility " ) . '</td><td>' ;
print $object -> LibPubPriv ( $object -> priv );
print '</td></tr>' ;
print '</table>' ;
print '</div>' ;
2017-06-07 16:44:04 +02:00
2020-04-27 17:35:14 +02:00
$object -> fetch_thirdparty ();
2020-09-08 21:27:28 +02:00
if ( ! empty ( $conf -> global -> THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES )) {
2021-02-23 21:16:15 +01:00
if ( $object -> thirdparty -> client == 2 || $object -> thirdparty -> client == 3 ) {
2020-08-02 22:30:23 +02:00
print '<br>' ;
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border" width="100%">' ;
// Level of prospect
print '<tr><td class="titlefield nowrap">' ;
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">' ;
print $langs -> trans ( 'ProspectLevel' );
print '<td>' ;
2021-02-23 21:16:15 +01:00
if ( $action != 'editlevel' && $user -> rights -> societe -> contact -> creer ) {
2021-09-27 12:24:01 +02:00
print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editlevel&token=' . newToken () . '&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'Modify' ), 1 ) . '</a></td>' ;
2021-02-23 21:16:15 +01:00
}
2020-08-02 22:30:23 +02:00
print '</tr></table>' ;
print '</td><td>' ;
if ( $action == 'editlevel' ) {
2020-09-08 21:27:28 +02:00
$formcompany -> formProspectContactLevel ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> fk_prospectlevel , 'prospect_contact_level_id' , 1 );
2020-08-02 22:30:23 +02:00
} else {
print $object -> getLibProspLevel ();
}
print " </td> " ;
print '</tr>' ;
// Status of prospection
$object -> loadCacheOfProspStatus ();
2020-09-08 21:27:28 +02:00
print '<tr><td>' . $langs -> trans ( " StatusProsp " ) . '</td><td>' . $object -> getLibProspCommStatut ( 4 , $object -> cacheprospectstatus [ $object -> stcomm_id ][ 'label' ]);
2020-08-02 22:30:23 +02:00
print ' ' ;
print '<div class="floatright">' ;
foreach ( $object -> cacheprospectstatus as $key => $val ) {
$titlealt = 'default' ;
2021-02-23 21:16:15 +01:00
if ( ! empty ( $val [ 'code' ]) && ! in_array ( $val [ 'code' ], array ( 'ST_NO' , 'ST_NEVER' , 'ST_TODO' , 'ST_PEND' , 'ST_DONE' ))) {
$titlealt = $val [ 'label' ];
}
if ( $object -> stcomm_id != $val [ 'id' ]) {
2021-09-19 18:03:38 +02:00
print '<a class="pictosubstatus" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&stcomm=' . urlencode ( $val [ 'code' ]) . '&action=setstcomm&token=' . newToken () . '">' . img_action ( $titlealt , $val [ 'code' ], $val [ 'picto' ]) . '</a>' ;
2021-02-23 21:16:15 +01:00
}
2020-08-02 22:30:23 +02:00
}
print '</div></td></tr>' ;
print " </table> " ;
print '</div>' ;
2020-04-27 17:35:14 +02:00
}
}
2021-10-23 17:18:35 +02:00
print '<div class="fichehalfright">' ;
2017-06-07 16:44:04 +02:00
2020-09-07 10:18:17 +02:00
print '<div class="underbanner clearboth"></div>' ;
2021-10-23 17:18:35 +02:00
print '<table class="border tableforfield centpercent">' ;
2017-06-07 16:44:04 +02:00
2015-06-11 14:50:11 +02:00
// Categories
2019-11-13 19:35:02 +01:00
if ( ! empty ( $conf -> categorie -> enabled ) && ! empty ( $user -> rights -> categorie -> lire )) {
print '<tr><td class="titlefield">' . $langs -> trans ( " Categories " ) . '</td>' ;
2015-06-11 14:50:11 +02:00
print '<td colspan="3">' ;
2019-11-14 08:15:39 +01:00
print $form -> showCategories ( $object -> id , Categorie :: TYPE_CONTACT , 1 );
2015-06-11 14:50:11 +02:00
print '</td></tr>' ;
}
2020-09-07 10:18:17 +02:00
if ( ! empty ( $object -> socid )) {
print '<tr><td class="titlefield">' . $langs -> trans ( " ContactByDefaultFor " ) . '</td>' ;
print '<td colspan="3">' ;
2021-01-06 11:07:25 +01:00
print $formcompany -> showRoles ( " roles " , $object , 'view' , $object -> roles );
2020-09-07 10:18:17 +02:00
print '</td></tr>' ;
}
// Other attributes
$cols = 3 ;
$parameters = array ( 'socid' => $socid );
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
$object -> load_ref_elements ();
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> propal -> enabled )) {
2020-09-07 10:18:17 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " ContactForProposals " ) . '</td><td colspan="3">' ;
print $object -> ref_propal ? $object -> ref_propal : $langs -> trans ( " NoContactForAnyProposal " );
print '</td></tr>' ;
}
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> commande -> enabled ) || ! empty ( $conf -> expedition -> enabled )) {
2020-09-07 10:18:17 +02:00
print '<tr><td>' ;
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> expedition -> enabled )) {
print $langs -> trans ( " ContactForOrdersOrShipments " );
} else {
print $langs -> trans ( " ContactForOrders " );
}
2020-09-07 10:18:17 +02:00
print '</td><td colspan="3">' ;
$none = $langs -> trans ( " NoContactForAnyOrder " );
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> expedition -> enabled )) {
$none = $langs -> trans ( " NoContactForAnyOrderOrShipments " );
}
2020-09-07 10:18:17 +02:00
print $object -> ref_commande ? $object -> ref_commande : $none ;
print '</td></tr>' ;
}
2021-02-23 21:16:15 +01:00
if ( ! empty ( $conf -> contrat -> enabled )) {
2020-09-07 10:18:17 +02:00
print '<tr><td>' . $langs -> trans ( " ContactForContracts " ) . '</td><td colspan="3">' ;
print $object -> ref_contrat ? $object -> ref_contrat : $langs -> trans ( " NoContactForAnyContract " );
print '</td></tr>' ;
}
2022-06-11 09:46:28 +02:00
if ( isModEnabled ( 'facture' )) {
2020-09-07 10:18:17 +02:00
print '<tr><td>' . $langs -> trans ( " ContactForInvoices " ) . '</td><td colspan="3">' ;
print $object -> ref_facturation ? $object -> ref_facturation : $langs -> trans ( " NoContactForAnyInvoice " );
print '</td></tr>' ;
}
print '<tr><td>' . $langs -> trans ( " DolibarrLogin " ) . '</td><td colspan="3">' ;
2021-02-23 21:16:15 +01:00
if ( $object -> user_id ) {
2020-09-07 10:18:17 +02:00
$dolibarr_user = new User ( $db );
$result = $dolibarr_user -> fetch ( $object -> user_id );
2022-07-18 11:51:28 +02:00
print $dolibarr_user -> getLoginUrl ( - 1 );
2021-02-23 21:16:15 +01:00
} else {
2022-07-18 11:51:28 +02:00
//print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
if ( ! $object -> user_id && $user -> rights -> user -> user -> creer ) {
2022-07-29 10:41:09 +02:00
print '<a class="aaa" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=create_user&token=' . newToken () . '">' . img_picto ( $langs -> trans ( " CreateDolibarrLogin " ), 'add' , 'class="pictofixedwidth"' ) . $langs -> trans ( " CreateDolibarrLogin " ) . '</a>' ;
2022-07-18 11:51:28 +02:00
}
2021-02-23 21:16:15 +01:00
}
2020-09-07 10:18:17 +02:00
print '</td></tr>' ;
print " </table> " ;
2017-06-07 16:44:04 +02:00
2021-10-23 17:18:35 +02:00
print '</div></div>' ;
2020-09-07 10:18:17 +02:00
print '<div style="clear:both"></div>' ;
2017-06-07 16:44:04 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2011-03-26 19:34:41 +01:00
2021-03-16 04:22:55 +01:00
/*
* Action bar
*/
2020-09-07 10:18:17 +02:00
print '<div class="tabsAction">' ;
2011-03-26 19:34:41 +01:00
2019-11-13 19:35:02 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'addMoreActionsButtons' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2021-02-23 21:16:15 +01:00
if ( empty ( $reshook ) && $action != 'presend' ) {
2020-04-10 01:37:04 +02:00
if ( empty ( $user -> socid )) {
2021-02-23 21:16:15 +01:00
if ( ! empty ( $object -> email )) {
2020-04-10 01:37:04 +02:00
$langs -> load ( " mails " );
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=presend&mode=init#formmailbeforetitle">' . $langs -> trans ( 'SendMail' ) . '</a></div>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 01:37:04 +02:00
$langs -> load ( " mails " );
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . dol_escape_htmltag ( $langs -> trans ( " NoEMail " )) . '">' . $langs -> trans ( 'SendMail' ) . '</a></div>' ;
}
2018-11-06 16:40:39 +01:00
}
2021-02-23 21:16:15 +01:00
if ( $user -> rights -> societe -> contact -> creer ) {
2021-09-27 12:24:01 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=edit&token=' . newToken () . '">' . $langs -> trans ( 'Modify' ) . '</a>' ;
2020-09-07 10:18:17 +02:00
}
// Activer
2021-02-23 21:16:15 +01:00
if ( $object -> statut == 0 && $user -> rights -> societe -> contact -> creer ) {
2021-03-19 12:44:59 +01:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=enable&token=' . newToken () . '">' . $langs -> trans ( " Reactivate " ) . '</a>' ;
2020-09-07 10:18:17 +02:00
}
// Desactiver
2021-02-23 21:16:15 +01:00
if ( $object -> statut == 1 && $user -> rights -> societe -> contact -> creer ) {
2021-03-19 12:44:59 +01:00
print '<a class="butActionDelete" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=disable&id=' . $object -> id . '&token=' . newToken () . '">' . $langs -> trans ( " DisableUser " ) . '</a>' ;
2020-09-07 10:18:17 +02:00
}
// Delete
2021-02-23 21:16:15 +01:00
if ( $user -> rights -> societe -> contact -> supprimer ) {
2020-10-01 10:50:54 +02:00
print '<a class="butActionDelete" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=delete&token=' . newToken () . '' . ( $backtopage ? '&backtopage=' . urlencode ( $backtopage ) : '' ) . '">' . $langs -> trans ( 'Delete' ) . '</a>' ;
2020-09-07 10:18:17 +02:00
}
}
print " </div> " ;
//Select mail models is same action as presend
if ( GETPOST ( 'modelselected' )) {
$action = 'presend' ;
}
2021-02-23 21:16:15 +01:00
if ( $action != 'presend' ) {
2020-09-07 10:18:17 +02:00
print '<div class="fichecenter"><div class="fichehalfleft">' ;
2021-10-23 17:18:35 +02:00
print '</div><div class="fichehalfright">' ;
2020-09-07 10:18:17 +02:00
$MAXEVENT = 10 ;
2022-05-18 23:11:59 +02:00
$morehtmlright = dolGetButtonTitle ( $langs -> trans ( 'SeeAll' ), '' , 'fa fa-bars imgforviewmode' , DOL_URL_ROOT . '/contact/agenda.php?id=' . $object -> id );
2020-09-07 10:18:17 +02:00
// List of actions on element
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php' ;
$formactions = new FormActions ( $db );
$somethingshown = $formactions -> showactions ( $object , 'contact' , $object -> socid , 1 , '' , $MAXEVENT , '' , $morehtmlright ); // Show all action for thirdparty
2021-10-23 17:18:35 +02:00
print '</div></div>' ;
2020-09-07 10:18:17 +02:00
}
// Presend form
$modelmail = 'contact' ;
$defaulttopic = 'Information' ;
2021-03-18 22:44:58 +01:00
$diroutput = $conf -> societe -> dir_output . '/contact/' ;
2020-11-08 14:39:20 +01:00
$trackid = 'ctc' . $object -> id ;
2020-09-07 10:18:17 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php' ;
}
2006-02-25 00:16:35 +01:00
}
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-02-13 01:43:35 +01:00
$db -> close ();