<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php

ini_set("log_errors", 1);
ini_set('error_reporting', E_ALL);

define("MYSQLSERVER","127.0.0.1");
define("MYSQLLOGIN","webbike");
define("MYSQLPASSWORD","honda");
define("BASE_DE_DONNEES","webbike");

print_r($_REQUEST);

if(isset($_REQUEST['actlist'])) $actlist=filter_var($_REQUEST['actlist'], FILTER_SANITIZE_STRING); else $actlist='';
if(isset($_REQUEST['NoClient'])) $NoClient=filter_var($_REQUEST['NoClient'], FILTER_SANITIZE_STRING); else $NoClient='';
if(isset($_REQUEST['Nom'])) $Nom=filter_var($_REQUEST['Nom'], FILTER_SANITIZE_STRING); else $Nom='';
if(isset($_REQUEST['Prenom'])) $Prenom=filter_var($_REQUEST['Prenom'], FILTER_SANITIZE_STRING); else $Prenom='';
if(isset($_REQUEST['email'])) $email=filter_var($_REQUEST['email'], FILTER_SANITIZE_STRING); else $email='';
if(isset($_REQUEST['NoChasis'])) $NoChasis=filter_var($_REQUEST['NoChasis'], FILTER_SANITIZE_STRING); else $NoChasis='';
if(isset($_REQUEST['Model'])) $Model=filter_var($_REQUEST['Model'], FILTER_SANITIZE_STRING); else $Model='';
if(isset($_REQUEST['Date'])) $Date=filter_var($_REQUEST['Date'], FILTER_SANITIZE_STRING); else $Date='';
if(isset($_REQUEST['Km'])) $Km=filter_var($_REQUEST['Km'], FILTER_SANITIZE_STRING); else $Km='';
if(isset($_REQUEST['LastSRvc'])) $LastSRvc=filter_var($_REQUEST['LastSRvc'], FILTER_SANITIZE_STRING); else $LastSRvc='';
if(isset($_REQUEST['NxtSrv'])) $NxtSrv=filter_var($_REQUEST['NxtSrv'], FILTER_SANITIZE_STRING); else $NxtSrv='';
if(isset($_REQUEST['Description'])) $Description=filter_var($_REQUEST['Description'], FILTER_SANITIZE_STRING); else $Description='';

require_once "functions.php";

switch ($actlist) {
    case 'courrier':
        include 'printPDF.php';
        $AlreadyAnEntry=ChckIfAlreadyAnEntry($NoChasis);
        if ($AlreadyAnEntry){
          $qry = "UPDATE service_suivis SET S_status='".$actlist."' WHERE S_ID='".$AlreadyAnEntry."'";
        }
        else $qry = "INSERT INTO `webbike`.`service_suivis` (`S_ID`, `S_Chassis`, `S_status`, `S_comment`) VALUES (NULL, '".$NoChasis."', '".$actlist."', '')";
        $result = Connection::executeRawQuery($qry) or die('Erreur SQL !<br>'.$qry.'<BR>'.Connection::getConnection()->errorInfo());
        header("Location:/default.php?Type=2&Sous_Type=14&NoVisu=0");
        break;
    case 'email':
        echo "email";
        require '../../../menu/client/promo/PHPMailer/PHPMailerAutoload.php';

        $mail = new PHPMailer;

        $mail->isSMTP();                       // Set mailer to use SMTP
        $mail->Host = 'smtp.hondageneve.com';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                // Enable SMTP authentication
        $mail->SMTPKeepAlive = true;      // le serveur ne racroche pas pour chaque email
        $mail->Username = 'service@hondageneve.com';   // SMTP username
        $mail->Password = '6EcyRpPbY7';        // SMTP password
        $mail->SMTPSecure = 'tls';             // Enable TLS encryption, `ssl` also accepted
        $mail->Port = 587;                     // TCP port to connect to

        $mail->From = 'service@hondageneve.com';
        $mail->FromName = 'service';

        $mail->addReplyTo('service@hondageneve.com', 'service');
        $mail->isHTML(true);
        $txtSubjct = "Concerne: service HONDA ".$Model;

        $mail->Subject = utf8_decode($txtSubjct);
       // $emailTST = 'genuix@genuix.org';
        $mail->addAddress( $email );

        $CLInFo = GetClientInfos($NoClient);
        
        $message = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
                      <html>
                      <head>
                        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
                      </head>
                      <body>
                          <div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">

                          '.$CLInFo['Allocution'].' '.$Nom.',<br><br><br>

                          Selon notre base de données le dernier service de votre '.$Model.' date du '.$Date.' avec '.number_format($Km, 0, '', '\'').' Kms<br><br>
                          
                          Nous nous permettons de vous écrire pour vous rappeler que le prochain service de votre véhicule est à '.number_format($NxtSrv, 0, '', '\'').' km ou 2 ans<br><br>

                          Vous avez la possibilité de prendre RDV sur notre application:<br><br>

                          <a href="https://services.hondageneve.com/">https://services.hondageneve.com/</a><br><br>
                          (une remise de Frs 25.- vous sera automatiquement accordé à la facturation de l\'intervention en prenant rendz-vous en ligne)<br><br>

                          Ou de nous appeler au:<br><br>

                          022 339 70 02 du 8h à midi et 13:45 à 18h le samedi de 9h à midi<br><br>

                          Nous vous remercions par avance de votre attention et vous prions d’agréer, '.$CLInFo['Allocution'].', nos salutations les meilleures.<br><br>

                          Centre Honda Genève<br><br>
                          Téléphone : 022 339 70 00         centre@hondageneve.com  Fax : 022 339 70 09<br><br>
                          </div>
                      </body>
                    </html>';

        error_log($email);
      
        $mail->Body = $message;
        if(!$mail->send()) {
            echo 'Message could not be sent.';
            echo 'Mailer Error: ' . $mail->ErrorInfo;
        } else {
          $AlreadyAnEntry=ChckIfAlreadyAnEntry($NoChasis);
          if ($AlreadyAnEntry){
            $qry = "UPDATE service_suivis SET S_status='".$actlist."' WHERE S_ID='".$AlreadyAnEntry."'";
          }
          else $qry = "INSERT INTO `webbike`.`service_suivis` (`S_ID`, `S_Chassis`, `S_status`, `S_comment`) VALUES (NULL, '".$NoChasis."', '".$actlist."', '')";
        }
        $result = Connection::executeRawQuery($qry) or die('Erreur SQL !<br>'.$qry.'<BR>'.Connection::getConnection()->errorInfo());error_log($qry);
        header("Location:/default.php?Type=2&Sous_Type=14&NoVisu=0");
        break;
    case 'hide':
    	$AlreadyAnEntry=ChckIfAlreadyAnEntry($NoChasis);
        if ($AlreadyAnEntry){
          $qry = "UPDATE service_suivis SET S_status='".$actlist."' WHERE S_ID='".$AlreadyAnEntry."'";
        }
        else $qry = "INSERT INTO `webbike`.`service_suivis` (`S_ID`, `S_Chassis`, `S_status`, `S_comment`) VALUES (NULL, '".$NoChasis."', '".$actlist."', '')";
      $result = Connection::executeRawQuery($qry) or die('Erreur SQL !<br>'.$qry.'<BR>'.Connection::getConnection()->errorInfo());error_log($qry);
      header("Location:/default.php?Type=2&Sous_Type=14&NoVisu=0");
    	break;
    default:
       echo "pas d'option choisie";
}

?>
