/**
  * Contruct time report controller
  *
  * @param Request $request
  * @return ProjectTimeReportsController
  */
 function __construct($request)
 {
     parent::__construct($request);
     if (!$this->logged_user->isAdministrator() && !$this->logged_user->getSystemPermission('use_time_reports')) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $this->wireframe->addBreadCrumb(lang('Reports'), timetracking_module_reports_url($this->active_project));
     $report_id = $this->request->getId('report_id');
     if ($report_id) {
         $this->active_report = TimeReports::findById($report_id);
     }
     // if
     if (instance_of($this->active_report, 'TimeReport')) {
         $this->wireframe->addBreadCrumb($this->active_report->getName(), $this->active_report->getUrl());
     } else {
         $this->active_report = new TimeReport();
     }
     // if
     $this->wireframe->page_actions = array();
     if (TimeReport::canAdd($this->logged_user)) {
         $this->wireframe->addPageAction(lang('New Report'), assemble_url('global_time_report_add', array('project_id' => $this->active_project->getId())));
     }
     // if
     $this->smarty->assign('active_report', $this->active_report);
 }
 /**
  * Update existing report
  *
  * @param void
  * @return null
  */
 function edit()
 {
     $this->wireframe->print_button = false;
     if ($this->active_report->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_report->canEdit($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $active_project = null;
     $project_id = $this->request->getId('project_id');
     if ($project_id) {
         $active_project = Projects::findById($project_id);
     }
     // if
     $report_data = $this->request->post('report');
     if (empty($report_data)) {
         $report_data = array('name' => $this->active_report->getName(), 'group_name' => $this->active_report->getGroupName(), 'user_filter' => $this->active_report->getUserFilter(), 'user_filter_data' => $this->active_report->getUserFilterData(), 'billable_filter' => $this->active_report->getBillableFilter(), 'date_filter' => $this->active_report->getDateFilter(), 'date_from' => $this->active_report->getDateFrom(), 'date_to' => $this->active_report->getDateTo(), 'sum_by_user' => $this->active_report->getSumByUser());
     }
     // if
     $this->smarty->assign(array('report_data' => $report_data, 'active_project' => $active_project));
     if ($this->request->isSubmitted()) {
         $old_name = $this->active_report->getName();
         $this->active_report->setAttributes($report_data);
         $this->active_report->setUserFilterData(array_var($report_data, 'user_filter_data'));
         $save = $this->active_report->save();
         if ($save && !is_error($save)) {
             flash_success("Report ':name' has been updated", array('name' => $old_name));
             $this->redirectToUrl($this->active_report->getUrl($active_project));
         } else {
             $this->smarty->assign('errors', $save);
         }
     }
     // if
 }