forked from davidmelhart/PAGAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
archived.php
126 lines (118 loc) · 6.08 KB
/
archived.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
<?php
require_once "config.php";
// Initialize the session
session_start();
// Generate User if User does not exists
if(!isset($_COOKIE['user'])){
$id = getGUID();
setcookie('user', $id, time()+315400000,"/");
$_COOKIE['user'] = $id;
}
$current_page = explode(".", $_SERVER['REQUEST_URI'])[0];
// Generates GUID for username
function getGUID(){
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);
$uuid = substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12);
return $uuid;
}
$title = 'Platform for Affective Game ANnotation';
$css = ['researcher.css'];
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
// Fetch the projects of the user
if($_SERVER["REQUEST_METHOD"] == "GET"){
$user = $_SESSION["username"];
$sql = "SELECT * FROM projects WHERE username = :user ORDER BY created_at DESC";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(":user", $user, PDO::PARAM_STR);
$stmt->execute();
$archived = 'true';
$archive_length = "SELECT * FROM projects WHERE archived = :archived ORDER BY created_at DESC";
$length_stmt = $pdo->prepare($archive_length);
$length_stmt->bindParam(":archived", $archived, PDO::PARAM_STR);
$length_stmt->execute();
}
include("header.php");
?>
<div id="subheader">
<h2>[Platform for Audiovisual General-purpose ANotation]</h2>
<div class="subheader-buttons"><a class="button" href="./logout.php">log out</a></div>
</div>
<div class="page-header">
<div>
<p>Hello, <?php echo htmlspecialchars($_SESSION["username"]); ?>. Welcome back.</p>
</div>
<div class="projects-buttons"><a class="button" href="./projects.php">live projects</a><a class="button" href="./create_project.php">add a new project</a></div>
</div>
<div>
<?php
if($length_stmt->rowCount() < 1){
echo "You have no archived projects.";
}else{
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$filename = str_replace(" ","-",$row['project_name']).'_'.$row['target'].'_log_'.explode(' ', $row['created_at'])[0];
$project_id = $row['project_id'];
$sql = "SELECT participant_id FROM logs WHERE project_id = :project_id";
$stmt2 = $pdo->prepare($sql);
$stmt2->bindParam(":project_id", $project_id, PDO::PARAM_STR);
$stmt2->execute();
$participants = array();
while ($participant = $stmt2->fetch(PDO::FETCH_ASSOC)) {
array_push($participants, $participant['participant_id']);
}
$participants = (count(array_unique($participants)));
unset($stmt2);
if ($row['archived'] === 'true') {
echo '
<div class="project-container" id="'.$project_id.'">
<div class="title-box">
<div>
<h2>'.$row['project_name'].'</h2>
<h3>a past <span class="project-info">project<span class="project-info-box">
<p><strong>annotation type:</strong> '.$row['type'].'</p>
<p><strong>source type:</strong> '.$row['source_type'].'</p>
<p><strong>video loading:</strong> '.$row['video_loading'].'</p>
<p><strong>endless mode:</strong> '.$row['endless'].'</p>
<p><strong>sound:</strong> '.$row['sound'].'</p>
<p><strong>number of entries:</strong> '.$row['n_of_entries'].'</p>
<p><strong>participant completes:</strong> '.$row['n_of_participant_runs'].'</p>';
if(!empty($row['survey_link'])){echo "
<p><strong>survey_link:</strong> ".$row['survey_link']."</p>";}
echo '</span></span>
on '.$row['target'].'</h3>
</div>
<div>
<span class="date">'.$row['created_at'].'</span><br>
<span class="participants">'.$participants.' participants</span><br>';
if ($row['source_type'] == 'upload' || $row['source_type'] == 'user_upload') {
echo '<span><a class="button download" href="util/fetch_vid.php?project_id='.$row['project_id'].'">download videos</a></span>';
}
echo '<span><a class="button download" href="util/fetch_log.php?project_id='.$row['project_id'].'&filename='.$filename.'">download logs</a></span><span class="button archive" data-projectid='.$row['project_id'].' data-archive="false">restore project</span>
</div>
</div>
</div>
';
}
}
// Close statement
unset($stmt);
// Close connection
unset($pdo);
}
?>
</div>
<?php
$scripts = ['researcher.js'];
include("scripts.php");
$tooltip = '';
include("footer.php");
?>