2 // We need a few arrays to populate project and task dropdowns.
3 // When client selection changes, the project dropdown must be re-populated with only relevant projects.
4 // When project selection changes, the task dropdown must be repopulated similarly.
6 // project_ids[143] = "325,370,390,400"; // Comma-separated list of project ids for client.
7 // project_names[325] = "Time Tracker"; // Project name.
8 // task_ids[325] = "100,101,302,303,304"; // Comma-separated list ot task ids for project.
9 // task_names[100] = "Coding"; // Task name.
11 // Prepare an array of project ids for clients.
12 var project_ids = new Array();
13 {foreach $client_list as $client}
14 project_ids[{$client.id}] = "{$client.projects}";
16 // Prepare an array of project names.
17 var project_names = new Array();
18 {foreach $project_list as $project}
19 project_names[{$project.id}] = "{$project.name|escape:'javascript'}";
21 // We'll use this array to populate project dropdown when client is not selected.
23 var projects = new Array();
24 {foreach $project_list as $project}
25 projects[idx] = new Array("{$project.id}", "{$project.name|escape:'javascript'}");
29 // Prepare an array of task ids for projects.
30 var task_ids = new Array();
31 {foreach $project_list as $project}
32 task_ids[{$project.id}] = "{$project.tasks}";
34 // Prepare an array of task names.
35 var task_names = new Array();
36 {foreach $task_list as $task}
37 task_names[{$task.id}] = "{$task.name|escape:'javascript'}";
40 // Mandatory top options for project and task dropdowns.
41 var empty_label_project = '{$i18n.dropdown.select|escape:'javascript'}';
42 var empty_label_task = '{$i18n.dropdown.select|escape:'javascript'}';
44 // The fillDropdowns function populates the "project" and "task" dropdown controls
45 // with relevant values.
46 function fillDropdowns() {
47 if(document.body.contains(document.timeRecordForm.client))
48 fillProjectDropdown(document.timeRecordForm.client.value);
50 fillTaskDropdown(document.timeRecordForm.project.value);
53 // The fillProjectDropdown function populates the project combo box with
54 // projects associated with a selected client (client id is passed here as id).
55 function fillProjectDropdown(id) {
56 var str_ids = project_ids[id];
57 var dropdown = document.getElementById("project");
58 // Determine previously selected item.
59 var selected_item = dropdown.options[dropdown.selectedIndex].value;
61 // Remove existing content.
63 var project_reset = true;
64 // Add mandatory top option.
65 dropdown.options[0] = new Option(empty_label_project, '', true);
67 // Populate project dropdown.
69 // If we are here, client is not selected.
70 var len = projects.length;
71 for (var i = 0; i < len; i++) {
72 dropdown.options[i+1] = new Option(projects[i][1], projects[i][0]);
73 if (dropdown.options[i+1].value == selected_item) {
74 dropdown.options[i+1].selected = true;
75 project_reset = false;
79 var ids = new Array();
80 ids = str_ids.split(",");
83 for (var i = 0; i < len; i++) {
85 dropdown.options[i+1] = new Option(project_names[p_id], p_id);
86 if (dropdown.options[i+1].value == selected_item) {
87 dropdown.options[i+1].selected = true;
88 project_reset = false;
93 // If project selection was reset - clear the tasks dropdown.
95 dropdown = document.getElementById("task");
97 dropdown.options[0] = new Option(empty_label_task, '', true);
101 // The fillTaskDropdown function populates the task combo box with
102 // tasks associated with a selected project (project id is passed here as id).
103 function fillTaskDropdown(id) {
104 var str_ids = task_ids[id];
106 var dropdown = document.getElementById("task");
107 if (dropdown == null) return; // Nothing to do.
109 // Determine previously selected item.
110 var selected_item = dropdown.options[dropdown.selectedIndex].value;
112 // Remove existing content.
114 // Add mandatory top option.
115 dropdown.options[0] = new Option(empty_label_task, '', true);
117 // Populate the dropdown from the task_names array.
119 var ids = new Array();
120 ids = str_ids.split(",");
121 var len = ids.length;
124 for (var i = 0; i < len; i++) {
126 if (task_names[t_id]) {
127 dropdown.options[idx] = new Option(task_names[t_id], t_id);
132 // If a previously selected item is still in dropdown - select it.
133 if (dropdown.options.length > 0) {
134 for (var i = 0; i < dropdown.options.length; i++) {
135 if (dropdown.options[i].value == selected_item) {
136 dropdown.options[i].selected = true;
143 // The formDisable function disables some fields depending on what we have in other fields.
144 function formDisable(formField) {
145 var formFieldValue = eval("document.timeRecordForm." + formField + ".value");
146 var formFieldName = eval("document.timeRecordForm." + formField + ".name");
149 if (((formFieldValue != "") && (formFieldName == "start")) || ((formFieldValue != "") && (formFieldName == "finish"))) {
150 x = eval("document.timeRecordForm.duration");
153 x.style.background = "#e9e9e9";
156 if (((formFieldValue == "") && (formFieldName == "start") && (document.timeRecordForm.finish.value == "")) || ((formFieldValue == "") && (formFieldName == "finish") && (document.timeRecordForm.start.value == ""))) {
157 x = eval("document.timeRecordForm.duration");
160 x.style.background = "white";
163 if ((formFieldValue != "") && (formFieldName == "duration")) {
164 x = eval("document.timeRecordForm.start");
167 x.style.background = "#e9e9e9";
168 x = eval("document.timeRecordForm.finish");
171 x.style.background = "#e9e9e9";
174 if ((formFieldValue == "") && (formFieldName == "duration")) {
175 x = eval("document.timeRecordForm.start");
177 x.style.background = "white";
178 x = eval("document.timeRecordForm.finish");
180 x.style.background = "white";
184 // The setNow function fills a given field with current time.
185 function setNow(formField) {
186 var x = eval("document.timeRecordForm.start");
188 x.style.background = "white";
189 x = eval("document.timeRecordForm.finish");
191 x.style.background = "white";
192 var today = new Date();
193 var time_format = '{$user->time_format}';
194 var obj = eval("document.timeRecordForm." + formField);
195 obj.value = today.strftime(time_format);
196 formDisable(formField);
199 function get_date() {
200 var date = new Date();
201 return date.strftime("%Y-%m-%d");
204 function get_time() {
205 var date = new Date();
206 return date.strftime("%H:%M");
216 {$forms.timeRecordForm.open}
217 <table cellspacing="4" cellpadding="0" border="0">
221 {if $on_behalf_control}
223 <td align="right">{$i18n.label.user}:</td>
224 <td>{$forms.timeRecordForm.onBehalfUser.control}</td>
227 {if $user->isPluginEnabled('cl')}
229 <td align="right">{$i18n.label.client}{if $user->isPluginEnabled('cm')} (*){/if}:</td>
230 <td>{$forms.timeRecordForm.client.control}</td>
233 {if $user->isPluginEnabled('iv')}
235 <td align="right"> </td>
236 <td><label>{$forms.timeRecordForm.billable.control}{$i18n.form.time.billable}</label></td>
239 {if ($custom_fields && $custom_fields->fields[0])}
241 <td align="right">{$custom_fields->fields[0]['label']|escape}{if $custom_fields->fields[0]['required']} (*){/if}:</td><td>{$forms.timeRecordForm.cf_1.control}</td>
244 {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
246 <td align="right">{$i18n.label.project} (*):</td>
247 <td>{$forms.timeRecordForm.project.control}</td>
250 {if ($smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
252 <td align="right">{$i18n.label.task}:</td>
253 <td>{$forms.timeRecordForm.task.control}</td>
256 {if (($smarty.const.TYPE_START_FINISH == $user->record_type) || ($smarty.const.TYPE_ALL == $user->record_type))}
258 <td align="right">{$i18n.label.start}:</td>
259 <td>{$forms.timeRecordForm.start.control} <input onclick="setNow('start');" type="button" tabindex="-1" value="{$i18n.button.now}"></td>
262 <td align="right">{$i18n.label.finish}:</td>
263 <td>{$forms.timeRecordForm.finish.control} <input onclick="setNow('finish');" type="button" tabindex="-1" value="{$i18n.button.now}"></td>
266 {if (($smarty.const.TYPE_DURATION == $user->record_type) || ($smarty.const.TYPE_ALL == $user->record_type))}
268 <td align="right">{$i18n.label.duration}:</td>
269 <td>{$forms.timeRecordForm.duration.control} {$i18n.form.time.duration_format}</td>
276 <tr><td>{$forms.timeRecordForm.date.control}</td></tr>
284 <td align="right">{$i18n.label.note}:</td>
285 <td align="left">{$forms.timeRecordForm.note.control}</td>
288 <td align="center" colspan="2">{$forms.timeRecordForm.btn_submit.control}</td>
296 <table border="0" cellpadding="3" cellspacing="1" width="100%">
298 {if $user->isPluginEnabled('cl')}
299 <td width="20%" class="tableHeader">{$i18n.label.client}</td>
301 {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
302 <td class="tableHeader">{$i18n.label.project}</td>
304 {if ($smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
305 <td class="tableHeader">{$i18n.label.task}</td>
307 {if (($smarty.const.TYPE_START_FINISH == $user->record_type) || ($smarty.const.TYPE_ALL == $user->record_type))}
308 <td width="5%" class="tableHeader" align="right">{$i18n.label.start}</td>
309 <td width="5%" class="tableHeader" align="right">{$i18n.label.finish}</td>
311 <td width="5%" class="tableHeader">{$i18n.label.duration}</td>
312 <td class="tableHeader">{$i18n.label.note}</td>
313 <td width="5%" class="tableHeader">{$i18n.label.edit}</td>
315 {foreach $time_records as $record}
316 <tr bgcolor="{cycle values="#f5f5f5,#ccccce"}" {if !$record.billable} class="not_billable" {/if}>
317 {if $user->isPluginEnabled('cl')}
318 <td valign="top">{$record.client|escape}</td>
320 {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
321 <td valign="top">{$record.project|escape}</td>
323 {if ($smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
324 <td valign="top">{$record.task|escape}</td>
326 {if (($smarty.const.TYPE_START_FINISH == $user->record_type) || ($smarty.const.TYPE_ALL == $user->record_type))}
327 <td nowrap align="right" valign="top">{if $record.start}{$record.start}{else} {/if}</td>
328 <td nowrap align="right" valign="top">{if $record.finish}{$record.finish}{else} {/if}</td>
330 <td align="right" valign="top">{if ($record.duration == '0:00' && $record.start <> '')}<font color="#ff0000">{$i18n.form.time.uncompleted}</font>{else}{$record.duration}{/if}</td>
331 <td valign="top">{if $record.comment}{$record.comment|escape}{else} {/if}</td>
332 <td valign="top" align="center">
333 {if $record.invoice_id}
336 <a href="time_edit.php?id={$record.id}">{$i18n.label.edit}</a>
337 {if ($record.duration == '0:00' && $record.start <> '')}
338 <input type="hidden" name="record_id" value="{$record.id}">
339 <input type="hidden" name="browser_date" value="">
340 <input type="hidden" name="browser_time" value="">
341 <input type="submit" id="btn_stop" name="btn_stop" onclick="browser_date.value=get_date();browser_time.value=get_time()" value="{$i18n.button.stop}">
353 <table cellpadding="3" cellspacing="1" width="720">
355 <td align="left">{$i18n.label.week_total}: {$week_total}</td>
356 <td align="right">{$i18n.label.day_total}: {$day_total}</td>
358 {if $user->isPluginEnabled('mq')}
360 <td align="left">{$i18n.label.month_total}: {$month_total}</td>
362 <td align="right">{$i18n.form.time.over_quota}: <span style="color: green;">{$quota_remaining}</span></td>
364 <td align="right">{$i18n.form.time.remaining_quota}: <span style="color: red;">{$quota_remaining}</span></td>
370 {$forms.timeRecordForm.close}