return $last_id;
}
- // The getTimesheets obtains timesheets for user.
- static function getTimesheets($user_id)
+ // The getActiveTimesheets obtains active timesheets for a user.
+ static function getActiveTimesheets($user_id)
{
global $user;
$mdb2 = getConnection();
if ($user->isClient())
$client_part = "and ts.client_id = $user->client_id";
- $sql = "select ts.id, ts.name, ts.client_id, c.name as client_name from tt_timesheets ts".
+ $sql = "select ts.id, ts.name, ts.client_id, c.name as client_name, ts.submit_status, ts.approval_status from tt_timesheets ts".
" left join tt_clients c on (c.id = ts.client_id)".
" where ts.status = 1 and ts.group_id = $group_id and ts.org_id = $org_id and ts.user_id = $user_id".
" $client_part order by ts.name";
}
return $result;
}
+
+ // The getInactiveTimesheets obtains inactive timesheets for a user.
+ static function getInactiveTimesheets($user_id)
+ {
+ global $user;
+ $mdb2 = getConnection();
+
+ $group_id = $user->getGroup();
+ $org_id = $user->org_id;
+
+ // $addPaidStatus = $user->isPluginEnabled('ps');
+ $result = array();
+
+ if ($user->isClient())
+ $client_part = "and ts.client_id = $user->client_id";
+
+ $sql = "select ts.id, ts.name, ts.client_id, c.name as client_name, ts.submit_status, ts.approval_status from tt_timesheets ts".
+ " left join tt_clients c on (c.id = ts.client_id)".
+ " where ts.status = 0 and ts.group_id = $group_id and ts.org_id = $org_id and ts.user_id = $user_id".
+ " $client_part order by ts.name";
+ $res = $mdb2->query($sql);
+ $result = array();
+ if (!is_a($res, 'PEAR_Error')) {
+ $dt = new DateAndTime(DB_DATEFORMAT);
+ while ($val = $res->fetchRow()) {
+ //if ($addPaidStatus)
+ // $val['paid'] = ttTimesheetHelper::isPaid($val['id']);
+ $result[] = $val;
+ }
+ }
+ return $result;
+ }
+
+ // getTimesheet - obtains timesheet data from the database.
+ static function getTimesheet($timesheet_id) {
+ global $user;
+ $mdb2 = getConnection();
+
+ $group_id = $user->getGroup();
+ $org_id = $user->org_id;
+
+ if ($user->isClient()) $client_part = "and client_id = $user->client_id";
+
+ $sql = "select * from tt_timesheets".
+ " where id = $timesheet_id and group_id = $group_id and org_id = $org_id $client_part and status = 1";
+ $res = $mdb2->query($sql);
+ if (!is_a($res, 'PEAR_Error')) {
+ if ($val = $res->fetchRow())
+ return $val;
+ }
+ return false;
+ }
+
+ // delete - deletes timesheet from the database.
+ static function delete($timesheet_id) {
+ global $user;
+ $mdb2 = getConnection();
+
+ $group_id = $user->getGroup();
+ $org_id = $user->org_id;
+
+ // Handle time records.
+ $sql = "update tt_log set timesheet_id = null".
+ " where timesheet_id = $timesheet_id and group_id = $group_id and org_id = $org_id";
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error')) return false;
+
+ // Handle expense items.
+ $sql = "update tt_expense_items set timesheet_id = null".
+ " where timesheet_id = $timesheet_id and group_id = $group_id and org_id = $org_id";
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error')) return false;
+
+ // Delete timesheet.
+ $sql = "update tt_timesheets set status = null".
+ " where id = $timesheet_id and group_id = $group_id and org_id = $org_id";
+ $affected = $mdb2->exec($sql);
+ return (!is_a($affected, 'PEAR_Error'));
+ }
}
<br>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
- <td align="center"> Anuko Time Tracker 1.18.37.4735 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+ <td align="center"> Anuko Time Tracker 1.18.37.4736 | 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>
--- /dev/null
+{$forms.timesheetDeleteForm.open}
+<table cellspacing="4" cellpadding="7" border="0">
+ <tr>
+ <td>
+ <table cellspacing="0" cellpadding="2" border="0">
+ <tr>
+ <td colspan="2" align="center"><b>{$timesheet_to_delete|escape}</b></td>
+ </tr>
+ <tr><td colspan="2" align="center"> </td></tr>
+ <tr>
+ <td align="right">{$forms.timesheetDeleteForm.btn_delete.control} </td>
+ <td align="left"> {$forms.timesheetDeleteForm.btn_cancel.control}</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+</table>
+{$forms.timesheetDeleteForm.close}
<table cellspacing="0" cellpadding="7" border="0" width="720">
<tr>
<td valign="top">
-{if $user->can('manage_invoices') || $user->can('view_own_invoices')}
<table cellspacing="1" cellpadding="3" border="0" width="100%">
<tr><td colspan="2">{$i18n.form.timesheets.hint}<br></td></tr>
+ <tr><td> </td></tr>
+ {if $inactive_timesheets}
+ <tr><td class="sectionHeaderNoBorder">{$i18n.form.timesheets.active_timesheets}</td></tr>
+ {/if}
<tr>
<td class="tableHeader">{$i18n.label.thing_name}</td>
- {if $user->isPluginEnabled('cl')}
+ {if $show_client}
<td class="tableHeader">{$i18n.label.client}</td>
{/if}
- <td class="tableHeader">{$i18n.label.submitted}</td>
- <td class="tableHeader">{$i18n.label.approved}</td>
+ {if $show_submit_status}
+ <td class="tableHeader">{$i18n.label.submitted}</td>
+ {/if}
+ {if $show_approval_status}
+ <td class="tableHeader">{$i18n.label.approved}</td>
+ {/if}
<td class="tableHeader">{$i18n.label.view}</td>
+ <td class="tableHeader">{$i18n.label.edit}</td>
+ <td class="tableHeader">{$i18n.label.delete}</td>
</tr>
- {foreach $timesheets as $timesheet}
+ {foreach $active_timesheets as $timesheet}
<tr valign="top" bgcolor="{cycle values="#f5f5f5,#ffffff"}">
<td>{$timesheet.name|escape}</td>
+ {if $show_client}
<td>{$timesheet.client_name|escape}</td>
- <td>{$invoice.date}</td>
- {if $user->isPluginEnabled('ps')}
- <td>{if $invoice.paid}{$i18n.label.yes}{else}{$i18n.label.no}{/if}</td>
{/if}
- <td><a href="invoice_view.php?id={$invoice.id}">{$i18n.label.view}</a></td>
+ {if $show_submit_status}
+ <td>{if $timesheet.submit_status}{$i18n.label.yes}{else}{$i18n.label.no}{/if}</td>
+ {/if}
+ {if $show_approval_status}
+ <td>{if $timesheet.approval_status}{$i18n.label.yes}{else}{$i18n.label.no}{/if}</td>
+ {/if}
+
+
+
+ <td><a href="timesheet_view.php?id={$timesheet.id}">{$i18n.label.view}</a></td>
{if !$user->isClient()}
- <td><a href="invoice_delete.php?id={$invoice.id}">{$i18n.label.delete}</a></td>
+ <td><a href="timesheet_edit.php?id={$timesheet.id}">{$i18n.label.edit}</a></td>
+ <td><a href="timesheet_delete.php?id={$timesheet.id}">{$i18n.label.delete}</a></td>
{/if}
</tr>
{/foreach}
<tr><td align="center"><br><form><input type="button" onclick="chLocation('reports.php');" value="{$i18n.button.add}"></form></td></tr>
</table>
{/if}
-{/if}
</td>
</tr>
</table>
if ($request->isPost()) {
if ($request->getParameter('btn_delete')) {
- if (ttInvoiceHelper::getInvoice($cl_invoice_id)) {
- if (ttInvoiceHelper::delete($cl_invoice_id, $request->getParameter('delete_invoice_entries'))) {
- header('Location: invoices.php');
- exit();
- } else
- $err->add($i18n->get('error.db'));
+ if (ttInvoiceHelper::delete($cl_invoice_id, $request->getParameter('delete_invoice_entries'))) {
+ header('Location: invoices.php');
+ exit();
} else
$err->add($i18n->get('error.db'));
} elseif ($request->getParameter('btn_cancel')) {
--- /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
+// +----------------------------------------------------------------------+
+
+require_once('initialize.php');
+import('form.Form');
+import('ttTimesheetHelper');
+
+// Access checks.
+if (!(ttAccessAllowed('manage_own_timesheets') || ttAccessAllowed('manage_timesheets'))) {
+ header('Location: access_denied.php');
+ exit();
+}
+if (!$user->isPluginEnabled('ts')) {
+ header('Location: feature_disabled.php');
+ exit();
+}
+$cl_timesheet_id = (int)$request->getParameter('id');
+$timesheet = ttTimesheetHelper::getTimesheet($cl_timesheet_id);
+if (!$timesheet) {
+ header('Location: access_denied.php');
+ exit();
+}
+// End of access checks.
+
+$timesheet_to_delete = $timesheet['name'];
+
+$form = new Form('timesheetDeleteForm');
+$form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_timesheet_id));
+$form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete')));
+$form->addInput(array('type'=>'submit','name'=>'btn_cancel','value'=>$i18n->get('button.cancel')));
+
+if ($request->isPost()) {
+ if ($request->getParameter('btn_delete')) {
+ if (ttTimesheetHelper::delete($cl_timesheet_id)) {
+ header('Location: timesheets.php');
+ exit();
+ } else
+ $err->add($i18n->get('error.db'));
+ } elseif ($request->getParameter('btn_cancel')) {
+ header('Location: timesheets.php');
+ exit();
+ }
+} // isPost
+
+$smarty->assign('timesheet_to_delete', $timesheet_to_delete);
+$smarty->assign('forms', array($form->getName()=>$form->toArray()));
+$smarty->assign('onload', 'onLoad="document.invoiceDeleteForm.btn_cancel.focus()"');
+$smarty->assign('title', $i18n->get('title.delete_timesheet'));
+$smarty->assign('content_page_name', 'timesheet_delete.tpl');
+$smarty->display('index.tpl');
}
// End of access checks.
-$timesheets = ttTimesheetHelper::getTimesheets($user->getUser());
+// TODO: determine user properly, using a dropdown.
+$user_id = $user->getUser();
+
+// TODO: fix this for client access.
+$active_timesheets = ttTimesheetHelper::getActiveTimesheets($user_id);
+$inactive_timesheets = ttTimesheetHelper::getInactiveTimesheets($user_id);
+$show_client = $user->isPluginEnabled('cl') && !$user->isClient();
+
+$smarty->assign('active_timesheets', $active_timesheets);
+$smarty->assign('inactive_timesheets', $inactive_timesheets);
+$smarty->assign('show_client', $show_client);
+$smarty->assign('show_submit_status', !$user->isClient());
+$smarty->assign('show_approval_status', !$user->isClient());
-$smarty->assign('timesheets', $timesheets);
$smarty->assign('title', $i18n->get('title.timesheets'));
$smarty->assign('content_page_name', 'timesheets.tpl');
$smarty->display('index.tpl');