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 // +----------------------------------------------------------------------+
30 // Class ttTemplateHelper is used to help with template related tasks.
31 class ttTemplateHelper {
33 // get - gets template details.
34 static function get($id) {
36 $mdb2 = getConnection();
38 $group_id = $user->getGroup();
39 $org_id = $user->org_id;
41 $sql = "select id, name, description, content, status from tt_templates".
42 " where id = $id and group_id = $group_id and org_id = $org_id".
43 " and status is not null";
44 $res = $mdb2->query($sql);
45 if (!is_a($res, 'PEAR_Error')) {
46 $val = $res->fetchRow();
54 // delete - marks a template as deleted in tt_templates table in database.
55 static function delete($id) {
57 $mdb2 = getConnection();
59 $group_id = $user->getGroup();
60 $org_id = $user->org_id;
62 $sql = "update from tt_templates set status = null".
63 " where id = $id and group_id = $group_id and org_id = $org_id";
64 $affected = $mdb2->exec($sql);
65 if (is_a($affected, 'PEAR_Error'))
71 // insert function inserts a new template into database.
72 static function insert($fields) {
74 $mdb2 = getConnection();
76 $group_id = $user->getGroup();
77 $org_id = $user->org_id;
79 $name = $fields['name'];
80 $description = $fields['description'];
81 $content = $fields['content'];
83 $sql = "insert into tt_templates (group_id, org_id, name, description, content)".
84 " values ($group_id, $org_id, ".$mdb2->quote($name).
85 ", ".$mdb2->quote($description).", ".$mdb2->quote($content).")";
86 $affected = $mdb2->exec($sql);
87 if (is_a($affected, 'PEAR_Error'))
93 // update function - updates a template in database.
94 static function update($fields) {
96 $mdb2 = getConnection();
98 $group_id = $user->getGroup();
99 $org_id = $user->org_id;
101 $template_id = (int) $fields['id'];
102 $name = $fields['name'];
103 $description = $fields['description'];
104 $content = $fields['content'];
105 $status = (int) $fields['status'];
107 $sql = "update tt_templates set name = ".$mdb2->quote($name).
108 ", description = ".$mdb2->quote($description).
109 ", content = ".$mdb2->quote($content).
110 ", status = ".$status.
111 " where id = $template_id and group_id = $group_id and org_id = $org_id";
112 $affected = $mdb2->exec($sql);
113 return (!is_a($affected, 'PEAR_Error'));