egroupware/admin/inc/class.html.inc.php

523 lines
12 KiB
PHP
Raw Normal View History

2001-08-05 08:48:42 +02:00
<?php
/**************************************************************************\
* phpGroupWare - html *
* http://www.phpgroupware.org *
* Written by Jerry Westrick <jerry@westrick.com> *
* -------------------------------------------- *
* This program 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. *
\**************************************************************************/
/* $Id$ */
class html
{
function hash_table($rows,$head='',$obj, $frtn)
{
2001-08-12 03:06:07 +02:00
global $phpgw, $start, $phpgw_info;
2001-08-05 08:48:42 +02:00
$html = '';
$edittable =$head['_edittable'];
if (isset($edittable))
{
if ($edittable)
{
// Generate the customization table...
return $this->edit_table($rows,$head,$obj,$frtn);
}
else
{
$html .= "<form method=\"post\" action=\""
2001-08-12 03:06:07 +02:00
. $phpgw->link('/admin/log.php') ;
// . "&editable=true\">\n";
// --------------------------------- nextmatch ---------------------------
// nextmatchs
$bo = CreateObject('admin.bolog',True);
if (!isset($start))
{
$start = 0;
}
$num_rows = $phpgw_info['user']['preferences']['common']['maxmatchs'];
$stop = $start + $num_rows;
if ($stop > count($rows))
{
$stop = count($rows);
}
$nextmatchs = CreateObject('phpgwapi.nextmatchs');
$total_records = $bo->get_no_errors();
$left = $nextmatchs->left('/admin/log.php',$start,$total_records,$extradata='');
$right = $nextmatchs->right('/admin/log.php',$start,$total_records,$extradata='');
$hits = $nextmatchs->show_hits($total_records,$start);
// -------------------------- end nextmatch ------------------------------------
$html .= "<table width=\"98%\"><tr>";
$html .= "<td align=left>$left</td>";
$html .= "<td align=right> $hits</td>";
$html .= "<td align=left> <A href=".$phpgw->link('/admin/log.php'). "&editable=true" ."> Edit Table format </A></td>";
$html .= "<td align=right>$right</td>";
$html .= "</tr></table>";
2001-08-05 08:48:42 +02:00
}
}
2001-08-12 03:06:07 +02:00
2001-08-05 08:48:42 +02:00
if ($head == '')
{
$frow = $rows[0];
$cnam = array_keys($frow);
while(list(,$fn)=each($cnam))
{
$head[$fn] = array();
}
};
if ( gettype($head['_cols'])=="NULL")
{
$cols = array_keys($rows[0]);
}
else
{
$cols = $head['_cols'];
2001-08-12 03:06:07 +02:00
}
2001-08-05 08:48:42 +02:00
// Build Header Row...
2001-08-12 03:06:07 +02:00
// First Get the layout arrays...
$layout = $head['#layout'];
if (gettype($layout) != 'array')
2001-08-05 08:48:42 +02:00
{
2001-08-12 03:06:07 +02:00
$layout = array_keys($cols);
}
// printlist, a list of all columns in a logical row,
// with Row/ColSpawn values, in print order...
2001-08-05 08:48:42 +02:00
2001-08-12 03:06:07 +02:00
$printlist = $this->make_printlist($layout,$cols);
2001-08-12 03:06:07 +02:00
// $table contains data for header row....
$table = $this->make_tblhead($printlist,$head);
// get GroupBy
$groupby = $head['_groupby'];
$supres = $head['_supres'];
$lastgroup = '';
// build actual Rows...
$rparms = array();
2001-08-12 03:06:07 +02:00
$mrow = $stop;
for ($rno=0;$rno<$mrow;$rno++)
{
// Build GroupKey
if (isset($groupby))
{
$gkey = '';
reset($groupby);
while (list($gname,)=each($groupby))
{
2001-08-12 03:06:07 +02:00
$gkey .= $rows[$rno][$gname]['value'];
}
2001-08-12 03:06:07 +02:00
$rows[$rno]['#gkey'] = $gkey;
}
reset($printlist);
while(list($pc,$pcol)=each($printlist))
{
$cname = $pcol['#name'];
$cparms = array_merge($head[$cname],$pcol,array('bgcolor'=>'FFFFFF'),$rows[$rno][$cname]);
$rows[$rno][$cname] = $cparms;
}
}
// Grouping Suppression
if (isset($groupby))
{
2001-08-12 03:06:07 +02:00
$grno = $start;
$gkey = $rows[$start]['#gkey'];
for ($rno=$start+1;$rno<$stop;$rno++)
{
$rowspan = 1;
2001-08-12 03:06:07 +02:00
$rkey = $rows[$rno]['#gkey'];
while ( $gkey == $rkey)
{
2001-08-12 03:06:07 +02:00
//echo "<p>grno:$grno ($gkey) rno:$rno ($rkey) are equal</p>";
$rowspan = $rowspan + 1;
2001-08-12 03:06:07 +02:00
$row = $rows[$rno];
2001-08-05 08:48:42 +02:00
2001-08-12 03:06:07 +02:00
for ($pc=0;$pc<count($row);$pc++)
{
2001-08-12 03:06:07 +02:00
$c = $row[$cols[$pc]];
$cno = $c['#colno'];
$cname = $c['#name'];
if ($supres[$cname])
{
2001-08-12 03:06:07 +02:00
$rows[$rno][$cname]['#supres']='yes';
$rows[$rno][$cname]['value']='&nbsp ';
$rows[$grno][$cname]['rowspan']=$printlist[$cno]['rowspan']*$rowspan;
}
}
$rno++;
2001-08-12 03:06:07 +02:00
$rkey = $rows[$rno]['#gkey'];
}
2001-08-12 03:06:07 +02:00
//echo "<p>grno:$grno ($gkey) rno:$rno ($rkey) are not equal</p>";
$grno=$rno;
$gkey=$rkey;
}
}
2001-08-12 03:06:07 +02:00
/*
** Now Generate the Html For the Table Header
*/
//print_r($table);
2001-08-12 03:06:07 +02:00
$html .= $this->html_head($head,$table,$printlist);
/*
** Now (finaly) Generate the Html For the Table
*/
2001-08-12 03:06:07 +02:00
//print_r($rows);
for ($rno=$start;$rno<$stop;$rno++)
2001-08-05 08:48:42 +02:00
{
// let user have a hack at the row...
2001-08-12 03:06:07 +02:00
$row = $obj->$frtn($rno,$rows[$rno]);
// $row = $rows[$rno];
// $rp = $this->makeparms($row[$rno]['#row_parms']);
$rp = '';
$gkey = $row['#gkey'];
// $html .= "\t<tr $rp> <comment $gkey>\n";
$html .= "\t<tr $rp> \n";
reset($printlist);
while(list($pc,$pcol)=each($printlist))
2001-08-05 08:48:42 +02:00
{
2001-08-12 03:06:07 +02:00
$cname = $pcol['#name'];
$cp = $this->makeparms($row[$cname]);
if($row[$cname]['#supres'] != 'yes')
{
2001-08-12 03:06:07 +02:00
$html .= "\t\t<td $cp>".$row[$cname]['value']."</td>\n";
}
if($pcol['#eor']=='1')
{
$html .= "\t</tr>\n"; // \t<tr $rp>\n
}
2001-08-05 08:48:42 +02:00
}
}
$html .= "</table>\n";
$html .= "</form>";
return $html;
}
function makeparms($parmlist)
{
$html = '';
$comma = ' ';
2001-08-12 03:06:07 +02:00
if (gettype($parmlist) != 'array')
{
return '';
}
reset($parmlist);
while(list($pname,$pvalue)=each($parmlist))
{
switch($pname)
{
case 'value':
break;
case 'colspan':
case 'rowspan':
if ($pvalue != 1)
{
$html .= $comma . $pname . '="' . $pvalue . '"';
$comma = ', ';
};
break;
default:
if (substr($pname,0,1) != '#')
{
$html .= $comma . $pname . '="' . $pvalue . '"';
$comma = ', ';
}
}
}
return $html;
}
2001-08-05 08:48:42 +02:00
function edit_table($rows,$head='',$obj, $frtn)
{
2001-08-12 03:06:07 +02:00
global $phpgw, $nocols, $noflds, $norows, $layout, $_cols;
2001-08-05 08:48:42 +02:00
$html = '';
$html .= "<form method=\"post\" action=\""
2001-08-05 08:54:52 +02:00
. $phpgw->link('/admin/log.php')
2001-08-05 08:48:42 +02:00
. "&editable=true"
. "\">\n";
$params = $head['_table_parms'];
$frow = $rows[0];
$cnam = array_keys($frow);
if ($head == '')
{
while(list(,$fn)=each($cnam))
{
$head[$fn] = array();
}
};
2001-08-12 03:06:07 +02:00
if (isset($_cols))
2001-08-05 08:48:42 +02:00
{
2001-08-12 03:06:07 +02:00
$cols = $_cols;
2001-08-05 08:48:42 +02:00
}
else
{
2001-08-12 03:06:07 +02:00
if ( gettype($head['_cols'])=="NULL")
{
$cols = array_keys($rows[0]);
}
else
{
$cols = $head['_cols'];
};
}
if (!isset($noflds))
{
$noflds = count($cols);
}
if (!isset($layout))
{
$layout = $head['#layout'];
2001-08-05 08:48:42 +02:00
};
2001-08-12 03:06:07 +02:00
if (!isset($norows))
{
$norows = count($layout);
}
2001-08-05 08:48:42 +02:00
if (!isset($nocols))
{
2001-08-12 03:06:07 +02:00
$nocols = count($layout[0]);
2001-08-05 08:48:42 +02:00
}
2001-08-12 03:06:07 +02:00
// Table Excmple
2001-08-05 08:48:42 +02:00
// Build Header Row...
2001-08-12 03:06:07 +02:00
$html .= "<h2>Table Size</h2>";
// $html .= "<p>";
$html .= "Rows: ";
$html .= "<input type=\"input\" name=\"norows\" value=\"$norows\">";
$html .= "Columns: ";
2001-08-05 08:48:42 +02:00
$html .= "<input type=\"input\" name=\"nocols\" value=\"$nocols\">";
2001-08-12 03:06:07 +02:00
$html .= "Fields: ";
$html .= "<input type=\"input\" name=\"noflds\" value=\"$noflds\">";
// $html .= "\t<tr> ";
// Column Defintions...
$html .= "<h2>Column Definition</h2>";
$html .= "<table width=\"98%\", bgcolor=\"000000\">\n";
$f = array();
for ($fno=0;$fno<$noflds;$fno++)
{
$f[]=$fno;
};
// Column Headings
$html .= "\t<tr bgcolor=\"D3DCFF\">\n";
for ($cno=0;$cno<$nocols;$cno++)
{
$html .= "\t\t<td align=center>$cno</td>\n";
}
$html .= "\t</tr >\n";
for ($rno=0;$rno<$norows;$rno++)
{
$html .= "\t<tr bgcolor=\"D3DCFF\">\n";
for ($cno=0;$cno<$nocols;$cno++)
{
$c = $layout[$rno][$cno];
$tname = "layout[$rno][]";
$t = $this->DropDown($f,$tname,$c);
$html .= "\t\t<td align=center>$t</td>\n";
}
$html .= "\t</tr >\n";
}
$html .= "</table>\n";
$html .= "<p>\n";
// Header of Table...
$printlist = $this->make_printlist($layout,$cols);
$table = $this->make_tblhead($printlist,$head);
$html .= $this->html_head($head,$table,$printlist);
$html .= "</table>\n";
$html .= "<input type=\"submit\" name=\"submit\" value=\"Update\">";
//Field Definitions
$html .= "<h2>Field Definitions</h2>";
2001-08-05 08:48:42 +02:00
$html .= "<table width=\"98%\", bgcolor=\"D3DCFF\">\n";
2001-08-12 03:06:07 +02:00
$html .= "\t\t<td width=\"2%\", align=\"center\">No</td>\n";
2001-08-05 08:48:42 +02:00
$html .= "\t\t<td width=\"2%\", align=\"center\">Del</td>\n";
2001-08-12 03:06:07 +02:00
$html .= "\t\t<td width=\"5%\">Field</td>\n";
2001-08-05 08:48:42 +02:00
$html .= "\t\t<td>Value</td>\n";
$html .= "\t</tr>\n";
// Add Table Rows...
reset($cols);
// while (list($cno,$name) = each($cols))
2001-08-12 03:06:07 +02:00
for ($fno=0;$fno<$noflds;$fno++)
2001-08-05 08:48:42 +02:00
{
2001-08-12 03:06:07 +02:00
$name = $cols[$fno];
2001-08-05 08:48:42 +02:00
$values = $head[$name];
$title = $values['title'];
if ($title == '')
{
$title = $name;
}
$html .= "\t</tr>\n";
2001-08-12 03:06:07 +02:00
$html .= "\t\t<td bgcolor=\"FFFFFF\">$fno</td>\n";
$html .= "\t\t<td bgcolor=\"FFFFFF\"><input type=\"checkbox\" name=\"_delcol[]\" value=\"$fno\"></td>\n";
2001-08-05 08:48:42 +02:00
$html .= "\t\t<td bgcolor=\"FFFFFF\">".$this->dropdown($cnam,'_cols[]',$name)."</td>\n";
2001-08-12 03:06:07 +02:00
$value = $rows[0][$name]['value'];
2001-08-05 08:48:42 +02:00
$html .= "\t\t<td bgcolor=\"FFFFFF\">$value</td>\n";
$html .= "\t</tr>\n";
}
$html .= "</table>\n";
$html .= "<input type=\"submit\" name=\"modifytable\" value=\"Save Changes\">";
$html .= "</form>";
return $html;
}
function dropdown($opts,$name='',$sel='')
{
$items = $opts;
$html = '<select ';
if ($name != '')
{
$html .= 'name="'.$name.'"';
}
$html .= ">\n";
while (list(,$itm)=each($opts))
{
2001-08-12 03:06:07 +02:00
$html .= '<option value="'.$itm.'" ';
2001-08-05 08:48:42 +02:00
if ($itm == $sel)
{
$html .= 'selected ';
}
$html .= '>'.$itm."</option>\n";
}
$html .= "</select>\n";
return $html;
}
2001-08-12 03:06:07 +02:00
function make_printlist($layout,$cols)
{
// Build Printlist... (Col and Row Spans...)
$tlayout = $layout;
$printlist = array();
$mrows = count($tlayout);
$mcols = count($tlayout[0]);
for($pr=0;$pr<$mrows;$pr++)
{
for($pc=0;$pc<$mcols;$pc++)
{
if (isset($tlayout[$pr][$pc]))
{
$cno = $tlayout[$pr][$pc];
$cname = $cols[$cno];
$colspan=1;
$rowspan=1;
while(($pr + $rowspan < $mrows) && ($tlayout[$pr + $rowspan][$pc] == $cno))
{
unset($tlayout[$pr + $rowspan][$pc]);
$rowspan++;
};
while(($pc + $colspan < $mcols) && ($tlayout[$pr][$pc+$colspan] == $cno))
{
unset($tlayout[$pr][$pc+$colspan]);
$colspan++;
};
if ($colspan > 1 && $rowspan > 1)
{
for($r=$pr+1;$r<$pr+$rowspan;$r++)
{
for($c=$pc+1;$c<$pc+$colspan;$c++)
{
unset($tlayout[$r][$c]);
}
}
}
$printlist[]=array('#name' =>$cname,
'rowspan' =>$rowspan,
'colspan' =>$colspan,
'valign' =>'top',
'#colno' =>$cno,
'#eor' =>0
);
}
}
$printlist[count($printlist)-1]['#eor']='1';
}
return $printlist;
}
2001-08-05 08:48:42 +02:00
2001-08-12 03:06:07 +02:00
function make_tblhead($printlist,$head)
{
// Build Title Row
$table = array();
reset($printlist);
while(list($pc,$pcol)=each($printlist))
{
$cname = $pcol['#name'];
$values = $head[$cname];
$title = $values['#title'];
if ($title == '')
{
$title = $cname;
}
$cparms = array_merge($values['#parms_hdr'],$pcol);
$cparms['value']=$title;
$table[0][$pc] = $cparms;
}
return $table;
}
function html_head($head,$table,$printlist)
{
$html = '';
$tparams = $this->makeparms($head['#table_parms']);
$html .= "<table $tparams>\n";
$rp = $this->makeparms($head['#head_parms']);
// $html .= "\t<tr $rp> <comment header>\n";
$html .= "\t<tr $rp> \n";
$row = $table[0];
reset($row);
$intr = true;
while(list(,$col)=each($row))
{
if (!$intr)
{
$html .= "\t<tr $rp>\n";
$intr = true;
}
$cname = $col['#name'];
$cp = $this->makeparms($col);
$html .= "\t\t<td $cp>".$col['value']."</td>\n";
if($col['#eor']=='1')
{
$html .= "\t</tr>\n";
$intr = false;
}
}
return $html;
}
}