<?php
/**
 * Level module
 * 
 * Level detail page
 * 
 * @package linea21\core\level
 * @author $Author$ - linea21 <info@linea21.com>
 * @version $Id$ 
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */

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


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

if (isset($_GET['id']))	$id=$_GET['id'];
if (isset($_POST['id'])) $id=$_POST['id'];


// getting Associated News
$newslist = '';
$data=$sql_object->DBSelect(SQL_getNewsByLevel($id));
if(isset($data[0]['news_id'])) {
	$link = 'index.php?rub=news&amp;todo=det&amp;id=';

	$newslist  .= '<ul>'.PHP_EOL;
	foreach($data as &$el) {
		$newslist  .= '<li><a href="'.$link.$el['news_id'].'">'.$el['news_title'].'</a></li>'.PHP_EOL;
	}
	$newslist .= '</ul>'.PHP_EOL;
}

// getting Associated Publications
$publilist = '';
$data=$sql_object->DBSelect(SQL_getPublicationsByLevel($id));
if(isset($data[0]['publi_id'])) {
	$link = 'index.php?rub=publication&amp;todo=det&amp;id=';

	$publilist  .= '<ul>'.PHP_EOL;
	foreach($data as &$el) {
		$publilist  .= '<li><a href="'.$link.$el['publi_id'].'">'.$el['publi_title'].'</a></li>'.PHP_EOL;
	}
	$publilist .= '</ul>'.PHP_EOL;
}

// getting Associated projects
$projectlist = '';
$data=$sql_object->DBSelect(SQL_getProjectsByLevel($id));
if(isset($data[0]['project_id'])) {
	$link = 'index.php?rub=project&amp;todo=det&amp;id=';

	$projectlist  .= '<ul>'.PHP_EOL;
	foreach($data as &$el) {
		$projectlist  .= '<li><a href="'.$link.$el['project_id'].'">'.$el['project_name'].'</a></li>'.PHP_EOL;
	}
	$projectlist .= '</ul>'.PHP_EOL;
}

// getting Associated indicators
$indicatorslist = '';
$data=$sql_object->DBSelect(SQL_getIndicatorsByLevel($id));
if(isset($data[0]['sdii_id'])) {
	$link = 'index.php?rub=sdi&amp;todo=det&amp;id=';

	$indicatorslist  .= '<ul>'.PHP_EOL;
	foreach($data as &$el) {
		$indicatorslist  .= '<li><a href="'.$link.$el['sdii_id'].'">'.$el['sdii_name'].'</a></li>'.PHP_EOL;
	}
	$indicatorslist .= '</ul>'.PHP_EOL;
}

// getting Associated workgroups
$workgroupslist = '';
$data=$sql_object->DBSelect(SQL_getWorkshopsByLevel($id));
if(isset($data[0]['workshop_id'])) {
	$link = 'index.php?rub=workshop&amp;todo=det&amp;id=';

	$workgroupslist  .= '<ul>'.PHP_EOL;
	foreach($data as &$el) {
		$workgroupslist  .= '<li><a href="'.$link.$el['workshop_id'].'">'.$el['workshop_denomination'].'</a></li>'.PHP_EOL;
	}
	$workgroupslist .= '</ul>'.PHP_EOL;
}


// getting Associated directory entries
$directorylist = '';
$data=$sql_object->DBSelect(SQL_getDirectoryEntriesByLevel($id));
if(isset($data[0]['yellowp_id'])) {
	$link = 'index.php?rub=yellowpages&amp;todo=det&amp;id=';

	$directorylist  .= '<ul>'.PHP_EOL;
	foreach($data as &$el) {
		$directorylist  .= '<li><a href="'.$link.$el['yellowp_id'].'">'.$el['yellowp_name'].'</a></li>'.PHP_EOL;
	}
	$directorylist .= '</ul>'.PHP_EOL;
}


  $req_det= SQL_getoneLevel($id);
  $result=$sql_object->DBSelect($req_det);
  
  // Do record exists?
  if(!isset($result[0]['level_name'])) redirect_to('@module_default');
  
  $current_title=formatText($result[0]['level_name'],'2HTML');
  $current_code=empty_nc(formatText($result[0]['level_code'],'2HTML'));
  $current_label=formatText($result[0]['level_label'],'2HTML');
  $parent_label=formatText($result[0]['parent_label'],'2HTML');

  // formattage des données
  $desc_project=empty_nc(formatText($result[0]['level_desc_project'], '2HTML'));
  $desc_dashboard=empty_nc(formatText($result[0]['level_desc_dashboard'], '2HTML'));
  $desc_publi=empty_nc(formatText($result[0]['level_desc_publication'], '2HTML'));
  $desc_workshop=empty_nc(formatText($result[0]['level_desc_workshop'], '2HTML'));
  $desc_news=empty_nc(formatText($result[0]['level_desc_news'], '2HTML'));
  $date_crea=$result[0]['level_date_crea'];
  $last_modify=$result[0]['level_last_modify'];

  $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=";
  ?>
