forked from Ben0it-T/timetracker
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimesheet_edit.php
More file actions
86 lines (77 loc) · 3.46 KB
/
timesheet_edit.php
File metadata and controls
86 lines (77 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/* Copyright (c) Anuko International Ltd. https://www.anuko.com
License: See license.txt */
require_once('initialize.php');
import('form.Form');
import('ttTimesheetHelper');
// Access checks.
if (!(ttAccessAllowed('track_own_time') || ttAccessAllowed('track_time'))) {
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.
if ($request->isPost()) {
$cl_name = is_null($request->getParameter('timesheet_name')) ? '' : trim($request->getParameter('timesheet_name'));
$cl_comment = is_null($request->getParameter('comment')) ? '' : trim($request->getParameter('comment'));
$cl_status = $request->getParameter('status');
} else {
$cl_name = $timesheet['name'];
$cl_comment = $timesheet['comment'];
$cl_status = $timesheet['status'];
}
// Can we delete this timesheet?
$canDelete = $timesheet['approve_status'] != 1
|| (($user->id == $timesheet['user_id'] && $user->can('approve_own_timesheets'))
|| ($user->id != $timesheet['user_id'] && $user->can('approve_timesheets')));
$form = new Form('timesheetForm');
$form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_timesheet_id));
$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'timesheet_name','value'=>$cl_name));
$form->addInput(array('type'=>'textarea','name'=>'comment','value'=>$cl_comment));
$form->addInput(array('type'=>'combobox','name'=>'status','value'=>$cl_status,
'data'=>array(ACTIVE=>$i18n->get('dropdown.status_active'),INACTIVE=>$i18n->get('dropdown.status_inactive'))));
$form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
if ($canDelete) $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete')));
if ($request->isPost()) {
// Validate user input.
if (!ttValidString($cl_name)) $err->add($i18n->get('error.field'), $i18n->get('label.thing_name'));
if (!ttValidString($cl_comment, true)) $err->add($i18n->get('error.field'), $i18n->get('label.comment'));
if (!ttValidStatus($cl_status)) $err->add($i18n->get('error.field'), $i18n->get('label.status'));
if ($request->getParameter('btn_save')) {
if ($err->no()) {
$existing_timesheet = ttTimesheetHelper::getTimesheetByName($cl_name);
if (!$existing_timesheet || ($cl_timesheet_id == $existing_timesheet['id'])) {
// Update timesheet information.
if (ttTimesheetHelper::update(array(
'id' => $cl_timesheet_id,
'name' => $cl_name,
'comment' => $cl_comment,
'status' => $cl_status))) {
header('Location: timesheets.php');
exit();
} else
$err->add($i18n->get('error.db'));
} else
$err->add($i18n->get('error.object_exists'));
}
}
if ($request->getParameter('btn_delete') && $canDelete) {
header("Location: timesheet_delete.php?id=$cl_timesheet_id");
exit();
}
} // isPost
$smarty->assign('forms', array($form->getName()=>$form->toArray()));
$smarty->assign('onload', 'onload="document.timesheetForm.timesheet_name.focus()"');
$smarty->assign('can_delete', $canDelete);
$smarty->assign('title', $i18n->get('title.edit_timesheet'));
$smarty->assign('content_page_name', 'timesheet_edit.tpl');
$smarty->display('index.tpl');