2017-11-26 20:21:01 +01:00
< ? php
/* Copyright ( C ) 2001 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2005 Brice Davoleau < brice . davoleau @ gmail . com >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2017-11-26 20:21:01 +01:00
* Copyright ( C ) 2006 - 2015 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2007 Patrick Raguin < patrick . raguin @ gmail . com >
* Copyright ( C ) 2010 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2015 Marcos García < marcosgdf @ gmail . com >
*
* 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 />.
2017-11-26 20:21:01 +01:00
*/
/**
* \file htdocs / product / agenda . php
* \ingroup product
* \brief Page of product events
*/
require '../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php' ;
2018-05-26 23:52:52 +02:00
// Load translation files required by the page
2017-11-26 20:21:01 +01:00
$langs -> load ( " companies " );
2021-02-26 14:25:17 +01:00
if ( GETPOST ( 'actioncode' , 'array' )) {
2020-10-31 14:32:18 +01:00
$actioncode = GETPOST ( 'actioncode' , 'array' , 3 );
2021-02-26 14:25:17 +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 ));
2017-11-26 20:21:01 +01:00
}
2020-04-10 10:59:32 +02:00
$search_agenda_label = GETPOST ( 'search_agenda_label' );
2017-11-26 20:21:01 +01:00
// Security check
2019-01-27 11:55:16 +01:00
$id = GETPOST ( 'id' , 'int' );
2017-11-26 20:21:01 +01:00
$ref = GETPOST ( 'ref' , 'alpha' );
2021-02-26 14:25:17 +01:00
if ( $user -> socid ) {
$id = $user -> socid ;
}
2017-11-26 20:21:01 +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-26 14:25:17 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2017-11-26 20:21:01 +01:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-26 14:25:17 +01:00
if ( ! $sortfield ) {
$sortfield = 'a.datep,a.id' ;
}
if ( ! $sortorder ) {
$sortorder = 'DESC,DESC' ;
}
2017-11-26 20:21:01 +01:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager -> initHooks ( array ( 'agendathirdparty' ));
2021-05-21 15:54:11 +02:00
$object = new Product ( $db );
if ( $id > 0 || ! empty ( $ref )) {
$object -> fetch ( $id , $ref );
}
if ( $object -> id > 0 ) {
if ( $object -> type == $object :: TYPE_PRODUCT ) {
restrictedArea ( $user , 'produit' , $object -> id , 'product&product' , '' , '' );
}
if ( $object -> type == $object :: TYPE_SERVICE ) {
restrictedArea ( $user , 'service' , $object -> id , 'product&product' , '' , '' );
}
} else {
restrictedArea ( $user , 'produit|service' , 0 , 'product&product' , '' , '' );
}
2021-04-01 11:01:07 +02:00
2017-11-26 20:21:01 +01:00
/*
* Actions
*/
2019-11-13 19:37:08 +01:00
$parameters = array ( 'id' => $id );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 14:25:17 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2017-11-26 20:21:01 +01:00
2021-02-26 14:25:17 +01:00
if ( empty ( $reshook )) {
2020-10-31 14:32:18 +01:00
// Cancel
2021-02-26 14:25:17 +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-26 14:25:17 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // All tests are required to be compatible with all browsers
2020-10-31 14:32:18 +01:00
$actioncode = '' ;
$search_agenda_label = '' ;
}
2017-11-26 20:21:01 +01:00
}
/*
* View
*/
$contactstatic = new Contact ( $db );
$form = new Form ( $db );
2021-02-26 14:25:17 +01:00
if ( $id > 0 || $ref ) {
2017-11-26 20:21:01 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
$langs -> load ( " companies " );
$object = new Product ( $db );
2017-11-26 20:43:37 +01:00
$result = $object -> fetch ( $id , $ref );
2017-11-26 20:21:01 +01:00
2020-04-10 10:59:32 +02:00
$title = $langs -> trans ( " Agenda " );
2021-04-12 19:37:21 +02:00
2021-04-12 19:35:14 +02:00
$help_url = 'EN:Module_Agenda_En|FR:Module_Agenda' ;
2021-04-12 19:37:21 +02:00
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> MAIN_HTML_TITLE ) && preg_match ( '/productnameonly/' , $conf -> global -> MAIN_HTML_TITLE ) && $object -> name ) {
$title = $object -> name . " - " . $title ;
}
2021-04-12 19:35:14 +02:00
llxHeader ( '' , $title , $help_url );
2017-11-26 20:21:01 +01:00
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> notification -> enabled )) {
$langs -> load ( " mails " );
}
2017-11-26 20:21:01 +01:00
$type = $langs -> trans ( 'Product' );
2021-02-26 14:25:17 +01:00
if ( $object -> isService ()) {
$type = $langs -> trans ( 'Service' );
}
2017-11-26 20:21:01 +01:00
$head = product_prepare_head ( $object );
2020-04-10 10:59:32 +02:00
$titre = $langs -> trans ( " CardProduct " . $object -> type );
$picto = ( $object -> type == Product :: TYPE_SERVICE ? 'service' : 'product' );
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'agenda' , $titre , - 1 , $picto );
2017-11-26 20:21:01 +01:00
2020-10-31 14:32:18 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/product/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
$object -> next_prev_filter = " fk_product_type = " . $object -> type ;
2017-11-26 20:21:01 +01:00
2020-10-31 14:32:18 +01:00
$shownav = 1 ;
2021-02-26 14:25:17 +01:00
if ( $user -> socid && ! in_array ( 'product' , explode ( ',' , $conf -> global -> MAIN_MODULES_FOR_EXTERNAL ))) {
$shownav = 0 ;
}
2017-11-26 20:21:01 +01:00
2020-10-31 14:32:18 +01:00
dol_banner_tab ( $object , 'ref' , $linkback , $shownav , 'ref' );
2017-11-26 20:21:01 +01:00
2020-10-31 14:32:18 +01:00
print '<div class="fichecenter">' ;
2017-11-26 20:21:01 +01:00
2020-10-31 14:32:18 +01:00
print '<div class="underbanner clearboth"></div>' ;
2017-11-26 20:21:01 +01:00
2020-10-31 14:32:18 +01:00
$object -> info ( $object -> id );
2019-05-19 09:15:51 +02:00
dol_print_object_info ( $object , 1 );
2017-11-26 20:21:01 +01:00
print '</div>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2017-11-26 20:21:01 +01:00
// Actions buttons
2020-10-31 14:32:18 +01:00
$objproduct = $object ;
$objcon = new stdClass ();
$out = '' ;
2020-04-10 10:59:32 +02:00
$morehtmlcenter = '' ;
2022-06-09 22:16:48 +02:00
if ( isModEnabled ( 'agenda' )) {
2022-05-24 22:53:26 +02:00
$permok = $user -> rights -> agenda -> myactions -> create ;
if (( ! empty ( $objproduct -> id ) || ! empty ( $objcon -> id )) && $permok ) {
if ( get_class ( $objproduct ) == 'Product' ) {
$out .= '&prodid=' . $objproduct -> id . '&origin=product&originid=' . $id ;
}
$out .= ( ! empty ( $objcon -> id ) ? '&contactid=' . $objcon -> id : '' ) . '&backtopage=' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&percentage=-1' ;
}
2020-10-31 14:32:18 +01:00
$linktocreatetimeBtnStatus = ! empty ( $user -> rights -> agenda -> myactions -> create ) || ! empty ( $user -> rights -> agenda -> allactions -> create );
$morehtmlcenter = dolGetButtonTitle ( $langs -> trans ( 'AddAction' ), '' , 'fa fa-plus-circle' , DOL_URL_ROOT . '/comm/action/card.php?action=create' . $out , '' , $linktocreatetimeBtnStatus );
}
2017-11-26 20:21:01 +01:00
2022-06-09 22:16:48 +02:00
if ( isModEnabled ( 'agenda' ) && ( ! empty ( $user -> rights -> agenda -> myactions -> read ) || ! empty ( $user -> rights -> agenda -> allactions -> read ))) {
2020-10-31 14:32:18 +01:00
print '<br>' ;
2017-11-26 20:21:01 +01:00
2020-10-31 14:32:18 +01:00
$param = '&id=' . $id ;
2021-02-26 14:25:17 +01:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) {
$param .= '&contextpage=' . $contextpage ;
}
if ( $limit > 0 && $limit != $conf -> liste_limit ) {
$param .= '&limit=' . $limit ;
}
2017-11-26 20:21:01 +01:00
2017-12-01 15:58:35 +01:00
print_barre_liste ( $langs -> trans ( " ActionsOnProduct " ), 0 , $_SERVER [ " PHP_SELF " ], '' , $sortfield , $sortorder , '' , 0 , - 1 , '' , 0 , $morehtmlcenter , '' , 0 , 1 , 1 );
2017-11-26 20:21:01 +01:00
2020-10-31 14:32:18 +01:00
// List of all actions
2020-04-10 10:59:32 +02:00
$filters = array ();
2020-10-31 14:32:18 +01:00
$filters [ 'search_agenda_label' ] = $search_agenda_label ;
2017-11-26 20:21:01 +01:00
2020-10-31 14:32:18 +01:00
// TODO Replace this with same code than into list.php
show_actions_done ( $conf , $langs , $db , $object , null , 0 , $actioncode , '' , $filters , $sortfield , $sortorder );
}
2017-11-26 20:21:01 +01:00
}
2018-08-15 12:48:13 +02:00
// End of page
2017-11-26 20:21:01 +01:00
llxFooter ();
$db -> close ();