Page 1 sur 1

Condition prioritaire lors du submit

Posté : 01 févr. 2013, 15:38
par vatmx
Bonjour

Grosso modo ligne 292 de mon fichier, j'ai une condition qui dit d'envoyer les résultats à l'adresse email A les jours pairs et à l'adresse email B les jours impairs!
<?php session_start(); header("Content-Type: text/html; charset=UTF-8"); ?>
<?php
/*
 * Auteur : VatMx
 * 
 * Programme sous licence GPL:
 * http://www.gnu.org/licenses/gpl.html
 * 
*/
echo '
<!--Formulaire Devis eco-driving-->
';
?>
<?php
$tabFieldsetLegends[5]="Titre";
?>
<?php
// Ensemble de fonctions
function fa_phpToJs($var) {
	if (is_array($var)) {
		$res = "[";
		$array = array();
		foreach ($var as $a_var) {
			$array[] = fa_phpToJs($a_var);
		}
		return "[" . join(",", $array) . "]";
	}
	elseif (is_bool($var)) {
		return $var ? "true" : "false";
	}
	elseif (is_int($var) || is_integer($var) || is_double($var) || is_float($var)) {
		return $var;
	}
	elseif (is_string($var)) {
		return "\"" . addslashes(stripslashes($var)) . "\"";
	}
	// autres cas: objets, on ne les gère pas
	return FALSE;
}

function fa_str_post($string){
	if (isset($_POST[$string])) { $return_string = trim($_POST[$string]); } else { $return_string = ""; }
	return $return_string;
}
?>
		<script type="text/javascript">
		var tabErrorFields=new Array();
		var tabErrorFormats=new Array();
		var tabFieldsRequired=new Array();
		var tabFormatsRequired=new Array();
		</script><?php $list_langIds="5"; $tab_langIds=explode(",",$list_langIds); ?>
