-
Notifications
You must be signed in to change notification settings - Fork 0
/
audit_type.php
341 lines (277 loc) · 12.3 KB
/
audit_type.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<?php
require(__DIR__.'/source/main.php');
require(__DIR__.'/source/common_functions/common_security.php');
$_page_config_config = new \dc\application\CommonEntry($yukon_connection);
$_page_config = new \dc\application\CommonEntryConfig($_page_config_config);
$_layout = $_page_config->create_config_object();
// common_list
// Caskey, Damon V.
// 2017-02-22
//
// Switch to list mode for a record. Verifies the list
// mode file exists first.
function action_list($_layout = NULL)
{
// Final result, and the target forwarding destination.
$result = '#';
// First thing we need is the self path.
$file = filter_input(INPUT_SERVER, 'PHP_SELF', FILTER_SANITIZE_URL);
// List giles are the name of a single record file
// with _list added on, so all we need to do is
// remove the file suffix, and add '_list.php' to
// get the list file's name. This is also all we
// need for forwarding purposes.
$target_name = basename($file, '.php').'_list.php';
// To verify the list file exists, we have to target the
// file system path. We can combine the document root
// and self's directory to get it.
$root = filter_input(INPUT_SERVER, 'DOCUMENT_ROOT', FILTER_SANITIZE_URL);
$directory = dirname($file);
//$target_file = $root.$directory.'/'.$target_name;
$target_file = $root.$directory.'/';
// Does the list file exisit? If so we can
// redirect to it. Otherwise, do nothing.
if(file_exists($target_file))
{
// Set target url.
$result = $target_name;
// Direct to listing.
header('Location: '.$result.'?id_form='.$_layout->get_id());
}
// Return final result.
return $result;
}
// Save this record.
function action_save($_layout = NULL, $database)
{
// Set up account info.
$access_obj = new \dc\stoeckl\status();
// Initialize main data class and populate it from
// post variables.
$_main_data = new \data\AuditType();
$_main_data->populate_from_request();
// Call update stored procedure.
$database->set_sql('{call '.$_layout->get_main_sql_name().'_update(@id = ?,
@log_update_by = ?,
@log_update_ip = ?,
@label = ?,
@details = ?,
@sort_order = ?)}');
$params = array(array('<root><row id="'.$_main_data->get_id().'"/></root>', SQLSRV_PARAM_IN),
array($access_obj->get_id(), SQLSRV_PARAM_IN),
array($access_obj->get_ip(), SQLSRV_PARAM_IN),
array($_main_data->get_label(), SQLSRV_PARAM_IN),
array($_main_data->get_details(), SQLSRV_PARAM_IN),
array($_main_data->get_sort_order(), SQLSRV_PARAM_IN));
$database->set_param_array($params);
$database->query_run();
// Repopulate main data object with results from merge query.
// We can use common data here because all we need
// is the ID for redirection.
$database->get_line_config()->set_class_name($_layout->get_main_object_name());
$_main_data = $database->get_line_object();
// Now that save operation has completed, reload page using ID from
// database. This ensures the ID is always up to date, even with a new
// or copied record.
header('Location: '.$_SERVER['PHP_SELF'].'?id_form='.$_layout->get_id().'&id='.$_main_data->get_id());
}
function action_delete($_layout = NULL, $database)
{
// Set up account info.
$access_obj = new \dc\stoeckl\status();
// Initialize main data class and populate it from
// post variables.
$_main_data = new \data\Area();
$_main_data->populate_from_request();
// Call update stored procedure.
$database->set_sql('{call master_delete(@param_id = ?,
@param_update_by = ?,
@param_update_ip = ?)}');
$params = array(array($_main_data->get_id(), SQLSRV_PARAM_IN),
array($access_obj->get_id(), SQLSRV_PARAM_IN),
array($access_obj->get_ip(), SQLSRV_PARAM_IN));
$database->set_param_array($params);
$database->query_run();
// Repopulate main data object with results from merge query.
// We can use common data here because all we need
// is the ID for redirection.
$database->get_line_config()->set_class_name($_layout->get_main_object_name());
$_main_data = $database->get_line_object();
// Now that save operation has completed, reload page using ID from
// database. This ensures the ID is always up to date, even with a new
// or copied record.
header('Location: '.$_SERVER['PHP_SELF'].'?id_form='.$_layout->get_id());
}
///////////////
// Verify user access.
common_security($yukon_database);
// Start page cache.
$page_obj = new \dc\cache\PageCache();
// Main navigaiton.
$obj_navigation_main = new class_navigation();
// Record navigation - also gets user record action requests.
$obj_navigation_rec = new \dc\recordnav\RecordNav();
// Apply user action request (if any). Depending on the
// action, the page may be reloaded with the same or
// another ID.
switch($obj_navigation_rec->get_action())
{
default:
case \dc\recordnav\COMMANDS::NEW_BLANK:
break;
case \dc\recordnav\COMMANDS::LISTING:
action_list($_layout);
break;
case \dc\recordnav\COMMANDS::DELETE:
action_delete($_layout, $yukon_database);
break;
case \dc\recordnav\COMMANDS::SAVE:
action_save($_layout, $yukon_database);
break;
}
// Class name has to be populated into local var to
// be instantiated.
$main_data_class_name = $_layout->get_main_object_name();
// Initialize a blank main data object.
$_main_data = new $main_data_class_name();
// Populate from request so that we have an
// ID and KEY ID (if nessesary) to work with.
$_main_data->populate_from_request();
// Set up primary query with parameters and arguments.
$yukon_database->set_sql('{call '.$_layout->get_main_sql_name().'(@param_filter_id = ?,
@param_filter_id_key = ?)}');
$params = array(array($_main_data->get_id(), SQLSRV_PARAM_IN),
array($_main_data->get_id_key(), SQLSRV_PARAM_IN));
// Apply arguments and execute query.
$yukon_database->set_param_array($params);
$yukon_database->query_run();
// Get navigation record set and populate navigation object.
$yukon_database->get_line_config()->set_class_name('\dc\recordnav\RecordNav');
if($yukon_database->get_row_exists() === TRUE) $obj_navigation_rec = $yukon_database->get_line_object();
// Get primary data record set.
$yukon_database->get_next_result();
$yukon_database->get_line_config()->set_class_name($_layout->get_main_object_name());
if($yukon_database->get_row_exists() === TRUE) $_main_data = $yukon_database->get_line_object();
?>
<!DOCtype html>
<html lang="en">
<head>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1" />
<title><?php echo APPLICATION_SETTINGS::NAME;
// Add page title, if any.
if($_layout->get_title())
{
echo ', '.$_layout->get_title();
}?></title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="source/css/style.css" />
<link rel="stylesheet" href="source/css/print.css" media="print" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<!-- WYSIWYG Text boxes -->
<script type="text/javascript" src="source/javascript/tinymce/tinymce.min.js"></script>
<script type="text/javascript" src="source/javascript/tinymce/settings.js"></script>
</head>
<body>
<div id="container" class="container">
<?php echo $obj_navigation_main->generate_markup_nav(); ?>
<div class="page-header">
<h1><?php
// Add page title, if any.
if($_layout->get_title())
{
echo $_layout->get_title();
}?></h1>
<?php
// Add page description, if any.
if($_layout->get_description())
{
echo $_layout->get_description();
}?>
<?php
// If this isn't the active version, better alert user.
if(!$_main_data->get_active() && $_main_data->get_id_key())
{
?>
<div class="alert alert-warning">
<strong>Notice:</strong> You are currently viewing an inactive revision of this record. Saving will make this the active revision. To return to the currently active revision without saving, click <a href="<?php echo $_SERVER['PHP_SELF'].'?id_form='.$_layout->get_id().'&id='.$_main_data->get_id(); ?>">here</a>.
</div>
<?php
}
?>
</div>
<form class="form-horizontal" role="form" method="post" enctype="multipart/form-data">
<?php echo $obj_navigation_rec->generate_button_list(); ?>
<hr />
<?php require(__DIR__.'/source/common_includes/details_field.php'); ?>
<div class="form-group">
<label class="control-label col-sm-2" for="revision">Revision</label>
<div class="col-sm-10">
<p class="form-control-static">
<?php if(is_object($_main_data->get_create_time()))
{
?>
<a id="revision" href = "common_version_list.php?id_form=<?php echo $_layout->get_id(); ?>&id=<?php echo $_main_data->get_id(); ?>"
data-toggle = ""
title = "View log for this record."
target = "_new"
><?php echo date(APPLICATION_SETTINGS::TIME_FORMAT, $_main_data->get_create_time()->getTimestamp()); ?></a>
<?php
}
else
{
?>
<span class="alert-success">New Record. Fill out form and save to create first revision.</span>
<?php
}
?>
</p>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="label">Label</label>
<div class="col-sm-10">
<input
type ="text"
class ="form-control"
name ="label"
id ="label"
placeholder="Label or name for item."
value="<?php echo trim($_main_data->get_label()); ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="order">Order</label>
<div class="col-sm-10">
<input
type ="number"
class ="form-control"
name ="sort_order"
id ="sort_order"
min ="1"
max ="<?php //echo $main_count; ?>"
step ="1"
value="<?php echo trim($_main_data->get_sort_order()); ?>">
</div>
</div>
<hr />
<div class="form-group">
<div class="col-sm-12">
<?php echo $obj_navigation_rec->get_markup_cmd_save_block(); ?>
</div>
</div>
</form>
<?php echo $obj_navigation_main->generate_markup_footer(); ?>
</div><!--container-->
<script src="source/javascript/verify_save.js"></script>
<script>
//Google Analytics Here//
$(document).ready(function(){
});
</script>
</body>
</html>
<?php
// Collect and output page markup.
echo $page_obj->markup_and_flush();
?>