/**
  * 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);
 }
 /**
  * Create new report
  *
  * @param void
  * @return null
  */
 function add()
 {
     $this->wireframe->print_button = false;
     if (!TimeReport::canAdd($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $project = null;
     $add_report_url = null;
     $project_id = (int) $this->request->get('project_id');
     if ($project_id) {
         $project = Projects::findById($project_id);
         if (instance_of($project, 'Project')) {
             $add_report_url = assemble_url('global_time_report_add', array('project_id' => $project_id));
         }
         // if
     }
     // if
     if ($add_report_url === null) {
         $add_report_url = assemble_url('global_time_report_add');
     }
     // if
     $report_data = $this->request->post('report');
     if (empty($report_data)) {
         $report_data = array('user_filter' => USER_FILTER_LOGGED_USER);
     }
     // if
     $this->smarty->assign(array('report_data' => $report_data, 'add_report_url' => $add_report_url));
     if ($this->request->isSubmitted()) {
         $this->active_report = new TimeReport();
         $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 created", array('name' => $this->active_report->getName()));
             $this->redirectToUrl($this->active_report->getUrl($project));
         } else {
             $this->smarty->assign('errors', $save);
         }
     }
     // if
 }