".myiconv($webim_encoding,"utf-8",escape_with_cdata(getstring("agent.not_logged_in")))."";
exit;
}
$threadstate_to_string = array(
$state_queue => "wait",
$state_waiting => "prio",
$state_chatting => "chat",
$state_closed => "closed"
);
$threadstate_key = array(
$state_queue => "chat.thread.state_wait",
$state_waiting => "chat.thread.state_wait_for_another_agent",
$state_chatting => "chat.thread.state_chatting_with_agent",
$state_closed => "chat.thread.state_closed"
);
function thread_to_xml($thread) {
global $threadstate_to_string, $threadstate_key, $webim_encoding;
$state = $threadstate_to_string[$thread['istate']];
$result = "";
$state = getstring($threadstate_key[$thread['istate']]);
$threadoperator = ($thread['agentName'] ? $thread['agentName'] : "-");
$result .= " canopen=\"true\"";
$result .= " state=\"$state\" typing=\"".$thread['userTyping']."\">";
$result .= "".htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'])))."";
$result .= "".htmlspecialchars(htmlspecialchars($thread['remote']))."";
$result .= "".htmlspecialchars(htmlspecialchars($threadoperator))."";
$result .= "";
$result .= "".$thread['unix_timestamp(dtmmodified)']."000";
$result .= "";
return $result;
}
function print_pending_threads($since) {
global $webim_encoding;
$link = connect();
$revision = $since;
$output = array();
$query = "select threadid, userName, agentName, unix_timestamp(dtmcreated), userTyping, ".
"unix_timestamp(dtmmodified), lrevision, istate, remote ".
"from chatthread where lrevision > $since ORDER BY threadid";
$result = mysql_query($query,$link) or die(' Query failed: ' .mysql_error().": ".$query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$thread = thread_to_xml($row);
$output[] = $thread;
if( $row['lrevision'] > $revision )
$revision = $row['lrevision'];
}
mysql_free_result($result);
mysql_close($link);
start_xml_output();
echo "";
foreach( $output as $thr ) {
print myiconv($webim_encoding,"utf-8",$thr);
}
echo "";
}
////////
$since = verifyparam( "since", "/^\d{1,9}$/", 0);
print_pending_threads($since);
notify_operator_alive($operator['operatorid']);
exit;
?>