Skip to content

Commit d216d06

Browse files
committed
Fixes #915
1. Added security token validation in the POST handler (lines 20-22) 2. Added user guidance message when no reviews exist (lines 115-137) Files changed in commit: HRPerformanceRatings.php
1 parent 281790b commit d216d06

1 file changed

Lines changed: 33 additions & 14 deletions

File tree

HRPerformanceRatings.php

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717

1818
// Handle form submission
1919
if (isset($_POST['SubmitRatings'])) {
20-
$ReviewID = (int)$_POST['ReviewID'];
21-
22-
if ($ReviewID > 0) {
20+
if (!hash_equals($_SESSION['FormID'], $_POST['FormID'])) {
21+
prnMsg(__('Form token validation failed'), 'error');
22+
} elseif (isset($_POST['ReviewID']) && (int)$_POST['ReviewID'] > 0) {
23+
$ReviewID = (int)$_POST['ReviewID'];
2324
DB_Txn_Begin();
2425

25-
// Delete existing ratings for this review
26+
/* Delete existing ratings inside a transaction so that if any
27+
* subsequent insert fails, the connection close rolls back the
28+
* delete automatically — leaving the original data intact. */
2629
$SQL = "DELETE FROM hrperformanceratings WHERE reviewid = " . $ReviewID;
27-
DB_query($SQL);
30+
DB_query($SQL, __('Could not delete existing ratings'));
2831

2932
// Insert new ratings
3033
$TotalWeightedScore = 0;
@@ -41,6 +44,10 @@
4144
$SQL = "SELECT weight FROM hrperformancecriteria WHERE criteriaid = " . $CriteriaID;
4245
$Result = DB_query($SQL);
4346
$CriteriaRow = DB_fetch_array($Result);
47+
if ($CriteriaRow === false) {
48+
/* Criteria no longer exists — skip this rating */
49+
continue;
50+
}
4451
$Weight = $CriteriaRow['weight'];
4552

4653
$WeightedScore = $Rating * ($Weight / 100);
@@ -57,7 +64,7 @@
5764
'" . $_SESSION['UserID'] . "',
5865
NOW()
5966
)";
60-
DB_query($SQL);
67+
DB_query($SQL, __('Could not insert performance rating'));
6168

6269
$TotalWeightedScore += $WeightedScore;
6370
$TotalWeight += $Weight;
@@ -105,17 +112,29 @@
105112
ORDER BY pr.reviewdate DESC, e.lastname, e.firstname";
106113
$Result = DB_query($SQL);
107114

108-
while ($Row = DB_fetch_array($Result)) {
109-
echo '<option value="' . $Row['reviewid'] . '">' .
110-
$Row['employeenumber'] . ' - ' . $Row['firstname'] . ' ' . $Row['lastname'] .
111-
' (' . ConvertSQLDate($Row['reviewdate']) . ' - ' . $Row['reviewtype'] . ')' .
112-
'</option>';
113-
}
115+
if (DB_num_rows($Result) == 0) {
116+
echo '</select></td>
117+
</tr>
118+
</table>
119+
</form>';
120+
echo '<div style="background-color: #fff3cd; padding: 15px; margin: 20px 0; border: 1px solid #ffc107; border-radius: 4px;">
121+
<p><strong>' . __('No Performance Reviews Found') . '</strong></p>
122+
<p>' . __('Before you can add performance ratings, you need to create a performance review first.') . '</p>
123+
<p>' . __('Please visit') . ' <a href="' . htmlspecialchars($RootPath . '/HRPerformanceReviews.php', ENT_QUOTES, 'UTF-8') . '">' . __('Performance Reviews') . '</a> ' . __('to create a new review.') . '</p>
124+
</div>';
125+
} else {
126+
while ($Row = DB_fetch_array($Result)) {
127+
echo '<option value="' . $Row['reviewid'] . '">' .
128+
$Row['employeenumber'] . ' - ' . $Row['firstname'] . ' ' . $Row['lastname'] .
129+
' (' . ConvertSQLDate($Row['reviewdate']) . ' - ' . $Row['reviewtype'] . ')' .
130+
'</option>';
131+
}
114132

115-
echo '</select></td>
133+
echo '</select></td>
116134
</tr>
117135
</table>
118136
</form>';
137+
}
119138
}
120139

121140
// Display rating form
@@ -154,7 +173,7 @@
154173
<td><strong>' . __('Review Type') . ':</strong></td>
155174
<td>' . __($ReviewRow['reviewtype']) . '</td>
156175
<td><strong>' . __('Overall Rating') . ':</strong></td>
157-
<td>' . __($ReviewRow['overallrating']) . '</td>
176+
<td>' . htmlspecialchars($ReviewRow['overallrating'], ENT_QUOTES, 'UTF-8') . '</td>
158177
</tr>
159178
</table>
160179
</div>';

0 commit comments

Comments
 (0)