-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathajax.php
executable file
·72 lines (66 loc) · 2.03 KB
/
ajax.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
<?php
$options = array('extension' => '.htm');
$ajaxTemplate = new Mustache_Engine(array(
'loader' => new Mustache_Loader_FilesystemLoader('AjaxTemplates', $options),
));
// Function to load in API Controllers.
// DO NOT TRUST THIS WITH EXTERNAL DATA!!!
// Note your class must be named in the following format:
// $name = "index" means a class name of IndexController
function GetAjaxController($name) {
//echo "<h1>File exits?</h1>";
if (file_exists('AjaxControllers/' . $name . ".php")) {
require_once('AjaxControllers/' . $name . ".php");
$className = ucwords($name)."Controller";
return new $className;
}else{
die();
}
}
function RenderAjax($templ, $objects) {
global $ajaxTemplate;
$objects["BaseURL"] = $GLOBALS['CONFIG']['app-path'];
$inner = $ajaxTemplate->render($templ, $objects);
//echo "<h1>RENDERING AJAX?</h1>";
return $inner;
}
class AjaxController {
public $template = "";
public $pageData = array();
public $failureReason = "";
public $session_id = "";
public function process($get, $post) {
$session = new SessionModel();
$session_id = $session->getCurrentSessionId();
if(!$session->isInSession()){
$this->failureReason = "Not in Session";
return false;
}else{
$this->session_id = $session_id;
$this->pageData = "ajaxcall";
return true;
}
// Must return if the opporations were successful
}
public function render($success) {
// Set universal "$this->pageData['defaultPP']" items here
if($success){
if(file_exists('AjaxTemplates/'.$this->template.'.htm')){ // If this ajax call has a template
echo json_encode(array(
"success" => true,
"data" => RenderAjax($this->template,$this->pageData)
));
}else{ // All that matters is that there was success (there's no template for this ajax call)
echo json_encode(array(
"success" => true,
"data" => $this->pageData
));
}
}else{
echo json_encode(array(
"success" => false,
"reason" => $this->failureReason
));
}
}
}