<?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_edit = new staff_edit();

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

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

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

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

	// Form object
	currentPageID = ew.PAGE_ID = "edit";
	fstaffedit = currentForm = new ew.Form("fstaffedit", "edit");

	// Validate form
	fstaffedit.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_edit->id->Required) { ?>
				elm = this.getElements("x" + infix + "_id");
				if (elm && !ew.isHidden(elm) && !ew.hasValue(elm))
					return this.onError(elm, "<?php echo JsEncode(str_replace("%s", $staff_edit->id->caption(), $staff_edit->id->RequiredErrorMessage)) ?>");
			<?php } ?>
			<?php if ($staff_edit->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_edit->Staff_Name->caption(), $staff_edit->Staff_Name->RequiredErrorMessage)) ?>");
			<?php } ?>
			<?php if ($staff_edit->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_edit->ContactNo->caption(), $staff_edit->ContactNo->RequiredErrorMessage)) ?>");
			<?php } ?>
				elm = this.getElements("x" + infix + "_ContactNo");
				if (elm && !ew.checkInteger(elm.value))
					return this.onError(elm, "<?php echo JsEncode($staff_edit->ContactNo->errorMessage()) ?>");
			<?php if ($staff_edit->_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_edit->_email->caption(), $staff_edit->_email->RequiredErrorMessage)) ?>");
			<?php } ?>
			<?php if ($staff_edit->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_edit->password->caption(), $staff_edit->password->RequiredErrorMessage)) ?>");
			<?php } ?>
			<?php if ($staff_edit->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_edit->userlevel->caption(), $staff_edit->userlevel->RequiredErrorMessage)) ?>");
			<?php } ?>
			<?php if ($staff_edit->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_edit->profile->caption(), $staff_edit->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
	fstaffedit.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
	fstaffedit.validateRequired = <?php echo Config("CLIENT_VALIDATE") ? "true" : "false" ?>;

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

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

});
</script>
<?php $staff_edit->showPageHeader(); ?>
<?php
$staff_edit->showMessage();
?>
<form name="fstaffedit" id="fstaffedit" class="<?php echo $staff_edit->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="update">
<input type="hidden" name="modal" value="<?php echo (int)$staff_edit->IsModal ?>">
<div class="ew-edit-div"><!-- page* -->
<?php if ($staff_edit->id->Visible) { // id ?>
	<div id="r_id" class="form-group row">
		<label id="elh_staff_id" class="<?php echo $staff_edit->LeftColumnClass ?>"><?php echo $staff_edit->id->caption() ?><?php echo $staff_edit->id->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $staff_edit->RightColumnClass ?>"><div <?php echo $staff_edit->id->cellAttributes() ?>>
<span id="el_staff_id">
<span<?php echo $staff_edit->id->viewAttributes() ?>><input type="text" readonly class="form-control-plaintext" value="<?php echo HtmlEncode(RemoveHtml($staff_edit->id->EditValue)) ?>"></span>
</span>
<input type="hidden" data-table="staff" data-field="x_id" name="x_id" id="x_id" value="<?php echo HtmlEncode($staff_edit->id->CurrentValue) ?>">
<?php echo $staff_edit->id->CustomMsg ?></div></div>
	</div>
<?php } ?>
<?php if ($staff_edit->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_edit->LeftColumnClass ?>"><?php echo $staff_edit->Staff_Name->caption() ?><?php echo $staff_edit->Staff_Name->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $staff_edit->RightColumnClass ?>"><div <?php echo $staff_edit->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_edit->Staff_Name->getPlaceHolder()) ?>" value="<?php echo $staff_edit->Staff_Name->EditValue ?>"<?php echo $staff_edit->Staff_Name->editAttributes() ?>>
</span>
<?php echo $staff_edit->Staff_Name->CustomMsg ?></div></div>
	</div>
