Linux SRV-16 6.18.44-paas #1 SMP PREEMPT_DYNAMIC Thu Aug 13 10:08:12 UTC 2026 x86_64
/
srv
/
data
/
web
/
vhosts
/
www.chauffagiste-essonne.com
/
htdocs
/
functions
/
/srv/data/web/vhosts/www.chauffagiste-essonne.com/htdocs/functions/devis.php
<?php //Si le formulaire est rempli par un robot if(isset($_POST['pseudo']) && $_POST['pseudo']!="") header("Location: ".$routes['devis-success']); //Init Variables $form_is_valid = true; $form_has_errors = false; $form_is_submitted = false; $error_captcha = false; //how to use it $data = array( 'company' => array('value' => null,'status'=>null,'regex'=> _2_CHARS_REGEX_, 'label'=>'Entreprise'), 'firstname' => array('value' => null,'status'=>null,'regex'=> _2_CHARS_REGEX_, 'label'=>'Prénom'), 'lastname' => array('value' => null,'status'=>null,'regex'=> _2_CHARS_REGEX_, 'label'=>'NOM'), 'address' => array('value' => null,'status'=>null,'regex'=> _2_CHARS_REGEX_, 'label'=>'Adresse'), 'zipcode' => array('value' => null,'status'=>null,'regex'=> _ZIPCODE_REGEX_, 'label'=>'Code postal'), 'city' => array('value' => null,'status'=>null,'regex'=> _2_CHARS_REGEX_, 'label'=>'Ville','force_display'=>true), 'email' => array('value' => null,'status'=>null,'regex'=> _EMAIL_REGEX_, 'label'=>'E-mail'), 'phone' => array('value' => null,'status'=>null,'regex'=> _PHONE_REGEX_, 'label'=>'Téléphone'), 'select1' => array('value' => null,'status'=>null,'regex'=> null, 'label'=>'Type de prestation'), 'checkbox1' => array('value' => null,'status'=>null,'regex'=> null, 'label'=>'Installation','force_display'=>true), 'checkbox2' => array('value' => null,'status'=>null,'regex'=> null, 'label'=>'Maintenance','force_display'=>true), 'checkbox3' => array('value' => null,'status'=>null,'regex'=> null, 'label'=>'Dépannage','force_display'=>true), //'radio1' => array('value' => null,'status'=>null,'regex'=> _2_CHARS_REGEX_, 'label'=> array('title'=>'Radio 1','options'=>array('option1'=>'Option 1','option2'=>'Option 2'))), //'input1' => array('value' => null,'status'=>null,'regex'=> _2_CHARS_REGEX_, 'label'=>'Input 1'), //'amount1' => array('value' => null,'status'=>null,'regex'=> _AMOUNT_REGEX_, 'label'=>'Montant 1'), //'date1' => array('value' => null,'status'=>null,'regex'=> null, 'label'=>'Date 1'), 'message' => array('value' => null,'status'=>null,'regex'=> null, 'label'=>'Informations complémentaires (facultatif)'), 'file' => array('value' => null,'status'=>null,'regex'=> null, 'label'=>'Pièce jointe'), 'pseudo' => array('value' => null,'status'=>null,'regex'=> null, 'label'=>'Pseudo'), ); //Formulaire envoyé if(isset($_POST['devis'])) { $data['address']['value'] = (isset($_POST['address']))?$_POST['address']:null; //$data['amount1']['value'] = (isset($_POST['amount1']))?$_POST['amount1']:null; $data['city']['value'] = (isset($_POST['city']))?$_POST['city']:null; $data['checkbox1']['value'] = (isset($_POST['checkbox1']))?$_POST['checkbox1']:null; $data['checkbox2']['value'] = (isset($_POST['checkbox2']))?$_POST['checkbox2']:null; $data['checkbox3']['value'] = (isset($_POST['checkbox3']))?$_POST['checkbox3']:null; $data['company']['value'] = (isset($_POST['company']))?$_POST['company']:null; //$data['date1']['value'] = (isset($_POST['date1']))?$_POST['date1']:null; $data['email']['value'] = (isset($_POST['email']))?$_POST['email']:null; $data['firstname']['value'] = (isset($_POST['firstname']))?$_POST['firstname']:null; $data['file']['value'] = (isset($_FILES['file']))?$_FILES['file']:null; //$data['input1']['value'] = (isset($_POST['input1']))?$_POST['input1']:null; $data['lastname']['value'] = (isset($_POST['lastname']))?$_POST['lastname']:null; $data['message']['value'] = (isset($_POST['message']))?$_POST['message']:null; $data['phone']['value'] = (isset($_POST['phone']))?$_POST['phone']:null; $data['pseudo']['value'] = (isset($_POST['pseudo']))?$_POST['pseudo']:null; //$data['radio1']['value'] = (isset($_POST['radio1']))?$_POST['radio1']:null; $data['select1']['value'] = (isset($_POST['select1']))?$_POST['select1']:null; $data['zipcode']['value'] = (isset($_POST['zipcode']))?$_POST['zipcode']:null; $form_is_submitted = true; // reCAPTCHA v3 Validation $captchaResponse = $_POST['recaptcha_token']; $secretKey = '6LfrFvcqAAAAAN20dSgvkZNHG-_MK7uBhcFdw-E9'; // Replace with your actual secret key $verifyUrl = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$captchaResponse"; $response = file_get_contents($verifyUrl); $captchaResult = json_decode($response, true); if (!$captchaResult['success'] || $captchaResult['score'] < 0.5) { $error_captcha = true; $form_is_valid = false; $form_has_errors = true; } //Form validation rules foreach($data as $key => $field) { if (!is_null($field['regex'])){ if (validate($field['regex'],$field['value'])){$data[$key]['status'] = 'has-success';} else{$data[$key]['status'] = 'has-error';$form_is_valid = false;} } } //file check // if(is_null($data['file']['value']) || file_is_uploaded($data['file']['value'])){$data['file']['status'] = 'has-success';} // else{$data['file']['status'] = 'has-error';$form_is_valid = false;} if ($form_is_valid && !$error_captcha) { //validation rules are OK //Filling my product field foreach($data as $field => $params) { //just fill the 'demande' section of the order if(!in_array($field,array('company','firstname','lastname','address','zipcode','city','email','phone','message','file','pseudo'))) { //search for checkboxN and fill it with Oui (checked) or No (unchecked) if(substr($field, 0, 8) == 'checkbox') { $product[$params['label']] = ($params['value'])?'Oui':'Non'; } //search for radio and fill it with the checked option label elseif(substr($field, 0, 5) == 'radio'){ $product[$params['label']['title']] = $params['label']['options'][$params['value']]; } //fill all the remain fields into products else{ $product[$params['label']] = $params['value']; } } } $form_data = array( $data['firstname']['value'], $data['lastname']['value'], $data['email']['value'], $data['phone']['value'], $data['company']['value'], $data['address']['value'], $data['zipcode']['value'], $data['city']['value'], $data['message']['value'], serialize($product), $conf_id_company, ); //insert form in db include "config/database_forms.php"; $stmt = $db_forms->prepare("INSERT INTO devis_client(firstname,lastname,email,phone,company,address,zipcode,city,message,product,send_at,id_company) VALUES (?,?,?,?,?,?,?,?,?,?,NOW(),?)"); $stmt->execute($form_data); $db_forms = null;//deconnexion de la db //Send emails mailDevis($data); mailConfirmation($data); header("Location: " . $routes['devis-success']); }else{ //On affichera un message d'erreur $form_has_errors = true; } }