1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
<?php
namespace Bitweaver\Plugins;
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Experimental work not finished yet
* An attempt to componentize all tables showing query results
* Usage:
* {querytable
* table ="" (Table or tables, example wiki_pages,users)
* template = "" (Template to be used for table rows, put them in templates/tables)
*
* where = "" (Where condition for the query)
* columns="col1,col2,col3" (Columns to be selected from the query, default = *)
* colalign="left,center,right" (Alignement for columns you can also use the template for this)
* sort_column = "col2" (Column to sort the data initially)
* sort_order = "desc" (Sort order)
* max_rows = "10" (Max number of rows to display per page)
* height = "" (Height for the table area)
* directpagination = "0" (Use directlinks to pages)
* combopagination = "0" (Use a combo to directly jump to a page)
* tableclass = "normal" (CSS class name for the table)
* columnheadingclass = "normal" (CSS class name for the columnheadings)
* oddrowclass = "odd"
* evenrowclass = "even"
* }
*/
//SECURITY HERE!
function smarty_function_querytable($params, &$gBitSmarty) {
global $gBitSystem;
extract($params);
//Security here
$arguments = ['table','template','tableclass','where',
'columns','height',
'sort_column','sort_order','colalign','columnheadingclass',
'max_rows','offset','total','directpagination',
'combopagination', ];
if(!isset($table)) {return "Table is a mandatory argument to querytable plugin!";}
if(!isset($template)) {return "Template is a mandatory argument to querytable plugin!";}
if(!isset($tableclass)) $tableclass='normal';
if(!isset($oddrowclass)) $oddrowclass="odd";
if(!isset($where)) $where="";
if(!isset($evenrowclass)) $evenrowclass="even";
if(!isset($columns)) $columns='*';
if(!isset($height)) $height=400;
if(!isset($directpagination)) $directpagination=0;
if(!isset($combopagination)) $combopagination=0;
if(!isset($max_rows)) $max_rows = 20;
if(!isset($offset)) $offset = 0;
if(!isset($total)) $total = 0;
if(!isset($sort_column)) $sort_column='';
if(!isset($sort_order)) $sort_order='';
if(!isset($colalign)) $colalign='left';
if(!isset($columnheadingclass)) $columnheadingclass='heading';
$columns = urlencode($columns);
$output = "<iframe marginwidth='4px' marginheight='4px' width='100%' height='$height' frameborder='0' scrolling='auto' src='querytable.php?f=1";
foreach($arguments as $arg) {
$val = $$arg;
$output.="&$arg=$val";
}
$output.="'></iframe>";
return $output;
}
|