-
Notifications
You must be signed in to change notification settings - Fork 468
/
install.lib.php
executable file
·2728 lines (2469 loc) · 109 KB
/
install.lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* For licensing terms, see /license.txt */
/**
* Chamilo LMS
* This file contains functions used by the install and upgrade scripts.
*
* Ideas for future additions:
* - a function get_old_version_settings to retrieve the config file settings
* of older versions before upgrading.
*/
use Doctrine\ORM\EntityManager;
use Chamilo\CoreBundle\Entity\ExtraField;
use Chamilo\CoreBundle\Entity\ExtraFieldOptions;
use Chamilo\CoreBundle\Entity\ExtraFieldValues;
/* CONSTANTS */
define('SYSTEM_CONFIG_FILENAME', 'configuration.dist.php');
/**
* This function detects whether the system has been already installed.
* It should be used for prevention from second running the installation
* script and as a result - destroying a production system.
* @return bool The detected result;
* @author Ivan Tcholakov, 2010;
*/
function isAlreadyInstalledSystem()
{
global $new_version, $_configuration;
if (empty($new_version)) {
return true; // Must be initialized.
}
$current_config_file = api_get_path(CONFIGURATION_PATH).'configuration.php';
if (!file_exists($current_config_file)) {
return false; // Configuration file does not exist, install the system.
}
require $current_config_file;
$current_version = null;
if (isset($_configuration['system_version'])) {
$current_version = trim($_configuration['system_version']);
}
// If the current version is old, upgrading is assumed, the installer goes ahead.
return empty($current_version) ? false : version_compare($current_version, $new_version, '>=');
}
/**
* This function checks if a php extension exists or not and returns an HTML status string.
*
* @param string $extensionName Name of the PHP extension to be checked
* @param string $returnSuccess Text to show when extension is available (defaults to 'Yes')
* @param string $returnFailure Text to show when extension is available (defaults to 'No')
* @param boolean $optional Whether this extension is optional (then show unavailable text in orange rather than red)
* @return string HTML string reporting the status of this extension. Language-aware.
* @author Christophe Gesch??
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @author Yannick Warnier <yannick.warnier@dokeos.com>
*/
function checkExtension($extensionName, $returnSuccess = 'Yes', $returnFailure = 'No', $optional = false)
{
if (extension_loaded($extensionName)) {
return Display::label($returnSuccess, 'success');
} else {
if ($optional) {
return Display::label($returnFailure, 'warning');
} else {
return Display::label($returnFailure, 'important');
}
}
}
/**
* This function checks whether a php setting matches the recommended value
* @param string $phpSetting A PHP setting to check
* @param string $recommendedValue A recommended value to show on screen
* @param mixed $returnSuccess What to show on success
* @param mixed $returnFailure What to show on failure
* @return string A label to show
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*/
function checkPhpSetting($phpSetting, $recommendedValue, $returnSuccess = false, $returnFailure = false)
{
$currentPhpValue = getPhpSetting($phpSetting);
if ($currentPhpValue == $recommendedValue) {
return Display::label($currentPhpValue.' '.$returnSuccess, 'success');
} else {
return Display::label($currentPhpValue.' '.$returnSuccess, 'important');
}
}
/**
* This function return the value of a php.ini setting if not "" or if exists,
* otherwise return false
* @param string $phpSetting The name of a PHP setting
* @return mixed The value of the setting, or false if not found
*/
function checkPhpSettingExists($phpSetting)
{
if (ini_get($phpSetting) != "") {
return ini_get($phpSetting);
}
return false;
}
/**
* Returns a textual value ('ON' or 'OFF') based on a requester 2-state ini- configuration setting.
*
* @param string $val a php ini value
* @return boolean: ON or OFF
* @author Joomla <http://www.joomla.org>
*/
function getPhpSetting($val)
{
return ini_get($val) == '1' ? 'ON' : 'OFF';
}
/**
* This function returns a string "true" or "false" according to the passed parameter.
*
* @param integer $var The variable to present as text
* @return string the string "true" or "false"
* @author Christophe Gesch??
*/
function trueFalse($var)
{
return $var ? 'true' : 'false';
}
/**
* Removes memory and time limits as much as possible.
*/
function remove_memory_and_time_limits()
{
if (function_exists('ini_set')) {
ini_set('memory_limit', -1);
ini_set('max_execution_time', 0);
error_log('Update-db script: memory_limit set to -1', 0);
error_log('Update-db script: max_execution_time 0', 0);
} else {
error_log('Update-db script: could not change memory and time limits', 0);
}
}
/**
* Detects browser's language.
* @return string Returns a language identificator, i.e. 'english', 'spanish', ...
* @author Ivan Tcholakov, 2010
*/
function detect_browser_language()
{
static $language_index = array(
'ar' => 'arabic',
'ast' => 'asturian',
'bg' => 'bulgarian',
'bs' => 'bosnian',
'ca' => 'catalan',
'zh' => 'simpl_chinese',
'zh-tw' => 'trad_chinese',
'cs' => 'czech',
'da' => 'danish',
'prs' => 'dari',
'de' => 'german',
'el' => 'greek',
'en' => 'english',
'es' => 'spanish',
'eo' => 'esperanto',
'eu' => 'basque',
'fa' => 'persian',
'fr' => 'french',
'fur' => 'friulian',
'gl' => 'galician',
'ka' => 'georgian',
'hr' => 'croatian',
'he' => 'hebrew',
'hi' => 'hindi',
'id' => 'indonesian',
'it' => 'italian',
'ko' => 'korean',
'lv' => 'latvian',
'lt' => 'lithuanian',
'mk' => 'macedonian',
'hu' => 'hungarian',
'ms' => 'malay',
'nl' => 'dutch',
'ja' => 'japanese',
'no' => 'norwegian',
'oc' => 'occitan',
'ps' => 'pashto',
'pl' => 'polish',
'pt' => 'portuguese',
'pt-br' => 'brazilian',
'ro' => 'romanian',
'qu' => 'quechua_cusco',
'ru' => 'russian',
'sk' => 'slovak',
'sl' => 'slovenian',
'sr' => 'serbian',
'fi' => 'finnish',
'sv' => 'swedish',
'th' => 'thai',
'tr' => 'turkish',
'uk' => 'ukrainian',
'vi' => 'vietnamese',
'sw' => 'swahili',
'yo' => 'yoruba'
);
$system_available_languages = & get_language_folder_list();
$accept_languages = strtolower(str_replace('_', '-', $_SERVER['HTTP_ACCEPT_LANGUAGE']));
foreach ($language_index as $code => $language) {
if (strpos($accept_languages, $code) === 0) {
if (!empty($system_available_languages[$language])) {
return $language;
}
}
}
$user_agent = strtolower(str_replace('_', '-', $_SERVER['HTTP_USER_AGENT']));
foreach ($language_index as $code => $language) {
if (@preg_match("/[\[\( ]{$code}[;,_\-\)]/", $user_agent)) {
if (!empty($system_available_languages[$language])) {
return $language;
}
}
}
return 'english';
}
/* FILESYSTEM RELATED FUNCTIONS */
/**
* This function checks if the given folder is writable
* @param string $folder Full path to a folder
* @param bool $suggestion Whether to show a suggestion or not
* @return string
*/
function check_writable($folder, $suggestion = false)
{
if (is_writable($folder)) {
return Display::label(get_lang('Writable'), 'success');
} else {
if ($suggestion) {
return Display::label(get_lang('NotWritable'), 'info');
} else {
return Display::label(get_lang('NotWritable'), 'important');
}
}
}
/**
* This function checks if the given folder is readable
* @param string $folder Full path to a folder
* @param bool $suggestion Whether to show a suggestion or not
*
* @return string
*/
function checkReadable($folder, $suggestion = false)
{
if (is_readable($folder)) {
return Display::label(get_lang('Readable'), 'success');
} else {
if ($suggestion) {
return Display::label(get_lang('NotReadable'), 'info');
} else {
return Display::label(get_lang('NotReadable'), 'important');
}
}
}
/**
* This function is similar to the core file() function, except that it
* works with line endings in Windows (which is not the case of file())
* @param string $filename
*
* @return array The lines of the file returned as an array
*/
function file_to_array($filename)
{
if (!is_readable($filename) || is_dir($filename)) {
return array();
}
$fp = fopen($filename, 'rb');
$buffer = fread($fp, filesize($filename));
fclose($fp);
return explode('<br />', nl2br($buffer));
}
/**
* We assume this function is called from install scripts that reside inside the install folder.
*/
function set_file_folder_permissions()
{
@chmod('.', 0755); //set permissions on install dir
@chmod('..', 0755); //set permissions on parent dir of install dir
}
/**
* Add's a .htaccess file to the courses directory
* @param string $url_append The path from your webroot to your chamilo root
* @return bool Result of writing the file
*/
/*function write_courses_htaccess_file($url_append)
{
$content = file_get_contents(dirname(__FILE__).'/'.COURSES_HTACCESS_FILENAME);
$content = str_replace('{CHAMILO_URL_APPEND_PATH}', $url_append, $content);
$fp = @fopen(api_get_path(SYS_COURSE_PATH).'.htaccess', 'w');
if ($fp) {
fwrite($fp, $content);
return fclose($fp);
}
return false;
}*/
/**
* Write the main system config file
* @param string $path Path to the config file
*/
function write_system_config_file($path)
{
global $dbHostForm;
global $dbPortForm;
global $dbUsernameForm;
global $dbPassForm;
global $dbNameForm;
global $urlForm;
global $pathForm;
global $urlAppendPath;
global $languageForm;
global $encryptPassForm;
global $session_lifetime;
global $new_version;
global $new_version_stable;
$root_sys = api_add_trailing_slash(str_replace('\\', '/', realpath($pathForm)));
$content = file_get_contents(dirname(__FILE__).'/'.SYSTEM_CONFIG_FILENAME);
$config['{DATE_GENERATED}'] = date('r');
$config['{DATABASE_HOST}'] = $dbHostForm;
$config['{DATABASE_PORT}'] = $dbPortForm;
$config['{DATABASE_USER}'] = $dbUsernameForm;
$config['{DATABASE_PASSWORD}'] = $dbPassForm;
$config['{DATABASE_MAIN}'] = $dbNameForm;
$config['{ROOT_WEB}'] = $urlForm;
$config['{ROOT_SYS}'] = $root_sys;
$config['{URL_APPEND_PATH}'] = $urlAppendPath;
$config['{PLATFORM_LANGUAGE}'] = $languageForm;
$config['{SECURITY_KEY}'] = md5(uniqid(rand().time()));
$config['{ENCRYPT_PASSWORD}'] = $encryptPassForm;
$config['SESSION_LIFETIME'] = $session_lifetime;
$config['{NEW_VERSION}'] = $new_version;
$config['NEW_VERSION_STABLE'] = trueFalse($new_version_stable);
foreach ($config as $key => $value) {
$content = str_replace($key, $value, $content);
}
$fp = @ fopen($path, 'w');
if (!$fp) {
echo '<strong><font color="red">Your script doesn\'t have write access to the config directory</font></strong><br />
<em>('.str_replace('\\', '/', realpath($path)).')</em><br /><br />
You probably do not have write access on Chamilo root directory,
i.e. you should <em>CHMOD 777</em> or <em>755</em> or <em>775</em>.<br /><br />
Your problems can be related on two possible causes:<br />
<ul>
<li>Permission problems.<br />Try initially with <em>chmod -R 777</em> and increase restrictions gradually.</li>
<li>PHP is running in <a href="http://www.php.net/manual/en/features.safe-mode.php" target="_blank">Safe-Mode</a>. If possible, try to switch it off.</li>
</ul>
<a href="http://forum.chamilo.org/" target="_blank">Read about this problem in Support Forum</a><br /><br />
Please go back to step 5.
<p><input type="submit" name="step5" value="< Back" /></p>
</td></tr></table></form></body></html>';
exit;
}
fwrite($fp, $content);
fclose($fp);
}
/**
* Returns a list of language directories.
*/
function & get_language_folder_list()
{
static $result;
if (!is_array($result)) {
$result = array();
$exceptions = array('.', '..', 'CVS', '.svn');
$search = array('_latin', '_unicode', '_corporate', '_org' , '_KM', '_');
$replace_with = array(' (Latin)', ' (unicode)', ' (corporate)', ' (org)', ' (KM)', ' ');
$dirname = api_get_path(SYS_LANG_PATH);
$handle = opendir($dirname);
while ($entries = readdir($handle)) {
if (in_array($entries, $exceptions)) {
continue;
}
if (is_dir($dirname.$entries)) {
if (is_file($dirname.$entries.'/install_disabled')) {
// Skip all languages that have this file present, just for
// the install process (languages incomplete)
continue;
}
$result[$entries] = ucwords(str_replace($search, $replace_with, $entries));
}
}
closedir($handle);
asort($result);
}
return $result;
}
/**
* TODO: my_directory_to_array() - maybe within the main API there is already a suitable function?
* @param string $directory Full path to a directory
* @return array A list of files and dirs in the directory
*/
function my_directory_to_array($directory)
{
$array_items = array();
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($directory. "/" . $file)) {
$array_items = array_merge($array_items, my_directory_to_array($directory. '/' . $file));
$file = $directory . "/" . $file;
$array_items[] = preg_replace("/\/\//si", '/', $file);
}
}
}
closedir($handle);
}
return $array_items;
}
/**
* This function returns the value of a parameter from the configuration file
*
* WARNING - this function relies heavily on global variables $updateFromConfigFile
* and $configFile, and also changes these globals. This can be rewritten.
*
* @param string $param the parameter of which the value is returned
* @param string If we want to give the path rather than take it from POST
* @return string the value of the parameter
* @author Olivier Brouckaert
* @author Reworked by Ivan Tcholakov, 2010
*/
function get_config_param($param, $updatePath = '')
{
global $configFile, $updateFromConfigFile;
// Look if we already have the queried parameter.
if (is_array($configFile) && isset($configFile[$param])) {
return $configFile[$param];
}
if (empty($updatePath) && !empty($_POST['updatePath'])) {
$updatePath = $_POST['updatePath'];
}
if (empty($updatePath)) {
$updatePath = api_get_path(SYS_PATH);
}
$updatePath = api_add_trailing_slash(str_replace('\\', '/', realpath($updatePath)));
$updateFromInstalledVersionFile = '';
if (empty($updateFromConfigFile)) {
// If update from previous install was requested,
// try to recover config file from Chamilo 1.9.x
if (file_exists($updatePath.'main/inc/conf/configuration.php')) {
$updateFromConfigFile = 'main/inc/conf/configuration.php';
} else {
// Give up recovering.
//error_log('Chamilo Notice: Could not find previous config file at '.$updatePath.'main/inc/conf/configuration.php nor at '.$updatePath.'claroline/inc/conf/claro_main.conf.php in get_config_param(). Will start new config (in '.__FILE__.', line '.__LINE__.')', 0);
return null;
}
}
if (file_exists($updatePath.$updateFromConfigFile) &&
!is_dir($updatePath.$updateFromConfigFile)
) {
require $updatePath.$updateFromConfigFile;
$config = new Zend\Config\Config($_configuration);
return $config->get($param);
}
error_log('Config array could not be found in get_config_param()', 0);
return null;
/*if (file_exists($updatePath.$updateFromConfigFile)) {
return $val;
} else {
error_log('Config array could not be found in get_config_param()', 0);
return null;
}*/
}
/* DATABASE RELATED FUNCTIONS */
/**
* Gets a configuration parameter from the database. Returns returns null on failure.
* @param string $param Name of param we want
* @return mixed The parameter value or null if not found
*/
function get_config_param_from_db($param = '')
{
if (($res = Database::query("SELECT * FROM settings_current WHERE variable = '$param'")) !== false) {
if (Database::num_rows($res) > 0) {
$row = Database::fetch_array($res);
return $row['selected_value'];
}
}
return null;
}
/**
* Connect to the database and returns the entity manager
* @param string $dbHostForm DB host
* @param string $dbUsernameForm DB username
* @param string $dbPassForm DB password
* @param string $dbNameForm DB name
* @param int $dbPortForm DB port
*
* @return EntityManager
*/
function connectToDatabase($dbHostForm, $dbUsernameForm, $dbPassForm, $dbNameForm, $dbPortForm = 3306)
{
$dbParams = array(
'driver' => 'pdo_mysql',
'host' => $dbHostForm,
'port' => $dbPortForm,
'user' => $dbUsernameForm,
'password' => $dbPassForm,
'dbname' => $dbNameForm
);
$database = new \Database();
$database->connect($dbParams);
return $database->getManager();
}
/* DISPLAY FUNCTIONS */
/**
* This function prints class=active_step $current_step=$param
* @param int $param A step in the installer process
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*/
function step_active($param)
{
global $current_step;
if ($param == $current_step) {
echo 'class="current-step" ';
}
}
/**
* This function displays the Step X of Y -
* @return string String that says 'Step X of Y' with the right values
*/
function display_step_sequence()
{
global $current_step;
return get_lang('Step'.$current_step).' – ';
}
/**
* Displays a drop down box for selection the preferred language.
*/
function display_language_selection_box($name = 'language_list', $default_language = 'english')
{
// Reading language list.
$language_list = get_language_folder_list();
/*
// Reduction of the number of languages shown. Enable this fragment of code for customization purposes.
// Modify the language list according to your preference. Don't exclude the 'english' item.
$language_to_display = array('asturian', 'bulgarian', 'english', 'italian', 'french', 'slovenian', 'slovenian_unicode', 'spanish');
foreach ($language_list as $key => & $value) {
if (!in_array($key, $language_to_display)) {
unset($language_list[$key]);
}
}
*/
// Sanity checks due to the possibility for customizations.
if (!is_array($language_list) || empty($language_list)) {
$language_list = array('english' => 'English');
}
// Sorting again, if it is necessary.
//asort($language_list);
// More sanity checks.
if (!array_key_exists($default_language, $language_list)) {
if (array_key_exists('english', $language_list)) {
$default_language = 'english';
} else {
$language_keys = array_keys($language_list);
$default_language = $language_keys[0];
}
}
// Displaying the box.
$html = '';
$html .= "\t\t<select class='selectpicker show-tick' name=\"$name\">\n";
foreach ($language_list as $key => $value) {
if ($key == $default_language) {
$option_end = ' selected="selected">';
} else {
$option_end = '>';
}
$html .= "\t\t\t<option value=\"$key\"$option_end";
$html .= $value;
$html .= "</option>\n";
}
$html .= "\t\t</select>\n";
return $html;
}
/**
* This function displays a language dropdown box so that the installatioin
* can be done in the language of the user
*/
function display_language_selection()
{ ?>
<h2><?php get_lang('WelcomeToTheChamiloInstaller'); ?></h2>
<div class="RequirementHeading">
<h2><?php echo display_step_sequence(); ?>
<?php echo get_lang('InstallationLanguage');?>
</h2>
<p><?php echo get_lang('PleaseSelectInstallationProcessLanguage'); ?>:</p>
<form id="lang_form" method="post" action="<?php echo api_get_self(); ?>">
<div class="form-group">
<div class="col-sm-4">
<?php echo display_language_selection_box('language_list', api_get_interface_language()); ?>
</div>
<div class="col-sm-6">
<button type="submit" name="step1" class="btn btn-success" value="<?php echo get_lang('Next'); ?>">
<em class="fa fa-forward"> </em>
<?php echo get_lang('Next'); ?></button>
</div>
</div>
<input type="hidden" name="is_executable" id="is_executable" value="-" />
</form>
</div>
<div class="RequirementHeading">
<?php echo get_lang('YourLanguageNotThereContactUs'); ?>
</div>
<?php
}
/**
* This function displays the requirements for installing Chamilo.
*
* @param string $installType
* @param boolean $badUpdatePath
* @param boolean $badUpdatePath
* @param string $updatePath The updatePath given (if given)
* @param array $update_from_version_8 The different subversions from version 1.9
*
* @author unknow
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*/
function display_requirements(
$installType,
$badUpdatePath,
$updatePath = '',
$update_from_version_8 = array()
) {
global $_setting;
echo '<div class="RequirementHeading"><h2>'.display_step_sequence().get_lang('Requirements')."</h2></div>";
echo '<div class="RequirementText">';
echo '<strong>'.get_lang('ReadThoroughly').'</strong><br />';
echo get_lang('MoreDetails').' <a href="../../documentation/installation_guide.html" target="_blank">'.get_lang('ReadTheInstallationGuide').'</a>.<br />'."\n";
if ($installType == 'update') {
echo get_lang('IfYouPlanToUpgradeFromOlderVersionYouMightWantToHaveAlookAtTheChangelog').'<br />';
}
echo '</div>';
// SERVER REQUIREMENTS
echo '<div class="RequirementHeading"><h4>'.get_lang('ServerRequirements').'</h4>';
$timezone = checkPhpSettingExists("date.timezone");
if (!$timezone) {
echo "<div class='warning-message'>".
Display::return_icon('warning.png', get_lang('Warning'), '', ICON_SIZE_MEDIUM).
get_lang("DateTimezoneSettingNotSet")."</div>";
}
echo '<div class="RequirementText">'.get_lang('ServerRequirementsInfo').'</div>';
echo '<div class="RequirementContent">';
echo '<table class="table">
<tr>
<td class="requirements-item">'.get_lang('PHPVersion').' >= '.REQUIRED_PHP_VERSION.'</td>
<td class="requirements-value">';
if (phpversion() < REQUIRED_PHP_VERSION) {
echo '<strong><font color="red">'.get_lang('PHPVersionError').'</font></strong>';
} else {
echo '<strong><font color="green">'.get_lang('PHPVersionOK'). ' '.phpversion().'</font></strong>';
}
echo '</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/en/book.session.php" target="_blank">Session</a> '.get_lang('support').'</td>
<td class="requirements-value">'.checkExtension('session', get_lang('Yes'), get_lang('ExtensionSessionsNotAvailable')).'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/en/book.mysql.php" target="_blank">MySQL</a> '.get_lang('support').'</td>
<td class="requirements-value">'.checkExtension('mysql', get_lang('Yes'), get_lang('ExtensionMySQLNotAvailable')).'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/en/book.zlib.php" target="_blank">Zlib</a> '.get_lang('support').'</td>
<td class="requirements-value">'.checkExtension('zlib', get_lang('Yes'), get_lang('ExtensionZlibNotAvailable')).'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/en/book.pcre.php" target="_blank">Perl-compatible regular expressions</a> '.get_lang('support').'</td>
<td class="requirements-value">'.checkExtension('pcre', get_lang('Yes'), get_lang('ExtensionPCRENotAvailable')).'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/en/book.xml.php" target="_blank">XML</a> '.get_lang('support').'</td>
<td class="requirements-value">'.checkExtension('xml', get_lang('Yes'), get_lang('No')).'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/en/book.intl.php" target="_blank">Internationalization</a> '.get_lang('support').'</td>
<td class="requirements-value">'.checkExtension('intl', get_lang('Yes'), get_lang('No')).'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/en/book.json.php" target="_blank">JSON</a> '.get_lang('support').'</td>
<td class="requirements-value">'.checkExtension('json', get_lang('Yes'), get_lang('No')).'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/en/book.image.php" target="_blank">GD</a> '.get_lang('support').'</td>
<td class="requirements-value">'.checkExtension('gd', get_lang('Yes'), get_lang('ExtensionGDNotAvailable')).'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/en/book.curl.php" target="_blank">cURL</a>'.get_lang('support').'</td>
<td class="requirements-value">'.checkExtension('curl', get_lang('Yes'), get_lang('No')).'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/en/book.mbstring.php" target="_blank">Multibyte string</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
<td class="requirements-value">'.checkExtension('mbstring', get_lang('Yes'), get_lang('ExtensionMBStringNotAvailable'), true).'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/en/book.iconv.php" target="_blank">Iconv</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
<td class="requirements-value">'.checkExtension('iconv', get_lang('Yes'), get_lang('No'), true).'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/en/book.ldap.php" target="_blank">LDAP</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
<td class="requirements-value">'.checkExtension('ldap', get_lang('Yes'), get_lang('ExtensionLDAPNotAvailable'), true).'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://xapian.org/" target="_blank">Xapian</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
<td class="requirements-value">'.checkExtension('xapian', get_lang('Yes'), get_lang('No'), true).'</td>
</tr>
</table>';
echo '</div>';
echo '</div>';
// RECOMMENDED SETTINGS
// Note: these are the settings for Joomla, does this also apply for Chamilo?
// Note: also add upload_max_filesize here so that large uploads are possible
echo '<div class="RequirementHeading"><h4>'.get_lang('RecommendedSettings').'</h4>';
echo '<div class="RequirementText">'.get_lang('RecommendedSettingsInfo').'</div>';
echo '<div class="RequirementContent">';
echo '<table class="table">
<tr>
<th>'.get_lang('Setting').'</th>
<th>'.get_lang('Recommended').'</th>
<th>'.get_lang('Actual').'</th>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/features.safe-mode.php">Safe Mode</a></td>
<td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
<td class="requirements-value">'.checkPhpSetting('safe_mode', 'OFF').'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/ref.errorfunc.php#ini.display-errors">Display Errors</a></td>
<td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
<td class="requirements-value">'.checkPhpSetting('display_errors', 'OFF').'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.file-uploads">File Uploads</a></td>
<td class="requirements-recommended">'.Display::label('ON', 'success').'</td>
<td class="requirements-value">'.checkPhpSetting('file_uploads', 'ON').'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/ref.info.php#ini.magic-quotes-gpc">Magic Quotes GPC</a></td>
<td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
<td class="requirements-value">'.checkPhpSetting('magic_quotes_gpc', 'OFF').'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/ref.info.php#ini.magic-quotes-runtime">Magic Quotes Runtime</a></td>
<td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
<td class="requirements-value">'.checkPhpSetting('magic_quotes_runtime', 'OFF').'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/security.globals.php">Register Globals</a></td>
<td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
<td class="requirements-value">'.checkPhpSetting('register_globals', 'OFF').'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/ref.session.php#ini.session.auto-start">Session auto start</a></td>
<td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
<td class="requirements-value">'.checkPhpSetting('session.auto_start', 'OFF').'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.short-open-tag">Short Open Tag</a></td>
<td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
<td class="requirements-value">'.checkPhpSetting('short_open_tag', 'OFF').'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-httponly">Cookie HTTP Only</a></td>
<td class="requirements-recommended">'.Display::label('ON', 'success').'</td>
<td class="requirements-value">'.checkPhpSetting('session.cookie_httponly', 'ON').'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.upload-max-filesize">Maximum upload file size</a></td>
<td class="requirements-recommended">'.Display::label('>= '.REQUIRED_MIN_UPLOAD_MAX_FILESIZE.'M', 'success').'</td>
<td class="requirements-value">'.compare_setting_values(ini_get('upload_max_filesize'), REQUIRED_MIN_UPLOAD_MAX_FILESIZE).'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.post-max-size">Maximum post size</a></td>
<td class="requirements-recommended">'.Display::label('>= '.REQUIRED_MIN_POST_MAX_SIZE.'M', 'success').'</td>
<td class="requirements-value">'.compare_setting_values(ini_get('post_max_size'), REQUIRED_MIN_POST_MAX_SIZE).'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://www.php.net/manual/en/ini.core.php#ini.memory-limit">Memory Limit</a></td>
<td class="requirements-recommended">'.Display::label('>= '.REQUIRED_MIN_MEMORY_LIMIT.'M', 'success').'</td>
<td class="requirements-value">'.compare_setting_values(ini_get('memory_limit'), REQUIRED_MIN_MEMORY_LIMIT).'</td>
</tr>
</table>';
echo ' </div>';
echo '</div>';
// DIRECTORY AND FILE PERMISSIONS
echo '<div class="RequirementHeading"><h4>'.get_lang('DirectoryAndFilePermissions').'</h4>';
echo '<div class="RequirementText">'.get_lang('DirectoryAndFilePermissionsInfo').'</div>';
echo '<div class="RequirementContent">';
$course_attempt_name = '__XxTestxX__';
$course_dir = api_get_path(SYS_COURSE_PATH).$course_attempt_name;
//Just in case
@unlink($course_dir.'/test.php');
@rmdir($course_dir);
$perms_dir = array(0777, 0755, 0775, 0770, 0750, 0700);
$perms_fil = array(0666, 0644, 0664, 0660, 0640, 0600);
$course_test_was_created = false;
$dir_perm_verified = 0777;
foreach ($perms_dir as $perm) {
$r = @mkdir($course_dir, $perm);
if ($r === true) {
$dir_perm_verified = $perm;
$course_test_was_created = true;
break;
}
}
$fil_perm_verified = 0666;
$file_course_test_was_created = false;
if (is_dir($course_dir)) {
foreach ($perms_fil as $perm) {
if ($file_course_test_was_created == true) {
break;
}
$r = @touch($course_dir.'/test.php',$perm);
if ($r === true) {
$fil_perm_verified = $perm;
if (check_course_script_interpretation($course_dir, $course_attempt_name, 'test.php')) {
$file_course_test_was_created = true;
}
}
}
}
@unlink($course_dir.'/test.php');
@rmdir($course_dir);
$_SESSION['permissions_for_new_directories'] = $_setting['permissions_for_new_directories'] = $dir_perm_verified;
$_SESSION['permissions_for_new_files'] = $_setting['permissions_for_new_files'] = $fil_perm_verified;
$dir_perm = Display::label('0'.decoct($dir_perm_verified), 'info');
$file_perm = Display::label('0'.decoct($fil_perm_verified), 'info');
$courseTestLabel = Display::label(get_lang('No'), 'important');
if ($course_test_was_created && $file_course_test_was_created) {
$courseTestLabel = Display::label(get_lang('Yes'), 'success');
}
if ($course_test_was_created && !$file_course_test_was_created) {
$courseTestLabel = Display::label(
sprintf(
get_lang('InstallWarningCouldNotInterpretPHP'),
api_get_path(WEB_COURSE_PATH).$course_attempt_name.'/test.php'
),
'warning'
);
}
if (!$course_test_was_created && !$file_course_test_was_created) {
$courseTestLabel = Display::label(get_lang('No'), 'important');
}
$oldConf = '';
if (file_exists(api_get_path(SYS_CODE_PATH).'inc/conf/configuration.php')) {
$oldConf = '<tr>
<td class="requirements-item">'.api_get_path(SYS_CODE_PATH).'inc/conf</td>
<td class="requirements-value">'.check_writable(api_get_path(SYS_CODE_PATH).'inc/conf').'</td>
</tr>';
}
echo '<table class="table">
'.$oldConf.'
<tr>
<td class="requirements-item">'.api_get_path(SYS_APP_PATH).'</td>
<td class="requirements-value">'.check_writable(api_get_path(SYS_APP_PATH)).'</td>
</tr>
<tr>
<td class="requirements-item">'.api_get_path(SYS_CODE_PATH).'default_course_document/images/</td>
<td class="requirements-value">'.check_writable(api_get_path(SYS_CODE_PATH).'default_course_document/images/').'</td>
</tr>
<tr>
<td class="requirements-item">'.api_get_path(SYS_CODE_PATH).'lang/</td>
<td class="requirements-value">'.check_writable(api_get_path(SYS_CODE_PATH).'lang/', true).' <br />('.get_lang('SuggestionOnlyToEnableSubLanguageFeature').')</td>
</tr>
<tr>
<td class="requirements-item">'.api_get_path(SYS_PATH).'vendor/</td>
<td class="requirements-value">'.checkReadable(api_get_path(SYS_PATH).'vendor').'</td>
</tr>
<tr>
<td class="requirements-item">'.api_get_path(SYS_PUBLIC_PATH).'</td>
<td class="requirements-value">'.check_writable(api_get_path(SYS_PUBLIC_PATH)).'</td>
</tr>
<tr>
<td class="requirements-item">'.get_lang('CourseTestWasCreated').'</td>
<td class="requirements-value">'.$courseTestLabel.' </td>
</tr>
<tr>
<td class="requirements-item">'.get_lang('PermissionsForNewDirs').'</td>
<td class="requirements-value">'.$dir_perm.' </td>
</tr>
<tr>
<td class="requirements-item">'.get_lang('PermissionsForNewFiles').'</td>
<td class="requirements-value">'.$file_perm.' </td>
</tr>
';
echo ' </table>';
echo ' </div>';
echo '</div>';
if ($installType == 'update' && (empty($updatePath) || $badUpdatePath)) {
if ($badUpdatePath) { ?>
<div class="alert alert-warning">
<?php echo get_lang('Error'); ?>!<br />
Chamilo <?php echo implode('|', $update_from_version_8).' '.get_lang('HasNotBeenFoundInThatDir'); ?>.
</div>
<?php }
else {
echo '<br />';
}
?>
<div class="row">
<div class="col-md-12">
<p><?php echo get_lang('OldVersionRootPath'); ?>:
<input type="text" name="updatePath" size="50" value="<?php echo ($badUpdatePath && !empty($updatePath)) ? htmlentities($updatePath) : api_get_path(SYS_SERVER_ROOT_PATH).'old_version/'; ?>" />
</p>
<p>
<button type="submit" class="btn btn-default" name="step1" value="<?php echo get_lang('Back'); ?>" >
<em class="fa fa-backward"> <?php echo get_lang('Back'); ?></em>
</button>
<input type="hidden" name="is_executable" id="is_executable" value="-" />
<button type="submit" class="btn btn-success" name="<?php echo (isset($_POST['step2_update_6']) ? 'step2_update_6' : 'step2_update_8'); ?>" value="<?php echo get_lang('Next'); ?> >" >
<em class="fa fa-forward"> </em> <?php echo get_lang('Next'); ?>
</button>
</p>
</div>
</div>
<?php
} else {
$error = false;