Files
EQN/appServer/distquake_download_chattest.php
2017-09-22 15:16:26 +02:00

83 lines
2.4 KiB
PHP

<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
mysql_set_charset("utf8");
$idmin=$_REQUEST['idmin'];
$postfix=$_REQUEST['postfix'];
$nick=$_REQUEST['nick'];
$password=$_REQUEST['password'];
$table="chat".$postfix;
if (strcmp($postfix,'_ita_gen')==0){
$online_table='online_chat_ita';
}
if (strcmp($postfix,'_es_gen')==0){
$online_table='online_chat_es';
}
if (strcmp($postfix,'_eng_gen')==0){
$online_table='online_chat_eng';
}
if (strcmp($postfix,'_pt_gen')==0){
$online_table='online_chat_pt';
}
if (strcmp($postfix,'_jp_gen')==0){
$online_table='online_chat_jp';
}
if (strcmp($postfix,'_zh_gen')==0){
$online_table='online_chat_zh';
}
$sql=mysql_query("select user_code,moderator from contest_nick where nick='$nick' and pwd='$password' limit 1");
if (mysql_num_rows($sql)){
$match=1;
$user_code=mysql_result($sql,0,"user_code");
$moderator=mysql_result($sql,0,"moderator");
}
else{
$match=0;
}
if ($match==1){
$sql=mysql_query("replace into $online_table (user_code,nick,moderator,date) values ($user_code,'$nick',$moderator,NOW())");
$q=mysql_query("SELECT * FROM (SELECT ID,user_code as user_id,nick,message,moderator,weather,day,TIMESTAMPDIFF(MINUTE,date, NOW()) AS difference FROM $table where ID>$idmin order by ID desc limit 250) AS dummy ORDER BY ID");
if (mysql_num_rows($q))
{
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
switch (json_last_error()) {
case JSON_ERROR_NONE:
echo ' - No errors';
break;
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
echo ' - Unknown error';
break;
}
}
else{
print("no_new");
}
}
mysql_close();
?>