<?
class simple_db_edit // Copyright by Mateusz Rusin © 2005 // 1.16
{
	var $db;
	var $ini;
	var $language;
	var $result;
	var $fields;
	var $primary_key;
	var $delete = false;
	var $form;
	var $inser_id;
	var $order_menu = false;
	var $ignored = array ();
	function simple_db_edit ($db, $ini, $language = 'pl', $result = null)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		
		$this -> db =& $db;
		$this -> ini =& $ini;
		if (!empty ($result))
			$this -> set_result ($result);
		if (!empty ($language))
			$this -> language = $language;
	}
	function set_result ($result)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		$this -> result = $result;
		$this -> set_fields ($result);
	}
	function set_select_menu ($field, $menu, $size = null)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		if (empty ($size))
			$size = count ($menu);
		$this -> fields [$field] -> select_menu = $menu;
		$this -> fields [$field] -> select_menu_size = $size;		
	}
	function set_checkbox ($field)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		$this -> fields [$field] -> type = 'checkbox';
	}
	function set_datetime ($field)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		$this -> fields [$field] -> type = 'datetime';
	}
	function hide ($field)	// Copyright by Mateusz Rusin © 2005 // 1.01
	{
		$this -> fields [$field] -> type = 'hidden';
		$this -> no_check ($field);
		unset ($this -> fields [$field] -> select_menu, $this -> fields [$field] -> select_menu_size);
	}
	function set_name ($field, $name)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		$this -> fields [$field] -> name = $name;
	}
	function set_title ($field, $title)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		$this -> fields [$field] -> title = $title;
	}
	function disable_field ($field)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		$this -> fields [$field] -> disabled = true;
	}
	function set_default_value ($field, $default_value)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		$this -> fields [$field] -> default_value = $default_value;
	}
	function set_delete ($delete = true)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		$this -> delete = $delete;
	}
	function set_file_type ($type_field, $file_fields, $hide = true)	// Copyright by Mateusz Rusin © 2005 // 1.01
	{
		if (!is_array ($file_fields))
			$file_fields = array ($file_fields);
		foreach ($file_fields as $file_field)
			$this -> fields [$file_field] -> file_type = $type_field;
		if ($hide)
			$this -> hide ($type_field);
	}
	function set_file_name ($name_field, $file_fields, $replace = true, $hide = false)	// Copyright by Mateusz Rusin © 2005 // 1.01
	{
		if (!is_array ($file_fields))
			$file_fields = array ($file_fields);
		foreach ($file_fields as $file_field)
			$this -> fields [$file_field] -> file_name = $name_field;
/*		if ($replace)
			$this -> fields [$file_field] -> replace = $replace;*/
		if ($hide)
			$this -> hide ($name_field);
	}
	function set_file ($field, $replace = false)	// Copyright by Mateusz Rusin © 2005 // 1.02
	{//echo '<pre>'; var_dump ($this -> fields);echo '</pre>'; 
		//$this -> fields ['file_' . $field] = $this -> fields [$field];
		//$this -> fields ['file_' . $field] -> type = 'file'; //echo '<pre>'; var_dump ($this -> fields);echo '</pre>'; 
		//if ($replace)
		//	$this -> unset_fields ($field); 
		$this -> fields [$field] -> type = 'file';
		if (!isset ($this -> fields [$field] -> blob))
			$this -> fields [$field] -> blob = true;
		if (empty ($this -> fields [$field] -> name));
			$this -> set_name ($field, $field);
	}
	function set_photo ($field, $url, $popup_url = null, $resampling = null)	// Copyright by Mateusz Rusin © 2005 // 1.03
	{
		$this -> set_file ($field, true);
		$this -> fields [$field] -> photo -> url = $url;
		if (!empty ($popup_url))
			$this -> fields [$field] -> photo -> popup_url = $popup_url;
		if (!empty ($resampling))
			$this -> fields [$field] -> photo -> resampling = $resampling;
	}
	function set_md5 ($field)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		$this -> fields [$field] -> type = 'md5';
	}
	function set_password ($field)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		//$this -> fields ['file_' . $field] = $this -> fields [$field];
		//$this -> fields ['file_' . $field] -> type = 'file';
	}
	function set_fields ($result = null)	// Copyright by Mateusz Rusin © 2005 // 1.01
	{
		if (empty ($result))
			$result = $this -> result;
		for ($i = 0; $i < $this -> db -> num_fields ($result); $i++)
		{
			$meta = $this -> db -> fetch_field ($result);
			$meta -> field_len = $this -> db -> field_len ($result, $i);
			/*if ($meta -> type == 'string' && !$meta -> blob)
			{
				$this -> db -> fetch_row = ($this -> db -> query ("show columns {$meta -> name} like '{$meta -> name} '"));
			$meta -> set = $this -> db -> field_len ($result, $i);
			}*/
			if ($meta -> primary_key)
				$this -> primary_key = ($meta -> name);
			$this -> fields [$meta -> name] = $meta;
			$this -> fields [$meta -> name] -> db_field = true;
			unset ($meta);
		}
	}
	function unset_fields ($fields)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		if (!is_array ($fields))
			$fields = array ($fields);
		foreach ($fields as $field)
			unset ($this -> fields [$field]);
	}
	function no_check ($fields)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		if (!is_array ($fields))
			$fields = array ($fields);
		foreach ($fields as $field)
			$this -> fields [$field] -> no_check = 'no_check';
	}
	function ignore ($fields)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		if (!is_array ($fields))
			$fields = array ($fields);
		foreach ($fields as $field)
		{
			$this -> fields [$field] -> no_check = 'ignore';
			if (empty ($this -> fields [$field] -> name));
				$this -> set_name ($field, $field);
		}
	}
	function set_primary_key ($field)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		$this -> fields -> $field -> primary_key = true;
	}
	function set_order_menu ($order)	// Copyright by Mateusz Rusin © 2005 // 1.00
	{
		if ($order)
			$this -> order_menu = $order;
	}
	function update ($table, $primary_key = 'id')	// Copyright by Mateusz Rusin © 2005 // 1.09
	{
		//echo '<pre>';
		if (!empty ($_POST))
			foreach ($_POST as $id => $fields)
			{
				if (substr ($id, 0, 3) == 'id_')
				{
					$id = substr ($id, 3);
					if (!empty ($id))
						if (empty ($_POST ['delete'] [$id]))
						{
							if (!empty ($_POST ['password']))
								foreach ($_POST ['password'] as $field_name => $password_type)
								{
									if (!empty ($fields [$field_name]) && $password_type == 'md5')
										$fields [$field_name] = md5 ($fields [$field_name]);
									else
										unset ($fields [$field_name]);
								}
							if (!empty ($_POST ['no_check']))
								foreach ($_POST ['no_check'] as $field_name => $no_check)
									if ($no_check == 'ignore')
									{
										$this -> ignored [$id] [$field_name] = $fields [$field_name];
										unset ($fields [$field_name]);
									}
							if (!empty ($_FILES ['id_' . $id] ['tmp_name']))
								foreach ($_FILES ['id_' . $id] ['tmp_name'] as $field_name => $file_tmp_name)
								{
									if (!empty ($file_tmp_name) && is_uploaded_file ($file_tmp_name))
									{
										if (empty ($_POST ['resampling'] [$field_name]))
										{
											$fields [$field_name] = file_get_contents ($file_tmp_name);
											if (!empty ($_POST ['file_name'] [$field_name]) && empty ($fields [$_POST ['file_name'] [$field_name]]))
												$fields [$_POST ['file_name'] [$field_name]] = $_FILES ['id_' . $id] ['name'] [$field_name];
											if (!empty ($_POST ['file_type'] [$field_name]))
												$fields [$_POST ['file_type'] [$field_name]] = $_FILES ['id_' . $id] ['type'] [$field_name];
										}
										else
										{
											if (strpos ($_FILES ['id_' . $id] ['type'] [$field_name], 'jpeg'))
												include_once ('resampling.php');
											else
												$file_content = file_get_contents ($file_tmp_name);
											foreach ($_POST ['resampling'] [$field_name] as $dest_field => $params)
												if ($field_name == $dest_field || empty ($_FILES ['id_' . $id] ['tmp_name'] [$dest_field]) || !is_uploaded_file ($_FILES ['id_' . $id] ['tmp_name'] [$dest_field]))
												{
													if (empty ($file_content))
													{
														if (empty ($params ['crop']))
															$fields [$dest_field] = scale ($file_tmp_name, $params ['width'], $params ['height']);
														else
															$fields [$dest_field] = crop ($file_tmp_name, $params ['width'], $params ['height']);
													}
													else
														$fields [$dest_field] = $file_content;
													if (!empty ($_POST ['file_name'] [$dest_field]) && empty ($fields [$_POST ['file_name'] [$dest_field]]))
														$fields [$_POST ['file_name'] [$dest_field]] = $_FILES ['id_' . $id] ['name'] [$field_name];
													if (!empty ($_POST ['file_type'] [$dest_field]))
														$fields [$_POST ['file_type'] [$dest_field]] = $_FILES ['id_' . $id] ['type'] [$field_name];
												}
											unset ($file_content);
										}
									}
									else
										unset ($fields [$field_name]);
									unset ($file_tmp_name);
								}
							$this -> db -> update ($table, array ($primary_key => $id), $fields);
						}
						elseif ($this -> delete)
							$this -> db -> delete ($table, array ($primary_key => $id));
					//var_dump ($id); echo '<br/ >'; var_dump ($fields); echo '<hr/ >';
				}
				elseif ($id == 'add')
				{
					if (!empty ($_FILES ['add'] ['tmp_name']))
						foreach ($_FILES ['add'] ['tmp_name'] as $field_name => $file_tmp_name)
						{
							if (!empty ($file_tmp_name) && is_uploaded_file ($file_tmp_name))
							{
								if (empty ($_POST ['resampling'] [$field_name]))
								{
									$fields [$field_name] = file_get_contents ($file_tmp_name);
									if (!empty ($_POST ['file_name'] [$field_name]) && empty ($fields [$_POST ['file_name'] [$field_name]]))
										$fields [$_POST ['file_name'] [$field_name]] = $_FILES ['add'] ['name'] [$field_name];
									if (!empty ($_POST ['file_type'] [$field_name]))
										$fields [$_POST ['file_type'] [$field_name]] = $_FILES ['add'] ['type'] [$field_name];
									$insert = true;
								}
								else
								{
									if (strpos ($_FILES ['add'] ['type'] [$field_name], 'jpeg'))
										include_once ('resampling.php');
									else
										$file_content = file_get_contents ($file_tmp_name);
									foreach ($_POST ['resampling'] [$field_name] as $dest_field => $params)
										if ($field_name == $dest_field || empty ($_FILES ['add'] ['tmp_name'] [$dest_field]) || !is_uploaded_file ($_FILES ['add'] ['tmp_name'] [$dest_field]))
										{
											if (empty ($file_content))
											{
												if (empty ($params ['crop']))
													$fields [$dest_field] = scale ($file_tmp_name, $params ['width'], $params ['height']);
												else
													$fields [$dest_field] = crop ($file_tmp_name, $params ['width'], $params ['height']);
											}
											else
												$fields [$dest_field] = $file_content;
											if (!empty ($_POST ['file_name'] [$dest_field]) && empty ($fields [$_POST ['file_name'] [$dest_field]]))
												$fields [$_POST ['file_name'] [$dest_field]] = $_FILES ['add'] ['name'] [$field_name];
											if (!empty ($_POST ['file_type'] [$dest_field]))
												$fields [$_POST ['file_type'] [$dest_field]] = $_FILES ['add'] ['type'] [$field_name];
											$insert = true;
										}
									unset ($file_content);
								}
							}
							else
								unset ($fields [$field_name]);
							unset ($file_tmp_name);
					}
					foreach ($_POST ['add']/*$fields*/ as $field_name => $field)
					{
						if (!empty ($_POST ['password'] [$field_name]))
						{
							if (!empty ($fields [$field_name]))
								$fields [$field_name] = md5 ($fields [$field_name]);
							else
								unset ($fields [$field_name], $field);
						}
						if 
							(
								!empty ($field) && 
								trim ($field) && 
								empty ($_POST ['no_check'] [$field_name]) && 
								$field != 'null' && 
								$field != 'nul' && 
								$field != 'auto' && 
								$field != 'aut' && 
								$field != 'no_check' &&
								$field != $this -> fields [$field] -> default_value
							)
								$insert = true;
						elseif (!empty ($_POST ['no_check'] [$field_name]) && $_POST ['no_check'] [$field_name] == 'ignore')
						{
							$this -> ignored ['add'] [$field_name] = $field;
							unset ($fields [$field_name], $field);
						}
					}
					if (!empty ($insert))
					{
						$this -> db -> insert ($table, $fields);
						$this -> insert_id = $this -> db -> insert_id ();
						if (empty ($this -> insert_id) && $this -> db -> affected_rows () > 0 && !empty ($fields [$primary_key]))
							$this -> insert_id = $fields [$primary_key];
					}
				}
			}
		//echo '</pre>';
	}
	function render ($result = null, $add_field = true)	// Copyright by Mateusz Rusin © 2005 // 1.16
	{
		if (empty ($result))
			$result = $this -> result;
		if ($this -> db -> num_rows ($result))
			$this -> db -> data_seek ($result, 0);
		$this -> form = '<form method="post" enctype="multipart/form-data">';
		foreach ($this -> fields as $field_name => $field_meta)
		{
			if (!empty ($field_meta -> type) && $field_meta -> type == 'datetime')
				$this -> form .= 
					$this -> make_input 
					(
						array
						(
							'name' => "no_check[$field_name]",
							'type' => 'hidden',
							'value' => 'no_check'
						)
					);				
			if (!empty ($field_meta -> no_check))
				$this -> form .= 
					$this -> make_input 
					(
						array
						(
							'name' => "no_check[$field_name]",
							'type' => 'hidden',
							'value' => $field_meta -> no_check
						)
					);				
			if (!empty ($field_meta -> type) && $field_meta -> type == 'md5')
				$this -> form .= 
					$this -> make_input 
					(
						array
						(
							'name' => "password[$field_name]",
							'type' => 'hidden',
							'value' => $field_meta -> type
						)
					);				
			if (!empty ($field_meta -> file_type))
				$this -> form .= 
					$this -> make_input 
					(
						array
						(
							'name' => "file_type[$field_name]",
							'type' => 'hidden',
							'value' => $field_meta -> file_type
						)
					);				
			if (!empty ($field_meta -> file_name))
				$this -> form .= 
					$this -> make_input 
					(
						array
						(
							'name' => "file_name[$field_name]",
							'type' => 'hidden',
							'value' => $field_meta -> file_name
						)
					);				
			if (!empty ($field_meta -> photo -> resampling))
			{
				if (!empty ($field_meta -> db_field) && !array_key_exists ($field_name, $field_meta -> photo -> resampling))
					$this -> form .= 
						$this -> make_input 
						(
							array
							(
								'name' => "resampling[$field_name][$field_name][width]",
								'type' => 'hidden',
								'value' => 0
							)
						)
						.
						$this -> make_input 
						(
							array
							(
								'name' => "resampling[$field_name][$field_name][height]",
								'type' => 'hidden',
								'value' => 0
							)
						);
				foreach ($field_meta -> photo -> resampling as $dest_field => $params)
					$this -> form .= 
						$this -> make_input 
						(
							array
							(
								'name' => "resampling[$field_name][$dest_field][width]",
								'type' => 'hidden',
								'value' => $params [0]
							)
						) 
						.
						$this -> make_input 
						(
							array
							(
								'name' => "resampling[$field_name][$dest_field][height]",
								'type' => 'hidden',
								'value' => $params [1]
							)
						)
						.
						(
						!empty ($params [2])
						?
						$this -> make_input 
						(
							array
							(
								'name' => "resampling[$field_name][$dest_field][crop]",
								'type' => 'hidden',
								'value' => $params [2]
							)
						)
						:
						''						
						);
			}
		}
		if ($add_field)
		{
			$this -> form .= '<fieldset><legend>' . $this -> ini -> get ('add_' . $this -> language) . '</legend>';
			foreach ($this -> fields as $field_name => $field_meta)
			{
				if (!empty ($field_meta -> select_menu))
				{//echo '<pre>';var_dump ($field_meta);echo '</pre>';
					$select_menu = $field_meta -> select_menu;
					foreach ($field_meta -> select_menu as $i => $menu_element)
						if (isset ($field_meta -> default_value) and $menu_element ['value'] == $field_meta -> default_value || array_search ($menu_element ['value'], explode (',', $field_meta -> default_value)) !== false)
							$select_menu [$i] ['selected'] = true;
					if (empty ($field_meta -> no_check))
						$this -> form .= 
							$this -> make_input 
							(
								array
								(
									'name' => "no_check[$field_name]",
									'type' => 'hidden',
									'value' => 'no_check'
								)
							);				
				}
				if (empty ($field_meta -> disabled))
					$this -> form .= 
						$this -> make_input 
						(
							array
							(
								'name' => "add[$field_name]",
								'label' => $field_meta -> name,
								'title' => !empty ($field_meta -> title) ? $field_meta -> title : false,
								'max_length' => empty ($select_menu) ? ($field_meta -> type == 'file' ? ($this -> ini -> get ('max_file_size') ? $this -> ini -> get ('max_file_size') : $this -> ini -> get ('download_size')) : $field_meta -> field_len) : $field_meta -> select_menu_size,
								'type' => !empty ($field_meta -> blob) 
									? 
										($field_meta -> type == 'file' ? 'file' : 'textarea') 
									: 
										(
											!empty ($select_menu) 
												? 
													'select' 
												: 
													($field_meta -> type == 'md5' ? 'password' : $field_meta -> type)
										),
								'value' => empty ($select_menu) 
									? 
										(
											!empty ($field_meta -> primary_key) && $field_meta -> type != 'string' 
												? 
													'auto' 
												: 
													(
														isset ($field_meta -> default_value)
															?
																$field_meta -> default_value
															:
																($field_meta -> type =='datetime' ? date ('Y-m-d H:i:s') : '')
													)
										) 
									: 
										$select_menu
							)
						);
				unset ($select_menu);
			}
			$this -> form .= '</fieldset>';
		}
		if ($this -> db -> num_rows ($result))
			while ($element = $this -> db -> fetch_array ($result)) 
			{
				$this -> form .= '<fieldset>';
				foreach ($this -> fields as $field_name => $field_meta)
				{
					if (!empty ($field_meta -> select_menu))
					{
						$select_menu = $field_meta -> select_menu;
						if (isset ($element [$field_name]))
							foreach ($field_meta -> select_menu as $i => $menu_element)
								if ($menu_element ['value'] == $element [$field_name] || array_search ($menu_element ['value'], explode (',', $element [$field_name])) !== false)
									$select_menu [$i] ['selected'] = true;
					}
					$no_photo = false;
					if (!empty ($field_meta -> photo -> resampling))
						foreach (array_keys ($field_meta -> photo -> resampling) as $photo_field_name)
							if (empty ($element [$photo_field_name]))
								$no_photo = true;
							else
							{
								$no_photo = false;
								break;
							}
					if ($no_photo && !empty ($field_meta -> db_field) && !empty ($element [$field_name]))
						$no_photo = false;
					$this -> form .= 
						!empty ($field_meta -> primary_key) 
						?
						'<legend id=' . $element [$field_name] . '>' . $element [$field_name] . '</legend>'
						:
						$this -> make_input 
						(
							array
							(
								'name' => 'id_' . $element [$this -> primary_key] . '[' . $field_name . ']',
								'label' => $field_meta -> name,
								'title' => !empty ($field_meta -> title) ? $field_meta -> title : false,
								'max_length' => empty ($select_menu) ? ($field_meta -> type == 'file' ? ($this -> ini -> get ('max_file_size') ? $this -> ini -> get ('max_file_size') : $this -> ini -> get ('download_size')) : $field_meta -> field_len) : $field_meta -> select_menu_size,
								'type' => !empty ($field_meta -> blob) 
									? 
										($field_meta -> type == 'file' ? 'file' : 'textarea') 
									: 
										(
											!empty ($select_menu) 
												? 
													'select' 
												: 
													($field_meta -> type == 'md5' ? 'password' : $field_meta -> type)
										),
								'value' => empty ($select_menu) 
									? 
										($field_meta -> type == 'file' || $field_meta -> type == 'md5' ? '' : $element [$field_name]) 
									: 
										$select_menu,
								'disabled' => empty ($field_meta -> disabled) ? false : true
							)
						) .
						(
						!empty ($field_meta -> photo) && empty ($no_photo)
						?
						(
						empty ($field_meta -> photo -> popup_url)
						?
						(
							empty ($field_meta -> photo -> resampling) && empty ($element [$field_name])
							?
								''
							:
								'<img src="' . $field_meta -> photo -> url . $element [$this -> primary_key] . '">'
						)
						:
							'<a href="' . $field_meta -> photo -> popup_url . $element [$this -> primary_key] . '" target="_blank"><img src="' . $field_meta -> photo -> url . $element [$this -> primary_key] . '"></a>'
						)
						:
						''
						);

					unset ($select_menu);
				}
				if ($this -> delete)
					$this -> form .= 
						$this -> make_input 
						(
							array
							(
								'name' => 'delete[' . $element [$this -> primary_key] . ']',
								'label' => $this -> ini -> get ('delete_' . $this -> language),
								'title' => !empty ($field_meta -> title) ? $field_meta -> title : false,
								'max_length' => true,
								'type' => 'checkbox',
								'value' => false
							)
						);
				$this -> form .= '</fieldset>';
			}
		$this -> form .= '
			<input type="reset" value="' . $this -> ini -> get ('reset_' . $this -> language) . '" class="button" title="' . $this -> ini -> get ('reset_title_' . $this -> language) . '" />
			<input type="submit" value="' . $this -> ini -> get ('submit_' . $this -> language) . '" class="button" title="' . $this -> ini -> get ('submit_title_' . $this -> language) . '" /></form>';
	}
	function get ($result = false, $add_field = true)	// Copyright by Mateusz Rusin © 2005 // 1.01
	{
		$this -> render ($result, $add_field);
		return $this -> form;
	}
	function make_form ($inputs, $name = null, $action = null, $method = 'post', $end_inputs_count = 0) // Copyright by Mateusz Rusin © 2005 // 1.00
	{
		$form = "\r\n<form " . (isset ($name) ? 'id="' . $name . '" name="' . $name . '"' : '') . 'method="' . $method . '"' . (isset ($action) ? ' action="' . $action . '">' : '>');
		$i = count ($inputs) - $end_inputs_count;	// liczba zwykłych inputów
		foreach ($inputs as $input_data)
		{
			if ($i--)												//	jeśli zwykły input
				$input_code = & $form;				//	to twórz formularz
			else														//	a jeśli końcowy
				$input_code = & $end_inputs;	//	to twórz końcówkę formularza
			$input_code .= $this -> make_input ($input_data);
		}
		$form .= (isset ($end_inputs) ? $end_inputs . '<hr />' : '') . "\r\n</form>";
		return $form;
	}
	function make_input ($input_data) // Copyright by Mateusz Rusin © 2005 // 1.01
	{
		//$name;
		//$label;
		$title = '';
		$max_length = 0;
		$value = '';
		$class= '';
		$type = 'text';
		$checked = false;
		foreach ($input_data as $data_name => $data_value)
			$$data_name = $data_value;
		if (is_string ($value))
			$value = htmlspecialchars ($value);
		$id = $name;
		switch ($type)
		{
			case 'html':
				$input = '$value';
				break;
			case 'select':
			case 'option':
				$input = '
					<label for="' . $id . '" class="' . $class . '" title="' . $title . '">' . $label . '
						<select id="' . $id . '" name="' . $name . ($max_length > 1 ? '[]' : '') . '" class="' . $class . '" size="' . $max_length . '" accesskey="' . menu :: access_key ($label) . ($max_length > 1 ? '" multiple="yes' : '') . (!empty ($disabled) ? ' disabled="true"' : '') .'">';
				foreach ($value as $v)
					$input .= '<option value="' . $v ['value'] . ((!empty ($v ['selected'])) ? '" selected="selected">' : '">') . $v ['name'] . '</option>';
				$input .= '</select></label>';
				break;
			case 'button':
				$input = '<button name="' . $name . '" value="' . $value . '" class="' . $class . '" type="submit">' . $label . '</button>';
				break;
			case 'link':
				$input = '
					<label class="' . $class . '" title="' . $title . '">' . $label . '
						<a href="' . $name . '" class="' . ($class ? $class : 'button') . '" accesskey="' . menu :: access_key ($label) . '">' . $value . '</a>
					</label>';
				break;
			case 'hidden':
				$input = '<input name="' . $name . '" type="' . $type . '" value="' . $value . '">';
				break;
			case 'textarea':
				$input = '
					<label for="' . $id . '" title="' . $title . '" class="' . $class . '">' . $label . '
						<textarea id="' . $id . '" name="' . $name . '" class="' . $class . '" accesskey="' . menu :: access_key ($label) . '">' .
						$value . '
						</textarea>
					</label>';
				break;			
			case 'file':
				$input = '
						<input name="MAX_FILE_SIZE" type="hidden" value="' . $max_length . '">
					<label for="' . $id . '" class="' . $class . '" title="' . $title . '">' . $label . '
						<input id="' . $id . '" name="' . $name . '" type="' . $type . '" value="' . $value . '" class="' . $class . '" accesskey="' . menu :: access_key ($label) . '">
					</label>';
				break;			
			case 'checkbox':
			case 'radio':
				$id .= $value;
				if ($value)
					$value = ' checked';
				$input = '
					<label for="' . $id . '" class="' . $class . '" title="' . $title . '">
						<input id="' . $id . '" name="' . $name . '" type="' . $type . '" class="checkbox" accesskey="' . menu :: access_key ($label) . '"' . $value . ($max_length === false || !empty ($disabled) ? ' disabled="true"' : '') . '>
						' . $label . '</label>';
				break;			
			default:
				$input = '
					<label for="' . $id . '" class="' . $class . '" title="' . $title . '">' . $label . '
						<input id="' . $id . '" name="' . $name . '" type="' . $type . '" maxlength="' . $max_length . '" value="' . $value . '" class="' . $class . '" accesskey="' . menu :: access_key ($label) . '"' . (($max_length == 'disabled' || $max_length === false || !empty ($disabled)) ? ' disabled="true"' : '') . '>
					</label>';
		}
		return $input;
	}
}//<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
?>
