<?php
/**
 * Indicator / SDI module - modify assessment information
 * 
 * Modify given assessment indicator from back-office
 * 
 * @package linea21\modules\sdi
 * @author $Author$ - linea21 <info@linea21.com>
 * @version $Id$ 
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */

//////////// Check Inclusion de pages ////////////
if (!class_exists('auth')){
  include_once("../lib/lib_common.php");
  ReloadIndex('admin');
}
////////////

//////////// Check Droits utilisateur ////////////
if (!$l21auth->isSuperAdmin()) ReloadIndex('admin');
////////////

$table="";
$link_mod_r=$rub_link."&amp;todo=mod_r&amp;id=";
$link_mod_p=$rub_link."&amp;todo=mod_p&amp;id=";
$link_mod=$rub_link."&amp;todo=mod&amp;id=";

if(!isset($_GET['id']) && !isset($_POST['id'])) {
  $id="1";
} else {
  if(isset($_POST['id']))	$id=$_POST['id'];
  if(isset($_GET['id']))	$id=$_GET['id'];
}


if (isset($_POST['enregistrer'])) {
  $data_table = unserialize(urldecode($_POST['data_table']));
  $j=0;
  for ($i=13;$i<19;$i++){
    $data_table_e[$j]=$data_table[$i];
    $j++;
  }
  $sdi_object= new sdi;
  $result=$sdi_object->ModifyParam($id, $data_table_e, "E", $sql_object);
  $link_confirm="confirm.php?rub=".$rub."&todo=".$todo."&id=".$id;
  if(isset($result)) header("Location: ".$link_confirm);
  else  system_error();
}

$sdi_object= new sdi;
//$data_evaluation=$sdi_object->GetEvaluation($id_idd=$id, $sql_object, $ID="-1");
$req_sdie=SQL_getEvaluation($id, $sql_object);
$data_evaluation = $sql_object -> DBSelect($req_sdie);

// Do record exists?
if(!isset($data_evaluation[0]['sdie_scale_compare'])) redirect_to('@module_default');

$form_e_scale_compare = $data_evaluation[0]['sdie_scale_compare'];
$form_e_fiability = $data_evaluation[0]['sdie_fiability'];
$form_e_accessibility = $data_evaluation[0]['sdie_accessibility'];
$form_e_lisibility = $data_evaluation[0]['sdie_lisibility'];
$form_e_relevance = $data_evaluation[0]['sdie_relevance'];
$form_e_global_performance =$data_evaluation[0]['sdie_global_performance'];

if (isset($_POST['valider2'])) {
  $table[13] = $_POST['e_scale_compare'];
  $table[14] = $_POST['e_fiability'];
  $table[15] = $_POST['e_accessibility'];
  $table[16] = $_POST['e_lisibility'];
  $table[17] = $_POST['e_relevance'];
  $table[18] = $_POST['e_global_performance'];
  $sdi_object = new sdi;
  $integrity2 = $sdi_object -> CheckDataIntegrity_eval($table);

  $form_e_scale_compare = $_POST['e_scale_compare'];
  $form_e_fiability = $_POST['e_fiability'];
  $form_e_accessibility = $_POST['e_accessibility'];
  $form_e_lisibility = $_POST['e_lisibility'];
  $form_e_relevance = $_POST['e_relevance'];
  $form_e_global_performance = $_POST['e_global_performance'];

  $table = urlencode(serialize($table));
}
$req_list_sdiname=SQL_getOnesdiname($id);
$data_sdi_name = $sql_object -> DBSelect($req_list_sdiname);

// Do record exists?
if(!isset($data_sdi_name[0]['sdii_name'])) redirect_to('@module_default');

$navtitle=_t('sdi','mod_e')." : ".$data_sdi_name[0]['sdii_name'];
?>

<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_<?php echo $rub; ?>" class="chemin_rub"><?php echo _t('menu','sdi')?></a></li>
	<li><span><?php echo formatnavTitle($navtitle) ?></span></li>
</ul>
</div>

<?php

