File: D:/web/secure/itpplates/admin/2022-04-05/prev/inc-template-main.asp
<!--#include file="inc-main.asp"--><!DOCTYPE html><%
' Notes
' =====
' (SS,24/07/20) Started on this ITP Plates web-based licence manager (Bootstrap 4 based)
' (SS,28/05/21) modified to allow expiry date to be set and also new edit modal
%>
<html lang="en">
<head><%HTMLHeadStart%>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<title>ITP Plates Licence Manager</title>
<script src="js/javascript.js?v=2"></script>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
<link rel="stylesheet" href="css/styles.css">
<!-- Custom styles for this template -->
<%If Not IsAuthenticated Then%>
<link href="css/signin.css" rel="stylesheet">
<%End If%>
<script src="js/jquery-3.4.1.min.js"></script>
<%HTMLHeadEnd%>
</head>
<body onload="itp_onload()">
<%
If Not IsAuthenticated Then
ShowSignIn
Else
ShowMain
End If
%>
<%Finalise%>
<script src="js/bootstrap.bundle.min.js"></script>
</body>
</html>
<%
Sub ShowMain
%>
<!--#include file="inc-template-menu.asp"-->
<!-- START OF MAIN BODY -->
<div class="container-fluid">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 mb-3">
<%
DoOperation
ShowLicences
ShowCreateNewLicenceButton
%>
</div><!--col-->
</div><!--row-->
</div><!--container-->
<footer class="footer">
<div class="container">
<span class="text-muted">© 2020 IT Partnership</span>
</div>
</footer>
<!-- END OF MAIN BODY -->
<%
End Sub
Sub ShowSignIn
%>
<form class="form-signin text-center" method="post" action="">
<!--
<div class="mb-3 pt-1 pb-1" style="background-color:white">
<img src="images/ITPPlatesV1.png" alt="" >
</div>
-->
<img class="mb-4 p-1 border" src="images/logo.gif" alt="" >
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus name="Email">
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required name="Password">
<!--
<div class="checkbox mb-3">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
-->
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
<p class="mt-5 mb-3 text-muted">© 2020 IT Partnership</p>
</form>
<%
End Sub
' (SS,28/5/21) added columns for showing disabled and Edit button (no heading)
Sub ShowLicencesHeader
%>
<h2 class="mt-3">Licences</h2>
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th>Company</th>
<th class="text-center">RNPS</th>
<th>Licence Key</th>
<th class="text-center"></th>
<th class="text-center"></th>
<th class="text-center">Expiry</th>
<th class="text-center"></th>
<th class="text-center">Days Left</th>
<th>Computer Name</th>
<th class="text-center">Last Print</th>
<th class="text-center">Print Count</th>
<th class="text-center">Weekly Prints</th>
</tr>
</thead>
<tbody>
<%
End Sub
Sub ShowLicencesRowStart
%>
<tr>
<%
End Sub
Sub ShowLicencesRowField(AFieldName, AAlign)
Dim LClass, LValue
' if Renew then show renewal button
If AFieldName = "Renew" Then
Response.Write "<td>"
If GetFieldValue("DaysLeft") <= 30 Then
'LValue = "<button type=""button"" class=""btn btn-success btn-sm"">Renew</button>"
ShowRenewLicenceButton GetFieldValue("LicenceID"), GetFieldValue("CompanyName")
End If
Response.Write "</td>"
ElseIf AFieldName = "Enabled" Then
Response.Write "<td>"
If GetFieldValue("Enabled") <> "1" Then
Response.Write "<span class=""text-danger"">disabled</span>"
End If
Response.Write "</td>"
' (SS,28/5/21)
ElseIf AFieldName = "Edit" Then
Response.Write "<td>"
ShowEditLicenceButton GetFieldValue("LicenceID"), GetFieldValue("CompanyName"), GetFieldValue("LicenceKey"), ISODate(GetFieldValue("ExpiryDate")), GetFieldValue("Enabled"), GetFieldValue("ComputerName")
Response.Write "</td>"
Else
LValue = GetFieldValue(AFieldName)
If AALign = "C" Then
LClass = " class=""text-center"""
ElseIf AALign = "R" Then
LClass = " class=""text-right"""
Else
LClass = ""
End If
If AFieldName = "LicenceKey" Or AFieldName = "ComputerName" Then
LValue = "<small>" & LValue & "</small>"
End If
%>
<td<%=LClass%>><%=LValue%></td>
<%
End If
End Sub
Sub ShowLicencesRowEnd
%>
</tr>
<%
End Sub
Sub ShowLicencesFooter
%>
</tbody>
</table>
</div>
<%
End Sub
Sub ShowCreateNewLicenceButton
%>
<!-- Button trigger modal -->
<button type="button" class="btn btn-lg btn-bd-primary mb-3 mr-md-3" data-toggle="modal" data-target="#NewLicenceModal">
Create new licence
</button>
<!-- Modal -->
<div class="modal fade" id="NewLicenceModal" tabindex="-1" role="dialog" aria-labelledby="NewLicenceModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<form id="frmModalCreate" name="frmModalCreate" class="form-createlicence text-center" method="post" action="">
<div class="modal-header">
<h5 class="modal-title" id="NewLicenceModalLabel">Create New Licence</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<label for="CompanyName" class="sr-only">Company name</label>
<input type="text" id="CompanyName" class="form-control" placeholder="Company name" required autofocus name="CompanyName">
<%ShowExpiryDateControl("C")%>
<input type="hidden" name="cmd" value="">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-bd-primary" onclick="itp_create_licence()">Create licence</button>
</div>
</form>
</div>
</div>
</div>
<!-- Modal for renewals -->
<div class="modal fade" id="RenewLicenceModal" tabindex="-1" role="dialog" aria-labelledby="RenewLicenceModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<form id="frmModalRenew" name="frmModalRenew" class="form-newlicence text-center" method="post" action="">
<div class="modal-header">
<h5 class="modal-title" id="RenewLicenceModalLabel">Renew Licence</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<label for="CompanyName" class="sr-only">Company name</label>
<input type="text" id="CompanyNameRenew" class="form-control" disabled autofocus name="CompanyName">
<%ShowExpiryDateControl("R")%>
<input type="hidden" name="cmd" value="">
<input type="hidden" name="LicenceID" value="">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-bd-primary" onclick="itp_renew_licence()">Renew licence</button>
</div>
</form>
</div>
</div>
</div>
<!-- Modal for edits -->
<div class="modal fade" id="EditLicenceModal" tabindex="-1" role="dialog" aria-labelledby="EditLicenceModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<form id="frmModalEdit" name="frmModalEdit" class="form-newlicence" method="post" action="">
<div class="modal-header">
<h5 class="modal-title" id="EditLicenceModalLabel">Edit Licence</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="CompanyName">Company name</label>
<input type="text" id="CompanyName" class="form-control" disabled autofocus name="CompanyName">
</div>
<div class="form-group">
<label for="LicenceKey">Licence key</label>
<input type="text" id="LicenceKey" class="form-control" disabled autofocus name="LicenceKey">
</div>
<div class="form-group">
<label for="ComputerName">Computer name</label>
<input type="text" id="ComputerName" class="form-control" disabled autofocus name="ComputerName">
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="LicenceEnabled" name="LicenceEnabled" value="yes">
<label class="form-check-label" for="LicenceEnabled">Licence enabled</label>
</div>
<div class="form-check mt-2">
<input type="checkbox" class="form-check-input" id="ClearComputerName" name="ClearComputerName" value="yes">
<label class="form-check-label" for="ClearComputerName">Clear computer name</label>
</div>
<%ShowExpiryDateControl("E")%>
<input type="hidden" name="cmd" value="">
<input type="hidden" name="LicenceID" value="">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-bd-primary" onclick="itp_edit_licence()">Save changes</button>
</div>
</form>
</div>
</div>
</div>
<%
' ***
ShowDaysDiffScript
End Sub
Sub ShowRenewLicenceButton(ALicenceID, ACompanyName)
%>
<!-- Button trigger modal for renewals -->
<button type="button" class="btn btn-success btn-sm" onclick="itp_renew_licence_modal('<%=ALicenceID%>', '<%=ACompanyName%>')">Renew</button>
<%
End Sub
' (SS,28/5/21)
Sub ShowEditLicenceButton(ALicenceID, ACompanyName, ALicenceKey, AExpiryDate, AEnabled, AComputerName)
%>
<!-- Button trigger modal for renewals -->
<button type="button" class="btn btn-primary btn-sm" onclick="itp_edit_licence_modal('<%=ALicenceID%>', '<%=ACompanyName%>', '<%=ALicenceKey%>', '<%=AExpiryDate%>', '<%=AEnabled%>', '<%=AComputerName%>')">Edit</button>
<%
End Sub
' (SS,27/5/21) AType can be "C" for Create, "R" for Renew or "E" for Edit
Sub ShowExpiryDateControl(AType)
If AllowExpiryDateEntry Then
Dim LFormID
If AType = "R" Then
LFormID = "frmModalRenew"
ElseIf AType = "E" Then
LFormID = "frmModalEdit"
Else ' i.e. "C"
LFormID = "frmModalCreate"
End If
%>
<div class="text-left mt-2">
<label for="ExpiryDate" class="text-left">Expiry date:
<input type="date" id="ExpiryDate" class="form-control" name="ExpiryDate" value="<%=GetDefaultExpiryDate%>" min="<%=GetMinExpiryDate%>" max="<%=GetMaxExpiryDate%>" onChange="itpRefreshValidDays('<%=LFormID%>')">
</label>
<div id="validdays"><span>Valid for x days</span></div>
</div>
<%
End If
End Sub
Sub ShowDaysDiffScript
' getNumberOfDays from https://stackabuse.com/javascript-get-number-of-days-between-dates/
' ready required to call itpRefreshValidDays when loaded
%>
<script>
$( document ).ready(function() {
itpRefreshValidDays('frmModalCreate');
itpRefreshValidDays('frmModalRenew');
});
function itpRefreshValidDays(AFormID) {
// get expiry date from input
var LExpiryDate = $("#" + AFormID + " input[name=ExpiryDate]").val();
// get today's date
var LDate = new Date();
var LToday = LDate.getFullYear() + '-' + (LDate.getMonth() + 1) + '-' + LDate.getDate();
// get the number of days
var LDays = getNumberOfDays(LToday, LExpiryDate)
// show the days
$("#" + AFormID + " #validdays span").text('Valid for ' + LDays + ' days');
}
function getNumberOfDays(start, end) {
const date1 = new Date(start);
const date2 = new Date(end);
// One day in milliseconds
const oneDay = 1000 * 60 * 60 * 24;
// Calculating the time difference between two dates
const diffInTime = date2.getTime() - date1.getTime();
// Calculating the no. of days between two dates
const diffInDays = Math.round(diffInTime / oneDay);
return diffInDays;
}
</script>
<%
End Sub
%>