From a07888e1e63e768e2ad8de17e9dd66f6e511968f Mon Sep 17 00:00:00 2001 From: acanas Date: Wed, 6 May 2020 01:43:48 +0200 Subject: [PATCH] Version19.213 --- swad_API.c | 2 +- swad_assignment.c | 33 +--------- swad_assignment.h | 1 - swad_attendance.c | 32 +--------- swad_attendance.h | 2 - swad_changelog.h | 4 +- swad_exam.h | 1 - swad_exam_event.c | 158 ++++++++++++++++++++++++++++++++-------------- swad_game.h | 1 - swad_group.c | 79 ++++++++++++++++------- swad_group.h | 9 ++- swad_match.c | 15 +---- swad_survey.c | 35 ++-------- swad_survey.h | 1 - 14 files changed, 190 insertions(+), 183 deletions(-) diff --git a/swad_API.c b/swad_API.c index 9fa3e040..1bcbfd5f 100644 --- a/swad_API.c +++ b/swad_API.c @@ -2944,7 +2944,7 @@ int swad__getAttendanceUsers (struct soap *soap, "Requester must be a teacher"); /***** Query list of attendance users *****/ - if (Att_CheckIfAttEventIsAssociatedToGrps (Event.AttCod)) + if (Grp_CheckIfAssociatedToGrps ("att_grp","AttCod",Event.AttCod)) // Event for one or more groups // Subquery: list of users in groups of this attendance event... // ...who have no entry in attendance list of users diff --git a/swad_assignment.c b/swad_assignment.c index b0286a57..5c0d92f5 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -97,7 +97,6 @@ static void Asg_ShowLstGrpsToEditAssignment (long AsgCod); static void Asg_UpdateNumUsrsNotifiedByEMailAboutAssignment (long AsgCod,unsigned NumUsrsToBeNotifiedByEMail); static void Asg_CreateAssignment (struct Asg_Assignment *Asg,const char *Txt); static void Asg_UpdateAssignment (struct Asg_Assignment *Asg,const char *Txt); -static bool Asg_CheckIfAsgIsAssociatedToGrps (long AsgCod); static void Asg_RemoveAllTheGrpsAssociatedToAnAssignment (long AsgCod); static void Asg_CreateGrps (long AsgCod); static void Asg_GetAndWriteNamesOfGrpsAssociatedToAsg (struct Asg_Assignment *Asg); @@ -1352,7 +1351,8 @@ static void Asg_ShowLstGrpsToEditAssignment (long AsgCod) HTM_INPUT_CHECKBOX ("WholeCrs",HTM_DONT_SUBMIT_ON_CHANGE, "id=\"WholeCrs\" value=\"Y\"%s" " onclick=\"uncheckChildren(this,'GrpCods')\"", - Asg_CheckIfAsgIsAssociatedToGrps (AsgCod) ? "" : " checked=\"checked\""); + Grp_CheckIfAssociatedToGrps ("asg_grp","AsgCod",AsgCod) ? "" : + " checked=\"checked\""); HTM_TxtF ("%s %s",Txt_The_whole_course,Gbl.Hierarchy.Crs.ShrtName); HTM_LABEL_End (); HTM_TD_End (); @@ -1364,7 +1364,7 @@ static void Asg_ShowLstGrpsToEditAssignment (long AsgCod) NumGrpTyp < Gbl.Crs.Grps.GrpTypes.Num; NumGrpTyp++) if (Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps) - Grp_ListGrpsToEditAsgAttSvyMch (&Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp], + Grp_ListGrpsToEditAsgAttSvyEvtMch (&Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp], AsgCod,Grp_ASSIGNMENT); /***** End table and box *****/ @@ -1602,33 +1602,6 @@ static void Asg_UpdateAssignment (struct Asg_Assignment *Asg,const char *Txt) Asg_CreateGrps (Asg->AsgCod); } -/*****************************************************************************/ -/*********** Check if an assignment is associated to any group ***************/ -/*****************************************************************************/ - -static bool Asg_CheckIfAsgIsAssociatedToGrps (long AsgCod) - { - /***** Get if an assignment is associated to a group from database *****/ - return (DB_QueryCOUNT ("can not check if an assignment" - " is associated to groups", - "SELECT COUNT(*) FROM asg_grp WHERE AsgCod=%ld", - AsgCod) != 0); - } - -/*****************************************************************************/ -/************ Check if an assignment is associated to a group ****************/ -/*****************************************************************************/ - -bool Asg_CheckIfAsgIsAssociatedToGrp (long AsgCod,long GrpCod) - { - /***** Get if an assignment is associated to a group from database *****/ - return (DB_QueryCOUNT ("can not check if an assignment" - " is associated to a group", - "SELECT COUNT(*) FROM asg_grp" - " WHERE AsgCod=%ld AND GrpCod=%ld", - AsgCod,GrpCod) != 0); - } - /*****************************************************************************/ /********************* Remove groups of an assignment ************************/ /*****************************************************************************/ diff --git a/swad_assignment.h b/swad_assignment.h index 101287c8..514518fc 100644 --- a/swad_assignment.h +++ b/swad_assignment.h @@ -96,7 +96,6 @@ void Asg_RemoveAssignment (void); void Asg_HideAssignment (void); void Asg_ShowAssignment (void); void Asg_ReceiveFormAssignment (void); -bool Asg_CheckIfAsgIsAssociatedToGrp (long AsgCod,long GrpCod); void Asg_RemoveGroup (long GrpCod); void Asg_RemoveGroupsOfType (long GrpTypCod); void Asg_RemoveCrsAssignments (long CrsCod); diff --git a/swad_attendance.c b/swad_attendance.c index e4ba3f23..2310c01a 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -1266,7 +1266,8 @@ static void Att_ShowLstGrpsToEditAttEvent (long AttCod) HTM_INPUT_CHECKBOX ("WholeCrs",HTM_DONT_SUBMIT_ON_CHANGE, "id=\"WholeCrs\" value=\"Y\"%s" " onclick=\"uncheckChildren(this,'GrpCods')\"", - Att_CheckIfAttEventIsAssociatedToGrps (AttCod) ? "" : " checked=\"checked\""); + Grp_CheckIfAssociatedToGrps ("att_grp","AttCod",AttCod) ? "" : + " checked=\"checked\""); HTM_TxtF ("%s %s",Txt_The_whole_course,Gbl.Hierarchy.Crs.ShrtName); HTM_LABEL_End (); HTM_TD_End (); @@ -1278,7 +1279,7 @@ static void Att_ShowLstGrpsToEditAttEvent (long AttCod) NumGrpTyp < Gbl.Crs.Grps.GrpTypes.Num; NumGrpTyp++) if (Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps) - Grp_ListGrpsToEditAsgAttSvyMch (&Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp], + Grp_ListGrpsToEditAsgAttSvyEvtMch (&Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp], AttCod,Grp_ATT_EVENT); /***** End table and box *****/ @@ -1452,33 +1453,6 @@ void Att_UpdateAttEvent (struct Att_Event *Event,const char *Description) Att_CreateGrps (Event->AttCod); } -/*****************************************************************************/ -/******** Check if an attendance event is associated to any group ************/ -/*****************************************************************************/ - -bool Att_CheckIfAttEventIsAssociatedToGrps (long AttCod) - { - /***** Get if an attendance event is associated to a group from database *****/ - return (DB_QueryCOUNT ("can not check if an attendance event" - " is associated to groups", - "SELECT COUNT(*) FROM att_grp WHERE AttCod=%ld", - AttCod) != 0); - } - -/*****************************************************************************/ -/********* Check if an attendance event is associated to a group *************/ -/*****************************************************************************/ - -bool Att_CheckIfAttEventIsAssociatedToGrp (long AttCod,long GrpCod) - { - /***** Get if an attendance event is associated to a group from database *****/ - return (DB_QueryCOUNT ("can not check if an attendance event" - " is associated to a group", - "SELECT COUNT(*) FROM att_grp" - " WHERE AttCod=%ld AND GrpCod=%ld", - AttCod,GrpCod) != 0); - } - /*****************************************************************************/ /****************** Remove groups of an attendance event *********************/ /*****************************************************************************/ diff --git a/swad_attendance.h b/swad_attendance.h index fe08b524..ae26d558 100644 --- a/swad_attendance.h +++ b/swad_attendance.h @@ -100,8 +100,6 @@ void Att_ShowAttEvent (void); void Att_ReceiveFormAttEvent (void); void Att_CreateAttEvent (struct Att_Event *Event,const char *Description); void Att_UpdateAttEvent (struct Att_Event *Event,const char *Description); -bool Att_CheckIfAttEventIsAssociatedToGrps (long AttCod); -bool Att_CheckIfAttEventIsAssociatedToGrp (long AsgCod,long GrpCod); void Att_RemoveGroupsOfType (long GrpTypCod); void Att_RemoveGroup (long GrpCod); diff --git a/swad_changelog.h b/swad_changelog.h index 071c70da..3a2e8a31 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -544,10 +544,12 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.212 (2020-05-05)" +#define Log_PLATFORM_VERSION "SWAD 19.213 (2020-05-06)" #define CSS_FILE "swad19.193.1.css" #define JS_FILE "swad19.193.1.js" /* + Version 19.213: May 06, 2020 Edition of exam event. + Code refactoring in groups. (301327 lines) Version 19.212: May 05, 2020 Icon to edit exam event. (301319 lines) Version 19.211: May 05, 2020 Exam events can be hidden/unhidden. (301215 lines) 1 change necessary in database: diff --git a/swad_exam.h b/swad_exam.h index 5d0d7915..309da2d9 100644 --- a/swad_exam.h +++ b/swad_exam.h @@ -84,7 +84,6 @@ void ExaSet_ChangeSetTitle (void); void ExaSet_ChangeNumQstsToExam (void); void Exa_ReceiveFormExam (void); -bool Mch_CheckIfMatchIsAssociatedToGrp (long EvtCod,long GrpCod); unsigned ExaSet_GetNumSetsExam (long ExaCod); unsigned ExaSet_GetNumQstsExam (long ExaCod); diff --git a/swad_exam_event.c b/swad_exam_event.c index 35274aba..81311fd2 100644 --- a/swad_exam_event.c +++ b/swad_exam_event.c @@ -145,14 +145,18 @@ static void ExaEvt_RemoveUsrEvtResultsInCrs (long UsrCod,long CrsCod,const char static void ExaEvt_PutParamsPlay (void *EvtCod); static void ExaEvt_PutParamEvtCod (long EvtCod); -static void ExaEvt_PutFormNewEvent (const struct ExaEvt_Event *Event); -static void ExaEvt_ShowLstGrpsToCreateEvent (void); +static void ExaEvt_PutFormEvent (const struct ExaEvt_Event *Event); +static void ExaEvt_ShowLstGrpsToCreateEvent (long EvtCod); static void ExaEvt_CreateEvent (struct ExaEvt_Event *Event); +static void ExaEvt_UpdateEvent (struct ExaEvt_Event *Event); + // static void ExaEvt_CreateIndexes (long ExaCod,long EvtCod); // static void ExaEvt_ReorderAnswer (long EvtCod,unsigned QstInd, // const struct Tst_Question *Question); static void ExaEvt_CreateGrps (long EvtCod); +static void ExaEvt_RemoveGroups (long EvtCod); + static void ExaEvt_UpdateEventStatusInDB (const struct ExaEvt_Event *Event); static void ExaEvt_UpdateElapsedTimeInQuestion (const struct ExaEvt_Event *Event); @@ -387,7 +391,7 @@ void ExaEvt_ListEvents (struct Exa_Exams *Exams, ExaEvt_MAX_BYTES_TITLE); /* Put form to create new event */ - ExaEvt_PutFormNewEvent (Event); // Form to fill in data and start playing a new exam event + ExaEvt_PutFormEvent (Event); // Form to create event } else ExaEvt_PutButtonNewEvent (Exams,Exam->ExaCod); // Button to create a new exam event @@ -552,7 +556,7 @@ static void ExaEvt_ListOneOrMoreEvents (struct Exa_Exams *Exams, { HTM_TR_Begin (NULL); HTM_TD_Begin ("colspan=\"8\" class=\"CT COLOR%u\"",Gbl.RowEvenOdd); - Ale_ShowAlert (Ale_INFO,"Form to edit this event."); // TODO: Replace by form + ExaEvt_PutFormEvent (&Event); // Form to edit existing event HTM_TD_End (); HTM_TR_End (); } @@ -663,7 +667,7 @@ static void ExaEvt_ListOneOrMoreEventsIcons (struct Exa_Exams *Exams, ExaEvt_PutParamsEdit,Exams); /***** Icon to edit the exam event *****/ - Ico_PutContextualIconToEdit (ActEdiOneExaEvt,NULL, + Ico_PutContextualIconToEdit (ActEdiOneExaEvt,Anchor, ExaEvt_PutParamsEdit,Exams); /***** End cell *****/ @@ -813,19 +817,6 @@ static void ExaEvt_GetAndWriteNamesOfGrpsAssociatedToEvent (const struct ExaEvt_ DB_FreeMySQLResult (&mysql_res); } -/*****************************************************************************/ -/********** Check if an exam event is associated to a given group ************/ -/*****************************************************************************/ - -bool ExaEvt_CheckIfMatchIsAssociatedToGrp (long EvtCod,long GrpCod) - { - /***** Get if an exam event is associated to a group from database *****/ - return (DB_QueryCOUNT ("can not check if an exam event is associated to a group", - "SELECT COUNT(*) FROM exa_groups" - " WHERE EvtCod=%ld AND GrpCod=%ld", - EvtCod,GrpCod) != 0); - } - /*****************************************************************************/ /**************** Put a column for number of participants ********************/ /*****************************************************************************/ @@ -1450,7 +1441,7 @@ long ExaEvt_GetParamEvtCod (void) /* Put a big button to play exam event (start a new exam event) as a teacher */ /*****************************************************************************/ -static void ExaEvt_PutFormNewEvent (const struct ExaEvt_Event *Event) +static void ExaEvt_PutFormEvent (const struct ExaEvt_Event *Event) { extern const char *Hlp_ASSESSMENT_Exams_events; extern const char *Txt_New_event; @@ -1462,18 +1453,23 @@ static void ExaEvt_PutFormNewEvent (const struct ExaEvt_Event *Event) [Dat_START_TIME] = Dat_HMS_DO_NOT_SET, [Dat_END_TIME ] = Dat_HMS_DO_NOT_SET }; - bool ItsANewEvent = true; // TODO: To be used also to edit existing events + bool ItsANewEvent = Event->EvtCod <= 0; /***** Start section for a new exam event *****/ HTM_SECTION_Begin (ExaEvt_NEW_EVENT_SECTION_ID); /***** Begin form *****/ - Frm_StartForm (ActNewExaEvt); + Frm_StartForm (ItsANewEvent ? ActNewExaEvt : // New event + ActChgExaEvt); // Existing event Exa_PutParamExamCod (Event->ExaCod); - Exa_PutParamQstInd (0); // Start by first question in exam + if (!ItsANewEvent) // Existing event + ExaEvt_PutParamEvtCod (Event->EvtCod); + + // Exa_PutParamQstInd (0); // Start by first question in exam /***** Begin box and table *****/ - Box_BoxTableBegin (NULL,Txt_New_event, + Box_BoxTableBegin (NULL,ItsANewEvent ? Txt_New_event : + Event->Title, NULL,NULL, Hlp_ASSESSMENT_Exams_events,Box_NOT_CLOSABLE,2); @@ -1498,7 +1494,7 @@ static void ExaEvt_PutFormNewEvent (const struct ExaEvt_Event *Event) SetHMS); /***** Groups *****/ - ExaEvt_ShowLstGrpsToCreateEvent (); + ExaEvt_ShowLstGrpsToCreateEvent (Event->EvtCod); /***** End table, send button and end box *****/ if (ItsANewEvent) @@ -1517,7 +1513,7 @@ static void ExaEvt_PutFormNewEvent (const struct ExaEvt_Event *Event) /************** Show list of groups to create a new exam event ***************/ /*****************************************************************************/ -static void ExaEvt_ShowLstGrpsToCreateEvent (void) +static void ExaEvt_ShowLstGrpsToCreateEvent (long EvtCod) { extern const char *The_ClassFormInBox[The_NUM_THEMES]; extern const char *Txt_Groups; @@ -1547,8 +1543,10 @@ static void ExaEvt_ShowLstGrpsToCreateEvent (void) HTM_TD_Begin ("colspan=\"7\" class=\"DAT LM\""); HTM_LABEL_Begin (NULL); HTM_INPUT_CHECKBOX ("WholeCrs",HTM_DONT_SUBMIT_ON_CHANGE, - "id=\"WholeCrs\" value=\"Y\" checked=\"checked\"" - " onclick=\"uncheckChildren(this,'GrpCods')\""); + "id=\"WholeCrs\" value=\"Y\"%s" + " onclick=\"uncheckChildren(this,'GrpCods')\"", + Grp_CheckIfAssociatedToGrps ("exa_groups","EvtCod",EvtCod) ? "" : + " checked=\"checked\""); HTM_TxtF ("%s %s",Txt_The_whole_course,Gbl.Hierarchy.Crs.ShrtName); HTM_LABEL_End (); HTM_TD_End (); @@ -1560,9 +1558,9 @@ static void ExaEvt_ShowLstGrpsToCreateEvent (void) NumGrpTyp < Gbl.Crs.Grps.GrpTypes.Num; NumGrpTyp++) if (Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps) - Grp_ListGrpsToEditAsgAttSvyMch (&Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp], - -1L, // -1 means "New exam event" - Grp_MATCH); + Grp_ListGrpsToEditAsgAttSvyEvtMch (&Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp], + EvtCod, + Grp_EXA_EVENT); /***** End table and box *****/ Box_BoxTableEnd (); @@ -1645,21 +1643,46 @@ void ExaEvt_RequestCreatOrEditEvent (void) void ExaEvt_ReceiveFormEvent (void) { extern const char *Txt_Created_new_event_X; + extern const char *Txt_The_event_has_been_modified; struct Exa_Exams Exams; struct Exa_Exam Exam; struct ExaEvt_Event Event; + bool ItsANewEvent; /***** Reset exams context *****/ Exa_ResetExams (&Exams); Exa_ResetExam (&Exam); ExaEvt_ResetEvent (&Event); - /***** Get parameters *****/ - /* Get context */ + /***** Get main parameters *****/ Exa_GetParams (&Exams); if (Exams.ExaCod <= 0) Lay_WrongExamExit (); + Exam.ExaCod = Exams.ExaCod; + Grp_GetParamWhichGroups (); + Event.EvtCod = ExaEvt_GetParamEvtCod (); + ItsANewEvent = (Event.EvtCod <= 0); + /***** Get exam data from database *****/ + Exa_GetDataOfExamByCod (&Exam); + if (Exam.CrsCod != Gbl.Hierarchy.Crs.CrsCod) + Lay_WrongExamExit (); + Exams.ExaCod = Exam.ExaCod; + + /***** Get event data from database *****/ + if (ItsANewEvent) + /* Initialize to empty event */ + ExaEvt_ResetEvent (&Event); + else + { + /* Get event data from database */ + ExaEvt_GetDataOfEventByCod (&Event); + if (Exam.ExaCod != Event.ExaCod) + Lay_WrongExamExit (); + Exams.EvtCod = Event.EvtCod; + } + + /***** Get parameters from form *****/ /* Get event title */ Par_GetParToText ("Title",Event.Title,ExaEvt_MAX_BYTES_TITLE); @@ -1670,22 +1693,21 @@ void ExaEvt_ReceiveFormEvent (void) /* Get groups associated to the event */ Grp_GetParCodsSeveralGrps (); - /***** Get exam data from database *****/ - Exam.ExaCod = Exams.ExaCod; - Exa_GetDataOfExamByCod (&Exam); - if (Exam.CrsCod != Gbl.Hierarchy.Crs.CrsCod) - Lay_WrongExamExit (); - Event.ExaCod = Exams.ExaCod = Exam.ExaCod; - - /***** Create a new exam event *****/ - ExaEvt_CreateEvent (&Event); + /***** Create/update event *****/ + if (ItsANewEvent) + ExaEvt_CreateEvent (&Event); + else + ExaEvt_UpdateEvent (&Event); /***** Free memory for list of selected groups *****/ Grp_FreeListCodSelectedGrps (); - /***** Write message *****/ - Ale_ShowAlert (Ale_SUCCESS,Txt_Created_new_event_X, - Event.Title); + /***** Write success message *****/ + if (ItsANewEvent) + Ale_ShowAlert (Ale_SUCCESS,Txt_Created_new_event_X, + Event.Title); + else + Ale_ShowAlert (Ale_SUCCESS,Txt_The_event_has_been_modified); /***** Show current exam *****/ Exa_ShowOnlyOneExam (&Exams,&Exam,&Event, @@ -1726,7 +1748,7 @@ void ExaEvt_ResumeEvent (void) } /*****************************************************************************/ -/******************* Create a new exam event in an exam **********************/ +/**************************** Create a new event *****************************/ /*****************************************************************************/ static void ExaEvt_CreateEvent (struct ExaEvt_Event *Event) @@ -1735,7 +1757,7 @@ static void ExaEvt_CreateEvent (struct ExaEvt_Event *Event) Event->EvtCod = DB_QueryINSERTandReturnCode ("can not create exam event", "INSERT exa_events " - "(ExaCod,UsrCod,StartTime,EndTime,Title," + "(ExaCod,UsrCod,StartTime,EndTime,Title,Hidden," "QstInd,QstCod,Showing,Countdown," "NumCols,ShowQstResults,ShowUsrResults)" " VALUES " @@ -1744,6 +1766,7 @@ static void ExaEvt_CreateEvent (struct ExaEvt_Event *Event) "FROM_UNIXTIME(%ld)," // Start time "FROM_UNIXTIME(%ld)," // End time "'%s'," // Title + "'%c'," "0," // QstInd: Event has not started, so not the first question yet "-1," // QstCod: Non-existent question "'%s', " // Showing: What is being shown @@ -1756,6 +1779,8 @@ static void ExaEvt_CreateEvent (struct ExaEvt_Event *Event) Event->TimeUTC[Dat_START_TIME], // Start time Event->TimeUTC[Dat_END_TIME ], // End time Event->Title, + Event->Hidden ? 'Y' : + 'N', ExaEvt_ShowingStringsDB[ExaEvt_SHOWING_DEFAULT], ExaEvt_NUM_COLS_DEFAULT); @@ -1767,6 +1792,35 @@ static void ExaEvt_CreateEvent (struct ExaEvt_Event *Event) ExaEvt_CreateGrps (Event->EvtCod); } +/*****************************************************************************/ +/************************* Update an existing event **************************/ +/*****************************************************************************/ + +static void ExaEvt_UpdateEvent (struct ExaEvt_Event *Event) + { + /***** Insert this new exam event into database *****/ + DB_QueryUPDATE ("can not update exam event", + "UPDATE exa_events,exa_exams" + " SET exa_events.StartTime=FROM_UNIXTIME(%ld)," + "exa_events.EndTime=FROM_UNIXTIME(%ld)," + "exa_events.Title='%s'," + "exa_events.Hidden='%c'" + " WHERE exa_events.EvtCod=%ld" + " AND exa_events.ExaCod=exa_exams.ExaCod" + " AND exa_exams.CrsCod=%ld", // Extra check + Event->TimeUTC[Dat_START_TIME], // Start time + Event->TimeUTC[Dat_END_TIME ], // End time + Event->Title, + Event->Hidden ? 'Y' : + 'N', + Event->EvtCod,Gbl.Hierarchy.Crs.CrsCod); + + /***** Update groups associated to the exam event *****/ + ExaEvt_RemoveGroups (Event->EvtCod); // Remove all groups associated to this event + if (Gbl.Crs.Grps.LstGrpsSel.NumGrps) + ExaEvt_CreateGrps (Event->EvtCod); // Associate new groups + } + /*****************************************************************************/ /******************** Create indexes for an exam event ***********************/ /*****************************************************************************/ @@ -1960,6 +2014,18 @@ static void ExaEvt_CreateGrps (long EvtCod) EvtCod,Gbl.Crs.Grps.LstGrpsSel.GrpCods[NumGrpSel]); } +/*****************************************************************************/ +/********************* Remove all groups from one event **********************/ +/*****************************************************************************/ + +static void ExaEvt_RemoveGroups (long EvtCod) + { + /***** Remove all groups from one event *****/ + DB_QueryDELETE ("can not remove groups associated to and event", + "DELETE FROM exa_groups WHERE EvtCod=%ld", + EvtCod); + } + /*****************************************************************************/ /********************* Remove one group from all events **********************/ /*****************************************************************************/ diff --git a/swad_game.h b/swad_game.h index 073e8f3f..a46776ea 100644 --- a/swad_game.h +++ b/swad_game.h @@ -134,7 +134,6 @@ void Gam_UnhideGame (void); void Gam_RequestCreatOrEditGame (void); void Gam_ReceiveFormGame (void); -bool Mch_CheckIfMatchIsAssociatedToGrp (long MchCod,long GrpCod); unsigned Gam_GetNumQstsGame (long GamCod); diff --git a/swad_group.c b/swad_group.c index 3fa56f45..6bbe9748 100644 --- a/swad_group.c +++ b/swad_group.c @@ -35,6 +35,7 @@ #include "swad_attendance.h" #include "swad_box.h" #include "swad_database.h" +#include "swad_exam_event.h" #include "swad_form.h" #include "swad_game.h" #include "swad_global.h" @@ -120,6 +121,8 @@ static void Grp_WriteHeadingGroupTypes (void); static void Grp_ListGroupsForEdition (const struct Roo_Rooms *Rooms); static void Grp_WriteHeadingGroups (void); +static bool Grp_CheckIfAssociatedToGrp (const char *Table,const char *Field, + long Cod,long GrpCod); static void Grp_PutIconToEditGroups (__attribute__((unused)) void *Args); static void Grp_ShowWarningToStdsToChangeGrps (void); @@ -1681,18 +1684,30 @@ static void Grp_WriteHeadingGroups (void) } /*****************************************************************************/ -/******** List groups of a type **********/ -/******** to edit assignments, attendance events, surveys or matches *********/ +/****** List groups of a type to edit ******/ +/****** assignments, attendance events, surveys, exam events or matches ******/ /*****************************************************************************/ -void Grp_ListGrpsToEditAsgAttSvyMch (struct GroupType *GrpTyp,long Cod, - Grp_AsgAttSvyGam_t Grp_AsgAttOrSvy) +void Grp_ListGrpsToEditAsgAttSvyEvtMch (struct GroupType *GrpTyp,long Cod, + Grp_WhichIsAssociatedToGrp_t WhichIsAssociatedToGrp) { + static const struct + { + const char *Table; + const char *Field; + } AssociationsToGrps[Grp_NUM_ASSOCIATIONS_TO_GROUPS] = + { + [Grp_ASSIGNMENT] = {"asg_grp" ,"AsgCod"}, + [Grp_ATT_EVENT ] = {"att_grp" ,"AttCod"}, + [Grp_SURVEY ] = {"svy_grp" ,"SvyCod"}, + [Grp_EXA_EVENT ] = {"exa_groups","EvtCod"}, + [Grp_MATCH ] = {"mch_groups","MchCod"}, + }; struct ListCodGrps LstGrpsIBelong; unsigned NumGrpThisType; bool IBelongToThisGroup; struct Group *Grp; - bool AssociatedToGrp = false; + bool AssociatedToGrp; /***** Write heading *****/ Grp_WriteGrpHead (GrpTyp); @@ -1709,23 +1724,12 @@ void Grp_ListGrpsToEditAsgAttSvyMch (struct GroupType *GrpTyp,long Cod, Grp = &(GrpTyp->LstGrps[NumGrpThisType]); IBelongToThisGroup = Grp_CheckIfGrpIsInList (Grp->GrpCod,&LstGrpsIBelong); - AssociatedToGrp = false; - if (Cod > 0) // Cod == -1L means new item, assignment, event, survey or match - switch (Grp_AsgAttOrSvy) - { - case Grp_ASSIGNMENT: - AssociatedToGrp = Asg_CheckIfAsgIsAssociatedToGrp (Cod,Grp->GrpCod); - break; - case Grp_ATT_EVENT: - AssociatedToGrp = Att_CheckIfAttEventIsAssociatedToGrp (Cod,Grp->GrpCod); - break; - case Grp_SURVEY: - AssociatedToGrp = Svy_CheckIfSvyIsAssociatedToGrp (Cod,Grp->GrpCod); - break; - case Grp_MATCH: - AssociatedToGrp = Mch_CheckIfMatchIsAssociatedToGrp (Cod,Grp->GrpCod); - break; - } + if (Cod > 0) // Cod == -1L means new item, assignment, event, survey, exam event or match + AssociatedToGrp = Grp_CheckIfAssociatedToGrp (AssociationsToGrps[WhichIsAssociatedToGrp].Table, + AssociationsToGrps[WhichIsAssociatedToGrp].Field, + Cod,Grp->GrpCod); + else + AssociatedToGrp = false; /* Put checkbox to select the group */ HTM_TR_Begin (NULL); @@ -1752,6 +1756,37 @@ void Grp_ListGrpsToEditAsgAttSvyMch (struct GroupType *GrpTyp,long Cod, Grp_FreeListCodGrp (&LstGrpsIBelong); } + +/*****************************************************************************/ +/************ Check if an assignment is associated to a group ****************/ +/*****************************************************************************/ + +static bool Grp_CheckIfAssociatedToGrp (const char *Table,const char *Field, + long Cod,long GrpCod) + { + /***** Get if an assignment, attendance event, survey, exam event or match + is associated to a given group from database *****/ + return (DB_QueryCOUNT ("can not check if associated to a group", + "SELECT COUNT(*) FROM %s" + " WHERE %s=%ld AND GrpCod=%ld", + Table,Field,Cod,GrpCod) != 0); + } + + +/*****************************************************************************/ +/*************** Check if a survey is associated to any group ****************/ +/*****************************************************************************/ + +bool Grp_CheckIfAssociatedToGrps (const char *Table,const char *Field,long Cod) + { + /***** Get if an assignment, attendance event, survey, exam event or match + is associated to any group from database *****/ + return (DB_QueryCOUNT ("can not check if associated to groups", + "SELECT COUNT(*) FROM %s" + " WHERE %s=%ld", + Table,Field,Cod) != 0); + } + /*****************************************************************************/ /***************** Show list of groups to register/remove me *****************/ /*****************************************************************************/ diff --git a/swad_group.h b/swad_group.h index 92ae2d31..aa70dcfe 100644 --- a/swad_group.h +++ b/swad_group.h @@ -132,13 +132,15 @@ typedef enum } Grp_WhichGroups_t; #define Grp_WHICH_GROUPS_DEFAULT Grp_ALL_GROUPS +#define Grp_NUM_ASSOCIATIONS_TO_GROUPS 5 typedef enum { Grp_ASSIGNMENT, Grp_ATT_EVENT, Grp_SURVEY, + Grp_EXA_EVENT, Grp_MATCH, - } Grp_AsgAttSvyGam_t; + } Grp_WhichIsAssociatedToGrp_t; struct Grp_Groups { @@ -178,9 +180,10 @@ void Grp_RegisterUsrIntoGroups (struct UsrData *UsrDat,struct ListCodGrps *LstGr unsigned Grp_RemoveUsrFromGroups (struct UsrData *UsrDat,struct ListCodGrps *LstGrps); void Grp_RemUsrFromAllGrpsInCrs (long UsrCod,long CrsCod); void Grp_RemUsrFromAllGrps (long UsrCod); -void Grp_ListGrpsToEditAsgAttSvyMch (struct GroupType *GrpTyp,long Cod, - Grp_AsgAttSvyGam_t Grp_AsgOrSvy); +void Grp_ListGrpsToEditAsgAttSvyEvtMch (struct GroupType *GrpTyp,long Cod, + Grp_WhichIsAssociatedToGrp_t WhichIsAssociatedToGrp); +bool Grp_CheckIfAssociatedToGrps (const char *Table,const char *Field,long Cod); void Grp_ReqRegisterInGrps (void); void Grp_ShowLstGrpsToChgMyGrps (void); void Grp_ShowLstGrpsToChgOtherUsrsGrps (long UsrCod); diff --git a/swad_match.c b/swad_match.c index 67c7b418..d2862870 100644 --- a/swad_match.c +++ b/swad_match.c @@ -745,19 +745,6 @@ static void Mch_GetAndWriteNamesOfGrpsAssociatedToMatch (const struct Mch_Match DB_FreeMySQLResult (&mysql_res); } -/*****************************************************************************/ -/************* Check if a match is associated to a given group ***************/ -/*****************************************************************************/ - -bool Mch_CheckIfMatchIsAssociatedToGrp (long MchCod,long GrpCod) - { - /***** Get if a match is associated to a group from database *****/ - return (DB_QueryCOUNT ("can not check if a match is associated to a group", - "SELECT COUNT(*) FROM mch_groups" - " WHERE MchCod=%ld AND GrpCod=%ld", - MchCod,GrpCod) != 0); - } - /*****************************************************************************/ /******************* Put a column for number of players **********************/ /*****************************************************************************/ @@ -1418,7 +1405,7 @@ static void Mch_ShowLstGrpsToCreateMatch (void) NumGrpTyp < Gbl.Crs.Grps.GrpTypes.Num; NumGrpTyp++) if (Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps) - Grp_ListGrpsToEditAsgAttSvyMch (&Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp], + Grp_ListGrpsToEditAsgAttSvyEvtMch (&Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp], -1L, // -1 means "New match" Grp_MATCH); diff --git a/swad_survey.c b/swad_survey.c index 046fe80a..fdccd138 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -133,7 +133,6 @@ static void Svy_UpdateNumUsrsNotifiedByEMailAboutSurvey (long SvyCod, unsigned NumUsrsToBeNotifiedByEMail); static void Svy_CreateSurvey (struct Svy_Survey *Svy,const char *Txt); static void Svy_UpdateSurvey (struct Svy_Survey *Svy,const char *Txt); -static bool Svy_CheckIfSvyIsAssociatedToGrps (long SvyCod); static void Svy_RemoveAllTheGrpsAssociatedToAndSurvey (long SvyCod); static void Svy_CreateGrps (long SvyCod); static void Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (struct Svy_Survey *Svy); @@ -2155,8 +2154,8 @@ static void Svy_ShowLstGrpsToEditSurvey (long SvyCod) HTM_LABEL_Begin (NULL); HTM_INPUT_CHECKBOX ("WholeCrs",HTM_DONT_SUBMIT_ON_CHANGE, "id=\"WholeCrs\" value=\"Y\"%s onclick=\"uncheckChildren(this,'GrpCods')\"", - Svy_CheckIfSvyIsAssociatedToGrps (SvyCod) ? "" : - " checked=\"checked\""); + Grp_CheckIfAssociatedToGrps ("svy_grp","SvyCod",SvyCod) ? "" : + " checked=\"checked\""); HTM_TxtF ("%s %s",Txt_The_whole_course,Gbl.Hierarchy.Crs.ShrtName); HTM_LABEL_End (); HTM_TD_End (); @@ -2168,8 +2167,8 @@ static void Svy_ShowLstGrpsToEditSurvey (long SvyCod) NumGrpTyp < Gbl.Crs.Grps.GrpTypes.Num; NumGrpTyp++) if (Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps) - Grp_ListGrpsToEditAsgAttSvyMch (&Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp], - SvyCod,Grp_SURVEY); + Grp_ListGrpsToEditAsgAttSvyEvtMch (&Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp], + SvyCod,Grp_SURVEY); /***** End table and box *****/ Box_BoxTableEnd (); @@ -2416,32 +2415,6 @@ static void Svy_UpdateSurvey (struct Svy_Survey *Svy,const char *Txt) Ale_ShowAlert (Ale_SUCCESS,Txt_The_survey_has_been_modified); } -/*****************************************************************************/ -/*************** Check if a survey is associated to any group ****************/ -/*****************************************************************************/ - -static bool Svy_CheckIfSvyIsAssociatedToGrps (long SvyCod) - { - /***** Get if a survey is associated to a group from database *****/ - return (DB_QueryCOUNT ("can not check if a survey is associated to groups", - "SELECT COUNT(*) FROM svy_grp" - " WHERE SvyCod=%ld", - SvyCod) != 0); - } - -/*****************************************************************************/ -/**************** Check if a survey is associated to a group *****************/ -/*****************************************************************************/ - -bool Svy_CheckIfSvyIsAssociatedToGrp (long SvyCod,long GrpCod) - { - /***** Get if a survey is associated to a group from database *****/ - return (DB_QueryCOUNT ("can not check if a survey is associated to a group", - "SELECT COUNT(*) FROM svy_grp" - " WHERE SvyCod=%ld AND GrpCod=%ld", - SvyCod,GrpCod) != 0); - } - /*****************************************************************************/ /************************* Remove groups of a survey *************************/ /*****************************************************************************/ diff --git a/swad_survey.h b/swad_survey.h index 2c67db4e..29c70416 100644 --- a/swad_survey.h +++ b/swad_survey.h @@ -108,7 +108,6 @@ void Svy_ResetSurvey (void); void Svy_HideSurvey (void); void Svy_UnhideSurvey (void); void Svy_ReceiveFormSurvey (void); -bool Svy_CheckIfSvyIsAssociatedToGrp (long SvyCod,long GrpCod); void Svy_RemoveGroup (long GrpCod); void Svy_RemoveGroupsOfType (long GrpTypCod); void Svy_RemoveSurveys (Hie_Level_t Scope,long Cod);