From 5db12e31e86ebd4cb4be29851c07139edcca5ac4 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sat, 17 Nov 2018 12:04:20 +0000 Subject: [PATCH] Introduced org_id in tt_monthly_quotas table. --- WEB-INF/templates/footer.tpl | 2 +- dbinstall.php | 11 +++++++---- mysql.sql | 3 ++- plugins/MonthlyQuota.class.php | 16 ++++++++-------- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index ab54bf61..a89ed9b3 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- - - + +
 Anuko Time Tracker 1.18.14.4435 | Copyright © Anuko | +  Anuko Time Tracker 1.18.15.4436 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/dbinstall.php b/dbinstall.php index f02e9021..0c26a457 100644 --- a/dbinstall.php +++ b/dbinstall.php @@ -957,7 +957,7 @@ if ($_POST) { print "Updated $tt_expense_items_updated tt_expense_items records...
\n"; } - if ($_POST["convert11797to11814"]) { + if ($_POST["convert11797to11815"]) { setChange("ALTER TABLE `tt_fav_reports` CHANGE `group_by` `group_by1` varchar(20) default NULL"); setChange("ALTER TABLE `tt_fav_reports` ADD `group_by2` varchar(20) default NULL AFTER `group_by1`"); setChange("ALTER TABLE `tt_fav_reports` ADD `group_by3` varchar(20) default NULL AFTER `group_by2`"); @@ -997,6 +997,9 @@ if ($_POST) { setChange("ALTER TABLE `tt_invoices` MODIFY `name` varchar(80) COLLATE utf8mb4_bin NOT NULL"); setChange("ALTER TABLE `tt_clients` MODIFY `name` varchar(80) COLLATE utf8mb4_bin NOT NULL"); setChange("UPDATE `tt_site_config` SET param_value = '1.18.14', modified = now() where param_name = 'version_db' and param_value = '1.18.13'"); + setChange("ALTER TABLE `tt_monthly_quotas` ADD `org_id` int(11) default NULL AFTER `group_id`"); + setChange("UPDATE `tt_monthly_quotas` inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.18.14') set org_id = group_id where org_id is null"); + setChange("UPDATE `tt_site_config` SET param_value = '1.18.15', modified = now() where param_name = 'version_db' and param_value = '1.18.14'"); // TODO: this does not work as we just introduced group_id and it is NULL. Same for tt_project_task_binds. Improve. // setChange("UPDATE `tt_user_project_binds` inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.18.12') set org_id = group_id where org_id is null"); @@ -1045,7 +1048,7 @@ if ($_POST) {

DB Install

-
Create database structure (v1.18.14) + Create database structure (v1.18.15)
(applies only to new installations, do not execute when updating)
@@ -1090,8 +1093,8 @@ if ($_POST) {
Update database structure (v1.17.97 to v1.18.14)Update database structure (v1.17.97 to v1.18.15)
diff --git a/mysql.sql b/mysql.sql index 14a8aa0f..3652c528 100644 --- a/mysql.sql +++ b/mysql.sql @@ -449,6 +449,7 @@ CREATE TABLE `tt_predefined_expenses` ( # CREATE TABLE `tt_monthly_quotas` ( `group_id` int(11) NOT NULL, # group id + `org_id` int(11) default NULL # organization id `year` smallint(5) UNSIGNED NOT NULL, # quota year `month` tinyint(3) UNSIGNED NOT NULL, # quota month `minutes` int(11) default NULL, # quota in minutes in specified month and year @@ -469,4 +470,4 @@ CREATE TABLE `tt_site_config` ( PRIMARY KEY (`param_name`) ); -INSERT INTO `tt_site_config` (`param_name`, `param_value`, `created`) VALUES ('version_db', '1.18.14', now()); # TODO: change when structure changes. +INSERT INTO `tt_site_config` (`param_name`, `param_value`, `created`) VALUES ('version_db', '1.18.15', now()); # TODO: change when structure changes. diff --git a/plugins/MonthlyQuota.class.php b/plugins/MonthlyQuota.class.php index 5a4e7079..6a047bad 100644 --- a/plugins/MonthlyQuota.class.php +++ b/plugins/MonthlyQuota.class.php @@ -33,20 +33,22 @@ class MonthlyQuota { var $db; // Database connection. var $group_id; // Group id. + var $org_id; // Organization id. function __construct() { $this->db = getConnection(); global $user; - $this->group_id = $user->group_id; + $this->group_id = $user->getActiveGroup(); + $this->org_id = $user->org_id; } // update - deletes a quota, then inserts a new one. public function update($year, $month, $minutes) { - $group_id = $this->group_id; - $deleteSql = "DELETE FROM tt_monthly_quotas WHERE year = $year AND month = $month AND group_id = $group_id"; + $deleteSql = "DELETE FROM tt_monthly_quotas WHERE year = $year AND month = $month AND group_id = $this->group_id"; $this->db->exec($deleteSql); if ($minutes){ - $insertSql = "INSERT INTO tt_monthly_quotas (group_id, year, month, minutes) values ($group_id, $year, $month, $minutes)"; + $insertSql = "INSERT INTO tt_monthly_quotas (group_id, org_id, year, month, minutes)". + " values ($this->group_id, $this->org_id, $year, $month, $minutes)"; $affected = $this->db->exec($insertSql); return (!is_a($affected, 'PEAR_Error')); } @@ -64,8 +66,7 @@ class MonthlyQuota { // getSingle - obtains a quota for a single month. private function getSingle($year, $month) { - $group_id = $this->group_id; - $sql = "SELECT minutes FROM tt_monthly_quotas WHERE year = $year AND month = $month AND group_id = $group_id"; + $sql = "SELECT minutes FROM tt_monthly_quotas WHERE year = $year AND month = $month AND group_id = $this->group_id"; $reader = $this->db->query($sql); if (is_a($reader, 'PEAR_Error')) { return false; @@ -83,8 +84,7 @@ class MonthlyQuota { // getMany - returns an array of quotas for a given year for group. private function getMany($year){ - $group_id = $this->group_id; - $sql = "SELECT month, minutes FROM tt_monthly_quotas WHERE year = $year AND group_id = $group_id"; + $sql = "SELECT month, minutes FROM tt_monthly_quotas WHERE year = $year AND group_id = $this->group_id"; $result = array(); $res = $this->db->query($sql); if (is_a($res, 'PEAR_Error')) { -- 2.20.1