/**
  * Create a new task and write it to the database.
  *
  * @return RedirectResponse
  */
 public function createTask()
 {
     // first we fill objects with data
     // if there is an error, we have not saved yet, so we need no rollback
     $newSchedule = $this->editSchedule(null);
     $newEntries = ScheduleController::createScheduleEntries();
     // capture showInWeekView-checkbox
     $newSchedule->schdl_show_in_week_view = !is_null(Input::get('showInWeekView'));
     // all data in the database
     $newSchedule->save();
     foreach ($newEntries as $newEntry) {
         $newEntry->schdl_id = $newSchedule->id;
         $newEntry->save();
     }
     // log the action
     Log::info('Create task: User ' . Session::get('userId') . ' with rigths ' . Session::get('userGroup') . ' creates task ' . $newSchedule->schdl_title . ' with id ' . $newSchedule->id . '.');
     // show new task
     return Redirect::action('ScheduleController@showSchedule', array('id' => $newSchedule->id));
 }
 /**
  * Create a new event with schedule and write it to the database.
  *
  * @return RedirectResponse
  */
 public function createEvent()
 {
     //validate passwords
     if (Input::get('password') != Input::get('passwordDouble')) {
         Session::put('message', Config::get('messages_de.password-mismatch'));
         Session::put('msgType', 'danger');
         return Redirect::back()->withInput();
     }
     $newEvent = $this->editClubEvent(null);
     $newEvent->save();
     $newSchedule = $this->editSchedule(null);
     $newSchedule->evnt_id = $newEvent->id;
     // log revision
     $newSchedule->entry_revisions = json_encode(array("0" => ["entry id" => null, "job type" => null, "action" => "Dienstplan erstellt", "old id" => null, "old value" => null, "new id" => null, "new value" => null, "user id" => Session::get('userId') != NULL ? Session::get('userId') : "", "user name" => Session::get('userId') != NULL ? Session::get('userName') . '(' . Session::get('userClub') . ')' : "Gast", "from ip" => Request::getClientIp(), "timestamp" => (new DateTime())->format('Y-m-d H:i:s')]));
     $newSchedule->save();
     $newEntries = ScheduleController::createScheduleEntries($newSchedule->id);
     foreach ($newEntries as $newEntry) {
         $newEntry->schdl_id = $newSchedule->id;
         $newEntry->save();
         // log revision
         ScheduleController::logRevision($newEntry->getSchedule, $newEntry, "Dienst erstellt", null, null);
         // new value
     }
     // log the action
     Log::info('Create event: User ' . Session::get('userName') . '(' . Session::get('userId') . ', ' . Session::get('userGroup') . ') created event ' . $newEvent->evnt_title . ' (ID: ' . $newEvent->id . ').');
     // show new event
     return Redirect::action('CalendarController@showId', array('id' => $newEvent->id));
 }