/**
* index.php
* initiates the Syllogistek Argument Database Software
*/
include("user.php");
include("class.php");
include("login.php");
// session_start();
if ($_GET['logout']) {
unset($_SESSION['user']);
unset($_SESSION['admin']);
// header("Location: index.php");
}
//Register
if(isset($_POST['register_button'])){
echo '';
}else if ($_POST['email'] != "") { //Login
$id = login($_POST['email'], $_POST['password']);
if ($id != -1) {
$_SESSION['user'] = $id;
$_SESSION['admin'] = getAdmin($id);
}
else
$_SESSION['error'] = 1;
}
// Add guest-user
if ($_POST['gemail'] != "") {
if (!get_magic_quotes_gpc()) {
$fname = addslashes($_POST['fname']);
$lname = addslashes($_POST['lname']);
$email = addslashes($_POST['gemail']);
$newuser = getUser('Email', $email);
}
else {
$fname = ($_POST['fname']);
$lname = ($_POST['lname']);
$email = ($_POST['gemail']);
$newuser = getUser('Email', $email);
}
if ($newuser) {
$regfail=1;
}
else {
$regfail="0";
$chars = "abcdefghijkmnopqrstuvwxyz023456789";
srand((double)microtime()*1000000);
$i = 0;
$randpass = '' ;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$randpass = $randpass.$tmp;
$i++;
}
$worked = addUser($fname, $lname, $email, $randpass, 1);
if ($worked) {
$address = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
$address = substr($address, 0, -9);
$body = "Hello, ".$_POST['fname']."! You have been added as a user to Syllogistek, the".
" Argument Library Software. Please login to the system ".
"at ".$address.". The password generated for you is:\n\n\t".$randpass."\n\nYou".
" may change this password from your user information screen once you log in.".
"\n\n\nThis message has been generated automatically. Please do not reply to ".
"this message.";
$body = wordwrap($body, 70);
mail($_POST['gemail'], "Welcome to Syllogistek!", $body, "From: donotreply@syll.net");
$regfail = 2;
$user=getUser('Email',$email);
$classes = getActiveClasses(true, null);
$max = count($classes);
for ($n = 0; $n < $max; $n++) {
if ($classes[$n]['CourseName'] == "Public") {
enrollUser($classes[$n]['ID'],$user['ID']);
break;
}
}
}
else
$regfail = 3;
}
}
//Add super-user?
if ($_POST['s_fname']) {
$fname = $_POST['s_fname'];
$lname = $_POST['s_lname'];
$email = $_POST['s_email'];
$pass = $_POST['s_pass'];
if ($fname != "" && $lname != "" && $email != "" && $pass != "") {
$pos = strpos($email, '@');
if ($pos > 0 && $pos < strlen($email)-1) {
if ($email !== $_POST['s_emailcon'])
$_SESSION['s_error_emailmatch'] = 1;
if ($pass !== $_POST['s_passcon'])
$_SESSION['s_error_passmatch'] = 1;
if (!(isset($_SESSION['s_error_emailmatch']) || isset($_SESSION['s_error_passmatch']))) {
$id = addUser($fname, $lname, $email, $pass, -2);
$_SESSION['user'] = $id;
$_SESSION['admin'] = getAdmin($id);
}
}
else
$_SESSION['s_error_bademail'] = 1;
}
else
$_SESSION['s_error_blank'] = 1;
}
include("header.php");
if (isset($_SESSION['user'])) {
if (isActive($_SESSION['user'])) {
$user = getUserName($_SESSION['user']);
?>
Welcome, echo($user['FirstName']) ?>!
What would you like to do?