actions_setnotes.inc.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. {
  29. 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');
  30. if (empty($object->id)) $object->fetch($id); // Fetch may not be already done
  31. $result_update = $object->update_note(dol_html_entity_decode(GETPOST('note_public', 'none'), ENT_QUOTES, 'UTF-8', 1), '_public');
  32. if ($result_update < 0) setEventMessages($object->error, $object->errors, 'errors');
  33. elseif (in_array($object->table_element, array('supplier_proposal', 'propal', 'commande_fournisseur', 'commande', 'facture_fourn', 'facture')))
  34. {
  35. // Define output language
  36. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  37. {
  38. $outputlangs = $langs;
  39. $newlang = '';
  40. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
  41. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  42. if (!empty($newlang)) {
  43. $outputlangs = new Translate("", $conf);
  44. $outputlangs->setDefaultLang($newlang);
  45. }
  46. $model = $object->modelpdf;
  47. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  48. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  49. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  50. $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  51. if ($result < 0) dol_print_error($db, $result);
  52. }
  53. }
  54. } elseif ($action == 'setnote_private' && !empty($permissionnote) && !GETPOST('cancel', 'alpha')) {
  55. // Set public note
  56. 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');
  57. if (empty($object->id)) $object->fetch($id); // Fetch may not be already done
  58. $result = $object->update_note(dol_html_entity_decode(GETPOST('note_private', 'none'), ENT_QUOTES), '_private');
  59. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  60. }