Fixed location update page

This commit is contained in:
xdrm-brackets 2017-09-16 12:19:05 +02:00
parent 27dfc1c03d
commit 9fb8327c24
1 changed files with 10 additions and 17 deletions

View File

@ -107,25 +107,17 @@
$location = []; $location = [];
/* (1) Get the list of available locations*/ /* (1) Get the list of available locations*/
$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 = DatabaseDriver::getPDO()->prepare("SELECT GROUP_CONCAT(DISTINCT l.id_location SEPARATOR ',') as idl, l.name as lname, l.basename as lbasename, 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 lname, lbasename, ename, color ORDER BY ename ASC, lbasename ASC");
$sqlr->execute([ ':idd' => $this->diplome_id ]); $sqlr->execute([ ':idd' => $this->diplome_id ]);
$fetched = $sqlr->fetchAll(); $fetched = $sqlr->fetchAll();
if( !$fetched ){ if( !$fetched )
$fetched[] = []; $fetched[] = [];
$locdata[] = [];
}
foreach($fetched as $raw){
if( !isset($location[$raw['ename']]) ) // foreach($fetched as $raw)
$location[$raw['ename']] = []; // $location[$raw['ename']] = [ $raw['ename'], $raw['idl'], $raw['lname'], $raw['lbasename'], $raw['color'] ];
$location[$raw['ename']][] = intval( $raw['idl'] );
$locdata[$raw['ename']] = [ $raw['name'], $raw['basename'], $raw['color'] ];
}
// } // }
@ -133,12 +125,13 @@
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($location as $ename=>$ids){ foreach($fetched as $raw){
$color = $locdata[$ename][2]; $color = $raw['color'];
$id = implode(",", $ids); $id = $raw['idl'];
$name = $locdata[$ename][0]; $name = $raw['lname'];
$basename = $locdata[$ename][1]; $basename = $raw['lbasename'];
$ename = $raw['ename'];
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 "<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>";
} }