<?php
ob_start();
require_once("init.php");
if ( !permission('settings')  ) { echo error($langadmin['noperms']); exit; }
$tmpl = new Koobi("templates/" . ADMINTHEME . "/settings/");

$tmpl->assign("theme", ADMINTHEME);
$tmpl->assign("lang", $lang);
$tmpl->assign("langadmin", $langadmin);
$tmpl->assign('pref', $pref);
/*
$row_uf->fieldtext = $lang['userfields_' . $row_uf->fieldname];
	$row_uf->fieldval = $_REQUEST[$row_uf->fieldname];
	*/
switch($_REQUEST['action']){
	case '':
	case 'show':
	
	$userfields = array();
	$sql = new dbc("SELECT * FROM ".PREFIX."_userfields order  by posi ASC");
	while($row = $sql->fetchrow()){
		$row->field_lang = $lang['userfields_' . $row->fieldname];
		array_push($userfields,$row);
		}
	$tmpl->assign('userfields', $userfields);
	$tmpl->display('userfields.tpl');
	break;
	
	case 'save':
	if($_POST['posi']>=1){
		foreach($_POST['posi'] as $id => $posi) {
			if( $posi != "")  {
				$query = new dbc("UPDATE ".PREFIX."_userfields SET posi='$posi' WHERE id = '$id'");
				
			}
		}
	}
	
	
	if($_POST['required']>=1){
		foreach($_POST['required'] as $id => $required) {
			if( $posi != "")  {
				$query = new dbc("UPDATE ".PREFIX."_userfields SET required='$required' WHERE id = '$id'");
				
			}
		}
	}
	
	
	if($_POST['active']>=1){
		foreach($_POST['active'] as $id => $active) {
			if( $posi != "")  {
				$query = new dbc("UPDATE ".PREFIX."_userfields SET active='$active' WHERE id = '$id'");
				
			}
		}
	}
	header("Location:userfields.php");
	break;

}
?>
