422 lines
14 KiB
PHP
422 lines
14 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']);
|
|
|
|
if ($ini['db']['log']=="1"){
|
|
$arrival_time=microtime(true);
|
|
$filename=basename(__FILE__);
|
|
$filename="log_".$filename.".txt";
|
|
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
|
|
file_put_contents($filename,$chunck,FILE_APPEND);
|
|
}
|
|
|
|
mysql_set_charset("utf8");
|
|
|
|
$user_id=$_REQUEST['u_id'];
|
|
$nick=$_REQUEST['nick'];
|
|
$password=$_REQUEST['password'];
|
|
$message_gcm=$_REQUEST['message'];
|
|
|
|
$message=mysql_real_escape_string($message_gcm);
|
|
$postfix=$_REQUEST['postfix'];
|
|
if (!empty($_REQUEST['u_code'])){
|
|
$user_code=$_REQUEST['u_code'];
|
|
}
|
|
else{
|
|
$user_code=0;
|
|
}
|
|
if (!empty($_REQUEST['msg_code'])){
|
|
$msg_code=$_REQUEST['msg_code'];
|
|
}
|
|
else{
|
|
$msg_code=0;
|
|
}
|
|
if (!empty($_REQUEST['ver'])){
|
|
$ver=$_REQUEST['ver'];
|
|
}
|
|
else{
|
|
$ver=0;
|
|
}
|
|
|
|
$sql=mysql_query("select * from banned where user_id=$user_id LIMIT 1");
|
|
if (mysql_num_rows($sql)){
|
|
$banned=1;
|
|
}
|
|
else{
|
|
$banned=0;
|
|
}
|
|
|
|
if($message!=='' && $banned==0 && $ver>=1)
|
|
{
|
|
if (strcmp($postfix,'_ita_gen')==0){
|
|
$id_notification=3;
|
|
$table_online="online_chat_ita";
|
|
}
|
|
if (strcmp($postfix,'_es_gen')==0){
|
|
$id_notification=2;
|
|
$table_online="online_chat_es";
|
|
}
|
|
if (strcmp($postfix,'_eng_gen')==0){
|
|
$id_notification=1;
|
|
$table_online="online_chat_eng";
|
|
}
|
|
if (strcmp($postfix,'_pt_gen')==0){
|
|
$id_notification=5;
|
|
$table_online="online_chat_pt";
|
|
}
|
|
if (strcmp($postfix,'_jp_gen')==0){
|
|
$id_notification=4;
|
|
$table_online="online_chat_jp";
|
|
}
|
|
if (strcmp($postfix,'_zh_gen')==0){
|
|
$id_notification=6;
|
|
$table_online="online_chat_zh";
|
|
}
|
|
if (strcmp($postfix,'_tag_gen')==0){
|
|
$id_notification=7;
|
|
$table_online="online_chat_tag";
|
|
}
|
|
|
|
$table_chat="chat".$postfix;
|
|
|
|
$can_notify=0;
|
|
if ($user_code!=0){
|
|
$sql=mysql_query("select ID,user_code,moderator,last_known_user_id from contest_nick where user_code=$user_code limit 1");
|
|
}
|
|
else{
|
|
$sql=mysql_query("select ID,user_code,moderator,last_known_user_id from contest_nick where nick='$nick' and pwd='$password' limit 1");
|
|
}
|
|
if (mysql_num_rows($sql))
|
|
{
|
|
$user_code=mysql_result($sql,0,"user_code");
|
|
$last_known_user_id=mysql_result($sql,0,"last_known_user_id");
|
|
$id=mysql_result($sql,0,"ID");
|
|
$moderator=mysql_result($sql,0,"moderator");
|
|
if ($user_id<>$last_known_user_id){
|
|
$sql=mysql_query("update contest_nick set last_known_user_id=$user_id where ID=$id");
|
|
}
|
|
$match=1;
|
|
}
|
|
else
|
|
{
|
|
$match=0;
|
|
}
|
|
|
|
if ($match==1 && $user_id<>0){
|
|
$sql=mysql_query("replace into $table_online (user_code,user_id,nick,moderator,date) values ($user_code,$user_id,'$nick',$moderator,NOW())");
|
|
$sql=mysql_query("insert into $table_chat (user_id,user_code,message,nick,moderator) values ($user_id,$user_code,'$message','$nick',$moderator)");
|
|
$new_insert_id=mysql_insert_id();
|
|
$output="ok";
|
|
$can_notify=1;
|
|
}
|
|
else
|
|
{
|
|
$output="wrong_id";
|
|
$new_insert_id=0;
|
|
}
|
|
|
|
ob_start();
|
|
$buffer = str_repeat(" ", 4096)."\r\n<span></span>\r\n";
|
|
$out=$output.$buffer;
|
|
print($out);
|
|
ob_end_flush();
|
|
flush();
|
|
|
|
if ($match==1 && $user_id<>0){
|
|
$sql=mysql_query("SELECT reg_id from gcm T1 join $table_online T2 on T1.user_id=T2.user_id where T2.status=0 and T1.reg_id<>''");
|
|
if (mysql_num_rows($sql))
|
|
{
|
|
$dataArray = array('postfix'=>$postfix,
|
|
'msg'=>$message_gcm,
|
|
'user_code'=>$user_code,
|
|
'moderator'=>$moderator,
|
|
'new_id'=>$new_insert_id,
|
|
'nick'=>$nick,
|
|
'msg_code'=>$msg_code,
|
|
'type'=>'chat_public');
|
|
|
|
$num_rows = mysql_num_rows($sql);
|
|
while($data = mysql_fetch_assoc($sql)){
|
|
$regidArray[] = $data['reg_id'];
|
|
}
|
|
|
|
$block_size=999;
|
|
$iter=ceil($num_rows/$block_size);
|
|
|
|
for ($i=0; $i<$iter; $i++){
|
|
$index_start=$i*$block_size;
|
|
$index_end=($i+1)*$block_size-1;
|
|
if ($index_end>$num_rows-1){
|
|
$index_end=$num_rows-1;
|
|
}
|
|
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
|
|
|
|
$headers = array(
|
|
'Authorization: key=AIzaSyAYaXDEapyd-mF9V9LNW1dmuoS-ea9GwWI',
|
|
'Content-Type: application/json');
|
|
|
|
$fields = array(
|
|
'registration_ids' => $regidArrayGCM,
|
|
'time_to_live' => 3600,
|
|
'data' => $dataArray);
|
|
|
|
$context = stream_context_create(array(
|
|
'http' => array(
|
|
'method' => 'POST',
|
|
'header' => $headers,
|
|
'content' => json_encode($fields))));
|
|
$response = file_get_contents('https://android.googleapis.com/gcm/send', FALSE, $context);
|
|
}
|
|
}
|
|
|
|
$sql2=mysql_query("SELECT TIMESTAMPDIFF(SECOND,last_notification,NOW()) AS difference from chat_last_notification where ID=$id_notification");
|
|
$difference=mysql_result($sql2,0,"difference");
|
|
if ($difference<20){
|
|
$can_notify=0;
|
|
}
|
|
|
|
if ($can_notify==1){
|
|
$dataArray = array('postfix'=>$postfix,'type'=>'chat');
|
|
|
|
if (strcmp($postfix,'_ita_gen')==0){
|
|
$sql2=mysql_query("select reg_id from gcm where cno_ita=1 and user_id<>$user_id");
|
|
}
|
|
if (strcmp($postfix,'_es_gen')==0){
|
|
$sql2=mysql_query("select reg_id from gcm where cno_es=1 and user_id<>$user_id");
|
|
}
|
|
if (strcmp($postfix,'_eng_gen')==0){
|
|
$sql2=mysql_query("select reg_id from gcm where cno_eng=1 and user_id<>$user_id");
|
|
}
|
|
if (strcmp($postfix,'_pt_gen')==0){
|
|
$sql2=mysql_query("select reg_id from gcm where cno_pt=1 and user_id<>$user_id");
|
|
}
|
|
if (strcmp($postfix,'_jp_gen')==0){
|
|
$sql2=mysql_query("select reg_id from gcm where cno_jp=1 and user_id<>$user_id");
|
|
}
|
|
if (strcmp($postfix,'_zh_gen')==0){
|
|
$sql2=mysql_query("select reg_id from gcm where cno_zh=1 and user_id<>$user_id");
|
|
}
|
|
if (strcmp($postfix,'_tag_gen')==0){
|
|
$sql2=mysql_query("select reg_id from gcm where cno_tag=1 and user_id<>$user_id");
|
|
}
|
|
|
|
$num_rows2 = mysql_num_rows($sql2);
|
|
while($data = mysql_fetch_assoc($sql2)){
|
|
$regidArray[] = $data['reg_id'];
|
|
}
|
|
|
|
$block_size=999;
|
|
$iter=ceil($num_rows2/$block_size);
|
|
|
|
for ($i=0; $i<$iter; $i++){
|
|
$index_start=$i*$block_size;
|
|
$index_end=($i+1)*$block_size-1;
|
|
if ($index_end>$num_rows2-1){
|
|
$index_end=$num_rows2-1;
|
|
}
|
|
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
|
|
|
|
$headers = array(
|
|
'Authorization: key=AIzaSyAYaXDEapyd-mF9V9LNW1dmuoS-ea9GwWI',
|
|
'Content-Type: application/json');
|
|
|
|
$fields = array(
|
|
'registration_ids' => $regidArrayGCM,
|
|
'time_to_live' => 120,
|
|
'data' => $dataArray);
|
|
|
|
$context = stream_context_create(array(
|
|
'http' => array(
|
|
'method' => 'POST',
|
|
'header' => $headers,
|
|
'content' => json_encode($fields))));
|
|
$response = file_get_contents('https://android.googleapis.com/gcm/send', FALSE, $context);
|
|
}
|
|
$sql=mysql_query("update chat_last_notification set last_notification=NOW() where ID=$id_notification");
|
|
}
|
|
}
|
|
$send_chat_message=0;
|
|
|
|
if (strcmp($postfix,'_ita_gen')==0){
|
|
$s1='Come si configura la app?';
|
|
$s2='Come si attiva la allarme?';
|
|
$s3='Chi mi aiuta con la app?';
|
|
$s4='Sono nuovo';
|
|
$s5='Dove attivo la allarme?';
|
|
similar_text($message,$s1,$perc1);
|
|
similar_text($message,$s2,$perc2);
|
|
similar_text($message,$s3,$perc3);
|
|
similar_text($message,$s4,$perc4);
|
|
similar_text($message,$s5,$perc5);
|
|
if ($perc1>70 || $perc2>70 || $perc3>70 || $perc4>70 || $perc5>70){
|
|
$text='@'.$nick.': Per configurare la app guarda questo video youtu.be/0LPWXLII4Ew';
|
|
$send_chat_message=1;
|
|
}
|
|
}
|
|
|
|
if (strcmp($postfix,'_eng_gen')==0){
|
|
$s1='How to set the app?';
|
|
$s2='How to configure the app?';
|
|
$s3='Who can help me to set the app?';
|
|
$s4='I am new';
|
|
$s5='How to set the alarm?';
|
|
similar_text($message,$s1,$perc1);
|
|
similar_text($message,$s2,$perc2);
|
|
similar_text($message,$s3,$perc3);
|
|
similar_text($message,$s4,$perc4);
|
|
similar_text($message,$s5,$perc5);
|
|
if ($perc1>70 || $perc2>70 || $perc3>70 || $perc4>70 || $perc5>70){
|
|
$text='@'.$nick.': To configure the app and the alarm watch the video: youtu.be/9CfwCly-Uf0';
|
|
$send_chat_message=1;
|
|
}
|
|
}
|
|
|
|
if (strcmp($postfix,'_tag_gen')==0){
|
|
$s1='How to set the app?';
|
|
$s2='How to configure the app?';
|
|
$s3='Who can help me to set the app?';
|
|
$s4='I am new';
|
|
$s5='How to set the alarm?';
|
|
similar_text($message,$s1,$perc1);
|
|
similar_text($message,$s2,$perc2);
|
|
similar_text($message,$s3,$perc3);
|
|
similar_text($message,$s4,$perc4);
|
|
similar_text($message,$s5,$perc5);
|
|
if ($perc1>70 || $perc2>70 || $perc3>70 || $perc4>70 || $perc5>70){
|
|
$text='@'.$nick.': To configure the app and the alarm watch the video: youtu.be/9CfwCly-Uf0';
|
|
$send_chat_message=1;
|
|
}
|
|
}
|
|
|
|
if (strcmp($postfix,'_es_gen')==0){
|
|
$s1='Cómo se configura la app?';
|
|
$s2='Cómo se activa la alarma?';
|
|
$s3='Robot qué hora es?';
|
|
$s4='Soy nuevo';
|
|
$s5='Soy nuevo quién me ayuda';
|
|
similar_text($message,$s1,$perc1);
|
|
similar_text($message,$s2,$perc2);
|
|
similar_text($message,$s3,$perc3);
|
|
similar_text($message,$s4,$perc4);
|
|
similar_text($message,$s5,$perc5);
|
|
if ($perc1>$perc2 && $perc1>60){
|
|
$text='@'.$nick.': para configurar la aplicación mira esto vídeo: https://youtu.be/OTfvulX_VJo';
|
|
$send_chat_message=1;
|
|
}
|
|
if ($perc2>$perc1 && $perc2>60){
|
|
$text='@'.$nick.': para configurar la alarma mira esto vídeo: https://youtu.be/OTfvulX_VJo';
|
|
$send_chat_message=1;
|
|
}
|
|
if ($perc4>90){
|
|
$text='@'.$nick.': Nuevo? Para configurar la alarma mira esto vídeo: https://youtu.be/OTfvulX_VJo';
|
|
$send_chat_message=1;
|
|
}
|
|
if ($perc5>90){
|
|
$text='@'.$nick.': Nuevo? Para configurar la alarma mira esto vÃdeo: https://youtu.be/OTfvulX_VJo';
|
|
$send_chat_message=1;
|
|
}
|
|
|
|
if ($perc3>85){
|
|
date_default_timezone_set("America/Santiago");
|
|
$date=date("H:i", time());
|
|
$text='Esta es la hora exacta'." ";
|
|
$text=$text.'Santiago: '.$date." - ";
|
|
date_default_timezone_set("America/Guayaquil");
|
|
$date=date("H:i", time());
|
|
$text=$text.'Guayaquil: '.$date." - ";
|
|
date_default_timezone_set("America/Mexico_City");
|
|
$date=date("H:i", time());
|
|
$text=$text.'Ciudad de México: '.$date." - ";
|
|
date_default_timezone_set("Europe/Madrid");
|
|
$date=date("H:i", time());
|
|
$text=$text.'Madrid: '.$date." - ";
|
|
date_default_timezone_set("America/Los_Angeles");
|
|
$date=date("H:i", time());
|
|
$text=$text.'Los Angeles: '.$date;
|
|
$send_chat_message=1;
|
|
}
|
|
}
|
|
|
|
if ($send_chat_message==1){
|
|
$url = 'http://www.earthquakenetwork.it/mysql/distquake_upload_chat3.php';
|
|
|
|
$chat_data = array('u_id'=>'1','nick' => 'Robot', 'password' => 'h7k32fw9','postfix' =>$postfix,'u_code'=>'1','msg_code'=>'1234','message'=>$text);
|
|
$options = array(
|
|
'http' => array(
|
|
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
|
|
'method' => 'POST',
|
|
'content' => http_build_query($chat_data)
|
|
)
|
|
);
|
|
$context = stream_context_create($options);
|
|
$result = file_get_contents($url, false, $context);
|
|
}
|
|
}
|
|
else{
|
|
if ($banned==1){
|
|
if (strcmp($postfix,'_ita_gen')==0){
|
|
$message="Il tuo account è bloccato. Se ritieni di essere stato bloccato ingiustamente scrivi a finazzif@gmail.com";
|
|
}
|
|
if (strcmp($postfix,'_es_gen')==0){
|
|
$message="Tu cuenta ha sido bloqueada. Si piensa que esto fue por error, por favor escriba un e-mail a finazzif@gmail.com";
|
|
}
|
|
if (strcmp($postfix,'_eng_gen')==0){
|
|
$message="You have been banned from the chat. If you think this was by mistake, please write an e-mail at finazzif@gmail.com";
|
|
}
|
|
if (strcmp($postfix,'_pt_gen')==0){
|
|
$message="Você foi banido do bate-papo. Se você acha que isso foi por engano, por favor escreva um e-mail para finazzif@gmail.com";
|
|
}
|
|
if (strcmp($postfix,'_jp_gen')==0){
|
|
$message="あなたはチャットから禁止されています。 これが間違っていると思われる場合は、finazzif@gmail.comまで電子メールでお書きください";
|
|
}
|
|
if (strcmp($postfix,'_zh_gen')==0){
|
|
$message="Vous avez été interdit de la salle de discussion. Si vous pensez que c'est par erreur, écrivez un e-mail à finazzif@gmail.com";
|
|
}
|
|
if (strcmp($postfix,'_tag_gen')==0){
|
|
$message="Ikaw ay pinagbawalan mula sa chatroom. Kung sa tingin mo ito ay hindi sinasadya, mangyaring sumulat ng isang e-mail sa finazzif@gmail.com";
|
|
}
|
|
}
|
|
else{
|
|
if ($ver<1){
|
|
if (strcmp($postfix,'_ita_gen')==0){
|
|
$message="Per poter inviare messaggi in chat aggiorna la app alla versione 7.7.13 o superiore";
|
|
}
|
|
if (strcmp($postfix,'_es_gen')==0){
|
|
$message="Para enviar mensajes actualizar la aplicación a la versión 7.7.13 o superior";
|
|
}
|
|
if (strcmp($postfix,'_eng_gen')==0){
|
|
$message="In order to send messages, please update the app to version 7.7.13 or higher";
|
|
}
|
|
if (strcmp($postfix,'_pt_gen')==0){
|
|
$message="Para enviar mensagens, atualize o aplicativo para a versão 7.7.13 ou superior";
|
|
}
|
|
if (strcmp($postfix,'_jp_gen')==0){
|
|
$message="メッセージを送信するには、アプリをバージョン7.7.13以上に更新してください";
|
|
}
|
|
if (strcmp($postfix,'_zh_gen')==0){
|
|
$message="Pour envoyer des messages, mettre à jour l'application à la version 7.7.13 ou supérieur";
|
|
}
|
|
if (strcmp($postfix,'_tag_gen')==0){
|
|
$message="Upang magpadala ng mga mensahe, paki-update ang app sa bersyon 7.7.13 o mas mataas";
|
|
}
|
|
}
|
|
}
|
|
|
|
$url = 'http://www.earthquakenetwork.it/mysql/distquake_upload_personal_chat.php';
|
|
|
|
$chat_data = array('u_id'=>'1','nick' => 'Robot', 'password' => 'h7k32fw9','postfix' =>$postfix,'u_code'=>'1','msg_code'=>'1234','message'=>$message,'user_code_to'=>$user_code);
|
|
$options = array(
|
|
'http' => array(
|
|
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
|
|
'method' => 'POST',
|
|
'content' => http_build_query($chat_data)
|
|
)
|
|
);
|
|
$context = stream_context_create($options);
|
|
$result = file_get_contents($url, false, $context);
|
|
}
|
|
mysql_close();
|
|
?>
|