Version 22.78.10: Mar 23, 2023 Code refactoring in notices.

This commit is contained in:
acanas 2023-03-23 18:06:03 +01:00
parent 4bdd37a586
commit be35a9d058
6 changed files with 116 additions and 123 deletions

View File

@ -629,15 +629,16 @@ TODO: Emilce Barrera Mesa: Podr
TODO: Emilce Barrera Mesa: Mis estudiantes presentan muchas dificultades a la hora de poner la foto porque la plataforma es muy exigente respecto al fondo de la imagen. TODO: Emilce Barrera Mesa: Mis estudiantes presentan muchas dificultades a la hora de poner la foto porque la plataforma es muy exigente respecto al fondo de la imagen.
*/ */
#define Log_PLATFORM_VERSION "SWAD 22.78.9 (2023-03-23)" #define Log_PLATFORM_VERSION "SWAD 22.78.10 (2023-03-23)"
#define CSS_FILE "swad22.57.1.css" #define CSS_FILE "swad22.57.1.css"
#define JS_FILE "swad22.49.js" #define JS_FILE "swad22.49.js"
/* /*
Version 22.78.9: Mar 22, 2023 Code refactoring in mail domains. (337657 lines) Version 22.78.10: Mar 23, 2023 Code refactoring in notices. (337650 lines)
Version 22.78.8: Mar 22, 2023 Code refactoring in holidays. (337648 lines) Version 22.78.9: Mar 23, 2023 Code refactoring in mail domains. (337657 lines)
Version 22.78.7: Mar 22, 2023 Code refactoring in exam sets. (337671 lines) Version 22.78.8: Mar 23, 2023 Code refactoring in holidays. (337648 lines)
Version 22.78.6: Mar 22, 2023 Code refactoring in departments. (337691 lines) Version 22.78.7: Mar 23, 2023 Code refactoring in exam sets. (337671 lines)
Version 22.78.5: Mar 22, 2023 Code refactoring in buildings. (337696 lines) Version 22.78.6: Mar 23, 2023 Code refactoring in departments. (337691 lines)
Version 22.78.5: Mar 23, 2023 Code refactoring in buildings. (337696 lines)
Version 22.78.4: Mar 22, 2023 Code refactoring in file browser. (337693 lines) Version 22.78.4: Mar 22, 2023 Code refactoring in file browser. (337693 lines)
Version 22.78.3: Mar 22, 2023 Code refactoring. (337767 lines) Version 22.78.3: Mar 22, 2023 Code refactoring. (337767 lines)
Version 22.78.2: Mar 22, 2023 Code refactoring in attendance. (337779 lines) Version 22.78.2: Mar 22, 2023 Code refactoring in attendance. (337779 lines)

View File

@ -383,24 +383,26 @@ static void Hld_GetHolidayDataFromRow (MYSQL_RES *mysql_res,
/***** Get row *****/ /***** Get row *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
/* /*
row[0]: PlcCod row[0]: HldCod
row[1]: Place row[1]: PlcCod
row[2]: HldTyp row[2]: Place
row[3]: StartDate row[3]: HldTyp
row[4]: EndDate row[4]: StartDate
row[5]: Name row[5]: EndDate
row[6]: Name
*/ */
/***** Get place code (row[0]) *****/ /***** Get holiday code (row[0]) and place code (row[1]) *****/
Hld->PlcCod = Str_ConvertStrCodToLongCod (row[0]); Hld->HldCod = Str_ConvertStrCodToLongCod (row[0]);
Hld->PlcCod = Str_ConvertStrCodToLongCod (row[1]);
/***** Get the full name of the place (row[1]) *****/ /***** Get the full name of the place (row[2]) *****/
Str_Copy (Hld->PlaceFullName,row[1],sizeof (Hld->PlaceFullName) - 1); Str_Copy (Hld->PlaceFullName,row[2],sizeof (Hld->PlaceFullName) - 1);
/***** Get type (row[2]) *****/ /***** Get type (row[3]) *****/
Hld->HldTyp = Hld_GetTypeOfHoliday (row[2]); Hld->HldTyp = Hld_GetTypeOfHoliday (row[3]);
/***** Get start date (row[3] holds the date in YYYYMMDD format) *****/ /***** Get start date (row[4] holds the date in YYYYMMDD format) *****/
if (!(Dat_GetDateFromYYYYMMDD (&(Hld->StartDate),row[3]))) if (!(Dat_GetDateFromYYYYMMDD (&(Hld->StartDate),row[4])))
Err_WrongDateExit (); Err_WrongDateExit ();
/***** Set / get end date *****/ /***** Set / get end date *****/
@ -411,14 +413,14 @@ static void Hld_GetHolidayDataFromRow (MYSQL_RES *mysql_res,
Dat_AssignDate (&Hld->EndDate,&Hld->StartDate); Dat_AssignDate (&Hld->EndDate,&Hld->StartDate);
break; break;
case Hld_NON_SCHOOL_PERIOD: // One or more days case Hld_NON_SCHOOL_PERIOD: // One or more days
/* Get end date (row[4] holds the date in YYYYMMDD format) */ /* Get end date (row[5] holds the date in YYYYMMDD format) */
if (!(Dat_GetDateFromYYYYMMDD (&(Hld->EndDate),row[4]))) if (!(Dat_GetDateFromYYYYMMDD (&(Hld->EndDate),row[5])))
Err_WrongDateExit (); Err_WrongDateExit ();
break; break;
} }
/***** Get the name of the holiday/non school period (row[5]) *****/ /***** Get the name of the holiday/non school period (row[6]) *****/
Str_Copy (Hld->Name,row[5],sizeof (Hld->Name) - 1); Str_Copy (Hld->Name,row[6],sizeof (Hld->Name) - 1);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -736,8 +736,8 @@ void Msg_DB_GetStatusOfRcvMsg (long MsgCod,
if (DB_QuerySELECT (&mysql_res,"can not get if a received message" if (DB_QuerySELECT (&mysql_res,"can not get if a received message"
" has been replied/expanded", " has been replied/expanded",
"SELECT Open," // row[0] "SELECT Open," // row[0]
"Replied," // row[1] "Replied," // row[1]
"Expanded" // row[2] "Expanded" // row[2]
" FROM msg_rcv" " FROM msg_rcv"
" WHERE MsgCod=%ld" " WHERE MsgCod=%ld"
" AND UsrCod=%ld", " AND UsrCod=%ld",

View File

@ -86,12 +86,12 @@ static void Not_PutIconsListNotices (__attribute__((unused)) void *Args);
static void Not_PutIconToAddNewNotice (void); static void Not_PutIconToAddNewNotice (void);
static void Not_PutButtonToAddNewNotice (void); static void Not_PutButtonToAddNewNotice (void);
static void Not_GetDataAndShowNotice (long NotCod); static void Not_GetDataAndShowNotice (long NotCod);
static void Not_GetNoticeDataFromRow (MYSQL_RES *mysql_res,
struct Not_Notice *Notice,
Not_Listing_t TypeNoticesListing);
static void Not_DrawANotice (Not_Listing_t TypeNoticesListing, static void Not_DrawANotice (Not_Listing_t TypeNoticesListing,
long NotCod,bool Highlight, struct Not_Notice *Notice,
time_t TimeUTC, bool Highlight);
const char *Content,
long UsrCod,
Not_Status_t Status);
static void Not_PutParNotCod (void *NotCod); static void Not_PutParNotCod (void *NotCod);
@ -315,17 +315,11 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing,long HighlightNotCod)
extern const char *Txt_Notices; extern const char *Txt_Notices;
extern const char *Txt_No_notices; extern const char *Txt_No_notices;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
char StrWidth[Cns_MAX_DECIMAL_DIGITS_UINT + 2 + 1]; char StrWidth[Cns_MAX_DECIMAL_DIGITS_UINT + 2 + 1];
char PathRelRSSFile[PATH_MAX + 1]; char PathRelRSSFile[PATH_MAX + 1];
long NotCod; struct Not_Notice Notice;
unsigned NumNot; unsigned NumNot;
unsigned NumNotices = 0; // Initialized to avoid warning unsigned NumNotices = 0; // Initialized to avoid warning
char Content[Cns_MAX_BYTES_TEXT + 1];
time_t TimeUTC;
long UsrCod;
unsigned UnsignedNum;
Not_Status_t Status;
char RSSLink[Cns_MAX_BYTES_WWW + 1]; char RSSLink[Cns_MAX_BYTES_WWW + 1];
/***** Trivial check *****/ /***** Trivial check *****/
@ -360,45 +354,11 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing,long HighlightNotCod)
NumNot < NumNotices; NumNot < NumNotices;
NumNot++) NumNot++)
{ {
row = mysql_fetch_row (mysql_res); Not_GetNoticeDataFromRow (mysql_res,&Notice,TypeNoticesListing);
/* Get notice code (row[0]) */
if (sscanf (row[0],"%ld",&NotCod) != 1)
Err_WrongNoticeExit ();
/* Get creation time (row[1] holds the UTC date-time) */
TimeUTC = Dat_GetUNIXTimeFromStr (row[1]);
/* Get user code (row[2]) */
UsrCod = Str_ConvertStrCodToLongCod (row[2]);
/* Get the content (row[3]) and insert links */
Str_Copy (Content,row[3],sizeof (Content) - 1);
/* Inserting links is incompatible with limiting the length
==> don't insert links when limiting length */
switch (TypeNoticesListing)
{
case Not_LIST_BRIEF_NOTICES:
Str_LimitLengthHTMLStr (Content,Not_MAX_CHARS_ON_NOTICE);
break;
case Not_LIST_FULL_NOTICES:
ALn_InsertLinks (Content,Cns_MAX_BYTES_TEXT,
Not_MaxCharsURLOnScreen[TypeNoticesListing]);
break;
}
/* Get status of the notice (row[4]) */
Status = Not_OBSOLETE_NOTICE;
if (sscanf (row[4],"%u",&UnsignedNum) == 1)
if (UnsignedNum < Not_NUM_STATUS)
Status = (Not_Status_t) UnsignedNum;
/* Draw the notice */ /* Draw the notice */
Not_DrawANotice (TypeNoticesListing, Not_DrawANotice (TypeNoticesListing,&Notice,
NotCod, (Notice.NotCod == HighlightNotCod)); // Highlighted?
(NotCod == HighlightNotCod), // Highlighted?
TimeUTC,Content,UsrCod,Status);
} }
switch (TypeNoticesListing) switch (TypeNoticesListing)
@ -490,56 +450,76 @@ static void Not_PutButtonToAddNewNotice (void)
static void Not_GetDataAndShowNotice (long NotCod) static void Not_GetDataAndShowNotice (long NotCod)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; struct Not_Notice Notice;
char Content[Cns_MAX_BYTES_TEXT + 1];
time_t TimeUTC;
long UsrCod;
unsigned UnsignedNum;
Not_Status_t Status;
/***** Get notice data from database *****/ /***** Get notice data from database *****/
if (Not_DB_GetNoticeData (&mysql_res,NotCod)) if (Not_DB_GetNoticeData (&mysql_res,NotCod))
{ {
row = mysql_fetch_row (mysql_res); Not_GetNoticeDataFromRow (mysql_res,&Notice,Not_LIST_FULL_NOTICES);
/* Get creation time (row[0] holds the UTC date-time) */
TimeUTC = Dat_GetUNIXTimeFromStr (row[0]);
/* Get user code (row[1]) */
UsrCod = Str_ConvertStrCodToLongCod (row[1]);
/* Get the content (row[2]) and insert links*/
Str_Copy (Content,row[2],sizeof (Content) - 1);
ALn_InsertLinks (Content,Cns_MAX_BYTES_TEXT,
Not_MaxCharsURLOnScreen[Not_LIST_FULL_NOTICES]);
/* Get status of the notice (row[3]) */
Status = Not_OBSOLETE_NOTICE;
if (sscanf (row[3],"%u",&UnsignedNum) == 1)
if (UnsignedNum < Not_NUM_STATUS)
Status = (Not_Status_t) UnsignedNum;
/***** Draw the notice *****/ /***** Draw the notice *****/
Not_DrawANotice (Not_LIST_FULL_NOTICES, Not_DrawANotice (Not_LIST_FULL_NOTICES,&Notice,
NotCod, false); // Not highlighted
false, // Not highlighted
TimeUTC,Content,UsrCod,Status);
} }
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
} }
/*****************************************************************************/
/******************* Get notice data from database row ***********************/
/*****************************************************************************/
static void Not_GetNoticeDataFromRow (MYSQL_RES *mysql_res,
struct Not_Notice *Notice,
Not_Listing_t TypeNoticesListing)
{
MYSQL_ROW row;
unsigned UnsignedNum;
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
/***** Get notice code (row[0]) *****/
if (sscanf (row[0],"%ld",&Notice->NotCod) != 1)
Err_WrongNoticeExit ();
/***** Get creation time (row[1] holds the UTC date-time) *****/
Notice->CreatTime = Dat_GetUNIXTimeFromStr (row[1]);
/***** Get user code (row[2]) *****/
Notice->UsrCod = Str_ConvertStrCodToLongCod (row[2]);
/***** Get the content (row[3]) and insert links *****/
Str_Copy (Notice->Content,row[3],sizeof (Notice->Content) - 1);
/* Inserting links is incompatible with limiting the length
==> don't insert links when limiting length */
switch (TypeNoticesListing)
{
case Not_LIST_BRIEF_NOTICES:
Str_LimitLengthHTMLStr (Notice->Content,Not_MAX_CHARS_ON_NOTICE);
break;
case Not_LIST_FULL_NOTICES:
ALn_InsertLinks (Notice->Content,Cns_MAX_BYTES_TEXT,
Not_MaxCharsURLOnScreen[Not_LIST_FULL_NOTICES]);
break;
}
/***** Get status of the notice (row[4]) *****/
Notice->Status = Not_OBSOLETE_NOTICE;
if (sscanf (row[4],"%u",&UnsignedNum) == 1)
if (UnsignedNum < Not_NUM_STATUS)
Notice->Status = (Not_Status_t) UnsignedNum;
}
/*****************************************************************************/ /*****************************************************************************/
/********************* Draw a notice as a yellow note ************************/ /********************* Draw a notice as a yellow note ************************/
/*****************************************************************************/ /*****************************************************************************/
static void Not_DrawANotice (Not_Listing_t TypeNoticesListing, static void Not_DrawANotice (Not_Listing_t TypeNoticesListing,
long NotCod,bool Highlight, struct Not_Notice *Notice,
time_t TimeUTC, bool Highlight)
const char *Content,
long UsrCod,
Not_Status_t Status)
{ {
extern const char *Txt_See_full_notice; extern const char *Txt_See_full_notice;
static Act_Action_t ActionHideUnhide[2] = static Act_Action_t ActionHideUnhide[2] =
@ -563,7 +543,7 @@ static void Not_DrawANotice (Not_Listing_t TypeNoticesListing,
char *Anchor = NULL; char *Anchor = NULL;
/***** Build anchor string *****/ /***** Build anchor string *****/
Frm_SetAnchorStr (NotCod,&Anchor); Frm_SetAnchorStr (Notice->NotCod,&Anchor);
/***** Begin article for this notice *****/ /***** Begin article for this notice *****/
if (TypeNoticesListing == Not_LIST_FULL_NOTICES) if (TypeNoticesListing == Not_LIST_FULL_NOTICES)
@ -576,7 +556,7 @@ static void Not_DrawANotice (Not_Listing_t TypeNoticesListing,
/***** Begin yellow note *****/ /***** Begin yellow note *****/
HTM_DIV_Begin ("class=\"%s %s\"", HTM_DIV_Begin ("class=\"%s %s\"",
ContainerClass[Status],ContainerWidthClass[TypeNoticesListing]); ContainerClass[Notice->Status],ContainerWidthClass[TypeNoticesListing]);
/***** Write the date in the top part of the yellow note *****/ /***** Write the date in the top part of the yellow note *****/
/* Write symbol to indicate if notice is obsolete or active */ /* Write symbol to indicate if notice is obsolete or active */
@ -585,12 +565,12 @@ static void Not_DrawANotice (Not_Listing_t TypeNoticesListing,
{ {
/***** Icon to remove announcement *****/ /***** Icon to remove announcement *****/
Ico_PutContextualIconToRemove (ActReqRemNot,NULL, Ico_PutContextualIconToRemove (ActReqRemNot,NULL,
Not_PutParNotCod,&NotCod); Not_PutParNotCod,&Notice->NotCod);
/***** Icon to change the status of the notice *****/ /***** Icon to change the status of the notice *****/
Ico_PutContextualIconToHideUnhide (ActionHideUnhide,NULL, // TODO: Put anchor Ico_PutContextualIconToHideUnhide (ActionHideUnhide,NULL, // TODO: Put anchor
Not_PutParNotCod,&NotCod, Not_PutParNotCod,&Notice->NotCod,
Status == Not_OBSOLETE_NOTICE); Notice->Status == Not_OBSOLETE_NOTICE);
} }
/* Write the date */ /* Write the date */
@ -601,7 +581,7 @@ static void Not_DrawANotice (Not_Listing_t TypeNoticesListing,
{ {
/* Form to view full notice */ /* Form to view full notice */
Frm_BeginFormAnchor (ActSeeOneNot,Anchor); Frm_BeginFormAnchor (ActSeeOneNot,Anchor);
ParCod_PutPar (ParCod_Not,NotCod); ParCod_PutPar (ParCod_Not,Notice->NotCod);
HTM_BUTTON_Submit_Begin (Txt_See_full_notice, HTM_BUTTON_Submit_Begin (Txt_See_full_notice,
"class=\"RT BT_LINK\""); "class=\"RT BT_LINK\"");
} }
@ -614,7 +594,7 @@ static void Not_DrawANotice (Not_Listing_t TypeNoticesListing,
HTM_BUTTON_End (); HTM_BUTTON_End ();
Frm_EndForm (); Frm_EndForm ();
} }
Dat_WriteLocalDateHMSFromUTC (Id,TimeUTC, Dat_WriteLocalDateHMSFromUTC (Id,Notice->CreatTime,
Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK, Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK,
true,true,false,0x6); true,true,false,0x6);
free (Id); free (Id);
@ -625,13 +605,13 @@ static void Not_DrawANotice (Not_Listing_t TypeNoticesListing,
{ {
HTM_DIV_Begin ("class=\"NOTICE_TEXT_BRIEF NOTICE_TEXT_%s\"", HTM_DIV_Begin ("class=\"NOTICE_TEXT_BRIEF NOTICE_TEXT_%s\"",
The_GetSuffix ()); The_GetSuffix ());
HTM_Txt (Content); HTM_Txt (Notice->Content);
HTM_DIV_End (); HTM_DIV_End ();
/* Put form to view full notice */ /* Put form to view full notice */
HTM_DIV_Begin ("class=\"CM\""); HTM_DIV_Begin ("class=\"CM\"");
Lay_PutContextualLinkOnlyIcon (ActSeeOneNot,Anchor, Lay_PutContextualLinkOnlyIcon (ActSeeOneNot,Anchor,
Not_PutParNotCod,&NotCod, Not_PutParNotCod,&Notice->NotCod,
"ellipsis-h.svg",Ico_BLACK); "ellipsis-h.svg",Ico_BLACK);
HTM_DIV_End (); HTM_DIV_End ();
} }
@ -639,7 +619,7 @@ static void Not_DrawANotice (Not_Listing_t TypeNoticesListing,
{ {
HTM_DIV_Begin ("class=\"NOTICE_TEXT NOTICE_TEXT_%s\"", HTM_DIV_Begin ("class=\"NOTICE_TEXT NOTICE_TEXT_%s\"",
The_GetSuffix ()); The_GetSuffix ());
HTM_Txt (Content); HTM_Txt (Notice->Content);
HTM_DIV_End (); HTM_DIV_End ();
} }
@ -647,7 +627,7 @@ static void Not_DrawANotice (Not_Listing_t TypeNoticesListing,
HTM_DIV_Begin ("class=\"NOTICE_AUTHOR NOTICE_AUTHOR_%s\"", // Limited width HTM_DIV_Begin ("class=\"NOTICE_AUTHOR NOTICE_AUTHOR_%s\"", // Limited width
The_GetSuffix ()); The_GetSuffix ());
Usr_UsrDataConstructor (&UsrDat); Usr_UsrDataConstructor (&UsrDat);
UsrDat.UsrCod = UsrCod; UsrDat.UsrCod = Notice->UsrCod;
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat, // Get author's data from database if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat, // Get author's data from database
Usr_DONT_GET_PREFS, Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CURRENT_CRS)) Usr_DONT_GET_ROLE_IN_CURRENT_CRS))

View File

@ -47,6 +47,15 @@ typedef enum
Not_OBSOLETE_NOTICE = 1, Not_OBSOLETE_NOTICE = 1,
} Not_Status_t; // Don't change these numbers because they are used in database } Not_Status_t; // Don't change these numbers because they are used in database
struct Not_Notice
{
long NotCod;
long UsrCod;
time_t CreatTime;
Not_Status_t Status;
char Content[Cns_MAX_BYTES_TEXT + 1];
};
/*****************************************************************************/ /*****************************************************************************/
/***************************** Public prototypes *****************************/ /***************************** Public prototypes *****************************/
/*****************************************************************************/ /*****************************************************************************/

View File

@ -116,10 +116,11 @@ unsigned Not_DB_GetNoticeData (MYSQL_RES **mysql_res,long NotCod)
{ {
return (unsigned) return (unsigned)
DB_QuerySELECT (mysql_res,"can not get notice from database", DB_QuerySELECT (mysql_res,"can not get notice from database",
"SELECT UNIX_TIMESTAMP(CreatTime) AS F," // row[0] "SELECT NotCod," // row[0]
"UsrCod," // row[1] "UNIX_TIMESTAMP(CreatTime) AS F," // row[1]
"Content," // row[2] "UsrCod," // row[2]
"Status" // row[3] "Content," // row[3]
"Status" // row[4]
" FROM not_notices" " FROM not_notices"
" WHERE NotCod=%ld" " WHERE NotCod=%ld"
" AND CrsCod=%ld", // Extra check " AND CrsCod=%ld", // Extra check