<?php
// www.bcoos.net 2006-09 1.0.2 GPL
// $Id: main.php,v 1.6 2003/03/19 07:04:10 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Francisco Burzi
// Author Website : http://phpnuke.org
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
if ( !preg_match("/admin\.php/i", _PHP_SELF) ) {
	exit();
}
include_once(XOOPS_ROOT_PATH."/modules/system/admin/users/users.php");
if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
switch($op) {
case "mod_users":
	include_once(XOOPS_ROOT_PATH.'/class/xoopspagenav.php');
	displayUsers();
	break;
case "modifyUser":
	modifyUser($uid);
	break;
case "updateUser":
	updateUser($uid, $uname, $name, $url, $email, $user_icq, $user_aim, $user_yim, $user_msnm, $user_from, $user_occ, $user_intrest, $user_viewemail, $user_avatar, $user_sig, $attachsig, $theme, $pass, $pass2, $rank, $bio, $uorder, $umode, $timezone_offset);
	break;
case "delUser":
	xoops_cp_header();
	OpenTable();
	$userdata = new XoopsUser($uid);
	echo "<h4>".sprintf(_AM_AYSYWTDU, $userdata->getVar("uname"))."</h4>";
	echo _AM_BYTHIS."<br /><br />";
	echo "<table><tr><td>";
	echo myTextForm("admin.php?fct=users&op=delUserConf&del_uid=".$userdata->getVar("uid"),_YES);
	echo "</td><td>";
	echo myTextForm("admin.php?op=adminMain", _NO);
	echo "</td></tr></table>";
	CloseTable();
	xoops_cp_footer();
	break;
case "delete_many":
	xoops_cp_header();
	OpenTable();
	$count = count($_POST['memberslist_id']);
	if ( $count > 0 ) {
		$list = "<a href='".XOOPS_URL."/userinfo.php?uid=".$_POST['memberslist_id'][0]."'>".$_POST['memberslist_uname'][$_POST['memberslist_id'][0]]."</a>";
		$hidden = "<input type='hidden' name='memberslist_id[]' value='".$_POST['memberslist_id'][0]."' />\n";
		for ( $i = 1; $i < $count; $i++ ) {
			$list .= ", <a href='".XOOPS_URL."/userinfo.php?uid=".$_POST['memberslist_id'][$i]."'>".$_POST['memberslist_uname'][$_POST['memberslist_id'][$i]]."</a>";
			$hidden .= "<input type='hidden' name='memberslist_id[]' value='".$_POST['memberslist_id'][$i]."' />\n";
		}
		echo "<h4>".sprintf(_AM_AYSYWTDU," ".$list." ")."</h4>";
		echo _AM_BYTHIS."<br /><br />
		<form action='admin.php' method='post'>
		<input type='hidden' name='fct' value='users' />
		<input type='hidden' name='op' value='delete_many_ok' />
		<input type='submit' class='button' value='"._YES."' />
		<input type='button' class='button' value='"._NO."' onclick='javascript:location.href=\"admin.php?op=adminMain\"' />";
		echo $hidden;
		echo "</form>";
		} else {
			echo _AM_NOUSERS;
		}
	CloseTable();
	xoops_cp_footer();
	break;
case "delete_many_ok":
	$count = count($_POST['memberslist_id']);
	$output = "";
	for ($i=0; $i<$count; $i++) {
		$deluser = new XoopsUser($_POST['memberslist_id'][$i]);
		if ( !$deluser->delete() ) {
			$output .= "Could not delete ".$deluser->getVar("uname")."<br />";
			} else {
				$output .= $deluser->getVar("uname")." deleted<br />";
			}
	}
	xoops_cp_header();
	OpenTable();
	echo $output;
	CloseTable();
	xoops_cp_footer();
	break;
case "delUserConf":
	$user = new XoopsUser($del_uid);
	$user->delete();
	redirect_header("admin.php?fct=users", 1, _UPDATED);
	break;
case "addUser":
	if ( !($uname && $email && $pass) ) {
		xoops_cp_header();
		OpenTable();
		echo _AM_YMCACF;
		CloseTable();
		xoops_cp_footer();
		exit();
	}
	$newuser = new XoopsUser();
	if ( isset($user_viewemail) ) {
		$newuser->setVar("user_viewemail", $user_viewemail);
	}
	if ( isset($attachsig) ) {
		$newuser->setVar("attachsig", $attachsig);
	}
	$newuser->setVar("name", $name);
	$newuser->setVar("uname", $uname);
	$newuser->setVar("email", $email);
	$newuser->setVar("url", formatURL($url));
	$newuser->setVar("user_avatar", $user_avatar);
	$newuser->setVar("theme", $theme);
	$newuser->setVar("user_icq", $user_icq);
	$newuser->setVar("user_from", $user_from);
	$newuser->setVar("user_sig", $user_sig);
	$newuser->setVar("user_aim", $user_aim);
	$newuser->setVar("user_yim", $user_yim);
	$newuser->setVar("user_msnm", $user_msnm);
	$newuser->setVar("pass", md5($pass));
	$newuser->setVar("actkey", substr(md5(makepass()), 0, 8));
	$newuser->setVar("timezone_offset", $timezone_offset);
	$newuser->setVar("theme", $theme);
	$newuser->setVar("uorder", $uorder);
	$newuser->setVar("umode", $umode);
	$newuser->setVar("bio", $bio);
	$newuser->setVar("rank", $rank);
	$newuser->setVar("level", 1);
	$newuser->setVar("user_occ", $user_occ);
	$newuser->setVar("user_intrest", $user_intrest);
	if ( !$newuser->store() ) {
		xoops_cp_header();
		OpenTable();
		echo _AM_CNRNU;
		CloseTable();
		xoops_cp_footer();
		exit();
		} else {
			redirect_header("admin.php?fct=users", 1, _UPDATED);
		}
	break;
case "synchronize":
	synchronize($id, $type);
	break;
case "reactivate":
	$result = $db->query("UPDATE ".$db->prefix("users")." SET level=1 WHERE uid=$uid");
	if (!$result) {
		redirect_header("admin.php?fct=users&op=modifyUser&uid=".$uid."", 1, _NOTUPDATED);
	}
	redirect_header("admin.php?fct=users&op=modifyUser&uid=".$uid."", 1, _UPDATED);
	break;
default:
	include_once(XOOPS_ROOT_PATH.'/class/xoopspagenav.php');
	displayUsers();
	break;
}
} else {
	echo "Access Denied";
}
?>
