swad-core/swad_test.c

7522 lines
261 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_test.c: self-assessment tests
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
2020-01-01 14:53:57 +01:00
Copyright (C) 1999-2020 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/*********************************** Headers *********************************/
/*****************************************************************************/
2019-11-01 22:53:39 +01:00
#define _GNU_SOURCE // For asprintf
2014-12-01 23:55:08 +01:00
#include <limits.h> // For UINT_MAX
#include <linux/limits.h> // For PATH_MAX
#include <mysql/mysql.h> // To access MySQL databases
2015-10-16 02:24:29 +02:00
#include <stdbool.h> // For boolean type
2019-12-29 12:39:00 +01:00
#include <stddef.h> // For NULL
2019-12-30 22:32:06 +01:00
#include <stdio.h> // For asprintf
2014-12-01 23:55:08 +01:00
#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"
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2014-12-01 23:55:08 +01:00
#include "swad_database.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2014-12-01 23:55:08 +01:00
#include "swad_ID.h"
2018-12-08 16:43:13 +01:00
#include "swad_language.h"
2019-09-14 12:59:34 +02:00
#include "swad_match.h"
2019-03-02 21:49:11 +01:00
#include "swad_media.h"
2014-12-01 23:55:08 +01:00
#include "swad_parameter.h"
#include "swad_theme.h"
#include "swad_test.h"
#include "swad_test_import.h"
2020-02-18 09:19:33 +01:00
#include "swad_test_visibility.h"
2014-12-01 23:55:08 +01:00
#include "swad_user.h"
#include "swad_xml.h"
/*****************************************************************************/
/***************************** Public constants ******************************/
/*****************************************************************************/
2017-03-08 03:48:23 +01:00
// strings are limited to Tst_MAX_BYTES_ANSWER_TYPE characters
2014-12-01 23:55:08 +01:00
const char *Tst_StrAnswerTypesXML[Tst_NUM_ANS_TYPES] =
{
2019-11-22 01:04:03 +01:00
[Tst_ANS_INT ] = "int",
[Tst_ANS_FLOAT ] = "float",
[Tst_ANS_TRUE_FALSE ] = "TF",
[Tst_ANS_UNIQUE_CHOICE ] = "uniqueChoice",
[Tst_ANS_MULTIPLE_CHOICE] = "multipleChoice",
[Tst_ANS_TEXT ] = "text",
2014-12-01 23:55:08 +01:00
};
/*****************************************************************************/
/**************************** Private constants ******************************/
/*****************************************************************************/
2017-01-28 15:58:46 +01:00
#define Tst_MAX_BYTES_TAGS_LIST (16 * 1024)
2014-12-01 23:55:08 +01:00
#define Tst_MAX_BYTES_FLOAT_ANSWER 30 // Maximum length of the strings that store an floating point answer
2019-12-15 20:02:34 +01:00
static const char *Tst_PluggableDB[Tst_NUM_OPTIONS_PLUGGABLE] =
2014-12-01 23:55:08 +01:00
{
2019-12-15 20:02:34 +01:00
[Tst_PLUGGABLE_UNKNOWN] = "unknown",
[Tst_PLUGGABLE_NO ] = "N",
[Tst_PLUGGABLE_YES ] = "Y",
2014-12-01 23:55:08 +01:00
};
2019-12-15 20:02:34 +01:00
static const char *Tst_StrAnswerTypesDB[Tst_NUM_ANS_TYPES] =
2014-12-01 23:55:08 +01:00
{
2019-12-15 20:02:34 +01:00
[Tst_ANS_INT ] = "int",
[Tst_ANS_FLOAT ] = "float",
[Tst_ANS_TRUE_FALSE ] = "true_false",
[Tst_ANS_UNIQUE_CHOICE ] = "unique_choice",
[Tst_ANS_MULTIPLE_CHOICE] = "multiple_choice",
[Tst_ANS_TEXT ] = "text",
2014-12-01 23:55:08 +01:00
};
2016-04-08 16:37:59 +02:00
// Test images will be saved with:
// - maximum width of Tst_IMAGE_SAVED_MAX_HEIGHT
// - maximum height of Tst_IMAGE_SAVED_MAX_HEIGHT
2016-04-01 13:37:49 +02:00
// - maintaining the original aspect ratio (aspect ratio recommended: 3:2)
2016-04-08 16:37:59 +02:00
#define Tst_IMAGE_SAVED_MAX_WIDTH 768
2020-02-13 22:33:31 +01:00
#define Tst_IMAGE_SAVED_MAX_HEIGHT 768
#define Tst_IMAGE_SAVED_QUALITY 90 // 1 to 100
2016-04-01 13:37:49 +02:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2019-11-21 16:47:07 +01:00
/******************************* Private types *******************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
#define Tst_NUM_STATUS 2
typedef enum
{
Tst_STATUS_SHOWN_BUT_NOT_ASSESSED = 0,
Tst_STATUS_ASSESSED = 1,
Tst_STATUS_ERROR = 2,
} Tst_Status_t;
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
2019-11-21 16:47:07 +01:00
/************************* Private global variables **************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*****************************************************************************/
2019-11-21 16:47:07 +01:00
/***************************** Private prototypes ****************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
static void Tst_GetQuestionsAndAnswersFromForm (void);
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);
2016-11-21 13:15:08 +01:00
static void Tst_ShowTestResultAfterAssess (long TstCod,unsigned *NumQstsNotBlank,double *TotalScore);
2019-03-02 21:49:11 +01:00
static void Tst_PutFormToEditQstMedia (struct Media *Media,int NumMediaInForm,
2016-04-05 10:47:36 +02:00
bool OptionsDisabled);
2019-11-11 00:15:44 +01:00
static void Tst_UpdateScoreQst (long QstCod,double ScoreThisQst,bool AnswerIsNotBlank);
2014-12-01 23:55:08 +01:00
static void Tst_UpdateMyNumAccessTst (unsigned NumAccessesTst);
static void Tst_UpdateLastAccTst (void);
2016-11-07 10:35:36 +01:00
static bool Tst_CheckIfICanEditTests (void);
static void Tst_PutIconsTests (void);
2017-09-07 12:00:01 +02:00
static void Tst_PutButtonToAddQuestion (void);
2014-12-01 23:55:08 +01:00
static long Tst_GetParamTagCode (void);
static bool Tst_CheckIfCurrentCrsHasTestTags (void);
static unsigned long Tst_GetAllTagsFromCurrentCrs (MYSQL_RES **mysql_res);
static unsigned long Tst_GetEnabledTagsFromThisCrs (MYSQL_RES **mysql_res);
2016-03-21 01:28:16 +01:00
static void Tst_ShowFormSelTags (unsigned long NumRows,MYSQL_RES *mysql_res,
2019-12-09 12:56:21 +01:00
bool ShowOnlyEnabledTags);
2014-12-01 23:55:08 +01:00
static void Tst_ShowFormEditTags (void);
static void Tst_PutIconEnable (long TagCod,const char *TagTxt);
static void Tst_PutIconDisable (long TagCod,const char *TagTxt);
static void Tst_ShowFormConfigTst (void);
2016-12-26 15:17:30 +01:00
static void Tst_PutInputFieldNumQst (const char *Field,const char *Label,
unsigned Value);
2014-12-01 23:55:08 +01:00
static Tst_Pluggable_t Tst_GetPluggableFromForm (void);
static void Tst_CheckAndCorrectNumbersQst (void);
2019-12-09 12:56:21 +01:00
static void Tst_ShowFormAnswerTypes (void);
2017-07-16 13:54:11 +02:00
static unsigned long Tst_GetQuestions (MYSQL_RES **mysql_res);
2016-11-21 13:15:08 +01:00
static unsigned long Tst_GetQuestionsForTest (MYSQL_RES **mysql_res);
2014-12-01 23:55:08 +01:00
static void Tst_ListOneQstToEdit (void);
2017-09-01 00:52:19 +02:00
static void Tst_ListOneOrMoreQuestionsForEdition (unsigned long NumRows,
MYSQL_RES *mysql_res);
2019-09-29 17:33:39 +02:00
static void Tst_ListOneOrMoreQuestionsForSelection (unsigned long NumRows,
2017-09-01 00:52:19 +02:00
MYSQL_RES *mysql_res);
2014-12-01 23:55:08 +01:00
2017-09-04 17:03:49 +02:00
static void Tst_WriteAnswersTestToAnswer (unsigned NumQst,long QstCod,bool Shuffle);
2018-12-09 13:11:20 +01:00
static void Tst_WriteAnswersTestResult (struct UsrData *UsrDat,
unsigned NumQst,long QstCod,
2020-02-17 23:15:08 +01:00
unsigned Visibility,
2017-09-04 17:03:49 +02:00
double *ScoreThisQst,bool *AnswerIsNotBlank);
static void Tst_WriteTFAnsViewTest (unsigned NumQst);
2018-12-09 13:11:20 +01:00
static void Tst_WriteTFAnsAssessTest (struct UsrData *UsrDat,
unsigned NumQst,MYSQL_RES *mysql_res,
2020-02-17 23:15:08 +01:00
unsigned Visibility,
2014-12-01 23:55:08 +01:00
double *ScoreThisQst,bool *AnswerIsNotBlank);
2017-09-04 17:03:49 +02:00
2016-11-21 13:15:08 +01:00
static void Tst_WriteChoiceAnsViewTest (unsigned NumQst,long QstCod,bool Shuffle);
2018-12-09 13:11:20 +01:00
static void Tst_WriteChoiceAnsAssessTest (struct UsrData *UsrDat,
unsigned NumQst,MYSQL_RES *mysql_res,
2020-02-17 23:15:08 +01:00
unsigned Visibility,
2014-12-01 23:55:08 +01:00
double *ScoreThisQst,bool *AnswerIsNotBlank);
2017-09-04 17:03:49 +02:00
2016-11-21 13:15:08 +01:00
static void Tst_WriteTextAnsViewTest (unsigned NumQst);
2018-12-09 13:11:20 +01:00
static void Tst_WriteTextAnsAssessTest (struct UsrData *UsrDat,
unsigned NumQst,MYSQL_RES *mysql_res,
2020-02-17 23:15:08 +01:00
unsigned Visibility,
2014-12-01 23:55:08 +01:00
double *ScoreThisQst,bool *AnswerIsNotBlank);
2017-09-04 17:03:49 +02:00
2016-11-21 13:15:08 +01:00
static void Tst_WriteIntAnsViewTest (unsigned NumQst);
2018-12-09 13:11:20 +01:00
static void Tst_WriteIntAnsAssessTest (struct UsrData *UsrDat,
unsigned NumQst,MYSQL_RES *mysql_res,
2020-02-17 23:15:08 +01:00
unsigned Visibility,
2014-12-01 23:55:08 +01:00
double *ScoreThisQst,bool *AnswerIsNotBlank);
2017-09-04 17:03:49 +02:00
2016-11-21 13:15:08 +01:00
static void Tst_WriteFloatAnsViewTest (unsigned NumQst);
2018-12-09 13:11:20 +01:00
static void Tst_WriteFloatAnsAssessTest (struct UsrData *UsrDat,
unsigned NumQst,MYSQL_RES *mysql_res,
2020-02-17 23:15:08 +01:00
unsigned Visibility,
2014-12-01 23:55:08 +01:00
double *ScoreThisQst,bool *AnswerIsNotBlank);
2017-09-04 17:03:49 +02:00
2018-12-09 13:11:20 +01:00
static void Tst_WriteHeadUserCorrect (struct UsrData *UsrDat);
2014-12-01 23:55:08 +01:00
static void Tst_WriteScoreStart (unsigned ColSpan);
static void Tst_WriteScoreEnd (void);
static void Tst_WriteParamQstCod (unsigned NumQst,long QstCod);
2017-07-16 13:54:11 +02:00
static bool Tst_GetParamsTst (Tst_ActionToDoWithQuestions_t ActionToDoWithQuestions);
2014-12-01 23:55:08 +01:00
static unsigned Tst_GetAndCheckParamNumTst (void);
static void Tst_GetParamNumQst (void);
static bool Tst_GetCreateXMLFromForm (void);
static int Tst_CountNumTagsInList (void);
static int Tst_CountNumAnswerTypesInList (void);
2017-01-17 03:10:43 +01:00
static void Tst_PutFormEditOneQst (char Stem[Cns_MAX_BYTES_TEXT + 1],
char Feedback[Cns_MAX_BYTES_TEXT + 1]);
2016-12-26 15:17:30 +01:00
static void Tst_PutFloatInputField (const char *Label,const char *Field,
double Value);
2016-12-26 16:30:46 +01:00
static void Tst_PutTFInputField (const char *Label,char Value);
2016-04-03 01:24:20 +02:00
2016-04-06 19:26:09 +02:00
static void Tst_FreeTextChoiceAnswers (void);
static void Tst_FreeTextChoiceAnswer (unsigned NumOpt);
2019-03-17 14:47:58 +01:00
static void Tst_ResetMediaOfQuestion (void);
2019-03-02 21:49:11 +01:00
static void Tst_FreeMediaOfQuestion (void);
2016-04-04 21:51:21 +02:00
2017-01-17 03:10:43 +01:00
static void Tst_GetQstDataFromDB (char Stem[Cns_MAX_BYTES_TEXT + 1],
char Feedback[Cns_MAX_BYTES_TEXT + 1]);
2019-03-19 11:20:29 +01:00
static long Tst_GetMedCodFromDB (int NumOpt);
2019-03-02 21:49:11 +01:00
static void Tst_GetMediaFromDB (int NumOpt,struct Media *Media);
2016-04-03 01:24:20 +02:00
2014-12-01 23:55:08 +01:00
static Tst_AnswerType_t Tst_ConvertFromUnsignedStrToAnsTyp (const char *UnsignedStr);
static void Tst_GetQstFromForm (char *Stem,char *Feedback);
2019-03-02 21:49:11 +01:00
static void Tst_MoveMediaToDefinitiveDirectories (void);
2016-04-04 21:51:21 +02:00
2014-12-01 23:55:08 +01:00
static long Tst_GetTagCodFromTagTxt (const char *TagTxt);
static long Tst_CreateNewTag (long CrsCod,const char *TagTxt);
static void Tst_EnableOrDisableTag (long TagCod,bool TagHidden);
2016-04-05 10:05:52 +02:00
2016-04-05 13:07:33 +02:00
static void Tst_PutIconToRemoveOneQst (void);
2016-04-05 10:05:52 +02:00
static void Tst_PutParamsRemoveOneQst (void);
2017-04-28 14:02:08 +02:00
static void Tst_PutParamsRemoveQst (void);
2016-04-05 10:05:52 +02:00
2016-04-06 19:26:09 +02:00
static long Tst_GetQstCod (void);
2014-12-01 23:55:08 +01:00
static void Tst_InsertOrUpdateQstIntoDB (void);
static void Tst_InsertTagsIntoDB (void);
static void Tst_InsertAnswersIntoDB (void);
static void Tst_RemAnsFromQst (void);
static void Tst_RemTagsFromQst (void);
static void Tst_RemoveUnusedTagsFromCurrentCrs (void);
2016-04-04 21:51:21 +02:00
2019-03-17 01:38:10 +01:00
static void Tst_RemoveAllMedFilesFromStemOfAllQstsInCrs (long CrsCod);
2019-03-19 11:20:29 +01:00
static void Tst_RemoveMediaFromAllAnsOfQst (long CrsCod,long QstCod);
2019-03-17 01:38:10 +01:00
static void Tst_RemoveAllMedFilesFromAnsOfAllQstsInCrs (long CrsCod);
2016-04-04 21:51:21 +02:00
2019-04-03 20:57:04 +02:00
static unsigned Tst_GetNumTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsType,struct Tst_Stats *Stats);
static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsType);
static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsType);
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*************** Show form to generate a self-assessment test ****************/
/*****************************************************************************/
void Tst_ShowFormAskTst (void)
{
2016-11-13 20:18:49 +01:00
extern const char *Hlp_ASSESSMENT_Tests;
2016-04-07 13:06:06 +02:00
extern const char *Txt_Take_a_test;
2014-12-01 23:55:08 +01:00
extern const char *Txt_No_of_questions;
2016-11-21 13:15:08 +01:00
extern const char *Txt_Generate_test;
2016-03-21 02:13:19 +01:00
extern const char *Txt_No_test_questions;
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
unsigned long NumRows;
/***** Read test configuration from database *****/
Tst_GetConfigTstFromDB ();
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,Txt_Take_a_test,Tst_PutIconsTests,
2017-06-12 15:03:29 +02:00
Hlp_ASSESSMENT_Tests,Box_NOT_CLOSABLE);
2016-03-20 23:38:22 +01:00
2014-12-01 23:55:08 +01:00
/***** Get tags *****/
if ((NumRows = Tst_GetEnabledTagsFromThisCrs (&mysql_res)) != 0)
{
/***** Check if minimum date-time of next access to test is older than now *****/
if (Tst_CheckIfNextTstAllowed ())
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeTst);
2017-05-01 21:17:38 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginPadding (2);
2014-12-01 23:55:08 +01:00
/***** Selection of tags *****/
2019-12-09 12:56:21 +01:00
Tst_ShowFormSelTags (NumRows,mysql_res,true);
2014-12-01 23:55:08 +01:00
/***** Selection of types of answers *****/
2019-12-09 12:56:21 +01:00
Tst_ShowFormAnswerTypes ();
2014-12-01 23:55:08 +01:00
/***** Number of questions to generate ****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
2019-12-27 21:10:39 +01:00
/* Label */
2019-12-27 15:45:19 +01:00
Frm_LabelColumn ("RT","NumQst",Txt_No_of_questions);
2019-10-07 21:15:14 +02:00
2019-12-27 21:10:39 +01:00
/* Data */
2019-12-26 22:29:04 +01:00
HTM_TD_Begin ("class=\"LT\"");
2019-11-27 01:01:27 +01:00
HTM_INPUT_LONG ("NumQst",
2019-11-04 13:50:33 +01:00
(long) Gbl.Test.Config.Min,
(long) Gbl.Test.Config.Max,
(long) Gbl.Test.Config.Def,
2019-11-12 15:41:58 +01:00
Gbl.Test.Config.Min == Gbl.Test.Config.Max,
"id=\"NumQst\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2017-05-01 21:17:38 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
/***** Send button *****/
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButton (Txt_Generate_test);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
}
else
{
2016-03-21 02:13:19 +01:00
/***** Warning message *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_INFO,Txt_No_test_questions);
2016-03-21 02:13:19 +01:00
/***** Button to create a new question *****/
2016-11-07 10:35:36 +01:00
if (Tst_CheckIfICanEditTests ())
2016-05-30 18:26:29 +02:00
Tst_PutButtonToAddQuestion ();
2014-12-01 23:55:08 +01:00
}
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-03-20 23:38:22 +01:00
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/********************** Generate self-assessment test ************************/
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
void Tst_ShowNewTest (void)
2014-12-01 23:55:08 +01:00
{
2016-11-13 20:18:49 +01:00
extern const char *Hlp_ASSESSMENT_Tests;
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_No_questions_found_matching_your_search_criteria;
2016-03-21 01:28:16 +01:00
extern const char *Txt_Test;
2016-11-21 13:15:08 +01:00
extern const char *Txt_Allow_teachers_to_consult_this_test;
extern const char *Txt_Done_assess_test;
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
unsigned long NumRows;
unsigned NumAccessesTst;
/***** Read test configuration from database *****/
Tst_GetConfigTstFromDB ();
if (Tst_CheckIfNextTstAllowed ())
{
/***** Check that all parameters used to generate a test are valid *****/
2017-09-04 17:03:49 +02:00
if (Tst_GetParamsTst (Tst_SHOW_TEST_TO_ANSWER)) // Get parameters from form
2014-12-01 23:55:08 +01:00
{
/***** Get questions *****/
2016-11-21 13:15:08 +01:00
if ((NumRows = Tst_GetQuestionsForTest (&mysql_res)) == 0) // Query database
2014-12-01 23:55:08 +01:00
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_INFO,Txt_No_questions_found_matching_your_search_criteria);
2014-12-01 23:55:08 +01:00
Tst_ShowFormAskTst (); // Show the form again
}
else
{
/***** Get and update number of hits *****/
NumAccessesTst = Tst_GetNumAccessesTst () + 1;
if (Gbl.Usrs.Me.IBelongToCurrentCrs)
Tst_UpdateMyNumAccessTst (NumAccessesTst);
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,Txt_Test,NULL,
2017-06-12 15:03:29 +02:00
Hlp_ASSESSMENT_Tests,Box_NOT_CLOSABLE);
2016-03-21 01:28:16 +01:00
Lay_WriteHeaderClassPhoto (false,false,
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Deg.DegCod,
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2016-03-21 01:28:16 +01:00
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActAssTst);
2014-12-01 23:55:08 +01:00
Gbl.Test.NumQsts = (unsigned) NumRows;
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamUnsigned (NULL,"NumTst",NumAccessesTst);
Par_PutHiddenParamUnsigned (NULL,"NumQst",Gbl.Test.NumQsts);
2014-12-01 23:55:08 +01:00
2016-03-21 01:28:16 +01:00
/***** List the questions *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWideMarginPadding (10);
2014-12-01 23:55:08 +01:00
Tst_ShowTestQuestionsWhenSeeing (mysql_res);
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
2016-11-21 13:15:08 +01:00
/***** Test result will be saved? *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"CM\"");
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2020-03-12 13:53:37 +01:00
HTM_INPUT_CHECKBOX ("AllowTchs",HTM_DONT_SUBMIT_ON_CHANGE,
2019-11-04 20:41:35 +01:00
"value=\"Y\"%s",
2020-03-11 09:43:30 +01:00
Gbl.Test.AllowTeachers ? " checked=\"checked\"" :
"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%s",Txt_Allow_teachers_to_consult_this_test);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
2016-03-21 01:28:16 +01:00
/***** End form *****/
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButton (Txt_Done_assess_test);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-03-21 01:28:16 +01:00
2014-12-01 23:55:08 +01:00
/***** Set test status *****/
Tst_SetTstStatus (NumAccessesTst,Tst_STATUS_SHOWN_BUT_NOT_ASSESSED);
/***** Update date-time of my next allowed access to test *****/
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged == Rol_STD)
2014-12-01 23:55:08 +01:00
Tst_UpdateLastAccTst ();
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
else
2019-12-06 18:42:11 +01:00
Tst_ShowFormAskTst (); // Show the form again
2014-12-01 23:55:08 +01:00
/***** Free memory used for by the list of tags *****/
Tst_FreeTagsList ();
}
}
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/******************************** Assess a test ******************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
void Tst_AssessTest (void)
2014-12-01 23:55:08 +01:00
{
2016-11-13 20:18:49 +01:00
extern const char *Hlp_ASSESSMENT_Tests;
2016-03-21 01:28:16 +01:00
extern const char *Txt_Test_result;
extern const char *Txt_Test_No_X_that_you_make_in_this_course;
2019-11-28 09:12:34 +01:00
extern const char *Txt_Score;
2019-11-28 09:45:32 +01:00
extern const char *Txt_Grade;
2014-12-01 23:55:08 +01:00
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;
long TstCod = -1L; // Initialized to avoid warning
unsigned NumQstsNotBlank;
double TotalScore;
/***** Read test configuration from database *****/
Tst_GetConfigTstFromDB ();
/***** Get number of this test from form *****/
NumTst = Tst_GetAndCheckParamNumTst ();
/****** Get test status in database for this session-course-num.test *****/
switch (Tst_GetTstStatus (NumTst))
{
case Tst_STATUS_SHOWN_BUT_NOT_ASSESSED:
/***** Get the parameters of the form *****/
/* Get number of questions */
Tst_GetParamNumQst ();
2020-03-11 09:43:30 +01:00
/***** Get if test will be visible by teachers *****/
Gbl.Test.AllowTeachers = Par_GetParToBool ("AllowTchs");
2014-12-01 23:55:08 +01:00
2016-11-21 13:15:08 +01:00
/***** Get questions and answers from form to assess a test *****/
2014-12-01 23:55:08 +01:00
Tst_GetQuestionsAndAnswersFromForm ();
2016-11-21 13:15:08 +01:00
/***** Create new test in database to store the result *****/
2020-02-16 13:02:30 +01:00
TstCod = TsR_CreateTestResultInDB ();
2014-12-01 23:55:08 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,Txt_Test_result,NULL,
2017-06-12 15:03:29 +02:00
Hlp_ASSESSMENT_Tests,Box_NOT_CLOSABLE);
2016-03-21 01:28:16 +01:00
Lay_WriteHeaderClassPhoto (false,false,
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Deg.DegCod,
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2016-03-21 01:28:16 +01:00
/***** Header *****/
if (Gbl.Usrs.Me.IBelongToCurrentCrs)
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TEST_SUBTITLE\"");
2019-11-11 00:15:44 +01:00
HTM_TxtF (Txt_Test_No_X_that_you_make_in_this_course,NumTst);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-03-21 01:28:16 +01:00
}
2014-12-01 23:55:08 +01:00
/***** Write answers and solutions *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWideMarginPadding (10);
2016-11-21 13:15:08 +01:00
Tst_ShowTestResultAfterAssess (TstCod,&NumQstsNotBlank,&TotalScore);
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
2019-11-28 09:45:32 +01:00
/***** Write total score and grade *****/
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleTotalScore (Gbl.Test.Config.Visibility))
2019-11-28 09:12:34 +01:00
{
2019-11-28 09:45:32 +01:00
HTM_DIV_Begin ("class=\"DAT_N_BOLD CM\"");
2020-01-11 15:22:02 +01:00
HTM_TxtColonNBSP (Txt_Score);
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (TotalScore);
2019-11-28 09:45:32 +01:00
HTM_BR ();
2020-01-11 15:22:02 +01:00
HTM_TxtColonNBSP (Txt_Grade);
2020-02-16 13:02:30 +01:00
Tst_ComputeAndShowGrade (Gbl.Test.NumQsts,TotalScore,TsR_SCORE_MAX);
2019-11-28 09:12:34 +01:00
HTM_DIV_End ();
}
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2014-12-01 23:55:08 +01:00
/***** Store test result in database *****/
2020-02-16 13:02:30 +01:00
TsR_StoreScoreOfTestResultInDB (TstCod,
2018-12-09 13:11:20 +01:00
NumQstsNotBlank,TotalScore);
2014-12-01 23:55:08 +01:00
/***** Set test status *****/
Tst_SetTstStatus (NumTst,Tst_STATUS_ASSESSED);
break;
case Tst_STATUS_ASSESSED:
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_The_test_X_has_already_been_assessed_previously,
NumTst);
2014-12-01 23:55:08 +01:00
break;
case Tst_STATUS_ERROR:
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_There_was_an_error_in_assessing_the_test_X,
NumTst);
2014-12-01 23:55:08 +01:00
break;
}
}
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/*********** Get questions and answers from form to assess a test ************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
static void Tst_GetQuestionsAndAnswersFromForm (void)
{
unsigned NumQst;
2019-11-08 01:10:32 +01:00
char StrQstIndOrAns[3 + Cns_MAX_DECIMAL_DIGITS_UINT + 1]; // "Qstxx...x", "Indxx...x" or "Ansxx...x"
2014-12-01 23:55:08 +01:00
/***** Get questions and answers *****/
for (NumQst = 0;
NumQst < Gbl.Test.NumQsts;
NumQst++)
{
/* Get question code */
2018-10-18 02:02:32 +02:00
snprintf (StrQstIndOrAns,sizeof (StrQstIndOrAns),
"Qst%06u",
NumQst);
2017-01-28 20:32:50 +01:00
if ((Gbl.Test.QstCodes[NumQst] = Par_GetParToLong (StrQstIndOrAns)) <= 0)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Code of question is missing.");
/* Get indexes for this question */
2018-10-18 02:02:32 +02:00
snprintf (StrQstIndOrAns,sizeof (StrQstIndOrAns),
"Ind%06u",
NumQst);
2017-03-13 19:02:15 +01:00
Par_GetParMultiToText (StrQstIndOrAns,Gbl.Test.StrIndexesOneQst[NumQst],
Tst_MAX_BYTES_INDEXES_ONE_QST); /* If choice ==> "0", "1", "2",... */
2014-12-01 23:55:08 +01:00
/* Get answers selected by user for this question */
2018-10-18 02:02:32 +02:00
snprintf (StrQstIndOrAns,sizeof (StrQstIndOrAns),
"Ans%06u",
NumQst);
2017-03-13 19:02:15 +01:00
Par_GetParMultiToText (StrQstIndOrAns,Gbl.Test.StrAnswersOneQst[NumQst],
Tst_MAX_BYTES_ANSWERS_ONE_QST); /* If answer type == T/F ==> " ", "T", "F"; if choice ==> "0", "2",... */
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
2019-11-28 09:45:32 +01:00
/************ Compute and show total grade out of maximum grade **************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2019-11-28 09:45:32 +01:00
void Tst_ComputeAndShowGrade (unsigned NumQsts,double Score,double MaxGrade)
2019-11-28 09:12:34 +01:00
{
Tst_ShowGrade (Tst_ComputeGrade (NumQsts,Score,MaxGrade),MaxGrade);
}
2019-11-28 09:45:32 +01:00
/*****************************************************************************/
/**************** Compute total grade out of maximum grade *******************/
/*****************************************************************************/
2019-11-28 09:12:34 +01:00
double Tst_ComputeGrade (unsigned NumQsts,double Score,double MaxGrade)
2014-12-01 23:55:08 +01:00
{
2019-11-28 01:41:13 +01:00
double MaxScore;
double Grade;
2014-12-01 23:55:08 +01:00
2019-11-28 09:12:34 +01:00
/***** Compute grade *****/
2019-11-28 01:41:13 +01:00
if (NumQsts)
{
MaxScore = (double) NumQsts;
Grade = Score * MaxGrade / MaxScore;
}
else
Grade = 0.0;
2019-11-28 09:12:34 +01:00
return Grade;
}
2019-11-28 09:45:32 +01:00
/*****************************************************************************/
/****************** Show total grade out of maximum grade ********************/
/*****************************************************************************/
2019-11-28 09:12:34 +01:00
void Tst_ShowGrade (double Grade,double MaxGrade)
{
/***** Write grade over maximum grade *****/
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (Grade);
2019-11-28 22:49:05 +01:00
HTM_Txt ("/");
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (MaxGrade);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** Check minimum date-time of next access to test ***************/
/*****************************************************************************/
// Return true if allowed date-time of next access to test is older than now
static bool Tst_CheckIfNextTstAllowed (void)
{
2016-11-13 20:18:49 +01:00
extern const char *Hlp_ASSESSMENT_Tests;
2015-11-11 03:00:22 +01:00
extern const char *Txt_Test;
2016-12-26 14:02:19 +01:00
extern const char *Txt_You_can_not_take_a_new_test_until;
2015-12-29 11:35:01 +01:00
extern const char *Txt_Today;
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long NumSecondsFromNowToNextAccTst = -1L; // Access allowed when this number <= 0
2015-11-11 03:00:22 +01:00
time_t TimeNextTestUTC = (time_t) 0;
2014-12-01 23:55:08 +01:00
2016-07-20 20:24:16 +02:00
/***** Teachers and superusers are allowed to do all tests they want *****/
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged == Rol_TCH ||
Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
2014-12-01 23:55:08 +01:00
return true;
/***** Get date of next allowed access to test from database *****/
2018-11-02 01:38:44 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get last access to test",
"SELECT UNIX_TIMESTAMP(LastAccTst+INTERVAL (NumQstsLastTst*%lu) SECOND)-"
2019-03-18 15:42:22 +01:00
"UNIX_TIMESTAMP()," // row[0]
"UNIX_TIMESTAMP(LastAccTst+INTERVAL (NumQstsLastTst*%lu) SECOND)" // row[1]
2018-11-02 01:38:44 +01:00
" FROM crs_usr"
" WHERE CrsCod=%ld AND UsrCod=%ld",
Gbl.Test.Config.MinTimeNxtTstPerQst,
Gbl.Test.Config.MinTimeNxtTstPerQst,
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod) == 1)
2014-12-01 23:55:08 +01:00
{
/* Get seconds from now to next access to test */
row = mysql_fetch_row (mysql_res);
if (row[0])
if (sscanf (row[0],"%ld",&NumSecondsFromNowToNextAccTst) == 1)
2015-11-11 03:00:22 +01:00
/* Time UTC of next access allowed (row[1]) */
TimeNextTestUTC = Dat_GetUNIXTimeFromStr (row[1]);
2014-12-01 23:55:08 +01:00
}
else
Lay_ShowErrorAndExit ("Error when reading date of next allowed access to test.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Check if access is allowed *****/
if (NumSecondsFromNowToNextAccTst > 0)
{
2015-11-11 03:00:22 +01:00
/***** Write warning *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,"%s:<br /><span id=\"date_next_test\"></span>."
"<script type=\"text/javascript\">"
"writeLocalDateHMSFromUTC('date_next_test',%ld,"
"%u,',&nbsp;','%s',true,true,0x7);"
"</script>",
Txt_You_can_not_take_a_new_test_until,
(long) TimeNextTestUTC,
(unsigned) Gbl.Prefs.DateFormat,Txt_Today);
2015-11-11 03:00:22 +01:00
2014-12-01 23:55:08 +01:00
return false;
}
return true;
}
/*****************************************************************************/
/****************************** Update test status ***************************/
/*****************************************************************************/
static void Tst_SetTstStatus (unsigned NumTst,Tst_Status_t TstStatus)
{
/***** Delete old status from expired sessions *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove old status of tests",
"DELETE FROM tst_status"
" WHERE SessionId NOT IN"
" (SELECT SessionId FROM sessions)");
2014-12-01 23:55:08 +01:00
/***** Update database *****/
2018-11-02 16:39:35 +01:00
DB_QueryREPLACE ("can not update status of test",
"REPLACE INTO tst_status"
" (SessionId,CrsCod,NumTst,Status)"
" VALUES"
" ('%s',%ld,%u,%u)",
2019-04-04 10:45:15 +02:00
Gbl.Session.Id,Gbl.Hierarchy.Crs.CrsCod,
2018-11-02 16:39:35 +01:00
NumTst,(unsigned) TstStatus);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************************** Update test status ***************************/
/*****************************************************************************/
static Tst_Status_t Tst_GetTstStatus (unsigned NumTst)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned UnsignedNum;
Tst_Status_t TstStatus = Tst_STATUS_ERROR;
/***** Get status of test from database *****/
2018-11-02 01:38:44 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get status of test",
2019-03-18 15:42:22 +01:00
"SELECT Status" // row[0]
" FROM tst_status"
2018-11-02 01:38:44 +01:00
" WHERE SessionId='%s'"
" AND CrsCod=%ld"
" AND NumTst=%u",
2019-04-04 10:45:15 +02:00
Gbl.Session.Id,Gbl.Hierarchy.Crs.CrsCod,NumTst);
2014-12-01 23:55:08 +01:00
if (NumRows == 1)
{
/* Get number of hits */
row = mysql_fetch_row (mysql_res);
if (row[0])
if (sscanf (row[0],"%u",&UnsignedNum) == 1)
if (UnsignedNum < Tst_NUM_STATUS)
TstStatus = (Tst_Status_t) UnsignedNum;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return TstStatus;
}
/*****************************************************************************/
/************************* Get number of hits to test ************************/
/*****************************************************************************/
static unsigned Tst_GetNumAccessesTst (void)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned NumAccessesTst = 0;
if (Gbl.Usrs.Me.IBelongToCurrentCrs)
{
/***** Get number of hits to test from database *****/
2018-11-02 01:38:44 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get number of hits to test",
2019-03-18 15:42:22 +01:00
"SELECT NumAccTst" // row[0]
" FROM crs_usr"
2018-11-02 01:38:44 +01:00
" WHERE CrsCod=%ld AND UsrCod=%ld",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-11-02 01:38:44 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod);
2014-12-01 23:55:08 +01:00
if (NumRows == 0)
NumAccessesTst = 0;
else if (NumRows == 1)
{
/* Get number of hits */
row = mysql_fetch_row (mysql_res);
if (row[0] == NULL)
NumAccessesTst = 0;
else if (sscanf (row[0],"%u",&NumAccessesTst) != 1)
NumAccessesTst = 0;
}
else
Lay_ShowErrorAndExit ("Error when getting number of hits to test.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return NumAccessesTst;
}
/*****************************************************************************/
/*************************** Write the test questions ************************/
/*****************************************************************************/
// 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)
{
unsigned NumQst;
long QstCod;
MYSQL_ROW row;
double ScoreThisQst; // Not used here
bool AnswerIsNotBlank; // Not used here
2019-03-18 15:42:22 +01:00
/*
row[0] QstCod
row[1] UNIX_TIMESTAMP(EditTime)
row[2] AnsType
row[3] Shuffle
row[4] Stem
row[5] Feedback
row[6] MedCod
row[7] NumHits
row[8] NumHitsNotBlank
row[9] Score
*/
2014-12-01 23:55:08 +01:00
/***** Write rows *****/
for (NumQst = 0;
NumQst < Gbl.Test.NumQsts;
NumQst++)
{
Gbl.RowEvenOdd = NumQst % 2;
/***** Get the row next of the result of the query in the database *****/
row = mysql_fetch_row (mysql_res);
/***** Get the code of question (row[0]) *****/
if ((QstCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of question.");
2017-09-04 17:03:49 +02:00
Tst_WriteQstAndAnsTest (Tst_SHOW_TEST_TO_ANSWER,
2018-12-09 13:11:20 +01:00
&Gbl.Usrs.Me.UsrDat,
2019-09-24 19:09:06 +02:00
NumQst,QstCod,row,
2020-02-18 09:19:33 +01:00
TsV_MAX_VISIBILITY, // All visible here
2014-12-01 23:55:08 +01:00
&ScoreThisQst, // Not used here
&AnswerIsNotBlank); // Not used here
}
}
2019-09-24 22:48:25 +02:00
/*****************************************************************************/
/************************** Show list of test tags ***************************/
/*****************************************************************************/
void Tst_ShowTagList (unsigned NumTags,MYSQL_RES *mysql_res)
{
extern const char *Txt_no_tags;
MYSQL_ROW row;
unsigned NumTag;
if (NumTags)
2014-12-01 23:55:08 +01:00
{
/***** Write the tags *****/
2019-10-26 12:25:27 +02:00
HTM_UL_Begin (NULL);
2019-09-24 22:48:25 +02:00
for (NumTag = 0;
NumTag < NumTags;
NumTag++)
2014-12-01 23:55:08 +01:00
{
row = mysql_fetch_row (mysql_res);
2019-10-26 22:49:13 +02:00
HTM_LI_Begin (NULL);
2019-11-10 12:36:37 +01:00
HTM_Txt (row[0]);
2019-10-26 22:49:13 +02:00
HTM_LI_End ();
2014-12-01 23:55:08 +01:00
}
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2014-12-01 23:55:08 +01:00
}
else
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_no_tags);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Show the result of assessing a test *********************/
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
static void Tst_ShowTestResultAfterAssess (long TstCod,unsigned *NumQstsNotBlank,double *TotalScore)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Question_removed;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumQst;
long QstCod;
double ScoreThisQst;
bool AnswerIsNotBlank;
/***** Initialize score and number of questions not blank *****/
*TotalScore = 0.0;
*NumQstsNotBlank = 0;
for (NumQst = 0;
NumQst < Gbl.Test.NumQsts;
NumQst++)
{
Gbl.RowEvenOdd = NumQst % 2;
/***** Query database *****/
if (Tst_GetOneQuestionByCod (Gbl.Test.QstCodes[NumQst],&mysql_res)) // Question exists
{
/***** Get row of the result of the query *****/
row = mysql_fetch_row (mysql_res);
/*
2019-03-18 15:42:22 +01:00
row[0] QstCod
row[1] UNIX_TIMESTAMP(EditTime)
row[2] AnsType
row[3] Shuffle
row[4] Stem
row[5] Feedback
row[6] MedCod
row[7] NumHits
row[8] NumHitsNotBlank
row[9] Score
2014-12-01 23:55:08 +01:00
*/
/***** Get the code of question (row[0]) *****/
if ((QstCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of question.");
2016-11-21 13:15:08 +01:00
/***** Write question and answers *****/
2017-09-04 17:03:49 +02:00
Tst_WriteQstAndAnsTest (Tst_SHOW_TEST_RESULT,
2018-12-09 13:11:20 +01:00
&Gbl.Usrs.Me.UsrDat,
2019-09-24 19:09:06 +02:00
NumQst,QstCod,row,
2020-02-17 23:15:08 +01:00
Gbl.Test.Config.Visibility,
2014-12-01 23:55:08 +01:00
&ScoreThisQst,&AnswerIsNotBlank);
2016-11-21 13:15:08 +01:00
/***** Store test result question in database *****/
2020-02-16 13:02:30 +01:00
TsR_StoreOneTestResultQstInDB (TstCod,QstCod,
2016-11-21 13:15:08 +01:00
NumQst, // 0, 1, 2, 3...
ScoreThisQst);
2014-12-01 23:55:08 +01:00
/***** Compute total score *****/
*TotalScore += ScoreThisQst;
if (AnswerIsNotBlank)
(*NumQstsNotBlank)++;
/***** Update the number of accesses and the score of this question *****/
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged == Rol_STD)
2014-12-01 23:55:08 +01:00
Tst_UpdateScoreQst (QstCod,ScoreThisQst,AnswerIsNotBlank);
}
else
2019-10-04 14:42:59 +02:00
{
2014-12-01 23:55:08 +01:00
/***** Question does not exists *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BIG_INDEX RT COLOR%u\"",Gbl.RowEvenOdd);
2019-11-10 13:31:47 +01:00
HTM_Unsigned (NumQst + 1);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT_LIGHT LT COLOR%u\"",Gbl.RowEvenOdd);
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_Question_removed);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-10-04 14:42:59 +02:00
}
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
}
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/********** Write a row of a test, with one question and its answer **********/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-02-16 13:02:30 +01:00
void Tst_WriteQstAndAnsTest (Tst_ActionToDoWithQuestions_t ActionToDoWithQuestions,
struct UsrData *UsrDat,
unsigned NumQst,long QstCod,MYSQL_ROW row,
2020-02-17 23:15:08 +01:00
unsigned Visibility,
2020-02-16 13:02:30 +01:00
double *ScoreThisQst,bool *AnswerIsNotBlank)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_TST_STR_ANSWER_TYPES[Tst_NUM_ANS_TYPES];
2020-02-18 09:19:33 +01:00
bool IsVisibleQstAndAnsTxt = TsV_IsVisibleQstAndAnsTxt (Visibility);
2014-12-01 23:55:08 +01:00
/*
2019-03-18 15:42:22 +01:00
row[0] QstCod
row[1] UNIX_TIMESTAMP(EditTime)
row[2] AnsType
row[3] Shuffle
row[4] Stem
row[5] Feedback
row[6] MedCod
row[7] NumHits
row[8] NumHitsNotBlank
row[9] Score
2014-12-01 23:55:08 +01:00
*/
2016-04-06 19:26:09 +02:00
/***** Create test question *****/
Tst_QstConstructor ();
Gbl.Test.QstCod = QstCod;
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-23 20:07:56 +02:00
HTM_TD_Begin ("class=\"RT COLOR%u\"",Gbl.RowEvenOdd);
2019-10-07 21:15:14 +02:00
/***** Write number of question *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"BIG_INDEX\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (NumQst + 1);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
/***** Write answer type (row[2]) *****/
Gbl.Test.AnswerType = Tst_ConvertFromStrAnsTypDBToAnsTyp (row[2]);
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"DAT_SMALL\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_TST_STR_ANSWER_TYPES[Gbl.Test.AnswerType]);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2019-03-18 15:42:22 +01:00
/***** Write stem (row[4]) *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd);
2020-02-17 23:15:08 +01:00
Tst_WriteQstStem (row[4],"TEST_EXA",IsVisibleQstAndAnsTxt);
2019-03-18 15:42:22 +01:00
/***** Get and show media (row[6]) *****/
2020-02-17 23:15:08 +01:00
if (IsVisibleQstAndAnsTxt)
{
Gbl.Test.Media.MedCod = Str_ConvertStrCodToLongCod (row[6]);
Med_GetMediaDataByCod (&Gbl.Test.Media);
Med_ShowMedia (&Gbl.Test.Media,
"TEST_MED_SHOW_CONT",
"TEST_MED_SHOW");
}
2016-04-06 19:26:09 +02:00
2019-03-18 15:42:22 +01:00
/***** Write answers depending on shuffle (row[3]) and feedback (row[5]) *****/
2017-09-01 14:36:25 +02:00
switch (ActionToDoWithQuestions)
2014-12-01 23:55:08 +01:00
{
2017-09-04 17:03:49 +02:00
case Tst_SHOW_TEST_TO_ANSWER:
Tst_WriteAnswersTestToAnswer (NumQst,QstCod,(row[3][0] == 'Y'));
2017-09-01 14:36:25 +02:00
break;
2017-09-04 17:03:49 +02:00
case Tst_SHOW_TEST_RESULT:
2020-02-17 23:15:08 +01:00
Tst_WriteAnswersTestResult (UsrDat,NumQst,QstCod,
Visibility,
ScoreThisQst,AnswerIsNotBlank);
2016-04-06 15:00:15 +02:00
2017-09-01 14:36:25 +02:00
/* Write question feedback (row[5]) */
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleFeedbackTxt (Visibility))
2017-09-01 14:36:25 +02:00
Tst_WriteQstFeedback (row[5],"TEST_EXA_LIGHT");
break;
2019-09-24 19:09:06 +02:00
default:
2017-09-01 14:36:25 +02:00
break;
2014-12-01 23:55:08 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
HTM_TR_End ();
2016-04-06 01:10:04 +02:00
2016-04-06 19:26:09 +02:00
/***** Destroy test question *****/
Tst_QstDestructor ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-03-30 00:15:26 +02:00
/********************* Write the stem of a test question *********************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-02-17 15:30:55 +01:00
void Tst_WriteQstStem (const char *Stem,const char *ClassStem,bool Visible)
2014-12-01 23:55:08 +01:00
{
unsigned long StemLength;
char *StemRigorousHTML;
2020-02-17 15:30:55 +01:00
/***** DIV begin *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"%s\"",ClassStem);
2014-12-01 23:55:08 +01:00
2020-02-17 15:30:55 +01:00
/***** Write stem *****/
if (Visible)
{
/* Convert the stem, that is in HTML, to rigorous HTML */
StemLength = strlen (Stem) * Str_MAX_BYTES_PER_CHAR;
if ((StemRigorousHTML = (char *) malloc (StemLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
Str_Copy (StemRigorousHTML,Stem,
StemLength);
2020-03-14 16:49:04 +01:00
2020-02-17 15:30:55 +01:00
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
StemRigorousHTML,StemLength,false);
/* Write stem text */
HTM_Txt (StemRigorousHTML);
/* Free memory allocated for the stem */
free (StemRigorousHTML);
}
else
2020-02-19 00:45:26 +01:00
Ico_PutIconNotVisible ();
2020-02-17 15:30:55 +01:00
/***** DIV end *****/
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
}
2016-03-30 01:28:58 +02:00
/*****************************************************************************/
/************* Put form to upload a new image for a test question ************/
/*****************************************************************************/
2019-03-02 21:49:11 +01:00
static void Tst_PutFormToEditQstMedia (struct Media *Media,int NumMediaInForm,
2016-04-05 10:47:36 +02:00
bool OptionsDisabled)
2016-03-30 01:28:58 +02:00
{
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2019-03-17 01:38:10 +01:00
extern const char *Txt_No_image_video;
extern const char *Txt_Current_image_video;
extern const char *Txt_Change_image_video;
2016-04-04 10:11:05 +02:00
static unsigned UniqueId = 0;
2019-03-02 21:49:11 +01:00
struct ParamUploadMedia ParamUploadMedia;
2016-04-03 14:42:22 +02:00
2019-03-02 21:49:11 +01:00
if (Media->Name[0])
2016-04-11 15:32:59 +02:00
{
2016-04-14 21:33:24 +02:00
/***** Set names of parameters depending on number of image in form *****/
2019-03-02 21:49:11 +01:00
Med_SetParamNames (&ParamUploadMedia,NumMediaInForm);
2016-04-14 21:33:24 +02:00
2016-04-14 18:59:18 +02:00
/***** Start container *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TEST_MED_EDIT_FORM\"");
2016-04-14 18:59:18 +02:00
2019-03-17 01:38:10 +01:00
/***** Choice 1: No media *****/
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-04 18:17:39 +01:00
HTM_INPUT_RADIO (ParamUploadMedia.Action,false,
"value=\"%u\"%s",
(unsigned) Med_ACTION_NO_MEDIA,
OptionsDisabled ? " disabled=\"disabled\"" : "");
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_No_image_video);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-11-09 21:08:20 +01:00
HTM_BR ();
2016-04-11 15:32:59 +02:00
2019-03-17 01:38:10 +01:00
/***** Choice 2: Current media *****/
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-04 18:17:39 +01:00
HTM_INPUT_RADIO (ParamUploadMedia.Action,false,
"value=\"%u\"%s checked=\"checked\"",
(unsigned) Med_ACTION_KEEP_MEDIA,
OptionsDisabled ? " disabled=\"disabled\"" : "");
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_Current_image_video);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-03-27 14:36:57 +01:00
Med_ShowMedia (Media,
2019-12-13 00:36:01 +01:00
"TEST_MED_EDIT_ONE_CONT",
2019-03-27 14:36:57 +01:00
"TEST_MED_EDIT_ONE");
2016-04-03 14:42:22 +02:00
2019-03-17 01:38:10 +01:00
/***** Choice 3: Change media *****/
2016-04-11 15:32:59 +02:00
UniqueId++;
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-04 18:17:39 +01:00
HTM_INPUT_RADIO (ParamUploadMedia.Action,false,
"id=\"chg_img_%u\" value=\"%u\"%s",
UniqueId,
(unsigned) Med_ACTION_NEW_MEDIA,
OptionsDisabled ? " disabled=\"disabled\"" : "");
2020-01-11 15:22:02 +01:00
HTM_TxtColonNBSP (Txt_Change_image_video);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-03-27 14:36:57 +01:00
Med_PutMediaUploader (NumMediaInForm,"TEST_MED_INPUT");
2016-04-05 21:44:06 +02:00
2016-04-14 18:59:18 +02:00
/***** End container *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-04-14 18:59:18 +02:00
}
else // No current image
2019-03-17 01:38:10 +01:00
/***** Attached media *****/
2019-03-27 14:36:57 +01:00
Med_PutMediaUploader (NumMediaInForm,"TEST_MED_INPUT");
2016-03-30 01:28:58 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******************* Write the feedback of a test question *******************/
/*****************************************************************************/
void Tst_WriteQstFeedback (const char *Feedback,const char *ClassFeedback)
{
unsigned long FeedbackLength;
char *FeedbackRigorousHTML;
if (Feedback)
if (Feedback[0])
{
/***** Convert the feedback, that is in HTML, to rigorous HTML *****/
2017-03-08 03:48:23 +01:00
FeedbackLength = strlen (Feedback) * Str_MAX_BYTES_PER_CHAR;
2018-10-08 12:37:29 +02:00
if ((FeedbackRigorousHTML = (char *) malloc (FeedbackLength + 1)) == NULL)
2018-10-18 20:06:54 +02:00
Lay_NotEnoughMemoryExit ();
2017-01-17 03:10:43 +01:00
Str_Copy (FeedbackRigorousHTML,Feedback,
FeedbackLength);
2014-12-01 23:55:08 +01:00
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
FeedbackRigorousHTML,FeedbackLength,false);
/***** Write the feedback *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"%s\"",ClassFeedback);
2019-11-10 12:36:37 +01:00
HTM_Txt (FeedbackRigorousHTML);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
/***** Free memory allocated for the feedback *****/
2019-11-06 19:45:20 +01:00
free (FeedbackRigorousHTML);
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/*********************** Update the score of a question **********************/
/*****************************************************************************/
2019-11-11 00:15:44 +01:00
static void Tst_UpdateScoreQst (long QstCod,double ScoreThisQst,bool AnswerIsNotBlank)
2014-12-01 23:55:08 +01:00
{
/***** Update number of clicks and score of the question *****/
2016-06-04 14:21:01 +02:00
Str_SetDecimalPointToUS (); // To print the floating point as a dot
2014-12-01 23:55:08 +01:00
if (AnswerIsNotBlank)
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the score of a question",
"UPDATE tst_questions"
" SET NumHits=NumHits+1,NumHitsNotBlank=NumHitsNotBlank+1,"
2020-01-11 15:22:02 +01:00
"Score=Score+(%.15lg)"
2018-11-03 12:16:40 +01:00
" WHERE QstCod=%ld",
ScoreThisQst,QstCod);
2014-12-01 23:55:08 +01:00
else // The answer is blank
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the score of a question",
"UPDATE tst_questions"
" SET NumHits=NumHits+1"
" WHERE QstCod=%ld",
QstCod);
2016-06-04 14:21:01 +02:00
Str_SetDecimalPointToLocal (); // Return to local system
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********** Update my number of accesses to test in this course *************/
/*****************************************************************************/
static void Tst_UpdateMyNumAccessTst (unsigned NumAccessesTst)
{
/***** Update my number of accesses to test in this course *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the number of accesses to test",
"UPDATE crs_usr SET NumAccTst=%u"
" WHERE CrsCod=%ld AND UsrCod=%ld",
NumAccessesTst,
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************ Update date-time of my next allowed access to test *************/
/*****************************************************************************/
static void Tst_UpdateLastAccTst (void)
{
/***** Update date-time and number of questions of this test *****/
2018-11-03 12:16:40 +01:00
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,
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-11-03 12:16:40 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******* Select tags and dates for edition of the self-assessment test *******/
/*****************************************************************************/
void Tst_ShowFormAskEditTsts (void)
{
2019-10-03 22:12:31 +02:00
extern const char *Hlp_ASSESSMENT_Tests_editing_questions;
2016-03-21 02:13:19 +01:00
extern const char *Txt_No_test_questions;
2016-04-07 12:55:58 +02:00
extern const char *Txt_List_edit_questions;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Show_questions;
MYSQL_RES *mysql_res;
unsigned long NumRows;
2020-02-26 19:35:33 +01:00
static const Dat_SetHMS SetHMS[Dat_NUM_START_END_TIME] =
{
Dat_HMS_DO_NOT_SET,
Dat_HMS_DO_NOT_SET
};
2014-12-01 23:55:08 +01:00
2016-03-21 12:53:02 +01:00
/***** Contextual menu *****/
2019-10-24 09:46:20 +02:00
Mnu_ContextMenuBegin ();
TsI_PutFormToImportQuestions (); // Import questions from XML file
Mnu_ContextMenuEnd ();
2014-12-01 23:55:08 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,Txt_List_edit_questions,Tst_PutIconsTests,
2019-10-03 22:12:31 +02:00
Hlp_ASSESSMENT_Tests_editing_questions,Box_NOT_CLOSABLE);
2016-03-21 02:13:19 +01:00
2014-12-01 23:55:08 +01:00
/***** Get tags already present in the table of questions *****/
2016-03-21 02:13:19 +01:00
if ((NumRows = Tst_GetAllTagsFromCurrentCrs (&mysql_res)))
2014-12-01 23:55:08 +01:00
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActLstTstQst);
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Tst_ORDER_STEM);
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginPadding (2);
2014-12-01 23:55:08 +01:00
/***** Selection of tags *****/
2019-12-09 12:56:21 +01:00
Tst_ShowFormSelTags (NumRows,mysql_res,false);
2014-12-01 23:55:08 +01:00
/***** Selection of types of answers *****/
2019-12-09 12:56:21 +01:00
Tst_ShowFormAnswerTypes ();
2014-12-01 23:55:08 +01:00
/***** Starting and ending dates in the search *****/
2020-02-26 19:35:33 +01:00
Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (SetHMS);
2017-05-01 21:17:38 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
/***** Send button *****/
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButton (Txt_Show_questions);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-03-21 02:13:19 +01:00
}
else // No test questions
{
/***** Warning message *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_INFO,Txt_No_test_questions);
2016-03-21 01:28:16 +01:00
2016-03-21 02:13:19 +01:00
/***** Button to create a new question *****/
Tst_PutButtonToAddQuestion ();
2014-12-01 23:55:08 +01:00
}
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-03-21 02:13:19 +01:00
2014-12-01 23:55:08 +01:00
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
}
2017-07-16 13:54:11 +02:00
/*****************************************************************************/
/************** Show form select test questions for a game *******************/
/*****************************************************************************/
2019-09-29 17:33:39 +02:00
void Tst_ShowFormAskSelectTstsForGame (void)
2017-07-16 13:54:11 +02:00
{
2019-10-03 22:12:31 +02:00
extern const char *Hlp_ASSESSMENT_Games_questions;
2017-07-16 13:54:11 +02:00
extern const char *Txt_No_test_questions;
extern const char *Txt_Select_questions;
extern const char *Txt_Show_questions;
MYSQL_RES *mysql_res;
unsigned long NumRows;
2020-02-26 19:35:33 +01:00
static const Dat_SetHMS SetHMS[Dat_NUM_START_END_TIME] =
{
Dat_HMS_DO_NOT_SET,
Dat_HMS_DO_NOT_SET
};
2017-07-16 13:54:11 +02:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,Txt_Select_questions,NULL,
2019-10-03 22:12:31 +02:00
Hlp_ASSESSMENT_Games_questions,Box_NOT_CLOSABLE);
2017-07-16 13:54:11 +02:00
/***** Get tags already present in the table of questions *****/
if ((NumRows = Tst_GetAllTagsFromCurrentCrs (&mysql_res)))
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActGamLstTstQst);
2019-09-29 17:33:39 +02:00
Gam_PutParams ();
2017-07-16 13:54:11 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginPadding (2);
2017-07-16 13:54:11 +02:00
/***** Selection of tags *****/
2019-12-09 12:56:21 +01:00
Tst_ShowFormSelTags (NumRows,mysql_res,false);
2017-07-16 13:54:11 +02:00
/***** Starting and ending dates in the search *****/
2020-02-26 19:35:33 +01:00
Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (SetHMS);
2017-07-16 13:54:11 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2017-07-16 13:54:11 +02:00
/***** Send button *****/
Btn_PutConfirmButton (Txt_Show_questions);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-07-16 13:54:11 +02:00
}
else // No test questions
{
/***** Warning message *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_INFO,Txt_No_test_questions);
2017-07-16 13:54:11 +02:00
/***** Button to create a new question *****/
Tst_PutButtonToAddQuestion ();
}
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2017-07-16 13:54:11 +02:00
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-07 10:35:36 +01:00
/************************* Check if I can edit tests *************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-07 10:35:36 +01:00
static bool Tst_CheckIfICanEditTests (void)
{
2017-06-04 18:18:54 +02:00
return (bool) (Gbl.Usrs.Me.Role.Logged == Rol_TCH ||
Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM);
2016-11-07 10:35:36 +01:00
}
/*****************************************************************************/
/********************* Put contextual icons in tests *************************/
/*****************************************************************************/
static void Tst_PutIconsTests (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_New_question;
2016-05-05 12:37:45 +02:00
2016-11-07 10:35:36 +01:00
if (Tst_CheckIfICanEditTests ())
{
/***** Put form to edit existing test questions *****/
if (Gbl.Action.Act != ActEdiTstQst)
2020-03-03 12:00:36 +01:00
Ico_PutContextualIconToEdit (ActEdiTstQst,NULL,NULL);
2016-11-07 10:35:36 +01:00
/***** Put form to create a new test question *****/
if (Gbl.Action.Act != ActEdiOneTstQst)
2019-01-10 15:26:33 +01:00
Ico_PutContextualIconToAdd (ActEdiOneTstQst,NULL,NULL,
Txt_New_question);
2016-11-07 10:35:36 +01:00
/***** Put form to go to test configuration *****/
2020-02-17 12:00:39 +01:00
Ico_PutContextualIconToConfigure (ActCfgTst,NULL);
2016-11-07 10:35:36 +01:00
}
2019-12-06 19:36:22 +01:00
/***** Put icon to view tests results *****/
2019-12-06 18:42:11 +01:00
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_STD:
2019-12-08 14:14:29 +01:00
Ico_PutContextualIconToShowResults (ActReqSeeMyTstRes,NULL,NULL);
2019-12-06 18:42:11 +01:00
break;
case Rol_NET:
case Rol_TCH:
case Rol_SYS_ADM:
2019-12-08 14:14:29 +01:00
Ico_PutContextualIconToShowResults (ActReqSeeUsrTstRes,NULL,NULL);
2019-12-06 18:42:11 +01:00
break;
default:
break;
}
2016-11-07 10:35:36 +01:00
/***** Put icon to show a figure *****/
2019-02-12 14:46:14 +01:00
Gbl.Figures.FigureType = Fig_TESTS;
Fig_PutIconToShowFigure ();
2014-12-01 23:55:08 +01:00
}
2016-03-21 02:13:19 +01:00
/*****************************************************************************/
/**************** Put button to create a new test question *******************/
/*****************************************************************************/
2017-09-07 12:00:01 +02:00
static void Tst_PutButtonToAddQuestion (void)
2016-03-21 02:13:19 +01:00
{
extern const char *Txt_New_question;
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActEdiOneTstQst);
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButton (Txt_New_question);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-03-21 02:13:19 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** Form to rename tags ***************************/
/*****************************************************************************/
void Tst_ShowFormConfig (void)
{
extern const char *Txt_Please_specify_if_you_allow_access_to_test_questions_from_mobile_applications;
/***** If current course has tests and pluggable is unknown... *****/
if (Tst_CheckIfCourseHaveTestsAndPluggableIsUnknown ())
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_Please_specify_if_you_allow_access_to_test_questions_from_mobile_applications);
2014-12-01 23:55:08 +01:00
/***** Form to configure test *****/
Tst_ShowFormConfigTst ();
/***** Form to edit tags *****/
Tst_ShowFormEditTags ();
}
/*****************************************************************************/
/******************************* Enable a test tag ***************************/
/*****************************************************************************/
void Tst_EnableTag (void)
{
long TagCod = Tst_GetParamTagCode ();
/***** Change tag status to enabled *****/
Tst_EnableOrDisableTag (TagCod,false);
/***** Show again the form to configure test *****/
Tst_ShowFormConfig ();
}
/*****************************************************************************/
/****************************** Disable a test tag ***************************/
/*****************************************************************************/
void Tst_DisableTag (void)
{
long TagCod = Tst_GetParamTagCode ();
/***** Change tag status to disabled *****/
Tst_EnableOrDisableTag (TagCod,true);
/***** Show again the form to configure test *****/
Tst_ShowFormConfig ();
}
/*****************************************************************************/
/************************* Get parameter with tag code ***********************/
/*****************************************************************************/
static long Tst_GetParamTagCode (void)
{
long TagCod;
2017-01-28 20:32:50 +01:00
/***** Get tag code *****/
if ((TagCod = Par_GetParToLong ("TagCod")) <= 0)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Code of tag is missing.");
return TagCod;
}
/*****************************************************************************/
/************************ Rename a tag of test questions *********************/
/*****************************************************************************/
void Tst_RenameTag (void)
{
extern const char *Txt_The_tag_X_has_been_renamed_as_Y;
extern const char *Txt_The_tag_X_has_not_changed;
2017-01-28 15:58:46 +01:00
char OldTagTxt[Tst_MAX_BYTES_TAG + 1];
char NewTagTxt[Tst_MAX_BYTES_TAG + 1];
2016-05-31 20:28:17 +02:00
long ExistingTagCod;
2014-12-01 23:55:08 +01:00
long OldTagCod;
2016-05-31 20:28:17 +02:00
bool ComplexRenaming;
2014-12-01 23:55:08 +01:00
/***** Get old and new tags from the form *****/
Par_GetParToText ("OldTagTxt",OldTagTxt,Tst_MAX_BYTES_TAG);
Par_GetParToText ("NewTagTxt",NewTagTxt,Tst_MAX_BYTES_TAG);
/***** Check that the new tag is not empty *****/
2019-12-20 00:30:54 +01:00
if (NewTagTxt[0]) // New tag not empty
2016-05-31 20:28:17 +02:00
{
/***** Check if the old tag is equal to the new one *****/
if (!strcmp (OldTagTxt,NewTagTxt)) // The old and the new tag
// are exactly the same (case sensitively).
// This happens when user press INTRO
// without changing anything in the form.
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_INFO,Txt_The_tag_X_has_not_changed,
NewTagTxt);
2016-05-31 20:28:17 +02:00
else // The old and the new tag
// are not exactly the same (case sensitively).
{
/***** Check if renaming is complex or easy *****/
ComplexRenaming = false;
if (strcasecmp (OldTagTxt,NewTagTxt)) // The old and the new tag
// are not the same (case insensitively)
/* Check if the new tag text is equal to any of the tags
already present in the database */
if ((ExistingTagCod = Tst_GetTagCodFromTagTxt (NewTagTxt)) > 0)
// The new tag was already in database
ComplexRenaming = true;
if (ComplexRenaming) // Renaming is not easy
{
/***** Complex update made to not repeat tags:
- If the new tag existed for a question ==>
delete old tag from tst_question_tags;
the new tag will remain
- If the new tag did not exist for a question ==>
change old tag to new tag in tst_question_tags *****/
/* Get tag code of the old tag */
if ((OldTagCod = Tst_GetTagCodFromTagTxt (OldTagTxt)) < 0)
Lay_ShowErrorAndExit ("Tag does not exists.");
/* Create a temporary table with all the question codes
that had the new tag as one of their tags */
2018-11-02 22:41:02 +01:00
DB_Query ("can not remove temporary table",
"DROP TEMPORARY TABLE IF EXISTS tst_question_tags_tmp");
2018-10-29 11:13:21 +01:00
2018-11-02 22:41:02 +01:00
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE tst_question_tags_tmp"
" ENGINE=MEMORY"
" SELECT QstCod FROM tst_question_tags"
" WHERE TagCod=%ld",
ExistingTagCod);
2016-05-31 20:28:17 +02:00
/* Remove old tag in questions where it would be repeated */
2017-03-13 19:02:15 +01:00
// New tag existed for a question ==> delete old tag
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove a tag from some questions",
"DELETE FROM tst_question_tags"
" WHERE TagCod=%ld"
" AND QstCod IN"
" (SELECT QstCod FROM tst_question_tags_tmp)",
OldTagCod);
2016-05-31 20:28:17 +02:00
/* Change old tag to new tag in questions where it would not be repeated */
2017-03-13 19:02:15 +01:00
// New tag did not exist for a question ==> change old tag to new tag
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update a tag in some questions",
"UPDATE tst_question_tags"
" SET TagCod=%ld"
" WHERE TagCod=%ld"
" AND QstCod NOT IN"
" (SELECT QstCod FROM tst_question_tags_tmp)",
ExistingTagCod,
OldTagCod);
2016-05-31 20:28:17 +02:00
/* Drop temporary table, no longer necessary */
2018-11-02 22:41:02 +01:00
DB_Query ("can not remove temporary table",
"DROP TEMPORARY TABLE IF EXISTS tst_question_tags_tmp");
2016-05-31 20:28:17 +02:00
/***** Delete old tag from tst_tags
because it is not longer used *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove old tag",
"DELETE FROM tst_tags WHERE TagCod=%ld",
OldTagCod);
2016-05-31 20:28:17 +02:00
}
else // Renaming is easy
{
/***** Simple update replacing each instance of the old tag by the new tag *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update tag",
"UPDATE tst_tags SET TagTxt='%s',ChangeTime=NOW()"
" WHERE tst_tags.CrsCod=%ld"
" AND tst_tags.TagTxt='%s'",
2019-04-04 10:45:15 +02:00
NewTagTxt,Gbl.Hierarchy.Crs.CrsCod,OldTagTxt);
2016-05-31 20:28:17 +02:00
}
/***** Write message to show the change made *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_The_tag_X_has_been_renamed_as_Y,
OldTagTxt,NewTagTxt);
2016-05-31 20:28:17 +02:00
}
2016-05-31 11:21:04 +02:00
}
2019-12-20 00:30:54 +01:00
else // New tag empty
Ale_ShowAlertYouCanNotLeaveFieldEmpty ();
2014-12-01 23:55:08 +01:00
/***** Show again the form to configure test *****/
Tst_ShowFormConfig ();
}
/*****************************************************************************/
/******************* Check if current course has test tags *******************/
/*****************************************************************************/
// Return the number of rows of the result
static bool Tst_CheckIfCurrentCrsHasTestTags (void)
{
/***** Get available tags from database *****/
2018-11-03 20:52:00 +01:00
return (DB_QueryCOUNT ("can not check if course has tags",
2018-11-04 20:51:38 +01:00
"SELECT COUNT(*) FROM tst_tags"
" WHERE CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod) != 0);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********* Get all (enabled or disabled) test tags for this course ***********/
/*****************************************************************************/
// Return the number of rows of the result
static unsigned long Tst_GetAllTagsFromCurrentCrs (MYSQL_RES **mysql_res)
{
/***** Get available tags from database *****/
2018-11-02 01:38:44 +01:00
return DB_QuerySELECT (mysql_res,"can not get available tags",
2019-03-18 15:42:22 +01:00
"SELECT TagCod," // row[0]
"TagTxt," // row[1]
"TagHidden" // row[2]
" FROM tst_tags"
2018-11-02 01:38:44 +01:00
" WHERE CrsCod=%ld"
" ORDER BY TagTxt",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************** Get enabled test tags for this course ****************/
/*****************************************************************************/
// Return the number of rows of the result
static unsigned long Tst_GetEnabledTagsFromThisCrs (MYSQL_RES **mysql_res)
{
/***** Get available not hidden tags from database *****/
2018-11-02 01:38:44 +01:00
return DB_QuerySELECT (mysql_res,"can not get available enabled tags",
2020-03-07 00:14:35 +01:00
"SELECT TagCod," // row[0]
"TagTxt" // row[1]
" FROM tst_tags"
2018-11-02 01:38:44 +01:00
" WHERE CrsCod=%ld AND TagHidden='N'"
" ORDER BY TagTxt",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Show a form to select test tags ***********************/
/*****************************************************************************/
2016-03-21 01:28:16 +01:00
static void Tst_ShowFormSelTags (unsigned long NumRows,MYSQL_RES *mysql_res,
2019-12-09 12:56:21 +01:00
bool ShowOnlyEnabledTags)
2014-12-01 23:55:08 +01:00
{
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2015-04-01 12:54:25 +02:00
extern const char *Txt_Tags;
extern const char *Txt_All_tags;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Tag_not_allowed;
extern const char *Txt_Tag_allowed;
unsigned long NumRow;
MYSQL_ROW row;
bool TagHidden = false;
2019-11-04 20:41:35 +01:00
bool Checked;
2014-12-01 23:55:08 +01:00
const char *Ptr;
2017-01-28 15:58:46 +01:00
char TagText[Tst_MAX_BYTES_TAG + 1];
2019-03-18 15:42:22 +01:00
/*
row[0] TagCod
row[1] TagTxt
row[2] TagHidden
*/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2014-12-01 23:55:08 +01:00
2016-03-21 01:28:16 +01:00
/***** Label *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"RT %s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_Tags);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Select all tags *****/
2019-12-09 12:56:21 +01:00
HTM_TD_Begin ("class=\"LT\"");
2019-10-10 00:49:39 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginPadding (2);
HTM_TR_Begin (NULL);
2014-12-01 23:55:08 +01:00
if (!ShowOnlyEnabledTags)
2019-10-23 19:05:05 +02:00
HTM_TD_Empty (1);
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2020-03-12 13:53:37 +01:00
HTM_INPUT_CHECKBOX ("AllTags",HTM_DONT_SUBMIT_ON_CHANGE,
2019-11-04 20:41:35 +01:00
"value=\"Y\"%s onclick=\"togglecheckChildren(this,'ChkTag');\"",
2020-03-12 13:53:37 +01:00
Gbl.Test.Tags.All ? " checked=\"checked\"" :
"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%s",Txt_All_tags);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Select tags one by one *****/
for (NumRow = 1;
NumRow <= NumRows;
NumRow++)
{
row = mysql_fetch_row (mysql_res);
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-10 10:41:00 +02:00
2014-12-01 23:55:08 +01:00
if (!ShowOnlyEnabledTags)
{
2016-09-07 18:48:10 +02:00
TagHidden = (row[2][0] == 'Y');
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2020-02-19 00:45:26 +01:00
Ico_PutIconOff (TagHidden ? "eye-slash-red.svg" :
"eye-green.svg",
2020-02-18 15:40:04 +01:00
TagHidden ? Txt_Tag_not_allowed :
Txt_Tag_allowed);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
}
2019-10-10 10:41:00 +02:00
2019-11-04 20:41:35 +01:00
Checked = false;
2016-04-06 22:27:33 +02:00
if (Gbl.Test.Tags.List)
2014-12-01 23:55:08 +01:00
{
2016-04-06 22:27:33 +02:00
Ptr = Gbl.Test.Tags.List;
2014-12-01 23:55:08 +01:00
while (*Ptr)
{
Par_GetNextStrUntilSeparParamMult (&Ptr,TagText,Tst_MAX_BYTES_TAG);
if (!strcmp (row[1],TagText))
2019-11-04 20:41:35 +01:00
{
Checked = true;
break;
}
2014-12-01 23:55:08 +01:00
}
}
2019-11-04 20:41:35 +01:00
HTM_TD_Begin ("class=\"LM\"");
HTM_LABEL_Begin ("class=\"DAT\"");
2020-03-12 13:53:37 +01:00
HTM_INPUT_CHECKBOX ("ChkTag",HTM_DONT_SUBMIT_ON_CHANGE,
2019-11-04 20:41:35 +01:00
"value=\"%s\"%s onclick=\"checkParent(this,'AllTags');\"",
row[1],
2020-03-12 13:53:37 +01:00
Checked ? " checked=\"checked\"" :
"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%s",row[1]);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
HTM_TD_End ();
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************* Show a form to enable/disable and rename test tags ************/
/*****************************************************************************/
static void Tst_ShowFormEditTags (void)
{
2019-03-27 14:36:57 +01:00
extern const char *Hlp_ASSESSMENT_Tests_writing_a_question;
2016-03-21 02:13:19 +01:00
extern const char *Txt_No_test_questions;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Tags;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2019-11-07 14:34:03 +01:00
unsigned long NumRows;
unsigned long NumRow;
2014-12-01 23:55:08 +01:00
long TagCod;
/***** Get current tags in current course *****/
2016-03-21 02:13:19 +01:00
if ((NumRows = Tst_GetAllTagsFromCurrentCrs (&mysql_res)))
2014-12-01 23:55:08 +01:00
{
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableBegin (NULL,Txt_Tags,NULL,
2019-03-27 14:36:57 +01:00
Hlp_ASSESSMENT_Tests_writing_a_question,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
/***** Show tags *****/
for (NumRow = 0;
NumRow < NumRows;
NumRow++)
{
row = mysql_fetch_row (mysql_res);
2019-03-18 15:42:22 +01:00
/*
row[0] TagCod
row[1] TagTxt
row[2] TagHidden
*/
2014-12-01 23:55:08 +01:00
if ((TagCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of tag.");
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2014-12-01 23:55:08 +01:00
/* Form to enable / disable this tag */
2016-09-07 18:48:10 +02:00
if (row[2][0] == 'Y') // Tag disabled
2014-12-01 23:55:08 +01:00
Tst_PutIconEnable (TagCod,row[1]);
else
Tst_PutIconDisable (TagCod,row[1]);
/* Form to rename this tag */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRenTag);
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamString (NULL,"OldTagTxt",row[1]);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("NewTagTxt",Tst_MAX_CHARS_TAG,row[1],true,
2020-02-07 00:32:48 +01:00
"size=\"36\" required=\"required\"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-10 10:41:00 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
2014-12-01 23:55:08 +01:00
}
2016-03-21 02:13:19 +01:00
else
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_INFO,Txt_No_test_questions);
2014-12-01 23:55:08 +01:00
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/******************* Put a link and an icon to enable a tag ******************/
/*****************************************************************************/
static void Tst_PutIconEnable (long TagCod,const char *TagTxt)
{
extern const char *Txt_Tag_X_not_allowed_Click_to_allow_it;
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BM\"");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActEnableTag);
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamLong (NULL,"TagCod",TagCod);
2020-02-19 00:45:26 +01:00
Ico_PutIconLink ("eye-slash-red.svg",
2019-12-30 21:47:07 +01:00
Str_BuildStringStr (Txt_Tag_X_not_allowed_Click_to_allow_it,
TagTxt));
Str_FreeString ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Put a link and an icon to disable a tag ******************/
/*****************************************************************************/
static void Tst_PutIconDisable (long TagCod,const char *TagTxt)
{
extern const char *Txt_Tag_X_allowed_Click_to_disable_it;
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BM\"");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActDisableTag);
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamLong (NULL,"TagCod",TagCod);
2020-02-19 00:45:26 +01:00
Ico_PutIconLink ("eye-green.svg",
2019-12-30 21:47:07 +01:00
Str_BuildStringStr (Txt_Tag_X_allowed_Click_to_disable_it,
TagTxt));
Str_FreeString ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Show a form to to configure test **********************/
/*****************************************************************************/
static void Tst_ShowFormConfigTst (void)
{
2016-11-13 20:18:49 +01:00
extern const char *Hlp_ASSESSMENT_Tests;
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Configure_tests;
extern const char *Txt_Plugins;
extern const char *Txt_TST_PLUGGABLE[Tst_NUM_OPTIONS_PLUGGABLE];
extern const char *Txt_No_of_questions;
extern const char *Txt_minimum;
extern const char *Txt_default;
extern const char *Txt_maximum;
extern const char *Txt_Minimum_time_seconds_per_question_between_two_tests;
2020-02-17 09:31:32 +01:00
extern const char *Txt_Result_visibility;
2019-02-18 18:27:45 +01:00
extern const char *Txt_Save_changes;
2014-12-01 23:55:08 +01:00
Tst_Pluggable_t Pluggable;
2019-11-08 01:10:32 +01:00
char StrMinTimeNxtTstPerQst[Cns_MAX_DECIMAL_DIGITS_ULONG + 1];
2014-12-01 23:55:08 +01:00
/***** Read test configuration from database *****/
Tst_GetConfigTstFromDB ();
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,Txt_Configure_tests,Tst_PutIconsTests,
2017-06-12 15:03:29 +02:00
Hlp_ASSESSMENT_Tests,Box_NOT_CLOSABLE);
2016-05-05 12:37:45 +02:00
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRcvCfgTst);
2014-12-01 23:55:08 +01:00
/***** Tests are visible from plugins? *****/
2019-10-25 22:48:34 +02:00
HTM_TABLE_BeginCenterPadding (2);
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RT\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_Plugins);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LB\"");
2014-12-01 23:55:08 +01:00
for (Pluggable = Tst_PLUGGABLE_NO;
Pluggable <= Tst_PLUGGABLE_YES;
Pluggable++)
{
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("class=\"DAT\"");
2019-11-04 18:17:39 +01:00
HTM_INPUT_RADIO ("Pluggable",false,
"value=\"%u\"%s",
(unsigned) Pluggable,
Pluggable == Gbl.Test.Config.Pluggable ? " checked=\"checked\"" : "");
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_TST_PLUGGABLE[Pluggable]);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-11-09 21:08:20 +01:00
HTM_BR ();
2014-12-01 23:55:08 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Number of questions *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RT\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_No_of_questions);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LB\"");
HTM_TABLE_BeginPadding (2);
2016-12-26 15:17:30 +01:00
Tst_PutInputFieldNumQst ("NumQstMin",Txt_minimum,
Gbl.Test.Config.Min); // Minimum number of questions
Tst_PutInputFieldNumQst ("NumQstDef",Txt_default,
Gbl.Test.Config.Def); // Default number of questions
Tst_PutInputFieldNumQst ("NumQstMax",Txt_maximum,
Gbl.Test.Config.Max); // Maximum number of questions
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2016-11-21 13:15:08 +01:00
/***** Minimum time between consecutive tests, per question *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
2019-12-27 21:10:39 +01:00
/* Label */
2019-12-27 15:45:19 +01:00
Frm_LabelColumn ("RT","MinTimeNxtTstPerQst",
Txt_Minimum_time_seconds_per_question_between_two_tests);
2019-10-07 21:15:14 +02:00
2019-12-27 21:10:39 +01:00
/* Data */
2019-12-27 15:45:19 +01:00
HTM_TD_Begin ("class=\"LB\"");
2019-11-04 01:29:46 +01:00
snprintf (StrMinTimeNxtTstPerQst,sizeof (StrMinTimeNxtTstPerQst),
"%lu",
Gbl.Test.Config.MinTimeNxtTstPerQst);
2019-11-08 01:10:32 +01:00
HTM_INPUT_TEXT ("MinTimeNxtTstPerQst",Cns_MAX_DECIMAL_DIGITS_ULONG,StrMinTimeNxtTstPerQst,false,
2019-11-12 15:41:58 +01:00
"id=\"MinTimeNxtTstPerQst\" size=\"7\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2020-02-17 09:31:32 +01:00
/***** Visibility of results *****/
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"%s RT\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
HTM_TxtF ("%s:",Txt_Result_visibility);
HTM_TD_End ();
HTM_TD_Begin ("class=\"LB\"");
2020-02-18 09:19:33 +01:00
TsV_PutVisibilityCheckboxes (Gbl.Test.Config.Visibility);
2020-02-17 09:31:32 +01:00
HTM_TD_End ();
HTM_TR_End ();
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
2016-05-05 12:37:45 +02:00
/***** Send button *****/
2019-02-18 18:27:45 +01:00
Btn_PutConfirmButton (Txt_Save_changes);
2015-04-11 23:46:21 +02:00
2014-12-01 23:55:08 +01:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-05-05 12:37:45 +02:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Get configuration of test for current course ****************/
/*****************************************************************************/
2016-12-26 15:17:30 +01:00
static void Tst_PutInputFieldNumQst (const char *Field,const char *Label,
unsigned Value)
{
2019-11-08 01:10:32 +01:00
char StrValue[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
2019-11-04 01:29:46 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"RM\"");
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("for=\"%s\" class=\"DAT\"",Field);
2019-11-10 12:36:37 +01:00
HTM_Txt (Label);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2019-11-04 01:29:46 +01:00
snprintf (StrValue,sizeof (StrValue),
"%u",
Value);
2019-11-08 01:10:32 +01:00
HTM_INPUT_TEXT (Field,Cns_MAX_DECIMAL_DIGITS_UINT,StrValue,false,
2019-11-12 15:41:58 +01:00
"id=\"%s\" size=\"3\" required=\"required\"",Field);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2016-12-26 15:17:30 +01:00
}
/*****************************************************************************/
/*************** Get configuration of test for current course ****************/
/*****************************************************************************/
2019-09-22 13:54:11 +02:00
void Tst_GetConfigTstFromDB (void)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
/***** Get configuration of test for current course from database *****/
2018-11-02 01:38:44 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get configuration of test",
"SELECT Pluggable," // row[0]
"Min," // row[1]
"Def," // row[2]
"Max," // row[3]
"MinTimeNxtTstPerQst," // row[4]
2020-02-17 12:00:39 +01:00
"Visibility" // row[5]
" FROM tst_config"
" WHERE CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
Gbl.Test.Config.MinTimeNxtTstPerQst = 0UL;
2020-02-18 09:19:33 +01:00
Gbl.Test.Config.Visibility = TsV_VISIBILITY_DEFAULT;
2014-12-01 23:55:08 +01:00
if (NumRows == 0)
{
Gbl.Test.Config.Pluggable = Tst_PLUGGABLE_UNKNOWN;
Gbl.Test.Config.Min = Tst_CONFIG_DEFAULT_MIN_QUESTIONS;
Gbl.Test.Config.Def = Tst_CONFIG_DEFAULT_DEF_QUESTIONS;
Gbl.Test.Config.Max = Tst_CONFIG_DEFAULT_MAX_QUESTIONS;
}
else // NumRows == 1
{
/***** Get minimun, default and maximum *****/
row = mysql_fetch_row (mysql_res);
Tst_GetConfigFromRow (row);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/************ Get configuration values from a database table row *************/
/*****************************************************************************/
void Tst_GetConfigFromRow (MYSQL_ROW row)
{
int IntNum;
long LongNum;
Tst_Pluggable_t Pluggable;
/***** Get whether test are visible via plugins or not *****/
Gbl.Test.Config.Pluggable = Tst_PLUGGABLE_UNKNOWN;
for (Pluggable = Tst_PLUGGABLE_NO;
Pluggable <= Tst_PLUGGABLE_YES;
Pluggable++)
if (!strcmp (row[0],Tst_PluggableDB[Pluggable]))
{
Gbl.Test.Config.Pluggable = Pluggable;
break;
}
/***** Get number of questions *****/
if (sscanf (row[1],"%d",&IntNum) == 1)
Gbl.Test.Config.Min = (IntNum < 1) ? 1 :
(unsigned) IntNum;
else
Gbl.Test.Config.Min = Tst_CONFIG_DEFAULT_MIN_QUESTIONS;
if (sscanf (row[2],"%d",&IntNum) == 1)
Gbl.Test.Config.Def = (IntNum < 1) ? 1 :
(unsigned) IntNum;
else
Gbl.Test.Config.Def = Tst_CONFIG_DEFAULT_DEF_QUESTIONS;
if (sscanf (row[3],"%d",&IntNum) == 1)
Gbl.Test.Config.Max = (IntNum < 1) ? 1 :
(unsigned) IntNum;
else
Gbl.Test.Config.Max = Tst_CONFIG_DEFAULT_MAX_QUESTIONS;
/***** Check and correct numbers *****/
Tst_CheckAndCorrectNumbersQst ();
2016-11-21 13:15:08 +01:00
/***** Get minimum time between consecutive tests, per question (row[4]) *****/
2014-12-01 23:55:08 +01:00
if (sscanf (row[4],"%ld",&LongNum) == 1)
Gbl.Test.Config.MinTimeNxtTstPerQst = (LongNum < 1L) ? 0UL :
(unsigned long) LongNum;
2020-02-17 12:00:39 +01:00
/***** Get visibility (row[5]) *****/
2020-02-18 15:40:04 +01:00
Gbl.Test.Config.Visibility = TsV_GetVisibilityFromStr (row[5]);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Get configuration of test for current course ****************/
/*****************************************************************************/
// Returns true if course has test tags and pluggable is unknown
// Return false if course has no test tags or pluggable is known
bool Tst_CheckIfCourseHaveTestsAndPluggableIsUnknown (void)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
Tst_Pluggable_t Pluggable;
/***** Get pluggability of tests for current course from database *****/
2018-11-02 01:38:44 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get configuration of test",
2019-03-18 15:42:22 +01:00
"SELECT Pluggable" // row[0]
" FROM tst_config"
" WHERE CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
if (NumRows == 0)
Gbl.Test.Config.Pluggable = Tst_PLUGGABLE_UNKNOWN;
else // NumRows == 1
{
/***** Get whether test are visible via plugins or not *****/
row = mysql_fetch_row (mysql_res);
Gbl.Test.Config.Pluggable = Tst_PLUGGABLE_UNKNOWN;
for (Pluggable = Tst_PLUGGABLE_NO;
Pluggable <= Tst_PLUGGABLE_YES;
Pluggable++)
if (!strcmp (row[0],Tst_PluggableDB[Pluggable]))
{
Gbl.Test.Config.Pluggable = Pluggable;
break;
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Get if current course has tests from database *****/
if (Gbl.Test.Config.Pluggable == Tst_PLUGGABLE_UNKNOWN)
return Tst_CheckIfCurrentCrsHasTestTags (); // Return true if course has tests
return false; // Pluggable is not unknown
}
/*****************************************************************************/
/************* Receive configuration of test for current course **************/
/*****************************************************************************/
void Tst_ReceiveConfigTst (void)
{
extern const char *Txt_The_test_configuration_has_been_updated;
/***** Get whether test are visible via plugins or not *****/
Gbl.Test.Config.Pluggable = Tst_GetPluggableFromForm ();
/***** Get number of questions *****/
/* Get minimum number of questions */
2017-01-29 21:41:08 +01:00
Gbl.Test.Config.Min = (unsigned)
Par_GetParToUnsignedLong ("NumQstMin",
1,
UINT_MAX,
1);
2014-12-01 23:55:08 +01:00
/* Get default number of questions */
2017-01-29 21:41:08 +01:00
Gbl.Test.Config.Def = (unsigned)
Par_GetParToUnsignedLong ("NumQstDef",
1,
UINT_MAX,
1);
2014-12-01 23:55:08 +01:00
/* Get maximum number of questions */
2017-01-29 21:41:08 +01:00
Gbl.Test.Config.Max = (unsigned)
Par_GetParToUnsignedLong ("NumQstMax",
1,
UINT_MAX,
1);
2014-12-01 23:55:08 +01:00
/* Check and correct numbers */
Tst_CheckAndCorrectNumbersQst ();
2016-11-21 13:15:08 +01:00
/***** Get minimum time between consecutive tests, per question *****/
2017-01-29 21:41:08 +01:00
Gbl.Test.Config.MinTimeNxtTstPerQst = Par_GetParToUnsignedLong ("MinTimeNxtTstPerQst",
0,
ULONG_MAX,
0);
2014-12-01 23:55:08 +01:00
2020-02-18 15:40:04 +01:00
/***** Get visibility from form *****/
2020-02-18 09:19:33 +01:00
Gbl.Test.Config.Visibility = TsV_GetVisibilityFromForm ();
2014-12-01 23:55:08 +01:00
/***** Update database *****/
2018-11-02 16:39:35 +01:00
DB_QueryREPLACE ("can not save configuration of tests",
"REPLACE INTO tst_config"
2020-02-17 12:00:39 +01:00
" (CrsCod,Pluggable,Min,Def,Max,MinTimeNxtTstPerQst,Visibility)"
2018-11-02 16:39:35 +01:00
" VALUES"
2020-02-17 12:00:39 +01:00
" (%ld,'%s',%u,%u,%u,'%lu',%u)",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-11-02 16:39:35 +01:00
Tst_PluggableDB[Gbl.Test.Config.Pluggable],
Gbl.Test.Config.Min,Gbl.Test.Config.Def,Gbl.Test.Config.Max,
Gbl.Test.Config.MinTimeNxtTstPerQst,
2020-02-17 12:00:39 +01:00
Gbl.Test.Config.Visibility);
2014-12-01 23:55:08 +01:00
/***** Show confirmation message *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_The_test_configuration_has_been_updated);
2014-12-01 23:55:08 +01:00
/***** Show again the form to configure test *****/
Tst_ShowFormConfig ();
}
/*****************************************************************************/
/******************* Get if tests are pluggable from form ********************/
/*****************************************************************************/
static Tst_Pluggable_t Tst_GetPluggableFromForm (void)
{
2017-01-29 21:41:08 +01:00
return (Tst_Pluggable_t)
Par_GetParToUnsignedLong ("Pluggable",
0,
Tst_NUM_OPTIONS_PLUGGABLE - 1,
(unsigned long) Tst_PLUGGABLE_UNKNOWN);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**** Check and correct minimum, default and maximum numbers of questions ****/
/*****************************************************************************/
static void Tst_CheckAndCorrectNumbersQst (void)
{
/***** Check if minimum is correct *****/
if (Gbl.Test.Config.Min < 1)
Gbl.Test.Config.Min = 1;
2016-11-21 13:15:08 +01:00
else if (Gbl.Test.Config.Min > Tst_MAX_QUESTIONS_PER_TEST)
Gbl.Test.Config.Min = Tst_MAX_QUESTIONS_PER_TEST;
2014-12-01 23:55:08 +01:00
/***** Check if maximum is correct *****/
if (Gbl.Test.Config.Max < 1)
Gbl.Test.Config.Max = 1;
2016-11-21 13:15:08 +01:00
else if (Gbl.Test.Config.Max > Tst_MAX_QUESTIONS_PER_TEST)
Gbl.Test.Config.Max = Tst_MAX_QUESTIONS_PER_TEST;
2014-12-01 23:55:08 +01:00
/***** Check if minimum is lower than maximum *****/
if (Gbl.Test.Config.Min > Gbl.Test.Config.Max)
Gbl.Test.Config.Min = Gbl.Test.Config.Max;
/***** Check if default is correct *****/
if (Gbl.Test.Config.Def < Gbl.Test.Config.Min)
Gbl.Test.Config.Def = Gbl.Test.Config.Min;
else if (Gbl.Test.Config.Def > Gbl.Test.Config.Max)
Gbl.Test.Config.Def = Gbl.Test.Config.Max;
}
/*****************************************************************************/
/***************** Show form for select the types of answers *****************/
/*****************************************************************************/
2019-12-09 12:56:21 +01:00
static void Tst_ShowFormAnswerTypes (void)
2014-12-01 23:55:08 +01:00
{
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2015-04-01 12:54:25 +02:00
extern const char *Txt_Types_of_answers;
2014-12-01 23:55:08 +01:00
extern const char *Txt_All_types_of_answers;
extern const char *Txt_TST_STR_ANSWER_TYPES[Tst_NUM_ANS_TYPES];
Tst_AnswerType_t AnsType;
2019-11-04 20:41:35 +01:00
bool Checked;
2019-11-08 01:10:32 +01:00
char UnsignedStr[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
2014-12-01 23:55:08 +01:00
const char *Ptr;
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
/***** Label *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"RT %s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_Types_of_answers);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Select all types of answers *****/
2019-12-09 12:56:21 +01:00
HTM_TD_Begin ("class=\"LT\"");
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginPadding (2);
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2020-03-12 13:53:37 +01:00
HTM_INPUT_CHECKBOX ("AllAnsTypes",HTM_DONT_SUBMIT_ON_CHANGE,
2019-11-04 20:41:35 +01:00
"value=\"Y\"%s onclick=\"togglecheckChildren(this,'AnswerType');\"",
2020-03-12 13:53:37 +01:00
Gbl.Test.AllAnsTypes ? " checked=\"checked\"" :
"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%s",Txt_All_types_of_answers);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Type of answer *****/
2019-12-15 20:02:34 +01:00
for (AnsType = (Tst_AnswerType_t) 0;
AnsType <= (Tst_AnswerType_t) (Tst_NUM_ANS_TYPES - 1);
2014-12-01 23:55:08 +01:00
AnsType++)
{
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
2019-11-04 20:41:35 +01:00
Checked = false;
2014-12-01 23:55:08 +01:00
Ptr = Gbl.Test.ListAnsTypes;
while (*Ptr)
{
2019-11-08 01:10:32 +01:00
Par_GetNextStrUntilSeparParamMult (&Ptr,UnsignedStr,Cns_MAX_DECIMAL_DIGITS_UINT);
2014-12-01 23:55:08 +01:00
if (Tst_ConvertFromUnsignedStrToAnsTyp (UnsignedStr) == AnsType)
2019-11-04 20:41:35 +01:00
{
Checked = true;
break;
}
2014-12-01 23:55:08 +01:00
}
2019-11-04 20:41:35 +01:00
HTM_TD_Begin ("class=\"LM\"");
HTM_LABEL_Begin ("class=\"DAT\"");
2020-03-12 13:53:37 +01:00
HTM_INPUT_CHECKBOX ("AnswerType",HTM_DONT_SUBMIT_ON_CHANGE,
2019-11-04 20:41:35 +01:00
"value=\"%u\"%s onclick=\"checkParent(this,'AllAnsTypes');\"",
(unsigned) AnsType,
2020-03-12 13:53:37 +01:00
Checked ? " checked=\"checked\"" :
"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%s",Txt_TST_STR_ANSWER_TYPES[AnsType]);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
HTM_TD_End ();
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** List several test questions for edition *******************/
/*****************************************************************************/
void Tst_ListQuestionsToEdit (void)
{
MYSQL_RES *mysql_res;
unsigned long NumRows;
/***** Get parameters, query the database and list the questions *****/
2017-09-04 17:03:49 +02:00
if (Tst_GetParamsTst (Tst_EDIT_TEST)) // Get parameters from the form
2014-12-01 23:55:08 +01:00
{
2017-07-16 13:54:11 +02:00
if ((NumRows = Tst_GetQuestions (&mysql_res)) != 0) // Query database
2014-12-01 23:55:08 +01:00
{
2019-10-24 09:46:20 +02:00
/***** Contextual menu *****/
Mnu_ContextMenuBegin ();
2014-12-01 23:55:08 +01:00
if (Gbl.Test.XML.CreateXML)
2019-10-24 09:46:20 +02:00
TsI_CreateXML (NumRows,mysql_res); // Create XML file with exported questions...
// ...and put a link to download it
2014-12-01 23:55:08 +01:00
else
2019-10-24 09:46:20 +02:00
TsI_PutFormToExportQuestions (); // Export questions
Mnu_ContextMenuEnd ();
2014-12-01 23:55:08 +01:00
2017-03-13 19:02:15 +01:00
/* Show the table with the questions */
2017-07-16 20:50:01 +02:00
Tst_ListOneOrMoreQuestionsForEdition (NumRows,mysql_res);
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
else
2017-03-13 19:02:15 +01:00
/* Show the form again */
Tst_ShowFormAskEditTsts ();
2014-12-01 23:55:08 +01:00
/***** Free memory used by the list of tags *****/
Tst_FreeTagsList ();
}
2017-07-16 13:54:11 +02:00
/*****************************************************************************/
/**************** List several test questions for selection ******************/
/*****************************************************************************/
2019-09-29 17:33:39 +02:00
void Tst_ListQuestionsToSelect (void)
2017-07-16 13:54:11 +02:00
{
MYSQL_RES *mysql_res;
unsigned long NumRows;
/***** Get parameters, query the database and list the questions *****/
if (Tst_GetParamsTst (Tst_SELECT_QUESTIONS_FOR_GAME)) // Get parameters from the form
{
if ((NumRows = Tst_GetQuestions (&mysql_res)) != 0) // Query database
/* Show the table with the questions */
2019-09-29 17:33:39 +02:00
Tst_ListOneOrMoreQuestionsForSelection (NumRows,mysql_res);
2017-07-16 13:54:11 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
else
/* Show the form again */
2019-09-29 17:33:39 +02:00
Tst_ShowFormAskSelectTstsForGame ();
2017-07-16 13:54:11 +02:00
/***** Free memory used by the list of tags *****/
Tst_FreeTagsList ();
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********** Get from the database several test questions for listing *********/
/*****************************************************************************/
2017-03-08 03:48:23 +01:00
#define Tst_MAX_BYTES_QUERY_TEST (16 * 1024 - 1)
2014-12-01 23:55:08 +01:00
2017-07-16 13:54:11 +02:00
static unsigned long Tst_GetQuestions (MYSQL_RES **mysql_res)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_No_questions_found_matching_your_search_criteria;
2018-10-30 03:29:40 +01:00
char *Query = NULL;
2014-12-01 23:55:08 +01:00
unsigned long NumRows;
long LengthQuery;
unsigned NumItemInList;
const char *Ptr;
2017-01-16 01:51:01 +01:00
char TagText[Tst_MAX_BYTES_TAG + 1];
2019-11-08 01:10:32 +01:00
char LongStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1];
char UnsignedStr[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
2014-12-01 23:55:08 +01:00
Tst_AnswerType_t AnsType;
2019-11-08 01:10:32 +01:00
char CrsCodStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1];
2014-12-01 23:55:08 +01:00
2018-10-29 22:22:02 +01:00
/***** Allocate space for query *****/
2018-10-30 02:37:09 +01:00
if ((Query = (char *) malloc (Tst_MAX_BYTES_QUERY_TEST + 1)) == NULL)
2018-10-29 22:22:02 +01:00
Lay_NotEnoughMemoryExit ();
2014-12-01 23:55:08 +01:00
/***** Select questions *****/
/* Start query */
2018-10-30 02:37:09 +01:00
snprintf (Query,Tst_MAX_BYTES_QUERY_TEST + 1,
2019-03-18 15:42:22 +01:00
"SELECT tst_questions.QstCod," // row[0]
"UNIX_TIMESTAMP(tst_questions.EditTime)," // row[1]
"tst_questions.AnsType," // row[2]
"tst_questions.Shuffle," // row[3]
"tst_questions.Stem," // row[4]
"tst_questions.Feedback," // row[5]
"tst_questions.MedCod," // row[6]
"tst_questions.NumHits," // row[7]
"tst_questions.NumHitsNotBlank," // row[8]
"tst_questions.Score" // row[9]
2018-10-29 22:22:02 +01:00
" FROM tst_questions");
2016-04-06 22:27:33 +02:00
if (!Gbl.Test.Tags.All)
2018-10-30 02:37:09 +01:00
Str_Concat (Query,",tst_question_tags,tst_tags",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
2018-10-30 02:37:09 +01:00
Str_Concat (Query," WHERE tst_questions.CrsCod='",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-18 02:02:32 +02:00
snprintf (CrsCodStr,sizeof (CrsCodStr),
"%ld",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,CrsCodStr,
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,"' AND tst_questions.EditTime>=FROM_UNIXTIME('",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-18 02:02:32 +02:00
snprintf (LongStr,sizeof (LongStr),
"%ld",
2020-02-14 10:02:58 +01:00
(long) Gbl.DateRange.TimeUTC[Dat_START_TIME]);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,LongStr,
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,"') AND tst_questions.EditTime<=FROM_UNIXTIME('",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-18 02:02:32 +02:00
snprintf (LongStr,sizeof (LongStr),
"%ld",
2020-02-14 10:02:58 +01:00
(long) Gbl.DateRange.TimeUTC[Dat_END_TIME]);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,LongStr,
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,"')",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
/* Add the tags selected */
2016-04-06 22:27:33 +02:00
if (!Gbl.Test.Tags.All)
2014-12-01 23:55:08 +01:00
{
2018-10-30 02:37:09 +01:00
Str_Concat (Query," AND tst_questions.QstCod=tst_question_tags.QstCod"
2017-01-16 01:51:01 +01:00
" AND tst_question_tags.TagCod=tst_tags.TagCod"
2017-01-17 03:33:05 +01:00
" AND tst_tags.CrsCod='",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,CrsCodStr,
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,"'",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-30 02:37:09 +01:00
LengthQuery = strlen (Query);
2014-12-01 23:55:08 +01:00
NumItemInList = 0;
2016-04-06 22:27:33 +02:00
Ptr = Gbl.Test.Tags.List;
2014-12-01 23:55:08 +01:00
while (*Ptr)
{
Par_GetNextStrUntilSeparParamMult (&Ptr,TagText,Tst_MAX_BYTES_TAG);
LengthQuery = LengthQuery + 35 + strlen (TagText) + 1;
2017-03-08 03:48:23 +01:00
if (LengthQuery > Tst_MAX_BYTES_QUERY_TEST - 256)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Query size exceed.");
2018-10-30 02:37:09 +01:00
Str_Concat (Query,
2017-01-16 01:51:01 +01:00
NumItemInList ? " OR tst_tags.TagTxt='" :
" AND (tst_tags.TagTxt='",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,TagText,
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,"'",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
NumItemInList++;
}
2018-10-30 02:37:09 +01:00
Str_Concat (Query,")",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
}
/* Add the types of answer selected */
if (!Gbl.Test.AllAnsTypes)
{
2018-10-30 02:37:09 +01:00
LengthQuery = strlen (Query);
2014-12-01 23:55:08 +01:00
NumItemInList = 0;
Ptr = Gbl.Test.ListAnsTypes;
while (*Ptr)
{
Par_GetNextStrUntilSeparParamMult (&Ptr,UnsignedStr,Tst_MAX_BYTES_TAG);
AnsType = Tst_ConvertFromUnsignedStrToAnsTyp (UnsignedStr);
LengthQuery = LengthQuery + 35 + strlen (Tst_StrAnswerTypesDB[AnsType]) + 1;
2017-03-08 03:48:23 +01:00
if (LengthQuery > Tst_MAX_BYTES_QUERY_TEST - 256)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Query size exceed.");
2018-10-30 02:37:09 +01:00
Str_Concat (Query,
2017-01-16 01:51:01 +01:00
NumItemInList ? " OR tst_questions.AnsType='" :
" AND (tst_questions.AnsType='",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,Tst_StrAnswerTypesDB[AnsType],
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,"'",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
NumItemInList++;
}
2018-10-30 02:37:09 +01:00
Str_Concat (Query,")",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
}
/* End the query */
2018-10-30 02:37:09 +01:00
Str_Concat (Query," GROUP BY tst_questions.QstCod",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
2017-01-29 12:42:19 +01:00
switch (Gbl.Test.SelectedOrder)
2014-12-01 23:55:08 +01:00
{
case Tst_ORDER_STEM:
2018-10-30 02:37:09 +01:00
Str_Concat (Query," ORDER BY tst_questions.Stem",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
break;
case Tst_ORDER_NUM_HITS:
2018-10-30 02:37:09 +01:00
Str_Concat (Query," ORDER BY tst_questions.NumHits DESC,"
2018-10-29 22:22:02 +01:00
"tst_questions.Stem",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
break;
case Tst_ORDER_AVERAGE_SCORE:
2018-10-30 02:37:09 +01:00
Str_Concat (Query," ORDER BY tst_questions.Score/tst_questions.NumHits DESC,"
2018-10-29 22:22:02 +01:00
"tst_questions.NumHits DESC,"
"tst_questions.Stem",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
break;
case Tst_ORDER_NUM_HITS_NOT_BLANK:
2018-10-30 02:37:09 +01:00
Str_Concat (Query," ORDER BY tst_questions.NumHitsNotBlank DESC,"
2018-10-29 22:22:02 +01:00
"tst_questions.Stem",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
break;
case Tst_ORDER_AVERAGE_SCORE_NOT_BLANK:
2018-10-30 02:37:09 +01:00
Str_Concat (Query," ORDER BY tst_questions.Score/tst_questions.NumHitsNotBlank DESC,"
2018-10-29 22:22:02 +01:00
"tst_questions.NumHitsNotBlank DESC,"
"tst_questions.Stem",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
break;
}
/* Make the query */
2018-11-14 23:40:56 +01:00
NumRows = DB_QuerySELECT (mysql_res,"can not get questions",
"%s",
Query);
2014-12-01 23:55:08 +01:00
if (NumRows == 0)
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_INFO,Txt_No_questions_found_matching_your_search_criteria);
2014-12-01 23:55:08 +01:00
return NumRows;
}
/*****************************************************************************/
/********* Get from the database several test questions to list them *********/
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
static unsigned long Tst_GetQuestionsForTest (MYSQL_RES **mysql_res)
2014-12-01 23:55:08 +01:00
{
2018-10-30 03:29:40 +01:00
char *Query = NULL;
2014-12-01 23:55:08 +01:00
long LengthQuery;
unsigned NumItemInList;
const char *Ptr;
2017-01-28 15:58:46 +01:00
char TagText[Tst_MAX_BYTES_TAG + 1];
2019-11-08 01:10:32 +01:00
char UnsignedStr[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
2014-12-01 23:55:08 +01:00
Tst_AnswerType_t AnsType;
2019-11-08 01:10:32 +01:00
char StrNumQsts[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
2014-12-01 23:55:08 +01:00
2018-10-29 22:22:02 +01:00
/***** Allocate space for query *****/
2018-10-30 02:37:09 +01:00
if ((Query = (char *) malloc (Tst_MAX_BYTES_QUERY_TEST + 1)) == NULL)
2018-10-29 22:22:02 +01:00
Lay_NotEnoughMemoryExit ();
2014-12-01 23:55:08 +01:00
/***** Select questions without hidden tags *****/
/* Start query */
// Reject questions with any tag hidden
// Select only questions with tags
2015-06-16 20:12:38 +02:00
// DISTINCTROW is necessary to not repeat questions
2018-10-30 02:37:09 +01:00
snprintf (Query,Tst_MAX_BYTES_QUERY_TEST + 1,
2019-03-18 15:42:22 +01:00
"SELECT DISTINCTROW tst_questions.QstCod," // row[0]
"UNIX_TIMESTAMP(tst_questions.EditTime)," // row[1]
"tst_questions.AnsType," // row[2]
"tst_questions.Shuffle," // row[3]
"tst_questions.Stem," // row[4]
"tst_questions.Feedback," // row[5]
"tst_questions.MedCod," // row[6]
"tst_questions.NumHits," // row[7]
"tst_questions.NumHitsNotBlank," // row[8]
"tst_questions.Score" // row[9]
2018-10-29 22:22:02 +01:00
" FROM tst_questions,tst_question_tags,tst_tags"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod NOT IN"
" (SELECT tst_question_tags.QstCod"
" FROM tst_tags,tst_question_tags"
" WHERE tst_tags.CrsCod=%ld AND tst_tags.TagHidden='Y'"
" AND tst_tags.TagCod=tst_question_tags.TagCod)"
" AND tst_questions.QstCod=tst_question_tags.QstCod"
" AND tst_question_tags.TagCod=tst_tags.TagCod"
" AND tst_tags.CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
Gbl.Hierarchy.Crs.CrsCod,
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
2016-04-06 22:27:33 +02:00
if (!Gbl.Test.Tags.All) // User has not selected all the tags
2014-12-01 23:55:08 +01:00
{
/* Add selected tags */
2018-10-30 02:37:09 +01:00
LengthQuery = strlen (Query);
2014-12-01 23:55:08 +01:00
NumItemInList = 0;
2016-04-06 22:27:33 +02:00
Ptr = Gbl.Test.Tags.List;
2014-12-01 23:55:08 +01:00
while (*Ptr)
{
Par_GetNextStrUntilSeparParamMult (&Ptr,TagText,Tst_MAX_BYTES_TAG);
LengthQuery = LengthQuery + 35 + strlen (TagText) + 1;
2017-03-08 03:48:23 +01:00
if (LengthQuery > Tst_MAX_BYTES_QUERY_TEST - 128)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Query size exceed.");
2018-10-30 02:37:09 +01:00
Str_Concat (Query,
2017-01-16 01:51:01 +01:00
NumItemInList ? " OR tst_tags.TagTxt='" :
" AND (tst_tags.TagTxt='",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,TagText,
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,"'",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
NumItemInList++;
}
2018-10-30 02:37:09 +01:00
Str_Concat (Query,")",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
}
/* Add answer types selected */
if (!Gbl.Test.AllAnsTypes)
{
2018-10-30 02:37:09 +01:00
LengthQuery = strlen (Query);
2014-12-01 23:55:08 +01:00
NumItemInList = 0;
Ptr = Gbl.Test.ListAnsTypes;
while (*Ptr)
{
Par_GetNextStrUntilSeparParamMult (&Ptr,UnsignedStr,Tst_MAX_BYTES_TAG);
AnsType = Tst_ConvertFromUnsignedStrToAnsTyp (UnsignedStr);
LengthQuery = LengthQuery + 35 + strlen (Tst_StrAnswerTypesDB[AnsType]) + 1;
2017-03-08 03:48:23 +01:00
if (LengthQuery > Tst_MAX_BYTES_QUERY_TEST - 128)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Query size exceed.");
2018-10-30 02:37:09 +01:00
Str_Concat (Query,
2017-01-16 01:51:01 +01:00
NumItemInList ? " OR tst_questions.AnsType='" :
" AND (tst_questions.AnsType='",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,Tst_StrAnswerTypesDB[AnsType],
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,"'",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
NumItemInList++;
}
2018-10-30 02:37:09 +01:00
Str_Concat (Query,")",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2014-12-01 23:55:08 +01:00
}
/* End query */
2018-10-30 02:37:09 +01:00
Str_Concat (Query," ORDER BY RAND(NOW()) LIMIT ",
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2018-10-18 02:02:32 +02:00
snprintf (StrNumQsts,sizeof (StrNumQsts),
"%u",
Gbl.Test.NumQsts);
2018-10-30 02:37:09 +01:00
Str_Concat (Query,StrNumQsts,
2017-03-08 03:48:23 +01:00
Tst_MAX_BYTES_QUERY_TEST);
2015-06-15 12:30:09 +02:00
/*
2017-06-04 14:22:04 +02:00
if (Gbl.Usrs.Me.Roles.LoggedRole == Rol_SYS_ADM)
2014-12-01 23:55:08 +01:00
Lay_ShowAlert (Lay_INFO,Query);
2015-06-15 12:30:09 +02:00
*/
2014-12-01 23:55:08 +01:00
/* Make the query */
2018-11-14 23:40:56 +01:00
return DB_QuerySELECT (mysql_res,"can not get questions",
"%s",
Query);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** List a test question for edition ********************/
/*****************************************************************************/
static void Tst_ListOneQstToEdit (void)
{
MYSQL_RES *mysql_res;
/***** Query database *****/
if (Tst_GetOneQuestionByCod (Gbl.Test.QstCod,&mysql_res))
/***** Show the question ready to edit it *****/
2017-07-16 20:50:01 +02:00
Tst_ListOneOrMoreQuestionsForEdition (1,mysql_res);
2014-12-01 23:55:08 +01:00
else
Lay_ShowErrorAndExit ("Can not get question.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/*********************** Get data of one test question ***********************/
/*****************************************************************************/
// Return true on success, false on error
2017-09-01 14:36:25 +02:00
bool Tst_GetOneQuestionByCod (long QstCod,MYSQL_RES **mysql_res)
2014-12-01 23:55:08 +01:00
{
/***** Get data of a question from database *****/
2018-11-02 01:38:44 +01:00
return (DB_QuerySELECT (mysql_res,"can not get data of a question",
2019-03-18 15:42:22 +01:00
"SELECT QstCod," // row[0]
"UNIX_TIMESTAMP(EditTime)," // row[1]
"AnsType," // row[2]
"Shuffle," // row[3]
"Stem," // row[4]
"Feedback," // row[5]
"MedCod," // row[6]
"NumHits," // row[7]
"NumHitsNotBlank," // row[8]
"Score" // row[9]
2018-11-02 01:38:44 +01:00
" FROM tst_questions"
" WHERE QstCod=%ld",
QstCod) == 1);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** List for edition one or more test questions **************/
/*****************************************************************************/
2017-09-01 00:52:19 +02:00
static void Tst_ListOneOrMoreQuestionsForEdition (unsigned long NumRows,
MYSQL_RES *mysql_res)
2014-12-01 23:55:08 +01:00
{
2016-11-13 20:18:49 +01:00
extern const char *Hlp_ASSESSMENT_Tests;
2015-04-12 18:01:06 +02:00
extern const char *Txt_Questions;
2014-12-01 23:55:08 +01:00
extern const char *Txt_No_INDEX;
extern const char *Txt_Code;
extern const char *Txt_Date;
extern const char *Txt_Tags;
extern const char *Txt_TST_STR_ORDER_FULL[Tst_NUM_TYPES_ORDER_QST];
extern const char *Txt_TST_STR_ORDER_SHORT[Tst_NUM_TYPES_ORDER_QST];
extern const char *Txt_TST_STR_ANSWER_TYPES[Tst_NUM_ANS_TYPES];
extern const char *Txt_Shuffle;
Tst_QuestionsOrder_t Order;
unsigned long NumRow;
MYSQL_ROW row;
2015-10-26 13:36:02 +01:00
unsigned UniqueId;
2019-11-01 22:53:39 +01:00
char *Id;
2015-10-26 13:36:02 +01:00
time_t TimeUTC;
2014-12-01 23:55:08 +01:00
unsigned long NumHitsThisQst;
unsigned long NumHitsNotBlankThisQst;
double TotalScoreThisQst;
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,Txt_Questions,Tst_PutIconsTests,
2017-07-16 20:50:01 +02:00
Hlp_ASSESSMENT_Tests,Box_NOT_CLOSABLE);
2014-12-01 23:55:08 +01:00
/***** Write the heading *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWideMarginPadding (2);
HTM_TR_Begin (NULL);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH_Empty (1);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"CT",Txt_No_INDEX);
HTM_TH (1,1,"CT",Txt_Code);
HTM_TH (1,1,"CT",Txt_Date);
HTM_TH (1,1,"CT",Txt_Tags);
HTM_TH (1,1,"CT",Txt_Shuffle);
2014-12-01 23:55:08 +01:00
/* Stem and answers of question */
/* Number of times that the question has been answered */
/* Average score */
2019-12-15 20:02:34 +01:00
for (Order = (Tst_QuestionsOrder_t) 0;
Order <= (Tst_QuestionsOrder_t) (Tst_NUM_TYPES_ORDER_QST - 1);
2014-12-01 23:55:08 +01:00
Order++)
{
2019-10-23 19:05:05 +02:00
HTM_TH_Begin (1,1,"LT");
2019-10-13 17:25:00 +02:00
2014-12-01 23:55:08 +01:00
if (NumRows > 1)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActLstTstQst);
2019-02-11 22:15:18 +01:00
Dat_WriteParamsIniEndDates ();
2014-12-01 23:55:08 +01:00
Tst_WriteParamEditQst ();
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (Txt_TST_STR_ORDER_FULL[Order],"BT_LINK TIT_TBL",NULL);
2017-01-29 12:42:19 +01:00
if (Order == Gbl.Test.SelectedOrder)
2019-11-10 16:41:47 +01:00
HTM_U_Begin ();
2014-12-01 23:55:08 +01:00
}
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_TST_STR_ORDER_SHORT[Order]);
2014-12-01 23:55:08 +01:00
if (NumRows > 1)
{
2017-01-29 12:42:19 +01:00
if (Order == Gbl.Test.SelectedOrder)
2019-11-10 16:41:47 +01:00
HTM_U_End ();
2019-11-18 20:12:10 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
2019-10-13 17:25:00 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH_End ();
2014-12-01 23:55:08 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Write rows *****/
2015-10-26 13:36:02 +01:00
for (NumRow = 0, UniqueId = 1;
2014-12-01 23:55:08 +01:00
NumRow < NumRows;
2015-10-26 13:36:02 +01:00
NumRow++, UniqueId++)
2014-12-01 23:55:08 +01:00
{
Gbl.RowEvenOdd = NumRow % 2;
row = mysql_fetch_row (mysql_res);
2016-03-29 22:24:03 +02:00
/*
2019-03-18 15:42:22 +01:00
row[0] QstCod
row[1] UNIX_TIMESTAMP(EditTime)
row[2] AnsType
row[3] Shuffle
row[4] Stem
row[5] Feedback
row[6] MedCod
row[7] NumHits
row[8] NumHitsNotBlank
row[9] Score
2016-03-29 22:24:03 +02:00
*/
2016-04-06 19:26:09 +02:00
/***** Create test question *****/
Tst_QstConstructor ();
2014-12-01 23:55:08 +01:00
/* row[0] holds the code of the question */
2016-04-06 19:26:09 +02:00
if ((Gbl.Test.QstCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Wrong code of question.");
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-10 10:41:00 +02:00
/***** Icons *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BT%u\"",Gbl.RowEvenOdd);
2017-07-16 20:50:01 +02:00
/* Write icon to remove the question */
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActReqRemTstQst);
2017-04-28 14:02:08 +02:00
Tst_PutParamQstCod ();
2016-04-05 02:59:34 +02:00
if (NumRows == 1)
Par_PutHiddenParamChar ("OnlyThisQst",'Y'); // If there are only one row, don't list again after removing
2019-02-11 22:15:18 +01:00
Dat_WriteParamsIniEndDates ();
2017-04-28 14:02:08 +02:00
Tst_WriteParamEditQst ();
2017-06-11 19:13:28 +02:00
Ico_PutIconRemove ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
/* Write icon to edit the question */
2020-03-03 12:00:36 +01:00
Ico_PutContextualIconToEdit (ActEdiOneTstQst,NULL,Tst_PutParamQstCod);
2017-07-16 20:50:01 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"RT COLOR%u\"",Gbl.RowEvenOdd);
2019-10-23 20:07:56 +02:00
/* Write number of question */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"BIG_INDEX\"");
2019-11-10 16:47:05 +01:00
HTM_UnsignedLong (NumRow + 1);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2017-09-06 13:18:35 +02:00
/* Write answer type (row[2]) */
Gbl.Test.AnswerType = Tst_ConvertFromStrAnsTypDBToAnsTyp (row[2]);
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"DAT_SMALL\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_TST_STR_ANSWER_TYPES[Gbl.Test.AnswerType]);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Write question code */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd);
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%ld&nbsp;",Gbl.Test.QstCod);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2015-10-26 13:36:02 +01:00
/* Write the date (row[1] has the UTC date-time) */
TimeUTC = Dat_GetUNIXTimeFromStr (row[1]);
2019-11-01 22:53:39 +01:00
if (asprintf (&Id,"tst_date_%u",UniqueId) < 0)
Lay_NotEnoughMemoryExit ();
HTM_TD_Begin ("id=\"%s\" class=\"DAT_SMALL CT COLOR%u\"",
Id,Gbl.RowEvenOdd);
2019-11-01 23:35:55 +01:00
Dat_WriteLocalDateHMSFromUTC (Id,TimeUTC,
2019-11-02 12:10:58 +01:00
Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK,
2019-11-02 11:45:41 +01:00
true,true,false,0x7);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-11-06 19:45:20 +01:00
free (Id);
2014-12-01 23:55:08 +01:00
/* Write the question tags */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd);
2016-04-06 19:26:09 +02:00
Tst_GetAndWriteTagsQst (Gbl.Test.QstCod);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Write if shuffle is enabled (row[3]) */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd);
2014-12-01 23:55:08 +01:00
if (Gbl.Test.AnswerType == Tst_ANS_UNIQUE_CHOICE ||
Gbl.Test.AnswerType == Tst_ANS_MULTIPLE_CHOICE)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActShfTstQst);
2017-04-28 14:02:08 +02:00
Tst_PutParamQstCod ();
2019-02-11 22:15:18 +01:00
Dat_WriteParamsIniEndDates ();
2014-12-01 23:55:08 +01:00
Tst_WriteParamEditQst ();
2016-04-05 02:59:34 +02:00
if (NumRows == 1)
Par_PutHiddenParamChar ("OnlyThisQst",'Y'); // If editing only one question, don't edit others
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Gbl.Test.SelectedOrder);
2020-03-12 13:53:37 +01:00
HTM_INPUT_CHECKBOX ("Shuffle",HTM_SUBMIT_ON_CHANGE,
2019-11-04 20:41:35 +01:00
"value=\"Y\"%s",
2020-03-12 13:53:37 +01:00
row[3][0] == 'Y' ? " checked=\"checked\"" :
"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2019-03-18 15:42:22 +01:00
/* Write stem (row[4]) */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd);
2020-02-17 15:30:55 +01:00
Tst_WriteQstStem (row[4],"TEST_EDI",
true); // Visible
2019-03-18 15:42:22 +01:00
/***** Get and show media (row[6]) *****/
Gbl.Test.Media.MedCod = Str_ConvertStrCodToLongCod (row[6]);
Med_GetMediaDataByCod (&Gbl.Test.Media);
2019-03-02 21:49:11 +01:00
Med_ShowMedia (&Gbl.Test.Media,
2019-12-13 00:36:01 +01:00
"TEST_MED_EDIT_LIST_CONT",
2019-03-27 14:36:57 +01:00
"TEST_MED_EDIT_LIST");
2019-03-18 15:42:22 +01:00
/* Write feedback (row[5]) and answers */
2016-04-06 01:10:04 +02:00
Tst_WriteQstFeedback (row[5],"TEST_EDI_LIGHT");
2017-09-04 17:03:49 +02:00
Tst_WriteAnswersEdit (Gbl.Test.QstCod);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2016-03-29 22:24:03 +02:00
/* Get number of hits
(number of times that the question has been answered,
2019-03-18 15:42:22 +01:00
including blank answers) (row[7]) */
if (sscanf (row[7],"%lu",&NumHitsThisQst) != 1)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Wrong number of hits to a question.");
2016-03-29 22:24:03 +02:00
/* Get number of hits not blank
(number of times that the question has been answered
2019-03-18 15:42:22 +01:00
with a not blank answer) (row[8]) */
if (sscanf (row[8],"%lu",&NumHitsNotBlankThisQst) != 1)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Wrong number of hits not blank to a question.");
2019-03-18 15:42:22 +01:00
/* Get the acumulated score of the question (row[9]) */
2016-06-04 14:21:01 +02:00
Str_SetDecimalPointToUS (); // To get the decimal point as a dot
2019-03-18 15:42:22 +01:00
if (sscanf (row[9],"%lf",&TotalScoreThisQst) != 1)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Wrong score of a question.");
2016-06-04 14:21:01 +02:00
Str_SetDecimalPointToLocal (); // Return to local system
2014-12-01 23:55:08 +01:00
/* Write number of times this question has been answered */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd);
2019-11-10 16:47:05 +01:00
HTM_UnsignedLong (NumHitsThisQst);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Write average score */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd);
2014-12-01 23:55:08 +01:00
if (NumHitsThisQst)
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (TotalScoreThisQst / (double) NumHitsThisQst);
2014-12-01 23:55:08 +01:00
else
2019-11-11 00:15:44 +01:00
HTM_Txt ("N.A.");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Write number of times this question has been answered (not blank) */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd);
2019-11-10 16:47:05 +01:00
HTM_UnsignedLong (NumHitsNotBlankThisQst);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Write average score (not blank) */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd);
2014-12-01 23:55:08 +01:00
if (NumHitsNotBlankThisQst)
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (TotalScoreThisQst / (double) NumHitsNotBlankThisQst);
2014-12-01 23:55:08 +01:00
else
2019-11-11 00:15:44 +01:00
HTM_Txt ("N.A.");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-10 10:41:00 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2016-04-06 19:26:09 +02:00
/***** Destroy test question *****/
Tst_QstDestructor ();
2014-12-01 23:55:08 +01:00
}
2016-03-20 13:47:46 +01:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2016-03-21 12:53:02 +01:00
/***** Button to add a new question *****/
Tst_PutButtonToAddQuestion ();
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2017-07-16 20:50:01 +02:00
}
/*****************************************************************************/
/****************** List for edition one or more test questions **************/
/*****************************************************************************/
2019-09-29 17:33:39 +02:00
static void Tst_ListOneOrMoreQuestionsForSelection (unsigned long NumRows,
2017-09-01 00:52:19 +02:00
MYSQL_RES *mysql_res)
2017-07-16 20:50:01 +02:00
{
2019-10-03 22:12:31 +02:00
extern const char *Hlp_ASSESSMENT_Games_questions;
2017-07-16 20:50:01 +02:00
extern const char *Txt_Questions;
extern const char *Txt_No_INDEX;
extern const char *Txt_Code;
extern const char *Txt_Date;
extern const char *Txt_Tags;
extern const char *Txt_Type;
extern const char *Txt_TST_STR_ANSWER_TYPES[Tst_NUM_ANS_TYPES];
extern const char *Txt_Shuffle;
extern const char *Txt_Question;
extern const char *Txt_Add_questions;
unsigned long NumRow;
MYSQL_ROW row;
unsigned UniqueId;
2019-11-01 22:53:39 +01:00
char *Id;
2017-07-16 20:50:01 +02:00
time_t TimeUTC;
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,Txt_Questions,NULL,
2019-10-03 22:12:31 +02:00
Hlp_ASSESSMENT_Games_questions,Box_NOT_CLOSABLE);
2017-07-16 20:50:01 +02:00
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActAddTstQstToGam);
2019-09-29 17:33:39 +02:00
Gam_PutParams ();
2017-07-16 20:50:01 +02:00
/***** Write the heading *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWideMarginPadding (2);
HTM_TR_Begin (NULL);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH_Empty (1);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"CT",Txt_No_INDEX);
HTM_TH (1,1,"CT",Txt_Code);
HTM_TH (1,1,"CT",Txt_Date);
HTM_TH (1,1,"LT",Txt_Tags);
HTM_TH (1,1,"CT",Txt_Type);
HTM_TH (1,1,"CT",Txt_Shuffle);
HTM_TH (1,1,"CT",Txt_Question);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2017-07-16 20:50:01 +02:00
/***** Write rows *****/
for (NumRow = 0, UniqueId = 1;
NumRow < NumRows;
NumRow++, UniqueId++)
{
Gbl.RowEvenOdd = NumRow % 2;
row = mysql_fetch_row (mysql_res);
/*
2019-03-18 15:42:22 +01:00
row[0] QstCod
row[1] UNIX_TIMESTAMP(EditTime)
row[2] AnsType
row[3] Shuffle
row[4] Stem
row[5] Feedback
row[6] MedCod
row[7] NumHits
row[8] NumHitsNotBlank
row[9] Score
2017-07-16 20:50:01 +02:00
*/
/***** Create test question *****/
Tst_QstConstructor ();
/* row[0] holds the code of the question */
if ((Gbl.Test.QstCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of question.");
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-10 10:41:00 +02:00
/***** Icons *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BT%u\"",Gbl.RowEvenOdd);
2017-07-16 20:50:01 +02:00
/* Write checkbox to select the question */
2020-03-12 13:53:37 +01:00
HTM_INPUT_CHECKBOX ("QstCods",HTM_DONT_SUBMIT_ON_CHANGE,
2019-11-04 20:41:35 +01:00
"value=\"%ld\"",
Gbl.Test.QstCod);
2017-07-16 20:50:01 +02:00
/* Write number of question */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd);
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%lu&nbsp;",NumRow + 1);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-07-16 20:50:01 +02:00
/* Write question code */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd);
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%ld&nbsp;",Gbl.Test.QstCod);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-07-16 20:50:01 +02:00
/* Write the date (row[1] has the UTC date-time) */
TimeUTC = Dat_GetUNIXTimeFromStr (row[1]);
2019-11-01 22:53:39 +01:00
if (asprintf (&Id,"tst_date_%u",UniqueId) < 0)
Lay_NotEnoughMemoryExit ();
HTM_TD_Begin ("id=\"%s\" class=\"DAT_SMALL CT COLOR%u\">",
Id,Gbl.RowEvenOdd);
2019-11-01 23:35:55 +01:00
Dat_WriteLocalDateHMSFromUTC (Id,TimeUTC,
2019-11-02 12:10:58 +01:00
Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK,
2019-11-02 11:45:41 +01:00
true,true,false,0x7);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-11-06 19:45:20 +01:00
free (Id);
2017-07-16 20:50:01 +02:00
/* Write the question tags */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd);
2017-07-16 20:50:01 +02:00
Tst_GetAndWriteTagsQst (Gbl.Test.QstCod);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-07-16 20:50:01 +02:00
/* Write the question type (row[2]) */
Gbl.Test.AnswerType = Tst_ConvertFromStrAnsTypDBToAnsTyp (row[2]);
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s&nbsp;",Txt_TST_STR_ANSWER_TYPES[Gbl.Test.AnswerType]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-07-16 20:50:01 +02:00
/* Write if shuffle is enabled (row[3]) */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd);
2020-03-12 13:53:37 +01:00
HTM_INPUT_CHECKBOX ("Shuffle",HTM_DONT_SUBMIT_ON_CHANGE,
2019-11-04 20:41:35 +01:00
"value=\"Y\"%s disabled=\"disabled\"",
2020-03-12 13:53:37 +01:00
row[3][0] == 'Y' ? " checked=\"checked\"" :
"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-07-16 20:50:01 +02:00
2019-03-18 15:42:22 +01:00
/* Write stem (row[4]) */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd);
2020-02-17 15:30:55 +01:00
Tst_WriteQstStem (row[4],"TEST_EDI",
true); // Visible
2019-03-18 15:42:22 +01:00
/***** Get and show media (row[6]) *****/
Gbl.Test.Media.MedCod = Str_ConvertStrCodToLongCod (row[6]);
Med_GetMediaDataByCod (&Gbl.Test.Media);
2019-03-02 21:49:11 +01:00
Med_ShowMedia (&Gbl.Test.Media,
2019-12-13 00:36:01 +01:00
"TEST_MED_EDIT_LIST_CONT",
2019-03-27 14:36:57 +01:00
"TEST_MED_EDIT_LIST");
2019-03-18 15:42:22 +01:00
/* Write feedback (row[5]) */
2017-07-16 20:50:01 +02:00
Tst_WriteQstFeedback (row[5],"TEST_EDI_LIGHT");
2019-03-18 15:42:22 +01:00
/* Write answers */
2017-09-04 17:03:49 +02:00
Tst_WriteAnswersEdit (Gbl.Test.QstCod);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
HTM_TR_End ();
2017-07-16 20:50:01 +02:00
/***** Destroy test question *****/
Tst_QstDestructor ();
}
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2017-07-16 20:50:01 +02:00
/***** Button to add questions *****/
Btn_PutConfirmButton (Txt_Add_questions);
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-07-16 20:50:01 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********** Write hidden parameters for edition of test questions ***********/
/*****************************************************************************/
void Tst_WriteParamEditQst (void)
{
Par_PutHiddenParamChar ("AllTags",
2016-04-06 22:27:33 +02:00
Gbl.Test.Tags.All ? 'Y' :
2019-11-04 23:33:59 +01:00
'N');
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamString (NULL,"ChkTag",
2016-04-06 22:27:33 +02:00
Gbl.Test.Tags.List ? Gbl.Test.Tags.List :
2019-11-04 23:33:59 +01:00
"");
2014-12-01 23:55:08 +01:00
Par_PutHiddenParamChar ("AllAnsTypes",
Gbl.Test.AllAnsTypes ? 'Y' :
'N');
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamString (NULL,"AnswerType",Gbl.Test.ListAnsTypes);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Get answers of a test question from database ****************/
/*****************************************************************************/
2019-05-22 09:36:18 +02:00
unsigned Tst_GetNumAnswersQst (long QstCod)
{
return (unsigned) DB_QueryCOUNT ("can not get number of answers of a question",
"SELECT COUNT(*)"
" FROM tst_answers"
" WHERE QstCod=%ld",
QstCod);
}
2014-12-01 23:55:08 +01:00
unsigned Tst_GetAnswersQst (long QstCod,MYSQL_RES **mysql_res,bool Shuffle)
{
unsigned long NumRows;
/***** Get answers of a question from database *****/
2018-11-02 01:38:44 +01:00
NumRows = DB_QuerySELECT (mysql_res,"can not get answers of a question",
2019-03-02 21:49:11 +01:00
"SELECT AnsInd," // row[0]
"Answer," // row[1]
"Feedback," // row[2]
2019-03-18 15:42:22 +01:00
"MedCod," // row[3]
"Correct" // row[4]
2019-09-23 01:48:28 +02:00
" FROM tst_answers"
2019-09-23 19:17:12 +02:00
" WHERE QstCod=%ld"
" ORDER BY %s",
2018-11-02 01:38:44 +01:00
QstCod,
Shuffle ? "RAND(NOW())" :
"AnsInd");
if (!NumRows)
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_ERROR,"Error when getting answers of a question.");
2014-12-01 23:55:08 +01:00
return (unsigned) NumRows;
}
2019-09-23 19:17:12 +02:00
void Tst_GetCorrectAnswersFromDB (long QstCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumOpt;
/***** Query database *****/
Gbl.Test.Answer.NumOptions = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get answers of a question",
"SELECT Correct" // row[0]
" FROM tst_answers"
" WHERE QstCod=%ld"
" ORDER BY AnsInd",
QstCod);
for (NumOpt = 0;
NumOpt < Gbl.Test.Answer.NumOptions;
NumOpt++)
{
/* Get next answer */
row = mysql_fetch_row (mysql_res);
/* Assign correctness (row[0]) of this answer (this option) */
Gbl.Test.Answer.Options[NumOpt].Correct = (row[0][0] == 'Y');
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/**************** Get and write the answers of a test question ***************/
/*****************************************************************************/
2019-09-24 19:09:06 +02:00
void Tst_WriteAnswersEdit (long QstCod)
2014-12-01 23:55:08 +01:00
{
2018-12-09 13:11:20 +01:00
extern const char *Txt_TST_Answer_given_by_the_teachers;
2014-12-01 23:55:08 +01:00
unsigned NumOpt;
unsigned i;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
char *Answer;
char *Feedback;
size_t LengthAnswer;
size_t LengthFeedback;
double FloatNum[2];
2017-09-04 17:03:49 +02:00
Gbl.Test.Answer.NumOptions = Tst_GetAnswersQst (QstCod,&mysql_res,false);
2016-04-06 14:41:47 +02:00
/*
2019-03-03 12:27:29 +01:00
row[0] AnsInd
row[1] Answer
row[2] Feedback
2019-03-18 15:42:22 +01:00
row[3] MedCod
row[4] Correct
2016-04-06 14:41:47 +02:00
*/
2014-12-01 23:55:08 +01:00
/***** Write the answers *****/
switch (Gbl.Test.AnswerType)
{
case Tst_ANS_INT:
Tst_CheckIfNumberOfAnswersIsOne ();
row = mysql_fetch_row (mysql_res);
2019-11-07 10:24:00 +01:00
HTM_SPAN_Begin ("class=\"TEST_EDI\"");
2019-11-11 00:15:44 +01:00
HTM_TxtF ("(%ld)",Tst_GetIntAnsFromStr (row[1]));
2019-11-07 10:24:00 +01:00
HTM_SPAN_End ();
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_FLOAT:
if (Gbl.Test.Answer.NumOptions != 2)
Lay_ShowErrorAndExit ("Wrong float range.");
for (i = 0;
i < 2;
i++)
{
row = mysql_fetch_row (mysql_res);
2019-11-27 09:01:45 +01:00
FloatNum[i] = Str_GetDoubleFromStr (row[1]);
2014-12-01 23:55:08 +01:00
}
2019-11-07 10:24:00 +01:00
HTM_SPAN_Begin ("class=\"TEST_EDI\"");
2020-01-11 15:22:02 +01:00
HTM_Txt ("([");
HTM_Double (FloatNum[0]);
HTM_Txt ("; ");
HTM_Double (FloatNum[1]);
HTM_Txt ("])");
2019-11-07 10:24:00 +01:00
HTM_SPAN_End ();
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_TRUE_FALSE:
Tst_CheckIfNumberOfAnswersIsOne ();
row = mysql_fetch_row (mysql_res);
2019-11-07 10:24:00 +01:00
HTM_SPAN_Begin ("class=\"TEST_EDI\"");
2019-11-10 13:51:07 +01:00
HTM_Txt ("(");
2014-12-01 23:55:08 +01:00
Tst_WriteAnsTF (row[1][0]);
2019-11-10 13:51:07 +01:00
HTM_Txt (")");
2019-11-07 10:24:00 +01:00
HTM_SPAN_End ();
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_UNIQUE_CHOICE:
case Tst_ANS_MULTIPLE_CHOICE:
case Tst_ANS_TEXT:
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginPadding (2);
2014-12-01 23:55:08 +01:00
for (NumOpt = 0;
NumOpt < Gbl.Test.Answer.NumOptions;
NumOpt++)
{
row = mysql_fetch_row (mysql_res);
/* Convert the answer (row[1]), that is in HTML, to rigorous HTML */
2017-03-08 03:48:23 +01:00
LengthAnswer = strlen (row[1]) * Str_MAX_BYTES_PER_CHAR;
2018-10-08 12:37:29 +02:00
if ((Answer = (char *) malloc (LengthAnswer + 1)) == NULL)
2018-10-18 20:06:54 +02:00
Lay_NotEnoughMemoryExit ();
2017-01-17 03:10:43 +01:00
Str_Copy (Answer,row[1],
LengthAnswer);
2014-12-01 23:55:08 +01:00
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
Answer,LengthAnswer,false);
2016-04-06 14:41:47 +02:00
/* Convert the feedback (row[2]), that is in HTML, to rigorous HTML */
2014-12-01 23:55:08 +01:00
LengthFeedback = 0;
Feedback = NULL;
2016-04-06 14:41:47 +02:00
if (row[2])
if (row[2][0])
2014-12-01 23:55:08 +01:00
{
2017-03-08 03:48:23 +01:00
LengthFeedback = strlen (row[2]) * Str_MAX_BYTES_PER_CHAR;
2018-10-08 12:37:29 +02:00
if ((Feedback = (char *) malloc (LengthFeedback + 1)) == NULL)
2018-10-18 20:06:54 +02:00
Lay_NotEnoughMemoryExit ();
2017-01-17 03:10:43 +01:00
Str_Copy (Feedback,row[2],
LengthFeedback);
2014-12-01 23:55:08 +01:00
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
Feedback,LengthFeedback,false);
}
2019-03-18 15:42:22 +01:00
/* Get media (row[3]) */
Gbl.Test.Answer.Options[NumOpt].Media.MedCod = Str_ConvertStrCodToLongCod (row[3]);
Med_GetMediaDataByCod (&Gbl.Test.Answer.Options[NumOpt].Media);
2016-04-04 21:51:21 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-10 10:41:00 +02:00
2019-03-18 15:42:22 +01:00
/* Put an icon that indicates whether the answer
is correct or wrong (row[4]) */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BT%u\"",Gbl.RowEvenOdd);
2019-03-18 15:42:22 +01:00
if (row[4][0] == 'Y')
2019-10-29 21:41:54 +01:00
Ico_PutIcon ("check.svg",Txt_TST_Answer_given_by_the_teachers,"CONTEXT_ICO_16x16");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Write the number of option */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT_SMALL LT\"");
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%c)&nbsp;",'a' + (char) NumOpt);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2019-10-10 10:41:00 +02:00
/* Write the text of the answer and the media */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TEST_EDI\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Answer);
2019-03-02 21:49:11 +01:00
Med_ShowMedia (&Gbl.Test.Answer.Options[NumOpt].Media,
2019-12-13 00:36:01 +01:00
"TEST_MED_EDIT_LIST_CONT",
2019-03-27 14:36:57 +01:00
"TEST_MED_EDIT_LIST");
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
/* Write the text of the feedback */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TEST_EDI_LIGHT\"");
2014-12-01 23:55:08 +01:00
if (LengthFeedback)
2019-11-10 12:36:37 +01:00
HTM_Txt (Feedback);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-24 00:04:40 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/* Free memory allocated for the answer and the feedback */
2019-11-06 19:45:20 +01:00
free (Answer);
2014-12-01 23:55:08 +01:00
if (LengthFeedback)
2019-11-06 19:45:20 +01:00
free (Feedback);
2014-12-01 23:55:08 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
break;
default:
break;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/************** Write answers of a question when viewing a test **************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-09-04 17:03:49 +02:00
static void Tst_WriteAnswersTestToAnswer (unsigned NumQst,long QstCod,bool Shuffle)
2014-12-01 23:55:08 +01:00
{
/***** Write parameter with question code *****/
Tst_WriteParamQstCod (NumQst,QstCod);
/***** Write answer depending on type *****/
switch (Gbl.Test.AnswerType)
{
case Tst_ANS_INT:
2016-11-21 13:15:08 +01:00
Tst_WriteIntAnsViewTest (NumQst);
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_FLOAT:
2016-11-21 13:15:08 +01:00
Tst_WriteFloatAnsViewTest (NumQst);
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_TRUE_FALSE:
2017-09-04 17:03:49 +02:00
Tst_WriteTFAnsViewTest (NumQst);
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_UNIQUE_CHOICE:
case Tst_ANS_MULTIPLE_CHOICE:
2016-11-21 13:15:08 +01:00
Tst_WriteChoiceAnsViewTest (NumQst,QstCod,Shuffle);
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_TEXT:
2016-11-21 13:15:08 +01:00
Tst_WriteTextAnsViewTest (NumQst);
2014-12-01 23:55:08 +01:00
break;
default:
break;
}
}
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/************* Write answers of a question when assessing a test *************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2018-12-09 13:11:20 +01:00
static void Tst_WriteAnswersTestResult (struct UsrData *UsrDat,
unsigned NumQst,long QstCod,
2020-02-17 23:15:08 +01:00
unsigned Visibility,
2018-12-09 13:11:20 +01:00
double *ScoreThisQst,bool *AnswerIsNotBlank)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
/***** Get answers of a question from database *****/
2017-09-04 17:03:49 +02:00
Gbl.Test.Answer.NumOptions = Tst_GetAnswersQst (QstCod,&mysql_res,false);
2016-04-06 14:41:47 +02:00
/*
2019-03-03 12:27:29 +01:00
row[0] AnsInd
row[1] Answer
row[2] Feedback
2019-03-18 15:42:22 +01:00
row[3] MedCod
row[4] Correct
2016-04-06 14:41:47 +02:00
*/
2014-12-01 23:55:08 +01:00
/***** Write answer depending on type *****/
switch (Gbl.Test.AnswerType)
{
case Tst_ANS_INT:
2020-02-17 23:15:08 +01:00
Tst_WriteIntAnsAssessTest (UsrDat,NumQst,mysql_res,
Visibility,
ScoreThisQst,AnswerIsNotBlank);
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_FLOAT:
2020-02-17 23:15:08 +01:00
Tst_WriteFloatAnsAssessTest (UsrDat,NumQst,mysql_res,
Visibility,
ScoreThisQst,AnswerIsNotBlank);
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_TRUE_FALSE:
2020-02-17 23:15:08 +01:00
Tst_WriteTFAnsAssessTest (UsrDat,NumQst,mysql_res,
Visibility,
ScoreThisQst,AnswerIsNotBlank);
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_UNIQUE_CHOICE:
case Tst_ANS_MULTIPLE_CHOICE:
2020-02-17 23:15:08 +01:00
Tst_WriteChoiceAnsAssessTest (UsrDat,NumQst,mysql_res,
Visibility,
ScoreThisQst,AnswerIsNotBlank);
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_TEXT:
2020-02-17 23:15:08 +01:00
Tst_WriteTextAnsAssessTest (UsrDat,NumQst,mysql_res,
Visibility,
ScoreThisQst,AnswerIsNotBlank);
2014-12-01 23:55:08 +01:00
break;
default:
break;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2019-05-22 09:36:18 +02:00
/*****************************************************************************/
/***************** Check if a question is valid for a game *******************/
/*****************************************************************************/
bool Tst_CheckIfQuestionIsValidForGame (long QstCod)
{
/***** Check if a question is valid for a game from database *****/
return DB_QueryCOUNT ("can not check type of a question",
"SELECT COUNT(*)"
" FROM tst_questions"
" WHERE QstCod=%ld AND AnsType='%s'",
QstCod,Tst_StrAnswerTypesDB[Tst_ANS_UNIQUE_CHOICE]) != 0;
2017-09-04 17:03:49 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/************** Write false / true answer when viewing a test ****************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-09-04 17:03:49 +02:00
static void Tst_WriteTFAnsViewTest (unsigned NumQst)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_TF_QST[2];
/***** Write selector for the answer *****/
2019-11-05 15:47:35 +01:00
HTM_SELECT_Begin (false,
"name=\"Ans%06u\"",NumQst);
2019-11-07 00:34:20 +01:00
HTM_OPTION (HTM_Type_STRING,"" ,true ,false,"&nbsp;");
HTM_OPTION (HTM_Type_STRING,"T",false,false,"%s",Txt_TF_QST[0]);
HTM_OPTION (HTM_Type_STRING,"F",false,false,"%s",Txt_TF_QST[1]);
2019-11-05 08:46:38 +01:00
HTM_SELECT_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/************** Write false / true answer when viewing a test ****************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
void Tst_WriteAnsTF (char AnsTF)
{
extern const char *Txt_TF_QST[2];
switch (AnsTF)
{
case 'T': // true
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_TF_QST[0]);
2014-12-01 23:55:08 +01:00
break;
case 'F': // false
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_TF_QST[1]);
2014-12-01 23:55:08 +01:00
break;
default: // no answer
2019-11-14 08:59:11 +01:00
HTM_NBSP ();
2014-12-01 23:55:08 +01:00
break;
}
}
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/************** Write false / true answer when assessing a test **************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2018-12-09 13:11:20 +01:00
static void Tst_WriteTFAnsAssessTest (struct UsrData *UsrDat,
unsigned NumQst,MYSQL_RES *mysql_res,
2020-02-17 23:15:08 +01:00
unsigned Visibility,
2014-12-01 23:55:08 +01:00
double *ScoreThisQst,bool *AnswerIsNotBlank)
{
MYSQL_ROW row;
char AnsTF;
2016-04-06 14:41:47 +02:00
/*
2019-03-02 21:49:11 +01:00
row[0] AnsInd
row[1] Answer
row[2] Feedback
2019-03-18 15:42:22 +01:00
row[3] MedCod
row[4] Correct
2016-04-06 14:41:47 +02:00
*/
2014-12-01 23:55:08 +01:00
/***** Check if number of rows is correct *****/
Tst_CheckIfNumberOfAnswersIsOne ();
/***** Get answer true or false *****/
row = mysql_fetch_row (mysql_res);
/***** Compute the mark for this question *****/
AnsTF = Gbl.Test.StrAnswersOneQst[NumQst][0];
if (AnsTF == '\0') // User has omitted the answer (the answer is blank)
{
*AnswerIsNotBlank = false;
*ScoreThisQst = 0.0;
}
else
{
*AnswerIsNotBlank = true;
if (AnsTF == row[1][0]) // Correct
*ScoreThisQst = 1.0;
else // Wrong
*ScoreThisQst = -1.0;
}
/***** Header with the title of each column *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginPadding (2);
HTM_TR_Begin (NULL);
2018-12-09 13:11:20 +01:00
Tst_WriteHeadUserCorrect (UsrDat);
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-10 10:41:00 +02:00
/***** Write the user answer *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s CM\"",
2020-02-18 09:19:33 +01:00
TsV_IsVisibleCorrectAns (Visibility) ?
2020-02-17 12:27:28 +01:00
(AnsTF == row[1][0] ? "ANS_OK" :
"ANS_BAD") :
"ANS_0");
2014-12-01 23:55:08 +01:00
Tst_WriteAnsTF (AnsTF);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Write the correct answer *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"ANS_0 CM\"");
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleQstAndAnsTxt (Visibility) &&
TsV_IsVisibleCorrectAns (Visibility))
2014-12-01 23:55:08 +01:00
Tst_WriteAnsTF (row[1][0]);
else
2020-02-19 00:45:26 +01:00
Ico_PutIconNotVisible ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-10 10:41:00 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2020-02-17 12:00:39 +01:00
/***** Write the score of this question *****/
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleEachQstScore (Visibility))
2014-12-01 23:55:08 +01:00
{
Tst_WriteScoreStart (2);
if (AnsTF == '\0') // If user has omitted the answer
2019-11-07 10:24:00 +01:00
{
HTM_SPAN_Begin ("class=\"ANS_0\"");
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (0.0);
2019-11-07 10:24:00 +01:00
}
2014-12-01 23:55:08 +01:00
else if (AnsTF == row[1][0]) // If correct
2019-11-07 10:24:00 +01:00
{
HTM_SPAN_Begin ("class=\"ANS_OK\"");
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (1.0);
2019-11-07 10:24:00 +01:00
}
2014-12-01 23:55:08 +01:00
else // If wrong
2019-11-07 10:24:00 +01:00
{
HTM_SPAN_Begin ("class=\"ANS_BAD\"");
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (-1.0);
2019-11-07 10:24:00 +01:00
}
HTM_SPAN_End ();
2014-12-01 23:55:08 +01:00
Tst_WriteScoreEnd ();
}
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/******** Write single or multiple choice answer when viewing a test *********/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
static void Tst_WriteChoiceAnsViewTest (unsigned NumQst,long QstCod,bool Shuffle)
2014-12-01 23:55:08 +01:00
{
unsigned NumOpt;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned Index;
bool ErrorInIndex = false;
2017-01-28 15:58:46 +01:00
char ParamName[3 + 6 + 1];
2019-11-04 20:41:35 +01:00
char StrAns[32];
2014-12-01 23:55:08 +01:00
/***** Get answers of a question from database *****/
2017-09-04 17:03:49 +02:00
Gbl.Test.Answer.NumOptions = Tst_GetAnswersQst (QstCod,&mysql_res,Shuffle);
2016-04-06 14:41:47 +02:00
/*
2019-03-03 12:27:29 +01:00
row[0] AnsInd
row[1] Answer
row[2] Feedback
2019-03-18 15:42:22 +01:00
row[3] MedCod
row[4] Correct
2016-04-06 14:41:47 +02:00
*/
2016-04-06 19:26:09 +02:00
2019-10-20 22:00:28 +02:00
/***** Begin table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginPadding (2);
2016-04-06 19:26:09 +02:00
2014-12-01 23:55:08 +01:00
for (NumOpt = 0;
NumOpt < Gbl.Test.Answer.NumOptions;
NumOpt++)
{
/***** Get next answer *****/
row = mysql_fetch_row (mysql_res);
/***** Allocate memory for text in this choice answer *****/
if (!Tst_AllocateTextChoiceAnswer (NumOpt))
2019-03-09 20:12:44 +01:00
/* Abort on error */
Ale_ShowAlertsAndExit ();
2014-12-01 23:55:08 +01:00
2017-09-04 17:03:49 +02:00
/***** Assign index (row[0]).
Index is 0,1,2,3... if no shuffle
or 1,3,0,2... (example) if shuffle *****/
2014-12-01 23:55:08 +01:00
if (sscanf (row[0],"%u",&Index) == 1)
{
if (Index >= Tst_MAX_OPTIONS_PER_QUESTION)
ErrorInIndex = true;
}
else
ErrorInIndex = true;
if (ErrorInIndex)
2016-11-21 13:15:08 +01:00
Lay_ShowErrorAndExit ("Wrong index of answer when showing a test.");
2014-12-01 23:55:08 +01:00
/***** Copy text (row[1]) and convert it, that is in HTML, to rigorous HTML ******/
2017-01-15 18:02:52 +01:00
Str_Copy (Gbl.Test.Answer.Options[NumOpt].Text,row[1],
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK);
2014-12-01 23:55:08 +01:00
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
2017-01-15 18:02:52 +01:00
Gbl.Test.Answer.Options[NumOpt].Text,
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false);
2014-12-01 23:55:08 +01:00
2019-03-18 15:42:22 +01:00
/***** Get media (row[3]) *****/
Gbl.Test.Answer.Options[NumOpt].Media.MedCod = Str_ConvertStrCodToLongCod (row[3]);
Med_GetMediaDataByCod (&Gbl.Test.Answer.Options[NumOpt].Media);
2016-04-04 21:51:21 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
2019-10-10 10:41:00 +02:00
/***** Write selectors and letter of this option *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2018-10-18 02:02:32 +02:00
snprintf (ParamName,sizeof (ParamName),
"Ind%06u",
NumQst);
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamUnsigned (NULL,ParamName,Index);
2019-11-04 20:41:35 +01:00
snprintf (StrAns,sizeof (StrAns),
"Ans%06u",
NumQst);
2014-12-01 23:55:08 +01:00
if (Gbl.Test.AnswerType == Tst_ANS_UNIQUE_CHOICE)
2019-11-04 20:41:35 +01:00
HTM_INPUT_RADIO (StrAns,false,
"id=\"Ans%06u_%u\" value=\"%u\""
" onclick=\"selectUnselectRadio(this,this.form.Ans%06u,%u);\"",
NumQst,NumOpt,
Index,
NumQst,Gbl.Test.Answer.NumOptions);
2014-12-01 23:55:08 +01:00
else // Gbl.Test.AnswerType == Tst_ANS_MULTIPLE_CHOICE
2020-03-12 13:53:37 +01:00
HTM_INPUT_CHECKBOX (StrAns,HTM_DONT_SUBMIT_ON_CHANGE,
2019-11-04 20:41:35 +01:00
"id=\"Ans%06u_%u\" value=\"%u\"",
NumQst,NumOpt,
Index);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("for=\"Ans%06u_%u\" class=\"ANS_TXT\"",NumQst,NumOpt);
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%c)&nbsp;",'a' + (char) NumOpt);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Write the option text *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("for=\"Ans%06u_%u\" class=\"ANS_TXT\"",NumQst,NumOpt);
2019-11-10 12:36:37 +01:00
HTM_Txt (Gbl.Test.Answer.Options[NumOpt].Text);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-03-02 21:49:11 +01:00
Med_ShowMedia (&Gbl.Test.Answer.Options[NumOpt].Media,
2019-12-13 00:36:01 +01:00
"TEST_MED_SHOW_CONT",
2019-03-27 14:36:57 +01:00
"TEST_MED_SHOW");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-10 10:41:00 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
2017-05-01 21:17:38 +02:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/******* Write single or multiple choice answer when assessing a test ********/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2018-12-09 13:11:20 +01:00
static void Tst_WriteChoiceAnsAssessTest (struct UsrData *UsrDat,
unsigned NumQst,MYSQL_RES *mysql_res,
2020-02-17 23:15:08 +01:00
unsigned Visibility,
2014-12-01 23:55:08 +01:00
double *ScoreThisQst,bool *AnswerIsNotBlank)
{
2018-12-09 13:11:20 +01:00
extern const char *Txt_TST_Answer_given_by_the_user;
extern const char *Txt_TST_Answer_given_by_the_teachers;
2014-12-01 23:55:08 +01:00
unsigned NumOpt;
unsigned Indexes[Tst_MAX_OPTIONS_PER_QUESTION]; // Indexes of all answers of this question
bool AnswersUsr[Tst_MAX_OPTIONS_PER_QUESTION];
2018-12-09 13:11:20 +01:00
struct
{
char *Class;
char *Str;
} Ans;
2014-12-01 23:55:08 +01:00
/***** Get text and correctness of answers for this question
from database (one row per answer) *****/
2019-09-23 01:48:28 +02:00
Tst_GetChoiceAns (mysql_res);
2014-12-01 23:55:08 +01:00
/***** Get indexes for this question from string *****/
2019-09-23 19:17:12 +02:00
Tst_GetIndexesFromStr (Gbl.Test.StrIndexesOneQst[NumQst],Indexes);
2014-12-01 23:55:08 +01:00
/***** Get the user's answers for this question from string *****/
2019-09-23 19:17:12 +02:00
Tst_GetAnswersFromStr (Gbl.Test.StrAnswersOneQst[NumQst],AnswersUsr);
2014-12-01 23:55:08 +01:00
2019-09-23 01:48:28 +02:00
/***** Compute the total score of this question *****/
Tst_ComputeScoreQst (Indexes,AnswersUsr,ScoreThisQst,AnswerIsNotBlank);
2019-10-20 22:00:28 +02:00
/***** Begin table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginPadding (2);
HTM_TR_Begin (NULL);
2018-12-09 13:11:20 +01:00
Tst_WriteHeadUserCorrect (UsrDat);
2019-10-23 19:05:05 +02:00
HTM_TD_Empty (2);
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Write answers (one row per answer) *****/
for (NumOpt = 0;
NumOpt < Gbl.Test.Answer.NumOptions;
NumOpt++)
{
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2018-12-09 13:11:20 +01:00
2014-12-01 23:55:08 +01:00
/* Draw icon depending on user's answer */
if (AnswersUsr[Indexes[NumOpt]] == true) // This answer has been selected by the user
2018-12-09 13:11:20 +01:00
{
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleCorrectAns (Visibility))
2018-12-09 13:11:20 +01:00
{
if (Gbl.Test.Answer.Options[Indexes[NumOpt]].Correct)
{
Ans.Class = "ANS_OK";
Ans.Str = "&check;";
}
else
{
Ans.Class = "ANS_BAD";
Ans.Str = "&cross;";
}
}
else
{
Ans.Class = "ANS_0";
Ans.Str = "&bull;";
}
2019-10-10 10:41:00 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s CT\" title=\"%s\"",
2019-10-10 23:14:13 +02:00
Ans.Class,Txt_TST_Answer_given_by_the_user);
2019-11-10 12:36:37 +01:00
HTM_Txt (Ans.Str);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2018-12-09 13:11:20 +01:00
}
else // This answer has NOT been selected by the user
2019-10-23 19:05:05 +02:00
HTM_TD_Empty (1);
2014-12-01 23:55:08 +01:00
/* Draw icon that indicates whether the answer is correct */
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleCorrectAns (Visibility))
2014-12-01 23:55:08 +01:00
{
if (Gbl.Test.Answer.Options[Indexes[NumOpt]].Correct)
2019-10-07 21:15:14 +02:00
{
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"ANS_0 CT\" title=\"%s\"",
2019-10-10 23:14:13 +02:00
Txt_TST_Answer_given_by_the_teachers);
2019-11-11 00:15:44 +01:00
HTM_Txt ("&bull;");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
}
2018-12-09 13:11:20 +01:00
else
2019-10-23 19:05:05 +02:00
HTM_TD_Empty (1);
2014-12-01 23:55:08 +01:00
}
else
2019-10-07 21:15:14 +02:00
{
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"ANS_0 CT\"");
2020-02-19 00:45:26 +01:00
Ico_PutIconNotVisible ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
}
2014-12-01 23:55:08 +01:00
/* Answer letter (a, b, c,...) */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"ANS_TXT LT\"");
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%c)&nbsp;",'a' + (char) NumOpt);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Answer text and feedback */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"ANS_TXT\"");
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleQstAndAnsTxt (Visibility))
2020-02-17 23:15:08 +01:00
{
HTM_Txt (Gbl.Test.Answer.Options[Indexes[NumOpt]].Text);
Med_ShowMedia (&Gbl.Test.Answer.Options[Indexes[NumOpt]].Media,
"TEST_MED_SHOW_CONT",
"TEST_MED_SHOW");
}
else
2020-02-19 00:45:26 +01:00
Ico_PutIconNotVisible ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-24 00:04:40 +02:00
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleCorrectAns (Visibility))
2014-12-01 23:55:08 +01:00
if (Gbl.Test.Answer.Options[Indexes[NumOpt]].Feedback)
if (Gbl.Test.Answer.Options[Indexes[NumOpt]].Feedback[0])
2019-10-23 20:07:56 +02:00
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TEST_EXA_LIGHT\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Gbl.Test.Answer.Options[Indexes[NumOpt]].Feedback);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
}
2019-10-24 00:04:40 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-10 10:41:00 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-09-23 01:48:28 +02:00
}
2020-02-17 12:27:28 +01:00
/***** Write the score of this question *****/
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleEachQstScore (Visibility))
2019-09-23 01:48:28 +02:00
{
Tst_WriteScoreStart (4);
if (*ScoreThisQst == 0.0)
2019-11-07 10:24:00 +01:00
HTM_SPAN_Begin ("class=\"ANS_0\"");
2019-09-23 01:48:28 +02:00
else if (*ScoreThisQst > 0.0)
2019-11-07 10:24:00 +01:00
HTM_SPAN_Begin ("class=\"ANS_OK\"");
2019-09-23 01:48:28 +02:00
else
2019-11-07 10:24:00 +01:00
HTM_SPAN_Begin ("class=\"ANS_BAD\"");
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (*ScoreThisQst);
2019-11-07 10:24:00 +01:00
HTM_SPAN_End ();
2019-09-23 01:48:28 +02:00
Tst_WriteScoreEnd ();
}
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2019-09-23 01:48:28 +02:00
}
/*****************************************************************************/
/************************ Get choice answer from row *************************/
/*****************************************************************************/
void Tst_GetChoiceAns (MYSQL_RES *mysql_res)
{
unsigned NumOpt;
MYSQL_ROW row;
/***** Get text and correctness of answers for this question
from database (one row per answer) *****/
/*
row[0] AnsInd
row[1] Answer
row[2] Feedback
row[3] MedCod
row[4] Correct
*/
for (NumOpt = 0;
NumOpt < Gbl.Test.Answer.NumOptions;
NumOpt++)
{
/***** Get next answer *****/
row = mysql_fetch_row (mysql_res);
/***** Allocate memory for text in this choice option *****/
if (!Tst_AllocateTextChoiceAnswer (NumOpt))
/* Abort on error */
Ale_ShowAlertsAndExit ();
2014-12-01 23:55:08 +01:00
2019-09-23 01:48:28 +02:00
/***** Copy answer text (row[1]) and convert it,
that is in HTML, to rigorous HTML ******/
Str_Copy (Gbl.Test.Answer.Options[NumOpt].Text,row[1],
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK);
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
Gbl.Test.Answer.Options[NumOpt].Text,
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false);
/***** Copy answer feedback (row[2]) and convert it,
that is in HTML, to rigorous HTML ******/
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleFeedbackTxt (Gbl.Test.Config.Visibility))
2019-09-23 01:48:28 +02:00
if (row[2])
if (row[2][0])
{
Str_Copy (Gbl.Test.Answer.Options[NumOpt].Feedback,row[2],
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK);
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
Gbl.Test.Answer.Options[NumOpt].Feedback,
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false);
}
/***** Get media (row[3]) *****/
Gbl.Test.Answer.Options[NumOpt].Media.MedCod = Str_ConvertStrCodToLongCod (row[3]);
Med_GetMediaDataByCod (&Gbl.Test.Answer.Options[NumOpt].Media);
/***** Assign correctness (row[4]) of this answer (this option) *****/
Gbl.Test.Answer.Options[NumOpt].Correct = (row[4][0] == 'Y');
}
}
2019-09-23 19:17:12 +02:00
/*****************************************************************************/
/********************* Get vector of indexes from string *********************/
/*****************************************************************************/
void Tst_GetIndexesFromStr (const char StrIndexesOneQst[Tst_MAX_BYTES_INDEXES_ONE_QST + 1], // 0 1 2 3, 3 0 2 1, etc.
unsigned Indexes[Tst_MAX_OPTIONS_PER_QUESTION])
{
unsigned NumOpt;
const char *Ptr;
2019-11-08 01:10:32 +01:00
char StrOneIndex[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
2019-09-23 19:17:12 +02:00
2019-09-24 01:41:51 +02:00
/***** Get indexes from string *****/
for (NumOpt = 0, Ptr = StrIndexesOneQst;
NumOpt < Tst_MAX_OPTIONS_PER_QUESTION && *Ptr;
2019-09-23 19:17:12 +02:00
NumOpt++)
{
2019-11-08 01:10:32 +01:00
Par_GetNextStrUntilSeparParamMult (&Ptr,StrOneIndex,Cns_MAX_DECIMAL_DIGITS_UINT);
2019-09-24 09:24:36 +02:00
2019-09-23 19:17:12 +02:00
if (sscanf (StrOneIndex,"%u",&(Indexes[NumOpt])) != 1)
2019-09-24 09:24:36 +02:00
Lay_ShowErrorAndExit ("Wrong index of answer.");
2019-09-24 01:41:51 +02:00
if (Indexes[NumOpt] >= Tst_MAX_OPTIONS_PER_QUESTION)
2019-09-24 09:24:36 +02:00
Lay_ShowErrorAndExit ("Wrong index of answer.");
2019-09-23 19:17:12 +02:00
}
2019-09-24 09:24:36 +02:00
/***** Initialize remaining to 0 *****/
for (;
NumOpt < Tst_MAX_OPTIONS_PER_QUESTION;
NumOpt++)
Indexes[NumOpt] = 0;
2019-09-23 19:17:12 +02:00
}
/*****************************************************************************/
/****************** Get vector of user's answers from string *****************/
/*****************************************************************************/
void Tst_GetAnswersFromStr (const char StrAnswersOneQst[Tst_MAX_BYTES_ANSWERS_ONE_QST + 1],
bool AnswersUsr[Tst_MAX_OPTIONS_PER_QUESTION])
{
unsigned NumOpt;
const char *Ptr;
2019-11-08 01:10:32 +01:00
char StrOneAnswer[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
2019-09-24 15:00:46 +02:00
unsigned AnsUsr;
2019-09-23 19:17:12 +02:00
2019-09-24 15:00:46 +02:00
/***** Initialize all answers to false *****/
2019-09-23 19:17:12 +02:00
for (NumOpt = 0;
NumOpt < Tst_MAX_OPTIONS_PER_QUESTION;
NumOpt++)
AnswersUsr[NumOpt] = false;
2019-09-24 15:00:46 +02:00
/***** Set selected answers to true *****/
2019-09-23 19:17:12 +02:00
for (NumOpt = 0, Ptr = StrAnswersOneQst;
2019-09-24 15:00:46 +02:00
NumOpt < Tst_MAX_OPTIONS_PER_QUESTION && *Ptr;
2019-09-23 19:17:12 +02:00
NumOpt++)
2019-09-24 15:00:46 +02:00
{
2019-11-08 01:10:32 +01:00
Par_GetNextStrUntilSeparParamMult (&Ptr,StrOneAnswer,Cns_MAX_DECIMAL_DIGITS_UINT);
2019-09-24 15:00:46 +02:00
if (sscanf (StrOneAnswer,"%u",&AnsUsr) != 1)
Lay_ShowErrorAndExit ("Bad user's answer.");
if (AnsUsr >= Tst_MAX_OPTIONS_PER_QUESTION)
Lay_ShowErrorAndExit ("Bad user's answer.");
AnswersUsr[AnsUsr] = true;
}
2019-09-23 19:17:12 +02:00
}
2019-09-23 01:48:28 +02:00
/*****************************************************************************/
/********************* Compute the score of this question ********************/
/*****************************************************************************/
void Tst_ComputeScoreQst (unsigned Indexes[Tst_MAX_OPTIONS_PER_QUESTION], // Indexes of all answers of this question
bool AnswersUsr[Tst_MAX_OPTIONS_PER_QUESTION],
double *ScoreThisQst,bool *AnswerIsNotBlank)
{
unsigned NumOpt;
unsigned NumOptTotInQst = 0;
unsigned NumOptCorrInQst = 0;
unsigned NumAnsGood = 0;
unsigned NumAnsBad = 0;
/***** Compute the total score of this question *****/
for (NumOpt = 0;
NumOpt < Gbl.Test.Answer.NumOptions;
NumOpt++)
{
2014-12-01 23:55:08 +01:00
NumOptTotInQst++;
2019-09-23 01:48:28 +02:00
if (Gbl.Test.Answer.Options[Indexes[NumOpt]].Correct)
NumOptCorrInQst++;
2014-12-01 23:55:08 +01:00
if (AnswersUsr[Indexes[NumOpt]] == true) // This answer has been selected by the user
{
if (Gbl.Test.Answer.Options[Indexes[NumOpt]].Correct)
NumAnsGood++;
else
NumAnsBad++;
}
}
2019-09-23 01:48:28 +02:00
/* The answer is blank? */
2014-12-01 23:55:08 +01:00
*AnswerIsNotBlank = NumAnsGood != 0 || NumAnsBad != 0;
if (*AnswerIsNotBlank)
{
/* Compute the score */
if (Gbl.Test.AnswerType == Tst_ANS_UNIQUE_CHOICE)
{
if (NumOptTotInQst >= 2) // It should be 2 options at least
*ScoreThisQst = (double) NumAnsGood -
(double) NumAnsBad / (double) (NumOptTotInQst - 1);
else // 0 or 1 options (impossible)
*ScoreThisQst = (double) NumAnsGood;
}
else // Gbl.Test.AnswerType == Tst_ANS_MULTIPLE_CHOICE
{
if (NumOptCorrInQst) // There are correct options in the question
{
if (NumOptCorrInQst < NumOptTotInQst) // If there are correct options and wrong options (typical case)
*ScoreThisQst = (double) NumAnsGood / (double) NumOptCorrInQst -
2018-04-24 13:21:53 +02:00
(double) NumAnsBad / (double) (NumOptTotInQst - NumOptCorrInQst);
2014-12-01 23:55:08 +01:00
else // Si todas the opciones son correctas (caso raro)
*ScoreThisQst = (double) NumAnsGood / (double) NumOptCorrInQst;
}
else
{
if (NumOptTotInQst) // There are options but none is correct (extrange case)
*ScoreThisQst = - (double) NumAnsBad / (double) NumOptTotInQst;
else // There are no options (impossible!)
*ScoreThisQst = 0.0;
}
}
}
else // Answer is blank
*ScoreThisQst = 0.0;
}
2017-09-04 17:03:49 +02:00
/*****************************************************************************/
2019-09-16 00:15:40 +02:00
/******** Write single or multiple choice answer when viewing a match ********/
2017-09-04 17:03:49 +02:00
/*****************************************************************************/
2019-10-23 01:30:11 +02:00
void Tst_WriteChoiceAnsViewMatch (long MchCod,unsigned QstInd,long QstCod,
unsigned NumCols,const char *Class,bool ShowResult)
2017-09-04 17:03:49 +02:00
{
unsigned NumOpt;
2019-10-23 01:30:11 +02:00
bool RowIsOpen = false;
2017-09-04 17:03:49 +02:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2020-03-12 13:53:37 +01:00
unsigned NumRespondersQst;
unsigned NumRespondersAns;
2019-09-24 01:41:51 +02:00
unsigned Indexes[Tst_MAX_OPTIONS_PER_QUESTION]; // Indexes of all answers of this question
2017-09-04 17:03:49 +02:00
2019-09-24 01:41:51 +02:00
/***** Get number of users who have answered this question from database *****/
2020-03-12 13:53:37 +01:00
NumRespondersQst = Mch_GetNumUsrsWhoAnsweredQst (MchCod,QstInd);
2019-09-16 00:15:40 +02:00
2017-09-04 17:03:49 +02:00
/***** Get answers of a question from database *****/
Gbl.Test.Answer.NumOptions = Tst_GetAnswersQst (QstCod,&mysql_res,false);
/*
2019-03-02 21:49:11 +01:00
row[0] AnsInd
row[1] Answer
row[2] Feedback
2019-03-18 15:42:22 +01:00
row[3] MedCod
row[4] Correct
2017-09-04 17:03:49 +02:00
*/
for (NumOpt = 0;
NumOpt < Gbl.Test.Answer.NumOptions;
NumOpt++)
{
2019-09-24 01:41:51 +02:00
/* Get next answer */
2017-09-04 17:03:49 +02:00
row = mysql_fetch_row (mysql_res);
2019-09-24 01:41:51 +02:00
/* Allocate memory for text in this choice answer */
2017-09-04 17:03:49 +02:00
if (!Tst_AllocateTextChoiceAnswer (NumOpt))
2019-03-09 20:12:44 +01:00
/* Abort on error */
Ale_ShowAlertsAndExit ();
2017-09-04 17:03:49 +02:00
2019-09-24 01:41:51 +02:00
/* Copy text (row[1]) and convert it, that is in HTML, to rigorous HTML */
2017-09-04 17:03:49 +02:00
Str_Copy (Gbl.Test.Answer.Options[NumOpt].Text,row[1],
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK);
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
Gbl.Test.Answer.Options[NumOpt].Text,
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false);
2019-09-24 01:41:51 +02:00
/* Get media (row[3]) */
2019-03-18 15:42:22 +01:00
Gbl.Test.Answer.Options[NumOpt].Media.MedCod = Str_ConvertStrCodToLongCod (row[3]);
Med_GetMediaDataByCod (&Gbl.Test.Answer.Options[NumOpt].Media);
2017-09-04 17:03:49 +02:00
2019-09-24 01:41:51 +02:00
/* Get if correct (row[4]) */
Gbl.Test.Answer.Options[NumOpt].Correct = (row[4][0] == 'Y');
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
/***** Get indexes for this question in match *****/
Mch_GetIndexes (MchCod,QstInd,Indexes);
2019-10-20 22:00:28 +02:00
/***** Begin table *****/
2020-03-12 13:53:37 +01:00
HTM_TABLE_BeginWidePadding (0);
2019-09-24 01:41:51 +02:00
2019-10-23 01:30:11 +02:00
/***** Show options distributed in columns *****/
2019-09-24 01:41:51 +02:00
for (NumOpt = 0;
NumOpt < Gbl.Test.Answer.NumOptions;
NumOpt++)
{
2019-10-23 01:30:11 +02:00
/***** Start row? *****/
if (NumOpt % NumCols == 0)
{
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-23 01:30:11 +02:00
RowIsOpen = true;
}
2019-09-16 00:15:40 +02:00
2019-05-22 09:36:18 +02:00
/***** Write letter for this option *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"MCH_TCH_BUTTON_TD\"");
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"MCH_TCH_BUTTON BT_%c\"",'A' + (char) NumOpt);
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%c",'a' + (char) NumOpt);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-09-04 17:03:49 +02:00
2019-09-16 00:15:40 +02:00
/***** Write the option text and the result *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("for=\"Ans%06u_%u\" class=\"%s\"",QstInd,NumOpt,Class);
2019-11-10 12:36:37 +01:00
HTM_Txt (Gbl.Test.Answer.Options[Indexes[NumOpt]].Text);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-09-24 01:41:51 +02:00
Med_ShowMedia (&Gbl.Test.Answer.Options[Indexes[NumOpt]].Media,
2019-12-13 00:36:01 +01:00
"TEST_MED_SHOW_CONT",
2019-03-27 14:36:57 +01:00
"TEST_MED_SHOW");
2017-09-06 23:17:52 +02:00
2019-09-16 00:15:40 +02:00
/* Show result (number of users who answered? */
2017-09-15 11:39:02 +02:00
if (ShowResult)
2020-03-12 13:53:37 +01:00
{
/* Get number of users who selected this answer */
NumRespondersAns = Mch_GetNumUsrsWhoHaveChosenAns (MchCod,QstInd,Indexes[NumOpt]);
/* Draw proportional bar for this answer */
Mch_DrawBarNumUsrs (NumRespondersAns,NumRespondersQst,
Gbl.Test.Answer.Options[Indexes[NumOpt]].Correct);
}
else
/* Draw empty bar for this answer
in order to show the same layout that the one shown with results */
Mch_DrawBarNumUsrs (0,0,
false); // Not used when length of bar is 0
2019-09-16 00:15:40 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-16 00:15:40 +02:00
2019-10-23 01:30:11 +02:00
/***** End row? *****/
if (NumOpt % NumCols == NumCols - 1)
{
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-10-23 01:30:11 +02:00
RowIsOpen = false;
}
2017-09-04 17:03:49 +02:00
}
2019-10-23 01:30:11 +02:00
/***** End row? *****/
if (RowIsOpen)
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-10-23 01:30:11 +02:00
2017-09-04 17:03:49 +02:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2017-09-04 17:03:49 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/******************** Write text answer when viewing a test ******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
static void Tst_WriteTextAnsViewTest (unsigned NumQst)
2014-12-01 23:55:08 +01:00
{
2019-11-04 01:29:46 +01:00
char StrAns[3 + 6 + 1];
2014-12-01 23:55:08 +01:00
/***** Write input field for the answer *****/
2019-11-04 01:29:46 +01:00
snprintf (StrAns,sizeof (StrAns),
"Ans%06u",
NumQst);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT (StrAns,Tst_MAX_BYTES_ANSWERS_ONE_QST,"",false,
2019-11-04 01:29:46 +01:00
"size=\"40\"");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/***************** Write text answer when assessing a test *******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2018-12-09 13:11:20 +01:00
static void Tst_WriteTextAnsAssessTest (struct UsrData *UsrDat,
unsigned NumQst,MYSQL_RES *mysql_res,
2020-02-17 23:15:08 +01:00
unsigned Visibility,
2014-12-01 23:55:08 +01:00
double *ScoreThisQst,bool *AnswerIsNotBlank)
{
unsigned NumOpt;
MYSQL_ROW row;
2017-03-13 19:02:15 +01:00
char TextAnsUsr[Tst_MAX_BYTES_ANSWERS_ONE_QST + 1];
char TextAnsOK[Tst_MAX_BYTES_ANSWERS_ONE_QST + 1];
2014-12-01 23:55:08 +01:00
bool Correct = false;
2016-04-06 14:41:47 +02:00
/*
2019-03-03 12:27:29 +01:00
row[0] AnsInd
row[1] Answer
row[2] Feedback
2019-03-18 15:42:22 +01:00
row[3] MedCod
row[4] Correct
2016-04-06 14:41:47 +02:00
*/
2014-12-01 23:55:08 +01:00
/***** Get text and correctness of answers for this question from database (one row per answer) *****/
for (NumOpt = 0;
NumOpt < Gbl.Test.Answer.NumOptions;
NumOpt++)
{
/***** Get next answer *****/
row = mysql_fetch_row (mysql_res);
/***** Allocate memory for text in this choice answer *****/
if (!Tst_AllocateTextChoiceAnswer (NumOpt))
2019-03-09 20:12:44 +01:00
/* Abort on error */
Ale_ShowAlertsAndExit ();
2014-12-01 23:55:08 +01:00
/***** Copy answer text (row[1]) and convert it, that is in HTML, to rigorous HTML ******/
2017-01-15 18:02:52 +01:00
Str_Copy (Gbl.Test.Answer.Options[NumOpt].Text,row[1],
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK);
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
Gbl.Test.Answer.Options[NumOpt].Text,
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false);
2014-12-01 23:55:08 +01:00
2016-04-06 14:41:47 +02:00
/***** Copy answer feedback (row[2]) and convert it, that is in HTML, to rigorous HTML ******/
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleFeedbackTxt (Visibility))
2016-04-06 14:41:47 +02:00
if (row[2])
if (row[2][0])
2014-12-01 23:55:08 +01:00
{
2017-01-15 18:02:52 +01:00
Str_Copy (Gbl.Test.Answer.Options[NumOpt].Feedback,row[2],
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK);
2014-12-01 23:55:08 +01:00
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
2017-01-15 18:02:52 +01:00
Gbl.Test.Answer.Options[NumOpt].Feedback,
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false);
2014-12-01 23:55:08 +01:00
}
2019-03-18 15:42:22 +01:00
/***** Assign correctness (row[4]) of this answer (this option) *****/
Gbl.Test.Answer.Options[NumOpt].Correct = (row[4][0] == 'Y');
2014-12-01 23:55:08 +01:00
}
/***** Header with the title of each column *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginPadding (2);
HTM_TR_Begin (NULL);
2018-12-09 13:11:20 +01:00
Tst_WriteHeadUserCorrect (UsrDat);
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-10 10:41:00 +02:00
/***** Write the user answer *****/
2014-12-26 14:45:14 +01:00
if (Gbl.Test.StrAnswersOneQst[NumQst][0]) // If user has answered the question
2014-12-01 23:55:08 +01:00
{
/* Filter the user answer */
2017-01-15 22:58:26 +01:00
Str_Copy (TextAnsUsr,Gbl.Test.StrAnswersOneQst[NumQst],
2017-03-13 19:02:15 +01:00
Tst_MAX_BYTES_ANSWERS_ONE_QST);
2016-11-27 14:34:36 +01:00
/* In order to compare student answer to stored answer,
the text answers are stored avoiding two or more consecurive spaces */
Str_ReplaceSeveralSpacesForOne (TextAnsUsr);
2014-12-01 23:55:08 +01:00
Str_ConvertToComparable (TextAnsUsr);
for (NumOpt = 0;
NumOpt < Gbl.Test.Answer.NumOptions;
NumOpt++)
{
/* Filter this correct answer */
2017-01-15 22:58:26 +01:00
Str_Copy (TextAnsOK,Gbl.Test.Answer.Options[NumOpt].Text,
2017-03-13 19:02:15 +01:00
Tst_MAX_BYTES_ANSWERS_ONE_QST);
2014-12-01 23:55:08 +01:00
Str_ConvertToComparable (TextAnsOK);
/* Check is user answer is correct */
if (!strcoll (TextAnsUsr,TextAnsOK))
{
Correct = true;
break;
}
}
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s CT\"",
2020-02-18 09:19:33 +01:00
TsV_IsVisibleCorrectAns (Visibility) ?
2020-02-17 12:27:28 +01:00
(Correct ? "ANS_OK" :
"ANS_BAD") :
"ANS_0");
2019-11-10 12:36:37 +01:00
HTM_Txt (Gbl.Test.StrAnswersOneQst[NumQst]);
2014-12-01 23:55:08 +01:00
}
2014-12-26 14:45:14 +01:00
else // If user has omitted the answer
2019-10-23 19:05:05 +02:00
HTM_TD_Begin (NULL);
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Write the correct answers *****/
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleQstAndAnsTxt (Visibility) &&
TsV_IsVisibleCorrectAns (Visibility))
2014-12-01 23:55:08 +01:00
{
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CT\"");
HTM_TABLE_BeginPadding (2);
2017-05-01 21:17:38 +02:00
2014-12-01 23:55:08 +01:00
for (NumOpt = 0;
NumOpt < Gbl.Test.Answer.NumOptions;
NumOpt++)
{
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-10 10:41:00 +02:00
2014-12-01 23:55:08 +01:00
/* Answer letter (a, b, c,...) */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"ANS_0 LT\"");
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%c)&nbsp;",'a' + (char) NumOpt);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Answer text and feedback */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"ANS_0\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Gbl.Test.Answer.Options[NumOpt].Text);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-24 00:04:40 +02:00
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleFeedbackTxt (Visibility))
2014-12-01 23:55:08 +01:00
if (Gbl.Test.Answer.Options[NumOpt].Feedback)
if (Gbl.Test.Answer.Options[NumOpt].Feedback[0])
2019-10-23 20:07:56 +02:00
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TEST_EXA_LIGHT\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Gbl.Test.Answer.Options[NumOpt].Feedback);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
}
2019-10-24 00:04:40 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-10 10:41:00 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
2017-05-01 21:17:38 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
}
else
2019-10-10 00:49:39 +02:00
{
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"ANS_0 CT\"");
2020-02-19 00:45:26 +01:00
Ico_PutIconNotVisible ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-10 00:49:39 +02:00
}
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Compute the mark *****/
if (!Gbl.Test.StrAnswersOneQst[NumQst][0]) // If user has omitted the answer
{
*AnswerIsNotBlank = false;
*ScoreThisQst = 0.0;
}
else
{
*AnswerIsNotBlank = true;
if (Correct) // If correct
*ScoreThisQst = 1.0;
else // If wrong
*ScoreThisQst = 0.0;
}
2020-02-17 12:27:28 +01:00
/***** Write the score of this question *****/
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleEachQstScore (Visibility))
2014-12-01 23:55:08 +01:00
{
Tst_WriteScoreStart (4);
if (!Gbl.Test.StrAnswersOneQst[NumQst][0]) // If user has omitted the answer
2019-11-07 10:24:00 +01:00
{
HTM_SPAN_Begin ("class=\"ANS_0\"");
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (0.0);
2019-11-07 10:24:00 +01:00
}
else if (Correct) // If correct
{
HTM_SPAN_Begin ("class=\"ANS_OK\"");
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (1.0);
2019-11-07 10:24:00 +01:00
}
else // If wrong
{
HTM_SPAN_Begin ("class=\"ANS_BAD\"");
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (0.0);
2019-11-07 10:24:00 +01:00
}
HTM_SPAN_End ();
2014-12-01 23:55:08 +01:00
Tst_WriteScoreEnd ();
}
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/****************** Write integer answer when viewing a test *****************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
static void Tst_WriteIntAnsViewTest (unsigned NumQst)
2014-12-01 23:55:08 +01:00
{
2019-11-04 01:29:46 +01:00
char StrAns[3 + 6 + 1];
2014-12-01 23:55:08 +01:00
/***** Write input field for the answer *****/
2019-11-04 01:29:46 +01:00
snprintf (StrAns,sizeof (StrAns),
"Ans%06u",
NumQst);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT (StrAns,11,"",false,
2019-11-04 01:29:46 +01:00
"size=\"11\"");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/**************** Write integer answer when assessing a test *****************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2018-12-09 13:11:20 +01:00
static void Tst_WriteIntAnsAssessTest (struct UsrData *UsrDat,
unsigned NumQst,MYSQL_RES *mysql_res,
2020-02-17 23:15:08 +01:00
unsigned Visibility,
2014-12-01 23:55:08 +01:00
double *ScoreThisQst,bool *AnswerIsNotBlank)
{
MYSQL_ROW row;
2017-09-04 17:03:49 +02:00
long IntAnswerUsr;
long IntAnswerCorr;
2016-04-06 14:41:47 +02:00
/*
2019-03-02 21:49:11 +01:00
row[0] AnsInd
row[1] Answer
row[2] Feedback
2019-03-18 15:42:22 +01:00
row[3] MedCod
row[4] Correct
2016-04-06 14:41:47 +02:00
*/
2014-12-01 23:55:08 +01:00
/***** Check if number of rows is correct *****/
Tst_CheckIfNumberOfAnswersIsOne ();
/***** Get the numerical value of the correct answer *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[1],"%ld",&IntAnswerCorr) != 1)
Lay_ShowErrorAndExit ("Wrong integer answer.");
/***** Header with the title of each column *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginPadding (2);
HTM_TR_Begin (NULL);
2018-12-09 13:11:20 +01:00
Tst_WriteHeadUserCorrect (UsrDat);
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-10 10:41:00 +02:00
/***** Write the user answer *****/
2014-12-01 23:55:08 +01:00
if (Gbl.Test.StrAnswersOneQst[NumQst][0]) // If user has answered the question
{
if (sscanf (Gbl.Test.StrAnswersOneQst[NumQst],"%ld",&IntAnswerUsr) == 1)
2019-10-10 15:03:47 +02:00
{
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s CM\"",
2020-02-18 09:19:33 +01:00
TsV_IsVisibleCorrectAns (Visibility) ?
2020-02-17 12:27:28 +01:00
(IntAnswerUsr == IntAnswerCorr ? "ANS_OK" :
"ANS_BAD") :
"ANS_0");
2019-11-10 13:38:17 +01:00
HTM_Long (IntAnswerUsr);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-10 15:03:47 +02:00
}
2014-12-01 23:55:08 +01:00
else
{
Gbl.Test.StrAnswersOneQst[NumQst][0] = '\0';
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"ANS_0 CM\"");
2019-11-10 16:41:47 +01:00
HTM_Txt ("?");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
}
}
else // If user has omitted the answer
2019-10-23 19:05:05 +02:00
HTM_TD_Empty (1);
2014-12-01 23:55:08 +01:00
/***** Write the correct answer *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"ANS_0 CM\"");
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleQstAndAnsTxt (Visibility) &&
TsV_IsVisibleCorrectAns (Visibility))
2019-11-10 13:38:17 +01:00
HTM_Long (IntAnswerCorr);
2014-12-01 23:55:08 +01:00
else
2020-02-19 00:45:26 +01:00
Ico_PutIconNotVisible ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-10 10:41:00 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Compute the score *****/
if (!Gbl.Test.StrAnswersOneQst[NumQst][0]) // If user has omitted the answer
{
*AnswerIsNotBlank = false;
*ScoreThisQst = 0.0;
}
else
{
*AnswerIsNotBlank = true;
if (IntAnswerUsr == IntAnswerCorr) // If correct
*ScoreThisQst = 1.0;
else // If wrong
*ScoreThisQst = 0.0;
}
2020-02-17 12:27:28 +01:00
/***** Write the score of this question *****/
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleEachQstScore (Visibility))
2014-12-01 23:55:08 +01:00
{
Tst_WriteScoreStart (2);
if (!Gbl.Test.StrAnswersOneQst[NumQst][0]) // If user has omitted the answer
2019-11-07 10:24:00 +01:00
{
HTM_SPAN_Begin ("class=\"ANS_0\"");
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (0.0);
2019-11-07 10:24:00 +01:00
}
else if (IntAnswerUsr == IntAnswerCorr) // If correct
{
HTM_SPAN_Begin ("class=\"ANS_OK\"");
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (1.0);
2019-11-07 10:24:00 +01:00
}
else // If wrong
{
HTM_SPAN_Begin ("class=\"ANS_BAD\"");
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (0.0);
2019-11-07 10:24:00 +01:00
}
HTM_SPAN_End ();
2014-12-01 23:55:08 +01:00
Tst_WriteScoreEnd ();
}
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/****************** Write float answer when viewing a test *******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
static void Tst_WriteFloatAnsViewTest (unsigned NumQst)
2014-12-01 23:55:08 +01:00
{
2019-11-04 01:29:46 +01:00
char StrAns[3 + 6 + 1];
2014-12-01 23:55:08 +01:00
/***** Write input field for the answer *****/
2019-11-04 01:29:46 +01:00
snprintf (StrAns,sizeof (StrAns),
"Ans%06u",
NumQst);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT (StrAns,Tst_MAX_BYTES_FLOAT_ANSWER,"",false,
2019-11-04 01:29:46 +01:00
"size=\"11\"");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-11-21 13:15:08 +01:00
/***************** Write float answer when assessing a test ******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2018-12-09 13:11:20 +01:00
static void Tst_WriteFloatAnsAssessTest (struct UsrData *UsrDat,
unsigned NumQst,MYSQL_RES *mysql_res,
2020-02-17 23:15:08 +01:00
unsigned Visibility,
2014-12-01 23:55:08 +01:00
double *ScoreThisQst,bool *AnswerIsNotBlank)
{
MYSQL_ROW row;
unsigned i;
double FloatAnsUsr = 0.0,Tmp;
double FloatAnsCorr[2];
2016-04-06 14:41:47 +02:00
/*
2019-03-02 21:49:11 +01:00
row[0] AnsInd
row[1] Answer
row[2] Feedback
2019-03-18 15:42:22 +01:00
row[3] MedCod
row[4] Correct
2016-04-06 14:41:47 +02:00
*/
2014-12-01 23:55:08 +01:00
/***** Check if number of rows is correct *****/
if (Gbl.Test.Answer.NumOptions != 2)
Lay_ShowErrorAndExit ("Wrong float range.");
/***** Get the numerical value of the minimum and maximum correct answers *****/
for (i = 0;
i < 2;
i++)
{
row = mysql_fetch_row (mysql_res);
2019-11-27 09:01:45 +01:00
FloatAnsCorr[i] = Str_GetDoubleFromStr (row[1]);
2014-12-01 23:55:08 +01:00
}
if (FloatAnsCorr[0] > FloatAnsCorr[1]) // The maximum and the minimum are swapped
{
/* Swap maximum and minimum */
Tmp = FloatAnsCorr[0];
FloatAnsCorr[0] = FloatAnsCorr[1];
FloatAnsCorr[1] = Tmp;
}
/***** Header with the title of each column *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginPadding (2);
HTM_TR_Begin (NULL);
2018-12-09 13:11:20 +01:00
Tst_WriteHeadUserCorrect (UsrDat);
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-10 10:41:00 +02:00
/***** Write the user answer *****/
2014-12-01 23:55:08 +01:00
if (Gbl.Test.StrAnswersOneQst[NumQst][0]) // If user has answered the question
{
2019-11-27 09:01:45 +01:00
FloatAnsUsr = Str_GetDoubleFromStr (Gbl.Test.StrAnswersOneQst[NumQst]);
2014-12-01 23:55:08 +01:00
if (Gbl.Test.StrAnswersOneQst[NumQst][0]) // It's a correct floating point number
2019-10-10 11:08:53 +02:00
{
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s CM\"",
2020-02-18 09:19:33 +01:00
TsV_IsVisibleCorrectAns (Visibility) ?
2020-02-17 12:27:28 +01:00
((FloatAnsUsr >= FloatAnsCorr[0] &&
FloatAnsUsr <= FloatAnsCorr[1]) ? "ANS_OK" :
"ANS_BAD") :
"ANS_0");
2020-01-11 15:22:02 +01:00
HTM_Double (FloatAnsUsr);
2019-10-10 11:08:53 +02:00
}
2014-12-01 23:55:08 +01:00
else // Not a floating point number
2019-10-10 11:08:53 +02:00
{
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"ANS_0 CM\"");
2019-11-10 16:41:47 +01:00
HTM_Txt ("?");
2019-10-10 11:08:53 +02:00
}
2014-12-01 23:55:08 +01:00
}
else // If user has omitted the answer
2019-10-23 19:05:05 +02:00
HTM_TD_Begin (NULL);
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Write the correct answer *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"ANS_0 CM\"");
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleQstAndAnsTxt (Visibility) &&
TsV_IsVisibleCorrectAns (Visibility))
2020-01-11 15:22:02 +01:00
{
HTM_Txt ("[");
HTM_Double (FloatAnsCorr[0]);
HTM_Txt ("; ");
HTM_Double (FloatAnsCorr[1]);
HTM_Txt ("]");
}
2014-12-01 23:55:08 +01:00
else
2020-02-19 00:45:26 +01:00
Ico_PutIconNotVisible ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-10 10:41:00 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Compute mark *****/
if (!Gbl.Test.StrAnswersOneQst[NumQst][0]) // If user has omitted the answer
{
*AnswerIsNotBlank = false;
*ScoreThisQst = 0.0;
}
else
{
*AnswerIsNotBlank = true;
if (FloatAnsUsr >= FloatAnsCorr[0] &&
FloatAnsUsr <= FloatAnsCorr[1]) // If correct (inside the interval)
*ScoreThisQst = 1.0;
else // If wrong (outside the interval)
*ScoreThisQst = 0.0;
}
2020-02-17 12:27:28 +01:00
/***** Write the score of this question *****/
2020-02-18 09:19:33 +01:00
if (TsV_IsVisibleEachQstScore (Visibility))
2014-12-01 23:55:08 +01:00
{
Tst_WriteScoreStart (2);
if (!Gbl.Test.StrAnswersOneQst[NumQst][0]) // If user has omitted the answer
2019-11-07 10:24:00 +01:00
{
HTM_SPAN_Begin ("class=\"ANS_0\"");
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (0.0);
2019-11-07 10:24:00 +01:00
}
2014-12-01 23:55:08 +01:00
else if (FloatAnsUsr >= FloatAnsCorr[0] &&
2019-11-07 10:24:00 +01:00
FloatAnsUsr <= FloatAnsCorr[1]) // If correct (inside the interval)
{
HTM_SPAN_Begin ("class=\"ANS_OK\"");
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (1.0);
2019-11-07 10:24:00 +01:00
}
else // If wrong (outside the interval)
{
HTM_SPAN_Begin ("class=\"ANS_BAD\"");
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (0.0);
2019-11-07 10:24:00 +01:00
}
HTM_SPAN_End ();
2014-12-01 23:55:08 +01:00
Tst_WriteScoreEnd ();
}
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********* Write head with two columns: ********/
/********* one for the user's answer and other for the correct answer ********/
/*****************************************************************************/
2018-12-09 13:11:20 +01:00
static void Tst_WriteHeadUserCorrect (struct UsrData *UsrDat)
2014-12-01 23:55:08 +01:00
{
2016-06-15 14:42:28 +02:00
extern const char *Txt_User[Usr_NUM_SEXS];
2018-12-09 13:11:20 +01:00
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT_SMALL CM\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_User[UsrDat->Sex]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT_SMALL CM\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_ROLES_PLURAL_Abc[Rol_TCH][Usr_SEX_UNKNOWN]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********** Write the start ans the end of the score of an answer ***********/
/*****************************************************************************/
static void Tst_WriteScoreStart (unsigned ColSpan)
{
extern const char *Txt_Score;
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
HTM_TD_Begin ("colspan=\"%u\" class=\"DAT_SMALL LM\"",ColSpan);
2020-01-11 15:22:02 +01:00
HTM_TxtColonNBSP (Txt_Score);
2014-12-01 23:55:08 +01:00
}
static void Tst_WriteScoreEnd (void)
{
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Write parameter with the code of a question *****************/
/*****************************************************************************/
static void Tst_WriteParamQstCod (unsigned NumQst,long QstCod)
{
2017-01-28 15:58:46 +01:00
char ParamName[3 + 6 + 1];
2014-12-01 23:55:08 +01:00
2018-10-18 02:02:32 +02:00
snprintf (ParamName,sizeof (ParamName),
"Qst%06u",
NumQst);
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamLong (NULL,ParamName,QstCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Check if number of answers is one *********************/
/*****************************************************************************/
void Tst_CheckIfNumberOfAnswersIsOne (void)
{
if (Gbl.Test.Answer.NumOptions != 1)
Lay_ShowErrorAndExit ("Wrong answer.");
}
/*****************************************************************************/
/************************* Get tags of a test question ***********************/
/*****************************************************************************/
unsigned long Tst_GetTagsQst (long QstCod,MYSQL_RES **mysql_res)
{
/***** Get the tags of a question from database *****/
2018-11-02 01:38:44 +01:00
return DB_QuerySELECT (mysql_res,"can not get the tags of a question",
"SELECT tst_tags.TagTxt FROM tst_question_tags,tst_tags"
" WHERE tst_question_tags.QstCod=%ld"
" AND tst_question_tags.TagCod=tst_tags.TagCod"
" AND tst_tags.CrsCod=%ld"
" ORDER BY tst_question_tags.TagInd",
2019-04-04 10:45:15 +02:00
QstCod,Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Get and write tags of a test question ******************/
/*****************************************************************************/
2017-09-06 15:03:43 +02:00
void Tst_GetAndWriteTagsQst (long QstCod)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_no_tags;
2019-11-07 14:34:03 +01:00
unsigned long NumRow;
unsigned long NumRows;
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
if ((NumRows = Tst_GetTagsQst (QstCod,&mysql_res))) // Result: TagTxt
{
/***** Write the tags *****/
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("class=\"TEST_TAG_LIST DAT_SMALL\"");
2014-12-01 23:55:08 +01:00
for (NumRow = 0;
NumRow < NumRows;
NumRow++)
{
row = mysql_fetch_row (mysql_res);
2019-10-26 22:49:13 +02:00
HTM_LI_Begin (NULL);
2019-11-10 12:36:37 +01:00
HTM_Txt (row[0]);
2019-10-26 22:49:13 +02:00
HTM_LI_End ();
2014-12-01 23:55:08 +01:00
}
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2014-12-01 23:55:08 +01:00
}
else
2019-11-07 10:24:00 +01:00
{
HTM_SPAN_Begin ("class=\"DAT_SMALL\"");
2019-11-11 00:15:44 +01:00
HTM_TxtF ("(%s)",Txt_no_tags);
2019-11-07 10:24:00 +01:00
HTM_SPAN_End ();
}
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/************ Get parameters for the selection of test questions *************/
/*****************************************************************************/
2016-04-05 02:59:34 +02:00
// Return true (OK) if all parameters are found, or false (error) if any necessary parameter is not found
2014-12-01 23:55:08 +01:00
2017-07-16 13:54:11 +02:00
static bool Tst_GetParamsTst (Tst_ActionToDoWithQuestions_t ActionToDoWithQuestions)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_You_must_select_one_ore_more_tags;
extern const char *Txt_You_must_select_one_ore_more_types_of_answer;
extern const char *Txt_The_number_of_questions_must_be_in_the_interval_X;
bool Error = false;
2019-11-08 01:10:32 +01:00
char UnsignedStr[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
2014-12-01 23:55:08 +01:00
unsigned UnsignedNum;
/***** Tags *****/
/* Get parameter that indicates whether all tags are selected */
2017-01-28 20:32:50 +01:00
Gbl.Test.Tags.All = Par_GetParToBool ("AllTags");
2014-12-01 23:55:08 +01:00
/* Get the tags */
2018-10-08 12:37:29 +02:00
if ((Gbl.Test.Tags.List = (char *) malloc (Tst_MAX_BYTES_TAGS_LIST + 1)) == NULL)
2018-10-18 20:06:54 +02:00
Lay_NotEnoughMemoryExit ();
2016-04-06 22:27:33 +02:00
Par_GetParMultiToText ("ChkTag",Gbl.Test.Tags.List,Tst_MAX_BYTES_TAGS_LIST);
2014-12-01 23:55:08 +01:00
/* Check number of tags selected */
if (Tst_CountNumTagsInList () == 0) // If no tags selected...
{ // ...write alert
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_select_one_ore_more_tags);
2014-12-01 23:55:08 +01:00
Error = true;
}
/***** Types of answer *****/
2017-07-16 13:54:11 +02:00
switch (ActionToDoWithQuestions)
{
2017-09-04 17:03:49 +02:00
case Tst_SHOW_TEST_TO_ANSWER:
case Tst_EDIT_TEST:
2017-07-16 13:54:11 +02:00
/* Get parameter that indicates if all types of answer are selected */
Gbl.Test.AllAnsTypes = Par_GetParToBool ("AllAnsTypes");
/* Get types of answer */
Par_GetParMultiToText ("AnswerType",Gbl.Test.ListAnsTypes,Tst_MAX_BYTES_LIST_ANSWER_TYPES);
/* Check number of types of answer */
if (Tst_CountNumAnswerTypesInList () == 0) // If no types of answer selected...
{ // ...write warning alert
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_select_one_ore_more_types_of_answer);
2017-07-16 13:54:11 +02:00
Error = true;
}
break;
case Tst_SELECT_QUESTIONS_FOR_GAME:
/* The unique allowed type of answer in a game is unique choice */
Gbl.Test.AllAnsTypes = false;
2018-10-18 02:02:32 +02:00
snprintf (Gbl.Test.ListAnsTypes,sizeof (Gbl.Test.ListAnsTypes),
"%u",
(unsigned) Tst_ANS_UNIQUE_CHOICE);
2017-07-16 13:54:11 +02:00
break;
2017-09-01 14:36:25 +02:00
default:
break;
2014-12-01 23:55:08 +01:00
}
/***** Get other parameters, depending on action *****/
2017-07-16 13:54:11 +02:00
switch (ActionToDoWithQuestions)
2014-12-01 23:55:08 +01:00
{
2017-09-04 17:03:49 +02:00
case Tst_SHOW_TEST_TO_ANSWER:
2017-07-16 13:54:11 +02:00
Tst_GetParamNumQst ();
if (Gbl.Test.NumQsts < Gbl.Test.Config.Min ||
Gbl.Test.NumQsts > Gbl.Test.Config.Max)
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_The_number_of_questions_must_be_in_the_interval_X,
Gbl.Test.Config.Min,Gbl.Test.Config.Max);
2017-07-16 13:54:11 +02:00
Error = true;
}
break;
2017-09-04 17:03:49 +02:00
case Tst_EDIT_TEST:
2017-07-16 13:54:11 +02:00
/* Get starting and ending dates */
Dat_GetIniEndDatesFromForm ();
/* Get ordering criteria */
2019-11-08 01:10:32 +01:00
Par_GetParMultiToText ("Order",UnsignedStr,Cns_MAX_DECIMAL_DIGITS_UINT);
2017-07-16 13:54:11 +02:00
if (sscanf (UnsignedStr,"%u",&UnsignedNum) == 1)
Gbl.Test.SelectedOrder = (Tst_QuestionsOrder_t) ((UnsignedNum < Tst_NUM_TYPES_ORDER_QST) ? UnsignedNum :
0);
else
Gbl.Test.SelectedOrder = (Tst_QuestionsOrder_t) 0;
/* Get whether we must create the XML file or not */
Gbl.Test.XML.CreateXML = Tst_GetCreateXMLFromForm ();
break;
case Tst_SELECT_QUESTIONS_FOR_GAME:
/* Get starting and ending dates */
Dat_GetIniEndDatesFromForm ();
2014-12-01 23:55:08 +01:00
2017-07-16 13:54:11 +02:00
/* Order question by stem */
Gbl.Test.SelectedOrder = Tst_ORDER_STEM;
break;
2017-09-01 14:36:25 +02:00
default:
break;
2014-12-01 23:55:08 +01:00
}
2016-04-05 02:59:34 +02:00
return !Error;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Get parameter with the number of test ******************/
/*****************************************************************************/
static unsigned Tst_GetAndCheckParamNumTst (void)
{
2017-01-29 21:41:08 +01:00
return (unsigned) Par_GetParToUnsignedLong ("NumTst",
1,
UINT_MAX,
1);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***** Get parameter with the number of questions to generate in an test *****/
/*****************************************************************************/
static void Tst_GetParamNumQst (void)
{
2017-01-29 21:41:08 +01:00
Gbl.Test.NumQsts = (unsigned)
Par_GetParToUnsignedLong ("NumQst",
(unsigned long) Gbl.Test.Config.Min,
(unsigned long) Gbl.Test.Config.Max,
(unsigned long) Gbl.Test.Config.Def);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Get whether to create XML file from form *****************/
/*****************************************************************************/
static bool Tst_GetCreateXMLFromForm (void)
{
2017-01-28 20:32:50 +01:00
return Par_GetParToBool ("CreateXML");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Count number of tags in the list of tags ******************/
/*****************************************************************************/
static int Tst_CountNumTagsInList (void)
{
const char *Ptr;
int NumTags = 0;
2017-01-28 15:58:46 +01:00
char TagText[Tst_MAX_BYTES_TAG + 1];
2014-12-01 23:55:08 +01:00
2016-04-06 22:27:33 +02:00
/***** Go over the list Gbl.Test.Tags.List counting the number of tags *****/
if (Gbl.Test.Tags.List)
2014-12-01 23:55:08 +01:00
{
2016-04-06 22:27:33 +02:00
Ptr = Gbl.Test.Tags.List;
2014-12-01 23:55:08 +01:00
while (*Ptr)
{
Par_GetNextStrUntilSeparParamMult (&Ptr,TagText,Tst_MAX_BYTES_TAG);
NumTags++;
}
}
return NumTags;
}
/*****************************************************************************/
/**** Count the number of types of answers in the list of types of answers ***/
/*****************************************************************************/
static int Tst_CountNumAnswerTypesInList (void)
{
const char *Ptr;
int NumAnsTypes = 0;
2019-11-08 01:10:32 +01:00
char UnsignedStr[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
2014-12-01 23:55:08 +01:00
/***** Go over the list Gbl.Test.ListAnsTypes counting the number of types of answer *****/
Ptr = Gbl.Test.ListAnsTypes;
while (*Ptr)
{
2019-11-08 01:10:32 +01:00
Par_GetNextStrUntilSeparParamMult (&Ptr,UnsignedStr,Cns_MAX_DECIMAL_DIGITS_UINT);
2014-12-01 23:55:08 +01:00
Tst_ConvertFromUnsignedStrToAnsTyp (UnsignedStr);
NumAnsTypes++;
}
return NumAnsTypes;
}
/*****************************************************************************/
/**************** Free memory allocated for the list of tags *****************/
/*****************************************************************************/
void Tst_FreeTagsList (void)
{
2016-04-06 22:27:33 +02:00
if (Gbl.Test.Tags.List)
2014-12-01 23:55:08 +01:00
{
2019-11-06 19:45:20 +01:00
free (Gbl.Test.Tags.List);
2016-04-06 22:27:33 +02:00
Gbl.Test.Tags.List = NULL;
Gbl.Test.Tags.Num = 0;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/******************** Show form to edit one test question ********************/
/*****************************************************************************/
void Tst_ShowFormEditOneQst (void)
{
2017-01-17 03:10:43 +01:00
char Stem[Cns_MAX_BYTES_TEXT + 1];
char Feedback[Cns_MAX_BYTES_TEXT + 1];
2014-12-01 23:55:08 +01:00
2016-04-06 19:26:09 +02:00
/***** Create test question *****/
Tst_QstConstructor ();
Gbl.Test.QstCod = Tst_GetQstCod ();
2014-12-01 23:55:08 +01:00
Stem[0] = Feedback[0] = '\0';
2016-04-06 19:26:09 +02:00
if (Gbl.Test.QstCod > 0) // If question already exists in the database
Tst_GetQstDataFromDB (Stem,Feedback);
/***** Put form to edit question *****/
2014-12-01 23:55:08 +01:00
Tst_PutFormEditOneQst (Stem,Feedback);
2016-04-06 19:26:09 +02:00
/***** Destroy test question *****/
Tst_QstDestructor ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Show form to edit one test question ********************/
/*****************************************************************************/
// This function may be called from three places:
2016-11-27 14:34:36 +01:00
// 1. By clicking "New question" icon
// 2. By clicking "Edit" icon in a listing of existing questions
2014-12-01 23:55:08 +01:00
// 3. From the action associated to reception of a question, on error in the parameters received from the form
2017-01-17 03:10:43 +01:00
static void Tst_PutFormEditOneQst (char Stem[Cns_MAX_BYTES_TEXT + 1],
char Feedback[Cns_MAX_BYTES_TEXT + 1])
2014-12-01 23:55:08 +01:00
{
2019-03-27 14:36:57 +01:00
extern const char *Hlp_ASSESSMENT_Tests_writing_a_question;
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Question_code_X;
extern const char *Txt_New_question;
extern const char *Txt_Tags;
extern const char *Txt_new_tag;
2019-09-12 23:53:00 +02:00
extern const char *Txt_Wording;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Feedback;
2016-04-05 17:33:33 +02:00
extern const char *Txt_optional;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Type;
extern const char *Txt_TST_STR_ANSWER_TYPES[Tst_NUM_ANS_TYPES];
extern const char *Txt_Answers;
extern const char *Txt_Integer_number;
extern const char *Txt_Real_number_between_A_and_B_1;
extern const char *Txt_Real_number_between_A_and_B_2;
extern const char *Txt_TF_QST[2];
extern const char *Txt_Shuffle;
2016-04-07 14:40:50 +02:00
extern const char *Txt_Expand;
extern const char *Txt_Contract;
2019-02-18 18:27:45 +01:00
extern const char *Txt_Save_changes;
2015-04-11 20:18:30 +02:00
extern const char *Txt_Create_question;
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-04-03 01:24:20 +02:00
unsigned long NumRows;
unsigned long NumRow;
2014-12-01 23:55:08 +01:00
unsigned NumOpt;
Tst_AnswerType_t AnsType;
unsigned NumTag;
2019-11-07 00:34:20 +01:00
bool IsThisTag;
bool TagFound;
2014-12-01 23:55:08 +01:00
bool OptionsDisabled;
2016-04-07 10:23:28 +02:00
bool AnswerHasContent;
2016-04-07 17:14:35 +02:00
bool DisplayRightColumn;
2019-11-08 01:10:32 +01:00
char StrTagTxt[6 + Cns_MAX_DECIMAL_DIGITS_UINT + 1];
char StrInteger[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
2019-12-30 22:32:06 +01:00
char *Title;
2014-12-01 23:55:08 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2015-04-11 13:05:44 +02:00
if (Gbl.Test.QstCod > 0) // The question already has assigned a code
{
2019-12-30 21:47:07 +01:00
Box_BoxBegin (NULL,Str_BuildStringLong (Txt_Question_code_X,Gbl.Test.QstCod),
2019-12-30 18:49:52 +01:00
Tst_PutIconToRemoveOneQst,
2019-03-27 14:36:57 +01:00
Hlp_ASSESSMENT_Tests_writing_a_question,Box_NOT_CLOSABLE);
2019-12-30 21:47:07 +01:00
Str_FreeString ();
2015-04-11 13:05:44 +02:00
}
else
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,Txt_New_question,NULL,
2019-03-27 14:36:57 +01:00
Hlp_ASSESSMENT_Tests_writing_a_question,Box_NOT_CLOSABLE);
2016-04-05 10:05:52 +02:00
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRcvTstQst);
2016-04-05 10:05:52 +02:00
if (Gbl.Test.QstCod > 0) // The question already has assigned a code
2017-04-28 14:02:08 +02:00
Tst_PutParamQstCod ();
2016-04-05 10:05:52 +02:00
2019-10-20 22:00:28 +02:00
/***** Begin table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginPadding (2); // Table for this question
2015-04-11 13:05:44 +02:00
/***** Help for text editor *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
HTM_TD_Begin ("colspan=\"2\"");
2015-04-11 13:05:44 +02:00
Lay_HelpPlainEditor ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Get tags already existing for questions in current course *****/
NumRows = Tst_GetAllTagsFromCurrentCrs (&mysql_res);
/***** Write the tags *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"RT %s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_Tags);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
HTM_TABLE_BeginPadding (2); // Table for tags
2017-05-01 21:17:38 +02:00
2014-12-01 23:55:08 +01:00
for (NumTag = 0;
NumTag < Tst_MAX_TAGS_PER_QUESTION;
NumTag++)
{
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2014-12-01 23:55:08 +01:00
/***** Write the tags already existing in a selector *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2019-11-05 15:47:35 +01:00
HTM_SELECT_Begin (false,
"id=\"SelDesc%u\" name=\"SelDesc%u\""
" class=\"TAG_SEL\" onchange=\"changeTxtTag('%u')\"",
NumTag,NumTag,NumTag);
2019-11-07 00:34:20 +01:00
HTM_OPTION (HTM_Type_STRING,"",false,false,"&nbsp;");
2017-04-25 14:48:47 +02:00
mysql_data_seek (mysql_res,0);
2019-11-07 00:34:20 +01:00
TagFound = false;
2014-12-01 23:55:08 +01:00
for (NumRow = 1;
NumRow <= NumRows;
NumRow++)
{
row = mysql_fetch_row (mysql_res);
2019-03-18 15:42:22 +01:00
/*
row[0] TagCod
row[1] TagTxt
row[2] TagHidden
*/
2019-11-07 00:34:20 +01:00
IsThisTag = false;
2016-04-06 22:27:33 +02:00
if (!strcasecmp (Gbl.Test.Tags.Txt[NumTag],row[1]))
2014-12-01 23:55:08 +01:00
{
2019-11-11 00:15:44 +01:00
HTM_Txt (" selected=\"selected\"");
2019-11-07 00:34:20 +01:00
IsThisTag = true;
TagFound = true;
2014-12-01 23:55:08 +01:00
}
2019-11-07 00:34:20 +01:00
HTM_OPTION (HTM_Type_STRING,row[1],
IsThisTag,false,
"%s",row[1]);
2014-12-01 23:55:08 +01:00
}
/* If it's a new tag received from the form */
2019-11-07 00:34:20 +01:00
if (!TagFound && Gbl.Test.Tags.Txt[NumTag][0])
HTM_OPTION (HTM_Type_STRING,Gbl.Test.Tags.Txt[NumTag],
true,false,
"%s",Gbl.Test.Tags.Txt[NumTag]);
HTM_OPTION (HTM_Type_STRING,"",
false,false,
"[%s]",Txt_new_tag);
2019-11-05 08:46:38 +01:00
HTM_SELECT_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Input of a new tag *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"RM\"");
2019-11-04 01:29:46 +01:00
snprintf (StrTagTxt,sizeof (StrTagTxt),
"TagTxt%u",
NumTag);
2019-11-05 00:30:51 +01:00
HTM_INPUT_TEXT (StrTagTxt,Tst_MAX_CHARS_TAG,Gbl.Test.Tags.Txt[NumTag],false,
2019-11-13 09:49:52 +01:00
"id=\"%s\" class=\"TAG_TXT\" onchange=\"changeSelTag('%u')\"",
StrTagTxt,NumTag);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
2017-05-01 21:17:38 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_End (); // Table for tags
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
2016-04-04 10:11:05 +02:00
/***** Stem and image *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
2019-12-27 21:10:39 +01:00
/* Label */
2019-12-27 15:45:19 +01:00
Frm_LabelColumn ("RT","Stem",Txt_Wording);
2019-10-07 21:15:14 +02:00
2019-12-27 21:10:39 +01:00
/* Data */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2019-10-31 17:42:05 +01:00
HTM_TEXTAREA_Begin ("id=\"Stem\" name=\"Stem\" class=\"STEM_TEXTAREA\""
" rows=\"5\" required=\"required\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Stem);
2019-10-31 17:42:05 +01:00
HTM_TEXTAREA_End ();
2019-11-09 21:08:20 +01:00
HTM_BR ();
2019-03-02 21:49:11 +01:00
Tst_PutFormToEditQstMedia (&Gbl.Test.Media,-1,
2016-04-14 21:33:24 +02:00
false);
2016-03-29 10:24:14 +02:00
2014-12-01 23:55:08 +01:00
/***** Feedback *****/
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s&nbsp;(%s):",Txt_Feedback,Txt_optional);
2019-11-09 21:08:20 +01:00
HTM_BR ();
2019-10-31 17:42:05 +01:00
HTM_TEXTAREA_Begin ("name=\"Feedback\" class=\"STEM_TEXTAREA\" rows=\"2\"");
2014-12-01 23:55:08 +01:00
if (Feedback)
if (Feedback[0])
2019-11-10 12:36:37 +01:00
HTM_Txt (Feedback);
2019-10-31 17:42:05 +01:00
HTM_TEXTAREA_End ();
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Type of answer *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"RT %s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_Type);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s LT\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-12-15 20:02:34 +01:00
for (AnsType = (Tst_AnswerType_t) 0;
AnsType <= (Tst_AnswerType_t) (Tst_NUM_ANS_TYPES - 1);
2014-12-01 23:55:08 +01:00
AnsType++)
{
2019-11-03 10:41:31 +01:00
HTM_LABEL_Begin (NULL);
2019-11-04 18:17:39 +01:00
HTM_INPUT_RADIO ("AnswerType",false,
"value=\"%u\"%s onclick=\"enableDisableAns(this.form);\"",
(unsigned) AnsType,
AnsType == Gbl.Test.AnswerType ? " checked=\"checked\"" : "");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s&nbsp;",Txt_TST_STR_ANSWER_TYPES[AnsType]);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-11-09 21:08:20 +01:00
HTM_BR ();
2014-12-01 23:55:08 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Answers *****/
/* Integer answer */
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"RT %s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_Answers);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2020-01-11 15:22:02 +01:00
HTM_TxtColonNBSP (Txt_Integer_number);
2019-11-04 01:29:46 +01:00
snprintf (StrInteger,sizeof (StrInteger),
"%ld",
Gbl.Test.Answer.Integer);
2019-11-08 01:10:32 +01:00
HTM_INPUT_TEXT ("AnsInt",Cns_MAX_DECIMAL_DIGITS_LONG,StrInteger,false,
2019-11-04 01:29:46 +01:00
"size=\"11\" required=\"required\"%s",
Gbl.Test.AnswerType == Tst_ANS_INT ? "" :
" disabled=\"disabled\"");
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/* Floating point answer */
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
HTM_TD_Empty (1);
HTM_TD_Begin ("class=\"LT\"");
2016-12-26 15:17:30 +01:00
Tst_PutFloatInputField (Txt_Real_number_between_A_and_B_1,"AnsFloatMin",
Gbl.Test.Answer.FloatingPoint[0]);
Tst_PutFloatInputField (Txt_Real_number_between_A_and_B_2,"AnsFloatMax",
Gbl.Test.Answer.FloatingPoint[1]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/* T/F answer */
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
HTM_TD_Empty (1);
HTM_TD_Begin ("class=\"LT\"");
2016-12-26 16:30:46 +01:00
Tst_PutTFInputField (Txt_TF_QST[0],'T');
Tst_PutTFInputField (Txt_TF_QST[1],'F');
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/* Questions can be shuffled? */
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Empty (1);
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2020-03-12 13:53:37 +01:00
HTM_INPUT_CHECKBOX ("Shuffle",HTM_DONT_SUBMIT_ON_CHANGE,
2019-11-04 20:41:35 +01:00
"value=\"Y\"%s%s",
Gbl.Test.Shuffle ? " checked=\"checked\"" : "",
Gbl.Test.AnswerType != Tst_ANS_UNIQUE_CHOICE &&
2020-03-12 13:53:37 +01:00
Gbl.Test.AnswerType != Tst_ANS_MULTIPLE_CHOICE ? " disabled=\"disabled\"" :
"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_Shuffle);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/* Simple or multiple choice answers */
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
HTM_TD_Empty (1);
HTM_TD_Begin ("class=\"LT\"");
HTM_TABLE_BeginPadding (2); // Table with choice answers
2017-05-01 21:17:38 +02:00
2014-12-01 23:55:08 +01:00
OptionsDisabled = Gbl.Test.AnswerType != Tst_ANS_UNIQUE_CHOICE &&
Gbl.Test.AnswerType != Tst_ANS_MULTIPLE_CHOICE &&
Gbl.Test.AnswerType != Tst_ANS_TEXT;
for (NumOpt = 0;
NumOpt < Tst_MAX_OPTIONS_PER_QUESTION;
NumOpt++)
{
2016-04-05 14:32:02 +02:00
Gbl.RowEvenOdd = NumOpt % 2;
2016-04-07 14:40:50 +02:00
AnswerHasContent = false;
if (Gbl.Test.Answer.Options[NumOpt].Text)
2019-03-19 01:41:27 +01:00
if (Gbl.Test.Answer.Options[NumOpt].Text[0] || // Text
Gbl.Test.Answer.Options[NumOpt].Media.Type != Med_TYPE_NONE) // or media
2016-04-07 14:40:50 +02:00
AnswerHasContent = true;
2016-11-19 19:39:17 +01:00
DisplayRightColumn = NumOpt < 2 || // Display at least the two first options
AnswerHasContent;
2016-04-07 14:40:50 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 21:15:14 +02:00
/***** Left column: selectors *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"TEST_EDI_ANS_LEFT_COL COLOR%u\"",Gbl.RowEvenOdd);
2016-11-19 19:39:17 +01:00
/* Radio selector for unique choice answers */
2019-11-04 18:17:39 +01:00
HTM_INPUT_RADIO ("AnsUni",false,
"value=\"%u\"%s%s%s onclick=\"enableDisableAns(this.form);\"",
NumOpt,
Gbl.Test.Answer.Options[NumOpt].Correct ? " checked=\"checked\"" : "",
NumOpt < 2 ? " required=\"required\"" : "", // First or second options required
Gbl.Test.AnswerType == Tst_ANS_UNIQUE_CHOICE ? "" : " disabled=\"disabled\"");
2016-11-19 19:39:17 +01:00
/* Checkbox for multiple choice answers */
2020-03-12 13:53:37 +01:00
HTM_INPUT_CHECKBOX ("AnsMulti",HTM_DONT_SUBMIT_ON_CHANGE,
2019-11-04 20:41:35 +01:00
"value=\"%u\"%s%s",
NumOpt,
Gbl.Test.Answer.Options[NumOpt].Correct ? " checked=\"checked\"" : "",
2020-03-12 13:53:37 +01:00
Gbl.Test.AnswerType == Tst_ANS_MULTIPLE_CHOICE ? "" :
" disabled=\"disabled\"");
2016-11-19 19:39:17 +01:00
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2016-04-07 17:14:35 +02:00
/***** Center column: letter of the answer and expand / contract icon *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s TEST_EDI_ANS_CENTER_COL COLOR%u\"",
2019-10-10 23:14:13 +02:00
The_ClassFormInBox[Gbl.Prefs.Theme],Gbl.RowEvenOdd);
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%c)",'a' + (char) NumOpt);
2014-12-01 23:55:08 +01:00
2016-04-07 17:14:35 +02:00
/* Icon to expand (show the answer) */
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"\" id=\"exp_%u\"%s"
" onclick=\"toggleAnswer('%u');return false;\"",
NumOpt,
DisplayRightColumn ? " style=\"display:none;\"" : // Answer does have content ==> Hide icon
"",
NumOpt);
2019-12-30 22:32:06 +01:00
if (asprintf (&Title,"%s %c)",Txt_Expand,'a' + (char) NumOpt) < 0)
Lay_NotEnoughMemoryExit ();
Ico_PutIcon ("caret-right.svg",Title,"ICO16x16");
free (Title);
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2016-04-07 17:14:35 +02:00
/* Icon to contract (hide the answer) */
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"\" id=\"con_%u\"%s"
" onclick=\"toggleAnswer(%u);return false;\"",
NumOpt,
DisplayRightColumn ? "" :
" style=\"display:none;\"", // Answer does not have content ==> Hide icon
NumOpt);
2019-12-30 22:32:06 +01:00
if (asprintf (&Title,"%s %c)",Txt_Contract,'a' + (char) NumOpt) < 0)
Lay_NotEnoughMemoryExit ();
Ico_PutIcon ("caret-down.svg",Title,"ICO16x16");
free (Title);
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2016-04-07 10:23:28 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2016-04-07 14:40:50 +02:00
/***** Right column: content of the answer *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"TEST_EDI_ANS_RIGHT_COL COLOR%u\"",Gbl.RowEvenOdd);
2019-10-28 20:38:29 +01:00
HTM_DIV_Begin ("id=\"ans_%u\"%s",
NumOpt,
DisplayRightColumn ? "" :
" style=\"display:none;\""); // Answer does not have content ==> Hide column
2016-04-07 10:23:28 +02:00
/* Answer text */
2019-10-31 17:42:05 +01:00
HTM_TEXTAREA_Begin ("name=\"AnsStr%u\" class=\"ANSWER_TEXTAREA\" rows=\"5\"%s",
NumOpt,OptionsDisabled ? " disabled=\"disabled\"" :
"");
2016-04-07 10:23:28 +02:00
if (AnswerHasContent)
2019-11-10 12:36:37 +01:00
HTM_Txt (Gbl.Test.Answer.Options[NumOpt].Text);
2019-10-31 17:42:05 +01:00
HTM_TEXTAREA_End ();
2016-04-05 14:32:02 +02:00
2019-03-02 21:49:11 +01:00
/* Media */
Tst_PutFormToEditQstMedia (&Gbl.Test.Answer.Options[NumOpt].Media,
2016-04-14 21:33:24 +02:00
(int) NumOpt,
2016-04-05 21:44:06 +02:00
OptionsDisabled);
2014-12-01 23:55:08 +01:00
/* Feedback */
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s&nbsp;(%s):",Txt_Feedback,Txt_optional);
2019-11-09 21:08:20 +01:00
HTM_BR ();
2019-10-31 17:42:05 +01:00
HTM_TEXTAREA_Begin ("name=\"FbStr%u\" class=\"ANSWER_TEXTAREA\" rows=\"2\"%s",
NumOpt,OptionsDisabled ? " disabled=\"disabled\"" :
"");
2014-12-01 23:55:08 +01:00
if (Gbl.Test.Answer.Options[NumOpt].Feedback)
if (Gbl.Test.Answer.Options[NumOpt].Feedback[0])
2019-11-10 12:36:37 +01:00
HTM_Txt (Gbl.Test.Answer.Options[NumOpt].Feedback);
2019-10-31 17:42:05 +01:00
HTM_TEXTAREA_End ();
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2016-04-07 10:23:28 +02:00
/* End of right column */
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 21:15:14 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TABLE_End (); // Table with choice answers
HTM_TD_End ();
HTM_TR_End ();
2015-04-11 13:05:44 +02:00
2016-04-05 10:05:52 +02:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End (); // Table for this question
2016-04-05 10:05:52 +02:00
/***** Send button *****/
2015-04-11 20:18:30 +02:00
if (Gbl.Test.QstCod > 0) // The question already has assigned a code
2019-02-18 18:27:45 +01:00
Btn_PutConfirmButton (Txt_Save_changes);
2015-04-11 20:18:30 +02:00
else
2017-06-11 19:02:40 +02:00
Btn_PutCreateButton (Txt_Create_question);
2015-04-11 13:05:44 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-12-26 15:17:30 +01:00
}
/*****************************************************************************/
/********************* Put input field for floating answer *******************/
/*****************************************************************************/
static void Tst_PutFloatInputField (const char *Label,const char *Field,
double Value)
{
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2019-11-11 10:59:24 +01:00
char StrDouble[32];
2016-12-26 15:17:30 +01:00
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s&nbsp;",Label);
snprintf (StrDouble,sizeof (StrDouble),
2020-01-11 15:22:02 +01:00
"%.15lg",
2019-11-04 01:29:46 +01:00
Value);
2019-11-11 10:59:24 +01:00
HTM_INPUT_TEXT (Field,Tst_MAX_BYTES_FLOAT_ANSWER,StrDouble,false,
2019-11-04 01:29:46 +01:00
"size=\"11\" required=\"required\"%s",
Gbl.Test.AnswerType == Tst_ANS_FLOAT ? "" :
" disabled=\"disabled\"");
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2016-12-26 16:30:46 +01:00
}
/*****************************************************************************/
/*********************** Put input field for T/F answer **********************/
/*****************************************************************************/
static void Tst_PutTFInputField (const char *Label,char Value)
{
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2016-12-26 16:30:46 +01:00
2019-11-02 23:40:52 +01:00
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-04 18:17:39 +01:00
HTM_INPUT_RADIO ("AnsTF",false,
"value=\"%c\"%s%s required=\"required\"",
Value,
Gbl.Test.Answer.TF == Value ? " checked=\"checked\"" : "",
Gbl.Test.AnswerType == Tst_ANS_TRUE_FALSE ? "" : " disabled=\"disabled\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Label);
2019-11-02 12:59:31 +01:00
HTM_LABEL_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Initialize a new question to zero *********************/
/*****************************************************************************/
2016-04-06 19:26:09 +02:00
void Tst_QstConstructor (void)
2014-12-01 23:55:08 +01:00
{
unsigned NumOpt;
2016-04-06 19:26:09 +02:00
Gbl.Test.QstCod = -1L;
2014-12-01 23:55:08 +01:00
Gbl.Test.Stem.Text = NULL;
Gbl.Test.Stem.Length = 0;
Gbl.Test.Feedback.Text = NULL;
Gbl.Test.Feedback.Length = 0;
2016-04-03 01:24:20 +02:00
Gbl.Test.Shuffle = false;
2014-12-01 23:55:08 +01:00
Gbl.Test.AnswerType = Tst_ANS_UNIQUE_CHOICE;
Gbl.Test.Answer.NumOptions = 0;
Gbl.Test.Answer.TF = ' ';
2016-04-08 23:30:43 +02:00
/***** Initialize image attached to stem *****/
2019-03-02 21:49:11 +01:00
Med_MediaConstructor (&Gbl.Test.Media);
2016-04-08 23:30:43 +02:00
2014-12-01 23:55:08 +01:00
for (NumOpt = 0;
NumOpt < Tst_MAX_OPTIONS_PER_QUESTION;
NumOpt++)
{
2016-04-04 10:11:05 +02:00
Gbl.Test.Answer.Options[NumOpt].Correct = false;
Gbl.Test.Answer.Options[NumOpt].Text = NULL;
Gbl.Test.Answer.Options[NumOpt].Feedback = NULL;
2016-04-08 23:30:43 +02:00
/***** Initialize image attached to option *****/
2019-03-02 21:49:11 +01:00
Med_MediaConstructor (&Gbl.Test.Answer.Options[NumOpt].Media);
2014-12-01 23:55:08 +01:00
}
Gbl.Test.Answer.Integer = 0;
Gbl.Test.Answer.FloatingPoint[0] =
Gbl.Test.Answer.FloatingPoint[1] = 0.0;
2016-04-04 21:51:21 +02:00
}
2016-04-06 19:26:09 +02:00
/*****************************************************************************/
/***************** Free memory allocated for test question *******************/
/*****************************************************************************/
void Tst_QstDestructor (void)
{
Tst_FreeTextChoiceAnswers ();
2019-03-02 21:49:11 +01:00
Tst_FreeMediaOfQuestion ();
2016-04-06 19:26:09 +02:00
}
/*****************************************************************************/
/******************* Allocate memory for a choice answer *********************/
/*****************************************************************************/
int Tst_AllocateTextChoiceAnswer (unsigned NumOpt)
{
Tst_FreeTextChoiceAnswer (NumOpt);
if ((Gbl.Test.Answer.Options[NumOpt].Text =
2018-10-08 12:37:29 +02:00
(char *) malloc (Tst_MAX_BYTES_ANSWER_OR_FEEDBACK + 1)) == NULL)
2016-04-06 19:26:09 +02:00
{
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_ERROR,NULL,
"Not enough memory to store answer.");
2016-04-06 19:26:09 +02:00
return 0;
}
if ((Gbl.Test.Answer.Options[NumOpt].Feedback =
2018-10-08 12:37:29 +02:00
(char *) malloc (Tst_MAX_BYTES_ANSWER_OR_FEEDBACK + 1)) == NULL)
2016-04-06 19:26:09 +02:00
{
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_ERROR,NULL,
"Not enough memory to store feedback.");
2016-04-06 19:26:09 +02:00
return 0;
}
Gbl.Test.Answer.Options[NumOpt].Text[0] =
Gbl.Test.Answer.Options[NumOpt].Feedback[0] = '\0';
return 1;
}
/*****************************************************************************/
/******************** Free memory of all choice answers **********************/
/*****************************************************************************/
static void Tst_FreeTextChoiceAnswers (void)
{
unsigned NumOpt;
for (NumOpt = 0;
NumOpt < Tst_MAX_OPTIONS_PER_QUESTION;
NumOpt++)
Tst_FreeTextChoiceAnswer (NumOpt);
}
/*****************************************************************************/
/********************** Free memory of a choice answer ***********************/
/*****************************************************************************/
static void Tst_FreeTextChoiceAnswer (unsigned NumOpt)
{
if (Gbl.Test.Answer.Options[NumOpt].Text)
{
2019-11-06 19:45:20 +01:00
free (Gbl.Test.Answer.Options[NumOpt].Text);
2016-04-06 19:26:09 +02:00
Gbl.Test.Answer.Options[NumOpt].Text = NULL;
}
if (Gbl.Test.Answer.Options[NumOpt].Feedback)
{
2019-11-06 19:45:20 +01:00
free (Gbl.Test.Answer.Options[NumOpt].Feedback);
2016-04-06 19:26:09 +02:00
Gbl.Test.Answer.Options[NumOpt].Feedback = NULL;
}
}
2016-04-04 21:51:21 +02:00
/*****************************************************************************/
/***************** Initialize images of a question to zero *******************/
/*****************************************************************************/
2016-04-09 02:04:45 +02:00
2019-03-17 14:47:58 +01:00
static void Tst_ResetMediaOfQuestion (void)
2016-04-04 21:51:21 +02:00
{
unsigned NumOpt;
2019-03-17 14:47:58 +01:00
/***** Reset media for stem *****/
Med_ResetMedia (&Gbl.Test.Media);
2016-04-08 23:30:43 +02:00
2019-03-17 14:47:58 +01:00
/***** Reset media for every answer option *****/
2016-04-04 21:51:21 +02:00
for (NumOpt = 0;
NumOpt < Tst_MAX_OPTIONS_PER_QUESTION;
NumOpt++)
2019-03-17 14:47:58 +01:00
Med_ResetMedia (&Gbl.Test.Answer.Options[NumOpt].Media);
2014-12-01 23:55:08 +01:00
}
2016-04-09 02:04:45 +02:00
2016-04-06 01:10:04 +02:00
/*****************************************************************************/
/*********************** Free images of a question ***************************/
/*****************************************************************************/
2019-03-02 21:49:11 +01:00
static void Tst_FreeMediaOfQuestion (void)
2016-04-06 01:10:04 +02:00
{
unsigned NumOpt;
2019-03-02 21:49:11 +01:00
Med_MediaDestructor (&Gbl.Test.Media);
2016-04-06 01:10:04 +02:00
for (NumOpt = 0;
NumOpt < Tst_MAX_OPTIONS_PER_QUESTION;
NumOpt++)
2019-03-02 21:49:11 +01:00
Med_MediaDestructor (&Gbl.Test.Answer.Options[NumOpt].Media);
2016-04-06 01:10:04 +02:00
}
2016-04-03 01:24:20 +02:00
/*****************************************************************************/
/****************** Get data of a question from database *********************/
/*****************************************************************************/
2017-01-17 03:10:43 +01:00
static void Tst_GetQstDataFromDB (char Stem[Cns_MAX_BYTES_TEXT + 1],
char Feedback[Cns_MAX_BYTES_TEXT + 1])
2016-04-03 01:24:20 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned long NumRow;
unsigned NumOpt;
/***** Get the type of answer and the stem from the database *****/
/* Get the question from database */
2018-11-02 01:38:44 +01:00
DB_QuerySELECT (&mysql_res,"can not get a question",
2019-03-02 21:49:11 +01:00
"SELECT AnsType," // row[0]
"Shuffle," // row[1]
"Stem," // row[2]
"Feedback," // row[3]
2019-03-18 15:42:22 +01:00
"MedCod" // row[4]
2018-11-02 01:38:44 +01:00
" FROM tst_questions"
" WHERE QstCod=%ld AND CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Gbl.Test.QstCod,Gbl.Hierarchy.Crs.CrsCod);
2016-04-03 01:24:20 +02:00
row = mysql_fetch_row (mysql_res);
2019-03-02 21:49:11 +01:00
2016-04-03 01:24:20 +02:00
/* Get the type of answer */
Gbl.Test.AnswerType = Tst_ConvertFromStrAnsTypDBToAnsTyp (row[0]);
/* Get shuffle (row[1]) */
2016-09-07 18:48:10 +02:00
Gbl.Test.Shuffle = (row[1][0] == 'Y');
2016-04-03 01:24:20 +02:00
/* Get the stem of the question from the database (row[2]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Stem,row[2],
Cns_MAX_BYTES_TEXT);
2016-04-03 01:24:20 +02:00
2016-04-06 01:10:04 +02:00
/* Get the feedback of the question from the database (row[3]) */
2016-04-03 01:24:20 +02:00
Feedback[0] = '\0';
2016-04-06 01:10:04 +02:00
if (row[3])
if (row[3][0])
2017-01-17 03:10:43 +01:00
Str_Copy (Feedback,row[3],
Cns_MAX_BYTES_TEXT);
2016-04-03 01:24:20 +02:00
2019-03-18 15:42:22 +01:00
/* Get media (row[4]) */
Gbl.Test.Media.MedCod = Str_ConvertStrCodToLongCod (row[4]);
Med_GetMediaDataByCod (&Gbl.Test.Media);
2016-04-06 01:10:04 +02:00
2016-04-03 01:24:20 +02:00
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
/***** Get the tags from the database *****/
NumRows = Tst_GetTagsQst (Gbl.Test.QstCod,&mysql_res);
for (NumRow = 0;
NumRow < NumRows;
NumRow++)
{
row = mysql_fetch_row (mysql_res);
2017-01-17 03:10:43 +01:00
Str_Copy (Gbl.Test.Tags.Txt[NumRow],row[0],
Tst_MAX_BYTES_TAG);
2016-04-03 01:24:20 +02:00
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
/***** Get the answers from the database *****/
2017-09-04 17:03:49 +02:00
Gbl.Test.Answer.NumOptions = Tst_GetAnswersQst (Gbl.Test.QstCod,&mysql_res,false);
2016-04-06 14:41:47 +02:00
/*
2019-03-02 21:49:11 +01:00
row[0] AnsInd
row[1] Answer
row[2] Feedback
2019-03-18 15:42:22 +01:00
row[3] MedCod
row[4] Correct
2016-04-06 14:41:47 +02:00
*/
2016-04-03 01:24:20 +02:00
for (NumOpt = 0;
NumOpt < Gbl.Test.Answer.NumOptions;
NumOpt++)
{
row = mysql_fetch_row (mysql_res);
switch (Gbl.Test.AnswerType)
{
case Tst_ANS_INT:
if (Gbl.Test.Answer.NumOptions != 1)
Lay_ShowErrorAndExit ("Wrong answer.");
Gbl.Test.Answer.Integer = Tst_GetIntAnsFromStr (row[1]);
break;
case Tst_ANS_FLOAT:
if (Gbl.Test.Answer.NumOptions != 2)
Lay_ShowErrorAndExit ("Wrong answer.");
2019-11-27 09:01:45 +01:00
Gbl.Test.Answer.FloatingPoint[NumOpt] = Str_GetDoubleFromStr (row[1]);
2016-04-03 01:24:20 +02:00
break;
case Tst_ANS_TRUE_FALSE:
if (Gbl.Test.Answer.NumOptions != 1)
Lay_ShowErrorAndExit ("Wrong answer.");
Gbl.Test.Answer.TF = row[1][0];
break;
case Tst_ANS_UNIQUE_CHOICE:
case Tst_ANS_MULTIPLE_CHOICE:
case Tst_ANS_TEXT:
if (Gbl.Test.Answer.NumOptions > Tst_MAX_OPTIONS_PER_QUESTION)
Lay_ShowErrorAndExit ("Wrong answer.");
if (!Tst_AllocateTextChoiceAnswer (NumOpt))
2019-03-09 20:12:44 +01:00
/* Abort on error */
Ale_ShowAlertsAndExit ();
2016-04-03 01:24:20 +02:00
2017-01-15 18:02:52 +01:00
Str_Copy (Gbl.Test.Answer.Options[NumOpt].Text,row[1],
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK);
2016-04-03 01:24:20 +02:00
2016-04-06 14:41:47 +02:00
// Feedback (row[2]) is initialized to empty string
if (row[2])
if (row[2][0])
2017-01-15 18:02:52 +01:00
Str_Copy (Gbl.Test.Answer.Options[NumOpt].Feedback,row[2],
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK);
2016-04-03 01:24:20 +02:00
2019-03-18 15:42:22 +01:00
/* Get media (row[3]) */
Gbl.Test.Answer.Options[NumOpt].Media.MedCod = Str_ConvertStrCodToLongCod (row[3]);
Med_GetMediaDataByCod (&Gbl.Test.Answer.Options[NumOpt].Media);
2016-04-04 21:51:21 +02:00
2019-03-18 15:42:22 +01:00
/* Get if this option is correct (row[4]) */
Gbl.Test.Answer.Options[NumOpt].Correct = (row[4][0] == 'Y');
2016-04-03 01:24:20 +02:00
break;
default:
break;
}
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
2019-03-19 11:20:29 +01:00
/******* Get media code associated with a test question from database ********/
2016-04-03 01:24:20 +02:00
/*****************************************************************************/
2019-03-19 01:41:27 +01:00
// NumOpt < 0 ==> media associated to stem
// NumOpt >= 0 ==> media associated to answer
2016-04-03 01:24:20 +02:00
2019-03-19 11:20:29 +01:00
static long Tst_GetMedCodFromDB (int NumOpt)
2016-04-03 01:24:20 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2019-03-21 20:04:01 +01:00
unsigned long NumRows;
long MedCod = -1L;
2016-04-03 01:24:20 +02:00
2019-04-01 00:45:50 +02:00
if (Gbl.Test.QstCod > 0) // Existing question
2019-03-21 20:04:01 +01:00
{
2019-04-01 00:45:50 +02:00
/***** Query depending on NumOpt *****/
if (NumOpt < 0)
// Get media associated to stem
NumRows = DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT MedCod" // row[0]
" FROM tst_questions"
" WHERE QstCod=%ld AND CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Gbl.Test.QstCod,Gbl.Hierarchy.Crs.CrsCod);
2019-04-01 00:45:50 +02:00
else
// Get media associated to answer
NumRows = DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT MedCod" // row[0]
" FROM tst_answers"
" WHERE QstCod=%ld AND AnsInd=%u",
Gbl.Test.QstCod,(unsigned) NumOpt);
if (NumRows)
2019-03-21 20:04:01 +01:00
{
2019-04-01 00:45:50 +02:00
if (NumRows == 1)
{
/***** Get media code (row[0]) *****/
row = mysql_fetch_row (mysql_res);
MedCod = Str_ConvertStrCodToLongCod (row[0]);
}
else // NumRows > 1
Lay_ShowErrorAndExit ("Duplicated media in database.");
2019-03-21 20:04:01 +01:00
}
2016-04-03 01:24:20 +02:00
2019-04-01 00:45:50 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2019-03-19 11:20:29 +01:00
return MedCod;
}
/*****************************************************************************/
/***** Get possible media associated with a test question from database ******/
/*****************************************************************************/
// NumOpt < 0 ==> media associated to stem
// NumOpt >= 0 ==> media associated to an answer option
static void Tst_GetMediaFromDB (int NumOpt,struct Media *Media)
{
/***** Get media *****/
Media->MedCod = Tst_GetMedCodFromDB (NumOpt);
Med_GetMediaDataByCod (Media);
2016-04-03 01:24:20 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/** Convert a string with the type of answer in database to type of answer ***/
/*****************************************************************************/
Tst_AnswerType_t Tst_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeBD)
{
Tst_AnswerType_t AnsType;
if (StrAnsTypeBD != NULL)
2019-12-15 20:02:34 +01:00
for (AnsType = (Tst_AnswerType_t) 0;
AnsType <= (Tst_AnswerType_t) (Tst_NUM_ANS_TYPES - 1);
2014-12-01 23:55:08 +01:00
AnsType++)
if (!strcmp (StrAnsTypeBD,Tst_StrAnswerTypesDB[AnsType]))
return AnsType;
Lay_ShowErrorAndExit ("Wrong type of answer.");
return (Tst_AnswerType_t) 0; // Not reached
}
/*****************************************************************************/
/************ Convert a string with an unsigned to answer type ***************/
/*****************************************************************************/
static Tst_AnswerType_t Tst_ConvertFromUnsignedStrToAnsTyp (const char *UnsignedStr)
{
unsigned AnsType;
if (sscanf (UnsignedStr,"%u",&AnsType) != 1)
Lay_ShowErrorAndExit ("Wrong type of answer.");
if (AnsType >= Tst_NUM_ANS_TYPES)
Lay_ShowErrorAndExit ("Wrong type of answer.");
return (Tst_AnswerType_t) AnsType;
}
/*****************************************************************************/
/*************** Receive a question of the self-assessment test **************/
/*****************************************************************************/
void Tst_ReceiveQst (void)
{
2017-01-28 15:58:46 +01:00
char Stem[Cns_MAX_BYTES_TEXT + 1];
char Feedback[Cns_MAX_BYTES_TEXT + 1];
2014-12-01 23:55:08 +01:00
2016-04-06 19:26:09 +02:00
/***** Create test question *****/
Tst_QstConstructor ();
2014-12-01 23:55:08 +01:00
/***** Get parameters of the question from form *****/
2016-04-06 19:26:09 +02:00
Stem[0] = Feedback[0] = '\0';
2014-12-01 23:55:08 +01:00
Tst_GetQstFromForm (Stem,Feedback);
/***** Make sure that tags, text and answer are not empty *****/
if (Tst_CheckIfQstFormatIsCorrectAndCountNumOptions ())
{
2016-04-04 21:51:21 +02:00
/***** Move images to definitive directories *****/
2019-03-02 21:49:11 +01:00
Tst_MoveMediaToDefinitiveDirectories ();
2016-04-04 01:02:41 +02:00
/***** Insert or update question, tags and answer in the database *****/
2014-12-01 23:55:08 +01:00
Tst_InsertOrUpdateQstTagsAnsIntoDB ();
/***** Show the question just inserted in the database *****/
Tst_ListOneQstToEdit ();
}
else // Question is wrong
2016-04-04 03:00:12 +02:00
{
2016-04-04 21:51:21 +02:00
/***** Whether images has been received or not, reset images *****/
2019-03-17 14:47:58 +01:00
Tst_ResetMediaOfQuestion ();
2016-04-04 03:00:12 +02:00
2016-04-03 01:24:20 +02:00
/***** Put form to edit question again *****/
2014-12-01 23:55:08 +01:00
Tst_PutFormEditOneQst (Stem,Feedback);
2016-04-04 03:00:12 +02:00
}
2014-12-01 23:55:08 +01:00
2016-04-06 19:26:09 +02:00
/***** Destroy test question *****/
Tst_QstDestructor ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************** Get parameters of a test question from form ****************/
/*****************************************************************************/
static void Tst_GetQstFromForm (char *Stem,char *Feedback)
{
unsigned NumTag;
unsigned NumTagRead;
unsigned NumOpt;
2019-11-08 01:10:32 +01:00
char UnsignedStr[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
char TagStr[6 + Cns_MAX_DECIMAL_DIGITS_UINT + 1];
char AnsStr[6 + Cns_MAX_DECIMAL_DIGITS_UINT + 1];
char FbStr[5 + Cns_MAX_DECIMAL_DIGITS_UINT + 1];
2017-03-13 19:02:15 +01:00
char StrMultiAns[Tst_MAX_BYTES_ANSWERS_ONE_QST + 1];
2017-02-24 19:04:52 +01:00
char TF[1 + 1]; // (T)rue or (F)alse
2014-12-01 23:55:08 +01:00
const char *Ptr;
unsigned NumCorrectAns;
/***** Get question code *****/
2016-04-06 19:26:09 +02:00
Gbl.Test.QstCod = Tst_GetQstCod ();
2014-12-01 23:55:08 +01:00
/***** Get answer type *****/
2017-01-29 21:41:08 +01:00
Gbl.Test.AnswerType = (Tst_AnswerType_t)
Par_GetParToUnsignedLong ("AnswerType",
0,
Tst_NUM_ANS_TYPES - 1,
(unsigned long) Tst_ANS_ALL);
if (Gbl.Test.AnswerType == Tst_ANS_ALL)
Lay_ShowErrorAndExit ("Wrong type of answer.");
2014-12-01 23:55:08 +01:00
/***** Get question tags *****/
for (NumTag = 0;
NumTag < Tst_MAX_TAGS_PER_QUESTION;
NumTag++)
{
2018-10-18 02:02:32 +02:00
snprintf (TagStr,sizeof (TagStr),
"TagTxt%u",
NumTag);
2016-04-06 22:27:33 +02:00
Par_GetParToText (TagStr,Gbl.Test.Tags.Txt[NumTag],Tst_MAX_BYTES_TAG);
2016-03-30 01:28:58 +02:00
2016-04-06 22:27:33 +02:00
if (Gbl.Test.Tags.Txt[NumTag][0])
2014-12-01 23:55:08 +01:00
{
Str_ChangeFormat (Str_FROM_FORM,Str_TO_TEXT,
2016-04-06 22:27:33 +02:00
Gbl.Test.Tags.Txt[NumTag],Tst_MAX_BYTES_TAG,true);
2014-12-01 23:55:08 +01:00
/* Check if not repeated */
for (NumTagRead = 0;
NumTagRead < NumTag;
NumTagRead++)
2016-04-06 22:27:33 +02:00
if (!strcmp (Gbl.Test.Tags.Txt[NumTagRead],Gbl.Test.Tags.Txt[NumTag]))
2014-12-01 23:55:08 +01:00
{
2016-04-06 22:27:33 +02:00
Gbl.Test.Tags.Txt[NumTag][0] = '\0';
2014-12-01 23:55:08 +01:00
break;
}
}
}
/***** Get question stem *****/
Par_GetParToHTML ("Stem",Stem,Cns_MAX_BYTES_TEXT);
2016-04-06 01:10:04 +02:00
/***** Get question feedback *****/
Par_GetParToHTML ("Feedback",Feedback,Cns_MAX_BYTES_TEXT);
2019-03-19 01:41:27 +01:00
/***** Get media associated to the stem (action, file and title) *****/
2019-03-02 21:49:11 +01:00
Gbl.Test.Media.Width = Tst_IMAGE_SAVED_MAX_WIDTH;
Gbl.Test.Media.Height = Tst_IMAGE_SAVED_MAX_HEIGHT;
Gbl.Test.Media.Quality = Tst_IMAGE_SAVED_QUALITY;
Med_GetMediaFromForm (-1, // < 0 ==> the image associated to the stem
2019-03-17 14:47:58 +01:00
&Gbl.Test.Media,Tst_GetMediaFromDB,
NULL);
Ale_ShowAlerts (NULL);
2016-04-04 12:13:37 +02:00
2014-12-01 23:55:08 +01:00
/***** Get answers *****/
Gbl.Test.Shuffle = false;
switch (Gbl.Test.AnswerType)
{
case Tst_ANS_INT:
if (!Tst_AllocateTextChoiceAnswer (0))
2019-03-09 20:12:44 +01:00
/* Abort on error */
Ale_ShowAlertsAndExit ();
2014-12-01 23:55:08 +01:00
2019-11-08 01:10:32 +01:00
Par_GetParToText ("AnsInt",Gbl.Test.Answer.Options[0].Text,
Cns_MAX_DECIMAL_DIGITS_LONG);
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_FLOAT:
if (!Tst_AllocateTextChoiceAnswer (0))
2019-03-09 20:12:44 +01:00
/* Abort on error */
Ale_ShowAlertsAndExit ();
2017-01-29 21:41:08 +01:00
Par_GetParToText ("AnsFloatMin",Gbl.Test.Answer.Options[0].Text,
Tst_MAX_BYTES_FLOAT_ANSWER);
2014-12-01 23:55:08 +01:00
if (!Tst_AllocateTextChoiceAnswer (1))
2019-03-09 20:12:44 +01:00
/* Abort on error */
Ale_ShowAlertsAndExit ();
2017-01-29 21:41:08 +01:00
Par_GetParToText ("AnsFloatMax",Gbl.Test.Answer.Options[1].Text,
Tst_MAX_BYTES_FLOAT_ANSWER);
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_TRUE_FALSE:
2017-02-24 19:04:52 +01:00
Par_GetParToText ("AnsTF",TF,1);
Gbl.Test.Answer.TF = TF[0];
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_UNIQUE_CHOICE:
case Tst_ANS_MULTIPLE_CHOICE:
/* Get shuffle */
2017-01-28 20:32:50 +01:00
Gbl.Test.Shuffle = Par_GetParToBool ("Shuffle");
2018-10-04 21:57:25 +02:00
/* falls through */
/* no break */
2014-12-01 23:55:08 +01:00
case Tst_ANS_TEXT:
/* Get the texts of the answers */
for (NumOpt = 0;
NumOpt < Tst_MAX_OPTIONS_PER_QUESTION;
NumOpt++)
{
if (!Tst_AllocateTextChoiceAnswer (NumOpt))
2019-03-09 20:12:44 +01:00
/* Abort on error */
Ale_ShowAlertsAndExit ();
2014-12-01 23:55:08 +01:00
/* Get answer */
2018-10-18 02:02:32 +02:00
snprintf (AnsStr,sizeof (AnsStr),
"AnsStr%u",
NumOpt);
2017-03-08 03:48:23 +01:00
Par_GetParToHTML (AnsStr,Gbl.Test.Answer.Options[NumOpt].Text,
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK);
2016-11-27 14:34:36 +01:00
if (Gbl.Test.AnswerType == Tst_ANS_TEXT)
/* In order to compare student answer to stored answer,
the text answers are stored avoiding two or more consecurive spaces */
Str_ReplaceSeveralSpacesForOne (Gbl.Test.Answer.Options[NumOpt].Text);
2014-12-01 23:55:08 +01:00
/* Get feedback */
2018-10-18 02:02:32 +02:00
snprintf (FbStr,sizeof (FbStr),
"FbStr%u",
NumOpt);
2017-03-08 03:48:23 +01:00
Par_GetParToHTML (FbStr,Gbl.Test.Answer.Options[NumOpt].Feedback,
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK);
2016-04-04 14:48:12 +02:00
2019-03-19 01:41:27 +01:00
/* Get media associated to the answer (action, file and title) */
2016-04-04 14:48:12 +02:00
if (Gbl.Test.AnswerType == Tst_ANS_UNIQUE_CHOICE ||
Gbl.Test.AnswerType == Tst_ANS_MULTIPLE_CHOICE)
{
2019-03-02 21:49:11 +01:00
Gbl.Test.Answer.Options[NumOpt].Media.Width = Tst_IMAGE_SAVED_MAX_WIDTH;
Gbl.Test.Answer.Options[NumOpt].Media.Height = Tst_IMAGE_SAVED_MAX_HEIGHT;
Gbl.Test.Answer.Options[NumOpt].Media.Quality = Tst_IMAGE_SAVED_QUALITY;
Med_GetMediaFromForm ((int) NumOpt, // >= 0 ==> the image associated to an answer
&Gbl.Test.Answer.Options[NumOpt].Media,
2019-03-17 14:47:58 +01:00
Tst_GetMediaFromDB,
NULL);
Ale_ShowAlerts (NULL);
2016-04-04 14:48:12 +02:00
}
2014-12-01 23:55:08 +01:00
}
/* Get the numbers of correct answers */
if (Gbl.Test.AnswerType == Tst_ANS_UNIQUE_CHOICE)
{
2017-01-29 21:41:08 +01:00
NumCorrectAns = (unsigned) Par_GetParToUnsignedLong ("AnsUni",
0,
Tst_MAX_OPTIONS_PER_QUESTION - 1,
0);
Gbl.Test.Answer.Options[NumCorrectAns].Correct = true;
2014-12-01 23:55:08 +01:00
}
else if (Gbl.Test.AnswerType == Tst_ANS_MULTIPLE_CHOICE)
{
2017-03-13 19:02:15 +01:00
Par_GetParMultiToText ("AnsMulti",StrMultiAns,Tst_MAX_BYTES_ANSWERS_ONE_QST);
2014-12-01 23:55:08 +01:00
Ptr = StrMultiAns;
while (*Ptr)
{
2019-11-08 01:10:32 +01:00
Par_GetNextStrUntilSeparParamMult (&Ptr,UnsignedStr,Cns_MAX_DECIMAL_DIGITS_UINT);
2014-12-01 23:55:08 +01:00
if (sscanf (UnsignedStr,"%u",&NumCorrectAns) != 1)
Lay_ShowErrorAndExit ("Wrong selected answer.");
if (NumCorrectAns >= Tst_MAX_OPTIONS_PER_QUESTION)
Lay_ShowErrorAndExit ("Wrong selected answer.");
Gbl.Test.Answer.Options[NumCorrectAns].Correct = true;
}
}
else // Tst_ANS_TEXT
for (NumOpt = 0;
NumOpt < Tst_MAX_OPTIONS_PER_QUESTION;
NumOpt++)
if (Gbl.Test.Answer.Options[NumOpt].Text[0])
Gbl.Test.Answer.Options[NumOpt].Correct = true; // All the answers are correct
break;
default:
break;
}
/***** Adjust global variables related to this test question *****/
2016-04-06 22:27:33 +02:00
for (NumTag = 0, Gbl.Test.Tags.Num = 0;
2014-12-01 23:55:08 +01:00
NumTag < Tst_MAX_TAGS_PER_QUESTION;
NumTag++)
2016-04-06 22:27:33 +02:00
if (Gbl.Test.Tags.Txt[NumTag][0])
Gbl.Test.Tags.Num++;
2014-12-01 23:55:08 +01:00
Gbl.Test.Stem.Text = Stem;
Gbl.Test.Stem.Length = strlen (Gbl.Test.Stem.Text);
Gbl.Test.Feedback.Text = Feedback;
Gbl.Test.Feedback.Length = strlen (Gbl.Test.Feedback.Text);
}
/*****************************************************************************/
/*********************** Check if a question is correct **********************/
/*****************************************************************************/
// Returns false if question format is wrong
// Counts Gbl.Test.Answer.NumOptions
// Computes Gbl.Test.Answer.Integer and Gbl.Test.Answer.FloatingPoint[0..1]
bool Tst_CheckIfQstFormatIsCorrectAndCountNumOptions (void)
{
extern const char *Txt_You_must_type_at_least_one_tag_for_the_question;
extern const char *Txt_You_must_type_the_stem_of_the_question;
extern const char *Txt_You_must_select_a_T_F_answer;
extern const char *Txt_You_can_not_leave_empty_intermediate_answers;
extern const char *Txt_You_must_type_at_least_the_first_two_answers;
extern const char *Txt_You_must_mark_an_answer_as_correct;
extern const char *Txt_You_must_type_at_least_the_first_answer;
extern const char *Txt_You_must_enter_an_integer_value_as_the_correct_answer;
extern const char *Txt_You_must_enter_the_range_of_floating_point_values_allowed_as_answer;
extern const char *Txt_The_lower_limit_of_correct_answers_must_be_less_than_or_equal_to_the_upper_limit;
unsigned NumOpt;
unsigned NumLastOpt;
bool ThereIsEndOfAnswers;
unsigned i;
/***** This function also counts the number of options. Initialize this number to 0. *****/
Gbl.Test.Answer.NumOptions = 0;
/***** A question must have at least one tag *****/
2016-04-06 22:27:33 +02:00
if (!Gbl.Test.Tags.Num) // There are no tags with text
2014-12-01 23:55:08 +01:00
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_type_at_least_one_tag_for_the_question);
2014-12-01 23:55:08 +01:00
return false;
}
/***** A question must have a stem*****/
if (!Gbl.Test.Stem.Length)
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_type_the_stem_of_the_question);
2014-12-01 23:55:08 +01:00
return false;
}
/***** Check answer *****/
switch (Gbl.Test.AnswerType)
{
case Tst_ANS_INT:
2019-03-17 14:47:58 +01:00
/* First option should be filled */
2014-12-01 23:55:08 +01:00
if (!Gbl.Test.Answer.Options[0].Text)
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_enter_an_integer_value_as_the_correct_answer);
2014-12-01 23:55:08 +01:00
return false;
}
if (!Gbl.Test.Answer.Options[0].Text[0])
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_enter_an_integer_value_as_the_correct_answer);
2014-12-01 23:55:08 +01:00
return false;
}
2019-03-17 14:47:58 +01:00
2014-12-01 23:55:08 +01:00
Gbl.Test.Answer.Integer = Tst_GetIntAnsFromStr (Gbl.Test.Answer.Options[0].Text);
Gbl.Test.Answer.NumOptions = 1;
break;
case Tst_ANS_FLOAT:
2019-03-17 14:47:58 +01:00
/* First two options should be filled */
2014-12-01 23:55:08 +01:00
if (!Gbl.Test.Answer.Options[0].Text ||
!Gbl.Test.Answer.Options[1].Text)
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_enter_the_range_of_floating_point_values_allowed_as_answer);
2014-12-01 23:55:08 +01:00
return false;
}
if (!Gbl.Test.Answer.Options[0].Text[0] ||
!Gbl.Test.Answer.Options[1].Text[0])
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_enter_the_range_of_floating_point_values_allowed_as_answer);
2014-12-01 23:55:08 +01:00
return false;
}
2019-03-17 14:47:58 +01:00
/* Lower limit should be <= upper limit */
2014-12-01 23:55:08 +01:00
for (i = 0;
i < 2;
i++)
2019-11-27 09:01:45 +01:00
Gbl.Test.Answer.FloatingPoint[i] = Str_GetDoubleFromStr (Gbl.Test.Answer.Options[i].Text);
2014-12-01 23:55:08 +01:00
if (Gbl.Test.Answer.FloatingPoint[0] >
Gbl.Test.Answer.FloatingPoint[1])
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_The_lower_limit_of_correct_answers_must_be_less_than_or_equal_to_the_upper_limit);
2014-12-01 23:55:08 +01:00
return false;
}
2019-03-17 14:47:58 +01:00
2014-12-01 23:55:08 +01:00
Gbl.Test.Answer.NumOptions = 2;
break;
case Tst_ANS_TRUE_FALSE:
2019-03-17 14:47:58 +01:00
/* Answer should be 'T' or 'F' */
2014-12-01 23:55:08 +01:00
if (Gbl.Test.Answer.TF != 'T' &&
Gbl.Test.Answer.TF != 'F')
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_select_a_T_F_answer);
2014-12-01 23:55:08 +01:00
return false;
}
2019-03-17 14:47:58 +01:00
2014-12-01 23:55:08 +01:00
Gbl.Test.Answer.NumOptions = 1;
break;
case Tst_ANS_UNIQUE_CHOICE:
case Tst_ANS_MULTIPLE_CHOICE:
2019-03-17 14:47:58 +01:00
/* No option should be empty before a non-empty option */
2014-12-01 23:55:08 +01:00
for (NumOpt = 0, NumLastOpt = 0, ThereIsEndOfAnswers = false;
NumOpt < Tst_MAX_OPTIONS_PER_QUESTION;
NumOpt++)
if (Gbl.Test.Answer.Options[NumOpt].Text)
{
2019-03-19 01:41:27 +01:00
if (Gbl.Test.Answer.Options[NumOpt].Text[0] || // Text
Gbl.Test.Answer.Options[NumOpt].Media.Type != Med_TYPE_NONE) // or media
2014-12-01 23:55:08 +01:00
{
if (ThereIsEndOfAnswers)
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_empty_intermediate_answers);
2014-12-01 23:55:08 +01:00
return false;
}
NumLastOpt = NumOpt;
Gbl.Test.Answer.NumOptions++;
}
else
ThereIsEndOfAnswers = true;
}
else
ThereIsEndOfAnswers = true;
2019-03-17 14:47:58 +01:00
/* The two first options must be filled */
2014-12-01 23:55:08 +01:00
if (NumLastOpt < 1)
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_type_at_least_the_first_two_answers);
2014-12-01 23:55:08 +01:00
return false;
}
2019-03-17 14:47:58 +01:00
/* Its mandatory to mark at least one option as correct */
2014-12-01 23:55:08 +01:00
for (NumOpt = 0;
NumOpt <= NumLastOpt;
NumOpt++)
if (Gbl.Test.Answer.Options[NumOpt].Correct)
break;
if (NumOpt > NumLastOpt)
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_mark_an_answer_as_correct);
2014-12-01 23:55:08 +01:00
return false;
}
break;
case Tst_ANS_TEXT:
2019-03-17 14:47:58 +01:00
/* First option should be filled */
2014-12-01 23:55:08 +01:00
if (!Gbl.Test.Answer.Options[0].Text) // If the first answer is empty
{
2019-03-17 14:47:58 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_type_at_least_the_first_answer);
2014-12-01 23:55:08 +01:00
return false;
}
2019-03-17 14:47:58 +01:00
if (!Gbl.Test.Answer.Options[0].Text[0]) // If the first answer is empty
2014-12-01 23:55:08 +01:00
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_type_at_least_the_first_answer);
2014-12-01 23:55:08 +01:00
return false;
}
2019-03-17 14:47:58 +01:00
/* No option should be empty before a non-empty option */
2014-12-01 23:55:08 +01:00
for (NumOpt=0, ThereIsEndOfAnswers=false;
NumOpt<Tst_MAX_OPTIONS_PER_QUESTION;
NumOpt++)
if (Gbl.Test.Answer.Options[NumOpt].Text)
{
if (Gbl.Test.Answer.Options[NumOpt].Text[0])
{
if (ThereIsEndOfAnswers)
{
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_empty_intermediate_answers);
2014-12-01 23:55:08 +01:00
return false;
}
Gbl.Test.Answer.NumOptions++;
}
else
ThereIsEndOfAnswers = true;
}
else
ThereIsEndOfAnswers = true;
break;
default:
break;
}
return true; // Question format without errors
}
2019-12-15 20:02:34 +01:00
/*****************************************************************************/
/*********** Check if a test question already exists in database *************/
/*****************************************************************************/
bool Tst_CheckIfQuestionExistsInDB (void)
{
extern const char *Tst_StrAnswerTypesDB[Tst_NUM_ANS_TYPES];
MYSQL_RES *mysql_res_qst;
MYSQL_RES *mysql_res_ans;
MYSQL_ROW row;
bool IdenticalQuestionFound = false;
bool IdenticalAnswers;
unsigned NumQst;
unsigned NumQstsWithThisStem;
unsigned NumOpt;
unsigned NumOptsExistingQstInDB;
long QstCod;
unsigned i;
/***** Check if stem exists *****/
NumQstsWithThisStem =
(unsigned) DB_QuerySELECT (&mysql_res_qst,"can not check"
" if a question exists",
"SELECT QstCod FROM tst_questions"
" WHERE CrsCod=%ld AND AnsType='%s' AND Stem='%s'",
Gbl.Hierarchy.Crs.CrsCod,
Tst_StrAnswerTypesDB[Gbl.Test.AnswerType],
Gbl.Test.Stem.Text);
if (NumQstsWithThisStem) // There are questions in database with the same stem that the one of this question
{
/***** Check if the answer exists in any of the questions with the same stem *****/
/* For each question with the same stem */
for (NumQst = 0;
!IdenticalQuestionFound && NumQst < NumQstsWithThisStem;
NumQst++)
{
row = mysql_fetch_row (mysql_res_qst);
if ((QstCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of question.");
/* Get answers from this question */
NumOptsExistingQstInDB =
(unsigned) DB_QuerySELECT (&mysql_res_ans,"can not get the answer"
" of a question",
"SELECT Answer FROM tst_answers"
" WHERE QstCod=%ld ORDER BY AnsInd",
QstCod);
switch (Gbl.Test.AnswerType)
{
case Tst_ANS_INT:
row = mysql_fetch_row (mysql_res_ans);
IdenticalQuestionFound = (Tst_GetIntAnsFromStr (row[0]) == Gbl.Test.Answer.Integer);
break;
case Tst_ANS_FLOAT:
for (IdenticalAnswers = true, i = 0;
IdenticalAnswers && i < 2;
i++)
{
row = mysql_fetch_row (mysql_res_ans);
IdenticalAnswers = (Str_GetDoubleFromStr (row[0]) == Gbl.Test.Answer.FloatingPoint[i]);
}
IdenticalQuestionFound = IdenticalAnswers;
break;
case Tst_ANS_TRUE_FALSE:
row = mysql_fetch_row (mysql_res_ans);
IdenticalQuestionFound = (Str_ConvertToUpperLetter (row[0][0]) == Gbl.Test.Answer.TF);
break;
case Tst_ANS_UNIQUE_CHOICE:
case Tst_ANS_MULTIPLE_CHOICE:
case Tst_ANS_TEXT:
if (NumOptsExistingQstInDB == Gbl.Test.Answer.NumOptions)
{
for (IdenticalAnswers = true, NumOpt = 0;
IdenticalAnswers && NumOpt < NumOptsExistingQstInDB;
NumOpt++)
{
row = mysql_fetch_row (mysql_res_ans);
if (strcasecmp (row[0],Gbl.Test.Answer.Options[NumOpt].Text))
IdenticalAnswers = false;
}
}
else // Different number of answers (options)
IdenticalAnswers = false;
IdenticalQuestionFound = IdenticalAnswers;
break;
default:
break;
}
/* Free structure that stores the query result for answers */
DB_FreeMySQLResult (&mysql_res_ans);
}
}
else // Stem does not exist
IdenticalQuestionFound = false;
/* Free structure that stores the query result for questions */
DB_FreeMySQLResult (&mysql_res_qst);
return IdenticalQuestionFound;
}
2016-04-04 21:51:21 +02:00
/*****************************************************************************/
/* Move images associates to a test question to their definitive directories */
/*****************************************************************************/
2019-03-02 21:49:11 +01:00
static void Tst_MoveMediaToDefinitiveDirectories (void)
2016-04-04 21:51:21 +02:00
{
unsigned NumOpt;
2019-03-19 11:20:29 +01:00
long CurrentMedCodInDB;
2016-04-04 21:51:21 +02:00
2019-03-19 01:41:27 +01:00
/***** Media associated to question stem *****/
2019-03-19 11:20:29 +01:00
CurrentMedCodInDB = Tst_GetMedCodFromDB (-1L); // Get current media code associated to stem
Med_RemoveKeepOrStoreMedia (CurrentMedCodInDB,&Gbl.Test.Media);
2019-03-18 15:42:22 +01:00
2019-03-19 01:41:27 +01:00
/****** Move media associated to answers *****/
2016-04-04 21:51:21 +02:00
if (Gbl.Test.AnswerType == Tst_ANS_UNIQUE_CHOICE ||
Gbl.Test.AnswerType == Tst_ANS_MULTIPLE_CHOICE)
for (NumOpt = 0;
NumOpt < Gbl.Test.Answer.NumOptions;
NumOpt++)
{
2019-03-19 11:20:29 +01:00
CurrentMedCodInDB = Tst_GetMedCodFromDB (NumOpt); // Get current media code associated to this option
Med_RemoveKeepOrStoreMedia (CurrentMedCodInDB,&Gbl.Test.Answer.Options[NumOpt].Media);
2016-04-04 21:51:21 +02:00
}
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******************** Get a integer number from a string *********************/
/*****************************************************************************/
long Tst_GetIntAnsFromStr (char *Str)
{
long LongNum;
if (Str == NULL)
return 0.0;
/***** The string is "scanned" as long *****/
if (sscanf (Str,"%ld",&LongNum) != 1) // If the string does not hold a valid integer number...
{
LongNum = 0L; // ...the number is reset to 0
Str[0] = '\0'; // ...and the string is reset to ""
}
return LongNum;
}
/*****************************************************************************/
/***************** Check if this tag exists for current course ***************/
/*****************************************************************************/
static long Tst_GetTagCodFromTagTxt (const char *TagTxt)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
long TagCod = -1L; // -1 means that the tag does not exist in database
/***** Get tag code from database *****/
2018-11-02 01:38:44 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get tag",
"SELECT TagCod FROM tst_tags"
" WHERE CrsCod=%ld AND TagTxt='%s'",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,TagTxt);
2014-12-01 23:55:08 +01:00
if (NumRows == 1)
{
/***** Get tag code *****/
row = mysql_fetch_row (mysql_res);
if ((TagCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_ERROR,NULL,
"Wrong code of tag.");
2014-12-01 23:55:08 +01:00
}
else if (NumRows > 1)
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_ERROR,NULL,
"Duplicated tag.");
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2019-03-09 20:12:44 +01:00
/***** Abort on error *****/
if (Ale_GetTypeOfLastAlert () == Ale_ERROR)
Ale_ShowAlertsAndExit ();
2014-12-01 23:55:08 +01:00
return TagCod;
}
/*****************************************************************************/
/********************* Insert new tag into tst_tags table ********************/
/*****************************************************************************/
static long Tst_CreateNewTag (long CrsCod,const char *TagTxt)
{
/***** Insert new tag into tst_tags table *****/
2018-11-03 01:45:36 +01:00
return
DB_QueryINSERTandReturnCode ("can not create new tag",
"INSERT INTO tst_tags"
" (CrsCod,ChangeTime,TagTxt,TagHidden)"
" VALUES"
" (%ld,NOW(),'%s','N')",
CrsCod,TagTxt);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********** Change visibility of an existing tag into tst_tags table *********/
/*****************************************************************************/
static void Tst_EnableOrDisableTag (long TagCod,bool TagHidden)
{
/***** Insert new tag into tst_tags table *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the visibility of a tag",
"UPDATE tst_tags SET TagHidden='%c',ChangeTime=NOW()"
" WHERE TagCod=%ld AND CrsCod=%ld",
TagHidden ? 'Y' :
'N',
2019-04-04 10:45:15 +02:00
TagCod,Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
}
2016-04-05 10:05:52 +02:00
/*****************************************************************************/
/********************* Put icon to remove one question ***********************/
/*****************************************************************************/
2016-04-05 13:07:33 +02:00
static void Tst_PutIconToRemoveOneQst (void)
2016-04-05 10:05:52 +02:00
{
2017-06-11 19:13:28 +02:00
Ico_PutContextualIconToRemove (ActReqRemTstQst,Tst_PutParamsRemoveOneQst);
2016-04-05 10:05:52 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-04-05 02:59:34 +02:00
/******************** Request the removal of a question **********************/
/*****************************************************************************/
void Tst_RequestRemoveQst (void)
{
extern const char *Txt_Do_you_really_want_to_remove_the_question_X;
extern const char *Txt_Remove_question;
bool EditingOnlyThisQst;
2016-04-05 10:47:36 +02:00
/***** Get main parameters from form *****/
/* Get the question code */
2016-04-06 19:26:09 +02:00
Gbl.Test.QstCod = Tst_GetQstCod ();
if (Gbl.Test.QstCod <= 0)
2016-04-05 02:59:34 +02:00
Lay_ShowErrorAndExit ("Wrong code of question.");
2016-04-05 10:47:36 +02:00
/* Get a parameter that indicates whether it's necessary
to continue listing the rest of questions */
2017-01-28 20:32:50 +01:00
EditingOnlyThisQst = Par_GetParToBool ("OnlyThisQst");
2016-04-05 02:59:34 +02:00
2017-04-28 14:02:08 +02:00
/* Get other parameters */
if (!EditingOnlyThisQst)
2017-09-04 17:03:49 +02:00
if (!Tst_GetParamsTst (Tst_EDIT_TEST))
2017-04-28 14:02:08 +02:00
Lay_ShowErrorAndExit ("Wrong test parameters.");
2016-04-05 02:59:34 +02:00
2017-04-28 14:02:08 +02:00
/***** Show question and button to remove question *****/
2019-02-17 01:14:55 +01:00
Ale_ShowAlertAndButton (ActRemTstQst,NULL,NULL,
EditingOnlyThisQst ? Tst_PutParamsRemoveOneQst :
Tst_PutParamsRemoveQst,
Btn_REMOVE_BUTTON,Txt_Remove_question,
Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_question_X,
2019-05-30 12:57:31 +02:00
Gbl.Test.QstCod);
2016-04-05 02:59:34 +02:00
/***** Continue editing questions *****/
if (EditingOnlyThisQst)
Tst_ListOneQstToEdit ();
else
2019-02-17 01:14:55 +01:00
{
Tst_FreeTagsList ();
2016-04-05 02:59:34 +02:00
Tst_ListQuestionsToEdit ();
2019-02-17 01:14:55 +01:00
}
2016-04-05 02:59:34 +02:00
}
2017-04-28 14:02:08 +02:00
/*****************************************************************************/
/***** Put parameter to remove question when editing only one question *******/
/*****************************************************************************/
static void Tst_PutParamsRemoveOneQst (void)
{
Tst_PutParamQstCod ();
Par_PutHiddenParamChar ("OnlyThisQst",'Y');
}
/*****************************************************************************/
/***** Put parameter to remove question when editing several questions *******/
/*****************************************************************************/
static void Tst_PutParamsRemoveQst (void)
{
Tst_PutParamQstCod ();
2019-02-11 22:15:18 +01:00
Dat_WriteParamsIniEndDates ();
2017-04-28 14:02:08 +02:00
Tst_WriteParamEditQst ();
}
2016-04-05 02:59:34 +02:00
/*****************************************************************************/
/***************************** Remove a question *****************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
void Tst_RemoveQst (void)
{
extern const char *Txt_Question_removed;
bool EditingOnlyThisQst;
2019-03-19 11:20:29 +01:00
long MedCod;
2014-12-01 23:55:08 +01:00
/***** Get the question code *****/
2016-04-06 19:26:09 +02:00
Gbl.Test.QstCod = Tst_GetQstCod ();
if (Gbl.Test.QstCod <= 0)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Wrong code of question.");
2016-04-05 02:59:34 +02:00
/***** Get a parameter that indicates whether it's necessary
to continue listing the rest of questions ******/
2017-01-28 20:32:50 +01:00
EditingOnlyThisQst = Par_GetParToBool ("OnlyThisQst");
2014-12-01 23:55:08 +01:00
2019-03-19 11:20:29 +01:00
/***** Remove media associated to question *****/
/* Remove media associated to answers */
2019-04-04 10:45:15 +02:00
Tst_RemoveMediaFromAllAnsOfQst (Gbl.Hierarchy.Crs.CrsCod,Gbl.Test.QstCod);
2019-03-19 11:20:29 +01:00
/* Remove media associated to stem */
MedCod = Tst_GetMedCodFromDB (-1L);
Med_RemoveMedia (MedCod);
2016-04-01 21:56:00 +02:00
2014-12-01 23:55:08 +01:00
/***** Remove the question from all the tables *****/
/* Remove answers and tags from this test question */
Tst_RemAnsFromQst ();
Tst_RemTagsFromQst ();
Tst_RemoveUnusedTagsFromCurrentCrs ();
/* Remove the question itself */
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove a question",
"DELETE FROM tst_questions"
" WHERE QstCod=%ld AND CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Gbl.Test.QstCod,Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
if (!mysql_affected_rows (&Gbl.mysql))
2020-03-07 00:14:35 +01:00
Lay_ShowErrorAndExit ("Wrong question.");
2014-12-01 23:55:08 +01:00
/***** Write message *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Question_removed);
2014-12-01 23:55:08 +01:00
/***** Continue editing questions *****/
if (!EditingOnlyThisQst)
Tst_ListQuestionsToEdit ();
}
/*****************************************************************************/
/*********************** Change the shuffle of a question ********************/
/*****************************************************************************/
void Tst_ChangeShuffleQst (void)
{
extern const char *Txt_The_answers_of_the_question_with_code_X_will_appear_shuffled;
extern const char *Txt_The_answers_of_the_question_with_code_X_will_appear_without_shuffling;
bool EditingOnlyThisQst;
bool Shuffle;
/***** Get the question code *****/
2016-04-06 19:26:09 +02:00
Gbl.Test.QstCod = Tst_GetQstCod ();
if (Gbl.Test.QstCod <= 0)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Wrong code of question.");
/***** Get a parameter that indicates whether it's necessary to continue listing the rest of questions ******/
2017-01-28 20:32:50 +01:00
EditingOnlyThisQst = Par_GetParToBool ("OnlyThisQst");
2014-12-01 23:55:08 +01:00
/***** Get a parameter that indicates whether it's possible to shuffle the answers of this question ******/
2017-01-28 20:32:50 +01:00
Shuffle = Par_GetParToBool ("Shuffle");
2014-12-01 23:55:08 +01:00
/***** Remove the question from all the tables *****/
/* Update the question changing the current shuffle */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the shuffle type of a question",
"UPDATE tst_questions SET Shuffle='%c'"
" WHERE QstCod=%ld AND CrsCod=%ld",
Shuffle ? 'Y' :
'N',
2019-04-04 10:45:15 +02:00
Gbl.Test.QstCod,Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
/***** Write message *****/
2019-02-16 19:29:27 +01:00
Ale_ShowAlert (Ale_SUCCESS,Shuffle ? Txt_The_answers_of_the_question_with_code_X_will_appear_shuffled :
Txt_The_answers_of_the_question_with_code_X_will_appear_without_shuffling,
Gbl.Test.QstCod);
2014-12-01 23:55:08 +01:00
/***** Continue editing questions *****/
if (EditingOnlyThisQst)
Tst_ListOneQstToEdit ();
else
Tst_ListQuestionsToEdit ();
}
/*****************************************************************************/
/************ Get the parameter with the code of a test question *************/
/*****************************************************************************/
2016-04-06 19:26:09 +02:00
static long Tst_GetQstCod (void)
2014-12-01 23:55:08 +01:00
{
2017-01-28 20:32:50 +01:00
/***** Get code of test question *****/
return Par_GetParToLong ("QstCod");
2014-12-01 23:55:08 +01:00
}
2017-04-28 14:02:08 +02:00
/*****************************************************************************/
/************ Put parameter with question code to edit, remove... ************/
/*****************************************************************************/
2017-09-08 01:18:20 +02:00
void Tst_PutParamQstCod (void)
2017-04-28 14:02:08 +02:00
{
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamLong (NULL,"QstCod",Gbl.Test.QstCod);
2017-04-28 14:02:08 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******** Insert or update question, tags and anser in the database **********/
/*****************************************************************************/
void Tst_InsertOrUpdateQstTagsAnsIntoDB (void)
{
/***** Insert or update question in the table of questions *****/
Tst_InsertOrUpdateQstIntoDB ();
/***** Insert tags in the tags table *****/
Tst_InsertTagsIntoDB ();
/***** Remove unused tags in current course *****/
Tst_RemoveUnusedTagsFromCurrentCrs ();
/***** Insert answers in the answers table *****/
Tst_InsertAnswersIntoDB ();
}
/*****************************************************************************/
/*********** Insert or update question in the table of questions *************/
/*****************************************************************************/
static void Tst_InsertOrUpdateQstIntoDB (void)
{
if (Gbl.Test.QstCod < 0) // It's a new question
{
2016-04-01 21:56:00 +02:00
/***** Insert question in the table of questions *****/
2018-11-03 01:45:36 +01:00
Gbl.Test.QstCod =
DB_QueryINSERTandReturnCode ("can not create question",
"INSERT INTO tst_questions"
" (CrsCod,EditTime,AnsType,Shuffle,"
2019-03-18 15:42:22 +01:00
"Stem,Feedback,MedCod,"
2018-11-03 01:45:36 +01:00
"NumHits,Score)"
" VALUES"
" (%ld,NOW(),'%s','%c',"
2019-03-18 15:42:22 +01:00
"'%s','%s',%ld,"
2018-11-03 01:45:36 +01:00
"0,0)",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-11-03 01:45:36 +01:00
Tst_StrAnswerTypesDB[Gbl.Test.AnswerType],
Gbl.Test.Shuffle ? 'Y' :
'N',
Gbl.Test.Stem.Text,
Gbl.Test.Feedback.Text ? Gbl.Test.Feedback.Text : "",
2019-03-18 15:42:22 +01:00
Gbl.Test.Media.MedCod);
2014-12-01 23:55:08 +01:00
}
else // It's an existing question
{
2016-04-01 21:56:00 +02:00
/***** Update existing question *****/
2016-04-03 18:51:48 +02:00
/* Update question in database */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update question",
"UPDATE tst_questions"
" SET EditTime=NOW(),AnsType='%s',Shuffle='%c',"
2019-03-18 15:42:22 +01:00
"Stem='%s',Feedback='%s',MedCod=%ld"
2018-11-03 12:16:40 +01:00
" WHERE QstCod=%ld AND CrsCod=%ld",
Tst_StrAnswerTypesDB[Gbl.Test.AnswerType],
Gbl.Test.Shuffle ? 'Y' :
'N',
Gbl.Test.Stem.Text,
Gbl.Test.Feedback.Text ? Gbl.Test.Feedback.Text : "",
2019-03-18 15:42:22 +01:00
Gbl.Test.Media.MedCod,
2019-04-04 10:45:15 +02:00
Gbl.Test.QstCod,Gbl.Hierarchy.Crs.CrsCod);
2016-04-03 18:51:48 +02:00
2014-12-01 23:55:08 +01:00
/* Remove answers and tags from this test question */
Tst_RemAnsFromQst ();
Tst_RemTagsFromQst ();
}
}
/*****************************************************************************/
/*********************** Insert tags in the tags table ***********************/
/*****************************************************************************/
static void Tst_InsertTagsIntoDB (void)
{
unsigned NumTag;
unsigned TagIdx;
long TagCod;
/***** For each tag... *****/
for (NumTag = 0, TagIdx = 0;
2016-04-06 22:27:33 +02:00
TagIdx < Gbl.Test.Tags.Num;
2014-12-01 23:55:08 +01:00
NumTag++)
2016-04-06 22:27:33 +02:00
if (Gbl.Test.Tags.Txt[NumTag][0])
2014-12-01 23:55:08 +01:00
{
/***** Check if this tag exists for current course *****/
2016-04-06 22:27:33 +02:00
if ((TagCod = Tst_GetTagCodFromTagTxt (Gbl.Test.Tags.Txt[NumTag])) < 0)
2014-12-01 23:55:08 +01:00
/* This tag is new for current course. Add it to tags table */
2019-04-04 10:45:15 +02:00
TagCod = Tst_CreateNewTag (Gbl.Hierarchy.Crs.CrsCod,Gbl.Test.Tags.Txt[NumTag]);
2014-12-01 23:55:08 +01:00
/***** Insert tag in tst_question_tags *****/
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not create tag",
"INSERT INTO tst_question_tags"
" (QstCod,TagCod,TagInd)"
" VALUES"
" (%ld,%ld,%u)",
Gbl.Test.QstCod,TagCod,TagIdx);
2014-12-01 23:55:08 +01:00
TagIdx++;
}
}
/*****************************************************************************/
/******************* Insert answers in the answers table *********************/
/*****************************************************************************/
static void Tst_InsertAnswersIntoDB (void)
{
unsigned NumOpt;
unsigned i;
/***** Insert answers in the answers table *****/
switch (Gbl.Test.AnswerType)
{
case Tst_ANS_INT:
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not create answer",
"INSERT INTO tst_answers"
2019-03-18 15:42:22 +01:00
" (QstCod,AnsInd,Answer,Feedback,MedCod,Correct)"
2018-11-02 19:37:11 +01:00
" VALUES"
2019-03-18 15:42:22 +01:00
" (%ld,0,%ld,'',-1,'Y')",
2018-11-02 19:37:11 +01:00
Gbl.Test.QstCod,
2019-03-18 15:42:22 +01:00
Gbl.Test.Answer.Integer);
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_FLOAT:
2019-11-27 09:01:45 +01:00
Str_SetDecimalPointToUS (); // To print the floating point as a dot
2014-12-01 23:55:08 +01:00
for (i = 0;
i < 2;
i++)
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not create answer",
"INSERT INTO tst_answers"
2019-03-18 15:42:22 +01:00
" (QstCod,AnsInd,Answer,Feedback,MedCod,Correct)"
2018-11-02 19:37:11 +01:00
" VALUES"
2020-01-11 15:22:02 +01:00
" (%ld,%u,'%.15lg','',-1,'Y')",
2018-11-02 19:37:11 +01:00
Gbl.Test.QstCod,i,
2019-03-18 15:42:22 +01:00
Gbl.Test.Answer.FloatingPoint[i]);
2016-06-04 14:21:01 +02:00
Str_SetDecimalPointToLocal (); // Return to local system
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_TRUE_FALSE:
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not create answer",
"INSERT INTO tst_answers"
2019-03-18 15:42:22 +01:00
" (QstCod,AnsInd,Answer,Feedback,MedCod,Correct)"
2018-11-02 19:37:11 +01:00
" VALUES"
2019-03-18 15:42:22 +01:00
" (%ld,0,'%c','',-1,'Y')",
2018-11-02 19:37:11 +01:00
Gbl.Test.QstCod,
2019-03-18 15:42:22 +01:00
Gbl.Test.Answer.TF);
2014-12-01 23:55:08 +01:00
break;
case Tst_ANS_UNIQUE_CHOICE:
case Tst_ANS_MULTIPLE_CHOICE:
case Tst_ANS_TEXT:
for (NumOpt = 0;
NumOpt < Gbl.Test.Answer.NumOptions;
NumOpt++)
2019-03-19 01:41:27 +01:00
if (Gbl.Test.Answer.Options[NumOpt].Text[0] || // Text
Gbl.Test.Answer.Options[NumOpt].Media.Type != Med_TYPE_NONE) // or media
2014-12-01 23:55:08 +01:00
{
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not create answer",
"INSERT INTO tst_answers"
2019-03-18 15:42:22 +01:00
" (QstCod,AnsInd,Answer,Feedback,MedCod,Correct)"
2018-11-02 19:37:11 +01:00
" VALUES"
2019-03-18 15:42:22 +01:00
" (%ld,%u,'%s','%s',%ld,'%c')",
2018-11-02 19:37:11 +01:00
Gbl.Test.QstCod,NumOpt,
Gbl.Test.Answer.Options[NumOpt].Text,
Gbl.Test.Answer.Options[NumOpt].Feedback ? Gbl.Test.Answer.Options[NumOpt].Feedback : "",
2019-03-18 15:42:22 +01:00
Gbl.Test.Answer.Options[NumOpt].Media.MedCod,
2018-11-02 19:37:11 +01:00
Gbl.Test.Answer.Options[NumOpt].Correct ? 'Y' :
'N');
2016-04-04 21:51:21 +02:00
/* Update image status */
2019-03-15 15:25:31 +01:00
if (Gbl.Test.Answer.Options[NumOpt].Media.Type != Med_TYPE_NONE)
Gbl.Test.Answer.Options[NumOpt].Media.Status = Med_STORED_IN_DB;
2014-12-01 23:55:08 +01:00
}
break;
default:
break;
}
}
2020-02-16 13:02:30 +01:00
/*****************************************************************************/
/******************* Remove all test exams made in a course ******************/
/*****************************************************************************/
void Tst_RemoveCrsTests (long CrsCod)
{
/***** Remove tests status in the course *****/
DB_QueryDELETE ("can not remove status of tests of a course",
"DELETE FROM tst_status WHERE CrsCod=%ld",
CrsCod);
/***** Remove test configuration of the course *****/
DB_QueryDELETE ("can not remove configuration of tests of a course",
"DELETE FROM tst_config WHERE CrsCod=%ld",
CrsCod);
/***** Remove associations between test questions
and test tags in the course *****/
DB_QueryDELETE ("can not remove tags associated"
" to questions of tests of a course",
"DELETE FROM tst_question_tags"
" USING tst_questions,tst_question_tags"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod=tst_question_tags.QstCod",
CrsCod);
/***** Remove test tags in the course *****/
DB_QueryDELETE ("can not remove tags of test of a course",
"DELETE FROM tst_tags WHERE CrsCod=%ld",
CrsCod);
/***** Remove test answers in the course *****/
DB_QueryDELETE ("can not remove answers of tests of a course",
"DELETE FROM tst_answers USING tst_questions,tst_answers"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod=tst_answers.QstCod",
CrsCod);
/***** Remove media associated to test questions in the course *****/
Tst_RemoveAllMedFilesFromAnsOfAllQstsInCrs (CrsCod);
Tst_RemoveAllMedFilesFromStemOfAllQstsInCrs (CrsCod);
/***** Remove test questions in the course *****/
DB_QueryDELETE ("can not remove test questions of a course",
"DELETE FROM tst_questions WHERE CrsCod=%ld",
CrsCod);
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******************** Remove answers from a test question ********************/
/*****************************************************************************/
static void Tst_RemAnsFromQst (void)
{
/***** Remove answers *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove the answers of a question",
"DELETE FROM tst_answers WHERE QstCod=%ld",
Gbl.Test.QstCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************** Remove tags from a test question *****************/
/*****************************************************************************/
static void Tst_RemTagsFromQst (void)
{
/***** Remove tags *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove the tags of a question",
"DELETE FROM tst_question_tags WHERE QstCod=%ld",
Gbl.Test.QstCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Remove unused tags in current course *******************/
/*****************************************************************************/
static void Tst_RemoveUnusedTagsFromCurrentCrs (void)
{
/***** Remove unused tags from tst_tags *****/
2018-11-02 22:27:26 +01:00
DB_QueryDELETE ("can not remove unused tags",
"DELETE FROM tst_tags"
" WHERE CrsCod=%ld AND TagCod NOT IN"
" (SELECT DISTINCT tst_question_tags.TagCod"
" FROM tst_questions,tst_question_tags"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod=tst_question_tags.QstCod)",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
}
2016-04-07 12:36:58 +02:00
/*****************************************************************************/
2019-03-18 19:35:23 +01:00
/** Remove all media associated to stems of all test questions in a course ***/
2016-04-07 12:36:58 +02:00
/*****************************************************************************/
2019-03-17 01:38:10 +01:00
static void Tst_RemoveAllMedFilesFromStemOfAllQstsInCrs (long CrsCod)
2016-04-04 21:51:21 +02:00
{
MYSQL_RES *mysql_res;
2019-03-02 21:49:11 +01:00
unsigned NumMedia;
2016-04-04 21:51:21 +02:00
2019-03-18 19:35:23 +01:00
/***** Get media codes associated to stems of test questions from database *****/
2019-03-02 21:49:11 +01:00
NumMedia =
2019-03-18 15:42:22 +01:00
(unsigned) DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT MedCod" // row[0]
2019-03-02 21:49:11 +01:00
" FROM tst_questions"
2018-11-02 01:38:44 +01:00
" WHERE CrsCod=%ld",
CrsCod);
2016-04-04 21:51:21 +02:00
2019-03-02 21:49:11 +01:00
/***** Go over result removing media files *****/
2019-03-18 15:42:22 +01:00
Med_RemoveMediaFromAllRows (NumMedia,mysql_res);
2016-04-04 21:51:21 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2016-04-07 12:36:58 +02:00
/*****************************************************************************/
2019-03-18 19:35:23 +01:00
/******* Remove all media associated to all answers of a test question *******/
2016-04-04 21:51:21 +02:00
/*****************************************************************************/
2019-03-19 11:20:29 +01:00
static void Tst_RemoveMediaFromAllAnsOfQst (long CrsCod,long QstCod)
2016-04-04 21:51:21 +02:00
{
MYSQL_RES *mysql_res;
2019-03-02 21:49:11 +01:00
unsigned NumMedia;
2016-04-04 21:51:21 +02:00
2019-03-18 19:35:23 +01:00
/***** Get media codes associated to answers of test questions from database *****/
2019-03-02 21:49:11 +01:00
NumMedia =
2019-03-18 15:42:22 +01:00
(unsigned) DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT tst_answers.MedCod" // row[0]
2018-11-02 01:38:44 +01:00
" FROM tst_questions,tst_answers"
" WHERE tst_questions.CrsCod=%ld" // Extra check
" AND tst_questions.QstCod=%ld" // Extra check
" AND tst_questions.QstCod=tst_answers.QstCod"
" AND tst_answers.QstCod=%ld",
CrsCod,QstCod,QstCod);
2016-04-07 12:36:58 +02:00
2019-03-18 19:35:23 +01:00
/***** Go over result removing media *****/
2019-03-18 15:42:22 +01:00
Med_RemoveMediaFromAllRows (NumMedia,mysql_res);
2016-04-07 12:36:58 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
2019-03-18 19:35:23 +01:00
/* Remove media associated to all answers of all test questions in a course **/
2016-04-07 12:36:58 +02:00
/*****************************************************************************/
2019-03-17 01:38:10 +01:00
static void Tst_RemoveAllMedFilesFromAnsOfAllQstsInCrs (long CrsCod)
2016-04-07 12:36:58 +02:00
{
MYSQL_RES *mysql_res;
2019-03-02 21:49:11 +01:00
unsigned NumMedia;
2016-04-07 12:36:58 +02:00
2019-03-02 21:49:11 +01:00
/***** Get names of media files associated to answers of test questions from database *****/
NumMedia =
2019-03-18 15:42:22 +01:00
(unsigned) DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT tst_answers.MedCod" // row[0]
2018-11-02 01:38:44 +01:00
" FROM tst_questions,tst_answers"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod=tst_answers.QstCod",
CrsCod);
2016-04-04 21:51:21 +02:00
2019-03-02 21:49:11 +01:00
/***** Go over result removing media files *****/
2019-03-18 15:42:22 +01:00
Med_RemoveMediaFromAllRows (NumMedia,mysql_res);
2016-04-04 21:51:21 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*********************** Get stats about test questions **********************/
/*****************************************************************************/
void Tst_GetTestStats (Tst_AnswerType_t AnsType,struct Tst_Stats *Stats)
{
Stats->NumQsts = 0;
Stats->NumCoursesWithQuestions = Stats->NumCoursesWithPluggableQuestions = 0;
Stats->AvgQstsPerCourse = 0.0;
Stats->NumHits = 0L;
Stats->AvgHitsPerCourse = 0.0;
Stats->AvgHitsPerQuestion = 0.0;
Stats->TotalScore = 0.0;
Stats->AvgScorePerQuestion = 0.0;
if (Tst_GetNumTstQuestions (Gbl.Scope.Current,AnsType,Stats))
{
if ((Stats->NumCoursesWithQuestions = Tst_GetNumCoursesWithTstQuestions (Gbl.Scope.Current,AnsType)) != 0)
{
Stats->NumCoursesWithPluggableQuestions = Tst_GetNumCoursesWithPluggableTstQuestions (Gbl.Scope.Current,AnsType);
2019-11-11 00:15:44 +01:00
Stats->AvgQstsPerCourse = (double) Stats->NumQsts / (double) Stats->NumCoursesWithQuestions;
Stats->AvgHitsPerCourse = (double) Stats->NumHits / (double) Stats->NumCoursesWithQuestions;
2014-12-01 23:55:08 +01:00
}
2019-11-11 00:15:44 +01:00
Stats->AvgHitsPerQuestion = (double) Stats->NumHits / (double) Stats->NumQsts;
2014-12-01 23:55:08 +01:00
if (Stats->NumHits)
Stats->AvgScorePerQuestion = Stats->TotalScore / (double) Stats->NumHits;
}
}
/*****************************************************************************/
/*********************** Get number of test questions ************************/
/*****************************************************************************/
// Returns the number of test questions
// in this location (all the platform, current degree or current course)
2019-04-03 20:57:04 +02:00
static unsigned Tst_GetNumTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsType,struct Tst_Stats *Stats)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
/***** Get number of test questions from database *****/
switch (Scope)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2014-12-01 23:55:08 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM tst_questions");
2014-12-01 23:55:08 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM tst_questions"
" WHERE AnsType='%s'",
Tst_StrAnswerTypesDB[AnsType]);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2015-03-09 11:03:55 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM institutions,centres,degrees,courses,tst_questions"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod);
2015-03-09 11:03:55 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM institutions,centres,degrees,courses,tst_questions"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod,
2018-11-02 11:33:58 +01:00
Tst_StrAnswerTypesDB[AnsType]);
2015-03-09 11:03:55 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2014-12-01 23:55:08 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM centres,degrees,courses,tst_questions"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod);
2014-12-01 23:55:08 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM centres,degrees,courses,tst_questions"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod,
2018-11-02 11:33:58 +01:00
Tst_StrAnswerTypesDB[AnsType]);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2014-12-01 23:55:08 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM degrees,courses,tst_questions"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod);
2014-12-01 23:55:08 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM degrees,courses,tst_questions"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod,
2018-11-02 11:33:58 +01:00
Tst_StrAnswerTypesDB[AnsType]);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2014-12-01 23:55:08 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM courses,tst_questions"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=tst_questions.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod);
2014-12-01 23:55:08 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM courses,tst_questions"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod,
2018-11-02 11:33:58 +01:00
Tst_StrAnswerTypesDB[AnsType]);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2014-12-01 23:55:08 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM tst_questions"
" WHERE CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),SUM(NumHits),SUM(Score)"
" FROM tst_questions"
" WHERE CrsCod=%ld AND AnsType='%s'",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-11-02 11:33:58 +01:00
Tst_StrAnswerTypesDB[AnsType]);
2014-12-01 23:55:08 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2014-12-01 23:55:08 +01:00
break;
}
/***** Get number of questions *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&(Stats->NumQsts)) != 1)
Lay_ShowErrorAndExit ("Error when getting number of test questions.");
if (Stats->NumQsts)
{
if (sscanf (row[1],"%lu",&(Stats->NumHits)) != 1)
Lay_ShowErrorAndExit ("Error when getting total number of hits in test questions.");
2016-06-04 14:21:01 +02:00
Str_SetDecimalPointToUS (); // To get the decimal point as a dot
2014-12-01 23:55:08 +01:00
if (sscanf (row[2],"%lf",&(Stats->TotalScore)) != 1)
Lay_ShowErrorAndExit ("Error when getting total score in test questions.");
2016-06-04 14:21:01 +02:00
Str_SetDecimalPointToLocal (); // Return to local system
2014-12-01 23:55:08 +01:00
}
else
{
Stats->NumHits = 0L;
Stats->TotalScore = 0.0;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return Stats->NumQsts;
}
/*****************************************************************************/
/**************** Get number of courses with test questions ******************/
/*****************************************************************************/
// Returns the number of courses with test questions
// in this location (all the platform, current degree or current course)
2019-04-03 20:57:04 +02:00
static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsType)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCourses;
/***** Get number of courses with test questions from database *****/
switch (Scope)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2014-12-01 23:55:08 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT CrsCod)"
" FROM tst_questions");
2014-12-01 23:55:08 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT CrsCod)"
" FROM tst_questions"
" WHERE AnsType='%s'",
Tst_StrAnswerTypesDB[AnsType]);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2015-03-09 11:03:55 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM institutions,centres,degrees,courses,tst_questions"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod);
2015-03-09 11:03:55 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM institutions,centres,degrees,courses,tst_questions"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod,
2018-11-02 11:33:58 +01:00
Tst_StrAnswerTypesDB[AnsType]);
2015-03-09 11:03:55 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2014-12-01 23:55:08 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM centres,degrees,courses,tst_questions"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod);
2014-12-01 23:55:08 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM centres,degrees,courses,tst_questions"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod,
2018-11-02 11:33:58 +01:00
Tst_StrAnswerTypesDB[AnsType]);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2014-12-01 23:55:08 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM degrees,courses,tst_questions"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod);
2014-12-01 23:55:08 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM degrees,courses,tst_questions"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod,
2018-11-02 11:33:58 +01:00
Tst_StrAnswerTypesDB[AnsType]);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2014-12-01 23:55:08 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNTDISTINCT (tst_questions.CrsCod)"
" FROM courses,tst_questions"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=tst_questions.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod);
2014-12-01 23:55:08 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM courses,tst_questions"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod,
2018-11-02 11:33:58 +01:00
Tst_StrAnswerTypesDB[AnsType]);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2014-12-01 23:55:08 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT CrsCod)"
" FROM tst_questions"
" WHERE CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with test questions",
"SELECT COUNT(DISTINCT CrsCod)"
" FROM tst_questions"
" WHERE CrsCod=%ld"
" AND AnsType='%s'",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-11-02 11:33:58 +01:00
Tst_StrAnswerTypesDB[AnsType]);
2014-12-01 23:55:08 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2014-12-01 23:55:08 +01:00
break;
}
/***** Get number of courses *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumCourses) != 1)
Lay_ShowErrorAndExit ("Error when getting number of courses with test questions.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumCourses;
}
/*****************************************************************************/
/*********** Get number of courses with pluggable test questions *************/
/*****************************************************************************/
// Returns the number of courses with pluggable test questions
// in this location (all the platform, current degree or current course)
2019-04-03 20:57:04 +02:00
static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Level_t Scope,Tst_AnswerType_t AnsType)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCourses;
/***** Get number of courses with test questions from database *****/
switch (Scope)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2014-12-01 23:55:08 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM tst_questions,tst_config"
" WHERE tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'",
Tst_PluggableDB[Tst_PLUGGABLE_YES]);
2014-12-01 23:55:08 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM tst_questions,tst_config"
" WHERE tst_questions.AnsType='%s'"
" AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'",
Tst_StrAnswerTypesDB[AnsType],
Tst_PluggableDB[Tst_PLUGGABLE_YES]);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2015-03-09 11:03:55 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM institutions,centres,degrees,courses,tst_questions,tst_config"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod,
2018-11-02 11:33:58 +01:00
Tst_PluggableDB[Tst_PLUGGABLE_YES]);
2015-03-09 11:03:55 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM institutions,centres,degrees,courses,tst_questions,tst_config"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'"
" AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod,
2018-11-02 11:33:58 +01:00
Tst_StrAnswerTypesDB[AnsType],
Tst_PluggableDB[Tst_PLUGGABLE_YES]);
2015-03-09 11:03:55 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2014-12-01 23:55:08 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM centres,degrees,courses,tst_questions,tst_config"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod,
2018-11-02 11:33:58 +01:00
Tst_PluggableDB[Tst_PLUGGABLE_YES]);
2014-12-01 23:55:08 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM centres,degrees,courses,tst_questions,tst_config"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'"
" AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod,
2018-11-02 11:33:58 +01:00
Tst_StrAnswerTypesDB[AnsType],
Tst_PluggableDB[Tst_PLUGGABLE_YES]);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2014-12-01 23:55:08 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM degrees,courses,tst_questions,tst_config"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod,
2018-11-02 11:33:58 +01:00
Tst_PluggableDB[Tst_PLUGGABLE_YES]);
2014-12-01 23:55:08 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM degrees,courses,tst_questions,tst_config"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'"
" AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod,
2018-11-02 11:33:58 +01:00
Tst_StrAnswerTypesDB[AnsType],
Tst_PluggableDB[Tst_PLUGGABLE_YES]);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2014-12-01 23:55:08 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM courses,tst_questions,tst_config"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod,
2018-11-02 11:33:58 +01:00
Tst_PluggableDB[Tst_PLUGGABLE_YES]);
2014-12-01 23:55:08 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM courses,tst_questions,tst_config"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'"
" AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod,
2018-11-02 11:33:58 +01:00
Tst_StrAnswerTypesDB[AnsType],
Tst_PluggableDB[Tst_PLUGGABLE_YES]);
2014-12-01 23:55:08 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2014-12-01 23:55:08 +01:00
if (AnsType == Tst_ANS_ALL)
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM tst_questions,tst_config"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-11-02 11:33:58 +01:00
Tst_PluggableDB[Tst_PLUGGABLE_YES]);
2014-12-01 23:55:08 +01:00
else
2018-11-02 11:33:58 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM tst_questions,tst_config"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.AnsType='%s'"
" AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-11-02 11:33:58 +01:00
Tst_StrAnswerTypesDB[AnsType],
Tst_PluggableDB[Tst_PLUGGABLE_YES]);
2014-12-01 23:55:08 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2014-12-01 23:55:08 +01:00
break;
}
/***** Get number of courses *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumCourses) != 1)
Lay_ShowErrorAndExit ("Error when getting number of courses with pluggable test questions.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumCourses;
}