diff --git a/swad_banner.c b/swad_banner.c index 6e6066ed..bf649bd5 100644 --- a/swad_banner.c +++ b/swad_banner.c @@ -649,14 +649,13 @@ static void Ban_RenameBanner (struct Ban_Banner *Ban, /* Write message to show the change made */ Ale_CreateAlert (Ale_SUCCESS,NULL, - Txt_The_banner_X_has_been_renamed_as_Y, + Txt_The_banner_X_has_been_renamed_as_Y, CurrentName[ShrtOrFullName],NewName); } } else // The same name /* Write warning message */ - Ale_CreateAlert (Ale_INFO,NULL, - Txt_The_name_X_has_not_changed, + Ale_CreateAlert (Ale_INFO,NULL,Txt_The_name_X_has_not_changed, CurrentName[ShrtOrFullName]); } @@ -882,7 +881,7 @@ void Ban_ReceiveFormNewBanner (void) if (Ban->ShrtName[0] && Ban->FullName[0]) // If there's a banner name { - /***** If name of banner was in database... *****/ + /***** If name of banner was not in database... *****/ if (!Nam_CheckIfNameExists (Ban_DB_CheckIfBannerNameExists,Names,-1L, -1L,0)) // Unused { @@ -892,7 +891,7 @@ void Ban_ReceiveFormNewBanner (void) else if (!Ban->WWW[0]) Ale_CreateAlert (Ale_WARNING,NULL, Txt_You_must_specify_the_web_address); - else // Add new banner to database + else { Ban_DB_CreateBanner (Ban); Ale_CreateAlert (Ale_SUCCESS,Txt_Created_new_banner_X, diff --git a/swad_banner_database.c b/swad_banner_database.c index 505146d2..332ed025 100644 --- a/swad_banner_database.c +++ b/swad_banner_database.c @@ -114,7 +114,6 @@ unsigned Ban_DB_GetBannerDataByCod (MYSQL_RES **mysql_res,long BanCod) /********************* Check if the name of banner exists ********************/ /*****************************************************************************/ -// bool Ban_DB_CheckIfBannerNameExists (const char *FldName,const char *Name,long BanCod) bool Ban_DB_CheckIfBannerNameExists (const char *FldName,const char *Name,long Cod, __attribute__((unused)) long PrtCod, __attribute__((unused)) unsigned Year) diff --git a/swad_building.c b/swad_building.c index aa1a8834..620147db 100644 --- a/swad_building.c +++ b/swad_building.c @@ -531,7 +531,7 @@ static void Bld_RenameBuilding (Nam_ShrtOrFullName_t ShrtOrFullName) extern const char *Nam_ParShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; extern unsigned Nam_MaxBytesShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_building_X_already_exists; + extern const char *Txt_X_already_exists; extern const char *Txt_The_building_X_has_been_renamed_as_Y; extern const char *Txt_The_name_X_has_not_changed; char *CurrentName[Nam_NUM_SHRT_FULL_NAMES] = @@ -560,10 +560,9 @@ static void Bld_RenameBuilding (Nam_ShrtOrFullName_t ShrtOrFullName) { /***** If building was in database... *****/ if (Bld_DB_CheckIfBuildingNameExists (Nam_ParShrtOrFullName[ShrtOrFullName], - NewName,Bld_EditingBuilding->BldCod)) - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_building_X_already_exists, - NewName); + NewName,Bld_EditingBuilding->BldCod, + -1L,0)) // Unused + Ale_CreateAlert (Ale_WARNING,NULL,Txt_X_already_exists,NewName); else { /* Update the table changing old name by new name */ @@ -722,11 +721,7 @@ static void Bld_PutHeadBuildings (void) void Bld_ReceiveFormNewBuilding (void) { - extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_building_X_already_exists; extern const char *Txt_Created_new_building_X; - Nam_ShrtOrFullName_t ShrtOrFullName; - bool Exists; char *Names[Nam_NUM_SHRT_FULL_NAMES] = { [Nam_SHRT_NAME] = Bld_EditingBuilding->ShrtName, @@ -746,19 +741,9 @@ void Bld_ReceiveFormNewBuilding (void) if (Bld_EditingBuilding->ShrtName[0] && Bld_EditingBuilding->FullName[0]) // If there's a building name { - /***** If name of building was in database... *****/ - for (ShrtOrFullName = Nam_SHRT_NAME, Exists = false; - ShrtOrFullName <= Nam_FULL_NAME && !Exists; - ShrtOrFullName++) - if (Bld_DB_CheckIfBuildingNameExists (Nam_FldShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName],-1L)) - { - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_building_X_already_exists, - Names[ShrtOrFullName]); - Exists = true; - } - if (!Exists) // Add new building to database + /***** If name of building was not in database... *****/ + if (!Nam_CheckIfNameExists (Bld_DB_CheckIfBuildingNameExists,Names,-1L, + -1L,0)) // Unused { Bld_DB_CreateBuilding (Bld_EditingBuilding); Ale_CreateAlert (Ale_SUCCESS,NULL,Txt_Created_new_building_X, diff --git a/swad_building_database.c b/swad_building_database.c index 75b055c7..a0d5fdd5 100644 --- a/swad_building_database.c +++ b/swad_building_database.c @@ -116,7 +116,9 @@ unsigned Bld_DB_GetBuildingDataByCod (MYSQL_RES **mysql_res,long BldCod) /******************** Check if the name of building exists *******************/ /*****************************************************************************/ -bool Bld_DB_CheckIfBuildingNameExists (const char *FldName,const char *Name,long BldCod) +bool Bld_DB_CheckIfBuildingNameExists (const char *FldName,const char *Name,long Cod, + __attribute__((unused)) long PrtCod, + __attribute__((unused)) unsigned Year) { return DB_QueryEXISTS ("can not check if the name of a building already existed", @@ -128,7 +130,7 @@ bool Bld_DB_CheckIfBuildingNameExists (const char *FldName,const char *Name,long " AND BldCod<>%ld)", Gbl.Hierarchy.Node[Hie_CTR].HieCod, FldName,Name, - BldCod); + Cod); } diff --git a/swad_building_database.h b/swad_building_database.h index e1a34a59..55a0d078 100644 --- a/swad_building_database.h +++ b/swad_building_database.h @@ -41,7 +41,9 @@ unsigned Bld_DB_GetListBuildings (MYSQL_RES **mysql_res, Bld_WhichData_t WhichData, Bld_Order_t SelectedOrder); unsigned Bld_DB_GetBuildingDataByCod (MYSQL_RES **mysql_res,long BldCod); -bool Bld_DB_CheckIfBuildingNameExists (const char *FldName,const char *Name,long BldCod); +bool Bld_DB_CheckIfBuildingNameExists (const char *FldName,const char *Name,long Cod, + __attribute__((unused)) long PrtCod, + __attribute__((unused)) unsigned Year); void Bld_DB_UpdateBuildingName (long BldCod,const char *FldName,const char *NewBuildingName); diff --git a/swad_center.c b/swad_center.c index cd038098..eddbf8d4 100644 --- a/swad_center.c +++ b/swad_center.c @@ -1064,7 +1064,7 @@ void Ctr_RenameCenter (struct Hie_Node *Ctr,Nam_ShrtOrFullName_t ShrtOrFullName) extern const char *Nam_ParShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; extern unsigned Nam_MaxBytesShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_center_X_already_exists; + extern const char *Txt_X_already_exists; extern const char *Txt_The_center_X_has_been_renamed_as_Y; extern const char *Txt_The_name_X_has_not_changed; char *CurrentName[Nam_NUM_SHRT_FULL_NAMES] = @@ -1093,10 +1093,9 @@ void Ctr_RenameCenter (struct Hie_Node *Ctr,Nam_ShrtOrFullName_t ShrtOrFullName) /***** If degree was in database... *****/ if (Ctr_DB_CheckIfCtrNameExistsInIns (Nam_ParShrtOrFullName[ShrtOrFullName], NewName,Ctr->HieCod, - Gbl.Hierarchy.Node[Hie_INS].HieCod)) - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_center_X_already_exists, - NewName); + Gbl.Hierarchy.Node[Hie_INS].HieCod, + 0)) // Unused + Ale_CreateAlert (Ale_WARNING,NULL,Txt_X_already_exists,NewName); else { /* Update the table changing old name by new name */ @@ -1475,16 +1474,12 @@ void Ctr_ReceiveFormNewCtr (void) static void Ctr_ReceiveFormRequestOrCreateCtr (Hie_Status_t Status) { - extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_center_X_already_exists; extern const char *Txt_Created_new_center_X; - Nam_ShrtOrFullName_t ShrtOrFullName; char *Names[Nam_NUM_SHRT_FULL_NAMES] = { [Nam_SHRT_NAME] = Ctr_EditingCtr->ShrtName, [Nam_FULL_NAME] = Ctr_EditingCtr->FullName, }; - bool Exists; /***** Get parameters from form *****/ /* Set center institution */ @@ -1505,19 +1500,9 @@ static void Ctr_ReceiveFormRequestOrCreateCtr (Hie_Status_t Status) if (Ctr_EditingCtr->WWW[0]) { /***** If name of center was in database... *****/ - for (ShrtOrFullName = Nam_SHRT_NAME, Exists = false; - ShrtOrFullName <= Nam_FULL_NAME && !Exists; - ShrtOrFullName++) - if (Ctr_DB_CheckIfCtrNameExistsInIns (Nam_FldShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName],-1L, - Gbl.Hierarchy.Node[Hie_INS].HieCod)) - { - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_center_X_already_exists, - Names[ShrtOrFullName]); - Exists = true; - } - if (!Exists) // Add new center to database + if (!Nam_CheckIfNameExists (Ctr_DB_CheckIfCtrNameExistsInIns,Names, + -1L,Gbl.Hierarchy.Node[Hie_INS].HieCod, + 0)) // Unused { Ctr_EditingCtr->HieCod = Ctr_DB_CreateCenter (Ctr_EditingCtr,Status); Ale_CreateAlert (Ale_SUCCESS,NULL,Txt_Created_new_center_X, diff --git a/swad_center_config.c b/swad_center_config.c index b252d312..ece2d8ef 100644 --- a/swad_center_config.c +++ b/swad_center_config.c @@ -1015,13 +1015,9 @@ void CtrCfg_ChangeCtrPhotoAttr (void) void CtrCfg_ChangeCtrIns (void) { - extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_center_X_already_exists; extern const char *Txt_The_center_X_has_been_moved_to_the_institution_Y; struct Hie_Node NewIns; - Nam_ShrtOrFullName_t ShrtOrFullName; - bool Exists; - char *Name[Nam_NUM_SHRT_FULL_NAMES] = + char *Names[Nam_NUM_SHRT_FULL_NAMES] = { [Nam_SHRT_NAME] = Gbl.Hierarchy.Node[Hie_CTR].ShrtName, [Nam_FULL_NAME] = Gbl.Hierarchy.Node[Hie_CTR].FullName, @@ -1037,20 +1033,9 @@ void CtrCfg_ChangeCtrIns (void) Ins_GetInstitDataByCod (&NewIns); /***** Check if it already exists a center with the same name in the new institution *****/ - for (ShrtOrFullName = Nam_SHRT_NAME, Exists = false; - ShrtOrFullName <= Nam_FULL_NAME && !Exists; - ShrtOrFullName++) - if (Ctr_DB_CheckIfCtrNameExistsInIns (Nam_FldShrtOrFullName[ShrtOrFullName], - Name[ShrtOrFullName], - Gbl.Hierarchy.Node[Hie_CTR].HieCod, - NewIns.HieCod)) - { - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_center_X_already_exists, - Name[ShrtOrFullName]); - Exists = true; - } - if (!Exists) + if (!Nam_CheckIfNameExists (Ctr_DB_CheckIfCtrNameExistsInIns,Names, + Gbl.Hierarchy.Node[Hie_CTR].HieCod,NewIns.HieCod, + 0)) // Unused { /***** Update institution in table of centers *****/ Ctr_DB_UpdateCtrIns (Gbl.Hierarchy.Node[Hie_CTR].HieCod,NewIns.HieCod); diff --git a/swad_center_database.c b/swad_center_database.c index 57bb5eb8..38c62733 100644 --- a/swad_center_database.c +++ b/swad_center_database.c @@ -297,7 +297,8 @@ unsigned Ctr_DB_GetPhotoAttribution (MYSQL_RES **mysql_res,long CtrCod) /*****************************************************************************/ bool Ctr_DB_CheckIfCtrNameExistsInIns (const char *FldName,const char *Name, - long CtrCod,long InsCod) + long Cod,long PrtCod, + __attribute__((unused)) unsigned Year) { return DB_QueryEXISTS ("can not check if the name of a center already existed", @@ -307,10 +308,9 @@ bool Ctr_DB_CheckIfCtrNameExistsInIns (const char *FldName,const char *Name, " WHERE InsCod=%ld" " AND %s='%s'" " AND CtrCod<>%ld)", - InsCod, - FldName, - Name, - CtrCod); + PrtCod, + FldName,Name, + Cod); } /*****************************************************************************/ diff --git a/swad_center_database.h b/swad_center_database.h index 46e5df97..252f1da6 100644 --- a/swad_center_database.h +++ b/swad_center_database.h @@ -51,7 +51,8 @@ long Ctr_DB_GetInsCodOfCenterByCod (long CtrCod); void Ctr_DB_GetShortNameOfCenterByCod (long CtrCod,char ShrtName[Nam_MAX_BYTES_SHRT_NAME + 1]); unsigned Ctr_DB_GetPhotoAttribution (MYSQL_RES **mysql_res,long CtrCod); bool Ctr_DB_CheckIfCtrNameExistsInIns (const char *FldName,const char *Name, - long CtrCod,long InsCod); + long Cod,long PrtCod, + __attribute__((unused)) unsigned Year); unsigned Ctr_DB_SearchCtrs (MYSQL_RES **mysql_res, const char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1], diff --git a/swad_changelog.h b/swad_changelog.h index 3caca324..2acf40b8 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -633,12 +633,13 @@ Me sale este error, no s "can npt create received message (duplicated entry '243218-2160773' for key 'UsrCod_MsgCod') */ -#define Log_PLATFORM_VERSION "SWAD 23.33.1 (2023-10-10)" +#define Log_PLATFORM_VERSION "SWAD 23.33.2 (2023-10-10)" #define CSS_FILE "swad23.25.2.css" #define JS_FILE "swad22.49.js" /* // TODO: Donde aparezca Txt_X_already_exists cambiar por la función nueva Nam_... + Version 23.33.2: Oct 10, 2023 Code refactoring in short and full names. Not finished. (335661 lines) Version 23.33.1: Oct 10, 2023 Code refactoring in short and full names. Not finished. (335930 lines) Version 23.33: Oct 10, 2023 Code refactoring in short and full names. (335919 lines) Version 23.32: Oct 10, 2023 Code refactoring in short and full names. (336110 lines) diff --git a/swad_course.c b/swad_course.c index a566b685..2ba4c104 100644 --- a/swad_course.c +++ b/swad_course.c @@ -1248,13 +1248,9 @@ void Crs_ReceiveFormNewCrs (void) static void Crs_ReceiveFormRequestOrCreateCrs (Hie_Status_t Status) { - extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_course_X_already_exists; extern const char *Txt_Created_new_course_X; extern const char *Txt_The_year_X_is_not_allowed; extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE]; - Nam_ShrtOrFullName_t ShrtOrFullName; - bool Exists; char *Names[Nam_NUM_SHRT_FULL_NAMES] = { [Nam_SHRT_NAME] = Crs_EditingCrs->ShrtName, @@ -1275,21 +1271,10 @@ static void Crs_ReceiveFormRequestOrCreateCrs (Hie_Status_t Status) if (Crs_EditingCrs->ShrtName[0] && Crs_EditingCrs->FullName[0]) // If there's a course name { - /***** If name of course was in database... *****/ - for (ShrtOrFullName = Nam_SHRT_NAME, Exists = false; - ShrtOrFullName <= Nam_FULL_NAME && !Exists; - ShrtOrFullName++) - if (Crs_DB_CheckIfCrsNameExistsInYearOfDeg (Nam_FldShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName], - -1L,Crs_EditingCrs->PrtCod, - Crs_EditingCrs->Specific.Year)) - { - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_course_X_already_exists, - Names[ShrtOrFullName]); - Exists = true; - } - if (!Exists) // Add new requested course to database + /***** If name of course was not in database... *****/ + if (!Nam_CheckIfNameExists (Crs_DB_CheckIfCrsNameExistsInYearOfDeg,Names, + -1L,Crs_EditingCrs->PrtCod, + Crs_EditingCrs->Specific.Year)) { Crs_DB_CreateCourse (Crs_EditingCrs,Status); Ale_CreateAlert (Ale_SUCCESS,NULL,Txt_Created_new_course_X, @@ -1612,15 +1597,11 @@ void Crs_ChangeInsCrsCod (void) void Crs_ChangeCrsYear (void) { - extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_course_X_already_exists_in_year_Y; extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE]; extern const char *Txt_The_year_of_the_course_X_has_changed; extern const char *Txt_The_year_X_is_not_allowed; char YearStr[2 + 1]; unsigned NewYear; - Nam_ShrtOrFullName_t ShrtOrFullName; - bool Exists; char *Names[Nam_NUM_SHRT_FULL_NAMES] = { [Nam_SHRT_NAME] = Crs_EditingCrs->ShrtName, @@ -1645,20 +1626,9 @@ void Crs_ChangeCrsYear (void) if (NewYear <= Deg_MAX_YEARS_PER_DEGREE) // If year is valid { - /***** If name of course was in database in the new year... *****/ - for (ShrtOrFullName = Nam_SHRT_NAME, Exists = false; - ShrtOrFullName <= Nam_FULL_NAME && !Exists; - ShrtOrFullName++) - { - if (Crs_DB_CheckIfCrsNameExistsInYearOfDeg (Nam_FldShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName], - -1L,Crs_EditingCrs->PrtCod,NewYear)) - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_course_X_already_exists_in_year_Y, - Names[ShrtOrFullName],Txt_YEAR_OF_DEGREE[NewYear]); - Exists = true; - } - if (!Exists) // Update year in database + /***** If name of course was not in database in the new year... *****/ + if (!Nam_CheckIfNameExists (Crs_DB_CheckIfCrsNameExistsInYearOfDeg,Names, + -1L,Crs_EditingCrs->PrtCod,NewYear)) { /***** Update year in table of courses *****/ Crs_UpdateCrsYear (Crs_EditingCrs,NewYear); @@ -1735,7 +1705,7 @@ void Crs_RenameCourse (struct Hie_Node *Crs,Nam_ShrtOrFullName_t ShrtOrFullName) extern const char *Nam_ParShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; extern unsigned Nam_MaxBytesShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_course_X_already_exists; + extern const char *Txt_X_already_exists; extern const char *Txt_The_course_X_has_been_renamed_as_Y; extern const char *Txt_The_name_X_has_not_changed; char *CurrentName[Nam_NUM_SHRT_FULL_NAMES] = @@ -1765,9 +1735,7 @@ void Crs_RenameCourse (struct Hie_Node *Crs,Nam_ShrtOrFullName_t ShrtOrFullName) if (Crs_DB_CheckIfCrsNameExistsInYearOfDeg (Nam_ParShrtOrFullName[ShrtOrFullName], NewName,Crs->HieCod, Crs->PrtCod,Crs->Specific.Year)) - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_course_X_already_exists, - NewName); + Ale_CreateAlert (Ale_WARNING,NULL,Txt_X_already_exists,NewName); else { /* Update the table changing old name by new name */ diff --git a/swad_course_config.c b/swad_course_config.c index 23825221..d7d370b8 100644 --- a/swad_course_config.c +++ b/swad_course_config.c @@ -458,13 +458,9 @@ static void CrsCfg_Indicators (void) void CrsCfg_ChangeCrsDeg (void) { - extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_In_the_year_X_of_the_degree_Y_already_existed_a_course_with_the_name_Z; extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE]; extern const char *Txt_The_course_X_has_been_moved_to_the_degree_Y; struct Hie_Node NewDeg; - Nam_ShrtOrFullName_t ShrtOrFullName; - bool Exists; char *Names[Nam_NUM_SHRT_FULL_NAMES] = { [Nam_SHRT_NAME] = Gbl.Hierarchy.Node[Hie_CRS].ShrtName, @@ -480,21 +476,10 @@ void CrsCfg_ChangeCrsDeg (void) /***** Get data of new degree *****/ Deg_GetDegreeDataByCod (&NewDeg); - /***** If name of course was in database in the new degree... *****/ - for (ShrtOrFullName = Nam_SHRT_NAME, Exists = false; - ShrtOrFullName <= Nam_FULL_NAME && !Exists; - ShrtOrFullName++) - if (Crs_DB_CheckIfCrsNameExistsInYearOfDeg (Nam_FldShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName],-1L, - NewDeg.HieCod,Gbl.Hierarchy.Node[Hie_CRS].Specific.Year)) - { - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_In_the_year_X_of_the_degree_Y_already_existed_a_course_with_the_name_Z, - Txt_YEAR_OF_DEGREE[Gbl.Hierarchy.Node[Hie_CRS].Specific.Year], - NewDeg.FullName,Names[ShrtOrFullName]); - Exists = true; - } - if (!Exists) // Update degree in database + /***** If name of course was not in database in the new degree... *****/ + if (!Nam_CheckIfNameExists (Crs_DB_CheckIfCrsNameExistsInYearOfDeg,Names, + -1L,NewDeg.HieCod, + Gbl.Hierarchy.Node[Hie_CRS].Specific.Year)) { /***** Update degree in table of courses *****/ Crs_DB_UpdateCrsDeg (Gbl.Hierarchy.Node[Hie_CRS].HieCod,NewDeg.HieCod); @@ -533,15 +518,11 @@ void CrsCfg_RenameCourseFull (void) void CrsCfg_ChangeCrsYear (void) { - extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_course_X_already_exists_in_year_Y; extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE]; extern const char *Txt_The_year_of_the_course_X_has_changed; extern const char *Txt_The_year_X_is_not_allowed; char YearStr[2 + 1]; unsigned NewYear; - Nam_ShrtOrFullName_t ShrtOrFullName; - bool Exists; char *Names[Nam_NUM_SHRT_FULL_NAMES] = { [Nam_SHRT_NAME] = Gbl.Hierarchy.Node[Hie_CRS].ShrtName, @@ -554,20 +535,9 @@ void CrsCfg_ChangeCrsYear (void) if (NewYear <= Deg_MAX_YEARS_PER_DEGREE) // If year is valid { - /***** If name of course was in database in the new year... *****/ - for (ShrtOrFullName = Nam_SHRT_NAME, Exists = false; - ShrtOrFullName <= Nam_FULL_NAME && !Exists; - ShrtOrFullName++) - if (Crs_DB_CheckIfCrsNameExistsInYearOfDeg (Nam_FldShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName],-1L, - Gbl.Hierarchy.Node[Hie_CRS].PrtCod,NewYear)) - { - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_course_X_already_exists_in_year_Y, - Names[ShrtOrFullName],Txt_YEAR_OF_DEGREE[NewYear]); - Exists = true; - } - if (!Exists) // Update year in database + /***** If name of course was not in database in the new year... *****/ + if (!Nam_CheckIfNameExists (Crs_DB_CheckIfCrsNameExistsInYearOfDeg,Names, + -1L,Gbl.Hierarchy.Node[Hie_CRS].PrtCod,NewYear)) { /***** Update year in table of courses *****/ Crs_UpdateCrsYear (&Gbl.Hierarchy.Node[Hie_CRS],NewYear); diff --git a/swad_course_database.c b/swad_course_database.c index 6d0f9fff..d06336f2 100644 --- a/swad_course_database.c +++ b/swad_course_database.c @@ -213,7 +213,7 @@ bool Crs_DB_CheckIfCrsCodExists (long CrsCod) /*****************************************************************************/ bool Crs_DB_CheckIfCrsNameExistsInYearOfDeg (const char *FldName,const char *Name, - long CrsCod,long DegCod,unsigned Year) + long Cod,long PrtCod,unsigned Year) { return DB_QueryEXISTS ("can not check if the name of a course already existed", @@ -224,11 +224,10 @@ bool Crs_DB_CheckIfCrsNameExistsInYearOfDeg (const char *FldName,const char *Nam " AND Year=%u" " AND %s='%s'" " AND CrsCod<>%ld)", - DegCod, + PrtCod, Year, - FldName, - Name, - CrsCod); + FldName,Name, + Cod); } /*****************************************************************************/ diff --git a/swad_course_database.h b/swad_course_database.h index abb7d087..6f513dfa 100644 --- a/swad_course_database.h +++ b/swad_course_database.h @@ -47,7 +47,7 @@ void Crs_DB_GetShortNamesByCod (long CrsCod, char DegShortName[Nam_MAX_BYTES_SHRT_NAME + 1]); bool Crs_DB_CheckIfCrsCodExists (long CrsCod); bool Crs_DB_CheckIfCrsNameExistsInYearOfDeg (const char *FldName,const char *Name, - long CrsCod,long DegCod,unsigned Year); + long Cod,long PrtCod,unsigned Year); unsigned Crs_DB_GetCrssOfAUsr (MYSQL_RES **mysql_res,long UsrCod,Rol_Role_t Role); unsigned Crs_DB_GetOldCrss (MYSQL_RES **mysql_res,unsigned long SecondsWithoutAccess); diff --git a/swad_degree.c b/swad_degree.c index f8a759aa..ef46c9f1 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -1045,11 +1045,7 @@ void Deg_ReceiveFormNewDeg (void) static void Deg_ReceiveFormRequestOrCreateDeg (Hie_Status_t Status) { - extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_degree_X_already_exists; extern const char *Txt_Created_new_degree_X; - Nam_ShrtOrFullName_t ShrtOrFullName; - bool Exists; char *Names[Nam_NUM_SHRT_FULL_NAMES] = { [Nam_SHRT_NAME] = Deg_EditingDeg->ShrtName, @@ -1074,20 +1070,10 @@ static void Deg_ReceiveFormRequestOrCreateDeg (Hie_Status_t Status) { if (Deg_EditingDeg->WWW[0]) { - /***** If name of degree was in database... *****/ - for (ShrtOrFullName = Nam_SHRT_NAME, Exists = false; - ShrtOrFullName <= Nam_FULL_NAME && !Exists; - ShrtOrFullName++) - if (Deg_DB_CheckIfDegNameExistsInCtr (Nam_FldShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName], - -1L,Deg_EditingDeg->PrtCod)) - { - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_degree_X_already_exists, - Names[ShrtOrFullName]); - Exists = true; - } - if (!Exists) // Add new degree to database + /***** If name of degree was not in database... *****/ + if (!Nam_CheckIfNameExists (Deg_DB_CheckIfDegNameExistsInCtr,Names, + -1L,Deg_EditingDeg->PrtCod, + 0)) // Unused { Deg_DB_CreateDegree (Deg_EditingDeg,Status); Ale_CreateAlert (Ale_SUCCESS,NULL,Txt_Created_new_degree_X, @@ -1302,7 +1288,7 @@ void Deg_RenameDegree (struct Hie_Node *Deg,Nam_ShrtOrFullName_t ShrtOrFullName) extern const char *Nam_ParShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; extern unsigned Nam_MaxBytesShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_degree_X_already_exists; + extern const char *Txt_X_already_exists; extern const char *Txt_The_degree_X_has_been_renamed_as_Y; extern const char *Txt_The_name_X_has_not_changed; char *CurrentName[Nam_NUM_SHRT_FULL_NAMES] = @@ -1328,9 +1314,9 @@ void Deg_RenameDegree (struct Hie_Node *Deg,Nam_ShrtOrFullName_t ShrtOrFullName) { /***** If degree was in database... *****/ if (Deg_DB_CheckIfDegNameExistsInCtr (Nam_ParShrtOrFullName[ShrtOrFullName], - NewName,Deg->HieCod,Deg->PrtCod)) - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_degree_X_already_exists,NewName); + NewName,Deg->HieCod,Deg->PrtCod, + 0)) // Unused + Ale_CreateAlert (Ale_WARNING,NULL,Txt_X_already_exists,NewName); else { /* Update the table changing old name by new name */ diff --git a/swad_degree_config.c b/swad_degree_config.c index 7d6b965b..4be23ab9 100644 --- a/swad_degree_config.c +++ b/swad_degree_config.c @@ -348,12 +348,8 @@ static void DegCfg_NumCrss (void) void DegCfg_ChangeDegCtr (void) { - extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_degree_X_already_exists; extern const char *Txt_The_degree_X_has_been_moved_to_the_center_Y; struct Hie_Node NewCtr; - Nam_ShrtOrFullName_t ShrtOrFullName; - bool Exists; char *Names[Nam_NUM_SHRT_FULL_NAMES] = { [Nam_SHRT_NAME] = Gbl.Hierarchy.Node[Hie_DEG].ShrtName, @@ -369,20 +365,10 @@ void DegCfg_ChangeDegCtr (void) /***** Get data of new center *****/ Ctr_GetCenterDataByCod (&NewCtr); - /***** Check if it already exists a degree with the same name in the new center *****/ - for (ShrtOrFullName = Nam_SHRT_NAME, Exists = false; - ShrtOrFullName <= Nam_FULL_NAME && !Exists; - ShrtOrFullName++) - if (Deg_DB_CheckIfDegNameExistsInCtr (Nam_FldShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName], - Gbl.Hierarchy.Node[Hie_DEG].HieCod, - NewCtr.HieCod)) - { - Ale_CreateAlert (Ale_WARNING,Txt_The_degree_X_already_exists, - Names[ShrtOrFullName]); - Exists = true; - } - if (Exists) + /***** Check if it already existed a degree with the same name in the new center *****/ + if (!Nam_CheckIfNameExists (Deg_DB_CheckIfDegNameExistsInCtr,Names, + Gbl.Hierarchy.Node[Hie_DEG].HieCod,NewCtr.HieCod, + 0)) // Unused { /***** Update center in table of degrees *****/ Deg_DB_UpdateDegCtr (Gbl.Hierarchy.Node[Hie_DEG].HieCod,NewCtr.HieCod); diff --git a/swad_degree_database.c b/swad_degree_database.c index f19b9b0f..72e82787 100644 --- a/swad_degree_database.c +++ b/swad_degree_database.c @@ -517,7 +517,8 @@ unsigned Deg_DB_GetDegsWithStds (MYSQL_RES **mysql_res) /*****************************************************************************/ bool Deg_DB_CheckIfDegNameExistsInCtr (const char *FldName,const char *Name, - long DegCod,long CtrCod) + long Cod,long PrtCod, + __attribute__((unused)) unsigned Year) { return DB_QueryEXISTS ("can not check if the name of a degree already existed", @@ -527,9 +528,9 @@ bool Deg_DB_CheckIfDegNameExistsInCtr (const char *FldName,const char *Name, " WHERE CtrCod=%ld" " AND %s='%s'" " AND DegCod<>%ld)", - CtrCod, + PrtCod, FldName,Name, - DegCod); + Cod); } /*****************************************************************************/ diff --git a/swad_degree_database.h b/swad_degree_database.h index 15999de3..bb4b50d8 100644 --- a/swad_degree_database.h +++ b/swad_degree_database.h @@ -56,7 +56,8 @@ unsigned Deg_DB_GetDegsOfCurrentCtrFull (MYSQL_RES **mysql_res); unsigned Deg_DB_GetDegsWithPendingCrss (MYSQL_RES **mysql_res); unsigned Deg_DB_GetDegsWithStds (MYSQL_RES **mysql_res); bool Deg_DB_CheckIfDegNameExistsInCtr (const char *FldName,const char *Name, - long DegCod,long CtrCod); + long Cod,long PrtCod, + __attribute__((unused)) unsigned Year); unsigned Deg_DB_SearchDegs (MYSQL_RES **mysql_res, const char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1], diff --git a/swad_department.c b/swad_department.c index eecd6e47..a85ff07b 100644 --- a/swad_department.c +++ b/swad_department.c @@ -673,7 +673,7 @@ static void Dpt_RenameDepartment (Nam_ShrtOrFullName_t ShrtOrFullName) extern const char *Nam_ParShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; extern unsigned Nam_MaxBytesShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_department_X_already_exists; + extern const char *Txt_X_already_exists; extern const char *Txt_The_department_X_has_been_renamed_as_Y; extern const char *Txt_The_name_X_has_not_changed; char *CurrentName[Nam_NUM_SHRT_FULL_NAMES] = @@ -700,12 +700,12 @@ static void Dpt_RenameDepartment (Nam_ShrtOrFullName_t ShrtOrFullName) (this happens when return is pressed without changes) *****/ if (strcmp (CurrentName[ShrtOrFullName],NewName)) // Different names { - /***** If degree was in database... *****/ + /***** If name department was not in database... *****/ if (Dpt_DB_CheckIfDepartmentNameExists (Nam_ParShrtOrFullName[ShrtOrFullName], - NewName,Dpt_EditingDpt->DptCod)) - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_department_X_already_exists, - NewName); + NewName,Dpt_EditingDpt->DptCod, + -1L, // Unused + 0)) // Unused + Ale_CreateAlert (Ale_WARNING,NULL,Txt_X_already_exists,NewName); else { /* Update the table changing old name by new name */ @@ -895,11 +895,7 @@ static void Dpt_PutHeadDepartments (void) void Dpt_ReceiveFormNewDpt (void) { - extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_department_X_already_exists; extern const char *Txt_Created_new_department_X; - Nam_ShrtOrFullName_t ShrtOrFullName; - bool Exists; char *Names[Nam_NUM_SHRT_FULL_NAMES] = { [Nam_SHRT_NAME] = Dpt_EditingDpt->ShrtName, @@ -924,19 +920,11 @@ void Dpt_ReceiveFormNewDpt (void) { if (Dpt_EditingDpt->WWW[0]) { - /***** If name of department was in database... *****/ - for (ShrtOrFullName = Nam_SHRT_NAME, Exists = false; - ShrtOrFullName <= Nam_FULL_NAME && !Exists; - ShrtOrFullName++) - if (Dpt_DB_CheckIfDepartmentNameExists (Nam_FldShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName],-1L)) - { - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_department_X_already_exists, - Names[ShrtOrFullName]); - Exists = true; - } - if (!Exists) // Add new department to database + /***** If name of department was not in database... *****/ + if (!Nam_CheckIfNameExists (Dpt_DB_CheckIfDepartmentNameExists,Names, + -1L, + -1L, // Unused + 0)) // Unused { Dpt_DB_CreateDepartment (Dpt_EditingDpt); Ale_CreateAlert (Ale_SUCCESS,NULL,Txt_Created_new_department_X, diff --git a/swad_department_database.c b/swad_department_database.c index 7284e8e2..2b9b417d 100644 --- a/swad_department_database.c +++ b/swad_department_database.c @@ -151,7 +151,9 @@ unsigned Dpt_DB_GetDepartmentDataByCod (MYSQL_RES **mysql_res,long DptCod) /******************* Check if the name of department exists ******************/ /*****************************************************************************/ -bool Dpt_DB_CheckIfDepartmentNameExists (const char *FldName,const char *Name,long DptCod) +bool Dpt_DB_CheckIfDepartmentNameExists (const char *FldName,const char *Name,long Cod, + __attribute__((unused)) long PrtCod, + __attribute__((unused)) unsigned Year) { return DB_QueryEXISTS ("can not check if the department name already existed", @@ -161,7 +163,7 @@ bool Dpt_DB_CheckIfDepartmentNameExists (const char *FldName,const char *Name,lo " WHERE %s='%s'" " AND DptCod<>%ld)", FldName,Name, - DptCod); + Cod); } /*****************************************************************************/ diff --git a/swad_department_database.h b/swad_department_database.h index fa0015d7..c64dc53d 100644 --- a/swad_department_database.h +++ b/swad_department_database.h @@ -41,7 +41,9 @@ void Dpt_DB_CreateDepartment (const struct Dpt_Department *Dpt); unsigned Dpt_DB_GetListDepartments (MYSQL_RES **mysql_res, long InsCod,Dpt_Order_t SelectedOrder); unsigned Dpt_DB_GetDepartmentDataByCod (MYSQL_RES **mysql_res,long DptCod); -bool Dpt_DB_CheckIfDepartmentNameExists (const char *FldName,const char *Name,long DptCod); +bool Dpt_DB_CheckIfDepartmentNameExists (const char *FldName,const char *Name,long Cod, + __attribute__((unused)) long PrtCod, + __attribute__((unused)) unsigned Year); unsigned Dpt_DB_GetNumDepartmentsInInstitution (long InsCod); unsigned Dpt_DB_GetNumTchsCurrentInsInDepartment (long DptCod); diff --git a/swad_text.c b/swad_text.c index 59491515..b6a9deec 100644 --- a/swad_text.c +++ b/swad_text.c @@ -46840,29 +46840,6 @@ const char *Txt_The_banner_X_has_been_renamed_as_Y = // Warning: it is very impo "The banner %s has been renamed as %s."; // Çeviri lazim! #endif -const char *Txt_The_building_X_already_exists = // Warning: it is very important to include %s in the following sentences -#if L==1 // ca - "L'edifici %s ja existeix."; -#elif L==2 // de - "Das Gebäude %s wurde bereits eingegeben."; -#elif L==3 // en - "The building %s already exists."; -#elif L==4 // es - "El edificio %s ya existe."; -#elif L==5 // fr - "Le bâtiment %s existe déjà."; -#elif L==6 // gn - "El edificio %s ya existe."; // Okoteve traducción -#elif L==7 // it - "L'edificio %s già esiste."; -#elif L==8 // pl - "Budynek %s już istnieje."; -#elif L==9 // pt - "O edifício %s já existe."; -#elif L==10 // tr - "The building %s already exists."; // Çeviri lazim! -#endif - const char *Txt_The_building_X_has_been_renamed_as_Y = // Warning: it is very important to include two %s in the following sentences #if L==1 // ca "L'edifici %s ha passat a anomenar-se %s."; @@ -47001,29 +46978,6 @@ const char *Txt_The_capacity_of_room_X_is_now_Y = // Warning: it is very importa "The capacity of room %s is now %u."; // Çeviri lazim! #endif -const char *Txt_The_center_X_already_exists = // Warning: it is very important to include %s in the following sentences -#if L==1 // ca - "El centre %s ja existeix."; -#elif L==2 // de - "Das Zentrum %s existiert bereits."; -#elif L==3 // en - "The center %s already exists."; -#elif L==4 // es - "El centro %s ya existe."; -#elif L==5 // fr - "Le centre %s existe déjà."; -#elif L==6 // gn - "El centro %s ya existe."; // Okoteve traducción -#elif L==7 // it - "Il centro %s già esiste."; -#elif L==8 // pl - "Centrum %s już istnieje."; -#elif L==9 // pt - "O centro %s já existe."; -#elif L==10 // tr - "The center %s already exists."; // Çeviri lazim! -#endif - const char *Txt_The_center_X_has_been_moved_to_the_institution_Y = // Warning: it is very important to include two %s in the following sentences #if L==1 // ca "El centre %s s'ha traslladat" @@ -47360,52 +47314,6 @@ const char *Txt_The_country_of_the_institution_X_has_changed_to_Y = // Warning: " has changed to %s."; // Çeviri lazim! #endif -const char *Txt_The_course_X_already_exists = // Warning: it is very important to include %s in the following sentences -#if L==1 // ca - "L´assignatura %s ja existeix."; -#elif L==2 // de - "Die Kurs %s wurde bereits eingegeben."; -#elif L==3 // en - "The course %s already exists."; -#elif L==4 // es - "La asignatura %s ya existe."; -#elif L==5 // fr - "La matière %s existe déjà."; -#elif L==6 // gn - "La asignatura %s ya existe."; // Okoteve traducción -#elif L==7 // it - "Il corso %s già esiste."; -#elif L==8 // pl - "Kurs %s już istnieje."; -#elif L==9 // pt - "A disciplina %s já existe."; -#elif L==10 // tr - "The course %s already exists."; // Çeviri lazim! -#endif - -const char *Txt_The_course_X_already_exists_in_year_Y = // Warning: it is very important to include two %s in the following sentences -#if L==1 // ca - "L'assignatura %s ja existeix a l'any/semestre %s."; -#elif L==2 // de - "Die Kurs %s wurde bereits in Studienjahr/Semester %s eingegeben."; -#elif L==3 // en - "The course %s already exists in year/semester %s."; -#elif L==4 // es - "La asignatura %s ya existe en el año/semestre %s."; -#elif L==5 // fr - "La matière %s existe déjà en année/semestre %s."; -#elif L==6 // gn - "La asignatura %s ya existe en el año/semestre %s."; // Okoteve traducción -#elif L==7 // it - "Il corso %s esiste già nell'anno/semester %s."; -#elif L==8 // pl - "Kurs %s istnieje już na roku/semestrze %s."; -#elif L==9 // pt - "A disciplina %s já existe no ano/semestre %s."; -#elif L==10 // tr - "The course %s already exists in year/semester %s."; // Çeviri lazim! -#endif - const char *Txt_The_course_X_has_been_moved_to_the_degree_Y = // Warning: it is very important to include two %s in the following sentences #if L==1 // ca "L'assignatura %s" @@ -47541,29 +47449,6 @@ const char *Txt_The_date_time_of_opening_of_groups_has_changed = "The date/time of opening of groups has changed."; // Çeviri lazim! #endif -const char *Txt_The_degree_X_already_exists = // Warning: it is very important to include %s in the following sentences -#if L==1 // ca - "La titulació %s ja existeix."; -#elif L==2 // de - "Der Studiengang %s wurde bereits eingegeben."; -#elif L==3 // en - "The degree %s already exists."; -#elif L==4 // es - "La titulación %s ya existe."; -#elif L==5 // fr - "L'étude %s existe déjà."; -#elif L==6 // gn - "La titulación %s ya existe."; // Okoteve traducción -#elif L==7 // it - "La laurea %s già esiste."; -#elif L==8 // pl - "Stopień %s już istnieje."; -#elif L==9 // pt - "O grau %s já existe."; -#elif L==10 // tr - "The degree %s already exists."; // Çeviri lazim! -#endif - const char *Txt_The_degree_X_has_been_moved_to_the_center_Y = // Warning: it is very important to include two %s in the following sentences #if L==1 // ca "La titulació %s s'ha traslladat" @@ -47630,29 +47515,6 @@ const char *Txt_The_degree_X_has_been_renamed_as_Y = // Warning: it is very impo " has been renamed as %s."; // Çeviri lazim! #endif -const char *Txt_The_department_X_already_exists = // Warning: it is very important to include %s in the following sentences -#if L==1 // ca - "El departament %s ja existeix."; -#elif L==2 // de - "Die Abteilung %s wurde bereits eingegeben."; -#elif L==3 // en - "The department %s already exists."; -#elif L==4 // es - "El departamento %s ya existe."; -#elif L==5 // fr - "The department %s already exists."; // Besoin de traduction -#elif L==6 // gn - "El departamento %s ya existe."; // Okoteve traducción -#elif L==7 // it - "IL dipartimento %s esiste già."; -#elif L==8 // pl - "The department %s already exists."; // Potrzebujesz tlumaczenie -#elif L==9 // pt - "O departamento %s já existe."; -#elif L==10 // tr - "The department %s already exists."; // Çeviri lazim! -#endif - const char *Txt_The_department_X_has_been_renamed_as_Y = // Warning: it is very important to include two %s in the following sentences #if L==1 // ca "El departament %s"