Below I am trying to create a feature where if a user is on a current page, all the other pages in the array are locked out (cannot be accessed), the other pages cannot be accessed until the user has completed the current page they are on.
Now below is the code which deals with 6 php scripts:
<script type="text/javascript">
$(function() {
var link = $("#createLink");
link.click(function() {
$.ajax({
url: "removesession.php",
async: false,
type: "POST",
success: function() {
window.location.href = link.attr("href");
}
});
//cancels the links true action of navigation
return false;
});
);
</script>
<?php
$steps = array('create_session.php', 'QandATable.php', 'individualmarks.php', 'penalty.php', 'penaltymarks', 'complete.php');
// Track $latestStep in either a session variable
// $currentStep will be dependent upon the page you're on
$latestStep = $_SESSION['latestStep'];
$currentStep = basename(__FILE__);
$currentIdx = array_search($currentStep, $steps);
$latestIdx = array_search($latestStep, $steps);
if ($currentIdx - $latestIdx > 1 ) {
?>
<div class="boxed">
<a href="<?= $pages[$currentPages+1] ?>">Continue</a>
<br/><a href="create_session.php" id="createLink">Create New</a>
</div>
<?
} else {
// let the user do the step
}
?>
So here is an example of what could happen:
- User is on
penalty.php
page, so the other pages in the array are locked out If user tries to access another page they are displayed with the div box shown above:
If user selects
Continue
link then it should navigate the user to the page they should be on which waspenalty.php
pageIf user selects
Create New
link then it should navigate to thecreate_session.php
and perform the jquery/ajax method and navigate to theremovesession.php
script in the background
Now the code above is in a php script known as steps.php
and this is externalized so that it can be accessed using include(steps.php)
and this will be included in the 6 php scripts in the array so that those scripts can access those pages.
Now my question is that I need to do one more thing in this code which deals with the if/else statement I have in the code above and including code in the other scripts:
Using return values, return 1 if user can do the step, 0 if they can not. Then on each page, you'd call this function, and depending on the return value, either show the page, or show the error
My question is that I don't quite seem to know how to code what is mentioned in the above quotation. Can somebody show what the if/else statement should look like and what code should be included in one of the php scripts of the 6 in order to be able to call the function in that script?
UPDATE:
steps.php
<?php
function allowed_in($steps){
$steps = array('create_session.php', 'QandATable.php', 'individualmarks.php', 'penalty.php', 'penaltymarks', 'complete.php');
// Track $latestStep in either a session variable
// $currentStep will be dependent upon the page you're on
$latestStep = $_SESSION['latestStep'];
$currentStep = basename(__FILE__);
$currentIdx = array_search($currentStep, $steps);
$latestIdx = array_search($latestStep, $steps);
if ($currentIdx - $latestIdx > 1 ) {
return 1;
} else {
return 0;
}
}
?>
create_session.php:
if(allowed_in($steps)){
//all code in the create_session.php
}else{
?>
<div class="boxed">
<a href="<?= $pages[$currentPages+1] ?>">Continue</a>
<br/>
<a href="create_session.php" id="createLink">Create New</a>
</div>
<?php
}
?>