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 import('ttConfigHelper');
30 import('ttGroupHelper');
32 // ttGroup class is used to store attributes for a single group in Time Tracker.
33 // We use it in ttUser class to have acces to "on behalf" group properties.
35 var $id = null; // Group id.
36 var $parent_id = null; // Paerent group id.
37 var $org_id = null; // Organization id.
38 var $name = null; // Group name.
39 var $lang = null; // Language.
40 var $decimal_mark = null; // Decimal separator.
41 var $date_format = null; // Date format.
42 var $time_format = null; // Time format.
43 var $week_start = 0; // Week start day.
44 var $tracking_mode = 0; // Tracking mode.
45 var $project_required = 0; // Whether project selection is required on time entires.
46 var $task_required = 0; // Whether task selection is required on time entires.
47 var $record_type = 0; // Record type (duration vs start and finish, or both).
48 var $punch_mode = 0; // Whether punch mode is enabled for user.
49 var $allow_overlap = 0; // Whether to allow overlapping time entries.
50 var $future_entries = 0; // Whether to allow creating future entries.
51 var $bcc_email = null; // Bcc email.
52 var $allow_ip = null; // Specification from where user is allowed access.
53 var $password_complexity = null; // Password complexity example.
54 var $currency = null; // Currency.
55 var $plugins = null; // Comma-separated list of enabled plugins.
57 var $config = null; // Comma-separated list of miscellaneous config options.
58 var $configHelper = null; // An instance of ttConfigHelper class.
60 var $custom_logo = 0; // Whether to use a custom logo for group.
61 var $lock_spec = null; // Cron specification for record locking.
62 var $holidays = null; // Holidays specification.
63 var $workday_minutes = 480; // Number of work minutes in a regular day.
65 var $active_users = 0; // Count of active users in group.
66 // We need a non-zero count to display some menus.
69 // Note: org_id is needed because we construct an object in ttUser constructor,
70 // when global $user object does not yet exist.
71 function __construct($id, $org_id) {
72 $mdb2 = getConnection();
74 $sql = "select * from tt_groups where id = $id and org_id = $org_id";
75 $res = $mdb2->query($sql);
76 if (is_a($res, 'PEAR_Error')) {
80 $val = $res->fetchRow();
82 $this->id = $val['id'];
83 $this->parent_id = $val['parent_id'];
84 $this->org_id = $val['org_id'];
85 $this->name = $val['name'];
86 $this->lang = $val['lang'];
87 $this->decimal_mark = $val['decimal_mark'];
88 $this->date_format = $val['date_format'];
89 $this->time_format = $val['time_format'];
90 $this->week_start = $val['week_start'];
91 $this->tracking_mode = $val['tracking_mode'];
92 /* TODO: initialize other things here.
93 $this->project_required = $val['project_required'];
94 $this->task_required = $val['task_required'];
96 $this->record_type = $val['record_type'];
98 $this->bcc_email = $val['bcc_email'];
99 $this->allow_ip = $val['allow_ip'];
100 $this->password_complexity = $val['password_complexity'];
101 $this->group_name = $val['group_name'];
103 $this->currency = $val['currency'];
104 $this->plugins = $val['plugins'];
105 $this->lock_spec = $val['lock_spec'];
106 $this->holidays = $val['holidays'];
107 $this->workday_minutes = $val['workday_minutes'];
109 $this->custom_logo = $val['custom_logo'];
112 // TODO: refactor this.
113 $this->config = $val['config'];
114 $this->configHelper = new ttConfigHelper($val['config']);
115 // Set user config options.
116 $this->punch_mode = $this->configHelper->getDefinedValue('punch_mode');
117 $this->allow_overlap = $this->configHelper->getDefinedValue('allow_overlap');
118 $this->future_entries = $this->configHelper->getDefinedValue('future_entries');
121 // Determine active user count in a separate query.
122 // TODO: If performance becomes an issue, investigate combining 2 queries in one.
123 // At this time we only need to know if at least 1 active user exists.
124 $sql = "select count(*) as user_count from tt_users".
125 " where group_id = $id and org_id = $org_id and status = 1";
126 $res = $mdb2->query($sql);
127 if (is_a($res, 'PEAR_Error')) {
130 $val = $res->fetchRow();
131 $this->active_users = $val['user_count'];