From e7b8b047fe5f280c5f96244ced44f4ee365dacf3 Mon Sep 17 00:00:00 2001 From: Raphael Dannecker Date: Fri, 27 Nov 2020 22:56:04 +0100 Subject: [PATCH] Initial commit --- composer.json | 5 +++++ config.php.sample | 25 +++++++++++++++++++++++++ upload_timetable.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 composer.json create mode 100644 config.php.sample create mode 100644 upload_timetable.php diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..457a3a5 --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "llagerlof/moodlerest": "2.3.0" + } +} diff --git a/config.php.sample b/config.php.sample new file mode 100644 index 0000000..2b53319 --- /dev/null +++ b/config.php.sample @@ -0,0 +1,25 @@ + 'lesson', 'file' => 'untis/export/lesson.txt'); +$config['files'][] = array('name' => 'teacher', 'file' => 'untis/export/teacher.txt'); +$config['files'][] = array('name' => 'room', 'file' => 'untis/export/room.txt'); +$config['files'][] = array('name' => 'class', 'file' => 'untis/export/class.txt'); +$config['files'][] = array('name' => 'time', 'file' => 'untis/export/time.txt'); +$config['files'][] = array('name' => 'absence_reason', 'file' => 'untis/export/GPU012.TXT'); +$config['files'][] = array('name' => 'absence', 'file' => 'untis/export/GPU013.TXT'); +$config['files'][] = array('name' => 'substitution', 'file' => 'untis/export/GPU014.TXT'); + + diff --git a/upload_timetable.php b/upload_timetable.php new file mode 100644 index 0000000..6ae3c67 --- /dev/null +++ b/upload_timetable.php @@ -0,0 +1,44 @@ + + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once dirname(__FILE__) . '/vendor/autoload.php'; +require_once('config.php'); + +$token = '8d962a172b9f56f65712e5710fca2435'; +$domainname = 'https://moodlesb.steinbeisschule-reutlingen.de'; + +$MoodleRest = new MoodleRest($config['url'], $config['token']); + +if (file_exists ($config['hashfile'])) { + $hashfile = file_get_contents($config['hashfile']); + $hashes = (array) json_decode($hashfile); +} else $hashes = array(); + +$untis_data = array('files' => array()); +foreach($config['files'] as $file) { + $content = file_get_contents($file['file']); + $hash = md5($content); + if (! array_key_exists($file['name'],$hashes) || $hashes[$file['name']] != $hash) + $untis_data['files'][] = array('name' => $file['name'], 'content' => base64_encode($content)); + $hashes[$file['name']] = $hash; +} + +if (count($untis_data['files'])) { + $result = $MoodleRest->request('mod_timetable_update', $untis_data, MoodleRest::METHOD_POST); + print_r($result); + if (true) { + $hashfile = fopen($config['hashfile'],'w'); + fwrite($hashfile, json_encode($hashes, JSON_FORCE_OBJECT)); + fclose($hashfile); + } +} else { + echo "Nothing to do\n"; +} + +