<?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");
$form_denomination='';
$form_resume='';
$form_comment='';
$form_organizer='';
$form_theme='';
$form_level='';
$mask_statut_P='';
$mask_statut_D="checked=\"checked\"";

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

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

$workshop_object= new workshop;

if(isset($_POST['enregistrer'])) {
	$data_table=unserialize(urldecode($_POST['data_table']));
	$result=$workshop_object->AddWorkshop($data_table, $sql_object);
	$data_table[6]=str_replace(" ","", $data_table[6]);	
	$table_organizer=@explode(MAIL_SEPARATOR,$data_table[6]);
		for ($i=0;$i<count($table_organizer);$i++){
	$result2=$workshop_object->AddUserWorkshop($result, $table_organizer[$i], "O" , $sql_object);
	}
	$link_confirm="confirm.php?rub=".$rub."&todo=".$todo;
	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'];

	
	$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)) {

// 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(THEME_ADMIN_PATH."quickicons.php");

?>
<div id="chemin">
	<ul>
		<li>
			<a href="index.php" class="chemin_home"><? echo _t('way','home') ?></a>
		</li>
		<li>
			   <a href="<?php echo $rub_link; ?>" id="chemin_<? echo $rub; ?>" class="chemin_rub"><? echo _t('menu','workshop')?></a>
		</li>
		<li>
			<span><? echo formatnavTitle(_t('workshop','add')); ?></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);
			?>
			<h2><? echo _t('workshop','add_title') ?></h2>
			<form id="addworkshop" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
				<p>
				<label for="workshop_denomination"><? echo _t('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 _t('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 _t('workshop','theme'); ?> * : </label>
				<?php echo $select_theme; ?>
				</p>
				<p>
				<label for="workshop_level" ><? echo _t('workshop','level'); ?> : </label>
				<?php echo $select_level; ?>
				</p>
				<p>
				<label for="workshop_organizer"><? echo _t('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="workshop_statut"><? echo _t('workshop','statut'); ?> * : </label>
				<input name="workshop_statut" type="radio" id="statut_P" value="P" <?php echo $mask_statut_P; ?> /><span class="radio"><?php echo _t('statut','public'); ?></span>
				<input name="workshop_statut" type="radio" id="statut_D" value="D" <?php echo $mask_statut_D; ?> /><span class="radio"><?php echo _t('statut','draft'); ?></span>
				<br />
				</p>
				<p>
				<label for="workshop_comment"><? echo _t('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" />
				<input name="todo" type="hidden" value="<?php echo $todo; ?>" id="todo" />
				<? echo cancel_button($rub_link."&amp;todo=list"); ?>
				<input name="valider" type="submit" value="<? echo _t('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');

if($form_level <> -1) {
$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');
}else $level_denomination=_t('divers','none');


$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">
			<h2><? echo _t('recap','title') ?></h2>
			<?php
			echo "<dl class=\"dl3\">\n";
			echo "<dt>"._t('workshop','title')."</dt>\n";
			echo "<dd>". $form_denomination."</dd>\n";
			echo "<dt>". _t('workshop','resume'). "</dt>\n";
			echo "<dd>".$display_form_resume."</dd>\n";
			echo "<dt>"._t('workshop','theme')." :</dt>\n";
			echo "<dd>".$theme_denomination."</dd>\n";
			echo "<dt>"._t('workshop','level')." :</dt>\n";
			echo "<dd>".$level_denomination."</dd>\n";
			echo "<dt>"._t('workshop','organizer')." :</dt>\n";
			echo "<dd>".$form_organizer."</dd>\n";
			echo "<dt>"._t('divers','statut') ."</dt>\n";
			echo "<dd>". display_statut($_POST['workshop_statut']). "</dd>\n";
			echo "<dt>"._t('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=list"); ?>
				<input name="data_table" type="hidden" value="<?php echo $table; ?>" id="data_table" />
				<input name="retour" type="button" value="<? echo _t('btn','preview') ?>" class="button" id="retour" onclick="history.go(-1);" />
				<input name="enregistrer" type="submit" value="<? echo _t('btn','save') ?>" class="button" id="valider" />
				</div>
			</form>
		</div>
	<?php include_once($dir."/help.php"); ?>
</div>
<?php
}
?>
