actions_setnotes.inc.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  43. $newlang = GETPOST('lang_id', 'aZ09');
  44. }
  45. if ($conf->global->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. $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  57. if ($result < 0) {
  58. dol_print_error($db, $result);
  59. }
  60. }
  61. }
  62. } elseif ($action == 'setnote_private' && !empty($permissionnote) && !GETPOST('cancel', 'alpha')) { // Set public note
  63. if (empty($user->socid)) {
  64. // Private notes (always hidden to external users)
  65. if (empty($action) || !is_object($object) || empty($id)) {
  66. dol_print_error('', 'Include of actions_setnotes.inc.php was done but required variable was not set before');
  67. }
  68. if (empty($object->id)) {
  69. $object->fetch($id); // Fetch may not be already done
  70. }
  71. $result = $object->update_note(dol_html_entity_decode(GETPOST('note_private', 'restricthtml'), ENT_QUOTES | ENT_HTML5), '_private');
  72. if ($result < 0) {
  73. setEventMessages($object->error, $object->errors, 'errors');
  74. }
  75. }
  76. }