Version19.151.3

This commit is contained in:
acanas 2020-03-22 01:15:27 +01:00
parent 63cbb9fb12
commit 4bdc8daf78
9 changed files with 77 additions and 91 deletions

View File

@ -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.151.2 (2020-03-21)"
#define Log_PLATFORM_VERSION "SWAD 19.151.3 (2020-03-22)"
#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.151.3: Mar 22, 2020 Code refactoring in tests. (283433 lines)
Version 19.151.2: Mar 21, 2020 Code refactoring in tests. (283446 lines)
Version 19.151.1: Mar 21, 2020 Code refactoring in tests. (283360 lines)
Version 19.151: Mar 21, 2020 Code refactoring in tests.

View File

@ -48,8 +48,6 @@
#include "swad_project.h"
#include "swad_role.h"
#include "swad_setting.h"
#include "swad_test_config.h"
#include "swad_test_visibility.h"
#include "swad_theme.h"
/*****************************************************************************/
@ -357,11 +355,6 @@ void Gbl_InitializeGlobals (void)
Gbl.Usrs.Connected.TimeToRefreshInMs = Con_MAX_TIME_TO_REFRESH_CONNECTED_IN_MS;
/* Tests */
// Tst_SetConfigPluggable (TstCfg_PLUGGABLE_UNKNOWN);
// Tst_SetConfigVisibility (TsV_VISIBILITY_DEFAULT);
Gbl.Test.NumQsts = TstCfg_DEFAULT_DEF_QUESTIONS;
/* Games for remote control */
Gbl.Games.ListQuestions = NULL;

View File

