swad-core/swad_match.c

3711 lines
125 KiB
C
Raw Permalink Normal View History

2019-09-14 12:59:34 +02:00
// swad_match.c: matches in games using remote control
/*
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.
Copyright (C) 1999-2024 Antonio Ca<EFBFBD>as Vargas
2019-09-14 12:59:34 +02: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 ***********************************/
/*****************************************************************************/
#define _GNU_SOURCE // For asprintf
#include <linux/limits.h> // For PATH_MAX
2019-12-29 12:39:00 +01:00
#include <stddef.h> // For NULL
2019-09-14 12:59:34 +02:00
#include <stdio.h> // For asprintf
#include <stdlib.h> // For free
2019-09-14 12:59:34 +02:00
#include <string.h> // For string functions
#include "swad_action_list.h"
#include "swad_alert.h"
#include "swad_box.h"
2019-09-14 12:59:34 +02:00
#include "swad_database.h"
2019-09-30 01:23:24 +02:00
#include "swad_date.h"
#include "swad_error.h"
2019-09-14 12:59:34 +02:00
#include "swad_form.h"
#include "swad_game.h"
#include "swad_game_database.h"
2019-09-14 12:59:34 +02:00
#include "swad_global.h"
#include "swad_group_database.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2019-09-14 12:59:34 +02:00
#include "swad_match.h"
#include "swad_match_database.h"
2019-09-28 02:31:42 +02:00
#include "swad_match_result.h"
#include "swad_parameter_code.h"
#include "swad_question_database.h"
2019-09-14 12:59:34 +02:00
#include "swad_role.h"
#include "swad_setting.h"
#include "swad_test.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
#define Mch_ICON_CLOSE "fas fa-times"
#define Mch_ICON_PLAY "fas fa-play"
#define Mch_ICON_PAUSE "fas fa-pause"
#define Mch_ICON_PREVIOUS "fas fa-step-backward"
#define Mch_ICON_NEXT "fas fa-step-forward"
#define Mch_ICON_RESULTS "fas fa-chart-bar"
2019-12-13 01:04:09 +01:00
#define Mch_COUNTDOWN_SECONDS_LARGE 60
#define Mch_COUNTDOWN_SECONDS_MEDIUM 30
#define Mch_COUNTDOWN_SECONDS_SMALL 10
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
2019-12-03 02:46:46 +01:00
typedef enum
{
Mch_CHANGE_STATUS_BY_STUDENT,
Mch_REFRESH_STATUS_BY_SERVER,
} Mch_Update_t;
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
long Mch_MchCodBeingPlayed; // Used to refresh game via AJAX
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_SetMchCodBeingPlayed (long MchCod);
2019-09-25 00:42:13 +02:00
2020-04-08 03:06:45 +02:00
static void Mch_PutIconsInListOfMatches (void *Games);
static void Mch_PutIconToCreateNewMatch (struct Gam_Games *Games);
static void Mch_ListOneOrMoreMatches (struct Gam_Games *Games,
Frm_PutForm_t PutFormMatch,
2019-09-14 12:59:34 +02:00
unsigned NumMatches,
MYSQL_RES *mysql_res);
static void Mch_ListOneOrMoreMatchesHeading (Usr_Can_t ICanEditMatches);
static Usr_Can_t Mch_CheckIfICanEditMatches (void);
static Usr_Can_t Mch_CheckIfICanEditThisMatch (const struct Mch_Match *Match);
static Usr_Can_t Mch_CheckIfICanChangeVisibilityOfResults (const struct Mch_Match *Match);
2020-04-08 03:06:45 +02:00
static void Mch_ListOneOrMoreMatchesIcons (struct Gam_Games *Games,
2020-11-25 01:50:13 +01:00
const struct Mch_Match *Match,
const char *Anchor);
static void Mch_ListOneOrMoreMatchesAuthor (const struct Gam_Games *Games,
const struct Mch_Match *Match);
static void Mch_ListOneOrMoreMatchesTimes (const struct Gam_Games *Games,
const struct Mch_Match *Match,
unsigned UniqueId);
static void Mch_ListOneOrMoreMatchesTitleGrps (const struct Gam_Games *Games,
const struct Mch_Match *Match,
2020-11-25 01:50:13 +01:00
const char *Anchor);
static void Mch_GetAndWriteNamesOfGrpsAssociatedToMatch (const struct Gam_Games *Games,
const struct Mch_Match *Match);
static void Mch_ListOneOrMoreMatchesNumPlayers (const struct Gam_Games *Games,
const struct Mch_Match *Match);
static void Mch_ListOneOrMoreMatchesStatus (const struct Gam_Games *Games,
struct Mch_Match *Match,
unsigned NumQsts);
static void Mch_PutParMchCod (void *MchCod);
2020-04-08 03:06:45 +02:00
static void Mch_ListOneOrMoreMatchesResult (struct Gam_Games *Games,
const struct Mch_Match *Match);
static void Mch_ListOneOrMoreMatchesResultStd (struct Gam_Games *Games,
const struct Mch_Match *Match);
static void Mch_ListOneOrMoreMatchesResultTch (struct Gam_Games *Games,
const struct Mch_Match *Match);
2019-09-25 00:42:13 +02:00
2019-09-14 12:59:34 +02:00
static void Mch_GetMatchDataFromRow (MYSQL_RES *mysql_res,
2020-04-08 03:06:45 +02:00
struct Mch_Match *Match);
2019-09-14 12:59:34 +02:00
static void Mch_PutFormMatch (struct Mch_Match *Match);
static void Mch_ParsFormMatch (void *Match);
2020-11-25 01:50:13 +01:00
static void Mch_ShowLstGrpsToEditMatch (long MchCod);
static void Mch_UpdateMatchTitleAndGrps (const struct Mch_Match *Match);
2019-09-14 12:59:34 +02:00
2020-11-25 01:50:13 +01:00
static long Mch_CreateMatch (long GamCod,char Title[Mch_MAX_BYTES_TITLE + 1]);
2019-09-23 21:39:54 +02:00
static void Mch_CreateIndexes (long GamCod,long MchCod);
static void Mch_ReorderAnswer (long MchCod,unsigned QstInd,
const struct Qst_Question *Question);
2019-09-14 12:59:34 +02:00
static void Mch_CreateGrps (long MchCod);
2020-04-08 03:06:45 +02:00
static void Mch_UpdateMatchStatusInDB (const struct Mch_Match *Match);
2019-09-14 12:59:34 +02:00
2020-04-08 03:06:45 +02:00
static void Mch_UpdateElapsedTimeInQuestion (const struct Mch_Match *Match);
static void Mch_GetElapsedTimeInQuestion (const struct Mch_Match *Match,
struct Dat_Time *Time);
2020-04-08 03:06:45 +02:00
static void Mch_GetElapsedTimeInMatch (const struct Mch_Match *Match,
struct Dat_Time *Time);
2019-09-14 12:59:34 +02:00
static void Mch_GetElapsedTime (unsigned NumRows,MYSQL_RES *mysql_res,
struct Dat_Time *Time);
2019-09-14 12:59:34 +02:00
2020-04-08 03:06:45 +02:00
static void Mch_SetMatchStatusToPrev (struct Mch_Match *Match);
static void Mch_SetMatchStatusToPrevQst (struct Mch_Match *Match);
static void Mch_SetMatchStatusToStart (struct Mch_Match *Match);
2019-09-17 15:42:41 +02:00
2020-04-08 03:06:45 +02:00
static void Mch_SetMatchStatusToNext (struct Mch_Match *Match);
static void Mch_SetMatchStatusToNextQst (struct Mch_Match *Match);
static void Mch_SetMatchStatusToEnd (struct Mch_Match *Match);
2019-09-17 15:42:41 +02:00
2020-04-08 03:06:45 +02:00
static void Mch_ShowMatchStatusForTch (struct Mch_Match *Match);
static void Mch_ShowMatchStatusForStd (struct Mch_Match *Match,Mch_Update_t Update);
2019-09-26 18:19:07 +02:00
2020-04-08 03:06:45 +02:00
static void Mch_ShowLeftColumnTch (struct Mch_Match *Match);
static void Mch_ShowRefreshablePartTch (struct Mch_Match *Match);
static void Mch_WriteElapsedTimeInMch (struct Mch_Match *Match);
static void Mch_WriteElapsedTimeInQst (struct Mch_Match *Match);
static void Mch_WriteNumRespondersQst (struct Mch_Match *Match);
static void Mch_PutFormCountdown (struct Mch_Match *Match,long Seconds,const char *Color);
static void Mch_PutCountdownAndHourglassIcon (struct Mch_Match *Match);
static void Mch_PutFormsCountdown (struct Mch_Match *Match);
2019-12-12 09:14:26 +01:00
2020-04-08 03:06:45 +02:00
static void Mch_ShowRightColumnTch (const struct Mch_Match *Match);
static void Mch_ShowLeftColumnStd (const struct Mch_Match *Match,
2019-12-03 02:46:46 +01:00
const struct Mch_UsrAnswer *UsrAnswer);
2020-04-08 03:06:45 +02:00
static void Mch_ShowRightColumnStd (struct Mch_Match *Match,
2019-12-03 02:46:46 +01:00
const struct Mch_UsrAnswer *UsrAnswer,
Mch_Update_t Update);
2019-09-26 18:19:07 +02:00
2020-04-08 03:06:45 +02:00
static void Mch_ShowNumQstInMch (const struct Mch_Match *Match);
static void Mch_PutMatchControlButtons (const struct Mch_Match *Match);
static void Mch_ShowFormColumns (const struct Mch_Match *Match);
static void Mch_PutParNumCols (unsigned NumCols);
2019-10-23 00:49:03 +02:00
2020-04-08 03:06:45 +02:00
static void Mch_ShowMatchTitleTch (const struct Mch_Match *Match);
static void Mch_ShowMatchTitleStd (const struct Mch_Match *Match);
2020-03-12 13:53:37 +01:00
2020-04-08 03:06:45 +02:00
static void Mch_PutCheckboxResult (const struct Mch_Match *Match);
static void Mch_PutIfAnswered (const struct Mch_Match *Match,bool Answered);
static void Mch_PutIconToRemoveMyAnswer (const struct Mch_Match *Match);
static void Mch_ShowQuestionAndAnswersTch (const struct Mch_Match *Match);
static void Mch_WriteAnswersMatchResult (const struct Mch_Match *Match,
struct Qst_Question *Question,
2020-03-27 21:54:13 +01:00
const char *Class,bool ShowResult);
2020-08-28 14:45:30 +02:00
static void Mch_WriteChoiceAnsViewMatch (const struct Mch_Match *Match,
struct Qst_Question *Question,
2020-08-28 14:45:30 +02:00
const char *Class,bool ShowResult);
static void Mch_ShowQuestionAndAnswersStd (const struct Mch_Match *Match,
2019-12-03 02:46:46 +01:00
const struct Mch_UsrAnswer *UsrAnswer,
Mch_Update_t Update);
2019-10-21 13:36:28 +02:00
2020-04-08 03:06:45 +02:00
static void Mch_ShowMatchScore (const struct Mch_Match *Match);
2019-12-14 01:31:32 +01:00
static void Mch_DrawEmptyScoreRow (unsigned NumRow,double MinScore,double MaxScore);
2019-10-21 15:07:00 +02:00
static void Mch_DrawScoreRow (double Score,double MinScore,double MaxScore,
2019-10-21 21:36:31 +02:00
unsigned NumRow,unsigned NumUsrs,unsigned MaxUsrs);
static const char *Mch_GetClassBorder (unsigned NumRow);
2019-09-14 12:59:34 +02:00
static void Mch_PutParNumOpt (unsigned NumOpt);
static unsigned Mch_GetParNumOpt (void);
2019-09-14 12:59:34 +02:00
static void Mch_PutBigButton (Act_Action_t NextAction,const char *Id,
2019-10-17 22:47:44 +02:00
long MchCod,const char *Icon,const char *Txt);
2019-12-13 00:36:01 +01:00
static void Mch_PutBigButtonHidden (const char *Icon);
// static void Mch_PutBigButtonClose (void);
2019-09-14 12:59:34 +02:00
static void Mch_ShowWaitImage (const char *Txt);
2020-04-08 03:06:45 +02:00
/*****************************************************************************/
/*************** Set/Get match code of the match being played ****************/
/*****************************************************************************/
static void Mch_SetMchCodBeingPlayed (long MchCod)
{
Mch_MchCodBeingPlayed = MchCod;
}
long Mch_GetMchCodBeingPlayed (void)
{
return Mch_MchCodBeingPlayed;
}
2019-09-29 22:38:32 +02:00
2020-04-23 23:09:28 +02:00
/*****************************************************************************/
/********************************* Reset match *******************************/
/*****************************************************************************/
void Mch_ResetMatch (struct Mch_Match *Match)
{
2020-05-05 20:09:28 +02:00
Dat_StartEndTime_t StartEndTime;
2020-04-23 23:09:28 +02:00
/***** Initialize to empty match *****/
Match->MchCod = -1L;
Match->GamCod = -1L;
Match->UsrCod = -1L;
2020-05-05 20:09:28 +02:00
for (StartEndTime = (Dat_StartEndTime_t) 0;
StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
StartEndTime++)
Match->TimeUTC[StartEndTime] = (time_t) 0;
2020-04-23 23:09:28 +02:00
Match->Title[0] = '\0';
Match->Status.QstInd = 0;
Match->Status.QstCod = -1L;
Match->Status.QstStartTimeUTC = (time_t) 0;
Match->Status.Showing = Mch_SHOWING_DEFAULT;
Match->Status.Countdown = 0;
Match->Status.NumCols = 1;
Match->Status.ShowQstResults = false;
Match->Status.ShowUsrResults = false;
Match->Status.Playing = false;
Match->Status.NumPlayers = 0;
};
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/************************* List the matches of a game ************************/
/*****************************************************************************/
void Mch_ListMatches (struct Gam_Games *Games,
Frm_PutForm_t PutFormNewMatch)
2019-09-14 12:59:34 +02:00
{
extern const char *Hlp_ASSESSMENT_Games_matches;
extern const char *Txt_Matches;
MYSQL_RES *mysql_res;
unsigned NumMatches;
/***** Get data of matches from database *****/
NumMatches = Mch_DB_GetMatchesInGame (&mysql_res,Games->Game.GamCod);
2019-09-14 12:59:34 +02:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
Box_BoxBegin (Txt_Matches,Mch_PutIconsInListOfMatches,Games,
2019-09-14 12:59:34 +02:00
Hlp_ASSESSMENT_Games_matches,Box_NOT_CLOSABLE);
/***** Select whether show only my groups or all groups *****/
if (Gbl.Crs.Grps.NumGrps && Mch_CheckIfICanEditMatches () == Usr_CAN)
{
Set_BeginSettingsHead ();
Grp_ShowFormToSelWhichGrps (ActSeeOneGam,Gam_PutPars,Games);
Set_EndSettingsHead ();
}
2019-09-29 17:33:39 +02:00
/***** Show the table with the matches *****/
Mch_ListOneOrMoreMatches (Games,PutFormNewMatch,
NumMatches,mysql_res);
2019-09-14 12:59:34 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2019-09-14 12:59:34 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/********************** Get match data using its code ************************/
/*****************************************************************************/
void Mch_GetMatchDataByCod (struct Mch_Match *Match)
2019-09-14 12:59:34 +02:00
{
MYSQL_RES *mysql_res;
/***** Get data of match from database *****/
if (Mch_DB_GetMatchDataByCod (&mysql_res,Match->MchCod)) // Match found...
2020-05-05 20:09:28 +02:00
/* Get match data from row */
2019-09-14 12:59:34 +02:00
Mch_GetMatchDataFromRow (mysql_res,Match);
else
/* Initialize to empty match */
2020-05-05 20:09:28 +02:00
Mch_ResetMatch (Match);
2019-09-14 12:59:34 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2019-12-07 02:12:13 +01:00
/*****************************************************************************/
/****************** Put icons in list of matches of a game *******************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_PutIconsInListOfMatches (void *Games)
2019-12-07 02:12:13 +01:00
{
2020-04-08 03:06:45 +02:00
if (Games)
if (Mch_CheckIfICanEditMatches () == Usr_CAN)
/***** Put icon to create a new match in current game *****/
2020-04-08 03:06:45 +02:00
Mch_PutIconToCreateNewMatch ((struct Gam_Games *) Games);
2019-12-07 02:12:13 +01:00
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
2019-09-29 17:33:39 +02:00
/********************* Put icon to create a new match ************************/
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_PutIconToCreateNewMatch (struct Gam_Games *Games)
2019-09-14 12:59:34 +02:00
{
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToAdd (ActReqNewMch,Mch_NEW_MATCH_SECTION_ID,
Gam_PutPars,Games);
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/*********************** List game matches for edition ***********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_ListOneOrMoreMatches (struct Gam_Games *Games,
Frm_PutForm_t PutFormMatch,
2019-09-14 12:59:34 +02:00
unsigned NumMatches,
MYSQL_RES *mysql_res)
2019-09-25 00:42:13 +02:00
{
unsigned NumMatch;
unsigned UniqueId;
2020-04-08 03:06:45 +02:00
struct Mch_Match Match;
2020-11-25 01:50:13 +01:00
char *Anchor;
Usr_Can_t ICanEditMatches = Mch_CheckIfICanEditMatches ();
long MchCodToBeEdited = PutFormMatch == Frm_PUT_FORM &&
Games->MchCod > 0 ? Games->MchCod :
-1L;
2020-04-28 12:34:56 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset match *****/
Mch_ResetMatch (&Match);
/***** Begin table *****/
HTM_TABLE_Begin ("TBL_SCROLL");
2019-09-25 00:42:13 +02:00
/***** Write the heading *****/
if (NumMatches)
Mch_ListOneOrMoreMatchesHeading (ICanEditMatches);
2019-09-25 00:42:13 +02:00
/***** Write rows *****/
for (NumMatch = 0, UniqueId = 1, The_ResetRowColor ();
NumMatch < NumMatches;
NumMatch++, UniqueId++, The_ChangeRowColor ())
2019-12-05 19:54:28 +01:00
{
/***** Get match data from row *****/
Mch_GetMatchDataFromRow (mysql_res,&Match);
2019-09-25 00:42:13 +02:00
if (Mch_CheckIfICanPlayThisMatchBasedOnGrps (&Match) == Usr_CAN)
{
/***** Build anchor string *****/
if (asprintf (&Anchor,"mch_%ld",Match.MchCod) < 0)
Err_NotEnoughMemoryExit ();
2019-09-25 00:42:13 +02:00
/***** First row for this match with match data ****/
HTM_TR_Begin (NULL);
2019-09-25 00:42:13 +02:00
/* Icons */
if (ICanEditMatches == Usr_CAN)
Mch_ListOneOrMoreMatchesIcons (Games,&Match,Anchor);
2019-09-25 00:42:13 +02:00
/* Start/end date/time */
Mch_ListOneOrMoreMatchesTimes (Games,&Match,UniqueId);
2019-09-25 00:42:13 +02:00
/* Title and groups */
Mch_ListOneOrMoreMatchesTitleGrps (Games,&Match,Anchor);
2019-09-25 00:42:13 +02:00
/* Number of players who have played the match */
Mch_ListOneOrMoreMatchesNumPlayers (Games,&Match);
2020-05-05 20:09:28 +02:00
/* Match status */
Mch_ListOneOrMoreMatchesStatus (Games,&Match,Games->Game.NumQsts);
2020-11-25 01:50:13 +01:00
/* Match result visible? */
Mch_ListOneOrMoreMatchesResult (Games,&Match);
2020-11-25 01:50:13 +01:00
HTM_TR_End ();
2020-11-25 01:50:13 +01:00
/***** Second row: match author ****/
HTM_TR_Begin (NULL);
Mch_ListOneOrMoreMatchesAuthor (Games,&Match);
HTM_TR_End ();
/***** Third row for this match used for edition ****/
if (ICanEditMatches == Usr_CAN &&
PutFormMatch == Frm_PUT_FORM && // Editing...
Match.MchCod == MchCodToBeEdited) // ...this match
/***** Check if I can edit this match *****/
if (Mch_CheckIfICanEditThisMatch (&Match) == Usr_CAN)
{
HTM_TR_Begin (NULL);
HTM_TD_Begin ("colspan=\"7\" class=\"LT %s\"",
The_GetColorRows ());
Mch_PutFormMatch (&Match); // Form to edit this match
HTM_TD_End ();
HTM_TR_End ();
}
2020-11-25 01:50:13 +01:00
/***** Free anchor string *****/
free (Anchor);
}
2019-12-05 19:54:28 +01:00
}
2019-09-25 00:42:13 +02:00
/***** Put button to play a new match in this game *****/
if (ICanEditMatches == Usr_CAN &&
PutFormMatch == Frm_PUT_FORM &&
MchCodToBeEdited <= 0)
{
/* Reset match */
Mch_ResetMatch (&Match);
Match.GamCod = Games->Game.GamCod;
Str_Copy (Match.Title,Games->Game.Title,sizeof (Match.Title) - 1);
/* Put form to create new match */
HTM_TR_Begin (NULL);
HTM_TD_Begin ("colspan=\"7\" class=\"LT %s\"",The_GetColorRows ());
Mch_PutFormMatch (&Match); // Form to create match
HTM_TD_End ();
HTM_TR_End ();
}
2019-09-25 00:42:13 +02:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2019-09-25 00:42:13 +02:00
}
/*****************************************************************************/
/***************** Put a column for match start and end times ****************/
/*****************************************************************************/
static void Mch_ListOneOrMoreMatchesHeading (Usr_Can_t ICanEditMatches)
2019-09-14 12:59:34 +02:00
{
extern const char *Txt_START_END_TIME[Dat_NUM_START_END_TIME];
extern const char *Txt_Match;
2019-09-17 20:44:29 +02:00
extern const char *Txt_Players;
2019-09-14 12:59:34 +02:00
extern const char *Txt_Status;
2020-02-19 00:45:26 +01:00
extern const char *Txt_Results;
2019-09-14 12:59:34 +02:00
/***** Begin row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-09-29 18:44:40 +02:00
/***** Column for icons *****/
if (ICanEditMatches == Usr_CAN)
HTM_TH_Empty (1);
2019-09-29 18:44:40 +02:00
/***** The rest of columns *****/
HTM_TH (Txt_START_END_TIME[Gam_ORDER_BY_START_DATE] ,HTM_HEAD_LEFT );
HTM_TH (Txt_START_END_TIME[Gam_ORDER_BY_END_DATE ] ,HTM_HEAD_LEFT );
HTM_TH (Txt_Match ,HTM_HEAD_LEFT );
HTM_TH_Begin (HTM_HEAD_RIGHT);
Ico_PutIconOn ("users.svg",Ico_BLUE,Txt_Players);
HTM_TH_End ();
HTM_TH (Txt_Status ,HTM_HEAD_CENTER);
HTM_TH (Txt_Results ,HTM_HEAD_CENTER);
2019-09-29 18:44:40 +02:00
/***** End row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-09-29 18:44:40 +02:00
}
/*****************************************************************************/
2019-09-29 23:40:33 +02:00
/*********************** Check if I can edit matches *************************/
2019-09-29 18:44:40 +02:00
/*****************************************************************************/
static Usr_Can_t Mch_CheckIfICanEditMatches (void)
2019-09-29 18:44:40 +02:00
{
static Usr_Can_t ICanEditMatches[Rol_NUM_ROLES] =
2019-09-29 18:44:40 +02:00
{
[Rol_NET ] = Usr_CAN,
[Rol_TCH ] = Usr_CAN,
[Rol_SYS_ADM] = Usr_CAN,
};
return ICanEditMatches[Gbl.Usrs.Me.Role.Logged];
2019-09-25 00:42:13 +02:00
}
2019-09-14 12:59:34 +02:00
2019-09-29 23:40:33 +02:00
/*****************************************************************************/
2019-09-30 01:10:57 +02:00
/***************** Check if I can edit (remove/resume) a match ***************/
2019-09-29 23:40:33 +02:00
/*****************************************************************************/
static Usr_Can_t Mch_CheckIfICanEditThisMatch (const struct Mch_Match *Match)
2019-09-29 23:40:33 +02:00
{
if (Match->MchCod <= 0)
return Usr_CAN;
2019-09-29 23:40:33 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_NET:
return (Match->UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) ? Usr_CAN : // Only if I am the creator
Usr_CAN_NOT;
2019-09-29 23:40:33 +02:00
case Rol_TCH:
case Rol_SYS_ADM:
return Usr_CAN;
2019-09-29 23:40:33 +02:00
default:
return Usr_CAN_NOT;
2019-09-29 23:40:33 +02:00
}
}
2020-06-23 12:57:31 +02:00
/*****************************************************************************/
/*********** Check if visibility of match results can be changed *************/
/*****************************************************************************/
static Usr_Can_t Mch_CheckIfICanChangeVisibilityOfResults (const struct Mch_Match *Match)
2020-06-23 12:57:31 +02:00
{
if (Match->Status.ShowUsrResults || // Results are currently visible
Match->Status.Showing == Mch_END) // Match has finished
return Mch_CheckIfICanEditThisMatch (Match);
2020-06-23 12:57:31 +02:00
return Usr_CAN_NOT;
2020-06-23 12:57:31 +02:00
}
2019-09-25 09:29:44 +02:00
/*****************************************************************************/
/************************* Put a column for icons ****************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_ListOneOrMoreMatchesIcons (struct Gam_Games *Games,
2020-11-25 01:50:13 +01:00
const struct Mch_Match *Match,
const char *Anchor)
2019-09-25 09:29:44 +02:00
{
HTM_TD_Begin ("rowspan=\"2\" class=\"BT %s\"",The_GetColorRows ());
2019-09-25 09:29:44 +02:00
switch (Mch_CheckIfICanEditThisMatch (Match))
{
case Usr_CAN:
Games->MchCod = Match->MchCod;
/***** Put icon to remove the match *****/
Ico_PutContextualIconToRemove (ActReqRemMch,NULL,Mch_PutParsEdit,Games);
/***** Put icon to edit the match *****/
Ico_PutContextualIconToEdit (ActReqChgMch,Anchor,Mch_PutParsEdit,Games);
break;
case Usr_CAN_NOT:
default:
Ico_PutIconRemovalNotAllowed ();
break;
}
2019-09-25 09:29:44 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-25 09:29:44 +02:00
}
/*****************************************************************************/
/************* Put a column for teacher who created the match ****************/
/*****************************************************************************/
static void Mch_ListOneOrMoreMatchesAuthor (const struct Gam_Games *Games,
const struct Mch_Match *Match)
2019-09-25 09:29:44 +02:00
{
/***** Match author (teacher) *****/
HTM_TD_Begin ("colspan=\"2\" class=\"LT %s\"",The_GetColorRows ());
Usr_WriteAuthor1Line (Match->UsrCod,Games->Game.HiddenOrVisible);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-25 09:29:44 +02:00
}
2019-09-25 00:42:13 +02:00
/*****************************************************************************/
/***************** Put a column for match start and end times ****************/
/*****************************************************************************/
2019-09-14 12:59:34 +02:00
static void Mch_ListOneOrMoreMatchesTimes (const struct Gam_Games *Games,
const struct Mch_Match *Match,
unsigned UniqueId)
2019-09-25 00:42:13 +02:00
{
extern const char *Dat_TimeStatusClass[Dat_NUM_TIME_STATUS][HidVis_NUM_HIDDEN_VISIBLE];
2019-09-25 00:42:13 +02:00
Dat_StartEndTime_t StartEndTime;
2019-11-01 22:53:39 +01:00
char *Id;
static Dat_TimeStatus_t TimeStatus[Mch_NUM_SHOWING] =
{
[Mch_START ] = Dat_FUTURE, // Start: don't show anything
[Mch_STEM ] = Dat_PRESENT, // Showing only the question stem
[Mch_ANSWERS] = Dat_PRESENT, // Showing the question stem and the answers
[Mch_RESULTS] = Dat_PRESENT, // Showing the results
[Mch_END ] = Dat_PAST, // End: don't show anything
};
2019-09-14 12:59:34 +02:00
2019-12-15 20:02:34 +01:00
for (StartEndTime = (Dat_StartEndTime_t) 0;
2019-09-25 00:42:13 +02:00
StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
StartEndTime++)
{
2019-11-01 22:53:39 +01:00
if (asprintf (&Id,"mch_time_%u_%u",(unsigned) StartEndTime,UniqueId) < 0)
Err_NotEnoughMemoryExit ();
HTM_TD_Begin ("id=\"%s\" class=\"LT %s_%s %s\"",
2019-11-01 22:53:39 +01:00
Id,
Dat_TimeStatusClass[TimeStatus[Match->Status.Showing]][Games->Game.HiddenOrVisible],
The_GetSuffix (),
The_GetColorRows ());
Dat_WriteLocalDateHMSFromUTC (Id,Match->TimeUTC[StartEndTime],
Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK,
true,true,true,0x7);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-11-06 19:45:20 +01:00
free (Id);
2019-09-25 00:42:13 +02:00
}
}
2019-09-14 12:59:34 +02:00
2019-09-25 00:42:13 +02:00
/*****************************************************************************/
/***************** Put a column for match title and grous ********************/
/*****************************************************************************/
2019-09-14 12:59:34 +02:00
static void Mch_ListOneOrMoreMatchesTitleGrps (const struct Gam_Games *Games,
const struct Mch_Match *Match,
2020-11-25 01:50:13 +01:00
const char *Anchor)
2019-09-25 00:42:13 +02:00
{
extern const char *HidVis_TitleClass[HidVis_NUM_HIDDEN_VISIBLE];
2019-12-05 19:54:28 +01:00
extern const char *Txt_Play;
extern const char *Txt_Resume;
HTM_TD_Begin ("rowspan=\"2\" class=\"LT %s\"",The_GetColorRows ());
HTM_ARTICLE_Begin (Anchor);
2019-09-14 12:59:34 +02:00
/***** Match title *****/
Frm_BeginForm (Gbl.Usrs.Me.Role.Logged == Rol_STD ? ActJoiMch :
ActResMch);
ParCod_PutPar (ParCod_Mch,Match->MchCod);
HTM_BUTTON_Submit_Begin (Gbl.Usrs.Me.Role.Logged == Rol_STD ? Txt_Play :
Txt_Resume,
"class=\"LT BT_LINK %s_%s\"",
HidVis_TitleClass[Games->Game.HiddenOrVisible],
The_GetSuffix ());
HTM_Txt (Match->Title);
HTM_BUTTON_End ();
2019-09-14 12:59:34 +02:00
Frm_EndForm ();
2019-09-14 12:59:34 +02:00
/***** Groups whose students can answer this match *****/
if (Gbl.Crs.Grps.NumGrps)
Mch_GetAndWriteNamesOfGrpsAssociatedToMatch (Games,Match);
HTM_ARTICLE_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-25 00:42:13 +02:00
}
2019-09-14 12:59:34 +02:00
2019-09-25 00:42:13 +02:00
/*****************************************************************************/
/************* Get and write the names of the groups of a match **************/
/*****************************************************************************/
2019-09-14 12:59:34 +02:00
static void Mch_GetAndWriteNamesOfGrpsAssociatedToMatch (const struct Gam_Games *Games,
const struct Mch_Match *Match)
2019-09-25 00:42:13 +02:00
{
extern const char *HidVis_GroupClass[HidVis_NUM_HIDDEN_VISIBLE];
2019-09-25 00:42:13 +02:00
extern const char *Txt_Group;
extern const char *Txt_Groups;
extern const char *Txt_and;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumGrps;
unsigned NumGrp;
2019-09-14 12:59:34 +02:00
2019-09-25 00:42:13 +02:00
/***** Get groups associated to a match from database *****/
NumGrps = Mch_DB_GetGrpNamesAssociatedToMatch (&mysql_res,Match->MchCod);
2019-09-14 12:59:34 +02:00
HTM_DIV_Begin ("class=\"%s_%s\"",
HidVis_GroupClass[Games->Game.HiddenOrVisible],
The_GetSuffix ());
2019-09-17 20:44:29 +02:00
/***** Write heading *****/
HTM_TxtColonNBSP (NumGrps == 1 ? Txt_Group :
Txt_Groups);
/***** Write groups *****/
if (NumGrps) // Groups found...
{
/* Get and write the group types and names */
for (NumGrp = 0;
NumGrp < NumGrps;
NumGrp++)
{
/* Get next group */
row = mysql_fetch_row (mysql_res);
/* Write group type name and group name */
HTM_TxtF ("%s %s",row[0],row[1]);
if (NumGrps >= 2)
{
if (NumGrp == NumGrps - 2)
HTM_TxtF (" %s ",Txt_and);
if (NumGrps >= 3)
if (NumGrp < NumGrps - 2)
HTM_Txt (", ");
}
}
}
else
Grp_WriteTheWholeCourse ();
2019-09-14 12:59:34 +02:00
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-25 00:42:13 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2019-09-14 12:59:34 +02:00
}
2019-09-25 09:29:44 +02:00
/*****************************************************************************/
/******************* Put a column for number of players **********************/
/*****************************************************************************/
static void Mch_ListOneOrMoreMatchesNumPlayers (const struct Gam_Games *Games,
const struct Mch_Match *Match)
2019-09-25 09:29:44 +02:00
{
extern const char *HidVis_DataClass[HidVis_NUM_HIDDEN_VISIBLE];
2019-09-25 09:29:44 +02:00
/***** Number of players who have answered any question in the match ******/
HTM_TD_Begin ("rowspan=\"2\" class=\"RT %s_%s %s\"",
HidVis_DataClass[Games->Game.HiddenOrVisible],The_GetSuffix (),
The_GetColorRows ());
HTM_Unsigned (Mch_DB_GetNumUsrsWhoHavePlayedMch (Match->MchCod));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-25 09:29:44 +02:00
}
2019-09-25 00:28:57 +02:00
/*****************************************************************************/
/********************** Put a column for match status ************************/
/*****************************************************************************/
static void Mch_ListOneOrMoreMatchesStatus (const struct Gam_Games *Games,
struct Mch_Match *Match,
unsigned NumQsts)
2019-09-25 00:28:57 +02:00
{
extern const char *HidVis_DataClass[HidVis_NUM_HIDDEN_VISIBLE];
HTM_TD_Begin ("rowspan=\"2\" class=\"CT DAT_%s %s\"",
The_GetSuffix (),The_GetColorRows ());
2019-09-25 00:28:57 +02:00
if (Match->Status.Showing != Mch_END) // Match not over
{
/* Current question index / total of questions */
HTM_DIV_Begin ("class=\"%s_%s\"",
HidVis_DataClass[Games->Game.HiddenOrVisible],
The_GetSuffix ());
HTM_TxtF ("%u/%u",Match->Status.QstInd,NumQsts);
HTM_DIV_End ();
}
2019-09-25 00:28:57 +02:00
/* Icon to join match or resume match */
Lay_PutContextualLinkOnlyIcon (Gbl.Usrs.Me.Role.Logged == Rol_STD ? ActJoiMch :
ActResMch,
NULL,
Mch_PutParMchCod,&Match->MchCod,
Match->Status.Showing == Mch_END ? "flag-checkered.svg" :
"play.svg",Ico_BLACK);
2019-09-25 00:28:57 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-25 00:28:57 +02:00
}
/*****************************************************************************/
/******************** Write parameter with code of match *********************/
/*****************************************************************************/
static void Mch_PutParMchCod (void *MchCod)
{
if (MchCod)
ParCod_PutPar (ParCod_Mch,*((long *) MchCod));
}
2019-09-25 00:28:57 +02:00
/*****************************************************************************/
/**************** Put a column for visibility of match result ****************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_ListOneOrMoreMatchesResult (struct Gam_Games *Games,
const struct Mch_Match *Match)
2019-09-25 00:28:57 +02:00
{
static void (*Function[Rol_NUM_ROLES]) (struct Gam_Games *Games,
const struct Mch_Match *Match) =
{
[Rol_STD ] = Mch_ListOneOrMoreMatchesResultStd,
[Rol_NET ] = Mch_ListOneOrMoreMatchesResultTch,
[Rol_TCH ] = Mch_ListOneOrMoreMatchesResultTch,
[Rol_SYS_ADM] = Mch_ListOneOrMoreMatchesResultTch,
};
HTM_TD_Begin ("rowspan=\"2\" class=\"CT %s\"",The_GetColorRows ());
2019-09-25 00:28:57 +02:00
if (Function[Gbl.Usrs.Me.Role.Logged])
Function[Gbl.Usrs.Me.Role.Logged] (Games,Match);
else
Err_WrongRoleExit ();
2019-09-25 00:28:57 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-25 00:28:57 +02:00
}
2020-04-08 03:06:45 +02:00
static void Mch_ListOneOrMoreMatchesResultStd (struct Gam_Games *Games,
const struct Mch_Match *Match)
2019-12-05 19:54:28 +01:00
{
Games->MchCod = Match->MchCod;
2019-12-05 19:54:28 +01:00
/***** Is match result visible or hidden? *****/
if (Match->Status.ShowUsrResults)
/* Result is visible by me */
2020-04-02 03:28:08 +02:00
Lay_PutContextualLinkOnlyIcon (ActSeeMyMchResMch,MchRes_RESULTS_BOX_ID,
Mch_PutParsEdit,Games,
"trophy.svg",Ico_BLACK);
2019-12-05 19:54:28 +01:00
else
/* Result is forbidden to me */
2020-02-19 00:45:26 +01:00
Ico_PutIconNotVisible ();
2019-12-05 19:54:28 +01:00
}
2020-04-08 03:06:45 +02:00
static void Mch_ListOneOrMoreMatchesResultTch (struct Gam_Games *Games,
const struct Mch_Match *Match)
2019-12-05 19:54:28 +01:00
{
2019-12-08 23:19:16 +01:00
extern const char *Txt_Visible_results;
extern const char *Txt_Hidden_results;
2019-12-05 19:54:28 +01:00
Games->MchCod = Match->MchCod;
2019-12-08 23:19:16 +01:00
2020-06-23 12:57:31 +02:00
/***** Show match results *****/
if (Mch_CheckIfICanEditThisMatch (Match) == Usr_CAN)
2020-05-18 22:59:07 +02:00
Lay_PutContextualLinkOnlyIcon (ActSeeUsrMchResMch,MchRes_RESULTS_BOX_ID,
Mch_PutParsEdit,Games,
"trophy.svg",Ico_BLACK);
2019-12-08 23:19:16 +01:00
2020-06-23 12:57:31 +02:00
/***** Check if visibility of session results can be changed *****/
switch (Mch_CheckIfICanChangeVisibilityOfResults (Match))
2020-06-23 12:57:31 +02:00
{
case Usr_CAN:
/* I can edit visibility */
if (Match->Status.ShowUsrResults)
Lay_PutContextualLinkOnlyIcon (ActChgVisResMchUsr,NULL,
Mch_PutParsEdit,Games,
"eye.svg",Ico_GREEN);
else
Lay_PutContextualLinkOnlyIcon (ActChgVisResMchUsr,NULL,
Mch_PutParsEdit,Games,
"eye-slash.svg",Ico_RED);
break;
case Usr_CAN_NOT:
default:
/* I can not edit visibility */
if (Match->Status.ShowUsrResults)
Ico_PutIconOff ("eye.svg" ,Ico_GREEN,Txt_Visible_results);
else
Ico_PutIconOff ("eye-slash.svg",Ico_RED ,Txt_Hidden_results );
break;
}
2019-12-05 19:54:28 +01:00
}
2019-09-25 21:58:12 +02:00
/*****************************************************************************/
/******************** Toggle visibility of match results *********************/
/*****************************************************************************/
2020-05-16 02:04:36 +02:00
void Mch_ToggleVisResultsMchUsr (void)
2019-09-25 21:58:12 +02:00
{
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
struct Mch_Match Match;
2020-04-23 23:09:28 +02:00
/***** Reset games context *****/
2020-04-08 03:06:45 +02:00
Gam_ResetGames (&Games);
Gam_ResetGame (&Games.Game);
2020-04-23 23:09:28 +02:00
Mch_ResetMatch (&Match);
2019-09-29 22:38:32 +02:00
/***** Get and check parameters *****/
Mch_GetAndCheckPars (&Games,&Match);
2019-09-25 21:58:12 +02:00
2020-06-23 12:57:31 +02:00
/***** Check if visibility of match results can be changed *****/
if (Mch_CheckIfICanChangeVisibilityOfResults (&Match) == Usr_CAN_NOT)
Err_NoPermissionExit ();
2019-09-30 01:10:57 +02:00
2019-09-25 21:58:12 +02:00
/***** Toggle visibility of match results *****/
Match.Status.ShowUsrResults = !Match.Status.ShowUsrResults;
Mch_DB_UpdateVisResultsMchUsr (Match.MchCod,Match.Status.ShowUsrResults);
2019-09-25 21:58:12 +02:00
/***** Show current game *****/
Gam_ShowOnlyOneGame (&Games,
2019-12-08 16:46:25 +01:00
false, // Do not list game questions
Frm_DONT_PUT_FORM);
2019-09-25 21:58:12 +02:00
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/******************** Get game data from a database row **********************/
/*****************************************************************************/
static void Mch_GetMatchDataFromRow (MYSQL_RES *mysql_res,
2020-04-08 03:06:45 +02:00
struct Mch_Match *Match)
2019-09-14 12:59:34 +02:00
{
MYSQL_ROW row;
2019-09-22 19:50:24 +02:00
Dat_StartEndTime_t StartEndTime;
2019-10-22 23:42:22 +02:00
long LongNum;
2019-09-14 12:59:34 +02:00
/***** Get next row from result *****/
2019-09-14 12:59:34 +02:00
row = mysql_fetch_row (mysql_res);
/*
2019-09-25 21:58:12 +02:00
row[ 0] MchCod
row[ 1] GamCod
row[ 2] UsrCod
row[ 3] UNIX_TIMESTAMP(StartTime)
row[ 4] UNIX_TIMESTAMP(EndTime)
row[ 5] Title
2019-09-14 12:59:34 +02:00
*/
/***** Get match data *****/
/* Code of the match (row[0]) */
if ((Match->MchCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongMatchExit ();
2019-09-14 12:59:34 +02:00
/* Code of the game (row[1]) */
if ((Match->GamCod = Str_ConvertStrCodToLongCod (row[1])) <= 0)
Err_WrongGameExit ();
2019-09-14 12:59:34 +02:00
/* Get match teacher (row[2]) */
Match->UsrCod = Str_ConvertStrCodToLongCod (row[2]);
2019-09-22 19:50:24 +02:00
/* Get start/end times (row[3], row[4] hold start/end UTC times) */
2019-12-15 20:02:34 +01:00
for (StartEndTime = (Dat_StartEndTime_t) 0;
2019-09-22 19:50:24 +02:00
StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
StartEndTime++)
Match->TimeUTC[StartEndTime] = Dat_GetUNIXTimeFromStr (row[3 + StartEndTime]);
2019-09-14 12:59:34 +02:00
2020-11-25 01:50:13 +01:00
/* Get the title of the match (row[5]) */
2019-09-14 12:59:34 +02:00
if (row[5])
Str_Copy (Match->Title,row[5],sizeof (Match->Title) - 1);
2019-09-14 12:59:34 +02:00
else
Match->Title[0] = '\0';
/***** Get current match status *****/
/*
2019-09-25 21:58:12 +02:00
row[ 6] QstInd
row[ 7] QstCod
row[ 8] Showing
2019-12-12 18:24:23 +01:00
row[ 9] Countdown
row[10] NumCols
row[11] ShowQstResults
row[12] ShowUsrResults
2019-09-14 12:59:34 +02:00
*/
/* Current question index (row[6]) */
2020-02-27 00:19:55 +01:00
Match->Status.QstInd = Str_ConvertStrToUnsigned (row[6]);
2019-09-14 12:59:34 +02:00
/* Current question code (row[7]) */
Match->Status.QstCod = Str_ConvertStrCodToLongCod (row[7]);
2019-09-25 21:58:12 +02:00
/* Get what to show (stem, answers, results) (row(8)) */
Match->Status.Showing = Mch_DB_GetShowingFromStr (row[8]);
2019-09-14 12:59:34 +02:00
2019-12-12 18:24:23 +01:00
/* Get countdown (row[9]) */
Match->Status.Countdown = Str_ConvertStrCodToLongCod (row[9]);
/* Get number of columns (row[10]) */
LongNum = Str_ConvertStrCodToLongCod (row[10]);
2019-10-22 23:42:22 +02:00
Match->Status.NumCols = (LongNum <= 1 ) ? 1 :
((LongNum >= Mch_MAX_COLS) ? Mch_MAX_COLS :
(unsigned) LongNum);
2019-12-12 18:24:23 +01:00
/* Get whether to show question results or not (row(11)) */
Match->Status.ShowQstResults = (row[11][0] == 'Y');
2019-09-25 21:58:12 +02:00
2019-12-12 18:24:23 +01:00
/* Get whether to show user results or not (row(12)) */
Match->Status.ShowUsrResults = (row[12][0] == 'Y');
2019-09-14 12:59:34 +02:00
/***** Get whether the match is being played or not *****/
2019-12-10 21:52:22 +01:00
if (Match->Status.Showing == Mch_END) // Match over
2019-09-17 15:42:41 +02:00
Match->Status.Playing = false;
2019-12-10 21:52:22 +01:00
else // Match not over
Match->Status.Playing = Mch_DB_CheckIfMatchIsBeingPlayed (Match->MchCod);
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/************** Request the removal of a match (game instance) ***************/
/*****************************************************************************/
void Mch_ReqRemMatch (void)
2019-09-14 12:59:34 +02:00
{
extern const char *Txt_Do_you_really_want_to_remove_the_match_X;
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
struct Mch_Match Match;
2020-04-23 23:09:28 +02:00
/***** Reset games context *****/
2020-04-08 03:06:45 +02:00
Gam_ResetGames (&Games);
Gam_ResetGame (&Games.Game);
2020-04-23 23:09:28 +02:00
Mch_ResetMatch (&Match);
2019-09-29 22:38:32 +02:00
/***** Get and check parameters *****/
Mch_GetAndCheckPars (&Games,&Match);
2019-09-14 12:59:34 +02:00
/***** Show question and button to remove question *****/
Ale_ShowAlertRemove (ActRemMch,NULL,
Mch_PutParsEdit,&Games,
Txt_Do_you_really_want_to_remove_the_match_X,
Match.Title);
2019-09-14 12:59:34 +02:00
/***** Show current game *****/
Gam_ShowOnlyOneGame (&Games,
2019-12-08 16:46:25 +01:00
false, // Do not list game questions
Frm_DONT_PUT_FORM);
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/********************** Remove a match (game instance) ***********************/
/*****************************************************************************/
2019-09-29 21:33:27 +02:00
void Mch_RemoveMatch (void)
2019-09-14 12:59:34 +02:00
{
extern const char *Txt_Match_X_removed;
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
struct Mch_Match Match;
2020-04-23 23:09:28 +02:00
/***** Reset games context *****/
2020-04-08 03:06:45 +02:00
Gam_ResetGames (&Games);
Gam_ResetGame (&Games.Game);
2020-04-23 23:09:28 +02:00
Mch_ResetMatch (&Match);
2019-09-29 22:38:32 +02:00
/***** Get and check parameters *****/
Mch_GetAndCheckPars (&Games,&Match);
2019-09-27 20:00:47 +02:00
2019-09-29 23:40:33 +02:00
/***** Check if I can remove this match *****/
if (Mch_CheckIfICanEditThisMatch (&Match) == Usr_CAN_NOT)
Err_NoPermissionExit ();
2019-09-29 23:40:33 +02:00
2019-09-27 20:00:47 +02:00
/***** Remove the match from all database tables *****/
Mch_DB_RemoveMatchFromAllTables (Match.MchCod);
2019-09-27 20:00:47 +02:00
2019-09-14 12:59:34 +02:00
/***** Write message *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_Match_X_removed,
Match.Title);
/***** Show current game *****/
Gam_ShowOnlyOneGame (&Games,
2019-12-08 16:46:25 +01:00
false, // Do not list game questions
Frm_DONT_PUT_FORM);
2019-09-14 12:59:34 +02:00
}
2019-09-27 20:00:47 +02:00
/*****************************************************************************/
2019-09-27 21:45:53 +02:00
/******************** Remove match in game from all tables *******************/
/*****************************************************************************/
2019-09-28 01:12:53 +02:00
void Mch_RemoveMatchesInGameFromAllTables (long GamCod)
{
/***** Remove matches from secondary tables *****/
Mch_DB_RemoveMatchesInGameFromOtherTable (GamCod,"mch_players");
Mch_DB_RemoveMatchesInGameFromOtherTable (GamCod,"mch_playing");
Mch_DB_RemoveMatchesInGameFromOtherTable (GamCod,"mch_results");
Mch_DB_RemoveMatchesInGameFromOtherTable (GamCod,"mch_answers");
Mch_DB_RemoveMatchesInGameFromOtherTable (GamCod,"mch_times");
Mch_DB_RemoveMatchesInGameFromOtherTable (GamCod,"mch_groups");
Mch_DB_RemoveMatchesInGameFromOtherTable (GamCod,"mch_indexes");
2019-09-28 01:12:53 +02:00
/***** Remove matches in game from main table *****/
Mch_DB_RemoveMatchesInGameFromMainTable (GamCod);
2019-09-29 23:13:20 +02:00
}
2019-09-28 01:12:53 +02:00
/*****************************************************************************/
/******************* Remove match in course from all tables ******************/
/*****************************************************************************/
2020-05-18 22:59:07 +02:00
void Mch_RemoveMatchesInCourseFromAllTables (long CrsCod)
2019-09-27 21:45:53 +02:00
{
2019-09-28 01:12:53 +02:00
/***** Remove matches from secondary tables *****/
Mch_DB_RemoveMatchesInCrsFromOtherTable (CrsCod,"mch_players");
Mch_DB_RemoveMatchesInCrsFromOtherTable (CrsCod,"mch_playing");
Mch_DB_RemoveMatchesInCrsFromOtherTable (CrsCod,"mch_results");
Mch_DB_RemoveMatchesInCrsFromOtherTable (CrsCod,"mch_answers");
Mch_DB_RemoveMatchesInCrsFromOtherTable (CrsCod,"mch_times");
Mch_DB_RemoveMatchesInCrsFromOtherTable (CrsCod,"mch_groups");
Mch_DB_RemoveMatchesInCrsFromOtherTable (CrsCod,"mch_indexes");
2019-09-27 21:45:53 +02:00
/***** Remove matches in course from main table *****/
Mch_DB_RemoveMatchesInCrsFromMainTable (CrsCod);
2019-09-27 20:00:47 +02:00
}
2019-09-28 01:12:53 +02:00
/*****************************************************************************/
2020-05-18 22:59:07 +02:00
/*************** Remove matches made by user in all courses ******************/
2019-09-28 01:12:53 +02:00
/*****************************************************************************/
2020-05-18 22:59:07 +02:00
void Mch_RemoveMatchesMadeByUsrInAllCrss (long UsrCod)
2019-09-29 23:13:20 +02:00
{
/***** Remove student from secondary tables *****/
Mch_DB_RemoveMatchesMadeByUsrFromTable (UsrCod,"mch_players");
Mch_DB_RemoveMatchesMadeByUsrFromTable (UsrCod,"mch_results");
Mch_DB_RemoveMatchesMadeByUsrFromTable (UsrCod,"mch_answers");
2019-09-29 23:13:20 +02:00
}
2020-05-18 22:59:07 +02:00
/*****************************************************************************/
/***************** Remove matches made by user in a course *******************/
/*****************************************************************************/
void Mch_RemoveMatchesMadeByUsrInCrs (long UsrCod,long CrsCod)
{
/***** Remove student from secondary tables *****/
Mch_DB_RemoveMatchesMadeByUsrInCrsFromTable (UsrCod,CrsCod,"mch_players");
Mch_DB_RemoveMatchesMadeByUsrInCrsFromTable (UsrCod,CrsCod,"mch_results");
Mch_DB_RemoveMatchesMadeByUsrInCrsFromTable (UsrCod,CrsCod,"mch_answers");
2020-05-18 22:59:07 +02:00
}
2020-10-13 22:34:31 +02:00
/*****************************************************************************/
/**************** Request the creation or edition of a match *****************/
2020-10-13 22:34:31 +02:00
/*****************************************************************************/
void Mch_ReqCreatOrEditMatch (void)
2020-10-13 22:34:31 +02:00
{
struct Gam_Games Games;
struct Mch_Match Match;
/***** Reset games context *****/
Gam_ResetGames (&Games);
Gam_ResetGame (&Games.Game);
2020-10-13 22:34:31 +02:00
Mch_ResetMatch (&Match);
/***** Get and check parameters *****/
Mch_GetAndCheckPars (&Games,&Match);
2020-10-13 22:34:31 +02:00
/***** Check if I can edit this match *****/
if (Mch_CheckIfICanEditThisMatch (&Match) == Usr_CAN_NOT)
Err_NoPermissionExit ();
2020-10-13 22:34:31 +02:00
/***** Show game *****/
Gam_ShowOnlyOneGame (&Games,
2020-10-13 22:34:31 +02:00
false, // Do not list game questions
Frm_PUT_FORM);
2020-10-13 22:34:31 +02:00
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
2019-09-29 17:33:39 +02:00
/*********************** Params used to edit a match *************************/
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
void Mch_PutParsEdit (void *Games)
2019-09-14 12:59:34 +02:00
{
2020-04-08 03:06:45 +02:00
if (Games)
2020-03-26 02:54:30 +01:00
{
Gam_PutPars (Games);
ParCod_PutPar (ParCod_Mch,((struct Gam_Games *) Games)->MchCod);
2020-03-26 02:54:30 +01:00
}
2019-09-29 22:38:32 +02:00
}
/*****************************************************************************/
/************************** Get and check parameters *************************/
/*****************************************************************************/
void Mch_GetAndCheckPars (struct Gam_Games *Games,
struct Mch_Match *Match)
2019-09-29 22:38:32 +02:00
{
/***** Get parameters *****/
/* Get parameters of game */
if ((Games->Game.GamCod = Gam_GetPars (Games)) <= 0)
Err_WrongGameExit ();
Grp_GetParWhichGroups ();
Gam_GetGameDataByCod (&Games->Game);
if (Games->Game.CrsCod != Gbl.Hierarchy.Node[Hie_CRS].HieCod)
Err_WrongGameExit ();
2020-11-25 01:50:13 +01:00
/* Get match code */
if ((Match->MchCod = ParCod_GetPar (ParCod_Mch)) > 0)
{
Mch_GetMatchDataByCod (Match);
if (Games->Game.GamCod != Match->GamCod)
Err_WrongGameExit ();
}
else
Mch_ResetMatch (Match);
2020-11-25 01:50:13 +01:00
/***** Initialize context *****/
Games->MchCod = Match->MchCod;
2019-09-29 22:38:32 +02:00
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
2020-11-25 01:50:13 +01:00
/******************* Put a form to change and existing match *****************/
/*****************************************************************************/
static void Mch_PutFormMatch (struct Mch_Match *Match)
2020-11-25 01:50:13 +01:00
{
extern const char *Hlp_ASSESSMENT_Games_matches;
extern const char *Txt_Title;
bool ItsANewMatch = (Match->MchCod <= 0);
2020-11-25 01:50:13 +01:00
/***** Begin section for match *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_Begin (Mch_NEW_MATCH_SECTION_ID);
2019-09-14 12:59:34 +02:00
/***** Begin form to create/edit *****/
Frm_BeginFormTable (ItsANewMatch ? ActNewMch :
ActChgMch,
Mch_NEW_MATCH_SECTION_ID,
Mch_ParsFormMatch,Match,"TBL_WIDE");
/***** Match title *****/
HTM_TR_Begin (NULL);
/* Label */
Frm_LabelColumn ("Frm_C1 RT","Title",Txt_Title);
/* Data */
HTM_TD_Begin ("class=\"Frm_C2 LT\"");
HTM_INPUT_TEXT ("Title",Mch_MAX_CHARS_TITLE,Match->Title,
HTM_DONT_SUBMIT_ON_CHANGE,
"id=\"Title\" class=\"Frm_C2_INPUT INPUT_%s\""
" required=\"required\"",
The_GetSuffix ());
HTM_TD_End ();
2019-09-14 12:59:34 +02:00
HTM_TR_End ();
2019-09-14 12:59:34 +02:00
/***** Groups *****/
Mch_ShowLstGrpsToEditMatch (Match->MchCod);
2019-09-14 12:59:34 +02:00
/***** End form to create *****/
Frm_EndFormTable (ItsANewMatch ? Btn_CREATE_BUTTON :
Btn_CONFIRM_BUTTON);
2019-09-14 12:59:34 +02:00
/***** End section for exam session *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_End ();
2019-09-14 12:59:34 +02:00
}
static void Mch_ParsFormMatch (void *Match)
{
ParCod_PutPar (ParCod_Gam,((struct Mch_Match *) Match)->GamCod);
ParCod_PutPar (ParCod_Mch,((struct Mch_Match *) Match)->MchCod);
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/***************** Show list of groups to create a new match *****************/
/*****************************************************************************/
2020-11-25 01:50:13 +01:00
static void Mch_ShowLstGrpsToEditMatch (long MchCod)
2019-09-14 12:59:34 +02:00
{
extern const char *Txt_Groups;
unsigned NumGrpTyp;
/***** Get list of groups types and groups in this course *****/
Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_ONLY_GROUP_TYPES_WITH_GROUPS);
if (Gbl.Crs.Grps.GrpTypes.NumGrpTypes)
2019-09-14 12:59:34 +02:00
{
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-09-14 12:59:34 +02:00
/* Label */
Frm_LabelColumn ("Frm_C1 RT","",Txt_Groups);
/* Groups */
HTM_TD_Begin ("class=\"Frm_C2 LT\"");
HTM_TABLE_Begin (NULL);
2019-12-26 22:29:04 +01:00
/***** First row: checkbox to select the whole course *****/
HTM_TR_Begin (NULL);
2019-10-07 17:36:41 +02:00
HTM_TD_Begin ("colspan=\"7\" class=\"LM DAT_%s\"",
The_GetSuffix ());
HTM_LABEL_Begin (NULL);
HTM_INPUT_CHECKBOX ("WholeCrs",HTM_DONT_SUBMIT_ON_CHANGE,
"id=\"WholeCrs\" value=\"Y\"%s"
" onclick=\"uncheckChildren(this,'GrpCods')\"",
Grp_DB_CheckIfAssociatedToGrps ("mch_groups",
"MchCod",
MchCod) ? "" :
" checked=\"checked\"");
Grp_WriteTheWholeCourse ();
HTM_LABEL_End ();
HTM_TD_End ();
2019-09-14 12:59:34 +02:00
HTM_TR_End ();
/***** List the groups for each group type *****/
for (NumGrpTyp = 0;
NumGrpTyp < Gbl.Crs.Grps.GrpTypes.NumGrpTypes;
NumGrpTyp++)
if (Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps)
Grp_ListGrpsToEditAsgAttSvyEvtMch (&Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp],
Grp_MATCH,MchCod);
HTM_TABLE_End ();
HTM_TD_End ();
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-09-14 12:59:34 +02:00
}
/***** Free list of groups types and groups in this course *****/
Grp_FreeListGrpTypesAndGrps ();
}
/*****************************************************************************/
/********************* Create a new match (by a teacher) *********************/
/*****************************************************************************/
2020-11-25 01:50:13 +01:00
void Mch_CreateNewMatch (void)
2019-09-14 12:59:34 +02:00
{
long GamCod;
2020-11-25 01:50:13 +01:00
char Title[Mch_MAX_BYTES_TITLE + 1];
2019-09-14 12:59:34 +02:00
/***** Get form parameters *****/
/* Get match code */
GamCod = ParCod_GetAndCheckPar (ParCod_Gam);
2019-09-14 12:59:34 +02:00
/* Get match title */
Par_GetParText ("Title",Title,Mch_MAX_BYTES_TITLE);
2019-09-14 12:59:34 +02:00
2020-11-25 01:50:13 +01:00
/* Get groups for this match */
2019-09-14 12:59:34 +02:00
Grp_GetParCodsSeveralGrps ();
/***** Create a new match *****/
2020-04-08 03:06:45 +02:00
Mch_SetMchCodBeingPlayed (Mch_CreateMatch (GamCod,Title));
2019-09-14 12:59:34 +02:00
/***** Free memory for list of selected groups *****/
Grp_FreeListCodSelectedGrps ();
}
2020-11-25 01:50:13 +01:00
/*****************************************************************************/
/************************ Change a match (by a teacher) **********************/
/*****************************************************************************/
void Mch_ChangeMatch (void)
{
struct Gam_Games Games;
struct Mch_Match Match;
/***** Reset games context *****/
Gam_ResetGames (&Games);
Gam_ResetGame (&Games.Game);
2020-11-25 01:50:13 +01:00
Mch_ResetMatch (&Match);
/***** Get and check parameters *****/
Mch_GetAndCheckPars (&Games,&Match);
2020-11-25 01:50:13 +01:00
/***** Check if I can update this match *****/
if (Mch_CheckIfICanEditThisMatch (&Match) == Usr_CAN_NOT)
Err_NoPermissionExit ();
2020-11-25 01:50:13 +01:00
/***** Get match title and groups *****/
/* Get match title */
Par_GetParText ("Title",Match.Title,Mch_MAX_BYTES_TITLE);
2020-11-25 01:50:13 +01:00
/* Get groups for this match */
Grp_GetParCodsSeveralGrps ();
/***** Update match *****/
Mch_UpdateMatchTitleAndGrps (&Match);
/***** Free memory for list of selected groups *****/
Grp_FreeListCodSelectedGrps ();
/***** Show current game *****/
Gam_ShowOnlyOneGame (&Games,
2020-11-25 01:50:13 +01:00
false, // Do not list game questions
Frm_DONT_PUT_FORM);
2020-11-25 01:50:13 +01:00
}
/*****************************************************************************/
/*************** Update title and groups of an existing match ****************/
/*****************************************************************************/
static void Mch_UpdateMatchTitleAndGrps (const struct Mch_Match *Match)
{
/***** Update match title into database *****/
Mch_DB_UpdateMatchTitle (Match->MchCod,Match->Title);
2020-11-25 01:50:13 +01:00
/***** Update groups associated to the match *****/
Mch_DB_RemoveMatchFromTable (Match->MchCod,"mch_groups"); // Remove all groups associated to this match
2020-11-25 01:50:13 +01:00
if (Gbl.Crs.Grps.LstGrpsSel.NumGrps)
Mch_CreateGrps (Match->MchCod); // Associate selected groups
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/******* Show button to actually start / resume a match (by a teacher) *******/
/*****************************************************************************/
2019-09-29 21:33:27 +02:00
void Mch_ResumeMatch (void)
2019-09-14 12:59:34 +02:00
{
2020-04-08 03:06:45 +02:00
struct Mch_Match Match;
2019-09-14 12:59:34 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset match *****/
Mch_ResetMatch (&Match);
2019-09-14 12:59:34 +02:00
/***** Remove old players.
2019-10-01 21:18:53 +02:00
This function must be called by a teacher
before getting match status. *****/
Mch_DB_RemoveOldPlaying ();
2019-09-14 12:59:34 +02:00
/***** Get data of the match from database *****/
2020-04-08 03:06:45 +02:00
Match.MchCod = Mch_GetMchCodBeingPlayed ();
Mch_GetMatchDataByCod (&Match);
2019-09-14 12:59:34 +02:00
2019-09-30 01:10:57 +02:00
/***** Check if I have permission to resume match *****/
if (Mch_CheckIfICanEditThisMatch (&Match) == Usr_CAN_NOT)
Err_NoPermissionExit ();
2019-09-30 01:10:57 +02:00
2019-09-14 12:59:34 +02:00
/***** Update match status in database *****/
Mch_UpdateMatchStatusInDB (&Match);
/***** Show current match status *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"match\" class=\"MCH_CONT\"");
Mch_ShowMatchStatusForTch (&Match);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/********************** Create a new match in a game *************************/
/*****************************************************************************/
2020-11-25 01:50:13 +01:00
static long Mch_CreateMatch (long GamCod,char Title[Mch_MAX_BYTES_TITLE + 1])
2019-09-14 12:59:34 +02:00
{
long MchCod;
/***** Insert this new match into database *****/
MchCod = Mch_DB_CreateMatch (GamCod,Title);
2019-09-14 12:59:34 +02:00
2019-09-23 21:39:54 +02:00
/***** Create indexes for answers *****/
Mch_CreateIndexes (GamCod,MchCod);
2019-09-14 12:59:34 +02:00
/***** Create groups associated to the match *****/
if (Gbl.Crs.Grps.LstGrpsSel.NumGrps)
Mch_CreateGrps (MchCod);
return MchCod;
}
2019-09-23 21:39:54 +02:00
/*****************************************************************************/
/*********************** Create indexes for a match **************************/
/*****************************************************************************/
/* Everytime a new match is created,
the answers of each shufflable question are shuffled.
The shuffling is stored in a table of indexes
that will be read when showing a match */
static void Mch_CreateIndexes (long GamCod,long MchCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumQsts;
unsigned NumQst;
struct Qst_Question Question;
2019-09-23 21:39:54 +02:00
unsigned QstInd;
/***** Get questions of the game *****/
NumQsts = Gam_DB_GetGameQuestionsFull (&mysql_res,GamCod);
2019-09-23 21:39:54 +02:00
/***** For each question in game... *****/
for (NumQst = 0;
NumQst < NumQsts;
NumQst++)
{
2020-03-25 01:36:22 +01:00
/***** Create test question *****/
Qst_QstConstructor (&Question);
2020-03-25 01:36:22 +01:00
2019-09-23 21:39:54 +02:00
/***** Get question data *****/
row = mysql_fetch_row (mysql_res);
2020-03-25 01:36:22 +01:00
/*
gam_questions.QstCod row[0]
gam_questions.QstInd row[1]
tst_questions.AnsType row[2]
tst_questions.Shuffle row[3]
*/
2019-09-23 21:39:54 +02:00
/* Get question code (row[0]) */
if ((Question.QstCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongQuestionExit ();
2019-09-23 21:39:54 +02:00
/* Get question index (row[1]) */
QstInd = Str_ConvertStrToUnsigned (row[1]);
2019-09-23 21:39:54 +02:00
/* Get answer type (row[2]) */
Question.Answer.Type = Qst_ConvertFromStrAnsTypDBToAnsTyp (row[2]);
if (Question.Answer.Type != Qst_ANS_UNIQUE_CHOICE)
Err_WrongAnswerExit ();
2019-09-23 21:39:54 +02:00
/* Get shuffle (row[3]) */
2020-04-03 19:13:00 +02:00
Question.Answer.Shuffle = (row[3][0] == 'Y');
2019-09-23 21:39:54 +02:00
/***** Reorder answer *****/
2020-03-25 01:36:22 +01:00
Mch_ReorderAnswer (MchCod,QstInd,&Question);
/***** Destroy test question *****/
Qst_QstDestructor (&Question);
2019-09-23 21:39:54 +02:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/******************* Reorder answers of a match question *********************/
/*****************************************************************************/
static void Mch_ReorderAnswer (long MchCod,unsigned QstInd,
const struct Qst_Question *Question)
2019-09-23 21:39:54 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumAnss;
unsigned NumAns;
unsigned AnsInd;
2019-11-08 01:10:32 +01:00
char StrOneAnswer[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
char StrAnswersOneQst[Qst_MAX_BYTES_ANSWERS_ONE_QST + 1];
2019-09-23 21:39:54 +02:00
/***** Initialize list of answers to empty string *****/
StrAnswersOneQst[0] = '\0';
/***** Get suffled/not-shuffled answers indexes of question *****/
NumAnss = Qst_DB_GetShuffledAnswersIndexes (&mysql_res,Question);
2019-09-23 21:39:54 +02:00
/***** For each answer in question... *****/
for (NumAns = 0;
NumAns < NumAnss;
NumAns++)
{
row = mysql_fetch_row (mysql_res);
/* Get answer index (row[0]) */
AnsInd = Str_ConvertStrToUnsigned (row[0]);
snprintf (StrOneAnswer,sizeof (StrOneAnswer),"%u",AnsInd);
2019-09-23 21:39:54 +02:00
/* Concatenate answer index to list of answers */
if (NumAns)
Str_Concat (StrAnswersOneQst,",",sizeof (StrAnswersOneQst) - 1);
Str_Concat (StrAnswersOneQst,StrOneAnswer,sizeof (StrAnswersOneQst) - 1);
2019-09-23 21:39:54 +02:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Create entry for this question in table of match indexes *****/
Mch_DB_CreateQstIndexes (MchCod,QstInd,StrAnswersOneQst);
2019-09-23 21:39:54 +02:00
}
2019-09-24 01:41:51 +02:00
/*****************************************************************************/
/***************** Get indexes for a question from database ******************/
/*****************************************************************************/
void Mch_GetIndexes (long MchCod,unsigned QstInd,
unsigned Indexes[Qst_MAX_OPTIONS_PER_QUESTION])
2019-09-24 01:41:51 +02:00
{
char StrIndexesOneQst[Qst_MAX_BYTES_INDEXES_ONE_QST + 1];
2019-09-24 01:41:51 +02:00
/***** Get indexes for a question from database *****/
Mch_DB_GetIndexes (MchCod,QstInd,StrIndexesOneQst);
if (!StrIndexesOneQst[0])
Err_WrongAnswerIndexExit ();
2019-09-24 01:41:51 +02:00
/***** Get indexes from string *****/
2020-05-07 18:33:26 +02:00
TstPrn_GetIndexesFromStr (StrIndexesOneQst,Indexes);
2019-09-24 01:41:51 +02:00
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/******************* Create groups associated to a match *********************/
/*****************************************************************************/
static void Mch_CreateGrps (long MchCod)
{
unsigned NumGrpSel;
for (NumGrpSel = 0;
NumGrpSel < Gbl.Crs.Grps.LstGrpsSel.NumGrps;
NumGrpSel++)
Mch_DB_AssociateGroupToMatch (MchCod,
Gbl.Crs.Grps.LstGrpsSel.GrpCods[NumGrpSel]);
2019-09-27 20:22:32 +02:00
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/***************** Insert/update a game match being played *******************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_UpdateMatchStatusInDB (const struct Mch_Match *Match)
2019-09-14 12:59:34 +02:00
{
/***** Update match status in database *****/
Mch_DB_UpdateMatchStatus (Match);
2019-09-14 12:59:34 +02:00
/***** Update match as being/not-being played */
2019-12-03 15:39:48 +01:00
if (Match->Status.Playing) // Match is being played
2019-09-14 12:59:34 +02:00
/* Update match as being played */
Mch_DB_UpdateMatchAsBeingPlayed (Match->MchCod);
2019-12-03 15:39:48 +01:00
else // Match is paused, not being played
2019-09-14 12:59:34 +02:00
/* Update match as not being played */
Mch_DB_RemoveMatchFromBeingPlayed (Match->MchCod);
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/********** Update elapsed time in current question (by a teacher) ***********/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_UpdateElapsedTimeInQuestion (const struct Mch_Match *Match)
2019-09-14 12:59:34 +02:00
{
/***** Update elapsed time in current question in database *****/
2019-12-03 15:39:48 +01:00
if (Match->Status.Playing && // Match is being played
2019-12-10 21:52:22 +01:00
Match->Status.Showing != Mch_START &&
Match->Status.Showing != Mch_END)
Mch_DB_UpdateElapsedTimeInQuestion (Match->MchCod,Match->Status.QstInd);
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/******************* Get elapsed time in a match question ********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_GetElapsedTimeInQuestion (const struct Mch_Match *Match,
struct Dat_Time *Time)
2019-09-14 12:59:34 +02:00
{
MYSQL_RES *mysql_res;
unsigned NumRows;
/***** Query database *****/
NumRows = Mch_DB_GetElapsedTimeInQuestion (&mysql_res,
Match->MchCod,
Match->Status.QstInd);
2019-09-14 12:59:34 +02:00
/***** Get elapsed time from query result *****/
Mch_GetElapsedTime (NumRows,mysql_res,Time);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/*********************** Get elapsed time in a match *************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_GetElapsedTimeInMatch (const struct Mch_Match *Match,
struct Dat_Time *Time)
2019-09-14 12:59:34 +02:00
{
MYSQL_RES *mysql_res;
unsigned NumRows;
/***** Query database *****/
NumRows = Mch_DB_GetElapsedTimeInMatch (&mysql_res,Match->MchCod);
2019-09-14 12:59:34 +02:00
/***** Get elapsed time from query result *****/
Mch_GetElapsedTime (NumRows,mysql_res,Time);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/*********************** Get elapsed time in a match *************************/
/*****************************************************************************/
static void Mch_GetElapsedTime (unsigned NumRows,MYSQL_RES *mysql_res,
struct Dat_Time *Time)
2019-09-14 12:59:34 +02:00
{
MYSQL_ROW row;
bool ElapsedTimeGotFromDB = false;
/***** Get time from H...H:MM:SS string *****/
if (NumRows)
{
row = mysql_fetch_row (mysql_res);
if (row[0])
/* Get the elapsed time (row[0]) */
if (sscanf (row[0],"%u:%02u:%02u",
&Time->Hour,
&Time->Minute,
&Time->Second) == 3)
2019-09-14 12:59:34 +02:00
ElapsedTimeGotFromDB = true;
}
/***** Initialize time to default value (0) *****/
if (!ElapsedTimeGotFromDB)
Time->Hour =
Time->Minute =
Time->Second = 0;
}
/*****************************************************************************/
2019-10-18 00:05:21 +02:00
/********************** Play/pause match (by a teacher) **********************/
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
2019-10-18 00:05:21 +02:00
void Mch_PlayPauseMatch (void)
2019-09-14 12:59:34 +02:00
{
2020-04-08 03:06:45 +02:00
struct Mch_Match Match;
2019-09-14 12:59:34 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset match *****/
Mch_ResetMatch (&Match);
2019-09-14 12:59:34 +02:00
/***** Remove old players.
2019-10-01 21:18:53 +02:00
This function must be called by a teacher
before getting match status. *****/
Mch_DB_RemoveOldPlaying ();
2019-09-14 12:59:34 +02:00
/***** Get data of the match from database *****/
2020-04-08 03:06:45 +02:00
Match.MchCod = Mch_GetMchCodBeingPlayed ();
Mch_GetMatchDataByCod (&Match);
2019-09-14 12:59:34 +02:00
2019-10-17 22:47:44 +02:00
/***** Update status *****/
2019-12-03 15:39:48 +01:00
if (Match.Status.Playing) // Match is being played ==> pause it
2019-12-10 21:52:22 +01:00
Match.Status.Playing = false; // Pause match
2019-12-03 15:39:48 +01:00
else // Match is paused, not being played ==> play it
2019-12-10 21:52:22 +01:00
/* If not over, update status */
if (Match.Status.Showing != Mch_END) // Match not over
Match.Status.Playing = true; // Start/resume match
2019-09-14 12:59:34 +02:00
/***** Update match status in database *****/
Mch_UpdateMatchStatusInDB (&Match);
/***** Show current match status *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"match\" class=\"MCH_CONT\"");
Mch_ShowMatchStatusForTch (&Match);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
}
2019-10-23 00:49:03 +02:00
/*****************************************************************************/
/******* Change number of columns in answers of a match (by a teacher) *******/
/*****************************************************************************/
void Mch_ChangeNumColsMch (void)
{
2020-04-08 03:06:45 +02:00
struct Mch_Match Match;
2019-10-23 00:49:03 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset match *****/
Mch_ResetMatch (&Match);
2019-10-23 00:49:03 +02:00
/***** Remove old players.
This function must be called by a teacher
before getting match status. *****/
Mch_DB_RemoveOldPlaying ();
2019-10-23 00:49:03 +02:00
/***** Get data of the match from database *****/
2020-04-08 03:06:45 +02:00
Match.MchCod = Mch_GetMchCodBeingPlayed ();
Mch_GetMatchDataByCod (&Match);
2019-10-23 00:49:03 +02:00
/***** Get number of columns *****/
Match.Status.NumCols = (unsigned)
Par_GetParUnsignedLong ("NumCols",
1,
Mch_MAX_COLS,
Mch_NUM_COLS_DEFAULT);
2019-10-23 00:49:03 +02:00
/***** Update match status in database *****/
Mch_UpdateMatchStatusInDB (&Match);
/***** Show current match status *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"match\" class=\"MCH_CONT\"");
Mch_ShowMatchStatusForTch (&Match);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-23 00:49:03 +02:00
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
2019-09-14 19:46:26 +02:00
/********* Toggle the display of results in a match (by a teacher) ***********/
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
2020-05-16 02:04:36 +02:00
void Mch_ToggleVisResultsMchQst (void)
2019-09-14 12:59:34 +02:00
{
2020-04-08 03:06:45 +02:00
struct Mch_Match Match;
2019-09-14 12:59:34 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset match *****/
Mch_ResetMatch (&Match);
2019-09-14 12:59:34 +02:00
/***** Remove old players.
2019-10-01 21:18:53 +02:00
This function must be called by a teacher
before getting match status. *****/
Mch_DB_RemoveOldPlaying ();
2019-09-14 12:59:34 +02:00
/***** Get data of the match from database *****/
2020-04-08 03:06:45 +02:00
Match.MchCod = Mch_GetMchCodBeingPlayed ();
Mch_GetMatchDataByCod (&Match);
2019-09-14 12:59:34 +02:00
/***** Update status *****/
2019-09-25 21:58:12 +02:00
Match.Status.ShowQstResults = !Match.Status.ShowQstResults; // Toggle display
if (Match.Status.Showing == Mch_RESULTS &&
!Match.Status.ShowQstResults)
2019-09-14 19:46:26 +02:00
Match.Status.Showing = Mch_ANSWERS; // Hide results
2019-09-14 12:59:34 +02:00
/***** Update match status in database *****/
Mch_UpdateMatchStatusInDB (&Match);
/***** Show current match status *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"match\" class=\"MCH_CONT\"");
Mch_ShowMatchStatusForTch (&Match);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/************* Show previous question in a match (by a teacher) **************/
/*****************************************************************************/
2019-09-29 21:33:27 +02:00
void Mch_BackMatch (void)
2019-09-14 12:59:34 +02:00
{
2020-04-08 03:06:45 +02:00
struct Mch_Match Match;
2019-09-14 12:59:34 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset match *****/
Mch_ResetMatch (&Match);
2019-09-14 12:59:34 +02:00
/***** Remove old players.
2019-10-01 21:18:53 +02:00
This function must be called by a teacher
before getting match status. *****/
Mch_DB_RemoveOldPlaying ();
2019-09-14 12:59:34 +02:00
/***** Get data of the match from database *****/
2020-04-08 03:06:45 +02:00
Match.MchCod = Mch_GetMchCodBeingPlayed ();
Mch_GetMatchDataByCod (&Match);
2019-09-14 12:59:34 +02:00
/***** Update status *****/
Mch_SetMatchStatusToPrev (&Match);
/***** Update match status in database *****/
Mch_UpdateMatchStatusInDB (&Match);
/***** Show current match status *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"match\" class=\"MCH_CONT\"");
Mch_ShowMatchStatusForTch (&Match);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/*************** Show next question in a match (by a teacher) ****************/
/*****************************************************************************/
2019-09-29 21:33:27 +02:00
void Mch_ForwardMatch (void)
2019-09-14 12:59:34 +02:00
{
2020-04-08 03:06:45 +02:00
struct Mch_Match Match;
2019-09-14 12:59:34 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset match *****/
Mch_ResetMatch (&Match);
2019-09-14 12:59:34 +02:00
/***** Remove old players.
2019-10-01 21:18:53 +02:00
This function must be called by a teacher
before getting match status. *****/
Mch_DB_RemoveOldPlaying ();
2019-09-14 12:59:34 +02:00
/***** Get data of the match from database *****/
2020-04-08 03:06:45 +02:00
Match.MchCod = Mch_GetMchCodBeingPlayed ();
Mch_GetMatchDataByCod (&Match);
2019-09-14 12:59:34 +02:00
/***** Update status *****/
Mch_SetMatchStatusToNext (&Match);
/***** Update match status in database *****/
Mch_UpdateMatchStatusInDB (&Match);
/***** Show current match status *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"match\" class=\"MCH_CONT\"");
Mch_ShowMatchStatusForTch (&Match);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/************** Set match status to previous (backward) status ***************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_SetMatchStatusToPrev (struct Mch_Match *Match)
2019-09-14 12:59:34 +02:00
{
/***** What to show *****/
2019-12-10 21:52:22 +01:00
switch (Match->Status.Showing)
{
case Mch_START:
Mch_SetMatchStatusToStart (Match);
break;
case Mch_STEM:
case Mch_END:
Mch_SetMatchStatusToPrevQst (Match);
break;
case Mch_ANSWERS:
Match->Status.Showing = Mch_STEM;
break;
case Mch_RESULTS:
Match->Status.Showing = Mch_ANSWERS;
break;
}
2020-06-23 12:57:31 +02:00
Match->Status.Countdown = -1L; // No countdown
/***** Force showing results to false when match is not at the end *****/
Match->Status.ShowUsrResults = false; // Force results to be hidden
2019-09-17 15:42:41 +02:00
}
2019-12-14 01:31:32 +01:00
/*****************************************************************************/
/****************** Set match status to previous question ********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_SetMatchStatusToPrevQst (struct Mch_Match *Match)
2019-09-17 15:42:41 +02:00
{
/***** Get index of the previous question *****/
Match->Status.QstInd = Gam_DB_GetPrevQuestionIndexInGame (Match->GamCod,
Match->Status.QstInd);
2019-12-10 21:52:22 +01:00
if (Match->Status.QstInd) // Start of questions not reached
2019-09-14 12:59:34 +02:00
{
Match->Status.QstCod = Gam_DB_GetQstCodFromQstInd (Match->GamCod,
Match->Status.QstInd);
2019-09-25 21:58:12 +02:00
Match->Status.Showing = Match->Status.ShowQstResults ? Mch_RESULTS :
Mch_ANSWERS;
2019-09-14 12:59:34 +02:00
}
2019-12-10 21:52:22 +01:00
else // Start of questions reached
Mch_SetMatchStatusToStart (Match);
2019-09-14 12:59:34 +02:00
}
2019-12-14 01:31:32 +01:00
/*****************************************************************************/
/************************ Set match status to start **************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_SetMatchStatusToStart (struct Mch_Match *Match)
2019-09-17 15:42:41 +02:00
{
Match->Status.QstInd = 0; // Before first question
Match->Status.QstCod = -1L;
Match->Status.Playing = false;
2019-12-10 21:52:22 +01:00
Match->Status.Showing = Mch_START;
2019-09-17 15:42:41 +02:00
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/**************** Set match status to next (forward) status ******************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_SetMatchStatusToNext (struct Mch_Match *Match)
2019-09-14 12:59:34 +02:00
{
/***** What to show *****/
2019-12-10 21:52:22 +01:00
switch (Match->Status.Showing)
{
case Mch_START:
Mch_SetMatchStatusToNextQst (Match);
break;
case Mch_STEM:
Match->Status.Showing = Mch_ANSWERS;
break;
case Mch_ANSWERS:
if (Match->Status.ShowQstResults)
Match->Status.Showing = Mch_RESULTS;
else
2019-09-17 15:42:41 +02:00
Mch_SetMatchStatusToNextQst (Match);
2019-12-10 21:52:22 +01:00
break;
case Mch_RESULTS:
Mch_SetMatchStatusToNextQst (Match);
break;
case Mch_END:
Mch_SetMatchStatusToEnd (Match);
break;
}
2019-12-12 18:24:23 +01:00
Match->Status.Countdown = -1L; // No countdown
2019-09-17 15:42:41 +02:00
}
2019-12-14 01:31:32 +01:00
/*****************************************************************************/
/****************** Set match status to next question ************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_SetMatchStatusToNextQst (struct Mch_Match *Match)
2019-09-17 15:42:41 +02:00
{
/***** Get index of the next question *****/
Match->Status.QstInd = Gam_DB_GetNextQuestionIndexInGame (Match->GamCod,
Match->Status.QstInd);
2019-09-17 15:42:41 +02:00
/***** Get question code *****/
if (Match->Status.QstInd < Gam_AFTER_LAST_QUESTION) // End of questions not reached
2019-09-17 15:42:41 +02:00
{
Match->Status.QstCod = Gam_DB_GetQstCodFromQstInd (Match->GamCod,
Match->Status.QstInd);
2019-09-17 15:42:41 +02:00
Match->Status.Showing = Mch_STEM;
2019-09-14 19:46:26 +02:00
}
2019-12-10 21:52:22 +01:00
else // End of questions reached
Mch_SetMatchStatusToEnd (Match);
2019-09-14 12:59:34 +02:00
}
2019-12-14 01:31:32 +01:00
/*****************************************************************************/
/************************* Set match status to end ***************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_SetMatchStatusToEnd (struct Mch_Match *Match)
2019-09-17 15:42:41 +02:00
{
Match->Status.QstInd = Gam_AFTER_LAST_QUESTION; // After last question
2019-09-17 15:42:41 +02:00
Match->Status.QstCod = -1L;
Match->Status.Playing = false;
2019-12-10 21:52:22 +01:00
Match->Status.Showing = Mch_END;
2019-09-17 15:42:41 +02:00
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/******* Show current match status (number, question, answers, button) *******/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_ShowMatchStatusForTch (struct Mch_Match *Match)
2019-09-14 12:59:34 +02:00
{
/***** Left column *****/
Mch_ShowLeftColumnTch (Match);
/***** Right column *****/
2019-09-26 18:19:07 +02:00
Mch_ShowRightColumnTch (Match);
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/************ Show current question being played for a student ***************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_ShowMatchStatusForStd (struct Mch_Match *Match,Mch_Update_t Update)
2019-09-14 12:59:34 +02:00
{
2019-12-03 02:46:46 +01:00
struct Mch_UsrAnswer UsrAnswer;
2019-09-14 12:59:34 +02:00
2019-09-29 19:36:32 +02:00
/***** Can I play this match? *****/
if (Mch_CheckIfICanPlayThisMatchBasedOnGrps (Match) == Usr_CAN_NOT)
Err_NoPermissionExit ();
2019-09-14 12:59:34 +02:00
2019-12-03 02:46:46 +01:00
/***** Get student's answer to this question
(<0 ==> no answer) *****/
Mch_GetQstAnsFromDB (Match->MchCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
Match->Status.QstInd,
&UsrAnswer);
2019-09-14 12:59:34 +02:00
/***** Left column *****/
2019-12-03 02:46:46 +01:00
Mch_ShowLeftColumnStd (Match,&UsrAnswer);
2019-09-14 12:59:34 +02:00
/***** Right column *****/
2019-12-03 02:46:46 +01:00
Mch_ShowRightColumnStd (Match,&UsrAnswer,Update);
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/************ Check if I belong to any of the groups of a match **************/
/*****************************************************************************/
Usr_Can_t Mch_CheckIfICanPlayThisMatchBasedOnGrps (const struct Mch_Match *Match)
2019-09-14 12:59:34 +02:00
{
2019-09-29 19:36:32 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_STD:
2019-12-05 19:54:28 +01:00
/***** Check if I belong to any of the groups
associated to the match *****/
return Mch_DB_CheckIfICanPlayThisMatchBasedOnGrps (Match->MchCod);
2019-09-29 19:36:32 +02:00
case Rol_NET:
2019-12-05 19:54:28 +01:00
/***** Only if I am the creator *****/
return (Match->UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) ? Usr_CAN :
Usr_CAN_NOT;
2019-09-29 19:36:32 +02:00
case Rol_TCH:
case Rol_SYS_ADM:
return Usr_CAN;
2019-09-29 19:36:32 +02:00
default:
return Usr_CAN_NOT;
2019-09-29 19:36:32 +02:00
}
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
2019-09-26 18:19:07 +02:00
/*********** Show left column when playing a match (as a teacher) ************/
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_ShowLeftColumnTch (struct Mch_Match *Match)
2019-09-26 19:54:09 +02:00
{
/***** Begin left container *****/
2020-03-12 13:53:37 +01:00
HTM_DIV_Begin ("class=\"MCH_LEFT_TCH\"");
2019-09-30 16:25:44 +02:00
/***** Refreshable part *****/
HTM_DIV_Begin ("id=\"match_left\" class=\"MCH_REFRESHABLE_TEACHER\"");
Mch_ShowRefreshablePartTch (Match);
HTM_DIV_End ();
2019-09-26 19:54:09 +02:00
/***** Put forms to start countdown *****/
Mch_PutFormsCountdown (Match);
2019-12-14 01:31:32 +01:00
/***** Buttons *****/
Mch_PutMatchControlButtons (Match);
2019-09-30 16:25:44 +02:00
/***** Put forms to choice which projects to show *****/
Set_BeginSettingsHead ();
Mch_ShowFormColumns (Match);
Set_EndSettingsHead ();
2019-10-22 20:43:03 +02:00
/***** Write button to request viewing results *****/
Mch_PutCheckboxResult (Match);
2019-09-26 19:54:09 +02:00
/***** End left container *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-26 19:54:09 +02:00
}
2019-12-14 01:31:32 +01:00
/*****************************************************************************/
/***************** Show left refreshable part for teachers *******************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_ShowRefreshablePartTch (struct Mch_Match *Match)
2019-09-14 12:59:34 +02:00
{
2019-12-12 09:14:26 +01:00
/***** Write elapsed time in match *****/
Mch_WriteElapsedTimeInMch (Match);
/***** Write number of question *****/
Mch_ShowNumQstInMch (Match);
/***** Write elapsed time in question *****/
Mch_WriteElapsedTimeInQst (Match);
/***** Number of users who have responded this question *****/
Mch_WriteNumRespondersQst (Match);
2019-12-14 01:31:32 +01:00
/***** Write hourglass *****/
Mch_PutCountdownAndHourglassIcon (Match);
2019-12-12 09:14:26 +01:00
}
2019-12-14 01:31:32 +01:00
/*****************************************************************************/
/******************** Write elapsed time in current match ********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_WriteElapsedTimeInMch (struct Mch_Match *Match)
2019-12-12 09:14:26 +01:00
{
struct Dat_Time Time;
2019-09-14 12:59:34 +02:00
2020-03-12 13:53:37 +01:00
HTM_DIV_Begin ("class=\"MCH_TOP CT\"");
2019-09-14 12:59:34 +02:00
/***** Get elapsed time in match *****/
Mch_GetElapsedTimeInMatch (Match,&Time);
2019-12-12 09:14:26 +01:00
/***** Write elapsed time in hh:mm'ss" format *****/
Dat_WriteHoursMinutesSeconds (&Time);
2019-09-14 12:59:34 +02:00
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-12-12 09:14:26 +01:00
}
2019-09-14 12:59:34 +02:00
2019-12-14 01:31:32 +01:00
/*****************************************************************************/
/****************** Write elapsed time in current question *******************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_WriteElapsedTimeInQst (struct Mch_Match *Match)
2019-12-12 09:14:26 +01:00
{
struct Dat_Time Time;
2019-09-14 12:59:34 +02:00
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"MCH_TIME_QST\"");
2019-12-12 09:14:26 +01:00
switch (Match->Status.Showing)
{
case Mch_START:
case Mch_END:
HTM_Hyphen (); // Do not write elapsed time
break;
default:
Mch_GetElapsedTimeInQuestion (Match,&Time);
Dat_WriteHoursMinutesSeconds (&Time);
break;
}
2019-12-12 09:14:26 +01:00
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-12-12 09:14:26 +01:00
}
2019-09-14 12:59:34 +02:00
2019-12-14 01:31:32 +01:00
/*****************************************************************************/
/*************** Write number of responders to a match question **************/
/*****************************************************************************/
2019-12-12 18:24:23 +01:00
2020-04-08 03:06:45 +02:00
static void Mch_WriteNumRespondersQst (struct Mch_Match *Match)
2019-12-13 23:38:29 +01:00
{
2019-12-14 01:31:32 +01:00
extern const char *Txt_MATCH_respond;
2019-12-13 23:38:29 +01:00
2019-12-14 01:31:32 +01:00
/***** Begin block *****/
HTM_DIV_Begin ("class=\"MCH_NUM_ANSWERERS\"");
2019-12-13 23:38:29 +01:00
HTM_Txt (Txt_MATCH_respond);
HTM_BR ();
HTM_STRONG_Begin ();
2019-12-12 18:24:23 +01:00
/***** Write number of responders *****/
switch (Match->Status.Showing)
{
case Mch_START:
case Mch_END:
HTM_Hyphen (); // Do not write number of responders
break;
default:
HTM_Unsigned (Mch_DB_GetNumUsrsWhoAnsweredQst (Match->MchCod,
Match->Status.QstInd));
break;
}
2019-12-12 18:24:23 +01:00
/***** Write number of players *****/
if (Match->Status.Playing) // Match is being played
{
/* Get current number of players */
Match->Status.NumPlayers = Mch_DB_GetNumPlayers (Match->MchCod);
/* Show current number of players */
HTM_TxtF ("/%u",Match->Status.NumPlayers);
}
HTM_STRONG_End ();
2019-12-12 18:24:23 +01:00
2019-12-14 01:31:32 +01:00
/***** End block *****/
2019-12-12 18:24:23 +01:00
HTM_DIV_End ();
}
2019-12-14 01:31:32 +01:00
/*****************************************************************************/
/*************** Write current countdown and hourglass icon ******************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_PutCountdownAndHourglassIcon (struct Mch_Match *Match)
2019-12-13 01:04:09 +01:00
{
extern const char *Txt_Countdown;
const char *Class;
const char *Icon;
/***** Set hourglass icon depending on countdown *****/
if (Match->Status.Showing == Mch_END) // Match over
{
Class = "BT_LINK_OFF MCH_BUTTON_HIDDEN MCH_GREEN";
Icon = "fa-hourglass-start";
}
else if (Match->Status.Countdown < 0) // No countdown
{
Class = "BT_LINK_OFF MCH_BUTTON_OFF MCH_GREEN";
Icon = "fa-hourglass-start";
}
else if (Match->Status.Countdown > Mch_COUNTDOWN_SECONDS_MEDIUM) // Countdown in progress
{
Class = "BT_LINK_OFF MCH_BUTTON_OFF MCH_LIMEGREEN";
Icon = "fa-hourglass-start";
}
else if (Match->Status.Countdown > Mch_COUNTDOWN_SECONDS_SMALL) // Countdown in progress
{
Class = "BT_LINK_OFF MCH_BUTTON_OFF MCH_YELLOW";
Icon = "fa-hourglass-half";
}
else // Countdown about to end
{
Class = "BT_LINK_OFF MCH_BUTTON_OFF MCH_RED";
Icon = "fa-hourglass-end";
}
2019-12-13 01:21:09 +01:00
/***** Write countdown and put hourglass icon *****/
2019-12-14 01:31:32 +01:00
HTM_DIV_Begin ("class=\"MCH_SHOW_HOURGLASS\"");
HTM_DIV_Begin ("class=\"MCH_BIGBUTTON_CONT\"");
HTM_BUTTON_Begin (Txt_Countdown,"class=\"%s\"",Class);
2019-12-13 01:21:09 +01:00
/* Countdown */
if (Match->Status.Countdown > 0)
HTM_TxtF ("&nbsp;%02ld&Prime;",Match->Status.Countdown);
else
HTM_NBSP ();
HTM_BR ();
2019-12-13 01:21:09 +01:00
/* Icon */
HTM_TxtF ("<i class=\"fas %s\"></i>",Icon);
2019-12-13 01:21:09 +01:00
HTM_BUTTON_End ();
HTM_DIV_End ();
2019-12-14 01:31:32 +01:00
HTM_DIV_End ();
2019-12-13 01:04:09 +01:00
}
/*****************************************************************************/
2019-12-14 01:31:32 +01:00
/******************** Put all forms to start countdowns **********************/
2019-12-13 01:04:09 +01:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_PutFormsCountdown (struct Mch_Match *Match)
2019-12-12 09:14:26 +01:00
{
/***** Begin container *****/
2019-12-14 01:31:32 +01:00
HTM_DIV_Begin ("class=\"MCH_SHOW_HOURGLASS\"");
2019-12-12 09:14:26 +01:00
/***** Put forms to start countdown *****/
Mch_PutFormCountdown (Match,-1 ,"MCH_GREEN" );
Mch_PutFormCountdown (Match,Mch_COUNTDOWN_SECONDS_LARGE ,"MCH_LIMEGREEN");
Mch_PutFormCountdown (Match,Mch_COUNTDOWN_SECONDS_MEDIUM,"MCH_YELLOW" );
Mch_PutFormCountdown (Match,Mch_COUNTDOWN_SECONDS_SMALL ,"MCH_RED" );
2019-12-12 09:14:26 +01:00
2019-12-14 01:31:32 +01:00
/***** End container *****/
HTM_DIV_End ();
}
/*****************************************************************************/
/****** Put a form to start a countdown with a given number of seconds *******/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_PutFormCountdown (struct Mch_Match *Match,long Seconds,const char *Color)
2019-12-14 01:31:32 +01:00
{
extern const char *Txt_Countdown;
static const char *fmt[Frm_NUM_PUT_FORM] =
{
[Frm_DONT_PUT_FORM] = "class=\"BT_LINK_OFF MCH_BUTTON_HIDDEN\"",
[Frm_PUT_FORM ] = "class=\"BT_LINK MCH_BUTTON_ON\"",
};
2019-12-14 01:31:32 +01:00
char *OnSubmit;
Frm_PutForm_t PutForm = (Match->Status.Showing != Mch_END) ? Frm_PUT_FORM :
Frm_DONT_PUT_FORM;
const char *Title[Frm_NUM_PUT_FORM] =
{
[Frm_DONT_PUT_FORM] = NULL,
[Frm_PUT_FORM ] = Txt_Countdown,
};
2019-12-14 01:31:32 +01:00
if (PutForm == Frm_PUT_FORM)
2019-12-12 09:14:26 +01:00
{
2020-05-11 02:28:38 +02:00
/***** Begin form *****/
2019-12-14 01:31:32 +01:00
if (asprintf (&OnSubmit,"updateMatchTch('match_left',"
"'act=%ld&ses=%s&MchCod=%ld&Countdown=%ld');"
" return false;", // return false is necessary to not submit form
Act_GetActCod (ActMchCntDwn),Gbl.Session.Id,
Match->MchCod,Seconds) < 0)
Err_NotEnoughMemoryExit ();
Frm_BeginFormOnSubmit (ActUnk,OnSubmit);
2019-12-14 01:31:32 +01:00
}
2019-09-30 14:55:55 +02:00
/***** Put icon *****/
HTM_DIV_Begin ("class=\"MCH_SMALLBUTTON_CONT %s\"",Color);
HTM_BUTTON_Submit_Begin (Title[PutForm],fmt[PutForm]);
HTM_NBSP ();
if (Seconds >= 0)
HTM_TxtF ("%ld&Prime;",Seconds);
else
{
HTM_Txt ("&infin;");
HTM_NBSP ();
}
2019-12-12 09:14:26 +01:00
HTM_BUTTON_End ();
2019-12-14 01:31:32 +01:00
HTM_DIV_End ();
2019-12-14 01:31:32 +01:00
/***** End form *****/
if (PutForm == Frm_PUT_FORM)
2019-12-14 01:31:32 +01:00
{
Frm_EndForm ();
free (OnSubmit);
}
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
2019-09-26 18:19:07 +02:00
/********** Show right column when playing a match (as a teacher) ************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_ShowRightColumnTch (const struct Mch_Match *Match)
2019-09-26 18:19:07 +02:00
{
/***** Begin right container *****/
2020-03-12 13:53:37 +01:00
HTM_DIV_Begin ("class=\"MCH_RIGHT_TCH\"");
2019-09-26 18:19:07 +02:00
/***** Top row: match title *****/
Mch_ShowMatchTitleTch (Match);
2019-09-26 18:19:07 +02:00
/***** Bottom row: current question and possible answers *****/
if (Match->Status.Showing == Mch_END) // Match over
Mch_ShowMatchScore (Match);
else // Match not over
Mch_ShowQuestionAndAnswersTch (Match);
2019-09-26 18:19:07 +02:00
/***** End right container *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-26 18:19:07 +02:00
}
/*****************************************************************************/
/*********** Show left column when playing a match (as a student) ************/
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_ShowLeftColumnStd (const struct Mch_Match *Match,
2019-12-03 02:46:46 +01:00
const struct Mch_UsrAnswer *UsrAnswer)
2019-09-14 12:59:34 +02:00
{
2019-12-03 02:46:46 +01:00
bool Answered = UsrAnswer->NumOpt >= 0;
/***** Begin left container *****/
2020-03-12 13:53:37 +01:00
HTM_DIV_Begin ("class=\"MCH_LEFT_STD\"");
2019-09-14 12:59:34 +02:00
/***** Top *****/
HTM_DIV_Begin ("class=\"MCH_TOP CT\"");
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
/***** Write number of question *****/
Mch_ShowNumQstInMch (Match);
2019-09-14 12:59:34 +02:00
switch (Match->Status.Showing)
{
case Mch_START:
case Mch_END:
break;
default:
/***** Write whether question is answered or not *****/
Mch_PutIfAnswered (Match,Answered);
if (Match->Status.Playing && // Match is being played
Match->Status.Showing == Mch_ANSWERS && // Teacher's screen is showing question answers
Answered) // I have answered this question
/***** Put icon to remove my answet *****/
Mch_PutIconToRemoveMyAnswer (Match);
break;
}
2019-12-03 02:46:46 +01:00
2019-09-14 12:59:34 +02:00
/***** End left container *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
}
2019-09-26 18:19:07 +02:00
/*****************************************************************************/
/********** Show right column when playing a match (as a student) ************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_ShowRightColumnStd (struct Mch_Match *Match,
2019-12-03 02:46:46 +01:00
const struct Mch_UsrAnswer *UsrAnswer,
Mch_Update_t Update)
2019-09-26 18:19:07 +02:00
{
extern const char *Txt_Please_wait_;
/***** Begin right container *****/
2020-03-12 13:53:37 +01:00
HTM_DIV_Begin ("class=\"MCH_RIGHT_STD\"");
2019-09-26 18:19:07 +02:00
/***** Top row *****/
Mch_ShowMatchTitleStd (Match);
2019-09-26 18:19:07 +02:00
/***** Bottom row *****/
if (Match->Status.Playing) // Match is being played
2019-09-29 21:33:27 +02:00
{
if (Match->Status.Showing == Mch_END) // Match over
Mch_ShowWaitImage (Txt_Please_wait_);
else // Match not over
2019-12-04 01:19:31 +01:00
{
HTM_DIV_Begin ("class=\"MCH_BOTTOM\"");
/***** Update players ******/
if (Mch_RegisterMeAsPlayerInMatch (Match))
{
if (Match->Status.Showing == Mch_ANSWERS) // Teacher's screen is showing question answers
/* Show current question and possible answers */
Mch_ShowQuestionAndAnswersStd (Match,UsrAnswer,Update);
}
else
Ale_ShowAlert (Ale_ERROR,"You can not join this match.");
HTM_DIV_End ();
2019-12-04 01:19:31 +01:00
}
2019-09-29 21:33:27 +02:00
}
else // Match is not being played
Mch_ShowWaitImage (Txt_Please_wait_);
2019-09-26 18:19:07 +02:00
/***** End right container *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-26 18:19:07 +02:00
}
2019-09-14 19:46:26 +02:00
/*****************************************************************************/
/********************* Show number of question in game ***********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_ShowNumQstInMch (const struct Mch_Match *Match)
2019-09-14 19:46:26 +02:00
{
extern const char *Txt_MATCH_Start;
extern const char *Txt_MATCH_End;
unsigned NumQsts = Gam_DB_GetNumQstsGame (Match->GamCod);
2019-09-14 19:46:26 +02:00
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"MCH_NUM_QST\"");
switch (Match->Status.Showing)
{
case Mch_START: // Not started
HTM_Txt (Txt_MATCH_Start);
break;
case Mch_END: // Match over
HTM_Txt (Txt_MATCH_End);
break;
default:
HTM_TxtF ("%u/%u",Match->Status.QstInd,NumQsts);
break;
}
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-14 19:46:26 +02:00
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/********************** Put buttons to control a match ***********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_PutMatchControlButtons (const struct Mch_Match *Match)
2019-09-14 12:59:34 +02:00
{
extern const char *Txt_Go_back;
extern const char *Txt_Go_forward;
extern const char *Txt_Pause;
extern const char *Txt_Start;
extern const char *Txt_Resume;
/***** Begin buttons container *****/
2019-12-13 00:36:01 +01:00
HTM_DIV_Begin ("class=\"MCH_BUTTONS_CONT\"");
2019-09-14 12:59:34 +02:00
/***** Left button *****/
HTM_DIV_Begin ("class=\"MCH_BUTTON_LEFT_CONT\"");
switch (Match->Status.Showing)
{
case Mch_START:
/* Put disabled button to go back.
Previously there was a button with a red cross
to close the browser tab using window.close,
but it no longer works in Firefox. */
Mch_PutBigButtonHidden (Mch_ICON_PREVIOUS);
break;
default:
/* Put button to go back */
Mch_PutBigButton (ActBckMch,"backward",Match->MchCod,
Mch_ICON_PREVIOUS,Txt_Go_back);
break;
}
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
/***** Center button *****/
HTM_DIV_Begin ("class=\"MCH_BUTTON_CENTER_CONT\"");
if (Match->Status.Playing) // Match is being played
/* Put button to pause match */
Mch_PutBigButton (ActPlyPauMch,"play_pause",Match->MchCod,
Mch_ICON_PAUSE,Txt_Pause);
else // Match is paused, not being played
{
switch (Match->Status.Showing)
{
case Mch_START: // Match just started, before first question
/* Put button to start playing match */
Mch_PutBigButton (ActPlyPauMch,"play_pause",Match->MchCod,
Mch_ICON_PLAY,Txt_Start);
break;
case Mch_END: // Match over
/* Put disabled button to play match */
Mch_PutBigButtonHidden (Mch_ICON_PLAY);
break;
default:
/* Put button to resume match */
Mch_PutBigButton (ActPlyPauMch,"play_pause",Match->MchCod,
Mch_ICON_PLAY,Txt_Resume);
}
}
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
/***** Right button *****/
HTM_DIV_Begin ("class=\"MCH_BUTTON_RIGHT_CONT\"");
switch (Match->Status.Showing)
{
case Mch_END: // Match over
/* Put disabled button to go forward.
Previously there was a button with a red cross
to close the browser tab using window.close,
but it no longer works in Firefox. */
Mch_PutBigButtonHidden (Mch_ICON_NEXT);
break;
default: // Match not over
/* Put button to show answers */
Mch_PutBigButton (ActFwdMch,"forward",Match->MchCod,
Mch_ICON_NEXT,Txt_Go_forward);
break;
}
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
/***** End buttons container *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
2019-10-22 22:39:37 +02:00
/** Show form to choice whether to show answers in one column or two columns */
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_ShowFormColumns (const struct Mch_Match *Match)
2019-10-22 22:39:37 +02:00
{
2019-10-22 23:42:22 +02:00
extern const char *Txt_column;
2019-10-22 22:39:37 +02:00
extern const char *Txt_columns;
char *Title;
2019-10-22 22:39:37 +02:00
unsigned NumCols;
2019-10-22 23:42:22 +02:00
static const char *NumColsIcon[1 + Mch_MAX_COLS] =
2019-10-22 22:39:37 +02:00
{
2019-10-23 02:18:24 +02:00
"", // Not used
"1col.png", // 1 column
"2col.png", // 2 columns
"3col.png", // 3 columns
"4col.png", // 4 columns
2019-10-22 22:39:37 +02:00
};
2019-10-22 23:42:22 +02:00
/***** Begin selector *****/
Set_BeginOneSettingSelector ();
2019-10-22 23:42:22 +02:00
for (NumCols = 1;
NumCols <= Mch_MAX_COLS;
2019-10-22 22:39:37 +02:00
NumCols++)
{
2019-12-30 20:41:40 +01:00
/* Begin container for this option */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"%s\"",
2020-03-12 13:53:37 +01:00
(Match->Status.NumCols == NumCols) ? "MCH_NUM_COL_ON" :
"MCH_NUM_COL_OFF");
2019-10-24 00:04:40 +02:00
/* Begin form */
Frm_BeginForm (ActChgNumColMch);
ParCod_PutPar (ParCod_Mch,Match->MchCod); // Current match being played
Mch_PutParNumCols (NumCols); // Number of columns
2019-10-22 22:39:37 +02:00
/* Number of columns */
if (asprintf (&Title,"%u %s",NumCols,
NumCols == 1 ? Txt_column :
Txt_columns) < 0)
Err_NotEnoughMemoryExit ();
Ico_PutSettingIconLink (NumColsIcon[NumCols],Ico_BLACK,Title);
free (Title);
2019-10-22 23:42:22 +02:00
/* End form */
Frm_EndForm ();
2019-10-22 23:42:22 +02:00
2019-12-30 20:41:40 +01:00
/* End container for this option */
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-22 22:39:37 +02:00
}
2019-10-22 23:42:22 +02:00
/***** End selector *****/
2019-10-22 22:39:37 +02:00
Set_EndOneSettingSelector ();
}
/*****************************************************************************/
2019-10-23 00:49:03 +02:00
/******** Write parameter with number of columns in answers of match *********/
2019-10-22 22:39:37 +02:00
/*****************************************************************************/
2019-09-14 19:46:26 +02:00
static void Mch_PutParNumCols (unsigned NumCols) // Number of columns
2019-10-23 00:49:03 +02:00
{
Par_PutParUnsigned (NULL,"NumCols",NumCols);
2019-10-23 00:49:03 +02:00
}
2019-09-14 19:46:26 +02:00
2019-10-31 08:47:16 +01:00
/*****************************************************************************/
/***************** Put checkbox to select if show results ********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_PutCheckboxResult (const struct Mch_Match *Match)
2019-10-31 08:47:16 +01:00
{
extern const char *Txt_View_results;
2019-12-12 18:24:23 +01:00
/***** Begin container *****/
HTM_DIV_Begin ("class=\"MCH_SHOW_RESULTS DAT_%s\"",
The_GetSuffix ());
2019-10-31 08:47:16 +01:00
/***** Begin form *****/
Frm_BeginForm (ActChgVisResMchQst);
ParCod_PutPar (ParCod_Mch,Match->MchCod); // Current match being played
2019-10-31 08:47:16 +01:00
/***** Put icon with link *****/
HTM_BUTTON_Submit_Begin (Txt_View_results,
"class=\"BT_LINK ICO_HIGHLIGHT\"");
HTM_TxtF ("<i class=\"%s\"></i>",
Match->Status.ShowQstResults ? "fas fa-toggle-on" :
"fas fa-toggle-off");
HTM_NBSPTxt (Txt_View_results);
HTM_BUTTON_End ();
2019-10-31 08:47:16 +01:00
/***** End form *****/
Frm_EndForm ();
2019-10-31 08:47:16 +01:00
/***** End container *****/
2019-11-04 22:42:03 +01:00
HTM_DIV_End ();
2019-10-31 08:47:16 +01:00
}
2019-10-22 20:43:03 +02:00
2019-12-03 02:46:46 +01:00
/*****************************************************************************/
/***************** Put checkbox to select if show results ********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_PutIfAnswered (const struct Mch_Match *Match,bool Answered)
2019-12-03 02:46:46 +01:00
{
2019-12-03 19:36:30 +01:00
extern const char *Txt_View_my_answer;
2019-12-04 01:19:31 +01:00
extern const char *Txt_MATCH_QUESTION_Answered;
extern const char *Txt_MATCH_QUESTION_Unanswered;
2019-12-03 02:46:46 +01:00
/***** Begin container *****/
2019-12-12 18:24:23 +01:00
HTM_DIV_Begin ("class=\"MCH_SHOW_ANSWERED\"");
2019-12-03 02:46:46 +01:00
/***** Put icon with link *****/
if (Match->Status.Playing && // Match is being played
Match->Status.Showing == Mch_ANSWERS && // Teacher's screen is showing question answers
Answered) // I have answered this question
{
/* Begin form */
Frm_BeginForm (ActSeeMchAnsQstStd);
ParCod_PutPar (ParCod_Mch,Match->MchCod); // Current match being played
2019-12-03 02:46:46 +01:00
HTM_BUTTON_Submit_Begin (Txt_View_my_answer,
"class=\"BT_LINK DAT_SMALL_GREEN_%s\""
" onmousedown=\"this.form.submit();return false;\"",
The_GetSuffix ());
HTM_TxtF ("<i class=\"%s\"></i>","fas fa-check-circle");
HTM_NBSPTxt (Txt_MATCH_QUESTION_Answered);
HTM_BUTTON_End ();
2019-12-03 02:46:46 +01:00
/* End form */
Frm_EndForm ();
}
else
{
HTM_DIV_Begin ("class=\"%s_%s\"",Answered ? "DAT_SMALL_GREEN" :
"DAT_SMALL_RED",
The_GetSuffix ());
HTM_TxtF ("<i class=\"%s\" title=\"%s\"></i>",
Answered ? "fas fa-check-circle" :
"fas fa-exclamation-circle",
Answered ? Txt_MATCH_QUESTION_Answered :
Txt_MATCH_QUESTION_Unanswered);
HTM_NBSPTxt (Answered ? Txt_MATCH_QUESTION_Answered :
Txt_MATCH_QUESTION_Unanswered);
HTM_DIV_End ();
}
2019-12-03 02:46:46 +01:00
/***** End container *****/
HTM_DIV_End ();
}
/*****************************************************************************/
/******************** Put checkbox to remove my answer ***********************/
2019-12-03 02:46:46 +01:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_PutIconToRemoveMyAnswer (const struct Mch_Match *Match)
2019-12-03 02:46:46 +01:00
{
2019-12-04 01:19:31 +01:00
extern const char *Txt_Delete_my_answer;
2019-12-03 02:46:46 +01:00
2020-05-11 02:28:38 +02:00
/***** Begin container *****/
2019-12-12 18:24:23 +01:00
HTM_DIV_Begin ("class=\"MCH_REM_MY_ANS\"");
2019-12-03 02:46:46 +01:00
/***** Begin form *****/
Frm_BeginForm (ActRemMchAnsQstStd);
ParCod_PutPar (ParCod_Mch,Match->MchCod); // Current match being played
Gam_PutParQstInd (Match->Status.QstInd); // Current question index shown
2019-12-03 02:46:46 +01:00
/***** Put icon with link *****/
HTM_DIV_Begin ("class=\"MCH_BIGBUTTON_CONT\"");
HTM_BUTTON_Submit_Begin (Txt_Delete_my_answer,
"BT_LINK MCH_BUTTON_ON ICO_DARKRED\""
" onmousedown=\"this.form.submit();return false;\"");
HTM_Txt ("<i class=\"fas fa-trash\"></i>");
HTM_BUTTON_End ();
HTM_DIV_End ();
2019-12-03 02:46:46 +01:00
/***** End form *****/
Frm_EndForm ();
2019-12-03 02:46:46 +01:00
/***** End container *****/
HTM_DIV_End ();
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/***************************** Show match title ******************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_ShowMatchTitleTch (const struct Mch_Match *Match)
2019-09-14 12:59:34 +02:00
{
/***** Match title *****/
2020-03-12 13:53:37 +01:00
HTM_DIV_Begin ("class=\"MCH_TOP LT\"");
HTM_Txt (Match->Title);
2020-03-12 13:53:37 +01:00
HTM_DIV_End ();
}
2020-04-08 03:06:45 +02:00
static void Mch_ShowMatchTitleStd (const struct Mch_Match *Match)
2020-03-12 13:53:37 +01:00
{
/***** Match title *****/
HTM_DIV_Begin ("class=\"MCH_TOP CT\"");
HTM_Txt (Match->Title);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/***** Show question and its answers when playing a match (as a teacher) *****/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_ShowQuestionAndAnswersTch (const struct Mch_Match *Match)
2019-09-14 12:59:34 +02:00
{
extern const char *Txt_MATCH_Paused;
2020-03-07 00:14:35 +01:00
extern const char *Txt_Question_removed;
struct Qst_Question Question;
2020-03-27 21:54:13 +01:00
/***** Create test question *****/
Qst_QstConstructor (&Question);
2020-03-27 21:54:13 +01:00
Question.QstCod = Match->Status.QstCod;
2019-09-14 12:59:34 +02:00
2019-12-12 09:14:26 +01:00
/***** Trivial check: do not show anything on match start and end *****/
switch (Match->Status.Showing)
{
case Mch_START:
case Mch_END:
return;
default:
break;
}
2019-09-14 12:59:34 +02:00
/***** Get data of question from database *****/
if (Qst_GetQstDataByCod (&Question))
2020-03-07 00:14:35 +01:00
{
/***** Show question *****/
2020-04-04 02:07:54 +02:00
/* Check answer type */
if (Question.Answer.Type != Qst_ANS_UNIQUE_CHOICE)
Err_WrongAnswerExit ();
2019-09-14 12:59:34 +02:00
2020-03-07 00:14:35 +01:00
/* Begin container */
HTM_DIV_Begin ("class=\"MCH_BOTTOM\""); // Bottom
2019-09-14 12:59:34 +02:00
/* Write stem */
Qst_WriteQstStem (Question.Stem,"MCH_TCH_STEM",
true); // Visible
2019-09-14 12:59:34 +02:00
/* Show media */
Med_ShowMedia (&Question.Media,
"Tst_MED_EDIT_LIST_CONT",
"Tst_MED_EDIT_LIST");
2019-09-14 12:59:34 +02:00
/***** Write answers? *****/
switch (Match->Status.Showing)
{
case Mch_ANSWERS:
if (Match->Status.Playing) // Match is being played
/* Write answers */
Mch_WriteAnswersMatchResult (Match,
&Question,
"MCH_TCH_ANS",
false); // Don't show result
else // Match is paused, not being played
Mch_ShowWaitImage (Txt_MATCH_Paused);
break;
case Mch_RESULTS:
/* Write answers with results */
2020-03-07 00:14:35 +01:00
Mch_WriteAnswersMatchResult (Match,
&Question,
2020-03-07 00:14:35 +01:00
"MCH_TCH_ANS",
true); // Show result
break;
default:
/* Don't write anything */
break;
}
2019-09-14 12:59:34 +02:00
2020-03-07 00:14:35 +01:00
/* End container */
HTM_DIV_End (); // Bottom
}
else
Ale_ShowAlert (Ale_WARNING,Txt_Question_removed);
2020-03-27 21:54:13 +01:00
/***** Destroy test question *****/
Qst_QstDestructor (&Question);
2019-09-14 12:59:34 +02:00
}
2019-10-23 01:30:11 +02:00
/*****************************************************************************/
2020-03-30 18:54:17 +02:00
/************* Write answers of a question when seeing a match ***************/
2019-10-23 01:30:11 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Mch_WriteAnswersMatchResult (const struct Mch_Match *Match,
struct Qst_Question *Question,
2020-03-27 21:54:13 +01:00
const char *Class,bool ShowResult)
2019-10-23 01:30:11 +02:00
{
/***** Write answer depending on type *****/
if (Question->Answer.Type == Qst_ANS_UNIQUE_CHOICE)
2020-03-27 22:02:01 +01:00
Mch_WriteChoiceAnsViewMatch (Match,
2020-03-27 21:54:13 +01:00
Question,
Class,ShowResult);
2019-10-23 01:30:11 +02:00
else
Err_WrongAnswerTypeExit ();
2019-10-23 01:30:11 +02:00
}
2020-03-27 22:02:01 +01:00
/*****************************************************************************/
2020-03-30 18:54:17 +02:00
/******** Write single or multiple choice answer when seeing a match *********/
2020-03-27 22:02:01 +01:00
/*****************************************************************************/
2020-08-28 14:45:30 +02:00
static void Mch_WriteChoiceAnsViewMatch (const struct Mch_Match *Match,
struct Qst_Question *Question,
2020-08-28 14:45:30 +02:00
const char *Class,bool ShowResult)
2020-03-27 22:02:01 +01:00
{
unsigned NumOpt;
bool RowIsOpen = false;
unsigned NumRespondersQst;
unsigned NumRespondersAns;
unsigned Indexes[Qst_MAX_OPTIONS_PER_QUESTION]; // Indexes of all answers of this question
2020-03-27 22:02:01 +01:00
/***** Get number of users who have answered this question from database *****/
NumRespondersQst = Mch_DB_GetNumUsrsWhoAnsweredQst (Match->MchCod,Match->Status.QstInd);
2020-03-27 22:02:01 +01:00
2020-06-17 02:31:42 +02:00
/***** Change format of answers text *****/
Qst_ChangeFormatAnswersText (Question);
2020-06-17 02:31:42 +02:00
2020-03-27 22:02:01 +01:00
/***** Get indexes for this question in match *****/
Mch_GetIndexes (Match->MchCod,Match->Status.QstInd,Indexes);
/***** Begin table *****/
HTM_TABLE_BeginWidePadding (0);
/***** Show options distributed in columns *****/
for (NumOpt = 0;
NumOpt < Question->Answer.NumOptions;
NumOpt++)
2020-03-27 22:02:01 +01:00
{
/***** Begin row? *****/
if (NumOpt % Match->Status.NumCols == 0)
{
HTM_TR_Begin (NULL);
RowIsOpen = true;
}
2020-03-27 22:02:01 +01:00
/***** Write letter for this option *****/
HTM_TD_Begin ("class=\"MCH_TCH_BUTTON_TD\"");
HTM_DIV_Begin ("class=\"MCH_TCH_BUTTON BT_%c\"",'A' + (char) NumOpt);
HTM_TxtF ("%c",'a' + (char) NumOpt);
HTM_DIV_End ();
HTM_TD_End ();
/***** Write the option text and the result *****/
HTM_TD_Begin ("class=\"LT\"");
HTM_LABEL_Begin ("for=\"Ans%06u_%u\" class=\"%s\"",Match->Status.QstInd,NumOpt,Class);
HTM_Txt (Question->Answer.Options[Indexes[NumOpt]].Text);
HTM_LABEL_End ();
Med_ShowMedia (&Question->Answer.Options[Indexes[NumOpt]].Media,
"Tst_MED_SHOW_CONT",
"Tst_MED_SHOW");
/* Show result (number of users who answered? */
if (ShowResult)
{
/* Get number of users who selected this answer */
NumRespondersAns = Mch_DB_GetNumUsrsWhoHaveChosenAns (Match->MchCod,Match->Status.QstInd,Indexes[NumOpt]);
/* Draw proportional bar for this answer */
Mch_DrawBarNumUsrs (NumRespondersAns,NumRespondersQst,
Question->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
HTM_TD_End ();
/***** End row? *****/
if (NumOpt % Match->Status.NumCols == Match->Status.NumCols - 1)
{
HTM_TR_End ();
RowIsOpen = false;
}
2020-03-27 22:02:01 +01:00
}
/***** End row? *****/
if (RowIsOpen)
HTM_TR_End ();
2020-03-27 22:02:01 +01:00
/***** End table *****/
HTM_TABLE_End ();
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/***** Show question and its answers when playing a match (as a student) *****/
/*****************************************************************************/
static void Mch_ShowQuestionAndAnswersStd (const struct Mch_Match *Match,
2019-12-03 02:46:46 +01:00
const struct Mch_UsrAnswer *UsrAnswer,
Mch_Update_t Update)
2019-09-14 12:59:34 +02:00
{
unsigned NumOptions;
unsigned NumOpt;
2019-12-04 22:22:42 +01:00
/***** Get number of options in this question *****/
NumOptions = Qst_DB_GetNumAnswersQst (Match->Status.QstCod);
2019-12-04 22:22:42 +01:00
/***** Begin table *****/
HTM_TABLE_BeginWidePadding (8);
for (NumOpt = 0;
NumOpt < NumOptions;
NumOpt++)
{
/***** Begin row *****/
HTM_TR_Begin (NULL);
2019-12-04 22:22:42 +01:00
/***** Write letter for this option *****/
/* Begin table cell */
HTM_TD_Begin ("class=\"MCH_STD_CELL\"");
/* Form with button.
Sumitting onmousedown instead of default onclick
is necessary in order to be fast
and not lose clicks due to refresh */
Frm_BeginForm (ActAnsMchQstStd);
ParCod_PutPar (ParCod_Mch,Match->MchCod); // Current match being played
Gam_PutParQstInd (Match->Status.QstInd); // Current question index shown
Mch_PutParNumOpt (NumOpt); // Number of button
HTM_BUTTON_Submit_Begin (NULL,
"class=\"MCH_STD_BUTTON%s BT_%c\""
" onmousedown=\"this.form.submit();return false;\"",
UsrAnswer->NumOpt == (int) NumOpt && // Student's answer
Update == Mch_CHANGE_STATUS_BY_STUDENT ? " MCH_STD_ANSWER_SELECTED" :
"",
'A' + (char) NumOpt);
HTM_TxtF ("%c",'a' + (char) NumOpt);
HTM_BUTTON_End ();
Frm_EndForm ();
/* End table cell */
HTM_TD_End ();
/***** End row *****/
HTM_TR_End ();
}
2019-12-04 22:22:42 +01:00
/***** End table *****/
HTM_TABLE_End ();
2019-09-14 12:59:34 +02:00
}
2019-10-01 01:01:35 +02:00
/*****************************************************************************/
2019-10-21 13:36:28 +02:00
/***************************** Show match scores *****************************/
2019-10-01 01:01:35 +02:00
/*****************************************************************************/
2019-10-21 21:36:31 +02:00
#define Mch_NUM_ROWS_SCORE 50
2019-10-21 13:36:28 +02:00
2020-04-08 03:06:45 +02:00
static void Mch_ShowMatchScore (const struct Mch_Match *Match)
2019-10-01 01:01:35 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2019-10-21 13:36:28 +02:00
unsigned NumScores;
unsigned NumScore;
double MinScore;
double MaxScore;
double Range;
double NumRowsPerScorePoint;
double Score;
unsigned MaxUsrs;
2019-10-21 13:36:28 +02:00
unsigned NumUsrs;
unsigned NumRowForThisScore;
2019-10-01 01:01:35 +02:00
unsigned NumRow;
2019-10-21 13:36:28 +02:00
/***** Get minimum and maximum scores *****/
Gam_GetScoreRange (Match->GamCod,&MinScore,&MaxScore);
Range = MaxScore - MinScore;
if (Range == 0.0)
return;
2019-10-21 13:36:28 +02:00
NumRowsPerScorePoint = (double) Mch_NUM_ROWS_SCORE / Range;
/***** Get maximum number of users *****/
MaxUsrs = Mch_DB_GetMaxUsrsPerScore (Match->MchCod);
2019-10-21 13:36:28 +02:00
/***** Get scores from database *****/
NumScores = Mch_DB_GetNumUsrsPerScore (&mysql_res,Match->MchCod);
2019-10-21 13:36:28 +02:00
/***** Begin table ****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWide ();
2019-10-21 13:36:28 +02:00
/***** Get and draw scores *****/
for (NumScore = 0, NumRow = 0;
NumScore < NumScores;
NumScore++)
{
/***** Get score and number of users from database *****/
row = mysql_fetch_row (mysql_res);
/* Get score (row[0]) */
Str_SetDecimalPointToUS (); // To get the decimal point as a dot
if (sscanf (row[0],"%lf",&Score) != 1)
Score = 0.0;
Str_SetDecimalPointToLocal (); // Return to local system
/* Get number of users (row[1]) *****/
if (sscanf (row[1],"%u",&NumUsrs) != 1)
NumUsrs = 0;
/***** Draw empty rows until reaching the adequate row *****/
NumRowForThisScore = (unsigned) ((MaxScore - Score) * NumRowsPerScorePoint);
if (NumRowForThisScore == Mch_NUM_ROWS_SCORE)
NumRowForThisScore = Mch_NUM_ROWS_SCORE - 1;
for (;
NumRow < NumRowForThisScore;
NumRow++)
Mch_DrawEmptyScoreRow (NumRow,MinScore,MaxScore);
/***** Draw row for this score *****/
Mch_DrawScoreRow (Score,MinScore,MaxScore,NumRow,NumUsrs,MaxUsrs);
NumRow++;
}
2019-10-21 13:36:28 +02:00
/***** Draw final empty rows *****/
2019-10-21 13:36:28 +02:00
for (;
NumRow < Mch_NUM_ROWS_SCORE;
2019-10-21 13:36:28 +02:00
NumRow++)
Mch_DrawEmptyScoreRow (NumRow,MinScore,MaxScore);
2019-10-01 01:01:35 +02:00
2019-10-21 13:36:28 +02:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2019-10-21 13:36:28 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2019-12-14 01:31:32 +01:00
/*****************************************************************************/
/*************************** Draw empty score row ****************************/
/*****************************************************************************/
static void Mch_DrawEmptyScoreRow (unsigned NumRow,double MinScore,double MaxScore)
2019-10-21 13:36:28 +02:00
{
/***** Draw row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-21 13:36:28 +02:00
/* Write score */
HTM_TD_Begin ("class=\"MCH_SCO_SCO\"");
if (NumRow == 0)
{
HTM_DoubleFewDigits (MaxScore);
HTM_NBSP ();
}
else if (NumRow == Mch_NUM_ROWS_SCORE - 1)
{
HTM_DoubleFewDigits (MinScore);
HTM_NBSP ();
}
HTM_TD_End ();
2019-10-01 01:01:35 +02:00
/* Empty column with bar and number of users */
HTM_TD_Begin ("class=\"MCH_SCO_NUM%s\"",Mch_GetClassBorder (NumRow));
HTM_TD_End ();
2019-10-21 13:36:28 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-10-21 13:36:28 +02:00
}
2019-10-01 01:01:35 +02:00
2019-12-14 01:31:32 +01:00
/*****************************************************************************/
/******************************* Draw score row ******************************/
/*****************************************************************************/
2019-10-21 15:07:00 +02:00
static void Mch_DrawScoreRow (double Score,double MinScore,double MaxScore,
2019-10-21 21:36:31 +02:00
unsigned NumRow,unsigned NumUsrs,unsigned MaxUsrs)
2019-10-21 13:36:28 +02:00
{
2019-10-21 21:36:31 +02:00
extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
extern const char *Txt_ROLES_PLURAL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2019-10-21 15:07:00 +02:00
unsigned Color;
2019-10-21 13:36:28 +02:00
unsigned BarWidth;
2019-10-30 23:55:49 +01:00
char *Icon;
char *Title;
2019-10-01 01:01:35 +02:00
2019-10-21 15:07:00 +02:00
/***** Compute color *****/
/*
+----------------- MaxScore
| score9_1x1.png
+-----------------
| score8_1x1.png
+-----------------
| score7_1x1.png
+-----------------
| score6_1x1.png
+-----------------
| score5_1x1.png
+-----------------
| score4_1x1.png
+-----------------
| score3_1x1.png
+-----------------
| score2_1x1.png
+-----------------
| score1_1x1.png
+-----------------
| score0_1x1.png
+----------------- MinScore
*/
Color = (unsigned) (((Score - MinScore) / (MaxScore - MinScore)) * 10.0);
2019-10-21 16:43:18 +02:00
if (Color == 10)
2019-10-21 15:07:00 +02:00
Color = 9;
2019-10-21 13:36:28 +02:00
/***** Compute bar width *****/
if (MaxUsrs > 0)
2019-10-01 01:01:35 +02:00
{
2019-10-21 13:36:28 +02:00
BarWidth = (unsigned) (((NumUsrs * 95.0) / MaxUsrs) + 0.5);
if (BarWidth == 0)
BarWidth = 1;
2019-10-01 01:01:35 +02:00
}
2019-10-21 13:36:28 +02:00
else
BarWidth = 0;
2019-10-01 01:01:35 +02:00
2019-10-21 13:36:28 +02:00
/***** Draw row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-01 01:01:35 +02:00
/* Write score */
HTM_TD_Begin ("class=\"MCH_SCO_SCO\"");
HTM_DoubleFewDigits (Score);
HTM_NBSP ();
HTM_TD_End ();
2019-10-21 13:36:28 +02:00
/* Draw bar and write number of users for this score */
HTM_TD_Begin ("class=\"MCH_SCO_NUM%s\"",Mch_GetClassBorder (NumRow));
if (asprintf (&Icon,"score%u_1x1.png",Color) < 0) // Background
Err_NotEnoughMemoryExit ();
if (asprintf (&Title,"%u %s",NumUsrs,
NumUsrs == 1 ? Txt_ROLES_SINGUL_abc[Rol_STD][Usr_SEX_UNKNOWN] :
Txt_ROLES_PLURAL_abc[Rol_STD][Usr_SEX_UNKNOWN]) < 0)
Err_NotEnoughMemoryExit ();
HTM_IMG (Cfg_URL_ICON_PUBLIC,Icon,Title,
"class=\"MCH_SCO_BAR\" style=\"width:%u%%;\"",BarWidth);
free (Title);
free (Icon);
HTM_TxtF ("&nbsp;%u",NumUsrs);
HTM_TD_End ();
2019-10-21 13:36:28 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-10-01 01:01:35 +02:00
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
2019-09-24 01:41:51 +02:00
/****** Write parameter with number of option (button) pressed by user *******/
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
2019-10-21 21:36:31 +02:00
static const char *Mch_GetClassBorder (unsigned NumRow)
{
return NumRow == 0 ? " MCH_SCO_TOP" :
(NumRow == Mch_NUM_ROWS_SCORE - 1 ? " MCH_SCO_BOT" :
" MCH_SCO_MID");
}
/*****************************************************************************/
/****** Write parameter with number of option (button) pressed by user *******/
/*****************************************************************************/
static void Mch_PutParNumOpt (unsigned NumOpt)
2019-09-14 12:59:34 +02:00
{
Par_PutParUnsigned (NULL,"NumOpt",NumOpt);
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
2019-09-24 01:41:51 +02:00
/******* Get parameter with number of option (button) pressed by user ********/
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
static unsigned Mch_GetParNumOpt (void)
2019-09-14 12:59:34 +02:00
{
2019-09-24 01:41:51 +02:00
long NumOpt;
2019-09-14 12:59:34 +02:00
NumOpt = Par_GetParLong ("NumOpt");
2019-09-24 01:41:51 +02:00
if (NumOpt < 0)
Err_WrongAnswerExit ();
2019-09-14 12:59:34 +02:00
2019-09-24 01:41:51 +02:00
return (unsigned) NumOpt;
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/*********************** Put a big button to do action ***********************/
/*****************************************************************************/
static void Mch_PutBigButton (Act_Action_t NextAction,const char *Id,
2019-10-17 22:47:44 +02:00
long MchCod,const char *Icon,const char *Txt)
2019-09-14 12:59:34 +02:00
{
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
Frm_BeginFormId (NextAction,Id);
ParCod_PutPar (ParCod_Mch,MchCod);
2019-09-14 12:59:34 +02:00
/***** Put icon with link *****/
HTM_DIV_Begin ("class=\"MCH_BIGBUTTON_CONT\"");
HTM_BUTTON_Submit_Begin (Txt,
"class=\"BT_LINK MCH_BUTTON_ON ICO_BLACK_%s\"",
The_GetSuffix ());
HTM_TxtF ("<i class=\"%s\"></i>",Icon);
HTM_BUTTON_End ();
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
/***** End form *****/
Frm_EndForm ();
}
2019-12-14 01:31:32 +01:00
/*****************************************************************************/
/************************** Put a big button hidden **************************/
/*****************************************************************************/
2019-12-13 00:36:01 +01:00
static void Mch_PutBigButtonHidden (const char *Icon)
2019-09-14 12:59:34 +02:00
{
/***** Put inactive icon *****/
2019-12-13 00:36:01 +01:00
HTM_DIV_Begin ("class=\"MCH_BIGBUTTON_CONT\"");
HTM_BUTTON_Begin (NULL,"class=\"BT_LINK_OFF MCH_BUTTON_HIDDEN ICO_BLACK_%s\"",
The_GetSuffix ());
HTM_TxtF ("<i class=\"%s\"></i>",Icon);
HTM_BUTTON_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
}
2019-12-14 01:31:32 +01:00
/*****************************************************************************/
/********************** Put a big button to close window *********************/
/*****************************************************************************/
/*
2019-09-14 12:59:34 +02:00
static void Mch_PutBigButtonClose (void)
{
extern const char *Txt_Close;
***** Put icon with link *****
2019-12-13 00:36:01 +01:00
HTM_DIV_Begin ("class=\"MCH_BIGBUTTON_CONT\"");
HTM_BUTTON_Begin (Txt_Close,
"class=\"BT_LINK MCH_BUTTON_ON ICO_DARKRED\""
" onclick=\"window.close();return false;\"");
HTM_TxtF ("<i class=\"%s\"></i>",Mch_ICON_CLOSE);
HTM_BUTTON_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
}
*/
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/****************************** Show wait image ******************************/
/*****************************************************************************/
static void Mch_ShowWaitImage (const char *Txt)
{
2019-12-13 00:36:01 +01:00
HTM_DIV_Begin ("class=\"MCH_WAIT_CONT\"");
Ico_PutIcon ("Spin-1s-200px.gif",Ico_UNCHANGED,Txt,"MCH_WAIT_IMG");
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
}
2019-12-02 09:57:17 +01:00
/*****************************************************************************/
/******************* Register me as a player in a match **********************/
/*****************************************************************************/
// Return true on success
2020-04-08 03:06:45 +02:00
bool Mch_RegisterMeAsPlayerInMatch (struct Mch_Match *Match)
2019-12-02 09:57:17 +01:00
{
/***** Trivial check: match code must be > 0 *****/
if (Match->MchCod <= 0)
return false;
/***** Trivial check: match must be being played *****/
2019-12-03 15:39:48 +01:00
if (!Match->Status.Playing) // Match is paused, not being played
2019-12-02 09:57:17 +01:00
return false;
/***** Trivial check: match must not be over *****/
2019-12-10 21:52:22 +01:00
if (Match->Status.Showing == Mch_END) // Match over
2019-12-02 09:57:17 +01:00
return false;
/***** Trivial check: only a student can join a match *****/
if (Gbl.Usrs.Me.Role.Logged != Rol_STD) // I am not logged as student
return false;
/***** Insert me as match player *****/
Mch_DB_RegisterMeAsPlayerInMatch (Match->MchCod);
2019-12-02 09:57:17 +01:00
return true;
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/********************** Get code of match being played ***********************/
/*****************************************************************************/
void Mch_GetMatchBeingPlayed (void)
{
2020-04-08 03:06:45 +02:00
long MchCodBeingPlayed;
2019-09-14 12:59:34 +02:00
/***** Get match code ****/
MchCodBeingPlayed = ParCod_GetAndCheckPar (ParCod_Mch);
2020-04-08 03:06:45 +02:00
Mch_SetMchCodBeingPlayed (MchCodBeingPlayed);
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
2019-12-03 02:46:46 +01:00
/********************* Show match being played as student ********************/
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
2019-09-29 21:33:27 +02:00
void Mch_JoinMatchAsStd (void)
2019-09-14 12:59:34 +02:00
{
2020-04-08 03:06:45 +02:00
struct Mch_Match Match;
2019-09-14 12:59:34 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset match *****/
Mch_ResetMatch (&Match);
2019-09-14 12:59:34 +02:00
/***** Get data of the match from database *****/
2020-04-08 03:06:45 +02:00
Match.MchCod = Mch_GetMchCodBeingPlayed ();
Mch_GetMatchDataByCod (&Match);
2019-09-14 12:59:34 +02:00
/***** Show current match status *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"match\" class=\"MCH_CONT\"");
Mch_ShowMatchStatusForStd (&Match,Mch_CHANGE_STATUS_BY_STUDENT);
2019-12-03 02:46:46 +01:00
HTM_DIV_End ();
}
/*****************************************************************************/
/****** Remove student's answer to a question and show match as student ******/
/*****************************************************************************/
2020-08-26 12:06:25 +02:00
void Mch_RemMyQstAnsAndShowMchStatus (void)
2019-12-03 02:46:46 +01:00
{
2020-04-08 03:06:45 +02:00
struct Mch_Match Match;
2019-12-03 02:46:46 +01:00
unsigned QstInd;
2020-04-23 23:09:28 +02:00
/***** Reset match *****/
Mch_ResetMatch (&Match);
2019-12-03 02:46:46 +01:00
/***** Get data of the match from database *****/
2020-04-08 03:06:45 +02:00
Match.MchCod = Mch_GetMchCodBeingPlayed ();
Mch_GetMatchDataByCod (&Match);
2019-12-03 02:46:46 +01:00
/***** Get question index from form *****/
QstInd = Gam_GetParQstInd ();
2019-12-03 02:46:46 +01:00
2020-08-26 12:06:25 +02:00
/***** Remove my answer to this question *****/
Mch_RemoveMyQuestionAnswer (&Match,QstInd);
/***** Show current match status *****/
HTM_DIV_Begin ("id=\"match\" class=\"MCH_CONT\"");
Mch_ShowMatchStatusForStd (&Match,Mch_CHANGE_STATUS_BY_STUDENT);
2020-08-26 12:06:25 +02:00
HTM_DIV_End ();
}
/*****************************************************************************/
/******************** Remove student's answer to a question ******************/
/*****************************************************************************/
void Mch_RemoveMyQuestionAnswer (const struct Mch_Match *Match,unsigned QstInd)
{
2019-12-03 02:46:46 +01:00
/***** Check that teacher's screen is showing answers
and question index is the current one being played *****/
2020-08-26 12:06:25 +02:00
if (Match->Status.Playing && // Match is being played
Match->Status.Showing == Mch_ANSWERS && // Teacher's screen is showing answers
QstInd == Match->Status.QstInd) // Removing answer to the current question being played
2020-05-18 14:34:31 +02:00
{
/***** Remove my answer to this question *****/
Mch_DB_RemoveMyAnswerToMatchQuestion (Match);
2019-12-03 02:46:46 +01:00
2020-05-18 14:34:31 +02:00
/***** Compute score and update my match result *****/
2020-08-26 12:06:25 +02:00
MchPrn_ComputeScoreAndUpdateMyMatchPrintInDB (Match->MchCod);
2020-05-18 14:34:31 +02:00
}
2019-09-14 12:59:34 +02:00
}
2019-12-13 23:38:29 +01:00
/*****************************************************************************/
/******************** Start match countdown (by a teacher) *******************/
/*****************************************************************************/
void Mch_StartCountdown (void)
{
2020-04-08 03:06:45 +02:00
struct Mch_Match Match;
2019-12-13 23:38:29 +01:00
long NewCountdown;
2020-04-23 23:09:28 +02:00
/***** Reset match *****/
Mch_ResetMatch (&Match);
2019-12-13 23:38:29 +01:00
/***** Get countdown parameter ****/
NewCountdown = Par_GetParLong ("Countdown");
2019-12-13 23:38:29 +01:00
/***** Remove old players.
This function must be called by a teacher
before getting match status. *****/
Mch_DB_RemoveOldPlaying ();
2019-12-13 23:38:29 +01:00
/***** Get data of the match from database *****/
2020-04-08 03:06:45 +02:00
Match.MchCod = Mch_GetMchCodBeingPlayed ();
Mch_GetMatchDataByCod (&Match);
2019-12-13 23:38:29 +01:00
/***** Start countdown *****/
Match.Status.Countdown = NewCountdown;
/***** Update match status in database *****/
Mch_UpdateMatchStatusInDB (&Match);
/***** Show current match status *****/
Mch_ShowRefreshablePartTch (&Match);
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/****************** Refresh match for a teacher via AJAX *********************/
/*****************************************************************************/
void Mch_RefreshMatchTch (void)
{
2020-04-08 03:06:45 +02:00
struct Mch_Match Match;
2019-12-12 18:24:23 +01:00
enum {REFRESH_LEFT,REFRESH_ALL} WhatToRefresh;
2019-09-14 12:59:34 +02:00
if (!Gbl.Session.IsOpen) // If session has been closed, do not write anything
return;
2020-04-23 23:09:28 +02:00
/***** Reset match *****/
Mch_ResetMatch (&Match);
2019-09-14 12:59:34 +02:00
/***** Remove old players.
2019-10-01 21:18:53 +02:00
This function must be called by a teacher
before getting match status. *****/
Mch_DB_RemoveOldPlaying ();
2019-09-14 12:59:34 +02:00
/***** Get data of the match from database *****/
2020-04-08 03:06:45 +02:00
Match.MchCod = Mch_GetMchCodBeingPlayed ();
Mch_GetMatchDataByCod (&Match);
2019-09-14 12:59:34 +02:00
2019-12-12 18:24:23 +01:00
/***** Update countdown *****/
// If current countdown is < 0 ==> no countdown in progress
WhatToRefresh = REFRESH_LEFT;
if (Match.Status.Playing && // Match is being played
Match.Status.Countdown >= 0) // Countdown in progress
{
/* Decrease countdown */
Match.Status.Countdown -= Cfg_SECONDS_TO_REFRESH_MATCH_TCH;
/* On countdown reached, set match status to next (forward) status */
if (Match.Status.Countdown <= 0) // End of countdown reached
{
Mch_SetMatchStatusToNext (&Match);
WhatToRefresh = REFRESH_ALL; // Refresh the whole page
}
}
2019-09-14 12:59:34 +02:00
/***** Update match status in database *****/
Mch_UpdateMatchStatusInDB (&Match);
/***** Update elapsed time in this question *****/
Mch_UpdateElapsedTimeInQuestion (&Match);
/***** Show current match status *****/
2019-12-12 18:24:23 +01:00
switch (WhatToRefresh)
{
case REFRESH_LEFT: // Refresh only left part
2019-12-14 01:31:32 +01:00
HTM_Txt ("match_left|0|"); // 0 ==> do not evaluate MatJax scripts after updating HTML
2019-12-12 18:24:23 +01:00
Mch_ShowRefreshablePartTch (&Match);
break;
case REFRESH_ALL: // Refresh the whole page
2019-12-14 01:31:32 +01:00
HTM_Txt ("match|1|"); // 1 ==> evaluate MatJax scripts after updating HTML
2019-12-12 18:24:23 +01:00
Mch_ShowMatchStatusForTch (&Match);
break;
}
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/*************** Refresh current game for a student via AJAX *****************/
/*****************************************************************************/
void Mch_RefreshMatchStd (void)
{
2020-04-08 03:06:45 +02:00
struct Mch_Match Match;
2019-09-14 12:59:34 +02:00
if (!Gbl.Session.IsOpen) // If session has been closed, do not write anything
return;
2020-04-23 23:09:28 +02:00
/***** Reset match *****/
Mch_ResetMatch (&Match);
2019-09-14 12:59:34 +02:00
/***** Get data of the match from database *****/
2020-04-08 03:06:45 +02:00
Match.MchCod = Mch_GetMchCodBeingPlayed ();
Mch_GetMatchDataByCod (&Match);
2019-09-14 12:59:34 +02:00
/***** Show current match status *****/
2019-12-03 02:46:46 +01:00
Mch_ShowMatchStatusForStd (&Match,Mch_REFRESH_STATUS_BY_SERVER);
2019-09-14 12:59:34 +02:00
}
/*****************************************************************************/
/**** Receive previous question answer in a match question from database *****/
/*****************************************************************************/
2019-09-28 02:31:42 +02:00
void Mch_GetQstAnsFromDB (long MchCod,long UsrCod,unsigned QstInd,
struct Mch_UsrAnswer *UsrAnswer)
2019-09-14 12:59:34 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2019-09-24 01:41:51 +02:00
/***** Set default values for number of option and answer index *****/
UsrAnswer->NumOpt = -1; // < 0 ==> no answer selected
UsrAnswer->AnsInd = -1; // < 0 ==> no answer selected
2019-09-14 12:59:34 +02:00
/***** Get student's answer *****/
if (Mch_DB_GetUsrAnsToQst (&mysql_res,MchCod,UsrCod,QstInd)) // Answer found...
2019-09-14 12:59:34 +02:00
{
row = mysql_fetch_row (mysql_res);
2019-09-24 01:41:51 +02:00
/***** Get number of option index (row[0]) *****/
if (sscanf (row[0],"%d",&(UsrAnswer->NumOpt)) != 1)
Err_WrongAnswerExit ();
2019-09-24 01:41:51 +02:00
/***** Get answer index (row[1]) *****/
if (sscanf (row[1],"%d",&(UsrAnswer->AnsInd)) != 1)
Err_WrongAnswerIndexExit ();
2019-09-14 12:59:34 +02:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/********* Receive question answer from student when playing a match *********/
/*****************************************************************************/
2019-09-29 21:33:27 +02:00
void Mch_ReceiveQuestionAnswer (void)
2019-09-14 12:59:34 +02:00
{
2020-04-08 03:06:45 +02:00
struct Mch_Match Match;
2020-08-22 13:05:15 +02:00
unsigned QstInd; // 0 means that the game has not started. First question has index 1.
2019-09-24 01:41:51 +02:00
struct Mch_UsrAnswer UsrAnswer;
2019-09-14 12:59:34 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset match *****/
Mch_ResetMatch (&Match);
2019-09-14 12:59:34 +02:00
/***** Get data of the match from database *****/
2020-04-08 03:06:45 +02:00
Match.MchCod = Mch_GetMchCodBeingPlayed ();
Mch_GetMatchDataByCod (&Match);
2019-09-14 12:59:34 +02:00
/***** Get question index from form *****/
QstInd = Gam_GetParQstInd ();
2019-09-14 12:59:34 +02:00
2020-08-22 13:05:15 +02:00
/***** Get number of option selected by student from form *****/
UsrAnswer.NumOpt = Mch_GetParNumOpt ();
2020-08-22 13:05:15 +02:00
/***** Store answer *****/
Mch_StoreQuestionAnswer (&Match,QstInd,&UsrAnswer);
/***** Show current match status *****/
HTM_DIV_Begin ("id=\"match\" class=\"MCH_CONT\"");
Mch_ShowMatchStatusForStd (&Match,Mch_CHANGE_STATUS_BY_STUDENT);
2020-08-22 13:05:15 +02:00
HTM_DIV_End ();
}
/*****************************************************************************/
/********** Store question answer from student when playing a match **********/
/*****************************************************************************/
2020-08-26 12:06:25 +02:00
void Mch_StoreQuestionAnswer (const struct Mch_Match *Match,unsigned QstInd,
2020-08-22 13:05:15 +02:00
struct Mch_UsrAnswer *UsrAnswer)
{
unsigned Indexes[Qst_MAX_OPTIONS_PER_QUESTION];
2020-08-22 13:05:15 +02:00
struct Mch_UsrAnswer PreviousUsrAnswer;
2019-10-01 23:05:07 +02:00
/***** Check that teacher's screen is showing answers
and question index is the current one being played *****/
2020-08-22 13:05:15 +02:00
if (Match->Status.Playing && // Match is being played
Match->Status.Showing == Mch_ANSWERS && // Teacher's screen is showing answers
QstInd == Match->Status.QstInd) // Receiving an answer to the current question being played
2019-09-14 12:59:34 +02:00
{
2019-12-03 02:46:46 +01:00
/***** Get indexes for this question from database *****/
2020-08-22 13:05:15 +02:00
Mch_GetIndexes (Match->MchCod,Match->Status.QstInd,Indexes);
2019-12-03 02:46:46 +01:00
2019-09-14 12:59:34 +02:00
/***** Get answer index *****/
2019-09-24 01:41:51 +02:00
/*
Indexes[4] = {0,3,1,2}
2020-05-18 14:34:31 +02:00
+--------+--------+----------+---------+
2019-09-24 01:41:51 +02:00
| Button | Option | Answer | Correct |
| letter | number | index | |
| screen | screen | database | |
+--------+--------+----------+---------+
| a | 0 | 0 | |
| b | 1 | 3 | |
| c | 2 | 1 | Y | <---- User press button #2 (index = 1, correct)
| d | 3 | 2 | |
+--------+--------+----------+---------+
2020-08-22 13:05:15 +02:00
UsrAnswer->NumOpt = 2
UsrAnswer->AnsInd = 1
2019-09-24 01:41:51 +02:00
*/
2020-08-22 13:05:15 +02:00
UsrAnswer->AnsInd = Indexes[UsrAnswer->NumOpt];
2019-09-14 12:59:34 +02:00
/***** Get previous student's answer to this question
(<0 ==> no answer) *****/
2020-08-22 13:05:15 +02:00
Mch_GetQstAnsFromDB (Match->MchCod,Gbl.Usrs.Me.UsrDat.UsrCod,Match->Status.QstInd,
2019-09-24 01:41:51 +02:00
&PreviousUsrAnswer);
2019-09-14 12:59:34 +02:00
/***** Store student's answer *****/
2020-08-22 13:05:15 +02:00
if (UsrAnswer->NumOpt >= 0 &&
UsrAnswer->AnsInd >= 0 &&
UsrAnswer->AnsInd != PreviousUsrAnswer.AnsInd)
2020-05-18 14:34:31 +02:00
{
/***** Update my answer to this question *****/
Mch_DB_UpdateMyAnswerToMatchQuestion (Match,UsrAnswer);
2020-05-18 14:34:31 +02:00
/***** Compute score and update my match result *****/
2020-08-22 13:05:15 +02:00
MchPrn_ComputeScoreAndUpdateMyMatchPrintInDB (Match->MchCod);
2020-05-18 14:34:31 +02:00
}
2019-09-14 12:59:34 +02:00
}
}
2020-05-18 14:34:31 +02:00
/*****************************************************************************/
/*************** Get the questions of a match from database ******************/
/*****************************************************************************/
2020-06-24 20:10:57 +02:00
void Mch_GetMatchQuestionsFromDB (struct MchPrn_Print *Print)
2020-05-18 14:34:31 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumQst;
unsigned QstInd;
struct Mch_UsrAnswer UsrAnswer;
/***** Get questions and answers of a match result *****/
Print->NumQsts.All = Mch_DB_GetMatchQuestions (&mysql_res,Print->MchCod);
2020-06-24 02:15:50 +02:00
for (NumQst = 0, Print->NumQsts.NotBlank = 0;
NumQst < Print->NumQsts.All;
2020-05-18 14:34:31 +02:00
NumQst++)
{
row = mysql_fetch_row (mysql_res);
/* Get question code (row[0]) */
if ((Print->PrintedQuestions[NumQst].QstCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongQuestionExit ();
2020-05-18 14:34:31 +02:00
/* Get question index (row[1]) */
QstInd = Str_ConvertStrToUnsigned (row[1]);
2020-05-18 14:34:31 +02:00
/* Get indexes for this question (row[2]) */
Str_Copy (Print->PrintedQuestions[NumQst].StrIndexes,row[2],
sizeof (Print->PrintedQuestions[NumQst].StrIndexes) - 1);
2020-05-18 14:34:31 +02:00
/* Get answers selected by user for this question */
2020-06-24 20:10:57 +02:00
Mch_GetQstAnsFromDB (Print->MchCod,Print->UsrCod,QstInd,&UsrAnswer);
2020-05-18 14:34:31 +02:00
if (UsrAnswer.AnsInd >= 0) // UsrAnswer.AnsInd >= 0 ==> answer selected
{
snprintf (Print->PrintedQuestions[NumQst].StrAnswers,
sizeof (Print->PrintedQuestions[NumQst].StrAnswers),
"%d",UsrAnswer.AnsInd);
2020-06-24 02:15:50 +02:00
Print->NumQsts.NotBlank++;
2020-05-18 14:34:31 +02:00
}
else // UsrAnswer.AnsInd < 0 ==> no answer selected
Print->PrintedQuestions[NumQst].StrAnswers[0] = '\0'; // Empty answer
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2019-09-14 12:59:34 +02:00
/*****************************************************************************/
/***************** Draw a bar with the percentage of answers *****************/
/*****************************************************************************/
2019-09-16 00:15:40 +02:00
#define Mch_MAX_BAR_WIDTH 100
2019-09-14 12:59:34 +02:00
2020-03-12 13:53:37 +01:00
void Mch_DrawBarNumUsrs (unsigned NumRespondersAns,unsigned NumRespondersQst,bool Correct)
2019-09-14 12:59:34 +02:00
{
extern const char *Txt_of_PART_OF_A_TOTAL;
2019-09-16 00:15:40 +02:00
unsigned i;
2019-09-14 12:59:34 +02:00
unsigned BarWidth = 0;
/***** Begin container *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"MCH_RESULT\"");
2019-09-14 12:59:34 +02:00
/***** Draw bar with a with proportional to the number of clicks *****/
if (NumRespondersAns && NumRespondersQst)
BarWidth = (unsigned) ((((double) NumRespondersAns * (double) Mch_MAX_BAR_WIDTH) /
(double) NumRespondersQst) + 0.5);
/***** Bar proportional to number of users *****/
HTM_TABLE_BeginWide ();
HTM_TR_Begin ("class=\"MCH_RES_TR\"");
for (i = 0;
i < 100;
i++)
{
HTM_TD_Begin ("class=\"%s\"",
(i < BarWidth) ? (Correct ? "MCH_RES_CORRECT" :
"MCH_RES_WRONG") :
"MCH_RES_VOID");
HTM_TD_End ();
}
HTM_TR_End ();
HTM_TABLE_End ();
/***** Write the number of users *****/
if (NumRespondersAns && NumRespondersQst)
HTM_TxtF ("%u&nbsp;(%u%%&nbsp;%s&nbsp;%u)",
NumRespondersAns,
(unsigned) ((((double) NumRespondersAns * 100.0) / (double) NumRespondersQst) + 0.5),
Txt_of_PART_OF_A_TOTAL,NumRespondersQst);
else
HTM_NBSP ();
2019-09-16 00:15:40 +02:00
/***** End container *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-09-14 12:59:34 +02:00
}