<?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 (!class_exists('auth')){
  include_once("../lib/lib_common.php");
  ReloadIndex('admin');
}
////////////

//////////// Check Droits utilisateur ////////////
if (!$l21auth->hasRight('workshop') && !$l21auth->isSuperAdmin())
	ReloadIndex('admin');
////////////


$req_det= SQL_getoneCompleteWorkshop($id);
$result=$sql_object->DBSelect($req_det);
if(count($result)>1) exit();

if ($result[0]['workshop_statut']<>'P' && !$l21auth->isSuperAdmin()){
  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'];

if($result[0]['workshop_restricted'] == 1) {
	$workshop_restricted = _t('divers', 'yes');
} else {
	$workshop_restricted = _t('divers', 'no');
}

$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'){
    $j++;
    if ($j<>1) $form_organizer.=", ";
    $form_organizer.=$result_user[$i]['user_login'];
  }
}

// formattage des données

//prepa affichage des infos générales
$reca_generals="<h3 class=\"part\">\n"._t('workshop','generals')." : </h3>\n";
$reca_generals.="<dl class=\"summary\">\n";
$reca_generals.="<dt>".mb_ucfirst(_t('workshop','title'))." :</dt>\n";
$reca_generals.="<dd>". $workshop_denomination."</dd>\n";
$reca_generals.="<dt>".mb_ucfirst(_t('workshop','resume')). " :</dt>\n";
$reca_generals.="<dd>".$workshop_resume."</dd>\n";
$reca_generals.="<dt>".mb_ucfirst(_t('workshop','restricted')). " :</dt>\n";
$reca_generals.="<dd>".$workshop_restricted."</dd>\n";
$reca_generals.="<dt>".mb_ucfirst(_t('workshop','theme'))." :</dt>\n";
if ($l21auth->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>".mb_ucfirst(_t('workshop','level'))." :</dt>\n";
if ($l21auth->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>".mb_ucfirst(_t('divers','date_crea')) ." :</dt>\n";
$reca_generals.="<dd>". $display_date_crea. "</dd>\n";
$reca_generals.="<dt>".mb_ucfirst(_t('divers','last_modify')) ." :</dt>\n";
$reca_generals.="<dd>". $display_last_modify. "</dd>\n";
$reca_generals.="<dt>".mb_ucfirst(_t('divers','statut'))." :</dt>\n";
$reca_generals.="<dd>". $workshop_statut. "</dd>\n";
$reca_generals.="<dt>".mb_ucfirst(_t('workshop','comment'))." :</dt>\n";
$reca_generals.="<dd>". $workshop_comment. "</dd>\n";
$reca_generals.="<dt>".mb_ucfirst(_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 multisort\">\n";
  $contents_user.="<thead>\n";
  $contents_user.="<tr>\n";
  $contents_user.="<td>".mb_ucfirst(_t('workshop','user'))."</td>\n";
  $contents_user.="<td class=\"sorter-false\"> <span class=\"semnone\">".mb_ucfirst(_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++) {
    
  	if ($result_user[$i]['jwu_user_right']=='A') {
  		$class=' class="to-moderate" '; 
  	} else {
  		$class='';
  	}
    $contents_user.="<tr".$class.">\n";
    $contents_user.="<td>";
    if ($l21auth->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')
    	$contents_user.=" <span class=\"text_det_it\">("._t('statut', 'O').")</span> ";
    if ($result_user[$i]['jwu_user_right']=='A')
    	$contents_user.=" <span class=\"text_det_it pending-user\">("._t('statut', 'pending').")</span> ";
    $contents_user.="</td>\n";
    if ($l21auth->isWorkgroupOrganiser($l21auth->GetSessionElement('id'), $sql_object, $id) || $l21auth->isSuperAdmin()){
      $contents_user.="<td><div class=\"iconetab\">";
      
      $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\"><i class=\"icon-trash\"></i><span>" . _t('workshop','del_user') . "</span></a>\n";
      $contents_user.="<a href=\"mailto:".$result_user[$i]['profile_email']."\" title=\"".$result_user[$i]['profile_email']."\" class=\"ico_mail\"><i class=\"icon-mail-1\"></i></a>";
      if ($result_user[$i]['jwu_user_right']=='A') {
      	$contents_user.="<a href=\"../workshop/_user.php?action=accept&amp;id=".$id."&amp;u_id=".$result_user[$i]['jwu_user_id']."\" title=\""._t('workshop','add_new_user')."\" class=\"ico_approve accept-user\"><i class=\"icon-ok\"></i><span>" . _t('workshop','add_new_user') . "</span></a>\n";
      }
      $contents_user.="</div>";
      $contents_user.="</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=\"toggle_title\">\n";
$reca_user.="<a id=\"workshopuser\" href=\"#\">"._t('workshop','user')."</a>\n";
$reca_user.="</div>\n";
$reca_user.="<div id=\"workshop_user\" style=\"display:none;\" >\n";
if ($l21auth->isWorkgroupOrganiser ($l21auth->GetSessionElement('id'), $sql_object, $id) || $l21auth->isSuperAdmin())
$reca_user.="<a href=\"".$link_add_u.$id."\" title=\""._t('workshop','add_new_user')."\" class=\"ico_add2\"><i class=\"icon-plus-circled\"></i><span>".  _t('workshop','add_new_user')."</span></a><br class=\"brendstep\" />";
$reca_user.=$contents_user;
if ($l21auth->isWorkgroupOrganiser ($l21auth->GetSessionElement('id'), $sql_object, $id) || $l21auth->isSuperAdmin())
$reca_user.="<div class=\"mailing_list\"><a href=\"mailto:".$mailing_list."\" title=\""._t('workshop','mailing_list')."\"><i class=\"icon-mail-1\"></i> &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 multisort\">\n";
  $contents_report.="<thead>\n";
  $contents_report.="<tr>\n";
  $contents_report.="<td>".mb_ucfirst(_t('workshop','title_report'))."</td>\n";
  $contents_report.="<td>".mb_ucfirst(_t('divers','statut'))."</td>\n";
  $contents_report.="<td>".mb_ucfirst(_t('divers','date_crea'))."</td>\n";
  $contents_report.="<td class=\"sorter-false\"> <span class=\"semnone\">".mb_ucfirst(_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 ($l21auth->isWorkgroupOrganiser ($l21auth->GetSessionElement('id'), $sql_object, $id) || $l21auth->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\"><i class=\"icon-trash\"></i><span>" . _t('workshop','del_report') . "</span></a>\n";
      $contents_report.="<a href=\"".$link_mod_rep.$result_report[$i]['workrep_id']."\" title=\""._t('workshop','mod_report')."\" class=\"ico_mod\"><i class=\"icon-pencil\"></i><span>" . _t('workshop','mod_report') . "</span></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=\"toggle_title\">\n";
$reca_report.="<a id=\"resreport\" href=\"#\">"._t('workshop','report')."</a>\n";
$reca_report.="</div>\n";
$reca_report.="<div id=\"res_report\" style=\"display:none;\" >\n";
if ($l21auth->isWorkgroupOrganiser ($l21auth->GetSessionElement('id'), $sql_object, $id) || $l21auth->isSuperAdmin())
$reca_report.="<a href=\"".$link_add_rep.$id."\" title=\""._t('workshop','add_new_report')."\" class=\"ico_add2\"><i class=\"icon-plus-circled\"></i><span>".  _t('workshop','add_new_report')."</span></a><br class=\"brendstep\" />";
$reca_report.=$contents_report;
$reca_report.="</div>\n";
$reca_report.="<br class=\"brendstep\" />\n";

$navtitle=_t('workshop','det')." : ".$workshop_denomination;

// ajax code
$js = '$("a.accept-user").click(function() {

			var el = this;
			var url = $(el).attr("href") + "&mode=ajax";
			
			$.ajax({
				type: "GET",
				url: url,
				dataType: "json",
				success: function(data){
					if(data.status==1) {
						humane.success = humane.spawn({ addnCls: "humane-jackedup-success"});
						humane.success(data.msg);
						var parentel = $(el).closest("tr");
						$(parentel).find("span.pending-user").fadeOut();
						$(parentel).removeClass("to-moderate");
						$(el).fadeOut();
					} else {
						humane.error = humane.spawn({ addnCls: "humane-jackedup-error"});
						humane.error(data.msg);
					}
				}
			});
			
			return false;

			});
			';

footerAddInlineJS($js);

// Ability to sort table
addDynamicCSS('../lib/js/jquery.tablesorter/theme.default.css');
footerAddJS('../lib/js/jquery.tablesorter/jquery.tablesorter.min.js');
$str = '$("table.multisort").tablesorter({	});';
footerAddInlineJS($str);
?>
<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_<?php echo $rub; ?>"
		class="chemin_rub"><?php echo _t('menu','workshop');?></a></li>
	<li><span><?php echo formatnavTitle($navtitle); ?></span></li>
</ul>
</div>
<!--end barre haute -->
<?php
include_once(THEME_ADMIN_PATH."quickicons.php");
?>
<div class="contentcontainer"><?php
include_once(override($dir.'/menurub.php', THEME_ADMIN_PATH));
?>
<div id="content"><?php	
afflinkbar($todo,$id, $lang);
echo "<h2>".formatTitleh2($workshop_denomination)."</h2>\n";
if ($l21auth->isSuperAdmin()){
  echo "<a href=\"".$link_sup.$id."\" title=\""._t('workshop','sup')."\" class=\"ico_sup2\"><i class=\"icon-trash\"></i><span>" . _t('workshop','sup') . "</span></a></a>";
}
if ($l21auth->isSuperAdmin() || $l21auth->isWorkgroupOrganiser ($l21auth->GetSessionElement('id'), $sql_object, $id)){
  echo "<a href=\"".$link_mod.$id."\" title=\""._t('workshop','mod')."\" class=\"ico_mod2\"><i class=\"icon-pencil\"></i><span>" . _t('workshop','mod') . "</span></a></a><br class=\"brendstep\" />";
}
echo $reca_generals;
echo $reca_user;
echo $reca_report;
?></div>

<?php
// Ability to drag'n drop items
if ($l21auth->isWorkgroupOrganiser ($l21auth->GetSessionElement('id'), $sql_object, $id) || $l21auth->isSuperAdmin()) {
	footerAddJS('../lib/js/jquery.tablednd_0_5.js');
	dragTableSettings();
}
?>
<?php include_once(override($dir.'/help.php', THEME_ADMIN_PATH)); ?>
</div>