<?php
/**
 * @package linea21.modules
 * @subpackage yellowpages
 * @author linea21 <info@linea21.com>
 * @version $id SVN
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */

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

include_once("../lib/input_helpers.php");
if (isset($_GET['id']))	$yp_id=$_GET['id'];
if (isset($_POST['id']))	$yp_id=$_POST['id'];

$requete=SQL_getdetyp($yp_id);
$data_yp=$sql_object->DBSelect($requete, 'OBJECT');
$display_title=formatTitleh2($data_yp[0]->yellowp_name);
$navtitle=_t('yp','mod')." : ".$data_yp[0]->yellowp_name;

?><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','yellowpages');?></a>
		</li>
		<li>
			<span><? echo formatnavTitle($navtitle); ?></span>
		</li>
	</ul>
</div>
<!--end barre haute -->
<?php
if(isset($_POST['enregistrer'])) {
	$data_table=unserialize(urldecode($_POST['data_table']));
	$yp_object= new yellowpages;
	$result=$yp_object->ModifyYellowPages($yp_id, $data_table, $sql_object);
	$link_confirm="confirm.php?rub=".$rub."&todo=".$todo."&id=".$yp_id;

	if($result) header("Location: ".$link_confirm);
	else  system_error();
}

$form_name=formatText($data_yp[0]->yellowp_name, '2FIELD');
$form_activity=formatText($data_yp[0]->yellowp_activity, '2FIELD');
$form_theme=$data_yp[0]->yellowp_theme;
$form_street=formatText($data_yp[0]->yellowp_street, '2FIELD');
$form_postal_code=formatText($data_yp[0]->yellowp_postal_code, '2FIELD');
$form_city=formatText($data_yp[0]->yellowp_city, '2FIELD');
$form_phone=$data_yp[0]->yellowp_phone;
$form_fax=$data_yp[0]->yellowp_fax;
$form_email=formatText($data_yp[0]->yellowp_email, '2FIELD');
$form_website=formatText($data_yp[0]->yellowp_website, '2FIELD');
$form_statut=$data_yp[0]->yellowp_statut;
if($form_statut=='AA') $mask_statut_D="checked=\"checked\""; else $mask_statut_D='';
if($form_statut=='P') $mask_statut_P="checked=\"checked\""; else $mask_statut_P='';


if(isset($_POST['valider'])) {
	$table[0]=$_POST['yp_name'];
	$table[1]=$_POST['yp_activity'];
	$table[2]=$_POST['yp_theme'];
	$table[3]=$_POST['yp_street'];
	$table[4]=$_POST['yp_postal_code'];
	$table[5]=$_POST['yp_city'];
	$table[6]='';
	$table[7]=$_POST['yp_phone'];
	$table[8]=$_POST['yp_fax'];
	$table[9]=$_POST['yp_email'];
	$table[10]=$_POST['yp_website'];
	$table[11]=$_POST['yp_statut'];
	$yp_object= new yellowpages;
	$integrity=$yp_object->CheckDataIntegrity($table);
	
	$form_name=formatText($_POST['yp_name'], '2FIELD');
	$form_activity=formatText($_POST['yp_activity'], '2FIELD');
	$form_theme=$_POST['yp_theme'];
	$form_street=formatText($_POST['yp_street'], '2FIELD');
	$form_postal_code=formatText($_POST['yp_postal_code'], '2FIELD');
	$form_city=formatText($_POST['yp_city'], '2FIELD');
	$form_phone=$_POST['yp_phone'];
	$form_fax=$_POST['yp_fax'];
	$form_email=formatText($_POST['yp_email'], '2FIELD');
	$form_website=formatText($_POST['yp_website'], '2FIELD');
	$form_statut=$_POST['yp_statut'];
	if($form_statut=='AA') $mask_statut_D="checked=\"checked\""; else $mask_statut_D='';
	if($form_statut=='P') $mask_statut_P="checked=\"checked\""; else $mask_statut_P='';
	
	$table=urlencode(serialize($table));
}
include_once(THEME_ADMIN_PATH."quickicons.php");

// select-box de thèmes
$data=$sql_object->DBSelect($req_list_theme);
$select_theme=ThemeSelectBox($data, "yp_theme", $form_theme);
?>

