$_POST['action'] = 'select_role';
     $error_level = 2;
 } else {
     if (!activity::validate('amount', $_POST['activity_amount'])) {
         $error_level = 3;
     } else {
         if ($_POST['tariffs_id'] == '') {
             $error_level = 4;
         } else {
             if (!activity::validate('travel_distance', $_POST['activity_travel_distance'])) {
                 $error_level = 5;
             } else {
                 if (!activity::validate('expenses', $_POST['activity_expenses'])) {
                     $error_level = 6;
                 } else {
                     if (activity::ticket_entry_is_required($_POST['tariffs_id']) && !tep_not_null($_POST['activity_ticket_number'])) {
                         // no ticket number when required
                         $error_level = 7;
                     } else {
                         if (!project::hours_fit_in_calculated_amount($_POST['projects_id'], activity::format('amount', $_POST['activity_amount']) - $_POST['original_activity_amount'], $_POST['selected_date']) && ($_POST['error_level_history'] != 32 || $_POST['previous_activity_amount'] != activity::format('amount', $_POST['activity_amount']))) {
                             // Exceeding calculated hours, the definite value is calculated by subtracting the original value
                             // (original_activity_amount, only available when editing an existing activity) from the entered value.
                             // When OK-ing the 2nd time (error_level_history==32) without changing the activity_amount value
                             // (tested with previous_activity_amount), the entry will be saved.
                             $error_level = 32;
                         } else {
                             // OK, entry can be saved
                             $_SESSION['timesheet']->save_activity($_POST['activity_id'], $_POST['selected_date'], $_POST['activity_amount'], $_POST['tariffs_id'], $_POST['activity_travel_distance'], $_POST['activity_travel_description'], $_POST['activity_expenses'], $_POST['activity_ticket_number'], $_POST['activity_comment']);
                             // Clear all values except mPath and period
                             foreach ($_POST as $key => $value) {
                                 if ($key != 'mPath' && $key != 'period' && $key != 'sort_order') {