garancia-pharmaciens/httpdocs/first_connexion.php
2017-05-30 17:55:38 +02:00

418 lines
12 KiB
PHP
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*-----------------------------------------------------*/
include_once("_inc/config.php");
/*-----------------------------------------------------*/
/////////////////////////////////////////////////////////////////////////////
// ACTIONS
if(isset($_POST['action'])){
header("Content-type: application/json");
echo '{"results":{';
switch($_POST['action']){
case "checkCodeClient" :
$code_client = sqlEscape($_POST['code_client']);
$query = "SELECT * FROM `".$GLOBALS['sql_prefixe']."pharmacies` WHERE `code_client` = '".$code_client."' ";
//echo $query;
$result = mysql_query($query);
$nb = mysql_num_rows($result);
if($nb == 0){
echo '"error":"<div style=\"margin-top:-10px;\">Ce code client est invalide, pour résoudre ce problème nhésitez pas à nous contacter.</div>"';
echo "}}";
exit();
}
$row = mysql_fetch_object($result);
if($row -> password != ""){
echo '"error":"<div style=\"margin-top:-10px;\">Votre compte a déjà été créé. Veuillez vous connecter avec votre mot de passe.</div>"';
echo "}}";
exit();
}
echo '"valid":"1"';
break;
case "create" :
/*
datas.action = "create";
datas.code_client = $("input[name='code_client']").val();
datas.email = $("input[name='email']").val();
datas.newsletter = 0;
*/
$code_client = sqlEscape($_POST['code_client']);
$email = sqlEscape($_POST['email']);
$newsletter = sqlEscape($_POST['newsletter']);
$password = genPassword();
$query = "UPDATE `".$GLOBALS['sql_prefixe']."pharmacies`
SET `email` = '".$email."' ,
`newsletter` = '".$newsletter."' ,
`date` = CURRENT_TIMESTAMP ,
`password` = '".md5($password)."' ,
`password_clear` = '".$password."'
WHERE `code_client` = '".$code_client."' ;";
$result = mysql_query($query);
if(!$result){
echo '"error":"Création impossible..."';
echo "}}";
exit();
}
$query = "SELECT * FROM `".$GLOBALS['sql_prefixe']."pharmacies` WHERE `code_client` = '".$code_client."' ";
$results = mysql_query($query);
$row = mysql_fetch_object($results);
$_SESSION["gar_front_CIP"] = $row -> CIP;
$_SESSION["gar_front_password"] = $password;
//envoie de l'email !!
//replaceMailVar
$mail_sender = "info@garancia-beauty.com";
$mail_to = $email;
$objet = "Garancia - confirmation d'inscription";
$html = file_get_contents("emails/confirm_inscription.html");
//$html = replaceMailVar($html,"message",$message);
$html = replaceMailVar($html,"code_client",$code_client);
$html = replaceMailVar($html,"CIP",$row -> CIP);
$html = replaceMailVar($html,"password",$password);
$html = replaceMailVar($html,"pharmacie_name",$row -> name);
$html = replaceMailVar($html,"site_url",$GLOBALS['site_url']);
//$html = replaceMailVar($html,"site_url",$password);
$html = html_entity_decode(stripslashes($html));
$html = preg_replace('/&apos;/', "'", $html);
$headers = "";
$headers .= "From: Garancia <$mail_sender>"."\n";
$headers .= "Reply-To: $mail_sender"."\n";
$headers .= "MIME-Version: 1.0"."\n";
$headers .= "Return-Path: <$mail_sender>"."\n";
$headers .= "Content-Type:text/html; charset=\"utf-8\" "."\n";
$headers .= "Content-Transfer-Encoding: 8bit"."\n";
//$headers .= "Bcc:chasleries@gmail.com,".$mail_to."\n";
//$headers .= "Bcc:".$bcc."\n";
//$headers .= "Cc:email2@example.com"."\n";
$sendMail = @mail($mail_to, $objet, $html , $headers);
echo '"complete":"1","password":"'.$password.'","CIP":"'.$row -> CIP.'"';
break;
}
echo "}}";
exit();
}
/*-----------------------------------------------------*/
$_RUBRIQUE = "login";
include_once("_inc/assets/metas.php");
include_once("_inc/assets/top.php");
/*-----------------------------------------------------*/
/////////////////////////////////////////////////////////////////////////////
?>
<div class="page">
<div id="arianne">
<span class="current">Création de compte</span>
</div>
<div class="page_contents">
<div id="login">
<h1><span>[</span> Création de votre compte <span>]</span></h1>
<div class="creationForm">
<div class="intro">
Afin de pouvoir accéder à lespace pharmacien qui vous est dédié,<br />
merci de compléter le formulaire ci-dessous :
</div>
<div class="line">
<label>Code Client</label>
<input class="saisie" type="text" name="code_client" value="" />
<div class="error"></div>
<div class="clear"></div>
<a href="#trouver_identifiant" class="popin" rel="popin">Où trouver votre Code Client ?</a>
</div>
<div class="line">
<label>Adresse e-mail</label>
<input class="saisie" type="text" name="email" value="" />
<div class="error"></div>
<div class="clear"></div>
</div>
<div class="line">
<label>Confirmation adresse e-mail</label>
<input class="saisie" type="text" name="confirm_email" value="" />
<div class="error"></div>
<div class="clear"></div>
</div>
<div class="clear"></div>
<div class="legend">
Tous les champs sont obligatoires.<br />
Vous rencontrez des difficultés pour créer votre compte ?<br />
Contactez-nous au 0 805 02 4033 (appel non surtaxé)
</div>
<!--
<div class="optin">
<input type="checkbox" name="optin" value="1" />
<div class="optin_legend">
Nous souhaitons recevoir des informations,<br />
offres spéciales et avant-premières du Laboratoire Garancia.
</div>
<div class="clear"></div>
</div>
-->
<div class="clear"></div>
<div class="btnCreate">
CRÉEZ VOTRE COMPTE
</div>
<div class="error formError" style="float:right;width:400px;margin:0;text-align:left;"></div>
<div class="clear"></div>
<div class="legend2">
Les informations contenues dans cet espace pharmaciens sont destinées au seul usage de l'équipe officinale<br />
Elles ne peuvent être communiquées à des tiers sans l'accord préalable et écrit du Laboratoire Garancia
</div>
</div>
<div class="clear"></div>
</div>
</div>
<div class="creationConfirm">
<div>
<img src="_img/felicitations.png" alt="félicitations" />
</div>
<p>
Toute léquipe du Laboratoire Garancia vous remercie pour votre inscription.<br />
Votre mot de passe vient dêtre envoyé à ladresse email que vous avez indiquée.
</p>
<div>
<img src="_img/img01.png" alt="" />
</div>
<a href="index.php" class="btnBack">Retour à l'accueil</a>
</div>
</div>
<script type="text/javascript">
var sendingForm = false;
function checkCodeClient(){
var datas = {};
datas.action = "checkCodeClient";
datas.code_client = $("input[name='code_client']").val();
$.ajax({
url: "<?php echo $pfile; ?>",
dataType: 'json',
data: datas,
type: 'POST',
success: onDatasCheckCodeClient,
error: onDatasError
});
}
function onDatasCheckCodeClient($datas)
{
if($datas.results.valid == 1){
//ok
if(sendingForm){
//envoie du reste des données
var datas = {};
datas.action = "create";
datas.code_client = $("input[name='code_client']").val();
datas.email = $("input[name='email']").val();
datas.newsletter = 0;
/*
if( $("input[name='optin']:checked").length > 0) {
datas.newsletter = 1;
}
*/
$.ajax({
url: "<?php echo $pfile; ?>",
dataType: 'json',
data: datas,
type: 'POST',
success: onDatasCreate,
error: onDatasError
});
}
}else if($datas.results.error){
$("input[name='code_client']").parent().children(".error").html($datas.results.error);
if(sendingForm){
//réaffichage du formulaire
sendingForm = false;
TweenLite.to($(".creationForm"),0.1,{opacity:1});
}
}else{
alert("Erreur inconnue...");
if(sendingForm){
//réaffichage du formulaire
sendingForm = false;
TweenLite.to($(".creationForm"),0.1,{opacity:1});
}
}
}
function onDatasCreate($datas)
{
if($datas.results.complete == 1){
//ok
debug("CIP : " + $datas.results.CIP);
debug("password : " + $datas.results.password);
$(".creationForm").slideUp(300);
$(".creationConfirm").slideDown(300);
}else if($datas.results.error){
$(".formError").html($datas.results.error);
if(sendingForm){
//réaffichage du formulaire
sendingForm = false;
TweenLite.to($(".creationForm"),0.1,{opacity:1});
}
}else{
alert("Erreur inconnue...");
}
}
function onDatasError(jqXHR, textStatus, errorThrown)
{
alert("error : " + textStatus);
}
$("input").focus(function(e) {
$(this).parent().children(".error").html("");
});
$("input[name='code_client']").blur(function(e) {
if($("input[name='code_client']").val() != ""){
sendingForm = false;
checkCodeClient();
}
});
$("input[name='email']").blur(function(e) {
var email = $("input[name='email']").val();
if(!isMail(email)){
$("input[name='email']").parent().children(".error").html("Format email incorrect.");
}
});
$("input[name='confirm_email']").blur(function(e) {
var email = $("input[name='email']").val();
var confirm_email = $("input[name='confirm_email']").val();
if(email != confirm_email && confirm_email != ""){
$("input[name='confirm_email']").parent().children(".error").html("Les adresses e-mail ne concordent pas.");
}
});
function sendForm(){
if(!sendingForm){
sendingForm = true;
var error = false;
TweenLite.to($(".creationForm"),0.1,{opacity:0.3});
var code_client = $("input[name='code_client']").val();
var email = $("input[name='email']").val();
var confirm_email = $("input[name='confirm_email']").val();
if(code_client == ""){
error = true;
$("input[name='code_client']").parent().children(".error").html("Veuillez renseigner votre n°client");
}
if(!isMail(email)){
error = true;
$("input[name='email']").parent().children(".error").html("Format email incorrect.");
}
if(!isMail(confirm_email)){
error = true;
$("input[name='confirm_email']").parent().children(".error").html("Format email incorrect.");
}
if(email != confirm_email){
error = true;
$("input[name='confirm_email']").parent().children(".error").html("Les adresses e-mail ne concordent pas.");
}
if(error){
sendingForm = false;
TweenLite.to($(".creationForm"),0.1,{opacity:1});
}else{
checkCodeClient();
}
}
}
$(".btnCreate").click(sendForm);
</script>
<?php
/*-----------------------------------------------------*/
include_once("_inc/assets/footer.php");
/*-----------------------------------------------------*/
?>