<?php
if(!isset($mode)){
	$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : 'normal';
}

if($mode=='normal')
{
	$pays = $_REQUEST['pays'];
	$paysCode = $_SESSION['graydon']['paysCode'];
	$_SESSION['graydon']['mode'] = 'normal';
	
	require_once 'dbbootstrap.php';
		
	//Récupération de la liste de tous les pays (bdd : sdv1)	
	setDbConn('sdv1');
	$q = Doctrine_Query::Create()
		->select('codPays, libPaysEN')
		->from('Tabpays')
		->orderBy('libPaysEN ASC')
		->setHydrationMode(Doctrine::HYDRATE_ARRAY);
	$tabPaysComplete = $q->execute();

	//Lecture des pays graydon
	setDbConn('graydon');
	$q = Doctrine_Query::Create()
		->select('code')
		->from('Country')
		->where('status = "actif"')
		->setHydrationMode(Doctrine::HYDRATE_ARRAY);
	$result = $q->execute();
	$tabPaysGraydon == array();
	if(count($result)>0) foreach($result as $item){ $tabPaysGraydon[] = $item['code']; }
	
	//Lecture des pays intersud
	setDbConn('intersud');
	$q = Doctrine_Query::Create()
		->select('code')
		->from('Country')
		->where('status = "actif"')
		->setHydrationMode(Doctrine::HYDRATE_ARRAY);
	$result = $q->execute();
	$tabPaysIntersud == array();
	if(count($result)>0) foreach($result as $item){ $tabPaysIntersud[] = $item['code']; }
?>
<div class="fieldgrp">
<label class="StyleInfoLib">Pays : </label>
<div class="field">
<select id="pays" name="frmRecherche[CountryCode]" size="10">
<?php 
//lecture des pays dans la bdd
foreach($tabPaysComplete as $kPays){
	$selected = '';
	//Test des la présence du pays dans chaque partenaires
	$graydonPays = FALSE;
	$intersudPays = FALSE;
	if(count($tabPaysGraydon)>0 && in_array($kPays['codPays'], $tabPaysGraydon)){ $graydonPays = TRUE; }
	if(count($tabPaysIntersud)>0 && in_array($kPays['codPays'], $tabPaysIntersud)){ $intersudPays = TRUE; }
	
	if($graydonPays || $intersudPays){
		if( isset($paysCode) && $paysCode==$kPays['codPays'] ){ $selected = ' selected'; }
		print '<option value="'.$kPays['codPays'].'"'.$selected.'>'.$kPays['libPaysEN'].'</option>\n';
	}
}
?>
</select>
</div>
</div>
<div id="method">
<?php  
if(isset($method) || $_SESSION['graydon']['paysCode'])
{
	require_once './pages/graydon/methodfield.php';
}
?>
</div>
<div class="submit"><p class="submit-button"><input type="submit" value="Rechercher"/></p></div>
	
<?php 	
}elseif($mode=='demo'){
?>

<div class="fieldgrp">
<label>Pays : </label>
<div class="field">
<select name="frmDemo[Country]" size="10">
<option value="Austria">Austria</option>
<option value="Belgium">Belgium</option>
<option value="Bulgaria">Bulgaria</option>
<option value="Croatia">Croatia</option>
<option value="Czech Republic">Czech Republic</option>
<option value="Denmark">Denmark</option>
<option value="Estonia">Estonia</option>  
<option value="France">France</option>    
<option value="Germany">Germany</option>
<option value="Greece">Greece</option> 
<option value="Hungary">Hungary</option>
<option value="Irish Republic">Irish Republic</option>
<option value="Italy">Italy</option>
<option value="Japan">Japan</option>
<option value="Latvia">Latvia</option>
<option value="Lithuania">Lithuania</option>  
<option value="Netherlands">Netherlands</option>   
<option value="Poland">Poland</option>
<option value="Portugal">Portugal</option>
<option value="Romania">Romania</option>
<option value="Russia">Russia</option>
<option value="Saudi Arabia">Saudi Arabia</option>
<option value="Slovakia">Slovakia</option>
<option value="Slovenia">Slovenia</option> 
<option value="Spain">Spain</option>
<option value="Sweden">Sweden</option>
<option value="Switzerland">Switzerland</option>    
<option value="United Kingdom">United Kingdom</option>
<option value="USA">USA</option>
</select>
</div>
</div>
<div class="submit"><p class="submit-button"><input type="submit" class="submit" value="Rechercher" /></p></div>
<?php 
}
?>