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