2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
29 require_once('initialize.php');
30 require_once('plugins/MonthlyQuota.class.php');
32 import('ttTeamHelper');
35 if (!ttAccessCheck(right_manage_team) || !$user->isPluginEnabled('mq')) {
36 header('Location: access_denied.php');
40 // Start and end fallback values for the Year dropdown.
44 // If values are defined in config - use them.
45 if (defined('MONTHLY_QUOTA_YEAR_START')){
46 $yearStart = (int)MONTHLY_QUOTA_YEAR_START;
48 if (defined('MONTHLY_QUOTA_YEAR_END')){
49 $yearEnd = (int)MONTHLY_QUOTA_YEAR_END;
52 // Create values for the Year dropdown.
54 for ($i = $yearStart; $i <= $yearEnd; $i++) {
55 array_push($years, array('id'=>$i,'name'=>$i));
58 // Get selected year from url parameter.
59 $selectedYear = $request->getParameter('year');
60 if (!$selectedYear or !ttValidInteger($selectedYear)){
61 $selectedYear = date('Y');
63 $selectedYear = intval($selectedYear);
66 // Months are zero indexed.
67 $months = $i18n->monthNames;
69 $quota = new MonthlyQuota();
71 if ($request->isPost()){
72 // TODO: Add parameter validation.
74 if ($_POST['btn_hours']){
76 // User changed workday hours for team.
77 $hours = (int)$request->getParameter('workdayHours');
78 $res = ttTeamHelper::update($user->team_id, array('name'=>$user->team,'workday_hours'=>$hours));
80 if ($_POST['btn_submit']){
81 // User pressed the Save button under monthly quotas table.
82 $postedYear = $request->getParameter('year');
83 $selectedYear = intval($postedYear);
84 for ($i = 0; $i < count($months); $i++){
85 $res = $quota->update($postedYear, $i+1, $request->getParameter($months[$i]));
89 header('Location: profile_edit.php');
92 $err->add($i18n->getKey('error.db'));
96 // Get monthly quotas for the entire year.
97 $monthsData = $quota->get($selectedYear);
99 $form = new Form('monthlyQuotasForm');
100 $form->addInput(array('type'=>'text', 'name'=>'workdayHours', 'value'=>$user->workday_hours, 'style'=>'width:50px'));
101 $form->addInput(array('type'=>'combobox','name'=>'year','data'=>$years,'datakeys'=>array('id','name'),'value'=>$selectedYear,'onchange'=>'yearChange(this.value);'));
102 for ($i=0; $i < count($months); $i++) {
104 if (array_key_exists($i+1, $monthsData)){
105 $value = $monthsData[$i+1];
108 $form->addInput(array('type'=>'text','name'=>$name,'maxlength'=>3,'value'=> $value,'style'=>'width:50px'));
111 $smarty->assign('months', $months);
112 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
113 $smarty->assign('title', $i18n->getKey('title.monthly_quotas'));
114 $smarty->assign('content_page_name', 'quotas.tpl');
115 $smarty->display('index.tpl');