PageRenderTime 22ms CodeModel.GetById 1ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/smarty2/plugins/function.input.php

http://zoop.googlecode.com/
PHP | 91 lines | 78 code | 9 blank | 4 comment | 15 complexity | 1feba7c8cdb32d0be3136d2ed7d18035 MD5 | raw file
 1<?php
 2function smarty_function_input($params, &$smarty)
 3{
 4	$type = isset($params['type']) ? $params['type'] : 'text';
 5	$valueAtt = isset($params['value']) ? $params['value'] : '';
 6	
 7	// handle the data bindings
 8	if(isset($params['data_object']))
 9	{
10		if(!isset($params['data_field']))
11			trigger_error("gui:input: if you specifiy a data object you must also specify a data field");
12		
13		$object = $params['data_object'];
14		$field = $params['data_field'];
15		if(!isset($params['append']) || $params['append'] == false)
16		{
17			if(!isset($smarty->zoop->form))
18				trigger_error("gui:input: if you specifiy a data object you must first use the 'init_form' tag");
19			$name = $smarty->zoop->form->addBinding(get_class($object), $object->getId(), $field);
20		}
21		else
22		{
23			$binding = new FormBinding(get_class($object), $object->getId(), $field);
24			Form::appendBindings(array($binding));
25			$name = $binding->getName();
26		}
27		if(isset($params['default']) && ($object->$field === '' || $object->$field === NULL))
28			$value = $params['default'];
29		else
30			$value = $object->$field;
31		
32		$namePart = ' name="' . $name . '"';
33		if($type == 'radio')
34			$valuePart = ' value="' . $valueAtt . '"';
35		else
36			$valuePart = ' value="' . $value . '"';
37	}
38	else
39	{
40		$value = $valueAtt;
41		$namePart = isset($params['name']) ? ' name="' . $params['name'] . '"' : '';
42		$valuePart = isset($params['value']) ? ' value="' . $params['value'] . '"' : '';
43	}
44	
45	
46	// pass on anything else they put in
47	$extraFields = '';
48	$extraMap = array();
49	foreach($params as $paramName => $paramValue)
50	{
51		if(in_array($paramName, array('type', 'name', 'type', 'value', 'default', 'data_object', 'data_field', 'append')))
52			continue;
53		
54		$extraMap[$paramName] = $paramValue;
55		$extraFields .= ' ' . $paramName . '="' . $paramValue . '"';
56	}
57	
58	switch($type)
59	{
60		case 'text':
61		case 'password':
62		case 'checkbox':
63		case 'submit':
64			return '<input type="' . $type . '"' . " $namePart $valuePart $extraFields>";
65			break;
66		case 'radio':
67			// var_dump($value);
68			// var_dump($valueAtt);
69			$checked = $valueAtt == $value ? ' checked' : '';
70			return '<input type="' . $type . '"' . " $namePart $valuePart $extraFields $checked>";
71			break;
72		case 'textarea':			
73			$return = '<textarea name="' . $name . '" ' . $extraFields . '>';
74			$return .= $value;
75			$return .= '</textarea>';
76			return $return;
77			break;
78		case 'select':
79	    	require_once $smarty->_get_plugin_filepath('function','html_options');
80			$selectParams = $extraMap;
81			$selectParams['name'] = $name;
82			$selectParams['selected'] = $value;
83			return smarty_function_html_options($selectParams, $smarty);
84			break;
85		default:
86			trigger_error("unknown input type: $type");
87			break;
88	}
89}
90
91