-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsuggestr.php
More file actions
executable file
·127 lines (108 loc) · 4.08 KB
/
suggestr.php
File metadata and controls
executable file
·127 lines (108 loc) · 4.08 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
<?php
/* Main Application - Request Router */
// Load our config and initialization
require_once('config.php');
require_once('./AjaxModels/SessionModel.php');
//header('Content-Type: text/html; charset=utf-8');
// Make sure we have a page to load.
// IIS should handle this for us through URL Rewriting.
// This script should not be loaded directly by anyone.
if(!isset($_GET['SUGGESTR_PAGE'])){
die();
}
// If this page load wasn't specified as an AJAX page load, mark it as such.
if(!isset($_GET['AJAX']))
$_GET['AJAX'] = false;
// Controller Router
// The keys in the router array are page URLs
// The values in the router array are controller names
$router = array();
$router["/landing"] = "Landing";
$router["/home"] = "Home";
$router["/ml"] = "ML";
//$router["/visualization"] = "Visual";
// API Router
// The keys in the router array are page URLs
// The values in the router array are controller names
$Ajaxrouter = array();
$Ajaxrouter["Search/"] = "Search";
$Ajaxrouter["Suggest/"] = "Suggest";
$Ajaxrouter["Slider/"] = "Slider";
$Ajaxrouter["IgnoreCourse/"] = "IgnoreCourse";
$Ajaxrouter["AddCourse/"] = "AddCourse";
$Ajaxrouter["TookCourse/"] = "TookCourse";
$Ajaxrouter["RemoveCourse/"] = "RemoveCourse";
$Ajaxrouter["AddTag/"] = "AddTag";
$Ajaxrouter["Reset/"] = "Reset";
$Ajaxrouter["AddRating/"] = "AddRating";
$Ajaxrouter["AddSessionAspect/"] = "AddSessionAspect";
$Ajaxrouter["MajorRelations/"] = "MajorRelations";
$Ajaxrouter["AddAdvisory/"] = "AddAdvisory";
$Ajaxrouter["GetMajors/"] = "GetMajors";
$Ajaxrouter["CreateSession/"] = "CreateSession";
$Ajaxrouter["SimilarSuggestions/"] = "SimilarSuggestions";
$Ajaxrouter["ListCourses/"] = "ListCourses";
$Ajaxrouter["AdvisoryQuery/"] = "AdvisoryQuery";
$Ajaxrouter["CustomAlgorithm/"] = "CustomAlgorithm";
// Is this an API method?
$isAjax = (isset($_GET['SUGGESTR_PAGE']) && (strpos($_GET['SUGGESTR_PAGE'],'ajax/') === 0));
// Redirect to the user's page if no page is specified (we already know that the user is logged in).
//echo $_GET['SUGGESTR_PAGE'];
//Cookie only set temporarily
//setcookie('sessionId', 4996842, time()+315360000, '/');
//***********HOW TO get to work this without default***/
//$_GET['SUGGESTR_PAGE'] = '/ml';
//$_GET['SUGGESTR_PAGE'] = '/landing';
#echo "cookie:",$_COOKIE['sessionId'];
$session_model = new SessionModel();
#$session_model->handleSession();
#echo "is in session_id:",var_dump($session_model->isInSession());
if($_GET['SUGGESTR_PAGE']=='/home'){
if(!$session_model->isInSession()){
//echo "Clear everything";
//$_GET['SUGGESTR_PAGE'] = '/home'
$_GET['SUGGESTR_PAGE'] = '/landing';
}else{
$_GET['SUGGESTR_PAGE'] = '/home';
}
}
#echo "page:",$_GET['SUGGESTR_PAGE'];
#echo "is in session_id:",var_dump($session_model->isInSession());
// Needs to reload since a cookie must be set at the start of the request.
$controller;
ob_start();
if(!$isAjax){
if(!array_key_exists($_GET['SUGGESTR_PAGE'],$router)) {
//echo "404";
header($_GET["SUGGESTR_PAGE"]." 404 Not Found");
$_SYSTEM["SUGGESTR_PAGE"] = "404 - Page Not Found";
$controller = GetController("error");
}else{
//echo "getcontroller";
$controller = GetController($router[$_GET['SUGGESTR_PAGE']]);
}
//echo "process";
$controller->process($_GET,$_POST,$_FILES,$_SYSTEM);
die($controller->render(!$_GET['AJAX']));
}else{
// We need to have authentication variables ready
// Running user_isadmin sets them.
// Note we don't care if the user is or is not an admin
//user_isadmin();
//Basically $_GET['SUGGESTR_PAGE'] tells the controller to display the home.htm
//and to render it with home.php
//echo "replace";
$method = str_replace("ajax/","",$_GET['SUGGESTR_PAGE']);
if(!array_key_exists($method,$Ajaxrouter)) {
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
die(json_encode(array(
"success" => false,
"reason" => "Invalid Method"
))
);
}else{
$controller = GetAjaxController($Ajaxrouter[$method]);
}
$success = $controller->process($_GET,$_POST,$_FILES,$_SYSTEM);
die($controller->render($success));
}