-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
executable file
·81 lines (63 loc) · 2.27 KB
/
index.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
<?php
error_reporting(E_ALL);
ini_set("display_errors", -1);
setlocale(LC_ALL, 'en_US.UTF8');
#==============================================#
define("SHA",false); # Small Http : SH Authentication [ Don't remove it ]
#==============================================#
require 'vendor/autoload.php';
require 'Http.php';
$app = new Http();
$app->get('/',function($app){
#$app->json('Welcome to SH service');
$q = $app->db->get('users');
#$q = db()->get('users');
$app->json($q->result());
});
$app->page('/users',function($app,$req){
$data['app'] = $app;
$data['req'] = $req;
$app->html("all-users",$data);
});
$app->get('/users/:id',function($app,$req){
$data['app'] = $app;
$data['req'] = $req;
$app->html("all-users",$data);
});
$app->post('/users/:id',function($app,$req){
$id = (int)$req->id; if($id==0) $app->json("Invalid argument");
#$req->session->delete('user_total'); die;
if($req->session->get('user_total') == ""){
$q = $app->db->query("SELECT count(id) as total FROM csv_table");
$result= $q->result_object();
$req->session->set('user_total',$result[0]->total);
}
$totalRecords = $req->session->get('user_total');
$paginator = $app->library('Paginator');
$paginator->itemsPerPage = 30;
$paginator->total = ($totalRecords/$paginator->itemsPerPage);
$paginator->_link = 'http://localhost:83/users/';
$currentPage = $req->id-1;
$limiter = $currentPage*$paginator->itemsPerPage;
//get record from database and show
$records = $app->db->query("Select id,email from csv_table LIMIT ".$limiter.", ".$paginator->itemsPerPage);
foreach($records->result_object() as $obj){
echo $obj->id.'=>'.$obj->email."<br>";
}
//print
$paginator->paginate($req->id);
echo 'Records '.$req->id*$paginator->itemsPerPage.' of '.$totalRecords;
});
/*
$app->get('/user/:id',function($app,$req){
$id = (isset($req->id) && $req->id!='')?$req->id:'1';
$q = $app->db->get_where('users',['user_id'=>$id]);
echo json_encode($q->result());
});
*/
# $obj = Curl::get('https://localhost/sh-service/'); # object
# echo Curl::get('https://localhost/sh-service/',true); # raw
# CMS Routes
#$app->droutes('PAGE/',true); # check routes from database
$app->run(); # Extender
?>