diff --git a/swad_assignment.c b/swad_assignment.c index c062051e..57ceb998 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -1401,7 +1401,7 @@ void Asg_RecFormAssignment (void) if (NewAssignmentIsCorrect) { /* Get groups for this assignments */ - Grp_GetParCodsSeveralGrpsToEditAsgAttOrSvy (); + Grp_GetParCodsSeveralGrps (); if (ItsANewAssignment) { @@ -1600,7 +1600,7 @@ static void Asg_CreateGrps (long AsgCod) { /* Create group */ sprintf (Query,"INSERT INTO asg_grp (AsgCod,GrpCod) VALUES ('%ld','%ld')", - AsgCod,Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod[NumGrpSel]); + AsgCod,Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]); DB_QueryINSERT (Query,"can not associate a group to an assignment"); } } diff --git a/swad_attendance.c b/swad_attendance.c index d25718ba..57b17d9e 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -1338,7 +1338,7 @@ void Att_RecFormAttEvent (void) if (ReceivedAttEventIsCorrect) { /* Get groups for this attendance events */ - Grp_GetParCodsSeveralGrpsToEditAsgAttOrSvy (); + Grp_GetParCodsSeveralGrps (); if (ItsANewAttEvent) { @@ -1520,7 +1520,7 @@ static void Att_CreateGrps (long AttCod) { /* Create group */ sprintf (Query,"INSERT INTO att_grp (AttCod,GrpCod) VALUES ('%ld','%ld')", - AttCod,Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod[NumGrpSel]); + AttCod,Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]); DB_QueryINSERT (Query,"can not associate a group to an attendance event"); } } @@ -2980,7 +2980,7 @@ static void Att_GetListSelectedAttCods (char **StrAttCodsSelected) NumGrpSel < Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps && !Gbl.AttEvents.Lst[NumAttEvent].Selected; NumGrpSel++) - if (Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod[NumGrpSel] == GrpCodInThisEvent) + if (Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel] == GrpCodInThisEvent) Gbl.AttEvents.Lst[NumAttEvent].Selected = true; } else // This event is not associated to groups diff --git a/swad_changelog.h b/swad_changelog.h index 8664c263..e696bda9 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -193,13 +193,15 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.120.2 (2017-01-19)" +#define Log_PLATFORM_VERSION "SWAD 16.121 (2017-01-19)" #define CSS_FILE "swad16.119.4.css" #define JS_FILE "swad16.119.3.js" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1 /* + Version 16.121: Jan 19, 2017 Fixed bug in groups selection, reported by Eva Martínez Ortigosa. + Code refactoring in groups selected. (211915 lines) Version 16.120.2: Jan 19, 2017 Changed the question to confirm user's enrollment. (211954 lines) Version 16.120.1: Jan 19, 2017 From now on, a teacher A can enroll another user B as a teacher in their courses, although user B is not yet a teacher in any course. (? lines) Version 16.120: Jan 19, 2017 Fixed bug when limiting length of links. (211934 lines) diff --git a/swad_enrollment.c b/swad_enrollment.c index f6a0d3d9..8a763173 100644 --- a/swad_enrollment.c +++ b/swad_enrollment.c @@ -1359,7 +1359,7 @@ static void Enr_ReceiveFormUsrsCrs (Rol_Role_t Role) Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_ONLY_GROUP_TYPES_WITH_GROUPS); /***** Get the list of groups to which register/remove students *****/ - LstGrps.GrpCod = NULL; // Initialized to avoid bug reported by Coverity + LstGrps.GrpCods = NULL; // Initialized to avoid bug reported by Coverity LstGrps.NumGrps = 0; // Initialized to avoid bug reported by Coverity Grp_GetLstCodsGrpWanted (&LstGrps); diff --git a/swad_file_browser.c b/swad_file_browser.c index cac9aecb..399aa018 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -3318,7 +3318,7 @@ static void Brw_FormToChangeCrsGrpZone (void) NumGrp++) { /* Get next group */ - GrpDat.GrpCod = LstMyGrps.GrpCod[NumGrp]; + GrpDat.GrpCod = LstMyGrps.GrpCods[NumGrp]; Grp_GetDataOfGroupByCod (&GrpDat); /* Select this group */ diff --git a/swad_global.c b/swad_global.c index 4d364d97..4991b90b 100644 --- a/swad_global.c +++ b/swad_global.c @@ -324,7 +324,7 @@ void Gbl_InitializeGlobals (void) Gbl.CurrentCrs.Grps.GrpName[0] = '\0'; Gbl.CurrentCrs.Grps.MaxStudents = INT_MAX; Gbl.CurrentCrs.Grps.Open = false; - Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod = NULL; + Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods = NULL; Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps = 0; Gbl.CurrentCrs.Grps.LstGrpsSel.NestedCalls = 0; diff --git a/swad_group.c b/swad_group.c index e4cc23bc..64c27707 100644 --- a/swad_group.c +++ b/swad_group.c @@ -61,6 +61,7 @@ extern struct Globals Gbl; static void Grp_EditGroupTypes (void); static void Grp_EditGroups (void); + static void Grp_ConstructorListGrpAlreadySelec (struct ListGrpsAlreadySelec **AlreadyExistsGroupOfType); static void Grp_DestructorListGrpAlreadySelec (struct ListGrpsAlreadySelec **AlreadyExistsGroupOfType); static void Grp_RemoveUsrFromGroup (long UsrCod,long GrpCod); @@ -126,7 +127,7 @@ void Grp_WriteNamesOfSelectedGrps (void) NumGrpSel < Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps; NumGrpSel++) { - if ((GrpCod = Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod[NumGrpSel]) >= 0) + if ((GrpCod = Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]) >= 0) { GrpDat.GrpCod = GrpCod; Grp_GetDataOfGroupByCod (&GrpDat); @@ -242,8 +243,6 @@ void Grp_ShowFormToSelectSeveralGroups (Act_Action_t NextAction) (Gbl.Usrs.Me.LoggedRole == Rol_TEACHER || Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM); - fprintf (Gbl.F.Out,"
"); - /***** Start frame *****/ Lay_StartRoundFrame (NULL,Txt_Groups, ICanEdit ? Grp_PutIconToEditGroups : @@ -304,7 +303,6 @@ void Grp_ShowFormToSelectSeveralGroups (Act_Action_t NextAction) /***** End frame *****/ Lay_EndRoundFrame (); - fprintf (Gbl.F.Out,"
"); } } @@ -332,7 +330,7 @@ void Grp_PutParamsCodGrps (void) { if (NumGrpSel) fprintf (Gbl.F.Out,"%c",Par_SEPARATOR_PARAM_MULTIPLE); - fprintf (Gbl.F.Out,"%ld",Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod[NumGrpSel]); + fprintf (Gbl.F.Out,"%ld",Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]); } fprintf (Gbl.F.Out,"\" />"); } @@ -341,85 +339,47 @@ void Grp_PutParamsCodGrps (void) /*****************************************************************************/ /**************** Get parameters related to groups selected ******************/ /*****************************************************************************/ -// Returns number of groups in current course -// TODO: Grp_GetParCodsSeveralGrpsToEditAsgAttOrSvy is very similar to Grp_GetParCodsSeveralGrpsToShowUsrs ==> merge code void Grp_GetParCodsSeveralGrpsToShowUsrs (void) { char YN[1+1]; - unsigned long MaxSizeLstGrpCods; - char *LstCodGrps; struct ListCodGrps LstGrpsIBelong; - const char *Ptr; - char LongStr[1+10+1]; unsigned NumGrp; if (++Gbl.CurrentCrs.Grps.LstGrpsSel.NestedCalls > 1) // If list is created yet, there's nothing to do return; - /***** Set default for number of groups selected by me *****/ - Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps = 0; - /***** Get boolean parameter that indicates if all groups must be listed *****/ Par_GetParToText ("AllGroups",YN,1); Gbl.Usrs.ClassPhoto.AllGroups = (Str_ConvertToUpperLetter (YN[0]) == 'Y'); - if (Gbl.CurrentCrs.Grps.NumGrps) + /***** Get parameter with list of groups selected *****/ + Grp_GetParCodsSeveralGrps (); + + if (Gbl.CurrentCrs.Grps.NumGrps && // This course has groups and... + !Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps) // ...I haven't selected any group { - /***** Allocate memory for the list of group codes *****/ - MaxSizeLstGrpCods = ((1+10+1) * Gbl.CurrentCrs.Grps.NumGrps) - 1; - if ((LstCodGrps = (char *) malloc (MaxSizeLstGrpCods + 1)) == NULL) - Lay_ShowErrorAndExit ("Not enough memory to store the codes of the selected groups."); + /***** I I haven't selected any group, show by default the groups I belong to *****/ + /* Get list of groups of all types in current course I belong to */ + Grp_GetLstCodGrpsUsrBelongs (Gbl.CurrentCrs.Crs.CrsCod,-1L, + Gbl.Usrs.Me.UsrDat.UsrCod,&LstGrpsIBelong); - /***** Get parameter with list of groups to list *****/ - Par_GetParMultiToText ("GrpCods",LstCodGrps,MaxSizeLstGrpCods); + if (LstGrpsIBelong.NumGrps) + { + /* Allocate space for list of selected groups */ + if ((Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods = (long *) calloc (LstGrpsIBelong.NumGrps,sizeof (long))) == NULL) + Lay_ShowErrorAndExit ("Not enough memory to store the codes of the selected groups."); - if (LstCodGrps[0]) - { - /***** Count number of groups selected from LstCodGrps *****/ - for (Ptr = LstCodGrps, NumGrp = 0; - *Ptr; - NumGrp++) - Par_GetNextStrUntilSeparParamMult (&Ptr,LongStr,1+10); - Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps = NumGrp; - } + /* Fill list of selected groups with list of groups I belong to */ + for (NumGrp = 0; + NumGrp < LstGrpsIBelong.NumGrps; + NumGrp++) + Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrp] = LstGrpsIBelong.GrpCods[NumGrp]; + Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps = LstGrpsIBelong.NumGrps; + } - if (Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps) // If I have selected groups... - { - /***** Create a list of groups selected from LstCodGrps *****/ - if ((Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod = (long *) calloc (Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps,sizeof (long))) == NULL) - Lay_ShowErrorAndExit ("Not enough memory to store the codes of the selected groups."); - for (Ptr = LstCodGrps, NumGrp = 0; - *Ptr; - NumGrp++) - { - Par_GetNextStrUntilSeparParamMult (&Ptr,LongStr,1+10); - Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod[NumGrp] = Str_ConvertStrCodToLongCod (LongStr); - } - } - else // If I haven't selected any group... - { - /***** I I haven't selected any group, show by default the groups I belong to *****/ - if (Gbl.CurrentCrs.Grps.NumGrps) - { - Grp_GetLstCodGrpsUsrBelongs (Gbl.CurrentCrs.Crs.CrsCod,-1L, - Gbl.Usrs.Me.UsrDat.UsrCod,&LstGrpsIBelong); - if (LstGrpsIBelong.NumGrps) - { - if ((Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod = (long *) calloc (LstGrpsIBelong.NumGrps,sizeof (long))) == NULL) - Lay_ShowErrorAndExit ("Not enough memory to store the codes of the selected groups."); - for (NumGrp = 0; - NumGrp < LstGrpsIBelong.NumGrps; - NumGrp++) - Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod[NumGrp] = LstGrpsIBelong.GrpCod[NumGrp]; - Grp_FreeListCodGrp (&LstGrpsIBelong); - Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps = LstGrpsIBelong.NumGrps; - } - } - } - - /***** Free memory used for the list of groups to show *****/ - free ((void *) LstCodGrps); + /* Free list of groups I belong to */ + Grp_FreeListCodGrp (&LstGrpsIBelong); } /***** If no groups selected ==> show all groups *****/ @@ -428,57 +388,55 @@ void Grp_GetParCodsSeveralGrpsToShowUsrs (void) } /*****************************************************************************/ -/***************** Get parameters related to groups selected *****************/ +/**************** Get parameter with list of groups selected *****************/ /*****************************************************************************/ -// TODO: Grp_GetParCodsSeveralGrpsToEditAsgAttOrSvy is very similar to Grp_GetParCodsSeveralGrpsToShowUsrs ==> merge code -void Grp_GetParCodsSeveralGrpsToEditAsgAttOrSvy (void) +void Grp_GetParCodsSeveralGrps (void) { - unsigned long MaxSizeLstGrpCods; - char *LstCodGrps; + char *ParamLstCodGrps; const char *Ptr; - char LongStr[1+10+1]; + char LongStr[1 + 10 + 1]; unsigned NumGrp; + unsigned long MaxSizeLstGrpCods = ((1 + 10 + 1) * Gbl.CurrentCrs.Grps.NumGrps) - 1; - /***** Set default for number of groups selected by me *****/ + /***** Reset number of groups selected *****/ Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps = 0; - if (Gbl.CurrentCrs.Grps.NumGrps) + if (Gbl.CurrentCrs.Grps.NumGrps) // If course has groups { - /***** Allocate memory for the list of group codes *****/ - MaxSizeLstGrpCods = ((1+10+1) * Gbl.CurrentCrs.Grps.NumGrps) - 1; - if ((LstCodGrps = (char *) malloc (MaxSizeLstGrpCods + 1)) == NULL) - Lay_ShowErrorAndExit ("Not enough memory to store the codes of the selected groups."); + /***** Allocate memory for the list of group codes selected *****/ + if ((ParamLstCodGrps = (char *) malloc (MaxSizeLstGrpCods + 1)) == NULL) + Lay_ShowErrorAndExit ("Not enough memory to store the codes of the selected groups."); /***** Get parameter with list of groups to list *****/ - Par_GetParMultiToText ("GrpCods",LstCodGrps,MaxSizeLstGrpCods); + Par_GetParMultiToText ("GrpCods",ParamLstCodGrps,MaxSizeLstGrpCods); - if (LstCodGrps[0]) - { - /***** Count number of groups selected from LstCodGrps *****/ - for (Ptr = LstCodGrps, NumGrp = 0; - *Ptr; - NumGrp++) - Par_GetNextStrUntilSeparParamMult (&Ptr,LongStr,1+10); - Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps = NumGrp; - } + if (ParamLstCodGrps[0]) + { + /***** Count number of groups selected from LstCodGrps *****/ + for (Ptr = ParamLstCodGrps, NumGrp = 0; + *Ptr; + NumGrp++) + Par_GetNextStrUntilSeparParamMult (&Ptr,LongStr,1+10); + Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps = NumGrp; - if (Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps) // If I have selected groups... - { - /***** Create a list of groups selected from LstCodGrps *****/ - if ((Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod = (long *) calloc (Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps,sizeof (long))) == NULL) - Lay_ShowErrorAndExit ("Not enough memory to store the codes of the selected groups."); - for (Ptr = LstCodGrps, NumGrp = 0; - *Ptr; - NumGrp++) - { - Par_GetNextStrUntilSeparParamMult (&Ptr,LongStr,1+10); - Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod[NumGrp] = Str_ConvertStrCodToLongCod (LongStr); - } - } + if (Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps) // If I have selected groups... + { + /***** Create a list of groups selected from LstCodGrps *****/ + if ((Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods = (long *) calloc (Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps,sizeof (long))) == NULL) + Lay_ShowErrorAndExit ("Not enough memory to store the codes of the selected groups."); + for (Ptr = ParamLstCodGrps, NumGrp = 0; + *Ptr; + NumGrp++) + { + Par_GetNextStrUntilSeparParamMult (&Ptr,LongStr,1+10); + Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrp] = Str_ConvertStrCodToLongCod (LongStr); + } + } + } /***** Free memory used for the list of groups to show *****/ - free ((void *) LstCodGrps); + free ((void *) ParamLstCodGrps); } } @@ -490,10 +448,10 @@ void Grp_FreeListCodSelectedGrps (void) { if (Gbl.CurrentCrs.Grps.LstGrpsSel.NestedCalls > 0) if (--Gbl.CurrentCrs.Grps.LstGrpsSel.NestedCalls == 0) - if (Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod) + if (Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods) { - free ((void *) Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod); - Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod = NULL; + free ((void *) Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods); + Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods = NULL; Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps = 0; } } @@ -527,7 +485,7 @@ void Grp_ChangeMyGrps (void) Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_ONLY_GROUP_TYPES_WITH_GROUPS); /***** Get the group codes which I want to join to *****/ - LstGrpsIWant.GrpCod = NULL; // Initialized to avoid bug reported by Coverity + LstGrpsIWant.GrpCods = NULL; // Initialized to avoid bug reported by Coverity LstGrpsIWant.NumGrps = 0; // Initialized to avoid bug reported by Coverity Grp_GetLstCodsGrpWanted (&LstGrpsIWant); @@ -577,7 +535,7 @@ void Grp_ChangeOtherUsrGrps (void) Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_ONLY_GROUP_TYPES_WITH_GROUPS); /***** Get the list of groups to which register this user *****/ - LstGrpsUsrWants.GrpCod = NULL; // Initialized to avoid bug reported by Coverity + LstGrpsUsrWants.GrpCods = NULL; // Initialized to avoid bug reported by Coverity LstGrpsUsrWants.NumGrps = 0; // Initialized to avoid bug reported by Coverity Grp_GetLstCodsGrpWanted (&LstGrpsUsrWants); @@ -650,7 +608,7 @@ bool Grp_ChangeMyGrpsAtomically (struct ListCodGrps *LstGrpsIWant) for (NumGrpIWant = 0, RemoveMeFromThisGrp = true; NumGrpIWant < LstGrpsIWant->NumGrps && RemoveMeFromThisGrp; NumGrpIWant++) - if (LstGrpsIBelong.GrpCod[NumGrpIBelong] == LstGrpsIWant->GrpCod[NumGrpIWant]) + if (LstGrpsIBelong.GrpCods[NumGrpIBelong] == LstGrpsIWant->GrpCods[NumGrpIWant]) RemoveMeFromThisGrp = false; if (RemoveMeFromThisGrp) /* Check if the group is closed */ @@ -662,7 +620,7 @@ bool Grp_ChangeMyGrpsAtomically (struct ListCodGrps *LstGrpsIWant) for (NumGrpThisType = 0; NumGrpThisType < GrpTyp->NumGrps && !ITryToLeaveAClosedGroup; NumGrpThisType++) - if ((GrpTyp->LstGrps[NumGrpThisType]).GrpCod == LstGrpsIBelong.GrpCod[NumGrpIBelong]) + if ((GrpTyp->LstGrps[NumGrpThisType]).GrpCod == LstGrpsIBelong.GrpCods[NumGrpIBelong]) if (!((GrpTyp->LstGrps[NumGrpThisType]).Open)) ITryToLeaveAClosedGroup = true; } @@ -680,7 +638,7 @@ bool Grp_ChangeMyGrpsAtomically (struct ListCodGrps *LstGrpsIWant) for (NumGrpIBelong = 0, RegisterMeInThisGrp = true; NumGrpIBelong < LstGrpsIBelong.NumGrps && RegisterMeInThisGrp; NumGrpIBelong++) - if (LstGrpsIWant->GrpCod[NumGrpIWant] == LstGrpsIBelong.GrpCod[NumGrpIBelong]) + if (LstGrpsIWant->GrpCods[NumGrpIWant] == LstGrpsIBelong.GrpCods[NumGrpIBelong]) RegisterMeInThisGrp = false; if (RegisterMeInThisGrp) /* Check if the group is closed or full */ @@ -696,7 +654,7 @@ bool Grp_ChangeMyGrpsAtomically (struct ListCodGrps *LstGrpsIWant) !ITryToRegisterInAClosedGroup && !ITryToRegisterInFullGroup; NumGrpThisType++) - if ((GrpTyp->LstGrps[NumGrpThisType]).GrpCod == LstGrpsIWant->GrpCod[NumGrpIWant]) + if ((GrpTyp->LstGrps[NumGrpThisType]).GrpCod == LstGrpsIWant->GrpCods[NumGrpIWant]) { /* Check if the group is closed */ if (!((GrpTyp->LstGrps[NumGrpThisType]).Open)) @@ -722,10 +680,10 @@ bool Grp_ChangeMyGrpsAtomically (struct ListCodGrps *LstGrpsIWant) for (NumGrpIWant = 0, RemoveMeFromThisGrp = true; NumGrpIWant < LstGrpsIWant->NumGrps && RemoveMeFromThisGrp; NumGrpIWant++) - if (LstGrpsIBelong.GrpCod[NumGrpIBelong] == LstGrpsIWant->GrpCod[NumGrpIWant]) + if (LstGrpsIBelong.GrpCods[NumGrpIBelong] == LstGrpsIWant->GrpCods[NumGrpIWant]) RemoveMeFromThisGrp = false; if (RemoveMeFromThisGrp) - Grp_RemoveUsrFromGroup (Gbl.Usrs.Me.UsrDat.UsrCod,LstGrpsIBelong.GrpCod[NumGrpIBelong]); + Grp_RemoveUsrFromGroup (Gbl.Usrs.Me.UsrDat.UsrCod,LstGrpsIBelong.GrpCods[NumGrpIBelong]); } /***** Go across the list of groups that I want to register in, adding those groups that are not present in the list of groups I belong to *****/ @@ -736,10 +694,10 @@ bool Grp_ChangeMyGrpsAtomically (struct ListCodGrps *LstGrpsIWant) for (NumGrpIBelong = 0, RegisterMeInThisGrp = true; NumGrpIBelong < LstGrpsIBelong.NumGrps && RegisterMeInThisGrp; NumGrpIBelong++) - if (LstGrpsIWant->GrpCod[NumGrpIWant] == LstGrpsIBelong.GrpCod[NumGrpIBelong]) + if (LstGrpsIWant->GrpCods[NumGrpIWant] == LstGrpsIBelong.GrpCods[NumGrpIBelong]) RegisterMeInThisGrp = false; if (RegisterMeInThisGrp) - Grp_AddUsrToGroup (&Gbl.Usrs.Me.UsrDat,LstGrpsIWant->GrpCod[NumGrpIWant]); + Grp_AddUsrToGroup (&Gbl.Usrs.Me.UsrDat,LstGrpsIWant->GrpCods[NumGrpIWant]); } ChangesMade = true; @@ -798,10 +756,10 @@ bool Grp_ChangeGrpsOtherUsrAtomically (struct ListCodGrps *LstGrpsUsrWants) for (NumGrpUsrWants = 0, RemoveUsrFromThisGrp = true; NumGrpUsrWants < LstGrpsUsrWants->NumGrps && RemoveUsrFromThisGrp; NumGrpUsrWants++) - if (LstGrpsUsrBelongs.GrpCod[NumGrpUsrBelongs] == LstGrpsUsrWants->GrpCod[NumGrpUsrWants]) + if (LstGrpsUsrBelongs.GrpCods[NumGrpUsrBelongs] == LstGrpsUsrWants->GrpCods[NumGrpUsrWants]) RemoveUsrFromThisGrp = false; if (RemoveUsrFromThisGrp) - Grp_RemoveUsrFromGroup (Gbl.Usrs.Other.UsrDat.UsrCod,LstGrpsUsrBelongs.GrpCod[NumGrpUsrBelongs]); + Grp_RemoveUsrFromGroup (Gbl.Usrs.Other.UsrDat.UsrCod,LstGrpsUsrBelongs.GrpCods[NumGrpUsrBelongs]); } /***** Go across the list of groups that user wants to register in, adding those groups that are not present in the list of groups user belongs to *****/ @@ -812,10 +770,10 @@ bool Grp_ChangeGrpsOtherUsrAtomically (struct ListCodGrps *LstGrpsUsrWants) for (NumGrpUsrBelongs = 0, RegisterUsrInThisGrp = true; NumGrpUsrBelongs < LstGrpsUsrBelongs.NumGrps && RegisterUsrInThisGrp; NumGrpUsrBelongs++) - if (LstGrpsUsrWants->GrpCod[NumGrpUsrWants] == LstGrpsUsrBelongs.GrpCod[NumGrpUsrBelongs]) + if (LstGrpsUsrWants->GrpCods[NumGrpUsrWants] == LstGrpsUsrBelongs.GrpCods[NumGrpUsrBelongs]) RegisterUsrInThisGrp = false; if (RegisterUsrInThisGrp) - Grp_AddUsrToGroup (&Gbl.Usrs.Other.UsrDat,LstGrpsUsrWants->GrpCod[NumGrpUsrWants]); + Grp_AddUsrToGroup (&Gbl.Usrs.Other.UsrDat,LstGrpsUsrWants->GrpCods[NumGrpUsrWants]); } ChangesMade = true; @@ -859,7 +817,7 @@ bool Grp_CheckIfSelectionGrpsIsValid (struct ListCodGrps *LstGrps) SelectionValid && NumCodGrp < LstGrps->NumGrps; NumCodGrp++) { - GrpTypCod = Grp_GetTypeOfGroupOfAGroup (LstGrps->GrpCod[NumCodGrp]); + GrpTypCod = Grp_GetTypeOfGroupOfAGroup (LstGrps->GrpCods[NumCodGrp]); if (!Grp_GetMultipleEnrollmentOfAGroupType (GrpTypCod)) for (NumGrpTyp = 0; NumGrpTyp < Gbl.CurrentCrs.Grps.GrpTypes.Num; @@ -938,7 +896,7 @@ void Grp_RegisterUsrIntoGroups (struct UsrData *UsrDat,struct ListCodGrps *LstGr /***** Query in the database the group codes of any group of this type the student belongs to *****/ LstGrpsHeBelongs.NumGrps = 0; // Initialized to avoid bug reported by Coverity - LstGrpsHeBelongs.GrpCod = NULL; // Initialized to avoid bug reported by Coverity + LstGrpsHeBelongs.GrpCods = NULL; // Initialized to avoid bug reported by Coverity Grp_GetLstCodGrpsUsrBelongs (Gbl.CurrentCrs.Crs.CrsCod,Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].GrpTypCod, UsrDat->UsrCod,&LstGrpsHeBelongs); @@ -951,7 +909,7 @@ void Grp_RegisterUsrIntoGroups (struct UsrData *UsrDat,struct ListCodGrps *LstGr for (NumGrpThisType = 0; NumGrpThisType < Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps; NumGrpThisType++) - if (LstGrps->GrpCod[NumGrpSel] == Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].LstGrps[NumGrpThisType].GrpCod) + if (LstGrps->GrpCods[NumGrpSel] == Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].LstGrps[NumGrpThisType].GrpCod) { // The selected group is of this type AlreadyRegisteredInGrp = false; @@ -959,13 +917,13 @@ void Grp_RegisterUsrIntoGroups (struct UsrData *UsrDat,struct ListCodGrps *LstGr for (NumGrpHeBelongs = 0; NumGrpHeBelongs < LstGrpsHeBelongs.NumGrps; NumGrpHeBelongs++) - if (LstGrps->GrpCod[NumGrpSel] == LstGrpsHeBelongs.GrpCod[NumGrpHeBelongs]) + if (LstGrps->GrpCods[NumGrpSel] == LstGrpsHeBelongs.GrpCods[NumGrpHeBelongs]) AlreadyRegisteredInGrp = true; else if (!MultipleEnrollment) // If the type of group is of single enrollment { /* If the enrollment is single and the group to which the user belongs is different from the selected ==> remove user from the group to which he belongs */ - Grp_RemoveUsrFromGroup (UsrDat->UsrCod,LstGrpsHeBelongs.GrpCod[NumGrpHeBelongs]); + Grp_RemoveUsrFromGroup (UsrDat->UsrCod,LstGrpsHeBelongs.GrpCods[NumGrpHeBelongs]); sprintf (Gbl.Message,Txt_THE_USER_X_has_been_removed_from_the_group_of_type_Y_to_which_it_belonged, UsrDat->FullName,Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].GrpTypName); Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); @@ -973,7 +931,7 @@ void Grp_RegisterUsrIntoGroups (struct UsrData *UsrDat,struct ListCodGrps *LstGr if (!AlreadyRegisteredInGrp) // If the user does not belong to the selected group { - Grp_AddUsrToGroup (UsrDat,LstGrps->GrpCod[NumGrpSel]); + Grp_AddUsrToGroup (UsrDat,LstGrps->GrpCods[NumGrpSel]); sprintf (Gbl.Message,Txt_THE_USER_X_has_been_enrolled_in_the_group_of_type_Y_Z, UsrDat->FullName,Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].GrpTypName, Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].LstGrps[NumGrpThisType].GrpName); @@ -1015,9 +973,9 @@ unsigned Grp_RemoveUsrFromGroups (struct UsrData *UsrDat,struct ListCodGrps *Lst NumGrpHeBelongs < LstGrpsHeBelongs.NumGrps; NumGrpHeBelongs++) /* If the user belongs to a selected group from which he must be removed */ - if (LstGrpsHeBelongs.GrpCod[NumGrpHeBelongs] == LstGrps->GrpCod[NumGrpSel]) + if (LstGrpsHeBelongs.GrpCods[NumGrpHeBelongs] == LstGrps->GrpCods[NumGrpSel]) { - Grp_RemoveUsrFromGroup (UsrDat->UsrCod,LstGrpsHeBelongs.GrpCod[NumGrpHeBelongs]); + Grp_RemoveUsrFromGroup (UsrDat->UsrCod,LstGrpsHeBelongs.GrpCods[NumGrpHeBelongs]); NumGrpsHeIsRemoved++; } @@ -1893,7 +1851,7 @@ static void Grp_ListGrpsForMultipleSelection (struct GroupType *GrpTyp) for (NumGrpSel = 0; NumGrpSel < Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps; NumGrpSel++) - if (Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod[NumGrpSel] == Grp->GrpCod) + if (Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel] == Grp->GrpCod) { fprintf (Gbl.F.Out," checked=\"checked\""); break; @@ -1923,7 +1881,7 @@ static void Grp_ListGrpsForMultipleSelection (struct GroupType *GrpTyp) for (NumGrpSel = 0; NumGrpSel < Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps; NumGrpSel++) - if (Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod[NumGrpSel] == -(GrpTyp->GrpTypCod)) + if (Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel] == -(GrpTyp->GrpTypCod)) { fprintf (Gbl.F.Out," checked=\"checked\""); break; @@ -2997,7 +2955,7 @@ static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod, if (LstGrps->NumGrps) { /***** Create a list of groups the user belongs to *****/ - if ((LstGrps->GrpCod = (long *) calloc (LstGrps->NumGrps,sizeof (long))) == NULL) + if ((LstGrps->GrpCods = (long *) calloc (LstGrps->NumGrps,sizeof (long))) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store codes of groups a user belongs to."); for (NumGrp = 0; NumGrp < LstGrps->NumGrps; @@ -3006,7 +2964,7 @@ static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod, row = mysql_fetch_row (mysql_res); /* Get the code of group (row[0]) */ - if ((LstGrps->GrpCod[NumGrp] = Str_ConvertStrCodToLongCod (row[0])) < 0) + if ((LstGrps->GrpCods[NumGrp] = Str_ConvertStrCodToLongCod (row[0])) < 0) Lay_ShowErrorAndExit ("Wrong code of group."); } } @@ -3041,7 +2999,7 @@ void Grp_GetLstCodGrpsWithFileZonesIBelong (struct ListCodGrps *LstGrps) if (LstGrps->NumGrps) { /***** Create a list of groups I belong to *****/ - if ((LstGrps->GrpCod = (long *) calloc (LstGrps->NumGrps,sizeof (long))) == NULL) + if ((LstGrps->GrpCods = (long *) calloc (LstGrps->NumGrps,sizeof (long))) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store codes of groups I belongs to."); for (NumGrp = 0; NumGrp < LstGrps->NumGrps; @@ -3050,7 +3008,7 @@ void Grp_GetLstCodGrpsWithFileZonesIBelong (struct ListCodGrps *LstGrps) row = mysql_fetch_row (mysql_res); /* Get the code of group (row[0]) */ - if ((LstGrps->GrpCod[NumGrp] = Str_ConvertStrCodToLongCod (row[0])) < 0) + if ((LstGrps->GrpCods[NumGrp] = Str_ConvertStrCodToLongCod (row[0])) < 0) Lay_ShowErrorAndExit ("Wrong code of group."); } } @@ -3070,7 +3028,7 @@ static bool Grp_CheckIfGrpIsInList (long GrpCod,struct ListCodGrps *LstGrps) for (NumGrp = 0; NumGrp < LstGrps->NumGrps; NumGrp++) - if (GrpCod == LstGrps->GrpCod[NumGrp]) + if (GrpCod == LstGrps->GrpCods[NumGrp]) return true; return false; } @@ -4191,7 +4149,7 @@ void Grp_GetLstCodsGrpWanted (struct ListCodGrps *LstGrpsWanted) with all the groups selected (of all the types) *****/ if (LstGrpsWanted->NumGrps) { - if ((LstGrpsWanted->GrpCod = (long *) calloc (LstGrpsWanted->NumGrps,sizeof (long))) == NULL) + if ((LstGrpsWanted->GrpCods = (long *) calloc (LstGrpsWanted->NumGrps,sizeof (long))) == NULL) Lay_ShowErrorAndExit ("Not enoguh memory to store codes of groups in which a user wants to be enrolled."); /***** Get the groups *****/ @@ -4205,7 +4163,7 @@ void Grp_GetLstCodsGrpWanted (struct ListCodGrps *LstGrpsWanted) NumGrpWanted++) { Par_GetNextStrUntilSeparParamMult (&Ptr,LongStr,1+10); - LstGrpsWanted->GrpCod[NumGrpWanted] = Str_ConvertStrCodToLongCod (LongStr); + LstGrpsWanted->GrpCods[NumGrpWanted] = Str_ConvertStrCodToLongCod (LongStr); } /* Free memory used by the list of group codes of this type */ free ((void *) LstStrCodGrps[NumGrpTyp]); @@ -4222,9 +4180,9 @@ void Grp_GetLstCodsGrpWanted (struct ListCodGrps *LstGrpsWanted) void Grp_FreeListCodGrp (struct ListCodGrps *LstGrps) { - if (LstGrps->NumGrps && LstGrps->GrpCod) - free ((void *) LstGrps->GrpCod); - LstGrps->GrpCod = NULL; + if (LstGrps->NumGrps && LstGrps->GrpCods) + free ((void *) LstGrps->GrpCods); + LstGrps->GrpCods = NULL; LstGrps->NumGrps = 0; } diff --git a/swad_group.h b/swad_group.h index 0cc9e640..c94a3307 100644 --- a/swad_group.h +++ b/swad_group.h @@ -93,7 +93,7 @@ struct GroupTypes }; struct ListCodGrps { - long *GrpCod; + long *GrpCods; unsigned NumGrps; int NestedCalls; // Number of nested calls to the function that allocates memory for this list }; @@ -124,7 +124,7 @@ void Grp_ReqEditGroups (void); void Grp_ShowFormToSelectSeveralGroups (Act_Action_t NextAction); void Grp_PutParamsCodGrps (void); void Grp_GetParCodsSeveralGrpsToShowUsrs (void); -void Grp_GetParCodsSeveralGrpsToEditAsgAttOrSvy (void); +void Grp_GetParCodsSeveralGrps (void); void Grp_FreeListCodSelectedGrps (void); void Grp_ChangeMyGrpsAndShowChanges (void); void Grp_ChangeMyGrps (void); diff --git a/swad_survey.c b/swad_survey.c index 9ea177b0..51b7d169 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -2219,7 +2219,7 @@ void Svy_RecFormSurvey (void) if (NewSurveyIsCorrect) { /* Get groups for this surveys */ - Grp_GetParCodsSeveralGrpsToEditAsgAttOrSvy (); + Grp_GetParCodsSeveralGrps (); if (ItsANewSurvey) Svy_CreateSurvey (&NewSvy,Txt); // Add new survey to database @@ -2423,7 +2423,7 @@ static void Svy_CreateGrps (long SvyCod) { /* Create group */ sprintf (Query,"INSERT INTO svy_grp (SvyCod,GrpCod) VALUES ('%ld','%ld')", - SvyCod,Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod[NumGrpSel]); + SvyCod,Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]); DB_QueryINSERT (Query,"can not associate a group to a survey"); } } diff --git a/swad_user.c b/swad_user.c index a1871bf1..341e8888 100644 --- a/swad_user.c +++ b/swad_user.c @@ -3872,7 +3872,7 @@ static void Usr_BuildQueryToGetUsrsLstCrs (Rol_Role_t Role, for (NumGrpSel = 0; NumGrpSel < Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps; NumGrpSel++) - if ((GrpCod = Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod[NumGrpSel]) > 0) + if ((GrpCod = Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]) > 0) NumPositiveCods++; else for (NumGrpTyp = 0; @@ -3893,7 +3893,7 @@ static void Usr_BuildQueryToGetUsrsLstCrs (Rol_Role_t Role, for (NumGrpSel = 0; NumGrpSel < Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps; NumGrpSel++) - if ((GrpCod = Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod[NumGrpSel]) > 0) + if ((GrpCod = Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]) > 0) { Str_Concat (Query,NumPositiveCods ? " OR GrpCod='" : " GrpCod='", diff --git a/swad_web_service.c b/swad_web_service.c index fa800bf5..cbf16309 100644 --- a/swad_web_service.c +++ b/swad_web_service.c @@ -1897,7 +1897,7 @@ int swad__sendMyGroups (struct soap *soap, /***** Get the group codes which I want to join to *****/ LstGrpsIWant.NumGrps = 0; - LstGrpsIWant.GrpCod = NULL; + LstGrpsIWant.GrpCods = NULL; if (myGroups[0]) { @@ -1911,7 +1911,7 @@ int swad__sendMyGroups (struct soap *soap, if (LstGrpsIWant.NumGrps) // If I have selected groups... { /***** Create a list of groups selected from myGroups *****/ - if ((LstGrpsIWant.GrpCod = (long *) calloc (LstGrpsIWant.NumGrps,sizeof (long))) == NULL) + if ((LstGrpsIWant.GrpCods = (long *) calloc (LstGrpsIWant.NumGrps,sizeof (long))) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store the codes of the selected groups."); for (NumGrp = 0, Ptr = myGroups; *Ptr; @@ -1919,7 +1919,7 @@ int swad__sendMyGroups (struct soap *soap, { /* Find next string in text until comma (leading and trailing spaces are removed) */ Str_GetNextStringUntilComma (&Ptr,LongStr,1+10); - LstGrpsIWant.GrpCod[NumGrp] = Str_ConvertStrCodToLongCod (LongStr); + LstGrpsIWant.GrpCods[NumGrp] = Str_ConvertStrCodToLongCod (LongStr); } } } @@ -2465,7 +2465,7 @@ static void Svc_GetLstGrpsSel (const char *Groups) // Here NestedCalls is always 0 Gbl.CurrentCrs.Grps.LstGrpsSel.NestedCalls++; // Here NestedCalls is always 1 - if ((Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod = (long *) calloc (Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps,sizeof (long))) == NULL) + if ((Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods = (long *) calloc (Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps,sizeof (long))) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store the codes of the selected groups."); for (Ptr = Groups, NumGrp = 0; @@ -2473,8 +2473,8 @@ static void Svc_GetLstGrpsSel (const char *Groups) ) { Str_GetNextStringUntilComma (&Ptr,LongStr,1+10); - Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod[NumGrp] = Str_ConvertStrCodToLongCod (LongStr); - if (Grp_CheckIfGroupBelongsToCourse (Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCod[NumGrp],Gbl.CurrentCrs.Crs.CrsCod)) + Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrp] = Str_ConvertStrCodToLongCod (LongStr); + if (Grp_CheckIfGroupBelongsToCourse (Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrp],Gbl.CurrentCrs.Crs.CrsCod)) NumGrp++; } Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps = NumGrp; // Update number of groups