1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * eGroupWare - html * |
---|
4 | * http://www.egroupware.org * |
---|
5 | * Written by Jerry Westrick <jerry@westrick.com> * |
---|
6 | * -------------------------------------------- * |
---|
7 | * This program is free software; you can redistribute it and/or modify it * |
---|
8 | * under the terms of the GNU General Public License as published by the * |
---|
9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
10 | * option) any later version. * |
---|
11 | \**************************************************************************/ |
---|
12 | |
---|
13 | |
---|
14 | class html_tables |
---|
15 | { |
---|
16 | function hash_table($rows,$head='',$obj, $frtn) |
---|
17 | { |
---|
18 | $start = $_POST['start'] ? $_POST['start'] : $_GET['start']; |
---|
19 | |
---|
20 | $html = ''; |
---|
21 | $edittable = $head['_edittable']; |
---|
22 | if(isset($edittable)) |
---|
23 | { |
---|
24 | if($edittable) |
---|
25 | { |
---|
26 | // Generate the customization table... |
---|
27 | return $this->edit_table($rows,$head,$obj,$frtn); |
---|
28 | } |
---|
29 | else |
---|
30 | { |
---|
31 | #$html .= '<form method="post" action="' |
---|
32 | # . $GLOBALS['phpgw']->link('/index.php') |
---|
33 | # . '">' . "\n"; |
---|
34 | $bo = CreateObject('admin.bolog',True); |
---|
35 | if(!isset($start)) |
---|
36 | { |
---|
37 | $start = 0; |
---|
38 | } |
---|
39 | $num_rows = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']; |
---|
40 | $stop = $start + $num_rows; |
---|
41 | if($stop > count($rows)) |
---|
42 | { |
---|
43 | $stop = count($rows); |
---|
44 | } |
---|
45 | $nextmatchs = CreateObject('phpgwapi.nextmatchs'); |
---|
46 | $total_records = $bo->get_no_errors(); |
---|
47 | $left = $nextmatchs->left('/index.php',$start,$total_records,'menuaction=admin.uilog.list_log'); |
---|
48 | $right = $nextmatchs->right('/index.php',$start,$total_records,'menuaction=admin.uilog.list_log'); |
---|
49 | $hits = $nextmatchs->show_hits($total_records,$start); |
---|
50 | |
---|
51 | $html .= '<table width="98%"><tr>'; |
---|
52 | $html .= $left; |
---|
53 | $html .= '<td align="right"> ' . $hits . ' </td>'; |
---|
54 | $html .= '<td align="left"> <a href=' . $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uilog.list_log&editable=true') .'> ' . lang('Edit Table format') . '</a></td>'; |
---|
55 | $html .= $right; |
---|
56 | $html .= '</tr></table>'; |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | if($head == '') |
---|
61 | { |
---|
62 | $frow = $rows[0]; |
---|
63 | $cnam = $this->arr_keys($frow); |
---|
64 | while(list(,$fn)=each($cnam)) |
---|
65 | { |
---|
66 | $head[$fn] = array(); |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | if(@is_null($head['_cols'])) |
---|
71 | { |
---|
72 | $cols = $this->arr_keys($rows[0]); |
---|
73 | } |
---|
74 | else |
---|
75 | { |
---|
76 | $cols = $head['_cols']; |
---|
77 | } |
---|
78 | |
---|
79 | // Build Header Row... |
---|
80 | |
---|
81 | // First Get the layout arrays... |
---|
82 | $layout = $head['#layout']; |
---|
83 | if(!is_array($layout)) |
---|
84 | { |
---|
85 | $layout = $this->arr_keys($cols); |
---|
86 | } |
---|
87 | |
---|
88 | // printlist, a list of all columns in a logical row, |
---|
89 | // with Row/ColSpawn values, in print order... |
---|
90 | |
---|
91 | $printlist = $this->make_printlist($layout,$cols); |
---|
92 | |
---|
93 | // $table contains data for header row.... |
---|
94 | $table = $this->make_tblhead($printlist,$head); |
---|
95 | |
---|
96 | // get GroupBy |
---|
97 | $groupby = $head['_groupby']; |
---|
98 | $supres = $head['_supres']; |
---|
99 | $lastgroup = ''; |
---|
100 | |
---|
101 | // build actual Rows... |
---|
102 | $rparms = array(); |
---|
103 | $mrow = $stop; |
---|
104 | for($rno=0;$rno<$mrow;++$rno) |
---|
105 | { |
---|
106 | // Build GroupKey |
---|
107 | if(isset($groupby)) |
---|
108 | { |
---|
109 | $gkey = ''; |
---|
110 | reset($groupby); |
---|
111 | while(list($gname,)=each($groupby)) |
---|
112 | { |
---|
113 | $gkey .= $rows[$rno][$gname]['value']; |
---|
114 | } |
---|
115 | $rows[$rno]['#gkey'] = $gkey; |
---|
116 | } |
---|
117 | |
---|
118 | reset($printlist); |
---|
119 | while(list($pc,$pcol)=each($printlist)) |
---|
120 | { |
---|
121 | $cname = $pcol['#name']; |
---|
122 | $cparms = $this->arr_merge($head[$cname],$pcol,array('bgcolor'=>'#FFFFFF'),$rows[$rno][$cname]); |
---|
123 | $rows[$rno][$cname] = $cparms; |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | // Grouping Suppression |
---|
128 | |
---|
129 | if(isset($groupby)) |
---|
130 | { |
---|
131 | $grno = $start; |
---|
132 | $gkey = $rows[$start]['#gkey']; |
---|
133 | for($rno=$start+1;$rno<$stop;++$rno) |
---|
134 | { |
---|
135 | $rowspan = 1; |
---|
136 | $rkey = $rows[$rno]['#gkey']; |
---|
137 | |
---|
138 | while( $gkey == $rkey) |
---|
139 | { |
---|
140 | //echo "<p>grno:$grno ($gkey) rno:$rno ($rkey) are equal</p>"; |
---|
141 | $rowspan = $rowspan + 1; |
---|
142 | $row = $rows[$rno]; |
---|
143 | |
---|
144 | $row_count = count($row); |
---|
145 | for($pc=0;$pc<$row_count;++$pc) |
---|
146 | { |
---|
147 | $c = $row[$cols[$pc]]; |
---|
148 | $cno = $c['#colno']; |
---|
149 | $cname = $c['#name']; |
---|
150 | |
---|
151 | if($supres[$cname]) |
---|
152 | { |
---|
153 | $rows[$rno][$cname]['#supres']='yes'; |
---|
154 | $rows[$rno][$cname]['value']='  '; |
---|
155 | $rows[$grno][$cname]['rowspan']=$printlist[$cno]['rowspan']*$rowspan; |
---|
156 | } |
---|
157 | } |
---|
158 | ++$rno; |
---|
159 | $rkey = $rows[$rno]['#gkey']; |
---|
160 | } |
---|
161 | //echo "<p>grno:$grno ($gkey) rno:$rno ($rkey) are not equal</p>"; |
---|
162 | $grno=$rno; |
---|
163 | $gkey=$rkey; |
---|
164 | } |
---|
165 | } |
---|
166 | /* |
---|
167 | ** Now Generate the Html For the Table Header |
---|
168 | */ |
---|
169 | //print_r($table); |
---|
170 | |
---|
171 | $html .= $this->html_head($head,$table,$printlist); |
---|
172 | /* |
---|
173 | ** Now (finally) Generate the Html For the Table |
---|
174 | */ |
---|
175 | //print_r($rows); |
---|
176 | for($rno=$start;$rno<$stop;++$rno) |
---|
177 | { |
---|
178 | // let user have a hack at the row... |
---|
179 | $row = $obj->$frtn($rno,$rows[$rno]); |
---|
180 | // $row = $rows[$rno]; |
---|
181 | |
---|
182 | // $rp = $this->makeparms($row[$rno]['#row_parms']); |
---|
183 | $rp = ''; |
---|
184 | $gkey = $row['#gkey']; |
---|
185 | // $html .= "\t<tr $rp> <comment $gkey>\n"; |
---|
186 | $html .= "\t<tr $rp> \n"; |
---|
187 | reset($printlist); |
---|
188 | while(list($pc,$pcol)=each($printlist)) |
---|
189 | { |
---|
190 | $cname = $pcol['#name']; |
---|
191 | |
---|
192 | $cp = $this->makeparms($row[$cname]); |
---|
193 | if($row[$cname]['#supres'] != 'yes') |
---|
194 | { |
---|
195 | $html .= "\t\t<td $cp>".$row[$cname]['value']."</td>\n"; |
---|
196 | } |
---|
197 | if($pcol['#eor']=='1') |
---|
198 | { |
---|
199 | $html .= "\t</tr>\n"; // \t<tr $rp>\n |
---|
200 | } |
---|
201 | } |
---|
202 | } |
---|
203 | $html .= "</table>\n"; |
---|
204 | #$html .= "</form>"; |
---|
205 | return $html; |
---|
206 | } |
---|
207 | |
---|
208 | function makeparms($parmlist) |
---|
209 | { |
---|
210 | $html = ''; |
---|
211 | $comma = ' '; |
---|
212 | if(!is_array($parmlist)) |
---|
213 | { |
---|
214 | return ''; |
---|
215 | } |
---|
216 | reset($parmlist); |
---|
217 | while(list($pname,$pvalue)=each($parmlist)) |
---|
218 | { |
---|
219 | switch($pname) |
---|
220 | { |
---|
221 | case 'value': |
---|
222 | break; |
---|
223 | case 'colspan': |
---|
224 | case 'rowspan': |
---|
225 | if($pvalue != 1) |
---|
226 | { |
---|
227 | $html .= $comma . $pname . '="' . $pvalue . '"'; |
---|
228 | #$comma = ', '; |
---|
229 | $comma = ' '; |
---|
230 | }; |
---|
231 | break; |
---|
232 | default: |
---|
233 | if(substr($pname,0,1) != '#') |
---|
234 | { |
---|
235 | $html .= $comma . $pname . '="' . $pvalue . '"'; |
---|
236 | #$comma = ', '; |
---|
237 | $comma = ' '; |
---|
238 | } |
---|
239 | } |
---|
240 | } |
---|
241 | return $html; |
---|
242 | } |
---|
243 | |
---|
244 | function edit_table($rows,$head='',$obj, $frtn) |
---|
245 | { |
---|
246 | $nocols = $_POST['nocols']; |
---|
247 | $noflds = $_POST['noflds']; |
---|
248 | $norows = $_POST['norows']; |
---|
249 | $layout = $_POST['layout']; |
---|
250 | $_cols = $_POST['_cols']; |
---|
251 | |
---|
252 | $html = ''; |
---|
253 | $html .= '<form method="post" action="' |
---|
254 | . $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uilog.list_log&editable=true') |
---|
255 | . '">' . "\n"; |
---|
256 | |
---|
257 | $params = $head['_table_parms']; |
---|
258 | $frow = $rows[0]; |
---|
259 | $cnam = $this->arr_keys($frow); |
---|
260 | if($head == '') |
---|
261 | { |
---|
262 | while(list(,$fn)=each($cnam)) |
---|
263 | { |
---|
264 | $head[$fn] = array(); |
---|
265 | } |
---|
266 | } |
---|
267 | |
---|
268 | if(isset($_cols)) |
---|
269 | { |
---|
270 | $cols = $_cols; |
---|
271 | } |
---|
272 | else |
---|
273 | { |
---|
274 | if(@is_null($head['_cols'])) |
---|
275 | { |
---|
276 | $cols = $this->arr_keys($rows[0]); |
---|
277 | } |
---|
278 | else |
---|
279 | { |
---|
280 | $cols = $head['_cols']; |
---|
281 | } |
---|
282 | } |
---|
283 | |
---|
284 | if(!isset($noflds)) |
---|
285 | { |
---|
286 | $noflds = count($cols); |
---|
287 | } |
---|
288 | if(!isset($layout)) |
---|
289 | { |
---|
290 | $layout = $head['#layout']; |
---|
291 | } |
---|
292 | if(!isset($norows)) |
---|
293 | { |
---|
294 | $norows = count($layout); |
---|
295 | } |
---|
296 | if(!isset($nocols)) |
---|
297 | { |
---|
298 | $nocols = count($layout[0]); |
---|
299 | } |
---|
300 | // Table Excmple |
---|
301 | |
---|
302 | // Build Header Row... |
---|
303 | $html .= "<h2>Table Size</h2>"; |
---|
304 | // $html .= "<p>"; |
---|
305 | $html .= "Rows: "; |
---|
306 | $html .= "<input type=\"input\" name=\"norows\" value=\"$norows\">"; |
---|
307 | $html .= "Columns: "; |
---|
308 | $html .= "<input type=\"input\" name=\"nocols\" value=\"$nocols\">"; |
---|
309 | $html .= "Fields: "; |
---|
310 | $html .= "<input type=\"input\" name=\"noflds\" value=\"$noflds\">"; |
---|
311 | // $html .= "\t<tr> "; |
---|
312 | |
---|
313 | // Column Defintions... |
---|
314 | $html .= "<h2>Column Definition</h2>"; |
---|
315 | $html .= "<table width=\"98%\" bgcolor=\"#000000\">\n"; |
---|
316 | $f = array(); |
---|
317 | for($fno=0;$fno<$noflds;++$fno) |
---|
318 | { |
---|
319 | $f[]=$fno; |
---|
320 | } |
---|
321 | // Column Headings |
---|
322 | $html .= "\t<tr bgcolor=\"#D3DCFF\">\n"; |
---|
323 | for($cno=0;$cno<$nocols;++$cno) |
---|
324 | { |
---|
325 | $html .= "\t\t<td align=\"center\">$cno</td>\n"; |
---|
326 | } |
---|
327 | $html .= "\t</tr >\n"; |
---|
328 | for($rno=0;$rno<$norows;++$rno) |
---|
329 | { |
---|
330 | $html .= "\t<tr bgcolor=\"#D3DCFF\">\n"; |
---|
331 | for($cno=0;$cno<$nocols;++$cno) |
---|
332 | { |
---|
333 | $c = $layout[$rno][$cno]; |
---|
334 | $tname = "layout[$rno][]"; |
---|
335 | $t = $this->DropDown($f,$tname,$c); |
---|
336 | $html .= "\t\t<td align=\"center\">$t</td>\n"; |
---|
337 | } |
---|
338 | $html .= "\t</tr >\n"; |
---|
339 | } |
---|
340 | $html .= "</table>\n"; |
---|
341 | $html .= "<p>\n"; |
---|
342 | |
---|
343 | // Header of Table... |
---|
344 | $printlist = $this->make_printlist($layout,$cols); |
---|
345 | $table = $this->make_tblhead($printlist,$head); |
---|
346 | $html .= $this->html_head($head,$table,$printlist); |
---|
347 | $html .= "</table>\n"; |
---|
348 | |
---|
349 | $html .= "<input type=\"submit\" name=\"submit\" value=\"Update\">"; |
---|
350 | //Field Definitions |
---|
351 | $html .= "<h2>Field Definitions</h2>"; |
---|
352 | $html .= "<table width=\"98%\" bgcolor=\"#D3DCFF\">\n"; |
---|
353 | $html .= "\t\t<td width=\"2%\" align=\"center\">No</td>\n"; |
---|
354 | $html .= "\t\t<td width=\"2%\" align=\"center\">Del</td>\n"; |
---|
355 | $html .= "\t\t<td width=\"5%\">Field</td>\n"; |
---|
356 | $html .= "\t\t<td>Value</td>\n"; |
---|
357 | $html .= "\t</tr>\n"; |
---|
358 | |
---|
359 | // Add Table Rows... |
---|
360 | reset($cols); |
---|
361 | // while(list($cno,$name) = each($cols)) |
---|
362 | for($fno=0;$fno<$noflds;++$fno) |
---|
363 | { |
---|
364 | $name = $cols[$fno]; |
---|
365 | $values = $head[$name]; |
---|
366 | $title = $values['title']; |
---|
367 | if($title == '') |
---|
368 | { |
---|
369 | $title = $name; |
---|
370 | } |
---|
371 | $html .= "\t</tr>\n"; |
---|
372 | $html .= "\t\t<td bgcolor=\"#FFFFFF\">$fno</td>\n"; |
---|
373 | $html .= "\t\t<td bgcolor=\"#FFFFFF\"><input type=\"checkbox\" name=\"_delcol[]\" value=\"$fno\"></td>\n"; |
---|
374 | $html .= "\t\t<td bgcolor=\"#FFFFFF\">".$this->dropdown($cnam,'_cols[]',$name)."</td>\n"; |
---|
375 | $value = $rows[0][$name]['value']; |
---|
376 | $html .= "\t\t<td bgcolor=\"#FFFFFF\">$value</td>\n"; |
---|
377 | $html .= "\t</tr>\n"; |
---|
378 | } |
---|
379 | $html .= "</table>\n"; |
---|
380 | $html .= "<input type=\"submit\" name=\"modifytable\" value=\"Save Changes\">"; |
---|
381 | $html .= "</form>"; |
---|
382 | return $html; |
---|
383 | } |
---|
384 | |
---|
385 | function dropdown($opts,$name='',$sel='') |
---|
386 | { |
---|
387 | $items = $opts; |
---|
388 | $html = '<select '; |
---|
389 | if($name != '') |
---|
390 | { |
---|
391 | $html .= 'name="'.$name.'"'; |
---|
392 | } |
---|
393 | $html .= ">\n"; |
---|
394 | |
---|
395 | while(list(,$itm)=each($opts)) |
---|
396 | { |
---|
397 | $html .= '<option value="'.$itm.'" '; |
---|
398 | if($itm == $sel) |
---|
399 | { |
---|
400 | $html .= 'selected '; |
---|
401 | } |
---|
402 | $html .= '>'.$itm."</option>\n"; |
---|
403 | } |
---|
404 | $html .= "</select>\n"; |
---|
405 | return $html; |
---|
406 | } |
---|
407 | |
---|
408 | function make_printlist($layout,$cols) |
---|
409 | { |
---|
410 | // Build Printlist... (Col and Row Spans...) |
---|
411 | $tlayout = $layout; |
---|
412 | $printlist = array(); |
---|
413 | $mrows = count($tlayout); |
---|
414 | $mcols = count($tlayout[0]); |
---|
415 | for($pr=0;$pr<$mrows;++$pr) |
---|
416 | { |
---|
417 | for($pc=0;$pc<$mcols;++$pc) |
---|
418 | { |
---|
419 | if(isset($tlayout[$pr][$pc])) |
---|
420 | { |
---|
421 | $cno = $tlayout[$pr][$pc]; |
---|
422 | $cname = $cols[$cno]; |
---|
423 | $colspan=1; |
---|
424 | $rowspan=1; |
---|
425 | while(($pr + $rowspan < $mrows) && ($tlayout[$pr + $rowspan][$pc] == $cno)) |
---|
426 | { |
---|
427 | unset($tlayout[$pr + $rowspan][$pc]); |
---|
428 | ++$rowspan; |
---|
429 | } |
---|
430 | while(($pc + $colspan < $mcols) && ($tlayout[$pr][$pc+$colspan] == $cno)) |
---|
431 | { |
---|
432 | unset($tlayout[$pr][$pc+$colspan]); |
---|
433 | ++$colspan; |
---|
434 | } |
---|
435 | if($colspan > 1 && $rowspan > 1) |
---|
436 | { |
---|
437 | for($r=$pr+1;$r<$pr+$rowspan;++$r) |
---|
438 | { |
---|
439 | for($c=$pc+1;$c<$pc+$colspan;++$c) |
---|
440 | { |
---|
441 | unset($tlayout[$r][$c]); |
---|
442 | } |
---|
443 | } |
---|
444 | } |
---|
445 | $printlist[] = array( |
---|
446 | '#name' =>$cname, |
---|
447 | 'rowspan' =>$rowspan, |
---|
448 | 'colspan' =>$colspan, |
---|
449 | 'valign' =>'top', |
---|
450 | '#colno' =>$cno, |
---|
451 | '#eor' =>0 |
---|
452 | ); |
---|
453 | } |
---|
454 | } |
---|
455 | $printlist[count($printlist)-1]['#eor'] = '1'; |
---|
456 | } |
---|
457 | return $printlist; |
---|
458 | } |
---|
459 | |
---|
460 | function make_tblhead($printlist,$head) |
---|
461 | { |
---|
462 | // Build Title Row |
---|
463 | $table = array(); |
---|
464 | reset($printlist); |
---|
465 | while(list($pc,$pcol)=each($printlist)) |
---|
466 | { |
---|
467 | $cname = $pcol['#name']; |
---|
468 | $values = $head[$cname]; |
---|
469 | $title = $values['#title']; |
---|
470 | if($title == '') |
---|
471 | { |
---|
472 | $title = $cname; |
---|
473 | } |
---|
474 | $cparms = $this->arr_merge($values['#parms_hdr'],$pcol); |
---|
475 | $cparms['value']=$title; |
---|
476 | $table[0][$pc] = $cparms; |
---|
477 | } |
---|
478 | return $table; |
---|
479 | } |
---|
480 | |
---|
481 | function html_head($head,$table,$printlist) |
---|
482 | { |
---|
483 | $html = ''; |
---|
484 | $tparams = $this->makeparms($head['#table_parms']); |
---|
485 | $html .= "<table $tparams>\n"; |
---|
486 | $rp = $this->makeparms($head['#head_parms']); |
---|
487 | // $html .= "\t<tr $rp> <comment header>\n"; |
---|
488 | $html .= "\t<tr $rp> \n"; |
---|
489 | |
---|
490 | $row = $table[0]; |
---|
491 | reset($row); |
---|
492 | $intr = true; |
---|
493 | while(list(,$col)=each($row)) |
---|
494 | { |
---|
495 | if(!$intr) |
---|
496 | { |
---|
497 | $html .= "\t<tr $rp>\n"; |
---|
498 | $intr = true; |
---|
499 | } |
---|
500 | $cname = $col['#name']; |
---|
501 | $cp = $this->makeparms($col); |
---|
502 | $html .= "\t\t<td $cp>".$col['value']."</td>\n"; |
---|
503 | if($col['#eor']=='1') |
---|
504 | { |
---|
505 | $html .= "\t</tr>\n"; |
---|
506 | $intr = false; |
---|
507 | } |
---|
508 | } |
---|
509 | return $html; |
---|
510 | } |
---|
511 | |
---|
512 | function arr_merge($a1='',$a2='',$a3='',$a4='',$a5='',$a6='',$a7='',$a8='') |
---|
513 | { |
---|
514 | $out = array(); |
---|
515 | $test = array($a1,$a2,$a3,$a4,$a5,$a6,$a7,$a8); |
---|
516 | while(list(,$val) = each($test)) |
---|
517 | { |
---|
518 | if(is_array($val)) |
---|
519 | { |
---|
520 | $out += $val; |
---|
521 | } |
---|
522 | } |
---|
523 | return $out; |
---|
524 | } |
---|
525 | |
---|
526 | function arr_keys($fields,$array=True) |
---|
527 | { |
---|
528 | @reset($fields); |
---|
529 | while(list($key,$val) = @each($fields)) |
---|
530 | { |
---|
531 | $fkeys .= $key . ','; |
---|
532 | } |
---|
533 | $fkeys = substr($fkeys,0,-1); |
---|
534 | if($array) |
---|
535 | { |
---|
536 | $ex = explode(',',$fkeys); |
---|
537 | return $ex; |
---|
538 | } |
---|
539 | else |
---|
540 | { |
---|
541 | return $fkeys; |
---|
542 | } |
---|
543 | } |
---|
544 | } |
---|