-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_project.php
999 lines (873 loc) · 44.1 KB
/
create_project.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
<?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;
}
// 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', 'forms.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;
}
// Define variables and initialize with empty values
$project_name = $target = $type = $source_type = $video_loading = $endless = $n_of_entries = $n_of_participant_runs = $n_of_participant_uploads = $sound = $upload_message = $start_message = $end_message = $survey_link = $autofill_id = $monochrome = $ranktrace_rate = $ranktrace_smooth = $gtrace_control = $gtrace_update = $gtrace_click = $gtrace_rate = $tolerance = "";
$project_name_err = $target_err = $source_url_err = "";
// Grab username
$username = $_SESSION["username"];
// Variables for file upload
$file_path = "";
$upload_dir = "user_uploads/";
define('MB', 1048576);
if($_SERVER["REQUEST_METHOD"] == "GET"){
$access = "default";
if (isset($_SESSION["access"])){
$access = $_SESSION["access"];
}
}
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
$project_id = getGUID();
// Checks if there are files are being uploaded or not
$file_check = array_sum($_FILES['file']['size']);
// Handle upload errors
if ($file_check > 0) {
for ($x = 0; $x < count($_FILES["file"]["name"]); $x++) {
$file = basename($_FILES["file"]["name"][$x]);
$fileType = strtolower(pathinfo($file,PATHINFO_EXTENSION));
$file_path = $upload_dir.$project_id.'-'.($x+1).'.'.strtolower($fileType);
// Check if not fake video
if(!preg_match('/video\/*/',$_FILES['file']['type'][$x])) {
$source_url_err = "File is not a video.";
}
// Check extention
if($fileType != "mp4" && $fileType != "mpeg" && $fileType != "avi" && $fileType != "webm" && $fileType != "mov") {
$source_url_err = "Sorry, only MP4, MPEG, WEBM, MOV, and AVI files are allowed.";
}
// Check file size
if ($_FILES["file"]["size"][$x] > 15000*MB) {
$source_url_err = "Sorry, the file is too large.";
}
}
}
// Validate project_name
if(empty(trim($_POST["project_name"]))){
$project_name_err = "Please enter an project name.";
} else{
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE project_name = :project_name";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":project_name", $param_project_name, PDO::PARAM_STR);
// Set parameters
$param_project_name = htmlspecialchars(trim($_POST["project_name"]));
// Attempt to execute the prepared statement
if($stmt->execute()){
$project_name = htmlspecialchars(trim($_POST["project_name"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
}
// Validate target
if(empty(trim($_POST["target"]))){
$target_err = "Please enter an annotation target.";
} else{
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE target = :target";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":target", $param_target, PDO::PARAM_STR);
// Set parameters
$param_target = htmlspecialchars(trim($_POST["target"]));
// Attempt to execute the prepared statement
if($stmt->execute()){
$target = htmlspecialchars(trim($_POST["target"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
}
// Get annotation type
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE type = :type";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":type", $param_type, PDO::PARAM_STR);
// Set parameters
$param_type = htmlspecialchars(trim($_POST["type"]));
// Attempt to execute the prepared statement
if($stmt->execute()){
$type = htmlspecialchars(trim($_POST["type"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get ranktrace monochrome
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE monochrome = :monochrome";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":monochrome", $param_monochrome, PDO::PARAM_STR);
// Set parameters
if (isset($_POST["monochrome"])){
$param_monochrome = htmlspecialchars(trim($_POST["monochrome"]));
} else {
$param_monochrome = NULL;
}
// Attempt to execute the prepared statement
if($stmt->execute()){
if (isset($_POST["monochrome"])){
$monochrome = htmlspecialchars(trim($_POST["monochrome"]));
} else {
$monochrome = 'off';
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get ranktrace ranktrace_smooth
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE ranktrace_smooth = :ranktrace_smooth";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":ranktrace_smooth", $param_ranktrace_smooth, PDO::PARAM_STR);
// Set parameters
if (isset($_POST["ranktrace_smooth"])){
$param_ranktrace_smooth = htmlspecialchars(trim($_POST["ranktrace_smooth"]));
} else {
$param_ranktrace_smooth = NULL;
}
// Attempt to execute the prepared statement
if($stmt->execute()){
if (isset($_POST["ranktrace_smooth"])){
$ranktrace_smooth = htmlspecialchars(trim($_POST["ranktrace_smooth"]));
} else {
$ranktrace_smooth = 'off';
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get ranktrace ranktrace_rate
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE ranktrace_rate = :ranktrace_rate";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":ranktrace_rate", $param_ranktrace_rate, PDO::PARAM_STR);
// Set parameters
$param_ranktrace_rate = htmlspecialchars(trim($_POST["ranktrace_rate"]));
// Attempt to execute the prepared statement
if($stmt->execute()){
$ranktrace_rate = htmlspecialchars(trim($_POST["ranktrace_rate"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get gtrace type
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE gtrace_control = :gtrace_control";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":gtrace_control", $param_gtrace_control, PDO::PARAM_STR);
// Set parameters
$param_gtrace_control = htmlspecialchars(trim($_POST["gtrace_control"]));
// Attempt to execute the prepared statement
if($stmt->execute()){
$gtrace_control = htmlspecialchars(trim($_POST["gtrace_control"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get gtrace update type
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE gtrace_update = :gtrace_update";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":gtrace_update", $param_gtrace_update, PDO::PARAM_STR);
// Set parameters
if (isset($_POST["gtrace_update"])){
$param_gtrace_update = htmlspecialchars(trim($_POST["gtrace_update"]));
} else {
$param_gtrace_update = NULL;
}
// Attempt to execute the prepared statement
if($stmt->execute()){
if (isset($_POST["gtrace_update"])){
$gtrace_update = htmlspecialchars(trim($_POST["gtrace_update"]));
} else {
if ($gtrace_control == "keyboard"){
$gtrace_update = 'on';
} else {
$gtrace_update = 'off';
}
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get gtrace update type
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE gtrace_rate = :gtrace_rate";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":gtrace_rate", $param_gtrace_rate, PDO::PARAM_STR);
// Set parameters
$param_gtrace_rate = htmlspecialchars(trim($_POST["gtrace_rate"]));
// Attempt to execute the prepared statement
if($stmt->execute()){
$gtrace_rate = htmlspecialchars(trim($_POST["gtrace_rate"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get ranktrace ranktrace_rate
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE gtrace_click = :gtrace_click";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":gtrace_click", $param_gtrace_click, PDO::PARAM_STR);
// Set parameters
if (isset($_POST["gtrace_click"])){
$param_gtrace_click = htmlspecialchars(trim($_POST["gtrace_click"]));
} else {
$param_gtrace_click = NULL;
}
// Attempt to execute the prepared statement
if($stmt->execute()){
if (isset($_POST["gtrace_click"])){
$gtrace_click = htmlspecialchars(trim($_POST["gtrace_click"]));
} else {
$gtrace_click = 'off';
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get source_type
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE source_type = :source_type";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":source_type", $param_source_type, PDO::PARAM_STR);
// Set parameters
if (isset($_POST["source_type"])){
$param_source_type = htmlspecialchars(trim($_POST["source_type"]));
} else {
$param_source_type = NULL;
}
// Attempt to execute the prepared statement
if($stmt->execute()){
$source_type = htmlspecialchars(trim($_POST["source_type"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Validate source_url
$source_urls = explode("\n", $_POST["source_url"]);
if($source_urls == 1 && $source_type == "youtube"){
$source_url_err = "Please enter at least one url to your video.";
}
if($file_check == 0 && $source_type == "upload"){
$source_url_err = "Please select at least one video to upload.";
}
// Get video_loading method
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE video_loading = :video_loading";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":video_loading", $param_video_loading, PDO::PARAM_STR);
// Set parameters
$param_video_loading = htmlspecialchars(trim($_POST["video_loading"]));
// Attempt to execute the prepared statement
if($stmt->execute()){
$video_loading = htmlspecialchars(trim($_POST["video_loading"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get endless mode
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE endless = :endless";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":endless", $param_endless, PDO::PARAM_STR);
// Set parameters
if (isset($_POST["endless"])){
$param_endless = htmlspecialchars(trim($_POST["endless"]));
} else {
$param_endless = NULL;
}
// Attempt to execute the prepared statement
if($stmt->execute()){
if (isset($_POST["endless"])){
$endless = htmlspecialchars(trim($_POST["endless"]));
} else {
$endless = 'off';
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get video_loading method
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE n_of_entries = :n_of_entries AND n_of_participant_runs = :n_of_participant_runs";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":n_of_entries", $param_n_of_entries, PDO::PARAM_STR);
$stmt->bindParam(":n_of_participant_runs", $param_n_of_participant_runs, PDO::PARAM_STR);
// Set parameters
if ($source_type == "upload"){
$param_n_of_entries = count($_FILES["file"]['name']);
} elseif ($source_type == "youtube" || $source_type == "ftp") {
$source_urls = explode("\n", $_POST["source_url"]);
$param_n_of_entries = count(source_urls);
} elseif ($source_type == "user_upload" || $source_type == "user_youtube") {
$param_n_of_entries = htmlspecialchars(trim($_POST['n_of_participant_uploads']));
}
$actual_runs = $param_n_of_entries;
if ($video_loading == "random"){
$input_runs = htmlspecialchars(trim($_POST["n_of_participant_runs"]));
$input_runs = (is_numeric($input_runs) ? (int)$input_runs : 0);
if ($input_runs > 0){
$actual_runs = htmlspecialchars(trim($_POST["n_of_participant_runs"]));
}
}
$param_n_of_participant_runs = $actual_runs;
// Attempt to execute the prepared statement
if($stmt->execute()){
if ($source_type == "upload"){
$n_of_entries = count($_FILES["file"]['name']);
} elseif ($source_type == "youtube") {
$source_urls = explode("\n", $_POST["source_url"]);
$n_of_entries = count($source_urls);
} else {
$n_of_entries = 0;
}
$n_of_participant_runs = $actual_runs;
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get tolerance
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE tolerance = :tolerance";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":tolerance", $param_tolerance, PDO::PARAM_STR);
// Set parameters
$param_gtolerance = htmlspecialchars(trim($_POST["tolerance"]));
// Attempt to execute the prepared statement
if($stmt->execute()){
$tolerance = htmlspecialchars(trim($_POST["tolerance"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get sound
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE sound = :sound";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":sound", $param_sound, PDO::PARAM_STR);
// Set parameters
$param_sound = htmlspecialchars(trim($_POST["video_sound"]));
// Attempt to execute the prepared statement
if($stmt->execute()){
$sound = htmlspecialchars(trim($_POST["video_sound"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get upload message
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE upload_message = :upload_message";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":upload_message", $param_upload_message, PDO::PARAM_STR);
// Set parameters
$param_upload_message = htmlspecialchars(trim($_POST["upload-message"]), ENT_QUOTES, "UTF-8");
// Attempt to execute the prepared statement
if($stmt->execute()){
$upload_message = htmlspecialchars(trim($_POST["upload-message"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get start message
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE start_message = :start_message";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":start_message", $param_start_message, PDO::PARAM_STR);
// Set parameters
$param_start_message = htmlspecialchars(trim($_POST["start-message"]), ENT_QUOTES, "UTF-8");
// Attempt to execute the prepared statement
if($stmt->execute()){
$start_message = htmlspecialchars(trim($_POST["start-message"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get end message
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE end_message = :end_message";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":end_message", $param_end_message, PDO::PARAM_STR);
// Set parameters
$param_end_message = htmlspecialchars(trim($_POST["end-message"]), ENT_QUOTES, "UTF-8");
// Attempt to execute the prepared statement
if($stmt->execute()){
$end_message = htmlspecialchars(trim($_POST["end-message"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get survey label
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE survey_label = :survey_label";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":survey_label", $param_survey_label, PDO::PARAM_STR);
// Set parameters
$param_survey_label = htmlspecialchars(trim($_POST["survey-label"]));
// Attempt to execute the prepared statement
if($stmt->execute()){
$survey_label = htmlspecialchars(trim($_POST["survey-label"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get survey link
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE survey_link = :survey_link";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":survey_link", $param_survey_link, PDO::PARAM_STR);
// Set parameters
$param_survey_link = htmlspecialchars(trim($_POST["survey-link"]));
// Attempt to execute the prepared statement
if($stmt->execute()){
$survey_link = htmlspecialchars(trim($_POST["survey-link"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get autofill id
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE autofill_id = :autofill_id";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":autofill_id", $param_autofill_id, PDO::PARAM_STR);
// Set parameters
$param_autofill_id = htmlspecialchars(trim($_POST["autofill-id"]));
// Attempt to execute the prepared statement
if($stmt->execute()){
$autofill_id = htmlspecialchars(trim($_POST["autofill-id"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Get autofill key
// Prepare a select statement
$sql = "SELECT id FROM projects WHERE autofill_key = :autofill_key";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":autofill_key", $param_autofill_key, PDO::PARAM_STR);
// Set parameters
$param_autofill_key = htmlspecialchars(trim($_POST["autofill-key"]));
// Attempt to execute the prepared statement
if($stmt->execute()){
$autofill_key = htmlspecialchars(trim($_POST["autofill-key"]));
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Check input errors before inserting in database
if(empty($project_name_err) && empty($target_err) && empty($source_url_err)){
// Prepare an insert statement
$sql = "INSERT INTO projects (username, project_id, project_name, target, type, source_type, video_loading, endless, n_of_entries, n_of_participant_runs, sound, upload_message, start_message, end_message, survey_label, survey_link, autofill_id, autofill_key, archived, monochrome, ranktrace_smooth, ranktrace_rate, gtrace_control, gtrace_update, gtrace_click, gtrace_rate, tolerance)
VALUES (:username, :project_id, :project_name, :target, :type, :source_type, :video_loading, :endless, :n_of_entries, :n_of_participant_runs, :sound, :upload_message, :start_message, :end_message, :survey_label, :survey_link, :autofill_id, :autofill_key, :archived, :monochrome, :ranktrace_smooth, :ranktrace_rate, :gtrace_control, :gtrace_update, :gtrace_click, :gtrace_rate, :tolerance)";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":username", $param_username, PDO::PARAM_STR);
$stmt->bindParam(":project_id", $param_project_id, PDO::PARAM_STR);
$stmt->bindParam(":project_name", $param_project_name, PDO::PARAM_STR);
$stmt->bindParam(":target", $param_target, PDO::PARAM_STR);
$stmt->bindParam(":type", $param_type, PDO::PARAM_STR);
$stmt->bindParam(":source_type", $param_source_type, PDO::PARAM_STR);
$stmt->bindParam(":video_loading", $param_video_loading, PDO::PARAM_STR);
$stmt->bindParam(":endless", $param_endless, PDO::PARAM_STR);
$stmt->bindParam(":n_of_entries", $param_n_of_entries, PDO::PARAM_STR);
$stmt->bindParam(":n_of_participant_runs", $param_n_of_participant_runs, PDO::PARAM_STR);
$stmt->bindParam(":sound", $param_sound, PDO::PARAM_STR);
$stmt->bindParam(":upload_message", $param_upload_message, PDO::PARAM_STR);
$stmt->bindParam(":start_message", $param_start_message, PDO::PARAM_STR);
$stmt->bindParam(":end_message", $param_end_message, PDO::PARAM_STR);
$stmt->bindParam(":survey_label", $param_survey_label, PDO::PARAM_STR);
$stmt->bindParam(":survey_link", $param_survey_link, PDO::PARAM_STR);
$stmt->bindParam(":autofill_id", $param_autofill_id, PDO::PARAM_STR);
$stmt->bindParam(":autofill_key", $param_autofill_key, PDO::PARAM_STR);
$stmt->bindParam(":archived", $param_archived, PDO::PARAM_STR);
$stmt->bindParam(":monochrome", $param_monochrome, PDO::PARAM_STR);
$stmt->bindParam(":ranktrace_smooth", $param_ranktrace_smooth, PDO::PARAM_STR);
$stmt->bindParam(":ranktrace_rate", $param_ranktrace_rate, PDO::PARAM_STR);
$stmt->bindParam(":gtrace_control", $param_gtrace_control, PDO::PARAM_STR);
$stmt->bindParam(":gtrace_update", $param_gtrace_update, PDO::PARAM_STR);
$stmt->bindParam(":gtrace_click", $param_gtrace_click, PDO::PARAM_STR);
$stmt->bindParam(":gtrace_rate", $param_gtrace_rate, PDO::PARAM_STR);
$stmt->bindParam(":tolerance", $param_tolerance, PDO::PARAM_STR);
// Set parameters
$param_username = $username;
$param_project_id = $project_id;
$param_project_name = $project_name;
$param_target = $target;
$param_type = $type;
$param_source_type = $source_type;
$param_video_loading = $video_loading;
$param_endless = $endless;
$param_n_of_entries = $n_of_entries;
$param_n_of_participant_runs = $n_of_participant_runs;
$param_sound = $sound;
$param_upload_message = $upload_message;
$param_start_message = $start_message;
$param_end_message = $end_message;
$param_survey_label = $survey_label;
$param_survey_link = $survey_link;
$param_autofill_id = $autofill_id;
$param_autofill_key = $autofill_key;
$param_archived = "false";
$param_monochrome = $monochrome;
$param_ranktrace_smooth = $ranktrace_smooth;
$param_ranktrace_rate = $ranktrace_rate;
$param_gtrace_control = $gtrace_control;
$param_gtrace_update = $gtrace_update;
$param_gtrace_click = $gtrace_click;
$param_gtrace_rate = $gtrace_rate;
$param_tolerance = $tolerance;
// Attempt to execute the prepared statement
if($stmt->execute()){
// Redirect to login page
header("location: login.php");
} else{
echo "Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Init the project entries (Last of the youtube links is always empty).
$project_entries = [];
if ($source_type == "upload"){
$project_entries = $_FILES["file"]['name'];
} elseif ($source_type == "youtube" || $source_type == "ftp") {
$source_urls = explode("\n", $_POST["source_url"]);
$project_entries = $source_urls;
}
for ($x = 0; $x < count($project_entries); $x++) {
$file = $fileType = $file_path = "";
if ($file_check > 0 ){
$file = basename($project_entries[$x]);
$fileType = strtolower(pathinfo($file,PATHINFO_EXTENSION));
$file_path = $upload_dir.$project_id.'-'.($x+1).'.'.strtolower($fileType);
}
// Prepare a select statement
$sql = "SELECT id FROM project_entries WHERE source_url = :source_url AND entry_id = :entry_id";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":source_url", $param_source_url, PDO::PARAM_STR);
$stmt->bindParam(":entry_id", $entry_id, PDO::PARAM_STR);
// Set parameters
$param_entry_id = $x+1;
if ($source_type == "upload"){
$param_source_url = $file_path;
$param_original_name = explode(".", $file)[0];
} elseif ($source_type == "youtube" || $source_type == "ftp") {
$param_source_url = htmlspecialchars(trim($project_entries[$x]));
if ($source_type == "youtube") {
$param_original_name = explode("=", $param_source_url)[1];
} elseif ($source_type == "ftp") {
$param_original_name = htmlspecialchars(trim($project_entries[$x]));
$exe = explode(".", $param_original_name)[1];
$param_source_url = 'user_uploads/'.$project_id.'-'.$param_entry_id.'.'.$exe;
}
}
// Attempt to execute the prepared statement
if($stmt->execute()){
$entry_id = $x+1;
if ($source_type == "upload"){
$source_url = $file_path;
$original_name = explode(".", $file)[0];
} elseif ($source_type == "youtube" || $source_type == "ftp") {
$source_url = htmlspecialchars(trim($project_entries[$x]));
if ($source_type == "youtube") {
$original_name = explode("=", $source_url)[1];
} elseif ($source_type == "ftp") {
$original_name = htmlspecialchars(trim($project_entries[$x]));
$exe = explode(".", $original_name)[1];
$source_url = 'user_uploads/'.$project_id.'-'.$entry_id.'.'.$exe;
}
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
// Prepare an insert statement
$sql = "INSERT INTO project_entries (project_id, entry_id, source_type, source_url, original_name)
VALUES (:project_id, :entry_id, :source_type, :source_url, :original_name)";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":project_id", $param_project_id, PDO::PARAM_STR);
$stmt->bindParam(":entry_id", $entry_id, PDO::PARAM_STR);
$stmt->bindParam(":source_type", $param_source_type, PDO::PARAM_STR);
$stmt->bindParam(":source_url", $param_source_url, PDO::PARAM_STR);
$stmt->bindParam(":original_name", $param_original_name, PDO::PARAM_STR);
// Set parameters
$param_project_id = $project_id;
$param_entry_id = $entry_id;
$param_source_type = $source_type;
$param_source_url = $source_url;
$param_original_name = $original_name;
// Attempt to execute the prepared statement
if($stmt->execute()){
// If successful, also upload files
if ($file_check > 0 && $source_type == "upload") {
if (move_uploaded_file($_FILES["file"]["tmp_name"][$x], $file_path)) {
//echo "The file ". basename($_FILES["file"]["name"][$x]). " has been uploaded.";
} else {
$source_url_err = "Sorry, there was an error uploading your file.";
}
}
// Redirect to projects page
header("location: projects.php");
} else{
echo "Something went wrong. Please try again later.";
}
}
// Close statement
unset($stmt);
}
}
// Close connection
unset($pdo);
}
include("header.php");
?>
<div id="subheader">
<h2>[Platform for Audiovisual General-purpose ANotation]</h2>
<div class="subheader-buttons"><a class="button" href="./projects.php">go back</a><a class="button" href="./logout.php">log out</a></div>
</div>
<div class="page-header">
<div>
<p>Create a new project below.</p>
</div>
</div>
<div>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="multipart/form-data">
<div class="form-group <?php echo (!empty($project_name_err)) ? 'has-error' : ''; ?>">
<label>Project Title</label>
<span class="help-block"><?php echo $project_name_err; ?></span>
<input placeholder="My Project" type="text" name="project_name" class="form-control" value="<?php echo $project_name; ?>">
</div>
<div class="form-group <?php echo (!empty($target_err)) ? 'has-error' : ''; ?>">
<label>Annotation Target</label>
<span class="help-block"><?php echo $target_err; ?></span>
<input placeholder="arousal" type="text" name="target" class="form-control" value="">
</div>
<div class="form-group" id="start-message">
<label>Optional Target Description</label>
<textarea class="form-control" placeholder="An optional short description displayed below the automatic instructions at the beginning of the annotation. Use it to help participants understand the labelling task (max 200 characters)." rows="5" cols="46" name="start-message" wrap="soft" maxlength="200" style="overflow:hidden; resize:none;"></textarea>
</div>
<div class="form-group">
<label>Annotation Type</label>
<div id="type-select" >
<input type="radio" name="type" value="ranktrace" checked><span>RankTrace</span>
<input type="radio" name="type" value="gtrace"><span>GTrace</span>
<input type="radio" name="type" value="binary"><span>BTrace</span>
<hr>
<input type="checkbox" name="monochrome" value="on"><span>Monochrome Graph</span>
<div id="ranktrace-config">
<label>Smooth RankTrace Display</label>
<input type="checkbox" name="ranktrace_smooth" value="on" checked><span>Smooth RankTrace graph</span><br>
<p style="padding-top:5px; margin: 0"><span id="ranktrace_rate-value">Update graph at a <b>500ms</b> interval.</span></p>
<input type="range" min="0" max="300" value="15" step="7.5" name="ranktrace_rate" class="form-control">
<br><i style="font-size: 0.7em">Smooths the displayed trace (not the collected data).</i>
</div>
<div id="gtrace-config" class="hidden">
<label>GTrace Configuration</label>
<input type="radio" name="gtrace_control" value="keyboard"> <span>Keyboard</span>
<input type="radio" name="gtrace_control" value="mouse" checked> <span>Mouse</span><br>
<span id="mouse-click-box">
<hr>
<input type="checkbox" name="gtrace_update" value="on" checked><span>Continuous Annotation</span><br>
<input type="checkbox" name="gtrace_click" value="on" checked><span>Annotation on Click</span>
</span>
<span id="rate-box">
<hr>
<p style="padding-top:5px; margin: 0"><span id="gtrace_rate-value">Update GTrace at a <b>1sec</b> interval.</span></p>
<input type="range" min="250" max="3000" value="1000" step="250" name="gtrace_rate" class="form-control">
</span>
</div>
</div>
</div>
<div class="form-group">
<label>Project Source</label>
<span class="help-block"><?php echo $source_url_err; ?></span>
<div id="source-select">
<input type="radio" name="source_type" value="youtube" checked> <span>YouTube</span>
<?php
if ($access == 'admin') {
echo '<input type="radio" name="source_type" value="upload"> <span>Uploaded Videos</span><br>';
echo '<input type="radio" name="source_type" value="ftp"> <span class="project-info">Direct FTP Uploads<span class="project-info-box" >Get database names for FTP upload from "Get Entries" on the Projects page.</span></span><br>';
}
?>
<hr>
<input type="radio" name="source_type" value="user_youtube"> <span>Subject Youtube</span>
<?php
if ($access == 'admin') {
echo '<input type="radio" name="source_type" value="user_upload"> <span>Subject Upload</span>';
}
?>
<!-- <hr> -->
<!-- <input type="radio" name="source_type" value="game"> <span>Uploaded Game</span> -->
</div>
<div class="form-group <?php echo (!empty($source_url_err)) ? 'has-error' : ''; ?>" id="project-entries">
<?php
if ($access == 'admin') {
echo '<input type="file" multiple name="file[]" class="form-control hidden" id="file-source" accept="video/mp4,video/avi,video/webm,video/mpeg,video/mov" value="">';
}
?>
<!-- <input type="text" name="source_url[]" class="form-control youtube-source" value=""> -->
<textarea class="form-control youtube-source" placeholder="One entry per row." rows="5" cols="46" name="source_url" wrap="soft" style="resize:vertical;"></textarea>
</div>
</div>
<div class="form-group subject-upload hidden" id="upload-message">
<label>Optional Upload Instructions</label>
<textarea class="form-control" placeholder="An optional short instruction displayed to your participants when they upload or link to their own videos for annotation (max 500 characters)." rows="13" cols="46" name="upload-message" wrap="soft" maxlength="500" style="overflow:hidden; resize:none;"></textarea>
</div>
<div class="form-group" id='loading'>
<label>How to Load Videos</label>
<input class="researcher-upload" type="radio" name="video_loading" value="random" checked><span class="researcher-upload">Randomly</span>
<input type="radio" name="video_loading" value="sequence"> <span style="margin-right: 0;">In Sequence</span>
<br><input type="checkbox" name="endless" value="on"><span>Endless Mode</span>
</div>
<div class="form-group" id='tolerance'>
<label>Tolerance of Missing Labels</label>
<p style="padding-top:5px; margin: 0">Completes at least <b><span id="tolerance-value">50</span>%</b> of the task.</p>
<input type="range" min="1" max="99" value="50" name="tolerance" class="form-control">
</div>
<div class="form-group researcher-upload" id="participant-runs">
<label>Number of Annotations<br>a Participant Completes</label>
<p style="padding-top:5px; margin: 0">Annotates <strong id="n_run-value">0</strong> out of <strong id="entry-n">0</strong> videos.</p>
<input type="range" min="1" max="1" value="1" name="n_of_participant_runs" class="form-control">
<!-- <input placeholder="play all (default)" type="number" min="1" name="n_of_participant_runs" class="form-control"><span> out of </span><strong id="entry-n">0</strong> -->
<br><i style="font-size: 0.7em">Optional for randomized video order.</i>
</div>
<div class="form-group subject-upload hidden" id="participant-uploads">
<label>Number of Videos<br>a Participant Uploads</label>
<input value="1" type="number" name="n_of_participant_uploads" class="form-control">
</div>
<div class="form-group">
<label>Play Videos With Sound</label>
<div id='sound'>
<input type="radio" name="video_sound" value="on" checked> <span>Yes</span>
<input type="radio" name="video_sound" value="off"> <span>No</span>
</div>
</div>
<div class="form-group" id="end-message">
<label>Optional End-Plate Message</label>
<textarea class="form-control" placeholder="An optional short message or instructions displayed to your participants below the automatic thank you message at the end of the annotation (max 200 characters)." rows="5" cols="46" name="end-message" wrap="soft" maxlength="200" style="overflow:hidden; resize:none;"></textarea>
</div>
<div class="form-group" id="survey-label">
<label>Optional Button Label</label>
<input placeholder="go to survey" type="text" name="survey-label" class="form-control survey-label" value="">
</div>
<div class="form-group" id="survey-link">
<label>Optional Button Link</label>
<input placeholder="Button will not be added if left empty." type="text" name="survey-link" class="form-control survey" value="">
</div>
<div class="form-group" id="autofill-id">
<label>Autofill Participant ID<br>to <span class="project-info">Google Forms<span class="project-info-box" id="google-forms">You can use the Google Form pre-fill entry ids to specify an field for the participant IDs, which are automatically filled in. This option lets you match the completed surveys to the video annotations through an anonymised ID (GUID). For more information see the <a href="https://gsuite.google.com/learning-center/tips/forms/#!/show-tip/pre-fill-form-answers" target="_blank">Google Forms Documentation</a>.</span></span></label>
<input placeholder='ID number of form entry (e.g. 1234567890).' type="text" name="autofill-id" class="form-control" value="">
</div>
<div class="form-group" id="autofill-key">
<label>Add Unique Verification Key<br>to <span class="project-info">Google Forms<span class="project-info-box" id="google-forms">You can use the Google Form pre-fill entry ids to specify an field for a unique key that will be given the user. This option allows you check whether a user has completed the task and the survey. For more information see the <a href="https://gsuite.google.com/learning-center/tips/forms/#!/show-tip/pre-fill-form-answers" target="_blank">Google Forms Documentation</a>.</span></span></label>
<input placeholder='ID number of form entry (e.g. 1234567890).' type="text" name="autofill-key" class="form-control" value="">
</div>
<div class="form-group" id="submit">
<input type="submit" class="button" value="submit">
<input type="reset" class="button" value="reset">
</div>
</form>
</div>
<?php
$scripts = ['create_project.js'];
include("scripts.php");
$tooltip = '';
include("footer.php");
?>