<?php
/**
 * @package linea21.core
 * @subpackage scale
 * @author linea21 <info@linea21.com>
 * @version $id SVN
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */

//////////// Check Inclusion de pages //////////// 
if (!function_exists('AuthenthificationProcess')){ 
include_once("../lib/lib_common.php");
ReloadIndex('admin');
}
////////////
?><div id="chemin">
	<ul>
		<li>
			<a href="index.php" class="chemin_home"><? echo _t('way','home'); ?></a>
		</li>
		<li>
			   <a href="<?php echo $rub_link; ?>" id="chemin_<? echo $rub; ?>" class="chemin_rub"><? echo _t('menu','scale'); ?></a>
		</li>
		<li>
			<span><? echo formatnavTitle(_t('scale','add')); ?></span>
		</li>
	</ul>
</div>
<!--end barre haute -->
<?php
if(isset($_POST['enregistrer'])) {
	$data_table=unserialize(urldecode($_POST['data_table']));
	$scale_object= new scale;
	$result=$scale_object->AddScale($data_table, $sql_object);
	$link_confirm="confirm.php?rub=".$rub."&todo=".$todo;
	if(is_numeric($result)) header("Location: ".$link_confirm);
	else  system_error();
}

$form_denomination='';
$form_comment='';
$form_surface='';
$form_population='';
$form_root_scale=-1;
if(isset($_POST['valider'])) {
	$table[0]=$_POST['denomination'];
	$table[1]=$_POST['surface'];
	$table[2]=$_POST['population'];
	$table[3]=$_POST['root_scale'];
	$table[4]=$_POST['com_scale'];
	$table[5]='P'; // statut
	$scale_object= new scale;
	$integrity=$scale_object->CheckDataIntegrity($table);
	if(is_string($integrity)) $format_text='2FIELD';
	else $format_text='2HTML';
	$form_denomination=formatText($_POST['denomination'], $format_text);
	$form_surface=$_POST['surface'];
	$form_population=$_POST['population'];
	$form_comment=formatText($_POST['com_scale'], $format_text);
	$form_root_scale=$_POST['root_scale'];
	$table=urlencode(serialize($table));
}
include_once(THEME_ADMIN_PATH."quickicons.php");

include_once("../lib/input_helpers.php");
// select-box des échelles
$data=$sql_object->DBSelect($req_add);
$select_root=ScaleSelectBox($data, "root_scale", $form_root_scale);
?>

<?php
if(!isset($integrity) || is_string($integrity)) {
?>
<div class="contentcontainer">
		<?php
		include_once($dir."/menurub.php");
		?>
		<div id="content">
			<?php
			if(isset($integrity) && is_string($integrity)) display_errors($integrity);
			?>
			<h2><? echo formatTitleh2(_t('scale','add_title')); ?></h2>
			<form id="addscale" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
				<p>
				<label for="denomination" ><? echo _t('scale','denomination') ?> : *</label>
				<input name="denomination" type="text" id="denomination" maxlength="200" value="<?php echo $form_denomination; ?>" class="textfield"/>
				</p>
				<p>
				<label for="surface" ><? echo _t('scale','surface') ?> (<?php echo SURFACE_UNIT; ?>) :</label>
				<input name="surface" type="text" id="surface" maxlength="8" value="<?php echo $form_surface; ?>" class="textfield" />
				</p>
				<p>
				<label for="population" ><? echo _t('scale','population') ?> :</label>
				<input name="population" type="text" id="population" maxlength="8" value="<?php echo $form_population; ?>" class="textfield" />
				</p>
				<p>
				<label for="root_scale" ><? echo _t('scale','root') ?> : *</label>
				<?php echo $select_root; ?>
				</p>
				<p>
				<label for="com_scale" ><? echo _t('scale','comment') ?> : </label>
				<textarea id="com_scale" name="com_scale" class="largetextfield" <?php echo AREA_SETTINGS; ?> ><?php echo $form_comment; ?></textarea>
				<br />
				</p>
				<div>
				<input name="rub" type="hidden" value="<?php echo $rub; ?>" id="rub" />
				<input name="todo" type="hidden" value="<?php echo $todo; ?>" id="todo" />
				<?php echo cancel_button('javascript:history.go(-1);'); ?>
				<input name="valider" type="submit" value="<? echo _t('btn','valid') ?>" class="button" id="valider" />
				</div>
			</form>
		</div>
<?php include_once($dir."/help.php"); ?>
</div>
<?php
// Récapitulatif
} else	{
$display_form_comment=empty_none($form_comment);
$display_form_surface=empty_nc($form_surface);
$display_form_population=empty_nc($form_population);

$requete=SQL_getonescale($_POST['root_scale']);
$data=$sql_object->DBSelect($requete);
$display_root_scale=formatText($data[0]['scale_denomination'], '2HTML');

?>
<div class="contentcontainer">
<?php
include_once($dir."/menurub.php");
?>
<div id="content">
			<h2><? echo formatTitleh2(_t('recap','title')); ?></h2>
			<dl class="dl3">
				<dt><? echo _t('scale','denomination'); ?> : </dt>
				<dd><?php echo $form_denomination; ?><br /></dd>
				<dt><? echo _t('scale','surface'); ?> (<?php echo SURFACE_UNIT; ?>) :</dt>
				<dd><?php echo $display_form_surface; ?><br /></dd>
				<dt><? echo _t('scale','population'); ?> :</dt>
				<dd><?php echo $display_form_population; ?><br /></dd>
				<dt><? echo _t('scale','root'); ?> : </dt>
				<dd><?php echo $display_root_scale; ?><br /></dd>
				<dt><? echo _t('scale','comment'); ?> : </dt>
				<dd><?php echo $display_form_comment; ?><br /></dd>
			</dl>
			<form id="addscale" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
				<div>
				<input name="rub" type="hidden" value="<?php echo $rub; ?>" id="rub" />
				<input name="todo" type="hidden" value="<?php echo $todo; ?>" id="todo" />
				<input name="data_table" type="hidden" value="<?php echo $table; ?>" id="data_table" />
				<?php echo cancel_button('?rub='.$rub.'&amp;todo=list'); ?>
				<input name="retour" type="button" value="<? echo _t('btn','preview') ?>" class="button" id="retour" onclick="history.go(-1);" />
				<input name="enregistrer" type="submit" value="<? echo _t('btn','save') ?>" class="button" id="valider" />
				</div>
			</form>
		</div>
	<?php include_once($dir."/help.php"); ?>
</div>
<?php
}
?>
