swad-core/swad_match_result.c

1406 lines
45 KiB
C
Raw Normal View History

2019-09-28 02:31:42 +02:00
// swad_match_result.c: matches results 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.
2021-02-09 12:43:45 +01:00
Copyright (C) 1999-2021 Antonio Ca<EFBFBD>as Vargas
2019-09-28 02:31:42 +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-28 02:31:42 +02:00
#include <stdio.h> // For asprintf
#include <stdlib.h> // For free
2019-09-28 02:31:42 +02:00
#include <string.h> // For string functions
2019-09-30 01:23:24 +02:00
#include "swad_action.h"
2019-09-28 02:31:42 +02:00
#include "swad_database.h"
2019-09-30 01:23:24 +02:00
#include "swad_date.h"
#include "swad_error.h"
2019-09-28 02:31:42 +02:00
#include "swad_form.h"
#include "swad_global.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2019-09-28 02:31:42 +02:00
#include "swad_ID.h"
#include "swad_match.h"
#include "swad_match_result.h"
2020-04-14 17:15:17 +02:00
#include "swad_photo.h"
2020-02-18 09:19:33 +01:00
#include "swad_test_visibility.h"
2019-09-28 02:31:42 +02:00
#include "swad_user.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
2020-06-23 11:48:06 +02:00
struct MchRes_ICanView
{
bool Result;
bool Score;
};
2019-09-28 02:31:42 +02:00
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void MchRes_PutFormToSelUsrsToViewMchResults (void *Games);
static void MchRes_ListMyMchResultsInCrs (struct Gam_Games *Games);
static void MchRes_ListMyMchResultsInGam (struct Gam_Games *Games,long GamCod);
static void MchRes_ListMyMchResultsInMch (struct Gam_Games *Games,long MchCod);
static void MchRes_ShowAllMchResultsInSelectedGames (void *Games);
static void MchRes_ListAllMchResultsInSelectedGames (struct Gam_Games *Games);
static void MchRes_ListAllMchResultsInGam (struct Gam_Games *Games,long GamCod);
static void MchRes_ListAllMchResultsInMch (struct Gam_Games *Games,long MchCod);
static void MchRes_ShowResultsBegin (struct Gam_Games *Games,
const char *Title,bool ListGamesToSelect);
2020-04-02 03:28:08 +02:00
static void MchRes_ShowResultsEnd (void);
2020-04-08 03:06:45 +02:00
static void MchRes_ListGamesToSelect (struct Gam_Games *Games);
2020-04-02 03:28:08 +02:00
static void MchRes_ShowHeaderMchResults (Usr_MeOrOther_t MeOrOther);
2020-04-08 03:06:45 +02:00
static void MchRes_BuildGamesSelectedCommas (struct Gam_Games *Games,
char **GamesSelectedCommas);
static void MchRes_ShowMchResults (struct Gam_Games *Games,
Usr_MeOrOther_t MeOrOther,
long MchCod, // <= 0 ==> any
long GamCod, // <= 0 ==> any
const char *GamesSelectedCommas);
2020-04-02 03:28:08 +02:00
static void MchRes_ShowMchResultsSummaryRow (unsigned NumResults,
2020-06-24 20:10:57 +02:00
struct MchPrn_NumQuestions *NumTotalQsts,
double TotalScore,
2020-04-08 03:06:45 +02:00
double TotalGrade);
2020-06-24 20:10:57 +02:00
2020-06-23 11:48:06 +02:00
static void MchRes_CheckIfICanSeeMatchResult (const struct Gam_Game *Game,
const struct Mch_Match *Match,
long UsrCod,
struct MchRes_ICanView *ICanView);
2019-09-28 02:31:42 +02:00
2019-12-08 13:34:12 +01:00
/*****************************************************************************/
/*************************** Show my matches results *************************/
/*****************************************************************************/
2020-04-02 03:28:08 +02:00
void MchRes_ShowMyMchResultsInCrs (void)
2019-12-08 13:34:12 +01:00
{
extern const char *Txt_Results;
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
2020-04-23 23:09:28 +02:00
/***** Reset games context *****/
2020-04-08 03:06:45 +02:00
Gam_ResetGames (&Games);
2019-12-08 13:34:12 +01:00
/***** Get list of games *****/
2020-04-08 03:06:45 +02:00
Gam_GetListGames (&Games,Gam_ORDER_BY_TITLE);
Gam_GetListSelectedGamCods (&Games);
2019-12-08 13:34:12 +01:00
2019-12-08 23:19:16 +01:00
/***** List my matches results in the current course *****/
2020-04-08 03:06:45 +02:00
MchRes_ShowResultsBegin (&Games,Txt_Results,true); // List games to select
MchRes_ListMyMchResultsInCrs (&Games);
2020-04-02 03:28:08 +02:00
MchRes_ShowResultsEnd ();
2019-12-08 13:34:12 +01:00
2019-12-08 23:19:16 +01:00
/***** Free list of games *****/
2020-04-08 03:06:45 +02:00
free (Games.GamCodsSelected);
Gam_FreeListGames (&Games);
2019-12-08 23:19:16 +01:00
}
2019-12-08 15:03:40 +01:00
2020-04-08 03:06:45 +02:00
static void MchRes_ListMyMchResultsInCrs (struct Gam_Games *Games)
2019-12-08 23:19:16 +01:00
{
char *GamesSelectedCommas = NULL; // Initialized to avoid warning
/***** Table header *****/
2020-04-02 03:28:08 +02:00
MchRes_ShowHeaderMchResults (Usr_ME);
2019-12-08 13:34:12 +01:00
2019-12-08 23:19:16 +01:00
/***** List my matches results in the current course *****/
2020-03-21 15:41:25 +01:00
TstCfg_GetConfigFromDB (); // Get feedback type
2020-04-08 03:06:45 +02:00
MchRes_BuildGamesSelectedCommas (Games,&GamesSelectedCommas);
MchRes_ShowMchResults (Games,Usr_ME,-1L,-1L,GamesSelectedCommas);
2019-12-08 13:34:12 +01:00
free (GamesSelectedCommas);
}
/*****************************************************************************/
/***************** Show my matches results in a given game *******************/
/*****************************************************************************/
2020-04-02 03:28:08 +02:00
void MchRes_ShowMyMchResultsInGam (void)
2019-12-08 13:34:12 +01:00
{
2019-12-08 23:19:16 +01:00
extern const char *Txt_Results_of_game_X;
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
struct Gam_Game Game;
2020-04-23 23:09:28 +02:00
/***** Reset games context *****/
2020-04-08 03:06:45 +02:00
Gam_ResetGames (&Games);
2019-12-08 13:34:12 +01:00
2020-04-23 23:09:28 +02:00
/***** Reset game *****/
Gam_ResetGame (&Game);
2019-12-08 14:14:29 +01:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
Err_WrongGameExit ();
2019-12-08 23:19:16 +01:00
Gam_GetDataOfGameByCod (&Game);
2019-12-08 13:34:12 +01:00
2019-12-08 17:08:15 +01:00
/***** Game begin *****/
2020-04-08 03:06:45 +02:00
Gam_ShowOnlyOneGameBegin (&Games,&Game,
2019-12-08 17:08:15 +01:00
false, // Do not list game questions
false); // Do not put form to start new match
2019-12-08 13:34:12 +01:00
2019-12-08 23:19:16 +01:00
/***** List my matches results in game *****/
2020-04-08 03:06:45 +02:00
MchRes_ShowResultsBegin (&Games,
Str_BuildStringStr (Txt_Results_of_game_X,Game.Title),
false); // Do not list games to select
2019-12-30 21:47:07 +01:00
Str_FreeString ();
2020-04-08 03:06:45 +02:00
MchRes_ListMyMchResultsInGam (&Games,Game.GamCod);
2020-04-02 03:28:08 +02:00
MchRes_ShowResultsEnd ();
2019-12-08 13:34:12 +01:00
2019-12-08 23:19:16 +01:00
/***** Game end *****/
Gam_ShowOnlyOneGameEnd ();
}
2020-04-08 03:06:45 +02:00
static void MchRes_ListMyMchResultsInGam (struct Gam_Games *Games,long GamCod)
2019-12-08 23:19:16 +01:00
{
/***** Table header *****/
2020-04-02 03:28:08 +02:00
MchRes_ShowHeaderMchResults (Usr_ME);
2019-12-08 13:34:12 +01:00
2019-12-08 23:19:16 +01:00
/***** List my matches results in game *****/
2020-03-21 15:41:25 +01:00
TstCfg_GetConfigFromDB (); // Get feedback type
2020-04-08 03:06:45 +02:00
MchRes_ShowMchResults (Games,Usr_ME,-1L,GamCod,NULL);
2019-12-08 23:19:16 +01:00
}
2019-12-08 13:34:12 +01:00
2019-12-08 23:19:16 +01:00
/*****************************************************************************/
/***************** Show my matches results in a given match ******************/
/*****************************************************************************/
2019-12-08 13:34:12 +01:00
2020-04-02 03:28:08 +02:00
void MchRes_ShowMyMchResultsInMch (void)
2019-12-08 23:19:16 +01:00
{
extern const char *Txt_Results_of_match_X;
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
struct Gam_Game Game;
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);
2019-12-08 23:19:16 +01:00
2020-04-23 23:09:28 +02:00
/***** Reset game and match *****/
Gam_ResetGame (&Game);
Mch_ResetMatch (&Match);
2019-12-08 23:19:16 +01:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
Err_WrongGameExit ();
2020-04-08 03:06:45 +02:00
if ((Match.MchCod = Mch_GetParamMchCod ()) <= 0)
Err_WrongMatchExit ();
2019-12-08 23:19:16 +01:00
Gam_GetDataOfGameByCod (&Game);
Mch_GetDataOfMatchByCod (&Match);
/***** Game begin *****/
2020-04-08 03:06:45 +02:00
Gam_ShowOnlyOneGameBegin (&Games,&Game,
2019-12-08 23:19:16 +01:00
false, // Do not list game questions
false); // Do not put form to start new match
/***** List my matches results in match *****/
2020-04-08 03:06:45 +02:00
MchRes_ShowResultsBegin (&Games,Str_BuildStringStr (Txt_Results_of_match_X,Match.Title),
false); // Do not list games to select
2019-12-30 21:47:07 +01:00
Str_FreeString ();
2020-04-08 03:06:45 +02:00
MchRes_ListMyMchResultsInMch (&Games,Match.MchCod);
2020-04-02 03:28:08 +02:00
MchRes_ShowResultsEnd ();
2019-12-08 13:34:12 +01:00
2019-12-08 17:08:15 +01:00
/***** Game end *****/
Gam_ShowOnlyOneGameEnd ();
2019-12-08 23:19:16 +01:00
}
2019-12-08 17:08:15 +01:00
2020-04-08 03:06:45 +02:00
static void MchRes_ListMyMchResultsInMch (struct Gam_Games *Games,long MchCod)
2019-12-08 23:19:16 +01:00
{
/***** Table header *****/
2020-04-02 03:28:08 +02:00
MchRes_ShowHeaderMchResults (Usr_ME);
2019-12-08 23:19:16 +01:00
/***** List my matches results in game *****/
2020-03-21 15:41:25 +01:00
TstCfg_GetConfigFromDB (); // Get feedback type
2020-04-08 03:06:45 +02:00
MchRes_ShowMchResults (Games,Usr_ME,MchCod,-1L,NULL);
2019-12-08 13:34:12 +01:00
}
2019-11-14 14:34:34 +01:00
/*****************************************************************************/
/****************** Get users and show their matches results *****************/
/*****************************************************************************/
2020-04-02 03:28:08 +02:00
void MchRes_ShowAllMchResultsInCrs (void)
2019-11-14 14:34:34 +01:00
{
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
2020-04-23 23:09:28 +02:00
/***** Reset games context *****/
2020-04-08 03:06:45 +02:00
Gam_ResetGames (&Games);
/***** Get users and show their matches results *****/
2019-11-15 03:34:48 +01:00
Usr_GetSelectedUsrsAndGoToAct (&Gbl.Usrs.Selected,
2020-04-08 03:06:45 +02:00
MchRes_ShowAllMchResultsInSelectedGames,&Games,
MchRes_PutFormToSelUsrsToViewMchResults,&Games);
2019-12-07 02:12:13 +01:00
}
2019-09-28 02:31:42 +02:00
/*****************************************************************************/
/****************** Show matches results for several users *******************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void MchRes_ShowAllMchResultsInSelectedGames (void *Games)
2019-09-28 02:31:42 +02:00
{
extern const char *Txt_Results;
2020-04-08 03:06:45 +02:00
if (!Games)
2020-04-06 16:00:06 +02:00
return;
2019-11-25 23:18:08 +01:00
/***** Get list of games *****/
2020-04-08 03:06:45 +02:00
Gam_GetListGames ((struct Gam_Games *) Games,Gam_ORDER_BY_TITLE);
Gam_GetListSelectedGamCods ((struct Gam_Games *) Games);
2019-12-08 13:34:12 +01:00
2019-12-08 23:19:16 +01:00
/***** List the matches results of the selected users *****/
2020-04-08 03:06:45 +02:00
MchRes_ShowResultsBegin ((struct Gam_Games *) Games,
Txt_Results,
true); // List games to select
MchRes_ListAllMchResultsInSelectedGames ((struct Gam_Games *) Games);
2020-04-02 03:28:08 +02:00
MchRes_ShowResultsEnd ();
2019-11-25 23:18:08 +01:00
2019-12-08 23:19:16 +01:00
/***** Free list of games *****/
2020-04-08 03:06:45 +02:00
free (((struct Gam_Games *) Games)->GamCodsSelected);
Gam_FreeListGames ((struct Gam_Games *) Games);
2019-12-08 23:19:16 +01:00
}
2019-11-25 23:18:08 +01:00
2020-04-08 03:06:45 +02:00
static void MchRes_ListAllMchResultsInSelectedGames (struct Gam_Games *Games)
2019-12-08 23:19:16 +01:00
{
char *GamesSelectedCommas = NULL; // Initialized to avoid warning
const char *Ptr;
/***** Table head *****/
2020-04-02 03:28:08 +02:00
MchRes_ShowHeaderMchResults (Usr_OTHER);
2019-12-08 13:34:12 +01:00
/***** List the matches results of the selected users *****/
2020-04-08 03:06:45 +02:00
MchRes_BuildGamesSelectedCommas (Games,&GamesSelectedCommas);
2019-12-08 13:34:12 +01:00
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
2019-11-25 23:18:08 +01:00
{
Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EnUsrCod,
2019-12-08 13:34:12 +01:00
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CURRENT_CRS))
2020-04-22 03:15:04 +02:00
if (Usr_CheckIfICanViewTstExaMchResult (&Gbl.Usrs.Other.UsrDat))
2019-12-08 13:34:12 +01:00
{
/***** Show matches results *****/
Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
2020-04-08 03:06:45 +02:00
MchRes_ShowMchResults (Games,Usr_OTHER,-1L,-1L,GamesSelectedCommas);
2019-12-08 13:34:12 +01:00
}
}
free (GamesSelectedCommas);
}
2020-04-08 03:06:45 +02:00
/*****************************************************************************/
/**************** Select users to show their matches results *****************/
/*****************************************************************************/
void MchRes_SelUsrsToViewMchResults (void)
{
struct Gam_Games Games;
2020-04-23 23:09:28 +02:00
/***** Reset games context *****/
2020-04-08 03:06:45 +02:00
Gam_ResetGames (&Games);
/***** Put form to select users *****/
MchRes_PutFormToSelUsrsToViewMchResults (&Games);
}
static void MchRes_PutFormToSelUsrsToViewMchResults (void *Games)
{
extern const char *Hlp_ASSESSMENT_Games_results;
extern const char *Txt_Results;
2020-05-18 22:59:07 +02:00
extern const char *Txt_View_results;
2020-04-08 03:06:45 +02:00
if (Games) // Not used
Usr_PutFormToSelectUsrsToGoToAct (&Gbl.Usrs.Selected,
2020-05-18 22:59:07 +02:00
ActSeeUsrMchResCrs,
2020-04-08 03:06:45 +02:00
NULL,NULL,
Txt_Results,
Hlp_ASSESSMENT_Games_results,
2020-05-18 22:59:07 +02:00
Txt_View_results,
2020-04-08 03:06:45 +02:00
false); // Do not put form with date range
}
2019-12-08 13:34:12 +01:00
/*****************************************************************************/
2019-12-08 23:19:16 +01:00
/*** Show matches results of a game for the users who answered in that game **/
2019-12-08 13:34:12 +01:00
/*****************************************************************************/
2020-04-02 03:28:08 +02:00
void MchRes_ShowAllMchResultsInGam (void)
2019-12-08 13:34:12 +01:00
{
2019-12-08 23:19:16 +01:00
extern const char *Txt_Results_of_game_X;
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
struct Gam_Game Game;
2020-04-23 23:09:28 +02:00
/***** Reset games context *****/
2020-04-08 03:06:45 +02:00
Gam_ResetGames (&Games);
2019-12-08 23:19:16 +01:00
2020-04-23 23:09:28 +02:00
/***** Reset game *****/
Gam_ResetGame (&Game);
2019-12-08 23:19:16 +01:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
Err_WrongGameExit ();
2019-12-08 23:19:16 +01:00
Gam_GetDataOfGameByCod (&Game);
/***** Game begin *****/
2020-04-08 03:06:45 +02:00
Gam_ShowOnlyOneGameBegin (&Games,&Game,
2019-12-08 23:19:16 +01:00
false, // Do not list game questions
false); // Do not put form to start new match
/***** List matches results in game *****/
2020-04-08 03:06:45 +02:00
MchRes_ShowResultsBegin (&Games,
Str_BuildStringStr (Txt_Results_of_game_X,Game.Title),
false); // Do not list games to select
2019-12-30 21:47:07 +01:00
Str_FreeString ();
2020-04-08 03:06:45 +02:00
MchRes_ListAllMchResultsInGam (&Games,Game.GamCod);
2020-04-02 03:28:08 +02:00
MchRes_ShowResultsEnd ();
2019-12-08 23:19:16 +01:00
/***** Game end *****/
Gam_ShowOnlyOneGameEnd ();
}
2020-04-08 03:06:45 +02:00
static void MchRes_ListAllMchResultsInGam (struct Gam_Games *Games,long GamCod)
2019-12-08 23:19:16 +01:00
{
2019-12-08 13:34:12 +01:00
MYSQL_RES *mysql_res;
unsigned NumUsrs;
unsigned NumUsr;
2019-12-08 13:34:12 +01:00
2019-12-08 23:19:16 +01:00
/***** Table head *****/
2020-04-02 03:28:08 +02:00
MchRes_ShowHeaderMchResults (Usr_OTHER);
2019-12-08 23:19:16 +01:00
/***** Get all users who have answered any match question in this game *****/
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users in game",
"SELECT users.UsrCod"
" FROM (SELECT DISTINCT mch_results.UsrCod AS UsrCod"
" FROM mch_results,"
"mch_matches,"
"gam_games"
" WHERE mch_matches.GamCod=%ld"
" AND mch_matches.MchCod=mch_results.MchCod"
" AND mch_matches.GamCod=gam_games.GamCod"
" AND gam_games.CrsCod=%ld) AS users," // Extra check
"usr_data"
" WHERE users.UsrCod=usr_data.UsrCod"
" ORDER BY usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName",
GamCod,
Gbl.Hierarchy.Crs.CrsCod);
/***** List matches results for each user *****/
for (NumUsr = 0;
NumUsr < NumUsrs;
NumUsr++)
/* Get match code */
if ((Gbl.Usrs.Other.UsrDat.UsrCod = DB_GetNextCode (mysql_res)) > 0)
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CURRENT_CRS))
if (Usr_CheckIfICanViewTstExaMchResult (&Gbl.Usrs.Other.UsrDat))
{
/***** Show matches results *****/
Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
MchRes_ShowMchResults (Games,Usr_OTHER,-1L,GamCod,NULL);
}
2019-12-08 23:19:16 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/** Show matches results of a match for the users who answered in that match */
/*****************************************************************************/
2020-04-02 03:28:08 +02:00
void MchRes_ShowAllMchResultsInMch (void)
2019-12-08 23:19:16 +01:00
{
extern const char *Txt_Results_of_match_X;
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
struct Gam_Game Game;
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);
2019-12-08 23:19:16 +01:00
2020-04-23 23:09:28 +02:00
/***** Reset game and match *****/
Gam_ResetGame (&Game);
Mch_ResetMatch (&Match);
2019-12-08 14:14:29 +01:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
Err_WrongGameExit ();
2020-04-08 03:06:45 +02:00
if ((Match.MchCod = Mch_GetParamMchCod ()) <= 0)
Err_WrongMatchExit ();
2019-12-08 23:19:16 +01:00
Gam_GetDataOfGameByCod (&Game);
Mch_GetDataOfMatchByCod (&Match);
2019-12-08 13:34:12 +01:00
2019-12-08 17:08:15 +01:00
/***** Game begin *****/
2020-04-08 03:06:45 +02:00
Gam_ShowOnlyOneGameBegin (&Games,&Game,
2019-12-08 17:08:15 +01:00
false, // Do not list game questions
false); // Do not put form to start new match
2019-12-08 14:14:29 +01:00
2019-12-08 23:19:16 +01:00
/***** List matches results in match *****/
2020-04-08 03:06:45 +02:00
MchRes_ShowResultsBegin (&Games,
Str_BuildStringStr (Txt_Results_of_match_X,Match.Title),
false); // Do not list games to select
2019-12-30 21:47:07 +01:00
Str_FreeString ();
2020-04-08 03:06:45 +02:00
MchRes_ListAllMchResultsInMch (&Games,Match.MchCod);
2020-04-02 03:28:08 +02:00
MchRes_ShowResultsEnd ();
2019-12-08 13:34:12 +01:00
2019-12-08 23:19:16 +01:00
/***** Game end *****/
Gam_ShowOnlyOneGameEnd ();
}
2020-04-08 03:06:45 +02:00
static void MchRes_ListAllMchResultsInMch (struct Gam_Games *Games,long MchCod)
2019-12-08 23:19:16 +01:00
{
MYSQL_RES *mysql_res;
unsigned NumUsrs;
unsigned NumUsr;
2019-12-08 23:19:16 +01:00
/***** Table head *****/
2020-04-02 03:28:08 +02:00
MchRes_ShowHeaderMchResults (Usr_OTHER);
2019-12-08 23:19:16 +01:00
/***** Get all users who have answered any match question in this game *****/
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users in match",
"SELECT users.UsrCod"
" FROM (SELECT mch_results.UsrCod AS UsrCod"
" FROM mch_results,"
"mch_matches,"
"gam_games"
" WHERE mch_results.MchCod=%ld"
" AND mch_results.MchCod=mch_matches.MchCod"
" AND mch_matches.GamCod=gam_games.GamCod"
" AND gam_games.CrsCod=%ld) AS users," // Extra check
"usr_data"
" WHERE users.UsrCod=usr_data.UsrCod"
" ORDER BY usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName",
MchCod,
Gbl.Hierarchy.Crs.CrsCod);
/***** List matches results for each user *****/
for (NumUsr = 0;
NumUsr < NumUsrs;
NumUsr++)
/* Get match code (row[0]) */
if ((Gbl.Usrs.Other.UsrDat.UsrCod = DB_GetNextCode (mysql_res)) > 0)
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CURRENT_CRS))
if (Usr_CheckIfICanViewTstExaMchResult (&Gbl.Usrs.Other.UsrDat))
{
/***** Show matches results *****/
Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
MchRes_ShowMchResults (Games,Usr_OTHER,MchCod,-1L,NULL);
}
2019-11-25 23:18:08 +01:00
2019-12-08 13:34:12 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2019-12-08 23:19:16 +01:00
}
2019-11-25 23:18:08 +01:00
2019-12-08 23:19:16 +01:00
/*****************************************************************************/
/************************ Show results (begin / end) *************************/
/*****************************************************************************/
2019-12-08 13:34:12 +01:00
2020-04-08 03:06:45 +02:00
static void MchRes_ShowResultsBegin (struct Gam_Games *Games,
const char *Title,bool ListGamesToSelect)
2019-12-08 23:19:16 +01:00
{
extern const char *Hlp_ASSESSMENT_Games_results;
2019-12-08 17:08:15 +01:00
2019-12-08 23:19:16 +01:00
/***** Begin box *****/
2020-04-02 03:28:08 +02:00
HTM_SECTION_Begin (MchRes_RESULTS_BOX_ID);
2020-06-24 20:10:57 +02:00
Box_BoxBegin (NULL,Title,
2020-03-26 02:54:30 +01:00
NULL,NULL,
2019-12-08 23:19:16 +01:00
Hlp_ASSESSMENT_Games_results,Box_NOT_CLOSABLE);
/***** List games to select *****/
if (ListGamesToSelect)
2020-04-08 03:06:45 +02:00
MchRes_ListGamesToSelect (Games);
2019-12-08 23:19:16 +01:00
2019-12-09 11:09:12 +01:00
/***** Begin match results table *****/
2020-04-02 03:28:08 +02:00
HTM_SECTION_Begin (MchRes_RESULTS_TABLE_ID);
2020-06-22 19:27:23 +02:00
HTM_TABLE_BeginWidePadding (5);
2019-12-08 23:19:16 +01:00
}
2020-04-02 03:28:08 +02:00
static void MchRes_ShowResultsEnd (void)
2019-12-08 23:19:16 +01:00
{
2019-12-09 11:09:12 +01:00
/***** End match results table *****/
2019-12-08 23:19:16 +01:00
HTM_TABLE_End ();
HTM_SECTION_End ();
/***** End box *****/
Box_BoxEnd ();
2019-12-09 11:09:12 +01:00
HTM_SECTION_End ();
2019-11-25 23:18:08 +01:00
}
/*****************************************************************************/
/********** Write list of those attendance events that have students *********/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void MchRes_ListGamesToSelect (struct Gam_Games *Games)
2019-11-25 23:18:08 +01:00
{
extern const char *The_ClassFormLinkInBoxBold[The_NUM_THEMES];
extern const char *Txt_Games;
extern const char *Txt_Game;
extern const char *Txt_Update_results;
unsigned UniqueId;
unsigned NumGame;
2020-04-08 03:06:45 +02:00
struct Gam_Game Game;
2019-09-28 02:31:42 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset game *****/
Gam_ResetGame (&Game);
2019-11-25 23:18:08 +01:00
/***** Begin box *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_Games,
NULL,NULL,
2020-05-18 22:59:07 +02:00
NULL,Box_CLOSABLE);
2019-11-25 23:18:08 +01:00
/***** Begin form to update the results
depending on the games selected *****/
2020-04-02 03:28:08 +02:00
Frm_StartFormAnchor (Gbl.Action.Act,MchRes_RESULTS_TABLE_ID);
2019-11-25 23:18:08 +01:00
Grp_PutParamsCodGrps ();
Usr_PutHiddenParSelectedUsrsCods (&Gbl.Usrs.Selected);
2019-11-14 14:34:34 +01:00
2019-11-25 23:18:08 +01:00
/***** Begin table *****/
HTM_TABLE_BeginWidePadding (2);
/***** Heading row *****/
HTM_TR_Begin (NULL);
2019-11-14 14:34:34 +01:00
2019-11-25 23:18:08 +01:00
HTM_TH (1,2,NULL,NULL);
HTM_TH (1,1,"LM",Txt_Game);
HTM_TR_End ();
/***** List the events *****/
for (NumGame = 0, UniqueId = 1, Gbl.RowEvenOdd = 0;
2020-04-08 03:06:45 +02:00
NumGame < Games->Num;
2019-11-25 23:18:08 +01:00
NumGame++, UniqueId++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd)
2019-09-28 02:31:42 +02:00
{
2019-11-25 23:18:08 +01:00
/* Get data of this game */
2020-04-08 03:06:45 +02:00
Game.GamCod = Games->Lst[NumGame].GamCod;
2019-11-25 23:18:08 +01:00
Gam_GetDataOfGameByCod (&Game);
/* Write a row for this event */
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"DAT CT COLOR%u\"",Gbl.RowEvenOdd);
2020-03-12 13:53:37 +01:00
HTM_INPUT_CHECKBOX ("GamCod",HTM_DONT_SUBMIT_ON_CHANGE,
2019-11-25 23:18:08 +01:00
"id=\"Gam%u\" value=\"%ld\"%s",
2020-04-08 03:06:45 +02:00
NumGame,Games->Lst[NumGame].GamCod,
Games->Lst[NumGame].Selected ? " checked=\"checked\"" :
"");
2019-11-25 23:18:08 +01:00
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT RT COLOR%u\"",Gbl.RowEvenOdd);
HTM_LABEL_Begin ("for=\"Gam%u\"",NumGame);
HTM_TxtF ("%u:",NumGame + 1);
HTM_LABEL_End ();
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT LT COLOR%u\"",Gbl.RowEvenOdd);
HTM_Txt (Game.Title);
HTM_TD_End ();
HTM_TR_End ();
2019-09-28 02:31:42 +02:00
}
2019-11-25 23:18:08 +01:00
/***** Put button to refresh *****/
HTM_TR_Begin (NULL);
HTM_TD_Begin ("colspan=\"3\" class=\"CM\"");
HTM_BUTTON_Animated_Begin (Txt_Update_results,
The_ClassFormLinkInBoxBold[Gbl.Prefs.Theme],
NULL);
Ico_PutCalculateIconWithText (Txt_Update_results);
HTM_BUTTON_End ();
HTM_TD_End ();
HTM_TR_End ();
/***** End table *****/
HTM_TABLE_End ();
/***** End form *****/
Frm_EndForm ();
/***** End box *****/
Box_BoxEnd ();
2019-09-28 02:31:42 +02:00
}
/*****************************************************************************/
/********************* Show header of my matches results *********************/
/*****************************************************************************/
2020-04-02 03:28:08 +02:00
static void MchRes_ShowHeaderMchResults (Usr_MeOrOther_t MeOrOther)
2019-09-28 02:31:42 +02:00
{
extern const char *Txt_User[Usr_NUM_SEXS];
2019-09-30 20:13:08 +02:00
extern const char *Txt_Match;
2019-09-28 02:31:42 +02:00
extern const char *Txt_START_END_TIME[Dat_NUM_START_END_TIME];
extern const char *Txt_Questions;
2020-06-24 20:10:57 +02:00
extern const char *Txt_Answers;
2019-11-28 22:17:00 +01:00
extern const char *Txt_Score;
2019-11-28 00:19:42 +01:00
extern const char *Txt_Grade;
2020-06-24 20:10:57 +02:00
extern const char *Txt_ANSWERS_non_blank;
extern const char *Txt_ANSWERS_blank;
extern const char *Txt_total;
extern const char *Txt_average;
/***** First row *****/
HTM_TR_Begin (NULL);
HTM_TH (3,2,"CT LINE_BOTTOM",Txt_User[MeOrOther == Usr_ME ? Gbl.Usrs.Me.UsrDat.Sex :
Usr_SEX_UNKNOWN]);
HTM_TH (3,1,"LT LINE_BOTTOM",Txt_START_END_TIME[Dat_START_TIME]);
HTM_TH (3,1,"LT LINE_BOTTOM",Txt_START_END_TIME[Dat_END_TIME ]);
HTM_TH (3,1,"LT LINE_BOTTOM",Txt_Match);
HTM_TH (3,1,"RT LINE_BOTTOM LINE_LEFT",Txt_Questions);
HTM_TH (1,2,"CT LINE_LEFT",Txt_Answers);
HTM_TH (1,2,"CT LINE_LEFT",Txt_Score);
HTM_TH (3,1,"RT LINE_BOTTOM LINE_LEFT",Txt_Grade);
HTM_TH (3,1,"LINE_BOTTOM LINE_LEFT",NULL);
2019-09-28 02:31:42 +02:00
2020-06-24 20:10:57 +02:00
HTM_TR_End ();
/***** Second row *****/
HTM_TR_Begin (NULL);
HTM_TH (1,1,"RT LINE_LEFT",Txt_ANSWERS_non_blank);
HTM_TH (1,1,"RT",Txt_ANSWERS_blank);
HTM_TH (1,1,"RT LINE_LEFT",Txt_total);
HTM_TH (1,1,"RT",Txt_average);
HTM_TR_End ();
/***** Third row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-12 00:07:52 +02:00
2020-06-24 20:10:57 +02:00
HTM_TH (1,1,"RT LINE_BOTTOM LINE_LEFT","{-1&le;<em>p<sub>i</sub></em>&le;1}");
HTM_TH (1,1,"RT LINE_BOTTOM","{<em>p<sub>i</sub></em>=0}");
HTM_TH (1,1,"RT LINE_BOTTOM LINE_LEFT","<em>&Sigma;p<sub>i</sub></em>");
HTM_TH (1,1,"RT LINE_BOTTOM","-1&le;<em style=\"text-decoration:overline;\">p</em>&le;1");
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-09-28 02:31:42 +02:00
}
2019-12-08 13:34:12 +01:00
/*****************************************************************************/
/******* Build string with list of selected games separated by commas ********/
/******* from list of selected games ********/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void MchRes_BuildGamesSelectedCommas (struct Gam_Games *Games,
char **GamesSelectedCommas)
2019-12-08 13:34:12 +01:00
{
size_t MaxLength;
unsigned NumGame;
char LongStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1];
/***** Allocate memory for subquery of games selected *****/
2020-04-08 03:06:45 +02:00
MaxLength = (size_t) Games->NumSelected * (Cns_MAX_DECIMAL_DIGITS_LONG + 1);
if ((*GamesSelectedCommas = malloc (MaxLength + 1)) == NULL)
Err_NotEnoughMemoryExit ();
2019-12-08 13:34:12 +01:00
/***** Build subquery with list of selected games *****/
2019-12-08 14:14:29 +01:00
(*GamesSelectedCommas)[0] = '\0';
2019-12-08 13:34:12 +01:00
for (NumGame = 0;
2020-04-08 03:06:45 +02:00
NumGame < Games->Num;
2019-12-08 13:34:12 +01:00
NumGame++)
2020-04-08 03:06:45 +02:00
if (Games->Lst[NumGame].Selected)
2019-12-08 13:34:12 +01:00
{
2020-04-08 03:06:45 +02:00
sprintf (LongStr,"%ld",Games->Lst[NumGame].GamCod);
2019-12-08 14:14:29 +01:00
if ((*GamesSelectedCommas)[0])
Str_Concat (*GamesSelectedCommas,",",MaxLength);
Str_Concat (*GamesSelectedCommas,LongStr,MaxLength);
2019-12-08 13:34:12 +01:00
}
}
2019-09-28 02:31:42 +02:00
/*****************************************************************************/
/********* Show the matches results of a user in the current course **********/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void MchRes_ShowMchResults (struct Gam_Games *Games,
Usr_MeOrOther_t MeOrOther,
long MchCod, // <= 0 ==> any
long GamCod, // <= 0 ==> any
const char *GamesSelectedCommas)
2019-09-28 02:31:42 +02:00
{
2020-05-17 02:28:30 +02:00
extern const char *Txt_Result;
2019-12-08 23:19:16 +01:00
char *MchSubQuery;
char *GamSubQuery;
2020-06-23 11:48:06 +02:00
char *HidGamSubQuery;
2019-09-28 02:31:42 +02:00
MYSQL_RES *mysql_res;
struct UsrData *UsrDat;
2020-06-23 11:48:06 +02:00
struct MchRes_ICanView ICanView;
2019-09-28 02:31:42 +02:00
unsigned NumResults;
unsigned NumResult;
static unsigned UniqueId = 0;
2020-06-24 20:10:57 +02:00
Dat_StartEndTime_t StartEndTime;
2019-11-01 22:53:39 +01:00
char *Id;
2020-06-24 20:10:57 +02:00
struct MchPrn_Print Print;
unsigned NumQstsBlank;
2020-04-08 03:06:45 +02:00
struct Mch_Match Match;
2020-06-23 11:48:06 +02:00
struct Gam_Game Game;
2019-11-28 00:19:42 +01:00
double Grade;
2020-06-24 20:10:57 +02:00
struct MchPrn_NumQuestions NumTotalQsts;
double TotalScore;
double TotalGrade;
2019-09-28 02:31:42 +02:00
2020-06-24 20:10:57 +02:00
/***** Reset total number of questions and total score *****/
NumTotalQsts.All =
NumTotalQsts.NotBlank = 0;
TotalScore = 0.0;
TotalGrade = 0.0;
2020-04-23 23:09:28 +02:00
2019-09-28 02:31:42 +02:00
/***** Set user *****/
UsrDat = (MeOrOther == Usr_ME) ? &Gbl.Usrs.Me.UsrDat :
2019-11-25 23:18:08 +01:00
&Gbl.Usrs.Other.UsrDat;
2019-12-08 23:19:16 +01:00
/***** Build matches subquery *****/
if (MchCod > 0)
{
if (asprintf (&MchSubQuery," AND mch_results.MchCod=%ld",MchCod) < 0)
Err_NotEnoughMemoryExit ();
2019-12-08 23:19:16 +01:00
}
else
{
if (asprintf (&MchSubQuery,"%s","") < 0)
Err_NotEnoughMemoryExit ();
2019-12-08 23:19:16 +01:00
}
/***** Build games subquery *****/
if (GamCod > 0)
{
if (asprintf (&GamSubQuery," AND mch_matches.GamCod=%ld",GamCod) < 0)
Err_NotEnoughMemoryExit ();
2019-12-08 23:19:16 +01:00
}
else if (GamesSelectedCommas)
{
2019-12-10 14:22:09 +01:00
if (GamesSelectedCommas[0])
{
if (asprintf (&GamSubQuery," AND mch_matches.GamCod IN (%s)",
GamesSelectedCommas) < 0)
Err_NotEnoughMemoryExit ();
2019-12-10 14:22:09 +01:00
}
else
{
if (asprintf (&GamSubQuery,"%s","") < 0)
Err_NotEnoughMemoryExit ();
2019-12-10 14:22:09 +01:00
}
2019-12-08 23:19:16 +01:00
}
else
{
if (asprintf (&GamSubQuery,"%s","") < 0)
Err_NotEnoughMemoryExit ();
2019-12-08 23:19:16 +01:00
}
2020-06-23 11:48:06 +02:00
/***** Subquery: get hidden games?
<EFBFBD> A student will not be able to see their results in hidden games
<EFBFBD> A teacher will be able to see results from other users even in hidden games
*****/
switch (MeOrOther)
{
case Usr_ME: // A student watching her/his results
if (asprintf (&HidGamSubQuery," AND gam_games.Hidden='N'") < 0)
Err_NotEnoughMemoryExit ();
2020-06-23 11:48:06 +02:00
break;
default: // A teacher/admin watching the results of other users
if (asprintf (&HidGamSubQuery,"%s","") < 0)
Err_NotEnoughMemoryExit ();
2020-06-23 11:48:06 +02:00
break;
}
2019-09-28 02:31:42 +02:00
/***** Make database query *****/
NumResults = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get matches results",
"SELECT mch_results.MchCod"
" FROM mch_results,"
"mch_matches,"
"gam_games"
" WHERE mch_results.UsrCod=%ld"
"%s" // Match subquery
" AND mch_results.MchCod=mch_matches.MchCod"
"%s" // Games subquery
" AND mch_matches.GamCod=gam_games.GamCod"
"%s" // Hidden games subquery
" AND gam_games.CrsCod=%ld" // Extra check
" ORDER BY mch_matches.Title",
UsrDat->UsrCod,
MchSubQuery,
GamSubQuery,
HidGamSubQuery,
Gbl.Hierarchy.Crs.CrsCod);
2020-06-23 11:48:06 +02:00
free (HidGamSubQuery);
2019-12-08 23:19:16 +01:00
free (GamSubQuery);
free (MchSubQuery);
2019-09-28 02:31:42 +02:00
/***** Show user's data *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-09-28 02:31:42 +02:00
Usr_ShowTableCellWithUsrData (UsrDat,NumResults);
/***** Get and print matches results *****/
if (NumResults)
{
for (NumResult = 0;
2019-11-25 23:18:08 +01:00
NumResult < NumResults;
NumResult++)
{
/* Get match code */
2020-06-24 20:10:57 +02:00
MchPrn_ResetPrint (&Print);
if ((Print.MchCod = DB_GetNextCode (mysql_res)) < 0)
Err_WrongMatchExit ();
2020-06-24 20:10:57 +02:00
/* Get match result data */
Print.UsrCod = UsrDat->UsrCod;
2020-06-24 20:47:54 +02:00
MchPrn_GetMatchPrintDataByMchCodAndUsrCod (&Print);
2019-09-28 02:31:42 +02:00
2020-06-23 11:48:06 +02:00
/* Get data of match and game */
2020-06-24 20:10:57 +02:00
Match.MchCod = Print.MchCod;
2020-06-23 11:48:06 +02:00
Mch_GetDataOfMatchByCod (&Match);
Game.GamCod = Match.GamCod;
Gam_GetDataOfGameByCod (&Game);
2020-02-18 15:40:04 +01:00
2020-06-23 11:48:06 +02:00
/* Check if I can view this match result and score */
MchRes_CheckIfICanSeeMatchResult (&Game,&Match,UsrDat->UsrCod,&ICanView);
2019-09-28 02:31:42 +02:00
2019-11-25 23:18:08 +01:00
if (NumResult)
HTM_TR_Begin (NULL);
2019-09-28 02:31:42 +02:00
2020-06-24 20:10:57 +02:00
/* Write start/end times */
2019-12-15 20:02:34 +01:00
for (StartEndTime = (Dat_StartEndTime_t) 0;
2019-09-28 02:31:42 +02:00
StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
StartEndTime++)
2019-11-25 23:18:08 +01:00
{
2019-09-28 02:31:42 +02:00
UniqueId++;
2019-12-09 16:59:19 +01:00
if (asprintf (&Id,"mch_res_time_%u_%u",(unsigned) StartEndTime,UniqueId) < 0)
Err_NotEnoughMemoryExit ();
2019-11-01 22:53:39 +01:00
HTM_TD_Begin ("id =\"%s\" class=\"DAT LT COLOR%u\"",
Id,Gbl.RowEvenOdd);
2020-06-24 20:10:57 +02:00
Dat_WriteLocalDateHMSFromUTC (Id,Print.TimeUTC[StartEndTime],
2019-11-02 12:10:58 +01:00
Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK,
2019-11-02 11:45:41 +01:00
true,true,false,0x7);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-11-25 23:18:08 +01:00
free (Id);
}
2019-09-28 02:31:42 +02:00
2019-11-25 23:18:08 +01:00
/* Write match title */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LT COLOR%u\"",Gbl.RowEvenOdd);
2019-11-10 12:36:37 +01:00
HTM_Txt (Match.Title);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-30 22:31:07 +02:00
2020-06-24 20:10:57 +02:00
/* Accumulate questions and score */
2020-06-23 11:48:06 +02:00
if (ICanView.Score)
2019-09-28 02:31:42 +02:00
{
2020-06-24 20:10:57 +02:00
NumTotalQsts.All += Print.NumQsts.All;
NumTotalQsts.NotBlank += Print.NumQsts.NotBlank;
TotalScore += Print.Score;
2019-09-28 02:31:42 +02:00
}
2019-11-25 23:18:08 +01:00
/* Write number of questions */
2020-06-24 20:10:57 +02:00
HTM_TD_Begin ("class=\"DAT RT LINE_LEFT COLOR%u\"",Gbl.RowEvenOdd);
2020-06-23 11:48:06 +02:00
if (ICanView.Score)
2020-06-24 20:10:57 +02:00
HTM_Unsigned (Print.NumQsts.All);
2019-11-28 22:17:00 +01:00
else
2020-02-19 00:45:26 +01:00
Ico_PutIconNotVisible ();
HTM_TD_End ();
2019-09-28 02:31:42 +02:00
2020-06-24 20:10:57 +02:00
/* Write number of non-blank answers */
HTM_TD_Begin ("class=\"DAT RT LINE_LEFT COLOR%u\"",Gbl.RowEvenOdd);
if (ICanView.Score)
{
if (Print.NumQsts.NotBlank)
HTM_Unsigned (Print.NumQsts.NotBlank);
else
HTM_Light0 ();
}
else
Ico_PutIconNotVisible ();
HTM_TD_End ();
/* Write number of blank answers */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RT COLOR%u\"",Gbl.RowEvenOdd);
2020-06-24 20:10:57 +02:00
NumQstsBlank = Print.NumQsts.All - Print.NumQsts.NotBlank;
2020-06-23 11:48:06 +02:00
if (ICanView.Score)
2020-06-24 20:10:57 +02:00
{
if (NumQstsBlank)
HTM_Unsigned (NumQstsBlank);
else
HTM_Light0 ();
}
2019-11-28 22:17:00 +01:00
else
2020-02-19 00:45:26 +01:00
Ico_PutIconNotVisible ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-28 02:31:42 +02:00
/* Write score */
2020-06-24 20:10:57 +02:00
HTM_TD_Begin ("class=\"DAT RT LINE_LEFT COLOR%u\"",Gbl.RowEvenOdd);
2020-06-23 11:48:06 +02:00
if (ICanView.Score)
2020-06-18 20:06:17 +02:00
{
2020-06-24 20:10:57 +02:00
HTM_Double2Decimals (Print.Score);
2020-06-18 20:06:17 +02:00
HTM_Txt ("/");
2020-06-24 20:10:57 +02:00
HTM_Unsigned (Print.NumQsts.All);
2020-06-18 20:06:17 +02:00
}
2019-11-28 22:17:00 +01:00
else
2020-02-19 00:45:26 +01:00
Ico_PutIconNotVisible ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-28 02:31:42 +02:00
2019-11-25 23:18:08 +01:00
/* Write average score per question */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RT COLOR%u\"",Gbl.RowEvenOdd);
2020-06-23 11:48:06 +02:00
if (ICanView.Score)
2020-06-24 20:10:57 +02:00
HTM_Double2Decimals (Print.NumQsts.All ? Print.Score /
(double) Print.NumQsts.All :
0.0);
2019-11-28 22:17:00 +01:00
else
2020-02-19 00:45:26 +01:00
Ico_PutIconNotVisible ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-28 02:31:42 +02:00
2019-11-28 00:19:42 +01:00
/* Write grade over maximum grade */
2020-06-24 20:10:57 +02:00
HTM_TD_Begin ("class=\"DAT RT LINE_LEFT COLOR%u\"",Gbl.RowEvenOdd);
2020-06-23 11:48:06 +02:00
if (ICanView.Score)
2019-11-28 00:19:42 +01:00
{
2020-06-24 20:10:57 +02:00
Grade = TstPrn_ComputeGrade (Print.NumQsts.All,Print.Score,Game.MaxGrade);
2020-06-23 11:48:06 +02:00
TstPrn_ShowGrade (Grade,Game.MaxGrade);
2019-11-28 00:19:42 +01:00
TotalGrade += Grade;
}
2019-11-28 22:17:00 +01:00
else
2020-02-19 00:45:26 +01:00
Ico_PutIconNotVisible ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-28 02:31:42 +02:00
/* Link to show this result */
2020-06-24 20:10:57 +02:00
HTM_TD_Begin ("class=\"RT LINE_LEFT COLOR%u\"",Gbl.RowEvenOdd);
2020-06-23 11:48:06 +02:00
if (ICanView.Result)
2019-09-28 02:31:42 +02:00
{
2020-11-25 01:50:13 +01:00
Games->GamCod = Match.GamCod;
Games->MchCod.Current = Match.MchCod;
2019-09-28 02:31:42 +02:00
switch (MeOrOther)
{
case Usr_ME:
Frm_BeginForm (ActSeeOneMchResMe);
2020-04-08 03:06:45 +02:00
Mch_PutParamsEdit (Games);
2019-09-28 02:31:42 +02:00
break;
case Usr_OTHER:
Frm_BeginForm (ActSeeOneMchResOth);
2020-04-08 03:06:45 +02:00
Mch_PutParamsEdit (Games);
Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
2019-09-28 02:31:42 +02:00
break;
}
2020-05-17 02:28:30 +02:00
Ico_PutIconLink ("tasks.svg",Txt_Result);
2019-09-28 02:31:42 +02:00
Frm_EndForm ();
}
else
2020-02-19 00:45:26 +01:00
Ico_PutIconNotVisible ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-28 02:31:42 +02:00
2019-11-25 23:18:08 +01:00
HTM_TR_End ();
}
2019-09-28 02:31:42 +02:00
/***** Write totals for this user *****/
2020-04-02 03:28:08 +02:00
MchRes_ShowMchResultsSummaryRow (NumResults,
2020-06-24 20:10:57 +02:00
&NumTotalQsts,
TotalScore,
2020-06-18 20:06:17 +02:00
TotalGrade);
2019-09-28 02:31:42 +02:00
}
else
{
2020-06-24 20:10:57 +02:00
/* Columns for dates and match */
HTM_TD_Begin ("colspan=\"3\" class=\"LINE_BOTTOM COLOR%u\"",Gbl.RowEvenOdd);
HTM_TD_End ();
/* Column for questions */
HTM_TD_Begin ("class=\"LINE_BOTTOM LINE_LEFT COLOR%u\"",Gbl.RowEvenOdd);
HTM_TD_End ();
/* Columns for answers */
HTM_TD_Begin ("colspan=\"2\" class=\"LINE_BOTTOM LINE_LEFT COLOR%u\"",Gbl.RowEvenOdd);
HTM_TD_End ();
/* Columns for score */
HTM_TD_Begin ("colspan=\"2\" class=\"LINE_BOTTOM LINE_LEFT COLOR%u\"",Gbl.RowEvenOdd);
HTM_TD_End ();
/* Column for grade */
HTM_TD_Begin ("class=\"LINE_BOTTOM LINE_LEFT COLOR%u\"",Gbl.RowEvenOdd);
HTM_TD_End ();
/* Column for link to show the result */
HTM_TD_Begin ("class=\"LINE_BOTTOM LINE_LEFT COLOR%u\"",Gbl.RowEvenOdd);
HTM_TD_End ();
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-09-28 02:31:42 +02:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
}
/*****************************************************************************/
/************** Show row with summary of user's matches results **************/
/*****************************************************************************/
2020-04-02 03:28:08 +02:00
static void MchRes_ShowMchResultsSummaryRow (unsigned NumResults,
2020-06-24 20:10:57 +02:00
struct MchPrn_NumQuestions *NumTotalQsts,
double TotalScore,
2020-04-08 03:06:45 +02:00
double TotalGrade)
2019-09-28 02:31:42 +02:00
{
extern const char *Txt_Matches;
/***** Start row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-09-28 02:31:42 +02:00
/***** Row title *****/
2020-06-24 20:10:57 +02:00
HTM_TD_Begin ("colspan=\"3\" class=\"DAT_N RM LINE_TOP LINE_BOTTOM COLOR%u\"",Gbl.RowEvenOdd);
2020-01-11 15:22:02 +01:00
HTM_TxtColonNBSP (Txt_Matches);
2019-11-11 00:15:44 +01:00
HTM_Unsigned (NumResults);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-28 02:31:42 +02:00
/***** Write total number of questions *****/
2020-06-24 20:10:57 +02:00
HTM_TD_Begin ("class=\"DAT_N RM LINE_TOP LINE_BOTTOM LINE_LEFT COLOR%u\"",Gbl.RowEvenOdd);
2019-09-28 02:31:42 +02:00
if (NumResults)
2020-06-24 20:10:57 +02:00
HTM_Unsigned (NumTotalQsts->All);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-28 02:31:42 +02:00
2020-06-24 20:10:57 +02:00
/***** Write total number of non-blank answers *****/
HTM_TD_Begin ("class=\"DAT_N RM LINE_TOP LINE_BOTTOM LINE_LEFT COLOR%u\"",Gbl.RowEvenOdd);
2019-09-28 02:31:42 +02:00
if (NumResults)
2020-06-24 20:10:57 +02:00
HTM_Unsigned (NumTotalQsts->NotBlank);
HTM_TD_End ();
/***** Write total number of blank answers *****/
HTM_TD_Begin ("class=\"DAT_N RM LINE_TOP LINE_BOTTOM COLOR%u\"",Gbl.RowEvenOdd);
if (NumResults)
HTM_Unsigned (NumTotalQsts->All - NumTotalQsts->NotBlank);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-28 02:31:42 +02:00
/***** Write total score *****/
2020-06-24 20:10:57 +02:00
HTM_TD_Begin ("class=\"DAT_N RM LINE_TOP LINE_BOTTOM LINE_LEFT COLOR%u\"",Gbl.RowEvenOdd);
HTM_Double2Decimals (TotalScore);
2020-06-18 20:06:17 +02:00
HTM_Txt ("/");
2020-06-24 20:10:57 +02:00
HTM_Unsigned (NumTotalQsts->All);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-28 02:31:42 +02:00
/***** Write average score per question *****/
2020-06-24 20:10:57 +02:00
HTM_TD_Begin ("class=\"DAT_N RM LINE_TOP LINE_BOTTOM COLOR%u\"",Gbl.RowEvenOdd);
HTM_Double2Decimals (NumTotalQsts->All ? TotalScore /
(double) NumTotalQsts->All :
0.0);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-28 02:31:42 +02:00
2019-11-28 00:19:42 +01:00
/***** Write total grade *****/
2020-06-24 20:10:57 +02:00
HTM_TD_Begin ("class=\"DAT_N RM LINE_TOP LINE_BOTTOM LINE_LEFT COLOR%u\"",Gbl.RowEvenOdd);
2019-12-14 13:35:35 +01:00
HTM_Double2Decimals (TotalGrade);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-28 02:31:42 +02:00
/***** Last cell *****/
2020-06-24 20:10:57 +02:00
HTM_TD_Begin ("class=\"DAT_N LINE_TOP LINE_BOTTOM LINE_LEFT COLOR%u\"",Gbl.RowEvenOdd);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-28 02:31:42 +02:00
/***** End row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-09-28 02:31:42 +02:00
}
/*****************************************************************************/
/******************* Show one match result of another user *******************/
/*****************************************************************************/
2020-04-02 03:28:08 +02:00
void MchRes_ShowOneMchResult (void)
2019-09-28 02:31:42 +02:00
{
extern const char *Hlp_ASSESSMENT_Games_results;
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
extern const char *Txt_START_END_TIME[Dat_NUM_START_END_TIME];
extern const char *Txt_Questions;
2020-06-22 19:27:23 +02:00
extern const char *Txt_Answers;
2019-09-28 02:31:42 +02:00
extern const char *Txt_Score;
2019-11-28 09:45:32 +01:00
extern const char *Txt_Grade;
2019-09-28 02:31:42 +02:00
extern const char *Txt_Tags;
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
struct Gam_Game Game;
struct Mch_Match Match;
2019-09-28 02:31:42 +02:00
Usr_MeOrOther_t MeOrOther;
struct UsrData *UsrDat;
Dat_StartEndTime_t StartEndTime;
2019-11-01 22:53:39 +01:00
char *Id;
2020-06-24 20:10:57 +02:00
struct MchPrn_Print Print;
2020-06-23 11:48:06 +02:00
struct MchRes_ICanView ICanView;
2019-09-28 02:31:42 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset games context *****/
2020-04-08 03:06:45 +02:00
Gam_ResetGames (&Games);
2020-04-23 23:09:28 +02:00
/***** Reset game and match *****/
Gam_ResetGame (&Game);
Mch_ResetMatch (&Match);
2019-09-29 22:38:32 +02:00
/***** Get and check parameters *****/
2020-04-08 03:06:45 +02:00
Mch_GetAndCheckParameters (&Games,&Game,&Match);
2019-09-28 02:31:42 +02:00
/***** Pointer to user's data *****/
MeOrOther = (Gbl.Action.Act == ActSeeOneMchResMe) ? Usr_ME :
Usr_OTHER;
switch (MeOrOther)
{
case Usr_ME:
UsrDat = &Gbl.Usrs.Me.UsrDat;
break;
case Usr_OTHER:
default:
UsrDat = &Gbl.Usrs.Other.UsrDat;
Usr_GetParamOtherUsrCodEncrypted (UsrDat);
break;
}
/***** Get match result data *****/
2020-06-24 20:10:57 +02:00
Print.MchCod = Match.MchCod;
Print.UsrCod = UsrDat->UsrCod;
2020-06-24 20:47:54 +02:00
MchPrn_GetMatchPrintDataByMchCodAndUsrCod (&Print);
2019-09-28 02:31:42 +02:00
2020-06-23 11:48:06 +02:00
/***** Check if I can view this match result and score *****/
MchRes_CheckIfICanSeeMatchResult (&Game,&Match,UsrDat->UsrCod,&ICanView);
2020-05-22 20:10:45 +02:00
2020-06-23 11:48:06 +02:00
if (ICanView.Result) // I am allowed to view this match result
2019-09-28 02:31:42 +02:00
{
/***** Get questions and user's answers of the match result from database *****/
2020-06-24 20:10:57 +02:00
Mch_GetMatchQuestionsFromDB (&Print);
2019-09-28 02:31:42 +02:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Match.Title,
NULL,NULL,
2019-09-28 02:31:42 +02:00
Hlp_ASSESSMENT_Games_results,Box_NOT_CLOSABLE);
Lay_WriteHeaderClassPhoto (false,false,
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Deg.DegCod,
Gbl.Hierarchy.Crs.CrsCod);
/***** Begin table *****/
HTM_TABLE_BeginWideMarginPadding (10);
/***** User *****/
/* Get data of the user who answer the match */
if (!Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (UsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CURRENT_CRS))
Err_WrongUserExit ();
if (!Usr_CheckIfICanViewTstExaMchResult (UsrDat))
Err_NoPermissionExit ();
/* User */
HTM_TR_Begin (NULL);
2019-09-28 02:31:42 +02:00
HTM_TD_Begin ("class=\"DAT_N RT\"");
HTM_TxtColon (Txt_ROLES_SINGUL_Abc[UsrDat->Roles.InCurrentCrs][UsrDat->Sex]);
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT LB\"");
ID_WriteUsrIDs (UsrDat,NULL);
HTM_TxtF ("&nbsp;%s",UsrDat->Surname1);
if (UsrDat->Surname2[0])
HTM_TxtF ("&nbsp;%s",UsrDat->Surname2);
if (UsrDat->FrstName[0])
HTM_TxtF (", %s",UsrDat->FrstName);
HTM_BR ();
Pho_ShowUsrPhotoIfAllowed (UsrDat,"PHOTO45x60",Pho_ZOOM,false);
HTM_TD_End ();
HTM_TR_End ();
/***** Start/end time (for user in this match) *****/
for (StartEndTime = (Dat_StartEndTime_t) 0;
StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
StartEndTime++)
{
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"DAT_N RT\"");
HTM_TxtColon (Txt_START_END_TIME[StartEndTime]);
HTM_TD_End ();
if (asprintf (&Id,"match_%u",(unsigned) StartEndTime) < 0)
Err_NotEnoughMemoryExit ();
HTM_TD_Begin ("id=\"%s\" class=\"DAT LB\"",Id);
Dat_WriteLocalDateHMSFromUTC (Id,Print.TimeUTC[StartEndTime],
Gbl.Prefs.DateFormat,Dat_SEPARATOR_COMMA,
true,true,true,0x7);
HTM_TD_End ();
free (Id);
HTM_TR_End ();
}
2019-10-07 17:36:41 +02:00
/***** Number of questions *****/
HTM_TR_Begin (NULL);
2019-10-07 17:36:41 +02:00
HTM_TD_Begin ("class=\"DAT_N RT\"");
HTM_TxtColon (Txt_Questions);
HTM_TD_End ();
2020-06-22 19:27:23 +02:00
HTM_TD_Begin ("class=\"DAT LB\"");
HTM_Unsigned (Print.NumQsts.All);
HTM_TD_End ();
2020-06-22 19:27:23 +02:00
HTM_TR_End ();
2020-06-22 19:27:23 +02:00
/***** Number of answers *****/
HTM_TR_Begin (NULL);
2020-06-22 19:27:23 +02:00
HTM_TD_Begin ("class=\"DAT_N RT\"");
HTM_TxtColon (Txt_Answers);
HTM_TD_End ();
2019-10-07 17:36:41 +02:00
HTM_TD_Begin ("class=\"DAT LB\"");
HTM_Unsigned (Print.NumQsts.NotBlank);
HTM_TD_End ();
2019-09-28 02:31:42 +02:00
HTM_TR_End ();
2019-10-07 17:36:41 +02:00
/***** Score *****/
HTM_TR_Begin (NULL);
2019-11-28 09:45:32 +01:00
HTM_TD_Begin ("class=\"DAT_N RT\"");
HTM_TxtColon (Txt_Score);
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT LB\"");
if (ICanView.Score)
{
HTM_STRONG_Begin ();
HTM_Double2Decimals (Print.Score);
HTM_Txt ("/");
HTM_Unsigned (Print.NumQsts.All);
HTM_STRONG_End ();
}
else
Ico_PutIconNotVisible ();
HTM_TD_End ();
HTM_TR_End ();
/***** Grade *****/
HTM_TR_Begin (NULL);
2019-11-28 09:45:32 +01:00
HTM_TD_Begin ("class=\"DAT_N RT\"");
HTM_TxtColon (Txt_Grade);
HTM_TD_End ();
2019-11-28 09:45:32 +01:00
HTM_TD_Begin ("class=\"DAT LB\"");
if (ICanView.Score)
{
HTM_STRONG_Begin ();
TstPrn_ComputeAndShowGrade (Print.NumQsts.All,Print.Score,Game.MaxGrade);
HTM_STRONG_End ();
}
else
Ico_PutIconNotVisible ();
HTM_TD_End ();
2019-10-07 17:36:41 +02:00
HTM_TR_End ();
2019-09-28 02:31:42 +02:00
/***** Tags present in this result *****/
HTM_TR_Begin (NULL);
2019-10-07 17:36:41 +02:00
HTM_TD_Begin ("class=\"DAT_N RT\"");
HTM_TxtColon (Txt_Tags);
HTM_TD_End ();
2019-10-07 17:36:41 +02:00
HTM_TD_Begin ("class=\"DAT LB\"");
Gam_ShowTstTagsPresentInAGame (Match.GamCod);
HTM_TD_End ();
2019-10-07 17:36:41 +02:00
HTM_TR_End ();
2019-09-28 02:31:42 +02:00
/***** Write answers and solutions *****/
TstPrn_ShowPrintAnswers (UsrDat,
Print.NumQsts.All,
Print.PrintedQuestions,
Print.TimeUTC,
Game.Visibility);
2019-09-28 02:31:42 +02:00
/***** End table *****/
HTM_TABLE_End ();
2019-09-28 02:31:42 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2019-09-28 02:31:42 +02:00
}
else // I am not allowed to view this match result
Err_NoPermissionExit ();
2019-09-28 02:31:42 +02:00
}
/*****************************************************************************/
2020-02-18 15:40:04 +01:00
/********************** Get if I can see match result ************************/
2019-09-28 02:31:42 +02:00
/*****************************************************************************/
2020-06-23 11:48:06 +02:00
static void MchRes_CheckIfICanSeeMatchResult (const struct Gam_Game *Game,
const struct Mch_Match *Match,
long UsrCod,
struct MchRes_ICanView *ICanView)
2019-09-28 02:31:42 +02:00
{
bool ItsMe;
2020-06-23 11:48:06 +02:00
/***** Check if I can view print result and score *****/
2019-09-28 02:31:42 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_STD:
2020-06-23 11:48:06 +02:00
// Depends on visibility of game and result (eye icons)
2019-09-28 02:31:42 +02:00
ItsMe = Usr_ItsMe (UsrCod);
2020-06-23 11:48:06 +02:00
ICanView->Result = (ItsMe && // The result is mine
!Game->Hidden && // The game is visible
Match->Status.ShowUsrResults); // The results of the match are visible to users
2020-06-19 13:37:45 +02:00
// Whether I belong or not to groups of match is not checked here...
// ...because I should be able to see old matches made in old groups to which I belonged
2019-09-28 02:31:42 +02:00
2020-06-23 11:48:06 +02:00
if (ICanView->Result)
// Depends on 5 visibility icons associated to game
ICanView->Score = TstVis_IsVisibleTotalScore (Game->Visibility);
else
ICanView->Score = false;
2020-02-18 15:40:04 +01:00
break;
case Rol_NET:
case Rol_TCH:
case Rol_DEG_ADM:
case Rol_CTR_ADM:
case Rol_INS_ADM:
case Rol_SYS_ADM:
2020-06-23 11:48:06 +02:00
ICanView->Result =
ICanView->Score = true;
break;
2020-02-18 15:40:04 +01:00
default:
2020-06-23 11:48:06 +02:00
ICanView->Result =
ICanView->Score = false;
break;
2019-09-28 02:31:42 +02:00
}
}