loadType("trainingplan", $id); $weeks_count = $trainingplan->getDuration(); $days_count = $trainingplan->getFrequency(); $starting_date = strtotime($start_date); $training_start_date = strtotime($start_date); $first_day = 0; foreach(range(1, $weeks_count) as $week) { if ($week == 1) { // find out first date $week_from_start = strtotime("+1 week", $training_start_date); foreach ($days as $daypos => $day) { $day_date = strtotime(ucfirst($day), $starting_date); if ($day_date < $week_from_start) { //$training_start_date = $day_date; $week_from_start = $day_date; $first_day = $daypos; } } } //$training_date = date('d.m.Y', $training_start_date); $startday = $first_day; foreach (range(1, $days_count) as $day_nr) { if ($day_nr != 1) { $startday = $startday + 1; if (count($days) <= $startday) { $startday = 0; } } $day = $days[$startday]; $training_start_date = strtotime(ucfirst($day),$training_start_date); $training_date = date('d.m.Y', $training_start_date); if ($days_count == 1 && ($week != $weeks_count)) $training_start_date = strtotime("+1 day", $training_start_date); $training = $fitness->loadType("training"); $training->setTitle($trainingplan->getTitle()); $training->setTrainingDate($training_date); $training->setBeginningHH($start_time_hour); $training->setBeginningMM($start_time_minutes); $training->setEndingHH($start_time_hour +1); $training->setEndingMM($start_time_minutes); $training_id = $training->create(); $exercises = $trainingplan->getDayExercises($day_nr); foreach ($exercises as $exercise_data) { if (!empty($exercise_data["exercise"])) { $exercise = $fitness->loadType("exercise"); $exercise->setTraining($training_id); $exercise->setMuscleGroup($exercise_data["muscle_group"]); $exercise->setExercise($exercise_data["exercise"]); $exercise->create(); } } } } // add record to activated_training_plans $trainingplan->addActivatedTrainingplanRecord($week_from_start, $training_start_date); //if ($delete_result) { $TeKe->add_system_message(_("Activated.")); //} forward(WWW_ROOT."{$handler}/view"); ?>