Version19.223.3

This commit is contained in:
acanas 2020-05-11 14:56:49 +02:00
parent 80cb083492
commit 377f4c00c2
6 changed files with 59 additions and 50 deletions

View File

@ -553,7 +553,7 @@ ps2pdf source.ps destination.pdf
#define JS_FILE "swad19.223.js"
/*
Version 19.223.4: May 11, 2020 Stored unique/multiple choice questions in exam print. (? lines)
Version 19.223.3: May 11, 2020 Fixed bug in test exam print, reported by Julio Ortega Lopera. (303043 lines)
Version 19.223.3: May 11, 2020 Fixed bug in test exam print, reported by Julio Ortega Lopera. (303050 lines)
Version 19.223.2: May 11, 2020 Stored T/F answers in exam print. (303034 lines)
Version 19.223.1: May 11, 2020 Code refactoring in exam print. Stored float and text answers. (303023 lines)
Version 19.223: May 11, 2020 Store int answer and refresh exam print. (303024 lines)

View File

@ -465,18 +465,17 @@ static void ExaPrn_GetPrintQuestionsFromDB (struct ExaPrn_Print *Print)
"SELECT exa_print_questions.QstCod," // row[0]
"exa_print_questions.SetCod," // row[1]
"tst_questions.AnsType," // row[2]
"exa_print_questions.Indexes," // row[3]
"exa_print_questions.Answers" // row[4]
" FROM exa_print_questions,tst_questions"
"exa_print_questions.Score," // row[3]
"exa_print_questions.Indexes," // row[4]
"exa_print_questions.Answers" // row[5]
" FROM exa_print_questions LEFT JOIN tst_questions"
" ON (exa_print_questions.QstCod=tst_questions.QstCod)"
" WHERE exa_print_questions.PrnCod=%ld"
" AND exa_print_questions.QstCod=tst_questions.QstCod"
" ORDER BY exa_print_questions.QstInd",
Print->PrnCod);
/***** Get questions *****/
// Some questions may be deleted, so the number of questions retrieved
// could be lower than the original number of questions in the exam print
if (NumQsts <= Print->NumQsts)
if (NumQsts == Print->NumQsts)
for (NumQst = 0;
NumQst < NumQsts;
NumQst++)
@ -494,12 +493,18 @@ static void ExaPrn_GetPrintQuestionsFromDB (struct ExaPrn_Print *Print)
/* Get answer type (row[2]) */
AnswerType = Tst_ConvertFromStrAnsTypDBToAnsTyp (row[2]);
/* Get indexes for this question (row[3]) */
Str_Copy (Print->PrintedQuestions[NumQst].StrIndexes,row[3],
/* Get score (row[3]) */
Str_SetDecimalPointToUS (); // To get the decimal point as a dot
if (sscanf (row[3],"%lf",&Print->PrintedQuestions[NumQst].Score) != 1)
Lay_ShowErrorAndExit ("Wrong question score.");
Str_SetDecimalPointToLocal (); // Return to local system
/* Get indexes for this question (row[4]) */
Str_Copy (Print->PrintedQuestions[NumQst].StrIndexes,row[4],
Tst_MAX_BYTES_INDEXES_ONE_QST);
/* Get answers selected by user for this question (row[4]) */
Str_Copy (Print->PrintedQuestions[NumQst].StrAnswers,row[4],
/* Get answers selected by user for this question (row[5]) */
Str_Copy (Print->PrintedQuestions[NumQst].StrAnswers,row[5],
Tst_MAX_BYTES_ANSWERS_ONE_QST);
/* Replace each comma by a separator of multiple parameters */
@ -514,7 +519,7 @@ static void ExaPrn_GetPrintQuestionsFromDB (struct ExaPrn_Print *Print)
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
if (NumQsts > Print->NumQsts)
if (NumQsts != Print->NumQsts)
Lay_WrongExamExit ();
}

View File

@ -3218,7 +3218,7 @@ static void Fig_GetAndShowTestsStats (void)
}
/***** Get the stats about test questions from this location *****/
Tst_GetTestStats (Tst_ANS_ALL,&Stats);
Tst_GetTestStats (Tst_ANS_UNKNOWN,&Stats);
/***** Write number of assignments *****/
HTM_TR_Begin (NULL);

