From 9b34ba6467291668d2f0066254a2b5e29da61f24 Mon Sep 17 00:00:00 2001 From: acanas Date: Thu, 6 Apr 2023 12:39:13 +0200 Subject: [PATCH] Version 22.91: Apr 06, 2023 Code refactoring in forums. --- swad_API.c | 2 +- swad_assignment.c | 1 + swad_assignment_resource.c | 2 - swad_attendance_resource.c | 1 - swad_changelog.h | 8 +- swad_database.c | 4 +- swad_forum.c | 208 +++++++++++++++++++++--------------- swad_forum.h | 10 +- swad_forum_database.c | 212 ++++++++++++++++++++----------------- swad_forum_database.h | 5 +- swad_forum_resource.c | 12 +-- swad_notification.c | 17 ++- swad_pagination.c | 39 +++---- swad_resource.h | 1 + swad_timeline_note.c | 4 +- 15 files changed, 291 insertions(+), 235 deletions(-) diff --git a/swad_API.c b/swad_API.c index 9bd2bcd6..d448a771 100644 --- a/swad_API.c +++ b/swad_API.c @@ -3000,7 +3000,7 @@ int swad__getNotifications (struct soap *soap, if (NotifyEvent == Ntf_EVENT_FORUM_POST_COURSE || NotifyEvent == Ntf_EVENT_FORUM_REPLY) { - For_GetForumTypeAndLocationOfAPost (Cod,&ForumSelected); + For_GetThreadForumTypeAndHieCodOfAPost (Cod,&ForumSelected); For_SetForumName (&ForumSelected, ForumName,Gbl.Prefs.Language,false); // Set forum name in recipient's language sprintf (getNotificationsOut->notificationsArray.__ptr[NumNotif].location,"%s: %s", diff --git a/swad_assignment.c b/swad_assignment.c index 32832412..354edb81 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -388,6 +388,7 @@ void Asg_SeeOneAssignment (void) Asg_ShowOneAssignmentInBox (&Assignments); /***** Show current assignments, if any *****/ + // TODO: The page should be that corresponding to the selected assignment. Asg_ShowAllAssignments (&Assignments); } diff --git a/swad_assignment_resource.c b/swad_assignment_resource.c index 62603205..d4da2340 100644 --- a/swad_assignment_resource.c +++ b/swad_assignment_resource.c @@ -96,8 +96,6 @@ void AsgRsc_WriteResourceAssignment (long AsgCod,Frm_PutFormToGo_t PutFormToGo, ActSeeAsg; // All assignments Frm_BeginForm (NextAction); ParCod_PutPar (ParCod_Asg,AsgCod); - // TODO: In the listing of assignments, the page is always the first. - // The page should be that corresponding to the selected assignment. HTM_BUTTON_Submit_Begin (Txt_Actions[NextAction], "class=\"LM BT_LINK PRG_LNK_%s\"", The_GetSuffix ()); diff --git a/swad_attendance_resource.c b/swad_attendance_resource.c index 1a1a5e53..916a6408 100644 --- a/swad_attendance_resource.c +++ b/swad_attendance_resource.c @@ -82,7 +82,6 @@ void AttRsc_WriteResourceEvent (long AttCod,Frm_PutFormToGo_t PutFormToGo, ActSeeAtt; // All attendance events Frm_BeginForm (NextAction); ParCod_PutPar (ParCod_Att,AttCod); - Att_PutParsCodGrps (AttCod); HTM_BUTTON_Submit_Begin (Txt_Actions[NextAction], "class=\"LM BT_LINK PRG_LNK_%s\"", The_GetSuffix ()); diff --git a/swad_changelog.h b/swad_changelog.h index 9c01ab8f..547e3ae5 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -629,10 +629,16 @@ TODO: Emilce Barrera Mesa: Podr TODO: Emilce Barrera Mesa: Mis estudiantes presentan muchas dificultades a la hora de poner la foto porque la plataforma es muy exigente respecto al fondo de la imagen. */ -#define Log_PLATFORM_VERSION "SWAD 22.90.1 (2023-04-04)" +#define Log_PLATFORM_VERSION "SWAD 22.91 (2023-04-04)" #define CSS_FILE "swad22.88.css" #define JS_FILE "swad22.49.js" /* + Version 22.91: Apr 06, 2023 Code refactoring in forums. (338928 lines) + 3 changes necessary in database: +ALTER TABLE for_threads CHANGE COLUMN Location HieCod INT NOT NULL DEFAULT -1; +ALTER TABLE for_threads DROP INDEX Location; +ALTER TABLE for_threads ADD INDEX (HieCod); + Version 22.90.1: Apr 04, 2023 Code refactoring in resources. (338881 lines) Version 22.90: Apr 04, 2023 Code refactoring checking user. (338807 lines) Version 22.89.1: Apr 04, 2023 Code refactoring in projects configuration. (338622 lines) diff --git a/swad_database.c b/swad_database.c index aeb96e4e..357d753e 100644 --- a/swad_database.c +++ b/swad_database.c @@ -1579,12 +1579,12 @@ mysql> DESCRIBE for_threads; DB_CreateTable ("CREATE TABLE IF NOT EXISTS for_threads (" "ThrCod INT NOT NULL AUTO_INCREMENT," "ForumType TINYINT NOT NULL," - "Location INT NOT NULL DEFAULT -1," + "HieCod INT NOT NULL DEFAULT -1," "FirstPstCod INT NOT NULL," "LastPstCod INT NOT NULL," "UNIQUE INDEX(ThrCod)," "INDEX(ForumType)," - "INDEX(Location)," + "INDEX(HieCod)," "UNIQUE INDEX(FirstPstCod)," "UNIQUE INDEX(LastPstCod))"); diff --git a/swad_forum.c b/swad_forum.c index 7102d2ba..a9e83fa3 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -317,6 +317,8 @@ static time_t For_GetThrReadTime (long ThrCod); static void For_PutIconsOneThread (void *Forums); +static void For_PutParsNewPost (void *Forums); + static void For_ShowAForumPost (struct For_Forums *Forums, unsigned PstNum, bool LastPst,char LastSubject[Cns_MAX_BYTES_SUBJECT + 1], @@ -330,7 +332,6 @@ static void For_WriteNumberOfPosts (const struct For_Forums *Forums,long UsrCod) static void For_PutParsForum (void *Forums); static void For_PutParForumSet (For_ForumSet_t ForumSet); -static void For_PutParForumLocation (long Location); static void For_PutIconsForums (__attribute__((unused)) void *Args); static void For_PutFormWhichForums (const struct For_Forums *Forums); @@ -403,7 +404,7 @@ void For_ResetForums (struct For_Forums *Forums) Forums->CurrentPagePsts = 0; Forums->Forum.Type = For_FORUM_UNKNOWN; - Forums->Forum.Location = -1L; + Forums->Forum.HieCod = -1L; Forums->Thread.Selected = Forums->Thread.Current = @@ -588,22 +589,63 @@ static void For_RemoveThreadAndItsPsts (long ThrCod) } /*****************************************************************************/ -/*************** Get the forum type and location of a post *******************/ +/*********** Get thread, forum type and hierarchy code of a post *************/ /*****************************************************************************/ +// Return thread to which the post belongs -void For_GetForumTypeAndLocationOfAPost (long PstCod,struct For_Forum *Forum) +long For_GetThreadForumTypeAndHieCodOfAPost (long PstCod,struct For_Forum *Forum) { MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned UnsignedNum; - long LongNum; + long ThrCod; - /***** Set default forum type and location *****/ + /***** Set defaults *****/ Forum->Type = For_FORUM_UNKNOWN; - Forum->Location = -1L; + Forum->HieCod = -1L; + ThrCod = -1L; /***** Check if there is a row with forum type *****/ - if (For_DB_GetForumTypeAndLocationOfAPost (&mysql_res,PstCod)) + if (For_DB_GetThreadForumTypeAndHieCodOfAPost (&mysql_res,PstCod)) + { + row = mysql_fetch_row (mysql_res); + + /* Get forum thread (row[0]) */ + if (sscanf (row[0],"%ld",&ThrCod) != 1) + Err_WrongThreadExit (); + + /* Get forum type (row[1]) */ + if (sscanf (row[1],"%u",&UnsignedNum) == 1) + if (UnsignedNum < For_NUM_TYPES_FORUM) + Forum->Type = (For_ForumType_t) UnsignedNum; + + /* Get forum hierarchy code (row[2]) */ + if (sscanf (row[2],"%ld",&Forum->HieCod) != 1) + Err_WrongForumExit (); + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + + return ThrCod; + } + +/*****************************************************************************/ +/*************** Get forum type and hierarchy code of a post *****************/ +/*****************************************************************************/ + +void For_GetForumTypeAndHieCodOfAThread (long ThrCod,struct For_Forum *Forum) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned UnsignedNum; + + /***** Set defaults *****/ + Forum->Type = For_FORUM_UNKNOWN; + Forum->HieCod = -1L; + + /***** Check if there is a row with forum type *****/ + if (For_DB_GetForumTypeAndHieCodOfAThread (&mysql_res,ThrCod)) { row = mysql_fetch_row (mysql_res); @@ -612,9 +654,9 @@ void For_GetForumTypeAndLocationOfAPost (long PstCod,struct For_Forum *Forum) if (UnsignedNum < For_NUM_TYPES_FORUM) Forum->Type = (For_ForumType_t) UnsignedNum; - /* Get forum location (row[1]) */ - if (sscanf (row[1],"%ld",&LongNum) == 1) - Forum->Location = LongNum; + /* Get forum hierarchy code (row[1]) */ + if (sscanf (row[1],"%ld",&Forum->HieCod) != 1) + Err_WrongForumExit (); } /***** Free structure that stores the query result *****/ @@ -837,14 +879,14 @@ static void For_PutIconsOneThread (void *Forums) } } -void For_PutParsNewPost (void *Forums) +static void For_PutParsNewPost (void *Forums) { if (Forums) For_PutAllParsForum (((struct For_Forums *) Forums)->CurrentPageThrs, // Page of threads = current UINT_MAX, // Page of posts = last ((struct For_Forums *) Forums)->ForumSet, ((struct For_Forums *) Forums)->ThreadsOrder, - ((struct For_Forums *) Forums)->Forum.Location, + ((struct For_Forums *) Forums)->Forum.HieCod, ((struct For_Forums *) Forums)->Thread.Current, -1L); } @@ -1039,7 +1081,7 @@ static void For_GetPstData (long PstCod,long *UsrCod,time_t *CreatTimeUTC, /***** Get creation time (row[1]) *****/ *CreatTimeUTC = Dat_GetUNIXTimeFromStr (row[1]); - /***** Get subject (row[2]) and location (row[3]) *****/ + /***** Get subject (row[2]) and content (row[3]) *****/ Str_Copy (Subject,row[2],Cns_MAX_BYTES_SUBJECT ); Str_Copy (Content,row[3],Cns_MAX_BYTES_LONG_TEXT); @@ -1124,7 +1166,7 @@ static void For_PutParsForum (void *Forums) ((struct For_Forums *) Forums)->CurrentPagePsts, // Page of posts = current ((struct For_Forums *) Forums)->ForumSet, ((struct For_Forums *) Forums)->ThreadsOrder, - ((struct For_Forums *) Forums)->Forum.Location, + ((struct For_Forums *) Forums)->Forum.HieCod, ((struct For_Forums *) Forums)->Thread.Current, ((struct For_Forums *) Forums)->PstCod); } @@ -1133,7 +1175,7 @@ void For_PutAllParsForum (unsigned NumPageThreads, unsigned NumPagePosts, For_ForumSet_t ForumSet, Dat_StartEndTime_t Order, - long Location, + long HieCod, long ThrCod, long PstCod) { @@ -1141,7 +1183,7 @@ void For_PutAllParsForum (unsigned NumPageThreads, Pag_PutParPagNum (Pag_POSTS_FORUM,NumPagePosts); For_PutParForumSet (ForumSet); Par_PutParOrder ((unsigned) Order); - For_PutParForumLocation (Location); + ParCod_PutPar (ParCod_OthHie,HieCod); ParCod_PutPar (ParCod_Thr,ThrCod); ParCod_PutPar (ParCod_Pst,PstCod); } @@ -1155,19 +1197,6 @@ static void For_PutParForumSet (For_ForumSet_t ForumSet) Par_PutParUnsigned (NULL,"ForumSet",(unsigned) ForumSet); } -/*****************************************************************************/ -/************** Put hidden parameter with code of *****************/ -/************** forum institution, center, degree and course *****************/ -/*****************************************************************************/ - -static void For_PutParForumLocation (long Location) - { - if (Location > 0) - /***** Put a hidden parameter with the - institution, center, degree or course of the forum *****/ - Par_PutParLong (NULL,"Location",Location); - } - /*****************************************************************************/ /************************** Show list of available forums ********************/ /*****************************************************************************/ @@ -1435,7 +1464,7 @@ static void For_WriteLinksToGblForums (const struct For_Forums *Forums, /***** Link to forum global *****/ Forum.Type = For_FORUM_GLOBAL_USRS; - Forum.Location = -1L; + Forum.HieCod = -1L; Highlight = (Forums->Forum.Type == For_FORUM_GLOBAL_USRS); IsLastItemInLevel[1] = false; For_WriteLinkToForum (Forums,&Forum,Highlight,1,IsLastItemInLevel); @@ -1445,7 +1474,7 @@ static void For_WriteLinksToGblForums (const struct For_Forums *Forums, if (ICanSeeTeacherForum) { Forum.Type = For_FORUM_GLOBAL_TCHS; - Forum.Location = -1L; + Forum.HieCod = -1L; Highlight = (Forums->Forum.Type == For_FORUM_GLOBAL_TCHS); IsLastItemInLevel[1] = false; For_WriteLinkToForum (Forums,&Forum,Highlight,1,IsLastItemInLevel); @@ -1472,7 +1501,7 @@ static void For_WriteLinksToPlatformForums (const struct For_Forums *Forums, /***** Link to forum of users about the platform *****/ Forum.Type = For_FORUM__SWAD__USRS; - Forum.Location = -1L; + Forum.HieCod = -1L; Highlight = (Forums->Forum.Type == For_FORUM__SWAD__USRS); IsLastItemInLevel[1] = (IsLastForum && !ICanSeeTeacherForum); For_WriteLinkToForum (Forums,&Forum,Highlight,1,IsLastItemInLevel); @@ -1481,7 +1510,7 @@ static void For_WriteLinksToPlatformForums (const struct For_Forums *Forums, if (ICanSeeTeacherForum) { Forum.Type = For_FORUM__SWAD__TCHS; - Forum.Location = -1L; + Forum.HieCod = -1L; Highlight = (Forums->Forum.Type == For_FORUM__SWAD__TCHS); IsLastItemInLevel[1] = IsLastForum; For_WriteLinkToForum (Forums,&Forum,Highlight,1,IsLastItemInLevel); @@ -1511,9 +1540,9 @@ static long For_WriteLinksToInsForums (const struct For_Forums *Forums, /***** Link to the forum of users from this institution *****/ Forum.Type = For_FORUM_INSTIT_USRS; - Forum.Location = InsCod; + Forum.HieCod = InsCod; Highlight = (Forums->Forum.Type == For_FORUM_INSTIT_USRS && - Forums->Forum.Location == InsCod); + Forums->Forum.HieCod == InsCod); IsLastItemInLevel[2] = (IsLastIns && !ICanSeeTeacherForum); For_WriteLinkToForum (Forums,&Forum,Highlight,2,IsLastItemInLevel); @@ -1521,9 +1550,9 @@ static long For_WriteLinksToInsForums (const struct For_Forums *Forums, if (ICanSeeTeacherForum) { Forum.Type = For_FORUM_INSTIT_TCHS; - Forum.Location = InsCod; + Forum.HieCod = InsCod; Highlight = (Forums->Forum.Type == For_FORUM_INSTIT_TCHS && - Forums->Forum.Location == InsCod); + Forums->Forum.HieCod == InsCod); IsLastItemInLevel[2] = IsLastIns; For_WriteLinkToForum (Forums,&Forum,Highlight,2,IsLastItemInLevel); } @@ -1554,9 +1583,9 @@ static long For_WriteLinksToCtrForums (const struct For_Forums *Forums, /***** Link to the forum of users from this center *****/ Forum.Type = For_FORUM_CENTER_USRS; - Forum.Location = CtrCod; + Forum.HieCod = CtrCod; Highlight = (Forums->Forum.Type == For_FORUM_CENTER_USRS && - Forums->Forum.Location == CtrCod); + Forums->Forum.HieCod == CtrCod); IsLastItemInLevel[3] = (IsLastCtr && !ICanSeeTeacherForum); For_WriteLinkToForum (Forums,&Forum,Highlight,3,IsLastItemInLevel); @@ -1564,9 +1593,9 @@ static long For_WriteLinksToCtrForums (const struct For_Forums *Forums, if (ICanSeeTeacherForum) { Forum.Type = For_FORUM_CENTER_TCHS; - Forum.Location = CtrCod; + Forum.HieCod = CtrCod; Highlight = (Forums->Forum.Type == For_FORUM_CENTER_TCHS && - Forums->Forum.Location == CtrCod); + Forums->Forum.HieCod == CtrCod); IsLastItemInLevel[3] = IsLastCtr; For_WriteLinkToForum (Forums,&Forum,Highlight,3,IsLastItemInLevel); } @@ -1597,9 +1626,9 @@ static long For_WriteLinksToDegForums (const struct For_Forums *Forums, /***** Link to the forum of users from this degree *****/ Forum.Type = For_FORUM_DEGREE_USRS; - Forum.Location = DegCod; + Forum.HieCod = DegCod; Highlight = (Forums->Forum.Type == For_FORUM_DEGREE_USRS && - Forums->Forum.Location == DegCod); + Forums->Forum.HieCod == DegCod); IsLastItemInLevel[4] = (IsLastDeg && !ICanSeeTeacherForum); For_WriteLinkToForum (Forums,&Forum,Highlight,4,IsLastItemInLevel); @@ -1607,9 +1636,9 @@ static long For_WriteLinksToDegForums (const struct For_Forums *Forums, if (ICanSeeTeacherForum) { Forum.Type = For_FORUM_DEGREE_TCHS; - Forum.Location = DegCod; + Forum.HieCod = DegCod; Highlight = (Forums->Forum.Type == For_FORUM_DEGREE_TCHS && - Forums->Forum.Location == DegCod); + Forums->Forum.HieCod == DegCod); IsLastItemInLevel[4] = IsLastDeg; For_WriteLinkToForum (Forums,&Forum,Highlight,4,IsLastItemInLevel); } @@ -1640,9 +1669,9 @@ static long For_WriteLinksToCrsForums (const struct For_Forums *Forums, /***** Link to the forum of users from this course *****/ Forum.Type = For_FORUM_COURSE_USRS; - Forum.Location = CrsCod; + Forum.HieCod = CrsCod; Highlight = (Forums->Forum.Type == For_FORUM_COURSE_USRS && - Forums->Forum.Location == CrsCod); + Forums->Forum.HieCod == CrsCod); IsLastItemInLevel[5] = (IsLastCrs && !ICanSeeTeacherForum); For_WriteLinkToForum (Forums,&Forum,Highlight,5,IsLastItemInLevel); @@ -1650,9 +1679,9 @@ static long For_WriteLinksToCrsForums (const struct For_Forums *Forums, if (ICanSeeTeacherForum) { Forum.Type = For_FORUM_COURSE_TCHS; - Forum.Location = CrsCod; + Forum.HieCod = CrsCod; Highlight = (Forums->Forum.Type == For_FORUM_COURSE_TCHS && - Forums->Forum.Location == CrsCod); + Forums->Forum.HieCod == CrsCod); IsLastItemInLevel[5] = IsLastCrs; For_WriteLinkToForum (Forums,&Forum,Highlight,5,IsLastItemInLevel); } @@ -1701,7 +1730,7 @@ static void For_WriteLinkToForum (const struct For_Forums *Forums, 1, // Page of posts = first Forums->ForumSet, Forums->ThreadsOrder, - Forum->Location, + Forum->HieCod, Forums->Thread.ToMove, -1L); Ico_PutIconPaste (For_ActionsPasThrFor[Forum->Type]); @@ -1716,7 +1745,7 @@ static void For_WriteLinkToForum (const struct For_Forums *Forums, 1, // Page of posts = first Forums->ForumSet, Forums->ThreadsOrder, - Forum->Location, + Forum->HieCod, -1L, -1L); @@ -1738,15 +1767,15 @@ static void For_WriteLinkToForum (const struct For_Forums *Forums, break; case For_FORUM_INSTIT_USRS: case For_FORUM_INSTIT_TCHS: - Lgo_DrawLogo (HieLvl_INS,Forum->Location,ForumName,16,NULL,true); + Lgo_DrawLogo (HieLvl_INS,Forum->HieCod,ForumName,16,NULL,true); break; case For_FORUM_CENTER_USRS: case For_FORUM_CENTER_TCHS: - Lgo_DrawLogo (HieLvl_CTR,Forum->Location,ForumName,16,NULL,true); + Lgo_DrawLogo (HieLvl_CTR,Forum->HieCod,ForumName,16,NULL,true); break; case For_FORUM_DEGREE_USRS: case For_FORUM_DEGREE_TCHS: - Lgo_DrawLogo (HieLvl_DEG,Forum->Location,ForumName,16,NULL,true); + Lgo_DrawLogo (HieLvl_DEG,Forum->HieCod,ForumName,16,NULL,true); break; case For_FORUM_COURSE_USRS: case For_FORUM_COURSE_TCHS: @@ -1768,7 +1797,7 @@ static void For_WriteLinkToForum (const struct For_Forums *Forums, /***** Put link to register students *****/ if (Forum->Type == For_FORUM_COURSE_USRS) - Enr_PutButtonInlineToRegisterStds (Forum->Location); + Enr_PutButtonInlineToRegisterStds (Forum->HieCod); HTM_LI_End (); } @@ -1812,13 +1841,13 @@ void For_SetForumName (const struct For_Forum *Forum, Txt_only_teachers_NO_HTML[Language]); break; case For_FORUM_INSTIT_USRS: - Hie.Ins.InsCod = Forum->Location; + Hie.Ins.InsCod = Forum->HieCod; if (!Ins_GetInstitDataByCod (&Hie.Ins)) Err_WrongInstitExit (); Str_Copy (ForumName,Hie.Ins.ShrtName,For_MAX_BYTES_FORUM_NAME); break; case For_FORUM_INSTIT_TCHS: - Hie.Ins.InsCod = Forum->Location; + Hie.Ins.InsCod = Forum->HieCod; if (!Ins_GetInstitDataByCod (&Hie.Ins)) Err_WrongInstitExit (); snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,"%s%s", @@ -1827,13 +1856,13 @@ void For_SetForumName (const struct For_Forum *Forum, Txt_only_teachers_NO_HTML[Language]); break; case For_FORUM_CENTER_USRS: - Hie.Ctr.CtrCod = Forum->Location; + Hie.Ctr.CtrCod = Forum->HieCod; if (!Ctr_GetCenterDataByCod (&Hie.Ctr)) Err_WrongCenterExit (); Str_Copy (ForumName,Hie.Ctr.ShrtName,For_MAX_BYTES_FORUM_NAME); break; case For_FORUM_CENTER_TCHS: - Hie.Ctr.CtrCod = Forum->Location; + Hie.Ctr.CtrCod = Forum->HieCod; if (!Ctr_GetCenterDataByCod (&Hie.Ctr)) Err_WrongCenterExit (); snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,"%s%s", @@ -1842,13 +1871,13 @@ void For_SetForumName (const struct For_Forum *Forum, Txt_only_teachers_NO_HTML[Language]); break; case For_FORUM_DEGREE_USRS: - Hie.Deg.DegCod = Forum->Location; + Hie.Deg.DegCod = Forum->HieCod; if (!Deg_GetDegreeDataByCod (&Hie.Deg)) Err_WrongDegreeExit (); Str_Copy (ForumName,Hie.Deg.ShrtName,For_MAX_BYTES_FORUM_NAME); break; case For_FORUM_DEGREE_TCHS: - Hie.Deg.DegCod = Forum->Location; + Hie.Deg.DegCod = Forum->HieCod; if (!Deg_GetDegreeDataByCod (&Hie.Deg)) Err_WrongDegreeExit (); snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,"%s%s", @@ -1857,13 +1886,13 @@ void For_SetForumName (const struct For_Forum *Forum, Txt_only_teachers_NO_HTML[Language]); break; case For_FORUM_COURSE_USRS: - Hie.Crs.CrsCod = Forum->Location; + Hie.Crs.CrsCod = Forum->HieCod; if (!Crs_GetCourseDataByCod (&Hie.Crs)) Err_WrongCourseExit (); Str_Copy (ForumName,Hie.Crs.ShrtName,For_MAX_BYTES_FORUM_NAME); break; case For_FORUM_COURSE_TCHS: - Hie.Crs.CrsCod = Forum->Location; + Hie.Crs.CrsCod = Forum->HieCod; if (!Crs_GetCourseDataByCod (&Hie.Crs)) Err_WrongCourseExit (); snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,"%s%s", @@ -2052,7 +2081,7 @@ void For_ShowForumThreadsHighlightingOneThread (struct For_Forums *Forums, 1, // Page of posts = first Forums->ForumSet, Order, - Forums->Forum.Location, + Forums->Forum.HieCod, -1L, -1L); HTM_BUTTON_Submit_Begin (Txt_FORUM_THREAD_HELP_ORDER[Order], @@ -2125,7 +2154,7 @@ static void For_PutParsNewThread (void *Forums) 1, // Page of posts = first ((struct For_Forums *)Forums)->ForumSet, ((struct For_Forums *)Forums)->ThreadsOrder, - ((struct For_Forums *)Forums)->Forum.Location, + ((struct For_Forums *)Forums)->Forum.HieCod, -1L, -1L); } @@ -2227,7 +2256,7 @@ static void For_ListForumThrs (struct For_Forums *Forums, 1, // Page of posts = first Forums->ForumSet, Forums->ThreadsOrder, - Forums->Forum.Location, + Forums->Forum.HieCod, Thr.ThrCod, -1L); Ico_PutIconCut (For_ActionsCutThrFor[Forums->Forum.Type]); @@ -2432,20 +2461,13 @@ void For_GetParsForums (struct For_Forums *Forums) case For_FORUM_DEGREE_TCHS: case For_FORUM_COURSE_USRS: case For_FORUM_COURSE_TCHS: - Forums->Forum.Location = Par_GetParLong ("Location"); + Forums->Forum.HieCod = ParCod_GetPar (ParCod_OthHie); break; default: - Forums->Forum.Location = -1L; + Forums->Forum.HieCod = -1L; break; } - /***** Get optional parameter with code of a selected thread *****/ - Forums->Thread.Current = - Forums->Thread.Selected = ParCod_GetPar (ParCod_Thr); - - /***** Get optional parameter with code of a selected post *****/ - Forums->PstCod = ParCod_GetPar (ParCod_Pst); - /***** Get which forums I want to see *****/ Forums->ForumSet = (For_ForumSet_t) Par_GetParUnsignedLong ("ForumSet", @@ -2464,6 +2486,22 @@ void For_GetParsForums (struct For_Forums *Forums) Forums->CurrentPageThrs = Pag_GetParPagNum (Pag_THREADS_FORUM); Forums->CurrentPagePsts = Pag_GetParPagNum (Pag_POSTS_FORUM); + /***** Get optional parameter with code of a selected thread *****/ + Forums->Thread.Current = + Forums->Thread.Selected = ParCod_GetPar (ParCod_Thr); + + /***** Get optional parameter with code of a selected post *****/ + Forums->PstCod = ParCod_GetPar (ParCod_Pst); + + /***** If post or thread are specified, get other params from them *****/ + if (Forums->PstCod > 0) // If post specified ==> get other parameters in function of post + // Get thread, type and hierarchy code from database + Forums->Thread.Selected = + Forums->Thread.Current = For_GetThreadForumTypeAndHieCodOfAPost (Forums->PstCod,&Forums->Forum); + else if (Forums->Thread.Current > 0) // If thread specified ==> get other parameters in function of thread + // Get type and hierarchy code from database + For_GetForumTypeAndHieCodOfAThread (Forums->Thread.Current,&Forums->Forum); + /***** Restrict access to forum *****/ For_RestrictAccess (Forums); } @@ -2602,53 +2640,53 @@ static void For_RestrictAccess (const struct For_Forums *Forums) (1 << Rol_TCH))); break; case For_FORUM_INSTIT_USRS: - MaxRole = Rol_GetMyMaxRoleInIns (Forums->Forum.Location); + MaxRole = Rol_GetMyMaxRoleInIns (Forums->Forum.HieCod); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole == Rol_STD || MaxRole == Rol_NET || MaxRole == Rol_TCH); break; case For_FORUM_INSTIT_TCHS: - MaxRole = Rol_GetMyMaxRoleInIns (Forums->Forum.Location); + MaxRole = Rol_GetMyMaxRoleInIns (Forums->Forum.HieCod); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole == Rol_NET || MaxRole == Rol_TCH); break; case For_FORUM_CENTER_USRS: - MaxRole = Rol_GetMyMaxRoleInCtr (Forums->Forum.Location); + MaxRole = Rol_GetMyMaxRoleInCtr (Forums->Forum.HieCod); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole >= Rol_STD || MaxRole == Rol_NET || MaxRole == Rol_TCH); break; case For_FORUM_CENTER_TCHS: - MaxRole = Rol_GetMyMaxRoleInCtr (Forums->Forum.Location); + MaxRole = Rol_GetMyMaxRoleInCtr (Forums->Forum.HieCod); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole == Rol_NET || MaxRole == Rol_TCH); break; case For_FORUM_DEGREE_USRS: - MaxRole = Rol_GetMyMaxRoleInDeg (Forums->Forum.Location); + MaxRole = Rol_GetMyMaxRoleInDeg (Forums->Forum.HieCod); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole >= Rol_STD || MaxRole == Rol_NET || MaxRole == Rol_TCH); break; case For_FORUM_DEGREE_TCHS: - MaxRole = Rol_GetMyMaxRoleInDeg (Forums->Forum.Location); + MaxRole = Rol_GetMyMaxRoleInDeg (Forums->Forum.HieCod); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole == Rol_NET || MaxRole == Rol_TCH); break; case For_FORUM_COURSE_USRS: - MaxRole = Rol_GetMyRoleInCrs (Forums->Forum.Location); + MaxRole = Rol_GetMyRoleInCrs (Forums->Forum.HieCod); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole >= Rol_STD || MaxRole == Rol_NET || MaxRole == Rol_TCH); break; case For_FORUM_COURSE_TCHS: - MaxRole = Rol_GetMyRoleInCrs (Forums->Forum.Location); + MaxRole = Rol_GetMyRoleInCrs (Forums->Forum.HieCod); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole == Rol_NET || MaxRole == Rol_TCH); @@ -3010,7 +3048,7 @@ static void For_PutParsRemThread (void *Forums) 1, // Page of posts = first ((struct For_Forums *) Forums)->ForumSet, ((struct For_Forums *) Forums)->ThreadsOrder, - ((struct For_Forums *) Forums)->Forum.Location, + ((struct For_Forums *) Forums)->Forum.HieCod, ((struct For_Forums *) Forums)->Thread.Current, -1L); } diff --git a/swad_forum.h b/swad_forum.h index be31ca48..b25a6405 100644 --- a/swad_forum.h +++ b/swad_forum.h @@ -68,7 +68,7 @@ typedef enum struct For_Forum { For_ForumType_t Type; // Type of forum - long Location; // Code of institution, center, degree or course + long HieCod; // Hierachy code (code of institution, center, degree or course) }; struct For_Thread @@ -127,13 +127,12 @@ void For_ResetForums (struct For_Forums *Forums); void For_EnablePost (void); void For_DisablePost (void); -void For_GetForumTypeAndLocationOfAPost (long PstCod,struct For_Forum *Forum); +long For_GetThreadForumTypeAndHieCodOfAPost (long PstCod,struct For_Forum *Forum); +void For_GetForumTypeAndHieCodOfAThread (long ThrCod,struct For_Forum *Forum); void For_ShowPostsOfAThread (struct For_Forums *Forums, Ale_AlertType_t AlertType,const char *Message); -void For_PutParsNewPost (void *Forums); - void For_GetSummaryAndContentForumPst (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], char **ContentStr, long PstCod,bool GetContent); @@ -142,10 +141,9 @@ void For_PutAllParsForum (unsigned NumPageThreads, unsigned NumPagePosts, For_ForumSet_t ForumSet, Dat_StartEndTime_t Order, - long Location, + long HieCod, long ThrCod, long PstCod); - void For_ShowForumList (struct For_Forums *Forums); void For_SetForumName (const struct For_Forum *Forum, diff --git a/swad_forum_database.c b/swad_forum_database.c index 5df154c7..9c84c039 100644 --- a/swad_forum_database.c +++ b/swad_forum_database.c @@ -48,8 +48,8 @@ unsigned For_DB_GetNumThrsInForum (const struct For_Forum *Forum) char SubQuery[256]; /***** Get number of threads in a forum from database *****/ - if (Forum->Location > 0) - sprintf (SubQuery," AND Location=%ld",Forum->Location); + if (Forum->HieCod > 0) + sprintf (SubQuery," AND HieCod=%ld",Forum->HieCod); else SubQuery[0] = '\0'; @@ -74,8 +74,8 @@ unsigned For_DB_GetNumThrsInForumNewerThan (const struct For_Forum *Forum, /***** Get number of threads with a last message modify time > specified time from database *****/ - if (Forum->Location > 0) - sprintf (SubQuery," AND for_threads.Location=%ld",Forum->Location); + if (Forum->HieCod > 0) + sprintf (SubQuery," AND for_threads.HieCod=%ld",Forum->HieCod); else SubQuery[0] = '\0'; @@ -103,8 +103,8 @@ unsigned For_DB_GetNumPstsOfUsrInForum (const struct For_Forum *Forum, char SubQuery[256]; /***** Get number of posts from database *****/ - if (Forum->Location > 0) - sprintf (SubQuery," AND for_threads.Location=%ld",Forum->Location); + if (Forum->HieCod > 0) + sprintf (SubQuery," AND for_threads.HieCod=%ld",Forum->HieCod); else SubQuery[0] = '\0'; @@ -126,7 +126,7 @@ unsigned For_DB_GetNumPstsOfUsrInForum (const struct For_Forum *Forum, /************* Remove all threads and posts in forums of a scope *************/ /*****************************************************************************/ -void For_DB_RemoveForums (HieLvl_Level_t Scope,long ForumLocation) +void For_DB_RemoveForums (HieLvl_Level_t Scope,long HieCod) { static const struct { @@ -153,12 +153,12 @@ void For_DB_RemoveForums (HieLvl_Level_t Scope,long ForumLocation) " (for_threads.ForumType=%u" " OR" " for_threads.ForumType=%u)" - " AND for_threads.Location=%ld" + " AND for_threads.HieCod=%ld" " AND for_threads.ThrCod=for_posts.ThrCod" " AND for_posts.PstCod=for_disabled.PstCod", ForumType[Scope].Usrs, ForumType[Scope].Tchs, - ForumLocation); + HieCod); /***** Remove posts *****/ DB_QueryDELETE ("can not remove posts in forums", @@ -169,11 +169,11 @@ void For_DB_RemoveForums (HieLvl_Level_t Scope,long ForumLocation) " (for_threads.ForumType=%u" " OR" " for_threads.ForumType=%u)" - " AND for_threads.Location=%ld" + " AND for_threads.HieCod=%ld" " AND for_threads.ThrCod=for_posts.ThrCod", ForumType[Scope].Usrs, ForumType[Scope].Tchs, - ForumLocation); + HieCod); /***** Remove threads read *****/ DB_QueryDELETE ("can not remove read threads in forums", @@ -184,11 +184,11 @@ void For_DB_RemoveForums (HieLvl_Level_t Scope,long ForumLocation) " (for_threads.ForumType=%u" " OR" " for_threads.ForumType=%u)" - " AND for_threads.Location=%ld" + " AND for_threads.HieCod=%ld" " AND for_threads.ThrCod=for_read.ThrCod", ForumType[Scope].Usrs, ForumType[Scope].Tchs, - ForumLocation); + HieCod); /***** Remove threads *****/ DB_QueryDELETE ("can not remove threads in forums", @@ -197,10 +197,10 @@ void For_DB_RemoveForums (HieLvl_Level_t Scope,long ForumLocation) " (for_threads.ForumType=%u" " OR" " for_threads.ForumType=%u)" - " AND Location=%ld", + " AND HieCod=%ld", ForumType[Scope].Usrs, ForumType[Scope].Tchs, - ForumLocation); + HieCod); } /*****************************************************************************/ @@ -290,15 +290,16 @@ unsigned For_DB_GetPstSubjectAndContent (MYSQL_RES **mysql_res,long PstCod) } /*****************************************************************************/ -/*************** Get the forum type and location of a post *******************/ +/********* Get the forum thread, type and hierarchy code of a post ***********/ /*****************************************************************************/ -unsigned For_DB_GetForumTypeAndLocationOfAPost (MYSQL_RES **mysql_res,long PstCod) +unsigned For_DB_GetThreadForumTypeAndHieCodOfAPost (MYSQL_RES **mysql_res,long PstCod) { return (unsigned) - DB_QuerySELECT (mysql_res,"can not get forum type and location", - "SELECT for_threads.ForumType," // row[0] - "for_threads.Location" // row[1] + DB_QuerySELECT (mysql_res,"can not get forum thread, type and hierarchy", + "SELECT for_threads.ThrCod," // row[0] + "for_threads.ForumType," // row[1] + "for_threads.HieCod" // row[2] " FROM for_posts," "for_threads" " WHERE for_posts.PstCod=%ld" @@ -306,6 +307,21 @@ unsigned For_DB_GetForumTypeAndLocationOfAPost (MYSQL_RES **mysql_res,long PstCo PstCod); } +/*****************************************************************************/ +/*********** Get the forum type and hierarchy code of a thread ***************/ +/*****************************************************************************/ + +unsigned For_DB_GetForumTypeAndHieCodOfAThread (MYSQL_RES **mysql_res,long ThrCod) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get forum type and hierarchy", + "SELECT ForumType," // row[0] + "HieCod" // row[1] + " FROM for_threads" + " WHERE ThrCod=%ld", + ThrCod); + } + /*****************************************************************************/ /*********************** Get number of posts from a user *********************/ /*****************************************************************************/ @@ -408,11 +424,11 @@ long For_DB_InsertForumThread (const struct For_Forums *Forums, return DB_QueryINSERTandReturnCode ("can not create a new thread in a forum", "INSERT INTO for_threads" - " (ForumType,Location,FirstPstCod,LastPstCod)" + " (ForumType,HieCod,FirstPstCod,LastPstCod)" " VALUES" " (%u,%ld,%ld,%ld)", (unsigned) Forums->Forum.Type, - Forums->Forum.Location, + Forums->Forum.HieCod, FirstPstCod, FirstPstCod); } @@ -458,9 +474,9 @@ unsigned For_DB_GetForumThreads (MYSQL_RES **mysql_res, char SubQuery[256]; /***** Get threads of a forum from database *****/ - if (Forums->Forum.Location > 0) - sprintf (SubQuery," AND for_threads.Location=%ld", - Forums->Forum.Location); + if (Forums->Forum.HieCod > 0) + sprintf (SubQuery," AND for_threads.HieCod=%ld", + Forums->Forum.HieCod); else SubQuery[0] = '\0'; @@ -544,8 +560,8 @@ bool For_DB_CheckIfThrBelongsToForum (long ThrCod,const struct For_Forum *Forum) char SubQuery[256]; /***** Get if a thread belong to current forum from database *****/ - if (Forum->Location > 0) - sprintf (SubQuery," AND for_threads.Location=%ld",Forum->Location); + if (Forum->HieCod > 0) + sprintf (SubQuery," AND for_threads.HieCod=%ld",Forum->HieCod); else SubQuery[0] = '\0'; @@ -738,8 +754,8 @@ unsigned For_DB_GetLastTimeIReadForum (MYSQL_RES **mysql_res, { char SubQuery[256]; - if (Forum->Location > 0) - sprintf (SubQuery," AND for_threads.Location=%ld",Forum->Location); + if (Forum->HieCod > 0) + sprintf (SubQuery," AND for_threads.HieCod=%ld",Forum->HieCod); else SubQuery[0] = '\0'; @@ -830,7 +846,7 @@ void For_DB_MoveThrToCurrentForum (const struct For_Forums *Forums) DB_QueryUPDATE ("can not move a thread to current forum", "UPDATE for_threads" " SET ForumType=%u," - "Location=-1" + "HieCod=-1" " WHERE ThrCod=%ld", (unsigned) Forums->Forum.Type, Forums->Thread.Current); @@ -840,10 +856,10 @@ void For_DB_MoveThrToCurrentForum (const struct For_Forums *Forums) DB_QueryUPDATE ("can not move a thread to current forum", "UPDATE for_threads" " SET ForumType=%u," - "Location=%ld" + "HieCod=%ld" " WHERE ThrCod=%ld", (unsigned) Forums->Forum.Type, - Forums->Forum.Location, + Forums->Forum.HieCod, Forums->Thread.Current); break; case For_FORUM_CENTER_USRS: @@ -851,10 +867,10 @@ void For_DB_MoveThrToCurrentForum (const struct For_Forums *Forums) DB_QueryUPDATE ("can not move a thread to current forum", "UPDATE for_threads" " SET ForumType=%u," - "Location=%ld" + "HieCod=%ld" " WHERE ThrCod=%ld", (unsigned) Forums->Forum.Type, - Forums->Forum.Location, + Forums->Forum.HieCod, Forums->Thread.Current); break; case For_FORUM_DEGREE_USRS: @@ -862,10 +878,10 @@ void For_DB_MoveThrToCurrentForum (const struct For_Forums *Forums) DB_QueryUPDATE ("can not move a thread to current forum", "UPDATE for_threads" " SET ForumType=%u," - "Location=%ld" + "HieCod=%ld" " WHERE ThrCod=%ld", (unsigned) Forums->Forum.Type, - Forums->Forum.Location, + Forums->Forum.HieCod, Forums->Thread.Current); break; case For_FORUM_COURSE_USRS: @@ -873,10 +889,10 @@ void For_DB_MoveThrToCurrentForum (const struct For_Forums *Forums) DB_QueryUPDATE ("can not move a thread to current forum", "UPDATE for_threads" " SET ForumType=%u," - "Location=%ld" + "HieCod=%ld" " WHERE ThrCod=%ld", (unsigned) Forums->Forum.Type, - Forums->Forum.Location, + Forums->Forum.HieCod, Forums->Thread.Current); break; default: @@ -1022,10 +1038,10 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // InsCod > 0 ==> 0 <= number of institutions forums for an institution <= 1 return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT Location)" + "SELECT COUNT(DISTINCT HieCod)" " FROM for_threads" " WHERE ForumType=%u" - " AND Location=%ld", + " AND HieCod=%ld", (unsigned) ForumType, InsCod); @@ -1033,11 +1049,11 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // InsCod <= 0 && CtyCod > 0 ==> Number of institution forums for a country return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT for_threads.Location)" + "SELECT COUNT(DISTINCT for_threads.HieCod)" " FROM for_threads," "ins_instits" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=ins_instits.InsCod" + " AND for_threads.HieCod=ins_instits.InsCod" " AND ins_instits.CtyCod=%ld", (unsigned) ForumType, CtyCod); @@ -1045,7 +1061,7 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // CtyCod <= 0 ==> Number of institutions forums for the whole platform return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT Location)" + "SELECT COUNT(DISTINCT HieCod)" " FROM for_threads" " WHERE ForumType=%u", (unsigned) ForumType); @@ -1055,10 +1071,10 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // CtrCod > 0 ==> 0 <= number of center forums for a center <= 1 return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT Location)" + "SELECT COUNT(DISTINCT HieCod)" " FROM for_threads" " WHERE ForumType=%u" - " AND Location=%ld", + " AND HieCod=%ld", (unsigned) ForumType, CtrCod); @@ -1066,11 +1082,11 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // CtrCod <= 0 && InsCod > 0 ==> Number of center forums for an institution return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT for_threads.Location)" + "SELECT COUNT(DISTINCT for_threads.HieCod)" " FROM for_threads," "ctr_centers" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=ctr_centers.CtrCod" + " AND for_threads.HieCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=%ld", (unsigned) ForumType, InsCod); @@ -1079,12 +1095,12 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // InsCod <= 0 && CtyCod > 0 ==> Number of center forums for a country return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT for_threads.Location)" + "SELECT COUNT(DISTINCT for_threads.HieCod)" " FROM for_threads," "ctr_centers," "ins_instits" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=ctr_centers.CtrCod" + " AND for_threads.HieCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=ins_instits.InsCod" " AND ins_instits.CtyCod=%ld", (unsigned) ForumType, @@ -1093,7 +1109,7 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // InsCod <= 0 ==> Number of center forums for the whole platform return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT Location)" + "SELECT COUNT(DISTINCT HieCod)" " FROM for_threads" " WHERE ForumType=%u", (unsigned) ForumType); @@ -1103,10 +1119,10 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // DegCod > 0 ==> 0 <= number of degree forums for a degree <= 1 return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT Location)" + "SELECT COUNT(DISTINCT HieCod)" " FROM for_threads" " WHERE ForumType=%u" - " AND Location=%ld", + " AND HieCod=%ld", (unsigned) ForumType, DegCod); @@ -1114,11 +1130,11 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // DegCod <= 0 && CtrCod > 0 ==> Number of degree forums for a center return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT for_threads.Location)" + "SELECT COUNT(DISTINCT for_threads.HieCod)" " FROM for_threads," "deg_degrees" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=deg_degrees.DegCod" + " AND for_threads.HieCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=%ld", (unsigned) ForumType, CtrCod); @@ -1127,12 +1143,12 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // CtrCod <= 0 && InsCod > 0 ==> Number of degree forums for an institution return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT for_threads.Location)" + "SELECT COUNT(DISTINCT for_threads.HieCod)" " FROM for_threads," "deg_degrees," "ctr_centers" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=deg_degrees.DegCod" + " AND for_threads.HieCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=%ld", (unsigned) ForumType, @@ -1142,13 +1158,13 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // InsCod <= 0 && CtyCod > 0 ==> Number of degree forums for a country return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT for_threads.Location)" + "SELECT COUNT(DISTINCT for_threads.HieCod)" " FROM for_threads," "deg_degrees," "ctr_centers," "ins_instits" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=deg_degrees.DegCod" + " AND for_threads.HieCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=ins_instits.InsCod" " AND ins_instits.CtyCod=%ld", @@ -1158,7 +1174,7 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // InsCod <= 0 ==> Number of degree forums for the whole platform return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT Location)" + "SELECT COUNT(DISTINCT HieCod)" " FROM for_threads" " WHERE ForumType=%u", (unsigned) ForumType); @@ -1168,10 +1184,10 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // CrsCod > 0 ==> 0 <= number of course forums for a course <= 1 return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT Location)" + "SELECT COUNT(DISTINCT HieCod)" " FROM for_threads" " WHERE ForumType=%u" - " AND Location=%ld", + " AND HieCod=%ld", (unsigned) ForumType, CrsCod); @@ -1179,11 +1195,11 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // CrsCod <= 0 && DegCod > 0 ==> Number of course forums for a degree return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT for_threads.Location)" + "SELECT COUNT(DISTINCT for_threads.HieCod)" " FROM for_threads," "crs_courses" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=crs_courses.CrsCod" + " AND for_threads.HieCod=crs_courses.CrsCod" " AND crs_courses.DegCod=%ld", (unsigned) ForumType, DegCod); @@ -1192,12 +1208,12 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // DegCod <= 0 && CtrCod > 0 ==> Number of course forums for a center return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT for_threads.Location)" + "SELECT COUNT(DISTINCT for_threads.HieCod)" " FROM for_threads," "crs_courses," "deg_degrees" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=crs_courses.CrsCod" + " AND for_threads.HieCod=crs_courses.CrsCod" " AND crs_courses.DegCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=%ld", (unsigned) ForumType, @@ -1207,13 +1223,13 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // CtrCod <= 0 && InsCod > 0 ==> Number of course forums for an institution return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT for_threads.Location)" + "SELECT COUNT(DISTINCT for_threads.HieCod)" " FROM for_threads," "crs_courses," "deg_degrees," "ctr_centers" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=crs_courses.CrsCod" + " AND for_threads.HieCod=crs_courses.CrsCod" " AND crs_courses.DegCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=%ld", @@ -1224,14 +1240,14 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // InsCod <= 0 && CtyCod > 0 ==> Number of course forums for a country return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT for_threads.Location)" + "SELECT COUNT(DISTINCT for_threads.HieCod)" " FROM for_threads," "crs_courses," "deg_degrees," "ctr_centers," "ins_instits" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=crs_courses.CrsCod" + " AND for_threads.HieCod=crs_courses.CrsCod" " AND crs_courses.DegCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=ins_instits.InsCod" @@ -1242,7 +1258,7 @@ unsigned For_DB_GetNumTotalForumsOfType (For_ForumType_t ForumType, // InsCod <= 0 ==> Number of course forums for the whole platform return (unsigned) DB_QueryCOUNT ("can not get number of forums of a type", - "SELECT COUNT(DISTINCT Location)" + "SELECT COUNT(DISTINCT HieCod)" " FROM for_threads" " WHERE ForumType=%u", (unsigned) ForumType); @@ -1285,7 +1301,7 @@ unsigned For_DB_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, "SELECT COUNT(*)" " FROM for_threads" " WHERE ForumType=%u" - " AND Location=%ld", + " AND HieCod=%ld", (unsigned) ForumType, InsCod); @@ -1297,7 +1313,7 @@ unsigned For_DB_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, " FROM for_threads," "ins_instits" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=ins_instits.InsCod" + " AND for_threads.HieCod=ins_instits.InsCod" " AND ins_instits.CtyCod=%ld", (unsigned) ForumType, CtyCod); @@ -1318,7 +1334,7 @@ unsigned For_DB_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, "SELECT COUNT(*)" " FROM for_threads" " WHERE ForumType=%u" - " AND Location=%ld", + " AND HieCod=%ld", (unsigned) ForumType, CtrCod); @@ -1330,7 +1346,7 @@ unsigned For_DB_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, " FROM for_threads," "ctr_centers" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=ctr_centers.CtrCod" + " AND for_threads.HieCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=%ld", (unsigned) ForumType, InsCod); @@ -1344,7 +1360,7 @@ unsigned For_DB_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, "ctr_centers," "ins_instits" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=ctr_centers.CtrCod" + " AND for_threads.HieCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=ins_instits.InsCod" " AND ins_instits.CtyCod=%ld", (unsigned) ForumType, @@ -1366,7 +1382,7 @@ unsigned For_DB_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, "SELECT COUNT(*)" " FROM for_threads" " WHERE ForumType=%u" - " AND Location=%ld", + " AND HieCod=%ld", (unsigned) ForumType, DegCod); @@ -1378,7 +1394,7 @@ unsigned For_DB_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, " FROM for_threads," "deg_degrees" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=deg_degrees.DegCod" + " AND for_threads.HieCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=%ld", (unsigned) ForumType, CtrCod); @@ -1392,7 +1408,7 @@ unsigned For_DB_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, "deg_degrees," "ctr_centers" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=deg_degrees.DegCod" + " AND for_threads.HieCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=%ld", (unsigned) ForumType, @@ -1407,7 +1423,7 @@ unsigned For_DB_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, "ctr_centers," "ins_instits" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=deg_degrees.DegCod" + " AND for_threads.HieCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=ins_instits.InsCod" " AND ins_instits.CtyCod=%ld", @@ -1430,7 +1446,7 @@ unsigned For_DB_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, "SELECT COUNT(*)" " FROM for_threads" " WHERE ForumType=%u" - " AND Location=%ld", + " AND HieCod=%ld", (unsigned) ForumType, CrsCod); @@ -1442,7 +1458,7 @@ unsigned For_DB_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, " FROM for_threads," "crs_courses" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=crs_courses.CrsCod" + " AND for_threads.HieCod=crs_courses.CrsCod" " AND crs_courses.DegCod=%ld", (unsigned) ForumType, DegCod); @@ -1456,7 +1472,7 @@ unsigned For_DB_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, "crs_courses," "deg_degrees" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=crs_courses.CrsCod" + " AND for_threads.HieCod=crs_courses.CrsCod" " AND crs_courses.DegCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=%ld", (unsigned) ForumType, @@ -1472,7 +1488,7 @@ unsigned For_DB_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, "deg_degrees," "ctr_centers" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=crs_courses.CrsCod" + " AND for_threads.HieCod=crs_courses.CrsCod" " AND crs_courses.DegCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=%ld", @@ -1490,7 +1506,7 @@ unsigned For_DB_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, "ctr_centers," "ins_instits" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=crs_courses.CrsCod" + " AND for_threads.HieCod=crs_courses.CrsCod" " AND crs_courses.DegCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=ins_instits.InsCod" @@ -1553,7 +1569,7 @@ unsigned For_DB_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType, " FROM for_threads," "for_posts" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=%ld" + " AND for_threads.HieCod=%ld" " AND for_threads.ThrCod=for_posts.ThrCod", (unsigned) ForumType, InsCod); @@ -1566,7 +1582,7 @@ unsigned For_DB_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType, "ins_instits," "for_posts" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=ins_instits.InsCod" + " AND for_threads.HieCod=ins_instits.InsCod" " AND ins_instits.CtyCod=%ld" " AND for_threads.ThrCod=for_posts.ThrCod", (unsigned) ForumType, @@ -1592,7 +1608,7 @@ unsigned For_DB_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType, " FROM for_threads," "for_posts" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=%ld" + " AND for_threads.HieCod=%ld" " AND for_threads.ThrCod=for_posts.ThrCod", (unsigned) ForumType, CtrCod); @@ -1605,7 +1621,7 @@ unsigned For_DB_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType, "ctr_centers," "for_posts" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=ctr_centers.CtrCod" + " AND for_threads.HieCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=%ld" " AND for_threads.ThrCod=for_posts.ThrCod", (unsigned) ForumType, @@ -1620,7 +1636,7 @@ unsigned For_DB_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType, "ins_instits," "for_posts" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=ctr_centers.CtrCod" + " AND for_threads.HieCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=ins_instits.InsCod" " AND ins_instits.CtyCod=%ld" " AND for_threads.ThrCod=for_posts.ThrCod", @@ -1647,7 +1663,7 @@ unsigned For_DB_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType, " FROM for_threads," "for_posts" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=%ld" + " AND for_threads.HieCod=%ld" " AND for_threads.ThrCod=for_posts.ThrCod", (unsigned) ForumType, DegCod); @@ -1660,7 +1676,7 @@ unsigned For_DB_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType, "deg_degrees," "for_posts" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=deg_degrees.DegCod" + " AND for_threads.HieCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=%ld" " AND for_threads.ThrCod=for_posts.ThrCod", (unsigned) ForumType, @@ -1675,7 +1691,7 @@ unsigned For_DB_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType, "ctr_centers," "for_posts" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=deg_degrees.DegCod" + " AND for_threads.HieCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=%ld" " AND for_threads.ThrCod=for_posts.ThrCod", @@ -1692,7 +1708,7 @@ unsigned For_DB_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType, "ins_instits," "for_posts" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=deg_degrees.DegCod" + " AND for_threads.HieCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=ins_instits.InsCod" " AND ins_instits.CtyCod=%ld" @@ -1720,7 +1736,7 @@ unsigned For_DB_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType, " FROM for_threads," "for_posts " " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=%ld" + " AND for_threads.HieCod=%ld" " AND for_threads.ThrCod=for_posts.ThrCod", (unsigned) ForumType, CrsCod); @@ -1733,7 +1749,7 @@ unsigned For_DB_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType, "crs_courses," "for_posts " " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=crs_courses.CrsCod" + " AND for_threads.HieCod=crs_courses.CrsCod" " AND crs_courses.DegCod=%ld" " AND for_threads.ThrCod=for_posts.ThrCod", (unsigned) ForumType, @@ -1748,7 +1764,7 @@ unsigned For_DB_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType, "deg_degrees," "for_posts " " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=crs_courses.CrsCod" + " AND for_threads.HieCod=crs_courses.CrsCod" " AND crs_courses.DegCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=%ld" " AND for_threads.ThrCod=for_posts.ThrCod", @@ -1765,7 +1781,7 @@ unsigned For_DB_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType, "ctr_centers," "for_posts" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=crs_courses.CrsCod" + " AND for_threads.HieCod=crs_courses.CrsCod" " AND crs_courses.DegCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=%ld" @@ -1784,7 +1800,7 @@ unsigned For_DB_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType, "ins_instits," "for_posts" " WHERE for_threads.ForumType=%u" - " AND for_threads.Location=crs_courses.CrsCod" + " AND for_threads.HieCod=crs_courses.CrsCod" " AND crs_courses.DegCod=deg_degrees.DegCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND ctr_centers.InsCod=ins_instits.InsCod" diff --git a/swad_forum_database.h b/swad_forum_database.h index 884876e1..689bfdff 100644 --- a/swad_forum_database.h +++ b/swad_forum_database.h @@ -39,7 +39,7 @@ unsigned For_DB_GetNumThrsInForumNewerThan (const struct For_Forum *Forum, const char *Time); unsigned For_DB_GetNumPstsOfUsrInForum (const struct For_Forum *Forum, long UsrCod); -void For_DB_RemoveForums (HieLvl_Level_t Scope,long ForumLocation); +void For_DB_RemoveForums (HieLvl_Level_t Scope,long HieCod); //------------------------------- Posts --------------------------------------- long For_DB_InsertForumPst (long ThrCod,long UsrCod, @@ -50,7 +50,8 @@ void For_DB_UpdateNumUsrsNotifiedByEMailAboutPost (long PstCod, bool For_DB_CheckIfForumPstExists (long PstCod); unsigned For_DB_GetPstData (MYSQL_RES **mysql_res,long PstCod); unsigned For_DB_GetPstSubjectAndContent (MYSQL_RES **mysql_res,long PstCod); -unsigned For_DB_GetForumTypeAndLocationOfAPost (MYSQL_RES **mysql_res,long PstCod); +unsigned For_DB_GetThreadForumTypeAndHieCodOfAPost (MYSQL_RES **mysql_res,long PstCod); +unsigned For_DB_GetForumTypeAndHieCodOfAThread (MYSQL_RES **mysql_res,long ThrCod); unsigned For_DB_GetNumPostsUsr (long UsrCod); unsigned For_DB_GetPostsOfAThread (MYSQL_RES **mysql_res,long ThrCod); unsigned For_DB_GetThreadAndNumPostsGivenPstCod (MYSQL_RES **mysql_res,long PstCod); diff --git a/swad_forum_resource.c b/swad_forum_resource.c index da1e2090..64a5de1c 100644 --- a/swad_forum_resource.c +++ b/swad_forum_resource.c @@ -31,6 +31,7 @@ #include "swad_forum_database.h" #include "swad_forum_resource.h" #include "swad_global.h" +#include "swad_parameter_code.h" #include "swad_resource_database.h" /*****************************************************************************/ @@ -84,7 +85,6 @@ void ForRsc_WriteResourceThread (long ThrCod,Frm_PutFormToGo_t PutFormToGo, { extern const char *Txt_Actions[ActLst_NUM_ACTIONS]; Act_Action_t NextAction; - struct For_Forums Forums; char Subject[Cns_MAX_BYTES_SUBJECT + 1]; /***** Get thread subject *****/ @@ -94,18 +94,16 @@ void ForRsc_WriteResourceThread (long ThrCod,Frm_PutFormToGo_t PutFormToGo, if (PutFormToGo == Frm_PUT_FORM_TO_GO) { /***** Set forum and thread *****/ - For_ResetForums (&Forums); - Forums.Forum.Type = For_FORUM_COURSE_USRS; - Forums.Forum.Location = Gbl.Hierarchy.Crs.CrsCod; - Forums.Thread.Current = - Forums.Thread.Selected = ThrCod; // TODO: In the listing of threads, the page is always the first. // The page should be that corresponding to the selected thread. NextAction = (ThrCod > 0) ? ActSeePstForCrsUsr : // Thread specified ActSeeForCrsUsr; // All threads Frm_BeginFormAnchor (NextAction,ThrCod > 0 ? For_FORUM_POSTS_SECTION_ID : For_FORUM_THREADS_SECTION_ID); - For_PutParsNewPost (&Forums); + if (ThrCod > 0) + ParCod_PutPar (ParCod_Thr,ThrCod); + else + ParCod_PutPar (ParCod_OthHie,Gbl.Hierarchy.Crs.CrsCod); HTM_BUTTON_Submit_Begin (Txt_Actions[NextAction], "class=\"LM BT_LINK PRG_LNK_%s\"", The_GetSuffix ()); diff --git a/swad_notification.c b/swad_notification.c index 880bcd4f..2a1dd833 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -442,7 +442,7 @@ void Ntf_ShowMyNotifications (void) NotifyEvent == Ntf_EVENT_FORUM_REPLY) { For_ResetForums (&Forums); - For_GetForumTypeAndLocationOfAPost (Cod,&Forums.Forum); + For_GetThreadForumTypeAndHieCodOfAPost (Cod,&Forums.Forum); For_SetForumName (&Forums.Forum, ForumName,Gbl.Prefs.Language,false); // Set forum name in recipient's language } @@ -796,7 +796,7 @@ static Act_Action_t Ntf_StartFormGoToAction (Ntf_NotifyEvent_t NotifyEvent, 1, // Page of posts = first Forums->ForumSet, Forums->ThreadsOrder, - Forums->Forum.Location, + Forums->Forum.HieCod, Forums->Thread.Selected, -1L); break; @@ -1102,8 +1102,7 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) return 0; case Ntf_EVENT_FORUM_POST_COURSE: // Check if forum is for users or for all users in the course - For_GetForumTypeAndLocationOfAPost (Cod,&ForumSelected); - + For_GetThreadForumTypeAndHieCodOfAPost (Cod,&ForumSelected); if (GetUsrsForum[ForumSelected.Type]) NumUsrs = GetUsrsForum[ForumSelected.Type] (&mysql_res); else @@ -1128,19 +1127,19 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) { case For_FORUM_INSTIT_USRS: case For_FORUM_INSTIT_TCHS: - InsCod = ForumSelected.Location; + InsCod = ForumSelected.HieCod; break; case For_FORUM_CENTER_USRS: case For_FORUM_CENTER_TCHS: - CtrCod = ForumSelected.Location; + CtrCod = ForumSelected.HieCod; break; case For_FORUM_DEGREE_USRS: case For_FORUM_DEGREE_TCHS: - DegCod = ForumSelected.Location; + DegCod = ForumSelected.HieCod; break; case For_FORUM_COURSE_USRS: case For_FORUM_COURSE_TCHS: - CrsCod = ForumSelected.Location; + CrsCod = ForumSelected.HieCod; break; default: break; @@ -1357,7 +1356,7 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (const struct Usr_Data *ToUsrDat /* Get forum type */ if (NotifyEvent == Ntf_EVENT_FORUM_POST_COURSE || NotifyEvent == Ntf_EVENT_FORUM_REPLY) - For_GetForumTypeAndLocationOfAPost (Cod,&ForumSelected); + For_GetThreadForumTypeAndHieCodOfAPost (Cod,&ForumSelected); /* Information about the type of this event */ fprintf (FileMail,Txt_NOTIFY_EVENTS_SINGULAR_NO_HTML[NotifyEvent][ToUsrLanguage], diff --git a/swad_pagination.c b/swad_pagination.c index e9312d68..f90575ff 100644 --- a/swad_pagination.c +++ b/swad_pagination.c @@ -84,9 +84,9 @@ static const char *Pag_ParNumPag[Pag_NUM_WHAT_PAGINATE] = /******* Calculate variables related to the pagination of the messages *******/ /*****************************************************************************/ // Return the number of subsets of N elements in a set of NumElements elements -#define NumSubsetsOfNElements(NumElements,N) ((NumElements+(N-1)) / N) -#define NUM_PAGES_BEFORE_CURRENT 1 -#define NUM_PAGES_AFTER_CURRENT 1 +#define Pag_NumPags(NumItems) ((Pagination->NumItems+(Pag_ITEMS_PER_PAGE-1)) / Pag_ITEMS_PER_PAGE) +#define Pag_NUM_PAGES_BEFORE_CURRENT 1 +#define Pag_NUM_PAGES_AFTER_CURRENT 1 void Pag_CalculatePagination (struct Pag_Pagination *Pagination) { @@ -95,7 +95,8 @@ void Pag_CalculatePagination (struct Pag_Pagination *Pagination) Pagination->RightPage = Pagination->EndPage = 1; Pagination->MoreThanOnePage = false; - if ((Pagination->NumPags = NumSubsetsOfNElements (Pagination->NumItems,Pag_ITEMS_PER_PAGE)) > 1) + Pagination->NumPags = ((Pagination->NumItems + (Pag_ITEMS_PER_PAGE-1)) / Pag_ITEMS_PER_PAGE); + if (Pagination->NumPags > 1) { Pagination->MoreThanOnePage = true; @@ -106,13 +107,13 @@ void Pag_CalculatePagination (struct Pag_Pagination *Pagination) Pagination->CurrentPage = Pagination->NumPags; /* Compute first page with link around the current */ - if (Pagination->CurrentPage <= NUM_PAGES_BEFORE_CURRENT) + if (Pagination->CurrentPage <= Pag_NUM_PAGES_BEFORE_CURRENT) Pagination->StartPage = 1; else - Pagination->StartPage = Pagination->CurrentPage - NUM_PAGES_BEFORE_CURRENT; + Pagination->StartPage = Pagination->CurrentPage - Pag_NUM_PAGES_BEFORE_CURRENT; /* Compute last page with link around the current */ - if ((Pagination->EndPage = Pagination->CurrentPage + NUM_PAGES_AFTER_CURRENT) > Pagination->NumPags) + if ((Pagination->EndPage = Pagination->CurrentPage + Pag_NUM_PAGES_AFTER_CURRENT) > Pagination->NumPags) Pagination->EndPage = Pagination->NumPags; /* Compute left page with link in the middle of first page and current page */ @@ -221,7 +222,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, 1, // Page of posts = first ((struct For_Forums *) Context)->ForumSet, ((struct For_Forums *) Context)->ThreadsOrder, - ((struct For_Forums *) Context)->Forum.Location, + ((struct For_Forums *) Context)->Forum.HieCod, -1L, -1L); break; @@ -232,7 +233,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, 1, // Page of posts = first ((struct For_Forums *) Context)->ForumSet, ((struct For_Forums *) Context)->ThreadsOrder, - ((struct For_Forums *) Context)->Forum.Location, + ((struct For_Forums *) Context)->Forum.HieCod, Cod, -1L); break; @@ -348,7 +349,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, 1, // Page of posts = first ((struct For_Forums *) Context)->ForumSet, ((struct For_Forums *) Context)->ThreadsOrder, - ((struct For_Forums *) Context)->Forum.Location, + ((struct For_Forums *) Context)->Forum.HieCod, -1L, -1L); break; @@ -359,7 +360,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, 1, // Page of posts = first ((struct For_Forums *) Context)->ForumSet, ((struct For_Forums *) Context)->ThreadsOrder, - ((struct For_Forums *) Context)->Forum.Location, + ((struct For_Forums *) Context)->Forum.HieCod, Cod, -1L); break; @@ -468,7 +469,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, 1, // Page of posts = first ((struct For_Forums *) Context)->ForumSet, ((struct For_Forums *) Context)->ThreadsOrder, - ((struct For_Forums *) Context)->Forum.Location, + ((struct For_Forums *) Context)->Forum.HieCod, -1L, -1L); break; @@ -479,7 +480,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, Pagination->LeftPage, // Page of posts = left ((struct For_Forums *) Context)->ForumSet, ((struct For_Forums *) Context)->ThreadsOrder, - ((struct For_Forums *) Context)->Forum.Location, + ((struct For_Forums *) Context)->Forum.HieCod, Cod, -1L); break; @@ -601,7 +602,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, 1, // Page of posts = first ((struct For_Forums *) Context)->ForumSet, ((struct For_Forums *) Context)->ThreadsOrder, - ((struct For_Forums *) Context)->Forum.Location, + ((struct For_Forums *) Context)->Forum.HieCod, -1L, -1L); break; @@ -612,7 +613,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, NumPage, // Page of posts = number of page ((struct For_Forums *) Context)->ForumSet, ((struct For_Forums *) Context)->ThreadsOrder, - ((struct For_Forums *) Context)->Forum.Location, + ((struct For_Forums *) Context)->Forum.HieCod, Cod, -1L); break; @@ -720,7 +721,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, 1, // Page of posts = first ((struct For_Forums *) Context)->ForumSet, ((struct For_Forums *) Context)->ThreadsOrder, - ((struct For_Forums *) Context)->Forum.Location, + ((struct For_Forums *) Context)->Forum.HieCod, -1L, -1L); break; @@ -731,7 +732,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, Pagination->RightPage, // Page of posts = right ((struct For_Forums *) Context)->ForumSet, ((struct For_Forums *) Context)->ThreadsOrder, - ((struct For_Forums *) Context)->Forum.Location, + ((struct For_Forums *) Context)->Forum.HieCod, Cod, -1L); break; @@ -840,7 +841,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, 1, // Page of posts = first ((struct For_Forums *) Context)->ForumSet, ((struct For_Forums *) Context)->ThreadsOrder, - ((struct For_Forums *) Context)->Forum.Location, + ((struct For_Forums *) Context)->Forum.HieCod, -1L, -1L); break; @@ -851,7 +852,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, Pagination->NumPags, // Page of posts = last ((struct For_Forums *) Context)->ForumSet, ((struct For_Forums *) Context)->ThreadsOrder, - ((struct For_Forums *) Context)->Forum.Location, + ((struct For_Forums *) Context)->Forum.HieCod, Cod, -1L); break; diff --git a/swad_resource.h b/swad_resource.h index 5874048c..4f5a23cd 100644 --- a/swad_resource.h +++ b/swad_resource.h @@ -29,6 +29,7 @@ #include // To access MySQL databases +#include "swad_form.h" #include "swad_HTML.h" #include "swad_string.h" diff --git a/swad_timeline_note.c b/swad_timeline_note.c index b3918a13..5975a2b0 100644 --- a/swad_timeline_note.c +++ b/swad_timeline_note.c @@ -466,7 +466,7 @@ static void TmlNot_GetLocationInHierarchy (const struct TmlNot_Note *Not, break; case TmlNot_FORUM_POST: /* Get forum type of the post */ - For_GetForumTypeAndLocationOfAPost (Not->Cod,Forum); + For_GetThreadForumTypeAndHieCodOfAPost (Not->Cod,Forum); /* Set forum name in recipient's language */ For_SetForumName (Forum,ForumName,Gbl.Prefs.Language,false); @@ -672,7 +672,7 @@ static void TmlNot_PutFormGoToAction (const struct TmlNot_Note *Not, 1, // Page of posts = first Forums->ForumSet, Forums->ThreadsOrder, - Forums->Forum.Location, + Forums->Forum.HieCod, Forums->Thread.Selected, -1L); if (Not->HieCod != Gbl.Hierarchy.Crs.CrsCod) // Not the current course