<?php
namespace PHPMaker2020\hostelmgr20;

// Session
if (session_status() !== PHP_SESSION_ACTIVE)
	session_start(); // Init session data

// Output buffering
ob_start();

// Autoload
include_once "autoload.php";
?>
<?php

// Write header
WriteHeader(FALSE);

// Create page object
$staff_add = new staff_add();

// Run the page
$staff_add->run();

// Setup login status
SetupLoginStatus();
SetClientVar("login", LoginStatus());

// Global Page Rendering event (in userfn*.php)
Page_Rendering();

// Page Rendering event
$staff_add->Page_Render();
?>
<?php include_once "header.php"; ?>
<script>
var fstaffadd, currentPageID;
loadjs.ready("head", function() {

	// Form object
	currentPageID = ew.PAGE_ID = "add";
	fstaffadd = currentForm = new ew.Form("fstaffadd", "add");

	// Validate form
	fstaffadd.validate = function() {
		if (!this.validateRequired)
			return true; // Ignore validation
		var $ = jQuery, fobj = this.getForm(), $fobj = $(fobj);
		if ($fobj.find("#confirm").val() == "F")
			return true;
		var elm, felm, uelm, addcnt = 0;
		var $k = $fobj.find("#" + this.formKeyCountName); // Get key_count
		var rowcnt = ($k[0]) ? parseInt($k.val(), 10) : 1;
		var startcnt = (rowcnt == 0) ? 0 : 1; // Check rowcnt == 0 => Inline-Add
		var gridinsert = ["insert", "gridinsert"].includes($fobj.find("#action").val()) && $k[0];
		for (var i = startcnt; i <= rowcnt; i++) {
			var infix = ($k[0]) ? String(i) : "";
			$fobj.data("rowindex", infix);
			<?php if ($staff_add->Staff_Name->Required) { ?>
				elm = this.getElements("x" + infix + "_Staff_Name");
				if (elm && !ew.isHidden(elm) && !ew.hasValue(elm))
					return this.onError(elm, "<?php echo JsEncode(str_replace("%s", $staff_add->Staff_Name->caption(), $staff_add->Staff_Name->RequiredErrorMessage)) ?>");
			<?php } ?>
			<?php if ($staff_add->ContactNo->Required) { ?>
				elm = this.getElements("x" + infix + "_ContactNo");
				if (elm && !ew.isHidden(elm) && !ew.hasValue(elm))
					return this.onError(elm, "<?php echo JsEncode(str_replace("%s", $staff_add->ContactNo->caption(), $staff_add->ContactNo->RequiredErrorMessage)) ?>");
			<?php } ?>
				elm = this.getElements("x" + infix + "_ContactNo");
				if (elm && !ew.checkInteger(elm.value))
					return this.onError(elm, "<?php echo JsEncode($staff_add->ContactNo->errorMessage()) ?>");
			<?php if ($staff_add->_email->Required) { ?>
				elm = this.getElements("x" + infix + "__email");
				if (elm && !ew.isHidden(elm) && !ew.hasValue(elm))
					return this.onError(elm, "<?php echo JsEncode(str_replace("%s", $staff_add->_email->caption(), $staff_add->_email->RequiredErrorMessage)) ?>");
			<?php } ?>
			<?php if ($staff_add->password->Required) { ?>
				elm = this.getElements("x" + infix + "_password");
				if (elm && !ew.isHidden(elm) && !ew.hasValue(elm))
					return this.onError(elm, "<?php echo JsEncode(str_replace("%s", $staff_add->password->caption(), $staff_add->password->RequiredErrorMessage)) ?>");
			<?php } ?>
			<?php if ($staff_add->userlevel->Required) { ?>
				elm = this.getElements("x" + infix + "_userlevel");
				if (elm && !ew.isHidden(elm) && !ew.hasValue(elm))
					return this.onError(elm, "<?php echo JsEncode(str_replace("%s", $staff_add->userlevel->caption(), $staff_add->userlevel->RequiredErrorMessage)) ?>");
			<?php } ?>
			<?php if ($staff_add->profile->Required) { ?>
				elm = this.getElements("x" + infix + "_profile");
				if (elm && !ew.isHidden(elm) && !ew.hasValue(elm))
					return this.onError(elm, "<?php echo JsEncode(str_replace("%s", $staff_add->profile->caption(), $staff_add->profile->RequiredErrorMessage)) ?>");
			<?php } ?>

				// Call Form_CustomValidate event
				if (!this.Form_CustomValidate(fobj))
					return false;
		}

		// Process detail forms
		var dfs = $fobj.find("input[name='detailpage']").get();
		for (var i = 0; i < dfs.length; i++) {
			var df = dfs[i], val = df.value;
			if (val && ew.forms[val])
				if (!ew.forms[val].validate())
					return false;
		}
		return true;
	}

	// Form_CustomValidate
	fstaffadd.Form_CustomValidate = function(fobj) { // DO NOT CHANGE THIS LINE!

		// Your custom validation code here, return false if invalid.
		return true;
	}

	// Use JavaScript validation or not
	fstaffadd.validateRequired = <?php echo Config("CLIENT_VALIDATE") ? "true" : "false" ?>;

	// Dynamic selection lists
	fstaffadd.lists["x_userlevel"] = <?php echo $staff_add->userlevel->Lookup->toClientList($staff_add) ?>;
	fstaffadd.lists["x_userlevel"].options = <?php echo JsonEncode($staff_add->userlevel->lookupOptions()) ?>;
	loadjs.done("fstaffadd");
});
</script>
<script>
loadjs.ready("head", function() {

	// Client script
	// Write your client script here, no need to add script tags.

});
</script>
<?php $staff_add->showPageHeader(); ?>
<?php
$staff_add->showMessage();
?>
<form name="fstaffadd" id="fstaffadd" class="<?php echo $staff_add->FormClassName ?>" action="<?php echo CurrentPageName() ?>" method="post">
<?php if ($Page->CheckToken) { ?>
<input type="hidden" name="<?php echo Config("TOKEN_NAME") ?>" value="<?php echo $Page->Token ?>">
<?php } ?>
<input type="hidden" name="t" value="staff">
<input type="hidden" name="action" id="action" value="insert">
<input type="hidden" name="modal" value="<?php echo (int)$staff_add->IsModal ?>">
<div class="ew-add-div"><!-- page* -->
<?php if ($staff_add->Staff_Name->Visible) { // Staff_Name ?>
	<div id="r_Staff_Name" class="form-group row">
		<label id="elh_staff_Staff_Name" for="x_Staff_Name" class="<?php echo $staff_add->LeftColumnClass ?>"><?php echo $staff_add->Staff_Name->caption() ?><?php echo $staff_add->Staff_Name->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $staff_add->RightColumnClass ?>"><div <?php echo $staff_add->Staff_Name->cellAttributes() ?>>
<span id="el_staff_Staff_Name">
<input type="text" data-table="staff" data-field="x_Staff_Name" name="x_Staff_Name" id="x_Staff_Name" size="30" maxlength="55" placeholder="<?php echo HtmlEncode($staff_add->Staff_Name->getPlaceHolder()) ?>" value="<?php echo $staff_add->Staff_Name->EditValue ?>"<?php echo $staff_add->Staff_Name->editAttributes() ?>>
</span>
<?php echo $staff_add->Staff_Name->CustomMsg ?></div></div>
	</div>
<?php } ?>
<?php if ($staff_add->ContactNo->Visible) { // ContactNo ?>
	<div id="r_ContactNo" class="form-group row">
		<label id="elh_staff_ContactNo" for="x_ContactNo" class="<?php echo $staff_add->LeftColumnClass ?>"><?php echo $staff_add->ContactNo->caption() ?><?php echo $staff_add->ContactNo->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $staff_add->RightColumnClass ?>"><div <?php echo $staff_add->ContactNo->cellAttributes() ?>>
<span id="el_staff_ContactNo">
<input type="text" data-table="staff" data-field="x_ContactNo" name="x_ContactNo" id="x_ContactNo" size="30" placeholder="<?php echo HtmlEncode($staff_add->ContactNo->getPlaceHolder()) ?>" value="<?php echo $staff_add->ContactNo->EditValue ?>"<?php echo $staff_add->ContactNo->editAttributes() ?>>
</span>
<?php echo $staff_add->ContactNo->CustomMsg ?></div></div>
	</div>
<?php } ?>
<?php if ($staff_add->_email->Visible) { // email ?>
	<div id="r__email" class="form-group row">
		<label id="elh_staff__email" for="x__email" class="<?php echo $staff_add->LeftColumnClass ?>"><?php echo $staff_add->_email->caption() ?><?php echo $staff_add->_email->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $staff_add->RightColumnClass ?>"><div <?php echo $staff_add->_email->cellAttributes() ?>>
<span id="el_staff__email">
<input type="text" data-table="staff" data-field="x__email" name="x__email" id="x__email" size="30" maxlength="55" placeholder="<?php echo HtmlEncode($staff_add->_email->getPlaceHolder()) ?>" value="<?php echo $staff_add->_email->EditValue ?>"<?php echo $staff_add->_email->editAttributes() ?>>
</span>
<?php echo $staff_add->_email->CustomMsg ?></div></div>
	</div>
<?php } ?>
<?php if ($staff_add->password->Visible) { // password ?>
	<div id="r_password" class="form-group row">
		<label id="elh_staff_password" for="x_password" class="<?php echo $staff_add->LeftColumnClass ?>"><?php echo $staff_add->password->caption() ?><?php echo $staff_add->password->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $staff_add->RightColumnClass ?>"><div <?php echo $staff_add->password->cellAttributes() ?>>
<span id="el_staff_password">
<input type="text" data-table="staff" data-field="x_password" name="x_password" id="x_password" size="30" maxlength="120" placeholder="<?php echo HtmlEncode($staff_add->password->getPlaceHolder()) ?>" value="<?php echo $staff_add->password->EditValue ?>"<?php echo $staff_add->password->editAttributes() ?>>
</span>
<?php echo $staff_add->password->CustomMsg ?></div></div>
	</div>
<?php } ?>
<?php if ($staff_add->userlevel->Visible) { // userlevel ?>
	<div id="r_userlevel" class="form-group row">
		<label id="elh_staff_userlevel" for="x_userlevel" class="<?php echo $staff_add->LeftColumnClass ?>"><?php echo $staff_add->userlevel->caption() ?><?php echo $staff_add->userlevel->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $staff_add->RightColumnClass ?>"><div <?php echo $staff_add->userlevel->cellAttributes() ?>>
<?php if (!$Security->isAdmin() && $Security->isLoggedIn()) { // Non system admin ?>
<span id="el_staff_userlevel">
<input type="text" readonly class="form-control-plaintext" value="<?php echo HtmlEncode(RemoveHtml($staff_add->userlevel->EditValue)) ?>">
</span>
<?php } else { ?>
<span id="el_staff_userlevel">
<div class="input-group">
	<select class="custom-select ew-custom-select" data-table="staff" data-field="x_userlevel" data-value-separator="<?php echo $staff_add->userlevel->displayValueSeparatorAttribute() ?>" id="x_userlevel" name="x_userlevel"<?php echo $staff_add->userlevel->editAttributes() ?>>
			<?php echo $staff_add->userlevel->selectOptionListHtml("x_userlevel") ?>
		</select>
</div>
<?php echo $staff_add->userlevel->Lookup->getParamTag($staff_add, "p_x_userlevel") ?>
</span>
<?php } ?>
<?php echo $staff_add->userlevel->CustomMsg ?></div></div>
	</div>
<?php } ?>
<?php if ($staff_add->profile->Visible) { // profile ?>
	<div id="r_profile" class="form-group row">
		<label id="elh_staff_profile" for="x_profile" class="<?php echo $staff_add->LeftColumnClass ?>"><?php echo $staff_add->profile->caption() ?><?php echo $staff_add->profile->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $staff_add->RightColumnClass ?>"><div <?php echo $staff_add->profile->cellAttributes() ?>>
<span id="el_staff_profile">
<input type="text" data-table="staff" data-field="x_profile" name="x_profile" id="x_profile" size="30" maxlength="250" placeholder="<?php echo HtmlEncode($staff_add->profile->getPlaceHolder()) ?>" value="<?php echo $staff_add->profile->EditValue ?>"<?php echo $staff_add->profile->editAttributes() ?>>
</span>
<?php echo $staff_add->profile->CustomMsg ?></div></div>
	</div>
<?php } ?>
</div><!-- /page* -->
<?php if (!$staff_add->IsModal) { ?>
<div class="form-group row"><!-- buttons .form-group -->
	<div class="<?php echo $staff_add->OffsetColumnClass ?>"><!-- buttons offset -->
<button class="btn btn-primary ew-btn" name="btn-action" id="btn-action" type="submit"><?php echo $Language->phrase("AddBtn") ?></button>
<button class="btn btn-default ew-btn" name="btn-cancel" id="btn-cancel" type="button" data-href="<?php echo $staff_add->getReturnUrl() ?>"><?php echo $Language->phrase("CancelBtn") ?></button>
	</div><!-- /buttons offset -->
</div><!-- /buttons .form-group -->
<?php } ?>
</form>
<?php
$staff_add->showPageFooter();
if (Config("DEBUG"))
	echo GetDebugMessage();
?>
<script>
loadjs.ready("load", function() {

	// Startup script
	// Write your table-specific startup script here
	// console.log("page loaded");

});
</script>
<?php include_once "footer.php"; ?>
<?php
$staff_add->terminate();
?>