/**
 * Handle on prepare project overview event
 *
 * @param NamedList $tabs
 * @param User $logged_user
 * @param Project $project
 * @return null
 */
function timetracking_handle_on_project_tabs(&$tabs, &$logged_user, &$project)
{
    if ($logged_user->getProjectPermission('timerecord', $project) >= PROJECT_PERMISSION_ACCESS) {
        $tabs->add('time', array('text' => lang('Time'), 'url' => timetracking_module_url($project)));
    }
    // if
}
 /**
  * Create a new time record
  *
  * @param void
  * @return null
  */
 function add()
 {
     $this->wireframe->print_button = false;
     if ($this->request->isApiCall() && !$this->request->isSubmitted()) {
         $this->httpError(HTTP_ERR_BAD_REQUEST);
     }
     // if
     if (!TimeRecord::canAdd($this->logged_user, $this->active_project)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $timetracking_data = $this->request->post('time');
     if (!is_array($timetracking_data)) {
         $timetracking_data = array('user_id' => $this->logged_user->getId(), 'record_user' => $this->logged_user, 'record_date' => new DateValue(time() + get_user_gmt_offset($this->logged_user)), 'billable_status' => BILLABLE_STATUS_BILLABLE);
     }
     // if
     $this->smarty->assign(array('timetracking_data' => $timetracking_data));
     $render_row = (bool) $this->request->get('async');
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $timetracking_data['value'] = time_to_float($timetracking_data['value']);
         $this->active_time->log_activities = false;
         $this->active_time->setAttributes($timetracking_data);
         $this->active_time->setProjectId($this->active_project->getId());
         $this->active_time->setCreatedBy($this->logged_user);
         $user_id = array_var($timetracking_data, 'user_id');
         if ($user_id) {
             $user = Users::findById($user_id);
             if (instance_of($user, 'User')) {
                 $this->active_time->setUser($user);
             }
             // if
         }
         // if
         $this->active_time->setState(STATE_VISIBLE);
         if (instance_of($this->active_object, 'ProjectObject')) {
             $this->active_time->setParent($this->active_object);
             $this->active_time->setVisibility($this->active_object->getVisibility());
         } else {
             $this->active_time->setVisibility(VISIBILITY_NORMAL);
         }
         // if
         $save = $this->active_time->save();
         if ($save && !is_error($save)) {
             $activity_log = new TimeAddedActivityLog();
             $activity_log->log($this->active_time, $this->logged_user);
             db_commit();
             $this->active_time->ready();
             if ($this->request->get('for_popup_dialog')) {
                 $this->_render_popup_content();
             }
             // if
             if ($render_row) {
                 $this->smarty->assign('timerecord', $this->active_time);
                 $this->smarty->display(get_template_path('_time_row', 'timetracking', TIMETRACKING_MODULE));
                 die;
             } else {
                 if ($this->request->getFormat() == FORMAT_HTML) {
                     if (!is_null($render_row)) {
                         flash_success('Time record has been added');
                         $this->redirectToUrl(timetracking_module_url($this->active_project));
                     }
                     // if
                 } else {
                     $this->serveData($this->active_time, 'time_record');
                 }
                 // if
             }
             // if
         } else {
             db_rollback();
             if ($this->request->get('for_popup_dialog')) {
                 $this->_render_popup_content();
             }
             // if
             if ($render_row) {
                 $this->httpError(HTTP_ERR_INVALID_PROPERTIES);
             } else {
                 if ($this->request->getFormat() == FORMAT_HTML) {
                     $this->smarty->assign('errors', $save);
                 } else {
                     $this->serveData($save);
                 }
                 // if
             }
             // if
         }
         // if
     }
     // if
 }
 /**
  * Return timetracking URL for this object
  *
  * @param void
  * @return string
  */
 function getTimeUrl()
 {
     return timetracking_module_url($this->getProject(), $this);
 }