PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/ajax/loadinplace.php

https://github.com/asterix14/dolibarr
PHP | 102 lines | 62 code | 12 blank | 28 comment | 29 complexity | ee6bf62d420d7d2fdbf11fad02286165 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
  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 2 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('NOREQUIREHTML')) define('NOREQUIREHTML','1');
  24. if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  25. if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  26. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  27. require('../../main.inc.php');
  28. require_once(DOL_DOCUMENT_ROOT."/core/class/genericobject.class.php");
  29. /*
  30. * View
  31. */
  32. top_httphead();
  33. //print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
  34. // Load original field value
  35. if((isset($_GET['field']) && ! empty($_GET['field']))
  36. && (isset($_GET['element']) && ! empty($_GET['element']))
  37. && (isset($_GET['table_element']) && ! empty($_GET['table_element']))
  38. && (isset($_GET['fk_element']) && ! empty($_GET['fk_element'])))
  39. {
  40. $element = GETPOST('element');
  41. $table_element = GETPOST('table_element');
  42. $fk_element = GETPOST('fk_element');
  43. $ext_element = GETPOST('ext_element');
  44. //$ext_table_element = GETPOST('ext_table_element');
  45. //$ext_fk_element = GETPOST('ext_fk_element');
  46. $field = substr(GETPOST('field'), 4); // remove prefix val_
  47. $type = GETPOST('type');
  48. $loadmethod = (GETPOST('loadmethod') ? GETPOST('loadmethod') : 'getValueFrom');
  49. if (preg_match('/^([^_]+)_([^_]+)/i',$element,$regs))
  50. {
  51. $element = $regs[1];
  52. $subelement = $regs[2];
  53. }
  54. if ($element == 'propal') $element = 'propale';
  55. else if ($element == 'fichinter') $element = 'ficheinter';
  56. if ($user->rights->$element->lire || $user->rights->$element->read
  57. || $user->rights->$element->$subelement->lire || $user->rights->$element->$subelement->read)
  58. {
  59. if ($type == 'select')
  60. {
  61. $methodname = 'load_cache_'.$loadmethod;
  62. $cachename = 'cache_'.GETPOST('loadmethod');
  63. $form = new Form($db);
  64. if (method_exists($form, $methodname))
  65. {
  66. $ret = $form->$methodname();
  67. if ($ret > 0) echo json_encode($form->$cachename);
  68. }
  69. else if (! empty($ext_element))
  70. {
  71. dol_include_once('/'.$ext_element.'/class/actions_'.$ext_element.'.class.php');
  72. $classname = 'Actions'.ucfirst($ext_element);
  73. $object = new $classname($db);
  74. $ret = $object->$methodname();
  75. if ($ret > 0) echo json_encode($object->$cachename);
  76. }
  77. }
  78. else
  79. {
  80. $object = new GenericObject($db);
  81. $value=$object->$loadmethod($table_element, $fk_element, $field);
  82. echo $value;
  83. }
  84. }
  85. else
  86. {
  87. echo $langs->transnoentities('NotEnoughPermissions');
  88. }
  89. }
  90. ?>