- $res = false;
- if ($_POST["quotas"]){
- // User pressed the Save button under monthly quotas table.
- $postedYear = $request->getParameter('years');
- $selectedYear = intval($postedYear);
+ // Validate user input.
+ $workdayMinutes = ttTimeHelper::postedDurationToMinutes($request->getParameter('workdayHours'));
+ if (false === $workdayMinutes || $workdayMinutes <= 0 )
+ $err->add($i18n->get('error.field'), $i18n->get('form.quota.workday_hours'));
+
+ for ($i = 0; $i < count($months); $i++){
+ $val = $request->getParameter($months[$i]);
+ $monthMinutes = ttTimeHelper::postedDurationToMinutes($val, 44640/*24*60*31*/);
+ if (false === $monthMinutes || $monthMinutes < 0)
+ $err->add($i18n->get('error.field'), $months[$i]);
+ }
+ // Finished validating user input.
+
+ if ($err->no()) {
+
+ // Handle workday hours.
+ $workday_minutes = ttTimeHelper::postedDurationToMinutes($request->getParameter('workdayHours'));
+ if ($workday_minutes != $user->getWorkdayMinutes()) {
+ if (!$user->updateGroup(array('workday_minutes'=>$workday_minutes)))
+ $err->add($i18n->get('error.db'));
+ }
+
+ // Handle monthly quotas for a selected year.
+ $selectedYear = (int) $request->getParameter('year');