/var/www/doncode.com.ua/www/libs
Edit: /var/www/doncode.com.ua/www/libs/class.dcu_api.php (2805B)
database = new database(DB_TYPE,DB_HOST,DB_NAME,DB_USER,DB_PASS,ENCODE);
// $this->mail = new mail();
}
final public function add_chat (){
$json['cmd'] = 'dcu_add_chat';
$json['city_id'] = $_POST['city_id'];
$json['user_id'] = $_POST['user_id'];
$json['time'] = date("Y-m-d H:i:s");
$json['text'] = urldecode($_POST['text']);
if($json['city_id']>0&&$json['user_id']>0){
$chat_id = $this->database->insert(DB_PREFIX.'chat',array(
'user_id' => $json['user_id'],
'city_id' => $json['city_id'],
'time' => $json['time'],
'text' => $json['text']
));
if($chat_id>0){
$json['id'] = $chat_id;
if(sendsocket(MOBILE_HOST,MOBILE_PORT,$this->json_encode__($json))){
echo '{"code":0,"success":true}';
exit;
}else{
echo '{"code":500,"fail":"Server shutdown"}';
exit;
}
}else{
echo '{"code":501,"fail":"Incorrect request"}';
exit;
}
}else{
echo '{"code":501,"fail":"Incorrect request"}';
exit;
}
}
final public function json_encode__($string) {
$arrayUtf = array('\u0410', '\u0430', '\u0411', '\u0431', '\u0412', '\u0432', '\u0413', '\u0433', '\u0414', '\u0434', '\u0415', '\u0435', '\u0401', '\u0451', '\u0416', '\u0436', '\u0417', '\u0437', '\u0418', '\u0438', '\u0419', '\u0439', '\u041a', '\u043a', '\u041b', '\u043b', '\u041c', '\u043c', '\u041d', '\u043d', '\u041e', '\u043e', '\u041f', '\u043f', '\u0420', '\u0440', '\u0421', '\u0441', '\u0422', '\u0442', '\u0423', '\u0443', '\u0424', '\u0444', '\u0425', '\u0445', '\u0426', '\u0446', '\u0427', '\u0447', '\u0428', '\u0448', '\u0429', '\u0449', '\u042a', '\u044a', '\u042b', '\u044b', '\u042c', '\u044c', '\u042d', '\u044d', '\u042e', '\u044e', '\u042f', '\u044f');
$arrayCyr = array('А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Д', 'д', 'Е', 'е', 'Ё', 'ё', 'Ж', 'ж', 'З', 'з', 'И', 'и', 'Й', 'й', 'К', 'к', 'Л', 'л', 'М', 'м', 'Н', 'н', 'О', 'о', 'П', 'п', 'Р', 'р', 'С', 'с', 'Т', 'т', 'У', 'у', 'Ф', 'ф', 'Х', 'х', 'Ц', 'ц', 'Ч', 'ч', 'Ш', 'ш', 'Щ', 'щ', 'Ъ', 'ъ', 'Ы', 'ы', 'Ь', 'ь', 'Э', 'э', 'Ю', 'ю', 'Я', 'я');
return str_replace($arrayUtf,$arrayCyr,json_encode($string));
}
function sendsocket($ip, $port, $cmd){
// Функция отправки $cmd в порт любого ip
// Возвращает ответ
$fp = @fsockopen ($ip, $port, $errno, $errstr, 2);
if(!$fp){
return false;
} else {
socket_set_timeout($fp, 2);
fputs($fp, $cmd);
$ans = fgets($fp);
fclose ($fp);
if(strlen($ans)<1){
//return true;
}
return $ans;
}
}
}