updated to add delete...

This commit is contained in:
Josh North 2015-02-19 22:41:20 -05:00
parent d45bf9c6dd
commit ca258c49fc
2 changed files with 30 additions and 8 deletions

View File

@ -35,7 +35,7 @@ if ($_POST['reporttype'] == "Hours per week per user") {
$query = "SELECT $query = "SELECT
YEAR(punches.intime) AS g_year, YEAR(punches.intime) AS g_year,
WEEK(punches.intime) AS g_week, WEEK(punches.intime) AS g_week,
SUM(TIME_TO_SEC(TIMEDIFF(punches.outtime, punches.intime))/3600) AS punchhours, ROUND(SUM(TIME_TO_SEC(TIMEDIFF(punches.outtime, punches.intime))/3600),2) AS punchhours,
punches.id as punchid, punches.id as punchid,
users.id as user, users.id as user,
users.username as username, users.username as username,
@ -79,8 +79,8 @@ echo '</table>';
elseif ($_POST['reporttype'] == "Hours per month per user") { elseif ($_POST['reporttype'] == "Hours per month per user") {
$query = "SELECT $query = "SELECT
YEAR(punches.intime) AS g_year, YEAR(punches.intime) AS g_year,
MONTH(punches.intime) AS g_month, MONTHNAME(punches.intime) AS g_month,
SUM(TIME_TO_SEC(TIMEDIFF(punches.outtime, punches.intime))/3600) AS punchhours, ROUND(SUM(TIME_TO_SEC(TIMEDIFF(punches.outtime, punches.intime))/3600),2) AS punchhours,
punches.id as punchid, punches.id as punchid,
users.id as user, users.id as user,
users.username as username, users.username as username,

View File

@ -13,7 +13,7 @@ echo "<h2 class=\"content-subhead\">Add User</h2>";
echo "<p>Use the following form to add users to the system. Passwords must be 8+ characters. Email must be filled out, and username must be unique.</p>"; echo "<p>Use the following form to add users to the system. Passwords must be 8+ characters. Email must be filled out, and username must be unique.</p>";
require_once($yaptc_lib . "phpass-0.3/PasswordHash.php"); require_once($yaptc_lib . "phpass-0.3/PasswordHash.php");
if (!empty($_POST)) if (!empty($_POST['newuser']))
{ {
if (empty($_POST['username'])) if (empty($_POST['username']))
{ {
@ -97,7 +97,7 @@ if (!empty($_POST))
* If the form has been submitted and no errors were detected, we can proceed * If the form has been submitted and no errors were detected, we can proceed
* to account creation. * to account creation.
*/ */
if (!empty($_POST) && empty($errors)) if (!empty($_POST['newuser']) && empty($errors))
{ {
/** /**
* Hash password before storing in database * Hash password before storing in database
@ -177,17 +177,34 @@ if (!empty($_POST) && empty($errors))
<option value="00000000001">Administrator</option> <option value="00000000001">Administrator</option>
</select> </select>
<?php echo isset($errors['usertype']) ? $errors['usertype'] : ''; ?> <?php echo isset($errors['usertype']) ? $errors['usertype'] : ''; ?>
<button type="submit" class="pure-button button-success" value="Submit">Create</button> <button type="submit" class="pure-button button-success" value="Submit" name="newuser">Create</button>
</div> </div>
</fieldset> </fieldset>
</form> </form>
</body>
</html>
<?php <?php
} }
// delete user only if submitted by button
if (!empty($_POST['deluser']))
{
if ($_SERVER['REQUEST_METHOD'] == 'DELETE' || ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['_METHOD'] == 'DELETE')) {
$deleteid = (int) $_POST['deleteid'];
$deletequery = $sql->prepare("DELETE FROM users WHERE users.id=$deleteid");
$deletequery->execute();
echo "user deleted!";
if ($deletequery !== false) {
header("Location: {$_SERVER['PHP_SELF']}", true, 303);
exit;
}
}
}
echo "<h2 class=\"content-subhead\">User List</h2>"; echo "<h2 class=\"content-subhead\">User List</h2>";
echo "<p>Current users. To edit, select the edit button in the right column.</p>"; echo "<p>Current users. To edit, select the edit button in the right column.</p>";
$result = $sql->prepare("SELECT users.id as userid, users.username as username, users.email as email, users.created as created, users.firstname as firstname, users.lastname as lastname, users.usertype as usertypeid, usertypes.typename as usertype $result = $sql->prepare("SELECT users.id as userid, users.username as username, users.email as email, users.created as created, users.firstname as firstname, users.lastname as lastname, users.usertype as usertypeid, usertypes.typename as usertype
@ -204,6 +221,7 @@ echo '<th>Username</th>';
echo '<th>Email</th>'; echo '<th>Email</th>';
echo '<th>Created</th>'; echo '<th>Created</th>';
echo '<th>User Type</th>'; echo '<th>User Type</th>';
echo '<th>Actions</th>';
echo '</tr>'; echo '</tr>';
echo '</thead>'; echo '</thead>';
echo '<tbody>'; echo '<tbody>';
@ -216,6 +234,10 @@ echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['email'] . "</td>"; echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['created'] . "</td>"; echo "<td>" . $row['created'] . "</td>";
echo "<td>" . $row['usertype'] . "</td>"; echo "<td>" . $row['usertype'] . "</td>";
?><td><form method="post" onsubmit="return confirm('Are you sure you want to delete this user?')">
<input type="hidden" name="_METHOD" value="DELETE">
<input type="hidden" name="deleteid" value="<?php echo $row['userid']; ?>"><button name="deluser" value="deluser" type="submit">Delete</button></form></td>
<?php
echo "</tr>"; echo "</tr>";
} }
echo '</tbody>'; echo '</tbody>';