Introduced ttGroup class to store attributes of on behalf group.
[timetracker.git] / WEB-INF / lib / ttGroup.class.php
1 <?php
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.
10 // |
11 // | There are only two ways to violate the license:
12 // |
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).
16 // |
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).
20 // |
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
23 // |
24 // +----------------------------------------------------------------------+
25 // | Contributors:
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
28
29 import('ttConfigHelper');
30 import('ttGroupHelper');
31
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.
34 class ttGroup {
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 $show_holidays = 0;       // Whether to show holidays in calendar.
45   var $tracking_mode = 0;       // Tracking mode.
46   var $project_required = 0;    // Whether project selection is required on time entires.
47   var $task_required = 0;       // Whether task selection is required on time entires.
48   var $record_type = 0;         // Record type (duration vs start and finish, or both).
49   var $punch_mode = 0;          // Whether punch mode is enabled for user.
50   var $allow_overlap = 0;       // Whether to allow overlapping time entries.
51   var $future_entries = 0;      // Whether to allow creating future entries.
52   var $uncompleted_indicators = 0; // Uncompleted time entry indicators (show nowhere or on users page).
53   var $bcc_email = null;        // Bcc email.
54   var $allow_ip = null;         // Specification from where user is allowed access.
55   var $password_complexity = null; // Password complexity example.
56   var $currency = null;         // Currency.
57   var $plugins = null;          // Comma-separated list of enabled plugins.
58   var $config = null;           // Comma-separated list of miscellaneous config options.
59   var $custom_logo = 0;         // Whether to use a custom logo for group.
60   var $lock_spec = null;        // Cron specification for record locking.
61   var $workday_minutes = 480;   // Number of work minutes in a regular day.
62   var $minutes_in_unit = 15;    // Number of minutes in unit for Work units plugin.
63   var $first_unit_threshold = 0;// Threshold for 1st unit for Work units plugin.
64   var $unit_totals_only = 0;    // Totals only option for the Work units plugin.
65
66   // Constructor.
67   function __construct($id, $org_id) {
68     $mdb2 = getConnection();
69
70     $sql = "select * from tt_groups where id = $id and org_id = $org_id";
71     $res = $mdb2->query($sql);
72     if (is_a($res, 'PEAR_Error')) {
73       return;
74     }
75
76     $val = $res->fetchRow();
77     if ($val['id'] > 0) {
78       $this->id = $val['id'];
79       $this->parent_id = $val['parent_id'];
80       $this->org_id = $val['org_id'];
81       $this->name = $val['name'];
82       $this->lang = $val['lang'];
83       $this->decimal_mark = $val['decimal_mark'];
84       $this->date_format = $val['date_format'];
85       $this->time_format = $val['time_format'];
86       $this->week_start = $val['week_start'];
87       /* TODO: initialize other things here.
88       $this->tracking_mode = $val['tracking_mode'];
89       $this->project_required = $val['project_required'];
90       $this->task_required = $val['task_required'];
91       $this->record_type = $val['record_type'];
92       $this->bcc_email = $val['bcc_email'];
93       $this->allow_ip = $val['allow_ip'];
94       $this->password_complexity = $val['password_complexity'];
95       $this->group_name = $val['group_name'];
96       $this->currency = $val['currency'];
97       $this->plugins = $val['plugins'];
98       $this->lock_spec = $val['lock_spec'];
99       $this->workday_minutes = $val['workday_minutes'];
100       $this->custom_logo = $val['custom_logo'];
101
102       $this->config = $val['config'];
103       $config = new ttConfigHelper($this->config);
104       // Set user config options.
105       $this->show_holidays = $config->getDefinedValue('show_holidays');
106       $this->punch_mode = $config->getDefinedValue('punch_mode');
107       $this->allow_overlap = $config->getDefinedValue('allow_overlap');
108       $this->future_entries = $config->getDefinedValue('future_entries');
109       $this->uncompleted_indicators = $config->getDefinedValue('uncompleted_indicators');
110       if ($this->isPluginEnabled('wu')) {
111         $minutes_in_unit = $config->getIntValue('minutes_in_unit');
112         if ($minutes_in_unit) $this->minutes_in_unit = $minutes_in_unit;
113         $first_unit_threshold = $config->getIntValue('1st_unit_threshold');
114         if ($first_unit_threshold) $this->first_unit_threshold = $first_unit_threshold;
115         $this->unit_totals_only = $config->getDefinedValue('unit_totals_only');
116       }
117
118       // Set "on behalf" id and name (user).
119       if (isset($_SESSION['behalf_id'])) {
120           $this->behalf_id = $_SESSION['behalf_id'];
121           $this->behalf_name = $_SESSION['behalf_name'];
122       }
123       // Set "on behalf" id and name (group).
124       if (isset($_SESSION['behalf_group_id'])) {
125           $this->behalf_group_id = $_SESSION['behalf_group_id'];
126           $this->behalf_group_name = $_SESSION['behalf_group_name'];
127       }
128       */
129     }
130   }
131 }