forked from Public/pics
		
	
		
			
				
	
	
		
			101 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			101 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
/*****************************************************************************
 | 
						|
 * InlineFormView.php
 | 
						|
 * Contains the template that renders inline forms.
 | 
						|
 *
 | 
						|
 * Kabuki CMS (C) 2013-2025, Aaron van Geffen
 | 
						|
 *****************************************************************************/
 | 
						|
 | 
						|
class InlineFormView
 | 
						|
{
 | 
						|
	public static function renderInlineForm($form)
 | 
						|
	{
 | 
						|
		if (!isset($form['is_embed']))
 | 
						|
			echo '
 | 
						|
			<form action="', $form['action'], '" method="', $form['method'], '" class="', $form['class'], '">';
 | 
						|
		else
 | 
						|
			echo '
 | 
						|
			<div class="', $form['class'], '">';
 | 
						|
 | 
						|
		if (!empty($form['is_group']))
 | 
						|
			echo '
 | 
						|
				<div class="input-group">';
 | 
						|
 | 
						|
		if (!empty($form['fields']))
 | 
						|
		{
 | 
						|
			foreach ($form['fields'] as $name => $field)
 | 
						|
			{
 | 
						|
				if ($field['type'] === 'select')
 | 
						|
				{
 | 
						|
					echo '
 | 
						|
					<select class="form-select" name="', $name, '"', (isset($field['onchange']) ? ' onchange="' . $field['onchange'] . '"' : ''), '>';
 | 
						|
 | 
						|
					foreach ($field['values'] as $value => $caption)
 | 
						|
					{
 | 
						|
						if (!is_array($caption))
 | 
						|
						{
 | 
						|
							echo '
 | 
						|
						<option value="', $value, '"', $value === $field['selected'] ? ' selected' : '', '>', $caption, '</option>';
 | 
						|
						}
 | 
						|
						else
 | 
						|
						{
 | 
						|
							$label = $value;
 | 
						|
							$options = $caption;
 | 
						|
 | 
						|
							echo '
 | 
						|
						<optgroup label="', $label, '">';
 | 
						|
 | 
						|
							foreach ($options as $value => $caption)
 | 
						|
							{
 | 
						|
								echo '
 | 
						|
							<option value="', $value, '"', $value === $field['selected'] ? ' selected' : '', '>', $caption, '</option>';
 | 
						|
							}
 | 
						|
 | 
						|
							echo '
 | 
						|
						</optgroup>';
 | 
						|
						}
 | 
						|
					}
 | 
						|
 | 
						|
					echo '
 | 
						|
					</select>';
 | 
						|
				}
 | 
						|
				else
 | 
						|
					echo '
 | 
						|
					<input name="', $name, '" id="field_', $name, '" type="', $field['type'], '" placeholder="', $field['placeholder'], '" class="form-control', isset($field['class']) ? ' ' . $field['class'] : '', '"', isset($field['value']) ? ' value="' . htmlspecialchars($field['value']) . '"' : '', '>';
 | 
						|
 | 
						|
				if (isset($field['html_after']))
 | 
						|
					echo $field['html_after'];
 | 
						|
			}
 | 
						|
		}
 | 
						|
 | 
						|
		echo '
 | 
						|
					<input type="hidden" name="', Session::getSessionTokenKey(), '" value="', Session::getSessionToken(), '">';
 | 
						|
 | 
						|
		if (!empty($form['buttons']))
 | 
						|
			foreach ($form['buttons'] as $name => $button)
 | 
						|
			{
 | 
						|
				echo '
 | 
						|
					<button class="btn ', isset($button['class']) ? $button['class'] : 'btn-primary', '" type="', $button['type'], '" name="', $name, '"';
 | 
						|
 | 
						|
				if (isset($button['onclick']))
 | 
						|
					echo ' onclick="', $button['onclick'], '"';
 | 
						|
 | 
						|
				echo '>', $button['caption'], '</button>';
 | 
						|
 | 
						|
				if (isset($button['html_after']))
 | 
						|
					echo $button['html_after'];
 | 
						|
			}
 | 
						|
 | 
						|
		if (!empty($form['is_group']))
 | 
						|
			echo '
 | 
						|
				</div>';
 | 
						|
 | 
						|
		if (!isset($form['is_embed']))
 | 
						|
			echo '
 | 
						|
			</form>';
 | 
						|
		else
 | 
						|
			echo '
 | 
						|
			</div>';
 | 
						|
	}
 | 
						|
}
 |