From eac6d08df51217e6a09d3730a97bc9e2cb3b1bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Fri, 27 Sep 2019 20:00:47 +0200 Subject: [PATCH] Version19.17 --- swad_changelog.h | 4 +- swad_game.c | 26 +++++++---- swad_game.h | 1 + swad_match.c | 119 +++++++++++++++++++++++++++-------------------- 4 files changed, 88 insertions(+), 62 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index e1c4540ac..9d94e65e9 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -447,6 +447,7 @@ Lo de mutear anuncios, en principio prefiero hacer una opci // de la asignatura si desean o no que se pueda solicitar // inscripción en la asignatura +// TODO: Reported by Francisco José Pelayo Valle: un estudiante sube 50 ficheros de golpe ==> el firewall le banea. No debería, ¿o sí? // TODO: En Eventos de asistencia, poner un icono de enlace a horario de la asignatura ¿y otro a grupos? // TODO: Reportado por Javier Fernández Baldomero. Un profesor debería poder cambiar la foto de un estudiante confirmado. Sale el icono, pero luego dice ue no hay permiso @@ -470,10 +471,11 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.16.8 (2019-09-27)" +#define Log_PLATFORM_VERSION "SWAD 19.17 (2019-09-27)" #define CSS_FILE "swad19.15.css" #define JS_FILE "swad19.15.js" /* + Version 19.17: Sep 27, 2019 Improvements in the code that deletes a match. (246410 lines) Version 19.16.8: Sep 27, 2019 Code refactoring. (246387 lines) Version 19.16.7: Sep 27, 2019 Show match result for student in listing of matches. (246386 lines) Version 19.16.6: Sep 27, 2019 Code refactoring in match dates. (246378 lines) diff --git a/swad_game.c b/swad_game.c index 140792578..5fc89ed1c 100644 --- a/swad_game.c +++ b/swad_game.c @@ -688,9 +688,10 @@ void Gam_GetDataOfGameByCod (struct Game *Game) /***** Get data of game from database *****/ NumRows = DB_QuerySELECT (&mysql_res,"can not get game data", "SELECT gam_games.GamCod," // row[0] - "gam_games.Hidden," // row[1] - "gam_games.UsrCod," // row[2] - "gam_games.Title" // row[3] + "gam_games.CrsCod," // row[1] + "gam_games.Hidden," // row[2] + "gam_games.UsrCod," // row[3] + "gam_games.Title" // row[4] " FROM gam_games" " LEFT JOIN mch_matches" " ON gam_games.GamCod=mch_matches.GamCod" @@ -704,14 +705,17 @@ void Gam_GetDataOfGameByCod (struct Game *Game) /* Get code of the game (row[0]) */ Game->GamCod = Str_ConvertStrCodToLongCod (row[0]); - /* Get whether the game is hidden (row[1]) */ - Game->Status.Visible = (row[1][0] == 'N'); + /* Get code of the course (row[1]) */ + Game->CrsCod = Str_ConvertStrCodToLongCod (row[1]); - /* Get author of the game (row[2]) */ - Game->UsrCod = Str_ConvertStrCodToLongCod (row[2]); + /* Get whether the game is hidden (row[2]) */ + Game->Status.Visible = (row[2][0] == 'N'); - /* Get the title of the game (row[3]) */ - Str_Copy (Game->Title,row[3], + /* Get author of the game (row[3]) */ + Game->UsrCod = Str_ConvertStrCodToLongCod (row[3]); + + /* Get the title of the game (row[4]) */ + Str_Copy (Game->Title,row[4], Gam_MAX_BYTES_TITLE); /* Get number of questions */ @@ -796,7 +800,9 @@ static void Gam_ResetGame (struct Game *Game,long UsrCod) { /***** Initialize to empty game *****/ Game->GamCod = -1L; - Game->UsrCod = UsrCod; + Game->CrsCod = -1L; + // Game->UsrCod = UsrCod; + Game->UsrCod = -1L; Game->TimeUTC[Dat_START_TIME] = (time_t) 0; Game->TimeUTC[Dat_END_TIME ] = (time_t) 0; Game->Title[0] = '\0'; diff --git a/swad_game.h b/swad_game.h index e21e8d805..d9c20ce50 100644 --- a/swad_game.h +++ b/swad_game.h @@ -40,6 +40,7 @@ struct Game { long GamCod; // Game code + long CrsCod; // Course code long UsrCod; // Author code char Title[Gam_MAX_BYTES_TITLE + 1]; time_t TimeUTC[Dat_NUM_START_END_TIME]; diff --git a/swad_match.c b/swad_match.c index dd701bbea..6aba98bf8 100644 --- a/swad_match.c +++ b/swad_match.c @@ -153,6 +153,9 @@ static void Mch_GetMatchDataFromRow (MYSQL_RES *mysql_res, struct Match *Match); static Mch_Showing_t Mch_GetShowingFromStr (const char *Str); +static void Mch_RemoveMatchFromAllTables (long MchCod); +static void Mch_RemoveMatchFromTable (long MchCod,const char *TableName); + static void Mch_PutParamCurrentMchCod (void); static void Mch_PutParamMchCod (long MchCod); static long Mch_GetParamMchCod (void); @@ -1006,6 +1009,7 @@ void Mch_RemoveMatchTch (void) { extern const char *Txt_Match_X_removed; struct Match Match; + struct Game Game; /***** Get parameters *****/ /* Get match code */ @@ -1014,59 +1018,18 @@ void Mch_RemoveMatchTch (void) /***** Get data of the match from database *****/ Mch_GetDataOfMatchByCod (&Match); - - /***** Remove the match from all the tables *****/ - /* Remove match players */ - DB_QueryDELETE ("can not remove match players", - "DELETE FROM mch_players" - " USING mch_players,mch_matches,gam_games" - " WHERE mch_players.MchCod=%ld" - " AND mch_players.MchCod=mch_matches.MchCod" - " AND mch_matches.GamCod=gam_games.GamCod" - " AND gam_games.CrsCod=%ld", // Extra check - Match.MchCod,Gbl.Hierarchy.Crs.CrsCod); - - /* Remove match from list of matches being played */ - DB_QueryDELETE ("can not remove match from matches being played", - "DELETE FROM mch_playing" - " USING mch_playing,mch_matches,gam_games" - " WHERE mch_playing.MchCod=%ld" - " AND mch_playing.MchCod=mch_matches.MchCod" - " AND mch_matches.GamCod=gam_games.GamCod" - " AND gam_games.CrsCod=%ld", // Extra check - Match.MchCod,Gbl.Hierarchy.Crs.CrsCod); - - /* Remove students' answers to match */ - DB_QueryDELETE ("can not remove students' answers associated to a match", - "DELETE FROM mch_answers" - " USING mch_answers,mch_matches,gam_games" - " WHERE mch_answers.MchCod=%ld" - " AND mch_answers.MchCod=mch_matches.MchCod" - " AND mch_matches.GamCod=gam_games.GamCod" - " AND gam_games.CrsCod=%ld", // Extra check - Match.MchCod,Gbl.Hierarchy.Crs.CrsCod); - - /* Remove groups associated to the match */ - DB_QueryDELETE ("can not remove the groups associated to a match", - "DELETE FROM mch_groups" - " USING mch_groups,mch_matches,gam_games" - " WHERE mch_groups.MchCod=%ld" - " AND mch_groups.MchCod=mch_matches.MchCod" - " AND mch_matches.GamCod=gam_games.GamCod" - " AND gam_games.CrsCod=%ld", // Extra check - Match.MchCod,Gbl.Hierarchy.Crs.CrsCod); - - /* Remove the match itself */ - DB_QueryDELETE ("can not remove a match", - "DELETE FROM mch_matches" - " USING mch_matches,gam_games" - " WHERE mch_matches.MchCod=%ld" - " AND mch_matches.GamCod=gam_games.GamCod" - " AND gam_games.CrsCod=%ld", // Extra check - Match.MchCod,Gbl.Hierarchy.Crs.CrsCod); - if (!mysql_affected_rows (&Gbl.mysql)) + if (Match.MchCod < 0) Lay_ShowErrorAndExit ("The match to be removed does not exist."); + /***** Ensure that the match belongs to this course *****/ + Game.GamCod = Match.GamCod; + Gam_GetDataOfGameByCod (&Game); + if (Game.CrsCod != Gbl.Hierarchy.Crs.CrsCod) + Lay_ShowErrorAndExit ("Match does not belong to this course."); + + /***** Remove the match from all database tables *****/ + Mch_RemoveMatchFromAllTables (Match.MchCod); + /***** Write message *****/ Ale_ShowAlert (Ale_SUCCESS,Txt_Match_X_removed, Match.Title); @@ -1078,6 +1041,60 @@ void Mch_RemoveMatchTch (void) false); // Do not put form to start new match } +/*****************************************************************************/ +/********************** Remove match from all tables *************************/ +/*****************************************************************************/ +/* +mysql> SELECT table_name FROM information_schema.tables WHERE table_name LIKE 'mch%'; ++-------------+ +| table_name | ++-------------+ +| mch_answers | +| mch_groups | +| mch_indexes | +| mch_matches | +| mch_players | +| mch_playing | +| mch_results | +| mch_times | ++-------------+ +8 rows in set (0.00 sec) +*/ +static void Mch_RemoveMatchFromAllTables (long MchCod) + { + static const char *MatchTables[] = + { + "mch_players", // match players + "mch_playing", // matches being played + "mch_results", // matches results + "mch_answers", // students' answers to matches + "mch_times", // times associated to matches + "mch_groups", // groups associated to matches + "mch_indexes", // indexes associated to matches + "mch_matches" // the matches themselves + }; +#define Mch_NUM_TABLES (sizeof (MatchTables) / sizeof (MatchTables[0])) + unsigned NumTable; + + for (NumTable = 0; + NumTable < Mch_NUM_TABLES; + NumTable++) + /* Remove match from table */ + Mch_RemoveMatchFromTable (MchCod,MatchTables[NumTable]); + } + +/*****************************************************************************/ +/************************ Remove match from table ****************************/ +/*****************************************************************************/ + +static void Mch_RemoveMatchFromTable (long MchCod,const char *TableName) + { + /***** Remove match from table *****/ + DB_QueryDELETE ("can not remove match from table", + "DELETE FROM %s WHERE MchCod=%ld", + TableName,MchCod); + } + /*****************************************************************************/ /***************** Put parameter with current match code *********************/ /*****************************************************************************/