  <script language="JavaScript">
  <?  
$groupe=$_SESSION['groupeUtilisateur'];
 
 
 if ($_SESSION['droitcmd'] == 1){	
	?>
	
	function verifValid()
	{
	//alert (document.recherch.typeUtilisation.value);
	var ok=0;
	for (var i=0; i<document.recherch.typeUtilisation.length;i++) {
         if (document.recherch.typeUtilisation[i].checked) {
           // alert(document.recherch.typeUtilisation[i].value);
	    ok = 1;
         }
      }
      if (ok==1){
			document.recherch.submit();
		}
	else
		{
		alert("Vous devez prciser une utilisation pour pouvoir lancer une recherche");	
		}
	}
/*
	if (document.recherch.typeUtilisation[0].status == '' && document.recherch.typeUtilisation[1].status == '' && document.recherch.typeUtilisation[2].status == '' <?if ($groupe==1){ echo "&& document.recherch.typeUtilisation[3].status == '' && document.recherch.typeUtilisation[4].status == '' && document.recherch.typeUtilisation[5].status== ''";} ?> )
		{
			alert("Vous devez prciser une utilisation pour pouvoir lancer une recherche");
		}
	else
		{
			document.recherch.submit();
		}
	}*/
	<?	
	}
	else
	{
	 ?>
	 	function verifValid()
	{	
			document.recherch.submit();	
	}
	 <?
	 }
 


?>

function verifFormu()
{
	
	var str;
	str=confirm("Voulez vous vraiment lancer une nouvelle recherche (vide aussi le panier) ?");
	//alert(str);
	if(str==true)
	{
		document.newRecherche.submit();
	}
	
}

</SCRIPT>
 
 <?  
include('config.php');
include("scripts/gstPanier.php");
//affichage ou non des photos non tlchargeables;
if(isset($_SESSION['telechargeable'])){
	$tele = $_SESSION['telechargeable'];
	}
	else{
	 if ($_SESSION['droitcmd'] == 1){	
	$_SESSION['telechargeable'] = 1;}
	else
	{
	$_SESSION['telechargeable'] = 0;
	
	}
}	

if(isset($_POST['telechargeable'])){
	
		$_SESSION['telechargeable'] = $_POST['telechargeable'];
		
	
}
$tele = $_SESSION['telechargeable'];



if(isset($_POST['new']))
{
		videPanier();	
}
if(isset($_POST['typeUtilisation'])){
	$_SESSION['idUtilisation'] =$_POST['typeUtilisation'];
	}
if(isset($_SESSION['idUtilisation'])){
	$crit = $_SESSION['idUtilisation'];}
	
