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

$requete=SQL_getonetheme($id);
$data=$sql_object->DBSelect($requete);
$display_title=formatText($data[0]['theme_name'],'2HTML');
$display_id=$data[0]['theme_id'];
$current_sdthemeid=$data[0]['sdtheme_id'];
$form_sdtheme=$data[0]['sdtheme_id'];
$current_statut=$data[0]['theme_statut'];
// $current_uri=$data[0]['theme_visual_uri'];
$form_description_all='';
$description_detail_form='';

$display_name=formatText($data[0]['theme_name'],'2FIELD');
$desc_project=formatText($data[0]['theme_desc_project'], '2FIELD');
$desc_dashboard=formatText($data[0]['theme_desc_dashboard'], '2FIELD');
$desc_publi=formatText($data[0]['theme_desc_publication'], '2FIELD');
$desc_workshop=formatText($data[0]['theme_desc_workshop'], '2FIELD');
$desc_news=formatText($data[0]['theme_desc_news'], '2FIELD');

$theme_object = new theme;

?>
<div id="chemin">
	<ul>
		<li>
			<a href="index.php"><? echo $GLOBALS['lang']['way']['home']; ?></a>
		</li>
		<li>
			<a href="<?php echo $rub_link; ?>"><? echo $GLOBALS['lang']['menu']['theme']; ?></a>
		</li>
		<li>
			<span><? echo formatnavTitle($GLOBALS['lang']['theme']['mod']. " : ".$display_title); ?></span>
		</li>
	</ul>
</div>
<!--end barre haute -->
<?php




if($current_statut=='D')  {
	$mask_statut_D="checked=\"checked\"";
	$mask_statut_P='';
	
}
elseif($current_statut=='P') {
	$mask_statut_D='';
	$mask_statut_P="checked=\"checked\"";
}
$mask_desc_ALL='';
$mask_desc_DET="checked=\"checked\"";
$layer_all_style= "style=\"display:none;\"";
$layer_det_style= "style=\"display:block;\"";

if(isset($_POST['enregistrer'])) {
	$data_table=unserialize(urldecode($_POST['data_table']));
	$result=$theme_object->ModifyTheme($id, $data_table, $sql_object);
	$link_confirm="confirm.php?rub=".$rub."&todo=".$todo;
	if($result) header("Location: ".$link_confirm);
	else  system_error();
}

if(isset($_POST['valider'])) {
	$table[0]=$_POST['denomination'];
	$table[1]=''; // anciennement visuel associé
	$table[2]=$_POST['sdtheme'];
	if($_POST['description']=='ALL') {
			$table[3]=$_POST['desc_for_all'];
			$table[4]=$_POST['desc_for_all'];
			$table[5]=$_POST['desc_for_all'];
			$table[6]=$_POST['desc_for_all'];
			$table[7]=$_POST['desc_for_all'];
	}
	if($_POST['description']=='DET') {
	    if(isset($_POST['desc_det_project'])) $table[3]=$_POST['desc_det_project']; else $table[3]='';
		if(isset($_POST['desc_det_dashboard'])) $table[4]=$_POST['desc_det_dashboard']; else $table[4]='';
		if(isset($_POST['desc_det_publication'])) $table[5]=$_POST['desc_det_publication']; else $table[5]='';
		if(isset($_POST['desc_det_news'])) $table[6]=$_POST['desc_det_news']; else $table[6]='';
		if(isset($_POST['desc_det_workshop'])) $table[7]=$_POST['desc_det_workshop']; else $table[7]='';
	}
	$table[8]=$_POST['statut'];


	$theme_object= new theme;
	$integrity=$theme_object->CheckDataIntegrity($table);
	if(is_string($integrity)) $format_text='2FIELD'; else $format_text='2HTML';

	$form_sdtheme=$_POST['sdtheme'];
	if($_POST['description']=='ALL') {
		$form_description_all=formatText($_POST['desc_for_all'],$format_text);
		$layer_all_style= "style=\"display:block;\"";
		$layer_det_style= "style=\"display:none;\"";
		$mask_desc_ALL="checked=\"checked\"";
		$mask_desc_DET='';
	}
	if($_POST['description']=='DET') {
		if(isset($_POST['desc_det_project'])) $desc_project=formatText($_POST['desc_det_project'], $format_text);
		if(isset($_POST['desc_det_dashboard'])) $desc_dashboard=formatText($_POST['desc_det_dashboard'], $format_text);
		if(isset($_POST['desc_det_publication'])) $desc_publi=formatText($_POST['desc_det_publication'], $format_text);
		if(isset($_POST['desc_det_news'])) $desc_news=formatText($_POST['desc_det_news'], $format_text);
		if(isset($_POST['desc_det_workshop'])) $desc_workshop=formatText($_POST['desc_det_workshop'], $format_text);
		$layer_all_style= "style=\"display:none;\"";
		$layer_det_style= "style=\"display:block;\"";
		$mask_desc_ALL='';
		$mask_desc_DET="checked=\"checked\"";
	}
	$display_name=$_POST['denomination'];
	if($_POST['statut']=='D') $mask_statut_D="checked=\"checked\""; else $mask_statut_D='';
	if($_POST['statut']=='P') $mask_statut_P="checked=\"checked\""; else $mask_statut_P='';
	$table=urlencode(serialize($table));
}

