Skip to content

Commit 7797eda

Browse files
committed
Some refactoring for subgroups.
1 parent 6cdff51 commit 7797eda

41 files changed

Lines changed: 95 additions & 95 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

WEB-INF/lib/ttClientHelper.class.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static function getClient($client_id, $all_fields = false) {
4141
else
4242
$sql .= 'name ';
4343

44-
$sql .= "from tt_clients where group_id = ".$user->getActiveGroup().
44+
$sql .= "from tt_clients where group_id = ".$user->getGroup().
4545
" and id = $client_id and (status = 1 or status = 0)";
4646
$res = $mdb2->query($sql);
4747
if (!is_a($res, 'PEAR_Error')) {
@@ -59,7 +59,7 @@ static function getClients()
5959
$result = array();
6060
$mdb2 = getConnection();
6161

62-
$sql = "select id, name from tt_clients where group_id = ".$user->getActiveGroup()." and (status = 0 or status = 1) order by upper(name)";
62+
$sql = "select id, name from tt_clients where group_id = ".$user->getGroup()." and (status = 0 or status = 1) order by upper(name)";
6363
$res = $mdb2->query($sql);
6464
if (!is_a($res, 'PEAR_Error')) {
6565
while ($val = $res->fetchRow()) {
@@ -75,7 +75,7 @@ static function getClientByName($client_name) {
7575
$mdb2 = getConnection();
7676
global $user;
7777

78-
$sql = "select id from tt_clients where group_id = ".$user->getActiveGroup().
78+
$sql = "select id from tt_clients where group_id = ".$user->getGroup().
7979
" and name = ".$mdb2->quote($client_name)." and (status = 1 or status = 0)";
8080

8181
$res = $mdb2->query($sql);
@@ -94,7 +94,7 @@ static function getDeletedClient($client_id) {
9494
$mdb2 = getConnection();
9595
global $user;
9696

97-
$sql = "select name, address from tt_clients where group_id = ".$user->getActiveGroup().
97+
$sql = "select name, address from tt_clients where group_id = ".$user->getGroup().
9898
" and id = $client_id and status is NULL";
9999
$res = $mdb2->query($sql);
100100
if (!is_a($res, 'PEAR_Error')) {
@@ -137,7 +137,7 @@ static function delete($id, $delete_client_entries) {
137137

138138
// Handle invoices.
139139
if ($delete_client_entries) {
140-
$sql = "update tt_invoices set status = NULL where client_id = $id and group_id = ".$user->getActiveGroup();
140+
$sql = "update tt_invoices set status = NULL where client_id = $id and group_id = ".$user->getGroup();
141141
$affected = $mdb2->exec($sql);
142142
if (is_a($affected, 'PEAR_Error'))
143143
return false;
@@ -150,13 +150,13 @@ static function delete($id, $delete_client_entries) {
150150
return false;
151151

152152
// Handle users for client.
153-
$sql = 'update tt_users set status = NULL'.$modified_part." where client_id = $id and group_id = ".$user->getActiveGroup();
153+
$sql = 'update tt_users set status = NULL'.$modified_part." where client_id = $id and group_id = ".$user->getGroup();
154154
$affected = $mdb2->exec($sql);
155155
if (is_a($affected, 'PEAR_Error'))
156156
return false;
157157

158158
// Mark client deleted.
159-
$sql = "update tt_clients set status = NULL where id = $id and group_id = ".$user->getActiveGroup();
159+
$sql = "update tt_clients set status = NULL where id = $id and group_id = ".$user->getGroup();
160160
$affected = $mdb2->exec($sql);
161161
return (!is_a($affected, 'PEAR_Error'));
162162
}
@@ -237,7 +237,7 @@ static function update($fields)
237237
$comma_separated = implode(",", $projects); // This is a comma-separated list of associated project ids.
238238
$sql = "update tt_clients set name = ".$mdb2->quote($name).", address = ".$mdb2->quote($address).
239239
", tax = $tax, projects = ".$mdb2->quote($comma_separated).", status = $status".
240-
" where group_id = ".$user->getActiveGroup()." and id = ".$id;
240+
" where group_id = ".$user->getGroup()." and id = ".$id;
241241
$affected = $mdb2->exec($sql);
242242
return (!is_a($affected, 'PEAR_Error'));
243243
}
@@ -273,7 +273,7 @@ static function getAssignedProjects($client_id)
273273
// Do a query with inner join to get assigned projects.
274274
$sql = "select p.id, p.name from tt_projects p".
275275
" inner join tt_client_project_binds cpb on (cpb.client_id = $client_id and cpb.project_id = p.id)".
276-
" where p.group_id = ".$user->getActiveGroup()." and p.status = 1 order by p.name";
276+
" where p.group_id = ".$user->getGroup()." and p.status = 1 order by p.name";
277277
$res = $mdb2->query($sql);
278278
if (!is_a($res, 'PEAR_Error')) {
279279
while ($val = $res->fetchRow()) {

WEB-INF/lib/ttExpenseHelper.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static function insert($fields)
3535
$mdb2 = getConnection();
3636

3737
$user_id = $user->getActiveUser();
38-
$group_id = $user->getActiveGroup();
38+
$group_id = $user->getGroup();
3939
$org_id = $user->org_id;
4040

4141
$date = $fields['date'];

WEB-INF/lib/ttFavReportHelper.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static function insertReport($fields) {
8080
global $user;
8181
$mdb2 = getConnection();
8282

83-
$group_id = $user->getActiveGroup();
83+
$group_id = $user->getGroup();
8484
$org_id = $user->org_id;
8585

8686
$sql = "insert into tt_fav_reports".

WEB-INF/lib/ttGroupHelper.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static function getSubgroupByName($name) {
6767
global $user;
6868

6969
$mdb2 = getConnection();
70-
$parent_id = $user->getActiveGroup();
70+
$parent_id = $user->getGroup();
7171
$org_id = $user->org_id;
7272

7373
$sql = "select id from tt_groups where parent_id = $parent_id and org_id = $org_id".
@@ -86,7 +86,7 @@ static function insertSubgroup($fields) {
8686
global $user;
8787

8888
$mdb2 = getConnection();
89-
$parent_id = $user->getActiveGroup();
89+
$parent_id = $user->getGroup();
9090
$org_id = $user->org_id;
9191
$name = $fields['name'];
9292
$description = $fields['description'];
@@ -259,7 +259,7 @@ static function getRoles() {
259259
global $user;
260260
$mdb2 = getConnection();
261261

262-
$group_id = $user->getActiveGroup();
262+
$group_id = $user->getGroup();
263263
$org_id = $user->org_id;
264264
$sql = "select * from tt_roles".
265265
" where group_id = $group_id and org_id = $org_id and status is not null";

WEB-INF/lib/ttInvoiceHelper.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static function getInvoice($invoice_id) {
7373
if ($user->isClient()) $client_part = " and client_id = $user->client_id";
7474

7575
$sql = "select * from tt_invoices where id = $invoice_id and group_id = ".
76-
$user->getActiveGroup()."$client_part and status = 1";
76+
$user->getGroup()."$client_part and status = 1";
7777
$res = $mdb2->query($sql);
7878
if (!is_a($res, 'PEAR_Error')) {
7979
if ($val = $res->fetchRow())
@@ -89,7 +89,7 @@ static function getInvoiceByName($invoice_name) {
8989
global $user;
9090

9191
$sql = "select id from tt_invoices where group_id = ".
92-
$user->getActiveGroup()." and name = ".$mdb2->quote($invoice_name)." and status = 1";
92+
$user->getGroup()." and name = ".$mdb2->quote($invoice_name)." and status = 1";
9393
$res = $mdb2->query($sql);
9494
if (!is_a($res, 'PEAR_Error')) {
9595
$val = $res->fetchRow();
@@ -236,7 +236,7 @@ static function delete($invoice_id, $delete_invoice_items) {
236236
$affected = $mdb2->exec($sql);
237237
if (is_a($affected, 'PEAR_Error')) return false;
238238

239-
$sql = "update tt_invoices set status = NULL where id = $invoice_id and group_id = ".$user->getActiveGroup();
239+
$sql = "update tt_invoices set status = NULL where id = $invoice_id and group_id = ".$user->getGroup();
240240
$affected = $mdb2->exec($sql);
241241
return (!is_a($affected, 'PEAR_Error'));
242242
}
@@ -332,7 +332,7 @@ static function createInvoice($fields) {
332332

333333
// Create a new invoice record.
334334
$sql = "insert into tt_invoices (group_id, org_id, name, date, client_id) values(".
335-
$user->getActiveGroup().", $user->org_id, ".$mdb2->quote($name).", ".$mdb2->quote($date).", $client_id)";
335+
$user->getGroup().", $user->org_id, ".$mdb2->quote($name).", ".$mdb2->quote($date).", $client_id)";
336336
$affected = $mdb2->exec($sql);
337337
if (is_a($affected, 'PEAR_Error')) return false;
338338

WEB-INF/lib/ttNotificationHelper.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static function get($id)
3838

3939
$sql = "select c.id, c.cron_spec, c.report_id, c.email, c.cc, c.subject, c.report_condition, c.status, fr.name from tt_cron c
4040
left join tt_fav_reports fr on (fr.id = c.report_id)
41-
where c.id = $id and c.group_id = ".$user->getActiveGroup();
41+
where c.id = $id and c.group_id = ".$user->getGroup();
4242
$res = $mdb2->query($sql);
4343
if (!is_a($res, 'PEAR_Error')) {
4444
$val = $res->fetchRow();
@@ -54,7 +54,7 @@ static function delete($id) {
5454

5555
$mdb2 = getConnection();
5656

57-
$sql = "delete from tt_cron where id = $id and group_id = ".$user->getActiveGroup();
57+
$sql = "delete from tt_cron where id = $id and group_id = ".$user->getGroup();
5858
$affected = $mdb2->exec($sql);
5959
if (is_a($affected, 'PEAR_Error'))
6060
return false;
@@ -68,7 +68,7 @@ static function insert($fields)
6868
global $user;
6969
$mdb2 = getConnection();
7070

71-
$group_id = $user->getActiveGroup();
71+
$group_id = $user->getGroup();
7272
$org_id = $user->org_id;
7373
$cron_spec = $fields['cron_spec'];
7474
$next = (int) $fields['next'];

WEB-INF/lib/ttPredefinedExpenseHelper.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static function get($id)
3939
$mdb2 = getConnection();
4040

4141
$sql = "select id, name, cost from tt_predefined_expenses
42-
where id = $id and group_id = ".$user->getActiveGroup();
42+
where id = $id and group_id = ".$user->getGroup();
4343
$res = $mdb2->query($sql);
4444
if (!is_a($res, 'PEAR_Error')) {
4545
$val = $res->fetchRow();
@@ -58,7 +58,7 @@ static function delete($id) {
5858

5959
$mdb2 = getConnection();
6060

61-
$sql = "delete from tt_predefined_expenses where id = $id and group_id = ".$user->getActiveGroup();
61+
$sql = "delete from tt_predefined_expenses where id = $id and group_id = ".$user->getGroup();
6262
$affected = $mdb2->exec($sql);
6363
if (is_a($affected, 'PEAR_Error'))
6464
return false;
@@ -73,7 +73,7 @@ static function insert($fields)
7373

7474
$mdb2 = getConnection();
7575

76-
$group_id = $user->getActiveGroup();
76+
$group_id = $user->getGroup();
7777
$org_id = $user->org_id;
7878
$name = $fields['name'];
7979
$cost = $fields['cost'];
@@ -96,7 +96,7 @@ static function update($fields)
9696

9797
$mdb2 = getConnection();
9898

99-
$group_id = $user->getActiveGroup();
99+
$group_id = $user->getGroup();
100100
$org_id = $user->org_id;
101101
$predefined_expense_id = (int) $fields['id'];
102102
$name = $fields['name'];

WEB-INF/lib/ttProjectHelper.class.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static function getAssignedProjects($user_id)
4343
// Do a query with inner join to get assigned projects.
4444
$sql = "select p.id, p.name, p.tasks, upb.rate from tt_projects p".
4545
" inner join tt_user_project_binds upb on (upb.user_id = $user_id and upb.project_id = p.id and upb.status = 1)".
46-
" where p.group_id = ".$user->getActiveGroup()." and p.status = 1 order by p.name";
46+
" where p.group_id = ".$user->getGroup()." and p.status = 1 order by p.name";
4747
$res = $mdb2->query($sql);
4848
if (!is_a($res, 'PEAR_Error')) {
4949
while ($val = $res->fetchRow()) {
@@ -63,7 +63,7 @@ static function getRates($user_id)
6363

6464
$sql = "select p.id, upb.rate from tt_projects p".
6565
" inner join tt_user_project_binds upb on (upb.user_id = $user_id and upb.project_id = p.id)".
66-
" where group_id = ".$user->getActiveGroup();
66+
" where group_id = ".$user->getGroup();
6767
$res = $mdb2->query($sql);
6868
if (!is_a($res, 'PEAR_Error')) {
6969
while ($val = $res->fetchRow()) {
@@ -83,7 +83,7 @@ static function getProjects()
8383
$mdb2 = getConnection();
8484

8585
$sql = "select id, name, tasks from tt_projects".
86-
" where group_id = ".$user->getActiveGroup()." and (status = 0 or status = 1) order by name";
86+
" where group_id = ".$user->getGroup()." and (status = 0 or status = 1) order by name";
8787

8888
$res = $mdb2->query($sql);
8989
if (!is_a($res, 'PEAR_Error')) {
@@ -104,7 +104,7 @@ static function getProjectsForClient()
104104

105105
$sql = "select p.id, p.name, p.tasks from tt_projects p".
106106
" inner join tt_client_project_binds cpb on (cpb.client_id = $user->client_id and cpb.project_id = p.id)".
107-
" where p.group_id = ".$user->getActiveGroup()." and (p.status = 0 or p.status = 1)".
107+
" where p.group_id = ".$user->getGroup()." and (p.status = 0 or p.status = 1)".
108108
" order by p.name";
109109

110110
$res = $mdb2->query($sql);
@@ -125,7 +125,7 @@ static function get($id)
125125
$mdb2 = getConnection();
126126

127127
$sql = "select id, name, description, status, tasks from tt_projects where id = $id and group_id = ".
128-
$user->getActiveGroup()." and (status = 0 or status = 1)";
128+
$user->getGroup()." and (status = 0 or status = 1)";
129129
$res = $mdb2->query($sql);
130130
if (!is_a($res, 'PEAR_Error')) {
131131
$val = $res->fetchRow();
@@ -142,7 +142,7 @@ static function getProjectByName($name) {
142142
global $user;
143143

144144
$sql = "select id from tt_projects where group_id = ".
145-
$user->getActiveGroup()." and name = ".$mdb2->quote($name).
145+
$user->getGroup()." and name = ".$mdb2->quote($name).
146146
" and (status = 1 or status = 0)";
147147
$res = $mdb2->query($sql);
148148
if (!is_a($res, 'PEAR_Error')) {
@@ -159,7 +159,7 @@ static function delete($id) {
159159
global $user;
160160
$mdb2 = getConnection();
161161

162-
$group_id = $user->getActiveGroup();
162+
$group_id = $user->getGroup();
163163
$org_id = $user->org_id;
164164

165165
// Start with project itself. Reason: if the passed in project_id is bogus,
@@ -245,7 +245,7 @@ static function update($fields) {
245245
global $user;
246246
$mdb2 = getConnection();
247247

248-
$group_id = $user->getActiveGroup();
248+
$group_id = $user->getGroup();
249249
$org_id = $user->org_id;
250250
$project_id = $fields['id']; // Project we are updating.
251251
$name = $fields['name']; // Project name.
@@ -323,7 +323,7 @@ static function update($fields) {
323323
// Update project name, description, tasks and status in tt_projects table.
324324
$comma_separated = implode(",", $tasks_to_bind); // This is a comma-separated list of associated task ids.
325325
$sql = "update tt_projects set name = ".$mdb2->quote($name).", description = ".$mdb2->quote($description).
326-
", tasks = ".$mdb2->quote($comma_separated).", status = $status where id = $project_id and group_id = ".$user->getActiveGroup();
326+
", tasks = ".$mdb2->quote($comma_separated).", status = $status where id = $project_id and group_id = ".$user->getGroup();
327327
$affected = $mdb2->exec($sql);
328328
return (!is_a($affected, 'PEAR_Error'));
329329
}

WEB-INF/lib/ttReportHelper.class.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static function getWhere($options) {
6262
$user_list_part = " and l.user_id in ($userlist)";
6363
else
6464
$user_list_part = " and l.user_id = ".$user->id;
65-
$user_list_part .= " and l.group_id = ".$user->getActiveGroup();
65+
$user_list_part .= " and l.group_id = ".$user->getGroup();
6666

6767
// Prepare sql query part for where.
6868
if ($options['period'])
@@ -100,7 +100,7 @@ static function getExpenseWhere($options) {
100100
$user_list_part = " and ei.user_id in ($userlist)";
101101
else
102102
$user_list_part = " and ei.user_id = ".$user->id;
103-
$user_list_part .= " and ei.group_id = ".$user->getActiveGroup();
103+
$user_list_part .= " and ei.group_id = ".$user->getGroup();
104104

105105
// Prepare sql query part for where.
106106
if ($options['period'])
@@ -157,7 +157,7 @@ static function getItems($options) {
157157
// Add custom field.
158158
$include_cf_1 = $options['show_custom_field_1'] || $grouping_by_cf_1;
159159
if ($include_cf_1) {
160-
$custom_fields = new CustomFields($user->getActiveGroup());
160+
$custom_fields = new CustomFields($user->getGroup());
161161
$cf_1_type = $custom_fields->fields[0]['type'];
162162
if ($cf_1_type == CustomFields::TYPE_TEXT) {
163163
array_push($fields, 'cfl.value as cf_1');
@@ -616,7 +616,7 @@ static function prepareReportBody($options, $comment = null)
616616

617617
// Use custom fields plugin if it is enabled.
618618
if ($user->isPluginEnabled('cf'))
619-
$custom_fields = new CustomFields($user->getActiveGroup());
619+
$custom_fields = new CustomFields($user->getGroup());
620620

621621
// Define some styles to use in email.
622622
$style_title = 'text-align: center; font-size: 15pt; font-family: Arial, Helvetica, sans-serif;';
@@ -1460,7 +1460,7 @@ static function makeJoinPart($options) {
14601460
$join .= ' left join tt_tasks t on (l.task_id = t.id)';
14611461
}
14621462
if (ttReportHelper::groupingBy('cf_1', $options)) {
1463-
$custom_fields = new CustomFields($user->getActiveGroup());
1463+
$custom_fields = new CustomFields($user->getGroup());
14641464
if ($custom_fields->fields[0]['type'] == CustomFields::TYPE_TEXT)
14651465
$join .= ' left join tt_custom_field_log cfl on (l.id = cfl.log_id and cfl.status = 1) left join tt_custom_field_options cfo on (cfl.value = cfo.id)';
14661466
elseif ($custom_fields->fields[0]['type'] == CustomFields::TYPE_DROPDOWN)

WEB-INF/lib/ttRoleHelper.class.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static function get($id)
3737
$mdb2 = getConnection();
3838

3939
$sql = "select id, name, description, rank, rights, status from tt_roles
40-
where id = $id and group_id = ".$user->getActiveGroup()." and (status = 0 or status = 1)";
40+
where id = $id and group_id = ".$user->getGroup()." and (status = 0 or status = 1)";
4141
$res = $mdb2->query($sql);
4242

4343
if (!is_a($res, 'PEAR_Error')) {
@@ -56,7 +56,7 @@ static function getRoleByName($role_name) {
5656
$mdb2 = getConnection();
5757
global $user;
5858

59-
$sql = "select id from tt_roles where group_id = ".$user->getActiveGroup().
59+
$sql = "select id from tt_roles where group_id = ".$user->getGroup().
6060
" and name = ".$mdb2->quote($role_name)." and (status = 1 or status = 0)";
6161
$res = $mdb2->query($sql);
6262

@@ -89,7 +89,7 @@ static function isClientRole($role_id) {
8989
global $user;
9090
$mdb2 = getConnection();
9191

92-
$sql = "select rights from tt_roles where group_id = ".$user->getActiveGroup()." and id = $role_id";
92+
$sql = "select rights from tt_roles where group_id = ".$user->getGroup()." and id = $role_id";
9393
$res = $mdb2->query($sql);
9494

9595
if (!is_a($res, 'PEAR_Error')) {
@@ -124,7 +124,7 @@ static function update($fields) {
124124
global $user;
125125
$mdb2 = getConnection();
126126

127-
$group_id = $user->getActiveGroup();
127+
$group_id = $user->getGroup();
128128
$org_id = $user->org_id;
129129

130130
$id = (int)$fields['id'];
@@ -144,7 +144,7 @@ static function delete($role_id) {
144144
global $user;
145145

146146
$mdb2 = getConnection();
147-
$group_id = $user->getActiveGroup();
147+
$group_id = $user->getGroup();
148148
$org_id = $user->org_id;
149149

150150
// Mark the task as deleted.

0 commit comments

Comments
 (0)