loadinplace.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /* Copyright (C) 2011-2014 Regis Houssin <regis.houssin@inodbox.com>
  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. */
  17. /**
  18. * \file htdocs/core/ajax/loadinplace.php
  19. * \brief File to load field value
  20. */
  21. if (!defined('NOTOKENRENEWAL')) {
  22. define('NOTOKENRENEWAL', '1'); // Disables token renewal
  23. }
  24. if (!defined('NOREQUIREMENU')) {
  25. define('NOREQUIREMENU', '1');
  26. }
  27. if (!defined('NOREQUIREAJAX')) {
  28. define('NOREQUIREAJAX', '1');
  29. }
  30. if (!defined('NOREQUIRESOC')) {
  31. define('NOREQUIRESOC', '1');
  32. }
  33. require '../../main.inc.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
  35. $field = GETPOST('field', 'alpha');
  36. $element = GETPOST('element', 'alpha');
  37. $table_element = GETPOST('table_element', 'alpha');
  38. $fk_element = GETPOST('fk_element', 'alpha');
  39. /*
  40. * View
  41. */
  42. top_httphead();
  43. //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  44. // Load original field value
  45. if (!empty($field) && !empty($element) && !empty($table_element) && !empty($fk_element)) {
  46. $ext_element = GETPOST('ext_element', 'alpha');
  47. $field = substr($field, 8); // remove prefix val_
  48. $type = GETPOST('type', 'alpha');
  49. $loadmethod = (GETPOST('loadmethod', 'alpha') ? GETPOST('loadmethod', 'alpha') : 'getValueFrom');
  50. if ($element != 'order_supplier' && $element != 'invoice_supplier' && preg_match('/^([^_]+)_([^_]+)/i', $element, $regs)) {
  51. $element = $regs[1];
  52. $subelement = $regs[2];
  53. }
  54. if ($element == 'propal') {
  55. $element = 'propale';
  56. } elseif ($element == 'fichinter') {
  57. $element = 'ficheinter';
  58. } elseif ($element == 'product') {
  59. $element = 'produit';
  60. } elseif ($element == 'member') {
  61. $element = 'adherent';
  62. } elseif ($element == 'order_supplier') {
  63. $element = 'fournisseur';
  64. $subelement = 'commande';
  65. } elseif ($element == 'invoice_supplier') {
  66. $element = 'fournisseur';
  67. $subelement = 'facture';
  68. }
  69. if ($user->rights->$element->lire || $user->rights->$element->read
  70. || (isset($subelement) && ($user->rights->$element->$subelement->lire || $user->rights->$element->$subelement->read))
  71. || ($element == 'payment' && $user->rights->facture->lire)
  72. || ($element == 'payment_supplier' && $user->rights->fournisseur->facture->lire)) {
  73. if ($type == 'select') {
  74. $methodname = 'load_cache_'.$loadmethod;
  75. $cachename = 'cache_'.GETPOST('loadmethod', 'alpha');
  76. $form = new Form($db);
  77. if (method_exists($form, $methodname)) {
  78. $ret = $form->$methodname();
  79. if ($ret > 0) {
  80. echo json_encode($form->$cachename);
  81. }
  82. } elseif (!empty($ext_element)) {
  83. $module = $subelement = $ext_element;
  84. if (preg_match('/^([^_]+)_([^_]+)/i', $ext_element, $regs)) {
  85. $module = $regs[1];
  86. $subelement = $regs[2];
  87. }
  88. dol_include_once('/'.$module.'/class/actions_'.$subelement.'.class.php');
  89. $classname = 'Actions'.ucfirst($subelement);
  90. $object = new $classname($db);
  91. $ret = $object->$methodname($fk_element);
  92. if ($ret > 0) {
  93. echo json_encode($object->$cachename);
  94. }
  95. }
  96. } else {
  97. $object = new GenericObject($db);
  98. $value = $object->$loadmethod($table_element, $fk_element, $field);
  99. echo $value;
  100. }
  101. } else {
  102. echo $langs->transnoentities('NotEnoughPermissions');
  103. }
  104. }