-
Notifications
You must be signed in to change notification settings - Fork 0
/
question.php
42 lines (35 loc) · 1.33 KB
/
question.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
//POST DATA
$tguser = (INT)$_POST['user']; //Telegram User ID
$token = $_POST['token'];
//Variables
$config = include('config.php');
$hosttoken = $config['token'];
$db_host = $config['db_host'];
$db_name = $config['db_name'];
$db_user = $config['db_user'];
$db_password = $config['db_password'];
if ($token = null or $tguser =null){
die("NOT_CORRECT_POST_DATA");
}
//Check Token
if (!$token = $hosttoken){
die("Auth_Failed");
}
//Database Connection
$db = new PDO('mysql:host='.$db_host.';dbname='.$db_name.';charset=utf8', $db_user, $db_password);
//get user question queue data
$QuesrionQueueList = $db->prepare("SELECT user, list, now, next FROM qalist WHERE user = :user");
$QuesrionQueueList->bindParam(':user',$tguser,PDO::PARAM_INT);
$QuesrionQueueList->execute();
$Object = $QuesrionQueueList->fetchObject();
$UserQuestionID = $Object->now;
$UserQuestionQueue = JSON_Decode($Object->list);
$QuestionID = $UserQuestionQueue[$UserQuestionID] + 0;
$QuestionList = $db->prepare("SELECT id, question, author, answers FROM question WHERE id = :id");
$QuestionList->bindParam(':id',$QuestionID,PDO::PARAM_INT);
$QuestionList->execute();
$Object2 = $QuestionList->fetchObject();
$TempArray = JSON_Decode($Object2->answers);
$Object2->answers = $TempArray;
echo JSON_Encode($Object2);