<?php
/*
Interface Creator
www.bioinformatics.org/phplabware
6 September 2014 release
By Santosh Patnaik, MD, PhD
GPL license
Based on DaDaBik version 3.2 by Eugenio Tacchini - http://www.dadabik.org
*/
// coming in from check_login.php
include(realpath(dirname(__FILE__) . '/../config.php'));
include(realpath(dirname(__FILE__) . '/functions.php'));
include(realpath(dirname(__FILE__) . '/common_start.php'));
include(realpath(dirname(__FILE__) . '/check_installation.php'));
// where from - GET values first
if(!empty($_GET['go_to'])) {
$go_to = $_GET['go_to'];
}
elseif(!empty($_POST['go_to'])) {
$go_to = $_POST['go_to'];
}
else {
$go_to = '(' . rawurlencode($dadabik_main_file) . ')';
}
// redirect location after logout
$location_after_logout = $site_url . $dadabik_main_file;
if($go_to == 'parent_front') {
// when Interface Creator is a backend
$location_after_logout = $parentsite_url;
}
// what type of check - admin or regular login check, or logout. GET first
if(!empty($_GET['function'])) {
$function = $_GET['function'];
}
elseif(!empty($_POST['function'])) {
$function = $_POST['function'];
}
else {
$function = 'regular';
}
if(!empty($_GET['login_message'])) {
$login_message = $_GET['login_message'];
}
/////// for logout ///////
if($function == 'logout') {
unset($_SESSION['logged_user_infos_ar']);
if(isset($_COOKIE['interface_creator_username']) or isset($_COOKIE['interface_creator_md5_password'])) {
setcookie('interface_creator_username');
// reset cookie
setcookie('interface_creator_md5_password');
// reset cookie
}
header('Location: ' . $location_after_logout);
die();
}
/////// end for logout ///////
/////// for login ///////
// if no values to check
if((empty($_POST['username_user']) or empty($_POST['password_user'])) and (empty($_COOKIE['interface_creator_username']) or empty($_COOKIE['interface_creator_md5_password']))) {
$login_message = $login_messages_ar['username_password_are_required'];
include(realpath(dirname(__FILE__) . '/login_form.php'));
echo '</body></html>';
die();
}
// if values to check, which values
if(!empty($_COOKIE['interface_creator_username']) and !empty($_COOKIE['interface_creator_md5_password'])) {
$_SESSION['logged_user_infos_ar'] = get_user_infos_ar_from_username_password($_COOKIE['interface_creator_username'], $_COOKIE['interface_creator_md5_password'], 'non-md5');
}
else {
$_SESSION['logged_user_infos_ar'] = get_user_infos_ar_from_username_password($_POST['username_user'], $_POST['password_user'], 'md5');
}
// check the values
if(!empty($_SESSION['logged_user_infos_ar'])) {
if($function == 'regular') {
if(isset($_POST['remember_me'])) {
setcookie('interface_creator_username', $_SESSION['logged_user_infos_ar']['username_user'], time() + 1000000);
//~6d
setcookie('interface_creator_md5_password', $_SESSION['logged_user_infos_ar']['password_user'], time() + 1000000);
//~6d
}
$go_to = substr($go_to, 1, - 1);
// remove the brackets
echo $go_to;
header('Location: ' . $go_to);
die();
}
elseif($function == 'admin') {
if($_SESSION['logged_user_infos_ar']['user_type_user'] === $users_table_user_type_administrator_value) {
if(isset($_POST['remember_me'])) {
setcookie('interface_creator_username', $_SESSION['logged_user_infos_ar']['username_user'], time() + 1000000);
//~6d
setcookie('interface_creator_md5_password', $_SESSION['logged_user_infos_ar']['password_user'], time() + 1000000);
//~6d
}
$go_to = substr($go_to, 1, - 1);
header('Location: ' . $go_to);
die();
}
else {
$login_message = $login_messages_ar['incorrect_admin_login'];
include(realpath(dirname(__FILE__) . '/login_form.php'));
echo '</body></html>';
die();
}
}
else {
$login_message = $login_messages_ar['username_password_are_required'];
include(realpath(dirname(__FILE__) . '/login_form.php'));
echo '</body></html>';
die();
}
}
else {
if(isset($_POST['login_submit'])) {
$login_message = ($function == 'regular') ? $login_messages_ar['username_password_are_required'] : $login_messages_ar['incorrect_admin_login'];
}
else {
$login_message = ($function == 'regular') ? '' : $login_messages_ar['incorrect_admin_login'];
}
include(realpath(dirname(__FILE__) . '/login_form.php'));
echo '</body></html>';
die();
}