2014-03-04 05:08:11 -08:00
< ? php
2014-03-08 07:08:56 -08:00
// The root url
2014-04-21 10:52:21 -07:00
$root_url = " http://rubenwardy.kd.io/spelling/ " ;
2014-03-08 07:08:56 -08:00
function burl ( $page ){
2014-03-29 12:41:21 -07:00
global $root_url ;
2014-03-08 07:08:56 -08:00
return $root_url . $page ;
}
2014-03-04 05:08:11 -08:00
// Shows the web page to the user, with a title
function showHeader ( $title ){
include ( " template/header.php " );
}
// Shows a message screen to the user, and stops the scripts
function msgscrn ( $msg , $text , $more , $buttons ){
showHeader ( $msg );
echo " <h1> $msg </h1> \n " ;
echo $text ;
2014-03-29 12:41:21 -07:00
// Add buttons
2014-03-04 05:08:11 -08:00
if ( $buttons ){
if ( $buttons == " rc " ){
echo " <p><a class= \" button \" href= \" // " . $_SERVER [ 'HTTP_HOST' ] . $_SERVER [ 'REQUEST_URI' ] . " \" >Retry</a> " ;
2014-03-29 12:41:21 -07:00
echo " <a class= \" button \" href= \" " . burl ( " " ) . " \" >Cancel</a> " ;
2014-03-04 05:08:11 -08:00
} else if ( $buttons -> type == " yn " ){
echo " <p><a class= \" button \" href= \" " . $buttons -> yes . " \" >Yes</a> " ;
echo " <a class= \" button \" href= \" " . $buttons -> no . " \" >No</a> " ;
} else if ( $buttons -> type == " oc " ){
echo " <p><a class= \" button \" href= \" " . $buttons -> ok . " \" >Ok</a> " ;
echo " <a class= \" button \" href= \" " . $buttons -> cancel . " \" >Cancel</a> " ;
} else if ( $buttons -> type == " c " ){
echo " <p><a class= \" button \" href= \" " . $buttons -> c . " \" >Continue</a> " ;
}
}
2014-03-29 12:41:21 -07:00
// Add more stuff text box
2014-03-04 05:08:11 -08:00
if ( $more ){
echo " <div class= \" code \" > $more </div> " ;
}
2014-03-29 12:41:21 -07:00
// Exit
2014-03-04 05:08:11 -08:00
die ( " " );
}
// Check that the user is logged in
define ( " AUTH_PUPIL " , 1 );
define ( " AUTH_STAFF " , 2 );
define ( " AUTH_ADMIN " , 3 );
function auth ( $level ){
global $current_user ;
if ( ! $current_user || $current_user -> rank < $level ){
if ( $current_user -> rank >= AUTH_PUPIL ){
2014-03-29 12:41:21 -07:00
msgscrn ( " Access Denied " , " You do not have the authority to do this.<br>Try logging in with " . getAuthLabel ( $level ) . " privileges.<p><a class= \" button \" href= \" " . burl ( " logout.php " ) . " \" >Log Out</a></p> " , " " , " " );
2014-03-04 05:08:11 -08:00
}
2014-04-21 10:52:21 -07:00
header ( " location: " . burl ( " login.php?id= $level " ));
2014-03-04 05:08:11 -08:00
die ( " " );
}
}
2014-03-29 12:41:21 -07:00
// Return a string describing the given rank level
2014-03-04 05:08:11 -08:00
function getAuthLabel ( $level ){
if ( $level == AUTH_PUPIL )
return " pupil " ;
else if ( $level == AUTH_STAFF )
return " staff " ;
2014-04-09 08:56:22 -07:00
else if ( $level == AUTH_ADMIN )
2014-03-04 05:08:11 -08:00
return " admin " ;
else
return " lvl( $level ) " ;
}
// Connect to the database
$handle = mysqli_connect ( " localhost " , " root " , " pass " , " spelling " ) or msgscrn ( " Database connection error " , " We can not connect to the MySQL database at this time. " , 0 , 0 );
// Include modules
require_once " database/user.php " ;
require_once " database/test.php " ;
require_once " database/testassign.php " ;
require_once " database/word.php " ;
require_once " database/nearword.php " ;
require_once " database/score.php " ;
require_once " database/wrongword.php " ;
// User login
session_start ();
$current_user = null ;
if ( $_SESSION [ 'user' ] != " " && $_SESSION [ 'user' ] != null ){
$current_user = user :: getUsername ( $_SESSION [ 'user' ]);
}
?>