X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=quotas.php;h=375d8a781c3e2fb2f567e8cb7fc8290eb08cd9b8;hb=4b203ad8b61fde986390ebc7d44727089d0595b4;hp=1dfa06fa207f4138ce319aee8edc78890e218512;hpb=f74704271ae5d37aee3fdf941f3462c8b92ad0fd;p=timetracker.git diff --git a/quotas.php b/quotas.php index 1dfa06fa..375d8a78 100644 --- a/quotas.php +++ b/quotas.php @@ -30,9 +30,10 @@ require_once('initialize.php'); require_once('plugins/MonthlyQuota.class.php'); import('form.Form'); import('ttTeamHelper'); +import('ttTimeHelper'); // Access check. -if (!ttAccessCheck(right_manage_team)) { +if (!ttAccessCheck(right_manage_team) || !$user->isPluginEnabled('mq')) { header('Location: access_denied.php'); exit(); } @@ -69,43 +70,52 @@ $months = $i18n->monthNames; $quota = new MonthlyQuota(); if ($request->isPost()){ - // TODO: Add parameter validation. - $res = false; - if ($_POST['btn_hours']){ + // Validate user input. + for ($i = 0; $i < count($months); $i++){ + $val = $request->getParameter($months[$i]); + if (!ttTimeHelper::isValidQuota($val)) + $err->add($i18n->getKey('error.field'), $months[$i]); + } + // Finished validating user input. + + if ($err->no()) { - // User changed workday hours for team. + // Handle workday hours. $hours = (int)$request->getParameter('workdayHours'); - $res = ttTeamHelper::update($user->team_id, array('name'=>$user->team,'workday_hours'=>$hours)); - } - if ($_POST['btn_submit']){ - // User pressed the Save button under monthly quotas table. - $postedYear = $request->getParameter('year'); - $selectedYear = intval($postedYear); + if ($hours != $user->workday_hours) { + if (!ttTeamHelper::update($user->team_id, array('name'=>$user->team,'workday_hours'=>$hours))) + $err->add($i18n->getKey('error.db')); + } + + // Handle monthly quotas for a selected year. + $selectedYear = intval($request->getParameter('year')); for ($i = 0; $i < count($months); $i++){ - $res = $quota->update($postedYear, $i+1, $request->getParameter($months[$i])); + if (!$quota->update($selectedYear, $i+1, $request->getParameter($months[$i]))) + $err->add($i18n->getKey('error.db')); + } + + if ($err->no()) { + // Redisplay the form. + header('Location: quotas.php?year='.$selectedYear); + exit(); } - } - if ($res) { - header('Location: profile_edit.php'); - exit(); - } else { - $err->add($i18n->getKey('error.db')); } } -// Returns monthly quotas where January is month 1, not 0. +// Get monthly quotas for the entire year. $monthsData = $quota->get($selectedYear); $form = new Form('monthlyQuotasForm'); -$form->addInput(array('type'=>'text', 'name'=>'workdayHours', 'value'=>$quota->getWorkdayHours(), 'style'=>'width:50px')); +$form->addInput(array('type'=>'text', 'name'=>'workdayHours', 'value'=>$user->workday_hours, 'style'=>'width:50px')); $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); } $name = $months[$i]; - $form->addInput(array('type'=>'text','name'=>$name,'maxlength'=>3,'value'=> $value,'style'=>'width:50px')); + $form->addInput(array('type'=>'text','name'=>$name,'maxlength'=>6,'value'=> $value,'style'=>'width:70px')); } $smarty->assign('months', $months);