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

include_once("../lib/input_helpers.php");
if (!isset($_GET['value_id']) && !isset($_POST['value_id'])) {
    $value_id = 1;
} else {
    if (isset($_POST['value_id'])) $value_id = $_POST['value_id'];
    if (isset($_GET['value_id'])) $value_id = $_GET['value_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($_GET['scale_id']) && !isset($_POST['scale_id'])) {
    $scale_id = 1;
} else {
    if (isset($_POST['scale_id'])) $scale_id = $_POST['scale_id'];
    if (isset($_GET['id'])) $scale_id = $_GET['scale_id'];
} 

$sdi_object = new sdi;
$req_sdiov=SQL_getOneValue($value_id);	
$result_value = $sql_object -> DBSelect($req_sdiov);
//$result_value = $sdi_object -> GetOneValue($value_id, $sql_object);

$link_mod_sdi = "index.php?&amp;rub=sdi&amp;todo=det&amp;id=";
$link_cancel=$rub_link."&amp;todo=det&amp;id=".$id."&amp;scale_id=".$scale_id;

if (isset($_POST['enregistrer'])) {
    $data_table = unserialize(urldecode($_POST['data_table']));
    $sdi_object = new sdi;
    $result = $sdi_object -> ModifyValue($value_id, $data_table, $sql_object);
	$link_confirm="confirm.php?rub=".$rub."&todo=".$todo."&id=".$id."&scale_id=".$scale_id;
    if (isset($result)) header("Location: " . $link_confirm);
    else system_error();
} 
$form_value = $result_value[0]['sdiv_value'];
$form_sdi_id = $id;
$form_scale_id = $scale_id;
$form_date = $result_value[0]['date_p'];
$form_statut = $result_value[0]['sdiv_statut'];
if($form_statut=='D') $mask_statut_D="checked=\"checked\""; else $mask_statut_D='';
if($form_statut=='P') $mask_statut_P="checked=\"checked\""; else $mask_statut_P='';

if (isset($_POST['valider1'])) {

    $table[0] = $_POST['value'];
    $table[1] = $_POST['id'];
    $table[2] = $_POST['scale'];
    $table[3] = $_POST['date'];
    $table[4] = $_POST['statut'];

    $sdi_object = new sdi;
    $integrity = $sdi_object -> CheckDataIntegrity_value($table, $sql_object);

    $form_value = $_POST['value'];
    $form_sdi_id = $_POST['id'];
    $form_scale_id = $_POST['scale'];
    $form_date = $_POST['date'];
    $form_statut = $_POST['statut'];
	if($form_statut=='D') $mask_statut_D="checked=\"checked\""; else $mask_statut_D='';
	if($form_statut=='P') $mask_statut_P="checked=\"checked\""; else $mask_statut_P='';
    $table = urlencode(serialize($table));
} 

include_once("quickicons.php");
$resultscale = $sql_object -> DBSelect($req_list_scale);
$listing=ScaleSelectBox($resultscale, "scale" ,$form_scale_id);	

$req_sdii=SQL_getInfoSdi($id);
$result_sdii = $sql_object -> DBSelect($req_sdii);

$navtitle=$GLOBALS['lang']['dashboard']['mod']." : ".$result_sdii[0]['sdii_name'];	
?>
<div id="chemin">
	<ul>
		<li>
			<a href="index.php"><?php echo $GLOBALS['lang']['way']['home']; ?></a>
		</li>
		<li>
			<a href="<?php echo $rub_link;

?>"><?php echo $GLOBALS['lang']['menu']['dashboard']; ?></a>
		</li>
		<li>
			<span><?php echo formatnavTitle($navtitle); ?></span>
		</li>
	</ul>
</div>
<!--end barre haute -->


<script type="text/javascript" charset="utf-8">
    Date.format = '<?php echo DATE_FORMAT ?>';
    
	$.dpText = {
	TEXT_PREV_YEAR		:	'<?php echo $GLOBALS['lang']['datePicker']['TEXT_PREV_YEAR']; ?>',
	TEXT_PREV_MONTH		:	'<?php echo $GLOBALS['lang']['datePicker']['TEXT_PREV_MONTH']; ?>',
	TEXT_NEXT_YEAR		:	'<?php echo $GLOBALS['lang']['datePicker']['TEXT_NEXT_YEAR']; ?>',
	TEXT_NEXT_MONTH		:	'<?php echo $GLOBALS['lang']['datePicker']['TEXT_NEXT_MONTH']; ?>',
	TEXT_CLOSE			:	'<?php echo $GLOBALS['lang']['datePicker']['TEXT_CLOSE']; ?>',
	TEXT_CHOOSE_DATE	:	'<?php echo $GLOBALS['lang']['datePicker']['TEXT_CHOOSE_DATE']; ?>'
	}
	
	$(function()
	{
		$('.date-pick').datePicker({startDate:'01/01/1990'});
    });
</script>

<?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);

       if (IsSuperAdmin()){?>
	<div class="mod_link">
	<a href="<?php echo $link_mod_sdi . $id ;
    ?>"><?php echo $GLOBALS['lang']['dashboard']['det_sdi'];
    ?></a>
	</div>
			<br class="brendstep" />
			
	<?php }?>
	<h2><?php echo formatTitleh2($result_sdii[0]['sdii_name']);
    ?></h2>
			
			<form id="addvalue" action="<?php echo $_SERVER['SCRIPT_NAME'];

    ?>" method="post">
				<p>
				<label for="value" ><?php echo $GLOBALS['lang']['dashboard']['value'] ?> * (<?php echo formatText($result_sdii[0]['sdii_unit'], '2HTML');
    ?>) :</label>
				<input name="value" type="text" id="value" maxlength="255" value="<?php echo $form_value;

    ?>" class="textfield" />
				</p>
				<p>
				<label for="scale" ><?php echo $GLOBALS['lang']['dashboard']['scale'] ?> * : </label>
				<?php echo $listing;
    ?>
				</p>
				<p>
				<label for="statut_P"><? echo $GLOBALS['lang']['divers']['statut']; ?> * : </label>
				<input name="statut" type="radio" id="statut_P" value="P" <?php echo $mask_statut_P; ?> /><span class="radio"><?php echo $GLOBALS['lang']['statut']['public']; ?></span>
				<input name="statut" type="radio" id="statut_D" value="D" <?php echo $mask_statut_D; ?> /><span class="radio"><?php echo $GLOBALS['lang']['statut']['draft']; ?></span>
				<br />
				</p>
				<p><label for="date"><? echo $GLOBALS['lang']['dashboard']['date']; ?> :