//echo $crit;
if(isset($_POST['rechercher'])){
	
	
	
	
//-------------------------------------------------------------------------Concatnation de la requte de recherche------------------------------------------------------/////	
	$rqResultat="select photo.* from photo ";
	
	$sqlrqt="select * from recherche";
	if ($groupe==0)
	{
		$sqlrqt=$sqlrqt." where NIVEAUAFFICHAGE='".$groupe."'";
	}
	$sqlrqt=$sqlrqt." Order by ORDRE ASC";
	$resultat2=mysql_query($sqlrqt) or die ("requte non execut");
	if (! $resultat2) { echo "Erreur requete"; exit;} 
	while ($ligne2=mysql_fetch_array($resultat2))
	{	
		if($_POST[$ligne2['NOMRECHERCHE']]!=$nomInd)
		{
			if ($ligne2['CLEETRANGERE']==0)
			{
				$rqResultat=$rqResultat.",ass_photo_".$ligne2['NOMRECHERCHE']." ";
			}
		}
	}
	$ph="where";
	
	//$existe=0;
	$sqlrqt="select * from recherche";
	if ($groupe==0)
	{
		$sqlrqt=$sqlrqt." where NIVEAUAFFICHAGE='".$groupe."'";
	}
	$sqlrqt2=$sqlrqt." Order by ORDRE ASC";
	$resultat3=mysql_query($sqlrqt2) or die ("requte non execut");
	if (! $resultat3) { echo "Erreur requete"; exit;}  
	while ($ligne3=mysql_fetch_array($resultat3))
	{	
		if($_POST[$ligne3['NOMRECHERCHE']]!=$nomInd)
		{
			if ($ligne3['CLEETRANGERE']==0)
			{
				$rqResultat=$rqResultat.$ph." photo.IDPHOTO=ass_photo_".$ligne3['NOMRECHERCHE'].".FK_PHOTO ";
				$ph="and";
			}
			/*else
			{
				$existe=1;
			}*/
		}
	}
	
	$sqlrqt="select * from recherche";
	if ($groupe==0)
	{
		$sqlrqt=$sqlrqt." where NIVEAUAFFICHAGE='".$groupe."'";
	}
	$sqlrqt3=$sqlrqt." Order by ORDRE ASC";
	$resultat4=mysql_query($sqlrqt3) or die ("requte non execut");
	if (! $resultat4) { echo "Erreur requete"; exit;} 
	while ($ligne4=mysql_fetch_array($resultat4))
	{	
		
		if($_POST[$ligne4['NOMRECHERCHE']]!=$nomInd)
		{
			$sqlrqtF="select ID".$ligne4['NOMRECHERCHE']." from ".strtolower($ligne4['NOMRECHERCHE'])." WHERE NOM".$ligne4['NOMRECHERCHE']."='".$_POST[$ligne4['NOMRECHERCHE']]."'";
			$resultatF=mysql_query($sqlrqtF) or die ("requte ".$sqlrqtF." execut");
			if (! $resultatF) { echo "Erreur requete"; exit;}
			$ligneF=mysql_fetch_array($resultatF);
			$rqResultat=$rqResultat.$ph.' FK_'.$ligne4['NOMRECHERCHE'].'="'.$ligneF['ID'.$ligne4['NOMRECHERCHE']].'" ';
			$ph="and";
		}
	}
	
	
	if($_POST['champlibre']!="")
	{
		if($_POST['typeChaine']=="ou")
		{
			//decoupage champ libre
			$mots=array();
			$chaine=ltrim(rtrim($_POST['champlibre']));
			foreach($tabApo as $val)
			{
				$chaine=str_replace($val,"",$chaine);
			}
			//echo $chaine."<br>";
			$mot=explode(" ", $chaine);
			foreach($mot as $valeur)
			{
				$trouv=0;
				foreach($tabMot as $value)
				{
					if($value==$valeur)
					{ 
						$trouv=1;
					}
				}
				if ($trouv==0)
				{
					$mots[]=$valeur;
				}
			}
			
			$rqResultatMots=$rqResultat;
			
			foreach($mots as $affi)
			{
				//echo $affi."<br>";
				if ($rqResultat=="select photo.* from photo ")
				{
					$rqResultat=$rqResultat.$ph.' LEGENDE like "%'.$affi.'%" ';
				}
				else
				{
					$rqResultat=$rqResultat." UNION ALL ".$rqResultatMots.$ph.' LEGENDE like "%'.$affi.'%" ';
				}
	
			}
		
		
			//$rqResultat=$rqResultat.$ph.' LEGENDE like "%'.$_POST['champlibre'].'%" ';
			//echo $_POST['champlibre']."%<br>";
			
			$sqlrqt="select * from recherche";
			if ($groupe==0)
			{
				$sqlrqt=$sqlrqt." where NIVEAUAFFICHAGE='".$groupe."'";
			}
			$sqlrqt4=$sqlrqt." Order by ORDRE ASC";
			$resultat5=mysql_query($sqlrqt4) or die ("requte non execut");
			if (! $resultat5) { echo "Erreur requete"; exit;} 
			while ($ligne5=mysql_fetch_array($resultat5))
			{	
				//echo $rqResultat."<br>";
				if($_POST[$ligne5['NOMRECHERCHE']]==$nomInd)
				{	
					foreach($mots as $affic)
					{
						$sqlrqtB='select ID'.$ligne5['NOMRECHERCHE'].' from '.strtolower($ligne5['NOMRECHERCHE']).' WHERE NOM'.$ligne5['NOMRECHERCHE'].' like "%'.$affic.'%"';
						$resultatB=mysql_query($sqlrqtB) or die ("requte ".$sqlrqtB." non execut");
						if (! $resultatB) { echo "Erreur requete"; exit;}
						while($ligneB=mysql_fetch_array($resultatB))
						{
							if ($ligne5['CLEETRANGERE']==0)
							{
								$rqResultat=$rqResultat.' UNION ALL select photo.* from photo,ass_photo_'.strtolower($ligne5['NOMRECHERCHE']).' where photo.IDPHOTO=ass_photo_'.strtolower($ligne5['NOMRECHERCHE']).'.FK_PHOTO and FK_'.$ligne5['NOMRECHERCHE'].'="'.$ligneB['ID'.$ligne5['NOMRECHERCHE']].'" AND ( ';
							}
							else
							{
								$rqResultat=$rqResultat.' UNION ALL select photo.* from photo where FK_'.$ligne5['NOMRECHERCHE'].'="'.$ligneB['ID'.$ligne5['NOMRECHERCHE']].'" AND ( ';
							}
							$ch="";
							foreach($mots as $afficha)
							{
								$rqResultat=$rqResultat.$ch.' LEGENDE like "%'.$afficha.'%"';
								$ch=" OR ";
							}
							$rqResultat=$rqResultat.' )';
						}
					}
				
				}
			}
		
		}
		else
		{
			$rqResultat=$rqResultat.$ph.' LEGENDE like "%'.$_POST['champlibre'].'%" ';
			//echo $_POST['champlibre']."%<br>";
			
			$sqlrqt="select * from recherche";
			if ($groupe==0)
			{
				$sqlrqt=$sqlrqt." where NIVEAUAFFICHAGE='".$groupe."'";
			}
			$sqlrqt4=$sqlrqt." Order by ORDRE ASC";
			$resultat5=mysql_query($sqlrqt4) or die ("requte non execut");
			if (! $resultat5) { echo "Erreur requete"; exit;} 
			while ($ligne5=mysql_fetch_array($resultat5))
			{	
				if($_POST[$ligne5['NOMRECHERCHE']]==$nomInd)
				{
				$sqlrqtB='select ID'.$ligne5['NOMRECHERCHE'].' from '.strtolower($ligne5['NOMRECHERCHE']).' WHERE NOM'.$ligne5['NOMRECHERCHE'].' like "%'.$_POST['champlibre'].'%"';
				$resultatB=mysql_query($sqlrqtB) or die ("requte ".$sqlrqtB." non execut");
				if (! $resultatB) { echo "Erreur requete"; exit;}
				while($ligneB=mysql_fetch_array($resultatB))
				{
					if ($ligne5['CLEETRANGERE']==0)
					{
						$rqResultat=$rqResultat.' UNION ALL select photo.* from photo,ass_photo_'.strtolower($ligne5['NOMRECHERCHE']).' where photo.IDPHOTO=ass_photo_'.strtolower($ligne5['NOMRECHERCHE']).'.FK_PHOTO and FK_'.$ligne5['NOMRECHERCHE'].'="'.$ligneB['ID'.$ligne5['NOMRECHERCHE']].'" ';
					}
					else
					{
						$rqResultat=$rqResultat.' UNION ALL select photo.* from photo where FK_'.$ligne5['NOMRECHERCHE'].'="'.$ligneB['ID'.$ligne5['NOMRECHERCHE']].'" ';
					}
				}
				
				}
			}
		}
	}
		
	if(isset($_POST['rcIDPHOTO']) && $_POST['rcIDPHOTO']!='')	{
		$rqResultat=$rqResultat.' UNION ALL select photo.* from photo where IDPHOTO like "%'.$_POST['rcIDPHOTO'].'%" ';
	}			

	//$ph="and";
	
	//requete de recherche
	if ($rqResultat=="select photo.* from photo ")
	{
		//echo "1";
		$rqResultat="select *,count(IDPHOTO) as nb from photo";
	}
	else
	{
		//echo "2";
		$rqResultat="select *,count(IDPHOTO) as nb from (".$rqResultat;
		$rqResultat=$rqResultat.") as tb"; 
	}

	$rqResultat=$rqResultat." where 1 ";
	
	if(isset($_POST['rcIDPHOTO']) && $_POST['rcIDPHOTO']!='')	{
		$rqResultat=$rqResultat.' and IDPHOTO='.$_POST['rcIDPHOTO'].' ';
	}	
	
	if ($crit!="BO_TOUTE" && $tele=='1')
	{
		$rqResultat=$rqResultat." and ".$crit."='1'";
	}
	$rqResultat=$rqResultat." group by IDPHOTO Order by nb DESC, LEGENDE ASC";
	echo $rqResultat;
	$_SESSION['rqRecherche']=$rqResultat;
}

