-
Notifications
You must be signed in to change notification settings - Fork 1
/
ajax_service.php
167 lines (146 loc) · 6.77 KB
/
ajax_service.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
* Created by PhpStorm.
* User: Tyemill
* Date: 4/13/14
* Time: 1:47 PM
*/
// ============================== authentication ===============================
//if (session_status() == PHP_SESSION_NONE) {
// session_start();
//}
//session_regenerate_id();
//if(!isset($_SESSION['user_email'])) { // if there is no valid session
// header("Location: index.php?notice=login_first");
//}
require_once "session_inc.php";
// ============================== authentication ===============================
require_once "dbconnect.php";
$root_url = "http://depts.washington.edu/";
if (isset($_GET['trigger']) && isset($_GET['type'])) {
try {
$dbq = db_connect();
$trigger = $_GET['trigger'];
$type = $_GET['type'];
$sql = null;
switch ($type) {
case "project_artifact" :
// service for projectArtifact
$sql = "SELECT a.artifactID AS id, a.artifactTitle AS Title
FROM projectArtifact pa
join artifact a on a.artifactID = pa.artifactID
where pa.projectID = " . $trigger;
break;
case "persona_scenario":
$sql = "select s.scenarioID as id, s.scenarioTitle as Title from personaScenario ps
join scenario s on ps.scenarioID = s.scenarioID
join personae p on ps.personaID = p.personaeID
where p.personaeID = " . $trigger;
break;
case "persona_user":
$sql = "SELECT u.userID as id, CONCAT(u.firstName, ' ', u.lastName) as Title FROM userPersonae up
join userProfile u on u.userID = up.userID
join personae p on p.personaeID = up.personaeID
where up.personaeID = " . $trigger;
break;
}
if ($sql) {
// $result = $dbq->query($sql);
$query = $dbq->prepare($sql);
$query->execute();
$rows = array();
while($r = $query->fetch(PDO::FETCH_ASSOC)) {
$rows[] = $r;
}
print json_encode($rows);
// print_r($result);
} else {
echo("error found");
}
}
catch(PDOException $e){
// Report errors
// printf ($e->getMessage());
}
// echo("Trigger is " . $trigger . "; type is " . $type);
} elseif (isset($_GET['email'])) {
try {
$dbq = db_connect();
$email = $_GET['email'];
$urpID = $_GET['urpID'];
$sendEmail = $_GET['sendEmail'];
$first_query = "SELECT * FROM userRatingProgress urp
join userProfile up on urp.userID = up.userID
where urp.`userRatingProgressID` = " . $urpID . "
and up.email = '" . (string)$email . "'";
$flag = $dbq->query($first_query)->fetchColumn();
// $flag->execute();
// echo($flag);
if ($flag) {
$query = $dbq->prepare("SELECT * FROM userRatingProgress urp
join projectArtifact pa on urp.projectArtifactID = pa.projectArtifactID
join userProfile upro on upro.userID = urp.userID
where urp.`userRatingProgressID` = " . $urpID);
$query->execute();
$result = $query->fetch(PDO::FETCH_ASSOC);
if ($result) {
$project = $result['projectID'];
$language = $result['preferredLanguage'];
$artifact = $result['artifactID'];
$persona = $result['personaID'];
$scenario = $result['scenarioID'];
$userName = $result['firstName'] . " " . $result['lastName'];
$targetURL = "/tedsrate/teds/rater.php?selLanguage=" . $language . "&selProject=" . $project . "&selArtifact=" . $artifact . "&selScenario=" . $scenario . "&selPersona=" . $persona . "&urpId=" . $urpID;
$email_flag = false;
$email_message = "Invalid email! Please try again!";
// sending email function
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
$to = (string)$email;
// subject
$subject = 'You are invited: please help us fill out this evaluation form -- TEDS';
// message
$message = '
<html>
<head>
<title>You are invited: please help us fill out this evaluation form -- TEDS</title>
</head>
<body>
<p>Dear ' . $userName . ', </p>
<p>Please help us make better web! Here is the link to access the TEDS evaluation form for you:</p>
<p><a href="' . $root_url . $targetURL . '" target="blank"><b>Link</b></a></p>
<br />
<br />
<p>Your help is greatly appreciated!</p>
<p>Sincerely,</p>
<p><a href="https://www.washington.edu/" target="blank">University of Washington</a></p>
<p><a href="https://ischool.uw.edu/" target="blank">Information School</a></p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: ' . $result['firstName'] . ' <' . $email . '>' . "\r\n";
$headers .= 'From: TEDS Eval <' . $root_url . '>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
// modify message
$email_flag = true;
$email_message = "Url sent successfully to " . $email;
}
//
$final_url = $root_url . $targetURL;
$final_result = [];
array_push($final_result,$email_flag, $email_message, $final_url);
print json_encode($final_result);
}
}
}
catch (PDOException $e){
// Report errors
printf ($e->getMessage());
}
}