Version 22.78.6: Mar 22, 2023 Code refactoring in departments.

This commit is contained in:
acanas 2023-03-23 11:28:22 +01:00
parent fc87db628c
commit 8727559e7d
8 changed files with 59 additions and 64 deletions

View File

@ -150,7 +150,7 @@ void Cfe_PutFrmEditACallForExam (void)
if (ExaCod > 0) // -1 indicates that this is a new call for exam if (ExaCod > 0) // -1 indicates that this is a new call for exam
/***** Read call for exam from the database *****/ /***** Read call for exam from the database *****/
Cfe_GetDataCallForExamFromDB (&CallsForExams,ExaCod); Cfe_GetCallForExamDataByCod (&CallsForExams,ExaCod);
/***** Show call for exam *****/ /***** Show call for exam *****/
Cfe_ShowCallForExam (&CallsForExams,ExaCod,Cfe_FORM_VIEW, Cfe_ShowCallForExam (&CallsForExams,ExaCod,Cfe_FORM_VIEW,
@ -382,7 +382,7 @@ void Cfe_PrintCallForExam (void)
ExaCod = ParCod_GetAndCheckPar (ParCod_Exa); ExaCod = ParCod_GetAndCheckPar (ParCod_Exa);
/***** Read call for exam from the database *****/ /***** Read call for exam from the database *****/
Cfe_GetDataCallForExamFromDB (&CallsForExams,ExaCod); Cfe_GetCallForExamDataByCod (&CallsForExams,ExaCod);
/***** Show call for exam *****/ /***** Show call for exam *****/
Cfe_ShowCallForExam (&CallsForExams,ExaCod,Cfe_PRINT_VIEW, Cfe_ShowCallForExam (&CallsForExams,ExaCod,Cfe_PRINT_VIEW,
@ -414,7 +414,7 @@ void Cfe_ReqRemCallForExam (void)
/* Show call for exam */ /* Show call for exam */
Cfe_AllocMemCallForExam (&CallsForExams); Cfe_AllocMemCallForExam (&CallsForExams);
Cfe_GetDataCallForExamFromDB (&CallsForExams,ExaCod); Cfe_GetCallForExamDataByCod (&CallsForExams,ExaCod);
Cfe_ShowCallForExam (&CallsForExams,ExaCod,Cfe_NORMAL_VIEW, Cfe_ShowCallForExam (&CallsForExams,ExaCod,Cfe_NORMAL_VIEW,
false); // Don't highlight false); // Don't highlight
Cfe_FreeMemCallForExam (&CallsForExams); Cfe_FreeMemCallForExam (&CallsForExams);
@ -640,7 +640,7 @@ static void Cfe_ListCallsForExams (struct Cfe_CallsForExams *CallsForExams,
Cfe_AllocMemCallForExam (CallsForExams); Cfe_AllocMemCallForExam (CallsForExams);
/***** Read the data of the call for exam *****/ /***** Read the data of the call for exam *****/
Cfe_GetDataCallForExamFromDB (CallsForExams,ExaCod); Cfe_GetCallForExamDataByCod (CallsForExams,ExaCod);
/***** Show call for exam *****/ /***** Show call for exam *****/
HighLight = false; HighLight = false;
@ -775,8 +775,8 @@ void Cfe_FreeListCallsForExams (struct Cfe_CallsForExams *CallsForExams)
/*********** Read the data of a call for exam from the database **************/ /*********** Read the data of a call for exam from the database **************/
/*****************************************************************************/ /*****************************************************************************/
void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExams, void Cfe_GetCallForExamDataByCod (struct Cfe_CallsForExams *CallsForExams,
long ExaCod) long ExaCod)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
@ -786,7 +786,7 @@ void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExams,
unsigned Second; unsigned Second;
/***** Get data of a call for exam from database *****/ /***** Get data of a call for exam from database *****/
if (Cfe_DB_GetDataCallForExam (&mysql_res,ExaCod) != 1) if (Cfe_DB_GetCallForExamDataByCod (&mysql_res,ExaCod) != 1)
Err_WrongCallForExamExit (); Err_WrongCallForExamExit ();
/***** Get the data of the call for exam *****/ /***** Get the data of the call for exam *****/
@ -1572,7 +1572,7 @@ void Cfe_GetSummaryAndContentCallForExam (char SummaryStr[Ntf_MAX_BYTES_SUMMARY
Cfe_AllocMemCallForExam (&CallsForExams); Cfe_AllocMemCallForExam (&CallsForExams);
/***** Get data of a call for exam from database *****/ /***** Get data of a call for exam from database *****/
Cfe_GetDataCallForExamFromDB (&CallsForExams,ExaCod); Cfe_GetCallForExamDataByCod (&CallsForExams,ExaCod);
/***** Content *****/ /***** Content *****/
if (GetContent) if (GetContent)

View File

@ -119,8 +119,8 @@ void Cfe_HideCallForExam (void);
void Cfe_UnhideCallForExam (void); void Cfe_UnhideCallForExam (void);
void Cfe_FreeListCallsForExams (struct Cfe_CallsForExams *CallsForExams); void Cfe_FreeListCallsForExams (struct Cfe_CallsForExams *CallsForExams);
void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExams, void Cfe_GetCallForExamDataByCod (struct Cfe_CallsForExams *CallsForExams,
long ExaCod); long ExaCod);
void Cfe_ListCallsForExamsSee (void); void Cfe_ListCallsForExamsSee (void);
void Cfe_ListCallsForExamsEdit (void); void Cfe_ListCallsForExamsEdit (void);

View File

@ -154,7 +154,7 @@ unsigned Cfe_DB_GetFutureCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res)
/***************** Get data of a call for exam from database *****************/ /***************** Get data of a call for exam from database *****************/
/*****************************************************************************/ /*****************************************************************************/
unsigned Cfe_DB_GetDataCallForExam (MYSQL_RES **mysql_res,long ExaCod) unsigned Cfe_DB_GetCallForExamDataByCod (MYSQL_RES **mysql_res,long ExaCod)
{ {
return (unsigned) return (unsigned)
DB_QuerySELECT (mysql_res,"can not get data of a call for exam", DB_QuerySELECT (mysql_res,"can not get data of a call for exam",

View File

@ -38,7 +38,7 @@ long Cfe_DB_CreateCallForExam (const struct Cfe_CallForExam *CallForExam);
unsigned Cfe_DB_GetCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res); unsigned Cfe_DB_GetCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res);
unsigned Cfe_DB_GetVisibleCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res); unsigned Cfe_DB_GetVisibleCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res);
unsigned Cfe_DB_GetFutureCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res); unsigned Cfe_DB_GetFutureCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res);
unsigned Cfe_DB_GetDataCallForExam (MYSQL_RES **mysql_res,long ExaCod); unsigned Cfe_DB_GetCallForExamDataByCod (MYSQL_RES **mysql_res,long ExaCod);
void Cfe_DB_ModifyCallForExam (const struct Cfe_CallForExam *CallForExam, void Cfe_DB_ModifyCallForExam (const struct Cfe_CallForExam *CallForExam,
long ExaCod); long ExaCod);

View File

@ -138,7 +138,7 @@ void CfeRsc_GetTitleFromExaCod (long ExaCod,char *Title,size_t TitleSize)
/***** Get data of call for exam *****/ /***** Get data of call for exam *****/
Cfe_AllocMemCallForExam (&CallsForExams); Cfe_AllocMemCallForExam (&CallsForExams);
Cfe_GetDataCallForExamFromDB (&CallsForExams,ExaCod); Cfe_GetCallForExamDataByCod (&CallsForExams,ExaCod);
/***** Session and date of the exam *****/ /***** Session and date of the exam *****/
Cfe_BuildSessionAndDate (&CallsForExams,SessionAndDate); Cfe_BuildSessionAndDate (&CallsForExams,SessionAndDate);

View File

@ -629,11 +629,12 @@ 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.5 (2023-03-23)" #define Log_PLATFORM_VERSION "SWAD 22.78.6 (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.5: Mar 22, 2023 Code refactoring in banners. (337696 lines) Version 22.78.6: Mar 22, 2023 Code refactoring in departments. (337691 lines)
Version 22.78.5: Mar 22, 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

@ -73,6 +73,9 @@ static void Dpt_EditDepartmentsInternal (void);
static void Dpt_GetListDepartments (struct Dpt_Departments *Departments,long InsCod); static void Dpt_GetListDepartments (struct Dpt_Departments *Departments,long InsCod);
static void Dpt_GetDepartmentDataFromRow (MYSQL_RES *mysql_res,
struct Dpt_Department *Dpt);
static void Dpt_ListDepartmentsForEdition (const struct Dpt_Departments *Departments); static void Dpt_ListDepartmentsForEdition (const struct Dpt_Departments *Departments);
static void Dpt_PutParDptCod (void *DptCod); static void Dpt_PutParDptCod (void *DptCod);
@ -325,9 +328,7 @@ static void Dpt_EditDepartmentsInternal (void)
static void Dpt_GetListDepartments (struct Dpt_Departments *Departments,long InsCod) static void Dpt_GetListDepartments (struct Dpt_Departments *Departments,long InsCod)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumDpt; unsigned NumDpt;
struct Dpt_Department *Dpt;
/***** Free list of departments *****/ /***** Free list of departments *****/
Dpt_FreeListDepartments (Departments); // List is initialized to empty Dpt_FreeListDepartments (Departments); // List is initialized to empty
@ -348,30 +349,7 @@ static void Dpt_GetListDepartments (struct Dpt_Departments *Departments,long Ins
for (NumDpt = 0; for (NumDpt = 0;
NumDpt < Departments->Num; NumDpt < Departments->Num;
NumDpt++) NumDpt++)
{ Dpt_GetDepartmentDataFromRow (mysql_res,&(Departments->Lst[NumDpt]));
Dpt = &(Departments->Lst[NumDpt]);
/* Get next department */
row = mysql_fetch_row (mysql_res);
/* Get department code (row[0]) */
if ((Dpt->DptCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongDepartmentExit ();
/* Get institution code (row[1]) */
if ((Dpt->InsCod = Str_ConvertStrCodToLongCod (row[1])) <= 0)
Err_WrongInstitExit ();
/* Get short name (row[2]), full name (row[3])
and URL (row[4]) of the department */
Str_Copy (Dpt->ShrtName,row[2],sizeof (Dpt->ShrtName) - 1);
Str_Copy (Dpt->FullName,row[3],sizeof (Dpt->FullName) - 1);
Str_Copy (Dpt->WWW ,row[4],sizeof (Dpt->WWW ) - 1);
/* Get number of non-editing teachers and teachers in this department (row[5]) */
if (sscanf (row[5],"%u",&Dpt->NumTchs) != 1)
Dpt->NumTchs = 0;
}
} }
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
@ -387,7 +365,6 @@ void Dpt_GetDepartmentDataByCod (struct Dpt_Department *Dpt)
{ {
extern const char *Txt_Another_department; extern const char *Txt_Another_department;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
/***** Clear data *****/ /***** Clear data *****/
Dpt->InsCod = -1L; Dpt->InsCod = -1L;
@ -404,23 +381,7 @@ void Dpt_GetDepartmentDataByCod (struct Dpt_Department *Dpt)
{ {
/***** Get data of a department from database *****/ /***** Get data of a department from database *****/
if (Dpt_DB_GetDepartmentDataByCod (&mysql_res,Dpt->DptCod)) // Department found... if (Dpt_DB_GetDepartmentDataByCod (&mysql_res,Dpt->DptCod)) // Department found...
{ Dpt_GetDepartmentDataFromRow (mysql_res,Dpt);
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get the code of the institution (row[0]) */
Dpt->InsCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get short name (row[1]), full name (row[2])
and URL (row[3]) of the department */
Str_Copy (Dpt->ShrtName,row[1],sizeof (Dpt->ShrtName) - 1);
Str_Copy (Dpt->FullName,row[2],sizeof (Dpt->FullName) - 1);
Str_Copy (Dpt->WWW ,row[3],sizeof (Dpt->WWW ) - 1);
/* Get number of teachers in this department (row[4]) */
if (sscanf (row[4],"%u",&Dpt->NumTchs) != 1)
Dpt->NumTchs = 0;
}
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
@ -441,6 +402,38 @@ void Dpt_FreeListDepartments (struct Dpt_Departments *Departments)
Departments->Num = 0; Departments->Num = 0;
} }
/*****************************************************************************/
/****************** Get data of department from database row *****************/
/*****************************************************************************/
static void Dpt_GetDepartmentDataFromRow (MYSQL_RES *mysql_res,
struct Dpt_Department *Dpt)
{
MYSQL_ROW row;
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
/***** Get department code (row[0]) *****/
if ((Dpt->DptCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongDepartmentExit ();
/***** Get institution code (row[1]) *****/
if ((Dpt->InsCod = Str_ConvertStrCodToLongCod (row[1])) <= 0)
Err_WrongInstitExit ();
/***** Get short name (row[2]), full name (row[3])
and URL (row[4]) of the department *****/
Str_Copy (Dpt->ShrtName,row[2],sizeof (Dpt->ShrtName) - 1);
Str_Copy (Dpt->FullName,row[3],sizeof (Dpt->FullName) - 1);
Str_Copy (Dpt->WWW ,row[4],sizeof (Dpt->WWW ) - 1);
/***** Get number of non-editing teachers and teachers
in this department (row[5]) *****/
if (sscanf (row[5],"%u",&Dpt->NumTchs) != 1)
Dpt->NumTchs = 0;
}
/*****************************************************************************/ /*****************************************************************************/
/***************************** List all departments **************************/ /***************************** List all departments **************************/
/*****************************************************************************/ /*****************************************************************************/

View File

@ -113,11 +113,12 @@ unsigned Dpt_DB_GetDepartmentDataByCod (MYSQL_RES **mysql_res,long DptCod)
{ {
return (unsigned) return (unsigned)
DB_QuerySELECT (mysql_res,"can not get data of a department", DB_QuerySELECT (mysql_res,"can not get data of a department",
"(SELECT dpt_departments.InsCod," // row[0] "(SELECT dpt_departments.DptCod," // row[0]
"dpt_departments.ShortName," // row[1] "dpt_departments.InsCod," // row[1]
"dpt_departments.FullName," // row[2] "dpt_departments.ShortName," // row[2]
"dpt_departments.WWW," // row[3] "dpt_departments.FullName," // row[3]
"COUNT(DISTINCT usr_data.UsrCod) AS NumTchs" // row[4] "dpt_departments.WWW," // row[4]
"COUNT(DISTINCT usr_data.UsrCod) AS NumTchs" // row[5]
" FROM dpt_departments," " FROM dpt_departments,"
"usr_data," "usr_data,"
"crs_users" "crs_users"