box.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. require '../../main.inc.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
  39. $boxid = GETPOST('boxid', 'int');
  40. $boxorder = GETPOST('boxorder');
  41. $zone = GETPOST('zone', 'int');
  42. $userid = GETPOST('userid', 'int');
  43. /*
  44. * View
  45. */
  46. // Ajout directives pour resoudre bug IE
  47. //header('Cache-Control: Public, must-revalidate');
  48. //header('Pragma: public');
  49. //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
  50. top_httphead();
  51. print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  52. // Add a box
  53. if ($boxid > 0 && $zone != '' && $userid > 0) {
  54. $tmp = explode('-', $boxorder);
  55. $nbboxonleft = substr_count($tmp[0], ',');
  56. $nbboxonright = substr_count($tmp[1], ',');
  57. print $nbboxonleft.'-'.$nbboxonright;
  58. if ($nbboxonleft > $nbboxonright) {
  59. $boxorder = preg_replace('/B:/', 'B:'.$boxid.',', $boxorder); // Insert id of new box into list
  60. } else {
  61. $boxorder = preg_replace('/^A:/', 'A:'.$boxid.',', $boxorder); // Insert id of new box into list
  62. }
  63. }
  64. // Registering the location of boxes after a move
  65. if ($boxorder && $zone != '' && $userid > 0) {
  66. // boxorder value is the target order: "A:idboxA1,idboxA2,A-B:idboxB1,idboxB2,B"
  67. dol_syslog("AjaxBox boxorder=".$boxorder." zone=".$zone." userid=".$userid, LOG_DEBUG);
  68. $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid);
  69. if ($result > 0) {
  70. $langs->load("boxes");
  71. if (!GETPOST('closing')) {
  72. setEventMessages($langs->trans("BoxAdded"), null);
  73. }
  74. }
  75. }