From 6e2bdbf4aaa14903b383b07bc2f15f39b2f49724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Wed, 13 Nov 2019 21:31:06 +0100 Subject: [PATCH] Version19.66.4 --- swad_action.c | 18 ++++---- swad_assignment.c | 2 +- swad_attendance.c | 68 ++++++++++++---------------- swad_changelog.h | 5 ++- swad_follow.c | 8 ++-- swad_global.c | 2 +- swad_match_result.c | 6 +-- swad_message.c | 6 +-- swad_project.c | 78 ++++++++++++++++---------------- swad_record.c | 10 ++--- swad_statistic.c | 6 +-- swad_test.c | 6 +-- swad_user.c | 107 +++++++++++++++++++++++++++++++++++++++----- swad_user.h | 16 +++++-- 14 files changed, 210 insertions(+), 128 deletions(-) diff --git a/swad_action.c b/swad_action.c index 930c449d..950cf4f3 100644 --- a/swad_action.c +++ b/swad_action.c @@ -1280,16 +1280,16 @@ Users: 1064. ActCnfID_Std Confirm another user's ID 1065. ActCnfID_Tch Confirm another user's ID - 1066. ActFrmAccOth Show forms to the change another user's account - 1067. ActFrmAccStd Show forms to the change another user's account - 1068. ActFrmAccTch Show forms to the change another user's account + 1066. ActFrmAccOth Show forms to the change another user's account + 1067. ActFrmAccStd Show forms to the change another user's account + 1068. ActFrmAccTch Show forms to the change another user's account - 1069. ActRemOldNicOth Remove one of another user's old nicknames - 1070. ActRemOldNicStd Remove one of another user's old nicknames - 1071. ActRemOldNicTch Remove one of another user's old nicknames - 1072. ActChgNicOth Change another user's nickname - 1073. ActChgNicStd Change another user's nickname - 1074. ActChgNicTch Change another user's nickname + 1069. ActRemOldNicOth Remove one of another user's old nicknames + 1070. ActRemOldNicStd Remove one of another user's old nicknames + 1071. ActRemOldNicTch Remove one of another user's old nicknames + 1072. ActChgNicOth Change another user's nickname + 1073. ActChgNicStd Change another user's nickname + 1074. ActChgNicTch Change another user's nickname 1075. ActRemID_Oth Remove one of the IDs of another user 1076. ActRemID_Std Remove one of the IDs of another user diff --git a/swad_assignment.c b/swad_assignment.c index 981e2222..838071d3 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -525,7 +525,7 @@ static void Asg_WriteAssignmentFolder (struct Assignment *Asg,bool PrintView) break; case Rol_NET: case Rol_TCH: - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); break; default: break; diff --git a/swad_attendance.c b/swad_attendance.c index c94f168b..27ea4e09 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -119,7 +119,9 @@ static void Att_PutLinkAttEvent (struct AttendanceEvent *AttEvent, const char *LinkStyle); static void Att_PutParamsCodGrps (long AttCod); static void Att_GetNumStdsTotalWhoAreInAttEvent (struct AttendanceEvent *Att); -static unsigned Att_GetNumStdsFromAListWhoAreInAttEvent (long AttCod,long LstSelectedUsrCods[],unsigned NumUsrsInList); +static unsigned Att_GetNumUsrsFromAListWhoAreInAttEvent (long AttCod, + long LstSelectedUsrCods[], + unsigned NumUsrsInList); static bool Att_CheckIfUsrIsInTableAttUsr (long AttCod,long UsrCod,bool *Present); static bool Att_CheckIfUsrIsPresentInAttEvent (long AttCod,long UsrCod); static bool Att_CheckIfUsrIsPresentInAttEventAndGetComments (long AttCod,long UsrCod, @@ -2362,7 +2364,7 @@ void Att_RegisterStudentsInAttEvent (void) /***** Free memory *****/ /* Free memory used by list of selected students' codes */ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); // 5. Delete from att_usr all the students marked as Remove=true // 6. Replace (insert without duplicated) into att_usr all the students marked as Remove=false @@ -2432,43 +2434,24 @@ static void Att_GetNumStdsTotalWhoAreInAttEvent (struct AttendanceEvent *Att) } /*****************************************************************************/ -/******* Get number of students from a list who attended to an event *********/ +/********* Get number of users from a list who attended to an event **********/ /*****************************************************************************/ -static unsigned Att_GetNumStdsFromAListWhoAreInAttEvent (long AttCod,long LstSelectedUsrCods[],unsigned NumUsrsInList) +static unsigned Att_GetNumUsrsFromAListWhoAreInAttEvent (long AttCod, + long LstSelectedUsrCods[], + unsigned NumUsrsInList) { - char *SubQueryAllUsrs = NULL; - char SubQueryOneUsr[1 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]; - unsigned NumUsr; - unsigned NumStdsInAttEvent = 0; - size_t MaxLength; + char *SubQueryAllUsrs; + unsigned NumUsrsInAttEvent; if (NumUsrsInList) { - /***** Allocate space for subquery *****/ - MaxLength = 256 + NumUsrsInList * (1 + Cns_MAX_DECIMAL_DIGITS_LONG); - if ((SubQueryAllUsrs = (char *) malloc (MaxLength + 1)) == NULL) - Lay_NotEnoughMemoryExit (); - SubQueryAllUsrs[0] = '\0'; + /***** Create subquery string *****/ + Usr_CreateSubqueryUsrCods (LstSelectedUsrCods,NumUsrsInList, + &SubQueryAllUsrs); - /***** Count number of students registered in an event in database *****/ - for (NumUsr = 0; - NumUsr < NumUsrsInList; - NumUsr++) - if (NumUsr) - { - snprintf (SubQueryOneUsr,sizeof (SubQueryOneUsr), - ",%ld", - LstSelectedUsrCods[NumUsr]); - Str_Concat (SubQueryAllUsrs,SubQueryOneUsr, - MaxLength); - } - else - snprintf (SubQueryAllUsrs,sizeof (SubQueryOneUsr), - "%ld", - LstSelectedUsrCods[NumUsr]); - - NumStdsInAttEvent = + /***** Get number of users in attendance event from database ****/ + NumUsrsInAttEvent = (unsigned) DB_QueryCOUNT ("can not get number of students" " from a list who are registered in an event", "SELECT COUNT(*) FROM att_usr" @@ -2477,9 +2460,12 @@ static unsigned Att_GetNumStdsFromAListWhoAreInAttEvent (long AttCod,long LstSel AttCod,SubQueryAllUsrs); /***** Free memory for subquery string *****/ - free (SubQueryAllUsrs); + Usr_FreeSubqueryUsrCods (SubQueryAllUsrs); } - return NumStdsInAttEvent; + else + NumUsrsInAttEvent = 0; + + return NumUsrsInAttEvent; } /*****************************************************************************/ @@ -2712,8 +2698,9 @@ static void Usr_ListOrPrintMyAttendanceCrs (Att_TypeOfView_t TypeOfView) NumAttEvent < Gbl.AttEvents.Num; NumAttEvent++) /* Get number of students in this event */ - Gbl.AttEvents.Lst[NumAttEvent].NumStdsFromList = Att_GetNumStdsFromAListWhoAreInAttEvent (Gbl.AttEvents.Lst[NumAttEvent].AttCod, - &Gbl.Usrs.Me.UsrDat.UsrCod,1); + Gbl.AttEvents.Lst[NumAttEvent].NumStdsFromList = + Att_GetNumUsrsFromAListWhoAreInAttEvent (Gbl.AttEvents.Lst[NumAttEvent].AttCod, + &Gbl.Usrs.Me.UsrDat.UsrCod,1); /***** Get list of attendance events selected *****/ Att_GetListSelectedAttCods (&Gbl.AttEvents.StrAttCodsSelected); @@ -2782,7 +2769,7 @@ static void Usr_ListOrPrintUsrsAttendanceCrs (Att_TypeOfView_t TypeOfView) Usr_GetListsSelectedUsrsCods (); /* Check the number of students to list */ - if ((NumUsrsInList = Usr_CountNumUsrsInListOfSelectedUsrs ())) + if ((NumUsrsInList = Usr_CountNumUsrsInListOfSelectedEncryptedUsrCods ())) { /***** Get boolean parameter that indicates if details must be shown *****/ Gbl.AttEvents.ShowDetails = Par_GetParToBool ("ShowDetails"); @@ -2798,8 +2785,9 @@ static void Usr_ListOrPrintUsrsAttendanceCrs (Att_TypeOfView_t TypeOfView) NumAttEvent < Gbl.AttEvents.Num; NumAttEvent++) /* Get number of students in this event */ - Gbl.AttEvents.Lst[NumAttEvent].NumStdsFromList = Att_GetNumStdsFromAListWhoAreInAttEvent (Gbl.AttEvents.Lst[NumAttEvent].AttCod, - LstSelectedUsrCods,NumUsrsInList); + Gbl.AttEvents.Lst[NumAttEvent].NumStdsFromList = + Att_GetNumUsrsFromAListWhoAreInAttEvent (Gbl.AttEvents.Lst[NumAttEvent].AttCod, + LstSelectedUsrCods,NumUsrsInList); /***** Get list of attendance events selected *****/ Att_GetListSelectedAttCods (&Gbl.AttEvents.StrAttCodsSelected); @@ -2844,7 +2832,7 @@ static void Usr_ListOrPrintUsrsAttendanceCrs (Att_TypeOfView_t TypeOfView) } /***** Free memory used by list of selected users' codes *****/ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); /***** Free list of attendance events *****/ Att_FreeListAttEvents (); diff --git a/swad_changelog.h b/swad_changelog.h index 066b2350..c9587103 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -487,7 +487,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.66.3 (2019-11-13)" +#define Log_PLATFORM_VERSION "SWAD 19.66.4 (2019-11-13)" #define CSS_FILE "swad19.47.css" #define JS_FILE "swad19.65.js" /* @@ -496,7 +496,8 @@ ps2pdf source.ps destination.pdf // TODO: Importante: filtrar proyectos por usuarios (igual que en trabajos o en asistencia) // TODO: Code refactoring in HTML h1, title, meta, video, p, iframe, input hidden, area - Version 19.66.4: Nov 13, 2019 Filter projects by selected users. (? lines) + Version 19.66.5: Nov 13, 2019 Filter projects by selected users. (? lines) + Version 19.66.4: Nov 13, 2019 Code refactoring in list of users in attendance event. (246729 lines) Version 19.66.3: Nov 13, 2019 Filter projects by selected users. Not finished. (246656 lines) Version 19.66.2: Nov 13, 2019 Fixed bug in edition of test question. (246628 lines) Version 19.66.1: Nov 13, 2019 Filter projects by selected users. Not finished. (246627 lines) diff --git a/swad_follow.c b/swad_follow.c index 808a0bf2..e4b75767 100644 --- a/swad_follow.c +++ b/swad_follow.c @@ -1103,7 +1103,7 @@ static void Fol_RequestFollowUsrs (Act_Action_t NextAction) } /***** Free memory used by list of selected users' codes *****/ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); } void Fol_RequestUnfollowStds (void) @@ -1147,7 +1147,7 @@ static void Fol_RequestUnfollowUsrs (Act_Action_t NextAction) } /***** Free memory used by list of selected users' codes *****/ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); } /*****************************************************************************/ @@ -1239,7 +1239,7 @@ void Fol_FollowUsrs () Usr_UsrDataDestructor (&UsrDat); /***** Free memory used by list of selected users' codes *****/ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); /***** Show alert *****/ if (NumFollowed == 1) @@ -1286,7 +1286,7 @@ void Fol_UnfollowUsrs (void) Usr_UsrDataDestructor (&UsrDat); /***** Free memory used by list of selected users' codes *****/ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); /***** Show alert *****/ if (NumUnfollowed == 1) diff --git a/swad_global.c b/swad_global.c index 355d4219..e85add59 100644 --- a/swad_global.c +++ b/swad_global.c @@ -466,7 +466,7 @@ void Gbl_Cleanup (void) Usr_FreeUsrsList (Role); Usr_FreeListOtherRecipients (); - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); Syl_FreeListItemsSyllabus (); Tst_FreeTagsList (); Exa_FreeMemExamAnnouncement (); diff --git a/swad_match_result.c b/swad_match_result.c index 72987264..42c8b978 100644 --- a/swad_match_result.c +++ b/swad_match_result.c @@ -250,7 +250,7 @@ void McR_SelUsrsToViewUsrsMchResults (void) Usr_FreeUsrsList (Rol_STD); /***** Free memory used by list of selected users' codes *****/ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); /***** Free memory for list of selected groups *****/ Grp_FreeListCodSelectedGrps (); @@ -274,7 +274,7 @@ void McR_ShowUsrsMchResults (void) Dat_GetIniEndDatesFromForm (); /***** Check the number of users whose matches results will be shown *****/ - if (Usr_CountNumUsrsInListOfSelectedUsrs ()) // If some users are selected... + if (Usr_CountNumUsrsInListOfSelectedEncryptedUsrCods ()) // If some users are selected... { /***** Begin box and table *****/ Box_StartBoxTable (NULL,Txt_Results,NULL, @@ -308,7 +308,7 @@ void McR_ShowUsrsMchResults (void) } /***** Free memory used by list of selected users' codes *****/ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); } /*****************************************************************************/ diff --git a/swad_message.c b/swad_message.c index 4b5caa75..f6d5c6b5 100644 --- a/swad_message.c +++ b/swad_message.c @@ -350,7 +350,7 @@ static void Msg_PutFormMsgUsrs (char Content[Cns_MAX_BYTES_LONG_TEXT + 1]) } /***** Free memory used by list of selected users' codes *****/ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); /***** Free memory for list of selected groups *****/ Grp_FreeListCodSelectedGrps (); @@ -728,7 +728,7 @@ void Msg_RecMsgFromUsr (void) Error = Usr_GetListMsgRecipientsWrittenExplicitelyBySender (true); /***** Check number of recipients *****/ - if ((NumRecipients = Usr_CountNumUsrsInListOfSelectedUsrs ())) + if ((NumRecipients = Usr_CountNumUsrsInListOfSelectedEncryptedUsrCods ())) { if (Gbl.Usrs.Me.Role.Logged == Rol_STD && NumRecipients > Cfg_MAX_RECIPIENTS) @@ -847,7 +847,7 @@ void Msg_RecMsgFromUsr (void) /***** Free memory *****/ /* Free memory used for list of users */ Usr_FreeListOtherRecipients (); - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); /***** Update received message setting Replied field to true *****/ if (Replied) diff --git a/swad_project.c b/swad_project.c index 9b9510fc..1345604b 100644 --- a/swad_project.c +++ b/swad_project.c @@ -125,7 +125,6 @@ struct Prj_Faults /*****************************************************************************/ static void Prj_ReqListUsrsToSelect (void); -static void Prj_GetListSelectedUsrCods (unsigned NumUsrsInList,long **LstSelectedUsrCods); static void Prj_ShowProjectsInCurrentPage (void); @@ -278,38 +277,6 @@ static void Prj_ReqListUsrsToSelect (void) Txt_View_projects); } -/*****************************************************************************/ -/************* Get list of users selected to show their projects *************/ -/*****************************************************************************/ - -static void Prj_GetListSelectedUsrCods (unsigned NumUsrsInList,long **LstSelectedUsrCods) - { - unsigned NumUsr; - const char *Ptr; - struct UsrData UsrDat; - - /***** Create list of user codes *****/ - if ((*LstSelectedUsrCods = (long *) calloc ((size_t) NumUsrsInList,sizeof (long))) == NULL) - Lay_NotEnoughMemoryExit (); - - /***** Initialize structure with user's data *****/ - Usr_UsrDataConstructor (&UsrDat); - - /***** Loop over the list Gbl.Usrs.Selected.List[Rol_UNK] getting users' codes *****/ - for (NumUsr = 0, Ptr = Gbl.Usrs.Selected.List[Rol_UNK]; - NumUsr < NumUsrsInList && *Ptr; - NumUsr++) - { - Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod, - Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64); - Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat); - (*LstSelectedUsrCods)[NumUsr] = UsrDat.UsrCod; - } - - /***** Free memory used for user's data *****/ - Usr_UsrDataDestructor (&UsrDat); - } - /*****************************************************************************/ /********************** Show selected projects in a table ********************/ /*****************************************************************************/ @@ -2691,13 +2658,11 @@ static void Prj_GetListProjects (void) /***** Get list of selected users' codes if not already got *****/ Usr_GetListsSelectedUsrsCods (); - NumUsrsInList = Usr_CountNumUsrsInListOfSelectedUsrs (); + NumUsrsInList = Usr_CountNumUsrsInListOfSelectedEncryptedUsrCods (); /***** Get list of users selected to show their projects *****/ if (NumUsrsInList) - Prj_GetListSelectedUsrCods (NumUsrsInList,&LstSelectedUsrCods); - - // TODO: Filter by selected users if any + Usr_GetListSelectedUsrCods (NumUsrsInList,&LstSelectedUsrCods); /***** Get list of projects from database *****/ if (Gbl.Prjs.LstIsRead) @@ -2808,6 +2773,41 @@ static void Prj_GetListProjects (void) } break; case Usr_WHO_SELECTED: + switch (Gbl.Prjs.SelectedOrder) + { + case Prj_ORDER_START_TIME: + case Prj_ORDER_END_TIME: + case Prj_ORDER_TITLE: + NumRows = DB_QuerySELECT (&mysql_res,"can not get projects", + "SELECT projects.PrjCod" + " FROM projects,prj_usr" + " WHERE projects.CrsCod=%ld" + "%s%s%s" + " AND projects.PrjCod=prj_usr.PrjCod" + " AND prj_usr.UsrCod=%ld" + " ORDER BY %s", + Gbl.Hierarchy.Crs.CrsCod, + PreNonSubQuery,HidVisSubQuery,DptCodSubQuery, + Gbl.Usrs.Me.UsrDat.UsrCod, + OrderBySubQuery[Gbl.Prjs.SelectedOrder]); + break; + case Prj_ORDER_DEPARTMENT: + NumRows = DB_QuerySELECT (&mysql_res,"can not get projects", + "SELECT projects.PrjCod" + " FROM prj_usr,projects LEFT JOIN departments" + " ON projects.DptCod=departments.DptCod" + " WHERE projects.CrsCod=%ld" + "%s%s%s" + " AND projects.PrjCod=prj_usr.PrjCod" + " AND prj_usr.UsrCod=%ld" + " ORDER BY %s", + Gbl.Hierarchy.Crs.CrsCod, + PreNonSubQuery,HidVisSubQuery,DptCodSubQuery, + Gbl.Usrs.Me.UsrDat.UsrCod, + OrderBySubQuery[Gbl.Prjs.SelectedOrder]); + break; + } + break; case Usr_WHO_ALL: switch (Gbl.Prjs.SelectedOrder) { @@ -2894,10 +2894,10 @@ static void Prj_GetListProjects (void) /***** Free list of user codes *****/ if (NumUsrsInList) - free (LstSelectedUsrCods); + Usr_FreeListSelectedUsrCods (LstSelectedUsrCods); /***** Free memory used by list of selected users' codes *****/ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); } /*****************************************************************************/ diff --git a/swad_record.c b/swad_record.c index 1af752f1..0e4d311c 100644 --- a/swad_record.c +++ b/swad_record.c @@ -1035,7 +1035,7 @@ static void Rec_ListRecordsGsts (Rec_SharedRecordViewType_t TypeOfView) Usr_UsrDataDestructor (&UsrDat); /***** Free memory used by list of selected users' codes *****/ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); } /*****************************************************************************/ @@ -1080,7 +1080,7 @@ static void Rec_ShowRecordOneStdCrs (void) Frm_StartForm (ActPrnRecSevStd); Usr_CreateListSelectedUsrsCodsAndFillWithOtherUsr (); Usr_PutHiddenParSelectedUsrsCods (); - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); Rec_ShowLinkToPrintPreviewOfRecords (); Frm_EndForm (); @@ -1259,7 +1259,7 @@ static void Rec_ListRecordsStds (Rec_SharedRecordViewType_t ShaTypeOfView, Rec_FreeListFields (); /***** Free memory used by list of selected users' codes *****/ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); } /*****************************************************************************/ @@ -1312,7 +1312,7 @@ static void Rec_ShowRecordOneTchCrs (void) Frm_StartForm (ActPrnRecSevTch); Usr_CreateListSelectedUsrsCodsAndFillWithOtherUsr (); Usr_PutHiddenParSelectedUsrsCods (); - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); Par_PutHiddenParamChar ("ParamOfficeHours",'Y'); Par_PutHiddenParamChar ("ShowOfficeHours",ShowOfficeHours ? 'Y' : 'N'); @@ -1474,7 +1474,7 @@ static void Rec_ListRecordsTchs (Rec_SharedRecordViewType_t TypeOfView) Usr_UsrDataDestructor (&UsrDat); /***** Free memory used by list of selected users' codes *****/ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); } /*****************************************************************************/ diff --git a/swad_statistic.c b/swad_statistic.c index 752bec4c..7e580df6 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -916,11 +916,11 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse) HTM_SECTION_Begin (Sta_STAT_RESULTS_SECTION_ID); /***** Check selection *****/ - if (!Usr_CountNumUsrsInListOfSelectedUsrs ()) // Error: there are no users selected + if (!Usr_CountNumUsrsInListOfSelectedEncryptedUsrCods ()) // Error: there are no users selected { /* Write warning message, clean and abort */ Ale_ShowAlert (Ale_WARNING,Txt_You_must_select_one_ore_more_users); - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); return; } break; @@ -1495,7 +1495,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse) /***** Free memory used by list of selected users' codes *****/ if (Gbl.Action.Act == ActSeeAccCrs) - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); /***** Write time zone used in the calculation of these statistics *****/ switch (Gbl.Stat.ClicksGroupedBy) diff --git a/swad_test.c b/swad_test.c index e446f337..96f1dcb8 100644 --- a/swad_test.c +++ b/swad_test.c @@ -7532,7 +7532,7 @@ void Tst_SelUsrsToViewUsrsTstResults (void) Usr_FreeUsrsList (Rol_STD); /***** Free memory used by list of selected users' codes *****/ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); /***** Free memory for list of selected groups *****/ Grp_FreeListCodSelectedGrps (); @@ -7646,7 +7646,7 @@ void Tst_ShowUsrsTstResults (void) Dat_GetIniEndDatesFromForm (); /***** Check the number of users whose tests results will be shown *****/ - if (Usr_CountNumUsrsInListOfSelectedUsrs ()) // If some users are selected... + if (Usr_CountNumUsrsInListOfSelectedEncryptedUsrCods ()) // If some users are selected... { /***** Begin box and table *****/ Box_StartBoxTable (NULL,Txt_Results,NULL, @@ -7680,7 +7680,7 @@ void Tst_ShowUsrsTstResults (void) } /***** Free memory used by list of selected users' codes *****/ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); } /*****************************************************************************/ diff --git a/swad_user.c b/swad_user.c index 5ad25c81..4d0f7ec9 100644 --- a/swad_user.c +++ b/swad_user.c @@ -205,7 +205,7 @@ static void Usr_PutButtonToConfirmIWantToSeeBigList (unsigned NumUsrs, const char *OnSubmit); static void Usr_PutParamsConfirmIWantToSeeBigList (void); -static void Usr_AllocateListSelectedUsrCod (Rol_Role_t Role); +static void Usr_AllocateListSelectedEncryptedUsrCods (Rol_Role_t Role); static void Usr_AllocateListOtherRecipients (void); static void Usr_FormToSelectUsrListType (void (*FuncParams) (void), @@ -5723,7 +5723,7 @@ void Usr_GetListsSelectedUsrsCods (void) if (!Gbl.Usrs.Selected.Filled) // Get list only if not already got { /***** Get possible list of all selected users *****/ - Usr_AllocateListSelectedUsrCod (Rol_UNK); + Usr_AllocateListSelectedEncryptedUsrCods (Rol_UNK); if (Gbl.Session.IsOpen) // If the session is open, get parameter from DB { Ses_GetHiddenParFromDB (Usr_ParamUsrCod[Rol_UNK],Gbl.Usrs.Selected.List[Rol_UNK], @@ -5742,7 +5742,7 @@ void Usr_GetListsSelectedUsrsCods (void) if (Usr_ParamUsrCod[Role]) { /* Get parameter with selected users with this role */ - Usr_AllocateListSelectedUsrCod (Role); + Usr_AllocateListSelectedEncryptedUsrCods (Role); Par_GetParMultiToText (Usr_ParamUsrCod[Role],Gbl.Usrs.Selected.List[Role], Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS); @@ -5900,7 +5900,7 @@ bool Usr_GetListMsgRecipientsWrittenExplicitelyBySender (bool WriteErrorMsgs) Usr_GetUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS); // Really only EncryptedUsrCod is needed /* Find if encrypted user's code is already in list */ - if (!Usr_FindUsrCodInListOfSelectedUsrs (UsrDat.EncryptedUsrCod)) // If not in list ==> add it + if (!Usr_FindEncryptedUsrCodsInListOfSelectedEncryptedUsrCods (UsrDat.EncryptedUsrCod)) // If not in list ==> add it { LengthUsrCod = strlen (UsrDat.EncryptedUsrCod); @@ -5951,7 +5951,7 @@ bool Usr_GetListMsgRecipientsWrittenExplicitelyBySender (bool WriteErrorMsgs) /*****************************************************************************/ // Returns true if EncryptedUsrCodToFind is in Gbl.Usrs.Selected.List[Rol_UNK] -bool Usr_FindUsrCodInListOfSelectedUsrs (const char *EncryptedUsrCodToFind) +bool Usr_FindEncryptedUsrCodsInListOfSelectedEncryptedUsrCods (const char *EncryptedUsrCodToFind) { const char *Ptr; char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1]; @@ -5974,7 +5974,7 @@ bool Usr_FindUsrCodInListOfSelectedUsrs (const char *EncryptedUsrCodToFind) /************ Count number of valid users' IDs in encrypted list *************/ /*****************************************************************************/ -unsigned Usr_CountNumUsrsInListOfSelectedUsrs (void) +unsigned Usr_CountNumUsrsInListOfSelectedEncryptedUsrCods (void) { const char *Ptr; unsigned NumUsrs = 0; @@ -5998,7 +5998,7 @@ unsigned Usr_CountNumUsrsInListOfSelectedUsrs (void) /*****************************************************************************/ // Role = Rol_UNK here means all users -static void Usr_AllocateListSelectedUsrCod (Rol_Role_t Role) +static void Usr_AllocateListSelectedEncryptedUsrCods (Rol_Role_t Role) { if (!Gbl.Usrs.Selected.List[Role]) { @@ -6013,7 +6013,7 @@ static void Usr_AllocateListSelectedUsrCod (Rol_Role_t Role) /*****************************************************************************/ // Role = Rol_UNK here means all users -void Usr_FreeListsSelectedUsrsCods (void) +void Usr_FreeListsSelectedEncryptedUsrsCods (void) { Rol_Role_t Role; @@ -6036,6 +6036,89 @@ void Usr_FreeListsSelectedUsrsCods (void) } } +/*****************************************************************************/ +/************* Get list of users selected to show their projects *************/ +/*****************************************************************************/ + +void Usr_GetListSelectedUsrCods (unsigned NumUsrsInList,long **LstSelectedUsrCods) + { + unsigned NumUsr; + const char *Ptr; + struct UsrData UsrDat; + + /***** Create list of user codes *****/ + if ((*LstSelectedUsrCods = (long *) calloc ((size_t) NumUsrsInList,sizeof (long))) == NULL) + Lay_NotEnoughMemoryExit (); + + /***** Initialize structure with user's data *****/ + Usr_UsrDataConstructor (&UsrDat); + + /***** Loop over the list Gbl.Usrs.Selected.List[Rol_UNK] getting users' codes *****/ + for (NumUsr = 0, Ptr = Gbl.Usrs.Selected.List[Rol_UNK]; + NumUsr < NumUsrsInList && *Ptr; + NumUsr++) + { + Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod, + Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64); + Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat); + (*LstSelectedUsrCods)[NumUsr] = UsrDat.UsrCod; + } + + /***** Free memory used for user's data *****/ + Usr_UsrDataDestructor (&UsrDat); + } + +void Usr_FreeListSelectedUsrCods (long *LstSelectedUsrCods) + { + if (LstSelectedUsrCods) + free (LstSelectedUsrCods); + } + +/*****************************************************************************/ +/******** Create subquery string with users' codes separated by commas *******/ +/******** from list of users' codes *******/ +/*****************************************************************************/ + +void Usr_CreateSubqueryUsrCods (long LstSelectedUsrCods[], + unsigned NumUsrsInList, + char **SubQueryAllUsrs) + { + char SubQueryOneUsr[1 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]; + unsigned NumUsr; + size_t MaxLength; + + if (NumUsrsInList) + { + /***** Allocate space for subquery *****/ + MaxLength = NumUsrsInList * (1 + Cns_MAX_DECIMAL_DIGITS_LONG); + if ((*SubQueryAllUsrs = (char *) malloc (MaxLength + 1)) == NULL) + Lay_NotEnoughMemoryExit (); + (*SubQueryAllUsrs)[0] = '\0'; + + /***** Count number of students registered in an event in database *****/ + for (NumUsr = 0; + NumUsr < NumUsrsInList; + NumUsr++) + if (NumUsr) + { + snprintf (SubQueryOneUsr,sizeof (SubQueryOneUsr), + ",%ld", + LstSelectedUsrCods[NumUsr]); + Str_Concat (*SubQueryAllUsrs,SubQueryOneUsr, + MaxLength); + } + else + snprintf (*SubQueryAllUsrs,sizeof (SubQueryOneUsr), + "%ld", + LstSelectedUsrCods[NumUsr]); + } + } + +void Usr_FreeSubqueryUsrCods (char *SubQueryAllUsrs) + { + free (SubQueryAllUsrs); + } + /*****************************************************************************/ /********** Allocate memory for list of users's IDs or nicknames *************/ /*****************************************************************************/ @@ -6254,7 +6337,7 @@ void Usr_GetSelectedUsrsAndGoToAct (void (*FuncWhenUsrsSelected) (), Usr_GetListsSelectedUsrsCods (); /***** Check number of users *****/ - if (Usr_CountNumUsrsInListOfSelectedUsrs ()) // If some users are selected... + if (Usr_CountNumUsrsInListOfSelectedEncryptedUsrCods ()) // If some users are selected... FuncWhenUsrsSelected (); else // If no users are selected... { @@ -6265,7 +6348,7 @@ void Usr_GetSelectedUsrsAndGoToAct (void (*FuncWhenUsrsSelected) (), } /***** Free memory used by list of selected users' codes *****/ - Usr_FreeListsSelectedUsrsCods (); + Usr_FreeListsSelectedEncryptedUsrsCods (); } /*****************************************************************************/ @@ -6378,7 +6461,7 @@ static void Usr_PutCheckboxToSelectUser (Rol_Role_t Role, CheckboxChecked = true; else /* Check if user is in lists of selected users */ - CheckboxChecked = Usr_FindUsrCodInListOfSelectedUsrs (EncryptedUsrCod); + CheckboxChecked = Usr_FindEncryptedUsrCodsInListOfSelectedEncryptedUsrCods (EncryptedUsrCod); /***** Check box *****/ HTM_INPUT_CHECKBOX (Usr_ParamUsrCod[Role],false, @@ -8371,7 +8454,7 @@ void Usr_DoActionOnSeveralUsrs1 (void) Usr_GetListsSelectedUsrsCods (); /* Check the number of users */ - if (!Usr_CountNumUsrsInListOfSelectedUsrs ())// If no users selected... + if (!Usr_CountNumUsrsInListOfSelectedEncryptedUsrCods ())// If no users selected... { // ...write warning notice Ale_CreateAlert (Ale_WARNING,NULL, Txt_You_must_select_one_ore_more_users); diff --git a/swad_user.h b/swad_user.h index 0e83af57..1ded3fd9 100644 --- a/swad_user.h +++ b/swad_user.h @@ -432,9 +432,19 @@ void Usr_PutHiddenParSelectedUsrsCods (void); void Usr_CreateListSelectedUsrsCodsAndFillWithOtherUsr (void); void Usr_GetListsSelectedUsrsCods (void); bool Usr_GetListMsgRecipientsWrittenExplicitelyBySender (bool WriteErrorMsgs); -bool Usr_FindUsrCodInListOfSelectedUsrs (const char *EncryptedUsrCodToFind); -unsigned Usr_CountNumUsrsInListOfSelectedUsrs (void); -void Usr_FreeListsSelectedUsrsCods (void); + +bool Usr_FindEncryptedUsrCodsInListOfSelectedEncryptedUsrCods (const char *EncryptedUsrCodToFind); +unsigned Usr_CountNumUsrsInListOfSelectedEncryptedUsrCods (void); +void Usr_FreeListsSelectedEncryptedUsrsCods (void); + +void Usr_GetListSelectedUsrCods (unsigned NumUsrsInList,long **LstSelectedUsrCods); +void Usr_FreeListSelectedUsrCods (long *LstSelectedUsrCods); + +void Usr_CreateSubqueryUsrCods (long LstSelectedUsrCods[], + unsigned NumUsrsInList, + char **SubQueryAllUsrs); +void Usr_FreeSubqueryUsrCods (char *SubQueryAllUsrs); + void Usr_FreeListOtherRecipients (void); void Usr_ShowFormsToSelectUsrListType (void (*FuncParams) (void));