2 // We need a few arrays to populate project dropdown.
3 // When client selection changes, the project dropdown must be re-populated with only relevant projects.
5 // project_ids[143] = "325,370,390,400"; // Comma-separated list of project ids for client.
6 // project_names[325] = "Time Tracker"; // Project name.
8 // Prepare an array of project ids for clients.
9 var project_ids = new Array();
10 {foreach $client_list as $client}
11 project_ids[{$client.id}] = "{$client.projects}";
13 // Prepare an array of project names.
14 var project_names = new Array();
15 {foreach $project_list as $project}
16 project_names[{$project.id}] = "{$project.name|escape:'javascript'}";
18 // We'll use this array to populate project dropdown when client is not selected.
20 var projects = new Array();
21 {foreach $project_list as $project}
22 projects[idx] = new Array("{$project.id}", "{$project.name|escape:'javascript'}");
26 // We need a couple of array-like objects, one for associated task ids, another for task names.
27 // For performance, and because associated arrays are frowned upon in JavaScript, we'll use a simple object
28 // with properties for project tasks. Format:
30 // obj_tasks.p325 = "100,101,302,303,304"; // Tasks ids for project 325 are "100,101,302,303,304".
31 // obj_tasks.p408 = "100,302"; // Tasks ids for project 408 are "100,302".
33 // Create an object for task ids.
35 var project_prefix = "p"; // Prefix for project property.
38 // Populate obj_tasks with task ids for each relevant project.
39 {foreach $project_list as $project}
40 project_property = project_prefix + {$project.id};
41 obj_tasks[project_property] = "{$project.tasks}";
44 // Prepare an array of task names.
45 // Format: task_names[0] = Array(100, 'Coding'), task_names[1] = Array(302, 'Debugging'), etc...
46 // First element = task_id, second element = task name.
47 task_names = new Array();
49 {foreach $task_list as $task}
50 task_names[idx] = new Array({$task.id}, "{$task.name|escape:'javascript'}");
54 // empty_label is the mandatory top option in dropdowns.
55 empty_label = '{$i18n.dropdown.all|escape:'javascript'}';
57 // inArray - determines whether needle is in haystack array.
58 function inArray(needle, haystack) {
59 var length = haystack.length;
60 for(var i = 0; i < length; i++) {
61 if(haystack[i] == needle) return true;
66 // The fillProjectDropdown function populates the project combo box with
67 // projects associated with a selected client (client id is passed here as id).
68 function fillProjectDropdown(id) {
69 var str_ids = project_ids[id];
70 var dropdown = document.getElementById("project");
72 // Determine previously selected item.
73 var selected_item = dropdown.options[dropdown.selectedIndex].value;
75 // Remove existing content.
77 var project_reset = true;
78 // Add mandatory top option.
79 dropdown.options[0] = new Option(empty_label, '', true);
81 // Populate project dropdown.
83 // If we are here, client is not selected.
84 var len = projects.length;
85 for (var i = 0; i < len; i++) {
86 dropdown.options[i+1] = new Option(projects[i][1], projects[i][0]);
87 if (dropdown.options[i+1].value == selected_item) {
88 dropdown.options[i+1].selected = true;
89 project_reset = false;
93 var ids = new Array();
94 ids = str_ids.split(",");
97 for (var i = 0; i < len; i++) {
99 dropdown.options[i+1] = new Option(project_names[p_id], p_id);
100 if (dropdown.options[i+1].value == selected_item) {
101 dropdown.options[i+1].selected = true;
102 project_reset = false;
107 // If project selection was reset - clear the tasks dropdown.
109 dropdown = document.getElementById("task");
111 dropdown.options[0] = new Option(empty_label, '', true);
116 // The fillTaskDropdown function populates the task combo box with
117 // tasks associated with a selected project_id.
118 function fillTaskDropdown(project_id) {
120 // Get a string of comma-separated task ids.
122 var property = "p" + project_id;
123 str_task_ids = obj_tasks[property];
126 var task_ids = new Array(); // Array of task ids.
127 task_ids = str_task_ids.split(",");
130 var dropdown = document.getElementById("task");
131 // Determine previously selected item.
132 var selected_item = dropdown.options[dropdown.selectedIndex].value;
134 // Remove existing content.
136 // Add mandatory top option.
137 dropdown.options[0] = new Option(empty_label, '', true);
139 // Populate the dropdown with associated tasks.
140 len = task_names.length;
141 var dropdown_idx = 0;
142 for (var i = 0; i < len; i++) {
144 // No project is selected. Fill in all tasks.
145 dropdown.options[dropdown_idx+1] = new Option(task_names[i][1], task_names[i][0]);
147 } else if (str_task_ids) {
148 // Project is selected and has associated tasks. Fill them in.
149 if (inArray(task_names[i][0], task_ids)) {
150 dropdown.options[dropdown_idx+1] = new Option(task_names[i][1], task_names[i][0]);
156 // If a previously selected item is still in dropdown - select it.
157 if (dropdown.options.length > 0) {
158 for (var i = 0; i < dropdown.options.length; i++) {
159 if (dropdown.options[i].value == selected_item) {
160 dropdown.options[i].selected = true;
166 // Build JavaScript array for assigned projects out of passed in PHP array.
167 var assigned_projects = new Array();
168 {if $assigned_projects}
169 {foreach $assigned_projects as $user_id => $projects}
170 assigned_projects[{$user_id}] = new Array();
172 {foreach $projects as $idx => $project_id}
173 assigned_projects[{$user_id}][{$idx}] = {$project_id};
179 // selectAssignedUsers is called when a project is changed in project dropdown.
180 // It selects users on the form who are assigned to this project.
181 function selectAssignedUsers(project_id) {
185 for (var i = 0; i < document.reportForm.elements.length; i++) {
186 if ((document.reportForm.elements[i].type == 'checkbox') && (document.reportForm.elements[i].name == 'users[]')) {
187 user_id = document.reportForm.elements[i].value;
189 document.reportForm.elements[i].checked = false;
191 document.reportForm.elements[i].checked = true;
193 if(assigned_projects[user_id] != undefined)
194 len = assigned_projects[user_id].length;
198 if (project_id != '')
199 for (var j = 0; j < len; j++) {
200 if (project_id == assigned_projects[user_id][j]) {
201 document.reportForm.elements[i].checked = true;
209 // handleCheckboxes - unmarks and hides the "Totals only" checkbox when
210 // "no grouping" is selected in the associated group by dropdowns.
211 function handleCheckboxes() {
212 var totalsOnlyCheckbox = document.getElementById("chtotalsonly");
213 var totalsOnlyLabel = document.getElementById("totals_only_label");
214 var groupBy1 = document.getElementById("group_by1");
215 var groupBy2 = document.getElementById("group_by2");
216 var groupBy3 = document.getElementById("group_by3");
217 var grouping = false;
218 if ((groupBy1 != null && "no_grouping" != groupBy1.value) ||
219 (groupBy2 != null && "no_grouping" != groupBy2.value) ||
220 (groupBy3 != null && "no_grouping" != groupBy3.value)) {
224 // Show the "Totals only" checkbox.
225 totalsOnlyCheckbox.style.visibility = "visible";
226 totalsOnlyLabel.style.visibility = "visible";
228 // Unmark and hide the "Totals only" checkbox.
229 totalsOnlyCheckbox.checked = false;
230 totalsOnlyCheckbox.style.visibility = "hidden";
231 totalsOnlyLabel.style.visibility = "hidden";
236 {$forms.reportForm.open}
237 <div style="padding: 0 0 10 0;">
238 <table border="0" class="divider">
241 <table cellspacing="1" cellpadding="3" border="0">
243 <td>{$i18n.label.fav_report}:</td><td>{$forms.reportForm.favorite_report.control}</td>
244 <td>{$forms.reportForm.btn_generate.control} {$forms.reportForm.btn_delete.control}</td>
252 <table cellspacing="4" cellpadding="7" border="0">
254 <td valign="top" colspan="2" align="center">
255 <table border="0" cellpadding="3">
258 <table border="0" cellpadding="3">
260 <tr><td><b>{$i18n.label.client}</b></td></tr>
261 <tr><td>{$forms.reportForm.client.control}</td></tr>
264 <tr><td><b>{$i18n.label.project}</b></td></tr>
265 <tr><td>{$forms.reportForm.project.control}</td></tr>
268 <tr><td><b>{$i18n.form.time.billable}</b></td></tr>
269 <tr><td>{$forms.reportForm.include_records.control}</td></tr>
271 {if $show_paid_status}
272 <tr><td><b>{$i18n.label.paid_status}</b></td></tr>
273 <tr><td>{$forms.reportForm.paid_status.control}</td></tr>
279 <table border="0" cellpadding="3">
280 {if $show_cf_1_dropdown}
281 <tr><td><b>{$i18n.label.option}</b></td></tr>
282 <tr><td>{$forms.reportForm.option.control}</td></tr>
285 <tr><td><b>{$i18n.label.task}</b></td></tr>
286 <tr><td>{$forms.reportForm.task.control}</td></tr>
289 <tr><td><b>{$i18n.label.approved}</b></td></tr>
290 <tr><td>{$forms.reportForm.approved.control}</td></tr>
292 {if $show_invoice_dropdown}
293 <tr><td><b>{$i18n.label.invoice}</b></td></tr>
294 <tr><td>{$forms.reportForm.invoice.control}</td></tr>
296 {if $show_timesheet_dropdown}
297 <tr><td><b>{$i18n.label.timesheet}</b></td></tr>
298 <tr><td>{$forms.reportForm.timesheet.control}</td></tr>
305 <td colspan="3"><b>{$i18n.label.users}</b></td>
308 <td colspan="3">{$forms.reportForm.users.control}</td>
312 <td><b>{$i18n.form.reports.select_period}</b></td>
314 <td><b>{$i18n.form.reports.set_period}</b></td>
317 <td>{$forms.reportForm.period.control}</td>
318 <td align="right">{$i18n.label.start_date}:</td>
319 <td>{$forms.reportForm.start_date.control}</td>
323 <td align="right">{$i18n.label.end_date}:</td>
324 <td>{$forms.reportForm.end_date.control}</td>
326 <tr><td colspan="3"><b>{$i18n.form.reports.show_fields}</b></td></tr>
329 <table border="0" width="100%">
331 <td width="25%" valign="top">
332 <table border="0" cellpadding="3">
334 <tr><td><label>{$forms.reportForm.chclient.control} {$i18n.label.client}</label></td></tr>
337 <tr><td><label>{$forms.reportForm.chproject.control} {$i18n.label.project}</label></td></tr>
339 {if $show_timesheet_checkbox}
340 <tr><td><label>{$forms.reportForm.chtimesheet.control} {$i18n.label.timesheet}</label></td></tr>
342 {if $show_cf_1_checkbox}
343 <tr><td><label>{$forms.reportForm.chcf_1.control} {$custom_fields->fields[0]['label']|escape}</label></td></tr>
347 <td width="25%" valign="top">
348 <table border="0" cellpadding="3">
350 <tr><td><label>{$forms.reportForm.chstart.control} {$i18n.label.start}</label></td></tr>
353 <tr><td><label>{$forms.reportForm.chtask.control} {$i18n.label.task}</label></td></tr>
356 <tr><td><label>{$forms.reportForm.chip.control} {$i18n.label.ip}</label></td></tr>
358 {if $show_work_units}
359 <tr><td><label>{$forms.reportForm.chunits.control} {$i18n.label.work_units}</label></td></tr>
363 <td width="25%" valign="top">
364 <table border="0" cellpadding="3">
366 <tr><td><label>{$forms.reportForm.chfinish.control} {$i18n.label.finish}</label></td></tr>
368 <tr><td><label>{$forms.reportForm.chnote.control} {$i18n.label.note}</label></td></tr>
370 <tr><td><label>{$forms.reportForm.chapproved.control} {$i18n.label.approved}</label></td></tr>
372 {if $show_invoice_checkbox}
373 <tr><td><label>{$forms.reportForm.chinvoice.control} {$i18n.label.invoice}</label></td></tr>
377 <td width="25%" valign="top">
378 <table border="0" cellpadding="3">
379 <tr><td><label>{$forms.reportForm.chduration.control} {$i18n.label.duration}</label></td></tr>
380 <tr><td><label>{$forms.reportForm.chcost.control} {$i18n.label.cost}</label></td></tr>
381 {if $show_paid_status}
382 <tr><td><label>{$forms.reportForm.chpaid.control} {$i18n.label.paid}</label></td></tr>
391 <tr><td><b>{$i18n.form.reports.group_by}</b></td></tr>
393 <td>{$forms.reportForm.group_by1.control}</td>
394 <td>{$forms.reportForm.group_by2.control}</td>
395 <td>{$forms.reportForm.group_by3.control}</td>
398 <td><span id="totals_only_label"><label>{$forms.reportForm.chtotalsonly.control} {$i18n.label.totals_only}</label></span></td>
402 <div style="padding: 10 0 10 0;">
403 <table border="0" class="divider">
406 <table cellspacing="1" cellpadding="3" border="0">
408 <td>{$i18n.form.reports.save_as_favorite}:</td><td>{$forms.reportForm.new_fav_report.control}</td>
409 <td>{$forms.reportForm.btn_save.control}</td>
417 <table border="0" cellpadding="3" width="100%">
418 <tr><td colspan="3" height="50" align="center">{$forms.reportForm.btn_generate.control}</td></tr>
423 {$forms.reportForm.close}