upload_timetable/upload_timetable.php

40 lines
1.2 KiB
PHP
Raw Normal View History

2020-11-27 22:56:04 +01:00
<?php
/**
* upload-timetable
*
* @package upload_timetable
* @copyright 2020 Raphael Dannecker <raphael.dannecker@steinbeisschule-reutlingen.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once dirname(__FILE__) . '/vendor/autoload.php';
require_once('config.php');
$MoodleRest = new MoodleRest($config['url'], $config['token']);
if (file_exists ($config['hashfile'])) {
2020-11-27 23:06:20 +01:00
$hashfile = file_get_contents($config['hashfile']);
$hashes = (array) json_decode($hashfile);
2020-11-27 22:56:04 +01:00
} else $hashes = array();
$untis_data = array('files' => array());
foreach($config['files'] as $file) {
2020-11-27 23:06:20 +01:00
$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;
2020-11-27 22:56:04 +01:00
}
if (count($untis_data['files'])) {
$result = $MoodleRest->request('mod_timetable_update', $untis_data, MoodleRest::METHOD_POST);
print_r($result);
if (true) {
2020-11-27 23:06:20 +01:00
$hashfile = fopen($config['hashfile'],'w');
fwrite($hashfile, json_encode($hashes, JSON_FORCE_OBJECT));
fclose($hashfile);
2020-11-27 22:56:04 +01:00
}
} else {
2020-11-27 23:06:20 +01:00
echo "Nothing to do\n";
2020-11-27 22:56:04 +01:00
}