<?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
 */

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');
}
////////////

include_once("../lib/lib_common.php");
$req_det= SQL_getoneCompleteWorkshop($id);
$result=$sql_object->DBSelect($req_det);
if(count($result)>1) exit();

if ($result[0]['workshop_statut']<>'P' && !IsSuperAdmin()){ 
include_once("../lib/lib_common.php");
ReloadIndex('admin');
}

$link_det=$rub_link."&amp;todo=det&amp;id=";
$link_sup=$rub_link."&amp;todo=sup&amp;id=";
$link_mod=$rub_link."&amp;todo=mod&amp;id=";
$link_det_u="index.php?rub=user&amp;todo=det&amp;id=";
$link_det_theme="index.php?rub=theme&amp;todo=det&amp;id=";
$link_det_level="index.php?rub=level&amp;todo=det&amp;id=";
$link_sup_u=$rub_link."&amp;todo=sup_u&amp;id=";
$link_add_u=$rub_link."&amp;todo=add_u&amp;id=";
$link_list_cal=$rub_link."&amp;todo=list_cal&amp;id=";
$link_list_com=$rub_link."&amp;todo=list_com&amp;id=";
$link_sup_rep="index.php?rub=workshoprep&amp;todo=sup&amp;id=";
$link_mod_rep="index.php?rub=workshoprep&amp;todo=mod&amp;id=";
$link_det_rep="index.php?rub=workshoprep&amp;todo=det&amp;id=";
$link_add_rep="index.php?rub=workshoprep&amp;todo=add&amp;work_id=";

$workshop_denomination=formatText($result[0]['workshop_denomination'], '2HTML');
$workshop_resume=empty_nc(formatText($result[0]['workshop_resume'], '2HTML'));
$workshop_comment=empty_nc(formatText($result[0]['workshop_comment'], '2HTML'));
$theme_denomination=formatText($result[0]['theme_name'], '2HTML');
$level_denomination=formatText(empty_none($result[0]['level_name'], '2HTML'));
$workshop_statut=display_statut($result[0]['workshop_statut']);
$display_date_crea=$result[0]['workshop_date_crea_display'];
$display_last_modify=$result[0]['workshop_last_modify_display'];
$workshop_object= new workshop ;

$req_user=SQL_getWorkshopUserList($id);
$result_user = $sql_object -> DBSelect($req_user);

//récupération des organisateurs du workshop
$form_organizer='';
$j=0;
for($i=0; $i<count($result_user); $i++) {
 if ($result_user[$i]['jwu_user_right']=='O' || $result_user[$i]['jwu_user_right']=='A'){
 $j++;
if ($j<>1) $form_organizer.=" ".MAIL_SEPARATOR." ";
$form_organizer.=$result_user[$i]['user_login'];
}
}

