-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetJSON_DB.php
More file actions
107 lines (99 loc) · 2.27 KB
/
Copy pathgetJSON_DB.php
File metadata and controls
107 lines (99 loc) · 2.27 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
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET');
class column
{
public $field;
public $title;
public $width;
public $hidden;
public $editor;
public $sortable;
function column($id, $caption)
{
$this->field = $id;
$this->title = $caption;
$this->width = "100px";
$this->hidden = false;
$this->sortable = false;
}
}
class combo
{
public $type;
public $options;
function combo()
{
$this->type = "combo";
$this->options = array();
}
}
class option
{
public $id;
public $text;
function option($id, $text)
{
$this->id = $id;
$this->text = $text;
}
}
class Course
{
public $CourseID;
public $Title;
public $Credits;
}
require_once("./db/DB_config.php");
require_once("./db/DB_Class.php");
$type = $_GET["type"];;
$page = isset($_POST['page']) ? intval($_POST['page']) : 0;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$sort = isset($_POST['sort']) ? strval($_POST['sort']) : "";
$offset = ($page)*$rows;
if($sort != "")
{
$sort = "Order By $sort";
}
$sql = "SELECT * FROM Course";
$sql = $sql." $sort limit $offset,$rows";
$db = new DB();
$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
$res = $db->query($sql);
if($res == "true"){
$items = array();
while($row = $db->fetch_assoc()){
array_push($items, $row);
}
}else{
echo get_class($this)."->".__FUNCTION__." at ".__LINE__." => $res";
}
$result["total"] = 30;
$result["rows"] = $items;
$result["msg"] = $sql;
if($type == "init")
{
$columns = array();
$col = new column("CourseID", "code");
$col->editor = "text";
array_push($columns, $col);
$col = new column("Title", "Title");
$col->editor = "text";
$col->sortable = true;
array_push($columns, $col);
$col = new column("Credits", "Credits");
$col->sortable = true;
$col->editor = new combo();
$opt = new option("1", "1");
array_push($col->editor->options, $opt);
$opt = new option("2", "2");
array_push($col->editor->options, $opt);
$opt = new option("3", "3");
array_push($col->editor->options, $opt);
$opt = new option("4", "4");
array_push($col->editor->options, $opt);
array_push($columns, $col);
$result["columns"] = $columns;
}
echo json_encode($result);
?>