<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','level');?></a></li>
	<li><span><?php echo formatNavTitle($current_label. " : " .$current_title)?></span></li>
</ul>
</div>
<!--end barre haute -->

<div class="contentcontainer"><?php
include_once(override($dir.'/menurub.php', THEME_ADMIN_PATH));
?>
<div id="content"><?php
include_once(override($dir.'/display.php', THEME_ADMIN_PATH));

echo "<h2>";
echo formatTitleh2("<span class=\"label-info\">" . $current_label. " : </span>" .$current_title);
echo "</h2>\n";
echo "\t<a href=\"".$link_sup.$id."\" title=\""._t('level','sup')."\" class=\"ico_sup2\"><i class=\"icon-trash\"></i><span>" . _t('level','sup') . "</span></a>\n";
echo "\t<a href=\"".$link_mod.$id."\" title=\""._t('level','mod')."\" class=\"ico_mod2\"><i class=\"icon-pencil\"></i><span>" . _t('level','mod') . "</span></a>\n";
echo "<dl class=\"summary\">\n";
if($result[0]['parent_id'] != 0) {
echo "<dt>".mb_ucfirst($parent_label). " :</dt>\n";
echo "<dd><a href=\"".$link_det.$result[0]['parent_id']."\">".formatText($result[0]['parent_name'],'2HTML')."</a></dd>\n";
}
echo "<dt>".formatText(mb_ucfirst(_t('level','code')), '2HTML')." :</dt>\n";
echo "<dd>".$current_code."</dd>\n";
if(defined('MOD_PROJECT')) {
  echo "<dt>".formatText(mb_ucfirst(_t('level','desc_det_project')), '2HTML')." :</dt>\n";
  echo "<dd>".$desc_project."</dd>\n";
}
if(defined('MOD_SDI')) {
  echo "<dt>".formatText(mb_ucfirst(_t('level','desc_det_dashboard')), '2HTML')." :</dt>\n";
  echo "<dd>".$desc_dashboard."</dd>\n";
}
if(defined('MOD_PUBLICATION')) {
  echo "<dt>".formatText(mb_ucfirst(_t('level','desc_det_publication')), '2HTML')." :</dt>\n";
  echo "<dd>".$desc_publi."</dd>\n";
}
if(defined('MOD_WORKSHOP')) {
  echo "<dt>".formatText(mb_ucfirst(_t('level','desc_det_workshop')), '2HTML')." :</dt>\n";
  echo "<dd>".$desc_workshop."</dd>\n";
}
if(defined('MOD_NEWS')) {
  echo "<dt>".formatText(mb_ucfirst(_t('level','desc_det_news')), '2HTML')." :</dt>\n";
  echo "<dd>".$desc_news."</dd>\n";
}
echo "<dt>".formatText(mb_ucfirst(_t('divers','last_modify')), '2HTML')." :</dt>\n";
echo "<dd>".$last_modify."</dd>\n";
echo "<dt>".formatText(mb_ucfirst(_t('divers','date_crea')), '2HTML')." :</dt>\n";
echo "<dd>".$date_crea."</dd>\n";
/** PAS DE GESTION DES STATUTS
 echo "<dt>".formatText(_t('divers','statut'), '2HTML') ." :</dt>\n";
 echo "<dd>".display_statut($result[0]['level_status']). "</dd>\n";
 **/
echo "</dl>\n";
?>
<h3 class="part"><?php echo mb_ucfirst(_t('content','associated_content')); ?></h3>
<dl class="summary">
	<dt><?php echo mb_ucfirst(_t('content','in_news')); ?> :</dt>
	<dd><?php echo empty_none($newslist); ?></dd>
	<dt><?php echo mb_ucfirst(_t('content','in_publication')); ?> :</dt>
	<dd><?php echo empty_none($publilist); ?></dd>
	<dt><?php echo mb_ucfirst(_t('content','in_project')); ?> :</dt>
	<dd><?php echo empty_none($projectlist); ?></dd>
	<dt><?php echo mb_ucfirst(_t('content','in_indicator')); ?> :</dt>
	<dd><?php echo empty_none($indicatorslist); ?></dd>
	<dt><?php echo mb_ucfirst(_t('content','in_workgroup')); ?> :</dt>
	<dd><?php echo empty_none($workgroupslist); ?></dd>
	<dt><?php echo mb_ucfirst(_t('content','in_directory')); ?> :</dt>
	<dd><?php echo empty_none($directorylist); ?></dd>
</dl>


</div> <!-- closing #content -->
</div> <!-- closing .contentcontainer -->