From 0ebad2dda72d5006f9aea903ebe7e2bf7cf12cd2 Mon Sep 17 00:00:00 2001 From: Evgeny Gryaznov Date: Mon, 29 Sep 2008 23:07:06 +0000 Subject: [PATCH] settings page, remove some options from config, add index into db git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@117 c66351dc-e62f-0410-b875-e3a5c0b9693f --- src/messenger/webim/install/dbinfo.php | 28 +++-- src/messenger/webim/install/dbperform.php | 42 +++++--- src/messenger/webim/libs/common.php | 67 ++++++++---- src/messenger/webim/libs/config.php | 31 ++---- src/messenger/webim/operator/settings.php | 72 +++++++++++++ src/messenger/webim/view/menu.php | 10 +- src/messenger/webim/view/settings.php | 118 ++++++++++++++++++++++ 7 files changed, 295 insertions(+), 73 deletions(-) create mode 100644 src/messenger/webim/operator/settings.php create mode 100644 src/messenger/webim/view/settings.php diff --git a/src/messenger/webim/install/dbinfo.php b/src/messenger/webim/install/dbinfo.php index 3ec2e9ff..a3111770 100644 --- a/src/messenger/webim/install/dbinfo.php +++ b/src/messenger/webim/install/dbinfo.php @@ -51,9 +51,15 @@ $dbtables = array( "vccommonname" => "varchar(64) NOT NULL", "dtmlastvisited" => "datetime DEFAULT 0", ), - + "chatrevision" => array( "id" => "INT NOT NULL" + ), + + "chatconfig" => array ( + "id" => "INT NOT NULL auto_increment PRIMARY KEY", + "vckey" => "varchar(255)", + "vcvalue" => "varchar(255)", ) ); @@ -66,30 +72,30 @@ $dbtables_can_update = array( function show_install_err($text) { global $page, $version, $errors, $webimroot; - $page = array( + $page = array( 'version' => $version, 'localeLinks' => get_locale_links("$webimroot/install/index.php") ); $errors = array($text); start_html_output(); require('view_installerr.php'); - exit; + exit; } function create_table($id,$link) { global $dbtables, $memtables, $dbencoding; - + if(!isset($dbtables[$id])) { show_install_err("Unknown table: $id, ".mysql_error()); } - - $query = + + $query = "CREATE TABLE $id\n". "(\n"; foreach( $dbtables[$id] as $k => $v ) { - $query .= " $k $v,\n"; + $query .= " $k $v,\n"; } - + $query = preg_replace("/,\n$/", "", $query); $query .= ") charset $dbencoding"; if (in_array($id, $memtables)) { @@ -97,11 +103,11 @@ function create_table($id,$link) { } else { $query .= " TYPE=InnoDb"; } + mysql_query($query,$link) or show_install_err(' Query failed: '.mysql_error()); - - // post create + if( $id == 'chatoperator' ) { - create_operator_("admin", "", "Administrator", "Administrator", $link); + create_operator_("admin", "", "Administrator", "Administrator", $link); } else if( $id == 'chatrevision' ) { perform_query("INSERT INTO chatrevision VALUES (1)",$link); } diff --git a/src/messenger/webim/install/dbperform.php b/src/messenger/webim/install/dbperform.php index 3d57350e..6cbf9d77 100644 --- a/src/messenger/webim/install/dbperform.php +++ b/src/messenger/webim/install/dbperform.php @@ -17,24 +17,31 @@ require_once('../libs/operator.php'); require_once('dbinfo.php'); function runsql($query,$link) { - mysql_query($query,$link) + $res = mysql_query($query,$link) or show_install_err(' Query failed: '.mysql_error()); + return $res; } -$act = verifyparam( "act", "/^(createdb|createtables|droptables|addcolumns)$/"); +$act = verifyparam( "act", "/^(silentcreateall|createdb|createtables|droptables|addcolumns)$/"); $link = @mysql_connect($mysqlhost,$mysqllogin ,$mysqlpass ) or show_install_err('Could not connect: ' . mysql_error()); -if($act == "createdb") { - mysql_query("CREATE DATABASE $mysqldb",$link) +if ($act == "silentcreateall") { + mysql_query("CREATE DATABASE $mysqldb",$link) + or show_install_err(' Query failed: '.mysql_error()); + foreach($dbtables as $id) { + create_table($id, $link); + } +} else if($act == "createdb") { + mysql_query("CREATE DATABASE $mysqldb",$link) or show_install_err(' Query failed: '.mysql_error()); } else { - mysql_select_db($mysqldb,$link) + mysql_select_db($mysqldb,$link) or show_install_err('Could not select database'); if( $force_charset_in_connection ) { mysql_query("SET character set $dbencoding", $link); } - + if( $act == "createtables") { $curr_tables = get_tables($link); if( $curr_tables === false) { @@ -48,45 +55,50 @@ if($act == "createdb") { foreach( array_keys($dbtables) as $id) { mysql_query("DROP TABLE IF EXISTS $id",$link) or show_install_err(' Query failed: '.mysql_error()); - } + } } else if( $act == "addcolumns") { $absent = array(); foreach( $dbtables as $id => $columns) { $curr_columns = get_columns($id, $link); if( $curr_columns === false ) { - show_install_err($errors[0]); + show_install_err($errors[0]); } $tocreate = array_diff(array_keys($columns), $curr_columns); foreach($tocreate as $v) { $absent[] = "$id.$v"; } } - + if( in_array("chatmessage.agentId", $absent) ) { runsql("ALTER TABLE chatmessage ADD agentId int NOT NULL DEFAULT 0 AFTER ikind", $link); - runsql("update chatmessage,chatoperator set agentId = operatorid where agentId = 0 AND ikind = 2 AND (vclocalename = tname OR vccommonname = tname)", $link); + runsql("update chatmessage,chatoperator set agentId = operatorid where agentId = 0 AND ikind = 2 AND (vclocalename = tname OR vccommonname = tname)", $link); } - + if( in_array("chatthread.agentId", $absent) ) { runsql("ALTER TABLE chatthread ADD agentId int NOT NULL DEFAULT 0 AFTER agentName", $link); - runsql("update chatthread,chatoperator set agentId = operatorid where agentId = 0 AND (vclocalename = agentName OR vccommonname = agentName)", $link); + runsql("update chatthread,chatoperator set agentId = operatorid where agentId = 0 AND (vclocalename = agentName OR vccommonname = agentName)", $link); } if( in_array("chatthread.agentTyping", $absent) ) { runsql("ALTER TABLE chatthread ADD agentTyping int DEFAULT 0", $link); } - + if( in_array("chatthread.userTyping", $absent) ) { runsql("ALTER TABLE chatthread ADD userTyping int DEFAULT 0", $link); } if( in_array("chatthread.messageCount", $absent) ) { runsql("ALTER TABLE chatthread ADD messageCount varchar(16)", $link); - runsql("ALTER TABLE chatmessage ADD index idx_threadid_ikind (threadid, ikind)", $link); - runsql("UPDATE chatthread t SET t.messageCount = (SELECT COUNT(*) FROM chatmessage WHERE chatmessage.threadid = t.threadid AND ikind = 1)", $link); + runsql("ALTER TABLE chatmessage ADD INDEX idx_threadid_ikind (threadid, ikind)", $link); + runsql("UPDATE chatthread t SET t.messageCount = (SELECT COUNT(*) FROM chatmessage WHERE chatmessage.threadid = t.threadid AND ikind = 1)", $link); runsql("ALTER TABLE chatmessage DROP INDEX idx_threadid_ikind", $link); } + $res = runsql("select null from information_schema.statistics where table_name = 'chatmessage' and index_name = 'idx_agentid'", $link); + if(mysql_num_rows($res) == 0) { + runsql("ALTER TABLE chatmessage ADD INDEX idx_agentid (agentid)", $link); + + } } } diff --git a/src/messenger/webim/libs/common.php b/src/messenger/webim/libs/common.php index 3fd0bf19..2d3f1832 100644 --- a/src/messenger/webim/libs/common.php +++ b/src/messenger/webim/libs/common.php @@ -17,7 +17,7 @@ session_start(); require_once(dirname(__FILE__).'/converter.php'); require_once(dirname(__FILE__).'/config.php'); -$version = 'v1.0.10'; +$version = 'v1.4.0'; function myiconv($in_enc, $out_enc, $string) { global $_utf8win1251, $_win1251utf8; @@ -25,8 +25,8 @@ function myiconv($in_enc, $out_enc, $string) { return $string; } if( function_exists('iconv') ) { - $converted = @iconv($in_enc, $out_enc, $string); - if( $converted !== FALSE ) { + $converted = @iconv($in_enc, $out_enc, $string); + if( $converted !== FALSE ) { return $converted; } } @@ -39,7 +39,6 @@ function myiconv($in_enc, $out_enc, $string) { } function verifyparam( $name, $regexp, $default = null ) { - if( isset( $_GET[$name] ) ) { $val = $_GET[$name]; if( preg_match( $regexp, $val ) ) @@ -54,7 +53,6 @@ function verifyparam( $name, $regexp, $default = null ) { if( isset( $default ) ) return $default; } - echo "Wrong parameter used or absent: ".$name.""; exit; } @@ -101,7 +99,7 @@ function get_locale() { $_SESSION['locale'] = $locale; setcookie('webim_locale', $locale, time()+60*60*24*1000, "$webimroot/"); } else if( isset($_SESSION['locale']) ){ - $locale = $_SESSION['locale']; + $locale = $_SESSION['locale']; } if( !$locale || !in_array($locale,$available_locales) ) @@ -132,18 +130,18 @@ function load_messages($locale) { global $messages, $webim_encoding, $output_encoding; $hash = array(); $current_encoding = $webim_encoding; - $fp = fopen(dirname(__FILE__)."/../locales/$locale/properties","r"); + $fp = fopen(dirname(__FILE__)."/../locales/$locale/properties", "r"); while (!feof($fp)) { - $line = fgets($fp, 4096); + $line = fgets($fp, 4096); $keyval = split("=", $line, 2 ); if( isset($keyval[1]) ) { if($keyval[0] == 'encoding') { $current_encoding = trim($keyval[1]); } else if($keyval[0] == 'output_encoding') { - $output_encoding[$locale] = trim($keyval[1]); + $output_encoding[$locale] = trim($keyval[1]); } else if( $current_encoding == $webim_encoding ) { $hash[$keyval[0]] = str_replace("\\n", "\n",trim($keyval[1])); - } else { + } else { $hash[$keyval[0]] = myiconv($current_encoding, $webim_encoding, str_replace("\\n", "\n",trim($keyval[1]))); } } @@ -241,20 +239,20 @@ function connect() { } function perform_query($query,$link) { - mysql_query($query,$link) + mysql_query($query,$link) or die(' Query failed: '.mysql_error()/*.": ".$query*/); } function select_one_row($query,$link) { - $result = mysql_query($query,$link) or die(' Query failed: ' . + $result = mysql_query($query,$link) or die(' Query failed: ' . mysql_error().": ".$query); $line = mysql_fetch_array($result, MYSQL_ASSOC); mysql_free_result($result); return $line; } -function select_multi_assoc($query,$link) { - $sqlresult = mysql_query($query,$link) or die(' Query failed: ' . +function select_multi_assoc($query, $link) { + $sqlresult = mysql_query($query,$link) or die(' Query failed: ' . mysql_error().": ".$query); $result = array(); @@ -266,14 +264,18 @@ function select_multi_assoc($query,$link) { } function start_xml_output() { + header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); + header("Pragma: no-cache"); header("Content-type: text/xml; charset=utf-8"); echo ""; } function start_html_output() { $charset = getstring("output_charset"); + header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); + header("Pragma: no-cache"); header("Content-type: text/html".(isset($charset)?"; charset=".$charset:"")); } @@ -299,7 +301,6 @@ function no_field($key) { return getlocal2("errors.required",array(getlocal($key))); } - function wrong_field($key) { return getlocal2("errors.wrong_field",array(getlocal($key))); } @@ -309,7 +310,7 @@ function get_popup($href,$message,$title,$wndName,$options) { } function get_image($href,$width,$height) { - if( $width != 0 && $height != 0 ) + if( $width != 0 && $height != 0 ) return ""; return ""; } @@ -342,11 +343,11 @@ function add_params($servlet, $params) { } function div($a,$b) { - return ($a-($a % $b)) / $b; + return ($a-($a % $b)) / $b; } function date_diff($seconds) { - $minutes = div($seconds,60); + $minutes = div($seconds,60); $seconds = $seconds % 60; if( $minutes < 60 ) { return sprintf("%02d:%02d",$minutes, $seconds); @@ -388,7 +389,7 @@ function get_month_selection($fromtime,$totime) { $month++; if( $month > 12 ) { $month = 1; - $year++; + $year++; } } while( $current < $totime ); return $result; @@ -420,4 +421,32 @@ function webim_mail($toaddr, $reply_to, $subject, $body) { mail($toaddr, $real_subject, wordwrap(myiconv($webim_encoding, $mail_encoding, $body),70), $headers); } +$settings = array( + 'email' => '', /* inbox for left messages */ + 'title' => 'Company', + 'hosturl' => 'http://www.webim.ru', + 'logo' => '' +); +$settingsloaded = false; +$settings_in_db = array(); + +function loadsettings() { + global $settingsloaded, $settings_in_db, $settings; + if($settingsloaded) { + return; + } + $settingsloaded = true; + + $link = connect(); + $sqlresult = mysql_query('select vckey,vcvalue from chatconfig',$link) or die(' Query failed: '.mysql_error().": ".$query); + + while ($row = mysql_fetch_array($sqlresult, MYSQL_ASSOC)) { + $name = $row['vckey']; + $settings[$name] = $row['vcvalue']; + $settings_in_db[$name] = true; + } + mysql_free_result($sqlresult); + mysql_close($link); +} + ?> \ No newline at end of file diff --git a/src/messenger/webim/libs/config.php b/src/messenger/webim/libs/config.php index 29a6e767..1e61cf86 100644 --- a/src/messenger/webim/libs/config.php +++ b/src/messenger/webim/libs/config.php @@ -12,8 +12,8 @@ * Evgeny Gryaznov - initial API and implementation */ -/* - * Application path on server +/* + * Application path on server */ $webimroot = "/webim"; @@ -51,32 +51,16 @@ $mail_encoding = $webim_encoding; $webim_from_email = "webim@yourdomain.com"; /* email from field */ /* - * Inbox for left messages + * Inbox for left messages encoding */ -$webim_messages_mail = "operators@yourdomain.com"; $webim_messages_locale = "en"; /* - * Company international name. - */ -$company_name = "My Company Ltd."; - -/* - * Company logo. - */ -$company_logo_link = ""; - -/* - * Web Messenger host - */ -$webim_host = ""; - -/* - * Locales + * Locales */ $available_locales = array("en", "ru"); -$home_locale = "ru"; /* native name will be used in this locale */ -$default_locale = "en"; /* if user does not provide known lang */ +$home_locale = "ru"; /* native name will be used in this locale */ +$default_locale = "en"; /* if user does not provide known lang */ /* * Allows users to change their names @@ -85,7 +69,7 @@ $user_can_change_name = true; /* * How to build presentable visitor name from {name} or {addr}. Default: {name} - */ + */ $presentable_name_pattern = "{name}"; /* @@ -99,5 +83,4 @@ $remote_visitor = 'visitor_from_request'; */ $online_timeout = 30; - ?> diff --git a/src/messenger/webim/operator/settings.php b/src/messenger/webim/operator/settings.php new file mode 100644 index 00000000..6055c5b6 --- /dev/null +++ b/src/messenger/webim/operator/settings.php @@ -0,0 +1,72 @@ + $value) { + if(!isset($settings_in_db[$key])) { + perform_query("insert into chatconfig (vckey) values ('$key')",$link); + } + $query = sprintf("update chatconfig set vcvalue='%s' where vckey='$key'", mysql_real_escape_string($value)); + perform_query($query,$link); + } + + mysql_close($link); +} + +$page = array('agentId' => ''); +$errors = array(); + +loadsettings(); +$email = $settings['email']; +$title = $settings['title']; +$logo = $settings['logo']; +$hosturl = $settings['hosturl']; + +if (isset($_POST['email']) && isset($_POST['title']) && isset($_POST['logo'])) { + $email = getparam('email'); + $title = getparam('title'); + $logo = getparam('logo'); + $hosturl = getparam('hosturl'); + + if($email && !is_valid_email($email)) { + $errors[] = getlocal("settings.wrong.email"); + } + + if (count($errors) == 0) { + $settings['email'] = $email; + $settings['title'] = $title; + $settings['logo'] = $logo; + $settings['hosturl'] = $hosturl; + update_settings(); + header("Location: $webimroot/operator/index.php"); + exit; + } +} + +$page['operator'] = topage(get_operator_name($operator)); +$page['formemail'] = topage($email); +$page['formtitle'] = topage($title); +$page['formlogo'] = topage($logo); +$page['formhosturl'] = topage($hosturl); + +start_html_output(); +require('../view/settings.php'); +?> \ No newline at end of file diff --git a/src/messenger/webim/view/menu.php b/src/messenger/webim/view/menu.php index c77397a6..740eb3a3 100644 --- a/src/messenger/webim/view/menu.php +++ b/src/messenger/webim/view/menu.php @@ -34,11 +34,11 @@ + +
- -
+ +

-
- +
+
@@ -54,6 +54,8 @@









diff --git a/src/messenger/webim/view/settings.php b/src/messenger/webim/view/settings.php new file mode 100644 index 00000000..edce38cd --- /dev/null +++ b/src/messenger/webim/view/settings.php @@ -0,0 +1,118 @@ + + + + + + + + + + + + <?php echo getlocal("app.title") ?> - <?php echo getlocal("settings.title") ?> + + +"> +"> + + + + + + + + +
+ +
+

+
|">
+ + + +
+
+ 0 ) { ?> + + + + + + +
+ 0 ) { + print getlocal("errors.header"); + foreach( $errors as $e ) { + print getlocal("errors.prefix"); + print $e; + print getlocal("errors.suffix"); + } + print getlocal("errors.footer"); + } ?> + +
+ + +
+
+ + + + + + + + + + + + + +
+ +
+ +
+ +
+ +
+ +
+ + + + + + + + + + + + + + +
+ + +
+ +
+ + + +