",Gbl.Title);
+ fprintf (Gbl.F.Out,"%s",Gbl.Title);
}
/*****************************************************************************/
@@ -3012,12 +3017,103 @@ static void Gam_PutBigButtonToPlayGameStd (long GamCod)
}
/*****************************************************************************/
-/**************** Show next question when playing a game *********************/
+/********* Show first question when playing a game (by a teacher) ************/
+/*****************************************************************************/
+
+void Gam_GameTchFirstQuestion (void)
+ {
+ long GamCod;
+
+ /***** Get parameters *****/
+ /* Get game code */
+ if ((GamCod = Gam_GetParamGameCod ()) == -1L)
+ Lay_ShowErrorAndExit ("Code of game is missing.");
+
+ /***** Check that the game is not being played *****/
+ if (Gam_CheckIfGameIsBeeingPlayed (GamCod))
+ Ale_ShowAlert (Ale_WARNING,"Este juego ya está jugándose."); // TODO: Need translation!!!!!!
+ else
+ /***** Show questions and possible answers *****/
+ Gam_PlayGameShowQuestionAndAnswers (GamCod,0,
+ false); // Don't show answers
+ }
+
+/*****************************************************************************/
+/******************** Check if I have answered a game ************************/
+/*****************************************************************************/
+
+static bool Gam_CheckIfGameIsBeeingPlayed (long GamCod)
+ {
+ /***** Get if game is being played from database *****/
+ return (DB_QueryCOUNT ("can not check if game is being played",
+ "SELECT COUNT(*) FROM gam_playing"
+ " WHERE GamCod=%ld",
+ GamCod) != 0);
+ }
+
+/*****************************************************************************/
+/********************** Insert/update game being played **********************/
+/*****************************************************************************/
+
+static void Gam_UpdateGameQstBeeingPlayed (long GamCod,unsigned QstInd,long QstCod,bool ShowingAnswers)
+ {
+ if (ShowingAnswers) // Show a question previously shown and its answers
+ DB_QueryUPDATE ("can not update game beeing played",
+ "UPDATE gam_playing"
+ " SET ShowingAnswers='Y'"
+ " WHERE GamCod=%ld AND QstInd=%u AND QstCod=%ld",
+ GamCod,QstInd,QstCod);
+ else // Show a question without answers
+ {
+ if (QstInd == 0) // 1st question beeing shown
+ DB_QueryINSERT ("can not update game beeing played",
+ "INSERT gam_playing"
+ " (GamCod,QstInd,QstCod,ShowingAnswers,GamStart,QstStart)"
+ " VALUES"
+ " (%ld,0,%ld,'N',NOW(),NOW())",
+ GamCod,QstCod);
+ else // 2nd, 3rd... question beeing shown
+ DB_QueryUPDATE ("can not update game beeing played",
+ "UPDATE gam_playing"
+ " SET QstInd=%u,QstCod=%ld,ShowingAnswers='N',QstStart=NOW()"
+ " WHERE GamCod=%ld",
+ QstInd,QstCod,GamCod);
+ }
+ }
+
+/*****************************************************************************/
+/******************** Remove game from games being played ********************/
+/*****************************************************************************/
+
+static void Gam_RemoveGameBeeingPlayed (long GamCod)
+ {
+ /***** Remove game being played from database *****/
+ DB_QueryDELETE ("can not remove game being played",
+ "DELETE FROM gam_playing"
+ " WHERE GamCod=%ld",
+ GamCod);
+ }
+
+/*****************************************************************************/
+/********* Show next question when playing a game (by a teacher) *************/
/*****************************************************************************/
void Gam_GameTchNextQuestion (void)
{
- Gam_PlayGameShowQuestionAndAnswers (false); // Don't show answers
+ long GamCod;
+ unsigned QstInd;
+
+ /***** Get parameters *****/
+ /* Get game code */
+ if ((GamCod = Gam_GetParamGameCod ()) == -1L)
+ Lay_ShowErrorAndExit ("Code of game is missing.");
+
+ /* Get question index */
+ QstInd = Gam_GetParamQstInd ();
+
+ /***** Show questions and possible answers *****/
+ Gam_PlayGameShowQuestionAndAnswers (GamCod,QstInd,
+ false); // Don't show answers
}
/*****************************************************************************/
@@ -3026,31 +3122,38 @@ void Gam_GameTchNextQuestion (void)
void Gam_GameTchShowAnswers (void)
{
- Gam_PlayGameShowQuestionAndAnswers (true); // Show answers
+ long GamCod;
+ unsigned QstInd;
+
+ /***** Get parameters *****/
+ /* Get game code */
+ if ((GamCod = Gam_GetParamGameCod ()) == -1L)
+ Lay_ShowErrorAndExit ("Code of game is missing.");
+
+ /* Get question index */
+ QstInd = Gam_GetParamQstInd ();
+
+ /***** Show questions and possible answers *****/
+ Gam_PlayGameShowQuestionAndAnswers (GamCod,QstInd,
+ true); // Show answers
}
/*****************************************************************************/
/************ Show question and its answers when playing a game **************/
/*****************************************************************************/
-static void Gam_PlayGameShowQuestionAndAnswers (bool ShowAnswers)
+static void Gam_PlayGameShowQuestionAndAnswers (long GamCod,
+ unsigned QstInd,
+ bool ShowAnswers)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
- struct Game Game;
- unsigned QstInd;
int NxtQstInd;
long QstCod;
-
- /***** Get parameters *****/
- /* Get game code */
- if ((Game.GamCod = Gam_GetParamGameCod ()) == -1L)
- Lay_ShowErrorAndExit ("Code of game is missing.");
-
- /* Get question index */
- QstInd = Gam_GetParamQstInd ();
+ struct Game Game;
/***** Get data of question from database *****/
+ Game.GamCod = GamCod;
if (!DB_QuerySELECT (&mysql_res,"can not get data of a question",
"SELECT tst_questions.QstCod," // row[0]
"tst_questions.AnsType," // row[1]
@@ -3074,6 +3177,10 @@ static void Gam_PlayGameShowQuestionAndAnswers (bool ShowAnswers)
fprintf (Gbl.F.Out,"
");
+ /* Get question code (row[0]) */
+ if ((QstCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
+ Lay_ShowErrorAndExit ("Error: wrong question code.");
+
/* Write stem (row[2]) */
Tst_WriteQstStem (row[2],"GAM_PLAY_QST");
@@ -3089,10 +3196,6 @@ static void Gam_PlayGameShowQuestionAndAnswers (bool ShowAnswers)
/* Write answers? */
if (ShowAnswers)
{
- /* Get question code (row[0]) */
- if ((QstCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
- Lay_ShowErrorAndExit ("Error: wrong question code.");
-
/* Get answer type (row[1]) */
Gbl.Test.AnswerType = Tst_ConvertFromStrAnsTypDBToAnsTyp (row[1]);
@@ -3111,9 +3214,12 @@ static void Gam_PlayGameShowQuestionAndAnswers (bool ShowAnswers)
{
/* Get index of the next question */
NxtQstInd = Gam_GetNextQuestionIndexInGame (Game.GamCod,QstInd);
- if (NxtQstInd > 0)
+ if (NxtQstInd >= 0) // Not last question
/* Put button to show next question */
Gam_PutBigButtonToContinue (ActGamTchNxtQst,Game.GamCod,(unsigned) NxtQstInd);
+ else // Last question
+ /* Put button to end */
+ Gam_PutBigButtonToEnd (Game.GamCod);
}
else
/* Put button to show answers */
@@ -3122,6 +3228,9 @@ static void Gam_PlayGameShowQuestionAndAnswers (bool ShowAnswers)
/***** End container for question *****/
fprintf (Gbl.F.Out,"
");
+
+ /***** Insert/update game in table of games currently being played *****/
+ Gam_UpdateGameQstBeeingPlayed (GamCod,QstInd,QstCod,ShowAnswers);
}
/*****************************************************************************/
@@ -3147,8 +3256,9 @@ static void Gam_PutBigButtonToContinue (Act_Action_t NextAction,
" alt=\"%s\" title=\"%s\" class=\"ICO64x64\" />"
" "
"%s",
- Cfg_URL_ICON_PUBLIC,Txt_Continue,Txt_Continue,
- Txt_Continue);
+ Cfg_URL_ICON_PUBLIC,
+ Txt_Continue,Txt_Continue,
+ Txt_Continue);
fprintf (Gbl.F.Out,"");
/***** End form *****/
@@ -3158,6 +3268,63 @@ static void Gam_PutBigButtonToContinue (Act_Action_t NextAction,
fprintf (Gbl.F.Out,"");
}
+
+/*****************************************************************************/
+/************************* Put a big button to end ***************************/
+/*****************************************************************************/
+
+static void Gam_PutBigButtonToEnd (long GamCod)
+ {
+ extern const char *Txt_Finish;
+
+ /***** Start container *****/
+ fprintf (Gbl.F.Out,"
");
+
+ /***** Start form *****/
+ Frm_StartForm (ActGamTchEnd);
+ Gam_PutParamGameCod (GamCod);
+
+ /***** Put icon with link *****/
+ Frm_LinkFormSubmit (Txt_Finish,"GAM_PLAY_CONTINUE ICO_HIGHLIGHT",NULL);
+ fprintf (Gbl.F.Out,""
+ " "
+ "%s",
+ Cfg_URL_ICON_PUBLIC,
+ Txt_Finish,Txt_Finish,
+ Txt_Finish);
+ fprintf (Gbl.F.Out,"");
+
+ /***** End form *****/
+ Frm_EndForm ();
+
+ /***** End container *****/
+ fprintf (Gbl.F.Out,"
");
+ }
+
+/*****************************************************************************/
+/******************** End playing a game (by a teacher) **********************/
+/*****************************************************************************/
+
+void Gam_GameTchEnd (void)
+ {
+ long GamCod;
+
+ /***** Get parameters *****/
+ /* Get game code */
+ if ((GamCod = Gam_GetParamGameCod ()) == -1L)
+ Lay_ShowErrorAndExit ("Code of game is missing.");
+
+ /***** Remove game being played *****/
+ Gam_RemoveGameBeeingPlayed (GamCod);
+
+ /***** Show alert *****/
+ Ale_ShowAlert (Ale_INFO,"Juego finalizado."); // TODO: Need translation!!!!!
+
+ /***** Button to close *****/
+ Btn_PutCloseButton ("Cerrar"); // TODO: Need translation!!!!!
+ }
+
/*****************************************************************************/
/***** Show current question to a student when he/she is playing a game ******/
/*****************************************************************************/
diff --git a/swad_game.h b/swad_game.h
index 200d4c7ad..7ad318252 100644
--- a/swad_game.h
+++ b/swad_game.h
@@ -122,8 +122,10 @@ void Gam_StartGameTch (void);
void Gam_PlayGameStd (void);
void Gam_ReceiveGameAnswers (void);
+void Gam_GameTchFirstQuestion (void);
void Gam_GameTchNextQuestion (void);
void Gam_GameTchShowAnswers (void);
+void Gam_GameTchEnd (void);
void Gam_GameStdCurrentQuestion (void);
diff --git a/swad_layout.c b/swad_layout.c
index dd97c267f..08ec8eb33 100644
--- a/swad_layout.c
+++ b/swad_layout.c
@@ -686,7 +686,6 @@ static void Lay_WriteScriptInit (void)
if ((Gbl.Prefs.SideCols & Lay_SHOW_RIGHT_COLUMN)) // Right column visible
Con_WriteScriptClockConnected ();
- // Put the focus on login form
fprintf (Gbl.F.Out," ActionAJAX = \"%s\";\n"
" setTimeout(\"refreshConnected()\",%lu);\n",
Lan_STR_LANG_ID[Gbl.Prefs.Language],
diff --git a/swad_test.c b/swad_test.c
index 290842df3..c1022fdc9 100644
--- a/swad_test.c
+++ b/swad_test.c
@@ -4122,16 +4122,17 @@ static void Tst_WriteChoiceAnsViewGame (struct Game *Game,
"");
/***** Show result (number of users who answered? *****/
- fprintf (Gbl.F.Out,"
"
- "
");
if (ShowResult)
+ {
+ fprintf (Gbl.F.Out,"
"
+ "
"
+ "
");
/* Get number of users who selected this answer
and draw proportional bar */
Gam_GetAndDrawBarNumUsrsWhoAnswered (Game,QstCod,AnsInd);
- else
- fprintf (Gbl.F.Out," ");
- fprintf (Gbl.F.Out,"
"
- "
");
+ fprintf (Gbl.F.Out,""
+ "");
+ }
}
/***** End table *****/
diff --git a/swad_text.c b/swad_text.c
index e74d2e660..9f83ce77a 100644
--- a/swad_text.c
+++ b/swad_text.c
@@ -12205,6 +12205,27 @@ const char *Txt_Filter = // As a noun
"Filtro";
#endif
+const char *Txt_Finish =
+#if L==1 // ca
+ "Acabar";
+#elif L==2 // de
+ "Fertig";
+#elif L==3 // en
+ "Finish";
+#elif L==4 // es
+ "Terminar";
+#elif L==5 // fr
+ "Terminer";
+#elif L==6 // gn
+ "Momba";
+#elif L==7 // it
+ "Finire";
+#elif L==8 // pl
+ "Koniec";
+#elif L==9 // pt
+ "Terminar";
+#endif
+
const char *Txt_First_day_of_the_week =
#if L==1 // ca
"Primer dia de la setmana";