</label> <input name="date" type="text" maxlength="10" id="date"
	class="date-pick shorttextfield date-text"
	value="<?php echo $form_date; ?>" /></p>
				<br class="brendstep" />
				<br class="brendstep" />
				<div class="sdi_det">
		<a name="affeval" id="affeval" style="display:none;"></a>
		<a href="#affeval" onclick="$('#evaluation').slideToggle();"><?php echo $GLOBALS['lang']['sdi']['info_mesure'];
    ?></a>
		</div>
		<div id="evaluation" style="display:none;" >
	<br class="brendstep" />
		<table cellspacing="0" cellpadding="3">
		<thead>
		<tr>
		<?php
    echo "<td>" . $GLOBALS['lang']['sdi']['unit'] . "</td>\n";
    echo "<td>" . $GLOBALS['lang']['sdi']['max_value'] . "</td>\n";
    echo "<td>" . $GLOBALS['lang']['sdi']['min_value'] . "</td>\n";
    echo "<td>" . $GLOBALS['lang']['sdi']['threshold_value'] . "</td>\n";

    ?>
		</tr>
		</thead>
		<tbody>
		<?php echo "<tr>\n";
    echo "<td>" . $result_sdii[0]['sdii_unit'] . "</td>\n";
    echo "<td>" . $result_sdii[0]['sdii_max_value'] . "</td>\n";
    echo "<td>" . $result_sdii[0]['sdii_min_value'] . "</td>\n";
    echo "<td>" . $result_sdii[0]['sdii_threshold_value'] . "</td>\n";
    echo "</tr>\n";

    ?>
		</tbody>
		</table>
		</div>
				<div>
				
				<input name="id" type="hidden" value="<?php echo $id;
    ?>" id="id" />
	<input name="scale_id" type="hidden" value="<?php echo $scale_id; ?>" id="scale_id" />
				
	<input name="value_id" type="hidden" value="<?php echo $value_id;
    ?>" id="value_id" />
	<? echo cancel_button($link_cancel); ?>
				<input name="rub" type="hidden" value="<?php echo $rub;
    ?>" id="rub" />
				<input name="todo" type="hidden" value="<?php echo $todo;
    ?>" id="todo" />
				<input name="valider1" type="submit" value="<?php echo $GLOBALS['lang']['btn']['valid'] ?>" class="button" id="valider" />
				</div>
			</form>
		</div>
