<?php
// ======================================================================== //
//                                                                          //
//   KooBI- Webportalsystem                                                 //
//   SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS                     //
//                                                                          //
//   ====================================================================   //
//                                                                          //   
//   dream4 | webservices - Am Michelsgrund 7 - 69469 Weinheim - Germany    //    
//   tel. +49(0) 6201 - 980442 / fax. +49(0) 6201 - 64809                   //
//                                                                          //
// ======================================================================== //
$sname = simpletitle($lang['changepw']);
if ($islogged!=1) {
	$EOUT = stderror("nopermission", $lang['nopermission_t'], str_replace("__URL__", "index.php", $lang['redirect']), "index.php", 1);
	$error = 1;
	$NOOUT = 1;
	
	} else {
	
	$tmpl->assign('msg', $lang['changepw_t']);
	$tmpl->assign('oldpw_t', $lang['oldpw_t']);
	$tmpl->assign('newpw_t', $lang['newpw_t']);
	$tmpl->assign('newpw2_t', $lang['newpw2_t']);
	$tmpl->assign('newpassbutt', $lang['changepw']);
	
	if ($_REQUEST['send']==1) {
		$ok = 1;
		$sql =& new dbc("SELECT pass FROM ".PREFIX."_user WHERE pass='".md5(iform($_POST['oldpass'],"35",""))."' AND uid='".$UID."'");
		$num = $sql->numrows();
		if ($num < 1) {
			$error .= emsg("newpw_error");
			$ok = 0;
		}
		
		if (empty($_POST['newpass']) && empty($_POST['newpass2'])) {
			$error .= emsg("newpw_error3");
			$ok = 0;
		}
		
		if (iform($_POST['newpass'],"35","") != iform($_POST['newpass2'],"35","")) {
			$error .= emsg("newpw_error2");
			$ok = 0;
		}
		
		$pw1 = iform($_POST['newpass'],"35","");
		if (isset($_POST['newpass']) &&  ($_POST['newpass']!="") && (strlen($pw1) <5) ) {
			$error .= emsg("error_ptoshort");
			$ok = "0";
		}
		
		// Werden Sonderzeichen verwendet?
		if (isset($_POST['newpass']) && $_POST['newpass']!="") {
			$pwcheck = str_replace(array("[","]",":","(",")","="), "", $_POST['newpass']);
			
			if (ereg("[^ _A-Za-zÀ-ÖØ-öø-ÿ0-9-]", $pwcheck)) {
				$error .= emsg("error_pnospecial");
				$ok = "0";
			}
		}
		
		if ($ok==0) {
			$tmpl->assign('title_error', $lang['error']);
			$tmpl->assign('iserror', 1);
			$tmpl->assign('error', $error);
		}
		
		
		
		if ($ok==1) {
			$sql =& new dbc("UPDATE ".PREFIX."_user SET pass='".md5(iform($_POST['newpass'],"35",""))."' WHERE uid='".$UID."'");
			setcookie("kuid", $UID , time()+(365*24*3600));
			setcookie("kpass",md5(iform($_POST['newpass'],"35","")),time()+(365*24*3600));
			header("Location:index.php?p=changepw&ok=1");
		}
	}
	
	if ($_REQUEST['ok']==1) {
		$tmpl->assign('msg', $lang['newpw_ok']);
	}
	
	$tmpl->assign('newpass', iform($_POST['newpass'],"35",""));
	$tmpl->assign('newpass2', iform($_POST['newpass2'],"35",""));
	
	if ($nometa==1) {
		$tmpl->assign("content", $OUT);
	} else {
		$tmpl->assign("content", parsetrue("container/".container("changepw"),$lang['changepw'], $tmpl->fetch("user/changepw.tpl")));
	}
}
?>