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 ]); + + } }