global_error_message.inc.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 = 'Warning: we have detected that your version of PHP is %s1. To install Chamilo, you need to have PHP %s2 or superior. If you don\'t know what we\'re talking about, please contact your hosting provider or your support team.
  25. %s3 Read the installation guide.';
  26. // Error code 2.
  27. $InstallationTitle = 'Chamilo has not been installed';
  28. $InstallationDescription = 'Click to INSTALL Chamilo %s or read the installation guide';
  29. // Error code 3.
  30. // Error code 4.
  31. // Error code 5.
  32. $DatabaseUnavailableTitle = 'Database is unavailable';
  33. $DatabaseUnavailableDescription = 'This portal is currently experiencing database issues. Please report this to the portal administrator. Thank you for your help.';
  34. // Error code 6.
  35. $AlreadyInstalledTitle = 'Chamilo has already been installed';
  36. $AlreadyInstalledDescription = 'The system has already been installed. In order its content to be protected you are not allowed to start the installation script again.';
  37. // Unspecified error.
  38. $TechnicalIssuesTitle = 'Technical issues';
  39. $TechnicalIssuesDescription = 'This portal is currently experiencing technical issues. Please report this to the portal administrator. Thank you for your help.';
  40. if (is_int($global_error_code) && $global_error_code > 0) {
  41. $theme = 'chamilo/';
  42. $css_path = 'main/css/';
  43. $css_file = $css_path.$theme.'default.css';
  44. $bootstrap_file = $css_path.'bootstrap.css';
  45. $css_base_file = $css_path.'base.css';
  46. $css_base_chamilo_file = $css_path.'base_chamilo.css';
  47. $css_list = array($bootstrap_file, $css_base_file, $css_base_chamilo_file, $css_file);
  48. $root_sys = str_replace('\\', '/', realpath(dirname(__FILE__).'/../../')).'/';
  49. $root_rel = htmlentities($_SERVER['PHP_SELF']);
  50. if (!empty($root_rel)) {
  51. $pos = strrpos($root_rel, '/');
  52. $root_rel = substr($root_rel, 0, $pos - strlen($root_rel) + 1);
  53. if (strpos($root_rel, '/main/') !== false) {
  54. $pos = 0;
  55. while (($test_pos = strpos(substr($root_rel, $pos, strlen($root_rel)), '/main/')) !== false) {
  56. $pos = $test_pos + 1;
  57. }
  58. $root_rel = substr($root_rel, 0, $pos);
  59. } elseif (strpos($root_rel, '/courses/') !== false) {
  60. $pos = 0;
  61. while (($test_pos = strpos(substr($root_rel, $pos, strlen($root_rel)), '/courses/')) !== false) {
  62. $pos = $test_pos + 1;
  63. }
  64. $root_rel = substr($root_rel, 0, $pos);
  65. }
  66. }
  67. $installation_guide_url = $root_rel.'documentation/installation_guide.html';
  68. $css_def = '';
  69. foreach ($css_list as $css_item) {
  70. $css_base_chamilo_file = $root_sys.$css_item;
  71. if (file_exists($css_base_chamilo_file)) {
  72. $css_def .= @file_get_contents($css_base_chamilo_file);
  73. }
  74. }
  75. $css_def = str_replace("@import url('bootstrap.css');", '', $css_def);
  76. $css_def = str_replace('main/', $root_rel.'main/', $css_def);
  77. $css_def = str_replace('images/', $root_rel.$css_path.$theme.'images/', $css_def);
  78. $css_def = str_replace('../../img/', $root_rel.'main/img/', $css_def);
  79. $global_error_message = array();
  80. switch ($global_error_code) {
  81. case 1:
  82. $global_error_message['section'] = $SectionSystemRequirementsProblem;
  83. $global_error_message['title'] = $IncorrectPhpVersionTitle;
  84. $php_version = function_exists('phpversion') ? phpversion() : (defined('PHP_VERSION') ? PHP_VERSION : '');
  85. $php_version = empty($php_version) ? '' : '(PHP '.$php_version.')';
  86. $IncorrectPhpVersionDescription = str_replace('%s1', $php_version, $IncorrectPhpVersionDescription);
  87. $IncorrectPhpVersionDescription = str_replace('%s2', REQUIRED_PHP_VERSION, $IncorrectPhpVersionDescription);
  88. $pos = strpos($IncorrectPhpVersionDescription, '%s3');
  89. if ($pos !== false) {
  90. $length = strlen($IncorrectPhpVersionDescription);
  91. $read_installation_guide = substr($IncorrectPhpVersionDescription, $pos + 3, $length);
  92. $IncorrectPhpVersionDescription = substr($IncorrectPhpVersionDescription, 0, $pos);
  93. $IncorrectPhpVersionDescription .= '<br /><a class="btn" href="'.$installation_guide_url.'" target="_blank">'.$read_installation_guide.'</a>';
  94. }
  95. $global_error_message['description'] = $IncorrectPhpVersionDescription;
  96. break;
  97. case 2:
  98. $global_error_message['section'] = $SectionInstallation;
  99. $global_error_message['title'] = $InstallationTitle;
  100. if (($pos = strpos($InstallationDescription, '%s')) === false) {
  101. $InstallationDescription = 'Click to INSTALL Chamilo %s or read the installation guide';
  102. }
  103. $read_installation_guide = substr($InstallationDescription, $pos + 2);
  104. $InstallationDescription = '<form action="'.$root_rel.'main/install/index.php" method="get">
  105. <p class="download-info">
  106. <button class="btn btn-primary btn-large" type="submit" value="INSTALL Chamilo" >INSTALL Chamilo</button>
  107. <a class="btn btn-large" href="'.$installation_guide_url.'" target="_blank">'.$read_installation_guide.'</a>
  108. </p>
  109. </form>';
  110. $global_error_message['description'] = $InstallationDescription;
  111. break;
  112. case 3:
  113. case 4:
  114. case 5:
  115. $global_error_message['section'] = $SectionDatabaseUnavailable;
  116. $global_error_message['title'] = $DatabaseUnavailableTitle;
  117. $global_error_message['description'] = $DatabaseUnavailableDescription;
  118. break;
  119. case 6:
  120. $global_error_message['section'] = $SectionProtection;
  121. $global_error_message['title'] = $AlreadyInstalledTitle;
  122. $global_error_message['description'] = $AlreadyInstalledDescription;
  123. break;
  124. default:
  125. $global_error_message['section'] = $SectionTechnicalIssues;
  126. $global_error_message['title'] = $TechnicalIssuesTitle;
  127. $global_error_message['description'] = $TechnicalIssuesDescription;
  128. break;
  129. }
  130. $show_error_codes = defined('SHOW_ERROR_CODES') && SHOW_ERROR_CODES && $global_error_code != 2;
  131. $global_error_message['code'] = $show_error_codes ? $ErrorCode.': '.$global_error_code.'<br /><br />' : '';
  132. $global_error_message['details'] = empty($global_error_message['details']) ? '' : ($show_error_codes ? ': '.$global_error_message['details'] : $global_error_message['details']);
  133. $global_error_message['organisation'] = $Organisation;
  134. $global_error_message['powered_by'] = $PoweredBy;
  135. $global_error_message['encoding'] = 'UTF-8';
  136. $global_error_message['css'] = $css_def;
  137. $global_error_message['chamilo_logo'] = $root_rel.$css_path.$theme.'images/header-logo.png';
  138. // {ORGANISATION} moved from the header
  139. $global_error_message_page =
  140. <<<EOM
  141. <!DOCTYPE html>
  142. <html>
  143. <head>
  144. <title>{TITLE}</title>
  145. <meta charset="{ENCODING}" />
  146. <style type="text/css" media="screen, projection">
  147. /*<![CDATA[*/
  148. {CSS}
  149. /*]]>*/
  150. </style>
  151. </head>
  152. <body>
  153. <div id="wrapper">
  154. <div id="main" class="container">
  155. <header>
  156. <div class="row">
  157. <div id="header_left" class="span4">
  158. <div id="logo">
  159. <img vspace="10" hspace="10" alt="Chamilo" src="{CHAMILO_LOGO}">
  160. </div>
  161. </div>
  162. </div>
  163. <div class="navbar subnav">
  164. <div class="navbar-inner">
  165. <div class="container">
  166. <div class="nav-collapse">
  167. <ul class="nav nav-pills">
  168. <li id="current" class="active">
  169. <a target="_top" href="index.php">Homepage</a>
  170. </li>
  171. </ul>
  172. </div>
  173. </div>
  174. </div>
  175. </div>
  176. <ul class="breadcrumb">
  177. <li><a href="#">{SECTION}</a></li>
  178. </ul>
  179. </header>
  180. <br />
  181. <section>
  182. <div style="text-align:center">
  183. {DESCRIPTION}
  184. {CODE}
  185. </div>
  186. </section>
  187. </div>
  188. <div class="push"/></div>
  189. </div>
  190. <footer>
  191. <div class="container">
  192. <div class="row">
  193. <div style="text-align: center;">
  194. &nbsp;<br />{POWERED_BY}
  195. </div>
  196. </div>
  197. </div>
  198. </footer>
  199. </body>
  200. </html>
  201. EOM;
  202. foreach ($global_error_message as $key => $value) {
  203. $global_error_message_page = str_replace('{'.strtoupper($key).'}', $value, $global_error_message_page);
  204. }
  205. header('Content-Type: text/html; charset='.$global_error_message['encoding']);
  206. die($global_error_message_page);
  207. }