if (!isset($integrity2) || is_string($integrity2)) {

?>
<div class="contentcontainer">
<?php
include_once(override($dir.'/menurub.php', THEME_ADMIN_PATH));
?>
<div id="content">
<?php
if (isset($integrity2) && is_string($integrity2)) display_errors($integrity2);
?>
<div class="mod_link">
<a href="<?php echo $link_mod.$id ;?>"><?php echo _t('sdi','mod'); ?></a><!-- @whitespace
--><a href="<?php echo $link_mod_p.$id ;?>"><?php echo _t('sdi','modify_sdi_p');?></a><!-- @whitespace
--><a href="<?php echo $link_mod_r.$id ;?>"><?php echo _t('sdi','modify_sdi_r');?></a>
</div>
<br class="brendstep" />

<h2><?php echo mb_ucfirst(_t('sdi','mod_title2')); ?></h2>
<div class="subtitle" id="indicator-subtitle"><?php echo formatText($data_sdi_name[0]['sdii_name'], '2HTML'); ?></div>
<form id="addsdi2" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
	<p>
		<label for="e_scale_compare"><?php echo mb_ucfirst(_t('sdi','e_scale_compare')) ?> : </label>
		<input name="e_scale_compare" type="text" class="textfield" id="e_scale_compare" maxlength="3" value="<?php echo $form_e_scale_compare; ?>" />
	</p>
	<p>
		<label for="e_fiability"><?php echo mb_ucfirst(_t('sdi','e_fiability')) ?> : </label>
		<input name="e_fiability" type="text" class="textfield" id="e_fiability" maxlength="3" value="<?php echo $form_e_fiability; ?>" />
	</p>
	<p>
		<label for="e_accessibility"><?php echo mb_ucfirst(_t('sdi','e_accessibility')) ?> : </label>
		<input name="e_accessibility" type="text" class="textfield" id="e_accessibility" maxlength="3" value="<?php echo $form_e_accessibility; ?>" />
	</p>
	<p>
		<label for="e_lisibility"><?php echo mb_ucfirst(_t('sdi','e_lisibility')) ?> : </label>
		<input name="e_lisibility" type="text" class="textfield" id="e_lisibility" maxlength="3" value="<?php echo $form_e_lisibility; ?>" />
	</p>
	<p>
		<label for="e_relevance"><?php echo mb_ucfirst(_t('sdi','e_relevance')) ?> : </label>
		<input name="e_relevance" type="text" class="textfield" id="e_relevance" maxlength="3" value="<?php echo $form_e_relevance; ?>" />
	</p>
	<p>
		<label for="e_global_performance"><?php echo mb_ucfirst(_t('sdi','e_global_performance')) ?> : </label>
		<input name="e_global_performance" type="text" class="textfield" id="e_global_performance" maxlength="3" value="<?php echo $form_e_global_performance; ?>" />
	</p>

	<div>
		<input name="table" type="hidden" value="<?php echo $table; ?>" id="table" />
		<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" />
		<?php echo cancel_button($rub_link."&amp;todo=det&amp;id=".$id); ?>
		<input name="valider2" type="submit" value="<?php echo _t('btn','valid') ?>" class="button" id="valider" />
	</div>
</form>
</div> <!-- closing #content -->
</div> <!-- closing .contentcontainer -->

        <?php
} else {
  if (!isset($integrity5) || is_string($integrity5)) {


    $table=unserialize(urldecode($table));

    $display_e_scale_compare = empty_nc($table[13]);
    $display_e_fiability = empty_nc($table[14]);
    $display_e_accessibility = empty_nc($table[15]);
    $display_e_lisibility = empty_nc($table[16]);
    $display_e_relevance = empty_nc($table[17]);
    $display_e_global_performance = empty_nc($table[18]);
    $table = urlencode(serialize($table));

    ?>
<div class="contentcontainer">
<?php
include_once(override($dir.'/menurub.php', THEME_ADMIN_PATH));
?>
<div id="content">
<h2><?php echo mb_ucfirst(_t('recap','title')) ; ?></h2>
<div class="subtitle" id="indicator-subtitle"><?php echo formatText($data_sdi_name[0]['sdii_name'], '2HTML'); ?></div>
<dl class="summary">
	<dt><?php echo mb_ucfirst(_t('sdi','e_scale_compare'));?> :</dt>
	<dd><?php echo $display_e_scale_compare; ?><br />
	</dd>
	<dt><?php echo mb_ucfirst(_t('sdi','e_fiability')); ?> :</dt>
	<dd><?php echo $display_e_fiability; ?><br />
	</dd>
	<dt><?php echo mb_ucfirst(_t('sdi','e_accessibility')); ?> :</dt>
	<dd><?php echo $display_e_accessibility; ?><br />
	</dd>
	<dt><?php echo mb_ucfirst(_t('sdi','e_lisibility')); ?> :</dt>
	<dd><?php echo $display_e_lisibility; ?><br />
	</dd>
	<dt><?php echo mb_ucfirst(_t('sdi','e_relevance')); ?> :</dt>
	<dd><?php echo $display_e_relevance; ?><br />
	</dd>
	<dt><?php echo mb_ucfirst(_t('sdi','e_global_performance')); ?> :</dt>
	<dd><?php echo $display_e_global_performance ; ?><br />
	</dd>
</dl>
<form id="addsdi5" 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="id" type="hidden" value="<?php echo $id; ?>" id="id" />
		<?php echo cancel_button($rub_link."&amp;todo=det&amp;id=".$id); ?>
		<input name="data_table" type="hidden" value="<?php echo $table; ?>" id="data_table" />
		<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> <!-- closing #content -->
</div> <!-- closing .contentcontainer -->
<?php
  }
}
?>