<?php
if(!isset($integrity) || is_string($integrity)) {
?>
<div class="contentcontainer">
		<?php
		include_once($dir."/menurub.php");
		?>
		<div id="content">
			<? 
    		$link_det_state=$rub_link."&todo=det&state=".$form_statut."&amp;id="; 
    		if ($form_statut=='D') {  ?>
        	<div class="mod_link">
        	<a href="<? echo $link_det_state.$yp_id ;?>"><?echo _t('yp','confirmation');?></a>
        	</div><br class="brendstep" />
    		<?php } ?>
		
			<?php
			if(isset($integrity) && is_string($integrity)) display_errors($integrity);
			?>
			<h2><?php echo $display_title; ?></h2>
			
			<form id="addyp" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
				<p>
				<label for="yp_name" ><? echo _t('yp','name2') ?> * :</label>
				<input name="yp_name" type="text" class="textfield" id="yp_name" maxlength="150" value="<?php echo $form_name; ?>" />
				</p>
				<p>
				<label for="yp_activity" ><? echo _t('yp','activity') ?> * :</label>
				<input name="yp_activity" type="text" class="textfield" id="yp_activity" maxlength="255" value="<?php echo $form_activity; ?>" />
				</p>
				<p>
				<label for="yp_theme" ><? echo _t('yp','theme') ?> : </label>
				<?php echo $select_theme; ?>
				</p>
				<?php if($form_statut=='P' || $form_statut=='AA'){?>
				<p>
				<label for="statut_P"><? echo _t('divers','statut'); ?> * : </label>
				<input name="yp_statut" type="radio" id="statut_P" value="P" <?php echo $mask_statut_P; ?> /><span class="radio"><?php echo _t('statut','public'); ?></span>
				<input name="yp_statut" type="radio" id="statut_D" value="AA" <?php echo $mask_statut_D; ?> /><span class="radio"><?php echo _t('statut','AA'); ?></span>
				<br />
				</p>
				<?php } else echo "<input name=\"yp_statut\" type=\"hidden\" value=\"D\" id=\"yp_statut\" />" ;?>
                <p>
				<? echo _t('yp','infos_adresse') ?>
				</p>

				<p>
				<label for="yp_street" ><? echo _t('yp','street') ?> * :</label>
				<input name="yp_street" type="text" class="textfield" id="yp_street" maxlength="200" value="<?php echo $form_street; ?>" />
				</p>
				<p>
				<label for="yp_postal_code" ><? echo _t('yp','postal_code') ?> * :</label>
				<input name="yp_postal_code" type="text" class="textfield" id="yp_postal_code" maxlength="6" value="<?php echo $form_postal_code; ?>" />
				</p>
				<p>
				<label for="yp_city" ><? echo _t('yp','city') ?> * :</label>
				<input name="yp_city" type="text" class="textfield" id="yp_city" maxlength="100" value="<?php echo $form_city; ?>" />
				</p>
				<p>
				<label for="yp_phone" ><? echo _t('yp','phone') ?> :</label>
				<input name="yp_phone" type="text" class="textfield" id="yp_phone" maxlength="12" value="<?php echo $form_phone; ?>" />
				</p>
				<p>
				<label for="yp_fax" ><? echo _t('yp','fax') ?> :</label>
				<input name="yp_fax" type="text" class="textfield" id="yp_fax" maxlength="12" value="<?php echo $form_fax; ?>" />
				</p>
				<p>
				<label for="yp_email" ><? echo _t('yp','email') ?> * :</label>
				<input name="yp_email" type="text" class="textfield" id="yp_email" maxlength="150" value="<?php echo $form_email; ?>" />
				</p>
				<p>
				<label for="yp_website" ><? echo _t('yp','website') ?> :</label>
				<input name="yp_website" type="text" class="textfield" id="yp_website" maxlength="150" value="<?php echo $form_website; ?>" />
				</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=det&amp;id=".$yp_id); ?>
				<input name="id" type="hidden" value="<?php echo $yp_id; ?>" id="id" />
				<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	{
if($form_theme==-1) $display_form_theme=_t('yp','notheme');
else {
$onetheme= SQL_getOneyptheme($form_theme);
$onetheme=$sql_object->DBSelect($onetheme);
$display_form_theme=formatText($onetheme[0]['theme_name'], '2HTML');
}			
$display_form_name=formatText(empty_nc($form_name), '2HTML');
$display_form_activity=formatText(empty_nc($form_activity), '2HTML');
$display_form_street=formatText(empty_nc($form_street), '2HTML');
$display_form_postal_code=formatText(empty_nc($form_postal_code), '2HTML');
$display_form_city=formatText(empty_nc($form_city), '2HTML');
$display_form_phone=formatText(empty_nc($form_phone), '2HTML');
$display_form_fax=formatText(empty_nc($form_fax), '2HTML');
$display_form_email=formatText(empty_nc($form_email), '2HTML');
$display_form_website=formatText(empty_nc($form_website), '2HTML');
if ($form_statut=='D') $display_form_statut=_t('yp','draft');
else $display_form_statut=display_statut($form_statut);
?>
<div class="contentcontainer">
<?php
include_once($dir."/menurub.php");
?>
<div id="content">
			<h2><? echo _t('recap','title'); ?></h2>
			<dl class="dl3">
				<dt><? echo _t('yp','name2'); ?> : </dt>
				<dd><?php echo $display_form_name; ?><br /></dd>
				<dt><? echo  _t('yp','activity') ;?> :</dt>
				<dd><?php echo $display_form_activity; ?><br /></dd>
				<dt><? echo _t('yp','theme'); ?> :</dt>
				<dd><?php echo $display_form_theme; ?><br /></dd>
				<dt><? echo _t('divers','statut'); ?> : </dt>
				<dd><?php echo $display_form_statut; ?><br /></dd>
				<dt><? echo _t('yp','street'); ?> : </dt>
				<dd><?php echo $display_form_street; ?><br /></dd>
				<dt><? echo _t('yp','postal_code') ;?> : </dt>
				<dd><?php echo $display_form_postal_code; ?><br /></dd>
				<dt><? echo _t('yp','city'); ?> : </dt>
				<dd><?php echo $display_form_city; ?><br /></dd>
				<dt><? echo  _t('yp','phone') ;?> : </dt>
				<dd><?php echo $display_form_phone; ?><br /></dd>
				<dt><? echo _t('yp','fax') ;?> : </dt>
				<dd><?php echo $display_form_fax; ?><br /></dd>
				<dt><? echo _t('yp','email') ;?> : </dt>
				<dd><?php echo $display_form_email; ?><br /></dd>
				<dt><? echo  _t('yp','website'); ?> : </dt>
				<dd><?php echo $display_form_website; ?><br /></dd>
			</dl>
			<form id="addscale" 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" />
				<input name="id" type="hidden" value="<?php echo $yp_id; ?>" id="id" />
				<? echo cancel_button($rub_link."&amp;todo=det&amp;id=".$yp_id); ?>
				<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
}
?>
