bst/webapp/index.php
2023-10-31 00:21:50 -04:00

333 lines
10 KiB
PHP

<?php
require("system.inc.php");
require_once("mocha/system.inc.php");
require_once("fx/system.inc.php");
require_once("bst/BSTApplication.inc.php");
use Mocha\Core\InstanceReference;
use Mocha\UI\DisplayOption;
use Mocha\UI\ElementContent;
use MBS\Web\WebApplication;
use MBS\Web\WebPage;
// valerie - schouvm / testing
$app = new BSTApplication(get_virtual_path_root(__FILE__));
//$wp = new WebPage("");
//$wp->MasterPage = $mpDefault;
$app->Pages[] = new WebPage("", function()
{
$oms = getOMS();
$tenant = $oms->getTenantInstance();
$current_user_title = WebApplication::$Current->Variables["current_user_title"];
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo($oms->getAttributeValue($tenant, $oms->getInstanceByGlobalIdentifier('9153A637992E4712ADF2B03F0D9EDEA6'))); ?></title>
<link rel="manifest" href="manifest.json" />
<link rel="stylesheet" type="text/css" href="style/main.css?v=202310280055" />
<link rel="shortcut icon" href="images/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="HandheldFriendly" content="true" />
<script type="text/javascript" src="scripts/System.js"></script>
<script type="text/javascript" src="scripts/bst.js"></script>
<script type="text/javascript" src="scripts/controls/CheckBox.js"></script>
</head>
<body class="uwt-layout uwt-layout-box uwt-orientation-vertical">
<div class="uwt-header uwt-layout uwt-layout-box uwt-orientation-horizontal">
<label>Welcome, <?php echo($current_user_title); ?>!</label>
<div class="uwt-pack-end">
<a href="/bst"><i class="fa fa-refresh"></i><span class="uwt-title">Refresh</span></a>
<a href="logout.php"><i class="fa fa-person-to-door"></i><span class="uwt-title">Log Out</span></a>
</div>
</div>
<form method="POST">
<div class="uwt-layout uwt-layout-box uwt-orientation-horizontal">
<?php
$dt = new DateTimeImmutable();
$dtend = $dt->add(new DateInterval("PT1H"));
$current_user_id = WebApplication::$Current->Variables["current_user_id"];
if (user_has_permission($current_user_id, 3))
{
?>
<div class="uwt-panel uwt-mobile-overlay" id="add_event_panel">
<div class="uwt-content">
<h1>Add a new event</h1>
<p>
Please specify where each kid is staying. If you will not need a babysitter, please select 'Home'.
</p>
<table class="uwt-formview">
<?php
// get the kids
$kids = sqlexec("SELECT * FROM bst_kids");
$locs = sqlexec("SELECT * FROM bst_locations");
foreach ($kids as $kid)
{
?>
<tr>
<td><?php echo($kid["name"]); ?></td>
<td>
<select id="kid_<?php echo($kid["id"]); ?>_location" name="kid_<?php echo($kid["id"]); ?>_location"><?php
foreach ($locs as $loc)
{
?><option value="<?php echo($loc["id"]); ?>"><?php echo($loc["name"]); ?></option><?php
}
?>
</select>
</td>
</tr>
<?php
}
?>
<tr>
<td>
Start moment:
</td>
<td>
<input type="date" value="<?php echo ($dt->format("Y-m-d")); /*echo ($dt->format("l, F d Y")); */?>" />
<input type="time" value="<?php echo ($dt->format("H:i:s")); ?>" />
</td>
</tr>
<tr>
<td>
<input id="end_moment_valid" type="checkbox" name="end_moment_valid" /><label style="vertical-align: middle" for="end_moment_valid">End moment:</label>
</td>
<td>
<input id="end_moment_date" name="end_moment_date" disabled="disabled" type="date" value="<?php echo ($dt->format("Y-m-d")); /*echo ($dt->format("l, F d Y")); */?>" />
<input id="end_moment_time" name="end_moment_time" disabled="disabled" type="time" value="<?php echo ($dt->format("H:i:s")); ?>" />
</td>
</tr>
<tr>
<td>
Event comment (optional):
</td>
<td>
<input type="text" name="comment" />
</td>
</tr>
</table>
</div>
<div class="uwt-footer">
<button class="uwt-button uwt-color-primary" name="submit_action" value="add_event">Add Event</button>
<button id="add_event_cancel_mobile_button" class="uwt-button uwt-mobile-only">Cancel</button>
</div>
</div>
<?php
}
if (user_has_permission($current_user_id, 2))
{
?>
<div class="uwt-panel uwt-expand">
<div class="uwt-content">
<h1>Previous events</h1>
<?php
$__DO_Mobile_Hidden = new InstanceReference();
$__DO_Mobile_Only = new InstanceReference();
$elements = array
(
new ElementContent("These are the events that are currently in progress. To end an event and calculate the final payment, click 'End Event Now'.",
array($__DO_Mobile_Only)),
new ElementContent("These are the events that are currently in progress. To view more details, tap on the event.",
array($__DO_Mobile_Hidden))
);
foreach ($elements as $elem)
{
$classList = "";
$displayOptions = $elem->getDisplayOptions();
if ($displayOptions !== null)
{
if ($displayOptions->contains($__DO_Mobile_Only))
{
$classList = "uwt-mobile-hidden";
}
else if ($displayOptions->contains($__DO_Mobile_Hidden))
{
$classList = "uwt-mobile-only";
}
}
?>
<p class="<?php echo($classList); ?>">
<?php
echo($elem->getText());
?>
</p>
<?php
}
?>
<ul class="uwt-mobile-only uwt-listbox"><?php
$bses = sqlexec("SELECT *, TIMEDIFF(end_datetime, start_datetime) AS diff_datetime, TIMESTAMPDIFF(second, start_datetime, end_datetime) AS diff_timestamp FROM bst_events");
if (count($bses) > 0)
{
foreach ($bses as $bs)
{
$event_id = $bs["id"];
$start_datetime = $bs["start_datetime"];
$end_datetime = $bs["end_datetime"];
$diff_datetime = $bs["diff_datetime"];
$diff_timestamp = $bs["diff_timestamp"];
$comment = $bs["comment"];
?>
<li>
<div class="uwt-title"><?php echo($comment);
if ($end_datetime === null)
{
?><span style="font-weight: normal; padding-left: 32px; color: var(--uwt-color-warning);">In progress</span><?php
}
else
{
?><span style="font-weight: normal; padding-left: 32px; color: var(--uwt-color-success);">Complete</span><?php
}
?>
</div>
<div class="uwt-description">Emily, Christopher * Valerie and Rob</div>
</li>
<?php
}
}
else
{
?>
<li class="uwt-empty">(empty)</li>
<?php
}
?>
</ul>
<table class="uwt-listview uwt-mobile-hidden" style="width: 100%; margin-left: auto; margin-right: auto;" class="uwt-listview">
<tr>
<th rowspan="2">Comment</th>
<th colspan="3">Kids</th>
<th rowspan="2">Start</th>
<th rowspan="2">End</th>
<th rowspan="2">Time</th>
<th rowspan="2">Total</th>
</tr>
<tr>
<th>Name</th>
<th>Location</th>
<th>Rate</th>
</tr>
<?php
// $bses = sqlexec("SELECT * FROM bst_kids_locations WHERE start_datetime <= NOW() AND (end_datetime IS NULL OR end_datetime >= NOW())");
if (count($bses) > 0)
{
foreach ($bses as $bs)
{
$event_id = $bs["id"];
$start_datetime = $bs["start_datetime"];
$end_datetime = $bs["end_datetime"];
$diff_datetime = $bs["diff_datetime"];
$diff_timestamp = $bs["diff_timestamp"];
$comment = $bs["comment"];
$bs_kids = sqlexec("SELECT * FROM bst_event_kids WHERE event_id = :event_id", array( "event_id" => $event_id));
$rowspan = count($bs_kids);
if ($rowspan == 0)
{
$rowspan = 1;
}
echo("<tr><td rowspan=\"" . $rowspan . "\">");
echo($comment);
echo("</td>");
$first = true;
$total_cost = 0;
$all_kids_rate = 0;
foreach ($bs_kids as $bs_kid)
{
$rate = get_kid_rate($bs_kid["kid_id"]);
$all_kids_rate += $rate;
}
foreach ($bs_kids as $bs_kid)
{
$rate = get_kid_rate($bs_kid["kid_id"]);
echo("<td>" . get_kid_name($bs_kid["kid_id"]) . "</td>");
echo("<td>" . get_location_name($bs_kid["location_id"]) . "</td>");
echo("<td>" . $rate . "</td>");
$hour_rate = round(($diff_timestamp / 60) / 60, 2);
$total_cost = round($all_kids_rate * $hour_rate, 2);
if ($first)
{
echo("<td rowspan=\"" . $rowspan . "\">" . $start_datetime . "</td>");
echo("<td rowspan=\"" . $rowspan . "\">");
if ($end_datetime === null)
{
echo("<button class=\"uwt-button uwt-color-primary\" name=\"end_event\" value=\"" . $event_id . "\">End Event Now</button>");
}
else
{
echo($end_datetime);
}
echo("</td>");
echo("<td rowspan=\"" . $rowspan . "\">" . $diff_datetime . " <!-- " . $hour_rate . " hours --></td>");
echo("<td rowspan=\"" . $rowspan . "\">\$" . $total_cost . "</td>");
$first = false;
}
echo("</tr>");
}
if ($first)
{
echo("<td rowspan=\"" . $rowspan . "\"></td>");
echo("<td rowspan=\"" . $rowspan . "\"></td>");
echo("<td rowspan=\"" . $rowspan . "\"></td>");
echo("<td rowspan=\"" . $rowspan . "\">" . $start_datetime . "</td>");
echo("<td rowspan=\"" . $rowspan . "\">" . $end_datetime . "</td>");
echo("<td rowspan=\"" . $rowspan . "\">" . $diff_datetime . " <!-- " . $hour_rate . " hours --></td>");
echo("<td rowspan=\"" . $rowspan . "\">\$" . $total_cost . "</td>");
}
}
}
else
{
?>
<tr>
<td colspan="8">No data available</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</div>
<div class="uwt-mobile-only uwt-button-container">
<a class="uwt-button uwt-button-round uwt-color-primary" href="#" id="add_event_mobile_button">
<i class="fa fa-plus"></i>
</a>
</div>
<?php
}
?>
</form>
<div style="text-align: center; color: #aaaaaa; font-size: 10pt; padding-top: 64px;">
<div style="margin-bottom: 8px;">Version <?php echo(get_version()); ?></div>
<div>Powered by Mocha &copy; MBS Business Solutions</div>
<div class="uwt-badge uwt-color-purple" style="margin-top: 16px;">QA Preview</div>
</div>
</body>
</html>
<?php
});
$app->Start();
?>