}
//print_r($_SESSION);
}
+
+ // saveDetachedAttribute saves a "detached" from form named attributed in session.
+ // There is no element in the form for it.
+ // Intended use is to add something to the session, when a form bean created on one page
+ // is used on other pages (ex.: reportForm).
+ // For example, to generate a timesheet we need a user_id, which is determined when a report
+ // is generated on report.php, using a bean created in reports.php.
+ function saveDetachedAttribute($name, $value) {
+ $_SESSION[$this->mSessionCell .'_'.$name] = $value;
+ }
+
+ function getDetachedAttribute($name) {
+ return $_SESSION[$this->mSessionCell.'_'.$name];
+ }
function loadBean() {
$el_list = @$_SESSION[$this->mSessionCell . "session_store_elements"];
--- /dev/null
+<?php
+// +----------------------------------------------------------------------+
+// | Anuko Time Tracker
+// +----------------------------------------------------------------------+
+// | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
+// +----------------------------------------------------------------------+
+// | LIBERAL FREEWARE LICENSE: This source code document may be used
+// | by anyone for any purpose, and freely redistributed alone or in
+// | combination with other software, provided that the license is obeyed.
+// |
+// | There are only two ways to violate the license:
+// |
+// | 1. To redistribute this code in source form, with the copyright
+// | notice or license removed or altered. (Distributing in compiled
+// | forms without embedded copyright notices is permitted).
+// |
+// | 2. To redistribute modified versions of this code in *any* form
+// | that bears insufficient indications that the modifications are
+// | not the work of the original author(s).
+// |
+// | This license applies to this document only, not any other software
+// | that it may be combined with.
+// |
+// +----------------------------------------------------------------------+
+// | Contributors:
+// | https://www.anuko.com/time_tracker/credits.htm
+// +----------------------------------------------------------------------+
+
+import('ttUserHelper');
+import('ttGroupHelper');
+
+// Class ttTimesheetHelper is used to help with project related tasks.
+class ttTimesheetHelper {
+
+ // The getTimesheetByName looks up a project by name.
+ static function getTimesheetByName($name, $user_id) {
+ global $user;
+ $mdb2 = getConnection();
+
+ $group_id = $user->getGroup();
+ $org_id = $user->org_id;
+
+ $sql = "select id from tt_timesheets".
+ " where group_id = $group_id and org_id = $org_id and user_id = $user_id and name = ".$mdb2->quote($name).
+ " and (status = 1 or status = 0)";
+ $res = $mdb2->query($sql);
+ if (!is_a($res, 'PEAR_Error')) {
+ $val = $res->fetchRow();
+ if ($val && $val['id'])
+ return $val;
+ }
+ return false;
+ }
+
+ // insert function inserts a new timesheet into database.
+ static function insert($fields)
+ {
+ global $user;
+ $mdb2 = getConnection();
+
+ $group_id = $user->getGroup();
+ $org_id = $user->org_id;
+
+ $user_id = $fields['user_id'];
+ $client_id = $fields['client_id'];
+ $name = $fields['name'];
+ $submitter_comment = $fields['comment'];
+
+ $sql = "insert into tt_timesheets (user_id, group_id, org_id, client_id, name, submitter_comment)".
+ " values ($user_id, $group_id, $org_id, ".$mdb2->quote($client_id).", ".$mdb2->quote($name).", ".$mdb2->quote($submitter_comment).")";
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error'))
+ return false;
+
+ $last_id = $mdb2->lastInsertID('tt_timesheets', 'id');
+
+ // TODO: Associate report items with new timesheet.
+
+ return $last_id;
+ }
+}
<br>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
- <td align="center"> Anuko Time Tracker 1.18.37.4732 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+ <td align="center"> Anuko Time Tracker 1.18.37.4733 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
<a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
<a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
<a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
function chLocation(newLocation) { document.location = newLocation; }
</script>
-{$forms.reportForm.open}
+{$forms.reportViewForm.open}
<table width="720">
<td valign="top">
<table border="0" cellpadding="3" cellspacing="1" width="100%">
<tr>
<td align="right">
<table>
- <tr><td>{$i18n.label.mark_paid}: {$forms.reportForm.mark_paid_select_options.control} {$forms.reportForm.mark_paid_action_options.control} {$forms.reportForm.btn_mark_paid.control}</td></tr>
+ <tr><td>{$i18n.label.mark_paid}: {$forms.reportViewForm.mark_paid_select_options.control} {$forms.reportViewForm.mark_paid_action_options.control} {$forms.reportViewForm.btn_mark_paid.control}</td></tr>
</table>
</td>
</tr>
<tr>
<td align="right">
<table>
- <tr><td>{$i18n.form.report.assign_to_invoice}: {$forms.reportForm.assign_invoice_select_options.control} {$forms.reportForm.recent_invoice.control} {$forms.reportForm.btn_assign.control}</td></tr>
+ <tr><td>{$i18n.form.report.assign_to_invoice}: {$forms.reportViewForm.assign_invoice_select_options.control} {$forms.reportViewForm.recent_invoice.control} {$forms.reportViewForm.btn_assign.control}</td></tr>
</table>
</td>
</tr>
{/if}
</table>
{/if}
-{$forms.reportForm.close}
+{$forms.reportViewForm.close}
<table width="720" cellspacing="4" cellpadding="4" border="0">
<tr>
$smarty->assign('custom_fields', $custom_fields);
}
-$form = new Form('reportForm');
+$form = new Form('reportViewForm');
// Report settings are stored in session bean before we get here from reports.php.
-$bean = new ActionForm('reportBean', $form, $request);
+$bean = new ActionForm('reportBean', new Form('reportForm'), $request);
// If we are in post, load the bean from session, as the constructor does it only in get.
if ($request->isPost()) $bean->loadBean();
break;
}
}
+ // Save user_id in session.
+ $bean->saveDetachedAttribute('timesheet_user_id', $first_user_id);
// TODO: Improve this for "view_all_reports" situation.
// We may need to add "manage_all_timesheets" right.
if ($showTimesheet)
$form->addInput(array('type'=>'checkbox','name'=>'chtimesheet'));
+// Add a hidden control for timesheet_user_id (who to generate a timesheet for).
+if ($showTimesheet)
+ $form->addInput(array('type'=>'hidden','name'=>'timesheet_user_id'));
+
// Add group by control.
$group_by_options['no_grouping'] = $i18n->get('form.reports.group_by_no');
$group_by_options['date'] = $i18n->get('form.reports.group_by_date');
require_once('initialize.php');
import('form.Form');
+import('ttTimesheetHelper');
// Access checks.
if (!(ttAccessAllowed('manage_own_timesheets') || ttAccessAllowed('manage_timesheets'))) {
if ($request->isPost()) {
$cl_name = trim($request->getParameter('timesheet_name'));
$cl_comment = trim($request->getParameter('submitter_comment'));
+
+ // Report settings are stored in session bean before we get here.
+ $bean = new ActionForm('reportBean', new Form('reportForm'), $request);
+ $bean->loadBean();
}
$form = new Form('timesheetForm');
if (!ttValidString($cl_comment, true)) $err->add($i18n->get('error.field'), $i18n->get('label.comment'));
if ($err->no()) {
- /*
- if (!ttProjectHelper::getProjectByName($cl_name)) {
- if (ttProjectHelper::insert(array('name' => $cl_name,
- 'description' => $cl_description,
- 'users' => $cl_users,
- 'tasks' => $cl_tasks,
- 'status' => ACTIVE))) {
- header('Location: projects.php');
+ $user_id = $bean->getDetachedAttribute('timesheet_user_id');
+ if (!ttTimesheetHelper::getTimesheetByName($cl_name, $user_id)) {
+ if (ttTimesheetHelper::insert(array('user_id' => $user_id,
+ // 'client_id' => ?
+ 'name' => $cl_name,
+ 'comment' => $cl_comment))) {
+ header('Location: timesheets.php');
exit();
} else
$err->add($i18n->get('error.db'));
} else
$err->add($i18n->get('error.object_exists'));
- */
}
} // isPost
$smarty->assign('forms', array($form->getName()=>$form->toArray()));
-$smarty->assign('onload', 'onLoad="document.timesheetForm.timmesheet_name.focus()"');
+$smarty->assign('onload', 'onLoad="document.timesheetForm.timesheet_name.focus()"');
$smarty->assign('title', $i18n->get('title.add_timesheet'));
$smarty->assign('content_page_name', 'timesheet_add.tpl');
$smarty->display('index.tpl');