X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=quotas.php;h=b6d63fa3ec639939ede4bfff3d141bf6569da076;hb=ce2df23479c88d1bc9db04a68164af3feb6346e1;hp=0336d44c38fccd3b3bd5fd0a9df8a4acd3a93286;hpb=a84f7509ea5462f08ca01c5435e0217045391a45;p=timetracker.git diff --git a/quotas.php b/quotas.php index 0336d44c..b6d63fa3 100644 --- a/quotas.php +++ b/quotas.php @@ -29,14 +29,17 @@ require_once('initialize.php'); require_once('plugins/MonthlyQuota.class.php'); import('form.Form'); -import('ttTeamHelper'); import('ttTimeHelper'); -// Access check. -if (!ttAccessCheck(right_manage_team) || !$user->isPluginEnabled('mq')) { +// Access checks. +if (!ttAccessAllowed('manage_advanced_settings')) { header('Location: access_denied.php'); exit(); } +if (!$user->isPluginEnabled('mq')) { + header('Location: feature_disabled.php'); + exit(); +} // Start and end fallback values for the Year dropdown. $yearStart = 2015; @@ -61,7 +64,7 @@ $selectedYear = $request->getParameter('year'); if (!$selectedYear or !ttValidInteger($selectedYear)){ $selectedYear = date('Y'); } else { - $selectedYear = intval($selectedYear); + $selectedYear = (int) $selectedYear; } // Months are zero indexed. @@ -71,51 +74,55 @@ $quota = new MonthlyQuota(); if ($request->isPost()){ // 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]); - if (!ttTimeHelper::isValidQuota($val)) - $err->add($i18n->getKey('error.field'), $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()) { - $res = false; - if ($_POST['btn_hours']){ - - // User changed workday hours for team. - $hours = (int)$request->getParameter('workdayHours'); - $res = ttTeamHelper::update($user->team_id, array('name'=>$user->team,'workday_hours'=>$hours)); + // 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')); } - if ($_POST['btn_submit']){ - // User pressed the Save button under monthly quotas table. - $postedYear = $request->getParameter('year'); - $selectedYear = intval($postedYear); - for ($i = 0; $i < count($months); $i++){ - $res = $quota->update($postedYear, $i+1, $request->getParameter($months[$i])); - } + + // Handle monthly quotas for a selected year. + $selectedYear = (int) $request->getParameter('year'); + for ($i = 0; $i < count($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->get('error.db')); } - if ($res) { - // header('Location: profile_edit.php'); - header('Location: quotas.php'); // For debugging. + + if ($err->no()) { + // Redisplay the form. + header('Location: quotas.php?year='.$selectedYear); exit(); - } else { - $err->add($i18n->getKey('error.db')); } } } // Get monthly quotas for the entire year. $monthsData = $quota->get($selectedYear); +$workdayHours = ttTimeHelper::toAbsDuration($user->getWorkdayMinutes(), 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')); @@ -123,6 +130,6 @@ for ($i=0; $i < count($months); $i++) { $smarty->assign('months', $months); $smarty->assign('forms', array($form->getName()=>$form->toArray())); -$smarty->assign('title', $i18n->getKey('title.monthly_quotas')); +$smarty->assign('title', $i18n->get('title.monthly_quotas')); $smarty->assign('content_page_name', 'quotas.tpl'); $smarty->display('index.tpl');