global_error_message.inc.php 7.8 KB

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