2013-08-07 20:32:44 +02:00
|
|
|
<?php
|
2013-08-11 22:25:25 +02:00
|
|
|
// Include necessary files
|
2013-08-09 00:44:43 +02:00
|
|
|
if(!file_exists('inc/config.php')) header('location: install.php');
|
|
|
|
require_once('inc/config.php');
|
|
|
|
require_once('inc/User.class.php');
|
|
|
|
require_once('inc/rain.tpl.class.php');
|
|
|
|
raintpl::$tpl_dir = 'tpl/';
|
|
|
|
raintpl::$cache_dir = 'tmp/';
|
|
|
|
|
2013-08-11 22:25:25 +02:00
|
|
|
// Define raintpl instance
|
2013-08-09 00:44:43 +02:00
|
|
|
$tpl = new raintpl();
|
2013-08-09 23:47:01 +02:00
|
|
|
$tpl->assign('instance_title', htmlspecialchars(INSTANCE_TITLE));
|
2013-08-09 23:35:20 +02:00
|
|
|
$tpl->assign('connection', false);
|
|
|
|
$tpl->assign('notice', '');
|
2013-08-09 23:43:56 +02:00
|
|
|
$tpl->assign('error', '');
|
2013-08-09 23:35:20 +02:00
|
|
|
|
2013-08-11 22:25:25 +02:00
|
|
|
// Handle current user status
|
|
|
|
session_start();
|
|
|
|
$current_user = new User();
|
|
|
|
if(isset($_SESSION['current_user'])) {
|
|
|
|
$current_user->sessionRestore($_SESSION['current_user'], true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$current_user = false;
|
|
|
|
}
|
|
|
|
$tpl->assign('current_user', $current_user);
|
2013-08-09 00:44:43 +02:00
|
|
|
|
2013-08-11 22:25:25 +02:00
|
|
|
// If not connected, redirect to connection page
|
|
|
|
if($current_user === false && (empty($_GET['do']) OR $_GET['do'] != 'connect')) {
|
2013-08-09 00:44:43 +02:00
|
|
|
header('location: index.php?do=connect');
|
|
|
|
}
|
|
|
|
|
2013-08-11 22:25:25 +02:00
|
|
|
// Initialize empty $_GET['do'] if required to avoid error
|
2013-08-09 00:44:43 +02:00
|
|
|
if(empty($_GET['do'])) {
|
|
|
|
$_GET['do'] = '';
|
|
|
|
}
|
|
|
|
|
2013-08-11 22:25:25 +02:00
|
|
|
// Check what to do
|
2013-08-09 00:44:43 +02:00
|
|
|
switch($_GET['do']) {
|
|
|
|
case 'connect':
|
2013-08-11 22:25:25 +02:00
|
|
|
if($current_user !== false) {
|
|
|
|
header('location: index.php');
|
|
|
|
}
|
2013-08-09 00:44:43 +02:00
|
|
|
if(!empty($_POST['login']) && !empty($_POST['password'])) {
|
|
|
|
if($current_user->exists($_POST['login']) && $current_user->checkPassword($_POST['password'])) {
|
|
|
|
$_SESSION['current_user'] = $current_user->sessionStore();
|
|
|
|
header('location: index.php');
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$error = "Unknown username/password.";
|
|
|
|
}
|
|
|
|
}
|
2013-08-09 23:35:20 +02:00
|
|
|
$tpl->assign('connection', true);
|
2013-08-09 23:47:01 +02:00
|
|
|
$tpl->assign('user_post', (!empty($_POST['login'])) ? htmlspecialchars($_POST['login']) : '');
|
2013-08-09 00:44:43 +02:00
|
|
|
$tpl->draw('connexion');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'disconnect':
|
|
|
|
$current_user = false;
|
|
|
|
session_destroy();
|
|
|
|
header('location: index.php?do=connect');
|
|
|
|
exit();
|
2013-08-09 23:35:20 +02:00
|
|
|
break;
|
2013-08-09 00:44:43 +02:00
|
|
|
|
2013-08-09 23:35:20 +02:00
|
|
|
case 'password':
|
2013-08-09 23:43:56 +02:00
|
|
|
if(!empty($_POST['password']) && !empty($_POST['password_confirm'])) {
|
|
|
|
if($_POST['password'] == $_POST['password_confirm']) {
|
2013-08-11 22:25:25 +02:00
|
|
|
$current_user->setPassword($user->encrypt($_POST['password']));
|
|
|
|
$current_user->save();
|
2013-08-09 00:44:43 +02:00
|
|
|
|
2013-08-09 23:43:56 +02:00
|
|
|
header('location: index.php');
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$tpl->assign('error', 'The content of the two password fields doesn\'t match.');
|
|
|
|
}
|
|
|
|
}
|
2013-08-10 23:58:40 +02:00
|
|
|
$tpl->assign('view', 'password');
|
2013-08-09 23:35:20 +02:00
|
|
|
$tpl->draw('edit_users');
|
|
|
|
break;
|
|
|
|
|
2013-08-10 23:58:40 +02:00
|
|
|
case 'edit_users':
|
|
|
|
case 'add_user':
|
2013-08-11 22:25:25 +02:00
|
|
|
if(!$current_user->getAdmin()) {
|
2013-08-10 23:58:40 +02:00
|
|
|
header('location: index.php');
|
|
|
|
}
|
2013-08-11 22:25:25 +02:00
|
|
|
|
|
|
|
if(!empty($_POST['login']) && (!empty($_POST['password']) || !empty($_POST['user_id'])) && isset($_POST['admin'])) {
|
|
|
|
$user = new User();
|
|
|
|
if(!empty($_POST['user_id'])) {
|
|
|
|
$user->setId($_POST['user_id']);
|
|
|
|
}
|
|
|
|
$user->setLogin($_POST['login']);
|
|
|
|
if(!empty($_POST['password'])) {
|
|
|
|
$user->setPassword($user->encrypt($_POST['password']));
|
|
|
|
}
|
|
|
|
$user->setAdmin($_POST['admin']);
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
header('location: index.php?do=edit_users');
|
|
|
|
exit();
|
|
|
|
}
|
2013-08-10 23:58:40 +02:00
|
|
|
|
|
|
|
if(!empty($_GET['user_id']) || $_GET['do'] == 'add_user') {
|
|
|
|
if(!empty($_GET['user_id'])) {
|
|
|
|
$user_id = (int) $_GET['user_id'];
|
|
|
|
$user = new User();
|
|
|
|
$user->load_user(array('id'=>$user_id));
|
|
|
|
$tpl->assign('user_data', $user);
|
|
|
|
}
|
|
|
|
$tpl->assign('user_id', (!empty($user_id) ? $user_id : -1));
|
|
|
|
$tpl->assign('view', 'edit_user');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$users_list = new User();
|
|
|
|
$users_list = $users_list->load_users();
|
2013-08-11 22:25:25 +02:00
|
|
|
|
2013-08-10 23:58:40 +02:00
|
|
|
$tpl->assign('users', $users_list);
|
|
|
|
$tpl->assign('view', 'list_users');
|
|
|
|
}
|
2013-08-11 22:25:25 +02:00
|
|
|
$tpl->assign('login_post', (!empty($_POST['login']) ? htmlspecialchars($_POST['login']) : ''));
|
|
|
|
$tpl->assign('admin_post', (isset($_POST['admin']) ? (int) $_POST['admin'] : -1));
|
2013-08-10 23:58:40 +02:00
|
|
|
$tpl->draw('edit_users');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete_user':
|
2013-08-11 22:25:25 +02:00
|
|
|
if($_GET['user_id'] != $current_user->getId()) {
|
|
|
|
$user = new User();
|
2013-08-11 22:34:39 +02:00
|
|
|
$user->setId($_GET['user_id']);
|
2013-08-11 22:25:25 +02:00
|
|
|
$user->delete();
|
|
|
|
|
2013-08-11 22:34:39 +02:00
|
|
|
header('location: index.php?do=edit_users');
|
2013-08-11 22:25:25 +02:00
|
|
|
exit();
|
|
|
|
}
|
2013-08-10 23:58:40 +02:00
|
|
|
break;
|
|
|
|
|
2013-08-09 23:35:20 +02:00
|
|
|
default:
|
2013-08-10 23:58:40 +02:00
|
|
|
$users_list = new User();
|
|
|
|
$users_list = $users_list->load_users();
|
|
|
|
$tpl->assign('users', $users_list);
|
2013-08-09 23:35:20 +02:00
|
|
|
$tpl->assign('bill', array(0=>array()));
|
|
|
|
$tpl->draw('index');
|
2013-08-09 00:44:43 +02:00
|
|
|
break;
|
|
|
|
}
|