<?php
$tabShortNames[4]="fr";
?>
<?php if(is_array($tabShortNames)){ $lang_id=array_search($_GET['lang'],$tabShortNames)+1; }else{ $lang_id=""; }?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php echo $_GET['lang'];?>" xml:lang="<?php echo $_GET['lang'];?>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
<link rel="stylesheet" href="style/style.css" type="text/css" />
<script type="text/javascript">var langId="<?php echo $lang_id;?>"; var issetCaptcha=false;</script>
<script src="../js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="../js/jquery-ui.min.js" type="text/javascript"></script>
<script src="../js/jquery.ui.datepicker.min.js"></script>
<script type="text/javascript">
$(function(){ $(".datepicker").datepicker({changeMonth: true,changeYear: true}); });
</script>
<script type="text/javascript">function validForm(){

	/*
	 * Initialisation des variables
	 */

	var nbrErrors=0;


	/*
	 * Fonctions de vérification des formatages
	 */

	function verifNumber(myString){ // idTag 3	
		if(isNaN(myString)){ return false; }else { return true; }	
	}


	function verifEmail(myString){ // idTag 4

		var reg= /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;

		if(reg.test(myString)==true){
			return true; // adresse valide
		}
		else{
			return false; // adresse non valide
		}
	}


	function verfifUrl(myString){ // idTag 5

		var reg= /(http):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;

		if(reg.test(myString)==true){
			return true; // adresse valide
		}
		else{
			return false; // adresse non valide
		}

	}	

	function verifCaptcha(myString){ // idTag 15
		myString = jQuery.trim(myString);
		
		if(myString==''){
			return false;
		}else{
			return true;
		}
	}
	
	/*
	 * Gestion des FieldsetErrors
	 */

	function verifField(){
		
		$.each(tabFieldsRequired, function(index,n){
			var i=0;
			var type=$('#element_id'+n+'-'+i).attr("type");
			var str=$('#element_id'+n+'-'+i).val();

			if(type=="checkbox" || type=="radio"){

				var checkStr=false;
				while(typeof $('#element_id'+n+'-'+i).attr('checked')!=="undefined"){
					if($('#element_id'+n+'-'+i).attr('checked')==true){checkStr=true;}
					i++;
				}
				if(checkStr==false){
					$('#errorField_'+n).html(tabErrorFields[n][langId]).hide().fadeIn(2000).css({"padding":"2px 2px 2px 8px"});
					nbrErrors++;
				}else{
					$('#errorField_'+n).html('').css({"padding":"0px"});
				}
			}else{

				str = jQuery.trim(str);

				if(str==''){
					$('#errorField_'+n).html(tabErrorFields[n][langId]).hide().fadeIn(2000).css({"padding":"2px 2px 2px 8px"});
					nbrErrors++;
				}
				else{
					if(str!=''){					
						$('#errorField_'+n).html('').css({"padding":"0px"});
					}
				}
			}
			
			// Gestion du captcha
			var ElemClass=$('#element_id'+n+'-'+i).attr("class");
			if(ElemClass=='formallin_captcha' && !verifCaptcha(str)){
				$('td#tdCaptcha input').css({"background-color":"FFE6E6"});
				nbrErrors++;
			}else{
				$('td#tdCaptcha input').css({"background-color":"fff"});
			}
		});
	}

	/*
	 * Gestion des FormatErrors
	 */

	function verifFormat(){

		$.each(tabFormatsRequired, function(index,n){ 
			var i=0;
			
			var ElemClass=$('#element_id'+n+'-'+i).attr("class");
			var ElemValue=$('#element_id'+n+'-'+i).val();
			ElemValue = jQuery.trim(ElemValue);

			switch(ElemClass){

			case 'formallin_numeric' : if(!verifNumber(ElemValue) && ElemValue!=''){
				$('#errorFormat_'+n).html(tabErrorFormats[n][langId]).hide().fadeIn(2000).css({"padding":"2px 2px 2px 8px"});
				nbrErrors++;
			}else{ 
				$('#errorFormat_'+n).html('').css({"padding":"0px"});
			}
			break;

			case 'formallin_email' : if(!verifEmail(ElemValue) && ElemValue!=''){
				$('#errorFormat_'+n).html(tabErrorFormats[n][langId]).hide().fadeIn(2000).css({"padding":"2px 2px 2px 8px"});
				nbrErrors++;
			}else{ 
				$('#errorFormat_'+n).html('').css({"padding":"0px"});
			}
			break;

			case 'formallin_url' : if(!verfifUrl(ElemValue) && ElemValue!=''){
				$('#errorFormat_'+n).html(tabErrorFormats[n][langId]).hide().fadeIn(2000).css({"padding":"2px 2px 2px 8px"});
				nbrErrors++;
			}else{ 
				$('#errorFormat_'+n).html('').css({"padding":"0px"});
			}
			break;

//			case 'datepicker' : ;
//			break;

			}


		});
	}

	/*
	 * Execution des tests
	 */

	verifField();
	verifFormat();

	/*
	 * Evaluation finale
	 */

	if(nbrErrors==0){
		return true;
	}else{
		return false;
	}
}</script>

		<?php
		switch($lang_id){
		
			case 1 : echo '<script src="../js/datepicker_i8n/jquery.ui.datepicker-zh-CN.js"></script>';
					break;
			
			case 2 : echo '<script src="../js/datepicker_i8n/jquery.ui.datepicker-ca.js"></script>';
					break;
					
			case 3 : echo '<script src="../js/datepicker_i8n/jquery.ui.datepicker-da.js"></script>';
					break;
			
			case 4 : echo '<script src="../js/datepicker_i8n/jquery.ui.datepicker-de.js"></script>';
					break;
		
			case 5 : echo '<script src="../js/datepicker_i8n/jquery.ui.datepicker-fr.js"></script>';
					break;
			
			case 6 : echo '<script src="../js/datepicker_i8n/jquery.ui.datepicker-it.js"></script>';
					break;
		
			case 7 : echo '<script src="../js/datepicker_i8n/jquery.ui.datepicker-pt-BR.js"></script>';
					break;
			
			case 8 : echo '<script src="../js/datepicker_i8n/jquery.ui.datepicker-ru.js"></script>';
					break;
		
			case 9 : echo '<script src="../js/datepicker_i8n/jquery.ui.datepicker-es.js"></script>';
					break;
		
			case 10 : echo '<script src="../js/datepicker_i8n/jquery.ui.datepicker-en-GB.js"></script>';
					break;
		
			case 11 : echo '<script src="../js/datepicker_i8n/jquery.ui.datepicker-ro.js"></script>';
					break;
		
			case 12 : echo '<script src="../js/datepicker_i8n/jquery.ui.datepicker-pl.js"></script>';
					break;
		
			case 13 : echo '<script src="../js/datepicker_i8n/jquery.ui.datepicker-nl.js"></script>';
					break;
		}
		?>
		




