Version 22.49.5: Oct 18, 2022 Code refactoring related to boxes.

This commit is contained in:
acanas 2022-10-18 16:23:54 +02:00
parent 4ab45f2c35
commit fea76913bc
7 changed files with 49 additions and 45 deletions

View File

@ -34,15 +34,23 @@
#include "swad_box.h"
#include "swad_error.h"
#include "swad_form.h"
#include "swad_global.h"
#include "swad_help.h"
#include "swad_HTML.h"
#include "swad_icon.h"
#include "swad_theme.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/************************* Private global variables **************************/
/*****************************************************************************/
extern struct Globals Gbl;
static struct
{
int Nested; // Index of top open box
char *Ids[Box_MAX_NESTED]; // 0 <= box index < Box_MAX_NESTED
} Box =
{
.Nested = -1, // -1 means no box open
};
/*****************************************************************************/
/***************************** Private prototypes ****************************/
@ -122,28 +130,28 @@ static void Box_BoxInternalBegin (const char *Width,const char *Title,
extern const char *Txt_Close;
/***** Check level of nesting *****/
if (Gbl.Box.Nested >= Box_MAX_NESTED - 1) // Can not nest a new box
if (Box.Nested >= Box_MAX_NESTED - 1) // Can not nest a new box
Err_ShowErrorAndExit ("Box nesting limit reached.");
/***** Increase level of nesting *****/
Gbl.Box.Nested++;
Box.Nested++;
/***** Create unique identifier for this box *****/
if (Closable == Box_CLOSABLE)
{
if ((Gbl.Box.Ids[Gbl.Box.Nested] = malloc (Frm_MAX_BYTES_ID + 1)) == NULL)
if ((Box.Ids[Box.Nested] = malloc (Frm_MAX_BYTES_ID + 1)) == NULL)
Err_NotEnoughMemoryExit ();
}
else
Gbl.Box.Ids[Gbl.Box.Nested] = NULL;
Box.Ids[Box.Nested] = NULL;
/***** Begin box container *****/
if (Closable == Box_CLOSABLE)
{
/* Create unique id for alert */
Frm_SetUniqueId (Gbl.Box.Ids[Gbl.Box.Nested]);
Frm_SetUniqueId (Box.Ids[Box.Nested]);
HTM_DIV_Begin ("class=\"FRAME_CONT\" id=\"%s\"",Gbl.Box.Ids[Gbl.Box.Nested]);
HTM_DIV_Begin ("class=\"FRAME_CONT\" id=\"%s\"",Box.Ids[Box.Nested]);
}
else
HTM_DIV_Begin ("class=\"FRAME_CONT\"");
@ -184,7 +192,7 @@ static void Box_BoxInternalBegin (const char *Width,const char *Title,
if (Closable == Box_CLOSABLE) // Icon to close the box
{
HTM_A_Begin ("href=\"\" onclick=\"toggleDisplay('%s');return false;\"",
Gbl.Box.Ids[Gbl.Box.Nested]);
Box.Ids[Box.Nested]);
Ico_PutDivIcon ("CONTEXT_OPT HLP_HIGHLIGHT",
"times.svg",Ico_BLACK,Txt_Close);
HTM_A_End ();
@ -200,8 +208,8 @@ static void Box_BoxInternalBegin (const char *Width,const char *Title,
if (Title)
{
HTM_DIV_Begin ("class=\"FRAME_TITLE %s FRAME_TITLE_%s\"",
Gbl.Box.Nested ? "FRAME_TITLE_SMALL" :
"FRAME_TITLE_BIG",
Box.Nested ? "FRAME_TITLE_SMALL" :
"FRAME_TITLE_BIG",
The_GetSuffix ());
HTM_Txt (Title);
HTM_DIV_End ();
@ -229,17 +237,17 @@ void Box_BoxWithButtonEnd (Btn_Button_t Button,const char *TxtButton)
void Box_BoxEnd (void)
{
/***** Check level of nesting *****/
if (Gbl.Box.Nested < 0)
if (Box.Nested < 0)
Err_ShowErrorAndExit ("Trying to end a box not open.");
/***** Free memory allocated for box id string *****/
if (Gbl.Box.Ids[Gbl.Box.Nested])
free (Gbl.Box.Ids[Gbl.Box.Nested]);
if (Box.Ids[Box.Nested])
free (Box.Ids[Box.Nested]);
/***** End box and box container *****/
HTM_DIV_End ();
HTM_DIV_End ();
/***** Decrease level of nesting *****/
Gbl.Box.Nested--;
Box.Nested--;
}

View File

@ -606,10 +606,11 @@ TODO: Fix bug: error al enviar un mensaje a dos recipientes, error on duplicate
TODO: Attach pdf files in multimedia.
*/
#define Log_PLATFORM_VERSION "SWAD 22.49.4 (2022-10-18)"
#define Log_PLATFORM_VERSION "SWAD 22.49.5 (2022-10-18)"
#define CSS_FILE "swad22.49.4.css"
#define JS_FILE "swad22.49.js"
/*
Version 22.49.5: Oct 18, 2022 Code refactoring related to boxes. (333190 lines)
Version 22.49.4: Oct 18, 2022 Lighter background colors in tables.
Changes in responsive layout. (333187 lines)
Version 22.49.3: Oct 18, 2022 Code refactoring related to parameters. (333213 lines)

View File

@ -47,6 +47,12 @@
extern struct Globals Gbl;
/*****************************************************************************/
/************************* Private global variables **************************/
/*****************************************************************************/
static MYSQL DB_mysql;
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
@ -3890,7 +3896,7 @@ static void DB_CreateTable (const char *Query)
HTM_Txt (Query);
HTM_LI_End ();
if (mysql_query (&Gbl.mysql,Query))
if (mysql_query (&DB_mysql,Query))
DB_ExitOnMySQLError ("can not create table");
}
@ -3900,10 +3906,10 @@ static void DB_CreateTable (const char *Query)
void DB_OpenDBConnection (void)
{
if (mysql_init (&Gbl.mysql) == NULL)
if (mysql_init (&DB_mysql) == NULL)
Err_ShowErrorAndExit ("Can not init MySQL.");
if (mysql_real_connect (&Gbl.mysql,Cfg_DATABASE_HOST,
if (mysql_real_connect (&DB_mysql,Cfg_DATABASE_HOST,
Cfg_DATABASE_USER,Gbl.Config.DatabasePassword,
Cfg_DATABASE_DBNAME,0,NULL,0) == NULL)
DB_ExitOnMySQLError ("can not connect to database");
@ -3919,7 +3925,7 @@ void DB_CloseDBConnection (void)
{
if (Gbl.DB.DatabaseIsOpen)
{
mysql_close (&Gbl.mysql); // Close the connection to the database
mysql_close (&DB_mysql); // Close the connection to the database
Gbl.DB.DatabaseIsOpen = false;
}
}
@ -4165,13 +4171,13 @@ static unsigned long DB_QuerySELECTusingQueryStr (char *Query,
Err_ShowErrorAndExit ("Wrong query string.");
/***** Query database and free query string pointer *****/
Result = mysql_query (&Gbl.mysql,Query); // Returns 0 on success
Result = mysql_query (&DB_mysql,Query); // Returns 0 on success
free (Query);
if (Result)
DB_ExitOnMySQLError (MsgError);
/***** Store query result *****/
if ((*mysql_res = mysql_store_result (&Gbl.mysql)) == NULL)
if ((*mysql_res = mysql_store_result (&DB_mysql)) == NULL)
DB_ExitOnMySQLError (MsgError);
/***** Return number of rows of result *****/
@ -4282,7 +4288,7 @@ void DB_QueryINSERT (const char *MsgError,const char *fmt,...)
Err_NotEnoughMemoryExit ();
/***** Query database and free query string pointer *****/
Result = mysql_query (&Gbl.mysql,Query); // Returns 0 on success
Result = mysql_query (&DB_mysql,Query); // Returns 0 on success
free (Query);
if (Result)
DB_ExitOnMySQLError (MsgError);
@ -4306,13 +4312,13 @@ long DB_QueryINSERTandReturnCode (const char *MsgError,const char *fmt,...)
Err_NotEnoughMemoryExit ();
/***** Query database and free query string pointer *****/
Result = mysql_query (&Gbl.mysql,Query); // Returns 0 on success
Result = mysql_query (&DB_mysql,Query); // Returns 0 on success
free (Query);
if (Result)
DB_ExitOnMySQLError (MsgError);
/***** Return the code of the inserted item *****/
return (long) mysql_insert_id (&Gbl.mysql);
return (long) mysql_insert_id (&DB_mysql);
}
/*****************************************************************************/
@ -4333,7 +4339,7 @@ void DB_QueryREPLACE (const char *MsgError,const char *fmt,...)
Err_NotEnoughMemoryExit ();
/***** Query database and free query string pointer *****/
Result = mysql_query (&Gbl.mysql,Query); // Returns 0 on success
Result = mysql_query (&DB_mysql,Query); // Returns 0 on success
free (Query);
if (Result)
DB_ExitOnMySQLError (MsgError);
@ -4357,7 +4363,7 @@ void DB_QueryUPDATE (const char *MsgError,const char *fmt,...)
Err_NotEnoughMemoryExit ();
/***** Query database and free query string pointer *****/
Result = mysql_query (&Gbl.mysql,Query); // Returns 0 on success
Result = mysql_query (&DB_mysql,Query); // Returns 0 on success
free (Query);
if (Result)
DB_ExitOnMySQLError (MsgError);
@ -4381,7 +4387,7 @@ void DB_QueryDELETE (const char *MsgError,const char *fmt,...)
Err_NotEnoughMemoryExit ();
/***** Query database and free query string pointer *****/
Result = mysql_query (&Gbl.mysql,Query); // Returns 0 on success
Result = mysql_query (&DB_mysql,Query); // Returns 0 on success
free (Query);
if (Result)
DB_ExitOnMySQLError (MsgError);
@ -4405,7 +4411,7 @@ void DB_CreateTmpTable (const char *fmt,...)
Err_NotEnoughMemoryExit ();
/***** Query database and free query string pointer *****/
Result = mysql_query (&Gbl.mysql,Query); // Returns 0 on success
Result = mysql_query (&DB_mysql,Query); // Returns 0 on success
free (Query);
if (Result)
DB_ExitOnMySQLError ("can not create temporary table");
@ -4435,7 +4441,7 @@ void DB_Query (const char *MsgError,const char *fmt,...)
Err_NotEnoughMemoryExit ();
/***** Query database and free query string pointer *****/
Result = mysql_query (&Gbl.mysql,Query); // Returns 0 on success
Result = mysql_query (&DB_mysql,Query); // Returns 0 on success
free (Query);
if (Result)
DB_ExitOnMySQLError (MsgError);
@ -4464,7 +4470,7 @@ void DB_ExitOnMySQLError (const char *Message)
char BigErrorMsg[64 * 1024];
snprintf (BigErrorMsg,sizeof (BigErrorMsg),"Database error: %s (%s).",
Message,mysql_error (&Gbl.mysql));
Message,mysql_error (&DB_mysql));
Err_ShowErrorAndExit (BigErrorMsg);
}

View File

@ -554,10 +554,7 @@ void Err_ShowErrorAndExit (const char *Txt)
{
/***** Unlock tables if locked *****/
if (Gbl.DB.LockedTables)
{
Gbl.DB.LockedTables = false;
mysql_query (&Gbl.mysql,"UNLOCK TABLES");
}
DB_UnlockTables ();
if (!Gbl.WebService.IsWebService)
{

View File

@ -106,8 +106,6 @@ void Gbl_InitializeGlobals (void)
Gbl.F.XML = NULL;
Gbl.F.Rep = NULL; // Report
Gbl.Box.Nested = -1; // -1 means no box open
Gbl.Alerts.Num = 0; // No pending alerts to be shown
Gbl.DB.DatabaseIsOpen = false;

View File

@ -73,13 +73,7 @@ struct Globals
char SMTPPassword[Cfg_MAX_BYTES_SMTP_PASSWORD + 1];
} Config;
struct Files F;
MYSQL mysql;
pid_t PID; // PID of current process
struct
{
int Nested; // Index of top open box
char *Ids[Box_MAX_NESTED]; // 0 <= box index < Box_MAX_NESTED
} Box;
struct
{
size_t Num; // Number of alert

View File

@ -14786,7 +14786,7 @@ const char *Txt_Force_students_to_read_this_information =
#elif L==9 // pt
"For&ccedil;ar os estudantes a ler esta informa&ccedil;&atilde;o";
#elif L==10 // tr
"Force students to read this information"; // Çeviri lazim!
"&Ouml;&gbreve;rencileri bu bilgileri okumaya zorla";
#endif
const char *Txt_Forgotten_password =