// preparation affichage detaillé
if(defined('MOD_PROJECT')) {
	$description_detail_form.= "<p>\n";
	$description_detail_form.= "<label for=\"desc_det_project\" >".$GLOBALS['lang']['theme']['desc_det_project']." : *</label>\n";
	$description_detail_form.= "<textarea id=\"desc_det_project\"  name=\"desc_det_project\" ".AREA_SETTINGS." class=\"largetextfield\" >".$desc_project."</textarea>\n";
	$description_detail_form.= "</p>\n";
}
if(defined('MOD_SDI')) {
	$description_detail_form.= "<p>\n";
	$description_detail_form.= "<label for=\"desc_det_dashboard\" >".$GLOBALS['lang']['theme']['desc_det_dashboard']." : *</label>\n";
	$description_detail_form.= "<textarea id=\"desc_det_dashboard\"  name=\"desc_det_dashboard\" ".AREA_SETTINGS." class=\"largetextfield\" >".$desc_dashboard."</textarea>\n";
	$description_detail_form.= "</p>\n";
}
if(defined('MOD_PUBLICATION')) {
	$description_detail_form.= "<p>\n";
	$description_detail_form.= "<label for=\"desc_det_publication\" >".$GLOBALS['lang']['theme']['desc_det_publication']." : *</label>\n";
	$description_detail_form.= "<textarea id=\"desc_det_publication\"  name=\"desc_det_publication\" ".AREA_SETTINGS." class=\"largetextfield\" >".$desc_publi."</textarea>\n";
	$description_detail_form.= "</p>\n";
}
if(defined('MOD_NEWS')) {
	$description_detail_form.= "<p>\n";
	$description_detail_form.= "<label for=\"desc_det_news\" >".$GLOBALS['lang']['theme']['desc_det_news']." : *</label>\n";
	$description_detail_form.= "<textarea id=\"desc_det_news\"  name=\"desc_det_news\" ".AREA_SETTINGS." class=\"largetextfield\">".$desc_news."</textarea>\n";
	$description_detail_form.= "</p>\n";
}
if(defined('MOD_WORKSHOP')) {
	$description_detail_form.= "<p>\n";
	$description_detail_form.= "<label for=\"desc_det_workshop\" >".$GLOBALS['lang']['theme']['desc_det_workshop']." : *</label>\n";
	$description_detail_form.= "<textarea id=\"desc_det_workshop\"  name=\"desc_det_workshop\" ".AREA_SETTINGS." class=\"largetextfield\">".$desc_workshop."</textarea>\n";
	$description_detail_form.= "</p>\n";
}



include_once("quickicons.php");
$data=$sql_object->DBSelect($req_listsdtheme);
include_once("../lib/input_helpers.php");
// select-box des SD thèmes
$data=$sql_object->DBSelect($req_listsdtheme);
$select_sdtheme=SDThemeSelectBox($data, "sdtheme", $form_sdtheme);
?>

