univ-pau-ics/build/service/lib/update.php

93 lines
1.8 KiB
PHP
Raw Normal View History

2017-09-12 07:49:38 +00:00
<?php
// Absolute root dir
$ABSROOT = dirname(__DIR__);
/* [1] Check needed files
=========================================================*/ {
$path = [
'cursus' => "$ABSROOT/../../tmp/cursus.json",
'period' => "$ABSROOT/../../tmp/period.json",
];
/* (1) cursus list */
if( !file_exists($path['cursus']) )
die(" * Missing tmp/cursus.json\n");
/* (2) period list */
if( !file_exists($path['period']) )
die(" * Missing tmp/period.json\n");
}
/* [2] Parse cursus list
=========================================================*/ {
/* (1) Read from file */
$clist = file_get_contents($path['cursus']);
/* (2) Manage error */
if( $clist == false )
die(" * Cannot read cursus file\n");
/* (3) Parse JSON */
$clist = json_decode($clist, true);
/* (4) Manage error */
if( $clist == null )
die(" * Cannot parse cursus file\n");
}
/* [3] Parse period list
=========================================================*/ {
/* (1) Read from file */
$plist = file_get_contents($path['period']);
/* (2) Manage error */
if( $plist == false )
die(" * Cannot read period file\n");
/* (3) Parse JSON */
$plist = json_decode($plist, true);
/* (4) Manage error */
if( $plist == null )
die(" * Cannot parse period file\n");
}
/* [4] Manage each cursus
=========================================================*/ {
/* (1) For each cursus */
foreach($clist as $cname=>$cvalue){
/* (1.2) Create a directory */
if( !file_exists("$ABSROOT/../../tmp/$cvalue") )
file_put_contents("$ABSROOT/../../tmp/$cvalue.ics", "");
/* (1) Download all images
---------------------------------------------------------*/
foreach($plist as $pvalue=>$pdate)
"http://sciences.univ-pau.fr/edt/diplomes/${cvalue}${pvalue}.png"; // image file
}
}