-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid-forms.php
83 lines (60 loc) · 1.74 KB
/
grid-forms.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
<?php
/**
* JqGrid neccessary callbacks for forms
*
* @author Adam Studenic
*
*/
include 'functions.php';
$userId = $_SESSION["user_id"];
$page = $_GET['page'];
$limit = $_GET['rows'];
$sidx = $_GET['sidx'];
$sord = $_GET['sord'];
if (!$sidx)
$sidx = 1;
$result = dibi::query("SELECT COUNT(*) AS count FROM `hd_form` WHERE user_id = $userId AND deleted = 0");
$count = $result->fetchSingle();
// calculate the total pages for the query
if ($count > 0 && $limit > 0) {
$total_pages = ceil($count / $limit);
} else {
$total_pages = 0;
}
// if for some reasons the requested page is greater than the total
// set the requested page to total page
if ($page > $total_pages) {
$page = $total_pages;
}
// calculate the starting position of the rows
$start = $limit * $page - $limit;
// if for some reasons start position is negative set it to 0
// typical case is that the user type 0 for the requested page
if ($start < 0)
$start = 0;
// the actual query for the grid data
$SQL = "SELECT * FROM hd_form WHERE user_id = $userId AND deleted = 0 ORDER BY $sidx $sord LIMIT $start , $limit";
try {
$result = dibi::query($SQL);
$rows = $result->fetchAll();
} catch (DibiException $e) {
var_dump($e);
};
$rowsArr = array();
foreach ($rows as $i => $row) {
$rowsArr[$i]["id"] = $i;
$rowsArr[$i]["cell"][] = $row["id"];
$config = (array) json_decode($row["config"]);
$form = (array)$config["form"];
$rowsArr[$i]["cell"][] = $form["form-action"];
$rowsArr[$i]["cell"][] = $form["domain"];
}
$resultArr = array();
$resultArr ["page"] = $page;
$resultArr ["total"] = $total_pages;
$resultArr ["records"] = $count;
$resultArr ["rows"] = $rowsArr;
$arrrr = fix_keys($resultArr);
$js = json_encode($arrrr);
echo $js;
?>