Skip to content

Commit 0296d29

Browse files
committed
Fixes #916
1. User creates a review in HRPerformanceReviews.php - Selects an optional Rating Scale from dropdown - Scale is saved to hrperformancereviews.scaleid 2. User enters ratings in HRPerformanceRatings.php - System loads the review's associated rating scale - Rating dropdown is dynamically generated from scale's min/max values - Users rate using the custom scale (e.g., 1-10 or 1-3 instead of just 1-5) 3. Backward Compatibility - If no scale is selected, defaults to 1-5 (original behavior) - Existing reviews without a scale still work - Scale field is optional Files changed in commit: HRPerformanceRatings.php HRPerformanceReviews.php sql/updates/61.php
1 parent d216d06 commit 0296d29

3 files changed

Lines changed: 58 additions & 15 deletions

File tree

HRPerformanceRatings.php

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,21 @@
137137
}
138138
}
139139

140-
// Display rating form
140+
// Display rating form
141141
if (isset($_GET['ReviewID']) || isset($_POST['ReviewID'])) {
142142
$ReviewID = isset($_GET['ReviewID']) ? (int)$_GET['ReviewID'] : (int)$_POST['ReviewID'];
143143

144-
// Get review details
144+
// Get review details with scale information
145145
$SQL = "SELECT pr.*,
146146
e.firstname, e.lastname, e.employeenumber,
147147
d.description,
148-
p.positiontitle
148+
p.positiontitle,
149+
hs.minvalue, hs.maxvalue
149150
FROM hrperformancereviews pr
150151
INNER JOIN hremployees e ON pr.employeeid = e.employeeid
151152
LEFT JOIN departments d ON e.departmentid = d.departmentid
152153
LEFT JOIN hrpositions p ON e.positionid = p.positionid
154+
LEFT JOIN hrratingscales hs ON pr.scaleid = hs.scaleid
153155
WHERE pr.reviewid = " . $ReviewID;
154156
$Result = DB_query($SQL);
155157
$ReviewRow = DB_fetch_array($Result);
@@ -229,13 +231,17 @@
229231
<td class="number">' . number_format($Row['weight'], 1) . '%</td>
230232
<td>
231233
<select name="Rating_' . $Row['criteriaid'] . '" required="required">
232-
<option value="">' . __('Select') . '</option>
233-
<option value="5"' . ($ExistingRating == 5 ? ' selected="selected"' : '') . '>5 - ' . __('Outstanding') . '</option>
234-
<option value="4"' . ($ExistingRating == 4 ? ' selected="selected"' : '') . '>4 - ' . __('Exceeds Expectations') . '</option>
235-
<option value="3"' . ($ExistingRating == 3 ? ' selected="selected"' : '') . '>3 - ' . __('Meets Expectations') . '</option>
236-
<option value="2"' . ($ExistingRating == 2 ? ' selected="selected"' : '') . '>2 - ' . __('Needs Improvement') . '</option>
237-
<option value="1"' . ($ExistingRating == 1 ? ' selected="selected"' : '') . '>1 - ' . __('Unsatisfactory') . '</option>
238-
</select>
234+
<option value="">' . __('Select') . '</option>';
235+
236+
/* Use rating scale from review if available, otherwise default to 1-5 */
237+
$MinRating = isset($ReviewRow['minvalue']) && $ReviewRow['minvalue'] !== NULL ? (int)$ReviewRow['minvalue'] : 1;
238+
$MaxRating = isset($ReviewRow['maxvalue']) && $ReviewRow['maxvalue'] !== NULL ? (int)$ReviewRow['maxvalue'] : 5;
239+
240+
for ($i = $MaxRating; $i >= $MinRating; $i--) {
241+
echo '<option value="' . $i . '"' . ($ExistingRating == $i ? ' selected="selected"' : '') . '>' . $i . '</option>';
242+
}
243+
244+
echo '</select>
239245
</td>
240246
<td><input type="text" name="Comments_' . $Row['criteriaid'] . '" value="' . htmlspecialchars($ExistingComments) . '" size="50" /></td>
241247
</tr>';
@@ -251,10 +257,14 @@
251257

252258
echo '</div>';
253259

254-
// Display existing overall score if available
260+
/* Display existing overall score if available */
255261
if ($ReviewRow['overallscore'] > 0) {
262+
$MinRating = isset($ReviewRow['minvalue']) && $ReviewRow['minvalue'] !== NULL ? (int)$ReviewRow['minvalue'] : 1;
263+
$MaxRating = isset($ReviewRow['maxvalue']) && $ReviewRow['maxvalue'] !== NULL ? (int)$ReviewRow['maxvalue'] : 5;
264+
$MaxPossibleScore = $MaxRating;
265+
256266
echo '<div style="margin-top: 20px; padding: 15px; background-color: #c8e6c9; border: 1px solid #4caf50;">
257-
<h3>' . __('Current Overall Score') . ': ' . number_format($ReviewRow['overallscore'], 2) . ' / 5.00</h3>
267+
<h3>' . __('Current Overall Score') . ': ' . number_format($ReviewRow['overallscore'], 2) . ' / ' . number_format($MaxPossibleScore, 2) . '</h3>
258268
</div>';
259269
}
260270

HRPerformanceReviews.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
reviewercomments = '" . $_POST['ReviewerComments'] . "',
5050
employeecomments = '" . $_POST['EmployeeComments'] . "',
5151
nextreviewdate = " . $NextReviewDate . ",
52+
scaleid = " . (isset($_POST['ScaleID']) && (int)$_POST['ScaleID'] > 0 ? (int)$_POST['ScaleID'] : 'NULL') . ",
5253
modifiedby = '" . $_SESSION['UserID'] . "',
5354
modifieddate = NOW()
5455
WHERE reviewid = " . (int)$_POST['ReviewID'];
@@ -64,7 +65,7 @@
6465
reviewerid, overallrating, reviewtype, status,
6566
strengths, areasforimprovement, goals,
6667
reviewercomments, employeecomments, nextreviewdate,
67-
createdby, createddate
68+
scaleid, createdby, createddate
6869
) VALUES (
6970
" . (int)$_POST['EmployeeID'] . ",
7071
'" . $ReviewDate . "',
@@ -80,6 +81,7 @@
8081
'" . $_POST['ReviewerComments'] . "',
8182
'" . $_POST['EmployeeComments'] . "',
8283
" . $NextReviewDate . ",
84+
" . (isset($_POST['ScaleID']) && (int)$_POST['ScaleID'] > 0 ? (int)$_POST['ScaleID'] : 'NULL') . ",
8385
'" . $_SESSION['UserID'] . "',
8486
NOW()
8587
)";
@@ -119,6 +121,7 @@
119121
$ReviewerComments = '';
120122
$EmployeeComments = '';
121123
$NextReviewDate = '';
124+
$ScaleID = 0;
122125

