"
"");
}
Tbl_EndTable ();
- if (PutFormAnswerGame)
+ if (ActionToDoWithQuestions == Tst_SHOW_GAME_TO_ANSWER)
{
/***** Button to create/modify game *****/
Btn_PutConfirmButton (Txt_Done);
@@ -3302,25 +3287,85 @@ static void Rmt_WriteQstStem (const char *Stem)
/************** Get and write the answers of a game question ***************/
/*****************************************************************************/
-static void Rmt_WriteAnswersOfAQst (struct Game *Game,struct GameQuestion *GameQst,bool PutFormAnswerGame)
+static void Rmt_WriteAnswersOfAQst (Tst_ActionToDoWithQuestions_t ActionToDoWithQuestions,
+ struct Game *Game,struct GameQuestion *GameQst)
{
+ extern const char *Txt_Question_removed;
+ MYSQL_RES *mysql_res;
+ MYSQL_ROW row;
+ double ScoreThisQst;
+ bool AnswerIsNotBlank;
+
+ /***** Query database *****/
+ if (Tst_GetOneQuestionByCod (GameQst->QstCod,&mysql_res)) // Question exists
+ {
+ /***** Get row of the result of the query *****/
+ row = mysql_fetch_row (mysql_res);
+ /*
+ row[ 0] QstCod
+ row[ 1] UNIX_TIMESTAMP(EditTime)
+ row[ 2] AnsType
+ row[ 3] Shuffle
+ row[ 4] Stem
+ row[ 5] Feedback
+ row[ 6] ImageName
+ row[ 7] ImageTitle
+ row[ 8] ImageURL
+ row[ 9] NumHits
+ row[10] NumHitsNotBlank
+ row[11] Score
+ */
+
+ /***** Write question and answers *****/
+ Gbl.Games.CurrentGamCod = Game->GamCod;
+ Tst_WriteQstAndAnsTest (ActionToDoWithQuestions,
+ GameQst->QstInd,GameQst->QstCod,row,
+ &ScoreThisQst,&AnswerIsNotBlank);
+ }
+ else
+ /***** Question does not exists *****/
+ fprintf (Gbl.F.Out,"
"
+ "
"
+ "%u"
+ "
"
+ "
"
+ "%s"
+ "
"
+ "
",
+ Gbl.RowEvenOdd,GameQst->QstInd + 1,
+ Gbl.RowEvenOdd,Txt_Question_removed);
+
+ /***** Free structure that stores the query result *****/
+ DB_FreeMySQLResult (&mysql_res);
+
+
+
+/*
+
+
+
+
+
+
+
+
unsigned NumAnswers;
unsigned NumAns;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrsThisAnswer;
- /***** Get answers of this question *****/
- NumAnswers = Rmt_GetAnswersQst (GameQst->QstCod,&mysql_res); // Result: AnsInd,NumUsrs,Answer
+ ***** Get answers of this question *****
+ NumAnswers = Rmt_GetNumUsrsWhoAnswered (GameQst->QstCod,&mysql_res); // Result: AnsInd,NumUsrs,Answer
- /***** Write the answers *****/
+ ***** Write the answers *****
if (NumAnswers)
{
- /* Check number of answers */
+ * Check number of answers *
if (NumAnswers > Rmt_MAX_ANSWERS_PER_QUESTION)
Lay_ShowErrorAndExit ("Wrong number of answers.");
- /* Write one row for each answer */
+ * Write one row for each answer *
Tbl_StartTable (5);
for (NumAns = 0;
NumAns < NumAnswers;
@@ -3328,11 +3373,11 @@ static void Rmt_WriteAnswersOfAQst (struct Game *Game,struct GameQuestion *GameQ
{
row = mysql_fetch_row (mysql_res);
- /* Get number of users who have marked this answer (row[1]) */
+ * Get number of users who have marked this answer (row[1]) *
if (sscanf (row[1],"%u",&NumUsrsThisAnswer) != 1)
Lay_ShowErrorAndExit ("Error when getting number of users who have marked an answer.");
- /* Convert the answer (row[2]), that is in HTML, to rigorous HTML */
+ * Convert the answer (row[2]), that is in HTML, to rigorous HTML *
if (!Rmt_AllocateTextChoiceAnswer (GameQst,NumAns))
Lay_ShowErrorAndExit (Gbl.Alert.Txt);
Str_Copy (GameQst->AnsChoice[NumAns].Text,row[2],
@@ -3340,12 +3385,12 @@ static void Rmt_WriteAnswersOfAQst (struct Game *Game,struct GameQuestion *GameQ
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
GameQst->AnsChoice[NumAns].Text,Rmt_MAX_BYTES_ANSWER,false);
- /* Selectors and label with the letter of the answer */
+ * Selectors and label with the letter of the answer *
fprintf (Gbl.F.Out,"
");
if (PutFormAnswerGame)
{
- /* Write selector to choice this answer */
+ * Write selector to choice this answer *
fprintf (Gbl.F.Out,"
"
"AnswerType == Rmt_ANS_UNIQUE_CHOICE)
@@ -3361,7 +3406,7 @@ static void Rmt_WriteAnswersOfAQst (struct Game *Game,struct GameQuestion *GameQ
NumAns);
}
- /* Write the number of option */
+ * Write the number of option *
fprintf (Gbl.F.Out,"
"
"
",
(unsigned) GameQst->QstCod,NumAns,NumAns + 1);
- /* Write the text of the answer */
+ * Write the text of the answer *
fprintf (Gbl.F.Out,"
"
""
"
",
(unsigned) GameQst->QstCod,NumAns,
GameQst->AnsChoice[NumAns].Text);
- /* Show stats of this answer */
+ * Show stats of this answer *
if (Game->Status.ICanViewResults)
Rmt_DrawBarNumUsrs (NumUsrsThisAnswer,Game->NumUsrs);
fprintf (Gbl.F.Out,"
");
- /* Free memory allocated for the answer */
+ * Free memory allocated for the answer *
Rmt_FreeTextChoiceAnswer (GameQst,NumAns);
}
Tbl_EndTable ();
}
- /***** Free structure that stores the query result *****/
+ ***** Free structure that stores the query result *****
DB_FreeMySQLResult (&mysql_res);
+*/
}
/*****************************************************************************/
@@ -3452,8 +3498,8 @@ static void Rmt_PutIconToRemoveOneQst (void)
static void Rmt_PutParamsRemoveOneQst (void)
{
- Rmt_PutParamGameCod (Gbl.Games.GamCodToEdit);
- Rmt_PutParamQstCod (Gbl.Games.GamQstCodToEdit);
+ Rmt_PutParamGameCod (Gbl.Games.CurrentGamCod);
+ Rmt_PutParamQstCod (Gbl.Games.CurrentQstCod);
}
/*****************************************************************************/
@@ -3480,8 +3526,8 @@ void Rmt_RequestRemoveQst (void)
GameQst.QstInd = Rmt_GetQstIndFromQstCod (GameQst.QstCod);
/***** Show question and button to remove question *****/
- Gbl.Games.GamCodToEdit = Game.GamCod;
- Gbl.Games.GamQstCodToEdit = GameQst.QstCod;
+ Gbl.Games.CurrentGamCod = Game.GamCod;
+ Gbl.Games.CurrentQstCod = GameQst.QstCod;
sprintf (Gbl.Alert.Txt,Txt_Do_you_really_want_to_remove_the_question_X,
(unsigned long) (GameQst.QstInd + 1));
Ale_ShowAlertAndButton (Ale_QUESTION,Gbl.Alert.Txt,
diff --git a/swad_remote_control.h b/swad_remote_control.h
index 3e991f15..3f11b3e1 100644
--- a/swad_remote_control.h
+++ b/swad_remote_control.h
@@ -113,6 +113,8 @@ void Rmt_RemoveGames (Sco_Scope_t Scope,long Cod);
void Rmt_RequestEditQuestion (void);
// void Rmt_ReceiveQst (void);
+unsigned Rmt_GetNumUsrsWhoAnswered (long GamCod,long QstCod,unsigned AnsInd);
+
void Rmt_AddTstQuestionsToGame (void);
void Rmt_RequestRemoveQst (void);
diff --git a/swad_test.c b/swad_test.c
index a2d87181..e1d8ba86 100644
--- a/swad_test.c
+++ b/swad_test.c
@@ -130,13 +130,6 @@ typedef enum
Tst_STATUS_ERROR = 2,
} Tst_Status_t;
-typedef enum
- {
- Tst_SHOW_QUESTIONS,
- Tst_EDIT_QUESTIONS,
- Tst_SELECT_QUESTIONS_FOR_GAME,
- } Tst_ActionToDoWithQuestions_t;
-
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
@@ -161,8 +154,6 @@ static Tst_Status_t Tst_GetTstStatus (unsigned NumTst);
static unsigned Tst_GetNumAccessesTst (void);
static void Tst_ShowTestQuestionsWhenSeeing (MYSQL_RES *mysql_res);
static void Tst_ShowTestResultAfterAssess (long TstCod,unsigned *NumQstsNotBlank,double *TotalScore);
-static void Tst_WriteQstAndAnsTest (unsigned NumQst,long QstCod,MYSQL_ROW row,
- double *ScoreThisQst,bool *AnswerIsNotBlank);
static void Tst_PutFormToEditQstImage (struct Image *Image,int NumImgInForm,
const char *ClassContainer,
const char *ClassImg,
@@ -193,7 +184,6 @@ static void Tst_ShowFormAnswerTypes (unsigned NumCols);
static unsigned long Tst_GetQuestions (MYSQL_RES **mysql_res);
static unsigned long Tst_GetQuestionsForTest (MYSQL_RES **mysql_res);
static void Tst_ListOneQstToEdit (void);
-static bool Tst_GetOneQuestionByCod (long QstCod,MYSQL_RES **mysql_res);
static void Tst_ListOneOrMoreQuestionsForEdition (unsigned long NumRows,
MYSQL_RES *mysql_res);
static void Tst_ListOneOrMoreQuestionsForSelection (long GamCod,
@@ -429,7 +419,7 @@ void Tst_ShowNewTest (void)
if (Tst_CheckIfNextTstAllowed ())
{
/***** Check that all parameters used to generate a test are valid *****/
- if (Tst_GetParamsTst (Tst_SHOW_QUESTIONS)) // Get parameters from form
+ if (Tst_GetParamsTst (Tst_SHOW_TST_TO_ANSWER)) // Get parameters from form
{
/***** Get questions *****/
if ((NumRows = Tst_GetQuestionsForTest (&mysql_res)) == 0) // Query database
@@ -835,7 +825,8 @@ static void Tst_ShowTestQuestionsWhenSeeing (MYSQL_RES *mysql_res)
if ((QstCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of question.");
- Tst_WriteQstAndAnsTest (NumQst,QstCod,row,
+ Tst_WriteQstAndAnsTest (Tst_SHOW_TST_TO_ANSWER,
+ NumQst,QstCod,row,
&ScoreThisQst, // Not used here
&AnswerIsNotBlank); // Not used here
}
@@ -935,7 +926,8 @@ static void Tst_ShowTestResultAfterAssess (long TstCod,unsigned *NumQstsNotBlank
Lay_ShowErrorAndExit ("Wrong code of question.");
/***** Write question and answers *****/
- Tst_WriteQstAndAnsTest (NumQst,QstCod,row,
+ Tst_WriteQstAndAnsTest (Tst_SHOW_TST_RESULT,
+ NumQst,QstCod,row,
&ScoreThisQst,&AnswerIsNotBlank);
/***** Store test result question in database *****/
@@ -974,8 +966,9 @@ static void Tst_ShowTestResultAfterAssess (long TstCod,unsigned *NumQstsNotBlank
/********** Write a row of a test, with one question and its answer **********/
/*****************************************************************************/
-static void Tst_WriteQstAndAnsTest (unsigned NumQst,long QstCod,MYSQL_ROW row,
- double *ScoreThisQst,bool *AnswerIsNotBlank)
+void Tst_WriteQstAndAnsTest (Tst_ActionToDoWithQuestions_t ActionToDoWithQuestions,
+ unsigned NumQst,long QstCod,MYSQL_ROW row,
+ double *ScoreThisQst,bool *AnswerIsNotBlank)
{
extern const char *Txt_TST_STR_ANSWER_TYPES[Tst_NUM_ANS_TYPES];
/*
@@ -1020,15 +1013,30 @@ static void Tst_WriteQstAndAnsTest (unsigned NumQst,long QstCod,MYSQL_ROW row,
"TEST_IMG_SHOW_STEM_CONTAINER",
"TEST_IMG_SHOW_STEM");
- if (Gbl.Action.Act == ActSeeTst)
- Tst_WriteAnswersOfAQstViewTest (NumQst,QstCod,(row[3][0] == 'Y'));
- else // Assessing test / Viewing old test result
+ switch (ActionToDoWithQuestions)
{
- Tst_WriteAnswersOfAQstAssessTest (NumQst,QstCod,ScoreThisQst,AnswerIsNotBlank);
+ case Tst_SHOW_TST_TO_ANSWER:
+ Tst_WriteAnswersOfAQstViewTest (NumQst,QstCod,(row[3][0] == 'Y'));
+ break;
+ case Tst_SHOW_TST_RESULT:
+ Tst_WriteAnswersOfAQstAssessTest (NumQst,QstCod,ScoreThisQst,AnswerIsNotBlank);
- /* Write question feedback (row[5]) */
- if (Gbl.Test.Config.FeedbackType == Tst_FEEDBACK_FULL_FEEDBACK)
- Tst_WriteQstFeedback (row[5],"TEST_EXA_LIGHT");
+ /* Write question feedback (row[5]) */
+ if (Gbl.Test.Config.FeedbackType == Tst_FEEDBACK_FULL_FEEDBACK)
+ Tst_WriteQstFeedback (row[5],"TEST_EXA_LIGHT");
+ break;
+ case Tst_EDIT_TST:
+ break;
+ case Tst_SELECT_QUESTIONS_FOR_GAME:
+ break;
+ case Tst_SHOW_GAME_TO_ANSWER:
+ // TODO: Change this!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ Tst_WriteAnswersOfAQstViewTest (NumQst,QstCod,(row[3][0] == 'Y'));
+ break;
+ case Tst_SHOW_GAME_RESULT:
+ // TODO: Change this!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ Tst_WriteAnswersOfAQstAssessTest (NumQst,QstCod,ScoreThisQst,AnswerIsNotBlank);
+ break;
}
fprintf (Gbl.F.Out,""
"");
@@ -2382,7 +2390,7 @@ void Tst_ListQuestionsToEdit (void)
unsigned long NumRows;
/***** Get parameters, query the database and list the questions *****/
- if (Tst_GetParamsTst (Tst_EDIT_QUESTIONS)) // Get parameters from the form
+ if (Tst_GetParamsTst (Tst_EDIT_TST)) // Get parameters from the form
{
if ((NumRows = Tst_GetQuestions (&mysql_res)) != 0) // Query database
{
@@ -2764,7 +2772,7 @@ static void Tst_ListOneQstToEdit (void)
/*****************************************************************************/
// Return true on success, false on error
-static bool Tst_GetOneQuestionByCod (long QstCod,MYSQL_RES **mysql_res)
+bool Tst_GetOneQuestionByCod (long QstCod,MYSQL_RES **mysql_res)
{
char Query[512];
@@ -4592,8 +4600,8 @@ static bool Tst_GetParamsTst (Tst_ActionToDoWithQuestions_t ActionToDoWithQuesti
/***** Types of answer *****/
switch (ActionToDoWithQuestions)
{
- case Tst_SHOW_QUESTIONS:
- case Tst_EDIT_QUESTIONS:
+ case Tst_SHOW_TST_TO_ANSWER:
+ case Tst_EDIT_TST:
/* Get parameter that indicates if all types of answer are selected */
Gbl.Test.AllAnsTypes = Par_GetParToBool ("AllAnsTypes");
@@ -4612,12 +4620,14 @@ static bool Tst_GetParamsTst (Tst_ActionToDoWithQuestions_t ActionToDoWithQuesti
Gbl.Test.AllAnsTypes = false;
sprintf (Gbl.Test.ListAnsTypes,"%u",(unsigned) Tst_ANS_UNIQUE_CHOICE);
break;
+ default:
+ break;
}
/***** Get other parameters, depending on action *****/
switch (ActionToDoWithQuestions)
{
- case Tst_SHOW_QUESTIONS:
+ case Tst_SHOW_TST_TO_ANSWER:
Tst_GetParamNumQst ();
if (Gbl.Test.NumQsts < Gbl.Test.Config.Min ||
Gbl.Test.NumQsts > Gbl.Test.Config.Max)
@@ -4628,7 +4638,7 @@ static bool Tst_GetParamsTst (Tst_ActionToDoWithQuestions_t ActionToDoWithQuesti
Error = true;
}
break;
- case Tst_EDIT_QUESTIONS:
+ case Tst_EDIT_TST:
/* Get starting and ending dates */
Dat_GetIniEndDatesFromForm ();
@@ -4650,6 +4660,8 @@ static bool Tst_GetParamsTst (Tst_ActionToDoWithQuestions_t ActionToDoWithQuesti
/* Order question by stem */
Gbl.Test.SelectedOrder = Tst_ORDER_STEM;
break;
+ default:
+ break;
}
return !Error;
@@ -6178,7 +6190,7 @@ void Tst_RequestRemoveQst (void)
/* Get other parameters */
if (!EditingOnlyThisQst)
- if (!Tst_GetParamsTst (Tst_EDIT_QUESTIONS))
+ if (!Tst_GetParamsTst (Tst_EDIT_TST))
Lay_ShowErrorAndExit ("Wrong test parameters.");
/***** Show question and button to remove question *****/
@@ -8188,7 +8200,8 @@ static void Tst_ShowTestResult (time_t TstTimeUTC)
Lay_ShowErrorAndExit ("Wrong code of question.");
/***** Write questions and answers *****/
- Tst_WriteQstAndAnsTest (NumQst,QstCod,row,
+ Tst_WriteQstAndAnsTest (Tst_SHOW_TST_RESULT,
+ NumQst,QstCod,row,
&ScoreThisQst, // Not used here
&AnswerIsNotBlank); // Not used here
}
diff --git a/swad_test.h b/swad_test.h
index 5da130d9..812b2e85 100644
--- a/swad_test.h
+++ b/swad_test.h
@@ -67,6 +67,16 @@ typedef enum
Tst_PLUGGABLE_YES = 2,
} Tst_Pluggable_t;
+typedef enum
+ {
+ Tst_SHOW_TST_TO_ANSWER, // Showing a test to a student
+ Tst_SHOW_TST_RESULT, // Showing the assessment of a test
+ Tst_EDIT_TST, // Editing test questions
+ Tst_SELECT_QUESTIONS_FOR_GAME, // Selecting test questions for a game
+ Tst_SHOW_GAME_TO_ANSWER, // Showing a game to a student
+ Tst_SHOW_GAME_RESULT, // Showing the assessment of a game
+ } Tst_ActionToDoWithQuestions_t;
+
#define Tst_NUM_TYPES_FEEDBACK 5
typedef enum
{
@@ -131,6 +141,10 @@ struct Tst_Stats
void Tst_ShowFormAskTst (void);
void Tst_ShowNewTest (void);
void Tst_AssessTest (void);
+
+void Tst_WriteQstAndAnsTest (Tst_ActionToDoWithQuestions_t ActionToDoWithQuestions,
+ unsigned NumQst,long QstCod,MYSQL_ROW row,
+ double *ScoreThisQst,bool *AnswerIsNotBlank);
void Tst_WriteQstStem (const char *Stem,const char *ClassStem);
void Tst_WriteQstFeedback (const char *Feedback,const char *ClassFeedback);
@@ -139,6 +153,7 @@ void Tst_ShowFormAskEditTsts (void);
void Tst_ShowFormAskSelectTstsForGame (long GamCod);
void Tst_ListQuestionsToEdit (void);
void Tst_ListQuestionsToSelect (void);
+bool Tst_GetOneQuestionByCod (long QstCod,MYSQL_RES **mysql_res);
void Tst_WriteParamEditQst (void);
unsigned Tst_GetAnswersQst (long QstCod,MYSQL_RES **mysql_res,bool Shuffle);
void Tst_WriteAnsTF (char AnsTF);