|
[php]
<?php
/*
本程序由陈刚在John Lim的tohtml.inc.php基础上改写;
V0.01 16 MAY 2005 (c)
以下是tohtml.inc.php的版权信息,请您在使用或改写本程序时予以注明;
V4.52 10 Aug 2004 (c)
2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
Some pretty-printing by Chris Oxenreider <oxenreid@state.net>
关于本程序的版权申明
本程序基于BSD协议。
作者联系方式:cg19700105@yahoo.com.cn
*/
/// specific code for tohtml;
GLOBAL $gSQLMaxRows,$gSQLBlockRows;
$gSQLMaxRows = 1000; // max no of rows to download
$gSQLBlockRows=20; // max no of rows per table block
// RecordSet to HTML Table
function rs2html(&$rs,$edit,$askpage,$ppage,$ztabhtml=false,$zheaderarray=false,$htmlspecialchars=true,$echo = true)
{
$s ='';$rows=0;$docnt = false;
$lengthedit=($edit)?sizeof($edit):0;
GLOBAL $gSQLMaxRows,$gSQLBlockRows;
if (!$rs)
{
printf(ADODB_BAD_RS,'rs2html');
return false;
}
if (! $ztabhtml) $ztabhtml = "BORDER='1' WIDTH='98%'";
//else $docnt = true;
$typearr = array();
//$ncols = $rs->FieldCount();
$ncolss = $rs->FieldCount();
$ncols =$lengthedit+$ncolss-1;
$hdr = "<form method=\"post\" enctype=\"multipart/form-data\">";
$hdr .= "<TABLE COLS=$ncols $ztabhtml><tr>\n\n";
for ($i=0; $i < $ncols+1; $i++)
{
$field = $rs->FetchField($i);
if ($zheaderarray) $fname = $zheaderarray[$i];
else $fname = htmlspecialchars($field->name);
$typearr[$i] = $rs->MetaType($field->type,$field->max_length);
//print " $field->name $field->type $typearr[$i] ";
if (strlen($fname)==0) $fname = ' ';
$hdr .= "<TH>$fname</TH>";
}
$hdr .= "\n</tr>";
if ($echo) print $hdr."\n\n";
else $html = $hdr;
// smart algorithm - handles ADODB_FETCH_MODE's correctly by probing...
$numoffset = isset($rs->fields[0]) ||isset($rs->fields[1]) || isset($rs->fields[2]);
while (!$rs->EOF)
{$num=($askpage-1)*$ppage+$rows+1;
$s .= "<TR valign=top>\n";
$s .= " <TD width=2 align=right><input size=2 type='checkbox' name=bz".$num." value=".$rs->fields[0] ." ></TD>\n";
for ($i=1; $i < $ncolss; $i++)
{if ($i===0) $v=($numoffset) ? $rs->fields[0] : reset($rs->fields);
else $v = ($numoffset) ? $rs->fields[$i] : next($rs->fields);
$type = $typearr[$i];
switch($type)
{case 'D':
if (!strpos($v,':')) {
$s .= " <TD>".$rs->UserDate($v,"D d, M Y") ." </TD>\n";
break;
}
case 'T':
$s .= " <TD>".$rs->UserTimeStamp($v,"D d, M Y, h:i:s") ." </TD>\n";
break;
case 'I':
case 'N':
$s .= " <TD align=right>".stripslashes((trim($v))) ." </TD>\n";
break;
default:
if ($htmlspecialchars) $v = htmlspecialchars(trim($v));
$v = trim($v);
if (strlen($v) == 0) $v = ' ';
$s .= " <TD>". str_replace("\n",'<br>',stripslashes($v)) ."</TD>\n";
}
} // for
$td="<td><input size=10 type='text' name=";
$tdend=' ></td>';
for ($m=0;$m<$lengthedit; $m++)
{$s.=$td.$edit[$m].$num.$tdend;}
$s .= "</TR>\n\n";
$rows += 1;
if ($rows >= $gSQLMaxRows) {
$rows = "<p>Truncated at $gSQLMaxRows</p>";
break;
} // switch
$rs->MoveNext();
// additional EOF check to prevent a widow header
if (!$rs->EOF && $rows % $gSQLBlockRows == 0) {
//if (connection_aborted()) break;// not needed as PHP aborts script, unlike ASP
if ($echo) print $s . "</TABLE>\n\n";
else $html .= $s ."</TABLE>\n\n";
$s = $hdr;
}
} // while
if ($echo) print $s."</TABLE>\n\n";
else $html .= $s."</TABLE>\n\n";
if ($docnt) if ($echo) print "<H2>".$rows." Rows</H2>";
//return ($echo) ? $rows : $html;
}
// pass in 2 dimensional array
function arr2html(&$arr,$ztabhtml='',$zheaderarray='')
{
if (!$ztabhtml) $ztabhtml = 'BORDER=1';
$s = "<TABLE $ztabhtml>";//';print_r($arr);
if ($zheaderarray) {
$s .= '<TR>';
for ($i=0; $i<sizeof($zheaderarray); $i++) {
$s .= " <TH>{$zheaderarray[$i]}</TH>\n";
}
$s .= "\n</TR>";
}
for ($i=0; $i<sizeof($arr); $i++) {
$s .= '<TR>';
$a = &$arr[$i];
if (is_array($a))
for ($j=0; $j<sizeof($a); $j++) {
$val = $a[$j];
if (empty($val)) $val = ' ';
$s .= " <TD>$val</TD>\n";
}
else if ($a) {
$s .= ' <TD>'.$a."</TD>\n";
} else $s .= " <TD> </TD>\n";
$s .= "\n</TR>\n";
}
$s .= '</TABLE>';
print $s;
}
?>
[/php] |
|