From: Nik Okuntseff Date: Mon, 19 Nov 2018 19:40:18 +0000 (+0000) Subject: Populating group_id and org_id in tt_config table. X-Git-Tag: timetracker_1.19-1~607 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=cfc33172165a50572d74d808c3c523484f60800f;p=timetracker.git Populating group_id and org_id in tt_config table. --- diff --git a/WEB-INF/lib/ttSysConfig.class.php b/WEB-INF/lib/ttSysConfig.class.php index cb7637d1..fd990521 100644 --- a/WEB-INF/lib/ttSysConfig.class.php +++ b/WEB-INF/lib/ttSysConfig.class.php @@ -35,18 +35,23 @@ define('SYSC_LAST_INVOICE_CC', 'last_invoice_cc'); // Class ttSysConfig is used for storing and retrieving named values associated with users. class ttSysConfig { - var $u_id = null; + var $user_id = null; + var $group_id = null; + var $org_id = null; var $mdb2 = null; // Constructor. - function __construct($u_id) { - $this->u_id = $u_id; + function __construct($user_id) { + global $user; + $this->user_id = $user_id; // TODO: review "on behalf" situation and refactor if necessary. + $this->group_id = $user->getActiveGroup(); + $this->org_id = $user->org_id; $this->mdb2 = getConnection(); } // The getValue retrieves a value identified by name. function getValue($name) { - $res = $this->mdb2->query("select param_value from tt_config where user_id = ".$this->u_id." and param_name=".$this->mdb2->quote($name)); + $res = $this->mdb2->query("select param_value from tt_config where user_id = ".$this->user_id." and param_name=".$this->mdb2->quote($name)); if (!is_a($res, 'PEAR_Error')) { $val = $res->fetchRow(); return $val['param_value']; @@ -57,13 +62,15 @@ class ttSysConfig { // The setValue sets a value identified by name. function setValue($name, $value) { $rcnt = 0; - $res = $this->mdb2->query("select count(*) as rcnt from tt_config where user_id = ".$this->u_id." and param_name = ".$this->mdb2->quote($name)); + $res = $this->mdb2->query("select count(*) as rcnt from tt_config where user_id = ".$this->user_id." and param_name = ".$this->mdb2->quote($name)); if ($val = $res->fetchRow()) $rcnt = $val['rcnt']; if ($rcnt > 0) { - $affected = $this->mdb2->exec("update tt_config set param_value = ".$this->mdb2->quote($value)." where user_id = ".$this->u_id." and param_name=".$this->mdb2->quote($name)); + $affected = $this->mdb2->exec("update tt_config set param_value = ".$this->mdb2->quote($value)." where user_id = ".$this->user_id." and param_name=".$this->mdb2->quote($name)); } else { - $affected = $this->mdb2->exec("insert into tt_config set param_value = ".$this->mdb2->quote($value).", param_name = ".$this->mdb2->quote($name).", user_id = ".$this->u_id); + $sql = "insert into tt_config set param_value = ".$this->mdb2->quote($value). + ", param_name = ".$this->mdb2->quote($name).", user_id = ".$this->user_id.", group_id = ".$this->group_id.", org_id = ".$this->org_id; + $affected = $this->mdb2->exec($sql); } return (!is_a($affected, 'PEAR_Error')); } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 3315253f..92095cf0 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.22.4464 | Copyright © Anuko | +  Anuko Time Tracker 1.18.22.4465 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/dbinstall.php b/dbinstall.php index 5ee0337e..c65175d5 100644 --- a/dbinstall.php +++ b/dbinstall.php @@ -1025,6 +1025,7 @@ if ($_POST) { setChange("ALTER TABLE `tt_config` ADD `group_id` int(11) default NULL AFTER `user_id`"); setChange("ALTER TABLE `tt_config` ADD `org_id` int(11) default NULL AFTER `group_id`"); setChange("UPDATE `tt_site_config` SET param_value = '1.18.22', modified = now() where param_name = 'version_db' and param_value = '1.18.21'"); + setChange("update `tt_config` c inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.18.22') inner join `tt_users` u on u.id = c.user_id set c.group_id = u.group_id, c.org_id = u.org_id where c.org_id is null"); } if ($_POST["cleanup"]) {