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 " ));
if ( ! empty ( $canvas ))
2016-12-19 16:22:41 +01:00
{
require_once DOL_DOCUMENT_ROOT . '/core/class/canvas.class.php' ;
$objcanvas = new Canvas ( $db , $action );
$objcanvas -> getCanvas ( 'contact' , 'contactcard' , $canvas );
}
2019-01-27 11:55:16 +01:00
if ( GETPOST ( 'actioncode' , 'array' ))
2016-12-19 16:22:41 +01:00
{
2020-04-10 10:59:32 +02:00
$actioncode = GETPOST ( 'actioncode' , 'array' , 3 );
if ( ! count ( $actioncode )) $actioncode = '0' ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02: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
2020-04-10 10:59:32 +02:00
if ( $user -> socid ) $socid = $user -> socid ;
2016-12-19 16:22:41 +01:00
$result = restrictedArea ( $user , 'contact' , $id , 'socpeople&societe' , '' , '' , 'rowid' , $objcanvas ); // If we create a contact with no company (shared contacts), no check on write permission
2020-04-10 10:59:32 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2019-01-27 11:55:16 +01:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2017-06-06 10:53:53 +02: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 ;
2019-11-13 19:35:39 +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
2016-12-19 16:22:41 +01:00
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
if ( empty ( $reshook ))
{
// Cancel
2019-11-13 19:35:39 +01:00
if ( GETPOST ( 'cancel' , 'alpha' ) && ! empty ( $backtopage ))
2016-12-19 16:22:41 +01:00
{
header ( " Location: " . $backtopage );
exit ;
}
// Purge search criteria
2019-01-27 11:55:16 +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
2016-12-19 16:22:41 +01:00
{
2019-11-13 19:35:39 +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 " ));
if ( ! empty ( $conf -> global -> MAIN_HTML_TITLE ) && preg_match ( '/contactnameonly/' , $conf -> global -> MAIN_HTML_TITLE ) && $object -> lastname ) $title = $object -> lastname ;
$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas' ;
2016-12-19 16:22:41 +01:00
llxHeader ( '' , $title , $help_url );
if ( $socid > 0 )
{
$objsoc = new Societe ( $db );
$objsoc -> fetch ( $socid );
}
if ( is_object ( $objcanvas ) && $objcanvas -> displayCanvasExists ( $action ))
{
// -----------------------------------------
// When used with CANVAS
// -----------------------------------------
if ( empty ( $object -> error ) && $id )
{
$object = new Contact ( $db );
2019-11-13 19:35:39 +01:00
$result = $object -> fetch ( $id );
2019-01-27 11:55:16 +01:00
if ( $result <= 0 ) dol_print_error ( '' , $object -> error );
2016-12-19 16:22:41 +01:00
}
2019-11-13 19:35:39 +01:00
$objcanvas -> assign_values ( $action , $object -> id , $object -> ref ); // Set value for templates
$objcanvas -> display_canvas ( $action ); // Show template
2020-05-21 15:05:19 +02:00
} else {
2016-12-19 16:22:41 +01:00
// -----------------------------------------
// When used in standard mode
// -----------------------------------------
// Confirm deleting contact
if ( $user -> rights -> societe -> contact -> supprimer )
{
if ( $action == 'delete' )
{
2019-11-13 19:35:39 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $id . ( $backtopage ? '&backtopage=' . $backtopage : '' ), $langs -> trans ( " DeleteContact " ), $langs -> trans ( " ConfirmDeleteContact " ), " confirm_delete " , '' , 0 , 1 );
2016-12-19 16:22:41 +01:00
}
}
/*
* Onglets
*/
2019-11-13 19:35:39 +01:00
$head = array ();
2016-12-19 16:22:41 +01:00
if ( $id > 0 )
{
// Si edition contact deja existant
$object = new Contact ( $db );
2019-11-13 19:35:39 +01:00
$res = $object -> fetch ( $id , $user );
2019-01-27 11:55:16 +01:00
if ( $res < 0 ) { dol_print_error ( $db , $object -> error ); exit ; }
2019-11-13 19:35:39 +01:00
$res = $object -> fetch_optionals ();
2019-01-27 11:55:16 +01:00
if ( $res < 0 ) { dol_print_error ( $db , $object -> error ); exit ; }
2016-12-19 16:22:41 +01:00
// Show tabs
$head = contact_prepare_head ( $object );
2019-11-13 19:35:39 +01:00
$title = ( ! empty ( $conf -> global -> SOCIETE_ADDRESSES_MANAGEMENT ) ? $langs -> trans ( " Contacts " ) : $langs -> trans ( " ContactsAddresses " ));
2016-12-19 16:22:41 +01:00
}
2019-11-13 19:35:39 +01:00
if ( ! empty ( $id ) && $action != 'edit' && $action != 'create' )
2016-12-19 16:22:41 +01:00
{
$objsoc = new Societe ( $db );
/*
* Fiche en mode visualisation
*/
2019-01-27 11:55:16 +01:00
dol_htmloutput_errors ( $error , $errors );
2016-12-19 16:22:41 +01:00
2017-05-23 01:32:19 +02:00
dol_fiche_head ( $head , 'agenda' , $title , - 1 , 'contact' );
2016-12-19 16:22:41 +01:00
2017-10-03 16:00:52 +02: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
2019-11-13 19:35:39 +01:00
$morehtmlref = '<div class="refidno">' ;
2016-12-19 16:35:40 +01:00
if ( empty ( $conf -> global -> SOCIETE_DISABLE_CONTACTS ))
{
2019-11-13 19:35:39 +01:00
$objsoc = new Societe ( $db );
2016-12-19 16:35:40 +01:00
$objsoc -> fetch ( $object -> socid );
// Thirdparty
2019-11-13 19:35:39 +01:00
$morehtmlref .= $langs -> trans ( 'ThirdParty' ) . ' : ' ;
if ( $objsoc -> id > 0 ) $morehtmlref .= $objsoc -> getNomUrl ( 1 );
else $morehtmlref .= $langs -> trans ( " ContactNotLinkedToCompany " );
2016-12-19 16:35:40 +01:00
}
2019-11-13 19:35:39 +01:00
$morehtmlref .= '</div>' ;
2017-08-25 13:50:45 +02:00
2016-12-19 16:35:40 +01:00
dol_banner_tab ( $object , 'id' , $linkback , 1 , 'rowid' , 'ref' , $morehtmlref );
2017-08-25 13:50:45 +02:00
2016-12-19 16:22:41 +01:00
print '<div class="fichecenter">' ;
2017-08-25 13:50:45 +02:00
2016-12-19 16:22:41 +01:00
print '<div class="underbanner clearboth"></div>' ;
2017-08-25 13:50:45 +02:00
2016-12-19 16:22:41 +01:00
$object -> info ( $id );
2019-05-19 09:15:10 +02:00
dol_print_object_info ( $object , 1 );
2017-08-25 13:50:45 +02:00
2016-12-19 16:22:41 +01:00
print '</div>' ;
2017-08-25 13:50:45 +02:00
2019-11-25 23:58:53 +01:00
dol_fiche_end ();
2016-12-19 16:22:41 +01:00
2017-08-25 13:50:45 +02:00
2016-12-19 16:22:41 +01:00
// Actions buttons
2017-08-25 13:50:45 +02:00
2019-11-13 19:35:39 +01:00
$objcon = $object ;
2016-12-19 16:22:41 +01:00
$object -> fetch_thirdparty ();
2019-11-13 19:35:39 +01:00
$objthirdparty = $object -> thirdparty ;
2017-08-25 13:50:45 +02:00
2019-11-13 19:35:39 +01:00
$out = '' ;
$permok = $user -> rights -> agenda -> myactions -> create ;
if (( ! empty ( $objthirdparty -> id ) || ! empty ( $objcon -> id )) && $permok )
2016-12-19 16:22:41 +01:00
{
//$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
2019-11-13 19:35:39 +01:00
if ( is_object ( $objthirdparty ) && get_class ( $objthirdparty ) == 'Societe' ) $out .= '&socid=' . $objthirdparty -> id ;
$out .= ( ! empty ( $objcon -> id ) ? '&contactid=' . $objcon -> id : '' ) . '&backtopage=1&percentage=-1' ;
2016-12-19 16:22:41 +01:00
//$out.=$langs->trans("AddAnAction").' ';
//$out.=img_picto($langs->trans("AddAnAction"),'filenew');
//$out.="</a>";
}
2017-08-25 13:50:45 +02:00
2017-10-04 12:58:13 +02:00
//print '<div class="tabsAction">';
//print '</div>';
2017-08-25 13:50:45 +02:00
2019-11-13 19:35:39 +01:00
$newcardbutton = '' ;
if ( ! empty ( $conf -> agenda -> enabled ))
2018-11-25 11:57:19 +01:00
{
2019-11-13 19:35:39 +01:00
if ( ! empty ( $user -> rights -> agenda -> myactions -> create ) || ! empty ( $user -> rights -> agenda -> allactions -> create ))
2018-11-25 11:57:19 +01:00
{
2019-11-13 19:35:39 +01:00
$newcardbutton .= dolGetButtonTitle ( $langs -> trans ( 'AddAction' ), '' , 'fa fa-plus-circle' , DOL_URL_ROOT . '/comm/action/card.php?action=create' . $out );
2018-11-25 11:57:19 +01:00
}
}
2017-08-25 13:50:45 +02:00
2019-11-13 19:35:39 +01:00
if ( ! empty ( $conf -> agenda -> enabled ) && ( ! empty ( $user -> rights -> agenda -> myactions -> read ) || ! empty ( $user -> rights -> agenda -> allactions -> read )))
2016-12-19 16:22:41 +01:00
{
2017-10-04 12:58:13 +02:00
print '<br>' ;
2019-11-13 19:35:39 +01:00
$param = '&id=' . $id ;
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) $param .= '&contextpage=' . $contextpage ;
if ( $limit > 0 && $limit != $conf -> liste_limit ) $param .= '&limit=' . $limit ;
2017-08-25 13:50:45 +02:00
2018-11-25 11:57:19 +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);
2017-08-25 13:50:45 +02:00
2016-12-19 16:22:41 +01:00
// List of all actions
2019-11-13 19:35:39 +01:00
$filters = array ();
$filters [ 'search_agenda_label' ] = $search_agenda_label ;
2017-08-25 13:50:45 +02:00
2019-01-27 11:55:16 +01:00
show_actions_done ( $conf , $langs , $db , $objthirdparty , $object , 0 , $actioncode , '' , $filters , $sortfield , $sortorder );
2016-12-19 16:22:41 +01:00
}
}
}
llxFooter ();
$db -> close ();