diff --git a/Makefile b/Makefile index 76a70c7c..34ba9332 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,7 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_action_list.o \ swad_match.o swad_match_database.o swad_match_print.o \ swad_match_result.o swad_media.o swad_media_database.o swad_menu.o \ swad_message.o swad_message_database.o swad_MFU.o swad_MFU_database.o \ - swad_network.o swad_network_database.o swad_nickname.o \ + swad_name.o swad_network.o swad_network_database.o swad_nickname.o \ swad_nickname_database.o swad_notice.o swad_notice_database.o \ swad_notification.o swad_notification_database.o \ swad_pagination.o swad_parameter.o swad_parameter_code.o \ diff --git a/swad_banner.c b/swad_banner.c index bf649bd5..fc4cf4e3 100644 --- a/swad_banner.c +++ b/swad_banner.c @@ -883,7 +883,8 @@ void Ban_ReceiveFormNewBanner (void) { /***** If name of banner was not in database... *****/ if (!Nam_CheckIfNameExists (Ban_DB_CheckIfBannerNameExists,Names,-1L, - -1L,0)) // Unused + -1L, // Unused + 0)) // Unused { if (!Ban->Img[0]) Ale_CreateAlert (Ale_WARNING,NULL, diff --git a/swad_banner.h b/swad_banner.h index ae92f3e2..9eff2302 100644 --- a/swad_banner.h +++ b/swad_banner.h @@ -29,6 +29,7 @@ #include "swad_constant.h" #include "swad_hidden_visible.h" +#include "swad_name.h" #include "swad_string.h" /*****************************************************************************/ diff --git a/swad_building.c b/swad_building.c index 620147db..b742f237 100644 --- a/swad_building.c +++ b/swad_building.c @@ -743,7 +743,8 @@ void Bld_ReceiveFormNewBuilding (void) { /***** If name of building was not in database... *****/ if (!Nam_CheckIfNameExists (Bld_DB_CheckIfBuildingNameExists,Names,-1L, - -1L,0)) // Unused + -1L, // Unused + 0)) // Unused { Bld_DB_CreateBuilding (Bld_EditingBuilding); Ale_CreateAlert (Ale_SUCCESS,NULL,Txt_Created_new_building_X, diff --git a/swad_building.h b/swad_building.h index 6d759df4..c5683f2e 100644 --- a/swad_building.h +++ b/swad_building.h @@ -28,6 +28,7 @@ /*****************************************************************************/ #include "swad_constant.h" +#include "swad_name.h" #include "swad_string.h" /*****************************************************************************/ diff --git a/swad_center.h b/swad_center.h index 64ea492e..84ffa591 100644 --- a/swad_center.h +++ b/swad_center.h @@ -34,6 +34,7 @@ #include "swad_degree.h" #include "swad_figure_cache.h" #include "swad_map.h" +#include "swad_name.h" #include "swad_role_type.h" /*****************************************************************************/ diff --git a/swad_changelog.h b/swad_changelog.h index 2acf40b8..d2b4fa1d 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -633,12 +633,12 @@ 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.2 (2023-10-10)" +#define Log_PLATFORM_VERSION "SWAD 23.34 (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.34: Oct 10, 2023 New module swad_name for short and full names. (335608 lines) + Version 23.33.3: Oct 10, 2023 Code refactoring in short and full names. (335515 lines) 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) diff --git a/swad_constant.c b/swad_constant.c index d4749f15..28440e6d 100644 --- a/swad_constant.c +++ b/swad_constant.c @@ -25,38 +25,10 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ -#include "swad_constant.h" - /*****************************************************************************/ /***************************** Public constants ******************************/ /*****************************************************************************/ -const char *Nam_ParShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES] = - { - [Nam_SHRT_NAME] = "ShortName", - [Nam_FULL_NAME] = "FullName", - }; -const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES] = - { - [Nam_SHRT_NAME] = "ShortName", - [Nam_FULL_NAME] = "FullName", - }; -unsigned Nam_MaxCharsShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES] = - { - [Nam_SHRT_NAME] = Nam_MAX_CHARS_SHRT_NAME, - [Nam_FULL_NAME] = Nam_MAX_CHARS_FULL_NAME, - }; -unsigned Nam_MaxBytesShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES] = - { - [Nam_SHRT_NAME] = Nam_MAX_BYTES_SHRT_NAME, - [Nam_FULL_NAME] = Nam_MAX_BYTES_FULL_NAME, - }; -const char *Nam_ClassShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES] = - { - [Nam_SHRT_NAME] = "INPUT_SHORT_NAME", - [Nam_FULL_NAME] = "INPUT_FULL_NAME", - }; - /*****************************************************************************/ /**************************** Private constants ******************************/ /*****************************************************************************/ diff --git a/swad_constant.h b/swad_constant.h index 728931fd..a1f399ce 100644 --- a/swad_constant.h +++ b/swad_constant.h @@ -33,12 +33,6 @@ /***************************** Public constants ******************************/ /*****************************************************************************/ -#define Nam_MAX_CHARS_SHRT_NAME (32 - 1) // 31 -#define Nam_MAX_BYTES_SHRT_NAME ((Nam_MAX_CHARS_SHRT_NAME + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 511 - -#define Nam_MAX_CHARS_FULL_NAME (128 - 1) // 127 -#define Nam_MAX_BYTES_FULL_NAME ((Nam_MAX_CHARS_FULL_NAME + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 2047 - #define Cns_MAX_CHARS_WWW (256 - 1) // 255: max. number of chars of a URL #define Cns_MAX_BYTES_WWW Cns_MAX_CHARS_WWW // 255 @@ -111,14 +105,6 @@ typedef enum Cns_VERBOSE, } Cns_QuietOrVerbose_t; -// Related with names of centers, degrees, courses,... -#define Nam_NUM_SHRT_FULL_NAMES 2 -typedef enum - { - Nam_SHRT_NAME, - Nam_FULL_NAME, - } Nam_ShrtOrFullName_t; - #define Cns_NUM_DISABLED_ENABLED 2 typedef enum { diff --git a/swad_course.h b/swad_course.h index 032c0f3f..be52bcb5 100644 --- a/swad_course.h +++ b/swad_course.h @@ -34,6 +34,7 @@ #include "swad_degree.h" #include "swad_figure_cache.h" #include "swad_hierarchy_type.h" +#include "swad_name.h" #include "swad_user.h" /*****************************************************************************/ diff --git a/swad_course_config.c b/swad_course_config.c index d7d370b8..191a2c76 100644 --- a/swad_course_config.c +++ b/swad_course_config.c @@ -537,7 +537,8 @@ void CrsCfg_ChangeCrsYear (void) { /***** 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)) + -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_degree.h b/swad_degree.h index eff7e57a..94e10686 100644 --- a/swad_degree.h +++ b/swad_degree.h @@ -33,6 +33,7 @@ #include "swad_constant.h" #include "swad_figure_cache.h" #include "swad_hierarchy_type.h" +#include "swad_name.h" #include "swad_role_type.h" #include "swad_string.h" diff --git a/swad_form.c b/swad_form.c index 86b23f17..6c012762 100644 --- a/swad_form.c +++ b/swad_form.c @@ -353,93 +353,3 @@ void Frm_LabelColumn (const char *TDClass,const char *Id,const char *Label) /***** Column/cell end *****/ HTM_TD_End (); } - -/*****************************************************************************/ -/************************ Write short and full names *************************/ -/*****************************************************************************/ - -void Nam_NewShortAndFullNames (const char *Names[Nam_NUM_SHRT_FULL_NAMES]) - { - extern const char *Nam_ParShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern unsigned Nam_MaxCharsShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Nam_ClassShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - Nam_ShrtOrFullName_t ShrtOrFullName; - - for (ShrtOrFullName = Nam_SHRT_NAME; - ShrtOrFullName <= Nam_FULL_NAME; - ShrtOrFullName++) - { - HTM_TD_Begin ("class=\"CM\""); - HTM_INPUT_TEXT (Nam_ParShrtOrFullName[ShrtOrFullName], - Nam_MaxCharsShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName], - HTM_DONT_SUBMIT_ON_CHANGE, - "class=\"%s INPUT_%s\"" - " required=\"required\"", - Nam_ClassShrtOrFullName[ShrtOrFullName], - The_GetSuffix ()); - HTM_TD_End (); - } - } - -void Nam_ExistingShortAndFullNames (Act_Action_t ActionRename[Nam_NUM_SHRT_FULL_NAMES], - ParCod_Param_t ParCod,long Cod, - const char *Names[Nam_NUM_SHRT_FULL_NAMES], - bool PutForm) - { - extern const char *Nam_ParShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern unsigned Nam_MaxCharsShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Nam_ClassShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - Nam_ShrtOrFullName_t ShrtOrFullName; - - for (ShrtOrFullName = Nam_SHRT_NAME; - ShrtOrFullName <= Nam_FULL_NAME; - ShrtOrFullName++) - { - HTM_TD_Begin ("class=\"LM DAT_%s\"",The_GetSuffix ()); - if (PutForm) - { - Frm_BeginForm (ActionRename[ShrtOrFullName]); - ParCod_PutPar (ParCod,Cod); - HTM_INPUT_TEXT (Nam_ParShrtOrFullName[ShrtOrFullName], - Nam_MaxCharsShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName], - HTM_SUBMIT_ON_CHANGE, - "class=\"%s INPUT_%s\"" - " required=\"required\"", - Nam_ClassShrtOrFullName[ShrtOrFullName], - The_GetSuffix ()); - Frm_EndForm (); - } - else - HTM_Txt (Names[ShrtOrFullName]); - HTM_TD_End (); - } - } - -/*****************************************************************************/ -/****************** Check if a short or full name exists *********************/ -/*****************************************************************************/ - -bool Nam_CheckIfNameExists (bool (*FuncToCheck) (const char *FldName,const char *Name, - long Cod,long PrtCod,unsigned Year), - char *Names[Nam_NUM_SHRT_FULL_NAMES], - long Cod,long PrtCod,unsigned Year) - { - extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_X_already_exists; - Nam_ShrtOrFullName_t ShrtOrFullName; - - for (ShrtOrFullName = Nam_SHRT_NAME; - ShrtOrFullName <= Nam_FULL_NAME; - ShrtOrFullName++) - if (FuncToCheck (Nam_FldShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName],Cod,PrtCod,Year)) - { - Ale_CreateAlert (Ale_WARNING,NULL,Txt_X_already_exists, - Names[ShrtOrFullName]); - return true; // Exists - } - - return false; // Does not exist - } diff --git a/swad_form.h b/swad_form.h index f1368125..abc826ca 100644 --- a/swad_form.h +++ b/swad_form.h @@ -79,15 +79,4 @@ void Frm_FreeAnchorStr (char **Anchor); void Frm_LabelColumn (const char *TDClass,const char *Id,const char *Label); -void Nam_NewShortAndFullNames (const char *Names[Nam_NUM_SHRT_FULL_NAMES]); -void Nam_ExistingShortAndFullNames (Act_Action_t ActionRename[Nam_NUM_SHRT_FULL_NAMES], - ParCod_Param_t ParCod,long Cod, - const char *Names[Nam_NUM_SHRT_FULL_NAMES], - bool PutForm); - -bool Nam_CheckIfNameExists (bool (*FuncToCheck) (const char *FldName,const char *Name, - long Cod,long PrtCod,unsigned Year), - char *Names[Nam_NUM_SHRT_FULL_NAMES], - long Cod,long PrtCod,unsigned Year); - #endif diff --git a/swad_hierarchy_type.h b/swad_hierarchy_type.h index 74a38d1e..0129b750 100644 --- a/swad_hierarchy_type.h +++ b/swad_hierarchy_type.h @@ -28,6 +28,7 @@ /*****************************************************************************/ #include "swad_constant.h" +#include "swad_name.h" #include "swad_role_type.h" #include "swad_string.h" diff --git a/swad_institution.c b/swad_institution.c index 4dd35d60..7299054d 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -1145,7 +1145,7 @@ void Ins_RenameInstitution (struct Hie_Node *Ins,Nam_ShrtOrFullName_t ShrtOrFull 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_institution_X_already_exists; + extern const char *Txt_X_already_exists; extern const char *Txt_The_institution_X_has_been_renamed_as_Y; extern const char *Txt_The_name_X_has_not_changed; char *CurrentName[Nam_NUM_SHRT_FULL_NAMES] = @@ -1168,13 +1168,12 @@ void Ins_RenameInstitution (struct Hie_Node *Ins,Nam_ShrtOrFullName_t ShrtOrFull (this happens when return is pressed without changes) *****/ if (strcmp (CurrentName[ShrtOrFullName],NewName)) // Different names { - /***** If institution was in database... *****/ + /***** If institution was not in database... *****/ if (Ins_DB_CheckIfInsNameExistsInCty (Nam_ParShrtOrFullName[ShrtOrFullName], NewName,Ins->HieCod, - Gbl.Hierarchy.Node[Hie_CTY].HieCod)) - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_institution_X_already_exists, - NewName); + Gbl.Hierarchy.Node[Hie_CTY].HieCod, + 0)) // Unused + Ale_CreateAlert (Ale_WARNING,NULL,Txt_X_already_exists,NewName); else { /* Update the table changing old name by new name */ @@ -1479,13 +1478,7 @@ void Ins_ReceiveFormNewIns (void) static void Ins_ReceiveFormRequestOrCreateIns (Hie_Status_t Status) { - 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_institution_X_already_exists; extern const char *Txt_Created_new_institution_X; - Nam_ShrtOrFullName_t ShrtOrFullName; - bool Exists; char *Names[Nam_NUM_SHRT_FULL_NAMES] = { [Nam_SHRT_NAME] = Ins_EditingIns->ShrtName, @@ -1507,20 +1500,10 @@ static void Ins_ReceiveFormRequestOrCreateIns (Hie_Status_t Status) { if (Ins_EditingIns->WWW[0]) { - /***** If name of institution was in database... *****/ - for (ShrtOrFullName = Nam_SHRT_NAME, Exists = false; - ShrtOrFullName <= Nam_FULL_NAME && !Exists; - ShrtOrFullName++) - if (Ins_DB_CheckIfInsNameExistsInCty (Nam_FldShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName], - -1L,Gbl.Hierarchy.Node[Hie_CTY].HieCod)) - { - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_institution_X_already_exists, - Names[ShrtOrFullName]); - Exists = true; - } - if (!Exists) // Add new institution to database + /***** If name of institution was not in database... *****/ + if (!Nam_CheckIfNameExists (Ins_DB_CheckIfInsNameExistsInCty,Names, + -1L,Gbl.Hierarchy.Node[Hie_CTY].HieCod, + 0)) // Unused { Ins_EditingIns->HieCod = Ins_DB_CreateInstitution (Ins_EditingIns,Status); Ale_CreateAlert (Ale_SUCCESS,NULL,Txt_Created_new_institution_X, diff --git a/swad_institution.h b/swad_institution.h index 24035804..7f4e43e0 100644 --- a/swad_institution.h +++ b/swad_institution.h @@ -30,6 +30,7 @@ #include "swad_center.h" #include "swad_constant.h" #include "swad_figure_cache.h" +#include "swad_name.h" #include "swad_role_type.h" /*****************************************************************************/ diff --git a/swad_institution_config.c b/swad_institution_config.c index 6f9336b7..3445c07d 100644 --- a/swad_institution_config.c +++ b/swad_institution_config.c @@ -533,12 +533,8 @@ void InsCfg_RemoveLogo (void) void InsCfg_ChangeInsCty (void) { - extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_institution_X_already_exists; extern const char *Txt_The_country_of_the_institution_X_has_changed_to_Y; struct Hie_Node NewCty; - Nam_ShrtOrFullName_t ShrtOrFullName; - bool Exists; char *Names[Nam_NUM_SHRT_FULL_NAMES] = { [Nam_SHRT_NAME] = Gbl.Hierarchy.Node[Hie_INS].ShrtName, @@ -555,19 +551,9 @@ void InsCfg_ChangeInsCty (void) Cty_GetBasicCountryDataByCod (&NewCty); /***** Check if it already exists an institution with the same name in the new country *****/ - for (ShrtOrFullName = Nam_SHRT_NAME, Exists = false; - ShrtOrFullName <= Nam_FULL_NAME && !Exists; - ShrtOrFullName++) - if (Ins_DB_CheckIfInsNameExistsInCty (Nam_FldShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName], - -1L,NewCty.HieCod)) - { - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_institution_X_already_exists, - Names[ShrtOrFullName]); - Exists = true; - } - if (!Exists) + if (!Nam_CheckIfNameExists (Ins_DB_CheckIfInsNameExistsInCty,Names, + -1L,NewCty.HieCod, + 0)) // Unused { /***** Update the table changing the country of the institution *****/ Ins_DB_UpdateInsCty (Gbl.Hierarchy.Node[Hie_INS].HieCod,NewCty.HieCod); diff --git a/swad_institution_database.c b/swad_institution_database.c index 4d5493ce..8928f613 100644 --- a/swad_institution_database.c +++ b/swad_institution_database.c @@ -193,8 +193,9 @@ unsigned Ins_DB_GetInsShrtNameAndCty (MYSQL_RES **mysql_res,long InsCod) bool Ins_DB_CheckIfInsNameExistsInCty (const char *FldName, const char *Name, - long InsCod, - long CtyCod) + long Cod, + long PrtCod, + __attribute__((unused)) unsigned Year) { return DB_QueryEXISTS ("can not check if the name of an institution already existed", @@ -204,9 +205,9 @@ bool Ins_DB_CheckIfInsNameExistsInCty (const char *FldName, " WHERE CtyCod=%ld" " AND %s='%s'" " AND InsCod<>%ld)", - CtyCod, + PrtCod, FldName,Name, - InsCod); + Cod); } /*****************************************************************************/ diff --git a/swad_institution_database.h b/swad_institution_database.h index 299ba22a..5a6c5b2e 100644 --- a/swad_institution_database.h +++ b/swad_institution_database.h @@ -48,8 +48,9 @@ void Ins_DB_GetInsShrtName (long InsCod,char ShrtName[Nam_MAX_BYTES_SHRT_NAME + unsigned Ins_DB_GetInsShrtNameAndCty (MYSQL_RES **mysql_res,long InsCod); bool Ins_DB_CheckIfInsNameExistsInCty (const char *FldName, const char *Name, - long InsCod, - long CtyCod); + long Cod, + long PrtCod, + __attribute__((unused)) unsigned Year); unsigned Ins_DB_GetAllInsWithPendingCtr (MYSQL_RES **mysql_res); unsigned Ins_DB_GetInsWithPendingCtrsAdminByMe (MYSQL_RES **mysql_res); diff --git a/swad_link.c b/swad_link.c index 54d32018..9820a326 100644 --- a/swad_link.c +++ b/swad_link.c @@ -529,7 +529,7 @@ static void Lnk_RenameLink (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_link_X_already_exists; + extern const char *Txt_X_already_exists; extern const char *Txt_The_link_X_has_been_renamed_as_Y; extern const char *Txt_The_name_X_has_not_changed; char *CurrentName[Nam_NUM_SHRT_FULL_NAMES] = @@ -558,10 +558,10 @@ static void Lnk_RenameLink (Nam_ShrtOrFullName_t ShrtOrFullName) { /***** If link was in database... *****/ if (Lnk_DB_CheckIfLinkNameExists (Nam_ParShrtOrFullName[ShrtOrFullName], - NewName,Lnk_EditingLnk->LnkCod)) - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_link_X_already_exists, - NewName); + NewName,Lnk_EditingLnk->LnkCod, + -1L, // Unused + 0)) // Unused + Ale_CreateAlert (Ale_WARNING,NULL,Txt_X_already_exists,NewName); else { /* Update the table changing old name by new name */ @@ -714,14 +714,8 @@ static void Lnk_PutHeadLinks (void) void Lnk_ReceiveFormNewLink (void) { - 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_link_X_already_exists; extern const char *Txt_You_must_specify_the_web_address; extern const char *Txt_Created_new_link_X; - Nam_ShrtOrFullName_t ShrtOrFullName; - bool Exists; char *Names[Nam_NUM_SHRT_FULL_NAMES] = { [Nam_SHRT_NAME] = Lnk_EditingLnk->ShrtName, @@ -742,18 +736,10 @@ void Lnk_ReceiveFormNewLink (void) Lnk_EditingLnk->FullName[0]) // If there's a link name { /***** If name of link was in database... *****/ - for (ShrtOrFullName = Nam_SHRT_NAME, Exists = false; - ShrtOrFullName <= Nam_FULL_NAME && !Exists; - ShrtOrFullName++) - if (Lnk_DB_CheckIfLinkNameExists (Nam_FldShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName],-1L)) - { - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_link_X_already_exists, - Names[ShrtOrFullName]); - Exists = true; - } - if (!Exists) + if (!Nam_CheckIfNameExists (Lnk_DB_CheckIfLinkNameExists,Names, + -1L, + -1L, // Unused + 0)) // Unused { if (!Lnk_EditingLnk->WWW[0]) Ale_CreateAlert (Ale_WARNING,NULL, diff --git a/swad_link_database.c b/swad_link_database.c index 9a87e017..e455a0ba 100644 --- a/swad_link_database.c +++ b/swad_link_database.c @@ -110,7 +110,9 @@ unsigned Lnk_DB_GetLinkDataByCod (MYSQL_RES **mysql_res,long LnkCod) /********************** Check if the name of link exists *********************/ /*****************************************************************************/ -bool Lnk_DB_CheckIfLinkNameExists (const char *FldName,const char *Name,long LnkCod) +bool Lnk_DB_CheckIfLinkNameExists (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 an institutional link already existed", @@ -120,7 +122,7 @@ bool Lnk_DB_CheckIfLinkNameExists (const char *FldName,const char *Name,long Lnk " WHERE %s='%s'" " AND LnkCod<>%ld)", FldName,Name, - LnkCod); + Cod); } /*****************************************************************************/ diff --git a/swad_link_database.h b/swad_link_database.h index 82e11abc..5ffb626a 100644 --- a/swad_link_database.h +++ b/swad_link_database.h @@ -41,7 +41,9 @@ void Lnk_DB_UpdateLnkWWW (long LnkCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]); unsigned Lnk_DB_GetLinks (MYSQL_RES **mysql_res); unsigned Lnk_DB_GetLinkDataByCod (MYSQL_RES **mysql_res,long LnkCod); -bool Lnk_DB_CheckIfLinkNameExists (const char *FldName,const char *Name,long LnkCod); +bool Lnk_DB_CheckIfLinkNameExists (const char *FldName,const char *Name,long Cod, + __attribute__((unused)) long PrtCod, + __attribute__((unused)) unsigned Year); void Lnk_DB_RemoveLink (long LnkCod); diff --git a/swad_name.c b/swad_name.c new file mode 100644 index 00000000..a51b81dc --- /dev/null +++ b/swad_name.c @@ -0,0 +1,200 @@ +// swad_name.c: short and full names + +/* + SWAD (Shared Workspace At a Distance), + is a web platform developed at the University of Granada (Spain), + and used to support university teaching. + + This file is part of SWAD core. + Copyright (C) 1999-2023 Antonio Cañas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +/*****************************************************************************/ +/*********************************** Headers *********************************/ +/*****************************************************************************/ + +#include "swad_alert.h" +#include "swad_form.h" +#include "swad_HTML.h" +#include "swad_name.h" +#include "swad_parameter.h" +#include "swad_theme.h" + +/*****************************************************************************/ +/***************************** Public constants ******************************/ +/*****************************************************************************/ + +const char *Nam_ParShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES] = + { + [Nam_SHRT_NAME] = "ShortName", + [Nam_FULL_NAME] = "FullName", + }; +const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES] = + { + [Nam_SHRT_NAME] = "ShortName", + [Nam_FULL_NAME] = "FullName", + }; +unsigned Nam_MaxCharsShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES] = + { + [Nam_SHRT_NAME] = Nam_MAX_CHARS_SHRT_NAME, + [Nam_FULL_NAME] = Nam_MAX_CHARS_FULL_NAME, + }; +unsigned Nam_MaxBytesShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES] = + { + [Nam_SHRT_NAME] = Nam_MAX_BYTES_SHRT_NAME, + [Nam_FULL_NAME] = Nam_MAX_BYTES_FULL_NAME, + }; +const char *Nam_ClassShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES] = + { + [Nam_SHRT_NAME] = "INPUT_SHORT_NAME", + [Nam_FULL_NAME] = "INPUT_FULL_NAME", + }; + +/*****************************************************************************/ +/**************************** Private constants ******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/******************************* Private types *******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/************** External global variables from others modules ****************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/************************** Public global variables **************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/************************* Private global variables **************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private prototypes ****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/************************ Get short name and full name ***********************/ +/*****************************************************************************/ + +void Nam_GetParsShrtAndFullName (char *Names[Nam_NUM_SHRT_FULL_NAMES]) + { + Nam_ShrtOrFullName_t ShrtOrFullName; + + for (ShrtOrFullName = Nam_SHRT_NAME; + ShrtOrFullName <= Nam_FULL_NAME; + ShrtOrFullName++) + Nam_GetParShrtOrFullName (ShrtOrFullName,Names[ShrtOrFullName]); + } + +void Nam_GetParShrtOrFullName (Nam_ShrtOrFullName_t ShrtOrFullName,char *Name) + { + extern const char *Nam_ParShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; + extern unsigned Nam_MaxBytesShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; + + Par_GetParText (Nam_ParShrtOrFullName[ShrtOrFullName],Name, + Nam_MaxBytesShrtOrFullName[ShrtOrFullName]); + } + +/*****************************************************************************/ +/************************ Write short and full names *************************/ +/*****************************************************************************/ + +void Nam_NewShortAndFullNames (const char *Names[Nam_NUM_SHRT_FULL_NAMES]) + { + extern const char *Nam_ParShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; + extern unsigned Nam_MaxCharsShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; + extern const char *Nam_ClassShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; + Nam_ShrtOrFullName_t ShrtOrFullName; + + for (ShrtOrFullName = Nam_SHRT_NAME; + ShrtOrFullName <= Nam_FULL_NAME; + ShrtOrFullName++) + { + HTM_TD_Begin ("class=\"CM\""); + HTM_INPUT_TEXT (Nam_ParShrtOrFullName[ShrtOrFullName], + Nam_MaxCharsShrtOrFullName[ShrtOrFullName], + Names[ShrtOrFullName], + HTM_DONT_SUBMIT_ON_CHANGE, + "class=\"%s INPUT_%s\"" + " required=\"required\"", + Nam_ClassShrtOrFullName[ShrtOrFullName], + The_GetSuffix ()); + HTM_TD_End (); + } + } + +void Nam_ExistingShortAndFullNames (Act_Action_t ActionRename[Nam_NUM_SHRT_FULL_NAMES], + ParCod_Param_t ParCod,long Cod, + const char *Names[Nam_NUM_SHRT_FULL_NAMES], + bool PutForm) + { + extern const char *Nam_ParShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; + extern unsigned Nam_MaxCharsShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; + extern const char *Nam_ClassShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; + Nam_ShrtOrFullName_t ShrtOrFullName; + + for (ShrtOrFullName = Nam_SHRT_NAME; + ShrtOrFullName <= Nam_FULL_NAME; + ShrtOrFullName++) + { + HTM_TD_Begin ("class=\"LM DAT_%s\"",The_GetSuffix ()); + if (PutForm) + { + Frm_BeginForm (ActionRename[ShrtOrFullName]); + ParCod_PutPar (ParCod,Cod); + HTM_INPUT_TEXT (Nam_ParShrtOrFullName[ShrtOrFullName], + Nam_MaxCharsShrtOrFullName[ShrtOrFullName], + Names[ShrtOrFullName], + HTM_SUBMIT_ON_CHANGE, + "class=\"%s INPUT_%s\"" + " required=\"required\"", + Nam_ClassShrtOrFullName[ShrtOrFullName], + The_GetSuffix ()); + Frm_EndForm (); + } + else + HTM_Txt (Names[ShrtOrFullName]); + HTM_TD_End (); + } + } + +/*****************************************************************************/ +/****************** Check if a short or full name exists *********************/ +/*****************************************************************************/ + +bool Nam_CheckIfNameExists (bool (*FuncToCheck) (const char *FldName,const char *Name, + long Cod,long PrtCod,unsigned Year), + char *Names[Nam_NUM_SHRT_FULL_NAMES], + long Cod,long PrtCod,unsigned Year) + { + extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; + extern const char *Txt_X_already_exists; + Nam_ShrtOrFullName_t ShrtOrFullName; + + for (ShrtOrFullName = Nam_SHRT_NAME; + ShrtOrFullName <= Nam_FULL_NAME; + ShrtOrFullName++) + if (FuncToCheck (Nam_FldShrtOrFullName[ShrtOrFullName], + Names[ShrtOrFullName],Cod,PrtCod,Year)) + { + Ale_CreateAlert (Ale_WARNING,NULL,Txt_X_already_exists, + Names[ShrtOrFullName]); + return true; // Exists + } + + return false; // Does not exist + } diff --git a/swad_name.h b/swad_name.h new file mode 100644 index 00000000..44a70bd6 --- /dev/null +++ b/swad_name.h @@ -0,0 +1,74 @@ +// swad_name.h: short and full names + +#ifndef _SWAD_NAM +#define _SWAD_NAM +/* + SWAD (Shared Workspace At a Distance in Spanish), + is a web platform developed at the University of Granada (Spain), + and used to support university teaching. + + This file is part of SWAD core. + Copyright (C) 1999-2023 Antonio Cañas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +/*****************************************************************************/ +/********************************* Headers ***********************************/ +/*****************************************************************************/ + +#include "swad_action.h" +#include "swad_parameter_code.h" +#include "swad_string.h" + +/*****************************************************************************/ +/***************************** Public constants ******************************/ +/*****************************************************************************/ + +#define Nam_MAX_CHARS_SHRT_NAME (32 - 1) // 31 +#define Nam_MAX_BYTES_SHRT_NAME ((Nam_MAX_CHARS_SHRT_NAME + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 511 + +#define Nam_MAX_CHARS_FULL_NAME (128 - 1) // 127 +#define Nam_MAX_BYTES_FULL_NAME ((Nam_MAX_CHARS_FULL_NAME + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 2047 + +/*****************************************************************************/ +/******************************* Public types ********************************/ +/*****************************************************************************/ + +// Related with names of centers, degrees, courses,... +#define Nam_NUM_SHRT_FULL_NAMES 2 +typedef enum + { + Nam_SHRT_NAME, + Nam_FULL_NAME, + } Nam_ShrtOrFullName_t; + +/*****************************************************************************/ +/***************************** Public prototypes *****************************/ +/*****************************************************************************/ + +void Nam_GetParsShrtAndFullName (char *Names[Nam_NUM_SHRT_FULL_NAMES]); +void Nam_GetParShrtOrFullName (Nam_ShrtOrFullName_t ShrtOrFullName,char *Name); + +void Nam_NewShortAndFullNames (const char *Names[Nam_NUM_SHRT_FULL_NAMES]); +void Nam_ExistingShortAndFullNames (Act_Action_t ActionRename[Nam_NUM_SHRT_FULL_NAMES], + ParCod_Param_t ParCod,long Cod, + const char *Names[Nam_NUM_SHRT_FULL_NAMES], + bool PutForm); + +bool Nam_CheckIfNameExists (bool (*FuncToCheck) (const char *FldName,const char *Name, + long Cod,long PrtCod,unsigned Year), + char *Names[Nam_NUM_SHRT_FULL_NAMES], + long Cod,long PrtCod,unsigned Year); + +#endif diff --git a/swad_parameter.c b/swad_parameter.c index a3ede3c0..fe99c3c9 100644 --- a/swad_parameter.c +++ b/swad_parameter.c @@ -908,29 +908,6 @@ unsigned Par_GetParText (const char *ParName,char *ParValue,size_t MaxBytes) Str_REMOVE_SPACES); } -/*****************************************************************************/ -/************************ Get short name and full name ***********************/ -/*****************************************************************************/ - -void Nam_GetParsShrtAndFullName (char *Names[Nam_NUM_SHRT_FULL_NAMES]) - { - Nam_ShrtOrFullName_t ShrtOrFullName; - - for (ShrtOrFullName = Nam_SHRT_NAME; - ShrtOrFullName <= Nam_FULL_NAME; - ShrtOrFullName++) - Nam_GetParShrtOrFullName (ShrtOrFullName,Names[ShrtOrFullName]); - } - -void Nam_GetParShrtOrFullName (Nam_ShrtOrFullName_t ShrtOrFullName,char *Name) - { - extern const char *Nam_ParShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern unsigned Nam_MaxBytesShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - - Par_GetParText (Nam_ParShrtOrFullName[ShrtOrFullName],Name, - Nam_MaxBytesShrtOrFullName[ShrtOrFullName]); - } - /*****************************************************************************/ /****************** Get the unsigned value of a parameter ********************/ /*****************************************************************************/ diff --git a/swad_parameter.h b/swad_parameter.h index 1555d6f8..41de43c5 100644 --- a/swad_parameter.h +++ b/swad_parameter.h @@ -82,8 +82,6 @@ void Par_GetMainPars (void); //------------------------------ Get parameters ------------------------------- unsigned Par_GetParText (const char *ParName,char *ParValue,size_t MaxBytes); -void Nam_GetParsShrtAndFullName (char *Names[Nam_NUM_SHRT_FULL_NAMES]); -void Nam_GetParShrtOrFullName (Nam_ShrtOrFullName_t ShrtOrFullName,char *Name); unsigned long Par_GetParUnsignedLong (const char *ParName, unsigned long Min, unsigned long Max, diff --git a/swad_place.c b/swad_place.c index 7338619f..540f94f4 100644 --- a/swad_place.c +++ b/swad_place.c @@ -582,7 +582,7 @@ static void Plc_RenamePlace (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_place_X_already_exists; + extern const char *Txt_X_already_exists; extern const char *Txt_The_place_X_has_been_renamed_as_Y; extern const char *Txt_The_name_X_has_not_changed; char *CurrentName[Nam_NUM_SHRT_FULL_NAMES] = @@ -611,10 +611,10 @@ static void Plc_RenamePlace (Nam_ShrtOrFullName_t ShrtOrFullName) { /***** If place was in database... *****/ if (Plc_DB_CheckIfPlaceNameExists (Nam_ParShrtOrFullName[ShrtOrFullName], - NewName,Plc_EditingPlc->PlcCod)) - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_place_X_already_exists, - NewName); + NewName,Plc_EditingPlc->PlcCod, + 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 */ @@ -724,11 +724,7 @@ static void Plc_PutHeadPlaces (void) void Plc_ReceiveFormNewPlace (void) { - extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_place_X_already_exists; extern const char *Txt_Created_new_place_X; - Nam_ShrtOrFullName_t ShrtOrFullName; - bool Exists; char *Names[Nam_NUM_SHRT_FULL_NAMES] = { [Nam_SHRT_NAME] = Plc_EditingPlc->ShrtName, @@ -745,19 +741,10 @@ void Plc_ReceiveFormNewPlace (void) if (Plc_EditingPlc->ShrtName[0] && Plc_EditingPlc->FullName[0]) // If there's a place name { - /***** If name of place was in database... *****/ - for (ShrtOrFullName = Nam_SHRT_NAME, Exists = false; - ShrtOrFullName <= Nam_FULL_NAME && !Exists; - ShrtOrFullName++) - if (Plc_DB_CheckIfPlaceNameExists (Nam_FldShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName],-1L)) - { - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_place_X_already_exists, - Names[ShrtOrFullName]); - Exists = true; - } - if (!Exists) // Add new place to database + /***** If name of place was not in database... *****/ + if (!Nam_CheckIfNameExists (Plc_DB_CheckIfPlaceNameExists,Names, + -1L,Gbl.Hierarchy.Node[Hie_INS].HieCod, + 0)) // Unused { Plc_DB_CreatePlace (Plc_EditingPlc); Ale_CreateAlert (Ale_SUCCESS,NULL,Txt_Created_new_place_X, diff --git a/swad_place_database.c b/swad_place_database.c index 4b8dcf8d..97c09923 100644 --- a/swad_place_database.c +++ b/swad_place_database.c @@ -149,7 +149,9 @@ unsigned Plc_DB_GetPlaceDataByCod (MYSQL_RES **mysql_res,long PlcCod) /********************** Check if the name of place exists ********************/ /*****************************************************************************/ -bool Plc_DB_CheckIfPlaceNameExists (const char *FldName,const char *Name,long PlcCod) +bool Plc_DB_CheckIfPlaceNameExists (const char *FldName,const char *Name,long Cod, + long PrtCod, + __attribute__((unused)) unsigned Year) { return DB_QueryEXISTS ("can not check if the name of a place already existed", @@ -159,9 +161,9 @@ bool Plc_DB_CheckIfPlaceNameExists (const char *FldName,const char *Name,long Pl " WHERE InsCod=%ld" " AND %s='%s'" " AND PlcCod<>%ld)", - Gbl.Hierarchy.Node[Hie_INS].HieCod, + PrtCod, FldName,Name, - PlcCod); + Cod); } /*****************************************************************************/ diff --git a/swad_place_database.h b/swad_place_database.h index b464ca65..bef4ce7a 100644 --- a/swad_place_database.h +++ b/swad_place_database.h @@ -38,7 +38,9 @@ void Plc_DB_UpdatePlcName (long PlcCod,const char *FldName,const char *NewPlcNam unsigned Plc_DB_GetListPlaces (MYSQL_RES **mysql_res,Plc_Order_t SelectedOrder); unsigned Plc_DB_GetPlaceDataByCod (MYSQL_RES **mysql_res,long PlcCod); -bool Plc_DB_CheckIfPlaceNameExists (const char *FldName,const char *Name,long PlcCod); +bool Plc_DB_CheckIfPlaceNameExists (const char *FldName,const char *Name,long Cod, + long PrtCod, + __attribute__((unused)) unsigned Year); void Plc_DB_RemovePlace (long PlcCod); diff --git a/swad_room.c b/swad_room.c index 342df9b6..0a336b25 100644 --- a/swad_room.c +++ b/swad_room.c @@ -1049,7 +1049,7 @@ static void Roo_RenameRoom (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_room_X_already_exists; + extern const char *Txt_X_already_exists; extern const char *Txt_The_room_X_has_been_renamed_as_Y; extern const char *Txt_The_name_X_has_not_changed; char *CurrentName[Nam_NUM_SHRT_FULL_NAMES] = @@ -1079,9 +1079,9 @@ static void Roo_RenameRoom (Nam_ShrtOrFullName_t ShrtOrFullName) /***** If room was in database... *****/ if (Roo_DB_CheckIfRoomNameExists (Nam_ParShrtOrFullName[ShrtOrFullName], NewName,Roo_EditingRoom->RooCod, - Gbl.Hierarchy.Node[Hie_CTR].HieCod)) - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_room_X_already_exists, + Gbl.Hierarchy.Node[Hie_CTR].HieCod, + 0)) // Unused + Ale_CreateAlert (Ale_WARNING,NULL,Txt_X_already_exists, NewName); else { @@ -1300,11 +1300,7 @@ static void Roo_PutHeadRooms (void) void Roo_ReceiveFormNewRoom (void) { - extern const char *Nam_FldShrtOrFullName[Nam_NUM_SHRT_FULL_NAMES]; - extern const char *Txt_The_room_X_already_exists; extern const char *Txt_Created_new_room_X; - Nam_ShrtOrFullName_t ShrtOrFullName; - bool Exists; char *Names[Nam_NUM_SHRT_FULL_NAMES] = { [Nam_SHRT_NAME] = Roo_EditingRoom->ShrtName, @@ -1336,19 +1332,10 @@ void Roo_ReceiveFormNewRoom (void) if (Roo_EditingRoom->ShrtName[0] && Roo_EditingRoom->FullName[0]) // If there's a room name { - /***** If name of room was in database... *****/ - for (ShrtOrFullName = Nam_SHRT_NAME, Exists = false; - ShrtOrFullName <= Nam_FULL_NAME && !Exists; - ShrtOrFullName++) - if (Roo_DB_CheckIfRoomNameExists (Nam_FldShrtOrFullName[ShrtOrFullName], - Names[ShrtOrFullName],-1L, - Gbl.Hierarchy.Node[Hie_CTR].HieCod)) - { - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_room_X_already_exists,Names[ShrtOrFullName]); - Exists = true; - } - if (!Exists) // Add new room to database + /***** If name of room was not in database... *****/ + if (!Nam_CheckIfNameExists (Roo_DB_CheckIfRoomNameExists,Names, + -1L,Gbl.Hierarchy.Node[Hie_CTR].HieCod, + 0)) // Unused { Roo_CreateRoom (Roo_EditingRoom); Ale_CreateAlert (Ale_SUCCESS,NULL,Txt_Created_new_room_X, diff --git a/swad_room_database.c b/swad_room_database.c index e89acd16..7777a5dc 100644 --- a/swad_room_database.c +++ b/swad_room_database.c @@ -264,7 +264,8 @@ unsigned Roo_DB_GetListRooms (MYSQL_RES **mysql_res, /*****************************************************************************/ bool Roo_DB_CheckIfRoomNameExists (const char *FldName,const char *Name, - long RooCod,long CtrCod) + long Cod,long PrtCod, + __attribute__((unused)) unsigned Year) { return DB_QueryEXISTS ("can not check if the name of a room already existed", @@ -274,9 +275,9 @@ bool Roo_DB_CheckIfRoomNameExists (const char *FldName,const char *Name, " WHERE CtrCod=%ld" " AND %s='%s'" " AND RooCod<>%ld)", - CtrCod, + PrtCod, FldName,Name, - RooCod); + Cod); } /*****************************************************************************/ diff --git a/swad_room_database.h b/swad_room_database.h index c64d0a34..05fc2bef 100644 --- a/swad_room_database.h +++ b/swad_room_database.h @@ -42,7 +42,8 @@ unsigned Roo_DB_GetListRooms (MYSQL_RES **mysql_res, Roo_WhichData_t WhichData, Roo_Order_t SelectedOrder); bool Roo_DB_CheckIfRoomNameExists (const char *FldName,const char *Name, - long RooCod,long CtrCod); + long Cod,long PrtCod, + __attribute__((unused)) unsigned Year); unsigned Roo_DB_GetRoomDataByCod (MYSQL_RES **mysql_res,long RooCod); unsigned Roo_DB_GetMACAddresses (MYSQL_RES **mysql_res,long RooCod); diff --git a/swad_text.c b/swad_text.c index b6a9deec..f987c96f 100644 --- a/swad_text.c +++ b/swad_text.c @@ -48647,29 +48647,6 @@ const char *Txt_The_ID_X_matches_one_of_the_existing = // Warning: it is very im " matches one of the existing."; // Çeviri lazim! #endif -const char *Txt_The_institution_X_already_exists = // Warning: it is very important to include %s in the following sentences -#if L==1 // ca - "La institució %s ja existeix."; -#elif L==2 // de - "Die Hochschule %s wurde bereits eingegeben."; -#elif L==3 // en - "The institution %s already exists."; -#elif L==4 // es - "La institución %s ya existe."; -#elif L==5 // fr - "The institution %s already exists."; // Besoin de traduction -#elif L==6 // gn - "La institución %s ya existe."; // Okoteve traducción -#elif L==7 // it - "L'istituzione %s già esiste."; -#elif L==8 // pl - "The institution %s already exists."; // Potrzebujesz tlumaczenie -#elif L==9 // pt - "A instituição %s já existe."; -#elif L==10 // tr - "The institution %s already exists."; // Çeviri lazim! -#endif - const char *Txt_The_institution_X_has_been_renamed_as_Y = // Warning: it is very important to include two %s in the following sentences #if L==1 // ca "La institució %s ha passat a anomenar-se %s."; @@ -48818,29 +48795,6 @@ const char *Txt_The_integrated_editor_is_not_yet_available = "The integrated editor is not yet available."; // Çeviri lazim! #endif -const char *Txt_The_link_X_already_exists = // Warning: it is very important to include %s in the following sentences -#if L==1 // ca - "L'enllaç %s ja existeix."; -#elif L==2 // de - "Der Link %s wurde bereits eingegeben."; -#elif L==3 // en - "The link %s already exists."; -#elif L==4 // es - "El enlace %s ya existe."; -#elif L==5 // fr - "Le lien %s existe déjà."; -#elif L==6 // gn - "El enlace %s ya existe."; // Okoteve traducción -#elif L==7 // it - "Il link %s già esiste."; -#elif L==8 // pl - "Link %s już istnieje."; -#elif L==9 // pt - "O link %s já existe."; -#elif L==10 // tr - "The link %s already exists."; // Çeviri lazim! -#endif - const char *Txt_The_link_X_has_been_placed_inside_the_folder_Y = // Warning: it is very important to include %s in the following sentences #if L==1 // ca "El enlace %s se ha almacenado" @@ -49908,29 +49862,6 @@ const char *Txt_The_password_has_been_changed_successfully = "The password has been changed successfully."; // Çeviri lazim! #endif -const char *Txt_The_place_X_already_exists = // Warning: it is very important to include %s in the following sentences -#if L==1 // ca - "El lloc %s ja existeix."; -#elif L==2 // de - "Der Standort %s wurde bereits eingegeben."; -#elif L==3 // en - "The place %s already exists."; -#elif L==4 // es - "El lugar %s ya existe."; -#elif L==5 // fr - "L'emplacement %s existe déjà."; -#elif L==6 // gn - "El lugar %s ya existe."; // Okoteve traducción -#elif L==7 // it - "Il luogo %s già esiste."; -#elif L==8 // pl - "Miejsce %s już istnieje."; -#elif L==9 // pt - "A localização %s já existe."; -#elif L==10 // tr - "The place %s already exists."; // Çeviri lazim! -#endif - const char *Txt_The_place_X_has_been_renamed_as_Y = // Warning: it is very important to include two %s in the following sentences #if L==1 // ca "El lloc %s ha passat a anomenar-se %s."; @@ -50204,29 +50135,6 @@ const char *Txt_The_role_of_THE_USER_X_in_the_course_Y_has_changed_from_A_to_B = " has changed from %s to %s."; // Çeviri lazim! #endif -const char *Txt_The_room_X_already_exists = // Warning: it is very important to include %s in the following sentences -#if L==1 // ca - "La sala %s ja existeix."; -#elif L==2 // de - "Das Raum %s wurde bereits eingegeben."; -#elif L==3 // en - "The room %s already exists."; -#elif L==4 // es - "La sala %s ya existe."; -#elif L==5 // fr - "La salle %s existe déjà."; -#elif L==6 // gn - "La sala %s ya existe."; // Okoteve traducción -#elif L==7 // it - "L'aula %s già esiste."; -#elif L==8 // pl - "Klasa %s już istnieje."; -#elif L==9 // pt - "A sala %s já existe."; -#elif L==10 // tr - "The room %s already exists."; // Çeviri lazim! -#endif - const char *Txt_The_room_X_does_not_have_a_limited_capacity_now = // Warning: it is very important to include %s in the following sentences #if L==1 // ca "La sala %s ja no té un aforament limitat.";