-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmanage_data.php
248 lines (238 loc) · 8.97 KB
/
manage_data.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
<?php include "php/inc/header.inc.php" ?>
<?php
$table_name = get_param('table');
$data_manager = null;
if (check_manager_exist($table_name)) {
include_once(__ROOT__."php/ctrl/ManageData/{$table_name}.php");
$data_manager = new data_manager();
}
function check_manager_exist($table_name) {
if ($table_name && strpos($table_name, '/') === false && strpos($table_name, "\\") === false) {
return file_exists(__ROOT__."php/ctrl/ManageData/{$table_name}.php");
}
return false;
}
/**
* This function looks at the current_role to determine if the table
* currently requested may be edited by the user in the current role.
*/
function may_edit_table($data_table) {
$table_aux = strstr($data_table, '_');
$prefix = strstr($data_table, '_', true);
if ($prefix !== 'aixada') {
$table_aux = '_' . $prefix.$table_aux;
}
if (is_created_session()) {
$rights_of = get_config('rights_of');
$current_role = get_current_role();
if (in_array('may_edit' . $table_aux, $rights_of[$current_role])) {
return true;
}
}
return false;
}
$is_edit = 'false';
if ($data_manager){
if (may_edit_table($table_name)) {
$page_title = i18n('dataman_edit',
array('data'=>$data_manager->title()) );
$is_edit = 'true';
} else {
$page_title = i18n('dataman_consult',
array('data'=>$data_manager->title()) );
}
} else {
$page_title = '??';
}
?>
<!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
echo $Text['global_title'] . " - " . $page_title; ?>
</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>
<?php echo aixada_js_src(); ?>
<style>
.ui-state-highlight,
.ui-widget-content .ui-state-highlight,
.ui-widget-header .ui-state-highlight {
background-image: none;
background-color: #fbf9df;
}
#gbox_desc {
margin-left:auto; margin-right:auto
}
</style>
<!-- load js of table on docuement redy -->
<script><?php
echo ($data_manager ? $data_manager->callCreateEditorJs() : '');
?></script>
<script type="text/javascript">
function createEditor(allowed_edit_modes, col_models, col_sort) {
createEditor_aux(
"<?php echo $data_manager ? $table_name : '' ?>",
"<?php echo $data_manager ? to_js_str($page_title) : '???' ?>",
(<?php echo $is_edit ?> ?
allowed_edit_modes :
{edit:false,add:false,del:false}
),
col_models,
col_sort
);
}
</script>
<script type="text/javascript">
function createEditor_aux(current_table, page_title, edit_modes,
col_models, col_sort) {
$.ajaxSetup({ cache: false });
if (current_table === '') { return; }
var selected_row;
var lastsel = 0;
if (current_table == null || current_table == '') {
alert("variable table not set in query");
return;
}
var filter_text = '';
var filter_cond = $.getUrlVar('filter');
if (filter_cond.length>0) {
filter_text = "&filter=" + filter_cond;
}
var col_names = [],
col_sortIndex = 0,
col_sortName = (col_sort ? col_sort[0] : ''),
col_sortOrder = (col_sort ? col_sort[1] : 'asc');
if (col_models[col_sortIndex].name === 'id') {
col_sortIndex++;
}
for (var i=0, len=col_models.length; i < len; i++) {
var col_model = col_models[i],
col_name = col_model.name;
// name as default
col_model = $.extend({ // Apply values as default
xmlmap:col_name,
index: col_name,
label: col_name,
hidden: (col_model.width ? false : true),
editable: true
},
col_model
);
if (col_sortIndex === i && col_model.hidden && i < len) {
col_sortIndex++;
}
// editrules
col_model.editrules = $.extend({ // Apply values as default
edithidden:true, searchhidden:true
},
col_model.editrules ? col_model.editrules : {}
);
// add label to col_names
col_models[i] = col_model;
col_names.push(col_model.label);
}
if (col_sortName === '') {
col_sortName = (
col_models[col_sortIndex].index ?
col_models[col_sortIndex].index :
col_models[col_sortIndex].name
);
}
var last_row_sel = null;
$("#desc").jqGrid({
url: "php/ctrl/ManageData.php?table="+current_table+
"&oper=listAll"+filter_text,
datatype: 'xml',
colNames: col_names,
colModel: col_models,
onSelectRow: function(id) {
if (edit_modes.edit && id && id !== last_row_sel) {
if (last_row_sel !== null) {
jQuery('#desc').saveRow(last_row_sel);
// TODO: Do automatic refresh without breaking anything,
// one step could be (but missing something):
// jQuery("#desc").trigger("reloadGrid");
}
jQuery('#desc').editRow(id, true);
last_row_sel = id;
}
},
// loadonce: false, // Used with "reloadGrid", see previous TODO
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: col_sortName,
sortorder: col_sortOrder,
viewrecords: true,
multiselect: false,
editurl:"php/ctrl/ManageData.php?table="+current_table,
caption: page_title
}); // close jqgrid
$("#desc").navGrid('#desc_pager',
$.extend({}, {search:false}, edit_modes), // TODO: Allow search
{ //edit options
reloadAfterSubmit:true,
width: 600,
// dataheight:400,
top:50, left:50,
errorTextFormat: function(data) {
return data.statusText; // + ' ['+data.status+']';
}
}, { //add options
reloadAfterSubmit:true,
width: 600,
// dataheight:400,
top:50, left:50,
errorTextFormat: function(data) {
return data.statusText; // + ' ['+data.status+']';
}
}, { //del options
reloadAfterSubmit:true,
width: 500,
errorTextFormat: function(data) {
return data.statusText; // + ' ['+data.status+']';
}
}, { //search options
width:600, top:50, left:50
}
);
}
</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>