<?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($display_title); ?></h2>
			<form id="modtheme" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
				<p>
				<label for="denomination" ><? echo $GLOBALS['lang']['theme']['denomination']; ?> : *</label>
				<input name="denomination" type="text" class="textfield" id="denomination" maxlength="200" value="<?php echo $display_name; ?>" />
				</p>
				<p>
				<label for="sdtheme" ><? echo $GLOBALS['lang']['theme']['sdtheme']; ?> : *</label>
				<?php echo $select_sdtheme; ?>
				</p>
				<p>
				<!--
				<label for="statut_P"><? echo $GLOBALS['lang']['theme']['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>
				-->
				<input name="statut" type="hidden" id="statut" value="P" />
				<br />
				</p>
				<p>
				<label for="description_ALL" ><? echo $GLOBALS['lang']['theme']['description']; ?> : *</label><br />
				<input name="description" class="radioinline" type="radio" id="description_ALL" value="ALL" onclick="ShowthemeDesc('all');" <?php echo $mask_desc_ALL; ?> /><span class="radio"><?php echo $GLOBALS['lang']['theme']['description_all']; ?></span><br />
				<input name="description" class="radioinline" type="radio" id="description_DET" value="DET" onclick="ShowthemeDesc('det');" <?php echo $mask_desc_DET; ?> /><span class="radio"><?php echo $GLOBALS['lang']['theme']['description_det']; ?></span>
				<br />
				</p>
				<div>
				<div id="all" <?php echo $layer_all_style; ?>>
					<p>
					<label for="desc_for_all" ><? echo $GLOBALS['lang']['theme']['desc_all']; ?> : *</label>
					<textarea id="desc_for_all"  name="desc_for_all" <?php echo AREA_SETTINGS; ?> class="largetextfield"><?php echo $form_description_all; ?></textarea>
					</p>
				</div>
				<div id="det" <?php echo $layer_det_style; ?>>
					<?php echo $description_detail_form; ?> 
				</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" />
				<?php echo cancel_button('javascript:history.go(-1);'); ?>
				<input name="valider" type="submit" value="<? echo $GLOBALS['lang']['btn']['valid'] ?>" class="button" id="valider" />
				</div>
			</form>
		</div>
<?php include_once($dir."/help.php"); ?>
</div>
<?php
// Récapitulatif
} else	{

$requete=SQL_getoneSDtheme($form_sdtheme);
$data=$sql_object->DBSelect($requete);
$display_sdtheme_name=formatText($data[0]['sdtheme_name'], '2HTML');

?>
<div class="contentcontainer">
<?php
include_once($dir."/menurub.php");
?>
<div id="content">
			<h2><? echo $GLOBALS['lang']['recap']['title'] ?></h2>
			<?php
			echo "<dl class=\"dl3\">";
			echo "<dt>".formatText($GLOBALS['lang']['theme']['denomination'],'2HTML')."</dt>";
			echo "<dd>". formatText($_POST['denomination'],'2HTML');"</dd>";
			echo "<dt>". formatText($GLOBALS['lang']['theme']['sdtheme'],'2HTML'). "</dt>";
			echo "<dd>".$display_sdtheme_name."</dd>";
			if($_POST['description']=='ALL') {
				echo "<dt>".formatText($GLOBALS['lang']['theme']['desc_all'],'2HTML')."</dt>";
				echo "<dd>". formatText($form_description_all,'2HTML')."</dd>";
			}
			if($_POST['description']=='DET') {
			    if(defined('MOD_PROJECT')) {
					echo "<dt>".formatText($GLOBALS['lang']['theme']['desc_det_project'],'2HTML')."</dt>";
					echo "<dd>". $desc_project."</dd>";
				}
				if(defined('MOD_SDI')) {
					echo "<dt>".formatText($GLOBALS['lang']['theme']['desc_det_dashboard'],'2HTML')."</dt>";
					echo "<dd>". $desc_dashboard."</dd>";
				}
				if(defined('MOD_PUBLICATION')) {
					echo "<dt>".formatText($GLOBALS['lang']['theme']['desc_det_publication'],'2HTML')."</dt>";
					echo "<dd>". $desc_publi."</dd>";
				}
				if(defined('MOD_NEWS')) {
					echo "<dt>".formatText($GLOBALS['lang']['theme']['desc_det_news'],'2HTML')."</dt>";
					echo "<dd>". $desc_news."</dd>";
				}
				if(defined('MOD_WORKSHOP')) {
					echo "<dt>".formatText($GLOBALS['lang']['theme']['desc_det_workshop'],'2HTML')."</dt>";
					echo "<dd>". $desc_workshop."</dd>";
				}
			}
			echo "</dl>";
			?>
			<form id="addscale" 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='.$rub.'&amp;todo=list'); ?>
				<input name="retour" type="button" value="<? echo $GLOBALS['lang']['btn']['preview'] ?>" class="button" id="retour" onclick="history.go(-1);" />
				<input name="enregistrer" type="submit" value="<? echo $GLOBALS['lang']['btn']['save'] ?>" class="button" id="valider" />
				</div>
			</form>
		</div>
	<?php include_once($dir."/help.php"); ?>
</div>
<?php
}
?>
