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

$table="";
$link_mod_e=$rub_link."&amp;todo=mod_e&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=27;$i<=30;$i++){
	$data_table_r[$j]=$data_table[$i];
	$j++;
	}
$sdi_object= new sdi;
	$result=$sdi_object->ModifyParam($id, $data_table_r, "R", $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_reglementation=$sdi_object->GetRules($id_idd=$id, $sql_object, $ID="-1");

$req_sdir=SQL_getRules($id_idd=$id, $sql_object, $ID="-1");
$data_reglementation = $sql_object -> DBSelect($req_sdir);

$form_r_title = formatText($data_reglementation[0]['sdir_title'], '2FIELD');
$form_r_body = formatText($data_reglementation[0]['sdir_body'], '2FIELD');
 if ($data_reglementation[0]['sdir_referer_uri']<>"") $form_r_referer_uri = formatText($data_reglementation[0]['sdir_referer_uri'], '2FIELD');
 else $form_r_referer_uri ='';
$form_r_mask_uri = formatText($data_reglementation[0]['sdir_mask_uri'], '2FIELD');

if (isset($_POST['valider4'])) {
    $table[27] = $_POST['r_title'];
    $table[28] = $_POST['r_body'];
    $table[29] = $_POST['r_referer_uri'];
	if ($_POST['r_mask_uri']=="")$table[30]  = $table[29];
	else $table[30] =$_POST['r_mask_uri'];
    $sdi_object = new sdi;
    $integrity4 = $sdi_object -> CheckDataIntegrity_reglementation($table);

    $form_r_title = formatText($_POST['r_title'], '2FIELD');
    $form_r_body = formatText($_POST['r_body'], '2FIELD');
   $form_r_referer_uri = formatText($_POST['r_referer_uri'], '2FIELD');
   	if ($_POST['r_mask_uri']=="")$form_r_mask_uri  = $form_r_referer_uri;
	else  $form_r_mask_uri = formatText($_POST['r_mask_uri'], '2FIELD');
    $table = urlencode(serialize($table));
} 

include_once(THEME_ADMIN_PATH."quickicons.php");
$req_list_sdiname=SQL_getOnesdiname($id);
$data_sdi_name = $sql_object -> DBSelect($req_list_sdiname);
$navtitle=_t('sdi','mod_r')." : ".$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_<? echo $rub; ?>" class="chemin_rub"><?php echo _t('menu','sdi')?></a>
		</li>
		<li>
			<span><?php  echo formatnavTitle($navtitle) ?></span>
		</li>
	</ul>
</div>
<!--end barre haute -->
<?
           if (!isset($integrity4) || is_string($integrity4)) {

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

                ?>
				
		<div id="content">
		<div class="mod_link">
	<a href="<? echo $link_mod.$id ;?>"><?echo _t('sdi','mod');?></a> | 
	<a href="<? echo $link_mod_p.$id ;?>"><?echo _t('sdi','modify_sdi_p');?></a> | 
	<a href="<? echo $link_mod_e.$id ;?>"><?echo _t('sdi','modify_sdi_e');?></a>
	</div>
			<br class="brendstep" />
		
			<?php
                if (isset($integrity4) && is_string($integrity4)) display_errors($integrity4);

                ?>
				
			<h2><?php echo formatTitleh2($data_sdi_name[0]['sdii_name']);  ?></h2>
			
			<form id="addsdi4" action="<?php echo $_SERVER['SCRIPT_NAME'];
                ?>" method="post">
				<p>
				<label for="r_title" ><?php echo _t('sdi','r_title') ?> * :</label>
				<input name="r_title" type="text" class="textfield" id="r_title" maxlength="255" value="<?php echo $form_r_title;
                ?>" />
				</p>
				<p>
				<label for="r_body" ><?php echo _t('sdi','r_body') ?> * :</label>
				<textarea id="r_body" name="r_body" <?php echo AREA_SETTINGS; ?> class="largetextfield"><?php echo $form_r_body;
                ?></textarea>
				</p>
				<p>
				<label for="r_referer_uri" ><?php echo _t('sdi','r_referer_uri') ?>  :</label>
				<input name="r_referer_uri" type="text" class="textfield" id="r_referer_uri" maxlength="255" value="<?php echo $form_r_referer_uri;
                ?>" />
				</p>
				<p>
				<label for="r_mask_uri" ><?php echo _t('sdi','r_mask_uri') ?>  :</label>
				<input name="r_mask_uri" type="text" class="textfield" id="r_mask_uri" maxlength="255" value="<?php echo $form_r_mask_uri;
                ?>" />
				</p>
				<div>
				<input name="table" type="hidden" value="<?php

                echo $table;
                ?>" id="table" />
				<input name="rub" type="hidden" value="<?php echo $rub;
                ?>" id="rub" />
				<input name="id" type="hidden" value="<?php echo $id;
            ?>" id="id" />
			<br />
				<? echo cancel_button($rub_link."&amp;todo=det&amp;id=".$id); ?>
				
				<input name="todo" type="hidden" value="<?php echo $todo;
                ?>" id="todo" />
				<input name="valider4" type="submit" value="<?php echo _t('btn','valid') ?>" class="button" id="valider" />
				</div>
			</form>
		</div>
<?php include_once($dir . "/help.php");
                ?>
</div>

<?php
            } else {
                if (!isset($integrity5) || is_string($integrity5)) {
				
				
                    $table=unserialize(urldecode($table));
    
                    $display_r_title =formatText(empty_nc($table[27]), '2HTML');
                    $display_r_body = formatText(empty_nc($table[28]), '2HTML');
                    $display_r_referer_uri = formatText(empty_nc($table[29]), '2HTML');
                    $display_r_mask_uri = formatText(empty_nc($table[30]), '2HTML');
					
                    $table = urlencode(serialize($table));

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

                    ?>
<div id="content">
			<h2><?php echo _t('recap','title') ;
                    ?></h2>
			<dl class="dl3">
				<dt><?php echo _t('sdi','r_title') ;
                    ?> : </dt>
				<dd><?php echo $display_r_title ;
                    ?><br /></dd>
				<dt><?php echo _t('sdi','r_body') ;
                    ?> : </dt>
				<dd><?php echo $display_r_body ;
                    ?><br /></dd>
				<dt><?php echo _t('sdi','r_referer_uri') ;
                    ?> : </dt>
				<dd><?php echo $display_r_referer_uri ;
                    ?><br /></dd>
				<dt><?php echo _t('sdi','r_mask_uri') ;
                    ?> : </dt>
				<dd><?php echo $display_r_mask_uri ;
                    ?><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" />
			<br />
				<? 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>
	<?php include_once($dir . "/help.php");
                    ?>
</div>
<?php
                } 
            } 
?>
