{*
 Шаблон вычисления "Создать расписание"
*}

$week_arr = [
    'Воскресенье',
    'Понедельник',
    'Вторник',
    'Среда',
    'Четверг',
    'Пятница',
    'Суббота',
];
$weekdays = explode("\r\n", $line['{$weekdays}']);
$date = $line['{$date1}'];
while ($date <= $line['{$date2}']) {
    $weekday = $week_arr[date('w', strtotime($date))];
    if (in_array($weekday, $weekdays)) {
        data_insert({$weekday.table}, EVENTS_ENABLE, [
            '{$weekday.link_field_id}' => $line['id'],
            '{$weekday.field}' => $weekday,
            '{$datetime1.field}' => str_replace('00:00:00', $line['{$time1}'], $date),
            '{$datetime2.field}' => str_replace('00:00:00', $line['{$time2}'], $date),
        ]);
    }
    $date = date('Y-m-d H:i:s', strtotime($date) + 3600 * 24);
}