</head>
<body>
<?php define("_TAB_FORMALLEX","formallin_formallex"); ?>
<?php $sessionFormallinEditor = "W74sbtAurtDHqKSHwsTQL71KinteXLdSi7kjICvY"; ?>
<?php if( isset($_POST['submit']) ){ // le formulaire a été posté
  if( date("d") % 2 == 0 ) // nous sommes un jour pair
    $email="[email protected]";
  else
    $email="[email protected]";
  // informations identiques quelque soit le jour
  $formName="Devis gratuit"; 
  $emailSubject="Informations transmises par le formulaire";
  ?>

<?php
//-------------------------------------------------------------------------------------------------------
/* version	1.3 | author : Leo West | [email protected]
 */
class Mail{
	var $sendto = array();
	var $acc = array();
	var $abcc = array();
	var $aattach = array();
	var $xheaders = array();
	var $priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
	var $charset = "utf-8"; /* us-ascii */
	var $ctencoding = "7bit";
	var $receipt = 0;

	function Mail(){
		$this->autoCheck( true );
		$this->boundary= "--" . md5( uniqid("myboundary") );
	}

	function autoCheck( $bool ){
		if( $bool )
		$this->checkAddress = true;
		else
		$this->checkAddress = false;
	}

	function Subject( $subject ){
		$this->xheaders['Subject'] = strtr( $subject, "\r\n" , "  " );
	}

	function From( $from ){
		if( ! is_string($from) ) {
			echo "Class Mail: error, From is not a string";
			exit;
		}
		$this->xheaders['From'] = $from;
	}

	function ReplyTo( $address ){
		if( ! is_string($address) )
		return false;
		$this->xheaders["Reply-To"] = $address;
	}

	function Receipt(){
		$this->receipt = 1;
	}

	function To( $to ){
		if( is_array( $to ) )
		$this->sendto= $to;
		else
		$this->sendto[] = $to;
		if( $this->checkAddress == true )
		$this->CheckAdresses( $this->sendto );
	}

	function Cc( $cc ){
		if( is_array($cc) )
		$this->acc= $cc;
		else
		$this->acc[]= $cc;
		if( $this->checkAddress == true )
		$this->CheckAdresses( $this->acc );
	}

	function Bcc( $bcc ){
		if( is_array($bcc) ) {
			$this->abcc = $bcc;
		} else {
			$this->abcc[]= $bcc;
		}
		if( $this->checkAddress == true )
		$this->CheckAdresses( $this->abcc );
	}

	function Body( $body, $charset="" ){
		$this->body = $body;
		if( $charset != "" ) {
			$this->charset = strtolower($charset);
			if( $this->charset != "utf-8" ) /* us-ascii */
			$this->ctencoding = "8bit";
		}
	}

	function Organization( $org ){
		if( trim( $org != "" )  )
		$this->xheaders['Organization'] = $org;
	}

	function Priority( $priority ){
		if( ! intval( $priority ) )
		return false;
		if( ! isset( $this->priorities[$priority-1]) )
		return false;
		$this->xheaders["X-Priority"] = $this->priorities[$priority-1];
		return true;
	}

	function Attach( $filename, $filetype = "", $disposition = "inline" ){
		if( $filetype == "" )
		$filetype = "application/x-unknown-content-type";
		$this->aattach[] = $filename;
		$this->actype[] = $filetype;
		$this->adispo[] = $disposition;
	}

	function BuildMail(){
		$this->headers = "";
		if( count($this->acc) > 0 )
		$this->xheaders['CC'] = implode( ", ", $this->acc );
		if( count($this->abcc) > 0 )
		$this->xheaders['BCC'] = implode( ", ", $this->abcc );
		if( $this->receipt ) {
			if( isset($this->xheaders["Reply-To"] ) )
			$this->xheaders["Disposition-Notification-To"] = $this->xheaders["Reply-To"];
			else
			$this->xheaders["Disposition-Notification-To"] = $this->xheaders['From'];
		}
		if( $this->charset != "" ) {
			$this->xheaders["Mime-Version"] = "1.0";
			$this->xheaders["Content-Type"] = "text/plain; charset=$this->charset";
			$this->xheaders["Content-Transfer-Encoding"] = $this->ctencoding;
		}
		$this->xheaders["X-Mailer"] = "Php/libMailv1.3";
		if( count( $this->aattach ) > 0 ) {
			$this->_build_attachement();
		} else {
			$this->fullBody = $this->body;
		}
		reset($this->xheaders);
		while( list( $hdr,$value ) = each( $this->xheaders )  ) {
			if( $hdr != "Subject" )
			$this->headers .= "$hdr: $value\n";
		}
	}

	function Send(){
		$this->BuildMail();
		$this->strTo = implode( ", ", $this->sendto );
		$res = @mail( $this->strTo, $this->xheaders['Subject'], $this->fullBody, $this->headers );
	}

	function Get(){
		$this->BuildMail();
		$mail = "To: " . $this->strTo . "\n";
		$mail .= $this->headers . "\n";
		$mail .= $this->fullBody;
		return $mail;
	}

	function ValidEmail($address){
		if( preg_match( "#.*<(.+)>#", $address, $regs ) ) {
			$address = $regs[1];
		}
		if(preg_match( "#^[^@  ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$#",$address) )
		return true;
		else
		return false;
	}

	function CheckAdresses( $aad ){
		for($i=0;$i< count( $aad); $i++ ) {
			if( ! $this->ValidEmail( $aad[$i]) ) {
				echo "Class Mail, method Mail : invalid address $aad[$i]";
				exit;
			}
		}
	}

	function _build_attachement(){
		$this->xheaders["Content-Type"] = "multipart/mixed;\n boundary=\"$this->boundary\"";
		$this->fullBody = "This is a multi-part message in MIME format.\n--$this->boundary\n";
		$this->fullBody .= "Content-Type: text/plain; charset=$this->charset\nContent-Transfer-Encoding: $this->ctencoding\n\n" . $this->body ."\n";
		$sep= chr(13) . chr(10);
		$ata= array();
		$k=0;
		for( $i=0; $i < count( $this->aattach); $i++ ) {
			$filename = $this->aattach[$i];
			$basename = basename($filename);
			$ctype = $this->actype[$i];	// content-type
			$disposition = $this->adispo[$i];
			if( ! file_exists( $filename) ) {
				echo "Class Mail, method attach : file $filename can't be found"; exit;
			}
			$subhdr= "--$this->boundary\nContent-type: $ctype;\n name=\"$basename\"\nContent-Transfer-Encoding: base64\nContent-Disposition: $disposition;\n  filename=\"$basename\"\n";
			$ata[$k++] = $subhdr;
			$linesz= filesize( $filename)+1;
			$fp= fopen( $filename, 'r' );
			$ata[$k++] = chunk_split(base64_encode(fread( $fp, $linesz)));
			fclose($fp);
		}
		$this->fullBody .= implode($sep, $ata);
	}
}
//-------------------------------------------------------------------------------------------------------
?><?php
$tabGroupeElementsLabel=unserialize(base64_decode($_POST['tabGroupeElementsLabel']));
$tabLabelText=unserialize(base64_decode($_POST['tabLabelText']));
$tabErrorFields=unserialize(base64_decode($_POST['tabErrorFields']));
$tabErrorFormats=unserialize(base64_decode($_POST['tabErrorFormats']));
$tabShortNames=unserialize(base64_decode($_POST['tabShortNames']));
$lang_id=array_search($_GET['lang'],$tabShortNames)+1;
$sys_lang_id=$_POST['sli'];

$lines='IP : '.$_SERVER['SERVER_ADDR'].'<br />'; // collecte de l'ip du visiteur
$nbrErrors=0;
$errorsText='';

foreach($tabGroupeElementsLabel as $key=>$tab){
	$tagId=$tab[0];
	$textLabel=$tabLabelText[$key][$lang_id];
	$fieldRequired=$tab[2];
	if($fieldRequired=="yes"){
		switch($tagId){
			case 1 : if(isset($_POST['element_text'][$key])){$val=trim($_POST['element_text'][$key]);} if(empty($val)){ $nbrErrors++; $errorsText.="\"$textLabel\" : ".$tabErrorFields[$key][$lang_id]."<br />";} break;
			case 2 : if(isset($_POST['element_password'][$key])){$val=trim($_POST['element_password'][$key]);} if(empty($val)){ $nbrErrors++; $errorsText.="\"$textLabel\" : ".$tabErrorFields[$key][$lang_id]."<br />";} break;
			case 3 : if(isset($_POST['element_numeric'][$key])){$val=trim($_POST['element_numeric'][$key]);} if(empty($val)){ $nbrErrors++; $errorsText.="\"$textLabel\" : ".$tabErrorFields[$key][$lang_id]."<br />";} break;
			case 4 : if(isset($_POST['element_email'][$key])){$val=trim($_POST['element_email'][$key]);} if(empty($val)){ $nbrErrors++; $errorsText.="\"$textLabel\" : ".$tabErrorFields[$key][$lang_id]."<br />";} break;
			case 5 : if(isset($_POST['element_url'][$key])){$val=trim($_POST['element_url'][$key]);} if(empty($val)){ $nbrErrors++; $errorsText.="\"$textLabel\" : ".$tabErrorFields[$key][$lang_id]."<br />";} break;
			case 6 : if(isset($_POST['element_textarea'][$key])){$val=trim($_POST['element_textarea'][$key]);} if(empty($val)){ $nbrErrors++; $errorsText.="\"$textLabel\" : ".$tabErrorFields[$key][$lang_id]."<br />";} break;
			case 7 : if(isset($_POST['element_checkbox'][$key])){$val=trim($_POST['element_checkbox'][$key][0]);} if(empty($val)){ $nbrErrors++; $errorsText.="\"$textLabel\" : ".$tabErrorFields[$key][$lang_id]."<br />";} break;
			case 8 : if(isset($_POST['element_radio'][$key])){$val=trim($_POST['element_radio'][$key]);} if(empty($val)){ $nbrErrors++; $errorsText.="\"$textLabel\" : ".$tabErrorFields[$key][$lang_id]."<br />";} break;
			case 9 : if(isset($_POST['element_select'][$key])){$val=trim($_POST['element_select'][$key]);} if(empty($val)){ $nbrErrors++; $errorsText.="\"$textLabel\" : ".$tabErrorFields[$key][$lang_id]."<br />";} break;
			case 10 : if(isset($_POST['element_datepicker'][$key])){$val=trim($_POST['element_datepicker'][$key]);} if(empty($val)){ $nbrErrors++; $errorsText.="\"$textLabel\" : ".$tabErrorFields[$key][$lang_id]."<br />";} break;
			case 11 : if(isset($_POST['element_file'][$key])){$val=trim($_POST['element_file'][$key]);} if(empty($val)){ $nbrErrors++; $errorsText.="\"$textLabel\" : ".$tabErrorFields[$key][$lang_id]."<br />";} break;
			case 15 : if(isset($_POST['element_captcha'][$key])){$val=trim($_POST['element_captcha'][$key]);} if(empty($val)){ $nbrErrors++; $errorsText.=$tabErrorFields[$key][$lang_id]."<br />";} break;
		}
	}
}


if($nbrErrors==0){

	foreach($tabGroupeElementsLabel as $key=>$tab){

		foreach($tab as $tagId=>$textLabel){
			$tagId=$tab[0];
			$textLabel=$tabLabelText[$key][$lang_id];
		}

		if($tagId==3){
			if (!is_numeric($_POST['element_numeric'][$key]) && !empty($_POST['element_numeric'][$key])){
				$nbrErrors++;
				$errorsText.='"'.$textLabel.'" : ';
				$errorsText.=$tabErrorFormats[$key][$lang_id]."<br />";
				$errorsText.="<br />";
			}
		}
		elseif($tagId==4){
			if (!preg_match("#^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#", $_POST['element_email'][$key]) && !empty($_POST['element_email'][$key])){
				$nbrErrors++;
				$errorsText.='"'.$textLabel.'" : ';
				$errorsText.=$tabErrorFormats[$key][$lang_id]."<br />";
				$errorsText.="<br />";
			}
		}
		elseif($tagId==5){
			if(strpos($_POST['element_url'][$key], 'http://') === FALSE && !empty($_POST['element_url'][$key])){
				$nbrErrors++;
				$errorsText.='"'.$textLabel.'" : ';
				$errorsText.=$tabErrorFormats[$key][$lang_id]."<br />";
				$errorsText.="<br />";
			}
		}
		elseif($tagId==10){
		}
		elseif($tagId==11){
			
			//print_r($tabExtension);
			
		}
		elseif($tagId==15){
			if( isset($_SESSION['security_code']) && ($_SESSION['security_code'] != $_POST['element_captcha'][$key])) {
				$nbrErrors++;
				$errorsText.=$tabErrorFields[$key][$lang_id]."<br />";
				$errorsText.="<br />";
			}
		}
	}

	
	if($nbrErrors==0){

		/*
		 * Récupération des Labels et des champs pour l'email envoyé au contact administratif
		 */

		foreach($tabGroupeElementsLabel as $key=>$tab){

			foreach($tab as $tagId=>$textLabel){
				$tagId=$tab[0];
				$textLabel=$tab[1];
			}

			if($tagId!=15){$lines.=$textLabel.' : ';}

			switch($tagId){
				case 1 : if(isset($_POST['element_text'][$key])){$lines.=trim($_POST['element_text'][$key]);} break;
				case 2 : if(isset($_POST['element_password'][$key])){$lines.=trim($_POST['element_password'][$key]);} break;
				case 3 : if(isset($_POST['element_numeric'][$key])){$lines.=trim($_POST['element_numeric'][$key]);} break;
				case 4 : if(isset($_POST['element_email'][$key])){$lines.=trim($_POST['element_email'][$key]);} break;
				case 5 : if(isset($_POST['element_url'][$key])){$lines.=trim($_POST['element_url'][$key]);} break;
				case 6 : if(isset($_POST['element_textarea'][$key])){$lines.=trim($_POST['element_textarea'][$key]);} break;
				case 7 : if(isset($_POST['element_checkbox'][$key]) && !empty($_POST['element_checkbox'][$key])){foreach($_POST['element_checkbox'][$key] as $key=>$value){$lines.=trim($value).", ";}} break;
				case 8 : if(isset($_POST['element_radio'][$key])){$lines.=trim($_POST['element_radio'][$key]);} break;
				case 9 : if(isset($_POST['element_select'][$key])){$lines.=trim($_POST['element_select'][$key]);} break;
				case 10 : if(isset($_POST['element_datepicker'][$key])){$lines.=trim($_POST['element_datepicker'][$key]);} break;
				case 11 : if(isset($_POST['element_file'][$key])){$lines.=trim($_POST['element_file'][$key]);} break;
			}
			
			$lines.="<br /><br />";
		}

		/*
		 * Envoi de l'email
		 */

		$lines=str_replace("<br />","\n",$lines);
		
		$em=explode(";",$email);
		
		foreach($em as $e){ // boucle pour transmettre la soumission du formulaire à tous les destinataires concernés
			
			// construction de l'email
			$subject=$emailSubject.' ['.$formName.']';
			$tab=explode("@",$e);
			$ndd=$tab[1];
			$expediteur="no-reply@$ndd";

			$m= new Mail;
			$m->From($expediteur);
			$m->To($e);
			$m->Subject($subject);
			$m->Body(stripslashes($lines));
			$m->Priority(1);
	
			// envoie de l'email
			$m->Send();
		}
		
		include_once("../../connectors/formallin_connector_bddAcces.php"); /* FORMALLIN */
		
		// connexion
		global $db;
		include("../../db.php");
		$db=new DB;
		$db->_connectar();

		include_once('../classes/FA_Sql.class.php');
		include_once('../classes/FA_Formallex.class.php');
		
		function fa_inDB($string){
			return mysql_real_escape_string(stripslashes($string));
		}
		
		$formallex = new FA_Formallex();
		$formallex->setSessionFormallinEditor($sessionFormallinEditor);
		$formallex->setContent(stripslashes($lines));
		$formallex->createFormallex();
		
		$db->_desconnectar();		
	}
}
?><?php } ?><?php if(in_array($lang_id,$tab_langIds)){ ?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>?lang=<?php echo $_GET['lang'];?>" onSubmit="return validForm();">
<fieldset>
<legend><?php echo $tabFieldsetLegends[$lang_id];?></legend>
<table>
<?php
$tabLabelText[0][5]="Code postal";
?>
<script type="text/javascript">
tabErrorFormats[0] = new Array();
tabErrorFormats[0][5]="le format n'est pas respecté";
tabFormatsRequired.push(0);
</script>
<tr>
<td><label for="element_id0-0"><?php echo $tabLabelText[0][$lang_id];?></label></td>
<td><input type="text" size="20" maxlength="45" class="formallin_numeric" name="element_numeric[0]" id="element_id0-0"/></td>
</tr>
<tr><td></td><td><div class="errorMessage" id="error_0"><div class="errorField" id="errorField_0"></div><div class="errorFormat" id="errorFormat_0"></div></div></td></tr><tr><td></td><td></td></tr>
<input type="hidden" name="tabGroupeElementsLabel" value="YToxOntpOjA7YTozOntpOjA7czoxOiIzIjtpOjE7czoxMToiQ29kZSBwb3N0YWwiO2k6MjtzOjI6Im5vIjt9fQ==" />
<input type="hidden" name="tabErrorFields" value="czowOiIiOw==" />
<input type="hidden" name="tabErrorFormats" value="YToxOntpOjA7YToxOntpOjU7czoyOToibGUgZm9ybWF0IG4nZXN0IHBhcyByZXNwZWN0w6kiO319" />
<input type="hidden" name="tabShortNames" value="<?php echo base64_encode(serialize($tabShortNames));?>" />
<input type="hidden" name="tabLabelText" value="<?php echo base64_encode(serialize($tabLabelText));?>" />
<input type="hidden" name="sli" value="5" />
<tr><td>&nbsp;</td><td><?php if(isset($_POST['submit']) && $nbrErrors>0){ echo '<div class="submitError"><br />'.$errorsText.'<br /></div>'; }?></td></tr>
<?php
$tabAttributesValues_1['value'][5]="valider";
?>
<tr><td><input id="element_id1-0" name="submit" type="submit" class="formallin_submit"  value="<?php echo $tabAttributesValues_1['value'][$lang_id];?>"  /> - 
<?php
$tabAttributesValues_2['value'][5]="effacer";
?>
<input id="element_id2-0" name="reset" type="reset" class="formallin_reset"  value="<?php echo $tabAttributesValues_2['value'][$lang_id];?>"  /></td></tr>
</table>
</fieldset>
</form>
<?php
if(isset($_POST['submit']) && $nbrErrors==0){
$lang = $_GET['lang'];
// si le message a bien été transmis
$tabLangSuccess['fr'] = "Les informations que vous avez saisies ont bien été transmises. Nous vous en remercions."; // France


// si le message n'a pu être transmis
$tabLangFailure['fr'] = "Les informations que vous avez saisies n'ont pu être transmises, veuillez réessayer ultérieurement."; // France

$messageText = $tabLangSuccess[$lang];

$successMessage=<<<msn
<script type="text/javascript">
var SUCCESS_MESSAGE="$messageText";
</script>
msn;
echo $successMessage;
?>
<script type="text/javascript">
$(document).ready(function(){

	var bgColor = $('fieldset').css('backgroundColor');
	
	// effet lumineux et confirmation de soumission du formulaire
	$('fieldset').animate({backgroundColor:"#9ee19a", opacity:0},500)
	.animate({backgroundColor:bgColor,opacity:1},500 )
	.animate({opacity:0},500 )
	.queue(function(){
		$('fieldset').html('<div id="success">'+SUCCESS_MESSAGE+'</div>').css({opacity:1});
		$('#success').hide().fadeIn('slow');
	})
});
</script>
<?php
};
?>
<?php } ?>
</body>
</html>

