mirror of
https://github.com/acanas/swad-core.git
synced 2024-06-16 21:45:43 +02:00
Version 22.49.5: Oct 18, 2022 Code refactoring related to boxes.
This commit is contained in:
parent
4ab45f2c35
commit
fea76913bc
40
swad_box.c
40
swad_box.c
|
@ -34,15 +34,23 @@
|
||||||
#include "swad_box.h"
|
#include "swad_box.h"
|
||||||
#include "swad_error.h"
|
#include "swad_error.h"
|
||||||
#include "swad_form.h"
|
#include "swad_form.h"
|
||||||
#include "swad_global.h"
|
|
||||||
#include "swad_help.h"
|
#include "swad_help.h"
|
||||||
#include "swad_HTML.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 ****************************/
|
/***************************** Private prototypes ****************************/
|
||||||
|
@ -122,28 +130,28 @@ static void Box_BoxInternalBegin (const char *Width,const char *Title,
|
||||||
extern const char *Txt_Close;
|
extern const char *Txt_Close;
|
||||||
|
|
||||||
/***** Check level of nesting *****/
|
/***** 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.");
|
Err_ShowErrorAndExit ("Box nesting limit reached.");
|
||||||
|
|
||||||
/***** Increase level of nesting *****/
|
/***** Increase level of nesting *****/
|
||||||
Gbl.Box.Nested++;
|
Box.Nested++;
|
||||||
|
|
||||||
/***** Create unique identifier for this box *****/
|
/***** Create unique identifier for this box *****/
|
||||||
if (Closable == Box_CLOSABLE)
|
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 ();
|
Err_NotEnoughMemoryExit ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Gbl.Box.Ids[Gbl.Box.Nested] = NULL;
|
Box.Ids[Box.Nested] = NULL;
|
||||||
|
|
||||||
/***** Begin box container *****/
|
/***** Begin box container *****/
|
||||||
if (Closable == Box_CLOSABLE)
|
if (Closable == Box_CLOSABLE)
|
||||||
{
|
{
|
||||||
/* Create unique id for alert */
|
/* 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
|
else
|
||||||
HTM_DIV_Begin ("class=\"FRAME_CONT\"");
|
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
|
if (Closable == Box_CLOSABLE) // Icon to close the box
|
||||||
{
|
{
|
||||||
HTM_A_Begin ("href=\"\" onclick=\"toggleDisplay('%s');return false;\"",
|
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",
|
Ico_PutDivIcon ("CONTEXT_OPT HLP_HIGHLIGHT",
|
||||||
"times.svg",Ico_BLACK,Txt_Close);
|
"times.svg",Ico_BLACK,Txt_Close);
|
||||||
HTM_A_End ();
|
HTM_A_End ();
|
||||||
|
@ -200,8 +208,8 @@ static void Box_BoxInternalBegin (const char *Width,const char *Title,
|
||||||
if (Title)
|
if (Title)
|
||||||
{
|
{
|
||||||
HTM_DIV_Begin ("class=\"FRAME_TITLE %s FRAME_TITLE_%s\"",
|
HTM_DIV_Begin ("class=\"FRAME_TITLE %s FRAME_TITLE_%s\"",
|
||||||
Gbl.Box.Nested ? "FRAME_TITLE_SMALL" :
|
Box.Nested ? "FRAME_TITLE_SMALL" :
|
||||||
"FRAME_TITLE_BIG",
|
"FRAME_TITLE_BIG",
|
||||||
The_GetSuffix ());
|
The_GetSuffix ());
|
||||||
HTM_Txt (Title);
|
HTM_Txt (Title);
|
||||||
HTM_DIV_End ();
|
HTM_DIV_End ();
|
||||||
|
@ -229,17 +237,17 @@ void Box_BoxWithButtonEnd (Btn_Button_t Button,const char *TxtButton)
|
||||||
void Box_BoxEnd (void)
|
void Box_BoxEnd (void)
|
||||||
{
|
{
|
||||||
/***** Check level of nesting *****/
|
/***** Check level of nesting *****/
|
||||||
if (Gbl.Box.Nested < 0)
|
if (Box.Nested < 0)
|
||||||
Err_ShowErrorAndExit ("Trying to end a box not open.");
|
Err_ShowErrorAndExit ("Trying to end a box not open.");
|
||||||
|
|
||||||
/***** Free memory allocated for box id string *****/
|
/***** Free memory allocated for box id string *****/
|
||||||
if (Gbl.Box.Ids[Gbl.Box.Nested])
|
if (Box.Ids[Box.Nested])
|
||||||
free (Gbl.Box.Ids[Gbl.Box.Nested]);
|
free (Box.Ids[Box.Nested]);
|
||||||
|
|
||||||
/***** End box and box container *****/
|
/***** End box and box container *****/
|
||||||
HTM_DIV_End ();
|
HTM_DIV_End ();
|
||||||
HTM_DIV_End ();
|
HTM_DIV_End ();
|
||||||
|
|
||||||
/***** Decrease level of nesting *****/
|
/***** Decrease level of nesting *****/
|
||||||
Gbl.Box.Nested--;
|
Box.Nested--;
|
||||||
}
|
}
|
||||||
|
|
|
@ -606,10 +606,11 @@ TODO: Fix bug: error al enviar un mensaje a dos recipientes, error on duplicate
|
||||||
|
|
||||||
TODO: Attach pdf files in multimedia.
|
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 CSS_FILE "swad22.49.4.css"
|
||||||
#define JS_FILE "swad22.49.js"
|
#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.
|
Version 22.49.4: Oct 18, 2022 Lighter background colors in tables.
|
||||||
Changes in responsive layout. (333187 lines)
|
Changes in responsive layout. (333187 lines)
|
||||||
Version 22.49.3: Oct 18, 2022 Code refactoring related to parameters. (333213 lines)
|
Version 22.49.3: Oct 18, 2022 Code refactoring related to parameters. (333213 lines)
|
||||||
|
|
|
@ -47,6 +47,12 @@
|
||||||
|
|
||||||
extern struct Globals Gbl;
|
extern struct Globals Gbl;
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************************* Private global variables **************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static MYSQL DB_mysql;
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/***************************** Private prototypes ****************************/
|
/***************************** Private prototypes ****************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -3890,7 +3896,7 @@ static void DB_CreateTable (const char *Query)
|
||||||
HTM_Txt (Query);
|
HTM_Txt (Query);
|
||||||
HTM_LI_End ();
|
HTM_LI_End ();
|
||||||
|
|
||||||
if (mysql_query (&Gbl.mysql,Query))
|
if (mysql_query (&DB_mysql,Query))
|
||||||
DB_ExitOnMySQLError ("can not create table");
|
DB_ExitOnMySQLError ("can not create table");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3900,10 +3906,10 @@ static void DB_CreateTable (const char *Query)
|
||||||
|
|
||||||
void DB_OpenDBConnection (void)
|
void DB_OpenDBConnection (void)
|
||||||
{
|
{
|
||||||
if (mysql_init (&Gbl.mysql) == NULL)
|
if (mysql_init (&DB_mysql) == NULL)
|
||||||
Err_ShowErrorAndExit ("Can not init MySQL.");
|
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_USER,Gbl.Config.DatabasePassword,
|
||||||
Cfg_DATABASE_DBNAME,0,NULL,0) == NULL)
|
Cfg_DATABASE_DBNAME,0,NULL,0) == NULL)
|
||||||
DB_ExitOnMySQLError ("can not connect to database");
|
DB_ExitOnMySQLError ("can not connect to database");
|
||||||
|
@ -3919,7 +3925,7 @@ void DB_CloseDBConnection (void)
|
||||||
{
|
{
|
||||||
if (Gbl.DB.DatabaseIsOpen)
|
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;
|
Gbl.DB.DatabaseIsOpen = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4165,13 +4171,13 @@ static unsigned long DB_QuerySELECTusingQueryStr (char *Query,
|
||||||
Err_ShowErrorAndExit ("Wrong query string.");
|
Err_ShowErrorAndExit ("Wrong query string.");
|
||||||
|
|
||||||
/***** Query database and free query string pointer *****/
|
/***** 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);
|
free (Query);
|
||||||
if (Result)
|
if (Result)
|
||||||
DB_ExitOnMySQLError (MsgError);
|
DB_ExitOnMySQLError (MsgError);
|
||||||
|
|
||||||
/***** Store query result *****/
|
/***** Store query result *****/
|
||||||
if ((*mysql_res = mysql_store_result (&Gbl.mysql)) == NULL)
|
if ((*mysql_res = mysql_store_result (&DB_mysql)) == NULL)
|
||||||
DB_ExitOnMySQLError (MsgError);
|
DB_ExitOnMySQLError (MsgError);
|
||||||
|
|
||||||
/***** Return number of rows of result *****/
|
/***** Return number of rows of result *****/
|
||||||
|
@ -4282,7 +4288,7 @@ void DB_QueryINSERT (const char *MsgError,const char *fmt,...)
|
||||||
Err_NotEnoughMemoryExit ();
|
Err_NotEnoughMemoryExit ();
|
||||||
|
|
||||||
/***** Query database and free query string pointer *****/
|
/***** 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);
|
free (Query);
|
||||||
if (Result)
|
if (Result)
|
||||||
DB_ExitOnMySQLError (MsgError);
|
DB_ExitOnMySQLError (MsgError);
|
||||||
|
@ -4306,13 +4312,13 @@ long DB_QueryINSERTandReturnCode (const char *MsgError,const char *fmt,...)
|
||||||
Err_NotEnoughMemoryExit ();
|
Err_NotEnoughMemoryExit ();
|
||||||
|
|
||||||
/***** Query database and free query string pointer *****/
|
/***** 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);
|
free (Query);
|
||||||
if (Result)
|
if (Result)
|
||||||
DB_ExitOnMySQLError (MsgError);
|
DB_ExitOnMySQLError (MsgError);
|
||||||
|
|
||||||
/***** Return the code of the inserted item *****/
|
/***** 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 ();
|
Err_NotEnoughMemoryExit ();
|
||||||
|
|
||||||
/***** Query database and free query string pointer *****/
|
/***** 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);
|
free (Query);
|
||||||
if (Result)
|
if (Result)
|
||||||
DB_ExitOnMySQLError (MsgError);
|
DB_ExitOnMySQLError (MsgError);
|
||||||
|
@ -4357,7 +4363,7 @@ void DB_QueryUPDATE (const char *MsgError,const char *fmt,...)
|
||||||
Err_NotEnoughMemoryExit ();
|
Err_NotEnoughMemoryExit ();
|
||||||
|
|
||||||
/***** Query database and free query string pointer *****/
|
/***** 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);
|
free (Query);
|
||||||
if (Result)
|
if (Result)
|
||||||
DB_ExitOnMySQLError (MsgError);
|
DB_ExitOnMySQLError (MsgError);
|
||||||
|
@ -4381,7 +4387,7 @@ void DB_QueryDELETE (const char *MsgError,const char *fmt,...)
|
||||||
Err_NotEnoughMemoryExit ();
|
Err_NotEnoughMemoryExit ();
|
||||||
|
|
||||||
/***** Query database and free query string pointer *****/
|
/***** 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);
|
free (Query);
|
||||||
if (Result)
|
if (Result)
|
||||||
DB_ExitOnMySQLError (MsgError);
|
DB_ExitOnMySQLError (MsgError);
|
||||||
|
@ -4405,7 +4411,7 @@ void DB_CreateTmpTable (const char *fmt,...)
|
||||||
Err_NotEnoughMemoryExit ();
|
Err_NotEnoughMemoryExit ();
|
||||||
|
|
||||||
/***** Query database and free query string pointer *****/
|
/***** 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);
|
free (Query);
|
||||||
if (Result)
|
if (Result)
|
||||||
DB_ExitOnMySQLError ("can not create temporary table");
|
DB_ExitOnMySQLError ("can not create temporary table");
|
||||||
|
@ -4435,7 +4441,7 @@ void DB_Query (const char *MsgError,const char *fmt,...)
|
||||||
Err_NotEnoughMemoryExit ();
|
Err_NotEnoughMemoryExit ();
|
||||||
|
|
||||||
/***** Query database and free query string pointer *****/
|
/***** 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);
|
free (Query);
|
||||||
if (Result)
|
if (Result)
|
||||||
DB_ExitOnMySQLError (MsgError);
|
DB_ExitOnMySQLError (MsgError);
|
||||||
|
@ -4464,7 +4470,7 @@ void DB_ExitOnMySQLError (const char *Message)
|
||||||
char BigErrorMsg[64 * 1024];
|
char BigErrorMsg[64 * 1024];
|
||||||
|
|
||||||
snprintf (BigErrorMsg,sizeof (BigErrorMsg),"Database error: %s (%s).",
|
snprintf (BigErrorMsg,sizeof (BigErrorMsg),"Database error: %s (%s).",
|
||||||
Message,mysql_error (&Gbl.mysql));
|
Message,mysql_error (&DB_mysql));
|
||||||
Err_ShowErrorAndExit (BigErrorMsg);
|
Err_ShowErrorAndExit (BigErrorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -554,10 +554,7 @@ void Err_ShowErrorAndExit (const char *Txt)
|
||||||
{
|
{
|
||||||
/***** Unlock tables if locked *****/
|
/***** Unlock tables if locked *****/
|
||||||
if (Gbl.DB.LockedTables)
|
if (Gbl.DB.LockedTables)
|
||||||
{
|
DB_UnlockTables ();
|
||||||
Gbl.DB.LockedTables = false;
|
|
||||||
mysql_query (&Gbl.mysql,"UNLOCK TABLES");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Gbl.WebService.IsWebService)
|
if (!Gbl.WebService.IsWebService)
|
||||||
{
|
{
|
||||||
|
|
|
@ -106,8 +106,6 @@ void Gbl_InitializeGlobals (void)
|
||||||
Gbl.F.XML = NULL;
|
Gbl.F.XML = NULL;
|
||||||
Gbl.F.Rep = NULL; // Report
|
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.Alerts.Num = 0; // No pending alerts to be shown
|
||||||
|
|
||||||
Gbl.DB.DatabaseIsOpen = false;
|
Gbl.DB.DatabaseIsOpen = false;
|
||||||
|
|
|
@ -73,13 +73,7 @@ struct Globals
|
||||||
char SMTPPassword[Cfg_MAX_BYTES_SMTP_PASSWORD + 1];
|
char SMTPPassword[Cfg_MAX_BYTES_SMTP_PASSWORD + 1];
|
||||||
} Config;
|
} Config;
|
||||||
struct Files F;
|
struct Files F;
|
||||||
MYSQL mysql;
|
|
||||||
pid_t PID; // PID of current process
|
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
|
struct
|
||||||
{
|
{
|
||||||
size_t Num; // Number of alert
|
size_t Num; // Number of alert
|
||||||
|
|
|
@ -14786,7 +14786,7 @@ const char *Txt_Force_students_to_read_this_information =
|
||||||
#elif L==9 // pt
|
#elif L==9 // pt
|
||||||
"Forçar os estudantes a ler esta informação";
|
"Forçar os estudantes a ler esta informação";
|
||||||
#elif L==10 // tr
|
#elif L==10 // tr
|
||||||
"Force students to read this information"; // Çeviri lazim!
|
"Öğrencileri bu bilgileri okumaya zorla";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char *Txt_Forgotten_password =
|
const char *Txt_Forgotten_password =
|
||||||
|
|
Loading…
Reference in New Issue
Block a user