A bit more progress with timesheets.
authorNik Okuntseff <support@anuko.com>
Mon, 18 Feb 2019 21:38:27 +0000 (21:38 +0000)
committerNik Okuntseff <support@anuko.com>
Mon, 18 Feb 2019 21:38:27 +0000 (21:38 +0000)
WEB-INF/templates/timesheets.tpl
timesheet_edit.php
timesheets.php

index 0ba8fd7..8c3acc9 100644 (file)
@@ -2,12 +2,15 @@
   function chLocation(newLocation) { document.location = newLocation; }
 </script>
 
+{$forms.timesheetsForm.open}
 <table cellspacing="0" cellpadding="7" border="0" width="720">
+  <tr><td align="left">{$i18n.form.timesheets.hint}<br></td></tr>
+{if $user_dropdown}
+  <tr><td align="center">{$i18n.label.user}: {$forms.timesheetsForm.user.control}</td></tr>
+{/if}
   <tr>
     <td valign="top">
       <table cellspacing="1" cellpadding="3" border="0" width="100%">
-        <tr><td colspan="2">{$i18n.form.timesheets.hint}<br></td></tr>
-        <tr><td>&nbsp;</td></tr>
   {if $inactive_timesheets}
         <tr><td class="sectionHeaderNoBorder">{$i18n.form.timesheets.active_timesheets}</td></tr>
   {/if}
@@ -58,3 +61,4 @@
     </td>
   </tr>
 </table>
+{$forms.timesheetsForm.close}
index e98d824..50d2a44 100644 (file)
@@ -72,7 +72,7 @@ if ($request->isPost()) {
 
   if ($err->no()) {
     if ($request->getParameter('btn_save')) {
-      $existing_timesheet = ttTimesheetHelper::getTimesheetByName($cl_name);
+      $existing_timesheet = ttTimesheetHelper::getTimesheetByName($cl_name, $timesheet['user_id']);
       if (!$existing_timesheet || ($cl_timesheet_id == $existing_timesheet['id'])) {
          // Update project information.
          if (ttTimesheetHelper::update(array(
index 191f749..fcdd401 100644 (file)
@@ -39,15 +39,53 @@ if (!(ttAccessAllowed('view_own_timesheets') ||
   header('Location: access_denied.php');
   exit();
 }
-
 if (!$user->isPluginEnabled('ts')) {
   header('Location: feature_disabled.php');
   exit();
 }
+if ($request->isPost()) {
+  $userChanged = $request->getParameter('user_changed');
+  if ($userChanged && !($user->can('track_time') && $user->isUserValid($request->getParameter('user')))) {
+    header('Location: access_denied.php'); // Group changed, but no rght or wrong user id.
+    exit();
+  }
+}
 // End of access checks.
 
-// TODO: determine user properly, using a dropdown.
-$user_id = $user->getUser();
+// Determine user for whom we display this page.
+if ($request->isPost() && $userChanged) {
+  $user_id = $request->getParameter('user');
+} else {
+  $user_id = $user->getUser();
+}
+
+$group_id = $user->getGroup();
+
+// Elements of timesheetsForm.
+$form = new Form('timesheetsForm');
+
+if ($user->can('view_timesheets') || $user->can('view_all_timesheets') || $user->can('manage_timesheets') || $user->can('manage_all_timesheets')) {
+  $rank = $user->getMaxRankForGroup($group_id);
+  if ($user->can('track_own_time'))
+    $options = array('group_id'=>$group_id,'status'=>ACTIVE,'max_rank'=>$rank,'include_self'=>true,'self_first'=>true);
+  else
+    $options = array('group_id'=>$group_id,'status'=>ACTIVE,'max_rank'=>$rank);
+  $user_list = $user->getUsers($options);
+  if (count($user_list) >= 1) {
+    $form->addInput(array('type'=>'combobox',
+      'onchange'=>'document.timesheetsForm.user_changed.value=1;document.timesheetsForm.submit();',
+      'name'=>'user',
+      'style'=>'width: 250px;',
+      'value'=>$user_id,
+      'data'=>$user_list,
+      'datakeys'=>array('id','name')));
+    $form->addInput(array('type'=>'hidden','name'=>'user_changed'));
+    $smarty->assign('user_dropdown', 1);
+  }
+}
+
+
+
 
 // TODO: fix this for client access.
 $active_timesheets = ttTimesheetHelper::getActiveTimesheets($user_id);
@@ -59,7 +97,7 @@ $smarty->assign('inactive_timesheets', $inactive_timesheets);
 $smarty->assign('show_client', $show_client);
 $smarty->assign('show_submit_status', !$user->isClient());
 $smarty->assign('show_approval_status', !$user->isClient());
-
+$smarty->assign('forms', array($form->getName()=>$form->toArray()));
 $smarty->assign('title', $i18n->get('title.timesheets'));
 $smarty->assign('content_page_name', 'timesheets.tpl');
 $smarty->display('index.tpl');