noalyss Version-9
html_table.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief contains HTML features
24 */
25/*!
26 * \class Html_Table
27 * \brief contains HTML features
28 */
29
31{
32 /**
33 * @brief Receives a SQL command and returns a string with the HTML code
34 * to display it as a table.
35 * Simple table without any feature (link in certain cell, sort,...)
36 * @param $cn database object
37 * @param $a_col header of the column it is an array of array
38 * indexes are link, name,image, style
39 * @param $sql query to execute
40 * @param $table_style style of the table
41 * @parm $a_sql_var array variable for the $sql DEFAULT NULL
42@code
43 static function test_me()
44 {
45 $cn=Dossier::connect();
46 $order=" order by f_id desc ";
47 $url=HtmlInput::get_to_string(array("gDossier","test_select"));
48
49 if ( isset($_GET['sb']))
50 {
51 $order=" order by f_id";
52 $img="image/select1.gif";
53 }
54 else
55 {
56 $url=$url."&sb=as";
57 $img="image/select2.gif";
58 }
59 $sql="select f_id,name,quick_code from vw_client $order limit 10";
60 echo $sql;
61
62
63 echo Html_Table::sql2table($cn,
64 array(
65 array('name'=>'N° de fiche',
66 'style'=>'text-align:right',
67 'link'=>$url,
68 'image'=>$img),
69 array('name'=>'Nom',
70 'style'=>'text-align:right'),
71 array('name'=>'QuickCode')
72 )
73 ,
74 $sql
75 );
76 }
77@endcode
78 */
79 static function sql2table($cn,$a_col,$sql,$table_style='class="result"',$a_sql_var=null)
80 {
81 $r='';
82 $r=sprintf('<table %s>',$table_style);
83 $r.='<tr>';
84 for ( $i=0;$i <count($a_col);$i++)
85 {
86 $content=h($a_col[$i]['name']);
87 $style=(isset($a_col[$i]['style']))?$a_col[$i]['style']:"";
88 if ( isset($a_col[$i]['image']) && $a_col[$i]['image'] != '')
89 {
90 $content=sprintf('<img src="%s" border="0"></img>%s',$a_col[$i]['image'],$content);
91 }
92 if ( isset($a_col[$i]['link']) )
93 {
94 $content=sprintf('<a href="%s">%s</a>',
95 $a_col[$i]['link'],
96 $content);
97 $r.="<th $style>$content</th>";
98 }
99 else
100 $r.= "<th $style>". h($content)."</th>";
101 }
102 $r.='</tr>';
103 $ret=$cn->exec_sql($sql,$a_sql_var);
104 for ($i=0;$i<Database::num_row($ret);$i++)
105 {
106 $r.='<tr>';
108 for ($e=0;$e<count($row);$e++)
109 {
110 $style='';$content=h($row[$e]);
111
112 if ( isset($a_col[$e]['style']) )
113 $style=$a_col[$e]['style'];
114 if ( isset ($a_col[$e]['raw']))
115 $r.='<td $style>'.$row[$e].'</td>';
116 else
118 }
119 $r.='</tr>';
120 }
121 $r.='</table>';
122 return $r;
123 }
124 static function test_me()
125 {
127 $order=" order by f_id desc ";
128 $url=HtmlInput::get_to_string(array("gDossier","test_select"));
129
130 if ( isset($_GET['sb']))
131 {
132 $order=" order by f_id";
133 $img="image/select1.gif";
134 }
135 else
136 {
137 $url=$url."&sb=as";
138 $img="image/select2.gif";
139 }
140 $sql="select f_id,name,quick_code from vw_client $order limit 10";
141 echo $sql;
142
143
145 array(
146 array('name'=>'N° de fiche',
147 'style'=>'text-align:right',
148 'link'=>$url,
149 'image'=>$img),
150 array('name'=>'Nom',
151 'style'=>'text-align:right'),
152 array('name'=>'QuickCode')
153 )
154 ,
155 $sql
156 );
157 }
158}
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
h( $row[ 'oa_description'])
$url
$_GET['qcode']
static fetch_row($ret, $p_row)
wrapper for the function pg_fetch_row
static num_row($ret)
wrapper for the function pg_num_rows
static connect()
contains HTML features
static sql2table($cn, $a_col, $sql, $table_style='class="result"', $a_sql_var=null)
static test_me()
static get_to_string($array, $start="?")
transform $_GET data to string
$img
$content
Definition: xml.php:17