X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=quotas.php;h=0336d44c38fccd3b3bd5fd0a9df8a4acd3a93286;hb=77ee17dc3eaba0f878d95c6c73b52ed891c002fe;hp=edf064e2432fb49184cc2332b059551cbffa0f1b;hpb=b1fe1560c671e89e586e683e359cbb96cd25a8bc;p=timetracker.git diff --git a/quotas.php b/quotas.php index edf064e2..0336d44c 100644 --- a/quotas.php +++ b/quotas.php @@ -30,18 +30,19 @@ 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(); } -// Fallback values for start and end year. +// Start and end fallback values for the Year dropdown. $yearStart = 2015; $yearEnd = 2030; -// If values are defined in config - get them. +// If values are defined in config - use them. if (defined('MONTHLY_QUOTA_YEAR_START')){ $yearStart = (int)MONTHLY_QUOTA_YEAR_START; } @@ -49,7 +50,7 @@ if (defined('MONTHLY_QUOTA_YEAR_END')){ $yearEnd = (int)MONTHLY_QUOTA_YEAR_END; } -// Create values for year dropdown. +// Create values for the Year dropdown. $years = array(); for ($i = $yearStart; $i <= $yearEnd; $i++) { array_push($years, array('id'=>$i,'name'=>$i)); @@ -69,45 +70,57 @@ $months = $i18n->monthNames; $quota = new MonthlyQuota(); if ($request->isPost()){ - $res = false; - if ($_POST["quotas"]){ - // User pressed the Save button under monthly quotas table. - $postedYear = $request->getParameter('years'); - $selectedYear = intval($postedYear); - for ($i = 0; $i < count($months); $i++){ - $res = $quota->update($postedYear, $i+1, $request->getParameter($months[$i])); - } - } - // if user saved required working hours for a day - if ($_POST["dailyHours"]){ - $hours = $request->getParameter("dailyWorkingHours"); - $teamDetails = ttTeamHelper::getTeamDetails($quota->usersTeamId); - $res = ttTeamHelper::update($quota->usersTeamId, array('name'=>$teamDetails['team_name'], - 'workday_hours'=>$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]); } - if ($res) { - header('Location: profile_edit.php'); - exit(); - } else { - $err->add($i18n->getKey('error.db')); + // 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)); + } + 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])); + } + } + if ($res) { + // header('Location: profile_edit.php'); + header('Location: quotas.php'); // For debugging. + exit(); + } else { + $err->add($i18n->getKey('error.db')); + } } } -// returns months where January is month 1, not 0 +// Get monthly quotas for the entire year. $monthsData = $quota->get($selectedYear); -$form = new Form('monthlyQuotaForm'); - -$form->addInput(array('type'=>'combobox', 'name'=>'years', 'data'=>$years, 'datakeys'=>array('id', 'name'), 'value'=>$selectedYear, 'onchange'=>'yearChange(this.value);')); +$form = new Form('monthlyQuotasForm'); +$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')); } -$form->addInput(array('type'=>'text', 'name'=>'dailyWorkingHours', 'value'=>$quota->getDailyWorkingHours(), 'style'=>'width:50px')); + $smarty->assign('months', $months); $smarty->assign('forms', array($form->getName()=>$form->toArray())); $smarty->assign('title', $i18n->getKey('title.monthly_quotas'));