box.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/core/ajax/box.php
  20. * \brief File to return Ajax response on Box move or close
  21. */
  22. if (!defined('NOTOKENRENEWAL')) {
  23. define('NOTOKENRENEWAL', '1'); // Disables token renewal
  24. }
  25. if (!defined('NOREQUIREMENU')) {
  26. define('NOREQUIREMENU', '1');
  27. }
  28. if (!defined('NOREQUIREHTML')) {
  29. define('NOREQUIREHTML', '1');
  30. }
  31. if (!defined('NOREQUIREAJAX')) {
  32. define('NOREQUIREAJAX', '1');
  33. }
  34. if (!defined('NOREQUIRESOC')) {
  35. define('NOREQUIRESOC', '1');
  36. }
  37. // Load Dolibarr environment
  38. require '../../main.inc.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
  40. $boxid = GETPOST('boxid', 'int');
  41. $boxorder = GETPOST('boxorder');
  42. $zone = GETPOST('zone', 'int');
  43. $userid = GETPOST('userid', 'int');
  44. /*
  45. * View
  46. */
  47. // Ajout directives pour resoudre bug IE
  48. //header('Cache-Control: Public, must-revalidate');
  49. //header('Pragma: public');
  50. //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
  51. top_httphead();
  52. print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  53. // Add a box
  54. if ($boxid > 0 && $zone != '' && $userid > 0) {
  55. $tmp = explode('-', $boxorder);
  56. $nbboxonleft = substr_count($tmp[0], ',');
  57. $nbboxonright = substr_count($tmp[1], ',');
  58. print $nbboxonleft.'-'.$nbboxonright;
  59. if ($nbboxonleft > $nbboxonright) {
  60. $boxorder = preg_replace('/B:/', 'B:'.$boxid.',', $boxorder); // Insert id of new box into list
  61. } else {
  62. $boxorder = preg_replace('/^A:/', 'A:'.$boxid.',', $boxorder); // Insert id of new box into list
  63. }
  64. }
  65. // Registering the location of boxes after a move
  66. if ($boxorder && $zone != '' && $userid > 0) {
  67. // boxorder value is the target order: "A:idboxA1,idboxA2,A-B:idboxB1,idboxB2,B"
  68. dol_syslog("AjaxBox boxorder=".$boxorder." zone=".$zone." userid=".$userid, LOG_DEBUG);
  69. $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid);
  70. if ($result > 0) {
  71. $langs->load("boxes");
  72. if (!GETPOST('closing')) {
  73. setEventMessages($langs->trans("BoxAdded"), null);
  74. }
  75. }
  76. }