-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserHomeCF.php
118 lines (110 loc) · 3 KB
/
userHomeCF.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
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<?php
session_start();
$username=$_SESSION["username"];
print '<h2>CrowdFluttr Peer Evaluation Demo - '.$username.' Home</h2>';
$conn =new mysqli("localhost","root","mishra2014","CrowdFluttr");
// Check connection
if ($conn->connect_error)
{
$result=array("DBConnection"=>0);
die("Connection failed: " . $conn->connect_error);
}
else
{
$result=array("DBConnection"=>1);
}
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$data = $_POST['submit'];
$id=key($data);
$action=$data[$id];
echo $id;
echo $action;
if($action=="Join")
{
$sql="insert into relations(projID, username, cred, contribution) values(".$id.",'".$username."',1.0,0.0)";
if($conn->query($sql)==true)
{
$result=$result+array("ProjectJoin"=>1);
$sql="ALTER TABLE ".$id."_PE add ".$username."_contribution float default 0.0";
if($conn->query($sql)==true)
{
$result=$result+array("PEJoin"=>1);
}
else
{
$result=$result+array("PEJoin"=>0);
}
}
else
{
$result=$result+array("ProjectJoin"=>0);
$result=$result+array("SQLError"=>$conn->error." in ".$sql);
}
}
if($action=="View")
{
//open PE for project
$_SESSION['username']=$username;
$_SESSION['id']=$id;
header("Location: http://mishra14.ddns.net/peerEvaluationCF.php");
}
$result=$result+array("ProjectID"=>$id);
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$sql="(SELECT projects.projname, projects.id, relations.username
FROM projects
JOIN relations ON relations.projID = projects.id
WHERE relations.username='".$username."')
UNION ALL
(SELECT projects.projname, projects.id , projects.projname
FROM projects
WHERE projects.id NOT IN
(SELECT projects.id
FROM projects
JOIN relations ON relations.projID = projects.id
WHERE relations.username='".$username."'))";
$queryResult=$conn->query($sql);
if($queryResult->num_rows > 0)
{
print '<form method="post" action="'.htmlspecialchars($_SERVER["PHP_SELF"]).'">';
print '<table border="1">';
print '<tr><td>Project Name</td><td>Project ID</td><td>Status</td></tr>';
while ($row = $queryResult->fetch_assoc())
{
print '<tr><td>'.$row['projname'].'</td><td>'.$row['id'].'</td>';
if($row['username']==$username)
{
print '<td><input type="submit" name="submit['.$row['id'].']" value="View"> </td></tr>';
}
else
{
print '<td><input type="submit" name="submit['.$row['id'].']" value="Join"> </td></tr>';
}
//print '<input type=”hidden” name=”ProjectID” value=”'.$row['id'].'”>';
}
print '</table>';
print '</form>';
$result=$result+array("NoProject"=>0);
}
else
{
$result=$result+array("NoProject"=>1);
}
$queryResult->close();
$conn->close();
print json_encode($result);
?>
</body>
</html>