format code

This commit is contained in:
Evgeny Gryaznov 2011-02-26 23:48:41 +01:00
parent 2bcffd5f4a
commit 03dec2afb2
53 changed files with 1874 additions and 1597 deletions

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<ADDITIONAL_INDENT_OPTIONS fileType="js">
<option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
<option name="USE_RELATIVE_INDENTS" value="false" />
</ADDITIONAL_INDENT_OPTIONS>
<ADDITIONAL_INDENT_OPTIONS fileType="jsp">
<option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
<option name="USE_RELATIVE_INDENTS" value="false" />
</ADDITIONAL_INDENT_OPTIONS>
<ADDITIONAL_INDENT_OPTIONS fileType="php">
<option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
<option name="USE_RELATIVE_INDENTS" value="false" />
</ADDITIONAL_INDENT_OPTIONS>
<ADDITIONAL_INDENT_OPTIONS fileType="sass">
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
<option name="USE_RELATIVE_INDENTS" value="false" />
</ADDITIONAL_INDENT_OPTIONS>
<ADDITIONAL_INDENT_OPTIONS fileType="sql">
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
<option name="USE_RELATIVE_INDENTS" value="false" />
</ADDITIONAL_INDENT_OPTIONS>
<ADDITIONAL_INDENT_OPTIONS fileType="xml">
<option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
<option name="USE_RELATIVE_INDENTS" value="false" />
</ADDITIONAL_INDENT_OPTIONS>
<ADDITIONAL_INDENT_OPTIONS fileType="yml">
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
<option name="USE_RELATIVE_INDENTS" value="false" />
</ADDITIONAL_INDENT_OPTIONS>
</value>
</option>
</component>
</project>

View File

