univ-pau-ics/build/router/controller/ics.php

124 lines
2.4 KiB
PHP
Raw Normal View History

<?php
namespace router\controller;
2017-09-14 17:56:24 +00:00
use \database\core\DatabaseDriver;
2017-09-13 13:03:36 +00:00
class ics{
private $diplome_id;
/* PRE-CALL
*
* @url<String> Calling URI
*
*/
public function __construct($url){
$this->diplome_id = $url['diplome_id'];
2017-09-13 13:03:36 +00:00
}
/* CALL
*
*/
public function download(){
/* [1] Check .ics file
=========================================================*/
/* (1) Set file name */
$file_name = __ROOT__."/tmp/".$this->diplome_id.".ics";
/* (2) Check if exists */
if( !file_exists($file_name) )
die("An error occured. Please contact the developers.\n");
/* [2] Display file
=========================================================*/
/* (1) Headers */
2017-09-14 15:15:08 +00:00
header('Content-Type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename='.$this->diplome_id.'.ics');
/* (2) Body */
readfile($file_name);
}
2017-09-13 13:03:36 +00:00
public function info(){
2017-09-14 17:56:24 +00:00
/* [1] Get database data
2017-09-13 13:03:36 +00:00
=========================================================*/
2017-09-14 17:56:24 +00:00
/* (1) Get the list of available events */
$sqlr = DatabaseDriver::getPDO()->prepare("SELECT * FROM event WHERE id_diplome = :idd");
$sqlr->execute([ ':idd' => $this->diplome_id ]);
$d_cols = $sqlr->fetchAll();
/* (2) Manage error */
if( !$d_cols )
die("Correction not available for this diplome");
echo "<form method='POST' action='/correct/".$this->diplome_id."'>";
foreach($d_cols as $data){
$id = $data['id_event'];
$basename = $data['basename'];
$color = $data['color'];
$name = $data['name'];
echo "$basename <input type='text' style='display: inline-block; margin: 1em .2em; padding: .2em; border: none; background-color: $color;' name='name[$id]' value='$name'><br>";
}
echo "<input type='submit' value='SAVE'>";
echo "</form>";
}
public function correct(){
/* [1] Update data
=========================================================*/ {
2017-09-13 13:03:36 +00:00
2017-09-14 17:56:24 +00:00
/* (1) Check $_POST['name'] */
if( !isset($_POST['name']) || !is_array($_POST['name']) )
die("No data received");
2017-09-13 13:03:36 +00:00
2017-09-14 17:56:24 +00:00
/* (2) Store corrections */
foreach($_POST['name'] as $id=>$correct){
2017-09-13 13:03:36 +00:00
2017-09-14 17:56:24 +00:00
if( !empty(trim($correct)) ){
2017-09-13 13:03:36 +00:00
2017-09-14 17:56:24 +00:00
$sqlr = DatabaseDriver::getPDO()->prepare("UPDATE event SET name = :name WHERE id_event = :ide");
$sqlr->execute([ ':name' => $correct, ':ide' => $id ]);
2017-09-13 13:03:36 +00:00
2017-09-14 17:56:24 +00:00
}
2017-09-13 13:03:36 +00:00
2017-09-14 17:56:24 +00:00
}
2017-09-13 13:03:36 +00:00
}
}
/* POST-CALL
*
*/
public function __destruct(){
}
}