global_error_message.inc.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 = 'Powered by <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 to protect its contents, we have to prevent you from starting the installation script again. Please return to the main page.';
  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. if (class_exists('Template')) {
  42. $theme = Template::getThemeFallback().'/';
  43. } else {
  44. $theme = 'chamilo';
  45. }
  46. $css_path = 'app/Resources/public/css/';
  47. $css_web_assets = 'web/assets/';
  48. $css_web_path = 'web/css/';
  49. $themePath = $css_path.'themes/'.$theme.'/default.css';
  50. $css_web_fontawesome = $css_web_assets.'fontawesome/css/font-awesome.css';
  51. $bootstrap_file = $css_web_assets.'bootstrap/dist/css/bootstrap.min.css';
  52. $css_base_file = $css_web_path.'base.css';
  53. $css_list = array($bootstrap_file, $css_base_file, $themePath);
  54. $web_img = 'main/img';
  55. $root_sys = str_replace('\\', '/', realpath(dirname(__FILE__).'/../../')).'/';
  56. $root_rel = htmlentities($_SERVER['PHP_SELF']);
  57. if (!empty($root_rel)) {
  58. $pos = strrpos($root_rel, '/');
  59. $root_rel = substr($root_rel, 0, $pos - strlen($root_rel) + 1);
  60. if (strpos($root_rel, '/main/') !== false) {
  61. $pos = 0;
  62. while (($test_pos = strpos(substr($root_rel, $pos, strlen($root_rel)), '/main/')) !== false) {
  63. $pos = $test_pos + 1;
  64. }
  65. $root_rel = substr($root_rel, 0, $pos);
  66. } elseif (strpos($root_rel, '/courses/') !== false) {
  67. $pos = 0;
  68. while (($test_pos = strpos(substr($root_rel, $pos, strlen($root_rel)), '/courses/')) !== false) {
  69. $pos = $test_pos + 1;
  70. }
  71. $root_rel = substr($root_rel, 0, $pos);
  72. }
  73. }
  74. $installation_guide_url = $root_rel.'documentation/installation_guide.html';
  75. $css_def = '';
  76. foreach ($css_list as $css_item) {
  77. $css_base_chamilo_file = $root_sys.$css_item;
  78. if (file_exists($css_base_chamilo_file)) {
  79. $css_def .= @file_get_contents($css_base_chamilo_file);
  80. }
  81. }
  82. $global_error_message = array();
  83. switch ($global_error_code) {
  84. case 1:
  85. $global_error_message['section'] = $SectionSystemRequirementsProblem;
  86. $global_error_message['title'] = $IncorrectPhpVersionTitle;
  87. $php_version = function_exists('phpversion') ? phpversion() : (defined('PHP_VERSION') ? PHP_VERSION : '');
  88. $php_version = empty($php_version) ? '' : '(PHP '.$php_version.')';
  89. $IncorrectPhpVersionDescription = str_replace('%s1', $php_version, $IncorrectPhpVersionDescription);
  90. $IncorrectPhpVersionDescription = str_replace('%s2', REQUIRED_PHP_VERSION, $IncorrectPhpVersionDescription);
  91. $pos = strpos($IncorrectPhpVersionDescription, '%s3');
  92. if ($pos !== false) {
  93. $length = strlen($IncorrectPhpVersionDescription);
  94. $read_installation_guide = substr($IncorrectPhpVersionDescription, $pos + 3, $length);
  95. $IncorrectPhpVersionDescription = substr($IncorrectPhpVersionDescription, 0, $pos);
  96. $IncorrectPhpVersionDescription .= '<br /><a class="btn btn-default" href="'.$installation_guide_url.'" target="_blank">'.$read_installation_guide.'</a>';
  97. }
  98. $global_error_message['description'] = $IncorrectPhpVersionDescription;
  99. break;
  100. case 2:
  101. $global_error_message['section'] = $SectionInstallation;
  102. $global_error_message['title'] = $InstallationTitle;
  103. if (($pos = strpos($InstallationDescription, '%s')) === false) {
  104. $InstallationDescription = 'Click to INSTALL Chamilo %s or read the installation guide';
  105. }
  106. $read_installation_guide = substr($InstallationDescription, $pos + 2);
  107. $InstallationDescription = '<form action="'.$root_rel.'main/install/index.php" method="get">
  108. <div class="row"><div class="col-md-12">
  109. <div class="office">
  110. <h2 class="title">Welcome to the Chamilo installation wizard</h2>
  111. <p class="text">Let\'s start hunting skills down with Chamilo LMS! This wizard will guide you through the Chamilo installation and configuration process.</p>
  112. <p class="download-info">
  113. <button class="btn btn-primary btn-lg" type="submit" value="INSTALL Chamilo" ><i class="fa fa-download"></i> Install Chamilo</button>
  114. <a class="btn btn-success btn-lg" href="'.$installation_guide_url.'" target="_blank"> <i class="fa fa-file-text-o"></i> '.$read_installation_guide.'</a>
  115. </p>
  116. </div>
  117. </form>';
  118. $global_error_message['description'] = $InstallationDescription;
  119. break;
  120. case 3:
  121. case 4:
  122. case 5:
  123. $global_error_message['section'] = $SectionDatabaseUnavailable;
  124. $global_error_message['title'] = $DatabaseUnavailableTitle;
  125. $global_error_message['description'] = $DatabaseUnavailableDescription;
  126. break;
  127. case 6:
  128. $global_error_message['section'] = $SectionProtection;
  129. $global_error_message['title'] = $AlreadyInstalledTitle;
  130. $global_error_message['description'] = $AlreadyInstalledDescription;
  131. break;
  132. default:
  133. $global_error_message['section'] = $SectionTechnicalIssues;
  134. $global_error_message['title'] = $TechnicalIssuesTitle;
  135. $global_error_message['description'] = $TechnicalIssuesDescription;
  136. break;
  137. }
  138. $show_error_codes = defined('SHOW_ERROR_CODES') && SHOW_ERROR_CODES && $global_error_code != 2;
  139. $global_error_message['code'] = $show_error_codes ? $ErrorCode.': '.$global_error_code.'<br /><br />' : '';
  140. $global_error_message['details'] = empty($global_error_message['details']) ? '' : ($show_error_codes ? ': '.$global_error_message['details'] : $global_error_message['details']);
  141. $global_error_message['organisation'] = $Organisation;
  142. $global_error_message['powered_by'] = $PoweredBy;
  143. $global_error_message['encoding'] = 'UTF-8';
  144. $global_error_message['chamilo_logo'] = "data:image/png;base64,".base64_encode(file_get_contents($root_sys.'web/css/themes/'.$theme.'/images/header-logo.png'));
  145. $installChamiloImage = base64_encode(file_get_contents("$root_sys/main/img/install-chamilo.gif"));
  146. $global_error_message_page =
  147. <<<EOM
  148. <!DOCTYPE html>
  149. <html>
  150. <head>
  151. <title>{TITLE}</title>
  152. <meta charset="{ENCODING}" />
  153. <style>
  154. $css_def
  155. </style>
  156. <style type="text/css">
  157. body{
  158. background: #d2ebf9; /* Old browsers */
  159. background: -moz-linear-gradient(top, #d2ebf9 0%, #feffff 100%); /* FF3.6+ */
  160. background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#d2ebf9), color-stop(100%,#feffff)); /* Chrome,Safari4+ */
  161. background: -webkit-linear-gradient(top, #d2ebf9 0%,#feffff 100%); /* Chrome10+,Safari5.1+ */
  162. background: -o-linear-gradient(top, #d2ebf9 0%,#feffff 100%); /* Opera 11.10+ */
  163. background: -ms-linear-gradient(top, #d2ebf9 0%,#feffff 100%); /* IE10+ */
  164. background: linear-gradient(to bottom, #d2ebf9 0%,#feffff 100%); /* W3C */
  165. filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#d2ebf9', endColorstr='#feffff',GradientType=0 ); /* IE6-9 */
  166. }
  167. .chamilo {
  168. background: url("data:image/gif;base64,$installChamiloImage") no-repeat center 0;
  169. margin:auto;
  170. }
  171. .office{
  172. padding-top:250px;
  173. }
  174. @media (max-width: 480px) {
  175. body{
  176. background: url("data:image/gif;base64,$installChamiloImage") no-repeat center 0;
  177. background-repeat: no-repeat;
  178. background-position: -10px -5px;
  179. background-color: #DFF1FA;
  180. }
  181. .chamilo{
  182. background: none;
  183. height:300px;
  184. width:100%;
  185. margin:auto;
  186. }
  187. .download-info .btn-success{
  188. margin-top: 10px;
  189. }
  190. }
  191. </style>
  192. </head>
  193. <body>
  194. <div id="page-install">
  195. <div class="container chamilo">
  196. <div class="row">
  197. <div class="col-md-12">
  198. <div class="logo">
  199. <img src="{CHAMILO_LOGO}"/>
  200. </div>
  201. </div>
  202. </div>
  203. <div class="welcome-install">
  204. {DESCRIPTION}
  205. {CODE}
  206. </div>
  207. </div>
  208. </div>
  209. </body>
  210. </html>
  211. EOM;
  212. foreach ($global_error_message as $key => $value) {
  213. $global_error_message_page = str_replace('{'.strtoupper($key).'}', $value, $global_error_message_page);
  214. }
  215. header('Content-Type: text/html; charset='.$global_error_message['encoding']);
  216. die($global_error_message_page);
  217. }