From: Nik Okuntseff Date: Mon, 19 Nov 2018 09:05:24 +0000 (+0000) Subject: Populated group_id and org_id in tt_fav_reports table. X-Git-Tag: timetracker_1.19-1~617 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=f1025fe95f90cd8dc7fa3b3f75617e447ab33f2e;p=timetracker.git Populated group_id and org_id in tt_fav_reports table. --- diff --git a/WEB-INF/lib/ttFavReportHelper.class.php b/WEB-INF/lib/ttFavReportHelper.class.php index 305a4fc8..ab9fa0e0 100644 --- a/WEB-INF/lib/ttFavReportHelper.class.php +++ b/WEB-INF/lib/ttFavReportHelper.class.php @@ -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']).", ". diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index 4c57739b..c57cc640 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -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')); + } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index f7d31bb2..463340b7 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.19.4454 | Copyright © Anuko | +  Anuko Time Tracker 1.18.19.4455 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/dbinstall.php b/dbinstall.php index 7dda4213..0d8ea9a4 100644 --- a/dbinstall.php +++ b/dbinstall.php @@ -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"]) { diff --git a/reports.php b/reports.php index 6a0687e6..efbf9642 100644 --- a/reports.php +++ b/reports.php @@ -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()) {