123126
if ($ReviewID > 0) {
124127
$SQL = "SELECT * FROM hrperformancereviews WHERE reviewid = " . $ReviewID;
@@ -139,6 +142,7 @@
139142
$ReviewerComments = $Row['reviewercomments'];
140143
$EmployeeComments = $Row['employeecomments'];
141144
$NextReviewDate = ConvertSQLDate($Row['nextreviewdate']);
145+
$ScaleID = $Row['scaleid'];
142146
}
143147
}
144148

@@ -216,6 +220,22 @@
216220
</select>
217221
</field>
218222
223+
<field>
224+
<label for="ScaleID">' . __('Rating Scale') . ':</label>
225+
<select name="ScaleID">
226+
<option value="">' . __('Select Rating Scale (Optional)') . '</option>';
227+
228+
$SQL = "SELECT scaleid, scalename FROM hrratingscales WHERE active = 1 ORDER BY scalename";
229+
$Result = DB_query($SQL);
230+
while ($Row = DB_fetch_array($Result)) {
231+
echo '<option value="' . $Row['scaleid'] . '"' .
232+
($ScaleID == $Row['scaleid'] ? ' selected="selected"' : '') .
233+
'>' . htmlspecialchars($Row['scalename'], ENT_QUOTES, 'UTF-8') . '</option>';
234+
}
235+
236+
echo '</select>
237+
</field>
238+
219239
<field>
220240
<label for="OverallRating">' . __('Overall Rating') . ':</label>
221241
<select name="OverallRating" required="required">
@@ -315,7 +335,7 @@
315335
316336
<hr style="margin: 20px 0;" />
317337
318-
<h3>' . __('Overall Rating') . ': <span style="color: #d32f2f;">' . __($ReviewRow['overallrating']) . '</span></h3>
338+
<h3>' . __('Overall Rating') . ': <span style="color: #d32f2f;">' . htmlspecialchars($ReviewRow['overallrating'], ENT_QUOTES, 'UTF-8') . '</span></h3>
319339
320340
<h3>' . __('Key Strengths') . '</h3>
321341
<p style="white-space: pre-wrap; padding: 10px; background-color: white; border: 1px solid #ccc;">' . htmlspecialchars($ReviewRow['strengths']) . '</p>
@@ -443,7 +463,7 @@
443463
<td>' . ConvertSQLDate($Row['reviewdate']) . '</td>
444464
<td>' . ConvertSQLDate($Row['reviewperiodstart']) . ' to ' . ConvertSQLDate($Row['reviewperiodend']) . '</td>
445465
<td>' . __($Row['reviewtype']) . '</td>
446-
<td><strong>' . __($Row['overallrating']) . '</strong></td>
466+
<td><strong>' . htmlspecialchars($Row['overallrating'], ENT_QUOTES, 'UTF-8') . '</strong></td>
447467
<td>' . ($Row['reviewerfirstname'] ? $Row['reviewerfirstname'] . ' ' . $Row['reviewerlastname'] : '-') . '</td>
448468
<td>' . __($Row['status']) . '</td>
449469
<td>

sql/updates/61.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/* Add rating scale support to performance reviews */
4+
5+
$SQL = "ALTER TABLE hrperformancereviews
6+
ADD COLUMN scaleid INT(11) DEFAULT NULL,
7+
ADD CONSTRAINT fk_review_scale FOREIGN KEY (scaleid) REFERENCES hrratingscales (scaleid) ON DELETE SET NULL";
8+
9+
DB_query($SQL, __('Failed to add scaleid to hrperformancereviews'));
10+
11+
if ($_SESSION['Updates']['Errors'] == 0) {
12+
UpdateDBNo(basename(__FILE__, '.php'), __('Add rating scale support to performance reviews'));
13+
}

0 commit comments

Comments
 (0)