altocompta/include/class_html_table.php
Dany De Bontridder 6da972d46a Merged revisions 4162-4170 via svnmerge from
svn+ssh://danydb@svn/svn/phpcompta/branches/rel560

........
  r4162 | danydb | 2011-06-11 02:14:22 +0200 (Sat, 11 Jun 2011) | 1 line
  
  Fix bug 
........
  r4163 | danydb | 2011-06-11 02:15:52 +0200 (Sat, 11 Jun 2011) | 1 line
  
  Improve creation of php script
........
  r4164 | danydb | 2011-06-14 18:36:48 +0200 (Tue, 14 Jun 2011) | 1 line
  
  Align numeric to right
........
  r4165 | danydb | 2011-06-17 21:55:06 +0200 (Fri, 17 Jun 2011) | 1 line
  
  0000297: Bug dans contact
........
  r4166 | danydb | 2011-06-17 22:26:23 +0200 (Fri, 17 Jun 2011) | 1 line
  
  0000296: Calcul automatique fiche
........
  r4167 | danydb | 2011-06-17 22:49:53 +0200 (Fri, 17 Jun 2011) | 2 lines
  
  fix bug if not plan proposed
........
  r4168 | danydb | 2011-06-17 22:57:29 +0200 (Fri, 17 Jun 2011) | 3 lines
  
  0000305: Charge au crédit
  
  new sql script
........
  r4169 | danydb | 2011-06-17 23:27:27 +0200 (Fri, 17 Jun 2011) | 1 line
  
  remove useless psql function public.account_insert
........
  r4170 | danydb | 2011-06-18 03:04:28 +0200 (Sat, 18 Jun 2011) | 1 line
  
  Update style
........
2011-06-28 21:10:26 +00:00

153 lines
No EOL
3.9 KiB
PHP

<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/*!\file
* \brief contains HTML features
*/
class Html_Table
{
/**
* Receives a SQL command and returns a string with the HTML code
* to display it as a table.
* Simple table without any feature (link in certain cell, sort,...)
* @param $cn database object
* @param $a_col header of the column it is an array of array
* indexes are link, name,image, style
* @param $sql query to execute
* @param $table_style style of the table
* @parm $a_sql_var array variable for the $sql DEFAULT NULL
@code
static function test_me()
{
$cn=new Database(Dossier::id());
$order=" order by f_id desc ";
$url=HtmlInput::get_to_string(array("gDossier","test_select"));
if ( isset($_GET['sb']))
{
$order=" order by f_id";
$img="image/select1.gif";
}
else
{
$url=$url."&sb=as";
$img="image/select2.gif";
}
$sql="select f_id,name,quick_code from vw_client $order limit 10";
echo $sql;
echo Html_Table::sql2table($cn,
array(
array('name'=>'N° de fiche',
'style'=>'text-align:right',
'link'=>$url,
'image'=>$img),
array('name'=>'Nom',
'style'=>'text-align:right'),
array('name'=>'QuickCode')
)
,
$sql
);
}
@endcode
*/
static function sql2table($cn,$a_col,$sql,$table_style='class="result"',$a_sql_var=null)
{
$r='';
$r=sprintf('<table %s>',$table_style);
$r.='<tr>';
for ( $i=0;$i <count($a_col);$i++)
{
$content=h($a_col[$i]['name']);
if ( isset($a_col[$i]['image']) && $a_col[$i]['image'] != '')
{
$content=sprintf('<img src="%s" border="0"></img>%s',$a_col[$i]['image'],$content);
}
if ( isset($a_col[$i]['link']) )
{
$content=sprintf('<a href="%s">%s</a>',
$a_col[$i]['link'],
$content);
$r.="<th>$content</th>";
}
else
$r.= th($content);
}
$r.='</tr>';
$ret=$cn->exec_sql($sql,$a_sql_var);
for ($i=0;$i<Database::num_row($ret);$i++)
{
$r.='<tr>';
$row=Database::fetch_row($ret,$i);
for ($e=0;$e<count($row);$e++)
{
$style='';$content=h($row[$e]);
if ( isset($a_col[$e]['style']) )
$style=sprintf('style="%s"',$a_col[$e]['style']);
$r.=td($content,$style);
}
$r.='</tr>';
}
$r.='</table>';
return $r;
}
static function test_me()
{
$cn=new Database(Dossier::id());
$order=" order by f_id desc ";
$url=HtmlInput::get_to_string(array("gDossier","test_select"));
if ( isset($_GET['sb']))
{
$order=" order by f_id";
$img="image/select1.gif";
}
else
{
$url=$url."&sb=as";
$img="image/select2.gif";
}
$sql="select f_id,name,quick_code from vw_client $order limit 10";
echo $sql;
echo Html_Table::sql2table($cn,
array(
array('name'=>'N° de fiche',
'style'=>'text-align:right',
'link'=>$url,
'image'=>$img),
array('name'=>'Nom',
'style'=>'text-align:right'),
array('name'=>'QuickCode')
)
,
$sql
);
}
}