$sql = "insert into tt_fav_reports (name, user_id, client_id, cf_1_option_id, project_id, task_id,
billable, invoice, users, period, period_start, period_end,
show_client, show_invoice,
$sql = "insert into tt_fav_reports (name, user_id, client_id, cf_1_option_id, project_id, task_id,
billable, invoice, users, period, period_start, period_end,
show_client, show_invoice,
- $mdb2 = getConnection();
- $sql = "update tt_fav_reports set ".
- "name = ".$mdb2->quote($fields['name']).", ".
- "client_id = ".$mdb2->quote($fields['client']).", ".
- "cf_1_option_id = ".$mdb2->quote($fields['option']).", ".
- "project_id = ".$mdb2->quote($fields['project']).", ".
- "task_id = ".$mdb2->quote($fields['task']).", ".
- "billable = ".$mdb2->quote($fields['billable']).", ".
- "invoice = ".$mdb2->quote($fields['invoice']).", ".
- "users = ".$mdb2->quote($fields['users']).", ".
- "period = ".$mdb2->quote($fields['period']).", ".
- "period_start = ".$mdb2->quote($fields['from']).", ".
- "period_end = ".$mdb2->quote($fields['to']).", ".
- "show_client = ".$fields['chclient'].", ".
- "show_invoice = ".$fields['chinvoice'].", ".
- "show_project = ".$fields['chproject'].", ".
- "show_start = ".$fields['chstart'].", ".
- "show_duration = ".$fields['chduration'].", ".
- "show_cost = ".$fields['chcost'].", ".
- "show_task = ".$fields['chtask'].", ".
- "show_end = ".$fields['chfinish'].", ".
- "show_note = ".$fields['chnote'].", ".
- "show_custom_field_1 = ".$fields['chcf_1'].", ".
- "group_by = ".$mdb2->quote($fields['group_by']).", ".
- "show_totals_only = ".$fields['chtotalsonly'].
- " where id = ".$fields['id'];
- $affected = $mdb2->exec($sql);
- if (is_a($affected, 'PEAR_Error'))
- return false;
-
+ $mdb2 = getConnection();
+ $sql = "update tt_fav_reports set ".
+ "name = ".$mdb2->quote($fields['name']).", ".
+ "client_id = ".$mdb2->quote($fields['client']).", ".
+ "cf_1_option_id = ".$mdb2->quote($fields['option']).", ".
+ "project_id = ".$mdb2->quote($fields['project']).", ".
+ "task_id = ".$mdb2->quote($fields['task']).", ".
+ "billable = ".$mdb2->quote($fields['billable']).", ".
+ "invoice = ".$mdb2->quote($fields['invoice']).", ".
+ "users = ".$mdb2->quote($fields['users']).", ".
+ "period = ".$mdb2->quote($fields['period']).", ".
+ "period_start = ".$mdb2->quote($fields['from']).", ".
+ "period_end = ".$mdb2->quote($fields['to']).", ".
+ "show_client = ".$fields['chclient'].", ".
+ "show_invoice = ".$fields['chinvoice'].", ".
+ "show_project = ".$fields['chproject'].", ".
+ "show_start = ".$fields['chstart'].", ".
+ "show_duration = ".$fields['chduration'].", ".
+ "show_cost = ".$fields['chcost'].", ".
+ "show_task = ".$fields['chtask'].", ".
+ "show_end = ".$fields['chfinish'].", ".
+ "show_note = ".$fields['chnote'].", ".
+ "show_custom_field_1 = ".$fields['chcf_1'].", ".
+ "group_by = ".$mdb2->quote($fields['group_by']).", ".
+ "show_totals_only = ".$fields['chtotalsonly'].
+ " where id = ".$fields['id'];
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error'))
+ return false;
+
// Set default value of 0 for not set checkboxes (in bean).
// Later in this function we use it to construct $fields array to update database.
if (!$bean->getAttribute('chclient')) $bean->setAttribute('chclient', 0);
if (!$bean->getAttribute('chinvoice')) $bean->setAttribute('chinvoice', 0);
if (!$bean->getAttribute('chproject')) $bean->setAttribute('chproject', 0);
// Set default value of 0 for not set checkboxes (in bean).
// Later in this function we use it to construct $fields array to update database.
if (!$bean->getAttribute('chclient')) $bean->setAttribute('chclient', 0);
if (!$bean->getAttribute('chinvoice')) $bean->setAttribute('chinvoice', 0);
if (!$bean->getAttribute('chproject')) $bean->setAttribute('chproject', 0);
if (!$bean->getAttribute('chduration')) $bean->setAttribute('chduration', 0);
if (!$bean->getAttribute('chcost')) $bean->setAttribute('chcost', 0);
if (!$bean->getAttribute('chtask')) $bean->setAttribute('chtask', 0);
if (!$bean->getAttribute('chfinish')) $bean->setAttribute('chfinish', 0);
if (!$bean->getAttribute('chnote')) $bean->setAttribute('chnote', 0);
if (!$bean->getAttribute('chcf_1')) $bean->setAttribute('chcf_1', 0);
if (!$bean->getAttribute('chduration')) $bean->setAttribute('chduration', 0);
if (!$bean->getAttribute('chcost')) $bean->setAttribute('chcost', 0);
if (!$bean->getAttribute('chtask')) $bean->setAttribute('chtask', 0);
if (!$bean->getAttribute('chfinish')) $bean->setAttribute('chfinish', 0);
if (!$bean->getAttribute('chnote')) $bean->setAttribute('chnote', 0);
if (!$bean->getAttribute('chcf_1')) $bean->setAttribute('chcf_1', 0);
- $users = join(',', $users_in_bean);
- }
- if ($bean->getAttribute('start_date')) {
- $dt = new DateAndTime($user->date_format, $bean->getAttribute('start_date'));
- $from = $dt->toString(DB_DATEFORMAT);
- }
- if ($bean->getAttribute('end_date')) {
+ $users = join(',', $users_in_bean);
+ }
+ if ($bean->getAttribute('start_date')) {
+ $dt = new DateAndTime($user->date_format, $bean->getAttribute('start_date'));
+ $from = $dt->toString(DB_DATEFORMAT);
+ }
+ if ($bean->getAttribute('end_date')) {
- 'client'=>$bean->getAttribute('client'),
- 'option'=>$bean->getAttribute('option'),
- 'project'=>$bean->getAttribute('project'),
- 'task'=>$bean->getAttribute('task'),
- 'billable'=>$bean->getAttribute('include_records'),
- 'invoice'=>$bean->getAttribute('invoice'),
- 'users'=>$users,
- 'period'=>$bean->getAttribute('period'),
- 'from'=>$from,
- 'to'=>$to,
- 'chclient'=>$bean->getAttribute('chclient'),
- 'chinvoice'=>$bean->getAttribute('chinvoice'),
+ 'client'=>$bean->getAttribute('client'),
+ 'option'=>$bean->getAttribute('option'),
+ 'project'=>$bean->getAttribute('project'),
+ 'task'=>$bean->getAttribute('task'),
+ 'billable'=>$bean->getAttribute('include_records'),
+ 'invoice'=>$bean->getAttribute('invoice'),
+ 'users'=>$users,
+ 'period'=>$bean->getAttribute('period'),
+ 'from'=>$from,
+ 'to'=>$to,
+ 'chclient'=>$bean->getAttribute('chclient'),
+ 'chinvoice'=>$bean->getAttribute('chinvoice'),
- 'chstart'=>$bean->getAttribute('chstart'),
- 'chduration'=>$bean->getAttribute('chduration'),
- 'chcost'=>$bean->getAttribute('chcost'),
- 'chtask'=>$bean->getAttribute('chtask'),
- 'chfinish'=>$bean->getAttribute('chfinish'),
- 'chnote'=>$bean->getAttribute('chnote'),
- 'chcf_1'=>$bean->getAttribute('chcf_1'),
- 'group_by'=>$bean->getAttribute('group_by'),
- 'chtotalsonly'=>$bean->getAttribute('chtotalsonly'));
-
- $id = false;
- $report = ttFavReportHelper::getReportByName($user_id, $fields['name']);
- if ($report) {
- $fields['id'] = $report['id'];
- $id = ttFavReportHelper::updateReport($fields);
+ 'chstart'=>$bean->getAttribute('chstart'),
+ 'chduration'=>$bean->getAttribute('chduration'),
+ 'chcost'=>$bean->getAttribute('chcost'),
+ 'chtask'=>$bean->getAttribute('chtask'),
+ 'chfinish'=>$bean->getAttribute('chfinish'),
+ 'chnote'=>$bean->getAttribute('chnote'),
+ 'chcf_1'=>$bean->getAttribute('chcf_1'),
+ 'group_by'=>$bean->getAttribute('group_by'),
+ 'chtotalsonly'=>$bean->getAttribute('chtotalsonly'));
+
+ $id = false;
+ $report = ttFavReportHelper::getReportByName($user_id, $fields['name']);
+ if ($report) {
+ $fields['id'] = $report['id'];
+ $id = ttFavReportHelper::updateReport($fields);
+ } else {
+ $fields['user_id'] = $user_id;
+ $id = ttFavReportHelper::insertReport($fields);
$bean->setAttribute('chtask', $val['show_task']);
$bean->setAttribute('chfinish', $val['show_end']);
$bean->setAttribute('chnote', $val['show_note']);
$bean->setAttribute('chcf_1', $val['show_custom_field_1']);
$bean->setAttribute('group_by', $val['group_by']);
$bean->setAttribute('chtask', $val['show_task']);
$bean->setAttribute('chfinish', $val['show_end']);
$bean->setAttribute('chnote', $val['show_note']);
$bean->setAttribute('chcf_1', $val['show_custom_field_1']);
$bean->setAttribute('group_by', $val['group_by']);