2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
29 // The ttRoleHelper is a class to help with custom group roles.
31 // insert - inserts an entry into tt_roles table.
32 static function insert($fields)
34 $mdb2 = getConnection();
36 $team_id = (int) $fields['team_id'];
37 $name = $fields['name'];
38 $rank = (int) $fields['rank'];
39 $rights = $fields['rights'];
40 $status = $fields['status'];
42 $sql = "insert into tt_roles (team_id, name, rank, rights, status)
43 values ($team_id, ".$mdb2->quote($name).", $rank, ".$mdb2->quote($rights).", ".$mdb2->quote($status).")";
44 $affected = $mdb2->exec($sql);
45 if (is_a($affected, 'PEAR_Error'))
51 // rolesExist - checks whether roles for team already exist.
52 static function rolesExist()
54 $mdb2 = getConnection();
57 $sql = "select count(*) as count from tt_roles where team_id = $user->team_id";
58 $res = $mdb2->query($sql);
59 if (!is_a($res, 'PEAR_Error')) {
60 $val = $res->fetchRow();
61 if ($val['count'] > 0)
62 return true; // Roles for team exist.
67 // createDefaultRoles - creates a set of predefined roles for the team to use.
68 static function createDefaultRoles()
70 $mdb2 = getConnection();
75 $name = $mdb2->quote($i18n->getKey('role.user.label'));
76 $description = $mdb2->quote($i18n->getKey('role.user.description'));
77 $rights = $mdb2->quote('data_entry,view_own_data,manage_own_settings,view_users');
78 $sql = "insert into tt_roles (team_id, name, description, rank, rights, status) values($user->team_id, $name, $description, 4, $rights, 1)";
79 $affected = $mdb2->exec($sql);
80 if (is_a($affected, 'PEAR_Error'))
83 $name = $mdb2->quote($i18n->getKey('role.client.label'));
84 $description = $mdb2->quote($i18n->getKey('role.client.description'));
85 $rights = $mdb2->quote('data_entry,view_own_data,manage_own_settings,view_users'); // TODO: adjust rights.
86 $sql = "insert into tt_roles (team_id, name, description, rank, rights, status) values($user->team_id, $name, $description, 16, $rights, 1)";
87 $affected = $mdb2->exec($sql);
88 if (is_a($affected, 'PEAR_Error'))
91 $name = $mdb2->quote($i18n->getKey('role.comanager.label'));
92 $description = $mdb2->quote($i18n->getKey('role.comanager.description'));
93 $rights = $mdb2->quote('data_entry,view_own_data,manage_own_settings,view_users'); // TODO: adjust rights.
94 $sql = "insert into tt_roles (team_id, name, description, rank, rights, status) values($user->team_id, $name, $description, 68, $rights, 1)";
95 $affected = $mdb2->exec($sql);
96 if (is_a($affected, 'PEAR_Error'))
99 $name = $mdb2->quote($i18n->getKey('role.manager.label'));
100 $description = $mdb2->quote($i18n->getKey('role.manager.description'));
101 $rights = $mdb2->quote('data_entry,view_own_data,manage_own_settings,view_users'); // TODO: adjust rights.
102 $sql = "insert into tt_roles (team_id, name, description, rank, rights, status) values($user->team_id, $name, $description, 324, $rights, 1)";
103 $affected = $mdb2->exec($sql);
104 if (is_a($affected, 'PEAR_Error'))
108 $name = $mdb2->quote($i18n->getKey('role.supervisor.label'));
109 $description = $mdb2->quote($i18n->getKey('role.supervisor.description'));
110 $rights = $mdb2->quote('data_entry,view_own_data,manage_own_settings,view_users'); // TODO: adjust rights.
111 $sql = "insert into tt_roles (team_id, name, description, rank, rights, status) values($user->team_id, $name, $description, 12, $rights, 0)";
112 $affected = $mdb2->exec($sql);
113 if (is_a($affected, 'PEAR_Error'))