-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin.php
More file actions
143 lines (126 loc) · 3.71 KB
/
Copy pathjoin.php
File metadata and controls
143 lines (126 loc) · 3.71 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
//Include this inside the <head> tag to require user to be logged in to view the page.
include 'includes/membersOnly.php';
define('INCLUDE_CHECK',true);
// Those two files can be included only if INCLUDE_CHECK is defined
require "includes/connect.php";
require 'includes/functions.php';
function addUsertoClass($userid,$classid)
{
//Join em in
$classRow = mysql_query("INSERT INTO classmates (userid,classid) VALUES ('$userid','$classid')");
$_SESSION['msg']['success'] = 'You are now enrolled in this class.';
header("Location: noteselection.php");
exit;
}
$classid = mysql_real_escape_string($_GET['classid']);
$classRow = mysql_query("SELECT name,description,password,owner FROM classes WHERE id='$classid'");
$row = mysql_fetch_assoc($classRow);
mysql_free_result($classRow);
$classarr = array();
if ($row)
{
$classarr['name'] = $row['name'];
$classarr['description'] = $row['description'];
$classarr['password'] = $row['password'];
$classarr['owner'] = $row['owner'];
if ($row['owner'] == $_SESSION['id'])
{
//Already in the class
$_SESSION['msg']['err'] = 'You are teaching this class.';
header("Location: noteselection.php");
exit;
}
//TODO: See if they are already in the class
$userid = mysql_real_escape_string($_SESSION['id']);
$classmateRow = mysql_query("SELECT COUNT(*) FROM classmates WHERE classid='$classid' AND userid='$userid'");
$cmrow = mysql_fetch_assoc($classmateRow);
mysql_free_result($classmateRow);
if ($cmrow['COUNT(*)'] != 0)
{
//User is already enrolled in the class
$_SESSION['msg']['err'] = 'You are already enrolled in this class.';
header("Location: noteselection.php");
exit;
}
if (strlen($row['password']) == 0)
{
addUsertoClass($userid,$classid);
}
else
{
//Check to see if the password is the same, or matches
if ($_POST['submit'])
{
if (strcmp($row['password'],$_POST['password']) == 0)
{
addUsertoClass($userid,$classid);
}
else
{
//Dont match
$_SESSION['msg']['err'] = "That password doesn't match. Try again.";
}
}
}
}
else
{
$classarr['name'] = 'N/A';
$classarr['description'] = '';
$classarr['password'] = NULL;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Pencl - Coming Soon</title>
<link rel="stylesheet" type="text/css" href="css/reset.css" media="screen">
<link rel="stylesheet" type="text/css" href="css/styles.css" media="screen">
<link rel="stylesheet" type="text/css" href="css/book.css" media="screen">
<!-- Load jQuery -->
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
</script>
<?php
include 'includes/topbar_header.php';
include 'includes/tracker.php';
?>
</head>
<body onload="$('#classPassword').focus()">
<?php
//Must be first thing in the <body> tag to function correctly
include 'includes/topbar.php';
?>
<div class="bookcontainer">
<div class="book">
<div class="page">
<?php
echo '<h1>Join class:</h1><h1>'.$classarr['name'].'</h1>';
echo '<p>'.$classarr['description'].'</p>';
?>
</div>
<div class="middle"><br></div>
<div class="page">
<h1>Password</h1>
<br>
<form action="" method="post">
<input id="classPassword" name="password" type="text"><br>
<input class="submit" name="submit" type="submit" value="Join class">
</form>
<br>
<?php
if($_SESSION['msg']['err'])
{
echo '<div class="error"><p>'.$_SESSION['msg']['err'].'</p></div>';
unset($_SESSION['msg']['err']);
}
?>
</div>
<div style="clear:both"></div>
</div>
</div>
</body>
</html>