Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 class Html_Table
00027 {
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 static function sql2table($cn,$a_col,$sql,$table_style='class="result"',$a_sql_var=null)
00076 {
00077 $r='';
00078 $r=sprintf('<table %s>',$table_style);
00079 $r.='<tr>';
00080 for ( $i=0;$i <count($a_col);$i++)
00081 {
00082 $content=h($a_col[$i]['name']);
00083 $style=(isset($a_col[$i]['style']))?$a_col[$i]['style']:"";
00084 if ( isset($a_col[$i]['image']) && $a_col[$i]['image'] != '')
00085 {
00086 $content=sprintf('<img src="%s" border="0"></img>%s',$a_col[$i]['image'],$content);
00087 }
00088 if ( isset($a_col[$i]['link']) )
00089 {
00090 $content=sprintf('<a href="%s">%s</a>',
00091 $a_col[$i]['link'],
00092 $content);
00093 $r.="<th $style>$content</th>";
00094 }
00095 else
00096 $r.= "<th $style>". h($content)."</th>";
00097 }
00098 $r.='</tr>';
00099 $ret=$cn->exec_sql($sql,$a_sql_var);
00100 for ($i=0;$i<Database::num_row($ret);$i++)
00101 {
00102 $r.='<tr>';
00103 $row=Database::fetch_row($ret,$i);
00104 for ($e=0;$e<count($row);$e++)
00105 {
00106 $style='';$content=h($row[$e]);
00107
00108 if ( isset($a_col[$e]['style']) )
00109 $style=$a_col[$e]['style'];
00110 if ( isset ($a_col[$e]['raw']))
00111 $r.='<td $style>'.$row[$e].'</td>';
00112 else
00113 $r.=td($content,$style);
00114 }
00115 $r.='</tr>';
00116 }
00117 $r.='</table>';
00118 return $r;
00119 }
00120 static function test_me()
00121 {
00122 $cn=new Database(Dossier::id());
00123 $order=" order by f_id desc ";
00124 $url=HtmlInput::get_to_string(array("gDossier","test_select"));
00125
00126 if ( isset($_GET['sb']))
00127 {
00128 $order=" order by f_id";
00129 $img="image/select1.gif";
00130 }
00131 else
00132 {
00133 $url=$url."&sb=as";
00134 $img="image/select2.gif";
00135 }
00136 $sql="select f_id,name,quick_code from vw_client $order limit 10";
00137 echo $sql;
00138
00139
00140 echo Html_Table::sql2table($cn,
00141 array(
00142 array('name'=>'N° de fiche',
00143 'style'=>'text-align:right',
00144 'link'=>$url,
00145 'image'=>$img),
00146 array('name'=>'Nom',
00147 'style'=>'text-align:right'),
00148 array('name'=>'QuickCode')
00149 )
00150 ,
00151 $sql
00152 );
00153 }
00154 }