Version19.17

This commit is contained in:
Antonio Cañas Vargas 2019-09-27 20:00:47 +02:00
parent dce208c78a
commit eac6d08df5
4 changed files with 88 additions and 62 deletions

View File

@ -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 // de la asignatura si desean o no que se pueda solicitar
// inscripción en la asignatura // 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: 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 // 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: En OpenSWAD:
ps2pdf source.ps destination.pdf 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 CSS_FILE "swad19.15.css"
#define JS_FILE "swad19.15.js" #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.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.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) Version 19.16.6: Sep 27, 2019 Code refactoring in match dates. (246378 lines)

View File

@ -688,9 +688,10 @@ void Gam_GetDataOfGameByCod (struct Game *Game)
/***** Get data of game from database *****/ /***** Get data of game from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get game data", NumRows = DB_QuerySELECT (&mysql_res,"can not get game data",
"SELECT gam_games.GamCod," // row[0] "SELECT gam_games.GamCod," // row[0]
"gam_games.Hidden," // row[1] "gam_games.CrsCod," // row[1]
"gam_games.UsrCod," // row[2] "gam_games.Hidden," // row[2]
"gam_games.Title" // row[3] "gam_games.UsrCod," // row[3]
"gam_games.Title" // row[4]
" FROM gam_games" " FROM gam_games"
" LEFT JOIN mch_matches" " LEFT JOIN mch_matches"
" ON gam_games.GamCod=mch_matches.GamCod" " ON gam_games.GamCod=mch_matches.GamCod"
@ -704,14 +705,17 @@ void Gam_GetDataOfGameByCod (struct Game *Game)
/* Get code of the game (row[0]) */ /* Get code of the game (row[0]) */
Game->GamCod = Str_ConvertStrCodToLongCod (row[0]); Game->GamCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get whether the game is hidden (row[1]) */ /* Get code of the course (row[1]) */
Game->Status.Visible = (row[1][0] == 'N'); Game->CrsCod = Str_ConvertStrCodToLongCod (row[1]);
/* Get author of the game (row[2]) */ /* Get whether the game is hidden (row[2]) */
Game->UsrCod = Str_ConvertStrCodToLongCod (row[2]); Game->Status.Visible = (row[2][0] == 'N');
/* Get the title of the game (row[3]) */ /* Get author of the game (row[3]) */
Str_Copy (Game->Title,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); Gam_MAX_BYTES_TITLE);
/* Get number of questions */ /* Get number of questions */
@ -796,7 +800,9 @@ static void Gam_ResetGame (struct Game *Game,long UsrCod)
{ {
/***** Initialize to empty game *****/ /***** Initialize to empty game *****/
Game->GamCod = -1L; 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_START_TIME] = (time_t) 0;
Game->TimeUTC[Dat_END_TIME ] = (time_t) 0; Game->TimeUTC[Dat_END_TIME ] = (time_t) 0;
Game->Title[0] = '\0'; Game->Title[0] = '\0';

View File

@ -40,6 +40,7 @@
struct Game struct Game
{ {
long GamCod; // Game code long GamCod; // Game code
long CrsCod; // Course code
long UsrCod; // Author code long UsrCod; // Author code
char Title[Gam_MAX_BYTES_TITLE + 1]; char Title[Gam_MAX_BYTES_TITLE + 1];
time_t TimeUTC[Dat_NUM_START_END_TIME]; time_t TimeUTC[Dat_NUM_START_END_TIME];

View File

@ -153,6 +153,9 @@ static void Mch_GetMatchDataFromRow (MYSQL_RES *mysql_res,
struct Match *Match); struct Match *Match);
static Mch_Showing_t Mch_GetShowingFromStr (const char *Str); 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_PutParamCurrentMchCod (void);
static void Mch_PutParamMchCod (long MchCod); static void Mch_PutParamMchCod (long MchCod);
static long Mch_GetParamMchCod (void); static long Mch_GetParamMchCod (void);
@ -1006,6 +1009,7 @@ void Mch_RemoveMatchTch (void)
{ {
extern const char *Txt_Match_X_removed; extern const char *Txt_Match_X_removed;
struct Match Match; struct Match Match;
struct Game Game;
/***** Get parameters *****/ /***** Get parameters *****/
/* Get match code */ /* Get match code */
@ -1014,59 +1018,18 @@ void Mch_RemoveMatchTch (void)
/***** Get data of the match from database *****/ /***** Get data of the match from database *****/
Mch_GetDataOfMatchByCod (&Match); Mch_GetDataOfMatchByCod (&Match);
if (Match.MchCod < 0)
/***** 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))
Lay_ShowErrorAndExit ("The match to be removed does not exist."); 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 *****/ /***** Write message *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_Match_X_removed, Ale_ShowAlert (Ale_SUCCESS,Txt_Match_X_removed,
Match.Title); Match.Title);
@ -1078,6 +1041,60 @@ void Mch_RemoveMatchTch (void)
false); // Do not put form to start new match 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 *********************/ /***************** Put parameter with current match code *********************/
/*****************************************************************************/ /*****************************************************************************/