X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=quotas.php;h=06fdbbe5a55769604f9f6d17f9880b2aa149c3d4;hb=75b65e92b21d45e2b09fb12daef169fb214a7acd;hp=d79e433ab5a6b4017cace19ea90b65bb1cfa5127;hpb=ad89dda4fdde5dd9be57cfe0f1f7ec609acf02b6;p=timetracker.git diff --git a/quotas.php b/quotas.php index d79e433a..06fdbbe5 100644 --- a/quotas.php +++ b/quotas.php @@ -33,7 +33,7 @@ import('ttTeamHelper'); import('ttTimeHelper'); // Access check. -if (!ttAccessCheck(right_manage_team) || !$user->isPluginEnabled('mq')) { +if (!ttAccessAllowed('manage_advanced_settings') || !$user->isPluginEnabled('mq')) { header('Location: access_denied.php'); exit(); } @@ -71,9 +71,12 @@ $quota = new MonthlyQuota(); if ($request->isPost()){ // Validate user input. + if (false === ttTimeHelper::postedDurationToMinutes($request->getParameter('workdayHours'))) + $err->add($i18n->getKey('error.field'), $i18n->getKey('form.quota.workday_hours')); + for ($i = 0; $i < count($months); $i++){ $val = $request->getParameter($months[$i]); - if (!ttTimeHelper::isValidQuota($val)) + if (false === ttTimeHelper::postedDurationToMinutes($val, 44640/*24*60*31*/)) $err->add($i18n->getKey('error.field'), $months[$i]); } // Finished validating user input. @@ -81,16 +84,17 @@ if ($request->isPost()){ if ($err->no()) { // Handle workday hours. - $hours = (int)$request->getParameter('workdayHours'); - if ($hours != $user->workday_hours) { - if (!ttTeamHelper::update($user->team_id, array('name'=>$user->team,'workday_hours'=>$hours))) + $workday_minutes = ttTimeHelper::postedDurationToMinutes($request->getParameter('workdayHours')); + if ($workday_minutes != $user->workday_minutes) { + if (!ttTeamHelper::update($user->team_id, array('name'=>$user->team,'workday_minutes'=>$workday_minutes))) $err->add($i18n->getKey('error.db')); } // Handle monthly quotas for a selected year. $selectedYear = (int) $request->getParameter('year'); for ($i = 0; $i < count($months); $i++){ - if (!$quota->update($selectedYear, $i+1, $request->getParameter($months[$i]))) + $quota_in_minutes = ttTimeHelper::postedDurationToMinutes($request->getParameter($months[$i]), 44640/*24*60*31*/); + if (!$quota->update($selectedYear, $i+1, $quota_in_minutes)) $err->add($i18n->getKey('error.db')); } @@ -104,15 +108,16 @@ if ($request->isPost()){ // Get monthly quotas for the entire year. $monthsData = $quota->get($selectedYear); +$workdayHours = ttTimeHelper::toAbsDuration($user->workday_minutes, true); $form = new Form('monthlyQuotasForm'); -$form->addInput(array('type'=>'text', 'name'=>'workdayHours', 'value'=>$user->workday_hours, 'style'=>'width:50px')); +$form->addInput(array('type'=>'text', 'name'=>'workdayHours', 'value'=>$workdayHours, 'style'=>'width:60px')); $form->addInput(array('type'=>'combobox','name'=>'year','data'=>$years,'datakeys'=>array('id','name'),'value'=>$selectedYear,'onchange'=>'yearChange(this.value);')); for ($i=0; $i < count($months); $i++) { $value = ""; if (array_key_exists($i+1, $monthsData)){ $value = $monthsData[$i+1]; - $value = ttTimeHelper::toAbsDuration($value * 60, true); + $value = ttTimeHelper::toAbsDuration($value, true); } $name = $months[$i]; $form->addInput(array('type'=>'text','name'=>$name,'maxlength'=>6,'value'=> $value,'style'=>'width:70px'));