/
questions.php
49 lines (44 loc) · 1.84 KB
/
questions.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
43
44
45
46
47
48
49
<?php
require_once('./config/require.php');
// check for taskId - mandatory param
if (!isset($taskId)) { fail(_error_no_task_id_code); }
// query!
// get task name
$q = $mysqli_->prepare('select name from task where taskId=?');
$q->bind_param('i', $taskId);
$q->bind_result($taskName);
if (!$q->execute()) { fail(_error_mysql_query_error_code); } // auto-close query
if (!$q->fetch()) { fail(_error_no_task_found_code); } // auto-close query
$q->close();
// end of getting task name
// åñëè åñòü àäìèíñêàÿ àâòîðèçàöèÿ - ïîêàçûâàåì âñå-âñå âîïðîñû
if (1 == $is_admin) { $show_all = ' or true'; } else { $show_all = ''; }
// get info about questions
$q = $mysqli_->prepare('select Q.questionId as `questionId`, Q.dateTime as `dateTime`, Q.userId as `userId`, U.nickname as `userNickName`,'
.' Q.question as `question`, Q.result as `result`, Q.comment as `comment`, Q.isPublic as `isPublic` '
.' from (questions Q left join `user` U on Q.userId=U.Id) '
.' where Q.taskId=? and (Q.userId=? or Q.isPublic=1'.$show_all.')'
.' order by dateTime');
$q->bind_param('ii', $taskId, $curuserid);
$q->bind_result($_questionId, $dateTime, $userId, $userNickName, $question, $result, $comment, $isPublic);
if (!$q->execute()) { fail(_error_mysql_query_error_code); } // auto-close query
$questions = array();
while ($q->fetch()) {
$instance = array();
$instance['questionId'] = $_questionId;
$instance['dateTime'] = $dateTime;
$instance['userId'] = $userId;
$instance['userNickName'] = $userNickName;
$instance['question'] = $question;
$instance['result'] = $result;
$instance['comment'] = $comment;
$instance['isPublic'] = $isPublic;
$instance = (object) $instance;
array_push($questions, $instance);
}
$q->close();
data('taskId', $taskId);
data('taskName', $taskName);
data('questions', $questions);
template('questions', $data);
?>