global_error_message.inc.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. *
  8. * @author Ivan Tcholakov, 2009-2010
  9. */
  10. $Organisation = '<a href="http://www.chamilo.org" target="_blank">Chamilo Homepage</a>';
  11. $PoweredBy = 'Powered by <a href="http://www.chamilo.org" target="_blank"> Chamilo </a> &copy; '.date('Y');
  12. /**
  13. * English language variables.
  14. */
  15. // Sections.
  16. $SectionSystemRequirementsProblem = 'System requirements problem';
  17. $SectionInstallation = 'Installation';
  18. $SectionDatabaseUnavailable = 'Database is unavailable';
  19. $SectionTechnicalIssues = 'Technical issues';
  20. $SectionProtection = 'Protection measure';
  21. // Error code.
  22. $ErrorCode = 'Error code';
  23. // Error code 1.
  24. $IncorrectPhpVersionTitle = 'Incorrect PHP version';
  25. $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.
  26. %s3 Read the installation guide.';
  27. // Error code 2.
  28. $InstallationTitle = 'Chamilo has not been installed';
  29. $InstallationDescription = 'Click to INSTALL Chamilo %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. // Error code 6.
  36. $AlreadyInstalledTitle = 'Chamilo has already been installed';
  37. $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.';
  38. // Unspecified error.
  39. $TechnicalIssuesTitle = 'Technical issues';
  40. $TechnicalIssuesDescription = 'This portal is currently experiencing technical issues. Please report this to the portal administrator. Thank you for your help.';
  41. if (is_int($global_error_code) && $global_error_code > 0) {
  42. if (class_exists('Template') && function_exists('api_get_configuration_value')) {
  43. $theme = Template::getThemeFallback().'/';
  44. } else {
  45. $theme = 'chamilo';
  46. }
  47. $root_rel = '';
  48. $installation_guide_url = $root_rel.'documentation/installation_guide.html';
  49. $css_path = 'app/Resources/public/css/';
  50. $css_web_assets = 'web/assets/';
  51. $css_web_path = 'web/css/';
  52. $themePath = $css_path.'themes/'.$theme.'/default.css';
  53. $bootstrap_file = $css_web_assets.'bootstrap/dist/css/bootstrap.min.css';
  54. $css_base_file = $css_web_path.'base.css';
  55. $css_list = [$bootstrap_file, $css_base_file, $themePath];
  56. $web_img = 'main/img';
  57. $root_sys = str_replace('\\', '/', realpath(__DIR__.'/../../')).'/';
  58. $css_def = '';
  59. foreach ($css_list as $cssFile) {
  60. $cssFile = $root_sys.$cssFile;
  61. if (file_exists($cssFile)) {
  62. $css_def .= file_get_contents($cssFile);
  63. }
  64. }
  65. $global_error_message = [];
  66. switch ($global_error_code) {
  67. case 1:
  68. $global_error_message['section'] = $SectionSystemRequirementsProblem;
  69. $global_error_message['title'] = $IncorrectPhpVersionTitle;
  70. $php_version = function_exists('phpversion') ? phpversion() : (defined('PHP_VERSION') ? PHP_VERSION : '');
  71. $php_version = empty($php_version) ? '' : '(PHP '.$php_version.')';
  72. $IncorrectPhpVersionDescription = str_replace('%s1', $php_version, $IncorrectPhpVersionDescription);
  73. $IncorrectPhpVersionDescription = str_replace('%s2', REQUIRED_PHP_VERSION, $IncorrectPhpVersionDescription);
  74. $pos = strpos($IncorrectPhpVersionDescription, '%s3');
  75. if ($pos !== false) {
  76. $length = strlen($IncorrectPhpVersionDescription);
  77. $read_installation_guide = substr($IncorrectPhpVersionDescription, $pos + 3, $length);
  78. $IncorrectPhpVersionDescription = substr($IncorrectPhpVersionDescription, 0, $pos);
  79. $IncorrectPhpVersionDescription .= '<br /><a class="btn btn-default" href="'.$installation_guide_url.'" target="_blank">'.$read_installation_guide.'</a>';
  80. }
  81. $global_error_message['description'] = $IncorrectPhpVersionDescription;
  82. break;
  83. case 2:
  84. require __DIR__.'/../install/version.php';
  85. $global_error_message['section'] = $SectionInstallation;
  86. $global_error_message['title'] = $InstallationTitle;
  87. if (($pos = strpos($InstallationDescription, '%s')) === false) {
  88. $InstallationDescription = 'Click to INSTALL Chamilo %s or read the installation guide';
  89. }
  90. $read_installation_guide = substr($InstallationDescription, $pos + 2);
  91. $versionStatus = (!empty($new_version_status) && $new_version_status != 'stable' ? $new_version_status : '');
  92. $InstallationDescription = '<form action="'.$root_rel.'main/install/index.php" method="get">
  93. <div class="row">
  94. <div class="col-md-12">
  95. <div class="office">
  96. <h2 class="title">Welcome to the Chamilo '.$new_version.' '.$new_version_status.' installation wizard</h2>
  97. <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>
  98. <p class="download-info">
  99. <button class="btn btn-primary btn-lg" type="submit" value="INSTALL Chamilo" ><i class="fa fa-download" aria-hidden="true"></i> Install Chamilo</button>
  100. <a class="btn btn-success btn-lg" href="'.$installation_guide_url.'" target="_blank"> '.$read_installation_guide.'</a>
  101. </p>
  102. </div>
  103. </div>
  104. </div>
  105. </form>';
  106. $global_error_message['description'] = $InstallationDescription;
  107. break;
  108. case 3:
  109. case 4:
  110. case 5:
  111. $global_error_message['section'] = $SectionDatabaseUnavailable;
  112. $global_error_message['title'] = $DatabaseUnavailableTitle;
  113. $global_error_message['description'] = $DatabaseUnavailableDescription;
  114. break;
  115. case 6:
  116. $global_error_message['section'] = $SectionProtection;
  117. $global_error_message['title'] = $AlreadyInstalledTitle;
  118. $global_error_message['description'] = $AlreadyInstalledDescription;
  119. break;
  120. default:
  121. $global_error_message['section'] = $SectionTechnicalIssues;
  122. $global_error_message['title'] = $TechnicalIssuesTitle;
  123. $global_error_message['description'] = $TechnicalIssuesDescription;
  124. break;
  125. }
  126. $show_error_codes = defined('SHOW_ERROR_CODES') && SHOW_ERROR_CODES && $global_error_code != 2;
  127. $global_error_message['code'] = $show_error_codes ? $ErrorCode.': '.$global_error_code.'<br /><br />' : '';
  128. $global_error_message['details'] = empty($global_error_message['details']) ? '' : ($show_error_codes ? ': '.$global_error_message['details'] : $global_error_message['details']);
  129. $global_error_message['organisation'] = $Organisation;
  130. $global_error_message['powered_by'] = $PoweredBy;
  131. $global_error_message['encoding'] = 'UTF-8';
  132. $global_error_message['chamilo_logo'] = "data:image/png;base64,".base64_encode(file_get_contents($root_sys.'web/css/themes/'.$theme.'/images/header-logo.png'));
  133. $bgImage = base64_encode(file_get_contents("$root_sys/main/img/bg_space.png"));
  134. $bgMoon = base64_encode(file_get_contents("$root_sys/main/img/bg_moon_two.png"));
  135. $installChamiloImage = "data:image/png;base64,".base64_encode(file_get_contents("$root_sys/main/img/mr_chamilo_install.png"));
  136. $global_error_message['mr_chamilo'] = $installChamiloImage;
  137. if ($global_error_code == 2) {
  138. $global_error_message_page =
  139. <<<EOM
  140. <!DOCTYPE html>
  141. <html>
  142. <head>
  143. <title>{TITLE}</title>
  144. <meta charset="{ENCODING}" />
  145. <style>
  146. $css_def
  147. html, body {min-height:100%; padding:0; margin:0;}
  148. #wrapper {padding:0; position:absolute; top:0; bottom:0; left:0; right:0;}
  149. @keyframes animatedBackground {
  150. from { background-position: 0 0; }
  151. to { background-position: 100% 0; }
  152. }
  153. @-webkit-keyframes animatedBackground {
  154. from { background-position: 0 0; }
  155. to { background-position: 100% 0; }
  156. }
  157. @-ms-keyframes animatedBackground {
  158. from { background-position: 0 0; }
  159. to { background-position: 100% 0; }
  160. }
  161. @-moz-keyframes animatedBackground {
  162. from { background-position: 0 0; }
  163. to { background-position: 100% 0; }
  164. }
  165. .install-home{
  166. background-image: url("data:image/png;base64,$bgImage");
  167. background-position: 0px 0px;
  168. background-repeat: repeat;
  169. animation: animatedBackground 40s linear infinite;
  170. -ms-animation: animatedBackground 40s linear infinite;
  171. -moz-animation: animatedBackground 40s linear infinite;
  172. -webkit-animation: animatedBackground 40s linear infinite;
  173. }
  174. .installer{
  175. background: url("data:image/png;base64,$bgMoon") no-repeat center 390px;
  176. }
  177. .avatar{
  178. text-align: center;
  179. }
  180. .avatar .img-responsive{
  181. display: initial;
  182. }
  183. .office{
  184. padding: 10px 20px;
  185. //background-color: rgba(35, 40, 56, 0.7);
  186. background-color: rgba(0, 22, 48, 0.8);
  187. border-radius: 5px;
  188. }
  189. @media (max-width: 480px) {
  190. .download-info .btn-success{
  191. margin-top: 10px;
  192. }
  193. }
  194. </style>
  195. </head>
  196. <body class="install-home">
  197. <div id="wrapper" class="installer">
  198. <header>
  199. <div class="container">
  200. <div class="row">
  201. <div class="col-md-12">
  202. <div class="logo">
  203. <img src="{CHAMILO_LOGO}"/>
  204. </div>
  205. </div>
  206. </div>
  207. </div>
  208. </header>
  209. <div id="content">
  210. <div class="container">
  211. <div class="welcome-install">
  212. <div class="avatar">
  213. <img class="img-responsive" src="{MR_CHAMILO}"/>
  214. </div>
  215. <div class="row">
  216. <div class="col-md-12">
  217. <div class="office">
  218. <p class="text">
  219. {DESCRIPTION}
  220. {CODE}
  221. </p>
  222. </div>
  223. </div>
  224. </div>
  225. </div>
  226. </div>
  227. </div>
  228. </div>
  229. </body>
  230. </html>
  231. EOM;
  232. } else {
  233. $global_error_message_page =
  234. <<<EOM
  235. <!DOCTYPE html>
  236. <html>
  237. <head>
  238. <title>{TITLE}</title>
  239. <meta charset="{ENCODING}" />
  240. <style>
  241. $css_def
  242. </style>
  243. </head>
  244. <body>
  245. <div id="page-error">
  246. <div class="page-wrap">
  247. <header>
  248. <div class="container">
  249. <div class="row">
  250. <div class="col-md-12">
  251. <div class="logo">
  252. <img src="{CHAMILO_LOGO}"/>
  253. </div>
  254. </div>
  255. </div>
  256. </div>
  257. </header>
  258. <section id="menu-bar">
  259. <nav class="navbar navbar-default">
  260. <div class="container">
  261. <div class="navbar-header">
  262. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#menuone" aria-expanded="false">
  263. <span class="sr-only">Toggle navigation</span>
  264. <span class="icon-bar"></span>
  265. <span class="icon-bar"></span>
  266. <span class="icon-bar"></span>
  267. </button>
  268. </div>
  269. <div class="collapse navbar-collapse" id="menuone">
  270. <ul class="nav navbar-nav">
  271. <li id="current" class="active tab-homepage"><a href="#" target="_self">Homepage</a></li>
  272. </ul>
  273. </div>
  274. </div>
  275. </nav>
  276. </section>
  277. <section id="content-error">
  278. <div class="container">
  279. <div class="panel panel-default">
  280. <div class="panel-body">
  281. <div class="alert alert-danger" role="alert">
  282. {DESCRIPTION}
  283. {CODE}
  284. </div>
  285. </div>
  286. </div>
  287. </div>
  288. </section>
  289. </div>
  290. </div>
  291. </body>
  292. </html>
  293. EOM;
  294. }
  295. foreach ($global_error_message as $key => $value) {
  296. $global_error_message_page = str_replace('{'.strtoupper($key).'}', $value, $global_error_message_page);
  297. }
  298. header('Content-Type: text/html; charset='.$global_error_message['encoding']);
  299. die($global_error_message_page);
  300. }