mirror of
				https://github.com/Mibew/tray.git
				synced 2025-10-03 00:03:34 +03:00 
			
		
		
		
	Fixed bug with placeholders and sql functions
This commit is contained in:
		
							parent
							
								
									63ab503077
								
							
						
					
					
						commit
						f54acb3ae5
					
				@ -511,29 +511,27 @@ function setup_chatview_for_operator($thread, $operator)
 | 
			
		||||
	$page['frequency'] = Settings::get('updatefrequency_chat');
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function update_thread_access($threadid, $params)
 | 
			
		||||
{
 | 
			
		||||
	$db = Database::getInstance();
 | 
			
		||||
	$clause = "";
 | 
			
		||||
	$values = array();
 | 
			
		||||
	foreach ($params as $k => $v) {
 | 
			
		||||
		if (strlen($clause) > 0)
 | 
			
		||||
			$clause .= ", ";
 | 
			
		||||
		$clause .= $k . "=?";
 | 
			
		||||
		$values[] = $v;
 | 
			
		||||
	}
 | 
			
		||||
	$values[] = $threadid;
 | 
			
		||||
 | 
			
		||||
	$db->query(
 | 
			
		||||
		"update {chatthread} set {$clause} where threadid = ?",
 | 
			
		||||
		$values
 | 
			
		||||
	);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Pings the chat thread. Updates 'lastpinguser' (or 'lastpingagent') to current timestamp. 
 | 
			
		||||
 * Sends system messages when operator or user was seen more than $connection_timeout seconds ago
 | 
			
		||||
 *
 | 
			
		||||
 * @global int $kind_for_agent
 | 
			
		||||
 * @global int $state_queue
 | 
			
		||||
 * @global int $state_loading
 | 
			
		||||
 * @global int $state_chatting
 | 
			
		||||
 * @global int $state_waiting
 | 
			
		||||
 * @global int $kind_conn
 | 
			
		||||
 * @global int $connection_timeout
 | 
			
		||||
 * @param array $thread Thread's array
 | 
			
		||||
 * @param boolean $isuser true for user and false for operator
 | 
			
		||||
 * @param boolean $istyping true if user (or agent) is typing
 | 
			
		||||
 */
 | 
			
		||||
function ping_thread($thread, $isuser, $istyping)
 | 
			
		||||
{
 | 
			
		||||
	global $kind_for_agent, $state_queue, $state_loading, $state_chatting, $state_waiting, $kind_conn, $connection_timeout;
 | 
			
		||||
 | 
			
		||||
	$db = Database::getInstance();
 | 
			
		||||
 | 
			
		||||
	$params = array(($isuser ? "lastpinguser" : "lastpingagent") => "CURRENT_TIMESTAMP",
 | 
			
		||||
					($isuser ? "userTyping" : "agentTyping") => ($istyping ? "1" : "0"));
 | 
			
		||||
 | 
			
		||||
@ -562,20 +560,49 @@ function ping_thread($thread, $isuser, $istyping)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	update_thread_access($thread['threadid'], $params);
 | 
			
		||||
	$clause = "";
 | 
			
		||||
	$values = array();
 | 
			
		||||
	foreach ($params as $k => $v) {
 | 
			
		||||
		if (strlen($clause) > 0) {
 | 
			
		||||
			$clause .= ", ";
 | 
			
		||||
		}
 | 
			
		||||
		if (($k == 'lastpinguser' || $k == 'lastpingagent') && $v == 'CURRENT_TIMESTAMP') {
 | 
			
		||||
			$clause .= $k . " = CURRENT_TIMESTAMP";
 | 
			
		||||
		}else{
 | 
			
		||||
			$clause .= $k . "=?";
 | 
			
		||||
			$values[] = $v;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	$values[] = $thread['threadid'];
 | 
			
		||||
 | 
			
		||||
	$db->query(
 | 
			
		||||
		"update {chatthread} set {$clause} where threadid = ?",
 | 
			
		||||
		$values
 | 
			
		||||
	);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function commit_thread($threadid, $params)
 | 
			
		||||
{
 | 
			
		||||
	$db = Database::getInstance();
 | 
			
		||||
 | 
			
		||||
	$timestamp_allowed_for = array(
 | 
			
		||||
		'dtmcreated',
 | 
			
		||||
		'dtmchatstarted',
 | 
			
		||||
		'dtmmodified',
 | 
			
		||||
		'lastpinguser',
 | 
			
		||||
		'lastpingagent'
 | 
			
		||||
	);
 | 
			
		||||
	$query = "update {chatthread} t " .
 | 
			
		||||
		"set lrevision = ?, dtmmodified = CURRENT_TIMESTAMP";
 | 
			
		||||
		$values = array(next_revision());
 | 
			
		||||
	foreach ($params as $k => $v) {
 | 
			
		||||
		if (in_array($k, $timestamp_allowed_for) && strcasecmp($v,'CURRENT_TIMESTAMP')) {
 | 
			
		||||
			$query .= ", " . $k . " = CURRENT_TIMESTAMP";
 | 
			
		||||
		} else {
 | 
			
		||||
			$query .= ", " . $k . "=?";
 | 
			
		||||
			$values[] = $v;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	$query .= " where threadid = ?";
 | 
			
		||||
	$values[] = $threadid;
 | 
			
		||||
 | 
			
		||||
@ -598,12 +625,21 @@ function close_thread($thread, $isuser)
 | 
			
		||||
{
 | 
			
		||||
	global $state_closed, $kind_events;
 | 
			
		||||
 | 
			
		||||
	$db = Database::getInstance();
 | 
			
		||||
	list($message_count) = $db->query(
 | 
			
		||||
		"SELECT COUNT(*) FROM {chatmessage} WHERE {chatmessage}.threadid = ? AND ikind = 1",
 | 
			
		||||
		array($thread['threadid']),
 | 
			
		||||
		array(
 | 
			
		||||
			'return_rows' => Database::RETURN_ONE_ROW,
 | 
			
		||||
			'fetch_type' => Database::FETCH_NUM
 | 
			
		||||
		)
 | 
			
		||||
	);
 | 
			
		||||
	if ($thread['istate'] != $state_closed) {
 | 
			
		||||
		commit_thread(
 | 
			
		||||
			$thread['threadid'],
 | 
			
		||||
			array(
 | 
			
		||||
				'istate' => $state_closed,
 | 
			
		||||
				'messageCount' => "(SELECT COUNT(*) FROM {chatmessage} WHERE {chatmessage}.threadid = t.threadid AND ikind = 1)"
 | 
			
		||||
				'messageCount' => $message_count
 | 
			
		||||
			)
 | 
			
		||||
		);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -183,21 +183,25 @@ function operator_is_disabled($operator)
 | 
			
		||||
function update_operator($operatorid, $login, $email, $password, $localename, $commonname)
 | 
			
		||||
{
 | 
			
		||||
	$db = Database::getInstance();
 | 
			
		||||
	$values = array(
 | 
			
		||||
		':login' => $login,
 | 
			
		||||
		':localname' => $localename,
 | 
			
		||||
		':commonname' => $commonname,
 | 
			
		||||
		':email' => $email,
 | 
			
		||||
		':jabbername' => '',
 | 
			
		||||
		':operatorid' => $operatorid
 | 
			
		||||
	);
 | 
			
		||||
	if ($password) {
 | 
			
		||||
		$values[':password'] = md5($password);
 | 
			
		||||
	}
 | 
			
		||||
	$db->query(
 | 
			
		||||
		"update {chatoperator} set vclogin = :login, " .
 | 
			
		||||
		($password ? " vcpassword=:password, " : "") .
 | 
			
		||||
		"vclocalename = :localname, vccommonname = :commonname, " .
 | 
			
		||||
		"vcemail = :email, vcjabbername= :jabbername " .
 | 
			
		||||
		"where operatorid = :operatorid",
 | 
			
		||||
		array(
 | 
			
		||||
			':login' => $login,
 | 
			
		||||
			':password' => $password,
 | 
			
		||||
			':localname' => $localename,
 | 
			
		||||
			':commonname' => $commonname,
 | 
			
		||||
			':email' => $email,
 | 
			
		||||
			':jabbername' => '',
 | 
			
		||||
			':operatorid' => $operatorid
 | 
			
		||||
		)
 | 
			
		||||
		$values
 | 
			
		||||
 | 
			
		||||
	);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -544,6 +548,7 @@ function get_groups_($checkaway, $operator, $order = NULL)
 | 
			
		||||
		$orderby = "iweight, vclocalname";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	$values = array();
 | 
			
		||||
	$query = "select {chatgroup}.groupid as groupid, {chatgroup}.parent as parent, vclocalname, vclocaldescription, iweight" .
 | 
			
		||||
		", (SELECT count(*) from {chatgroupoperator} where {chatgroup}.groupid = " .
 | 
			
		||||
		"{chatgroupoperator}.groupid) as inumofagents" .
 | 
			
		||||
@ -558,17 +563,17 @@ function get_groups_($checkaway, $operator, $order = NULL)
 | 
			
		||||
			"and {chatgroupoperator}.operatorid = {chatoperator}.operatorid) as ilastseenaway"
 | 
			
		||||
			: ""
 | 
			
		||||
		) .
 | 
			
		||||
		" from {chatgroup} " .
 | 
			
		||||
		($operator
 | 
			
		||||
			? ", (select distinct parent from {chatgroup}, {chatgroupoperator} " .
 | 
			
		||||
		" from {chatgroup} ";
 | 
			
		||||
	if ($operator) {
 | 
			
		||||
		$query .= ", (select distinct parent from {chatgroup}, {chatgroupoperator} " .
 | 
			
		||||
			"where {chatgroup}.groupid = {chatgroupoperator}.groupid and {chatgroupoperator}.operatorid = ?) i " .
 | 
			
		||||
			"where {chatgroup}.groupid = i.parent or {chatgroup}.parent = i.parent "
 | 
			
		||||
			: ""
 | 
			
		||||
		) .
 | 
			
		||||
		" order by " . $orderby;
 | 
			
		||||
			"where {chatgroup}.groupid = i.parent or {chatgroup}.parent = i.parent ";
 | 
			
		||||
		$values[] = $operator['operatorid'];
 | 
			
		||||
	}
 | 
			
		||||
	$query .= " order by " . $orderby;
 | 
			
		||||
	$groups = $db->query(
 | 
			
		||||
		$query,
 | 
			
		||||
		array($operator['operatorid']),
 | 
			
		||||
		$values,
 | 
			
		||||
		array('return_rows' => Database::RETURN_ALL_ROWS)
 | 
			
		||||
	);
 | 
			
		||||
	return get_sorted_child_groups_($groups);
 | 
			
		||||
 | 
			
		||||
@ -48,9 +48,7 @@ if ($query !== false) {
 | 
			
		||||
	$page['groupName'] = $groupName;
 | 
			
		||||
 | 
			
		||||
	$values = array(
 | 
			
		||||
		':query' => "%{$escapedQuery}%",
 | 
			
		||||
		':kind_user' => $kind_user,
 | 
			
		||||
		':kind_agent' => $kind_agent
 | 
			
		||||
		':query' => "%{$escapedQuery}%"
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	$searchConditions = array();
 | 
			
		||||
@ -58,6 +56,8 @@ if ($query !== false) {
 | 
			
		||||
		$searchConditions[] = "({chatmessage}.tmessage LIKE :query" .
 | 
			
		||||
					($searchInSystemMessages?'':" AND ({chatmessage}.ikind = :kind_user OR {chatmessage}.ikind = :kind_agent)") .
 | 
			
		||||
					")";
 | 
			
		||||
		$values[':kind_user'] = $kind_user;
 | 
			
		||||
		$values[':kind_agent'] = $kind_agent;
 | 
			
		||||
	}
 | 
			
		||||
	if ($searchType == 'operator' || $searchType == 'all') {
 | 
			
		||||
		$searchConditions[] = "({chatthread}.agentName LIKE :query)";
 | 
			
		||||
 | 
			
		||||
@ -135,9 +135,7 @@ function print_pending_threads($groupids, $since)
 | 
			
		||||
		"ORDER BY threadid";
 | 
			
		||||
	$rows = $db->query(
 | 
			
		||||
		$query,
 | 
			
		||||
		array(
 | 
			
		||||
			':since' => $since
 | 
			
		||||
		),
 | 
			
		||||
		array(':since' => $since),
 | 
			
		||||
		array('return_rows' => Database::RETURN_ALL_ROWS)
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user