diff --git a/swad_attendance.c b/swad_attendance.c index 1f623a37..3fc25513 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -92,14 +92,12 @@ static void Att_PutButtonToCreateNewAttEvent (struct Att_Events *Events); static void Att_PutParamsToCreateNewAttEvent (void *Events); static void Att_PutParamsToListUsrsAttendance (void *Events); -static void Att_ShowOneAttEvent (struct Att_Events *Events, - struct Att_Event *Event, - bool ShowOnlyThisAttEventComplete); +static void Att_ShowOneAttEventRow (struct Att_Events *Events, + bool ShowOnlyThisAttEventComplete); static void Att_WriteAttEventAuthor (struct Att_Event *Event); static Dat_StartEndTime_t Att_GetParamAttOrder (void); static void Att_PutFormsToRemEditOneAttEvent (struct Att_Events *Events, - const struct Att_Event *Event, const char *Anchor); static void Att_PutParams (void *Events); static void Att_GetListAttEvents (struct Att_Events *Events, @@ -118,8 +116,7 @@ static void Att_ShowEvent (struct Att_Events *Events); static void Att_PutIconsOneAtt (void *Events); static void Att_ListAttOnlyMeAsStudent (struct Att_Event *Event); -static void Att_ListAttStudents (struct Att_Events *Events, - struct Att_Event *Event); +static void Att_ListAttStudents (struct Att_Events *Events); static void Att_WriteRowUsrToCallTheRoll (unsigned NumUsr, struct Usr_Data *UsrDat, struct Att_Event *Event); @@ -146,22 +143,22 @@ static void Att_PutIconsStdsAttList (void *Events); static void Att_PutParamsToPrintStdsList (void *Events); static void Att_PutButtonToShowDetails (const struct Att_Events *Events); -static void Att_ListEventsToSelect (const struct Att_Events *Events, +static void Att_ListEventsToSelect (struct Att_Events *Events, Att_TypeOfView_t TypeOfView); static void Att_PutIconToViewAttEvents (__attribute__((unused)) void *Args); static void Att_PutIconToEditAttEvents (__attribute__((unused)) void *Args); -static void Att_ListUsrsAttendanceTable (const struct Att_Events *Events, +static void Att_ListUsrsAttendanceTable (struct Att_Events *Events, Att_TypeOfView_t TypeOfView, unsigned NumUsrsInList, long *LstSelectedUsrCods); -static void Att_WriteTableHeadSeveralAttEvents (const struct Att_Events *Events); +static void Att_WriteTableHeadSeveralAttEvents (struct Att_Events *Events); static void Att_WriteRowUsrSeveralAttEvents (const struct Att_Events *Events, unsigned NumUsr,struct Usr_Data *UsrDat); static void Att_PutCheckOrCross (bool Present); -static void Att_ListStdsWithAttEventsDetails (const struct Att_Events *Events, +static void Att_ListStdsWithAttEventsDetails (struct Att_Events *Events, unsigned NumUsrsInList, long *LstSelectedUsrCods); -static void Att_ListAttEventsForAStd (const struct Att_Events *Events, +static void Att_ListAttEventsForAStd (struct Att_Events *Events, unsigned NumUsr,struct Usr_Data *UsrDat); /*****************************************************************************/ @@ -174,7 +171,7 @@ static void Att_ResetEvents (struct Att_Events *Events) Events->Num = 0; // Number of attendance events Events->Lst = NULL; // List of attendance events Events->SelectedOrder = Att_ORDER_DEFAULT; - Events->AttCod = -1L; + Events->Event.AttCod = -1L; Events->ShowDetails = false; Events->StrAttCodsSelected = NULL; Events->CurrentPage = 0; @@ -292,9 +289,16 @@ static void Att_ShowAllAttEvents (struct Att_Events *Events) for (NumAttEvent = Pagination.FirstItemVisible, The_ResetRowColor (); NumAttEvent <= Pagination.LastItemVisible; NumAttEvent++, The_ChangeRowColor ()) - Att_ShowOneAttEvent (Events, - &Events->Lst[NumAttEvent - 1], - false); + { + /***** Get data of this attendance event *****/ + Events->Event.AttCod = Events->Lst[NumAttEvent - 1].AttCod; + Att_GetDataOfAttEventByCodAndCheckCrs (&Events->Event); + Events->Event.NumStdsTotal = Att_DB_GetNumStdsTotalWhoAreInAttEvent (Events->Event.AttCod); + + /***** Show one attendance event *****/ + Att_ShowOneAttEventRow (Events, + false); // Don't show only this event + } /***** End table *****/ HTM_TABLE_End (); @@ -443,9 +447,8 @@ static void Att_PutParamsToListUsrsAttendance (void *Events) /*****************************************************************************/ // Only Event->AttCod must be filled -static void Att_ShowOneAttEvent (struct Att_Events *Events, - struct Att_Event *Event, - bool ShowOnlyThisAttEventComplete) +static void Att_ShowOneAttEventRow (struct Att_Events *Events, + bool ShowOnlyThisAttEventComplete) { extern const char *Txt_View_event; char *Anchor = NULL; @@ -454,32 +457,20 @@ static void Att_ShowOneAttEvent (struct Att_Events *Events, Dat_StartEndTime_t StartEndTime; char Description[Cns_MAX_BYTES_TEXT + 1]; - /***** Get data of this attendance event *****/ - Att_GetDataOfAttEventByCodAndCheckCrs (Event); - Event->NumStdsTotal = Att_DB_GetNumStdsTotalWhoAreInAttEvent (Event->AttCod); - /***** Set anchor string *****/ - Frm_SetAnchorStr (Event->AttCod,&Anchor); + Frm_SetAnchorStr (Events->Event.AttCod,&Anchor); /***** Write first row of data of this attendance event *****/ /* Forms to remove/edit this attendance event */ HTM_TR_Begin (NULL); - if (ShowOnlyThisAttEventComplete) - HTM_TD_Begin ("rowspan=\"2\" class=\"CONTEXT_COL\""); - else + if (!ShowOnlyThisAttEventComplete) + { HTM_TD_Begin ("rowspan=\"2\" class=\"CONTEXT_COL %s\"", The_GetColorRows ()); - switch (Gbl.Usrs.Me.Role.Logged) - { - case Rol_TCH: - case Rol_SYS_ADM: - Att_PutFormsToRemEditOneAttEvent (Events,Event,Anchor); - break; - default: - break; + Att_PutFormsToRemEditOneAttEvent (Events,Anchor); + HTM_TD_End (); } - HTM_TD_End (); /* Start/end date/time */ UniqueId++; @@ -492,21 +483,21 @@ static void Att_ShowOneAttEvent (struct Att_Events *Events, if (ShowOnlyThisAttEventComplete) HTM_TD_Begin ("id=\"%s\" class=\"LB %s_%s\"", Id, - Event->Hidden ? (Event->Open ? "DATE_GREEN_LIGHT" : - "DATE_RED_LIGHT") : - (Event->Open ? "DATE_GREEN" : - "DATE_RED"), + Events->Event.Hidden ? (Events->Event.Open ? "DATE_GREEN_LIGHT" : + "DATE_RED_LIGHT") : + (Events->Event.Open ? "DATE_GREEN" : + "DATE_RED"), The_GetSuffix ()); else HTM_TD_Begin ("id=\"%s\" class=\"LB %s_%s %s\"", Id, - Event->Hidden ? (Event->Open ? "DATE_GREEN_LIGHT" : - "DATE_RED_LIGHT") : - (Event->Open ? "DATE_GREEN" : - "DATE_RED"), + Events->Event.Hidden ? (Events->Event.Open ? "DATE_GREEN_LIGHT" : + "DATE_RED_LIGHT") : + (Events->Event.Open ? "DATE_GREEN" : + "DATE_RED"), The_GetSuffix (), The_GetColorRows ()); - Dat_WriteLocalDateHMSFromUTC (Id,Event->TimeUTC[StartEndTime], + Dat_WriteLocalDateHMSFromUTC (Id,Events->Event.TimeUTC[StartEndTime], Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK, true,true,true,0x7); HTM_TD_End (); @@ -519,7 +510,7 @@ static void Att_ShowOneAttEvent (struct Att_Events *Events, else HTM_TD_Begin ("class=\"LT %s\"",The_GetColorRows ()); HTM_ARTICLE_Begin (Anchor); - Att_PutLinkAttEvent (Event,Txt_View_event,Event->Title); + Att_PutLinkAttEvent (&Events->Event,Txt_View_event,Events->Event.Title); HTM_ARTICLE_End (); HTM_TD_End (); @@ -529,10 +520,10 @@ static void Att_ShowOneAttEvent (struct Att_Events *Events, else HTM_TD_Begin ("class=\"RT %s\"",The_GetColorRows ()); HTM_SPAN_Begin ("class=\"%s_%s\"", - Event->Hidden ? "ASG_TITLE_LIGHT" : - "ASG_TITLE", + Events->Event.Hidden ? "ASG_TITLE_LIGHT" : + "ASG_TITLE", The_GetSuffix ()); - HTM_Unsigned (Event->NumStdsTotal); + HTM_Unsigned (Events->Event.NumStdsTotal); HTM_SPAN_End (); HTM_TD_End (); @@ -546,11 +537,11 @@ static void Att_ShowOneAttEvent (struct Att_Events *Events, HTM_TD_Begin ("colspan=\"2\" class=\"LT\""); else HTM_TD_Begin ("colspan=\"2\" class=\"LT %s\"",The_GetColorRows ()); - Att_WriteAttEventAuthor (Event); + Att_WriteAttEventAuthor (&Events->Event); HTM_TD_End (); /* Text of the attendance event */ - Att_DB_GetAttEventDescription (Event->AttCod,Description); + Att_DB_GetAttEventDescription (Events->Event.AttCod,Description); Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, Description,Cns_MAX_BYTES_TEXT,false); // Convert from HTML to recpectful HTML ALn_InsertLinks (Description,Cns_MAX_BYTES_TEXT,60); // Insert links @@ -559,11 +550,11 @@ static void Att_ShowOneAttEvent (struct Att_Events *Events, else HTM_TD_Begin ("colspan=\"2\" class=\"LT %s\"",The_GetColorRows ()); if (Gbl.Crs.Grps.NumGrps) - Att_GetAndWriteNamesOfGrpsAssociatedToAttEvent (Event); + Att_GetAndWriteNamesOfGrpsAssociatedToAttEvent (&Events->Event); HTM_DIV_Begin ("class=\"%s_%s\"", - Event->Hidden ? "DAT_LIGHT" : - "DAT", + Events->Event.Hidden ? "DAT_LIGHT" : + "DAT", The_GetSuffix ()); HTM_Txt (Description); HTM_DIV_End (); @@ -603,7 +594,6 @@ static Dat_StartEndTime_t Att_GetParamAttOrder (void) /*****************************************************************************/ static void Att_PutFormsToRemEditOneAttEvent (struct Att_Events *Events, - const struct Att_Event *Event, const char *Anchor) { static Act_Action_t ActionHideUnhide[2] = @@ -612,20 +602,42 @@ static void Att_PutFormsToRemEditOneAttEvent (struct Att_Events *Events, [true ] = ActUnhAtt, // Hidden ==> action to unhide }; - Events->AttCod = Event->AttCod; + if (Att_CheckIfICanEditAttEvents ()) + { + /***** Icon to remove attendance event *****/ + Ico_PutContextualIconToRemove (ActReqRemAtt,NULL, + Att_PutParams,Events); - /***** Icon to remove attendance event *****/ - Ico_PutContextualIconToRemove (ActReqRemAtt,NULL, - Att_PutParams,Events); + /***** Icon to hide/unhide attendance event *****/ + Ico_PutContextualIconToHideUnhide (ActionHideUnhide,Anchor, + Att_PutParams,Events, + Events->Event.Hidden); - /***** Icon to hide/unhide attendance event *****/ - Ico_PutContextualIconToHideUnhide (ActionHideUnhide,Anchor, - Att_PutParams,Events, - Event->Hidden); + /***** Icon to edit attendance event *****/ + Ico_PutContextualIconToEdit (ActEdiOneAtt,NULL, + Att_PutParams,Events); + } - /***** Icon to edit attendance event *****/ - Ico_PutContextualIconToEdit (ActEdiOneAtt,NULL, - Att_PutParams,Events); + /***** Icon to get resource link *****/ + if (PrgRsc_CheckIfICanGetLink ()) + Ico_PutContextualIconToGetLink (ActReqLnkAtt,NULL, + Att_PutParams,Events); + } + + +/*****************************************************************************/ +/******************* Check if I can edit calls for exams *********************/ +/*****************************************************************************/ + +bool Att_CheckIfICanEditAttEvents (void) + { + static const bool ICanEditAttEvents[Rol_NUM_ROLES] = + { + [Rol_TCH ] = true, + [Rol_SYS_ADM] = true, + }; + + return ICanEditAttEvents[Gbl.Usrs.Me.Role.Logged]; } /*****************************************************************************/ @@ -638,7 +650,7 @@ static void Att_PutParams (void *Events) if (Events) { - Att_PutParamAttCod (((struct Att_Events *) Events)->AttCod); + Att_PutParamAttCod (((struct Att_Events *) Events)->Event.AttCod); Dat_PutHiddenParamOrder (((struct Att_Events *) Events)->SelectedOrder); WhichGroups = Grp_GetParamWhichGroups (); Grp_PutParamWhichGroups (&WhichGroups); @@ -773,8 +785,6 @@ static void Att_ResetAttendanceEvent (struct Att_Event *Event) { Event->AttCod = -1L; Event->NumStdsTotal = 0; - Event->NumStdsFromList = 0; - Event->Selected = false; } Event->CrsCod = -1L; Event->Hidden = false; @@ -809,7 +819,7 @@ static void Att_FreeListAttEvents (struct Att_Events *Events) static void Att_PutParamSelectedAttCod (void *Events) { if (Events) - Att_PutParamAttCod (((struct Att_Events *) Events)->AttCod); + Att_PutParamAttCod (((struct Att_Events *) Events)->Event.AttCod); } void Att_PutParamAttCod (long AttCod) @@ -1466,7 +1476,7 @@ void Att_SeeOneAttEvent (void) Att_ResetEvents (&Events); /***** Get attendance event code *****/ - if ((Events.AttCod = Att_GetParamAttCod ()) < 0) + if ((Events.Event.AttCod = Att_GetParamAttCod ()) < 0) Err_WrongEventExit (); /***** Show event *****/ @@ -1477,35 +1487,34 @@ static void Att_ShowEvent (struct Att_Events *Events) { extern const char *Hlp_USERS_Attendance; extern const char *Txt_Event; - struct Att_Event Event; /***** Get parameters *****/ Events->SelectedOrder = Att_GetParamAttOrder (); Grp_GetParamWhichGroups (); Events->CurrentPage = Pag_GetParamPagNum (Pag_ATT_EVENTS); - /***** Begin box and table *****/ + /***** Get data of this attendance event *****/ + Att_GetDataOfAttEventByCodAndCheckCrs (&Events->Event); + Events->Event.NumStdsTotal = Att_DB_GetNumStdsTotalWhoAreInAttEvent (Events->Event.AttCod); + + /***** Show attendance event inside a box *****/ Box_BoxTableBegin (NULL,Txt_Event, Att_PutIconsOneAtt,Events, Hlp_USERS_Attendance,Box_NOT_CLOSABLE,2); - - /***** Show attendance event *****/ - Event.AttCod = Events->AttCod; - Att_ShowOneAttEvent (Events,&Event,true); - - /***** End table and box *****/ + Att_ShowOneAttEventRow (Events, + true); // Show only this event Box_BoxTableEnd (); switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: - Att_ListAttOnlyMeAsStudent (&Event); + Att_ListAttOnlyMeAsStudent (&Events->Event); break; case Rol_NET: case Rol_TCH: case Rol_SYS_ADM: /***** Show list of students *****/ - Att_ListAttStudents (Events,&Event); + Att_ListAttStudents (Events); break; default: break; @@ -1518,10 +1527,16 @@ static void Att_ShowEvent (struct Att_Events *Events) static void Att_PutIconsOneAtt (void *Events) { - /***** Put icon to get resource link *****/ - if (PrgRsc_CheckIfICanGetLink ()) - Ico_PutContextualIconToGetLink (ActReqLnkAtt,NULL, - Att_PutParams,Events); + char *Anchor = NULL; + + /***** Set anchor string *****/ + Frm_SetAnchorStr (((struct Att_Events *) Events)->Event.AttCod,&Anchor); + + /***** Put icons to edit resource link *****/ + Att_PutFormsToRemEditOneAttEvent ((struct Att_Events *) Events,Anchor); + + /***** Free anchor string *****/ + Frm_FreeAnchorStr (Anchor); } /*****************************************************************************/ @@ -1592,8 +1607,7 @@ static void Att_ListAttOnlyMeAsStudent (struct Att_Event *Event) /*****************************************************************************/ // Event must be filled before calling this function -static void Att_ListAttStudents (struct Att_Events *Events, - struct Att_Event *Event) +static void Att_ListAttStudents (struct Att_Events *Events) { extern const char *Hlp_USERS_Attendance; extern const char *Txt_Attendance; @@ -1632,7 +1646,7 @@ static void Att_ListAttStudents (struct Att_Events *Events, /* Begin form */ Frm_BeginForm (ActRecAttStd); - Att_PutParamAttCod (Event->AttCod); + Att_PutParamAttCod (Events->Event.AttCod); Grp_PutParamsCodGrps (); /* Begin table */ @@ -1661,7 +1675,7 @@ static void Att_ListAttStudents (struct Att_Events *Events, /* Get list of user's IDs */ ID_GetListIDsFromUsrCod (&UsrDat); - Att_WriteRowUsrToCallTheRoll (NumUsr + 1,&UsrDat,Event); + Att_WriteRowUsrToCallTheRoll (NumUsr + 1,&UsrDat,&Events->Event); } /* End table */ @@ -1945,7 +1959,6 @@ void Att_RegisterMeAsStdInAttEvent (void) { extern const char *Txt_Your_comment_has_been_updated; struct Att_Events Events; - struct Att_Event Event; bool Present; char *ParamName; char CommentStd[Cns_MAX_BYTES_TEXT + 1]; @@ -1955,14 +1968,14 @@ void Att_RegisterMeAsStdInAttEvent (void) Att_ResetEvents (&Events); /***** Get attendance event code *****/ - if ((Event.AttCod = Att_GetParamAttCod ()) < 0) + if ((Events.Event.AttCod = Att_GetParamAttCod ()) < 0) Err_WrongEventExit (); - Att_GetDataOfAttEventByCodAndCheckCrs (&Event); // This checks that event belong to current course + Att_GetDataOfAttEventByCodAndCheckCrs (&Events.Event); // This checks that event belong to current course - if (Event.Open) + if (Events.Event.Open) { /***** Get comments for this student *****/ - Present = Att_CheckIfUsrIsPresentInAttEventAndGetComments (Event.AttCod,Gbl.Usrs.Me.UsrDat.UsrCod, + Present = Att_CheckIfUsrIsPresentInAttEventAndGetComments (Events.Event.AttCod,Gbl.Usrs.Me.UsrDat.UsrCod, CommentStd,CommentTch); if (asprintf (&ParamName,"CommentStd%s",Gbl.Usrs.Me.UsrDat.EnUsrCod) < 0) Err_NotEnoughMemoryExit (); @@ -1973,18 +1986,17 @@ void Att_RegisterMeAsStdInAttEvent (void) CommentStd[0] || CommentTch[0]) /***** Register student *****/ - Att_DB_RegUsrInAttEventChangingComments (Event.AttCod,Gbl.Usrs.Me.UsrDat.UsrCod, + Att_DB_RegUsrInAttEventChangingComments (Events.Event.AttCod,Gbl.Usrs.Me.UsrDat.UsrCod, Present,CommentStd,CommentTch); else /***** Remove student *****/ - Att_DB_RemoveUsrFromAttEvent (Event.AttCod,Gbl.Usrs.Me.UsrDat.UsrCod); + Att_DB_RemoveUsrFromAttEvent (Events.Event.AttCod,Gbl.Usrs.Me.UsrDat.UsrCod); /***** Write final message *****/ Ale_ShowAlert (Ale_SUCCESS,Txt_Your_comment_has_been_updated); } /***** Show the attendance event again *****/ - Events.AttCod = Event.AttCod; Att_ShowEvent (&Events); } @@ -2006,7 +2018,6 @@ void Att_RegisterStudentsInAttEvent (void) extern const char *Txt_Presents; extern const char *Txt_Absents; struct Att_Events Events; - struct Att_Event Event; unsigned NumUsr; const char *Ptr; bool Present; @@ -2021,9 +2032,9 @@ void Att_RegisterStudentsInAttEvent (void) Att_ResetEvents (&Events); /***** Get attendance event code *****/ - if ((Event.AttCod = Att_GetParamAttCod ()) < 0) + if ((Events.Event.AttCod = Att_GetParamAttCod ()) < 0) Err_WrongEventExit (); - Att_GetDataOfAttEventByCodAndCheckCrs (&Event); // This checks that event belong to current course + Att_GetDataOfAttEventByCodAndCheckCrs (&Events.Event); // This checks that event belong to current course /***** Get groups selected *****/ Grp_GetParCodsSeveralGrpsToShowUsrs (); @@ -2081,7 +2092,7 @@ void Att_RegisterStudentsInAttEvent (void) NumUsr++) { /***** Get comments for this student *****/ - Att_CheckIfUsrIsPresentInAttEventAndGetComments (Event.AttCod, + Att_CheckIfUsrIsPresentInAttEventAndGetComments (Events.Event.AttCod, Gbl.Usrs.LstUsrs[Rol_STD].Lst[NumUsr].UsrCod, CommentStd, CommentTch); @@ -2097,11 +2108,11 @@ void Att_RegisterStudentsInAttEvent (void) CommentStd[0] || CommentTch[0]) /***** Register student *****/ - Att_DB_RegUsrInAttEventChangingComments (Event.AttCod,Gbl.Usrs.LstUsrs[Rol_STD].Lst[NumUsr].UsrCod, + Att_DB_RegUsrInAttEventChangingComments (Events.Event.AttCod,Gbl.Usrs.LstUsrs[Rol_STD].Lst[NumUsr].UsrCod, Present,CommentStd,CommentTch); else /***** Remove student *****/ - Att_DB_RemoveUsrFromAttEvent (Event.AttCod,Gbl.Usrs.LstUsrs[Rol_STD].Lst[NumUsr].UsrCod); + Att_DB_RemoveUsrFromAttEvent (Events.Event.AttCod,Gbl.Usrs.LstUsrs[Rol_STD].Lst[NumUsr].UsrCod); if (Present) NumStdsPresent++; @@ -2123,7 +2134,6 @@ void Att_RegisterStudentsInAttEvent (void) Usr_ShowWarningNoUsersFound (Rol_STD); /***** Show the attendance event again *****/ - Events.AttCod = Event.AttCod; Att_ShowEvent (&Events); /***** Free memory for list of groups selected *****/ @@ -2671,7 +2681,7 @@ static void Att_PutButtonToShowDetails (const struct Att_Events *Events) /********** Write list of those attendance events that have students *********/ /*****************************************************************************/ -static void Att_ListEventsToSelect (const struct Att_Events *Events, +static void Att_ListEventsToSelect (struct Att_Events *Events, Att_TypeOfView_t TypeOfView) { extern const char *Txt_Events; @@ -2729,8 +2739,9 @@ static void Att_ListEventsToSelect (const struct Att_Events *Events, NumAttEvent++, UniqueId++, The_ChangeRowColor ()) { /* Get data of the attendance event from database */ - Att_GetDataOfAttEventByCodAndCheckCrs (&Events->Lst[NumAttEvent]); - Events->Lst[NumAttEvent].NumStdsTotal = Att_DB_GetNumStdsTotalWhoAreInAttEvent (Events->Lst[NumAttEvent].AttCod); + Events->Event.AttCod = Events->Lst[NumAttEvent].AttCod; + Att_GetDataOfAttEventByCodAndCheckCrs (&Events->Event); + Events->Event.NumStdsTotal = Att_DB_GetNumStdsTotalWhoAreInAttEvent (Events->Event.AttCod); /* Write a row for this event */ HTM_TR_Begin (NULL); @@ -2740,7 +2751,7 @@ static void Att_ListEventsToSelect (const struct Att_Events *Events, The_GetColorRows ()); HTM_INPUT_CHECKBOX ("AttCods",HTM_DONT_SUBMIT_ON_CHANGE, "id=\"Event%u\" value=\"%ld\"%s", - NumAttEvent,Events->Lst[NumAttEvent].AttCod, + NumAttEvent,Events->Event.AttCod, Events->Lst[NumAttEvent].Selected ? " checked=\"checked\"" : ""); HTM_TD_End (); @@ -2762,7 +2773,7 @@ static void Att_ListEventsToSelect (const struct Att_Events *Events, HTM_SPAN_Begin ("id=\"%s\"",Id); HTM_SPAN_End (); HTM_LABEL_End (); - Dat_WriteLocalDateHMSFromUTC (Id,Events->Lst[NumAttEvent].TimeUTC[Dat_STR_TIME], + Dat_WriteLocalDateHMSFromUTC (Id,Events->Event.TimeUTC[Dat_STR_TIME], Gbl.Prefs.DateFormat,Dat_SEPARATOR_COMMA, true,true,true,0x7); free (Id); @@ -2771,13 +2782,13 @@ static void Att_ListEventsToSelect (const struct Att_Events *Events, HTM_TD_Begin ("class=\"LT DAT_%s %s\"", The_GetSuffix (), The_GetColorRows ()); - HTM_Txt (Events->Lst[NumAttEvent].Title); + HTM_Txt (Events->Event.Title); HTM_TD_End (); HTM_TD_Begin ("class=\"RT DAT_%s %s\"", The_GetSuffix (), The_GetColorRows ()); - HTM_Unsigned (Events->Lst[NumAttEvent].NumStdsTotal); + HTM_Unsigned (Events->Event.NumStdsTotal); HTM_TD_End (); HTM_TR_End (); @@ -2830,7 +2841,7 @@ static void Att_PutIconToEditAttEvents (__attribute__((unused)) void *Args) /************ Show table with attendances for every user in list *************/ /*****************************************************************************/ -static void Att_ListUsrsAttendanceTable (const struct Att_Events *Events, +static void Att_ListUsrsAttendanceTable (struct Att_Events *Events, Att_TypeOfView_t TypeOfView, unsigned NumUsrsInList, long *LstSelectedUsrCods) @@ -2923,7 +2934,7 @@ static void Att_ListUsrsAttendanceTable (const struct Att_Events *Events, /* Write table heading for listing of students in several attendance events **/ /*****************************************************************************/ -static void Att_WriteTableHeadSeveralAttEvents (const struct Att_Events *Events) +static void Att_WriteTableHeadSeveralAttEvents (struct Att_Events *Events) { extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; extern const char *Txt_Attendance; @@ -2942,13 +2953,14 @@ static void Att_WriteTableHeadSeveralAttEvents (const struct Att_Events *Events) if (Events->Lst[NumAttEvent].Selected) { /***** Get data of this attendance event *****/ - Att_GetDataOfAttEventByCodAndCheckCrs (&Events->Lst[NumAttEvent]); + Events->Event.AttCod = Events->Lst[NumAttEvent].AttCod; + Att_GetDataOfAttEventByCodAndCheckCrs (&Events->Event); /***** Put link to this attendance event *****/ HTM_TH_Begin (HTM_HEAD_CENTER); snprintf (StrNumAttEvent,sizeof (StrNumAttEvent),"%u",NumAttEvent + 1); - Att_PutLinkAttEvent (&Events->Lst[NumAttEvent], - Events->Lst[NumAttEvent].Title, + Att_PutLinkAttEvent (&Events->Event, + Events->Event.Title, StrNumAttEvent); HTM_TH_End (); } @@ -3078,7 +3090,7 @@ static void Att_PutCheckOrCross (bool Present) /**************** List the students with details and comments ****************/ /*****************************************************************************/ -static void Att_ListStdsWithAttEventsDetails (const struct Att_Events *Events, +static void Att_ListStdsWithAttEventsDetails (struct Att_Events *Events, unsigned NumUsrsInList, long *LstSelectedUsrCods) { @@ -3127,7 +3139,7 @@ static void Att_ListStdsWithAttEventsDetails (const struct Att_Events *Events, /*************** Write list of attendance events for a student ***************/ /*****************************************************************************/ -static void Att_ListAttEventsForAStd (const struct Att_Events *Events, +static void Att_ListAttEventsForAStd (struct Att_Events *Events, unsigned NumUsr,struct Usr_Data *UsrDat) { extern const char *Txt_Student_comment; @@ -3206,15 +3218,16 @@ static void Att_ListAttEventsForAStd (const struct Att_Events *Events, if (Events->Lst[NumAttEvent].Selected) { /***** Get data of the attendance event from database *****/ - Att_GetDataOfAttEventByCodAndCheckCrs (&Events->Lst[NumAttEvent]); - Events->Lst[NumAttEvent].NumStdsTotal = Att_DB_GetNumStdsTotalWhoAreInAttEvent (Events->Lst[NumAttEvent].AttCod); + Events->Event.AttCod = Events->Lst[NumAttEvent].AttCod; + Att_GetDataOfAttEventByCodAndCheckCrs (&Events->Event); + Events->Event.NumStdsTotal = Att_DB_GetNumStdsTotalWhoAreInAttEvent (Events->Event.AttCod); /***** Get comments for this student *****/ - Present = Att_CheckIfUsrIsPresentInAttEventAndGetComments (Events->Lst[NumAttEvent].AttCod,UsrDat->UsrCod,CommentStd,CommentTch); + Present = Att_CheckIfUsrIsPresentInAttEventAndGetComments (Events->Event.AttCod,UsrDat->UsrCod,CommentStd,CommentTch); ShowCommentStd = CommentStd[0]; ShowCommentTch = CommentTch[0] && (Gbl.Usrs.Me.Role.Logged == Rol_TCH || - Events->Lst[NumAttEvent].CommentTchVisible); + Events->Event.CommentTchVisible); /***** Write a row for this event *****/ HTM_TR_Begin (NULL); @@ -3241,8 +3254,8 @@ static void Att_ListAttEventsForAStd (const struct Att_Events *Events, HTM_SPAN_Begin ("id=\"%s\"",Id); HTM_SPAN_End (); HTM_BR (); - HTM_Txt (Events->Lst[NumAttEvent].Title); - Dat_WriteLocalDateHMSFromUTC (Id,Events->Lst[NumAttEvent].TimeUTC[Dat_STR_TIME], + HTM_Txt (Events->Event.Title); + Dat_WriteLocalDateHMSFromUTC (Id,Events->Event.TimeUTC[Dat_STR_TIME], Gbl.Prefs.DateFormat,Dat_SEPARATOR_COMMA, true,true,true,0x7); free (Id); diff --git a/swad_attendance.h b/swad_attendance.h index e227e71e..350cab08 100644 --- a/swad_attendance.h +++ b/swad_attendance.h @@ -58,19 +58,22 @@ struct Att_Event char Title[Att_MAX_BYTES_ATTENDANCE_EVENT_TITLE + 1]; bool CommentTchVisible; - /* Fields computed, not associated to the event in database */ + /* Field computed, not associated to the event in database */ unsigned NumStdsTotal; // Number total of students who have assisted to the event - unsigned NumStdsFromList; // Number of students (taken from a list) who has assisted to the event - bool Selected; // I have selected this attendance event }; struct Att_Events { - bool LstIsRead; // Is the list already read from database, or it needs to be read? - unsigned Num; // Number of attendance events - struct Att_Event *Lst; // List of attendance events + bool LstIsRead; // Is the list already read from database, or it needs to be read? + unsigned Num; // Number of attendance events + struct + { + long AttCod; // Attendance event code + unsigned NumStdsFromList; // Number of students (taken from a list) who has assisted to the event + bool Selected; // I have selected this attendance event + } *Lst; // List of attendance events Dat_StartEndTime_t SelectedOrder; - long AttCod; + struct Att_Event Event; // Selected/current event bool ShowDetails; char *StrAttCodsSelected; unsigned CurrentPage; @@ -81,6 +84,9 @@ struct Att_Events /*****************************************************************************/ void Att_SeeAttEvents (void); + +bool Att_CheckIfICanEditAttEvents (void); + void Att_RequestCreatOrEditAttEvent (void); bool Att_GetDataOfAttEventByCod (struct Att_Event *Event); diff --git a/swad_call_for_exam.c b/swad_call_for_exam.c index d9d98b6b..86fff3e0 100644 --- a/swad_call_for_exam.c +++ b/swad_call_for_exam.c @@ -79,6 +79,7 @@ static void Cfe_ShowCallForExam (struct Cfe_CallsForExams *CallsForExams, Cfe_TypeViewCallForExam_t TypeViewCallForExam, bool HighLight); static void Cfe_PutIconsCallForExam (void *CallsForExams); + static void Cfe_PutParamExaCodToEdit (void *ExaCod); static void Cfe_GetNotifContentCallForExam (const struct Cfe_CallsForExams *CallsForExams, @@ -618,65 +619,58 @@ static void Cfe_ListCallsForExams (struct Cfe_CallsForExams *CallsForExams, unsigned NumExaAnn; long ExaCod; bool HighLight; - bool ICanEdit = (Gbl.Usrs.Me.Role.Logged == Rol_TCH || - Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM); /***** Get calls for exams (the most recent first) in current course from database *****/ - NumExaAnns = Cfe_DB_GetCallsForExamsInCurrentCrs (&mysql_res,ICanEdit); + NumExaAnns = Cfe_DB_GetCallsForExamsInCurrentCrs (&mysql_res); /***** Begin box *****/ - if (ICanEdit) - Box_BoxBegin (NULL,Txt_Calls_for_exams, - Cfe_PutIconsCallsForExams,NULL, - Hlp_ASSESSMENT_Calls_for_exams,Box_NOT_CLOSABLE); - else - Box_BoxBegin (NULL,Txt_Calls_for_exams, - NULL,NULL, - Hlp_ASSESSMENT_Calls_for_exams,Box_NOT_CLOSABLE); + Box_BoxBegin (NULL,Txt_Calls_for_exams, + Cfe_PutIconsCallsForExams,NULL, + Hlp_ASSESSMENT_Calls_for_exams,Box_NOT_CLOSABLE); - if (NumExaAnns) /***** List the existing calls for exams *****/ - for (NumExaAnn = 0; - NumExaAnn < NumExaAnns; - NumExaAnn++) - { - /***** Get the code of the call for exam (row[0]) *****/ - if ((ExaCod = DB_GetNextCode (mysql_res)) <= 0) - Err_WrongCallForExamExit (); - - /***** Allocate memory for the call for exam *****/ - Cfe_AllocMemCallForExam (CallsForExams); - - /***** Read the data of the call for exam *****/ - Cfe_GetDataCallForExamFromDB (CallsForExams,ExaCod); - - /***** Show call for exam *****/ - HighLight = false; - if (ExaCod == CallsForExams->HighlightExaCod) - HighLight = true; - else if (CallsForExams->HighlightDate[0]) + if (NumExaAnns) + for (NumExaAnn = 0; + NumExaAnn < NumExaAnns; + NumExaAnn++) { - if (!strcmp (CallsForExams->CallForExam.ExamDate.YYYYMMDD, - CallsForExams->HighlightDate)) + /***** Get the code of the call for exam (row[0]) *****/ + if ((ExaCod = DB_GetNextCode (mysql_res)) <= 0) + Err_WrongCallForExamExit (); + + /***** Allocate memory for the call for exam *****/ + Cfe_AllocMemCallForExam (CallsForExams); + + /***** Read the data of the call for exam *****/ + Cfe_GetDataCallForExamFromDB (CallsForExams,ExaCod); + + /***** Show call for exam *****/ + HighLight = false; + if (ExaCod == CallsForExams->HighlightExaCod) HighLight = true; + else if (CallsForExams->HighlightDate[0]) + { + if (!strcmp (CallsForExams->CallForExam.ExamDate.YYYYMMDD, + CallsForExams->HighlightDate)) + HighLight = true; + } + Cfe_ShowCallForExam (CallsForExams,ExaCod,TypeViewCallForExam, + HighLight); + + /***** Free memory of the call for exam *****/ + Cfe_FreeMemCallForExam (CallsForExams); } - Cfe_ShowCallForExam (CallsForExams,ExaCod,TypeViewCallForExam, - HighLight); + else + Ale_ShowAlert (Ale_INFO,Txt_No_calls_for_exams_of_X, + Gbl.Hierarchy.Crs.FullName); - /***** Free memory of the call for exam *****/ - Cfe_FreeMemCallForExam (CallsForExams); - } - else - Ale_ShowAlert (Ale_INFO,Txt_No_calls_for_exams_of_X, - Gbl.Hierarchy.Crs.FullName); + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - - /***** Button to create a new call for exam *****/ - if (ICanEdit) - Cfe_PutButtonToCreateNewCallForExam (); + /***** Button to create a new call for exam *****/ + if (Cfe_CheckIfICanEditCallsForExams ()) + Cfe_PutButtonToCreateNewCallForExam (); /***** End box *****/ Box_BoxEnd (); @@ -688,10 +682,11 @@ static void Cfe_ListCallsForExams (struct Cfe_CallsForExams *CallsForExams, static void Cfe_PutIconsCallsForExams (__attribute__((unused)) void *Args) { - /***** Put icon to create a new call for exam *****/ - Ico_PutContextualIconToAdd (ActEdiCfe,NULL,NULL,NULL); + /***** Icon to create a new call for exam *****/ + if (Cfe_CheckIfICanEditCallsForExams ()) + Ico_PutContextualIconToAdd (ActEdiCfe,NULL,NULL,NULL); - /***** Link to get resource link *****/ + /***** Icon to get resource link *****/ if (PrgRsc_CheckIfICanGetLink ()) Ico_PutContextualIconToGetLink (ActReqLnkCfe,NULL, NULL,NULL); @@ -1493,8 +1488,7 @@ static void Cfe_PutIconsCallForExam (void *CallsForExams) if (CallsForExams) { - if (Gbl.Usrs.Me.Role.Logged == Rol_TCH || - Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM) + if (Cfe_CheckIfICanEditCallsForExams ()) { /***** Icon to remove call for exam *****/ Ico_PutContextualIconToRemove (ActReqRemCfe,NULL, @@ -1534,6 +1528,21 @@ static void Cfe_PutIconsCallForExam (void *CallsForExams) } } +/*****************************************************************************/ +/******************* Check if I can edit calls for exams *********************/ +/*****************************************************************************/ + +bool Cfe_CheckIfICanEditCallsForExams (void) + { + static const bool ICanEditCallsForExams[Rol_NUM_ROLES] = + { + [Rol_TCH ] = true, + [Rol_SYS_ADM] = true, + }; + + return ICanEditCallsForExams[Gbl.Usrs.Me.Role.Logged]; + } + /*****************************************************************************/ /***************** Param with the code of a call for exam ********************/ /*****************************************************************************/ diff --git a/swad_call_for_exam.h b/swad_call_for_exam.h index 376e0e48..368afe30 100644 --- a/swad_call_for_exam.h +++ b/swad_call_for_exam.h @@ -128,6 +128,9 @@ void Cfe_ListCallsForExamsCod (void); void Cfe_ListCallsForExamsDay (void); void Cfe_CreateListCallsForExams (struct Cfe_CallsForExams *CallsForExams); + +bool Cfe_CheckIfICanEditCallsForExams (void); + void Cfe_PutHiddenParamExaCod (long ExaCod); long Cfe_GetParamExaCod (void); diff --git a/swad_call_for_exam_database.c b/swad_call_for_exam_database.c index c0318007..c0c7ef8b 100644 --- a/swad_call_for_exam_database.c +++ b/swad_call_for_exam_database.c @@ -80,12 +80,12 @@ long Cfe_DB_CreateCallForExam (const struct Cfe_CallForExam *CallForExam) /**************** Get all calls for exams in current course ******************/ /*****************************************************************************/ -unsigned Cfe_DB_GetCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res,bool ICanEdit) +unsigned Cfe_DB_GetCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res) { char SubQueryStatus[64]; /***** Build subquery about status depending on my role *****/ - if (ICanEdit) + if (Cfe_CheckIfICanEditCallsForExams ()) sprintf (SubQueryStatus,"Status<>%u", (unsigned) Cfe_DELETED_CALL_FOR_EXAM); else diff --git a/swad_call_for_exam_database.h b/swad_call_for_exam_database.h index 3a3db51d..0ba94588 100644 --- a/swad_call_for_exam_database.h +++ b/swad_call_for_exam_database.h @@ -35,7 +35,7 @@ long Cfe_DB_CreateCallForExam (const struct Cfe_CallForExam *CallForExam); -unsigned Cfe_DB_GetCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res,bool ICanEdit); +unsigned Cfe_DB_GetCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res); unsigned Cfe_DB_GetVisibleCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res); unsigned Cfe_DB_GetFutureCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res); unsigned Cfe_DB_GetDataCallForExam (MYSQL_RES **mysql_res,long ExaCod); diff --git a/swad_changelog.h b/swad_changelog.h index e9b112ce..a1d5c795 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -606,11 +606,13 @@ TODO: Fix bug: error al enviar un mensaje a dos recipientes, error on duplicate TODO: Attach pdf files in multimedia. */ -#define Log_PLATFORM_VERSION "SWAD 22.38 (2022-10-02)" +#define Log_PLATFORM_VERSION "SWAD 22.39 (2022-10-02)" #define CSS_FILE "swad22.35.css" #define JS_FILE "swad21.100.js" /* - Version 22.38.1: Oct 02, 2022 TODO: El botón de "Poner encuesta a cero" debería salir dentro del diálogo, igual que el de borrar encuesta. (? lines) + Version 22.39.2: Oct 02, 2022 TODO: El botón de "Eliminar evento" debería salir dentro del diálogo. (? lines) + Version 22.39.1: Oct 02, 2022 TODO: El botón de "Poner encuesta a cero" debería salir dentro del diálogo, igual que el de borrar encuesta. (? lines) + Version 22.39: Oct 02, 2022 Code refactoring and changes in layout of attendance events. (332537 lines) Version 22.38: Oct 02, 2022 Code refactoring and changes in layout of surveys. (332518 lines) Version 22.37.2: Oct 01, 2022 Fixed minor issues in layout. (332526 lines) Version 22.37.1: Oct 01, 2022 Fixed issues in exams and games. (332525 lines)