File: /var/www/selfanalyse/wp-content/plugins/psychometrics/psy_profile_test.php
<?php
if (is_user_logged_in()) {
?>
<section class="dashboard-section">
<div class="container">
<div class="row dashboard-page-section-box">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="dashboard-bg-img"></div>
</div>
<div class="detail-section">
<div class="col-md-3 col-sm-3 col-xs-12">
<!-----Include sidebar menus ----->
<?php include 'psy_profile_sidebar.php'; ?>
</div>
<div class="col-md-9 col-sm-9 col-xs-12">
<!-----Include menus of profile header ----->
<?php include 'psy_profile_menus.php'; ?>
<?php
//get plans of user
$getPlans = $wpdb->get_results("SELECT ps.plan_id as plans,p.plan_name,p.plan_image,p.plan_short_desc,ps.purchase_date FROM $PSY_SUBSCRIPTION as ps LEFT JOIN $PSY_PLANS as p on p.plan_id=ps.plan_id where ps.user_id='$user_id' and ps.status='1' group by cast(ps.purchase_date as date),ps.plan_id order by ps.purchase_date desc");
$curDate = date('Y-m-d H:i:s');
if (sizeof($getPlans) > 0) {
foreach ($getPlans as $pl) {
$pDate = date('Y-m-d', strtotime($pl->purchase_date));
//get exams by user plans wise
$getPlaExams = $wpdb->get_results("SELECT ps.subscription_id,ps.test_type,ps.purchase_date,e.category_name,ps.plan_id,ps.active_date,ps.active_status FROM $PSY_SUBSCRIPTION as ps LEFT JOIN $PSY_EXAMS as e on e.exam_category_id=ps.exam_id where ps.user_id='$user_id' and ps.plan_id='$pl->plans' and date(ps.purchase_date)='$pDate' and ps.status='1'");
?>
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="my-test-box-details">
<h4><?php echo $pl->plan_name; ?></h4>
<p><?php echo $pl->plan_short_desc ?></p>
<ul class="test-box-details-ul">
<?php foreach ($getPlaExams as $pe) {
$pStatus = $pe->active_status;
//page url by test type
$test_type = $pe->test_type;
if ($test_type == 'APT') {
$testLink = 'aptitude-test/';
$videoConfirm = "type='button' onclick='videoConfirm($pe->subscription_id)' data-toggle='modal' data-target='#step1-confirm'";
} else if ($test_type == 'PER') {
$testLink = 'personality-test/';
$videoConfirm = "type='submit'";
} else if ($test_type == 'INT') {
$testLink = 'interest-test/';
$videoConfirm = "type='submit'";
} else {
$e_plan_id = $pe->plan_id;
$getLink = $wpdb->get_row("SELECT test_url FROM $PSY_PLANS where plan_id='$e_plan_id'");
$testLink = $getLink->test_url . '/';
$videoConfirm = "type='submit'";
}
# expire difference
$activeDate1 = $pe->active_date;
$activeDate2 = date('Y-m-d H:i:s');
$datetime1 = new DateTime($activeDate1);
$datetime2 = new DateTime($activeDate2);
$dteDiff = $datetime2->diff($datetime1);
$todayDate = date("Y-m-d");
$expireDays = $dteDiff->format('%a');
$activeOn = str_replace('-', '/', date('Y-m-d H:i:s', strtotime($activeDate1)));
$expiredDate = date('d M,Y', strtotime($activeOn . '+15 days'));
//check if user already taken test
$checkTest = $wpdb->get_row("SELECT count(test_taken_id) as count_test,test_taken_id,start_date,status FROM $PSY_TEST_GEN_TEST_TAKEN where reference_id='$pe->subscription_id' and user_id='$user_id'");
//check if test taken then show 24 hour message
$dateAttempt = date('d F, Y', strtotime($checkTest->start_date));
$testDate = date('Y-m-d H:i:s', strtotime($checkTest->start_date));
$date1 = str_replace('-', '/', $testDate);
$tomorrow = date('Y-m-d H:i:s', strtotime($date1 . '+1 days'));
$takenTest = $checkTest->status;
if ($takenTest == '') {
$view = 'new';
$testID = 0;
$btnName = 'Start Test';
} else if ($takenTest == 'N') {
$view = 'old';
$testID = $checkTest->test_taken_id;
$btnName = 'Resume Test';
} else {
$view = 'complete';
$btnName = '';
}
# plan expiry code
if ($expireDays > 15 && $pStatus == '1') {
# code
if ($view == 'new') {
if ($pe->subscription_id != '' && $pe->subscription_id != '0') {
$updatePlan = $wpdb->query("UPDATE $PSY_SUBSCRIPTION set active_status='2' where subscription_id='$pe->subscription_id'");
$expiredStatus = 1; //can't take test
}
} else {
$expiredStatus = 0; //can take test
}
} else if ($pStatus == '2') {
$expiredStatus = 1; //can't take test
} else {
$expiredStatus = 0; //can take test
}
?>
<li>
<h4><?php echo $pe->category_name ?></h4>
<h6><?php echo date('d M, Y', strtotime($pe->purchase_date)) ?></h6>
<?php if ($view == 'new' || $view == 'old') { ?>
<?php if ($testStatus == 1) {
if ($expiredStatus == '0') {
?>
<form id="testForm<?php echo $pe->subscription_id ?>" action="<?php echo ROOT_LINK . $testLink ?>" method="POST">
<input type="hidden" name="sID" value="<?php echo $pe->subscription_id ?>">
<input type="hidden" name="class_id" value="<?php echo $class_id ?>">
<input type="hidden" name="view" value="<?php echo $view ?>">
<input type="hidden" name="pending_test_id" value="<?php echo $testID ?>">
<input <?php echo $videoConfirm; ?> name="start_test" value="<?php echo $btnName; ?>" class="start-test-btn">
</form>
<?php } else { ?>
<h5 class="alert alert-danger" role="alert">
Your plan is Expired on <?php echo $expiredDate; ?>
</h5>
<?php }
} else { ?>
<button type="button" class="start-test-btn" id="testStatus">Start Test</button>
<?php } ?>
<?php } //if not test taken
else {
if ($curDate >= $tomorrow) {
?>
<a href="<?php echo ROOT_LINK . $testLink . 'test-report?testId=' . $checkTest->test_taken_id ?>" class="start-test-btn"><h3>View Report</h3></a>
<?php } //if test taken and time complete 24 hour
else { ?>
<h6>Thank you for taking the test
Your reports will be ready within 24 hrs on your dashboard after our experts have created your profile. You will be intimated through email.</h6>
<?php } // else shoe msg of 24 hour
?>
<?php } // test taken else condition
?>
</li>
<?php } // foreach for plan wise euser exams
?>
</ul>
</div>
</div>
<?php } // foreach for user plans
?>
<?php } // if plan purchases
else {
?>
<div class="col-md-9 col-sm-9 col-xs-12">
<h4 style="color:#513b87;">You have not purchased any test <a href="/psychometric-test/#plan1">Click here</a> to purchase a Psychometric Test</h4>
</div>
<?php } // not buy any plan
?>
</div>
</div>
</div>
</div>
</section>
<!----Start Test Video---------->
<div class="modal fade start-video-modal" id="step1-confirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog socialmodal-dialog">
<div class="loginmodal-container sociallink-box">
<div class="section-description-content">
<h2>Watch these videos before taking Aptitude test:
<button type="button" class="close" data-dismiss="modal">
×</button>
</h2>
</div>
<input type="hidden" name="btn_id" id="catch_id">
<div class="row m-0">
<div class="col-md-6 col-sm-6 col-xs-12">
<iframe width="400" height="250" src="https://www.youtube.com/embed/eKOzP1AdAcE" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<iframe width="400" height="250" src="https://www.youtube.com/embed/BFpfh_IXWy8" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</div>
<div class="row m-0">
<div class="col-md-6">
<iframe width="400" height="250" src="https://www.youtube.com/embed/HZiMf0iO23s" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div class="col-md-6">
<iframe width="400" height="250" src="https://www.youtube.com/embed/i9uBAmDyekU" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div class="col-md-2">
</div>
</div>
<div class="row m-0">
<div class="col-md-12 col-sm-12 col-xs-12 text-center">
<p>
<a href="https://www.youtube.com/channel/UC_Y9Si7E4Xjt9hjYhGuo_gQ" target="_blank">
<i class="fa fa-arrow-right"></i> More videos on career development</a>
</p>
<p class="lead">
<input type="checkbox" name="watched" id="watched" value="Y"> I have watched all the videos. Proceed with test.
</p>
<p class="lead">
<button type="button" class="" id="startTestConfirm">Start Test</button>
or <a href="javascript:void(0);" data-dismiss="modal">
<< Back</a>
</p>
</div>
</div>
</div>
</div>
</div>
<!----Start Test Video ENd------>
<script type="text/javascript">
jQuery(document).on('click', '#testStatus', function() {
toastr.options = {
"closeButton": true,
"debug": false,
"positionClass": "toast-bottom-full-width",
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "10000",
"extendedTimeOut": "10000000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "slideDown",
"hideMethod": "hide"
};
toastr.error("To start test you have to fill your details, for example: Date of birth,State and Class <button type='button' class='btn btn-sm btn-info' id='toast'>Click Here</button>")
});
jQuery(document).on('click', '#toast', function() {
window.location.href = '/profile'
});
/**function for opening video modal */
function videoConfirm(id) {
jQuery("#catch_id").val(id);
}
/***start test on modal btn click */
jQuery(document).on('click', '#startTestConfirm', function() {
if (jQuery("input[name='watched']").is(':checked')) {
var from_id = jQuery("#catch_id").val();
jQuery("#testForm" + from_id).submit();
} else {
alert("It seems, that you haven't watched our videos");
}
});
</script>
<?php
} else {
?>
<script>
window.location.href = '/login'
</script>
<?php
}
?>