Initial repo created
[timetracker.git] / WEB-INF / lib / ttSysConfig.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
36 // Class ttSysConfig is used for storing and retrieving named values associated with users.
37 class ttSysConfig {
38   var $u_id = null;
39   var $mdb2 = null;
40
41   // Constructor.
42   function ttSysConfig($u_id) {
43     $this->u_id = $u_id;
44     $this->mdb2 = getConnection();
45   }
46
47   // The getValue retrieves a value identified by name.
48   function getValue($name) {
49     $res = $this->mdb2->query("select param_value from tt_config where user_id = ".$this->u_id." and param_name=".$this->mdb2->quote($name));
50     if (!is_a($res, 'PEAR_Error')) {
51       $val = $res->fetchRow();
52       return $val['param_value'];
53     }
54     return false;
55   }
56
57   // The setValue sets a value identified by name.
58   function setValue($name, $value) {
59     $rcnt = 0;
60     $res = $this->mdb2->query("select count(*) as rcnt from tt_config where user_id = ".$this->u_id." and param_name = ".$this->mdb2->quote($name));
61     if ($val = $res->fetchRow()) $rcnt = $val['rcnt'];
62     
63     if ($rcnt > 0) {
64       $affected = $this->mdb2->exec("update tt_config set param_value = ".$this->mdb2->quote($value)." where user_id = ".$this->u_id." and param_name=".$this->mdb2->quote($name));
65     } else {
66       $affected = $this->mdb2->exec("insert into tt_config set param_value = ".$this->mdb2->quote($value).", param_name = ".$this->mdb2->quote($name).", user_id = ".$this->u_id);
67     }
68     return (!is_a($affected, 'PEAR_Error'));
69   }
70 }
71 ?>