diff --git a/swad_changelog.h b/swad_changelog.h index 2f2f069fb..310dd7e16 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -497,7 +497,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.152 (2020-03-23)" +#define Log_PLATFORM_VERSION "SWAD 19.152.1 (2020-03-23)" #define CSS_FILE "swad19.146.css" #define JS_FILE "swad19.91.1.js" /* @@ -524,6 +524,7 @@ Param // TODO: Oresti Baños: cambiar ojos por candados en descriptores para prohibir/permitir y dejar los ojos para poder elegir descriptores // TODO: Si el alumno ha marcado "Permitir que los profesores...", entonces pedir confirmación al pulsar el botón azul, para evitar que se envíe por error antes de tiempo + Version 19.152.1: Mar 23, 2020 Code refactoring in tests. (283499 lines) Version 19.152: Mar 23, 2020 Code refactoring in tests. (283525 lines) Version 19.151.4: Mar 22, 2020 Code refactoring in tests. (283471 lines) Version 19.151.3: Mar 22, 2020 Code refactoring in tests. (283433 lines) diff --git a/swad_global.h b/swad_global.h index 1c09970cc..ba9ac84dd 100644 --- a/swad_global.h +++ b/swad_global.h @@ -649,14 +649,6 @@ struct Globals bool PutIconPrint; } ContextualIcons; } TimeTable; - /* - struct - { - long QstCodes[TstCfg_MAX_QUESTIONS_PER_TEST]; // Codes of the sent/received questions in a test - char StrIndexesOneQst[TstCfg_MAX_QUESTIONS_PER_TEST][Tst_MAX_BYTES_INDEXES_ONE_QST + 1]; // 0 1 2 3, 3 0 2 1, etc. - char StrAnswersOneQst[TstCfg_MAX_QUESTIONS_PER_TEST][Tst_MAX_BYTES_ANSWERS_ONE_QST + 1]; // Answers selected by user - } Test; - */ struct { struct DateTime DateIni; // TODO: Remove in future versions diff --git a/swad_match.c b/swad_match.c index 746659633..4c1e4dd26 100644 --- a/swad_match.c +++ b/swad_match.c @@ -222,7 +222,7 @@ static void Mch_GetNumPlayers (struct Match *Match); static void Mch_RemoveMyAnswerToMatchQuestion (const struct Match *Match); -static double Mch_ComputeScore (unsigned NumQsts,const struct Tst_UsrAnswers *UsrAnswers); +static double Mch_ComputeScore (const struct Tst_UsrAnswers *UsrAnswers); static unsigned Mch_GetNumUsrsWhoHaveAnswerMch (long MchCod); @@ -3672,8 +3672,6 @@ void Mch_ReceiveQuestionAnswer (void) unsigned Indexes[Tst_MAX_OPTIONS_PER_QUESTION]; struct Mch_UsrAnswer PreviousUsrAnswer; struct Mch_UsrAnswer UsrAnswer; - unsigned NumQsts; - unsigned NumQstsNotBlank; struct Tst_UsrAnswers UsrAnswers; double TotalScore; @@ -3731,9 +3729,8 @@ void Mch_ReceiveQuestionAnswer (void) /***** Update student's match result *****/ McR_GetMatchResultQuestionsFromDB (Match.MchCod,Gbl.Usrs.Me.UsrDat.UsrCod, - &NumQsts,&NumQstsNotBlank, &UsrAnswers); - TotalScore = Mch_ComputeScore (NumQsts,&UsrAnswers); + TotalScore = Mch_ComputeScore (&UsrAnswers); Str_SetDecimalPointToUS (); // To print the floating point as a dot if (DB_QueryCOUNT ("can not get if match result exists", @@ -3748,7 +3745,9 @@ void Mch_ReceiveQuestionAnswer (void) "NumQstsNotBlank=%u," "Score='%.15lg'" " WHERE MchCod=%ld AND UsrCod=%ld", - NumQsts,NumQstsNotBlank,TotalScore, + UsrAnswers.NumQsts, + UsrAnswers.NumQstsNotBlank, + TotalScore, Match.MchCod,Gbl.Usrs.Me.UsrDat.UsrCod); else // Result doesn't exist /* Create result */ @@ -3764,7 +3763,9 @@ void Mch_ReceiveQuestionAnswer (void) "%u," // NumQstsNotBlank "'%.15lg')", // Score Match.MchCod,Gbl.Usrs.Me.UsrDat.UsrCod, - NumQsts,NumQstsNotBlank,TotalScore); + UsrAnswers.NumQsts, + UsrAnswers.NumQstsNotBlank, + TotalScore); Str_SetDecimalPointToLocal (); // Return to local system } @@ -3790,7 +3791,7 @@ static void Mch_RemoveMyAnswerToMatchQuestion (const struct Match *Match) /******************** Compute match score for a student **********************/ /*****************************************************************************/ -static double Mch_ComputeScore (unsigned NumQsts,const struct Tst_UsrAnswers *UsrAnswers) +static double Mch_ComputeScore (const struct Tst_UsrAnswers *UsrAnswers) { unsigned NumQst; struct Tst_Question Question; @@ -3805,7 +3806,7 @@ static double Mch_ComputeScore (unsigned NumQsts,const struct Tst_UsrAnswers *Us Question.Answer.Type = Tst_ANS_UNIQUE_CHOICE; for (NumQst = 0; - NumQst < NumQsts; + NumQst < UsrAnswers->NumQsts; NumQst++) { /***** Get indexes for this question from string *****/ diff --git a/swad_match_result.c b/swad_match_result.c index 0561cd963..d214ede7a 100644 --- a/swad_match_result.c +++ b/swad_match_result.c @@ -96,8 +96,7 @@ static void McR_ShowMchResultsSummaryRow (unsigned NumResults, double TotalGrade); static void McR_GetMatchResultDataByMchCod (long MchCod,long UsrCod, time_t TimeUTC[Dat_NUM_START_END_TIME], - unsigned *NumQsts, - unsigned *NumQstsNotBlank, + struct Tst_UsrAnswers *UsrAnswers, double *Score); static bool McR_CheckIfICanSeeMatchResult (struct Match *Match,long UsrCod); @@ -1005,8 +1004,6 @@ void McR_ShowOneMchResult (void) time_t TimeUTC[Dat_NUM_START_END_TIME]; // Match result UTC date-time Dat_StartEndTime_t StartEndTime; char *Id; - unsigned NumQsts; - unsigned NumQstsNotBlank; struct Tst_UsrAnswers UsrAnswers; double TotalScore; bool ShowPhoto; @@ -1035,8 +1032,7 @@ void McR_ShowOneMchResult (void) /***** Get match result data *****/ McR_GetMatchResultDataByMchCod (Match.MchCod,UsrDat->UsrCod, TimeUTC, - &NumQsts, - &NumQstsNotBlank, + &UsrAnswers, &TotalScore); /***** Check if I can view this match result *****/ @@ -1068,7 +1064,6 @@ void McR_ShowOneMchResult (void) { /***** Get questions and user's answers of the match result from database *****/ McR_GetMatchResultQuestionsFromDB (Match.MchCod,UsrDat->UsrCod, - &NumQsts,&NumQstsNotBlank, &UsrAnswers); /***** Begin box *****/ @@ -1143,7 +1138,9 @@ void McR_ShowOneMchResult (void) HTM_TD_End (); HTM_TD_Begin ("class=\"DAT LT\""); - HTM_TxtF ("%u (%u %s)",NumQsts,NumQstsNotBlank,Txt_non_blank_QUESTIONS); + HTM_TxtF ("%u (%u %s)", + UsrAnswers.NumQsts, + UsrAnswers.NumQstsNotBlank,Txt_non_blank_QUESTIONS); HTM_TD_End (); HTM_TR_End (); @@ -1173,7 +1170,7 @@ void McR_ShowOneMchResult (void) HTM_TD_Begin ("class=\"DAT LT\""); if (ICanViewScore) - Tst_ComputeAndShowGrade (NumQsts,TotalScore,Game.MaxGrade); + Tst_ComputeAndShowGrade (UsrAnswers.NumQsts,TotalScore,Game.MaxGrade); else Ico_PutIconNotVisible (); HTM_TD_End (); @@ -1194,7 +1191,7 @@ void McR_ShowOneMchResult (void) HTM_TR_End (); /***** Write answers and solutions *****/ - TsR_ShowTestResult (UsrDat,NumQsts,&UsrAnswers,TimeUTC[Dat_START_TIME], + TsR_ShowTestResult (UsrDat,&UsrAnswers,TimeUTC[Dat_START_TIME], Game.Visibility); /***** End table *****/ @@ -1208,7 +1205,7 @@ void McR_ShowOneMchResult (void) HTM_Double2Decimals (TotalScore); HTM_BR (); HTM_TxtColonNBSP (Txt_Grade); - Tst_ComputeAndShowGrade (NumQsts,TotalScore,Game.MaxGrade); + Tst_ComputeAndShowGrade (UsrAnswers.NumQsts,TotalScore,Game.MaxGrade); HTM_DIV_End (); } @@ -1224,7 +1221,6 @@ void McR_ShowOneMchResult (void) /*****************************************************************************/ void McR_GetMatchResultQuestionsFromDB (long MchCod,long UsrCod, - unsigned *NumQsts,unsigned *NumQstsNotBlank, struct Tst_UsrAnswers *UsrAnswers) { MYSQL_RES *mysql_res; @@ -1235,21 +1231,21 @@ void McR_GetMatchResultQuestionsFromDB (long MchCod,long UsrCod, struct Mch_UsrAnswer UsrAnswer; /***** Get questions and answers of a match result *****/ - *NumQsts = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get questions and answers" - " of a match result", - "SELECT gam_questions.QstCod," // row[0] - "gam_questions.QstInd," // row[1] - "mch_indexes.Indexes" // row[2] - " FROM mch_matches,gam_questions,mch_indexes" - " WHERE mch_matches.MchCod=%ld" - " AND mch_matches.GamCod=gam_questions.GamCod" - " AND mch_matches.MchCod=mch_indexes.MchCod" - " AND gam_questions.QstInd=mch_indexes.QstInd" - " ORDER BY gam_questions.QstInd", - MchCod); - for (NumQst = 0, *NumQstsNotBlank = 0; - NumQst < *NumQsts; + UsrAnswers->NumQsts = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get questions and answers" + " of a match result", + "SELECT gam_questions.QstCod," // row[0] + "gam_questions.QstInd," // row[1] + "mch_indexes.Indexes" // row[2] + " FROM mch_matches,gam_questions,mch_indexes" + " WHERE mch_matches.MchCod=%ld" + " AND mch_matches.GamCod=gam_questions.GamCod" + " AND mch_matches.MchCod=mch_indexes.MchCod" + " AND gam_questions.QstInd=mch_indexes.QstInd" + " ORDER BY gam_questions.QstInd", + MchCod); + for (NumQst = 0, UsrAnswers->NumQstsNotBlank = 0; + NumQst < UsrAnswers->NumQsts; NumQst++) { row = mysql_fetch_row (mysql_res); @@ -1273,7 +1269,7 @@ void McR_GetMatchResultQuestionsFromDB (long MchCod,long UsrCod, { snprintf (UsrAnswers->StrAnswersOneQst[NumQst],Tst_MAX_BYTES_ANSWERS_ONE_QST + 1, "%d",UsrAnswer.AnsInd); - (*NumQstsNotBlank)++; + UsrAnswers->NumQstsNotBlank++; } else // UsrAnswer.AnsInd < 0 ==> no answer selected UsrAnswers->StrAnswersOneQst[NumQst][0] = '\0'; // Empty answer @@ -1294,8 +1290,7 @@ void McR_GetMatchResultQuestionsFromDB (long MchCod,long UsrCod, static void McR_GetMatchResultDataByMchCod (long MchCod,long UsrCod, time_t TimeUTC[Dat_NUM_START_END_TIME], - unsigned *NumQsts, - unsigned *NumQstsNotBlank, + struct Tst_UsrAnswers *UsrAnswers, double *Score) { MYSQL_RES *mysql_res; @@ -1328,12 +1323,12 @@ static void McR_GetMatchResultDataByMchCod (long MchCod,long UsrCod, TimeUTC[StartEndTime] = Dat_GetUNIXTimeFromStr (row[StartEndTime]); /* Get number of questions (row[2]) */ - if (sscanf (row[2],"%u",NumQsts) != 1) - *NumQsts = 0; + if (sscanf (row[2],"%u",&UsrAnswers->NumQsts) != 1) + UsrAnswers->NumQsts = 0; /* Get number of questions not blank (row[3]) */ - if (sscanf (row[3],"%u",NumQstsNotBlank) != 1) - *NumQstsNotBlank = 0; + if (sscanf (row[3],"%u",&UsrAnswers->NumQstsNotBlank) != 1) + UsrAnswers->NumQstsNotBlank = 0; /* Get score (row[4]) */ Str_SetDecimalPointToUS (); // To get the decimal point as a dot diff --git a/swad_match_result.h b/swad_match_result.h index 356d4cbc7..6d13540fe 100644 --- a/swad_match_result.h +++ b/swad_match_result.h @@ -50,7 +50,6 @@ void McR_ShowAllMchResultsInMch (void); void McR_ShowOneMchResult (void); void McR_GetMatchResultQuestionsFromDB (long MchCod,long UsrCod, - unsigned *NumQsts,unsigned *NumQstsNotBlank, struct Tst_UsrAnswers *UsrAnswers); #endif diff --git a/swad_test.c b/swad_test.c index 178dd20d4..4c8ba1f17 100644 --- a/swad_test.c +++ b/swad_test.c @@ -131,8 +131,7 @@ static void Tst_ResetAnswerTypes (struct Tst_AnswerTypes *AnswerTypes); static void Tst_ShowFormRequestTest (const struct Tst_Tags *Tags, const struct Tst_AnswerTypes *AnswerTypes); -static void Tst_GetQuestionsAndAnswersFromForm (unsigned NumQsts, - struct Tst_UsrAnswers *UsrAnswers); +static void Tst_GetQuestionsAndAnswersFromForm (struct Tst_UsrAnswers *UsrAnswers); static bool Tst_CheckIfNextTstAllowed (void); static void Tst_SetTstStatus (unsigned NumTst,Tst_Status_t TstStatus); static Tst_Status_t Tst_GetTstStatus (unsigned NumTst); @@ -141,9 +140,7 @@ static void Tst_ShowTestQuestionsWhenSeeing (unsigned NumQsts, MYSQL_RES *mysql_res); static void Tst_ShowOneTestQuestionWhenSeeing (unsigned NumQst,long QstCod); static void Tst_ShowTestResultAfterAssess (long TstCod, - unsigned NumQsts, - unsigned *NumQstsNotBlank, - const struct Tst_UsrAnswers *UsrAnswers, + struct Tst_UsrAnswers *UsrAnswers, double *TotalScore); static void Tst_WriteQstAndAnsTestToAnswer (unsigned NumQst, long QstCod, @@ -587,10 +584,8 @@ void Tst_AssessTest (void) extern const char *Txt_The_test_X_has_already_been_assessed_previously; extern const char *Txt_There_was_an_error_in_assessing_the_test_X; unsigned NumTst; - unsigned NumQsts; bool AllowTeachers; // Can teachers of this course see the test result? long TstCod = -1L; // Initialized to avoid warning - unsigned NumQstsNotBlank; struct Tst_UsrAnswers UsrAnswers; double TotalScore; @@ -606,16 +601,16 @@ void Tst_AssessTest (void) case Tst_STATUS_SHOWN_BUT_NOT_ASSESSED: /***** Get the parameters of the form *****/ /* Get number of questions */ - NumQsts = Tst_GetParamNumQsts (); + UsrAnswers.NumQsts = Tst_GetParamNumQsts (); /***** Get if test will be visible by teachers *****/ AllowTeachers = Par_GetParToBool ("AllowTchs"); /***** Get questions and answers from form to assess a test *****/ - Tst_GetQuestionsAndAnswersFromForm (NumQsts,&UsrAnswers); + Tst_GetQuestionsAndAnswersFromForm (&UsrAnswers); /***** Create new test in database to store the result *****/ - TstCod = TsR_CreateTestResultInDB (AllowTeachers,NumQsts); + TstCod = TsR_CreateTestResultInDB (AllowTeachers,UsrAnswers.NumQsts); /***** Begin box *****/ Box_BoxBegin (NULL,Txt_Test_result,NULL, @@ -635,8 +630,7 @@ void Tst_AssessTest (void) /***** Write answers and solutions *****/ HTM_TABLE_BeginWideMarginPadding (10); - Tst_ShowTestResultAfterAssess (TstCod,NumQsts,&NumQstsNotBlank, - &UsrAnswers,&TotalScore); + Tst_ShowTestResultAfterAssess (TstCod,&UsrAnswers,&TotalScore); HTM_TABLE_End (); /***** Write total score and grade *****/ @@ -647,7 +641,7 @@ void Tst_AssessTest (void) HTM_Double2Decimals (TotalScore); HTM_BR (); HTM_TxtColonNBSP (Txt_Grade); - Tst_ComputeAndShowGrade (NumQsts,TotalScore,TsR_SCORE_MAX); + Tst_ComputeAndShowGrade (UsrAnswers.NumQsts,TotalScore,TsR_SCORE_MAX); HTM_DIV_End (); } @@ -656,7 +650,7 @@ void Tst_AssessTest (void) /***** Store test result in database *****/ TsR_StoreScoreOfTestResultInDB (TstCod, - NumQstsNotBlank,TotalScore); + &UsrAnswers,TotalScore); /***** Set test status *****/ Tst_SetTstStatus (NumTst,Tst_STATUS_ASSESSED); @@ -676,15 +670,14 @@ void Tst_AssessTest (void) /*********** Get questions and answers from form to assess a test ************/ /*****************************************************************************/ -static void Tst_GetQuestionsAndAnswersFromForm (unsigned NumQsts, - struct Tst_UsrAnswers *UsrAnswers) +static void Tst_GetQuestionsAndAnswersFromForm (struct Tst_UsrAnswers *UsrAnswers) { unsigned NumQst; char StrQstIndOrAns[3 + Cns_MAX_DECIMAL_DIGITS_UINT + 1]; // "Qstxx...x", "Indxx...x" or "Ansxx...x" /***** Get questions and answers *****/ for (NumQst = 0; - NumQst < NumQsts; + NumQst < UsrAnswers->NumQsts; NumQst++) { /* Get question code */ @@ -999,9 +992,7 @@ void Tst_ShowTagList (unsigned NumTags,MYSQL_RES *mysql_res) /*****************************************************************************/ static void Tst_ShowTestResultAfterAssess (long TstCod, - unsigned NumQsts, - unsigned *NumQstsNotBlank, - const struct Tst_UsrAnswers *UsrAnswers, + struct Tst_UsrAnswers *UsrAnswers, double *TotalScore) { extern const char *Txt_Question_removed; @@ -1013,10 +1004,10 @@ static void Tst_ShowTestResultAfterAssess (long TstCod, /***** Initialize score and number of questions not blank *****/ *TotalScore = 0.0; - *NumQstsNotBlank = 0; + UsrAnswers->NumQstsNotBlank = 0; for (NumQst = 0; - NumQst < NumQsts; + NumQst < UsrAnswers->NumQsts; NumQst++) { Gbl.RowEvenOdd = NumQst % 2; @@ -1041,7 +1032,7 @@ static void Tst_ShowTestResultAfterAssess (long TstCod, /***** Compute total score *****/ *TotalScore += ScoreThisQst; if (AnswerIsNotBlank) - (*NumQstsNotBlank)++; + UsrAnswers->NumQstsNotBlank++; /***** Update the number of accesses and the score of this question *****/ if (Gbl.Usrs.Me.Role.Logged == Rol_STD) diff --git a/swad_test_result.c b/swad_test_result.c index 9f48883bb..ee20685f1 100644 --- a/swad_test_result.c +++ b/swad_test_result.c @@ -89,8 +89,7 @@ static void TsR_ShowTstTagsPresentInATestResult (long TstCod); static void TsR_GetTestResultDataByTstCod (long TstCod, bool *AllowTeachers, time_t *TstTimeUTC, - unsigned *NumQsts, - unsigned *NumQstsNotBlank, + struct Tst_UsrAnswers *UsrAnswers, double *Score); static unsigned TsR_GetTestResultQuestionsFromDB (long TstCod,struct Tst_UsrAnswers *UsrAnswers); @@ -194,7 +193,7 @@ long TsR_CreateTestResultInDB (bool AllowTeachers,unsigned NumQsts) /*****************************************************************************/ void TsR_StoreScoreOfTestResultInDB (long TstCod, - unsigned NumQstsNotBlank,double Score) + const struct Tst_UsrAnswers *UsrAnswers,double Score) { /***** Update score in test result *****/ Str_SetDecimalPointToUS (); // To print the floating point as a dot @@ -202,7 +201,7 @@ void TsR_StoreScoreOfTestResultInDB (long TstCod, "UPDATE tst_exams" " SET NumQstsNotBlank=%u,Score='%.15lg'" " WHERE TstCod=%ld", - NumQstsNotBlank,Score, + UsrAnswers->NumQstsNotBlank,Score, TstCod); Str_SetDecimalPointToLocal (); // Return to local system } @@ -604,8 +603,6 @@ void TsR_ShowOneTstResult (void) long TstCod; bool AllowTeachers = false; // Initialized to avoid warning time_t TstTimeUTC = 0; // Test result UTC date-time, initialized to avoid warning - unsigned NumQsts; - unsigned NumQstsNotBlank; struct Tst_UsrAnswers UsrAnswers; double TotalScore; bool ShowPhoto; @@ -622,8 +619,7 @@ void TsR_ShowOneTstResult (void) TsR_GetTestResultDataByTstCod (TstCod, &AllowTeachers, &TstTimeUTC, - &NumQsts, - &NumQstsNotBlank, + &UsrAnswers, &TotalScore); TstCfg_SetConfigVisibility (TsV_MAX_VISIBILITY); @@ -675,7 +671,7 @@ void TsR_ShowOneTstResult (void) if (ICanViewTest) // I am allowed to view this test result { /***** Get questions and user's answers of the test result from database *****/ - NumQsts = TsR_GetTestResultQuestionsFromDB (TstCod,&UsrAnswers); + UsrAnswers.NumQsts = TsR_GetTestResultQuestionsFromDB (TstCod,&UsrAnswers); /***** Begin box *****/ Box_BoxBegin (NULL,Txt_Test_result,NULL, @@ -742,7 +738,8 @@ void TsR_ShowOneTstResult (void) HTM_TD_Begin ("class=\"DAT LT\""); HTM_TxtF ("%u (%u %s)", - NumQsts,NumQstsNotBlank,Txt_non_blank_QUESTIONS); + UsrAnswers.NumQsts, + UsrAnswers.NumQstsNotBlank,Txt_non_blank_QUESTIONS); HTM_TD_End (); HTM_TR_End (); @@ -770,7 +767,7 @@ void TsR_ShowOneTstResult (void) HTM_TD_Begin ("class=\"DAT LT\""); if (ICanViewScore) - Tst_ComputeAndShowGrade (NumQsts,TotalScore,TsR_SCORE_MAX); + Tst_ComputeAndShowGrade (UsrAnswers.NumQsts,TotalScore,TsR_SCORE_MAX); else Ico_PutIconNotVisible (); HTM_TD_End (); @@ -792,7 +789,6 @@ void TsR_ShowOneTstResult (void) /***** Write answers and solutions *****/ TsR_ShowTestResult (&Gbl.Usrs.Other.UsrDat, - NumQsts, &UsrAnswers, TstTimeUTC, TstCfg_GetConfigVisibility ()); @@ -808,7 +804,7 @@ void TsR_ShowOneTstResult (void) HTM_Double2Decimals (TotalScore); HTM_BR (); HTM_TxtColonNBSP (Txt_Grade); - Tst_ComputeAndShowGrade (NumQsts,TotalScore,TsR_SCORE_MAX); + Tst_ComputeAndShowGrade (UsrAnswers.NumQsts,TotalScore,TsR_SCORE_MAX); HTM_DIV_End (); } @@ -853,7 +849,6 @@ static void TsR_ShowTstTagsPresentInATestResult (long TstCod) /*****************************************************************************/ void TsR_ShowTestResult (struct UsrData *UsrDat, - unsigned NumQsts, const struct Tst_UsrAnswers *UsrAnswers, time_t TstTimeUTC, unsigned Visibility) @@ -869,7 +864,7 @@ void TsR_ShowTestResult (struct UsrData *UsrDat, time_t EditTimeUTC; for (NumQst = 0; - NumQst < NumQsts; + NumQst < UsrAnswers->NumQsts; NumQst++) { Gbl.RowEvenOdd = NumQst % 2; @@ -940,8 +935,7 @@ void TsR_ShowTestResult (struct UsrData *UsrDat, static void TsR_GetTestResultDataByTstCod (long TstCod, bool *AllowTeachers, time_t *TstTimeUTC, - unsigned *NumQsts, - unsigned *NumQstsNotBlank, + struct Tst_UsrAnswers *UsrAnswers, double *Score) { MYSQL_RES *mysql_res; @@ -973,12 +967,12 @@ static void TsR_GetTestResultDataByTstCod (long TstCod, *TstTimeUTC = Dat_GetUNIXTimeFromStr (row[2]); /* Get number of questions (row[3]) */ - if (sscanf (row[3],"%u",NumQsts) != 1) - *NumQsts = 0; + if (sscanf (row[3],"%u",&UsrAnswers->NumQsts) != 1) + UsrAnswers->NumQsts = 0; /* Get number of questions not blank (row[4]) */ - if (sscanf (row[4],"%u",NumQstsNotBlank) != 1) - *NumQstsNotBlank = 0; + if (sscanf (row[4],"%u",&UsrAnswers->NumQstsNotBlank) != 1) + UsrAnswers->NumQstsNotBlank = 0; /* Get score (row[5]) */ Str_SetDecimalPointToUS (); // To get the decimal point as a dot diff --git a/swad_test_result.h b/swad_test_result.h index 3a81c9b3b..ac8a29c29 100644 --- a/swad_test_result.h +++ b/swad_test_result.h @@ -45,6 +45,8 @@ struct Tst_UsrAnswers { + unsigned NumQsts; + unsigned NumQstsNotBlank; long QstCodes[TstCfg_MAX_QUESTIONS_PER_TEST]; // Codes of the sent/received questions in a test char StrIndexesOneQst[TstCfg_MAX_QUESTIONS_PER_TEST] [Tst_MAX_BYTES_INDEXES_ONE_QST + 1]; // 0 1 2 3, 3 0 2 1, etc. @@ -61,11 +63,10 @@ void TsR_SelDatesToSeeMyTstResults (void); void TsR_ShowMyTstResults (void); long TsR_CreateTestResultInDB (bool AllowTeachers,unsigned NumQsts); void TsR_StoreScoreOfTestResultInDB (long TstCod, - unsigned NumQstsNotBlank,double Score); + const struct Tst_UsrAnswers *UsrAnswers,double Score); void TsR_GetUsrsAndShowTstResults (void); void TsR_ShowOneTstResult (void); void TsR_ShowTestResult (struct UsrData *UsrDat, - unsigned NumQsts, const struct Tst_UsrAnswers *UsrAnswers, time_t TstTimeUTC, unsigned Visibility);