3 * FusionForge reporting system
5 * Copyright 2003-2004, Tim Perdue/GForge, LLC
6 * Copyright 2009, Roland Mas
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 require_once $gfcommon.'include/Error.class.php';
30 * Time Entry model object
32 * This is a simple OO-wrapper to the existing time entry methods. At some point someone will want
33 * to actually implement the procedural functions direct in this file. This class is only used by
36 * @author Tony Bibbs <tony@geeklog.net>
37 * @copyright Copyright 2005, Tony Bibbs
38 * @todo This is just a wrapper to the existing procedural methods. At some point someone will
39 * want to move that implementation here.
40 * @todo I'm sure this isn't code per the gForge coding standards. This should be fixed.
43 class TimeEntry extends Error {
47 * @author Tony Bibbs <tony@geeklog.net>
56 * Creates a time entry record
58 * NOTE: this is a real hack as it uses the existing procedural code to call on functionality.
59 * The biggest drawback is that this method will not be able to return the Primary Key for the
60 * time entry record because the key is a unixtimestamp (see the way the UI uses timeadd.php
61 * to fully appreciate what I mean).
63 * @author Tony Bibbs <tony@geeklog.net>
65 * @param int $projectTaskId The project task the user is reporting time to
66 * @param int $week The week the time being reported was done
67 * @param int $days_adjust Represents the offset to add to the given week to specify the day
68 * @param int $timeCode The type of work that was done (general categorization)
69 * @param float $hours The actual time spent
70 * @return int This will be the Artificat ID otherwise it will be false if an error occurred
71 * @todo I'm quite concerned that none of the form data is being sanitized for things like
72 * unwanted HTML, JavaSript and SQL Injection. Might be worth adding that sort of filtering
73 * as provided by the KSES Filter (search Google).
74 * @todo The check that looks to see if this method works is not language independent.
75 * someone that better understands how that all works will want to remove the hardcoded
76 * 'successfully added'.
79 function create($projectTaskId, $week, $days_adjust, $timeCode, $hours)
83 $report_date=($week + ($days_adjust*REPORT_DAY_SPAN))+(12*60*60);
84 $res = db_query_params ('INSERT INTO rep_time_tracking (user_id,week,report_date,project_task_id,time_code,hours) VALUES ($1,$2,$3,$4,$5,$6)',
92 exit_error(db_error(),'tracker');
94 $feedback.=_('Successfully Added');
96 return db_affected_rows($res);
100 * Updates a timeEntry record.
102 * This isn't supported by the current timeadd.php code so I'm assuming that all
103 * that is expected is that instead of changing something you'd simply delete it
104 * and readd it. Messy, IMHO, but I am still including this method here to let
105 * know I purposely left this unimplemented.
107 * @author Tony Bibbs <tony@geeklog.net>
109 * @return boolean Always false
114 // Not supported in timeadd.php
119 * Deletes an existing timeEntry record
121 * @author Tony Bibbs <tony@geeklog.net>
123 * @param int $projectTaskId ID for the task which the time entry record belongs to.
124 * @param int $reportDate
125 * @param int $oldTimeCode ID of time code that was associated with time entry record.
126 * @return boolean True if delete works, otherwise false)
129 function delete($projectTaskId, $reportDate, $oldTimeCode)
133 // Trick procedural code into thinking this was posted via the HTML form
134 $_POST['submit'] = 1;
135 $_POST['delete'] = 1;
137 // Sanitize the data at some point.
138 $project_task_id = $projectTaskId;
139 $report_date = $reportDate;
140 $old_time_code = $oldTimeCode;
142 // Prepare to have the procedural code process all of this. We'll need to buffer any
143 // output so we can gracefully ignore it since this class is only used by the SOAP
147 // Now pull in the procedural code to handle the processing.
148 require_once $GLOBALS['gfwww'].'reporting/timeadd.php';
149 $tmpOutput = ob_get_contents();
151 // Now discard any output.
154 if (!stristr($tmpOutput, 'successfully deleted')) return false;
158 function getTimeCodes()
165 // c-file-style: "bsd"