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 // +----------------------------------------------------------------------+
29 import('ttUserHelper');
30 import('ttGroupHelper');
32 // Class ttTimesheetHelper is used to help with project related tasks.
33 class ttTimesheetHelper {
35 // The getTimesheetByName looks up a project by name.
36 static function getTimesheetByName($name, $user_id) {
38 $mdb2 = getConnection();
40 $group_id = $user->getGroup();
41 $org_id = $user->org_id;
43 $sql = "select id from tt_timesheets".
44 " where group_id = $group_id and org_id = $org_id and user_id = $user_id and name = ".$mdb2->quote($name).
45 " and (status = 1 or status = 0)";
46 $res = $mdb2->query($sql);
47 if (!is_a($res, 'PEAR_Error')) {
48 $val = $res->fetchRow();
49 if ($val && $val['id'])
55 // insert function inserts a new timesheet into database.
56 static function insert($fields)
59 $mdb2 = getConnection();
61 $group_id = $user->getGroup();
62 $org_id = $user->org_id;
64 $user_id = $fields['user_id'];
65 $client_id = $fields['client_id'];
66 $name = $fields['name'];
67 $submitter_comment = $fields['comment'];
69 $sql = "insert into tt_timesheets (user_id, group_id, org_id, client_id, name, submitter_comment)".
70 " values ($user_id, $group_id, $org_id, ".$mdb2->quote($client_id).", ".$mdb2->quote($name).", ".$mdb2->quote($submitter_comment).")";
71 $affected = $mdb2->exec($sql);
72 if (is_a($affected, 'PEAR_Error'))
75 $last_id = $mdb2->lastInsertID('tt_timesheets', 'id');
77 // TODO: Associate report items with new timesheet.