<?php
if (isset($_POST["req"]) && $_POST["req"]=="save") {
	include("../master.php");
	$tmp=explode("-",$_POST["id_all"]);
	foreach($tmp as $id){
		if ($id!="") mysql_query("UPDATE contrats SET prime_paye=NOW() WHERE id='".$id."'");
		}
	echo '<center>Les informations ont été enregistrées !</center>';
	}
/*
if(isset($_POST["req"]) && $_POST["req"]=="print"){
		echo '<html>
		<head>
		<style>
		table, body, div, span {
		font-family:  Eras Light ITC;
			font-size:14px;
			color:black;
			line-height:16px;
			text-align:justify;
			}
		</style>
		</head>
		<body>
		';
		$tmp=explode("-",$_POST["id_all"]);
		$sql_more="0";
		foreach($tmp as $id){
			if ($id!="") $sql_more.=",".$id;
			}
		$result_all=mysql_query("SELECT id_apporteur, id_client, prime FROM contrats WHERE id IN(".$sql_more.")", $link);
		$echo_me="<table>";
		if (mysql_num_rows($result_all)==0) echo '<center><br /><br />Aucune commission sélectionnée !</center>';
		while ($row_all=mysql_fetch_array($result_all)){
			$echo_me.='<tr><td>'.html(client_nom($row_all["id_client"])).'</td>';
			$echo_me.='<td>'.client_nom($row_all["prime"]).'€</td></tr>';
			$id_apporteur=$row_all["id_apporteur"];
			}
		$echo_me.="</table>";
			
		$result=mysql_query("SELECT  civilite, nom, prenom, adresse1, adresse2, adresse3, code_postal, ville FROM utlisateurs WHERE id='".$id_apporteur."'", $link);
		while ($row=mysql_fetch_array($result)){
			if ($row["civilite"]=="") $row["civilite"]=3;
			$titre=$CLIENTS["civilite"][$row["civilite"]];
			$nom=$row["nom"];
			$prenom=$row["prenom"];
			$adresse1=$row["adresse1"];
			$adresse2=$row["adresse2"];
			$adresse3=$row["adresse3"];
			$code_postal=$row["code_postal"];
			$ville=$row["ville"];
			}	
						
					
		if (!$first) echo '<div style="page-break-before: always;">';
		include("../courriers/courrier_modele.php");
		echo '<div style="width:550px; text-align:justify; margin-left:45px;"><br /><br />';
		if ($idr=="" || $idr=="0") include("../courriers/".$courrier.".php");
		echo '</div>';
				
		
		echo '
			</div>
		<script>					
		function print_me(){
			this.focus();
			window.print();
			}
		</script>
		</body></html>
		';
		}
*/
if (!isset($_GET["req"])) {?>

<html>
<head>
<title>Impression de courrier</title>
<link rel="stylesheet" href="../style/axa.css">
</head>

 <frameset rows="20%, 80%">
      <frame id="print_top" name="print_top" src="print_apporteur.php?req=top&id_all=<?php echo $_GET["id_all"];?>">
      <frame id="print_print" name="print_print" src="print_apporteur.php?req=print&id_all=<?php echo $_GET["id_all"];?>&total=<?php echo $_GET["total"];?>">
  </frameset>
</html><?php }
else {
	include("../master.php");

	
	if ($_GET["req"]!="print") 
		echo '<html>
			<head>
			<link rel="stylesheet" href="../style/axa.css">
			</head>
			<body>
			';
			
	if($_GET["req"]=="top"){
		
	
			echo '
			<center>
			<form name="save_me" method="post" action="print_apporteur.php" target="iframe_save">
			<input type="hidden" name="req" value="save">
			<input type="hidden" name="id_all" id="id_all" value="'.$_GET["id_all"].'">
			
			
			<iframe id="iframe_save" name="iframe_save" src="" scrolling="no" frameborder="0" width="500" height="30"></iframe><br />
			<input type="button" id="my_button" value="Imprimer" onclick="parent.print_print.print_me(); document.getElementById(\'save_me\').submit();">
			</form>
			</center>
			';
			}

	if($_GET["req"]=="print"){
		echo '<html>
		<head>
		<style>
		table, body, div, span {
		font-family:  Eras Light ITC;
			font-size:14px;
			color:black;
			line-height:16px;
			text-align:justify;
			}
		</style>
		</head>
		<body>
		';
		$tmp=explode("-",$_GET["id_all"]);
		$sql_more="0";
		foreach($tmp as $id){
			if ($id!="") $sql_more.=",".$id;
			}
		$result_all=mysql_query("SELECT id_apporteur, id_client, prime, id_type FROM contrats WHERE id IN(".$sql_more.")", $link);
		
		$echo_me="<table cellpadding='0' cellspacing='0' border='0'><tr><td bgcolor='black'>
		<table cellpadding='4' cellspacing='1' border='0'><tr bgcolor='white'><td>Nom du souscripteur</td><td>Type de contrat</td><td>Prime</td></tr>";
		if (mysql_num_rows($result_all)==0) {
			echo '<center><br /><br />Aucune commission sélectionnée !</center></body></html>';
			exit();
			}
		while ($row_all=mysql_fetch_array($result_all)){
			$echo_me.='<tr bgcolor="white"><td>'.html(client_nom($row_all["id_client"])).'</td>';
			$echo_me.='<td>'.contrat_type_nom($row_all["id_type"]).'</td>';
			$echo_me.='<td>'.$row_all["prime"].'€</td></tr>';
			$id_apporteur=$row_all["id_apporteur"];
			}
		$echo_me.="</table></td></tr></table>";
			
		$result=mysql_query("SELECT  nom, prenom, adresse1, adresse2, adresse3, code_postal, ville FROM utilisateurs WHERE id='".$id_apporteur."'", $link);
		echo mysql_error();
		while ($row=mysql_fetch_array($result)){
			$nom=$row["nom"];
			$prenom=$row["prenom"];
			$adresse1=$row["adresse1"];
			$adresse2=$row["adresse2"];
			$adresse3=$row["adresse3"];
			$code_postal=$row["code_postal"];
			$ville=$row["ville"];
			}
		$total=$_GET["total"];
		$titre="Monsieur";
		$date=date("d/m/Y");
		$tableau=$echo_me;
						
					

		
		include("../courriers/courrier_apporteur.php");
		
				
		
		echo '
		
		<script>					
		function print_me(){
			this.focus();
			window.print();
			}
		</script>
		';
		}
	echo '
		</body>
		</html>';
	}

?>