@@ -5,9 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | * @license GNU |
7 | 7 | * @author marcan <[email protected]> |
8 | - |
|
9 | 8 | * @version $Id: smartobjecttable.php 2067 2008-05-08 16:12:18Z fx2024 $ |
10 | - |
|
11 | 9 | * @link http://smartfactory.ca The SmartFactory |
12 | 10 | * @package SmartObject |
13 | 11 | * @subpackage SmartObjectTable |
@@ -24,48 +22,48 @@ discard block |
||
24 | 22 | */ |
25 | 23 | class SmartObjectColumn { |
26 | 24 | |
27 | - var $_keyname; |
|
28 | - var $_align; |
|
29 | - var $_width; |
|
30 | - var $_customMethodForValue; |
|
31 | - var $_extraParams; |
|
32 | - var $_sortable; |
|
33 | - var $_customCaption; |
|
34 | - |
|
35 | - function SmartObjectColumn($keyname, $align='left', $width=false, $customMethodForValue=false, $param = false, $customCaption = false, $sortable = true) { |
|
36 | - $this->_keyname = $keyname; |
|
37 | - $this->_align = $align; |
|
38 | - $this->_width = $width; |
|
39 | - $this->_customMethodForValue = $customMethodForValue; |
|
40 | - $this->_sortable = $sortable; |
|
41 | - $this->_param = $param; |
|
42 | - $this->_customCaption = $customCaption; |
|
43 | - } |
|
44 | - |
|
45 | - function getKeyName() { |
|
46 | - return $this->_keyname; |
|
47 | - } |
|
48 | - |
|
49 | - function getAlign() { |
|
50 | - return $this->_align; |
|
51 | - } |
|
52 | - |
|
53 | - function isSortable() { |
|
54 | - return $this->_sortable; |
|
55 | - } |
|
56 | - |
|
57 | - function getWidth() { |
|
58 | - if ($this->_width) { |
|
59 | - $ret = $this->_width; |
|
60 | - } else { |
|
61 | - $ret = ''; |
|
62 | - } |
|
63 | - return $ret; |
|
64 | - } |
|
65 | - |
|
66 | - function getCustomCaption() { |
|
67 | - return $this->_customCaption; |
|
68 | - } |
|
25 | + var $_keyname; |
|
26 | + var $_align; |
|
27 | + var $_width; |
|
28 | + var $_customMethodForValue; |
|
29 | + var $_extraParams; |
|
30 | + var $_sortable; |
|
31 | + var $_customCaption; |
|
32 | + |
|
33 | + function SmartObjectColumn($keyname, $align='left', $width=false, $customMethodForValue=false, $param = false, $customCaption = false, $sortable = true) { |
|
34 | + $this->_keyname = $keyname; |
|
35 | + $this->_align = $align; |
|
36 | + $this->_width = $width; |
|
37 | + $this->_customMethodForValue = $customMethodForValue; |
|
38 | + $this->_sortable = $sortable; |
|
39 | + $this->_param = $param; |
|
40 | + $this->_customCaption = $customCaption; |
|
41 | + } |
|
42 | + |
|
43 | + function getKeyName() { |
|
44 | + return $this->_keyname; |
|
45 | + } |
|
46 | + |
|
47 | + function getAlign() { |
|
48 | + return $this->_align; |
|
49 | + } |
|
50 | + |
|
51 | + function isSortable() { |
|
52 | + return $this->_sortable; |
|
53 | + } |
|
54 | + |
|
55 | + function getWidth() { |
|
56 | + if ($this->_width) { |
|
57 | + $ret = $this->_width; |
|
58 | + } else { |
|
59 | + $ret = ''; |
|
60 | + } |
|
61 | + return $ret; |
|
62 | + } |
|
63 | + |
|
64 | + function getCustomCaption() { |
|
65 | + return $this->_customCaption; |
|
66 | + } |
|
69 | 67 | |
70 | 68 | } |
71 | 69 | |
@@ -80,639 +78,639 @@ discard block |
||
80 | 78 | */ |
81 | 79 | class SmartObjectTable { |
82 | 80 | |
83 | - var $_id; |
|
84 | - var $_objectHandler; |
|
85 | - var $_columns; |
|
86 | - var $_criteria; |
|
87 | - var $_actions; |
|
88 | - var $_objects=false; |
|
89 | - var $_aObjects; |
|
90 | - var $_custom_actions; |
|
91 | - var $_sortsel; |
|
92 | - var $_ordersel; |
|
93 | - var $_limitsel; |
|
94 | - var $_filtersel; |
|
95 | - var $_filterseloptions; |
|
96 | - var $_filtersel2; |
|
97 | - var $_filtersel2options; |
|
98 | - var $_filtersel2optionsDefault; |
|
99 | - |
|
100 | - var $_tempObject; |
|
101 | - var $_tpl; |
|
102 | - var $_introButtons; |
|
103 | - var $_quickSearch=false; |
|
104 | - var $_actionButtons=false; |
|
105 | - var $_head_css_class='bg3'; |
|
106 | - var $_hasActions=false; |
|
107 | - var $_userSide=false; |
|
108 | - var $_printerFriendlyPage=false; |
|
109 | - var $_tableHeader=false; |
|
110 | - var $_tableFooter=false; |
|
111 | - var $_showActionsColumnTitle = true; |
|
112 | - var $_isTree = false; |
|
113 | - var $_showFilterAndLimit = true; |
|
114 | - var $_enableColumnsSorting = true; |
|
115 | - var $_customTemplate = false; |
|
116 | - var $_withSelectedActions = array(); |
|
117 | - |
|
118 | - /** |
|
119 | - * Constructor |
|
120 | - * |
|
121 | - * @param object $objectHandler {@link SmartPersistableObjectHandler} |
|
122 | - * @param array $columns array representing the columns to display in the table |
|
123 | - * @param object $criteria |
|
124 | - * @param array $actions array representing the actions to offer |
|
125 | - * |
|
126 | - * @return array |
|
127 | - */ |
|
128 | - function SmartObjectTable(&$objectHandler, $criteria=false, $actions=array('edit', 'delete'), $userSide=false) |
|
129 | - { |
|
130 | - $this->_id = $objectHandler->className; |
|
131 | - $this->_objectHandler = $objectHandler; |
|
132 | - |
|
133 | - if (!$criteria) { |
|
134 | - $criteria = new CriteriaCompo(); |
|
135 | - } |
|
136 | - $this->_criteria = $criteria; |
|
137 | - $this->_actions = $actions; |
|
138 | - $this->_custom_actions = array(); |
|
139 | - $this->_userSide = $userSide; |
|
140 | - if ($userSide) { |
|
141 | - $this->_head_css_class = 'head'; |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - function addActionButton($op, $caption=false, $text=false) { |
|
146 | - $action = array( |
|
147 | - 'op' => $op, |
|
148 | - 'caption' => $caption, |
|
149 | - 'text' => $text |
|
150 | - ); |
|
151 | - $this->_actionButtons[] = $action; |
|
152 | - } |
|
153 | - |
|
154 | - function addColumn($columnObj) { |
|
155 | - $this->_columns[] = $columnObj; |
|
156 | - } |
|
157 | - |
|
158 | - function addIntroButton($name, $location, $value) { |
|
159 | - $introButton = array(); |
|
160 | - $introButton['name'] = $name; |
|
161 | - $introButton['location'] = $location; |
|
162 | - $introButton['value'] = $value; |
|
163 | - $this->_introButtons[] = $introButton; |
|
164 | - unset($introButton); |
|
165 | - } |
|
166 | - |
|
167 | - function addPrinterFriendlyLink() { |
|
168 | - $current_urls = smart_getCurrentUrls(); |
|
169 | - $current_url = $current_urls['full']; |
|
170 | - $this->_printerFriendlyPage = $current_url . '&print'; |
|
171 | - } |
|
172 | - |
|
173 | - function addQuickSearch($fields, $caption=_CO_SOBJECT_QUICK_SEARCH) { |
|
174 | - $this->_quickSearch = array('fields' => $fields, 'caption' => $caption); |
|
175 | - } |
|
176 | - |
|
177 | - function addHeader($content) { |
|
178 | - $this->_tableHeader = $content; |
|
179 | - } |
|
180 | - |
|
181 | - function addFooter($content) { |
|
182 | - $this->_tableFooter = $content; |
|
183 | - } |
|
184 | - |
|
185 | - function addDefaultIntroButton($caption) { |
|
186 | - $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . "?op=mod", $caption); |
|
187 | - } |
|
188 | - |
|
189 | - function addCustomAction($method) { |
|
190 | - $this->_custom_actions[] = $method; |
|
191 | - } |
|
192 | - |
|
193 | - function setDefaultSort($default_sort) { |
|
194 | - $this->_sortsel = $default_sort; |
|
195 | - } |
|
196 | - |
|
197 | - function getDefaultSort() { |
|
198 | - if ($this->_sortsel) { |
|
199 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
200 | - } else { |
|
201 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
202 | - } |
|
203 | - } |
|
204 | - |
|
205 | - function setDefaultOrder($default_order) { |
|
206 | - $this->_ordersel = $default_order; |
|
207 | - } |
|
208 | - |
|
209 | - function getDefaultOrder() { |
|
210 | - if ($this->_ordersel) { |
|
211 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
212 | - } else { |
|
213 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
214 | - } |
|
215 | - } |
|
216 | - function addWithSelectedActions($actions = array()){ |
|
217 | - $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
218 | - $this->_withSelectedActions = $actions; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Adding a filter in the table |
|
223 | - * |
|
224 | - * @param string $key key to the field that will be used for sorting |
|
225 | - * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
226 | - */ |
|
227 | - function addFilter($key, $method, $default=false) { |
|
228 | - $this->_filterseloptions[$key] = $method; |
|
229 | - $this->_filtersel2optionsDefault = $default; |
|
230 | - } |
|
231 | - |
|
232 | - function setDefaultFilter($default_filter) { |
|
233 | - $this->_filtersel = $default_filter; |
|
234 | - } |
|
235 | - |
|
236 | - function isForUserSide() { |
|
237 | - $this->_userSide = true; |
|
238 | - } |
|
239 | - function setCustomTemplate($template) { |
|
240 | - $this->_customTemplate = $template; |
|
241 | - } |
|
242 | - function setSortOrder() { |
|
243 | - $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
244 | - //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel'] : $this->_sortsel; |
|
245 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
246 | - $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
247 | - |
|
248 | - if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
249 | - $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . "." . $this->_sortsel); |
|
250 | - } else { |
|
251 | - |
|
252 | - $this->_criteria->setSort($this->_objectHandler->_itemname . "." . $this->_sortsel); |
|
253 | - } |
|
254 | - |
|
255 | - $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
256 | - //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel'] :$this->_ordersel; |
|
257 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
258 | - $ordersArray = $this->getOrdersArray(); |
|
259 | - $this->_criteria->setOrder($this->_ordersel); |
|
260 | - } |
|
261 | - |
|
262 | - function setTableId($id) { |
|
263 | - $this->_id = $id; |
|
264 | - } |
|
265 | - |
|
266 | - function setObjects($objects) { |
|
267 | - $this->_objects = $objects; |
|
268 | - } |
|
269 | - |
|
270 | - function createTableRows() { |
|
271 | - $this->_aObjects = array(); |
|
272 | - |
|
273 | - $doWeHaveActions = false; |
|
274 | - |
|
275 | - $objectclass = 'odd'; |
|
276 | - if (count($this->_objects) > 0) { |
|
277 | - foreach ($this->_objects as $object) { |
|
278 | - |
|
279 | - $aObject = array(); |
|
280 | - |
|
281 | - $i=0; |
|
282 | - |
|
283 | - $aColumns = array(); |
|
284 | - |
|
285 | - foreach ($this->_columns as $column) { |
|
286 | - |
|
287 | - $aColumn = array(); |
|
288 | - |
|
289 | - if ($i==0) { |
|
290 | - $class = "head"; |
|
291 | - } elseif ($i % 2 == 0) { |
|
292 | - $class = "even"; |
|
293 | - } else { |
|
294 | - $class = "odd"; |
|
295 | - } |
|
296 | - if(method_exists($object, 'initiateCustomFields')){ |
|
297 | - //$object->initiateCustomFields(); |
|
298 | - } |
|
299 | - if($column->_keyname == 'checked'){ |
|
300 | - $value = '<input type ="checkbox" name="selected_smartobjects[]" value="'.$object->id().'" />'; |
|
301 | - }elseif ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
302 | - $method = $column->_customMethodForValue; |
|
303 | - if($column->_param){ |
|
304 | - $value = $object->$method($column->_param); |
|
305 | - }else{ |
|
306 | - $value = $object->$method(); |
|
307 | - } |
|
308 | - } else { |
|
309 | - /** |
|
310 | - * If the column is the identifier, then put a link on it |
|
311 | - */ |
|
312 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
313 | - $value = $object->getItemLink(); |
|
314 | - } else { |
|
315 | - $value = $object->getVar($column->getKeyName()); |
|
316 | - } |
|
317 | - } |
|
318 | - |
|
319 | - $aColumn['value'] = $value; |
|
320 | - $aColumn['class'] = $class; |
|
321 | - $aColumn['width'] = $column->getWidth(); |
|
322 | - $aColumn['align'] = $column->getAlign(); |
|
323 | - |
|
324 | - $aColumns[] = $aColumn; |
|
325 | - $i++; |
|
326 | - } |
|
327 | - |
|
328 | - $aObject['columns'] = $aColumns; |
|
329 | - $aObject['id'] = $object->id(); |
|
330 | - |
|
331 | - $objectclass = ($objectclass == 'even') ? 'odd' : 'even'; |
|
332 | - |
|
333 | - $aObject['class'] = $objectclass; |
|
334 | - |
|
335 | - $actions = array(); |
|
336 | - |
|
337 | - // Adding the custom actions if any |
|
338 | - foreach ($this->_custom_actions as $action) { |
|
339 | - if (method_exists($object, $action)) { |
|
340 | - $actions[] = $object->$action(); |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - include_once SMARTOBJECT_ROOT_PATH . "class/smartobjectcontroller.php"; |
|
345 | - $controller = new SmartObjectController($this->_objectHandler); |
|
346 | - |
|
347 | - if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
348 | - $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
349 | - } |
|
350 | - if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
351 | - $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
352 | - } |
|
353 | - $aObject['actions'] = $actions; |
|
354 | - |
|
355 | - $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
356 | - |
|
357 | - $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
358 | - |
|
359 | - $this->_aObjects[] = $aObject; |
|
360 | - } |
|
361 | - $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
362 | - } else { |
|
363 | - $colspan = count($this->_columns) + 1; |
|
364 | - $this->_tpl->assign('smartobject_colspan', $colspan); |
|
365 | - } |
|
366 | - $this->_hasActions = $doWeHaveActions; |
|
367 | - } |
|
368 | - |
|
369 | - function fetchObjects($debug=false) { |
|
370 | - return $this->_objectHandler->getObjects($this->_criteria, true,true, false, $debug); |
|
371 | - } |
|
372 | - |
|
373 | - function getDefaultFilter() { |
|
374 | - if ($this->_filtersel) { |
|
375 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
376 | - } else { |
|
377 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
378 | - } |
|
379 | - } |
|
380 | - |
|
381 | - function getFiltersArray() { |
|
382 | - $ret = array(); |
|
383 | - $field = array(); |
|
384 | - $field['caption'] = _CO_OBJ_NONE; |
|
385 | - $field['selected'] = ''; |
|
386 | - $ret['default'] = $field; |
|
387 | - unset($field); |
|
388 | - |
|
389 | - if ($this->_filterseloptions) { |
|
390 | - foreach($this->_filterseloptions as $key=>$value) { |
|
391 | - $field = array(); |
|
392 | - if (is_array($value)) { |
|
393 | - $field['caption'] = $key; |
|
394 | - $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
395 | - } else { |
|
396 | - $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
397 | - $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
398 | - } |
|
399 | - $ret[$key] = $field; |
|
400 | - unset($field); |
|
401 | - } |
|
402 | - } else { |
|
403 | - $ret = false; |
|
404 | - } |
|
405 | - return $ret; |
|
406 | - } |
|
407 | - |
|
408 | - function setDefaultFilter2($default_filter2) { |
|
409 | - $this->_filtersel2 = $default_filter2; |
|
410 | - } |
|
411 | - |
|
412 | - function getDefaultFilter2() { |
|
413 | - if ($this->_filtersel2) { |
|
414 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
415 | - } else { |
|
416 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - function getFilters2Array() { |
|
421 | - $ret = array(); |
|
422 | - |
|
423 | - foreach($this->_filtersel2options as $key=>$value) { |
|
424 | - $field = array(); |
|
425 | - $field['caption'] = $value; |
|
426 | - $field['selected'] = $this->_filtersel2 == $key ? "selected='selected'" : ''; |
|
427 | - $ret[$key] = $field; |
|
428 | - unset($field); |
|
429 | - } |
|
430 | - return $ret; |
|
431 | - } |
|
432 | - |
|
433 | - function renderOptionSelection($limitsArray, $params_of_the_options_sel) { |
|
434 | - // Rendering the form to select options on the table |
|
435 | - $current_urls = smart_getCurrentUrls(); |
|
436 | - $current_url = $current_urls['full']; |
|
437 | - |
|
438 | - /** |
|
439 | - * What was $params_of_the_options_sel doing again ? |
|
440 | - */ |
|
441 | - //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
442 | - $this->_tpl->assign('smartobject_optionssel_action', $current_url ); |
|
443 | - $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
444 | - } |
|
445 | - |
|
446 | - function getLimitsArray() { |
|
447 | - $ret = array(); |
|
448 | - $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
449 | - $ret['all']['selected'] = ('all' == $this->_limitsel) ? "selected='selected'" : ""; |
|
450 | - |
|
451 | - $ret['5']['caption'] = '5'; |
|
452 | - $ret['5']['selected'] = ('5' == $this->_limitsel) ? "selected='selected'" : ""; |
|
453 | - |
|
454 | - $ret['10']['caption'] = '10'; |
|
455 | - $ret['10']['selected'] = ('10' == $this->_limitsel) ? "selected='selected'" : ""; |
|
456 | - |
|
457 | - $ret['15']['caption'] = '15'; |
|
458 | - $ret['15']['selected'] = ('15' == $this->_limitsel) ? "selected='selected'" : ""; |
|
459 | - |
|
460 | - $ret['20']['caption'] = '20'; |
|
461 | - $ret['20']['selected'] = ('20' == $this->_limitsel) ? "selected='selected'" : ""; |
|
462 | - |
|
463 | - $ret['25']['caption'] = '25'; |
|
464 | - $ret['25']['selected'] = ('25' == $this->_limitsel) ? "selected='selected'" : ""; |
|
465 | - |
|
466 | - $ret['30']['caption'] = '30'; |
|
467 | - $ret['30']['selected'] = ('30' == $this->_limitsel) ? "selected='selected'" : ""; |
|
468 | - |
|
469 | - $ret['35']['caption'] = '35'; |
|
470 | - $ret['35']['selected'] = ('35' == $this->_limitsel) ? "selected='selected'" : ""; |
|
471 | - |
|
472 | - $ret['40']['caption'] = '40'; |
|
473 | - $ret['40']['selected'] = ('40' == $this->_limitsel) ? "selected='selected'" : ""; |
|
474 | - return $ret; |
|
475 | - } |
|
476 | - |
|
477 | - function getObjects() { |
|
478 | - return $this->_objects; |
|
479 | - } |
|
480 | - |
|
481 | - function hideActionColumnTitle() { |
|
482 | - $this->_showActionsColumnTitle = false; |
|
483 | - } |
|
484 | - |
|
485 | - function hideFilterAndLimit() { |
|
486 | - $this->_showFilterAndLimit = false; |
|
487 | - } |
|
488 | - |
|
489 | - function getOrdersArray() { |
|
490 | - $ret = array(); |
|
491 | - $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
492 | - $ret['ASC']['selected'] = ('ASC' == $this->_ordersel) ? "selected='selected'" : ""; |
|
493 | - |
|
494 | - $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
495 | - $ret['DESC']['selected'] = ('DESC' == $this->_ordersel) ? "selected='selected'" : ""; |
|
496 | - |
|
497 | - return $ret; |
|
498 | - } |
|
499 | - |
|
500 | - function renderD() { |
|
501 | - return $this->render(false, true); |
|
502 | - } |
|
503 | - |
|
504 | - function renderForPrint() { |
|
505 | - |
|
506 | - } |
|
507 | - |
|
508 | - function render($fetchOnly=false, $debug=false) |
|
509 | - { |
|
510 | - include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
511 | - |
|
512 | - $this->_tpl = new XoopsTpl(); |
|
513 | - |
|
514 | - /** |
|
515 | - * We need access to the vars of the SmartObject for a few things in the table creation. |
|
516 | - * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
517 | - * and we will free it after |
|
518 | - */ |
|
519 | - $this->_tempObject =& $this->_objectHandler->create(); |
|
520 | - |
|
521 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? intval($_GET['start' . $this->_objectHandler->keyName]) : 0); |
|
522 | - |
|
523 | - $this->setSortOrder(); |
|
524 | - |
|
525 | - if (!$this->_isTree) { |
|
526 | - $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
527 | - } else { |
|
528 | - $this->_limitsel = 'all'; |
|
529 | - } |
|
530 | - |
|
531 | - $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
532 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
533 | - $limitsArray = $this->getLimitsArray(); |
|
534 | - $this->_criteria->setLimit($this->_limitsel); |
|
535 | - |
|
536 | - $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
537 | - $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
538 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
539 | - $filtersArray = $this->getFiltersArray(); |
|
540 | - |
|
541 | - if ($filtersArray) { |
|
542 | - $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
543 | - } |
|
544 | - |
|
545 | - // Check if the selected filter is defined and if so, create the selfilter2 |
|
546 | - if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
547 | - // check if method associate with this filter exists in the handler |
|
548 | - if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
549 | - $filter = $this->_filterseloptions[$this->_filtersel]; |
|
550 | - $this->_criteria->add($filter['criteria']); |
|
551 | - } else { |
|
552 | - if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
553 | - |
|
554 | - // then we will create the selfilter2 options by calling this method |
|
555 | - $method = $this->_filterseloptions[$this->_filtersel]; |
|
556 | - $this->_filtersel2options = $this->_objectHandler->$method(); |
|
557 | - |
|
558 | - $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
559 | - $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
560 | - |
|
561 | - $filters2Array = $this->getFilters2Array(); |
|
562 | - $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
563 | - |
|
564 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
565 | - if ($this->_filtersel2 != 'default') { |
|
566 | - $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2)); |
|
567 | - } |
|
568 | - } |
|
569 | - } |
|
570 | - } |
|
571 | - // Check if we have a quicksearch |
|
572 | - |
|
573 | - if (isset($_POST['quicksearch_' . $this->_id]) && $_POST['quicksearch_' . $this->_id] != '') { |
|
574 | - $quicksearch_criteria = new CriteriaCompo(); |
|
575 | - if (is_array($this->_quickSearch['fields'])) { |
|
576 | - foreach($this->_quickSearch['fields'] as $v) { |
|
577 | - $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
578 | - } |
|
579 | - } else { |
|
580 | - $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
581 | - } |
|
582 | - $this->_criteria->add($quicksearch_criteria); |
|
583 | - } |
|
584 | - |
|
585 | - $this->_objects = $this->fetchObjects($debug); |
|
586 | - |
|
587 | - include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
588 | - if ($this->_criteria->getLimit() > 0) { |
|
589 | - |
|
590 | - /** |
|
591 | - * Geeting rid of the old params |
|
592 | - * $new_get_array is an array containing the new GET parameters |
|
593 | - */ |
|
594 | - $new_get_array = array(); |
|
595 | - |
|
596 | - /** |
|
597 | - * $params_of_the_options_sel is an array with all the parameters of the page |
|
598 | - * but without the pagenave parameters. This array will be used in the |
|
599 | - * OptionsSelection |
|
600 | - */ |
|
601 | - $params_of_the_options_sel = array(); |
|
602 | - |
|
603 | - $not_needed_params = array('sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName); |
|
604 | - foreach ($_GET as $k => $v) { |
|
605 | - if (!in_array($k, $not_needed_params)) { |
|
606 | - $new_get_array[] = "$k=$v"; |
|
607 | - $params_of_the_options_sel[] = "$k=$v"; |
|
608 | - } |
|
609 | - } |
|
610 | - |
|
611 | - /** |
|
612 | - * Adding the new params of the pagenav |
|
613 | - */ |
|
614 | - $new_get_array[] = "sortsel=" . $this->_sortsel; |
|
615 | - $new_get_array[] = "ordersel=" . $this->_ordersel; |
|
616 | - $new_get_array[] = "limitsel=" . $this->_limitsel; |
|
617 | - $otherParams = implode('&', $new_get_array); |
|
618 | - |
|
619 | - $pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
620 | - $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
621 | - } |
|
622 | - $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
623 | - |
|
624 | - // retreive the current url and the query string |
|
625 | - $current_urls = smart_getCurrentUrls(); |
|
626 | - $current_url = $current_urls['full_phpself']; |
|
627 | - $query_string = $current_urls['querystring']; |
|
628 | - if ($query_string) { |
|
629 | - $query_string = str_replace('?', '',$query_string); |
|
630 | - } |
|
631 | - $query_stringArray = explode('&', $query_string); |
|
632 | - $new_query_stringArray = array(); |
|
633 | - foreach($query_stringArray as $query_string) { |
|
634 | - if (strpos($query_string, 'sortsel') == FALSE && strpos($query_string, 'ordersel') == FALSE) { |
|
635 | - $new_query_stringArray[] = $query_string; |
|
636 | - } |
|
637 | - } |
|
638 | - $new_query_string = implode('&', $new_query_stringArray); |
|
639 | - |
|
640 | - $orderArray = array(); |
|
641 | - $orderArray['ASC']['image'] = 'desc.png'; |
|
642 | - $orderArray['ASC']['neworder'] = 'DESC'; |
|
643 | - $orderArray['DESC']['image'] = 'asc.png'; |
|
644 | - $orderArray['DESC']['neworder'] = 'ASC'; |
|
645 | - |
|
646 | - $aColumns = array(); |
|
647 | - |
|
648 | - foreach ($this->_columns as $column) { |
|
649 | - $qs_param = ''; |
|
650 | - $aColumn = array(); |
|
651 | - $aColumn['width'] = $column->getWidth(); |
|
652 | - $aColumn['align'] = $column->getAlign(); |
|
653 | - $aColumn['key'] = $column->getKeyName(); |
|
654 | - if($column->_keyname == 'checked'){ |
|
655 | - $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . |
|
656 | - ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_'.$this->_id.', \'selected_smartobjects\');" />'; |
|
657 | - }elseif($column->getCustomCaption()){ |
|
658 | - $aColumn['caption'] = $column->getCustomCaption(); |
|
659 | - }else{ |
|
660 | - $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
661 | - } |
|
662 | - // Are we doing a GET sort on this column ? |
|
663 | - $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) || ($this->_sortsel == $column->getKeyName()); |
|
664 | - $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
665 | - |
|
666 | - if (isset($_REQUEST['quicksearch_' . $this->_id]) && $_REQUEST['quicksearch_' . $this->_id] != '') { |
|
667 | - $qs_param = "&quicksearch_".$this->_id."=".$_REQUEST['quicksearch_' . $this->_id]; |
|
668 | - } |
|
669 | - if (!$this->_enableColumnsSorting || $column->_keyname == 'checked' || !$column->isSortable()) { |
|
670 | - $aColumn['caption'] = $aColumn['caption']; |
|
671 | - } elseif ($getSort) { |
|
672 | - $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=' . $orderArray[$order]['neworder'].$qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . ' <img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . $orderArray[$order]['image'] . '" alt="ASC" /></a>'; |
|
673 | - } else { |
|
674 | - $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC'.$qs_param.'&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
675 | - } |
|
676 | - $aColumns[] = $aColumn; |
|
677 | - } |
|
678 | - $this->_tpl->assign('smartobject_columns', $aColumns); |
|
679 | - |
|
680 | - if ($this->_quickSearch) { |
|
681 | - $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
682 | - } |
|
683 | - |
|
684 | - $this->createTableRows(); |
|
685 | - |
|
686 | - $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
687 | - $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
688 | - $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
689 | - $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
690 | - $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
691 | - $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
692 | - $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
693 | - $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
694 | - $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
695 | - $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
696 | - $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
697 | - $this->_tpl->assign('smartobject_id', $this->_id); |
|
698 | - if(!empty($this->_withSelectedActions)){ |
|
699 | - $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
700 | - } |
|
701 | - |
|
702 | - $smartobject_table_template = $this->_customTemplate ? $this->_customTemplate : 'smartobject_smarttable_display.html'; |
|
703 | - if ($fetchOnly) { |
|
704 | - return $this->_tpl->fetch( 'db:' . $smartobject_table_template ); |
|
705 | - } else { |
|
706 | - $this->_tpl->display( 'db:' . $smartobject_table_template ); |
|
707 | - } |
|
708 | - } |
|
709 | - |
|
710 | - function disableColumnsSorting() { |
|
711 | - $this->_enableColumnsSorting = false; |
|
712 | - } |
|
713 | - function fetch($debug=false) { |
|
714 | - return $this->render(true, $debug); |
|
715 | - } |
|
81 | + var $_id; |
|
82 | + var $_objectHandler; |
|
83 | + var $_columns; |
|
84 | + var $_criteria; |
|
85 | + var $_actions; |
|
86 | + var $_objects=false; |
|
87 | + var $_aObjects; |
|
88 | + var $_custom_actions; |
|
89 | + var $_sortsel; |
|
90 | + var $_ordersel; |
|
91 | + var $_limitsel; |
|
92 | + var $_filtersel; |
|
93 | + var $_filterseloptions; |
|
94 | + var $_filtersel2; |
|
95 | + var $_filtersel2options; |
|
96 | + var $_filtersel2optionsDefault; |
|
97 | + |
|
98 | + var $_tempObject; |
|
99 | + var $_tpl; |
|
100 | + var $_introButtons; |
|
101 | + var $_quickSearch=false; |
|
102 | + var $_actionButtons=false; |
|
103 | + var $_head_css_class='bg3'; |
|
104 | + var $_hasActions=false; |
|
105 | + var $_userSide=false; |
|
106 | + var $_printerFriendlyPage=false; |
|
107 | + var $_tableHeader=false; |
|
108 | + var $_tableFooter=false; |
|
109 | + var $_showActionsColumnTitle = true; |
|
110 | + var $_isTree = false; |
|
111 | + var $_showFilterAndLimit = true; |
|
112 | + var $_enableColumnsSorting = true; |
|
113 | + var $_customTemplate = false; |
|
114 | + var $_withSelectedActions = array(); |
|
115 | + |
|
116 | + /** |
|
117 | + * Constructor |
|
118 | + * |
|
119 | + * @param object $objectHandler {@link SmartPersistableObjectHandler} |
|
120 | + * @param array $columns array representing the columns to display in the table |
|
121 | + * @param object $criteria |
|
122 | + * @param array $actions array representing the actions to offer |
|
123 | + * |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + function SmartObjectTable(&$objectHandler, $criteria=false, $actions=array('edit', 'delete'), $userSide=false) |
|
127 | + { |
|
128 | + $this->_id = $objectHandler->className; |
|
129 | + $this->_objectHandler = $objectHandler; |
|
130 | + |
|
131 | + if (!$criteria) { |
|
132 | + $criteria = new CriteriaCompo(); |
|
133 | + } |
|
134 | + $this->_criteria = $criteria; |
|
135 | + $this->_actions = $actions; |
|
136 | + $this->_custom_actions = array(); |
|
137 | + $this->_userSide = $userSide; |
|
138 | + if ($userSide) { |
|
139 | + $this->_head_css_class = 'head'; |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + function addActionButton($op, $caption=false, $text=false) { |
|
144 | + $action = array( |
|
145 | + 'op' => $op, |
|
146 | + 'caption' => $caption, |
|
147 | + 'text' => $text |
|
148 | + ); |
|
149 | + $this->_actionButtons[] = $action; |
|
150 | + } |
|
151 | + |
|
152 | + function addColumn($columnObj) { |
|
153 | + $this->_columns[] = $columnObj; |
|
154 | + } |
|
155 | + |
|
156 | + function addIntroButton($name, $location, $value) { |
|
157 | + $introButton = array(); |
|
158 | + $introButton['name'] = $name; |
|
159 | + $introButton['location'] = $location; |
|
160 | + $introButton['value'] = $value; |
|
161 | + $this->_introButtons[] = $introButton; |
|
162 | + unset($introButton); |
|
163 | + } |
|
164 | + |
|
165 | + function addPrinterFriendlyLink() { |
|
166 | + $current_urls = smart_getCurrentUrls(); |
|
167 | + $current_url = $current_urls['full']; |
|
168 | + $this->_printerFriendlyPage = $current_url . '&print'; |
|
169 | + } |
|
170 | + |
|
171 | + function addQuickSearch($fields, $caption=_CO_SOBJECT_QUICK_SEARCH) { |
|
172 | + $this->_quickSearch = array('fields' => $fields, 'caption' => $caption); |
|
173 | + } |
|
174 | + |
|
175 | + function addHeader($content) { |
|
176 | + $this->_tableHeader = $content; |
|
177 | + } |
|
178 | + |
|
179 | + function addFooter($content) { |
|
180 | + $this->_tableFooter = $content; |
|
181 | + } |
|
182 | + |
|
183 | + function addDefaultIntroButton($caption) { |
|
184 | + $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . "?op=mod", $caption); |
|
185 | + } |
|
186 | + |
|
187 | + function addCustomAction($method) { |
|
188 | + $this->_custom_actions[] = $method; |
|
189 | + } |
|
190 | + |
|
191 | + function setDefaultSort($default_sort) { |
|
192 | + $this->_sortsel = $default_sort; |
|
193 | + } |
|
194 | + |
|
195 | + function getDefaultSort() { |
|
196 | + if ($this->_sortsel) { |
|
197 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
198 | + } else { |
|
199 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + function setDefaultOrder($default_order) { |
|
204 | + $this->_ordersel = $default_order; |
|
205 | + } |
|
206 | + |
|
207 | + function getDefaultOrder() { |
|
208 | + if ($this->_ordersel) { |
|
209 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
210 | + } else { |
|
211 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
212 | + } |
|
213 | + } |
|
214 | + function addWithSelectedActions($actions = array()){ |
|
215 | + $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
216 | + $this->_withSelectedActions = $actions; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Adding a filter in the table |
|
221 | + * |
|
222 | + * @param string $key key to the field that will be used for sorting |
|
223 | + * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
224 | + */ |
|
225 | + function addFilter($key, $method, $default=false) { |
|
226 | + $this->_filterseloptions[$key] = $method; |
|
227 | + $this->_filtersel2optionsDefault = $default; |
|
228 | + } |
|
229 | + |
|
230 | + function setDefaultFilter($default_filter) { |
|
231 | + $this->_filtersel = $default_filter; |
|
232 | + } |
|
233 | + |
|
234 | + function isForUserSide() { |
|
235 | + $this->_userSide = true; |
|
236 | + } |
|
237 | + function setCustomTemplate($template) { |
|
238 | + $this->_customTemplate = $template; |
|
239 | + } |
|
240 | + function setSortOrder() { |
|
241 | + $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
242 | + //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel'] : $this->_sortsel; |
|
243 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
244 | + $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
245 | + |
|
246 | + if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
247 | + $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . "." . $this->_sortsel); |
|
248 | + } else { |
|
249 | + |
|
250 | + $this->_criteria->setSort($this->_objectHandler->_itemname . "." . $this->_sortsel); |
|
251 | + } |
|
252 | + |
|
253 | + $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
254 | + //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel'] :$this->_ordersel; |
|
255 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
256 | + $ordersArray = $this->getOrdersArray(); |
|
257 | + $this->_criteria->setOrder($this->_ordersel); |
|
258 | + } |
|
259 | + |
|
260 | + function setTableId($id) { |
|
261 | + $this->_id = $id; |
|
262 | + } |
|
263 | + |
|
264 | + function setObjects($objects) { |
|
265 | + $this->_objects = $objects; |
|
266 | + } |
|
267 | + |
|
268 | + function createTableRows() { |
|
269 | + $this->_aObjects = array(); |
|
270 | + |
|
271 | + $doWeHaveActions = false; |
|
272 | + |
|
273 | + $objectclass = 'odd'; |
|
274 | + if (count($this->_objects) > 0) { |
|
275 | + foreach ($this->_objects as $object) { |
|
276 | + |
|
277 | + $aObject = array(); |
|
278 | + |
|
279 | + $i=0; |
|
280 | + |
|
281 | + $aColumns = array(); |
|
282 | + |
|
283 | + foreach ($this->_columns as $column) { |
|
284 | + |
|
285 | + $aColumn = array(); |
|
286 | + |
|
287 | + if ($i==0) { |
|
288 | + $class = "head"; |
|
289 | + } elseif ($i % 2 == 0) { |
|
290 | + $class = "even"; |
|
291 | + } else { |
|
292 | + $class = "odd"; |
|
293 | + } |
|
294 | + if(method_exists($object, 'initiateCustomFields')){ |
|
295 | + //$object->initiateCustomFields(); |
|
296 | + } |
|
297 | + if($column->_keyname == 'checked'){ |
|
298 | + $value = '<input type ="checkbox" name="selected_smartobjects[]" value="'.$object->id().'" />'; |
|
299 | + }elseif ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
300 | + $method = $column->_customMethodForValue; |
|
301 | + if($column->_param){ |
|
302 | + $value = $object->$method($column->_param); |
|
303 | + }else{ |
|
304 | + $value = $object->$method(); |
|
305 | + } |
|
306 | + } else { |
|
307 | + /** |
|
308 | + * If the column is the identifier, then put a link on it |
|
309 | + */ |
|
310 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
311 | + $value = $object->getItemLink(); |
|
312 | + } else { |
|
313 | + $value = $object->getVar($column->getKeyName()); |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + $aColumn['value'] = $value; |
|
318 | + $aColumn['class'] = $class; |
|
319 | + $aColumn['width'] = $column->getWidth(); |
|
320 | + $aColumn['align'] = $column->getAlign(); |
|
321 | + |
|
322 | + $aColumns[] = $aColumn; |
|
323 | + $i++; |
|
324 | + } |
|
325 | + |
|
326 | + $aObject['columns'] = $aColumns; |
|
327 | + $aObject['id'] = $object->id(); |
|
328 | + |
|
329 | + $objectclass = ($objectclass == 'even') ? 'odd' : 'even'; |
|
330 | + |
|
331 | + $aObject['class'] = $objectclass; |
|
332 | + |
|
333 | + $actions = array(); |
|
334 | + |
|
335 | + // Adding the custom actions if any |
|
336 | + foreach ($this->_custom_actions as $action) { |
|
337 | + if (method_exists($object, $action)) { |
|
338 | + $actions[] = $object->$action(); |
|
339 | + } |
|
340 | + } |
|
341 | + |
|
342 | + include_once SMARTOBJECT_ROOT_PATH . "class/smartobjectcontroller.php"; |
|
343 | + $controller = new SmartObjectController($this->_objectHandler); |
|
344 | + |
|
345 | + if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
346 | + $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
347 | + } |
|
348 | + if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
349 | + $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
350 | + } |
|
351 | + $aObject['actions'] = $actions; |
|
352 | + |
|
353 | + $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
354 | + |
|
355 | + $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
356 | + |
|
357 | + $this->_aObjects[] = $aObject; |
|
358 | + } |
|
359 | + $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
360 | + } else { |
|
361 | + $colspan = count($this->_columns) + 1; |
|
362 | + $this->_tpl->assign('smartobject_colspan', $colspan); |
|
363 | + } |
|
364 | + $this->_hasActions = $doWeHaveActions; |
|
365 | + } |
|
366 | + |
|
367 | + function fetchObjects($debug=false) { |
|
368 | + return $this->_objectHandler->getObjects($this->_criteria, true,true, false, $debug); |
|
369 | + } |
|
370 | + |
|
371 | + function getDefaultFilter() { |
|
372 | + if ($this->_filtersel) { |
|
373 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
374 | + } else { |
|
375 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + function getFiltersArray() { |
|
380 | + $ret = array(); |
|
381 | + $field = array(); |
|
382 | + $field['caption'] = _CO_OBJ_NONE; |
|
383 | + $field['selected'] = ''; |
|
384 | + $ret['default'] = $field; |
|
385 | + unset($field); |
|
386 | + |
|
387 | + if ($this->_filterseloptions) { |
|
388 | + foreach($this->_filterseloptions as $key=>$value) { |
|
389 | + $field = array(); |
|
390 | + if (is_array($value)) { |
|
391 | + $field['caption'] = $key; |
|
392 | + $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
393 | + } else { |
|
394 | + $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
395 | + $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
396 | + } |
|
397 | + $ret[$key] = $field; |
|
398 | + unset($field); |
|
399 | + } |
|
400 | + } else { |
|
401 | + $ret = false; |
|
402 | + } |
|
403 | + return $ret; |
|
404 | + } |
|
405 | + |
|
406 | + function setDefaultFilter2($default_filter2) { |
|
407 | + $this->_filtersel2 = $default_filter2; |
|
408 | + } |
|
409 | + |
|
410 | + function getDefaultFilter2() { |
|
411 | + if ($this->_filtersel2) { |
|
412 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
413 | + } else { |
|
414 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
415 | + } |
|
416 | + } |
|
417 | + |
|
418 | + function getFilters2Array() { |
|
419 | + $ret = array(); |
|
420 | + |
|
421 | + foreach($this->_filtersel2options as $key=>$value) { |
|
422 | + $field = array(); |
|
423 | + $field['caption'] = $value; |
|
424 | + $field['selected'] = $this->_filtersel2 == $key ? "selected='selected'" : ''; |
|
425 | + $ret[$key] = $field; |
|
426 | + unset($field); |
|
427 | + } |
|
428 | + return $ret; |
|
429 | + } |
|
430 | + |
|
431 | + function renderOptionSelection($limitsArray, $params_of_the_options_sel) { |
|
432 | + // Rendering the form to select options on the table |
|
433 | + $current_urls = smart_getCurrentUrls(); |
|
434 | + $current_url = $current_urls['full']; |
|
435 | + |
|
436 | + /** |
|
437 | + * What was $params_of_the_options_sel doing again ? |
|
438 | + */ |
|
439 | + //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
440 | + $this->_tpl->assign('smartobject_optionssel_action', $current_url ); |
|
441 | + $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
442 | + } |
|
443 | + |
|
444 | + function getLimitsArray() { |
|
445 | + $ret = array(); |
|
446 | + $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
447 | + $ret['all']['selected'] = ('all' == $this->_limitsel) ? "selected='selected'" : ""; |
|
448 | + |
|
449 | + $ret['5']['caption'] = '5'; |
|
450 | + $ret['5']['selected'] = ('5' == $this->_limitsel) ? "selected='selected'" : ""; |
|
451 | + |
|
452 | + $ret['10']['caption'] = '10'; |
|
453 | + $ret['10']['selected'] = ('10' == $this->_limitsel) ? "selected='selected'" : ""; |
|
454 | + |
|
455 | + $ret['15']['caption'] = '15'; |
|
456 | + $ret['15']['selected'] = ('15' == $this->_limitsel) ? "selected='selected'" : ""; |
|
457 | + |
|
458 | + $ret['20']['caption'] = '20'; |
|
459 | + $ret['20']['selected'] = ('20' == $this->_limitsel) ? "selected='selected'" : ""; |
|
460 | + |
|
461 | + $ret['25']['caption'] = '25'; |
|
462 | + $ret['25']['selected'] = ('25' == $this->_limitsel) ? "selected='selected'" : ""; |
|
463 | + |
|
464 | + $ret['30']['caption'] = '30'; |
|
465 | + $ret['30']['selected'] = ('30' == $this->_limitsel) ? "selected='selected'" : ""; |
|
466 | + |
|
467 | + $ret['35']['caption'] = '35'; |
|
468 | + $ret['35']['selected'] = ('35' == $this->_limitsel) ? "selected='selected'" : ""; |
|
469 | + |
|
470 | + $ret['40']['caption'] = '40'; |
|
471 | + $ret['40']['selected'] = ('40' == $this->_limitsel) ? "selected='selected'" : ""; |
|
472 | + return $ret; |
|
473 | + } |
|
474 | + |
|
475 | + function getObjects() { |
|
476 | + return $this->_objects; |
|
477 | + } |
|
478 | + |
|
479 | + function hideActionColumnTitle() { |
|
480 | + $this->_showActionsColumnTitle = false; |
|
481 | + } |
|
482 | + |
|
483 | + function hideFilterAndLimit() { |
|
484 | + $this->_showFilterAndLimit = false; |
|
485 | + } |
|
486 | + |
|
487 | + function getOrdersArray() { |
|
488 | + $ret = array(); |
|
489 | + $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
490 | + $ret['ASC']['selected'] = ('ASC' == $this->_ordersel) ? "selected='selected'" : ""; |
|
491 | + |
|
492 | + $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
493 | + $ret['DESC']['selected'] = ('DESC' == $this->_ordersel) ? "selected='selected'" : ""; |
|
494 | + |
|
495 | + return $ret; |
|
496 | + } |
|
497 | + |
|
498 | + function renderD() { |
|
499 | + return $this->render(false, true); |
|
500 | + } |
|
501 | + |
|
502 | + function renderForPrint() { |
|
503 | + |
|
504 | + } |
|
505 | + |
|
506 | + function render($fetchOnly=false, $debug=false) |
|
507 | + { |
|
508 | + include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
509 | + |
|
510 | + $this->_tpl = new XoopsTpl(); |
|
511 | + |
|
512 | + /** |
|
513 | + * We need access to the vars of the SmartObject for a few things in the table creation. |
|
514 | + * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
515 | + * and we will free it after |
|
516 | + */ |
|
517 | + $this->_tempObject =& $this->_objectHandler->create(); |
|
518 | + |
|
519 | + $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? intval($_GET['start' . $this->_objectHandler->keyName]) : 0); |
|
520 | + |
|
521 | + $this->setSortOrder(); |
|
522 | + |
|
523 | + if (!$this->_isTree) { |
|
524 | + $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
525 | + } else { |
|
526 | + $this->_limitsel = 'all'; |
|
527 | + } |
|
528 | + |
|
529 | + $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
530 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
531 | + $limitsArray = $this->getLimitsArray(); |
|
532 | + $this->_criteria->setLimit($this->_limitsel); |
|
533 | + |
|
534 | + $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
535 | + $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
536 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
537 | + $filtersArray = $this->getFiltersArray(); |
|
538 | + |
|
539 | + if ($filtersArray) { |
|
540 | + $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
541 | + } |
|
542 | + |
|
543 | + // Check if the selected filter is defined and if so, create the selfilter2 |
|
544 | + if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
545 | + // check if method associate with this filter exists in the handler |
|
546 | + if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
547 | + $filter = $this->_filterseloptions[$this->_filtersel]; |
|
548 | + $this->_criteria->add($filter['criteria']); |
|
549 | + } else { |
|
550 | + if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
551 | + |
|
552 | + // then we will create the selfilter2 options by calling this method |
|
553 | + $method = $this->_filterseloptions[$this->_filtersel]; |
|
554 | + $this->_filtersel2options = $this->_objectHandler->$method(); |
|
555 | + |
|
556 | + $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
557 | + $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
558 | + |
|
559 | + $filters2Array = $this->getFilters2Array(); |
|
560 | + $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
561 | + |
|
562 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
563 | + if ($this->_filtersel2 != 'default') { |
|
564 | + $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2)); |
|
565 | + } |
|
566 | + } |
|
567 | + } |
|
568 | + } |
|
569 | + // Check if we have a quicksearch |
|
570 | + |
|
571 | + if (isset($_POST['quicksearch_' . $this->_id]) && $_POST['quicksearch_' . $this->_id] != '') { |
|
572 | + $quicksearch_criteria = new CriteriaCompo(); |
|
573 | + if (is_array($this->_quickSearch['fields'])) { |
|
574 | + foreach($this->_quickSearch['fields'] as $v) { |
|
575 | + $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
576 | + } |
|
577 | + } else { |
|
578 | + $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
579 | + } |
|
580 | + $this->_criteria->add($quicksearch_criteria); |
|
581 | + } |
|
582 | + |
|
583 | + $this->_objects = $this->fetchObjects($debug); |
|
584 | + |
|
585 | + include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
586 | + if ($this->_criteria->getLimit() > 0) { |
|
587 | + |
|
588 | + /** |
|
589 | + * Geeting rid of the old params |
|
590 | + * $new_get_array is an array containing the new GET parameters |
|
591 | + */ |
|
592 | + $new_get_array = array(); |
|
593 | + |
|
594 | + /** |
|
595 | + * $params_of_the_options_sel is an array with all the parameters of the page |
|
596 | + * but without the pagenave parameters. This array will be used in the |
|
597 | + * OptionsSelection |
|
598 | + */ |
|
599 | + $params_of_the_options_sel = array(); |
|
600 | + |
|
601 | + $not_needed_params = array('sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName); |
|
602 | + foreach ($_GET as $k => $v) { |
|
603 | + if (!in_array($k, $not_needed_params)) { |
|
604 | + $new_get_array[] = "$k=$v"; |
|
605 | + $params_of_the_options_sel[] = "$k=$v"; |
|
606 | + } |
|
607 | + } |
|
608 | + |
|
609 | + /** |
|
610 | + * Adding the new params of the pagenav |
|
611 | + */ |
|
612 | + $new_get_array[] = "sortsel=" . $this->_sortsel; |
|
613 | + $new_get_array[] = "ordersel=" . $this->_ordersel; |
|
614 | + $new_get_array[] = "limitsel=" . $this->_limitsel; |
|
615 | + $otherParams = implode('&', $new_get_array); |
|
616 | + |
|
617 | + $pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
618 | + $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
619 | + } |
|
620 | + $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
621 | + |
|
622 | + // retreive the current url and the query string |
|
623 | + $current_urls = smart_getCurrentUrls(); |
|
624 | + $current_url = $current_urls['full_phpself']; |
|
625 | + $query_string = $current_urls['querystring']; |
|
626 | + if ($query_string) { |
|
627 | + $query_string = str_replace('?', '',$query_string); |
|
628 | + } |
|
629 | + $query_stringArray = explode('&', $query_string); |
|
630 | + $new_query_stringArray = array(); |
|
631 | + foreach($query_stringArray as $query_string) { |
|
632 | + if (strpos($query_string, 'sortsel') == FALSE && strpos($query_string, 'ordersel') == FALSE) { |
|
633 | + $new_query_stringArray[] = $query_string; |
|
634 | + } |
|
635 | + } |
|
636 | + $new_query_string = implode('&', $new_query_stringArray); |
|
637 | + |
|
638 | + $orderArray = array(); |
|
639 | + $orderArray['ASC']['image'] = 'desc.png'; |
|
640 | + $orderArray['ASC']['neworder'] = 'DESC'; |
|
641 | + $orderArray['DESC']['image'] = 'asc.png'; |
|
642 | + $orderArray['DESC']['neworder'] = 'ASC'; |
|
643 | + |
|
644 | + $aColumns = array(); |
|
645 | + |
|
646 | + foreach ($this->_columns as $column) { |
|
647 | + $qs_param = ''; |
|
648 | + $aColumn = array(); |
|
649 | + $aColumn['width'] = $column->getWidth(); |
|
650 | + $aColumn['align'] = $column->getAlign(); |
|
651 | + $aColumn['key'] = $column->getKeyName(); |
|
652 | + if($column->_keyname == 'checked'){ |
|
653 | + $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . |
|
654 | + ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_'.$this->_id.', \'selected_smartobjects\');" />'; |
|
655 | + }elseif($column->getCustomCaption()){ |
|
656 | + $aColumn['caption'] = $column->getCustomCaption(); |
|
657 | + }else{ |
|
658 | + $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
659 | + } |
|
660 | + // Are we doing a GET sort on this column ? |
|
661 | + $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) || ($this->_sortsel == $column->getKeyName()); |
|
662 | + $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
663 | + |
|
664 | + if (isset($_REQUEST['quicksearch_' . $this->_id]) && $_REQUEST['quicksearch_' . $this->_id] != '') { |
|
665 | + $qs_param = "&quicksearch_".$this->_id."=".$_REQUEST['quicksearch_' . $this->_id]; |
|
666 | + } |
|
667 | + if (!$this->_enableColumnsSorting || $column->_keyname == 'checked' || !$column->isSortable()) { |
|
668 | + $aColumn['caption'] = $aColumn['caption']; |
|
669 | + } elseif ($getSort) { |
|
670 | + $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=' . $orderArray[$order]['neworder'].$qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . ' <img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . $orderArray[$order]['image'] . '" alt="ASC" /></a>'; |
|
671 | + } else { |
|
672 | + $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC'.$qs_param.'&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
673 | + } |
|
674 | + $aColumns[] = $aColumn; |
|
675 | + } |
|
676 | + $this->_tpl->assign('smartobject_columns', $aColumns); |
|
677 | + |
|
678 | + if ($this->_quickSearch) { |
|
679 | + $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
680 | + } |
|
681 | + |
|
682 | + $this->createTableRows(); |
|
683 | + |
|
684 | + $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
685 | + $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
686 | + $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
687 | + $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
688 | + $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
689 | + $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
690 | + $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
691 | + $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
692 | + $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
693 | + $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
694 | + $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
695 | + $this->_tpl->assign('smartobject_id', $this->_id); |
|
696 | + if(!empty($this->_withSelectedActions)){ |
|
697 | + $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
698 | + } |
|
699 | + |
|
700 | + $smartobject_table_template = $this->_customTemplate ? $this->_customTemplate : 'smartobject_smarttable_display.html'; |
|
701 | + if ($fetchOnly) { |
|
702 | + return $this->_tpl->fetch( 'db:' . $smartobject_table_template ); |
|
703 | + } else { |
|
704 | + $this->_tpl->display( 'db:' . $smartobject_table_template ); |
|
705 | + } |
|
706 | + } |
|
707 | + |
|
708 | + function disableColumnsSorting() { |
|
709 | + $this->_enableColumnsSorting = false; |
|
710 | + } |
|
711 | + function fetch($debug=false) { |
|
712 | + return $this->render(true, $debug); |
|
713 | + } |
|
716 | 714 | } |
717 | 715 | |
718 | 716 | ?> |
719 | 717 | \ No newline at end of file |
@@ -28,120 +28,120 @@ |
||
28 | 28 | // -------------------------------------------------------------------------// |
29 | 29 | |
30 | 30 | if (!defined("XOOPS_ROOT_PATH")) { |
31 | - die("XOOPS root path not defined"); |
|
31 | + die("XOOPS root path not defined"); |
|
32 | 32 | } |
33 | 33 | include_once XOOPS_ROOT_PATH."/modules/smartobject/class/smartobject.php"; |
34 | 34 | class SmartobjectLink extends SmartObject { |
35 | 35 | |
36 | - function SmartobjectLink() { |
|
37 | - $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
38 | - $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null,'', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
39 | - $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
40 | - $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
41 | - $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
42 | - $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
43 | - $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
44 | - $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
45 | - $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
36 | + function SmartobjectLink() { |
|
37 | + $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
38 | + $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null,'', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
39 | + $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
40 | + $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
41 | + $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
42 | + $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
43 | + $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
44 | + $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
45 | + $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
46 | 46 | $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
47 | 47 | $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
48 | - $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
49 | - $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * returns a specific variable for the object in a proper format |
|
55 | - * |
|
56 | - * @access public |
|
57 | - * @param string $key key of the object's variable to be returned |
|
58 | - * @param string $format format to use for the output |
|
59 | - * @return mixed formatted value of the variable |
|
60 | - */ |
|
61 | - function getVar($key, $format = 's') { |
|
62 | - if ($format == 's' && in_array($key, array('from_uid', 'to_uid', 'date', 'link'))) { |
|
63 | - return call_user_func(array($this,$key)); |
|
64 | - } |
|
65 | - return parent::getVar($key, $format); |
|
66 | - } |
|
67 | - |
|
68 | - function from_uid() { |
|
69 | - $ret = smart_getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
70 | - return $ret; |
|
71 | - } |
|
72 | - |
|
73 | - function to_uid($withContact=false) { |
|
74 | - $ret = smart_getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
75 | - return $ret; |
|
76 | - } |
|
77 | - |
|
78 | - function date() { |
|
79 | - $ret = formatTimestamp($this->getVar('date','e')); |
|
80 | - return $ret; |
|
81 | - } |
|
82 | - |
|
83 | - function link($full=false) { |
|
84 | - $ret = $this->getVar('link','e'); |
|
85 | - if ($full) { |
|
86 | - $myts = MyTextSanitizer::getInstance(); |
|
87 | - $ret = $myts->displayTarea($ret); |
|
88 | - return $ret; |
|
89 | - } else { |
|
90 | - $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link','e') . '" title="' . $this->getVar('link','e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
91 | - return $ret; |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - function getViewItemLink() { |
|
48 | + $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
49 | + $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * returns a specific variable for the object in a proper format |
|
55 | + * |
|
56 | + * @access public |
|
57 | + * @param string $key key of the object's variable to be returned |
|
58 | + * @param string $format format to use for the output |
|
59 | + * @return mixed formatted value of the variable |
|
60 | + */ |
|
61 | + function getVar($key, $format = 's') { |
|
62 | + if ($format == 's' && in_array($key, array('from_uid', 'to_uid', 'date', 'link'))) { |
|
63 | + return call_user_func(array($this,$key)); |
|
64 | + } |
|
65 | + return parent::getVar($key, $format); |
|
66 | + } |
|
67 | + |
|
68 | + function from_uid() { |
|
69 | + $ret = smart_getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
70 | + return $ret; |
|
71 | + } |
|
72 | + |
|
73 | + function to_uid($withContact=false) { |
|
74 | + $ret = smart_getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
75 | + return $ret; |
|
76 | + } |
|
77 | + |
|
78 | + function date() { |
|
79 | + $ret = formatTimestamp($this->getVar('date','e')); |
|
80 | + return $ret; |
|
81 | + } |
|
82 | + |
|
83 | + function link($full=false) { |
|
84 | + $ret = $this->getVar('link','e'); |
|
85 | + if ($full) { |
|
86 | + $myts = MyTextSanitizer::getInstance(); |
|
87 | + $ret = $myts->displayTarea($ret); |
|
88 | + return $ret; |
|
89 | + } else { |
|
90 | + $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link','e') . '" title="' . $this->getVar('link','e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
91 | + return $ret; |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + function getViewItemLink() { |
|
96 | 96 | $ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '" /></a>'; |
97 | 97 | return $ret; |
98 | - } |
|
98 | + } |
|
99 | 99 | |
100 | - function getFromInfo() { |
|
101 | - // check if from_uid represent a user |
|
100 | + function getFromInfo() { |
|
101 | + // check if from_uid represent a user |
|
102 | 102 | |
103 | - if ($this->getVar('from_uid')) { |
|
103 | + if ($this->getVar('from_uid')) { |
|
104 | 104 | $user = smart_getLinkedUnameFromId($this->getVar('from_uid')); |
105 | 105 | if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
106 | 106 | $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
107 | 107 | } |
108 | - } else { |
|
109 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
110 | - } |
|
108 | + } else { |
|
109 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
110 | + } |
|
111 | 111 | |
112 | - return $user; |
|
112 | + return $user; |
|
113 | 113 | |
114 | - } |
|
114 | + } |
|
115 | 115 | |
116 | - function toArray() { |
|
117 | - $ret = parent::toArray(); |
|
118 | - $ret['fromInfo'] = $this->getFromInfo(); |
|
119 | - $ret['toInfo'] = $this->getToInfo(); |
|
120 | - $ret['fullLink'] = $this->link(true); |
|
121 | - return $ret; |
|
122 | - } |
|
116 | + function toArray() { |
|
117 | + $ret = parent::toArray(); |
|
118 | + $ret['fromInfo'] = $this->getFromInfo(); |
|
119 | + $ret['toInfo'] = $this->getToInfo(); |
|
120 | + $ret['fullLink'] = $this->link(true); |
|
121 | + return $ret; |
|
122 | + } |
|
123 | 123 | |
124 | - function getToInfo() { |
|
125 | - // check if from_uid represent a user |
|
124 | + function getToInfo() { |
|
125 | + // check if from_uid represent a user |
|
126 | 126 | |
127 | - if ($this->getVar('to_uid')) { |
|
127 | + if ($this->getVar('to_uid')) { |
|
128 | 128 | $user = smart_getLinkedUnameFromId($this->getVar('to_uid')); |
129 | 129 | if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
130 | 130 | $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
131 | 131 | } |
132 | - } else { |
|
133 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
134 | - } |
|
132 | + } else { |
|
133 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
134 | + } |
|
135 | 135 | |
136 | - return $user; |
|
136 | + return $user; |
|
137 | 137 | |
138 | - } |
|
138 | + } |
|
139 | 139 | } |
140 | 140 | class SmartobjectLinkHandler extends SmartPersistableObjectHandler { |
141 | - function SmartobjectLinkHandler($db) { |
|
141 | + function SmartobjectLinkHandler($db) { |
|
142 | 142 | |
143 | - $this->SmartPersistableObjectHandler($db, 'link', 'linkid', 'subject', 'body', 'smartobject'); |
|
144 | - } |
|
143 | + $this->SmartPersistableObjectHandler($db, 'link', 'linkid', 'subject', 'body', 'smartobject'); |
|
144 | + } |
|
145 | 145 | |
146 | 146 | } |
147 | 147 | ?> |
148 | 148 | \ No newline at end of file |
@@ -21,91 +21,91 @@ |
||
21 | 21 | |
22 | 22 | class SmartHighlighter { |
23 | 23 | |
24 | - /** |
|
25 | - * @access private |
|
26 | - */ |
|
27 | - var $preg_keywords = ''; |
|
28 | - /** |
|
29 | - * @access private |
|
30 | - */ |
|
31 | - var $keywords = ''; |
|
32 | - /** |
|
33 | - * @access private |
|
34 | - */ |
|
35 | - var $singlewords = false; |
|
36 | - /** |
|
37 | - * @access private |
|
38 | - */ |
|
39 | - var $replace_callback = null; |
|
24 | + /** |
|
25 | + * @access private |
|
26 | + */ |
|
27 | + var $preg_keywords = ''; |
|
28 | + /** |
|
29 | + * @access private |
|
30 | + */ |
|
31 | + var $keywords = ''; |
|
32 | + /** |
|
33 | + * @access private |
|
34 | + */ |
|
35 | + var $singlewords = false; |
|
36 | + /** |
|
37 | + * @access private |
|
38 | + */ |
|
39 | + var $replace_callback = null; |
|
40 | 40 | |
41 | - var $content; |
|
41 | + var $content; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Main constructor |
|
45 | - * |
|
46 | - * This is the main constructor of keyhighlighter class. <br /> |
|
47 | - * It's the only public method of the class. |
|
48 | - * @param string $keywords the keywords you want to highlight |
|
49 | - * @param boolean $singlewords specify if it has to highlight also the single words. |
|
50 | - * @param callback $replace_callback a custom callback for keyword highlight. |
|
51 | - * <code> |
|
52 | - * <?php |
|
53 | - * require ('keyhighlighter.class.php'); |
|
54 | - * |
|
55 | - * function my_highlighter ($matches) { |
|
56 | - * return '<span style="font-weight: bolder; color: #FF0000;">' . $matches[0] . '</span>'; |
|
57 | - * } |
|
58 | - * |
|
59 | - * new keyhighlighter ('W3C', false, 'my_highlighter'); |
|
60 | - * readfile ('http://www.w3c.org/'); |
|
61 | - * ?> |
|
62 | - * </code> |
|
63 | - */ |
|
64 | - // public function __construct () |
|
65 | - function SmartHighlighter ($keywords, $singlewords = false, $replace_callback = null ) { |
|
66 | - $this->keywords = $keywords; |
|
67 | - $this->singlewords = $singlewords; |
|
68 | - $this->replace_callback = $replace_callback; |
|
69 | - } |
|
43 | + /** |
|
44 | + * Main constructor |
|
45 | + * |
|
46 | + * This is the main constructor of keyhighlighter class. <br /> |
|
47 | + * It's the only public method of the class. |
|
48 | + * @param string $keywords the keywords you want to highlight |
|
49 | + * @param boolean $singlewords specify if it has to highlight also the single words. |
|
50 | + * @param callback $replace_callback a custom callback for keyword highlight. |
|
51 | + * <code> |
|
52 | + * <?php |
|
53 | + * require ('keyhighlighter.class.php'); |
|
54 | + * |
|
55 | + * function my_highlighter ($matches) { |
|
56 | + * return '<span style="font-weight: bolder; color: #FF0000;">' . $matches[0] . '</span>'; |
|
57 | + * } |
|
58 | + * |
|
59 | + * new keyhighlighter ('W3C', false, 'my_highlighter'); |
|
60 | + * readfile ('http://www.w3c.org/'); |
|
61 | + * ?> |
|
62 | + * </code> |
|
63 | + */ |
|
64 | + // public function __construct () |
|
65 | + function SmartHighlighter ($keywords, $singlewords = false, $replace_callback = null ) { |
|
66 | + $this->keywords = $keywords; |
|
67 | + $this->singlewords = $singlewords; |
|
68 | + $this->replace_callback = $replace_callback; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @access private |
|
73 | - */ |
|
74 | - function replace ($replace_matches) { |
|
71 | + /** |
|
72 | + * @access private |
|
73 | + */ |
|
74 | + function replace ($replace_matches) { |
|
75 | 75 | |
76 | - $patterns = array (); |
|
77 | - if ($this->singlewords) { |
|
78 | - $keywords = explode (' ', $this->preg_keywords); |
|
79 | - foreach ($keywords as $keyword) { |
|
80 | - $patterns[] = '/(?' . '>' . $keyword . '+)/si'; |
|
81 | - } |
|
82 | - } else { |
|
83 | - $patterns[] = '/(?' . '>' . $this->preg_keywords . '+)/si'; |
|
84 | - } |
|
76 | + $patterns = array (); |
|
77 | + if ($this->singlewords) { |
|
78 | + $keywords = explode (' ', $this->preg_keywords); |
|
79 | + foreach ($keywords as $keyword) { |
|
80 | + $patterns[] = '/(?' . '>' . $keyword . '+)/si'; |
|
81 | + } |
|
82 | + } else { |
|
83 | + $patterns[] = '/(?' . '>' . $this->preg_keywords . '+)/si'; |
|
84 | + } |
|
85 | 85 | |
86 | - $result = $replace_matches[0]; |
|
86 | + $result = $replace_matches[0]; |
|
87 | 87 | |
88 | - foreach ($patterns as $pattern) { |
|
89 | - if (!is_null ($this->replace_callback)) { |
|
90 | - $result = preg_replace_callback ($pattern, $this->replace_callback, $result); |
|
91 | - } else { |
|
92 | - $result = preg_replace ($pattern, '<span class="highlightedkey">\\0</span>', $result); |
|
93 | - } |
|
94 | - } |
|
88 | + foreach ($patterns as $pattern) { |
|
89 | + if (!is_null ($this->replace_callback)) { |
|
90 | + $result = preg_replace_callback ($pattern, $this->replace_callback, $result); |
|
91 | + } else { |
|
92 | + $result = preg_replace ($pattern, '<span class="highlightedkey">\\0</span>', $result); |
|
93 | + } |
|
94 | + } |
|
95 | 95 | |
96 | - return $result; |
|
97 | - } |
|
96 | + return $result; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @access private |
|
101 | - */ |
|
102 | - function highlight ($buffer) { |
|
103 | - $buffer = '>' . $buffer . '<'; |
|
104 | - $this->preg_keywords = preg_replace ('/[^\w ]/si', '', $this->keywords); |
|
105 | - $buffer = preg_replace_callback ("/(\>(((?" . ">[^><]+)|(?R))*)\<)/is", array (&$this, 'replace'), $buffer); |
|
106 | - $buffer = substr ($buffer, 1, -1); |
|
107 | - return $buffer; |
|
108 | - } |
|
99 | + /** |
|
100 | + * @access private |
|
101 | + */ |
|
102 | + function highlight ($buffer) { |
|
103 | + $buffer = '>' . $buffer . '<'; |
|
104 | + $this->preg_keywords = preg_replace ('/[^\w ]/si', '', $this->keywords); |
|
105 | + $buffer = preg_replace_callback ("/(\>(((?" . ">[^><]+)|(?R))*)\<)/is", array (&$this, 'replace'), $buffer); |
|
106 | + $buffer = substr ($buffer, 1, -1); |
|
107 | + return $buffer; |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | ?> |
112 | 112 | \ No newline at end of file |
@@ -23,139 +23,139 @@ |
||
23 | 23 | */ |
24 | 24 | class SmartObjectTreeTable extends SmartObjectTable { |
25 | 25 | |
26 | - function SmartObjectTreeTable(&$objectHandler, $criteria=false, $actions=array('edit', 'delete'), $userSide=false) |
|
27 | - { |
|
28 | - $this->SmartObjectTable($objectHandler, $criteria, $actions, $userSide); |
|
29 | - $this->_isTree = true; |
|
30 | - } |
|
31 | - /** |
|
32 | - * Get children objects given a specific parentid |
|
33 | - * |
|
34 | - * @var int $parentid id of the parent which children we want to retreive |
|
35 | - * @return array of SmartObject |
|
36 | - */ |
|
37 | - function getChildrenOf($parentid=0) { |
|
38 | - return isset($this->_objects[$parentid]) ? $this->_objects[$parentid] : false; |
|
39 | - } |
|
40 | - |
|
41 | - function createTableRow($object, $level=0) { |
|
42 | - |
|
43 | - $aObject = array(); |
|
44 | - |
|
45 | - $i=0; |
|
46 | - |
|
47 | - $aColumns = array(); |
|
48 | - $doWeHaveActions = false; |
|
49 | - |
|
50 | - foreach ($this->_columns as $column) { |
|
51 | - |
|
52 | - $aColumn = array(); |
|
53 | - |
|
54 | - if ($i==0) { |
|
55 | - $class = "head"; |
|
56 | - } elseif ($i % 2 == 0) { |
|
57 | - $class = "even"; |
|
58 | - } else { |
|
59 | - $class = "odd"; |
|
60 | - } |
|
61 | - |
|
62 | - if ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
63 | - $method = $column->_customMethodForValue; |
|
64 | - $value = $object->$method(); |
|
65 | - } else { |
|
66 | - /** |
|
67 | - * If the column is the identifier, then put a link on it |
|
68 | - */ |
|
69 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
70 | - $value = $object->getItemLink(); |
|
71 | - } else { |
|
72 | - $value = $object->getVar($column->getKeyName()); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - $space = ''; |
|
77 | - if($column->getKeyName() == $this->_objectHandler->identifierName){ |
|
78 | - for ($i = 0; $i < $level; $i++) { |
|
79 | - $space = $space . '--'; |
|
80 | - } |
|
81 | - } |
|
82 | - |
|
83 | - if ($space != '') { |
|
84 | - $space .= ' '; |
|
85 | - } |
|
86 | - |
|
87 | - $aColumn['value'] = $space . $value; |
|
88 | - $aColumn['class'] = $class; |
|
89 | - $aColumn['width'] = $column->getWidth(); |
|
90 | - $aColumn['align'] = $column->getAlign(); |
|
91 | - $aColumn['key'] = $column->getKeyName(); |
|
92 | - |
|
93 | - $aColumns[] = $aColumn; |
|
94 | - $i++; |
|
95 | - } |
|
96 | - |
|
97 | - $aObject['columns'] = $aColumns; |
|
98 | - |
|
99 | - $class = $class == 'even' ? 'odd' : 'even'; |
|
100 | - $aObject['class'] = $class; |
|
101 | - |
|
102 | - $actions = array(); |
|
103 | - |
|
104 | - // Adding the custom actions if any |
|
105 | - foreach ($this->_custom_actions as $action) { |
|
106 | - if (method_exists($object, $action)) { |
|
107 | - $actions[] = $object->$action(); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - include_once SMARTOBJECT_ROOT_PATH . "class/smartobjectcontroller.php"; |
|
112 | - $controller = new SmartObjectController($this->_objectHandler); |
|
113 | - |
|
114 | - if (in_array('edit', $this->_actions)) { |
|
115 | - $actions[] = $controller->getEditItemLink($object, false, true); |
|
116 | - } |
|
117 | - if (in_array('delete', $this->_actions)) { |
|
118 | - $actions[] = $controller->getDeleteItemLink($object, false, true); |
|
119 | - } |
|
120 | - $aObject['actions'] = $actions; |
|
121 | - |
|
122 | - $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
123 | - $aObject['id'] = $object->id(); |
|
124 | - $this->_aObjects[] = $aObject; |
|
125 | - |
|
126 | - $childrenObjects = $this->getChildrenOf($object->id()); |
|
127 | - |
|
128 | - $this->_hasActions =$this->_hasActions ? true : count($actions) > 0; |
|
129 | - |
|
130 | - if ($childrenObjects) { |
|
131 | - $level++; |
|
132 | - foreach ($childrenObjects as $subObject) { |
|
133 | - $this->createTableRow($subObject, $level); |
|
134 | - } |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - function createTableRows() { |
|
139 | - $this->_aObjects = array(); |
|
140 | - |
|
141 | - if (count($this->_objects) > 0) { |
|
142 | - |
|
143 | - foreach ($this->getChildrenOf() as $object) { |
|
144 | - $this->createTableRow($object); |
|
145 | - } |
|
146 | - |
|
147 | - $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
148 | - } else { |
|
149 | - $colspan = count($this->_columns) + 1; |
|
150 | - $this->_tpl->assign('smartobject_colspan', $colspan); |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - function fetchObjects() { |
|
155 | - $ret = $this->_objectHandler->getObjects($this->_criteria, 'parentid'); |
|
156 | - return $ret; |
|
157 | - |
|
158 | - } |
|
26 | + function SmartObjectTreeTable(&$objectHandler, $criteria=false, $actions=array('edit', 'delete'), $userSide=false) |
|
27 | + { |
|
28 | + $this->SmartObjectTable($objectHandler, $criteria, $actions, $userSide); |
|
29 | + $this->_isTree = true; |
|
30 | + } |
|
31 | + /** |
|
32 | + * Get children objects given a specific parentid |
|
33 | + * |
|
34 | + * @var int $parentid id of the parent which children we want to retreive |
|
35 | + * @return array of SmartObject |
|
36 | + */ |
|
37 | + function getChildrenOf($parentid=0) { |
|
38 | + return isset($this->_objects[$parentid]) ? $this->_objects[$parentid] : false; |
|
39 | + } |
|
40 | + |
|
41 | + function createTableRow($object, $level=0) { |
|
42 | + |
|
43 | + $aObject = array(); |
|
44 | + |
|
45 | + $i=0; |
|
46 | + |
|
47 | + $aColumns = array(); |
|
48 | + $doWeHaveActions = false; |
|
49 | + |
|
50 | + foreach ($this->_columns as $column) { |
|
51 | + |
|
52 | + $aColumn = array(); |
|
53 | + |
|
54 | + if ($i==0) { |
|
55 | + $class = "head"; |
|
56 | + } elseif ($i % 2 == 0) { |
|
57 | + $class = "even"; |
|
58 | + } else { |
|
59 | + $class = "odd"; |
|
60 | + } |
|
61 | + |
|
62 | + if ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
63 | + $method = $column->_customMethodForValue; |
|
64 | + $value = $object->$method(); |
|
65 | + } else { |
|
66 | + /** |
|
67 | + * If the column is the identifier, then put a link on it |
|
68 | + */ |
|
69 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
70 | + $value = $object->getItemLink(); |
|
71 | + } else { |
|
72 | + $value = $object->getVar($column->getKeyName()); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + $space = ''; |
|
77 | + if($column->getKeyName() == $this->_objectHandler->identifierName){ |
|
78 | + for ($i = 0; $i < $level; $i++) { |
|
79 | + $space = $space . '--'; |
|
80 | + } |
|
81 | + } |
|
82 | + |
|
83 | + if ($space != '') { |
|
84 | + $space .= ' '; |
|
85 | + } |
|
86 | + |
|
87 | + $aColumn['value'] = $space . $value; |
|
88 | + $aColumn['class'] = $class; |
|
89 | + $aColumn['width'] = $column->getWidth(); |
|
90 | + $aColumn['align'] = $column->getAlign(); |
|
91 | + $aColumn['key'] = $column->getKeyName(); |
|
92 | + |
|
93 | + $aColumns[] = $aColumn; |
|
94 | + $i++; |
|
95 | + } |
|
96 | + |
|
97 | + $aObject['columns'] = $aColumns; |
|
98 | + |
|
99 | + $class = $class == 'even' ? 'odd' : 'even'; |
|
100 | + $aObject['class'] = $class; |
|
101 | + |
|
102 | + $actions = array(); |
|
103 | + |
|
104 | + // Adding the custom actions if any |
|
105 | + foreach ($this->_custom_actions as $action) { |
|
106 | + if (method_exists($object, $action)) { |
|
107 | + $actions[] = $object->$action(); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + include_once SMARTOBJECT_ROOT_PATH . "class/smartobjectcontroller.php"; |
|
112 | + $controller = new SmartObjectController($this->_objectHandler); |
|
113 | + |
|
114 | + if (in_array('edit', $this->_actions)) { |
|
115 | + $actions[] = $controller->getEditItemLink($object, false, true); |
|
116 | + } |
|
117 | + if (in_array('delete', $this->_actions)) { |
|
118 | + $actions[] = $controller->getDeleteItemLink($object, false, true); |
|
119 | + } |
|
120 | + $aObject['actions'] = $actions; |
|
121 | + |
|
122 | + $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
123 | + $aObject['id'] = $object->id(); |
|
124 | + $this->_aObjects[] = $aObject; |
|
125 | + |
|
126 | + $childrenObjects = $this->getChildrenOf($object->id()); |
|
127 | + |
|
128 | + $this->_hasActions =$this->_hasActions ? true : count($actions) > 0; |
|
129 | + |
|
130 | + if ($childrenObjects) { |
|
131 | + $level++; |
|
132 | + foreach ($childrenObjects as $subObject) { |
|
133 | + $this->createTableRow($subObject, $level); |
|
134 | + } |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + function createTableRows() { |
|
139 | + $this->_aObjects = array(); |
|
140 | + |
|
141 | + if (count($this->_objects) > 0) { |
|
142 | + |
|
143 | + foreach ($this->getChildrenOf() as $object) { |
|
144 | + $this->createTableRow($object); |
|
145 | + } |
|
146 | + |
|
147 | + $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
148 | + } else { |
|
149 | + $colspan = count($this->_columns) + 1; |
|
150 | + $this->_tpl->assign('smartobject_colspan', $colspan); |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + function fetchObjects() { |
|
155 | + $ret = $this->_objectHandler->getObjects($this->_criteria, 'parentid'); |
|
156 | + return $ret; |
|
157 | + |
|
158 | + } |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | ?> |
@@ -8,17 +8,17 @@ discard block |
||
8 | 8 | * Licence: GNU |
9 | 9 | */ |
10 | 10 | if (!defined("XOOPS_ROOT_PATH")) { |
11 | - die("XOOPS root path not defined"); |
|
11 | + die("XOOPS root path not defined"); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class SmartobjectPermissionHandler extends XoopsObjectHandler |
15 | 15 | { |
16 | - var $handler; |
|
17 | - function SmartObjectPermissionHandler($handler) { |
|
18 | - $this->handler=$handler; |
|
19 | - } |
|
16 | + var $handler; |
|
17 | + function SmartObjectPermissionHandler($handler) { |
|
18 | + $this->handler=$handler; |
|
19 | + } |
|
20 | 20 | |
21 | - /* |
|
21 | + /* |
|
22 | 22 | * Returns permissions for a certain type |
23 | 23 | * |
24 | 24 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -26,62 +26,62 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return array |
28 | 28 | */ |
29 | - function getGrantedGroups($gperm_name, $id = null) { |
|
30 | - static $groups; |
|
31 | - |
|
32 | - if (!isset($groups[$gperm_name]) || ($id != null && !isset($groups[$gperm_name][$id]))) { |
|
33 | - $smartModule =& $this->handler->getModuleInfo(); |
|
34 | - //Get group permissions handler |
|
35 | - $gperm_handler =& xoops_gethandler('groupperm'); |
|
36 | - |
|
37 | - //Get groups allowed for an item id |
|
38 | - $allowedgroups = $gperm_handler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
39 | - $groups[$gperm_name][$id] = $allowedgroups; |
|
40 | - } |
|
41 | - //Return the permission array |
|
42 | - return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : array(); |
|
43 | - } |
|
44 | - |
|
45 | - function getGrantedGroupsForIds($item_ids_array, $gperm_name=false) { |
|
46 | - |
|
47 | - static $groups; |
|
48 | - |
|
49 | - if ($gperm_name){ |
|
50 | - if (isset($groups[$gperm_name])) { |
|
51 | - return $groups[$gperm_name]; |
|
52 | - } |
|
53 | - } else { |
|
54 | - // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
55 | - return $groups; |
|
56 | - } |
|
57 | - |
|
58 | - $smartModule =& $this->handler->getModuleInfo(); |
|
59 | - |
|
60 | - $criteria = new CriteriaCompo(); |
|
61 | - $criteria->add(new Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
62 | - |
|
63 | - if ($gperm_name) { |
|
64 | - $criteria->add(new Criteria('gperm_name', $gperm_name)); |
|
65 | - } |
|
66 | - |
|
67 | - //Get group permissions handler |
|
68 | - $gperm_handler =& xoops_gethandler('groupperm'); |
|
69 | - |
|
70 | - $permissionsObj = $gperm_handler->getObjects($criteria); |
|
71 | - |
|
72 | - foreach ($permissionsObj as $permissionObj) { |
|
73 | - $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
74 | - } |
|
75 | - |
|
76 | - //Return the permission array |
|
77 | - if ($gperm_name) { |
|
78 | - return isset($groups[$gperm_name]) ? $groups[$gperm_name] : array(); |
|
79 | - } else { |
|
80 | - return isset($groups) ? $groups : array(); |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - /* |
|
29 | + function getGrantedGroups($gperm_name, $id = null) { |
|
30 | + static $groups; |
|
31 | + |
|
32 | + if (!isset($groups[$gperm_name]) || ($id != null && !isset($groups[$gperm_name][$id]))) { |
|
33 | + $smartModule =& $this->handler->getModuleInfo(); |
|
34 | + //Get group permissions handler |
|
35 | + $gperm_handler =& xoops_gethandler('groupperm'); |
|
36 | + |
|
37 | + //Get groups allowed for an item id |
|
38 | + $allowedgroups = $gperm_handler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
39 | + $groups[$gperm_name][$id] = $allowedgroups; |
|
40 | + } |
|
41 | + //Return the permission array |
|
42 | + return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : array(); |
|
43 | + } |
|
44 | + |
|
45 | + function getGrantedGroupsForIds($item_ids_array, $gperm_name=false) { |
|
46 | + |
|
47 | + static $groups; |
|
48 | + |
|
49 | + if ($gperm_name){ |
|
50 | + if (isset($groups[$gperm_name])) { |
|
51 | + return $groups[$gperm_name]; |
|
52 | + } |
|
53 | + } else { |
|
54 | + // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
55 | + return $groups; |
|
56 | + } |
|
57 | + |
|
58 | + $smartModule =& $this->handler->getModuleInfo(); |
|
59 | + |
|
60 | + $criteria = new CriteriaCompo(); |
|
61 | + $criteria->add(new Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
62 | + |
|
63 | + if ($gperm_name) { |
|
64 | + $criteria->add(new Criteria('gperm_name', $gperm_name)); |
|
65 | + } |
|
66 | + |
|
67 | + //Get group permissions handler |
|
68 | + $gperm_handler =& xoops_gethandler('groupperm'); |
|
69 | + |
|
70 | + $permissionsObj = $gperm_handler->getObjects($criteria); |
|
71 | + |
|
72 | + foreach ($permissionsObj as $permissionObj) { |
|
73 | + $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
74 | + } |
|
75 | + |
|
76 | + //Return the permission array |
|
77 | + if ($gperm_name) { |
|
78 | + return isset($groups[$gperm_name]) ? $groups[$gperm_name] : array(); |
|
79 | + } else { |
|
80 | + return isset($groups) ? $groups : array(); |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + /* |
|
85 | 85 | * Returns permissions for a certain type |
86 | 86 | * |
87 | 87 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -89,112 +89,112 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return array |
91 | 91 | */ |
92 | - function getGrantedItems($gperm_name, $id = null) { |
|
93 | - global $xoopsUser; |
|
94 | - static $permissions; |
|
95 | - |
|
96 | - if (!isset($permissions[$gperm_name]) || ($id != null && !isset($permissions[$gperm_name][$id]))) { |
|
97 | - |
|
98 | - $smartModule =& $this->handler->getModuleInfo(); |
|
99 | - |
|
100 | - if (is_object($smartModule)) { |
|
101 | - |
|
102 | - //Get group permissions handler |
|
103 | - $gperm_handler =& xoops_gethandler('groupperm'); |
|
104 | - |
|
105 | - //Get user's groups |
|
106 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
107 | - |
|
108 | - //Get all allowed item ids in this module and for this user's groups |
|
109 | - $userpermissions =& $gperm_handler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
110 | - $permissions[$gperm_name] = $userpermissions; |
|
111 | - } |
|
112 | - } |
|
113 | - //Return the permission array |
|
114 | - return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : array(); |
|
115 | - } |
|
116 | - |
|
117 | - function storeAllPermissionsForId($id) { |
|
118 | - foreach ($this->handler->getPermissions() as $permission) { |
|
119 | - $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Saves permissions for the selected category |
|
125 | - * |
|
126 | - * saveCategory_Permissions() |
|
127 | - * |
|
128 | - * @param array $groups : group with granted permission |
|
129 | - * @param integer $categoryID : categoryID on which we are setting permissions for Categories and Forums |
|
130 | - * @param string $perm_name : name of the permission |
|
131 | - * @return boolean : TRUE if the no errors occured |
|
132 | - **/ |
|
133 | - |
|
134 | - function saveItem_Permissions($groups, $itemid, $perm_name) |
|
135 | - { |
|
136 | - $smartModule =& $this->handler->getModuleInfo(); |
|
137 | - |
|
138 | - $result = true; |
|
139 | - $module_id = $smartModule->getVar('mid'); |
|
140 | - $gperm_handler =& xoops_gethandler('groupperm'); |
|
141 | - |
|
142 | - // First, if the permissions are already there, delete them |
|
143 | - $gperm_handler->deleteByModule($module_id, $perm_name, $itemid); |
|
144 | - //echo "itemid : $itemid - perm : $perm_name - modid : $module_id"; |
|
145 | - //exit; |
|
146 | - // Save the new permissions |
|
147 | - |
|
148 | - if (count($groups) > 0) { |
|
149 | - foreach ($groups as $group_id) { |
|
150 | - $gperm_handler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
151 | - } |
|
152 | - } |
|
153 | - return $result; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Delete all permission for a specific item |
|
158 | - * |
|
159 | - * deletePermissions() |
|
160 | - * |
|
161 | - * @param integer $itemid : id of the item for which to delete the permissions |
|
162 | - * @return boolean : TRUE if the no errors occured |
|
163 | - **/ |
|
164 | - function deletePermissions($itemid, $gperm_name) |
|
165 | - { |
|
166 | - global $xoopsModule; |
|
167 | - |
|
168 | - $smartModule =& smartsection_getModuleInfo(); |
|
169 | - |
|
170 | - $result = true; |
|
171 | - $module_id = $smartModule->getVar('mid') ; |
|
172 | - $gperm_handler =& xoops_gethandler('groupperm'); |
|
173 | - |
|
174 | - |
|
175 | - $gperm_handler->deleteByModule($module_id, $gperm_name, $itemid); |
|
176 | - |
|
177 | - return $result; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Checks if the user has access to a specific permission on a given object |
|
182 | - * |
|
183 | - * @param string $gperm_name name of the permission to test |
|
184 | - * @param int $gperm_itemid id of the object to check |
|
185 | - * @return boolean : TRUE if user has access, FALSE if not |
|
186 | - **/ |
|
187 | - function accessGranted($gperm_name, $gperm_itemid) { |
|
188 | - global $xoopsUser; |
|
189 | - |
|
190 | - $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
191 | - $smartModule =& $this->handler->getModuleInfo(); |
|
192 | - $gperm_modid = $smartModule->getVar('mid') ; |
|
193 | - |
|
194 | - //Get group permissions handler |
|
195 | - $gperm_handler =& xoops_gethandler('groupperm'); |
|
196 | - |
|
197 | - return $gperm_handler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
198 | - } |
|
92 | + function getGrantedItems($gperm_name, $id = null) { |
|
93 | + global $xoopsUser; |
|
94 | + static $permissions; |
|
95 | + |
|
96 | + if (!isset($permissions[$gperm_name]) || ($id != null && !isset($permissions[$gperm_name][$id]))) { |
|
97 | + |
|
98 | + $smartModule =& $this->handler->getModuleInfo(); |
|
99 | + |
|
100 | + if (is_object($smartModule)) { |
|
101 | + |
|
102 | + //Get group permissions handler |
|
103 | + $gperm_handler =& xoops_gethandler('groupperm'); |
|
104 | + |
|
105 | + //Get user's groups |
|
106 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
107 | + |
|
108 | + //Get all allowed item ids in this module and for this user's groups |
|
109 | + $userpermissions =& $gperm_handler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
110 | + $permissions[$gperm_name] = $userpermissions; |
|
111 | + } |
|
112 | + } |
|
113 | + //Return the permission array |
|
114 | + return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : array(); |
|
115 | + } |
|
116 | + |
|
117 | + function storeAllPermissionsForId($id) { |
|
118 | + foreach ($this->handler->getPermissions() as $permission) { |
|
119 | + $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Saves permissions for the selected category |
|
125 | + * |
|
126 | + * saveCategory_Permissions() |
|
127 | + * |
|
128 | + * @param array $groups : group with granted permission |
|
129 | + * @param integer $categoryID : categoryID on which we are setting permissions for Categories and Forums |
|
130 | + * @param string $perm_name : name of the permission |
|
131 | + * @return boolean : TRUE if the no errors occured |
|
132 | + **/ |
|
133 | + |
|
134 | + function saveItem_Permissions($groups, $itemid, $perm_name) |
|
135 | + { |
|
136 | + $smartModule =& $this->handler->getModuleInfo(); |
|
137 | + |
|
138 | + $result = true; |
|
139 | + $module_id = $smartModule->getVar('mid'); |
|
140 | + $gperm_handler =& xoops_gethandler('groupperm'); |
|
141 | + |
|
142 | + // First, if the permissions are already there, delete them |
|
143 | + $gperm_handler->deleteByModule($module_id, $perm_name, $itemid); |
|
144 | + //echo "itemid : $itemid - perm : $perm_name - modid : $module_id"; |
|
145 | + //exit; |
|
146 | + // Save the new permissions |
|
147 | + |
|
148 | + if (count($groups) > 0) { |
|
149 | + foreach ($groups as $group_id) { |
|
150 | + $gperm_handler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
151 | + } |
|
152 | + } |
|
153 | + return $result; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Delete all permission for a specific item |
|
158 | + * |
|
159 | + * deletePermissions() |
|
160 | + * |
|
161 | + * @param integer $itemid : id of the item for which to delete the permissions |
|
162 | + * @return boolean : TRUE if the no errors occured |
|
163 | + **/ |
|
164 | + function deletePermissions($itemid, $gperm_name) |
|
165 | + { |
|
166 | + global $xoopsModule; |
|
167 | + |
|
168 | + $smartModule =& smartsection_getModuleInfo(); |
|
169 | + |
|
170 | + $result = true; |
|
171 | + $module_id = $smartModule->getVar('mid') ; |
|
172 | + $gperm_handler =& xoops_gethandler('groupperm'); |
|
173 | + |
|
174 | + |
|
175 | + $gperm_handler->deleteByModule($module_id, $gperm_name, $itemid); |
|
176 | + |
|
177 | + return $result; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Checks if the user has access to a specific permission on a given object |
|
182 | + * |
|
183 | + * @param string $gperm_name name of the permission to test |
|
184 | + * @param int $gperm_itemid id of the object to check |
|
185 | + * @return boolean : TRUE if user has access, FALSE if not |
|
186 | + **/ |
|
187 | + function accessGranted($gperm_name, $gperm_itemid) { |
|
188 | + global $xoopsUser; |
|
189 | + |
|
190 | + $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
|
191 | + $smartModule =& $this->handler->getModuleInfo(); |
|
192 | + $gperm_modid = $smartModule->getVar('mid') ; |
|
193 | + |
|
194 | + //Get group permissions handler |
|
195 | + $gperm_handler =& xoops_gethandler('groupperm'); |
|
196 | + |
|
197 | + return $gperm_handler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
198 | + } |
|
199 | 199 | } |
200 | 200 | ?> |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | // -------------------------------------------------------------------------// |
29 | 29 | |
30 | 30 | if (!defined("XOOPS_ROOT_PATH")) { |
31 | - die("XOOPS root path not defined"); |
|
31 | + die("XOOPS root path not defined"); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | include_once XOOPS_ROOT_PATH."/modules/smartobject/class/smartobject.php"; |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | |
39 | 39 | var $_modulePlugin=false; |
40 | 40 | |
41 | - function SmartobjectRating() { |
|
42 | - $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
|
41 | + function SmartobjectRating() { |
|
42 | + $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
|
43 | 43 | $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
44 | 44 | $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_ITEM); |
45 | 45 | $this->quickInitVar('itemid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_ITEMID); |
@@ -49,47 +49,47 @@ discard block |
||
49 | 49 | |
50 | 50 | $this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_SOBJECT_RATING_NAME); |
51 | 51 | |
52 | - $this->setControl('dirname', array( |
|
53 | - 'handler' => 'rating', |
|
54 | - 'method' => 'getModuleList', |
|
52 | + $this->setControl('dirname', array( |
|
53 | + 'handler' => 'rating', |
|
54 | + 'method' => 'getModuleList', |
|
55 | 55 | 'onSelect' => 'submit')); |
56 | 56 | |
57 | - $this->setControl('item', array( |
|
58 | - 'object' => &$this, |
|
59 | - 'method' => 'getItemList')); |
|
57 | + $this->setControl('item', array( |
|
58 | + 'object' => &$this, |
|
59 | + 'method' => 'getItemList')); |
|
60 | 60 | |
61 | - $this->setControl('uid', 'user'); |
|
61 | + $this->setControl('uid', 'user'); |
|
62 | 62 | |
63 | - $this->setControl('rate', array( |
|
64 | - 'handler' => 'rating', |
|
65 | - 'method' => 'getRateList')); |
|
66 | - } |
|
63 | + $this->setControl('rate', array( |
|
64 | + 'handler' => 'rating', |
|
65 | + 'method' => 'getRateList')); |
|
66 | + } |
|
67 | 67 | |
68 | - function getVar($key, $format = 's') { |
|
69 | - if ($format == 's' && in_array($key, array('name', 'dirname'))) { |
|
70 | - return call_user_func(array($this,$key)); |
|
71 | - } |
|
72 | - return parent::getVar($key, $format); |
|
73 | - } |
|
68 | + function getVar($key, $format = 's') { |
|
69 | + if ($format == 's' && in_array($key, array('name', 'dirname'))) { |
|
70 | + return call_user_func(array($this,$key)); |
|
71 | + } |
|
72 | + return parent::getVar($key, $format); |
|
73 | + } |
|
74 | 74 | |
75 | - function name() { |
|
76 | - $ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, array()); |
|
75 | + function name() { |
|
76 | + $ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, array()); |
|
77 | 77 | |
78 | - return $ret; |
|
79 | - } |
|
78 | + return $ret; |
|
79 | + } |
|
80 | 80 | |
81 | - function dirname() { |
|
82 | - global $smartobject_rating_handler; |
|
83 | - $moduleArray = $smartobject_rating_handler->getModuleList(); |
|
84 | - return $moduleArray[$this->getVar('dirname', 'n')]; |
|
85 | - } |
|
81 | + function dirname() { |
|
82 | + global $smartobject_rating_handler; |
|
83 | + $moduleArray = $smartobject_rating_handler->getModuleList(); |
|
84 | + return $moduleArray[$this->getVar('dirname', 'n')]; |
|
85 | + } |
|
86 | 86 | |
87 | - function getItemList() { |
|
88 | - $plugin = $this->getModulePlugin(); |
|
89 | - return $plugin->getItemList(); |
|
90 | - } |
|
87 | + function getItemList() { |
|
88 | + $plugin = $this->getModulePlugin(); |
|
89 | + return $plugin->getItemList(); |
|
90 | + } |
|
91 | 91 | |
92 | - function getItemValue() { |
|
92 | + function getItemValue() { |
|
93 | 93 | $moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
94 | 94 | $plugin = $this->getModulePlugin(); |
95 | 95 | $pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
100 | 100 | $ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
101 | 101 | return $ret; |
102 | - } |
|
102 | + } |
|
103 | 103 | |
104 | - function getRateValue() { |
|
105 | - return $this->getVar('rate'); |
|
106 | - } |
|
104 | + function getRateValue() { |
|
105 | + return $this->getVar('rate'); |
|
106 | + } |
|
107 | 107 | |
108 | - function getModulePlugin() { |
|
108 | + function getModulePlugin() { |
|
109 | 109 | if (!$this->_modulePlugin) { |
110 | 110 | global $smartobject_rating_handler; |
111 | 111 | $this->_modulePlugin = $smartobject_rating_handler->pluginsObject->getPlugin($this->getVar('dirname', 'n')); |
112 | 112 | } |
113 | 113 | return $this->_modulePlugin; |
114 | - } |
|
114 | + } |
|
115 | 115 | } |
116 | 116 | class SmartobjectRatingHandler extends SmartPersistableObjectHandler { |
117 | 117 | |
@@ -119,18 +119,18 @@ discard block |
||
119 | 119 | var $_moduleList=false; |
120 | 120 | var $pluginsObject; |
121 | 121 | |
122 | - function SmartobjectRatingHandler($db) { |
|
123 | - $this->SmartPersistableObjectHandler($db, 'rating', 'ratingid', 'rate', '', 'smartobject'); |
|
122 | + function SmartobjectRatingHandler($db) { |
|
123 | + $this->SmartPersistableObjectHandler($db, 'rating', 'ratingid', 'rate', '', 'smartobject'); |
|
124 | 124 | $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid'; |
125 | 125 | |
126 | - $this->_rateOptions[1] = 1; |
|
127 | - $this->_rateOptions[2] = 2; |
|
128 | - $this->_rateOptions[3] = 3; |
|
129 | - $this->_rateOptions[4] = 4; |
|
130 | - $this->_rateOptions[5] = 5; |
|
126 | + $this->_rateOptions[1] = 1; |
|
127 | + $this->_rateOptions[2] = 2; |
|
128 | + $this->_rateOptions[3] = 3; |
|
129 | + $this->_rateOptions[4] = 4; |
|
130 | + $this->_rateOptions[5] = 5; |
|
131 | 131 | |
132 | - $this->pluginsObject = new SmartPluginHandler(); |
|
133 | - } |
|
132 | + $this->pluginsObject = new SmartPluginHandler(); |
|
133 | + } |
|
134 | 134 | |
135 | 135 | function getModuleList() { |
136 | 136 | if (!$this->_moduleList) { |
@@ -151,12 +151,12 @@ discard block |
||
151 | 151 | $sql = "SELECT AVG(rate), COUNT(ratingid) FROM " . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid"; |
152 | 152 | $result = $this->db->query($sql); |
153 | 153 | if (!$result) { |
154 | - return 0; |
|
155 | - } |
|
156 | - list($average, $sum) = $this->db->fetchRow($result); |
|
157 | - $ret['average'] = isset($average) ? $average : 0; |
|
158 | - $ret['sum'] = isset($sum) ? $sum : 0; |
|
159 | - return $ret; |
|
154 | + return 0; |
|
155 | + } |
|
156 | + list($average, $sum) = $this->db->fetchRow($result); |
|
157 | + $ret['average'] = isset($average) ? $average : 0; |
|
158 | + $ret['sum'] = isset($sum) ? $sum : 0; |
|
159 | + return $ret; |
|
160 | 160 | } |
161 | 161 | function already_rated($item, $itemid, $dirname, $uid){ |
162 | 162 |
@@ -158,16 +158,16 @@ |
||
158 | 158 | // Author's note |
159 | 159 | $this->_tpl->assign('module_author_word', $versioninfo->getInfo('author_word')); |
160 | 160 | |
161 | - // For changelog thanks to 3Dev |
|
162 | - global $xoopsModule; |
|
163 | - $filename = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/changelog.txt'; |
|
164 | - if(is_file($filename)){ |
|
165 | - |
|
166 | - $filesize = filesize($filename); |
|
167 | - $handle = fopen($filename, 'r'); |
|
168 | - $this->_tpl->assign('module_version_history', $myts->displayTarea(fread($handle, $filesize), true)); |
|
169 | - fclose($handle); |
|
170 | - } |
|
161 | + // For changelog thanks to 3Dev |
|
162 | + global $xoopsModule; |
|
163 | + $filename = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/changelog.txt'; |
|
164 | + if(is_file($filename)){ |
|
165 | + |
|
166 | + $filesize = filesize($filename); |
|
167 | + $handle = fopen($filename, 'r'); |
|
168 | + $this->_tpl->assign('module_version_history', $myts->displayTarea(fread($handle, $filesize), true)); |
|
169 | + fclose($handle); |
|
170 | + } |
|
171 | 171 | |
172 | 172 | $this->_tpl->display( 'db:smartobject_about.html' ); |
173 | 173 |
@@ -246,37 +246,37 @@ |
||
246 | 246 | trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
247 | 247 | } else { |
248 | 248 | $mimeType = 'text/csv'; |
249 | - $file = strrev($this->filename); |
|
250 | - $temp_name = strtolower(strrev(substr($file,0,strpos($file,"--"))) ); |
|
249 | + $file = strrev($this->filename); |
|
250 | + $temp_name = strtolower(strrev(substr($file,0,strpos($file,"--"))) ); |
|
251 | 251 | if ($temp_name == '') { |
252 | 252 | $file_name = $this->filename; |
253 | 253 | } else { |
254 | 254 | $file_name = $temp_name; |
255 | 255 | } |
256 | - $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
256 | + $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
257 | 257 | |
258 | - if(ini_get('zlib.output_compression')) { |
|
259 | - ini_set('zlib.output_compression', 'Off'); |
|
260 | - } |
|
258 | + if(ini_get('zlib.output_compression')) { |
|
259 | + ini_set('zlib.output_compression', 'Off'); |
|
260 | + } |
|
261 | 261 | |
262 | - header("Pragma: public"); |
|
263 | - header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); |
|
264 | - header("Cache-Control: private",false); |
|
265 | - header("Content-Transfer-Encoding: binary"); |
|
266 | - if(isset($mimeType)) { |
|
267 | - header("Content-Type: " . $mimeType); |
|
268 | - } |
|
262 | + header("Pragma: public"); |
|
263 | + header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); |
|
264 | + header("Cache-Control: private",false); |
|
265 | + header("Content-Transfer-Encoding: binary"); |
|
266 | + if(isset($mimeType)) { |
|
267 | + header("Content-Type: " . $mimeType); |
|
268 | + } |
|
269 | 269 | |
270 | - header("Content-Disposition: attachment; filename=" . $file_name); |
|
270 | + header("Content-Disposition: attachment; filename=" . $file_name); |
|
271 | 271 | |
272 | - if(isset($mimeType) && strstr($mimeType, "text/")) { |
|
273 | - $fp = fopen($fullFileName, "r"); |
|
274 | - } |
|
275 | - else { |
|
276 | - $fp = fopen($fullFileName, "rb"); |
|
277 | - } |
|
278 | - fpassthru($fp); |
|
279 | - exit(); |
|
272 | + if(isset($mimeType) && strstr($mimeType, "text/")) { |
|
273 | + $fp = fopen($fullFileName, "r"); |
|
274 | + } |
|
275 | + else { |
|
276 | + $fp = fopen($fullFileName, "rb"); |
|
277 | + } |
|
278 | + fpassthru($fp); |
|
279 | + exit(); |
|
280 | 280 | } |
281 | 281 | fclose($handle); |
282 | 282 | } |
@@ -6,7 +6,6 @@ discard block |
||
6 | 6 | * @license GNU |
7 | 7 | * @author marcan <[email protected]> |
8 | 8 | * @version $Id: smartobjectcategory.php 799 2008-02-04 22:14:27Z malanciault $ |
9 | - |
|
10 | 9 | * @link http://smartfactory.ca The SmartFactory |
11 | 10 | * @package SmartObject |
12 | 11 | * @subpackage SmartObjectItems |
@@ -21,74 +20,74 @@ discard block |
||
21 | 20 | var $_categoryPath; |
22 | 21 | |
23 | 22 | function SmartobjectCategory() { |
24 | - $this->initVar('categoryid', XOBJ_DTYPE_INT, '', true); |
|
25 | - $this->initVar('parentid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_CATEGORY_PARENTID, _CO_SOBJECT_CATEGORY_PARENTID_DSC); |
|
26 | - $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_NAME, _CO_SOBJECT_CATEGORY_NAME_DSC); |
|
27 | - $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SOBJECT_CATEGORY_DESCRIPTION, _CO_SOBJECT_CATEGORY_DESCRIPTION_DSC); |
|
28 | - $this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_IMAGE, _CO_SOBJECT_CATEGORY_IMAGE_DSC); |
|
29 | - |
|
30 | - $this->initCommonVar('doxcode'); |
|
31 | - |
|
32 | - $this->setControl('image', array('name' => 'image')); |
|
33 | - $this->setControl('parentid', array('name' => 'parentcategory')); |
|
34 | - $this->setControl('description', array('name' => 'textarea', |
|
35 | - 'itemHandler' => false, |
|
36 | - 'method' => false, |
|
37 | - 'module' => false, |
|
38 | - 'form_editor' => 'default')); |
|
39 | - |
|
40 | - // call parent constructor to get SEO fields initiated |
|
41 | - $this->SmartSeoObject(); |
|
23 | + $this->initVar('categoryid', XOBJ_DTYPE_INT, '', true); |
|
24 | + $this->initVar('parentid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_CATEGORY_PARENTID, _CO_SOBJECT_CATEGORY_PARENTID_DSC); |
|
25 | + $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_NAME, _CO_SOBJECT_CATEGORY_NAME_DSC); |
|
26 | + $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SOBJECT_CATEGORY_DESCRIPTION, _CO_SOBJECT_CATEGORY_DESCRIPTION_DSC); |
|
27 | + $this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_IMAGE, _CO_SOBJECT_CATEGORY_IMAGE_DSC); |
|
28 | + |
|
29 | + $this->initCommonVar('doxcode'); |
|
30 | + |
|
31 | + $this->setControl('image', array('name' => 'image')); |
|
32 | + $this->setControl('parentid', array('name' => 'parentcategory')); |
|
33 | + $this->setControl('description', array('name' => 'textarea', |
|
34 | + 'itemHandler' => false, |
|
35 | + 'method' => false, |
|
36 | + 'module' => false, |
|
37 | + 'form_editor' => 'default')); |
|
38 | + |
|
39 | + // call parent constructor to get SEO fields initiated |
|
40 | + $this->SmartSeoObject(); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * returns a specific variable for the object in a proper format |
|
45 | + * |
|
46 | + * @access public |
|
47 | + * @param string $key key of the object's variable to be returned |
|
48 | + * @param string $format format to use for the output |
|
49 | + * @return mixed formatted value of the variable |
|
50 | + */ |
|
51 | + function getVar($key, $format = 's') { |
|
52 | + if ($format == 's' && in_array($key, array('description', 'image'))) { |
|
53 | + return call_user_func(array($this,$key)); |
|
54 | + } |
|
55 | + return parent::getVar($key, $format); |
|
56 | + } |
|
57 | + |
|
58 | + function description() { |
|
59 | + return $this->getValueFor('description', false); |
|
60 | + } |
|
61 | + |
|
62 | + function image() { |
|
63 | + $ret = $this->getVar('image', 'e'); |
|
64 | + if ($ret == '-1') { |
|
65 | + return false; |
|
66 | + } else { |
|
67 | + return $ret; |
|
68 | + } |
|
42 | 69 | } |
43 | 70 | |
44 | - /** |
|
45 | - * returns a specific variable for the object in a proper format |
|
46 | - * |
|
47 | - * @access public |
|
48 | - * @param string $key key of the object's variable to be returned |
|
49 | - * @param string $format format to use for the output |
|
50 | - * @return mixed formatted value of the variable |
|
51 | - */ |
|
52 | - function getVar($key, $format = 's') { |
|
53 | - if ($format == 's' && in_array($key, array('description', 'image'))) { |
|
54 | - return call_user_func(array($this,$key)); |
|
55 | - } |
|
56 | - return parent::getVar($key, $format); |
|
57 | - } |
|
58 | - |
|
59 | - function description() { |
|
60 | - return $this->getValueFor('description', false); |
|
61 | - } |
|
62 | - |
|
63 | - function image() { |
|
64 | - $ret = $this->getVar('image', 'e'); |
|
65 | - if ($ret == '-1') { |
|
66 | - return false; |
|
67 | - } else { |
|
68 | - return $ret; |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - function toArray() { |
|
73 | - $this->setVar('doxcode', true); |
|
74 | - global $myts; |
|
75 | - $objectArray = parent::toArray(); |
|
76 | - if ($objectArray['image']) { |
|
77 | - $objectArray['image'] = $this->getImageDir() . $objectArray['image']; |
|
78 | - } |
|
79 | - return $objectArray; |
|
80 | - } |
|
81 | - /** |
|
82 | - * Create the complete path of a category |
|
83 | - * |
|
84 | - * @todo this could be improved as it uses multiple queries |
|
85 | - * @param bool $withAllLink make all name clickable |
|
86 | - * @return string complete path (breadcrumb) |
|
87 | - */ |
|
71 | + function toArray() { |
|
72 | + $this->setVar('doxcode', true); |
|
73 | + global $myts; |
|
74 | + $objectArray = parent::toArray(); |
|
75 | + if ($objectArray['image']) { |
|
76 | + $objectArray['image'] = $this->getImageDir() . $objectArray['image']; |
|
77 | + } |
|
78 | + return $objectArray; |
|
79 | + } |
|
80 | + /** |
|
81 | + * Create the complete path of a category |
|
82 | + * |
|
83 | + * @todo this could be improved as it uses multiple queries |
|
84 | + * @param bool $withAllLink make all name clickable |
|
85 | + * @return string complete path (breadcrumb) |
|
86 | + */ |
|
88 | 87 | function getCategoryPath($withAllLink=true, $currentCategory=false) { |
89 | 88 | |
90 | 89 | include_once SMARTOBJECT_ROOT_PATH . "class/smartobjectcontroller.php"; |
91 | - $controller = new SmartObjectController($this->handler); |
|
90 | + $controller = new SmartObjectController($this->handler); |
|
92 | 91 | |
93 | 92 | if (!$this->_categoryPath) { |
94 | 93 | if ($withAllLink && !$currentCategory) { |
@@ -107,7 +106,7 @@ discard block |
||
107 | 106 | $ret = $parentObj->getCategoryPath($withAllLink, $currentCategory) . " > " .$ret; |
108 | 107 | } |
109 | 108 | $this->_categoryPath = $ret; |
110 | - } |
|
109 | + } |
|
111 | 110 | |
112 | 111 | return $this->_categoryPath; |
113 | 112 | } |
@@ -119,9 +118,9 @@ discard block |
||
119 | 118 | var $allCategoriesObj = false; |
120 | 119 | var $_allCategoriesId = false; |
121 | 120 | |
122 | - function SmartobjectCategoryHandler($db, $modulename) { |
|
123 | - $this->SmartPersistableObjectHandler($db, 'category', 'categoryid', 'name', 'description', $modulename); |
|
124 | - } |
|
121 | + function SmartobjectCategoryHandler($db, $modulename) { |
|
122 | + $this->SmartPersistableObjectHandler($db, 'category', 'categoryid', 'name', 'description', $modulename); |
|
123 | + } |
|
125 | 124 | |
126 | 125 | function getAllCategoriesArray($parentid=0, $perm_name=false, $sort = 'parentid', $order='ASC') { |
127 | 126 | |
@@ -158,18 +157,18 @@ discard block |
||
158 | 157 | |
159 | 158 | if (!$this->allCategoriesId) { |
160 | 159 | |
161 | - $ret = array(); |
|
162 | - $sql = 'SELECT categoryid, parentid FROM '.$this->table . " AS " . $this->_itemname . ' ORDER BY parentid'; |
|
160 | + $ret = array(); |
|
161 | + $sql = 'SELECT categoryid, parentid FROM '.$this->table . " AS " . $this->_itemname . ' ORDER BY parentid'; |
|
163 | 162 | |
164 | - $result = $this->db->query($sql); |
|
163 | + $result = $this->db->query($sql); |
|
165 | 164 | |
166 | - if (!$result) { |
|
167 | - return $ret; |
|
168 | - } |
|
165 | + if (!$result) { |
|
166 | + return $ret; |
|
167 | + } |
|
169 | 168 | |
170 | - while ($myrow = $this->db->fetchArray($result)) { |
|
171 | - $this->allCategoriesId[$myrow['categoryid']] = $myrow['parentid']; |
|
172 | - } |
|
169 | + while ($myrow = $this->db->fetchArray($result)) { |
|
170 | + $this->allCategoriesId[$myrow['categoryid']] = $myrow['parentid']; |
|
171 | + } |
|
173 | 172 | } |
174 | 173 | |
175 | 174 | $retArray = array($parentid); |