@ -651,7 +651,6 @@ struct Globals
} TimeTable;
struct
{
unsigned NumQsts;
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

View File

@ -131,19 +131,21 @@ 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 (void);
static void Tst_GetQuestionsAndAnswersFromForm (unsigned NumQsts);
static bool Tst_CheckIfNextTstAllowed (void);
static void Tst_SetTstStatus (unsigned NumTst,Tst_Status_t TstStatus);
static Tst_Status_t Tst_GetTstStatus (unsigned NumTst);
static unsigned Tst_GetNumAccessesTst (void);
static void Tst_ShowTestQuestionsWhenSeeing (MYSQL_RES *mysql_res);
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 *NumQstsNotBlank,double *TotalScore);
static void Tst_ShowTestResultAfterAssess (long TstCod,unsigned NumQsts,
unsigned *NumQstsNotBlank,
double *TotalScore);
static void Tst_PutFormToEditQstMedia (const struct Media *Media,int NumMediaInForm,
bool OptionsDisabled);
static void Tst_UpdateScoreQst (long QstCod,double ScoreThisQst,bool AnswerIsNotBlank);
static void Tst_UpdateMyNumAccessTst (unsigned NumAccessesTst);
static void Tst_UpdateLastAccTst (void);
static void Tst_UpdateLastAccTst (unsigned NumQsts);
static void Tst_ShowFormRequestEditTests (const struct Tst_Tags *Tags,
const struct Tst_AnswerTypes *AnswerTypes);
@ -173,6 +175,7 @@ static unsigned long Tst_GetQuestions (const struct Tst_Tags *Tags,
MYSQL_RES **mysql_res);
static unsigned long Tst_GetQuestionsForTest (const struct Tst_Tags *Tags,
const struct Tst_AnswerTypes *AnswerTypes,
unsigned NumQsts,
MYSQL_RES **mysql_res);
static void Tst_ListOneQstToEdit (long QstCod,
const struct Tst_Tags *Tags,
@ -260,9 +263,10 @@ static void Tst_WriteScoreEnd (void);
static void Tst_WriteParamQstCod (unsigned NumQst,long QstCod);
static bool Tst_GetParamsTst (struct Tst_Tags *Tags,
struct Tst_AnswerTypes *AnswerTypes,
unsigned *NumQsts,
Tst_ActionToDoWithQuestions_t ActionToDoWithQuestions);
static unsigned Tst_GetAndCheckParamNumTst (void);
static void Tst_GetParamNumQst (void);
static unsigned Tst_GetParamNumQsts (void);
static unsigned Tst_CountNumTagsInList (const struct Tst_Tags *Tags);
static int Tst_CountNumAnswerTypesInList (const struct Tst_AnswerTypes *AnswerTypes);
@ -466,6 +470,7 @@ void Tst_ShowNewTest (void)
extern const char *Txt_Done_assess_test;
struct Tst_Tags Tags;
struct Tst_AnswerTypes AnswerTypes;
unsigned NumQsts;
MYSQL_RES *mysql_res;
unsigned long NumRows;
unsigned NumAccessesTst;
@ -476,10 +481,11 @@ void Tst_ShowNewTest (void)
if (Tst_CheckIfNextTstAllowed ())
{
/***** Check that all parameters used to generate a test are valid *****/
if (Tst_GetParamsTst (&Tags,&AnswerTypes,Tst_SHOW_TEST_TO_ANSWER)) // Get parameters from form
if (Tst_GetParamsTst (&Tags,&AnswerTypes,&NumQsts,Tst_SHOW_TEST_TO_ANSWER)) // Get parameters from form
{
/***** Get questions *****/
if ((NumRows = Tst_GetQuestionsForTest (&Tags,&AnswerTypes,&mysql_res)) == 0) // Query database
if ((NumRows = Tst_GetQuestionsForTest (&Tags,&AnswerTypes,NumQsts,
&mysql_res)) == 0) // Query database
{
Ale_ShowAlert (Ale_INFO,Txt_No_questions_found_matching_your_search_criteria);
Tst_ShowFormRequestTest (&Tags,&AnswerTypes); // Show the form again
@ -501,13 +507,13 @@ void Tst_ShowNewTest (void)
/***** Begin form *****/
Frm_StartForm (ActAssTst);
Gbl.Test.NumQsts = (unsigned) NumRows;
NumQsts = (unsigned) NumRows;
Par_PutHiddenParamUnsigned (NULL,"NumTst",NumAccessesTst);
Par_PutHiddenParamUnsigned (NULL,"NumQst",Gbl.Test.NumQsts);
Par_PutHiddenParamUnsigned (NULL,"NumQst",NumQsts);
/***** List the questions *****/
HTM_TABLE_BeginWideMarginPadding (10);
Tst_ShowTestQuestionsWhenSeeing (mysql_res);
Tst_ShowTestQuestionsWhenSeeing (NumQsts,mysql_res);
HTM_TABLE_End ();
/***** Test result will be saved? *****/
@ -532,7 +538,7 @@ void Tst_ShowNewTest (void)
/***** Update date-time of my next allowed access to test *****/
if (Gbl.Usrs.Me.Role.Logged == Rol_STD)
Tst_UpdateLastAccTst ();
Tst_UpdateLastAccTst (NumQsts);
}
/***** Free structure that stores the query result *****/
@ -560,6 +566,7 @@ 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;
@ -577,16 +584,16 @@ void Tst_AssessTest (void)
case Tst_STATUS_SHOWN_BUT_NOT_ASSESSED:
/***** Get the parameters of the form *****/
/* Get number of questions */
Tst_GetParamNumQst ();
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 ();
Tst_GetQuestionsAndAnswersFromForm (NumQsts);
/***** Create new test in database to store the result *****/
TstCod = TsR_CreateTestResultInDB (AllowTeachers);
TstCod = TsR_CreateTestResultInDB (AllowTeachers,NumQsts);
/***** Begin box *****/
Box_BoxBegin (NULL,Txt_Test_result,NULL,
@ -606,7 +613,7 @@ void Tst_AssessTest (void)
/***** Write answers and solutions *****/
HTM_TABLE_BeginWideMarginPadding (10);
Tst_ShowTestResultAfterAssess (TstCod,&NumQstsNotBlank,&TotalScore);
Tst_ShowTestResultAfterAssess (TstCod,NumQsts,&NumQstsNotBlank,&TotalScore);
HTM_TABLE_End ();
/***** Write total score and grade *****/
@ -617,7 +624,7 @@ void Tst_AssessTest (void)
HTM_Double2Decimals (TotalScore);
HTM_BR ();
HTM_TxtColonNBSP (Txt_Grade);
Tst_ComputeAndShowGrade (Gbl.Test.NumQsts,TotalScore,TsR_SCORE_MAX);
Tst_ComputeAndShowGrade (NumQsts,TotalScore,TsR_SCORE_MAX);
HTM_DIV_End ();
}
@ -646,14 +653,14 @@ void Tst_AssessTest (void)
/*********** Get questions and answers from form to assess a test ************/
/*****************************************************************************/
static void Tst_GetQuestionsAndAnswersFromForm (void)
static void Tst_GetQuestionsAndAnswersFromForm (unsigned NumQsts)
{
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 < Gbl.Test.NumQsts;
NumQst < NumQsts;
NumQst++)
{
/* Get question code */
@ -891,7 +898,7 @@ static unsigned Tst_GetNumAccessesTst (void)
// NumRows must hold the number of rows of a MySQL query
// In each row mysql_res holds: in the column 0 the code of a question, in the column 1 the type of answer, and in the column 2 the stem
static void Tst_ShowTestQuestionsWhenSeeing (MYSQL_RES *mysql_res)
static void Tst_ShowTestQuestionsWhenSeeing (unsigned NumQsts,MYSQL_RES *mysql_res)
{
unsigned NumQst;
long QstCod;
@ -899,7 +906,7 @@ static void Tst_ShowTestQuestionsWhenSeeing (MYSQL_RES *mysql_res)
/***** Write rows *****/
for (NumQst = 0;
NumQst < Gbl.Test.NumQsts;
NumQst < NumQsts;
NumQst++)
{
Gbl.RowEvenOdd = NumQst % 2;
@ -986,7 +993,9 @@ void Tst_ShowTagList (unsigned NumTags,MYSQL_RES *mysql_res)
/******************* Show the result of assessing a test *********************/
/*****************************************************************************/
static void Tst_ShowTestResultAfterAssess (long TstCod,unsigned *NumQstsNotBlank,double *TotalScore)
static void Tst_ShowTestResultAfterAssess (long TstCod,unsigned NumQsts,
unsigned *NumQstsNotBlank,
double *TotalScore)
{
extern const char *Txt_Question_removed;
MYSQL_RES *mysql_res;
@ -1000,7 +1009,7 @@ static void Tst_ShowTestResultAfterAssess (long TstCod,unsigned *NumQstsNotBlank
*NumQstsNotBlank = 0;
for (NumQst = 0;
NumQst < Gbl.Test.NumQsts;
NumQst < NumQsts;
NumQst++)
{
Gbl.RowEvenOdd = NumQst % 2;
@ -1325,13 +1334,13 @@ static void Tst_UpdateMyNumAccessTst (unsigned NumAccessesTst)
/************ Update date-time of my next allowed access to test *************/
/*****************************************************************************/
static void Tst_UpdateLastAccTst (void)
static void Tst_UpdateLastAccTst (unsigned NumQsts)
{
/***** Update date-time and number of questions of this test *****/
DB_QueryUPDATE ("can not update time and number of questions of this test",
"UPDATE crs_usr SET LastAccTst=NOW(),NumQstsLastTst=%u"
" WHERE CrsCod=%ld AND UsrCod=%ld",
Gbl.Test.NumQsts,
NumQsts,
Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
@ -2301,11 +2310,12 @@ void Tst_ListQuestionsToEdit (void)
{
struct Tst_Tags Tags;
struct Tst_AnswerTypes AnswerTypes;
unsigned NumQsts;
MYSQL_RES *mysql_res;
unsigned long NumRows;
/***** Get parameters, query the database and list the questions *****/
if (Tst_GetParamsTst (&Tags,&AnswerTypes,Tst_EDIT_TEST)) // Get parameters from the form
if (Tst_GetParamsTst (&Tags,&AnswerTypes,&NumQsts,Tst_EDIT_TEST)) // Get parameters from the form
{
/***** Get question codes from database *****/
if ((NumRows = Tst_GetQuestions (&Tags,&AnswerTypes,&mysql_res)) != 0) // Query database
@ -2343,11 +2353,12 @@ void Tst_ListQuestionsToSelect (void)
{
struct Tst_Tags Tags;
struct Tst_AnswerTypes AnswerTypes;
unsigned NumQsts;
MYSQL_RES *mysql_res;
unsigned long NumRows;
/***** Get parameters, query the database and list the questions *****/
if (Tst_GetParamsTst (&Tags,&AnswerTypes,Tst_SELECT_QUESTIONS_FOR_GAME)) // Get parameters from the form
if (Tst_GetParamsTst (&Tags,&AnswerTypes,&NumQsts,Tst_SELECT_QUESTIONS_FOR_GAME)) // Get parameters from the form
{
if ((NumRows = Tst_GetQuestions (&Tags,&AnswerTypes,&mysql_res)) != 0) // Query database
/* Show the table with the questions */
@ -2535,6 +2546,7 @@ static unsigned long Tst_GetQuestions (const struct Tst_Tags *Tags,
static unsigned long Tst_GetQuestionsForTest (const struct Tst_Tags *Tags,
const struct Tst_AnswerTypes *AnswerTypes,
unsigned NumQsts,
MYSQL_RES **mysql_res)
{
char *Query = NULL;
@ -2629,7 +2641,7 @@ static unsigned long Tst_GetQuestionsForTest (const struct Tst_Tags *Tags,
Tst_MAX_BYTES_QUERY_TEST);
snprintf (StrNumQsts,sizeof (StrNumQsts),
"%u",
Gbl.Test.NumQsts);
NumQsts);
Str_Concat (Query,StrNumQsts,
Tst_MAX_BYTES_QUERY_TEST);
/*
@ -4975,6 +4987,7 @@ void Tst_GetAndWriteTagsQst (long QstCod)
static bool Tst_GetParamsTst (struct Tst_Tags *Tags,
struct Tst_AnswerTypes *AnswerTypes,
unsigned *NumQsts,
Tst_ActionToDoWithQuestions_t ActionToDoWithQuestions)
{
extern const char *Txt_You_must_select_one_ore_more_tags;
@ -5033,9 +5046,9 @@ static bool Tst_GetParamsTst (struct Tst_Tags *Tags,
switch (ActionToDoWithQuestions)
{
case Tst_SHOW_TEST_TO_ANSWER:
Tst_GetParamNumQst ();
if (Gbl.Test.NumQsts < TstCfg_GetConfigMin () ||
Gbl.Test.NumQsts > TstCfg_GetConfigMax ())
*NumQsts = Tst_GetParamNumQsts ();
if (*NumQsts < TstCfg_GetConfigMin () ||
*NumQsts > TstCfg_GetConfigMax ())
{
Ale_ShowAlert (Ale_WARNING,Txt_The_number_of_questions_must_be_in_the_interval_X,
TstCfg_GetConfigMin (),TstCfg_GetConfigMax ());
@ -5087,13 +5100,12 @@ static unsigned Tst_GetAndCheckParamNumTst (void)
/***** Get parameter with the number of questions to generate in an test *****/
/*****************************************************************************/
static void Tst_GetParamNumQst (void)
static unsigned Tst_GetParamNumQsts (void)
{
Gbl.Test.NumQsts = (unsigned)
Par_GetParToUnsignedLong ("NumQst",
(unsigned long) TstCfg_GetConfigMin (),
(unsigned long) TstCfg_GetConfigMax (),
(unsigned long) TstCfg_GetConfigDef ());
return (unsigned) Par_GetParToUnsignedLong ("NumQst",
(unsigned long) TstCfg_GetConfigMin (),
(unsigned long) TstCfg_GetConfigMax (),
(unsigned long) TstCfg_GetConfigDef ());
}
/*****************************************************************************/
@ -6696,11 +6708,12 @@ void Tst_RequestRemoveSelectedQsts (void)
{
extern const char *Txt_Do_you_really_want_to_remove_the_selected_questions;
extern const char *Txt_Remove_questions;
unsigned NumQsts;
struct Tst_Tags Tags;
struct Tst_AnswerTypes AnswerTypes;
/***** Get parameters *****/
if (Tst_GetParamsTst (&Tags,&AnswerTypes,Tst_EDIT_TEST)) // Get parameters from the form
if (Tst_GetParamsTst (&Tags,&AnswerTypes,&NumQsts,Tst_EDIT_TEST)) // Get parameters from the form
{
/***** Show question and button to remove question *****/
Tst_SetParamGblTags (&Tags);
@ -6739,6 +6752,7 @@ void Tst_RemoveSelectedQsts (void)
extern const char *Txt_Questions_removed_X;
struct Tst_Tags Tags;
struct Tst_AnswerTypes AnswerTypes;
unsigned NumQsts;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumRows;
@ -6746,7 +6760,7 @@ void Tst_RemoveSelectedQsts (void)
long QstCod;
/***** Get parameters *****/
if (Tst_GetParamsTst (&Tags,&AnswerTypes,Tst_EDIT_TEST)) // Get parameters
if (Tst_GetParamsTst (&Tags,&AnswerTypes,&NumQsts,Tst_EDIT_TEST)) // Get parameters
{
/***** Get question codes *****/
NumRows = (unsigned) Tst_GetQuestions (&Tags,&AnswerTypes,&mysql_res); // Query database
@ -6794,6 +6808,7 @@ void Tst_RequestRemoveOneQst (void)
bool EditingOnlyThisQst;
struct Tst_Tags Tags;
struct Tst_AnswerTypes AnswerTypes;
unsigned NumQsts;
/***** Get main parameters from form *****/
/* Get the question code */
@ -6807,7 +6822,7 @@ void Tst_RequestRemoveOneQst (void)
/* Get other parameters */
if (!EditingOnlyThisQst)
if (!Tst_GetParamsTst (&Tags,&AnswerTypes,Tst_EDIT_TEST))
if (!Tst_GetParamsTst (&Tags,&AnswerTypes,&NumQsts,Tst_EDIT_TEST))
Lay_ShowErrorAndExit ("Wrong test parameters.");
/***** Show question and button to remove question *****/

View File

@ -95,7 +95,6 @@ struct Tst_Test
{
struct Tst_Tags Tags;
struct Tst_AnswerTypes AnswerTypes;
unsigned NumQsts;
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.

View File

@ -25,36 +25,12 @@
/*********************************** Headers *********************************/
/*****************************************************************************/
// #define _GNU_SOURCE // For asprintf
// #include <limits.h> // For UINT_MAX
// #include <linux/limits.h> // For PATH_MAX
// #include <mysql/mysql.h> // To access MySQL databases
// #include <stdbool.h> // For boolean type
// #include <stddef.h> // For NULL
// #include <stdio.h> // For asprintf
// #include <stdlib.h> // For exit, system, malloc, free, etc
#include <string.h> // For string functions
// #include <sys/stat.h> // For mkdir
// #include <sys/types.h> // For mkdir
// #include "swad_action.h"
// #include "swad_box.h"
#include "swad_database.h"
// #include "swad_form.h"
#include "swad_global.h"
// #include "swad_HTML.h"
// #include "swad_ID.h"
// #include "swad_language.h"
// #include "swad_match.h"
// #include "swad_media.h"
// #include "swad_parameter.h"
// #include "swad_theme.h"
// #include "swad_test.h"
#include "swad_test_config.h"
// #include "swad_test_import.h"
#include "swad_test_visibility.h"
// #include "swad_user.h"
// #include "swad_xml.h"
/*****************************************************************************/
/***************************** Public constants ******************************/

View File

@ -30,10 +30,6 @@
#include <mysql/mysql.h> // To access MySQL databases
#include <stdbool.h> // For boolean type
// #include "swad_game.h"
// #include "swad_media.h"
// #include "swad_test_result.h"
/*****************************************************************************/
/***************************** Public constants ******************************/
/*****************************************************************************/

View File

@ -89,9 +89,10 @@ static void TsR_ShowTstTagsPresentInATestResult (long TstCod);
static void TsR_GetTestResultDataByTstCod (long TstCod,
bool *AllowTeachers,
time_t *TstTimeUTC,
unsigned *NumQsts,
unsigned *NumQstsNotBlank,
double *Score);
static void TsR_GetTestResultQuestionsFromDB (long TstCod);
static unsigned TsR_GetTestResultQuestionsFromDB (long TstCod);
/*****************************************************************************/
/************ Select users and dates to show their test results **************/
@ -172,7 +173,7 @@ void TsR_ShowMyTstResults (void)
/********************* Store test result in database *************************/
/*****************************************************************************/
long TsR_CreateTestResultInDB (bool AllowTeachers)
long TsR_CreateTestResultInDB (bool AllowTeachers,unsigned NumQsts)
{
/***** Insert new test result into table *****/
return
@ -185,7 +186,7 @@ long TsR_CreateTestResultInDB (bool AllowTeachers)
Gbl.Usrs.Me.UsrDat.UsrCod,
AllowTeachers ? 'Y' :
'N',
Gbl.Test.NumQsts);
NumQsts);
}
/*****************************************************************************/
@ -603,6 +604,7 @@ 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;
double TotalScore;
bool ShowPhoto;
@ -619,6 +621,7 @@ void TsR_ShowOneTstResult (void)
TsR_GetTestResultDataByTstCod (TstCod,
&AllowTeachers,
&TstTimeUTC,
&NumQsts,
&NumQstsNotBlank,
&TotalScore);
TstCfg_SetConfigVisibility (TsV_MAX_VISIBILITY);
@ -671,7 +674,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 *****/
TsR_GetTestResultQuestionsFromDB (TstCod);
NumQsts = TsR_GetTestResultQuestionsFromDB (TstCod);
/***** Begin box *****/
Box_BoxBegin (NULL,Txt_Test_result,NULL,
@ -738,7 +741,7 @@ void TsR_ShowOneTstResult (void)
HTM_TD_Begin ("class=\"DAT LT\"");
HTM_TxtF ("%u (%u %s)",
Gbl.Test.NumQsts,NumQstsNotBlank,Txt_non_blank_QUESTIONS);
NumQsts,NumQstsNotBlank,Txt_non_blank_QUESTIONS);
HTM_TD_End ();
HTM_TR_End ();
@ -766,7 +769,7 @@ void TsR_ShowOneTstResult (void)
HTM_TD_Begin ("class=\"DAT LT\"");
if (ICanViewScore)
Tst_ComputeAndShowGrade (Gbl.Test.NumQsts,TotalScore,TsR_SCORE_MAX);
Tst_ComputeAndShowGrade (NumQsts,TotalScore,TsR_SCORE_MAX);
else
Ico_PutIconNotVisible ();
HTM_TD_End ();
@ -788,7 +791,7 @@ void TsR_ShowOneTstResult (void)
/***** Write answers and solutions *****/
TsR_ShowTestResult (&Gbl.Usrs.Other.UsrDat,
Gbl.Test.NumQsts,TstTimeUTC,
NumQsts,TstTimeUTC,
TstCfg_GetConfigVisibility ());
/***** End table *****/
@ -802,7 +805,7 @@ void TsR_ShowOneTstResult (void)
HTM_Double2Decimals (TotalScore);
HTM_BR ();
HTM_TxtColonNBSP (Txt_Grade);
Tst_ComputeAndShowGrade (Gbl.Test.NumQsts,TotalScore,TsR_SCORE_MAX);
Tst_ComputeAndShowGrade (NumQsts,TotalScore,TsR_SCORE_MAX);
HTM_DIV_End ();
}
@ -943,6 +946,7 @@ void TsR_ShowTestResult (struct UsrData *UsrDat,
static void TsR_GetTestResultDataByTstCod (long TstCod,
bool *AllowTeachers,
time_t *TstTimeUTC,
unsigned *NumQsts,
unsigned *NumQstsNotBlank,
double *Score)
{
@ -975,8 +979,8 @@ static void TsR_GetTestResultDataByTstCod (long TstCod,
*TstTimeUTC = Dat_GetUNIXTimeFromStr (row[2]);
/* Get number of questions (row[3]) */
if (sscanf (row[3],"%u",&Gbl.Test.NumQsts) != 1)
Gbl.Test.NumQsts = 0;
if (sscanf (row[3],"%u",NumQsts) != 1)
*NumQsts = 0;
/* Get number of questions not blank (row[4]) */
if (sscanf (row[4],"%u",NumQstsNotBlank) != 1)
@ -1026,14 +1030,15 @@ void TsR_StoreOneTestResultQstInDB (long TstCod,long QstCod,unsigned NumQst,doub
/************ Get the questions of a test result from database ***************/
/*****************************************************************************/
static void TsR_GetTestResultQuestionsFromDB (long TstCod)
static unsigned TsR_GetTestResultQuestionsFromDB (long TstCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumQsts;
unsigned NumQst;
/***** Get questions of a test result from database *****/
Gbl.Test.NumQsts =
NumQsts =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get questions"
" of a test result",
"SELECT QstCod," // row[0]
@ -1045,7 +1050,7 @@ static void TsR_GetTestResultQuestionsFromDB (long TstCod)
/***** Get questions codes *****/
for (NumQst = 0;
NumQst < Gbl.Test.NumQsts;
NumQst < NumQsts;
NumQst++)
{
row = mysql_fetch_row (mysql_res);
@ -1070,6 +1075,8 @@ static void TsR_GetTestResultQuestionsFromDB (long TstCod)
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumQsts;
}
/*****************************************************************************/

View File

@ -46,7 +46,7 @@
void TsR_SelUsrsToViewUsrsTstResults (void);
void TsR_SelDatesToSeeMyTstResults (void);
void TsR_ShowMyTstResults (void);
long TsR_CreateTestResultInDB (bool AllowTeachers);
long TsR_CreateTestResultInDB (bool AllowTeachers,unsigned NumQsts);
void TsR_StoreScoreOfTestResultInDB (long TstCod,
unsigned NumQstsNotBlank,double Score);
void TsR_GetUsrsAndShowTstResults (void);