<?php
if ( !eregi("admin.php", $PHP_SELF) ) {
	die("Access Denied");
}
include_once(XOOPS_ROOT_PATH."/modules/system/admin/users/users.php");
if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
switch($op) {
               	case "mod_users":
                        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 "<div><h4>".sprintf(_AM_AYSYWTDU,$userdata->getVar("uname"))."</h4>";
			echo _AM_BYTHIS."<br><br>";
			echo "<table><tr><td>\n";
			echo myTextForm("admin.php?fct=users&op=delUserConf&del_uid=".$userdata->getVar("uid"),_AM_YES);
			echo "</td><td>\n";
			echo myTextForm("admin.php?op=adminMain", _AM_NO);
			echo "</td></tr></table>\n";
			echo "</div>";
			CloseTable();
                        xoops_cp_footer();
                        break;
               case "delete_many":
                        xoops_cp_header();
			OpenTable();
			$count = count($HTTP_POST_VARS['memberslist_id']);
			if ( $count > 0 ) {
				$list = "<a href='".XOOPS_URL."/userinfo.php?uid=".$HTTP_POST_VARS['memberslist_id'][0]."' target='_blank'>".$HTTP_POST_VARS['memberslist_uname'][$HTTP_POST_VARS['memberslist_id'][0]]."</a>";
				$hidden = "<input type='hidden' name='memberslist_id[]' value='".$HTTP_POST_VARS['memberslist_id'][0]."' />\n";
				for ( $i = 1; $i < $count; $i++ ) {
					$list .= ", <a href='".XOOPS_URL."/userinfo.php?uid=".$HTTP_POST_VARS['memberslist_id'][$i]."' target='_blank'>".$HTTP_POST_VARS['memberslist_uname'][$HTTP_POST_VARS['memberslist_id'][$i]]."</a>";
					$hidden .= "<input type='hidden' name='memberslist_id[]' value='".$HTTP_POST_VARS['memberslist_id'][$i]."' />\n";
				}
                        	echo "<div><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' value='"._YES."' /> 
				<input type='button' value='"._NO."' onclick='javascript:location.href=\"admin.php?op=adminMain\"' />";
				echo $hidden;
				echo "</form></div>";
			} else {
				echo _AM_NOUSERS;
			}
			CloseTable();
                        xoops_cp_footer();
                        break;
		case "delete_many_ok":
			$count = count($HTTP_POST_VARS['memberslist_id']);
			$output = "";
			for ( $i = 0; $i < $count; $i++ ) {
				$deluser = new XoopsUser($HTTP_POST_VARS['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,_AM_DBUPDATED);
                        break;
                case "addUser":
                        if ( !($uname && $email && $pass) ) {
                        	echo _AM_YMCACF;
                            	return;
                        }
			$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("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() ) {
				echo _AM_CNRNU;
				exit();
			} else {
            			redirect_header("admin.php?fct=users",1,_AM_DBUPDATED);
			}
            		break;
		case "synchronize":
			synchronize($id, $type);
			break;
		case "reactivate":
			$result=$xoopsDB->query("UPDATE ".$xoopsDB->prefix("users")." SET level=1 WHERE uid=".$uid."");
			if(!$result){
				exit();
			}
                        redirect_header("admin.php?fct=users&op=modifyUser&uid=".$uid."",1,_AM_DBUPDATED);
                        break;
    		default:
			displayUsers();
			break;
}
} else {
    	echo "Access Denied";
}
?>