-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_entry_list.php
415 lines (351 loc) · 16.2 KB
/
common_entry_list.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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
<?php
require_once(__DIR__.'/source/main.php');
require_once(__DIR__.'/source/common_functions/common_security.php');
class class_filter_control
{
const _DATE_FORMAT = 'Y-m-d H:i:s';
private
$data_common = NULL,
$building = NULL,
$floor = NULL,
$time_obj = NULL,
$time_end = NULL,
$time_start = NULL;
public function __construct(\dc\chronofix\Chronofix $iChronofix)
{
$this->data_common = new \data\Common();
$this->time_obj = $iChronofix;
}
// Accessors
public function get_data_common()
{
return $this->data_common;
}
public function get_id()
{
return $this->data_common->get_id();
}
public function get_time_end()
{
return $this->time_end;
}
public function get_time_start()
{
return $this->time_start;
}
// Mutators
public function set_time_end($value)
{
// Run time through sanitizer to
// get a valid and uniform date/time.
$this->time_obj->set_time($value);
$this->time_obj->sanitize();
// Set member.
$this->time_end = $this->time_obj->get_time();
}
public function set_time_start($value)
{
// Run time through sanitizer to
// get a valid and uniform date/time.
$this->time_obj->set_time($value);
$this->time_obj->sanitize();
// Set member.
$this->time_start = $this->time_obj->get_time();
}
public function populate_from_request()
{
$this->data_common->populate_from_request();
}
}
// Get page configuration (title, description, query names, etc.)
$_page_config_config = new \dc\application\CommonEntry($yukon_connection);
$_page_config = new \dc\application\CommonEntryConfig($_page_config_config);
$_layout = $_page_config->create_config_object();
// Start page cache.
$page_obj = new \dc\cache\PageCache();
// Main navigaiton.
$obj_navigation_main = new class_navigation();
// Initialize time library with settings.
$iChronofix = new \dc\chronofix\Chronofix();
$filter_control = new class_filter_control($iChronofix);
$filter_control->populate_from_request();
// Establish sorting object, set defaults, and then get settings
// from user (if any).
$sorting = new \dc\sorting\SortControl;
$sorting->set_sort_field(2); // Label.
$sorting->set_sort_order(\dc\sorting\ORDER_TYPE::ASCENDING);
$sorting->populate_from_request();
// Set up navigaiton.
$navigation_obj = new class_navigation();
// Set up database.
$query = new \dc\yukon\Database($yukon_connection);
$paging = new \dc\recordnav\Paging();
$paging->set_row_max(APPLICATION_SETTINGS::PAGE_ROW_MAX);
// Record navigation.
$obj_navigation_rec = new \dc\recordnav\RecordNav();
$query->set_sql('{call '.$_layout->get_main_sql_name().'_list(@param_page_current = ?,
@param_page_rows = ?,
@param_sort_field = ?,
@param_sort_order = ?,
@param_date_start = ?,
@param_date_end = ?)}');
$params = array(array($paging->get_page_current(), SQLSRV_PARAM_IN),
array($paging->get_row_max(), SQLSRV_PARAM_IN),
array($sorting->get_sort_field(), SQLSRV_PARAM_IN),
array($sorting->get_sort_order(), SQLSRV_PARAM_IN),
array($filter_control->get_time_start(), SQLSRV_PARAM_IN),
array($filter_control->get_time_end(), SQLSRV_PARAM_IN));
// Debugging tools
//var_dump($params);
//exit;
$query->set_param_array($params);
$query->query_run();
$query->get_line_config()->set_class_name($_layout->get_main_object_name());
$_obj_data_main_list = $query->get_line_object_list();
// --Paging
$query->get_next_result();
$query->get_line_config()->set_class_name('\dc\recordnav\Paging');
//$_obj_data_paging = new \dc\recordnav\Paging();
if($query->get_row_exists()) $paging = $query->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();
}?> List</title>
<!-- CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<!--link rel="stylesheet" href="source/css/jquery.datetimepicker.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>
<script src="source/javascript/modernizr.js"></script>
<script src="source/javascript/iChronofix.js"></script>
</head>
<body>
<div id="container" class="container">
<?php echo $navigation_obj->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();
}?>
<p class="lead">This form allows you to view the complete <?php echo $_layout->get_title();?> list. Click any row to view details.</p>
</div>
<div class="panel panel-default" id="filter_container">
<div class="panel-heading" id="filter_header">
<h4 id="h41" class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" href="#collapse_module_1"><span class="glyphicon glyphicon-filter"></span><span class="glyphicon glyphicon-menu-down pull-right"></span> Filters</a>
</h4>
</div><!--#filter_header-->
<div style="" id="collapse_module_1" class="panel-collapse collapse" id="filter_collapse">
<div class="panel-body" id="filter_body">
<form class="form-horizontal" role="form" id="form_filter" method="get">
<input type="hidden" name="id_form" value="<?php echo $_layout->get_id(); ?>" />
<input type="hidden" name="id" value="<?php echo $filter_control->get_id(); ?>" />
<input type="hidden" name="field" value="<?php echo $sorting->get_sort_field(); ?>" />
<input type="hidden" name="order" value="<?php echo $sorting->get_sort_order(); ?>" />
<div class="form-group" id="group_filter_time">
<label class="control-label col-sm-2" for="filter_time_start">Time (from):</label>
<div class="col-sm-4">
<input
type ="datetime-local"
class ="form-control time_start_filter"
name ="time_start"
id ="time_start"
step ="1"
placeholder="yyyy-mm-dd hh:mm:ss"
value="<?php echo $filter_control->get_time_start(); ?>">
</div>
<label class="control-label col-sm-2" for="filter_time_end">Time (to):</label>
<div class="col-sm-4">
<input
name ="time_end"
type ="datetime-local"
class ="form-control time_end_filter"
id ="time_end"
step ="1"
placeholder="yyyy-mm-dd hh:mm:ss" autocomplete="on"
min="01"
value="<?php echo $filter_control->get_time_end(); ?>">
</div>
</div><!--#group_filter_time-->
<button
type ="submit"
class ="btn btn-primary btn-block"
name ="set_filter"
id ="set_filter"
title ="Apply selected filters to list."
><span class="glyphicon glyphicon-filter"></span>Apply Filters</button>
</form><!--#form_filter-->
</div><!--#filter_body-->
</div><!--#filter_collapse-->
</div><!--#filter_container-->
<?php
// Clickable rows. Clicking on table rows
// should take user to a detail page for the
// record in that row. To do this we first get
// the base name of this file, and remove "list".
//
// The detail file will always have same name
// without "list". Example: area.php, area_list.php
//
// Once we have the base name, we can use script to
// make table rows clickable by class selector
// and passing a completed URL (see the <tr> in
// data table we are making clickable).
//
// Just to ease in development, we verify the detail
// file exists before we actually include the script
// and build a complete URL string. That way if the
// detail file is not yet built, clicking on a table
// row does nothing at all instead of giving the end
// user an ugly 404 error.
//
// Lastly, if the base name exists we also build a
// "new item" button that takes user directly
// to detail page with a blank record.
$target_url = '#';
$target_name = basename(__FILE__, '_list.php').'.php';
$target_file = __DIR__.'/'.$target_name;
// Does the file exisit? If so we can
// use the URL, script, and new
// item button.
if(file_exists($target_file))
{
$target_url = $target_name.'?id_form='.$_layout->get_id();
?>
<script>
// Clickable table row.
jQuery(document).ready(function($) {
$(".clickable-row").click(function() {
window.document.location = '<?php echo $target_url; ?>&id=' + $(this).data("href");
});
});
</script>
<a href="<?php echo $target_url; ?>&nav_command=<?php echo \dc\recordnav\COMMANDS::NEW_BLANK;?>&id=<?php echo \dc\yukon\DEFAULTS::NEW_ID; ?>" class="btn btn-success btn-block" title="Click here to start entering a new item."><span class="glyphicon glyphicon-plus"></span> <?php echo $_layout->get_title(); ?></a>
<?php
}
?>
<!-- Top record paging controls -->
<br />
<?php echo $paging->generate_paging_markup(); ?>
<!--div class="table-responsive"-->
<table class="table table-striped table-hover">
<thead>
<tr>
<th><a href="<?php echo $sorting->sort_url(1); ?>">Revision <?php echo $sorting->sorting_markup(1); ?></a></th>
<th><a href="<?php echo $sorting->sort_url(2); ?>">Label <?php echo $sorting->sorting_markup(2); ?></a></th>
</tr>
</thead>
<tfoot>
<tr>
<th><a href="<?php echo $sorting->sort_url(1); ?>">Revision <?php echo $sorting->sorting_markup(1); ?></a></th>
<th><a href="<?php echo $sorting->sort_url(2); ?>">Label <?php echo $sorting->sorting_markup(2); ?></a></th
></tr>
</tfoot>
<tbody>
<?php
if(is_object($_obj_data_main_list) === TRUE)
{
for($_obj_data_main_list->rewind(); $_obj_data_main_list->valid(); $_obj_data_main_list->next())
{
$_obj_data_main = $_obj_data_main_list->current();
?>
<tr class="clickable-row" role="button" data-href="<?php echo $_obj_data_main->get_id(); ?>">
<td><?php if(is_object($_obj_data_main->get_create_time()) === TRUE) echo date(APPLICATION_SETTINGS::TIME_FORMAT, $_obj_data_main->get_create_time()->getTimestamp()); ?></td>
<td><?php echo $_obj_data_main->get_label(); ?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<?php
echo $paging->get_markup();
echo $navigation_obj->generate_markup_footer();
?>
</div><!--container-->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-40196994-1', 'uky.edu');
ga('send', 'pageview');
// Reload window when gaining focus.
var $blurred = false;
window.onblur = function() { $blurred = true; };
window.onfocus = function() { $blurred && (location.reload()); };
// Let's handle date and time entry.
// We want to use the jquery time picker,
// but only if the browser doesn't
// support a datetime-local type
// field. We'll use modernizr library
// to check for support and act accordingly.
// Get support status of datetime-local field.
$supported = Modernizr.inputtypes['datetime-local'];
var $format = 'Y-m-d h:m:s';
// If the datetime-local type is not supported,
// then we need to load the files needed for
// timepicker, and execute it.
if(!$supported){
include('source/javascript/jquery.datetimepicker.full.min.js', function(){
// Load css for the time picker.
if (document.createStyleSheet){
document.createStyleSheet('style.css');
}
else {
$('head').append($('<link rel="stylesheet" href="source/css/jquery.datetimepicker.min.css" type="text/css" media="screen" />'));
}
// Apply time picker to fields.
jQuery('.time_start_filter').datetimepicker({
validateOnBlur:true,
value:'<?php echo $filter_control->get_time_start(); ?>',
format:$format
});
jQuery('.time_end_filter').datetimepicker({
validateOnBlur:true,
value:'<?php echo $filter_control->get_time_end(); ?>',
format:$format
});
});
}
else
{
include('source/javascript/moment.js', function(){
$format = 'YYYY-MM-DDTHH:mm:ss';
// Datetime is supported, so just populate the fields.
jQuery('.time_start_filter').val(moment('<?php echo $filter_control->get_time_start(); ?>').format($format));
jQuery('.time_end_filter').val(moment('<?php echo $filter_control->get_time_end(); ?>').format($format));
});
}
// Conditonally load and fire script.
function include(script,callback){
$.getScript(script, function(){
if(typeof callback == 'function')
callback.apply({},arguments);
});
}
</script>
</body>
</html>
<?php
// Collect and output page markup.
echo $page_obj->markup_and_flush();
?>