A bit more work in progress on subgroups.
authorNik Okuntseff <support@anuko.com>
Fri, 2 Nov 2018 17:36:47 +0000 (17:36 +0000)
committerNik Okuntseff <support@anuko.com>
Fri, 2 Nov 2018 17:36:47 +0000 (17:36 +0000)
WEB-INF/lib/ttGroupHelper.class.php
WEB-INF/lib/ttUser.class.php
WEB-INF/templates/footer.tpl
WEB-INF/templates/time.tpl
time.php

index d28c306..22362b5 100644 (file)
@@ -48,4 +48,18 @@ class ttGroupHelper {
     }
     return false;
   }
+
+  // The getGroupName function returns group name.
+  static function getGroupName($group_id) {
+    $mdb2 = getConnection();
+
+    $sql = "select name from tt_groups where id = $group_id and (status = 1 or status = 0)";
+    $res = $mdb2->query($sql);
+
+    if (!is_a($res, 'PEAR_Error')) {
+      $val = $res->fetchRow();
+      return $val['name'];
+    }
+    return false;
+  }
 }
index e7fa3fa..21cd19a 100644 (file)
@@ -155,7 +155,7 @@ class ttUser {
       // Set "on behalf" id and name (group).
       if (isset($_SESSION['behalf_group_id'])) {
           $this->behalf_group_id = $_SESSION['behalf_group_id'];
-          $this->behalf_group = $_SESSION['behalf_group'];
+          $this->behalf_group = $_SESSION['behalf_group_name'];
       }
     }
   }
@@ -371,6 +371,7 @@ class ttUser {
     $mdb2 = getConnection();
 
     $selected_group_id = ($this->behalf_group_id ? $this->behalf_group_id : $this->group_id);
+    $selected_group_name = ($this->behalf_group_id ? $this->behalf_group : $this->group);
 
     // Start with parent group.
     if ($selected_group_id != $this->org_id) {
@@ -394,7 +395,6 @@ class ttUser {
     }
 
     // Add current group.
-    $selected_group_name = ($this->behalf_group_id ? $this->behalf_group : $this->group);
     $groups[] = array('id'=>$selected_group_id,'name'=>$selected_group_name);
 
     // Add subgroups.
index e635a97..3f32ac0 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.18.06.4350 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.18.06.4351 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
index f532be4..0e05f05 100644 (file)
   <tr>
     <td valign="top">
       <table>
+{if $on_behalf_group_control}
+        <tr>
+          <td align="right">{$i18n.label.group}:</td>
+          <td>{$forms.timeRecordForm.onBehalfGroup.control}</td>
+        </tr>
+{/if}
 {if $on_behalf_control}
         <tr>
           <td align="right">{$i18n.label.user}:</td>
index 98f6bba..5307d8b 100644 (file)
--- a/time.php
+++ b/time.php
@@ -29,6 +29,7 @@
 require_once('initialize.php');
 import('form.Form');
 import('ttUserHelper');
+import('ttGroupHelper');
 import('ttTeamHelper');
 import('ttClientHelper');
 import('ttTimeHelper');
@@ -95,6 +96,7 @@ if ($user->isPluginEnabled('iv')) {
       $cl_billable = $_SESSION['billable'];
 }
 $on_behalf_id = $request->getParameter('onBehalfUser', (isset($_SESSION['behalf_id'])? $_SESSION['behalf_id'] : $user->id));
+$on_behalf_group_id = $request->getParameter('onBehalfGroup', (isset($_SESSION['behalf_group_id'])? $_SESSION['behalf_group_id'] : $user->group_id));
 $cl_client = $request->getParameter('client', ($request->isPost() ? null : @$_SESSION['client']));
 $_SESSION['client'] = $cl_client;
 $cl_project = $request->getParameter('project', ($request->isPost() ? null : @$_SESSION['project']));
@@ -105,6 +107,22 @@ $_SESSION['task'] = $cl_task;
 // Elements of timeRecordForm.
 $form = new Form('timeRecordForm');
 
+if (defined('SUBGROUP_DEBUG') && isTrue(SUBGROUP_DEBUG)) {
+if ($user->can('manage_subgroups')) {
+  $groups = $user->getGroups();
+  if (count($groups) > 1) {
+    $form->addInput(array('type'=>'combobox',
+      'onchange'=>'this.form.submit();',
+      'name'=>'onBehalfGroup',
+      'style'=>'width: 250px;',
+      'value'=>$on_behalf_group_id,
+      'data'=>$groups,
+      'datakeys'=>array('id','name')));
+    $smarty->assign('on_behalf_group_control', 1);
+  }
+}
+} // SUBGROUP_DEBUG
+
 if ($user->can('track_time')) {
   if ($user->can('track_own_time'))
     $options = array('status'=>ACTIVE,'max_rank'=>$user->rank-1,'include_self'=>true,'self_first'=>true);
@@ -347,6 +365,19 @@ if ($request->isPost()) {
       exit();
     }
   }
+  elseif ($request->getParameter('onBehalfGroup')) {
+    if($user->can('manage_subgroups')) {
+      unset($_SESSION['behalf_group_id']);
+      unset($_SESSION['behalf_group_name']);
+
+      if($on_behalf_group_id != $user->group_id) {
+        $_SESSION['behalf_group_id'] = $on_behalf_group_id;
+        $_SESSION['behalf_group_name'] = ttGroupHelper::getGroupName($on_behalf_group_id);
+      }
+      header('Location: time.php');
+      exit();
+    }
+  }
   elseif ($request->getParameter('onBehalfUser')) {
     if($user->can('track_time')) {
       unset($_SESSION['behalf_id']);