/lib/OA/Dashboard/Widgets/Reload.php

https://bitbucket.org/valmy/openx · PHP · 125 lines · 63 code · 16 blank · 46 comment · 13 complexity · a3dd9c63ebaf6b9362119593a63102ad MD5 · raw file

  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v2.8 |
  5. | ========== |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id$
  25. */
  26. require_once MAX_PATH . '/lib/OA/Dashboard/Widget.php';
  27. require_once MAX_PATH . '/lib/OA/Central/Dashboard.php';
  28. /**
  29. * A class to display the dashboard iframe content
  30. *
  31. */
  32. class OA_Dashboard_Widget_Reload extends OA_Dashboard_Widget
  33. {
  34. var $aUrl;
  35. /**
  36. * The class constructor
  37. *
  38. * @param array $aParams The parameters array, usually $_REQUEST
  39. * @return OA_Dashboard_Widget
  40. */
  41. function OA_Dashboard_Widget_Reload($aParams)
  42. {
  43. parent::OA_Dashboard_Widget($aParams);
  44. if (isset($aParams['url'])) {
  45. if ($aUrl = @parse_url(stripslashes($aParams['url']))) {
  46. $aUrl['protocol'] = $aUrl['scheme'];
  47. if (empty($aUrl['path'])) {
  48. $aUrl['path'] = '/';
  49. }
  50. if (!empty($aUrl['query'])) {
  51. $aUrl['path'] .= '?'.$aUrl['query'];
  52. }
  53. $this->aUrl = $aUrl;
  54. }
  55. }
  56. if (empty($this->aUrl)) {
  57. $this->aUrl = $GLOBALS['_MAX']['CONF']['oacDashboard'];
  58. }
  59. }
  60. /**
  61. * A method to launch and display the widget
  62. *
  63. */
  64. function display()
  65. {
  66. $oDashboard = new OA_Central_Dashboard();
  67. $m2mTicket = $oDashboard->getM2MTicket();
  68. if (PEAR::isError($m2mTicket)) {
  69. $this->showError($m2mTicket);
  70. } else {
  71. $url = $this->buildDashboardUrl($m2mTicket, $this->buildUrl($this->aUrl), '&');
  72. if (!preg_match('/[\r\n]/', $url)) {
  73. header("Location: {$url}");
  74. }
  75. }
  76. }
  77. /**
  78. * A method to display an M2M/Dashboard error
  79. *
  80. * @param PEAR_Error $oError
  81. */
  82. function showError($oError)
  83. {
  84. $aConf = $GLOBALS['_MAX']['CONF'];
  85. $oTpl = new OA_Admin_Template('dashboard/error.html');
  86. $errorCode = $oError->getCode();
  87. $nativeErrorMessage = $oError->getMessage();
  88. // Set error message
  89. if (isset($GLOBALS['strDashboardErrorMsg'.$errorCode])) {
  90. $errorMessage = $GLOBALS['strDashboardErrorMsg'.$errorCode];
  91. } else if (!empty($nativeErrorMessage)) {
  92. $errorMessage = $nativeErrorMessage;
  93. // Don't show this message twice on error page
  94. unset($nativeErrorMessage);
  95. } else {
  96. $errorMessage = $GLOBALS['strDashboardGenericError'];
  97. }
  98. // Set error description
  99. if (isset($GLOBALS['strDashboardErrorDsc'.$errorCode])) {
  100. $errorDescription = $GLOBALS['strDashboardErrorDsc'.$errorCode];
  101. }
  102. $oTpl->assign('errorCode', $errorCode);
  103. $oTpl->assign('errorMessage', $errorMessage);
  104. $oTpl->assign('systemMessage', $nativeErrorMessage);
  105. $oTpl->assign('errorDescription', $errorDescription);
  106. $oTpl->display();
  107. }
  108. }
  109. ?>