<?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
$reswardens_add = new reswardens_add();

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

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

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

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

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

	// Validate form
	freswardensadd.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 ($reswardens_add->Hostel->Required) { ?>
				elm = this.getElements("x" + infix + "_Hostel");
				if (elm && !ew.isHidden(elm) && !ew.hasValue(elm))
					return this.onError(elm, "<?php echo JsEncode(str_replace("%s", $reswardens_add->Hostel->caption(), $reswardens_add->Hostel->RequiredErrorMessage)) ?>");
			<?php } ?>
			<?php if ($reswardens_add->Floor->Required) { ?>
				elm = this.getElements("x" + infix + "_Floor");
				if (elm && !ew.isHidden(elm) && !ew.hasValue(elm))
					return this.onError(elm, "<?php echo JsEncode(str_replace("%s", $reswardens_add->Floor->caption(), $reswardens_add->Floor->RequiredErrorMessage)) ?>");
			<?php } ?>
			<?php if ($reswardens_add->ResWarden->Required) { ?>
				elm = this.getElements("x" + infix + "_ResWarden");
				if (elm && !ew.isHidden(elm) && !ew.hasValue(elm))
					return this.onError(elm, "<?php echo JsEncode(str_replace("%s", $reswardens_add->ResWarden->caption(), $reswardens_add->ResWarden->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
	freswardensadd.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
	freswardensadd.validateRequired = <?php echo Config("CLIENT_VALIDATE") ? "true" : "false" ?>;

	// Dynamic selection lists
	freswardensadd.lists["x_Hostel"] = <?php echo $reswardens_add->Hostel->Lookup->toClientList($reswardens_add) ?>;
	freswardensadd.lists["x_Hostel"].options = <?php echo JsonEncode($reswardens_add->Hostel->lookupOptions()) ?>;
	freswardensadd.lists["x_Floor"] = <?php echo $reswardens_add->Floor->Lookup->toClientList($reswardens_add) ?>;
	freswardensadd.lists["x_Floor"].options = <?php echo JsonEncode($reswardens_add->Floor->lookupOptions()) ?>;
	freswardensadd.lists["x_ResWarden"] = <?php echo $reswardens_add->ResWarden->Lookup->toClientList($reswardens_add) ?>;
	freswardensadd.lists["x_ResWarden"].options = <?php echo JsonEncode($reswardens_add->ResWarden->lookupOptions()) ?>;
	loadjs.done("freswardensadd");
});
</script>
<script>
loadjs.ready("head", function() {

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

});
</script>
<?php $reswardens_add->showPageHeader(); ?>
<?php
$reswardens_add->showMessage();
?>
<form name="freswardensadd" id="freswardensadd" class="<?php echo $reswardens_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="reswardens">
<input type="hidden" name="action" id="action" value="insert">
<input type="hidden" name="modal" value="<?php echo (int)$reswardens_add->IsModal ?>">
<div class="ew-add-div"><!-- page* -->
<?php if ($reswardens_add->Hostel->Visible) { // Hostel ?>
	<div id="r_Hostel" class="form-group row">
		<label id="elh_reswardens_Hostel" for="x_Hostel" class="<?php echo $reswardens_add->LeftColumnClass ?>"><?php echo $reswardens_add->Hostel->caption() ?><?php echo $reswardens_add->Hostel->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $reswardens_add->RightColumnClass ?>"><div <?php echo $reswardens_add->Hostel->cellAttributes() ?>>
<span id="el_reswardens_Hostel">
<?php $reswardens_add->Hostel->EditAttrs->prepend("onchange", "ew.updateOptions.call(this);"); ?>
<div class="input-group">
	<select class="custom-select ew-custom-select" data-table="reswardens" data-field="x_Hostel" data-value-separator="<?php echo $reswardens_add->Hostel->displayValueSeparatorAttribute() ?>" id="x_Hostel" name="x_Hostel"<?php echo $reswardens_add->Hostel->editAttributes() ?>>
			<?php echo $reswardens_add->Hostel->selectOptionListHtml("x_Hostel") ?>
		</select>
</div>
<?php echo $reswardens_add->Hostel->Lookup->getParamTag($reswardens_add, "p_x_Hostel") ?>
</span>
<?php echo $reswardens_add->Hostel->CustomMsg ?></div></div>
	</div>
<?php } ?>
<?php if ($reswardens_add->Floor->Visible) { // Floor ?>
	<div id="r_Floor" class="form-group row">
		<label id="elh_reswardens_Floor" for="x_Floor" class="<?php echo $reswardens_add->LeftColumnClass ?>"><?php echo $reswardens_add->Floor->caption() ?><?php echo $reswardens_add->Floor->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $reswardens_add->RightColumnClass ?>"><div <?php echo $reswardens_add->Floor->cellAttributes() ?>>
<span id="el_reswardens_Floor">
<div class="input-group">
	<select class="custom-select ew-custom-select" data-table="reswardens" data-field="x_Floor" data-value-separator="<?php echo $reswardens_add->Floor->displayValueSeparatorAttribute() ?>" id="x_Floor" name="x_Floor"<?php echo $reswardens_add->Floor->editAttributes() ?>>
			<?php echo $reswardens_add->Floor->selectOptionListHtml("x_Floor") ?>
		</select>
</div>
<?php echo $reswardens_add->Floor->Lookup->getParamTag($reswardens_add, "p_x_Floor") ?>
</span>
<?php echo $reswardens_add->Floor->CustomMsg ?></div></div>
	</div>
<?php } ?>
<?php if ($reswardens_add->ResWarden->Visible) { // ResWarden ?>
	<div id="r_ResWarden" class="form-group row">
		<label id="elh_reswardens_ResWarden" for="x_ResWarden" class="<?php echo $reswardens_add->LeftColumnClass ?>"><?php echo $reswardens_add->ResWarden->caption() ?><?php echo $reswardens_add->ResWarden->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
		<div class="<?php echo $reswardens_add->RightColumnClass ?>"><div <?php echo $reswardens_add->ResWarden->cellAttributes() ?>>
<span id="el_reswardens_ResWarden">
<div class="input-group">
	<select class="custom-select ew-custom-select" data-table="reswardens" data-field="x_ResWarden" data-value-separator="<?php echo $reswardens_add->ResWarden->displayValueSeparatorAttribute() ?>" id="x_ResWarden" name="x_ResWarden"<?php echo $reswardens_add->ResWarden->editAttributes() ?>>
			<?php echo $reswardens_add->ResWarden->selectOptionListHtml("x_ResWarden") ?>
		</select>
</div>
<?php echo $reswardens_add->ResWarden->Lookup->getParamTag($reswardens_add, "p_x_ResWarden") ?>
</span>
<?php echo $reswardens_add->ResWarden->CustomMsg ?></div></div>
	</div>
<?php } ?>
</div><!-- /page* -->
<?php if (!$reswardens_add->IsModal) { ?>
<div class="form-group row"><!-- buttons .form-group -->
	<div class="<?php echo $reswardens_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 $reswardens_add->getReturnUrl() ?>"><?php echo $Language->phrase("CancelBtn") ?></button>
	</div><!-- /buttons offset -->
</div><!-- /buttons .form-group -->
<?php } ?>
</form>
<?php
$reswardens_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
$reswardens_add->terminate();
?>