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