<?php
/**
 * Directory module
 * 
 * Directory entry detail page
 * 
 * @package linea21\modules\yellowpages
 * @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');
////////////

include_once(override('../yellowpages/display.php', THEME_ADMIN_PATH));


if(isset($_GET['state'])) {
  $state=$_GET['state'];
  if(isset($_POST['id']))	$yp_id=$_POST['id'];
  if(isset($_GET['id']))	$yp_id=$_GET['id'];
  $yp_object= new yellowpages;
  $result_update=$yp_object->StateYellowPages($yp_id, 'P', $sql_object);
  $link_confirm="confirm.php?rub=".$rub."&todo=mod&id=".$yp_id;
  if (ALERT_DIRECTORY==1) {
  	
  	include_once(override('../mail/mail_actions.php'));
  	include_once(override('../mail/send.php'));
  	$a = array();
  	
  	$a['action'] = 'confirm_entry';
  	$link = HrefMaker(array('rub' => $GLOBALS['links'][U_L]['directory-detail']['linkvalue'], 'id' => $yp_id));
  	$a['link_entry'] = $link;
  	
  	$result=$sql_object->DBSelect(SQL_getdetyp($yp_id));
  	$a['recipient'] = $result[0]['yellowp_email'];

    $emailContainer = prepare_email($a);
    $r = send_email($emailContainer);
    
  }
  echo $result_update;
  if($result_update) header("Location: ".safe_redirect($link_confirm));
  else  system_error();
}

if(!isset($_GET['id']) && !isset($_POST['id'])) {
  $id="1";
} else {
  if(isset($_POST['id']))	$id=$_POST['id'];
  if(isset($_GET['id']))	$id=$_GET['id'];
}

$req_det= SQL_getdetyp($id);
$result=$sql_object->DBSelect($req_det);

// Do record exists?
if(!isset($result[0]['yellowp_name'])) redirect_to('@module_default');

$link_det=$rub_link."&amp;todo=det&amp;id=";
$link_det_level="index.php?rub=level&amp;todo=det&amp;id=";
$link_sup=$rub_link."&amp;todo=sup&amp;id=";
$link_mod=$rub_link."&amp;todo=mod&amp;id=";
$navtitle=_t('yp','det')." : ".$result[0]['yellowp_name'];
$display_title=formatTitleh2($result[0]['yellowp_name']);
?>
<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','yellowpages')?></a></li>
  	<li><span><?php echo formatnavTitle($navtitle); ?></span></li>
  </ul>
</div>
<!--end barre haute -->

<div class="contentcontainer"><?php
include_once(override($dir.'/menurub.php', THEME_ADMIN_PATH));
?>
<div id="content">
<?php
$link_det_state=$rub_link."&todo=det&state=".$result[0]['yellowp_statut']."&amp;id=";
if ($result[0]['yellowp_statut']=='D') {  ?>
<div class="mod_link">
	<a href="<?php echo $link_det_state.$id ;?>"><?php echo _t('yp','confirmation');?></a>
</div>
<br class="brendstep" />
<?php } ?>
<h2><?php  echo $display_title; ?></h2>
<?php echo "<a href=\"".$link_sup.$id."\" title=\""._t('yp','sup')."\" class=\"ico_sup2\">"; ?><i class="icon-trash"></i><span><?php echo _t('yp','sup'); ?></span></a>
<?php echo "<a href=\"".$link_mod.$id."\" title=\""._t('yp','mod')."\" class=\"ico_mod2\">"; ?><i class="icon-pencil"></i><span><?php echo _t('yp','mod'); ?></span></a>

<dl class="dl2">
	<dt><?php echo mb_ucfirst(_t('yp','level')); ?> :</dt>
	<dd><?php
	if ($result[0]['yellowp_level'] != 0) echo "<a href=\"".$link_det_level.$result[0]['yellowp_level']."\" title=\"".formatText($result[0]['level_name'], '2HTML')."\">".formatText($result[0]['level_name'], '2HTML')."</a></dd>";
	else echo _t('yp','nolevel')."</dd>";
	?>
	<dt><?php echo mb_ucfirst(_t('yp','name2')); ?> :</dt>
	<dd><?php echo formatText(empty_nc($result[0]['yellowp_name']), '2HTML'); ?></dd>
	<dt><?php echo mb_ucfirst(_t('yp','activity')); ?> :</dt>
	<dd><?php echo formatText(empty_nc($result[0]['yellowp_activity']), '2HTML'); ?></dd>
	<dt><?php echo mb_ucfirst(_t('yp','street')); ?> :</dt>
	<dd><?php echo formatText(empty_nc($result[0]['yellowp_street']), '2HTML');?></dd>
	<dt><?php echo mb_ucfirst(_t('yp','postal_code')); ?> :</dt>
	<dd><?php echo formatText(empty_nc($result[0]['yellowp_postal_code']), '2HTML');?></dd>
	<dt><?php echo mb_ucfirst(_t('yp','city')); ?> :</dt>
	<dd><?php echo formatText(empty_nc($result[0]['yellowp_city']), '2HTML');?></dd>
	<dt><?php echo mb_ucfirst(_t('yp','phone')); ?> :</dt>
	<dd class="phone-format"><?php echo formatText(empty_nc($result[0]['yellowp_phone']), '2HTML');?></dd>
	<dt><?php echo mb_ucfirst(_t('yp','fax'));?> :</dt>
	<dd class="phone-format"><?php echo formatText(empty_nc($result[0]['yellowp_fax']), '2HTML');?></dd>
	<dt><?php echo mb_ucfirst(_t('yp','email')); ?> :</dt>
	<dd><?php echo "<a href=\"mailto:".$result[0]['yellowp_email']."\" title=\"" .formatText($result[0]['yellowp_email'], '2HTML')."\">" .formatText($result[0]['yellowp_email'], '2HTML')."</a>";?></dd>
	<dt><?php echo mb_ucfirst(_t('yp','website')); ?> :</dt>
	<dd><?php
	if ($result[0]['yellowp_website']<>"")
	echo "<a href=\"".$result[0]['yellowp_website']."\" title=\"".formatText($result[0]['yellowp_website'], '2HTML')."\">".formatText($result[0]['yellowp_website'], '2HTML')."</a></dd>";
	else    echo formatText(empty_nc($result[0]['yellowp_website']), '2HTML')."</dd>";

	?>
	<dt><?php echo mb_ucfirst(_t('divers','date_crea')); ?> :</dt>
	<dd><?php echo $result[0]['yellowp_date_crea'];?></dd>
	<dt><?php echo mb_ucfirst(_t('divers','statut')); ?> :</dt>
	<dd><?php if ($result[0]['yellowp_statut']=='D') {
	  echo mb_ucfirst(_t('yp','draft'));
	}
	else echo display_statut($result[0]['yellowp_statut']);?></dd>

</dl>
<?php 
if(defined('MAP_ENGINE') && MAP_ENGINE == 'leaflet') {
    	echo generateLMap('map', $result, 16) ;
    } else {
    	echo generateGMap('map', $result, 16) ;
    }
?>
<?php 
if(U_L == 'fr') {
	footerAddJS('../lib/js/jquery-mask-plugin/dist/jquery.mask.min.js');
	footerAddInlineJS("
 		$( '.phone-format').each(function( index ) {
	  if($(this).text() != '".empty_nc('')."') $(this).mask('00 00 00 00 00');
	});");
}
?>
</div> <!-- closing #content -->
</div> <!-- closing .contentcontainer -->