2 // We need a couple of array-like objects, one for associated task ids, another for task names.
3 // For performance, and because associated arrays are frowned upon in JavaScript, we'll use a simple object
4 // with properties for project tasks. Format:
6 // obj_tasks.p325 = "100,101,302,303,304"; // Tasks ids for project 325 are "100,101,302,303,304".
7 // obj_tasks.p408 = "100,302"; // Tasks ids for project 408 are "100,302".
9 // Create an object for task ids.
11 var project_prefix = "p"; // Prefix for project property.
14 // Populate obj_tasks with task ids for each relevant project.
15 {foreach $project_list as $project}
16 project_property = project_prefix + {$project.id};
17 obj_tasks[project_property] = "{$project.tasks}";
20 // Prepare an array of task names.
21 // Format: task_names[0] = Array(100, 'Coding'), task_names[1] = Array(302, 'Debugging'), etc...
22 // First element = task_id, second element = task name.
23 task_names = new Array();
25 {foreach $task_list as $task}
26 task_names[idx] = new Array({$task.id}, "{$task.name|escape:'javascript'}");
31 // empty_label is the mandatory top option in the tasks dropdown.
32 empty_label = '{$i18n.dropdown.all|escape:'javascript'}';
34 // inArray - determines whether needle is in haystack array.
35 function inArray(needle, haystack) {
36 var length = haystack.length;
37 for(var i = 0; i < length; i++) {
38 if(haystack[i] == needle) return true;
43 // The fillTaskDropdown function populates the task combo box with
44 // tasks associated with a selected project_id.
45 function fillTaskDropdown(project_id) {
47 // Get a string of comma-separated task ids.
49 var property = "p" + project_id;
50 str_task_ids = obj_tasks[property];
53 var task_ids = new Array(); // Array of task ids.
54 task_ids = str_task_ids.split(",");
57 var dropdown = document.getElementById("task");
58 // Determine previously selected item.
59 var selected_item = dropdown.options[dropdown.selectedIndex].value;
61 // Remove existing content.
63 // Add mandatory top option.
64 dropdown.options[0] = new Option(empty_label, '', true);
66 // Populate the dropdown with associated tasks.
67 len = task_names.length;
69 for (var i = 0; i < len; i++) {
71 // No project is selected. Fill in all tasks.
72 dropdown.options[dropdown_idx+1] = new Option(task_names[i][1], task_names[i][0]);
74 } else if (str_task_ids) {
75 // Project is selected and has associated tasks. Fill them in.
76 if (inArray(task_names[i][0], task_ids)) {
77 dropdown.options[dropdown_idx+1] = new Option(task_names[i][1], task_names[i][0]);
83 // If a previously selected item is still in dropdown - select it.
84 if (dropdown.options.length > 0) {
85 for (var i = 0; i < dropdown.options.length; i++) {
86 if (dropdown.options[i].value == selected_item) {
87 dropdown.options[i].selected = true;
93 // Build JavaScript array for assigned projects out of passed in PHP array.
94 var assigned_projects = new Array();
95 {if $assigned_projects}
96 {foreach $assigned_projects as $user_id => $projects}
97 assigned_projects[{$user_id}] = new Array();
99 {foreach $projects as $idx => $project_id}
100 assigned_projects[{$user_id}][{$idx}] = {$project_id};
106 // selectAssignedUsers is called when a project is changed in project dropdown.
107 // It selects users on the form who are assigned to this project.
108 function selectAssignedUsers(project_id) {
112 for (var i = 0; i < document.reportForm.elements.length; i++) {
113 if ((document.reportForm.elements[i].type == 'checkbox') && (document.reportForm.elements[i].name == 'users[]')) {
114 user_id = document.reportForm.elements[i].value;
116 document.reportForm.elements[i].checked = false;
118 document.reportForm.elements[i].checked = true;
120 if(assigned_projects[user_id] != undefined)
121 len = assigned_projects[user_id].length;
125 if (project_id != '')
126 for (var j = 0; j < len; j++) {
127 if (project_id == assigned_projects[user_id][j]) {
128 document.reportForm.elements[i].checked = true;
136 // handleCheckboxes - unmarks and hides the "Totals only" checkbox when
137 // "no grouping" is selected in the associated dropdown.
138 function handleCheckboxes() {
139 var totalsOnlyCheckbox = document.getElementById("chtotalsonly");
140 var totalsOnlyLabel = document.getElementById("totals_only_label");
141 if ("no_grouping" == document.getElementById("group_by1").value
142 && "no_grouping" == document.getElementById("group_by2").value
143 && "no_grouping" == document.getElementById("group_by3").value) {
144 // Unmark and hide the "Totals only" checkbox.
145 totalsOnlyCheckbox.checked = false;
146 totalsOnlyCheckbox.style.visibility = "hidden";
147 totalsOnlyLabel.style.visibility = "hidden";
149 totalsOnlyCheckbox.style.visibility = "visible";
150 totalsOnlyLabel.style.visibility = "visible";
155 {$forms.reportForm.open}
156 <div style="padding: 0 0 10 0;">
157 <table border="0" class="divider">
160 <table cellspacing="1" cellpadding="3" border="0">
162 <td>{$i18n.label.fav_report}:</td><td>{$forms.reportForm.favorite_report.control}</td>
163 <td>{$forms.reportForm.btn_generate.control} {$forms.reportForm.btn_delete.control}</td>
171 <table cellspacing="4" cellpadding="7" border="0">
173 <td valign="top" colspan="2" align="center">
174 <table border="0" cellpadding="3">
175 {if (($user->isPluginEnabled('cl') && !($user->isClient() && $user->client_id)) || ($custom_fields && $custom_fields->fields[0] && $custom_fields->fields[0]['type'] == CustomFields::TYPE_DROPDOWN))}
177 {if $user->isPluginEnabled('cl') && !($user->isClient() && $user->client_id)}<td><b>{$i18n.label.client}</b></td>{else}<td> </td>{/if}
179 {if ($custom_fields && $custom_fields->fields[0] && $custom_fields->fields[0]['type'] == CustomFields::TYPE_DROPDOWN)}<td><b>{$i18n.label.option}</b></td>{else}<td> </td>{/if}
182 <td>{$forms.reportForm.client.control}</td>
184 <td>{$forms.reportForm.option.control}</td>
187 {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
189 <td><b>{$i18n.label.project}</b></td>
191 {if ($smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
192 <td><b>{$i18n.label.task}</b></td>
196 {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
198 <td>{$forms.reportForm.project.control}</td>
200 {if ($smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
201 <td>{$forms.reportForm.task.control}</td>
205 {if $user->isPluginEnabled('iv')}
207 <td><b>{$i18n.form.time.billable}</b></td>
209 {if $user->can('manage_invoices')}
210 <td><b>{$i18n.label.invoice}</b></td>
214 <td>{$forms.reportForm.include_records.control}</td>
216 {if $user->can('manage_invoices')}
217 <td>{$forms.reportForm.invoice.control}</td>
221 {if ($user->can('manage_invoices') && $user->isPluginEnabled('ps'))}
223 <td><b>{$i18n.label.paid_status}</b></td>
226 <td>{$forms.reportForm.paid_status.control}</td>
229 {if $user->can('view_reports') || $user->can('view_all_reports') || $user->isClient()}
231 <td colspan="3"><b>{$i18n.label.users}</b></td>
234 <td colspan="3">{$forms.reportForm.users.control}</td>
238 <td><b>{$i18n.form.reports.select_period}</b></td>
240 <td><b>{$i18n.form.reports.set_period}</b></td>
243 <td>{$forms.reportForm.period.control}</td>
244 <td align="right">{$i18n.label.start_date}:</td>
245 <td>{$forms.reportForm.start_date.control}</td>
249 <td align="right">{$i18n.label.end_date}:</td>
250 <td>{$forms.reportForm.end_date.control}</td>
252 <tr><td colspan="3"><b>{$i18n.form.reports.show_fields}</b></td></tr>
255 <table border="0" width="100%">
256 {if $user->can('view_reports') || $user->can('view_all_reports') || $user->isPluginEnabled('cl') || $user->isPluginEnabled('iv') || $user->isPluginEnabled('ps')}
258 {if $user->isPluginEnabled('cl')}
259 <td width="25%"><label>{$forms.reportForm.chclient.control} {$i18n.label.client}</label></td>
261 {if ($user->can('manage_invoices') || $user->isClient()) && $user->isPluginEnabled('iv')}
262 <td width="25%"><label>{$forms.reportForm.chinvoice.control} {$i18n.label.invoice}</label></td>
264 {if ($user->can('manage_invoices') && $user->isPluginEnabled('ps'))}
265 <td width="25%"><label>{$forms.reportForm.chpaid.control} {$i18n.label.paid}</label></td>
267 {if $user->can('view_reports') || $user->can('view_all_reports')}
268 <td width="25%"><label>{$forms.reportForm.chip.control} {$i18n.label.ip}</label></td>
273 <td width="25%">{if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}<label>{$forms.reportForm.chproject.control} {$i18n.label.project}</label>{/if}</td>
274 <td width="25%">{if (($smarty.const.TYPE_START_FINISH == $user->record_type) || ($smarty.const.TYPE_ALL == $user->record_type))}<label>{$forms.reportForm.chstart.control} {$i18n.label.start}</label>{/if}</td>
275 <td width="25%"><label>{$forms.reportForm.chduration.control} {$i18n.label.duration}</label></td>
276 {if ($user->can('manage_invoices') || $user->isClient()) || $user->isPluginEnabled('ex')}
277 <td width="25%"><label>{$forms.reportForm.chcost.control} {$i18n.label.cost}</label></td>
283 <td>{if ($smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}<label>{$forms.reportForm.chtask.control} {$i18n.label.task}</label>{/if}</td>
284 <td>{if (($smarty.const.TYPE_START_FINISH == $user->record_type) || ($smarty.const.TYPE_ALL == $user->record_type))}<label>{$forms.reportForm.chfinish.control} {$i18n.label.finish}</label>{/if}</td>
285 <td><label>{$forms.reportForm.chnote.control} {$i18n.label.note}</label></td>
286 {if ($custom_fields && $custom_fields->fields[0])}
287 <td><label>{$forms.reportForm.chcf_1.control} {$custom_fields->fields[0]['label']|escape}</label></td>
292 {if $user->isPluginEnabled('wu')}
296 <td width="25%"><label>{$forms.reportForm.chunits.control} {$i18n.label.work_units}</label></td>
304 <td><b>{$i18n.form.reports.group_by}</b></td>
307 <td>{$forms.reportForm.group_by1.control}</td>
308 <td>{$forms.reportForm.group_by2.control}</td>
309 <td>{$forms.reportForm.group_by3.control}</td>
312 <td><span id="totals_only_label"><label>{$forms.reportForm.chtotalsonly.control} {$i18n.label.totals_only}</label></span></td>
316 <div style="padding: 10 0 10 0;">
317 <table border="0" class="divider">
320 <table cellspacing="1" cellpadding="3" border="0">
322 <td>{$i18n.form.reports.save_as_favorite}:</td><td>{$forms.reportForm.new_fav_report.control}</td>
323 <td>{$forms.reportForm.btn_save.control}</td>
331 <table border="0" cellpadding="3" width="100%">
332 <tr><td colspan="3" height="50" align="center">{$forms.reportForm.btn_generate.control}</td></tr>
337 {$forms.reportForm.close}