Template editor done.
[timetracker.git] / WEB-INF / templates / reports.tpl
1 <script>
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.
4 // Format:
5 // project_ids[143] = "325,370,390,400";  // Comma-separated list of project ids for client.
6 // project_names[325] = "Time Tracker";   // Project name.
7
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}";
12 {/foreach}
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'}";
17 {/foreach}
18 // We'll use this array to populate project dropdown when client is not selected.
19 var idx = 0;
20 var projects = new Array();
21 {foreach $project_list as $project}
22   projects[idx] = new Array("{$project.id}", "{$project.name|escape:'javascript'}");
23   idx++;
24 {/foreach}
25
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:
29
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".
32
33 // Create an object for task ids.
34 obj_tasks = {};
35 var project_prefix = "p"; // Prefix for project property.
36 var project_property;
37
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}";
42 {/foreach}
43
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();
48 var idx = 0;
49 {foreach $task_list as $task}
50   task_names[idx] = new Array({$task.id}, "{$task.name|escape:'javascript'}");
51   idx++;
52 {/foreach}
53
54 // empty_label is the mandatory top option in dropdowns.
55 empty_label = '{$i18n.dropdown.all|escape:'javascript'}';
56
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;
62   }
63   return false;
64 }
65
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");
71
72   // Determine previously selected item.
73   var selected_item = dropdown.options[dropdown.selectedIndex].value;
74
75   // Remove existing content.
76   dropdown.length = 0;
77   var project_reset = true;
78   // Add mandatory top option.
79   dropdown.options[0] = new Option(empty_label, '', true);
80
81   // Populate project dropdown.
82   if (!id) {
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;
90       }
91     }
92   } else if (str_ids) {
93     var ids = new Array();
94     ids = str_ids.split(",");
95     var len = ids.length;
96
97     for (var i = 0; i < len; i++) {
98       var p_id = ids[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;
103       }
104     }
105   }
106
107   // If project selection was reset - clear the tasks dropdown.
108   if (project_reset) {
109     dropdown = document.getElementById("task");
110     dropdown.length = 0;
111     dropdown.options[0] = new Option(empty_label, '', true);
112   }
113 }
114
115
116 // The fillTaskDropdown function populates the task combo box with
117 // tasks associated with a selected project_id.
118 function fillTaskDropdown(project_id) {
119   var str_task_ids;
120   // Get a string of comma-separated task ids.
121   if (project_id) {  
122     var property = "p" + project_id;
123     str_task_ids = obj_tasks[property];
124   }
125   if (str_task_ids) {
126     var task_ids = new Array(); // Array of task ids.
127     task_ids = str_task_ids.split(",");
128   }
129
130   var dropdown = document.getElementById("task");
131   // Determine previously selected item.
132   var selected_item = dropdown.options[dropdown.selectedIndex].value;
133
134   // Remove existing content.
135   dropdown.length = 0;
136   // Add mandatory top option.
137   dropdown.options[0] = new Option(empty_label, '', true);
138
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++) {
143     if (!project_id) {
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]);
146       dropdown_idx++;
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]);
151         dropdown_idx++;
152       }
153     }
154   }
155
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;
161       }
162     }
163   }
164 }
165
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();
171     {if $projects}
172       {foreach $projects as $idx => $project_id}
173         assigned_projects[{$user_id}][{$idx}] = {$project_id};
174       {/foreach}
175     {/if}
176   {/foreach}
177 {/if}
178
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) {
182   var user_id;
183   var len;
184
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;
188       if (project_id)
189         document.reportForm.elements[i].checked = false;
190       else
191         document.reportForm.elements[i].checked = true;
192
193       if(assigned_projects[user_id] != undefined)
194         len = assigned_projects[user_id].length;
195       else
196         len = 0;
197
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;
202             break;
203           }
204         }
205     }
206   }
207 }
208
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)) {
221     grouping = true;
222   }
223   if (grouping) {
224     // Show the "Totals only" checkbox.
225     totalsOnlyCheckbox.style.visibility = "visible";
226     totalsOnlyLabel.style.visibility = "visible";
227   } else {
228     // Unmark and hide the "Totals only" checkbox.
229     totalsOnlyCheckbox.checked = false;
230     totalsOnlyCheckbox.style.visibility = "hidden";
231     totalsOnlyLabel.style.visibility = "hidden";
232   }
233 }
234 </script>
235
236 {$forms.reportForm.open}
237 <div style="padding: 0 0 10 0;">
238   <table border="0" class="divider">
239     <tr>
240       <td>
241         <table cellspacing="1" cellpadding="3" border="0">
242           <tr>
243             <td>{$i18n.label.fav_report}:</td><td>{$forms.reportForm.favorite_report.control}</td>
244             <td>{$forms.reportForm.btn_generate.control}&nbsp;{$forms.reportForm.btn_delete.control}</td>
245           </tr>
246         </table>
247       </td>
248     </tr>
249   </table>
250 </div>
251
252 <table cellspacing="4" cellpadding="7" border="0">
253   <tr>
254     <td valign="top" colspan="2" align="center">
255       <table border="0" cellpadding="3">
256         <tr>
257           <td valign="top">
258             <table border="0" cellpadding="3">
259 {if $show_client}
260               <tr><td><b>{$i18n.label.client}</b></td></tr>
261               <tr><td>{$forms.reportForm.client.control}</td></tr>
262 {/if}
263 {if $show_project}
264               <tr><td><b>{$i18n.label.project}</b></td></tr>
265               <tr><td>{$forms.reportForm.project.control}</td></tr>
266 {/if}
267 {if $show_billable}
268               <tr><td><b>{$i18n.form.time.billable}</b></td></tr>
269               <tr><td>{$forms.reportForm.include_records.control}</td></tr>
270 {/if}
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>
274 {/if}
275             </table>
276           </td>
277           <td></td>
278           <td valign="top">
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>
283 {/if}
284 {if $show_task}
285               <tr><td><b>{$i18n.label.task}</b></td></tr>
286               <tr><td>{$forms.reportForm.task.control}</td></tr>
287 {/if}
288 {if $show_approved}
289               <tr><td><b>{$i18n.label.approved}</b></td></tr>
290               <tr><td>{$forms.reportForm.approved.control}</td></tr>
291 {/if}
292 {if $show_invoice_dropdown}
293               <tr><td><b>{$i18n.label.invoice}</b></td></tr>
294               <tr><td>{$forms.reportForm.invoice.control}</td></tr>
295 {/if}
296 {if $show_timesheet_dropdown}
297               <tr><td><b>{$i18n.label.timesheet}</b></td></tr>
298               <tr><td>{$forms.reportForm.timesheet.control}</td></tr>
299 {/if}
300             </table>
301           </td>
302         </tr>
303 {if $show_users}
304         <tr>
305           <td colspan="3"><b>{$i18n.label.users}</b></td>
306         </tr>
307         <tr>
308           <td colspan="3">{$forms.reportForm.users.control}</td>
309         </tr>
310 {/if}
311         <tr>
312           <td><b>{$i18n.form.reports.select_period}</b></td>
313           <td>&nbsp;</td>
314           <td><b>{$i18n.form.reports.set_period}</b></td>
315         </tr>
316         <tr valign="top">
317           <td>{$forms.reportForm.period.control}</td>
318           <td align="right">{$i18n.label.start_date}:</td>
319           <td>{$forms.reportForm.start_date.control}</td>
320         </tr>
321         <tr>
322           <td></td>
323           <td align="right">{$i18n.label.end_date}:</td>
324           <td>{$forms.reportForm.end_date.control}</td>
325         </tr>
326         <tr><td colspan="3"><b>{$i18n.form.reports.show_fields}</b></td></tr>
327         <tr>
328           <td colspan="3">
329             <table border="0" width="100%">
330               <tr>
331                 <td width="25%" valign="top">
332                   <table border="0" cellpadding="3">
333 {if $show_client}
334                     <tr><td><label>{$forms.reportForm.chclient.control}&nbsp;{$i18n.label.client}</label></td></tr>
335 {/if}
336 {if $show_project}
337                     <tr><td><label>{$forms.reportForm.chproject.control}&nbsp;{$i18n.label.project}</label></td></tr>
338 {/if}
339 {if $show_timesheet_checkbox}
340                     <tr><td><label>{$forms.reportForm.chtimesheet.control}&nbsp;{$i18n.label.timesheet}</label></td></tr>
341 {/if}
342 {if $show_cf_1_checkbox}
343                     <tr><td><label>{$forms.reportForm.chcf_1.control}&nbsp;{$custom_fields->fields[0]['label']|escape}</label></td></tr>
344 {/if}
345                   </table>
346                 </td>
347                 <td width="25%" valign="top">
348                   <table border="0" cellpadding="3">
349 {if $show_start}
350                     <tr><td><label>{$forms.reportForm.chstart.control}&nbsp;{$i18n.label.start}</label></td></tr>
351 {/if}
352 {if $show_task}
353                     <tr><td><label>{$forms.reportForm.chtask.control}&nbsp;{$i18n.label.task}</label></td></tr>
354 {/if}
355 {if $show_ip}
356                     <tr><td><label>{$forms.reportForm.chip.control}&nbsp;{$i18n.label.ip}</label></td></tr>
357 {/if}
358 {if $show_work_units}
359                     <tr><td><label>{$forms.reportForm.chunits.control}&nbsp;{$i18n.label.work_units}</label></td></tr>
360 {/if}
361                   </table>
362                 </td>
363                 <td width="25%" valign="top">
364                   <table border="0" cellpadding="3">
365 {if $show_finish}
366                     <tr><td><label>{$forms.reportForm.chfinish.control}&nbsp;{$i18n.label.finish}</label></td></tr>
367 {/if}
368                     <tr><td><label>{$forms.reportForm.chnote.control}&nbsp;{$i18n.label.note}</label></td></tr>
369 {if $show_approved}
370                     <tr><td><label>{$forms.reportForm.chapproved.control}&nbsp;{$i18n.label.approved}</label></td></tr>
371 {/if}
372 {if $show_invoice_checkbox}
373                     <tr><td><label>{$forms.reportForm.chinvoice.control}&nbsp;{$i18n.label.invoice}</label></td></tr>
374 {/if}
375                   </table>
376                 </td>
377                 <td width="25%" valign="top">
378                   <table border="0" cellpadding="3">
379                     <tr><td><label>{$forms.reportForm.chduration.control}&nbsp;{$i18n.label.duration}</label></td></tr>
380                     <tr><td><label>{$forms.reportForm.chcost.control}&nbsp;{$i18n.label.cost}</label></td></tr>
381 {if $show_paid_status}
382                     <tr><td><label>{$forms.reportForm.chpaid.control}&nbsp;{$i18n.label.paid}</label></td></tr>
383 {/if}
384                   </table>
385                 </td>
386               </tr>
387             </table>
388           </td>
389         </tr>
390
391         <tr><td><b>{$i18n.form.reports.group_by}</b></td></tr>
392         <tr valign="top">
393           <td>{$forms.reportForm.group_by1.control}</td>
394           <td>{$forms.reportForm.group_by2.control}</td>
395           <td>{$forms.reportForm.group_by3.control}</td>
396         </tr>
397         <tr>
398             <td><span id="totals_only_label"><label>{$forms.reportForm.chtotalsonly.control} {$i18n.label.totals_only}</label></span></td>
399         </tr>
400       </table>
401
402 <div style="padding: 10 0 10 0;">
403   <table border="0" class="divider">
404     <tr>
405       <td align="center">
406         <table cellspacing="1" cellpadding="3" border="0">
407           <tr>
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>
410           </tr>
411         </table>
412       </td>
413     </tr>
414   </table>
415 </div>
416
417       <table border="0" cellpadding="3" width="100%">
418         <tr><td colspan="3" height="50" align="center">{$forms.reportForm.btn_generate.control}</td></tr>
419       </table>
420     </td>
421   </tr>
422 </table>
423 {$forms.reportForm.close}