// formattage des données

	//prepa affichage des infos générales
	$reca_generals="<dl class=\"dl3\">\n";
	$reca_generals.="<dt  class=\"dl_intitule\">"._t('workshop','generals')." : </dt>\n";
	$reca_generals.="<dd>&nbsp;<br /></dd>\n";
	$reca_generals.="<dt>"._t('workshop','title')."</dt>\n";
	$reca_generals.="<dd>". $workshop_denomination."</dd>\n";
	$reca_generals.="<dt>". _t('workshop','resume'). "</dt>\n";
	$reca_generals.="<dd>".$workshop_resume."</dd>\n";
	$reca_generals.="<dt>"._t('workshop','theme')." :</dt>\n";
	if (IsSuperAdmin())
	$reca_generals.="<dd><a href=\"".$link_det_theme.$result[0]['workshop_theme']."\" title=\"".$theme_denomination."\">".$theme_denomination."</a></dd>\n";
	else $reca_generals.="<dd>".$theme_denomination."</dd>\n";
	$reca_generals.="<dt>"._t('workshop','level')." :</dt>\n";
	if (IsSuperAdmin() && $result[0]['workshop_level'] <> -1)
	$reca_generals.="<dd><a href=\"".$link_det_level.$result[0]['workshop_level']."\" title=\"".$level_denomination."\">".$level_denomination."</a></dd>\n";
	
	else $reca_generals.="<dd>".$level_denomination."</dd>\n";
	
	$reca_generals.="<dt>"._t('divers','date_crea') ."</dt>\n";
	$reca_generals.="<dd>". $display_date_crea. "</dd>\n";
	$reca_generals.="<dt>"._t('divers','last_modify') ."</dt>\n";
	$reca_generals.="<dd>". $display_last_modify. "</dd>\n";
	$reca_generals.="<dt>"._t('divers','statut')." :</dt>\n";
	$reca_generals.="<dd>". $workshop_statut. "</dd>\n";
	$reca_generals.="<dt>"._t('workshop','comment')." :</dt>\n";
	$reca_generals.="<dd>". $workshop_comment. "</dd>\n";
	$reca_generals.="<dt>"._t('workshop','organizer')." :</dt>\n";
	$reca_generals.="<dd>". $form_organizer. "</dd>\n";
	$reca_generals.="</dl>\n";
	
	
	// Récuperation des différentes parties
	
	//prepa affichage des utilisateurs du workgroup
	
	if($result_user==false) $contents_user="<div class=\"info\">"._t('workshop','no_user')."</div>";
	else {
			$contents_user= "<table cellspacing=\"0\" cellpadding=\"3\" class=\"table2\">\n";
		    $contents_user.="<thead>\n";
			$contents_user.="<tr>\n"; 
			$contents_user.="<td>"._t('workshop','user')."</td>\n";
			$contents_user.="<td> <span class=\"semnone\">"._t('divers','actions')."</span></td>\n";
			$contents_user.="</tr>\n";
			$contents_user.="</thead>\n";
			$contents_user.="<tbody>\n";	
			$mailing_list='';
			
			
			for($i=0; $i<count($result_user); $i++) {
			
	$contents_user.="<tr>\n";
	$contents_user.="<td>";
	if (IsSuperAdmin())
	$contents_user.="<a href=\"".$link_det_u.$result_user[$i]['jwu_user_id']."\" title=\"".formatText(_t('workshop','user'), '2HTML')."\">".formatText($result_user[$i]['user_login'], '2HTML')."</a>\n";
    else 
	$contents_user.="<span>".formatText($result_user[$i]['user_login'], '2HTML')."</span>";
	if ($result_user[$i]['jwu_user_right']=='O' || $result_user[$i]['jwu_user_right']=='A')
	$contents_user.="<span class=\"text_det_it\">(".display_statut($result_user[$i]['jwu_user_right']).")</span> ";
	$contents_user.="</td>\n";
	if (WorkshopAuth_id(GetSessionElement('id'), $sql_object, $id)==true || IsSuperAdmin()){
	$contents_user.="<td><div class=\"iconetab\">";
	if ($result_user[$i]['jwu_user_right']<>'O')
	$contents_user.="<a href=\"".$link_sup_u.$id."&amp;u_id=".$result_user[$i]['jwu_user_id']."\" title=\""._t('workshop','del_user')."\" class=\"ico_sup\"></a>\n";
	else if (IsSuperAdmin())
	$contents_user.="<a href=\"".$link_sup_u.$id."&amp;u_id=".$result_user[$i]['jwu_user_id']."\" title=\""._t('workshop','del_user')."\" class=\"ico_sup\"></a>\n";
	$contents_user.="<a href=\"mailto:".$result_user[$i]['profile_email']."\" title=\"".$result_user[$i]['profile_email']."\" class=\"ico_mail\"></a></div></td>";
	}
	else $contents_user.="<td>&nbsp;</td>\n";
	$contents_user.="</tr>\n";
	$mailing_list.=$result_user[$i]['profile_email'].MAIL_SEPARATOR."%20";
			}
			$contents_user.="</tbody>";
$contents_user.="</table>";
	}
	
	$reca_user ="<br class=\"brendstep\" />\n";
	$reca_user.="<div class=\"workshop_det\">\n";
	$reca_user.="<a name=\"workshopuser\" id=\"workshopuser\" href=\"#workshopuser\" onclick=\"$('#workshop_user').slideToggle();\">"._t('workshop','user')."</a>\n";
	$reca_user.="</div>\n";
	$reca_user.="<div id=\"workshop_user\" style=\"display:none;\" >\n";
	if (WorkshopAuth_id (GetSessionElement('id'), $sql_object, $id)==true || IsSuperAdmin())
	$reca_user.="<a href=\"".$link_add_u.$id."\" title=\""._t('workshop','add_new_user')."\" class=\"ico_add2\"></a><br class=\"brendstep\" />"; 	
	$reca_user.=$contents_user;
	if (WorkshopAuth_id (GetSessionElement('id'), $sql_object, $id)==true || IsSuperAdmin())
	$reca_user.="<div class=\"mailing_list\"><a href=\"mailto:".$mailing_list."\" title=\""._t('workshop','mailing_list')."\"> <img src=\"" .THEME_ADMIN_PATH. "images/ico_mail2.gif\" alt=\""._t('workshop','mailing_list')."\" /> &nbsp;"._t('workshop','mailing_list')."</a></div>";
	$reca_user.="</div>\n";
	$reca_user.="<br class=\"brendstep\" />\n";
	
	//prepa affichage des rapports d'un workgroup
	
	$req_workshop_report= SQL_getWorkshopReportList($id);
