diff --git a/swad_center.c b/swad_center.c index 7cc5c030..9d263a65 100644 --- a/swad_center.c +++ b/swad_center.c @@ -1760,58 +1760,6 @@ static void Ctr_FormToGoToMap (struct Hie_Node *Ctr) } } -/*****************************************************************************/ -/***** Get all my centers (those of my courses) and store them in a list *****/ -/*****************************************************************************/ -/* -void Ctr_GetMyCenters (void) - { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned NumCtr; - unsigned NumCtrs; - long CtrCod; - - ***** If my centers are yet filled, there's nothing to do ***** - if (!Gbl.Usrs.Me.Hierarchy[Hie_CTR].Filled) - { - Gbl.Usrs.Me.Hierarchy[Hie_CTR].Num = 0; - Gbl.Usrs.Me.Hierarchy[Hie_CTR].Nodes = NULL; - - ***** Get my centers from database ***** - NumCtrs = Ctr_DB_GetCtrsFromUsr (&mysql_res, - Gbl.Usrs.Me.UsrDat.UsrCod,-1L); - if (NumCtrs) - { - if ((Gbl.Usrs.Me.Hierarchy[Hie_CTR].Nodes = malloc (NumCtrs * - sizeof (*Gbl.Usrs.Me.Hierarchy[Hie_CTR].Nodes))) == NULL) - Err_NotEnoughMemoryExit (); - for (NumCtr = 0; - NumCtr < NumCtrs; - NumCtr++) - { - * Get next center * - row = mysql_fetch_row (mysql_res); - - * Get center code * - if ((CtrCod = Str_ConvertStrCodToLongCod (row[0])) > 0) - { - Gbl.Usrs.Me.Hierarchy[Hie_CTR].Nodes[Gbl.Usrs.Me.Hierarchy[Hie_CTR].Num].HieCod = CtrCod; - Gbl.Usrs.Me.Hierarchy[Hie_CTR].Nodes[Gbl.Usrs.Me.Hierarchy[Hie_CTR].Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]); - - Gbl.Usrs.Me.Hierarchy[Hie_CTR].Num++; - } - } - } - - ***** Free structure that stores the query result ***** - DB_FreeMySQLResult (&mysql_res); - - ***** Set boolean that indicates that my centers are yet filled ***** - Gbl.Usrs.Me.Hierarchy[Hie_CTR].Filled = true; - } - } -*/ /*****************************************************************************/ /*********************** Check if I belong to a center ***********************/ /*****************************************************************************/ @@ -1821,7 +1769,6 @@ bool Ctr_CheckIfIBelongToCtr (long CtrCod) unsigned NumMyCtr; /***** Fill the list with the centers I belong to *****/ - // Ctr_GetMyCenters (); Hie_GetMyHierarchy (Hie_CTR); /***** Check if the center passed as parameter is any of my centers *****/ diff --git a/swad_center.h b/swad_center.h index 9bb9a137..d2f84053 100644 --- a/swad_center.h +++ b/swad_center.h @@ -73,7 +73,6 @@ unsigned Ctr_GetCachedNumCtrsWithUsrs (Rol_Role_t Role); void Ctr_ListCtrsFound (MYSQL_RES **mysql_res,unsigned NumCtrs); -// void Ctr_GetMyCenters (void); bool Ctr_CheckIfIBelongToCtr (long CtrCod); #endif diff --git a/swad_center_database.c b/swad_center_database.c index 32b83d5a..fd531439 100644 --- a/swad_center_database.c +++ b/swad_center_database.c @@ -720,14 +720,13 @@ unsigned Ctr_DB_GetCtrsWithCoordsInCurrentIns (MYSQL_RES **mysql_res) } /*****************************************************************************/ -/***************** Get the centers of a user from database *******************/ +/********************** Get my centers from database *************************/ /*****************************************************************************/ // Returns the number of rows of the result -unsigned Ctr_DB_GetCtrsFromUsr (MYSQL_RES **mysql_res,long UsrCod,long HieCod) +unsigned Ctr_DB_GetMyCtrs (MYSQL_RES **mysql_res,long PrtCod) { - /***** Get from database the centers a user belongs to *****/ - if (HieCod > 0) + if (PrtCod > 0) return (unsigned) DB_QuerySELECT (mysql_res,"can not check the centers a user belongs to", "SELECT ctr_centers.CtrCod," // row[0] @@ -743,8 +742,8 @@ unsigned Ctr_DB_GetCtrsFromUsr (MYSQL_RES **mysql_res,long UsrCod,long HieCod) " AND ctr_centers.InsCod=%ld" " GROUP BY ctr_centers.CtrCod" " ORDER BY ctr_centers.ShortName", - UsrCod, - HieCod); + Gbl.Usrs.Me.UsrDat.UsrCod, + PrtCod); else return (unsigned) DB_QuerySELECT (mysql_res,"can not check the centers a user belongs to", @@ -760,7 +759,7 @@ unsigned Ctr_DB_GetCtrsFromUsr (MYSQL_RES **mysql_res,long UsrCod,long HieCod) " AND deg_degrees.CtrCod=ctr_centers.CtrCod" " GROUP BY ctr_centers.CtrCod" " ORDER BY ctr_centers.ShortName", - UsrCod); + Gbl.Usrs.Me.UsrDat.UsrCod); } /*****************************************************************************/ diff --git a/swad_center_database.h b/swad_center_database.h index 77bfd09b..5248ff0b 100644 --- a/swad_center_database.h +++ b/swad_center_database.h @@ -85,7 +85,7 @@ void Ctr_DB_GetAvgCoordAndZoomInCurrentIns (struct Map_Coordinates *Coord,unsign unsigned Ctr_DB_GetCtrsWithCoords (MYSQL_RES **mysql_res); unsigned Ctr_DB_GetCtrsWithCoordsInCurrentIns (MYSQL_RES **mysql_res); -unsigned Ctr_DB_GetCtrsFromUsr (MYSQL_RES **mysql_res,long UsrCod,long HieCod); +unsigned Ctr_DB_GetMyCtrs (MYSQL_RES **mysql_res,long PrtCod); bool Ctr_DB_CheckIfUsrBelongsToCtr (long UsrCod,long HieCod, bool CountOnlyAcceptedCourses); unsigned Ctr_DB_GetNumUsrsWhoClaimToBelongToCtr (long CtrCod); diff --git a/swad_changelog.h b/swad_changelog.h index f07f899a..b9efd9ea 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -632,12 +632,13 @@ 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 (2023-10-03)" +#define Log_PLATFORM_VERSION "SWAD 23.23.1 (2023-10-03)" #define CSS_FILE "swad23.16.1.css" #define JS_FILE "swad22.49.js" /* - Version 23.23: Oct 03, 2023 Code refactoring un user's hierarchy. (336620 lines) - Version 23.22: Oct 03, 2023 Code refactoring un user's hierarchy. (336518 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) Version 23.21: Oct 03, 2023 User's hierarchy is allocated dinamically. (336598 lines) Version 23.20.1: Oct 02, 2023 Fixed minor CSS issue in games and exams. (336576 lines) Version 23.20: Sep 29, 2023 Removed button to change between view and edit mode in in file browser. (336571 lines) diff --git a/swad_chat.c b/swad_chat.c index 409607db..a386e319 100644 --- a/swad_chat.c +++ b/swad_chat.c @@ -126,7 +126,6 @@ void Cht_ShowListOfAvailableChatRooms (void) char ThisRoomFullName[Cht_MAX_BYTES_ROOM_FULL_NAME + 1]; /***** Fill the list with the degrees I belong to *****/ - // Deg_GetMyDegrees (); Hie_GetMyHierarchy (Hie_DEG); /***** Begin box *****/ @@ -407,9 +406,7 @@ void Cht_OpenChatWindow (void) Err_ShowErrorAndExit ("Wrong code of chat room."); /***** Fill the lists with the degrees and courses I belong to *****/ - // Deg_GetMyDegrees (); Hie_GetMyHierarchy (Hie_DEG); - // Enr_GetMyCourses (); Hie_GetMyHierarchy (Hie_CRS); /***** Build my user's name *****/ diff --git a/swad_country.c b/swad_country.c index c31b3510..f526afe1 100644 --- a/swad_country.c +++ b/swad_country.c @@ -1774,57 +1774,6 @@ static void Cty_FormToGoToMap (struct Hie_Node *Cty) } } -/*****************************************************************************/ -/**** Get all my countries (those of my courses) and store them in a list ****/ -/*****************************************************************************/ -/* -void Cty_GetMyCountrs (void) - { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned NumCty; - unsigned NumCtys; - long CtyCod; - - ***** If my countries are yet filled, there's nothing to do ***** - if (!Gbl.Usrs.Me.Hierarchy[Hie_CTY].Filled) - { - Gbl.Usrs.Me.Hierarchy[Hie_CTY].Num = 0; - Gbl.Usrs.Me.Hierarchy[Hie_CTY].Nodes = NULL; - - ***** Get my countries from database ***** - NumCtys = Cty_DB_GetCtysFromUsr (&mysql_res,Gbl.Usrs.Me.UsrDat.UsrCod,-1L); - if (NumCtys) - { - if ((Gbl.Usrs.Me.Hierarchy[Hie_CTY].Nodes = malloc (NumCtys * - sizeof (*Gbl.Usrs.Me.Hierarchy[Hie_CTY].Nodes))) == NULL) - Err_NotEnoughMemoryExit (); - for (NumCty = 0; - NumCty < NumCtys; - NumCty++) - { - * Get next country * - row = mysql_fetch_row (mysql_res); - - * Get country code * - if ((CtyCod = Str_ConvertStrCodToLongCod (row[0])) > 0) - { - Gbl.Usrs.Me.Hierarchy[Hie_CTY].Nodes[Gbl.Usrs.Me.Hierarchy[Hie_CTY].Num].HieCod = CtyCod; - Gbl.Usrs.Me.Hierarchy[Hie_CTY].Nodes[Gbl.Usrs.Me.Hierarchy[Hie_CTY].Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]); - - Gbl.Usrs.Me.Hierarchy[Hie_CTY].Num++; - } - } - } - - ***** Free structure that stores the query result ***** - DB_FreeMySQLResult (&mysql_res); - - ***** Set boolean that indicates that my institutions are yet filled ***** - Gbl.Usrs.Me.Hierarchy[Hie_CTY].Filled = true; - } - } -*/ /*****************************************************************************/ /********************** Check if I belong to a country **********************/ /*****************************************************************************/ @@ -1834,7 +1783,6 @@ bool Cty_CheckIfIBelongToCty (long CtyCod) unsigned NumMyCty; /***** Fill the list with the institutions I belong to *****/ - // Cty_GetMyCountrs (); Hie_GetMyHierarchy (Hie_CTY); /***** Check if the country passed as parameter is any of my countries *****/ diff --git a/swad_country.h b/swad_country.h index 75685c26..60a80804 100644 --- a/swad_country.h +++ b/swad_country.h @@ -84,7 +84,6 @@ unsigned Cty_GetCachedNumCtysWithUsrs (Rol_Role_t Role); void Cty_ListCtysFound (MYSQL_RES **mysql_res,unsigned NumCtys); -// void Cty_GetMyCountrs (void); bool Cty_CheckIfIBelongToCty (long CtyCod); void Cty_FlushCacheNumUsrsWhoDontClaimToBelongToAnyCty (void); diff --git a/swad_country_database.c b/swad_country_database.c index b7311b0e..383916f9 100644 --- a/swad_country_database.c +++ b/swad_country_database.c @@ -595,12 +595,12 @@ void Cty_DB_UpdateCtyMapAttr (const char NewMapAttribution[Med_MAX_BYTES_ATTRIBU } /*****************************************************************************/ -/**************** Get the countries of a user from database ******************/ +/********************* Get my countries from database ************************/ /*****************************************************************************/ // Returns the number of rows of the result -unsigned Cty_DB_GetCtysFromUsr (MYSQL_RES **mysql_res, - long UsrCod,__attribute__((unused)) long HieCod) +unsigned Cty_DB_GetMyCtys (MYSQL_RES **mysql_res, + __attribute__((unused)) long PrtCod) { extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; @@ -622,7 +622,7 @@ unsigned Cty_DB_GetCtysFromUsr (MYSQL_RES **mysql_res, " AND ins_instits.CtyCod=cty_countrs.CtyCod" " GROUP BY cty_countrs.CtyCod" " ORDER BY cty_countrs.Name_%s", - UsrCod, + Gbl.Usrs.Me.UsrDat.UsrCod, Lan_STR_LANG_ID[Gbl.Prefs.Language]); } diff --git a/swad_country_database.h b/swad_country_database.h index d4fd6b91..0df91340 100644 --- a/swad_country_database.h +++ b/swad_country_database.h @@ -75,8 +75,8 @@ bool Cty_DB_CheckIfMapIsAvailable (long CtyCod); void Cty_DB_UpdateCtyField (long CtyCod,const char *FldName,const char *FldValue); void Cty_DB_UpdateCtyMapAttr (const char NewMapAttribution[Med_MAX_BYTES_ATTRIBUTION + 1]); -unsigned Cty_DB_GetCtysFromUsr (MYSQL_RES **mysql_res, - long UsrCod,__attribute__((unused)) long HieCod); +unsigned Cty_DB_GetMyCtys (MYSQL_RES **mysql_res, + __attribute__((unused)) long PrtCod); unsigned Cty_DB_GetNumUsrsWhoDontClaimToBelongToAnyCty (void); unsigned Cty_DB_GetNumUsrsWhoClaimToBelongToAnotherCty (void); unsigned Cty_DB_GetNumUsrsWhoClaimToBelongToCty (long CtyCod); diff --git a/swad_course.c b/swad_course.c index a18f5fe1..44802880 100644 --- a/swad_course.c +++ b/swad_course.c @@ -199,7 +199,7 @@ static void Crs_WriteListMyCoursesToSelectOne (void) HTM_LI_End (); /***** Get my countries *****/ - NumCtys = Cty_DB_GetCtysFromUsr (&mysql_resCty,Gbl.Usrs.Me.UsrDat.UsrCod,-1L); + NumCtys = Cty_DB_GetMyCtys (&mysql_resCty,-1L); for (NumCty = 0; NumCty < NumCtys; NumCty++) @@ -231,9 +231,8 @@ static void Crs_WriteListMyCoursesToSelectOne (void) HTM_LI_End (); /***** Get my institutions in this country *****/ - NumInss = Ins_DB_GetInssFromUsr (&mysql_resIns, - Gbl.Usrs.Me.UsrDat.UsrCod, - Hie[Hie_CTY].HieCod); + NumInss = Ins_DB_GetMyInss (&mysql_resIns, + Hie[Hie_CTY].HieCod); for (NumIns = 0; NumIns < NumInss; NumIns++) @@ -268,9 +267,7 @@ static void Crs_WriteListMyCoursesToSelectOne (void) HTM_LI_End (); /***** Get my centers in this institution *****/ - NumCtrs = Ctr_DB_GetCtrsFromUsr (&mysql_resCtr, - Gbl.Usrs.Me.UsrDat.UsrCod, - Hie[Hie_INS].HieCod); + NumCtrs = Ctr_DB_GetMyCtrs (&mysql_resCtr,Hie[Hie_INS].HieCod); for (NumCtr = 0; NumCtr < NumCtrs; NumCtr++) @@ -305,9 +302,7 @@ static void Crs_WriteListMyCoursesToSelectOne (void) HTM_LI_End (); /***** Get my degrees in this center *****/ - NumDegs = Deg_DB_GetDegsFromUsr (&mysql_resDeg, - Gbl.Usrs.Me.UsrDat.UsrCod, - Hie[Hie_CTR].HieCod); + NumDegs = Deg_DB_GetMyDegs (&mysql_resDeg,Hie[Hie_CTR].HieCod); for (NumDeg = 0; NumDeg < NumDegs; NumDeg++) @@ -575,7 +570,6 @@ void Crs_WriteSelectorMyCoursesInBreadcrumb (void) /***** Fill the list with the courses I belong to, if not filled *****/ if (Gbl.Usrs.Me.Logged) - // Enr_GetMyCourses (); Hie_GetMyHierarchy (Hie_CRS); /***** Begin form *****/ @@ -1955,7 +1949,6 @@ static void Crs_PutButtonToRegisterInCrs (void) void Crs_ReqSelectOneOfMyCourses (void) { /***** Fill the list with the courses I belong to, if not filled *****/ - // Enr_GetMyCourses (); Hie_GetMyHierarchy (Hie_CRS); /***** Select one of my courses *****/ diff --git a/swad_degree.c b/swad_degree.c index d689b565..04ae416d 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -1642,58 +1642,6 @@ static void Deg_EditingDegreeDestructor (void) } } -/*****************************************************************************/ -/***** Get all my degrees (those of my courses) and store them in a list *****/ -/*****************************************************************************/ -/* -void Deg_GetMyDegrees (void) - { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned NumDeg; - unsigned NumDegs; - long DegCod; - - ***** If my degrees are yet filled, there's nothing to do ***** - if (!Gbl.Usrs.Me.Hierarchy[Hie_DEG].Filled) - { - Gbl.Usrs.Me.Hierarchy[Hie_DEG].Num = 0; - Gbl.Usrs.Me.Hierarchy[Hie_DEG].Nodes = NULL; - - ***** Get my degrees from database ***** - NumDegs = Deg_DB_GetDegsFromUsr (&mysql_res, - Gbl.Usrs.Me.UsrDat.UsrCod,-1L); - if (NumDegs) - { - if ((Gbl.Usrs.Me.Hierarchy[Hie_DEG].Nodes = malloc (NumDegs * - sizeof (*Gbl.Usrs.Me.Hierarchy[Hie_DEG].Nodes))) == NULL) - Err_NotEnoughMemoryExit (); - for (NumDeg = 0; - NumDeg < NumDegs; - NumDeg++) - { - * Get next degree * - row = mysql_fetch_row (mysql_res); - - * Get degree code * - if ((DegCod = Str_ConvertStrCodToLongCod (row[0])) > 0) - { - Gbl.Usrs.Me.Hierarchy[Hie_DEG].Nodes[Gbl.Usrs.Me.Hierarchy[Hie_DEG].Num].HieCod = DegCod; - Gbl.Usrs.Me.Hierarchy[Hie_DEG].Nodes[Gbl.Usrs.Me.Hierarchy[Hie_DEG].Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]); - - Gbl.Usrs.Me.Hierarchy[Hie_DEG].Num++; - } - } - } - - ***** Free structure that stores the query result ***** - DB_FreeMySQLResult (&mysql_res); - - ***** Set boolean that indicates that my degrees are yet filled ***** - Gbl.Usrs.Me.Hierarchy[Hie_DEG].Filled = true; - } - } -*/ /*****************************************************************************/ /*********************** Check if I belong to a degree ***********************/ /*****************************************************************************/ @@ -1703,7 +1651,6 @@ bool Deg_CheckIfIBelongToDeg (long DegCod) unsigned NumMyDeg; /***** Fill the list with the degrees I belong to *****/ - // Deg_GetMyDegrees (); Hie_GetMyHierarchy (Hie_DEG); /***** Check if the degree passed as parameter is any of my degrees *****/ diff --git a/swad_degree.h b/swad_degree.h index d5cda7de..dac4dcdb 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); -// void Deg_GetMyDegrees (void); bool Deg_CheckIfIBelongToDeg (long DegCod); void Deg_GetUsrMainDeg (long UsrCod, char ShrtName[Hie_MAX_BYTES_SHRT_NAME + 1], diff --git a/swad_degree_database.c b/swad_degree_database.c index dfb376e4..99a247ad 100644 --- a/swad_degree_database.c +++ b/swad_degree_database.c @@ -757,13 +757,13 @@ void Deg_DB_UpdateDegStatus (long DegCod,Hie_Status_t NewStatus) } /*****************************************************************************/ -/***************** Get the degrees of a user from database *******************/ +/********************** Get my degrees from database *************************/ /*****************************************************************************/ // Returns the number of rows of the result -unsigned Deg_DB_GetDegsFromUsr (MYSQL_RES **mysql_res,long UsrCod,long HieCod) +unsigned Deg_DB_GetMyDegs (MYSQL_RES **mysql_res,long PrtCod) { - if (HieCod > 0) + if (PrtCod > 0) return (unsigned) DB_QuerySELECT (mysql_res,"can not check the degrees a user belongs to", "SELECT deg_degrees.DegCod," // row[0] @@ -777,8 +777,8 @@ unsigned Deg_DB_GetDegsFromUsr (MYSQL_RES **mysql_res,long UsrCod,long HieCod) " AND deg_degrees.CtrCod=%ld" " GROUP BY deg_degrees.DegCod" " ORDER BY deg_degrees.ShortName", - UsrCod, - HieCod); + Gbl.Usrs.Me.UsrDat.UsrCod, + PrtCod); else return (unsigned) DB_QuerySELECT (mysql_res,"can not check the degrees a user belongs to", @@ -792,7 +792,7 @@ unsigned Deg_DB_GetDegsFromUsr (MYSQL_RES **mysql_res,long UsrCod,long HieCod) " AND crs_courses.DegCod=deg_degrees.DegCod" " GROUP BY deg_degrees.DegCod" " ORDER BY deg_degrees.ShortName", - UsrCod); + Gbl.Usrs.Me.UsrDat.UsrCod); } /*****************************************************************************/ diff --git a/swad_degree_database.h b/swad_degree_database.h index 1b288764..0054a9df 100644 --- a/swad_degree_database.h +++ b/swad_degree_database.h @@ -80,7 +80,7 @@ void Deg_DB_UpdateDegTyp (long DegCod,long NewDegTypCod); void Deg_DB_UpdateDegWWW (long DegCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]); void Deg_DB_UpdateDegStatus (long DegCod,Hie_Status_t NewStatus); -unsigned Deg_DB_GetDegsFromUsr (MYSQL_RES **mysql_res,long UsrCod,long HieCod); +unsigned Deg_DB_GetMyDegs (MYSQL_RES **mysql_res,long HieCod); unsigned Deg_DB_GetUsrMainDeg (MYSQL_RES **mysql_res,long UsrCod); bool Deg_DB_CheckIfUsrBelongsToDeg (long UsrCod,long HieCod, bool CountOnlyAcceptedCourses); diff --git a/swad_enrolment.c b/swad_enrolment.c index 9b12cb35..973d042c 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -3189,7 +3189,6 @@ static void Enr_EffectivelyRemUsrFromCrs (struct Usr_Data *UsrDat, /* Fill the list with the courses I belong to */ Gbl.Usrs.Me.Hierarchy[Hie_CRS].Filled = false; - // Enr_GetMyCourses (); Hie_GetMyHierarchy (Hie_CRS); /* Set my roles */ @@ -3222,70 +3221,6 @@ static void Enr_EffectivelyRemUsrFromCrs (struct Usr_Data *UsrDat, Ale_CreateAlertUserNotFoundOrYouDoNotHavePermission (); } -/*****************************************************************************/ -/*************** Get all my courses and store them in a list *****************/ -/*****************************************************************************/ -/* -void Enr_GetMyCourses (void) - { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned NumCrss; - unsigned NumCrs; - long CrsCod; - - ***** Trivial check 1: if my courses are already filled, there's nothing to do ***** - if (Gbl.Usrs.Me.Hierarchy[Hie_CRS].Filled) - return; - - ***** Trivial check 2: if user's code is not set, don't query database ***** - if (Gbl.Usrs.Me.UsrDat.UsrCod <= 0) - return; - - ***** Remove temporary table with my courses ***** - Enr_DB_DropTmpTableMyCourses (); - - ***** Create temporary table with my courses ***** - Enr_DB_CreateTmpTableMyCourses (); - - ***** Get my courses from database ***** - Gbl.Usrs.Me.Hierarchy[Hie_CRS].Num = 0; - Gbl.Usrs.Me.Hierarchy[Hie_CRS].Nodes = NULL; - - NumCrss = Enr_DB_GetMyCourses (&mysql_res); - if (NumCrss) - { - if ((Gbl.Usrs.Me.Hierarchy[Hie_CRS].Nodes = malloc (NumCrss * - sizeof (*Gbl.Usrs.Me.Hierarchy[Hie_CRS].Nodes))) == NULL) - Err_NotEnoughMemoryExit (); - for (NumCrs = 0; - NumCrs < NumCrss; - NumCrs++) - { - * Get next course * - row = mysql_fetch_row (mysql_res); - - * Get course code (row[0]) * - if ((CrsCod = Str_ConvertStrCodToLongCod (row[0])) > 0) - { - Gbl.Usrs.Me.Hierarchy[Hie_CRS].Nodes[Gbl.Usrs.Me.Hierarchy[Hie_CRS].Num].HieCod = CrsCod; - - * Get role (row[1]) and degree code (row[2]) * - Gbl.Usrs.Me.Hierarchy[Hie_CRS].Nodes[Gbl.Usrs.Me.Hierarchy[Hie_CRS].Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]); - Gbl.Usrs.Me.Hierarchy[Hie_CRS].Nodes[Gbl.Usrs.Me.Hierarchy[Hie_CRS].Num].PrtCod = Str_ConvertStrCodToLongCod (row[2]); - - Gbl.Usrs.Me.Hierarchy[Hie_CRS].Num++; - } - } - } - - ***** Free structure that stores the query result ***** - DB_FreeMySQLResult (&mysql_res); - - ***** Set boolean that indicates that my courses are already filled ***** - Gbl.Usrs.Me.Hierarchy[Hie_CRS].Filled = true; - } -*/ /*****************************************************************************/ /*********************** Check if I belong to a course ***********************/ /*****************************************************************************/ @@ -3295,7 +3230,6 @@ bool Enr_CheckIfIBelongToCrs (long CrsCod) unsigned NumMyCrs; /***** Fill the list with the courses I belong to *****/ - // Enr_GetMyCourses (); Hie_GetMyHierarchy (Hie_CRS); /***** Check if the course passed as parameter is any of my courses *****/ diff --git a/swad_enrolment.h b/swad_enrolment.h index d1ad47a2..c7d1fef8 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); -// void Enr_GetMyCourses (void); bool Enr_CheckIfIBelongToCrs (long CrsCod); void Enr_FlushCacheUsrBelongsToCurrentCrs (void); bool Enr_CheckIfUsrBelongsToCurrentCrs (const struct Usr_Data *UsrDat); diff --git a/swad_enrolment_database.c b/swad_enrolment_database.c index 757270fa..662a2511 100644 --- a/swad_enrolment_database.c +++ b/swad_enrolment_database.c @@ -101,9 +101,8 @@ void Enr_DB_CreateTmpTableMyCourses (void) /************************* Get my courses from database **********************/ /*****************************************************************************/ -unsigned Enr_DB_GetMyCourses (MYSQL_RES **mysql_res, - __attribute__((unused)) long UsrCod, - __attribute__((unused)) long HieCod) +unsigned Enr_DB_GetMyCrss (MYSQL_RES **mysql_res, + __attribute__((unused)) long PrtCod) { return (unsigned) DB_QuerySELECT (mysql_res,"can not get which courses you belong to", @@ -172,7 +171,6 @@ bool Enr_DB_CheckIfUsrBelongsToCrs (long UsrCod,long HieCod, bool Enr_DB_CheckIfUsrSharesAnyOfMyCrs (long UsrCod) { /***** Fill the list with the courses I belong to (if not already filled) *****/ - // Enr_GetMyCourses (); Hie_GetMyHierarchy (Hie_CRS); /***** Check if user shares any course with me *****/ @@ -203,7 +201,6 @@ bool Enr_DB_CheckIfUsrSharesAnyOfMyCrsWithDifferentRole (long UsrCod) /***** 2. Slow check: Get if user shares any course with me with a different role, from database *****/ /* Fill the list with the courses I belong to (if not already filled) */ - // Enr_GetMyCourses (); Hie_GetMyHierarchy (Hie_CRS); /* Remove temporary table if exists */ diff --git a/swad_enrolment_database.h b/swad_enrolment_database.h index 1b1cfab0..7de5b4f3 100644 --- a/swad_enrolment_database.h +++ b/swad_enrolment_database.h @@ -40,9 +40,8 @@ void Enr_DB_InsertUsrInCurrentCrs (long UsrCod,long CrsCod,Rol_Role_t NewRole, void Enr_DB_AcceptUsrInCrs (long UsrCod,long CrsCod); void Enr_DB_CreateTmpTableMyCourses (void); -unsigned Enr_DB_GetMyCourses (MYSQL_RES **mysql_res, - __attribute__((unused)) long UsrCod, - __attribute__((unused)) long HieCod); +unsigned Enr_DB_GetMyCrss (MYSQL_RES **mysql_res, + __attribute__((unused)) long PrtCod); void Enr_DB_DropTmpTableMyCourses (void); unsigned Enr_DB_GetMyCoursesNames (MYSQL_RES **mysql_res); diff --git a/swad_forum.c b/swad_forum.c index 149adab0..601ea1dc 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -1238,7 +1238,6 @@ void For_ShowForumList (struct For_Forums *Forums) Forums->Thread.ToMove = For_DB_GetThrInMyClipboard (); /***** Fill the list with the institutions I belong to *****/ - // Ins_GetMyInstits (); Hie_GetMyHierarchy (Hie_INS); /***** Begin box *****/ @@ -1327,9 +1326,7 @@ void For_ShowForumList (struct For_Forums *Forums) IsLastItemInLevel); /* Get my centers in this institution from database */ - NumCtrs = Ctr_DB_GetCtrsFromUsr (&mysql_resCtr, - Gbl.Usrs.Me.UsrDat.UsrCod, - InsCod); + NumCtrs = Ctr_DB_GetMyCtrs (&mysql_resCtr,InsCod); for (NumCtr = 0; NumCtr < NumCtrs; NumCtr++) @@ -1345,9 +1342,7 @@ void For_ShowForumList (struct For_Forums *Forums) IsLastItemInLevel) > 0) { /* Get my degrees in this institution from database */ - NumDegs = Deg_DB_GetDegsFromUsr (&mysql_resDeg, - Gbl.Usrs.Me.UsrDat.UsrCod, - CtrCod); + NumDegs = Deg_DB_GetMyDegs (&mysql_resDeg,CtrCod); for (NumDeg = 0; NumDeg < NumDegs; NumDeg++) diff --git a/swad_hierarchy.c b/swad_hierarchy.c index 82efbd82..0c2ebe2a 100644 --- a/swad_hierarchy.c +++ b/swad_hierarchy.c @@ -975,13 +975,13 @@ void Hie_GetMyHierarchy (Hie_Level_t Level) unsigned NumNodes; long HieCod; static unsigned (*GetNodesFromDB[Hie_NUM_LEVELS]) (MYSQL_RES **mysql_res, - long UsrCod,long HieCod) = + long PrtCod) = { - [Hie_CTY] = Cty_DB_GetCtysFromUsr, - [Hie_INS] = Ins_DB_GetInssFromUsr, - [Hie_CTR] = Ctr_DB_GetCtrsFromUsr, - [Hie_DEG] = Deg_DB_GetDegsFromUsr, - [Hie_CRS] = Enr_DB_GetMyCourses, + [Hie_CTY] = Cty_DB_GetMyCtys, + [Hie_INS] = Ins_DB_GetMyInss, + [Hie_CTR] = Ctr_DB_GetMyCtrs, + [Hie_DEG] = Deg_DB_GetMyDegs, + [Hie_CRS] = Enr_DB_GetMyCrss, }; /***** Trivial check 1: if list of nodes is already filled, there's nothing to do *****/ @@ -1004,8 +1004,7 @@ void Hie_GetMyHierarchy (Hie_Level_t Level) Gbl.Usrs.Me.Hierarchy[Level].Nodes = NULL; /***** Get my courses/degrees/centers/institutions/countries from database *****/ - NumNodes = GetNodesFromDB[Level] (&mysql_res,Gbl.Usrs.Me.UsrDat.UsrCod,-1L); - if (NumNodes) + if ((NumNodes = GetNodesFromDB[Level] (&mysql_res,-1L))) { if ((Gbl.Usrs.Me.Hierarchy[Level].Nodes = malloc (NumNodes * sizeof (*Gbl.Usrs.Me.Hierarchy[Level].Nodes))) == NULL) diff --git a/swad_institution.c b/swad_institution.c index bf40c1bf..d5049437 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -1683,59 +1683,6 @@ static void Ins_FormToGoToMap (struct Hie_Node *Ins) } } -/*****************************************************************************/ -/** Get all my institutions (those of my courses) and store them in a list ***/ -/*****************************************************************************/ -/* -void Ins_GetMyInstits (void) - { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned NumIns; - unsigned NumInss; - long InsCod; - - ***** If my institutions are yet filled, there's nothing to do ***** - if (!Gbl.Usrs.Me.Hierarchy[Hie_INS].Filled) - { - Gbl.Usrs.Me.Hierarchy[Hie_INS].Num = 0; - Gbl.Usrs.Me.Hierarchy[Hie_INS].Nodes = NULL; - - ***** Get my institutions from database ***** - NumInss = Ins_DB_GetInssFromUsr (&mysql_res, - Gbl.Usrs.Me.UsrDat.UsrCod,-1L); - if (NumInss) - { - if ((Gbl.Usrs.Me.Hierarchy[Hie_INS].Nodes = malloc (NumInss * - sizeof (*Gbl.Usrs.Me.Hierarchy[Hie_INS].Nodes))) == NULL) - Err_NotEnoughMemoryExit (); - for (NumIns = 0; - NumIns < NumInss; - NumIns++) - { - * Get next institution * - row = mysql_fetch_row (mysql_res); - - * Get institution code * - if ((InsCod = Str_ConvertStrCodToLongCod (row[0])) > 0) - { - Gbl.Usrs.Me.Hierarchy[Hie_INS].Nodes[Gbl.Usrs.Me.Hierarchy[Hie_INS].Num].HieCod = InsCod; - Gbl.Usrs.Me.Hierarchy[Hie_INS].Nodes[Gbl.Usrs.Me.Hierarchy[Hie_INS].Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]); - - Gbl.Usrs.Me.Hierarchy[Hie_INS].Num++; - } - } - } - - - ***** Free structure that stores the query result ***** - DB_FreeMySQLResult (&mysql_res); - - ***** Set boolean that indicates that my institutions are yet filled ***** - Gbl.Usrs.Me.Hierarchy[Hie_INS].Filled = true; - } - } -*/ /*****************************************************************************/ /******************** Check if I belong to an institution ********************/ /*****************************************************************************/ @@ -1745,7 +1692,6 @@ bool Ins_CheckIfIBelongToIns (long InsCod) unsigned NumMyIns; /***** Fill the list with the institutions I belong to *****/ - // Ins_GetMyInstits (); Hie_GetMyHierarchy (Hie_INS); /***** Check if the institution passed as parameter is any of my institutions *****/ diff --git a/swad_institution.h b/swad_institution.h index c5f1e171..ac72023d 100644 --- a/swad_institution.h +++ b/swad_institution.h @@ -70,7 +70,6 @@ unsigned Ins_GetCachedNumInssWithUsrs (Rol_Role_t Role); void Ins_ListInssFound (MYSQL_RES **mysql_res,unsigned NumInss); -// void Ins_GetMyInstits (void); bool Ins_CheckIfIBelongToIns (long InsCod); void Ins_PutParInsCod (void *InsCod); diff --git a/swad_institution_database.c b/swad_institution_database.c index ef2ec7fe..f909bba6 100644 --- a/swad_institution_database.c +++ b/swad_institution_database.c @@ -756,13 +756,13 @@ unsigned Ins_DB_GetNumInnsWithUsrs (Rol_Role_t Role, } /*****************************************************************************/ -/************** Get the institutions of a user from database *****************/ +/******************* Get my institutions from database ***********************/ /*****************************************************************************/ // Returns the number of rows of the result -unsigned Ins_DB_GetInssFromUsr (MYSQL_RES **mysql_res,long UsrCod,long HieCod) +unsigned Ins_DB_GetMyInss (MYSQL_RES **mysql_res,long PrtCod) { - if (HieCod > 0) + if (PrtCod > 0) return (unsigned) DB_QuerySELECT (mysql_res,"can not get the institutions a user belongs to", "SELECT ins_instits.InsCod," // row[0] @@ -780,8 +780,8 @@ unsigned Ins_DB_GetInssFromUsr (MYSQL_RES **mysql_res,long UsrCod,long HieCod) " AND ins_instits.CtyCod=%ld" " GROUP BY ins_instits.InsCod" " ORDER BY ins_instits.ShortName", - UsrCod, - HieCod); + Gbl.Usrs.Me.UsrDat.UsrCod, + PrtCod); else return (unsigned) DB_QuerySELECT (mysql_res,"can not get the institutions a user belongs to", @@ -799,7 +799,7 @@ unsigned Ins_DB_GetInssFromUsr (MYSQL_RES **mysql_res,long UsrCod,long HieCod) " AND ctr_centers.InsCod=ins_instits.InsCod" " GROUP BY ins_instits.InsCod" " ORDER BY ins_instits.ShortName", - UsrCod); + Gbl.Usrs.Me.UsrDat.UsrCod); } /*****************************************************************************/ diff --git a/swad_institution_database.h b/swad_institution_database.h index 3692e6e5..802c7831 100644 --- a/swad_institution_database.h +++ b/swad_institution_database.h @@ -77,7 +77,7 @@ unsigned Ins_DB_GetNumInssWithCrss (Hie_Level_t Level,long HieCod); unsigned Ins_DB_GetNumInnsWithUsrs (Rol_Role_t Role, Hie_Level_t Level,long HieCod); -unsigned Ins_DB_GetInssFromUsr (MYSQL_RES **mysql_res,long UsrCod,long HieCod); +unsigned Ins_DB_GetMyInss (MYSQL_RES **mysql_res,long HieCod); bool Ins_DB_CheckIfUsrBelongsToIns (long UsrCod,long HieCod, bool CountOnlyAcceptedCourses); unsigned Ins_DB_GetNumUsrsWhoClaimToBelongToIns (long InsCod); diff --git a/swad_role.c b/swad_role.c index a235ea49..39cd79be 100644 --- a/swad_role.c +++ b/swad_role.c @@ -257,7 +257,6 @@ Rol_Role_t Rol_GetMyMaxRoleInIns (long InsCod) if (InsCod > 0) { /***** Fill the list with the institutions I belong to (if not already filled) *****/ - // Ins_GetMyInstits (); Hie_GetMyHierarchy (Hie_INS); /***** Check if the institution passed as parameter is any of my institutions *****/ @@ -282,7 +281,6 @@ Rol_Role_t Rol_GetMyMaxRoleInCtr (long CtrCod) if (CtrCod > 0) { /***** Fill the list with the centers I belong to (if not already filled) *****/ - // Ctr_GetMyCenters (); Hie_GetMyHierarchy (Hie_CTR); /***** Check if the center passed as parameter is any of my centers *****/ @@ -309,7 +307,6 @@ Rol_Role_t Rol_GetMyMaxRoleInDeg (long DegCod) return Rol_UNK; /***** Fill the list with the degrees I belong to (if not already filled) *****/ - // Deg_GetMyDegrees (); Hie_GetMyHierarchy (Hie_DEG); /***** Check if the degree passed as parameter is any of my degrees *****/ @@ -346,7 +343,6 @@ Rol_Role_t Rol_GetMyRoleInCrs (long CrsCod) /***** 3. Slow check: get my role from list of my courses *****/ /* Fill the list with the courses I belong to (if not already filled) */ - // Enr_GetMyCourses (); Hie_GetMyHierarchy (Hie_CRS); /* Check if the current course is any of my courses */