2007-10-17 14:43:34 +04:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* This file is part of Web Instant Messenger project.
|
|
|
|
*
|
2009-01-14 01:21:52 +03:00
|
|
|
* Copyright (c) 2005-2009 Web Messenger Community
|
2007-10-17 14:43:34 +04:00
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under 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
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* Evgeny Gryaznov - initial API and implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
$dbtables = array(
|
2009-01-03 04:23:19 +03:00
|
|
|
"chatdepartment" => array(
|
|
|
|
"departmentid" => "int NOT NULL auto_increment PRIMARY KEY",
|
|
|
|
"vcname" => "varchar(64) NOT NULL",
|
|
|
|
"vcdescription" => "varchar(1024) NOT NULL",
|
|
|
|
),
|
|
|
|
|
2007-10-17 14:43:34 +04:00
|
|
|
"chatthread" => array(
|
|
|
|
"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)",
|
|
|
|
"departmentid" => "int references chatdepartment(departmentid)",
|
2007-10-17 14:43:34 +04:00
|
|
|
),
|
|
|
|
|
|
|
|
"chatmessage" => array(
|
|
|
|
"messageid" => "int NOT NULL auto_increment PRIMARY KEY",
|
|
|
|
"threadid" => "int NOT NULL references chatthread(threadid)",
|
|
|
|
"ikind" => "int NOT NULL",
|
|
|
|
"agentId" => "int NOT NULL DEFAULT 0",
|
|
|
|
"tmessage" => "text NOT NULL",
|
|
|
|
"dtmcreated" => "datetime DEFAULT 0",
|
|
|
|
"tname" => "varchar(64)"
|
|
|
|
),
|
|
|
|
|
|
|
|
"chatoperator" => array(
|
|
|
|
"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",
|
|
|
|
"dtmlastvisited" => "datetime DEFAULT 0",
|
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",
|
2007-10-17 14:43:34 +04:00
|
|
|
),
|
2008-09-30 03:07:06 +04:00
|
|
|
|
2007-10-17 14:43:34 +04:00
|
|
|
"chatrevision" => array(
|
|
|
|
"id" => "INT NOT NULL"
|
2008-09-30 03:07:06 +04:00
|
|
|
),
|
|
|
|
|
2009-01-03 04:23:19 +03:00
|
|
|
"chatdepartmentoperator" => array(
|
|
|
|
"departmentid" => "int NOT NULL references chatdepartment(departmentid)",
|
|
|
|
"operatorid" => "int NOT NULL references chatoperator(operatorid)",
|
|
|
|
),
|
|
|
|
|
2008-10-04 03:35:17 +04:00
|
|
|
"chatban" => array(
|
|
|
|
"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"
|
|
|
|
),
|
|
|
|
|
2008-09-30 03:07:06 +04:00
|
|
|
"chatconfig" => array (
|
|
|
|
"id" => "INT NOT NULL auto_increment PRIMARY KEY",
|
|
|
|
"vckey" => "varchar(255)",
|
|
|
|
"vcvalue" => "varchar(255)",
|
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(
|
2009-01-03 04:23:19 +03:00
|
|
|
"chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount", "nextagent", "shownmessageid", "userid", "userAgent", "departmentid"),
|
2007-12-03 00:32:47 +03:00
|
|
|
"chatmessage" => array("agentId"),
|
2008-12-08 03:34:28 +03:00
|
|
|
"chatoperator" => array("vcavatar", "vcjabbername", "iperm"),
|
2008-10-04 03:35:17 +04:00
|
|
|
"chatban" => array(),
|
2009-01-03 04:23:19 +03:00
|
|
|
"chatdepartment" => array(),
|
|
|
|
"chatdepartmentoperator" => array(),
|
2007-10-17 14:43:34 +04: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
|
|
|
}
|
|
|
|
|
|
|
|
function create_table($id,$link) {
|
2008-05-10 03:19:11 +04:00
|
|
|
global $dbtables, $memtables, $dbencoding;
|
2008-09-30 03:07:06 +04:00
|
|
|
|
2007-10-17 14:43:34 +04:00
|
|
|
if(!isset($dbtables[$id])) {
|
|
|
|
show_install_err("Unknown table: $id, ".mysql_error());
|
|
|
|
}
|
2008-09-30 03:07:06 +04:00
|
|
|
|
|
|
|
$query =
|
2007-10-17 14:43:34 +04: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 {
|
|
|
|
$query .= " TYPE=InnoDb";
|
|
|
|
}
|
2008-09-30 03:07:06 +04:00
|
|
|
|
2008-05-10 03:19:11 +04:00
|
|
|
mysql_query($query,$link) or show_install_err(' Query failed: '.mysql_error());
|
2008-09-30 03:07:06 +04:00
|
|
|
|
2007-10-17 14:43:34 +04:00
|
|
|
if( $id == 'chatoperator' ) {
|
2008-10-06 03:46:54 +04:00
|
|
|
create_operator_("admin", "", "Administrator", "Administrator", "", $link);
|
2007-10-17 14:43:34 +04:00
|
|
|
} else if( $id == 'chatrevision' ) {
|
|
|
|
perform_query("INSERT INTO chatrevision VALUES (1)",$link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_tables($link) {
|
|
|
|
global $mysqldb, $errors;
|
2008-06-05 02:51:46 +04:00
|
|
|
$result = mysql_query("SHOW TABLES FROM `$mysqldb`");
|
2007-10-17 14:43:34 +04:00
|
|
|
if( $result ) {
|
|
|
|
$arr = array();
|
|
|
|
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
|
|
|
|
$arr[] = $row[0];
|
|
|
|
}
|
|
|
|
mysql_free_result($result);
|
|
|
|
return $arr;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$errors[] = "Cannot get tables from database. Error: ".mysql_error();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_columns($tablename,$link) {
|
|
|
|
global $errors;
|
|
|
|
$result = mysql_query("SHOW COLUMNS FROM $tablename");
|
|
|
|
if( $result ) {
|
|
|
|
$arr = array();
|
|
|
|
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
|
|
|
|
$arr[] = $row[0];
|
|
|
|
}
|
|
|
|
mysql_free_result($result);
|
|
|
|
return $arr;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$errors[] = "Cannot get columns from table \"$tablename\". Error: ".mysql_error();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|