<?php
/**
 * @package linea21.modules
 * @subpackage workshop
 * @author linea21 <info@linea21.com>
 * @version $id SVN
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */

include_once("../lib/input_helpers.php");
if(isset($_POST['id']))	$id=$_POST['id'];
if(isset($_GET['id']))	$id=$_GET['id'];

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

//////////// Check Droits utilisateur ////////////  
if (!IsSuperAdmin())
ReloadIndex('admin');  
////////////

$req_det= SQL_getoneCompleteWorkshop($id);
$result=$sql_object->DBSelect($req_det);
$workshop_object= new workshop;
$req_user=SQL_getWorkshopUserList($id);
$result_user = $sql_object -> DBSelect($req_user);
//$result_user=$workshop_object->GetWorkshopUserList($id, $sql_object);

$form_organizer='';
$j=0;
for($i=0; $i<count($result_user); $i++) {
		    if ($result_user[$i]['jwu_user_right']=='O') {
			 	$j++;
				if ($j<>1) $form_organizer.=MAIL_SEPARATOR;
				$form_organizer.=$result_user[$i]['user_login'];
			}	
}
			
if ($result[0]['workshop_denomination']<>"") {
$workshop_denomination=$result[0]['workshop_denomination'];
$form_denomination=formatText($result[0]['workshop_denomination']);
}
else $form_denomination="";
if ($result[0]['workshop_resume']<>"") $form_resume=formatText($result[0]['workshop_resume']);
else $form_resume="";
if ($result[0]['workshop_comment']<>"") $form_comment=formatText($result[0]['workshop_comment']);
else $form_comment="";
$form_theme=$result[0]['workshop_theme'];
$form_level=$result[0]['workshop_level'];


if($result[0]['workshop_statut']=='D') $mask_statut_D="checked=\"checked\""; else $mask_statut_D='';
if($result[0]['workshop_statut']=='P') $mask_statut_P="checked=\"checked\""; else $mask_statut_P='';
	
if(isset($_POST['enregistrer'])) {
	$data_table=unserialize(urldecode($_POST['data_table']));
	$result=$workshop_object->ModifyWorkshop($id, $data_table, $sql_object);
	$result=$workshop_object->StateWorkshop($id,  $data_table[5], $sql_object);
	$result=$workshop_object->ModifyOrganizerWorkshop($id, $data_table[6], $sql_object);
	$link_confirm="confirm.php?rub=".$rub."&todo=".$todo."&id=".$id;
	if(is_numeric($result)) 
	header("Location: ".$link_confirm);
	else  system_error();
}

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

	$table[0]=$_POST['workshop_denomination'];
	$table[1]=$_POST['workshop_resume'];
	$table[2]=$_POST['workshop_theme'];
	$table[3]=$_POST['workshop_comment'];
	$table[4]=$_POST['workshop_level'];
	$table[5]=$_POST['workshop_statut'];
	$table[6]=$_POST['workshop_organizer'];
	$table[6]=str_replace(" ","", $table[6]);	
    $workshop_object= new workshop;
	$integrity=$workshop_object->CheckDataIntegrity($table, $sql_object);
	if(is_string($integrity)) {
		$text_format='2FIELD';
	} else {
		$text_format='2HTML';
		}
	$form_denomination=formatText($_POST['workshop_denomination'], $text_format);
	$form_resume=formatText($_POST['workshop_resume'], $text_format);
	$form_theme=$_POST['workshop_theme'];
	$form_level=$_POST['workshop_level'];
	$form_organizer=formatText($_POST['workshop_organizer'], $text_format);
	$form_comment=formatText($_POST['workshop_comment'], $text_format);

	if($_POST['workshop_statut']=='D') $mask_statut_D="checked=\"checked\""; else $mask_statut_D='';
	if($_POST['workshop_statut']=='P') $mask_statut_P="checked=\"checked\""; else $mask_statut_P='';
	$table=urlencode(serialize($table));
}


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

$close='';
// select-box de thèmes
$data=$sql_object->DBSelect($req_list_theme);
$select_theme=ThemeSelectBox($data, "workshop_theme", $form_theme);


// select-box des niveaux
$data=$sql_object->DBSelect($req_list_level);
$select_level=LevelSelectBox($data, "workshop_level", $form_level);
}

include_once("quickicons.php");
$navtitle=$GLOBALS['lang']['workshop']['mod']." : ".$workshop_denomination;
?>
<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']['workshop']?></a>
		</li>
		<li>
			<span><? echo formatnavTitle($navtitle); ?></span>
		</li>
	</ul>
