This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
pnuser.php
executable file
·272 lines (221 loc) · 10.5 KB
/
pnuser.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
<?php
/**
* locations
*
* @copyright (c) 2008,2010, Locations Development Team
* @link http://code.zikula.org/locations
* @author Steffen Voß
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @package locations
*/
/**
* Even though we're handling objects for multiple tables, we only have one function for any use case.
* The specific functionality for each object is encapsulated in the actual class implementation within the
* module's classes directory while the handling code can remain identical for any number of entities.
* This component-based approach allows you to have generic handler code which relies on the functionality
* implemented in the object's class in order to achieve it's goals.
*/
// preload common used classes
Loader::requireOnce('modules/locations/common.php');
// include pnForm in order to be able to inherit from pnFormHandler
Loader::requireOnce('includes/pnForm.php');
/**
* This function is the default function, and is called whenever the
* module's User area is called without defining arguments.
*
* @author Steffen Voß
* @params TODO
* @return Render output
*/
function locations_user_main($args)
{
if (!SecurityUtil::checkPermission('locations::', '::', ACCESS_OVERVIEW)) {
return LogUtil::registerPermissionError();
}
// call view method
return locations_user_view();
}
/**
* This function provides a generic item list overview.
*
* @author Steffen Voß
* @params TODO
* @param ot string treated object type
* @param sort string sorting field
* @param sdir string sorting direction
* @param pos int current pager position
* @param tpl string name of alternative template (for alternative display options, feeds and xml output)
* @param raw boolean optional way to display a template instead of fetching it (needed for standalone output)
* @return Render output
*/
function locations_user_view($args)
{
if (!SecurityUtil::checkPermission('locations::', '::', ACCESS_READ)) {
return LogUtil::registerPermissionError();
}
$dom = ZLanguage::getModuleDomain('locations');
// parameter specifying which type of objects we are treating
$objectType = FormUtil::getPassedValue('ot', 'location', 'GET');
if (!in_array($objectType, locations_getObjectTypes())) {
$objectType = 'location';
}
// load the object array class corresponding to $objectType
if (!($class = Loader::loadArrayClassFromModule('locations', $objectType))) {
pn_exit(__f('Error! Unable to load class [%s].', $objectType, $dom));
}
// instantiate the object-array
$objectArray = new $class();
if (pnModGetVar('locations', 'enablecategorization')) {
$category = FormUtil :: getPassedValue('cat', null);
if (!($categoryclass = Loader::loadClass('CategoryUtil'))) {
pn_exit (__f('Error! Unable to load class [%s].', 'CategoryUtil', $dom));
}
if (!($categoryclass = Loader::loadClass('CategoryRegistryUtil'))) {
pn_exit (__f('Error! Unable to load class [%s].', 'CategoryRegistryUtil', $dom));
}
$categories = CategoryRegistryUtil::getRegisteredModuleCategory('locations', 'locations_location', 'Type', '/__SYSTEM__/Modules/locations');
if ($category > 0) {
if (!is_array($objectArray->_objCategoryFilter)) {
$objectArray->_objCategoryFilter = array();
}
$categoryWithSubIDs = array($category);
$subCats = CategoryUtil::getSubCategories($category);
foreach($subCats as $subCat) {
$categoryWithSubIDs[] = $subCat['id'];
}
$objectArray->_objCategoryFilter['Type'] = $categoryWithSubIDs;
}
}
// parameter for used sorting field
$sort = FormUtil::getPassedValue('sort', '', 'GET');
if (empty($sort) || !in_array($sort, $objectArray->getAllowedSortingFields())) {
$sort = $objectArray->getDefaultSortingField();
}
// parameter for used sort order
$sdir = FormUtil::getPassedValue('sdir', '', 'GET');
if ($sdir != 'asc' && $sdir != 'desc') $sdir = 'asc';
// startnum is the current offset which is used to calculate the pagination
$startnum = (int) FormUtil::getPassedValue('pos', 1, 'GET');
// pagesize is the number of items displayed on a page for pagination
$pagesize = pnModGetVar('locations', 'pagesize', 25);
// convenience vars to make code clearer
$where = '';
$sortParam = $sort . ' ' . $sdir;
// use locationsFilterUtil to support generic filtering based on an object-oriented approach
Loader::LoadClass('locationsFilterUtil', 'modules/locations/classes/FilterUtil/');
$fu =& new locationsFilterUtil(array('table' => $objectArray->_objType));
// you could set explicit filters at this point, something like
// $fu->setFilter('type:eq:' . $args['type'] . ',id:eq:' . $args['id']);
// supported operators: eq, ne, like, lt, le, gt, ge, null, notnull
// process request input filters and get result for DBUtil
$ret = $fu->GetSQL();
$where = $ret['where'];
// get() returns the cached object fetched from the DB during object instantiation
// get() with parameters always performs a new select
// while the result will be saved in the object, we assign in to a local variable for convenience.
$objectData = $objectArray->get($where, $sortParam, $startnum-1, $pagesize);
// get total number of records for building the pagination by method call
$objcount = $objectArray->getCount($where);
// get pnRender instance for this module
$render = pnRender::getInstance('locations', false);
$render->assign('modvar', pnModGetVar('locations'));
$render->assign('categories', $categories);
$render->assign('selectedCat', $category);
// assign current sorting information
$render->assign('sort', $sort);
$render->assign('sdir', ($sdir == 'asc') ? 'desc' : 'asc'); // reverted for links
// assign the information required to create the pager
$render->assign('pager', array('numitems' => $objcount,
'itemsperpage' => $pagesize));
// assign Google Maps Key to template
$render->assign('GoogleMapsAPIKey', pnModGetVar('locations', 'GoogleMapsAPIKey'));
$tpl = FormUtil::getPassedValue('tpl', isset($args['tpl']) ? $args['tpl'] : '');
if ($tpl == 'xml' || $tpl == 'kml') {
foreach ($objectData as $k => $obj) {
$objectData[$k]['latlng'] = pnModAPIFunc('locations', 'user', 'swapLatLng', array('latlng' => $obj['latlng']));
}
if ($tpl == 'kml') {
header("Content-type: application/vnd.google-earth.kml+xml");
header("Content-Disposition: attachment; filename=location".$objectData[$k]['locationid'].".kml");
}
$args['raw'] = true;
}
// assign the object-array we loaded above
$render->assign('objectArray', $objectData);
// fetch and return the appropriate template
return locations_processRenderTemplate($render, 'user', $objectType, 'view', $args);
}
/**
* This function provides a generic item detail view.
*
* @author Steffen Voß
* @params TODO
* @param ot string treated object type
* @param tpl string name of alternative template (for alternative display options, feeds and xml output)
* @param raw boolean optional way to display a template instead of fetching it (needed for standalone output)
* @return Render output
*/
function locations_user_display($args)
{
if (!SecurityUtil::checkPermission('locations::', '::', ACCESS_READ)) {
return LogUtil::registerPermissionError();
}
$dom = ZLanguage::getModuleDomain('locations');
// parameter specifying which type of objects we are treating
$objectType = FormUtil::getPassedValue('ot', 'location', 'GET');
if (!in_array($objectType, locations_getObjectTypes())) {
$objectType = 'location';
}
// load the object class corresponding to $objectType
if (!($class = Loader::loadClassFromModule('locations', $objectType))) {
pn_exit(__f('Error! Unable to load class [%s].', $objectType, $dom));
}
// intantiate object model
$object = new $class();
$idField = $object->getIDField();
// retrieve the ID of the object we wish to view
$id = (int) FormUtil::getPassedValue($idField, isset($args[$idField]) && is_numeric($args[$idField]) ? $args[$idField] : 0, 'GET');
if (!$id) {
pn_exit('Error! Invalid Id received.', $dom);
}
// assign object data
// this performs a new database select operation
// while the result will be saved within the object, we assign it to a local variable for convenience
$objectData = $object->get($id, $idField);
if (!is_array($objectData) || !isset($objectData[$idField]) || !is_numeric($objectData[$idField])) {
return LogUtil::registerError(__('Error! No such location found.', $dom));
}
// get pnRender instance for this module
$render = pnRender::getInstance('locations', false);
$render->assign('modvar', pnModGetVar('locations'));
$render->assign('lang', ZLanguage::getLanguageCode());
// assign the object we loaded above.
// since the same code is used the handle the entry of the new object,
// we need to check wether we have a valid object.
// If not, we just pass in an empty data-array.
$render->assign($objectType, $objectData);
// assign Google Maps Key to template
$render->assign('GoogleMapsAPIKey', pnModGetVar('locations', 'GoogleMapsAPIKey'));
// fetch and return the appropriate template
if ($args['type'] =='short') {
return $render->fetch('locations_user_' . $objectType . '_short_display.htm');
} else {
return locations_processRenderTemplate($render, 'user', $objectType, 'display', $args);
}
}
/**
* This function does...
*
* @author Steffen Voß
* @return Render output
* FIXME
*/
function locations_user_getLocationsWithinDistanceOfZIP($args)
{
if (!SecurityUtil::checkPermission('locations::', '::', ACCESS_READ)) {
return LogUtil::registerPermissionError();
}
$render = FormUtil::newpnForm('locations');
Loader::requireOnce('modules/locations/classes/FormHandler/locations_user_getLocationsWithinDistanceOfZIPHandler.php');
return $render->pnFormExecute('locations_user_getLocationsWithinDistanceOfZIP.htm', new locations_user_getLocationsWithinDistanceOfZIPHandler());
}