-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.php
executable file
·275 lines (219 loc) · 9.07 KB
/
group.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<?php
require_once('appvars.php');
session_start();
if (!isset($_SESSION['group_id_max'])) {
$dbc = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
or die('Error connecting to MySQL server.'. mysql_error());
mysql_select_db(DB_NAME)
or die('Error selecting MySQL database.'. mysql_error());
$name = mysql_real_escape_string(trim($_POST['name']));
$gender = mysql_real_escape_string(trim($_POST['gender']));
$age = mysql_real_escape_string(trim($_POST['age']));
$livingState = mysql_real_escape_string(trim($_POST['livingState']));
$livingCity = mysql_real_escape_string(trim($_POST['livingCity']));
$livingCountry = mysql_real_escape_string(trim($_POST['livingCountry']));
$birthState = mysql_real_escape_string(trim($_POST['birthState']));
$birthCity = mysql_real_escape_string(trim($_POST['birthCity']));
$birthCountry = mysql_real_escape_string(trim($_POST['birthCountry']));
$placeType = mysql_real_escape_string(trim($_POST['placeType']));
$education = mysql_real_escape_string(trim($_POST['education']));
$occupation = mysql_real_escape_string(trim($_POST['occupation']));
$race = mysql_real_escape_string(trim($_POST['race']));
$query = "INSERT INTO users (id, name, gender, age, livingState, livingCity, livingCountry, birthState, birthCity, birthCountry, placeType, education, occupation, race) VALUES (0, '$name', '$gender', '$age', '$livingState', '$livingCity', '$livingCountry', '$birthState', '$birthCity', '$birthCountry', '$placeType', '$education', '$occupation', '$race')";
$result=mysql_query($query);
if($result===FALSE)
die('Error querying MySQL server.'. $query);
$query = "INSERT INTO sessions (id, user_id, time) VALUES ('". session_id(). "', LAST_INSERT_ID(), NOW())";
$result=mysql_query($query);
if($result===FALSE)
die('Error querying MySQL server.'. $query);
mysql_close($dbc);
// $_SESSION['group_num']=$_POST['groups'];
// $_SESSION['image_num_per_group']=$_POST['images'];
$_SESSION['group_id_max']=-1;
$_SESSION['group_id']=0;
$files=scandir(IMAGE_DIR);
$files=array_diff($files, array('.', '..', '.DS_Store'));
// foreach (scandir(IMAGE_DIR) as $file){
// if(is_file(IMAGE_DIR.$file))
// $files[]=$file;
// }
shuffle($files);
if(APP_GROUP_NUM*APP_IMAGE_NUM_PER_GROUP<=count($files)){
$_SESSION['image_sequence']=array_slice($files, 0, APP_GROUP_NUM*APP_IMAGE_NUM_PER_GROUP);
}else{
die("Error exceeding the number of images in database!");
}
}else{
// order matters
if ($_SERVER['REQUEST_METHOD']=='POST'){
$dbc = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
or die('Error connecting to MySQL server.'. mysql_error());
mysql_select_db(DB_NAME)
or die('Error selecting MySQL database.'. mysql_error());
for ($i=0; $i<count($_POST); $i++){
$session=session_id();
$group=$_SESSION['group_id'];
$image=basename($_POST[$i]);
if($_SESSION['group_id']>$_SESSION['group_id_max']){
$query = "INSERT INTO ratings (session_id, group_id, rating, image) VALUES ('$session', $group, $i, '$image')";
}else{
$query = "UPDATE ratings SET image='$image' WHERE session_id='$session' AND group_id=$group AND rating=$i";
}
$result=mysql_query($query);
if($result===FALSE)
die('Error querying MySQL server.'. mysql_error());
}
mysql_close($dbc);
}
//order matters
if($_SERVER['REQUEST_METHOD']=='GET'){
// if ($_SESSION['group_id_max']<0)
// $_SESSION['group_id']++;
// else
$_SESSION['group_id']--;
}else{
if($_SESSION['group_id_max']<$_SESSION['group_id']){
$_SESSION['group_id_max']=$_SESSION['group_id'];
}
$_SESSION['group_id']++;
}
if($_SESSION['group_id']<=$_SESSION['group_id_max']){
//read database
$dbc = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
or die('Error connecting to MySQL server.'. mysql_error());
mysql_select_db(DB_NAME)
or die('Error selecting MySQL database.'. mysql_error());
$session=session_id();
$group=$_SESSION['group_id'];
$query = "SELECT * FROM ratings WHERE session_id='$session' AND group_id=$group ORDER BY rating";
$data=mysql_query($query);
if($data===FALSE)
die('Error querying MySQL server.'. mysql_error());
while ($row = mysql_fetch_array($data)) {
$_SESSION['image_sequence'][$group*APP_IMAGE_NUM_PER_GROUP+$row['rating']]=$row['image'];
}
mysql_close($dbc);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Visual Assessment</title>
<!-- load Dojo -->
<link rel="stylesheet" type="text/css"
href="./js/dojo/resources/dojo.css" />
<link rel="stylesheet" type="text/css"
href="./js/dijit/themes/tundra/tundra.css" />
<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="text/javascript" src="./js/dojo/dojo.js"
data-dojo-config="parseOnLoad: true, isDebug:true"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dojox.image.LightboxNano");
dojo.require("dijit.form.Button");
dojo.require("dijit.form.Form");
dojo.require("dijit.ProgressBar");
dojo.require("dojo.dnd.Source");
dojo.require("dojo.dnd.Container");
dojo.addOnLoad(function(){
dojo.subscribe("/dnd/start", function(source, nodes, copy){
dojo.query(".dojoDndAvatar .dojoDndItem").style("width", "200px");
});
});
</script>
</head>
<body class="tundra" style="background-color: white; font-size: medium;">
<div class="myRating">
Please rank the photos in order of visual preference, with #1 being
your favorite. <br> Click on the image to see a larger version. <br>
Photos can also be rearranged once they are in the box below. <br>
Once you are satisfied with the order, click submit to go to the next
group.
</div>
<div id="imageTable" data-dojo-id="imageTable"
data-dojo-type="dojo.dnd.Source"
data-dojo-props="horizontal: true, accept: []"
class="myRatingImageTable">
<?php
for ($i=0; $i<APP_IMAGE_NUM_PER_GROUP; $i++){
?>
<div class="dojoDndItem"
style="border: 1px solid black; padding: 8px; margin: 0.6%; box-shadow: 5px 5px 5px #888888; width: <?php echo 80/APP_IMAGE_NUM_PER_GROUP. '%'?>; background: white; float: left;">
<img data-dojo-type="dojox.image.LightboxNano"
data-dojo-props="<?php echo 'href: \''. IMAGE_DIR. $_SESSION['image_sequence'][APP_IMAGE_NUM_PER_GROUP*$_SESSION['group_id']+$i]. '\'';?>"
href="<?php echo IMAGE_DIR. $_SESSION['image_sequence'][APP_IMAGE_NUM_PER_GROUP*$_SESSION['group_id']+$i];?>"
src="<?php echo IMAGE_DIR. $_SESSION['image_sequence'][APP_IMAGE_NUM_PER_GROUP*$_SESSION['group_id']+$i];?>"
style="width: 100%;">
</div>
<?php
}
?>
</div>
<div id="alert" class="myRatingAlert">You have images left!</div>
<div id="resultTable" data-dojo-id="resultTable"
data-dojo-type="dojo.dnd.Source" data-dojo-props="horizontal: true"
class="myRatingResultTable">
<p style="margin: 5px auto">Drag and drop images here in sorted order</p>
</div>
<div class="myRatingNumber">
<?php
for ($i=0; $i<APP_IMAGE_NUM_PER_GROUP; $i++){
?>
<div style="padding: 8px; margin: 0px 0.6%; width: <?php echo 80/APP_IMAGE_NUM_PER_GROUP. '%'?>; text-align: center; font: large bold; color: lightgray; float: left">
<?php echo $i+1;?>
</div>
<?php
}
?>
</div>
<table class="myRatingButtonTable">
<tr>
<!--td class="myRatingButtonBack" style="visibility: <?php if ($_SESSION['group_id']==0) echo 'hidden'; else echo 'visible';?>">
<div id="backForm" data-dojo-id="backForm"
data-dojo-type="dijit.form.Form"
data-dojo-props='action: "<?php echo $_SERVER['PHP_SELF'] ?>", method:"GET"'>
<button data-dojo-type="dijit.form.Button"
data-dojo-props='type:"submit", baseClass: "mycss"' type="submit">Back</button>
</div>
</td-->
<td class="myRatingButtonSubmit">
<div id="submitForm" data-dojo-id="submitForm"
data-dojo-type="dijit.form.Form"
data-dojo-props='action: "<?php if($_SESSION['group_id']<(APP_GROUP_NUM-1)) echo $_SERVER['PHP_SELF']; else echo './end.php'; ?>", method:"POST"'>
<script type="dojo/method" data-dojo-event="onSubmit"
data-dojo-args="evt">
if(imageTable.getAllNodes().length>0){
dojo.style("alert", "visibility", "visible");
dojo.style("imageTable", "border", "1px solid red");
return false;
}
resultTable.getAllNodes().forEach(function(dndNode, index, list){
dojo.query("img", dndNode).forEach(function(imageNode){
var imageFile=dojo.attr(imageNode, "src");
dojo.create("input", {"type": "hidden", "name": ""+index, "value": imageFile}, dojo.byId("submitForm"));
});
});
dojo.style("alert", "visibility", "hidden");
dojo.style("imageTable", "border", "");
return true;
</script>
<button data-dojo-type="dijit.form.Button"
data-dojo-props='type:"submit", baseClass: "mycss"' type="submit">Submit
</button>
</div>
</td>
<!--td class="myRatingButtonExit">
<div id="exitForm" data-dojo-id="exitForm"
data-dojo-type="dijit.form.Form"
data-dojo-props='action: "<?php echo './end.php'; ?>", method:"GET"'>
<button data-dojo-type="dijit.form.Button"
data-dojo-props='type:"submit", baseClass: "mycss"' type="submit">Exit</button>
</div>
</td-->
</tr>
</table>
</body>
</html>