noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_html_table.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*!\file
00023  * \brief contains HTML features
00024  */
00025 
00026 class Html_Table
00027 {
00028   /**
00029    * Receives a SQL command and returns a string with the HTML code
00030    * to display it as a table.
00031    * Simple table without any feature (link in certain cell, sort,...)
00032    * @param $cn database object
00033    * @param $a_col header of the column it is an array of array
00034    *        indexes are link, name,image, style
00035    * @param $sql query to execute
00036    * @param $table_style style of the table
00037    * @parm $a_sql_var array variable for the $sql DEFAULT NULL
00038 @code
00039  static function test_me()
00040   {
00041     $cn=new Database(Dossier::id());
00042     $order=" order by f_id desc ";
00043     $url=HtmlInput::get_to_string(array("gDossier","test_select"));
00044 
00045     if ( isset($_GET['sb']))
00046       {
00047         $order=" order by f_id";
00048         $img="image/select1.gif";
00049       }
00050     else
00051       {
00052         $url=$url."&sb=as";
00053         $img="image/select2.gif";
00054       }
00055     $sql="select f_id,name,quick_code from vw_client  $order limit 10";
00056     echo $sql;
00057 
00058 
00059     echo Html_Table::sql2table($cn,
00060                                array(
00061                                      array('name'=>'N° de fiche',
00062                                            'style'=>'text-align:right',
00063                                            'link'=>$url,
00064                                            'image'=>$img),
00065                                      array('name'=>'Nom',
00066                                            'style'=>'text-align:right'),
00067                                      array('name'=>'QuickCode')
00068                                      )
00069                                ,
00070                                $sql
00071                                );
00072   }
00073 @endcode
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 }
 All Data Structures Namespaces Files Functions Variables Enumerations