forked from glllcarchive/widget_list
-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.php
executable file
·117 lines (98 loc) · 3.51 KB
/
page.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
<?php
$developmentMachine = (PHP_OS == "WINNT");
// -- first setup defaults
if (!isset($parms['render_full_page']))
{
$parms['render_full_page'] = true;
}
if ($parms['render_full_page'])
{
$template['page_wrapper'] = file_get_contents('index.tpl');
}
else
{
$template['page_wrapper'] = '<!--CONTENT-->';
}
// -- validate parameters else die() in windows - sorry matt
if (!is_array($parms) && $developmentMachine)
{
die("Pass \$parms variable with configuration for list view");
}
$requiredParameters = array('name','view','noDataMessage');
foreach ($requiredParameters as $req)
{
if (!array_key_exists($req,$parms) && $developmentMachine)
{
die("Please pass \$parms['".$req."']");
}
}
if (!array_key_exists('orderBy',$parms))
{
$parms['orderBy'] = '';
}
$SQL = "
SELECT
*
FROM
{$parms['view']}";
// -- always pass these common bind vars mixed with your bind vars
$bindVars = array('DELETED' => 0,
'YES' => '<div style=\'color:#1e7b17;\'>Yes</div>',
'NO' => '<div style=\'color:#b70a0a;\'>No</div>');
if (!empty($parms['bindVars']))
{
foreach ($parms['bindVars'] as $k=>$v)
{
$bindVars[$k] = $v;
}
}
$list = array(
'title' => $parms['title'],
'pageId' => (array_key_exists('pageId',$parms)) ? $parms['pageId'] : basename($_SERVER['PHP_SELF']),
'orderBy' => $parms['orderBy'],
'noDataMessage' => $parms['noDataMessage'],
'sql' => $SQL,
'bindVars' => $bindVars);
foreach ($parms as $miscItemKey=>$value)
{
if (!array_key_exists($miscItemKey,$list) && $miscItemKey != 'list_buttons')
{
$list[$miscItemKey] = $value;
}
}
if (array_key_exists('pk_column',$parms) && array_key_exists($parms['pk_column'],$_GET))
{
$list['filter'] = array("`{$parms['pk_column']}` = '{$_GET[$parms['pk_column']]}'");
}
$buttons = array_key_exists('list_buttons',$parms) ? $parms['list_buttons'] : '';
if (function_exists('page_overrides') && !array_key_exists('page_override_function',$parms))
{
page_overrides($list,$parms['name']);
}
elseif (array_key_exists('page_override_function',$parms) && function_exists($parms['page_override_function']))
{
$parms['page_override_function']($list,$parms['name']);
}
// -- Display the Notifications page or AJAX JSON
if(array_key_exists('BUTTON_VALUE', $_GET) && ! empty($_GET['BUTTON_VALUE']) && $_GET['LIST_NAME'] == $parms['name'])
{
$templateList = new WidgetList( (!empty($_GET['LIST_NAME'])) ? $_GET['LIST_NAME'] : $parms['name'] , $list );
// -- Only fall into here when the list is equal to the list name of the page (just in case two lists use page.php)
$return['list'] = str_replace(array('<!--CUSTOM_CONTENT-->'), array($buttons), $templateList->Render());
$return['list_id'] = (!empty($_GET['LIST_NAME'])) ? $_GET['LIST_NAME'] : $parms['name'];
$return['callback'] = 'ListSearchAheadResponse';
JsonEncode($return);
exit;
}
elseif (!array_key_exists('BUTTON_VALUE', $_GET))
{
$templateList = new WidgetList( (!empty($_GET['LIST_NAME'])) ? $_GET['LIST_NAME'] : $parms['name'] , $list );
$pagePieces = array(
'<!--CONTENT-->' => $templateList->Render(),
'<!--CUSTOM_CONTENT-->' => $buttons
);
$pageHTML = Fill($pagePieces, $template['page_wrapper']);
}
// -- clear out parms if used in another list view on the page
$parms = array();
?>