<?php
/**
 * WebEngine CMS
 * https://webenginecms.org/
 * 
 * @version 1.2.5
 * @author Gabo Development <https://gabodevelop.com/>
 * @copyright (c) 2026 Gabriel Development, All Rights Reserved
 * 
 * Licensed under the MIT license
 * http://opensource.org/licenses/MIT
 */

if(!isLoggedIn()) redirect(1,'login');

$pageTitle = lang('module_titles_txt_5',true) ?: 'Change Email';

try {
	if(!mconfig('active')) throw new Exception(lang('error_47',true));
	if(isset($_POST['webengineEmail_submit'])) {
		try {
			$Account = new Account();
			$Account->changeEmailAddress($_SESSION['userid'], $_POST['webengineEmail_newemail'], $_SERVER['REMOTE_ADDR']);
			if(mconfig('require_verification')) message('success', lang('success_19',true));
			else message('success', lang('success_20',true));
		} catch (Exception $ex) {
			message('error', $ex->getMessage());
		}
	}
	echo '<div class="nexora-usercp-page">';
	echo '<header class="nexora-usercp-page-header"><h1 class="nexora-usercp-page-title">'.htmlspecialchars($pageTitle).'</h1></header>';
	echo '<div class="nexora-usercp-panel"><div class="nexora-usercp-panel-body">';
	echo '<form class="nexora-usercp-form" action="" method="post">';
	echo '<div class="nexora-usercp-field"><label class="nexora-usercp-label" for="webengineEmail">'.lang('changemail_txt_1',true).'</label><input type="text" class="nexora-usercp-input" id="webengineEmail" name="webengineEmail_newemail" required></div>';
	echo '<div class="nexora-usercp-field"><button type="submit" name="webengineEmail_submit" value="submit" class="nexora-usercp-btn">'.lang('changemail_txt_1',true).'</button></div>';
	echo '</form></div></div></div>';
} catch(Exception $ex) {
	message('error', $ex->getMessage());
}