swad-core/swad_game.c

2958 lines
97 KiB
C
Raw Normal View History

2017-09-07 18:38:18 +02:00
// swad_game.c: games using remote control
2017-07-09 20:31:40 +02:00
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
2020-01-01 14:53:57 +01:00
Copyright (C) 1999-2020 Antonio Ca<EFBFBD>as Vargas
2017-07-09 20:31:40 +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 ***********************************/
/*****************************************************************************/
2018-10-22 09:04:08 +02:00
#define _GNU_SOURCE // For asprintf
2019-11-27 01:01:27 +01:00
#include <float.h> // For DBL_MAX
2017-07-09 20:31:40 +02:00
#include <linux/limits.h> // For PATH_MAX
2019-12-29 12:39:00 +01:00
#include <stddef.h> // For NULL
2018-10-22 09:04:08 +02:00
#include <stdio.h> // For asprintf
2017-07-09 20:31:40 +02:00
#include <stdlib.h> // For calloc
#include <string.h> // For string functions
#include "swad_database.h"
2020-04-14 17:15:17 +02:00
#include "swad_figure.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2017-09-07 18:38:18 +02:00
#include "swad_game.h"
2017-07-09 20:31:40 +02:00
#include "swad_global.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"
2019-09-28 02:31:42 +02:00
#include "swad_match_result.h"
2017-07-09 20:31:40 +02:00
#include "swad_pagination.h"
#include "swad_role.h"
2017-07-16 13:54:11 +02:00
#include "swad_test.h"
2020-02-18 15:40:04 +01:00
#include "swad_test_visibility.h"
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
2017-09-07 18:38:18 +02:00
#define Gam_MAX_CHARS_ANSWER (1024 - 1) // 1023
#define Gam_MAX_BYTES_ANSWER ((Gam_MAX_CHARS_ANSWER + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 16383
2017-07-09 20:31:40 +02:00
2017-09-07 18:38:18 +02:00
#define Gam_MAX_ANSWERS_PER_QUESTION 10
2017-07-09 20:31:40 +02:00
2020-04-16 21:03:22 +02:00
#define Gam_MAX_SELECTED_QUESTIONS 10000
2019-11-08 01:10:32 +01:00
#define Gam_MAX_BYTES_LIST_SELECTED_QUESTIONS (Gam_MAX_SELECTED_QUESTIONS * (Cns_MAX_DECIMAL_DIGITS_LONG + 1))
2017-07-18 20:34:32 +02:00
2019-11-27 22:03:25 +01:00
/* Score range [0...max.score]
will be converted to
grade range [0...max.grade]
Example: Game with 5 questions, unique-choice, 4 options per question
max.score = 5 * 1 = 5
min.score = 5 * (-0.33) = -1,67
max.grade given by teacher = 0.2 ==> min.grade = -0,067
grade
^
| /
max.grade--> +---------+
| /|
| / |
| / |
| / |
| / |
| / |
| / |
| / |
|/ |
------+---0-+---------+---------> score
^ /0 ^
min.score/ | max.score
| / | (num.questions)
| / |
|/ |
+-----+ <--min.grade
/ |
*/
#define Gam_MAX_GRADE_DEFAULT 1.0
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_ListAllGames (struct Gam_Games *Games);
2019-07-04 19:45:15 +02:00
static bool Gam_CheckIfICanEditGames (void);
2020-04-08 03:06:45 +02:00
static void Gam_PutIconsListGames (void *Games);
static void Gam_PutIconToCreateNewGame (struct Gam_Games *Games);
static void Gam_PutButtonToCreateNewGame (struct Gam_Games *Games);
static void Gam_PutParamsToCreateNewGame (void *Games);
static void Gam_ShowOneGame (struct Gam_Games *Games,
struct Gam_Game *Game,bool ShowOnlyThisGame);
2019-12-08 16:46:25 +01:00
2020-04-08 03:06:45 +02:00
static void Gam_PutIconToShowResultsOfGame (void *Games);
static void Gam_WriteAuthor (struct Gam_Game *Game);
2019-12-08 16:46:25 +01:00
2020-04-08 03:06:45 +02:00
static void Gam_PutHiddenParamGameOrder (Gam_Order_t SelectedOrder);
2017-07-09 20:31:40 +02:00
2020-04-08 03:06:45 +02:00
static void Gam_PutFormsToRemEditOneGame (struct Gam_Games *Games,
const struct Gam_Game *Game,
2019-05-20 08:52:07 +02:00
const char *Anchor);
2019-09-29 17:33:39 +02:00
2020-04-08 03:06:45 +02:00
static void Gam_PutParamsOneQst (void *Games);
static void Gam_PutHiddenParamOrder (Gam_Order_t SelectedOrder);
static Gam_Order_t Gam_GetParamOrder (void);
2017-07-09 20:31:40 +02:00
2017-09-07 18:38:18 +02:00
static void Gam_GetGameTxtFromDB (long GamCod,char Txt[Cns_MAX_BYTES_TEXT + 1]);
2017-07-09 20:31:40 +02:00
2019-09-27 21:45:53 +02:00
static void Gam_RemoveGameFromAllTables (long GamCod);
2020-04-08 03:06:45 +02:00
static bool Gam_CheckIfSimilarGameExists (const struct Gam_Game *Game);
2017-09-13 16:24:29 +02:00
2020-04-08 03:06:45 +02:00
static void Gam_PutFormsEditionGame (struct Gam_Games *Games,
struct Gam_Game *Game,
2020-03-08 19:13:38 +01:00
char Txt[Cns_MAX_BYTES_TEXT + 1],
bool ItsANewGame);
2020-04-08 03:06:45 +02:00
static void Gam_ReceiveGameFieldsFromForm (struct Gam_Game *Game,
2020-03-08 20:48:12 +01:00
char Txt[Cns_MAX_BYTES_TEXT + 1]);
2020-04-08 03:06:45 +02:00
static bool Gam_CheckGameFieldsReceivedFromForm (const struct Gam_Game *Game);
2019-10-03 09:22:09 +02:00
2020-04-08 03:06:45 +02:00
static void Gam_CreateGame (struct Gam_Game *Game,const char *Txt);
static void Gam_UpdateGame (struct Gam_Game *Game,const char *Txt);
2019-09-14 12:59:34 +02:00
2019-05-30 12:57:31 +02:00
static void Gam_RemAnswersOfAQuestion (long GamCod,unsigned QstInd);
2017-09-07 18:38:18 +02:00
2019-05-30 12:57:31 +02:00
static unsigned Gam_GetMaxQuestionIndexInGame (long GamCod);
2020-04-08 03:06:45 +02:00
static void Gam_ListGameQuestions (struct Gam_Games *Games,struct Gam_Game *Game);
static void Gam_ListOneOrMoreQuestionsForEdition (struct Gam_Games *Games,
long GamCod,unsigned NumQsts,
2019-09-30 12:45:45 +02:00
MYSQL_RES *mysql_res,
bool ICanEditQuestions);
2020-04-04 02:07:54 +02:00
static void Gam_ListQuestionForEdition (const struct Tst_Question *Question,
unsigned QstInd,bool QuestionExists);
2020-04-08 03:06:45 +02:00
static void Gam_PutIconToAddNewQuestions (void *Games);
static void Gam_PutButtonToAddNewQuestions (struct Gam_Games *Games);
2017-07-18 20:34:32 +02:00
2020-04-08 03:06:45 +02:00
static void Gam_AllocateListSelectedQuestions (struct Gam_Games *Games);
static void Gam_FreeListsSelectedQuestions (struct Gam_Games *Games);
static unsigned Gam_CountNumQuestionsInList (const struct Gam_Games *Games);
2017-07-18 20:34:32 +02:00
2017-09-11 19:06:46 +02:00
static void Gam_ExchangeQuestions (long GamCod,
unsigned QstIndTop,unsigned QstIndBottom);
2020-04-08 03:06:45 +02:00
static bool Gam_CheckIfEditable (const struct Gam_Game *Game);
/*****************************************************************************/
2020-04-23 23:09:28 +02:00
/*************************** Reset games context *****************************/
2020-04-08 03:06:45 +02:00
/*****************************************************************************/
void Gam_ResetGames (struct Gam_Games *Games)
{
Games->LstIsRead = false; // List not read from database...
Games->Num = 0; // Total number of games
Games->NumSelected = 0; // Number of games selected
Games->Lst = NULL; // List of games
Games->SelectedOrder = Gam_ORDER_DEFAULT;
Games->CurrentPage = 0;
Games->ListQuestions = NULL;
Games->GamCodsSelected = NULL; // String with selected game codes separated by separator multiple
Games->GamCod = -1L; // Selected/current game code
Games->MchCod = -1L; // Selected/current match code
Games->QstInd = 0; // Current question index
}
2019-09-26 21:40:25 +02:00
2020-04-23 23:09:28 +02:00
/*****************************************************************************/
/*************************** Initialize game to empty ************************/
/*****************************************************************************/
void Gam_ResetGame (struct Gam_Game *Game)
{
/***** Initialize to empty game *****/
Game->GamCod = -1L;
Game->CrsCod = -1L;
Game->UsrCod = -1L;
Game->MaxGrade = Gam_MAX_GRADE_DEFAULT;
Game->Visibility = TstVis_VISIBILITY_DEFAULT;
Game->TimeUTC[Dat_START_TIME] = (time_t) 0;
Game->TimeUTC[Dat_END_TIME ] = (time_t) 0;
Game->Title[0] = '\0';
Game->NumQsts = 0;
Game->NumMchs = 0;
Game->NumUnfinishedMchs = 0;
Game->Hidden = false;
}
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2019-09-26 23:57:10 +02:00
/***************************** List all games ********************************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2017-09-07 18:38:18 +02:00
void Gam_SeeAllGames (void)
2017-07-09 20:31:40 +02: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);
2017-07-09 20:31:40 +02:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
Gam_GetParams (&Games); // Return value ignored
2017-07-09 20:31:40 +02:00
2019-09-26 23:57:10 +02:00
/***** Show all games *****/
2020-04-08 03:06:45 +02:00
Gam_ListAllGames (&Games);
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
2017-09-07 18:38:18 +02:00
/**************************** Show all the games *****************************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_ListAllGames (struct Gam_Games *Games)
2017-07-09 20:31:40 +02:00
{
extern const char *Hlp_ASSESSMENT_Games;
extern const char *Txt_Games;
2019-07-04 17:17:15 +02:00
extern const char *Txt_GAMES_ORDER_HELP[Gam_NUM_ORDERS];
extern const char *Txt_GAMES_ORDER[Gam_NUM_ORDERS];
2019-09-26 01:15:21 +02:00
extern const char *Txt_Matches;
2017-07-09 20:31:40 +02:00
extern const char *Txt_No_games;
2017-09-07 18:38:18 +02:00
Gam_Order_t Order;
2017-07-09 20:31:40 +02:00
struct Pagination Pagination;
unsigned NumGame;
2020-04-08 03:06:45 +02:00
struct Gam_Game Game;
2017-07-09 20:31:40 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset game *****/
Gam_ResetGame (&Game);
2017-07-09 20:31:40 +02:00
/***** Get number of groups in current course *****/
2019-04-04 10:45:15 +02:00
if (!Gbl.Crs.Grps.NumGrps)
Gbl.Crs.Grps.WhichGrps = Grp_ALL_GROUPS;
2017-07-09 20:31:40 +02:00
/***** Get list of games *****/
2020-04-08 03:06:45 +02:00
Gam_GetListGames (Games,Games->SelectedOrder);
2017-07-09 20:31:40 +02:00
/***** Compute variables related to pagination *****/
2020-04-08 03:06:45 +02:00
Pagination.NumItems = Games->Num;
Pagination.CurrentPage = (int) Games->CurrentPage;
2017-07-09 20:31:40 +02:00
Pag_CalculatePagination (&Pagination);
2020-04-08 03:06:45 +02:00
Games->CurrentPage = (unsigned) Pagination.CurrentPage;
2017-07-09 20:31:40 +02:00
2019-12-06 22:18:05 +01:00
/***** Begin box *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin ("100%",Txt_Games,
2020-04-08 03:06:45 +02:00
Gam_PutIconsListGames,Games,
2019-12-06 22:18:05 +01:00
Hlp_ASSESSMENT_Games,Box_NOT_CLOSABLE);
2017-07-09 20:31:40 +02:00
/***** Write links to pages *****/
2020-04-10 19:14:08 +02:00
Pag_WriteLinksToPagesCentered (Pag_GAMES,&Pagination,
Games,-1L);
2017-07-09 20:31:40 +02:00
2020-04-08 03:06:45 +02:00
if (Games->Num)
2017-07-09 20:31:40 +02:00
{
/***** Table head *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWideMarginPadding (2);
HTM_TR_Begin (NULL);
2019-07-04 19:45:15 +02:00
if (Gam_CheckIfICanEditGames ())
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"CONTEXT_COL",NULL); // Column for contextual icons
2019-07-04 19:45:15 +02:00
2019-07-04 17:17:15 +02:00
for (Order = (Gam_Order_t) 0;
Order <= (Gam_Order_t) (Gam_NUM_ORDERS - 1);
2017-07-09 20:31:40 +02:00
Order++)
{
2019-10-23 19:05:05 +02:00
HTM_TH_Begin (1,1,"LM");
2017-07-09 20:31:40 +02:00
/* Form to change order */
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeAllGam);
2020-04-08 03:06:45 +02:00
Pag_PutHiddenParamPagNum (Pag_GAMES,Games->CurrentPage);
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (Txt_GAMES_ORDER_HELP[Order],"BT_LINK TIT_TBL",NULL);
2020-04-08 03:06:45 +02:00
if (Order == Games->SelectedOrder)
2019-11-10 16:41:47 +01:00
HTM_U_Begin ();
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_GAMES_ORDER[Order]);
2020-04-08 03:06:45 +02:00
if (Order == Games->SelectedOrder)
2019-11-10 16:41:47 +01:00
HTM_U_End ();
2019-11-18 14:21:01 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-07-09 20:31:40 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH_End ();
2017-07-09 20:31:40 +02:00
}
2019-09-26 01:15:21 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"RM",Txt_Matches);
2019-09-26 01:15:21 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2017-07-09 20:31:40 +02:00
2019-12-10 21:52:22 +01:00
/***** Write all games *****/
for (NumGame = Pagination.FirstItemVisible;
2017-07-09 20:31:40 +02:00
NumGame <= Pagination.LastItemVisible;
NumGame++)
2019-12-08 16:46:25 +01:00
{
/* Get data of this game */
2020-04-08 03:06:45 +02:00
Game.GamCod = Games->Lst[NumGame - 1].GamCod;
2019-12-08 16:46:25 +01:00
Gam_GetDataOfGameByCod (&Game);
/* Show game */
2020-04-08 03:06:45 +02:00
Gam_ShowOneGame (Games,
&Game,
2019-12-08 16:46:25 +01:00
false); // Do not show only this game
}
2017-07-09 20:31:40 +02:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2017-07-09 20:31:40 +02:00
}
else // No games created
2019-02-16 16:18:54 +01:00
Ale_ShowAlert (Ale_INFO,Txt_No_games);
2017-07-09 20:31:40 +02:00
2019-12-06 22:18:05 +01:00
/***** Write again links to pages *****/
2020-04-10 19:14:08 +02:00
Pag_WriteLinksToPagesCentered (Pag_GAMES,&Pagination,
Games,-1L);
2019-12-06 22:18:05 +01:00
2017-07-09 20:31:40 +02:00
/***** Button to create a new game *****/
2019-07-04 19:45:15 +02:00
if (Gam_CheckIfICanEditGames ())
2020-04-08 03:06:45 +02:00
Gam_PutButtonToCreateNewGame (Games);
2017-07-09 20:31:40 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2017-07-09 20:31:40 +02:00
/***** Free list of games *****/
2020-04-08 03:06:45 +02:00
Gam_FreeListGames (Games);
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
2019-09-29 18:44:40 +02:00
/************************ Check if I can edit games **************************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2019-07-04 19:45:15 +02:00
static bool Gam_CheckIfICanEditGames (void)
2017-07-09 20:31:40 +02:00
{
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_TCH:
case Rol_SYS_ADM:
return true;
default:
return false;
}
return false;
}
/*****************************************************************************/
/***************** Put contextual icons in list of games *******************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_PutIconsListGames (void *Games)
2017-07-09 20:31:40 +02:00
{
2020-04-08 03:06:45 +02:00
if (Games)
2019-12-06 19:36:22 +01:00
{
2020-03-26 02:54:30 +01:00
/***** Put icon to create a new game *****/
if (Gam_CheckIfICanEditGames ())
2020-04-08 03:06:45 +02:00
Gam_PutIconToCreateNewGame ((struct Gam_Games *) Games);
2020-03-26 02:54:30 +01:00
/***** Put icon to view matches results *****/
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_STD:
Ico_PutContextualIconToShowResults (ActSeeMyMchResCrs,NULL,
NULL,NULL);
break;
case Rol_NET:
case Rol_TCH:
case Rol_SYS_ADM:
Ico_PutContextualIconToShowResults (ActReqSeeAllMchRes,NULL,
NULL,NULL);
break;
default:
break;
}
2019-12-06 19:36:22 +01:00
2020-03-26 02:54:30 +01:00
/***** Put icon to show a figure *****/
2020-04-06 23:18:02 +02:00
Fig_PutIconToShowFigure (Fig_GAMES);
2020-03-26 02:54:30 +01:00
}
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
/********************** Put icon to create a new game **********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_PutIconToCreateNewGame (struct Gam_Games *Games)
2017-07-09 20:31:40 +02:00
{
extern const char *Txt_New_game;
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToAdd (ActFrmNewGam,NULL,
2020-04-08 03:06:45 +02:00
Gam_PutParamsToCreateNewGame,Games,
2019-01-10 15:26:33 +01:00
Txt_New_game);
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
/********************* Put button to create a new game *********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_PutButtonToCreateNewGame (struct Gam_Games *Games)
2017-07-09 20:31:40 +02:00
{
extern const char *Txt_New_game;
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActFrmNewGam);
2020-04-08 03:06:45 +02:00
Gam_PutParamsToCreateNewGame (Games);
2017-07-09 20:31:40 +02:00
Btn_PutConfirmButton (Txt_New_game);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
/******************* Put parameters to create a new game *******************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_PutParamsToCreateNewGame (void *Games)
2017-07-09 20:31:40 +02:00
{
2020-04-08 03:06:45 +02:00
if (Games)
2020-03-26 02:54:30 +01:00
{
2020-04-08 03:06:45 +02:00
Gam_PutHiddenParamGameOrder (((struct Gam_Games *) Games)->SelectedOrder);
Pag_PutHiddenParamPagNum (Pag_GAMES,((struct Gam_Games *) Games)->CurrentPage);
2020-03-26 02:54:30 +01:00
}
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
/****************************** Show one game ******************************/
/*****************************************************************************/
2017-09-07 18:38:18 +02:00
void Gam_SeeOneGame (void)
2017-07-09 20:31:40 +02:00
{
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);
2017-07-09 20:31:40 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset game *****/
Gam_ResetGame (&Game);
2017-07-09 20:31:40 +02:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
2017-07-09 20:31:40 +02:00
Lay_ShowErrorAndExit ("Code of game is missing.");
2019-12-08 23:19:16 +01:00
Gam_GetDataOfGameByCod (&Game);
2017-07-09 20:31:40 +02:00
/***** Show game *****/
2020-04-08 03:06:45 +02:00
Gam_ShowOnlyOneGame (&Games,&Game,
2019-12-08 16:46:25 +01:00
false, // Do not list game questions
false); // Do not put form to start new match
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
2017-09-13 16:24:29 +02:00
/******************************* Show one game *******************************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
void Gam_ShowOnlyOneGame (struct Gam_Games *Games,
struct Gam_Game *Game,
2019-12-08 16:46:25 +01:00
bool ListGameQuestions,
bool PutFormNewMatch)
2019-12-08 17:08:15 +01:00
{
2020-04-08 03:06:45 +02:00
Gam_ShowOnlyOneGameBegin (Games,Game,ListGameQuestions,PutFormNewMatch);
2019-12-08 17:08:15 +01:00
Gam_ShowOnlyOneGameEnd ();
}
2020-04-08 03:06:45 +02:00
void Gam_ShowOnlyOneGameBegin (struct Gam_Games *Games,
struct Gam_Game *Game,
2019-12-08 17:08:15 +01:00
bool ListGameQuestions,
bool PutFormNewMatch)
2017-07-09 20:31:40 +02:00
{
extern const char *Hlp_ASSESSMENT_Games;
extern const char *Txt_Game;
2019-12-08 16:46:25 +01:00
/***** Begin box *****/
2020-04-08 03:06:45 +02:00
Games->GamCod = Game->GamCod;
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_Game,
2020-04-08 03:06:45 +02:00
Gam_PutIconToShowResultsOfGame,Games,
2019-12-08 16:46:25 +01:00
Hlp_ASSESSMENT_Games,Box_NOT_CLOSABLE);
/***** Show game *****/
2020-04-08 03:06:45 +02:00
Gam_ShowOneGame (Games,
Game,
2019-12-08 16:46:25 +01:00
true); // Show only this game
if (ListGameQuestions)
/***** Write questions of this game *****/
2020-04-08 03:06:45 +02:00
Gam_ListGameQuestions (Games,Game);
2019-12-08 16:46:25 +01:00
else
/***** List matches *****/
2020-04-08 03:06:45 +02:00
Mch_ListMatches (Games,Game,PutFormNewMatch);
2019-12-08 17:08:15 +01:00
}
2019-12-08 16:46:25 +01:00
2019-12-08 17:08:15 +01:00
void Gam_ShowOnlyOneGameEnd (void)
{
2019-12-08 16:46:25 +01:00
/***** End box *****/
Box_BoxEnd ();
}
2020-04-08 03:06:45 +02:00
static void Gam_ShowOneGame (struct Gam_Games *Games,
struct Gam_Game *Game,bool ShowOnlyThisGame)
2019-12-08 16:46:25 +01:00
{
2017-07-09 20:31:40 +02:00
extern const char *Txt_View_game;
extern const char *Txt_No_of_questions;
2020-02-18 15:40:04 +01:00
extern const char *Txt_Maximum_grade;
extern const char *Txt_Result_visibility;
2019-09-26 01:15:21 +02:00
extern const char *Txt_Matches;
2019-04-20 22:40:57 +02:00
char *Anchor = NULL;
2017-07-09 20:31:40 +02:00
static unsigned UniqueId = 0;
2019-11-01 22:53:39 +01:00
char *Id;
2019-09-27 00:25:40 +02:00
Dat_StartEndTime_t StartEndTime;
2019-12-10 21:52:22 +01:00
const char *Color;
2017-07-09 20:31:40 +02:00
char Txt[Cns_MAX_BYTES_TEXT + 1];
2019-04-20 22:40:57 +02:00
/***** Set anchor string *****/
2019-12-08 16:46:25 +01:00
Frm_SetAnchorStr (Game->GamCod,&Anchor);
2019-04-20 22:40:57 +02:00
2019-12-08 16:46:25 +01:00
/***** Begin box and table *****/
2017-09-13 16:24:29 +02:00
if (ShowOnlyThisGame)
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWidePadding (2);
2017-07-09 20:31:40 +02:00
2019-05-20 08:52:07 +02:00
/***** Start first row of this game *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-05-20 08:52:07 +02:00
/***** Icons related to this game *****/
2019-09-29 20:00:54 +02:00
if (Gam_CheckIfICanEditGames ())
2019-07-04 19:45:15 +02:00
{
2019-10-08 23:28:51 +02:00
if (ShowOnlyThisGame)
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("rowspan=\"2\" class=\"CONTEXT_COL\"");
2019-10-08 23:28:51 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("rowspan=\"2\" class=\"CONTEXT_COL COLOR%u\"",Gbl.RowEvenOdd);
2019-07-04 19:45:15 +02:00
2019-05-20 08:52:07 +02:00
/* Icons to remove/edit this game */
2020-04-08 03:06:45 +02:00
Gam_PutFormsToRemEditOneGame (Games,Game,Anchor);
2019-05-20 08:52:07 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-07-04 19:45:15 +02:00
}
2017-07-09 20:31:40 +02:00
2019-09-27 00:25:40 +02:00
/***** Start/end date/time *****/
2017-07-09 20:31:40 +02:00
UniqueId++;
2019-12-10 21:52:22 +01:00
for (StartEndTime = (Dat_StartEndTime_t) 0;
2019-09-27 00:25:40 +02:00
StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
StartEndTime++)
{
2019-11-01 22:53:39 +01:00
if (asprintf (&Id,"gam_date_%u_%u",(unsigned) StartEndTime,UniqueId) < 0)
Lay_NotEnoughMemoryExit ();
2019-12-10 21:52:22 +01:00
Color = Game->NumUnfinishedMchs ? (Game->Hidden ? "DATE_GREEN_LIGHT":
"DATE_GREEN") :
(Game->Hidden ? "DATE_RED_LIGHT":
"DATE_RED");
2019-10-08 23:28:51 +02:00
if (ShowOnlyThisGame)
2019-11-01 22:53:39 +01:00
HTM_TD_Begin ("id=\"%s\" class=\"%s LT\"",
2019-12-10 21:52:22 +01:00
Id,Color);
2019-10-08 23:28:51 +02:00
else
2019-11-01 22:53:39 +01:00
HTM_TD_Begin ("id=\"%s\" class=\"%s LT COLOR%u\"",
2019-12-10 21:52:22 +01:00
Id,Color,Gbl.RowEvenOdd);
2019-12-08 16:46:25 +01:00
if (Game->TimeUTC[Dat_START_TIME])
Dat_WriteLocalDateHMSFromUTC (Id,Game->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,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-27 00:25:40 +02:00
}
2017-07-09 20:31:40 +02:00
2019-05-20 08:52:07 +02:00
/***** Game title and main data *****/
2019-10-08 23:28:51 +02:00
if (ShowOnlyThisGame)
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2019-10-08 23:28:51 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd);
2019-05-20 08:52:07 +02:00
/* Game title */
2020-04-08 03:06:45 +02:00
Games->GamCod = Game->GamCod;
2019-10-26 01:56:36 +02:00
HTM_ARTICLE_Begin (Anchor);
2019-05-20 08:52:07 +02:00
Frm_StartForm (ActSeeGam);
2020-04-08 03:06:45 +02:00
Gam_PutParams (Games);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (Txt_View_game,
2019-12-13 18:22:59 +01:00
Game->Hidden ? "BT_LINK LT ASG_TITLE_LIGHT":
"BT_LINK LT ASG_TITLE",
2019-11-20 11:04:54 +01:00
NULL);
2019-12-08 16:46:25 +01:00
HTM_Txt (Game->Title);
2019-11-18 14:21:01 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-26 01:56:36 +02:00
HTM_ARTICLE_End ();
2017-07-09 20:31:40 +02:00
2020-02-18 15:40:04 +01:00
/* Number of questions, maximum grade, visibility of results */
2019-12-08 16:46:25 +01:00
HTM_DIV_Begin ("class=\"%s\"",Game->Hidden ? "ASG_GRP_LIGHT" :
"ASG_GRP");
2020-01-11 15:22:02 +01:00
HTM_TxtColonNBSP (Txt_No_of_questions);
HTM_Unsigned (Game->NumQsts);
2019-11-27 22:15:10 +01:00
HTM_BR ();
2020-01-11 15:22:02 +01:00
HTM_TxtColonNBSP (Txt_Maximum_grade);
HTM_Double (Game->MaxGrade);
2020-02-19 01:55:32 +01:00
HTM_BR ();
HTM_TxtColonNBSP (Txt_Result_visibility);
2020-04-02 03:28:08 +02:00
TstVis_ShowVisibilityIcons (Game->Visibility,Game->Hidden);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2017-07-09 20:31:40 +02:00
2019-09-26 01:15:21 +02:00
/***** Number of matches in game *****/
2019-10-08 23:28:51 +02:00
if (ShowOnlyThisGame)
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"RT\"");
2019-10-08 23:28:51 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"RT COLOR%u\"",Gbl.RowEvenOdd);
2019-09-26 01:15:21 +02:00
2020-04-08 03:06:45 +02:00
Games->GamCod = Game->GamCod;
2019-09-26 01:15:21 +02:00
Frm_StartForm (ActSeeGam);
2020-04-08 03:06:45 +02:00
Gam_PutParams (Games);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (Txt_Matches,
2019-12-13 18:22:59 +01:00
Game->Hidden ? "BT_LINK LT ASG_TITLE_LIGHT" :
"BT_LINK LT ASG_TITLE",
2019-11-20 11:04:54 +01:00
NULL);
2019-09-26 01:15:21 +02:00
if (ShowOnlyThisGame)
2020-01-11 15:22:02 +01:00
HTM_TxtColonNBSP (Txt_Matches);
2019-12-08 16:46:25 +01:00
HTM_Unsigned (Game->NumMchs);
2019-11-18 14:21:01 +01:00
HTM_BUTTON_End ();
2019-09-26 01:15:21 +02:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-09-26 01:15:21 +02:00
2019-05-20 08:52:07 +02:00
/***** End 1st row of this game *****/
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2017-07-09 20:31:40 +02:00
2019-05-20 08:52:07 +02:00
/***** Start 2nd row of this game *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-05-20 10:35:57 +02:00
/***** Author of the game *****/
2019-10-08 23:28:51 +02:00
if (ShowOnlyThisGame)
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("colspan=\"2\" class=\"LT\"");
2019-10-08 23:28:51 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("colspan=\"2\" class=\"LT COLOR%u\"",Gbl.RowEvenOdd);
2019-12-08 16:46:25 +01:00
Gam_WriteAuthor (Game);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-07-09 20:31:40 +02:00
2019-05-20 10:35:57 +02:00
/***** Text of the game *****/
2019-10-08 23:28:51 +02:00
if (ShowOnlyThisGame)
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("colspan=\"2\" class=\"LT\"");
2019-10-08 23:28:51 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("colspan=\"2\" class=\"LT COLOR%u\"",Gbl.RowEvenOdd);
2019-12-08 16:46:25 +01:00
Gam_GetGameTxtFromDB (Game->GamCod,Txt);
2017-07-09 20:31:40 +02:00
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
Txt,Cns_MAX_BYTES_TEXT,false); // Convert from HTML to rigorous HTML
Str_InsertLinks (Txt,Cns_MAX_BYTES_TEXT,60); // Insert links
2019-12-08 16:46:25 +01:00
HTM_DIV_Begin ("class=\"PAR %s\"",Game->Hidden ? "DAT_LIGHT" :
"DAT");
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-07-09 20:31:40 +02:00
2019-05-20 10:35:57 +02:00
/***** End 2nd row of this game *****/
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-05-20 10:35:57 +02:00
2017-09-13 16:24:29 +02:00
/***** End table *****/
if (ShowOnlyThisGame)
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2017-09-13 16:24:29 +02:00
else
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
2019-04-20 22:40:57 +02:00
/***** Free anchor string *****/
Frm_FreeAnchorStr (Anchor);
2017-07-09 20:31:40 +02:00
}
2019-12-07 02:12:13 +01:00
/*****************************************************************************/
/************* Put icon to show results of matches in a game *****************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_PutIconToShowResultsOfGame (void *Games)
2019-12-07 02:12:13 +01:00
{
2020-04-08 03:06:45 +02:00
if (Games)
2019-12-07 02:12:13 +01:00
{
2020-03-26 02:54:30 +01:00
/***** Put icon to view matches results *****/
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_STD:
2020-04-02 03:28:08 +02:00
Ico_PutContextualIconToShowResults (ActSeeMyMchResGam,MchRes_RESULTS_BOX_ID,
2020-04-08 03:06:45 +02:00
Gam_PutParams,Games);
2020-03-26 02:54:30 +01:00
break;
case Rol_NET:
case Rol_TCH:
case Rol_SYS_ADM:
2020-04-02 03:28:08 +02:00
Ico_PutContextualIconToShowResults (ActSeeAllMchResGam,MchRes_RESULTS_BOX_ID,
2020-04-08 03:06:45 +02:00
Gam_PutParams,Games);
2020-03-26 02:54:30 +01:00
break;
default:
break;
}
2019-12-07 02:12:13 +01:00
}
}
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
/*********************** Write the author of a game ************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_WriteAuthor (struct Gam_Game *Game)
2017-07-09 20:31:40 +02:00
{
2019-09-29 20:00:54 +02:00
Usr_WriteAuthor1Line (Game->UsrCod,Game->Hidden);
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
2017-09-13 21:22:52 +02:00
/****** Put a hidden parameter with the type of order in list of games *******/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_PutHiddenParamGameOrder (Gam_Order_t SelectedOrder)
2017-07-09 20:31:40 +02:00
{
2020-04-08 03:06:45 +02:00
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) SelectedOrder);
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
2017-09-01 14:36:25 +02:00
/******************** Put a link (form) to edit one game *********************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_PutFormsToRemEditOneGame (struct Gam_Games *Games,
const struct Gam_Game *Game,
2019-05-20 08:52:07 +02:00
const char *Anchor)
2017-07-09 20:31:40 +02:00
{
2020-04-08 03:06:45 +02:00
Games->GamCod = Game->GamCod;
2019-09-29 22:38:32 +02:00
2017-09-13 12:25:45 +02:00
/***** Put icon to remove game *****/
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToRemove (ActReqRemGam,
2020-04-08 03:06:45 +02:00
Gam_PutParams,Games);
2017-07-09 20:31:40 +02:00
2019-09-29 20:00:54 +02:00
/***** Put icon to unhide/hide game *****/
if (Game->Hidden)
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToUnhide (ActShoGam,Anchor,
2020-04-08 03:06:45 +02:00
Gam_PutParams,Games);
2019-09-29 20:00:54 +02:00
else
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToHide (ActHidGam,Anchor,
2020-04-08 03:06:45 +02:00
Gam_PutParams,Games);
2017-07-09 20:31:40 +02:00
2017-09-13 12:25:45 +02:00
/***** Put icon to edit game *****/
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToEdit (ActEdiOneGam,NULL,
2020-04-08 03:06:45 +02:00
Gam_PutParams,Games);
2020-02-26 00:26:07 +01:00
}
/*****************************************************************************/
/**************** Put parameter to move/remove one question ******************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_PutParamsOneQst (void *Games)
2020-02-26 00:26:07 +01:00
{
2020-04-08 03:06:45 +02:00
if (Games)
2020-03-26 02:54:30 +01:00
{
2020-04-08 03:06:45 +02:00
Gam_PutParams (Games);
Gam_PutParamQstInd (((struct Gam_Games *) Games)->QstInd);
2020-03-26 02:54:30 +01:00
}
2020-02-26 00:26:07 +01:00
}
2017-12-20 19:01:49 +01:00
/*****************************************************************************/
2019-09-29 17:33:39 +02:00
/*********************** Params used to edit a game **************************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
void Gam_PutParams (void *Games)
2019-12-07 02:12:13 +01:00
{
2020-03-27 14:56:54 +01:00
Grp_WhichGroups_t WhichGroups;
2020-04-08 03:06:45 +02:00
if (Games)
2020-03-26 02:54:30 +01:00
{
2020-04-08 03:06:45 +02:00
if (((struct Gam_Games *) Games)->GamCod > 0)
Gam_PutParamGameCod (((struct Gam_Games *) Games)->GamCod);
Gam_PutHiddenParamOrder (((struct Gam_Games *) Games)->SelectedOrder);
2020-03-27 14:56:54 +01:00
WhichGroups = Grp_GetParamWhichGroups ();
Grp_PutParamWhichGroups (&WhichGroups);
2020-04-08 03:06:45 +02:00
Pag_PutHiddenParamPagNum (Pag_GAMES,((struct Gam_Games *) Games)->CurrentPage);
2020-03-26 02:54:30 +01:00
}
2019-12-07 02:12:13 +01:00
}
/*****************************************************************************/
/******************** Write parameter with code of game **********************/
/*****************************************************************************/
void Gam_PutParamGameCod (long GamCod)
{
Par_PutHiddenParamLong (NULL,"GamCod",GamCod);
}
/*****************************************************************************/
/********************* Get parameter with code of game ***********************/
/*****************************************************************************/
long Gam_GetParamGameCod (void)
{
/***** Get code of game *****/
return Par_GetParToLong ("GamCod");
2017-07-09 20:31:40 +02:00
}
2019-09-29 17:33:39 +02:00
/*****************************************************************************/
/******************* Get parameters used to edit a game **********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
long Gam_GetParams (struct Gam_Games *Games)
2019-09-29 17:33:39 +02:00
{
/***** Get other parameters *****/
2020-04-08 03:06:45 +02:00
Games->SelectedOrder = Gam_GetParamOrder ();
Games->CurrentPage = Pag_GetParamPagNum (Pag_GAMES);
2019-09-29 17:33:39 +02:00
/***** Get game code *****/
return Gam_GetParamGameCod ();
}
2019-07-04 17:17:15 +02:00
/*****************************************************************************/
/****** Put a hidden parameter with the type of order in list of games *******/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_PutHiddenParamOrder (Gam_Order_t SelectedOrder)
2019-07-04 17:17:15 +02:00
{
2020-04-08 03:06:45 +02:00
if (SelectedOrder != Gam_ORDER_DEFAULT)
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) SelectedOrder);
2019-07-04 17:17:15 +02:00
}
/*****************************************************************************/
/********** Get parameter with the type or order in list of games ************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static Gam_Order_t Gam_GetParamOrder (void)
2019-07-04 17:17:15 +02:00
{
2020-04-08 03:06:45 +02:00
return (Gam_Order_t) Par_GetParToUnsignedLong ("Order",
0,
Gam_NUM_ORDERS - 1,
(unsigned long) Gam_ORDER_DEFAULT);
2019-07-04 17:17:15 +02:00
}
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
/*********************** Get list of all the games *************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
void Gam_GetListGames (struct Gam_Games *Games,Gam_Order_t SelectedOrder)
2017-07-09 20:31:40 +02:00
{
2019-01-03 15:25:18 +01:00
static const char *OrderBySubQuery[Gam_NUM_ORDERS] =
{
2019-11-21 01:27:17 +01:00
[Gam_ORDER_BY_START_DATE] = "StartTime DESC,EndTime DESC,gam_games.Title DESC",
[Gam_ORDER_BY_END_DATE ] = "EndTime DESC,StartTime DESC,gam_games.Title DESC",
2019-11-25 23:18:08 +01:00
[Gam_ORDER_BY_TITLE ] = "gam_games.Title",
2019-01-03 15:25:18 +01:00
};
2017-07-09 20:31:40 +02:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2019-09-28 14:46:51 +02:00
char *HiddenSubQuery;
2018-10-31 10:19:01 +01:00
unsigned long NumRows = 0; // Initialized to avoid warning
2017-07-09 20:31:40 +02:00
unsigned NumGame;
/***** Free list of games *****/
2020-04-08 03:06:45 +02:00
if (Games->LstIsRead)
Gam_FreeListGames (Games);
2017-07-09 20:31:40 +02:00
2019-09-28 14:46:51 +02:00
/***** Subquery: get hidden games depending on user's role *****/
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_STD:
2019-12-01 21:34:50 +01:00
if (asprintf (&HiddenSubQuery," AND gam_games.Hidden='N'") < 0)
2019-09-28 14:46:51 +02:00
Lay_NotEnoughMemoryExit ();
break;
case Rol_NET:
case Rol_TCH:
case Rol_DEG_ADM:
case Rol_CTR_ADM:
case Rol_INS_ADM:
case Rol_SYS_ADM:
if (asprintf (&HiddenSubQuery,"%s","") < 0)
Lay_NotEnoughMemoryExit ();
break;
default:
2019-09-28 15:03:22 +02:00
Rol_WrongRoleExit ();
2019-09-28 14:46:51 +02:00
break;
}
2017-07-09 20:31:40 +02:00
/***** Get list of games from database *****/
2019-05-20 08:52:07 +02:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get games",
2019-09-28 14:46:51 +02:00
"SELECT gam_games.GamCod," // row[0]
"MIN(mch_matches.StartTime) AS StartTime," // row[1]
"MAX(mch_matches.EndTime) AS EndTime" // row[2]
2019-09-17 01:37:07 +02:00
" FROM gam_games"
" LEFT JOIN mch_matches"
" ON gam_games.GamCod=mch_matches.GamCod"
" WHERE gam_games.CrsCod=%ld"
2019-09-28 14:46:51 +02:00
"%s"
2019-09-17 01:37:07 +02:00
" GROUP BY gam_games.GamCod"
2019-05-20 08:52:07 +02:00
" ORDER BY %s",
2019-05-28 15:06:53 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2019-09-28 14:46:51 +02:00
HiddenSubQuery,
2019-11-25 23:18:08 +01:00
OrderBySubQuery[SelectedOrder]);
2019-09-28 14:46:51 +02:00
/***** Free allocated memory for subquery *****/
2019-11-06 19:45:20 +01:00
free (HiddenSubQuery);
2019-09-28 14:46:51 +02:00
2017-07-09 20:31:40 +02:00
if (NumRows) // Games found...
{
2020-04-08 03:06:45 +02:00
Games->Num = (unsigned) NumRows;
2017-07-09 20:31:40 +02:00
/***** Create list of games *****/
2020-04-08 03:06:45 +02:00
if ((Games->Lst = (struct Gam_GameSelected *) malloc (NumRows * sizeof (struct Gam_GameSelected))) == NULL)
2018-10-18 20:06:54 +02:00
Lay_NotEnoughMemoryExit ();
2017-07-09 20:31:40 +02:00
/***** Get the games codes *****/
for (NumGame = 0;
2020-04-08 03:06:45 +02:00
NumGame < Games->Num;
2017-07-09 20:31:40 +02:00
NumGame++)
{
2019-09-28 14:46:51 +02:00
/* Get next game code (row[0]) */
2017-07-09 20:31:40 +02:00
row = mysql_fetch_row (mysql_res);
2020-04-08 03:06:45 +02:00
if ((Games->Lst[NumGame].GamCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
2017-07-09 20:31:40 +02:00
Lay_ShowErrorAndExit ("Error: wrong game code.");
}
}
else
2020-04-08 03:06:45 +02:00
Games->Num = 0;
2017-07-09 20:31:40 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2020-04-08 03:06:45 +02:00
Games->LstIsRead = true;
2017-07-09 20:31:40 +02:00
}
2019-11-25 23:18:08 +01:00
/*****************************************************************************/
/********************* Get list of game events selected **********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
void Gam_GetListSelectedGamCods (struct Gam_Games *Games)
2019-11-25 23:18:08 +01:00
{
unsigned MaxSizeListGamCodsSelected;
unsigned NumGame;
const char *Ptr;
long GamCod;
char LongStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1];
/***** Allocate memory for list of games selected *****/
2020-04-08 03:06:45 +02:00
MaxSizeListGamCodsSelected = Games->Num * (Cns_MAX_DECIMAL_DIGITS_LONG + 1);
if ((Games->GamCodsSelected = (char *) malloc (MaxSizeListGamCodsSelected + 1)) == NULL)
2019-11-25 23:18:08 +01:00
Lay_NotEnoughMemoryExit ();
/***** Get parameter multiple with list of games selected *****/
2020-04-08 03:06:45 +02:00
Par_GetParMultiToText ("GamCod",Games->GamCodsSelected,MaxSizeListGamCodsSelected);
2019-11-25 23:18:08 +01:00
/***** Set which games will be shown as selected (checkboxes on) *****/
2020-04-08 03:06:45 +02:00
if (Games->GamCodsSelected[0]) // Some games selected
2019-11-25 23:18:08 +01:00
{
/* Reset selection */
for (NumGame = 0;
2020-04-08 03:06:45 +02:00
NumGame < Games->Num;
2019-11-25 23:18:08 +01:00
NumGame++)
2020-04-08 03:06:45 +02:00
Games->Lst[NumGame].Selected = false;
Games->NumSelected = 0;
2019-11-25 23:18:08 +01:00
/* Set some games as selected */
2020-04-08 03:06:45 +02:00
for (Ptr = Games->GamCodsSelected;
2019-11-25 23:18:08 +01:00
*Ptr;
)
{
/* Get next game selected */
Par_GetNextStrUntilSeparParamMult (&Ptr,LongStr,Cns_MAX_DECIMAL_DIGITS_LONG);
GamCod = Str_ConvertStrCodToLongCod (LongStr);
/* Set each game in *StrGamCodsSelected as selected */
for (NumGame = 0;
2020-04-08 03:06:45 +02:00
NumGame < Games->Num;
2019-11-25 23:18:08 +01:00
NumGame++)
2020-04-08 03:06:45 +02:00
if (Games->Lst[NumGame].GamCod == GamCod)
2019-11-25 23:18:08 +01:00
{
2020-04-08 03:06:45 +02:00
Games->Lst[NumGame].Selected = true;
Games->NumSelected++;
2019-11-25 23:18:08 +01:00
break;
}
}
}
2019-12-08 13:34:12 +01:00
else // No games selected
2019-11-25 23:18:08 +01:00
{
/***** Set all games as selected *****/
for (NumGame = 0;
2020-04-08 03:06:45 +02:00
NumGame < Games->Num;
2019-11-25 23:18:08 +01:00
NumGame++)
2020-04-08 03:06:45 +02:00
Games->Lst[NumGame].Selected = true;
Games->NumSelected = Games->Num;
2019-11-25 23:18:08 +01:00
}
}
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2019-05-28 15:06:53 +02:00
/********************** Get game data using its code *************************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
void Gam_GetDataOfGameByCod (struct Gam_Game *Game)
2017-07-09 20:31:40 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
/***** Get data of game from database *****/
2018-10-31 10:19:01 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get game data",
2019-09-17 01:37:07 +02:00
"SELECT gam_games.GamCod," // row[0]
2019-09-27 20:00:47 +02:00
"gam_games.CrsCod," // row[1]
"gam_games.Hidden," // row[2]
"gam_games.UsrCod," // row[3]
2019-11-27 22:03:25 +01:00
"gam_games.MaxGrade," // row[4]
2020-02-18 15:40:04 +01:00
"gam_games.Visibility," // row[5]
"gam_games.Title" // row[6]
2019-09-17 01:37:07 +02:00
" FROM gam_games"
" LEFT JOIN mch_matches"
" ON gam_games.GamCod=mch_matches.GamCod"
" WHERE gam_games.GamCod=%ld",
2018-10-31 10:19:01 +01:00
Game->GamCod);
2017-07-09 20:31:40 +02:00
if (NumRows) // Game found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get code of the game (row[0]) */
Game->GamCod = Str_ConvertStrCodToLongCod (row[0]);
2019-09-27 20:00:47 +02:00
/* Get code of the course (row[1]) */
Game->CrsCod = Str_ConvertStrCodToLongCod (row[1]);
2017-07-09 20:31:40 +02:00
2019-09-27 20:00:47 +02:00
/* Get whether the game is hidden (row[2]) */
2019-09-29 20:00:54 +02:00
Game->Hidden = (row[2][0] == 'Y');
2017-07-09 20:31:40 +02:00
2019-09-27 20:00:47 +02:00
/* Get author of the game (row[3]) */
Game->UsrCod = Str_ConvertStrCodToLongCod (row[3]);
2019-11-27 22:03:25 +01:00
/* Get maximum grade (row[4]) */
Game->MaxGrade = Str_GetDoubleFromStr (row[4]);
2019-11-28 01:41:13 +01:00
if (Game->MaxGrade < 0.0) // Only positive values allowed
Game->MaxGrade = 0.0;
2019-11-27 22:03:25 +01:00
2020-02-18 15:40:04 +01:00
/* Get visibility (row[5]) */
2020-04-02 03:28:08 +02:00
Game->Visibility = TstVis_GetVisibilityFromStr (row[5]);
2020-02-18 15:40:04 +01:00
/* Get the title of the game (row[6]) */
Str_Copy (Game->Title,row[6],
2019-05-28 15:06:53 +02:00
Gam_MAX_BYTES_TITLE);
2017-07-09 20:31:40 +02:00
2019-07-17 19:39:35 +02:00
/* Get number of questions */
2017-09-07 18:38:18 +02:00
Game->NumQsts = Gam_GetNumQstsGame (Game->GamCod);
2017-07-09 20:31:40 +02:00
2019-09-26 01:15:21 +02:00
/* Get number of matches */
2019-09-28 02:31:42 +02:00
Game->NumMchs = Mch_GetNumMchsInGame (Game->GamCod);
2019-12-10 21:52:22 +01:00
/* Get number of unfinished matches */
Game->NumUnfinishedMchs = Mch_GetNumUnfinishedMchsInGame (Game->GamCod);
2017-07-09 20:31:40 +02:00
}
else
/* Initialize to empty game */
2019-09-27 20:22:32 +02:00
Gam_ResetGame (Game);
2017-07-09 20:31:40 +02:00
2019-07-04 16:06:31 +02:00
/* Free structure that stores the query result */
2017-07-09 20:31:40 +02:00
DB_FreeMySQLResult (&mysql_res);
2019-07-04 16:06:31 +02:00
if (Game->GamCod > 0)
{
/***** Get start and end times from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get game data",
"SELECT UNIX_TIMESTAMP(MIN(StartTime))," // row[0]
2019-07-09 22:44:41 +02:00
"UNIX_TIMESTAMP(MAX(EndTime))" // row[1]
2019-09-17 01:37:07 +02:00
" FROM mch_matches"
2019-07-04 16:06:31 +02:00
" WHERE GamCod=%ld",
Game->GamCod);
if (NumRows)
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get start date (row[0] holds the start UTC time) */
2019-09-22 19:50:24 +02:00
Game->TimeUTC[Dat_START_TIME] = Dat_GetUNIXTimeFromStr (row[0]);
2019-07-04 16:06:31 +02:00
/* Get end date (row[1] holds the end UTC time) */
2019-09-22 19:50:24 +02:00
Game->TimeUTC[Dat_END_TIME ] = Dat_GetUNIXTimeFromStr (row[1]);
2019-07-04 16:06:31 +02:00
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
}
else
{
2019-09-22 19:50:24 +02:00
Game->TimeUTC[Dat_START_TIME] =
Game->TimeUTC[Dat_END_TIME ] = (time_t) 0;
2019-07-04 16:06:31 +02:00
}
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
2019-05-28 15:06:53 +02:00
/***************************** Free list of games ****************************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
void Gam_FreeListGames (struct Gam_Games *Games)
2017-07-09 20:31:40 +02:00
{
2020-04-08 03:06:45 +02:00
if (Games->LstIsRead && Games->Lst)
2017-07-09 20:31:40 +02:00
{
/***** Free memory used by the list of games *****/
2020-04-08 03:06:45 +02:00
free (Games->Lst);
Games->Lst = NULL;
Games->Num = 0;
Games->LstIsRead = false;
2017-07-09 20:31:40 +02:00
}
}
/*****************************************************************************/
/********************** Get game text from database ************************/
/*****************************************************************************/
2017-09-07 18:38:18 +02:00
static void Gam_GetGameTxtFromDB (long GamCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
2017-07-09 20:31:40 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
/***** Get text of game from database *****/
2018-10-31 10:19:01 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get game text",
2019-09-17 01:37:07 +02:00
"SELECT Txt FROM gam_games WHERE GamCod=%ld",
2018-10-31 10:19:01 +01:00
GamCod);
2017-07-09 20:31:40 +02:00
/***** The result of the query must have one row or none *****/
if (NumRows == 1)
{
/* Get info text */
row = mysql_fetch_row (mysql_res);
Str_Copy (Txt,row[0],
Cns_MAX_BYTES_TEXT);
}
else
Txt[0] = '\0';
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
if (NumRows > 1)
Lay_ShowErrorAndExit ("Error when getting game text.");
}
2019-05-28 15:06:53 +02:00
/*****************************************************************************/
/*************** Ask for confirmation of removing of a game ******************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2017-09-07 18:38:18 +02:00
void Gam_AskRemGame (void)
2017-07-09 20:31:40 +02:00
{
extern const char *Txt_Do_you_really_want_to_remove_the_game_X;
extern const char *Txt_Remove_game;
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);
2017-07-09 20:31:40 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset game *****/
Gam_ResetGame (&Game);
2017-07-09 20:31:40 +02:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
2017-07-09 20:31:40 +02:00
Lay_ShowErrorAndExit ("Code of game is missing.");
/***** Get data of the game from database *****/
2017-09-07 18:38:18 +02:00
Gam_GetDataOfGameByCod (&Game);
2019-09-29 20:00:54 +02:00
if (!Gam_CheckIfICanEditGames ())
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2017-07-09 20:31:40 +02:00
/***** Show question and button to remove game *****/
2020-04-08 03:06:45 +02:00
Games.GamCod = Game.GamCod;
2020-03-26 02:54:30 +01:00
Ale_ShowAlertAndButton (ActRemGam,NULL,NULL,
2020-04-08 03:06:45 +02:00
Gam_PutParams,&Games,
2019-02-17 01:14:55 +01:00
Btn_REMOVE_BUTTON,Txt_Remove_game,
Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_game_X,
Game.Title);
2017-07-09 20:31:40 +02:00
/***** Show games again *****/
2020-04-08 03:06:45 +02:00
Gam_ListAllGames (&Games);
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
2019-05-28 15:06:53 +02:00
/******************************* Remove a game *******************************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2017-09-07 18:38:18 +02:00
void Gam_RemoveGame (void)
2017-07-09 20:31:40 +02:00
{
extern const char *Txt_Game_X_removed;
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);
2017-07-09 20:31:40 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset game *****/
Gam_ResetGame (&Game);
2017-07-09 20:31:40 +02:00
/***** Get game code *****/
2017-09-07 18:38:18 +02:00
if ((Game.GamCod = Gam_GetParamGameCod ()) == -1L)
2017-07-09 20:31:40 +02:00
Lay_ShowErrorAndExit ("Code of game is missing.");
/***** Get data of the game from database *****/
2017-09-07 18:38:18 +02:00
Gam_GetDataOfGameByCod (&Game);
2019-09-29 20:00:54 +02:00
if (!Gam_CheckIfICanEditGames ())
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2017-07-09 20:31:40 +02:00
2019-09-27 21:45:53 +02:00
/***** Remove game from all tables *****/
Gam_RemoveGameFromAllTables (Game.GamCod);
2017-07-09 20:31:40 +02:00
/***** Write message to show the change made *****/
2019-02-16 16:18:54 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Game_X_removed,
Game.Title);
2017-07-09 20:31:40 +02:00
/***** Show games again *****/
2020-04-08 03:06:45 +02:00
Gam_ListAllGames (&Games);
2017-07-09 20:31:40 +02:00
}
2019-09-27 21:45:53 +02:00
/*****************************************************************************/
/*********************** Remove game from all tables *************************/
/*****************************************************************************/
static void Gam_RemoveGameFromAllTables (long GamCod)
{
2019-09-28 01:12:53 +02:00
/***** Remove all matches in this game *****/
Mch_RemoveMatchesInGameFromAllTables (GamCod);
/***** Remove game question *****/
DB_QueryDELETE ("can not remove game questions",
"DELETE FROM gam_questions WHERE GamCod=%ld",
GamCod);
2019-09-27 21:45:53 +02:00
2019-09-28 01:12:53 +02:00
/***** Remove game *****/
DB_QueryDELETE ("can not remove game",
"DELETE FROM gam_games WHERE GamCod=%ld",
GamCod);
2019-09-27 21:45:53 +02:00
}
/*****************************************************************************/
2019-09-28 01:12:53 +02:00
/******************** Remove all the games of a course ***********************/
2019-09-27 21:45:53 +02:00
/*****************************************************************************/
2019-09-28 01:12:53 +02:00
void Gam_RemoveGamesCrs (long CrsCod)
2019-09-27 21:45:53 +02:00
{
2019-09-28 01:12:53 +02:00
/***** Remove all matches in this course *****/
Mch_RemoveMatchInCourseFromAllTables (CrsCod);
/***** Remove the questions in games *****/
DB_QueryDELETE ("can not remove questions in course games",
"DELETE FROM gam_questions"
" USING gam_games,gam_questions"
" WHERE gam_games.CrsCod=%ld"
" AND gam_games.GamCod=gam_questions.GamCod",
CrsCod);
/***** Remove the games *****/
DB_QueryDELETE ("can not remove course games",
"DELETE FROM gam_games"
" WHERE CrsCod=%ld",
CrsCod);
2019-09-27 21:45:53 +02:00
}
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
/******************************** Hide a game ******************************/
/*****************************************************************************/
2017-09-07 18:38:18 +02:00
void Gam_HideGame (void)
2017-07-09 20:31:40 +02:00
{
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);
2017-07-09 20:31:40 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset game *****/
Gam_ResetGame (&Game);
2019-09-29 17:33:39 +02:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
2017-07-09 20:31:40 +02:00
Lay_ShowErrorAndExit ("Code of game is missing.");
/***** Get data of the game from database *****/
2017-09-07 18:38:18 +02:00
Gam_GetDataOfGameByCod (&Game);
2019-09-29 20:00:54 +02:00
if (!Gam_CheckIfICanEditGames ())
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2017-07-09 20:31:40 +02:00
/***** Hide game *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not hide game",
2019-09-17 01:37:07 +02:00
"UPDATE gam_games SET Hidden='Y' WHERE GamCod=%ld",
2018-11-03 12:16:40 +01:00
Game.GamCod);
2017-07-09 20:31:40 +02:00
/***** Show games again *****/
2020-04-08 03:06:45 +02:00
Gam_ListAllGames (&Games);
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
/******************************** Show a game ******************************/
/*****************************************************************************/
2017-09-07 18:38:18 +02:00
void Gam_UnhideGame (void)
2017-07-09 20:31:40 +02:00
{
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);
2017-07-09 20:31:40 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset game *****/
Gam_ResetGame (&Game);
2019-09-29 17:33:39 +02:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
2017-07-09 20:31:40 +02:00
Lay_ShowErrorAndExit ("Code of game is missing.");
/***** Get data of the game from database *****/
2017-09-07 18:38:18 +02:00
Gam_GetDataOfGameByCod (&Game);
2019-09-29 20:00:54 +02:00
if (!Gam_CheckIfICanEditGames ())
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2017-07-09 20:31:40 +02:00
/***** Show game *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not show game",
2019-09-17 01:37:07 +02:00
"UPDATE gam_games SET Hidden='N' WHERE GamCod=%ld",
2018-11-03 12:16:40 +01:00
Game.GamCod);
2017-07-09 20:31:40 +02:00
/***** Show games again *****/
2020-04-08 03:06:45 +02:00
Gam_ListAllGames (&Games);
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
/******************* Check if the title of a game exists *******************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static bool Gam_CheckIfSimilarGameExists (const struct Gam_Game *Game)
2017-07-09 20:31:40 +02:00
{
/***** Get number of games with a field value from database *****/
2018-11-03 20:52:00 +01:00
return (DB_QueryCOUNT ("can not get similar games",
2019-09-17 01:37:07 +02:00
"SELECT COUNT(*) FROM gam_games"
2019-05-20 08:52:07 +02:00
" WHERE CrsCod=%ld AND Title='%s'"
" AND GamCod<>%ld",
Gbl.Hierarchy.Crs.CrsCod,Game->Title,
Game->GamCod) != 0);
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
2019-10-03 09:22:09 +02:00
/**************** Request the creation or edition of a game ******************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2017-09-07 18:38:18 +02:00
void Gam_RequestCreatOrEditGame (void)
2019-10-03 09:22:09 +02:00
{
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
struct Gam_Game Game;
2019-10-03 09:22:09 +02:00
bool ItsANewGame;
2020-03-08 19:13:38 +01:00
char Txt[Cns_MAX_BYTES_TEXT + 1];
2019-10-03 09:22:09 +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 *****/
Gam_ResetGame (&Game);
2020-03-08 19:13:38 +01:00
/***** Check if I can edit games *****/
2019-10-03 09:22:09 +02:00
if (!Gam_CheckIfICanEditGames ())
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2019-10-03 09:22:09 +02:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
ItsANewGame = ((Game.GamCod = Gam_GetParams (&Games)) <= 0);
2019-10-03 09:22:09 +02:00
2020-03-09 22:14:06 +01:00
/***** Get game data *****/
if (ItsANewGame)
{
/* Initialize to empty game */
Gam_ResetGame (&Game);
Txt[0] = '\0';
}
else
{
/* Get game data from database */
Gam_GetDataOfGameByCod (&Game);
Gam_GetGameTxtFromDB (Game.GamCod,Txt);
}
2019-10-03 09:22:09 +02:00
/***** Put forms to create/edit a game *****/
2020-04-08 03:06:45 +02:00
Gam_PutFormsEditionGame (&Games,&Game,Txt,ItsANewGame);
2019-10-03 09:22:09 +02:00
2020-03-09 22:14:06 +01:00
/***** Show games or questions *****/
2020-03-08 19:13:38 +01:00
if (ItsANewGame)
2020-03-09 22:14:06 +01:00
/* Show games again */
2020-04-08 03:06:45 +02:00
Gam_ListAllGames (&Games);
2020-03-09 22:14:06 +01:00
else
/* Show questions of the game ready to be edited */
2020-04-08 03:06:45 +02:00
Gam_ListGameQuestions (&Games,&Game);
2020-03-09 22:14:06 +01:00
2019-10-03 09:22:09 +02:00
}
/*****************************************************************************/
/********************* Put a form to create/edit a game **********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_PutFormsEditionGame (struct Gam_Games *Games,
struct Gam_Game *Game,
2020-03-08 19:13:38 +01:00
char Txt[Cns_MAX_BYTES_TEXT + 1],
bool ItsANewGame)
2017-07-09 20:31:40 +02:00
{
extern const char *Hlp_ASSESSMENT_Games_new_game;
extern const char *Hlp_ASSESSMENT_Games_edit_game;
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2017-07-09 20:31:40 +02:00
extern const char *Txt_New_game;
extern const char *Txt_Edit_game;
extern const char *Txt_Title;
2019-11-27 01:01:27 +01:00
extern const char *Txt_Maximum_grade;
2020-02-18 15:40:04 +01:00
extern const char *Txt_Result_visibility;
2017-07-09 20:31:40 +02:00
extern const char *Txt_Description;
extern const char *Txt_Create_game;
2019-02-18 18:27:45 +01:00
extern const char *Txt_Save_changes;
2017-07-09 20:31:40 +02:00
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2020-04-08 03:06:45 +02:00
Games->GamCod = Game->GamCod;
2019-09-30 12:45:45 +02:00
Frm_StartForm (ItsANewGame ? ActNewGam :
ActChgGam);
2020-04-08 03:06:45 +02:00
Gam_PutParams (Games);
2017-07-09 20:31:40 +02:00
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2019-09-30 12:45:45 +02:00
if (ItsANewGame)
2020-03-26 02:54:30 +01:00
Box_BoxTableBegin (NULL,Txt_New_game,
NULL,NULL,
2019-09-30 12:45:45 +02:00
Hlp_ASSESSMENT_Games_new_game,Box_NOT_CLOSABLE,2);
else
2019-11-25 23:18:08 +01:00
Box_BoxTableBegin (NULL,
2019-10-03 09:22:09 +02:00
Game->Title[0] ? Game->Title :
Txt_Edit_game,
2020-03-26 02:54:30 +01:00
NULL,NULL,
2019-09-30 12:45:45 +02:00
Hlp_ASSESSMENT_Games_edit_game,Box_NOT_CLOSABLE,2);
2017-07-09 20:31:40 +02:00
2019-09-30 12:45:45 +02:00
/***** Game title *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 15:15:55 +02:00
2019-12-27 21:10:39 +01:00
/* Label */
2019-12-27 15:45:19 +01:00
Frm_LabelColumn ("RT","Title",Txt_Title);
2019-10-07 15:15:55 +02:00
2019-12-27 21:10:39 +01:00
/* Data */
2019-12-26 22:29:04 +01:00
HTM_TD_Begin ("class=\"LT\"");
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("Title",Gam_MAX_CHARS_TITLE,Game->Title,false,
2019-11-27 00:27:42 +01:00
"id=\"Title\" required=\"required\""
" class=\"TITLE_DESCRIPTION_WIDTH\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 15:15:55 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-09-30 12:45:45 +02:00
2019-11-27 01:01:27 +01:00
/***** Maximum grade *****/
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"%s RM\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
HTM_TxtF ("%s:",Txt_Maximum_grade);
HTM_TD_End ();
HTM_TD_Begin ("class=\"LM\"");
2019-11-28 09:56:26 +01:00
HTM_INPUT_FLOAT ("MaxGrade",0.0,DBL_MAX,0.01,Game->MaxGrade,false,
2019-11-27 09:01:45 +01:00
"required=\"required\"");
2019-11-27 01:01:27 +01:00
HTM_TD_End ();
HTM_TR_End ();
2020-02-18 15:40:04 +01:00
/***** Visibility of results *****/
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"%s RT\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
HTM_TxtF ("%s:",Txt_Result_visibility);
HTM_TD_End ();
HTM_TD_Begin ("class=\"LB\"");
2020-04-02 03:28:08 +02:00
TstVis_PutVisibilityCheckboxes (Game->Visibility);
2020-02-18 15:40:04 +01:00
HTM_TD_End ();
HTM_TR_End ();
2019-09-30 12:45:45 +02:00
/***** Game text *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 15:15:55 +02:00
2019-12-27 21:10:39 +01:00
/* Label */
2019-12-27 15:45:19 +01:00
Frm_LabelColumn ("RT","Txt",Txt_Description);
2019-10-07 15:15:55 +02:00
2019-12-27 21:10:39 +01:00
/* Data */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2019-11-27 00:27:42 +01:00
HTM_TEXTAREA_Begin ("id=\"Txt\" name=\"Txt\" rows=\"5\""
" class=\"TITLE_DESCRIPTION_WIDTH\"");
2020-03-09 22:14:06 +01:00
HTM_Txt (Txt);
2019-10-31 17:42:05 +01:00
HTM_TEXTAREA_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 15:15:55 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-09-30 12:45:45 +02:00
/***** End table, send button and end box *****/
if (ItsANewGame)
2019-11-25 23:18:08 +01:00
Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_game);
2019-09-30 12:45:45 +02:00
else
2019-11-25 23:18:08 +01:00
Box_BoxTableWithButtonEnd (Btn_CONFIRM_BUTTON,Txt_Save_changes);
2017-07-09 20:31:40 +02:00
2019-09-30 12:45:45 +02:00
/***** End form *****/
Frm_EndForm ();
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
2020-03-08 19:13:38 +01:00
/********************** Receive form to create a new game ********************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2017-09-07 18:38:18 +02:00
void Gam_RecFormGame (void)
2017-07-09 20:31:40 +02:00
{
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
struct Gam_Game Game;
2017-07-09 20:31:40 +02:00
bool ItsANewGame;
char Txt[Cns_MAX_BYTES_TEXT + 1];
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 *****/
Gam_ResetGame (&Game);
2020-03-08 19:13:38 +01:00
/***** Check if I can edit games *****/
if (!Gam_CheckIfICanEditGames ())
Lay_NoPermissionExit ();
2019-11-28 10:15:39 +01:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
ItsANewGame = ((Game.GamCod = Gam_GetParams (&Games)) <= 0);
2017-07-09 20:31:40 +02:00
2020-03-08 19:13:38 +01:00
/***** If I can edit games ==> receive game from form *****/
2019-09-30 12:54:10 +02:00
if (Gam_CheckIfICanEditGames ())
2017-07-09 20:31:40 +02:00
{
2020-03-08 19:13:38 +01:00
Gam_ReceiveGameFieldsFromForm (&Game,Txt);
if (Gam_CheckGameFieldsReceivedFromForm (&Game))
2019-09-26 21:27:36 +02:00
{
2020-03-08 19:13:38 +01:00
/***** Create a new game or update an existing one *****/
2019-09-26 21:27:36 +02:00
if (ItsANewGame)
2019-11-27 22:03:25 +01:00
Gam_CreateGame (&Game,Txt); // Add new game to database
2019-09-26 21:27:36 +02:00
else
2020-03-09 22:14:06 +01:00
Gam_UpdateGame (&Game,Txt); // Update game data in database
2019-10-03 09:22:09 +02:00
2020-03-09 22:14:06 +01:00
/***** Put forms to edit the game created or updated *****/
2020-04-08 03:06:45 +02:00
Gam_PutFormsEditionGame (&Games,&Game,Txt,
2020-03-09 22:14:06 +01:00
false); // No new game
/***** Show questions of the game ready to be edited ******/
2020-04-08 03:06:45 +02:00
Gam_ListGameQuestions (&Games,&Game);
2020-03-09 22:14:06 +01:00
}
else
{
/***** Put forms to create/edit the game *****/
2020-04-08 03:06:45 +02:00
Gam_PutFormsEditionGame (&Games,&Game,Txt,ItsANewGame);
2020-03-09 22:14:06 +01:00
/***** Show games or questions *****/
if (ItsANewGame)
/* Show games again */
2020-04-08 03:06:45 +02:00
Gam_ListAllGames (&Games);
2020-03-09 22:14:06 +01:00
else
/* Show questions of the game ready to be edited */
2020-04-08 03:06:45 +02:00
Gam_ListGameQuestions (&Games,&Game);
2020-03-09 22:14:06 +01:00
}
2017-07-09 20:31:40 +02:00
}
2019-09-30 12:54:10 +02:00
else
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2020-03-08 19:13:38 +01:00
}
2020-04-08 03:06:45 +02:00
static void Gam_ReceiveGameFieldsFromForm (struct Gam_Game *Game,
2020-03-08 19:13:38 +01:00
char Txt[Cns_MAX_BYTES_TEXT + 1])
{
char MaxGradeStr[64];
/***** Get game title *****/
Par_GetParToText ("Title",Game->Title,Gam_MAX_BYTES_TITLE);
/***** Get maximum grade *****/
Par_GetParToText ("MaxGrade",MaxGradeStr,sizeof (MaxGradeStr) - 1);
Game->MaxGrade = Str_GetDoubleFromStr (MaxGradeStr);
if (Game->MaxGrade < 0.0) // Only positive values allowed
Game->MaxGrade = 0.0;
/***** Get visibility *****/
2020-04-02 03:28:08 +02:00
Game->Visibility = TstVis_GetVisibilityFromForm ();
2020-03-08 19:13:38 +01:00
/***** Get game text *****/
Par_GetParToHTML ("Txt",Txt,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous)
}
2020-04-08 03:06:45 +02:00
static bool Gam_CheckGameFieldsReceivedFromForm (const struct Gam_Game *Game)
2020-03-08 19:13:38 +01:00
{
extern const char *Txt_Already_existed_a_game_with_the_title_X;
extern const char *Txt_You_must_specify_the_title_of_the_game;
bool NewGameIsCorrect;
/***** Check if title is correct *****/
NewGameIsCorrect = true;
if (Game->Title[0]) // If there's a game title
{
/* If title of game was in database... */
if (Gam_CheckIfSimilarGameExists (Game))
{
NewGameIsCorrect = false;
Ale_ShowAlert (Ale_WARNING,Txt_Already_existed_a_game_with_the_title_X,
Game->Title);
}
}
else // If there is not a game title
{
NewGameIsCorrect = false;
Ale_ShowAlert (Ale_WARNING,Txt_You_must_specify_the_title_of_the_game);
}
return NewGameIsCorrect;
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
2017-09-13 09:47:45 +02:00
/**************************** Create a new game ******************************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_CreateGame (struct Gam_Game *Game,const char *Txt)
2017-07-09 20:31:40 +02:00
{
extern const char *Txt_Created_new_game_X;
/***** Create a new game *****/
2019-11-27 22:03:25 +01:00
Str_SetDecimalPointToUS (); // To write the decimal point as a dot
2018-11-03 01:45:36 +01:00
Game->GamCod =
DB_QueryINSERTandReturnCode ("can not create new game",
2019-09-17 01:37:07 +02:00
"INSERT INTO gam_games"
2020-02-18 15:40:04 +01:00
" (CrsCod,Hidden,UsrCod,MaxGrade,Visibility,Title,Txt)"
2018-11-03 01:45:36 +01:00
" VALUES"
2020-02-18 15:40:04 +01:00
" (%ld,'N',%ld,%.15lg,%u,'%s','%s')",
2019-05-20 08:52:07 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-11-03 01:45:36 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod,
2019-11-27 22:03:25 +01:00
Game->MaxGrade,
2020-02-18 15:40:04 +01:00
Game->Visibility,
2018-11-03 01:45:36 +01:00
Game->Title,
Txt);
2019-11-27 22:03:25 +01:00
Str_SetDecimalPointToLocal (); // Return to local system
2017-07-09 20:31:40 +02:00
/***** Write success message *****/
2019-02-16 16:18:54 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Created_new_game_X,
Game->Title);
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
/************************* Update an existing game *************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_UpdateGame (struct Gam_Game *Game,const char *Txt)
2017-07-09 20:31:40 +02:00
{
extern const char *Txt_The_game_has_been_modified;
/***** Update the data of the game *****/
2019-11-27 22:03:25 +01:00
Str_SetDecimalPointToUS (); // To write the decimal point as a dot
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update game",
2019-09-17 01:37:07 +02:00
"UPDATE gam_games"
2019-05-20 08:52:07 +02:00
" SET CrsCod=%ld,"
2020-01-11 15:22:02 +01:00
"MaxGrade=%.15lg,"
2020-02-18 15:40:04 +01:00
"Visibility=%u,"
2019-05-20 08:52:07 +02:00
"Title='%s',"
"Txt='%s'"
2018-11-03 12:16:40 +01:00
" WHERE GamCod=%ld",
2019-05-20 08:52:07 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2019-11-27 22:03:25 +01:00
Game->MaxGrade,
2020-02-18 15:40:04 +01:00
Game->Visibility,
2018-11-03 12:16:40 +01:00
Game->Title,
Txt,
Game->GamCod);
2019-11-27 22:03:25 +01:00
Str_SetDecimalPointToLocal (); // Return to local system
2017-07-09 20:31:40 +02:00
/***** Write success message *****/
2019-02-16 16:18:54 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_The_game_has_been_modified);
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
/******************* Get number of questions of a game *********************/
/*****************************************************************************/
2019-09-14 12:59:34 +02:00
unsigned Gam_GetNumQstsGame (long GamCod)
2017-07-09 20:31:40 +02:00
{
2019-07-19 13:11:59 +02:00
/***** Get nuumber of questions in a game from database *****/
2018-11-03 20:52:00 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of questions of a game",
"SELECT COUNT(*) FROM gam_questions"
" WHERE GamCod=%ld",
GamCod);
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
2020-02-14 10:02:58 +01:00
/*************** Put a form to edit/create a question in game ****************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2017-09-07 18:38:18 +02:00
void Gam_RequestNewQuestion (void)
2017-07-09 20:31:40 +02:00
{
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);
2017-07-09 20:31:40 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset game *****/
Gam_ResetGame (&Game);
2019-09-29 17:33:39 +02:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
2017-07-09 20:31:40 +02:00
Lay_ShowErrorAndExit ("Code of game is missing.");
2019-12-08 23:19:16 +01:00
Gam_GetDataOfGameByCod (&Game);
2017-07-09 20:31:40 +02:00
2019-09-26 21:27:36 +02:00
/***** Check if game has matches *****/
2019-12-10 21:52:22 +01:00
if (Gam_CheckIfEditable (&Game))
2019-09-26 21:27:36 +02:00
{
/***** Show form to create a new question in this game *****/
2020-04-08 03:06:45 +02:00
Games.GamCod = Game.GamCod;
Tst_RequestSelectTestsForGame (&Games);
2019-09-26 21:27:36 +02:00
}
2019-09-30 12:54:10 +02:00
else
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2017-07-09 20:31:40 +02:00
/***** Show current game *****/
2020-04-08 03:06:45 +02:00
Gam_ShowOnlyOneGame (&Games,&Game,
2019-12-08 16:46:25 +01:00
true, // List game questions
false); // Do not put form to start new match
2017-07-09 20:31:40 +02:00
}
2019-09-26 21:27:36 +02:00
/*****************************************************************************/
/**************** List several test questions for selection ******************/
/*****************************************************************************/
void Gam_ListTstQuestionsToSelect (void)
{
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-09-26 21:27:36 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset game *****/
Gam_ResetGame (&Game);
2019-09-29 17:33:39 +02:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
2019-09-26 21:27:36 +02:00
Lay_ShowErrorAndExit ("Code of game is missing.");
2019-12-10 21:52:22 +01:00
Gam_GetDataOfGameByCod (&Game);
2019-09-26 21:27:36 +02:00
/***** Check if game has matches *****/
2019-12-10 21:52:22 +01:00
if (Gam_CheckIfEditable (&Game))
2019-09-29 17:33:39 +02:00
{
2019-09-26 21:27:36 +02:00
/***** List several test questions for selection *****/
2020-04-08 03:06:45 +02:00
Games.GamCod = Game.GamCod;
2020-04-22 03:15:04 +02:00
Tst_ListQuestionsToSelectForGame (&Games);
2019-09-29 17:33:39 +02:00
}
2019-09-30 12:54:10 +02:00
else
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2019-09-26 21:27:36 +02:00
}
2017-09-13 21:22:52 +02:00
/*****************************************************************************/
/****************** Write parameter with index of question *******************/
/*****************************************************************************/
2019-09-14 12:59:34 +02:00
void Gam_PutParamQstInd (unsigned QstInd)
2017-09-13 21:22:52 +02:00
{
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamUnsigned (NULL,"QstInd",QstInd);
2017-09-13 21:22:52 +02:00
}
/*****************************************************************************/
/******************* Get parameter with index of question ********************/
/*****************************************************************************/
2019-09-14 12:59:34 +02:00
unsigned Gam_GetParamQstInd (void)
2017-09-13 21:22:52 +02:00
{
2019-09-24 01:41:51 +02:00
long QstInd;
2017-09-13 21:22:52 +02:00
2019-09-24 01:41:51 +02:00
QstInd = Par_GetParToLong ("QstInd");
if (QstInd < 0)
2017-09-13 21:22:52 +02:00
Lay_ShowErrorAndExit ("Wrong question index.");
2019-09-24 01:41:51 +02:00
return (unsigned) QstInd;
2017-09-13 21:22:52 +02:00
}
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2019-05-30 12:57:31 +02:00
/********************** Remove answers of a game question ********************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2019-05-30 12:57:31 +02:00
static void Gam_RemAnswersOfAQuestion (long GamCod,unsigned QstInd)
2017-07-09 20:31:40 +02:00
{
2019-09-17 08:43:50 +02:00
/***** Remove answers from all matches of this game *****/
2019-05-30 12:57:31 +02:00
DB_QueryDELETE ("can not remove the answers of a question",
2019-09-17 01:37:07 +02:00
"DELETE FROM mch_answers"
2019-09-17 08:43:50 +02:00
" USING mch_matches,mch_answers"
" WHERE mch_matches.GamCod=%ld" // From all matches of this game...
" AND mch_matches.MchCod=mch_answers.MchCod"
" AND mch_answers.QstInd=%u", // ...remove only answers to this question
2019-05-30 12:57:31 +02:00
GamCod,QstInd);
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
2017-09-11 19:06:46 +02:00
/************ Get question code given game and index of question *************/
/*****************************************************************************/
2019-09-14 12:59:34 +02:00
long Gam_GetQstCodFromQstInd (long GamCod,unsigned QstInd)
2017-09-11 19:06:46 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long QstCod;
2020-04-26 11:56:52 +02:00
/***** Get question code of the question to be moved up *****/
2018-10-31 10:19:01 +01:00
if (!DB_QuerySELECT (&mysql_res,"can not get question code",
"SELECT QstCod FROM gam_questions"
" WHERE GamCod=%ld AND QstInd=%u",
GamCod,QstInd))
2020-02-26 00:26:07 +01:00
Lay_ShowErrorAndExit ("Error: wrong question index.");
2017-09-11 19:06:46 +02:00
/***** Get question code (row[0]) *****/
row = mysql_fetch_row (mysql_res);
if ((QstCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Lay_ShowErrorAndExit ("Error: wrong question code.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return QstCod;
}
/*****************************************************************************/
/****************** Get maximum question index in a game *********************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2019-05-30 12:57:31 +02:00
// Question index can be 1, 2, 3...
// Return 0 if no questions
2017-07-09 20:31:40 +02:00
2019-05-30 12:57:31 +02:00
static unsigned Gam_GetMaxQuestionIndexInGame (long GamCod)
2017-07-09 20:31:40 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2019-05-30 12:57:31 +02:00
unsigned QstInd = 0;
2017-07-09 20:31:40 +02:00
2017-09-01 14:36:25 +02:00
/***** Get maximum question index in a game from database *****/
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get last question index",
2020-02-26 00:26:07 +01:00
"SELECT MAX(QstInd)"
" FROM gam_questions"
" WHERE GamCod=%ld",
2018-10-31 10:19:01 +01:00
GamCod);
2017-07-09 20:31:40 +02:00
row = mysql_fetch_row (mysql_res);
if (row[0]) // There are questions
2019-05-30 12:57:31 +02:00
if (sscanf (row[0],"%u",&QstInd) != 1)
2017-07-09 20:31:40 +02:00
Lay_ShowErrorAndExit ("Error when getting last question index.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return QstInd;
}
2017-09-11 19:06:46 +02:00
/*****************************************************************************/
/*********** Get previous question index to a given index in a game **********/
/*****************************************************************************/
2019-05-30 13:46:57 +02:00
// Input question index can be 1, 2, 3... n-1
// Return question index will be 1, 2, 3... n if previous question exists, or 0 if no previous question
2017-09-11 19:06:46 +02:00
2019-09-14 12:59:34 +02:00
unsigned Gam_GetPrevQuestionIndexInGame (long GamCod,unsigned QstInd)
2017-09-11 19:06:46 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2019-05-30 12:57:31 +02:00
unsigned PrevQstInd = 0;
2017-09-11 19:06:46 +02:00
/***** Get previous question index in a game from database *****/
// Although indexes are always continuous...
// ...this implementation works even with non continuous indexes
2018-10-31 10:19:01 +01:00
if (!DB_QuerySELECT (&mysql_res,"can not get previous question index",
"SELECT MAX(QstInd) FROM gam_questions"
2019-05-30 12:57:31 +02:00
" WHERE GamCod=%ld AND QstInd<%u",
2018-10-31 10:19:01 +01:00
GamCod,QstInd))
2017-09-11 19:06:46 +02:00
Lay_ShowErrorAndExit ("Error: previous question index not found.");
/***** Get previous question index (row[0]) *****/
row = mysql_fetch_row (mysql_res);
2019-12-10 21:52:22 +01:00
if (row)
if (row[0])
if (sscanf (row[0],"%u",&PrevQstInd) != 1)
Lay_ShowErrorAndExit ("Error when getting previous question index.");
2017-09-11 19:06:46 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return PrevQstInd;
}
/*****************************************************************************/
/************* Get next question index to a given index in a game ************/
/*****************************************************************************/
2019-05-30 13:46:57 +02:00
// Input question index can be 0, 1, 2, 3... n-1
// Return question index will be 1, 2, 3... n if next question exists, or 0 if no next question
2017-09-11 19:06:46 +02:00
2019-09-14 12:59:34 +02:00
unsigned Gam_GetNextQuestionIndexInGame (long GamCod,unsigned QstInd)
2017-09-11 19:06:46 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2020-03-07 00:14:35 +01:00
unsigned NextQstInd = Mch_AFTER_LAST_QUESTION; // End of questions has been reached
2017-09-11 19:06:46 +02:00
/***** Get next question index in a game from database *****/
// Although indexes are always continuous...
// ...this implementation works even with non continuous indexes
2018-10-31 10:19:01 +01:00
if (!DB_QuerySELECT (&mysql_res,"can not get next question index",
"SELECT MIN(QstInd) FROM gam_questions"
2019-05-30 12:57:31 +02:00
" WHERE GamCod=%ld AND QstInd>%u",
2018-10-31 10:19:01 +01:00
GamCod,QstInd))
2017-09-11 19:06:46 +02:00
Lay_ShowErrorAndExit ("Error: next question index not found.");
/***** Get next question index (row[0]) *****/
row = mysql_fetch_row (mysql_res);
2019-12-10 21:52:22 +01:00
if (row)
if (row[0])
if (sscanf (row[0],"%u",&NextQstInd) != 1)
Lay_ShowErrorAndExit ("Error when getting next question index.");
2017-09-11 19:06:46 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NextQstInd;
}
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2017-09-06 15:03:43 +02:00
/************************ List the questions of a game ***********************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_ListGameQuestions (struct Gam_Games *Games,struct Gam_Game *Game)
2017-07-09 20:31:40 +02:00
{
extern const char *Hlp_ASSESSMENT_Games_questions;
extern const char *Txt_Questions;
extern const char *Txt_This_game_has_no_questions;
MYSQL_RES *mysql_res;
unsigned NumQsts;
2019-12-10 21:52:22 +01:00
bool ICanEditQuestions = Gam_CheckIfEditable (Game);
2017-07-09 20:31:40 +02:00
/***** Get data of questions from database *****/
2020-03-07 00:14:35 +01:00
NumQsts = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get game questions",
"SELECT QstInd," // row[0]
"QstCod" // row[1]
" FROM gam_questions"
" WHERE GamCod=%ld"
" ORDER BY QstInd",
Game->GamCod);
2017-07-09 20:31:40 +02:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2020-04-08 03:06:45 +02:00
Games->GamCod = Game->GamCod;
2020-03-26 02:54:30 +01:00
if (ICanEditQuestions)
Box_BoxBegin (NULL,Txt_Questions,
2020-04-09 21:36:21 +02:00
Gam_PutIconToAddNewQuestions,Games,
2020-03-26 02:54:30 +01:00
Hlp_ASSESSMENT_Games_questions,Box_NOT_CLOSABLE);
else
Box_BoxBegin (NULL,Txt_Questions,
NULL,NULL,
Hlp_ASSESSMENT_Games_questions,Box_NOT_CLOSABLE);
2017-07-09 20:31:40 +02:00
2019-10-03 09:22:09 +02:00
/***** Show table with questions *****/
2017-07-09 20:31:40 +02:00
if (NumQsts)
2020-04-08 03:06:45 +02:00
Gam_ListOneOrMoreQuestionsForEdition (Games,
Game->GamCod,NumQsts,mysql_res,
2019-09-30 12:45:45 +02:00
ICanEditQuestions);
2017-07-09 20:31:40 +02:00
else // This game has no questions
2019-02-16 16:18:54 +01:00
Ale_ShowAlert (Ale_INFO,Txt_This_game_has_no_questions);
2017-07-09 20:31:40 +02:00
2019-10-03 09:22:09 +02:00
/***** Put button to add a new question in this game *****/
if (ICanEditQuestions) // I can edit questions
2020-04-08 03:06:45 +02:00
Gam_PutButtonToAddNewQuestions (Games);
2017-07-09 20:31:40 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2017-07-09 20:31:40 +02:00
}
2017-09-06 15:03:43 +02:00
/*****************************************************************************/
/********************* List game questions for edition ***********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_ListOneOrMoreQuestionsForEdition (struct Gam_Games *Games,
long GamCod,unsigned NumQsts,
2019-09-30 12:45:45 +02:00
MYSQL_RES *mysql_res,
bool ICanEditQuestions)
2017-09-06 15:03:43 +02:00
{
extern const char *Txt_Questions;
extern const char *Txt_No_INDEX;
extern const char *Txt_Code;
extern const char *Txt_Tags;
extern const char *Txt_Question;
2017-09-08 01:18:20 +02:00
extern const char *Txt_Move_up_X;
extern const char *Txt_Move_down_X;
2017-09-10 18:58:26 +02:00
extern const char *Txt_Movement_not_allowed;
2017-09-06 15:03:43 +02:00
unsigned NumQst;
MYSQL_ROW row;
2020-03-17 14:47:58 +01:00
struct Tst_Question Question;
2019-05-30 12:57:31 +02:00
unsigned QstInd;
unsigned MaxQstInd;
2019-11-08 01:10:32 +01:00
char StrQstInd[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
2020-04-04 02:07:54 +02:00
bool QuestionExists;
2019-05-30 12:57:31 +02:00
/***** Get maximum question index *****/
MaxQstInd = Gam_GetMaxQuestionIndexInGame (GamCod);
2017-09-06 15:03:43 +02:00
/***** Write the heading *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWideMarginPadding (2);
HTM_TR_Begin (NULL);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH_Empty (1);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"CT",Txt_No_INDEX);
HTM_TH (1,1,"CT",Txt_Code);
HTM_TH (1,1,"CT",Txt_Tags);
HTM_TH (1,1,"CT",Txt_Question);
2019-10-12 00:07:52 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2017-09-06 15:03:43 +02:00
/***** Write rows *****/
2019-05-30 12:57:31 +02:00
for (NumQst = 0;
2017-09-06 15:03:43 +02:00
NumQst < NumQsts;
2019-05-30 12:57:31 +02:00
NumQst++)
2017-09-06 15:03:43 +02:00
{
Gbl.RowEvenOdd = NumQst % 2;
2020-03-25 01:36:22 +01:00
/***** Create test question *****/
Tst_QstConstructor (&Question);
/***** Get question data *****/
2017-09-06 15:03:43 +02:00
row = mysql_fetch_row (mysql_res);
/*
2019-05-30 12:57:31 +02:00
row[0] QstInd
row[1] QstCod
2017-09-06 15:03:43 +02:00
*/
2019-05-30 12:57:31 +02:00
/* Get question index (row[0]) */
2020-02-27 00:19:55 +01:00
QstInd = Str_ConvertStrToUnsigned (row[0]);
2019-05-30 12:57:31 +02:00
snprintf (StrQstInd,sizeof (StrQstInd),
"%u",
QstInd);
/* Get question code (row[1]) */
2020-03-25 01:36:22 +01:00
Question.QstCod = Str_ConvertStrCodToLongCod (row[1]);
2017-09-06 15:03:43 +02:00
/***** Icons *****/
2020-04-08 03:06:45 +02:00
Games->GamCod = GamCod;
Games->QstInd = QstInd;
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-08 23:28:51 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BT%u\"",Gbl.RowEvenOdd);
2017-09-06 15:03:43 +02:00
2017-09-13 12:25:45 +02:00
/* Put icon to remove the question */
2019-09-30 12:45:45 +02:00
if (ICanEditQuestions)
{
Frm_StartForm (ActReqRemGamQst);
2020-04-08 03:06:45 +02:00
Gam_PutParams (Games);
2019-09-30 12:45:45 +02:00
Gam_PutParamQstInd (QstInd);
Ico_PutIconRemove ();
Frm_EndForm ();
}
else
Ico_PutIconRemovalNotAllowed ();
2017-09-06 15:03:43 +02:00
2017-09-11 19:06:46 +02:00
/* Put icon to move up the question */
2019-09-30 12:45:45 +02:00
if (ICanEditQuestions && QstInd > 1)
2017-09-10 18:58:26 +02:00
{
2020-03-26 02:54:30 +01:00
Lay_PutContextualLinkOnlyIcon (ActUp_GamQst,NULL,
2020-04-08 03:06:45 +02:00
Gam_PutParamsOneQst,Games,
2019-01-12 03:00:59 +01:00
"arrow-up.svg",
2019-12-30 21:47:07 +01:00
Str_BuildStringStr (Txt_Move_up_X,
StrQstInd));
Str_FreeString ();
2017-09-10 18:58:26 +02:00
}
else
2019-01-11 02:55:01 +01:00
Ico_PutIconOff ("arrow-up.svg",Txt_Movement_not_allowed);
2017-09-08 01:18:20 +02:00
2017-09-11 19:06:46 +02:00
/* Put icon to move down the question */
2019-09-30 12:45:45 +02:00
if (ICanEditQuestions && QstInd < MaxQstInd)
2017-09-10 18:58:26 +02:00
{
2020-03-26 02:54:30 +01:00
Lay_PutContextualLinkOnlyIcon (ActDwnGamQst,NULL,
2020-04-08 03:06:45 +02:00
Gam_PutParamsOneQst,Games,
2019-01-12 03:00:59 +01:00
"arrow-down.svg",
2019-12-30 21:47:07 +01:00
Str_BuildStringStr (Txt_Move_down_X,
StrQstInd));
Str_FreeString ();
2017-09-10 18:58:26 +02:00
}
else
2019-01-11 02:55:01 +01:00
Ico_PutIconOff ("arrow-down.svg",Txt_Movement_not_allowed);
2017-09-08 01:18:20 +02:00
2017-09-11 19:06:46 +02:00
/* Put icon to edit the question */
2019-09-30 12:45:45 +02:00
if (ICanEditQuestions)
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToEdit (ActEdiOneTstQst,NULL,
2020-03-27 14:56:54 +01:00
Tst_PutParamQstCod,&Question.QstCod);
2017-09-06 15:03:43 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-09-06 15:03:43 +02:00
2020-03-07 00:14:35 +01:00
/***** Question *****/
2020-04-04 19:20:50 +02:00
QuestionExists = Tst_GetQstDataFromDB (&Question);
Gam_ListQuestionForEdition (&Question,QstInd,QuestionExists);
2020-03-07 00:14:35 +01:00
HTM_TR_End ();
/***** Destroy test question *****/
2020-03-19 20:57:54 +01:00
Tst_QstDestructor (&Question);
2020-03-07 00:14:35 +01:00
}
/***** End table *****/
HTM_TABLE_End ();
}
/*****************************************************************************/
/********************** List game question for edition ***********************/
/*****************************************************************************/
2020-04-04 02:07:54 +02:00
static void Gam_ListQuestionForEdition (const struct Tst_Question *Question,
unsigned QstInd,bool QuestionExists)
2020-03-07 00:14:35 +01:00
{
extern const char *Txt_Question_removed;
2019-10-23 20:07:56 +02:00
2020-03-23 17:14:41 +01:00
/***** Number of question and answer type (row[1]) *****/
2020-03-07 00:14:35 +01:00
HTM_TD_Begin ("class=\"RT COLOR%u\"",Gbl.RowEvenOdd);
2020-03-23 17:14:41 +01:00
Tst_WriteNumQst (QstInd);
2020-04-04 02:07:54 +02:00
if (QuestionExists)
Tst_WriteAnswerType (Question->Answer.Type);
2020-03-07 00:14:35 +01:00
HTM_TD_End ();
2017-09-06 15:03:43 +02:00
2020-03-07 00:14:35 +01:00
/***** Write question code *****/
HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd);
2020-03-25 01:36:22 +01:00
HTM_TxtF ("%ld&nbsp;",Question->QstCod);
2020-03-07 00:14:35 +01:00
HTM_TD_End ();
2017-09-06 15:03:43 +02:00
2020-03-07 00:14:35 +01:00
/***** Write the question tags *****/
HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd);
2020-04-04 02:07:54 +02:00
if (QuestionExists)
2020-03-25 01:36:22 +01:00
Tst_GetAndWriteTagsQst (Question->QstCod);
2020-03-07 00:14:35 +01:00
HTM_TD_End ();
2017-09-06 15:03:43 +02:00
2020-03-17 13:10:44 +01:00
/***** Write stem (row[3]) and media *****/
2020-03-07 00:14:35 +01:00
HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd);
2020-04-04 02:07:54 +02:00
if (QuestionExists)
2020-03-07 00:14:35 +01:00
{
/* Write stem */
2020-04-04 19:20:50 +02:00
Tst_WriteQstStem (Question->Stem,"TEST_EDI",
2020-02-17 15:30:55 +01:00
true); // Visible
2019-03-18 15:42:22 +01:00
/* Show media */
2020-04-04 02:07:54 +02:00
Med_ShowMedia (&Question->Media,
2020-03-07 00:14:35 +01:00
"TEST_MED_EDIT_LIST_STEM_CONTAINER",
"TEST_MED_EDIT_LIST_STEM");
2019-03-18 15:42:22 +01:00
2020-04-04 02:07:54 +02:00
/* Show feedback */
2020-04-04 19:20:50 +02:00
Tst_WriteQstFeedback (Question->Feedback,"TEST_EDI_LIGHT");
2019-03-18 15:42:22 +01:00
/* Show answers */
2020-03-30 18:54:17 +02:00
Tst_WriteAnswersListing (Question);
2017-09-06 15:03:43 +02:00
}
2020-03-07 00:14:35 +01:00
else
{
HTM_SPAN_Begin ("class=\"DAT_LIGHT\"");
HTM_Txt (Txt_Question_removed);
HTM_SPAN_End ();
}
HTM_TD_End ();
2017-09-06 15:03:43 +02:00
}
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2017-07-16 19:39:20 +02:00
/***************** Put icon to add a new questions to game *******************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_PutIconToAddNewQuestions (void *Games)
2017-07-09 20:31:40 +02:00
{
2017-07-16 19:39:20 +02:00
extern const char *Txt_Add_questions;
2017-07-09 20:31:40 +02:00
2020-04-09 21:36:21 +02:00
/***** Put form to create a new question *****/
Ico_PutContextualIconToAdd (ActAddOneGamQst,NULL,
Gam_PutParams,Games,
Txt_Add_questions);
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
2017-07-16 19:39:20 +02:00
/***************** Put button to add new questions to game *******************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_PutButtonToAddNewQuestions (struct Gam_Games *Games)
2017-07-09 20:31:40 +02:00
{
2017-07-16 19:39:20 +02:00
extern const char *Txt_Add_questions;
2017-07-09 20:31:40 +02:00
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActAddOneGamQst);
2020-04-08 03:06:45 +02:00
Gam_PutParams (Games);
2017-07-16 19:39:20 +02:00
Btn_PutConfirmButton (Txt_Add_questions);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-07-09 20:31:40 +02:00
}
2017-07-16 20:50:01 +02:00
/*****************************************************************************/
/******************** Add selected test questions to game ********************/
/*****************************************************************************/
2017-09-07 18:38:18 +02:00
void Gam_AddTstQuestionsToGame (void)
2017-07-16 20:50:01 +02:00
{
2019-10-03 09:22:09 +02:00
extern const char *Txt_No_questions_have_been_added;
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
struct Gam_Game Game;
2017-09-01 00:52:19 +02:00
const char *Ptr;
2019-11-08 01:10:32 +01:00
char LongStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1];
2017-09-07 12:00:01 +02:00
long QstCod;
2019-05-30 12:57:31 +02:00
unsigned MaxQstInd;
2017-09-01 00:52:19 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset games context *****/
2020-04-16 21:03:22 +02:00
Gam_ResetGames (&Games);
2020-04-23 23:09:28 +02:00
/***** Reset game *****/
Gam_ResetGame (&Game);
2019-09-29 17:33:39 +02:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
2017-09-01 00:52:19 +02:00
Lay_ShowErrorAndExit ("Code of game is missing.");
2019-12-08 23:19:16 +01:00
Gam_GetDataOfGameByCod (&Game);
2017-07-18 20:34:32 +02:00
2019-09-26 21:27:36 +02:00
/***** Check if game has matches *****/
2019-12-10 21:52:22 +01:00
if (Gam_CheckIfEditable (&Game))
2019-09-26 21:27:36 +02:00
{
/***** Get selected questions *****/
/* Allocate space for selected question codes */
2020-04-08 03:06:45 +02:00
Gam_AllocateListSelectedQuestions (&Games);
2017-07-18 20:34:32 +02:00
2019-09-26 21:27:36 +02:00
/* Get question codes */
2020-04-08 03:06:45 +02:00
Par_GetParMultiToText ("QstCods",Games.ListQuestions,
2019-09-26 21:27:36 +02:00
Gam_MAX_BYTES_LIST_SELECTED_QUESTIONS);
2017-07-18 20:34:32 +02:00
2019-09-26 21:27:36 +02:00
/* Check number of questions */
2020-04-08 03:06:45 +02:00
if (Gam_CountNumQuestionsInList (&Games)) // If questions selected...
2019-09-26 21:27:36 +02:00
{
2019-10-03 09:22:09 +02:00
/***** Insert questions in database *****/
2020-04-08 03:06:45 +02:00
Ptr = Games.ListQuestions;
2019-10-03 09:22:09 +02:00
while (*Ptr)
{
/* Get next code */
2019-11-08 01:10:32 +01:00
Par_GetNextStrUntilSeparParamMult (&Ptr,LongStr,Cns_MAX_DECIMAL_DIGITS_LONG);
2019-10-03 09:22:09 +02:00
if (sscanf (LongStr,"%ld",&QstCod) != 1)
Lay_ShowErrorAndExit ("Wrong question code.");
/* Get current maximum index */
MaxQstInd = Gam_GetMaxQuestionIndexInGame (Game.GamCod); // -1 if no questions
/* Insert question in the table of questions */
DB_QueryINSERT ("can not create question",
"INSERT INTO gam_questions"
" (GamCod,QstCod,QstInd)"
" VALUES"
" (%ld,%ld,%u)",
Game.GamCod,QstCod,MaxQstInd + 1);
}
2019-09-26 21:27:36 +02:00
}
2019-10-03 09:22:09 +02:00
else
Ale_ShowAlert (Ale_WARNING,Txt_No_questions_have_been_added);
2017-09-01 00:52:19 +02:00
2019-09-26 21:27:36 +02:00
/***** Free space for selected question codes *****/
2020-04-08 03:06:45 +02:00
Gam_FreeListsSelectedQuestions (&Games);
2017-09-01 00:52:19 +02:00
}
2019-09-30 12:54:10 +02:00
else
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2017-09-01 00:52:19 +02:00
2017-09-07 18:38:18 +02:00
/***** Show current game *****/
2020-04-08 03:06:45 +02:00
Gam_ShowOnlyOneGame (&Games,&Game,
2019-12-08 16:46:25 +01:00
true, // List game questions
false); // Do not put form to start new match
2017-07-18 20:34:32 +02:00
}
/*****************************************************************************/
/****************** Allocate memory for list of questions ********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_AllocateListSelectedQuestions (struct Gam_Games *Games)
2017-07-18 20:34:32 +02:00
{
2020-04-08 03:06:45 +02:00
if (!Games->ListQuestions)
2017-07-18 20:34:32 +02:00
{
2020-04-08 03:06:45 +02:00
if ((Games->ListQuestions = (char *) malloc (Gam_MAX_BYTES_LIST_SELECTED_QUESTIONS + 1)) == NULL)
2020-04-16 21:03:22 +02:00
Lay_NotEnoughMemoryExit ();
2020-04-08 03:06:45 +02:00
Games->ListQuestions[0] = '\0';
2017-07-18 20:34:32 +02:00
}
}
/*****************************************************************************/
/*********** Free memory used by list of selected question codes *************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Gam_FreeListsSelectedQuestions (struct Gam_Games *Games)
2017-07-18 20:34:32 +02:00
{
2020-04-08 03:06:45 +02:00
if (Games->ListQuestions)
2017-07-18 20:34:32 +02:00
{
2020-04-08 03:06:45 +02:00
free (Games->ListQuestions);
Games->ListQuestions = NULL;
2017-07-18 20:34:32 +02:00
}
}
/*****************************************************************************/
/**** Count the number of questions in the list of selected question codes ***/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static unsigned Gam_CountNumQuestionsInList (const struct Gam_Games *Games)
2017-07-18 20:34:32 +02:00
{
const char *Ptr;
unsigned NumQuestions = 0;
2019-11-08 01:10:32 +01:00
char LongStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1];
2017-07-18 20:34:32 +02:00
long QstCod;
2020-03-21 22:18:24 +01:00
/***** Go over list of questions counting the number of questions *****/
2020-04-08 03:06:45 +02:00
Ptr = Games->ListQuestions;
2017-07-18 20:34:32 +02:00
while (*Ptr)
{
2019-11-08 01:10:32 +01:00
Par_GetNextStrUntilSeparParamMult (&Ptr,LongStr,Cns_MAX_DECIMAL_DIGITS_LONG);
2017-07-18 20:34:32 +02:00
if (sscanf (LongStr,"%ld",&QstCod) != 1)
Lay_ShowErrorAndExit ("Wrong question code.");
NumQuestions++;
}
return NumQuestions;
2017-07-16 20:50:01 +02:00
}
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
/********************** Request the removal of a question ********************/
/*****************************************************************************/
2017-09-07 18:38:18 +02:00
void Gam_RequestRemoveQst (void)
2017-07-09 20:31:40 +02:00
{
extern const char *Txt_Do_you_really_want_to_remove_the_question_X;
extern const char *Txt_Remove_question;
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
struct Gam_Game Game;
2017-09-07 12:00:01 +02:00
unsigned QstInd;
2017-07-09 20:31:40 +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 *****/
Gam_ResetGame (&Game);
2019-09-29 17:33:39 +02:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
2017-07-09 20:31:40 +02:00
Lay_ShowErrorAndExit ("Code of game is missing.");
2019-12-08 23:19:16 +01:00
Gam_GetDataOfGameByCod (&Game);
2017-07-09 20:31:40 +02:00
2019-09-26 21:27:36 +02:00
/***** Check if game has matches *****/
2019-12-10 21:52:22 +01:00
if (Gam_CheckIfEditable (&Game))
2019-09-26 21:27:36 +02:00
{
/***** Get question index *****/
QstInd = Gam_GetParamQstInd ();
2017-07-09 20:31:40 +02:00
2019-09-26 21:27:36 +02:00
/***** Show question and button to remove question *****/
2020-04-08 03:06:45 +02:00
Games.GamCod = Game.GamCod;
Games.QstInd = QstInd;
2020-03-26 02:54:30 +01:00
Ale_ShowAlertAndButton (ActRemGamQst,NULL,NULL,
2020-04-09 21:36:21 +02:00
Gam_PutParamsOneQst,&Games,
2019-09-26 21:27:36 +02:00
Btn_REMOVE_BUTTON,Txt_Remove_question,
Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_question_X,
QstInd);
}
2019-09-30 12:54:10 +02:00
else
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2017-07-09 20:31:40 +02:00
/***** Show current game *****/
2020-04-08 03:06:45 +02:00
Gam_ShowOnlyOneGame (&Games,&Game,
2019-12-08 16:46:25 +01:00
true, // List game questions
false); // Do not put form to start new match
2017-07-09 20:31:40 +02:00
}
/*****************************************************************************/
/****************************** Remove a question ****************************/
/*****************************************************************************/
2017-09-07 18:38:18 +02:00
void Gam_RemoveQst (void)
2017-07-09 20:31:40 +02:00
{
extern const char *Txt_Question_removed;
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
struct Gam_Game Game;
2017-09-07 12:00:01 +02:00
unsigned QstInd;
2017-07-09 20:31:40 +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 *****/
Gam_ResetGame (&Game);
2019-09-29 17:33:39 +02:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
2017-07-09 20:31:40 +02:00
Lay_ShowErrorAndExit ("Code of game is missing.");
2019-12-08 23:19:16 +01:00
Gam_GetDataOfGameByCod (&Game);
2017-07-09 20:31:40 +02:00
2019-09-26 21:27:36 +02:00
/***** Check if game has matches *****/
2019-12-10 21:52:22 +01:00
if (Gam_CheckIfEditable (&Game))
2019-09-26 21:27:36 +02:00
{
/***** Get question index *****/
QstInd = Gam_GetParamQstInd ();
/***** Remove the question from all the tables *****/
/* Remove answers from this test question */
Gam_RemAnswersOfAQuestion (Game.GamCod,QstInd);
/* Remove the question itself */
DB_QueryDELETE ("can not remove a question",
"DELETE FROM gam_questions"
" WHERE GamCod=%ld AND QstInd=%u",
Game.GamCod,QstInd);
if (!mysql_affected_rows (&Gbl.mysql))
Lay_ShowErrorAndExit ("The question to be removed does not exist.");
/* Change index of questions greater than this */
DB_QueryUPDATE ("can not update indexes of questions in table of answers",
"UPDATE mch_answers,mch_matches"
" SET mch_answers.QstInd=mch_answers.QstInd-1"
" WHERE mch_matches.GamCod=%ld"
2019-09-26 23:57:10 +02:00
" AND mch_matches.MchCod=mch_answers.MchCod"
2019-09-26 21:27:36 +02:00
" AND mch_answers.QstInd>%u",
Game.GamCod,QstInd);
DB_QueryUPDATE ("can not update indexes of questions",
"UPDATE gam_questions SET QstInd=QstInd-1"
" WHERE GamCod=%ld AND QstInd>%u",
Game.GamCod,QstInd);
/***** Write message *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_Question_removed);
}
2019-09-30 12:54:10 +02:00
else
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2017-07-09 20:31:40 +02:00
/***** Show current game *****/
2020-04-08 03:06:45 +02:00
Gam_ShowOnlyOneGame (&Games,&Game,
2019-12-08 16:46:25 +01:00
true, // List game questions
false); // Do not put form to start new match
2017-07-09 20:31:40 +02:00
}
2017-09-11 19:06:46 +02:00
/*****************************************************************************/
/***************** Move up position of a question in a game ******************/
/*****************************************************************************/
void Gam_MoveUpQst (void)
{
extern const char *Txt_The_question_has_been_moved_up;
2019-05-30 12:57:31 +02:00
extern const char *Txt_Movement_not_allowed;
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
struct Gam_Game Game;
2019-05-30 12:57:31 +02:00
unsigned QstIndTop;
unsigned QstIndBottom;
2017-09-11 19:06:46 +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 *****/
Gam_ResetGame (&Game);
2019-09-29 17:33:39 +02:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
2017-09-11 19:06:46 +02:00
Lay_ShowErrorAndExit ("Code of game is missing.");
2019-12-08 23:19:16 +01:00
Gam_GetDataOfGameByCod (&Game);
2017-09-11 19:06:46 +02:00
2019-09-26 21:27:36 +02:00
/***** Check if game has matches *****/
2019-12-10 21:52:22 +01:00
if (Gam_CheckIfEditable (&Game))
2017-09-11 19:06:46 +02:00
{
2019-09-26 21:27:36 +02:00
/***** Get question index *****/
QstIndBottom = Gam_GetParamQstInd ();
2017-09-11 19:06:46 +02:00
2019-09-26 21:27:36 +02:00
/***** Move up question *****/
if (QstIndBottom > 1)
{
/* Indexes of questions to be exchanged */
QstIndTop = Gam_GetPrevQuestionIndexInGame (Game.GamCod,QstIndBottom);
if (!QstIndTop)
Lay_ShowErrorAndExit ("Wrong index of question.");
/* Exchange questions */
Gam_ExchangeQuestions (Game.GamCod,QstIndTop,QstIndBottom);
2017-09-11 19:06:46 +02:00
2019-09-26 21:27:36 +02:00
/* Success alert */
Ale_ShowAlert (Ale_SUCCESS,Txt_The_question_has_been_moved_up);
}
else
Ale_ShowAlert (Ale_WARNING,Txt_Movement_not_allowed);
2017-09-11 19:06:46 +02:00
}
2019-09-30 12:54:10 +02:00
else
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2017-09-11 19:06:46 +02:00
/***** Show current game *****/
2020-04-08 03:06:45 +02:00
Gam_ShowOnlyOneGame (&Games,&Game,
2019-12-08 16:46:25 +01:00
true, // List game questions
false); // Do not put form to start new match
2017-09-11 19:06:46 +02:00
}
/*****************************************************************************/
/**************** Move down position of a question in a game *****************/
/*****************************************************************************/
void Gam_MoveDownQst (void)
{
extern const char *Txt_The_question_has_been_moved_down;
2019-05-30 12:57:31 +02:00
extern const char *Txt_Movement_not_allowed;
extern const char *Txt_This_game_has_no_questions;
2020-04-08 03:06:45 +02:00
struct Gam_Games Games;
struct Gam_Game Game;
2019-05-30 12:57:31 +02:00
unsigned QstIndTop;
unsigned QstIndBottom;
unsigned MaxQstInd; // 0 if no questions
2017-09-11 19:06:46 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset games context *****/
2020-04-16 21:03:22 +02:00
Gam_ResetGames (&Games);
2020-04-23 23:09:28 +02:00
/***** Reset game *****/
Gam_ResetGame (&Game);
2019-09-29 17:33:39 +02:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
2017-09-11 19:06:46 +02:00
Lay_ShowErrorAndExit ("Code of game is missing.");
2019-12-08 23:19:16 +01:00
Gam_GetDataOfGameByCod (&Game);
2017-09-11 19:06:46 +02:00
2019-09-26 21:27:36 +02:00
/***** Check if game has matches *****/
2019-12-10 21:52:22 +01:00
if (Gam_CheckIfEditable (&Game))
2019-05-30 12:57:31 +02:00
{
2019-09-26 21:27:36 +02:00
/***** Get question index *****/
QstIndTop = Gam_GetParamQstInd ();
2017-09-11 19:06:46 +02:00
2019-09-26 21:27:36 +02:00
/***** Get maximum question index *****/
MaxQstInd = Gam_GetMaxQuestionIndexInGame (Game.GamCod);
2017-09-11 19:06:46 +02:00
2019-09-26 21:27:36 +02:00
/***** Move down question *****/
if (MaxQstInd)
{
if (QstIndTop < MaxQstInd)
{
/* Indexes of questions to be exchanged */
QstIndBottom = Gam_GetNextQuestionIndexInGame (Game.GamCod,QstIndTop);
if (!QstIndBottom)
Lay_ShowErrorAndExit ("Wrong index of question.");
/* Exchange questions */
Gam_ExchangeQuestions (Game.GamCod,QstIndTop,QstIndBottom);
/* Success alert */
Ale_ShowAlert (Ale_SUCCESS,Txt_The_question_has_been_moved_down);
}
else
Ale_ShowAlert (Ale_WARNING,Txt_Movement_not_allowed);
2017-09-11 19:06:46 +02:00
}
2019-05-30 12:57:31 +02:00
else
2019-09-26 21:27:36 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_This_game_has_no_questions);
2019-05-30 12:57:31 +02:00
}
2019-09-30 12:54:10 +02:00
else
2019-10-26 01:56:36 +02:00
Lay_NoPermissionExit ();
2017-09-11 19:06:46 +02:00
/***** Show current game *****/
2020-04-08 03:06:45 +02:00
Gam_ShowOnlyOneGame (&Games,&Game,
2019-12-08 16:46:25 +01:00
true, // List game questions
false); // Do not put form to start new match
2017-09-11 19:06:46 +02:00
}
/*****************************************************************************/
/********* Exchange the order of two consecutive questions in a game *********/
/*****************************************************************************/
static void Gam_ExchangeQuestions (long GamCod,
unsigned QstIndTop,unsigned QstIndBottom)
{
long QstCodTop;
long QstCodBottom;
2019-09-30 09:37:50 +02:00
/***** Lock table to make the move atomic *****/
2018-11-02 22:41:02 +01:00
DB_Query ("can not lock tables to move game question",
"LOCK TABLES gam_questions WRITE");
2017-09-11 19:06:46 +02:00
Gbl.DB.LockedTables = true;
/***** Get question code of the questions to be moved *****/
QstCodTop = Gam_GetQstCodFromQstInd (GamCod,QstIndTop);
QstCodBottom = Gam_GetQstCodFromQstInd (GamCod,QstIndBottom);
/***** Exchange indexes of questions *****/
/*
Example:
2019-05-30 12:57:31 +02:00
QstIndTop = 1; QstCodTop = 218
QstIndBottom = 2; QstCodBottom = 220
2017-09-11 19:06:46 +02:00
+--------+--------+ +--------+--------+ +--------+--------+
| QstInd | QstCod | | QstInd | QstCod | | QstInd | QstCod |
+--------+--------+ +--------+--------+ +--------+--------+
2019-05-30 12:57:31 +02:00
| 1 | 218 | -----> | 2 | 218 | = | 1 | 220 |
| 2 | 220 | | 1 | 220 | | 2 | 218 |
| 3 | 232 | | 3 | 232 | | 3 | 232 |
2017-09-11 19:06:46 +02:00
+--------+--------+ +--------+--------+ +--------+--------+
*/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not exchange indexes of questions",
"UPDATE gam_questions SET QstInd=%u"
" WHERE GamCod=%ld AND QstCod=%ld",
QstIndBottom,
GamCod,QstCodTop);
DB_QueryUPDATE ("can not exchange indexes of questions",
"UPDATE gam_questions SET QstInd=%u"
" WHERE GamCod=%ld AND QstCod=%ld",
QstIndTop,
GamCod,QstCodBottom);
2017-09-11 19:06:46 +02:00
/***** Unlock table *****/
Gbl.DB.LockedTables = false; // Set to false before the following unlock...
// ...to not retry the unlock if error in unlocking
2018-11-02 22:41:02 +01:00
DB_Query ("can not unlock tables after moving game questions",
"UNLOCK TABLES");
2017-09-11 19:06:46 +02:00
}
2019-09-26 21:40:25 +02:00
/*****************************************************************************/
/*********** Get number of matches and check is edition is possible **********/
/*****************************************************************************/
2019-12-10 21:52:22 +01:00
// Before calling this function, number of matches must be calculated
2019-09-26 21:40:25 +02:00
2020-04-08 03:06:45 +02:00
static bool Gam_CheckIfEditable (const struct Gam_Game *Game)
2019-09-26 21:40:25 +02:00
{
2019-09-30 12:45:45 +02:00
if (Gam_CheckIfICanEditGames ())
/***** Questions are editable only if game has no matches *****/
2019-12-10 21:52:22 +01:00
return (bool) (Game->NumMchs == 0); // Games with matches should not be edited
2019-09-26 21:40:25 +02:00
else
2019-09-30 12:45:45 +02:00
return false; // Questions are not editable
2019-09-26 21:40:25 +02:00
}
2019-09-29 17:33:39 +02:00
/*****************************************************************************/
/********************* Put button to create a new match **********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
void Gam_PutButtonNewMatch (struct Gam_Games *Games,long GamCod)
2019-09-29 17:33:39 +02:00
{
extern const char *Txt_New_match;
2020-04-08 03:06:45 +02:00
Games->GamCod = GamCod;
2019-09-29 21:33:27 +02:00
Frm_StartFormAnchor (ActReqNewMch,Mch_NEW_MATCH_SECTION_ID);
2020-04-08 03:06:45 +02:00
Gam_PutParams (Games);
2019-09-29 17:33:39 +02:00
Btn_PutConfirmButton (Txt_New_match);
Frm_EndForm ();
}
2019-05-28 15:06:53 +02:00
/*****************************************************************************/
2019-09-14 12:59:34 +02:00
/************* Request the creation of a new match as a teacher **************/
2019-05-28 15:06:53 +02:00
/*****************************************************************************/
2019-09-29 21:33:27 +02:00
void Gam_RequestNewMatch (void)
2019-05-28 15:06:53 +02:00
{
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-08-02 00:44:30 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset game *****/
Gam_ResetGame (&Game);
2019-09-14 12:59:34 +02:00
/***** Get parameters *****/
2020-04-08 03:06:45 +02:00
if ((Game.GamCod = Gam_GetParams (&Games)) <= 0)
2019-09-14 12:59:34 +02:00
Lay_ShowErrorAndExit ("Code of game is missing.");
2019-12-08 23:19:16 +01:00
Gam_GetDataOfGameByCod (&Game);
2017-09-13 09:47:45 +02:00
/***** Show game *****/
2020-04-08 03:06:45 +02:00
Gam_ShowOnlyOneGame (&Games,&Game,
2019-12-08 16:46:25 +01:00
false, // Do not list game questions
true); // Put form to start new match
2019-05-20 10:35:57 +02:00
}
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2017-09-01 10:37:00 +02:00
/********************* Get number of courses with games **********************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2017-09-17 18:22:36 +02:00
// Returns the number of courses with games in this location
2017-07-09 20:31:40 +02:00
2019-04-03 20:57:04 +02:00
unsigned Gam_GetNumCoursesWithGames (Hie_Level_t Scope)
2017-07-09 20:31:40 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCourses;
/***** Get number of courses with games from database *****/
switch (Scope)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
2019-09-17 01:37:07 +02:00
"SELECT COUNT(DISTINCT CrsCod)"
" FROM gam_games");
2017-07-09 20:31:40 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
2019-09-17 01:37:07 +02:00
"SELECT COUNT(DISTINCT gam_games.CrsCod)"
" FROM institutions,centres,degrees,courses,gam_games"
2018-10-31 10:19:01 +01:00
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
2019-09-17 01:37:07 +02:00
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Ins.InsCod);
2017-07-09 20:31:40 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
2019-09-17 01:37:07 +02:00
"SELECT COUNT(DISTINCT gam_games.CrsCod)"
" FROM centres,degrees,courses,gam_games"
2018-10-31 10:19:01 +01:00
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
2019-09-17 01:37:07 +02:00
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Ins.InsCod);
2017-07-09 20:31:40 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
2019-09-17 01:37:07 +02:00
"SELECT COUNT(DISTINCT gam_games.CrsCod)"
" FROM degrees,courses,gam_games"
2018-10-31 10:19:01 +01:00
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
2019-09-17 01:37:07 +02:00
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Ctr.CtrCod);
2017-07-09 20:31:40 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
2019-09-17 01:37:07 +02:00
"SELECT COUNT(DISTINCT gam_games.CrsCod)"
" FROM courses,gam_games"
2018-10-31 10:19:01 +01:00
" WHERE courses.DegCod=%ld"
2019-09-17 01:37:07 +02:00
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Deg.DegCod);
2017-07-09 20:31:40 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
2019-09-17 01:37:07 +02:00
"SELECT COUNT(DISTINCT CrsCod)"
" FROM gam_games"
" WHERE CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2017-07-09 20:31:40 +02:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2017-07-09 20:31:40 +02:00
break;
}
/***** Get number of games *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumCourses) != 1)
Lay_ShowErrorAndExit ("Error when getting number of courses with games.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumCourses;
}
/*****************************************************************************/
2017-09-17 18:22:36 +02:00
/**************************** Get number of games ****************************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2017-09-17 18:22:36 +02:00
// Returns the number of games in this location
2017-07-09 20:31:40 +02:00
2019-04-03 20:57:04 +02:00
unsigned Gam_GetNumGames (Hie_Level_t Scope)
2017-07-09 20:31:40 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumGames;
/***** Get number of games from database *****/
switch (Scope)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
2019-09-17 01:37:07 +02:00
" FROM gam_games");
2017-07-09 20:31:40 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
2019-09-17 01:37:07 +02:00
" FROM institutions,centres,degrees,courses,gam_games"
2018-10-31 10:19:01 +01:00
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
2019-09-17 01:37:07 +02:00
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Cty.CtyCod);
2017-07-09 20:31:40 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
2019-09-17 01:37:07 +02:00
" FROM centres,degrees,courses,gam_games"
2018-10-31 10:19:01 +01:00
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
2019-09-17 01:37:07 +02:00
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Ins.InsCod);
2017-07-09 20:31:40 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
2019-09-17 01:37:07 +02:00
" FROM degrees,courses,gam_games"
2018-10-31 10:19:01 +01:00
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
2019-09-17 01:37:07 +02:00
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Ctr.CtrCod);
2017-07-09 20:31:40 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
2019-09-17 01:37:07 +02:00
" FROM courses,gam_games"
2018-10-31 10:19:01 +01:00
" WHERE courses.DegCod=%ld"
2019-09-17 01:37:07 +02:00
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Deg.DegCod);
2017-07-09 20:31:40 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
2019-09-17 01:37:07 +02:00
" FROM gam_games"
" WHERE CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2017-07-09 20:31:40 +02:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2017-07-09 20:31:40 +02:00
break;
}
/***** Get number of games *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumGames) != 1)
Lay_ShowErrorAndExit ("Error when getting number of games.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumGames;
}
/*****************************************************************************/
2017-09-01 10:37:00 +02:00
/************* Get average number of questions per course game ***************/
2017-07-09 20:31:40 +02:00
/*****************************************************************************/
2019-11-11 00:15:44 +01:00
double Gam_GetNumQstsPerCrsGame (Hie_Level_t Scope)
2017-07-09 20:31:40 +02:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2019-11-11 00:15:44 +01:00
double NumQstsPerGame;
2017-07-09 20:31:40 +02:00
/***** Get number of questions per game from database *****/
switch (Scope)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
2019-09-17 01:37:07 +02:00
" FROM gam_games,gam_questions"
" WHERE gam_games.GamCod=gam_questions.GamCod"
" GROUP BY gam_questions.GamCod) AS NumQstsTable");
2017-07-09 20:31:40 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
2019-09-17 01:37:07 +02:00
" FROM institutions,centres,degrees,courses,gam_games,gam_questions"
2018-10-31 10:19:01 +01:00
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
2019-09-17 01:37:07 +02:00
" AND courses.CrsCod=gam_games.CrsCod"
" AND gam_games.GamCod=gam_questions.GamCod"
2018-10-31 10:19:01 +01:00
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
2019-09-17 01:37:07 +02:00
Gbl.Hierarchy.Cty.CtyCod);
2017-07-09 20:31:40 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
2019-09-17 01:37:07 +02:00
" FROM centres,degrees,courses,gam_games,gam_questions"
2018-10-31 10:19:01 +01:00
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
2019-09-17 01:37:07 +02:00
" AND courses.CrsCod=gam_games.CrsCod"
" AND gam_games.GamCod=gam_questions.GamCod"
2018-10-31 10:19:01 +01:00
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
2019-09-17 01:37:07 +02:00
Gbl.Hierarchy.Ins.InsCod);
2017-07-09 20:31:40 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
2019-09-17 01:37:07 +02:00
" FROM degrees,courses,gam_games,gam_questions"
2018-10-31 10:19:01 +01:00
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
2019-09-17 01:37:07 +02:00
" AND courses.CrsCod=gam_games.CrsCod"
" AND gam_games.GamCod=gam_questions.GamCod"
2018-10-31 10:19:01 +01:00
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
2019-09-17 01:37:07 +02:00
Gbl.Hierarchy.Ctr.CtrCod);
2017-07-09 20:31:40 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
2019-09-17 01:37:07 +02:00
" FROM courses,gam_games,gam_questions"
2018-10-31 10:19:01 +01:00
" WHERE courses.DegCod=%ld"
2019-09-17 01:37:07 +02:00
" AND courses.CrsCod=gam_games.CrsCod"
" AND gam_games.GamCod=gam_questions.GamCod"
2018-10-31 10:19:01 +01:00
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
2019-09-17 01:37:07 +02:00
Gbl.Hierarchy.Deg.DegCod);
2017-07-09 20:31:40 +02:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2018-10-31 10:19:01 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
2019-09-17 01:37:07 +02:00
" FROM gam_games,gam_questions"
" WHERE gam_games.Cod=%ld"
" AND gam_games.GamCod=gam_questions.GamCod"
2018-10-31 10:19:01 +01:00
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
2019-09-17 01:37:07 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2017-07-09 20:31:40 +02:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2017-07-09 20:31:40 +02:00
break;
}
2019-11-27 09:01:45 +01:00
/***** Get average number of questions per game *****/
2017-07-09 20:31:40 +02:00
row = mysql_fetch_row (mysql_res);
2019-11-27 09:01:45 +01:00
NumQstsPerGame = Str_GetDoubleFromStr (row[0]);
2017-07-09 20:31:40 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumQstsPerGame;
}
2019-09-25 21:58:12 +02:00
/*****************************************************************************/
/************************* Show test tags in a game **************************/
/*****************************************************************************/
void Gam_ShowTstTagsPresentInAGame (long GamCod)
{
MYSQL_RES *mysql_res;
unsigned long NumTags;
/***** Get all tags of questions in this game *****/
NumTags = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get tags"
" present in a match result",
"SELECT tst_tags.TagTxt" // row[0]
" FROM"
" (SELECT DISTINCT(tst_question_tags.TagCod)"
" FROM tst_question_tags,gam_questions"
" WHERE gam_questions.GamCod=%ld"
" AND gam_questions.QstCod=tst_question_tags.QstCod)"
" AS TagsCods,tst_tags"
" WHERE TagsCods.TagCod=tst_tags.TagCod"
" ORDER BY tst_tags.TagTxt",
GamCod);
Tst_ShowTagList (NumTags,mysql_res);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2019-09-29 22:38:32 +02:00
2019-10-21 13:36:28 +02:00
/*****************************************************************************/
/*************** Get maximum score of a game from database *******************/
/*****************************************************************************/
void Gam_GetScoreRange (long GamCod,double *MinScore,double *MaxScore)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumRows;
unsigned NumRow;
unsigned NumAnswers;
/***** Get maximum score of a game from database *****/
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get data of a question",
"SELECT COUNT(tst_answers.AnsInd) AS N"
" FROM tst_answers,gam_questions"
" WHERE gam_questions.GamCod=%ld"
" AND gam_questions.QstCod=tst_answers.QstCod"
" GROUP BY tst_answers.QstCod",
GamCod);
for (NumRow = 0, *MinScore = *MaxScore = 0.0;
NumRow < NumRows;
NumRow++)
{
row = mysql_fetch_row (mysql_res);
/* Get min answers (row[0]) */
if (sscanf (row[0],"%u",&NumAnswers) != 1)
NumAnswers = 0;
/* Accumulate minimum and maximum score */
if (NumAnswers < 2)
Lay_ShowErrorAndExit ("Wrong number of answers.");
*MinScore += -1.0 / (double) (NumAnswers - 1);
*MaxScore += 1.0;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}