<center>
<?php

if(isset($_POST['motcle'])) {

$motcle = stripslashes($_POST['motcle']);

// on remplace les caractères spéciaux
$motcle = str_replace(array('à','á','â','ã','ä','å'),'a',$motcle);
$motcle = str_replace(array('ò','ó','ô','õ','ö','ø'),'o',$motcle);
$motcle = str_replace(array('è','é','ê','ë'),'e',$motcle);
$motcle = str_replace('ç','c',$motcle);
$motcle = str_replace(array('ì','í','î','ï'),'i',$motcle);
$motcle = str_replace(array('ù','ú','û','ü'),'u',$motcle);
$motcle = str_replace('ÿ','y',$motcle);
$motcle = str_replace('ñ','n',$motcle);
$motcle = str_replace('É','E',$motcle);
$motcle = str_replace('Ç','C',$motcle);
$motcle = str_replace('E','E',$motcle);
// passage des majuscule en minuscule
$motcle = strtolower($motcle);

$search_list = explode("\n", htmlentities($motcle));
$tmp = 0;

foreach($search_list as $search_string) {

	$url_amazon = 'http://www.amazon.fr/s/ref=nb_ss_m?__mk_fr_FR=%C5M%C5Z%D5%D1&url=search-alias%3Dstripbooks&field-keywords=' . $search_string;
	$url_amazon = str_replace(" ","+",$url_amazon);

	list($ebooks,$erreur) = getListEbookAmazon($url_amazon);

		  
	if(!empty($ebooks)) {
	
		foreach($ebooks as $unEbook)
		{

			echo '<form name="virgin" method="post" action="?page=ebooks&action=info">';
			
			echo '<table width="97%" border="0" align="center" cellpadding="0" cellspacing="0">
                  <tr>
                  <td height="91" valign="bottom" background="./images/img_ebook/f_ebook_h.png"><table width="200" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                  <td width="170" height="33" align="center"><input type="hidden" name="ebookinfo[' . $tmp . '][titre]" value="' . $unEbook['titre'] . '">
                  <input type="hidden" name="ebookinfo[' . $tmp . '][id]" value="' . $unEbook['id'] . '">
                  <input type="image" src="./images/fiche_valid.png" border="0" name="go" title="Selectionner cette Fiche" onmouseover="javascript:this.src=\'./images/fiche_valid1.png\';" onmouseout="javascript:this.src=\'./images/fiche_valid.png\';"></td>
                  <td align="center"><a href="http://www.amazon.fr/dp/' . $unEbook['id'] . '" target="_blank">
				  <img src="./images/amz.png" title="Voir la Fiche Complète sur Amazon.fr" width="38" height="26" border="0" onmouseover="javascript:this.src=\'./images/amz1.png\';" onmouseout="javascript:this.src=\'./images/amz.png\';"></a></td>
                  </tr><tr><td height="33"></td><td></td></tr></table></td></tr><tr>
                  <td background="./images/img_ebook/f_ebook_c.png">';
		
		    echo '<div class="ebooks" ><table border="0" cellspacing="0" cellpadding="0">';
            echo '<tr><td width="10"></td><td rowspan="2">';

            echo '<div style="background:url(./images/list/book.png); "><img src="' . $unEbook['affiche'] . '" width="110" height="156" style="border: 5px solid transparent;" title="Affiche de ' . trim($unEbook['titre']) . '" /></div></td><td width="30"></td><td width="550"><div style="border:#000000 1px solid; background:url(./images/list_film.gif); background-repeat: repeat-x;color:#000000;">';		
			echo '<strong>&nbsp;Titre :</strong> <span><u>' . $unEbook['titre'] . '</u></span><br>';
            echo '<strong>&nbsp;Par :</strong> <span><u>' . $unEbook['par'] . '</u></span><br>';
			echo '<strong>&nbsp;Date :</strong> <span><u>' . $unEbook['date'] . '</u></span><br>';
			echo '<strong>&nbsp;Type :</strong> <span><u>' . $unEbook['type'] . '</u></span><br>';

           echo '</div></td></tr>';
           echo '</table></div>';
		   echo '<br></td></tr><tr><td height="13" background="./images/img_ebook/f_ebook_b.png"></td></tr></table>';
		   echo '</form><br />';

		   $tmp++;
 
		}
		
		}else{
		if(!empty($erreur)) {
		echo '<center><meta http-equiv="Refresh" content="5;URL='.$PHP_SELF.'?page=ebooks">
              <div style="background-color:#FFCCCC; border:#000000 1px double; width:100%">
              <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
              <td align="center" valign="middle"><img src="./images/Panneauattention.png" hspace="10" vspace="10" border="0"></td>
              <td width="100%" align="center" valign="middle"><p>! --- ### ATTENTION ### --- !</p>
              <p>Une erreur s\'est produite, Veuillez nous en excuser ....</p>
              <p>( Redirection dans 5 secondes)</p></td>
              <td align="center" valign="middle"><img src="./images/Panneauattention.png" hspace="10" vspace="10" border="0"></td>
              </tr>
              </table>
              </div></center>';

	}else {
	
	echo '<center><meta http-equiv="Refresh" content="5;URL='.$PHP_SELF.'?page=ebooks">
          <div style="background-color:#FFCCCC; border:#000000 1px dashed; width:100%">
          <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
          <td align="center" valign="middle"><img src="./images/Aide.png" hspace="10" vspace="10" border="0"></td>
          <td width="100%" align="center" valign="middle"><p>! --- ### ATTENTION ### --- !</p>
          <p>&quot; Vous avez specifi&eacute; un mot cl&eacute; incorrect , ou il n\'existe pas &quot;</p>
          <p>Veuillez retaper un mot cl&eacute; svp ...</p>
          <p>( Redirection dans 5 secondes)</p></td>
          <td align="center" valign="middle"><img src="./images/Aide.png" hspace="10" vspace="10" border="0"></td>
          </tr>
          </table>
          </div></center>';
		
	}
	}
	
}
}else{ echo '<meta http-equiv="Refresh" content="1;URL='.$PHP_SELF.'?page=ebooks">';}
?>
</center>