From 27dfc1c03d99d5a0b488beda306869bb30cceabb Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 16 Sep 2017 01:37:54 +0200 Subject: [PATCH] =?UTF-8?q?Gestion=20renommage=20salles=20par=20nom=20cour?= =?UTF-8?q?s=20(nom=20corrig=C3=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/router/controller/ics.php | 77 ++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/build/router/controller/ics.php b/build/router/controller/ics.php index b33a49a..f4535e5 100644 --- a/build/router/controller/ics.php +++ b/build/router/controller/ics.php @@ -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 "
"; echo ""; - 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 ""; - - } - + echo ""; } echo "
LessonRead nameCorrection
$e_name$basename
$ename$basename
"; @@ -237,11 +240,23 @@ die("No data received"); /* (2) Store corrections */ - foreach($_POST['name'] as $id=>$correct){ + foreach($_POST['name'] as $ids=>$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 ]); + + } }