</div>
<!--end barre haute -->
<?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);
			?>
			<?php afflinkbar($todo,$id, $lang); ?>
			<h2><? echo formatTitleh2($GLOBALS['lang']['workshop']['name']." : ".$workshop_denomination); ?></h2>
			<form id="addworkshop" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
				<p>
				<label for="workshop_denomination"><? echo $GLOBALS['lang']['workshop']['title']; ?> * : </label>
				<input name="workshop_denomination" type="text" class="textfield" id="workshop_denomination" maxlength="255" value="<?php echo $form_denomination; ?>" />
				</p>
				<p>
				<label for="workshop_resume"><? echo $GLOBALS['lang']['workshop']['resume']; ?> * : </label>
				<textarea id="workshop_resume" name="workshop_resume" <?php echo AREA_SETTINGS; ?> class="largetextfield" ><?php echo $form_resume; ?></textarea>
				</p>
				<p>
				<label for="workshop_theme" ><? echo $GLOBALS['lang']['workshop']['theme']; ?> * : </label>
				<?php echo $select_theme; ?>
				</p>
				<p>
				<label for="workshop_level" ><? echo $GLOBALS['lang']['workshop']['level']; ?> * : </label>
				<?php echo $select_level; ?>
				</p>
				<p>
				<label for="workshop_organizer"><? echo $GLOBALS['lang']['workshop']['organizer']; ?> * : </label>
				<input name="workshop_organizer" type="text" class="textfield" id="workshop_organizer" maxlength="150" value="<?php echo $form_organizer; ?>" />
				</p>
				<p>
				<label for="statut_P"><? echo $GLOBALS['lang']['workshop']['statut']; ?> * : </label>
				<input name="workshop_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="workshop_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="workshop_comment"><? echo $GLOBALS['lang']['workshop']['comment']; ?> : </label>
				<textarea id="workshop_comment" name="workshop_comment" <?php echo AREA_SETTINGS; ?> class="largetextfield" ><?php echo $form_comment; ?></textarea>
				</p>
				<div>
				<input name="rub" type="hidden" value="<?php echo $rub; ?>" id="rub" />
				<? echo cancel_button($rub_link."&amp;todo=det&amp;id=".$id); ?>
				<input name="id" type="hidden" value="<?php echo $id; ?>" id="id_workshop" />
				<input name="todo" type="hidden" value="<?php echo $todo; ?>" id="todo" />
				<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_getonethemeName($form_theme);
$result=$sql_object->DBSelect($requete);
if($result==0 || count($result)!=1) exit;
else $theme_denomination=formatText($result[0]['theme_name'], '2HTML');
$requete=SQL_getonelevelName($form_level);
$result=$sql_object->DBSelect($requete);
if($result==0 || count($result)!=1) exit;
else $level_denomination=formatText($result[0]['level_name'], '2HTML');

$display_form_resume=empty_nc($form_resume);
$display_form_comment=empty_nc($form_comment);

?>
<div class="contentcontainer">
<?php
include_once($dir."/menurub.php");
?>
<div id="content">
<?php afflinkbar($todo,$id, $lang); ?>
			<h2><? echo $GLOBALS['lang']['recap']['title'] ?></h2>
			<?php
			echo "<dl class=\"dl3\">\n";
			echo "<dt>".$GLOBALS['lang']['workshop']['title']."</dt>\n";
			echo "<dd>". $form_denomination."</dd>\n";
			echo "<dt>". $GLOBALS['lang']['workshop']['resume']. "</dt>\n";
			echo "<dd>".$display_form_resume."</dd>\n";
			echo "<dt>".$GLOBALS['lang']['workshop']['theme']." :</dt>\n";
			echo "<dd>".$theme_denomination."</dd>\n";
			echo "<dt>".$GLOBALS['lang']['workshop']['level']." :</dt>\n";
			echo "<dd>".$level_denomination."</dd>\n";
			echo "<dt>".$GLOBALS['lang']['workshop']['organizer']." :</dt>\n";
			echo "<dd>".$form_organizer."</dd>\n";
			echo "<dt>".$GLOBALS['lang']['divers']['statut'] ."</dt>\n";
			echo "<dd>". display_statut($_POST['workshop_statut']). "</dd>\n";
			echo "<dt>".$GLOBALS['lang']['workshop']['comment'] ."</dt>\n";
			echo "<dd>". $display_form_comment. "</dd>\n";
			echo "</dl>\n";
			?>
			<form id="addworkshop" 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" />
				<? echo cancel_button($rub_link."&amp;todo=det&id=".$id); ?>
				<input name="data_table" type="hidden" value="<?php echo $table; ?>" id="data_table" />
				<input name="id" type="hidden" value="<?php echo $id; ?>" id="id_workshop" />
				<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
}
?>
