diff --git a/swad_call_for_exam.c b/swad_call_for_exam.c index ded19ab7..da10a8a4 100644 --- a/swad_call_for_exam.c +++ b/swad_call_for_exam.c @@ -150,7 +150,7 @@ void Cfe_PutFrmEditACallForExam (void) if (ExaCod > 0) // -1 indicates that this is a new call for exam /***** Read call for exam from the database *****/ - Cfe_GetDataCallForExamFromDB (&CallsForExams,ExaCod); + Cfe_GetCallForExamDataByCod (&CallsForExams,ExaCod); /***** Show call for exam *****/ Cfe_ShowCallForExam (&CallsForExams,ExaCod,Cfe_FORM_VIEW, @@ -382,7 +382,7 @@ void Cfe_PrintCallForExam (void) ExaCod = ParCod_GetAndCheckPar (ParCod_Exa); /***** Read call for exam from the database *****/ - Cfe_GetDataCallForExamFromDB (&CallsForExams,ExaCod); + Cfe_GetCallForExamDataByCod (&CallsForExams,ExaCod); /***** Show call for exam *****/ Cfe_ShowCallForExam (&CallsForExams,ExaCod,Cfe_PRINT_VIEW, @@ -414,7 +414,7 @@ void Cfe_ReqRemCallForExam (void) /* Show call for exam */ Cfe_AllocMemCallForExam (&CallsForExams); - Cfe_GetDataCallForExamFromDB (&CallsForExams,ExaCod); + Cfe_GetCallForExamDataByCod (&CallsForExams,ExaCod); Cfe_ShowCallForExam (&CallsForExams,ExaCod,Cfe_NORMAL_VIEW, false); // Don't highlight Cfe_FreeMemCallForExam (&CallsForExams); @@ -640,7 +640,7 @@ static void Cfe_ListCallsForExams (struct Cfe_CallsForExams *CallsForExams, Cfe_AllocMemCallForExam (CallsForExams); /***** Read the data of the call for exam *****/ - Cfe_GetDataCallForExamFromDB (CallsForExams,ExaCod); + Cfe_GetCallForExamDataByCod (CallsForExams,ExaCod); /***** Show call for exam *****/ HighLight = false; @@ -775,8 +775,8 @@ void Cfe_FreeListCallsForExams (struct Cfe_CallsForExams *CallsForExams) /*********** Read the data of a call for exam from the database **************/ /*****************************************************************************/ -void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExams, - long ExaCod) +void Cfe_GetCallForExamDataByCod (struct Cfe_CallsForExams *CallsForExams, + long ExaCod) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -786,7 +786,7 @@ void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExams, unsigned Second; /***** 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 (); /***** Get the data of the call for exam *****/ @@ -1572,7 +1572,7 @@ void Cfe_GetSummaryAndContentCallForExam (char SummaryStr[Ntf_MAX_BYTES_SUMMARY Cfe_AllocMemCallForExam (&CallsForExams); /***** Get data of a call for exam from database *****/ - Cfe_GetDataCallForExamFromDB (&CallsForExams,ExaCod); + Cfe_GetCallForExamDataByCod (&CallsForExams,ExaCod); /***** Content *****/ if (GetContent) diff --git a/swad_call_for_exam.h b/swad_call_for_exam.h index ef178a64..6aa64466 100644 --- a/swad_call_for_exam.h +++ b/swad_call_for_exam.h @@ -119,8 +119,8 @@ void Cfe_HideCallForExam (void); void Cfe_UnhideCallForExam (void); void Cfe_FreeListCallsForExams (struct Cfe_CallsForExams *CallsForExams); -void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExams, - long ExaCod); +void Cfe_GetCallForExamDataByCod (struct Cfe_CallsForExams *CallsForExams, + long ExaCod); void Cfe_ListCallsForExamsSee (void); void Cfe_ListCallsForExamsEdit (void); diff --git a/swad_call_for_exam_database.c b/swad_call_for_exam_database.c index 50402cba..b7972ca9 100644 --- a/swad_call_for_exam_database.c +++ b/swad_call_for_exam_database.c @@ -154,7 +154,7 @@ unsigned Cfe_DB_GetFutureCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res) /***************** 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) DB_QuerySELECT (mysql_res,"can not get data of a call for exam", diff --git a/swad_call_for_exam_database.h b/swad_call_for_exam_database.h index 507e2e23..bf297dee 100644 --- a/swad_call_for_exam_database.h +++ b/swad_call_for_exam_database.h @@ -38,7 +38,7 @@ long Cfe_DB_CreateCallForExam (const struct Cfe_CallForExam *CallForExam); unsigned Cfe_DB_GetCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res); unsigned Cfe_DB_GetVisibleCallsForExamsInCurrentCrs (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, long ExaCod); diff --git a/swad_call_for_exam_resource.c b/swad_call_for_exam_resource.c index 709ead55..08aa52f3 100644 --- a/swad_call_for_exam_resource.c +++ b/swad_call_for_exam_resource.c @@ -138,7 +138,7 @@ void CfeRsc_GetTitleFromExaCod (long ExaCod,char *Title,size_t TitleSize) /***** Get data of call for exam *****/ Cfe_AllocMemCallForExam (&CallsForExams); - Cfe_GetDataCallForExamFromDB (&CallsForExams,ExaCod); + Cfe_GetCallForExamDataByCod (&CallsForExams,ExaCod); /***** Session and date of the exam *****/ Cfe_BuildSessionAndDate (&CallsForExams,SessionAndDate); diff --git a/swad_changelog.h b/swad_changelog.h index 8fd13355..6b7a5a32 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -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. */ -#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 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.3: Mar 22, 2023 Code refactoring. (337767 lines) Version 22.78.2: Mar 22, 2023 Code refactoring in attendance. (337779 lines) diff --git a/swad_department.c b/swad_department.c index ad0f5178..6c232cb9 100644 --- a/swad_department.c +++ b/swad_department.c @@ -73,6 +73,9 @@ static void Dpt_EditDepartmentsInternal (void); 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_PutParDptCod (void *DptCod); @@ -325,9 +328,7 @@ static void Dpt_EditDepartmentsInternal (void) static void Dpt_GetListDepartments (struct Dpt_Departments *Departments,long InsCod) { MYSQL_RES *mysql_res; - MYSQL_ROW row; unsigned NumDpt; - struct Dpt_Department *Dpt; /***** Free list of departments *****/ 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; NumDpt < Departments->Num; 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; - } + Dpt_GetDepartmentDataFromRow (mysql_res,&(Departments->Lst[NumDpt])); } /***** Free structure that stores the query result *****/ @@ -387,7 +365,6 @@ void Dpt_GetDepartmentDataByCod (struct Dpt_Department *Dpt) { extern const char *Txt_Another_department; MYSQL_RES *mysql_res; - MYSQL_ROW row; /***** Clear data *****/ Dpt->InsCod = -1L; @@ -404,23 +381,7 @@ void Dpt_GetDepartmentDataByCod (struct Dpt_Department *Dpt) { /***** Get data of a department from database *****/ if (Dpt_DB_GetDepartmentDataByCod (&mysql_res,Dpt->DptCod)) // Department found... - { - /* 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; - } + Dpt_GetDepartmentDataFromRow (mysql_res,Dpt); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -441,6 +402,38 @@ void Dpt_FreeListDepartments (struct Dpt_Departments *Departments) 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 **************************/ /*****************************************************************************/ diff --git a/swad_department_database.c b/swad_department_database.c index 080830c4..8d29e48c 100644 --- a/swad_department_database.c +++ b/swad_department_database.c @@ -113,11 +113,12 @@ unsigned Dpt_DB_GetDepartmentDataByCod (MYSQL_RES **mysql_res,long DptCod) { return (unsigned) DB_QuerySELECT (mysql_res,"can not get data of a department", - "(SELECT dpt_departments.InsCod," // row[0] - "dpt_departments.ShortName," // row[1] - "dpt_departments.FullName," // row[2] - "dpt_departments.WWW," // row[3] - "COUNT(DISTINCT usr_data.UsrCod) AS NumTchs" // row[4] + "(SELECT dpt_departments.DptCod," // row[0] + "dpt_departments.InsCod," // row[1] + "dpt_departments.ShortName," // row[2] + "dpt_departments.FullName," // row[3] + "dpt_departments.WWW," // row[4] + "COUNT(DISTINCT usr_data.UsrCod) AS NumTchs" // row[5] " FROM dpt_departments," "usr_data," "crs_users"