Initial repo created
[timetracker.git] / WEB-INF / lib / ttCustomFieldHelper.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 // Class ttCustomFieldHelper is used to help with custom field related tasks.
30 class ttCustomFieldHelper {
31         
32   // The insertField function inserts a new custom field in database.
33   static function insertField($fields)
34   {
35     $mdb2 = getConnection();
36
37     $team_id = (int) $fields['team_id'];
38     $type = (int) $fields['type'];
39     $label = $fields['label'];
40     $required = (int) $fields['required'];
41     $status = $fields['status'];
42     
43     $sql = "insert into tt_custom_fields (team_id, type, label, required, status) 
44       values ($team_id, $type, ".$mdb2->quote($label).", $required, ".$mdb2->quote($status).")";
45       
46     $affected = $mdb2->exec($sql);
47     if (is_a($affected, 'PEAR_Error'))
48       return false;
49       
50     $last_id = 0;
51     $sql = "select last_insert_id() as last_insert_id";
52     $res = $mdb2->query($sql);
53     $val = $res->fetchRow();
54     $last_id = $val['last_insert_id'];
55       
56     return $last_id;
57   }
58   
59   // The insertOption function inserts a new custom field option in database.
60   static function insertOption($fields)
61   {
62     $mdb2 = getConnection();
63
64     $field_id = (int) $fields['field_id'];
65     $value = $fields['value'];
66     
67     $sql = "insert into tt_custom_field_options (field_id, value) 
68       values ($field_id, ".$mdb2->quote($value).")";
69       
70     $affected = $mdb2->exec($sql);
71     if (is_a($affected, 'PEAR_Error'))
72       return false;
73       
74     $last_id = 0;
75     $sql = "select last_insert_id() as last_insert_id";
76     $res = $mdb2->query($sql);
77     $val = $res->fetchRow();
78     $last_id = $val['last_insert_id'];
79       
80     return $last_id;
81   }
82   
83   // The insertLogEntry function inserts a new custom field log entry in database.
84   static function insertLogEntry($fields)
85   {
86     $mdb2 = getConnection();
87
88     $log_id = (int) $fields['log_id'];
89     $field_id = (int) $fields['field_id'];
90     $option_id = $fields['option_id'];
91     $value = $fields['value'];
92     $status = $fields['status'];
93     
94     $sql = "insert into tt_custom_field_log (log_id, field_id, option_id, value, status) 
95       values ($log_id, $field_id, ".$mdb2->quote($option_id).", ".$mdb2->quote($value).", ".$mdb2->quote($status).")";
96       
97     $affected = $mdb2->exec($sql);
98     return (!is_a($affected, 'PEAR_Error'));
99   }
100 }
101 ?>