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.
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Copyright (C) 1999-2023 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
|
2021-04-23 22:57:57 +02:00
|
|
|
|
#include <stdlib.h> // For free
|
2017-07-09 20:31:40 +02:00
|
|
|
|
#include <string.h> // For string functions
|
|
|
|
|
|
2022-11-06 18:11:10 +01:00
|
|
|
|
#include "swad_action_list.h"
|
2021-11-28 00:49:23 +01:00
|
|
|
|
#include "swad_autolink.h"
|
2022-10-19 18:07:49 +02:00
|
|
|
|
#include "swad_box.h"
|
2017-07-09 20:31:40 +02:00
|
|
|
|
#include "swad_database.h"
|
2021-04-26 15:27:27 +02:00
|
|
|
|
#include "swad_error.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"
|
2021-09-18 17:34:19 +02:00
|
|
|
|
#include "swad_game_database.h"
|
2017-07-09 20:31:40 +02:00
|
|
|
|
#include "swad_global.h"
|
2021-05-27 23:30:16 +02:00
|
|
|
|
#include "swad_hierarchy_level.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"
|
2021-09-24 21:49:06 +02:00
|
|
|
|
#include "swad_match_database.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"
|
2022-10-19 18:07:49 +02:00
|
|
|
|
#include "swad_parameter.h"
|
2023-03-10 17:21:04 +01:00
|
|
|
|
#include "swad_parameter_code.h"
|
2022-09-18 23:15:43 +02:00
|
|
|
|
#include "swad_program_database.h"
|
2017-07-09 20:31:40 +02:00
|
|
|
|
#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 prototypes ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2019-07-04 19:45:15 +02:00
|
|
|
|
static bool Gam_CheckIfICanEditGames (void);
|
2020-09-30 20:23:52 +02:00
|
|
|
|
static bool Gam_CheckIfICanListGameQuestions (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);
|
2023-03-10 00:13:55 +01:00
|
|
|
|
static void Gam_PutParsToCreateNewGame (void *Games);
|
2020-04-08 03:06:45 +02:00
|
|
|
|
|
2022-10-01 13:19:05 +02:00
|
|
|
|
static void Gam_ShowGameMainData (struct Gam_Games *Games,
|
|
|
|
|
bool ShowOnlyThisGame);
|
2019-12-08 16:46:25 +01:00
|
|
|
|
|
2022-09-18 23:15:43 +02:00
|
|
|
|
static void Gam_PutIconsOneGame (void *Games);
|
2020-04-08 03:06:45 +02:00
|
|
|
|
static void Gam_WriteAuthor (struct Gam_Game *Game);
|
2019-12-08 16:46:25 +01:00
|
|
|
|
|
2023-03-10 00:13:55 +01:00
|
|
|
|
static void Gam_PutParGameOrder (Gam_Order_t SelectedOrder);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2022-10-01 13:19:05 +02:00
|
|
|
|
static void Gam_PutIconsToRemEditOneGame (struct Gam_Games *Games,
|
2019-05-20 08:52:07 +02:00
|
|
|
|
const char *Anchor);
|
2019-09-29 17:33:39 +02:00
|
|
|
|
|
2023-03-10 00:13:55 +01:00
|
|
|
|
static void Gam_PutParsOneQst (void *Games);
|
|
|
|
|
static void Gam_PutParOrder (Gam_Order_t SelectedOrder);
|
|
|
|
|
static Gam_Order_t Gam_GetParOrder (void);
|
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 void Gam_PutFormsEditionGame (struct Gam_Games *Games,
|
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
|
|
|
|
|
2022-10-01 13:19:05 +02:00
|
|
|
|
static void Gam_ListGameQuestions (struct Gam_Games *Games);
|
2020-04-08 03:06:45 +02:00
|
|
|
|
static void Gam_ListOneOrMoreQuestionsForEdition (struct Gam_Games *Games,
|
2022-10-01 13:51:03 +02:00
|
|
|
|
unsigned NumQsts,
|
2019-09-30 12:45:45 +02:00
|
|
|
|
MYSQL_RES *mysql_res,
|
|
|
|
|
bool ICanEditQuestions);
|
2020-04-27 16:00:53 +02:00
|
|
|
|
|
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);
|
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
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Games->Game.GamCod = -1L; // Current/selected game code
|
2020-11-25 01:50:13 +01:00
|
|
|
|
Games->MchCod.Current =
|
|
|
|
|
Games->MchCod.Selected = -1L; // Current/selected match code
|
2020-04-08 03:06:45 +02:00
|
|
|
|
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;
|
2021-09-18 18:22:26 +02:00
|
|
|
|
Game->TimeUTC[Dat_STR_TIME] = (time_t) 0;
|
|
|
|
|
Game->TimeUTC[Dat_END_TIME] = (time_t) 0;
|
2020-04-23 23:09:28 +02:00
|
|
|
|
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 *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_GetPars (&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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-10-30 13:28:48 +02:00
|
|
|
|
/******************************* Show all games ******************************/
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2022-09-23 22:57:42 +02:00
|
|
|
|
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;
|
2023-03-02 22:40:41 +01:00
|
|
|
|
struct Pag_Pagination Pagination;
|
2017-07-09 20:31:40 +02:00
|
|
|
|
unsigned NumGame;
|
|
|
|
|
|
2020-04-23 23:09:28 +02:00
|
|
|
|
/***** Reset game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games->Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
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);
|
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** Write links to pages *****/
|
|
|
|
|
Pag_WriteLinksToPagesCentered (Pag_GAMES,&Pagination,
|
|
|
|
|
Games,-1L);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
if (Games->Num)
|
2017-07-09 20:31:40 +02:00
|
|
|
|
{
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** Begin table *****/
|
|
|
|
|
HTM_TABLE_BeginWideMarginPadding (5);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** Table head *****/
|
|
|
|
|
HTM_TR_Begin (NULL);
|
2019-09-26 01:15:21 +02:00
|
|
|
|
|
2022-10-01 13:51:03 +02:00
|
|
|
|
HTM_TH_Span (NULL,HTM_HEAD_CENTER,1,1,"CONTEXT_COL"); // Column for contextual icons
|
2019-09-26 01:15:21 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
for (Order = (Gam_Order_t) 0;
|
|
|
|
|
Order <= (Gam_Order_t) (Gam_NUM_ORDERS - 1);
|
|
|
|
|
Order++)
|
|
|
|
|
{
|
2022-01-02 15:17:30 +01:00
|
|
|
|
HTM_TH_Begin (HTM_HEAD_LEFT);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/* Form to change order */
|
|
|
|
|
Frm_BeginForm (ActSeeAllGam);
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Pag_PutParPagNum (Pag_GAMES,Games->CurrentPage);
|
2023-03-07 09:55:39 +01:00
|
|
|
|
Par_PutParUnsigned (NULL,"Order",(unsigned) Order);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2022-04-01 01:06:44 +02:00
|
|
|
|
HTM_BUTTON_Submit_Begin (Txt_GAMES_ORDER_HELP[Order],
|
|
|
|
|
"class=\"BT_LINK\"");
|
2021-05-20 18:44:13 +02:00
|
|
|
|
if (Order == Games->SelectedOrder)
|
|
|
|
|
HTM_U_Begin ();
|
|
|
|
|
HTM_Txt (Txt_GAMES_ORDER[Order]);
|
|
|
|
|
if (Order == Games->SelectedOrder)
|
|
|
|
|
HTM_U_End ();
|
|
|
|
|
HTM_BUTTON_End ();
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
Frm_EndForm ();
|
2019-12-06 22:18:05 +01:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TH_End ();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-02 15:17:30 +01:00
|
|
|
|
HTM_TH (Txt_Matches,HTM_HEAD_RIGHT);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
|
|
|
|
|
HTM_TR_End ();
|
|
|
|
|
|
|
|
|
|
/***** Write all games *****/
|
|
|
|
|
for (NumGame = Pagination.FirstItemVisible;
|
|
|
|
|
NumGame <= Pagination.LastItemVisible;
|
|
|
|
|
NumGame++)
|
|
|
|
|
{
|
|
|
|
|
/* Get data of this game */
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Games->Game.GamCod = Games->Lst[NumGame - 1].GamCod;
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games->Game);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
|
2022-10-01 13:19:05 +02:00
|
|
|
|
/* Show a pair of rows with the main data of this game */
|
|
|
|
|
Gam_ShowGameMainData (Games,
|
|
|
|
|
false); // Do not show only this game
|
2021-05-20 18:44:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** End table *****/
|
|
|
|
|
HTM_TABLE_End ();
|
|
|
|
|
}
|
|
|
|
|
else // No games created
|
|
|
|
|
Ale_ShowAlert (Ale_INFO,Txt_No_games);
|
|
|
|
|
|
|
|
|
|
/***** Write again links to pages *****/
|
|
|
|
|
Pag_WriteLinksToPagesCentered (Pag_GAMES,&Pagination,
|
|
|
|
|
Games,-1L);
|
|
|
|
|
|
|
|
|
|
/***** Button to create a new game *****/
|
|
|
|
|
if (Gam_CheckIfICanEditGames ())
|
|
|
|
|
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
|
|
|
|
{
|
2021-11-10 21:04:34 +01:00
|
|
|
|
static const bool ICanEditGames[Rol_NUM_ROLES] =
|
2017-07-09 20:31:40 +02:00
|
|
|
|
{
|
2021-11-10 21:04:34 +01:00
|
|
|
|
[Rol_TCH ] = true,
|
|
|
|
|
[Rol_SYS_ADM] = true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ICanEditGames[Gbl.Usrs.Me.Role.Logged];
|
2017-07-09 20:31:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 20:23:52 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************** Check if I can list questions in games *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static bool Gam_CheckIfICanListGameQuestions (void)
|
|
|
|
|
{
|
2021-11-10 21:04:34 +01:00
|
|
|
|
static const bool ICanListGameQuestions[Rol_NUM_ROLES] =
|
2020-09-30 20:23:52 +02:00
|
|
|
|
{
|
2021-11-10 21:04:34 +01:00
|
|
|
|
[Rol_NET ] = true,
|
|
|
|
|
[Rol_TCH ] = true,
|
|
|
|
|
[Rol_SYS_ADM] = true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ICanListGameQuestions[Gbl.Usrs.Me.Role.Logged];
|
2020-09-30 20:23:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/*****************************************************************************/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
/****************** Put contextual icons in list of games ********************/
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-08 03:06:45 +02:00
|
|
|
|
static void Gam_PutIconsListGames (void *Games)
|
2017-07-09 20:31:40 +02:00
|
|
|
|
{
|
2021-11-10 21:04:34 +01:00
|
|
|
|
static const Act_Action_t NextAction[Rol_NUM_ROLES] =
|
|
|
|
|
{
|
|
|
|
|
[Rol_STD ] = ActSeeMyMchResCrs,
|
|
|
|
|
[Rol_NET ] = ActReqSeeUsrMchRes,
|
|
|
|
|
[Rol_TCH ] = ActReqSeeUsrMchRes,
|
|
|
|
|
[Rol_SYS_ADM] = ActReqSeeUsrMchRes,
|
|
|
|
|
};
|
|
|
|
|
|
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 *****/
|
2021-11-10 21:04:34 +01:00
|
|
|
|
if (NextAction[Gbl.Usrs.Me.Role.Logged])
|
|
|
|
|
Ico_PutContextualIconToShowResults (NextAction[Gbl.Usrs.Me.Role.Logged],NULL,
|
|
|
|
|
NULL,NULL);
|
2019-12-06 19:36:22 +01:00
|
|
|
|
|
2022-09-29 01:46:52 +02:00
|
|
|
|
/***** Link to get resource link *****/
|
2023-03-26 20:46:28 +02:00
|
|
|
|
if (Rsc_CheckIfICanGetLink ())
|
2022-09-29 01:46:52 +02:00
|
|
|
|
Ico_PutContextualIconToGetLink (ActReqLnkGam,NULL,
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutPars,Games);
|
2022-09-29 01:46:52 +02: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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
/*********************** Put icon to create a new game ***********************/
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-08 03:06:45 +02:00
|
|
|
|
static void Gam_PutIconToCreateNewGame (struct Gam_Games *Games)
|
2017-07-09 20:31:40 +02:00
|
|
|
|
{
|
2020-03-26 02:54:30 +01:00
|
|
|
|
Ico_PutContextualIconToAdd (ActFrmNewGam,NULL,
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutParsToCreateNewGame,Games);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
/********************* Put button to create a new game ***********************/
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
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;
|
|
|
|
|
|
2021-03-02 00:54:26 +01:00
|
|
|
|
Frm_BeginForm (ActFrmNewGam);
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutParsToCreateNewGame (Games);
|
2021-05-20 18:44:13 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
/******************** Put parameters to create a new game ********************/
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-10 00:13:55 +01:00
|
|
|
|
static void Gam_PutParsToCreateNewGame (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
|
|
|
|
{
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutParGameOrder (((struct Gam_Games *) Games)->SelectedOrder);
|
|
|
|
|
Pag_PutParPagNum (Pag_GAMES,((struct Gam_Games *) Games)->CurrentPage);
|
2020-03-26 02:54:30 +01:00
|
|
|
|
}
|
2017-07-09 20:31:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
/******************************* Show one game *******************************/
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
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;
|
|
|
|
|
|
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 *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/***** Get parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
if ((Games.Game.GamCod = Gam_GetPars (&Games)) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongGameExit ();
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games.Game);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
|
|
|
|
/***** Show game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ShowOnlyOneGame (&Games,
|
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,
|
2019-12-08 16:46:25 +01:00
|
|
|
|
bool ListGameQuestions,
|
|
|
|
|
bool PutFormNewMatch)
|
2019-12-08 17:08:15 +01:00
|
|
|
|
{
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ShowOnlyOneGameBegin (Games,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,
|
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 *****/
|
2023-04-18 17:29:39 +02:00
|
|
|
|
Box_BoxBegin (NULL,Games->Game.Title[0] ? Games->Game.Title :
|
|
|
|
|
Txt_Game,
|
2022-09-18 23:15:43 +02:00
|
|
|
|
Gam_PutIconsOneGame,Games,
|
2019-12-08 16:46:25 +01:00
|
|
|
|
Hlp_ASSESSMENT_Games,Box_NOT_CLOSABLE);
|
|
|
|
|
|
2022-10-01 13:19:05 +02:00
|
|
|
|
/***** Show main data of this game *****/
|
|
|
|
|
Gam_ShowGameMainData (Games,
|
|
|
|
|
true); // Show only this game
|
2019-12-08 16:46:25 +01:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
if (ListGameQuestions)
|
2022-10-01 13:19:05 +02:00
|
|
|
|
/***** Write questions of this game *****/
|
|
|
|
|
Gam_ListGameQuestions (Games);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
else
|
|
|
|
|
/***** List matches *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Mch_ListMatches (Games,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 ();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-01 13:19:05 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********** Show a pair of rows with the main data of a given game ***********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Gam_ShowGameMainData (struct Gam_Games *Games,
|
|
|
|
|
bool ShowOnlyThisGame)
|
2019-12-08 16:46:25 +01:00
|
|
|
|
{
|
2017-07-09 20:31:40 +02:00
|
|
|
|
extern const char *Txt_View_game;
|
2020-05-07 14:15:39 +02:00
|
|
|
|
extern const char *Txt_Number_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 *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Frm_SetAnchorStr (Games->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
|
|
|
|
|
2021-07-08 15:00:17 +02:00
|
|
|
|
/***** Begin 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
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** Icons related to this game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
if (!ShowOnlyThisGame)
|
2022-10-01 13:51:03 +02:00
|
|
|
|
{
|
|
|
|
|
HTM_TD_Begin ("rowspan=\"2\" class=\"CONTEXT_COL %s\"",
|
|
|
|
|
The_GetColorRows ());
|
|
|
|
|
Gam_PutIconsToRemEditOneGame (Games,Anchor);
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
}
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** Start/end date/time *****/
|
|
|
|
|
UniqueId++;
|
|
|
|
|
for (StartEndTime = (Dat_StartEndTime_t) 0;
|
|
|
|
|
StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
|
|
|
|
|
StartEndTime++)
|
|
|
|
|
{
|
|
|
|
|
if (asprintf (&Id,"gam_date_%u_%u",(unsigned) StartEndTime,UniqueId) < 0)
|
|
|
|
|
Err_NotEnoughMemoryExit ();
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Color = Games->Game.NumUnfinishedMchs ? (Games->Game.Hidden ? "DATE_GREEN_LIGHT":
|
|
|
|
|
"DATE_GREEN") :
|
|
|
|
|
(Games->Game.Hidden ? "DATE_RED_LIGHT":
|
|
|
|
|
"DATE_RED");
|
2021-05-20 18:44:13 +02:00
|
|
|
|
if (ShowOnlyThisGame)
|
2022-04-07 13:04:45 +02:00
|
|
|
|
HTM_TD_Begin ("id=\"%s\" class=\"LT %s_%s\"",
|
|
|
|
|
Id,Color,The_GetSuffix ());
|
2021-05-20 18:44:13 +02:00
|
|
|
|
else
|
2022-04-07 13:04:45 +02:00
|
|
|
|
HTM_TD_Begin ("id=\"%s\" class=\"LT %s_%s %s\"",
|
|
|
|
|
Id,Color,The_GetSuffix (),The_GetColorRows ());
|
2022-10-01 13:19:05 +02:00
|
|
|
|
if (Games->Game.TimeUTC[Dat_STR_TIME])
|
|
|
|
|
Dat_WriteLocalDateHMSFromUTC (Id,Games->Game.TimeUTC[StartEndTime],
|
2021-05-20 18:44:13 +02:00
|
|
|
|
Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK,
|
|
|
|
|
true,true,true,0x7);
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
free (Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Game title and main data *****/
|
2019-10-08 23:28:51 +02:00
|
|
|
|
if (ShowOnlyThisGame)
|
2022-04-22 13:33:30 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"LT\"");
|
2019-10-08 23:28:51 +02:00
|
|
|
|
else
|
2022-04-22 13:33:30 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"LT %s\"",The_GetColorRows ());
|
2019-05-20 08:52:07 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/* Game title */
|
|
|
|
|
HTM_ARTICLE_Begin (Anchor);
|
2023-04-06 21:43:41 +02:00
|
|
|
|
Frm_BeginForm (ActSeeOneGam);
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutPars (Games);
|
2022-04-23 00:56:15 +02:00
|
|
|
|
HTM_BUTTON_Submit_Begin (Txt_View_game,"class=\"LT BT_LINK %s_%s\"",
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Games->Game.Hidden ? "ASG_TITLE_LIGHT":
|
|
|
|
|
"ASG_TITLE",
|
2022-04-22 13:33:30 +02:00
|
|
|
|
The_GetSuffix ());
|
2022-10-01 13:19:05 +02:00
|
|
|
|
HTM_Txt (Games->Game.Title);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_BUTTON_End ();
|
|
|
|
|
Frm_EndForm ();
|
|
|
|
|
HTM_ARTICLE_End ();
|
|
|
|
|
|
|
|
|
|
/* Number of questions, maximum grade, visibility of results */
|
2022-04-22 22:22:14 +02:00
|
|
|
|
HTM_DIV_Begin ("class=\"%s_%s\"",
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Games->Game.Hidden ? "ASG_GRP_LIGHT" :
|
2022-04-22 22:22:14 +02:00
|
|
|
|
"ASG_GRP",
|
|
|
|
|
The_GetSuffix ());
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TxtColonNBSP (Txt_Number_of_questions);
|
2022-10-01 13:19:05 +02:00
|
|
|
|
HTM_Unsigned (Games->Game.NumQsts);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_BR ();
|
|
|
|
|
HTM_TxtColonNBSP (Txt_Maximum_grade);
|
2022-10-01 13:19:05 +02:00
|
|
|
|
HTM_Double (Games->Game.MaxGrade);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_BR ();
|
|
|
|
|
HTM_TxtColonNBSP (Txt_Result_visibility);
|
2022-10-01 13:19:05 +02:00
|
|
|
|
TstVis_ShowVisibilityIcons (Games->Game.Visibility,Games->Game.Hidden);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_DIV_End ();
|
|
|
|
|
|
|
|
|
|
/***** Number of matches in game *****/
|
|
|
|
|
if (ShowOnlyThisGame)
|
2022-04-22 13:33:30 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"RT\"");
|
2021-05-20 18:44:13 +02:00
|
|
|
|
else
|
2022-04-22 13:33:30 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"RT %s\"",The_GetColorRows ());
|
2019-09-26 01:15:21 +02:00
|
|
|
|
|
2023-04-06 21:43:41 +02:00
|
|
|
|
Frm_BeginForm (ActSeeOneGam);
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutPars (Games);
|
2022-04-23 00:56:15 +02:00
|
|
|
|
HTM_BUTTON_Submit_Begin (Txt_Matches,"class=\"LT BT_LINK %s_%s\"",
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Games->Game.Hidden ? "ASG_TITLE_LIGHT":
|
|
|
|
|
"ASG_TITLE",
|
2022-04-22 13:33:30 +02:00
|
|
|
|
The_GetSuffix ());
|
2021-05-20 18:44:13 +02:00
|
|
|
|
if (ShowOnlyThisGame)
|
|
|
|
|
HTM_TxtColonNBSP (Txt_Matches);
|
2022-10-01 13:19:05 +02:00
|
|
|
|
HTM_Unsigned (Games->Game.NumMchs);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_BUTTON_End ();
|
|
|
|
|
Frm_EndForm ();
|
2019-09-26 01:15:21 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +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
|
|
|
|
|
2021-07-08 15:00:17 +02:00
|
|
|
|
/***** Begin 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
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** Author of the game *****/
|
|
|
|
|
if (ShowOnlyThisGame)
|
|
|
|
|
HTM_TD_Begin ("colspan=\"2\" class=\"LT\"");
|
|
|
|
|
else
|
2021-12-20 22:43:32 +01:00
|
|
|
|
HTM_TD_Begin ("colspan=\"2\" class=\"LT %s\"",
|
2022-03-19 02:05:53 +01:00
|
|
|
|
The_GetColorRows ());
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_WriteAuthor (&Games->Game);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TD_End ();
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** Text of the game *****/
|
|
|
|
|
if (ShowOnlyThisGame)
|
|
|
|
|
HTM_TD_Begin ("colspan=\"2\" class=\"LT\"");
|
|
|
|
|
else
|
2021-12-20 22:43:32 +01:00
|
|
|
|
HTM_TD_Begin ("colspan=\"2\" class=\"LT %s\"",
|
2022-03-19 02:05:53 +01:00
|
|
|
|
The_GetColorRows ());
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_DB_GetGameTxt (Games->Game.GamCod,Txt);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
|
|
|
|
|
Txt,Cns_MAX_BYTES_TEXT,false); // Convert from HTML to rigorous HTML
|
2021-11-28 00:49:23 +01:00
|
|
|
|
ALn_InsertLinks (Txt,Cns_MAX_BYTES_TEXT,60); // Insert links
|
2022-03-25 11:09:51 +01:00
|
|
|
|
HTM_DIV_Begin ("class=\"PAR %s_%s\"",
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Games->Game.Hidden ? "DAT_LIGHT" :
|
|
|
|
|
"DAT",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
The_GetSuffix ());
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_Txt (Txt);
|
|
|
|
|
HTM_DIV_End ();
|
|
|
|
|
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
|
2022-03-24 01:18:19 +01:00
|
|
|
|
The_ChangeRowColor ();
|
2017-09-13 16:24:29 +02:00
|
|
|
|
|
2019-04-20 22:40:57 +02:00
|
|
|
|
/***** Free anchor string *****/
|
2023-04-06 19:59:33 +02:00
|
|
|
|
Frm_FreeAnchorStr (&Anchor);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-07 02:12:13 +01:00
|
|
|
|
/*****************************************************************************/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
/******************** Put icons to remove/edit one game **********************/
|
2019-12-07 02:12:13 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2022-09-18 23:15:43 +02:00
|
|
|
|
static void Gam_PutIconsOneGame (void *Games)
|
2019-12-07 02:12:13 +01:00
|
|
|
|
{
|
2022-10-01 13:19:05 +02:00
|
|
|
|
char *Anchor = NULL;
|
2021-11-10 21:04:34 +01:00
|
|
|
|
|
|
|
|
|
if (Games)
|
2022-09-18 23:15:43 +02:00
|
|
|
|
{
|
2022-10-01 13:19:05 +02:00
|
|
|
|
/***** Set anchor string *****/
|
|
|
|
|
Frm_SetAnchorStr (((struct Gam_Games *) Games)->Game.GamCod,&Anchor);
|
2022-09-18 23:15:43 +02:00
|
|
|
|
|
2022-10-01 13:19:05 +02:00
|
|
|
|
/***** Icons to remove/edit this game *****/
|
|
|
|
|
Gam_PutIconsToRemEditOneGame (Games,Anchor);
|
|
|
|
|
|
|
|
|
|
/***** Free anchor string *****/
|
2023-04-06 19:59:33 +02:00
|
|
|
|
Frm_FreeAnchorStr (&Anchor);
|
2022-09-18 23:15:43 +02:00
|
|
|
|
}
|
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
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-10 00:13:55 +01:00
|
|
|
|
static void Gam_PutParGameOrder (Gam_Order_t SelectedOrder)
|
2017-07-09 20:31:40 +02:00
|
|
|
|
{
|
2023-03-07 09:55:39 +01:00
|
|
|
|
Par_PutParUnsigned (NULL,"Order",(unsigned) SelectedOrder);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
/******************** Put icons to remove/edit one game **********************/
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2022-10-01 13:19:05 +02:00
|
|
|
|
static void Gam_PutIconsToRemEditOneGame (struct Gam_Games *Games,
|
2019-05-20 08:52:07 +02:00
|
|
|
|
const char *Anchor)
|
2017-07-09 20:31:40 +02:00
|
|
|
|
{
|
2022-07-21 19:30:03 +02:00
|
|
|
|
static Act_Action_t ActionHideUnhide[2] =
|
|
|
|
|
{
|
|
|
|
|
[false] = ActHidGam, // Visible ==> action to hide
|
|
|
|
|
[true ] = ActUnhGam, // Hidden ==> action to unhide
|
|
|
|
|
};
|
2022-10-01 13:19:05 +02:00
|
|
|
|
static const Act_Action_t ActionShowResults[Rol_NUM_ROLES] =
|
|
|
|
|
{
|
|
|
|
|
[Rol_STD ] = ActSeeMyMchResGam,
|
|
|
|
|
[Rol_NET ] = ActSeeUsrMchResGam,
|
|
|
|
|
[Rol_TCH ] = ActSeeUsrMchResGam,
|
|
|
|
|
[Rol_SYS_ADM] = ActSeeUsrMchResGam,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (Gam_CheckIfICanEditGames ())
|
|
|
|
|
{
|
|
|
|
|
/***** Icon to remove game *****/
|
|
|
|
|
Ico_PutContextualIconToRemove (ActReqRemGam,NULL,
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutPars,Games);
|
2022-10-01 13:19:05 +02:00
|
|
|
|
|
|
|
|
|
/***** Icon to unhide/hide game *****/
|
|
|
|
|
Ico_PutContextualIconToHideUnhide (ActionHideUnhide,Anchor,
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutPars,Games,
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Games->Game.Hidden);
|
|
|
|
|
|
|
|
|
|
/***** Icon to edit game *****/
|
|
|
|
|
Ico_PutContextualIconToEdit (ActEdiOneGam,NULL,
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutPars,Games);
|
2022-10-01 13:19:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Gam_CheckIfICanListGameQuestions ())
|
|
|
|
|
/***** Icon to view game listing its questions *****/
|
|
|
|
|
Ico_PutContextualIconToView (ActLstOneGam,NULL,
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutPars,Games);
|
2022-07-21 19:30:03 +02:00
|
|
|
|
|
2022-10-01 13:19:05 +02:00
|
|
|
|
/***** Put icon to view matches results *****/
|
|
|
|
|
if (ActionShowResults[Gbl.Usrs.Me.Role.Logged])
|
|
|
|
|
Ico_PutContextualIconToShowResults (ActionShowResults[Gbl.Usrs.Me.Role.Logged],MchRes_RESULTS_BOX_ID,
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutPars,Games);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2022-10-01 13:19:05 +02:00
|
|
|
|
/***** Link to get resource link *****/
|
2023-03-26 20:46:28 +02:00
|
|
|
|
if (Rsc_CheckIfICanGetLink ())
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Ico_PutContextualIconToGetLink (ActReqLnkGam,NULL,
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutPars,Games);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2020-02-26 00:26:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************** Put parameter to move/remove one question ******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-10 00:13:55 +01:00
|
|
|
|
static void Gam_PutParsOneQst (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
|
|
|
|
{
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutPars (Games);
|
|
|
|
|
Gam_PutParQstInd (((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
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-10 00:13:55 +01:00
|
|
|
|
void Gam_PutPars (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
|
|
|
|
{
|
2023-03-10 17:21:04 +01:00
|
|
|
|
ParCod_PutPar (ParCod_Gam,((struct Gam_Games *) Games)->Game.GamCod);
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutParOrder (((struct Gam_Games *) Games)->SelectedOrder);
|
|
|
|
|
WhichGroups = Grp_GetParWhichGroups ();
|
|
|
|
|
Grp_PutParWhichGroups (&WhichGroups);
|
|
|
|
|
Pag_PutParPagNum (Pag_GAMES,((struct Gam_Games *) Games)->CurrentPage);
|
2020-03-26 02:54:30 +01:00
|
|
|
|
}
|
2019-12-07 02:12:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-29 17:33:39 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Get parameters used to edit a game **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-10 00:13:55 +01:00
|
|
|
|
long Gam_GetPars (struct Gam_Games *Games)
|
2019-09-29 17:33:39 +02:00
|
|
|
|
{
|
|
|
|
|
/***** Get other parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Games->SelectedOrder = Gam_GetParOrder ();
|
|
|
|
|
Games->CurrentPage = Pag_GetParPagNum (Pag_GAMES);
|
2019-09-29 17:33:39 +02:00
|
|
|
|
|
|
|
|
|
/***** Get game code *****/
|
2023-03-10 17:21:04 +01:00
|
|
|
|
return ParCod_GetPar (ParCod_Gam);
|
2019-09-29 17:33:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-04 17:17:15 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****** Put a hidden parameter with the type of order in list of games *******/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-10 00:13:55 +01:00
|
|
|
|
static void Gam_PutParOrder (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)
|
2023-03-07 09:55:39 +01:00
|
|
|
|
Par_PutParUnsigned (NULL,"Order",(unsigned) SelectedOrder);
|
2019-07-04 17:17:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********** Get parameter with the type or order in list of games ************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-10 00:13:55 +01:00
|
|
|
|
static Gam_Order_t Gam_GetParOrder (void)
|
2019-07-04 17:17:15 +02:00
|
|
|
|
{
|
2023-03-07 09:55:39 +01:00
|
|
|
|
return (Gam_Order_t) Par_GetParUnsignedLong ("Order",
|
2023-03-10 00:13:55 +01:00
|
|
|
|
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
|
|
|
|
/*****************************************************************************/
|
2021-10-30 13:28:48 +02:00
|
|
|
|
/************************** Get list of all games ****************************/
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
/***** Get list of games from database *****/
|
2021-09-18 17:34:19 +02:00
|
|
|
|
if ((Games->Num = Gam_DB_GetListGames (&mysql_res,SelectedOrder))) // Games found...
|
2017-07-09 20:31:40 +02:00
|
|
|
|
{
|
|
|
|
|
/***** Create list of games *****/
|
2021-04-16 13:51:12 +02:00
|
|
|
|
if ((Games->Lst = malloc ((size_t) Games->Num *
|
|
|
|
|
sizeof (*Games->Lst))) == NULL)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_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)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongGameExit ();
|
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
|
|
|
|
{
|
2023-03-06 23:53:45 +01:00
|
|
|
|
extern const char *Par_CodeStr[];
|
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];
|
|
|
|
|
|
2020-06-23 11:48:06 +02:00
|
|
|
|
/***** Default selected *****/
|
|
|
|
|
Games->NumSelected = 0;
|
|
|
|
|
|
|
|
|
|
/***** Trivial check: there are games visibles by me *****/
|
|
|
|
|
if (!Games->Num)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-11-25 23:18:08 +01:00
|
|
|
|
/***** Allocate memory for list of games selected *****/
|
2020-04-08 03:06:45 +02:00
|
|
|
|
MaxSizeListGamCodsSelected = Games->Num * (Cns_MAX_DECIMAL_DIGITS_LONG + 1);
|
2021-02-15 16:25:55 +01:00
|
|
|
|
if ((Games->GamCodsSelected = malloc (MaxSizeListGamCodsSelected + 1)) == NULL)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NotEnoughMemoryExit ();
|
2019-11-25 23:18:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Get parameter multiple with list of games selected *****/
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Par_GetParMultiToText (Par_CodeStr[ParCod_Gam],Games->GamCodsSelected,
|
2023-03-06 23:53:45 +01:00
|
|
|
|
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;
|
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 */
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Par_GetNextStrUntilSeparParMult (&Ptr,LongStr,Cns_MAX_DECIMAL_DIGITS_LONG);
|
2019-11-25 23:18:08 +01:00
|
|
|
|
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
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
void Gam_GetGameDataByCod (struct Gam_Game *Game)
|
2017-07-09 20:31:40 +02:00
|
|
|
|
{
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
|
|
|
|
|
/***** Get data of game from database *****/
|
2023-03-23 09:35:20 +01:00
|
|
|
|
if (Gam_DB_GetGameDataByCod (&mysql_res,Game->GamCod)) // Game found...
|
2017-07-09 20:31:40 +02:00
|
|
|
|
{
|
|
|
|
|
/* 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]) */
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (Game->Title,row[6],sizeof (Game->Title) - 1);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2019-07-17 19:39:35 +02:00
|
|
|
|
/* Get number of questions */
|
2021-05-20 18:44:13 +02:00
|
|
|
|
Game->NumQsts = Gam_DB_GetNumQstsGame (Game->GamCod);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2019-09-26 01:15:21 +02:00
|
|
|
|
/* Get number of matches */
|
2021-09-18 17:34:19 +02:00
|
|
|
|
Game->NumMchs = Mch_DB_GetNumMchsInGame (Game->GamCod);
|
2019-12-10 21:52:22 +01:00
|
|
|
|
|
|
|
|
|
/* Get number of unfinished matches */
|
2021-09-18 17:34:19 +02:00
|
|
|
|
Game->NumUnfinishedMchs = Mch_DB_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 *****/
|
2021-09-18 17:34:19 +02:00
|
|
|
|
if (Mch_DB_GetStartEndMatchesInGame (&mysql_res,Game->GamCod))
|
2019-07-04 16:06:31 +02:00
|
|
|
|
{
|
|
|
|
|
/* Get row */
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
|
|
|
|
|
2021-09-18 17:34:19 +02:00
|
|
|
|
/* Get start date (row[0] holds the start UTC time)
|
|
|
|
|
and end date (row[1] holds the end UTC time) */
|
2021-09-18 18:22:26 +02:00
|
|
|
|
Game->TimeUTC[Dat_STR_TIME] = Dat_GetUNIXTimeFromStr (row[0]);
|
|
|
|
|
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
|
|
|
|
|
{
|
2021-09-18 18:22:26 +02:00
|
|
|
|
Game->TimeUTC[Dat_STR_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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
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 *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/***** Get parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
if ((Games.Game.GamCod = Gam_GetPars (&Games)) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongGameExit ();
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
|
|
|
|
/***** Get data of the game from database *****/
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games.Game);
|
2019-09-29 20:00:54 +02:00
|
|
|
|
if (!Gam_CheckIfICanEditGames ())
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NoPermissionExit ();
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
|
|
|
|
/***** Show question and button to remove game *****/
|
2020-03-26 02:54:30 +01:00
|
|
|
|
Ale_ShowAlertAndButton (ActRemGam,NULL,NULL,
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutPars,&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,
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Games.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;
|
|
|
|
|
|
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 *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/***** Get game code *****/
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Games.Game.GamCod = ParCod_GetAndCheckPar (ParCod_Gam);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
|
|
|
|
/***** Get data of the game from database *****/
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games.Game);
|
2019-09-29 20:00:54 +02:00
|
|
|
|
if (!Gam_CheckIfICanEditGames ())
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NoPermissionExit ();
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2019-09-27 21:45:53 +02:00
|
|
|
|
/***** Remove game from all tables *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_RemoveGameFromAllTables (Games.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,
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Games.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);
|
|
|
|
|
|
2021-09-18 19:33:01 +02:00
|
|
|
|
/***** Remove game questions *****/
|
|
|
|
|
Gam_DB_RemoveGameQsts (GamCod);
|
2019-09-27 21:45:53 +02:00
|
|
|
|
|
2019-09-28 01:12:53 +02:00
|
|
|
|
/***** Remove game *****/
|
2021-09-18 19:33:01 +02:00
|
|
|
|
Gam_DB_RemoveGame (GamCod);
|
2019-09-27 21:45:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-10-30 13:28:48 +02:00
|
|
|
|
/*********************** Remove all games of a course ************************/
|
2019-09-27 21:45:53 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-05-18 22:59:07 +02:00
|
|
|
|
void Gam_RemoveCrsGames (long CrsCod)
|
2019-09-27 21:45:53 +02:00
|
|
|
|
{
|
2019-09-28 01:12:53 +02:00
|
|
|
|
/***** Remove all matches in this course *****/
|
2020-05-18 22:59:07 +02:00
|
|
|
|
Mch_RemoveMatchesInCourseFromAllTables (CrsCod);
|
2019-09-28 01:12:53 +02:00
|
|
|
|
|
|
|
|
|
/***** Remove the questions in games *****/
|
2021-09-18 19:33:01 +02:00
|
|
|
|
Gam_DB_RemoveCrsGameQsts (CrsCod);
|
2019-09-28 01:12:53 +02:00
|
|
|
|
|
|
|
|
|
/***** Remove the games *****/
|
2021-09-18 19:33:01 +02:00
|
|
|
|
Gam_DB_RemoveCrsGames (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;
|
|
|
|
|
|
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 *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
2019-09-29 17:33:39 +02:00
|
|
|
|
/***** Get parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
if ((Games.Game.GamCod = Gam_GetPars (&Games)) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongGameExit ();
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
|
|
|
|
/***** Get data of the game from database *****/
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games.Game);
|
2019-09-29 20:00:54 +02:00
|
|
|
|
if (!Gam_CheckIfICanEditGames ())
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NoPermissionExit ();
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
|
|
|
|
/***** Hide game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_DB_HideOrUnhideGame (Games.Game.GamCod,true);
|
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;
|
|
|
|
|
|
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 *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
2019-09-29 17:33:39 +02:00
|
|
|
|
/***** Get parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
if ((Games.Game.GamCod = Gam_GetPars (&Games)) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongGameExit ();
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
|
|
|
|
/***** Get data of the game from database *****/
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games.Game);
|
2019-09-29 20:00:54 +02:00
|
|
|
|
if (!Gam_CheckIfICanEditGames ())
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NoPermissionExit ();
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2021-09-18 19:33:01 +02:00
|
|
|
|
/***** Unhide game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_DB_HideOrUnhideGame (Games.Game.GamCod,false);
|
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
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 20:23:52 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************* List the questions in a game **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Gam_ListGame (void)
|
|
|
|
|
{
|
|
|
|
|
struct Gam_Games Games;
|
|
|
|
|
char Txt[Cns_MAX_BYTES_TEXT + 1];
|
|
|
|
|
|
|
|
|
|
/***** Reset games context *****/
|
|
|
|
|
Gam_ResetGames (&Games);
|
|
|
|
|
|
|
|
|
|
/***** Reset game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-09-30 20:23:52 +02:00
|
|
|
|
|
|
|
|
|
/***** Check if I can list game questions *****/
|
|
|
|
|
if (!Gam_CheckIfICanListGameQuestions ())
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NoPermissionExit ();
|
2020-09-30 20:23:52 +02:00
|
|
|
|
|
|
|
|
|
/***** Get parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
if ((Games.Game.GamCod = Gam_GetPars (&Games)) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongGameExit ();
|
2020-09-30 20:23:52 +02:00
|
|
|
|
|
|
|
|
|
/***** Get game data *****/
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games.Game);
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_DB_GetGameTxt (Games.Game.GamCod,Txt);
|
2020-09-30 20:23:52 +02:00
|
|
|
|
|
|
|
|
|
/***** Show game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ShowOnlyOneGame (&Games,
|
2020-09-30 20:23:52 +02:00
|
|
|
|
true, // List game questions
|
|
|
|
|
false); // Do not put form to start new match
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-17 12:51:11 +01:00
|
|
|
|
void Gam_ReqCreatOrEditGame (void)
|
2019-10-03 09:22:09 +02:00
|
|
|
|
{
|
2020-04-08 03:06:45 +02:00
|
|
|
|
struct Gam_Games Games;
|
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 *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
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 ())
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NoPermissionExit ();
|
2019-10-03 09:22:09 +02:00
|
|
|
|
|
|
|
|
|
/***** Get parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
ItsANewGame = ((Games.Game.GamCod = Gam_GetPars (&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 */
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-03-09 22:14:06 +01:00
|
|
|
|
Txt[0] = '\0';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Get game data from database */
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games.Game);
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_DB_GetGameTxt (Games.Game.GamCod,Txt);
|
2020-03-09 22:14:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-03 09:22:09 +02:00
|
|
|
|
/***** Put forms to create/edit a game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_PutFormsEditionGame (&Games,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 */
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ListGameQuestions (&Games);
|
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,
|
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;
|
|
|
|
|
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 *****/
|
2021-03-02 00:54:26 +01:00
|
|
|
|
Frm_BeginForm (ItsANewGame ? ActNewGam :
|
2019-09-30 12:45:45 +02:00
|
|
|
|
ActChgGam);
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutPars (Games);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** Begin box and table *****/
|
|
|
|
|
if (ItsANewGame)
|
|
|
|
|
Box_BoxTableBegin (NULL,Txt_New_game,
|
|
|
|
|
NULL,NULL,
|
|
|
|
|
Hlp_ASSESSMENT_Games_new_game,Box_NOT_CLOSABLE,2);
|
|
|
|
|
else
|
|
|
|
|
Box_BoxTableBegin (NULL,
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Games->Game.Title[0] ? Games->Game.Title :
|
|
|
|
|
Txt_Edit_game,
|
2021-05-20 18:44:13 +02:00
|
|
|
|
NULL,NULL,
|
|
|
|
|
Hlp_ASSESSMENT_Games_edit_game,Box_NOT_CLOSABLE,2);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** Game title *****/
|
|
|
|
|
HTM_TR_Begin (NULL);
|
2019-10-07 15:15:55 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/* Label */
|
|
|
|
|
Frm_LabelColumn ("RT","Title",Txt_Title);
|
2019-10-07 15:15:55 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/* Data */
|
|
|
|
|
HTM_TD_Begin ("class=\"LT\"");
|
2022-10-01 13:19:05 +02:00
|
|
|
|
HTM_INPUT_TEXT ("Title",Gam_MAX_CHARS_TITLE,Games->Game.Title,
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_DONT_SUBMIT_ON_CHANGE,
|
2021-12-18 00:57:27 +01:00
|
|
|
|
"id=\"Title\""
|
2022-03-30 00:46:18 +02:00
|
|
|
|
" class=\"TITLE_DESCRIPTION_WIDTH INPUT_%s\""
|
2021-12-18 00:57:27 +01:00
|
|
|
|
" required=\"required\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
The_GetSuffix ());
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TD_End ();
|
2019-10-07 15:15:55 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TR_End ();
|
2019-09-30 12:45:45 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** Maximum grade *****/
|
|
|
|
|
HTM_TR_Begin (NULL);
|
2019-11-27 01:01:27 +01:00
|
|
|
|
|
2022-04-05 01:00:24 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"RM FORM_IN_%s\"",The_GetSuffix ());
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TxtColon (Txt_Maximum_grade);
|
|
|
|
|
HTM_TD_End ();
|
2019-11-27 01:01:27 +01:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"LM\"");
|
2022-10-01 13:19:05 +02:00
|
|
|
|
HTM_INPUT_FLOAT ("MaxGrade",0.0,DBL_MAX,0.01,Games->Game.MaxGrade,false,
|
2022-03-30 00:46:18 +02:00
|
|
|
|
" class=\"INPUT_%s\" required=\"required\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
The_GetSuffix ());
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TD_End ();
|
2019-11-27 01:01:27 +01:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TR_End ();
|
2019-11-27 01:01:27 +01:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** Visibility of results *****/
|
|
|
|
|
HTM_TR_Begin (NULL);
|
2020-02-18 15:40:04 +01:00
|
|
|
|
|
2022-04-05 01:00:24 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"RT FORM_IN_%s\"",The_GetSuffix ());
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TxtColon (Txt_Result_visibility);
|
|
|
|
|
HTM_TD_End ();
|
2020-02-18 15:40:04 +01:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"LB\"");
|
2022-10-01 13:19:05 +02:00
|
|
|
|
TstVis_PutVisibilityCheckboxes (Games->Game.Visibility);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TD_End ();
|
2020-02-18 15:40:04 +01:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TR_End ();
|
2020-02-18 15:40:04 +01:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** Game text *****/
|
|
|
|
|
HTM_TR_Begin (NULL);
|
2019-10-07 15:15:55 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/* Label */
|
|
|
|
|
Frm_LabelColumn ("RT","Txt",Txt_Description);
|
2019-10-07 15:15:55 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/* Data */
|
|
|
|
|
HTM_TD_Begin ("class=\"LT\"");
|
|
|
|
|
HTM_TEXTAREA_Begin ("id=\"Txt\" name=\"Txt\" rows=\"5\""
|
2022-03-30 00:46:18 +02:00
|
|
|
|
" class=\"TITLE_DESCRIPTION_WIDTH INPUT_%s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
The_GetSuffix ());
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_Txt (Txt);
|
|
|
|
|
HTM_TEXTAREA_End ();
|
|
|
|
|
HTM_TD_End ();
|
2019-10-07 15:15:55 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TR_End ();
|
2019-09-30 12:45:45 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** End table, send button and end box *****/
|
|
|
|
|
if (ItsANewGame)
|
|
|
|
|
Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_game);
|
|
|
|
|
else
|
|
|
|
|
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
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-05-05 21:49:00 +02:00
|
|
|
|
void Gam_ReceiveFormGame (void)
|
2017-07-09 20:31:40 +02:00
|
|
|
|
{
|
2020-04-08 03:06:45 +02:00
|
|
|
|
struct Gam_Games Games;
|
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 *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
2020-03-08 19:13:38 +01:00
|
|
|
|
/***** Check if I can edit games *****/
|
|
|
|
|
if (!Gam_CheckIfICanEditGames ())
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NoPermissionExit ();
|
2020-03-08 19:13:38 +01:00
|
|
|
|
|
2019-11-28 10:15:39 +01:00
|
|
|
|
/***** Get parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
ItsANewGame = ((Games.Game.GamCod = Gam_GetPars (&Games)) <= 0);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2023-04-10 14:41:20 +02:00
|
|
|
|
/***** Receive game from form *****/
|
|
|
|
|
Gam_ReceiveGameFieldsFromForm (&Games.Game,Txt);
|
|
|
|
|
if (Gam_CheckGameFieldsReceivedFromForm (&Games.Game))
|
2017-07-09 20:31:40 +02:00
|
|
|
|
{
|
2023-04-10 14:41:20 +02:00
|
|
|
|
/***** Create a new game or update an existing one *****/
|
|
|
|
|
if (ItsANewGame)
|
|
|
|
|
Gam_CreateGame (&Games.Game,Txt); // Add new game to database
|
|
|
|
|
else
|
|
|
|
|
Gam_UpdateGame (&Games.Game,Txt); // Update game data in database
|
2019-10-03 09:22:09 +02:00
|
|
|
|
|
2023-04-10 14:41:20 +02:00
|
|
|
|
/***** Put forms to edit the game created or updated *****/
|
|
|
|
|
Gam_PutFormsEditionGame (&Games,Txt,
|
|
|
|
|
false); // No new game
|
2020-03-09 22:14:06 +01:00
|
|
|
|
|
2023-04-10 14:41:20 +02:00
|
|
|
|
/***** Show questions of the game ready to be edited ******/
|
|
|
|
|
Gam_ListGameQuestions (&Games);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
}
|
2019-09-30 12:54:10 +02:00
|
|
|
|
else
|
2023-04-10 14:41:20 +02:00
|
|
|
|
{
|
|
|
|
|
/***** Put forms to create/edit the game *****/
|
|
|
|
|
Gam_PutFormsEditionGame (&Games,Txt,ItsANewGame);
|
|
|
|
|
|
|
|
|
|
/***** Show games or questions *****/
|
|
|
|
|
if (ItsANewGame)
|
|
|
|
|
/* Show games again */
|
|
|
|
|
Gam_ListAllGames (&Games);
|
|
|
|
|
else
|
|
|
|
|
/* Show questions of the game ready to be edited */
|
|
|
|
|
Gam_ListGameQuestions (&Games);
|
|
|
|
|
}
|
|
|
|
|
|
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 *****/
|
2023-03-07 09:55:39 +01:00
|
|
|
|
Par_GetParText ("Title",Game->Title,Gam_MAX_BYTES_TITLE);
|
2020-03-08 19:13:38 +01:00
|
|
|
|
|
|
|
|
|
/***** Get maximum grade *****/
|
2023-03-07 09:55:39 +01:00
|
|
|
|
Par_GetParText ("MaxGrade",MaxGradeStr,sizeof (MaxGradeStr) - 1);
|
2020-03-08 19:13:38 +01:00
|
|
|
|
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 *****/
|
2023-03-07 09:55:39 +01:00
|
|
|
|
Par_GetParHTML ("Txt",Txt,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous)
|
2020-03-08 19:13:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
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... */
|
2021-05-20 18:44:13 +02:00
|
|
|
|
if (Gam_DB_CheckIfSimilarGameExists (Game))
|
2020-03-08 19:13:38 +01:00
|
|
|
|
{
|
|
|
|
|
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;
|
2023-04-17 23:55:22 +02:00
|
|
|
|
Ale_CreateAlertYouMustSpecifyTheTitle ();
|
2020-03-08 19:13:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 *****/
|
2021-09-18 19:33:01 +02:00
|
|
|
|
Game->GamCod = Gam_DB_CreateGame (Game,Txt);
|
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 *****/
|
2021-09-18 19:33:01 +02:00
|
|
|
|
Gam_DB_UpdateGame (Game,Txt);
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
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
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-27 14:20:21 +02:00
|
|
|
|
void Gam_ReqSelectQstsToAddToGame (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
|
|
|
|
|
2020-04-23 23:09:28 +02:00
|
|
|
|
/***** Reset game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
2019-09-29 17:33:39 +02:00
|
|
|
|
/***** Get parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
if ((Games.Game.GamCod = Gam_GetPars (&Games)) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongGameExit ();
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games.Game);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2019-09-26 21:27:36 +02:00
|
|
|
|
/***** Check if game has matches *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
if (!Gam_CheckIfEditable (&Games.Game))
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NoPermissionExit ();
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2020-04-27 00:06:58 +02:00
|
|
|
|
/***** Show form to create a new question in this game *****/
|
2021-10-24 21:35:42 +02:00
|
|
|
|
Qst_RequestSelectQstsForGame (&Games);
|
2020-04-27 00:06:58 +02:00
|
|
|
|
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/***** Show current game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ShowOnlyOneGame (&Games,
|
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 ******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-27 14:20:21 +02:00
|
|
|
|
void Gam_ListQstsToAddToGame (void)
|
2019-09-26 21:27:36 +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);
|
2019-09-26 21:27:36 +02:00
|
|
|
|
|
2020-04-23 23:09:28 +02:00
|
|
|
|
/***** Reset game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
2019-09-29 17:33:39 +02:00
|
|
|
|
/***** Get parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
if ((Games.Game.GamCod = Gam_GetPars (&Games)) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongGameExit ();
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games.Game);
|
2019-09-26 21:27:36 +02:00
|
|
|
|
|
|
|
|
|
/***** Check if game has matches *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
if (!Gam_CheckIfEditable (&Games.Game))
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NoPermissionExit ();
|
2020-04-27 00:06:58 +02:00
|
|
|
|
|
|
|
|
|
/***** List several test questions for selection *****/
|
2021-10-25 09:30:46 +02:00
|
|
|
|
Qst_ListQuestionsToSelectForGame (&Games);
|
2019-09-26 21:27:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-13 21:22:52 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Write parameter with index of question *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-10 00:13:55 +01:00
|
|
|
|
void Gam_PutParQstInd (unsigned QstInd)
|
2017-09-13 21:22:52 +02:00
|
|
|
|
{
|
2023-03-07 09:55:39 +01:00
|
|
|
|
Par_PutParUnsigned (NULL,"QstInd",QstInd);
|
2017-09-13 21:22:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Get parameter with index of question ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-10 00:13:55 +01:00
|
|
|
|
unsigned Gam_GetParQstInd (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
|
|
|
|
|
2023-03-07 09:55:39 +01:00
|
|
|
|
if ((QstInd = Par_GetParLong ("QstInd")) <= 0) // In games, question index should be 1, 2, 3...
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongQuestionIndexExit ();
|
2017-09-13 21:22:52 +02:00
|
|
|
|
|
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
|
|
|
|
/*****************************************************************************/
|
2017-09-06 15:03:43 +02:00
|
|
|
|
/************************ List the questions of a game ***********************/
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2022-10-01 13:19:05 +02:00
|
|
|
|
static void Gam_ListGameQuestions (struct Gam_Games *Games)
|
2017-07-09 20:31:40 +02:00
|
|
|
|
{
|
|
|
|
|
extern const char *Hlp_ASSESSMENT_Games_questions;
|
|
|
|
|
extern const char *Txt_Questions;
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
unsigned NumQsts;
|
2022-10-01 13:19:05 +02:00
|
|
|
|
bool ICanEditQuestions = Gam_CheckIfEditable (&Games->Game);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
|
|
|
|
/***** Get data of questions from database *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
NumQsts = Gam_DB_GetGameQuestionsBasic (&mysql_res,Games->Game.GamCod);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2019-10-26 02:19:42 +02:00
|
|
|
|
/***** Begin box *****/
|
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)
|
2022-10-01 13:51:03 +02:00
|
|
|
|
Gam_ListOneOrMoreQuestionsForEdition (Games,NumQsts,mysql_res,
|
2019-09-30 12:45:45 +02:00
|
|
|
|
ICanEditQuestions);
|
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,
|
2022-10-01 13:51:03 +02:00
|
|
|
|
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-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;
|
2021-10-24 21:35:42 +02:00
|
|
|
|
struct Qst_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;
|
2020-04-27 16:00:53 +02:00
|
|
|
|
char *Anchor = NULL;
|
2019-05-30 12:57:31 +02:00
|
|
|
|
|
2020-04-28 12:34:56 +02:00
|
|
|
|
/***** Trivial check *****/
|
|
|
|
|
if (!NumQsts)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-05-30 12:57:31 +02:00
|
|
|
|
/***** Get maximum question index *****/
|
2022-10-01 13:51:03 +02:00
|
|
|
|
MaxQstInd = Gam_DB_GetMaxQuestionIndexInGame (Games->Game.GamCod); // 0 is no questions in game
|
2017-09-06 15:03:43 +02:00
|
|
|
|
|
|
|
|
|
/***** Write the heading *****/
|
2020-05-17 22:16:39 +02:00
|
|
|
|
HTM_TABLE_BeginWideMarginPadding (5);
|
2019-10-08 23:28:51 +02:00
|
|
|
|
|
2022-01-02 00:39:26 +01:00
|
|
|
|
HTM_TR_Begin (NULL);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TH_Empty (1);
|
2022-01-02 15:17:30 +01:00
|
|
|
|
HTM_TH (Txt_No_INDEX,HTM_HEAD_CENTER);
|
|
|
|
|
HTM_TH (Txt_Code ,HTM_HEAD_CENTER);
|
|
|
|
|
HTM_TH (Txt_Tags ,HTM_HEAD_CENTER);
|
|
|
|
|
HTM_TH (Txt_Question,HTM_HEAD_CENTER);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
HTM_TR_End ();
|
2017-09-08 01:18:20 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** Write rows *****/
|
2022-09-02 23:57:38 +02:00
|
|
|
|
for (NumQst = 0, The_ResetRowColor ();
|
2021-05-20 18:44:13 +02:00
|
|
|
|
NumQst < NumQsts;
|
2022-03-24 01:18:19 +01:00
|
|
|
|
NumQst++, The_ChangeRowColor ())
|
2017-09-10 18:58:26 +02:00
|
|
|
|
{
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** Create test question *****/
|
2021-10-24 21:35:42 +02:00
|
|
|
|
Qst_QstConstructor (&Question);
|
2017-09-06 15:03:43 +02:00
|
|
|
|
|
2021-05-20 18:44:13 +02:00
|
|
|
|
/***** Get question data *****/
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
|
|
|
|
/*
|
2021-09-24 21:49:06 +02:00
|
|
|
|
row[0] QstCod
|
|
|
|
|
row[1] QstInd
|
2021-05-20 18:44:13 +02:00
|
|
|
|
*/
|
2021-09-24 21:49:06 +02:00
|
|
|
|
/* Get question code (row[0]) */
|
|
|
|
|
Question.QstCod = Str_ConvertStrCodToLongCod (row[0]);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
|
2021-09-24 21:49:06 +02:00
|
|
|
|
/* Get question index (row[1]) */
|
|
|
|
|
QstInd = Str_ConvertStrToUnsigned (row[1]);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
snprintf (StrQstInd,sizeof (StrQstInd),"%u",QstInd);
|
|
|
|
|
|
|
|
|
|
/* Initialize context */
|
2022-10-01 13:51:03 +02:00
|
|
|
|
Games->QstInd = QstInd;
|
2021-05-20 18:44:13 +02:00
|
|
|
|
|
|
|
|
|
/***** Build anchor string *****/
|
|
|
|
|
Frm_SetAnchorStr (Question.QstCod,&Anchor);
|
|
|
|
|
|
|
|
|
|
/***** Begin row *****/
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
|
|
|
|
|
/***** Icons *****/
|
2022-03-19 02:05:53 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"BT %s\"",The_GetColorRows ());
|
2021-05-20 18:44:13 +02:00
|
|
|
|
|
|
|
|
|
/* Put icon to remove the question */
|
|
|
|
|
if (ICanEditQuestions)
|
|
|
|
|
Ico_PutContextualIconToRemove (ActReqRemGamQst,NULL,
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutParsOneQst,Games);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
else
|
|
|
|
|
Ico_PutIconRemovalNotAllowed ();
|
|
|
|
|
|
|
|
|
|
/* Put icon to move up the question */
|
|
|
|
|
if (ICanEditQuestions && QstInd > 1)
|
|
|
|
|
Lay_PutContextualLinkOnlyIcon (ActUp_GamQst,Anchor,
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutParsOneQst,Games,
|
2022-06-29 18:34:15 +02:00
|
|
|
|
"arrow-up.svg",Ico_BLACK);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
else
|
2021-12-22 00:20:06 +01:00
|
|
|
|
Ico_PutIconOff ("arrow-up.svg",Ico_BLACK,
|
|
|
|
|
Txt_Movement_not_allowed);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
|
|
|
|
|
/* Put icon to move down the question */
|
|
|
|
|
if (ICanEditQuestions && QstInd < MaxQstInd)
|
|
|
|
|
Lay_PutContextualLinkOnlyIcon (ActDwnGamQst,Anchor,
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutParsOneQst,Games,
|
2022-06-29 18:34:15 +02:00
|
|
|
|
"arrow-down.svg",Ico_BLACK);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
else
|
2021-12-22 00:20:06 +01:00
|
|
|
|
Ico_PutIconOff ("arrow-down.svg",Ico_BLACK,
|
|
|
|
|
Txt_Movement_not_allowed);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
|
|
|
|
|
/* Put icon to edit the question */
|
|
|
|
|
if (ICanEditQuestions)
|
|
|
|
|
Ico_PutContextualIconToEdit (ActEdiOneTstQst,NULL,
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Qst_PutParQstCod,&Question.QstCod);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/***** Question *****/
|
2023-03-23 19:31:53 +01:00
|
|
|
|
QuestionExists = Qst_GetQstDataByCod (&Question);
|
2021-10-24 21:35:42 +02:00
|
|
|
|
Qst_ListQuestionForEdition (&Question,QstInd,QuestionExists,Anchor);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
|
|
|
|
|
/***** End row *****/
|
|
|
|
|
HTM_TR_End ();
|
|
|
|
|
|
|
|
|
|
/***** Free anchor string *****/
|
2023-04-06 19:59:33 +02:00
|
|
|
|
Frm_FreeAnchorStr (&Anchor);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
|
|
|
|
|
/***** Destroy test question *****/
|
2021-10-24 21:35:42 +02:00
|
|
|
|
Qst_QstDestructor (&Question);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
}
|
2020-03-07 00:14:35 +01:00
|
|
|
|
|
|
|
|
|
/***** End table *****/
|
|
|
|
|
HTM_TABLE_End ();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Ico_PutContextualIconToAdd (ActAddOneGamQst,NULL,Gam_PutPars,Games);
|
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
|
|
|
|
|
2021-03-02 00:54:26 +01:00
|
|
|
|
Frm_BeginForm (ActAddOneGamQst);
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutPars (Games);
|
2021-05-20 18:44:13 +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 ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-27 14:20:21 +02:00
|
|
|
|
void Gam_AddQstsToGame (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-27 00:06:58 +02:00
|
|
|
|
extern const char *Txt_A_question_has_been_added;
|
|
|
|
|
extern const char *Txt_X_questions_have_been_added;
|
2020-04-08 03:06:45 +02:00
|
|
|
|
struct Gam_Games Games;
|
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;
|
2020-04-27 00:06:58 +02:00
|
|
|
|
unsigned NumQstsAdded;
|
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 *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
2019-09-29 17:33:39 +02:00
|
|
|
|
/***** Get parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
if ((Games.Game.GamCod = Gam_GetPars (&Games)) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongGameExit ();
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games.Game);
|
2017-07-18 20:34:32 +02:00
|
|
|
|
|
2019-09-26 21:27:36 +02:00
|
|
|
|
/***** Check if game has matches *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
if (!Gam_CheckIfEditable (&Games.Game))
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NoPermissionExit ();
|
2017-07-18 20:34:32 +02:00
|
|
|
|
|
2020-04-27 00:06:58 +02:00
|
|
|
|
/***** Get selected questions *****/
|
|
|
|
|
/* Allocate space for selected question codes */
|
|
|
|
|
Gam_AllocateListSelectedQuestions (&Games);
|
2017-07-18 20:34:32 +02:00
|
|
|
|
|
2020-04-27 00:06:58 +02:00
|
|
|
|
/* Get question codes */
|
|
|
|
|
Par_GetParMultiToText ("QstCods",Games.ListQuestions,
|
|
|
|
|
Gam_MAX_BYTES_LIST_SELECTED_QUESTIONS);
|
|
|
|
|
|
|
|
|
|
/* Check number of questions */
|
|
|
|
|
NumQstsAdded = 0;
|
2021-10-26 17:33:20 +02:00
|
|
|
|
if (Qst_CountNumQuestionsInList (Games.ListQuestions)) // If questions selected...
|
2020-04-27 00:06:58 +02:00
|
|
|
|
{
|
|
|
|
|
/***** Insert questions in database *****/
|
|
|
|
|
Ptr = Games.ListQuestions;
|
|
|
|
|
while (*Ptr)
|
2019-09-26 21:27:36 +02:00
|
|
|
|
{
|
2020-04-27 00:06:58 +02:00
|
|
|
|
/* Get next code */
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Par_GetNextStrUntilSeparParMult (&Ptr,LongStr,Cns_MAX_DECIMAL_DIGITS_LONG);
|
2020-04-27 00:06:58 +02:00
|
|
|
|
if (sscanf (LongStr,"%ld",&QstCod) != 1)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongQuestionExit ();
|
2019-10-03 09:22:09 +02:00
|
|
|
|
|
2020-04-27 00:06:58 +02:00
|
|
|
|
/* Check if question is already present in game */
|
2022-10-01 13:19:05 +02:00
|
|
|
|
if (Gam_DB_GetQstIndFromQstCod (Games.Game.GamCod,QstCod) == 0) // This question is not yet in this game
|
2020-04-27 00:06:58 +02:00
|
|
|
|
{
|
2019-10-03 09:22:09 +02:00
|
|
|
|
/* Get current maximum index */
|
2022-10-01 13:19:05 +02:00
|
|
|
|
MaxQstInd = Gam_DB_GetMaxQuestionIndexInGame (Games.Game.GamCod); // 0 is no questions in game
|
2019-10-03 09:22:09 +02:00
|
|
|
|
|
|
|
|
|
/* Insert question in the table of questions */
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_DB_InsertQstInGame (Games.Game.GamCod,MaxQstInd + 1,QstCod);
|
2020-04-27 00:06:58 +02:00
|
|
|
|
|
|
|
|
|
NumQstsAdded++;
|
2019-10-03 09:22:09 +02:00
|
|
|
|
}
|
2019-09-26 21:27:36 +02:00
|
|
|
|
}
|
2017-09-01 00:52:19 +02:00
|
|
|
|
}
|
2020-04-27 00:06:58 +02:00
|
|
|
|
|
|
|
|
|
/***** Show warning in no questions added *****/
|
|
|
|
|
if (NumQstsAdded == 0)
|
|
|
|
|
Ale_ShowAlert (Ale_WARNING,Txt_No_questions_have_been_added);
|
|
|
|
|
else if (NumQstsAdded == 1)
|
|
|
|
|
Ale_ShowAlert (Ale_SUCCESS,Txt_A_question_has_been_added);
|
2019-09-30 12:54:10 +02:00
|
|
|
|
else
|
2020-04-27 00:06:58 +02:00
|
|
|
|
Ale_ShowAlert (Ale_SUCCESS,Txt_X_questions_have_been_added,NumQstsAdded);
|
|
|
|
|
|
|
|
|
|
/***** Free space for selected question codes *****/
|
|
|
|
|
Gam_FreeListsSelectedQuestions (&Games);
|
2017-09-01 00:52:19 +02:00
|
|
|
|
|
2017-09-07 18:38:18 +02:00
|
|
|
|
/***** Show current game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ShowOnlyOneGame (&Games,
|
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
|
|
|
|
{
|
2021-02-15 16:25:55 +01:00
|
|
|
|
if ((Games->ListQuestions = malloc (Gam_MAX_BYTES_LIST_SELECTED_QUESTIONS + 1)) == NULL)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************** Request the removal of a question ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-17 12:51:11 +01:00
|
|
|
|
void Gam_ReqRemQstFromGame (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;
|
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 *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
2019-09-29 17:33:39 +02:00
|
|
|
|
/***** Get parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
if ((Games.Game.GamCod = Gam_GetPars (&Games)) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongGameExit ();
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games.Game);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2019-09-26 21:27:36 +02:00
|
|
|
|
/***** Check if game has matches *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
if (!Gam_CheckIfEditable (&Games.Game))
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NoPermissionExit ();
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2020-04-27 00:06:58 +02:00
|
|
|
|
/***** Get question index *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
QstInd = Gam_GetParQstInd ();
|
2020-04-27 00:06:58 +02:00
|
|
|
|
|
|
|
|
|
/***** Show question and button to remove question *****/
|
|
|
|
|
Games.QstInd = QstInd;
|
|
|
|
|
Ale_ShowAlertAndButton (ActRemGamQst,NULL,NULL,
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutParsOneQst,&Games,
|
2020-04-27 00:06:58 +02:00
|
|
|
|
Btn_REMOVE_BUTTON,Txt_Remove_question,
|
|
|
|
|
Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_question_X,
|
|
|
|
|
QstInd);
|
|
|
|
|
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/***** Show current game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ShowOnlyOneGame (&Games,
|
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 ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-27 19:37:49 +02:00
|
|
|
|
void Gam_RemoveQstFromGame (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;
|
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 *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
2019-09-29 17:33:39 +02:00
|
|
|
|
/***** Get parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
if ((Games.Game.GamCod = Gam_GetPars (&Games)) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongGameExit ();
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games.Game);
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2019-09-26 21:27:36 +02:00
|
|
|
|
/***** Check if game has matches *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
if (!Gam_CheckIfEditable (&Games.Game))
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NoPermissionExit ();
|
2017-07-09 20:31:40 +02:00
|
|
|
|
|
2020-04-27 00:06:58 +02:00
|
|
|
|
/***** Get question index *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
QstInd = Gam_GetParQstInd ();
|
2020-04-27 00:06:58 +02:00
|
|
|
|
|
2021-10-30 13:28:48 +02:00
|
|
|
|
/***** Remove the question from all tables *****/
|
2020-04-27 00:06:58 +02:00
|
|
|
|
/* Remove answers from this test question */
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Mch_DB_RemUsrAnswersOfAQuestion (Games.Game.GamCod,QstInd);
|
2020-04-27 00:06:58 +02:00
|
|
|
|
|
|
|
|
|
/* Remove the question itself */
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_DB_RemoveQstFromGame (Games.Game.GamCod,QstInd);
|
2021-09-18 19:33:01 +02:00
|
|
|
|
|
|
|
|
|
/* Change indexes of questions greater than this */
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Mch_DB_UpdateIndexesOfQstsGreaterThan (Games.Game.GamCod,QstInd);
|
|
|
|
|
Gam_DB_UpdateIndexesOfQstsGreaterThan (Games.Game.GamCod,QstInd);
|
2020-04-27 00:06:58 +02:00
|
|
|
|
|
|
|
|
|
/***** Write message *****/
|
|
|
|
|
Ale_ShowAlert (Ale_SUCCESS,Txt_Question_removed);
|
|
|
|
|
|
2017-07-09 20:31:40 +02:00
|
|
|
|
/***** Show current game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ShowOnlyOneGame (&Games,
|
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)
|
|
|
|
|
{
|
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;
|
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 *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
2019-09-29 17:33:39 +02:00
|
|
|
|
/***** Get parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
if ((Games.Game.GamCod = Gam_GetPars (&Games)) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongGameExit ();
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games.Game);
|
2017-09-11 19:06:46 +02:00
|
|
|
|
|
2019-09-26 21:27:36 +02:00
|
|
|
|
/***** Check if game has matches *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
if (!Gam_CheckIfEditable (&Games.Game))
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NoPermissionExit ();
|
2017-09-11 19:06:46 +02:00
|
|
|
|
|
2020-04-27 00:06:58 +02:00
|
|
|
|
/***** Get question index *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
QstIndBottom = Gam_GetParQstInd ();
|
2019-09-26 21:27:36 +02:00
|
|
|
|
|
2020-04-27 00:06:58 +02:00
|
|
|
|
/***** Move up question *****/
|
2021-04-29 19:52:35 +02:00
|
|
|
|
if (QstIndBottom > 1) // 2, 3, 4...
|
2020-04-27 00:06:58 +02:00
|
|
|
|
{
|
|
|
|
|
/* Indexes of questions to be exchanged */
|
2022-10-01 13:19:05 +02:00
|
|
|
|
QstIndTop = Gam_DB_GetPrevQuestionIndexInGame (Games.Game.GamCod,QstIndBottom);
|
2021-04-29 19:52:35 +02:00
|
|
|
|
if (QstIndTop == 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongQuestionIndexExit ();
|
2017-09-11 19:06:46 +02:00
|
|
|
|
|
2020-04-27 00:06:58 +02:00
|
|
|
|
/* Exchange questions */
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ExchangeQuestions (Games.Game.GamCod,QstIndTop,QstIndBottom);
|
2017-09-11 19:06:46 +02:00
|
|
|
|
}
|
2019-09-30 12:54:10 +02:00
|
|
|
|
else
|
2020-04-27 00:06:58 +02:00
|
|
|
|
Ale_ShowAlert (Ale_WARNING,Txt_Movement_not_allowed);
|
2017-09-11 19:06:46 +02:00
|
|
|
|
|
|
|
|
|
/***** Show current game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ShowOnlyOneGame (&Games,
|
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)
|
|
|
|
|
{
|
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;
|
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 *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
2019-09-29 17:33:39 +02:00
|
|
|
|
/***** Get parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
if ((Games.Game.GamCod = Gam_GetPars (&Games)) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongGameExit ();
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games.Game);
|
2017-09-11 19:06:46 +02:00
|
|
|
|
|
2019-09-26 21:27:36 +02:00
|
|
|
|
/***** Check if game has matches *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
if (!Gam_CheckIfEditable (&Games.Game))
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NoPermissionExit ();
|
2017-09-11 19:06:46 +02:00
|
|
|
|
|
2020-04-27 00:06:58 +02:00
|
|
|
|
/***** Get question index *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
QstIndTop = Gam_GetParQstInd ();
|
2017-09-11 19:06:46 +02:00
|
|
|
|
|
2020-04-27 00:06:58 +02:00
|
|
|
|
/***** Get maximum question index *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
MaxQstInd = Gam_DB_GetMaxQuestionIndexInGame (Games.Game.GamCod); // 0 is no questions in game
|
2019-09-26 21:27:36 +02:00
|
|
|
|
|
2020-04-27 00:06:58 +02:00
|
|
|
|
/***** Move down question *****/
|
2020-04-28 12:34:56 +02:00
|
|
|
|
if (QstIndTop < MaxQstInd)
|
2020-04-27 00:06:58 +02:00
|
|
|
|
{
|
2020-04-28 12:34:56 +02:00
|
|
|
|
/* Indexes of questions to be exchanged */
|
2022-10-01 13:19:05 +02:00
|
|
|
|
QstIndBottom = Gam_DB_GetNextQuestionIndexInGame (Games.Game.GamCod,QstIndTop);
|
2021-04-26 19:34:29 +02:00
|
|
|
|
if (QstIndBottom == Gam_AFTER_LAST_QUESTION)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongQuestionIndexExit ();
|
2019-09-26 21:27:36 +02:00
|
|
|
|
|
2020-04-28 12:34:56 +02:00
|
|
|
|
/* Exchange questions */
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ExchangeQuestions (Games.Game.GamCod,QstIndTop,QstIndBottom);
|
2019-05-30 12:57:31 +02:00
|
|
|
|
}
|
2019-09-30 12:54:10 +02:00
|
|
|
|
else
|
2020-04-28 12:34:56 +02:00
|
|
|
|
Ale_ShowAlert (Ale_WARNING,Txt_Movement_not_allowed);
|
2017-09-11 19:06:46 +02:00
|
|
|
|
|
|
|
|
|
/***** Show current game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ShowOnlyOneGame (&Games,
|
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 *****/
|
2021-09-20 13:40:17 +02:00
|
|
|
|
Gam_DB_LockTable ();
|
2017-09-11 19:06:46 +02:00
|
|
|
|
|
|
|
|
|
/***** Get question code of the questions to be moved *****/
|
2021-09-18 19:33:01 +02:00
|
|
|
|
QstCodTop = Gam_DB_GetQstCodFromQstInd (GamCod,QstIndTop);
|
|
|
|
|
QstCodBottom = Gam_DB_GetQstCodFromQstInd (GamCod,QstIndBottom);
|
2017-09-11 19:06:46 +02:00
|
|
|
|
|
|
|
|
|
/***** Exchange indexes of questions *****/
|
|
|
|
|
/*
|
|
|
|
|
Example:
|
2019-05-30 12:57:31 +02:00
|
|
|
|
QstIndTop = 1; QstCodTop = 218
|
|
|
|
|
QstIndBottom = 2; QstCodBottom = 220
|
2020-04-27 00:25:02 +02:00
|
|
|
|
Step 1 Step 2 Step 3
|
|
|
|
|
+--------+--------+ +--------+--------+ +--------+--------+ +--------+--------+
|
|
|
|
|
| QstInd | QstCod | | QstInd | QstCod | | QstInd | QstCod | | QstInd | QstCod |
|
|
|
|
|
+--------+--------+ +--------+--------+ +--------+--------+ +--------+--------+
|
|
|
|
|
| 1 | 218 |>| -2 | 218 |>| -2 | 218 |>| 2 | 218 |
|
|
|
|
|
| 2 | 220 | | 2 | 220 | | 1 | 220 | | 1 | 220 |
|
|
|
|
|
| 3 | 232 | | 3 | 232 | | 3 | 232 | | 3 | 232 |
|
|
|
|
|
+--------+--------+ +--------+--------+ +--------+--------+ +--------+--------+
|
2020-04-27 00:06:58 +02:00
|
|
|
|
*/
|
|
|
|
|
/* Step 1: change temporarily top index to minus bottom index
|
|
|
|
|
in order to not repeat unique index (GamCod,QstInd) */
|
2021-09-20 13:40:17 +02:00
|
|
|
|
Gam_DB_UpdateQstIndex (-((long) QstIndBottom),GamCod,QstCodTop );
|
2020-04-27 00:06:58 +02:00
|
|
|
|
|
|
|
|
|
/* Step 2: change bottom index to old top index */
|
2021-09-20 13:40:17 +02:00
|
|
|
|
Gam_DB_UpdateQstIndex ( (long) QstIndTop ,GamCod,QstCodBottom);
|
2018-11-03 12:16:40 +01:00
|
|
|
|
|
2020-04-27 00:06:58 +02:00
|
|
|
|
/* Step 3: change top index to old bottom index */
|
2021-09-20 13:40:17 +02:00
|
|
|
|
Gam_DB_UpdateQstIndex ( (long) QstIndBottom ,GamCod,QstCodTop );
|
2017-09-11 19:06:46 +02:00
|
|
|
|
|
|
|
|
|
/***** Unlock table *****/
|
2022-07-15 18:15:40 +02:00
|
|
|
|
DB_UnlockTables ();
|
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 *****/
|
2021-11-12 01:12:15 +01:00
|
|
|
|
return Game->NumMchs == 0; // Games with matches should not be edited
|
2019-09-26 21:40:25 +02:00
|
|
|
|
else
|
2021-11-12 01:12:15 +01: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 **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2022-10-01 13:19:05 +02:00
|
|
|
|
void Gam_PutButtonNewMatch (struct Gam_Games *Games)
|
2019-09-29 17:33:39 +02:00
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_New_match;
|
|
|
|
|
|
2021-06-29 15:25:42 +02:00
|
|
|
|
Frm_BeginFormAnchor (ActReqNewMch,Mch_NEW_MATCH_SECTION_ID);
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gam_PutPars (Games);
|
2021-05-20 18:44:13 +02:00
|
|
|
|
|
|
|
|
|
Btn_PutConfirmButton (Txt_New_match);
|
|
|
|
|
|
2019-09-29 17:33:39 +02:00
|
|
|
|
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
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-17 12:51:11 +01:00
|
|
|
|
void Gam_ReqNewMatch (void)
|
2019-05-28 15:06:53 +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);
|
2019-08-02 00:44:30 +02:00
|
|
|
|
|
2020-04-23 23:09:28 +02:00
|
|
|
|
/***** Reset game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ResetGame (&Games.Game);
|
2020-04-23 23:09:28 +02:00
|
|
|
|
|
2019-09-14 12:59:34 +02:00
|
|
|
|
/***** Get parameters *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
if ((Games.Game.GamCod = Gam_GetPars (&Games)) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongGameExit ();
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Gam_GetGameDataByCod (&Games.Game);
|
2017-09-13 09:47:45 +02:00
|
|
|
|
|
|
|
|
|
/***** Show game *****/
|
2022-10-01 13:19:05 +02:00
|
|
|
|
Gam_ShowOnlyOneGame (&Games,
|
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
|
|
|
|
}
|
|
|
|
|
|
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 *****/
|
2021-09-20 13:40:17 +02:00
|
|
|
|
NumTags = Gam_DB_GetTstTagsPresentInAGame (&mysql_res,GamCod);
|
2021-10-24 21:35:42 +02:00
|
|
|
|
Tag_ShowTagList (NumTags,mysql_res);
|
2019-09-25 21:58:12 +02:00
|
|
|
|
|
|
|
|
|
/***** 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)
|
|
|
|
|
{
|
2021-05-20 12:16:49 +02:00
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
unsigned NumQsts;
|
|
|
|
|
unsigned NumQst;
|
2019-10-21 13:36:28 +02:00
|
|
|
|
unsigned NumAnswers;
|
|
|
|
|
|
2021-05-20 12:16:49 +02:00
|
|
|
|
/***** Get maximum score of a game from database *****/
|
2021-09-20 13:40:17 +02:00
|
|
|
|
NumQsts = Gam_DB_GetNumAnswersOfQstsInGame (&mysql_res,GamCod);
|
2021-05-20 12:16:49 +02:00
|
|
|
|
for (NumQst = 0, *MinScore = *MaxScore = 0.0;
|
|
|
|
|
NumQst < NumQsts;
|
|
|
|
|
NumQst++)
|
|
|
|
|
{
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
2021-04-04 20:12:31 +02:00
|
|
|
|
|
2021-05-20 12:16:49 +02:00
|
|
|
|
/* Get number of answers (row[0]) for this question */
|
|
|
|
|
if (sscanf (row[0],"%u",&NumAnswers) != 1)
|
|
|
|
|
NumAnswers = 0;
|
|
|
|
|
|
2021-09-20 13:40:17 +02:00
|
|
|
|
/* Check number of answers */
|
2021-05-20 12:16:49 +02:00
|
|
|
|
if (NumAnswers < 2)
|
2021-09-25 22:49:05 +02:00
|
|
|
|
Err_WrongAnswerExit ();
|
2021-09-20 13:40:17 +02:00
|
|
|
|
|
|
|
|
|
/* Accumulate minimum and maximum score */
|
2021-05-20 12:16:49 +02:00
|
|
|
|
*MinScore += -1.0 / (double) (NumAnswers - 1);
|
|
|
|
|
*MaxScore += 1.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Free structure that stores the query result *****/
|
|
|
|
|
DB_FreeMySQLResult (&mysql_res);
|
2019-10-21 13:36:28 +02:00
|
|
|
|
}
|
2022-01-03 02:47:16 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************************** Show stats about games **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Gam_GetAndShowGamesStats (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Hlp_ANALYTICS_Figures_games;
|
|
|
|
|
extern const char *Txt_FIGURE_TYPES[Fig_NUM_FIGURES];
|
|
|
|
|
extern const char *Txt_Number_of_BR_games;
|
|
|
|
|
extern const char *Txt_Number_of_BR_courses_with_BR_games;
|
|
|
|
|
extern const char *Txt_Average_number_BR_of_games_BR_per_course;
|
|
|
|
|
unsigned NumGames;
|
|
|
|
|
unsigned NumCoursesWithGames = 0;
|
|
|
|
|
double NumGamesPerCourse = 0.0;
|
|
|
|
|
|
|
|
|
|
/***** Get the number of games from this location *****/
|
|
|
|
|
if ((NumGames = Gam_DB_GetNumGames (Gbl.Scope.Current)))
|
|
|
|
|
if ((NumCoursesWithGames = Gam_DB_GetNumCoursesWithGames (Gbl.Scope.Current)) != 0)
|
|
|
|
|
NumGamesPerCourse = (double) NumGames / (double) NumCoursesWithGames;
|
|
|
|
|
|
|
|
|
|
/***** Begin box and table *****/
|
|
|
|
|
Box_BoxTableBegin (NULL,Txt_FIGURE_TYPES[Fig_GAMES],
|
|
|
|
|
NULL,NULL,
|
|
|
|
|
Hlp_ANALYTICS_Figures_games,Box_NOT_CLOSABLE,2);
|
|
|
|
|
|
|
|
|
|
/***** Write table heading *****/
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
HTM_TH (Txt_Number_of_BR_games ,HTM_HEAD_RIGHT);
|
|
|
|
|
HTM_TH (Txt_Number_of_BR_courses_with_BR_games ,HTM_HEAD_RIGHT);
|
|
|
|
|
HTM_TH (Txt_Average_number_BR_of_games_BR_per_course,HTM_HEAD_RIGHT);
|
|
|
|
|
HTM_TR_End ();
|
|
|
|
|
|
|
|
|
|
/***** Write number of games *****/
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
|
2022-04-05 01:00:24 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ());
|
2022-01-03 02:47:16 +01:00
|
|
|
|
HTM_Unsigned (NumGames);
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
2022-04-05 01:00:24 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ());
|
2022-01-03 02:47:16 +01:00
|
|
|
|
HTM_Unsigned (NumCoursesWithGames);
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
2022-04-05 01:00:24 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ());
|
2022-01-03 02:47:16 +01:00
|
|
|
|
HTM_Double2Decimals (NumGamesPerCourse);
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
HTM_TR_End ();
|
|
|
|
|
|
|
|
|
|
/***** End table and box *****/
|
|
|
|
|
Box_BoxTableEnd ();
|
|
|
|
|
}
|