Gestion renommage salles par nom cours (nom corrigé)
This commit is contained in:
parent
fa5948fd2a
commit
27dfc1c03d
|
@ -92,52 +92,55 @@
|
||||||
/* [1] Get events data
|
/* [1] Get events data
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
/* (1) Get the list of available events */
|
/* (1) Get the list of available events */
|
||||||
$sqlr = DatabaseDriver::getPDO()->prepare("SELECT * FROM event WHERE id_diplome = :idd");
|
// $sqlr = DatabaseDriver::getPDO()->prepare("SELECT * FROM event WHERE id_diplome = :idd");
|
||||||
$sqlr->execute([ ':idd' => $this->diplome_id ]);
|
// $sqlr->execute([ ':idd' => $this->diplome_id ]);
|
||||||
$events = $sqlr->fetchAll();
|
// $events = $sqlr->fetchAll();
|
||||||
|
|
||||||
/* (2) Manage error */
|
/* (2) Manage error */
|
||||||
if( !$events )
|
// if( !$events )
|
||||||
die("Correction not available for this diplome");
|
// die("Correction not available for this diplome");
|
||||||
|
|
||||||
/* [2] Get location data
|
/* [2] Get location data
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
foreach($events as &$event){
|
// foreach($events as &$event){
|
||||||
|
|
||||||
$event['location'] = [];
|
$location = [];
|
||||||
|
|
||||||
/* (1) Get the list of available locations*/
|
/* (1) Get the list of available locations*/
|
||||||
$sqlr = DatabaseDriver::getPDO()->prepare("SELECT * FROM location WHERE id_event = :ide");
|
$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([ ':ide' => $event['id_event'] ]);
|
$sqlr->execute([ ':idd' => $this->diplome_id ]);
|
||||||
$locations = $sqlr->fetchAll();
|
$fetched = $sqlr->fetchAll();
|
||||||
|
|
||||||
if( !$locations )
|
if( !$fetched ){
|
||||||
$locations = [];
|
$fetched[] = [];
|
||||||
|
$locdata[] = [];
|
||||||
|
}
|
||||||
|
|
||||||
foreach($locations as $location)
|
foreach($fetched as $raw){
|
||||||
$event['location'][] = $location;
|
|
||||||
|
|
||||||
}
|
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 "<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>";
|
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){
|
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>";
|
||||||
|
|
||||||
$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 "</tbody></table>";
|
echo "</tbody></table>";
|
||||||
|
@ -237,11 +240,23 @@
|
||||||
die("No data received");
|
die("No data received");
|
||||||
|
|
||||||
/* (2) Store corrections */
|
/* (2) Store corrections */
|
||||||
foreach($_POST['name'] as $id=>$correct){
|
foreach($_POST['name'] as $ids=>$correct){
|
||||||
|
|
||||||
if( !empty(trim($correct)) ){
|
if( !empty(trim($correct)) ){
|
||||||
$sqlr = DatabaseDriver::getPDO()->prepare("UPDATE location SET name = :name WHERE id_location = :idl");
|
|
||||||
$sqlr->execute([ ':name' => $correct, ':idl' => $id ]);
|
// 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 ]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue