forked from jmueller17/Aixada
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage_table.php
253 lines (206 loc) · 8.22 KB
/
manage_table.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?php include "php/inc/header.inc.php" ?>
<?php
/**
* This function looks at the current_role written to the
* cookie and the $_SESSION['userdata'] to determine if the table
* currently requested may be edited by the user in the current role.
*/
function navGrid_options() {
if (isset($_REQUEST['table'])) {
$table = strstr($_REQUEST['table'], '_');
$property = 'may_edit' . $table;
if (in_array($property,
configuration_vars::get_instance()->rights_of[$_SESSION['userdata']['current_role']])) {
echo '{edit:true,add:true,del:true,search:false},';
} else {
echo '{edit:false,add:false,del:false,search:false},';
}
} else {
echo '{edit:false,add:false,del:false,search:false},';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?=$language;?>" lang="<?=$language;?>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php
$what = (isset($_REQUEST['what']) ? ' - ' . $_REQUEST['what'] : '');
echo $Text['global_title'] . " - " . $Text['head_ti_manage'] . $what; ?>
</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/aixada_main.css" />
<link rel="stylesheet" type="text/css" media="screen" href="js/fgmenu/fg.menu.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui-themes/<?=$default_theme;?>/jqueryui.css"/>
<link rel="stylesheet" type="text/css" media="screen" href="js/jqGrid-4.3.1/css/ui.jqgrid.css"/>
<!-- this cannot be minified because the order of the i18n file for jqgrid is important -->
<script type="text/javascript" src="js/jquery/jquery.js"></script>
<script type="text/javascript" src="js/jqGrid-4.3.1/js/i18n/grid.locale-<?=$language;?>.js"></script>
<script type="text/javascript" src="js/jqGrid-4.3.1/js/jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="js/jqueryui/jqueryui.js"></script>
<script type="text/javascript" src="js/fgmenu/fg.menu.js"></script>
<script type="text/javascript" src="js/aixadautilities/jquery.aixadaMenu.js"></script>
<script type="text/javascript" src="js/aixadautilities/jquery.aixadaXML2HTML.js" ></script>
<script type="text/javascript" src="js/aixadautilities/jquery.aixadaUtilities.js" ></script>
<script type="text/javascript">
var selected_row;
var lastsel = 0;
/**
* Custom extension to retrieve the detail table for a given table
*/
$.extend({
getDetails: function(table){
var tbl = (table == null)? $.getUrlVar('table'):table;
var details = [];
if (tbl == 'aixada_uf'){
details['table'] = 'aixada_member';
details['key'] = 'uf_id';
} else if (tbl == 'aixada_provider'){
details['table'] = 'aixada_product';
details['key'] = 'provider_id';
} else if (tbl == 'aixada_order_cart'){
details['table'] = 'aixada_order_item';
details['key'] = 'order_cart_id';
}
return details;
}
});
/**
* main table
*/
$(document).ready(function (){
var current_table = $.getUrlVar('table');
if (current_table == null || current_table == '') {
alert("variable table not set in query");
}
$.ajax({
type: 'POST',
url: 'php/ctrl/TableManager.php?table='+current_table+'&oper=getColumnsAsJSON',
dataType: 'json',
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.statusText +" "+ thrownError);
},
success: function(result){
colN = result.col_names;
colM = result.col_model;
active_fields = result.active_fields;
opt = result.field_options;
var filter_text = new String('');
var filter_cond = $.getUrlVar('filter');
if (filter_cond.length>0) {
filter_text = "&filter=" + filter_cond;
}
$("#desc").jqGrid({
url: "php/ctrl/TableManager.php?table="+current_table+"&oper=listAll" + filter_text,
height: 200,
datatype: 'xml',
colNames: eval(colN),
colModel: eval('('+colM+')'),
xmlReader: {
root: 'rowset',
row: 'row',
page: 'page',
total: 'total',
records: 'records',
repeatitems: false,
id: 'id'
},
rowNum: 10,
rowList: [10,20,30],
autowidth: true,
height:'100%',
pager: '#desc_pager',
sortname: 'name',
viewrecords: true,
sortorder: 'asc',
onSelectRow: function(ids) {
if (current_table == 'aixada_uf' || current_table == 'aixada_provider' || current_table == 'aixada_order_cart') {
var details = $.getDetails();
$("#detail").jqGrid('clearGridData');
$("#detail").jqGrid('setGridParam',{url:"php/ctrl/TableManager.php?table="+details['table']+"&oper=listAll&filter="+details['key']+"="+ids,page:1});
$("#detail").jqGrid('setCaption', 'Detail for ' + current_table + ': ' +ids).trigger('reloadGrid');
$("#detail").jqGrid('setGridParam',{editurl:"php/ctrl/TableManager.php?table="+details['table']+"&oper=get_by_key"+"&key="+details['key']+"&val="+ids,page:1});
}
}, //end on select row
multiselect: false,
editurl:"php/ctrl/TableManager.php?table=" + current_table,
caption: current_table,
}) // close jqgrid
$("#desc").navGrid('#desc_pager',
<?php navGrid_options(); ?>
{reloadAfterSubmit:true, width:600, dataheight:400, top:50, left:50}, //edit options
{reloadAfterSubmit:true, width:600, dataheight:400, top:50, left:50}, //add options
{reloadAfterSubmit:true}, //del options
{width:600, top:50, left:50} //search options
);
}//close success
});//close ajax
/**
* detail Grid
*/
if (current_table == 'aixada_uf' || current_table == 'aixada_provider' || current_table == 'aixada_order_cart'){
$.ajax({
type: 'POST',
url: "php/ctrl/TableManager.php?table="+$.getDetails()['table']+"&oper=getColumnsAsJSON",
dataType: 'json',
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.statusText +" "+ thrownError);
},
success: function(result){
colN = result.col_names;
colM = result.col_model;
opt = result.field_options;
$("#detail").jqGrid({
url: "", // this should be empty so that the table doesn't display junk on the first load of the page
height: 200,
width: 1600,
datatype: 'xml',
colNames: eval(colN),
colModel: eval('('+colM+')'),
xmlReader: {
root: 'rowset',
row: 'row',
page: 'page',
total: 'total',
records: 'records',
repeatitems: false,
id: 'id'
},
autowidth: true,
height:'100%',
pager: '#detail_pager',
sortname: 'name',
viewrecords: true,
sortorder: 'asc',
multiselect: false,
editurl:"php/ctrl/TableManager.php?table=" + $.getDetails()['table']
}) // close jqgrid
$("#detail").navGrid('#detail_pager',
<?php navGrid_options(); ?>
{reloadAfterSubmit:true, width:600, dataheight:400, top:50, left:50}, //edit options
{reloadAfterSubmit:true, width:600, dataheight:400, top:50, left:50}, //add options
{reloadAfterSubmit:true}, //del options
{} //search options
);
}//close success detail
});//close ajax detail
}//close if tables
}); //close document ready
</script>
</head>
<body>
<div id="wrap">
<div id="headwrap">
<?php include "php/inc/menu.inc.php" ?>
</div>
<br />
<table id="desc"></table>
<div id="desc_pager"></div>
<br />
<br />
<table id="detail" class="hideInPrint"></table>
<div id="detail_pager"></div>
<!--input type="button" id="editData" value="Edit Selected" /-->
<br />
</div>
</body>
</html>