<?php
/**************************************************************************************************
* ChurchCMS
* Copyright (C) 2005 jsvoyager
*
* Developers & Contributors:
* jsvoyager hide@address.com
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* (license.txt)
***************************************************************************************************/
include ("lib/header.inc.php");
//Language File
include ("lang/"._LANG_."/login.inc.php");
if ($_GET['op'] == "login"){
if (isset($_POST['uname'])){
//Someone's trying to login
$query = "SELECT * FROM "._USERS_." WHERE uname='{$_POST['uname']}' AND pass=password('{$_POST['pass']}') LIMIT 1";
$result = $db->query(__FILE__,__LINE__,$query);
$user = $db->results($result);
if ($user['uname'] != $_POST['uname']){
$smarty->assign("error", $lang['login']['incorrect']);
$smarty->display("login.tpl");
}else{
//Set up their user var
$_SESSION['user']['uname'] = $user['uname'];
$_SESSION['user']['name'] = $user['disp_name'];
$_SESSION['user']['admin'] = ($user['admin'] == 1) ? (true) : (false);
$_SESSION['user']['email'] = $user['email'];
$_SESSION['user']['id'] = $user['id'];
//Direct them away
$_SESSION['next_page']['msg'] = $lang['login']['success'];
$_SESSION['next_page']['class'] = "good";
if ($_SESSION['user']['admin']){
header("Location: admin.php?op=cp");
}else{
header("Location: index.php");
}
}
}
}elseif ($_GET['op'] == "logout"){
unset($_SESSION['user']);
header("Location: index.php");
}
//Now for the restricted stuff
if ($_SESSION['user']['admin'] == true){
include ("lang/"._LANG_."/cp.inc.php");
if ($_GET['op'] == "cp"){
//Control Panel
if ($_SESSION['user']['id'] == 1){
//They are "the administrator" and get special privs. which we must construct
//First, there's the module manager
$dh = opendir("modules");
while ($file = readdir($dh)){
if ($file != "." && $file != ".."){
$modules[] = $file;
}
}
closedir($dh);
$smarty->assign("modules", $modules);
//Then there's the user manager
$query = "SELECT * FROM "._USERS_;
$result = $db->query(__FILE__, __LINE__, $query);
$i = 0;
while ($user = $db->results($result)){
$users[$i]['id'] = $user['id'];
$users[$i]['login'] = $user['uname'];
$users[$i]['name'] = $user['disp_name'];
$users[$i]['email'] = $user['email'];
$users[$i]['admin'] = ($user['admin'] == 1) ? (true) : (false);
$i++;
}
$smarty->assign("users", $users);
print_r ($users);
}
$smarty->display("cp.admin.tpl");
}elseif ($_GET['op'] == "add_mod"){
//Adding a module
//Move it
move_uploaded_file($_FILES['new_mod_file']['tmp_name'], "new_mod.tar.gz");
//Call to module installer
header("Location: install_mod.php?file=new_mod.tar.gz");
}elseif ($_GET['op'] == "post_mod_install"){
//Remove that file!
unlink(_ROOT_ . "/new_mod.tar.gz");
header("Location: index.php");
}
}
include ("lib/footer.inc.php");
?>