J'ai besoin d'ajouter en première condition (prioritaire) que le formulaire saisi avec les 2 premiers chiffres des départements suivant :
93 / 95 / 60/ 62 / 80 / 59 / 02 / 27 / 28 / 76 / 14 / 50
Soit envoyé sur l'adresse email A systématiquement et pour tous les autres départements, le formulaire soit envoyé avec la condition actuelle des jours pairs et impairs.
Est-ce que c'est possible? Si oui pouvez-vous m'aider svp.
Je suis à l'aise en xhtlm css mais pas trop en php.
Merci beaucoup

Bien amicalement
VatMx

Re: Condition prioritaire lors du submit

Posté : 01 févr. 2013, 15:44
par Mazarini
If "condition/département"  {
  $email = "emaila";
} else {
   if "jour pair" {
       $email = "emailpair";
   } else {
       $email = "emailimpair";
   }
}

Re: Condition prioritaire lors du submit

Posté : 01 févr. 2013, 16:15
par vatmx
Bonjour mazarini

Et merci pour le code
Comme je l'ai dis, je suis plus que novice en php.
Pouvez-vous m'aider d'avantage car seul, c'est impossible pour moi.
  if ( element_id0-0("93;95;60;62;80;59;02;27;28;76;14;50") )  {
  $email = "[email protected]";
} else {
   if ( date("d") % 2 == 0 ) {
       $email = "[email protected]";
   } else {
       $email = "[email protected]";
   }
}
C'est certainement pas bon!
En plus le code postal à 5 chiffres et il faut uniquement faire la condition sur les 2 premiers.

