-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
77 lines (65 loc) · 1.75 KB
/
index.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
<?php
require_once "config.php";
use \Tsugi\Core\LTIX;
// Retrieve the launch data if present
$LTI = LTIX::requireData();
$p = $CFG->dbprefix;
$displayname = $USER->displayname;
// Handle your POST data here...
if ( isset($_POST['guess'])) {
if ( !is_numeric($_POST['guess'])) {
$_SESSION['error'] = "Guess must be numeric";
header('Location: '.addSession('index.php'));
return;
}
$PDOX->queryDie("INSERT INTO {$p}tsugi_sample_module
(link_id, user_id, guess, updated_at)
VALUES ( :LI, :UI, :GUESS, NOW() )
ON DUPLICATE KEY UPDATE guess=:GUESS, updated_at = NOW()",
array(
':LI' => $LINK->id,
':UI' => $USER->id,
':GUESS' => $_POST["guess"]
)
);
if ( $_POST['guess'] == 42 ) {
$_SESSION['success'] = "Nice work";
} else {
$_SESSION['error'] = "Please try again";
}
header('Location: '.addSession('index.php'));
return;
}
// Retrieve the old data
$row = $PDOX->rowDie("SELECT guess FROM {$p}tsugi_sample_module
WHERE user_id = :UI",
array(':UI' => $USER->id)
);
$oldguess = $row ? $row['guess'] : '';
// Start of the output
$OUTPUT->header();
$OUTPUT->bodyStart();
$OUTPUT->flashMessages();
echo("<h1>Guessing Game</h1>\n");
$OUTPUT->welcomeUserCourse();
?>
<form method="post">
Pick a number:
<input type="text" name="guess" value="<?= $oldguess ?>"><br/>
<input type="submit" name="send" value="Guess">
</form>
<?php
echo("<pre>Global Tsugi Objects:\n\n");
var_dump($USER);
var_dump($CONTEXT);
var_dump($LINK);
echo("\n<hr/>\n");
echo("Session data (low level):\n");
echo($OUTPUT->safe_var_dump($_SESSION));
$OUTPUT->footerStart();
?>
<script>
// You might put some JavaScript here
</script>
<?php
$OUTPUT->footerEnd();