1<?php
2 /**********************************************************************\
3 * phpGroupWare - InfoLog						*
4 * http://www.phpgroupware.org						*
5 * This program is part of the GNU project, see http://www.gnu.org/	*
6 *									*
7 * Copyright 2002, 2003 Free Software Foundation, Inc.			*
8 *									*
9 * Originally Written by Ralf Becker - <RalfBecker@outdoor-training.de>	*
10 * --------------------------------------------				*
11 * This program is Free Software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or 	*
14 * at your option) any later version.					*
15 \**********************************************************************/
16 /* $Id: class.customfields_widget.inc.php 13407 2003-09-07 01:29:29Z skwashd $ */
17
18	/*!
19	@class customfields_widget
20	@author ralfbecker
21	@abstract generates a template based on an array with definitions
22	@discussion This widget has neither a render nor a post_process function as it only generates a template
23	*/
24	class customfields_widget
25	{
26		var $public_functions = array(
27			'pre_process' => True
28		);
29		var $human_name = 'InfoLog custom fields';
30
31		function customfields_widget($ui)
32		{
33		}
34
35		function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
36		{
37			if (!is_array($value))
38			{
39				$cell['type'] = 'label';
40				return True;
41			}
42			$tpl = new etemplate;
43			$tpl->init('*** generated custom fields for InfoLog','','',0,'',0,0);	// make an empty template
44
45			$typ = $value['###typ###'];
46			unset($value['###typ###']);
47
48			//echo '<pre style="text-aling: left;">'; print_r($value); echo "</pre>\n";
49			foreach($value as $name => $field)
50			{
51				if (!empty($field['typ']) && $field['typ'] != $typ)
52				{
53					continue;	// not for our typ
54				}
55				$row_class = 'row';
56				$label = &$tpl->new_cell(++$n,'label',$field['label'],'',array(
57					'no_lang' => substr(lang($field['label']),-1) == '*' ? 2 : 0
58				));
59				if (count($field['values']))	// selectbox
60				{
61					foreach($field['values'] as $key => $val)
62					{
63						if (substr($val = lang($val),-1) != '*')
64						{
65							$field['values'][$key] = $val;
66						}
67					}
68					$input = &$tpl->new_cell($n,'select','','#'.$name,array(
69						'sel_options' => $field['values'],
70						'size'        => $field['rows'],
71						'no_lang'     => True
72					));
73				}
74				elseif ($field['rows'] > 1)		// textarea
75				{
76					$input = &$tpl->new_cell($n,'textarea','','#'.$name,array(
77						'size' => $field['rows'].($field['len'] > 0 ? ','.intval($field['len']) : '')
78					));
79				}
80				elseif (intval($field['len']) > 0)	// regular input field
81				{
82					list($max,$shown) = explode(',',$field['len']);
83					$input = &$tpl->new_cell($n,'text','','#'.$name,array(
84						'size' => intval($shown > 0 ? $shown : $max).','.intval($max)
85					));
86				}
87				else	// header-row
88				{
89					$label['span'] = 'all';
90					$tpl->new_cell($n);		// is needed even if its over-span-ed
91					$row_class = 'th';
92				}
93				if (!empty($field['help']) && $row_class != 'th')
94				{
95					$input['help'] = $field['help'];
96					$input['no_lang'] = substr(lang($help),-1) == '*' ? 2 : 0;
97				}
98				$tpl->set_row_attributes($n,0,$row_class);
99			}
100			// create an empty line which (should) take all the remaining height
101			$tpl->new_cell(++$n,'label','','',array(
102				'span' => 'all'
103			));
104			$tpl->set_row_attributes($n,'99%','row');
105
106			// set width of 1. (label) column to 100
107			$tpl->set_column_attributes(0,'100');
108
109			$tpl->set_rows_cols();		// msie (at least 5.5 shows nothing with div overflow=auto)
110			$tpl->size = '100%,100%'.($tpl->html->user_agent != 'msie' ? ',,,,,auto' : '');
111			//echo '<pre style="text-align: left;">'; print_r($tpl); echo "</pre>\n";
112
113			if (count($tpl->data) < 2)
114			{
115				$cell['type'] = 'label';
116				return True;
117			}
118			$cell['size'] = '';	// no separate namespace
119			$cell['type'] = 'template';
120			$cell['name'] = $tpl->name;
121			$cell['obj'] = &$tpl;
122
123			return True;	// extra Label is ok
124		}
125	}
126