CRM-11823 - D6 - Warn during upgrade if the 'preprocess function' for outputing JS...
[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;
70
71 $installURLPath = WP_PLUGIN_URL . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR;
72}
73
74set_include_path(get_include_path() . PATH_SEPARATOR . $crmPath);
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') {
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
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 }
133 if (!file_exists(implode(CIVICRM_DIRECTORY_SEPARATOR, array($crmPath, 'sql', "civicrm_data.$locale.mysql"))))unset($langs[$locale]);
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(
278 "PHP Configuration",
279 "MySQL support",
280 "MySQL support not included in PHP.",
281 )
282 )) {
283 $this->requireMySQLServer($databaseConfig['server'],
284 array(
285 "MySQL $dbName Configuration",
286 "Does the server exist",
287 "Can't find the a MySQL server on '$databaseConfig[server]'",
288 $databaseConfig['server'],
289 )
290 );
291 if ($this->requireMysqlConnection($databaseConfig['server'],
292 $databaseConfig['username'],
293 $databaseConfig['password'],
294 array(
295 "MySQL $dbName Configuration",
296 "Are the access credentials correct",
297 "That username/password doesn't work",
298 )
299 )) {
300 @$this->requireMySQLVersion("5.1",
301 array(
302 "MySQL $dbName Configuration",
303 "MySQL version at least 5.1",
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
395 $this->requirePHPVersion('5.3.3', array("PHP Configuration", "PHP5 installed", NULL, "PHP version " . phpversion()));
396
397 // Check that we can identify the root folder successfully
398 $this->requireFile($crmPath . CIVICRM_DIRECTORY_SEPARATOR . 'README.txt',
399 array(
400 "File permissions",
401 "Does the webserver know where files are stored?",
402 "The webserver isn't letting me identify where files are stored.",
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(
411 'File permissions',
412 'does the CiviCRM path contain PATH_SEPARATOR?',
413 'the ' . $this->getBaseDir() . ' path contains PATH_SEPARATOR (the ' . PATH_SEPARATOR . ' character)',
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(
422 "File permissions", "$dir folder exists", "There is no $dir folder"), TRUE
423 );
424 }
425
426 $configIDSiniDir = NULL;
427 global $cmsPath;
428 if ($installType == 'drupal') {
429 $siteDir = getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']);
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,
450 array("File permissions", "Is the $dir folder writeable?", NULL),
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 == '') {
474 $webserver = "I can't tell what webserver you are running";
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',
482 array("PHP Configuration", "MySQL support", "MySQL support not included in PHP.")
483 );
484
485 // Check for JSON support
486 $this->requireFunction('json_encode',
487 array("PHP Configuration", "JSON support", "JSON support not included in PHP.")
488 );
489
490 // Check for xcache_isset and emit warning if exists
491 $this->checkXCache(array(
492 "PHP Configuration",
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(
501 "PHP Configuration",
502 "Memory allocated (PHP config option 'memory_limit')",
503 "CiviCRM needs a minimum of 32M allocated to PHP, but recommends 64M.",
504 ini_get("memory_limit"),
505 )
506 );
507
508 return $this->errors;
509 }
510
511 function requireMemory($min, $recommended, $testDetails) {
512 $this->testing($testDetails);
513 $mem = $this->getPHPMemory();
514
515 if ($mem < $min && $mem > 0) {
516 $testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated";
517 $this->error($testDetails);
518 }
519 elseif ($mem < $recommended && $mem > 0) {
520 $testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated";
521 $this->warning($testDetails);
522 }
523 elseif ($mem == 0) {
524 $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.";
525 $this->warning($testDetails);
526 }
527 }
528
529 function getPHPMemory() {
530 $memString = ini_get("memory_limit");
531
532 switch (strtolower(substr($memString, -1))) {
533 case "k":
534 return round(substr($memString, 0, -1) * 1024);
535
536 case "m":
537 return round(substr($memString, 0, -1) * 1024 * 1024);
538
539 case "g":
540 return round(substr($memString, 0, -1) * 1024 * 1024 * 1024);
541
542 default:
543 return round($memString);
544 }
545 }
546
547 function listErrors() {
548 if ($this->errors) {
549 echo "<p>The following problems are preventing me from installing CiviCRM:</p>";
550 foreach ($this->errors as $error) {
551 echo "<li>" . htmlentities($error) . "</li>";
552 }
553 }
554 }
555
556 function showTable($section = NULL) {
557 if ($section) {
558 $tests = $this->tests[$section];
559 echo "<table class=\"testResults\" width=\"100%\">";
560 foreach ($tests as $test => $result) {
561 echo "<tr class=\"$result[0]\"><td>$test</td><td>" . nl2br(htmlentities($result[1])) . "</td></tr>";
562 }
563 echo "</table>";
564 }
565 else {
566 foreach ($this->tests as $section => $tests) {
567 echo "<h3>$section</h3>";
568 echo "<table class=\"testResults\" width=\"100%\">";
569
570 foreach ($tests as $test => $result) {
571 echo "<tr class=\"$result[0]\"><td>$test</td><td>" . nl2br(htmlentities($result[1])) . "</td></tr>";
572 }
573 echo "</table>";
574 }
575 }
576 }
577
578 function requireFunction($funcName, $testDetails) {
579 $this->testing($testDetails);
580
581 if (!function_exists($funcName)) {
582 $this->error($testDetails);
583 return FALSE;
584 }
585 else {
586 return TRUE;
587 }
588 }
589
590 function checkXCache($testDetails) {
591 if (function_exists('xcache_isset') &&
592 ini_get('xcache.size') > 0
593 ) {
594 $this->testing($testDetails);
595 $this->warning($testDetails);
596 }
597 }
598
599 function requirePHPVersion($minVersion, $testDetails, $maxVersion = NULL) {
600
601 $this->testing($testDetails);
602
603 $phpVersion = phpversion();
604 $aboveMinVersion = version_compare($phpVersion, $minVersion) >= 0;
605 $belowMaxVersion = $maxVersion ? version_compare($phpVersion, $maxVersion) < 0 : TRUE;
606
607 if ($maxVersion && $aboveMinVersion && $belowMaxVersion) {
608 return TRUE;
609 }
610 elseif (!$maxVersion && $aboveMinVersion) {
611 return TRUE;
612 }
613
614 if (!$testDetails[2]) {
615 if (!$aboveMinVersion) {
616 $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.";
617 }
618 else {
619 $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.";
620 }
621 }
622
623 $this->error($testDetails);
624 }
625
626 function requireFile($filename, $testDetails, $absolute = FALSE) {
627 $this->testing($testDetails);
628 if (!$absolute) {
629 $filename = $this->getBaseDir() . $filename;
630 }
631 if (!file_exists($filename)) {
632 $testDetails[2] .= " (file '$filename' not found)";
633 $this->error($testDetails);
634 }
635 }
636
637 function requireNoPathSeparator($testDetails) {
638 $this->testing($testDetails);
639 if (substr_count($this->getBaseDir(), PATH_SEPARATOR)) {
640 $this->error($testDetails);
641 }
642 }
643
644 function requireNoFile($filename, $testDetails) {
645 $this->testing($testDetails);
646 $filename = $this->getBaseDir() . $filename;
647 if (file_exists($filename)) {
648 $testDetails[2] .= " (file '$filename' found)";
649 $this->error($testDetails);
650 }
651 }
652
653 function moveFileOutOfTheWay($filename, $testDetails) {
654 $this->testing($testDetails);
655 $filename = $this->getBaseDir() . $filename;
656 if (file_exists($filename)) {
657 if (file_exists("$filename.bak")) {
658 rm("$filename.bak");
659 }
660 rename($filename, "$filename.bak");
661 }
662 }
663
664 function requireWriteable($filename, $testDetails, $absolute = FALSE) {
665 $this->testing($testDetails);
666 if (!$absolute) {
667 $filename = $this->getBaseDir() . $filename;
668 }
669
670 if (!is_writeable($filename)) {
671 $name = NULL;
672 if (function_exists('posix_getpwuid')) {
673 $user = posix_getpwuid(posix_geteuid());
674 $name = '- ' . $user['name'] . ' -';
675 }
676
677 if (!isset($testDetails[2])) {
678 $testDetails[2] = NULL;
679 }
680 $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";
681 $this->error($testDetails);
682 }
683 }
684
685 function requireApacheModule($moduleName, $testDetails) {
686 $this->testing($testDetails);
687 if (!in_array($moduleName, apache_get_modules())) {
688 $this->error($testDetails);
689 }
690 }
691
692 function requireMysqlConnection($server, $username, $password, $testDetails) {
693 $this->testing($testDetails);
694 $conn = @mysql_connect($server, $username, $password);
695
696 if ($conn) {
697 return TRUE;
698 }
699 else {
700 $testDetails[2] .= ": " . mysql_error();
701 $this->error($testDetails);
702 }
703 }
704
705 function requireMySQLServer($server, $testDetails) {
706 $this->testing($testDetails);
707 $conn = @mysql_connect($server, NULL, NULL);
708
709 if ($conn || mysql_errno() < 2000) {
710 return TRUE;
711 }
712 else {
713 $testDetails[2] .= ": " . mysql_error();
714 $this->error($testDetails);
715 }
716 }
717
718 function requireMySQLVersion($version, $testDetails) {
719 $this->testing($testDetails);
720
721 if (!mysql_get_server_info()) {
722 $testDetails[2] = 'Cannot determine the version of MySQL installed. Please ensure at least version 4.1 is installed.';
723 $this->warning($testDetails);
724 }
725 else {
726 list($majorRequested, $minorRequested) = explode('.', $version);
727 list($majorHas, $minorHas) = explode('.', mysql_get_server_info());
728
729 if (($majorHas > $majorRequested) || ($majorHas == $majorRequested && $minorHas >= $minorRequested)) {
730 return TRUE;
731 }
732 else {
733 $testDetails[2] .= "{$majorHas}.{$minorHas}.";
734 $this->error($testDetails);
735 }
736 }
737 }
738
739 function requireMySQLInnoDB($server, $username, $password, $database, $testDetails) {
740 $this->testing($testDetails);
741 $conn = @mysql_connect($server, $username, $password);
742 if (!$conn) {
743 $testDetails[2] .= ' Could not determine if mysql has innodb support. Assuming no';
744 $this->error($testDetails);
745 return;
746 }
747
748 $innodb_support = FALSE;
749 $result = mysql_query("SHOW ENGINES", $conn);
750 while ($values = mysql_fetch_array($result)) {
751 if ($values['Engine'] == 'InnoDB') {
752 if (strtolower($values['Support']) == 'yes' ||
753 strtolower($values['Support']) == 'default'
754 ) {
755 $innodb_support = TRUE;
756 }
757 }
758 }
759 if ($innodb_support) {
760 $testDetails[3] = 'MySQL server does have innodb support';
761 }
762 else {
763 $testDetails[2] .= ' Could not determine if mysql has innodb support. Assuming no';
764 }
765 }
766
767 function requireMySQLTempTables($server, $username, $password, $database, $testDetails) {
768 $this->testing($testDetails);
769 $conn = @mysql_connect($server, $username, $password);
770 if (!$conn) {
771 $testDetails[2] = 'Could not login to the database.';
772 $this->error($testDetails);
773 return;
774 }
775
776 if (!@mysql_select_db($database, $conn)) {
777 $testDetails[2] = 'Could not select the database.';
778 $this->error($testDetails);
779 return;
780 }
781
782 $result = mysql_query('CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)', $conn);
783 if (!$result) {
784 $testDetails[2] = 'Could not create a temp table.';
785 $this->error($testDetails);
786 }
787 $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
788 }
789
790 function requireMySQLTrigger($server, $username, $password, $database, $testDetails) {
791 $this->testing($testDetails);
792 $conn = @mysql_connect($server, $username, $password);
793 if (!$conn) {
794 $testDetails[2] = 'Could not login to the database.';
795 $this->error($testDetails);
796 return;
797 }
798
799 if (!@mysql_select_db($database, $conn)) {
800 $testDetails[2] = 'Could not select the database.';
801 $this->error($testDetails);
802 return;
803 }
804
805 $result = mysql_query('CREATE TABLE civicrm_install_temp_table_test (test text)', $conn);
806 if (!$result) {
807 $testDetails[2] = 'Could not create a table.';
808 $this->error($testDetails);
809 }
810
811 $result = mysql_query('CREATE TRIGGER civicrm_install_temp_table_test_trigger BEFORE INSERT ON civicrm_install_temp_table_test FOR EACH ROW BEGIN END');
812 if (!$result) {
813 mysql_query('DROP TABLE civicrm_install_temp_table_test');
814 $testDetails[2] = 'Could not create a trigger.';
815 $this->error($testDetails);
816 }
817
818
819 mysql_query('DROP TRIGGER civicrm_install_temp_table_test_trigger');
820 mysql_query('DROP TABLE civicrm_install_temp_table_test');
821 }
822
823
824 function requireMySQLLockTables($server, $username, $password, $database, $testDetails) {
825 $this->testing($testDetails);
826 $conn = @mysql_connect($server, $username, $password);
827 if (!$conn) {
828 $testDetails[2] = 'Could not login to the database.';
829 $this->error($testDetails);
830 return;
831 }
832
833 if (!@mysql_select_db($database, $conn)) {
834 $testDetails[2] = 'Could not select the database.';
835 $this->error($testDetails);
836 return;
837 }
838
839 $result = mysql_query('CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)', $conn);
840 if (!$result) {
841 $testDetails[2] = 'Could not create a table.';
842 $this->error($testDetails);
843 return;
844 }
845
846 $result = mysql_query('LOCK TABLES civicrm_install_temp_table_test WRITE', $conn);
847 if (!$result) {
848 $testDetails[2] = 'Could not obtain a write lock for the table.';
849 $this->error($testDetails);
850 $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
851 return;
852 }
853
854 $result = mysql_query('UNLOCK TABLES', $conn);
855 if (!$result) {
856 $testDetails[2] = 'Could not release the lock for the table.';
857 $this->error($testDetails);
858 $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
859 return;
860 }
861
862 $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
863 return;
864 }
865
866 function requireMySQLAutoIncrementIncrementOne($server, $username, $password, $testDetails) {
867 $this->testing($testDetails);
868 $conn = @mysql_connect($server, $username, $password);
869 if (!$conn) {
870 $testDetails[2] = 'Could not connect to the database server.';
871 $this->error($testDetails);
872 return;
873 }
874
875 $result = mysql_query("SHOW variables like 'auto_increment_increment'", $conn);
876 if (!$result) {
877 $testDetails[2] = 'Could not query database server variables.';
878 $this->error($testDetails);
879 return;
880 }
881 else {
882 $values = mysql_fetch_row($result);
883 if ($values[1] == 1) {
884 $testDetails[3] = 'MySQL server auto_increment_increment is 1';
885 }
886 else {
887 $this->error($testDetails);
888 }
889 }
890 }
891
892 function requireMySQLThreadStack($server, $username, $password, $database, $minValueKB, $testDetails) {
893 $this->testing($testDetails);
894 $conn = @mysql_connect($server, $username, $password);
895 if (!$conn) {
896 $testDetails[2] = 'Could not login to the database.';
897 $this->error($testDetails);
898 return;
899 }
900
901 if (!@mysql_select_db($database, $conn)) {
902 $testDetails[2] = 'Could not select the database.';
903 $this->error($testDetails);
904 return;
905 }
906
032c9d10 907 $result = mysql_query("SHOW VARIABLES LIKE 'thread_stack'", $conn); // bytes => kb
6a488035
TO
908 if (!$result) {
909 $testDetails[2] = 'Could not query thread_stack.';
910 $this->error($testDetails);
911 } else {
912 $values = mysql_fetch_row($result);
032c9d10
TO
913 if ($values[1] < (1024*$minValueKB)) {
914 $testDetails[2] = 'MySQL "thread_stack" is ' . ($values[1]/1024) . 'k';
6a488035
TO
915 $this->error($testDetails);
916 }
917 }
918 }
919
920 function requireDatabaseOrCreatePermissions($server,
921 $username,
922 $password,
923 $database,
924 $testDetails,
925 $onlyRequire = FALSE
926 ) {
927 $this->testing($testDetails);
928 $conn = @mysql_connect($server, $username, $password);
929
930 $okay = NULL;
931 if (@mysql_select_db($database)) {
932 $okay = "Database '$database' exists";
933 }
934 elseif ($onlyRequire) {
935 $testDetails[2] = "The database: '$database' does not exist";
936 $this->error($testDetails);
937 return;
938 }
939 else {
940 if (@mysql_query("CREATE DATABASE $database")) {
941 $okay = "Able to create a new database";
942 }
943 else {
944 $testDetails[2] .= " (user '$username' doesn't have CREATE DATABASE permissions.)";
945 $this->error($testDetails);
946 return;
947 }
948 }
949
950 if ($okay) {
951 $testDetails[3] = $okay;
952 $this->testing($testDetails);
953 }
954 }
955
956 function requireServerVariables($varNames, $errorMessage) {
957 //$this->testing($testDetails);
958 foreach ($varNames as $varName) {
959 if (!$_SERVER[$varName]) {
960 $missing[] = '$_SERVER[' . $varName . ']';
961 }
962 }
963 if (!isset($missing)) {
964 return TRUE;
965 }
966 else {
967 $testDetails[2] .= " (the following PHP variables are missing: " . implode(", ", $missing) . ")";
968 $this->error($testDetails);
969 }
970 }
971
972 function isRunningApache($testDetails) {
973 $this->testing($testDetails);
974 if (function_exists('apache_get_modules') || stristr($_SERVER['SERVER_SIGNATURE'], 'Apache')) {
975 return TRUE;
976 }
977
978 $this->warning($testDetails);
979 return FALSE;
980 }
981
982 function getBaseDir() {
983 return dirname($_SERVER['SCRIPT_FILENAME']) . CIVICRM_DIRECTORY_SEPARATOR;
984 }
985
986 function testing($testDetails) {
987 if (!$testDetails) {
988 return;
989 }
990
991 $section = $testDetails[0];
992 $test = $testDetails[1];
993
994 $message = "OK";
995 if (isset($testDetails[3])) {
996 $message .= " ($testDetails[3])";
997 }
998
999 $this->tests[$section][$test] = array("good", $message);
1000 }
1001
1002 function error($testDetails) {
1003 $section = $testDetails[0];
1004 $test = $testDetails[1];
1005
1006 $this->tests[$section][$test] = array("error", $testDetails[2]);
1007 $this->errors[] = $testDetails;
1008 }
1009
1010 function warning($testDetails) {
1011 $section = $testDetails[0];
1012 $test = $testDetails[1];
1013
1014
1015 $this->tests[$section][$test] = array("warning", $testDetails[2]);
1016 $this->warnings[] = $testDetails;
1017 }
1018
1019 function hasErrors() {
1020 return sizeof($this->errors);
1021 }
1022
1023 function hasWarnings() {
1024 return sizeof($this->warnings);
1025 }
1026}
1027
1028class Installer extends InstallRequirements {
1029 function createDatabaseIfNotExists($server, $username, $password, $database) {
1030 $conn = @mysql_connect($server, $username, $password);
1031
1032 if (@mysql_select_db($database)) {
1033 // skip if database already present
1034 return;
1035 }
1036
1037 if (@mysql_query("CREATE DATABASE $database")) {}
1038 else {
1039 $errorTitle = "Oops! Could not create Database $database";
1040 $errorMsg = "We encountered an error when attempting to create the database. Please check your mysql server permissions and the database name and try again.";
1041 errorDisplayPage($errorTitle, $errorMsg);
1042 }
1043 }
1044
1045 function install($config) {
1046 global $installDirPath;
1047
1048 // create database if does not exists
1049 $this->createDatabaseIfNotExists($config['mysql']['server'],
1050 $config['mysql']['username'],
1051 $config['mysql']['password'],
1052 $config['mysql']['database']
1053 );
1054
1055 global $installDirPath;
1056
1057 // Build database
1058 require_once $installDirPath . 'civicrm.php';
1059 civicrm_main($config);
1060
1061 if (!$this->errors) {
1062 global $installType, $installURLPath;
1063
1064 $output = NULL;
1065 if (
1066 $installType == 'drupal' &&
1067 version_compare(VERSION, '7.0-rc1') >= 0
1068 ) {
1069
1070 // clean output
1071 @ob_clean();
1072
1073 $output .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
1074 $output .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1075 $output .= '<head>';
1076 $output .= '<title>CiviCRM Installed</title>';
1077 $output .= '<link rel="stylesheet" type="text/css" href="template.css" />';
1078 $output .= '</head>';
1079 $output .= '<body>';
1080 $output .= '<div style="padding: 1em;"><p class="good">CiviCRM has been successfully installed</p>';
1081 $output .= '<ul>';
1082 $docLinkConfig = CRM_Utils_System::docURL2('Configuring a New Site', FALSE, 'here',NULL,NULL,"wiki");
1083 if (!function_exists('ts')) {
1084 $docLinkConfig = "<a href=\"{$docLinkConfig}\">here</a>";
1085 }
1086 $drupalURL = civicrm_cms_base();
1087 $drupalPermissionsURL = "{$drupalURL}index.php?q=admin/people/permissions";
1088 $drupalURL .= "index.php?q=civicrm/admin/configtask&reset=1";
1089 $registerSiteURL = "http://civicrm.org/civicrm/profile/create?reset=1&gid=15";
1090
1091 $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>
1092 <li>Use the <a target='_blank' href=\"$drupalURL\">Configuration Checklist</a> to review and configure settings for your new site</li>
1093 <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>
1094 <li>We have integrated KCFinder with CKEditor and TinyMCE, which enables user to upload images. Note that all the images uploaded using KCFinder will be public.</li>";
1095
1096 // automatically enable CiviCRM module once it is installed successfully.
1097 // so we need to Bootstrap Drupal, so that we can call drupal hooks.
1098 global $cmsPath, $crmPath;
1099
1100 // relative / abosolute paths are not working for drupal, hence using chdir()
1101 chdir($cmsPath);
1102
1103 include_once "./includes/bootstrap.inc";
1104 include_once "./includes/unicode.inc";
1105
1106 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
1107
1108 // prevent session information from being saved.
1109 drupal_save_session(FALSE);
1110
1111 // Force the current user to anonymous.
1112 $original_user = $GLOBALS['user'];
1113 $GLOBALS['user'] = drupal_anonymous_user();
1114
1115 // explicitly setting error reporting, since we cannot handle drupal related notices
1116 error_reporting(1);
1117
1118 // rebuild modules, so that civicrm is added
1119 system_rebuild_module_data();
1120
1121 // now enable civicrm module.
1122 module_enable(array('civicrm', 'civicrmtheme'));
1123
1124 // clear block and page cache, to make sure civicrm link is present in navigation block
1125 cache_clear_all();
1126
1127 //add basic drupal permissions
1128 civicrm_install_set_drupal_perms();
1129
1130 // restore the user.
1131 $GLOBALS['user'] = $original_user;
1132 drupal_save_session(TRUE);
1133
1134 $output .= '</ul>';
1135 $output .= '</div>';
1136 $output .= '</body>';
1137 $output .= '</html>';
1138 echo $output;
1139 }
1140 elseif ($installType == 'drupal' && version_compare(VERSION, '6.0') >= 0) {
1141 // clean output
1142 @ob_clean();
1143
1144 $output .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
1145 $output .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1146 $output .= '<head>';
1147 $output .= '<title>CiviCRM Installed</title>';
1148 $output .= '<link rel="stylesheet" type="text/css" href="template.css" />';
1149 $output .= '</head>';
1150 $output .= '<body>';
1151 $output .= '<div style="padding: 1em;"><p class="good">CiviCRM has been successfully installed</p>';
1152 $output .= '<ul>';
1153 $docLinkConfig = CRM_Utils_System::docURL2('Configuring a New Site', FALSE, 'here',NULL,NULL,"wiki");
1154 if (!function_exists('ts')) {
1155 $docLinkConfig = "<a href=\"{$docLinkConfig}\">here</a>";
1156 }
1157 $drupalURL = civicrm_cms_base();
1158 $drupalPermissionsURL = "{$drupalURL}index.php?q=admin/user/permissions";
1159 $drupalURL .= "index.php?q=civicrm/admin/configtask&reset=1";
1160 $registerSiteURL = "http://civicrm.org/civicrm/profile/create?reset=1&gid=15";
1161
1162 $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>
1163 <li>Use the <a target='_blank' href=\"$drupalURL\">Configuration Checklist</a> to review and configure settings for your new site</li>
1164 <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>
1165 <li>We have integrated KCFinder with CKEditor and TinyMCE, which enables user to upload images. Note that all the images uploaded using KCFinder will be public.</li>";
1166
1167 // explicitly setting error reporting, since we cannot handle drupal related notices
1168 error_reporting(1);
1169
1170 // automatically enable CiviCRM module once it is installed successfully.
1171 // so we need to Bootstrap Drupal, so that we can call drupal hooks.
1172 global $cmsPath, $crmPath;
1173
1174 // relative / abosolute paths are not working for drupal, hence using chdir()
1175 chdir($cmsPath);
1176
1177 include_once "./includes/bootstrap.inc";
1178 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
1179
1180 // rebuild modules, so that civicrm is added
1181 module_rebuild_cache();
1182
1183 // now enable civicrm module.
1184 module_enable(array('civicrm'));
1185
1186 // clear block and page cache, to make sure civicrm link is present in navigation block
1187 cache_clear_all();
1188
1189 //add basic drupal permissions
1190 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)');
1191
1192 echo $output;
1193 }
1194 elseif ($installType == 'wordpress') {
1195 echo '<h1>CiviCRM Installed</h1>';
1196 echo '<div style="padding: 1em;"><p style="background-color: #0C0; border: 1px #070 solid; color: white;">CiviCRM has been successfully installed</p>';
1197 echo '<ul>';
1198 $docLinkConfig = CRM_Utils_System::docURL2('Configuring a New Site', FALSE, 'here',NULL,NULL,"wiki");
1199 if (!function_exists('ts')) {
1200 $docLinkConfig = "<a href=\"{$docLinkConfig}\">here</a>";
1201 }
1202
1203 $cmsURL = civicrm_cms_base();
1204 $cmsURL .= "wp-admin/admin.php?page=CiviCRM&q=civicrm/admin/configtask&reset=1";
1205 $registerSiteURL = "http://civicrm.org/civicrm/profile/create?reset=1&gid=15";
1206
1207 echo "<li>Use the <a target='_blank' href=\"$cmsURL\">Configuration Checklist</a> to review and configure settings for your new site</li>
1208 <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>
1209 <li>We have integrated KCFinder with CKEditor and TinyMCE, which enables user to upload images. Note that all the images uploaded using KCFinder will be public.</li>";
1210 echo '</ul>';
1211 echo '</div>';
1212 }
1213 }
1214
1215 return $this->errors;
1216 }
1217}
1218
1219function civicrm_install_set_drupal_perms() {
1220 if (!function_exists('db_select')) {
1221 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)');
1222 }
1223 else {
1224 $perms = array(
1225 'access all custom data',
1226 'access uploaded files',
1227 'make online contributions',
1228 'profile create',
1229 'profile edit',
1230 'profile view',
1231 'register for events',
1232 'view event info',
1233 'view event participants',
1234 'access CiviMail subscribe/unsubscribe pages',
1235 );
1236
1237 // Adding a permission that has not yet been assigned to a module by
1238 // a hook_permission implementation results in a database error.
1239 // CRM-9042
1240 $allPerms = array_keys(module_invoke_all('permission'));
1241 foreach (array_diff($perms, $allPerms) as $perm) {
1242 watchdog('civicrm',
1243 'Cannot grant the %perm permission because it does not yet exist.',
1244 array(
1245 '%perm' => $perm), WATCHDOG_ERROR
1246 );
1247 }
1248 $perms = array_intersect($perms, $allPerms);
1249 user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, $perms);
1250 user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, $perms);
1251 }
1252}
1253
1254function getSiteDir($cmsPath, $str) {
1255 static $siteDir = '';
1256
1257 if ($siteDir) {
1258 return $siteDir;
1259 }
1260
1261 $sites = CIVICRM_DIRECTORY_SEPARATOR . 'sites' . CIVICRM_DIRECTORY_SEPARATOR;
1262 $modules = CIVICRM_DIRECTORY_SEPARATOR . 'modules' . CIVICRM_DIRECTORY_SEPARATOR;
1263 preg_match("/" . preg_quote($sites, CIVICRM_DIRECTORY_SEPARATOR) .
1264 "([\-a-zA-Z0-9_.]+)" .
1265 preg_quote($modules, CIVICRM_DIRECTORY_SEPARATOR) . "/",
1266 $_SERVER['SCRIPT_FILENAME'], $matches
1267 );
1268 $siteDir = isset($matches[1]) ? $matches[1] : 'default';
1269
1270 if (strtolower($siteDir) == 'all') {
1271 // For this case - use drupal's way of finding out multi-site directory
1272 $uri = explode(CIVICRM_DIRECTORY_SEPARATOR, $_SERVER['SCRIPT_FILENAME']);
1273 $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
1274 for ($i = count($uri) - 1; $i > 0; $i--) {
1275 for ($j = count($server); $j > 0; $j--) {
1276 $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
1277 if (file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
1278 'sites' . CIVICRM_DIRECTORY_SEPARATOR . $dir
1279 )) {
1280 $siteDir = $dir;
1281 return $siteDir;
1282 }
1283 }
1284 }
1285 $siteDir = 'default';
1286 }
1287
1288 return $siteDir;
1289}
1290
1291function errorDisplayPage($errorTitle, $errorMsg) {
1292 include ('error.html');
1293 exit();
1294}
1295