$result_report=$sql_object->DBSelect($req_workshop_report);
	
	//$workshop_report_object= new workshop_report ;

	$link_res_sup="?rub=resources&amp;todo=sup&amp;id=&amp;parent=".$id."&amp;type=P&amp;id=";
	$link_mod=$rub_link."&amp;todo=mod&amp;id=";
	
	if($result_report==0) {
		$contents_report="<div class=\"info\">"._t('workshop','no_report')."</div>";
	} else {
			$contents_report= "<table cellspacing=\"0\" cellpadding=\"3\" class=\"table2\">\n";
			$contents_report.="<thead>\n";
			$contents_report.="<tr>\n"; 
			$contents_report.="<td>"._t('workshop','title_report')."</td>\n";
			$contents_report.="<td>"._t('divers','statut')."</td>\n";
			$contents_report.="<td>"._t('divers','date_crea')."</td>\n";
			$contents_report.="<td> <span class=\"semnone\">"._t('divers','actions')."</span></td>\n";
			$contents_report.="</tr>\n";
			$contents_report.="</thead>\n";
			$contents_report.="<tbody>\n";	
	
			for($i=0; $i<count($result_report); $i++) {
	
	$workshop_report_title=formatText(cutText($result_report[$i]['workrep_title'], 60, 1), '2HTML'); 
	
	$contents_report.="<tr>\n";
	$contents_report.="<td width=\"50%\"><a href=\"".$link_det_rep.$result_report[$i]['workrep_id']."\" title=\"".$workshop_report_title."\">".$workshop_report_title."</a></td>\n";
	$contents_report.="<td>".display_statut($result_report[$i]['workrep_statut'])."</td>\n";
	$contents_report.="<td>".$result_report[$i]['workrep_date_crea_display']."</td>\n";
	if (WorkshopAuth_id (GetSessionElement('id'), $sql_object, $id)==true || IsSuperAdmin()){
	$contents_report.="<td><div class=\"iconetab\"><a href=\"".$link_sup_rep.$result_report[$i]['workrep_id']."\" title=\""._t('workshop','del_report')."\" class=\"ico_sup\"></a>\n";
	$contents_report.="<a href=\"".$link_mod_rep.$result_report[$i]['workrep_id']."\" title=\""._t('workshop','mod_report')."\" class=\"ico_mod\"></a></div></td>";
	}
	else $contents_report.="<td>&nbsp;</td>\n";
	$contents_report.="</tr>\n";
}

$contents_report.="</tbody>";
$contents_report.="</table>";
			}
			
	$reca_report='';
	$reca_report.="<div class=\"workshop_det\">\n";
	$reca_report.="<a name=\"resreport\" id=\"resreport\" href=\"#resreport\" onclick=\"$('#res_report').slideToggle();\">"._t('workshop','report')."</a>\n";
	$reca_report.="</div>\n";
	$reca_report.="<div id=\"res_report\" style=\"display:none;\" >\n";
	if (WorkshopAuth_id (GetSessionElement('id'), $sql_object, $id)==true || IsSuperAdmin())
	$reca_report.="<a href=\"".$link_add_rep.$id."\" title=\""._t('workshop','add_new_report')."\" class=\"ico_add2\"></a><br class=\"brendstep\" />"; 		
	$reca_report.=$contents_report;
	$reca_report.="</div>\n";
	$reca_report.="<br class=\"brendstep\" />\n";
	
	$navtitle=_t('workshop','det')." : ".$workshop_denomination;
?>
<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($navtitle); ?></span>
		</li>
	</ul>
</div>
  <!--end barre haute -->
<?php
include_once(THEME_ADMIN_PATH."quickicons.php");
?>
<div class="contentcontainer">
<?php
include_once($dir."/menurub.php");
?>
<div id="content">
<?php	
		afflinkbar($todo,$id, $lang); 
		echo "<h2>".formatTitleh2($workshop_denomination)."</h2>\n";
		if (IsSuperAdmin()){
		echo "<a href=\"".$link_sup.$id."\" title=\""._t('workshop','sup')."\" class=\"ico_sup2\"></a>";
		echo "<a href=\"".$link_mod.$id."\" title=\""._t('workshop','mod')."\" class=\"ico_mod2\"></a><br class=\"brendstep\" />"; 		 		
		}
		echo $reca_generals;
		echo $reca_user;
		echo $reca_report;
?>

		
		

</div>
<?php include_once($dir."/help.php"); ?>
</div>