<?php include_once($dir . "/help.php");

    ?>
</div>
<?php 
    // Récapitulatif
} else {
    if (!isset($integrity5) || is_string($integrity5)) {
        $table = unserialize(urldecode($table));
        $req_scale = SQL_getonescale($table[2]);
        $resultscale2 = $sql_object -> DBSelect($req_scale);

        $display_sdi_value = $table[0]; 
        // afficher nom de scale
        $display_sdi_scale = formatText($resultscale2[0]['scale_denomination'], '2HTML');
        $display_sdi_date = $table[3];
		$display_sdi_date2=explode ("-", $display_sdi_date);
		$display_sdi_date=$display_sdi_date2[2]."-".$display_sdi_date2[1]."-".$display_sdi_date2[0];
        $display_sdi_statut = $table[4];
        $table = urlencode(serialize($table));

        ?>
<div class="contentcontainer">
<?php
        include_once($dir . "/menurub.php");

        ?>
<div id="content">
			<h2><?php echo $GLOBALS['lang']['recap']['title'] ;

        ?></h2>
			<dl class="dl3">
							<dt><?php echo $GLOBALS['lang']['dashboard']['value'];

        ?> : </dt>
				<dd><?php echo $display_sdi_value . " " . $result_sdii[0]['sdii_unit'] ;

        ?><br /></dd>
				<dt><?php echo $GLOBALS['lang']['sdi']['name2'] ;

        ?> : </dt>
				<dd><?php echo formatText($result_sdii[0]['sdii_name'], '2HTML');

        ?><br /></dd>
				<dt><?php echo $GLOBALS['lang']['divers']['statut'] ;

        ?> :</dt>
				<dd><?php echo display_statut($display_sdi_statut) ;

        ?><br /></dd>
				<dt><?php echo $GLOBALS['lang']['dashboard']['date'] ;

        ?> :</dt>
				<dd><?php echo $display_sdi_date ;

        ?><br /></dd>
				<dt><?php echo $GLOBALS['lang']['dashboard']['scale'] ;

        ?> :</dt>
				<dd><?php echo $display_sdi_scale ;

        ?><br /></dd>
			</dl>
			<form id="addvalue2" 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" />
		<input name="scale_id" type="hidden" value="<?php echo $scale_id; ?>" id="scale_id" />
				
			<input name="value_id" type="hidden" value="<?php echo $value_id;
    ?>" id="value_id" />
	
				<input name="data_table" type="hidden" value="<?php echo $table;

        ?>" id="data_table" />
		<? echo cancel_button($link_cancel); ?>
				<input name="retour" type="button" value="<?php echo $GLOBALS['lang']['btn']['preview'] ?>" class="button" id="retour" onclick="history.go(-1);" />
				<input name="enregistrer" type="submit" value="<?php echo $GLOBALS['lang']['btn']['save'] ?>" class="button" id="valider" />
				</div>
			</form>
		</div>
	<?php include_once($dir . "/help.php");

        ?>
</div>
<?php
    } 
} 

?>
