This commit is contained in:
2021-06-23 10:06:26 -04:00
parent c7c5ae17fa
commit 3ae19a8ea5
6 changed files with 109 additions and 92 deletions

183
users.php
View File

@@ -87,6 +87,8 @@
<?php // FILTER POSTED DATA
$form_data = filter_input_array(INPUT_POST, [
'fd_formAction' => (string)FILTER_SANITIZE_STRING,
'fd_pgNumUsers' => (int)FILTER_VALIDATE_INT,
'fd_pgNumSites' => (int)FILTER_VALIDATE_INT,
'edituser' => (string)FILTER_SANITIZE_STRING,
'fd_editUserId' => (string)FILTER_SANITIZE_STRING,
'fd_initialPassword' => (string)FILTER_SANITIZE_STRING,
@@ -98,6 +100,9 @@ $form_data = filter_input_array(INPUT_POST, [
'fd_newSiteTimezone' => (string)FILTER_SANITIZE_STRING,
'fd_newSiteRegion' => (string)FILTER_SANITIZE_STRING
]);
if(empty($form_data['fd_formAction'])){ // SET INITIAL STAGE
$form_data['fd_formAction'] = 'actionInitial';
}
?>
<?php // PAGE CONSTANTS
@@ -303,90 +308,89 @@ if (Registry::AUTHMETHOD == 'INTERNAL') {
header('Location: users.php');
}
}
// 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) * $StaticFunctions->getPageRows();
$row_count = count($Users->getUserInfo("%", "%", "%"));
$page_count = 0;
if (0 === $row_count): else: $page_count = (int)ceil($row_count / $StaticFunctions->getPageRows()); if($page_num > $page_count): $page_num = 1; endif; endif;
?>
<!-- USER MANAGEMENT SECTION -->
<?php if ($form_data['fd_formAction'] == 'actionInitial') { // SHOW USERS LISTING
$pgNumUsers=(int)1; // PAGINATION LOGIC
if(!empty($form_data['fd_pgNumUsers'])){$pgNumUsers = $form_data['fd_pgNumUsers'];}
$pgOffsetUsers=(int)($pgNumUsers-1)*$StaticFunctions->getPageRows();
$pgRowCountUsers=(int)count($Users->getUserInfo("%", "%", "%"));
$pgCountUsers=(int)0;
if(0===$pgRowCountUsers){}else{$pgCountUsers=(int)ceil($pgRowCountUsers/$StaticFunctions->getPageRows());if($pgNumUsers>$pgCountUsers){$pgNumUsers=(int)1;}} ?>
<!-- USER MANAGEMENT -->
<div class="container-fluid">
<div class="row row-cols-3 mb-2">
<div class="col d-grid gap-2">
<h2><i class="fas fa-users"></i> <?php echo $transLang['USER-USERS']; ?></h2>
</div>
<div class="col d-grid gap-2 text-center">
<form method="post">
<ul class="pagination pagination-sm">
<li class="page-item disabled"><a class="page-link" href="#" tabindex="-1"><?php echo $transLang['STR_COMMON_PAGE']; ?></a></li>
<?php for ($i = 1; $i <= $page_count; $i++): ?>
<li class="page-item<?php if ($i === $page_num): echo ' active'; else: echo ' '; endif; ?>"><a class="page-link" href="<?php echo 'users.php?pnum=' . $i; ?>"><?php echo $i; ?></a></li>
<?php endfor; ?>
<li class="page-item disabled"><a class="page-link" href="#" tabindex="-1"><?=$transLang['STR_COMMON_PAGE']?></a></li>
<?php for($i=1; $i<=$pgCountUsers; $i++){ ?>
<li class="page-item<?php if($i===$pgNumUsers){echo ' active';} ?>"><button type="submit" class="page-link<?php if($i===$pgNumUsers){echo ' active';} ?>" id="fd_pgNumUsers" name="fd_pgNumUsers" value="<?php echo $i; ?>"><?php echo $i; ?></button></li>
<?php } ?>
</ul>
</form>
</div>
<div class="col text-end">
<a data-bs-toggle="modal" data-bs-target="#addUserModal" href="#addUserModal" name="addUserModal" type="button" class="btn btn-info btn-lg open-addUserModal"><i class="fas fa-user-plus"></i> <?php echo $transLang['STR_ACCOUNTINFO_ADDUSER_TITLE']; ?></a>
<a data-bs-toggle="modal" data-bs-target="#modalAddUser" href="#modalAddUser" name="modalAddUser" type="button" class="btn btn-info btn-lg open-modalAddUser"><i class="fas fa-user-plus"></i> <?php echo $transLang['STR_ACCOUNTINFO_ADDUSER_TITLE']; ?></a>
<a href="users.php" type="button" class="btn btn-primary btn-lg"><i class="fa fa-redo"></i> <?php echo $transLang['REFRESH']; ?></a>
</div>
</div>
<div class="row row-cols-1 mb-2">
<div class="row row-cols-1">
<div class="col d-grid gap-2">
<table class="table table-striped w-auto">
<thead>
<tr>
<th><?php echo $transLang['NAME']; ?></th><th><?php echo $transLang['USER-USERNAME']; ?></th><th><?php echo $transLang['EMAIL']; ?></th><th><?php echo $transLang['CREATED']; ?></th><th><?php echo $transLang['USER-TYPE']; ?></th><th><?php echo $transLang['STR_COMMON_SITE']; ?></th><th><?php echo $transLang['ACTIONS']; ?></th>
</tr>
</thead>
<tbody>
<?php foreach($Users->getUserInfo("%", $StaticFunctions->getPageRows(), $offset) as $row): ?>
<?php if ($row['users_id'] == "1"): echo " "; else: ?>
<?php if ($row['users_id'] == "2"): echo " "; else: ?>
<tr>
<td><?php echo $row['users_lastname'] . ", " . $row['users_firstname']; ?></td>
<td><?php echo $row['users_username']; ?></td>
<td><?php echo $row['users_email']; ?></td>
<td><?php echo $row['users_created']; ?></td>
<td><?php echo $transLang[$row['users_usertype']]; ?></td>
<td>
<?php $sidrowcount=0; foreach($SiteInfo->getSite("0", $row['users_id'], "0", "0") as $sidrow) { ?>
<table class="table table-striped table-sm table-responsive-sm text-nowrap">
<thead class="thead-dark">
<tr>
<th class="small col-xs-1"><?php echo $transLang['NAME']; ?></th><th class="small col-xs-1"><?php echo $transLang['USER-USERNAME']; ?></th><th class="small col-xs-1"><?php echo $transLang['EMAIL']; ?></th><th class="small col-xs-1"><?php echo $transLang['CREATED']; ?></th><th class="small col-xs-1"><?php echo $transLang['USER-TYPE']; ?></th><th class="small col-xs-1"><?php echo $transLang['STR_COMMON_SITE']; ?></th><th class="small col-xs-1"><?php echo $transLang['ACTIONS']; ?></th>
</tr>
</thead>
<tbody>
<?php foreach($Users->getUserInfo("%", $StaticFunctions->getPageRows(), $pgOffsetUsers) as $rowUsers): ?>
<?php if ($rowUsers['users_id'] == "1"): echo " "; else: ?>
<?php if ($rowUsers['users_id'] == "2"): echo " "; else: ?>
<tr>
<td class="small"><?php echo $rowUsers['users_lastname'] . ", " . $rowUsers['users_firstname']; ?></td>
<td class="small"><?php echo $rowUsers['users_username']; ?></td>
<td class="small"><?php echo $rowUsers['users_email']; ?></td>
<td class="small"><?php echo $rowUsers['users_created']; ?></td>
<td class="small"><?php echo $transLang[$rowUsers['users_usertype']]; ?></td>
<td class="small">
<?php $sidrowcount=0; foreach($SiteInfo->getSite("0", $rowUsers['users_id'], "0", "0") as $sidrow) { ?>
<span class="badge rounded-pill bg-info text-dark"><?php echo $sidrow['sites_name']; ?></span>
<?php ++$sidrowcount; if($sidrowcount==3) { echo "<br>"; } elseif($sidrowcount==5) {echo '<span class="badge rounded-pill bg-danger">...</span>'; break; } } ?>
</td>
<td class="nowrap">
<form method="post">
<input type="hidden" id="_METHOD" name="_METHOD" value="EDITUSER" />
<input type="hidden" id="fd_editUserId" name="fd_editUserId" value="<?php echo $row['users_id']; ?>" />
<button class="btn btn-primary btn-sm" id="edituser" name="edituser" value="edituser" type="submit" <?php if ($row['users_username'] == "admin"): echo "disabled"; endif; if ($row['users_username'] == "KIOSK"): echo "disabled"; endif; ?>><i class="fa fa-edit"></i> </button>
</form>
<form method="post" onsubmit="return confirm('<?php echo $transLang['DELETE_WARNING']; ?>')">
<input type="hidden" id="_METHOD" name="_METHOD" value="DELETE" />
<input type="hidden" id="deleteid" name="deleteid" value="<?php echo $row['users_id']; ?>" />
<button class="btn btn-danger btn-sm" id="deluser" name="deluser" value="deluser" type="submit" <?php if ($row['users_username'] == "admin"): echo "disabled"; endif; if ($row['users_username'] == "KIOSK"): echo "disabled"; endif; ?>><i class="fa fa-trash"></i> </button>
</form>
</td>
</tr>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>
</td>
<td class="small" class="nowrap">
<div class="btn-group">
<form method="post">
<input type="hidden" id="_METHOD" name="_METHOD" value="EDITUSER" />
<input type="hidden" id="fd_editUserId" name="fd_editUserId" value="<?php echo $rowUsers['users_id']; ?>" />
<button class="btn btn-primary btn-sm" id="edituser" name="edituser" value="edituser" type="submit" <?php if ($rowUsers['users_username'] == "admin"): echo "disabled"; endif; if ($rowUsers['users_username'] == "KIOSK"): echo "disabled"; endif; ?>><i class="fa fa-edit"></i> </button>
</form>
<form method="post" onsubmit="return confirm('<?php echo $transLang['DELETE_WARNING']; ?>')">
<input type="hidden" id="_METHOD" name="_METHOD" value="DELETE" />
<input type="hidden" id="deleteid" name="deleteid" value="<?php echo $rowUsers['users_id']; ?>" />
<button class="btn btn-danger btn-sm" id="deluser" name="deluser" value="deluser" type="submit" <?php if ($rowUsers['users_username'] == "admin"): echo "disabled"; endif; if ($rowUsers['users_username'] == "KIOSK"): echo "disabled"; endif; ?>><i class="fa fa-trash"></i> </button>
</form>
</div>
</td>
</tr>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- END USER MANAGEMENT SECTION -->
<!-- USER MANAGEMENT END -->
<?php } ?>
<!-- ADD USER FORM MODAL -->
<div class="modal fade" id="addUserModal" tabindex="-1" role="dialog">
<div class="modal fade" id="modalAddUser" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header text-light bg-secondary">
@@ -497,54 +501,49 @@ if (!empty($_POST['delsite'])) {
header('Location: users.php');
}
}
// Set up pagination
$page_num1 = 1;
if(!empty($_GET['pnum1'])):
$page_num1 = filter_input(INPUT_GET, 'pnum1', FILTER_VALIDATE_INT);
if(false === $page_num1):
$page_num1 = 1;
endif;
endif;
$offset1 = ($page_num1 - 1) * $StaticFunctions->getPageRows();
$row_count1 = count($SiteInfo->listSite("0", "0"));
$page_count1 = 0;
if (0 === $row_count1): else: $page_count1 = (int)ceil($row_count1 / $StaticFunctions->getPageRows()); if($page_num1 > $page_count1): $page_num1 = 1; endif; endif;
?>
<!-- SITE MGMT START -->
<?php if ($form_data['fd_formAction'] == 'actionInitial') { // SHOW SITES LISTING
$pgNumSites=(int)1; // PAGINATION LOGIC
if(!empty($form_data['fd_pgNumSites'])){$pgNumSites = $form_data['fd_pgNumSites'];}
$pgOffsetSites=(int)($pgNumSites-1)*$StaticFunctions->getPageRows();
$pgRowCountSites=(int)count($SiteInfo->listSite("0", "0"));
$pgCountSites=(int)0;
if(0===$pgRowCountSites){}else{$pgCountSites=(int)ceil($pgRowCountSites/$StaticFunctions->getPageRows());if($pgNumSites>$pgCountSites){$pgNumSites=(int)1;}} ?>
<!-- SITE MANAGEMENT -->
<div class="container-fluid">
<div class="row row-cols-3 mb-2">
<div class="col d-grid gap-2">
<h2><i class="fas fa-globe-americas"></i> <?php echo $transLang['USER-SITES']; ?></h2>
</div>
<div class="col d-grid gap-2 text-center">
<form method="post">
<ul class="pagination pagination-sm">
<li class="page-item disabled"><a class="page-link" href="#" tabindex="-1"><?php echo $transLang['STR_COMMON_PAGE']; ?></a></li>
<?php for ($i1 = 1; $i1 <= $page_count1; $i1++): ?>
<li class="page-item<?php if ($i1 === $page_num1): echo ' active'; else: echo ' '; endif; ?>"><a class="page-link" href="<?php echo 'users.php?pnum1=' . $i1; ?>"><?php echo $i1; ?></a></li>
<?php endfor; ?>
<li class="page-item disabled"><a class="page-link" href="#" tabindex="-1"><?=$transLang['STR_COMMON_PAGE']?></a></li>
<?php for($i=1; $i<=$pgCountSites; $i++){ ?>
<li class="page-item<?php if($i===$pgNumSites){echo ' active';} ?>"><button type="submit" class="page-link<?php if($i===$pgNumSites){echo ' active';} ?>" id="fd_pgNumSites" name="fd_pgNumSites" value="<?php echo $i; ?>"><?php echo $i; ?></button></li>
<?php } ?>
</ul>
</form>
</div>
<div class="col text-end">
<a data-bs-toggle="modal" data-bs-target="#modalAddSite" href="#modalAddSite" name="modalAddSite" type="button" class="btn btn-info btn-lg open-modalAddSite"><i class="fas fa-map-marker-alt"></i> <?php echo $transLang['ADD_SITE']; ?></a>
<a href="users.php" type="button" class="btn btn-primary btn-lg"><i class="fa fa-redo"></i> <?php echo $transLang['REFRESH']; ?></a>
</div>
</div>
<div class="row row-cols-1 mb-2">
<div class="row row-cols-1">
<div class="col d-grid gap-2">
<table class="table table-striped w-auto">
<thead>
<tr>
<th><?php echo $transLang['NAME']; ?></th><th><?php echo $transLang['STR_COMMON_TIMEZONE']; ?></th><th><?php echo $transLang['STR_COMMON_REGION']; ?></th><th><?php echo $transLang['ACTIONS']; ?></th>
<table class="table table-striped table-sm table-responsive-sm text-nowrap">
<thead class="thead-dark">
<tr>
<th class="small col-xs-1"><?php echo $transLang['NAME']; ?></th><th class="small col-xs-1"><?php echo $transLang['STR_COMMON_TIMEZONE']; ?></th><th class="small col-xs-1"><?php echo $transLang['STR_COMMON_REGION']; ?></th><th class="small col-xs-1"><?php echo $transLang['STR_COMMON_USERCOUNT']; ?></th><th class="small col-xs-1"><?php echo $transLang['ACTIONS']; ?></th>
</tr>
</thead>
<tbody>
<?php foreach($SiteInfo->listSite($StaticFunctions->getPageRows(), $offset1) as $row1): ?>
<?php if ($row1['sites_name'] === "NOSITE"): echo " "; else: ?>
<?php foreach($SiteInfo->listSite($StaticFunctions->getPageRows(), $pgOffsetSites) as $rowSites): ?>
<?php if ($rowSites['sites_name'] === "NOSITE"): echo " "; else: ?>
<tr>
<td><?php echo $row1['sites_name']; ?></td><td><?php echo $row1['sites_timezone']; ?></td><td><?php echo $row1['sites_region']; ?></td><td><form method="post" onsubmit="return confirm('<?php echo $transLang['DELETE_WARNING']; ?>')"><input type="hidden" id="_METHOD" name="_METHOD" value="DELETE" /><input type="hidden" id="deleteid" name="deleteid" value="<?php echo $row1['sites_id']; ?>" /><button class="btn btn-danger btn-sm" id="deluser" name="delsite" value="delsite" type="submit"><i class="fa fa-trash"></i> </button></form></td>
<td class="small"><?php echo $rowSites['sites_name']; ?></td><td class="small"><?php echo $rowSites['sites_timezone']; ?></td><td class="small"><?php echo $rowSites['sites_region']; ?></td><td class="small"><?=$SiteInfo->countSiteUsers($rowSites['sites_id'])?></td><td class="small"><form method="post" onsubmit="return confirm('<?php echo $transLang['DELETE_WARNING']; ?>')"><input type="hidden" id="_METHOD" name="_METHOD" value="DELETE" /><input type="hidden" id="deleteid" name="deleteid" value="<?php echo $rowSites['sites_id']; ?>" /><button class="btn btn-danger btn-sm" id="deluser" name="delsite" value="delsite" type="submit"><i class="fa fa-trash"></i> </button></form></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
@@ -553,10 +552,11 @@ if (0 === $row_count1): else: $page_count1 = (int)ceil($row_count1 / $StaticFunc
</div>
</div>
</div>
<hr />
<!-- SITE MANAGEMENT END -->
<?php } ?>
<!-- START ADDSITE MODAL -->
<!-- SITE ADD MODAL -->
<form class="form form-approve" method="post">
<input type="hidden" name="fd_formAction" id="fd_formAction" value="actionNewSite" />
<div class="modal fade" id="modalAddSite" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" role="dialog">
@@ -615,9 +615,8 @@ if (0 === $row_count1): else: $page_count1 = (int)ceil($row_count1 / $StaticFunc
</div>
</form>
<!-- END ADDSITE MODAL -->
<!-- SITE ADD MODAL END -->
<?php } ?>
<hr />
<!-- END PAGE -->
<?php } require_once("inc/footer.inc.php");