Skip to content

Instantly share code, notes, and snippets.

@AladinDridi
Created February 12, 2018 15:31
Show Gist options
  • Save AladinDridi/257b024c178a006d2b34f320aafe7b12 to your computer and use it in GitHub Desktop.
Save AladinDridi/257b024c178a006d2b34f320aafe7b12 to your computer and use it in GitHub Desktop.
<?php
if(!is_user_logged_in()){
wp_redirect('https://www.kademia.tn/wp-login.php');
exit;
}
$msg="";
$url= bp_learndash_adminbar_nav_link(bp_learndash_profile_courses_slug());
$user_id = get_current_user_id();
if($_POST){
if ((trim($_POST['question1'])=="9789938210132")&&(trim($_POST['question2'])=="171")&&($_POST['choices']=="valeur1")){
$level = pmpro_getLevel(104);
if(!empty($level->expiration_number))
{
$custom_level = array(
'user_id' => $user_id,
'membership_id' => 104,
'code_id' => '',
'initial_payment' => $level->initial_payment,
'billing_amount' => $level->billing_amount,
'cycle_number' => $level->cycle_number,
'cycle_period' => $level->cycle_period,
'billing_limit' => $level->billing_limit,
'trial_amount' => $level->trial_amount,
'trial_limit' => $level->trial_limit,
'startdate' => "'" . current_time('mysql') . "'",
'enddate' => date("Y-m-d", strtotime("+" . $level->expiration_number . " " . $level->expiration_period)),
);
pmpro_changeMembershipLevel($custom_level, get_current_user_id());
return wp_redirect($url);
}
else {
pmpro_changeMembershipLevel($level, get_current_user_id());
return wp_redirect($url);
}
}
else if ((trim($_POST['question1'])=="9789938210132")&&(trim($_POST['question2'])=="171")&&($_POST['choices2']=="valeur2")){
$level = pmpro_getLevel(104);
if(!empty($level->expiration_number))
{
$custom_level = array(
'user_id' => $user_id,
'membership_id' => 104,
'code_id' => '',
'initial_payment' => $level->initial_payment,
'billing_amount' => $level->billing_amount,
'cycle_number' => $level->cycle_number,
'cycle_period' => $level->cycle_period,
'billing_limit' => $level->billing_limit,
'trial_amount' => $level->trial_amount,
'trial_limit' => $level->trial_limit,
'startdate' => "'" . current_time('mysql') . "'",
'enddate' => date("Y-m-d", strtotime("+" . $level->expiration_number . " " . $level->expiration_period)),
);
pmpro_changeMembershipLevel($custom_level, get_current_user_id());
return wp_redirect($url);
}
else {
pmpro_changeMembershipLevel($level, get_current_user_id());
return wp_redirect($url);
}
}
else if ((trim($_POST['question1'])=="9789938210132")&&(trim($_POST['question2'])=="171")&&($_POST['choices3']=="valeur3")){
$level = pmpro_getLevel(104);
if(!empty($level->expiration_number))
{
$custom_level = array(
'user_id' => $user_id,
'membership_id' => 104,
'code_id' => '',
'initial_payment' => $level->initial_payment,
'billing_amount' => $level->billing_amount,
'cycle_number' => $level->cycle_number,
'cycle_period' => $level->cycle_period,
'billing_limit' => $level->billing_limit,
'trial_amount' => $level->trial_amount,
'trial_limit' => $level->trial_limit,
'startdate' => "'" . current_time('mysql') . "'",
'enddate' => date("Y-m-d", strtotime("+" . $level->expiration_number . " " . $level->expiration_period)),
);
pmpro_changeMembershipLevel($custom_level, get_current_user_id());
return wp_redirect($url);
}
else {
pmpro_changeMembershipLevel($level, get_current_user_id());
return wp_redirect($url);
}
}
else{
$msg="vérifiez encore ..!";
}
}
?>
<?php get_header(); ?>
<script>
var textarray = [
"Question 1",
"Question 2",
"Question 3"
// pas virgule aprés dernier champs du tableau //
];
function RndText() {
var rannum= Math.floor(Math.random()*textarray.length);
if(textarray[rannum]=="Question 1"){
document.getElementById('select1').style.display="initial";
document.getElementById('select2').style.display="none";
document.getElementById('select3').style.display="none";
} else if(textarray[rannum]=="Question 2"){
document.getElementById('select1').style.display="none";
document.getElementById('select2').style.display="initial";
document.getElementById('select3').style.display="none";
}else if (textarray[rannum]="Question 3"){
document.getElementById('select1').style.display="none";
document.getElementById('select2').style.display="none";
document.getElementById('select3').style.display="initial"; }
}
window.onload = function() { RndText();}
</script>
<style>
.formpara{
margin-top:100px;
}
label , input,button,.choixmultiple,.titre3{
margin-left: 40px;
display:block;
}
label[for="choices"],label[for="choices2"],label[for="choices3"]{
margin-left:0px;
}
select{
width: 200px;
}
.titre3{
font-family: 'Domine', serif,"verdana",sans-serif,cursive,monospace;
}
input[type="text"],button[type="submit"]{
width:auto;
height: auto;
}
button[type="submit"]{
margin-top: 40px;
background-color: cadetblue;
}
.formpara{
display: block;
}
@media (max-width:800px){
label , input,button,.choixmultiple,.titre3{
margin-left: auto;
display:block;
}
label[for="choices"],label[for="choices2"],label[for="choices3"]{
margin-left:auto;
}
}
</style>
<link href="https://fonts.googleapis.com/css?family=Domine" rel="stylesheet">
<div class="formpara">
<meta charset="utf-8"/>
<h2>Répondez aux questions pour activer votre abonnement ( livre Mathématiques-Anglais-1ère année)</h2>
<br/>
<form method="post">
<meta charset="utf-8"/>
<label for="question1">Veuillez taper le code secret indiqué à la page de présentation du livre :</label>
<input type="text" required name="question1"/>
<br/>
<label for="question2">Quel est le nombre de pages de ce livre ?</label>
<input type="text" required name="question2"/>
<br/>
<div id="select1" class="choixmultiple">
<label for="choices">Quel est le dernier mot sur la page N°52 ?</label>
<SELECT required name="choices">
<option value="valeur1">Times</option>
<option value="valeur2" selected>Days</option>
<option value="valeur3">Night</option>
</SELECT>
</div>
<div id="select2" class="choixmultiple">
<label for="choices2">Quel est le dernier mot sur la page N°60 ?</label>
<SELECT required name="choices2">
<option value="valeur1">Skills</option>
<option value="valeur2">Drawer</option>
<option value="valeur3">Imaginations</option>
</SELECT>
</div>
<div id="select3" class="choixmultiple">
<label for="choices3">Quel est le dernier mot sur la page N°25 ?</label>
<SELECT required name="choices3">
<option value="valeur1">Justifié</option>
<option value="valeur2">Aligné</option>
<option value="valeur3">Associés</option>
</SELECT>
</div>
<br/>
<button id="button" type="submit" class="btn btn-default">Valider mon abonnement</button>
</form>
<p><?php echo $msg; ?></p>
</div>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment