forked from CiviCRM42/civicrm42-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
1207 lines (1038 loc) · 42.6 KB
/
index.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
/**
* Note that this installer has been based of the SilverStripe installer.
* You can get more information from the SilverStripe Website at
* http://www.silverstripe.com/. Please check
* http://www.silverstripe.com/licensing for licensing details.
*
* Copyright (c) 2006-7, SilverStripe Limited - www.silverstripe.com
* All rights reserved.
*
* Changes and modifications (c) 2007-8 by CiviCRM LLC
*
*/
/**
* CiviCRM Installer
*/
ini_set('max_execution_time', 3000);
if (stristr(PHP_OS, 'WIN')) {
define('CIVICRM_DIRECTORY_SEPARATOR', '/');
define('CIVICRM_WINDOWS', 1 );
}
else {
define('CIVICRM_DIRECTORY_SEPARATOR', DIRECTORY_SEPARATOR);
define('CIVICRM_WINDOWS', 0 );
}
// set installation type - drupal
if (!session_id()) {
session_start();
}
// unset civicrm session if any
if (array_key_exists('CiviCRM', $_SESSION)) {
unset($_SESSION['CiviCRM']);
}
if (isset($_GET['civicrm_install_type'])) {
$_SESSION['civicrm_install_type'] = $_GET['civicrm_install_type'];
}
else {
if (!isset($_SESSION['civicrm_install_type'])) {
$_SESSION['civicrm_install_type'] = "drupal";
}
}
global $installType;
$installType = strtolower($_SESSION['civicrm_install_type']);
if (!in_array($installType, array(
'drupal', 'wordpress'))) {
$errorTitle = "Oops! Unsupported installation mode";
$errorMsg = "";
errorDisplayPage($errorTitle, $errorMsg);
}
global $crmPath;
global $installDirPath;
global $installURLPath;
if ($installType == 'drupal') {
$crmPath = dirname(dirname($_SERVER['SCRIPT_FILENAME']));
$installDirPath = $installURLPath = '';
}
elseif ($installType == 'wordpress') {
$crmPath = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR;
$installDirPath = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR;
$installURLPath = WP_PLUGIN_URL . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR;
}
set_include_path(get_include_path() . PATH_SEPARATOR . $crmPath);
require_once $crmPath . '/CRM/Core/ClassLoader.php';
CRM_Core_ClassLoader::singleton()->register();
$docLink = CRM_Utils_System::docURL2('Installation and Upgrades', FALSE, 'Installation Guide',NULL,NULL,"wiki");
if ($installType == 'drupal') {
//lets check only /modules/.
$pattern = '/' . preg_quote(CIVICRM_DIRECTORY_SEPARATOR . 'modules', CIVICRM_DIRECTORY_SEPARATOR) . '/';
if (!preg_match($pattern,
str_replace("\\", "/", $_SERVER['SCRIPT_FILENAME'])
)) {
$errorTitle = "Oops! Please Correct Your Install Location";
$errorMsg = "Please untar (uncompress) your downloaded copy of CiviCRM in the <strong>" . implode(CIVICRM_DIRECTORY_SEPARATOR, array(
'sites', 'all', 'modules')) . "</strong> directory below your Drupal root directory. Refer to the online " . $docLink . " for more information.";
errorDisplayPage($errorTitle, $errorMsg);
}
}
// Load civicrm database config
if (isset($_REQUEST['mysql'])) {
$databaseConfig = $_REQUEST['mysql'];
}
else {
$databaseConfig = array(
"server" => "localhost",
"username" => "civicrm",
"password" => "",
"database" => "civicrm",
);
}
if ($installType == 'drupal') {
// Load drupal database config
if (isset($_REQUEST['drupal'])) {
$drupalConfig = $_REQUEST['drupal'];
}
else {
$drupalConfig = array(
"server" => "localhost",
"username" => "drupal",
"password" => "",
"database" => "drupal",
);
}
}
$loadGenerated = 0;
if (isset($_REQUEST['loadGenerated'])) {
$loadGenerated = 1;
}
require_once dirname(__FILE__) . CIVICRM_DIRECTORY_SEPARATOR . 'langs.php';
foreach ($langs as $locale => $_) {
if ($locale == 'en_US') {
continue;
}
if (!file_exists(implode(CIVICRM_DIRECTORY_SEPARATOR, array($crmPath, 'sql', "civicrm_data.$locale.mysql"))))unset($langs[$locale]);
}
$seedLanguage = 'en_US';
if (isset($_REQUEST['seedLanguage']) and isset($langs[$_REQUEST['seedLanguage']])) {
$seedLanguage = $_REQUEST['seedLanguage'];
}
global $cmsPath;
if ($installType == 'drupal') {
//CRM-6840 -don't force to install in sites/all/modules/
$object = new CRM_Utils_System_Drupal();
$cmsPath = $object->cmsRootPath();
$siteDir = getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']);
$alreadyInstalled = file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
'sites' . CIVICRM_DIRECTORY_SEPARATOR .
$siteDir . CIVICRM_DIRECTORY_SEPARATOR .
'civicrm.settings.php'
);
}
elseif ($installType == 'wordpress') {
$cmsPath = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'civicrm';
$alreadyInstalled = file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
'civicrm.settings.php'
);
}
// Exit with error if CiviCRM has already been installed.
if ($alreadyInstalled) {
$errorTitle = "Oops! CiviCRM is Already Installed";
if ($installType == 'drupal') {
$errorMsg = "CiviCRM has already been installed in this Drupal site. <ul><li>To <strong>start over</strong>, you must delete or rename the existing CiviCRM settings file - <strong>civicrm.settings.php</strong> - from <strong>" . implode(CIVICRM_DIRECTORY_SEPARATOR, array(
'[your Drupal root directory]', 'sites', $siteDir)) . "</strong>.</li><li>To <strong>upgrade an existing installation</strong>, refer to the online " . $docLink . ".</li></ul>";
}
elseif ($installType == 'wordpress') {
$errorMsg = "CiviCRM has already been installed in this WordPress site. <ul><li>To <strong>start over</strong>, you must delete or rename the existing CiviCRM settings file - <strong>civicrm.settings.php</strong> - from <strong>" . $cmsPath . "</strong>.</li><li>To <strong>upgrade an existing installation</strong>, refer to the online " . $docLink . ".</li></ul>";
}
errorDisplayPage($errorTitle, $errorMsg);
}
$versionFile = $crmPath . CIVICRM_DIRECTORY_SEPARATOR . 'civicrm-version.php';
if (file_exists($versionFile)) {
require_once ($versionFile);
$civicrm_version = civicrmVersion();
}
else {
$civicrm_version = 'unknown';
}
if ($installType == 'drupal') {
// Ensure that they have downloaded the correct version of CiviCRM
if ($civicrm_version['cms'] != 'Drupal' &&
$civicrm_version['cms'] != 'Drupal6'
) {
$errorTitle = "Oops! Incorrect CiviCRM Version";
$errorMsg = "This installer can only be used for the Drupal version of CiviCRM. Refer to the online " . $docLink . " for information about installing CiviCRM on PHP4 servers OR installing CiviCRM for Joomla!";
errorDisplayPage($errorTitle, $errorMsg);
}
define('DRUPAL_ROOT', $cmsPath);
$drupalVersionFiles = array(
// D6
implode(CIVICRM_DIRECTORY_SEPARATOR, array($cmsPath, 'modules', 'system', 'system.module')),
// D7
implode(CIVICRM_DIRECTORY_SEPARATOR, array($cmsPath, 'includes', 'bootstrap.inc')),
);
foreach ($drupalVersionFiles as $drupalVersionFile) {
if (file_exists($drupalVersionFile)) {
require_once $drupalVersionFile;
}
}
if (!defined('VERSION') or version_compare(VERSION, '6.0') < 0) {
$errorTitle = "Oops! Incorrect Drupal Version";
$errorMsg = "This version of CiviCRM can only be used with Drupal 6.x or 7.x. Please ensure that '" . implode("' or '", $drupalVersionFiles) . "' exists if you are running Drupal 7.0 and over. Refer to the online " . $docLink . " for information about installing CiviCRM.";
errorDisplayPage($errorTitle, $errorMsg);
}
}
elseif ($installType == 'wordpress') {
//HACK for now
$civicrm_version['cms'] = 'WordPress';
// Ensure that they have downloaded the correct version of CiviCRM
if ($civicrm_version['cms'] != 'WordPress') {
$errorTitle = "Oops! Incorrect CiviCRM Version";
$errorMsg = "This installer can only be used for the WordPress version of CiviCRM. Refer to the online " . $docLink . " for information about installing CiviCRM for Drupal or Joomla!";
errorDisplayPage($errorTitle, $errorMsg);
}
}
// Check requirements
$req = new InstallRequirements();
$req->check();
if ($req->hasErrors()) {
$hasErrorOtherThanDatabase = TRUE;
}
if ($databaseConfig) {
$dbReq = new InstallRequirements();
$dbReq->checkdatabase($databaseConfig, 'CiviCRM');
if ($installType == 'drupal') {
$dbReq->checkdatabase($drupalConfig, 'Drupal');
}
}
// Actual processor
if (isset($_REQUEST['go']) && !$req->hasErrors() && !$dbReq->hasErrors()) {
// Confirm before reinstalling
if (!isset($_REQUEST['force_reinstall']) && $alreadyInstalled) {
include ($installDirPath . 'template.html');
}
else {
$inst = new Installer();
$inst->install($_REQUEST);
}
// Show the config form
}
else {
include ($installDirPath . 'template.html');
}
/**
* This class checks requirements
* Each of the requireXXX functions takes an argument which gives a user description of the test. It's an array
* of 3 parts:
* $description[0] - The test catetgory
* $description[1] - The test title
* $description[2] - The test error to show, if it goes wrong
*/
class InstallRequirements {
var $errors, $warnings, $tests;
/**
* Just check that the database configuration is okay
*/
function checkdatabase($databaseConfig, $dbName) {
if ($this->requireFunction('mysql_connect',
array(
"PHP Configuration",
"MySQL support",
"MySQL support not included in PHP.",
)
)) {
$this->requireMySQLServer($databaseConfig['server'],
array(
"MySQL $dbName Configuration",
"Does the server exist",
"Can't find the a MySQL server on '$databaseConfig[server]'",
$databaseConfig['server'],
)
);
if ($this->requireMysqlConnection($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
array(
"MySQL $dbName Configuration",
"Are the access credentials correct",
"That username/password doesn't work",
)
)) {
@$this->requireMySQLVersion("5.1",
array(
"MySQL $dbName Configuration",
"MySQL version at least 5.1",
"MySQL version 5.1 or higher is required, you only have ",
"MySQL " . mysql_get_server_info(),
)
);
$this->requireMySQLAutoIncrementIncrementOne($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
array(
"MySQL $dbName Configuration",
"Is auto_increment_increment set to 1",
"An auto_increment_increment value greater than 1 is not currently supported. Please see issue CRM-7923 for further details and potential workaround.",
)
);
}
$onlyRequire = ($dbName == 'Drupal') ? TRUE : FALSE;
$this->requireDatabaseOrCreatePermissions(
$databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
array(
"MySQL $dbName Configuration",
"Can I access/create the database",
"I can't create new databases and the database '$databaseConfig[database]' doesn't exist",
),
$onlyRequire
);
if ($dbName != 'Drupal') {
$this->requireMySQLInnoDB($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
array(
"MySQL $dbName Configuration",
"Can I access/create InnoDB tables in the database",
"Unable to create InnoDB tables. MySQL InnoDB support is required for CiviCRM but is either not available or not enabled in this MySQL database server.",
)
);
$this->requireMySQLTempTables($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
array(
"MySQL $dbName Configuration",
'Can I create temporary tables in the database',
'Unable to create temporary tables. This MySQL user is missing the CREATE TEMPORARY TABLES privilege.',
)
);
$this->requireMySQLLockTables($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
array(
"MySQL $dbName Configuration",
'Can I create lock tables in the database',
'Unable to lock tables. This MySQL user is missing the LOCK TABLES privilege.',
)
);
}
}
}
/**
* Check everything except the database
*/
function check() {
global $crmPath, $installType;
$this->errors = NULL;
$this->requirePHPVersion('5.3.0', array("PHP Configuration", "PHP5 installed", NULL, "PHP version " . phpversion()));
// Check that we can identify the root folder successfully
$this->requireFile($crmPath . CIVICRM_DIRECTORY_SEPARATOR . 'README.txt',
array(
"File permissions",
"Does the webserver know where files are stored?",
"The webserver isn't letting me identify where files are stored.",
$this->getBaseDir(),
),
TRUE
);
// CRM-6485: make sure the path does not contain PATH_SEPARATOR, as we don’t know how to escape it
$this->requireNoPathSeparator(
array(
'File permissions',
'does the CiviCRM path contain PATH_SEPARATOR?',
'the ' . $this->getBaseDir() . ' path contains PATH_SEPARATOR (the ' . PATH_SEPARATOR . ' character)',
$this->getBaseDir(),
)
);
$requiredDirectories = array('CRM', 'packages', 'templates', 'js', 'api', 'i', 'sql');
foreach ($requiredDirectories as $dir) {
$this->requireFile($crmPath . CIVICRM_DIRECTORY_SEPARATOR . $dir,
array(
"File permissions", "$dir folder exists", "There is no $dir folder"), TRUE
);
}
$configIDSiniDir = NULL;
global $cmsPath;
if ($installType == 'drupal') {
$siteDir = getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']);
// make sure that we can write to sites/default and files/
$writableDirectories = array(
$cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
'sites' . CIVICRM_DIRECTORY_SEPARATOR .
$siteDir . CIVICRM_DIRECTORY_SEPARATOR .
'files',
$cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
'sites' . CIVICRM_DIRECTORY_SEPARATOR .
$siteDir,
);
}
elseif ($installType == 'wordpress') {
// make sure that we can write to plugins/civicrm and plugins/files/
$writableDirectories = array(WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'files', $cmsPath);
}
foreach ($writableDirectories as $dir) {
$dirName = CIVICRM_WINDOWS ? $dir : CIVICRM_DIRECTORY_SEPARATOR . $dir;
$this->requireWriteable($dirName,
array("File permissions", "Is the $dir folder writeable?", NULL),
TRUE
);
}
//check for Config.IDS.ini, file may exist in re-install
$configIDSiniDir = array($cmsPath, 'sites', $siteDir, 'files', 'civicrm', 'upload', 'Config.IDS.ini');
if (is_array($configIDSiniDir) && !empty($configIDSiniDir)) {
$configIDSiniFile = implode(CIVICRM_DIRECTORY_SEPARATOR, $configIDSiniDir);
if (file_exists($configIDSiniFile)) {
unlink($configIDSiniFile);
}
}
// Check for rewriting
if (isset($_SERVER['SERVER_SOFTWARE'])) {
$webserver = strip_tags(trim($_SERVER['SERVER_SOFTWARE']));
}
elseif (isset($_SERVER['SERVER_SIGNATURE'])) {
$webserver = strip_tags(trim($_SERVER['SERVER_SIGNATURE']));
}
if ($webserver == '') {
$webserver = "I can't tell what webserver you are running";
}
// Check for $_SERVER configuration
$this->requireServerVariables(array('SCRIPT_NAME', 'HTTP_HOST', 'SCRIPT_FILENAME'), array("Webserver config", "Recognised webserver", "You seem to be using an unsupported webserver. The server variables SCRIPT_NAME, HTTP_HOST, SCRIPT_FILENAME need to be set."));
// Check for MySQL support
$this->requireFunction('mysql_connect',
array("PHP Configuration", "MySQL support", "MySQL support not included in PHP.")
);
// Check for JSON support
$this->requireFunction('json_encode',
array("PHP Configuration", "JSON support", "JSON support not included in PHP.")
);
// Check for xcache_isset and emit warning if exists
$this->checkXCache(array(
"PHP Configuration",
"XCache compatibility",
"XCache is installed and there are known compatibility issues between XCache and CiviCRM. Consider using an alternative PHP caching mechanism or disable PHP caching altogether.",
));
// Check memory allocation
$this->requireMemory(32 * 1024 * 1024,
64 * 1024 * 1024,
array(
"PHP Configuration",
"Memory allocated (PHP config option 'memory_limit')",
"CiviCRM needs a minimum of 32M allocated to PHP, but recommends 64M.",
ini_get("memory_limit"),
)
);
return $this->errors;
}
function requireMemory($min, $recommended, $testDetails) {
$this->testing($testDetails);
$mem = $this->getPHPMemory();
if ($mem < $min && $mem > 0) {
$testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated";
$this->error($testDetails);
}
elseif ($mem < $recommended && $mem > 0) {
$testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated";
$this->warning($testDetails);
}
elseif ($mem == 0) {
$testDetails[2] .= " We can't determine how much memory you have allocated. Install only if you're sure you've allocated at least 20 MB.";
$this->warning($testDetails);
}
}
function getPHPMemory() {
$memString = ini_get("memory_limit");
switch (strtolower(substr($memString, -1))) {
case "k":
return round(substr($memString, 0, -1) * 1024);
case "m":
return round(substr($memString, 0, -1) * 1024 * 1024);
case "g":
return round(substr($memString, 0, -1) * 1024 * 1024 * 1024);
default:
return round($memString);
}
}
function listErrors() {
if ($this->errors) {
echo "<p>The following problems are preventing me from installing CiviCRM:</p>";
foreach ($this->errors as $error) {
echo "<li>" . htmlentities($error) . "</li>";
}
}
}
function showTable($section = NULL) {
if ($section) {
$tests = $this->tests[$section];
echo "<table class=\"testResults\" width=\"100%\">";
foreach ($tests as $test => $result) {
echo "<tr class=\"$result[0]\"><td>$test</td><td>" . nl2br(htmlentities($result[1])) . "</td></tr>";
}
echo "</table>";
}
else {
foreach ($this->tests as $section => $tests) {
echo "<h3>$section</h3>";
echo "<table class=\"testResults\" width=\"100%\">";
foreach ($tests as $test => $result) {
echo "<tr class=\"$result[0]\"><td>$test</td><td>" . nl2br(htmlentities($result[1])) . "</td></tr>";
}
echo "</table>";
}
}
}
function requireFunction($funcName, $testDetails) {
$this->testing($testDetails);
if (!function_exists($funcName)) {
$this->error($testDetails);
return FALSE;
}
else {
return TRUE;
}
}
function checkXCache($testDetails) {
if (function_exists('xcache_isset') &&
ini_get('xcache.size') > 0
) {
$this->testing($testDetails);
$this->warning($testDetails);
}
}
function requirePHPVersion($minVersion, $testDetails, $maxVersion = NULL) {
$this->testing($testDetails);
$phpVersion = phpversion();
$aboveMinVersion = version_compare($phpVersion, $minVersion) >= 0;
$belowMaxVersion = $maxVersion ? version_compare($phpVersion, $maxVersion) < 0 : TRUE;
if ($maxVersion && $aboveMinVersion && $belowMaxVersion) {
return TRUE;
}
elseif (!$maxVersion && $aboveMinVersion) {
return TRUE;
}
if (!$testDetails[2]) {
if (!$aboveMinVersion) {
$testDetails[2] = "You need PHP version $minVersion or later, only {$phpVersion} is installed. Please upgrade your server, or ask your web-host to do so.";
}
else {
$testDetails[2] = "PHP version {$phpVersion} is not supported. PHP version earlier than $maxVersion is required. You might want to downgrade your server, or ask your web-host to do so.";
}
}
$this->error($testDetails);
}
function requireFile($filename, $testDetails, $absolute = FALSE) {
$this->testing($testDetails);
if (!$absolute) {
$filename = $this->getBaseDir() . $filename;
}
if (!file_exists($filename)) {
$testDetails[2] .= " (file '$filename' not found)";
$this->error($testDetails);
}
}
function requireNoPathSeparator($testDetails) {
$this->testing($testDetails);
if (substr_count($this->getBaseDir(), PATH_SEPARATOR)) {
$this->error($testDetails);
}
}
function requireNoFile($filename, $testDetails) {
$this->testing($testDetails);
$filename = $this->getBaseDir() . $filename;
if (file_exists($filename)) {
$testDetails[2] .= " (file '$filename' found)";
$this->error($testDetails);
}
}
function moveFileOutOfTheWay($filename, $testDetails) {
$this->testing($testDetails);
$filename = $this->getBaseDir() . $filename;
if (file_exists($filename)) {
if (file_exists("$filename.bak")) {
rm("$filename.bak");
}
rename($filename, "$filename.bak");
}
}
function requireWriteable($filename, $testDetails, $absolute = FALSE) {
$this->testing($testDetails);
if (!$absolute) {
$filename = $this->getBaseDir() . $filename;
}
if (!is_writeable($filename)) {
$name = NULL;
if (function_exists('posix_getpwuid')) {
$user = posix_getpwuid(posix_geteuid());
$name = '- ' . $user['name'] . ' -';
}
if (!isset($testDetails[2])) {
$testDetails[2] = NULL;
}
$testDetails[2] .= "The user account used by your web-server $name needs to be granted write access to the following directory in order to configure the CiviCRM settings file:\n$filename";
$this->error($testDetails);
}
}
function requireApacheModule($moduleName, $testDetails) {
$this->testing($testDetails);
if (!in_array($moduleName, apache_get_modules())) {
$this->error($testDetails);
}
}
function requireMysqlConnection($server, $username, $password, $testDetails) {
$this->testing($testDetails);
$conn = @mysql_connect($server, $username, $password);
if ($conn) {
return TRUE;
}
else {
$testDetails[2] .= ": " . mysql_error();
$this->error($testDetails);
}
}
function requireMySQLServer($server, $testDetails) {
$this->testing($testDetails);
$conn = @mysql_connect($server, NULL, NULL);
if ($conn || mysql_errno() < 2000) {
return TRUE;
}
else {
$testDetails[2] .= ": " . mysql_error();
$this->error($testDetails);
}
}
function requireMySQLVersion($version, $testDetails) {
$this->testing($testDetails);
if (!mysql_get_server_info()) {
$testDetails[2] = 'Cannot determine the version of MySQL installed. Please ensure at least version 4.1 is installed.';
$this->warning($testDetails);
}
else {
list($majorRequested, $minorRequested) = explode('.', $version);
list($majorHas, $minorHas) = explode('.', mysql_get_server_info());
if (($majorHas > $majorRequested) || ($majorHas == $majorRequested && $minorHas >= $minorRequested)) {
return TRUE;
}
else {
$testDetails[2] .= "{$majorHas}.{$minorHas}.";
$this->error($testDetails);
}
}
}
function requireMySQLInnoDB($server, $username, $password, $database, $testDetails) {
$this->testing($testDetails);
$conn = @mysql_connect($server, $username, $password);
if (!$conn) {
$testDetails[2] .= ' Could not determine if mysql has innodb support. Assuming no';
$this->error($testDetails);
return;
}
$innodb_support = FALSE;
$result = mysql_query("SHOW ENGINES", $conn);
while ($values = mysql_fetch_array($result)) {
if ($values['Engine'] == 'InnoDB') {
if (strtolower($values['Support']) == 'yes' ||
strtolower($values['Support']) == 'default'
) {
$innodb_support = TRUE;
}
}
}
if ($innodb_support) {
$testDetails[3] = 'MySQL server does have innodb support';
}
else {
$testDetails[2] .= ' Could not determine if mysql has innodb support. Assuming no';
}
}
function requireMySQLTempTables($server, $username, $password, $database, $testDetails) {
$this->testing($testDetails);
$conn = @mysql_connect($server, $username, $password);
if (!$conn) {
$testDetails[2] = 'Could not login to the database.';
$this->error($testDetails);
return;
}
if (!@mysql_select_db($database, $conn)) {
$testDetails[2] = 'Could not select the database.';
$this->error($testDetails);
return;
}
$result = mysql_query('CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)', $conn);
if (!$result) {
$this->error($testDetails);
}
$result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
}
function requireMySQLLockTables($server, $username, $password, $database, $testDetails) {
$this->testing($testDetails);
$conn = @mysql_connect($server, $username, $password);
if (!$conn) {
$testDetails[2] = 'Could not login to the database.';
$this->error($testDetails);
return;
}
if (!@mysql_select_db($database, $conn)) {
$testDetails[2] = 'Could not select the database.';
$this->error($testDetails);
return;
}
$result = mysql_query('CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)', $conn);
if (!$result) {
$testDetails[2] = 'Could not create a table.';
$this->error($testDetails);
return;
}
$result = mysql_query('LOCK TABLES civicrm_install_temp_table_test WRITE', $conn);
if (!$result) {
$testDetails[2] = 'Could not obtain a write lock for the table.';
$this->error($testDetails);
$result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
return;
}
$result = mysql_query('UNLOCK TABLES', $conn);
if (!$result) {
$testDetails[2] = 'Could not release the lock for the table.';
$this->error($testDetails);
$result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
return;
}
$result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
return;
}
function requireMySQLAutoIncrementIncrementOne($server, $username, $password, $testDetails) {
$this->testing($testDetails);
$conn = @mysql_connect($server, $username, $password);
if (!$conn) {
$testDetails[2] = 'Could not connect to the database server.';
$this->error($testDetails);
return;
}
$result = mysql_query("SHOW variables like 'auto_increment_increment'", $conn);
if (!$result) {
$testDetails[2] = 'Could not query database server variables.';
$this->error($testDetails);
return;
}
else {
$values = mysql_fetch_row($result);
if ($values[1] == 1) {
$testDetails[3] = 'MySQL server auto_increment_increment is 1';
}
else {
$this->error($testDetails);
}
}
}
function requireDatabaseOrCreatePermissions($server,
$username,
$password,
$database,
$testDetails,
$onlyRequire = FALSE
) {
$this->testing($testDetails);
$conn = @mysql_connect($server, $username, $password);
$okay = NULL;
if (@mysql_select_db($database)) {
$okay = "Database '$database' exists";
}
elseif ($onlyRequire) {
$testDetails[2] = "The database: '$database' does not exist";
$this->error($testDetails);
return;
}
else {
if (@mysql_query("CREATE DATABASE $database")) {
$okay = "Able to create a new database";
}
else {
$testDetails[2] .= " (user '$username' doesn't have CREATE DATABASE permissions.)";
$this->error($testDetails);
return;
}
}
if ($okay) {
$testDetails[3] = $okay;
$this->testing($testDetails);
}
}
function requireServerVariables($varNames, $errorMessage) {
//$this->testing($testDetails);
foreach ($varNames as $varName) {
if (!$_SERVER[$varName]) {
$missing[] = '$_SERVER[' . $varName . ']';
}
}
if (!isset($missing)) {
return TRUE;
}
else {
$testDetails[2] .= " (the following PHP variables are missing: " . implode(", ", $missing) . ")";
$this->error($testDetails);
}
}
function isRunningApache($testDetails) {
$this->testing($testDetails);
if (function_exists('apache_get_modules') || stristr($_SERVER['SERVER_SIGNATURE'], 'Apache')) {
return TRUE;
}
$this->warning($testDetails);
return FALSE;
}
function getBaseDir() {
return dirname($_SERVER['SCRIPT_FILENAME']) . CIVICRM_DIRECTORY_SEPARATOR;
}
function testing($testDetails) {
if (!$testDetails) {
return;
}
$section = $testDetails[0];
$test = $testDetails[1];
$message = "OK";
if (isset($testDetails[3])) {
$message .= " ($testDetails[3])";
}
$this->tests[$section][$test] = array("good", $message);
}
function error($testDetails) {
$section = $testDetails[0];
$test = $testDetails[1];
$this->tests[$section][$test] = array("error", $testDetails[2]);
$this->errors[] = $testDetails;
}
function warning($testDetails) {
$section = $testDetails[0];
$test = $testDetails[1];
$this->tests[$section][$test] = array("warning", $testDetails[2]);
$this->warnings[] = $testDetails;
}
function hasErrors() {
return sizeof($this->errors);
}
function hasWarnings() {
return sizeof($this->warnings);
}
}
class Installer extends InstallRequirements {
function createDatabaseIfNotExists($server, $username, $password, $database) {
$conn = @mysql_connect($server, $username, $password);
if (@mysql_select_db($database)) {
// skip if database already present
return;
}
if (@mysql_query("CREATE DATABASE $database")) {}
else {
$errorTitle = "Oops! Could not create Database $database";
$errorMsg = "We encountered an error when attempting to create the database. Please check your mysql server permissions and the database name and try again.";
errorDisplayPage($errorTitle, $errorMsg);
}
}
function install($config) {
global $installDirPath;
// create database if does not exists
$this->createDatabaseIfNotExists($config['mysql']['server'],
$config['mysql']['username'],
$config['mysql']['password'],
$config['mysql']['database']
);
global $installDirPath;
// Build database
require_once $installDirPath . 'civicrm.php';
civicrm_main($config);
if (!$this->errors) {
global $installType, $installURLPath;
$output = NULL;
if ($installType == 'drupal' &&
version_compare(VERSION, '7.0-rc1') >= 0
) {
// clean output
@ob_clean();
$output .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
$output .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
$output .= '<head>';
$output .= '<title>CiviCRM Installed</title>';
$output .= '<link rel="stylesheet" type="text/css" href="template.css" />';
$output .= '</head>';
$output .= '<body>';
$output .= '<div style="padding: 1em;"><p class="good">CiviCRM has been successfully installed</p>';
$output .= '<ul>';
$docLinkConfig = CRM_Utils_System::docURL2('Configuring a New Site', FALSE, 'here',NULL,NULL,"wiki");
if (!function_exists('ts')) {
$docLinkConfig = "<a href=\"{$docLinkConfig}\">here</a>";
}
$drupalURL = civicrm_cms_base();
$drupalPermissionsURL = "{$drupalURL}index.php?q=admin/people/permissions";
$drupalURL .= "index.php?q=civicrm/admin/configtask&reset=1";