dolibarr 24.0.0-beta
actions_setnotes.inc.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2014 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 * or see https://www.gnu.org/
18 */
19
26// $action must be defined
27// $permissionnote must be defined to permission to edit object
28// $object must be defined (object is loaded in this file with fetch)
29// $id must be defined (object is loaded in this file with fetch)
41// Set public note
42if ($action == 'setnote_public' && !empty($permissionnote) && !GETPOST('cancel', 'alpha')) {
43 if (!is_object($object) || empty($id)) {
44 dol_print_error(null, 'Include of actions_setnotes.inc.php was done but required variable was not set before');
45 }
46 if (empty($object->id)) {
47 $object->fetch($id); // Fetch may not be already done
48 }
49
50 $notePublic = GETPOST('note_public', 'restricthtml');
51
52 $result_update = $object->update_note(dol_html_entity_decode($notePublic, ENT_QUOTES | ENT_HTML5, 'UTF-8', 1), '_public');
53
54 if ($result_update < 0) {
55 setEventMessages($object->error, $object->errors, 'errors');
56 } elseif (in_array($object->table_element, array('supplier_proposal', 'propal', 'commande_fournisseur', 'commande', 'facture_fourn', 'facture'))) {
57 // Define output language
58 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
59 $outputlangs = $langs;
60 $newlang = '';
61 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
62 $newlang = GETPOST('lang_id', 'aZ09');
63 }
64 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
65 if (!is_object($object->thirdparty)) {
66 $object->fetch_thirdparty();
67 }
68 $newlang = $object->thirdparty->default_lang;
69 }
70 if (!empty($newlang)) {
71 $outputlangs = new Translate("", $conf);
72 $outputlangs->setDefaultLang($newlang);
73 }
74 $model = $object->model_pdf;
75 $hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
76 $hidedesc = (GETPOSTINT('hidedesc') ? GETPOSTINT('hidedesc') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));
77 $hideref = (GETPOSTINT('hideref') ? GETPOSTINT('hideref') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));
78
79 //see #21072: Update a public note with a "document model not found" is not really a problem : the PDF is not created/updated
80 //but the note is saved, so just add a notification will be enough
81
82 $resultGenDoc = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
83
84 if ($resultGenDoc < 0) {
85 setEventMessages($object->error, $object->errors, 'warnings');
86 }
87 }
88 }
89} elseif ($action == 'setnote_private' && !empty($permissionnote) && !GETPOST('cancel', 'alpha')) { // Set public note
90 if (empty($user->socid)) {
91 // Private notes (always hidden to external users)
92 if (!is_object($object) || empty($id)) {
93 dol_print_error(null, 'Include of actions_setnotes.inc.php was done but required variable was not set before');
94 }
95 if (empty($object->id)) {
96 $object->fetch($id); // Fetch may not be already done
97 }
98
99 $notePrivate = GETPOST('note_private', 'restricthtml');
100
101 $result = $object->update_note(dol_html_entity_decode($notePrivate, ENT_QUOTES | ENT_HTML5, 'UTF-8', 1), '_private');
102 if ($result < 0) {
103 setEventMessages($object->error, $object->errors, 'errors');
104 }
105 }
106}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage translations.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.