mirror of
				https://github.com/Mibew/i18n.git
				synced 2025-11-04 10:35:08 +03:00 
			
		
		
		
	format code
This commit is contained in:
		
							parent
							
								
									2bcffd5f4a
								
							
						
					
					
						commit
						03dec2afb2
					
				
							
								
								
									
										80
									
								
								src/messenger/.idea/projectCodeStyle.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								src/messenger/.idea/projectCodeStyle.xml
									
									
									
									
									
										Normal 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>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -99,7 +99,7 @@ $dbtables = array(
 | 
				
			|||||||
		"blockedCount" => "int DEFAULT 0"
 | 
							"blockedCount" => "int DEFAULT 0"
 | 
				
			||||||
	),
 | 
						),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"${mysqlprefix}chatconfig" => array (
 | 
						"${mysqlprefix}chatconfig" => array(
 | 
				
			||||||
		"id" => "INT NOT NULL auto_increment PRIMARY KEY",
 | 
							"id" => "INT NOT NULL auto_increment PRIMARY KEY",
 | 
				
			||||||
		"vckey" => "varchar(255)",
 | 
							"vckey" => "varchar(255)",
 | 
				
			||||||
		"vcvalue" => "varchar(255)",
 | 
							"vcvalue" => "varchar(255)",
 | 
				
			||||||
@ -137,7 +137,8 @@ $dbtables_can_update = array(
 | 
				
			|||||||
	"${mysqlprefix}chatnotification" => array(),
 | 
						"${mysqlprefix}chatnotification" => array(),
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function show_install_err($text) {
 | 
					function show_install_err($text)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page, $version, $errors, $webimroot;
 | 
						global $page, $version, $errors, $webimroot;
 | 
				
			||||||
	$page = array(
 | 
						$page = array(
 | 
				
			||||||
		'version' => $version,
 | 
							'version' => $version,
 | 
				
			||||||
@ -149,17 +150,18 @@ function show_install_err($text) {
 | 
				
			|||||||
	exit;
 | 
						exit;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function create_table($id,$link) {
 | 
					function create_table($id, $link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $dbtables, $memtables, $dbencoding, $mysqlprefix;
 | 
						global $dbtables, $memtables, $dbencoding, $mysqlprefix;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(!isset($dbtables[$id])) {
 | 
						if (!isset($dbtables[$id])) {
 | 
				
			||||||
		show_install_err("Unknown table: $id, ".mysql_error());
 | 
							show_install_err("Unknown table: $id, " . mysql_error());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$query =
 | 
						$query =
 | 
				
			||||||
		"CREATE TABLE $id\n".
 | 
								"CREATE TABLE $id\n" .
 | 
				
			||||||
		"(\n";
 | 
								"(\n";
 | 
				
			||||||
	foreach( $dbtables[$id] as $k => $v ) {
 | 
						foreach ($dbtables[$id] as $k => $v) {
 | 
				
			||||||
		$query .= "	$k $v,\n";
 | 
							$query .= "	$k $v,\n";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -171,19 +173,20 @@ function create_table($id,$link) {
 | 
				
			|||||||
		$query .= " TYPE=InnoDb";
 | 
							$query .= " TYPE=InnoDb";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mysql_query($query,$link) or show_install_err(' Query failed: '.mysql_error());
 | 
						mysql_query($query, $link) or show_install_err(' Query failed: ' . mysql_error());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $id == "${mysqlprefix}chatoperator" ) {
 | 
						if ($id == "${mysqlprefix}chatoperator") {
 | 
				
			||||||
		create_operator_("admin", "", "", "", "Administrator", "Administrator", 0, $link);
 | 
							create_operator_("admin", "", "", "", "Administrator", "Administrator", 0, $link);
 | 
				
			||||||
	} else if( $id == "${mysqlprefix}chatrevision" ) {
 | 
						} else if ($id == "${mysqlprefix}chatrevision") {
 | 
				
			||||||
		perform_query("INSERT INTO ${mysqlprefix}chatrevision VALUES (1)",$link);
 | 
							perform_query("INSERT INTO ${mysqlprefix}chatrevision VALUES (1)", $link);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_tables($link) {
 | 
					function get_tables($link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqldb, $errors;
 | 
						global $mysqldb, $errors;
 | 
				
			||||||
	$result = mysql_query("SHOW TABLES FROM `$mysqldb`");
 | 
						$result = mysql_query("SHOW TABLES FROM `$mysqldb`");
 | 
				
			||||||
	if( $result ) {
 | 
						if ($result) {
 | 
				
			||||||
		$arr = array();
 | 
							$arr = array();
 | 
				
			||||||
		while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
 | 
							while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
 | 
				
			||||||
			$arr[] = $row[0];
 | 
								$arr[] = $row[0];
 | 
				
			||||||
@ -192,15 +195,16 @@ function get_tables($link) {
 | 
				
			|||||||
		return $arr;
 | 
							return $arr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$errors[] = "Cannot get tables from database. Error: ".mysql_error();
 | 
							$errors[] = "Cannot get tables from database. Error: " . mysql_error();
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_columns($tablename,$link) {
 | 
					function get_columns($tablename, $link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $errors;
 | 
						global $errors;
 | 
				
			||||||
	$result = mysql_query("SHOW COLUMNS FROM $tablename");
 | 
						$result = mysql_query("SHOW COLUMNS FROM $tablename");
 | 
				
			||||||
	if( $result ) {
 | 
						if ($result) {
 | 
				
			||||||
		$arr = array();
 | 
							$arr = array();
 | 
				
			||||||
		while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
 | 
							while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
 | 
				
			||||||
			$arr[] = $row[0];
 | 
								$arr[] = $row[0];
 | 
				
			||||||
@ -209,7 +213,7 @@ function get_columns($tablename,$link) {
 | 
				
			|||||||
		return $arr;
 | 
							return $arr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$errors[] = "Cannot get columns from table \"$tablename\". Error: ".mysql_error();
 | 
							$errors[] = "Cannot get columns from table \"$tablename\". Error: " . mysql_error();
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -23,143 +23,144 @@ require_once('../libs/common.php');
 | 
				
			|||||||
require_once('../libs/operator.php');
 | 
					require_once('../libs/operator.php');
 | 
				
			||||||
require_once('dbinfo.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());
 | 
						$res = mysql_query($query, $link)
 | 
				
			||||||
 | 
						or show_install_err(' Query failed: ' . mysql_error());
 | 
				
			||||||
	return $res;
 | 
						return $res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$act = verifyparam( "act", "/^(silentcreateall|createdb|ct|dt|addcolumns)$/");
 | 
					$act = verifyparam("act", "/^(silentcreateall|createdb|ct|dt|addcolumns)$/");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$link = @mysql_connect($mysqlhost,$mysqllogin ,$mysqlpass )
 | 
					$link = @mysql_connect($mysqlhost, $mysqllogin, $mysqlpass)
 | 
				
			||||||
	or show_install_err('Could not connect: ' . mysql_error());
 | 
							 or show_install_err('Could not connect: ' . mysql_error());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if ($act == "silentcreateall") {
 | 
					if ($act == "silentcreateall") {
 | 
				
			||||||
	mysql_query("CREATE DATABASE $mysqldb",$link)
 | 
						mysql_query("CREATE DATABASE $mysqldb", $link)
 | 
				
			||||||
		or show_install_err(' Query failed: '.mysql_error());
 | 
						or show_install_err(' Query failed: ' . mysql_error());
 | 
				
			||||||
	foreach($dbtables as $id) {
 | 
						foreach ($dbtables as $id) {
 | 
				
			||||||
		create_table($id, $link);
 | 
							create_table($id, $link);
 | 
				
			||||||
   	}
 | 
						}
 | 
				
			||||||
} else if($act == "createdb") {
 | 
					} else if ($act == "createdb") {
 | 
				
			||||||
	mysql_query("CREATE DATABASE $mysqldb",$link)
 | 
						mysql_query("CREATE DATABASE $mysqldb", $link)
 | 
				
			||||||
		or show_install_err(' Query failed: '.mysql_error());
 | 
						or show_install_err(' Query failed: ' . mysql_error());
 | 
				
			||||||
} else {
 | 
					} else {
 | 
				
			||||||
	mysql_select_db($mysqldb,$link)
 | 
						mysql_select_db($mysqldb, $link)
 | 
				
			||||||
		or show_install_err('Could not select database');
 | 
						or show_install_err('Could not select database');
 | 
				
			||||||
	if( $force_charset_in_connection ) {
 | 
						if ($force_charset_in_connection) {
 | 
				
			||||||
		mysql_query("SET character set $dbencoding", $link);
 | 
							mysql_query("SET character set $dbencoding", $link);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $act == "ct") {
 | 
						if ($act == "ct") {
 | 
				
			||||||
		$curr_tables = get_tables($link);
 | 
							$curr_tables = get_tables($link);
 | 
				
			||||||
		if( $curr_tables === false) {
 | 
							if ($curr_tables === false) {
 | 
				
			||||||
			show_install_err($errors[0]);
 | 
								show_install_err($errors[0]);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$tocreate = array_diff(array_keys($dbtables), $curr_tables);
 | 
							$tocreate = array_diff(array_keys($dbtables), $curr_tables);
 | 
				
			||||||
		foreach( $tocreate as $id) {
 | 
							foreach ($tocreate as $id) {
 | 
				
			||||||
			create_table($id, $link);
 | 
								create_table($id, $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else if( $act == "dt") {
 | 
						} else if ($act == "dt") {
 | 
				
			||||||
		foreach( array_keys($dbtables) as $id) {
 | 
							foreach (array_keys($dbtables) as $id) {
 | 
				
			||||||
			mysql_query("DROP TABLE IF EXISTS $id",$link)
 | 
								mysql_query("DROP TABLE IF EXISTS $id", $link)
 | 
				
			||||||
				or show_install_err(' Query failed: '.mysql_error());
 | 
								or show_install_err(' Query failed: ' . mysql_error());
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else if( $act == "addcolumns") {
 | 
						} else if ($act == "addcolumns") {
 | 
				
			||||||
		$absent = array();
 | 
							$absent = array();
 | 
				
			||||||
		foreach( $dbtables as $id => $columns) {
 | 
							foreach ($dbtables as $id => $columns) {
 | 
				
			||||||
			$curr_columns = get_columns($id, $link);
 | 
								$curr_columns = get_columns($id, $link);
 | 
				
			||||||
			if( $curr_columns === false ) {
 | 
								if ($curr_columns === false) {
 | 
				
			||||||
				show_install_err($errors[0]);
 | 
									show_install_err($errors[0]);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			$tocreate = array_diff(array_keys($columns), $curr_columns);
 | 
								$tocreate = array_diff(array_keys($columns), $curr_columns);
 | 
				
			||||||
			foreach($tocreate as $v) {
 | 
								foreach ($tocreate as $v) {
 | 
				
			||||||
				$absent[] = "$id.$v";
 | 
									$absent[] = "$id.$v";
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatmessage.agentId", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatmessage.agentId", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatmessage ADD agentId int NOT NULL DEFAULT 0 AFTER ikind", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatmessage ADD agentId int NOT NULL DEFAULT 0 AFTER ikind", $link);
 | 
				
			||||||
			runsql("update ${mysqlprefix}chatmessage, ${mysqlprefix}chatoperator set agentId = operatorid where agentId = 0 AND ikind = 2 AND (vclocalename = tname OR vccommonname = tname)", $link);
 | 
								runsql("update ${mysqlprefix}chatmessage, ${mysqlprefix}chatoperator set agentId = operatorid where agentId = 0 AND ikind = 2 AND (vclocalename = tname OR vccommonname = tname)", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatthread.agentId", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatthread.agentId", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatthread ADD agentId int NOT NULL DEFAULT 0 AFTER agentName", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatthread ADD agentId int NOT NULL DEFAULT 0 AFTER agentName", $link);
 | 
				
			||||||
			runsql("update ${mysqlprefix}chatthread, ${mysqlprefix}chatoperator set agentId = operatorid where agentId = 0 AND (vclocalename = agentName OR vccommonname = agentName)", $link);
 | 
								runsql("update ${mysqlprefix}chatthread, ${mysqlprefix}chatoperator set agentId = operatorid where agentId = 0 AND (vclocalename = agentName OR vccommonname = agentName)", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatthread.agentTyping", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatthread.agentTyping", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatthread ADD agentTyping int DEFAULT 0", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatthread ADD agentTyping int DEFAULT 0", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatthread.userTyping", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatthread.userTyping", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatthread ADD userTyping int DEFAULT 0", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatthread ADD userTyping int DEFAULT 0", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatthread.messageCount", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatthread.messageCount", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatthread ADD messageCount varchar(16)", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatthread ADD messageCount varchar(16)", $link);
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatmessage ADD INDEX idx_threadid_ikind (threadid, ikind)", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatmessage ADD INDEX idx_threadid_ikind (threadid, ikind)", $link);
 | 
				
			||||||
			runsql("UPDATE ${mysqlprefix}chatthread t SET t.messageCount = (SELECT COUNT(*) FROM ${mysqlprefix}chatmessage WHERE ${mysqlprefix}chatmessage.threadid = t.threadid AND ikind = 1)", $link);
 | 
								runsql("UPDATE ${mysqlprefix}chatthread t SET t.messageCount = (SELECT COUNT(*) FROM ${mysqlprefix}chatmessage WHERE ${mysqlprefix}chatmessage.threadid = t.threadid AND ikind = 1)", $link);
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatmessage DROP INDEX idx_threadid_ikind", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatmessage DROP INDEX idx_threadid_ikind", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatthread.nextagent", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatthread.nextagent", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatthread ADD nextagent int NOT NULL DEFAULT 0", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatthread ADD nextagent int NOT NULL DEFAULT 0", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatthread.shownmessageid", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatthread.shownmessageid", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatthread ADD shownmessageid int NOT NULL DEFAULT 0", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatthread ADD shownmessageid int NOT NULL DEFAULT 0", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatthread.userid", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatthread.userid", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatthread ADD userid varchar(255) DEFAULT \"\"", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatthread ADD userid varchar(255) DEFAULT \"\"", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatoperator.iperm", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatoperator.iperm", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD iperm int DEFAULT 65535", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD iperm int DEFAULT 65535", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatoperator.istatus", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatoperator.istatus", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD istatus int DEFAULT 0", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD istatus int DEFAULT 0", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatoperator.inotify", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatoperator.inotify", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD inotify int DEFAULT 0", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD inotify int DEFAULT 0", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatoperator.vcavatar", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatoperator.vcavatar", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD vcavatar varchar(255)", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD vcavatar varchar(255)", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatoperator.vcjabbername", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatoperator.vcjabbername", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD vcjabbername varchar(255)", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD vcjabbername varchar(255)", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatoperator.vcemail", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatoperator.vcemail", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD vcemail varchar(64)", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD vcemail varchar(64)", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatoperator.dtmrestore", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatoperator.dtmrestore", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD dtmrestore datetime DEFAULT 0", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD dtmrestore datetime DEFAULT 0", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatoperator.vcrestoretoken", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatoperator.vcrestoretoken", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD vcrestoretoken varchar(64)", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD vcrestoretoken varchar(64)", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatthread.groupid", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatthread.groupid", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatthread ADD groupid int references ${mysqlprefix}chatgroup(groupid)", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatthread ADD groupid int references ${mysqlprefix}chatgroup(groupid)", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatthread.userAgent", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatthread.userAgent", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatthread ADD userAgent varchar(255)", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatthread ADD userAgent varchar(255)", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( in_array("${mysqlprefix}chatgroup.vcemail", $absent) ) {
 | 
							if (in_array("${mysqlprefix}chatgroup.vcemail", $absent)) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD vcemail varchar(64)", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD vcemail varchar(64)", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$res = mysql_query("select null from information_schema.statistics where table_name = '${mysqlprefix}chatmessage' and index_name = 'idx_agentid'", $link);
 | 
							$res = mysql_query("select null from information_schema.statistics where table_name = '${mysqlprefix}chatmessage' and index_name = 'idx_agentid'", $link);
 | 
				
			||||||
		if($res && mysql_num_rows($res) == 0) {
 | 
							if ($res && mysql_num_rows($res) == 0) {
 | 
				
			||||||
			runsql("ALTER TABLE ${mysqlprefix}chatmessage ADD INDEX idx_agentid (agentid)", $link);
 | 
								runsql("ALTER TABLE ${mysqlprefix}chatmessage ADD INDEX idx_agentid (agentid)", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -33,16 +33,17 @@ $page['nextstep'] = false;
 | 
				
			|||||||
$page['nextnotice'] = false;
 | 
					$page['nextnotice'] = false;
 | 
				
			||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function check_webimroot() {
 | 
					function check_webimroot()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page, $errors, $webimroot;
 | 
						global $page, $errors, $webimroot;
 | 
				
			||||||
	$requestUri = $_SERVER["REQUEST_URI"];
 | 
						$requestUri = $_SERVER["REQUEST_URI"];
 | 
				
			||||||
	if(!preg_match('/^(.*)\\/install(\\/[^\\/\\\\]*)?$/', $requestUri, $matches)) {
 | 
						if (!preg_match('/^(.*)\\/install(\\/[^\\/\\\\]*)?$/', $requestUri, $matches)) {
 | 
				
			||||||
		$errors[] = "Cannot detect application location: $requestUri";
 | 
							$errors[] = "Cannot detect application location: $requestUri";
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$applocation = $matches[1];
 | 
						$applocation = $matches[1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if($applocation != $webimroot) {
 | 
						if ($applocation != $webimroot) {
 | 
				
			||||||
		$errors[] = "Please, check file ${applocation}/libs/config.php<br/>Wrong value of \$webimroot variable, should be \"$applocation\"";
 | 
							$errors[] = "Please, check file ${applocation}/libs/config.php<br/>Wrong value of \$webimroot variable, should be \"$applocation\"";
 | 
				
			||||||
		$webimroot = $applocation;
 | 
							$webimroot = $applocation;
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
@ -52,16 +53,17 @@ function check_webimroot() {
 | 
				
			|||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function check_connection() {
 | 
					function check_connection()
 | 
				
			||||||
	global $mysqlhost,$mysqllogin,$mysqlpass, $page, $errors, $webimroot;
 | 
					{
 | 
				
			||||||
	$link = @mysql_connect($mysqlhost,$mysqllogin,$mysqlpass);
 | 
						global $mysqlhost, $mysqllogin, $mysqlpass, $page, $errors, $webimroot;
 | 
				
			||||||
 | 
						$link = @mysql_connect($mysqlhost, $mysqllogin, $mysqlpass);
 | 
				
			||||||
	if ($link) {
 | 
						if ($link) {
 | 
				
			||||||
		$result = mysql_query("SELECT VERSION() as c", $link);
 | 
							$result = mysql_query("SELECT VERSION() as c", $link);
 | 
				
			||||||
		if( $result && $ver = mysql_fetch_array($result, MYSQL_ASSOC)) {
 | 
							if ($result && $ver = mysql_fetch_array($result, MYSQL_ASSOC)) {
 | 
				
			||||||
			$page['done'][] = getlocal2("install.1.connected", array($ver['c']));
 | 
								$page['done'][] = getlocal2("install.1.connected", array($ver['c']));
 | 
				
			||||||
			mysql_free_result($result);
 | 
								mysql_free_result($result);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			$errors[] = "Version of your SQL server is unknown. Please check. Error: ".mysql_error();
 | 
								$errors[] = "Version of your SQL server is unknown. Please check. Error: " . mysql_error();
 | 
				
			||||||
			mysql_close($link);
 | 
								mysql_close($link);
 | 
				
			||||||
			return null;
 | 
								return null;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -72,11 +74,12 @@ function check_connection() {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function check_database($link) {
 | 
					function check_database($link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqldb, $force_charset_in_connection, $dbencoding, $page, $webimroot;
 | 
						global $mysqldb, $force_charset_in_connection, $dbencoding, $page, $webimroot;
 | 
				
			||||||
	if(mysql_select_db($mysqldb,$link)) {
 | 
						if (mysql_select_db($mysqldb, $link)) {
 | 
				
			||||||
		$page['done'][] = getlocal2("install.2.db_exists", array($mysqldb));
 | 
							$page['done'][] = getlocal2("install.2.db_exists", array($mysqldb));
 | 
				
			||||||
		if( $force_charset_in_connection ) {
 | 
							if ($force_charset_in_connection) {
 | 
				
			||||||
			mysql_query("SET character set $dbencoding", $link);
 | 
								mysql_query("SET character set $dbencoding", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
@ -88,12 +91,13 @@ function check_database($link) {
 | 
				
			|||||||
	return false;
 | 
						return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function check_tables($link) {
 | 
					function check_tables($link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $dbtables, $page, $webimroot;
 | 
						global $dbtables, $page, $webimroot;
 | 
				
			||||||
	$curr_tables = get_tables($link);
 | 
						$curr_tables = get_tables($link);
 | 
				
			||||||
	if( $curr_tables !== false) {
 | 
						if ($curr_tables !== false) {
 | 
				
			||||||
		$tocreate = array_diff(array_keys($dbtables), $curr_tables);
 | 
							$tocreate = array_diff(array_keys($dbtables), $curr_tables);
 | 
				
			||||||
		if( count($tocreate) == 0 ) {
 | 
							if (count($tocreate) == 0) {
 | 
				
			||||||
			$page['done'][] = getlocal("install.3.tables_exist");
 | 
								$page['done'][] = getlocal("install.3.tables_exist");
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
@ -104,19 +108,20 @@ function check_tables($link) {
 | 
				
			|||||||
	return false;
 | 
						return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function check_columns($link) {
 | 
					function check_columns($link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $dbtables, $dbtables_can_update, $errors, $page, $webimroot;
 | 
						global $dbtables, $dbtables_can_update, $errors, $page, $webimroot;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$need_to_create_columns = false;
 | 
						$need_to_create_columns = false;
 | 
				
			||||||
	foreach( $dbtables as $id => $columns) {
 | 
						foreach ($dbtables as $id => $columns) {
 | 
				
			||||||
		$curr_columns = get_columns($id, $link);
 | 
							$curr_columns = get_columns($id, $link);
 | 
				
			||||||
		if( $curr_columns === false ) {
 | 
							if ($curr_columns === false) {
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$tocreate = array_diff(array_keys($columns), $curr_columns);
 | 
							$tocreate = array_diff(array_keys($columns), $curr_columns);
 | 
				
			||||||
		if( count($tocreate) != 0 ) {
 | 
							if (count($tocreate) != 0) {
 | 
				
			||||||
			$cannot_update = array_diff($tocreate, $dbtables_can_update[$id]);
 | 
								$cannot_update = array_diff($tocreate, $dbtables_can_update[$id]);
 | 
				
			||||||
			if( count($cannot_update) != 0) {
 | 
								if (count($cannot_update) != 0) {
 | 
				
			||||||
				$errors[] = "Key columns are absent in table `$id'. Unable to continue installation.";
 | 
									$errors[] = "Key columns are absent in table `$id'. Unable to continue installation.";
 | 
				
			||||||
				$page['nextstep'] = getlocal("install.kill_tables");
 | 
									$page['nextstep'] = getlocal("install.kill_tables");
 | 
				
			||||||
				$page['nextstepurl'] = "$webimroot/install/dbperform.php?act=dt";
 | 
									$page['nextstepurl'] = "$webimroot/install/dbperform.php?act=dt";
 | 
				
			||||||
@ -127,7 +132,7 @@ function check_columns($link) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $need_to_create_columns ) {
 | 
						if ($need_to_create_columns) {
 | 
				
			||||||
		$page['nextstep'] = getlocal("install.4.create");
 | 
							$page['nextstep'] = getlocal("install.4.create");
 | 
				
			||||||
		$page['nextstepurl'] = "$webimroot/install/dbperform.php?act=addcolumns";
 | 
							$page['nextstepurl'] = "$webimroot/install/dbperform.php?act=addcolumns";
 | 
				
			||||||
		$page['nextnotice'] = getlocal("install.4.notice");
 | 
							$page['nextnotice'] = getlocal("install.4.notice");
 | 
				
			||||||
@ -138,29 +143,30 @@ function check_columns($link) {
 | 
				
			|||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function check_status() {
 | 
					function check_status()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page, $webimroot, $settings, $dbversion;
 | 
						global $page, $webimroot, $settings, $dbversion;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(!check_webimroot()) {
 | 
						if (!check_webimroot()) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$link = check_connection();
 | 
						$link = check_connection();
 | 
				
			||||||
	if(!$link) {
 | 
						if (!$link) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !check_database($link)) {
 | 
						if (!check_database($link)) {
 | 
				
			||||||
		mysql_close($link);
 | 
							mysql_close($link);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !check_tables($link)) {
 | 
						if (!check_tables($link)) {
 | 
				
			||||||
		mysql_close($link);
 | 
							mysql_close($link);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !check_columns($link)) {
 | 
						if (!check_columns($link)) {
 | 
				
			||||||
		mysql_close($link);
 | 
							mysql_close($link);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -168,7 +174,7 @@ function check_status() {
 | 
				
			|||||||
	$page['done'][] = getlocal("installed.message");
 | 
						$page['done'][] = getlocal("installed.message");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$page['nextstep'] = getlocal("installed.login_link");
 | 
						$page['nextstep'] = getlocal("installed.login_link");
 | 
				
			||||||
	$page['nextnotice'] = getlocal2("installed.notice", array($webimroot."/install/"));
 | 
						$page['nextnotice'] = getlocal2("installed.notice", array($webimroot . "/install/"));
 | 
				
			||||||
	$page['nextstepurl'] = "$webimroot/";
 | 
						$page['nextstepurl'] = "$webimroot/";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$page['show_small_login'] = true;
 | 
						$page['show_small_login'] = true;
 | 
				
			||||||
 | 
				
			|||||||
@ -15,54 +15,57 @@
 | 
				
			|||||||
	Copyright 2006 WebCheatSheet.com
 | 
						Copyright 2006 WebCheatSheet.com
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function can_show_captcha() {
 | 
					function can_show_captcha()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	return extension_loaded("gd");
 | 
						return extension_loaded("gd");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function gen_captcha() {
 | 
					function gen_captcha()
 | 
				
			||||||
	$md5_hash = md5(rand(0,9999)); 
 | 
					{
 | 
				
			||||||
 | 
						$md5_hash = md5(rand(0, 9999));
 | 
				
			||||||
	return substr($md5_hash, 15, 5);
 | 
						return substr($md5_hash, 15, 5);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function draw_captcha($security_code) { 
 | 
					function draw_captcha($security_code)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Set the image width and height 
 | 
						//Set the image width and height
 | 
				
			||||||
    $width = 100; 
 | 
						$width = 100;
 | 
				
			||||||
    $height = 25;  
 | 
						$height = 25;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Create the image resource 
 | 
						//Create the image resource
 | 
				
			||||||
    $image = ImageCreate($width, $height);  
 | 
						$image = ImageCreate($width, $height);
 | 
				
			||||||
    if(function_exists('imageantialias')) {
 | 
						if (function_exists('imageantialias')) {
 | 
				
			||||||
		imageantialias($image, true);
 | 
							imageantialias($image, true);
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //We are making three colors, white, black and gray 
 | 
						//We are making three colors, white, black and gray
 | 
				
			||||||
    $white = ImageColorAllocate($image, 255, 255, 255); 
 | 
						$white = ImageColorAllocate($image, 255, 255, 255);
 | 
				
			||||||
    $black = ImageColorAllocate($image, 15, 50, 15); 
 | 
						$black = ImageColorAllocate($image, 15, 50, 15);
 | 
				
			||||||
    $grey = ImageColorAllocate($image, 204, 204, 204); 
 | 
						$grey = ImageColorAllocate($image, 204, 204, 204);
 | 
				
			||||||
    $ellipsec = ImageColorAllocate($image, 0, 100, 60); 
 | 
						$ellipsec = ImageColorAllocate($image, 0, 100, 60);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Make the background black 
 | 
						//Make the background black
 | 
				
			||||||
    ImageFill($image, 0, 0, $black); 
 | 
						ImageFill($image, 0, 0, $black);
 | 
				
			||||||
    imagefilledellipse($image, 56,15,30,17, $ellipsec);
 | 
						imagefilledellipse($image, 56, 15, 30, 17, $ellipsec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Add randomly generated string in white to the image
 | 
						//Add randomly generated string in white to the image
 | 
				
			||||||
    ImageString($image, 5, 30, 4, $security_code, $white); 
 | 
						ImageString($image, 5, 30, 4, $security_code, $white);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Throw in some lines to make it a little bit harder for any bots to break 
 | 
						//Throw in some lines to make it a little bit harder for any bots to break
 | 
				
			||||||
    ImageRectangle($image,0,0,$width-1,$height-1,$grey); 
 | 
						ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
 | 
				
			||||||
    imageline($image, 0, $height/2+3, $width, $height/2+5, $grey); 
 | 
						imageline($image, 0, $height / 2 + 3, $width, $height / 2 + 5, $grey);
 | 
				
			||||||
    imageline($image, $width/2-14, 0, $width/2+7, $height, $grey);
 | 
						imageline($image, $width / 2 - 14, 0, $width / 2 + 7, $height, $grey);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Tell the browser what kind of file is come in 
 | 
						//Tell the browser what kind of file is come in
 | 
				
			||||||
    header("Content-Type: image/jpeg"); 
 | 
						header("Content-Type: image/jpeg");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Output the newly created image in jpeg format 
 | 
						//Output the newly created image in jpeg format
 | 
				
			||||||
    ImageJpeg($image); 
 | 
						ImageJpeg($image);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Free up resources
 | 
						//Free up resources
 | 
				
			||||||
    ImageDestroy($image); 
 | 
						ImageDestroy($image);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
@ -40,88 +40,97 @@ $kind_conn = 5;
 | 
				
			|||||||
$kind_events = 6;
 | 
					$kind_events = 6;
 | 
				
			||||||
$kind_avatar = 7;
 | 
					$kind_avatar = 7;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$kind_to_string = array( $kind_user => "user", $kind_agent => "agent", $kind_for_agent => "hidden",
 | 
					$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" );
 | 
											$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);
 | 
					{
 | 
				
			||||||
 | 
						return (time() + microtime()) . rand(0, 99999999);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function next_token() {
 | 
					function next_token()
 | 
				
			||||||
	return rand(99999,99999999);
 | 
					{
 | 
				
			||||||
 | 
						return rand(99999, 99999999);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function next_revision($link) {
 | 
					function next_revision($link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	perform_query("update ${mysqlprefix}chatrevision set id=LAST_INSERT_ID(id+1)",$link);
 | 
						perform_query("update ${mysqlprefix}chatrevision set id=LAST_INSERT_ID(id+1)", $link);
 | 
				
			||||||
	$val = mysql_insert_id($link);
 | 
						$val = mysql_insert_id($link);
 | 
				
			||||||
	return $val;
 | 
						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;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$query = sprintf(
 | 
						$query = sprintf(
 | 
				
			||||||
		"insert into ${mysqlprefix}chatmessage (threadid,ikind,tmessage,tname,agentId,dtmcreated) values (%s, %s,'%s',%s,%s,%s)",
 | 
							"insert into ${mysqlprefix}chatmessage (threadid,ikind,tmessage,tname,agentId,dtmcreated) values (%s, %s,'%s',%s,%s,%s)",
 | 
				
			||||||
			$threadid,
 | 
							$threadid,
 | 
				
			||||||
			$kind,
 | 
							$kind,
 | 
				
			||||||
			mysql_real_escape_string($message,$link),
 | 
							mysql_real_escape_string($message, $link),
 | 
				
			||||||
			$from ? "'".mysql_real_escape_string($from,$link)."'" : "null",
 | 
							$from ? "'" . mysql_real_escape_string($from, $link) . "'" : "null",
 | 
				
			||||||
			$opid ? $opid : "0",
 | 
							$opid ? $opid : "0",
 | 
				
			||||||
			$utime ? "FROM_UNIXTIME($utime)" : "CURRENT_TIMESTAMP" );
 | 
							$utime ? "FROM_UNIXTIME($utime)" : "CURRENT_TIMESTAMP");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	perform_query($query,$link);
 | 
						perform_query($query, $link);
 | 
				
			||||||
	return mysql_insert_id($link);
 | 
						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();
 | 
						$link = connect();
 | 
				
			||||||
	$id = post_message_($threadid,$kind,$message,$link,$from,null,$agentid);
 | 
						$id = post_message_($threadid, $kind, $message, $link, $from, null, $agentid);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
	return $id;
 | 
						return $id;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function prepare_html_message($text) {
 | 
					function prepare_html_message($text)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	$escaped_text = htmlspecialchars($text);
 | 
						$escaped_text = htmlspecialchars($text);
 | 
				
			||||||
	$text_w_links = preg_replace('/(http|ftp):\/\/\S*/','<a href="$0" target="_blank">$0</a>',$escaped_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);
 | 
						$multiline = str_replace("\n", "<br/>", $text_w_links);
 | 
				
			||||||
	return $multiline;
 | 
						return $multiline;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function message_to_html($msg) {
 | 
					function message_to_html($msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $kind_to_string, $kind_avatar;
 | 
						global $kind_to_string, $kind_avatar;
 | 
				
			||||||
	if( $msg['ikind'] == $kind_avatar ) return "";
 | 
						if ($msg['ikind'] == $kind_avatar) return "";
 | 
				
			||||||
	$message = "<span>".date("H:i:s",$msg['created'])."</span> ";
 | 
						$message = "<span>" . date("H:i:s", $msg['created']) . "</span> ";
 | 
				
			||||||
	$kind = $kind_to_string{$msg['ikind']};
 | 
						$kind = $kind_to_string{$msg['ikind']};
 | 
				
			||||||
	if( $msg['tname'] )
 | 
						if ($msg['tname'])
 | 
				
			||||||
		$message.= "<span class='n$kind'>".htmlspecialchars($msg['tname'])."</span>: ";
 | 
							$message .= "<span class='n$kind'>" . htmlspecialchars($msg['tname']) . "</span>: ";
 | 
				
			||||||
	$message.= "<span class='m$kind'>".prepare_html_message($msg['tmessage'])."</span><br/>";
 | 
						$message .= "<span class='m$kind'>" . prepare_html_message($msg['tmessage']) . "</span><br/>";
 | 
				
			||||||
	return $message;
 | 
						return $message;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function message_to_text($msg) {
 | 
					function message_to_text($msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $kind_user, $kind_agent, $kind_info, $kind_avatar;
 | 
						global $kind_user, $kind_agent, $kind_info, $kind_avatar;
 | 
				
			||||||
	if( $msg['ikind'] == $kind_avatar ) return "";
 | 
						if ($msg['ikind'] == $kind_avatar) return "";
 | 
				
			||||||
	$message_time = date("H:i:s ",$msg['created']);
 | 
						$message_time = date("H:i:s ", $msg['created']);
 | 
				
			||||||
	if($msg['ikind'] == $kind_user || $msg['ikind'] == $kind_agent) {
 | 
						if ($msg['ikind'] == $kind_user || $msg['ikind'] == $kind_agent) {
 | 
				
			||||||
		if( $msg['tname'] )
 | 
							if ($msg['tname'])
 | 
				
			||||||
			return $message_time.$msg['tname'].": ".$msg['tmessage']."\n";
 | 
								return $message_time . $msg['tname'] . ": " . $msg['tmessage'] . "\n";
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			return $message_time.$msg['tmessage']."\n";
 | 
								return $message_time . $msg['tmessage'] . "\n";
 | 
				
			||||||
	} else if($msg['ikind'] == $kind_info ) {
 | 
						} else if ($msg['ikind'] == $kind_info) {
 | 
				
			||||||
		return $message_time.$msg['tmessage']."\n";
 | 
							return $message_time . $msg['tmessage'] . "\n";
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		return $message_time."[".$msg['tmessage']."]\n";
 | 
							return $message_time . "[" . $msg['tmessage'] . "]\n";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_messages($threadid,$meth,$isuser,&$lastid) {
 | 
					function get_messages($threadid, $meth, $isuser, &$lastid)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $kind_for_agent, $kind_avatar, $webim_encoding, $mysqlprefix;
 | 
						global $kind_for_agent, $kind_avatar, $webim_encoding, $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$query = sprintf(
 | 
						$query = sprintf(
 | 
				
			||||||
		"select messageid,ikind,unix_timestamp(dtmcreated) as created,tname,tmessage from ${mysqlprefix}chatmessage ".
 | 
							"select messageid,ikind,unix_timestamp(dtmcreated) as created,tname,tmessage from ${mysqlprefix}chatmessage " .
 | 
				
			||||||
		"where threadid = %s and messageid > %s %s order by messageid",
 | 
							"where threadid = %s and messageid > %s %s order by messageid",
 | 
				
			||||||
		$threadid, $lastid, $isuser ? "and ikind <> $kind_for_agent" : "" );
 | 
							$threadid, $lastid, $isuser ? "and ikind <> $kind_for_agent" : "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$messages = array();
 | 
						$messages = array();
 | 
				
			||||||
	$msgs = select_multi_assoc($query, $link);
 | 
						$msgs = select_multi_assoc($query, $link);
 | 
				
			||||||
@ -130,10 +139,10 @@ function get_messages($threadid,$meth,$isuser,&$lastid) {
 | 
				
			|||||||
		if ($meth == 'xml') {
 | 
							if ($meth == 'xml') {
 | 
				
			||||||
			switch ($msg['ikind']) {
 | 
								switch ($msg['ikind']) {
 | 
				
			||||||
				case $kind_avatar:
 | 
									case $kind_avatar:
 | 
				
			||||||
					$message = "<avatar>".myiconv($webim_encoding,"utf-8",escape_with_cdata($msg['tmessage']))."</avatar>";
 | 
										$message = "<avatar>" . myiconv($webim_encoding, "utf-8", escape_with_cdata($msg['tmessage'])) . "</avatar>";
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
				default:
 | 
									default:
 | 
				
			||||||
					$message = "<message>".myiconv($webim_encoding,"utf-8",escape_with_cdata(message_to_html($msg)))."</message>\n";
 | 
										$message = "<message>" . myiconv($webim_encoding, "utf-8", escape_with_cdata(message_to_html($msg))) . "</message>\n";
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			if ($msg['ikind'] != $kind_avatar) {
 | 
								if ($msg['ikind'] != $kind_avatar) {
 | 
				
			||||||
@ -142,7 +151,7 @@ function get_messages($threadid,$meth,$isuser,&$lastid) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$messages[] = $message;
 | 
							$messages[] = $message;
 | 
				
			||||||
		if( $msg['messageid'] > $lastid ) {
 | 
							if ($msg['messageid'] > $lastid) {
 | 
				
			||||||
			$lastid = $msg['messageid'];
 | 
								$lastid = $msg['messageid'];
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -151,97 +160,102 @@ function get_messages($threadid,$meth,$isuser,&$lastid) {
 | 
				
			|||||||
	return $messages;
 | 
						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;
 | 
						global $webim_encoding, $webimroot, $connection_timeout, $settings;
 | 
				
			||||||
	$threadid = $thread['threadid'];
 | 
						$threadid = $thread['threadid'];
 | 
				
			||||||
	$istyping = abs($thread['current']-$thread[$isuser ? "lpagent" : "lpuser"]) < $connection_timeout
 | 
						$istyping = abs($thread['current'] - $thread[$isuser ? "lpagent" : "lpuser"]) < $connection_timeout
 | 
				
			||||||
				&& $thread[$isuser?"agentTyping":"userTyping"] == "1" ? "1" : "0";
 | 
									&& $thread[$isuser ? "agentTyping" : "userTyping"] == "1" ? "1" : "0";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $format == "xml" ) {
 | 
						if ($format == "xml") {
 | 
				
			||||||
		$output = get_messages($threadid,"xml",$isuser,$lastid);
 | 
							$output = get_messages($threadid, "xml", $isuser, $lastid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		start_xml_output();
 | 
							start_xml_output();
 | 
				
			||||||
		print("<thread lastid=\"$lastid\" typing=\"".$istyping."\" canpost=\"".(($isuser || $agentid != null && $agentid == $thread['agentId']) ? 1 : 0)."\">");
 | 
							print("<thread lastid=\"$lastid\" typing=\"" . $istyping . "\" canpost=\"" . (($isuser || $agentid != null && $agentid == $thread['agentId']) ? 1 : 0) . "\">");
 | 
				
			||||||
		foreach( $output as $msg ) {
 | 
							foreach ($output as $msg) {
 | 
				
			||||||
			print $msg;
 | 
								print $msg;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		print("</thread>");
 | 
							print("</thread>");
 | 
				
			||||||
	} else if( $format == "html" ) {
 | 
						} else if ($format == "html") {
 | 
				
			||||||
		loadsettings();
 | 
							loadsettings();
 | 
				
			||||||
		$output = get_messages($threadid,"html",$isuser,$lastid);
 | 
							$output = get_messages($threadid, "html", $isuser, $lastid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		start_html_output();
 | 
							start_html_output();
 | 
				
			||||||
		$url = "$webimroot/thread.php?act=refresh&thread=$threadid&token=$token&html=on&user=".($isuser?"true":"false");
 | 
							$url = "$webimroot/thread.php?act=refresh&thread=$threadid&token=$token&html=on&user=" . ($isuser ? "true" : "false");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		print(
 | 
							print(
 | 
				
			||||||
			"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">".
 | 
									"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">" .
 | 
				
			||||||
			"<html>\n<head>\n".
 | 
									"<html>\n<head>\n" .
 | 
				
			||||||
			"<link href=\"$webimroot/styles/default/chat.css\" rel=\"stylesheet\" type=\"text/css\">\n".
 | 
									"<link href=\"$webimroot/styles/default/chat.css\" rel=\"stylesheet\" type=\"text/css\">\n" .
 | 
				
			||||||
			"<meta http-equiv=\"Refresh\" content=\"".$settings['updatefrequency_oldchat']."; URL=$url&sn=11\">\n".
 | 
									"<meta http-equiv=\"Refresh\" content=\"" . $settings['updatefrequency_oldchat'] . "; URL=$url&sn=11\">\n" .
 | 
				
			||||||
			"<meta http-equiv=\"Pragma\" content=\"no-cache\">\n".
 | 
									"<meta http-equiv=\"Pragma\" content=\"no-cache\">\n" .
 | 
				
			||||||
			"<title>chat</title>\n".
 | 
									"<title>chat</title>\n" .
 | 
				
			||||||
			"</head>\n".
 | 
									"</head>\n" .
 | 
				
			||||||
			"<body bgcolor='#FFFFFF' text='#000000' link='#C28400' vlink='#C28400' alink='#C28400' onload=\"if( location.hash != '#aend' ){location.hash='#aend';}\">".
 | 
									"<body bgcolor='#FFFFFF' text='#000000' link='#C28400' vlink='#C28400' alink='#C28400' onload=\"if( location.hash != '#aend' ){location.hash='#aend';}\">" .
 | 
				
			||||||
			"<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td valign='top' class='message'>" );
 | 
									"<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td valign='top' class='message'>");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		foreach( $output as $msg ) {
 | 
							foreach ($output as $msg) {
 | 
				
			||||||
			print $msg;
 | 
								print $msg;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		print(
 | 
							print(
 | 
				
			||||||
			"</td></tr></table><a name='aend'></a>".
 | 
									"</td></tr></table><a name='aend'></a>" .
 | 
				
			||||||
			"</body></html>" );
 | 
									"</body></html>");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_user_name($username, $addr, $id) {
 | 
					function get_user_name($username, $addr, $id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings;
 | 
						global $settings;
 | 
				
			||||||
	loadsettings();
 | 
						loadsettings();
 | 
				
			||||||
	return str_replace("{addr}", $addr,
 | 
						return str_replace("{addr}", $addr,
 | 
				
			||||||
			str_replace("{id}", $id,
 | 
										   str_replace("{id}", $id,
 | 
				
			||||||
			str_replace("{name}", $username, $settings['usernamepattern'])));
 | 
													   str_replace("{name}", $username, $settings['usernamepattern'])));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function is_ajax_browser($browserid,$ver,$useragent) {
 | 
					function is_ajax_browser($browserid, $ver, $useragent)
 | 
				
			||||||
	if( $browserid == "opera" )
 | 
					{
 | 
				
			||||||
 | 
						if ($browserid == "opera")
 | 
				
			||||||
		return $ver >= 8.02;
 | 
							return $ver >= 8.02;
 | 
				
			||||||
	if( $browserid == "safari" )
 | 
						if ($browserid == "safari")
 | 
				
			||||||
		return $ver >= 125;
 | 
							return $ver >= 125;
 | 
				
			||||||
	if( $browserid == "msie" )
 | 
						if ($browserid == "msie")
 | 
				
			||||||
		return $ver >= 5.5 && !strstr($useragent, "powerpc");
 | 
							return $ver >= 5.5 && !strstr($useragent, "powerpc");
 | 
				
			||||||
	if( $browserid == "netscape" )
 | 
						if ($browserid == "netscape")
 | 
				
			||||||
		return $ver >= 7.1;
 | 
							return $ver >= 7.1;
 | 
				
			||||||
	if( $browserid == "mozilla")
 | 
						if ($browserid == "mozilla")
 | 
				
			||||||
		return $ver >= 1.4;
 | 
							return $ver >= 1.4;
 | 
				
			||||||
	if( $browserid == "firefox")
 | 
						if ($browserid == "firefox")
 | 
				
			||||||
		return $ver >= 1.0;
 | 
							return $ver >= 1.0;
 | 
				
			||||||
	if( $browserid == "chrome")
 | 
						if ($browserid == "chrome")
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return false;
 | 
						return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function is_old_browser($browserid,$ver) {
 | 
					function is_old_browser($browserid, $ver)
 | 
				
			||||||
	if( $browserid == "opera" )
 | 
					{
 | 
				
			||||||
 | 
						if ($browserid == "opera")
 | 
				
			||||||
		return $ver < 7.0;
 | 
							return $ver < 7.0;
 | 
				
			||||||
	if( $browserid == "msie" )
 | 
						if ($browserid == "msie")
 | 
				
			||||||
		return $ver < 5.0;
 | 
							return $ver < 5.0;
 | 
				
			||||||
	return false;
 | 
						return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$knownAgents = array("opera","msie","chrome","safari","firefox","netscape","mozilla");
 | 
					$knownAgents = array("opera", "msie", "chrome", "safari", "firefox", "netscape", "mozilla");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_remote_level($useragent) {
 | 
					function get_remote_level($useragent)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $knownAgents;
 | 
						global $knownAgents;
 | 
				
			||||||
	$useragent = strtolower($useragent);
 | 
						$useragent = strtolower($useragent);
 | 
				
			||||||
	foreach( $knownAgents as $agent ) {
 | 
						foreach ($knownAgents as $agent) {
 | 
				
			||||||
		if( strstr($useragent,$agent) ) {
 | 
							if (strstr($useragent, $agent)) {
 | 
				
			||||||
			if( preg_match( "/".$agent."[\\s\/]?(\\d+(\\.\\d+)?)/", $useragent, $matches ) ) {
 | 
								if (preg_match("/" . $agent . "[\\s\/]?(\\d+(\\.\\d+)?)/", $useragent, $matches)) {
 | 
				
			||||||
				$ver = $matches[1];
 | 
									$ver = $matches[1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if( is_ajax_browser($agent,$ver,$useragent) )
 | 
									if (is_ajax_browser($agent, $ver, $useragent))
 | 
				
			||||||
					return "ajaxed";
 | 
										return "ajaxed";
 | 
				
			||||||
				else if( is_old_browser($agent,$ver) )
 | 
									else if (is_old_browser($agent, $ver))
 | 
				
			||||||
					return "old";
 | 
										return "old";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				return "simple";
 | 
									return "simple";
 | 
				
			||||||
@ -251,10 +265,11 @@ function get_remote_level($useragent) {
 | 
				
			|||||||
	return "simple";
 | 
						return "simple";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function is_agent_opera95() {
 | 
					function is_agent_opera95()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
 | 
						$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
 | 
				
			||||||
	if( strstr($useragent,"opera") ) {
 | 
						if (strstr($useragent, "opera")) {
 | 
				
			||||||
		if( preg_match( "/opera[\\s\/]?(\\d+(\\.\\d+)?)/", $useragent, $matches ) ) {
 | 
							if (preg_match("/opera[\\s\/]?(\\d+(\\.\\d+)?)/", $useragent, $matches)) {
 | 
				
			||||||
			$ver = $matches[1];
 | 
								$ver = $matches[1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if ($ver >= "9.5")
 | 
								if ($ver >= "9.5")
 | 
				
			||||||
@ -264,17 +279,20 @@ function is_agent_opera95() {
 | 
				
			|||||||
	return false;
 | 
						return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function is_mac_opera() {
 | 
					function is_mac_opera()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
 | 
						$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
 | 
				
			||||||
	return strstr($useragent,"opera") && strstr($useragent, "mac");
 | 
						return strstr($useragent, "opera") && strstr($useragent, "mac");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function needsFramesrc() {
 | 
					function needsFramesrc()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
 | 
						$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
 | 
				
			||||||
	return strstr($useragent,"safari/");
 | 
						return strstr($useragent, "safari/");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function setup_logo() {
 | 
					function setup_logo()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page, $settings;
 | 
						global $page, $settings;
 | 
				
			||||||
	loadsettings();
 | 
						loadsettings();
 | 
				
			||||||
	$page['ct.company.name'] = topage($settings['title']);
 | 
						$page['ct.company.name'] = topage($settings['title']);
 | 
				
			||||||
@ -282,7 +300,8 @@ function setup_logo() {
 | 
				
			|||||||
	$page['webimHost'] = topage($settings['hosturl']);
 | 
						$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;
 | 
						global $settings, $page;
 | 
				
			||||||
	$page['formname'] = topage($name);
 | 
						$page['formname'] = topage($name);
 | 
				
			||||||
	$page['formemail'] = topage($email);
 | 
						$page['formemail'] = topage($email);
 | 
				
			||||||
@ -294,7 +313,8 @@ function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info
 | 
				
			|||||||
	$page['referrer'] = urlencode(topage($referrer));
 | 
						$page['referrer'] = urlencode(topage($referrer));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function setup_survey($name, $email, $groupid, $info, $referrer) {
 | 
					function setup_survey($name, $email, $groupid, $info, $referrer)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings, $page;
 | 
						global $settings, $page;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$page['formname'] = topage($name);
 | 
						$page['formname'] = topage($name);
 | 
				
			||||||
@ -303,25 +323,25 @@ function setup_survey($name, $email, $groupid, $info, $referrer) {
 | 
				
			|||||||
	$page['forminfo'] = topage($info);
 | 
						$page['forminfo'] = topage($info);
 | 
				
			||||||
	$page['referrer'] = urlencode(topage($referrer));
 | 
						$page['referrer'] = urlencode(topage($referrer));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if($settings['enablegroups'] == '1' && $settings["surveyaskgroup"] == "1") {
 | 
						if ($settings['enablegroups'] == '1' && $settings["surveyaskgroup"] == "1") {
 | 
				
			||||||
		$link = connect();
 | 
							$link = connect();
 | 
				
			||||||
		$allgroups = get_groups($link,false);
 | 
							$allgroups = get_groups($link, false);
 | 
				
			||||||
		mysql_close($link);
 | 
							mysql_close($link);
 | 
				
			||||||
		$val = "";
 | 
							$val = "";
 | 
				
			||||||
		foreach($allgroups as $k) {
 | 
							foreach ($allgroups as $k) {
 | 
				
			||||||
			$groupname = $k['vclocalname'];
 | 
								$groupname = $k['vclocalname'];
 | 
				
			||||||
			if($k['inumofagents'] == 0) {
 | 
								if ($k['inumofagents'] == 0) {
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if($k['ilastseen'] !== NULL && $k['ilastseen'] < $settings['online_timeout']) {
 | 
								if ($k['ilastseen'] !== NULL && $k['ilastseen'] < $settings['online_timeout']) {
 | 
				
			||||||
				if(!$groupid) {
 | 
									if (!$groupid) {
 | 
				
			||||||
					$groupid = $k['groupid'];  // select first online group
 | 
										$groupid = $k['groupid']; // select first online group
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				$groupname .= " (offline)";
 | 
									$groupname .= " (offline)";
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			$isselected = $k['groupid'] == $groupid;
 | 
								$isselected = $k['groupid'] == $groupid;
 | 
				
			||||||
			$val .= "<option value=\"".$k['groupid']."\"".($isselected ? " selected=\"selected\"" : "").">$groupname</option>";
 | 
								$val .= "<option value=\"" . $k['groupid'] . "\"" . ($isselected ? " selected=\"selected\"" : "") . ">$groupname</option>";
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$page['groups'] = $val;
 | 
							$page['groups'] = $val;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -331,7 +351,8 @@ function setup_survey($name, $email, $groupid, $info, $referrer) {
 | 
				
			|||||||
	$page['showname'] = $settings['usercanchangename'] == "1" ? "1" : "";
 | 
						$page['showname'] = $settings['usercanchangename'] == "1" ? "1" : "";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function setup_chatview_for_user($thread,$level) {
 | 
					function setup_chatview_for_user($thread, $level)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page, $webimroot, $settings;
 | 
						global $page, $webimroot, $settings;
 | 
				
			||||||
	loadsettings();
 | 
						loadsettings();
 | 
				
			||||||
	$page = array();
 | 
						$page = array();
 | 
				
			||||||
@ -349,19 +370,19 @@ function setup_chatview_for_user($thread,$level) {
 | 
				
			|||||||
	$page['chat.title'] = topage($settings['chattitle']);
 | 
						$page['chat.title'] = topage($settings['chattitle']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	setup_logo();
 | 
						setup_logo();
 | 
				
			||||||
	if($settings['sendmessagekey'] == 'enter') {
 | 
						if ($settings['sendmessagekey'] == 'enter') {
 | 
				
			||||||
		$page['send_shortcut'] = "Enter";
 | 
							$page['send_shortcut'] = "Enter";
 | 
				
			||||||
		$page['ignorectrl'] =  1;
 | 
							$page['ignorectrl'] = 1;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$page['send_shortcut'] = is_mac_opera() ? "⌘-Enter" : "Ctrl-Enter";
 | 
							$page['send_shortcut'] = is_mac_opera() ? "⌘-Enter" : "Ctrl-Enter";
 | 
				
			||||||
		$page['ignorectrl'] =  0;
 | 
							$page['ignorectrl'] = 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$params = "thread=".$thread['threadid']."&token=".$thread['ltoken'];
 | 
						$params = "thread=" . $thread['threadid'] . "&token=" . $thread['ltoken'];
 | 
				
			||||||
	$page['mailLink'] = "$webimroot/client.php?".$params."&level=$level&act=mailthread";
 | 
						$page['mailLink'] = "$webimroot/client.php?" . $params . "&level=$level&act=mailthread";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if($settings['enablessl'] == "1" && !is_secure_request()) {
 | 
						if ($settings['enablessl'] == "1" && !is_secure_request()) {
 | 
				
			||||||
		$page['sslLink'] = get_app_location(true, true)."/client.php?".$params."&level=$level";
 | 
							$page['sslLink'] = get_app_location(true, true) . "/client.php?" . $params . "&level=$level";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$page['isOpera95'] = is_agent_opera95();
 | 
						$page['isOpera95'] = is_agent_opera95();
 | 
				
			||||||
@ -370,22 +391,23 @@ function setup_chatview_for_user($thread,$level) {
 | 
				
			|||||||
	$page['frequency'] = $settings['updatefrequency_chat'];
 | 
						$page['frequency'] = $settings['updatefrequency_chat'];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function load_canned_messages($locale, $groupid) {
 | 
					function load_canned_messages($locale, $groupid)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$result = select_multi_assoc(
 | 
						$result = select_multi_assoc(
 | 
				
			||||||
			"select vcvalue from ${mysqlprefix}chatresponses where locale = '".$locale."' ".
 | 
							"select vcvalue from ${mysqlprefix}chatresponses where locale = '" . $locale . "' " .
 | 
				
			||||||
			"AND (groupid is NULL OR groupid = 0) order by vcvalue", $link);
 | 
							"AND (groupid is NULL OR groupid = 0) order by vcvalue", $link);
 | 
				
			||||||
	if(count($result) == 0) {
 | 
						if (count($result) == 0) {
 | 
				
			||||||
		foreach(explode("\n", getstring_('chat.predefined_answers', $locale)) as $answer) {
 | 
							foreach (explode("\n", getstring_('chat.predefined_answers', $locale)) as $answer) {
 | 
				
			||||||
			$result[] = array('vcvalue' => $answer);
 | 
								$result[] = array('vcvalue' => $answer);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if($groupid) {
 | 
						if ($groupid) {
 | 
				
			||||||
		$result2 = select_multi_assoc(
 | 
							$result2 = select_multi_assoc(
 | 
				
			||||||
				"select vcvalue from ${mysqlprefix}chatresponses where locale = '".$locale."' ".
 | 
								"select vcvalue from ${mysqlprefix}chatresponses where locale = '" . $locale . "' " .
 | 
				
			||||||
				"AND groupid = $groupid order by vcvalue", $link);
 | 
								"AND groupid = $groupid order by vcvalue", $link);
 | 
				
			||||||
		foreach($result as $r) {
 | 
							foreach ($result as $r) {
 | 
				
			||||||
			$result2[] = $r;
 | 
								$result2[] = $r;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$result = $result2;
 | 
							$result = $result2;
 | 
				
			||||||
@ -394,7 +416,8 @@ function load_canned_messages($locale, $groupid) {
 | 
				
			|||||||
	return $result;
 | 
						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;
 | 
						global $page, $webimroot, $company_logo_link, $company_name, $settings;
 | 
				
			||||||
	loadsettings();
 | 
						loadsettings();
 | 
				
			||||||
	$page = array();
 | 
						$page = array();
 | 
				
			||||||
@ -403,76 +426,78 @@ function setup_chatview_for_operator($thread,$operator) {
 | 
				
			|||||||
	$page['canpost'] = $thread['agentId'] == $operator['operatorid'];
 | 
						$page['canpost'] = $thread['agentId'] == $operator['operatorid'];
 | 
				
			||||||
	$page['ct.chatThreadId'] = $thread['threadid'];
 | 
						$page['ct.chatThreadId'] = $thread['threadid'];
 | 
				
			||||||
	$page['ct.token'] = $thread['ltoken'];
 | 
						$page['ct.token'] = $thread['ltoken'];
 | 
				
			||||||
	$page['ct.user.name'] = htmlspecialchars(topage(get_user_name($thread['userName'],$thread['remote'],$thread['userid'])));
 | 
						$page['ct.user.name'] = htmlspecialchars(topage(get_user_name($thread['userName'], $thread['remote'], $thread['userid'])));
 | 
				
			||||||
	$page['chat.title'] = topage($settings['chattitle']);
 | 
						$page['chat.title'] = topage($settings['chattitle']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	setup_logo();
 | 
						setup_logo();
 | 
				
			||||||
	if($settings['sendmessagekey'] == 'enter') {
 | 
						if ($settings['sendmessagekey'] == 'enter') {
 | 
				
			||||||
		$page['send_shortcut'] = "Enter";
 | 
							$page['send_shortcut'] = "Enter";
 | 
				
			||||||
		$page['ignorectrl'] =  1;
 | 
							$page['ignorectrl'] = 1;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$page['send_shortcut'] = is_mac_opera() ? "⌘-Enter" : "Ctrl-Enter";
 | 
							$page['send_shortcut'] = is_mac_opera() ? "⌘-Enter" : "Ctrl-Enter";
 | 
				
			||||||
		$page['ignorectrl'] =  0;
 | 
							$page['ignorectrl'] = 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if($settings['enablessl'] == "1" && !is_secure_request()) {
 | 
						if ($settings['enablessl'] == "1" && !is_secure_request()) {
 | 
				
			||||||
		$page['sslLink'] = get_app_location(true, true)."/operator/agent.php?thread=".$thread['threadid']."&token=".$thread['ltoken'];
 | 
							$page['sslLink'] = get_app_location(true, true) . "/operator/agent.php?thread=" . $thread['threadid'] . "&token=" . $thread['ltoken'];
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$page['isOpera95'] = is_agent_opera95();
 | 
						$page['isOpera95'] = is_agent_opera95();
 | 
				
			||||||
	$page['neediframesrc'] = needsFramesrc();
 | 
						$page['neediframesrc'] = needsFramesrc();
 | 
				
			||||||
	$page['historyParams'] = array("userid" => "".$thread['userid']);
 | 
						$page['historyParams'] = array("userid" => "" . $thread['userid']);
 | 
				
			||||||
	$page['historyParamsLink'] = add_params($webimroot."/operator/userhistory.php",$page['historyParams']);
 | 
						$page['historyParamsLink'] = add_params($webimroot . "/operator/userhistory.php", $page['historyParams']);
 | 
				
			||||||
	$predefinedres = "";
 | 
						$predefinedres = "";
 | 
				
			||||||
	$canned_messages = load_canned_messages($thread['locale'], $thread['groupid']);
 | 
						$canned_messages = load_canned_messages($thread['locale'], $thread['groupid']);
 | 
				
			||||||
	foreach($canned_messages as $answer) {
 | 
						foreach ($canned_messages as $answer) {
 | 
				
			||||||
		$predefinedres .= "<option>".htmlspecialchars(topage($answer['vcvalue']))."</option>";
 | 
							$predefinedres .= "<option>" . htmlspecialchars(topage($answer['vcvalue'])) . "</option>";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$page['predefinedAnswers'] = $predefinedres;
 | 
						$page['predefinedAnswers'] = $predefinedres;
 | 
				
			||||||
	$params = "thread=".$thread['threadid']."&token=".$thread['ltoken'];
 | 
						$params = "thread=" . $thread['threadid'] . "&token=" . $thread['ltoken'];
 | 
				
			||||||
	$page['redirectLink'] = "$webimroot/operator/agent.php?".$params."&act=redirect";
 | 
						$page['redirectLink'] = "$webimroot/operator/agent.php?" . $params . "&act=redirect";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$page['namePostfix'] = "";
 | 
						$page['namePostfix'] = "";
 | 
				
			||||||
	$page['frequency'] = $settings['updatefrequency_chat'];
 | 
						$page['frequency'] = $settings['updatefrequency_chat'];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function update_thread_access($threadid, $params, $link) {
 | 
					function update_thread_access($threadid, $params, $link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$clause = "";
 | 
						$clause = "";
 | 
				
			||||||
	foreach( $params as $k => $v ) {
 | 
						foreach ($params as $k => $v) {
 | 
				
			||||||
		if( strlen($clause) > 0 )
 | 
							if (strlen($clause) > 0)
 | 
				
			||||||
			$clause .= ", ";
 | 
								$clause .= ", ";
 | 
				
			||||||
		$clause .= $k."=".$v;
 | 
							$clause .= $k . "=" . $v;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	perform_query(
 | 
						perform_query(
 | 
				
			||||||
		 "update ${mysqlprefix}chatthread set $clause ".
 | 
							"update ${mysqlprefix}chatthread set $clause " .
 | 
				
			||||||
		 "where threadid = ".$threadid,$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;
 | 
						global $kind_for_agent, $state_queue, $state_loading, $state_chatting, $state_waiting, $kind_conn, $connection_timeout;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$params = array(($isuser ? "lastpinguser" : "lastpingagent") => "CURRENT_TIMESTAMP",
 | 
						$params = array(($isuser ? "lastpinguser" : "lastpingagent") => "CURRENT_TIMESTAMP",
 | 
				
			||||||
					($isuser ? "userTyping" : "agentTyping") => ($istyping? "1" : "0") );
 | 
										($isuser ? "userTyping" : "agentTyping") => ($istyping ? "1" : "0"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$lastping = $thread[$isuser ? "lpagent" : "lpuser"];
 | 
						$lastping = $thread[$isuser ? "lpagent" : "lpuser"];
 | 
				
			||||||
	$current = $thread['current'];
 | 
						$current = $thread['current'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $thread['istate'] == $state_loading && $isuser) {
 | 
						if ($thread['istate'] == $state_loading && $isuser) {
 | 
				
			||||||
		$params['istate'] = $state_queue;
 | 
							$params['istate'] = $state_queue;
 | 
				
			||||||
		commit_thread($thread['threadid'], $params, $link);
 | 
							commit_thread($thread['threadid'], $params, $link);
 | 
				
			||||||
		mysql_close($link);
 | 
							mysql_close($link);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 	if( $lastping > 0 && abs($current-$lastping) > $connection_timeout ) {
 | 
						if ($lastping > 0 && abs($current - $lastping) > $connection_timeout) {
 | 
				
			||||||
		$params[$isuser ? "lastpingagent" : "lastpinguser"] = "0";
 | 
							$params[$isuser ? "lastpingagent" : "lastpinguser"] = "0";
 | 
				
			||||||
		if( !$isuser ) {
 | 
							if (!$isuser) {
 | 
				
			||||||
			$message_to_post = getstring_("chat.status.user.dead", $thread['locale']);
 | 
								$message_to_post = getstring_("chat.status.user.dead", $thread['locale']);
 | 
				
			||||||
			post_message_($thread['threadid'],$kind_for_agent,$message_to_post,$link,null,$lastping+$connection_timeout);
 | 
								post_message_($thread['threadid'], $kind_for_agent, $message_to_post, $link, null, $lastping + $connection_timeout);
 | 
				
			||||||
		} else if( $thread['istate'] == $state_chatting ) {
 | 
							} else if ($thread['istate'] == $state_chatting) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$message_to_post = getstring_("chat.status.operator.dead", $thread['locale']);
 | 
								$message_to_post = getstring_("chat.status.operator.dead", $thread['locale']);
 | 
				
			||||||
			post_message_($thread['threadid'],$kind_conn,$message_to_post,$link,null,$lastping+$connection_timeout);
 | 
								post_message_($thread['threadid'], $kind_conn, $message_to_post, $link, null, $lastping + $connection_timeout);
 | 
				
			||||||
			$params['istate'] = $state_waiting;
 | 
								$params['istate'] = $state_waiting;
 | 
				
			||||||
			$params['nextagent'] = 0;
 | 
								$params['nextagent'] = 0;
 | 
				
			||||||
			commit_thread($thread['threadid'], $params, $link);
 | 
								commit_thread($thread['threadid'], $params, $link);
 | 
				
			||||||
@ -485,111 +510,120 @@ function ping_thread($thread, $isuser,$istyping) {
 | 
				
			|||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function commit_thread($threadid,$params,$link) {
 | 
					function commit_thread($threadid, $params, $link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$query = "update ${mysqlprefix}chatthread t set lrevision = ".next_revision($link).", dtmmodified = CURRENT_TIMESTAMP";
 | 
						$query = "update ${mysqlprefix}chatthread t set lrevision = " . next_revision($link) . ", dtmmodified = CURRENT_TIMESTAMP";
 | 
				
			||||||
	foreach( $params as $k => $v ) {
 | 
						foreach ($params as $k => $v) {
 | 
				
			||||||
		$query .= ", ".$k."=".$v;
 | 
							$query .= ", " . $k . "=" . $v;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$query .= " where threadid = ".$threadid;
 | 
						$query .= " where threadid = " . $threadid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	perform_query($query,$link);
 | 
						perform_query($query, $link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function rename_user($thread, $newname) {
 | 
					function rename_user($thread, $newname)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $kind_events;
 | 
						global $kind_events;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	commit_thread( $thread['threadid'], array('userName' => "'".mysql_real_escape_string($newname,$link)."'"), $link);
 | 
						commit_thread($thread['threadid'], array('userName' => "'" . mysql_real_escape_string($newname, $link) . "'"), $link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $thread['userName'] != $newname ) {
 | 
						if ($thread['userName'] != $newname) {
 | 
				
			||||||
		post_message_($thread['threadid'],$kind_events,
 | 
							post_message_($thread['threadid'], $kind_events,
 | 
				
			||||||
			getstring2_("chat.status.user.changedname",array($thread['userName'], $newname), $thread['locale']), $link);
 | 
										  getstring2_("chat.status.user.changedname", array($thread['userName'], $newname), $thread['locale']), $link);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function close_thread($thread,$isuser) {
 | 
					function close_thread($thread, $isuser)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $state_closed, $kind_events, $mysqlprefix;
 | 
						global $state_closed, $kind_events, $mysqlprefix;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	if( $thread['istate'] != $state_closed ) {
 | 
						if ($thread['istate'] != $state_closed) {
 | 
				
			||||||
		commit_thread( $thread['threadid'], array('istate' => $state_closed,
 | 
							commit_thread($thread['threadid'], array('istate' => $state_closed,
 | 
				
			||||||
			'messageCount' => "(SELECT COUNT(*) FROM ${mysqlprefix}chatmessage WHERE ${mysqlprefix}chatmessage.threadid = t.threadid AND ikind = 1)"), $link);
 | 
																	'messageCount' => "(SELECT COUNT(*) FROM ${mysqlprefix}chatmessage WHERE ${mysqlprefix}chatmessage.threadid = t.threadid AND ikind = 1)"), $link);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$message =  $isuser ? getstring2_("chat.status.user.left", array($thread['userName']), $thread['locale'])
 | 
						$message = $isuser ? getstring2_("chat.status.user.left", array($thread['userName']), $thread['locale'])
 | 
				
			||||||
					: getstring2_("chat.status.operator.left", array($thread['agentName']), $thread['locale']);
 | 
								: getstring2_("chat.status.operator.left", array($thread['agentName']), $thread['locale']);
 | 
				
			||||||
	post_message_($thread['threadid'], $kind_events, $message, $link);
 | 
						post_message_($thread['threadid'], $kind_events, $message, $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function thread_by_id_($id,$link) {
 | 
					function thread_by_id_($id, $link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	return select_one_row("select threadid,userName,agentName,agentId,lrevision,istate,ltoken,userTyping,agentTyping".
 | 
						return select_one_row("select threadid,userName,agentName,agentId,lrevision,istate,ltoken,userTyping,agentTyping" .
 | 
				
			||||||
			",unix_timestamp(dtmmodified) as modified, unix_timestamp(dtmcreated) as created".
 | 
											  ",unix_timestamp(dtmmodified) as modified, unix_timestamp(dtmcreated) as created" .
 | 
				
			||||||
			",remote,referer,locale,unix_timestamp(lastpinguser) as lpuser,unix_timestamp(lastpingagent) as lpagent, unix_timestamp(CURRENT_TIMESTAMP) as current,nextagent,shownmessageid,userid,userAgent,groupid".
 | 
											  ",remote,referer,locale,unix_timestamp(lastpinguser) as lpuser,unix_timestamp(lastpingagent) as lpagent, unix_timestamp(CURRENT_TIMESTAMP) as current,nextagent,shownmessageid,userid,userAgent,groupid" .
 | 
				
			||||||
			" from ${mysqlprefix}chatthread where threadid = ". $id, $link );
 | 
											  " from ${mysqlprefix}chatthread where threadid = " . $id, $link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function ban_for_addr_($addr,$link) {
 | 
					function ban_for_addr_($addr, $link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						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 );
 | 
						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();
 | 
						$link = connect();
 | 
				
			||||||
	$thread = thread_by_id_($id,$link);
 | 
						$thread = thread_by_id_($id, $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
	return $thread;
 | 
						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;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$query = sprintf(
 | 
						$query = sprintf(
 | 
				
			||||||
		 "insert into ${mysqlprefix}chatthread (userName,userid,ltoken,remote,referer,lrevision,locale,userAgent,dtmcreated,dtmmodified,istate".($groupid?",groupid":"").") values ".
 | 
							"insert into ${mysqlprefix}chatthread (userName,userid,ltoken,remote,referer,lrevision,locale,userAgent,dtmcreated,dtmmodified,istate" . ($groupid ? ",groupid" : "") . ") values " .
 | 
				
			||||||
								 "('%s','%s',%s,'%s','%s',%s,'%s','%s',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,$initialState".($groupid?",$groupid":"").")",
 | 
							"('%s','%s',%s,'%s','%s',%s,'%s','%s',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,$initialState" . ($groupid ? ",$groupid" : "") . ")",
 | 
				
			||||||
			mysql_real_escape_string($username, $link),
 | 
							mysql_real_escape_string($username, $link),
 | 
				
			||||||
			mysql_real_escape_string($userid, $link),
 | 
							mysql_real_escape_string($userid, $link),
 | 
				
			||||||
			next_token(),
 | 
							next_token(),
 | 
				
			||||||
			mysql_real_escape_string($remoteHost, $link),
 | 
							mysql_real_escape_string($remoteHost, $link),
 | 
				
			||||||
			mysql_real_escape_string($referer, $link),
 | 
							mysql_real_escape_string($referer, $link),
 | 
				
			||||||
			next_revision($link),
 | 
							next_revision($link),
 | 
				
			||||||
			mysql_real_escape_string($lang, $link),
 | 
							mysql_real_escape_string($lang, $link),
 | 
				
			||||||
			mysql_real_escape_string($userbrowser, $link));
 | 
							mysql_real_escape_string($userbrowser, $link));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	perform_query($query,$link);
 | 
						perform_query($query, $link);
 | 
				
			||||||
	$id = mysql_insert_id($link);
 | 
						$id = mysql_insert_id($link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$newthread = thread_by_id_($id,$link);
 | 
						$newthread = thread_by_id_($id, $link);
 | 
				
			||||||
	return $newthread;
 | 
						return $newthread;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function do_take_thread($threadid,$operatorId,$operatorName) {
 | 
					function do_take_thread($threadid, $operatorId, $operatorName)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $state_chatting;
 | 
						global $state_chatting;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	commit_thread( $threadid,
 | 
						commit_thread($threadid,
 | 
				
			||||||
		array("istate" => $state_chatting,
 | 
									  array("istate" => $state_chatting,
 | 
				
			||||||
			  "nextagent" => 0,
 | 
										   "nextagent" => 0,
 | 
				
			||||||
			  "agentId" => $operatorId,
 | 
										   "agentId" => $operatorId,
 | 
				
			||||||
			  "agentName" => "'".mysql_real_escape_string($operatorName, $link)."'"), $link);
 | 
										   "agentName" => "'" . mysql_real_escape_string($operatorName, $link) . "'"), $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						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;
 | 
					{
 | 
				
			||||||
 | 
						global $state_queue, $state_loading, $state_waiting, $state_chatting, $state_closed, $state_left, $kind_events;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$thread = thread_by_id_($threadid, $link);
 | 
						$thread = thread_by_id_($threadid, $link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !$thread )
 | 
						if (!$thread)
 | 
				
			||||||
		return FALSE;
 | 
							return FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $thread['istate'] == $state_closed || $thread['istate'] == $state_left )
 | 
						if ($thread['istate'] == $state_closed || $thread['istate'] == $state_left)
 | 
				
			||||||
		return FALSE;
 | 
							return FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $thread['istate'] != $state_chatting && $thread['istate'] != $state_queue && $thread['istate'] != $state_loading ) {
 | 
						if ($thread['istate'] != $state_chatting && $thread['istate'] != $state_queue && $thread['istate'] != $state_loading) {
 | 
				
			||||||
		commit_thread( $threadid,
 | 
							commit_thread($threadid,
 | 
				
			||||||
			array("istate" => $state_waiting, "nextagent" => 0), $link);
 | 
										  array("istate" => $state_waiting, "nextagent" => 0), $link);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	post_message_($thread['threadid'], $kind_events, getstring_("chat.status.user.reopenedthread", $thread['locale']), $link);
 | 
						post_message_($thread['threadid'], $kind_events, getstring_("chat.status.user.reopenedthread", $thread['locale']), $link);
 | 
				
			||||||
@ -597,7 +631,8 @@ function reopen_thread($threadid) {
 | 
				
			|||||||
	return $thread;
 | 
						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;
 | 
						global $state_queue, $state_loading, $state_waiting, $state_chatting, $kind_events, $kind_avatar, $home_locale;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$state = $thread['istate'];
 | 
						$state = $thread['istate'];
 | 
				
			||||||
@ -606,11 +641,11 @@ function take_thread($thread,$operator) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	$operatorName = ($thread['locale'] == $home_locale) ? $operator['vclocalename'] : $operator['vccommonname'];
 | 
						$operatorName = ($thread['locale'] == $home_locale) ? $operator['vclocalename'] : $operator['vccommonname'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $state == $state_queue || $state == $state_waiting || $state == $state_loading) {
 | 
						if ($state == $state_queue || $state == $state_waiting || $state == $state_loading) {
 | 
				
			||||||
		do_take_thread($threadid, $operator['operatorid'], $operatorName);
 | 
							do_take_thread($threadid, $operator['operatorid'], $operatorName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( $state == $state_waiting ) {
 | 
							if ($state == $state_waiting) {
 | 
				
			||||||
			if( $operatorName != $thread['agentName'] ) {
 | 
								if ($operatorName != $thread['agentName']) {
 | 
				
			||||||
				$message_to_post = getstring2_("chat.status.operator.changed", array($operatorName, $thread['agentName']), $thread['locale']);
 | 
									$message_to_post = getstring2_("chat.status.operator.changed", array($operatorName, $thread['agentName']), $thread['locale']);
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				$message_to_post = getstring2_("chat.status.operator.returned", array($operatorName), $thread['locale']);
 | 
									$message_to_post = getstring2_("chat.status.operator.returned", array($operatorName), $thread['locale']);
 | 
				
			||||||
@ -618,8 +653,8 @@ function take_thread($thread,$operator) {
 | 
				
			|||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			$message_to_post = getstring2_("chat.status.operator.joined", array($operatorName), $thread['locale']);
 | 
								$message_to_post = getstring2_("chat.status.operator.joined", array($operatorName), $thread['locale']);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else if( $state == $state_chatting ) {
 | 
						} else if ($state == $state_chatting) {
 | 
				
			||||||
		if( $operator['operatorid'] != $thread['agentId'] ) {
 | 
							if ($operator['operatorid'] != $thread['agentId']) {
 | 
				
			||||||
			do_take_thread($threadid, $operator['operatorid'], $operatorName);
 | 
								do_take_thread($threadid, $operator['operatorid'], $operatorName);
 | 
				
			||||||
			$message_to_post = getstring2_("chat.status.operator.changed", array($operatorName, $thread['agentName']), $thread['locale']);
 | 
								$message_to_post = getstring2_("chat.status.operator.changed", array($operatorName, $thread['agentName']), $thread['locale']);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -627,36 +662,38 @@ function take_thread($thread,$operator) {
 | 
				
			|||||||
		die("cannot take thread");
 | 
							die("cannot take thread");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $message_to_post ) {
 | 
						if ($message_to_post) {
 | 
				
			||||||
		post_message($threadid,$kind_events,$message_to_post);
 | 
							post_message($threadid, $kind_events, $message_to_post);
 | 
				
			||||||
		post_message($threadid,$kind_avatar,$operator['vcavatar'] ? $operator['vcavatar'] : "");
 | 
							post_message($threadid, $kind_avatar, $operator['vcavatar'] ? $operator['vcavatar'] : "");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function check_for_reassign($thread,$operator) {
 | 
					function check_for_reassign($thread, $operator)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $state_waiting, $home_locale, $kind_events, $kind_avatar;
 | 
						global $state_waiting, $home_locale, $kind_events, $kind_avatar;
 | 
				
			||||||
	$operatorName = ($thread['locale'] == $home_locale) ? $operator['vclocalename'] : $operator['vccommonname'];
 | 
						$operatorName = ($thread['locale'] == $home_locale) ? $operator['vclocalename'] : $operator['vccommonname'];
 | 
				
			||||||
	if( $thread['istate'] == $state_waiting &&
 | 
						if ($thread['istate'] == $state_waiting &&
 | 
				
			||||||
			(  $thread['nextagent'] == $operator['operatorid']
 | 
							($thread['nextagent'] == $operator['operatorid']
 | 
				
			||||||
			|| $thread['agentId'] == $operator['operatorid'] )) {
 | 
							 || $thread['agentId'] == $operator['operatorid'])) {
 | 
				
			||||||
		do_take_thread($thread['threadid'], $operator['operatorid'], $operatorName);
 | 
							do_take_thread($thread['threadid'], $operator['operatorid'], $operatorName);
 | 
				
			||||||
		if( $operatorName != $thread['agentName'] ) {
 | 
							if ($operatorName != $thread['agentName']) {
 | 
				
			||||||
			$message_to_post = getstring2_("chat.status.operator.changed", array($operatorName, $thread['agentName']), $thread['locale']);
 | 
								$message_to_post = getstring2_("chat.status.operator.changed", array($operatorName, $thread['agentName']), $thread['locale']);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			$message_to_post = getstring2_("chat.status.operator.returned", array($operatorName), $thread['locale']);
 | 
								$message_to_post = getstring2_("chat.status.operator.returned", array($operatorName), $thread['locale']);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		post_message($thread['threadid'],$kind_events,$message_to_post);
 | 
							post_message($thread['threadid'], $kind_events, $message_to_post);
 | 
				
			||||||
		post_message($thread['threadid'],$kind_avatar,$operator['vcavatar'] ? $operator['vcavatar'] : "");
 | 
							post_message($thread['threadid'], $kind_avatar, $operator['vcavatar'] ? $operator['vcavatar'] : "");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function notify_operators($thread,$firstmessage,$link) {
 | 
					function notify_operators($thread, $firstmessage, $link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings, $mysqlprefix;
 | 
						global $settings, $mysqlprefix;
 | 
				
			||||||
	if($settings['enablejabber'] == 1) {
 | 
						if ($settings['enablejabber'] == 1) {
 | 
				
			||||||
		$groupid = $thread['groupid'];
 | 
							$groupid = $thread['groupid'];
 | 
				
			||||||
		$query = "select ${mysqlprefix}chatoperator.operatorid as opid, inotify, vcjabbername, vcemail, (unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time from ${mysqlprefix}chatoperator";
 | 
							$query = "select ${mysqlprefix}chatoperator.operatorid as opid, inotify, vcjabbername, vcemail, (unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time from ${mysqlprefix}chatoperator";
 | 
				
			||||||
		if($groupid) {
 | 
							if ($groupid) {
 | 
				
			||||||
			$query .= ", ${mysqlprefix}chatgroupoperator where groupid = $groupid and ${mysqlprefix}chatoperator.operatorid = ${mysqlprefix}chatgroupoperator.operatorid and istatus = 0";
 | 
								$query .= ", ${mysqlprefix}chatgroupoperator where groupid = $groupid and ${mysqlprefix}chatoperator.operatorid = ${mysqlprefix}chatgroupoperator.operatorid and istatus = 0";
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			$query .= " where istatus = 0";
 | 
								$query .= " where istatus = 0";
 | 
				
			||||||
@ -664,46 +701,48 @@ function notify_operators($thread,$firstmessage,$link) {
 | 
				
			|||||||
		$query .= " and inotify = 1";
 | 
							$query .= " and inotify = 1";
 | 
				
			||||||
		$result = select_multi_assoc($query, $link);
 | 
							$result = select_multi_assoc($query, $link);
 | 
				
			||||||
		$text = getstring2_("notify.new.text", array(
 | 
							$text = getstring2_("notify.new.text", array(
 | 
				
			||||||
			get_app_location(true, $settings['enablessl'] == '1' && $settings['forcessl'] == '1')."/operator/agent.php?thread=".$thread['threadid'],
 | 
																		get_app_location(true, $settings['enablessl'] == '1' && $settings['forcessl'] == '1') . "/operator/agent.php?thread=" . $thread['threadid'],
 | 
				
			||||||
			$thread['userName']
 | 
																		$thread['userName']
 | 
				
			||||||
		), $thread['locale']);
 | 
																   ), $thread['locale']);
 | 
				
			||||||
		if($firstmessage) {
 | 
							if ($firstmessage) {
 | 
				
			||||||
			$text .= "\n$firstmessage";
 | 
								$text .= "\n$firstmessage";
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		foreach($result as $op) {
 | 
							foreach ($result as $op) {
 | 
				
			||||||
			if($op['time'] < $settings['online_timeout'] && is_valid_email($op['vcjabbername'])) {
 | 
								if ($op['time'] < $settings['online_timeout'] && is_valid_email($op['vcjabbername'])) {
 | 
				
			||||||
				webim_xmpp($op['vcjabbername'], getstring2("notify.new.subject", array($thread['userName'])), $text, $link);
 | 
									webim_xmpp($op['vcjabbername'], getstring2("notify.new.subject", array($thread['userName'])), $text, $link);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function check_connections_from_remote($remote,$link) {
 | 
					function check_connections_from_remote($remote, $link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings, $state_closed, $state_left, $mysqlprefix;
 | 
						global $settings, $state_closed, $state_left, $mysqlprefix;
 | 
				
			||||||
	if($settings['max_connections_from_one_host'] == 0) {
 | 
						if ($settings['max_connections_from_one_host'] == 0) {
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$result = select_one_row(
 | 
						$result = select_one_row(
 | 
				
			||||||
			"select count(*) as opened from ${mysqlprefix}chatthread ".
 | 
							"select count(*) as opened from ${mysqlprefix}chatthread " .
 | 
				
			||||||
			"where remote = '". mysql_real_escape_string($remote, $link)."' AND istate <> $state_closed AND istate <> $state_left", $link );
 | 
							"where remote = '" . mysql_real_escape_string($remote, $link) . "' AND istate <> $state_closed AND istate <> $state_left", $link);
 | 
				
			||||||
	if($result && isset($result['opened'])) {
 | 
						if ($result && isset($result['opened'])) {
 | 
				
			||||||
		return $result['opened'] < $settings['max_connections_from_one_host'];
 | 
							return $result['opened'] < $settings['max_connections_from_one_host'];
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function visitor_from_request() {
 | 
					function visitor_from_request()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $namecookie, $webim_encoding, $usercookie;
 | 
						global $namecookie, $webim_encoding, $usercookie;
 | 
				
			||||||
	$defaultName = getstring("chat.default.username");
 | 
						$defaultName = getstring("chat.default.username");
 | 
				
			||||||
	$userName = $defaultName;
 | 
						$userName = $defaultName;
 | 
				
			||||||
	if( isset($_COOKIE[$namecookie]) ) {
 | 
						if (isset($_COOKIE[$namecookie])) {
 | 
				
			||||||
		$data = base64_decode(strtr($_COOKIE[$namecookie],'-_,', '+/='));
 | 
							$data = base64_decode(strtr($_COOKIE[$namecookie], '-_,', '+/='));
 | 
				
			||||||
		if( strlen($data) > 0 ) {
 | 
							if (strlen($data) > 0) {
 | 
				
			||||||
			$userName = myiconv("utf-8",$webim_encoding,$data);
 | 
								$userName = myiconv("utf-8", $webim_encoding, $data);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if($userName == $defaultName) {
 | 
						if ($userName == $defaultName) {
 | 
				
			||||||
		$userName = getgetparam('name', $userName);
 | 
							$userName = getgetparam('name', $userName);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -711,16 +750,17 @@ function visitor_from_request() {
 | 
				
			|||||||
		$userId = $_COOKIE[$usercookie];
 | 
							$userId = $_COOKIE[$usercookie];
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$userId = get_user_id();
 | 
							$userId = get_user_id();
 | 
				
			||||||
		setcookie($usercookie, $userId, time()+60*60*24*365);
 | 
							setcookie($usercookie, $userId, time() + 60 * 60 * 24 * 365);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return array( 'id' => $userId, 'name' => $userName );
 | 
						return array('id' => $userId, 'name' => $userName);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_remote_host() {
 | 
					function get_remote_host()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	$extAddr = $_SERVER['REMOTE_ADDR'];
 | 
						$extAddr = $_SERVER['REMOTE_ADDR'];
 | 
				
			||||||
	if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) &&
 | 
						if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) &&
 | 
				
			||||||
	          $_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR']) {
 | 
							$_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR']) {
 | 
				
			||||||
		$extAddr = $_SERVER['REMOTE_ADDR'].' ('.$_SERVER['HTTP_X_FORWARDED_FOR'].')';
 | 
							$extAddr = $_SERVER['REMOTE_ADDR'] . ' (' . $_SERVER['HTTP_X_FORWARDED_FOR'] . ')';
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr;
 | 
						return isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -21,68 +21,73 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
session_start();
 | 
					session_start();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require_once(dirname(__FILE__).'/converter.php');
 | 
					require_once(dirname(__FILE__) . '/converter.php');
 | 
				
			||||||
require_once(dirname(__FILE__).'/config.php');
 | 
					require_once(dirname(__FILE__) . '/config.php');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$version = '1.6.4';
 | 
					$version = '1.6.4';
 | 
				
			||||||
$jsver = "164";
 | 
					$jsver = "164";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function myiconv($in_enc, $out_enc, $string) {
 | 
					function myiconv($in_enc, $out_enc, $string)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $_utf8win1251, $_win1251utf8;
 | 
						global $_utf8win1251, $_win1251utf8;
 | 
				
			||||||
	if($in_enc == $out_enc ) {
 | 
						if ($in_enc == $out_enc) {
 | 
				
			||||||
		return $string;
 | 
							return $string;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if( function_exists('iconv') ) {
 | 
						if (function_exists('iconv')) {
 | 
				
			||||||
		$converted = @iconv($in_enc, $out_enc, $string);
 | 
							$converted = @iconv($in_enc, $out_enc, $string);
 | 
				
			||||||
		if( $converted !== FALSE ) {
 | 
							if ($converted !== FALSE) {
 | 
				
			||||||
			return $converted;
 | 
								return $converted;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if( $in_enc == "cp1251" && $out_enc == "utf-8" )
 | 
						if ($in_enc == "cp1251" && $out_enc == "utf-8")
 | 
				
			||||||
		return strtr($string, $_win1251utf8);
 | 
							return strtr($string, $_win1251utf8);
 | 
				
			||||||
	if( $in_enc == "utf-8" && $out_enc == "cp1251" )
 | 
						if ($in_enc == "utf-8" && $out_enc == "cp1251")
 | 
				
			||||||
		return strtr($string, $_utf8win1251);
 | 
							return strtr($string, $_utf8win1251);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return $string; // do not know how to convert
 | 
						return $string; // do not know how to convert
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function verifyparam( $name, $regexp, $default = null ) {
 | 
					function verifyparam($name, $regexp, $default = null)
 | 
				
			||||||
	if( isset( $_GET[$name] ) ) {
 | 
					{
 | 
				
			||||||
 | 
						if (isset($_GET[$name])) {
 | 
				
			||||||
		$val = $_GET[$name];
 | 
							$val = $_GET[$name];
 | 
				
			||||||
		if( preg_match( $regexp, $val ) )
 | 
							if (preg_match($regexp, $val))
 | 
				
			||||||
			return $val;
 | 
								return $val;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	} else if( isset( $_POST[$name] ) ) {
 | 
						} else if (isset($_POST[$name])) {
 | 
				
			||||||
		$val = $_POST[$name];
 | 
							$val = $_POST[$name];
 | 
				
			||||||
		if( preg_match( $regexp, $val ) )
 | 
							if (preg_match($regexp, $val))
 | 
				
			||||||
			return $val;
 | 
								return $val;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		if( isset( $default ) )
 | 
							if (isset($default))
 | 
				
			||||||
			return $default;
 | 
								return $default;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	echo "<html><head></head><body>Wrong parameter used or absent: ".$name."</body></html>";
 | 
						echo "<html><head></head><body>Wrong parameter used or absent: " . $name . "</body></html>";
 | 
				
			||||||
	exit;
 | 
						exit;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function debugexit_print( $var ) {
 | 
					function debugexit_print($var)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	echo "<html><body><pre>";
 | 
						echo "<html><body><pre>";
 | 
				
			||||||
	print_r( $var );
 | 
						print_r($var);
 | 
				
			||||||
	echo "</pre></body></html>";
 | 
						echo "</pre></body></html>";
 | 
				
			||||||
	exit;
 | 
						exit;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$locale_pattern = "/^[\w-]{2,5}$/";
 | 
					$locale_pattern = "/^[\w-]{2,5}$/";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function locale_exists($locale) {
 | 
					function locale_exists($locale)
 | 
				
			||||||
	return file_exists(dirname(__FILE__)."/../locales/$locale/properties");
 | 
					{
 | 
				
			||||||
 | 
						return file_exists(dirname(__FILE__) . "/../locales/$locale/properties");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_available_locales() {
 | 
					function get_available_locales()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $locale_pattern;
 | 
						global $locale_pattern;
 | 
				
			||||||
	$list = array();
 | 
						$list = array();
 | 
				
			||||||
	$folder = dirname(__FILE__)."/../locales";
 | 
						$folder = dirname(__FILE__) . "/../locales";
 | 
				
			||||||
	if($handle = opendir($folder)) {
 | 
						if ($handle = opendir($folder)) {
 | 
				
			||||||
		while (false !== ($file = readdir($handle))) {
 | 
							while (false !== ($file = readdir($handle))) {
 | 
				
			||||||
			if (preg_match($locale_pattern, $file) && $file != 'names' && is_dir("$folder/$file")) {
 | 
								if (preg_match($locale_pattern, $file) && $file != 'names' && is_dir("$folder/$file")) {
 | 
				
			||||||
				$list[] = $file;
 | 
									$list[] = $file;
 | 
				
			||||||
@ -94,45 +99,47 @@ function get_available_locales() {
 | 
				
			|||||||
	return $list;
 | 
						return $list;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_user_locale() {
 | 
					function get_user_locale()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $default_locale;
 | 
						global $default_locale;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( isset($_COOKIE['webim_locale']) ) {
 | 
						if (isset($_COOKIE['webim_locale'])) {
 | 
				
			||||||
		$requested_lang = $_COOKIE['webim_locale'];
 | 
							$requested_lang = $_COOKIE['webim_locale'];
 | 
				
			||||||
		if( locale_exists($requested_lang) )
 | 
							if (locale_exists($requested_lang))
 | 
				
			||||||
			return $requested_lang;
 | 
								return $requested_lang;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ) {
 | 
						if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
 | 
				
			||||||
		$requested_langs = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
 | 
							$requested_langs = explode(",", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
 | 
				
			||||||
		foreach( $requested_langs as $requested_lang) {
 | 
							foreach ($requested_langs as $requested_lang) {
 | 
				
			||||||
			if( strlen($requested_lang) > 2 )
 | 
								if (strlen($requested_lang) > 2)
 | 
				
			||||||
				$requested_lang = substr($requested_lang,0,2);
 | 
									$requested_lang = substr($requested_lang, 0, 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if( locale_exists($requested_lang) )
 | 
								if (locale_exists($requested_lang))
 | 
				
			||||||
				return $requested_lang;
 | 
									return $requested_lang;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( locale_exists($default_locale) )
 | 
						if (locale_exists($default_locale))
 | 
				
			||||||
		return $default_locale;
 | 
							return $default_locale;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 'en';
 | 
						return 'en';
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_locale() {
 | 
					function get_locale()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $webimroot, $locale_pattern;
 | 
						global $webimroot, $locale_pattern;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$locale = verifyparam("locale", $locale_pattern, "");
 | 
						$locale = verifyparam("locale", $locale_pattern, "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $locale && locale_exists($locale) ) {
 | 
						if ($locale && locale_exists($locale)) {
 | 
				
			||||||
		$_SESSION['locale'] = $locale;
 | 
							$_SESSION['locale'] = $locale;
 | 
				
			||||||
		setcookie('webim_locale', $locale, time()+60*60*24*1000, "$webimroot/");
 | 
							setcookie('webim_locale', $locale, time() + 60 * 60 * 24 * 1000, "$webimroot/");
 | 
				
			||||||
	} else if( isset($_SESSION['locale']) ){
 | 
						} else if (isset($_SESSION['locale'])) {
 | 
				
			||||||
		$locale = $_SESSION['locale'];
 | 
							$locale = $_SESSION['locale'];
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !$locale || !locale_exists($locale) )
 | 
						if (!$locale || !locale_exists($locale))
 | 
				
			||||||
		$locale = get_user_locale();
 | 
							$locale = get_user_locale();
 | 
				
			||||||
	return $locale;
 | 
						return $locale;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -141,42 +148,44 @@ $current_locale = get_locale();
 | 
				
			|||||||
$messages = array();
 | 
					$messages = array();
 | 
				
			||||||
$output_encoding = array();
 | 
					$output_encoding = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if(function_exists("date_default_timezone_set")) {
 | 
					if (function_exists("date_default_timezone_set")) {
 | 
				
			||||||
	// TODO try to get timezone from config.php/session etc.
 | 
						// TODO try to get timezone from config.php/session etc.
 | 
				
			||||||
	// autodetect timezone
 | 
						// autodetect timezone
 | 
				
			||||||
	@date_default_timezone_set(function_exists("date_default_timezone_get") ? @date_default_timezone_get() : "GMT");
 | 
						@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;
 | 
						global $current_locale;
 | 
				
			||||||
	$localeLinks = array();
 | 
						$localeLinks = array();
 | 
				
			||||||
	$allLocales = get_available_locales();
 | 
						$allLocales = get_available_locales();
 | 
				
			||||||
	if(count($allLocales) < 2) {
 | 
						if (count($allLocales) < 2) {
 | 
				
			||||||
		return null;
 | 
							return null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	foreach($allLocales as $k) {
 | 
						foreach ($allLocales as $k) {
 | 
				
			||||||
		$localeLinks[$k] = getlocal_($k, "names");
 | 
							$localeLinks[$k] = getlocal_($k, "names");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return $localeLinks;
 | 
						return $localeLinks;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function load_messages($locale) {
 | 
					function load_messages($locale)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $messages, $webim_encoding, $output_encoding;
 | 
						global $messages, $webim_encoding, $output_encoding;
 | 
				
			||||||
	$hash = array();
 | 
						$hash = array();
 | 
				
			||||||
	$current_encoding = $webim_encoding;
 | 
						$current_encoding = $webim_encoding;
 | 
				
			||||||
	$fp = fopen(dirname(__FILE__)."/../locales/$locale/properties", "r");
 | 
						$fp = fopen(dirname(__FILE__) . "/../locales/$locale/properties", "r");
 | 
				
			||||||
	while (!feof($fp)) {
 | 
						while (!feof($fp)) {
 | 
				
			||||||
		$line = fgets($fp, 4096);
 | 
							$line = fgets($fp, 4096);
 | 
				
			||||||
		$keyval = preg_split("/=/", $line, 2 );
 | 
							$keyval = preg_split("/=/", $line, 2);
 | 
				
			||||||
		if( isset($keyval[1]) ) {
 | 
							if (isset($keyval[1])) {
 | 
				
			||||||
			if($keyval[0] == 'encoding') {
 | 
								if ($keyval[0] == 'encoding') {
 | 
				
			||||||
				$current_encoding = trim($keyval[1]);
 | 
									$current_encoding = trim($keyval[1]);
 | 
				
			||||||
			} else if($keyval[0] == 'output_encoding') {
 | 
								} else if ($keyval[0] == 'output_encoding') {
 | 
				
			||||||
				$output_encoding[$locale] = trim($keyval[1]);
 | 
									$output_encoding[$locale] = trim($keyval[1]);
 | 
				
			||||||
			} else if( $current_encoding == $webim_encoding ) {
 | 
								} else if ($current_encoding == $webim_encoding) {
 | 
				
			||||||
				$hash[$keyval[0]] = str_replace("\\n", "\n",trim($keyval[1]));
 | 
									$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])));
 | 
									$hash[$keyval[0]] = myiconv($current_encoding, $webim_encoding, str_replace("\\n", "\n", trim($keyval[1])));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -184,132 +193,146 @@ function load_messages($locale) {
 | 
				
			|||||||
	$messages[$locale] = $hash;
 | 
						$messages[$locale] = $hash;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getoutputenc() {
 | 
					function getoutputenc()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $current_locale, $output_encoding, $webim_encoding, $messages;
 | 
						global $current_locale, $output_encoding, $webim_encoding, $messages;
 | 
				
			||||||
	if(!isset($messages[$current_locale]))
 | 
						if (!isset($messages[$current_locale]))
 | 
				
			||||||
		load_messages($current_locale);
 | 
							load_messages($current_locale);
 | 
				
			||||||
	return isset($output_encoding[$current_locale]) ? $output_encoding[$current_locale] : $webim_encoding;
 | 
						return isset($output_encoding[$current_locale]) ? $output_encoding[$current_locale] : $webim_encoding;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getstring_($text,$locale) {
 | 
					function getstring_($text, $locale)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $messages;
 | 
						global $messages;
 | 
				
			||||||
	if(!isset($messages[$locale]))
 | 
						if (!isset($messages[$locale]))
 | 
				
			||||||
		load_messages($locale);
 | 
							load_messages($locale);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$localized = $messages[$locale];
 | 
						$localized = $messages[$locale];
 | 
				
			||||||
	if( isset($localized[$text]) )
 | 
						if (isset($localized[$text]))
 | 
				
			||||||
		return $localized[$text];
 | 
							return $localized[$text];
 | 
				
			||||||
	if( $locale != 'en' ) {
 | 
						if ($locale != 'en') {
 | 
				
			||||||
		return getstring_($text,'en');
 | 
							return getstring_($text, 'en');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return "!".$text;
 | 
						return "!" . $text;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getstring($text) {
 | 
					function getstring($text)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $current_locale;
 | 
						global $current_locale;
 | 
				
			||||||
	return getstring_($text,$current_locale);
 | 
						return getstring_($text, $current_locale);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getlocal($text) {
 | 
					function getlocal($text)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $current_locale, $webim_encoding;
 | 
						global $current_locale, $webim_encoding;
 | 
				
			||||||
	return myiconv($webim_encoding,getoutputenc(), getstring_($text,$current_locale));
 | 
						return myiconv($webim_encoding, getoutputenc(), getstring_($text, $current_locale));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getlocal_($text,$locale) {
 | 
					function getlocal_($text, $locale)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $webim_encoding;
 | 
						global $webim_encoding;
 | 
				
			||||||
	return myiconv($webim_encoding,getoutputenc(), getstring_($text,$locale));
 | 
						return myiconv($webim_encoding, getoutputenc(), getstring_($text, $locale));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function topage($text) {
 | 
					function topage($text)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $webim_encoding;
 | 
						global $webim_encoding;
 | 
				
			||||||
	return myiconv($webim_encoding,getoutputenc(), $text);
 | 
						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 = getstring_($text, $locale);
 | 
				
			||||||
		$string = str_replace("{".$i."}", $params[$i], $string);
 | 
						for ($i = 0; $i < count($params); $i++) {
 | 
				
			||||||
 | 
							$string = str_replace("{" . $i . "}", $params[$i], $string);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return $string;
 | 
						return $string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getstring2($text,$params) {
 | 
					function getstring2($text, $params)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $current_locale;
 | 
						global $current_locale;
 | 
				
			||||||
	return getstring2_($text,$params,$current_locale);
 | 
						return getstring2_($text, $params, $current_locale);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getlocal2($text,$params) {
 | 
					function getlocal2($text, $params)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $current_locale, $webim_encoding;
 | 
						global $current_locale, $webim_encoding;
 | 
				
			||||||
	$string = myiconv($webim_encoding,getoutputenc(), getstring_($text,$current_locale));
 | 
						$string = myiconv($webim_encoding, getoutputenc(), getstring_($text, $current_locale));
 | 
				
			||||||
	for( $i = 0; $i < count($params); $i++ ) {
 | 
						for ($i = 0; $i < count($params); $i++) {
 | 
				
			||||||
		$string = str_replace("{".$i."}", $params[$i], $string);
 | 
							$string = str_replace("{" . $i . "}", $params[$i], $string);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return $string;
 | 
						return $string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* prepares for Javascript string */
 | 
					/* prepares for Javascript string */
 | 
				
			||||||
function getlocalforJS($text,$params) {
 | 
					function getlocalforJS($text, $params)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $current_locale, $webim_encoding;
 | 
						global $current_locale, $webim_encoding;
 | 
				
			||||||
	$string = myiconv($webim_encoding,getoutputenc(), getstring_($text,$current_locale));
 | 
						$string = myiconv($webim_encoding, getoutputenc(), getstring_($text, $current_locale));
 | 
				
			||||||
	$string = str_replace("\"", "\\\"", str_replace("\n", "\\n", $string));
 | 
						$string = str_replace("\"", "\\\"", str_replace("\n", "\\n", $string));
 | 
				
			||||||
	for( $i = 0; $i < count($params); $i++ ) {
 | 
						for ($i = 0; $i < count($params); $i++) {
 | 
				
			||||||
		$string = str_replace("{".$i."}", $params[$i], $string);
 | 
							$string = str_replace("{" . $i . "}", $params[$i], $string);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return $string;
 | 
						return $string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* ajax server actions use utf-8 */
 | 
					/* ajax server actions use utf-8 */
 | 
				
			||||||
function getrawparam( $name ) {
 | 
					function getrawparam($name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $webim_encoding;
 | 
						global $webim_encoding;
 | 
				
			||||||
	if( isset($_POST[$name]) ) {
 | 
						if (isset($_POST[$name])) {
 | 
				
			||||||
		$value = myiconv("utf-8",$webim_encoding,$_POST[$name]);
 | 
							$value = myiconv("utf-8", $webim_encoding, $_POST[$name]);
 | 
				
			||||||
		if (get_magic_quotes_gpc()) {
 | 
							if (get_magic_quotes_gpc()) {
 | 
				
			||||||
			$value = stripslashes($value);
 | 
								$value = stripslashes($value);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return $value;
 | 
							return $value;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	die("no ".$name." parameter");
 | 
						die("no " . $name . " parameter");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* form processors use current Output encoding */
 | 
					/* form processors use current Output encoding */
 | 
				
			||||||
function getparam( $name ) {
 | 
					function getparam($name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $webim_encoding;
 | 
						global $webim_encoding;
 | 
				
			||||||
	if( isset($_POST[$name]) ) {
 | 
						if (isset($_POST[$name])) {
 | 
				
			||||||
		$value = myiconv(getoutputenc(), $webim_encoding, $_POST[$name]);
 | 
							$value = myiconv(getoutputenc(), $webim_encoding, $_POST[$name]);
 | 
				
			||||||
		if (get_magic_quotes_gpc()) {
 | 
							if (get_magic_quotes_gpc()) {
 | 
				
			||||||
			$value = stripslashes($value);
 | 
								$value = stripslashes($value);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return $value;
 | 
							return $value;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	die("no ".$name." parameter");
 | 
						die("no " . $name . " parameter");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function unicode_urldecode($url) {
 | 
					function unicode_urldecode($url)
 | 
				
			||||||
    preg_match_all('/%u([[:alnum:]]{4})/', $url, $a);
 | 
					{
 | 
				
			||||||
 | 
						preg_match_all('/%u([[:alnum:]]{4})/', $url, $a);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    foreach ($a[1] as $uniord) {
 | 
						foreach ($a[1] as $uniord) {
 | 
				
			||||||
        $dec = hexdec($uniord);
 | 
							$dec = hexdec($uniord);
 | 
				
			||||||
        $utf = '';
 | 
							$utf = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($dec < 128) {
 | 
							if ($dec < 128) {
 | 
				
			||||||
            $utf = chr($dec);
 | 
								$utf = chr($dec);
 | 
				
			||||||
        } else if ($dec < 2048) {
 | 
							} else if ($dec < 2048) {
 | 
				
			||||||
            $utf = chr(192 + (($dec - ($dec % 64)) / 64));
 | 
								$utf = chr(192 + (($dec - ($dec % 64)) / 64));
 | 
				
			||||||
            $utf .= chr(128 + ($dec % 64));
 | 
								$utf .= chr(128 + ($dec % 64));
 | 
				
			||||||
        } else {
 | 
							} else {
 | 
				
			||||||
            $utf = chr(224 + (($dec - ($dec % 4096)) / 4096));
 | 
								$utf = chr(224 + (($dec - ($dec % 4096)) / 4096));
 | 
				
			||||||
            $utf .= chr(128 + ((($dec % 4096) - ($dec % 64)) / 64));
 | 
								$utf .= chr(128 + ((($dec % 4096) - ($dec % 64)) / 64));
 | 
				
			||||||
            $utf .= chr(128 + ($dec % 64));
 | 
								$utf .= chr(128 + ($dec % 64));
 | 
				
			||||||
        }
 | 
							}
 | 
				
			||||||
        $url = str_replace('%u'.$uniord, $utf, $url);
 | 
							$url = str_replace('%u' . $uniord, $utf, $url);
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
    return urldecode($url);
 | 
						return urldecode($url);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getgetparam($name,$default='') {
 | 
					function getgetparam($name, $default = '')
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $webim_encoding;
 | 
						global $webim_encoding;
 | 
				
			||||||
	if( !isset($_GET[$name]) || !$_GET[$name] ) {
 | 
						if (!isset($_GET[$name]) || !$_GET[$name]) {
 | 
				
			||||||
		return $default;
 | 
							return $default;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$value = myiconv("utf-8", $webim_encoding, unicode_urldecode($_GET[$name]));
 | 
						$value = myiconv("utf-8", $webim_encoding, unicode_urldecode($_GET[$name]));
 | 
				
			||||||
@ -319,36 +342,40 @@ function getgetparam($name,$default='') {
 | 
				
			|||||||
	return $value;
 | 
						return $value;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function connect() {
 | 
					function connect()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlhost, $mysqllogin, $mysqlpass, $mysqldb, $dbencoding, $force_charset_in_connection;
 | 
						global $mysqlhost, $mysqllogin, $mysqlpass, $mysqldb, $dbencoding, $force_charset_in_connection;
 | 
				
			||||||
	if(!extension_loaded("mysql")) {
 | 
						if (!extension_loaded("mysql")) {
 | 
				
			||||||
		die('Mysql extension is not loaded');
 | 
							die('Mysql extension is not loaded');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$link = @mysql_connect($mysqlhost,$mysqllogin ,$mysqlpass )
 | 
						$link = @mysql_connect($mysqlhost, $mysqllogin, $mysqlpass)
 | 
				
			||||||
		or die('Could not connect: ' . mysql_error());
 | 
								 or die('Could not connect: ' . mysql_error());
 | 
				
			||||||
	mysql_select_db($mysqldb,$link) or die('Could not select database');
 | 
						mysql_select_db($mysqldb, $link) or die('Could not select database');
 | 
				
			||||||
	if( $force_charset_in_connection ) {
 | 
						if ($force_charset_in_connection) {
 | 
				
			||||||
		mysql_query("SET NAMES '$dbencoding'", $link);
 | 
							mysql_query("SET NAMES '$dbencoding'", $link);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return $link;
 | 
						return $link;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function perform_query($query,$link) {
 | 
					function perform_query($query, $link)
 | 
				
			||||||
	mysql_query($query,$link)
 | 
					{
 | 
				
			||||||
		or die(' Query failed: '.mysql_error()/*.": ".$query*/);
 | 
						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);
 | 
						$result = mysql_query($query, $link) or die(' Query failed: ' .
 | 
				
			||||||
 | 
																	mysql_error() . ": " . $query);
 | 
				
			||||||
	$line = mysql_fetch_array($result, MYSQL_ASSOC);
 | 
						$line = mysql_fetch_array($result, MYSQL_ASSOC);
 | 
				
			||||||
	mysql_free_result($result);
 | 
						mysql_free_result($result);
 | 
				
			||||||
	return $line;
 | 
						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);
 | 
						$sqlresult = mysql_query($query, $link) or die(' Query failed: ' .
 | 
				
			||||||
 | 
																	   mysql_error() . ": " . $query);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$result = array();
 | 
						$result = array();
 | 
				
			||||||
	while ($row = mysql_fetch_array($sqlresult, MYSQL_ASSOC)) {
 | 
						while ($row = mysql_fetch_array($sqlresult, MYSQL_ASSOC)) {
 | 
				
			||||||
@ -358,21 +385,24 @@ function select_multi_assoc($query, $link) {
 | 
				
			|||||||
	return $result;
 | 
						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;
 | 
						$condition = count($conditions) > 0 ? " where " . implode(" and ", $conditions) : "";
 | 
				
			||||||
 | 
						if ($orderandgroup) $orderandgroup = " " . $orderandgroup;
 | 
				
			||||||
	return "select $fields from $table$condition$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());
 | 
						$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);
 | 
						$line = mysql_fetch_array($result, MYSQL_NUM);
 | 
				
			||||||
	mysql_free_result($result);
 | 
						mysql_free_result($result);
 | 
				
			||||||
	return $line[0];
 | 
						return $line[0];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function start_xml_output() {
 | 
					function start_xml_output()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
 | 
						header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
 | 
				
			||||||
	header("Cache-Control: no-store, no-cache, must-revalidate");
 | 
						header("Cache-Control: no-store, no-cache, must-revalidate");
 | 
				
			||||||
	header("Pragma: no-cache");
 | 
						header("Pragma: no-cache");
 | 
				
			||||||
@ -380,159 +410,182 @@ function start_xml_output() {
 | 
				
			|||||||
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
 | 
						echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function start_html_output() {
 | 
					function start_html_output()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	$charset = getstring("output_charset");
 | 
						$charset = getstring("output_charset");
 | 
				
			||||||
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
 | 
						header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
 | 
				
			||||||
	header("Cache-Control: no-store, no-cache, must-revalidate");
 | 
						header("Cache-Control: no-store, no-cache, must-revalidate");
 | 
				
			||||||
	header("Pragma: no-cache");
 | 
						header("Pragma: no-cache");
 | 
				
			||||||
	header("Content-type: text/html".(isset($charset)?"; charset=".$charset:""));
 | 
						header("Content-type: text/html" . (isset($charset) ? "; charset=" . $charset : ""));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function escape_with_cdata($text) {
 | 
					function escape_with_cdata($text)
 | 
				
			||||||
	return "<![CDATA[" . str_replace("]]>", "]]>]]><![CDATA[",$text) . "]]>";
 | 
					{
 | 
				
			||||||
 | 
						return "<![CDATA[" . str_replace("]]>", "]]>]]><![CDATA[", $text) . "]]>";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function form_value($key) {
 | 
					function form_value($key)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page;
 | 
						global $page;
 | 
				
			||||||
	if( isset($page) && isset($page["form$key"]) )
 | 
						if (isset($page) && isset($page["form$key"]))
 | 
				
			||||||
		return htmlspecialchars($page["form$key"]);
 | 
							return htmlspecialchars($page["form$key"]);
 | 
				
			||||||
	return "";
 | 
						return "";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function form_value_cb($key) {
 | 
					function form_value_cb($key)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page;
 | 
						global $page;
 | 
				
			||||||
	if( isset($page) && isset($page["form$key"]) )
 | 
						if (isset($page) && isset($page["form$key"]))
 | 
				
			||||||
		return $page["form$key"] === true;
 | 
							return $page["form$key"] === true;
 | 
				
			||||||
	return false;
 | 
						return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function form_value_mb($key,$id) {
 | 
					function form_value_mb($key, $id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page;
 | 
						global $page;
 | 
				
			||||||
	if( isset($page) && isset($page["form$key"]) && is_array($page["form$key"]) ) {
 | 
						if (isset($page) && isset($page["form$key"]) && is_array($page["form$key"])) {
 | 
				
			||||||
		return in_array($id, $page["form$key"]);
 | 
							return in_array($id, $page["form$key"]);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return false;
 | 
						return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function no_field($key) {
 | 
					function no_field($key)
 | 
				
			||||||
	return getlocal2("errors.required",array(getlocal($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",
 | 
						return getlocal2("errors.failed.uploading.file",
 | 
				
			||||||
					  array($filename, getlocal($key)));
 | 
										 array($filename, getlocal($key)));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function wrong_field($key) {
 | 
					function wrong_field($key)
 | 
				
			||||||
	return getlocal2("errors.wrong_field",array(getlocal($key)));
 | 
					{
 | 
				
			||||||
 | 
						return getlocal2("errors.wrong_field", array(getlocal($key)));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_popup($href,$jshref,$message,$title,$wndName,$options) {
 | 
					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 && window.event.preventDefault) window.event.preventDefault();this.newWindow = window.open($jshref, '$wndName', '$options');this.newWindow.focus();this.newWindow.opener=window;return false;\">$message</a>";
 | 
						if (!$jshref) {
 | 
				
			||||||
 | 
							$jshref = "'$href'";
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return "<a href=\"$href\" target=\"_blank\" " . ($title ? "title=\"$title\" " : "") . "onclick=\"if(navigator.userAgent.toLowerCase().indexOf('opera') != -1 && 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 )
 | 
					{
 | 
				
			||||||
 | 
						if ($width != 0 && $height != 0)
 | 
				
			||||||
		return "<img src=\"$href\" border=\"0\" width=\"$width\" height=\"$height\" alt=\"\"/>";
 | 
							return "<img src=\"$href\" border=\"0\" width=\"$width\" height=\"$height\" alt=\"\"/>";
 | 
				
			||||||
	return "<img src=\"$href\" border=\"0\" alt=\"\"/>";
 | 
						return "<img src=\"$href\" border=\"0\" alt=\"\"/>";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_gifimage_size($filename) {
 | 
					function get_gifimage_size($filename)
 | 
				
			||||||
	if( function_exists('gd_info')) {
 | 
					{
 | 
				
			||||||
 | 
						if (function_exists('gd_info')) {
 | 
				
			||||||
		$info = gd_info();
 | 
							$info = gd_info();
 | 
				
			||||||
		if( isset($info['GIF Read Support']) && $info['GIF Read Support'] ) {
 | 
							if (isset($info['GIF Read Support']) && $info['GIF Read Support']) {
 | 
				
			||||||
			$img = @imagecreatefromgif($filename);
 | 
								$img = @imagecreatefromgif($filename);
 | 
				
			||||||
			if($img) {
 | 
								if ($img) {
 | 
				
			||||||
				$height = imagesy($img);
 | 
									$height = imagesy($img);
 | 
				
			||||||
				$width = imagesx($img);
 | 
									$width = imagesx($img);
 | 
				
			||||||
				imagedestroy($img);
 | 
									imagedestroy($img);
 | 
				
			||||||
				return array($width,$height);
 | 
									return array($width, $height);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return array(0,0);
 | 
						return array(0, 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function add_params($servlet, $params) {
 | 
					function add_params($servlet, $params)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	$infix = '?';
 | 
						$infix = '?';
 | 
				
			||||||
	if( strstr($servlet,$infix) !== FALSE )
 | 
						if (strstr($servlet, $infix) !== FALSE)
 | 
				
			||||||
		$infix = '&';
 | 
							$infix = '&';
 | 
				
			||||||
	foreach($params as $k => $v) {
 | 
						foreach ($params as $k => $v) {
 | 
				
			||||||
		$servlet .= $infix.$k."=".$v;
 | 
							$servlet .= $infix . $k . "=" . $v;
 | 
				
			||||||
		$infix = '&';
 | 
							$infix = '&';
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return $servlet;
 | 
						return $servlet;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function div($a,$b) {
 | 
					function div($a, $b)
 | 
				
			||||||
	return ($a-($a % $b)) / $b;
 | 
					{
 | 
				
			||||||
 | 
						return ($a - ($a % $b)) / $b;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function date_diff_to_text($seconds) {
 | 
					function date_diff_to_text($seconds)
 | 
				
			||||||
	$minutes = div($seconds,60);
 | 
					{
 | 
				
			||||||
 | 
						$minutes = div($seconds, 60);
 | 
				
			||||||
	$seconds = $seconds % 60;
 | 
						$seconds = $seconds % 60;
 | 
				
			||||||
	if( $minutes < 60 ) {
 | 
						if ($minutes < 60) {
 | 
				
			||||||
		return sprintf("%02d:%02d",$minutes, $seconds);
 | 
							return sprintf("%02d:%02d", $minutes, $seconds);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$hours = div($minutes,60);
 | 
							$hours = div($minutes, 60);
 | 
				
			||||||
		$minutes = $minutes % 60;
 | 
							$minutes = $minutes % 60;
 | 
				
			||||||
		return sprintf("%02d:%02d:%02d",$hours, $minutes, $seconds);
 | 
							return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function is_valid_email($email) {
 | 
					function is_valid_email($email)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	return preg_match("/^[^@]+@[^\.]+(\.[^\.]+)*$/", $email);
 | 
						return preg_match("/^[^@]+@[^\.]+(\.[^\.]+)*$/", $email);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_app_location($showhost,$issecure) {
 | 
					function get_app_location($showhost, $issecure)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $webimroot;
 | 
						global $webimroot;
 | 
				
			||||||
	if( $showhost ) {
 | 
						if ($showhost) {
 | 
				
			||||||
		return ($issecure?"https://":"http://").$_SERVER['HTTP_HOST'].$webimroot;
 | 
							return ($issecure ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . $webimroot;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		return $webimroot;
 | 
							return $webimroot;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function is_secure_request() {
 | 
					function is_secure_request()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	return
 | 
						return
 | 
				
			||||||
		   isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443'
 | 
								isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443'
 | 
				
			||||||
		|| isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on"
 | 
								|| isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on"
 | 
				
			||||||
		|| isset($_SERVER["HTTP_HTTPS"]) && $_SERVER["HTTP_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);
 | 
						$start = getdate($fromtime);
 | 
				
			||||||
	$month = $start['mon'];
 | 
						$month = $start['mon'];
 | 
				
			||||||
	$year = $start['year'];
 | 
						$year = $start['year'];
 | 
				
			||||||
	$result = array();
 | 
						$result = array();
 | 
				
			||||||
	do {
 | 
						do {
 | 
				
			||||||
		$current = mktime(0,0,0,$month,1,$year);
 | 
							$current = mktime(0, 0, 0, $month, 1, $year);
 | 
				
			||||||
		$result[date("m.y",$current)] = strftime("%B, %Y",$current);
 | 
							$result[date("m.y", $current)] = strftime("%B, %Y", $current);
 | 
				
			||||||
		$month++;
 | 
							$month++;
 | 
				
			||||||
		if( $month > 12 ) {
 | 
							if ($month > 12) {
 | 
				
			||||||
			$month = 1;
 | 
								$month = 1;
 | 
				
			||||||
			$year++;
 | 
								$year++;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} while( $current < $totime );
 | 
						} while ($current < $totime);
 | 
				
			||||||
	return $result;
 | 
						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]);
 | 
						if (preg_match('/^(\d{2}).(\d{2})$/', $month, $matches)) {
 | 
				
			||||||
 | 
							return mktime(0, 0, 0, $matches[1], $day, $matches[2]);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function set_form_date($utime,$prefix) {
 | 
					function set_form_date($utime, $prefix)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page;
 | 
						global $page;
 | 
				
			||||||
	$page["form${prefix}day"] = date("d", $utime);
 | 
						$page["form${prefix}day"] = date("d", $utime);
 | 
				
			||||||
	$page["form${prefix}month"] = date("m.y", $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)
 | 
					{
 | 
				
			||||||
 | 
						if ($unixtime < 60 * 60 * 24 * 30)
 | 
				
			||||||
		return getlocal("time.never");
 | 
							return getlocal("time.never");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$then = getdate($unixtime);
 | 
						$then = getdate($unixtime);
 | 
				
			||||||
@ -540,13 +593,13 @@ function date_to_text($unixtime) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
 | 
						if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
 | 
				
			||||||
		$date_format = getlocal("time.today.at");
 | 
							$date_format = getlocal("time.today.at");
 | 
				
			||||||
	} else if (($then['yday']+1) == $now['yday'] && $then['year'] == $now['year']) {
 | 
						} else if (($then['yday'] + 1) == $now['yday'] && $then['year'] == $now['year']) {
 | 
				
			||||||
		$date_format = getlocal("time.yesterday.at");
 | 
							$date_format = getlocal("time.yesterday.at");
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$date_format = getlocal("time.dateformat");
 | 
							$date_format = getlocal("time.dateformat");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return strftime($date_format." ".getlocal("time.timeformat"), $unixtime);
 | 
						return strftime($date_format . " " . getlocal("time.timeformat"), $unixtime);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$dbversion = '1.6.3';
 | 
					$dbversion = '1.6.3';
 | 
				
			||||||
@ -566,26 +619,26 @@ $settings = array(
 | 
				
			|||||||
	'max_uploaded_file_size' => 100000,
 | 
						'max_uploaded_file_size' => 100000,
 | 
				
			||||||
	'max_connections_from_one_host' => 10,
 | 
						'max_connections_from_one_host' => 10,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	'email' => '',				/* inbox for left messages */
 | 
						'email' => '', /* inbox for left messages */
 | 
				
			||||||
	'left_messages_locale' => $home_locale,
 | 
						'left_messages_locale' => $home_locale,
 | 
				
			||||||
	'sendmessagekey' => 'center',
 | 
						'sendmessagekey' => 'center',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	'enableban' => '0',
 | 
						'enableban' => '0',
 | 
				
			||||||
	'enablessl' => '0',
 | 
						'enablessl' => '0',
 | 
				
			||||||
		'forcessl' => '0',
 | 
						'forcessl' => '0',
 | 
				
			||||||
	'usercanchangename' => '1',
 | 
						'usercanchangename' => '1',
 | 
				
			||||||
	'enablegroups' => '0',
 | 
						'enablegroups' => '0',
 | 
				
			||||||
	'enablestatistics' => '1',
 | 
						'enablestatistics' => '1',
 | 
				
			||||||
	'enablejabber' => '0',
 | 
						'enablejabber' => '0',
 | 
				
			||||||
	'enablepresurvey' => '1',
 | 
						'enablepresurvey' => '1',
 | 
				
			||||||
		'surveyaskmail' => '0',
 | 
						'surveyaskmail' => '0',
 | 
				
			||||||
		'surveyaskgroup' => '1',
 | 
						'surveyaskgroup' => '1',
 | 
				
			||||||
		'surveyaskmessage' => '0',
 | 
						'surveyaskmessage' => '0',
 | 
				
			||||||
	'enablepopupnotification' => '0',
 | 
						'enablepopupnotification' => '0',
 | 
				
			||||||
	'showonlineoperators' => '0',
 | 
						'showonlineoperators' => '0',
 | 
				
			||||||
	'enablecaptcha' => '0',
 | 
						'enablecaptcha' => '0',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	'online_timeout' => 30,		/* Timeout (in seconds) when online operator becomes offline */
 | 
						'online_timeout' => 30, /* Timeout (in seconds) when online operator becomes offline */
 | 
				
			||||||
	'updatefrequency_operator' => 2,
 | 
						'updatefrequency_operator' => 2,
 | 
				
			||||||
	'updatefrequency_chat' => 2,
 | 
						'updatefrequency_chat' => 2,
 | 
				
			||||||
	'updatefrequency_oldchat' => 7,
 | 
						'updatefrequency_oldchat' => 7,
 | 
				
			||||||
@ -593,14 +646,15 @@ $settings = array(
 | 
				
			|||||||
$settingsloaded = false;
 | 
					$settingsloaded = false;
 | 
				
			||||||
$settings_in_db = array();
 | 
					$settings_in_db = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function loadsettings_($link) {
 | 
					function loadsettings_($link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settingsloaded, $settings_in_db, $settings, $mysqlprefix;
 | 
						global $settingsloaded, $settings_in_db, $settings, $mysqlprefix;
 | 
				
			||||||
	if($settingsloaded) {
 | 
						if ($settingsloaded) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$settingsloaded = true;
 | 
						$settingsloaded = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$sqlresult = mysql_query("select vckey,vcvalue from ${mysqlprefix}chatconfig", $link) or die(' Query failed: '.mysql_error($link));
 | 
						$sqlresult = mysql_query("select vckey,vcvalue from ${mysqlprefix}chatconfig", $link) or die(' Query failed: ' . mysql_error($link));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while ($row = mysql_fetch_array($sqlresult, MYSQL_ASSOC)) {
 | 
						while ($row = mysql_fetch_array($sqlresult, MYSQL_ASSOC)) {
 | 
				
			||||||
		$name = $row['vckey'];
 | 
							$name = $row['vckey'];
 | 
				
			||||||
@ -610,26 +664,29 @@ function loadsettings_($link) {
 | 
				
			|||||||
	mysql_free_result($sqlresult);
 | 
						mysql_free_result($sqlresult);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function loadsettings() {
 | 
					function loadsettings()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settingsloaded;
 | 
						global $settingsloaded;
 | 
				
			||||||
	if(!$settingsloaded) {
 | 
						if (!$settingsloaded) {
 | 
				
			||||||
		$link = connect();
 | 
							$link = connect();
 | 
				
			||||||
		loadsettings_($link);
 | 
							loadsettings_($link);
 | 
				
			||||||
		mysql_close($link);
 | 
							mysql_close($link);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getchatstyle() {
 | 
					function getchatstyle()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings;
 | 
						global $settings;
 | 
				
			||||||
	$chatstyle = verifyparam( "style", "/^\w+$/", "");
 | 
						$chatstyle = verifyparam("style", "/^\w+$/", "");
 | 
				
			||||||
	if($chatstyle) {
 | 
						if ($chatstyle) {
 | 
				
			||||||
		return $chatstyle;
 | 
							return $chatstyle;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	loadsettings();
 | 
						loadsettings();
 | 
				
			||||||
	return $settings['chatstyle'];
 | 
						return $settings['chatstyle'];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function jspath() {
 | 
					function jspath()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $jsver;
 | 
						global $jsver;
 | 
				
			||||||
	return "js/$jsver";
 | 
						return "js/$jsver";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -50,7 +50,7 @@ $mail_encoding = "utf-8";
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 *  Locales
 | 
					 *  Locales
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
$home_locale = "en";                        /* native name will be used in this locale */
 | 
					$home_locale = "en"; /* native name will be used in this locale */
 | 
				
			||||||
$default_locale = "en";                     /* if user does not provide known lang */
 | 
					$default_locale = "en"; /* if user does not provide known lang */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
 | 
				
			|||||||
@ -20,36 +20,36 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$_utf8win1251 = array(
 | 
					$_utf8win1251 = array(
 | 
				
			||||||
"\xD0\x90"=>"\xC0","\xD0\x91"=>"\xC1","\xD0\x92"=>"\xC2","\xD0\x93"=>"\xC3","\xD0\x94"=>"\xC4",
 | 
						"\xD0\x90" => "\xC0", "\xD0\x91" => "\xC1", "\xD0\x92" => "\xC2", "\xD0\x93" => "\xC3", "\xD0\x94" => "\xC4",
 | 
				
			||||||
"\xD0\x95"=>"\xC5","\xD0\x81"=>"\xA8","\xD0\x96"=>"\xC6","\xD0\x97"=>"\xC7","\xD0\x98"=>"\xC8",
 | 
						"\xD0\x95" => "\xC5", "\xD0\x81" => "\xA8", "\xD0\x96" => "\xC6", "\xD0\x97" => "\xC7", "\xD0\x98" => "\xC8",
 | 
				
			||||||
"\xD0\x99"=>"\xC9","\xD0\x9A"=>"\xCA","\xD0\x9B"=>"\xCB","\xD0\x9C"=>"\xCC","\xD0\x9D"=>"\xCD",
 | 
						"\xD0\x99" => "\xC9", "\xD0\x9A" => "\xCA", "\xD0\x9B" => "\xCB", "\xD0\x9C" => "\xCC", "\xD0\x9D" => "\xCD",
 | 
				
			||||||
"\xD0\x9E"=>"\xCE","\xD0\x9F"=>"\xCF","\xD0\xA0"=>"\xD0","\xD0\xA1"=>"\xD1","\xD0\xA2"=>"\xD2",
 | 
						"\xD0\x9E" => "\xCE", "\xD0\x9F" => "\xCF", "\xD0\xA0" => "\xD0", "\xD0\xA1" => "\xD1", "\xD0\xA2" => "\xD2",
 | 
				
			||||||
"\xD0\xA3"=>"\xD3","\xD0\xA4"=>"\xD4","\xD0\xA5"=>"\xD5","\xD0\xA6"=>"\xD6","\xD0\xA7"=>"\xD7",
 | 
						"\xD0\xA3" => "\xD3", "\xD0\xA4" => "\xD4", "\xD0\xA5" => "\xD5", "\xD0\xA6" => "\xD6", "\xD0\xA7" => "\xD7",
 | 
				
			||||||
"\xD0\xA8"=>"\xD8","\xD0\xA9"=>"\xD9","\xD0\xAA"=>"\xDA","\xD0\xAB"=>"\xDB","\xD0\xAC"=>"\xDC",
 | 
						"\xD0\xA8" => "\xD8", "\xD0\xA9" => "\xD9", "\xD0\xAA" => "\xDA", "\xD0\xAB" => "\xDB", "\xD0\xAC" => "\xDC",
 | 
				
			||||||
"\xD0\xAD"=>"\xDD","\xD0\xAE"=>"\xDE","\xD0\xAF"=>"\xDF","\xD0\x87"=>"\xAF","\xD0\x86"=>"\xB2",
 | 
						"\xD0\xAD" => "\xDD", "\xD0\xAE" => "\xDE", "\xD0\xAF" => "\xDF", "\xD0\x87" => "\xAF", "\xD0\x86" => "\xB2",
 | 
				
			||||||
"\xD0\x84"=>"\xAA","\xD0\x8E"=>"\xA1","\xD0\xB0"=>"\xE0","\xD0\xB1"=>"\xE1","\xD0\xB2"=>"\xE2",
 | 
						"\xD0\x84" => "\xAA", "\xD0\x8E" => "\xA1", "\xD0\xB0" => "\xE0", "\xD0\xB1" => "\xE1", "\xD0\xB2" => "\xE2",
 | 
				
			||||||
"\xD0\xB3"=>"\xE3","\xD0\xB4"=>"\xE4","\xD0\xB5"=>"\xE5","\xD1\x91"=>"\xB8","\xD0\xB6"=>"\xE6",
 | 
						"\xD0\xB3" => "\xE3", "\xD0\xB4" => "\xE4", "\xD0\xB5" => "\xE5", "\xD1\x91" => "\xB8", "\xD0\xB6" => "\xE6",
 | 
				
			||||||
"\xD0\xB7"=>"\xE7","\xD0\xB8"=>"\xE8","\xD0\xB9"=>"\xE9","\xD0\xBA"=>"\xEA","\xD0\xBB"=>"\xEB",
 | 
						"\xD0\xB7" => "\xE7", "\xD0\xB8" => "\xE8", "\xD0\xB9" => "\xE9", "\xD0\xBA" => "\xEA", "\xD0\xBB" => "\xEB",
 | 
				
			||||||
"\xD0\xBC"=>"\xEC","\xD0\xBD"=>"\xED","\xD0\xBE"=>"\xEE","\xD0\xBF"=>"\xEF","\xD1\x80"=>"\xF0",
 | 
						"\xD0\xBC" => "\xEC", "\xD0\xBD" => "\xED", "\xD0\xBE" => "\xEE", "\xD0\xBF" => "\xEF", "\xD1\x80" => "\xF0",
 | 
				
			||||||
"\xD1\x81"=>"\xF1","\xD1\x82"=>"\xF2","\xD1\x83"=>"\xF3","\xD1\x84"=>"\xF4","\xD1\x85"=>"\xF5",
 | 
						"\xD1\x81" => "\xF1", "\xD1\x82" => "\xF2", "\xD1\x83" => "\xF3", "\xD1\x84" => "\xF4", "\xD1\x85" => "\xF5",
 | 
				
			||||||
"\xD1\x86"=>"\xF6","\xD1\x87"=>"\xF7","\xD1\x88"=>"\xF8","\xD1\x89"=>"\xF9","\xD1\x8A"=>"\xFA",
 | 
						"\xD1\x86" => "\xF6", "\xD1\x87" => "\xF7", "\xD1\x88" => "\xF8", "\xD1\x89" => "\xF9", "\xD1\x8A" => "\xFA",
 | 
				
			||||||
"\xD1\x8B"=>"\xFB","\xD1\x8C"=>"\xFC","\xD1\x8D"=>"\xFD","\xD1\x8E"=>"\xFE","\xD1\x8F"=>"\xFF",
 | 
						"\xD1\x8B" => "\xFB", "\xD1\x8C" => "\xFC", "\xD1\x8D" => "\xFD", "\xD1\x8E" => "\xFE", "\xD1\x8F" => "\xFF",
 | 
				
			||||||
"\xD1\x96"=>"\xB3","\xD1\x97"=>"\xBF","\xD1\x94"=>"\xBA","\xD1\x9E"=>"\xA2");
 | 
						"\xD1\x96" => "\xB3", "\xD1\x97" => "\xBF", "\xD1\x94" => "\xBA", "\xD1\x9E" => "\xA2");
 | 
				
			||||||
$_win1251utf8 = array(
 | 
					$_win1251utf8 = array(
 | 
				
			||||||
"\xC0"=>"\xD0\x90","\xC1"=>"\xD0\x91","\xC2"=>"\xD0\x92","\xC3"=>"\xD0\x93","\xC4"=>"\xD0\x94",
 | 
						"\xC0" => "\xD0\x90", "\xC1" => "\xD0\x91", "\xC2" => "\xD0\x92", "\xC3" => "\xD0\x93", "\xC4" => "\xD0\x94",
 | 
				
			||||||
"\xC5"=>"\xD0\x95","\xA8"=>"\xD0\x81","\xC6"=>"\xD0\x96","\xC7"=>"\xD0\x97","\xC8"=>"\xD0\x98",
 | 
						"\xC5" => "\xD0\x95", "\xA8" => "\xD0\x81", "\xC6" => "\xD0\x96", "\xC7" => "\xD0\x97", "\xC8" => "\xD0\x98",
 | 
				
			||||||
"\xC9"=>"\xD0\x99","\xCA"=>"\xD0\x9A","\xCB"=>"\xD0\x9B","\xCC"=>"\xD0\x9C","\xCD"=>"\xD0\x9D",
 | 
						"\xC9" => "\xD0\x99", "\xCA" => "\xD0\x9A", "\xCB" => "\xD0\x9B", "\xCC" => "\xD0\x9C", "\xCD" => "\xD0\x9D",
 | 
				
			||||||
"\xCE"=>"\xD0\x9E","\xCF"=>"\xD0\x9F","\xD0"=>"\xD0\xA0","\xD1"=>"\xD0\xA1","\xD2"=>"\xD0\xA2",
 | 
						"\xCE" => "\xD0\x9E", "\xCF" => "\xD0\x9F", "\xD0" => "\xD0\xA0", "\xD1" => "\xD0\xA1", "\xD2" => "\xD0\xA2",
 | 
				
			||||||
"\xD3"=>"\xD0\xA3","\xD4"=>"\xD0\xA4","\xD5"=>"\xD0\xA5","\xD6"=>"\xD0\xA6","\xD7"=>"\xD0\xA7",
 | 
						"\xD3" => "\xD0\xA3", "\xD4" => "\xD0\xA4", "\xD5" => "\xD0\xA5", "\xD6" => "\xD0\xA6", "\xD7" => "\xD0\xA7",
 | 
				
			||||||
"\xD8"=>"\xD0\xA8","\xD9"=>"\xD0\xA9","\xDA"=>"\xD0\xAA","\xDB"=>"\xD0\xAB","\xDC"=>"\xD0\xAC",
 | 
						"\xD8" => "\xD0\xA8", "\xD9" => "\xD0\xA9", "\xDA" => "\xD0\xAA", "\xDB" => "\xD0\xAB", "\xDC" => "\xD0\xAC",
 | 
				
			||||||
"\xDD"=>"\xD0\xAD","\xDE"=>"\xD0\xAE","\xDF"=>"\xD0\xAF","\xAF"=>"\xD0\x87","\xB2"=>"\xD0\x86",
 | 
						"\xDD" => "\xD0\xAD", "\xDE" => "\xD0\xAE", "\xDF" => "\xD0\xAF", "\xAF" => "\xD0\x87", "\xB2" => "\xD0\x86",
 | 
				
			||||||
"\xAA"=>"\xD0\x84","\xA1"=>"\xD0\x8E","\xE0"=>"\xD0\xB0","\xE1"=>"\xD0\xB1","\xE2"=>"\xD0\xB2",
 | 
						"\xAA" => "\xD0\x84", "\xA1" => "\xD0\x8E", "\xE0" => "\xD0\xB0", "\xE1" => "\xD0\xB1", "\xE2" => "\xD0\xB2",
 | 
				
			||||||
"\xE3"=>"\xD0\xB3","\xE4"=>"\xD0\xB4","\xE5"=>"\xD0\xB5","\xB8"=>"\xD1\x91","\xE6"=>"\xD0\xB6",
 | 
						"\xE3" => "\xD0\xB3", "\xE4" => "\xD0\xB4", "\xE5" => "\xD0\xB5", "\xB8" => "\xD1\x91", "\xE6" => "\xD0\xB6",
 | 
				
			||||||
"\xE7"=>"\xD0\xB7","\xE8"=>"\xD0\xB8","\xE9"=>"\xD0\xB9","\xEA"=>"\xD0\xBA","\xEB"=>"\xD0\xBB",
 | 
						"\xE7" => "\xD0\xB7", "\xE8" => "\xD0\xB8", "\xE9" => "\xD0\xB9", "\xEA" => "\xD0\xBA", "\xEB" => "\xD0\xBB",
 | 
				
			||||||
"\xEC"=>"\xD0\xBC","\xED"=>"\xD0\xBD","\xEE"=>"\xD0\xBE","\xEF"=>"\xD0\xBF","\xF0"=>"\xD1\x80",
 | 
						"\xEC" => "\xD0\xBC", "\xED" => "\xD0\xBD", "\xEE" => "\xD0\xBE", "\xEF" => "\xD0\xBF", "\xF0" => "\xD1\x80",
 | 
				
			||||||
"\xF1"=>"\xD1\x81","\xF2"=>"\xD1\x82","\xF3"=>"\xD1\x83","\xF4"=>"\xD1\x84","\xF5"=>"\xD1\x85",
 | 
						"\xF1" => "\xD1\x81", "\xF2" => "\xD1\x82", "\xF3" => "\xD1\x83", "\xF4" => "\xD1\x84", "\xF5" => "\xD1\x85",
 | 
				
			||||||
"\xF6"=>"\xD1\x86","\xF7"=>"\xD1\x87","\xF8"=>"\xD1\x88","\xF9"=>"\xD1\x89","\xFA"=>"\xD1\x8A",
 | 
						"\xF6" => "\xD1\x86", "\xF7" => "\xD1\x87", "\xF8" => "\xD1\x88", "\xF9" => "\xD1\x89", "\xFA" => "\xD1\x8A",
 | 
				
			||||||
"\xFB"=>"\xD1\x8B","\xFC"=>"\xD1\x8C","\xFD"=>"\xD1\x8D","\xFE"=>"\xD1\x8E","\xFF"=>"\xD1\x8F",
 | 
						"\xFB" => "\xD1\x8B", "\xFC" => "\xD1\x8C", "\xFD" => "\xD1\x8D", "\xFE" => "\xD1\x8E", "\xFF" => "\xD1\x8F",
 | 
				
			||||||
"\xB3"=>"\xD1\x96","\xBF"=>"\xD1\x97","\xBA"=>"\xD1\x94","\xA2"=>"\xD1\x9E");
 | 
						"\xB3" => "\xD1\x96", "\xBF" => "\xD1\x97", "\xBA" => "\xD1\x94", "\xA2" => "\xD1\x9E");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
@ -19,72 +19,74 @@
 | 
				
			|||||||
 *    Evgeny Gryaznov - initial API and implementation
 | 
					 *    Evgeny Gryaznov - initial API and implementation
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function demo_print_message($msg,$format) {
 | 
					function demo_print_message($msg, $format)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $webim_encoding;
 | 
						global $webim_encoding;
 | 
				
			||||||
	if($format == "xml") {
 | 
						if ($format == "xml") {
 | 
				
			||||||
		print "<message>".myiconv($webim_encoding,"utf-8",escape_with_cdata(message_to_html($msg)))."</message>\n";
 | 
							print "<message>" . myiconv($webim_encoding, "utf-8", escape_with_cdata(message_to_html($msg))) . "</message>\n";
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		print topage(message_to_html($msg));
 | 
							print topage(message_to_html($msg));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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;
 | 
						global $kind_for_agent, $kind_info, $kind_events, $kind_user, $kind_agent, $webimroot, $settings;
 | 
				
			||||||
	loadsettings();
 | 
						loadsettings();
 | 
				
			||||||
	if( $act == "refresh" || $act == "post" ) {
 | 
						if ($act == "refresh" || $act == "post") {
 | 
				
			||||||
		$lastid++;
 | 
							$lastid++;
 | 
				
			||||||
		if($outformat == "xml") {
 | 
							if ($outformat == "xml") {
 | 
				
			||||||
			start_xml_output();
 | 
								start_xml_output();
 | 
				
			||||||
			print("<thread lastid=\"$lastid\" typing=\"".($istyping ? 1 : 0)."\" canpost=\"".($canpost ? 1 : 0)."\">");
 | 
								print("<thread lastid=\"$lastid\" typing=\"" . ($istyping ? 1 : 0) . "\" canpost=\"" . ($canpost ? 1 : 0) . "\">");
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			start_html_output();
 | 
								start_html_output();
 | 
				
			||||||
			$url = "$webimroot/thread.php?act=refresh&thread=0&token=123&html=on&user=".($isuser?"true":"false");
 | 
								$url = "$webimroot/thread.php?act=refresh&thread=0&token=123&html=on&user=" . ($isuser ? "true" : "false");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			print(
 | 
								print(
 | 
				
			||||||
				"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">".
 | 
										"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">" .
 | 
				
			||||||
				"<html>\n<head>\n".
 | 
										"<html>\n<head>\n" .
 | 
				
			||||||
				"<link href=\"$webimroot/styles/default/chat.css\" rel=\"stylesheet\" type=\"text/css\">\n".
 | 
										"<link href=\"$webimroot/styles/default/chat.css\" rel=\"stylesheet\" type=\"text/css\">\n" .
 | 
				
			||||||
				"<meta http-equiv=\"Refresh\" content=\"".$settings['updatefrequency_oldchat']."; URL=$url&sn=11\">\n".
 | 
										"<meta http-equiv=\"Refresh\" content=\"" . $settings['updatefrequency_oldchat'] . "; URL=$url&sn=11\">\n" .
 | 
				
			||||||
				"<meta http-equiv=\"Pragma\" content=\"no-cache\">\n".
 | 
										"<meta http-equiv=\"Pragma\" content=\"no-cache\">\n" .
 | 
				
			||||||
				"<title>chat</title>\n".
 | 
										"<title>chat</title>\n" .
 | 
				
			||||||
				"</head>\n".
 | 
										"</head>\n" .
 | 
				
			||||||
				"<body bgcolor='#FFFFFF' text='#000000' link='#C28400' vlink='#C28400' alink='#C28400'>".
 | 
										"<body bgcolor='#FFFFFF' text='#000000' link='#C28400' vlink='#C28400' alink='#C28400'>" .
 | 
				
			||||||
				"<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td valign='top' class='message'>" );
 | 
										"<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td valign='top' class='message'>");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if($lastid == 1) {
 | 
							if ($lastid == 1) {
 | 
				
			||||||
			demo_print_message(
 | 
								demo_print_message(
 | 
				
			||||||
				array('ikind'=>$kind_for_agent,'created'=>time()-15,'tname'=>'',
 | 
									array('ikind' => $kind_for_agent, 'created' => time() - 15, 'tname' => '',
 | 
				
			||||||
					  'tmessage'=>getstring2('chat.came.from',array("http://google.com"))), $outformat);
 | 
										 'tmessage' => getstring2('chat.came.from', array("http://google.com"))), $outformat);
 | 
				
			||||||
			demo_print_message(
 | 
								demo_print_message(
 | 
				
			||||||
				array('ikind'=>$kind_info,'created'=>time()-15,'tname'=>'',
 | 
									array('ikind' => $kind_info, 'created' => time() - 15, 'tname' => '',
 | 
				
			||||||
					  'tmessage'=>getstring('chat.wait')), $outformat);
 | 
										 'tmessage' => getstring('chat.wait')), $outformat);
 | 
				
			||||||
			demo_print_message(
 | 
								demo_print_message(
 | 
				
			||||||
				array('ikind'=>$kind_events,'created'=>time()-10,'tname'=>'',
 | 
									array('ikind' => $kind_events, 'created' => time() - 10, 'tname' => '',
 | 
				
			||||||
					  'tmessage'=>getstring2("chat.status.operator.joined", array("Administrator"))), $outformat);
 | 
										 'tmessage' => getstring2("chat.status.operator.joined", array("Administrator"))), $outformat);
 | 
				
			||||||
			demo_print_message(
 | 
								demo_print_message(
 | 
				
			||||||
				array('ikind'=>$kind_agent,'created'=>time()-9,'tname'=>'Administrator',
 | 
									array('ikind' => $kind_agent, 'created' => time() - 9, 'tname' => 'Administrator',
 | 
				
			||||||
					  'tmessage'=>getstring("demo.chat.welcome")), $outformat);
 | 
										 'tmessage' => getstring("demo.chat.welcome")), $outformat);
 | 
				
			||||||
			demo_print_message(
 | 
								demo_print_message(
 | 
				
			||||||
				array('ikind'=>$kind_user,'created'=>time()-5,'tname'=>getstring("chat.default.username"),
 | 
									array('ikind' => $kind_user, 'created' => time() - 5, 'tname' => getstring("chat.default.username"),
 | 
				
			||||||
					  'tmessage'=>getstring("demo.chat.question")), $outformat);
 | 
										 'tmessage' => getstring("demo.chat.question")), $outformat);
 | 
				
			||||||
			if($canpost && $outformat == 'xml') {
 | 
								if ($canpost && $outformat == 'xml') {
 | 
				
			||||||
				demo_print_message(
 | 
									demo_print_message(
 | 
				
			||||||
					array('ikind'=>$kind_info,'created'=>time()-5,'tname'=>'',
 | 
										array('ikind' => $kind_info, 'created' => time() - 5, 'tname' => '',
 | 
				
			||||||
						  'tmessage'=>'Hint: type something in message field to see typing notification'), $outformat);
 | 
											 'tmessage' => 'Hint: type something in message field to see typing notification'), $outformat);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if($act == 'post') {
 | 
							if ($act == 'post') {
 | 
				
			||||||
			demo_print_message(
 | 
								demo_print_message(
 | 
				
			||||||
				array('ikind'=>$isuser?$kind_user:$kind_agent,'created'=>time(),'tmessage'=>$postmessage,
 | 
									array('ikind' => $isuser ? $kind_user : $kind_agent, 'created' => time(), 'tmessage' => $postmessage,
 | 
				
			||||||
					  'tname'=>$isuser?getstring("chat.default.username"):"Administrator"), $outformat);
 | 
										 'tname' => $isuser ? getstring("chat.default.username") : "Administrator"), $outformat);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if($outformat == "xml") {
 | 
							if ($outformat == "xml") {
 | 
				
			||||||
			print("</thread>");
 | 
								print("</thread>");
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			print(
 | 
								print(
 | 
				
			||||||
				"</td></tr></table><a name='aend'></a>".
 | 
										"</td></tr></table><a name='aend'></a>" .
 | 
				
			||||||
				"</body></html>" );
 | 
										"</body></html>");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -23,97 +23,103 @@ $ifregexp = "/\\\${(if|ifnot):([\w\.]+)}(.*?)(\\\${else:\\2}.*?)?\\\${endif:\\2}
 | 
				
			|||||||
$expand_include_path = "";
 | 
					$expand_include_path = "";
 | 
				
			||||||
$current_style = "";
 | 
					$current_style = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function check_condition($condition) {
 | 
					function check_condition($condition)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $errors, $page;
 | 
						global $errors, $page;
 | 
				
			||||||
	if($condition == 'errors') {
 | 
						if ($condition == 'errors') {
 | 
				
			||||||
		return isset($errors) && count($errors) > 0;
 | 
							return isset($errors) && count($errors) > 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return isset($page[$condition]) && $page[$condition];
 | 
						return isset($page[$condition]) && $page[$condition];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function expand_condition($matches) {
 | 
					function expand_condition($matches)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page, $ifregexp;
 | 
						global $page, $ifregexp;
 | 
				
			||||||
	$value = check_condition($matches[2]) ^ ($matches[1] != 'if');
 | 
						$value = check_condition($matches[2]) ^ ($matches[1] != 'if');
 | 
				
			||||||
	if($value) {
 | 
						if ($value) {
 | 
				
			||||||
		return preg_replace_callback($ifregexp, "expand_condition", $matches[3]);
 | 
							return preg_replace_callback($ifregexp, "expand_condition", $matches[3]);
 | 
				
			||||||
	} else if(isset($matches[4])) {
 | 
						} else if (isset($matches[4])) {
 | 
				
			||||||
		return preg_replace_callback($ifregexp, "expand_condition", substr($matches[4],strpos($matches[4],"}")+1));
 | 
							return preg_replace_callback($ifregexp, "expand_condition", substr($matches[4], strpos($matches[4], "}") + 1));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return "";
 | 
						return "";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function expand_var($matches) {
 | 
					function expand_var($matches)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page, $webimroot, $jsver, $errors, $current_style;
 | 
						global $page, $webimroot, $jsver, $errors, $current_style;
 | 
				
			||||||
	$prefix = $matches[1];
 | 
						$prefix = $matches[1];
 | 
				
			||||||
	$var = $matches[2];
 | 
						$var = $matches[2];
 | 
				
			||||||
	if(!$prefix) {
 | 
						if (!$prefix) {
 | 
				
			||||||
		if($var == 'webimroot') {
 | 
							if ($var == 'webimroot') {
 | 
				
			||||||
			return $webimroot;
 | 
								return $webimroot;
 | 
				
			||||||
		} else if($var == 'jsver') {
 | 
							} else if ($var == 'jsver') {
 | 
				
			||||||
			return $jsver;
 | 
								return $jsver;
 | 
				
			||||||
		} else if($var == 'tplroot') {
 | 
							} else if ($var == 'tplroot') {
 | 
				
			||||||
			return "$webimroot/styles/$current_style";
 | 
								return "$webimroot/styles/$current_style";
 | 
				
			||||||
		} else if($var == 'styleid') {
 | 
							} else if ($var == 'styleid') {
 | 
				
			||||||
			return $current_style;
 | 
								return $current_style;
 | 
				
			||||||
		} else if($var == 'pagination') {
 | 
							} else if ($var == 'pagination') {
 | 
				
			||||||
			return generate_pagination($page['pagination']);
 | 
								return generate_pagination($page['pagination']);
 | 
				
			||||||
		} else if($var == 'errors' || $var == 'harderrors') {
 | 
							} else if ($var == 'errors' || $var == 'harderrors') {
 | 
				
			||||||
			if( isset($errors) && count($errors) > 0 ) {
 | 
								if (isset($errors) && count($errors) > 0) {
 | 
				
			||||||
				$result = getlocal("$var.header");
 | 
									$result = getlocal("$var.header");
 | 
				
			||||||
				foreach( $errors as $e ) {
 | 
									foreach ($errors as $e) {
 | 
				
			||||||
					$result .= getlocal("errors.prefix").$e.getlocal("errors.suffix");
 | 
										$result .= getlocal("errors.prefix") . $e . getlocal("errors.suffix");
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				$result .= getlocal("errors.footer");
 | 
									$result .= getlocal("errors.footer");
 | 
				
			||||||
				return $result;
 | 
									return $result;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	} else if($prefix == 'msg:' || $prefix == 'url:') {
 | 
						} else if ($prefix == 'msg:' || $prefix == 'url:') {
 | 
				
			||||||
		if(strpos($var,",")!==false) {
 | 
							if (strpos($var, ",") !== false) {
 | 
				
			||||||
			$pos = strpos($var,",");
 | 
								$pos = strpos($var, ",");
 | 
				
			||||||
			$param = substr($var, $pos+1);
 | 
								$param = substr($var, $pos + 1);
 | 
				
			||||||
			$var = substr($var, 0, $pos);
 | 
								$var = substr($var, 0, $pos);
 | 
				
			||||||
			return getlocal2($var, array($page[$param]));
 | 
								return getlocal2($var, array($page[$param]));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return getlocal($var);
 | 
							return getlocal($var);
 | 
				
			||||||
	} else if($prefix == 'form:') {
 | 
						} else if ($prefix == 'form:') {
 | 
				
			||||||
		return form_value($var);
 | 
							return form_value($var);
 | 
				
			||||||
	} else if($prefix == 'page:') {
 | 
						} else if ($prefix == 'page:') {
 | 
				
			||||||
		return isset($page[$var]) ? $page[$var] : "";
 | 
							return isset($page[$var]) ? $page[$var] : "";
 | 
				
			||||||
	} else if($prefix == 'if:' || $prefix == 'else:' || $prefix == 'endif:' || $prefix == 'ifnot:') {
 | 
						} else if ($prefix == 'if:' || $prefix == 'else:' || $prefix == 'endif:' || $prefix == 'ifnot:') {
 | 
				
			||||||
		return "<!-- wrong $prefix:$var -->";
 | 
							return "<!-- wrong $prefix:$var -->";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return "";
 | 
						return "";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function expand_include($matches) {
 | 
					function expand_include($matches)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $expand_include_path;
 | 
						global $expand_include_path;
 | 
				
			||||||
	$name = $matches[1];
 | 
						$name = $matches[1];
 | 
				
			||||||
	$contents = @file_get_contents($expand_include_path.$name) or die("cannot load template");
 | 
						$contents = @file_get_contents($expand_include_path . $name) or die("cannot load template");
 | 
				
			||||||
	return $contents;
 | 
						return $contents;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function expandtext($text) {
 | 
					function expandtext($text)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $ifregexp;
 | 
						global $ifregexp;
 | 
				
			||||||
	$text = preg_replace_callback("/\\\${include:([\w\.]+)}/", "expand_include", $text);
 | 
						$text = preg_replace_callback("/\\\${include:([\w\.]+)}/", "expand_include", $text);
 | 
				
			||||||
	$text = preg_replace_callback($ifregexp, "expand_condition", $text);
 | 
						$text = preg_replace_callback($ifregexp, "expand_condition", $text);
 | 
				
			||||||
	return preg_replace_callback("/\\\${(\w+:)?([\w\.,]+)}/", "expand_var", $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;
 | 
						global $expand_include_path, $current_style;
 | 
				
			||||||
	start_html_output();
 | 
						start_html_output();
 | 
				
			||||||
	if(!is_dir("$basedir/$style")) {
 | 
						if (!is_dir("$basedir/$style")) {
 | 
				
			||||||
		$style = "default";
 | 
							$style = "default";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$expand_include_path = "$basedir/$style/templates/";
 | 
						$expand_include_path = "$basedir/$style/templates/";
 | 
				
			||||||
	$current_style = $style;
 | 
						$current_style = $style;
 | 
				
			||||||
	$contents = @file_get_contents($expand_include_path.$filename);
 | 
						$contents = @file_get_contents($expand_include_path . $filename);
 | 
				
			||||||
	if($contents === false) {
 | 
						if ($contents === false) {
 | 
				
			||||||
		$expand_include_path = "$basedir/default/templates/";
 | 
							$expand_include_path = "$basedir/default/templates/";
 | 
				
			||||||
		$current_style = "default";
 | 
							$current_style = "default";
 | 
				
			||||||
		$contents = @file_get_contents($expand_include_path.$filename) or die("cannot load template");
 | 
							$contents = @file_get_contents($expand_include_path . $filename) or die("cannot load template");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	echo expandtext($contents);
 | 
						echo expandtext($contents);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -19,34 +19,37 @@
 | 
				
			|||||||
 *    Evgeny Gryaznov - initial API and implementation
 | 
					 *    Evgeny Gryaznov - initial API and implementation
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function setup_getcode_tabs($active) {
 | 
					function setup_getcode_tabs($active)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page, $webimroot;
 | 
						global $page, $webimroot;
 | 
				
			||||||
	$page['tabselected'] = $active;
 | 
						$page['tabselected'] = $active;
 | 
				
			||||||
	$page['tabs'] = array(
 | 
						$page['tabs'] = array(
 | 
				
			||||||
		array('title'=> getlocal("page_getcode.tab.image"), 'link' => "$webimroot/operator/getcode.php"),
 | 
							array('title' => getlocal("page_getcode.tab.image"), 'link' => "$webimroot/operator/getcode.php"),
 | 
				
			||||||
		array('title'=> getlocal("page_getcode.tab.text"), 'link' => "$webimroot/operator/gettextcode.php"),
 | 
							array('title' => getlocal("page_getcode.tab.text"), 'link' => "$webimroot/operator/gettextcode.php"),
 | 
				
			||||||
	);
 | 
						);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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 = get_app_location($showhost, $forcesecure) . "/client.php";
 | 
				
			||||||
 | 
						if ($locale)
 | 
				
			||||||
		$link = append_query($link, "locale=$locale");
 | 
							$link = append_query($link, "locale=$locale");
 | 
				
			||||||
	if($style)
 | 
						if ($style)
 | 
				
			||||||
		$link = append_query($link, "style=$style");
 | 
							$link = append_query($link, "style=$style");
 | 
				
			||||||
	if($group)
 | 
						if ($group)
 | 
				
			||||||
		$link = append_query($link, "group=$group");
 | 
							$link = append_query($link, "group=$group");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$modsecfix = $modsecurity ? ".replace('http://','').replace('https://','')" : "";
 | 
						$modsecfix = $modsecurity ? ".replace('http://','').replace('https://','')" : "";
 | 
				
			||||||
	$jslink = append_query("'".$link,"url='+escape(document.location.href$modsecfix)+'&referrer='+escape(document.referrer$modsecfix)");	
 | 
						$jslink = append_query("'" . $link, "url='+escape(document.location.href$modsecfix)+'&referrer='+escape(document.referrer$modsecfix)");
 | 
				
			||||||
	$temp = get_popup($link, "$jslink",
 | 
						$temp = get_popup($link, "$jslink",
 | 
				
			||||||
			$inner, $title, "webim", "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=640,height=480,resizable=1" );
 | 
										  $inner, $title, "webim", "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=640,height=480,resizable=1");
 | 
				
			||||||
	return "<!-- mibew button -->".$temp."<!-- / mibew button -->";
 | 
						return "<!-- mibew button -->" . $temp . "<!-- / mibew button -->";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_style_list($stylesfolder) {
 | 
					function get_style_list($stylesfolder)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	$stylelist = array("" => getlocal("page.preview.style_default"));
 | 
						$stylelist = array("" => getlocal("page.preview.style_default"));
 | 
				
			||||||
	if($handle = opendir($stylesfolder)) {
 | 
						if ($handle = opendir($stylesfolder)) {
 | 
				
			||||||
		while (false !== ($file = readdir($handle))) {
 | 
							while (false !== ($file = readdir($handle))) {
 | 
				
			||||||
			if (preg_match("/^\w+$/", $file) && is_dir("$stylesfolder/$file")) {
 | 
								if (preg_match("/^\w+$/", $file) && is_dir("$stylesfolder/$file")) {
 | 
				
			||||||
				$stylelist[$file] = $file;
 | 
									$stylelist[$file] = $file;
 | 
				
			||||||
@ -57,14 +60,15 @@ function get_style_list($stylesfolder) {
 | 
				
			|||||||
	return $stylelist;
 | 
						return $stylelist;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function verifyparam_groupid($paramid) {
 | 
					function verifyparam_groupid($paramid)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings, $errors;
 | 
						global $settings, $errors;
 | 
				
			||||||
	$groupid = "";
 | 
						$groupid = "";
 | 
				
			||||||
	if($settings['enablegroups'] == '1') {
 | 
						if ($settings['enablegroups'] == '1') {
 | 
				
			||||||
		$groupid = verifyparam($paramid, "/^\d{0,8}$/", "");
 | 
							$groupid = verifyparam($paramid, "/^\d{0,8}$/", "");
 | 
				
			||||||
		if($groupid) {
 | 
							if ($groupid) {
 | 
				
			||||||
			$group = group_by_id($groupid);
 | 
								$group = group_by_id($groupid);
 | 
				
			||||||
			if(!$group) {
 | 
								if (!$group) {
 | 
				
			||||||
				$errors[] = getlocal("page.group.no_such");
 | 
									$errors[] = getlocal("page.group.no_such");
 | 
				
			||||||
				$groupid = "";
 | 
									$groupid = "";
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -73,32 +77,34 @@ function verifyparam_groupid($paramid) {
 | 
				
			|||||||
	return $groupid;
 | 
						return $groupid;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_groups_list() {
 | 
					function get_groups_list()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings;
 | 
						global $settings;
 | 
				
			||||||
	$result = array();
 | 
						$result = array();
 | 
				
			||||||
	if($settings['enablegroups'] == '1') {
 | 
						if ($settings['enablegroups'] == '1') {
 | 
				
			||||||
		$link = connect();
 | 
							$link = connect();
 | 
				
			||||||
		$allgroups = get_all_groups($link);
 | 
							$allgroups = get_all_groups($link);
 | 
				
			||||||
		mysql_close($link);
 | 
							mysql_close($link);
 | 
				
			||||||
		$result[] = array('groupid' => '', 'vclocalname' => getlocal("page.gen_button.default_group"));
 | 
							$result[] = array('groupid' => '', 'vclocalname' => getlocal("page.gen_button.default_group"));
 | 
				
			||||||
		foreach($allgroups as $g) {
 | 
							foreach ($allgroups as $g) {
 | 
				
			||||||
			$result[] = $g;
 | 
								$result[] = $g;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return $result;
 | 
						return $result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_image_locales_map($localesdir) {
 | 
					function get_image_locales_map($localesdir)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	$imageLocales = array();
 | 
						$imageLocales = array();
 | 
				
			||||||
	$allLocales = get_available_locales();
 | 
						$allLocales = get_available_locales();
 | 
				
			||||||
	foreach($allLocales as $curr) {
 | 
						foreach ($allLocales as $curr) {
 | 
				
			||||||
		$imagesDir = "$localesdir/$curr/button";
 | 
							$imagesDir = "$localesdir/$curr/button";
 | 
				
			||||||
		if($handle = @opendir($imagesDir)) {
 | 
							if ($handle = @opendir($imagesDir)) {
 | 
				
			||||||
			while (false !== ($file = readdir($handle))) {
 | 
								while (false !== ($file = readdir($handle))) {
 | 
				
			||||||
				if (preg_match("/^(\w+)_on.gif$/", $file, $matches)
 | 
									if (preg_match("/^(\w+)_on.gif$/", $file, $matches)
 | 
				
			||||||
						&& is_file("$imagesDir/".$matches[1]."_off.gif")) {
 | 
										&& is_file("$imagesDir/" . $matches[1] . "_off.gif")) {
 | 
				
			||||||
					$image = $matches[1];
 | 
										$image = $matches[1];
 | 
				
			||||||
					if( !isset($imageLocales[$image]) ) {
 | 
										if (!isset($imageLocales[$image])) {
 | 
				
			||||||
						$imageLocales[$image] = array();
 | 
											$imageLocales[$image] = array();
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					$imageLocales[$image][] = $curr;
 | 
										$imageLocales[$image][] = $curr;
 | 
				
			||||||
 | 
				
			|||||||
@ -19,26 +19,29 @@
 | 
				
			|||||||
 *    Evgeny Gryaznov - initial API and implementation
 | 
					 *    Evgeny Gryaznov - initial API and implementation
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function group_by_id($id) {
 | 
					function group_by_id($id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$group = select_one_row(
 | 
						$group = select_one_row(
 | 
				
			||||||
		 "select * from ${mysqlprefix}chatgroup where groupid = $id", $link );
 | 
							"select * from ${mysqlprefix}chatgroup where groupid = $id", $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
	return $group;
 | 
						return $group;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_group_name($group) {
 | 
					function get_group_name($group)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $home_locale, $current_locale;
 | 
						global $home_locale, $current_locale;
 | 
				
			||||||
	if( $home_locale == $current_locale || !isset($group['vccommonname']) || !$group['vccommonname'])
 | 
						if ($home_locale == $current_locale || !isset($group['vccommonname']) || !$group['vccommonname'])
 | 
				
			||||||
		return $group['vclocalname'];
 | 
							return $group['vclocalname'];
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		return $group['vccommonname'];
 | 
							return $group['vccommonname'];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function setup_group_settings_tabs($gid, $active) {
 | 
					function setup_group_settings_tabs($gid, $active)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page, $webimroot, $settings;
 | 
						global $page, $webimroot, $settings;
 | 
				
			||||||
	if($gid) {
 | 
						if ($gid) {
 | 
				
			||||||
		$page['tabs'] = array(
 | 
							$page['tabs'] = array(
 | 
				
			||||||
			getlocal("page_group.tab.main") => $active != 0 ? "$webimroot/operator/group.php?gid=$gid" : "",
 | 
								getlocal("page_group.tab.main") => $active != 0 ? "$webimroot/operator/group.php?gid=$gid" : "",
 | 
				
			||||||
			getlocal("page_group.tab.members") => $active != 1 ? "$webimroot/operator/groupmembers.php?gid=$gid" : "",
 | 
								getlocal("page_group.tab.members") => $active != 1 ? "$webimroot/operator/groupmembers.php?gid=$gid" : "",
 | 
				
			||||||
@ -48,12 +51,13 @@ function setup_group_settings_tabs($gid, $active) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_operator_groupslist($operatorid, $link) {
 | 
					function get_operator_groupslist($operatorid, $link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings, $mysqlprefix;
 | 
						global $settings, $mysqlprefix;
 | 
				
			||||||
	if($settings['enablegroups'] == '1') {
 | 
						if ($settings['enablegroups'] == '1') {
 | 
				
			||||||
		$groupids = array(0);
 | 
							$groupids = array(0);
 | 
				
			||||||
		$allgroups = select_multi_assoc("select groupid from ${mysqlprefix}chatgroupoperator where operatorid = $operatorid order by groupid",$link);
 | 
							$allgroups = select_multi_assoc("select groupid from ${mysqlprefix}chatgroupoperator where operatorid = $operatorid order by groupid", $link);
 | 
				
			||||||
		foreach($allgroups as $g) {
 | 
							foreach ($allgroups as $g) {
 | 
				
			||||||
			$groupids[] = $g['groupid'];
 | 
								$groupids[] = $g['groupid'];
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return implode(",", $groupids);
 | 
							return implode(",", $groupids);
 | 
				
			||||||
 | 
				
			|||||||
@ -19,38 +19,41 @@
 | 
				
			|||||||
 *    Evgeny Gryaznov - initial API and implementation
 | 
					 *    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;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$query = sprintf(
 | 
						$query = sprintf(
 | 
				
			||||||
		"insert into ${mysqlprefix}chatnotification (locale,vckind,vcto,vcsubject,tmessage,refoperator,dtmcreated) values ('%s','%s','%s','%s','%s',%s,%s)",
 | 
							"insert into ${mysqlprefix}chatnotification (locale,vckind,vcto,vcsubject,tmessage,refoperator,dtmcreated) values ('%s','%s','%s','%s','%s',%s,%s)",
 | 
				
			||||||
			$locale,
 | 
							$locale,
 | 
				
			||||||
			$kind,
 | 
							$kind,
 | 
				
			||||||
			mysql_real_escape_string($to,$link),
 | 
							mysql_real_escape_string($to, $link),
 | 
				
			||||||
			mysql_real_escape_string($subj,$link),
 | 
							mysql_real_escape_string($subj, $link),
 | 
				
			||||||
			mysql_real_escape_string($text,$link),
 | 
							mysql_real_escape_string($text, $link),
 | 
				
			||||||
			$refop ? $refop : "0",
 | 
							$refop ? $refop : "0",
 | 
				
			||||||
			"CURRENT_TIMESTAMP" );
 | 
							"CURRENT_TIMESTAMP");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	perform_query($query,$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;
 | 
						global $webim_encoding, $webim_mailbox, $mail_encoding, $current_locale;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$headers = "From: $webim_mailbox\r\n"
 | 
						$headers = "From: $webim_mailbox\r\n"
 | 
				
			||||||
	   ."Reply-To: ".myiconv($webim_encoding, $mail_encoding, $reply_to)."\r\n"
 | 
								   . "Reply-To: " . myiconv($webim_encoding, $mail_encoding, $reply_to) . "\r\n"
 | 
				
			||||||
	   ."Content-Type: text/plain; charset=$mail_encoding\r\n"
 | 
								   . "Content-Type: text/plain; charset=$mail_encoding\r\n"
 | 
				
			||||||
	   .'X-Mailer: PHP/'.phpversion();
 | 
								   . 'X-Mailer: PHP/' . phpversion();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$real_subject = "=?".$mail_encoding."?B?".base64_encode(myiconv($webim_encoding,$mail_encoding,$subject))."?=";
 | 
						$real_subject = "=?" . $mail_encoding . "?B?" . base64_encode(myiconv($webim_encoding, $mail_encoding, $subject)) . "?=";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$body = preg_replace("/\n/","\r\n", $body);
 | 
						$body = preg_replace("/\n/", "\r\n", $body);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	log_notification($current_locale, "mail", $toaddr, $subject, $body, null, $link);
 | 
						log_notification($current_locale, "mail", $toaddr, $subject, $body, null, $link);
 | 
				
			||||||
	@mail($toaddr, $real_subject, wordwrap(myiconv($webim_encoding, $mail_encoding, $body),70), $headers);
 | 
						@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;
 | 
						global $current_locale;
 | 
				
			||||||
	log_notification($current_locale, "xmpp", $toaddr, $subject, $text, null, $link);
 | 
						log_notification($current_locale, "xmpp", $toaddr, $subject, $text, null, $link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -33,183 +33,201 @@ $permission_ids = array(
 | 
				
			|||||||
	$can_modifyprofile => "modifyprofile"
 | 
						$can_modifyprofile => "modifyprofile"
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function operator_by_login($login) {
 | 
					function operator_by_login($login)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$operator = select_one_row(
 | 
						$operator = select_one_row(
 | 
				
			||||||
		 "select * from ${mysqlprefix}chatoperator where vclogin = '".mysql_real_escape_string($login)."'", $link );
 | 
							"select * from ${mysqlprefix}chatoperator where vclogin = '" . mysql_real_escape_string($login) . "'", $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
	return $operator;
 | 
						return $operator;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function operator_by_email($mail) {
 | 
					function operator_by_email($mail)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$operator = select_one_row(
 | 
						$operator = select_one_row(
 | 
				
			||||||
		 "select * from ${mysqlprefix}chatoperator where vcemail = '".mysql_real_escape_string($mail)."'", $link );
 | 
							"select * from ${mysqlprefix}chatoperator where vcemail = '" . mysql_real_escape_string($mail) . "'", $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
	return $operator;
 | 
						return $operator;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function operator_by_id_($id,$link) {
 | 
					function operator_by_id_($id, $link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	return select_one_row(
 | 
						return select_one_row(
 | 
				
			||||||
		 "select * from ${mysqlprefix}chatoperator where operatorid = $id", $link );
 | 
							"select * from ${mysqlprefix}chatoperator where operatorid = $id", $link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function operator_by_id($id) {
 | 
					function operator_by_id($id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$operator = operator_by_id_($id,$link);
 | 
						$operator = operator_by_id_($id, $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
	return $operator;
 | 
						return $operator;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function operator_get_all() {
 | 
					function operator_get_all()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$query = "select operatorid, vclogin, vclocalename, vccommonname, istatus, (unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time ".
 | 
						$query = "select operatorid, vclogin, vclocalename, vccommonname, istatus, (unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
 | 
				
			||||||
			 "from ${mysqlprefix}chatoperator order by vclogin";
 | 
								 "from ${mysqlprefix}chatoperator order by vclogin";
 | 
				
			||||||
	$operators = select_multi_assoc($query, $link);
 | 
						$operators = select_multi_assoc($query, $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
	return $operators;
 | 
						return $operators;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function operator_is_online($operator) {
 | 
					function operator_is_online($operator)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings;
 | 
						global $settings;
 | 
				
			||||||
	return $operator['time'] < $settings['online_timeout'];
 | 
						return $operator['time'] < $settings['online_timeout'];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function operator_is_available($operator) {
 | 
					function operator_is_available($operator)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings;
 | 
						global $settings;
 | 
				
			||||||
	return $operator['istatus'] == 0 && $operator['time'] < $settings['online_timeout'] ? "1" : "";
 | 
						return $operator['istatus'] == 0 && $operator['time'] < $settings['online_timeout'] ? "1" : "";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function operator_is_away($operator) {
 | 
					function operator_is_away($operator)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings;
 | 
						global $settings;
 | 
				
			||||||
	return $operator['istatus'] != 0 && $operator['time'] < $settings['online_timeout'] ? "1" : "";
 | 
						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;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$query = sprintf(
 | 
						$query = sprintf(
 | 
				
			||||||
		"update ${mysqlprefix}chatoperator set vclogin = '%s',%s vclocalename = '%s', vccommonname = '%s'".
 | 
							"update ${mysqlprefix}chatoperator set vclogin = '%s',%s vclocalename = '%s', vccommonname = '%s'" .
 | 
				
			||||||
		", vcemail = '%s', vcjabbername= '%s', inotify = %s".
 | 
							", vcemail = '%s', vcjabbername= '%s', inotify = %s" .
 | 
				
			||||||
		" where operatorid = %s",
 | 
							" where operatorid = %s",
 | 
				
			||||||
		mysql_real_escape_string($login),
 | 
							mysql_real_escape_string($login),
 | 
				
			||||||
		($password ? " vcpassword='".md5($password)."'," : ""),
 | 
							($password ? " vcpassword='" . md5($password) . "'," : ""),
 | 
				
			||||||
		mysql_real_escape_string($localename),
 | 
							mysql_real_escape_string($localename),
 | 
				
			||||||
		mysql_real_escape_string($commonname),
 | 
							mysql_real_escape_string($commonname),
 | 
				
			||||||
		mysql_real_escape_string($email),
 | 
							mysql_real_escape_string($email),
 | 
				
			||||||
		mysql_real_escape_string($jabber),
 | 
							mysql_real_escape_string($jabber),
 | 
				
			||||||
		$notify,
 | 
							$notify,
 | 
				
			||||||
		$operatorid );
 | 
							$operatorid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	perform_query($query,$link);
 | 
						perform_query($query, $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function update_operator_avatar($operatorid,$avatar) {
 | 
					function update_operator_avatar($operatorid, $avatar)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$query = sprintf(
 | 
						$query = sprintf(
 | 
				
			||||||
		"update ${mysqlprefix}chatoperator set vcavatar = '%s' where operatorid = %s",
 | 
							"update ${mysqlprefix}chatoperator set vcavatar = '%s' where operatorid = %s",
 | 
				
			||||||
		mysql_real_escape_string($avatar), $operatorid );
 | 
							mysql_real_escape_string($avatar), $operatorid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	perform_query($query,$link);
 | 
						perform_query($query, $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						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;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$query = sprintf(
 | 
						$query = sprintf(
 | 
				
			||||||
		"insert into ${mysqlprefix}chatoperator (vclogin,vcpassword,vclocalename,vccommonname,vcavatar,vcemail,vcjabbername,inotify) values ('%s','%s','%s','%s','%s','%s','%s',%s)",
 | 
							"insert into ${mysqlprefix}chatoperator (vclogin,vcpassword,vclocalename,vccommonname,vcavatar,vcemail,vcjabbername,inotify) values ('%s','%s','%s','%s','%s','%s','%s',%s)",
 | 
				
			||||||
			mysql_real_escape_string($login),
 | 
							mysql_real_escape_string($login),
 | 
				
			||||||
			md5($password),
 | 
							md5($password),
 | 
				
			||||||
			mysql_real_escape_string($localename),
 | 
							mysql_real_escape_string($localename),
 | 
				
			||||||
			mysql_real_escape_string($commonname),
 | 
							mysql_real_escape_string($commonname),
 | 
				
			||||||
			'' /* no avatar */,
 | 
							'' /* no avatar */,
 | 
				
			||||||
			mysql_real_escape_string($email),
 | 
							mysql_real_escape_string($email),
 | 
				
			||||||
			mysql_real_escape_string($jabber),
 | 
							mysql_real_escape_string($jabber),
 | 
				
			||||||
			$notify);
 | 
							$notify);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	perform_query($query,$link);
 | 
						perform_query($query, $link);
 | 
				
			||||||
	$id = mysql_insert_id($link);
 | 
						$id = mysql_insert_id($link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return select_one_row("select * from ${mysqlprefix}chatoperator where operatorid = $id", $link );
 | 
						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();
 | 
						$link = connect();
 | 
				
			||||||
	$newop = create_operator_($login,$email,$jabber,$password,$localename,$commonname,$notify,$link);
 | 
						$newop = create_operator_($login, $email, $jabber, $password, $localename, $commonname, $notify, $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
	return $newop;
 | 
						return $newop;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function notify_operator_alive($operatorid, $istatus) {
 | 
					function notify_operator_alive($operatorid, $istatus)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	perform_query("update ${mysqlprefix}chatoperator set istatus = $istatus, dtmlastvisited = CURRENT_TIMESTAMP where operatorid = $operatorid",$link);
 | 
						perform_query("update ${mysqlprefix}chatoperator set istatus = $istatus, dtmlastvisited = CURRENT_TIMESTAMP where operatorid = $operatorid", $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function has_online_operators($groupid="") {
 | 
					function has_online_operators($groupid = "")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings, $mysqlprefix;
 | 
						global $settings, $mysqlprefix;
 | 
				
			||||||
	loadsettings();
 | 
						loadsettings();
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$query = "select count(*) as total, min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time from ${mysqlprefix}chatoperator";
 | 
						$query = "select count(*) as total, min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time from ${mysqlprefix}chatoperator";
 | 
				
			||||||
	if($groupid) {
 | 
						if ($groupid) {
 | 
				
			||||||
		$query .= ", ${mysqlprefix}chatgroupoperator where groupid = $groupid and ${mysqlprefix}chatoperator.operatorid = " .
 | 
							$query .= ", ${mysqlprefix}chatgroupoperator where groupid = $groupid and ${mysqlprefix}chatoperator.operatorid = " .
 | 
				
			||||||
		"${mysqlprefix}chatgroupoperator.operatorid and istatus = 0";
 | 
									  "${mysqlprefix}chatgroupoperator.operatorid and istatus = 0";
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$query .= " where istatus = 0";
 | 
							$query .= " where istatus = 0";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$row = select_one_row($query,$link);
 | 
						$row = select_one_row($query, $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
	return $row['time'] < $settings['online_timeout'] && $row['total'] > 0;
 | 
						return $row['time'] < $settings['online_timeout'] && $row['total'] > 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function is_operator_online($operatorid, $link) {
 | 
					function is_operator_online($operatorid, $link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings, $mysqlprefix;
 | 
						global $settings, $mysqlprefix;
 | 
				
			||||||
	loadsettings_($link);
 | 
						loadsettings_($link);
 | 
				
			||||||
	$query = "select count(*) as total, min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time ".
 | 
						$query = "select count(*) as total, min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
 | 
				
			||||||
			 "from ${mysqlprefix}chatoperator where operatorid = $operatorid";
 | 
								 "from ${mysqlprefix}chatoperator where operatorid = $operatorid";
 | 
				
			||||||
	$row = select_one_row($query,$link);
 | 
						$row = select_one_row($query, $link);
 | 
				
			||||||
	return $row['time'] < $settings['online_timeout'] && $row['total'] == 1;
 | 
						return $row['time'] < $settings['online_timeout'] && $row['total'] == 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_operator_name($operator) {
 | 
					function get_operator_name($operator)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $home_locale, $current_locale;
 | 
						global $home_locale, $current_locale;
 | 
				
			||||||
	if( $home_locale == $current_locale )
 | 
						if ($home_locale == $current_locale)
 | 
				
			||||||
		return $operator['vclocalename'];
 | 
							return $operator['vclocalename'];
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		return $operator['vccommonname'];
 | 
							return $operator['vccommonname'];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function append_query($link,$pv) {
 | 
					function append_query($link, $pv)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	$infix = '?';
 | 
						$infix = '?';
 | 
				
			||||||
	if( strstr($link,$infix) !== FALSE )
 | 
						if (strstr($link, $infix) !== FALSE)
 | 
				
			||||||
		$infix = '&';
 | 
							$infix = '&';
 | 
				
			||||||
	return "$link$infix$pv";
 | 
						return "$link$infix$pv";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function check_login($redirect=true) {
 | 
					function check_login($redirect = true)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $webimroot, $mysqlprefix;
 | 
						global $webimroot, $mysqlprefix;
 | 
				
			||||||
	if( !isset( $_SESSION["${mysqlprefix}operator"] ) ) {
 | 
						if (!isset($_SESSION["${mysqlprefix}operator"])) {
 | 
				
			||||||
		if( isset($_COOKIE['webim_lite']) ) {
 | 
							if (isset($_COOKIE['webim_lite'])) {
 | 
				
			||||||
			list($login,$pwd) = preg_split("/,/", $_COOKIE['webim_lite'], 2);
 | 
								list($login, $pwd) = preg_split("/,/", $_COOKIE['webim_lite'], 2);
 | 
				
			||||||
			$op = operator_by_login($login);
 | 
								$op = operator_by_login($login);
 | 
				
			||||||
			if( $op && isset($pwd) && isset($op['vcpassword']) && md5($op['vcpassword']) == $pwd ) {
 | 
								if ($op && isset($pwd) && isset($op['vcpassword']) && md5($op['vcpassword']) == $pwd) {
 | 
				
			||||||
				$_SESSION["${mysqlprefix}operator"] = $op;
 | 
									$_SESSION["${mysqlprefix}operator"] = $op;
 | 
				
			||||||
				return $op;
 | 
									return $op;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$requested = $_SERVER['PHP_SELF'];
 | 
							$requested = $_SERVER['PHP_SELF'];
 | 
				
			||||||
		if($_SERVER['REQUEST_METHOD'] == 'GET' && $_SERVER['QUERY_STRING']) {
 | 
							if ($_SERVER['REQUEST_METHOD'] == 'GET' && $_SERVER['QUERY_STRING']) {
 | 
				
			||||||
			$requested .= "?".$_SERVER['QUERY_STRING'];
 | 
								$requested .= "?" . $_SERVER['QUERY_STRING'];
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if($redirect) {
 | 
							if ($redirect) {
 | 
				
			||||||
			$_SESSION['backpath'] = $requested;
 | 
								$_SESSION['backpath'] = $requested;
 | 
				
			||||||
			header("Location: $webimroot/operator/login.php");
 | 
								header("Location: $webimroot/operator/login.php");
 | 
				
			||||||
			exit;
 | 
								exit;
 | 
				
			||||||
@ -220,33 +238,37 @@ function check_login($redirect=true) {
 | 
				
			|||||||
	return $_SESSION["${mysqlprefix}operator"];
 | 
						return $_SESSION["${mysqlprefix}operator"];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_logged_in() {
 | 
					function get_logged_in()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	return isset( $_SESSION["${mysqlprefix}operator"] ) ? $_SESSION["${mysqlprefix}operator"] : FALSE;
 | 
						return isset($_SESSION["${mysqlprefix}operator"]) ? $_SESSION["${mysqlprefix}operator"] : FALSE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function login_operator($operator,$remember) {
 | 
					function login_operator($operator, $remember)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $webimroot, $mysqlprefix;
 | 
						global $webimroot, $mysqlprefix;
 | 
				
			||||||
	$_SESSION["${mysqlprefix}operator"] = $operator;
 | 
						$_SESSION["${mysqlprefix}operator"] = $operator;
 | 
				
			||||||
	if( $remember ) {
 | 
						if ($remember) {
 | 
				
			||||||
		$value = $operator['vclogin'].",".md5($operator['vcpassword']);
 | 
							$value = $operator['vclogin'] . "," . md5($operator['vcpassword']);
 | 
				
			||||||
		setcookie('webim_lite', $value, time()+60*60*24*1000, "$webimroot/");
 | 
							setcookie('webim_lite', $value, time() + 60 * 60 * 24 * 1000, "$webimroot/");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	} else if( isset($_COOKIE['webim_lite']) ) {
 | 
						} else if (isset($_COOKIE['webim_lite'])) {
 | 
				
			||||||
		setcookie('webim_lite', '', time() - 3600, "$webimroot/");
 | 
							setcookie('webim_lite', '', time() - 3600, "$webimroot/");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function logout_operator() {
 | 
					function logout_operator()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $webimroot, $mysqlprefix;
 | 
						global $webimroot, $mysqlprefix;
 | 
				
			||||||
	unset($_SESSION["${mysqlprefix}operator"]);
 | 
						unset($_SESSION["${mysqlprefix}operator"]);
 | 
				
			||||||
	unset($_SESSION['backpath']);
 | 
						unset($_SESSION['backpath']);
 | 
				
			||||||
	if( isset($_COOKIE['webim_lite']) ) {
 | 
						if (isset($_COOKIE['webim_lite'])) {
 | 
				
			||||||
		setcookie('webim_lite', '', time() - 3600, "$webimroot/");
 | 
							setcookie('webim_lite', '', time() - 3600, "$webimroot/");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function setup_redirect_links($threadid,$token) {
 | 
					function setup_redirect_links($threadid, $token)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page, $webimroot, $settings, $mysqlprefix;
 | 
						global $page, $webimroot, $settings, $mysqlprefix;
 | 
				
			||||||
	loadsettings();
 | 
						loadsettings();
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
@ -254,10 +276,10 @@ function setup_redirect_links($threadid,$token) {
 | 
				
			|||||||
	$operatorscount = db_rows_count("${mysqlprefix}chatoperator", array(), "", $link);
 | 
						$operatorscount = db_rows_count("${mysqlprefix}chatoperator", array(), "", $link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$groupscount = 0;
 | 
						$groupscount = 0;
 | 
				
			||||||
    $groups = array();
 | 
						$groups = array();
 | 
				
			||||||
	if($settings['enablegroups'] == "1") {
 | 
						if ($settings['enablegroups'] == "1") {
 | 
				
			||||||
		foreach(get_groups($link, true) as $group) {
 | 
							foreach (get_groups($link, true) as $group) {
 | 
				
			||||||
			if($group['inumofagents'] == 0) {
 | 
								if ($group['inumofagents'] == 0) {
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			$groups[] = $group;
 | 
								$groups[] = $group;
 | 
				
			||||||
@ -265,48 +287,48 @@ function setup_redirect_links($threadid,$token) {
 | 
				
			|||||||
		$groupscount = count($groups);
 | 
							$groupscount = count($groups);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	prepare_pagination(max($operatorscount,$groupscount),8);
 | 
						prepare_pagination(max($operatorscount, $groupscount), 8);
 | 
				
			||||||
	$p = $page['pagination'];
 | 
						$p = $page['pagination'];
 | 
				
			||||||
	$limit = $p['limit'];
 | 
						$limit = $p['limit'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$operators = select_multi_assoc(db_build_select(
 | 
						$operators = select_multi_assoc(db_build_select(
 | 
				
			||||||
		"operatorid, vclogin, vclocalename, vccommonname, istatus, (unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time",
 | 
															"operatorid, vclogin, vclocalename, vccommonname, istatus, (unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time",
 | 
				
			||||||
		"${mysqlprefix}chatoperator", array(), "order by vclogin $limit"), $link);
 | 
															"${mysqlprefix}chatoperator", array(), "order by vclogin $limit"), $link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$groups = array_slice($groups, $p['start'], $p['end']-$p['start']);
 | 
						$groups = array_slice($groups, $p['start'], $p['end'] - $p['start']);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$agent_list = "";
 | 
						$agent_list = "";
 | 
				
			||||||
	$params = array('thread' => $threadid, 'token' => $token);
 | 
						$params = array('thread' => $threadid, 'token' => $token);
 | 
				
			||||||
	foreach($operators as $agent) {
 | 
						foreach ($operators as $agent) {
 | 
				
			||||||
		$params['nextAgent'] = $agent['operatorid'];
 | 
							$params['nextAgent'] = $agent['operatorid'];
 | 
				
			||||||
		$status = $agent['time'] < $settings['online_timeout']
 | 
							$status = $agent['time'] < $settings['online_timeout']
 | 
				
			||||||
			? ($agent['istatus'] == 0
 | 
									? ($agent['istatus'] == 0
 | 
				
			||||||
				? getlocal("char.redirect.operator.online_suff")
 | 
											? getlocal("char.redirect.operator.online_suff")
 | 
				
			||||||
				: getlocal("char.redirect.operator.away_suff")
 | 
											: getlocal("char.redirect.operator.away_suff")
 | 
				
			||||||
			) 
 | 
									)
 | 
				
			||||||
			: "";
 | 
									: "";
 | 
				
			||||||
		$agent_list .= "<li><a href=\"".add_params($webimroot."/operator/redirect.php",$params).
 | 
							$agent_list .= "<li><a href=\"" . add_params($webimroot . "/operator/redirect.php", $params) .
 | 
				
			||||||
						"\" title=\"".topage(get_operator_name($agent))."\">".
 | 
										   "\" title=\"" . topage(get_operator_name($agent)) . "\">" .
 | 
				
			||||||
						    topage(get_operator_name($agent)).
 | 
										   topage(get_operator_name($agent)) .
 | 
				
			||||||
						"</a> $status</li>";
 | 
										   "</a> $status</li>";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$page['redirectToAgent'] = $agent_list;
 | 
						$page['redirectToAgent'] = $agent_list;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$group_list = "";
 | 
						$group_list = "";
 | 
				
			||||||
	if($settings['enablegroups'] == "1") {
 | 
						if ($settings['enablegroups'] == "1") {
 | 
				
			||||||
		$params = array('thread' => $threadid, 'token' => $token);
 | 
							$params = array('thread' => $threadid, 'token' => $token);
 | 
				
			||||||
		foreach($groups as $group) {
 | 
							foreach ($groups as $group) {
 | 
				
			||||||
			$params['nextGroup'] = $group['groupid'];
 | 
								$params['nextGroup'] = $group['groupid'];
 | 
				
			||||||
			$status = $group['ilastseen'] !== NULL && $group['ilastseen'] < $settings['online_timeout']
 | 
								$status = $group['ilastseen'] !== NULL && $group['ilastseen'] < $settings['online_timeout']
 | 
				
			||||||
					? getlocal("char.redirect.operator.online_suff")
 | 
										? getlocal("char.redirect.operator.online_suff")
 | 
				
			||||||
					: ($group['ilastseenaway'] !== NULL && $group['ilastseenaway'] < $settings['online_timeout']
 | 
										: ($group['ilastseenaway'] !== NULL && $group['ilastseenaway'] < $settings['online_timeout']
 | 
				
			||||||
						? getlocal("char.redirect.operator.away_suff")
 | 
												? getlocal("char.redirect.operator.away_suff")
 | 
				
			||||||
						: "");
 | 
												: "");
 | 
				
			||||||
			$group_list .= "<li><a href=\"".add_params($webimroot."/operator/redirect.php",$params).
 | 
								$group_list .= "<li><a href=\"" . add_params($webimroot . "/operator/redirect.php", $params) .
 | 
				
			||||||
								"\" title=\"".topage(get_group_name($group))."\">".
 | 
											   "\" title=\"" . topage(get_group_name($group)) . "\">" .
 | 
				
			||||||
								topage(get_group_name($group)).
 | 
											   topage(get_group_name($group)) .
 | 
				
			||||||
							"</a> $status</li>";
 | 
											   "</a> $status</li>";
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$page['redirectToGroup'] = $group_list;
 | 
						$page['redirectToGroup'] = $group_list;
 | 
				
			||||||
@ -314,10 +336,11 @@ function setup_redirect_links($threadid,$token) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$permission_list = array();
 | 
					$permission_list = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_permission_list() {
 | 
					function get_permission_list()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $permission_list, $permission_ids;
 | 
						global $permission_list, $permission_ids;
 | 
				
			||||||
	if(count($permission_list) == 0) {
 | 
						if (count($permission_list) == 0) {
 | 
				
			||||||
		foreach($permission_ids as $permid) {
 | 
							foreach ($permission_ids as $permid) {
 | 
				
			||||||
			$permission_list[] = array(
 | 
								$permission_list[] = array(
 | 
				
			||||||
				'id' => $permid,
 | 
									'id' => $permid,
 | 
				
			||||||
				'descr' => getlocal("permission.$permid")
 | 
									'descr' => getlocal("permission.$permid")
 | 
				
			||||||
@ -327,15 +350,17 @@ function get_permission_list() {
 | 
				
			|||||||
	return $permission_list;
 | 
						return $permission_list;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function is_capable($perm,$operator) {
 | 
					function is_capable($perm, $operator)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	$permissions = $operator && isset($operator['iperm']) ? $operator['iperm'] : 0;
 | 
						$permissions = $operator && isset($operator['iperm']) ? $operator['iperm'] : 0;
 | 
				
			||||||
	return $perm >= 0 && $perm < 32 && ($permissions & (1 << $perm)) != 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;
 | 
						global $page, $settings, $can_administrate;
 | 
				
			||||||
	$page['operator'] = topage(get_operator_name($operator));
 | 
						$page['operator'] = topage(get_operator_name($operator));
 | 
				
			||||||
	if($hasright) {
 | 
						if ($hasright) {
 | 
				
			||||||
		loadsettings();
 | 
							loadsettings();
 | 
				
			||||||
		$page['showban'] = $settings['enableban'] == "1";
 | 
							$page['showban'] = $settings['enableban'] == "1";
 | 
				
			||||||
		$page['showgroups'] = $settings['enablegroups'] == "1";
 | 
							$page['showgroups'] = $settings['enablegroups'] == "1";
 | 
				
			||||||
@ -345,33 +370,36 @@ function prepare_menu($operator,$hasright=true) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_all_groups($link) {
 | 
					function get_all_groups($link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$query = "select ${mysqlprefix}chatgroup.groupid as groupid, vclocalname, vclocaldescription from ${mysqlprefix}chatgroup order by vclocalname";
 | 
						$query = "select ${mysqlprefix}chatgroup.groupid as groupid, vclocalname, vclocaldescription from ${mysqlprefix}chatgroup order by vclocalname";
 | 
				
			||||||
	return select_multi_assoc($query, $link);
 | 
						return select_multi_assoc($query, $link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_groups($link,$checkaway) {
 | 
					function get_groups($link, $checkaway)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$query = "select ${mysqlprefix}chatgroup.groupid as groupid, vclocalname, vclocaldescription".
 | 
						$query = "select ${mysqlprefix}chatgroup.groupid as groupid, vclocalname, vclocaldescription" .
 | 
				
			||||||
			", (SELECT count(*) from ${mysqlprefix}chatgroupoperator where ${mysqlprefix}chatgroup.groupid = " .
 | 
								 ", (SELECT count(*) from ${mysqlprefix}chatgroupoperator where ${mysqlprefix}chatgroup.groupid = " .
 | 
				
			||||||
			"${mysqlprefix}chatgroupoperator.groupid) as inumofagents".
 | 
								 "${mysqlprefix}chatgroupoperator.groupid) as inumofagents" .
 | 
				
			||||||
			", (SELECT min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time ".
 | 
								 ", (SELECT min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
 | 
				
			||||||
					"from ${mysqlprefix}chatgroupoperator, ${mysqlprefix}chatoperator where istatus = 0 and " .
 | 
								 "from ${mysqlprefix}chatgroupoperator, ${mysqlprefix}chatoperator where istatus = 0 and " .
 | 
				
			||||||
					"${mysqlprefix}chatgroup.groupid = ${mysqlprefix}chatgroupoperator.groupid ".
 | 
								 "${mysqlprefix}chatgroup.groupid = ${mysqlprefix}chatgroupoperator.groupid " .
 | 
				
			||||||
					"and ${mysqlprefix}chatgroupoperator.operatorid = ${mysqlprefix}chatoperator.operatorid) as ilastseen".
 | 
								 "and ${mysqlprefix}chatgroupoperator.operatorid = ${mysqlprefix}chatoperator.operatorid) as ilastseen" .
 | 
				
			||||||
			($checkaway
 | 
								 ($checkaway
 | 
				
			||||||
				 ? ", (SELECT min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time ".
 | 
										 ? ", (SELECT min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
 | 
				
			||||||
						"from ${mysqlprefix}chatgroupoperator, ${mysqlprefix}chatoperator where istatus <> 0 and " .
 | 
										   "from ${mysqlprefix}chatgroupoperator, ${mysqlprefix}chatoperator where istatus <> 0 and " .
 | 
				
			||||||
						"${mysqlprefix}chatgroup.groupid = ${mysqlprefix}chatgroupoperator.groupid ".
 | 
										   "${mysqlprefix}chatgroup.groupid = ${mysqlprefix}chatgroupoperator.groupid " .
 | 
				
			||||||
						"and ${mysqlprefix}chatgroupoperator.operatorid = ${mysqlprefix}chatoperator.operatorid) as ilastseenaway"
 | 
										   "and ${mysqlprefix}chatgroupoperator.operatorid = ${mysqlprefix}chatoperator.operatorid) as ilastseenaway"
 | 
				
			||||||
				 : ""
 | 
										 : ""
 | 
				
			||||||
			 ).
 | 
								 ) .
 | 
				
			||||||
			 " from ${mysqlprefix}chatgroup order by vclocalname";
 | 
								 " from ${mysqlprefix}chatgroup order by vclocalname";
 | 
				
			||||||
	return select_multi_assoc($query, $link);
 | 
						return select_multi_assoc($query, $link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_operator_groupids($operatorid) {
 | 
					function get_operator_groupids($operatorid)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$query = "select groupid from ${mysqlprefix}chatgroupoperator where operatorid = $operatorid";
 | 
						$query = "select groupid from ${mysqlprefix}chatgroupoperator where operatorid = $operatorid";
 | 
				
			||||||
 | 
				
			|||||||
@ -19,26 +19,27 @@
 | 
				
			|||||||
 *    Evgeny Gryaznov - initial API and implementation
 | 
					 *    Evgeny Gryaznov - initial API and implementation
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function setup_operator_settings_tabs($opId, $active) {
 | 
					function setup_operator_settings_tabs($opId, $active)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page, $webimroot, $settings;
 | 
						global $page, $webimroot, $settings;
 | 
				
			||||||
	loadsettings();
 | 
						loadsettings();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if($opId) {
 | 
						if ($opId) {
 | 
				
			||||||
		$page['tabselected'] = $active;
 | 
							$page['tabselected'] = $active;
 | 
				
			||||||
		if($settings['enablegroups'] == '1') {
 | 
							if ($settings['enablegroups'] == '1') {
 | 
				
			||||||
			$page['tabs'] = array(
 | 
								$page['tabs'] = array(
 | 
				
			||||||
				array('title'=> getlocal("page_agent.tab.main"), 'link' => "$webimroot/operator/operator.php?op=$opId"),
 | 
									array('title' => getlocal("page_agent.tab.main"), 'link' => "$webimroot/operator/operator.php?op=$opId"),
 | 
				
			||||||
				array('title'=> getlocal("page_agent.tab.avatar"), 'link' => "$webimroot/operator/avatar.php?op=$opId"),
 | 
									array('title' => getlocal("page_agent.tab.avatar"), 'link' => "$webimroot/operator/avatar.php?op=$opId"),
 | 
				
			||||||
				array('title'=> getlocal("page_agent.tab.groups"), 'link' => "$webimroot/operator/opgroups.php?op=$opId"),
 | 
									array('title' => getlocal("page_agent.tab.groups"), 'link' => "$webimroot/operator/opgroups.php?op=$opId"),
 | 
				
			||||||
				array('title'=> getlocal("page_agent.tab.permissions"), 'link' => "$webimroot/operator/permissions.php?op=$opId"),
 | 
									array('title' => getlocal("page_agent.tab.permissions"), 'link' => "$webimroot/operator/permissions.php?op=$opId"),
 | 
				
			||||||
			);
 | 
								);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			$page['tabs'] = array(
 | 
								$page['tabs'] = array(
 | 
				
			||||||
				array('title'=> getlocal("page_agent.tab.main"), 'link' => "$webimroot/operator/operator.php?op=$opId"),
 | 
									array('title' => getlocal("page_agent.tab.main"), 'link' => "$webimroot/operator/operator.php?op=$opId"),
 | 
				
			||||||
				array('title'=> getlocal("page_agent.tab.avatar"), 'link' => "$webimroot/operator/avatar.php?op=$opId"),
 | 
									array('title' => getlocal("page_agent.tab.avatar"), 'link' => "$webimroot/operator/avatar.php?op=$opId"),
 | 
				
			||||||
				array('title'=> getlocal("page_agent.tab.permissions"), 'link' => "$webimroot/operator/permissions.php?op=$opId"),
 | 
									array('title' => getlocal("page_agent.tab.permissions"), 'link' => "$webimroot/operator/permissions.php?op=$opId"),
 | 
				
			||||||
			);
 | 
								);
 | 
				
			||||||
			if($active == 3) $active--;
 | 
								if ($active == 3) $active--;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$page['tabs'] = array();
 | 
							$page['tabs'] = array();
 | 
				
			||||||
 | 
				
			|||||||
@ -22,110 +22,117 @@
 | 
				
			|||||||
$pagination_spacing = "   ";
 | 
					$pagination_spacing = "   ";
 | 
				
			||||||
$links_on_page = 5;
 | 
					$links_on_page = 5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function generate_pagination_link($page,$title) {
 | 
					function generate_pagination_link($page, $title)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	$lnk = $_SERVER['REQUEST_URI'];
 | 
						$lnk = $_SERVER['REQUEST_URI'];
 | 
				
			||||||
	$href = preg_replace("/\?page=\d+\&/", "?", preg_replace("/\&page=\d+/", "", $lnk));
 | 
						$href = preg_replace("/\?page=\d+\&/", "?", preg_replace("/\&page=\d+/", "", $lnk));
 | 
				
			||||||
	$href .= strstr($href,"?") ? "&page=$page" : "?page=$page";
 | 
						$href .= strstr($href, "?") ? "&page=$page" : "?page=$page";
 | 
				
			||||||
	return "<a href=\"".htmlspecialchars($href)."\" class=\"pagelink\">$title</a>";
 | 
						return "<a href=\"" . htmlspecialchars($href) . "\" class=\"pagelink\">$title</a>";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function generate_pagination_image($id,$alt) {
 | 
					function generate_pagination_image($id, $alt)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $webimroot;
 | 
						global $webimroot;
 | 
				
			||||||
	return "<img src=\"$webimroot/images/$id.gif\" border=\"0\" alt=\"".htmlspecialchars($alt)."\"/>";
 | 
						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;
 | 
						global $page;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $items_count ) {
 | 
						if ($items_count) {
 | 
				
			||||||
		$items_per_page = verifyparam("items", "/^\d{1,3}$/", $default_items_per_page);
 | 
							$items_per_page = verifyparam("items", "/^\d{1,3}$/", $default_items_per_page);
 | 
				
			||||||
		if( $items_per_page < 2 )
 | 
							if ($items_per_page < 2)
 | 
				
			||||||
			$items_per_page = 2;
 | 
								$items_per_page = 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$total_pages = div($items_count + $items_per_page - 1, $items_per_page);
 | 
							$total_pages = div($items_count + $items_per_page - 1, $items_per_page);
 | 
				
			||||||
		$curr_page = verifyparam("page", "/^\d{1,6}$/", 1);
 | 
							$curr_page = verifyparam("page", "/^\d{1,6}$/", 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( $curr_page < 1 )
 | 
							if ($curr_page < 1)
 | 
				
			||||||
			$curr_page = 1;
 | 
								$curr_page = 1;
 | 
				
			||||||
		if( $curr_page > $total_pages )
 | 
							if ($curr_page > $total_pages)
 | 
				
			||||||
			$curr_page = $total_pages;
 | 
								$curr_page = $total_pages;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$start_index = ($curr_page-1)*$items_per_page;
 | 
							$start_index = ($curr_page - 1) * $items_per_page;
 | 
				
			||||||
		$end_index = min($start_index+$items_per_page, $items_count);
 | 
							$end_index = min($start_index + $items_per_page, $items_count);
 | 
				
			||||||
		$page['pagination'] =
 | 
							$page['pagination'] =
 | 
				
			||||||
			array(  "page" => $curr_page, "items" => $items_per_page, "total" => $total_pages,
 | 
									array("page" => $curr_page, "items" => $items_per_page, "total" => $total_pages,
 | 
				
			||||||
					"count" => $items_count, "start" => $start_index, "end" => $end_index,
 | 
										  "count" => $items_count, "start" => $start_index, "end" => $end_index,
 | 
				
			||||||
					"limit" => "LIMIT $start_index,".($end_index - $start_index) );
 | 
										  "limit" => "LIMIT $start_index," . ($end_index - $start_index));
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$page['pagination'] = true;
 | 
							$page['pagination'] = true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function setup_pagination($items,$default_items_per_page=15) {
 | 
					function setup_pagination($items, $default_items_per_page = 15)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page;
 | 
						global $page;
 | 
				
			||||||
	prepare_pagination($items ? count($items) : 0, $default_items_per_page);
 | 
						prepare_pagination($items ? count($items) : 0, $default_items_per_page);
 | 
				
			||||||
	if($items && count($items) > 0) {
 | 
						if ($items && count($items) > 0) {
 | 
				
			||||||
		$p = $page['pagination'];
 | 
							$p = $page['pagination'];
 | 
				
			||||||
		$page['pagination.items'] = array_slice($items, $p['start'], $p['end']-$p['start']);
 | 
							$page['pagination.items'] = array_slice($items, $p['start'], $p['end'] - $p['start']);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$page['pagination.items'] = false;
 | 
							$page['pagination.items'] = false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function select_with_pagintation($fields, $table, $conditions, $order, $countfields, $link) {
 | 
					function select_with_pagintation($fields, $table, $conditions, $order, $countfields, $link)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page;
 | 
						global $page;
 | 
				
			||||||
	$count = db_rows_count($table, $conditions, $countfields, $link);
 | 
						$count = db_rows_count($table, $conditions, $countfields, $link);
 | 
				
			||||||
	prepare_pagination($count);
 | 
						prepare_pagination($count);
 | 
				
			||||||
	if($count) {
 | 
						if ($count) {
 | 
				
			||||||
		$p = $page['pagination'];
 | 
							$p = $page['pagination'];
 | 
				
			||||||
		$limit = $p['limit'];
 | 
							$limit = $p['limit'];
 | 
				
			||||||
		$page['pagination.items'] = select_multi_assoc(db_build_select($fields, $table, $conditions, $order)." ".$limit, $link);
 | 
							$page['pagination.items'] = select_multi_assoc(db_build_select($fields, $table, $conditions, $order) . " " . $limit, $link);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$page['pagination.items'] = false;
 | 
							$page['pagination.items'] = false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function setup_empty_pagination() {
 | 
					function setup_empty_pagination()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page;
 | 
						global $page;
 | 
				
			||||||
	$page['pagination.items'] = false;
 | 
						$page['pagination.items'] = false;
 | 
				
			||||||
	$page['pagination'] = false;
 | 
						$page['pagination'] = false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function generate_pagination($pagination,$bottom=true) {
 | 
					function generate_pagination($pagination, $bottom = true)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $pagination_spacing, $links_on_page;
 | 
						global $pagination_spacing, $links_on_page;
 | 
				
			||||||
	$result = getlocal2("tag.pagination.info",
 | 
						$result = getlocal2("tag.pagination.info",
 | 
				
			||||||
		array($pagination['page'],$pagination['total'],$pagination['start']+1,$pagination['end'],$pagination['count']))."<br/>";
 | 
											array($pagination['page'], $pagination['total'], $pagination['start'] + 1, $pagination['end'], $pagination['count'])) . "<br/>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $pagination['total'] > 1 ) {
 | 
						if ($pagination['total'] > 1) {
 | 
				
			||||||
		if(!$bottom) {
 | 
							if (!$bottom) {
 | 
				
			||||||
			$result = "";
 | 
								$result = "";
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			$result .= "<br/>";
 | 
								$result .= "<br/>";
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$result.="<div class='pagination'>";
 | 
							$result .= "<div class='pagination'>";
 | 
				
			||||||
		$curr_page = $pagination['page'];
 | 
							$curr_page = $pagination['page'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$minPage = max( $curr_page - $links_on_page, 1 );
 | 
							$minPage = max($curr_page - $links_on_page, 1);
 | 
				
			||||||
		$maxPage = min( $curr_page + $links_on_page, $pagination['total'] );
 | 
							$maxPage = min($curr_page + $links_on_page, $pagination['total']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( $curr_page > 1 ) {
 | 
							if ($curr_page > 1) {
 | 
				
			||||||
			$result .= generate_pagination_link($curr_page-1, generate_pagination_image("prevpage", getlocal("tag.pagination.previous"))).$pagination_spacing;
 | 
								$result .= generate_pagination_link($curr_page - 1, generate_pagination_image("prevpage", getlocal("tag.pagination.previous"))) . $pagination_spacing;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for($i = $minPage; $i <= $maxPage; $i++ ) {
 | 
							for ($i = $minPage; $i <= $maxPage; $i++) {
 | 
				
			||||||
			$title = abs($curr_page-$i) >= $links_on_page && $i != 1 ? "..." : $i;
 | 
								$title = abs($curr_page - $i) >= $links_on_page && $i != 1 ? "..." : $i;
 | 
				
			||||||
			if( $i != $curr_page)
 | 
								if ($i != $curr_page)
 | 
				
			||||||
				$result .= generate_pagination_link($i, $title);
 | 
									$result .= generate_pagination_link($i, $title);
 | 
				
			||||||
			else
 | 
								else
 | 
				
			||||||
				$result .= "<span class=\"pagecurrent\">$title</span>";
 | 
									$result .= "<span class=\"pagecurrent\">$title</span>";
 | 
				
			||||||
			if( $i < $maxPage )
 | 
								if ($i < $maxPage)
 | 
				
			||||||
				$result .= $pagination_spacing;
 | 
									$result .= $pagination_spacing;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( $curr_page < $pagination['total'] ) {
 | 
							if ($curr_page < $pagination['total']) {
 | 
				
			||||||
			$result .= $pagination_spacing.generate_pagination_link($curr_page+1, generate_pagination_image("nextpage", getlocal("tag.pagination.next")));
 | 
								$result .= $pagination_spacing . generate_pagination_link($curr_page + 1, generate_pagination_image("nextpage", getlocal("tag.pagination.next")));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$result.="</div>";
 | 
							$result .= "</div>";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return $result;
 | 
						return $result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -19,28 +19,30 @@
 | 
				
			|||||||
 *    Evgeny Gryaznov - initial API and implementation
 | 
					 *    Evgeny Gryaznov - initial API and implementation
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function update_settings() {
 | 
					function update_settings()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings, $settings_in_db, $mysqlprefix;
 | 
						global $settings, $settings_in_db, $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	foreach ($settings as $key => $value) {
 | 
						foreach ($settings as $key => $value) {
 | 
				
			||||||
		if(!isset($settings_in_db[$key])) {
 | 
							if (!isset($settings_in_db[$key])) {
 | 
				
			||||||
			perform_query("insert into ${mysqlprefix}chatconfig (vckey) values ('$key')",$link);
 | 
								perform_query("insert into ${mysqlprefix}chatconfig (vckey) values ('$key')", $link);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
        $query = sprintf("update ${mysqlprefix}chatconfig set vcvalue='%s' where vckey='$key'", mysql_real_escape_string($value));
 | 
							$query = sprintf("update ${mysqlprefix}chatconfig set vcvalue='%s' where vckey='$key'", mysql_real_escape_string($value));
 | 
				
			||||||
		perform_query($query,$link);
 | 
							perform_query($query, $link);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function setup_settings_tabs($active) {
 | 
					function setup_settings_tabs($active)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $page, $webimroot;
 | 
						global $page, $webimroot;
 | 
				
			||||||
	$page['tabselected'] = $active;
 | 
						$page['tabselected'] = $active;
 | 
				
			||||||
	$page['tabs'] = array(
 | 
						$page['tabs'] = array(
 | 
				
			||||||
		array('title'=> getlocal("page_settings.tab.main"), 'link' => "$webimroot/operator/settings.php"),
 | 
							array('title' => getlocal("page_settings.tab.main"), 'link' => "$webimroot/operator/settings.php"),
 | 
				
			||||||
		array('title'=> getlocal("page_settings.tab.features"), 'link' => "$webimroot/operator/features.php"),
 | 
							array('title' => getlocal("page_settings.tab.features"), 'link' => "$webimroot/operator/features.php"),
 | 
				
			||||||
		array('title'=> getlocal("page_settings.tab.performance"), 'link' => "$webimroot/operator/performance.php"),
 | 
							array('title' => getlocal("page_settings.tab.performance"), 'link' => "$webimroot/operator/performance.php"),
 | 
				
			||||||
		array('title'=> getlocal("page_settings.tab.themes"), 'link' => "$webimroot/operator/themes.php"),
 | 
							array('title' => getlocal("page_settings.tab.themes"), 'link' => "$webimroot/operator/themes.php"),
 | 
				
			||||||
	);
 | 
						);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -19,38 +19,40 @@
 | 
				
			|||||||
 *    Evgeny Gryaznov - initial API and implementation
 | 
					 *    Evgeny Gryaznov - initial API and implementation
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_useragent_version($userAgent) {
 | 
					function get_useragent_version($userAgent)
 | 
				
			||||||
    global $knownAgents;
 | 
					{
 | 
				
			||||||
    if (is_array($knownAgents)) {
 | 
						global $knownAgents;
 | 
				
			||||||
	$userAgent = strtolower($userAgent);
 | 
						if (is_array($knownAgents)) {
 | 
				
			||||||
	foreach( $knownAgents as $agent ) {
 | 
							$userAgent = strtolower($userAgent);
 | 
				
			||||||
		if( strstr($userAgent,$agent) ) {
 | 
							foreach ($knownAgents as $agent) {
 | 
				
			||||||
			if( preg_match( "/".$agent."[\\s\/]?(\\d+(\\.\\d+(\\.\\d+(\\.\\d+)?)?)?)/", $userAgent, $matches ) ) {
 | 
								if (strstr($userAgent, $agent)) {
 | 
				
			||||||
				$ver = $matches[1];
 | 
									if (preg_match("/" . $agent . "[\\s\/]?(\\d+(\\.\\d+(\\.\\d+(\\.\\d+)?)?)?)/", $userAgent, $matches)) {
 | 
				
			||||||
				if($agent=='safari') {
 | 
										$ver = $matches[1];
 | 
				
			||||||
					if(preg_match( "/version\/(\\d+(\\.\\d+(\\.\\d+)?)?)/", $userAgent, $matches)) {
 | 
										if ($agent == 'safari') {
 | 
				
			||||||
						$ver = $matches[1];
 | 
											if (preg_match("/version\/(\\d+(\\.\\d+(\\.\\d+)?)?)/", $userAgent, $matches)) {
 | 
				
			||||||
					} else {
 | 
												$ver = $matches[1];
 | 
				
			||||||
						$ver = "1 or 2 (build ".$ver.")";
 | 
											} else {
 | 
				
			||||||
 | 
												$ver = "1 or 2 (build " . $ver . ")";
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											if (preg_match("/mobile\/(\\d+(\\.\\d+(\\.\\d+)?)?)/", $userAgent, $matches)) {
 | 
				
			||||||
 | 
												$userAgent = "iPhone " . $matches[1] . " ($agent $ver)";
 | 
				
			||||||
 | 
												break;
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					if(preg_match( "/mobile\/(\\d+(\\.\\d+(\\.\\d+)?)?)/", $userAgent, $matches)) {
 | 
					 | 
				
			||||||
						$userAgent = "iPhone ".$matches[1]." ($agent $ver)";
 | 
					 | 
				
			||||||
						break;
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				$userAgent = ucfirst($agent)." ".$ver;
 | 
										$userAgent = ucfirst($agent) . " " . $ver;
 | 
				
			||||||
				break;
 | 
										break;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
    }
 | 
						return $userAgent;
 | 
				
			||||||
    return $userAgent;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_user_addr($addr) {
 | 
					function get_user_addr($addr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings;
 | 
						global $settings;
 | 
				
			||||||
	if($settings['geolink'] && preg_match( "/(\\d+\\.\\d+\\.\\d+\\.\\d+)/", $addr, $matches )) {
 | 
						if ($settings['geolink'] && preg_match("/(\\d+\\.\\d+\\.\\d+\\.\\d+)/", $addr, $matches)) {
 | 
				
			||||||
		$userip = $matches[1];
 | 
							$userip = $matches[1];
 | 
				
			||||||
		return get_popup(str_replace("{ip}", $userip, $settings['geolink']), '', htmlspecialchars($addr), "GeoLocation", "ip$userip", $settings['geolinkparams']);
 | 
							return get_popup(str_replace("{ip}", $userip, $settings['geolink']), '', htmlspecialchars($addr), "GeoLocation", "ip$userip", $settings['geolinkparams']);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -29,11 +29,11 @@ require_once('../libs/expand.php');
 | 
				
			|||||||
$operator = check_login();
 | 
					$operator = check_login();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
loadsettings();
 | 
					loadsettings();
 | 
				
			||||||
if($settings['enablessl'] == "1" && $settings['forcessl'] == "1") {
 | 
					if ($settings['enablessl'] == "1" && $settings['forcessl'] == "1") {
 | 
				
			||||||
	if(!is_secure_request()) {
 | 
						if (!is_secure_request()) {
 | 
				
			||||||
		$requested = $_SERVER['PHP_SELF'];
 | 
							$requested = $_SERVER['PHP_SELF'];
 | 
				
			||||||
		if($_SERVER['REQUEST_METHOD'] == 'GET' && $_SERVER['QUERY_STRING']) {
 | 
							if ($_SERVER['REQUEST_METHOD'] == 'GET' && $_SERVER['QUERY_STRING']) {
 | 
				
			||||||
			header("Location: ".get_app_location(true,true)."/operator/agent.php?".$_SERVER['QUERY_STRING']);
 | 
								header("Location: " . get_app_location(true, true) . "/operator/agent.php?" . $_SERVER['QUERY_STRING']);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			die("only https connections are handled");
 | 
								die("only https connections are handled");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -41,35 +41,35 @@ if($settings['enablessl'] == "1" && $settings['forcessl'] == "1") {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$threadid = verifyparam( "thread", "/^\d{1,8}$/");
 | 
					$threadid = verifyparam("thread", "/^\d{1,8}$/");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if( !isset($_GET['token']) ) {
 | 
					if (!isset($_GET['token'])) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$remote_level = get_remote_level($_SERVER['HTTP_USER_AGENT']);
 | 
						$remote_level = get_remote_level($_SERVER['HTTP_USER_AGENT']);
 | 
				
			||||||
	if( $remote_level != "ajaxed" ) {
 | 
						if ($remote_level != "ajaxed") {
 | 
				
			||||||
		die("old browser is used, please update it");
 | 
							die("old browser is used, please update it");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$thread = thread_by_id($threadid);
 | 
						$thread = thread_by_id($threadid);
 | 
				
			||||||
	if( !$thread || !isset($thread['ltoken']) ) {
 | 
						if (!$thread || !isset($thread['ltoken'])) {
 | 
				
			||||||
		die("wrong thread");
 | 
							die("wrong thread");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$viewonly = verifyparam( "viewonly", "/^true$/", false);
 | 
						$viewonly = verifyparam("viewonly", "/^true$/", false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$forcetake = verifyparam("force", "/^true$/", false);
 | 
						$forcetake = verifyparam("force", "/^true$/", false);
 | 
				
			||||||
	if( !$viewonly && $thread['istate'] == $state_chatting && $operator['operatorid'] != $thread['agentId'] ) {
 | 
						if (!$viewonly && $thread['istate'] == $state_chatting && $operator['operatorid'] != $thread['agentId']) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(!is_capable($can_takeover, $operator)) {
 | 
							if (!is_capable($can_takeover, $operator)) {
 | 
				
			||||||
			$errors = array("Cannot take over");
 | 
								$errors = array("Cannot take over");
 | 
				
			||||||
			start_html_output();
 | 
								start_html_output();
 | 
				
			||||||
			expand("../styles", getchatstyle(), "error.tpl");
 | 
								expand("../styles", getchatstyle(), "error.tpl");
 | 
				
			||||||
			exit;
 | 
								exit;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( $forcetake == false ) {
 | 
							if ($forcetake == false) {
 | 
				
			||||||
			$page = array(
 | 
								$page = array(
 | 
				
			||||||
				'user' => topage($thread['userName']), 'agent' => topage($thread['agentName']), 'link' => $_SERVER['PHP_SELF']."?thread=$threadid&force=true"
 | 
									'user' => topage($thread['userName']), 'agent' => topage($thread['agentName']), 'link' => $_SERVER['PHP_SELF'] . "?thread=$threadid&force=true"
 | 
				
			||||||
			);
 | 
								);
 | 
				
			||||||
			start_html_output();
 | 
								start_html_output();
 | 
				
			||||||
			require('../view/confirm.php');
 | 
								require('../view/confirm.php');
 | 
				
			||||||
@ -78,8 +78,8 @@ if( !isset($_GET['token']) ) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!$viewonly) {
 | 
						if (!$viewonly) {
 | 
				
			||||||
		take_thread($thread,$operator);
 | 
							take_thread($thread, $operator);
 | 
				
			||||||
	} else if(!is_capable($can_viewthreads, $operator)) {
 | 
						} else if (!is_capable($can_viewthreads, $operator)) {
 | 
				
			||||||
		$errors = array("Cannot view threads");
 | 
							$errors = array("Cannot view threads");
 | 
				
			||||||
		start_html_output();
 | 
							start_html_output();
 | 
				
			||||||
		expand("../styles", getchatstyle(), "error.tpl");
 | 
							expand("../styles", getchatstyle(), "error.tpl");
 | 
				
			||||||
@ -91,14 +91,14 @@ if( !isset($_GET['token']) ) {
 | 
				
			|||||||
	exit;
 | 
						exit;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$token = verifyparam( "token", "/^\d{1,8}$/");
 | 
					$token = verifyparam("token", "/^\d{1,8}$/");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$thread = thread_by_id($threadid);
 | 
					$thread = thread_by_id($threadid);
 | 
				
			||||||
if( !$thread || !isset($thread['ltoken']) || $token != $thread['ltoken'] ) {
 | 
					if (!$thread || !isset($thread['ltoken']) || $token != $thread['ltoken']) {
 | 
				
			||||||
	die("wrong thread");
 | 
						die("wrong thread");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if($thread['agentId'] != $operator['operatorid'] && !is_capable($can_viewthreads, $operator)) {
 | 
					if ($thread['agentId'] != $operator['operatorid'] && !is_capable($can_viewthreads, $operator)) {
 | 
				
			||||||
	$errors = array("Cannot view threads");
 | 
						$errors = array("Cannot view threads");
 | 
				
			||||||
	start_html_output();
 | 
						start_html_output();
 | 
				
			||||||
	expand("../styles", getchatstyle(), "error.tpl");
 | 
						expand("../styles", getchatstyle(), "error.tpl");
 | 
				
			||||||
@ -109,9 +109,9 @@ setup_chatview_for_operator($thread, $operator);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
start_html_output();
 | 
					start_html_output();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$pparam = verifyparam( "act", "/^(redirect)$/", "default");
 | 
					$pparam = verifyparam("act", "/^(redirect)$/", "default");
 | 
				
			||||||
if( $pparam == "redirect" ) {
 | 
					if ($pparam == "redirect") {
 | 
				
			||||||
	setup_redirect_links($threadid,$token);
 | 
						setup_redirect_links($threadid, $token);
 | 
				
			||||||
	expand("../styles", getchatstyle(), "redirect.tpl");
 | 
						expand("../styles", getchatstyle(), "redirect.tpl");
 | 
				
			||||||
} else {
 | 
					} else {
 | 
				
			||||||
	expand("../styles", getchatstyle(), "chat.tpl");
 | 
						expand("../styles", getchatstyle(), "chat.tpl");
 | 
				
			||||||
 | 
				
			|||||||
@ -25,7 +25,7 @@ require_once('../libs/operator.php');
 | 
				
			|||||||
$operator = check_login(false);
 | 
					$operator = check_login(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
start_xml_output();
 | 
					start_xml_output();
 | 
				
			||||||
if($operator) {
 | 
					if ($operator) {
 | 
				
			||||||
	echo "<login><status>OK</status></login>";
 | 
						echo "<login><status>OK</status></login>";
 | 
				
			||||||
} else {
 | 
					} else {
 | 
				
			||||||
	echo "<login><status>FAILED</status></login>";
 | 
						echo "<login><status>FAILED</status></login>";
 | 
				
			||||||
 | 
				
			|||||||
@ -25,57 +25,57 @@ require_once('../libs/operator_settings.php');
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$operator = check_login();
 | 
					$operator = check_login();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$opId = verifyparam( "op","/^\d{1,9}$/");
 | 
					$opId = verifyparam("op", "/^\d{1,9}$/");
 | 
				
			||||||
$page = array('opid' => $opId, 'avatar' => '');
 | 
					$page = array('opid' => $opId, 'avatar' => '');
 | 
				
			||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$canmodify = ($opId == $operator['operatorid'] && is_capable($can_modifyprofile, $operator))
 | 
					$canmodify = ($opId == $operator['operatorid'] && is_capable($can_modifyprofile, $operator))
 | 
				
			||||||
				|| is_capable($can_administrate, $operator);
 | 
								 || is_capable($can_administrate, $operator);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$op = operator_by_id($opId);
 | 
					$op = operator_by_id($opId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if( !$op ) {
 | 
					if (!$op) {
 | 
				
			||||||
	$errors[] = getlocal("no_such_operator");
 | 
						$errors[] = getlocal("no_such_operator");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} else if( isset($_POST['op']) ) {
 | 
					} else if (isset($_POST['op'])) {
 | 
				
			||||||
	$avatar = $op['vcavatar'];
 | 
						$avatar = $op['vcavatar'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(!$canmodify) {
 | 
						if (!$canmodify) {
 | 
				
			||||||
		$errors[] = getlocal('page_agent.cannot_modify');
 | 
							$errors[] = getlocal('page_agent.cannot_modify');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	} else if( isset($_FILES['avatarFile']) && $_FILES['avatarFile']['name']) {
 | 
						} else if (isset($_FILES['avatarFile']) && $_FILES['avatarFile']['name']) {
 | 
				
			||||||
        $valid_types = array("gif","jpg", "png", "tif");
 | 
							$valid_types = array("gif", "jpg", "png", "tif");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $orig_filename = $_FILES['avatarFile']['name'];
 | 
							$orig_filename = $_FILES['avatarFile']['name'];
 | 
				
			||||||
        $tmp_file_name = $_FILES['avatarFile']['tmp_name'];
 | 
							$tmp_file_name = $_FILES['avatarFile']['tmp_name'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $ext = strtolower(substr($orig_filename, 1 + strrpos($orig_filename, ".")));
 | 
							$ext = strtolower(substr($orig_filename, 1 + strrpos($orig_filename, ".")));
 | 
				
			||||||
        $new_file_name = "$opId.$ext";
 | 
							$new_file_name = "$opId.$ext";
 | 
				
			||||||
        loadsettings();
 | 
							loadsettings();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $file_size = $_FILES['avatarFile']['size'];
 | 
							$file_size = $_FILES['avatarFile']['size'];
 | 
				
			||||||
        if ($file_size == 0 || $file_size > $settings['max_uploaded_file_size']) {
 | 
							if ($file_size == 0 || $file_size > $settings['max_uploaded_file_size']) {
 | 
				
			||||||
            $errors[] = failed_uploading_file($orig_filename, "errors.file.size.exceeded");
 | 
								$errors[] = failed_uploading_file($orig_filename, "errors.file.size.exceeded");
 | 
				
			||||||
        } elseif(!in_array($ext, $valid_types)) {
 | 
							} elseif (!in_array($ext, $valid_types)) {
 | 
				
			||||||
            $errors[] = failed_uploading_file($orig_filename, "errors.invalid.file.type");
 | 
								$errors[] = failed_uploading_file($orig_filename, "errors.invalid.file.type");
 | 
				
			||||||
        } else {
 | 
							} else {
 | 
				
			||||||
            $avatar_local_dir = "../images/avatar/";
 | 
								$avatar_local_dir = "../images/avatar/";
 | 
				
			||||||
            $full_file_path = $avatar_local_dir.$new_file_name;
 | 
								$full_file_path = $avatar_local_dir . $new_file_name;
 | 
				
			||||||
            if (file_exists($full_file_path)) {
 | 
								if (file_exists($full_file_path)) {
 | 
				
			||||||
                unlink($full_file_path);
 | 
									unlink($full_file_path);
 | 
				
			||||||
            }
 | 
								}
 | 
				
			||||||
            if (!move_uploaded_file($_FILES['avatarFile']['tmp_name'], $full_file_path)) {
 | 
								if (!move_uploaded_file($_FILES['avatarFile']['tmp_name'], $full_file_path)) {
 | 
				
			||||||
                $errors[] = failed_uploading_file($orig_filename, "errors.file.move.error");
 | 
									$errors[] = failed_uploading_file($orig_filename, "errors.file.move.error");
 | 
				
			||||||
            } else {
 | 
								} else {
 | 
				
			||||||
                $avatar = "$webimroot/images/avatar/$new_file_name";
 | 
									$avatar = "$webimroot/images/avatar/$new_file_name";
 | 
				
			||||||
            }
 | 
								}
 | 
				
			||||||
        }
 | 
							}
 | 
				
			||||||
    } else {
 | 
						} else {
 | 
				
			||||||
    	$errors[] = "No file selected";
 | 
							$errors[] = "No file selected";
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(count($errors) == 0) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		update_operator_avatar($op['operatorid'],$avatar);
 | 
							update_operator_avatar($op['operatorid'], $avatar);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ($opId && $avatar && $_SESSION[$mysqlprefix . 'operator'] && $operator['operatorid'] == $opId) {
 | 
							if ($opId && $avatar && $_SESSION[$mysqlprefix . 'operator'] && $operator['operatorid'] == $opId) {
 | 
				
			||||||
			$_SESSION[$mysqlprefix . 'operator']['vcavatar'] = $avatar;
 | 
								$_SESSION[$mysqlprefix . 'operator']['vcavatar'] = $avatar;
 | 
				
			||||||
@ -88,18 +88,18 @@ if( !$op ) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
} else {
 | 
					} else {
 | 
				
			||||||
	if (isset($_GET['delete']) && $_GET['delete'] == "true" && $canmodify) {
 | 
						if (isset($_GET['delete']) && $_GET['delete'] == "true" && $canmodify) {
 | 
				
			||||||
		update_operator_avatar($op['operatorid'],'');
 | 
							update_operator_avatar($op['operatorid'], '');
 | 
				
			||||||
		header("Location: $webimroot/operator/avatar.php?op=$opId");
 | 
							header("Location: $webimroot/operator/avatar.php?op=$opId");
 | 
				
			||||||
		exit;
 | 
							exit;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$page['avatar'] = topage($op['vcavatar']);
 | 
						$page['avatar'] = topage($op['vcavatar']);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page['currentop'] = $op ? topage(get_operator_name($op))." (".$op['vclogin'].")" : "-not found-";
 | 
					$page['currentop'] = $op ? topage(get_operator_name($op)) . " (" . $op['vclogin'] . ")" : "-not found-";
 | 
				
			||||||
$page['canmodify'] = $canmodify ? "1" : "";
 | 
					$page['canmodify'] = $canmodify ? "1" : "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
prepare_menu($operator);
 | 
					prepare_menu($operator);
 | 
				
			||||||
setup_operator_settings_tabs($opId,1);
 | 
					setup_operator_settings_tabs($opId, 1);
 | 
				
			||||||
start_html_output();
 | 
					start_html_output();
 | 
				
			||||||
require('../view/avatar.php');
 | 
					require('../view/avatar.php');
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
@ -31,55 +31,55 @@ $page['thread'] = '';
 | 
				
			|||||||
$page['threadid'] = '';
 | 
					$page['threadid'] = '';
 | 
				
			||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if( isset($_POST['address']) ) {
 | 
					if (isset($_POST['address'])) {
 | 
				
			||||||
	$banId = verifyparam( "banId", "/^(\d{1,9})?$/", "");
 | 
						$banId = verifyparam("banId", "/^(\d{1,9})?$/", "");
 | 
				
			||||||
	$address = getparam("address");
 | 
						$address = getparam("address");
 | 
				
			||||||
	$days = getparam("days");
 | 
						$days = getparam("days");
 | 
				
			||||||
	$comment = getparam('comment');
 | 
						$comment = getparam('comment');
 | 
				
			||||||
	$threadid = isset($_POST['threadid']) ? getparam('threadid') : "";
 | 
						$threadid = isset($_POST['threadid']) ? getparam('threadid') : "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !$address ) {
 | 
						if (!$address) {
 | 
				
			||||||
		$errors[] = no_field("form.field.address");
 | 
							$errors[] = no_field("form.field.address");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !preg_match( "/^\d+$/", $days )) {
 | 
						if (!preg_match("/^\d+$/", $days)) {
 | 
				
			||||||
		$errors[] = wrong_field("form.field.ban_days");
 | 
							$errors[] = wrong_field("form.field.ban_days");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !$comment ) {
 | 
						if (!$comment) {
 | 
				
			||||||
		$errors[] = no_field("form.field.ban_comment");
 | 
							$errors[] = no_field("form.field.ban_comment");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$existing_ban = ban_for_addr_($address,$link);
 | 
						$existing_ban = ban_for_addr_($address, $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( (!$banId && $existing_ban) ||
 | 
						if ((!$banId && $existing_ban) ||
 | 
				
			||||||
		( $banId && $existing_ban && $banId != $existing_ban['banid']) ) {
 | 
							($banId && $existing_ban && $banId != $existing_ban['banid'])) {
 | 
				
			||||||
		$errors[] = getlocal2("ban.error.duplicate",array($address,$existing_ban['banid']));
 | 
							$errors[] = getlocal2("ban.error.duplicate", array($address, $existing_ban['banid']));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( count($errors) == 0 ) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		$link = connect();
 | 
							$link = connect();
 | 
				
			||||||
		$utime = time() + $days * 24*60*60;
 | 
							$utime = time() + $days * 24 * 60 * 60;
 | 
				
			||||||
		if (!$banId) {
 | 
							if (!$banId) {
 | 
				
			||||||
			$query = sprintf(
 | 
								$query = sprintf(
 | 
				
			||||||
				"insert into ${mysqlprefix}chatban (dtmcreated,dtmtill,address,comment) values (CURRENT_TIMESTAMP,%s,'%s','%s')",
 | 
									"insert into ${mysqlprefix}chatban (dtmcreated,dtmtill,address,comment) values (CURRENT_TIMESTAMP,%s,'%s','%s')",
 | 
				
			||||||
				"FROM_UNIXTIME($utime)",
 | 
									"FROM_UNIXTIME($utime)",
 | 
				
			||||||
				mysql_real_escape_string($address,$link),
 | 
									mysql_real_escape_string($address, $link),
 | 
				
			||||||
				mysql_real_escape_string($comment,$link));
 | 
									mysql_real_escape_string($comment, $link));
 | 
				
			||||||
			perform_query($query,$link);
 | 
								perform_query($query, $link);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			$query = sprintf(
 | 
								$query = sprintf(
 | 
				
			||||||
				"update ${mysqlprefix}chatban set dtmtill = %s,address = '%s',comment = '%s' where banid = $banId",
 | 
									"update ${mysqlprefix}chatban set dtmtill = %s,address = '%s',comment = '%s' where banid = $banId",
 | 
				
			||||||
				"FROM_UNIXTIME($utime)",
 | 
									"FROM_UNIXTIME($utime)",
 | 
				
			||||||
				mysql_real_escape_string($address,$link),
 | 
									mysql_real_escape_string($address, $link),
 | 
				
			||||||
				mysql_real_escape_string($comment,$link));
 | 
									mysql_real_escape_string($comment, $link));
 | 
				
			||||||
			perform_query($query,$link);
 | 
								perform_query($query, $link);
 | 
				
			||||||
					}
 | 
							}
 | 
				
			||||||
		mysql_close($link);
 | 
							mysql_close($link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(!$threadid) {
 | 
							if (!$threadid) {
 | 
				
			||||||
			header("Location: $webimroot/operator/blocked.php");
 | 
								header("Location: $webimroot/operator/blocked.php");
 | 
				
			||||||
			exit;
 | 
								exit;
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
@ -93,24 +93,24 @@ if( isset($_POST['address']) ) {
 | 
				
			|||||||
		$page['formcomment'] = topage($comment);
 | 
							$page['formcomment'] = topage($comment);
 | 
				
			||||||
		$page['threadid'] = $threadid;
 | 
							$page['threadid'] = $threadid;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
} else if(isset($_GET['id'])) {
 | 
					} else if (isset($_GET['id'])) {
 | 
				
			||||||
	$banId = verifyparam( 'id', "/^\d{1,9}$/");
 | 
						$banId = verifyparam('id', "/^\d{1,9}$/");
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$ban = select_one_row("select banid,(unix_timestamp(dtmtill)-unix_timestamp(CURRENT_TIMESTAMP)) as days,address,comment from ${mysqlprefix}chatban where banid = $banId", $link);
 | 
						$ban = select_one_row("select banid,(unix_timestamp(dtmtill)-unix_timestamp(CURRENT_TIMESTAMP)) as days,address,comment from ${mysqlprefix}chatban where banid = $banId", $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $ban ) {
 | 
						if ($ban) {
 | 
				
			||||||
		$page['banId'] = topage($ban['banid']);
 | 
							$page['banId'] = topage($ban['banid']);
 | 
				
			||||||
		$page['formaddress'] = topage($ban['address']);
 | 
							$page['formaddress'] = topage($ban['address']);
 | 
				
			||||||
		$page['formdays'] = topage(round($ban['days']/86400));
 | 
							$page['formdays'] = topage(round($ban['days'] / 86400));
 | 
				
			||||||
		$page['formcomment'] = topage($ban['comment']);
 | 
							$page['formcomment'] = topage($ban['comment']);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$errors[] = "Wrong id";
 | 
							$errors[] = "Wrong id";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
} else if(isset($_GET['thread'])) {
 | 
					} else if (isset($_GET['thread'])) {
 | 
				
			||||||
	$threadid = verifyparam( 'thread', "/^\d{1,9}$/");
 | 
						$threadid = verifyparam('thread', "/^\d{1,9}$/");
 | 
				
			||||||
	$thread = thread_by_id($threadid);
 | 
						$thread = thread_by_id($threadid);
 | 
				
			||||||
	if( $thread ) {
 | 
						if ($thread) {
 | 
				
			||||||
		$page['thread'] = topage($thread['userName']);
 | 
							$page['thread'] = topage($thread['userName']);
 | 
				
			||||||
		$page['threadid'] = $threadid;
 | 
							$page['threadid'] = $threadid;
 | 
				
			||||||
		$page['formaddress'] = topage($thread['remote']);
 | 
							$page['formaddress'] = topage($thread['remote']);
 | 
				
			||||||
 | 
				
			|||||||
@ -32,22 +32,22 @@ setlocale(LC_TIME, getstring("time.locale"));
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$link = connect();
 | 
					$link = connect();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if( isset($_GET['act']) && $_GET['act'] == 'del' ) {
 | 
					if (isset($_GET['act']) && $_GET['act'] == 'del') {
 | 
				
			||||||
	$banId = isset($_GET['id']) ? $_GET['id'] : "";
 | 
						$banId = isset($_GET['id']) ? $_GET['id'] : "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !preg_match( "/^\d+$/", $banId )) {
 | 
						if (!preg_match("/^\d+$/", $banId)) {
 | 
				
			||||||
		$errors[] = "Cannot delete: wrong argument";
 | 
							$errors[] = "Cannot delete: wrong argument";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( count($errors) == 0 ) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		perform_query("delete from ${mysqlprefix}chatban where banid = $banId",$link);
 | 
							perform_query("delete from ${mysqlprefix}chatban where banid = $banId", $link);
 | 
				
			||||||
		header("Location: $webimroot/operator/blocked.php");
 | 
							header("Location: $webimroot/operator/blocked.php");
 | 
				
			||||||
		exit;
 | 
							exit;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$result = mysql_query("select banid,unix_timestamp(dtmtill) as till,address,comment from ${mysqlprefix}chatban", $link)
 | 
					$result = mysql_query("select banid,unix_timestamp(dtmtill) as till,address,comment from ${mysqlprefix}chatban", $link)
 | 
				
			||||||
	or die(' Query failed: ' .mysql_error());
 | 
					or die(' Query failed: ' . mysql_error());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$blockedList = array();
 | 
					$blockedList = array();
 | 
				
			||||||
while ($ban = mysql_fetch_array($result, MYSQL_ASSOC)) {
 | 
					while ($ban = mysql_fetch_array($result, MYSQL_ASSOC)) {
 | 
				
			||||||
 | 
				
			|||||||
@ -31,28 +31,29 @@ loadsettings();
 | 
				
			|||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
$page = array();
 | 
					$page = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function load_canned_messages($locale, $groupid) {
 | 
					function load_canned_messages($locale, $groupid)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$query = "select id, vcvalue from ${mysqlprefix}chatresponses ".
 | 
						$query = "select id, vcvalue from ${mysqlprefix}chatresponses " .
 | 
				
			||||||
			 "where locale = '".$locale."' AND (".
 | 
								 "where locale = '" . $locale . "' AND (" .
 | 
				
			||||||
			 ($groupid
 | 
								 ($groupid
 | 
				
			||||||
			 		? "groupid = $groupid" 
 | 
										 ? "groupid = $groupid"
 | 
				
			||||||
			 		: "groupid is NULL OR groupid = 0").
 | 
										 : "groupid is NULL OR groupid = 0") .
 | 
				
			||||||
			 ") order by vcvalue";
 | 
								 ") order by vcvalue";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$result = select_multi_assoc($query, $link);
 | 
						$result = select_multi_assoc($query, $link);
 | 
				
			||||||
	if(!$groupid && count($result) == 0) {
 | 
						if (!$groupid && count($result) == 0) {
 | 
				
			||||||
		foreach(explode("\n", getstring_('chat.predefined_answers', $locale)) as $answer) {
 | 
							foreach (explode("\n", getstring_('chat.predefined_answers', $locale)) as $answer) {
 | 
				
			||||||
			$result[] = array('id' => '', 'vcvalue' => $answer);
 | 
								$result[] = array('id' => '', 'vcvalue' => $answer);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if(count($result) > 0) {
 | 
							if (count($result) > 0) {
 | 
				
			||||||
			$updatequery = "insert into ${mysqlprefix}chatresponses (vcvalue,locale,groupid) values ";
 | 
								$updatequery = "insert into ${mysqlprefix}chatresponses (vcvalue,locale,groupid) values ";
 | 
				
			||||||
			for($i=0;$i<count($result);$i++) {
 | 
								for ($i = 0; $i < count($result); $i++) {
 | 
				
			||||||
				if($i > 0) {
 | 
									if ($i > 0) {
 | 
				
			||||||
					$updatequery .= ", ";
 | 
										$updatequery .= ", ";
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				$updatequery .= "('".mysql_real_escape_string($result[$i]['vcvalue'], $link)."','$locale', NULL)";
 | 
									$updatequery .= "('" . mysql_real_escape_string($result[$i]['vcvalue'], $link) . "','$locale', NULL)";
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			perform_query($updatequery, $link);
 | 
								perform_query($updatequery, $link);
 | 
				
			||||||
			$result = select_multi_assoc($query, $link);
 | 
								$result = select_multi_assoc($query, $link);
 | 
				
			||||||
@ -66,24 +67,24 @@ function load_canned_messages($locale, $groupid) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$all_locales = get_available_locales();
 | 
					$all_locales = get_available_locales();
 | 
				
			||||||
$locales_with_label = array();
 | 
					$locales_with_label = array();
 | 
				
			||||||
foreach($all_locales as $id) {
 | 
					foreach ($all_locales as $id) {
 | 
				
			||||||
	$locales_with_label[] = array('id' => $id, 'name' => getlocal_($id,"names"));
 | 
						$locales_with_label[] = array('id' => $id, 'name' => getlocal_($id, "names"));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
$page['locales'] = $locales_with_label;
 | 
					$page['locales'] = $locales_with_label;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$lang = verifyparam("lang", "/^[\w-]{2,5}$/", "");
 | 
					$lang = verifyparam("lang", "/^[\w-]{2,5}$/", "");
 | 
				
			||||||
if( !$lang || !in_array($lang,$all_locales) ) {
 | 
					if (!$lang || !in_array($lang, $all_locales)) {
 | 
				
			||||||
	$lang = in_array($current_locale,$all_locales) ? $current_locale : $all_locales[0];
 | 
						$lang = in_array($current_locale, $all_locales) ? $current_locale : $all_locales[0];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# groups
 | 
					# groups
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$groupid = "";
 | 
					$groupid = "";
 | 
				
			||||||
if($settings['enablegroups'] == '1') {
 | 
					if ($settings['enablegroups'] == '1') {
 | 
				
			||||||
	$groupid = verifyparam( "group", "/^\d{0,8}$/", "");
 | 
						$groupid = verifyparam("group", "/^\d{0,8}$/", "");
 | 
				
			||||||
	if($groupid) {
 | 
						if ($groupid) {
 | 
				
			||||||
		$group = group_by_id($groupid);
 | 
							$group = group_by_id($groupid);
 | 
				
			||||||
		if(!$group) {
 | 
							if (!$group) {
 | 
				
			||||||
			$errors[] = getlocal("page.group.no_such");
 | 
								$errors[] = getlocal("page.group.no_such");
 | 
				
			||||||
			$groupid = "";
 | 
								$groupid = "";
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -94,23 +95,23 @@ if($settings['enablegroups'] == '1') {
 | 
				
			|||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
	$page['groups'] = array();
 | 
						$page['groups'] = array();
 | 
				
			||||||
	$page['groups'][] = array('groupid' => '', 'vclocalname' => getlocal("page.gen_button.default_group"));
 | 
						$page['groups'][] = array('groupid' => '', 'vclocalname' => getlocal("page.gen_button.default_group"));
 | 
				
			||||||
	foreach($allgroups as $g) {
 | 
						foreach ($allgroups as $g) {
 | 
				
			||||||
		$page['groups'][] = $g;
 | 
							$page['groups'][] = $g;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# delete
 | 
					# delete
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if(isset($_GET['act']) && $_GET['act'] == 'delete') {
 | 
					if (isset($_GET['act']) && $_GET['act'] == 'delete') {
 | 
				
			||||||
	$key = isset($_GET['key']) ? $_GET['key'] : "";
 | 
						$key = isset($_GET['key']) ? $_GET['key'] : "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !preg_match( "/^\d+$/", $key )) {
 | 
						if (!preg_match("/^\d+$/", $key)) {
 | 
				
			||||||
		$errors[] = "Wrong key";
 | 
							$errors[] = "Wrong key";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( count($errors) == 0 ) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		$link = connect();
 | 
							$link = connect();
 | 
				
			||||||
		perform_query("delete from ${mysqlprefix}chatresponses where id = $key",$link);
 | 
							perform_query("delete from ${mysqlprefix}chatresponses where id = $key", $link);
 | 
				
			||||||
		mysql_close($link);
 | 
							mysql_close($link);
 | 
				
			||||||
		header("Location: $webimroot/operator/canned.php?lang=$lang&group=$groupid");
 | 
							header("Location: $webimroot/operator/canned.php?lang=$lang&group=$groupid");
 | 
				
			||||||
		exit;
 | 
							exit;
 | 
				
			||||||
 | 
				
			|||||||
@ -23,7 +23,8 @@ require_once('../libs/common.php');
 | 
				
			|||||||
require_once('../libs/operator.php');
 | 
					require_once('../libs/operator.php');
 | 
				
			||||||
require_once('../libs/pagination.php');
 | 
					require_once('../libs/pagination.php');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function load_message($key) {
 | 
					function load_message($key)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$result = select_one_row("select vcvalue from ${mysqlprefix}chatresponses where id = $key", $link);
 | 
						$result = select_one_row("select vcvalue from ${mysqlprefix}chatresponses where id = $key", $link);
 | 
				
			||||||
@ -31,20 +32,22 @@ function load_message($key) {
 | 
				
			|||||||
	return $result ? $result['vcvalue'] : null;
 | 
						return $result ? $result['vcvalue'] : null;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function save_message($key,$message) {
 | 
					function save_message($key, $message)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	perform_query("update ${mysqlprefix}chatresponses set vcvalue = '".mysql_real_escape_string($message,$link)."' ".
 | 
						perform_query("update ${mysqlprefix}chatresponses set vcvalue = '" . mysql_real_escape_string($message, $link) . "' " .
 | 
				
			||||||
				"where id = $key", $link);
 | 
									  "where id = $key", $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function add_message($locale,$groupid,$message) {
 | 
					function add_message($locale, $groupid, $message)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	perform_query("insert into ${mysqlprefix}chatresponses (locale,groupid,vcvalue) values ('$locale',".
 | 
						perform_query("insert into ${mysqlprefix}chatresponses (locale,groupid,vcvalue) values ('$locale'," .
 | 
				
			||||||
				($groupid ? "$groupid, " : "null, ").
 | 
									  ($groupid ? "$groupid, " : "null, ") .
 | 
				
			||||||
				"'".mysql_real_escape_string($message,$link)."')", $link);
 | 
									  "'" . mysql_real_escape_string($message, $link) . "')", $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -56,9 +59,9 @@ $stringid = verifyparam("key", "/^\d{0,9}$/", "");
 | 
				
			|||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
$page = array();
 | 
					$page = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if($stringid) {
 | 
					if ($stringid) {
 | 
				
			||||||
	$message = load_message($stringid);
 | 
						$message = load_message($stringid);
 | 
				
			||||||
	if(!$message) {
 | 
						if (!$message) {
 | 
				
			||||||
		$errors[] = getlocal("cannededit.no_such");
 | 
							$errors[] = getlocal("cannededit.no_such");
 | 
				
			||||||
		$stringid = "";
 | 
							$stringid = "";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -66,19 +69,19 @@ if($stringid) {
 | 
				
			|||||||
	$message = "";
 | 
						$message = "";
 | 
				
			||||||
	$page['locale'] = verifyparam("lang", "/^[\w-]{2,5}$/", "");
 | 
						$page['locale'] = verifyparam("lang", "/^[\w-]{2,5}$/", "");
 | 
				
			||||||
	$page['groupid'] = "";
 | 
						$page['groupid'] = "";
 | 
				
			||||||
	if($settings['enablegroups'] == '1') {
 | 
						if ($settings['enablegroups'] == '1') {
 | 
				
			||||||
		$page['groupid'] = verifyparam( "group", "/^\d{0,8}$/");
 | 
							$page['groupid'] = verifyparam("group", "/^\d{0,8}$/");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if(isset($_POST['message'])) {
 | 
					if (isset($_POST['message'])) {
 | 
				
			||||||
	$message = getparam('message');
 | 
						$message = getparam('message');
 | 
				
			||||||
	if(!$message) {
 | 
						if (!$message) {
 | 
				
			||||||
		$errors[] = no_field("form.field.message");
 | 
							$errors[] = no_field("form.field.message");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(count($errors) == 0) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		if($stringid) {
 | 
							if ($stringid) {
 | 
				
			||||||
			save_message($stringid, $message);
 | 
								save_message($stringid, $message);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			add_message($page['locale'], $page['groupid'], $message);
 | 
								add_message($page['locale'], $page['groupid'], $message);
 | 
				
			||||||
 | 
				
			|||||||
@ -29,30 +29,30 @@ $page = array('agentId' => '');
 | 
				
			|||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$options = array(
 | 
					$options = array(
 | 
				
			||||||
		'enableban', 'usercanchangename', 'enablegroups', 'enablestatistics', 'enablejabber',
 | 
						'enableban', 'usercanchangename', 'enablegroups', 'enablestatistics', 'enablejabber',
 | 
				
			||||||
		'enablessl', 'forcessl',  
 | 
						'enablessl', 'forcessl',
 | 
				
			||||||
		'enablepresurvey', 'surveyaskmail', 'surveyaskgroup', 'surveyaskmessage',
 | 
						'enablepresurvey', 'surveyaskmail', 'surveyaskgroup', 'surveyaskmessage',
 | 
				
			||||||
		'enablepopupnotification', 'showonlineoperators',
 | 
						'enablepopupnotification', 'showonlineoperators',
 | 
				
			||||||
		'enablecaptcha');
 | 
						'enablecaptcha');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
loadsettings();
 | 
					loadsettings();
 | 
				
			||||||
if($settings['featuresversion'] != $featuresversion) {
 | 
					if ($settings['featuresversion'] != $featuresversion) {
 | 
				
			||||||
	$settings['featuresversion'] = $featuresversion;
 | 
						$settings['featuresversion'] = $featuresversion;
 | 
				
			||||||
	update_settings();
 | 
						update_settings();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
$params = array();
 | 
					$params = array();
 | 
				
			||||||
foreach($options as $opt) {
 | 
					foreach ($options as $opt) {
 | 
				
			||||||
	$params[$opt] = $settings[$opt];
 | 
						$params[$opt] = $settings[$opt];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if (isset($_POST['sent'])) {
 | 
					if (isset($_POST['sent'])) {
 | 
				
			||||||
	if (is_capable($can_administrate, $operator)) {
 | 
						if (is_capable($can_administrate, $operator)) {
 | 
				
			||||||
		foreach($options as $opt) {
 | 
							foreach ($options as $opt) {
 | 
				
			||||||
    		$settings[$opt] = verifyparam($opt,"/^on$/", "") == "on" ? "1" : "0";
 | 
								$settings[$opt] = verifyparam($opt, "/^on$/", "") == "on" ? "1" : "0";
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
    	update_settings();
 | 
							update_settings();
 | 
				
			||||||
	    header("Location: $webimroot/operator/features.php?stored");
 | 
							header("Location: $webimroot/operator/features.php?stored");
 | 
				
			||||||
	    exit;
 | 
							exit;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$errors[] = "Not an administrator";
 | 
							$errors[] = "Not an administrator";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -60,8 +60,8 @@ if (isset($_POST['sent'])) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$page['canmodify'] = is_capable($can_administrate, $operator);
 | 
					$page['canmodify'] = is_capable($can_administrate, $operator);
 | 
				
			||||||
$page['stored'] = isset($_GET['stored']);
 | 
					$page['stored'] = isset($_GET['stored']);
 | 
				
			||||||
foreach($options as $opt) {
 | 
					foreach ($options as $opt) {
 | 
				
			||||||
   	$page["form$opt"] = $params[$opt] == "1";
 | 
						$page["form$opt"] = $params[$opt] == "1";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
prepare_menu($operator);
 | 
					prepare_menu($operator);
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,7 @@ loadsettings();
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$imageLocales = get_image_locales_map("../locales");
 | 
					$imageLocales = get_image_locales_map("../locales");
 | 
				
			||||||
$image = verifyparam(isset($_GET['image']) ? "image" : "i", "/^\w+$/", "webim");
 | 
					$image = verifyparam(isset($_GET['image']) ? "image" : "i", "/^\w+$/", "webim");
 | 
				
			||||||
if(!isset($imageLocales[$image])) {
 | 
					if (!isset($imageLocales[$image])) {
 | 
				
			||||||
	$errors[] = "Unknown image: $image";
 | 
						$errors[] = "Unknown image: $image";
 | 
				
			||||||
	$avail = array_keys($imageLocales);
 | 
						$avail = array_keys($imageLocales);
 | 
				
			||||||
	$image = $avail[0];
 | 
						$image = $avail[0];
 | 
				
			||||||
@ -37,31 +37,31 @@ if(!isset($imageLocales[$image])) {
 | 
				
			|||||||
$image_locales = $imageLocales[$image];
 | 
					$image_locales = $imageLocales[$image];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$stylelist = get_style_list("../styles");
 | 
					$stylelist = get_style_list("../styles");
 | 
				
			||||||
$style = verifyparam("style","/^\w*$/", "");
 | 
					$style = verifyparam("style", "/^\w*$/", "");
 | 
				
			||||||
if($style && !in_array($style, $stylelist)) {
 | 
					if ($style && !in_array($style, $stylelist)) {
 | 
				
			||||||
	$style = "";
 | 
						$style = "";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$groupid = verifyparam_groupid("group");
 | 
					$groupid = verifyparam_groupid("group");
 | 
				
			||||||
$showhost = verifyparam("hostname","/^on$/", "") == "on";
 | 
					$showhost = verifyparam("hostname", "/^on$/", "") == "on";
 | 
				
			||||||
$forcesecure = verifyparam("secure","/^on$/", "") == "on";
 | 
					$forcesecure = verifyparam("secure", "/^on$/", "") == "on";
 | 
				
			||||||
$modsecurity = verifyparam("modsecurity","/^on$/", "") == "on";
 | 
					$modsecurity = verifyparam("modsecurity", "/^on$/", "") == "on";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$lang = verifyparam("lang", "/^[\w-]{2,5}$/", "");
 | 
					$lang = verifyparam("lang", "/^[\w-]{2,5}$/", "");
 | 
				
			||||||
if( !$lang || !in_array($lang,$image_locales) )
 | 
					if (!$lang || !in_array($lang, $image_locales))
 | 
				
			||||||
	$lang = in_array($current_locale,$image_locales) ? $current_locale : $image_locales[0];
 | 
						$lang = in_array($current_locale, $image_locales) ? $current_locale : $image_locales[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$file = "../locales/${lang}/button/${image}_on.gif";
 | 
					$file = "../locales/${lang}/button/${image}_on.gif";
 | 
				
			||||||
$size = get_gifimage_size($file);
 | 
					$size = get_gifimage_size($file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$imagehref = get_app_location($showhost,$forcesecure)."/b.php?i=$image&lang=$lang";
 | 
					$imagehref = get_app_location($showhost, $forcesecure) . "/b.php?i=$image&lang=$lang";
 | 
				
			||||||
if($groupid) {
 | 
					if ($groupid) {
 | 
				
			||||||
	$imagehref .= "&group=$groupid";
 | 
						$imagehref .= "&group=$groupid";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
$message = get_image($imagehref,$size[0],$size[1]);
 | 
					$message = get_image($imagehref, $size[0], $size[1]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page = array();
 | 
					$page = array();
 | 
				
			||||||
$page['buttonCode'] = generate_button("",$lang,$style,$groupid,$message,$showhost,$forcesecure,$modsecurity);
 | 
					$page['buttonCode'] = generate_button("", $lang, $style, $groupid, $message, $showhost, $forcesecure, $modsecurity);
 | 
				
			||||||
$page['availableImages'] = array_keys($imageLocales);
 | 
					$page['availableImages'] = array_keys($imageLocales);
 | 
				
			||||||
$page['availableLocales'] = $image_locales;
 | 
					$page['availableLocales'] = $image_locales;
 | 
				
			||||||
$page['availableStyles'] = $stylelist;
 | 
					$page['availableStyles'] = $stylelist;
 | 
				
			||||||
 | 
				
			|||||||
@ -28,26 +28,26 @@ $operator = check_login();
 | 
				
			|||||||
loadsettings();
 | 
					loadsettings();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$stylelist = get_style_list("../styles");
 | 
					$stylelist = get_style_list("../styles");
 | 
				
			||||||
$style = verifyparam("style","/^\w*$/", "");
 | 
					$style = verifyparam("style", "/^\w*$/", "");
 | 
				
			||||||
if($style && !in_array($style, $stylelist)) {
 | 
					if ($style && !in_array($style, $stylelist)) {
 | 
				
			||||||
	$style = "";
 | 
						$style = "";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$groupid = verifyparam_groupid("group");
 | 
					$groupid = verifyparam_groupid("group");
 | 
				
			||||||
$showhost = verifyparam("hostname","/^on$/", "") == "on";
 | 
					$showhost = verifyparam("hostname", "/^on$/", "") == "on";
 | 
				
			||||||
$forcesecure = verifyparam("secure","/^on$/", "") == "on";
 | 
					$forcesecure = verifyparam("secure", "/^on$/", "") == "on";
 | 
				
			||||||
$modsecurity = verifyparam("modsecurity","/^on$/", "") == "on";
 | 
					$modsecurity = verifyparam("modsecurity", "/^on$/", "") == "on";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$allLocales = get_available_locales();
 | 
					$allLocales = get_available_locales();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$lang = verifyparam("lang", "/^[\w-]{2,5}$/", "");
 | 
					$lang = verifyparam("lang", "/^[\w-]{2,5}$/", "");
 | 
				
			||||||
if( !$lang || !in_array($lang,$allLocales) )
 | 
					if (!$lang || !in_array($lang, $allLocales))
 | 
				
			||||||
	$lang = in_array($current_locale,$allLocales) ? $current_locale : $allLocales[0];
 | 
						$lang = in_array($current_locale, $allLocales) ? $current_locale : $allLocales[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$message = "Click to chat"; // TODO
 | 
					$message = "Click to chat"; // TODO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page = array();
 | 
					$page = array();
 | 
				
			||||||
$page['buttonCode'] = generate_button("",$lang,$style,$groupid,$message,$showhost,$forcesecure,$modsecurity);
 | 
					$page['buttonCode'] = generate_button("", $lang, $style, $groupid, $message, $showhost, $forcesecure, $modsecurity);
 | 
				
			||||||
$page['availableLocales'] = $allLocales;
 | 
					$page['availableLocales'] = $allLocales;
 | 
				
			||||||
$page['availableStyles'] = $stylelist;
 | 
					$page['availableStyles'] = $stylelist;
 | 
				
			||||||
$page['groups'] = get_groups_list();
 | 
					$page['groups'] = get_groups_list();
 | 
				
			||||||
 | 
				
			|||||||
@ -29,34 +29,37 @@ $page = array('grid' => '');
 | 
				
			|||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
$groupid = '';
 | 
					$groupid = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function group_by_name($name) {
 | 
					function group_by_name($name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$group = select_one_row(
 | 
						$group = select_one_row(
 | 
				
			||||||
		 "select * from ${mysqlprefix}chatgroup where vclocalname = '".mysql_real_escape_string($name)."'", $link );
 | 
							"select * from ${mysqlprefix}chatgroup where vclocalname = '" . mysql_real_escape_string($name) . "'", $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
	return $group;
 | 
						return $group;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function create_group($name,$descr,$commonname,$commondescr) {
 | 
					function create_group($name, $descr, $commonname, $commondescr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$query = sprintf(
 | 
						$query = sprintf(
 | 
				
			||||||
		"insert into ${mysqlprefix}chatgroup (vclocalname,vclocaldescription,vccommonname,vccommondescription) values ('%s','%s','%s','%s')",
 | 
							"insert into ${mysqlprefix}chatgroup (vclocalname,vclocaldescription,vccommonname,vccommondescription) values ('%s','%s','%s','%s')",
 | 
				
			||||||
			mysql_real_escape_string($name),
 | 
							mysql_real_escape_string($name),
 | 
				
			||||||
			mysql_real_escape_string($descr),
 | 
							mysql_real_escape_string($descr),
 | 
				
			||||||
			mysql_real_escape_string($commonname),
 | 
							mysql_real_escape_string($commonname),
 | 
				
			||||||
			mysql_real_escape_string($commondescr));
 | 
							mysql_real_escape_string($commondescr));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	perform_query($query,$link);
 | 
						perform_query($query, $link);
 | 
				
			||||||
	$id = mysql_insert_id($link);
 | 
						$id = mysql_insert_id($link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$newdep = select_one_row("select * from ${mysqlprefix}chatgroup where groupid = $id", $link );
 | 
						$newdep = select_one_row("select * from ${mysqlprefix}chatgroup where groupid = $id", $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
	return $newdep;
 | 
						return $newdep;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function update_group($groupid,$name,$descr,$commonname,$commondescr) {
 | 
					function update_group($groupid, $name, $descr, $commonname, $commondescr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$query = sprintf(
 | 
						$query = sprintf(
 | 
				
			||||||
@ -65,35 +68,35 @@ function update_group($groupid,$name,$descr,$commonname,$commondescr) {
 | 
				
			|||||||
		mysql_real_escape_string($descr),
 | 
							mysql_real_escape_string($descr),
 | 
				
			||||||
		mysql_real_escape_string($commonname),
 | 
							mysql_real_escape_string($commonname),
 | 
				
			||||||
		mysql_real_escape_string($commondescr),
 | 
							mysql_real_escape_string($commondescr),
 | 
				
			||||||
		$groupid );
 | 
							$groupid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	perform_query($query,$link);
 | 
						perform_query($query, $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if( isset($_POST['name'])) {
 | 
					if (isset($_POST['name'])) {
 | 
				
			||||||
	$groupid = verifyparam( "gid", "/^(\d{1,9})?$/", "");
 | 
						$groupid = verifyparam("gid", "/^(\d{1,9})?$/", "");
 | 
				
			||||||
	$name = getparam('name');
 | 
						$name = getparam('name');
 | 
				
			||||||
	$description = getparam('description');
 | 
						$description = getparam('description');
 | 
				
			||||||
	$commonname = getparam('commonname');
 | 
						$commonname = getparam('commonname');
 | 
				
			||||||
	$commondescription = getparam('commondescription');
 | 
						$commondescription = getparam('commondescription');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !$name )
 | 
						if (!$name)
 | 
				
			||||||
		$errors[] = no_field("form.field.groupname");
 | 
							$errors[] = no_field("form.field.groupname");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$existing_group = group_by_name($name);
 | 
						$existing_group = group_by_name($name);
 | 
				
			||||||
	if( (!$groupid && $existing_group) ||
 | 
						if ((!$groupid && $existing_group) ||
 | 
				
			||||||
		( $groupid && $existing_group && $groupid != $existing_group['groupid']) )
 | 
							($groupid && $existing_group && $groupid != $existing_group['groupid']))
 | 
				
			||||||
		$errors[] = getlocal("page.group.duplicate_name");
 | 
							$errors[] = getlocal("page.group.duplicate_name");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( count($errors) == 0 ) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		if (!$groupid) {
 | 
							if (!$groupid) {
 | 
				
			||||||
			$newdep = create_group($name,$description,$commonname,$commondescription);
 | 
								$newdep = create_group($name, $description, $commonname, $commondescription);
 | 
				
			||||||
			header("Location: $webimroot/operator/groupmembers.php?gid=".$newdep['groupid']);
 | 
								header("Location: $webimroot/operator/groupmembers.php?gid=" . $newdep['groupid']);
 | 
				
			||||||
			exit;
 | 
								exit;
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			update_group($groupid,$name,$description,$commonname,$commondescription);
 | 
								update_group($groupid, $name, $description, $commonname, $commondescription);
 | 
				
			||||||
			header("Location: $webimroot/operator/group.php?gid=$groupid&stored");
 | 
								header("Location: $webimroot/operator/group.php?gid=$groupid&stored");
 | 
				
			||||||
			exit;
 | 
								exit;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -105,11 +108,11 @@ if( isset($_POST['name'])) {
 | 
				
			|||||||
		$page['grid'] = topage($groupid);
 | 
							$page['grid'] = topage($groupid);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} else if( isset($_GET['gid']) ) {
 | 
					} else if (isset($_GET['gid'])) {
 | 
				
			||||||
	$groupid = verifyparam( 'gid', "/^\d{1,9}$/");
 | 
						$groupid = verifyparam('gid', "/^\d{1,9}$/");
 | 
				
			||||||
	$group = group_by_id($groupid);
 | 
						$group = group_by_id($groupid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !$group ) {
 | 
						if (!$group) {
 | 
				
			||||||
		$errors[] = getlocal("page.group.no_such");
 | 
							$errors[] = getlocal("page.group.no_such");
 | 
				
			||||||
		$page['grid'] = topage($groupid);
 | 
							$page['grid'] = topage($groupid);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
 | 
				
			|||||||
@ -25,7 +25,8 @@ require_once('../libs/groups.php');
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$operator = check_login();
 | 
					$operator = check_login();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_group_members($groupid) {
 | 
					function get_group_members($groupid)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$query = "select operatorid from ${mysqlprefix}chatgroupoperator where groupid = $groupid";
 | 
						$query = "select operatorid from ${mysqlprefix}chatgroupoperator where groupid = $groupid";
 | 
				
			||||||
@ -34,17 +35,19 @@ function get_group_members($groupid) {
 | 
				
			|||||||
	return $result;
 | 
						return $result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function update_group_members($groupid,$newvalue) {
 | 
					function update_group_members($groupid, $newvalue)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	perform_query("delete from ${mysqlprefix}chatgroupoperator where groupid = $groupid", $link);
 | 
						perform_query("delete from ${mysqlprefix}chatgroupoperator where groupid = $groupid", $link);
 | 
				
			||||||
	foreach($newvalue as $opid) {
 | 
						foreach ($newvalue as $opid) {
 | 
				
			||||||
		perform_query("insert into ${mysqlprefix}chatgroupoperator (groupid, operatorid) values ($groupid,$opid)", $link);
 | 
							perform_query("insert into ${mysqlprefix}chatgroupoperator (groupid, operatorid) values ($groupid,$opid)", $link);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_operators() {
 | 
					function get_operators()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -54,21 +57,21 @@ function get_operators() {
 | 
				
			|||||||
	return $result;
 | 
						return $result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$groupid = verifyparam( "gid","/^\d{1,9}$/");
 | 
					$groupid = verifyparam("gid", "/^\d{1,9}$/");
 | 
				
			||||||
$page = array('groupid' => $groupid);
 | 
					$page = array('groupid' => $groupid);
 | 
				
			||||||
$page['operators'] = get_operators();
 | 
					$page['operators'] = get_operators();
 | 
				
			||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$group = group_by_id($groupid);
 | 
					$group = group_by_id($groupid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if( !$group ) {
 | 
					if (!$group) {
 | 
				
			||||||
	$errors[] = getlocal("page.group.no_such");
 | 
						$errors[] = getlocal("page.group.no_such");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} else if( isset($_POST['gid']) ) {
 | 
					} else if (isset($_POST['gid'])) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$new_members = array();
 | 
						$new_members = array();
 | 
				
			||||||
	foreach($page['operators'] as $op) {
 | 
						foreach ($page['operators'] as $op) {
 | 
				
			||||||
		if( verifyparam("op".$op['operatorid'],"/^on$/", "") == "on") {
 | 
							if (verifyparam("op" . $op['operatorid'], "/^on$/", "") == "on") {
 | 
				
			||||||
			$new_members[] = $op['operatorid'];
 | 
								$new_members[] = $op['operatorid'];
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -81,7 +84,7 @@ if( !$group ) {
 | 
				
			|||||||
$page['formop'] = array();
 | 
					$page['formop'] = array();
 | 
				
			||||||
$page['currentgroup'] = $group ? topage(htmlspecialchars($group['vclocalname'])) : "";
 | 
					$page['currentgroup'] = $group ? topage(htmlspecialchars($group['vclocalname'])) : "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
foreach(get_group_members($groupid) as $rel) {
 | 
					foreach (get_group_members($groupid) as $rel) {
 | 
				
			||||||
	$page['formop'][] = $rel['operatorid'];
 | 
						$page['formop'][] = $rel['operatorid'];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -24,35 +24,37 @@ require_once('../libs/operator.php');
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$operator = check_login();
 | 
					$operator = check_login();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if( isset($_GET['act']) && $_GET['act'] == 'del' ) {
 | 
					if (isset($_GET['act']) && $_GET['act'] == 'del') {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$groupid = isset($_GET['gid']) ? $_GET['gid'] : "";
 | 
						$groupid = isset($_GET['gid']) ? $_GET['gid'] : "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !preg_match( "/^\d+$/", $groupid )) {
 | 
						if (!preg_match("/^\d+$/", $groupid)) {
 | 
				
			||||||
		$errors[] = "Cannot delete: wrong argument";
 | 
							$errors[] = "Cannot delete: wrong argument";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !is_capable($can_administrate, $operator)) {
 | 
						if (!is_capable($can_administrate, $operator)) {
 | 
				
			||||||
		$errors[] = "You are not allowed to remove groups";
 | 
							$errors[] = "You are not allowed to remove groups";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( count($errors) == 0 ) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		$link = connect();
 | 
							$link = connect();
 | 
				
			||||||
		perform_query("delete from ${mysqlprefix}chatgroup where groupid = $groupid",$link);
 | 
							perform_query("delete from ${mysqlprefix}chatgroup where groupid = $groupid", $link);
 | 
				
			||||||
		perform_query("delete from ${mysqlprefix}chatgroupoperator where groupid = $groupid",$link);
 | 
							perform_query("delete from ${mysqlprefix}chatgroupoperator where groupid = $groupid", $link);
 | 
				
			||||||
		perform_query("update ${mysqlprefix}chatthread set groupid = 0 where groupid = $groupid",$link);
 | 
							perform_query("update ${mysqlprefix}chatthread set groupid = 0 where groupid = $groupid", $link);
 | 
				
			||||||
		mysql_close($link);
 | 
							mysql_close($link);
 | 
				
			||||||
		header("Location: $webimroot/operator/groups.php");
 | 
							header("Location: $webimroot/operator/groups.php");
 | 
				
			||||||
		exit;
 | 
							exit;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function is_online($group) {
 | 
					function is_online($group)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings;
 | 
						global $settings;
 | 
				
			||||||
	return $group['ilastseen'] !== NULL && $group['ilastseen'] < $settings['online_timeout'] ? "1" : "";
 | 
						return $group['ilastseen'] !== NULL && $group['ilastseen'] < $settings['online_timeout'] ? "1" : "";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function is_away($group) {
 | 
					function is_away($group)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $settings;
 | 
						global $settings;
 | 
				
			||||||
	return $group['ilastseenaway'] !== NULL && $group['ilastseenaway'] < $settings['online_timeout'] ? "1" : "";
 | 
						return $group['ilastseenaway'] !== NULL && $group['ilastseenaway'] < $settings['online_timeout'] ? "1" : "";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -33,11 +33,11 @@ setlocale(LC_TIME, getstring("time.locale"));
 | 
				
			|||||||
$page = array();
 | 
					$page = array();
 | 
				
			||||||
$query = isset($_GET['q']) ? myiconv(getoutputenc(), $webim_encoding, $_GET['q']) : false;
 | 
					$query = isset($_GET['q']) ? myiconv(getoutputenc(), $webim_encoding, $_GET['q']) : false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if($query !== false) {
 | 
					if ($query !== false) {
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$result = mysql_query("select ${mysqlprefix}chatgroup.groupid as groupid, vclocalname ".
 | 
						$result = mysql_query("select ${mysqlprefix}chatgroup.groupid as groupid, vclocalname " .
 | 
				
			||||||
			 "from ${mysqlprefix}chatgroup order by vclocalname", $link);
 | 
											  "from ${mysqlprefix}chatgroup order by vclocalname", $link);
 | 
				
			||||||
	$groupName = array();
 | 
						$groupName = array();
 | 
				
			||||||
	while ($group = mysql_fetch_array($result, MYSQL_ASSOC)) {
 | 
						while ($group = mysql_fetch_array($result, MYSQL_ASSOC)) {
 | 
				
			||||||
		$groupName[$group['groupid']] = $group['vclocalname'];
 | 
							$groupName[$group['groupid']] = $group['vclocalname'];
 | 
				
			||||||
@ -45,18 +45,18 @@ if($query !== false) {
 | 
				
			|||||||
	mysql_free_result($result);
 | 
						mysql_free_result($result);
 | 
				
			||||||
	$page['groupName'] = $groupName;
 | 
						$page['groupName'] = $groupName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$escapedQuery = mysql_real_escape_string($query,$link);
 | 
						$escapedQuery = mysql_real_escape_string($query, $link);
 | 
				
			||||||
	select_with_pagintation("DISTINCT unix_timestamp(${mysqlprefix}chatthread.dtmcreated) as created, ".
 | 
						select_with_pagintation("DISTINCT unix_timestamp(${mysqlprefix}chatthread.dtmcreated) as created, " .
 | 
				
			||||||
    	 "unix_timestamp(${mysqlprefix}chatthread.dtmmodified) as modified, ${mysqlprefix}chatthread.threadid, ".
 | 
												"unix_timestamp(${mysqlprefix}chatthread.dtmmodified) as modified, ${mysqlprefix}chatthread.threadid, " .
 | 
				
			||||||
		 "${mysqlprefix}chatthread.remote, ${mysqlprefix}chatthread.agentName, ${mysqlprefix}chatthread.userName, groupid, ".
 | 
												"${mysqlprefix}chatthread.remote, ${mysqlprefix}chatthread.agentName, ${mysqlprefix}chatthread.userName, groupid, " .
 | 
				
			||||||
		 "messageCount as size",
 | 
												"messageCount as size",
 | 
				
			||||||
		 "${mysqlprefix}chatthread, ${mysqlprefix}chatmessage",
 | 
												"${mysqlprefix}chatthread, ${mysqlprefix}chatmessage",
 | 
				
			||||||
		 array(
 | 
												array(
 | 
				
			||||||
		 	"${mysqlprefix}chatmessage.threadid = ${mysqlprefix}chatthread.threadid",
 | 
													 "${mysqlprefix}chatmessage.threadid = ${mysqlprefix}chatthread.threadid",
 | 
				
			||||||
		 	"((${mysqlprefix}chatthread.userName LIKE '%%$escapedQuery%%') or (${mysqlprefix}chatmessage.tmessage LIKE '%%$escapedQuery%%'))"
 | 
													 "((${mysqlprefix}chatthread.userName LIKE '%%$escapedQuery%%') or (${mysqlprefix}chatmessage.tmessage LIKE '%%$escapedQuery%%'))"
 | 
				
			||||||
		 ),
 | 
												),
 | 
				
			||||||
		 "order by created DESC",
 | 
												"order by created DESC",
 | 
				
			||||||
		 "DISTINCT ${mysqlprefix}chatthread.dtmcreated", $link);
 | 
												"DISTINCT ${mysqlprefix}chatthread.dtmcreated", $link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -23,21 +23,21 @@ require_once('../libs/common.php');
 | 
				
			|||||||
require_once('../libs/operator.php');
 | 
					require_once('../libs/operator.php');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
$page = array( 'formisRemember' => true, 'version' => $version);
 | 
					$page = array('formisRemember' => true, 'version' => $version);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if( isset($_POST['login']) && isset($_POST['password']) ) {
 | 
					if (isset($_POST['login']) && isset($_POST['password'])) {
 | 
				
			||||||
	$login = getparam('login');
 | 
						$login = getparam('login');
 | 
				
			||||||
	$password = getparam('password');
 | 
						$password = getparam('password');
 | 
				
			||||||
	$remember = isset($_POST['isRemember']) && $_POST['isRemember'] == "on";
 | 
						$remember = isset($_POST['isRemember']) && $_POST['isRemember'] == "on";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$operator = operator_by_login( $login );
 | 
						$operator = operator_by_login($login);
 | 
				
			||||||
	if( $operator && isset($operator['vcpassword']) && $operator['vcpassword'] == md5($password) ) {
 | 
						if ($operator && isset($operator['vcpassword']) && $operator['vcpassword'] == md5($password)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$target = isset($_SESSION['backpath'])
 | 
							$target = isset($_SESSION['backpath'])
 | 
				
			||||||
				? $_SESSION['backpath']
 | 
									? $_SESSION['backpath']
 | 
				
			||||||
				: "$webimroot/operator/index.php";
 | 
									: "$webimroot/operator/index.php";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        login_operator($operator,$remember);
 | 
							login_operator($operator, $remember);
 | 
				
			||||||
		header("Location: $target");
 | 
							header("Location: $target");
 | 
				
			||||||
		exit;
 | 
							exit;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
 | 
				
			|||||||
@ -29,18 +29,19 @@ $page = array();
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
setlocale(LC_TIME, getstring("time.locale"));
 | 
					setlocale(LC_TIME, getstring("time.locale"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function notification_info($id) {
 | 
					function notification_info($id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$notification = select_one_row(db_build_select(
 | 
						$notification = select_one_row(db_build_select(
 | 
				
			||||||
		"id, locale, vckind, vcto, unix_timestamp(dtmcreated) as created, vcsubject, tmessage, refoperator", "${mysqlprefix}chatnotification",
 | 
														   "id, locale, vckind, vcto, unix_timestamp(dtmcreated) as created, vcsubject, tmessage, refoperator", "${mysqlprefix}chatnotification",
 | 
				
			||||||
		array("id = $id"), ""), $link);
 | 
														   array("id = $id"), ""), $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
	return $notification;
 | 
						return $notification;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$notificationid = verifyparam( "id", "/^(\d{1,9})$/");
 | 
					$notificationid = verifyparam("id", "/^(\d{1,9})$/");
 | 
				
			||||||
$page['notification'] = notification_info($notificationid);
 | 
					$page['notification'] = notification_info($notificationid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
prepare_menu($operator, false);
 | 
					prepare_menu($operator, false);
 | 
				
			||||||
 | 
				
			|||||||
@ -28,7 +28,7 @@ $operator = check_login();
 | 
				
			|||||||
$page = array();
 | 
					$page = array();
 | 
				
			||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if( !is_capable($can_administrate, $operator)) {
 | 
					if (!is_capable($can_administrate, $operator)) {
 | 
				
			||||||
	die("Permission denied.");
 | 
						die("Permission denied.");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -38,13 +38,13 @@ setlocale(LC_TIME, getstring("time.locale"));
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$all_locales = get_available_locales();
 | 
					$all_locales = get_available_locales();
 | 
				
			||||||
$locales_with_label = array(array('id' => '', 'name' => getlocal("notifications.locale.all")));
 | 
					$locales_with_label = array(array('id' => '', 'name' => getlocal("notifications.locale.all")));
 | 
				
			||||||
foreach($all_locales as $id) {
 | 
					foreach ($all_locales as $id) {
 | 
				
			||||||
	$locales_with_label[] = array('id' => $id, 'name' => getlocal_($id,"names"));
 | 
						$locales_with_label[] = array('id' => $id, 'name' => getlocal_($id, "names"));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
$page['locales'] = $locales_with_label;
 | 
					$page['locales'] = $locales_with_label;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$lang = verifyparam("lang", "/^([\w-]{2,5})?$/", "");
 | 
					$lang = verifyparam("lang", "/^([\w-]{2,5})?$/", "");
 | 
				
			||||||
if( $lang && !in_array($lang,$all_locales) ) {
 | 
					if ($lang && !in_array($lang, $all_locales)) {
 | 
				
			||||||
	$lang = "";
 | 
						$lang = "";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -56,10 +56,10 @@ $page['allkinds'] = array('', 'mail', 'xmpp');
 | 
				
			|||||||
# fetch
 | 
					# fetch
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$conditions = array();
 | 
					$conditions = array();
 | 
				
			||||||
if($kind) {
 | 
					if ($kind) {
 | 
				
			||||||
	$conditions[] = "vckind = '$kind'";
 | 
						$conditions[] = "vckind = '$kind'";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
if($lang) {
 | 
					if ($lang) {
 | 
				
			||||||
	$conditions[] = "locale = '$lang'";
 | 
						$conditions[] = "locale = '$lang'";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -30,8 +30,8 @@ $errors = array();
 | 
				
			|||||||
$opId = '';
 | 
					$opId = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
loadsettings();
 | 
					loadsettings();
 | 
				
			||||||
if( isset($_POST['login']) && isset($_POST['password']) ) {
 | 
					if (isset($_POST['login']) && isset($_POST['password'])) {
 | 
				
			||||||
	$opId = verifyparam( "opid", "/^(\d{1,9})?$/", "");
 | 
						$opId = verifyparam("opid", "/^(\d{1,9})?$/", "");
 | 
				
			||||||
	$login = getparam('login');
 | 
						$login = getparam('login');
 | 
				
			||||||
	$email = getparam('email');
 | 
						$email = getparam('email');
 | 
				
			||||||
	$jabber = getparam('jabber');
 | 
						$jabber = getparam('jabber');
 | 
				
			||||||
@ -39,58 +39,58 @@ if( isset($_POST['login']) && isset($_POST['password']) ) {
 | 
				
			|||||||
	$passwordConfirm = getparam('passwordConfirm');
 | 
						$passwordConfirm = getparam('passwordConfirm');
 | 
				
			||||||
	$localname = getparam('name');
 | 
						$localname = getparam('name');
 | 
				
			||||||
	$commonname = getparam('commonname');
 | 
						$commonname = getparam('commonname');
 | 
				
			||||||
	$jabbernotify = verifyparam("jabbernotify","/^on$/", "") == "on";
 | 
						$jabbernotify = verifyparam("jabbernotify", "/^on$/", "") == "on";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !$localname )
 | 
						if (!$localname)
 | 
				
			||||||
		$errors[] = no_field("form.field.agent_name");
 | 
							$errors[] = no_field("form.field.agent_name");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !$commonname )
 | 
						if (!$commonname)
 | 
				
			||||||
		$errors[] = no_field("form.field.agent_commonname");
 | 
							$errors[] = no_field("form.field.agent_commonname");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !$login ) {
 | 
						if (!$login) {
 | 
				
			||||||
		$errors[] = no_field("form.field.login");
 | 
							$errors[] = no_field("form.field.login");
 | 
				
			||||||
	} else if( !preg_match( "/^[\w_\.]+$/",$login) ) {
 | 
						} else if (!preg_match("/^[\w_\.]+$/", $login)) {
 | 
				
			||||||
		$errors[] = getlocal("page_agent.error.wrong_login");
 | 
							$errors[] = getlocal("page_agent.error.wrong_login");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if($email != '' && !is_valid_email($email))
 | 
						if ($email != '' && !is_valid_email($email))
 | 
				
			||||||
		$errors[] = wrong_field("form.field.mail");
 | 
							$errors[] = wrong_field("form.field.mail");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if($jabber != '' && !is_valid_email($jabber))
 | 
						if ($jabber != '' && !is_valid_email($jabber))
 | 
				
			||||||
		$errors[] = wrong_field("form.field.jabber");
 | 
							$errors[] = wrong_field("form.field.jabber");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if($jabbernotify && $jabber == '') {
 | 
						if ($jabbernotify && $jabber == '') {
 | 
				
			||||||
		if( $settings['enablejabber'] == "1" ) {
 | 
							if ($settings['enablejabber'] == "1") {
 | 
				
			||||||
			$errors[] = no_field("form.field.jabber");
 | 
								$errors[] = no_field("form.field.jabber");
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			$jabbernotify = false;
 | 
								$jabbernotify = false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !$opId && !$password )
 | 
						if (!$opId && !$password)
 | 
				
			||||||
		$errors[] = no_field("form.field.password");
 | 
							$errors[] = no_field("form.field.password");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $password != $passwordConfirm )
 | 
						if ($password != $passwordConfirm)
 | 
				
			||||||
		$errors[] = getlocal("my_settings.error.password_match");
 | 
							$errors[] = getlocal("my_settings.error.password_match");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$existing_operator = operator_by_login($login);
 | 
						$existing_operator = operator_by_login($login);
 | 
				
			||||||
	if( (!$opId && $existing_operator) ||
 | 
						if ((!$opId && $existing_operator) ||
 | 
				
			||||||
		( $opId && $existing_operator && $opId != $existing_operator['operatorid']) )
 | 
							($opId && $existing_operator && $opId != $existing_operator['operatorid']))
 | 
				
			||||||
		$errors[] = getlocal("page_agent.error.duplicate_login");
 | 
							$errors[] = getlocal("page_agent.error.duplicate_login");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$canmodify = ($opId == $operator['operatorid'] && is_capable($can_modifyprofile, $operator))
 | 
						$canmodify = ($opId == $operator['operatorid'] && is_capable($can_modifyprofile, $operator))
 | 
				
			||||||
				|| is_capable($can_administrate, $operator);
 | 
									 || is_capable($can_administrate, $operator);
 | 
				
			||||||
	if(!$canmodify) {
 | 
						if (!$canmodify) {
 | 
				
			||||||
		$errors[] = getlocal('page_agent.cannot_modify');
 | 
							$errors[] = getlocal('page_agent.cannot_modify');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( count($errors) == 0 ) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		if (!$opId) {
 | 
							if (!$opId) {
 | 
				
			||||||
			$newop = create_operator($login,$email,$jabber,$password,$localname,$commonname,$jabbernotify ? 1 : 0);
 | 
								$newop = create_operator($login, $email, $jabber, $password, $localname, $commonname, $jabbernotify ? 1 : 0);
 | 
				
			||||||
			header("Location: $webimroot/operator/avatar.php?op=".$newop['operatorid']);
 | 
								header("Location: $webimroot/operator/avatar.php?op=" . $newop['operatorid']);
 | 
				
			||||||
			exit;
 | 
								exit;
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			update_operator($opId,$login,$email,$jabber,$password,$localname,$commonname,$jabbernotify ? 1 : 0);
 | 
								update_operator($opId, $login, $email, $jabber, $password, $localname, $commonname, $jabbernotify ? 1 : 0);
 | 
				
			||||||
			header("Location: $webimroot/operator/operator.php?op=$opId&stored");
 | 
								header("Location: $webimroot/operator/operator.php?op=$opId&stored");
 | 
				
			||||||
			exit;
 | 
								exit;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -104,11 +104,11 @@ if( isset($_POST['login']) && isset($_POST['password']) ) {
 | 
				
			|||||||
		$page['opid'] = topage($opId);
 | 
							$page['opid'] = topage($opId);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} else if( isset($_GET['op']) ) {
 | 
					} else if (isset($_GET['op'])) {
 | 
				
			||||||
	$opId = verifyparam( 'op', "/^\d{1,9}$/");
 | 
						$opId = verifyparam('op', "/^\d{1,9}$/");
 | 
				
			||||||
	$op = operator_by_id($opId);
 | 
						$op = operator_by_id($opId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !$op ) {
 | 
						if (!$op) {
 | 
				
			||||||
		$errors[] = getlocal("no_such_operator");
 | 
							$errors[] = getlocal("no_such_operator");
 | 
				
			||||||
		$page['opid'] = topage($opId);
 | 
							$page['opid'] = topage($opId);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
@ -122,19 +122,19 @@ if( isset($_POST['login']) && isset($_POST['password']) ) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if(!$opId && !is_capable($can_administrate, $operator)) {
 | 
					if (!$opId && !is_capable($can_administrate, $operator)) {
 | 
				
			||||||
	$errors[] = "You are not allowed to create operators";
 | 
						$errors[] = "You are not allowed to create operators";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$canmodify = ($opId == $operator['operatorid'] && is_capable($can_modifyprofile, $operator))
 | 
					$canmodify = ($opId == $operator['operatorid'] && is_capable($can_modifyprofile, $operator))
 | 
				
			||||||
				|| is_capable($can_administrate, $operator);
 | 
								 || is_capable($can_administrate, $operator);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page['stored'] = isset($_GET['stored']);
 | 
					$page['stored'] = isset($_GET['stored']);
 | 
				
			||||||
$page['canmodify'] = $canmodify ? "1" : "";
 | 
					$page['canmodify'] = $canmodify ? "1" : "";
 | 
				
			||||||
$page['showjabber'] = $settings['enablejabber'] == "1";
 | 
					$page['showjabber'] = $settings['enablejabber'] == "1";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
prepare_menu($operator);
 | 
					prepare_menu($operator);
 | 
				
			||||||
setup_operator_settings_tabs($opId,0);
 | 
					setup_operator_settings_tabs($opId, 0);
 | 
				
			||||||
start_html_output();
 | 
					start_html_output();
 | 
				
			||||||
require('../view/agent.php');
 | 
					require('../view/agent.php');
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
@ -24,34 +24,34 @@ require_once('../libs/operator.php');
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$operator = check_login();
 | 
					$operator = check_login();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if( isset($_GET['act']) && $_GET['act'] == 'del' ) {
 | 
					if (isset($_GET['act']) && $_GET['act'] == 'del') {
 | 
				
			||||||
	$operatorid = isset($_GET['id']) ? $_GET['id'] : "";
 | 
						$operatorid = isset($_GET['id']) ? $_GET['id'] : "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !preg_match( "/^\d+$/", $operatorid )) {
 | 
						if (!preg_match("/^\d+$/", $operatorid)) {
 | 
				
			||||||
		$errors[] = "Cannot delete: wrong argument";
 | 
							$errors[] = "Cannot delete: wrong argument";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !is_capable($can_administrate, $operator)) {
 | 
						if (!is_capable($can_administrate, $operator)) {
 | 
				
			||||||
		$errors[] = "You are not allowed to remove operators";
 | 
							$errors[] = "You are not allowed to remove operators";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $operatorid == $operator['operatorid']) {
 | 
						if ($operatorid == $operator['operatorid']) {
 | 
				
			||||||
		$errors[] = "Cannot remove self";
 | 
							$errors[] = "Cannot remove self";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(count($errors) == 0) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		$op = operator_by_id($operatorid);
 | 
							$op = operator_by_id($operatorid);
 | 
				
			||||||
		if( !$op ) {
 | 
							if (!$op) {
 | 
				
			||||||
			$errors[] = getlocal("no_such_operator");
 | 
								$errors[] = getlocal("no_such_operator");
 | 
				
			||||||
		} else if($op['vclogin'] == 'admin') {
 | 
							} else if ($op['vclogin'] == 'admin') {
 | 
				
			||||||
			$errors[] = 'Cannot remove operator "admin"';
 | 
								$errors[] = 'Cannot remove operator "admin"';
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( count($errors) == 0 ) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		$link = connect();
 | 
							$link = connect();
 | 
				
			||||||
		perform_query("delete from ${mysqlprefix}chatgroupoperator where operatorid = $operatorid",$link);
 | 
							perform_query("delete from ${mysqlprefix}chatgroupoperator where operatorid = $operatorid", $link);
 | 
				
			||||||
		perform_query("delete from ${mysqlprefix}chatoperator where operatorid = $operatorid",$link);
 | 
							perform_query("delete from ${mysqlprefix}chatoperator where operatorid = $operatorid", $link);
 | 
				
			||||||
		mysql_close($link);
 | 
							mysql_close($link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		header("Location: $webimroot/operator/operators.php");
 | 
							header("Location: $webimroot/operator/operators.php");
 | 
				
			||||||
 | 
				
			|||||||
@ -25,18 +25,19 @@ require_once('../libs/operator_settings.php');
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$operator = check_login();
 | 
					$operator = check_login();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function update_operator_groups($operatorid,$newvalue) {
 | 
					function update_operator_groups($operatorid, $newvalue)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	perform_query("delete from ${mysqlprefix}chatgroupoperator where operatorid = $operatorid", $link);
 | 
						perform_query("delete from ${mysqlprefix}chatgroupoperator where operatorid = $operatorid", $link);
 | 
				
			||||||
	foreach($newvalue as $groupid) {
 | 
						foreach ($newvalue as $groupid) {
 | 
				
			||||||
		perform_query("insert into ${mysqlprefix}chatgroupoperator (groupid, operatorid) values ($groupid,$operatorid)", $link);
 | 
							perform_query("insert into ${mysqlprefix}chatgroupoperator (groupid, operatorid) values ($groupid,$operatorid)", $link);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$opId = verifyparam( "op","/^\d{1,9}$/");
 | 
					$opId = verifyparam("op", "/^\d{1,9}$/");
 | 
				
			||||||
$page = array('opid' => $opId);
 | 
					$page = array('opid' => $opId);
 | 
				
			||||||
$link = connect();
 | 
					$link = connect();
 | 
				
			||||||
$page['groups'] = get_all_groups($link);
 | 
					$page['groups'] = get_all_groups($link);
 | 
				
			||||||
@ -44,46 +45,46 @@ mysql_close($link);
 | 
				
			|||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$canmodify = ($opId == $operator['operatorid'] && is_capable($can_modifyprofile, $operator))
 | 
					$canmodify = ($opId == $operator['operatorid'] && is_capable($can_modifyprofile, $operator))
 | 
				
			||||||
				|| is_capable($can_administrate, $operator);
 | 
								 || is_capable($can_administrate, $operator);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$op = operator_by_id($opId);
 | 
					$op = operator_by_id($opId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if( !$op ) {
 | 
					if (!$op) {
 | 
				
			||||||
	$errors[] = getlocal("no_such_operator");
 | 
						$errors[] = getlocal("no_such_operator");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} else if( isset($_POST['op']) ) {
 | 
					} else if (isset($_POST['op'])) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(!$canmodify) {
 | 
						if (!$canmodify) {
 | 
				
			||||||
		$errors[] = getlocal('page_agent.cannot_modify');
 | 
							$errors[] = getlocal('page_agent.cannot_modify');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(count($errors) == 0) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		$new_groups = array();
 | 
							$new_groups = array();
 | 
				
			||||||
		foreach($page['groups'] as $group) {
 | 
							foreach ($page['groups'] as $group) {
 | 
				
			||||||
			if( verifyparam("group".$group['groupid'],"/^on$/", "") == "on") {
 | 
								if (verifyparam("group" . $group['groupid'], "/^on$/", "") == "on") {
 | 
				
			||||||
				$new_groups[] = $group['groupid'];
 | 
									$new_groups[] = $group['groupid'];
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		update_operator_groups($op['operatorid'],$new_groups);
 | 
							update_operator_groups($op['operatorid'], $new_groups);
 | 
				
			||||||
		header("Location: $webimroot/operator/opgroups.php?op=$opId&stored");
 | 
							header("Location: $webimroot/operator/opgroups.php?op=$opId&stored");
 | 
				
			||||||
		exit;
 | 
							exit;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page['formgroup'] = array();
 | 
					$page['formgroup'] = array();
 | 
				
			||||||
$page['currentop'] = $op ? topage(get_operator_name($op))." (".$op['vclogin'].")" : "-not found-";
 | 
					$page['currentop'] = $op ? topage(get_operator_name($op)) . " (" . $op['vclogin'] . ")" : "-not found-";
 | 
				
			||||||
$page['canmodify'] = $canmodify ? "1" : "";
 | 
					$page['canmodify'] = $canmodify ? "1" : "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if($op) {
 | 
					if ($op) {
 | 
				
			||||||
	foreach(get_operator_groupids($opId) as $rel) {
 | 
						foreach (get_operator_groupids($opId) as $rel) {
 | 
				
			||||||
		$page['formgroup'][] = $rel['groupid'];
 | 
							$page['formgroup'][] = $rel['groupid'];
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page['stored'] = isset($_GET['stored']);
 | 
					$page['stored'] = isset($_GET['stored']);
 | 
				
			||||||
prepare_menu($operator);
 | 
					prepare_menu($operator);
 | 
				
			||||||
setup_operator_settings_tabs($opId,2);
 | 
					setup_operator_settings_tabs($opId, 2);
 | 
				
			||||||
start_html_output();
 | 
					start_html_output();
 | 
				
			||||||
require('../view/operator_groups.php');
 | 
					require('../view/operator_groups.php');
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
 | 
				
			|||||||
@ -29,49 +29,49 @@ $page = array('agentId' => '');
 | 
				
			|||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$options = array(
 | 
					$options = array(
 | 
				
			||||||
		'online_timeout', 'updatefrequency_operator', 'updatefrequency_chat',
 | 
						'online_timeout', 'updatefrequency_operator', 'updatefrequency_chat',
 | 
				
			||||||
		'updatefrequency_oldchat', 'max_connections_from_one_host');
 | 
						'updatefrequency_oldchat', 'max_connections_from_one_host');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
loadsettings();
 | 
					loadsettings();
 | 
				
			||||||
$params = array();
 | 
					$params = array();
 | 
				
			||||||
foreach($options as $opt) {
 | 
					foreach ($options as $opt) {
 | 
				
			||||||
	$params[$opt] = $settings[$opt];
 | 
						$params[$opt] = $settings[$opt];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if (isset($_POST['onlinetimeout'])) {
 | 
					if (isset($_POST['onlinetimeout'])) {
 | 
				
			||||||
    $params['online_timeout'] = getparam('onlinetimeout');
 | 
						$params['online_timeout'] = getparam('onlinetimeout');
 | 
				
			||||||
    if(!is_numeric($params['online_timeout'])) {
 | 
						if (!is_numeric($params['online_timeout'])) {
 | 
				
			||||||
    	$errors[] = wrong_field("settings.onlinetimeout");
 | 
							$errors[] = wrong_field("settings.onlinetimeout");
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $params['updatefrequency_operator'] = getparam('frequencyoperator');
 | 
						$params['updatefrequency_operator'] = getparam('frequencyoperator');
 | 
				
			||||||
    if(!is_numeric($params['updatefrequency_operator'])) {
 | 
						if (!is_numeric($params['updatefrequency_operator'])) {
 | 
				
			||||||
    	$errors[] = wrong_field("settings.frequencyoperator");
 | 
							$errors[] = wrong_field("settings.frequencyoperator");
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $params['updatefrequency_chat'] = getparam('frequencychat');
 | 
						$params['updatefrequency_chat'] = getparam('frequencychat');
 | 
				
			||||||
    if(!is_numeric($params['updatefrequency_chat'])) {
 | 
						if (!is_numeric($params['updatefrequency_chat'])) {
 | 
				
			||||||
    	$errors[] = wrong_field("settings.frequencychat");
 | 
							$errors[] = wrong_field("settings.frequencychat");
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $params['updatefrequency_oldchat'] = getparam('frequencyoldchat');
 | 
						$params['updatefrequency_oldchat'] = getparam('frequencyoldchat');
 | 
				
			||||||
    if(!is_numeric($params['updatefrequency_oldchat'])) {
 | 
						if (!is_numeric($params['updatefrequency_oldchat'])) {
 | 
				
			||||||
    	$errors[] = wrong_field("settings.frequencyoldchat");
 | 
							$errors[] = wrong_field("settings.frequencyoldchat");
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$params['max_connections_from_one_host'] = getparam('onehostconnections');
 | 
						$params['max_connections_from_one_host'] = getparam('onehostconnections');
 | 
				
			||||||
    if(!is_numeric($params['max_connections_from_one_host'])) {
 | 
						if (!is_numeric($params['max_connections_from_one_host'])) {
 | 
				
			||||||
    	$errors[] = getlocal("settings.wrong.onehostconnections");
 | 
							$errors[] = getlocal("settings.wrong.onehostconnections");
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (count($errors) == 0) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		foreach($options as $opt) {
 | 
							foreach ($options as $opt) {
 | 
				
			||||||
			$settings[$opt] = $params[$opt];
 | 
								$settings[$opt] = $params[$opt];
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
    	update_settings();
 | 
							update_settings();
 | 
				
			||||||
        header("Location: $webimroot/operator/performance.php?stored");
 | 
							header("Location: $webimroot/operator/performance.php?stored");
 | 
				
			||||||
        exit;
 | 
							exit;
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page['formonlinetimeout'] = $params['online_timeout'];
 | 
					$page['formonlinetimeout'] = $params['online_timeout'];
 | 
				
			||||||
 | 
				
			|||||||
@ -25,42 +25,43 @@ require_once('../libs/operator_settings.php');
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$operator = check_login();
 | 
					$operator = check_login();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function update_operator_permissions($operatorid,$newvalue) {
 | 
					function update_operator_permissions($operatorid, $newvalue)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$query = "update ${mysqlprefix}chatoperator set iperm = $newvalue where operatorid = $operatorid";
 | 
						$query = "update ${mysqlprefix}chatoperator set iperm = $newvalue where operatorid = $operatorid";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	perform_query($query,$link);
 | 
						perform_query($query, $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$opId = verifyparam( "op","/^\d{1,9}$/");
 | 
					$opId = verifyparam("op", "/^\d{1,9}$/");
 | 
				
			||||||
$page = array('opid' => $opId, 'canmodify' => is_capable($can_administrate, $operator) ? "1" : "");
 | 
					$page = array('opid' => $opId, 'canmodify' => is_capable($can_administrate, $operator) ? "1" : "");
 | 
				
			||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$op = operator_by_id($opId);
 | 
					$op = operator_by_id($opId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if( !$op ) {
 | 
					if (!$op) {
 | 
				
			||||||
	$errors[] = getlocal("no_such_operator");
 | 
						$errors[] = getlocal("no_such_operator");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} else if( isset($_POST['op']) ) {
 | 
					} else if (isset($_POST['op'])) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(!is_capable($can_administrate, $operator)) {
 | 
						if (!is_capable($can_administrate, $operator)) {
 | 
				
			||||||
		$errors[] = getlocal('page_agent.cannot_modify');
 | 
							$errors[] = getlocal('page_agent.cannot_modify');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$new_permissions = isset($op['iperm']) ? $op['iperm'] : 0;
 | 
						$new_permissions = isset($op['iperm']) ? $op['iperm'] : 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	foreach($permission_ids as $perm => $id) {
 | 
						foreach ($permission_ids as $perm => $id) {
 | 
				
			||||||
		if( verifyparam("permissions$id","/^on$/", "") == "on") {
 | 
							if (verifyparam("permissions$id", "/^on$/", "") == "on") {
 | 
				
			||||||
			$new_permissions |= (1 << $perm);
 | 
								$new_permissions |= (1 << $perm);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			$new_permissions &= ~ (1 << $perm);
 | 
								$new_permissions &= ~(1 << $perm);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(count($errors) == 0) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		update_operator_permissions($op['operatorid'],$new_permissions);
 | 
							update_operator_permissions($op['operatorid'], $new_permissions);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ($opId && $_SESSION["${mysqlprefix}operator"] && $operator['operatorid'] == $opId) {
 | 
							if ($opId && $_SESSION["${mysqlprefix}operator"] && $operator['operatorid'] == $opId) {
 | 
				
			||||||
			$_SESSION["${mysqlprefix}operator"]['iperm'] = $new_permissions;
 | 
								$_SESSION["${mysqlprefix}operator"]['iperm'] = $new_permissions;
 | 
				
			||||||
@ -73,11 +74,11 @@ if( !$op ) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$page['permissionsList'] = get_permission_list();
 | 
					$page['permissionsList'] = get_permission_list();
 | 
				
			||||||
$page['formpermissions'] = array("");
 | 
					$page['formpermissions'] = array("");
 | 
				
			||||||
$page['currentop'] = $op ? topage(get_operator_name($op))." (".$op['vclogin'].")" : "-not found-";
 | 
					$page['currentop'] = $op ? topage(get_operator_name($op)) . " (" . $op['vclogin'] . ")" : "-not found-";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if($op) {
 | 
					if ($op) {
 | 
				
			||||||
	foreach($permission_ids as $perm => $id) {
 | 
						foreach ($permission_ids as $perm => $id) {
 | 
				
			||||||
		if(is_capable($perm,$op)) {
 | 
							if (is_capable($perm, $op)) {
 | 
				
			||||||
			$page['formpermissions'][] = $id;
 | 
								$page['formpermissions'][] = $id;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -85,7 +86,7 @@ if($op) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$page['stored'] = isset($_GET['stored']);
 | 
					$page['stored'] = isset($_GET['stored']);
 | 
				
			||||||
prepare_menu($operator);
 | 
					prepare_menu($operator);
 | 
				
			||||||
setup_operator_settings_tabs($opId,3);
 | 
					setup_operator_settings_tabs($opId, 3);
 | 
				
			||||||
start_html_output();
 | 
					start_html_output();
 | 
				
			||||||
require('../view/permissions.php');
 | 
					require('../view/permissions.php');
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
 | 
				
			|||||||
@ -27,30 +27,30 @@ require_once('../libs/groups.php');
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$operator = check_login();
 | 
					$operator = check_login();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$threadid = verifyparam( "thread", "/^\d{1,8}$/");
 | 
					$threadid = verifyparam("thread", "/^\d{1,8}$/");
 | 
				
			||||||
$token = verifyparam( "token", "/^\d{1,8}$/");
 | 
					$token = verifyparam("token", "/^\d{1,8}$/");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$thread = thread_by_id($threadid);
 | 
					$thread = thread_by_id($threadid);
 | 
				
			||||||
if( !$thread || !isset($thread['ltoken']) || $token != $thread['ltoken'] ) {
 | 
					if (!$thread || !isset($thread['ltoken']) || $token != $thread['ltoken']) {
 | 
				
			||||||
	die("wrong thread");
 | 
						die("wrong thread");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page = array();
 | 
					$page = array();
 | 
				
			||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if(isset($_GET['nextGroup'])) {
 | 
					if (isset($_GET['nextGroup'])) {
 | 
				
			||||||
	$nextid = verifyparam( "nextGroup", "/^\d{1,8}$/");
 | 
						$nextid = verifyparam("nextGroup", "/^\d{1,8}$/");
 | 
				
			||||||
	$nextGroup = group_by_id($nextid);
 | 
						$nextGroup = group_by_id($nextid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $nextGroup ) {
 | 
						if ($nextGroup) {
 | 
				
			||||||
		$page['message'] = getlocal2("chat.redirected.group.content",array(topage(get_group_name($nextGroup))));
 | 
							$page['message'] = getlocal2("chat.redirected.group.content", array(topage(get_group_name($nextGroup))));
 | 
				
			||||||
		if( $thread['istate'] == $state_chatting ) {
 | 
							if ($thread['istate'] == $state_chatting) {
 | 
				
			||||||
			$link = connect();
 | 
								$link = connect();
 | 
				
			||||||
			commit_thread( $threadid,
 | 
								commit_thread($threadid,
 | 
				
			||||||
				array("istate" => $state_waiting, "nextagent" => 0, "groupid" => $nextid, "agentId" => 0, "agentName" => "''"), $link);
 | 
											  array("istate" => $state_waiting, "nextagent" => 0, "groupid" => $nextid, "agentId" => 0, "agentName" => "''"), $link);
 | 
				
			||||||
			post_message_($thread['threadid'], $kind_events,
 | 
								post_message_($thread['threadid'], $kind_events,
 | 
				
			||||||
				getstring2_("chat.status.operator.redirect",
 | 
											  getstring2_("chat.status.operator.redirect",
 | 
				
			||||||
					array(get_operator_name($operator)),$thread['locale']), $link);
 | 
														  array(get_operator_name($operator)), $thread['locale']), $link);
 | 
				
			||||||
			mysql_close($link);
 | 
								mysql_close($link);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			$errors[] = getlocal("chat.redirect.cannot");
 | 
								$errors[] = getlocal("chat.redirect.cannot");
 | 
				
			||||||
@ -60,23 +60,23 @@ if(isset($_GET['nextGroup'])) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} else {
 | 
					} else {
 | 
				
			||||||
	$nextid = verifyparam( "nextAgent", "/^\d{1,8}$/");
 | 
						$nextid = verifyparam("nextAgent", "/^\d{1,8}$/");
 | 
				
			||||||
	$nextOperator = operator_by_id($nextid);
 | 
						$nextOperator = operator_by_id($nextid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $nextOperator ) {
 | 
						if ($nextOperator) {
 | 
				
			||||||
		$page['message'] = getlocal2("chat.redirected.content",array(topage(get_operator_name($nextOperator))));
 | 
							$page['message'] = getlocal2("chat.redirected.content", array(topage(get_operator_name($nextOperator))));
 | 
				
			||||||
		if( $thread['istate'] == $state_chatting ) {
 | 
							if ($thread['istate'] == $state_chatting) {
 | 
				
			||||||
			$link = connect();
 | 
								$link = connect();
 | 
				
			||||||
			$threadupdate = array("istate" => $state_waiting, "nextagent" => $nextid, "agentId" => 0);
 | 
								$threadupdate = array("istate" => $state_waiting, "nextagent" => $nextid, "agentId" => 0);
 | 
				
			||||||
			if($thread['groupid'] != 0) {
 | 
								if ($thread['groupid'] != 0) {
 | 
				
			||||||
				if(FALSE === select_one_row("select groupid from ${mysqlprefix}chatgroupoperator where operatorid = $nextid and groupid = ".$thread['groupid'], $link)) {
 | 
									if (FALSE === select_one_row("select groupid from ${mysqlprefix}chatgroupoperator where operatorid = $nextid and groupid = " . $thread['groupid'], $link)) {
 | 
				
			||||||
					$threadupdate['groupid'] = 0;
 | 
										$threadupdate['groupid'] = 0;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			commit_thread( $threadid, $threadupdate, $link);
 | 
								commit_thread($threadid, $threadupdate, $link);
 | 
				
			||||||
			post_message_($thread['threadid'], $kind_events,
 | 
								post_message_($thread['threadid'], $kind_events,
 | 
				
			||||||
				getstring2_("chat.status.operator.redirect",
 | 
											  getstring2_("chat.status.operator.redirect",
 | 
				
			||||||
					array(get_operator_name($operator)),$thread['locale']), $link);
 | 
														  array(get_operator_name($operator)), $thread['locale']), $link);
 | 
				
			||||||
			mysql_close($link);
 | 
								mysql_close($link);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			$errors[] = getlocal("chat.redirect.cannot");
 | 
								$errors[] = getlocal("chat.redirect.cannot");
 | 
				
			||||||
@ -87,7 +87,7 @@ if(isset($_GET['nextGroup'])) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
setup_logo();
 | 
					setup_logo();
 | 
				
			||||||
if( count($errors) > 0 ) {
 | 
					if (count($errors) > 0) {
 | 
				
			||||||
	expand("../styles", getchatstyle(), "error.tpl");
 | 
						expand("../styles", getchatstyle(), "error.tpl");
 | 
				
			||||||
} else {
 | 
					} else {
 | 
				
			||||||
	expand("../styles", getchatstyle(), "redirected.tpl");
 | 
						expand("../styles", getchatstyle(), "redirected.tpl");
 | 
				
			||||||
 | 
				
			|||||||
@ -26,15 +26,15 @@ require_once('../libs/settings.php');
 | 
				
			|||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
$page = array('version' => $version, 'showform' => true);
 | 
					$page = array('version' => $version, 'showform' => true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$opId = verifyparam( "id", "/^\d{1,9}$/");
 | 
					$opId = verifyparam("id", "/^\d{1,9}$/");
 | 
				
			||||||
$token = verifyparam("token", "/^[\dabcdef]+$/");
 | 
					$token = verifyparam("token", "/^[\dabcdef]+$/");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$operator = operator_by_id($opId);
 | 
					$operator = operator_by_id($opId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if(!$operator) {
 | 
					if (!$operator) {
 | 
				
			||||||
	$errors[] = "No such operator";
 | 
						$errors[] = "No such operator";
 | 
				
			||||||
	$page['showform'] = false;
 | 
						$page['showform'] = false;
 | 
				
			||||||
} else if($token != $operator['vcrestoretoken']) {
 | 
					} else if ($token != $operator['vcrestoretoken']) {
 | 
				
			||||||
	$errors[] = "Wrong token";
 | 
						$errors[] = "Wrong token";
 | 
				
			||||||
	$page['showform'] = false;
 | 
						$page['showform'] = false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -43,24 +43,24 @@ if (count($errors) == 0 && isset($_POST['password'])) {
 | 
				
			|||||||
	$password = getparam('password');
 | 
						$password = getparam('password');
 | 
				
			||||||
	$passwordConfirm = getparam('passwordConfirm');
 | 
						$passwordConfirm = getparam('passwordConfirm');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( !$password )
 | 
						if (!$password)
 | 
				
			||||||
		$errors[] = no_field("form.field.password");
 | 
							$errors[] = no_field("form.field.password");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if( $password != $passwordConfirm )
 | 
						if ($password != $passwordConfirm)
 | 
				
			||||||
		$errors[] = getlocal("my_settings.error.password_match");
 | 
							$errors[] = getlocal("my_settings.error.password_match");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (count($errors) == 0) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		$page['isdone'] = true;
 | 
							$page['isdone'] = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$link = connect();
 | 
							$link = connect();
 | 
				
			||||||
		$query = "update ${mysqlprefix}chatoperator set vcpassword = '".md5($password)."', vcrestoretoken = '' where operatorid = ".$opId;
 | 
							$query = "update ${mysqlprefix}chatoperator set vcpassword = '" . md5($password) . "', vcrestoretoken = '' where operatorid = " . $opId;
 | 
				
			||||||
		perform_query($query, $link);
 | 
							perform_query($query, $link);
 | 
				
			||||||
		mysql_close($link);
 | 
							mysql_close($link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		start_html_output();
 | 
							start_html_output();
 | 
				
			||||||
		require('../view/resetpwd.php');
 | 
							require('../view/resetpwd.php');
 | 
				
			||||||
		exit;
 | 
							exit;
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page['id'] = $opId;
 | 
					$page['id'] = $opId;
 | 
				
			||||||
 | 
				
			|||||||
@ -32,30 +32,30 @@ if (isset($_POST['loginoremail'])) {
 | 
				
			|||||||
	$loginoremail = getparam("loginoremail");
 | 
						$loginoremail = getparam("loginoremail");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$torestore = is_valid_email($loginoremail) ? operator_by_email($loginoremail) : operator_by_login($loginoremail);
 | 
						$torestore = is_valid_email($loginoremail) ? operator_by_email($loginoremail) : operator_by_login($loginoremail);
 | 
				
			||||||
	if(!$torestore) {
 | 
						if (!$torestore) {
 | 
				
			||||||
		$errors[] = getlocal("no_such_operator");
 | 
							$errors[] = getlocal("no_such_operator");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$email = $torestore['vcemail'];
 | 
						$email = $torestore['vcemail'];
 | 
				
			||||||
	if(count($errors) == 0 && !is_valid_email($email)) {
 | 
						if (count($errors) == 0 && !is_valid_email($email)) {
 | 
				
			||||||
		$errors[] = "Operator hasn't set his e-mail";
 | 
							$errors[] = "Operator hasn't set his e-mail";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (count($errors) == 0) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		$token = md5((time() + microtime()).rand(0,99999999));
 | 
							$token = md5((time() + microtime()) . rand(0, 99999999));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$link = connect();
 | 
							$link = connect();
 | 
				
			||||||
		$query = "update ${mysqlprefix}chatoperator set dtmrestore = CURRENT_TIMESTAMP, vcrestoretoken = '$token' where operatorid = ".$torestore['operatorid'];
 | 
							$query = "update ${mysqlprefix}chatoperator set dtmrestore = CURRENT_TIMESTAMP, vcrestoretoken = '$token' where operatorid = " . $torestore['operatorid'];
 | 
				
			||||||
		perform_query($query, $link);
 | 
							perform_query($query, $link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$href = get_app_location(true,false)."/operator/resetpwd.php?id=".$torestore['operatorid']."&token=$token";
 | 
							$href = get_app_location(true, false) . "/operator/resetpwd.php?id=" . $torestore['operatorid'] . "&token=$token";
 | 
				
			||||||
		webim_mail($email, $email, getstring("restore.mailsubj"), getstring2("restore.mailtext",array(get_operator_name($torestore), $href)), $link);
 | 
							webim_mail($email, $email, getstring("restore.mailsubj"), getstring2("restore.mailtext", array(get_operator_name($torestore), $href)), $link);
 | 
				
			||||||
		mysql_close($link);
 | 
							mysql_close($link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$page['isdone'] = true;
 | 
							$page['isdone'] = true;
 | 
				
			||||||
		require('../view/restore.php');
 | 
							require('../view/restore.php');
 | 
				
			||||||
		exit;
 | 
							exit;
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page['formloginoremail'] = topage($loginoremail);
 | 
					$page['formloginoremail'] = topage($loginoremail);
 | 
				
			||||||
 | 
				
			|||||||
@ -30,7 +30,7 @@ $errors = array();
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$stylelist = array();
 | 
					$stylelist = array();
 | 
				
			||||||
$stylesfolder = "../styles";
 | 
					$stylesfolder = "../styles";
 | 
				
			||||||
if($handle = opendir($stylesfolder)) {
 | 
					if ($handle = opendir($stylesfolder)) {
 | 
				
			||||||
	while (false !== ($file = readdir($handle))) {
 | 
						while (false !== ($file = readdir($handle))) {
 | 
				
			||||||
		if (preg_match("/^\w+$/", $file) && is_dir("$stylesfolder/$file")) {
 | 
							if (preg_match("/^\w+$/", $file) && is_dir("$stylesfolder/$file")) {
 | 
				
			||||||
			$stylelist[] = $file;
 | 
								$stylelist[] = $file;
 | 
				
			||||||
@ -40,57 +40,57 @@ if($handle = opendir($stylesfolder)) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$options = array(
 | 
					$options = array(
 | 
				
			||||||
		'email', 'title', 'logo', 'hosturl', 'usernamepattern',
 | 
						'email', 'title', 'logo', 'hosturl', 'usernamepattern',
 | 
				
			||||||
		'chatstyle', 'chattitle', 'geolink', 'geolinkparams', 'sendmessagekey');
 | 
						'chatstyle', 'chattitle', 'geolink', 'geolinkparams', 'sendmessagekey');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
loadsettings();
 | 
					loadsettings();
 | 
				
			||||||
$params = array();
 | 
					$params = array();
 | 
				
			||||||
foreach($options as $opt) {
 | 
					foreach ($options as $opt) {
 | 
				
			||||||
	$params[$opt] = $settings[$opt];
 | 
						$params[$opt] = $settings[$opt];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if (isset($_POST['email']) && isset($_POST['title']) && isset($_POST['logo'])) {
 | 
					if (isset($_POST['email']) && isset($_POST['title']) && isset($_POST['logo'])) {
 | 
				
			||||||
    $params['email'] = getparam('email');
 | 
						$params['email'] = getparam('email');
 | 
				
			||||||
    $params['title'] = getparam('title');
 | 
						$params['title'] = getparam('title');
 | 
				
			||||||
    $params['logo']  = getparam('logo');
 | 
						$params['logo'] = getparam('logo');
 | 
				
			||||||
    $params['hosturl'] = getparam('hosturl');
 | 
						$params['hosturl'] = getparam('hosturl');
 | 
				
			||||||
    $params['usernamepattern'] = getparam('usernamepattern');
 | 
						$params['usernamepattern'] = getparam('usernamepattern');
 | 
				
			||||||
    $params['chattitle'] = getparam('chattitle');
 | 
						$params['chattitle'] = getparam('chattitle');
 | 
				
			||||||
    $params['geolink'] = getparam('geolink');
 | 
						$params['geolink'] = getparam('geolink');
 | 
				
			||||||
	$params['geolinkparams'] = getparam('geolinkparams');
 | 
						$params['geolinkparams'] = getparam('geolinkparams');
 | 
				
			||||||
	$params['sendmessagekey'] = verifyparam('sendmessagekey', "/^c?enter$/");
 | 
						$params['sendmessagekey'] = verifyparam('sendmessagekey', "/^c?enter$/");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$params['chatstyle'] = verifyparam("chatstyle","/^\w+$/", $params['chatstyle']);
 | 
						$params['chatstyle'] = verifyparam("chatstyle", "/^\w+$/", $params['chatstyle']);
 | 
				
			||||||
	if(!in_array($params['chatstyle'], $stylelist)) {
 | 
						if (!in_array($params['chatstyle'], $stylelist)) {
 | 
				
			||||||
		$params['chatstyle'] = $stylelist[0];
 | 
							$params['chatstyle'] = $stylelist[0];
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if($params['email'] && !is_valid_email($params['email'])) {
 | 
						if ($params['email'] && !is_valid_email($params['email'])) {
 | 
				
			||||||
        $errors[] = getlocal("settings.wrong.email");
 | 
							$errors[] = getlocal("settings.wrong.email");
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if($params['geolinkparams']) {
 | 
						if ($params['geolinkparams']) {
 | 
				
			||||||
    	foreach(preg_split("/,/", $params['geolinkparams']) as $oneparam) {
 | 
							foreach (preg_split("/,/", $params['geolinkparams']) as $oneparam) {
 | 
				
			||||||
    		if(!preg_match("/^\s*(toolbar|scrollbars|location|status|menubar|width|height|resizable)=\d{1,4}$/", $oneparam)) {
 | 
								if (!preg_match("/^\s*(toolbar|scrollbars|location|status|menubar|width|height|resizable)=\d{1,4}$/", $oneparam)) {
 | 
				
			||||||
    			$errors[] = "Wrong link parameter: \"$oneparam\", should be one of 'toolbar, scrollbars, location, status, menubar, width, height or resizable'";
 | 
									$errors[] = "Wrong link parameter: \"$oneparam\", should be one of 'toolbar, scrollbars, location, status, menubar, width, height or resizable'";
 | 
				
			||||||
    		}
 | 
								}
 | 
				
			||||||
    	}
 | 
							}
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (count($errors) == 0) {
 | 
						if (count($errors) == 0) {
 | 
				
			||||||
		foreach($options as $opt) {
 | 
							foreach ($options as $opt) {
 | 
				
			||||||
			$settings[$opt] = $params[$opt];
 | 
								$settings[$opt] = $params[$opt];
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
    	update_settings();
 | 
							update_settings();
 | 
				
			||||||
        header("Location: $webimroot/operator/settings.php?stored");
 | 
							header("Location: $webimroot/operator/settings.php?stored");
 | 
				
			||||||
        exit;
 | 
							exit;
 | 
				
			||||||
    }
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page['formemail'] = topage($params['email']);
 | 
					$page['formemail'] = topage($params['email']);
 | 
				
			||||||
$page['formtitle'] = topage($params['title']);
 | 
					$page['formtitle'] = topage($params['title']);
 | 
				
			||||||
$page['formlogo']  = topage($params['logo']);
 | 
					$page['formlogo'] = topage($params['logo']);
 | 
				
			||||||
$page['formhosturl']  = topage($params['hosturl']);
 | 
					$page['formhosturl'] = topage($params['hosturl']);
 | 
				
			||||||
$page['formgeolink'] = topage($params['geolink']);
 | 
					$page['formgeolink'] = topage($params['geolink']);
 | 
				
			||||||
$page['formgeolinkparams'] = topage($params['geolinkparams']);
 | 
					$page['formgeolinkparams'] = topage($params['geolinkparams']);
 | 
				
			||||||
$page['formusernamepattern'] = topage($params['usernamepattern']);
 | 
					$page['formusernamepattern'] = topage($params['usernamepattern']);
 | 
				
			||||||
 | 
				
			|||||||
@ -29,55 +29,55 @@ setlocale(LC_TIME, getstring("time.locale"));
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$page = array();
 | 
					$page = array();
 | 
				
			||||||
$page['operator'] = topage(get_operator_name($operator));
 | 
					$page['operator'] = topage(get_operator_name($operator));
 | 
				
			||||||
$page['availableDays'] = range(1,31);
 | 
					$page['availableDays'] = range(1, 31);
 | 
				
			||||||
$page['availableMonth'] = get_month_selection(time()-400*24*60*60,time()+50*24*60*60 );
 | 
					$page['availableMonth'] = get_month_selection(time() - 400 * 24 * 60 * 60, time() + 50 * 24 * 60 * 60);
 | 
				
			||||||
$page['showresults'] = false;
 | 
					$page['showresults'] = false;
 | 
				
			||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if(isset($_GET['startday'])) {
 | 
					if (isset($_GET['startday'])) {
 | 
				
			||||||
	$startday = verifyparam("startday","/^\d+$/");
 | 
						$startday = verifyparam("startday", "/^\d+$/");
 | 
				
			||||||
	$startmonth = verifyparam("startmonth","/^\d{2}.\d{2}$/");
 | 
						$startmonth = verifyparam("startmonth", "/^\d{2}.\d{2}$/");
 | 
				
			||||||
	$endday = verifyparam("endday","/^\d+$/");
 | 
						$endday = verifyparam("endday", "/^\d+$/");
 | 
				
			||||||
	$endmonth = verifyparam("endmonth","/^\d{2}.\d{2}$/");
 | 
						$endmonth = verifyparam("endmonth", "/^\d{2}.\d{2}$/");
 | 
				
			||||||
	$start = get_form_date($startday,$startmonth);
 | 
						$start = get_form_date($startday, $startmonth);
 | 
				
			||||||
	$end = get_form_date($endday, $endmonth)+24*60*60;
 | 
						$end = get_form_date($endday, $endmonth) + 24 * 60 * 60;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} else {
 | 
					} else {
 | 
				
			||||||
	$curr = getdate(time());
 | 
						$curr = getdate(time());
 | 
				
			||||||
	if( $curr['mday'] < 7 ) {
 | 
						if ($curr['mday'] < 7) {
 | 
				
			||||||
		// previous month
 | 
							// previous month
 | 
				
			||||||
		if($curr['mon'] == 1) {
 | 
							if ($curr['mon'] == 1) {
 | 
				
			||||||
			$month = 12;
 | 
								$month = 12;
 | 
				
			||||||
			$year = $curr['year']-1;
 | 
								$year = $curr['year'] - 1;
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			$month = $curr['mon']-1; 
 | 
								$month = $curr['mon'] - 1;
 | 
				
			||||||
			$year = $curr['year'];
 | 
								$year = $curr['year'];
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$start = mktime(0,0,0,$month,1,$year);
 | 
							$start = mktime(0, 0, 0, $month, 1, $year);
 | 
				
			||||||
		$end = mktime(0,0,0,$month, date("t",$start),$year)+24*60*60;
 | 
							$end = mktime(0, 0, 0, $month, date("t", $start), $year) + 24 * 60 * 60;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$start = mktime(0,0,0,$curr['mon'],1,$curr['year']);
 | 
							$start = mktime(0, 0, 0, $curr['mon'], 1, $curr['year']);
 | 
				
			||||||
		$end = time()+24*60*60;
 | 
							$end = time() + 24 * 60 * 60;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
set_form_date($start, "start");
 | 
					set_form_date($start, "start");
 | 
				
			||||||
set_form_date($end-24*60*60, "end");
 | 
					set_form_date($end - 24 * 60 * 60, "end");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if( $start > $end ) {
 | 
					if ($start > $end) {
 | 
				
			||||||
	$errors[] = getlocal("statistics.wrong.dates");
 | 
						$errors[] = getlocal("statistics.wrong.dates");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$link = connect();
 | 
					$link = connect();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page['reportByDate'] = select_multi_assoc("select DATE(dtmcreated) as date, COUNT(distinct threadid) as threads, SUM(${mysqlprefix}chatmessage.ikind = $kind_agent) as agents, SUM(${mysqlprefix}chatmessage.ikind = $kind_user) as users ".
 | 
					$page['reportByDate'] = select_multi_assoc("select DATE(dtmcreated) as date, COUNT(distinct threadid) as threads, SUM(${mysqlprefix}chatmessage.ikind = $kind_agent) as agents, SUM(${mysqlprefix}chatmessage.ikind = $kind_user) as users " .
 | 
				
			||||||
	 "from ${mysqlprefix}chatmessage where unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end group by DATE(dtmcreated) order by dtmcreated desc", $link);
 | 
															   "from ${mysqlprefix}chatmessage where unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end group by DATE(dtmcreated) order by dtmcreated desc", $link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page['reportByDateTotal'] = select_one_row("select COUNT(distinct threadid) as threads, SUM(${mysqlprefix}chatmessage.ikind = $kind_agent) as agents, SUM(${mysqlprefix}chatmessage.ikind = $kind_user) as users ".
 | 
					$page['reportByDateTotal'] = select_one_row("select COUNT(distinct threadid) as threads, SUM(${mysqlprefix}chatmessage.ikind = $kind_agent) as agents, SUM(${mysqlprefix}chatmessage.ikind = $kind_user) as users " .
 | 
				
			||||||
	 "from ${mysqlprefix}chatmessage where unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end", $link);
 | 
																"from ${mysqlprefix}chatmessage where unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end", $link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page['reportByAgent'] = select_multi_assoc("select vclocalename as name, COUNT(distinct threadid) as threads, SUM(ikind = $kind_agent) as msgs, AVG(CHAR_LENGTH(tmessage)) as avglen ".
 | 
					$page['reportByAgent'] = select_multi_assoc("select vclocalename as name, COUNT(distinct threadid) as threads, SUM(ikind = $kind_agent) as msgs, AVG(CHAR_LENGTH(tmessage)) as avglen " .
 | 
				
			||||||
	 "from ${mysqlprefix}chatmessage, ${mysqlprefix}chatoperator ".
 | 
																"from ${mysqlprefix}chatmessage, ${mysqlprefix}chatoperator " .
 | 
				
			||||||
         "where agentId = operatorid AND unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end group by operatorid", $link);
 | 
																"where agentId = operatorid AND unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end group by operatorid", $link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page['showresults'] = count($errors) == 0;
 | 
					$page['showresults'] = count($errors) == 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -31,7 +31,7 @@ $operator = check_login();
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$stylelist = array();
 | 
					$stylelist = array();
 | 
				
			||||||
$stylesfolder = "../styles";
 | 
					$stylesfolder = "../styles";
 | 
				
			||||||
if($handle = opendir($stylesfolder)) {
 | 
					if ($handle = opendir($stylesfolder)) {
 | 
				
			||||||
	while (false !== ($file = readdir($handle))) {
 | 
						while (false !== ($file = readdir($handle))) {
 | 
				
			||||||
		if (preg_match("/^\w+$/", $file) && is_dir("$stylesfolder/$file")) {
 | 
							if (preg_match("/^\w+$/", $file) && is_dir("$stylesfolder/$file")) {
 | 
				
			||||||
			$stylelist[] = $file;
 | 
								$stylelist[] = $file;
 | 
				
			||||||
@ -40,55 +40,55 @@ if($handle = opendir($stylesfolder)) {
 | 
				
			|||||||
	closedir($handle);
 | 
						closedir($handle);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$preview = verifyparam("preview","/^\w+$/", "default");
 | 
					$preview = verifyparam("preview", "/^\w+$/", "default");
 | 
				
			||||||
if(!in_array($preview, $stylelist)) {
 | 
					if (!in_array($preview, $stylelist)) {
 | 
				
			||||||
	$preview = $stylelist[0];
 | 
						$preview = $stylelist[0];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$show = verifyparam("show", "/^(chat|chatsimple|nochat|mail|mailsent|survey|leavemessage|leavemessagesent|redirect|redirected|agentchat|agentrochat|error)$/", "");
 | 
					$show = verifyparam("show", "/^(chat|chatsimple|nochat|mail|mailsent|survey|leavemessage|leavemessagesent|redirect|redirected|agentchat|agentrochat|error)$/", "");
 | 
				
			||||||
$showerrors = verifyparam("showerr", "/^on$/", "") == "on";
 | 
					$showerrors = verifyparam("showerr", "/^on$/", "") == "on";
 | 
				
			||||||
$errors = array();
 | 
					$errors = array();
 | 
				
			||||||
if($showerrors || $show == 'error') {
 | 
					if ($showerrors || $show == 'error') {
 | 
				
			||||||
	$errors[] = "Test error";
 | 
						$errors[] = "Test error";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if($show == 'chat' || $show == 'mail' || $show == 'leavemessage' || $show == 'leavemessagesent' || $show == 'chatsimple' || $show == 'nochat') {
 | 
					if ($show == 'chat' || $show == 'mail' || $show == 'leavemessage' || $show == 'leavemessagesent' || $show == 'chatsimple' || $show == 'nochat') {
 | 
				
			||||||
	setup_chatview_for_user(array('threadid' => 0,'userName' => getstring("chat.default.username"), 'ltoken' => 123), "ajaxed");
 | 
						setup_chatview_for_user(array('threadid' => 0, 'userName' => getstring("chat.default.username"), 'ltoken' => 123), "ajaxed");
 | 
				
			||||||
	$page['mailLink'] = "$webimroot/operator/themes.php?preview=$preview&show=mail";
 | 
						$page['mailLink'] = "$webimroot/operator/themes.php?preview=$preview&show=mail";
 | 
				
			||||||
	$page['info'] = "";
 | 
						$page['info'] = "";
 | 
				
			||||||
	expand("../styles", "$preview", "$show.tpl");
 | 
						expand("../styles", "$preview", "$show.tpl");
 | 
				
			||||||
	exit;
 | 
						exit;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
if($show == 'survey') {
 | 
					if ($show == 'survey') {
 | 
				
			||||||
	loadsettings();
 | 
						loadsettings();
 | 
				
			||||||
	setup_survey("Visitor", "", "", "", "http://google.com");
 | 
						setup_survey("Visitor", "", "", "", "http://google.com");
 | 
				
			||||||
	setup_logo();
 | 
						setup_logo();
 | 
				
			||||||
	expand("../styles", "$preview", "$show.tpl");
 | 
						expand("../styles", "$preview", "$show.tpl");
 | 
				
			||||||
	exit;
 | 
						exit;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
if($show == 'mailsent' || $show == 'error') {
 | 
					if ($show == 'mailsent' || $show == 'error') {
 | 
				
			||||||
	$page['email'] = "admin@yourdomain.com";
 | 
						$page['email'] = "admin@yourdomain.com";
 | 
				
			||||||
	setup_logo();
 | 
						setup_logo();
 | 
				
			||||||
	expand("../styles", "$preview", "$show.tpl");
 | 
						expand("../styles", "$preview", "$show.tpl");
 | 
				
			||||||
	exit;
 | 
						exit;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
if($show == 'redirect' || $show == 'redirected' || $show == 'agentchat' || $show == 'agentrochat' ) {
 | 
					if ($show == 'redirect' || $show == 'redirected' || $show == 'agentchat' || $show == 'agentrochat') {
 | 
				
			||||||
	setup_chatview_for_operator(
 | 
						setup_chatview_for_operator(
 | 
				
			||||||
		array(
 | 
							array(
 | 
				
			||||||
			'threadid' => 0,
 | 
								 'threadid' => 0,
 | 
				
			||||||
			'userName' => getstring("chat.default.username"),
 | 
								 'userName' => getstring("chat.default.username"),
 | 
				
			||||||
			'remote' => "1.2.3.4",
 | 
								 'remote' => "1.2.3.4",
 | 
				
			||||||
			'agentId' => 1,
 | 
								 'agentId' => 1,
 | 
				
			||||||
			'userid' => 'visitor1',
 | 
								 'userid' => 'visitor1',
 | 
				
			||||||
			'locale' => $current_locale,
 | 
								 'locale' => $current_locale,
 | 
				
			||||||
			'ltoken' => $show=='agentrochat' ? 124 : 123),
 | 
								 'ltoken' => $show == 'agentrochat' ? 124 : 123),
 | 
				
			||||||
		array(
 | 
							array(
 | 
				
			||||||
			'operatorid' => ($show=='agentrochat' ? 2 : 1),
 | 
								 'operatorid' => ($show == 'agentrochat' ? 2 : 1),
 | 
				
			||||||
			));
 | 
							));
 | 
				
			||||||
	if($show=='redirect') {
 | 
						if ($show == 'redirect') {
 | 
				
			||||||
		setup_redirect_links( 0,$show=='agentrochat' ? 124 : 123);
 | 
							setup_redirect_links(0, $show == 'agentrochat' ? 124 : 123);
 | 
				
			||||||
	} elseif($show=='redirected') {
 | 
						} elseif ($show == 'redirected') {
 | 
				
			||||||
		$page['message'] = getlocal2("chat.redirected.content",array("Administrator"));
 | 
							$page['message'] = getlocal2("chat.redirected.content", array("Administrator"));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$page['redirectLink'] = "$webimroot/operator/themes.php?preview=$preview&show=redirect";
 | 
						$page['redirectLink'] = "$webimroot/operator/themes.php?preview=$preview&show=redirect";
 | 
				
			||||||
	expand("../styles", "$preview", "$show.tpl");
 | 
						expand("../styles", "$preview", "$show.tpl");
 | 
				
			||||||
@ -126,12 +126,12 @@ $page['availableTemplates'] = array(
 | 
				
			|||||||
	"agentchat", "agentrochat", "error",
 | 
						"agentchat", "agentrochat", "error",
 | 
				
			||||||
	"all");
 | 
						"all");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page['showlink'] = "$webimroot/operator/themes.php?preview=$preview&".($showerrors?"showerr=on&":"")."show=";
 | 
					$page['showlink'] = "$webimroot/operator/themes.php?preview=$preview&" . ($showerrors ? "showerr=on&" : "") . "show=";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page['previewList'] = array();
 | 
					$page['previewList'] = array();
 | 
				
			||||||
foreach($templateList as $tpl) {
 | 
					foreach ($templateList as $tpl) {
 | 
				
			||||||
	if($tpl['id'] == $template || $template == 'all') {
 | 
						if ($tpl['id'] == $template || $template == 'all') {
 | 
				
			||||||
		 $page['previewList'][] = $tpl;
 | 
							$page['previewList'][] = $tpl;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -31,23 +31,24 @@ $page = array();
 | 
				
			|||||||
loadsettings();
 | 
					loadsettings();
 | 
				
			||||||
setlocale(LC_TIME, getstring("time.locale"));
 | 
					setlocale(LC_TIME, getstring("time.locale"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function thread_info($id) {
 | 
					function thread_info($id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
	$thread = select_one_row("select userName,agentName,remote,userAgent,".
 | 
						$thread = select_one_row("select userName,agentName,remote,userAgent," .
 | 
				
			||||||
			"unix_timestamp(dtmmodified) as modified, unix_timestamp(dtmcreated) as created,".
 | 
												 "unix_timestamp(dtmmodified) as modified, unix_timestamp(dtmcreated) as created," .
 | 
				
			||||||
			"vclocalname as groupName ".
 | 
												 "vclocalname as groupName " .
 | 
				
			||||||
			"from ${mysqlprefix}chatthread left join ${mysqlprefix}chatgroup on ${mysqlprefix}chatthread.groupid = ${mysqlprefix}chatgroup.groupid ".
 | 
												 "from ${mysqlprefix}chatthread left join ${mysqlprefix}chatgroup on ${mysqlprefix}chatthread.groupid = ${mysqlprefix}chatgroup.groupid " .
 | 
				
			||||||
			"where threadid = ". $id, $link );
 | 
												 "where threadid = " . $id, $link);
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
	return $thread;
 | 
						return $thread;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if( isset($_GET['threadid'])) {
 | 
					if (isset($_GET['threadid'])) {
 | 
				
			||||||
        $threadid = verifyparam( "threadid", "/^(\d{1,9})?$/", "");
 | 
						$threadid = verifyparam("threadid", "/^(\d{1,9})?$/", "");
 | 
				
			||||||
	$lastid = -1;
 | 
						$lastid = -1;
 | 
				
			||||||
	$page['threadMessages'] = get_messages($threadid,"html",false,$lastid);
 | 
						$page['threadMessages'] = get_messages($threadid, "html", false, $lastid);
 | 
				
			||||||
	$page['thread'] = thread_info($threadid);
 | 
						$page['thread'] = thread_info($threadid);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -23,27 +23,30 @@ require_once('../libs/common.php');
 | 
				
			|||||||
require_once('../libs/operator.php');
 | 
					require_once('../libs/operator.php');
 | 
				
			||||||
require_once('../libs/pagination.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;
 | 
						if ($a == $b) {
 | 
				
			||||||
    }
 | 
							return 0;
 | 
				
			||||||
    return ($a['l1'] < $b['l1']) ? -1 : 1;
 | 
						}
 | 
				
			||||||
 | 
						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;
 | 
						if ($a == $b) {
 | 
				
			||||||
    }
 | 
							return 0;
 | 
				
			||||||
    return ($a['id'] < $b['id']) ? -1 : 1;
 | 
						}
 | 
				
			||||||
 | 
						return ($a['id'] < $b['id']) ? -1 : 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function load_idlist($name) {
 | 
					function load_idlist($name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	$result = array();
 | 
						$result = array();
 | 
				
			||||||
	$fp = @fopen(dirname(__FILE__)."/../locales/names/$name", "r");
 | 
						$fp = @fopen(dirname(__FILE__) . "/../locales/names/$name", "r");
 | 
				
			||||||
	if($fp !== FALSE) {
 | 
						if ($fp !== FALSE) {
 | 
				
			||||||
		while (!feof($fp)) {
 | 
							while (!feof($fp)) {
 | 
				
			||||||
			$line = trim(fgets($fp, 4096));
 | 
								$line = trim(fgets($fp, 4096));
 | 
				
			||||||
			if($line && preg_match("/^[\w_\.]+$/", $line)) {
 | 
								if ($line && preg_match("/^[\w_\.]+$/", $line)) {
 | 
				
			||||||
				$result[] = $line;
 | 
									$result[] = $line;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -52,62 +55,64 @@ function load_idlist($name) {
 | 
				
			|||||||
	return $result;
 | 
						return $result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function save_message($locale,$key,$value) {
 | 
					function save_message($locale, $key, $value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $webim_encoding;
 | 
						global $webim_encoding;
 | 
				
			||||||
	$result = "";
 | 
						$result = "";
 | 
				
			||||||
	$added = false;
 | 
						$added = false;
 | 
				
			||||||
	$current_encoding = $webim_encoding;
 | 
						$current_encoding = $webim_encoding;
 | 
				
			||||||
	$fp = fopen(dirname(__FILE__)."/../locales/$locale/properties", "r");
 | 
						$fp = fopen(dirname(__FILE__) . "/../locales/$locale/properties", "r");
 | 
				
			||||||
	while (!feof($fp)) {
 | 
						while (!feof($fp)) {
 | 
				
			||||||
		$line = fgets($fp, 4096);
 | 
							$line = fgets($fp, 4096);
 | 
				
			||||||
		$keyval = preg_split("/=/", $line, 2 );
 | 
							$keyval = preg_split("/=/", $line, 2);
 | 
				
			||||||
		if( isset($keyval[1]) ) {
 | 
							if (isset($keyval[1])) {
 | 
				
			||||||
			if($keyval[0] == 'encoding') {
 | 
								if ($keyval[0] == 'encoding') {
 | 
				
			||||||
				$current_encoding = trim($keyval[1]);
 | 
									$current_encoding = trim($keyval[1]);
 | 
				
			||||||
			} else if(!$added && $keyval[0] == $key) {
 | 
								} else if (!$added && $keyval[0] == $key) {
 | 
				
			||||||
				$line = "$key=".myiconv($webim_encoding, $current_encoding, str_replace("\r", "",str_replace("\n", "\\n",trim($value))))."\n";
 | 
									$line = "$key=" . myiconv($webim_encoding, $current_encoding, str_replace("\r", "", str_replace("\n", "\\n", trim($value)))) . "\n";
 | 
				
			||||||
				$added = true;
 | 
									$added = true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$result .= $line;
 | 
							$result .= $line;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	fclose($fp);
 | 
						fclose($fp);
 | 
				
			||||||
	if(!$added) {
 | 
						if (!$added) {
 | 
				
			||||||
		$result .= "$key=".myiconv($webim_encoding, $current_encoding, str_replace("\r", "",str_replace("\n", "\\n",trim($value))))."\n";
 | 
							$result .= "$key=" . myiconv($webim_encoding, $current_encoding, str_replace("\r", "", str_replace("\n", "\\n", trim($value)))) . "\n";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$fp = @fopen(dirname(__FILE__)."/../locales/$locale/properties", "w");
 | 
						$fp = @fopen(dirname(__FILE__) . "/../locales/$locale/properties", "w");
 | 
				
			||||||
	if($fp !== FALSE) {
 | 
						if ($fp !== FALSE) {
 | 
				
			||||||
		fwrite($fp, $result);
 | 
							fwrite($fp, $result);
 | 
				
			||||||
		fclose($fp);
 | 
							fclose($fp);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		die("cannot write /locales/$locale/properties, please check file permissions on your server");
 | 
							die("cannot write /locales/$locale/properties, please check file permissions on your server");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$fp = @fopen(dirname(__FILE__)."/../locales/$locale/properties.log", "a");
 | 
						$fp = @fopen(dirname(__FILE__) . "/../locales/$locale/properties.log", "a");
 | 
				
			||||||
	if($fp !== FALSE) {
 | 
						if ($fp !== FALSE) {
 | 
				
			||||||
		$extAddr = $_SERVER['REMOTE_ADDR'];
 | 
							$extAddr = $_SERVER['REMOTE_ADDR'];
 | 
				
			||||||
		if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) &&
 | 
							if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) &&
 | 
				
			||||||
		          $_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR']) {
 | 
								$_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR']) {
 | 
				
			||||||
			$extAddr = $_SERVER['REMOTE_ADDR'].' ('.$_SERVER['HTTP_X_FORWARDED_FOR'].')';
 | 
								$extAddr = $_SERVER['REMOTE_ADDR'] . ' (' . $_SERVER['HTTP_X_FORWARDED_FOR'] . ')';
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$userbrowser = $_SERVER['HTTP_USER_AGENT'];
 | 
							$userbrowser = $_SERVER['HTTP_USER_AGENT'];
 | 
				
			||||||
		$remoteHost = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr;
 | 
							$remoteHost = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		fwrite($fp,"# ".date(DATE_RFC822)." by $remoteHost using $userbrowser\n");
 | 
							fwrite($fp, "# " . date(DATE_RFC822) . " by $remoteHost using $userbrowser\n");
 | 
				
			||||||
		fwrite($fp,"$key=".myiconv($webim_encoding, $current_encoding, str_replace("\r", "",str_replace("\n", "\\n",trim($value))))."\n");
 | 
							fwrite($fp, "$key=" . myiconv($webim_encoding, $current_encoding, str_replace("\r", "", str_replace("\n", "\\n", trim($value)))) . "\n");
 | 
				
			||||||
		fclose($fp);
 | 
							fclose($fp);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_auxiliary($s) {
 | 
					function get_auxiliary($s)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	$res = "";
 | 
						$res = "";
 | 
				
			||||||
	if(preg_match_all("/<[^>]+?>|[:]|\{\d+\}|[Mm]ibew|[Ww]ebim/", $s, $matches, PREG_PATTERN_ORDER)) {
 | 
						if (preg_match_all("/<[^>]+?>|[:]|\{\d+\}|[Mm]ibew|[Ww]ebim/", $s, $matches, PREG_PATTERN_ORDER)) {
 | 
				
			||||||
		foreach ($matches[0] as $val) {
 | 
							foreach ($matches[0] as $val) {
 | 
				
			||||||
			if($val != "<br/>") {
 | 
								if ($val != "<br/>") {
 | 
				
			||||||
				$res .= $val;
 | 
									$res .= $val;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if(substr(trim($s),-1) == "." || substr(trim($s),-1) == "?") {
 | 
						if (substr(trim($s), -1) == "." || substr(trim($s), -1) == "?") {
 | 
				
			||||||
		$res .= ".";
 | 
							$res .= ".";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return $res;
 | 
						return $res;
 | 
				
			||||||
@ -119,11 +124,11 @@ $source = verifyparam("source", "/^[\w-]{2,5}$/", $default_locale);
 | 
				
			|||||||
$target = verifyparam("target", "/^[\w-]{2,5}$/", $current_locale);
 | 
					$target = verifyparam("target", "/^[\w-]{2,5}$/", $current_locale);
 | 
				
			||||||
$stringid = verifyparam("key", "/^[_\.\w]+$/", "");
 | 
					$stringid = verifyparam("key", "/^[_\.\w]+$/", "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if(!isset($messages[$source])) {
 | 
					if (!isset($messages[$source])) {
 | 
				
			||||||
	load_messages($source);
 | 
						load_messages($source);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
$lang1 = $messages[$source];
 | 
					$lang1 = $messages[$source];
 | 
				
			||||||
if(!isset($messages[$target])) {
 | 
					if (!isset($messages[$target])) {
 | 
				
			||||||
	load_messages($target);
 | 
						load_messages($target);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
$lang2 = $messages[$target];
 | 
					$lang2 = $messages[$target];
 | 
				
			||||||
@ -136,16 +141,16 @@ $page = array(
 | 
				
			|||||||
	'title2' => isset($lang2["localeid"]) ? $lang2["localeid"] : $target
 | 
						'title2' => isset($lang2["localeid"]) ? $lang2["localeid"] : $target
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if($stringid) {
 | 
					if ($stringid) {
 | 
				
			||||||
	$translation = isset($lang2[$stringid]) ? $lang2[$stringid] : "";
 | 
						$translation = isset($lang2[$stringid]) ? $lang2[$stringid] : "";
 | 
				
			||||||
	if(isset($_POST['translation'])) {
 | 
						if (isset($_POST['translation'])) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$translation = getparam('translation');
 | 
							$translation = getparam('translation');
 | 
				
			||||||
		if(!$translation) {
 | 
							if (!$translation) {
 | 
				
			||||||
			$errors[] = no_field("form.field.translation");
 | 
								$errors[] = no_field("form.field.translation");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(count($errors) == 0) {
 | 
							if (count($errors) == 0) {
 | 
				
			||||||
			save_message($target, $stringid, $translation);
 | 
								save_message($target, $stringid, $translation);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$page['saved'] = true;
 | 
								$page['saved'] = true;
 | 
				
			||||||
@ -169,7 +174,7 @@ if($stringid) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$localesList = array();
 | 
					$localesList = array();
 | 
				
			||||||
$allLocales = get_available_locales();
 | 
					$allLocales = get_available_locales();
 | 
				
			||||||
foreach($allLocales as $loc) {
 | 
					foreach ($allLocales as $loc) {
 | 
				
			||||||
	$localesList[] = array("id" => $loc, "name" => getlocal_("localeid", $loc));
 | 
						$localesList[] = array("id" => $loc, "name" => getlocal_("localeid", $loc));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -177,35 +182,35 @@ $show = verifyparam("show", "/^(all|s1|s2|s3)$/", "all");
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$result = array();
 | 
					$result = array();
 | 
				
			||||||
$allkeys = array_keys($lang1);
 | 
					$allkeys = array_keys($lang1);
 | 
				
			||||||
if($show == 's1') {
 | 
					if ($show == 's1') {
 | 
				
			||||||
	$allkeys = array_intersect($allkeys, load_idlist('level1'));
 | 
						$allkeys = array_intersect($allkeys, load_idlist('level1'));
 | 
				
			||||||
} else if($show == 's2') {
 | 
					} else if ($show == 's2') {
 | 
				
			||||||
	$allkeys = array_intersect($allkeys, load_idlist('level2'));
 | 
						$allkeys = array_intersect($allkeys, load_idlist('level2'));
 | 
				
			||||||
} else if($show == 's3') {
 | 
					} else if ($show == 's3') {
 | 
				
			||||||
	$allkeys = array_diff($allkeys, load_idlist('level1'), load_idlist('level2'));
 | 
						$allkeys = array_diff($allkeys, load_idlist('level1'), load_idlist('level2'));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
foreach($allkeys as $key) {
 | 
					foreach ($allkeys as $key) {
 | 
				
			||||||
	if($key != 'output_charset') {
 | 
						if ($key != 'output_charset') {
 | 
				
			||||||
		$tsource = htmlspecialchars($lang1[$key]);
 | 
							$tsource = htmlspecialchars($lang1[$key]);
 | 
				
			||||||
		if(isset($lang2[$key])) {
 | 
							if (isset($lang2[$key])) {
 | 
				
			||||||
			$value = htmlspecialchars($lang2[$key]);
 | 
								$value = htmlspecialchars($lang2[$key]);
 | 
				
			||||||
			if(get_auxiliary($lang2[$key]) != get_auxiliary($lang1[$key])) {
 | 
								if (get_auxiliary($lang2[$key]) != get_auxiliary($lang1[$key])) {
 | 
				
			||||||
				$value = "<font color=\"#6030c1\"><b>$value</b></font> <strong>(wrong formatting)</strong>";
 | 
									$value = "<font color=\"#6030c1\"><b>$value</b></font> <strong>(wrong formatting)</strong>";
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			$value  = "<font color=\"#c13030\"><b>absent</b></font>";
 | 
								$value = "<font color=\"#c13030\"><b>absent</b></font>";
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$result[] = array(
 | 
							$result[] = array(
 | 
				
			||||||
				'id' => $key,
 | 
								'id' => $key,
 | 
				
			||||||
				'l1' => $tsource,
 | 
								'l1' => $tsource,
 | 
				
			||||||
				'l2' => $value );
 | 
								'l2' => $value);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$order = verifyparam("sort", "/^(id|l1)$/", "id");
 | 
					$order = verifyparam("sort", "/^(id|l1)$/", "id");
 | 
				
			||||||
usort($result, "compare_localization_by_$order");
 | 
					usort($result, "compare_localization_by_$order");
 | 
				
			||||||
setup_pagination($result,100);
 | 
					setup_pagination($result, 100);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$page['formtarget'] = $target;
 | 
					$page['formtarget'] = $target;
 | 
				
			||||||
$page['formsource'] = $source;
 | 
					$page['formsource'] = $source;
 | 
				
			||||||
 | 
				
			|||||||
@ -26,9 +26,9 @@ require_once('../libs/operator.php');
 | 
				
			|||||||
require_once('../libs/groups.php');
 | 
					require_once('../libs/groups.php');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$operator = get_logged_in();
 | 
					$operator = get_logged_in();
 | 
				
			||||||
if( !$operator ) {
 | 
					if (!$operator) {
 | 
				
			||||||
	start_xml_output();
 | 
						start_xml_output();
 | 
				
			||||||
	echo "<error><descr>".myiconv($webim_encoding,"utf-8",escape_with_cdata(getstring("agent.not_logged_in")))."</descr></error>";
 | 
						echo "<error><descr>" . myiconv($webim_encoding, "utf-8", escape_with_cdata(getstring("agent.not_logged_in"))) . "</descr></error>";
 | 
				
			||||||
	exit;
 | 
						exit;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -49,110 +49,113 @@ $threadstate_key = array(
 | 
				
			|||||||
	$state_loading => "chat.thread.state_loading"
 | 
						$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,
 | 
						global $state_chatting, $threadstate_to_string, $threadstate_key,
 | 
				
			||||||
			$webim_encoding, $operator, $settings,
 | 
					$webim_encoding, $operator, $settings,
 | 
				
			||||||
			$can_viewthreads, $can_takeover, $mysqlprefix;
 | 
					$can_viewthreads, $can_takeover, $mysqlprefix;
 | 
				
			||||||
	$state = $threadstate_to_string[$thread['istate']];
 | 
						$state = $threadstate_to_string[$thread['istate']];
 | 
				
			||||||
	$result = "<thread id=\"".$thread['threadid']."\" stateid=\"$state\"";
 | 
						$result = "<thread id=\"" . $thread['threadid'] . "\" stateid=\"$state\"";
 | 
				
			||||||
	if( $state == "closed" )
 | 
						if ($state == "closed")
 | 
				
			||||||
		return $result."/>";
 | 
							return $result . "/>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$state = getstring($threadstate_key[$thread['istate']]);
 | 
						$state = getstring($threadstate_key[$thread['istate']]);
 | 
				
			||||||
	$nextagent = $thread['nextagent'] != 0 ? operator_by_id_($thread['nextagent'],$link) : null;
 | 
						$nextagent = $thread['nextagent'] != 0 ? operator_by_id_($thread['nextagent'], $link) : null;
 | 
				
			||||||
	$threadoperator = $nextagent ? get_operator_name($nextagent)
 | 
						$threadoperator = $nextagent ? get_operator_name($nextagent)
 | 
				
			||||||
						: ($thread['agentName'] ? $thread['agentName'] : "-");
 | 
								: ($thread['agentName'] ? $thread['agentName'] : "-");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if($threadoperator == "-" && $thread['groupname']) {
 | 
						if ($threadoperator == "-" && $thread['groupname']) {
 | 
				
			||||||
		$threadoperator = "- ".$thread['groupname']." -";
 | 
							$threadoperator = "- " . $thread['groupname'] . " -";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(!($thread['istate'] == $state_chatting && $thread['agentId'] != $operator['operatorid'] && !is_capable($can_takeover,$operator))) {
 | 
						if (!($thread['istate'] == $state_chatting && $thread['agentId'] != $operator['operatorid'] && !is_capable($can_takeover, $operator))) {
 | 
				
			||||||
		$result .= " canopen=\"true\"";
 | 
							$result .= " canopen=\"true\"";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if ($thread['agentId'] != $operator['operatorid'] && $thread['nextagent'] != $operator['operatorid']
 | 
						if ($thread['agentId'] != $operator['operatorid'] && $thread['nextagent'] != $operator['operatorid']
 | 
				
			||||||
			&& is_capable($can_viewthreads, $operator)) {
 | 
							&& is_capable($can_viewthreads, $operator)) {
 | 
				
			||||||
		$result .= " canview=\"true\"";
 | 
							$result .= " canview=\"true\"";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if ($settings['enableban'] == "1") {
 | 
						if ($settings['enableban'] == "1") {
 | 
				
			||||||
		$result .= " canban=\"true\"";
 | 
							$result .= " canban=\"true\"";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$banForThread = $settings['enableban'] == "1" ? ban_for_addr_($thread['remote'],$link) : false;
 | 
						$banForThread = $settings['enableban'] == "1" ? ban_for_addr_($thread['remote'], $link) : false;
 | 
				
			||||||
	if($banForThread) {
 | 
						if ($banForThread) {
 | 
				
			||||||
		$result .= " ban=\"blocked\" banid=\"".$banForThread['banid']."\"";
 | 
							$result .= " ban=\"blocked\" banid=\"" . $banForThread['banid'] . "\"";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$result .= " state=\"$state\" typing=\"".$thread['userTyping']."\">";
 | 
						$result .= " state=\"$state\" typing=\"" . $thread['userTyping'] . "\">";
 | 
				
			||||||
	$result .="<name>";
 | 
						$result .= "<name>";
 | 
				
			||||||
	if($banForThread) {
 | 
						if ($banForThread) {
 | 
				
			||||||
		$result .= htmlspecialchars(getstring('chat.client.spam.prefix'));
 | 
							$result .= htmlspecialchars(getstring('chat.client.spam.prefix'));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$result .= htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'],$thread['remote'], $thread['userid'])))."</name>";
 | 
						$result .= htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'], $thread['remote'], $thread['userid']))) . "</name>";
 | 
				
			||||||
	$result .= "<addr>".htmlspecialchars(get_user_addr($thread['remote']))."</addr>";
 | 
						$result .= "<addr>" . htmlspecialchars(get_user_addr($thread['remote'])) . "</addr>";
 | 
				
			||||||
	$result .= "<agent>".htmlspecialchars(htmlspecialchars($threadoperator))."</agent>";
 | 
						$result .= "<agent>" . htmlspecialchars(htmlspecialchars($threadoperator)) . "</agent>";
 | 
				
			||||||
	$result .= "<time>".$thread['unix_timestamp(dtmcreated)']."000</time>";
 | 
						$result .= "<time>" . $thread['unix_timestamp(dtmcreated)'] . "000</time>";
 | 
				
			||||||
	$result .= "<modified>".$thread['unix_timestamp(dtmmodified)']."000</modified>";
 | 
						$result .= "<modified>" . $thread['unix_timestamp(dtmmodified)'] . "000</modified>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if($banForThread) {
 | 
						if ($banForThread) {
 | 
				
			||||||
		$result .= "<reason>".$banForThread['comment']."</reason>";
 | 
							$result .= "<reason>" . $banForThread['comment'] . "</reason>";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$userAgent = get_useragent_version($thread['userAgent']);
 | 
						$userAgent = get_useragent_version($thread['userAgent']);
 | 
				
			||||||
	$result .= "<useragent>".$userAgent."</useragent>";
 | 
						$result .= "<useragent>" . $userAgent . "</useragent>";
 | 
				
			||||||
	if( $thread["shownmessageid"] != 0 ) {
 | 
						if ($thread["shownmessageid"] != 0) {
 | 
				
			||||||
		$query = "select tmessage from ${mysqlprefix}chatmessage where messageid = ".$thread["shownmessageid"];
 | 
							$query = "select tmessage from ${mysqlprefix}chatmessage where messageid = " . $thread["shownmessageid"];
 | 
				
			||||||
		$line = select_one_row($query, $link);
 | 
							$line = select_one_row($query, $link);
 | 
				
			||||||
		if( $line ) {
 | 
							if ($line) {
 | 
				
			||||||
			$message = preg_replace("/[\r\n\t]+/", " ", $line["tmessage"]);
 | 
								$message = preg_replace("/[\r\n\t]+/", " ", $line["tmessage"]);
 | 
				
			||||||
			$result .= "<message>".htmlspecialchars(htmlspecialchars($message))."</message>";
 | 
								$result .= "<message>" . htmlspecialchars(htmlspecialchars($message)) . "</message>";
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$result .= "</thread>";
 | 
						$result .= "</thread>";
 | 
				
			||||||
	return $result;
 | 
						return $result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function print_pending_threads($groupids,$since) {
 | 
					function print_pending_threads($groupids, $since)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $webim_encoding, $settings, $state_closed, $state_left, $mysqlprefix;
 | 
						global $webim_encoding, $settings, $state_closed, $state_left, $mysqlprefix;
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$revision = $since;
 | 
						$revision = $since;
 | 
				
			||||||
	$output = array();
 | 
						$output = array();
 | 
				
			||||||
	$query = "select threadid, userName, agentName, unix_timestamp(dtmcreated), userTyping, ".
 | 
						$query = "select threadid, userName, agentName, unix_timestamp(dtmcreated), userTyping, " .
 | 
				
			||||||
			 "unix_timestamp(dtmmodified), lrevision, istate, remote, nextagent, agentId, userid, shownmessageid, userAgent, (select vclocalname from ${mysqlprefix}chatgroup where ${mysqlprefix}chatgroup.groupid = ${mysqlprefix}chatthread.groupid) as groupname ".
 | 
								 "unix_timestamp(dtmmodified), lrevision, istate, remote, nextagent, agentId, userid, shownmessageid, userAgent, (select vclocalname from ${mysqlprefix}chatgroup where ${mysqlprefix}chatgroup.groupid = ${mysqlprefix}chatthread.groupid) as groupname " .
 | 
				
			||||||
			 "from ${mysqlprefix}chatthread where lrevision > $since ".
 | 
								 "from ${mysqlprefix}chatthread where lrevision > $since " .
 | 
				
			||||||
			 ($since <= 0
 | 
								 ($since <= 0
 | 
				
			||||||
			 		? "AND istate <> $state_closed AND istate <> $state_left " 
 | 
										 ? "AND istate <> $state_closed AND istate <> $state_left "
 | 
				
			||||||
			 		: "").
 | 
										 : "") .
 | 
				
			||||||
			 ($settings['enablegroups'] == '1'
 | 
								 ($settings['enablegroups'] == '1'
 | 
				
			||||||
			 		? "AND (groupid is NULL".($groupids 
 | 
										 ? "AND (groupid is NULL" . ($groupids
 | 
				
			||||||
			 					? " OR groupid IN ($groupids)"
 | 
												 ? " OR groupid IN ($groupids)"
 | 
				
			||||||
			 					: "").
 | 
												 : "") .
 | 
				
			||||||
			 			  ") " 
 | 
										   ") "
 | 
				
			||||||
			 		: "").
 | 
										 : "") .
 | 
				
			||||||
			 "ORDER BY threadid";
 | 
								 "ORDER BY threadid";
 | 
				
			||||||
	$rows = select_multi_assoc($query, $link);
 | 
						$rows = select_multi_assoc($query, $link);
 | 
				
			||||||
	foreach ($rows as $row) {
 | 
						foreach ($rows as $row) {
 | 
				
			||||||
		$thread = thread_to_xml($row,$link);
 | 
							$thread = thread_to_xml($row, $link);
 | 
				
			||||||
		$output[] = $thread;
 | 
							$output[] = $thread;
 | 
				
			||||||
		if( $row['lrevision'] > $revision )
 | 
							if ($row['lrevision'] > $revision)
 | 
				
			||||||
			$revision = $row['lrevision'];
 | 
								$revision = $row['lrevision'];
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mysql_close($link);
 | 
						mysql_close($link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	echo "<threads revision=\"$revision\" time=\"".time()."000\">";
 | 
						echo "<threads revision=\"$revision\" time=\"" . time() . "000\">";
 | 
				
			||||||
	foreach( $output as $thr ) {
 | 
						foreach ($output as $thr) {
 | 
				
			||||||
		print myiconv($webim_encoding,"utf-8",$thr);
 | 
							print myiconv($webim_encoding, "utf-8", $thr);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	echo "</threads>";
 | 
						echo "</threads>";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function print_operators() {
 | 
					function print_operators()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	echo "<operators>";
 | 
						echo "<operators>";
 | 
				
			||||||
	$operators = operator_get_all();
 | 
						$operators = operator_get_all();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	foreach($operators as $operator) {
 | 
						foreach ($operators as $operator) {
 | 
				
			||||||
		if (!operator_is_online($operator))
 | 
							if (!operator_is_online($operator))
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -164,13 +167,13 @@ function print_operators() {
 | 
				
			|||||||
	echo "</operators>";
 | 
						echo "</operators>";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$since = verifyparam( "since", "/^\d{1,9}$/", 0);
 | 
					$since = verifyparam("since", "/^\d{1,9}$/", 0);
 | 
				
			||||||
$status = verifyparam( "status", "/^\d{1,2}$/", 0);
 | 
					$status = verifyparam("status", "/^\d{1,2}$/", 0);
 | 
				
			||||||
$showonline = verifyparam( "showonline", "/^1$/", 0);
 | 
					$showonline = verifyparam("showonline", "/^1$/", 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$link = connect();
 | 
					$link = connect();
 | 
				
			||||||
loadsettings_($link);
 | 
					loadsettings_($link);
 | 
				
			||||||
if(!isset($_SESSION['operatorgroups'])) {
 | 
					if (!isset($_SESSION['operatorgroups'])) {
 | 
				
			||||||
	$_SESSION['operatorgroups'] = get_operator_groupslist($operator['operatorid'], $link);
 | 
						$_SESSION['operatorgroups'] = get_operator_groupslist($operator['operatorid'], $link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
mysql_close($link);
 | 
					mysql_close($link);
 | 
				
			||||||
@ -178,10 +181,10 @@ $groupids = $_SESSION['operatorgroups'];
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
start_xml_output();
 | 
					start_xml_output();
 | 
				
			||||||
echo '<update>';
 | 
					echo '<update>';
 | 
				
			||||||
if($showonline) {
 | 
					if ($showonline) {
 | 
				
			||||||
	print_operators();
 | 
						print_operators();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
print_pending_threads($groupids,$since);
 | 
					print_pending_threads($groupids, $since);
 | 
				
			||||||
echo '</update>';
 | 
					echo '</update>';
 | 
				
			||||||
notify_operator_alive($operator['operatorid'], $status);
 | 
					notify_operator_alive($operator['operatorid'], $status);
 | 
				
			||||||
exit;
 | 
					exit;
 | 
				
			||||||
 | 
				
			|||||||
@ -34,8 +34,8 @@ $page = array(
 | 
				
			|||||||
	'version' => $version,
 | 
						'version' => $version,
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
foreach($default_extensions as $ext) {
 | 
					foreach ($default_extensions as $ext) {
 | 
				
			||||||
	if(!extension_loaded($ext)) {
 | 
						if (!extension_loaded($ext)) {
 | 
				
			||||||
		$page['phpVersion'] .= " $ext/absent";
 | 
							$page['phpVersion'] .= " $ext/absent";
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		$ver = phpversion($ext);
 | 
							$ver = phpversion($ext);
 | 
				
			||||||
 | 
				
			|||||||
@ -33,23 +33,24 @@ $page = array();
 | 
				
			|||||||
setlocale(LC_TIME, getstring("time.locale"));
 | 
					setlocale(LC_TIME, getstring("time.locale"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$userid = "";
 | 
					$userid = "";
 | 
				
			||||||
if( isset($_GET['userid'])) {
 | 
					if (isset($_GET['userid'])) {
 | 
				
			||||||
	$userid = verifyparam( "userid", "/^.{0,63}$/", "");
 | 
						$userid = verifyparam("userid", "/^.{0,63}$/", "");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function threads_by_userid($userid) {
 | 
					function threads_by_userid($userid)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	global $mysqlprefix;
 | 
						global $mysqlprefix;
 | 
				
			||||||
	if ($userid == "") {
 | 
						if ($userid == "") {
 | 
				
			||||||
	    return null;
 | 
							return null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	$link = connect();
 | 
						$link = connect();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$query = sprintf("select unix_timestamp(dtmcreated) as created, unix_timestamp(dtmmodified) as modified, ".
 | 
						$query = sprintf("select unix_timestamp(dtmcreated) as created, unix_timestamp(dtmmodified) as modified, " .
 | 
				
			||||||
			 " threadid, remote, agentName, userName ".
 | 
										 " threadid, remote, agentName, userName " .
 | 
				
			||||||
			 "from ${mysqlprefix}chatthread ".
 | 
										 "from ${mysqlprefix}chatthread " .
 | 
				
			||||||
			 "where userid=\"$userid\" order by created DESC", $userid);
 | 
										 "where userid=\"$userid\" order by created DESC", $userid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$result = mysql_query($query, $link) or die(' Query failed: ' .mysql_error().": ".$query);
 | 
						$result = mysql_query($query, $link) or die(' Query failed: ' . mysql_error() . ": " . $query);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$foundThreads = array();
 | 
						$foundThreads = array();
 | 
				
			||||||
	while ($thread = mysql_fetch_array($result, MYSQL_ASSOC)) {
 | 
						while ($thread = mysql_fetch_array($result, MYSQL_ASSOC)) {
 | 
				
			||||||
@ -64,7 +65,7 @@ function threads_by_userid($userid) {
 | 
				
			|||||||
$found = threads_by_userid($userid);
 | 
					$found = threads_by_userid($userid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
prepare_menu($operator);
 | 
					prepare_menu($operator);
 | 
				
			||||||
setup_pagination($found,6);
 | 
					setup_pagination($found, 6);
 | 
				
			||||||
start_html_output();
 | 
					start_html_output();
 | 
				
			||||||
require('../view/userhistory.php');
 | 
					require('../view/userhistory.php');
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user