<?php
	if ( !defined('IN_MFA') )
		die("Hacking attempt");
	
	$user->dieNotValid();
	$layoutusercpargs = array();
	
	$layoutusercpargs['errmsg'] = "";
	if(IsSet($_POST['changepw']))
	{
		if(crypt($_POST['oldpw'],$user->user_password) != $user->user_password)
			$layoutusercpargs['errmsg'] .= "<span class='error'>The old password is wrong</span>";
		elseif($_POST['pw1'] != $_POST['pw2'])
			$layoutusercpargs['errmsg'] .= "<span class='error'>There are two different inputs</span>";
		else
		{
			$user->user_password = crypt($_POST['pw1']);
			if(! $user->writeuser())
				$layoutusercpargs['errmsg'] .= "<span class='error'>Couldn't write userdata</span>";
			else
				$layoutusercpargs['errmsg'] .= "<span class='success'>Done</span>";
		}	
		$layoutusercpargs['errmsg'] .= "<br>";
	}
	if(IsSet($_POST['changeeditorset']))
	{
		$user->editor_setting = $_POST['seleditor'];
		if(! $user->writeuser())
			$layoutusercpargs['errmsg'] .= "<span class='error'>Couldn't write userdata</span>";
		else
			$layoutusercpargs['errmsg'] .= "<span class='success'>Done</span>";
	}	

	$layoutusercpargs['lang_general_user_info'] = $lang['general_user_info'];
	if($user->user_level == 1)
    	$user_rank = $lang['admin'];
  if($user->user_level == 0)
    	$user_rank = $lang['normal_user'];
	$layoutusercpargs['lang_rank'] = $lang['rank'];
	$layoutusercpargs['rank'] = $user_rank;

	$layoutusercpargs['lang_canview'] = $lang['canview'];
	$layoutusercpargs['lang_canedit'] = $lang['canedit'];
	$layoutusercpargs['lang_canupload'] = $lang['canupload'];
	$layoutusercpargs['lang_candelete'] = $lang['candelete'];
	$layoutusercpargs['lang_canscript'] = $lang['canscript'];
	
	$canview = $user->has_right("view");
	$layoutusercpargs['canview'] = ($canview)? $lang['yes']:$lang['no'];
	$layoutusercpargs['viewoption'] = ($canview)? "success":"error";
	$canview = $user->has_right("edit");
	$layoutusercpargs['canedit'] = ($canview)? $lang['yes']:$lang['no'];
	$layoutusercpargs['editoption'] = ($canview)? "success":"error";
	$canview = $user->has_right("upload");
	$layoutusercpargs['canupload'] = ($canview)? $lang['yes']:$lang['no'];
	$layoutusercpargs['uploadoption'] = ($canview)? "success":"error";
	$canview = $user->has_right("delete");
	$layoutusercpargs['candelete'] = ($canview)? $lang['yes']:$lang['no'];
	$layoutusercpargs['deleteoption'] = ($canview)? "success":"error";
	$canview = $user->has_right("scripting");
	$layoutusercpargs['canscript'] = ($canview)? $lang['yes']:$lang['no'];
	$layoutusercpargs['scriptoption'] = ($canview)? "success":"error";
	
	$layoutusercpargs['lang_who_is_online'] = $lang['who_is_online'];
	
	$layoutusercpargs['online_users'] = "";
	if(!$userlist = getusers())
		$layoutusercpargs['online_users'] .= "<span class='error'>Couldn't obtain userdata</span>";
	else
	{	
		foreach($userlist as $usr)
		{
			$usr = new users($usr);
			if($usr->user_tmppw != "0")
			{
				if($usr->user_normallevel == 1)
    			$user_rank = $lang['admin'];
 				if($usr->user_normallevel == 0)
    			$user_rank = $lang['normal_user'];
				$layoutusercpargs['online_users'] .= "<b>".$usr->user_name."</b> - ".$user_rank."<br>";
			}
		}
	}	
	$layoutusercpargs['lang_change_pw'] = $lang['change_pw'];
	$layoutusercpargs['lang_oldpw'] = $lang['oldpw'];
	$layoutusercpargs['lang_password'] = $lang['password'];
	$layoutusercpargs['lang_repeat'] = $lang['repeat'];
	
	$layoutusercpargs['lang_language'] = $lang['language'];
	$layoutusercpargs['languages'] = "";
	//get languages
	$dh = opendir( "includes/lang/" ) or die("<p class='error'>In der Konfiguration ist eine falsche Angabe. Gehen sie in den Administrationsbereich -> Allgemeine Konfiguration und überüprüfen dort die Eingaben");
	while ( gettype($langfile = readdir( $dh )) != "boolean")
	{
		if(($langfile != ".") && ($langfile != "..")) 
		{
 			$language = substr($langfile,0, strlen($langfile)-4);
				$layoutusercpargs['languages'] .= "<option value='".$language."'";
			if(strtoupper($language) == strtoupper($user->user_lang))
				$layoutusercpargs['languages']  .= " SELECTED";
			$layoutusercpargs['languages']  .= ">".$language;
		}
	}
	closedir($dh);

	$layoutusercpargs['layouts'] = "";
	//get languages
	$dh = opendir( "template" ) or die("<p class='error'>In der Konfiguration ist eine falsche Angabe. Gehen sie in den Administrationsbereich -> Allgemeine Konfiguration und überüprüfen dort die Eingaben");
	while ( gettype($templatedir = readdir( $dh )) != "boolean")
	{
		if(($templatedir != ".") && ($templatedir != "..")) 
		{
				$layoutusercpargs['layouts'] .= "<option value='".$templatedir."'";
			if(strtoupper($templatedir) == strtoupper($user->user_template))
				$layoutusercpargs['layouts']  .= " SELECTED";
			$layoutusercpargs['layouts']  .= ">".$templatedir;
		}
	}
	closedir($dh);
	
	$layoutusercpargs['editorset'] = "<option value='simple' ".($user->editor_setting == "simple"?"selected":"").">".$lang['simpleeditor'];
	$layoutusercpargs['editorset'] .= "<option value='codepress' ".($user->editor_setting == "codepress"?"selected":"").">Codrepress";

	
	
	$show_after_header .= $template->layoutparser("usercp",$layoutusercpargs);
?>