X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=quotas.php;h=d846ae25d79196f4c5449bb33941caea26486738;hb=0fa80122e692abac96010f4da8ed55c3aa52b81b;hp=f648f9d2db1b895daac45d578453bc28d8f98b2c;hpb=c304a055bafbb8db6b94dbf538c4c74e88952189;p=timetracker.git diff --git a/quotas.php b/quotas.php index f648f9d2..d846ae25 100644 --- a/quotas.php +++ b/quotas.php @@ -1,20 +1,47 @@ isPluginEnabled('mq')) { header('Location: access_denied.php'); exit(); } -// fallback values +// Start and end fallback values for the Year dropdown. $yearStart = 2015; $yearEnd = 2030; +// If values are defined in config - use them. if (defined('MONTHLY_QUOTA_YEAR_START')){ $yearStart = (int)MONTHLY_QUOTA_YEAR_START; } @@ -22,42 +49,42 @@ if (defined('MONTHLY_QUOTA_YEAR_END')){ $yearEnd = (int)MONTHLY_QUOTA_YEAR_END; } -// create values for dropdown +// Create values for the Year dropdown. $years = array(); -for ($i=$yearStart; $i <= $yearEnd; $i++) { - array_push($years, array('id'=>$i, 'name'=>$i)); +for ($i = $yearStart; $i <= $yearEnd; $i++) { + array_push($years, array('id'=>$i,'name'=>$i)); } -// get selected year from url parameters -$selectedYear = $request->getParameter("year"); +// Get selected year from url parameter. +$selectedYear = $request->getParameter('year'); if (!$selectedYear or !ttValidInteger($selectedYear)){ - $selectedYear = date("Y"); + $selectedYear = date('Y'); } else { $selectedYear = intval($selectedYear); } -// months are zero indexed +// Months are zero indexed. $months = $i18n->monthNames; $quota = new MonthlyQuota(); if ($request->isPost()){ + // TODO: Add parameter validation. $res = false; - // if user pressed save fpr monthly quotas - if ($_POST["quotas"]){ - $postedYear = $request->getParameter("years"); + 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++){ + 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)); - } if ($res) { header('Location: profile_edit.php'); exit(); @@ -66,21 +93,21 @@ if ($request->isPost()){ } } -// returns months where January is month 1, not 0 +// Returns monthly quotas where January is month 1, not 0. $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]; } $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'=>3,'value'=> $value,'style'=>'width:50px')); } -$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'));