I'm having a nightmarish day figuring out the problem.
I made a panel allowing people to access theirs informations with 2 level of access, one for simple users and one for managers and this is working fine.
But i'd like to control the access with the dates and send special message if the date is out of range. (If i just check the date at the end of my if statement it's working, but then i can't set the special message), but if i make any other statement then all statements are working except my last "else" that is never returning its value, and on the login page it just keeps loading without any error and without any result. (while it works for all others statements)
I'm sending $_POST information to a php page thats makes the curl requests and controls the informations before returning the resulst allowing me to login as a user or as a manager.
Here is the code for the login page :
<div id="modal-full" class="uk-modal-full" uk-modal>
<div class="uk-modal-dialog">
<button class="uk-modal-close-full uk-close-large" type="button" uk-close></button>
<div class="uk-grid-collapse uk-flex-middle" uk-grid>
<div class="xs-media uk-background-cover uk-width-1-2@s" style="background-image: url('images/14.jpg'); min-height: 100vh" ></div>
<div class="target uk-padding-large uk-width-1-2@s">
<h1>Headline</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<div id="result"></div>
<form method="post" >
<label for="cocli">Votre code</label>
<input class="log-input" id="cocli" type="text" name="cocli" size="20">
<br />
<label for="clecli">Votre Clé d'identification</label>
<input class="log-input" id="clecli" type="text" name="clecli" size="20">
<br />
<input class="log-submit" id="log-submit" type="submit" value="Valider"><span id="submit-target"></span>
</form>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(window).resize(function() {
if (jQuery('.target').eq(0).height() > jQuery(window).height()) {
jQuery('.uk-background-cover').eq(0).css('min-height', jQuery('.target').eq(0).height())
}
})
jQuery("#log-submit").click(function(e){
e.preventDefault();
jQuery('#submit-target').html("<div id='loader-container'><img src='/images/Spinner-1s-200px.gif' alt='loader' style='margin: 0 auto;'></div>")
$cocli = jQuery("#cocli").val()
$clecli = jQuery("#clecli").val()
jQuery.post(
'../../includes/verif.php',
{
cocli : jQuery("#cocli").val(),
clecli : jQuery("#clecli").val()
},
function(data){
if(data.replace(/\s+/g, '') == "OK") {
jQuery("#result").html("<p style='color: #8ABC1F;'>Identifiants ORGANISATEUR acceptés, redirection en cours</p>")
setTimeout(function(){
jQuery('.target').eq(0).html("<div id='loader-container'><img src='/images/Spinner-1s-200px.gif' alt='loader' style='margin: 0 auto;'></div>")
}, 1000);
setTimeout(function(){
jQuery('.uk-background-cover').eq(0).addClass('uk-width-1-5@s').removeClass('uk-width-1-2@s')
jQuery('.uk-padding-large').eq(0).addClass('uk-width-4-5@s target').removeClass('uk-padding-large uk-width-1-2@s')
jQuery('.target').eq(0).load("/includes/orga-index.php?code="+$cocli+"&cle="+$clecli)
}, 2000);
}if(data.replace(/\s+/g, '') == "CLIENT") {
jQuery("#result").html("<p style='color: #8ABC1F;'>Identifiants VOYAGEUR acceptés, redirection en cours</p>")
setTimeout(function(){
jQuery('.target').eq(0).html("<div id='loader-container'><img src='/images/Spinner-1s-200px.gif' alt='loader' style='margin: 0 auto;'></div>")
}, 1000);
setTimeout(function(){
jQuery('.uk-background-cover').eq(0).addClass('uk-width-1-5@s').removeClass('uk-width-1-2@s')
jQuery('.uk-padding-large').eq(0).addClass('uk-width-4-5@s target').removeClass('uk-padding-large uk-width-1-2@s')
jQuery('.target').eq(0).load("/includes/user-index.php?code="+$cocli+"&cle="+$clecli)
}, 2000);
}if(data.replace(/\s+/g, '') == "nOK"){
jQuery("#result").html("<p style='color: #EA1409;'>identifiants incorrects, veuillez vérifier les informations saisies</p>")
jQuery('#submit-target').html("")
}if(data.replace(/\s+/g, '') == "CLIENTOUT"){
jQuery("#result").html("<p style='color: #EA1409;'>Votre voyage a commencé et l'interface voyageur n'est désormais plus disponible</p>")
jQuery('#submit-target').html("")
}if(data.replace(/\s+/g, '') == "ORGAOUT"){
jQuery("#result").html("<p style='color: #EA1409;'>Votre voyage est terminé et l'interface organisateur n'est désormais plus disponible</p>")
jQuery('#submit-target').html("")
}
},
'text'
);
});
});
</script>
</div>
</div>
</div>
And here is the verif.php called from the login page (i hided database table info & server adress on purpose to post here)
<?php
if ( isset($_POST['cocli']) && isset($_POST['clecli']) ){
$code = $_POST['cocli'];
$cle = $_POST['clecli'];
include 'db.php';
$reponse = $dbh->query('SELECT * FROM XXXX');
$donnees = $reponse->fetch();
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "9055",
CURLOPT_URL => "http://XXXX/api/authenticate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "CodeClient=" . $donnees['codedistant'] . "&CleClient=" . $donnees['cledistant'],
CURLOPT_HTTPHEADER => [
"Content-Type: application/x-www-form-urlencoded"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
$parsedresponse = json_decode($response);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
}
$curl1 = curl_init();
curl_setopt_array($curl1, [
CURLOPT_PORT => "9055",
CURLOPT_URL => "http://XXXX/api/client/getCustomerById/". $code,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer ". $parsedresponse,
"COMPTE: LOGICAR"
],
]);
$response1 = curl_exec($curl1);
$err1 = curl_error($curl1);
$parsedresponse1 = json_decode($response1, TRUE);
curl_close($curl1);
if ($err1) {
echo "cURL Error #:" . $err1;
}
$curl2 = curl_init();
curl_setopt_array($curl2, [
CURLOPT_PORT => "9055",
CURLOPT_URL => "http://XXXX/api/inscription/getInscript/" . $cle,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer ". $parsedresponse,
"COMPTE: LOGICAR"
],
]);
$response2 = curl_exec($curl2);
$err2 = curl_error($curl2);
$parsedresponse2 = json_decode($response2, TRUE);
curl_close($curl2);
if ($err1) {
echo "cURL Error #:" . $err1;
}
if (isset($parsedresponse2['INSCRIPT'][0]['INSCRIPT.FIN'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.DEBUT']) {
$initDate2 = date('d-m-y');
$initDate3 = $parsedresponse2['INSCRIPT'][0]['INSCRIPT.FIN'];
//$initDate3 = "03/01/2021";
$initDate4 = $parsedresponse2['INSCRIPT'][0]['INSCRIPT.DEBUT'];
//$initDate4 = "03/01/2021";
$date2 = DateTime::createFromFormat('d-m-y', date('d-m-y'));
$date3 = date_create(str_replace('/', '-', $initDate3));
$date4 = date_create(str_replace('/', '-', $initDate4));
$date3->modify('+1 day');
$date4->modify('+1 day');
}
if (isset($parsedresponse2['INSCRIPT'][0]['INSCRIPT.ID'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.CODVEND']) && $parsedresponse2['INSCRIPT'][0]['INSCRIPT.ID'] == $_POST['clecli'] && $parsedresponse2['INSCRIPT'][0]['INSCRIPT.CODVEND'] == $_POST['cocli'] && $date2 < $date4){
echo "CLIENT";
} elseif (isset($parsedresponse2['INSCRIPT'][0]['INSCRIPT.ID'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.CODVEND']) && $parsedresponse2['INSCRIPT'][0]['INSCRIPT.ID'] == $_POST['clecli'] && $parsedresponse2['INSCRIPT'][0]['INSCRIPT.CODVEND'] == $_POST['cocli'] && $date2 > $date4){
echo "CLIENTOUT";
} elseif (isset($parsedresponse1['LO_CLIENT'][0]['LO_CLIENT.ID'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.COCLIPAY']) && $parsedresponse1['LO_CLIENT'][0]['LO_CLIENT.ID'] == $parsedresponse2['INSCRIPT'][0]['INSCRIPT.COCLIPAY'] && $date2 < $date3){
echo "OK";
} elseif (isset($parsedresponse1['LO_CLIENT'][0]['LO_CLIENT.ID'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.COCLIPAY']) && $parsedresponse1['LO_CLIENT'][0]['LO_CLIENT.ID'] == $parsedresponse2['INSCRIPT'][0]['INSCRIPT.COCLIPAY'] && $date2 > $date3){
echo 'ORGAOUT';
} else {
echo 'nOK';
}
}
?>
So this is working :
if (isset($parsedresponse2['INSCRIPT'][0]['INSCRIPT.FIN'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.DEBUT'])){
$initDate2 = date('d-m-y');
$initDate3 = $parsedresponse2['INSCRIPT'][0]['INSCRIPT.FIN'];
$initDate4 = $parsedresponse2['INSCRIPT'][0]['INSCRIPT.DEBUT'];
//$initDate4 = "01/01/2021";
$date2 = DateTime::createFromFormat('d-m-y', date('d-m-y'));
$date3 = date_create(str_replace('/', '-', $initDate3));
$date4 = date_create(str_replace('/', '-', $initDate4));
$date4->modify('+1 day');
$date3->modify('+1 day');
}
if (isset($parsedresponse2['INSCRIPT'][0]['INSCRIPT.ID'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.CODVEND']) && $parsedresponse2['INSCRIPT'][0]['INSCRIPT.ID'] == $_POST['clecli'] && $parsedresponse2['INSCRIPT'][0]['INSCRIPT.CODVEND'] == $_POST['cocli'] && $date2 <= $date4){
echo "CLIENT";
} elseif (isset($parsedresponse1['LO_CLIENT'][0]['LO_CLIENT.ID'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.COCLIPAY']) && $parsedresponse1['LO_CLIENT'][0]['LO_CLIENT.ID'] == $parsedresponse2['INSCRIPT'][0]['INSCRIPT.COCLIPAY'] && $date2 <= $date3){
echo "OK";
} else {
echo 'nOK';
}
This is working for the 4 first statements (i can log, or if the date is out of range, i get the correct message), but then even if no statement matches, the last else is not returning it's value (if i put wrong infos or no infos the spining gif on the login page just keeps running):
if (isset($parsedresponse2['INSCRIPT'][0]['INSCRIPT.FIN'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.DEBUT']) {
$initDate2 = date('d-m-y');
$initDate3 = $parsedresponse2['INSCRIPT'][0]['INSCRIPT.FIN'];
//$initDate3 = "03/01/2021";
$initDate4 = $parsedresponse2['INSCRIPT'][0]['INSCRIPT.DEBUT'];
//$initDate4 = "03/01/2021";
$date2 = DateTime::createFromFormat('d-m-y', date('d-m-y'));
$date3 = date_create(str_replace('/', '-', $initDate3));
$date4 = date_create(str_replace('/', '-', $initDate4));
$date3->modify('+1 day');
$date4->modify('+1 day');
}
if (isset($parsedresponse2['INSCRIPT'][0]['INSCRIPT.ID'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.CODVEND']) && $parsedresponse2['INSCRIPT'][0]['INSCRIPT.ID'] == $_POST['clecli'] && $parsedresponse2['INSCRIPT'][0]['INSCRIPT.CODVEND'] == $_POST['cocli'] && $date2 < $date4){
echo "CLIENT";
} elseif (isset($parsedresponse2['INSCRIPT'][0]['INSCRIPT.ID'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.CODVEND']) && $parsedresponse2['INSCRIPT'][0]['INSCRIPT.ID'] == $_POST['clecli'] && $parsedresponse2['INSCRIPT'][0]['INSCRIPT.CODVEND'] == $_POST['cocli'] && $date2 > $date4){
echo "CLIENTOUT";
} elseif (isset($parsedresponse1['LO_CLIENT'][0]['LO_CLIENT.ID'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.COCLIPAY']) && $parsedresponse1['LO_CLIENT'][0]['LO_CLIENT.ID'] == $parsedresponse2['INSCRIPT'][0]['INSCRIPT.COCLIPAY'] && $date2 < $date3){
echo "OK";
} elseif (isset($parsedresponse1['LO_CLIENT'][0]['LO_CLIENT.ID'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.COCLIPAY']) && $parsedresponse1['LO_CLIENT'][0]['LO_CLIENT.ID'] == $parsedresponse2['INSCRIPT'][0]['INSCRIPT.COCLIPAY'] && $date2 > $date3){
echo 'ORGAOUT';
} else {
echo 'nOK';
}
I tried nested if statements, but then none of my startement works
if (isset($parsedresponse2['INSCRIPT'][0]['INSCRIPT.FIN'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.DEBUT'])){
$initDate2 = date('d-m-y');
$initDate3 = $parsedresponse2['INSCRIPT'][0]['INSCRIPT.FIN'];
$initDate4 = $parsedresponse2['INSCRIPT'][0]['INSCRIPT.DEBUT'];
//$initDate4 = "01/01/2021";
$date2 = DateTime::createFromFormat('d-m-y', date('d-m-y'));
$date3 = date_create(str_replace('/', '-', $initDate3));
$date4 = date_create(str_replace('/', '-', $initDate4));
$date4->modify('+1 day');
$date3->modify('+1 day');
}
if (isset($parsedresponse2['INSCRIPT'][0]['INSCRIPT.ID'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.CODVEND']) && $parsedresponse2['INSCRIPT'][0]['INSCRIPT.ID'] == $_POST['clecli'] && $parsedresponse2['INSCRIPT'][0]['INSCRIPT.CODVEND'] == $_POST['cocli'] && $date2 <= $date4){
echo "CLIENT";
if($Date2 > $date4) {
echo "CLIENT";
}else{
echo "CLIENTOUT;
}
} elseif (isset($parsedresponse1['LO_CLIENT'][0]['LO_CLIENT.ID'], $parsedresponse2['INSCRIPT'][0]['INSCRIPT.COCLIPAY']) && $parsedresponse1['LO_CLIENT'][0]['LO_CLIENT.ID'] == $parsedresponse2['INSCRIPT'][0]['INSCRIPT.COCLIPAY'] && $date2 $date3){
echo "OK";
if($Date2 > $date3) {
echo "OK";
}else{
echo "ORGAOUT";
}
} else {
echo 'nOK';
}
It's really driving me crazy, i can't figure out what's going on :/ So if anybody got an idea about it it would be awesome.
Thanks in advance !
JIM
Aucun commentaire:
Enregistrer un commentaire