<?php
/**
 * @package linea21.core
 * @subpackage level
 * @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');
}
////////////

if (isset($_GET['id']))	$id=$_GET['id'];
if (isset($_POST['id'])) $id=$_POST['id'];

$level_object= new level;

$mask_statut_P='';
$mask_statut_D='';

$requete=SQL_getonelevel($id);
$data=$sql_object->DBSelect($requete, 'OBJECT');
$display_title=formatText($data[0]->level_name, '2HTML');

$form_denomination=formatText($data[0]->level_name, '2FIELD');
$form_description=formatText($data[0]->level_description, '2FIELD');
$form_comment=formatText($data[0]->level_comment, '2FIELD');
$form_visual_identity=$data[0]->level_visual_identity;

if(!empty($form_visual_identity)) {
	$complete_uri="../".$data[0]->level_visual_identity;
	$complete_uri=EnlargeImage($complete_uri);
} else $complete_uri=_t('divers','novisu');

$form_statut_level=$data[0]->level_statut;
$form_range=$data[0]->level_range;


if(isset($_POST['valider'])) {		
	$table[0]=$_POST['denomination'];
	$table[1]=$_POST['description'];
	$table[2]=$_POST['com_level'];
	$table[3]=$form_visual_identity;
	$table[4]=$form_range;
	$table[5]=$_POST['statut'];
	
	$integrity=$level_object->CheckDataIntegrity($table);
	if(is_string($integrity)) $format_text='2FIELD'; else $format_text='HTML';
	
	$form_denomination=formatText($_POST['denomination'], $format_text);
	$form_description=formatText($_POST['description'], $format_text);
	$form_comment=formatText($_POST['com_level'], $format_text);
	$form_statut_level=$_POST['statut'];

	$table=urlencode(serialize($table));
   }

if(isset($_POST['enregistrer'])) {
	include_once('../class/system/class.upload.php');
	$upload_object= new upload;
	$data_table=unserialize(urldecode($_POST['data_table']));
	$result=$level_object->ModifyLevel($id, $data_table, $sql_object);
	$visual_uri="../".$data_table[3];
	$result_rename=$upload_object->Archivefile($visual_uri);
	$link_confirm="confirm.php?rub=".$rub."&todo=".$todo."&id=".$id;
	if($result) header("Location: ".$link_confirm);
	else  system_error();
}


if($form_statut_level=='P') $mask_statut_P=' checked="checked"';
if($form_statut_level=='D') $mask_statut_D=' checked="checked"';
?>
<div id="chemin">
	<ul>
		<li>
			<a href="index.php" class="chemin_home"><?php echo _t('way','home'); ?></a>
		</li>
		<li>
			   <a href="<?php echo $rub_link; ?>" id="chemin_<? echo $rub; ?>" class="chemin_rub"><?php echo _t('menu','level'); ?></a>
		</li>
		<li>
			<span><?php echo formatNavTitle(_t('level','mod').' : '.$display_title); ?></span>
		</li>
	</ul>
</div>
<!--end barre haute -->
<?php
include_once(THEME_ADMIN_PATH."quickicons.php");
// select box statut
	$select_statut="<!--";
	$select_statut.="<label for=\"statut_P\" >"._t('divers','statut') ." : *</label>\n";
	$select_statut.="<input type=\"radio\" name=\"statut\" id=\"statut_P\" value=\"P\"".$mask_statut_P." /><span class=\"radio\">"._t('statut','public')."</span>\n";
	$select_statut.="<input type=\"radio\" name=\"statut\" id=\"statut_D\" value=\"D\"".$mask_statut_D." /><span class=\"radio\">"._t('statut','draft')."</span>\n";
	$select_statut.='-->';
	$select_statut.='<input name="statut" type="hidden" id="statut" value="P" />'.END_LINE;
	
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><?php echo formatTitleh2($display_title); ?></h2>
			<form id="modlevel" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
				<p>
				<label for="denomination"><?php echo _t('level','denomination'); ?> : *</label>
				<input name="denomination" type="text" id="denomination" maxlength="200" value="<?php echo $form_denomination; ?>" class="textfield"/>
				</p>
				<p>
				<label for="description"><?php echo _t('level','description'); ?> : </label>
				<textarea id="description" name="description" class="largetextfield" <?php echo AREA_SETTINGS; ?>><?php echo $form_description; ?></textarea>
				<br />
				</p>
				<p>
				<label for="com_level"><?php echo _t('level','comment'); ?> : </label>
				<textarea id="com_level" name="com_level" class="largetextfield" <?php echo AREA_SETTINGS; ?> ><?php echo $form_comment; ?></textarea>
				<br />
				</p>	
				<p>
				<?php echo $select_statut; ?>
				</p>
				<p>
				<label for="img"><?php echo _t('level','visual_identity'); ?> :</label>
				<?php echo $complete_uri; ?>
				</p>
				<div>
				<input name="id" type="hidden" value="<?php echo $id; ?>" id="id" />
				<input name="rub" type="hidden" value="<?php echo $rub; ?>" id="rub" />
				<?php echo cancel_button('javascript:history.go(-1);'); ?>
				<input name="todo" type="hidden" value="<?php echo $todo; ?>" id="todo" />
				<input name="valider" type="submit" value="<?php echo _t('btn','valid') ?>" class="button" id="valider" />
				</div>
			</form>
		</div>
		<?php include_once($dir."/help.php"); ?>
</div>
<?php
// Récapitulatif
} else	{


?>
<div class="contentcontainer">
		<?php
		include_once($dir."/menurub.php");
		?>
		<div id="content">
			<h2><?php echo formatTitleh2(_t('recap','title')); ?></h2>
			<dl class="dl3">
				<dt><?php echo _t('level','denomination'); ?> : </dt>
				<dd><?php echo $form_denomination; ?><br /></dd>
				
				<dt><?php echo _t('level','description'); ?> : </dt>
				<dd><?php echo empty_none($form_description); ?><br /></dd>
				
				<dt><?php echo _t('level','comment'); ?> : </dt>
				<dd><?php echo empty_none($form_comment); ?><br /></dd>
				<!--
				<dt><?php echo _t('divers','statut'); ?> : </dt>
				<dd><?php echo display_statut($form_statut_level); ?><br /></dd>		
				-->
				<dt><?php echo _t('level','visual_identity'); ?></dt>
				<dd><?php echo $complete_uri; ?><br /></dd>
			
			</dl>
			<form id="modlevel" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
				<div>
				<input name="id" type="hidden" value="<?php echo $id; ?>" id="id" />
				<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=level&amp;todo=list'); ?>
				<input name="retour" type="button" value="<?php echo _t('btn','preview') ?>" class="button" id="retour" onclick="history.go(-1);" />
				<input name="enregistrer" type="submit" value="<?php echo _t('btn','save') ?>" class="button" id="valider" />
				</div>
			</form>
		</div>
		<?php include_once($dir."/help.php"); ?>
</div>
<?php
}
?>