$rq="";

if(isset($_SESSION['rqRecherche']))
{
	$rq=$_SESSION['rqRecherche'];
}


//////////-------------------------------------------------------Affichage rsultats------------------------------------------------------------------------------


if ($rq!="")
{
 if ($_SESSION['droitcmd'] == 1){	
echo "<form method='POST' action='index.php?page=recherche.php' name='frmtele'>";

if ($tele==1){
echo "<a href='javascript:document.frmtele.submit()' > Afficher les photographies ngociables auprs des photographes >>></a>\n";
echo "<input type='hidden' value='0' name='telechargeable' />";	
if(isset($_POST['telechargeable']) && $crit!="BO_TOUTE"){
	$rq =str_replace(' group by',' and '.$crit.'=\'1\' group by ',$rq);
	$_SESSION['rqRecherche'] = $rq;
	}
}else{
echo "<a href='javascript:document.frmtele.submit()' > Afficher seulement les photos directement tlchargeables >>></a>\n";
echo "<input type='hidden' value='1' name='telechargeable' />";	
if(isset($_POST['telechargeable']) && $crit!="BO_TOUTE"){
	$rq = str_replace(' and '.$crit.'=\'1\' group by ',' group by ',$rq);
	$_SESSION['rqRecherche'] = $rq;
	}
}
echo "</form>";
}

	echo "<div align=center><form method='POST' action='index.php?page=recherche.php' name='newRecherche'>";	
	//echo "<input type='button' value='Nouvelle Recherche' onClick='javascript:verifFormu()' name='Nouvellerecherche' size='40'  />";
	echo "<a href='javascript:verifFormu()'>Nouvelle Recherche</a>";
	echo "<input type='hidden' value='new' name='new' />";
	echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='index.php?page=panier.php' >Valider mon panier</a>"; 
	echo "</form></div>";	
	if(isset($_POST['visucouleur'])){
	
		$_SESSION['visucouleur'] = $_POST['visucouleur'];
		$sqlColor= "UPDATE utilisateur SET utilisateur.VISUCOULEUR = '".$_POST['visucouleur']."' WHERE utilisateur.IDUTILISATEUR = ".$_SESSION['idUtilisateur'] ;
		//echo $sqlColor;
		mysql_query($sqlColor ) or die ("Requte non execute.");
		
		
	}
	
	
	$nbTotResultat=mysql_num_rows(mysql_query($rq));
	//Gestion du Panier

	//----------chaine de variable de positionnement page et nb photo par page
	$strInput="<input type=hidden name='nomPage' value='recherche.php' />";
	//recup du nombre de photo par page
	
	if(isset($_POST['parPage'])){
		$parPage=$_POST['parPage'];
		$_SESSION['parPage'] = $parPage;
	}else{
		if(isset($_SESSION['parPage'])){
			$parPage=$_SESSION['parPage'];
		}else{
			$parPage=25;
			}
		
	}
	$strInput.="<input type=hidden name='parPage' value='".$parPage."' />";
	//recup du num de page
	if(isset($_POST['page'])){
		$page=$_POST['page'];
		$_SESSION['page'] = $page;
	}else{
		if(isset($_SESSION['page'])){
			$page=$_SESSION['page'];
		}else{
			$page=1;
			}
	}
	
	
	$strInput.="<input type=hidden name='page' value='".$page."' />";
	
	$curAff = " LIMIT ".(($page*$parPage)-$parPage).",".$parPage;
	$resultat=mysql_query($rq.$curAff) or die ("requte ".$rq.$curAff." non execut");
	//calcul du nombre de page
	$nbPage=intval(abs($nbTotResultat/$parPage))+1;
	echo "<P align='center'><br />";
	include("scripts/paginateur.php");
	echo "</P>";
	
	$icpt=1;
	echo "<table align=center width=790>";
	
	if (! $resultat) { echo "Erreur requete"; exit;} 
		while ($photo=mysql_fetch_array($resultat)){	
			$ficPhoto="IMG".substr((100000+$photo['IDPHOTO']),1).".JPG";
			$repPhoto=substr((100000+$photo['IDPHOTO']),1,3)."00";
			if ($icpt==1){
				echo "<tr bgcolor=#FFFFFF  valign=top><td colspan=5  valign=top><hr /></td></tr><tr>";
			}
			echo "<td align=center width='18%' valign=top>";
			echo"<table width='100%' height=110 valign=top><tr><td colspan=2 align=center bgcolor=".$_SESSION['visucouleur']." ><br />";
			
			if (file_exists("photos/vignettes/".$repPhoto."/".$ficPhoto)) {
			$imgSrc = "src='photos/vignettes/".$repPhoto."/".$ficPhoto."'";
			}else{
			$imgSrc ="src='pics/default.jpg'";		
			}
			//echo "<table><tr><td>";
			echo "<form name='zoom".$photo['IDPHOTO']."' action=index.php?page=zoom.php method=POST >";		
			echo "<input type=image $imgSrc onClick='javascript:submit()' height=90 alt='Dtail'/><br />";			
			echo $strInput;
			echo "<input type=hidden name='IDPHOTOzoom' value=".$photo['IDPHOTO']." />";
			//echo "<input type=hidden name='IDPHOTO' value=".$photo['IDPHOTO']." />";
			echo "</form>\n	</td></tr><tr><td align=center width='80%' colspan=2>";
			
			if ($crit=="BO_TOUTE"){
			include('scripts/logoPanier.php');
			}else{
			//echo $photo[$_SESSION['idUtilisation']];
				if ($photo[$crit] && $_SESSION['droitcmd'] == 1 && $crit!=1){
				
				include('scripts/logoPanier.php');
				}
				else
				{
				include('scripts/logoVisu.php');
				}
			}			
			
			echo "</td></tr>";		
			include('scripts/propPhoto.php')
			?>
			</table>
			
			<?
			echo "</td>";
			if ($icpt==5){
				echo "</tr>";
				$icpt=0;
			}
			$icpt++;
		}
		
	echo "</table>";	
	echo "<P align='center'><br />";
	include("scripts/minipaginateur.php");
	echo "</P><br />";
}
else
{
	//affichage des criteres de recherche

//////////-------------------------------------------------------Affichage criteres de recherche------------------------------------------------------------------------------
	
	echo "<form method='POST' action='index.php?page=recherche.php' name='recherch'><center><table >";	
	echo "<tr><td>Identifiant</td><td><input type=texte value='' name='rcIDPHOTO' /></td></tr>";
	$sqlrqt="select * from recherche where BO_AFF=1";
	if ($groupe==0)
	{
		$sqlrqt=$sqlrqt." And NIVEAUAFFICHAGE='".$groupe."'";
	}
	$sqlrqt=$sqlrqt." Order by ORDRE ASC";
	echo $sqlrqt;
	$resultat2=mysql_query($sqlrqt) or die ("requte non execut");
	if (! $resultat2) { echo "Erreur requete"; exit;} 
	while ($ligne2=mysql_fetch_array($resultat2))
	{	
		echo "<tr><td>".$ligne2['LIBELLERECHERCHE']." :</td>";	
		$sqlrqtC="select NOM".$ligne2['NOMRECHERCHE']." from ".strtolower($ligne2['NOMRECHERCHE'])." Order by 1 ASC";
		//echo $sqlrqtC;
		echo '<td><select name='.$ligne2['NOMRECHERCHE'].'>';
		echo "<option>".$nomInd."</option>";
		$resultatC=mysql_query($sqlrqtC) or die ("requte non execut");
		if (! $resultatC) { echo "Erreur requete"; exit;} 
		while ($ligneC=mysql_fetch_array($resultatC))
		{
			?>
			<option><?php echo ''.$ligneC['NOM'.$ligne2['NOMRECHERCHE']]?></option>
			<?php
		}
		echo '</select></td></tr>';
	}
	
	
	//motcle
	echo "<tr><td>Champ libre :</td>";	
	echo "<td><input type='text' value='' name='champlibre' size='40'  /> <INPUT TYPE='radio' NAME='typeChaine' VALUE='ou' CHECKED> Au moins un des mots <INPUT TYPE='radio' NAME='typeChaine' VALUE='et'> Expression exacte</td></tr>";
	//echo "<tr><td>Utilisation :</td>";	
	//echo "<td><INPUT TYPE='radio' NAME='typeUtilisation' VALUE='BO_ARTICLE_PRESSE' /> Article de presse <INPUT TYPE='radio' NAME='typeUtilisation' VALUE='BO_BRO_PLA_TOURISTIQUE' /> Brochure, plaquette tourisique <INPUT TYPE='radio' NAME='typeUtilisation' VALUE='BO_INTERNETOK' /> Internet </td></tr>";
	//if ($groupe==1)
	//{
	//	echo "<tr><td>Spcifique CDT :</td><td><INPUT TYPE='radio' NAME='typeUtilisation' VALUE='BO_EDITIONS_CDT' /> Edition CDT <INPUT TYPE='radio' NAME='typeUtilisation' VALUE='BO_SITE_CDT ' /> Site CDT <INPUT TYPE='radio' NAME='typeUtilisation' VALUE='BO_TOUTE' /> Toutes utilisations </td></tr>";
	//}
	
	
 if ($_SESSION['droitcmd'] == 1){	
	//--------------------UTILISATIONS---------------------------------------------
	$sqlutil="select * from utilisation where NIVEAU = 0";
	
	$rsutil=mysql_query($sqlutil) or die ("requte non execut");
	echo "<tr><td valign='top'>Utilisation :</td><td>";
	while ($curUtil=mysql_fetch_array($rsutil)){
	
		echo "<INPUT TYPE='radio' NAME='typeUtilisation' VALUE='".$curUtil['NOMCHAMPBO']."' /> ".$curUtil['NOMUTILISATION']."\n<br />";
	
	}
	echo "</td></tr>";
	if ($groupe==1)
	{
		$sqlutil="select * from utilisation where NIVEAU = 1";
	
		$rsutil=mysql_query($sqlutil) or die ("requte non execut");
		echo "<tr><td>Utilisations CDT :</td><td>";
		while ($curUtil=mysql_fetch_array($rsutil)){
	
			echo "<INPUT TYPE='radio' NAME='typeUtilisation' VALUE='".$curUtil['NOMCHAMPBO']."' /> ".$curUtil['NOMUTILISATION']."\n";
	
		}
	echo "<INPUT TYPE='radio' NAME='typeUtilisation' VALUE='BO_TOUTE' /> Toutes utilisations </td></tr>";
	
	
	
	}
}	
	//-----------------------------------------------------------------------------------
	echo "</table><br>";
	echo "<input type='button' onClick='javascript:verifValid();'  value='Rechercher' name='recherc'  />";
	echo "<input type='hidden'  value='' name='rechercher'  />";
	echo "</form></center>";


}
?>