PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/ajax/loadinplace.php

https://bitbucket.org/speedealing/speedealing
PHP | 149 lines | 97 code | 23 blank | 29 comment | 28 complexity | 9f34e71602dd10d27208911b59e6ec76 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2011-2012 Regis Houssin <regis.houssin@capnetworks.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'))
  22. define('NOTOKENRENEWAL', '1'); // Disables token renewal
  23. if (!defined('NOREQUIREMENU'))
  24. define('NOREQUIREMENU', '1');
  25. //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
  26. if (!defined('NOREQUIREAJAX'))
  27. define('NOREQUIREAJAX', '1');
  28. if (!defined('NOREQUIRESOC'))
  29. define('NOREQUIRESOC', '1');
  30. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  31. require '../../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT . '/core/class/genericobject.class.php';
  33. $key = GETPOST('key', 'alpha');
  34. $class = GETPOST('element_class', 'alpha');
  35. $id = GETPOST('id', 'alpha');
  36. $type = GETPOST('type', 'alpha');
  37. $field = GETPOST('field', 'alpha');
  38. $element = GETPOST('element', 'alpha');
  39. $table_element = GETPOST('table_element', 'alpha');
  40. $fk_element = GETPOST('fk_element', 'alpha');
  41. $key = substr($key, 8); // remove prefix editval_
  42. /*
  43. * View
  44. */
  45. top_httphead();
  46. error_log(print_r($_GET, true));
  47. if (!empty($key) && !empty($class) && !empty($id)) {
  48. dol_include_once("/" . strtolower($class) . "/class/" . strtolower($class) . ".class.php");
  49. $return = array();
  50. $object = new $class($db);
  51. $object->load($id);
  52. // Load langs files
  53. if (count($object->fk_extrafields->langs))
  54. foreach ($object->fk_extrafields->langs as $row)
  55. $langs->load($row);
  56. if ($type == "select") {
  57. if (!empty($object->$key))
  58. $return['selected'] = $object->$key;
  59. else
  60. $return['selected'] = $object->fk_extrafields->fields->$key->default;
  61. }
  62. $aRow = $object->fk_extrafields->fields->$key;
  63. if (isset($aRow->view)) { // Is a view
  64. if (isset($aRow->class)) { // Is another class
  65. $class_obj = $aRow->class;
  66. dol_include_once("/" . strtolower($class_obj) . "/class/" . strtolower($class_obj) . ".class.php");
  67. $object_tmp = new $class_obj($db);
  68. }
  69. $params = array();
  70. if (count($aRow->params))
  71. foreach ($aRow->params as $idx => $row) {
  72. eval("\$row = $row;");
  73. if (!empty($row))
  74. $params[$idx] = $row;
  75. }
  76. try {
  77. if (isset($aRow->class)) // Is view is an other class
  78. $result = $object_tmp->getView($aRow->view, $params);
  79. else
  80. $result = $object->getView($aRow->view, $params);
  81. } catch (Exception $e) {
  82. $error = "Fetch : Something weird happened: " . $e->getMessage() . " (errcode=" . $e->getCode() . ")\n";
  83. dol_print_error($db, $error);
  84. return 0;
  85. }
  86. if ($type == "select") {
  87. $aRow->values[0] = new stdClass();
  88. $aRow->values[0]->label = "";
  89. $aRow->values[0]->enable = true;
  90. }
  91. foreach ($result->rows as $row) {
  92. if (empty($aRow->getkey)) {
  93. $aRow->values[$row->value->_id] = new stdClass();
  94. $aRow->values[$row->value->_id]->label = $row->value->name;
  95. $aRow->values[$row->value->_id]->enable = true;
  96. } else { // For getkey
  97. $aRow->values[$row->key] = new stdClass();
  98. $aRow->values[$row->key]->label = $row->key;
  99. $aRow->values[$row->key]->enable = true;
  100. }
  101. }
  102. if ($type == "select") {
  103. $return['selected'] = $object->$key->id; // Index of key
  104. }
  105. }
  106. // Value for select or autocomplete
  107. if (isset($object->fk_extrafields->fields->$key->values)) {
  108. foreach ($object->fk_extrafields->fields->$key->values as $keys => $aRow) {
  109. if ($aRow->enable) {
  110. if ($type == "select") {
  111. if (isset($aRow->label))
  112. $return[$keys] = $langs->trans($aRow->label);
  113. else
  114. $return[$keys] = $langs->trans($keys);
  115. //if(!empty($return[$keys]) && $object->fk_extrafields->fields->$key->class != "User")
  116. // $return[$keys] = $keys."-".$return[$keys];
  117. } else { //autocomplete
  118. echo $keys . ";";
  119. }
  120. }
  121. }
  122. }
  123. //if ($type == "select")
  124. echo json_encode($return);
  125. }
  126. ?>