Gestion renommage salles par nom cours (nom corrigé)

This commit is contained in:
xdrm-brackets 2017-09-16 01:37:54 +02:00
parent fa5948fd2a
commit 27dfc1c03d
1 changed files with 46 additions and 31 deletions

View File

@ -92,52 +92,55 @@
/* [1] Get events data
=========================================================*/
/* (1) Get the list of available events */
$sqlr = DatabaseDriver::getPDO()->prepare("SELECT * FROM event WHERE id_diplome = :idd");
$sqlr->execute([ ':idd' => $this->diplome_id ]);
$events = $sqlr->fetchAll();
// $sqlr = DatabaseDriver::getPDO()->prepare("SELECT * FROM event WHERE id_diplome = :idd");
// $sqlr->execute([ ':idd' => $this->diplome_id ]);
// $events = $sqlr->fetchAll();
/* (2) Manage error */
if( !$events )
die("Correction not available for this diplome");
// if( !$events )
// die("Correction not available for this diplome");
/* [2] Get location data
=========================================================*/
foreach($events as &$event){
// foreach($events as &$event){
$event['location'] = [];
$location = [];
/* (1) Get the list of available locations*/
$sqlr = DatabaseDriver::getPDO()->prepare("SELECT * FROM location WHERE id_event = :ide");
$sqlr->execute([ ':ide' => $event['id_event'] ]);
$locations = $sqlr->fetchAll();
$sqlr = DatabaseDriver::getPDO()->prepare("SELECT l.id_location as idl, l.name as name, l.basename as basename, e.name as ename, e.color as color FROM location as l, event as e WHERE l.id_event = e.id_event AND e.id_diplome = :idd GROUP BY idl, name, basename, ename, color");
$sqlr->execute([ ':idd' => $this->diplome_id ]);
$fetched = $sqlr->fetchAll();
if( !$locations )
$locations = [];
if( !$fetched ){
$fetched[] = [];
$locdata[] = [];
}
foreach($locations as $location)
$event['location'][] = $location;
foreach($fetched as $raw){
if( !isset($location[$raw['ename']]) )
$location[$raw['ename']] = [];
$location[$raw['ename']][] = intval( $raw['idl'] );
$locdata[$raw['ename']] = [ $raw['name'], $raw['basename'], $raw['color'] ];
}
// }
echo "<form method='POST' action='/xlocation/".$this->diplome_id."'>";
echo "<table><thead style='font-weight: bold;'><tr><td>Lesson</td><td>Read name</td><td>Correction</td></tr></thead><tbody>";
foreach($events as $event){
foreach($location as $ename=>$ids){
$color = $locdata[$ename][2];
$id = implode(",", $ids);
$name = $locdata[$ename][0];
$basename = $locdata[$ename][1];
foreach($event['location'] as $location){
$color = $event['color'];
$id = $location['id_location'];
$basename = $location['basename'];
$name = $location['name'];
$e_name = $event['name'];
echo "<tr><td><b>$e_name</b></td><td>$basename</td><td><input type='text' style='display: inline-block; margin: 1em .2em; padding: .2em; border: none; background-color: $color;' name='name[$id]' value='$name'></td></tr>";
}
echo "<tr><td><b>$ename</b></td><td>$basename</td><td><input type='text' style='display: inline-block; margin: 1em .2em; padding: .2em; border: none; background-color: $color;' name='name[$id]' value='$name'></td></tr>";
}
echo "</tbody></table>";
@ -237,9 +240,19 @@
die("No data received");
/* (2) Store corrections */
foreach($_POST['name'] as $id=>$correct){
foreach($_POST['name'] as $ids=>$correct){
if( !empty(trim($correct)) ){
// check if containing id list
if( !preg_match('@^\d+(,\d+)*$@', $ids) )
continue;
// update for each location
$id_list = explode(',', $ids);
foreach($id_list as $id){
$sqlr = DatabaseDriver::getPDO()->prepare("UPDATE location SET name = :name WHERE id_location = :idl");
$sqlr->execute([ ':name' => $correct, ':idl' => $id ]);
@ -249,6 +262,8 @@
}
}