diff --git a/swad_center.c b/swad_center.c index 9d263a65..0bdcea16 100644 --- a/swad_center.c +++ b/swad_center.c @@ -1760,26 +1760,6 @@ static void Ctr_FormToGoToMap (struct Hie_Node *Ctr) } } -/*****************************************************************************/ -/*********************** Check if I belong to a center ***********************/ -/*****************************************************************************/ - -bool Ctr_CheckIfIBelongToCtr (long CtrCod) - { - unsigned NumMyCtr; - - /***** Fill the list with the centers I belong to *****/ - Hie_GetMyHierarchy (Hie_CTR); - - /***** Check if the center passed as parameter is any of my centers *****/ - for (NumMyCtr = 0; - NumMyCtr < Gbl.Usrs.Me.Hierarchy[Hie_CTR].Num; - NumMyCtr++) - if (Gbl.Usrs.Me.Hierarchy[Hie_CTR].Nodes[NumMyCtr].HieCod == CtrCod) - return true; - return false; - } - /*****************************************************************************/ /******************** Write parameter with code of center ********************/ /*****************************************************************************/ diff --git a/swad_center.h b/swad_center.h index d2f84053..3e7a822a 100644 --- a/swad_center.h +++ b/swad_center.h @@ -73,6 +73,4 @@ unsigned Ctr_GetCachedNumCtrsWithUsrs (Rol_Role_t Role); void Ctr_ListCtrsFound (MYSQL_RES **mysql_res,unsigned NumCtrs); -bool Ctr_CheckIfIBelongToCtr (long CtrCod); - #endif diff --git a/swad_changelog.h b/swad_changelog.h index b9efd9ea..20e66cfe 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.23.1 (2023-10-03)" +#define Log_PLATFORM_VERSION "SWAD 23.24 (2023-10-03)" #define CSS_FILE "swad23.16.1.css" #define JS_FILE "swad22.49.js" /* + Version 23.24: Oct 03, 2023 Code refactoring in user's hierarchy. (336276 lines) Version 23.23.1: Oct 03, 2023 Removed unused code in user's hierarchy. (336349 lines) Version 23.23: Oct 03, 2023 Code refactoring in user's hierarchy. (336620 lines) Version 23.22: Oct 03, 2023 Code refactoring in user's hierarchy. (336518 lines) diff --git a/swad_country.c b/swad_country.c index f526afe1..3cb14b44 100644 --- a/swad_country.c +++ b/swad_country.c @@ -1774,26 +1774,6 @@ static void Cty_FormToGoToMap (struct Hie_Node *Cty) } } -/*****************************************************************************/ -/********************** Check if I belong to a country **********************/ -/*****************************************************************************/ - -bool Cty_CheckIfIBelongToCty (long CtyCod) - { - unsigned NumMyCty; - - /***** Fill the list with the institutions I belong to *****/ - Hie_GetMyHierarchy (Hie_CTY); - - /***** Check if the country passed as parameter is any of my countries *****/ - for (NumMyCty = 0; - NumMyCty < Gbl.Usrs.Me.Hierarchy[Hie_CTY].Num; - NumMyCty++) - if (Gbl.Usrs.Me.Hierarchy[Hie_CTY].Nodes[NumMyCty].HieCod == CtyCod) - return true; - return false; - } - /*****************************************************************************/ /******* Get number of users who don't claim to belong to any country ********/ /*****************************************************************************/ diff --git a/swad_country.h b/swad_country.h index 60a80804..e508bcdb 100644 --- a/swad_country.h +++ b/swad_country.h @@ -84,8 +84,6 @@ unsigned Cty_GetCachedNumCtysWithUsrs (Rol_Role_t Role); void Cty_ListCtysFound (MYSQL_RES **mysql_res,unsigned NumCtys); -bool Cty_CheckIfIBelongToCty (long CtyCod); - void Cty_FlushCacheNumUsrsWhoDontClaimToBelongToAnyCty (void); unsigned Cty_GetCachedNumUsrsWhoDontClaimToBelongToAnyCty (void); unsigned Cty_GetNumUsrsWhoDontClaimToBelongToAnyCty (void); diff --git a/swad_course.c b/swad_course.c index 44802880..130ee27f 100644 --- a/swad_course.c +++ b/swad_course.c @@ -744,8 +744,8 @@ static bool Crs_ListCoursesOfAYearForSeeing (unsigned Year) } /* Check if this course is one of my courses */ - BgColor = (Enr_CheckIfIBelongToCrs (Crs->HieCod)) ? "BG_HIGHLIGHT" : - The_GetColorRows (); + BgColor = (Hie_CheckIfIBelongTo (Hie_CRS,Crs->HieCod)) ? "BG_HIGHLIGHT" : + The_GetColorRows (); HTM_TR_Begin (NULL); diff --git a/swad_degree.c b/swad_degree.c index 04ae416d..b64c98f2 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -1642,26 +1642,6 @@ static void Deg_EditingDegreeDestructor (void) } } -/*****************************************************************************/ -/*********************** Check if I belong to a degree ***********************/ -/*****************************************************************************/ - -bool Deg_CheckIfIBelongToDeg (long DegCod) - { - unsigned NumMyDeg; - - /***** Fill the list with the degrees I belong to *****/ - Hie_GetMyHierarchy (Hie_DEG); - - /***** Check if the degree passed as parameter is any of my degrees *****/ - for (NumMyDeg = 0; - NumMyDeg < Gbl.Usrs.Me.Hierarchy[Hie_DEG].Num; - NumMyDeg++) - if (Gbl.Usrs.Me.Hierarchy[Hie_DEG].Nodes[NumMyDeg].HieCod == DegCod) - return true; - return false; - } - /*****************************************************************************/ /********* Get the degree in which a user is enroled in more courses *********/ /*****************************************************************************/ diff --git a/swad_degree.h b/swad_degree.h index dac4dcdb..fcfa19f7 100644 --- a/swad_degree.h +++ b/swad_degree.h @@ -83,7 +83,6 @@ unsigned Deg_GetCachedNumDegsWithUsrs (Rol_Role_t Role); void Deg_ListDegsFound (MYSQL_RES **mysql_res,unsigned NumCrss); -bool Deg_CheckIfIBelongToDeg (long DegCod); void Deg_GetUsrMainDeg (long UsrCod, char ShrtName[Hie_MAX_BYTES_SHRT_NAME + 1], Rol_Role_t *MaxRole); diff --git a/swad_enrolment.c b/swad_enrolment.c index 973d042c..de68ea16 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -3221,27 +3221,6 @@ static void Enr_EffectivelyRemUsrFromCrs (struct Usr_Data *UsrDat, Ale_CreateAlertUserNotFoundOrYouDoNotHavePermission (); } -/*****************************************************************************/ -/*********************** Check if I belong to a course ***********************/ -/*****************************************************************************/ - -bool Enr_CheckIfIBelongToCrs (long CrsCod) - { - unsigned NumMyCrs; - - /***** Fill the list with the courses I belong to *****/ - Hie_GetMyHierarchy (Hie_CRS); - - /***** Check if the course passed as parameter is any of my courses *****/ - for (NumMyCrs = 0; - NumMyCrs < Gbl.Usrs.Me.Hierarchy[Hie_CRS].Num; - NumMyCrs++) - if (Gbl.Usrs.Me.Hierarchy[Hie_CRS].Nodes[NumMyCrs].HieCod == CrsCod) - return true; - - return false; - } - /*****************************************************************************/ /***** Check if user belongs (no matter if he/she has accepted or not) *******/ /***** to the current course *******/ diff --git a/swad_enrolment.h b/swad_enrolment.h index c7d1fef8..7df0ba2c 100644 --- a/swad_enrolment.h +++ b/swad_enrolment.h @@ -137,7 +137,6 @@ void Enr_CreateNewUsr2 (void); void Enr_ModifyUsr1 (void); void Enr_ModifyUsr2 (void); -bool Enr_CheckIfIBelongToCrs (long CrsCod); void Enr_FlushCacheUsrBelongsToCurrentCrs (void); bool Enr_CheckIfUsrBelongsToCurrentCrs (const struct Usr_Data *UsrDat); void Enr_FlushCacheUsrHasAcceptedInCurrentCrs (void); diff --git a/swad_forum.c b/swad_forum.c index 601ea1dc..71be16bc 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -1261,7 +1261,7 @@ void For_ShowForumList (struct For_Forums *Forums) if (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM) ICanSeeInsForum = true; else - ICanSeeInsForum = Ins_CheckIfIBelongToIns (Gbl.Hierarchy.Node[Hie_INS].HieCod); + ICanSeeInsForum = Hie_CheckIfIBelongTo (Hie_INS,Gbl.Hierarchy.Node[Hie_INS].HieCod); } else ICanSeeInsForum = false; @@ -1274,7 +1274,7 @@ void For_ShowForumList (struct For_Forums *Forums) if (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM) ICanSeeCtrForum = true; else - ICanSeeCtrForum = Ctr_CheckIfIBelongToCtr (Gbl.Hierarchy.Node[Hie_CTR].HieCod); + ICanSeeCtrForum = Hie_CheckIfIBelongTo (Hie_CTR,Gbl.Hierarchy.Node[Hie_CTR].HieCod); /***** Links to forums of current institution *****/ if (For_WriteLinksToInsForums (Forums,Gbl.Hierarchy.Node[Hie_INS].HieCod, @@ -1285,7 +1285,7 @@ void For_ShowForumList (struct For_Forums *Forums) if (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM) ICanSeeDegForum = true; else - ICanSeeDegForum = Deg_CheckIfIBelongToDeg (Gbl.Hierarchy.Node[Hie_DEG].HieCod); + ICanSeeDegForum = Hie_CheckIfIBelongTo (Hie_DEG,Gbl.Hierarchy.Node[Hie_DEG].HieCod); /***** Links to forums of current center *****/ if (For_WriteLinksToCtrForums (Forums, diff --git a/swad_hierarchy.c b/swad_hierarchy.c index 0c2ebe2a..86424f86 100644 --- a/swad_hierarchy.c +++ b/swad_hierarchy.c @@ -1040,6 +1040,26 @@ void Hie_GetMyHierarchy (Hie_Level_t Level) Gbl.Usrs.Me.Hierarchy[Level].Filled = true; } +/*****************************************************************************/ +/****** Check if I belong to a course/degree/center/institution/country ******/ +/*****************************************************************************/ + +bool Hie_CheckIfIBelongTo (Hie_Level_t Level,long HieCod) + { + unsigned NumMyNode; + + /***** Fill the list with the centers I belong to *****/ + Hie_GetMyHierarchy (Level); + + /***** Check if the node passed as parameter is any of my nodes *****/ + for (NumMyNode = 0; + NumMyNode < Gbl.Usrs.Me.Hierarchy[Level].Num; + NumMyNode++) + if (Gbl.Usrs.Me.Hierarchy[Level].Nodes[NumMyNode].HieCod == HieCod) + return true; + return false; + } + /*****************************************************************************/ /*** Flush cache that stores if a user belongs to a node of the hierarchy ****/ /*****************************************************************************/ diff --git a/swad_hierarchy.h b/swad_hierarchy.h index 9481f282..566862c9 100644 --- a/swad_hierarchy.h +++ b/swad_hierarchy.h @@ -67,6 +67,7 @@ void Hie_FreeList (Hie_Level_t Level); void Hie_ResetMyHierarchy (void); void Hie_FreeMyHierarchy (void); void Hie_GetMyHierarchy (Hie_Level_t Level); +bool Hie_CheckIfIBelongTo (Hie_Level_t Level,long HieCod); void Hie_FlushCacheUsrBelongsTo (Hie_Level_t Level); bool Hie_CheckIfUsrBelongsTo (Hie_Level_t Level,long UsrCod,long HieCod, diff --git a/swad_institution.c b/swad_institution.c index d5049437..c6d8e09a 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -1683,26 +1683,6 @@ static void Ins_FormToGoToMap (struct Hie_Node *Ins) } } -/*****************************************************************************/ -/******************** Check if I belong to an institution ********************/ -/*****************************************************************************/ - -bool Ins_CheckIfIBelongToIns (long InsCod) - { - unsigned NumMyIns; - - /***** Fill the list with the institutions I belong to *****/ - Hie_GetMyHierarchy (Hie_INS); - - /***** Check if the institution passed as parameter is any of my institutions *****/ - for (NumMyIns = 0; - NumMyIns < Gbl.Usrs.Me.Hierarchy[Hie_INS].Num; - NumMyIns++) - if (Gbl.Usrs.Me.Hierarchy[Hie_INS].Nodes[NumMyIns].HieCod == InsCod) - return true; - return false; - } - /*****************************************************************************/ /***************** Write parameter with code of institution ******************/ /*****************************************************************************/ diff --git a/swad_institution.h b/swad_institution.h index ac72023d..5152c5f0 100644 --- a/swad_institution.h +++ b/swad_institution.h @@ -70,8 +70,6 @@ unsigned Ins_GetCachedNumInssWithUsrs (Rol_Role_t Role); void Ins_ListInssFound (MYSQL_RES **mysql_res,unsigned NumInss); -bool Ins_CheckIfIBelongToIns (long InsCod); - void Ins_PutParInsCod (void *InsCod); //-------------------------------- Figures ------------------------------------ diff --git a/swad_role.c b/swad_role.c index 39cd79be..216c6a6d 100644 --- a/swad_role.c +++ b/swad_role.c @@ -143,7 +143,7 @@ void Rol_SetMyRoles (void) if (Gbl.Usrs.Me.IBelongToCurrentCrs) Gbl.Usrs.Me.IBelongToCurrentDeg = true; else - Gbl.Usrs.Me.IBelongToCurrentDeg = Deg_CheckIfIBelongToDeg (Gbl.Hierarchy.Node[Hie_DEG].HieCod); + Gbl.Usrs.Me.IBelongToCurrentDeg = Hie_CheckIfIBelongTo (Hie_DEG,Gbl.Hierarchy.Node[Hie_DEG].HieCod); } else Gbl.Usrs.Me.IBelongToCurrentDeg = false; @@ -154,7 +154,7 @@ void Rol_SetMyRoles (void) if (Gbl.Usrs.Me.IBelongToCurrentDeg) Gbl.Usrs.Me.IBelongToCurrentCtr = true; else - Gbl.Usrs.Me.IBelongToCurrentCtr = Ctr_CheckIfIBelongToCtr (Gbl.Hierarchy.Node[Hie_CTR].HieCod); + Gbl.Usrs.Me.IBelongToCurrentCtr = Hie_CheckIfIBelongTo (Hie_CTR,Gbl.Hierarchy.Node[Hie_CTR].HieCod); } else Gbl.Usrs.Me.IBelongToCurrentCtr = false; @@ -165,7 +165,7 @@ void Rol_SetMyRoles (void) if (Gbl.Usrs.Me.IBelongToCurrentCtr) Gbl.Usrs.Me.IBelongToCurrentIns = true; else - Gbl.Usrs.Me.IBelongToCurrentIns = Ins_CheckIfIBelongToIns (Gbl.Hierarchy.Node[Hie_INS].HieCod); + Gbl.Usrs.Me.IBelongToCurrentIns = Hie_CheckIfIBelongTo (Hie_INS,Gbl.Hierarchy.Node[Hie_INS].HieCod); } else Gbl.Usrs.Me.IBelongToCurrentIns = false; diff --git a/swad_survey.c b/swad_survey.c index 615c8976..7cc0bd0e 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -965,16 +965,16 @@ static void Svy_SetAllowedAndHiddenScopes (unsigned *ScopesAllowed, // ...but not belonging to the current course ********* *ScopesAllowed = 1 << Hie_SYS; *HiddenAllowed = 0; - if (Cty_CheckIfIBelongToCty (Gbl.Hierarchy.Node[Hie_CTY].HieCod)) + if (Hie_CheckIfIBelongTo (Hie_CTY,Gbl.Hierarchy.Node[Hie_CTY].HieCod)) { *ScopesAllowed |= 1 << Hie_CTY; - if (Ins_CheckIfIBelongToIns (Gbl.Hierarchy.Node[Hie_INS].HieCod)) + if (Hie_CheckIfIBelongTo (Hie_INS,Gbl.Hierarchy.Node[Hie_INS].HieCod)) { *ScopesAllowed |= 1 << Hie_INS; - if (Ctr_CheckIfIBelongToCtr (Gbl.Hierarchy.Node[Hie_CTR].HieCod)) + if (Hie_CheckIfIBelongTo (Hie_CTR,Gbl.Hierarchy.Node[Hie_CTR].HieCod)) { *ScopesAllowed |= 1 << Hie_CTR; - if (Deg_CheckIfIBelongToDeg (Gbl.Hierarchy.Node[Hie_DEG].HieCod)) + if (Hie_CheckIfIBelongTo (Hie_DEG,Gbl.Hierarchy.Node[Hie_DEG].HieCod)) *ScopesAllowed |= 1 << Hie_DEG; } } @@ -983,16 +983,16 @@ static void Svy_SetAllowedAndHiddenScopes (unsigned *ScopesAllowed, case Rol_STD: // Student in current course ************************** *ScopesAllowed = 1 << Hie_SYS; *HiddenAllowed = 0; - if (Cty_CheckIfIBelongToCty (Gbl.Hierarchy.Node[Hie_CTY].HieCod)) + if (Hie_CheckIfIBelongTo (Hie_CTY,Gbl.Hierarchy.Node[Hie_CTY].HieCod)) { *ScopesAllowed |= 1 << Hie_CTY; - if (Ins_CheckIfIBelongToIns (Gbl.Hierarchy.Node[Hie_INS].HieCod)) + if (Hie_CheckIfIBelongTo (Hie_INS,Gbl.Hierarchy.Node[Hie_INS].HieCod)) { *ScopesAllowed |= 1 << Hie_INS; - if (Ctr_CheckIfIBelongToCtr (Gbl.Hierarchy.Node[Hie_CTR].HieCod)) + if (Hie_CheckIfIBelongTo (Hie_CTR,Gbl.Hierarchy.Node[Hie_CTR].HieCod)) { *ScopesAllowed |= 1 << Hie_CTR; - if (Deg_CheckIfIBelongToDeg (Gbl.Hierarchy.Node[Hie_DEG].HieCod)) + if (Hie_CheckIfIBelongTo (Hie_DEG,Gbl.Hierarchy.Node[Hie_DEG].HieCod)) { *ScopesAllowed |= 1 << Hie_DEG; if (Gbl.Usrs.Me.IBelongToCurrentCrs) @@ -1006,16 +1006,16 @@ static void Svy_SetAllowedAndHiddenScopes (unsigned *ScopesAllowed, case Rol_TCH: // Teacher in current course ************************** *ScopesAllowed = 1 << Hie_SYS; *HiddenAllowed = 0; - if (Cty_CheckIfIBelongToCty (Gbl.Hierarchy.Node[Hie_CTY].HieCod)) + if (Hie_CheckIfIBelongTo (Hie_CTY,Gbl.Hierarchy.Node[Hie_CTY].HieCod)) { *ScopesAllowed |= 1 << Hie_CTY; - if (Ins_CheckIfIBelongToIns (Gbl.Hierarchy.Node[Hie_INS].HieCod)) + if (Hie_CheckIfIBelongTo (Hie_INS,Gbl.Hierarchy.Node[Hie_INS].HieCod)) { *ScopesAllowed |= 1 << Hie_INS; - if (Ctr_CheckIfIBelongToCtr (Gbl.Hierarchy.Node[Hie_CTR].HieCod)) + if (Hie_CheckIfIBelongTo (Hie_CTR,Gbl.Hierarchy.Node[Hie_CTR].HieCod)) { *ScopesAllowed |= 1 << Hie_CTR; - if (Deg_CheckIfIBelongToDeg (Gbl.Hierarchy.Node[Hie_DEG].HieCod)) + if (Hie_CheckIfIBelongTo (Hie_DEG,Gbl.Hierarchy.Node[Hie_DEG].HieCod)) { *ScopesAllowed |= 1 << Hie_DEG; if (Gbl.Usrs.Me.IBelongToCurrentCrs) @@ -1167,28 +1167,22 @@ void Svy_GetSurveyDataByCod (struct Svy_Survey *Svy) /* Do I belong to valid groups to answer this survey? */ switch (Svy->Level) { - case Hie_UNK: // Unknown - Err_WrongHierarchyLevelExit (); - break; case Hie_SYS: // System Svy->Status.IBelongToScope = Gbl.Usrs.Me.Logged; break; case Hie_CTY: // Country - Svy->Status.IBelongToScope = Cty_CheckIfIBelongToCty (Svy->HieCod); - break; case Hie_INS: // Institution - Svy->Status.IBelongToScope = Ins_CheckIfIBelongToIns (Svy->HieCod); - break; case Hie_CTR: // Center - Svy->Status.IBelongToScope = Ctr_CheckIfIBelongToCtr (Svy->HieCod); - break; case Hie_DEG: // Degree - Svy->Status.IBelongToScope = Deg_CheckIfIBelongToDeg (Svy->HieCod); + Svy->Status.IBelongToScope = Hie_CheckIfIBelongTo (Svy->Level,Svy->HieCod); break; case Hie_CRS: // Course - Svy->Status.IBelongToScope = Enr_CheckIfIBelongToCrs (Svy->HieCod) && + Svy->Status.IBelongToScope = Hie_CheckIfIBelongTo (Svy->Level,Svy->HieCod) && Svy_DB_CheckIfICanDoThisSurveyBasedOnGrps (Svy->SvyCod); break; + default: // Unknown + Err_WrongHierarchyLevelExit (); + break; } /* Have I answered this survey? */