<?php } ?>
<?php if ($staff_edit->ContactNo->Visible) { // ContactNo ?>
	<div id="r_ContactNo" class="form-group row">
		<label id="elh_staff_ContactNo" for="x_ContactNo" class="<?php echo $staff_edit->LeftColumnClass ?>"><?php echo $staff_edit->ContactNo->caption() ?><?php echo $staff_edit->ContactNo->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $staff_edit->RightColumnClass ?>"><div <?php echo $staff_edit->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_edit->ContactNo->getPlaceHolder()) ?>" value="<?php echo $staff_edit->ContactNo->EditValue ?>"<?php echo $staff_edit->ContactNo->editAttributes() ?>>
</span>
<?php echo $staff_edit->ContactNo->CustomMsg ?></div></div>
	</div>
<?php } ?>
<?php if ($staff_edit->_email->Visible) { // email ?>
	<div id="r__email" class="form-group row">
		<label id="elh_staff__email" for="x__email" class="<?php echo $staff_edit->LeftColumnClass ?>"><?php echo $staff_edit->_email->caption() ?><?php echo $staff_edit->_email->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $staff_edit->RightColumnClass ?>"><div <?php echo $staff_edit->_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_edit->_email->getPlaceHolder()) ?>" value="<?php echo $staff_edit->_email->EditValue ?>"<?php echo $staff_edit->_email->editAttributes() ?>>
</span>
<?php echo $staff_edit->_email->CustomMsg ?></div></div>
	</div>
<?php } ?>
<?php if ($staff_edit->password->Visible) { // password ?>
	<div id="r_password" class="form-group row">
		<label id="elh_staff_password" for="x_password" class="<?php echo $staff_edit->LeftColumnClass ?>"><?php echo $staff_edit->password->caption() ?><?php echo $staff_edit->password->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $staff_edit->RightColumnClass ?>"><div <?php echo $staff_edit->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_edit->password->getPlaceHolder()) ?>" value="<?php echo $staff_edit->password->EditValue ?>"<?php echo $staff_edit->password->editAttributes() ?>>
</span>
<?php echo $staff_edit->password->CustomMsg ?></div></div>
	</div>
<?php } ?>
<?php if ($staff_edit->userlevel->Visible) { // userlevel ?>
	<div id="r_userlevel" class="form-group row">
		<label id="elh_staff_userlevel" for="x_userlevel" class="<?php echo $staff_edit->LeftColumnClass ?>"><?php echo $staff_edit->userlevel->caption() ?><?php echo $staff_edit->userlevel->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $staff_edit->RightColumnClass ?>"><div <?php echo $staff_edit->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_edit->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_edit->userlevel->displayValueSeparatorAttribute() ?>" id="x_userlevel" name="x_userlevel"<?php echo $staff_edit->userlevel->editAttributes() ?>>
			<?php echo $staff_edit->userlevel->selectOptionListHtml("x_userlevel") ?>
		</select>
</div>
<?php echo $staff_edit->userlevel->Lookup->getParamTag($staff_edit, "p_x_userlevel") ?>
</span>
<?php } ?>
<?php echo $staff_edit->userlevel->CustomMsg ?></div></div>
	</div>
<?php } ?>
<?php if ($staff_edit->profile->Visible) { // profile ?>
	<div id="r_profile" class="form-group row">
		<label id="elh_staff_profile" for="x_profile" class="<?php echo $staff_edit->LeftColumnClass ?>"><?php echo $staff_edit->profile->caption() ?><?php echo $staff_edit->profile->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $staff_edit->RightColumnClass ?>"><div <?php echo $staff_edit->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_edit->profile->getPlaceHolder()) ?>" value="<?php echo $staff_edit->profile->EditValue ?>"<?php echo $staff_edit->profile->editAttributes() ?>>
</span>
<?php echo $staff_edit->profile->CustomMsg ?></div></div>
	</div>
<?php } ?>
</div><!-- /page* -->
<?php if (!$staff_edit->IsModal) { ?>
<div class="form-group row"><!-- buttons .form-group -->
	<div class="<?php echo $staff_edit->OffsetColumnClass ?>"><!-- buttons offset -->
<button class="btn btn-primary ew-btn" name="btn-action" id="btn-action" type="submit"><?php echo $Language->phrase("SaveBtn") ?></button>
<button class="btn btn-default ew-btn" name="btn-cancel" id="btn-cancel" type="button" data-href="<?php echo $staff_edit->getReturnUrl() ?>"><?php echo $Language->phrase("CancelBtn") ?></button>
	</div><!-- /buttons offset -->
</div><!-- /buttons .form-group -->
<?php } ?>
</form>
<?php
$staff_edit->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_edit->terminate();
?>