<?php
include_once(__DIR__."/../../core.php");

echo '
<form action="" method="post" role="form">
	<input type="hidden" name="backto" value="record-edit">
	<input type="hidden" name="op" value="update">
	<div class="pull-left">
		<button type="submit" class="btn-app btn-success"><i class="fa fa-check"></i> ' . _("Salva") . '</button>
	</div>
	<div class="clearfix"></div><br>
	<!-- DATI -->
	<div class="panel panel-<?php echo $_SESSION['profilo_pannello'] ?>">
		<div class="panel-heading">
			<h3 class="panel-title">' . _("Valori della sezione") . '</h3>
		</div>

		<div class="panel-body">
			
			';
foreach ($records as $record) {
	// Scelta fra più valori
	echo '
			<div class="col-xs-12 col-md-6">';
	if (preg_match("/list\[(.+?)\]/", $record['tipo'], $m)) {
		$m = explode(",", $m[1]);
		$list = "";
		for($j = 0; $j < sizeof($m); $j ++) {
			if ($j != 0) $list .= ",";
			$list .= "\\\"" . $m[$j] . "\\\": \\\"" . $m[$j] . "\\\"";
		}
		echo '
				{[ "type": "select", "label": "' . $record['nome'] . '", "name": "' . $record['idimpostazione'] . '", "required": 0, "class": "", "values": "list=' . $list . '", "value": "' . $record['valore'] . '", "extra": "" ]}';
	}

	// query
	else if (preg_match("/^query=(.+?)$/", $record['tipo'], $m)) {
		echo '
				{[ "type": "select", "label": "' . $record['nome'] . '", "name": "' . $record['idimpostazione'] . '", "required": 0, "class": "", "values": "' . $record["tipo"] . '", "value": "' . $record['valore'] . '", "extra": "" ]}';
	}

	// Boolean (checkbox)
	else if ($record['tipo'] == 'boolean') {
	$checkbox .= $record['idimpostazione'] . ",";
		echo '
				{[ "type": "checkbox", "label": "' . $record['nome'] . '", "name": "' . $record['idimpostazione'] . '", "placeholder": "' . _("Attivo") . '", "required": 0, "class": "", "value": "", "extra": "';
		if ($record['valore'] == 1) echo ' checked';
		echo '" ]}';
	}
	else if ($record['tipo'] == 'textarea') {
		echo '
				{[ "type": "textarea", "label": "' . $record['nome'] . '", "name": "' . $record['idimpostazione'] . '", "required": 0, "class": "autosize", "value": "' . $record['valore'] . '", "extra": "" ]}';
	}
	// Campo di testo normale
	else {
		$tipo = (preg_match("/password/i", $record['nome'], $m)) ? "password" : "text";
		echo '
				{[ "type": "' . $tipo . '", "label": "' . $record['nome'] . '", "name": "' . $record['idimpostazione'] . '", "required": 0, "class": "", "value": "' . $record['valore'] . '", "extra": "" ]}';
	}
	echo '
			</div>';
}
echo '
		</div>
	</div>

</form>';
?>
