actions_setnotes.inc.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <http://www.gnu.org/licenses/>.
  16. * or see http://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),'_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. }
  55. // Set public note
  56. else if ($action == 'setnote_private' && ! empty($permissionnote) && ! GETPOST('cancel','alpha'))
  57. {
  58. 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');
  59. if (empty($object->id)) $object->fetch($id); // Fetch may not be already done
  60. $result=$object->update_note(dol_html_entity_decode(GETPOST('note_private', 'none'), ENT_QUOTES),'_private');
  61. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  62. }