3 require_once('initialize.php');
 
   4 require_once('plugins/MonthlyQuota.class.php');
 
   6 import('WEB-INF/lib/ttTeamHelper');
 
   9 if (!ttAccessCheck(right_manage_team)) {
 
  10   header('Location: access_denied.php');
 
  18 if (defined('MONTHLY_QUOTA_YEAR_START')){
 
  19   $yearStart = (int)MONTHLY_QUOTA_YEAR_START;
 
  21 if (defined('MONTHLY_QUOTA_YEAR_END')){
 
  22   $yearEnd = (int)MONTHLY_QUOTA_YEAR_END;
 
  25 // create values for dropdown
 
  27 for ($i=$yearStart; $i <= $yearEnd; $i++) {
 
  28   array_push($years, array('id'=>$i, 'name'=>$i));
 
  31 // get selected year from url parameters
 
  32 $selectedYear = $request->getParameter("year");
 
  33 if (!$selectedYear or !ttValidInteger($selectedYear)){
 
  34   $selectedYear = date("Y");
 
  36   $selectedYear = intval($selectedYear);
 
  39 // months are zero indexed
 
  40 $months = $i18n->monthNames;
 
  42 $quota = new MonthlyQuota();
 
  44 if ($request->isPost()){
 
  46   // if user pressed save fpr monthly quotas
 
  47   if ($_POST["quotas"]){
 
  48     $postedYear = $request->getParameter("years");
 
  49     $selectedYear = intval($postedYear);
 
  50     for ($i=0; $i < count($months); $i++){
 
  51       $res = $quota->update($postedYear, $i+1, $request->getParameter($months[$i]));
 
  54   // if user saved required working hours for a day
 
  55   if ($_POST["dailyHours"]){
 
  56     $hours = $request->getParameter("dailyWorkingHours");
 
  57     $teamDetails = ttTeamHelper::getTeamDetails($quota->usersTeamId);
 
  58     $res = ttTeamHelper::update($quota->usersTeamId, array('name'=>$teamDetails['team_name'], 
 
  59                                                            'workday_hours'=>$hours));
 
  62     header('Location: profile_edit.php');
 
  65     $err->add($i18n->getKey('error.db'));
 
  69 // returns months where January is month 1, not 0
 
  70 $monthsData = $quota->get($selectedYear);
 
  72 $form = new Form('monthlyQuotaForm');
 
  74 $form->addInput(array('type'=>'combobox', 'name'=>'years', 'data'=>$years, 'datakeys'=>array('id', 'name'), 'value'=>$selectedYear, 'onchange'=>'yearChange(this.value);'));
 
  75 for ($i=0; $i < count($months); $i++) { 
 
  77   if (array_key_exists($i+1, $monthsData)){
 
  78     $value = $monthsData[$i+1];
 
  81   $form->addInput(array('type'=>'text', 'name'=>$name, 'maxlength'=>3, 'value'=> $value, 'style'=>'width:50px'));
 
  83 $form->addInput(array('type'=>'text', 'name'=>'dailyWorkingHours', 'value'=>$quota->getDailyWorkingHours(), 'style'=>'width:50px'));
 
  84 $smarty->assign('months', $months);
 
  85 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
 
  86 $smarty->assign('title', $i18n->getKey('title.monthly_quota'));
 
  87 $smarty->assign('content_page_name', 'cf_monthly_quota.tpl');
 
  88 $smarty->display('index.tpl');