Added an option to use page breaks on PDF reports after grouped by blocks.
[timetracker.git] / WEB-INF / lib / ttUserConfig.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 define('SYSC_CHART_INTERVAL', 'chart_interval');
30 define('SYSC_CHART_TYPE', 'chart_type');
31 define('SYSC_LAST_REPORT_EMAIL', 'last_report_email');
32 define('SYSC_LAST_REPORT_CC', 'last_report_cc');
33 define('SYSC_LAST_INVOICE_EMAIL', 'last_invoice_email');
34 define('SYSC_LAST_INVOICE_CC', 'last_invoice_cc');
35 define('SYSC_PDF_REPORT_PAGE_BREAKS', 'pdf_report_page_breaks');
36
37 // Class ttUserConfig is used for storing and retrieving named values associated with users.
38 // When user is working on behalf of someone else, this class is still associated with a user.
39 class ttUserConfig {
40   var $user_id = null;
41   var $group_id = null;
42   var $org_id = null;
43   var $mdb2 = null;
44
45   // Constructor.
46   function __construct() {
47     global $user;
48     $this->user_id = $user->id; // Not behalf id by design.
49     $this->group_id = $user->group_id;
50     $this->org_id = $user->org_id;
51     $this->mdb2 = getConnection();
52   }
53
54   // The getValue retrieves a value identified by name.
55   function getValue($name) {
56     $res = $this->mdb2->query("select param_value from tt_config".
57       " where user_id = $this->user_id and group_id = $this->group_id and org_id = $this->org_id".
58       " and param_name=".$this->mdb2->quote($name));
59     if (!is_a($res, 'PEAR_Error')) {
60       $val = $res->fetchRow();
61       return $val['param_value'];
62     }
63     return false;
64   }
65
66   // The setValue sets a value identified by name.
67   function setValue($name, $value) {
68     $count = 0;
69     $res = $this->mdb2->query("select count(*) as count from tt_config where user_id = ".$this->user_id." and param_name = ".$this->mdb2->quote($name));
70     if ($val = $res->fetchRow()) $count = $val['count'];
71
72     if ($count > 0) {
73       $affected = $this->mdb2->exec("update tt_config set param_value = ".$this->mdb2->quote($value).
74         " where user_id = $this->user_id and group_id = $this->group_id and org_id = $this->org_id".
75         " and param_name=".$this->mdb2->quote($name));
76     } else {
77       $sql = "insert into tt_config set param_value = ".$this->mdb2->quote($value).
78         ", param_name = ".$this->mdb2->quote($name).", user_id = $this->user_id, group_id = $this->group_id, org_id = ".$this->org_id;
79       $affected = $this->mdb2->exec($sql);
80     }
81     return (!is_a($affected, 'PEAR_Error'));
82   }
83 }