2014-01-11 13:33:30 +01:00
< ? php
/* Copyright ( C ) 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
*
* 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 />.
* or see https :// www . gnu . org /
2014-01-11 13:33:30 +01:00
*/
/**
* \file htdocs / core / actions_setnotes . inc . php
* \brief Code for actions on setting notes of object page
*/
// $action must be defined
2015-02-28 03:11:15 +01:00
// $permissionnote must be defined to permission to edit object
2014-01-11 13:33:30 +01:00
// $object must be defined (object is loaded in this file with fetch)
// $id must be defined (object is loaded in this file with fetch)
// Set public note
2020-04-10 10:59:32 +02:00
if ( $action == 'setnote_public' && ! empty ( $permissionnote ) && ! GETPOST ( 'cancel' , 'alpha' ))
2014-01-11 13:33:30 +01:00
{
2020-04-10 10:59:32 +02:00
if ( empty ( $action ) || ! is_object ( $object ) || empty ( $id )) dol_print_error ( '' , 'Include of actions_setnotes.inc.php was done but required variable was not set before' );
if ( empty ( $object -> id )) $object -> fetch ( $id ); // Fetch may not be already done
2019-01-27 23:23:38 +01:00
2020-10-15 19:36:08 +02:00
$result_update = $object -> update_note ( dol_html_entity_decode ( GETPOST ( 'note_public' , 'restricthtml' ), ENT_QUOTES | ENT_HTML5 , 'UTF-8' , 1 ), '_public' );
2018-08-13 23:52:33 +02:00
2018-08-13 23:53:48 +02:00
if ( $result_update < 0 ) setEventMessages ( $object -> error , $object -> errors , 'errors' );
elseif ( in_array ( $object -> table_element , array ( 'supplier_proposal' , 'propal' , 'commande_fournisseur' , 'commande' , 'facture_fourn' , 'facture' )))
2018-08-13 23:52:33 +02:00
{
2018-07-27 14:47:22 +02:00
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
2019-01-27 11:55:16 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
2018-07-27 14:47:22 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
2020-04-10 10:59:32 +02:00
if ( ! empty ( $newlang )) {
2018-07-27 14:47:22 +02:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2020-09-10 01:49:09 +02:00
$model = $object -> model_pdf ;
2020-04-10 10:59:32 +02:00
$hidedetails = ( GETPOST ( 'hidedetails' , 'int' ) ? GETPOST ( 'hidedetails' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS ) ? 1 : 0 ));
$hidedesc = ( GETPOST ( 'hidedesc' , 'int' ) ? GETPOST ( 'hidedesc' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DESC ) ? 1 : 0 ));
$hideref = ( GETPOST ( 'hideref' , 'int' ) ? GETPOST ( 'hideref' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_REF ) ? 1 : 0 ));
2018-09-02 15:59:09 +02:00
2020-04-10 10:59:32 +02:00
$result = $object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
2019-01-27 23:23:38 +01:00
2019-01-27 11:55:16 +01:00
if ( $result < 0 ) dol_print_error ( $db , $result );
2018-07-27 14:47:22 +02:00
}
}
2020-04-10 10:59:32 +02:00
} elseif ( $action == 'setnote_private' && ! empty ( $permissionnote ) && ! GETPOST ( 'cancel' , 'alpha' )) {
2020-03-23 15:54:02 +01:00
// Set public note
2020-04-10 10:59:32 +02:00
if ( empty ( $action ) || ! is_object ( $object ) || empty ( $id )) dol_print_error ( '' , 'Include of actions_setnotes.inc.php was done but required variable was not set before' );
if ( empty ( $object -> id )) $object -> fetch ( $id ); // Fetch may not be already done
2020-10-15 19:36:08 +02:00
$result = $object -> update_note ( dol_html_entity_decode ( GETPOST ( 'note_private' , 'restricthtml' ), ENT_QUOTES | ENT_HTML5 ), '_private' );
2015-11-19 13:59:58 +01:00
if ( $result < 0 ) setEventMessages ( $object -> error , $object -> errors , 'errors' );
2014-01-11 13:33:30 +01:00
}