Version19.21

This commit is contained in:
Antonio Cañas Vargas 2019-09-29 22:38:32 +02:00
parent c91a0758e1
commit 49d0c44847
6 changed files with 128 additions and 70 deletions

View File

@ -471,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.20 (2019-09-29)"
#define Log_PLATFORM_VERSION "SWAD 19.21 (2019-09-29)"
#define CSS_FILE "swad19.15.css"
#define JS_FILE "swad19.15.js"
/*
Version 19.21: Sep 29, 2019 Code refactoring in games and matches. (246674 lines)
Version 19.20: Sep 29, 2019 Code refactoring in games and matches. (246631 lines)
14 changes necessary in database:
UPDATE actions SET Txt='Solicitar eliminación partida' WHERE ActCod='1783' AND Language='es';

View File

@ -100,7 +100,6 @@ static void Gam_WriteAuthor (struct Game *Game);
static void Gam_PutFormsToRemEditOneGame (const struct Game *Game,
const char *Anchor);
static long Gam_GetParams (void);
static void Gam_PutHiddenParamOrder (void);
static void Gam_GetParamOrder (void);
@ -135,6 +134,8 @@ static void Gam_ExchangeQuestions (long GamCod,
static bool Gam_GetNumMchsGameAndCheckIfEditable (struct Game *Game);
static long Gam_GetParamCurrentGamCod (void);
/*****************************************************************************/
/***************************** List all games ********************************/
/*****************************************************************************/
@ -389,7 +390,6 @@ void Gam_ShowOneGame (long GamCod,
/***** Get data of this game *****/
Game.GamCod = GamCod;
Gam_GetDataOfGameByCod (&Game);
Gam_CurrentGamCod = Game.GamCod; // Used as parameter in contextual links
/***** Set anchor string *****/
Frm_SetAnchorStr (Game.GamCod,&Anchor);
@ -446,7 +446,7 @@ void Gam_ShowOneGame (long GamCod,
fprintf (Gbl.F.Out,"\">");
/* Game title */
Gam_CurrentGamCod = GamCod;
Gam_SetParamCurrentGamCod (GamCod); // Used to pass parameter
Lay_StartArticle (Anchor);
Frm_StartForm (ActSeeGam);
Gam_PutParams ();
@ -473,7 +473,7 @@ void Gam_ShowOneGame (long GamCod,
fprintf (Gbl.F.Out," COLOR%u",Gbl.RowEvenOdd);
fprintf (Gbl.F.Out,"\">");
Gam_CurrentGamCod = GamCod;
Gam_SetParamCurrentGamCod (GamCod); // Used to pass parameter
Frm_StartForm (ActSeeGam);
Gam_PutParams ();
Frm_LinkFormSubmit (Txt_Matches,
@ -566,6 +566,8 @@ void Gam_PutHiddenParamGameOrder (void)
static void Gam_PutFormsToRemEditOneGame (const struct Game *Game,
const char *Anchor)
{
Gam_SetParamCurrentGamCod (Game->GamCod); // Used to pass parameter
/***** Put icon to remove game *****/
Ico_PutContextualIconToRemove (ActReqRemGam,Gam_PutParams);
@ -586,8 +588,11 @@ static void Gam_PutFormsToRemEditOneGame (const struct Game *Game,
void Gam_PutParams (void)
{
if (Gam_CurrentGamCod > 0)
Gam_PutParamGameCod (Gam_CurrentGamCod);
long CurrentGamCod = Gam_GetParamCurrentGamCod ();
if (CurrentGamCod > 0)
Gam_PutParamGameCod (CurrentGamCod);
Gam_PutHiddenParamOrder ();
Grp_PutParamWhichGrps ();
Pag_PutHiddenParamPagNum (Pag_GAMES,Gbl.Games.CurrentPage);
@ -597,7 +602,7 @@ void Gam_PutParams (void)
/******************* Get parameters used to edit a game **********************/
/*****************************************************************************/
static long Gam_GetParams (void)
long Gam_GetParams (void)
{
/***** Get other parameters *****/
Gam_GetParamOrder ();
@ -913,7 +918,7 @@ void Gam_AskRemGame (void)
Lay_ShowErrorAndExit ("You can not remove this game.");
/***** Show question and button to remove game *****/
Gam_CurrentGamCod = Game.GamCod;
Gam_SetParamCurrentGamCod (Game.GamCod); // Used to pass parameter
Ale_ShowAlertAndButton (ActRemGam,NULL,NULL,Gam_PutParams,
Btn_REMOVE_BUTTON,Txt_Remove_game,
Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_game_X,
@ -1111,7 +1116,7 @@ void Gam_RequestCreatOrEditGame (void)
}
/***** Start form *****/
Gam_CurrentGamCod = Game.GamCod;
Gam_SetParamCurrentGamCod (Game.GamCod); // Used to pass parameter
Frm_StartForm (ItsANewGame ? ActNewGam :
ActChgGam);
Gam_PutParams ();
@ -1337,7 +1342,7 @@ void Gam_RequestNewQuestion (void)
if (Gam_GetNumMchsGameAndCheckIfEditable (&Game))
{
/***** Show form to create a new question in this game *****/
Gam_CurrentGamCod = Game.GamCod;
Gam_SetParamCurrentGamCod (Game.GamCod); // Used to pass parameter
Tst_ShowFormAskSelectTstsForGame ();
}
@ -1364,7 +1369,7 @@ void Gam_ListTstQuestionsToSelect (void)
if (Gam_GetNumMchsGameAndCheckIfEditable (&Game))
{
/***** List several test questions for selection *****/
Gam_CurrentGamCod = Game.GamCod;
Gam_SetParamCurrentGamCod (Game.GamCod); // Used to pass parameter
Tst_ListQuestionsToSelect ();
}
}
@ -1573,7 +1578,7 @@ static void Gam_ListGameQuestions (struct Game *Game)
Game->GamCod);
/***** Start box *****/
Gam_CurrentGamCod = Game->GamCod;
Gam_SetParamCurrentGamCod (Game->GamCod); // Used to pass parameter
Box_StartBox (NULL,Txt_Questions,ICanEditGames ? Gam_PutIconToAddNewQuestions :
NULL,
Hlp_ASSESSMENT_Games_questions,Box_NOT_CLOSABLE);
@ -1674,13 +1679,12 @@ static void Gam_ListOneOrMoreQuestionsForEdition (long GamCod,unsigned NumQsts,
QstCod = Str_ConvertStrCodToLongCod (row[1]);
/***** Icons *****/
Gam_CurrentGamCod = GamCod;
Gam_SetParamCurrentGamCod (GamCod); // Used to pass parameter
Gam_CurrentQstInd = QstInd;
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"BT%u\">",Gbl.RowEvenOdd);
/* Put icon to remove the question */
Gam_CurrentGamCod = GamCod;
Frm_StartForm (ActReqRemGamQst);
Gam_PutParams ();
Gam_PutParamQstInd (QstInd);
@ -1951,7 +1955,7 @@ void Gam_RequestRemoveQst (void)
QstInd = Gam_GetParamQstInd ();
/***** Show question and button to remove question *****/
Gam_CurrentGamCod = Game.GamCod;
Gam_SetParamCurrentGamCod (Game.GamCod); // Used to pass parameter
Gam_CurrentQstInd = QstInd;
Ale_ShowAlertAndButton (ActRemGamQst,NULL,NULL,Gam_PutParamsOneQst,
Btn_REMOVE_BUTTON,Txt_Remove_question,
@ -2206,7 +2210,7 @@ void Gam_PutButtonNewMatch (long GamCod)
{
extern const char *Txt_New_match;
Gam_CurrentGamCod = GamCod;
Gam_SetParamCurrentGamCod (GamCod); // Used to pass parameter
Frm_StartFormAnchor (ActReqNewMch,Mch_NEW_MATCH_SECTION_ID);
Gam_PutParams ();
Btn_PutConfirmButton (Txt_New_match);
@ -2516,3 +2520,17 @@ void Gam_ShowTstTagsPresentInAGame (long GamCod)
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/**************** Access to variable used to pass parameter ******************/
/*****************************************************************************/
void Gam_SetParamCurrentGamCod (long GamCod)
{
Gam_CurrentGamCod = GamCod;
}
static long Gam_GetParamCurrentGamCod (void)
{
return Gam_CurrentGamCod;
}

View File

@ -80,6 +80,7 @@ void Gam_PutHiddenParamGameOrder (void);
void Gam_RequestCreatOrEditGame (void);
void Gam_PutParams (void);
long Gam_GetParams (void);
void Gam_GetListGames (void);
void Gam_GetDataOfGameByCod (struct Game *Gam);
@ -127,4 +128,6 @@ float Gam_GetNumQstsPerCrsGame (Hie_Level_t Scope);
void Gam_ShowTstTagsPresentInAGame (long GamCod);
void Gam_SetParamCurrentGamCod (long GamCod);
#endif

View File

@ -137,7 +137,8 @@ static void Mch_RemoveMatchFromTable (long MchCod,const char *TableName);
static void Mch_RemoveMatchesInGameFromTable (long GamCod,const char *TableName);
static void Mch_RemoveMatchInCourseFromTable (long CrsCod,const char *TableName);
static void Mch_PutParams (void);
static void Mch_PutParamsEdit (void);
static void Mch_PutParamsPlay (void);
static void Mch_PutFormNewMatch (struct Game *Game);
static void Mch_ShowLstGrpsToCreateMatch (void);
@ -205,6 +206,9 @@ static unsigned Mch_GetNumUsrsWhoHaveChosenAns (long MchCod,unsigned QstInd,unsi
static unsigned Mch_GetNumUsrsWhoHaveAnswerMch (long MchCod);
static void Mch_DrawBarNumUsrs (unsigned NumAnswerersAns,unsigned NumAnswerersQst,bool Correct);
static void Mch_SetParamCurrentMchCod (long MchCod);
static long Mch_GetParamCurrentMchCod (void);
/*****************************************************************************/
/************************* List the matches of a game ************************/
/*****************************************************************************/
@ -213,7 +217,6 @@ void Mch_ListMatches (struct Game *Game,bool PutFormNewMatch)
{
extern const char *Hlp_ASSESSMENT_Games_matches;
extern const char *Txt_Matches;
extern long Gam_CurrentGamCod; // Used as parameter in contextual links;
char *SubQuery;
MYSQL_RES *mysql_res;
unsigned NumMatches;
@ -261,7 +264,7 @@ void Mch_ListMatches (struct Game *Game,bool PutFormNewMatch)
free ((void *) SubQuery);
/***** Start box *****/
Gam_CurrentGamCod = Game->GamCod;
Gam_SetParamCurrentGamCod (Game->GamCod); // Used to pass parameter
Box_StartBox (NULL,Txt_Matches,Mch_PutIconToPlayNewMatch,
Hlp_ASSESSMENT_Games_matches,Box_NOT_CLOSABLE);
@ -514,9 +517,10 @@ static void Mch_ListOneOrMoreMatchesIcons (const struct Match *Match)
fprintf (Gbl.F.Out,"<td class=\"BT%u\">",Gbl.RowEvenOdd);
/***** Put icon to remove the match *****/
Mch_CurrentMchCod = Match->MchCod;
Gam_SetParamCurrentGamCod (Match->GamCod); // Used to pass parameter
Mch_SetParamCurrentMchCod (Match->MchCod); // Used to pass parameter
Frm_StartForm (ActReqRemMch);
Mch_PutParams ();
Mch_PutParamsEdit ();
Ico_PutIconRemove ();
Frm_EndForm ();
@ -684,9 +688,9 @@ static void Mch_ListOneOrMoreMatchesStatus (const struct Match *Match,unsigned N
if (ICanPlayThisMatchBasedOnGrps)
{
/* Icon to play as student */
Mch_CurrentMchCod = Match->MchCod;
Mch_SetParamCurrentMchCod (Match->MchCod); // Used to pass parameter
Lay_PutContextualLinkOnlyIcon (ActJoiMch,NULL,
Mch_PutParams,
Mch_PutParamsPlay,
Match->Status.QstInd < Mch_AFTER_LAST_QUESTION ? "play.svg" :
"flag-checkered.svg",
Txt_Play);
@ -696,9 +700,9 @@ static void Mch_ListOneOrMoreMatchesStatus (const struct Match *Match,unsigned N
case Rol_TCH:
case Rol_SYS_ADM:
/* Icon to resume */
Mch_CurrentMchCod = Match->MchCod;
Mch_SetParamCurrentMchCod (Match->MchCod); // Used to pass parameter
Lay_PutContextualLinkOnlyIcon (ActResMch,NULL,
Mch_PutParams,
Mch_PutParamsPlay,
Match->Status.QstInd < Mch_AFTER_LAST_QUESTION ? "play.svg" :
"flag-checkered.svg",
Txt_Resume);
@ -731,8 +735,10 @@ static void Mch_ListOneOrMoreMatchesResult (const struct Match *Match,
/* Match result visible or hidden? */
if (Match->Status.ShowUsrResults)
{
Gam_SetParamCurrentGamCod (Match->GamCod); // Used to pass parameter
Mch_SetParamCurrentMchCod (Match->MchCod); // Used to pass parameter
Frm_StartForm (ActSeeOneMchResMe);
Mch_PutParamMchCod (Match->MchCod);
Mch_PutParamsEdit ();
Ico_PutIconLink ("tasks.svg",Txt_Match_result);
Frm_EndForm ();
}
@ -744,9 +750,10 @@ static void Mch_ListOneOrMoreMatchesResult (const struct Match *Match,
case Rol_TCH:
case Rol_SYS_ADM:
/* Match result visible or hidden? */
Mch_CurrentMchCod = Match->MchCod;
Gam_SetParamCurrentGamCod (Match->GamCod); // Used to pass parameter
Mch_SetParamCurrentMchCod (Match->MchCod); // Used to pass parameter
Lay_PutContextualLinkOnlyIcon (ActChgVisResMchUsr,NULL,
Mch_PutParams,
Mch_PutParamsEdit,
Match->Status.ShowUsrResults ? "eye.svg" :
"eye-slash.svg",
Match->Status.ShowUsrResults ? Txt_Visible_result :
@ -765,14 +772,11 @@ static void Mch_ListOneOrMoreMatchesResult (const struct Match *Match,
void Mch_ToggleVisibilResultsMchUsr (void)
{
struct Game Game;
struct Match Match;
/***** Get game code *****/
if ((Match.MchCod = Mch_GetParamMchCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of match is missing.");
/***** Get data of the match and the game from database *****/
Mch_GetDataOfMatchByCod (&Match);
/***** Get and check parameters *****/
Mch_GetAndCheckParameters (&Game,&Match);
/***** Toggle visibility of match results *****/
Match.Status.ShowUsrResults = !Match.Status.ShowUsrResults;
@ -891,19 +895,16 @@ void Mch_RequestRemoveMatch (void)
{
extern const char *Txt_Do_you_really_want_to_remove_the_match_X;
extern const char *Txt_Remove_match;
struct Game Game;
struct Match Match;
/***** Get parameters *****/
/* Get match code */
if ((Match.MchCod = Mch_GetParamMchCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of match is missing.");
/***** Get data of the match from database *****/
Mch_GetDataOfMatchByCod (&Match);
/***** Get and check parameters *****/
Mch_GetAndCheckParameters (&Game,&Match);
/***** Show question and button to remove question *****/
Mch_CurrentMchCod = Match.MchCod;
Ale_ShowAlertAndButton (ActRemMch,NULL,NULL,Mch_PutParams,
Gam_SetParamCurrentGamCod (Match.GamCod); // Used to pass parameter
Mch_SetParamCurrentMchCod (Match.MchCod); // Used to pass parameter
Ale_ShowAlertAndButton (ActRemMch,NULL,NULL,Mch_PutParamsEdit,
Btn_REMOVE_BUTTON,Txt_Remove_match,
Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_match_X,
Match.Title);
@ -922,24 +923,11 @@ void Mch_RequestRemoveMatch (void)
void Mch_RemoveMatch (void)
{
extern const char *Txt_Match_X_removed;
struct Match Match;
struct Game Game;
struct Match Match;
/***** Get parameters *****/
/* Get match code */
if ((Match.MchCod = Mch_GetParamMchCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of match is missing.");
/***** Get data of the match from database *****/
Mch_GetDataOfMatchByCod (&Match);
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.");
/***** Get and check parameters *****/
Mch_GetAndCheckParameters (&Game,&Match);
/***** Remove the match from all database tables *****/
Mch_RemoveMatchFromAllTables (Match.MchCod);
@ -1072,11 +1060,22 @@ static void Mch_RemoveMatchInCourseFromTable (long CrsCod,const char *TableName)
/*********************** Params used to edit a match *************************/
/*****************************************************************************/
static void Mch_PutParams (void)
static void Mch_PutParamsEdit (void)
{
if (Mch_CurrentMchCod > 0)
Mch_PutParamMchCod (Mch_CurrentMchCod);
Grp_PutParamWhichGrps ();
Gam_PutParams ();
Mch_PutParamsPlay ();
}
/*****************************************************************************/
/*********************** Params used to edit a match *************************/
/*****************************************************************************/
static void Mch_PutParamsPlay (void)
{
long CurrentMchCod = Mch_GetParamCurrentMchCod ();
if (CurrentMchCod > 0)
Mch_PutParamMchCod (CurrentMchCod);
}
/*****************************************************************************/
@ -1088,6 +1087,30 @@ void Mch_PutParamMchCod (long MchCod)
Par_PutHiddenParamLong ("MchCod",MchCod);
}
/*****************************************************************************/
/************************** Get and check parameters *************************/
/*****************************************************************************/
void Mch_GetAndCheckParameters (struct Game *Game,struct Match *Match)
{
/***** Get parameters *****/
/* Get parameters of game */
if ((Game->GamCod = Gam_GetParams ()) == -1L)
Lay_ShowErrorAndExit ("Code of game is missing.");
Gam_GetDataOfGameByCod (Game);
/* Get match code */
if ((Match->MchCod = Mch_GetParamMchCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of match is missing.");
Mch_GetDataOfMatchByCod (Match);
/***** Ensure parameters are correct *****/
if (Game->GamCod != Match->GamCod)
Lay_ShowErrorAndExit ("Wrong game code.");
if (Game->CrsCod != Gbl.Hierarchy.Crs.CrsCod)
Lay_ShowErrorAndExit ("Match does not belong to this course.");
}
/*****************************************************************************/
/********************* Get parameter with code of match **********************/
/*****************************************************************************/
@ -3016,3 +3039,18 @@ static void Mch_DrawBarNumUsrs (unsigned NumAnswerersAns,unsigned NumAnswerersQs
/***** End container *****/
fprintf (Gbl.F.Out,"</div>");
}
/*****************************************************************************/
/**************** Access to variable used to pass parameter ******************/
/*****************************************************************************/
static void Mch_SetParamCurrentMchCod (long MchCod)
{
Mch_CurrentMchCod = MchCod;
}
static long Mch_GetParamCurrentMchCod (void)
{
return Mch_CurrentMchCod;
}

View File

@ -89,6 +89,7 @@ void Mch_RemoveMatchesInGameFromAllTables (long GamCod);
void Mch_RemoveMatchInCourseFromAllTables (long CrsCod);
void Mch_PutParamMchCod (long MchCod);
void Mch_GetAndCheckParameters (struct Game *Game,struct Match *Match);
long Mch_GetParamMchCod (void);
void Mch_CreateNewMatchTch (void);

View File

@ -653,6 +653,7 @@ void Mch_ShowOneMchResult (void)
extern const char *Txt_Score;
extern const char *Txt_out_of_PART_OF_A_SCORE;
extern const char *Txt_Tags;
struct Game Game;
struct Match Match;
Usr_MeOrOther_t MeOrOther;
struct UsrData *UsrDat;
@ -668,12 +669,8 @@ void Mch_ShowOneMchResult (void)
bool ICanViewResult;
bool ICanViewScore;
/***** Get match code *****/
if ((Match.MchCod = Mch_GetParamMchCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of match is missing.");
/***** Get data of the match from database *****/
Mch_GetDataOfMatchByCod (&Match);
/***** Get and check parameters *****/
Mch_GetAndCheckParameters (&Game,&Match);
/***** Pointer to user's data *****/
MeOrOther = (Gbl.Action.Act == ActSeeOneMchResMe) ? Usr_ME :