actions_setnotes.inc.php 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /**
  19. * \file htdocs/core/actions_setnotes.inc.php
  20. * \brief Code for actions on setting notes of object page
  21. */
  22. // $action must be defined
  23. // $permissionnote must be defined to permission to edit object
  24. // $object must be defined (object is loaded in this file with fetch)
  25. // $id must be defined (object is loaded in this file with fetch)
  26. // Set public note
  27. if ($action == 'setnote_public' && !empty($permissionnote) && !GETPOST('cancel', 'alpha')) {
  28. if (empty($action) || !is_object($object) || empty($id)) {
  29. dol_print_error('', 'Include of actions_setnotes.inc.php was done but required variable was not set before');
  30. }
  31. if (empty($object->id)) {
  32. $object->fetch($id); // Fetch may not be already done
  33. }
  34. $result_update = $object->update_note(dol_html_entity_decode(GETPOST('note_public', 'restricthtml'), ENT_QUOTES | ENT_HTML5, 'UTF-8', 1), '_public');
  35. if ($result_update < 0) {
  36. setEventMessages($object->error, $object->errors, 'errors');
  37. } elseif (in_array($object->table_element, array('supplier_proposal', 'propal', 'commande_fournisseur', 'commande', 'facture_fourn', 'facture'))) {
  38. // Define output language
  39. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  40. $outputlangs = $langs;
  41. $newlang = '';
  42. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  43. $newlang = GETPOST('lang_id', 'aZ09');
  44. }
  45. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
  46. $newlang = $object->thirdparty->default_lang;
  47. }
  48. if (!empty($newlang)) {
  49. $outputlangs = new Translate("", $conf);
  50. $outputlangs->setDefaultLang($newlang);
  51. }
  52. $model = $object->model_pdf;
  53. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  54. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  55. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  56. //see #21072: Update a public note with a "document model not found" is not really a problem : the PDF is not created/updated
  57. //but the note is saved, so just add a notification will be enought
  58. $resultGenDoc = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  59. if ($resultGenDoc < 0) {
  60. setEventMessages($object->error, $object->errors, 'warnings');
  61. }
  62. if ($result < 0) {
  63. dol_print_error($db, $result);
  64. }
  65. }
  66. }
  67. } elseif ($action == 'setnote_private' && !empty($permissionnote) && !GETPOST('cancel', 'alpha')) { // Set public note
  68. if (empty($user->socid)) {
  69. // Private notes (always hidden to external users)
  70. if (empty($action) || !is_object($object) || empty($id)) {
  71. dol_print_error('', 'Include of actions_setnotes.inc.php was done but required variable was not set before');
  72. }
  73. if (empty($object->id)) {
  74. $object->fetch($id); // Fetch may not be already done
  75. }
  76. $result = $object->update_note(dol_html_entity_decode(GETPOST('note_private', 'restricthtml'), ENT_QUOTES | ENT_HTML5), '_private');
  77. if ($result < 0) {
  78. setEventMessages($object->error, $object->errors, 'errors');
  79. }
  80. }
  81. }