Populated group_id and org_id in tt_fav_reports table.
authorNik Okuntseff <support@anuko.com>
Mon, 19 Nov 2018 09:05:24 +0000 (09:05 +0000)
committerNik Okuntseff <support@anuko.com>
Mon, 19 Nov 2018 09:05:24 +0000 (09:05 +0000)
WEB-INF/lib/ttFavReportHelper.class.php
WEB-INF/lib/ttOrgImportHelper.class.php
WEB-INF/templates/footer.tpl
dbinstall.php
reports.php

index 305a4fc..ab9fa0e 100644 (file)
@@ -77,16 +77,21 @@ class ttFavReportHelper {
 
   // insertReport - stores reports settings in database.
   static function insertReport($fields) {
+    global $user;
     $mdb2 = getConnection();
 
-    $sql = "insert into tt_fav_reports (name, user_id, client_id, cf_1_option_id, project_id, task_id,
-      billable, invoice, paid_status, users, period, period_start, period_end,
-      show_client, show_invoice, show_paid, show_ip,
-      show_project, show_start, show_duration, show_cost,
-      show_task, show_end, show_note, show_custom_field_1, show_work_units,
-      group_by1, group_by2, group_by3, show_totals_only)
-      values(".
-      $mdb2->quote($fields['name']).", ".$fields['user_id'].", ".
+    $group_id = $user->getActiveGroup();
+    $org_id = $user->org_id;
+
+    $sql = "insert into tt_fav_reports".
+      " (name, user_id, group_id, org_id, client_id, cf_1_option_id, project_id, task_id,".
+      " billable, invoice, paid_status, users, period, period_start, period_end,".
+      " show_client, show_invoice, show_paid, show_ip,".
+      " show_project, show_start, show_duration, show_cost,".
+      " show_task, show_end, show_note, show_custom_field_1, show_work_units,".
+      " group_by1, group_by2, group_by3, show_totals_only)".
+      " values(".
+      $mdb2->quote($fields['name']).", ".$fields['user_id'].", $group_id, $org_id, ".
       $mdb2->quote($fields['client']).", ".$mdb2->quote($fields['option']).", ".
       $mdb2->quote($fields['project']).", ".$mdb2->quote($fields['task']).", ".
       $mdb2->quote($fields['billable']).", ".$mdb2->quote($fields['invoice']).", ".
index 4c57739..c57cc64 100644 (file)
@@ -462,9 +462,11 @@ class ttOrgImportHelper {
           foreach ($arr as $v)
             $user_list .= (strlen($user_list) == 0 ? '' : ',').$this->currentGroupUserMap[$v];
         }
-        $fav_report_id = ttFavReportHelper::insertReport(array(
+        if (!$this->insertFavReport(array(
           'name' => $attrs['NAME'],
           'user_id' => $this->currentGroupUserMap[$attrs['USER_ID']],
+          'group_id' => $this->current_group_id,
+          'org_id' => $this->org_id,
           'client' => $this->currentGroupClientMap[$attrs['CLIENT_ID']],
           'option' => $this->currentGroupCustomFieldOptionMap[$attrs['CF_1_OPTION_ID']],
           'project' => $this->currentGroupProjectMap[$attrs['PROJECT_ID']],
@@ -490,8 +492,9 @@ class ttOrgImportHelper {
           'group_by1' => $attrs['GROUP_BY1'],
           'group_by2' => $attrs['GROUP_BY2'],
           'group_by3' => $attrs['GROUP_BY3'],
-          'chtotalsonly' => (int) $attrs['SHOW_TOTALS_ONLY']));
-         if (!$fav_report_id) $this->errors->add($i18n->get('error.db'));
+          'chtotalsonly' => (int) $attrs['SHOW_TOTALS_ONLY']))) {
+           $this->errors->add($i18n->get('error.db'));
+         }
          return;
       }
     }
@@ -746,4 +749,35 @@ class ttOrgImportHelper {
 
     return $last_id;
   }
+
+  // insertFavReport - inserts a favorite report in database.
+  private function insertFavReport($fields) {
+    $mdb2 = getConnection();
+
+    $group_id = (int) $fields['group_id'];
+    $org_id = (int) $fields['org_id'];
+
+    $sql = "insert into tt_fav_reports".
+      " (name, user_id, group_id, org_id, client_id, cf_1_option_id, project_id, task_id,".
+      " billable, invoice, paid_status, users, period, period_start, period_end,".
+      " show_client, show_invoice, show_paid, show_ip,".
+      " show_project, show_start, show_duration, show_cost,".
+      " show_task, show_end, show_note, show_custom_field_1, show_work_units,".
+      " group_by1, group_by2, group_by3, show_totals_only)".
+      " values(".
+      $mdb2->quote($fields['name']).", ".$fields['user_id'].", $group_id, $org_id, ".
+      $mdb2->quote($fields['client']).", ".$mdb2->quote($fields['option']).", ".
+      $mdb2->quote($fields['project']).", ".$mdb2->quote($fields['task']).", ".
+      $mdb2->quote($fields['billable']).", ".$mdb2->quote($fields['invoice']).", ".
+      $mdb2->quote($fields['paid_status']).", ".
+      $mdb2->quote($fields['users']).", ".$mdb2->quote($fields['period']).", ".
+      $mdb2->quote($fields['from']).", ".$mdb2->quote($fields['to']).", ".
+      $fields['chclient'].", ".$fields['chinvoice'].", ".$fields['chpaid'].", ".$fields['chip'].", ".
+      $fields['chproject'].", ".$fields['chstart'].", ".$fields['chduration'].", ".$fields['chcost'].", ".
+      $fields['chtask'].", ".$fields['chfinish'].", ".$fields['chnote'].", ".$fields['chcf_1'].", ".$fields['chunits'].", ".
+      $mdb2->quote($fields['group_by1']).", ".$mdb2->quote($fields['group_by2']).", ".
+      $mdb2->quote($fields['group_by3']).", ".$fields['chtotalsonly'].")";
+    $affected = $mdb2->exec($sql);
+    return (!is_a($affected, 'PEAR_Error'));
+  }
 }
index f7d31bb..463340b 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.19.4454 | 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.19.4455 | 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 7dda421..0d8ea9a 100644 (file)
@@ -1013,6 +1013,7 @@ if ($_POST) {
     setChange("ALTER TABLE `tt_fav_reports` ADD `group_id` int(11) default NULL AFTER `user_id`");
     setChange("ALTER TABLE `tt_fav_reports` ADD `org_id` int(11) default NULL AFTER `group_id`");
     setChange("UPDATE `tt_site_config` SET param_value = '1.18.19', modified = now() where param_name = 'version_db' and param_value = '1.18.18'");
+    setChange("update `tt_fav_reports` fr inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.18.19') inner join `tt_users` u on u.id = fr.user_id set fr.group_id = u.group_id, fr.org_id = u.org_id where fr.org_id is null");
   }
 
   if ($_POST["cleanup"]) {
index 6a0687e..efbf964 100644 (file)
@@ -298,7 +298,7 @@ if ($request->isPost()) {
     if (!ttValidString($bean->getAttribute('new_fav_report'))) $err->add($i18n->get('error.field'), $i18n->get('form.reports.save_as_favorite'));
 
     if ($err->no()) {
-      $id = ttFavReportHelper::saveReport($user->id, $bean);
+      $id = ttFavReportHelper::saveReport($user->id, $bean); // TODO: review "on behalf" situations (both user and group), redesign if needed.
       if (!$id)
         $err->add($i18n->get('error.db'));
       if ($err->no()) {