<?php
if (!defined('USING_SYSTEM')) exit;

class p201_sxExe extends xIExecutor {
	
	public function main() {
		global $_APP;
		$mysql = xGbl::$mysql;
		$tips = '';
		if(isset($_POST['usernameTxt'])) {
			$username = trim($_POST['usernameTxt']);
			$password = trim($_POST['passwordTxt']);
			$email = trim($_POST['emailTxt']);
			if($username!='' && $password!='' && $email!='') {
				try {
					$user = xUser::creat($username, $password, $email);
					$user->class = $_POST['groupTxt'];
					$user->update();
					// --- AppData ---
					$rootFolder = new xFolder(0, $user);
					xFolder::create('AppData', $user, $rootFolder);
					$tips = '添加成功，ID 为 '.$user->id;
				} catch(xError $e) {
					if($e->getCode() == xError::ERR_DUP) {
						$tips = '添加失败，用户名已存在';
					} else if($e->getCode() == xUser::ERR_BAD_EMAIL) {
						$tips = '添加失败，无效的邮箱地址';
					} else if($e->getCode() == xUser::ERR_BAD_USERNAME) {
						$tips = '添加失败，用户名禁止含有特殊字符';
					}
				}
			} else {
				$tips = '添加失败，用户名、邮箱与密码都不可为空';
			}
		}
		$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
		include_once(__ROOT__.'admin/ui.p201.php');
	}
	
	public function onError($result) {
		
	}
	
}
