2016-12-19 16:22:41 +01:00
< ? php
/* Copyright ( C ) 2004 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2018-11-25 11:57:19 +01:00
* Copyright ( C ) 2004 - 2018 Laurent Destailleur < eldy @ users . sourceforge . net >
2016-12-19 16:22:41 +01:00
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2016-12-19 16:22:41 +01: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 >
2016-12-19 16:22:41 +01:00
* Copyright ( C ) 2014 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
*
* 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
* the Free Software Foundation ; either version 3 of the License , or
* ( 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 />.
2016-12-19 16:22:41 +01:00
*/
/**
* \file htdocs / contact / card . php
* \ingroup societe
* \brief Card of a contact
*/
require '../main.inc.php' ;
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' ;
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' ;
2019-11-13 19:35:39 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php' ;
2016-12-19 16:22:41 +01:00
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2018-05-26 20:32:23 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'companies' , 'users' , 'other' , 'commercial' ));
2016-12-19 16:22:41 +01:00
2019-11-13 19:35:39 +01:00
$mesg = '' ; $error = 0 ; $errors = array ();
2016-12-19 16:22:41 +01:00
2019-01-27 11:55:16 +01:00
$action = ( GETPOST ( 'action' , 'alpha' ) ? GETPOST ( 'action' , 'alpha' ) : 'view' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
$backtopage = GETPOST ( 'backtopage' , 'alpha' );
2019-11-13 19:35:39 +01:00
$id = GETPOST ( 'id' , 'int' );
2019-01-27 11:55:16 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2016-12-19 16:22:41 +01:00
$object = new Contact ( $db );
$extrafields = new ExtraFields ( $db );
// fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2016-12-19 16:22:41 +01:00
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
$object -> getCanvas ( $id );
2019-11-13 19:35:39 +01:00
$objcanvas = null ;
$canvas = ( ! empty ( $object -> canvas ) ? $object -> canvas : GETPOST ( " canvas " ));
2021-02-23 21:16:15 +01:00
if ( ! empty ( $canvas )) {
2020-10-31 14:32:18 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/canvas.class.php' ;
$objcanvas = new Canvas ( $db , $action );
$objcanvas -> getCanvas ( 'contact' , 'contactcard' , $canvas );
2016-12-19 16:22:41 +01:00
}
2021-02-23 21:16:15 +01:00
if ( GETPOST ( 'actioncode' , 'array' )) {
2020-10-31 14:32:18 +01:00
$actioncode = GETPOST ( 'actioncode' , 'array' , 3 );
2021-02-23 21:16:15 +01:00
if ( ! count ( $actioncode )) {
$actioncode = '0' ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
$actioncode = GETPOST ( " actioncode " , " alpha " , 3 ) ? GETPOST ( " actioncode " , " alpha " , 3 ) : ( GETPOST ( " actioncode " ) == '0' ? '0' : ( empty ( $conf -> global -> AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT ) ? '' : $conf -> global -> AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT ));
2016-12-19 16:22:41 +01:00
}
2020-04-10 10:59:32 +02:00
$search_agenda_label = GETPOST ( 'search_agenda_label' );
2016-12-19 16:22:41 +01:00
// Security check
2021-02-23 21:16:15 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2020-09-18 06:02:52 +02:00
$result = restrictedArea ( $user , 'contact' , $id , 'socpeople&societe' , '' , '' , 'rowid' , 0 ); // If we create a contact with no company (shared contacts), no check on write permission
2016-12-19 16:22:41 +01:00
2020-04-10 10:59:32 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2022-01-13 11:09:37 +01:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-23 21:16:15 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2016-12-19 16:22:41 +01:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-23 21:16:15 +01:00
if ( ! $sortfield ) {
$sortfield = 'a.datep, a.id' ;
}
if ( ! $sortorder ) {
$sortorder = 'DESC' ;
}
2016-12-19 16:22:41 +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
2019-11-13 19:35:39 +01:00
$hookmanager -> initHooks ( array ( 'contactagenda' , 'globalcard' ));
2016-12-19 16:22:41 +01:00
/*
* Actions
*/
2019-11-13 19:35:39 +01: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' );
}
2016-12-19 16:22:41 +01:00
2021-02-23 21:16:15 +01:00
if ( empty ( $reshook )) {
2020-10-31 14:32:18 +01:00
// Cancel
2021-02-23 21:16:15 +01:00
if ( GETPOST ( 'cancel' , 'alpha' ) && ! empty ( $backtopage )) {
2020-10-31 14:32:18 +01:00
header ( " Location: " . $backtopage );
exit ;
}
// Purge search criteria
2021-02-23 21:16:15 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // All test are required to be compatible with all browsers
2020-10-31 14:32:18 +01:00
$actioncode = '' ;
$search_agenda_label = '' ;
}
2016-12-19 16:22:41 +01:00
}
/*
* View
*/
2018-11-25 11:57:19 +01:00
$form = new Form ( $db );
2016-12-19 16:22:41 +01:00
2019-11-13 19:35:39 +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 ;
}
2021-06-14 11:02:43 +02:00
$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas|DE:Modul_Partner' ;
2016-12-19 16:22:41 +01:00
llxHeader ( '' , $title , $help_url );
2021-02-23 21:16:15 +01:00
if ( $socid > 0 ) {
2020-10-31 14:32:18 +01:00
$objsoc = new Societe ( $db );
$objsoc -> fetch ( $socid );
2016-12-19 16:22:41 +01:00
}
2021-02-23 21:16:15 +01:00
if ( is_object ( $objcanvas ) && $objcanvas -> displayCanvasExists ( $action )) {
2020-10-31 14:32:18 +01: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-10-31 14:32:18 +01:00
$objcanvas -> display_canvas ( $action ); // Show template
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01: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-10-31 14:32:18 +01: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-10-31 14:32:18 +01:00
$head = array ();
2021-02-23 21:16:15 +01:00
if ( $id > 0 ) {
2020-10-31 14:32:18 +01:00
// Si edition contact deja existant
$object = new Contact ( $db );
$res = $object -> fetch ( $id , $user );
2021-02-23 21:16:15 +01:00
if ( $res < 0 ) {
dol_print_error ( $db , $object -> error ); exit ;
}
2020-10-31 14:32:18 +01:00
$res = $object -> fetch_optionals ();
2021-02-23 21:16:15 +01:00
if ( $res < 0 ) {
dol_print_error ( $db , $object -> error ); exit ;
}
2020-10-31 14:32:18 +01:00
// 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 ( ! empty ( $id ) && $action != 'edit' && $action != 'create' ) {
2020-10-31 14:32:18 +01:00
$objsoc = new Societe ( $db );
/*
2021-02-23 21:16:15 +01:00
* Fiche en mode visualisation
*/
2016-12-19 16:22:41 +01:00
2020-10-31 14:32:18 +01:00
dol_htmloutput_errors ( $error , $errors );
2016-12-19 16:22:41 +01:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_head ( $head , 'agenda' , $title , - 1 , 'contact' );
2016-12-19 16:22:41 +01:00
2020-10-31 14:32:18 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/contact/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-08-25 13:50:45 +02:00
2022-01-10 00:33:54 +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-10-31 14:32:18 +01:00
$objsoc = new Societe ( $db );
$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 );
} else {
$morehtmlref .= $langs -> trans ( " ContactNotLinkedToCompany " );
}
2020-10-31 14:32:18 +01:00
}
$morehtmlref .= '</div>' ;
2017-08-25 13:50:45 +02:00
2020-10-31 14:32:18 +01:00
dol_banner_tab ( $object , 'id' , $linkback , 1 , 'rowid' , 'ref' , $morehtmlref );
2017-08-25 13:50:45 +02:00
2020-10-31 14:32:18 +01:00
print '<div class="fichecenter">' ;
2017-08-25 13:50:45 +02:00
2020-10-31 14:32:18 +01:00
print '<div class="underbanner clearboth"></div>' ;
2017-08-25 13:50:45 +02:00
2020-10-31 14:32:18 +01:00
$object -> info ( $id );
dol_print_object_info ( $object , 1 );
2017-08-25 13:50:45 +02:00
2020-10-31 14:32:18 +01:00
print '</div>' ;
2017-08-25 13:50:45 +02:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_end ();
2016-12-19 16:22:41 +01:00
2017-08-25 13:50:45 +02:00
2020-10-31 14:32:18 +01:00
// Actions buttons
2017-08-25 13:50:45 +02:00
2020-10-31 14:32:18 +01:00
$objcon = $object ;
$object -> fetch_thirdparty ();
$objthirdparty = $object -> thirdparty ;
2017-08-25 13:50:45 +02:00
2020-10-31 14:32:18 +01:00
$out = '' ;
$newcardbutton = '' ;
2022-06-09 22:16:48 +02:00
if ( isModEnabled ( 'agenda' )) {
2022-05-24 22:42:32 +02:00
$permok = $user -> rights -> agenda -> myactions -> create ;
if (( ! empty ( $objthirdparty -> id ) || ! empty ( $objcon -> id )) && $permok ) {
if ( is_object ( $objthirdparty ) && get_class ( $objthirdparty ) == 'Societe' ) {
$out .= '&originid=' . $objthirdparty -> id . ( $objthirdparty -> id > 0 ? '&socid=' . $objthirdparty -> id : '' );
}
$out .= ( ! empty ( $objcon -> id ) ? '&contactid=' . $objcon -> id : '' ) . '&origin=contact&originid=' . $object -> id . '&percentage=-1&backtopage=' . urlencode ( $_SERVER [ 'PHP_SELF' ] . ( $objcon -> id > 0 ? '?id=' . $objcon -> id : '' ));
$out .= '&datep=' . urlencode ( dol_print_date ( dol_now (), 'dayhourlog' ));
}
2021-02-23 21:16:15 +01:00
if ( ! empty ( $user -> rights -> agenda -> myactions -> create ) || ! empty ( $user -> rights -> agenda -> allactions -> create )) {
2020-10-31 14:32:18 +01:00
$newcardbutton .= dolGetButtonTitle ( $langs -> trans ( 'AddAction' ), '' , 'fa fa-plus-circle' , DOL_URL_ROOT . '/comm/action/card.php?action=create' . $out );
}
}
2022-06-09 22:16:48 +02:00
if ( isModEnabled ( 'agenda' ) && ( ! empty ( $user -> rights -> agenda -> myactions -> read ) || ! empty ( $user -> rights -> agenda -> allactions -> read ))) {
2021-02-23 21:16:15 +01:00
print '<br>' ;
2020-10-31 14:32:18 +01:00
$param = '&id=' . $id ;
2021-02-23 21:16:15 +01:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) {
$param .= '&contextpage=' . $contextpage ;
}
if ( $limit > 0 && $limit != $conf -> liste_limit ) {
$param .= '&limit=' . $limit ;
}
2020-10-31 14:32:18 +01:00
print load_fiche_titre ( $langs -> trans ( " ActionsOnContact " ), $newcardbutton , '' );
//print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $morehtmlcenter, 0, -1, '', '', '', '', 0, 1, 1);
// List of all actions
$filters = array ();
$filters [ 'search_agenda_label' ] = $search_agenda_label ;
show_actions_done ( $conf , $langs , $db , $objthirdparty , $object , 0 , $actioncode , '' , $filters , $sortfield , $sortorder );
}
}
2016-12-19 16:22:41 +01:00
}
llxFooter ();
$db -> close ();