loadinplace.php 3.8 KB

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