Updated Pure to 0.6, added pagination, don't think I broke anything...
This commit is contained in:
123
manualpunch.php
123
manualpunch.php
@@ -2,25 +2,29 @@
|
||||
session_start();
|
||||
require_once("config.inc.php");
|
||||
require_once($yaptc_inc . "functions.inc.php");
|
||||
$yaptc_pagename = "Manual Punch";
|
||||
$yaptc_pagename = lang('PUNCH_EDITOR');
|
||||
require_once($yaptc_inc . "header.inc.php");
|
||||
require_once($yaptc_inc . "menu.inc.php");
|
||||
if (getSessionStatus() == false):
|
||||
killSession();
|
||||
else: ?>
|
||||
<!-- ********** BEGIN CONTENT ********** -->
|
||||
<!-- ********** BEGIN CONTENT ********** -->
|
||||
|
||||
<?php if($session_user["0"]["usertype"] !== "Administrator"): header("Location: index.php"); ?>
|
||||
<h2 class="content-subhead"><?php echo lang('NOT_AUTHORIZED'); ?></h2>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
$timenow = date('Y-m-d H:i');
|
||||
if (!empty($_POST['punchuser'])) {
|
||||
|
||||
|
||||
if (isset($_POST['notes'])) { if (!empty($_POST['notes'])) { $notes = $_POST['notes']; } else { $notes = NULL; } } else { $notes = NULL; }
|
||||
if (isset($_POST['punchtime'])) {
|
||||
// this needs work to check existing modified flag!!! i.e. if already set to 1, leave as 1!!!
|
||||
if (!empty($_POST['punchtime'])) { $punchtime = $_POST['punchtime'] . ':00'; $modified = "1"; } else { $punchtime = $timenow . ':00'; }
|
||||
} else { $punchtime = $timenow . ':00'; }
|
||||
if (!empty($_POST['punchtime'])) { $punchtime = $_POST['punchtime']; $modified = "1"; } else { $punchtime = $timenow; }
|
||||
} else { $punchtime = $timenow; }
|
||||
|
||||
// Is the user currently punched in? If so, insert the punch out record, otherwise, insert a new punch in
|
||||
if ($_POST['status']=="In") {
|
||||
@@ -37,91 +41,52 @@ header('Location: '.$_SERVER['PHP_SELF']);
|
||||
|
||||
|
||||
|
||||
if ($session_user["0"]["usertype"] == "Administrator"): ?>
|
||||
<h2 class="content-subhead">User Status</h2>
|
||||
<p>Below is the current state of all users. You may enter punches for them using the buttons, or edit existing punches in the next section.</p>
|
||||
?>
|
||||
|
||||
<table class="pure-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Status</th>
|
||||
<th>Notes</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<?php
|
||||
|
||||
foreach (getUserInfo($db, "%") as $row) {
|
||||
echo "<td>" . $row['lastname'] . ", " . $row['firstname'] . "</td>";
|
||||
|
||||
$user_punch = listPunches($db, $row['userid'], 1);
|
||||
if (!$user_punch): $status = "Out"; $statustime = "No Punches"; $notes="";
|
||||
elseif (!empty($user_punch['0']['outtime'])): $status = "Out"; $statustime = date('g:i a \o\n M jS, Y', strtotime($user_punch['0']['outtime'])); $punchid = ""; $notes="";
|
||||
else: $status = "In"; $statustime = date('g:i a \o\n M jS, Y', strtotime($user_punch['0']['intime'])); $punchid = $user_punch['0']['punchid']; if (!empty($user_punch['0']['notes'])): $notes = $user_punch['0']['notes']; else: $notes=""; endif;
|
||||
endif;
|
||||
|
||||
echo "<td>";
|
||||
if ($statustime == "No Punches"): echo $statustime; else: echo $status . " since " . $statustime; endif;
|
||||
echo "</td>"; ?>
|
||||
|
||||
<form method="post" onsubmit="return confirm('Are you sure you want to punch this user NOW?')">
|
||||
<td><input type="text" name="notes" placeholder="<?php echo $notes; ?>"></td>
|
||||
<td>
|
||||
<input type="hidden" name="_METHOD" value="PUNCH">
|
||||
<input type="hidden" name="userid" value="<?php echo $row['userid']; ?>">
|
||||
<input type="hidden" name="punchid" value="<?php echo $punchid; ?>">
|
||||
<input type="hidden" name="status" value="<?php echo $status; ?>">
|
||||
<input type="text" name="punchtime" placeholder="<?php echo $timenow; ?>" maxlength="20">
|
||||
<?php if ($status == "In"): ?>
|
||||
<button type="submit" name="punchuser" value="punchuser" class="pure-button button-error">Punch OUT</button>
|
||||
<?php elseif ($status == "Out"): ?>
|
||||
<button type="submit" name="punchuser" value="punchuser" class="pure-button button-success">Punch IN</button>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<?php
|
||||
if (!empty($_POST['editpunch'])) {
|
||||
editPunch($yaptc_db, $_POST['punchid'], $_POST['intime'], $_POST['outtime'], $_POST['notes']);
|
||||
editPunch($db, $_POST['editpunch'], $_POST[$_POST['editpunch'] . "-intime"], $_POST[$_POST['editpunch'] . "-outtime"], $_POST[$_POST['editpunch'] . "-notes"]);
|
||||
}
|
||||
if (!empty($_POST['deletepunch'])) {
|
||||
deletePunch($yaptc_db, $_POST['punchid']);
|
||||
deletePunch($db, $_POST['deletepunch']);
|
||||
}
|
||||
|
||||
// Set up pagination
|
||||
$page_num = 1;
|
||||
if(!empty($_GET['pnum'])):
|
||||
$page_num = filter_input(INPUT_GET, 'pnum', FILTER_VALIDATE_INT);
|
||||
if(false === $page_num):
|
||||
$page_num = 1;
|
||||
endif;
|
||||
endif;
|
||||
$offset = ($page_num - 1) * $rowsperpage;
|
||||
$row_count = count(listPunches($db, "%"));
|
||||
$page_count = 0;
|
||||
if (0 === $row_count): else: $page_count = (int)ceil($row_count / $rowsperpage); if($page_num > $page_count): $page_num = 1; endif; endif;
|
||||
?>
|
||||
|
||||
|
||||
<h2 class="content-subhead">Edit Punches</h2>
|
||||
<p>Edit existing punches for users if needed.</p>
|
||||
<table class="pure-table">
|
||||
<thead><tr><th>In/Out</th><th>Name</th><th>Hours</th><th>Flag</th><th>Notes</th><th>Action</th></tr></thead>
|
||||
<tbody><?php foreach (listPunches($db, "%") as $row): ?>
|
||||
<tr><form method="post" onsubmit="return confirm('Are you sure you want to save the edit to this user punch?')">
|
||||
<td><input type="text" name="intime" value="<?php echo $row['intime']; ?>"><input type="text" name="outtime" value="<?php echo $row['outtime']; ?>"></td>
|
||||
<td><?php echo $row['lastname'] . ", " . $row['firstname']; ?></td><td><?php echo $row['punchhours']; ?></td><td><?php echo $row['modified']; ?></td>
|
||||
<td><input type="text" name="notes" value="<?php echo $row['notes']; ?>"></td>
|
||||
<td><input type="hidden" name="punchid" value="<?php echo $row['punchid']; ?>"><button type="submit" name="editpunch" value="editpunch" class="pure-button button-success">Save</button><button type="submit" name="deletepunch" value="deletepunch" class="pure-button button-error">Delete</button></td></form>
|
||||
</tr><?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h2 class="content-subhead"><?php echo lang('EDIT_PUNCH_HEADER'); ?></h2>
|
||||
<p><?php echo lang('EDIT_PUNCH_DESC'); ?></p>
|
||||
<form method="post" onsubmit="return confirm('<?php echo lang('SAVE_PUNCH_WARNING'); ?>')">
|
||||
<table class="pure-table pure-table-striped">
|
||||
<thead>
|
||||
<tr><th colspan="6"><?php echo lang('PAGE') . ": "; for ($i = 1; $i <= $page_count; $i++): if ($i === $page_num): echo $i . ' '; else: echo '<a href="' . $_SERVER['PHP_SELF'] . '?pnum=' . $i . '">' . $i . '</a> '; endif; endfor; ?></th></tr>
|
||||
<tr><th><?php echo lang('IN') . "/" . lang('OUT'); ?></th><th><?php echo lang('NAME'); ?></th><th><?php echo lang('HOURS'); ?></th><th><?php echo lang('FLAG'); ?></th><th><?php echo lang('NOTES'); ?></th><th><?php echo lang('ACTIONS'); ?></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach (listPunches($db, "%", $rowsperpage, $offset) as $row): ?>
|
||||
<tr>
|
||||
<td><input type="text" name="<?php echo $row['punchid']; ?>-intime" value="<?php echo $row['intime']; ?>" /><input type="text" name="<?php echo $row['punchid']; ?>-outtime" value="<?php echo $row['outtime']; ?>" /></td><td><?php echo $row['lastname'] . ", " . $row['firstname']; ?></td><td><?php echo $row['punchhours']; ?></td><td><?php echo $row['modified']; ?></td><td><input type="text" name="<?php echo $row['punchid']; ?>-notes" value="<?php echo $row['notes']; ?>" /></td><td><button type="submit" name="editpunch" value="<?php echo $row['punchid']; ?>" class="pure-button button-success"><?php echo lang('SAVE'); ?></button><button type="submit" name="deletepunch" value="<?php echo $row['punchid']; ?>" class="pure-button button-error"><?php echo lang('DELETE'); ?></button></td>
|
||||
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
|
||||
<?php else: ?>
|
||||
<h2 class="content-subhead">NOT AUTHORIZED!</h2>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<!-- ********** END CONTENT ********** -->
|
||||
<!-- ********** END CONTENT ********** -->
|
||||
<?php endif; require_once($yaptc_inc . "footer.inc.php"); ?>
|
||||
|
||||
Reference in New Issue
Block a user