-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathask.php
More file actions
76 lines (69 loc) · 1.72 KB
/
Copy pathask.php
File metadata and controls
76 lines (69 loc) · 1.72 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
session_start();
require_once 'vendor/autoload.php';
require_once 'db.php';
$loader = new Twig_Loader_Filesystem('views');
$twig = new Twig_Environment($loader, array());
$db = new db;
$db->connect();
if(!isset($_SESSION['username'])){
if (isset($_REQUEST["login"])) {
login();
}else{
echo $twig->render('login.html',array());
}
}else{
ask_question();
}
function ask_question(){
global $twig;
global $db;
$question = $db->get_question_by_id($qid);
$replies = $db->get_reply_by_question($qid);
/*echo "<pre>";
print_r($replies);
die();*/
$params = array();
$params["userName"] = $_SESSION['username'];
echo $twig->render('ask.html',$params);
}
function post_question(){
global $db;
$db->post_question($_SESSION['id'],$_REQUEST['QuestionTitle'],$_REQUEST['QuestionBody']);
}
function login(){
global $db;
global $twig;
$id = $db->authenticate($_REQUEST["username"],$_REQUEST["password"]);
if ($id == null) {
$msg = "access denied";
echo "denied";
} else {
//session_start();
// $_SESSION['check'] = new foo();
$_SESSION['id'] = $id["ID"];
$_SESSION['username'] = $_REQUEST["username"];
//Hack! change to show_home
ask_question();
}
}
/*$template = $twig->loadTemplate('template2.phtml');
$params = array(
'name' => 'Krzysztof',
'friends' => array(
array(
'firstname' => 'John',
'lastname' => 'Smith'
),
array(
'firstname' => 'Britney',
'lastname' => 'Spears'
),
array(
'firstname' => 'Brad',
'lastname' => 'Pitt'
)
)
);
$template->display($params);*/
?>