-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewcards.php
128 lines (105 loc) · 3.47 KB
/
viewcards.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php require("inc/cookiecheck.inc"); ?>
<!DOCTYPE html>
<html>
<head>
<title> View your flashcards</title>
<link type="text/css" rel="stylesheet" href="css/reset.css"/>
<link type="text/css" rel="stylesheet" href="css/main.css"/>
<script src="js/jquery-2.0.3.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="js/common.js"></script>
</head>
<body>
<?php
require("header.php");
if(isset($_GET['deckid'])){
if(isset($_GET['status'])){
$msg = '';
switch($_GET['status']){
case 'added':
$msg = "Records successfully added!";
break;
}
echo $msg."<br/>";
}
require("inc/getdeckname.inc");
echo '<div id=title>'.
($_GET['deckid'] == 'all' ? "All Decks" : getDeckName($_GET['deckid'])) . "</div>";
echo '<table id="card-table">';
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "\n";
}
}
require("inc/dbinfo.inc");
$userid = $_COOKIE['userid'];
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$tableCols = array();
if( $_GET['deckid'] == 'all' ){
$tableCols = array("Deck name","front","back");
$sql = "
SELECT decks.name,front,back
FROM flashcards JOIN decks ON decks.deckid = flashcards.deckid
WHERE userid=?
ORDER BY decks.deckid, cardid ";
$stmt = $conn->prepare($sql);
$stmt->bindValue(1, $userid);
}else{
$tableCols = array("front","back");
$sql = "
SELECT front,back
FROM flashcards JOIN decks ON flashcards.deckid=decks.deckid
WHERE userid=?
AND flashcards.deckid=?";
$stmt = $conn->prepare($sql);
$stmt->bindValue(1, $userid);
$stmt->bindValue(2, $_GET['deckid']);
}
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
echo "<tr>";
foreach($tableCols as $colName){
echo "<th>".$colName."</th>";
}
echo "</tr>";
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
exit;
}
$conn = null;
echo "</table>";
}else{
?>
Choose a deck:
<form method="get" action="<?php echo basename(__FILE__); ?>" >
<?php
$allDecksOption = true;
require("inc/deckselect.inc");
foreach($_GET as $k=>$v){
echo '<input type="hidden" name="'.$k.'" value="'.$v.'" />';
}
?>
<input type="submit" />
</form>
<?php
}
require("footer.php");
?>
</body>