2007-10-10 19:15:47 +04:00
|
|
|
<?php
|
|
|
|
/*
|
2009-06-04 02:44:32 +04:00
|
|
|
* This file is part of Mibew Messenger project.
|
2009-08-04 20:30:39 +04:00
|
|
|
*
|
2009-06-04 02:44:32 +04:00
|
|
|
* Copyright (c) 2005-2009 Mibew Messenger Community
|
2009-08-04 19:03:27 +04:00
|
|
|
* All rights reserved. The contents of this file are subject to the terms of
|
|
|
|
* the Eclipse Public License v1.0 which accompanies this distribution, and
|
|
|
|
* is available at http://www.eclipse.org/legal/epl-v10.html
|
2009-08-04 20:30:39 +04:00
|
|
|
*
|
2009-08-04 17:38:37 +04:00
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* the GNU General Public License Version 2 or later (the "GPL"), in which case
|
|
|
|
* the provisions of the GPL are applicable instead of those above. If you wish
|
|
|
|
* to allow use of your version of this file only under the terms of the GPL, and
|
|
|
|
* not to allow others to use your version of this file under the terms of the
|
|
|
|
* EPL, indicate your decision by deleting the provisions above and replace them
|
|
|
|
* with the notice and other provisions required by the GPL.
|
2009-08-04 20:30:39 +04:00
|
|
|
*
|
2007-10-10 19:15:47 +04:00
|
|
|
* Contributors:
|
|
|
|
* Evgeny Gryaznov - initial API and implementation
|
|
|
|
*/
|
|
|
|
|
2008-06-05 01:36:54 +04:00
|
|
|
require_once('../libs/common.php');
|
2009-02-04 03:31:26 +03:00
|
|
|
require_once('../libs/settings.php');
|
2008-06-05 01:36:54 +04:00
|
|
|
require_once('dbinfo.php');
|
2007-10-17 14:43:34 +04:00
|
|
|
|
|
|
|
$page = array(
|
|
|
|
'version' => $version,
|
2007-10-30 15:13:04 +03:00
|
|
|
'localeLinks' => get_locale_links("$webimroot/install/index.php")
|
2007-10-17 14:43:34 +04:00
|
|
|
);
|
|
|
|
|
|
|
|
$page['done'] = array();
|
|
|
|
$page['nextstep'] = false;
|
|
|
|
$page['nextnotice'] = false;
|
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
function check_connection() {
|
2008-09-30 02:59:58 +04:00
|
|
|
global $mysqlhost,$mysqllogin,$mysqlpass, $page, $errors, $webimroot;
|
2007-10-17 14:43:34 +04:00
|
|
|
$link = @mysql_connect($mysqlhost,$mysqllogin,$mysqlpass);
|
|
|
|
if ($link) {
|
|
|
|
$result = mysql_query("SELECT VERSION() as c", $link);
|
|
|
|
if( $result && $ver = mysql_fetch_array($result, MYSQL_ASSOC)) {
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['done'][] = getlocal2("install.1.connected", array($ver['c']));
|
2007-10-17 14:43:34 +04:00
|
|
|
mysql_free_result($result);
|
|
|
|
} else {
|
|
|
|
$errors[] = "Version of your SQL server is unknown. Please check. Error: ".mysql_error();
|
|
|
|
mysql_close($link);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $link;
|
|
|
|
} else {
|
2008-05-06 15:14:48 +04:00
|
|
|
$errors[] = getlocal2("install.connection.error", array(mysql_error()));
|
2007-10-17 14:43:34 +04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_database($link) {
|
2008-09-30 02:59:58 +04:00
|
|
|
global $mysqldb, $force_charset_in_connection, $dbencoding, $page, $webimroot;
|
2007-10-17 14:43:34 +04:00
|
|
|
if(mysql_select_db($mysqldb,$link)) {
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['done'][] = getlocal2("install.2.db_exists", array($mysqldb));
|
2007-10-17 14:43:34 +04:00
|
|
|
if( $force_charset_in_connection ) {
|
|
|
|
mysql_query("SET character set $dbencoding", $link);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['nextstep'] = getlocal2("install.2.create", array($mysqldb));
|
|
|
|
$page['nextnotice'] = getlocal("install.2.notice");
|
2008-09-30 02:59:58 +04:00
|
|
|
$page['nextstepurl'] = "$webimroot/install/dbperform.php?act=createdb";
|
2007-10-17 14:43:34 +04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_tables($link) {
|
2008-09-30 02:59:58 +04:00
|
|
|
global $dbtables, $page, $webimroot;
|
2007-10-17 14:43:34 +04:00
|
|
|
$curr_tables = get_tables($link);
|
|
|
|
if( $curr_tables !== false) {
|
|
|
|
$tocreate = array_diff(array_keys($dbtables), $curr_tables);
|
|
|
|
if( count($tocreate) == 0 ) {
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['done'][] = getlocal("install.3.tables_exist");
|
2007-10-17 14:43:34 +04:00
|
|
|
return true;
|
|
|
|
} else {
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['nextstep'] = getlocal("install.3.create");
|
2009-05-31 19:29:55 +04:00
|
|
|
$page['nextstepurl'] = "$webimroot/install/dbperform.php?act=ct";
|
2007-10-17 14:43:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_columns($link) {
|
2008-09-30 02:59:58 +04:00
|
|
|
global $dbtables, $dbtables_can_update, $errors, $page, $webimroot;
|
2007-10-17 14:43:34 +04:00
|
|
|
|
|
|
|
$need_to_create_columns = false;
|
|
|
|
foreach( $dbtables as $id => $columns) {
|
|
|
|
$curr_columns = get_columns($id, $link);
|
|
|
|
if( $curr_columns === false ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$tocreate = array_diff(array_keys($columns), $curr_columns);
|
|
|
|
if( count($tocreate) != 0 ) {
|
|
|
|
$cannot_update = array_diff($tocreate, $dbtables_can_update[$id]);
|
|
|
|
if( count($cannot_update) != 0) {
|
|
|
|
$errors[] = "Key columns are absent in table `$id'. Unable to continue installation.";
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['nextstep'] = getlocal("install.kill_tables");
|
2009-05-31 19:29:55 +04:00
|
|
|
$page['nextstepurl'] = "$webimroot/install/dbperform.php?act=dt";
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['nextnotice'] = getlocal("install.kill_tables.notice");
|
2007-10-17 14:43:34 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$need_to_create_columns = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $need_to_create_columns ) {
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['nextstep'] = getlocal("install.4.create");
|
2008-09-30 02:59:58 +04:00
|
|
|
$page['nextstepurl'] = "$webimroot/install/dbperform.php?act=addcolumns";
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['nextnotice'] = getlocal("install.4.notice");
|
2007-10-17 14:43:34 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['done'][] = getlocal("install.4.done");
|
2007-10-17 14:43:34 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_status() {
|
2009-02-04 03:31:26 +03:00
|
|
|
global $page, $webimroot, $settings, $dbversion;
|
2007-10-17 14:43:34 +04:00
|
|
|
$link = check_connection();
|
|
|
|
if(!$link) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !check_database($link)) {
|
|
|
|
mysql_close($link);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !check_tables($link)) {
|
|
|
|
mysql_close($link);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !check_columns($link)) {
|
|
|
|
mysql_close($link);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['done'][] = getlocal("installed.message");
|
2007-10-17 14:43:34 +04:00
|
|
|
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['nextstep'] = getlocal("installed.login_link");
|
|
|
|
$page['nextnotice'] = getlocal("installed.notice");
|
2007-10-30 15:13:04 +03:00
|
|
|
$page['nextstepurl'] = "$webimroot/";
|
2009-03-13 03:52:37 +03:00
|
|
|
|
|
|
|
$page['show_small_login'] = true;
|
2007-10-17 14:43:34 +04:00
|
|
|
|
|
|
|
mysql_close($link);
|
2009-02-04 03:31:26 +03:00
|
|
|
|
|
|
|
loadsettings();
|
|
|
|
$settings['dbversion'] = $dbversion;
|
|
|
|
update_settings();
|
2007-10-17 14:43:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
check_status();
|
2007-10-10 19:15:47 +04:00
|
|
|
|
|
|
|
start_html_output();
|
2009-03-12 04:07:35 +03:00
|
|
|
require('../view/install_index.php');
|
2007-10-17 14:43:34 +04:00
|
|
|
?>
|