Skip to content

Commit

Permalink
Fixes #9 - Managing penalties via admin panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Schulz committed Dec 5, 2018
1 parent 1356fb5 commit ea8a2b0
Show file tree
Hide file tree
Showing 6 changed files with 300 additions and 25 deletions.
33 changes: 30 additions & 3 deletions admin/cup_admin/penalty.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
throw new \Exception($_language->module['error_penalty_no_points']);
}

// 1 point = 1 week
$duration_time = time() + (3600 * 24 * 7 * $penalty_points);

}
Expand Down Expand Up @@ -181,9 +182,13 @@

} else if (isset($_POST['submitDeleteCategory'])) {

$reason_id = (isset($_POST['reason_id']) && is_numeric($_POST['reason_id'])) ?
$reason_id = (isset($_POST['reason_id']) && validate_int($_POST['reason_id'], true)) ?
(int)$_POST['reason_id'] : 0;

if ($reason_id < 1) {
throw new \Exception($_language->module['unknown_reason_id']);
}

$deleteQuery = mysqli_query(
$_database,
"DELETE FROM `" . PREFIX . "cups_penalty_category`
Expand All @@ -204,6 +209,28 @@
throw new \Exception($_language->module['query_delete_failed']);
}

} else if (isset($_POST['submitDeletePenalty'])) {

$penalty_id = (isset($_POST['penalty_details_id']) && validate_int($_POST['penalty_details_id'], true)) ?
(int)$_POST['penalty_details_id'] : 0;

if ($penalty_id < 1) {
throw new \Exception($_language->module['unknown_penalty_id']);
}

$updateQuery = mysqli_query(
$_database,
"UPDATE `" . PREFIX . "cups_penalty`
SET `deleted` = 1
WHERE `ppID` = " . $penalty_id
);

if (!$updateQuery) {
throw new \Exception($_language->module['query_update_failed']);
}

$_SESSION['errorArray'][] = $_language->module['penalty_deleted'];

} else {
throw new \Exception($_language->module['unknown_action']);
}
Expand Down Expand Up @@ -433,7 +460,7 @@

while ($ds = mysqli_fetch_array($get_pp)) {

$ppID = $ds['ppID'];
$penalty_id = $ds['ppID'];

if ($ds['teamID'] > 0) {
$profile = 'admincenter.php?site=cup&amp;mod=teams&amp;action=active&amp;teamID=' . $ds['teamID'];
Expand All @@ -444,7 +471,7 @@
}

$data_array = array();
$data_array['$ppID'] = $ppID;
$data_array['$penalty_id'] = $penalty_id;
$data_array['$profile'] = $profile;
$data_array['$name'] = $name;
$data_array['$reason_name'] = $ds['reason_name'];
Expand Down
89 changes: 89 additions & 0 deletions cup/ajax/admin/admin_penalty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

$returnArray = array(
'status' => FALSE,
'message' => array()
);

try {

$_language->readModule('cups', false, true);

if (!$loggedin || !iscupadmin($userID)) {
throw new \Exception($_language->module['access_denied']);
}

if (empty($getAction)) {
throw new \Exception($_language->module['unknown_action']);
}

if ($getAction == 'getPenaltyDetails') {

$penalty_id = (isset($_GET['penalty_id']) && validate_int($_GET['penalty_id'], true)) ?
(int)$_GET['penalty_id'] : 0;

if ($penalty_id < 1) {
throw new \Exception('unknown_penalty_id');
}

$selectQuery = mysqli_query(
$_database,
"SELECT
cp.`adminID`,
cp.`date`,
cp.`duration_time`,
cp.`teamID`,
cp.`userID`,
cp.`comment`,
cp.`reasonID`,
cpc.`name_de`,
cpc.`name_uk`,
cpc.`points`,
cpc.`lifetime`,
u.`nickname`,
ct.`name` AS `team_name`
FROM `" . PREFIX . "cups_penalty` cp
JOIN `" . PREFIX . "cups_penalty_category` cpc ON cp.`reasonID` = cpc.`reasonID`
LEFT JOIN `" . PREFIX . "user` u ON u.`userID` = cp.`userID`
LEFT JOIN `" . PREFIX . "cups_teams` ct ON ct.`teamID` = cp.`teamID`
WHERE `ppID` = " . $penalty_id
);

if (!$selectQuery) {
$returnArray['message'][] = mysqli_error($_database);
throw new \Exception($_language->module['query_select_failed']);
}

$get = mysqli_fetch_array($selectQuery);

if ($get['userID'] > 0) {
$receiver_url = $hp_url . '/index.php?site=profile&amp;id=' . $get['userID'];
$receiver_name = $get['nickname'];
} else {
$receiver_url = $hp_url . '/index.php?site=teams&amp;action=details&amp;id=' . $get['teamID'];
$receiver_name = $get['team_name'];
}

$receiver = '<a href="' . $receiver_url . '" target="_blank" class="blue">' . $receiver_name . '</a>';

$returnArray['details'] = array(
'receiver' => $receiver,
'duration' => getformatdatetime($get['date']),
'comment' => $get['comment'],
'category' => array(
'name_de' => $get['name_de'],
'name_uk' => $get['name_uk']
)
);

} else {
throw new \Exception($_language->module['unknown_action']);
}

$returnArray['status'] = TRUE;

} catch (Exception $e) {
$returnArray['message'][] = $e->getMessage();
}

echo json_encode($returnArray);
16 changes: 12 additions & 4 deletions cup/html/penalty_list.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<tr>
<td><a href="$profile" class="blue">$name</a></td>
<td>
<a href="$profile" class="blue">$name</a>
</td>
<td>$reason_name</td>
<td><a href="$admin_profile" class="blue" target="_blank">$admin</a></td>
<td>
<a href="$admin_profile" class="blue" target="_blank">
$admin
</a>
</td>
<td>$duration</td>
<td>
<button type="button" class="btn btn-info btn-xs white darkshadow">
<button type="button" name="showPenaltyDetails"
id="btnPenaltyDetails_$penalty_id"
class="btn-penalty-details btn btn-info btn-xs white darkshadow">
Details
</button>
</td>
</tr>
</tr>
Loading

0 comments on commit ea8a2b0

Please sign in to comment.