Bien amicalement
VatMx

Re: Condition prioritaire lors du submit

Posté : 01 févr. 2013, 16:31
par Mazarini
$dep['50'] = '';
...
$dep['95'] = '';
$depart = substr($codepostal,0,2);  // 0 ou 1 à vérifier
if (isset($dep[$depart]) {
...
ou
$depart = substr($codepostal,0,2);  // 0 ou 1 à vérifier
if (strpos('50;....;95',$depart) !== false) {
...

Re: Condition prioritaire lors du submit

Posté : 01 févr. 2013, 17:16
par vatmx
Merci Mazarini

En compilant le tout avec mon fichier.php
j'obtient ceci
<?php define("_TAB_FORMALLEX","formallin_formallex"); ?>
<?php $sessionFormallinEditor = "9GieGfkwwP15H6GIJsI4yNBhxW0AsfnQDnNstPE7"; ?>
<?php if( isset($_POST['submit']) ){ // le formulaire a été posté
$depart = substr($tabLabelText[0],0,2);  // 0 ou 1 à vérifier
  if (strpos('93;95;60;62;80;59;02;27;28;76;14;50',$depart) !== false) {
    $email = "[email protected]";
} else {
  if( date("d") % 2 == 0 ) 
    $email="[email protected]";// nous sommes un jour pair
  else
    $email="[email protected]";// nous sommes un jour impair
    $formName="Devis gratuit"; 
    $emailSubject="Informations transmises par le formulaire";
   }
  ?>

<?php
J'ai fait un test mais la condition pour l'adresseA du formulaire fonctionne pas!
Allors j'ai essayé la valeur 1 pour $depart = substr conne ceci
<?php define("_TAB_FORMALLEX","formallin_formallex"); ?>
<?php $sessionFormallinEditor = "9GieGfkwwP15H6GIJsI4yNBhxW0AsfnQDnNstPE7"; ?>
<?php if( isset($_POST['submit']) ){ // le formulaire a été posté
$depart = substr($tabLabelText[0],1,2);  // 0 ou 1 à vérifier
  if (strpos('93;95;60;62;80;59;02;27;28;76;14;50',$depart) !== false) {
    $email = "[email protected]";
} else {
  if( date("d") % 2 == 0 ) 
    $email="[email protected]";// nous sommes un jour pair
  else
    $email="[email protected]";// nous sommes un jour impair
    $formName="Devis gratuit"; 
    $emailSubject="Informations transmises par le formulaire";
   }
  ?>

<?php
Mais toujours pas bon, j'ai fait une erreur?

Bien amicalement
VatMx

Re: Condition prioritaire lors du submit

Posté : 02 févr. 2013, 13:53
par vatmx
Bonjour

J'ai testé aussi la solution N°1 comme ceci
<?php if( isset($_POST['submit']) ){ // le formulaire a été posté
$dep['93'] = '';
$dep['95'] = '';
$dep['60'] = '';
$dep['62'] = '';
$dep['80'] = '';
$dep['59'] = '';
$dep['02'] = '';
$dep['27'] = '';
$dep['28'] = '';
$dep['76'] = '';
$dep['14'] = '';
$dep['50'] = '';
$depart = substr($tabLabelText[0],0,2);  // 0 ou 1 à vérifier
if (isset($dep[$depart]) ){
  $email = "[email protected]";
  } else {
  if( date("d") % 2 == 0 ) // nous sommes un jour pair
    $email="[email protected]";
  else
    $email="[email protected]";}
  // informations identiques quelque soit le jour
  $formName="Devis TEST"; 
  $emailSubject="Informations transmises par le formulaire";
  ?>
en changeant également :priere:
$depart = substr($tabLabelText[0],0,2); // 0 ou 1 à vérifier
pour
$depart = substr($tabLabelText[0],1,2); // 0 ou 1 à vérifier
et même au cas ou!
$depart = substr($tabLabelText[0],0,1); // 0 ou 1 à vérifier
Mais bon pas de chance :cry: .

Je suis méga novice en PHP donc c'est plutôt du piffff!
Aidez-moi

Bien amicalement
VatMx

Re: Condition prioritaire lors du submit

Posté : 04 févr. 2013, 15:53
par vatmx
Un petit coup de pouce SVP

bien amicalement

Re: Condition prioritaire lors du submit

Posté : 05 févr. 2013, 18:24
par vatmx
Bonsoir
J'en suis là:
<?php if( isset($_POST['submit']) ){ // le formulaire a été posté
$tab_cp=array(93,95,60,62,80,59,02,27,28,76,14,50); // Tableaux des codes postaux
$select_email='0';
  
if(isset($_POST['$tabLabelText[0]']))
{
  $cp=$_POST['$tabLabelText[0]'];
  $int_cp = intval(substr($cp,0,2)); //Troncature du code postal pour ne garder que les 2 premiers caracteres et transforme en entier
  
    if (in_array($int_cp,$tab_cp)){
  $select_email='1'; // Si code postal est dans la liste on choisi cet email
        }
   }
  
if($select_email == '1'){
  $email="[email protected]";// code postal dans la liste
  
}else{
    if( date("d") % 2 == 0 ) // nous sommes un jour pair
  $email="[email protected]";
else
  $email="[email protected]";// nous sommes un jour impair
}
  $formName="Devis campagne N°1";
  $emailSubject="Informations transmises par le formulaire";
  
?>
 
<?php
Mais j'ai fait un test avec un departement 95 qui figure dans la liste et un autre 78 qui lui n'y figure pas, les 2 arrivent dans [email protected]

donc cela ne fonctionne pas.

Merci d'avance

Re: Condition prioritaire lors du submit

Posté : 05 févr. 2013, 18:33
par sam12
Pour debugger, tu pourrais afficher $_POST['$tabLabelText[0]'] et $int_cp. Voir si déjà tu récupères le bon format.

Re: Condition prioritaire lors du submit

Posté : 07 févr. 2013, 11:21
par vatmx
Bonjour

Je transmet la solution ici:
<?php if (isset($_POST['submit'])) { // le formulaire a été posté
$tab_cp=array(93, 95, 60, 62 , 80 , 59 , 02 ,27 , 28 , 76 ,  14 , 50); // Tableaux des codes postaux
$select_email='0';
 $cp=$_POST['element_numeric'][0] ; // Le champs où l'utilisateur entre son code postal
echo "cp=".$cp;  
  $int_cp = intval(substr($cp,0,2)); /*Troncature du code postal pour ne garder que les 2 premiers caracteres et transforme en entier*/
 
if(!empty($cp)) 
{
  if (in_array($int_cp,$tab_cp)){
  $select_email='1'; // Si code postal est dans la liste on choisi cet email
    	}
   }
 
if($select_email == '1'){
  $email="[email protected]";// code postal dans la liste
 
}else{
	if( date("d") % 2 == 0 ) // nous sommes un jour pair
  $email="[email protected]";
else
  $email="[email protected]";// nous sommes un jour impair
}
  $formName="Test N°1";// en sortant du else le message et valable pour les 2 conditions
  $emailSubject="Informations transmises par le formulaire";
?>
Bien amicalement
VatMx