diff --git a/swad_assignment.c b/swad_assignment.c index 9c9efe686..baaa5c69d 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -1293,7 +1293,8 @@ static void Asg_ShowLstGrpsToEditAssignment (long AsgCod) "AsgCod", AsgCod) ? "" : " checked=\"checked\""); - HTM_TxtF ("%s %s",Txt_The_whole_course,Gbl.Hierarchy.Node[HieLvl_CRS].ShrtName); + HTM_TxtF ("%s %s",Txt_The_whole_course, + Gbl.Hierarchy.Node[HieLvl_CRS].ShrtName); HTM_LABEL_End (); HTM_TD_End (); HTM_TR_End (); @@ -1572,7 +1573,8 @@ static void Asg_GetAndWriteNamesOfGrpsAssociatedToAsg (struct Asg_Assignment *As } } else - HTM_TxtF ("%s %s",Txt_The_whole_course,Gbl.Hierarchy.Node[HieLvl_CRS].ShrtName); + HTM_TxtF ("%s %s",Txt_The_whole_course, + Gbl.Hierarchy.Node[HieLvl_CRS].ShrtName); HTM_DIV_End (); diff --git a/swad_attendance.c b/swad_attendance.c index 94eaa0aaf..3f799da4e 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -1109,7 +1109,8 @@ static void Att_ShowLstGrpsToEditEvent (long AttCod) "AttCod", AttCod) ? "" : " checked=\"checked\""); - HTM_TxtF ("%s %s",Txt_The_whole_course,Gbl.Hierarchy.Node[HieLvl_CRS].ShrtName); + HTM_TxtF ("%s %s",Txt_The_whole_course, + Gbl.Hierarchy.Node[HieLvl_CRS].ShrtName); HTM_LABEL_End (); HTM_TD_End (); @@ -1335,8 +1336,8 @@ static void Att_GetAndWriteNamesOfGrpsAssociatedToEvent (struct Att_Event *Event } } else - HTM_TxtF ("%s %s", - Txt_The_whole_course,Gbl.Hierarchy.Node[HieLvl_CRS].ShrtName); + HTM_TxtF ("%s %s",Txt_The_whole_course, + Gbl.Hierarchy.Node[HieLvl_CRS].ShrtName); /***** End container *****/ HTM_DIV_End (); diff --git a/swad_center.c b/swad_center.c index 3f31db8ab..8f6a130bc 100644 --- a/swad_center.c +++ b/swad_center.c @@ -241,7 +241,7 @@ void Ctr_ShowCtrsOfCurrentIns (void) Ctr_ListCenters (); /***** Free list of centers *****/ - Ctr_FreeListCenters (); + Hie_FreeList (HieLvl_INS); } /*****************************************************************************/ @@ -450,7 +450,7 @@ static void Ctr_EditCentersInternal (void) Box_BoxEnd (); /***** Free list of centers *****/ - Ctr_FreeListCenters (); + Hie_FreeList (HieLvl_INS); /***** Free list of places *****/ Plc_FreeListPlaces (&Places); @@ -654,21 +654,6 @@ static void Ctr_GetCoordFromRow (MYSQL_RES *mysql_res, Coord->Altitude = Map_GetAltitudeFromStr (row[2]); } -/*****************************************************************************/ -/**************************** Free list of centers ***************************/ -/*****************************************************************************/ - -void Ctr_FreeListCenters (void) - { - if (Gbl.Hierarchy.List[HieLvl_INS].Lst) - { - /***** Free memory used by the list of courses in degree *****/ - free (Gbl.Hierarchy.List[HieLvl_INS].Lst); - Gbl.Hierarchy.List[HieLvl_INS].Lst = NULL; - Gbl.Hierarchy.List[HieLvl_INS].Num = 0; - } - } - /*****************************************************************************/ /************************** Write selector of center *************************/ /*****************************************************************************/ diff --git a/swad_center.h b/swad_center.h index b6e653918..f9bcc36f2 100644 --- a/swad_center.h +++ b/swad_center.h @@ -57,7 +57,6 @@ void Ctr_GetBasicListOfCenters (long InsCod); void Ctr_GetFullListOfCenters (long InsCod,Hie_Order_t SelectedOrder); bool Ctr_GetCenterDataByCod (struct Hie_Node *Ctr); void Ctr_GetCoordByCod (long CtrCod,struct Map_Coordinates *Coord); -void Ctr_FreeListCenters (void); void Ctr_WriteSelectorOfCenter (void); void Ctr_RemoveCenter (void); void Ctr_ChangeCtrPlc (void); diff --git a/swad_center_config.c b/swad_center_config.c index d5a73d24d..621a46aac 100644 --- a/swad_center_config.c +++ b/swad_center_config.c @@ -437,7 +437,8 @@ static void CtrCfg_Photo (bool PrintView,bool PutForm,bool PutLink, /***** Photo image *****/ HTM_DIV_Begin ("class=\"CM\""); if (PutLink) - HTM_A_Begin ("href=\"%s\" target=\"_blank\"",Gbl.Hierarchy.Node[HieLvl_CTR].WWW); + HTM_A_Begin ("href=\"%s\" target=\"_blank\"", + Gbl.Hierarchy.Node[HieLvl_CTR].WWW); if (asprintf (&URL,"%s/%02u/%u", Cfg_URL_CTR_PUBLIC, (unsigned) (Gbl.Hierarchy.Node[HieLvl_CTR].Cod % 100), @@ -573,7 +574,7 @@ static void CtrCfg_Institution (bool PrintView,bool PutForm) Frm_EndForm (); /* Free list of institutions */ - Ins_FreeListInstitutions (); + Hie_FreeList (HieLvl_CTY); } else // I can not move center to another institution { @@ -769,7 +770,8 @@ static void CtrCfg_NumDegs (void) HTM_TD_Begin ("class=\"LB DAT_%s\"",The_GetSuffix ()); Frm_BeginFormGoTo (ActSeeDeg); ParCod_PutPar (ParCod_Ctr,Gbl.Hierarchy.Node[HieLvl_CTR].Cod); - if (asprintf (&Title,Txt_Degrees_of_CENTER_X,Gbl.Hierarchy.Node[HieLvl_CTR].ShrtName) < 0) + if (asprintf (&Title,Txt_Degrees_of_CENTER_X, + Gbl.Hierarchy.Node[HieLvl_CTR].ShrtName) < 0) Err_NotEnoughMemoryExit (); HTM_BUTTON_Submit_Begin (Title,"class=\"LB BT_LINK\""); free (Title); @@ -1002,7 +1004,8 @@ void CtrCfg_ChangeCtrPhotoAttr (void) Par_GetParText ("Attribution",NewPhotoAttribution,Med_MAX_BYTES_ATTRIBUTION); /***** Update the table changing old attribution by new attribution *****/ - Ctr_DB_UpdateCtrPhotoAttribution (Gbl.Hierarchy.Node[HieLvl_CTR].Cod,NewPhotoAttribution); + Ctr_DB_UpdateCtrPhotoAttribution (Gbl.Hierarchy.Node[HieLvl_CTR].Cod, + NewPhotoAttribution); /***** Show the center information again *****/ CtrCfg_ShowConfiguration (); @@ -1113,7 +1116,8 @@ void CtrCfg_ChangeCtrLatitude (void) NewLatitude = Map_GetLatitudeFromStr (LatitudeStr); /***** Update database changing old latitude by new latitude *****/ - Ctr_DB_UpdateCtrCoordinate (Gbl.Hierarchy.Node[HieLvl_CTR].Cod,"Latitude",NewLatitude); + Ctr_DB_UpdateCtrCoordinate (Gbl.Hierarchy.Node[HieLvl_CTR].Cod, + "Latitude",NewLatitude); /***** Show the form again *****/ CtrCfg_ShowConfiguration (); @@ -1133,7 +1137,8 @@ void CtrCfg_ChangeCtrLongitude (void) NewLongitude = Map_GetLongitudeFromStr (LongitudeStr); /***** Update database changing old longitude by new longitude *****/ - Ctr_DB_UpdateCtrCoordinate (Gbl.Hierarchy.Node[HieLvl_CTR].Cod,"Longitude",NewLongitude); + Ctr_DB_UpdateCtrCoordinate (Gbl.Hierarchy.Node[HieLvl_CTR].Cod, + "Longitude",NewLongitude); /***** Show the form again *****/ CtrCfg_ShowConfiguration (); @@ -1153,7 +1158,8 @@ void CtrCfg_ChangeCtrAltitude (void) NewAltitude = Map_GetAltitudeFromStr (AltitudeStr); /***** Update database changing old altitude by new altitude *****/ - Ctr_DB_UpdateCtrCoordinate (Gbl.Hierarchy.Node[HieLvl_CTR].Cod,"Altitude",NewAltitude); + Ctr_DB_UpdateCtrCoordinate (Gbl.Hierarchy.Node[HieLvl_CTR].Cod, + "Altitude",NewAltitude); /***** Show the form again *****/ CtrCfg_ShowConfiguration (); diff --git a/swad_changelog.h b/swad_changelog.h index 89b7c17f8..324c33ade 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -632,10 +632,11 @@ TODO: Francisco Javier Fern Me sale este error, no sé si por no recordar yo la sintaxis apropiada para mandar a varios destinatarios. ¿No era así? "can npt create received message (duplicated entry '243218-2160773' for key 'UsrCod_MsgCod') */ -#define Log_PLATFORM_VERSION "SWAD 23.9.5 (2023-09-19)" +#define Log_PLATFORM_VERSION "SWAD 23.9.6 (2023-09-19)" #define CSS_FILE "swad22.120.4.css" #define JS_FILE "swad22.49.js" /* + Version 23.9.6: Sep 19, 2023 Code refactoring in hierarchy. (337410 lines) Version 23.9.5: Sep 19, 2023 Code refactoring in hierarchy. (337441 lines) Version 23.9.4: Sep 19, 2023 Code refactoring in calls for exams. (337504 lines) Version 23.9.3: Sep 19, 2023 Changes and code refactoring related to class photo. (337507 lines) diff --git a/swad_country.c b/swad_country.c index 36a4e4b7d..1525ecdd2 100644 --- a/swad_country.c +++ b/swad_country.c @@ -335,7 +335,7 @@ void Cty_ListCountries2 (void) } /***** Free list of countries *****/ - Cty_FreeListCountries (); + Hie_FreeList (HieLvl_SYS); } /*****************************************************************************/ @@ -695,7 +695,7 @@ static void Cty_EditCountriesInternal (void) Box_BoxEnd (); /***** Free list of countries *****/ - Cty_FreeListCountries (); + Hie_FreeList (HieLvl_SYS); } /*****************************************************************************/ @@ -1028,21 +1028,6 @@ void Cty_GetCountryNameInLanguage (long CtyCod,Lan_Language_t Language, Str_Copy (Gbl.Cache.CountryName.CtyName,CtyName,Cty_MAX_BYTES_NAME); } -/*****************************************************************************/ -/*************************** Free list of countries **************************/ -/*****************************************************************************/ - -void Cty_FreeListCountries (void) - { - if (Gbl.Hierarchy.List[HieLvl_SYS].Lst) - { - /***** Free memory used by the list of courses in institution *****/ - free (Gbl.Hierarchy.List[HieLvl_SYS].Lst); - Gbl.Hierarchy.List[HieLvl_SYS].Lst = NULL; - Gbl.Hierarchy.List[HieLvl_SYS].Num = 0; - } - } - /*****************************************************************************/ /***************************** List all countries ****************************/ /*****************************************************************************/ diff --git a/swad_country.h b/swad_country.h index e85cdd90b..333320d77 100644 --- a/swad_country.h +++ b/swad_country.h @@ -67,7 +67,6 @@ void Cty_WriteScriptGoogleGeochart (void); void Cty_PutParCtyOrder (void); void Cty_EditCountries (void); void Cty_GetBasicListOfCountries (void); -void Cty_FreeListCountries (void); void Cty_WriteSelectorOfCountry (void); void Cty_WriteCountryName (long CtyCod); bool Cty_GetBasicCountryDataByCod (struct Hie_Node *Cty); diff --git a/swad_course.c b/swad_course.c index a8cebb6be..27f071f60 100644 --- a/swad_course.c +++ b/swad_course.c @@ -711,7 +711,7 @@ void Crs_ShowCrssOfCurrentDeg (void) Crs_ListCourses (); /***** Free list of courses in this degree *****/ - Crs_FreeListCoursesInCurrentDegree (); + Hie_FreeList (HieLvl_DEG); } /*****************************************************************************/ @@ -746,20 +746,6 @@ static void Crs_GetListCrssInCurrentDeg (void) DB_FreeMySQLResult (&mysql_res); } -/*****************************************************************************/ -/********************* Free list of courses in this degree *******************/ -/*****************************************************************************/ - -void Crs_FreeListCoursesInCurrentDegree (void) - { - if (Gbl.Hierarchy.List[HieLvl_DEG].Lst) - { - /***** Free memory used by the list of courses in degree *****/ - free (Gbl.Hierarchy.List[HieLvl_DEG].Lst); - Gbl.Hierarchy.List[HieLvl_DEG].Lst = NULL; - } - } - /*****************************************************************************/ /********************** Write selector of my coursess ************************/ /*****************************************************************************/ @@ -1070,10 +1056,10 @@ static void Crs_EditCoursesInternal (void) Box_BoxEnd (); /***** Free list of courses in this degree *****/ - Crs_FreeListCoursesInCurrentDegree (); + Hie_FreeList (HieLvl_DEG); /***** Free list of degrees in this center *****/ - Deg_FreeListDegs (&Gbl.Hierarchy.List[HieLvl_CTR]); + Hie_FreeList (HieLvl_CTR); } /*****************************************************************************/ diff --git a/swad_course.h b/swad_course.h index fa6f9232b..16bf96ef4 100644 --- a/swad_course.h +++ b/swad_course.h @@ -73,7 +73,6 @@ unsigned Crs_GetCachedNumCrssWithUsrs (Rol_Role_t Role); void Crs_WriteSelectorOfCourse (void); void Crs_ShowCrssOfCurrentDeg (void); -void Crs_FreeListCoursesInCurrentDegree (void); void Crs_WriteSelectorMyCoursesInBreadcrumb (void); void Crs_EditCourses (void); diff --git a/swad_course_config.c b/swad_course_config.c index 32a2c6ed2..a2e070993 100644 --- a/swad_course_config.c +++ b/swad_course_config.c @@ -236,7 +236,7 @@ static void CrsCfg_Degree (bool PrintView,bool PutForm) Frm_EndForm (); /* Free list of degrees of the current center */ - Deg_FreeListDegs (&Gbl.Hierarchy.List[HieLvl_CTR]); + Hie_FreeList (HieLvl_CTR); } else // I can not move course to another degree { diff --git a/swad_degree.c b/swad_degree.c index 533d5b9ae..770948cc3 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -306,8 +306,8 @@ void Deg_ShowDegsOfCurrentCtr (void) Deg_ListDegrees (); /***** Free list of degrees and centers *****/ - Deg_FreeListDegs (&Gbl.Hierarchy.List[HieLvl_CTR]); - Ctr_FreeListCenters (); + Hie_FreeList (HieLvl_CTR); + Hie_FreeList (HieLvl_INS); } /*****************************************************************************/ @@ -1027,7 +1027,7 @@ void Deg_GetListDegsInCurrentCtr (void) /*************************** Free list of degrees ****************************/ /*****************************************************************************/ -void Deg_FreeListDegs (struct Hie_List *Degs) +void Deg_FreeListAllDegsWithStds (struct Hie_List *Degs) { if (Degs->Lst) { diff --git a/swad_degree.h b/swad_degree.h index 010dbaf19..747ddb2d1 100644 --- a/swad_degree.h +++ b/swad_degree.h @@ -64,7 +64,7 @@ void Deg_PutIconToViewDegrees (void); void Deg_GetListAllDegsWithStds (struct Hie_List *Degs); void Deg_GetListDegsInCurrentCtr (void); -void Deg_FreeListDegs (struct Hie_List *Degs); +void Deg_FreeListAllDegsWithStds (struct Hie_List *Degs); void Deg_ReceiveFormReqDeg (void); void Deg_ReceiveFormNewDeg (void); diff --git a/swad_degree_config.c b/swad_degree_config.c index 16fd1cd78..07412223c 100644 --- a/swad_degree_config.c +++ b/swad_degree_config.c @@ -231,7 +231,7 @@ static void DegCfg_Center (bool PrintView,bool PutForm) Frm_EndForm (); /* Free list of centers */ - Ctr_FreeListCenters (); + Hie_FreeList (HieLvl_INS); } else // I can not move degree to another center { diff --git a/swad_department.c b/swad_department.c index 2b6e20861..074ea6b2c 100644 --- a/swad_department.c +++ b/swad_department.c @@ -338,7 +338,7 @@ static void Dpt_EditDepartmentsInternal (void) Dpt_FreeListDepartments (&Departments); /***** Free list of institutions *****/ - Ins_FreeListInstitutions (); + Hie_FreeList (HieLvl_CTY); } /*****************************************************************************/ diff --git a/swad_global.c b/swad_global.c index 56c138e21..7c57dd422 100644 --- a/swad_global.c +++ b/swad_global.c @@ -278,11 +278,11 @@ void Gbl_Cleanup (void) Rec_FreeListFields (); Grp_FreeListGrpTypesAndGrps (); Grp_FreeListCodSelectedGrps (); - Crs_FreeListCoursesInCurrentDegree (); - Deg_FreeListDegs (&Gbl.Hierarchy.List[HieLvl_CTR]); - Ins_FreeListInstitutions (); - Ctr_FreeListCenters (); - Cty_FreeListCountries (); + Hie_FreeList (HieLvl_DEG); + Hie_FreeList (HieLvl_CTR); + Hie_FreeList (HieLvl_INS); + Hie_FreeList (HieLvl_CTY); + Hie_FreeList (HieLvl_SYS); for (Role = (Rol_Role_t) 0; Role <= (Rol_Role_t) (Rol_NUM_ROLES - 1); diff --git a/swad_hierarchy.c b/swad_hierarchy.c index bd26a5f88..d980b65df 100644 --- a/swad_hierarchy.c +++ b/swad_hierarchy.c @@ -929,6 +929,21 @@ Hie_Order_t Hie_GetParHieOrder (void) (unsigned long) Hie_ORDER_DEFAULT); } +/*****************************************************************************/ +/**************************** Free list of centers ***************************/ +/*****************************************************************************/ + +void Hie_FreeList (HieLvl_Level_t Level) + { + if (Gbl.Hierarchy.List[Level].Lst) + { + /***** Free memory used by the list of child nodes *****/ + free (Gbl.Hierarchy.List[Level].Lst); + Gbl.Hierarchy.List[Level].Lst = NULL; + Gbl.Hierarchy.List[Level].Num = 0; + } + } + /*****************************************************************************/ /********* Get and show stats about hierarchy ***********/ /********* (countries, institutions, centers, degrees and courses) ***********/ diff --git a/swad_hierarchy.h b/swad_hierarchy.h index d155a4bd2..46563dc07 100644 --- a/swad_hierarchy.h +++ b/swad_hierarchy.h @@ -62,6 +62,8 @@ void Hie_PutParOtherHieCod (void *HieCod); Hie_Order_t Hie_GetParHieOrder (void); +void Hie_FreeList (HieLvl_Level_t Level); + //-------------------------------- Figures ------------------------------------ void Hie_GetAndShowHierarchyStats (void); diff --git a/swad_institution.c b/swad_institution.c index ed61a2965..a75c1512a 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -280,7 +280,7 @@ void Ins_ShowInssOfCurrentCty (void) Ins_ListInstitutions (); /***** Free list of institutions *****/ - Ins_FreeListInstitutions (); + Hie_FreeList (HieLvl_CTY); } } @@ -542,7 +542,7 @@ static void Ins_EditInstitutionsInternal (void) Box_BoxEnd (); /***** Free list of institutions *****/ - Ins_FreeListInstitutions (); + Hie_FreeList (HieLvl_CTY); } /*****************************************************************************/ @@ -794,21 +794,6 @@ void Ins_GetShrtNameAndCtyOfInstitution (struct Hie_Node *Ins, Cns_HIERARCHY_MAX_BYTES_FULL_NAME); } -/*****************************************************************************/ -/************************* Free list of institutions *************************/ -/*****************************************************************************/ - -void Ins_FreeListInstitutions (void) - { - if (Gbl.Hierarchy.List[HieLvl_CTY].Lst) - { - /***** Free memory used by the list of institutions *****/ - free (Gbl.Hierarchy.List[HieLvl_CTY].Lst); - Gbl.Hierarchy.List[HieLvl_CTY].Num = 0; - Gbl.Hierarchy.List[HieLvl_CTY].Lst = NULL; - } - } - /*****************************************************************************/ /************************ Write selector of institution **********************/ /*****************************************************************************/ diff --git a/swad_institution.h b/swad_institution.h index 1c50d4027..4874e6191 100644 --- a/swad_institution.h +++ b/swad_institution.h @@ -58,7 +58,6 @@ void Ins_FlushCacheFullNameAndCtyOfInstitution (void); void Ins_GetShrtNameAndCtyOfInstitution (struct Hie_Node *Ins, char CtyName[Cns_HIERARCHY_MAX_BYTES_FULL_NAME + 1]); -void Ins_FreeListInstitutions (void); void Ins_WriteSelectorOfInstitution (void); void Ins_RemoveInstitution (void); diff --git a/swad_photo.c b/swad_photo.c index 99ad6ca24..33c3a1657 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -2070,7 +2070,7 @@ static void Pho_PutLinkToCalculateDegreeStats (const struct Pho_DegPhotos *DegPh HTM_DIV_End (); /***** Free list of all degrees with students *****/ - Deg_FreeListDegs (&Degs); + Deg_FreeListAllDegsWithStds (&Degs); } } diff --git a/swad_record.c b/swad_record.c index 57da32729..91601cb2b 100644 --- a/swad_record.c +++ b/swad_record.c @@ -3859,7 +3859,7 @@ static void Rec_ShowFormMyInsCtrDpt (bool IAmATeacher) HTM_TD_Begin ("class=\"REC_C2_BOT LM\""); /* Get list of institutions in this country */ - Ins_FreeListInstitutions (); + Hie_FreeList (HieLvl_CTY); if (Gbl.Usrs.Me.UsrDat.InsCtyCod > 0) Ins_GetBasicListOfInstitutions (Gbl.Usrs.Me.UsrDat.InsCtyCod); @@ -3911,7 +3911,7 @@ static void Rec_ShowFormMyInsCtrDpt (bool IAmATeacher) HTM_TD_Begin ("class=\"REC_C2_BOT LM\""); /* Get list of centers in this institution */ - Ctr_FreeListCenters (); + Hie_FreeList (HieLvl_INS); if (Gbl.Usrs.Me.UsrDat.InsCod > 0) Ctr_GetBasicListOfCenters (Gbl.Usrs.Me.UsrDat.InsCod);