|
1 | 1 | <?php |
2 | | -$csrf_got = @$_POST['csrf']; |
| 2 | +header("Access-Control-Allow-Origin: *"); |
| 3 | +header('Content-Type: text/event-stream'); |
| 4 | +header('Cache-Control: no-cache'); |
| 5 | + |
| 6 | + |
| 7 | +$db = new DATABASE; |
| 8 | +$sse = new SSE; |
| 9 | + |
| 10 | +$csrf_got = @$_REQUEST['csrf']; |
3 | 11 | $validateEmail = false; // VALIDATE EMAIL (true/false) |
4 | 12 | $url = page(PAGE); |
| 13 | +$validkey = false; |
| 14 | + |
| 15 | + |
| 16 | +if(check_csrf($csrf_got)){ |
| 17 | + $validkey = true; |
| 18 | +} |
| 19 | + |
| 20 | +// FREE CASES |
| 21 | +$casefree = explode(",","test"); |
| 22 | +if(isset($url[1]) && in_array($url[1],$casefree)){ |
| 23 | + $validkey = true; |
| 24 | +} |
| 25 | +// ========= |
| 26 | + |
| 27 | +if(!$validkey){ |
| 28 | + $err['error'] = "Token is not valid"; |
| 29 | + $err['success'] = false; |
| 30 | + die(json_encode($err)); |
| 31 | +} |
| 32 | + |
5 | 33 | //print_r($url); |
6 | 34 | switch (@$url[1]){ |
7 | 35 |
|
8 | | - // Dummy |
9 | | - case "categorylist": |
10 | | - echo '<option value="0">Main</option>'; |
11 | | - $db = new DATABASE; |
12 | | - $res = $db->query("SELECT c.id,c.category FROM category as c |
13 | | - WHERE c.pid='0' AND c.status='1'"); |
14 | | - $tpl=new TEMPLATE; |
15 | | - $template='<option value="{{id}}">{{category}}</option>'; |
16 | | - $list=$tpl->viewer($res,$template); |
| 36 | + // dummy1 |
| 37 | + case "test": |
| 38 | + $msx = '<select name="" label="All Users" multiple>'; |
| 39 | + $msx .= $tmp->viewer($db->query("SELECT * FROM users"),'<option value="{{id}}">{{name}}</option>',false,true); |
| 40 | + $msx .= '</select>'; |
| 41 | + |
| 42 | + $sse->seepreformat($msx); |
| 43 | + break; |
| 44 | + |
| 45 | + // dummy2 |
| 46 | + case "tbldata": |
| 47 | + $sql = @$url[2]; |
| 48 | + $tbtn = @$url[3]; |
| 49 | + $sqlquery = base64_decode($sql); |
| 50 | + $token = $_SESSION["token"]; |
| 51 | + $template = '<tr template="" id="row{{id}}"> |
| 52 | + <td class="status-field"><span onclick="statusupdate(this)" data-value="{{status}}" data-id="{{id}}" data-action="users" class="status {{statustxt}}">{{statustxt}}</span> {{name}}</td><td>{{email}}</td><td>{{phone}}</td> |
| 53 | + <td class="elitable-actions"> |
| 54 | + <span class="mdi mdi-pencil btn blue white-text small" onclick="editData(this,\'#editusersmod\',\'getdatajson\')" data-t="users" csrf="'.$token.'" data-id="{{id}}"></span> |
| 55 | + <span class="mdi mdi-close btn red white-text small" onclick="delrow(this,\'#row\')" csrf="'.$token.'" data-id="{{id}}" data-action="users"></span> |
| 56 | + </td> |
| 57 | + </tr>'; |
| 58 | + |
| 59 | + $templatex = str_replace('template=""',"",$template); |
| 60 | + $tbldata = $template; |
| 61 | + $tbldata .= $tmp->viewer($db->query($sqlquery),$templatex,false,true); |
| 62 | + |
| 63 | + $sse->seepreformat($tbldata); |
| 64 | + break; |
| 65 | + |
| 66 | + // Option Field |
| 67 | + case "optionfield": |
| 68 | + // Example: "v/optionfield/tblname/columns|id|true"; |
| 69 | + $tbl = @$url[2]; |
| 70 | + $col = explode("|",$url[3]); |
| 71 | + |
| 72 | + $val = (isset($col[1]))?$col[1] : 'id'; |
| 73 | + $txt = (isset($col[0]))?$col[0] : 'id'; |
| 74 | + |
| 75 | + $where = " "; |
| 76 | + if(isset($col[2]) AND $col[2] == "true"){ |
| 77 | + $where .= " status='1' "; |
| 78 | + } |
| 79 | + else |
| 80 | + { |
| 81 | + $where .=" 1 "; |
| 82 | + } |
| 83 | + |
| 84 | + $xmsg = '<option value=""></option>'; |
| 85 | + $res = $db->query("SELECT $val,$txt FROM $tbl |
| 86 | + WHERE $where "); |
| 87 | + $template='<option value="{{'.$val.'}}">{{'.$txt.'}}</option>'; |
| 88 | + $xmsg .= $tmp->viewer($res,$template,false,true); |
| 89 | + |
| 90 | + $data = array( |
| 91 | + 'message' => base64_encode($xmsg), |
| 92 | + 'timestamp' => time() |
| 93 | + ); |
| 94 | + $sse->sendSSE($data); |
| 95 | + // Simulate a delay between updates |
| 96 | + // sleep(5); |
| 97 | + |
17 | 98 | break; |
18 | 99 |
|
19 | 100 | default: |
20 | | - $pageurl = VIEW."$page"; |
| 101 | + $pageurl = VIEW.end($url); |
21 | 102 | if(file_exists($pageurl)) |
22 | 103 | { |
23 | 104 | include($pageurl); |
24 | 105 | } |
25 | 106 | else |
26 | 107 | { |
27 | | - include(VIEW.'404.php'); |
| 108 | + if(file_exists(VIEW.'404.php')){ |
| 109 | + include(VIEW.'404.php'); |
| 110 | + } |
| 111 | + else |
| 112 | + { |
| 113 | + echo "404 Error. Page not Found"; |
| 114 | + } |
28 | 115 | } |
29 | 116 | break; |
30 | 117 | } |
|
0 commit comments