X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=quotas.php;h=1f376190ef6add417e57fa945f18afda2dedacb9;hb=bbea8c35f79ef9699e4b6deab0be3c1108628ef0;hp=d3e7912e7e28177ed0316808d4345141a65d7c4a;hpb=d27b08cc3e9c657bdb361379657d185f0ea47485;p=timetracker.git diff --git a/quotas.php b/quotas.php index d3e7912e..1f376190 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; @@ -71,30 +74,31 @@ $quota = new MonthlyQuota(); if ($request->isPost()){ // Validate user input. - if (!ttTimeHelper::isValidDuration($request->getParameter('workdayHours'))) - $err->add($i18n->getKey('error.field'), $i18n->getKey('form.quota.workday_hours')); + if (false === ttTimeHelper::postedDurationToMinutes($request->getParameter('workdayHours'))) + $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 (!$quota->isValidQuota($val)) - $err->add($i18n->getKey('error.field'), $months[$i]); + if (false === ttTimeHelper::postedDurationToMinutes($val, 44640/*24*60*31*/)) + $err->add($i18n->get('error.field'), $months[$i]); } // Finished validating user input. if ($err->no()) { // Handle workday hours. - $hours = $quota->quotaToFloat($request->getParameter('workdayHours')); - if ($hours != $user->workday_hours) { - if (!ttTeamHelper::update($user->team_id, array('name'=>$user->team,'workday_hours'=>$hours))) - $err->add($i18n->getKey('error.db')); + $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'); for ($i = 0; $i < count($months); $i++){ - if (!$quota->update($selectedYear, $i+1, $request->getParameter($months[$i]))) - $err->add($i18n->getKey('error.db')); + $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 ($err->no()) { @@ -107,7 +111,7 @@ if ($request->isPost()){ // Get monthly quotas for the entire year. $monthsData = $quota->get($selectedYear); -$workdayHours = ttTimeHelper::toAbsDuration($user->workday_hours * 60, true); +$workdayHours = ttTimeHelper::toAbsDuration($user->getWorkdayMinutes(), true); $form = new Form('monthlyQuotasForm'); $form->addInput(array('type'=>'text', 'name'=>'workdayHours', 'value'=>$workdayHours, 'style'=>'width:60px')); @@ -116,7 +120,7 @@ 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')); @@ -124,6 +128,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');