CRM-15689 - Fix js error in dateField initialization
[civicrm-core.git] / install / index.php
CommitLineData
6a488035
TO
1<?php
2
3/**
4 * Note that this installer has been based of the SilverStripe installer.
5 * You can get more information from the SilverStripe Website at
6 * http://www.silverstripe.com/. Please check
7 * http://www.silverstripe.com/licensing for licensing details.
8 *
9 * Copyright (c) 2006-7, SilverStripe Limited - www.silverstripe.com
10 * All rights reserved.
11 *
12 * Changes and modifications (c) 2007-8 by CiviCRM LLC
13 *
14 */
15
16/**
17 * CiviCRM Installer
18 */
19
20ini_set('max_execution_time', 3000);
21
22if (stristr(PHP_OS, 'WIN')) {
23 define('CIVICRM_DIRECTORY_SEPARATOR', '/');
24 define('CIVICRM_WINDOWS', 1 );
25}
26else {
27 define('CIVICRM_DIRECTORY_SEPARATOR', DIRECTORY_SEPARATOR);
28 define('CIVICRM_WINDOWS', 0 );
29}
30
31// set installation type - drupal
32if (!session_id()) {
33 session_start();
34}
35
36// unset civicrm session if any
37if (array_key_exists('CiviCRM', $_SESSION)) {
38 unset($_SESSION['CiviCRM']);
39}
40
41if (isset($_GET['civicrm_install_type'])) {
42 $_SESSION['civicrm_install_type'] = $_GET['civicrm_install_type'];
43}
44else {
45 if (!isset($_SESSION['civicrm_install_type'])) {
46 $_SESSION['civicrm_install_type'] = "drupal";
47 }
48}
49
50global $installType;
51$installType = strtolower($_SESSION['civicrm_install_type']);
52
53if (!in_array($installType, array(
54 'drupal', 'wordpress'))) {
55 $errorTitle = "Oops! Unsupported installation mode";
56 $errorMsg = "";
57 errorDisplayPage($errorTitle, $errorMsg);
58}
59
60global $crmPath;
61global $installDirPath;
62global $installURLPath;
63if ($installType == 'drupal') {
64 $crmPath = dirname(dirname($_SERVER['SCRIPT_FILENAME']));
65 $installDirPath = $installURLPath = '';
66}
67elseif ($installType == 'wordpress') {
68 $crmPath = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR;
69 $installDirPath = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR;
4046d167 70
6a488035
TO
71 $installURLPath = WP_PLUGIN_URL . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR;
72}
73
4046d167 74set_include_path(get_include_path() . PATH_SEPARATOR . $crmPath);
6a488035
TO
75
76require_once $crmPath . '/CRM/Core/ClassLoader.php';
77CRM_Core_ClassLoader::singleton()->register();
78
79$docLink = CRM_Utils_System::docURL2('Installation and Upgrades', FALSE, 'Installation Guide',NULL,NULL,"wiki");
80
81if ($installType == 'drupal') {
4046d167 82 //lets check only /modules/.
6a488035
TO
83 $pattern = '/' . preg_quote(CIVICRM_DIRECTORY_SEPARATOR . 'modules', CIVICRM_DIRECTORY_SEPARATOR) . '/';
84
4046d167
C
85 if (!preg_match($pattern,
86 str_replace("\\", "/", $_SERVER['SCRIPT_FILENAME'])
87 )) {
6a488035
TO
88 $errorTitle = "Oops! Please Correct Your Install Location";
89 $errorMsg = "Please untar (uncompress) your downloaded copy of CiviCRM in the <strong>" . implode(CIVICRM_DIRECTORY_SEPARATOR, array(
90 'sites', 'all', 'modules')) . "</strong> directory below your Drupal root directory. Refer to the online " . $docLink . " for more information.";
91 errorDisplayPage($errorTitle, $errorMsg);
92 }
93}
94
95// Load civicrm database config
96if (isset($_REQUEST['mysql'])) {
97 $databaseConfig = $_REQUEST['mysql'];
98}
99else {
100 $databaseConfig = array(
101 "server" => "localhost",
102 "username" => "civicrm",
103 "password" => "",
104 "database" => "civicrm",
105 );
106}
107
108if ($installType == 'drupal') {
109 // Load drupal database config
110 if (isset($_REQUEST['drupal'])) {
111 $drupalConfig = $_REQUEST['drupal'];
112 }
113 else {
114 $drupalConfig = array(
115 "server" => "localhost",
116 "username" => "drupal",
117 "password" => "",
118 "database" => "drupal",
119 );
120 }
121}
122
123$loadGenerated = 0;
124if (isset($_REQUEST['loadGenerated'])) {
125 $loadGenerated = 1;
126}
127
128require_once dirname(__FILE__) . CIVICRM_DIRECTORY_SEPARATOR . 'langs.php';
129foreach ($langs as $locale => $_) {
130 if ($locale == 'en_US') {
131 continue;
132 }
4046d167 133 if (!file_exists(implode(CIVICRM_DIRECTORY_SEPARATOR, array($crmPath, 'sql', "civicrm_data.$locale.mysql"))))unset($langs[$locale]);
6a488035
TO
134}
135
136$seedLanguage = 'en_US';
137if (isset($_REQUEST['seedLanguage']) and isset($langs[$_REQUEST['seedLanguage']])) {
138 $seedLanguage = $_REQUEST['seedLanguage'];
139}
140
141global $cmsPath;
142if ($installType == 'drupal') {
143 //CRM-6840 -don't force to install in sites/all/modules/
144 $object = new CRM_Utils_System_Drupal();
145 $cmsPath = $object->cmsRootPath();
146
147 $siteDir = getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']);
148 $alreadyInstalled = file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
149 'sites' . CIVICRM_DIRECTORY_SEPARATOR .
150 $siteDir . CIVICRM_DIRECTORY_SEPARATOR .
151 'civicrm.settings.php'
152 );
153}
154elseif ($installType == 'wordpress') {
155 $cmsPath = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'civicrm';
156 $alreadyInstalled = file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
157 'civicrm.settings.php'
158 );
159}
160
161// Exit with error if CiviCRM has already been installed.
162if ($alreadyInstalled) {
163 $errorTitle = "Oops! CiviCRM is Already Installed";
164 if ($installType == 'drupal') {
165
166 $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(
167 '[your Drupal root directory]', 'sites', $siteDir)) . "</strong>.</li><li>To <strong>upgrade an existing installation</strong>, refer to the online " . $docLink . ".</li></ul>";
168 }
169 elseif ($installType == 'wordpress') {
170 $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>";
171 }
172 errorDisplayPage($errorTitle, $errorMsg);
173}
174
175$versionFile = $crmPath . CIVICRM_DIRECTORY_SEPARATOR . 'civicrm-version.php';
176if (file_exists($versionFile)) {
177 require_once ($versionFile);
178 $civicrm_version = civicrmVersion();
179}
180else {
181 $civicrm_version = 'unknown';
182}
183
184if ($installType == 'drupal') {
185 // Ensure that they have downloaded the correct version of CiviCRM
186 if ($civicrm_version['cms'] != 'Drupal' &&
187 $civicrm_version['cms'] != 'Drupal6'
188 ) {
189 $errorTitle = "Oops! Incorrect CiviCRM Version";
190 $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!";
191 errorDisplayPage($errorTitle, $errorMsg);
192 }
193
194 define('DRUPAL_ROOT', $cmsPath);
195 $drupalVersionFiles = array(
196 // D6
197 implode(CIVICRM_DIRECTORY_SEPARATOR, array($cmsPath, 'modules', 'system', 'system.module')),
198 // D7
199 implode(CIVICRM_DIRECTORY_SEPARATOR, array($cmsPath, 'includes', 'bootstrap.inc')),
200 );
201 foreach ($drupalVersionFiles as $drupalVersionFile) {
202 if (file_exists($drupalVersionFile)) {
203 require_once $drupalVersionFile;
204 }
205 }
206
207 if (!defined('VERSION') or version_compare(VERSION, '6.0') < 0) {
208 $errorTitle = "Oops! Incorrect Drupal Version";
209 $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.";
210 errorDisplayPage($errorTitle, $errorMsg);
211 }
212}
213elseif ($installType == 'wordpress') {
214 //HACK for now
215 $civicrm_version['cms'] = 'WordPress';
216
217 // Ensure that they have downloaded the correct version of CiviCRM
218 if ($civicrm_version['cms'] != 'WordPress') {
219 $errorTitle = "Oops! Incorrect CiviCRM Version";
220 $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!";
221 errorDisplayPage($errorTitle, $errorMsg);
222 }
223}
224
225// Check requirements
226$req = new InstallRequirements();
227$req->check();
228
229if ($req->hasErrors()) {
230 $hasErrorOtherThanDatabase = TRUE;
231}
232
233if ($databaseConfig) {
234 $dbReq = new InstallRequirements();
235 $dbReq->checkdatabase($databaseConfig, 'CiviCRM');
236 if ($installType == 'drupal') {
237 $dbReq->checkdatabase($drupalConfig, 'Drupal');
238 }
239}
240
241// Actual processor
242if (isset($_REQUEST['go']) && !$req->hasErrors() && !$dbReq->hasErrors()) {
243 // Confirm before reinstalling
244 if (!isset($_REQUEST['force_reinstall']) && $alreadyInstalled) {
245 include ($installDirPath . 'template.html');
246 }
247 else {
248 $inst = new Installer();
249 $inst->install($_REQUEST);
250 }
251
252 // Show the config form
253}
254else {
255 include ($installDirPath . 'template.html');
256}
257
258/**
259 * This class checks requirements
260 * Each of the requireXXX functions takes an argument which gives a user description of the test. It's an array
261 * of 3 parts:
262 * $description[0] - The test catetgory
263 * $description[1] - The test title
264 * $description[2] - The test error to show, if it goes wrong
265 */
266class InstallRequirements {
267 var $errors, $warnings, $tests;
268
269 // @see CRM_Upgrade_Form::MINIMUM_THREAD_STACK
270 const MINIMUM_THREAD_STACK = 192;
271
272 /**
273 * Just check that the database configuration is okay
274 */
275 function checkdatabase($databaseConfig, $dbName) {
276 if ($this->requireFunction('mysql_connect',
277 array(
4046d167
C
278 "PHP Configuration",
279 "MySQL support",
280 "MySQL support not included in PHP.",
6a488035
TO
281 )
282 )) {
283 $this->requireMySQLServer($databaseConfig['server'],
284 array(
4046d167
C
285 "MySQL $dbName Configuration",
286 "Does the server exist",
287 "Can't find the a MySQL server on '$databaseConfig[server]'",
6a488035
TO
288 $databaseConfig['server'],
289 )
290 );
291 if ($this->requireMysqlConnection($databaseConfig['server'],
292 $databaseConfig['username'],
293 $databaseConfig['password'],
294 array(
4046d167
C
295 "MySQL $dbName Configuration",
296 "Are the access credentials correct",
297 "That username/password doesn't work",
6a488035
TO
298 )
299 )) {
300 @$this->requireMySQLVersion("5.1",
301 array(
4046d167
C
302 "MySQL $dbName Configuration",
303 "MySQL version at least 5.1",
6a488035
TO
304 "MySQL version 5.1 or higher is required, you only have ",
305 "MySQL " . mysql_get_server_info(),
306 )
307 );
308 $this->requireMySQLAutoIncrementIncrementOne($databaseConfig['server'],
309 $databaseConfig['username'],
310 $databaseConfig['password'],
311 array(
312 "MySQL $dbName Configuration",
313 "Is auto_increment_increment set to 1",
314 "An auto_increment_increment value greater than 1 is not currently supported. Please see issue CRM-7923 for further details and potential workaround.",
315 )
316 );
317 $this->requireMySQLThreadStack($databaseConfig['server'],
318 $databaseConfig['username'],
319 $databaseConfig['password'],
320 $databaseConfig['database'],
321 self::MINIMUM_THREAD_STACK,
322 array(
323 "MySQL $dbName Configuration",
324 "Does MySQL thread_stack meet minimum (" . self::MINIMUM_THREAD_STACK . "k)",
325 "", // "The MySQL thread_stack does not meet minimum " . CRM_Upgrade_Form::MINIMUM_THREAD_STACK . "k. Please update thread_stack in my.cnf.",
326 )
327 );
328 }
329 $onlyRequire = ($dbName == 'Drupal') ? TRUE : FALSE;
330 $this->requireDatabaseOrCreatePermissions(
331 $databaseConfig['server'],
332 $databaseConfig['username'],
333 $databaseConfig['password'],
334 $databaseConfig['database'],
335 array(
336 "MySQL $dbName Configuration",
337 "Can I access/create the database",
338 "I can't create new databases and the database '$databaseConfig[database]' doesn't exist",
339 ),
340 $onlyRequire
341 );
342 if ($dbName != 'Drupal') {
343 $this->requireMySQLInnoDB($databaseConfig['server'],
344 $databaseConfig['username'],
345 $databaseConfig['password'],
346 $databaseConfig['database'],
347 array(
348 "MySQL $dbName Configuration",
349 "Can I access/create InnoDB tables in the database",
350 "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.",
351 )
352 );
353 $this->requireMySQLTempTables($databaseConfig['server'],
354 $databaseConfig['username'],
355 $databaseConfig['password'],
356 $databaseConfig['database'],
357 array(
358 "MySQL $dbName Configuration",
359 'Can I create temporary tables in the database',
360 'Unable to create temporary tables. This MySQL user is missing the CREATE TEMPORARY TABLES privilege.',
361 )
362 );
363 $this->requireMySQLLockTables($databaseConfig['server'],
364 $databaseConfig['username'],
365 $databaseConfig['password'],
366 $databaseConfig['database'],
367 array(
368 "MySQL $dbName Configuration",
369 'Can I create lock tables in the database',
370 'Unable to lock tables. This MySQL user is missing the LOCK TABLES privilege.',
371 )
372 );
373 $this->requireMySQLTrigger($databaseConfig['server'],
374 $databaseConfig['username'],
375 $databaseConfig['password'],
376 $databaseConfig['database'],
377 array(
378 "MySQL $dbName Configuration",
379 'Can I create triggers in the database',
380 'Unable to create triggers. This MySQL user is missing the CREATE TRIGGERS privilege.',
381 )
382 );
383 }
384 }
385 }
386
387 /**
388 * Check everything except the database
389 */
390 function check() {
391 global $crmPath, $installType;
392
393 $this->errors = NULL;
394
4046d167 395 $this->requirePHPVersion('5.3.3', array("PHP Configuration", "PHP5 installed", NULL, "PHP version " . phpversion()));
6a488035
TO
396
397 // Check that we can identify the root folder successfully
398 $this->requireFile($crmPath . CIVICRM_DIRECTORY_SEPARATOR . 'README.txt',
399 array(
4046d167
C
400 "File permissions",
401 "Does the webserver know where files are stored?",
402 "The webserver isn't letting me identify where files are stored.",
6a488035
TO
403 $this->getBaseDir(),
404 ),
405 TRUE
406 );
407
408 // CRM-6485: make sure the path does not contain PATH_SEPARATOR, as we don’t know how to escape it
409 $this->requireNoPathSeparator(
410 array(
4046d167
C
411 'File permissions',
412 'does the CiviCRM path contain PATH_SEPARATOR?',
413 'the ' . $this->getBaseDir() . ' path contains PATH_SEPARATOR (the ' . PATH_SEPARATOR . ' character)',
6a488035
TO
414 $this->getBaseDir(),
415 )
416 );
417
418 $requiredDirectories = array('CRM', 'packages', 'templates', 'js', 'api', 'i', 'sql');
419 foreach ($requiredDirectories as $dir) {
420 $this->requireFile($crmPath . CIVICRM_DIRECTORY_SEPARATOR . $dir,
421 array(
4046d167 422 "File permissions", "$dir folder exists", "There is no $dir folder"), TRUE
6a488035
TO
423 );
424 }
425
426 $configIDSiniDir = NULL;
427 global $cmsPath;
3fdcdfbb 428 $siteDir = getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']);
6a488035 429 if ($installType == 'drupal') {
6a488035
TO
430
431 // make sure that we can write to sites/default and files/
432 $writableDirectories = array(
433 $cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
434 'sites' . CIVICRM_DIRECTORY_SEPARATOR .
435 $siteDir . CIVICRM_DIRECTORY_SEPARATOR .
436 'files',
437 $cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
438 'sites' . CIVICRM_DIRECTORY_SEPARATOR .
439 $siteDir,
440 );
441 }
442 elseif ($installType == 'wordpress') {
443 // make sure that we can write to plugins/civicrm and plugins/files/
444 $writableDirectories = array(WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'files', $cmsPath);
445 }
446
447 foreach ($writableDirectories as $dir) {
448 $dirName = CIVICRM_WINDOWS ? $dir : CIVICRM_DIRECTORY_SEPARATOR . $dir;
449 $this->requireWriteable($dirName,
4046d167 450 array("File permissions", "Is the $dir folder writeable?", NULL),
6a488035
TO
451 TRUE
452 );
453 }
454
455 //check for Config.IDS.ini, file may exist in re-install
456 $configIDSiniDir = array($cmsPath, 'sites', $siteDir, 'files', 'civicrm', 'upload', 'Config.IDS.ini');
457
458 if (is_array($configIDSiniDir) && !empty($configIDSiniDir)) {
459 $configIDSiniFile = implode(CIVICRM_DIRECTORY_SEPARATOR, $configIDSiniDir);
460 if (file_exists($configIDSiniFile)) {
461 unlink($configIDSiniFile);
462 }
463 }
464
465 // Check for rewriting
466 if (isset($_SERVER['SERVER_SOFTWARE'])) {
467 $webserver = strip_tags(trim($_SERVER['SERVER_SOFTWARE']));
468 }
469 elseif (isset($_SERVER['SERVER_SIGNATURE'])) {
470 $webserver = strip_tags(trim($_SERVER['SERVER_SIGNATURE']));
471 }
472
473 if ($webserver == '') {
4046d167 474 $webserver = "I can't tell what webserver you are running";
6a488035
TO
475 }
476
477 // Check for $_SERVER configuration
478 $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."));
479
480 // Check for MySQL support
481 $this->requireFunction('mysql_connect',
4046d167 482 array("PHP Configuration", "MySQL support", "MySQL support not included in PHP.")
6a488035
TO
483 );
484
485 // Check for JSON support
486 $this->requireFunction('json_encode',
4046d167 487 array("PHP Configuration", "JSON support", "JSON support not included in PHP.")
6a488035
TO
488 );
489
490 // Check for xcache_isset and emit warning if exists
491 $this->checkXCache(array(
4046d167 492 "PHP Configuration",
6a488035
TO
493 "XCache compatibility",
494 "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.",
495 ));
496
497 // Check memory allocation
498 $this->requireMemory(32 * 1024 * 1024,
499 64 * 1024 * 1024,
500 array(
4046d167
C
501 "PHP Configuration",
502 "Memory allocated (PHP config option 'memory_limit')",
503 "CiviCRM needs a minimum of 32M allocated to PHP, but recommends 64M.",
6a488035
TO
504 ini_get("memory_limit"),
505 )
506 );
507
508 return $this->errors;
509 }
510
627456b5
EM
511 /**
512 * @param $min
513 * @param $recommended
514 * @param $testDetails
515 */
6a488035
TO
516 function requireMemory($min, $recommended, $testDetails) {
517 $this->testing($testDetails);
518 $mem = $this->getPHPMemory();
519
520 if ($mem < $min && $mem > 0) {
4046d167 521 $testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated";
6a488035
TO
522 $this->error($testDetails);
523 }
524 elseif ($mem < $recommended && $mem > 0) {
4046d167 525 $testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated";
6a488035
TO
526 $this->warning($testDetails);
527 }
528 elseif ($mem == 0) {
4046d167 529 $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.";
6a488035
TO
530 $this->warning($testDetails);
531 }
532 }
533
627456b5
EM
534 /**
535 * @return float
536 */
6a488035
TO
537 function getPHPMemory() {
538 $memString = ini_get("memory_limit");
539
540 switch (strtolower(substr($memString, -1))) {
541 case "k":
542 return round(substr($memString, 0, -1) * 1024);
543
544 case "m":
545 return round(substr($memString, 0, -1) * 1024 * 1024);
546
547 case "g":
548 return round(substr($memString, 0, -1) * 1024 * 1024 * 1024);
549
550 default:
551 return round($memString);
552 }
553 }
554
555 function listErrors() {
556 if ($this->errors) {
4046d167 557 echo "<p>The following problems are preventing me from installing CiviCRM:</p>";
6a488035
TO
558 foreach ($this->errors as $error) {
559 echo "<li>" . htmlentities($error) . "</li>";
560 }
561 }
562 }
563
627456b5
EM
564 /**
565 * @param null $section
566 */
6a488035
TO
567 function showTable($section = NULL) {
568 if ($section) {
569 $tests = $this->tests[$section];
570 echo "<table class=\"testResults\" width=\"100%\">";
571 foreach ($tests as $test => $result) {
572 echo "<tr class=\"$result[0]\"><td>$test</td><td>" . nl2br(htmlentities($result[1])) . "</td></tr>";
573 }
574 echo "</table>";
575 }
576 else {
577 foreach ($this->tests as $section => $tests) {
578 echo "<h3>$section</h3>";
579 echo "<table class=\"testResults\" width=\"100%\">";
580
581 foreach ($tests as $test => $result) {
582 echo "<tr class=\"$result[0]\"><td>$test</td><td>" . nl2br(htmlentities($result[1])) . "</td></tr>";
583 }
584 echo "</table>";
585 }
586 }
587 }
588
627456b5
EM
589 /**
590 * @param $funcName
591 * @param $testDetails
592 *
593 * @return bool
594 */
6a488035
TO
595 function requireFunction($funcName, $testDetails) {
596 $this->testing($testDetails);
597
598 if (!function_exists($funcName)) {
599 $this->error($testDetails);
600 return FALSE;
601 }
602 else {
603 return TRUE;
604 }
605 }
606
627456b5
EM
607 /**
608 * @param $testDetails
609 */
6a488035
TO
610 function checkXCache($testDetails) {
611 if (function_exists('xcache_isset') &&
612 ini_get('xcache.size') > 0
613 ) {
614 $this->testing($testDetails);
615 $this->warning($testDetails);
616 }
617 }
618
627456b5
EM
619 /**
620 * @param $minVersion
621 * @param $testDetails
622 * @param null $maxVersion
623 */
6a488035
TO
624 function requirePHPVersion($minVersion, $testDetails, $maxVersion = NULL) {
625
626 $this->testing($testDetails);
627
628 $phpVersion = phpversion();
629 $aboveMinVersion = version_compare($phpVersion, $minVersion) >= 0;
630 $belowMaxVersion = $maxVersion ? version_compare($phpVersion, $maxVersion) < 0 : TRUE;
631
632 if ($maxVersion && $aboveMinVersion && $belowMaxVersion) {
633 return TRUE;
634 }
635 elseif (!$maxVersion && $aboveMinVersion) {
636 return TRUE;
637 }
638
639 if (!$testDetails[2]) {
640 if (!$aboveMinVersion) {
641 $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.";
642 }
643 else {
644 $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.";
645 }
646 }
647
648 $this->error($testDetails);
649 }
650
627456b5
EM
651 /**
652 * @param $filename
653 * @param $testDetails
654 * @param bool $absolute
655 */
6a488035
TO
656 function requireFile($filename, $testDetails, $absolute = FALSE) {
657 $this->testing($testDetails);
658 if (!$absolute) {
659 $filename = $this->getBaseDir() . $filename;
660 }
661 if (!file_exists($filename)) {
662 $testDetails[2] .= " (file '$filename' not found)";
663 $this->error($testDetails);
664 }
665 }
666
627456b5
EM
667 /**
668 * @param $testDetails
669 */
6a488035
TO
670 function requireNoPathSeparator($testDetails) {
671 $this->testing($testDetails);
672 if (substr_count($this->getBaseDir(), PATH_SEPARATOR)) {
673 $this->error($testDetails);
674 }
675 }
676
627456b5
EM
677 /**
678 * @param $filename
679 * @param $testDetails
680 */
6a488035
TO
681 function requireNoFile($filename, $testDetails) {
682 $this->testing($testDetails);
683 $filename = $this->getBaseDir() . $filename;
684 if (file_exists($filename)) {
685 $testDetails[2] .= " (file '$filename' found)";
686 $this->error($testDetails);
687 }
688 }
689
627456b5
EM
690 /**
691 * @param $filename
692 * @param $testDetails
693 */
6a488035
TO
694 function moveFileOutOfTheWay($filename, $testDetails) {
695 $this->testing($testDetails);
696 $filename = $this->getBaseDir() . $filename;
697 if (file_exists($filename)) {
698 if (file_exists("$filename.bak")) {
699 rm("$filename.bak");
700 }
701 rename($filename, "$filename.bak");
702 }
703 }
704
627456b5
EM
705 /**
706 * @param $filename
707 * @param $testDetails
708 * @param bool $absolute
709 */
6a488035
TO
710 function requireWriteable($filename, $testDetails, $absolute = FALSE) {
711 $this->testing($testDetails);
712 if (!$absolute) {
713 $filename = $this->getBaseDir() . $filename;
714 }
715
716 if (!is_writeable($filename)) {
717 $name = NULL;
718 if (function_exists('posix_getpwuid')) {
719 $user = posix_getpwuid(posix_geteuid());
720 $name = '- ' . $user['name'] . ' -';
721 }
722
723 if (!isset($testDetails[2])) {
724 $testDetails[2] = NULL;
725 }
726 $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";
727 $this->error($testDetails);
728 }
729 }
730
627456b5
EM
731 /**
732 * @param $moduleName
733 * @param $testDetails
734 */
6a488035
TO
735 function requireApacheModule($moduleName, $testDetails) {
736 $this->testing($testDetails);
737 if (!in_array($moduleName, apache_get_modules())) {
738 $this->error($testDetails);
739 }
740 }
741
627456b5
EM
742 /**
743 * @param $server
744 * @param $username
745 * @param $password
746 * @param $testDetails
747 */
6a488035
TO
748 function requireMysqlConnection($server, $username, $password, $testDetails) {
749 $this->testing($testDetails);
750 $conn = @mysql_connect($server, $username, $password);
751
752 if ($conn) {
753 return TRUE;
754 }
755 else {
756 $testDetails[2] .= ": " . mysql_error();
757 $this->error($testDetails);
758 }
759 }
760
627456b5
EM
761 /**
762 * @param $server
763 * @param $testDetails
764 */
6a488035
TO
765 function requireMySQLServer($server, $testDetails) {
766 $this->testing($testDetails);
767 $conn = @mysql_connect($server, NULL, NULL);
768
769 if ($conn || mysql_errno() < 2000) {
770 return TRUE;
771 }
772 else {
773 $testDetails[2] .= ": " . mysql_error();
774 $this->error($testDetails);
775 }
776 }
777
627456b5
EM
778 /**
779 * @param $version
780 * @param $testDetails
781 */
6a488035
TO
782 function requireMySQLVersion($version, $testDetails) {
783 $this->testing($testDetails);
784
785 if (!mysql_get_server_info()) {
786 $testDetails[2] = 'Cannot determine the version of MySQL installed. Please ensure at least version 4.1 is installed.';
787 $this->warning($testDetails);
788 }
789 else {
790 list($majorRequested, $minorRequested) = explode('.', $version);
791 list($majorHas, $minorHas) = explode('.', mysql_get_server_info());
792
793 if (($majorHas > $majorRequested) || ($majorHas == $majorRequested && $minorHas >= $minorRequested)) {
794 return TRUE;
795 }
796 else {
797 $testDetails[2] .= "{$majorHas}.{$minorHas}.";
798 $this->error($testDetails);
799 }
800 }
801 }
802
627456b5
EM
803 /**
804 * @param $server
805 * @param $username
806 * @param $password
807 * @param $database
808 * @param $testDetails
809 */
6a488035
TO
810 function requireMySQLInnoDB($server, $username, $password, $database, $testDetails) {
811 $this->testing($testDetails);
812 $conn = @mysql_connect($server, $username, $password);
813 if (!$conn) {
814 $testDetails[2] .= ' Could not determine if mysql has innodb support. Assuming no';
815 $this->error($testDetails);
816 return;
817 }
818
819 $innodb_support = FALSE;
820 $result = mysql_query("SHOW ENGINES", $conn);
821 while ($values = mysql_fetch_array($result)) {
822 if ($values['Engine'] == 'InnoDB') {
823 if (strtolower($values['Support']) == 'yes' ||
824 strtolower($values['Support']) == 'default'
825 ) {
826 $innodb_support = TRUE;
827 }
828 }
829 }
830 if ($innodb_support) {
831 $testDetails[3] = 'MySQL server does have innodb support';
832 }
833 else {
834 $testDetails[2] .= ' Could not determine if mysql has innodb support. Assuming no';
835 }
836 }
837
627456b5
EM
838 /**
839 * @param $server
840 * @param $username
841 * @param $password
842 * @param $database
843 * @param $testDetails
844 */
6a488035
TO
845 function requireMySQLTempTables($server, $username, $password, $database, $testDetails) {
846 $this->testing($testDetails);
847 $conn = @mysql_connect($server, $username, $password);
848 if (!$conn) {
849 $testDetails[2] = 'Could not login to the database.';
850 $this->error($testDetails);
851 return;
852 }
853
854 if (!@mysql_select_db($database, $conn)) {
855 $testDetails[2] = 'Could not select the database.';
856 $this->error($testDetails);
857 return;
858 }
859
860 $result = mysql_query('CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)', $conn);
861 if (!$result) {
862 $testDetails[2] = 'Could not create a temp table.';
863 $this->error($testDetails);
864 }
865 $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
866 }
867
627456b5
EM
868 /**
869 * @param $server
870 * @param $username
871 * @param $password
872 * @param $database
873 * @param $testDetails
874 */
6a488035
TO
875 function requireMySQLTrigger($server, $username, $password, $database, $testDetails) {
876 $this->testing($testDetails);
877 $conn = @mysql_connect($server, $username, $password);
878 if (!$conn) {
879 $testDetails[2] = 'Could not login to the database.';
880 $this->error($testDetails);
881 return;
882 }
883
884 if (!@mysql_select_db($database, $conn)) {
885 $testDetails[2] = 'Could not select the database.';
886 $this->error($testDetails);
887 return;
888 }
889
890 $result = mysql_query('CREATE TABLE civicrm_install_temp_table_test (test text)', $conn);
891 if (!$result) {
892 $testDetails[2] = 'Could not create a table.';
893 $this->error($testDetails);
894 }
895
896 $result = mysql_query('CREATE TRIGGER civicrm_install_temp_table_test_trigger BEFORE INSERT ON civicrm_install_temp_table_test FOR EACH ROW BEGIN END');
897 if (!$result) {
898 mysql_query('DROP TABLE civicrm_install_temp_table_test');
899 $testDetails[2] = 'Could not create a trigger.';
900 $this->error($testDetails);
901 }
902
903
904 mysql_query('DROP TRIGGER civicrm_install_temp_table_test_trigger');
905 mysql_query('DROP TABLE civicrm_install_temp_table_test');
906 }
907
908
627456b5
EM
909 /**
910 * @param $server
911 * @param $username
912 * @param $password
913 * @param $database
914 * @param $testDetails
915 */
6a488035
TO
916 function requireMySQLLockTables($server, $username, $password, $database, $testDetails) {
917 $this->testing($testDetails);
918 $conn = @mysql_connect($server, $username, $password);
919 if (!$conn) {
920 $testDetails[2] = 'Could not login to the database.';
921 $this->error($testDetails);
922 return;
923 }
924
925 if (!@mysql_select_db($database, $conn)) {
926 $testDetails[2] = 'Could not select the database.';
927 $this->error($testDetails);
928 return;
929 }
930
931 $result = mysql_query('CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)', $conn);
932 if (!$result) {
933 $testDetails[2] = 'Could not create a table.';
934 $this->error($testDetails);
935 return;
936 }
937
938 $result = mysql_query('LOCK TABLES civicrm_install_temp_table_test WRITE', $conn);
939 if (!$result) {
940 $testDetails[2] = 'Could not obtain a write lock for the table.';
941 $this->error($testDetails);
942 $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
943 return;
944 }
945
946 $result = mysql_query('UNLOCK TABLES', $conn);
947 if (!$result) {
948 $testDetails[2] = 'Could not release the lock for the table.';
949 $this->error($testDetails);
950 $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
951 return;
952 }
953
954 $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
955 return;
956 }
957
627456b5
EM
958 /**
959 * @param $server
960 * @param $username
961 * @param $password
962 * @param $testDetails
963 */
6a488035
TO
964 function requireMySQLAutoIncrementIncrementOne($server, $username, $password, $testDetails) {
965 $this->testing($testDetails);
966 $conn = @mysql_connect($server, $username, $password);
967 if (!$conn) {
968 $testDetails[2] = 'Could not connect to the database server.';
969 $this->error($testDetails);
970 return;
971 }
972
973 $result = mysql_query("SHOW variables like 'auto_increment_increment'", $conn);
974 if (!$result) {
975 $testDetails[2] = 'Could not query database server variables.';
976 $this->error($testDetails);
977 return;
978 }
979 else {
980 $values = mysql_fetch_row($result);
981 if ($values[1] == 1) {
982 $testDetails[3] = 'MySQL server auto_increment_increment is 1';
983 }
984 else {
985 $this->error($testDetails);
986 }
987 }
988 }
989
627456b5
EM
990 /**
991 * @param $server
992 * @param $username
993 * @param $password
994 * @param $database
995 * @param $minValueKB
996 * @param $testDetails
997 */
6a488035
TO
998 function requireMySQLThreadStack($server, $username, $password, $database, $minValueKB, $testDetails) {
999 $this->testing($testDetails);
1000 $conn = @mysql_connect($server, $username, $password);
1001 if (!$conn) {
1002 $testDetails[2] = 'Could not login to the database.';
1003 $this->error($testDetails);
1004 return;
1005 }
1006
1007 if (!@mysql_select_db($database, $conn)) {
1008 $testDetails[2] = 'Could not select the database.';
1009 $this->error($testDetails);
1010 return;
1011 }
1012
032c9d10 1013 $result = mysql_query("SHOW VARIABLES LIKE 'thread_stack'", $conn); // bytes => kb
6a488035
TO
1014 if (!$result) {
1015 $testDetails[2] = 'Could not query thread_stack.';
1016 $this->error($testDetails);
1017 } else {
1018 $values = mysql_fetch_row($result);
032c9d10
TO
1019 if ($values[1] < (1024*$minValueKB)) {
1020 $testDetails[2] = 'MySQL "thread_stack" is ' . ($values[1]/1024) . 'k';
6a488035
TO
1021 $this->error($testDetails);
1022 }
1023 }
1024 }
1025
627456b5
EM
1026 /**
1027 * @param $server
1028 * @param $username
1029 * @param $password
1030 * @param $database
1031 * @param $testDetails
1032 * @param bool $onlyRequire
1033 */
6a488035
TO
1034 function requireDatabaseOrCreatePermissions($server,
1035 $username,
1036 $password,
1037 $database,
1038 $testDetails,
1039 $onlyRequire = FALSE
1040 ) {
1041 $this->testing($testDetails);
1042 $conn = @mysql_connect($server, $username, $password);
1043
1044 $okay = NULL;
1045 if (@mysql_select_db($database)) {
1046 $okay = "Database '$database' exists";
1047 }
1048 elseif ($onlyRequire) {
1049 $testDetails[2] = "The database: '$database' does not exist";
1050 $this->error($testDetails);
1051 return;
1052 }
1053 else {
1054 if (@mysql_query("CREATE DATABASE $database")) {
1055 $okay = "Able to create a new database";
1056 }
1057 else {
1058 $testDetails[2] .= " (user '$username' doesn't have CREATE DATABASE permissions.)";
1059 $this->error($testDetails);
1060 return;
1061 }
1062 }
1063
1064 if ($okay) {
1065 $testDetails[3] = $okay;
1066 $this->testing($testDetails);
1067 }
1068 }
1069
627456b5
EM
1070 /**
1071 * @param $varNames
1072 * @param $errorMessage
1073 */
6a488035
TO
1074 function requireServerVariables($varNames, $errorMessage) {
1075 //$this->testing($testDetails);
1076 foreach ($varNames as $varName) {
1077 if (!$_SERVER[$varName]) {
1078 $missing[] = '$_SERVER[' . $varName . ']';
1079 }
1080 }
1081 if (!isset($missing)) {
1082 return TRUE;
1083 }
1084 else {
3fdcdfbb 1085 $testDetails[2] = " (the following PHP variables are missing: " . implode(", ", $missing) . ")";
6a488035
TO
1086 $this->error($testDetails);
1087 }
1088 }
1089
627456b5
EM
1090 /**
1091 * @param $testDetails
1092 *
1093 * @return bool
1094 */
6a488035
TO
1095 function isRunningApache($testDetails) {
1096 $this->testing($testDetails);
1097 if (function_exists('apache_get_modules') || stristr($_SERVER['SERVER_SIGNATURE'], 'Apache')) {
1098 return TRUE;
1099 }
1100
1101 $this->warning($testDetails);
1102 return FALSE;
1103 }
1104
627456b5
EM
1105 /**
1106 * @return string
1107 */
6a488035
TO
1108 function getBaseDir() {
1109 return dirname($_SERVER['SCRIPT_FILENAME']) . CIVICRM_DIRECTORY_SEPARATOR;
1110 }
1111
627456b5
EM
1112 /**
1113 * @param $testDetails
1114 */
6a488035
TO
1115 function testing($testDetails) {
1116 if (!$testDetails) {
1117 return;
1118 }
1119
1120 $section = $testDetails[0];
1121 $test = $testDetails[1];
1122
1123 $message = "OK";
1124 if (isset($testDetails[3])) {
1125 $message .= " ($testDetails[3])";
1126 }
1127
1128 $this->tests[$section][$test] = array("good", $message);
1129 }
1130
627456b5
EM
1131 /**
1132 * @param $testDetails
1133 */
6a488035
TO
1134 function error($testDetails) {
1135 $section = $testDetails[0];
1136 $test = $testDetails[1];
1137
1138 $this->tests[$section][$test] = array("error", $testDetails[2]);
1139 $this->errors[] = $testDetails;
1140 }
1141
627456b5
EM
1142 /**
1143 * @param $testDetails
1144 */
6a488035
TO
1145 function warning($testDetails) {
1146 $section = $testDetails[0];
1147 $test = $testDetails[1];
1148
1149
1150 $this->tests[$section][$test] = array("warning", $testDetails[2]);
1151 $this->warnings[] = $testDetails;
1152 }
1153
627456b5
EM
1154 /**
1155 * @return int
1156 */
6a488035
TO
1157 function hasErrors() {
1158 return sizeof($this->errors);
1159 }
1160
627456b5
EM
1161 /**
1162 * @return int
1163 */
6a488035
TO
1164 function hasWarnings() {
1165 return sizeof($this->warnings);
1166 }
1167}
1168
627456b5
EM
1169/**
1170 * Class Installer
1171 */
6a488035 1172class Installer extends InstallRequirements {
627456b5
EM
1173 /**
1174 * @param $server
1175 * @param $username
1176 * @param $password
1177 * @param $database
1178 */
6a488035
TO
1179 function createDatabaseIfNotExists($server, $username, $password, $database) {
1180 $conn = @mysql_connect($server, $username, $password);
1181
1182 if (@mysql_select_db($database)) {
1183 // skip if database already present
1184 return;
1185 }
1186
1187 if (@mysql_query("CREATE DATABASE $database")) {}
1188 else {
1189 $errorTitle = "Oops! Could not create Database $database";
1190 $errorMsg = "We encountered an error when attempting to create the database. Please check your mysql server permissions and the database name and try again.";
1191 errorDisplayPage($errorTitle, $errorMsg);
1192 }
1193 }
1194
627456b5
EM
1195 /**
1196 * @param $config
1197 *
1198 * @return mixed
1199 */
6a488035
TO
1200 function install($config) {
1201 global $installDirPath;
1202
1203 // create database if does not exists
1204 $this->createDatabaseIfNotExists($config['mysql']['server'],
1205 $config['mysql']['username'],
1206 $config['mysql']['password'],
1207 $config['mysql']['database']
1208 );
1209
1210 global $installDirPath;
1211
1212 // Build database
1213 require_once $installDirPath . 'civicrm.php';
1214 civicrm_main($config);
1215
1216 if (!$this->errors) {
1217 global $installType, $installURLPath;
1218
bb216f68 1219 $registerSiteURL = "https://civicrm.org/register-site";
41547a19 1220 $commonOutputMessage = "
bb216f68 1221 <li>Have you registered this site at CiviCRM.org? If not, please help strengthen the CiviCRM ecosystem by taking a few minutes to <a href='$registerSiteURL' target='_blank'>fill out the site registration form</a>. The information collected will help us prioritize improvements, target our communications and build the community. If you have a technical role for this site, be sure to check Keep in Touch to receive technical updates (a low volume mailing list).</li>
41547a19
DL
1222 <li>We have integrated KCFinder with CKEditor and TinyMCE. This allows a user to upload images. All uploaded images are public.</li>
1223";
1224
6a488035
TO
1225 $output = NULL;
1226 if (
1227 $installType == 'drupal' &&
1228 version_compare(VERSION, '7.0-rc1') >= 0
1229 ) {
1230
1231 // clean output
1232 @ob_clean();
1233
1234 $output .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
1235 $output .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1236 $output .= '<head>';
1237 $output .= '<title>CiviCRM Installed</title>';
1238 $output .= '<link rel="stylesheet" type="text/css" href="template.css" />';
1239 $output .= '</head>';
1240 $output .= '<body>';
1241 $output .= '<div style="padding: 1em;"><p class="good">CiviCRM has been successfully installed</p>';
1242 $output .= '<ul>';
1243 $docLinkConfig = CRM_Utils_System::docURL2('Configuring a New Site', FALSE, 'here',NULL,NULL,"wiki");
1244 if (!function_exists('ts')) {
1245 $docLinkConfig = "<a href=\"{$docLinkConfig}\">here</a>";
1246 }
1247 $drupalURL = civicrm_cms_base();
1248 $drupalPermissionsURL = "{$drupalURL}index.php?q=admin/people/permissions";
1249 $drupalURL .= "index.php?q=civicrm/admin/configtask&reset=1";
6a488035
TO
1250
1251 $output .= "<li>Drupal user permissions have been automatically set - giving anonymous and authenticated users access to public CiviCRM forms and features. We recommend that you <a target='_blank' href={$drupalPermissionsURL}>review these permissions</a> to ensure that they are appropriate for your requirements (<a target='_blank' href='http://wiki.civicrm.org/confluence/display/CRMDOC/Default+Permissions+and+Roles'>learn more...</a>)</li>
1252 <li>Use the <a target='_blank' href=\"$drupalURL\">Configuration Checklist</a> to review and configure settings for your new site</li>
41547a19 1253 {$commonOutputMessage}";
6a488035
TO
1254
1255 // automatically enable CiviCRM module once it is installed successfully.
1256 // so we need to Bootstrap Drupal, so that we can call drupal hooks.
1257 global $cmsPath, $crmPath;
1258
1259 // relative / abosolute paths are not working for drupal, hence using chdir()
1260 chdir($cmsPath);
1261
1262 include_once "./includes/bootstrap.inc";
1263 include_once "./includes/unicode.inc";
1264
1265 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
1266
1267 // prevent session information from being saved.
1268 drupal_save_session(FALSE);
1269
1270 // Force the current user to anonymous.
1271 $original_user = $GLOBALS['user'];
1272 $GLOBALS['user'] = drupal_anonymous_user();
1273
1274 // explicitly setting error reporting, since we cannot handle drupal related notices
1275 error_reporting(1);
1276
1277 // rebuild modules, so that civicrm is added
1278 system_rebuild_module_data();
1279
1280 // now enable civicrm module.
1281 module_enable(array('civicrm', 'civicrmtheme'));
1282
d8a4acc0
C
1283 // clear block, page, theme, and hook caches
1284 drupal_flush_all_caches();
6a488035
TO
1285
1286 //add basic drupal permissions
1287 civicrm_install_set_drupal_perms();
1288
1289 // restore the user.
1290 $GLOBALS['user'] = $original_user;
1291 drupal_save_session(TRUE);
1292
1293 $output .= '</ul>';
1294 $output .= '</div>';
1295 $output .= '</body>';
1296 $output .= '</html>';
1297 echo $output;
1298 }
1299 elseif ($installType == 'drupal' && version_compare(VERSION, '6.0') >= 0) {
1300 // clean output
1301 @ob_clean();
1302
1303 $output .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
1304 $output .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1305 $output .= '<head>';
1306 $output .= '<title>CiviCRM Installed</title>';
1307 $output .= '<link rel="stylesheet" type="text/css" href="template.css" />';
1308 $output .= '</head>';
1309 $output .= '<body>';
1310 $output .= '<div style="padding: 1em;"><p class="good">CiviCRM has been successfully installed</p>';
1311 $output .= '<ul>';
1312 $docLinkConfig = CRM_Utils_System::docURL2('Configuring a New Site', FALSE, 'here',NULL,NULL,"wiki");
1313 if (!function_exists('ts')) {
1314 $docLinkConfig = "<a href=\"{$docLinkConfig}\">here</a>";
1315 }
1316 $drupalURL = civicrm_cms_base();
1317 $drupalPermissionsURL = "{$drupalURL}index.php?q=admin/user/permissions";
1318 $drupalURL .= "index.php?q=civicrm/admin/configtask&reset=1";
6a488035
TO
1319
1320 $output .= "<li>Drupal user permissions have been automatically set - giving anonymous and authenticated users access to public CiviCRM forms and features. We recommend that you <a target='_blank' href={$drupalPermissionsURL}>review these permissions</a> to ensure that they are appropriate for your requirements (<a target='_blank' href='http://wiki.civicrm.org/confluence/display/CRMDOC/Default+Permissions+and+Roles'>learn more...</a>)</li>
1321 <li>Use the <a target='_blank' href=\"$drupalURL\">Configuration Checklist</a> to review and configure settings for your new site</li>
41547a19 1322 {$commonOutputMessage}";
6a488035
TO
1323
1324 // explicitly setting error reporting, since we cannot handle drupal related notices
1325 error_reporting(1);
1326
1327 // automatically enable CiviCRM module once it is installed successfully.
1328 // so we need to Bootstrap Drupal, so that we can call drupal hooks.
1329 global $cmsPath, $crmPath;
1330
1331 // relative / abosolute paths are not working for drupal, hence using chdir()
1332 chdir($cmsPath);
1333
1334 include_once "./includes/bootstrap.inc";
1335 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
1336
1337 // rebuild modules, so that civicrm is added
1338 module_rebuild_cache();
1339
1340 // now enable civicrm module.
1341 module_enable(array('civicrm'));
1342
d8a4acc0
C
1343 // clear block, page, theme, and hook caches
1344 drupal_flush_all_caches();
6a488035
TO
1345
1346 //add basic drupal permissions
1347 db_query('UPDATE {permission} SET perm = CONCAT( perm, \', access CiviMail subscribe/unsubscribe pages, access all custom data, access uploaded files, make online contributions, profile create, profile edit, profile view, register for events, view event info\') WHERE rid IN (1, 2)');
1348
1349 echo $output;
1350 }
1351 elseif ($installType == 'wordpress') {
1352 echo '<h1>CiviCRM Installed</h1>';
1353 echo '<div style="padding: 1em;"><p style="background-color: #0C0; border: 1px #070 solid; color: white;">CiviCRM has been successfully installed</p>';
1354 echo '<ul>';
1355 $docLinkConfig = CRM_Utils_System::docURL2('Configuring a New Site', FALSE, 'here',NULL,NULL,"wiki");
1356 if (!function_exists('ts')) {
1357 $docLinkConfig = "<a href=\"{$docLinkConfig}\">here</a>";
1358 }
1359
1360 $cmsURL = civicrm_cms_base();
1361 $cmsURL .= "wp-admin/admin.php?page=CiviCRM&q=civicrm/admin/configtask&reset=1";
41547a19
DL
1362 $wpPermissionsURL = "wp-admin/admin.php?page=CiviCRM&q=civicrm/admin/access/wp-permissions&reset=1";
1363
1364 $output .= "
bc62fd4e 1365 <li>WordPress user permissions have been automatically set - giving Anonymous and Subscribers access to public CiviCRM forms and features. We recommend that you <a target='_blank' href={$wpPermissionsURL}>review these permissions</a> to ensure that they are appropriate for your requirements (<a target='_blank' href='http://wiki.civicrm.org/confluence/display/CRMDOC/Default+Permissions+and+Roles'>learn more...</a>)</li>
41547a19
DL
1366 <li>Use the <a target='_blank' href=\"$cmsURL\">Configuration Checklist</a> to review and configure settings for your new site</li>
1367 {$commonOutputMessage}
1368";
1369
1370 echo '</ul>';
1371 echo '</div>';
1372 }
1373 }
6a488035
TO
1374
1375 return $this->errors;
1376 }
1377}
1378
1379function civicrm_install_set_drupal_perms() {
1380 if (!function_exists('db_select')) {
1381 db_query('UPDATE {permission} SET perm = CONCAT( perm, \', access CiviMail subscribe/unsubscribe pages, access all custom data, access uploaded files, make online contributions, profile listings and forms, register for events, view event info, view event participants\') WHERE rid IN (1, 2)');
1382 }
1383 else {
1384 $perms = array(
1385 'access all custom data',
1386 'access uploaded files',
1387 'make online contributions',
1388 'profile create',
1389 'profile edit',
1390 'profile view',
1391 'register for events',
1392 'view event info',
1393 'view event participants',
1394 'access CiviMail subscribe/unsubscribe pages',
1395 );
1396
1397 // Adding a permission that has not yet been assigned to a module by
1398 // a hook_permission implementation results in a database error.
1399 // CRM-9042
1400 $allPerms = array_keys(module_invoke_all('permission'));
1401 foreach (array_diff($perms, $allPerms) as $perm) {
1402 watchdog('civicrm',
1403 'Cannot grant the %perm permission because it does not yet exist.',
1404 array(
1405 '%perm' => $perm), WATCHDOG_ERROR
1406 );
1407 }
1408 $perms = array_intersect($perms, $allPerms);
1409 user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, $perms);
1410 user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, $perms);
1411 }
1412}
1413
627456b5
EM
1414/**
1415 * @param $cmsPath
1416 * @param $str
1417 *
1418 * @return string
1419 */
6a488035
TO
1420function getSiteDir($cmsPath, $str) {
1421 static $siteDir = '';
1422
1423 if ($siteDir) {
1424 return $siteDir;
1425 }
1426
1427 $sites = CIVICRM_DIRECTORY_SEPARATOR . 'sites' . CIVICRM_DIRECTORY_SEPARATOR;
1428 $modules = CIVICRM_DIRECTORY_SEPARATOR . 'modules' . CIVICRM_DIRECTORY_SEPARATOR;
1429 preg_match("/" . preg_quote($sites, CIVICRM_DIRECTORY_SEPARATOR) .
1430 "([\-a-zA-Z0-9_.]+)" .
1431 preg_quote($modules, CIVICRM_DIRECTORY_SEPARATOR) . "/",
1432 $_SERVER['SCRIPT_FILENAME'], $matches
1433 );
1434 $siteDir = isset($matches[1]) ? $matches[1] : 'default';
1435
1436 if (strtolower($siteDir) == 'all') {
1437 // For this case - use drupal's way of finding out multi-site directory
1438 $uri = explode(CIVICRM_DIRECTORY_SEPARATOR, $_SERVER['SCRIPT_FILENAME']);
1439 $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
1440 for ($i = count($uri) - 1; $i > 0; $i--) {
1441 for ($j = count($server); $j > 0; $j--) {
1442 $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
1443 if (file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
1444 'sites' . CIVICRM_DIRECTORY_SEPARATOR . $dir
1445 )) {
1446 $siteDir = $dir;
1447 return $siteDir;
1448 }
1449 }
1450 }
1451 $siteDir = 'default';
1452 }
1453
1454 return $siteDir;
1455}
1456
627456b5
EM
1457/**
1458 * @param $errorTitle
1459 * @param $errorMsg
1460 */
6a488035
TO
1461function errorDisplayPage($errorTitle, $errorMsg) {
1462 include ('error.html');
1463 exit();
1464}
1465