Untitled

                Never    
PHP
       
<?php

header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=calendar.csv');

require('spreadsheet-reader-master/SpreadsheetReader.php');

$events = parse2018IDPart1('Orar-semI-ID-2018-2019_V2.xlsx');
$events_sorted_per_request = $events[$_GET['year']][$_GET['group']];

foreach ($events_sorted_per_request as $key => $row) {
    $arr_date[$key] = $row['_Date'];
}
array_multisort($arr_date,  SORT_ASC, $events_sorted_per_request);

echo "Subject,Start Date,Start Time,End Date,End Time,Location\n";
foreach ($events_sorted_per_request as $event) {
    echo "\"" . $event['Subject'] . "\"," . $event['Start Date'] . "," . $event['Start Time'] . "," . $event['End Date'] . "," . $event['End Time'] . ",\"" . $event['Location'] . "\"\n";
}

function parse2018IDPart1($fileName)
{
    $events = array();

    $date_begin = strtotime('2018-10-06');

    $dates = array();
    for ($i = 0; $i < 15; $i++) {
      if (date('d/m/Y', strtotime('+' . $i . ' week', $date_begin)) == '01/12/2018' ||
          date('d/m/Y', strtotime('+' . $i . ' week', $date_begin)) == '22/12/2018' ||
          date('d/m/Y', strtotime('+' . $i . ' week', $date_begin)) == '29/12/2018' ||
          date('d/m/Y', strtotime('+' . $i . ' week', $date_begin)) == '05/01/2019') {
          continue;
      }

      $dates[] = array(date('m/d/Y', strtotime('+' . $i . ' week', $date_begin)), date('Y-m-d', strtotime('+' . $i . ' week', $date_begin)));
      $dates[] = array(date('m/d/Y', strtotime('+' . $i . ' week, +1 day', $date_begin)), date('Y-m-d', strtotime('+' . $i . ' week, +1 day', $date_begin)));
      $dates[] = '';
    }

    $reader = new SpreadsheetReader($fileName);

    $year = '';
    foreach ($reader as $row) {
        $date_index = 0;

        $group = '0';
        $start_time = '';
        $end_time = '';

        foreach ($row as $cell) {
            if (strpos($cell, "Anul ") === 0) {
                $year = strlen(substr($cell, 5));

                continue;
            }

            if (strpos($cell, "G1") === 0 || strpos($cell, "G2") === 0) {
                $group = intval(substr($cell, 1));

                continue;
            }

            preg_match('/^([0-9]{1,}).([0-9]{1,})-([0-9]{1,}).([0-9]{1,})$/', $cell, $matches, PREG_OFFSET_CAPTURE);
            if (count($matches)) {
                $start_time = (intval($matches[1][0]) > 12 ? (intval($matches[1][0]) - 12) : intval($matches[1][0])) . ':' . $matches[2][0] . ' ' . (intval($matches[1][0]) > 11 ? 'PM' : 'AM');
                $end_time = (intval($matches[3][0]) > 12 ? (intval($matches[3][0]) - 12) : intval($matches[3][0])) . ':' . $matches[4][0] . ' ' . (intval($matches[3][0]) > 11 ? 'PM' : 'AM');

                continue;
            }

            if ($year && $start_time && $end_time) {
                $location_building = '';
                $location_level = '';
                $location_room = '';

                if ($cell) {
                    preg_match('/([A-Z]{1})([I]{1,})([0-9]{1})$/', $cell, $matches, PREG_OFFSET_CAPTURE);
                    if (count($matches)) {
                        $location_building = $matches[1][0];
                        $location_level = strlen($matches[2][0]);
                        $location_room = intval($matches[3][0]);

                        $description = trim(substr($cell, 0, $matches[0][1]));
                    } else {
                        $description = trim($cell);
                    }

                    if (!isset($events[$year])) {
                        $events[$year] = array();
                    }

                    if (!isset($events[$year][$group])) {
                        $events[$year][$group] = array();
                    }

                    $events[$year][$group][] = array(
                        'Subject' => $description,
                        'Start Date' => $dates[$date_index][0],
                        'Start Time' => $start_time,
                        'End Date' => $dates[$date_index][0],
                        'End Time' => $end_time,
                        'Location' => ($location_building != '' ? ('Corp ' . $location_building . ' Etaj ' . $location_level . ' Sala ' . $location_room) : 'Necunoscuta'),
                        '_Date' => date('Y-m-d H:i:s', strtotime($dates[$date_index][1] . ' ' . $start_time)),
                        '_Index' => $date_index
                    );

                    if ($description == 'Deschidere an universitar' && $year == 1 && $group == 1) {
                        if (!isset($events[$year][2])) {
                            $events[$year][2] = array();
                        }

                        $events[$year][2][] = array(
                            'Subject' => $description,
                            'Start Date' => $dates[$date_index][0],
                            'Start Time' => $start_time,
                            'End Date' => $dates[$date_index][0],
                            'End Time' => $end_time,
                            'Location' => ($location_building != '' ? ('Corp ' . $location_building . ' Etaj ' . $location_level . ' Sala ' . $location_room) : 'Necunoscuta'),
                            '_Date' => date('Y-m-d H:i:s', strtotime($dates[$date_index][1] . ' ' . $start_time)),
                            '_Index' => $date_index
                        );
                    }
                }

                $date_index++;
            }
        }
    }

    return $events;
}

Raw Text