@ -137,7 +137,8 @@ $dbtables_can_update = array(
"${mysqlprefix}chatnotification" => array(),
);
function show_install_err($text) {
function show_install_err($text)
{
global $page, $version, $errors, $webimroot;
$page = array(
'version' => $version,
@ -149,7 +150,8 @@ function show_install_err($text) {
exit;
}
function create_table($id,$link) {
function create_table($id, $link)
{
global $dbtables, $memtables, $dbencoding, $mysqlprefix;
if (!isset($dbtables[$id])) {
@ -180,7 +182,8 @@ function create_table($id,$link) {
}
}
function get_tables($link) {
function get_tables($link)
{
global $mysqldb, $errors;
$result = mysql_query("SHOW TABLES FROM `$mysqldb`");
if ($result) {
@ -197,7 +200,8 @@ function get_tables($link) {
}
}
function get_columns($tablename,$link) {
function get_columns($tablename, $link)
{
global $errors;
$result = mysql_query("SHOW COLUMNS FROM $tablename");
if ($result) {

View File

@ -23,7 +23,8 @@ require_once('../libs/common.php');
require_once('../libs/operator.php');
require_once('dbinfo.php');
function runsql($query,$link) {
function runsql($query, $link)
{
$res = mysql_query($query, $link)
or show_install_err(' Query failed: ' . mysql_error());
return $res;

View File

@ -33,7 +33,8 @@ $page['nextstep'] = false;
$page['nextnotice'] = false;
$errors = array();
function check_webimroot() {
function check_webimroot()
{
global $page, $errors, $webimroot;
$requestUri = $_SERVER["REQUEST_URI"];
if (!preg_match('/^(.*)\\/install(\\/[^\\/\\\\]*)?$/', $requestUri, $matches)) {
@ -52,7 +53,8 @@ function check_webimroot() {
return true;
}
function check_connection() {
function check_connection()
{
global $mysqlhost, $mysqllogin, $mysqlpass, $page, $errors, $webimroot;
$link = @mysql_connect($mysqlhost, $mysqllogin, $mysqlpass);
if ($link) {
@ -72,7 +74,8 @@ function check_connection() {
}
}
function check_database($link) {
function check_database($link)
{
global $mysqldb, $force_charset_in_connection, $dbencoding, $page, $webimroot;
if (mysql_select_db($mysqldb, $link)) {
$page['done'][] = getlocal2("install.2.db_exists", array($mysqldb));
@ -88,7 +91,8 @@ function check_database($link) {
return false;
}
function check_tables($link) {
function check_tables($link)
{
global $dbtables, $page, $webimroot;
$curr_tables = get_tables($link);
if ($curr_tables !== false) {
@ -104,7 +108,8 @@ function check_tables($link) {
return false;
}
function check_columns($link) {
function check_columns($link)
{
global $dbtables, $dbtables_can_update, $errors, $page, $webimroot;
$need_to_create_columns = false;
@ -138,7 +143,8 @@ function check_columns($link) {
return true;
}
function check_status() {
function check_status()
{
global $page, $webimroot, $settings, $dbversion;
if (!check_webimroot()) {

View File

@ -15,16 +15,19 @@
Copyright 2006 WebCheatSheet.com
*/
function can_show_captcha() {
function can_show_captcha()
{
return extension_loaded("gd");
}
function gen_captcha() {
function gen_captcha()
{
$md5_hash = md5(rand(0, 9999));
return substr($md5_hash, 15, 5);
}
function draw_captcha($security_code) {
function draw_captcha($security_code)
{
//Set the image width and height
$width = 100;

View File

@ -43,22 +43,26 @@ $kind_avatar = 7;
$kind_to_string = array($kind_user => "user", $kind_agent => "agent", $kind_for_agent => "hidden",
$kind_info => "inf", $kind_conn => "conn", $kind_events => "event", $kind_avatar => "avatar");
function get_user_id() {
function get_user_id()
{
return (time() + microtime()) . rand(0, 99999999);
}
function next_token() {
function next_token()
{
return rand(99999, 99999999);
}
function next_revision($link) {
function next_revision($link)
{
global $mysqlprefix;
perform_query("update ${mysqlprefix}chatrevision set id=LAST_INSERT_ID(id+1)", $link);
$val = mysql_insert_id($link);
return $val;
}
function post_message_($threadid,$kind,$message,$link,$from=null,$utime=null,$opid=null) {
function post_message_($threadid, $kind, $message, $link, $from = null, $utime = null, $opid = null)
{
global $mysqlprefix;
$query = sprintf(
"insert into ${mysqlprefix}chatmessage (threadid,ikind,tmessage,tname,agentId,dtmcreated) values (%s, %s,'%s',%s,%s,%s)",
@ -73,21 +77,24 @@ function post_message_($threadid,$kind,$message,$link,$from=null,$utime=null,$op
return mysql_insert_id($link);
}
function post_message($threadid,$kind,$message,$from=null,$agentid=null) {
function post_message($threadid, $kind, $message, $from = null, $agentid = null)
{
$link = connect();
$id = post_message_($threadid, $kind, $message, $link, $from, null, $agentid);
mysql_close($link);
return $id;
}
function prepare_html_message($text) {
function prepare_html_message($text)
{
$escaped_text = htmlspecialchars($text);
$text_w_links = preg_replace('/(http|ftp):\/\/\S*/', '<a href="$0" target="_blank">$0</a>', $escaped_text);
$multiline = str_replace("\n", "<br/>", $text_w_links);
return $multiline;
}
function message_to_html($msg) {
function message_to_html($msg)
{
global $kind_to_string, $kind_avatar;
if ($msg['ikind'] == $kind_avatar) return "";
$message = "<span>" . date("H:i:s", $msg['created']) . "</span> ";
@ -98,7 +105,8 @@ function message_to_html($msg) {
return $message;
}
function message_to_text($msg) {
function message_to_text($msg)
{
global $kind_user, $kind_agent, $kind_info, $kind_avatar;
if ($msg['ikind'] == $kind_avatar) return "";
$message_time = date("H:i:s ", $msg['created']);
@ -114,7 +122,8 @@ function message_to_text($msg) {
}
}
function get_messages($threadid,$meth,$isuser,&$lastid) {
function get_messages($threadid, $meth, $isuser, &$lastid)
{
global $kind_for_agent, $kind_avatar, $webim_encoding, $mysqlprefix;
$link = connect();
@ -151,7 +160,8 @@ function get_messages($threadid,$meth,$isuser,&$lastid) {
return $messages;
}
function print_thread_messages($thread, $token, $lastid, $isuser, $format, $agentid=null) {
function print_thread_messages($thread, $token, $lastid, $isuser, $format, $agentid = null)
{
global $webim_encoding, $webimroot, $connection_timeout, $settings;
$threadid = $thread['threadid'];
$istyping = abs($thread['current'] - $thread[$isuser ? "lpagent" : "lpuser"]) < $connection_timeout
@ -194,7 +204,8 @@ function print_thread_messages($thread, $token, $lastid, $isuser, $format, $agen
}
}
function get_user_name($username, $addr, $id) {
function get_user_name($username, $addr, $id)
{
global $settings;
loadsettings();
return str_replace("{addr}", $addr,
@ -202,7 +213,8 @@ function get_user_name($username, $addr, $id) {
str_replace("{name}", $username, $settings['usernamepattern'])));
}
function is_ajax_browser($browserid,$ver,$useragent) {
function is_ajax_browser($browserid, $ver, $useragent)
{
if ($browserid == "opera")
return $ver >= 8.02;
if ($browserid == "safari")
@ -221,7 +233,8 @@ function is_ajax_browser($browserid,$ver,$useragent) {
return false;
}
function is_old_browser($browserid,$ver) {
function is_old_browser($browserid, $ver)
{
if ($browserid == "opera")
return $ver < 7.0;
if ($browserid == "msie")
@ -231,7 +244,8 @@ function is_old_browser($browserid,$ver) {
$knownAgents = array("opera", "msie", "chrome", "safari", "firefox", "netscape", "mozilla");
function get_remote_level($useragent) {
function get_remote_level($useragent)
{
global $knownAgents;
$useragent = strtolower($useragent);
foreach ($knownAgents as $agent) {
@ -251,7 +265,8 @@ function get_remote_level($useragent) {
return "simple";
}
function is_agent_opera95() {
function is_agent_opera95()
{
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strstr($useragent, "opera")) {
if (preg_match("/opera[\\s\/]?(\\d+(\\.\\d+)?)/", $useragent, $matches)) {
@ -264,17 +279,20 @@ function is_agent_opera95() {
return false;
}
function is_mac_opera() {
function is_mac_opera()
{
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
return strstr($useragent, "opera") && strstr($useragent, "mac");
}
function needsFramesrc() {
function needsFramesrc()
{
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
return strstr($useragent, "safari/");
}
function setup_logo() {
function setup_logo()
{
global $page, $settings;
loadsettings();
$page['ct.company.name'] = topage($settings['title']);
@ -282,7 +300,8 @@ function setup_logo() {
$page['webimHost'] = topage($settings['hosturl']);
}
function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info, $referrer,$canshowcaptcha) {
function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info, $referrer, $canshowcaptcha)
{
global $settings, $page;
$page['formname'] = topage($name);
$page['formemail'] = topage($email);
@ -294,7 +313,8 @@ function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info
$page['referrer'] = urlencode(topage($referrer));
}
function setup_survey($name, $email, $groupid, $info, $referrer) {
function setup_survey($name, $email, $groupid, $info, $referrer)
{
global $settings, $page;
$page['formname'] = topage($name);
@ -331,7 +351,8 @@ function setup_survey($name, $email, $groupid, $info, $referrer) {
$page['showname'] = $settings['usercanchangename'] == "1" ? "1" : "";
}
function setup_chatview_for_user($thread,$level) {
function setup_chatview_for_user($thread, $level)
{
global $page, $webimroot, $settings;
loadsettings();
$page = array();
@ -370,7 +391,8 @@ function setup_chatview_for_user($thread,$level) {
$page['frequency'] = $settings['updatefrequency_chat'];
}
function load_canned_messages($locale, $groupid) {
function load_canned_messages($locale, $groupid)
{
global $mysqlprefix;
$link = connect();
$result = select_multi_assoc(
@ -394,7 +416,8 @@ function load_canned_messages($locale, $groupid) {
return $result;
}
function setup_chatview_for_operator($thread,$operator) {
function setup_chatview_for_operator($thread, $operator)
{
global $page, $webimroot, $company_logo_link, $company_name, $settings;
loadsettings();
$page = array();
@ -435,7 +458,8 @@ function setup_chatview_for_operator($thread,$operator) {
$page['frequency'] = $settings['updatefrequency_chat'];
}
function update_thread_access($threadid, $params, $link) {
function update_thread_access($threadid, $params, $link)
{
global $mysqlprefix;
$clause = "";
foreach ($params as $k => $v) {
@ -448,7 +472,8 @@ function update_thread_access($threadid, $params, $link) {
"where threadid = " . $threadid, $link);
}
function ping_thread($thread, $isuser,$istyping) {
function ping_thread($thread, $isuser, $istyping)
{
global $kind_for_agent, $state_queue, $state_loading, $state_chatting, $state_waiting, $kind_conn, $connection_timeout;
$link = connect();
$params = array(($isuser ? "lastpinguser" : "lastpingagent") => "CURRENT_TIMESTAMP",
@ -485,7 +510,8 @@ function ping_thread($thread, $isuser,$istyping) {
mysql_close($link);
}
function commit_thread($threadid,$params,$link) {
function commit_thread($threadid, $params, $link)
{
global $mysqlprefix;
$query = "update ${mysqlprefix}chatthread t set lrevision = " . next_revision($link) . ", dtmmodified = CURRENT_TIMESTAMP";
foreach ($params as $k => $v) {
@ -496,7 +522,8 @@ function commit_thread($threadid,$params,$link) {
perform_query($query, $link);
}
function rename_user($thread, $newname) {
function rename_user($thread, $newname)
{
global $kind_events;
$link = connect();
@ -509,7 +536,8 @@ function rename_user($thread, $newname) {
mysql_close($link);
}
function close_thread($thread,$isuser) {
function close_thread($thread, $isuser)
{
global $state_closed, $kind_events, $mysqlprefix;
$link = connect();
@ -524,7 +552,8 @@ function close_thread($thread,$isuser) {
mysql_close($link);
}
function thread_by_id_($id,$link) {
function thread_by_id_($id, $link)
{
global $mysqlprefix;
return select_one_row("select threadid,userName,agentName,agentId,lrevision,istate,ltoken,userTyping,agentTyping" .
",unix_timestamp(dtmmodified) as modified, unix_timestamp(dtmcreated) as created" .
@ -532,19 +561,22 @@ function thread_by_id_($id,$link) {
" from ${mysqlprefix}chatthread where threadid = " . $id, $link);
}
function ban_for_addr_($addr,$link) {
function ban_for_addr_($addr, $link)
{
global $mysqlprefix;
return select_one_row("select banid,comment from ${mysqlprefix}chatban where unix_timestamp(dtmtill) > unix_timestamp(CURRENT_TIMESTAMP) AND address = '" . mysql_real_escape_string($addr, $link) . "'", $link);
}
function thread_by_id($id) {
function thread_by_id($id)
{
$link = connect();
$thread = thread_by_id_($id, $link);
mysql_close($link);
return $thread;
}
function create_thread($groupid,$username,$remoteHost,$referer,$lang,$userid,$userbrowser,$initialState,$link) {
function create_thread($groupid, $username, $remoteHost, $referer, $lang, $userid, $userbrowser, $initialState, $link)
{
global $mysqlprefix;
$query = sprintf(
"insert into ${mysqlprefix}chatthread (userName,userid,ltoken,remote,referer,lrevision,locale,userAgent,dtmcreated,dtmmodified,istate" . ($groupid ? ",groupid" : "") . ") values " .
@ -565,7 +597,8 @@ function create_thread($groupid,$username,$remoteHost,$referer,$lang,$userid,$us
return $newthread;
}
function do_take_thread($threadid,$operatorId,$operatorName) {
function do_take_thread($threadid, $operatorId, $operatorName)
{
global $state_chatting;
$link = connect();
commit_thread($threadid,
@ -576,7 +609,8 @@ function do_take_thread($threadid,$operatorId,$operatorName) {
mysql_close($link);
}
function reopen_thread($threadid) {
function reopen_thread($threadid)
{
global $state_queue, $state_loading, $state_waiting, $state_chatting, $state_closed, $state_left, $kind_events;
$link = connect();
$thread = thread_by_id_($threadid, $link);
@ -597,7 +631,8 @@ function reopen_thread($threadid) {
return $thread;
}
function take_thread($thread,$operator) {
function take_thread($thread, $operator)
{
global $state_queue, $state_loading, $state_waiting, $state_chatting, $kind_events, $kind_avatar, $home_locale;
$state = $thread['istate'];
@ -633,7 +668,8 @@ function take_thread($thread,$operator) {
}
}
function check_for_reassign($thread,$operator) {
function check_for_reassign($thread, $operator)
{
global $state_waiting, $home_locale, $kind_events, $kind_avatar;
$operatorName = ($thread['locale'] == $home_locale) ? $operator['vclocalename'] : $operator['vccommonname'];
if ($thread['istate'] == $state_waiting &&
@ -651,7 +687,8 @@ function check_for_reassign($thread,$operator) {
}
}
function notify_operators($thread,$firstmessage,$link) {
function notify_operators($thread, $firstmessage, $link)
{
global $settings, $mysqlprefix;
if ($settings['enablejabber'] == 1) {
$groupid = $thread['groupid'];
@ -678,7 +715,8 @@ function notify_operators($thread,$firstmessage,$link) {
}
}
function check_connections_from_remote($remote,$link) {
function check_connections_from_remote($remote, $link)
{
global $settings, $state_closed, $state_left, $mysqlprefix;
if ($settings['max_connections_from_one_host'] == 0) {
return true;
@ -692,7 +730,8 @@ function check_connections_from_remote($remote,$link) {
return true;
}
function visitor_from_request() {
function visitor_from_request()
{
global $namecookie, $webim_encoding, $usercookie;
$defaultName = getstring("chat.default.username");
$userName = $defaultName;
@ -716,7 +755,8 @@ function visitor_from_request() {
return array('id' => $userId, 'name' => $userName);
}
function get_remote_host() {
function get_remote_host()
{
$extAddr = $_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) &&
$_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR']) {

View File

@ -27,7 +27,8 @@ require_once(dirname(__FILE__).'/config.php');
$version = '1.6.4';
$jsver = "164";
function myiconv($in_enc, $out_enc, $string) {
function myiconv($in_enc, $out_enc, $string)
{
global $_utf8win1251, $_win1251utf8;
if ($in_enc == $out_enc) {
return $string;
@ -46,7 +47,8 @@ function myiconv($in_enc, $out_enc, $string) {
return $string; // do not know how to convert
}
function verifyparam( $name, $regexp, $default = null ) {
function verifyparam($name, $regexp, $default = null)
{
if (isset($_GET[$name])) {
$val = $_GET[$name];
if (preg_match($regexp, $val))
@ -65,7 +67,8 @@ function verifyparam( $name, $regexp, $default = null ) {
exit;
}
function debugexit_print( $var ) {
function debugexit_print($var)
{
echo "<html><body><pre>";
print_r($var);
echo "</pre></body></html>";
@ -74,11 +77,13 @@ function debugexit_print( $var ) {
$locale_pattern = "/^[\w-]{2,5}$/";
function locale_exists($locale) {
function locale_exists($locale)
{
return file_exists(dirname(__FILE__) . "/../locales/$locale/properties");
}
function get_available_locales() {
function get_available_locales()
{
global $locale_pattern;
$list = array();
$folder = dirname(__FILE__) . "/../locales";
@ -94,7 +99,8 @@ function get_available_locales() {
return $list;
}
function get_user_locale() {
function get_user_locale()
{
global $default_locale;
if (isset($_COOKIE['webim_locale'])) {
@ -120,7 +126,8 @@ function get_user_locale() {
return 'en';
}
function get_locale() {
function get_locale()
{
global $webimroot, $locale_pattern;
$locale = verifyparam("locale", $locale_pattern, "");
@ -147,7 +154,8 @@ if(function_exists("date_default_timezone_set")) {
@date_default_timezone_set(function_exists("date_default_timezone_get") ? @date_default_timezone_get() : "GMT");
}
function get_locale_links($href) {
function get_locale_links($href)
{
global $current_locale;
$localeLinks = array();
$allLocales = get_available_locales();
@ -160,7 +168,8 @@ function get_locale_links($href) {
return $localeLinks;
}
function load_messages($locale) {
function load_messages($locale)
{
global $messages, $webim_encoding, $output_encoding;
$hash = array();
$current_encoding = $webim_encoding;
@ -184,14 +193,16 @@ function load_messages($locale) {
$messages[$locale] = $hash;
}
function getoutputenc() {
function getoutputenc()
{
global $current_locale, $output_encoding, $webim_encoding, $messages;
if (!isset($messages[$current_locale]))
load_messages($current_locale);
return isset($output_encoding[$current_locale]) ? $output_encoding[$current_locale] : $webim_encoding;
}
function getstring_($text,$locale) {
function getstring_($text, $locale)
{
global $messages;
if (!isset($messages[$locale]))
load_messages($locale);
@ -206,27 +217,32 @@ function getstring_($text,$locale) {
return "!" . $text;
}
function getstring($text) {
function getstring($text)
{
global $current_locale;
return getstring_($text, $current_locale);
}
function getlocal($text) {
function getlocal($text)
{
global $current_locale, $webim_encoding;
return myiconv($webim_encoding, getoutputenc(), getstring_($text, $current_locale));
}
function getlocal_($text,$locale) {
function getlocal_($text, $locale)
{
global $webim_encoding;
return myiconv($webim_encoding, getoutputenc(), getstring_($text, $locale));
}
function topage($text) {
function topage($text)
{
global $webim_encoding;
return myiconv($webim_encoding, getoutputenc(), $text);
}
function getstring2_($text,$params,$locale) {
function getstring2_($text, $params, $locale)
{
$string = getstring_($text, $locale);
for ($i = 0; $i < count($params); $i++) {
$string = str_replace("{" . $i . "}", $params[$i], $string);
@ -234,12 +250,14 @@ function getstring2_($text,$params,$locale) {
return $string;
}
function getstring2($text,$params) {
function getstring2($text, $params)
{
global $current_locale;
return getstring2_($text, $params, $current_locale);
}
function getlocal2($text,$params) {
function getlocal2($text, $params)
{
global $current_locale, $webim_encoding;
$string = myiconv($webim_encoding, getoutputenc(), getstring_($text, $current_locale));
for ($i = 0; $i < count($params); $i++) {
@ -249,7 +267,8 @@ function getlocal2($text,$params) {
}
/* prepares for Javascript string */
function getlocalforJS($text,$params) {
function getlocalforJS($text, $params)
{
global $current_locale, $webim_encoding;
$string = myiconv($webim_encoding, getoutputenc(), getstring_($text, $current_locale));
$string = str_replace("\"", "\\\"", str_replace("\n", "\\n", $string));
@ -260,7 +279,8 @@ function getlocalforJS($text,$params) {
}
/* ajax server actions use utf-8 */
function getrawparam( $name ) {
function getrawparam($name)
{
global $webim_encoding;
if (isset($_POST[$name])) {
$value = myiconv("utf-8", $webim_encoding, $_POST[$name]);
@ -273,7 +293,8 @@ function getrawparam( $name ) {
}
/* form processors use current Output encoding */
function getparam( $name ) {
function getparam($name)
{
global $webim_encoding;
if (isset($_POST[$name])) {
$value = myiconv(getoutputenc(), $webim_encoding, $_POST[$name]);
@ -285,7 +306,8 @@ function getparam( $name ) {
die("no " . $name . " parameter");
}
function unicode_urldecode($url) {
function unicode_urldecode($url)
{
preg_match_all('/%u([[:alnum:]]{4})/', $url, $a);
foreach ($a[1] as $uniord) {
@ -307,7 +329,8 @@ function unicode_urldecode($url) {
return urldecode($url);
}
function getgetparam($name,$default='') {
function getgetparam($name, $default = '')
{
global $webim_encoding;
if (!isset($_GET[$name]) || !$_GET[$name]) {
return $default;
@ -319,7 +342,8 @@ function getgetparam($name,$default='') {
return $value;
}
function connect() {
function connect()
{
global $mysqlhost, $mysqllogin, $mysqlpass, $mysqldb, $dbencoding, $force_charset_in_connection;
if (!extension_loaded("mysql")) {
die('Mysql extension is not loaded');
@ -333,12 +357,14 @@ function connect() {
return $link;
}
function perform_query($query,$link) {
function perform_query($query, $link)
{
mysql_query($query, $link)
or die(' Query failed: ' . mysql_error() /*.": ".$query*/);
}
function select_one_row($query,$link) {
function select_one_row($query, $link)
{
$result = mysql_query($query, $link) or die(' Query failed: ' .
mysql_error() . ": " . $query);
$line = mysql_fetch_array($result, MYSQL_ASSOC);
@ -346,7 +372,8 @@ function select_one_row($query,$link) {
return $line;
}
function select_multi_assoc($query, $link) {
function select_multi_assoc($query, $link)
{
$sqlresult = mysql_query($query, $link) or die(' Query failed: ' .
mysql_error() . ": " . $query);
@ -358,13 +385,15 @@ function select_multi_assoc($query, $link) {
return $result;
}
function db_build_select($fields, $table, $conditions, $orderandgroup) {
function db_build_select($fields, $table, $conditions, $orderandgroup)
{
$condition = count($conditions) > 0 ? " where " . implode(" and ", $conditions) : "";
if ($orderandgroup) $orderandgroup = " " . $orderandgroup;
return "select $fields from $table$condition$orderandgroup";
}
function db_rows_count($table,$conditions,$countfields, $link) {
function db_rows_count($table, $conditions, $countfields, $link)
{
$result = mysql_query(db_build_select("count(" . ($countfields ? $countfields : "*") . ")", $table, $conditions, ""), $link)
or die(' Count query failed: ' . mysql_error());
$line = mysql_fetch_array($result, MYSQL_NUM);
@ -372,7 +401,8 @@ function db_rows_count($table,$conditions,$countfields, $link) {
return $line[0];
}
function start_xml_output() {
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");
@ -380,7 +410,8 @@ function start_xml_output() {
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
}
function start_html_output() {
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");
@ -388,25 +419,29 @@ function start_html_output() {
header("Content-type: text/html" . (isset($charset) ? "; charset=" . $charset : ""));
}
function escape_with_cdata($text) {
function escape_with_cdata($text)
{
return "<![CDATA[" . str_replace("]]>", "]]>]]&gt;<![CDATA[", $text) . "]]>";
}
function form_value($key) {
function form_value($key)
{
global $page;
if (isset($page) && isset($page["form$key"]))
return htmlspecialchars($page["form$key"]);
return "";
}
function form_value_cb($key) {
function form_value_cb($key)
{
global $page;
if (isset($page) && isset($page["form$key"]))
return $page["form$key"] === true;
return false;
}
function form_value_mb($key,$id) {
function form_value_mb($key, $id)
{
global $page;
if (isset($page) && isset($page["form$key"]) && is_array($page["form$key"])) {
return in_array($id, $page["form$key"]);
@ -414,31 +449,39 @@ function form_value_mb($key,$id) {
return false;
}
function no_field($key) {
function no_field($key)
{
return getlocal2("errors.required", array(getlocal($key)));
}
function failed_uploading_file($filename, $key) {
function failed_uploading_file($filename, $key)
{
return getlocal2("errors.failed.uploading.file",
array($filename, getlocal($key)));
}
function wrong_field($key) {
function wrong_field($key)
{
return getlocal2("errors.wrong_field", array(getlocal($key)));
}
function get_popup($href,$jshref,$message,$title,$wndName,$options) {
if(!$jshref) { $jshref = "'$href'"; }
function get_popup($href, $jshref, $message, $title, $wndName, $options)
{
if (!$jshref) {
$jshref = "'$href'";
}
return "<a href=\"$href\" target=\"_blank\" " . ($title ? "title=\"$title\" " : "") . "onclick=\"if(navigator.userAgent.toLowerCase().indexOf('opera') != -1 &amp;&amp; window.event.preventDefault) window.event.preventDefault();this.newWindow = window.open($jshref, '$wndName', '$options');this.newWindow.focus();this.newWindow.opener=window;return false;\">$message</a>";
}
function get_image($href,$width,$height) {
function get_image($href, $width, $height)
{
if ($width != 0 && $height != 0)
return "<img src=\"$href\" border=\"0\" width=\"$width\" height=\"$height\" alt=\"\"/>";
return "<img src=\"$href\" border=\"0\" alt=\"\"/>";
}
function get_gifimage_size($filename) {
function get_gifimage_size($filename)
{
if (function_exists('gd_info')) {
$info = gd_info();
if (isset($info['GIF Read Support']) && $info['GIF Read Support']) {
@ -454,7 +497,8 @@ function get_gifimage_size($filename) {
return array(0, 0);
}
function add_params($servlet, $params) {
function add_params($servlet, $params)
{
$infix = '?';
if (strstr($servlet, $infix) !== FALSE)
$infix = '&amp;';
@ -465,11 +509,13 @@ function add_params($servlet, $params) {
return $servlet;
}
function div($a,$b) {
function div($a, $b)
{
return ($a - ($a % $b)) / $b;
}
function date_diff_to_text($seconds) {
function date_diff_to_text($seconds)
{
$minutes = div($seconds, 60);
$seconds = $seconds % 60;
if ($minutes < 60) {
@ -481,11 +527,13 @@ function date_diff_to_text($seconds) {
}
}
function is_valid_email($email) {
function is_valid_email($email)
{
return preg_match("/^[^@]+@[^\.]+(\.[^\.]+)*$/", $email);
}
function get_app_location($showhost,$issecure) {
function get_app_location($showhost, $issecure)
{
global $webimroot;
if ($showhost) {
return ($issecure ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . $webimroot;
@ -494,14 +542,16 @@ function get_app_location($showhost,$issecure) {
}
}
function is_secure_request() {
function is_secure_request()
{
return
isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443'
|| isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on"
|| isset($_SERVER["HTTP_HTTPS"]) && $_SERVER["HTTP_HTTPS"] == "on";
}
function get_month_selection($fromtime,$totime) {
function get_month_selection($fromtime, $totime)
{
$start = getdate($fromtime);
$month = $start['mon'];
$year = $start['year'];
@ -518,20 +568,23 @@ function get_month_selection($fromtime,$totime) {
return $result;
}
function get_form_date($day,$month) {
function get_form_date($day, $month)
{
if (preg_match('/^(\d{2}).(\d{2})$/', $month, $matches)) {
return mktime(0, 0, 0, $matches[1], $day, $matches[2]);
}
return 0;
}
function set_form_date($utime,$prefix) {
function set_form_date($utime, $prefix)
{
global $page;
$page["form${prefix}day"] = date("d", $utime);
$page["form${prefix}month"] = date("m.y", $utime);
}
function date_to_text($unixtime) {
function date_to_text($unixtime)
{
if ($unixtime < 60 * 60 * 24 * 30)
return getlocal("time.never");
@ -593,7 +646,8 @@ $settings = array(
$settingsloaded = false;
$settings_in_db = array();
function loadsettings_($link) {
function loadsettings_($link)
{
global $settingsloaded, $settings_in_db, $settings, $mysqlprefix;
if ($settingsloaded) {
return;
@ -610,7 +664,8 @@ function loadsettings_($link) {
mysql_free_result($sqlresult);
}
function loadsettings() {
function loadsettings()
{
global $settingsloaded;
if (!$settingsloaded) {
$link = connect();
@ -619,7 +674,8 @@ function loadsettings() {
}
}
function getchatstyle() {
function getchatstyle()
{
global $settings;
$chatstyle = verifyparam("style", "/^\w+$/", "");
if ($chatstyle) {
@ -629,7 +685,8 @@ function getchatstyle() {
return $settings['chatstyle'];
}
function jspath() {
function jspath()
{
global $jsver;
return "js/$jsver";
}

View File

@ -19,7 +19,8 @@
* Evgeny Gryaznov - initial API and implementation
*/
function demo_print_message($msg,$format) {
function demo_print_message($msg, $format)
{
global $webim_encoding;
if ($format == "xml") {
print "<message>" . myiconv($webim_encoding, "utf-8", escape_with_cdata(message_to_html($msg))) . "</message>\n";
@ -28,7 +29,8 @@ function demo_print_message($msg,$format) {
}
}
function demo_process_thread($act,$outformat,$lastid,$isuser,$canpost,$istyping,$postmessage) {
function demo_process_thread($act, $outformat, $lastid, $isuser, $canpost, $istyping, $postmessage)
{
global $kind_for_agent, $kind_info, $kind_events, $kind_user, $kind_agent, $webimroot, $settings;
loadsettings();
if ($act == "refresh" || $act == "post") {

View File

@ -23,7 +23,8 @@ $ifregexp = "/\\\${(if|ifnot):([\w\.]+)}(.*?)(\\\${else:\\2}.*?)?\\\${endif:\\2}
$expand_include_path = "";
$current_style = "";
function check_condition($condition) {
function check_condition($condition)
{
global $errors, $page;
if ($condition == 'errors') {
return isset($errors) && count($errors) > 0;
@ -31,7 +32,8 @@ function check_condition($condition) {
return isset($page[$condition]) && $page[$condition];
}
function expand_condition($matches) {
function expand_condition($matches)
{
global $page, $ifregexp;
$value = check_condition($matches[2]) ^ ($matches[1] != 'if');
if ($value) {
@ -42,7 +44,8 @@ function expand_condition($matches) {
return "";
}
function expand_var($matches) {
function expand_var($matches)
{
global $page, $webimroot, $jsver, $errors, $current_style;
$prefix = $matches[1];
$var = $matches[2];
@ -87,21 +90,24 @@ function expand_var($matches) {
return "";
}
function expand_include($matches) {
function expand_include($matches)
{
global $expand_include_path;
$name = $matches[1];
$contents = @file_get_contents($expand_include_path . $name) or die("cannot load template");
return $contents;
}
function expandtext($text) {
function expandtext($text)
{
global $ifregexp;
$text = preg_replace_callback("/\\\${include:([\w\.]+)}/", "expand_include", $text);
$text = preg_replace_callback($ifregexp, "expand_condition", $text);
return preg_replace_callback("/\\\${(\w+:)?([\w\.,]+)}/", "expand_var", $text);
}
function expand($basedir,$style,$filename) {
function expand($basedir, $style, $filename)
{
global $expand_include_path, $current_style;
start_html_output();
if (!is_dir("$basedir/$style")) {

View File

@ -19,7 +19,8 @@
* Evgeny Gryaznov - initial API and implementation
*/
function setup_getcode_tabs($active) {
function setup_getcode_tabs($active)
{
global $page, $webimroot;
$page['tabselected'] = $active;
$page['tabs'] = array(
@ -28,7 +29,8 @@ function setup_getcode_tabs($active) {
);
}
function generate_button($title,$locale,$style,$group,$inner,$showhost,$forcesecure,$modsecurity) {
function generate_button($title, $locale, $style, $group, $inner, $showhost, $forcesecure, $modsecurity)
{
$link = get_app_location($showhost, $forcesecure) . "/client.php";
if ($locale)
$link = append_query($link, "locale=$locale");
@ -44,7 +46,8 @@ function generate_button($title,$locale,$style,$group,$inner,$showhost,$forcesec
return "<!-- mibew button -->" . $temp . "<!-- / mibew button -->";
}
function get_style_list($stylesfolder) {
function get_style_list($stylesfolder)
{
$stylelist = array("" => getlocal("page.preview.style_default"));
if ($handle = opendir($stylesfolder)) {
while (false !== ($file = readdir($handle))) {
@ -57,7 +60,8 @@ function get_style_list($stylesfolder) {
return $stylelist;
}
function verifyparam_groupid($paramid) {
function verifyparam_groupid($paramid)
{
global $settings, $errors;
$groupid = "";
if ($settings['enablegroups'] == '1') {
@ -73,7 +77,8 @@ function verifyparam_groupid($paramid) {
return $groupid;
}
function get_groups_list() {
function get_groups_list()
{
global $settings;
$result = array();
if ($settings['enablegroups'] == '1') {
@ -88,7 +93,8 @@ function get_groups_list() {
return $result;
}
function get_image_locales_map($localesdir) {
function get_image_locales_map($localesdir)
{
$imageLocales = array();
$allLocales = get_available_locales();
foreach ($allLocales as $curr) {

View File

@ -19,7 +19,8 @@
* Evgeny Gryaznov - initial API and implementation
*/
function group_by_id($id) {
function group_by_id($id)
{
global $mysqlprefix;
$link = connect();
$group = select_one_row(
@ -28,7 +29,8 @@ function group_by_id($id) {
return $group;
}
function get_group_name($group) {
function get_group_name($group)
{
global $home_locale, $current_locale;
if ($home_locale == $current_locale || !isset($group['vccommonname']) || !$group['vccommonname'])
return $group['vclocalname'];
@ -36,7 +38,8 @@ function get_group_name($group) {
return $group['vccommonname'];
}
function setup_group_settings_tabs($gid, $active) {
function setup_group_settings_tabs($gid, $active)
{
global $page, $webimroot, $settings;
if ($gid) {
$page['tabs'] = array(
@ -48,7 +51,8 @@ function setup_group_settings_tabs($gid, $active) {
}
}
function get_operator_groupslist($operatorid, $link) {
function get_operator_groupslist($operatorid, $link)
{
global $settings, $mysqlprefix;
if ($settings['enablegroups'] == '1') {
$groupids = array(0);

View File

@ -19,7 +19,8 @@
* Evgeny Gryaznov - initial API and implementation
*/
function log_notification($locale,$kind,$to,$subj,$text,$refop,$link) {
function log_notification($locale, $kind, $to, $subj, $text, $refop, $link)
{
global $mysqlprefix;
$query = sprintf(
"insert into ${mysqlprefix}chatnotification (locale,vckind,vcto,vcsubject,tmessage,refoperator,dtmcreated) values ('%s','%s','%s','%s','%s',%s,%s)",
@ -34,7 +35,8 @@ function log_notification($locale,$kind,$to,$subj,$text,$refop,$link) {
perform_query($query, $link);
}
function webim_mail($toaddr, $reply_to, $subject, $body, $link) {
function webim_mail($toaddr, $reply_to, $subject, $body, $link)
{
global $webim_encoding, $webim_mailbox, $mail_encoding, $current_locale;
$headers = "From: $webim_mailbox\r\n"
@ -50,7 +52,8 @@ function webim_mail($toaddr, $reply_to, $subject, $body, $link) {
@mail($toaddr, $real_subject, wordwrap(myiconv($webim_encoding, $mail_encoding, $body), 70), $headers);
}
function webim_xmpp($toaddr, $subject, $text, $link) {
function webim_xmpp($toaddr, $subject, $text, $link)
{
global $current_locale;
log_notification($current_locale, "xmpp", $toaddr, $subject, $text, null, $link);
}

View File

@ -33,7 +33,8 @@ $permission_ids = array(
$can_modifyprofile => "modifyprofile"
);
function operator_by_login($login) {
function operator_by_login($login)
{
global $mysqlprefix;
$link = connect();
$operator = select_one_row(
@ -42,7 +43,8 @@ function operator_by_login($login) {
return $operator;
}
function operator_by_email($mail) {
function operator_by_email($mail)
{
global $mysqlprefix;
$link = connect();
$operator = select_one_row(
@ -51,20 +53,23 @@ function operator_by_email($mail) {
return $operator;
}
function operator_by_id_($id,$link) {
function operator_by_id_($id, $link)
{
global $mysqlprefix;
return select_one_row(
"select * from ${mysqlprefix}chatoperator where operatorid = $id", $link);
}
function operator_by_id($id) {
function operator_by_id($id)
{
$link = connect();
$operator = operator_by_id_($id, $link);
mysql_close($link);
return $operator;
}
function operator_get_all() {
function operator_get_all()
{
global $mysqlprefix;
$link = connect();
@ -75,22 +80,26 @@ function operator_get_all() {
return $operators;
}
function operator_is_online($operator) {
function operator_is_online($operator)
{
global $settings;
return $operator['time'] < $settings['online_timeout'];
}
function operator_is_available($operator) {
function operator_is_available($operator)
{
global $settings;
return $operator['istatus'] == 0 && $operator['time'] < $settings['online_timeout'] ? "1" : "";
}
function operator_is_away($operator) {
function operator_is_away($operator)
{
global $settings;
return $operator['istatus'] != 0 && $operator['time'] < $settings['online_timeout'] ? "1" : "";
}
function update_operator($operatorid,$login,$email,$jabber,$password,$localename,$commonname,$notify) {
function update_operator($operatorid, $login, $email, $jabber, $password, $localename, $commonname, $notify)
{
global $mysqlprefix;
$link = connect();
$query = sprintf(
@ -110,7 +119,8 @@ function update_operator($operatorid,$login,$email,$jabber,$password,$localename
mysql_close($link);
}
function update_operator_avatar($operatorid,$avatar) {
function update_operator_avatar($operatorid, $avatar)
{
global $mysqlprefix;
$link = connect();
$query = sprintf(
@ -121,7 +131,8 @@ function update_operator_avatar($operatorid,$avatar) {
mysql_close($link);
}
function create_operator_($login,$email,$jabber,$password,$localename,$commonname,$notify,$link) {
function create_operator_($login, $email, $jabber, $password, $localename, $commonname, $notify, $link)
{
global $mysqlprefix;
$query = sprintf(
"insert into ${mysqlprefix}chatoperator (vclogin,vcpassword,vclocalename,vccommonname,vcavatar,vcemail,vcjabbername,inotify) values ('%s','%s','%s','%s','%s','%s','%s',%s)",
@ -140,21 +151,24 @@ function create_operator_($login,$email,$jabber,$password,$localename,$commonnam
return select_one_row("select * from ${mysqlprefix}chatoperator where operatorid = $id", $link);
}
function create_operator($login,$email,$jabber,$password,$localename,$commonname,$notify) {
function create_operator($login, $email, $jabber, $password, $localename, $commonname, $notify)
{
$link = connect();
$newop = create_operator_($login, $email, $jabber, $password, $localename, $commonname, $notify, $link);
mysql_close($link);
return $newop;
}
function notify_operator_alive($operatorid, $istatus) {
function notify_operator_alive($operatorid, $istatus)
{
global $mysqlprefix;
$link = connect();
perform_query("update ${mysqlprefix}chatoperator set istatus = $istatus, dtmlastvisited = CURRENT_TIMESTAMP where operatorid = $operatorid", $link);
mysql_close($link);
}
function has_online_operators($groupid="") {
function has_online_operators($groupid = "")
{
global $settings, $mysqlprefix;
loadsettings();
$link = connect();
@ -170,7 +184,8 @@ function has_online_operators($groupid="") {
return $row['time'] < $settings['online_timeout'] && $row['total'] > 0;
}
function is_operator_online($operatorid, $link) {
function is_operator_online($operatorid, $link)
{
global $settings, $mysqlprefix;
loadsettings_($link);
$query = "select count(*) as total, min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
@ -179,7 +194,8 @@ function is_operator_online($operatorid, $link) {
return $row['time'] < $settings['online_timeout'] && $row['total'] == 1;
}
function get_operator_name($operator) {
function get_operator_name($operator)
{
global $home_locale, $current_locale;
if ($home_locale == $current_locale)
return $operator['vclocalename'];
@ -187,14 +203,16 @@ function get_operator_name($operator) {
return $operator['vccommonname'];
}
function append_query($link,$pv) {
function append_query($link, $pv)
{
$infix = '?';
if (strstr($link, $infix) !== FALSE)
$infix = '&amp;';
return "$link$infix$pv";
}
function check_login($redirect=true) {
function check_login($redirect = true)
{
global $webimroot, $mysqlprefix;
if (!isset($_SESSION["${mysqlprefix}operator"])) {
if (isset($_COOKIE['webim_lite'])) {
@ -220,12 +238,14 @@ function check_login($redirect=true) {
return $_SESSION["${mysqlprefix}operator"];
}
function get_logged_in() {
function get_logged_in()
{
global $mysqlprefix;
return isset($_SESSION["${mysqlprefix}operator"]) ? $_SESSION["${mysqlprefix}operator"] : FALSE;
}
function login_operator($operator,$remember) {
function login_operator($operator, $remember)
{
global $webimroot, $mysqlprefix;
$_SESSION["${mysqlprefix}operator"] = $operator;
if ($remember) {
@ -237,7 +257,8 @@ function login_operator($operator,$remember) {
}
}
function logout_operator() {
function logout_operator()
{
global $webimroot, $mysqlprefix;
unset($_SESSION["${mysqlprefix}operator"]);
unset($_SESSION['backpath']);
@ -246,7 +267,8 @@ function logout_operator() {
}
}
function setup_redirect_links($threadid,$token) {
function setup_redirect_links($threadid, $token)
{
global $page, $webimroot, $settings, $mysqlprefix;
loadsettings();
$link = connect();
@ -314,7 +336,8 @@ function setup_redirect_links($threadid,$token) {
$permission_list = array();
function get_permission_list() {
function get_permission_list()
{
global $permission_list, $permission_ids;
if (count($permission_list) == 0) {
foreach ($permission_ids as $permid) {
@ -327,12 +350,14 @@ function get_permission_list() {
return $permission_list;
}
function is_capable($perm,$operator) {
function is_capable($perm, $operator)
{
$permissions = $operator && isset($operator['iperm']) ? $operator['iperm'] : 0;
return $perm >= 0 && $perm < 32 && ($permissions & (1 << $perm)) != 0;
}
function prepare_menu($operator,$hasright=true) {
function prepare_menu($operator, $hasright = true)
{
global $page, $settings, $can_administrate;
$page['operator'] = topage(get_operator_name($operator));
if ($hasright) {
@ -345,13 +370,15 @@ function prepare_menu($operator,$hasright=true) {
}
}
function get_all_groups($link) {
function get_all_groups($link)
{
global $mysqlprefix;
$query = "select ${mysqlprefix}chatgroup.groupid as groupid, vclocalname, vclocaldescription from ${mysqlprefix}chatgroup order by vclocalname";
return select_multi_assoc($query, $link);
}
function get_groups($link,$checkaway) {
function get_groups($link, $checkaway)
{
global $mysqlprefix;
$query = "select ${mysqlprefix}chatgroup.groupid as groupid, vclocalname, vclocaldescription" .
", (SELECT count(*) from ${mysqlprefix}chatgroupoperator where ${mysqlprefix}chatgroup.groupid = " .
@ -371,7 +398,8 @@ function get_groups($link,$checkaway) {
return select_multi_assoc($query, $link);
}
function get_operator_groupids($operatorid) {
function get_operator_groupids($operatorid)
{
global $mysqlprefix;
$link = connect();
$query = "select groupid from ${mysqlprefix}chatgroupoperator where operatorid = $operatorid";

View File

@ -19,7 +19,8 @@
* Evgeny Gryaznov - initial API and implementation
*/
function setup_operator_settings_tabs($opId, $active) {
function setup_operator_settings_tabs($opId, $active)
{
global $page, $webimroot, $settings;
loadsettings();

View File

@ -22,19 +22,22 @@
$pagination_spacing = "&nbsp;&nbsp;&nbsp;";
$links_on_page = 5;
function generate_pagination_link($page,$title) {
function generate_pagination_link($page, $title)
{
$lnk = $_SERVER['REQUEST_URI'];
$href = preg_replace("/\?page=\d+\&/", "?", preg_replace("/\&page=\d+/", "", $lnk));
$href .= strstr($href, "?") ? "&page=$page" : "?page=$page";
return "<a href=\"" . htmlspecialchars($href) . "\" class=\"pagelink\">$title</a>";
}
function generate_pagination_image($id,$alt) {
function generate_pagination_image($id, $alt)
{
global $webimroot;
return "<img src=\"$webimroot/images/$id.gif\" border=\"0\" alt=\"" . htmlspecialchars($alt) . "\"/>";
}
function prepare_pagination($items_count,$default_items_per_page=15) {
function prepare_pagination($items_count, $default_items_per_page = 15)
{
global $page;
if ($items_count) {
@ -61,7 +64,8 @@ function prepare_pagination($items_count,$default_items_per_page=15) {
}
}
function setup_pagination($items,$default_items_per_page=15) {
function setup_pagination($items, $default_items_per_page = 15)
{
global $page;
prepare_pagination($items ? count($items) : 0, $default_items_per_page);
if ($items && count($items) > 0) {
@ -72,7 +76,8 @@ function setup_pagination($items,$default_items_per_page=15) {
}
}
function select_with_pagintation($fields, $table, $conditions, $order, $countfields, $link) {
function select_with_pagintation($fields, $table, $conditions, $order, $countfields, $link)
{
global $page;
$count = db_rows_count($table, $conditions, $countfields, $link);
prepare_pagination($count);
@ -85,13 +90,15 @@ function select_with_pagintation($fields, $table, $conditions, $order, $countfie
}
}
function setup_empty_pagination() {
function setup_empty_pagination()
{
global $page;
$page['pagination.items'] = false;
$page['pagination'] = false;
}
function generate_pagination($pagination,$bottom=true) {
function generate_pagination($pagination, $bottom = true)
{
global $pagination_spacing, $links_on_page;
$result = getlocal2("tag.pagination.info",
array($pagination['page'], $pagination['total'], $pagination['start'] + 1, $pagination['end'], $pagination['count'])) . "<br/>";

View File

@ -19,7 +19,8 @@
* Evgeny Gryaznov - initial API and implementation
*/
function update_settings() {
function update_settings()
{
global $settings, $settings_in_db, $mysqlprefix;
$link = connect();
foreach ($settings as $key => $value) {
@ -33,7 +34,8 @@ function update_settings() {
mysql_close($link);
}
function setup_settings_tabs($active) {
function setup_settings_tabs($active)
{
global $page, $webimroot;
$page['tabselected'] = $active;
$page['tabs'] = array(

View File

@ -19,7 +19,8 @@
* Evgeny Gryaznov - initial API and implementation
*/
function get_useragent_version($userAgent) {
function get_useragent_version($userAgent)
{
global $knownAgents;
if (is_array($knownAgents)) {
$userAgent = strtolower($userAgent);
@ -48,7 +49,8 @@ function get_useragent_version($userAgent) {
return $userAgent;
}
function get_user_addr($addr) {
function get_user_addr($addr)
{
global $settings;
if ($settings['geolink'] && preg_match("/(\\d+\\.\\d+\\.\\d+\\.\\d+)/", $addr, $matches)) {
$userip = $matches[1];

View File

@ -31,7 +31,8 @@ loadsettings();
$errors = array();
$page = array();
function load_canned_messages($locale, $groupid) {
function load_canned_messages($locale, $groupid)
{
global $mysqlprefix;
$link = connect();
$query = "select id, vcvalue from ${mysqlprefix}chatresponses " .

View File

@ -23,7 +23,8 @@ require_once('../libs/common.php');
require_once('../libs/operator.php');
require_once('../libs/pagination.php');
function load_message($key) {
function load_message($key)
{
global $mysqlprefix;
$link = connect();
$result = select_one_row("select vcvalue from ${mysqlprefix}chatresponses where id = $key", $link);
@ -31,7 +32,8 @@ function load_message($key) {
return $result ? $result['vcvalue'] : null;
}
function save_message($key,$message) {
function save_message($key, $message)
{
global $mysqlprefix;
$link = connect();
perform_query("update ${mysqlprefix}chatresponses set vcvalue = '" . mysql_real_escape_string($message, $link) . "' " .
@ -39,7 +41,8 @@ function save_message($key,$message) {
mysql_close($link);
}
function add_message($locale,$groupid,$message) {
function add_message($locale, $groupid, $message)
{
global $mysqlprefix;
$link = connect();
perform_query("insert into ${mysqlprefix}chatresponses (locale,groupid,vcvalue) values ('$locale'," .

View File

@ -29,7 +29,8 @@ $page = array('grid' => '');
$errors = array();
$groupid = '';
function group_by_name($name) {
function group_by_name($name)
{
global $mysqlprefix;
$link = connect();
$group = select_one_row(
@ -38,7 +39,8 @@ function group_by_name($name) {
return $group;
}
function create_group($name,$descr,$commonname,$commondescr) {
function create_group($name, $descr, $commonname, $commondescr)
{
global $mysqlprefix;
$link = connect();
$query = sprintf(
@ -56,7 +58,8 @@ function create_group($name,$descr,$commonname,$commondescr) {
return $newdep;
}
function update_group($groupid,$name,$descr,$commonname,$commondescr) {
function update_group($groupid, $name, $descr, $commonname, $commondescr)
{
global $mysqlprefix;
$link = connect();
$query = sprintf(

View File

@ -25,7 +25,8 @@ require_once('../libs/groups.php');
$operator = check_login();
function get_group_members($groupid) {
function get_group_members($groupid)
{
global $mysqlprefix;
$link = connect();
$query = "select operatorid from ${mysqlprefix}chatgroupoperator where groupid = $groupid";
@ -34,7 +35,8 @@ function get_group_members($groupid) {
return $result;
}
function update_group_members($groupid,$newvalue) {
function update_group_members($groupid, $newvalue)
{
global $mysqlprefix;
$link = connect();
perform_query("delete from ${mysqlprefix}chatgroupoperator where groupid = $groupid", $link);
@ -44,7 +46,8 @@ function update_group_members($groupid,$newvalue) {
mysql_close($link);
}
function get_operators() {
function get_operators()
{
global $mysqlprefix;
$link = connect();

View File

@ -47,12 +47,14 @@ if( isset($_GET['act']) && $_GET['act'] == 'del' ) {
}
}
function is_online($group) {
function is_online($group)
{
global $settings;
return $group['ilastseen'] !== NULL && $group['ilastseen'] < $settings['online_timeout'] ? "1" : "";
}
function is_away($group) {
function is_away($group)
{
global $settings;
return $group['ilastseenaway'] !== NULL && $group['ilastseenaway'] < $settings['online_timeout'] ? "1" : "";
}

View File

@ -29,7 +29,8 @@ $page = array();
setlocale(LC_TIME, getstring("time.locale"));
function notification_info($id) {
function notification_info($id)
{
global $mysqlprefix;
$link = connect();
$notification = select_one_row(db_build_select(

View File

@ -25,7 +25,8 @@ require_once('../libs/operator_settings.php');
$operator = check_login();
function update_operator_groups($operatorid,$newvalue) {
function update_operator_groups($operatorid, $newvalue)
{
global $mysqlprefix;
$link = connect();
perform_query("delete from ${mysqlprefix}chatgroupoperator where operatorid = $operatorid", $link);

View File

@ -25,7 +25,8 @@ require_once('../libs/operator_settings.php');
$operator = check_login();
function update_operator_permissions($operatorid,$newvalue) {
function update_operator_permissions($operatorid, $newvalue)
{
global $mysqlprefix;
$link = connect();
$query = "update ${mysqlprefix}chatoperator set iperm = $newvalue where operatorid = $operatorid";

View File

@ -31,7 +31,8 @@ $page = array();
loadsettings();
setlocale(LC_TIME, getstring("time.locale"));
function thread_info($id) {
function thread_info($id)
{
global $mysqlprefix;
$link = connect();
$thread = select_one_row("select userName,agentName,remote,userAgent," .

View File

@ -23,21 +23,24 @@ require_once('../libs/common.php');
require_once('../libs/operator.php');
require_once('../libs/pagination.php');
function compare_localization_by_l1($a, $b) {
function compare_localization_by_l1($a, $b)
{
if ($a == $b) {
return 0;
}
return ($a['l1'] < $b['l1']) ? -1 : 1;
}
function compare_localization_by_id($a, $b) {
function compare_localization_by_id($a, $b)
{
if ($a == $b) {
return 0;
}
return ($a['id'] < $b['id']) ? -1 : 1;
}
function load_idlist($name) {
function load_idlist($name)
{
$result = array();
$fp = @fopen(dirname(__FILE__) . "/../locales/names/$name", "r");
if ($fp !== FALSE) {
@ -52,7 +55,8 @@ function load_idlist($name) {
return $result;
}
function save_message($locale,$key,$value) {
function save_message($locale, $key, $value)
{
global $webim_encoding;
$result = "";
$added = false;
@ -98,7 +102,8 @@ function save_message($locale,$key,$value) {
}
}
function get_auxiliary($s) {
function get_auxiliary($s)
{
$res = "";
if (preg_match_all("/<[^>]+?>|[:]|\{\d+\}|[Mm]ibew|[Ww]ebim/", $s, $matches, PREG_PATTERN_ORDER)) {
foreach ($matches[0] as $val) {

View File

@ -49,7 +49,8 @@ $threadstate_key = array(
$state_loading => "chat.thread.state_loading"
);
function thread_to_xml($thread,$link) {
function thread_to_xml($thread, $link)
{
global $state_chatting, $threadstate_to_string, $threadstate_key,
$webim_encoding, $operator, $settings,
$can_viewthreads, $can_takeover, $mysqlprefix;
@ -112,7 +113,8 @@ function thread_to_xml($thread,$link) {
return $result;
}
function print_pending_threads($groupids,$since) {
function print_pending_threads($groupids, $since)
{
global $webim_encoding, $settings, $state_closed, $state_left, $mysqlprefix;
$link = connect();
@ -148,7 +150,8 @@ function print_pending_threads($groupids,$since) {
echo "</threads>";
}
function print_operators() {
function print_operators()
{
echo "<operators>";
$operators = operator_get_all();

View File

@ -37,7 +37,8 @@ if( isset($_GET['userid'])) {
$userid = verifyparam("userid", "/^.{0,63}$/", "");
}
function threads_by_userid($userid) {
function threads_by_userid($userid)
{
global $mysqlprefix;
if ($userid == "") {
return null;