Version19.162

This commit is contained in:
acanas 2020-04-04 19:20:50 +02:00
parent d567240d06
commit a4e2997f75
7 changed files with 102 additions and 140 deletions

View File

@ -497,7 +497,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD: En OpenSWAD:
ps2pdf source.ps destination.pdf ps2pdf source.ps destination.pdf
*/ */
#define Log_PLATFORM_VERSION "SWAD 19.161 (2020-04-04)" #define Log_PLATFORM_VERSION "SWAD 19.162 (2020-04-04)"
#define CSS_FILE "swad19.146.css" #define CSS_FILE "swad19.146.css"
#define JS_FILE "swad19.153.js" #define JS_FILE "swad19.153.js"
/* /*
@ -527,8 +527,8 @@ Param
// TODO: Miguel Damas: al principio de los exámenes tendría que poner cuánto resta cada pregunta // TODO: Miguel Damas: al principio de los exámenes tendría que poner cuánto resta cada pregunta
// TODO: Oresti Baños: cambiar ojos por candados en descriptores para prohibir/permitir y dejar los ojos para poder elegir descriptores // TODO: Oresti Baños: cambiar ojos por candados en descriptores para prohibir/permitir y dejar los ojos para poder elegir descriptores
// TODO: Integrar pull requests con traducciones del alemán del usuario eruedin en GitHub // TODO: Integrar pull requests con traducciones del alemán del usuario eruedin en GitHub
// TODO: Integrar Stem y Feedback en question, creando espacio con malloc como en las respuestas
Version 19.162: Apr 04, 2020 Code refactoring in tests. (284492 lines)
Version 19.161: Apr 04, 2020 Code refactoring in tests. (284529 lines) Version 19.161: Apr 04, 2020 Code refactoring in tests. (284529 lines)
Version 19.160.1: Apr 03, 2020 Score calculated is removed from each test question. (284817 lines) Version 19.160.1: Apr 03, 2020 Score calculated is removed from each test question. (284817 lines)
Version 19.160: Apr 03, 2020 The score for each test question displayed in an exam is the one stored in the database instead of being calculated. Version 19.160: Apr 03, 2020 The score for each test question displayed in an exam is the one stored in the database instead of being calculated.

View File

@ -157,7 +157,6 @@ static void Gam_ListOneOrMoreQuestionsForEdition (long GamCod,unsigned NumQsts,
MYSQL_RES *mysql_res, MYSQL_RES *mysql_res,
bool ICanEditQuestions); bool ICanEditQuestions);
static void Gam_ListQuestionForEdition (const struct Tst_Question *Question, static void Gam_ListQuestionForEdition (const struct Tst_Question *Question,
const char *Stem,const char *Feedback,
unsigned QstInd,bool QuestionExists); unsigned QstInd,bool QuestionExists);
static void Gam_PutIconToAddNewQuestions (void *Args); static void Gam_PutIconToAddNewQuestions (void *Args);
static void Gam_PutButtonToAddNewQuestions (void); static void Gam_PutButtonToAddNewQuestions (void);
@ -1912,8 +1911,6 @@ static void Gam_ListOneOrMoreQuestionsForEdition (long GamCod,unsigned NumQsts,
unsigned NumQst; unsigned NumQst;
MYSQL_ROW row; MYSQL_ROW row;
struct Tst_Question Question; struct Tst_Question Question;
char Stem[Cns_MAX_BYTES_TEXT + 1];
char Feedback[Cns_MAX_BYTES_TEXT + 1];
unsigned QstInd; unsigned QstInd;
unsigned MaxQstInd; unsigned MaxQstInd;
char StrQstInd[Cns_MAX_DECIMAL_DIGITS_UINT + 1]; char StrQstInd[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
@ -2014,8 +2011,8 @@ static void Gam_ListOneOrMoreQuestionsForEdition (long GamCod,unsigned NumQsts,
HTM_TD_End (); HTM_TD_End ();
/***** Question *****/ /***** Question *****/
QuestionExists = Tst_GetQstDataFromDB (&Question,Stem,Feedback); QuestionExists = Tst_GetQstDataFromDB (&Question);
Gam_ListQuestionForEdition (&Question,Stem,Feedback,QstInd,QuestionExists); Gam_ListQuestionForEdition (&Question,QstInd,QuestionExists);
HTM_TR_End (); HTM_TR_End ();
@ -2032,7 +2029,6 @@ static void Gam_ListOneOrMoreQuestionsForEdition (long GamCod,unsigned NumQsts,
/*****************************************************************************/ /*****************************************************************************/
static void Gam_ListQuestionForEdition (const struct Tst_Question *Question, static void Gam_ListQuestionForEdition (const struct Tst_Question *Question,
const char *Stem,const char *Feedback,
unsigned QstInd,bool QuestionExists) unsigned QstInd,bool QuestionExists)
{ {
extern const char *Txt_Question_removed; extern const char *Txt_Question_removed;
@ -2060,7 +2056,7 @@ static void Gam_ListQuestionForEdition (const struct Tst_Question *Question,
if (QuestionExists) if (QuestionExists)
{ {
/* Write stem */ /* Write stem */
Tst_WriteQstStem (Stem,"TEST_EDI", Tst_WriteQstStem (Question->Stem,"TEST_EDI",
true); // Visible true); // Visible
/* Show media */ /* Show media */
@ -2069,7 +2065,7 @@ static void Gam_ListQuestionForEdition (const struct Tst_Question *Question,
"TEST_MED_EDIT_LIST_STEM"); "TEST_MED_EDIT_LIST_STEM");
/* Show feedback */ /* Show feedback */
Tst_WriteQstFeedback (Feedback,"TEST_EDI_LIGHT"); Tst_WriteQstFeedback (Question->Feedback,"TEST_EDI_LIGHT");
/* Show answers */ /* Show answers */
Tst_WriteAnswersListing (Question); Tst_WriteAnswersListing (Question);

View File

@ -2890,8 +2890,6 @@ static void Mch_ShowQuestionAndAnswersTch (const struct Match *Match)
extern const char *Txt_MATCH_Paused; extern const char *Txt_MATCH_Paused;
extern const char *Txt_Question_removed; extern const char *Txt_Question_removed;
struct Tst_Question Question; struct Tst_Question Question;
char Stem[Cns_MAX_BYTES_TEXT + 1];
char Feedback[Cns_MAX_BYTES_TEXT + 1];
/***** Create test question *****/ /***** Create test question *****/
Tst_QstConstructor (&Question); Tst_QstConstructor (&Question);
@ -2908,7 +2906,7 @@ static void Mch_ShowQuestionAndAnswersTch (const struct Match *Match)
} }
/***** Get data of question from database *****/ /***** Get data of question from database *****/
if (Tst_GetQstDataFromDB (&Question,Stem,Feedback)) if (Tst_GetQstDataFromDB (&Question))
{ {
/***** Show question *****/ /***** Show question *****/
/* Check answer type */ /* Check answer type */
@ -2919,7 +2917,7 @@ static void Mch_ShowQuestionAndAnswersTch (const struct Match *Match)
HTM_DIV_Begin ("class=\"MCH_BOTTOM\""); // Bottom HTM_DIV_Begin ("class=\"MCH_BOTTOM\""); // Bottom
/* Write stem */ /* Write stem */
Tst_WriteQstStem (Stem,"MCH_TCH_STEM", Tst_WriteQstStem (Question.Stem,"MCH_TCH_STEM",
true); // Visible true); // Visible
/* Show media */ /* Show media */

View File

@ -151,8 +151,7 @@ static void Tst_ShowTestExamToFillIt (struct TstExa_Exam *Exam,
static void Tst_WriteQstAndAnsSeeing (const struct TstExa_Exam *Exam, static void Tst_WriteQstAndAnsSeeing (const struct TstExa_Exam *Exam,
unsigned NumQst, unsigned NumQst,
const struct Tst_Question *Question, const struct Tst_Question *Question);
const char *Stem);
static void Tst_PutFormToEditQstMedia (const struct Media *Media,int NumMediaInForm, static void Tst_PutFormToEditQstMedia (const struct Media *Media,int NumMediaInForm,
bool OptionsDisabled); bool OptionsDisabled);
@ -230,9 +229,7 @@ static unsigned Tst_GetParamNumQsts (void);
static unsigned Tst_CountNumTagsInList (const struct Tst_Tags *Tags); static unsigned Tst_CountNumTagsInList (const struct Tst_Tags *Tags);
static int Tst_CountNumAnswerTypesInList (const struct Tst_AnswerTypes *AnswerTypes); static int Tst_CountNumAnswerTypesInList (const struct Tst_AnswerTypes *AnswerTypes);
static void Tst_PutFormEditOneQst (struct Tst_Question *Question, static void Tst_PutFormEditOneQst (struct Tst_Question *Question);
char Stem[Cns_MAX_BYTES_TEXT + 1],
char Feedback[Cns_MAX_BYTES_TEXT + 1]);
static void Tst_PutFloatInputField (const char *Label,const char *Field, static void Tst_PutFloatInputField (const char *Label,const char *Field,
const struct Tst_Question *Question, const struct Tst_Question *Question,
unsigned Index); unsigned Index);
@ -250,8 +247,7 @@ static void Tst_GetMediaFromDB (long CrsCod,long QstCod,int NumOpt,
struct Media *Media); struct Media *Media);
static Tst_AnswerType_t Tst_ConvertFromUnsignedStrToAnsTyp (const char *UnsignedStr); static Tst_AnswerType_t Tst_ConvertFromUnsignedStrToAnsTyp (const char *UnsignedStr);
static void Tst_GetQstFromForm (struct Tst_Question *Question, static void Tst_GetQstFromForm (struct Tst_Question *Question);
char *Stem,char *Feedback);
static void Tst_MoveMediaToDefinitiveDirectories (struct Tst_Question *Question); static void Tst_MoveMediaToDefinitiveDirectories (struct Tst_Question *Question);
static long Tst_GetTagCodFromTagTxt (const char *TagTxt); static long Tst_GetTagCodFromTagTxt (const char *TagTxt);
@ -867,8 +863,6 @@ static void Tst_ShowTestExamToFillIt (struct TstExa_Exam *Exam,
extern const char *Txt_Test; extern const char *Txt_Test;
unsigned NumQst; unsigned NumQst;
struct Tst_Question Question; struct Tst_Question Question;
char Stem[Cns_MAX_BYTES_TEXT + 1];
char Feedback[Cns_MAX_BYTES_TEXT + 1];
static const Act_Action_t Action[Tst_NUM_REQUEST_OR_CONFIRM] = static const Act_Action_t Action[Tst_NUM_REQUEST_OR_CONFIRM] =
{ {
[Tst_REQUEST] = ActReqAssTst, [Tst_REQUEST] = ActReqAssTst,
@ -906,11 +900,11 @@ static void Tst_ShowTestExamToFillIt (struct TstExa_Exam *Exam,
Question.QstCod = Exam->Questions[NumQst].QstCod; Question.QstCod = Exam->Questions[NumQst].QstCod;
/* Show question */ /* Show question */
if (!Tst_GetQstDataFromDB (&Question,Stem,Feedback)) // Question exists if (!Tst_GetQstDataFromDB (&Question)) // Question exists
Lay_ShowErrorAndExit ("Wrong question."); Lay_ShowErrorAndExit ("Wrong question.");
/* Write question and answers */ /* Write question and answers */
Tst_WriteQstAndAnsSeeing (Exam,NumQst,&Question,Stem); Tst_WriteQstAndAnsSeeing (Exam,NumQst,&Question);
/* Destroy test question */ /* Destroy test question */
Tst_QstDestructor (&Question); Tst_QstDestructor (&Question);
@ -976,8 +970,7 @@ void Tst_ShowTagList (unsigned NumTags,MYSQL_RES *mysql_res)
static void Tst_WriteQstAndAnsSeeing (const struct TstExa_Exam *Exam, static void Tst_WriteQstAndAnsSeeing (const struct TstExa_Exam *Exam,
unsigned NumQst, unsigned NumQst,
const struct Tst_Question *Question, const struct Tst_Question *Question)
const char *Stem)
{ {
/***** Begin row *****/ /***** Begin row *****/
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
@ -995,7 +988,7 @@ static void Tst_WriteQstAndAnsSeeing (const struct TstExa_Exam *Exam,
Tst_WriteParamQstCod (NumQst,Question->QstCod); Tst_WriteParamQstCod (NumQst,Question->QstCod);
/* Stem */ /* Stem */
Tst_WriteQstStem (Stem,"TEST_EXA",true); Tst_WriteQstStem (Question->Stem,"TEST_EXA",true);
/* Media */ /* Media */
Med_ShowMedia (&Question->Media, Med_ShowMedia (&Question->Media,
@ -1049,23 +1042,26 @@ void Tst_WriteQstStem (const char *Stem,const char *ClassStem,bool Visible)
HTM_DIV_Begin ("class=\"%s\"",ClassStem); HTM_DIV_Begin ("class=\"%s\"",ClassStem);
/***** Write stem *****/ /***** Write stem *****/
if (Visible) if (Stem && Visible)
{ {
/* Convert the stem, that is in HTML, to rigorous HTML */ if (Stem[0])
StemLength = strlen (Stem) * Str_MAX_BYTES_PER_CHAR; {
if ((StemRigorousHTML = (char *) malloc (StemLength + 1)) == NULL) /* Convert the stem, that is in HTML, to rigorous HTML */
Lay_NotEnoughMemoryExit (); StemLength = strlen (Stem) * Str_MAX_BYTES_PER_CHAR;
Str_Copy (StemRigorousHTML,Stem, if ((StemRigorousHTML = (char *) malloc (StemLength + 1)) == NULL)
StemLength); Lay_NotEnoughMemoryExit ();
Str_Copy (StemRigorousHTML,Stem,
StemLength);
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
StemRigorousHTML,StemLength,false); StemRigorousHTML,StemLength,false);
/* Write stem text */ /* Write stem text */
HTM_Txt (StemRigorousHTML); HTM_Txt (StemRigorousHTML);
/* Free memory allocated for the stem */ /* Free memory allocated for the stem */
free (StemRigorousHTML); free (StemRigorousHTML);
}
} }
else else
Ico_PutIconNotVisible (); Ico_PutIconNotVisible ();
@ -2806,11 +2802,9 @@ static void Tst_WriteQuestionListing (struct Tst_Test *Test,unsigned NumQst)
{ {
static unsigned UniqueId = 0; static unsigned UniqueId = 0;
char *Id; char *Id;
char Stem[Cns_MAX_BYTES_TEXT + 1];
char Feedback[Cns_MAX_BYTES_TEXT + 1];
/***** Get and show question data *****/ /***** Get and show question data *****/
if (Tst_GetQstDataFromDB (&Test->Question,Stem,Feedback)) if (Tst_GetQstDataFromDB (&Test->Question))
{ {
/***** Begin table row *****/ /***** Begin table row *****/
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
@ -2883,7 +2877,7 @@ static void Tst_WriteQuestionListing (struct Tst_Test *Test,unsigned NumQst)
/* Stem (row[3]) */ /* Stem (row[3]) */
HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd); HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd);
Tst_WriteQstStem (Stem,"TEST_EDI", Tst_WriteQstStem (Test->Question.Stem,"TEST_EDI",
true); // Visible true); // Visible
/***** Get and show media (row[5]) *****/ /***** Get and show media (row[5]) *****/
@ -2892,7 +2886,7 @@ static void Tst_WriteQuestionListing (struct Tst_Test *Test,unsigned NumQst)
"TEST_MED_EDIT_LIST"); "TEST_MED_EDIT_LIST");
/* Feedback (row[4]) and answers */ /* Feedback (row[4]) and answers */
Tst_WriteQstFeedback (Feedback,"TEST_EDI_LIGHT"); Tst_WriteQstFeedback (Test->Question.Feedback,"TEST_EDI_LIGHT");
Tst_WriteAnswersListing (&Test->Question); Tst_WriteAnswersListing (&Test->Question);
HTM_TD_End (); HTM_TD_End ();
@ -2904,7 +2898,8 @@ static void Tst_WriteQuestionListing (struct Tst_Test *Test,unsigned NumQst)
/* Average score */ /* Average score */
HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd); HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd);
if (Test->Question.NumHits) if (Test->Question.NumHits)
HTM_Double2Decimals (Test->Question.Score / (double) Test->Question.NumHits); HTM_Double2Decimals (Test->Question.Score /
(double) Test->Question.NumHits);
else else
HTM_Txt ("N.A."); HTM_Txt ("N.A.");
HTM_TD_End (); HTM_TD_End ();
@ -2917,7 +2912,8 @@ static void Tst_WriteQuestionListing (struct Tst_Test *Test,unsigned NumQst)
/* Average score (not blank) */ /* Average score (not blank) */
HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd); HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd);
if (Test->Question.NumHitsNotBlank) if (Test->Question.NumHitsNotBlank)
HTM_Double2Decimals (Test->Question.Score / (double) Test->Question.NumHitsNotBlank); HTM_Double2Decimals (Test->Question.Score /
(double) Test->Question.NumHitsNotBlank);
else else
HTM_Txt ("N.A."); HTM_Txt ("N.A.");
HTM_TD_End (); HTM_TD_End ();
@ -3016,13 +3012,11 @@ static void Tst_WriteQuestionRowForSelection (unsigned NumQst,
struct Tst_Question *Question) struct Tst_Question *Question)
{ {
extern const char *Txt_TST_STR_ANSWER_TYPES[Tst_NUM_ANS_TYPES]; extern const char *Txt_TST_STR_ANSWER_TYPES[Tst_NUM_ANS_TYPES];
char Stem[Cns_MAX_BYTES_TEXT + 1];
char Feedback[Cns_MAX_BYTES_TEXT + 1];
static unsigned UniqueId = 0; static unsigned UniqueId = 0;
char *Id; char *Id;
/***** Get and show questvoidion data *****/ /***** Get and show questvoidion data *****/
if (Tst_GetQstDataFromDB (Question,Stem,Feedback)) if (Tst_GetQstDataFromDB (Question))
{ {
/***** Begin table row *****/ /***** Begin table row *****/
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
@ -3076,7 +3070,7 @@ static void Tst_WriteQuestionRowForSelection (unsigned NumQst,
/* Write stem */ /* Write stem */
HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd); HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd);
Tst_WriteQstStem (Stem,"TEST_EDI", Tst_WriteQstStem (Question->Stem,"TEST_EDI",
true); // Visible true); // Visible
/***** Get and show media *****/ /***** Get and show media *****/
@ -3085,7 +3079,7 @@ static void Tst_WriteQuestionRowForSelection (unsigned NumQst,
"TEST_MED_EDIT_LIST"); "TEST_MED_EDIT_LIST");
/* Write feedback */ /* Write feedback */
Tst_WriteQstFeedback (Feedback,"TEST_EDI_LIGHT"); Tst_WriteQstFeedback (Question->Feedback,"TEST_EDI_LIGHT");
/* Write answers */ /* Write answers */
Tst_WriteAnswersListing (Question); Tst_WriteAnswersListing (Question);
@ -3837,8 +3831,6 @@ void Tst_ShowFormEditOneQst (void)
{ {
extern const char *Txt_Question_removed; extern const char *Txt_Question_removed;
struct Tst_Question Question; struct Tst_Question Question;
char Stem[Cns_MAX_BYTES_TEXT + 1];
char Feedback[Cns_MAX_BYTES_TEXT + 1];
bool PutFormToEditQuestion; bool PutFormToEditQuestion;
/***** Create test question *****/ /***** Create test question *****/
@ -3846,15 +3838,14 @@ void Tst_ShowFormEditOneQst (void)
/***** Get question data *****/ /***** Get question data *****/
Question.QstCod = Tst_GetQstCod (); Question.QstCod = Tst_GetQstCod ();
Stem[0] = Feedback[0] = '\0';
if (Question.QstCod > 0) // Question already exists in the database if (Question.QstCod > 0) // Question already exists in the database
PutFormToEditQuestion = Tst_GetQstDataFromDB (&Question,Stem,Feedback); PutFormToEditQuestion = Tst_GetQstDataFromDB (&Question);
else // New question else // New question
PutFormToEditQuestion = true; PutFormToEditQuestion = true;
/***** Put form to edit question *****/ /***** Put form to edit question *****/
if (PutFormToEditQuestion) if (PutFormToEditQuestion)
Tst_PutFormEditOneQst (&Question,Stem,Feedback); Tst_PutFormEditOneQst (&Question);
else else
Ale_ShowAlert (Ale_WARNING,Txt_Question_removed); Ale_ShowAlert (Ale_WARNING,Txt_Question_removed);
@ -3871,9 +3862,7 @@ void Tst_ShowFormEditOneQst (void)
// 2. By clicking "Edit" icon in a listing of existing questions // 2. By clicking "Edit" icon in a listing of existing questions
// 3. From the action associated to reception of a question, on error in the parameters received from the form // 3. From the action associated to reception of a question, on error in the parameters received from the form
static void Tst_PutFormEditOneQst (struct Tst_Question *Question, static void Tst_PutFormEditOneQst (struct Tst_Question *Question)
char Stem[Cns_MAX_BYTES_TEXT + 1],
char Feedback[Cns_MAX_BYTES_TEXT + 1])
{ {
extern const char *Hlp_ASSESSMENT_Tests_writing_a_question; extern const char *Hlp_ASSESSMENT_Tests_writing_a_question;
extern const char *The_ClassFormInBox[The_NUM_THEMES]; extern const char *The_ClassFormInBox[The_NUM_THEMES];
@ -4030,7 +4019,7 @@ static void Tst_PutFormEditOneQst (struct Tst_Question *Question,
HTM_TD_Begin ("class=\"LT\""); HTM_TD_Begin ("class=\"LT\"");
HTM_TEXTAREA_Begin ("id=\"Stem\" name=\"Stem\" class=\"STEM_TEXTAREA\"" HTM_TEXTAREA_Begin ("id=\"Stem\" name=\"Stem\" class=\"STEM_TEXTAREA\""
" rows=\"5\" required=\"required\""); " rows=\"5\" required=\"required\"");
HTM_Txt (Stem); HTM_Txt (Question->Stem);
HTM_TEXTAREA_End (); HTM_TEXTAREA_End ();
HTM_BR (); HTM_BR ();
Tst_PutFormToEditQstMedia (&Question->Media,-1, Tst_PutFormToEditQstMedia (&Question->Media,-1,
@ -4041,9 +4030,8 @@ static void Tst_PutFormEditOneQst (struct Tst_Question *Question,
HTM_TxtF ("%s (%s):",Txt_Feedback,Txt_optional); HTM_TxtF ("%s (%s):",Txt_Feedback,Txt_optional);
HTM_BR (); HTM_BR ();
HTM_TEXTAREA_Begin ("name=\"Feedback\" class=\"STEM_TEXTAREA\" rows=\"2\""); HTM_TEXTAREA_Begin ("name=\"Feedback\" class=\"STEM_TEXTAREA\" rows=\"2\"");
if (Feedback) if (Question->Feedback[0])
if (Feedback[0]) HTM_Txt (Question->Feedback);
HTM_Txt (Feedback);
HTM_TEXTAREA_End (); HTM_TEXTAREA_End ();
HTM_LABEL_End (); HTM_LABEL_End ();
HTM_TD_End (); HTM_TD_End ();
@ -4333,14 +4321,20 @@ void Tst_QstConstructor (struct Tst_Question *Question)
{ {
unsigned NumOpt; unsigned NumOpt;
/***** Reset question tags *****/
Tst_ResetTags (&Question->Tags); Tst_ResetTags (&Question->Tags);
/***** Reset edition time *****/
Question->EditTime = (time_t) 0; Question->EditTime = (time_t) 0;
Question->Stem.Text = NULL; /***** Allocate memory for stem and feedback *****/
Question->Stem.Length = 0; if ((Question->Stem = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Question->Feedback.Text = NULL; Lay_NotEnoughMemoryExit ();
Question->Feedback.Length = 0; Question->Stem[0] = '\0';
if ((Question->Feedback = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
Question->Feedback[0] = '\0';
/***** Initialize answers *****/ /***** Initialize answers *****/
Question->Answer.Type = Tst_ANS_UNIQUE_CHOICE; Question->Answer.Type = Tst_ANS_UNIQUE_CHOICE;
@ -4367,7 +4361,7 @@ void Tst_QstConstructor (struct Tst_Question *Question)
Question->Answer.FloatingPoint[0] = Question->Answer.FloatingPoint[0] =
Question->Answer.FloatingPoint[1] = 0.0; Question->Answer.FloatingPoint[1] = 0.0;
/* Initialize stats */ /***** Initialize stats *****/
Question->NumHits = Question->NumHits =
Question->NumHitsNotBlank = 0; Question->NumHitsNotBlank = 0;
Question->Score = 0.0; Question->Score = 0.0;
@ -4381,6 +4375,16 @@ void Tst_QstDestructor (struct Tst_Question *Question)
{ {
Tst_FreeTextChoiceAnswers (Question); Tst_FreeTextChoiceAnswers (Question);
Tst_FreeMediaOfQuestion (Question); Tst_FreeMediaOfQuestion (Question);
if (Question->Feedback)
{
free (Question->Feedback);
Question->Feedback = NULL;
}
if (Question->Stem)
{
free (Question->Stem);
Question->Stem = NULL;
}
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4508,9 +4512,7 @@ Tst_AnswerType_t Tst_GetQstAnswerType (long QstCod)
/****************** Get data of a question from database *********************/ /****************** Get data of a question from database *********************/
/*****************************************************************************/ /*****************************************************************************/
bool Tst_GetQstDataFromDB (struct Tst_Question *Question, bool Tst_GetQstDataFromDB (struct Tst_Question *Question)
char Stem[Cns_MAX_BYTES_TEXT + 1],
char Feedback[Cns_MAX_BYTES_TEXT + 1])
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
@ -4550,17 +4552,17 @@ bool Tst_GetQstDataFromDB (struct Tst_Question *Question,
Question->Answer.Shuffle = (row[2][0] == 'Y'); Question->Answer.Shuffle = (row[2][0] == 'Y');
/* Get the stem (row[3]) */ /* Get the stem (row[3]) */
Stem[0] = '\0'; Question->Stem[0] = '\0';
if (row[3]) if (row[3])
if (row[3][0]) if (row[3][0])
Str_Copy (Stem,row[3], Str_Copy (Question->Stem,row[3],
Cns_MAX_BYTES_TEXT); Cns_MAX_BYTES_TEXT);
/* Get the feedback (row[4]) */ /* Get the feedback (row[4]) */
Feedback[0] = '\0'; Question->Feedback[0] = '\0';
if (row[4]) if (row[4])
if (row[4][0]) if (row[4][0])
Str_Copy (Feedback,row[4], Str_Copy (Question->Feedback,row[4],
Cns_MAX_BYTES_TEXT); Cns_MAX_BYTES_TEXT);
/* Get media (row[5]) */ /* Get media (row[5]) */
@ -4782,15 +4784,12 @@ static Tst_AnswerType_t Tst_ConvertFromUnsignedStrToAnsTyp (const char *Unsigned
void Tst_ReceiveQst (void) void Tst_ReceiveQst (void)
{ {
struct Tst_Test Test; struct Tst_Test Test;
char Stem[Cns_MAX_BYTES_TEXT + 1];
char Feedback[Cns_MAX_BYTES_TEXT + 1];
/***** Create test *****/ /***** Create test *****/
Tst_TstConstructor (&Test); Tst_TstConstructor (&Test);
/***** Get parameters of the question from form *****/ /***** Get parameters of the question from form *****/
Stem[0] = Feedback[0] = '\0'; Tst_GetQstFromForm (&Test.Question);
Tst_GetQstFromForm (&Test.Question,Stem,Feedback);
/***** Make sure that tags, text and answer are not empty *****/ /***** Make sure that tags, text and answer are not empty *****/
if (Tst_CheckIfQstFormatIsCorrectAndCountNumOptions (&Test.Question)) if (Tst_CheckIfQstFormatIsCorrectAndCountNumOptions (&Test.Question))
@ -4813,7 +4812,7 @@ void Tst_ReceiveQst (void)
Tst_ResetMediaOfQuestion (&Test.Question); Tst_ResetMediaOfQuestion (&Test.Question);
/***** Put form to edit question again *****/ /***** Put form to edit question again *****/
Tst_PutFormEditOneQst (&Test.Question,Stem,Feedback); Tst_PutFormEditOneQst (&Test.Question);
} }
/***** Destroy test *****/ /***** Destroy test *****/
@ -4824,8 +4823,7 @@ void Tst_ReceiveQst (void)
/**************** Get parameters of a test question from form ****************/ /**************** Get parameters of a test question from form ****************/
/*****************************************************************************/ /*****************************************************************************/
static void Tst_GetQstFromForm (struct Tst_Question *Question, static void Tst_GetQstFromForm (struct Tst_Question *Question)
char *Stem,char *Feedback)
{ {
unsigned NumTag; unsigned NumTag;
unsigned NumTagRead; unsigned NumTagRead;
@ -4878,10 +4876,10 @@ static void Tst_GetQstFromForm (struct Tst_Question *Question,
} }
/***** Get question stem *****/ /***** Get question stem *****/
Par_GetParToHTML ("Stem",Stem,Cns_MAX_BYTES_TEXT); Par_GetParToHTML ("Stem",Question->Stem,Cns_MAX_BYTES_TEXT);
/***** Get question feedback *****/ /***** Get question feedback *****/
Par_GetParToHTML ("Feedback",Feedback,Cns_MAX_BYTES_TEXT); Par_GetParToHTML ("Feedback",Question->Feedback,Cns_MAX_BYTES_TEXT);
/***** Get media associated to the stem (action, file and title) *****/ /***** Get media associated to the stem (action, file and title) *****/
Question->Media.Width = Tst_IMAGE_SAVED_MAX_WIDTH; Question->Media.Width = Tst_IMAGE_SAVED_MAX_WIDTH;
@ -5015,10 +5013,6 @@ static void Tst_GetQstFromForm (struct Tst_Question *Question,
NumTag++) NumTag++)
if (Question->Tags.Txt[NumTag][0]) if (Question->Tags.Txt[NumTag][0])
Question->Tags.Num++; Question->Tags.Num++;
Question->Stem.Text = Stem;
Question->Stem.Length = strlen (Question->Stem.Text);
Question->Feedback.Text = Feedback;
Question->Feedback.Length = strlen (Question->Feedback.Text);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -5055,8 +5049,8 @@ bool Tst_CheckIfQstFormatIsCorrectAndCountNumOptions (struct Tst_Question *Quest
return false; return false;
} }
/***** A question must have a stem*****/ /***** A question must have a stem *****/
if (!Question->Stem.Length) if (!Question->Stem[0])
{ {
Ale_ShowAlert (Ale_WARNING,Txt_You_must_type_the_stem_of_the_question); Ale_ShowAlert (Ale_WARNING,Txt_You_must_type_the_stem_of_the_question);
return false; return false;
@ -5232,7 +5226,7 @@ bool Tst_CheckIfQuestionExistsInDB (struct Tst_Question *Question)
" WHERE CrsCod=%ld AND AnsType='%s' AND Stem='%s'", " WHERE CrsCod=%ld AND AnsType='%s' AND Stem='%s'",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Tst_StrAnswerTypesDB[Question->Answer.Type], Tst_StrAnswerTypesDB[Question->Answer.Type],
Question->Stem.Text); Question->Stem);
if (NumQstsWithThisStem) // There are questions in database with the same stem that the one of this question if (NumQstsWithThisStem) // There are questions in database with the same stem that the one of this question
{ {
@ -5819,8 +5813,8 @@ static void Tst_InsertOrUpdateQstIntoDB (struct Tst_Question *Question)
Tst_StrAnswerTypesDB[Question->Answer.Type], Tst_StrAnswerTypesDB[Question->Answer.Type],
Question->Answer.Shuffle ? 'Y' : Question->Answer.Shuffle ? 'Y' :
'N', 'N',
Question->Stem.Text, Question->Stem,
Question->Feedback.Text ? Question->Feedback.Text : Question->Feedback ? Question->Feedback :
"", "",
Question->Media.MedCod); Question->Media.MedCod);
} }
@ -5840,8 +5834,8 @@ static void Tst_InsertOrUpdateQstIntoDB (struct Tst_Question *Question)
Tst_StrAnswerTypesDB[Question->Answer.Type], Tst_StrAnswerTypesDB[Question->Answer.Type],
Question->Answer.Shuffle ? 'Y' : Question->Answer.Shuffle ? 'Y' :
'N', 'N',
Question->Stem.Text, Question->Stem,
Question->Feedback.Text ? Question->Feedback.Text : Question->Feedback ? Question->Feedback :
"", "",
Question->Media.MedCod, Question->Media.MedCod,
Question->QstCod,Gbl.Hierarchy.Crs.CrsCod); Question->QstCod,Gbl.Hierarchy.Crs.CrsCod);

View File

@ -95,11 +95,8 @@ struct Tst_Question
long QstCod; long QstCod;
struct Tst_Tags Tags; struct Tst_Tags Tags;
time_t EditTime; time_t EditTime;
struct char *Stem;
{ char *Feedback;
char *Text;
size_t Length;
} Stem, Feedback;
struct Media Media; struct Media Media;
struct struct
{ {
@ -202,9 +199,7 @@ void Tst_QstDestructor (struct Tst_Question *Question);
bool Tst_AllocateTextChoiceAnswer (struct Tst_Question *Question,unsigned NumOpt); bool Tst_AllocateTextChoiceAnswer (struct Tst_Question *Question,unsigned NumOpt);
Tst_AnswerType_t Tst_GetQstAnswerType (long QstCod); Tst_AnswerType_t Tst_GetQstAnswerType (long QstCod);
bool Tst_GetQstDataFromDB (struct Tst_Question *Question, bool Tst_GetQstDataFromDB (struct Tst_Question *Question);
char Stem[Cns_MAX_BYTES_TEXT + 1],
char Feedback[Cns_MAX_BYTES_TEXT + 1]);
Tst_AnswerType_t Tst_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeBD); Tst_AnswerType_t Tst_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeBD);
void Tst_ReceiveQst (void); void Tst_ReceiveQst (void);
bool Tst_CheckIfQstFormatIsCorrectAndCountNumOptions (struct Tst_Question *Question); bool Tst_CheckIfQstFormatIsCorrectAndCountNumOptions (struct Tst_Question *Question);

View File

@ -81,8 +81,6 @@ static void TstExa_WriteQstAndAnsExam (struct UsrData *UsrDat,
struct TstExa_Exam *Exam, struct TstExa_Exam *Exam,
unsigned NumQst, unsigned NumQst,
struct Tst_Question *Question, struct Tst_Question *Question,
const char *Stem,
const char *Feedback,
unsigned Visibility); unsigned Visibility);
static void TstExa_ComputeAnswerScore (struct TstExa_Exam *Exam, static void TstExa_ComputeAnswerScore (struct TstExa_Exam *Exam,
unsigned NumQst, unsigned NumQst,
@ -224,8 +222,6 @@ void TstExa_ShowExamAfterAssess (struct TstExa_Exam *Exam)
{ {
unsigned NumQst; unsigned NumQst;
struct Tst_Question Question; struct Tst_Question Question;
char Stem[Cns_MAX_BYTES_TEXT + 1];
char Feedback[Cns_MAX_BYTES_TEXT + 1];
/***** Begin table *****/ /***** Begin table *****/
HTM_TABLE_BeginWideMarginPadding (10); HTM_TABLE_BeginWideMarginPadding (10);
@ -245,12 +241,12 @@ void TstExa_ShowExamAfterAssess (struct TstExa_Exam *Exam)
Question.QstCod = Exam->Questions[NumQst].QstCod; Question.QstCod = Exam->Questions[NumQst].QstCod;
/***** Get question data *****/ /***** Get question data *****/
if (Tst_GetQstDataFromDB (&Question,Stem,Feedback)) // Question exists if (Tst_GetQstDataFromDB (&Question)) // Question exists
{ {
/***** Write question and answers *****/ /***** Write question and answers *****/
TstExa_WriteQstAndAnsExam (&Gbl.Usrs.Me.UsrDat, TstExa_WriteQstAndAnsExam (&Gbl.Usrs.Me.UsrDat,
Exam,NumQst, Exam,NumQst,
&Question,Stem,Feedback, &Question,
TstCfg_GetConfigVisibility ()); TstCfg_GetConfigVisibility ());
/***** Store test exam question in database *****/ /***** Store test exam question in database *****/
@ -282,8 +278,6 @@ static void TstExa_WriteQstAndAnsExam (struct UsrData *UsrDat,
struct TstExa_Exam *Exam, struct TstExa_Exam *Exam,
unsigned NumQst, unsigned NumQst,
struct Tst_Question *Question, struct Tst_Question *Question,
const char *Stem,
const char *Feedback,
unsigned Visibility) unsigned Visibility)
{ {
extern const char *Txt_Score; extern const char *Txt_Score;
@ -320,7 +314,7 @@ static void TstExa_WriteQstAndAnsExam (struct UsrData *UsrDat,
if (QuestionUneditedAfterExam) if (QuestionUneditedAfterExam)
{ {
/* Stem */ /* Stem */
Tst_WriteQstStem (Stem,"TEST_EXA",IsVisibleQstAndAnsTxt); Tst_WriteQstStem (Question->Stem,"TEST_EXA",IsVisibleQstAndAnsTxt);
/* Media */ /* Media */
if (IsVisibleQstAndAnsTxt) if (IsVisibleQstAndAnsTxt)
@ -356,7 +350,7 @@ static void TstExa_WriteQstAndAnsExam (struct UsrData *UsrDat,
/* Question feedback */ /* Question feedback */
if (QuestionUneditedAfterExam) if (QuestionUneditedAfterExam)
if (TstVis_IsVisibleFeedbackTxt (Visibility)) if (TstVis_IsVisibleFeedbackTxt (Visibility))
Tst_WriteQstFeedback (Feedback,"TEST_EXA_LIGHT"); Tst_WriteQstFeedback (Question->Feedback,"TEST_EXA_LIGHT");
HTM_TD_End (); HTM_TD_End ();
@ -2203,8 +2197,6 @@ void TstExa_ShowExamAnswers (struct UsrData *UsrDat,
{ {
unsigned NumQst; unsigned NumQst;
struct Tst_Question Question; struct Tst_Question Question;
char Stem[Cns_MAX_BYTES_TEXT + 1];
char Feedback[Cns_MAX_BYTES_TEXT + 1];
for (NumQst = 0; for (NumQst = 0;
NumQst < Exam->NumQsts; NumQst < Exam->NumQsts;
@ -2217,12 +2209,9 @@ void TstExa_ShowExamAnswers (struct UsrData *UsrDat,
Question.QstCod = Exam->Questions[NumQst].QstCod; Question.QstCod = Exam->Questions[NumQst].QstCod;
/***** Get question data *****/ /***** Get question data *****/
if (Tst_GetQstDataFromDB (&Question,Stem,Feedback)) // Question exists? if (Tst_GetQstDataFromDB (&Question)) // Question exists?
/***** Write questions and answers *****/ /***** Write questions and answers *****/
TstExa_WriteQstAndAnsExam (UsrDat, TstExa_WriteQstAndAnsExam (UsrDat,Exam,NumQst,&Question,Visibility);
Exam,NumQst,
&Question,Stem,Feedback,
Visibility);
/***** Destroy test question *****/ /***** Destroy test question *****/
Tst_QstDestructor (&Question); Tst_QstDestructor (&Question);

View File

@ -259,10 +259,8 @@ static void TsI_ExportQuestion (struct Tst_Question *Question,FILE *FileXML)
{ {
extern const char *Tst_StrAnswerTypesXML[Tst_NUM_ANS_TYPES]; extern const char *Tst_StrAnswerTypesXML[Tst_NUM_ANS_TYPES];
extern const char *Txt_NEW_LINE; extern const char *Txt_NEW_LINE;
char Stem[Cns_MAX_BYTES_TEXT + 1];
char Feedback[Cns_MAX_BYTES_TEXT + 1];
if (Tst_GetQstDataFromDB (Question,Stem,Feedback)) if (Tst_GetQstDataFromDB (Question))
{ {
/***** Write the answer type *****/ /***** Write the answer type *****/
fprintf (FileXML,"<question type=\"%s\">%s", fprintf (FileXML,"<question type=\"%s\">%s",
@ -275,12 +273,12 @@ static void TsI_ExportQuestion (struct Tst_Question *Question,FILE *FileXML)
/***** Write the stem, that is in HTML format *****/ /***** Write the stem, that is in HTML format *****/
fprintf (FileXML,"<stem>%s</stem>%s", fprintf (FileXML,"<stem>%s</stem>%s",
Stem,Txt_NEW_LINE); Question->Stem,Txt_NEW_LINE);
/***** Write the feedback, that is in HTML format *****/ /***** Write the feedback, that is in HTML format *****/
if (Feedback[0]) if (Question->Feedback[0])
fprintf (FileXML,"<feedback>%s</feedback>%s", fprintf (FileXML,"<feedback>%s</feedback>%s",
Feedback,Txt_NEW_LINE); Question->Feedback,Txt_NEW_LINE);
/***** Write the answers of this question. /***** Write the answers of this question.
Shuffle can be enabled or disabled *****/ Shuffle can be enabled or disabled *****/
@ -501,8 +499,6 @@ static void TsI_ImportQuestionsFromXMLBuffer (const char *XMLBuffer)
struct Tst_Question Question; struct Tst_Question Question;
bool QuestionExists; bool QuestionExists;
bool AnswerTypeFound; bool AnswerTypeFound;
char Stem[Cns_MAX_BYTES_TEXT + 1];
char Feedback[Cns_MAX_BYTES_TEXT + 1];
/***** Allocate and get XML tree *****/ /***** Allocate and get XML tree *****/
XML_GetTree (XMLBuffer,&RootElem); XML_GetTree (XMLBuffer,&RootElem);
@ -592,13 +588,10 @@ static void TsI_ImportQuestionsFromXMLBuffer (const char *XMLBuffer)
if (StemElem->Content) if (StemElem->Content)
{ {
/* Convert stem from text to HTML (in database stem is stored in HTML) */ /* Convert stem from text to HTML (in database stem is stored in HTML) */
Str_Copy (Stem,StemElem->Content, Str_Copy (Question.Stem,StemElem->Content,
Cns_MAX_BYTES_TEXT); Cns_MAX_BYTES_TEXT);
Str_ChangeFormat (Str_FROM_TEXT,Str_TO_HTML, Str_ChangeFormat (Str_FROM_TEXT,Str_TO_HTML,
Stem,Cns_MAX_BYTES_TEXT,true); Question.Stem,Cns_MAX_BYTES_TEXT,true);
Question.Stem.Text = Stem;
Question.Stem.Length = strlen (Stem);
} }
break; // Only first element "stem" break; // Only first element "stem"
} }
@ -612,13 +605,10 @@ static void TsI_ImportQuestionsFromXMLBuffer (const char *XMLBuffer)
if (FeedbackElem->Content) if (FeedbackElem->Content)
{ {
/* Convert feedback from text to HTML (in database feedback is stored in HTML) */ /* Convert feedback from text to HTML (in database feedback is stored in HTML) */
Str_Copy (Feedback,FeedbackElem->Content, Str_Copy (Question.Feedback,FeedbackElem->Content,
Cns_MAX_BYTES_TEXT); Cns_MAX_BYTES_TEXT);
Str_ChangeFormat (Str_FROM_TEXT,Str_TO_HTML, Str_ChangeFormat (Str_FROM_TEXT,Str_TO_HTML,
Feedback,Cns_MAX_BYTES_TEXT,true); Question.Feedback,Cns_MAX_BYTES_TEXT,true);
Question.Feedback.Text = Feedback;
Question.Feedback.Length = strlen (Feedback);
} }
break; // Only first element "feedback" break; // Only first element "feedback"
} }