Started to populate group_id and org_id in tt_user_project_binds.
authorNik Okuntseff <support@anuko.com>
Thu, 8 Nov 2018 15:57:34 +0000 (15:57 +0000)
committerNik Okuntseff <support@anuko.com>
Thu, 8 Nov 2018 15:57:34 +0000 (15:57 +0000)
WEB-INF/lib/ttImportHelper.class.php
WEB-INF/lib/ttProjectHelper.class.php
WEB-INF/lib/ttUserHelper.class.php
WEB-INF/templates/footer.tpl
user_add.php

index 64a32e0..307be16 100644 (file)
@@ -206,11 +206,19 @@ class ttImportHelper {
           'status' => $this->currentElement['STATUS']));
     }
     if ($name == 'USER_PROJECT_BIND' && $this->canImport) {
-      ttUserHelper::insertBind(
+/*
+        ttUserHelper::insertBind(
         $this->userMap[$this->currentElement['USER_ID']],
         $this->projectMap[$this->currentElement['PROJECT_ID']],
         $this->currentElement['RATE'],
-        $this->currentElement['STATUS']);
+        $this->currentElement['STATUS']);*/
+      ttUserHelper::insertBind2(array(
+        'user_id' => $this->userMap[$this->currentElement['USER_ID']],
+        'project_id' => $this->projectMap[$this->currentElement['PROJECT_ID']],
+        'group_id' => $this->group_id,
+        'org_id' => $this->org_id,
+        'rate' => $this->currentElement['RATE'],
+        'status' => $this->currentElement['STATUS']));
     }
 
     if ($name == 'CLIENT' && $this->canImport) {
index 72b7171..47783d5 100644 (file)
@@ -214,8 +214,8 @@ class ttProjectHelper {
     $active_users = ttTeamHelper::getActiveUsers(array('getAllFields'=>true));
     foreach ($active_users as $u) {
       if(in_array($u['id'], $users)) {
-        $sql = "insert into tt_user_project_binds (project_id, user_id, status, rate) values(
-          $last_id, ".$u['id'].", 1, ".$u['rate'].")";
+        $sql = "insert into tt_user_project_binds (project_id, user_id, group_id, org_id, status, rate) values(
+          $last_id, ".$u['id'].", $group_id, $org_id, 1, ".$u['rate'].")";
         $affected = $mdb2->exec($sql);
         if (is_a($affected, 'PEAR_Error'))
           return false;
@@ -271,8 +271,11 @@ class ttProjectHelper {
       while ($row = $res->fetchRow()) {
         $user_rate[$row['id']] = $row['rate'];
       }
+      $group_id = $user->getActiveGroup();
+      $org_id = $user->org_id;
       foreach ($users_to_add as $id) {
-        $sql = "insert into tt_user_project_binds (user_id, project_id, rate, status) values($id, $project_id, ".$user_rate[$id].", 1)";
+        $sql = "insert into tt_user_project_binds (user_id, project_id, group_id, org_id, rate, status)".
+          " values($id, $project_id, $group_id, $org_id, ".$user_rate[$id].", 1)";
         $affected = $mdb2->exec($sql);
         if (is_a($affected, 'PEAR_Error'))
           return false;
index 2817508..bd5e46b 100644 (file)
@@ -134,7 +134,8 @@ class ttUserHelper {
           else
             $p['rate'] = str_replace(',', '.', $p['rate']);
 
-          $sql = "insert into tt_user_project_binds (project_id, user_id, rate, status) values(".$p['id'].",".$last_id.",".$p['rate'].", 1)";
+          $sql = "insert into tt_user_project_binds (project_id, user_id, group_id, org_id, rate, status)".
+            " values(".$p['id'].", $last_id, $group_id, $org_id, ".$p['rate'].", 1)";
           $affected = $mdb2->exec($sql);
         }
       }
@@ -309,10 +310,33 @@ class ttUserHelper {
 
   // insertBind - inserts a user to project bind into tt_user_project_binds table.
   static function insertBind($user_id, $project_id, $rate, $status) {
+    global $user;
+    $mdb2 = getConnection();
+
+    $group_id = $user->getActiveGroup();
+    $org_id = $user->org_id;
+    $sql = "insert into tt_user_project_binds (user_id, project_id, group_id, org_id, rate, status)".
+      " values($user_id, $project_id, $group_id, $org_id, ".$mdb2->quote($rate).", $status)";
+    $affected = $mdb2->exec($sql);
+    return (!is_a($affected, 'PEAR_Error'));
+  }
+
+    // insertBind2 - inserts a user to project bind into tt_user_project_binds table.
+  static function insertBind2($fields) {
+    global $user;
     $mdb2 = getConnection();
 
-    $sql = "insert into tt_user_project_binds (user_id, project_id, rate, status)
-      values($user_id, $project_id, ".$mdb2->quote($rate).", $status)";
+    // This may be used during import. Use the following until we have import refactored.
+    $group_id = $fields['group_id'] ? (int) $fields['group_id'] : $user->getActiveGroup();
+    $org_id = $fields['org_id'] ? (int) $fields['org_id'] : $user->org_id;
+
+    $user_id = (int) $fields['user_id'];
+    $project_id = (int) $fields['project_id'];
+    $rate = $mdb2->quote($fields['rate']);
+    $status = $mdb2->quote($fields['status']);
+
+    $sql = "insert into tt_user_project_binds (user_id, project_id, group_id, org_id, rate, status)".
+      " values($user_id, $project_id, $group_id, $org_id, $rate, $status)";
     $affected = $mdb2->exec($sql);
     return (!is_a($affected, 'PEAR_Error'));
   }
index f807fe1..ee8659b 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.12.4387 | 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.12.4388 | 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 ac2d8c4..eb93914 100644 (file)
@@ -150,7 +150,7 @@ if ($request->isPost()) {
         'login' => $cl_login,
         'password' => $cl_password1,
         'rate' => $cl_rate,
-        'group_id' => $user->group_id, // TODO: this needs to be fixed for on-behalf group work.
+        'group_id' => $user->getActiveGroup(),
         'org_id' => $user->org_id,
         'role_id' => $cl_role_id,
         'client_id' => $cl_client_id,