View File

@ -4972,8 +4972,7 @@ Tst_AnswerType_t Tst_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeBD)
if (!strcmp (StrAnsTypeBD,Tst_StrAnswerTypesDB[AnsType]))
return AnsType;
Lay_ShowErrorAndExit ("Wrong type of answer. 1");
return (Tst_AnswerType_t) 0; // Not reached
return Tst_ANS_UNKNOWN;
}
/*****************************************************************************/
@ -5059,9 +5058,9 @@ static void Tst_GetQstFromForm (struct Tst_Question *Question)
Par_GetParToUnsignedLong ("AnswerType",
0,
Tst_NUM_ANS_TYPES - 1,
(unsigned long) Tst_ANS_ALL);
if (Question->Answer.Type == Tst_ANS_ALL)
Lay_ShowErrorAndExit ("Wrong type of answer. 4");
(unsigned long) Tst_ANS_UNKNOWN);
if (Question->Answer.Type == Tst_ANS_UNKNOWN)
Lay_ShowErrorAndExit ("Wrong type of answer.");
/***** Get question tags *****/
for (NumTag = 0;
@ -6383,7 +6382,7 @@ static unsigned Tst_GetNumTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsTy
switch (Scope)
{
case Hie_SYS:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM tst_questions");
@ -6395,7 +6394,7 @@ static unsigned Tst_GetNumTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsTy
Tst_StrAnswerTypesDB[AnsType]);
break;
case Hie_CTY:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM institutions,centres,degrees,courses,tst_questions"
@ -6419,7 +6418,7 @@ static unsigned Tst_GetNumTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsTy
Tst_StrAnswerTypesDB[AnsType]);
break;
case Hie_INS:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM centres,degrees,courses,tst_questions"
@ -6441,7 +6440,7 @@ static unsigned Tst_GetNumTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsTy
Tst_StrAnswerTypesDB[AnsType]);
break;
case Hie_CTR:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM degrees,courses,tst_questions"
@ -6461,7 +6460,7 @@ static unsigned Tst_GetNumTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsTy
Tst_StrAnswerTypesDB[AnsType]);
break;
case Hie_DEG:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM courses,tst_questions"
@ -6479,7 +6478,7 @@ static unsigned Tst_GetNumTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsTy
Tst_StrAnswerTypesDB[AnsType]);
break;
case Hie_CRS:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM tst_questions"
@ -6541,7 +6540,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Level_t Scope,Tst_AnswerT
switch (Scope)
{
case Hie_SYS:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT CrsCod)"
@ -6555,7 +6554,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Level_t Scope,Tst_AnswerT
Tst_StrAnswerTypesDB[AnsType]);
break;
case Hie_CTY:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
@ -6581,7 +6580,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Level_t Scope,Tst_AnswerT
Tst_StrAnswerTypesDB[AnsType]);
break;
case Hie_INS:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
@ -6605,7 +6604,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Level_t Scope,Tst_AnswerT
Tst_StrAnswerTypesDB[AnsType]);
break;
case Hie_CTR:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
@ -6627,7 +6626,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Level_t Scope,Tst_AnswerT
Tst_StrAnswerTypesDB[AnsType]);
break;
case Hie_DEG:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNTDISTINCT (tst_questions.CrsCod)"
@ -6647,7 +6646,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Level_t Scope,Tst_AnswerT
Tst_StrAnswerTypesDB[AnsType]);
break;
case Hie_CRS:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT CrsCod)"
@ -6697,7 +6696,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Level_t Scope,Ts
switch (Scope)
{
case Hie_SYS:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
@ -6717,7 +6716,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Level_t Scope,Ts
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
break;
case Hie_CTY:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
@ -6749,7 +6748,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Level_t Scope,Ts
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
break;
case Hie_INS:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
@ -6779,7 +6778,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Level_t Scope,Ts
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
break;
case Hie_CTR:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
@ -6807,7 +6806,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Level_t Scope,Ts
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
break;
case Hie_DEG:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
@ -6833,7 +6832,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Level_t Scope,Ts
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
break;
case Hie_CRS:
if (AnsType == Tst_ANS_ALL)
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"

View File

@ -2274,18 +2274,17 @@ void TstPrn_GetPrintQuestionsFromDB (struct TstPrn_Print *Print)
" of a test exam",
"SELECT tst_exam_questions.QstCod," // row[0]
"tst_questions.AnsType," // row[1]
"tst_exam_questions.Indexes," // row[2]
"tst_exam_questions.Answers" // row[3]
" FROM tst_exam_questions,tst_questions"
"tst_exam_questions.Score," // row[2]
"tst_exam_questions.Indexes," // row[3]
"tst_exam_questions.Answers" // row[4]
" FROM tst_exam_questions LEFT JOIN tst_questions"
" ON (tst_exam_questions.QstCod=tst_questions.QstCod)"
" WHERE tst_exam_questions.ExaCod=%ld"
" AND tst_exam_questions.QstCod=tst_questions.QstCod"
" ORDER BY tst_exam_questions.QstInd",
Print->PrnCod);
/***** Get questions *****/
// Some questions may be deleted, so the number of questions retrieved
// could be lower than the original number of questions in the exam print
if (NumQsts <= Print->NumQsts)
if (NumQsts == Print->NumQsts)
for (NumQst = 0;
NumQst < NumQsts;
NumQst++)
@ -2299,12 +2298,18 @@ void TstPrn_GetPrintQuestionsFromDB (struct TstPrn_Print *Print)
/* Get answer type (row[1]) */
AnswerType = Tst_ConvertFromStrAnsTypDBToAnsTyp (row[1]);
/* Get indexes for this question (row[2]) */
Str_Copy (Print->PrintedQuestions[NumQst].StrIndexes,row[2],
/* Get score (row[2]) */
Str_SetDecimalPointToUS (); // To get the decimal point as a dot
if (sscanf (row[2],"%lf",&Print->PrintedQuestions[NumQst].Score) != 1)
Lay_ShowErrorAndExit ("Wrong question score.");
Str_SetDecimalPointToLocal (); // Return to local system
/* Get indexes for this question (row[3]) */
Str_Copy (Print->PrintedQuestions[NumQst].StrIndexes,row[3],
Tst_MAX_BYTES_INDEXES_ONE_QST);
/* Get answers selected by user for this question (row[3]) */
Str_Copy (Print->PrintedQuestions[NumQst].StrAnswers,row[3],
/* Get answers selected by user for this question (row[4]) */
Str_Copy (Print->PrintedQuestions[NumQst].StrAnswers,row[4],
Tst_MAX_BYTES_ANSWERS_ONE_QST);
/* Replace each comma by a separator of multiple parameters */
@ -2319,7 +2324,7 @@ void TstPrn_GetPrintQuestionsFromDB (struct TstPrn_Print *Print)
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
if (NumQsts > Print->NumQsts)
if (NumQsts != Print->NumQsts)
Lay_WrongExamExit ();
}

View File

@ -68,7 +68,7 @@ typedef enum
Tst_ANS_UNIQUE_CHOICE = 3,
Tst_ANS_MULTIPLE_CHOICE = 4,
Tst_ANS_TEXT = 5,
Tst_ANS_ALL = 6, // All/any type of answer
Tst_ANS_UNKNOWN = 6, // Unknown/all/any type of answer
} Tst_AnswerType_t;
struct Tst_Question