global_error_message.inc.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. *==============================================================================
  5. * This script displays error messages on fatal errors
  6. * during initialization.
  7. *
  8. * @package dokeos.include
  9. * @author Ivan Tcholakov, 2009
  10. *==============================================================================
  11. */
  12. $Organisation = '<a href="http://www.dokeos.com" target="_blank">Dokeos Homepage</a>';
  13. $PoweredBy = 'Platform <a href="http://www.dokeos.com" target="_blank"> Dokeos </a> &copy; 2009';
  14. /**
  15. * English language variables.
  16. */
  17. // Sections.
  18. $SectionSystemRequirementsProblem = 'System requirements problem';
  19. $SectionInstallation = 'Installation';
  20. $SectionDatabaseUnavailable = 'Database is unavailable';
  21. $SectionTechnicalIssues = 'Technical issues';
  22. // Error code.
  23. $ErrorCode = 'Error code';
  24. // Error code 1.
  25. $IncorrectPhpVersionTitle = 'Incorrect PHP version';
  26. $IncorrectPhpVersionDescription = 'Scripting language version %s1 on your server is incorrect. PHP %s2 should be supported. %s3 Read the installation guide.';
  27. // Error code 2.
  28. $InstallationTitle = 'Dokeos has not been installed';
  29. $InstallationDescription = 'Click to INSTALL Dokeos %s or read the installation guide';
  30. // Error code 3.
  31. // Error code 4.
  32. // Error code 5.
  33. $DatabaseUnavailableTitle = 'Database is unavailable';
  34. $DatabaseUnavailableDescription = 'This portal is currently experiencing database issues. Please report this to the portal administrator. Thank you for your help.';
  35. // Unspecified error.
  36. $TechnicalIssuesTitle = 'Technical issues';
  37. $TechnicalIssuesDescription = 'This portal is currently experiencing technical issues. Please report this to the portal administrator. Thank you for your help.';
  38. if (is_int($global_error_code) && $global_error_code > 0) {
  39. $theme = 'dokeos_blue/';
  40. $css_path = 'main/css/';
  41. $css_file = $css_path.$theme.'default.css';
  42. $root_sys = str_replace('\\', '/', realpath(dirname(__FILE__).'/../../')).'/';
  43. $root_rel = htmlentities($_SERVER['PHP_SELF']);
  44. if (!empty($root_rel)) {
  45. $pos = strrpos($root_rel, '/');
  46. $root_rel = substr($root_rel, 0, $pos - strlen($root_rel) + 1);
  47. if (strpos($root_rel, '/main/') !== false) {
  48. $pos = 0;
  49. while (($test_pos = strpos(substr($root_rel, $pos, strlen($root_rel)), '/main/')) !== false) {
  50. $pos = $test_pos + 1;
  51. }
  52. $root_rel = substr($root_rel, 0, $pos);
  53. }
  54. elseif (strpos($root_rel, '/courses/') !== false) {
  55. $pos = 0;
  56. while (($test_pos = strpos(substr($root_rel, $pos, strlen($root_rel)), '/courses/')) !== false) {
  57. $pos = $test_pos + 1;
  58. }
  59. $root_rel = substr($root_rel, 0, $pos);
  60. }
  61. }
  62. $css_file = $root_sys.$css_file;
  63. if (file_exists($css_file)) {
  64. $css_def = @file_get_contents($css_file);
  65. } else {
  66. $css_def = '';
  67. }
  68. $css_def = str_replace('behavior:url("/main/css/csshover3.htc");', '', $css_def);
  69. $css_def = str_replace('main/', $root_rel.'main/', $css_def);
  70. $css_def = str_replace('images/', $root_rel.$css_path.$theme.'images/', $css_def);
  71. $css_def = str_replace('../../img/', $root_rel.'main/img/', $css_def);
  72. $global_error_message = array();
  73. switch ($global_error_code) {
  74. case 1:
  75. $global_error_message['section'] = $SectionSystemRequirementsProblem;
  76. $global_error_message['title'] = $IncorrectPhpVersionTitle;
  77. $php_version = function_exists('phpversion') ? phpversion() : (defined('PHP_VERSION') ? PHP_VERSION : '');
  78. $php_version = empty($php_version) ? '' : '(PHP '.$php_version.')';
  79. $IncorrectPhpVersionDescription = str_replace('%s1', $php_version, $IncorrectPhpVersionDescription);
  80. $IncorrectPhpVersionDescription = str_replace('%s2', REQUIRED_PHP_VERSION, $IncorrectPhpVersionDescription);
  81. $pos = strpos($IncorrectPhpVersionDescription, '%s3');
  82. if ($pos !== false) {
  83. $length = strlen($IncorrectPhpVersionDescription);
  84. $read_installation_guide = substr($IncorrectPhpVersionDescription, $pos + 3, $length);
  85. $IncorrectPhpVersionDescription = substr($IncorrectPhpVersionDescription, 0, $pos);
  86. $IncorrectPhpVersionDescription .= '<br /><a href="documentation/installation_guide.html" target="_blank">'.$read_installation_guide.'</a>';
  87. }
  88. $global_error_message['description'] = $IncorrectPhpVersionDescription;
  89. break;
  90. case 2:
  91. $global_error_message['section'] = $SectionInstallation;
  92. $global_error_message['title'] = $InstallationTitle;
  93. if (($pos = strpos($InstallationDescription, '%s')) === false) {
  94. $InstallationDescription = 'Click to INSTALL Dokeos %s or read the installation guide';
  95. }
  96. $click_to_install = substr($InstallationDescription, 0, $pos);
  97. $read_installation_guide = substr($InstallationDescription, $pos + 2);
  98. $InstallationDescription = '<form action="main/install/index.php" method="get"><button class="save" type="submit" value="&nbsp;&nbsp; '.$click_to_install.' &nbsp;&nbsp;" >'.$click_to_install.'</button></form><br />
  99. <a href="documentation/installation_guide.html" target="_blank">'.$read_installation_guide.'</a>';
  100. $global_error_message['description'] = $InstallationDescription;
  101. break;
  102. case 3:
  103. case 4:
  104. case 5:
  105. $global_error_message['section'] = $SectionDatabaseUnavailable;
  106. $global_error_message['title'] = $DatabaseUnavailableTitle;
  107. $global_error_message['description'] = $DatabaseUnavailableDescription;
  108. break;
  109. default:
  110. $global_error_message['section'] = $SectionTechnicalIssues;
  111. $global_error_message['title'] = $TechnicalIssuesTitle;
  112. $global_error_message['description'] = $TechnicalIssuesDescription;
  113. break;
  114. }
  115. $show_error_codes = defined('SHOW_ERROR_CODES') && SHOW_ERROR_CODES && $global_error_code != 2;
  116. $global_error_message['code'] = $show_error_codes ? $ErrorCode.': '.$global_error_code.'<br /><br />' : '';
  117. $global_error_message['details'] = empty($global_error_message['details']) ? '' : ($show_error_codes ? ': '.$global_error_message['details'] : $global_error_message['details']);
  118. $global_error_message['organisation'] = $Organisation;
  119. $global_error_message['powered_by'] = $PoweredBy;
  120. $global_error_message['encoding'] = 'UTF-8';
  121. $global_error_message['css'] = $css_def;
  122. $global_error_message_page =
  123. <<<EOM
  124. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  125. <html>
  126. <head>
  127. <title>{TITLE}</title>
  128. <meta http-equiv="Content-Type" content="text/html; charset={ENCODING}" />
  129. <style type="text/css" media="screen, projection">
  130. /*<![CDATA[*/
  131. {CSS}
  132. /*]]>*/
  133. </style>
  134. </head>
  135. <body>
  136. <div id="header">
  137. <div id="header1">{ORGANISATION}</div>
  138. <div class="clear"></div>
  139. <div id="header2">&nbsp;</div>
  140. <div id="header3">
  141. <ul id="logout">
  142. <li><a href="" target="_top"><span>&nbsp;</span></a></li>
  143. </ul>
  144. <ul>
  145. <li id="current"><a href="#"><span>{SECTION}</span></a></li>
  146. </ul>
  147. <div style="clear: both;" class="clear"></div>
  148. </div>
  149. <div id="header4">&nbsp;</div>
  150. </div>
  151. <div style="text-align: center;">
  152. <br /><br />{DESCRIPTION}<br /><br />
  153. {CODE}
  154. </div>
  155. <div id="footer">
  156. <div class="copyright">{POWERED_BY}</div>
  157. &nbsp;
  158. </div>
  159. </body>
  160. </html>
  161. EOM;
  162. foreach ($global_error_message as $key => $value) {
  163. $global_error_message_page = str_replace('{'.strtoupper($key).'}', $value, $global_error_message_page);
  164. }
  165. header('Content-Type: text/html; charset='.$global_error_message['encoding']);
  166. die($global_error_message_page);
  167. }