<?php
include('include/autoloader.php');
if (!isset($_SESSION['media_cms_user'])) {
die('You Can\'t Access This Page.');	
} 
if (isset($_GET['case'])) {
$case = make_safe(xss_clean($_GET['case']));	
} else {
die('You Can\'t Access This Page.');	
}
switch ($case) {
case 'change_password';
if (isset($_POST['submit'])) {
	$new_password = make_safe($_POST['new_password']);
	$confirm_new_password = make_safe($_POST['confirm_new_password']);
	if (empty($new_password)) {
		$message = notification('warning',"$language[insert_password]");
	} elseif (mb_strlen($new_password,'UTF-8') < 6) {
		$message = notification('warning',"$language[password_min_max]");
	} elseif (empty($confirm_new_password)) {
		$message = notification('warning',"$language[insert_password_confirm]");
	} elseif ($new_password != $confirm_new_password) {
		$message = notification('warning',"$language[password_no_match]");
	} else {
	$encoded_password = hash('sha256', md5($new_password));
	$activation_code = genRandomString(24);	
	$update = $mysqli->query("UPDATE users SET password='$encoded_password' WHERE id='$_SESSION[media_cms_user]'");
	if ($update) {
		$message = notification('success',"$language[password_success_changed]");	
	} else {
		$message = notification('danger',"$language[error_happened]");	
	}
	}
$smarty->assign('message',$message);	
}
$smarty->assign('seo_title',$language['change_password'].' - '.$options['general_seo_title']);
$smarty->assign('seo_keywords',$options['general_seo_keywords']);
$smarty->assign('seo_description',$options['general_seo_description']);
$smarty->display('change-password.html');
break;
default;
die('You Can\'t Access This Page.');	
}
?>