2007-10-17 14:43:34 +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
|
|
|
*
|
2011-02-16 03:22:22 +03:00
|
|
|
* Copyright (c) 2005-2011 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-17 14:43:34 +04:00
|
|
|
* Contributors:
|
|
|
|
* Evgeny Gryaznov - initial API and implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
$dbtables = array(
|
2011-02-26 16:13:16 +03:00
|
|
|
"${mysqlprefix}chatgroup" => array(
|
2009-03-23 00:22:51 +03:00
|
|
|
"groupid" => "int NOT NULL auto_increment PRIMARY KEY",
|
2009-08-19 03:29:05 +04:00
|
|
|
"vcemail" => "varchar(64)",
|
2009-03-17 00:49:45 +03:00
|
|
|
"vclocalname" => "varchar(64) NOT NULL",
|
|
|
|
"vccommonname" => "varchar(64) NOT NULL",
|
|
|
|
"vclocaldescription" => "varchar(1024) NOT NULL",
|
|
|
|
"vccommondescription" => "varchar(1024) NOT NULL",
|
2009-01-03 04:23:19 +03:00
|
|
|
),
|
|
|
|
|
2011-02-26 16:13:16 +03:00
|
|
|
"${mysqlprefix}chatthread" => array(
|
2007-10-17 14:43:34 +04:00
|
|
|
"threadid" => "int NOT NULL auto_increment PRIMARY KEY",
|
|
|
|
"userName" => "varchar(64) NOT NULL",
|
2008-10-03 19:11:02 +04:00
|
|
|
"userid" => "varchar(255)",
|
2007-10-17 14:43:34 +04:00
|
|
|
"agentName" => "varchar(64)",
|
|
|
|
"agentId" => "int NOT NULL DEFAULT 0",
|
|
|
|
"dtmcreated" => "datetime DEFAULT 0",
|
|
|
|
"dtmmodified" => "datetime DEFAULT 0",
|
|
|
|
"lrevision" => "int NOT NULL DEFAULT 0",
|
|
|
|
"istate" => "int NOT NULL DEFAULT 0",
|
|
|
|
"ltoken" => "int NOT NULL",
|
|
|
|
"remote" => "varchar(255)",
|
|
|
|
"referer" => "text",
|
2008-10-02 13:35:49 +04:00
|
|
|
"nextagent" => "int NOT NULL DEFAULT 0",
|
2007-10-17 14:43:34 +04:00
|
|
|
"locale" => "varchar(8)",
|
|
|
|
"lastpinguser" => "datetime DEFAULT 0",
|
2007-12-03 00:32:47 +03:00
|
|
|
"lastpingagent" => "datetime DEFAULT 0",
|
2008-05-11 02:35:16 +04:00
|
|
|
"userTyping" => "int DEFAULT 0",
|
|
|
|
"agentTyping" => "int DEFAULT 0",
|
2008-10-03 19:11:02 +04:00
|
|
|
"shownmessageid" => "int NOT NULL DEFAULT 0",
|
|
|
|
"userAgent" => "varchar(255)",
|
2009-01-03 04:23:19 +03:00
|
|
|
"messageCount" => "varchar(16)",
|
2011-02-26 16:13:16 +03:00
|
|
|
"groupid" => "int references ${mysqlprefix}chatgroup(groupid)",
|
2007-10-17 14:43:34 +04:00
|
|
|
),
|
|
|
|
|
2011-02-26 16:13:16 +03:00
|
|
|
"${mysqlprefix}chatmessage" => array(
|
2007-10-17 14:43:34 +04:00
|
|
|
"messageid" => "int NOT NULL auto_increment PRIMARY KEY",
|
2011-02-26 16:13:16 +03:00
|
|
|
"threadid" => "int NOT NULL references ${mysqlprefix}chatthread(threadid)",
|
2007-10-17 14:43:34 +04:00
|
|
|
"ikind" => "int NOT NULL",
|
|
|
|
"agentId" => "int NOT NULL DEFAULT 0",
|
|
|
|
"tmessage" => "text NOT NULL",
|
|
|
|
"dtmcreated" => "datetime DEFAULT 0",
|
|
|
|
"tname" => "varchar(64)"
|
|
|
|
),
|
|
|
|
|
2011-02-26 16:13:16 +03:00
|
|
|
"${mysqlprefix}chatoperator" => array(
|
2007-10-17 14:43:34 +04:00
|
|
|
"operatorid" => "int NOT NULL auto_increment PRIMARY KEY",
|
|
|
|
"vclogin" => "varchar(64) NOT NULL",
|
|
|
|
"vcpassword" => "varchar(64) NOT NULL",
|
|
|
|
"vclocalename" => "varchar(64) NOT NULL",
|
|
|
|
"vccommonname" => "varchar(64) NOT NULL",
|
2009-08-19 03:29:05 +04:00
|
|
|
"vcemail" => "varchar(64)",
|
2007-10-17 14:43:34 +04:00
|
|
|
"dtmlastvisited" => "datetime DEFAULT 0",
|
2009-07-24 11:37:58 +04:00
|
|
|
"istatus" => "int DEFAULT 0", /* 0 - online, 1 - away */
|
2008-10-06 02:47:09 +04:00
|
|
|
"vcavatar" => "varchar(255)",
|
|
|
|
"vcjabbername" => "varchar(255)",
|
2008-12-08 03:34:28 +03:00
|
|
|
"iperm" => "int DEFAULT 65535",
|
2009-09-01 02:43:30 +04:00
|
|
|
"dtmrestore" => "datetime DEFAULT 0",
|
|
|
|
"vcrestoretoken" => "varchar(64)",
|
2007-10-17 14:43:34 +04:00
|
|
|
),
|
2008-09-30 03:07:06 +04:00
|
|
|
|
2011-02-26 16:13:16 +03:00
|
|
|
"${mysqlprefix}chatrevision" => array(
|
2007-10-17 14:43:34 +04:00
|
|
|
"id" => "INT NOT NULL"
|
2008-09-30 03:07:06 +04:00
|
|
|
),
|
|
|
|
|
2011-02-26 16:13:16 +03:00
|
|
|
"${mysqlprefix}chatgroupoperator" => array(
|
|
|
|
"groupid" => "int NOT NULL references ${mysqlprefix}chatgroup(groupid)",
|
|
|
|
"operatorid" => "int NOT NULL references ${mysqlprefix}chatoperator(operatorid)",
|
2009-01-03 04:23:19 +03:00
|
|
|
),
|
|
|
|
|
2011-02-26 16:13:16 +03:00
|
|
|
"${mysqlprefix}chatban" => array(
|
2008-10-04 03:35:17 +04:00
|
|
|
"banid" => "INT NOT NULL auto_increment PRIMARY KEY",
|
|
|
|
"dtmcreated" => "datetime DEFAULT 0",
|
|
|
|
"dtmtill" => "datetime DEFAULT 0",
|
|
|
|
"address" => "varchar(255)",
|
|
|
|
"comment" => "varchar(255)",
|
|
|
|
"blockedCount" => "int DEFAULT 0"
|
|
|
|
),
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
"${mysqlprefix}chatconfig" => array(
|
2008-09-30 03:07:06 +04:00
|
|
|
"id" => "INT NOT NULL auto_increment PRIMARY KEY",
|
|
|
|
"vckey" => "varchar(255)",
|
|
|
|
"vcvalue" => "varchar(255)",
|
2009-04-09 02:40:26 +04:00
|
|
|
),
|
|
|
|
|
2011-02-26 16:13:16 +03:00
|
|
|
"${mysqlprefix}chatresponses" => array(
|
2009-04-09 02:40:26 +04:00
|
|
|
"id" => "INT NOT NULL auto_increment PRIMARY KEY",
|
|
|
|
"locale" => "varchar(8)",
|
2011-02-26 16:13:16 +03:00
|
|
|
"groupid" => "int references ${mysqlprefix}chatgroup(groupid)",
|
2009-04-09 02:40:26 +04:00
|
|
|
"vcvalue" => "varchar(1024) NOT NULL",
|
2007-10-17 14:43:34 +04:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2008-05-10 03:19:11 +04:00
|
|
|
$memtables = array();
|
|
|
|
|
2007-10-17 14:43:34 +04:00
|
|
|
$dbtables_can_update = array(
|
2011-02-26 16:13:16 +03:00
|
|
|
"${mysqlprefix}chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount", "nextagent", "shownmessageid", "userid", "userAgent", "groupid"),
|
|
|
|
"${mysqlprefix}chatmessage" => array("agentId"),
|
|
|
|
"${mysqlprefix}chatoperator" => array("vcavatar", "vcjabbername", "iperm", "istatus", "vcemail", "dtmrestore", "vcrestoretoken"),
|
|
|
|
"${mysqlprefix}chatban" => array(),
|
|
|
|
"${mysqlprefix}chatgroup" => array("vcemail"),
|
|
|
|
"${mysqlprefix}chatgroupoperator" => array(),
|
|
|
|
"${mysqlprefix}chatresponses" => array(),
|
2007-10-17 14:43:34 +04:00
|
|
|
);
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
function show_install_err($text)
|
|
|
|
{
|
2007-10-30 15:13:04 +03:00
|
|
|
global $page, $version, $errors, $webimroot;
|
2008-09-30 03:07:06 +04:00
|
|
|
$page = array(
|
2007-10-17 14:43:34 +04:00
|
|
|
'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
|
|
|
);
|
|
|
|
$errors = array($text);
|
|
|
|
start_html_output();
|
2009-03-12 04:07:35 +03:00
|
|
|
require('../view/install_err.php');
|
2008-09-30 03:07:06 +04:00
|
|
|
exit;
|
2007-10-17 14:43:34 +04:00
|
|
|
}
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
function create_table($id, $link)
|
|
|
|
{
|
2011-02-26 16:13:16 +03:00
|
|
|
global $dbtables, $memtables, $dbencoding, $mysqlprefix;
|
2008-09-30 03:07:06 +04:00
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
if (!isset($dbtables[$id])) {
|
|
|
|
show_install_err("Unknown table: $id, " . mysql_error($link));
|
2007-10-17 14:43:34 +04:00
|
|
|
}
|
2008-09-30 03:07:06 +04:00
|
|
|
|
|
|
|
$query =
|
2011-02-26 16:57:23 +03:00
|
|
|
"CREATE TABLE $id\n" .
|
|
|
|
"(\n";
|
|
|
|
foreach ($dbtables[$id] as $k => $v) {
|
2008-09-30 03:07:06 +04:00
|
|
|
$query .= " $k $v,\n";
|
2007-10-17 14:43:34 +04:00
|
|
|
}
|
2008-09-30 03:07:06 +04:00
|
|
|
|
2007-10-17 14:43:34 +04:00
|
|
|
$query = preg_replace("/,\n$/", "", $query);
|
2008-05-10 03:19:11 +04:00
|
|
|
$query .= ") charset $dbencoding";
|
|
|
|
if (in_array($id, $memtables)) {
|
|
|
|
$query .= " ENGINE=MEMORY";
|
|
|
|
} else {
|
2011-03-07 01:36:34 +03:00
|
|
|
$query .= " ENGINE=InnoDb";
|
2008-05-10 03:19:11 +04:00
|
|
|
}
|
2008-09-30 03:07:06 +04:00
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
mysql_query($query, $link) or show_install_err(' Query failed: ' . mysql_error($link));
|
2008-09-30 03:07:06 +04:00
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
if ($id == "${mysqlprefix}chatoperator") {
|
2009-09-01 02:43:30 +04:00
|
|
|
create_operator_("admin", "", "", "Administrator", "Administrator", "", $link);
|
2011-02-26 16:57:23 +03:00
|
|
|
} else if ($id == "${mysqlprefix}chatrevision") {
|
|
|
|
perform_query("INSERT INTO ${mysqlprefix}chatrevision VALUES (1)", $link);
|
2007-10-17 14:43:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
function get_tables($link)
|
|
|
|
{
|
2007-10-17 14:43:34 +04:00
|
|
|
global $mysqldb, $errors;
|
2011-02-26 16:57:23 +03:00
|
|
|
$result = mysql_query("SHOW TABLES FROM `$mysqldb`", $link);
|
|
|
|
if ($result) {
|
2007-10-17 14:43:34 +04:00
|
|
|
$arr = array();
|
|
|
|
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
|
|
|
|
$arr[] = $row[0];
|
|
|
|
}
|
|
|
|
mysql_free_result($result);
|
|
|
|
return $arr;
|
|
|
|
|
|
|
|
} else {
|
2011-02-26 16:57:23 +03:00
|
|
|
$errors[] = "Cannot get tables from database. Error: " . mysql_error($link);
|
2007-10-17 14:43:34 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-26 16:57:23 +03:00
|
|
|
function get_columns($tablename, $link)
|
|
|
|
{
|
2007-10-17 14:43:34 +04:00
|
|
|
global $errors;
|
2011-02-26 16:57:23 +03:00
|
|
|
$result = mysql_query("SHOW COLUMNS FROM $tablename", $link);
|
|
|
|
if ($result) {
|
2007-10-17 14:43:34 +04:00
|
|
|
$arr = array();
|
|
|
|
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
|
|
|
|
$arr[] = $row[0];
|
|
|
|
}
|
|
|
|
mysql_free_result($result);
|
|
|
|
return $arr;
|
|
|
|
|
|
|
|
} else {
|
2011-02-26 16:57:23 +03:00
|
|
|
$errors[] = "Cannot get columns from table \"$tablename\". Error: " . mysql_error($link);
|
2007-10-17 14:43:34 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|