dolibarr  20.0.0-alpha
actions_setnotes.inc.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2014 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  * or see https://www.gnu.org/
17  */
18 
25 // $action must be defined
26 // $permissionnote must be defined to permission to edit object
27 // $object must be defined (object is loaded in this file with fetch)
28 // $id must be defined (object is loaded in this file with fetch)
29 
30 // Set public note
31 if ($action == 'setnote_public' && !empty($permissionnote) && !GETPOST('cancel', 'alpha')) {
32  if (empty($action) || !is_object($object) || empty($id)) {
33  dol_print_error(null, 'Include of actions_setnotes.inc.php was done but required variable was not set before');
34  }
35  if (empty($object->id)) {
36  $object->fetch($id); // Fetch may not be already done
37  }
38 
39  $result_update = $object->update_note(dol_html_entity_decode(GETPOST('note_public', 'restricthtml'), ENT_QUOTES | ENT_HTML5, 'UTF-8', 1), '_public');
40 
41  if ($result_update < 0) {
42  setEventMessages($object->error, $object->errors, 'errors');
43  } elseif (in_array($object->table_element, array('supplier_proposal', 'propal', 'commande_fournisseur', 'commande', 'facture_fourn', 'facture'))) {
44  // Define output language
45  if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
46  $outputlangs = $langs;
47  $newlang = '';
48  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
49  $newlang = GETPOST('lang_id', 'aZ09');
50  }
51  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
52  if (!is_object($object->thirdparty)) {
53  $object->fetch_thirdparty();
54  }
55  $newlang = $object->thirdparty->default_lang;
56  }
57  if (!empty($newlang)) {
58  $outputlangs = new Translate("", $conf);
59  $outputlangs->setDefaultLang($newlang);
60  }
61  $model = $object->model_pdf;
62  $hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
63  $hidedesc = (GETPOSTINT('hidedesc') ? GETPOSTINT('hidedesc') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));
64  $hideref = (GETPOSTINT('hideref') ? GETPOSTINT('hideref') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));
65 
66  //see #21072: Update a public note with a "document model not found" is not really a problem : the PDF is not created/updated
67  //but the note is saved, so just add a notification will be enough
68  $resultGenDoc = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
69  if ($resultGenDoc < 0) {
70  setEventMessages($object->error, $object->errors, 'warnings');
71  }
72 
73  if ($result < 0) {
74  dol_print_error($db, $result);
75  }
76  }
77  }
78 } elseif ($action == 'setnote_private' && !empty($permissionnote) && !GETPOST('cancel', 'alpha')) { // Set public note
79  if (empty($user->socid)) {
80  // Private notes (always hidden to external users)
81  if (empty($action) || !is_object($object) || empty($id)) {
82  dol_print_error(null, 'Include of actions_setnotes.inc.php was done but required variable was not set before');
83  }
84  if (empty($object->id)) {
85  $object->fetch($id); // Fetch may not be already done
86  }
87  $result = $object->update_note(dol_html_entity_decode(GETPOST('note_private', 'restricthtml'), ENT_QUOTES | ENT_HTML5, 'UTF-8', 1), '_private');
88  if ($result < 0) {
89  setEventMessages($object->error, $object->errors, 'errors');
90  }
91  }
92 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
Class to manage translations.
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 dolibarr global constant string value.