|
17 | 17 |
|
18 | 18 | // Handle form submission |
19 | 19 | 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']; |
23 | 24 | DB_Txn_Begin(); |
24 | 25 |
|
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. */ |
26 | 29 | $SQL = "DELETE FROM hrperformanceratings WHERE reviewid = " . $ReviewID; |
27 | | - DB_query($SQL); |
| 30 | + DB_query($SQL, __('Could not delete existing ratings')); |
28 | 31 |
|
29 | 32 | // Insert new ratings |
30 | 33 | $TotalWeightedScore = 0; |
|
41 | 44 | $SQL = "SELECT weight FROM hrperformancecriteria WHERE criteriaid = " . $CriteriaID; |
42 | 45 | $Result = DB_query($SQL); |
43 | 46 | $CriteriaRow = DB_fetch_array($Result); |
| 47 | + if ($CriteriaRow === false) { |
| 48 | + /* Criteria no longer exists — skip this rating */ |
| 49 | + continue; |
| 50 | + } |
44 | 51 | $Weight = $CriteriaRow['weight']; |
45 | 52 |
|
46 | 53 | $WeightedScore = $Rating * ($Weight / 100); |
|
57 | 64 | '" . $_SESSION['UserID'] . "', |
58 | 65 | NOW() |
59 | 66 | )"; |
60 | | - DB_query($SQL); |
| 67 | + DB_query($SQL, __('Could not insert performance rating')); |
61 | 68 |
|
62 | 69 | $TotalWeightedScore += $WeightedScore; |
63 | 70 | $TotalWeight += $Weight; |
|
105 | 112 | ORDER BY pr.reviewdate DESC, e.lastname, e.firstname"; |
106 | 113 | $Result = DB_query($SQL); |
107 | 114 |
|
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 | + } |
114 | 132 |
|
115 | | - echo '</select></td> |
| 133 | + echo '</select></td> |
116 | 134 | </tr> |
117 | 135 | </table> |
118 | 136 | </form>'; |
| 137 | + } |
119 | 138 | } |
120 | 139 |
|
121 | 140 | // Display rating form |
|
154 | 173 | <td><strong>' . __('Review Type') . ':</strong></td> |
155 | 174 | <td>' . __($ReviewRow['reviewtype']) . '</td> |
156 | 175 | <td><strong>' . __('Overall Rating') . ':</strong></td> |
157 | | - <td>' . __($ReviewRow['overallrating']) . '</td> |
| 176 | + <td>' . htmlspecialchars($ReviewRow['overallrating'], ENT_QUOTES, 'UTF-8') . '</td> |
158 | 177 | </tr> |
159 | 178 | </table> |
160 | 179 | </div>'; |
|
0 commit comments