diff --git a/swad_API.c b/swad_API.c index 10af55ae..335a8565 100644 --- a/swad_API.c +++ b/swad_API.c @@ -4939,7 +4939,7 @@ int swad__getMatches (struct soap *soap, struct swad__getMatchesOutput *getMatchesOut) // output { int ReturnCode; - struct Game Game; + struct Gam_Game Game; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned long NumRows; @@ -5119,8 +5119,8 @@ int swad__getMatchStatus (struct soap *soap, struct swad__getMatchStatusOutput *getMatchStatusOut) // output { int ReturnCode; - struct Match Match; - struct Game Game; + struct Mch_Match Match; + struct Gam_Game Game; bool ICanPlayThisMatchBasedOnGrps; unsigned NumOptions; struct Mch_UsrAnswer UsrAnswer; diff --git a/swad_action.c b/swad_action.c index dcc894b4..e7069697 100644 --- a/swad_action.c +++ b/swad_action.c @@ -675,13 +675,13 @@ const struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = [ActSeeMyMchResCrs ] = {1796,-1,TabUnk,ActSeeAllGam ,0x208,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,MchRes_ShowMyMchResultsInCrs ,NULL}, [ActSeeMyMchResGam ] = {1810,-1,TabUnk,ActSeeAllGam ,0x208,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,MchRes_ShowMyMchResultsInGam ,NULL}, [ActSeeMyMchResMch ] = {1812,-1,TabUnk,ActSeeAllGam ,0x208,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,MchRes_ShowMyMchResultsInMch ,NULL}, - [ActSeeOneMchResMe ] = {1797,-1,TabUnk,ActSeeAllGam ,0x208,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,MchRes_ShowOneMchResult ,NULL}, + [ActSeeOneMchResMe ] = {1797,-1,TabUnk,ActSeeAllGam ,0x208,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,MchRes_ShowOneMchResult ,NULL}, [ActReqSeeAllMchRes ] = {1798,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,MchRes_SelUsrsToViewMchResults ,NULL}, [ActSeeAllMchResCrs ] = {1799,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,MchRes_ShowAllMchResultsInCrs ,NULL}, [ActSeeAllMchResGam ] = {1811,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,MchRes_ShowAllMchResultsInGam ,NULL}, [ActSeeAllMchResMch ] = {1813,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,MchRes_ShowAllMchResultsInMch ,NULL}, - [ActSeeOneMchResOth ] = {1800,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,MchRes_ShowOneMchResult ,NULL}, + [ActSeeOneMchResOth ] = {1800,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,MchRes_ShowOneMchResult ,NULL}, [ActChgVisResMchUsr ] = {1801,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Mch_ToggleVisibilResultsMchUsr ,NULL}, diff --git a/swad_agenda.c b/swad_agenda.c index eab29385..305f93fd 100644 --- a/swad_agenda.c +++ b/swad_agenda.c @@ -108,18 +108,18 @@ static void Agd_PutIconsOtherPublicAgenda (void *EncryptedUsrCod); static void Agd_PutButtonToCreateNewEvent (void); static void Agd_ShowOneEvent (Agd_AgendaType_t AgendaType,long AgdCod); static void Agd_GetParamEventOrder (void); -static void Agd_PutFormsToRemEditOneEvent (struct AgendaEvent *AgdEvent, +static void Agd_PutFormsToRemEditOneEvent (struct Agd_Event *AgdEvent, const char *Anchor); static void Agd_PutCurrentParamsMyAgenda (void *Agenda); static void Agd_GetParams (Agd_AgendaType_t AgendaType); static void Agd_GetListEvents (Agd_AgendaType_t AgendaType); -static void Agd_GetDataOfEventByCod (struct AgendaEvent *AgdEvent); -static void Agd_GetEventTxtFromDB (struct AgendaEvent *AgdEvent, +static void Agd_GetDataOfEventByCod (struct Agd_Event *AgdEvent); +static void Agd_GetEventTxtFromDB (struct Agd_Event *AgdEvent, char Txt[Cns_MAX_BYTES_TEXT + 1]); -static void Agd_CreateEvent (struct AgendaEvent *AgdEvent,const char *Txt); -static void Agd_UpdateEvent (struct AgendaEvent *AgdEvent,const char *Txt); +static void Agd_CreateEvent (struct Agd_Event *AgdEvent,const char *Txt); +static void Agd_UpdateEvent (struct Agd_Event *AgdEvent,const char *Txt); /*****************************************************************************/ /********** Put form to log in and then show another user's agenda ***********/ @@ -739,7 +739,7 @@ static void Agd_ShowOneEvent (Agd_AgendaType_t AgendaType,long AgdCod) char *Anchor = NULL; static unsigned UniqueId = 0; char *Id; - struct AgendaEvent AgdEvent; + struct Agd_Event AgdEvent; Dat_StartEndTime_t StartEndTime; char Txt[Cns_MAX_BYTES_TEXT + 1]; @@ -845,7 +845,7 @@ static void Agd_ShowOneEvent (Agd_AgendaType_t AgendaType,long AgdCod) /******************* Put a link (form) to edit one event *********************/ /*****************************************************************************/ -static void Agd_PutFormsToRemEditOneEvent (struct AgendaEvent *AgdEvent, +static void Agd_PutFormsToRemEditOneEvent (struct Agd_Event *AgdEvent, const char *Anchor) { extern const char *Txt_Event_private_click_to_make_it_visible_to_the_users_of_your_courses; @@ -1145,7 +1145,7 @@ static void Agd_GetListEvents (Agd_AgendaType_t AgendaType) /*********************** Get event data using its code ***********************/ /*****************************************************************************/ -static void Agd_GetDataOfEventByCod (struct AgendaEvent *AgdEvent) +static void Agd_GetDataOfEventByCod (struct Agd_Event *AgdEvent) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -1240,7 +1240,7 @@ void Agd_FreeListEvents (void) /*********************** Get event text from database ************************/ /*****************************************************************************/ -static void Agd_GetEventTxtFromDB (struct AgendaEvent *AgdEvent, +static void Agd_GetEventTxtFromDB (struct Agd_Event *AgdEvent, char Txt[Cns_MAX_BYTES_TEXT + 1]) { MYSQL_RES *mysql_res; @@ -1289,7 +1289,7 @@ void Agd_AskRemEvent (void) { extern const char *Txt_Do_you_really_want_to_remove_the_event_X; extern const char *Txt_Remove_event; - struct AgendaEvent AgdEvent; + struct Agd_Event AgdEvent; /***** Get parameters *****/ Agd_GetParams (Agd_MY_AGENDA); @@ -1321,7 +1321,7 @@ void Agd_AskRemEvent (void) void Agd_RemoveEvent (void) { extern const char *Txt_Event_X_removed; - struct AgendaEvent AgdEvent; + struct Agd_Event AgdEvent; /***** Get event code *****/ if ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L) @@ -1350,7 +1350,7 @@ void Agd_RemoveEvent (void) void Agd_HideEvent (void) { - struct AgendaEvent AgdEvent; + struct Agd_Event AgdEvent; /***** Get event code *****/ if ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L) @@ -1376,7 +1376,7 @@ void Agd_HideEvent (void) void Agd_UnhideEvent (void) { - struct AgendaEvent AgdEvent; + struct Agd_Event AgdEvent; /***** Get event code *****/ if ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L) @@ -1403,7 +1403,7 @@ void Agd_UnhideEvent (void) void Agd_MakeEventPrivate (void) { extern const char *Txt_Event_X_is_now_private; - struct AgendaEvent AgdEvent; + struct Agd_Event AgdEvent; /***** Get event code *****/ if ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L) @@ -1434,7 +1434,7 @@ void Agd_MakeEventPrivate (void) void Agd_MakeEventPublic (void) { extern const char *Txt_Event_X_is_now_visible_to_users_of_your_courses; - struct AgendaEvent AgdEvent; + struct Agd_Event AgdEvent; /***** Get event code *****/ if ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L) @@ -1473,7 +1473,7 @@ void Agd_RequestCreatOrEditEvent (void) extern const char *Txt_Description; extern const char *Txt_Create_event; extern const char *Txt_Save_changes; - struct AgendaEvent AgdEvent; + struct Agd_Event AgdEvent; bool ItsANewEvent; char Txt[Cns_MAX_BYTES_TEXT + 1]; static const Dat_SetHMS SetHMS[Dat_NUM_START_END_TIME] = @@ -1606,7 +1606,7 @@ void Agd_RecFormEvent (void) extern const char *Txt_You_must_specify_the_title_of_the_event; extern const char *Txt_Created_new_event_X; extern const char *Txt_The_event_has_been_modified; - struct AgendaEvent AgdEvent; + struct Agd_Event AgdEvent; bool ItsANewEvent; bool NewEventIsCorrect = true; char EventTxt[Cns_MAX_BYTES_TEXT + 1]; @@ -1684,7 +1684,7 @@ void Agd_RecFormEvent (void) /************************** Create a new event *******************************/ /*****************************************************************************/ -static void Agd_CreateEvent (struct AgendaEvent *AgdEvent,const char *Txt) +static void Agd_CreateEvent (struct Agd_Event *AgdEvent,const char *Txt) { /***** Create a new event *****/ AgdEvent->AgdCod = @@ -1706,7 +1706,7 @@ static void Agd_CreateEvent (struct AgendaEvent *AgdEvent,const char *Txt) /************************ Update an existing event ***************************/ /*****************************************************************************/ -static void Agd_UpdateEvent (struct AgendaEvent *AgdEvent,const char *Txt) +static void Agd_UpdateEvent (struct Agd_Event *AgdEvent,const char *Txt) { /***** Update the data of the event *****/ DB_QueryUPDATE ("can not update event", diff --git a/swad_agenda.h b/swad_agenda.h index 8488e4a0..96fbfbfe 100644 --- a/swad_agenda.h +++ b/swad_agenda.h @@ -47,7 +47,7 @@ typedef enum Agd_END_TIME = 1, } Agd_StartOrEndTime_t; -struct AgendaEvent +struct Agd_Event { long AgdCod; long UsrCod; diff --git a/swad_assignment.c b/swad_assignment.c index 17c758a6..b9ee1fee 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -83,35 +83,35 @@ static void Asg_ShowAllAssignments (struct Asg_Assignments *Assignments); static void Asg_PutHeadForSeeing (struct Asg_Assignments *Assignments, bool PrintView); static bool Asg_CheckIfICanCreateAssignments (void); -static void Asg_PutIconsListAssignments (void *Args); +static void Asg_PutIconsListAssignments (void *Assignments); static void Asg_PutIconToCreateNewAsg (void *Assignments); static void Asg_PutButtonToCreateNewAsg (void *Assignments); -static void Asg_ParamsWhichGroupsToShow (void *Args); +static void Asg_ParamsWhichGroupsToShow (void *Assignments); static void Asg_ShowOneAssignment (long AsgCod,bool PrintView); -static void Asg_WriteAsgAuthor (struct Assignment *Asg); -static void Asg_WriteAssignmentFolder (struct Assignment *Asg,bool PrintView); +static void Asg_WriteAsgAuthor (struct Asg_Assignment *Asg); +static void Asg_WriteAssignmentFolder (struct Asg_Assignment *Asg,bool PrintView); static Dat_StartEndTime_t Asg_GetParamAsgOrder (void); -static void Asg_PutFormsToRemEditOneAsg (const struct Assignment *Asg, +static void Asg_PutFormsToRemEditOneAsg (const struct Asg_Assignment *Asg, const char *Anchor); static void Asg_PutParams (void *Assignments); static void Asg_GetListAssignments (struct Asg_Assignments *Assignments); -static void Asg_GetDataOfAssignment (struct Assignment *Asg, +static void Asg_GetDataOfAssignment (struct Asg_Assignment *Asg, MYSQL_RES **mysql_res, unsigned long NumRows); -static void Asg_ResetAssignment (struct Assignment *Asg); +static void Asg_ResetAssignment (struct Asg_Assignment *Asg); static void Asg_FreeListAssignments (struct Asg_Assignments *Assignments); static void Asg_GetAssignmentTxtFromDB (long AsgCod,char Txt[Cns_MAX_BYTES_TEXT + 1]); static void Asg_PutParamAsgCod (long AsgCod); static bool Asg_CheckIfSimilarAssignmentExists (const char *Field,const char *Value,long AsgCod); static void Asg_ShowLstGrpsToEditAssignment (long AsgCod); static void Asg_UpdateNumUsrsNotifiedByEMailAboutAssignment (long AsgCod,unsigned NumUsrsToBeNotifiedByEMail); -static void Asg_CreateAssignment (struct Assignment *Asg,const char *Txt); -static void Asg_UpdateAssignment (struct Assignment *Asg,const char *Txt); +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 Assignment *Asg); +static void Asg_GetAndWriteNamesOfGrpsAssociatedToAsg (struct Asg_Assignment *Asg); static bool Asg_CheckIfIBelongToCrsOrGrpsThisAssignment (long AsgCod); /*****************************************************************************/ @@ -395,7 +395,7 @@ static void Asg_ShowOneAssignment (long AsgCod,bool PrintView) char *Anchor = NULL; static unsigned UniqueId = 0; char *Id; - struct Assignment Asg; + struct Asg_Assignment Asg; Dat_StartEndTime_t StartEndTime; char Txt[Cns_MAX_BYTES_TEXT + 1]; @@ -521,7 +521,7 @@ static void Asg_ShowOneAssignment (long AsgCod,bool PrintView) /********************* Write the author of an assignment *********************/ /*****************************************************************************/ -static void Asg_WriteAsgAuthor (struct Assignment *Asg) +static void Asg_WriteAsgAuthor (struct Asg_Assignment *Asg) { Usr_WriteAuthor1Line (Asg->UsrCod,Asg->Hidden); } @@ -530,7 +530,7 @@ static void Asg_WriteAsgAuthor (struct Assignment *Asg) /********************* Write the folder of an assignment *********************/ /*****************************************************************************/ -static void Asg_WriteAssignmentFolder (struct Assignment *Asg,bool PrintView) +static void Asg_WriteAssignmentFolder (struct Asg_Assignment *Asg,bool PrintView) { extern const char *Txt_Upload_file_or_create_folder; extern const char *Txt_Folder; @@ -611,7 +611,7 @@ static Dat_StartEndTime_t Asg_GetParamAsgOrder (void) /***************** Put a link (form) to edit one assignment ******************/ /*****************************************************************************/ -static void Asg_PutFormsToRemEditOneAsg (const struct Assignment *Asg, +static void Asg_PutFormsToRemEditOneAsg (const struct Asg_Assignment *Asg, const char *Anchor) { struct Asg_Assignments Assignments; @@ -760,7 +760,7 @@ static void Asg_GetListAssignments (struct Asg_Assignments *Assignments) /******************* Get assignment data using its code **********************/ /*****************************************************************************/ -void Asg_GetDataOfAssignmentByCod (struct Assignment *Asg) +void Asg_GetDataOfAssignmentByCod (struct Asg_Assignment *Asg) { MYSQL_RES *mysql_res; unsigned long NumRows; @@ -793,7 +793,7 @@ void Asg_GetDataOfAssignmentByCod (struct Assignment *Asg) /*************** Get assignment data using its folder name *******************/ /*****************************************************************************/ -void Asg_GetDataOfAssignmentByFolder (struct Assignment *Asg) +void Asg_GetDataOfAssignmentByFolder (struct Asg_Assignment *Asg) { MYSQL_RES *mysql_res; unsigned long NumRows; @@ -826,7 +826,7 @@ void Asg_GetDataOfAssignmentByFolder (struct Assignment *Asg) /************************* Get assignment data *******************************/ /*****************************************************************************/ -static void Asg_GetDataOfAssignment (struct Assignment *Asg, +static void Asg_GetDataOfAssignment (struct Asg_Assignment *Asg, MYSQL_RES **mysql_res, unsigned long NumRows) { @@ -880,7 +880,7 @@ static void Asg_GetDataOfAssignment (struct Assignment *Asg, /************************* Clear all assignment data **************************/ /*****************************************************************************/ -static void Asg_ResetAssignment (struct Assignment *Asg) +static void Asg_ResetAssignment (struct Asg_Assignment *Asg) { if (Asg->AsgCod <= 0) // If > 0 ==> keep value Asg->AsgCod = -1L; @@ -1022,7 +1022,7 @@ void Asg_ReqRemAssignment (void) extern const char *Txt_Do_you_really_want_to_remove_the_assignment_X; extern const char *Txt_Remove_assignment; struct Asg_Assignments Assignments; - struct Assignment Asg; + struct Asg_Assignment Asg; /***** Reset assignments *****/ Asg_ResetAssignments (&Assignments); @@ -1059,7 +1059,7 @@ void Asg_RemoveAssignment (void) { extern const char *Txt_Assignment_X_removed; struct Asg_Assignments Assignments; - struct Assignment Asg; + struct Asg_Assignment Asg; /***** Reset assignments *****/ Asg_ResetAssignments (&Assignments); @@ -1101,7 +1101,7 @@ void Asg_RemoveAssignment (void) void Asg_HideAssignment (void) { struct Asg_Assignments Assignments; - struct Assignment Asg; + struct Asg_Assignment Asg; /***** Reset assignments *****/ Asg_ResetAssignments (&Assignments); @@ -1130,7 +1130,7 @@ void Asg_HideAssignment (void) void Asg_ShowAssignment (void) { struct Asg_Assignments Assignments; - struct Assignment Asg; + struct Asg_Assignment Asg; /***** Reset assignments *****/ Asg_ResetAssignments (&Assignments); @@ -1184,7 +1184,7 @@ void Asg_RequestCreatOrEditAsg (void) extern const char *Txt_Create_assignment; extern const char *Txt_Save_changes; struct Asg_Assignments Assignments; - struct Assignment Asg; + struct Asg_Assignment Asg; bool ItsANewAssignment; char Txt[Cns_MAX_BYTES_TEXT + 1]; static const Dat_SetHMS SetHMS[Dat_NUM_START_END_TIME] = @@ -1398,8 +1398,8 @@ void Asg_RecFormAssignment (void) extern const char *Txt_The_assignment_has_been_modified; extern const char *Txt_You_can_not_disable_file_uploading_once_folders_have_been_created; struct Asg_Assignments Assignments; - struct Assignment OldAsg; // Current assigment data in database - struct Assignment NewAsg; // Assignment data received from form + struct Asg_Assignment OldAsg; // Current assigment data in database + struct Asg_Assignment NewAsg; // Assignment data received from form bool ItsANewAssignment; bool NewAssignmentIsCorrect = true; unsigned NumUsrsToBeNotifiedByEMail; @@ -1557,7 +1557,7 @@ static void Asg_UpdateNumUsrsNotifiedByEMailAboutAssignment (long AsgCod,unsigne /************************ Create a new assignment ****************************/ /*****************************************************************************/ -static void Asg_CreateAssignment (struct Assignment *Asg,const char *Txt) +static void Asg_CreateAssignment (struct Asg_Assignment *Asg,const char *Txt) { /***** Create a new assignment *****/ Asg->AsgCod = @@ -1584,7 +1584,7 @@ static void Asg_CreateAssignment (struct Assignment *Asg,const char *Txt) /********************* Update an existing assignment *************************/ /*****************************************************************************/ -static void Asg_UpdateAssignment (struct Assignment *Asg,const char *Txt) +static void Asg_UpdateAssignment (struct Asg_Assignment *Asg,const char *Txt) { /***** Update the data of the assignment *****/ DB_QueryUPDATE ("can not update assignment", @@ -1702,7 +1702,7 @@ static void Asg_CreateGrps (long AsgCod) /********* Get and write the names of the groups of an assignment ************/ /*****************************************************************************/ -static void Asg_GetAndWriteNamesOfGrpsAssociatedToAsg (struct Assignment *Asg) +static void Asg_GetAndWriteNamesOfGrpsAssociatedToAsg (struct Asg_Assignment *Asg) { extern const char *Txt_Group; extern const char *Txt_Groups; diff --git a/swad_assignment.h b/swad_assignment.h index c1894622..05028368 100644 --- a/swad_assignment.h +++ b/swad_assignment.h @@ -46,7 +46,7 @@ typedef enum Asg_SEND_WORK = 1, } Asg_SendWork_t; -struct Assignment +struct Asg_Assignment { long AsgCod; bool Hidden; @@ -72,8 +72,8 @@ void Asg_SeeAssignments (void); void Asg_PrintOneAssignment (void); void Asg_RequestCreatOrEditAsg (void); -void Asg_GetDataOfAssignmentByCod (struct Assignment *Asg); -void Asg_GetDataOfAssignmentByFolder (struct Assignment *Asg); +void Asg_GetDataOfAssignmentByCod (struct Asg_Assignment *Asg); +void Asg_GetDataOfAssignmentByFolder (struct Asg_Assignment *Asg); void Asg_GetNotifAssignment (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], char **ContentStr, diff --git a/swad_attendance.c b/swad_attendance.c index ec6aa997..8c68ce8e 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -171,8 +171,8 @@ static void Att_PutParamsToPrintStdsList (void *Events); static void Att_PutButtonToShowDetails (const struct Att_Events *Events); static void Att_ListEventsToSelect (const struct Att_Events *Events, Att_TypeOfView_t TypeOfView); -static void Att_PutIconToViewAttEvents (void *Args); -static void Att_PutIconToEditAttEvents (void *Args); +static void Att_PutIconToViewAttEvents (void *Events); +static void Att_PutIconToEditAttEvents (void *Events); static void Att_ListUsrsAttendanceTable (const struct Att_Events *Events, Att_TypeOfView_t TypeOfView, unsigned NumUsrsInList, @@ -2733,33 +2733,39 @@ void Att_RemoveUsrsAbsentWithoutCommentsFromAttEvent (long AttCod) /********** Request listing attendance of users to several events ************/ /*****************************************************************************/ -void Att_ReqListUsrsAttendanceCrs (void *Args) +void Att_ReqListUsrsAttendanceCrs (void *TypeOfView) { extern const char *Hlp_USERS_Attendance_attendance_list; extern const char *Txt_Attendance_list; extern const char *Txt_View_attendance; struct Att_Events Events; - if (!Args) - return; + switch (*(Att_TypeOfView_t *) TypeOfView) + { + case Att_VIEW_SEL_USR: + case Att_PRNT_SEL_USR: + /***** Reset attendance events *****/ + Att_ResetEvents (&Events); - /***** Reset attendance events *****/ - Att_ResetEvents (&Events); + /***** Get list of attendance events *****/ + Att_GetListAttEvents (&Events,Att_OLDEST_FIRST); - /***** Get list of attendance events *****/ - Att_GetListAttEvents (&Events,Att_OLDEST_FIRST); + /***** List users to select some of them *****/ + Usr_PutFormToSelectUsrsToGoToAct (&Gbl.Usrs.Selected, + ActSeeLstUsrAtt, + NULL,NULL, + Txt_Attendance_list, + Hlp_USERS_Attendance_attendance_list, + Txt_View_attendance, + false); // Do not put form with date range - /***** List users to select some of them *****/ - Usr_PutFormToSelectUsrsToGoToAct (&Gbl.Usrs.Selected, - ActSeeLstUsrAtt, - NULL,NULL, - Txt_Attendance_list, - Hlp_USERS_Attendance_attendance_list, - Txt_View_attendance, - false); // Do not put form with date range - - /***** Free list of attendance events *****/ - Att_FreeListAttEvents (&Events); + /***** Free list of attendance events *****/ + Att_FreeListAttEvents (&Events); + break; + default: + Lay_WrongTypeOfViewExit (); + break; + } } /*****************************************************************************/ @@ -2783,72 +2789,81 @@ static void Att_ListOrPrintMyAttendanceCrs (Att_TypeOfView_t TypeOfView) struct Att_Events Events; unsigned NumAttEvent; - /***** Reset attendance events *****/ - Att_ResetEvents (&Events); - - /***** Get list of attendance events *****/ - Att_GetListAttEvents (&Events,Att_OLDEST_FIRST); - - /***** Get boolean parameter that indicates if details must be shown *****/ - Events.ShowDetails = Par_GetParToBool ("ShowDetails"); - - /***** Get list of groups selected ******/ - Grp_GetParCodsSeveralGrpsToShowUsrs (); - - /***** Get number of students in each event *****/ - for (NumAttEvent = 0; - NumAttEvent < Events.Num; - NumAttEvent++) - /* Get number of students in this event */ - Events.Lst[NumAttEvent].NumStdsFromList = - Att_GetNumUsrsFromAListWhoAreInAttEvent (Events.Lst[NumAttEvent].AttCod, - &Gbl.Usrs.Me.UsrDat.UsrCod,1); - - /***** Get list of attendance events selected *****/ - Att_GetListSelectedAttCods (&Events); - - /***** Begin box *****/ switch (TypeOfView) { case Att_VIEW_ONLY_ME: - Box_BoxBegin (NULL,Txt_Attendance, - Att_PutIconsMyAttList,&Gbl, - Hlp_USERS_Attendance_attendance_list,Box_NOT_CLOSABLE); - break; case Att_PRNT_ONLY_ME: - Box_BoxBegin (NULL,Txt_Attendance, - NULL,NULL, - NULL,Box_NOT_CLOSABLE); + /***** Reset attendance events *****/ + Att_ResetEvents (&Events); + + /***** Get list of attendance events *****/ + Att_GetListAttEvents (&Events,Att_OLDEST_FIRST); + + /***** Get boolean parameter that indicates if details must be shown *****/ + Events.ShowDetails = Par_GetParToBool ("ShowDetails"); + + /***** Get list of groups selected ******/ + Grp_GetParCodsSeveralGrpsToShowUsrs (); + + /***** Get number of students in each event *****/ + for (NumAttEvent = 0; + NumAttEvent < Events.Num; + NumAttEvent++) + /* Get number of students in this event */ + Events.Lst[NumAttEvent].NumStdsFromList = + Att_GetNumUsrsFromAListWhoAreInAttEvent (Events.Lst[NumAttEvent].AttCod, + &Gbl.Usrs.Me.UsrDat.UsrCod,1); + + /***** Get list of attendance events selected *****/ + Att_GetListSelectedAttCods (&Events); + + /***** Begin box *****/ + switch (TypeOfView) + { + case Att_VIEW_ONLY_ME: + Box_BoxBegin (NULL,Txt_Attendance, + Att_PutIconsMyAttList,&Gbl, + Hlp_USERS_Attendance_attendance_list,Box_NOT_CLOSABLE); + break; + case Att_PRNT_ONLY_ME: + Box_BoxBegin (NULL,Txt_Attendance, + NULL,NULL, + NULL,Box_NOT_CLOSABLE); + break; + default: + Lay_WrongTypeOfViewExit (); + break; + } + + /***** List events to select *****/ + Att_ListEventsToSelect (&Events,TypeOfView); + + /***** Get my preference about photos in users' list for current course *****/ + Usr_GetMyPrefAboutListWithPhotosFromDB (); + + /***** Show table with attendances for every student in list *****/ + Att_ListUsrsAttendanceTable (&Events,TypeOfView,1,&Gbl.Usrs.Me.UsrDat.UsrCod); + + /***** Show details or put button to show details *****/ + if (Events.ShowDetails) + Att_ListStdsWithAttEventsDetails (&Events,1,&Gbl.Usrs.Me.UsrDat.UsrCod); + + /***** End box *****/ + Box_BoxEnd (); + + /***** Free memory for list of attendance events selected *****/ + free (Events.StrAttCodsSelected); + + /***** Free list of groups selected *****/ + Grp_FreeListCodSelectedGrps (); + + /***** Free list of attendance events *****/ + Att_FreeListAttEvents (&Events); break; default: - Lay_ShowErrorAndExit ("Wrong type of view."); + Lay_WrongTypeOfViewExit (); break; } - - /***** List events to select *****/ - Att_ListEventsToSelect (&Events,TypeOfView); - - /***** Get my preference about photos in users' list for current course *****/ - Usr_GetMyPrefAboutListWithPhotosFromDB (); - - /***** Show table with attendances for every student in list *****/ - Att_ListUsrsAttendanceTable (&Events,TypeOfView,1,&Gbl.Usrs.Me.UsrDat.UsrCod); - - /***** Show details or put button to show details *****/ - if (Events.ShowDetails) - Att_ListStdsWithAttEventsDetails (&Events,1,&Gbl.Usrs.Me.UsrDat.UsrCod); - - /***** End box *****/ - Box_BoxEnd (); - - /***** Free memory for list of attendance events selected *****/ - free (Events.StrAttCodsSelected); - - /***** Free list of groups selected *****/ - Grp_FreeListCodSelectedGrps (); - - /***** Free list of attendance events *****/ - Att_FreeListAttEvents (&Events); } /*****************************************************************************/ @@ -2869,7 +2884,7 @@ static void Att_GetUsrsAndListOrPrintAttendanceCrs (Att_TypeOfView_t TypeOfView) { Usr_GetSelectedUsrsAndGoToAct (&Gbl.Usrs.Selected, Att_ListOrPrintUsrsAttendanceCrs,&TypeOfView, - Att_ReqListUsrsAttendanceCrs,&Gbl); + Att_ReqListUsrsAttendanceCrs,&TypeOfView); } static void Att_ListOrPrintUsrsAttendanceCrs (void *TypeOfView) @@ -2881,84 +2896,93 @@ static void Att_ListOrPrintUsrsAttendanceCrs (void *TypeOfView) long *LstSelectedUsrCods; unsigned NumAttEvent; - /***** Reset attendance events *****/ - Att_ResetEvents (&Events); - - /***** Get parameters *****/ - /* Get boolean parameter that indicates if details must be shown */ - Events.ShowDetails = Par_GetParToBool ("ShowDetails"); - - /* Get list of groups selected */ - Grp_GetParCodsSeveralGrpsToShowUsrs (); - - /***** Count number of valid users in list of encrypted user codes *****/ - NumUsrsInList = Usr_CountNumUsrsInListOfSelectedEncryptedUsrCods (&Gbl.Usrs.Selected); - - if (NumUsrsInList) + switch (*(Att_TypeOfView_t *) TypeOfView) { - /***** Get list of students selected to show their attendances *****/ - Usr_GetListSelectedUsrCods (&Gbl.Usrs.Selected,NumUsrsInList,&LstSelectedUsrCods); + case Att_VIEW_SEL_USR: + case Att_PRNT_SEL_USR: + /***** Reset attendance events *****/ + Att_ResetEvents (&Events); - /***** Get list of attendance events *****/ - Att_GetListAttEvents (&Events,Att_OLDEST_FIRST); + /***** Get parameters *****/ + /* Get boolean parameter that indicates if details must be shown */ + Events.ShowDetails = Par_GetParToBool ("ShowDetails"); - /***** Get number of students in each event *****/ - for (NumAttEvent = 0; - NumAttEvent < Events.Num; - NumAttEvent++) - /* Get number of students in this event */ - Events.Lst[NumAttEvent].NumStdsFromList = - Att_GetNumUsrsFromAListWhoAreInAttEvent (Events.Lst[NumAttEvent].AttCod, - LstSelectedUsrCods,NumUsrsInList); + /* Get list of groups selected */ + Grp_GetParCodsSeveralGrpsToShowUsrs (); - /***** Get list of attendance events selected *****/ - Att_GetListSelectedAttCods (&Events); + /***** Count number of valid users in list of encrypted user codes *****/ + NumUsrsInList = Usr_CountNumUsrsInListOfSelectedEncryptedUsrCods (&Gbl.Usrs.Selected); - /***** Begin box *****/ - switch (*(Att_TypeOfView_t *) TypeOfView) - { - case Att_VIEW_SEL_USR: - Box_BoxBegin (NULL,Txt_Attendance_list, - Att_PutIconsStdsAttList,&Events, - Hlp_USERS_Attendance_attendance_list,Box_NOT_CLOSABLE); - break; - case Att_PRNT_SEL_USR: - Box_BoxBegin (NULL,Txt_Attendance_list, - NULL,NULL, - NULL,Box_NOT_CLOSABLE); - break; - default: - Lay_ShowErrorAndExit ("Wrong type of view."); - } + if (NumUsrsInList) + { + /***** Get list of students selected to show their attendances *****/ + Usr_GetListSelectedUsrCods (&Gbl.Usrs.Selected,NumUsrsInList,&LstSelectedUsrCods); - /***** List events to select *****/ - Att_ListEventsToSelect (&Events,*(Att_TypeOfView_t *) TypeOfView); + /***** Get list of attendance events *****/ + Att_GetListAttEvents (&Events,Att_OLDEST_FIRST); - /***** Get my preference about photos in users' list for current course *****/ - Usr_GetMyPrefAboutListWithPhotosFromDB (); + /***** Get number of students in each event *****/ + for (NumAttEvent = 0; + NumAttEvent < Events.Num; + NumAttEvent++) + /* Get number of students in this event */ + Events.Lst[NumAttEvent].NumStdsFromList = + Att_GetNumUsrsFromAListWhoAreInAttEvent (Events.Lst[NumAttEvent].AttCod, + LstSelectedUsrCods,NumUsrsInList); - /***** Show table with attendances for every student in list *****/ - Att_ListUsrsAttendanceTable (&Events,*(Att_TypeOfView_t *) TypeOfView,NumUsrsInList,LstSelectedUsrCods); + /***** Get list of attendance events selected *****/ + Att_GetListSelectedAttCods (&Events); - /***** Show details or put button to show details *****/ - if (Events.ShowDetails) - Att_ListStdsWithAttEventsDetails (&Events,NumUsrsInList,LstSelectedUsrCods); + /***** Begin box *****/ + switch (*(Att_TypeOfView_t *) TypeOfView) + { + case Att_VIEW_SEL_USR: + Box_BoxBegin (NULL,Txt_Attendance_list, + Att_PutIconsStdsAttList,&Events, + Hlp_USERS_Attendance_attendance_list,Box_NOT_CLOSABLE); + break; + case Att_PRNT_SEL_USR: + Box_BoxBegin (NULL,Txt_Attendance_list, + NULL,NULL, + NULL,Box_NOT_CLOSABLE); + break; + default: + Lay_WrongTypeOfViewExit (); + } - /***** End box *****/ - Box_BoxEnd (); + /***** List events to select *****/ + Att_ListEventsToSelect (&Events,*(Att_TypeOfView_t *) TypeOfView); - /***** Free memory for list of attendance events selected *****/ - free (Events.StrAttCodsSelected); + /***** Get my preference about photos in users' list for current course *****/ + Usr_GetMyPrefAboutListWithPhotosFromDB (); - /***** Free list of attendance events *****/ - Att_FreeListAttEvents (&Events); + /***** Show table with attendances for every student in list *****/ + Att_ListUsrsAttendanceTable (&Events,*(Att_TypeOfView_t *) TypeOfView,NumUsrsInList,LstSelectedUsrCods); - /***** Free list of user codes *****/ - Usr_FreeListSelectedUsrCods (LstSelectedUsrCods); + /***** Show details or put button to show details *****/ + if (Events.ShowDetails) + Att_ListStdsWithAttEventsDetails (&Events,NumUsrsInList,LstSelectedUsrCods); + + /***** End box *****/ + Box_BoxEnd (); + + /***** Free memory for list of attendance events selected *****/ + free (Events.StrAttCodsSelected); + + /***** Free list of attendance events *****/ + Att_FreeListAttEvents (&Events); + + /***** Free list of user codes *****/ + Usr_FreeListSelectedUsrCods (LstSelectedUsrCods); + } + + /***** Free list of groups selected *****/ + Grp_FreeListCodSelectedGrps (); + break; + default: + Lay_WrongTypeOfViewExit (); + break; } - - /***** Free list of groups selected *****/ - Grp_FreeListCodSelectedGrps (); } /*****************************************************************************/ @@ -3178,12 +3202,12 @@ static void Att_ListEventsToSelect (const struct Att_Events *Events, { case Att_VIEW_ONLY_ME: Box_BoxBegin (NULL,Txt_Events, - Att_PutIconToViewAttEvents,&Gbl, + Att_PutIconToViewAttEvents,&Events, NULL,Box_NOT_CLOSABLE); break; case Att_VIEW_SEL_USR: Box_BoxBegin (NULL,Txt_Events, - Att_PutIconToEditAttEvents,&Gbl, + Att_PutIconToEditAttEvents,&Events, NULL,Box_NOT_CLOSABLE); break; case Att_PRNT_ONLY_ME: @@ -3295,9 +3319,9 @@ static void Att_ListEventsToSelect (const struct Att_Events *Events, /*********** Put icon to list (without edition) attendance events ************/ /*****************************************************************************/ -static void Att_PutIconToViewAttEvents (void *Args) +static void Att_PutIconToViewAttEvents (void *Events) { - if (Args) + if (Events) // Not used Ico_PutContextualIconToView (ActSeeAtt, NULL,NULL); } @@ -3306,9 +3330,9 @@ static void Att_PutIconToViewAttEvents (void *Args) /************ Put icon to list (with edition) attendance events **************/ /*****************************************************************************/ -static void Att_PutIconToEditAttEvents (void *Args) +static void Att_PutIconToEditAttEvents (void *Events) { - if (Args) + if (Events) // Not used Ico_PutContextualIconToEdit (ActSeeAtt,NULL, NULL,NULL); } diff --git a/swad_attendance.h b/swad_attendance.h index 2a1db63a..1e98857f 100644 --- a/swad_attendance.h +++ b/swad_attendance.h @@ -111,7 +111,7 @@ void Att_RegisterStudentsInAttEvent (void); void Att_RegUsrInAttEventNotChangingComments (long AttCod,long UsrCod); void Att_RemoveUsrsAbsentWithoutCommentsFromAttEvent (long AttCod); -void Att_ReqListUsrsAttendanceCrs (void *Args); +void Att_ReqListUsrsAttendanceCrs (void *TypeOfView); void Att_ListMyAttendanceCrs (void); void Att_PrintMyAttendanceCrs (void); void Att_ListUsrsAttendanceCrs (void); diff --git a/swad_banner.c b/swad_banner.c index eb7d716e..796123db 100644 --- a/swad_banner.c +++ b/swad_banner.c @@ -58,7 +58,7 @@ extern struct Globals Gbl; struct Ban_Banners { unsigned Num; // Number of banners - struct Banner *Lst; // List of banners + struct Ban_Banner *Lst; // List of banners long BanCodToEdit; // Used as parameter in contextual links long BanCodClicked; // Banned clicked, used to log it }; @@ -67,57 +67,57 @@ struct Ban_Banners /***************************** Private variables *****************************/ /*****************************************************************************/ -static struct Banner *Ban_EditingBan; +static struct Ban_Banner *Ban_EditingBan; static long Ban_BanCodClicked; /*****************************************************************************/ /***************************** Private prototypes ****************************/ /*****************************************************************************/ -static void Ban_SetEditingBanner (struct Banner *Ban); -static struct Banner *Ban_GetEditingBanner (void); +static void Ban_SetEditingBanner (struct Ban_Banner *Ban); +static struct Ban_Banner *Ban_GetEditingBanner (void); static void Ban_WriteListOfBanners (const struct Ban_Banners *Banners); -static void Ban_PutIconsListingBanners (void *Args); +static void Ban_PutIconsListingBanners (void *Banners); static void Ban_PutIconToEditBanners (void); static void Ban_EditBannersInternal (struct Ban_Banners *Banners, - const struct Banner *Ban); + const struct Ban_Banner *Ban); static void Ban_GetListBanners (struct Ban_Banners *Banners, MYSQL_RES **mysql_res,unsigned long NumRows); static void Ban_FreeListBanners (struct Ban_Banners *Banners); -static void Ban_PutIconsEditingBanners (void *Args); +static void Ban_PutIconsEditingBanners (void *Banners); static void Ban_ListBannersForEdition (struct Ban_Banners *Banners); static void Ban_PutParamBanCodToEdit (void *BanCod); static void Ban_PutParamBanCod (long BanCod); -static void Ban_ShowOrHideBanner (struct Banner *Ban,bool Hide); +static void Ban_ShowOrHideBanner (struct Ban_Banner *Ban,bool Hide); -static void Ban_RenameBanner (struct Banner *Ban, +static void Ban_RenameBanner (struct Ban_Banner *Ban, Cns_ShrtOrFullName_t ShrtOrFullName); static bool Ban_CheckIfBannerNameExists (const char *FieldName,const char *Name,long BanCod); static void Ban_UpdateBanNameDB (long BanCod,const char *FieldName, const char *NewBanName); -static void Ban_PutFormToCreateBanner (const struct Banner *Ban); +static void Ban_PutFormToCreateBanner (const struct Ban_Banner *Ban); static void Ban_PutHeadBanners (void); -static void Ban_CreateBanner (const struct Banner *Ban); +static void Ban_CreateBanner (const struct Ban_Banner *Ban); static void Ban_SetBanCodClicked (long BanCod); static void Ban_ResetBanners (struct Ban_Banners *Banners); -static void Ban_ResetBanner (struct Banner *Ban); +static void Ban_ResetBanner (struct Ban_Banner *Ban); /*****************************************************************************/ /************************** Access to editing banner *************************/ /*****************************************************************************/ -static void Ban_SetEditingBanner (struct Banner *Ban) +static void Ban_SetEditingBanner (struct Ban_Banner *Ban) { Ban_EditingBan = Ban; } -static struct Banner *Ban_GetEditingBanner (void) +static struct Ban_Banner *Ban_GetEditingBanner (void) { return Ban_EditingBan; } @@ -149,7 +149,7 @@ void Ban_SeeBanners (void) /***** Begin box *****/ Box_BoxBegin (NULL,Txt_Banners, - Ban_PutIconsListingBanners,&Gbl, + Ban_PutIconsListingBanners,&Banners, Hlp_SYSTEM_Banners,Box_NOT_CLOSABLE); /***** Write all banners *****/ @@ -208,9 +208,9 @@ static void Ban_WriteListOfBanners (const struct Ban_Banners *Banners) /***************** Put contextual icons in list of banners *******************/ /*****************************************************************************/ -static void Ban_PutIconsListingBanners (void *Args) +static void Ban_PutIconsListingBanners (void *Banners) { - if (Args) + if (Banners) // Not used { /***** Put icon to view banners *****/ if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM) @@ -238,7 +238,7 @@ static void Ban_PutIconToEditBanners (void) void Ban_EditBanners (void) { struct Ban_Banners Banners; - struct Banner Ban; + struct Ban_Banner Ban; /***** Reset banners *****/ Ban_ResetBanners (&Banners); @@ -251,7 +251,7 @@ void Ban_EditBanners (void) } static void Ban_EditBannersInternal (struct Ban_Banners *Banners, - const struct Banner *Ban) + const struct Ban_Banner *Ban) { extern const char *Hlp_SYSTEM_Banners_edit; extern const char *Txt_Banners; @@ -266,7 +266,7 @@ static void Ban_EditBannersInternal (struct Ban_Banners *Banners, /***** Begin box *****/ Box_BoxBegin (NULL,Txt_Banners, - Ban_PutIconsEditingBanners,&Gbl, + Ban_PutIconsEditingBanners,Banners, Hlp_SYSTEM_Banners_edit,Box_NOT_CLOSABLE); /***** Put a form to create a new banner *****/ @@ -292,7 +292,7 @@ static void Ban_GetListBanners (struct Ban_Banners *Banners, { MYSQL_ROW row; unsigned NumBan; - struct Banner *Ban; + struct Ban_Banner *Ban; /***** Get banners from database *****/ if (NumRows) // Banners found... @@ -300,8 +300,8 @@ static void Ban_GetListBanners (struct Ban_Banners *Banners, Banners->Num = (unsigned) NumRows; /***** Create list with banners *****/ - if ((Banners->Lst = (struct Banner *) - calloc (NumRows,sizeof (struct Banner))) == NULL) + if ((Banners->Lst = (struct Ban_Banner *) + calloc (NumRows,sizeof (struct Ban_Banner))) == NULL) Lay_NotEnoughMemoryExit (); /***** Get the banners *****/ @@ -349,7 +349,7 @@ static void Ban_GetListBanners (struct Ban_Banners *Banners, /*************************** Get banner full name ****************************/ /*****************************************************************************/ -void Ban_GetDataOfBannerByCod (struct Banner *Ban) +void Ban_GetDataOfBannerByCod (struct Ban_Banner *Ban) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -416,9 +416,9 @@ static void Ban_FreeListBanners (struct Ban_Banners *Banners) /**************** Put contextual icons in edition of banners *****************/ /*****************************************************************************/ -static void Ban_PutIconsEditingBanners (void *Args) +static void Ban_PutIconsEditingBanners (void *Banners) { - if (Args) + if (Banners) // Not used { /***** Put icon to view banners *****/ Ban_PutIconToViewBanners (); @@ -449,7 +449,7 @@ void Ban_PutIconToViewBanners (void) static void Ban_ListBannersForEdition (struct Ban_Banners *Banners) { unsigned NumBan; - struct Banner *Ban; + struct Ban_Banner *Ban; char *Anchor = NULL; /***** Begin table *****/ @@ -574,7 +574,7 @@ long Ban_GetParamBanCod (void) void Ban_RemoveBanner (void) { extern const char *Txt_Banner_X_removed; - struct Banner Ban; + struct Ban_Banner Ban; /***** Reset banner *****/ Ban_ResetBanner (&Ban); @@ -606,7 +606,7 @@ void Ban_RemoveBanner (void) void Ban_ShowBanner (void) { - struct Banner Ban; + struct Ban_Banner Ban; /***** Reset banner *****/ Ban_ResetBanner (&Ban); @@ -624,7 +624,7 @@ void Ban_ShowBanner (void) void Ban_HideBanner (void) { - struct Banner Ban; + struct Ban_Banner Ban; /***** Reset banner *****/ Ban_ResetBanner (&Ban); @@ -640,7 +640,7 @@ void Ban_HideBanner (void) /*************** Change hiddeness of banner in the database ******************/ /*****************************************************************************/ -static void Ban_ShowOrHideBanner (struct Banner *Ban,bool Hide) +static void Ban_ShowOrHideBanner (struct Ban_Banner *Ban,bool Hide) { /***** Get banner code *****/ if ((Ban->BanCod = Ban_GetParamBanCod ()) == -1L) @@ -665,7 +665,7 @@ static void Ban_ShowOrHideBanner (struct Banner *Ban,bool Hide) void Ban_RenameBannerShort (void) { - struct Banner Ban; + struct Ban_Banner Ban; /***** Reset banner *****/ Ban_ResetBanner (&Ban); @@ -683,7 +683,7 @@ void Ban_RenameBannerShort (void) void Ban_RenameBannerFull (void) { - struct Banner Ban; + struct Ban_Banner Ban; /***** Reset banner *****/ Ban_ResetBanner (&Ban); @@ -699,7 +699,7 @@ void Ban_RenameBannerFull (void) /*********************** Change the name of a banner *************************/ /*****************************************************************************/ -static void Ban_RenameBanner (struct Banner *Ban, +static void Ban_RenameBanner (struct Ban_Banner *Ban, Cns_ShrtOrFullName_t ShrtOrFullName) { extern const char *Txt_The_banner_X_already_exists; @@ -809,7 +809,7 @@ void Ban_ChangeBannerImg (void) { extern const char *Txt_The_new_image_is_X; extern const char *Txt_You_can_not_leave_the_image_empty; - struct Banner Ban; + struct Ban_Banner Ban; char NewImg[Ban_MAX_BYTES_IMAGE + 1]; /***** Reset banner *****/ @@ -858,7 +858,7 @@ void Ban_ChangeBannerImg (void) void Ban_ChangeBannerWWW (void) { extern const char *Txt_The_new_web_address_is_X; - struct Banner Ban; + struct Ban_Banner Ban; char NewWWW[Cns_MAX_BYTES_WWW + 1]; /***** Reset banner *****/ @@ -906,7 +906,7 @@ void Ban_ChangeBannerWWW (void) void Ban_ContEditAfterChgBan (void) { struct Ban_Banners Banners; - struct Banner *Ban = Ban_GetEditingBanner (); + struct Ban_Banner *Ban = Ban_GetEditingBanner (); /***** Reset banners *****/ Ban_ResetBanners (&Banners); @@ -922,7 +922,7 @@ void Ban_ContEditAfterChgBan (void) /********************* Put a form to create a new banner *********************/ /*****************************************************************************/ -static void Ban_PutFormToCreateBanner (const struct Banner *Ban) +static void Ban_PutFormToCreateBanner (const struct Ban_Banner *Ban) { extern const char *Hlp_SYSTEM_Banners_edit; extern const char *Txt_New_banner; @@ -1019,7 +1019,7 @@ void Ban_RecFormNewBanner (void) extern const char *Txt_You_must_specify_the_URL_of_the_new_banner; extern const char *Txt_Created_new_banner_X; extern const char *Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_banner; - struct Banner Ban; + struct Ban_Banner Ban; /***** Reset banner *****/ Ban_ResetBanner (&Ban); @@ -1074,7 +1074,7 @@ void Ban_RecFormNewBanner (void) /**************************** Create a new banner ****************************/ /*****************************************************************************/ -static void Ban_CreateBanner (const struct Banner *Ban) +static void Ban_CreateBanner (const struct Ban_Banner *Ban) { /***** Create a new banner *****/ DB_QueryINSERT ("can not create banner", @@ -1136,7 +1136,7 @@ void Ban_WriteMenuWithBanners (void) void Ban_ClickOnBanner (void) { - struct Banner Ban; + struct Ban_Banner Ban; /***** Get banner code *****/ if ((Ban.BanCod = Ban_GetParamBanCod ()) == -1L) @@ -1184,7 +1184,7 @@ static void Ban_ResetBanners (struct Ban_Banners *Banners) /************************* Reset banner/destructor **********************/ /*****************************************************************************/ -static void Ban_ResetBanner (struct Banner *Ban) +static void Ban_ResetBanner (struct Ban_Banner *Ban) { /***** Reset banner *****/ Ban->BanCod = -1L; diff --git a/swad_banner.h b/swad_banner.h index 34167b4e..8aef618e 100644 --- a/swad_banner.h +++ b/swad_banner.h @@ -42,7 +42,7 @@ #define Ban_MAX_CHARS_IMAGE NAME_MAX // 255 #define Ban_MAX_BYTES_IMAGE Ban_MAX_CHARS_IMAGE // 255 -struct Banner +struct Ban_Banner { long BanCod; bool Hidden; @@ -61,7 +61,7 @@ void Ban_EditBanners (void); void Ban_PutIconToViewBanners (void); -void Ban_GetDataOfBannerByCod (struct Banner *Ban); +void Ban_GetDataOfBannerByCod (struct Ban_Banner *Ban); long Ban_GetParamLnkCod (void); void Ban_RemoveBanner (void); void Ban_ShowBanner (void); diff --git a/swad_changelog.h b/swad_changelog.h index 0c6ac201..9be0ccba 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -497,7 +497,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.168 (2020-04-07)" +#define Log_PLATFORM_VERSION "SWAD 19.169 (2020-04-08)" #define CSS_FILE "swad19.146.css" #define JS_FILE "swad19.153.js" /* @@ -548,8 +548,7 @@ Funci // TODO: Oresti Baños: cambiar ojos por candados en descriptores para prohibir/permitir y dejar los ojos para poder elegir descriptores // TODO: Integrar pull requests con traducciones del alemán del usuario eruedin en GitHub -// TODO: Bug en SWADroid: loginByUserPasswordKey falla cuando se le pasa como parámetro un DNI - + Version 19.169: Apr 08, 2020 Code refactoring in games and matches. (285024 lines) Version 19.168: Apr 07, 2020 Code refactoring in forums. (284866 lines) Version 19.167: Apr 06, 2020 Code refactoring in figures. (284772 lines) Version 19.166.1: Apr 06, 2020 Fixed bug in API function loginByUserPasswordKey, reported by Javier Bueno López. (? lines) diff --git a/swad_game.c b/swad_game.c index 6d4ad1c4..a92a2845 100644 --- a/swad_game.c +++ b/swad_game.c @@ -103,72 +103,92 @@ extern struct Globals Gbl; /***************************** Private variables *****************************/ /*****************************************************************************/ -long Gam_CurrentGamCod = -1L; // Used as parameter in contextual links -unsigned Gam_CurrentQstInd = 0; // Used as parameter in contextual links - /*****************************************************************************/ /***************************** Private prototypes ****************************/ /*****************************************************************************/ -static void Gam_ListAllGames (void); +static void Gam_ListAllGames (struct Gam_Games *Games); static bool Gam_CheckIfICanEditGames (void); -static void Gam_PutIconsListGames (void *Args); -static void Gam_PutIconToCreateNewGame (void); -static void Gam_PutButtonToCreateNewGame (void); -static void Gam_PutParamsToCreateNewGame (void *Args); +static void Gam_PutIconsListGames (void *Games); +static void Gam_PutIconToCreateNewGame (struct Gam_Games *Games); +static void Gam_PutButtonToCreateNewGame (struct Gam_Games *Games); +static void Gam_PutParamsToCreateNewGame (void *Games); -static void Gam_ShowOneGame (struct Game *Game,bool ShowOnlyThisGame); +static void Gam_ShowOneGame (struct Gam_Games *Games, + struct Gam_Game *Game,bool ShowOnlyThisGame); -static void Gam_PutIconToShowResultsOfGame (void *Args); -static void Gam_WriteAuthor (struct Game *Game); +static void Gam_PutIconToShowResultsOfGame (void *Games); +static void Gam_WriteAuthor (struct Gam_Game *Game); -static void Gam_PutFormsToRemEditOneGame (const struct Game *Game, +static void Gam_PutHiddenParamGameOrder (Gam_Order_t SelectedOrder); + +static void Gam_PutFormsToRemEditOneGame (struct Gam_Games *Games, + const struct Gam_Game *Game, const char *Anchor); -static long Gam_GetCurrentGamCod (void); -static void Gam_PutParamsOneQst (void *Args); -static void Gam_PutParamCurrentGamCod (void); -static void Gam_PutHiddenParamOrder (void); -static void Gam_GetParamOrder (void); +static void Gam_PutParamsOneQst (void *Games); +static void Gam_PutHiddenParamOrder (Gam_Order_t SelectedOrder); +static Gam_Order_t Gam_GetParamOrder (void); -static void Gam_ResetGame (struct Game *Game); +static void Gam_ResetGame (struct Gam_Game *Game); static void Gam_GetGameTxtFromDB (long GamCod,char Txt[Cns_MAX_BYTES_TEXT + 1]); static void Gam_RemoveGameFromAllTables (long GamCod); -static bool Gam_CheckIfSimilarGameExists (const struct Game *Game); +static bool Gam_CheckIfSimilarGameExists (const struct Gam_Game *Game); -static void Gam_PutFormsEditionGame (struct Game *Game, +static void Gam_PutFormsEditionGame (struct Gam_Games *Games, + struct Gam_Game *Game, char Txt[Cns_MAX_BYTES_TEXT + 1], bool ItsANewGame); -static void Gam_ReceiveGameFieldsFromForm (struct Game *Game, +static void Gam_ReceiveGameFieldsFromForm (struct Gam_Game *Game, char Txt[Cns_MAX_BYTES_TEXT + 1]); -static bool Gam_CheckGameFieldsReceivedFromForm (const struct Game *Game); +static bool Gam_CheckGameFieldsReceivedFromForm (const struct Gam_Game *Game); -static void Gam_CreateGame (struct Game *Game,const char *Txt); -static void Gam_UpdateGame (struct Game *Game,const char *Txt); +static void Gam_CreateGame (struct Gam_Game *Game,const char *Txt); +static void Gam_UpdateGame (struct Gam_Game *Game,const char *Txt); static void Gam_RemAnswersOfAQuestion (long GamCod,unsigned QstInd); static unsigned Gam_GetMaxQuestionIndexInGame (long GamCod); -static void Gam_ListGameQuestions (struct Game *Game); -static void Gam_ListOneOrMoreQuestionsForEdition (long GamCod,unsigned NumQsts, +static void Gam_ListGameQuestions (struct Gam_Games *Games,struct Gam_Game *Game); +static void Gam_ListOneOrMoreQuestionsForEdition (struct Gam_Games *Games, + long GamCod,unsigned NumQsts, MYSQL_RES *mysql_res, bool ICanEditQuestions); static void Gam_ListQuestionForEdition (const struct Tst_Question *Question, unsigned QstInd,bool QuestionExists); -static void Gam_PutIconToAddNewQuestions (void *Args); -static void Gam_PutButtonToAddNewQuestions (void); +static void Gam_PutIconToAddNewQuestions (void *Games); +static void Gam_PutButtonToAddNewQuestions (struct Gam_Games *Games); -static void Gam_AllocateListSelectedQuestions (void); -static void Gam_FreeListsSelectedQuestions (void); -static unsigned Gam_CountNumQuestionsInList (void); +static void Gam_AllocateListSelectedQuestions (struct Gam_Games *Games); +static void Gam_FreeListsSelectedQuestions (struct Gam_Games *Games); +static unsigned Gam_CountNumQuestionsInList (const struct Gam_Games *Games); static void Gam_ExchangeQuestions (long GamCod, unsigned QstIndTop,unsigned QstIndBottom); -static bool Gam_CheckIfEditable (const struct Game *Game); +static bool Gam_CheckIfEditable (const struct Gam_Game *Game); + +/*****************************************************************************/ +/******************************* Reset games *********************************/ +/*****************************************************************************/ + +void Gam_ResetGames (struct Gam_Games *Games) + { + Games->LstIsRead = false; // List not read from database... + Games->Num = 0; // Total number of games + Games->NumSelected = 0; // Number of games selected + Games->Lst = NULL; // List of games + Games->SelectedOrder = Gam_ORDER_DEFAULT; + Games->CurrentPage = 0; + Games->ListQuestions = NULL; + Games->GamCodsSelected = NULL; // String with selected game codes separated by separator multiple + Games->GamCod = -1L; // Selected/current game code + Games->MchCod = -1L; // Selected/current match code + Games->QstInd = 0; // Current question index + } /*****************************************************************************/ /***************************** List all games ********************************/ @@ -176,18 +196,23 @@ static bool Gam_CheckIfEditable (const struct Game *Game); void Gam_SeeAllGames (void) { + struct Gam_Games Games; + + /***** Reset games *****/ + Gam_ResetGames (&Games); + /***** Get parameters *****/ - Gam_GetParams (); // Return value ignored + Gam_GetParams (&Games); // Return value ignored /***** Show all games *****/ - Gam_ListAllGames (); + Gam_ListAllGames (&Games); } /*****************************************************************************/ /**************************** Show all the games *****************************/ /*****************************************************************************/ -static void Gam_ListAllGames (void) +static void Gam_ListAllGames (struct Gam_Games *Games) { extern const char *Hlp_ASSESSMENT_Games; extern const char *Txt_Games; @@ -198,33 +223,33 @@ static void Gam_ListAllGames (void) Gam_Order_t Order; struct Pagination Pagination; unsigned NumGame; - struct Game Game; + struct Gam_Game Game; /***** Get number of groups in current course *****/ if (!Gbl.Crs.Grps.NumGrps) Gbl.Crs.Grps.WhichGrps = Grp_ALL_GROUPS; /***** Get list of games *****/ - Gam_GetListGames (Gbl.Games.SelectedOrder); + Gam_GetListGames (Games,Games->SelectedOrder); /***** Compute variables related to pagination *****/ - Pagination.NumItems = Gbl.Games.Num; - Pagination.CurrentPage = (int) Gbl.Games.CurrentPage; + Pagination.NumItems = Games->Num; + Pagination.CurrentPage = (int) Games->CurrentPage; Pag_CalculatePagination (&Pagination); - Gbl.Games.CurrentPage = (unsigned) Pagination.CurrentPage; + Games->CurrentPage = (unsigned) Pagination.CurrentPage; /***** Begin box *****/ Box_BoxBegin ("100%",Txt_Games, - Gam_PutIconsListGames,&Gbl, + Gam_PutIconsListGames,Games, Hlp_ASSESSMENT_Games,Box_NOT_CLOSABLE); /***** Write links to pages *****/ Pag_WriteLinksToPagesCentered (Pag_GAMES, &Pagination, - (unsigned) Gbl.Games.SelectedOrder, + (unsigned) Games->SelectedOrder, NULL,0); - if (Gbl.Games.Num) + if (Games->Num) { /***** Table head *****/ HTM_TABLE_BeginWideMarginPadding (2); @@ -240,13 +265,13 @@ static void Gam_ListAllGames (void) /* Form to change order */ Frm_StartForm (ActSeeAllGam); - Pag_PutHiddenParamPagNum (Pag_GAMES,Gbl.Games.CurrentPage); + Pag_PutHiddenParamPagNum (Pag_GAMES,Games->CurrentPage); Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order); HTM_BUTTON_SUBMIT_Begin (Txt_GAMES_ORDER_HELP[Order],"BT_LINK TIT_TBL",NULL); - if (Order == Gbl.Games.SelectedOrder) + if (Order == Games->SelectedOrder) HTM_U_Begin (); HTM_Txt (Txt_GAMES_ORDER[Order]); - if (Order == Gbl.Games.SelectedOrder) + if (Order == Games->SelectedOrder) HTM_U_End (); HTM_BUTTON_End (); Frm_EndForm (); @@ -264,11 +289,12 @@ static void Gam_ListAllGames (void) NumGame++) { /* Get data of this game */ - Game.GamCod = Gbl.Games.Lst[NumGame - 1].GamCod; + Game.GamCod = Games->Lst[NumGame - 1].GamCod; Gam_GetDataOfGameByCod (&Game); /* Show game */ - Gam_ShowOneGame (&Game, + Gam_ShowOneGame (Games, + &Game, false); // Do not show only this game } @@ -281,18 +307,18 @@ static void Gam_ListAllGames (void) /***** Write again links to pages *****/ Pag_WriteLinksToPagesCentered (Pag_GAMES, &Pagination, - (unsigned) Gbl.Games.SelectedOrder, + (unsigned) Games->SelectedOrder, NULL,0); /***** Button to create a new game *****/ if (Gam_CheckIfICanEditGames ()) - Gam_PutButtonToCreateNewGame (); + Gam_PutButtonToCreateNewGame (Games); /***** End box *****/ Box_BoxEnd (); /***** Free list of games *****/ - Gam_FreeListGames (); + Gam_FreeListGames (Games); } /*****************************************************************************/ @@ -316,13 +342,13 @@ static bool Gam_CheckIfICanEditGames (void) /***************** Put contextual icons in list of games *******************/ /*****************************************************************************/ -static void Gam_PutIconsListGames (void *Args) +static void Gam_PutIconsListGames (void *Games) { - if (Args) + if (Games) { /***** Put icon to create a new game *****/ if (Gam_CheckIfICanEditGames ()) - Gam_PutIconToCreateNewGame (); + Gam_PutIconToCreateNewGame ((struct Gam_Games *) Games); /***** Put icon to view matches results *****/ switch (Gbl.Usrs.Me.Role.Logged) @@ -350,12 +376,12 @@ static void Gam_PutIconsListGames (void *Args) /********************** Put icon to create a new game **********************/ /*****************************************************************************/ -static void Gam_PutIconToCreateNewGame (void) +static void Gam_PutIconToCreateNewGame (struct Gam_Games *Games) { extern const char *Txt_New_game; Ico_PutContextualIconToAdd (ActFrmNewGam,NULL, - Gam_PutParamsToCreateNewGame,&Gbl, + Gam_PutParamsToCreateNewGame,Games, Txt_New_game); } @@ -363,12 +389,12 @@ static void Gam_PutIconToCreateNewGame (void) /********************* Put button to create a new game *********************/ /*****************************************************************************/ -static void Gam_PutButtonToCreateNewGame (void) +static void Gam_PutButtonToCreateNewGame (struct Gam_Games *Games) { extern const char *Txt_New_game; Frm_StartForm (ActFrmNewGam); - Gam_PutParamsToCreateNewGame (&Gbl); + Gam_PutParamsToCreateNewGame (Games); Btn_PutConfirmButton (Txt_New_game); Frm_EndForm (); } @@ -377,12 +403,12 @@ static void Gam_PutButtonToCreateNewGame (void) /******************* Put parameters to create a new game *******************/ /*****************************************************************************/ -static void Gam_PutParamsToCreateNewGame (void *Args) +static void Gam_PutParamsToCreateNewGame (void *Games) { - if (Args) + if (Games) { - Gam_PutHiddenParamGameOrder (); - Pag_PutHiddenParamPagNum (Pag_GAMES,Gbl.Games.CurrentPage); + Gam_PutHiddenParamGameOrder (((struct Gam_Games *) Games)->SelectedOrder); + Pag_PutHiddenParamPagNum (Pag_GAMES,((struct Gam_Games *) Games)->CurrentPage); } } @@ -392,15 +418,19 @@ static void Gam_PutParamsToCreateNewGame (void *Args) void Gam_SeeOneGame (void) { - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); Gam_GetDataOfGameByCod (&Game); /***** Show game *****/ - Gam_ShowOnlyOneGame (&Game, + Gam_ShowOnlyOneGame (&Games,&Game, false, // Do not list game questions false); // Do not put form to start new match } @@ -409,15 +439,17 @@ void Gam_SeeOneGame (void) /******************************* Show one game *******************************/ /*****************************************************************************/ -void Gam_ShowOnlyOneGame (struct Game *Game, +void Gam_ShowOnlyOneGame (struct Gam_Games *Games, + struct Gam_Game *Game, bool ListGameQuestions, bool PutFormNewMatch) { - Gam_ShowOnlyOneGameBegin (Game,ListGameQuestions,PutFormNewMatch); + Gam_ShowOnlyOneGameBegin (Games,Game,ListGameQuestions,PutFormNewMatch); Gam_ShowOnlyOneGameEnd (); } -void Gam_ShowOnlyOneGameBegin (struct Game *Game, +void Gam_ShowOnlyOneGameBegin (struct Gam_Games *Games, + struct Gam_Game *Game, bool ListGameQuestions, bool PutFormNewMatch) { @@ -425,21 +457,22 @@ void Gam_ShowOnlyOneGameBegin (struct Game *Game, extern const char *Txt_Game; /***** Begin box *****/ - Gam_SetCurrentGamCod (Game->GamCod); + Games->GamCod = Game->GamCod; Box_BoxBegin (NULL,Txt_Game, - Gam_PutIconToShowResultsOfGame,&Gbl, + Gam_PutIconToShowResultsOfGame,Games, Hlp_ASSESSMENT_Games,Box_NOT_CLOSABLE); /***** Show game *****/ - Gam_ShowOneGame (Game, + Gam_ShowOneGame (Games, + Game, true); // Show only this game if (ListGameQuestions) /***** Write questions of this game *****/ - Gam_ListGameQuestions (Game); + Gam_ListGameQuestions (Games,Game); else /***** List matches *****/ - Mch_ListMatches (Game,PutFormNewMatch); + Mch_ListMatches (Games,Game,PutFormNewMatch); } void Gam_ShowOnlyOneGameEnd (void) @@ -448,7 +481,8 @@ void Gam_ShowOnlyOneGameEnd (void) Box_BoxEnd (); } -static void Gam_ShowOneGame (struct Game *Game,bool ShowOnlyThisGame) +static void Gam_ShowOneGame (struct Gam_Games *Games, + struct Gam_Game *Game,bool ShowOnlyThisGame) { extern const char *Txt_View_game; extern const char *Txt_No_of_questions; @@ -481,7 +515,7 @@ static void Gam_ShowOneGame (struct Game *Game,bool ShowOnlyThisGame) HTM_TD_Begin ("rowspan=\"2\" class=\"CONTEXT_COL COLOR%u\"",Gbl.RowEvenOdd); /* Icons to remove/edit this game */ - Gam_PutFormsToRemEditOneGame (Game,Anchor); + Gam_PutFormsToRemEditOneGame (Games,Game,Anchor); HTM_TD_End (); } @@ -519,10 +553,10 @@ static void Gam_ShowOneGame (struct Game *Game,bool ShowOnlyThisGame) HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd); /* Game title */ - Gam_SetCurrentGamCod (Game->GamCod); // Used to pass parameter + Games->GamCod = Game->GamCod; HTM_ARTICLE_Begin (Anchor); Frm_StartForm (ActSeeGam); - Gam_PutParams (&Gbl); + Gam_PutParams (Games); HTM_BUTTON_SUBMIT_Begin (Txt_View_game, Game->Hidden ? "BT_LINK LT ASG_TITLE_LIGHT": "BT_LINK LT ASG_TITLE", @@ -551,9 +585,9 @@ static void Gam_ShowOneGame (struct Game *Game,bool ShowOnlyThisGame) else HTM_TD_Begin ("class=\"RT COLOR%u\"",Gbl.RowEvenOdd); - Gam_SetCurrentGamCod (Game->GamCod); // Used to pass parameter + Games->GamCod = Game->GamCod; Frm_StartForm (ActSeeGam); - Gam_PutParams (&Gbl); + Gam_PutParams (Games); HTM_BUTTON_SUBMIT_Begin (Txt_Matches, Game->Hidden ? "BT_LINK LT ASG_TITLE_LIGHT" : "BT_LINK LT ASG_TITLE", @@ -612,22 +646,22 @@ static void Gam_ShowOneGame (struct Game *Game,bool ShowOnlyThisGame) /************* Put icon to show results of matches in a game *****************/ /*****************************************************************************/ -static void Gam_PutIconToShowResultsOfGame (void *Args) +static void Gam_PutIconToShowResultsOfGame (void *Games) { - if (Args) + if (Games) { /***** Put icon to view matches results *****/ switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: Ico_PutContextualIconToShowResults (ActSeeMyMchResGam,MchRes_RESULTS_BOX_ID, - Gam_PutParams,&Gbl); + Gam_PutParams,Games); break; case Rol_NET: case Rol_TCH: case Rol_SYS_ADM: Ico_PutContextualIconToShowResults (ActSeeAllMchResGam,MchRes_RESULTS_BOX_ID, - Gam_PutParams,&Gbl); + Gam_PutParams,Games); break; default: break; @@ -639,7 +673,7 @@ static void Gam_PutIconToShowResultsOfGame (void *Args) /*********************** Write the author of a game ************************/ /*****************************************************************************/ -static void Gam_WriteAuthor (struct Game *Game) +static void Gam_WriteAuthor (struct Gam_Game *Game) { Usr_WriteAuthor1Line (Game->UsrCod,Game->Hidden); } @@ -648,61 +682,48 @@ static void Gam_WriteAuthor (struct Game *Game) /****** Put a hidden parameter with the type of order in list of games *******/ /*****************************************************************************/ -void Gam_PutHiddenParamGameOrder (void) +static void Gam_PutHiddenParamGameOrder (Gam_Order_t SelectedOrder) { - Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Gbl.Games.SelectedOrder); + Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) SelectedOrder); } /*****************************************************************************/ /******************** Put a link (form) to edit one game *********************/ /*****************************************************************************/ -static void Gam_PutFormsToRemEditOneGame (const struct Game *Game, +static void Gam_PutFormsToRemEditOneGame (struct Gam_Games *Games, + const struct Gam_Game *Game, const char *Anchor) { - Gam_SetCurrentGamCod (Game->GamCod); // Used to pass parameter + Games->GamCod = Game->GamCod; /***** Put icon to remove game *****/ Ico_PutContextualIconToRemove (ActReqRemGam, - Gam_PutParams,&Gbl); + Gam_PutParams,Games); /***** Put icon to unhide/hide game *****/ if (Game->Hidden) Ico_PutContextualIconToUnhide (ActShoGam,Anchor, - Gam_PutParams,&Gbl); + Gam_PutParams,Games); else Ico_PutContextualIconToHide (ActHidGam,Anchor, - Gam_PutParams,&Gbl); + Gam_PutParams,Games); /***** Put icon to edit game *****/ Ico_PutContextualIconToEdit (ActEdiOneGam,NULL, - Gam_PutParams,&Gbl); - } - -/*****************************************************************************/ -/**************** Access to variable used to pass parameter ******************/ -/*****************************************************************************/ - -void Gam_SetCurrentGamCod (long GamCod) - { - Gam_CurrentGamCod = GamCod; - } - -static long Gam_GetCurrentGamCod (void) - { - return Gam_CurrentGamCod; + Gam_PutParams,Games); } /*****************************************************************************/ /**************** Put parameter to move/remove one question ******************/ /*****************************************************************************/ -static void Gam_PutParamsOneQst (void *Args) +static void Gam_PutParamsOneQst (void *Games) { - if (Args) + if (Games) { - Gam_PutParams (&Gbl); - Gam_PutParamQstInd (Gam_CurrentQstInd); + Gam_PutParams (Games); + Gam_PutParamQstInd (((struct Gam_Games *) Games)->QstInd); } } @@ -710,17 +731,18 @@ static void Gam_PutParamsOneQst (void *Args) /*********************** Params used to edit a game **************************/ /*****************************************************************************/ -void Gam_PutParams (void *Args) +void Gam_PutParams (void *Games) { Grp_WhichGroups_t WhichGroups; - if (Args) + if (Games) { - Gam_PutParamCurrentGamCod (); - Gam_PutHiddenParamOrder (); + if (((struct Gam_Games *) Games)->GamCod > 0) + Gam_PutParamGameCod (((struct Gam_Games *) Games)->GamCod); + Gam_PutHiddenParamOrder (((struct Gam_Games *) Games)->SelectedOrder); WhichGroups = Grp_GetParamWhichGroups (); Grp_PutParamWhichGroups (&WhichGroups); - Pag_PutHiddenParamPagNum (Pag_GAMES,Gbl.Games.CurrentPage); + Pag_PutHiddenParamPagNum (Pag_GAMES,((struct Gam_Games *) Games)->CurrentPage); } } @@ -728,18 +750,6 @@ void Gam_PutParams (void *Args) /******************** Write parameter with code of game **********************/ /*****************************************************************************/ -static void Gam_PutParamCurrentGamCod (void) - { - long CurrentGamCod = Gam_GetCurrentGamCod (); - - if (CurrentGamCod > 0) - Gam_PutParamGameCod (CurrentGamCod); - } - -/*****************************************************************************/ -/******************** Write parameter with code of game **********************/ -/*****************************************************************************/ - void Gam_PutParamGameCod (long GamCod) { Par_PutHiddenParamLong (NULL,"GamCod",GamCod); @@ -759,11 +769,11 @@ long Gam_GetParamGameCod (void) /******************* Get parameters used to edit a game **********************/ /*****************************************************************************/ -long Gam_GetParams (void) +long Gam_GetParams (struct Gam_Games *Games) { /***** Get other parameters *****/ - Gam_GetParamOrder (); - Gbl.Games.CurrentPage = Pag_GetParamPagNum (Pag_GAMES); + Games->SelectedOrder = Gam_GetParamOrder (); + Games->CurrentPage = Pag_GetParamPagNum (Pag_GAMES); /***** Get game code *****/ return Gam_GetParamGameCod (); @@ -773,30 +783,29 @@ long Gam_GetParams (void) /****** Put a hidden parameter with the type of order in list of games *******/ /*****************************************************************************/ -static void Gam_PutHiddenParamOrder (void) +static void Gam_PutHiddenParamOrder (Gam_Order_t SelectedOrder) { - if (Gbl.Games.SelectedOrder != Gam_ORDER_DEFAULT) - Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Gbl.Games.SelectedOrder); + if (SelectedOrder != Gam_ORDER_DEFAULT) + Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) SelectedOrder); } /*****************************************************************************/ /********** Get parameter with the type or order in list of games ************/ /*****************************************************************************/ -static void Gam_GetParamOrder (void) +static Gam_Order_t Gam_GetParamOrder (void) { - Gbl.Games.SelectedOrder = (Gam_Order_t) - Par_GetParToUnsignedLong ("Order", - 0, - Gam_NUM_ORDERS - 1, - (unsigned long) Gam_ORDER_DEFAULT); + return (Gam_Order_t) Par_GetParToUnsignedLong ("Order", + 0, + Gam_NUM_ORDERS - 1, + (unsigned long) Gam_ORDER_DEFAULT); } /*****************************************************************************/ /*********************** Get list of all the games *************************/ /*****************************************************************************/ -void Gam_GetListGames (Gam_Order_t SelectedOrder) +void Gam_GetListGames (struct Gam_Games *Games,Gam_Order_t SelectedOrder) { static const char *OrderBySubQuery[Gam_NUM_ORDERS] = { @@ -811,8 +820,8 @@ void Gam_GetListGames (Gam_Order_t SelectedOrder) unsigned NumGame; /***** Free list of games *****/ - if (Gbl.Games.LstIsRead) - Gam_FreeListGames (); + if (Games->LstIsRead) + Gam_FreeListGames (Games); /***** Subquery: get hidden games depending on user's role *****/ switch (Gbl.Usrs.Me.Role.Logged) @@ -856,37 +865,37 @@ void Gam_GetListGames (Gam_Order_t SelectedOrder) if (NumRows) // Games found... { - Gbl.Games.Num = (unsigned) NumRows; + Games->Num = (unsigned) NumRows; /***** Create list of games *****/ - if ((Gbl.Games.Lst = (struct GameSelected *) malloc (NumRows * sizeof (struct GameSelected))) == NULL) + if ((Games->Lst = (struct Gam_GameSelected *) malloc (NumRows * sizeof (struct Gam_GameSelected))) == NULL) Lay_NotEnoughMemoryExit (); /***** Get the games codes *****/ for (NumGame = 0; - NumGame < Gbl.Games.Num; + NumGame < Games->Num; NumGame++) { /* Get next game code (row[0]) */ row = mysql_fetch_row (mysql_res); - if ((Gbl.Games.Lst[NumGame].GamCod = Str_ConvertStrCodToLongCod (row[0])) <= 0) + if ((Games->Lst[NumGame].GamCod = Str_ConvertStrCodToLongCod (row[0])) <= 0) Lay_ShowErrorAndExit ("Error: wrong game code."); } } else - Gbl.Games.Num = 0; + Games->Num = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); - Gbl.Games.LstIsRead = true; + Games->LstIsRead = true; } /*****************************************************************************/ /********************* Get list of game events selected **********************/ /*****************************************************************************/ -void Gam_GetListSelectedGamCods (void) +void Gam_GetListSelectedGamCods (struct Gam_Games *Games) { unsigned MaxSizeListGamCodsSelected; unsigned NumGame; @@ -895,25 +904,25 @@ void Gam_GetListSelectedGamCods (void) char LongStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1]; /***** Allocate memory for list of games selected *****/ - MaxSizeListGamCodsSelected = Gbl.Games.Num * (Cns_MAX_DECIMAL_DIGITS_LONG + 1); - if ((Gbl.Games.GamCodsSelected = (char *) malloc (MaxSizeListGamCodsSelected + 1)) == NULL) + MaxSizeListGamCodsSelected = Games->Num * (Cns_MAX_DECIMAL_DIGITS_LONG + 1); + if ((Games->GamCodsSelected = (char *) malloc (MaxSizeListGamCodsSelected + 1)) == NULL) Lay_NotEnoughMemoryExit (); /***** Get parameter multiple with list of games selected *****/ - Par_GetParMultiToText ("GamCod",Gbl.Games.GamCodsSelected,MaxSizeListGamCodsSelected); + Par_GetParMultiToText ("GamCod",Games->GamCodsSelected,MaxSizeListGamCodsSelected); /***** Set which games will be shown as selected (checkboxes on) *****/ - if (Gbl.Games.GamCodsSelected[0]) // Some games selected + if (Games->GamCodsSelected[0]) // Some games selected { /* Reset selection */ for (NumGame = 0; - NumGame < Gbl.Games.Num; + NumGame < Games->Num; NumGame++) - Gbl.Games.Lst[NumGame].Selected = false; - Gbl.Games.NumSelected = 0; + Games->Lst[NumGame].Selected = false; + Games->NumSelected = 0; /* Set some games as selected */ - for (Ptr = Gbl.Games.GamCodsSelected; + for (Ptr = Games->GamCodsSelected; *Ptr; ) { @@ -923,12 +932,12 @@ void Gam_GetListSelectedGamCods (void) /* Set each game in *StrGamCodsSelected as selected */ for (NumGame = 0; - NumGame < Gbl.Games.Num; + NumGame < Games->Num; NumGame++) - if (Gbl.Games.Lst[NumGame].GamCod == GamCod) + if (Games->Lst[NumGame].GamCod == GamCod) { - Gbl.Games.Lst[NumGame].Selected = true; - Gbl.Games.NumSelected++; + Games->Lst[NumGame].Selected = true; + Games->NumSelected++; break; } } @@ -937,10 +946,10 @@ void Gam_GetListSelectedGamCods (void) { /***** Set all games as selected *****/ for (NumGame = 0; - NumGame < Gbl.Games.Num; + NumGame < Games->Num; NumGame++) - Gbl.Games.Lst[NumGame].Selected = true; - Gbl.Games.NumSelected = Gbl.Games.Num; + Games->Lst[NumGame].Selected = true; + Games->NumSelected = Games->Num; } } @@ -948,7 +957,7 @@ void Gam_GetListSelectedGamCods (void) /********************** Get game data using its code *************************/ /*****************************************************************************/ -void Gam_GetDataOfGameByCod (struct Game *Game) +void Gam_GetDataOfGameByCod (struct Gam_Game *Game) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -1048,7 +1057,7 @@ void Gam_GetDataOfGameByCod (struct Game *Game) /*************************** Initialize game to empty ************************/ /*****************************************************************************/ -static void Gam_ResetGame (struct Game *Game) +static void Gam_ResetGame (struct Gam_Game *Game) { /***** Initialize to empty game *****/ Game->GamCod = -1L; @@ -1069,15 +1078,15 @@ static void Gam_ResetGame (struct Game *Game) /***************************** Free list of games ****************************/ /*****************************************************************************/ -void Gam_FreeListGames (void) +void Gam_FreeListGames (struct Gam_Games *Games) { - if (Gbl.Games.LstIsRead && Gbl.Games.Lst) + if (Games->LstIsRead && Games->Lst) { /***** Free memory used by the list of games *****/ - free (Gbl.Games.Lst); - Gbl.Games.Lst = NULL; - Gbl.Games.Num = 0; - Gbl.Games.LstIsRead = false; + free (Games->Lst); + Games->Lst = NULL; + Games->Num = 0; + Games->LstIsRead = false; } } @@ -1122,10 +1131,14 @@ void Gam_AskRemGame (void) { extern const char *Txt_Do_you_really_want_to_remove_the_game_X; extern const char *Txt_Remove_game; - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); /***** Get data of the game from database *****/ @@ -1134,15 +1147,15 @@ void Gam_AskRemGame (void) Lay_NoPermissionExit (); /***** Show question and button to remove game *****/ - Gam_SetCurrentGamCod (Game.GamCod); // Used to pass parameter + Games.GamCod = Game.GamCod; Ale_ShowAlertAndButton (ActRemGam,NULL,NULL, - Gam_PutParams,&Gbl, + Gam_PutParams,&Games, Btn_REMOVE_BUTTON,Txt_Remove_game, Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_game_X, Game.Title); /***** Show games again *****/ - Gam_ListAllGames (); + Gam_ListAllGames (&Games); } /*****************************************************************************/ @@ -1152,7 +1165,11 @@ void Gam_AskRemGame (void) void Gam_RemoveGame (void) { extern const char *Txt_Game_X_removed; - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get game code *****/ if ((Game.GamCod = Gam_GetParamGameCod ()) == -1L) @@ -1171,7 +1188,7 @@ void Gam_RemoveGame (void) Game.Title); /***** Show games again *****/ - Gam_ListAllGames (); + Gam_ListAllGames (&Games); } /*****************************************************************************/ @@ -1224,10 +1241,14 @@ void Gam_RemoveGamesCrs (long CrsCod) void Gam_HideGame (void) { - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); /***** Get data of the game from database *****/ @@ -1241,7 +1262,7 @@ void Gam_HideGame (void) Game.GamCod); /***** Show games again *****/ - Gam_ListAllGames (); + Gam_ListAllGames (&Games); } /*****************************************************************************/ @@ -1250,10 +1271,14 @@ void Gam_HideGame (void) void Gam_UnhideGame (void) { - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); /***** Get data of the game from database *****/ @@ -1267,14 +1292,14 @@ void Gam_UnhideGame (void) Game.GamCod); /***** Show games again *****/ - Gam_ListAllGames (); + Gam_ListAllGames (&Games); } /*****************************************************************************/ /******************* Check if the title of a game exists *******************/ /*****************************************************************************/ -static bool Gam_CheckIfSimilarGameExists (const struct Game *Game) +static bool Gam_CheckIfSimilarGameExists (const struct Gam_Game *Game) { /***** Get number of games with a field value from database *****/ return (DB_QueryCOUNT ("can not get similar games", @@ -1291,16 +1316,20 @@ static bool Gam_CheckIfSimilarGameExists (const struct Game *Game) void Gam_RequestCreatOrEditGame (void) { - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; bool ItsANewGame; char Txt[Cns_MAX_BYTES_TEXT + 1]; + /***** Reset games *****/ + Gam_ResetGames (&Games); + /***** Check if I can edit games *****/ if (!Gam_CheckIfICanEditGames ()) Lay_NoPermissionExit (); /***** Get parameters *****/ - ItsANewGame = ((Game.GamCod = Gam_GetParams ()) < 0); + ItsANewGame = ((Game.GamCod = Gam_GetParams (&Games)) <= 0); /***** Get game data *****/ if (ItsANewGame) @@ -1317,15 +1346,15 @@ void Gam_RequestCreatOrEditGame (void) } /***** Put forms to create/edit a game *****/ - Gam_PutFormsEditionGame (&Game,Txt,ItsANewGame); + Gam_PutFormsEditionGame (&Games,&Game,Txt,ItsANewGame); /***** Show games or questions *****/ if (ItsANewGame) /* Show games again */ - Gam_ListAllGames (); + Gam_ListAllGames (&Games); else /* Show questions of the game ready to be edited */ - Gam_ListGameQuestions (&Game); + Gam_ListGameQuestions (&Games,&Game); } @@ -1333,7 +1362,8 @@ void Gam_RequestCreatOrEditGame (void) /********************* Put a form to create/edit a game **********************/ /*****************************************************************************/ -static void Gam_PutFormsEditionGame (struct Game *Game, +static void Gam_PutFormsEditionGame (struct Gam_Games *Games, + struct Gam_Game *Game, char Txt[Cns_MAX_BYTES_TEXT + 1], bool ItsANewGame) { @@ -1350,10 +1380,10 @@ static void Gam_PutFormsEditionGame (struct Game *Game, extern const char *Txt_Save_changes; /***** Begin form *****/ - Gam_SetCurrentGamCod (Game->GamCod); // Used to pass parameter + Games->GamCod = Game->GamCod; Frm_StartForm (ItsANewGame ? ActNewGam : ActChgGam); - Gam_PutParams (&Gbl); + Gam_PutParams (Games); /***** Begin box and table *****/ if (ItsANewGame) @@ -1441,16 +1471,20 @@ static void Gam_PutFormsEditionGame (struct Game *Game, void Gam_RecFormGame (void) { - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; bool ItsANewGame; char Txt[Cns_MAX_BYTES_TEXT + 1]; + /***** Reset games *****/ + Gam_ResetGames (&Games); + /***** Check if I can edit games *****/ if (!Gam_CheckIfICanEditGames ()) Lay_NoPermissionExit (); /***** Get parameters *****/ - ItsANewGame = ((Game.GamCod = Gam_GetParams ()) < 0); + ItsANewGame = ((Game.GamCod = Gam_GetParams (&Games)) <= 0); /***** If I can edit games ==> receive game from form *****/ if (Gam_CheckIfICanEditGames ()) @@ -1465,31 +1499,31 @@ void Gam_RecFormGame (void) Gam_UpdateGame (&Game,Txt); // Update game data in database /***** Put forms to edit the game created or updated *****/ - Gam_PutFormsEditionGame (&Game,Txt, + Gam_PutFormsEditionGame (&Games,&Game,Txt, false); // No new game /***** Show questions of the game ready to be edited ******/ - Gam_ListGameQuestions (&Game); + Gam_ListGameQuestions (&Games,&Game); } else { /***** Put forms to create/edit the game *****/ - Gam_PutFormsEditionGame (&Game,Txt,ItsANewGame); + Gam_PutFormsEditionGame (&Games,&Game,Txt,ItsANewGame); /***** Show games or questions *****/ if (ItsANewGame) /* Show games again */ - Gam_ListAllGames (); + Gam_ListAllGames (&Games); else /* Show questions of the game ready to be edited */ - Gam_ListGameQuestions (&Game); + Gam_ListGameQuestions (&Games,&Game); } } else Lay_NoPermissionExit (); } -static void Gam_ReceiveGameFieldsFromForm (struct Game *Game, +static void Gam_ReceiveGameFieldsFromForm (struct Gam_Game *Game, char Txt[Cns_MAX_BYTES_TEXT + 1]) { char MaxGradeStr[64]; @@ -1510,7 +1544,7 @@ static void Gam_ReceiveGameFieldsFromForm (struct Game *Game, Par_GetParToHTML ("Txt",Txt,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous) } -static bool Gam_CheckGameFieldsReceivedFromForm (const struct Game *Game) +static bool Gam_CheckGameFieldsReceivedFromForm (const struct Gam_Game *Game) { extern const char *Txt_Already_existed_a_game_with_the_title_X; extern const char *Txt_You_must_specify_the_title_of_the_game; @@ -1541,7 +1575,7 @@ static bool Gam_CheckGameFieldsReceivedFromForm (const struct Game *Game) /**************************** Create a new game ******************************/ /*****************************************************************************/ -static void Gam_CreateGame (struct Game *Game,const char *Txt) +static void Gam_CreateGame (struct Gam_Game *Game,const char *Txt) { extern const char *Txt_Created_new_game_X; @@ -1570,7 +1604,7 @@ static void Gam_CreateGame (struct Game *Game,const char *Txt) /************************* Update an existing game *************************/ /*****************************************************************************/ -static void Gam_UpdateGame (struct Game *Game,const char *Txt) +static void Gam_UpdateGame (struct Gam_Game *Game,const char *Txt) { extern const char *Txt_The_game_has_been_modified; @@ -1596,19 +1630,6 @@ static void Gam_UpdateGame (struct Game *Game,const char *Txt) Ale_ShowAlert (Ale_SUCCESS,Txt_The_game_has_been_modified); } -/*****************************************************************************/ -/************* Check if a match is associated to a given group ***************/ -/*****************************************************************************/ - -bool Gam_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); - } - /*****************************************************************************/ /******************* Get number of questions of a game *********************/ /*****************************************************************************/ @@ -1629,10 +1650,14 @@ unsigned Gam_GetNumQstsGame (long GamCod) void Gam_RequestNewQuestion (void) { - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); Gam_GetDataOfGameByCod (&Game); @@ -1640,14 +1665,14 @@ void Gam_RequestNewQuestion (void) if (Gam_CheckIfEditable (&Game)) { /***** Show form to create a new question in this game *****/ - Gam_SetCurrentGamCod (Game.GamCod); // Used to pass parameter - Tst_RequestSelectTestsForGame (); + Games.GamCod = Game.GamCod; + Tst_RequestSelectTestsForGame (&Games); } else Lay_NoPermissionExit (); /***** Show current game *****/ - Gam_ShowOnlyOneGame (&Game, + Gam_ShowOnlyOneGame (&Games,&Game, true, // List game questions false); // Do not put form to start new match } @@ -1658,10 +1683,14 @@ void Gam_RequestNewQuestion (void) void Gam_ListTstQuestionsToSelect (void) { - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); Gam_GetDataOfGameByCod (&Game); @@ -1669,8 +1698,8 @@ void Gam_ListTstQuestionsToSelect (void) if (Gam_CheckIfEditable (&Game)) { /***** List several test questions for selection *****/ - Gam_SetCurrentGamCod (Game.GamCod); // Used to pass parameter - Tst_ListQuestionsToSelect (); + Games.GamCod = Game.GamCod; + Tst_ListQuestionsToSelect (&Games); } else Lay_NoPermissionExit (); @@ -1845,7 +1874,7 @@ unsigned Gam_GetNextQuestionIndexInGame (long GamCod,unsigned QstInd) /************************ List the questions of a game ***********************/ /*****************************************************************************/ -static void Gam_ListGameQuestions (struct Game *Game) +static void Gam_ListGameQuestions (struct Gam_Games *Games,struct Gam_Game *Game) { extern const char *Hlp_ASSESSMENT_Games_questions; extern const char *Txt_Questions; @@ -1865,7 +1894,7 @@ static void Gam_ListGameQuestions (struct Game *Game) Game->GamCod); /***** Begin box *****/ - Gam_SetCurrentGamCod (Game->GamCod); // Used to pass parameter + Games->GamCod = Game->GamCod; if (ICanEditQuestions) Box_BoxBegin (NULL,Txt_Questions, Gam_PutIconToAddNewQuestions,&Gbl, @@ -1877,14 +1906,15 @@ static void Gam_ListGameQuestions (struct Game *Game) /***** Show table with questions *****/ if (NumQsts) - Gam_ListOneOrMoreQuestionsForEdition (Game->GamCod,NumQsts,mysql_res, + Gam_ListOneOrMoreQuestionsForEdition (Games, + Game->GamCod,NumQsts,mysql_res, ICanEditQuestions); else // This game has no questions Ale_ShowAlert (Ale_INFO,Txt_This_game_has_no_questions); /***** Put button to add a new question in this game *****/ if (ICanEditQuestions) // I can edit questions - Gam_PutButtonToAddNewQuestions (); + Gam_PutButtonToAddNewQuestions (Games); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -1897,7 +1927,8 @@ static void Gam_ListGameQuestions (struct Game *Game) /********************* List game questions for edition ***********************/ /*****************************************************************************/ -static void Gam_ListOneOrMoreQuestionsForEdition (long GamCod,unsigned NumQsts, +static void Gam_ListOneOrMoreQuestionsForEdition (struct Gam_Games *Games, + long GamCod,unsigned NumQsts, MYSQL_RES *mysql_res, bool ICanEditQuestions) { @@ -1960,8 +1991,8 @@ static void Gam_ListOneOrMoreQuestionsForEdition (long GamCod,unsigned NumQsts, Question.QstCod = Str_ConvertStrCodToLongCod (row[1]); /***** Icons *****/ - Gam_SetCurrentGamCod (GamCod); // Used to pass parameter - Gam_CurrentQstInd = QstInd; + Games->GamCod = GamCod; + Games->QstInd = QstInd; HTM_TR_Begin (NULL); HTM_TD_Begin ("class=\"BT%u\"",Gbl.RowEvenOdd); @@ -1970,7 +2001,7 @@ static void Gam_ListOneOrMoreQuestionsForEdition (long GamCod,unsigned NumQsts, if (ICanEditQuestions) { Frm_StartForm (ActReqRemGamQst); - Gam_PutParams (&Gbl); + Gam_PutParams (Games); Gam_PutParamQstInd (QstInd); Ico_PutIconRemove (); Frm_EndForm (); @@ -1982,7 +2013,7 @@ static void Gam_ListOneOrMoreQuestionsForEdition (long GamCod,unsigned NumQsts, if (ICanEditQuestions && QstInd > 1) { Lay_PutContextualLinkOnlyIcon (ActUp_GamQst,NULL, - Gam_PutParamsOneQst,&Gbl, + Gam_PutParamsOneQst,Games, "arrow-up.svg", Str_BuildStringStr (Txt_Move_up_X, StrQstInd)); @@ -1995,7 +2026,7 @@ static void Gam_ListOneOrMoreQuestionsForEdition (long GamCod,unsigned NumQsts, if (ICanEditQuestions && QstInd < MaxQstInd) { Lay_PutContextualLinkOnlyIcon (ActDwnGamQst,NULL, - Gam_PutParamsOneQst,&Gbl, + Gam_PutParamsOneQst,Games, "arrow-down.svg", Str_BuildStringStr (Txt_Move_down_X, StrQstInd)); @@ -2084,14 +2115,14 @@ static void Gam_ListQuestionForEdition (const struct Tst_Question *Question, /***************** Put icon to add a new questions to game *******************/ /*****************************************************************************/ -static void Gam_PutIconToAddNewQuestions (void *Args) +static void Gam_PutIconToAddNewQuestions (void *Games) { extern const char *Txt_Add_questions; - if (Args) + if (Games) /***** Put form to create a new question *****/ Ico_PutContextualIconToAdd (ActAddOneGamQst,NULL, - Gam_PutParams,&Gbl, + Gam_PutParams,Games, Txt_Add_questions); } @@ -2099,12 +2130,12 @@ static void Gam_PutIconToAddNewQuestions (void *Args) /***************** Put button to add new questions to game *******************/ /*****************************************************************************/ -static void Gam_PutButtonToAddNewQuestions (void) +static void Gam_PutButtonToAddNewQuestions (struct Gam_Games *Games) { extern const char *Txt_Add_questions; Frm_StartForm (ActAddOneGamQst); - Gam_PutParams (&Gbl); + Gam_PutParams (Games); Btn_PutConfirmButton (Txt_Add_questions); Frm_EndForm (); } @@ -2116,14 +2147,15 @@ static void Gam_PutButtonToAddNewQuestions (void) void Gam_AddTstQuestionsToGame (void) { extern const char *Txt_No_questions_have_been_added; - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; const char *Ptr; char LongStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1]; long QstCod; unsigned MaxQstInd; /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); Gam_GetDataOfGameByCod (&Game); @@ -2132,17 +2164,17 @@ void Gam_AddTstQuestionsToGame (void) { /***** Get selected questions *****/ /* Allocate space for selected question codes */ - Gam_AllocateListSelectedQuestions (); + Gam_AllocateListSelectedQuestions (&Games); /* Get question codes */ - Par_GetParMultiToText ("QstCods",Gbl.Games.ListQuestions, + Par_GetParMultiToText ("QstCods",Games.ListQuestions, Gam_MAX_BYTES_LIST_SELECTED_QUESTIONS); /* Check number of questions */ - if (Gam_CountNumQuestionsInList ()) // If questions selected... + if (Gam_CountNumQuestionsInList (&Games)) // If questions selected... { /***** Insert questions in database *****/ - Ptr = Gbl.Games.ListQuestions; + Ptr = Games.ListQuestions; while (*Ptr) { /* Get next code */ @@ -2166,13 +2198,13 @@ void Gam_AddTstQuestionsToGame (void) Ale_ShowAlert (Ale_WARNING,Txt_No_questions_have_been_added); /***** Free space for selected question codes *****/ - Gam_FreeListsSelectedQuestions (); + Gam_FreeListsSelectedQuestions (&Games); } else Lay_NoPermissionExit (); /***** Show current game *****/ - Gam_ShowOnlyOneGame (&Game, + Gam_ShowOnlyOneGame (&Games,&Game, true, // List game questions false); // Do not put form to start new match } @@ -2181,13 +2213,13 @@ void Gam_AddTstQuestionsToGame (void) /****************** Allocate memory for list of questions ********************/ /*****************************************************************************/ -static void Gam_AllocateListSelectedQuestions (void) +static void Gam_AllocateListSelectedQuestions (struct Gam_Games *Games) { - if (!Gbl.Games.ListQuestions) + if (!Games->ListQuestions) { - if ((Gbl.Games.ListQuestions = (char *) malloc (Gam_MAX_BYTES_LIST_SELECTED_QUESTIONS + 1)) == NULL) + if ((Games->ListQuestions = (char *) malloc (Gam_MAX_BYTES_LIST_SELECTED_QUESTIONS + 1)) == NULL) Lay_NotEnoughMemoryExit ();; - Gbl.Games.ListQuestions[0] = '\0'; + Games->ListQuestions[0] = '\0'; } } @@ -2195,12 +2227,12 @@ static void Gam_AllocateListSelectedQuestions (void) /*********** Free memory used by list of selected question codes *************/ /*****************************************************************************/ -static void Gam_FreeListsSelectedQuestions (void) +static void Gam_FreeListsSelectedQuestions (struct Gam_Games *Games) { - if (Gbl.Games.ListQuestions) + if (Games->ListQuestions) { - free (Gbl.Games.ListQuestions); - Gbl.Games.ListQuestions = NULL; + free (Games->ListQuestions); + Games->ListQuestions = NULL; } } @@ -2208,7 +2240,7 @@ static void Gam_FreeListsSelectedQuestions (void) /**** Count the number of questions in the list of selected question codes ***/ /*****************************************************************************/ -static unsigned Gam_CountNumQuestionsInList (void) +static unsigned Gam_CountNumQuestionsInList (const struct Gam_Games *Games) { const char *Ptr; unsigned NumQuestions = 0; @@ -2216,7 +2248,7 @@ static unsigned Gam_CountNumQuestionsInList (void) long QstCod; /***** Go over list of questions counting the number of questions *****/ - Ptr = Gbl.Games.ListQuestions; + Ptr = Games->ListQuestions; while (*Ptr) { Par_GetNextStrUntilSeparParamMult (&Ptr,LongStr,Cns_MAX_DECIMAL_DIGITS_LONG); @@ -2235,11 +2267,15 @@ void Gam_RequestRemoveQst (void) { extern const char *Txt_Do_you_really_want_to_remove_the_question_X; extern const char *Txt_Remove_question; - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; unsigned QstInd; + /***** Reset games *****/ + Gam_ResetGames (&Games); + /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); Gam_GetDataOfGameByCod (&Game); @@ -2250,8 +2286,8 @@ void Gam_RequestRemoveQst (void) QstInd = Gam_GetParamQstInd (); /***** Show question and button to remove question *****/ - Gam_SetCurrentGamCod (Game.GamCod); // Used to pass parameter - Gam_CurrentQstInd = QstInd; + Games.GamCod = Game.GamCod; + Games.QstInd = QstInd; Ale_ShowAlertAndButton (ActRemGamQst,NULL,NULL, Gam_PutParamsOneQst,&Gbl, Btn_REMOVE_BUTTON,Txt_Remove_question, @@ -2262,7 +2298,7 @@ void Gam_RequestRemoveQst (void) Lay_NoPermissionExit (); /***** Show current game *****/ - Gam_ShowOnlyOneGame (&Game, + Gam_ShowOnlyOneGame (&Games,&Game, true, // List game questions false); // Do not put form to start new match } @@ -2274,11 +2310,15 @@ void Gam_RequestRemoveQst (void) void Gam_RemoveQst (void) { extern const char *Txt_Question_removed; - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; unsigned QstInd; + /***** Reset games *****/ + Gam_ResetGames (&Games); + /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); Gam_GetDataOfGameByCod (&Game); @@ -2320,7 +2360,7 @@ void Gam_RemoveQst (void) Lay_NoPermissionExit (); /***** Show current game *****/ - Gam_ShowOnlyOneGame (&Game, + Gam_ShowOnlyOneGame (&Games,&Game, true, // List game questions false); // Do not put form to start new match } @@ -2333,12 +2373,16 @@ void Gam_MoveUpQst (void) { extern const char *Txt_The_question_has_been_moved_up; extern const char *Txt_Movement_not_allowed; - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; unsigned QstIndTop; unsigned QstIndBottom; + /***** Reset games *****/ + Gam_ResetGames (&Games); + /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); Gam_GetDataOfGameByCod (&Game); @@ -2369,7 +2413,7 @@ void Gam_MoveUpQst (void) Lay_NoPermissionExit (); /***** Show current game *****/ - Gam_ShowOnlyOneGame (&Game, + Gam_ShowOnlyOneGame (&Games,&Game, true, // List game questions false); // Do not put form to start new match } @@ -2383,13 +2427,14 @@ void Gam_MoveDownQst (void) extern const char *Txt_The_question_has_been_moved_down; extern const char *Txt_Movement_not_allowed; extern const char *Txt_This_game_has_no_questions; - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; unsigned QstIndTop; unsigned QstIndBottom; unsigned MaxQstInd; // 0 if no questions /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); Gam_GetDataOfGameByCod (&Game); @@ -2428,7 +2473,7 @@ void Gam_MoveDownQst (void) Lay_NoPermissionExit (); /***** Show current game *****/ - Gam_ShowOnlyOneGame (&Game, + Gam_ShowOnlyOneGame (&Games,&Game, true, // List game questions false); // Do not put form to start new match } @@ -2489,7 +2534,7 @@ static void Gam_ExchangeQuestions (long GamCod, /*****************************************************************************/ // Before calling this function, number of matches must be calculated -static bool Gam_CheckIfEditable (const struct Game *Game) +static bool Gam_CheckIfEditable (const struct Gam_Game *Game) { if (Gam_CheckIfICanEditGames ()) /***** Questions are editable only if game has no matches *****/ @@ -2502,13 +2547,13 @@ static bool Gam_CheckIfEditable (const struct Game *Game) /********************* Put button to create a new match **********************/ /*****************************************************************************/ -void Gam_PutButtonNewMatch (long GamCod) +void Gam_PutButtonNewMatch (struct Gam_Games *Games,long GamCod) { extern const char *Txt_New_match; - Gam_SetCurrentGamCod (GamCod); // Used to pass parameter + Games->GamCod = GamCod; Frm_StartFormAnchor (ActReqNewMch,Mch_NEW_MATCH_SECTION_ID); - Gam_PutParams (&Gbl); + Gam_PutParams (Games); Btn_PutConfirmButton (Txt_New_match); Frm_EndForm (); } @@ -2519,15 +2564,19 @@ void Gam_PutButtonNewMatch (long GamCod) void Gam_RequestNewMatch (void) { - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); Gam_GetDataOfGameByCod (&Game); /***** Show game *****/ - Gam_ShowOnlyOneGame (&Game, + Gam_ShowOnlyOneGame (&Games,&Game, false, // Do not list game questions true); // Put form to start new match } diff --git a/swad_game.h b/swad_game.h index 133f7a2f..bb8b6f1a 100644 --- a/swad_game.h +++ b/swad_game.h @@ -37,29 +37,6 @@ #define Gam_MAX_CHARS_TITLE (128 - 1) // 127 #define Gam_MAX_BYTES_TITLE ((Gam_MAX_CHARS_TITLE + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 2047 -struct GameSelected - { - long GamCod; // Game code - bool Selected; // Is this game selected when seeing match results? - }; - -struct Game - { - long GamCod; // Game code - long CrsCod; // Course code - long UsrCod; // Author code - double MaxGrade; // Score range [0...max.score] - // will be converted to - // grade range [0...max.grade] - unsigned Visibility; // Visibility of results - char Title[Gam_MAX_BYTES_TITLE + 1]; - time_t TimeUTC[Dat_NUM_START_END_TIME]; - bool Hidden; // Game is hidden - unsigned NumQsts; // Number of questions in the game - unsigned NumMchs; // Number of matches in the game - unsigned NumUnfinishedMchs; // Number of unfinished matches in the game - }; - #define Gam_NUM_ORDERS 3 typedef enum { @@ -77,33 +54,74 @@ typedef enum } Gam_AnswerType_t; #define Gam_ANSWER_TYPE_DEFAULT Gam_ANS_UNIQUE_CHOICE +struct Gam_GameSelected + { + long GamCod; // Game code + bool Selected; // Is this game selected when seeing match results? + }; + +struct Gam_Games + { + bool LstIsRead; // Is the list already read from database... + // ...or it needs to be read? + unsigned Num; // Total number of games + unsigned NumSelected; // Number of games selected + struct Gam_GameSelected *Lst;// List of games + Gam_Order_t SelectedOrder; + unsigned CurrentPage; + char *ListQuestions; + char *GamCodsSelected; // String with selected game codes separated by separator multiple + long GamCod; // Selected/current game code + long MchCod; // Selected/current match code + unsigned QstInd; // Current question index + }; + +struct Gam_Game + { + long GamCod; // Game code + long CrsCod; // Course code + long UsrCod; // Author code + double MaxGrade; // Score range [0...max.score] + // will be converted to + // grade range [0...max.grade] + unsigned Visibility; // Visibility of results + char Title[Gam_MAX_BYTES_TITLE + 1]; + time_t TimeUTC[Dat_NUM_START_END_TIME]; + bool Hidden; // Game is hidden + unsigned NumQsts; // Number of questions in the game + unsigned NumMchs; // Number of matches in the game + unsigned NumUnfinishedMchs; // Number of unfinished matches in the game + }; + /*****************************************************************************/ /***************************** Public prototypes *****************************/ /*****************************************************************************/ +void Gam_ResetGames (struct Gam_Games *Games); + void Gam_SeeAllGames (void); void Gam_SeeOneGame (void); -void Gam_ShowOnlyOneGame (struct Game *Game, +void Gam_ShowOnlyOneGame (struct Gam_Games *Games, + struct Gam_Game *Game, bool ListGameQuestions, bool PutFormNewMatch); -void Gam_ShowOnlyOneGameBegin (struct Game *Game, +void Gam_ShowOnlyOneGameBegin (struct Gam_Games *Games, + struct Gam_Game *Game, bool ListGameQuestions, bool PutFormNewMatch); void Gam_ShowOnlyOneGameEnd (void); -void Gam_PutHiddenParamGameOrder (void); -void Gam_RequestCreatOrEditGame (void); void Gam_SetCurrentGamCod (long GamCod); -void Gam_PutParams (void *Args); +void Gam_PutParams (void *Games); void Gam_PutParamGameCod (long GamCod); long Gam_GetParamGameCod (void); -long Gam_GetParams (void); +long Gam_GetParams (struct Gam_Games *Games); -void Gam_GetListGames (Gam_Order_t SelectedOrder); -void Gam_GetListSelectedGamCods (void); -void Gam_GetDataOfGameByCod (struct Game *Gam); -void Gam_GetDataOfGameByFolder (struct Game *Gam); -void Gam_FreeListGames (void); +void Gam_GetListGames (struct Gam_Games *Games,Gam_Order_t SelectedOrder); +void Gam_GetListSelectedGamCods (struct Gam_Games *Games); +void Gam_GetDataOfGameByCod (struct Gam_Game *Gam); +void Gam_GetDataOfGameByFolder (struct Gam_Game *Gam); +void Gam_FreeListGames (struct Gam_Games *Games); void Gam_AskRemGame (void); void Gam_RemoveGame (void); @@ -111,8 +129,11 @@ void Gam_RemoveGamesCrs (long CrsCod); void Gam_HideGame (void); void Gam_UnhideGame (void); + +void Gam_RequestCreatOrEditGame (void); + void Gam_RecFormGame (void); -bool Gam_CheckIfMatchIsAssociatedToGrp (long MchCod,long GrpCod); +bool Mch_CheckIfMatchIsAssociatedToGrp (long MchCod,long GrpCod); unsigned Gam_GetNumQstsGame (long GamCod); @@ -133,7 +154,7 @@ void Gam_RemoveQst (void); void Gam_MoveUpQst (void); void Gam_MoveDownQst (void); -void Gam_PutButtonNewMatch (long GamCod); +void Gam_PutButtonNewMatch (struct Gam_Games *Games,long GamCod); void Gam_RequestNewMatch (void); unsigned Gam_GetNumCoursesWithGames (Hie_Level_t Scope); diff --git a/swad_global.c b/swad_global.c index 1e5a6d4d..b3baab58 100644 --- a/swad_global.c +++ b/swad_global.c @@ -337,9 +337,6 @@ void Gbl_InitializeGlobals (void) Gbl.Usrs.Connected.TimeToRefreshInMs = Con_MAX_TIME_TO_REFRESH_CONNECTED_IN_MS; - /* Games for remote control */ - Gbl.Games.ListQuestions = NULL; - /* Public activity */ Gbl.Timeline.Who = TL_DEFAULT_WHO; diff --git a/swad_global.h b/swad_global.h index 0b898fdc..92a70b4e 100644 --- a/swad_global.h +++ b/swad_global.h @@ -513,7 +513,7 @@ struct Globals bool HiddenLevels[1 + Brw_MAX_DIR_LEVELS]; const char *TxtStyle; const char *InputStyle; - struct Assignment Asg; // Data of assignment when browsing level 1 or an assignment zone + struct Asg_Assignment Asg; // Data of assignment when browsing level 1 or an assignment zone struct { bool CreateZIP; @@ -603,19 +603,6 @@ struct Globals struct DateTime DateEnd; // TODO: Remove in future versions time_t TimeUTC[Dat_NUM_START_END_TIME]; } DateRange; - struct - { - bool LstIsRead; // Is the list already read from database... - // ...or it needs to be read? - unsigned Num; // Total number of games - unsigned NumSelected; // Number of games selected - struct GameSelected *Lst; // List of games - Gam_Order_t SelectedOrder; - unsigned CurrentPage; - char *ListQuestions; - long MchCodBeingPlayed; // Used to refresh game via AJAX - char *GamCodsSelected; // String with selected game codes separated by separator multiple - } Games; struct { bool LstIsRead; // Is the list already read from database, or it needs to be read? diff --git a/swad_group.c b/swad_group.c index 8743d900..5c2857a2 100644 --- a/swad_group.c +++ b/swad_group.c @@ -1718,7 +1718,7 @@ void Grp_ListGrpsToEditAsgAttSvyMch (struct GroupType *GrpTyp,long Cod, AssociatedToGrp = Svy_CheckIfSvyIsAssociatedToGrp (Cod,Grp->GrpCod); break; case Grp_MATCH: - AssociatedToGrp = Gam_CheckIfMatchIsAssociatedToGrp (Cod,Grp->GrpCod); + AssociatedToGrp = Mch_CheckIfMatchIsAssociatedToGrp (Cod,Grp->GrpCod); break; } diff --git a/swad_layout.c b/swad_layout.c index 2c8640ed..b7faf87e 100644 --- a/swad_layout.c +++ b/swad_layout.c @@ -48,6 +48,7 @@ #include "swad_language.h" #include "swad_log.h" #include "swad_logo.h" +#include "swad_match.h" #include "swad_MFU.h" #include "swad_notice.h" #include "swad_notification.h" @@ -898,7 +899,7 @@ static void Lay_WriteScriptParamsAJAX (void) HTM_TxtF ("var RefreshParamNxtActMch = \"act=%ld\";\n" "var RefreshParamMchCod = \"MchCod=%ld\";\n", Act_GetActCod (ActRefMchStd), - Gbl.Games.MchCodBeingPlayed); + Mch_GetMchCodBeingPlayed ()); break; /* Parameters related with match refreshing (for teachers) */ case ActNewMch: @@ -915,7 +916,7 @@ static void Lay_WriteScriptParamsAJAX (void) HTM_TxtF ("var RefreshParamNxtActMch = \"act=%ld\";\n" "var RefreshParamMchCod = \"MchCod=%ld\";\n", Act_GetActCod (ActRefMchTch), - Gbl.Games.MchCodBeingPlayed); + Mch_GetMchCodBeingPlayed ()); break; /* Parameter related with clicks refreshing */ case ActLstClk: @@ -1389,6 +1390,15 @@ void Lay_WrongOrderExit (void) Lay_ShowErrorAndExit ("Wrong order."); } +/*****************************************************************************/ +/************* Write error message and exit when wrong order *****************/ +/*****************************************************************************/ + +void Lay_WrongTypeOfViewExit (void) + { + Lay_ShowErrorAndExit ("Wrong type of view."); + } + /*****************************************************************************/ /******* Write error message, close files, remove lock file, and exit ********/ /*****************************************************************************/ diff --git a/swad_layout.h b/swad_layout.h index cbe55a31..ef353087 100644 --- a/swad_layout.h +++ b/swad_layout.h @@ -72,6 +72,7 @@ void Lay_PutContextualCheckbox (Act_Action_t NextAction, void Lay_NotEnoughMemoryExit (void); void Lay_WrongScopeExit (void); void Lay_WrongOrderExit (void); +void Lay_WrongTypeOfViewExit (void); void Lay_NoPermissionExit (void); void Lay_ShowErrorAndExit (const char *Txt); diff --git a/swad_match.c b/swad_match.c index f80dc62a..e24bf44d 100644 --- a/swad_match.c +++ b/swad_match.c @@ -95,34 +95,41 @@ const char *Mch_ShowingStringsDB[Mch_NUM_SHOWING] = /***************************** Private variables *****************************/ /*****************************************************************************/ -long Mch_CurrentMchCod = -1L; // Used as parameter in contextual links +long Mch_MchCodBeingPlayed; // Used to refresh game via AJAX /*****************************************************************************/ /***************************** Private prototypes ****************************/ /*****************************************************************************/ -static void Mch_PutIconsInListOfMatches (void *Args); -static void Mch_PutIconToCreateNewMatch (void); +static void Mch_SetMchCodBeingPlayed (long MchCod); -static void Mch_ListOneOrMoreMatches (const struct Game *Game, +static void Mch_PutIconsInListOfMatches (void *Games); +static void Mch_PutIconToCreateNewMatch (struct Gam_Games *Games); + +static void Mch_ListOneOrMoreMatches (struct Gam_Games *Games, + const struct Gam_Game *Game, unsigned NumMatches, MYSQL_RES *mysql_res); static void Mch_ListOneOrMoreMatchesHeading (bool ICanEditMatches); static bool Mch_CheckIfICanEditMatches (void); -static bool Mch_CheckIfICanEditThisMatch (const struct Match *Match); -static void Mch_ListOneOrMoreMatchesIcons (const struct Match *Match); -static void Mch_ListOneOrMoreMatchesAuthor (const struct Match *Match); -static void Mch_ListOneOrMoreMatchesTimes (const struct Match *Match,unsigned UniqueId); -static void Mch_ListOneOrMoreMatchesTitleGrps (const struct Match *Match); -static void Mch_GetAndWriteNamesOfGrpsAssociatedToMatch (const struct Match *Match); -static void Mch_ListOneOrMoreMatchesNumPlayers (const struct Match *Match); -static void Mch_ListOneOrMoreMatchesStatus (const struct Match *Match,unsigned NumQsts); -static void Mch_ListOneOrMoreMatchesResult (const struct Match *Match); -static void Mch_ListOneOrMoreMatchesResultStd (const struct Match *Match); -static void Mch_ListOneOrMoreMatchesResultTch (const struct Match *Match); +static bool Mch_CheckIfICanEditThisMatch (const struct Mch_Match *Match); +static void Mch_ListOneOrMoreMatchesIcons (struct Gam_Games *Games, + const struct Mch_Match *Match); +static void Mch_ListOneOrMoreMatchesAuthor (const struct Mch_Match *Match); +static void Mch_ListOneOrMoreMatchesTimes (const struct Mch_Match *Match,unsigned UniqueId); +static void Mch_ListOneOrMoreMatchesTitleGrps (const struct Mch_Match *Match); +static void Mch_GetAndWriteNamesOfGrpsAssociatedToMatch (const struct Mch_Match *Match); +static void Mch_ListOneOrMoreMatchesNumPlayers (const struct Mch_Match *Match); +static void Mch_ListOneOrMoreMatchesStatus (struct Mch_Match *Match,unsigned NumQsts); +static void Mch_ListOneOrMoreMatchesResult (struct Gam_Games *Games, + const struct Mch_Match *Match); +static void Mch_ListOneOrMoreMatchesResultStd (struct Gam_Games *Games, + const struct Mch_Match *Match); +static void Mch_ListOneOrMoreMatchesResultTch (struct Gam_Games *Games, + const struct Mch_Match *Match); static void Mch_GetMatchDataFromRow (MYSQL_RES *mysql_res, - struct Match *Match); + struct Mch_Match *Match); static Mch_Showing_t Mch_GetShowingFromStr (const char *Str); static void Mch_RemoveMatchFromAllTables (long MchCod); @@ -131,10 +138,10 @@ static void Mch_RemoveMatchesInGameFromTable (long GamCod,const char *TableName) static void Mch_RemoveMatchInCourseFromTable (long CrsCod,const char *TableName); static void Mch_RemoveUsrMchResultsInCrs (long UsrCod,long CrsCod,const char *TableName); -static void Mch_PutParamsPlay (void *Args); +static void Mch_PutParamsPlay (void *MchCod); static void Mch_PutParamMchCod (long MchCod); -static void Mch_PutFormNewMatch (const struct Game *Game); +static void Mch_PutFormNewMatch (const struct Gam_Game *Game); static void Mch_ShowLstGrpsToCreateMatch (void); static long Mch_CreateMatch (long GamCod,char Title[Gam_MAX_BYTES_TITLE + 1]); @@ -142,63 +149,63 @@ static void Mch_CreateIndexes (long GamCod,long MchCod); static void Mch_ReorderAnswer (long MchCod,unsigned QstInd, const struct Tst_Question *Question); static void Mch_CreateGrps (long MchCod); -static void Mch_UpdateMatchStatusInDB (const struct Match *Match); +static void Mch_UpdateMatchStatusInDB (const struct Mch_Match *Match); -static void Mch_UpdateElapsedTimeInQuestion (const struct Match *Match); -static void Mch_GetElapsedTimeInQuestion (const struct Match *Match, +static void Mch_UpdateElapsedTimeInQuestion (const struct Mch_Match *Match); +static void Mch_GetElapsedTimeInQuestion (const struct Mch_Match *Match, struct Time *Time); -static void Mch_GetElapsedTimeInMatch (const struct Match *Match, +static void Mch_GetElapsedTimeInMatch (const struct Mch_Match *Match, struct Time *Time); static void Mch_GetElapsedTime (unsigned NumRows,MYSQL_RES *mysql_res, struct Time *Time); -static void Mch_SetMatchStatusToPrev (struct Match *Match); -static void Mch_SetMatchStatusToPrevQst (struct Match *Match); -static void Mch_SetMatchStatusToStart (struct Match *Match); +static void Mch_SetMatchStatusToPrev (struct Mch_Match *Match); +static void Mch_SetMatchStatusToPrevQst (struct Mch_Match *Match); +static void Mch_SetMatchStatusToStart (struct Mch_Match *Match); -static void Mch_SetMatchStatusToNext (struct Match *Match); -static void Mch_SetMatchStatusToNextQst (struct Match *Match); -static void Mch_SetMatchStatusToEnd (struct Match *Match); +static void Mch_SetMatchStatusToNext (struct Mch_Match *Match); +static void Mch_SetMatchStatusToNextQst (struct Mch_Match *Match); +static void Mch_SetMatchStatusToEnd (struct Mch_Match *Match); -static void Mch_ShowMatchStatusForTch (struct Match *Match); -static void Mch_ShowMatchStatusForStd (struct Match *Match,Mch_Update_t Update); +static void Mch_ShowMatchStatusForTch (struct Mch_Match *Match); +static void Mch_ShowMatchStatusForStd (struct Mch_Match *Match,Mch_Update_t Update); -static void Mch_ShowLeftColumnTch (struct Match *Match); -static void Mch_ShowRefreshablePartTch (struct Match *Match); -static void Mch_WriteElapsedTimeInMch (struct Match *Match); -static void Mch_WriteElapsedTimeInQst (struct Match *Match); -static void Mch_WriteNumRespondersQst (struct Match *Match); -static void Mch_PutFormCountdown (struct Match *Match,long Seconds,const char *Color); -static void Mch_PutCountdownAndHourglassIcon (struct Match *Match); -static void Mch_PutFormsCountdown (struct Match *Match); +static void Mch_ShowLeftColumnTch (struct Mch_Match *Match); +static void Mch_ShowRefreshablePartTch (struct Mch_Match *Match); +static void Mch_WriteElapsedTimeInMch (struct Mch_Match *Match); +static void Mch_WriteElapsedTimeInQst (struct Mch_Match *Match); +static void Mch_WriteNumRespondersQst (struct Mch_Match *Match); +static void Mch_PutFormCountdown (struct Mch_Match *Match,long Seconds,const char *Color); +static void Mch_PutCountdownAndHourglassIcon (struct Mch_Match *Match); +static void Mch_PutFormsCountdown (struct Mch_Match *Match); -static void Mch_ShowRightColumnTch (const struct Match *Match); -static void Mch_ShowLeftColumnStd (const struct Match *Match, +static void Mch_ShowRightColumnTch (const struct Mch_Match *Match); +static void Mch_ShowLeftColumnStd (const struct Mch_Match *Match, const struct Mch_UsrAnswer *UsrAnswer); -static void Mch_ShowRightColumnStd (struct Match *Match, +static void Mch_ShowRightColumnStd (struct Mch_Match *Match, const struct Mch_UsrAnswer *UsrAnswer, Mch_Update_t Update); -static void Mch_ShowNumQstInMch (const struct Match *Match); -static void Mch_PutMatchControlButtons (const struct Match *Match); -static void Mch_ShowFormColumns (const struct Match *Match); +static void Mch_ShowNumQstInMch (const struct Mch_Match *Match); +static void Mch_PutMatchControlButtons (const struct Mch_Match *Match); +static void Mch_ShowFormColumns (const struct Mch_Match *Match); static void Mch_PutParamNumCols (unsigned NumCols); -static void Mch_ShowMatchTitleTch (const struct Match *Match); -static void Mch_ShowMatchTitleStd (const struct Match *Match); +static void Mch_ShowMatchTitleTch (const struct Mch_Match *Match); +static void Mch_ShowMatchTitleStd (const struct Mch_Match *Match); -static void Mch_PutCheckboxResult (const struct Match *Match); -static void Mch_PutIfAnswered (const struct Match *Match,bool Answered); -static void Mch_PutIconToRemoveMyAnswer (const struct Match *Match); -static void Mch_ShowQuestionAndAnswersTch (const struct Match *Match); -static void Mch_WriteAnswersMatchResult (const struct Match *Match, +static void Mch_PutCheckboxResult (const struct Mch_Match *Match); +static void Mch_PutIfAnswered (const struct Mch_Match *Match,bool Answered); +static void Mch_PutIconToRemoveMyAnswer (const struct Mch_Match *Match); +static void Mch_ShowQuestionAndAnswersTch (const struct Mch_Match *Match); +static void Mch_WriteAnswersMatchResult (const struct Mch_Match *Match, const struct Tst_Question *Question, const char *Class,bool ShowResult); -static bool Mch_ShowQuestionAndAnswersStd (const struct Match *Match, +static bool Mch_ShowQuestionAndAnswersStd (const struct Mch_Match *Match, const struct Mch_UsrAnswer *UsrAnswer, Mch_Update_t Update); -static void Mch_ShowMatchScore (const struct Match *Match); +static void Mch_ShowMatchScore (const struct Mch_Match *Match); static void Mch_DrawEmptyScoreRow (unsigned NumRow,double MinScore,double MaxScore); static void Mch_DrawScoreRow (double Score,double MinScore,double MaxScore, unsigned NumRow,unsigned NumUsrs,unsigned MaxUsrs); @@ -218,21 +225,35 @@ static void Mch_RemoveOldPlayers (void); static void Mch_UpdateMatchAsBeingPlayed (long MchCod); static void Mch_SetMatchAsNotBeingPlayed (long MchCod); static bool Mch_GetIfMatchIsBeingPlayed (long MchCod); -static void Mch_GetNumPlayers (struct Match *Match); +static void Mch_GetNumPlayers (struct Mch_Match *Match); -static void Mch_RemoveMyAnswerToMatchQuestion (const struct Match *Match); +static void Mch_RemoveMyAnswerToMatchQuestion (const struct Mch_Match *Match); static void Mch_ComputeScore (struct TstExa_Exam *Result); static unsigned Mch_GetNumUsrsWhoHaveAnswerMch (long MchCod); -static long Mch_GetCurrentMchCod (void); +/*****************************************************************************/ +/*************** Set/Get match code of the match being played ****************/ +/*****************************************************************************/ + +static void Mch_SetMchCodBeingPlayed (long MchCod) + { + Mch_MchCodBeingPlayed = MchCod; + } + +long Mch_GetMchCodBeingPlayed (void) + { + return Mch_MchCodBeingPlayed; + } /*****************************************************************************/ /************************* List the matches of a game ************************/ /*****************************************************************************/ -void Mch_ListMatches (struct Game *Game,bool PutFormNewMatch) +void Mch_ListMatches (struct Gam_Games *Games, + struct Gam_Game *Game, + bool PutFormNewMatch) { extern const char *Hlp_ASSESSMENT_Games_matches; extern const char *Txt_Matches; @@ -285,9 +306,9 @@ void Mch_ListMatches (struct Game *Game,bool PutFormNewMatch) free (SubQuery); /***** Begin box *****/ - Gam_SetCurrentGamCod (Game->GamCod); // Used to pass parameter + Games->GamCod = Game->GamCod; Box_BoxBegin ("100%",Txt_Matches, - Mch_PutIconsInListOfMatches,&Gbl, + Mch_PutIconsInListOfMatches,Games, Hlp_ASSESSMENT_Games_matches,Box_NOT_CLOSABLE); /***** Select whether show only my groups or all groups *****/ @@ -295,13 +316,13 @@ void Mch_ListMatches (struct Game *Game,bool PutFormNewMatch) { Set_StartSettingsHead (); Grp_ShowFormToSelWhichGrps (ActSeeGam, - Gam_PutParams,&Gbl); + Gam_PutParams,Games); Set_EndSettingsHead (); } if (NumMatches) /***** Show the table with the matches *****/ - Mch_ListOneOrMoreMatches (Game,NumMatches,mysql_res); + Mch_ListOneOrMoreMatches (Games,Game,NumMatches,mysql_res); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -315,7 +336,7 @@ void Mch_ListMatches (struct Game *Game,bool PutFormNewMatch) if (PutFormNewMatch) Mch_PutFormNewMatch (Game); // Form to fill in data and start playing a new match else - Gam_PutButtonNewMatch (Game->GamCod); // Button to create a new match + Gam_PutButtonNewMatch (Games,Game->GamCod); // Button to create a new match break; default: break; @@ -329,7 +350,7 @@ void Mch_ListMatches (struct Game *Game,bool PutFormNewMatch) /********************** Get match data using its code ************************/ /*****************************************************************************/ -void Mch_GetDataOfMatchByCod (struct Match *Match) +void Mch_GetDataOfMatchByCod (struct Mch_Match *Match) { MYSQL_RES *mysql_res; unsigned long NumRows; @@ -391,16 +412,16 @@ void Mch_GetDataOfMatchByCod (struct Match *Match) /****************** Put icons in list of matches of a game *******************/ /*****************************************************************************/ -static void Mch_PutIconsInListOfMatches (void *Args) +static void Mch_PutIconsInListOfMatches (void *Games) { bool ICanEditMatches; - if (Args) + if (Games) { /***** Put icon to create a new match in current game *****/ ICanEditMatches = Mch_CheckIfICanEditMatches (); if (ICanEditMatches) - Mch_PutIconToCreateNewMatch (); + Mch_PutIconToCreateNewMatch ((struct Gam_Games *) Games); } } @@ -408,13 +429,13 @@ static void Mch_PutIconsInListOfMatches (void *Args) /********************* Put icon to create a new match ************************/ /*****************************************************************************/ -static void Mch_PutIconToCreateNewMatch (void) +static void Mch_PutIconToCreateNewMatch (struct Gam_Games *Games) { extern const char *Txt_New_match; /***** Put form to create a new match *****/ Ico_PutContextualIconToAdd (ActReqNewMch,Mch_NEW_MATCH_SECTION_ID, - Gam_PutParams,&Gbl, + Gam_PutParams,Games, Txt_New_match); } @@ -422,13 +443,14 @@ static void Mch_PutIconToCreateNewMatch (void) /*********************** List game matches for edition ***********************/ /*****************************************************************************/ -static void Mch_ListOneOrMoreMatches (const struct Game *Game, +static void Mch_ListOneOrMoreMatches (struct Gam_Games *Games, + const struct Gam_Game *Game, unsigned NumMatches, MYSQL_RES *mysql_res) { unsigned NumMatch; unsigned UniqueId; - struct Match Match; + struct Mch_Match Match; bool ICanEditMatches = Mch_CheckIfICanEditMatches (); /***** Write the heading *****/ @@ -452,7 +474,7 @@ static void Mch_ListOneOrMoreMatches (const struct Game *Game, /* Icons */ if (ICanEditMatches) - Mch_ListOneOrMoreMatchesIcons (&Match); + Mch_ListOneOrMoreMatchesIcons (Games,&Match); /* Match player */ Mch_ListOneOrMoreMatchesAuthor (&Match); @@ -470,7 +492,7 @@ static void Mch_ListOneOrMoreMatches (const struct Game *Game, Mch_ListOneOrMoreMatchesStatus (&Match,Game->NumQsts); /* Match result visible? */ - Mch_ListOneOrMoreMatchesResult (&Match); + Mch_ListOneOrMoreMatchesResult (Games,&Match); } } @@ -532,7 +554,7 @@ static bool Mch_CheckIfICanEditMatches (void) /***************** Check if I can edit (remove/resume) a match ***************/ /*****************************************************************************/ -static bool Mch_CheckIfICanEditThisMatch (const struct Match *Match) +static bool Mch_CheckIfICanEditThisMatch (const struct Mch_Match *Match) { switch (Gbl.Usrs.Me.Role.Logged) { @@ -550,17 +572,18 @@ static bool Mch_CheckIfICanEditThisMatch (const struct Match *Match) /************************* Put a column for icons ****************************/ /*****************************************************************************/ -static void Mch_ListOneOrMoreMatchesIcons (const struct Match *Match) +static void Mch_ListOneOrMoreMatchesIcons (struct Gam_Games *Games, + const struct Mch_Match *Match) { HTM_TD_Begin ("class=\"BT%u\"",Gbl.RowEvenOdd); /***** Put icon to remove the match *****/ if (Mch_CheckIfICanEditThisMatch (Match)) { - Gam_SetCurrentGamCod (Match->GamCod); // Used to pass parameter - Mch_SetCurrentMchCod (Match->MchCod); // Used to pass parameter + Games->GamCod = Match->GamCod; + Games->MchCod = Match->MchCod; Frm_StartForm (ActReqRemMch); - Mch_PutParamsEdit (&Gbl); + Mch_PutParamsEdit (Games); Ico_PutIconRemove (); Frm_EndForm (); } @@ -574,7 +597,7 @@ static void Mch_ListOneOrMoreMatchesIcons (const struct Match *Match) /************* Put a column for teacher who created the match ****************/ /*****************************************************************************/ -static void Mch_ListOneOrMoreMatchesAuthor (const struct Match *Match) +static void Mch_ListOneOrMoreMatchesAuthor (const struct Mch_Match *Match) { /***** Match author (teacher) *****/ HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd); @@ -586,7 +609,7 @@ static void Mch_ListOneOrMoreMatchesAuthor (const struct Match *Match) /***************** Put a column for match start and end times ****************/ /*****************************************************************************/ -static void Mch_ListOneOrMoreMatchesTimes (const struct Match *Match,unsigned UniqueId) +static void Mch_ListOneOrMoreMatchesTimes (const struct Mch_Match *Match,unsigned UniqueId) { Dat_StartEndTime_t StartEndTime; char *Id; @@ -614,7 +637,7 @@ static void Mch_ListOneOrMoreMatchesTimes (const struct Match *Match,unsigned Un /***************** Put a column for match title and grous ********************/ /*****************************************************************************/ -static void Mch_ListOneOrMoreMatchesTitleGrps (const struct Match *Match) +static void Mch_ListOneOrMoreMatchesTitleGrps (const struct Mch_Match *Match) { extern const char *Txt_Play; extern const char *Txt_Resume; @@ -622,10 +645,9 @@ static void Mch_ListOneOrMoreMatchesTitleGrps (const struct Match *Match) HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd); /***** Match title *****/ - Mch_SetCurrentMchCod (Match->MchCod); // Used to pass parameter Frm_StartForm (Gbl.Usrs.Me.Role.Logged == Rol_STD ? ActJoiMch : ActResMch); - Mch_PutParamsPlay (&Gbl); + Mch_PutParamMchCod (Match->MchCod); HTM_BUTTON_SUBMIT_Begin (Gbl.Usrs.Me.Role.Logged == Rol_STD ? Txt_Play : Txt_Resume, "BT_LINK LT ASG_TITLE",NULL); @@ -644,7 +666,7 @@ static void Mch_ListOneOrMoreMatchesTitleGrps (const struct Match *Match) /************* Get and write the names of the groups of a match **************/ /*****************************************************************************/ -static void Mch_GetAndWriteNamesOfGrpsAssociatedToMatch (const struct Match *Match) +static void Mch_GetAndWriteNamesOfGrpsAssociatedToMatch (const struct Mch_Match *Match) { extern const char *Txt_Group; extern const char *Txt_Groups; @@ -703,11 +725,24 @@ static void Mch_GetAndWriteNamesOfGrpsAssociatedToMatch (const struct Match *Mat 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 **********************/ /*****************************************************************************/ -static void Mch_ListOneOrMoreMatchesNumPlayers (const struct Match *Match) +static void Mch_ListOneOrMoreMatchesNumPlayers (const struct Mch_Match *Match) { /***** Number of players who have answered any question in the match ******/ HTM_TD_Begin ("class=\"DAT RT COLOR%u\"",Gbl.RowEvenOdd); @@ -719,7 +754,7 @@ static void Mch_ListOneOrMoreMatchesNumPlayers (const struct Match *Match) /********************** Put a column for match status ************************/ /*****************************************************************************/ -static void Mch_ListOneOrMoreMatchesStatus (const struct Match *Match,unsigned NumQsts) +static void Mch_ListOneOrMoreMatchesStatus (struct Mch_Match *Match,unsigned NumQsts) { extern const char *Txt_Play; extern const char *Txt_Resume; @@ -735,11 +770,10 @@ static void Mch_ListOneOrMoreMatchesStatus (const struct Match *Match,unsigned N } /* Icon to join match or resume match */ - Mch_SetCurrentMchCod (Match->MchCod); // Used to pass parameter Lay_PutContextualLinkOnlyIcon (Gbl.Usrs.Me.Role.Logged == Rol_STD ? ActJoiMch : ActResMch, NULL, - Mch_PutParamsPlay,&Gbl, + Mch_PutParamsPlay,&Match->MchCod, Match->Status.Showing == Mch_END ? "flag-checkered.svg" : "play.svg", Gbl.Usrs.Me.Role.Logged == Rol_STD ? Txt_Play : @@ -752,19 +786,20 @@ static void Mch_ListOneOrMoreMatchesStatus (const struct Match *Match,unsigned N /**************** Put a column for visibility of match result ****************/ /*****************************************************************************/ -static void Mch_ListOneOrMoreMatchesResult (const struct Match *Match) +static void Mch_ListOneOrMoreMatchesResult (struct Gam_Games *Games, + const struct Mch_Match *Match) { HTM_TD_Begin ("class=\"DAT CT COLOR%u\"",Gbl.RowEvenOdd); switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: - Mch_ListOneOrMoreMatchesResultStd (Match); + Mch_ListOneOrMoreMatchesResultStd (Games,Match); break; case Rol_NET: case Rol_TCH: case Rol_SYS_ADM: - Mch_ListOneOrMoreMatchesResultTch (Match); + Mch_ListOneOrMoreMatchesResultTch (Games,Match); break; default: Rol_WrongRoleExit (); @@ -774,7 +809,8 @@ static void Mch_ListOneOrMoreMatchesResult (const struct Match *Match) HTM_TD_End (); } -static void Mch_ListOneOrMoreMatchesResultStd (const struct Match *Match) +static void Mch_ListOneOrMoreMatchesResultStd (struct Gam_Games *Games, + const struct Mch_Match *Match) { extern const char *Txt_Results; @@ -782,10 +818,10 @@ static void Mch_ListOneOrMoreMatchesResultStd (const struct Match *Match) if (Match->Status.ShowUsrResults) { /* Result is visible by me */ - Gam_SetCurrentGamCod (Match->GamCod); // Used to pass parameter - Mch_SetCurrentMchCod (Match->MchCod); // Used to pass parameter + Games->GamCod = Match->GamCod; + Games->MchCod = Match->MchCod; Lay_PutContextualLinkOnlyIcon (ActSeeMyMchResMch,MchRes_RESULTS_BOX_ID, - Mch_PutParamsEdit,&Gbl, + Mch_PutParamsEdit,Games, "trophy.svg", Txt_Results); } @@ -794,7 +830,8 @@ static void Mch_ListOneOrMoreMatchesResultStd (const struct Match *Match) Ico_PutIconNotVisible (); } -static void Mch_ListOneOrMoreMatchesResultTch (const struct Match *Match) +static void Mch_ListOneOrMoreMatchesResultTch (struct Gam_Games *Games, + const struct Mch_Match *Match) { extern const char *Txt_Visible_results; extern const char *Txt_Hidden_results; @@ -803,18 +840,18 @@ static void Mch_ListOneOrMoreMatchesResultTch (const struct Match *Match) /***** Can I edit match vivibility? *****/ if (Mch_CheckIfICanEditThisMatch (Match)) { - Gam_SetCurrentGamCod (Match->GamCod); // Used to pass parameter - Mch_SetCurrentMchCod (Match->MchCod); // Used to pass parameter + Games->GamCod = Match->GamCod; + Games->MchCod = Match->MchCod; /* Show match results */ Lay_PutContextualLinkOnlyIcon (ActSeeAllMchResMch,MchRes_RESULTS_BOX_ID, - Mch_PutParamsEdit,&Gbl, + Mch_PutParamsEdit,Games, "trophy.svg", Txt_Results); /* I can edit visibility */ Lay_PutContextualLinkOnlyIcon (ActChgVisResMchUsr,NULL, - Mch_PutParamsEdit,&Gbl, + Mch_PutParamsEdit,Games, Match->Status.ShowUsrResults ? "eye-green.svg" : "eye-slash-red.svg", Match->Status.ShowUsrResults ? Txt_Visible_results : @@ -834,11 +871,15 @@ static void Mch_ListOneOrMoreMatchesResultTch (const struct Match *Match) void Mch_ToggleVisibilResultsMchUsr (void) { - struct Game Game; - struct Match Match; + struct Gam_Games Games; + struct Gam_Game Game; + struct Mch_Match Match; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get and check parameters *****/ - Mch_GetAndCheckParameters (&Game,&Match); + Mch_GetAndCheckParameters (&Games,&Game,&Match); /***** Check if I have permission to change visibility *****/ if (!Mch_CheckIfICanEditThisMatch (&Match)) @@ -855,7 +896,7 @@ void Mch_ToggleVisibilResultsMchUsr (void) Match.MchCod); /***** Show current game *****/ - Gam_ShowOnlyOneGame (&Game, + Gam_ShowOnlyOneGame (&Games,&Game, false, // Do not list game questions false); // Do not put form to start new match } @@ -865,7 +906,7 @@ void Mch_ToggleVisibilResultsMchUsr (void) /*****************************************************************************/ static void Mch_GetMatchDataFromRow (MYSQL_RES *mysql_res, - struct Match *Match) + struct Mch_Match *Match) { MYSQL_ROW row; Dat_StartEndTime_t StartEndTime; @@ -972,23 +1013,27 @@ void Mch_RequestRemoveMatch (void) { extern const char *Txt_Do_you_really_want_to_remove_the_match_X; extern const char *Txt_Remove_match; - struct Game Game; - struct Match Match; + struct Gam_Games Games; + struct Gam_Game Game; + struct Mch_Match Match; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get and check parameters *****/ - Mch_GetAndCheckParameters (&Game,&Match); + Mch_GetAndCheckParameters (&Games,&Game,&Match); /***** Show question and button to remove question *****/ - Gam_SetCurrentGamCod (Match.GamCod); // Used to pass parameter - Mch_SetCurrentMchCod (Match.MchCod); // Used to pass parameter + Games.GamCod = Match.GamCod; + Games.MchCod = Match.MchCod; Ale_ShowAlertAndButton (ActRemMch,NULL,NULL, - Mch_PutParamsEdit,&Gbl, + Mch_PutParamsEdit,&Games, Btn_REMOVE_BUTTON,Txt_Remove_match, Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_match_X, Match.Title); /***** Show current game *****/ - Gam_ShowOnlyOneGame (&Game, + Gam_ShowOnlyOneGame (&Games,&Game, false, // Do not list game questions false); // Do not put form to start new match } @@ -1000,11 +1045,15 @@ void Mch_RequestRemoveMatch (void) void Mch_RemoveMatch (void) { extern const char *Txt_Match_X_removed; - struct Game Game; - struct Match Match; + struct Gam_Games Games; + struct Gam_Game Game; + struct Mch_Match Match; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get and check parameters *****/ - Mch_GetAndCheckParameters (&Game,&Match); + Mch_GetAndCheckParameters (&Games,&Game,&Match); /***** Check if I can remove this match *****/ if (!Mch_CheckIfICanEditThisMatch (&Match)) @@ -1018,7 +1067,7 @@ void Mch_RemoveMatch (void) Match.Title); /***** Show current game *****/ - Gam_ShowOnlyOneGame (&Game, + Gam_ShowOnlyOneGame (&Games,&Game, false, // Do not list game questions false); // Do not put form to start new match } @@ -1163,12 +1212,12 @@ static void Mch_RemoveUsrMchResultsInCrs (long UsrCod,long CrsCod,const char *Ta /*********************** Params used to edit a match *************************/ /*****************************************************************************/ -void Mch_PutParamsEdit (void *Args) +void Mch_PutParamsEdit (void *Games) { - if (Args) + if (Games) { - Gam_PutParams (&Gbl); - Mch_PutParamsPlay (&Gbl); + Gam_PutParams (Games); + Mch_PutParamMchCod (((struct Gam_Games *) Games)->MchCod); } } @@ -1176,15 +1225,12 @@ void Mch_PutParamsEdit (void *Args) /*********************** Params used to edit a match *************************/ /*****************************************************************************/ -static void Mch_PutParamsPlay (void *Args) +static void Mch_PutParamsPlay (void *MchCod) { - long CurrentMchCod; - - if (Args) + if (MchCod) { - CurrentMchCod = Mch_GetCurrentMchCod (); - if (CurrentMchCod > 0) - Mch_PutParamMchCod (CurrentMchCod); + if (*(long *) MchCod > 0) + Mch_PutParamMchCod (*(long *) MchCod); } } @@ -1201,17 +1247,19 @@ static void Mch_PutParamMchCod (long MchCod) /************************** Get and check parameters *************************/ /*****************************************************************************/ -void Mch_GetAndCheckParameters (struct Game *Game,struct Match *Match) +void Mch_GetAndCheckParameters (struct Gam_Games *Games, + struct Gam_Game *Game, + struct Mch_Match *Match) { /***** Get parameters *****/ /* Get parameters of game */ - if ((Game->GamCod = Gam_GetParams ()) == -1L) + if ((Game->GamCod = Gam_GetParams (Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); Grp_GetParamWhichGroups (); Gam_GetDataOfGameByCod (Game); /* Get match code */ - if ((Match->MchCod = Mch_GetParamMchCod ()) == -1L) + if ((Match->MchCod = Mch_GetParamMchCod ()) <= 0) Lay_ShowErrorAndExit ("Code of match is missing."); Mch_GetDataOfMatchByCod (Match); @@ -1236,7 +1284,7 @@ long Mch_GetParamMchCod (void) /****** Put a big button to play match (start a new match) as a teacher ******/ /*****************************************************************************/ -static void Mch_PutFormNewMatch (const struct Game *Game) +static void Mch_PutFormNewMatch (const struct Gam_Game *Game) { extern const char *Hlp_ASSESSMENT_Games_matches; extern const char *Txt_New_match; @@ -1372,7 +1420,7 @@ void Mch_CreateNewMatchTch (void) Grp_GetParCodsSeveralGrps (); /***** Create a new match *****/ - Gbl.Games.MchCodBeingPlayed = Mch_CreateMatch (GamCod,Title); + Mch_SetMchCodBeingPlayed (Mch_CreateMatch (GamCod,Title)); /***** Free memory for list of selected groups *****/ Grp_FreeListCodSelectedGrps (); @@ -1384,7 +1432,7 @@ void Mch_CreateNewMatchTch (void) void Mch_ResumeMatch (void) { - struct Match Match; + struct Mch_Match Match; /***** Remove old players. This function must be called by a teacher @@ -1392,7 +1440,7 @@ void Mch_ResumeMatch (void) Mch_RemoveOldPlayers (); /***** Get data of the match from database *****/ - Match.MchCod = Gbl.Games.MchCodBeingPlayed; + Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); /***** Check if I have permission to resume match *****/ @@ -1677,7 +1725,7 @@ void Mch_RemoveGroupsOfType (long GrpTypCod) /***************** Insert/update a game match being played *******************/ /*****************************************************************************/ -static void Mch_UpdateMatchStatusInDB (const struct Match *Match) +static void Mch_UpdateMatchStatusInDB (const struct Mch_Match *Match) { char *MchSubQuery; @@ -1727,7 +1775,7 @@ static void Mch_UpdateMatchStatusInDB (const struct Match *Match) /********** Update elapsed time in current question (by a teacher) ***********/ /*****************************************************************************/ -static void Mch_UpdateElapsedTimeInQuestion (const struct Match *Match) +static void Mch_UpdateElapsedTimeInQuestion (const struct Mch_Match *Match) { /***** Update elapsed time in current question in database *****/ if (Match->Status.Playing && // Match is being played @@ -1747,7 +1795,7 @@ static void Mch_UpdateElapsedTimeInQuestion (const struct Match *Match) /******************* Get elapsed time in a match question ********************/ /*****************************************************************************/ -static void Mch_GetElapsedTimeInQuestion (const struct Match *Match, +static void Mch_GetElapsedTimeInQuestion (const struct Mch_Match *Match, struct Time *Time) { MYSQL_RES *mysql_res; @@ -1771,7 +1819,7 @@ static void Mch_GetElapsedTimeInQuestion (const struct Match *Match, /*********************** Get elapsed time in a match *************************/ /*****************************************************************************/ -static void Mch_GetElapsedTimeInMatch (const struct Match *Match, +static void Mch_GetElapsedTimeInMatch (const struct Mch_Match *Match, struct Time *Time) { MYSQL_RES *mysql_res; @@ -1824,7 +1872,7 @@ static void Mch_GetElapsedTime (unsigned NumRows,MYSQL_RES *mysql_res, void Mch_PlayPauseMatch (void) { - struct Match Match; + struct Mch_Match Match; /***** Remove old players. This function must be called by a teacher @@ -1832,7 +1880,7 @@ void Mch_PlayPauseMatch (void) Mch_RemoveOldPlayers (); /***** Get data of the match from database *****/ - Match.MchCod = Gbl.Games.MchCodBeingPlayed; + Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); /***** Update status *****/ @@ -1858,7 +1906,7 @@ void Mch_PlayPauseMatch (void) void Mch_ChangeNumColsMch (void) { - struct Match Match; + struct Mch_Match Match; /***** Remove old players. This function must be called by a teacher @@ -1866,7 +1914,7 @@ void Mch_ChangeNumColsMch (void) Mch_RemoveOldPlayers (); /***** Get data of the match from database *****/ - Match.MchCod = Gbl.Games.MchCodBeingPlayed; + Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); /***** Get number of columns *****/ @@ -1891,7 +1939,7 @@ void Mch_ChangeNumColsMch (void) void Mch_ToggleVisibilResultsMchQst (void) { - struct Match Match; + struct Mch_Match Match; /***** Remove old players. This function must be called by a teacher @@ -1899,7 +1947,7 @@ void Mch_ToggleVisibilResultsMchQst (void) Mch_RemoveOldPlayers (); /***** Get data of the match from database *****/ - Match.MchCod = Gbl.Games.MchCodBeingPlayed; + Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); /***** Update status *****/ @@ -1923,7 +1971,7 @@ void Mch_ToggleVisibilResultsMchQst (void) void Mch_BackMatch (void) { - struct Match Match; + struct Mch_Match Match; /***** Remove old players. This function must be called by a teacher @@ -1931,7 +1979,7 @@ void Mch_BackMatch (void) Mch_RemoveOldPlayers (); /***** Get data of the match from database *****/ - Match.MchCod = Gbl.Games.MchCodBeingPlayed; + Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); /***** Update status *****/ @@ -1952,7 +2000,7 @@ void Mch_BackMatch (void) void Mch_ForwardMatch (void) { - struct Match Match; + struct Mch_Match Match; /***** Remove old players. This function must be called by a teacher @@ -1960,7 +2008,7 @@ void Mch_ForwardMatch (void) Mch_RemoveOldPlayers (); /***** Get data of the match from database *****/ - Match.MchCod = Gbl.Games.MchCodBeingPlayed; + Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); /***** Update status *****/ @@ -1979,7 +2027,7 @@ void Mch_ForwardMatch (void) /************** Set match status to previous (backward) status ***************/ /*****************************************************************************/ -static void Mch_SetMatchStatusToPrev (struct Match *Match) +static void Mch_SetMatchStatusToPrev (struct Mch_Match *Match) { /***** What to show *****/ switch (Match->Status.Showing) @@ -2005,7 +2053,7 @@ static void Mch_SetMatchStatusToPrev (struct Match *Match) /****************** Set match status to previous question ********************/ /*****************************************************************************/ -static void Mch_SetMatchStatusToPrevQst (struct Match *Match) +static void Mch_SetMatchStatusToPrevQst (struct Mch_Match *Match) { /***** Get index of the previous question *****/ Match->Status.QstInd = Gam_GetPrevQuestionIndexInGame (Match->GamCod, @@ -2025,7 +2073,7 @@ static void Mch_SetMatchStatusToPrevQst (struct Match *Match) /************************ Set match status to start **************************/ /*****************************************************************************/ -static void Mch_SetMatchStatusToStart (struct Match *Match) +static void Mch_SetMatchStatusToStart (struct Mch_Match *Match) { Match->Status.QstInd = 0; // Before first question Match->Status.QstCod = -1L; @@ -2037,7 +2085,7 @@ static void Mch_SetMatchStatusToStart (struct Match *Match) /**************** Set match status to next (forward) status ******************/ /*****************************************************************************/ -static void Mch_SetMatchStatusToNext (struct Match *Match) +static void Mch_SetMatchStatusToNext (struct Mch_Match *Match) { /***** What to show *****/ switch (Match->Status.Showing) @@ -2068,7 +2116,7 @@ static void Mch_SetMatchStatusToNext (struct Match *Match) /****************** Set match status to next question ************************/ /*****************************************************************************/ -static void Mch_SetMatchStatusToNextQst (struct Match *Match) +static void Mch_SetMatchStatusToNextQst (struct Mch_Match *Match) { /***** Get index of the next question *****/ Match->Status.QstInd = Gam_GetNextQuestionIndexInGame (Match->GamCod, @@ -2089,7 +2137,7 @@ static void Mch_SetMatchStatusToNextQst (struct Match *Match) /************************* Set match status to end ***************************/ /*****************************************************************************/ -static void Mch_SetMatchStatusToEnd (struct Match *Match) +static void Mch_SetMatchStatusToEnd (struct Mch_Match *Match) { Match->Status.QstInd = Mch_AFTER_LAST_QUESTION; // After last question Match->Status.QstCod = -1L; @@ -2101,7 +2149,7 @@ static void Mch_SetMatchStatusToEnd (struct Match *Match) /******* Show current match status (number, question, answers, button) *******/ /*****************************************************************************/ -static void Mch_ShowMatchStatusForTch (struct Match *Match) +static void Mch_ShowMatchStatusForTch (struct Mch_Match *Match) { /***** Left column *****/ Mch_ShowLeftColumnTch (Match); @@ -2114,7 +2162,7 @@ static void Mch_ShowMatchStatusForTch (struct Match *Match) /************ Show current question being played for a student ***************/ /*****************************************************************************/ -static void Mch_ShowMatchStatusForStd (struct Match *Match,Mch_Update_t Update) +static void Mch_ShowMatchStatusForStd (struct Mch_Match *Match,Mch_Update_t Update) { bool ICanPlayThisMatchBasedOnGrps; struct Mch_UsrAnswer UsrAnswer; @@ -2178,7 +2226,7 @@ unsigned Mch_GetNumUnfinishedMchsInGame (long GamCod) /************ Check if I belong to any of the groups of a match **************/ /*****************************************************************************/ -bool Mch_CheckIfICanPlayThisMatchBasedOnGrps (const struct Match *Match) +bool Mch_CheckIfICanPlayThisMatchBasedOnGrps (const struct Mch_Match *Match) { switch (Gbl.Usrs.Me.Role.Logged) { @@ -2214,7 +2262,7 @@ bool Mch_CheckIfICanPlayThisMatchBasedOnGrps (const struct Match *Match) /*********** Show left column when playing a match (as a teacher) ************/ /*****************************************************************************/ -static void Mch_ShowLeftColumnTch (struct Match *Match) +static void Mch_ShowLeftColumnTch (struct Mch_Match *Match) { /***** Start left container *****/ HTM_DIV_Begin ("class=\"MCH_LEFT_TCH\""); @@ -2246,7 +2294,7 @@ static void Mch_ShowLeftColumnTch (struct Match *Match) /***************** Show left refreshable part for teachers *******************/ /*****************************************************************************/ -static void Mch_ShowRefreshablePartTch (struct Match *Match) +static void Mch_ShowRefreshablePartTch (struct Mch_Match *Match) { /***** Write elapsed time in match *****/ Mch_WriteElapsedTimeInMch (Match); @@ -2268,7 +2316,7 @@ static void Mch_ShowRefreshablePartTch (struct Match *Match) /******************** Write elapsed time in current match ********************/ /*****************************************************************************/ -static void Mch_WriteElapsedTimeInMch (struct Match *Match) +static void Mch_WriteElapsedTimeInMch (struct Mch_Match *Match) { struct Time Time; @@ -2287,7 +2335,7 @@ static void Mch_WriteElapsedTimeInMch (struct Match *Match) /****************** Write elapsed time in current question *******************/ /*****************************************************************************/ -static void Mch_WriteElapsedTimeInQst (struct Match *Match) +static void Mch_WriteElapsedTimeInQst (struct Mch_Match *Match) { struct Time Time; @@ -2312,7 +2360,7 @@ static void Mch_WriteElapsedTimeInQst (struct Match *Match) /*************** Write number of responders to a match question **************/ /*****************************************************************************/ -static void Mch_WriteNumRespondersQst (struct Match *Match) +static void Mch_WriteNumRespondersQst (struct Mch_Match *Match) { extern const char *Txt_MATCH_respond; @@ -2354,7 +2402,7 @@ static void Mch_WriteNumRespondersQst (struct Match *Match) /*************** Write current countdown and hourglass icon ******************/ /*****************************************************************************/ -static void Mch_PutCountdownAndHourglassIcon (struct Match *Match) +static void Mch_PutCountdownAndHourglassIcon (struct Mch_Match *Match) { extern const char *Txt_Countdown; const char *Class; @@ -2411,7 +2459,7 @@ static void Mch_PutCountdownAndHourglassIcon (struct Match *Match) /******************** Put all forms to start countdowns **********************/ /*****************************************************************************/ -static void Mch_PutFormsCountdown (struct Match *Match) +static void Mch_PutFormsCountdown (struct Mch_Match *Match) { /***** Start container *****/ HTM_DIV_Begin ("class=\"MCH_SHOW_HOURGLASS\""); @@ -2430,7 +2478,7 @@ static void Mch_PutFormsCountdown (struct Match *Match) /****** Put a form to start a countdown with a given number of seconds *******/ /*****************************************************************************/ -static void Mch_PutFormCountdown (struct Match *Match,long Seconds,const char *Color) +static void Mch_PutFormCountdown (struct Mch_Match *Match,long Seconds,const char *Color) { extern const char *Txt_Countdown; char *OnSubmit; @@ -2488,7 +2536,7 @@ static void Mch_PutFormCountdown (struct Match *Match,long Seconds,const char *C /********** Show right column when playing a match (as a teacher) ************/ /*****************************************************************************/ -static void Mch_ShowRightColumnTch (const struct Match *Match) +static void Mch_ShowRightColumnTch (const struct Mch_Match *Match) { /***** Start right container *****/ HTM_DIV_Begin ("class=\"MCH_RIGHT_TCH\""); @@ -2510,7 +2558,7 @@ static void Mch_ShowRightColumnTch (const struct Match *Match) /*********** Show left column when playing a match (as a student) ************/ /*****************************************************************************/ -static void Mch_ShowLeftColumnStd (const struct Match *Match, +static void Mch_ShowLeftColumnStd (const struct Mch_Match *Match, const struct Mch_UsrAnswer *UsrAnswer) { bool Answered = UsrAnswer->NumOpt >= 0; @@ -2550,7 +2598,7 @@ static void Mch_ShowLeftColumnStd (const struct Match *Match, /********** Show right column when playing a match (as a student) ************/ /*****************************************************************************/ -static void Mch_ShowRightColumnStd (struct Match *Match, +static void Mch_ShowRightColumnStd (struct Mch_Match *Match, const struct Mch_UsrAnswer *UsrAnswer, Mch_Update_t Update) { @@ -2596,7 +2644,7 @@ static void Mch_ShowRightColumnStd (struct Match *Match, /********************* Show number of question in game ***********************/ /*****************************************************************************/ -static void Mch_ShowNumQstInMch (const struct Match *Match) +static void Mch_ShowNumQstInMch (const struct Mch_Match *Match) { extern const char *Txt_MATCH_Start; extern const char *Txt_MATCH_End; @@ -2622,7 +2670,7 @@ static void Mch_ShowNumQstInMch (const struct Match *Match) /********************** Put buttons to control a match ***********************/ /*****************************************************************************/ -static void Mch_PutMatchControlButtons (const struct Match *Match) +static void Mch_PutMatchControlButtons (const struct Mch_Match *Match) { extern const char *Txt_Go_back; extern const char *Txt_Go_forward; @@ -2695,7 +2743,7 @@ static void Mch_PutMatchControlButtons (const struct Match *Match) /** Show form to choice whether to show answers in one column or two columns */ /*****************************************************************************/ -static void Mch_ShowFormColumns (const struct Match *Match) +static void Mch_ShowFormColumns (const struct Mch_Match *Match) { extern const char *Txt_column; extern const char *Txt_columns; @@ -2757,7 +2805,7 @@ static void Mch_PutParamNumCols (unsigned NumCols) // Number of columns /***************** Put checkbox to select if show results ********************/ /*****************************************************************************/ -static void Mch_PutCheckboxResult (const struct Match *Match) +static void Mch_PutCheckboxResult (const struct Mch_Match *Match) { extern const char *Txt_View_results; @@ -2787,7 +2835,7 @@ static void Mch_PutCheckboxResult (const struct Match *Match) /***************** Put checkbox to select if show results ********************/ /*****************************************************************************/ -static void Mch_PutIfAnswered (const struct Match *Match,bool Answered) +static void Mch_PutIfAnswered (const struct Mch_Match *Match,bool Answered) { extern const char *Txt_View_my_answer; extern const char *Txt_MATCH_QUESTION_Answered; @@ -2835,7 +2883,7 @@ static void Mch_PutIfAnswered (const struct Match *Match,bool Answered) /***************** Put checkbox to select if show results ********************/ /*****************************************************************************/ -static void Mch_PutIconToRemoveMyAnswer (const struct Match *Match) +static void Mch_PutIconToRemoveMyAnswer (const struct Mch_Match *Match) { extern const char *Txt_Delete_my_answer; @@ -2865,7 +2913,7 @@ static void Mch_PutIconToRemoveMyAnswer (const struct Match *Match) /***************************** Show match title ******************************/ /*****************************************************************************/ -static void Mch_ShowMatchTitleTch (const struct Match *Match) +static void Mch_ShowMatchTitleTch (const struct Mch_Match *Match) { /***** Match title *****/ HTM_DIV_Begin ("class=\"MCH_TOP LT\""); @@ -2873,7 +2921,7 @@ static void Mch_ShowMatchTitleTch (const struct Match *Match) HTM_DIV_End (); } -static void Mch_ShowMatchTitleStd (const struct Match *Match) +static void Mch_ShowMatchTitleStd (const struct Mch_Match *Match) { /***** Match title *****/ HTM_DIV_Begin ("class=\"MCH_TOP CT\""); @@ -2885,7 +2933,7 @@ static void Mch_ShowMatchTitleStd (const struct Match *Match) /***** Show question and its answers when playing a match (as a teacher) *****/ /*****************************************************************************/ -static void Mch_ShowQuestionAndAnswersTch (const struct Match *Match) +static void Mch_ShowQuestionAndAnswersTch (const struct Mch_Match *Match) { extern const char *Txt_MATCH_Paused; extern const char *Txt_Question_removed; @@ -2964,7 +3012,7 @@ static void Mch_ShowQuestionAndAnswersTch (const struct Match *Match) /************* Write answers of a question when seeing a match ***************/ /*****************************************************************************/ -static void Mch_WriteAnswersMatchResult (const struct Match *Match, +static void Mch_WriteAnswersMatchResult (const struct Mch_Match *Match, const struct Tst_Question *Question, const char *Class,bool ShowResult) { @@ -2981,7 +3029,7 @@ static void Mch_WriteAnswersMatchResult (const struct Match *Match, /******** Write single or multiple choice answer when seeing a match *********/ /*****************************************************************************/ -void Mch_WriteChoiceAnsViewMatch (const struct Match *Match, +void Mch_WriteChoiceAnsViewMatch (const struct Mch_Match *Match, const struct Tst_Question *Question, const char *Class,bool ShowResult) { @@ -3073,7 +3121,7 @@ void Mch_WriteChoiceAnsViewMatch (const struct Match *Match, /*****************************************************************************/ // Return true on valid question, false on invalid question -static bool Mch_ShowQuestionAndAnswersStd (const struct Match *Match, +static bool Mch_ShowQuestionAndAnswersStd (const struct Mch_Match *Match, const struct Mch_UsrAnswer *UsrAnswer, Mch_Update_t Update) { @@ -3143,7 +3191,7 @@ static bool Mch_ShowQuestionAndAnswersStd (const struct Match *Match, #define Mch_NUM_ROWS_SCORE 50 -static void Mch_ShowMatchScore (const struct Match *Match) +static void Mch_ShowMatchScore (const struct Mch_Match *Match) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -3520,7 +3568,7 @@ static bool Mch_GetIfMatchIsBeingPlayed (long MchCod) /*************************** Get number of players ***************************/ /*****************************************************************************/ -static void Mch_GetNumPlayers (struct Match *Match) +static void Mch_GetNumPlayers (struct Mch_Match *Match) { /***** Get number of players who are playing a match *****/ Match->Status.NumPlayers = @@ -3535,7 +3583,7 @@ static void Mch_GetNumPlayers (struct Match *Match) /*****************************************************************************/ // Return true on success -bool Mch_RegisterMeAsPlayerInMatch (struct Match *Match) +bool Mch_RegisterMeAsPlayerInMatch (struct Mch_Match *Match) { /***** Trivial check: match code must be > 0 *****/ if (Match->MchCod <= 0) @@ -3566,9 +3614,13 @@ bool Mch_RegisterMeAsPlayerInMatch (struct Match *Match) void Mch_GetMatchBeingPlayed (void) { + long MchCodBeingPlayed; + /***** Get match code ****/ - if ((Gbl.Games.MchCodBeingPlayed = Mch_GetParamMchCod ()) == -1L) + if ((MchCodBeingPlayed = Mch_GetParamMchCod ()) <= 0) Lay_ShowErrorAndExit ("Code of match is missing."); + + Mch_SetMchCodBeingPlayed (MchCodBeingPlayed); } /*****************************************************************************/ @@ -3577,10 +3629,10 @@ void Mch_GetMatchBeingPlayed (void) void Mch_JoinMatchAsStd (void) { - struct Match Match; + struct Mch_Match Match; /***** Get data of the match from database *****/ - Match.MchCod = Gbl.Games.MchCodBeingPlayed; + Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); /***** Show current match status *****/ @@ -3595,11 +3647,11 @@ void Mch_JoinMatchAsStd (void) void Mch_RemoveMyQuestionAnswer (void) { - struct Match Match; + struct Mch_Match Match; unsigned QstInd; /***** Get data of the match from database *****/ - Match.MchCod = Gbl.Games.MchCodBeingPlayed; + Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); /***** Get question index from form *****/ @@ -3625,7 +3677,7 @@ void Mch_RemoveMyQuestionAnswer (void) void Mch_StartCountdown (void) { - struct Match Match; + struct Mch_Match Match; long NewCountdown; /***** Get countdown parameter ****/ @@ -3637,7 +3689,7 @@ void Mch_StartCountdown (void) Mch_RemoveOldPlayers (); /***** Get data of the match from database *****/ - Match.MchCod = Gbl.Games.MchCodBeingPlayed; + Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); /***** Start countdown *****/ @@ -3656,7 +3708,7 @@ void Mch_StartCountdown (void) void Mch_RefreshMatchTch (void) { - struct Match Match; + struct Mch_Match Match; enum {REFRESH_LEFT,REFRESH_ALL} WhatToRefresh; if (!Gbl.Session.IsOpen) // If session has been closed, do not write anything @@ -3668,7 +3720,7 @@ void Mch_RefreshMatchTch (void) Mch_RemoveOldPlayers (); /***** Get data of the match from database *****/ - Match.MchCod = Gbl.Games.MchCodBeingPlayed; + Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); /***** Update countdown *****/ @@ -3714,13 +3766,13 @@ void Mch_RefreshMatchTch (void) void Mch_RefreshMatchStd (void) { - struct Match Match; + struct Mch_Match Match; if (!Gbl.Session.IsOpen) // If session has been closed, do not write anything return; /***** Get data of the match from database *****/ - Match.MchCod = Gbl.Games.MchCodBeingPlayed; + Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); /***** Show current match status *****/ @@ -3774,7 +3826,7 @@ void Mch_GetQstAnsFromDB (long MchCod,long UsrCod,unsigned QstInd, void Mch_ReceiveQuestionAnswer (void) { - struct Match Match; + struct Mch_Match Match; unsigned QstInd; unsigned Indexes[Tst_MAX_OPTIONS_PER_QUESTION]; struct Mch_UsrAnswer PreviousUsrAnswer; @@ -3782,7 +3834,7 @@ void Mch_ReceiveQuestionAnswer (void) struct TstExa_Exam Result; /***** Get data of the match from database *****/ - Match.MchCod = Gbl.Games.MchCodBeingPlayed; + Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); /***** Get question index from form *****/ @@ -3885,7 +3937,7 @@ void Mch_ReceiveQuestionAnswer (void) /********************* Remove answer to match question ***********************/ /*****************************************************************************/ -static void Mch_RemoveMyAnswerToMatchQuestion (const struct Match *Match) +static void Mch_RemoveMyAnswerToMatchQuestion (const struct Mch_Match *Match) { DB_QueryDELETE ("can not remove your answer to the match question", "DELETE FROM mch_answers" @@ -4015,17 +4067,3 @@ void Mch_DrawBarNumUsrs (unsigned NumRespondersAns,unsigned NumRespondersQst,boo /***** End container *****/ HTM_DIV_End (); } - -/*****************************************************************************/ -/**************** Access to variable used to pass parameter ******************/ -/*****************************************************************************/ - -void Mch_SetCurrentMchCod (long MchCod) - { - Mch_CurrentMchCod = MchCod; - } - -static long Mch_GetCurrentMchCod (void) - { - return Mch_CurrentMchCod; - } diff --git a/swad_match.h b/swad_match.h index 58d91c6a..a5e739d3 100644 --- a/swad_match.h +++ b/swad_match.h @@ -48,7 +48,7 @@ typedef enum } Mch_Showing_t; #define Mch_SHOWING_DEFAULT Mch_START -struct Match +struct Mch_Match { long MchCod; long GamCod; @@ -82,8 +82,12 @@ struct Mch_UsrAnswer /***************************** Public prototypes *****************************/ /*****************************************************************************/ -void Mch_ListMatches (struct Game *Game,bool PutFormNewMatch); -void Mch_GetDataOfMatchByCod (struct Match *Match); +long Mch_GetMchCodBeingPlayed (void); + +void Mch_ListMatches (struct Gam_Games *Games, + struct Gam_Game *Game, + bool PutFormNewMatch); +void Mch_GetDataOfMatchByCod (struct Mch_Match *Match); void Mch_ToggleVisibilResultsMchUsr (void); @@ -94,8 +98,10 @@ void Mch_RemoveMatchesInGameFromAllTables (long GamCod); void Mch_RemoveMatchInCourseFromAllTables (long CrsCod); void Mch_RemoveUsrFromMatchTablesInCrs (long UsrCod,long CrsCod); -void Mch_PutParamsEdit (void *Args); -void Mch_GetAndCheckParameters (struct Game *Game,struct Match *Match); +void Mch_PutParamsEdit (void *Games); +void Mch_GetAndCheckParameters (struct Gam_Games *Games, + struct Gam_Game *Game, + struct Mch_Match *Match); long Mch_GetParamMchCod (void); void Mch_CreateNewMatchTch (void); @@ -115,13 +121,13 @@ void Mch_ForwardMatch (void); unsigned Mch_GetNumMchsInGame (long GamCod); unsigned Mch_GetNumUnfinishedMchsInGame (long GamCod); -bool Mch_CheckIfICanPlayThisMatchBasedOnGrps (const struct Match *Match); +bool Mch_CheckIfICanPlayThisMatchBasedOnGrps (const struct Mch_Match *Match); -void Mch_WriteChoiceAnsViewMatch (const struct Match *Match, +void Mch_WriteChoiceAnsViewMatch (const struct Mch_Match *Match, const struct Tst_Question *Question, const char *Class,bool ShowResult); -bool Mch_RegisterMeAsPlayerInMatch (struct Match *Match); +bool Mch_RegisterMeAsPlayerInMatch (struct Mch_Match *Match); void Mch_GetMatchBeingPlayed (void); void Mch_JoinMatchAsStd (void); @@ -139,6 +145,4 @@ unsigned Mch_GetNumUsrsWhoAnsweredQst (long MchCod,unsigned QstInd); unsigned Mch_GetNumUsrsWhoHaveChosenAns (long MchCod,unsigned QstInd,unsigned AnsInd); void Mch_DrawBarNumUsrs (unsigned NumRespondersAns,unsigned NumRespondersQst,bool Correct); -void Mch_SetCurrentMchCod (long MchCod); - #endif diff --git a/swad_match_result.c b/swad_match_result.c index b146e977..776e29e9 100644 --- a/swad_match_result.c +++ b/swad_match_result.c @@ -70,56 +70,41 @@ extern struct Globals Gbl; /***************************** Private prototypes ****************************/ /*****************************************************************************/ -static void MchRes_ListMyMchResultsInCrs (void); -static void MchRes_ListMyMchResultsInGam (long GamCod); -static void MchRes_ListMyMchResultsInMch (long MchCod); -static void MchRes_ShowAllMchResultsInSelectedGames (void *Args); -static void MchRes_ListAllMchResultsInSelectedGames (void); -static void MchRes_ListAllMchResultsInGam (long GamCod); -static void MchRes_ListAllMchResultsInMch (long MchCod); +static void MchRes_PutFormToSelUsrsToViewMchResults (void *Games); -static void MchRes_ShowResultsBegin (const char *Title,bool ListGamesToSelect); +static void MchRes_ListMyMchResultsInCrs (struct Gam_Games *Games); +static void MchRes_ListMyMchResultsInGam (struct Gam_Games *Games,long GamCod); +static void MchRes_ListMyMchResultsInMch (struct Gam_Games *Games,long MchCod); +static void MchRes_ShowAllMchResultsInSelectedGames (void *Games); +static void MchRes_ListAllMchResultsInSelectedGames (struct Gam_Games *Games); +static void MchRes_ListAllMchResultsInGam (struct Gam_Games *Games,long GamCod); +static void MchRes_ListAllMchResultsInMch (struct Gam_Games *Games,long MchCod); + +static void MchRes_ShowResultsBegin (struct Gam_Games *Games, + const char *Title,bool ListGamesToSelect); static void MchRes_ShowResultsEnd (void); -static void MchRes_ListGamesToSelect (void); +static void MchRes_ListGamesToSelect (struct Gam_Games *Games); static void MchRes_ShowHeaderMchResults (Usr_MeOrOther_t MeOrOther); -static void MchRes_BuildGamesSelectedCommas (char **GamesSelectedCommas); -static void MchRes_ShowMchResults (Usr_MeOrOther_t MeOrOther, - long MchCod, // <= 0 ==> any - long GamCod, // <= 0 ==> any - const char *GamesSelectedCommas); +static void MchRes_BuildGamesSelectedCommas (struct Gam_Games *Games, + char **GamesSelectedCommas); +static void MchRes_ShowMchResults (struct Gam_Games *Games, + Usr_MeOrOther_t MeOrOther, + long MchCod, // <= 0 ==> any + long GamCod, // <= 0 ==> any + const char *GamesSelectedCommas); static void MchRes_ShowMchResultsSummaryRow (unsigned NumResults, - unsigned NumTotalQsts, - unsigned NumTotalQstsNotBlank, - double TotalScoreOfAllResults, - double TotalGrade); + unsigned NumTotalQsts, + unsigned NumTotalQstsNotBlank, + double TotalScoreOfAllResults, + double TotalGrade); static void MchRes_GetMatchResultDataByMchCod (long MchCod,long UsrCod, struct TstExa_Exam *Exam); -static bool MchRes_CheckIfICanSeeMatchResult (struct Match *Match,long UsrCod); +static bool MchRes_CheckIfICanSeeMatchResult (struct Mch_Match *Match,long UsrCod); static bool MchRes_CheckIfICanViewScore (bool ICanViewResult,unsigned Visibility); -/*****************************************************************************/ -/*********** Select users and dates to show their matches results ************/ -/*****************************************************************************/ - -void MchRes_SelUsrsToViewMchResults (void *Args) - { - extern const char *Hlp_ASSESSMENT_Games_results; - extern const char *Txt_Results; - extern const char *Txt_View_matches_results; - - if (Args) - Usr_PutFormToSelectUsrsToGoToAct (&Gbl.Usrs.Selected, - ActSeeAllMchResCrs, - NULL,NULL, - Txt_Results, - Hlp_ASSESSMENT_Games_results, - Txt_View_matches_results, - false); // Do not put form with date range - } - /*****************************************************************************/ /*************************** Show my matches results *************************/ /*****************************************************************************/ @@ -127,22 +112,26 @@ void MchRes_SelUsrsToViewMchResults (void *Args) void MchRes_ShowMyMchResultsInCrs (void) { extern const char *Txt_Results; + struct Gam_Games Games; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get list of games *****/ - Gam_GetListGames (Gam_ORDER_BY_TITLE); - Gam_GetListSelectedGamCods (); + Gam_GetListGames (&Games,Gam_ORDER_BY_TITLE); + Gam_GetListSelectedGamCods (&Games); /***** List my matches results in the current course *****/ - MchRes_ShowResultsBegin (Txt_Results,true); // List games to select - MchRes_ListMyMchResultsInCrs (); + MchRes_ShowResultsBegin (&Games,Txt_Results,true); // List games to select + MchRes_ListMyMchResultsInCrs (&Games); MchRes_ShowResultsEnd (); /***** Free list of games *****/ - free (Gbl.Games.GamCodsSelected); - Gam_FreeListGames (); + free (Games.GamCodsSelected); + Gam_FreeListGames (&Games); } -static void MchRes_ListMyMchResultsInCrs (void) +static void MchRes_ListMyMchResultsInCrs (struct Gam_Games *Games) { char *GamesSelectedCommas = NULL; // Initialized to avoid warning @@ -151,8 +140,8 @@ static void MchRes_ListMyMchResultsInCrs (void) /***** List my matches results in the current course *****/ TstCfg_GetConfigFromDB (); // Get feedback type - MchRes_BuildGamesSelectedCommas (&GamesSelectedCommas); - MchRes_ShowMchResults (Usr_ME,-1L,-1L,GamesSelectedCommas); + MchRes_BuildGamesSelectedCommas (Games,&GamesSelectedCommas); + MchRes_ShowMchResults (Games,Usr_ME,-1L,-1L,GamesSelectedCommas); free (GamesSelectedCommas); } @@ -163,37 +152,42 @@ static void MchRes_ListMyMchResultsInCrs (void) void MchRes_ShowMyMchResultsInGam (void) { extern const char *Txt_Results_of_game_X; - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); Gam_GetDataOfGameByCod (&Game); /***** Game begin *****/ - Gam_ShowOnlyOneGameBegin (&Game, + Gam_ShowOnlyOneGameBegin (&Games,&Game, false, // Do not list game questions false); // Do not put form to start new match /***** List my matches results in game *****/ - MchRes_ShowResultsBegin (Str_BuildStringStr (Txt_Results_of_game_X,Game.Title), - false); // Do not list games to select + MchRes_ShowResultsBegin (&Games, + Str_BuildStringStr (Txt_Results_of_game_X,Game.Title), + false); // Do not list games to select Str_FreeString (); - MchRes_ListMyMchResultsInGam (Game.GamCod); + MchRes_ListMyMchResultsInGam (&Games,Game.GamCod); MchRes_ShowResultsEnd (); /***** Game end *****/ Gam_ShowOnlyOneGameEnd (); } -static void MchRes_ListMyMchResultsInGam (long GamCod) +static void MchRes_ListMyMchResultsInGam (struct Gam_Games *Games,long GamCod) { /***** Table header *****/ MchRes_ShowHeaderMchResults (Usr_ME); /***** List my matches results in game *****/ TstCfg_GetConfigFromDB (); // Get feedback type - MchRes_ShowMchResults (Usr_ME,-1L,GamCod,NULL); + MchRes_ShowMchResults (Games,Usr_ME,-1L,GamCod,NULL); } /*****************************************************************************/ @@ -203,41 +197,45 @@ static void MchRes_ListMyMchResultsInGam (long GamCod) void MchRes_ShowMyMchResultsInMch (void) { extern const char *Txt_Results_of_match_X; - struct Game Game; - struct Match Match; + struct Gam_Games Games; + struct Gam_Game Game; + struct Mch_Match Match; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); - if ((Match.MchCod = Mch_GetParamMchCod ()) == -1L) + if ((Match.MchCod = Mch_GetParamMchCod ()) <= 0) Lay_ShowErrorAndExit ("Code of match is missing."); Gam_GetDataOfGameByCod (&Game); Mch_GetDataOfMatchByCod (&Match); /***** Game begin *****/ - Gam_ShowOnlyOneGameBegin (&Game, + Gam_ShowOnlyOneGameBegin (&Games,&Game, false, // Do not list game questions false); // Do not put form to start new match /***** List my matches results in match *****/ - MchRes_ShowResultsBegin (Str_BuildStringStr (Txt_Results_of_match_X,Match.Title), - false); // Do not list games to select + MchRes_ShowResultsBegin (&Games,Str_BuildStringStr (Txt_Results_of_match_X,Match.Title), + false); // Do not list games to select Str_FreeString (); - MchRes_ListMyMchResultsInMch (Match.MchCod); + MchRes_ListMyMchResultsInMch (&Games,Match.MchCod); MchRes_ShowResultsEnd (); /***** Game end *****/ Gam_ShowOnlyOneGameEnd (); } -static void MchRes_ListMyMchResultsInMch (long MchCod) +static void MchRes_ListMyMchResultsInMch (struct Gam_Games *Games,long MchCod) { /***** Table header *****/ MchRes_ShowHeaderMchResults (Usr_ME); /***** List my matches results in game *****/ TstCfg_GetConfigFromDB (); // Get feedback type - MchRes_ShowMchResults (Usr_ME,MchCod,-1L,NULL); + MchRes_ShowMchResults (Games,Usr_ME,MchCod,-1L,NULL); } /*****************************************************************************/ @@ -246,37 +244,45 @@ static void MchRes_ListMyMchResultsInMch (long MchCod) void MchRes_ShowAllMchResultsInCrs (void) { + struct Gam_Games Games; + + /***** Reset games *****/ + Gam_ResetGames (&Games); + + /***** Get users and show their matches results *****/ Usr_GetSelectedUsrsAndGoToAct (&Gbl.Usrs.Selected, - MchRes_ShowAllMchResultsInSelectedGames,&Gbl, - MchRes_SelUsrsToViewMchResults,&Gbl); + MchRes_ShowAllMchResultsInSelectedGames,&Games, + MchRes_PutFormToSelUsrsToViewMchResults,&Games); } /*****************************************************************************/ /****************** Show matches results for several users *******************/ /*****************************************************************************/ -static void MchRes_ShowAllMchResultsInSelectedGames (void *Args) +static void MchRes_ShowAllMchResultsInSelectedGames (void *Games) { extern const char *Txt_Results; - if (!Args) + if (!Games) return; /***** Get list of games *****/ - Gam_GetListGames (Gam_ORDER_BY_TITLE); - Gam_GetListSelectedGamCods (); + Gam_GetListGames ((struct Gam_Games *) Games,Gam_ORDER_BY_TITLE); + Gam_GetListSelectedGamCods ((struct Gam_Games *) Games); /***** List the matches results of the selected users *****/ - MchRes_ShowResultsBegin (Txt_Results,true); // List games to select - MchRes_ListAllMchResultsInSelectedGames (); + MchRes_ShowResultsBegin ((struct Gam_Games *) Games, + Txt_Results, + true); // List games to select + MchRes_ListAllMchResultsInSelectedGames ((struct Gam_Games *) Games); MchRes_ShowResultsEnd (); /***** Free list of games *****/ - free (Gbl.Games.GamCodsSelected); - Gam_FreeListGames (); + free (((struct Gam_Games *) Games)->GamCodsSelected); + Gam_FreeListGames ((struct Gam_Games *) Games); } -static void MchRes_ListAllMchResultsInSelectedGames (void) +static void MchRes_ListAllMchResultsInSelectedGames (struct Gam_Games *Games) { char *GamesSelectedCommas = NULL; // Initialized to avoid warning const char *Ptr; @@ -285,7 +291,7 @@ static void MchRes_ListAllMchResultsInSelectedGames (void) MchRes_ShowHeaderMchResults (Usr_OTHER); /***** List the matches results of the selected users *****/ - MchRes_BuildGamesSelectedCommas (&GamesSelectedCommas); + MchRes_BuildGamesSelectedCommas (Games,&GamesSelectedCommas); Ptr = Gbl.Usrs.Selected.List[Rol_UNK]; while (*Ptr) { @@ -297,12 +303,43 @@ static void MchRes_ListAllMchResultsInSelectedGames (void) { /***** Show matches results *****/ Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat); - MchRes_ShowMchResults (Usr_OTHER,-1L,-1L,GamesSelectedCommas); + MchRes_ShowMchResults (Games,Usr_OTHER,-1L,-1L,GamesSelectedCommas); } } free (GamesSelectedCommas); } +/*****************************************************************************/ +/**************** Select users to show their matches results *****************/ +/*****************************************************************************/ + +void MchRes_SelUsrsToViewMchResults (void) + { + struct Gam_Games Games; + + /***** Reset games *****/ + Gam_ResetGames (&Games); + + /***** Put form to select users *****/ + MchRes_PutFormToSelUsrsToViewMchResults (&Games); + } + +static void MchRes_PutFormToSelUsrsToViewMchResults (void *Games) + { + extern const char *Hlp_ASSESSMENT_Games_results; + extern const char *Txt_Results; + extern const char *Txt_View_matches_results; + + if (Games) // Not used + Usr_PutFormToSelectUsrsToGoToAct (&Gbl.Usrs.Selected, + ActSeeAllMchResCrs, + NULL,NULL, + Txt_Results, + Hlp_ASSESSMENT_Games_results, + Txt_View_matches_results, + false); // Do not put form with date range + } + /*****************************************************************************/ /*** Show matches results of a game for the users who answered in that game **/ /*****************************************************************************/ @@ -310,30 +347,35 @@ static void MchRes_ListAllMchResultsInSelectedGames (void) void MchRes_ShowAllMchResultsInGam (void) { extern const char *Txt_Results_of_game_X; - struct Game Game; + struct Gam_Games Games; + struct Gam_Game Game; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); Gam_GetDataOfGameByCod (&Game); /***** Game begin *****/ - Gam_ShowOnlyOneGameBegin (&Game, + Gam_ShowOnlyOneGameBegin (&Games,&Game, false, // Do not list game questions false); // Do not put form to start new match /***** List matches results in game *****/ - MchRes_ShowResultsBegin (Str_BuildStringStr (Txt_Results_of_game_X,Game.Title), - false); // Do not list games to select + MchRes_ShowResultsBegin (&Games, + Str_BuildStringStr (Txt_Results_of_game_X,Game.Title), + false); // Do not list games to select Str_FreeString (); - MchRes_ListAllMchResultsInGam (Game.GamCod); + MchRes_ListAllMchResultsInGam (&Games,Game.GamCod); MchRes_ShowResultsEnd (); /***** Game end *****/ Gam_ShowOnlyOneGameEnd (); } -static void MchRes_ListAllMchResultsInGam (long GamCod) +static void MchRes_ListAllMchResultsInGam (struct Gam_Games *Games,long GamCod) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -375,7 +417,7 @@ static void MchRes_ListAllMchResultsInGam (long GamCod) { /***** Show matches results *****/ Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat); - MchRes_ShowMchResults (Usr_OTHER,-1L,GamCod,NULL); + MchRes_ShowMchResults (Games,Usr_OTHER,-1L,GamCod,NULL); } } } @@ -391,34 +433,39 @@ static void MchRes_ListAllMchResultsInGam (long GamCod) void MchRes_ShowAllMchResultsInMch (void) { extern const char *Txt_Results_of_match_X; - struct Game Game; - struct Match Match; + struct Gam_Games Games; + struct Gam_Game Game; + struct Mch_Match Match; + + /***** Reset games *****/ + Gam_ResetGames (&Games); /***** Get parameters *****/ - if ((Game.GamCod = Gam_GetParams ()) == -1L) + if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); - if ((Match.MchCod = Mch_GetParamMchCod ()) == -1L) + if ((Match.MchCod = Mch_GetParamMchCod ()) <= 0) Lay_ShowErrorAndExit ("Code of match is missing."); Gam_GetDataOfGameByCod (&Game); Mch_GetDataOfMatchByCod (&Match); /***** Game begin *****/ - Gam_ShowOnlyOneGameBegin (&Game, + Gam_ShowOnlyOneGameBegin (&Games,&Game, false, // Do not list game questions false); // Do not put form to start new match /***** List matches results in match *****/ - MchRes_ShowResultsBegin (Str_BuildStringStr (Txt_Results_of_match_X,Match.Title), - false); // Do not list games to select + MchRes_ShowResultsBegin (&Games, + Str_BuildStringStr (Txt_Results_of_match_X,Match.Title), + false); // Do not list games to select Str_FreeString (); - MchRes_ListAllMchResultsInMch (Match.MchCod); + MchRes_ListAllMchResultsInMch (&Games,Match.MchCod); MchRes_ShowResultsEnd (); /***** Game end *****/ Gam_ShowOnlyOneGameEnd (); } -static void MchRes_ListAllMchResultsInMch (long MchCod) +static void MchRes_ListAllMchResultsInMch (struct Gam_Games *Games,long MchCod) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -460,7 +507,7 @@ static void MchRes_ListAllMchResultsInMch (long MchCod) { /***** Show matches results *****/ Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat); - MchRes_ShowMchResults (Usr_OTHER,MchCod,-1L,NULL); + MchRes_ShowMchResults (Games,Usr_OTHER,MchCod,-1L,NULL); } } } @@ -473,7 +520,8 @@ static void MchRes_ListAllMchResultsInMch (long MchCod) /************************ Show results (begin / end) *************************/ /*****************************************************************************/ -static void MchRes_ShowResultsBegin (const char *Title,bool ListGamesToSelect) +static void MchRes_ShowResultsBegin (struct Gam_Games *Games, + const char *Title,bool ListGamesToSelect) { extern const char *Hlp_ASSESSMENT_Games_results; @@ -485,7 +533,7 @@ static void MchRes_ShowResultsBegin (const char *Title,bool ListGamesToSelect) /***** List games to select *****/ if (ListGamesToSelect) - MchRes_ListGamesToSelect (); + MchRes_ListGamesToSelect (Games); /***** Begin match results table *****/ HTM_SECTION_Begin (MchRes_RESULTS_TABLE_ID); @@ -507,7 +555,7 @@ static void MchRes_ShowResultsEnd (void) /********** Write list of those attendance events that have students *********/ /*****************************************************************************/ -static void MchRes_ListGamesToSelect (void) +static void MchRes_ListGamesToSelect (struct Gam_Games *Games) { extern const char *Hlp_ASSESSMENT_Games_results; extern const char *The_ClassFormLinkInBoxBold[The_NUM_THEMES]; @@ -516,7 +564,7 @@ static void MchRes_ListGamesToSelect (void) extern const char *Txt_Update_results; unsigned UniqueId; unsigned NumGame; - struct Game Game; + struct Gam_Game Game; /***** Begin box *****/ Box_BoxBegin (NULL,Txt_Games, @@ -542,11 +590,11 @@ static void MchRes_ListGamesToSelect (void) /***** List the events *****/ for (NumGame = 0, UniqueId = 1, Gbl.RowEvenOdd = 0; - NumGame < Gbl.Games.Num; + NumGame < Games->Num; NumGame++, UniqueId++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd) { /* Get data of this game */ - Game.GamCod = Gbl.Games.Lst[NumGame].GamCod; + Game.GamCod = Games->Lst[NumGame].GamCod; Gam_GetDataOfGameByCod (&Game); /* Write a row for this event */ @@ -555,9 +603,9 @@ static void MchRes_ListGamesToSelect (void) HTM_TD_Begin ("class=\"DAT CT COLOR%u\"",Gbl.RowEvenOdd); HTM_INPUT_CHECKBOX ("GamCod",HTM_DONT_SUBMIT_ON_CHANGE, "id=\"Gam%u\" value=\"%ld\"%s", - NumGame,Gbl.Games.Lst[NumGame].GamCod, - Gbl.Games.Lst[NumGame].Selected ? " checked=\"checked\"" : - ""); + NumGame,Games->Lst[NumGame].GamCod, + Games->Lst[NumGame].Selected ? " checked=\"checked\"" : + ""); HTM_TD_End (); HTM_TD_Begin ("class=\"DAT RT COLOR%u\"",Gbl.RowEvenOdd); @@ -633,25 +681,26 @@ static void MchRes_ShowHeaderMchResults (Usr_MeOrOther_t MeOrOther) /******* from list of selected games ********/ /*****************************************************************************/ -static void MchRes_BuildGamesSelectedCommas (char **GamesSelectedCommas) +static void MchRes_BuildGamesSelectedCommas (struct Gam_Games *Games, + char **GamesSelectedCommas) { size_t MaxLength; unsigned NumGame; char LongStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1]; /***** Allocate memory for subquery of games selected *****/ - MaxLength = (size_t) Gbl.Games.NumSelected * (Cns_MAX_DECIMAL_DIGITS_LONG + 1); + MaxLength = (size_t) Games->NumSelected * (Cns_MAX_DECIMAL_DIGITS_LONG + 1); if ((*GamesSelectedCommas = (char *) malloc (MaxLength + 1)) == NULL) Lay_NotEnoughMemoryExit (); /***** Build subquery with list of selected games *****/ (*GamesSelectedCommas)[0] = '\0'; for (NumGame = 0; - NumGame < Gbl.Games.Num; + NumGame < Games->Num; NumGame++) - if (Gbl.Games.Lst[NumGame].Selected) + if (Games->Lst[NumGame].Selected) { - sprintf (LongStr,"%ld",Gbl.Games.Lst[NumGame].GamCod); + sprintf (LongStr,"%ld",Games->Lst[NumGame].GamCod); if ((*GamesSelectedCommas)[0]) Str_Concat (*GamesSelectedCommas,",",MaxLength); Str_Concat (*GamesSelectedCommas,LongStr,MaxLength); @@ -662,10 +711,11 @@ static void MchRes_BuildGamesSelectedCommas (char **GamesSelectedCommas) /********* Show the matches results of a user in the current course **********/ /*****************************************************************************/ -static void MchRes_ShowMchResults (Usr_MeOrOther_t MeOrOther, - long MchCod, // <= 0 ==> any - long GamCod, // <= 0 ==> any - const char *GamesSelectedCommas) +static void MchRes_ShowMchResults (struct Gam_Games *Games, + Usr_MeOrOther_t MeOrOther, + long MchCod, // <= 0 ==> any + long GamCod, // <= 0 ==> any + const char *GamesSelectedCommas) { extern const char *Txt_Match_result; char *MchSubQuery; @@ -679,7 +729,7 @@ static void MchRes_ShowMchResults (Usr_MeOrOther_t MeOrOther, unsigned NumResult; static unsigned UniqueId = 0; char *Id; - struct Match Match; + struct Mch_Match Match; Dat_StartEndTime_t StartEndTime; unsigned NumQstsInThisResult; unsigned NumQstsNotBlankInThisResult; @@ -888,17 +938,17 @@ static void MchRes_ShowMchResults (Usr_MeOrOther_t MeOrOther, HTM_TD_Begin ("class=\"RT COLOR%u\"",Gbl.RowEvenOdd); if (ICanViewResult) { - Gam_SetCurrentGamCod (Match.GamCod); // Used to pass parameter - Mch_SetCurrentMchCod (Match.MchCod); // Used to pass parameter + Games->GamCod = Match.GamCod; + Games->MchCod = Match.MchCod; switch (MeOrOther) { case Usr_ME: Frm_StartForm (ActSeeOneMchResMe); - Mch_PutParamsEdit (&Gbl); + Mch_PutParamsEdit (Games); break; case Usr_OTHER: Frm_StartForm (ActSeeOneMchResOth); - Mch_PutParamsEdit (&Gbl); + Mch_PutParamsEdit (Games); Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod); break; } @@ -935,10 +985,10 @@ static void MchRes_ShowMchResults (Usr_MeOrOther_t MeOrOther, /*****************************************************************************/ static void MchRes_ShowMchResultsSummaryRow (unsigned NumResults, - unsigned NumTotalQsts, - unsigned NumTotalQstsNotBlank, - double TotalScoreOfAllResults, - double TotalGrade) + unsigned NumTotalQsts, + unsigned NumTotalQstsNotBlank, + double TotalScoreOfAllResults, + double TotalGrade) { extern const char *Txt_Matches; @@ -1003,8 +1053,9 @@ void MchRes_ShowOneMchResult (void) extern const char *Txt_Score; extern const char *Txt_Grade; extern const char *Txt_Tags; - struct Game Game; - struct Match Match; + struct Gam_Games Games; + struct Gam_Game Game; + struct Mch_Match Match; Usr_MeOrOther_t MeOrOther; struct UsrData *UsrDat; Dat_StartEndTime_t StartEndTime; @@ -1015,8 +1066,11 @@ void MchRes_ShowOneMchResult (void) bool ICanViewResult; bool ICanViewScore; + /***** Reset games *****/ + Gam_ResetGames (&Games); + /***** Get and check parameters *****/ - Mch_GetAndCheckParameters (&Game,&Match); + Mch_GetAndCheckParameters (&Games,&Game,&Match); /***** Pointer to user's data *****/ MeOrOther = (Gbl.Action.Act == ActSeeOneMchResMe) ? Usr_ME : @@ -1353,7 +1407,7 @@ static void MchRes_GetMatchResultDataByMchCod (long MchCod,long UsrCod, /********************** Get if I can see match result ************************/ /*****************************************************************************/ -static bool MchRes_CheckIfICanSeeMatchResult (struct Match *Match,long UsrCod) +static bool MchRes_CheckIfICanSeeMatchResult (struct Mch_Match *Match,long UsrCod) { bool ItsMe; diff --git a/swad_match_result.h b/swad_match_result.h index 125f57b6..cefb0d91 100644 --- a/swad_match_result.h +++ b/swad_match_result.h @@ -40,13 +40,12 @@ /***************************** Public prototypes *****************************/ /*****************************************************************************/ -void MchRes_SelUsrsToViewMchResults (void *Args); - void MchRes_ShowMyMchResultsInCrs (void); void MchRes_ShowMyMchResultsInGam (void); void MchRes_ShowMyMchResultsInMch (void); void MchRes_ShowAllMchResultsInCrs (void); +void MchRes_SelUsrsToViewMchResults (void); void MchRes_ShowAllMchResultsInGam (void); void MchRes_ShowAllMchResultsInMch (void); diff --git a/swad_statistic.c b/swad_statistic.c index 5b9d57ad..5e2fc9c1 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -3182,7 +3182,7 @@ static void Sta_ShowNumHitsPerBanner (unsigned long NumRows, double MaxClicks = 0.0; double TotalClicks = 0.0; MYSQL_ROW row; - struct Banner Ban; + struct Ban_Banner Ban; /***** Write heading *****/ HTM_TR_Begin (NULL); diff --git a/swad_test.c b/swad_test.c index 7fd12e30..59258b24 100644 --- a/swad_test.c +++ b/swad_test.c @@ -159,7 +159,8 @@ static void Tst_IncreaseMyNumAccessTst (void); static void Tst_UpdateLastAccTst (unsigned NumQsts); static void Tst_ShowFormRequestEditTests (struct Tst_Test *Test); -static void Tst_ShowFormRequestSelectTestsForGame (struct Tst_Test *Test); +static void Tst_ShowFormRequestSelectTestsForGame (struct Gam_Games *Games, + struct Tst_Test *Test); static bool Tst_CheckIfICanEditTests (void); static void Tst_PutIconsTests (void *TestPtr); static void Tst_PutButtonToAddQuestion (void); @@ -192,7 +193,8 @@ static void Tst_ListOneOrMoreQuestionsForEdition (struct Tst_Test *Test, MYSQL_RES *mysql_res); static void Tst_WriteHeadingRowQuestionsForEdition (const struct Tst_Test *Test); static void Tst_WriteQuestionListing (struct Tst_Test *Test,unsigned NumQst); -static void Tst_ListOneOrMoreQuestionsForSelection (unsigned NumQsts, +static void Tst_ListOneOrMoreQuestionsForSelection (struct Gam_Games *Games, + unsigned NumQsts, MYSQL_RES *mysql_res); static void Tst_WriteQuestionRowForSelection (unsigned NumQst, struct Tst_Question *Question); @@ -1285,7 +1287,7 @@ static void Tst_ShowFormRequestEditTests (struct Tst_Test *Test) /******************* Select test questions for a game ************************/ /*****************************************************************************/ -void Tst_RequestSelectTestsForGame (void) +void Tst_RequestSelectTestsForGame (struct Gam_Games *Games) { struct Tst_Test Test; @@ -1293,7 +1295,7 @@ void Tst_RequestSelectTestsForGame (void) Tst_TstConstructor (&Test); /***** Show form to select test for game *****/ - Tst_ShowFormRequestSelectTestsForGame (&Test); // No tags selected + Tst_ShowFormRequestSelectTestsForGame (Games,&Test); // No tags selected /***** Destroy test *****/ Tst_TstDestructor (&Test); @@ -1303,7 +1305,8 @@ void Tst_RequestSelectTestsForGame (void) /************** Show form to select test questions for a game ****************/ /*****************************************************************************/ -static void Tst_ShowFormRequestSelectTestsForGame (struct Tst_Test *Test) +static void Tst_ShowFormRequestSelectTestsForGame (struct Gam_Games *Games, + struct Tst_Test *Test) { extern const char *Hlp_ASSESSMENT_Games_questions; extern const char *Txt_No_test_questions; @@ -1325,7 +1328,7 @@ static void Tst_ShowFormRequestSelectTestsForGame (struct Tst_Test *Test) if ((Test->Tags.Num = Tst_GetAllTagsFromCurrentCrs (&mysql_res))) { Frm_StartForm (ActGamLstTstQst); - Gam_PutParams (&Gbl); + Gam_PutParams (Games); HTM_TABLE_BeginPadding (2); @@ -2215,7 +2218,7 @@ void Tst_ListQuestionsToEdit (void) /**************** List several test questions for selection ******************/ /*****************************************************************************/ -void Tst_ListQuestionsToSelect (void) +void Tst_ListQuestionsToSelect (struct Gam_Games *Games) { struct Tst_Test Test; MYSQL_RES *mysql_res; @@ -2229,14 +2232,14 @@ void Tst_ListQuestionsToSelect (void) Tst_GetQuestions (&Test,&mysql_res); // Query database if (Test.NumQsts) /* Show the table with the questions */ - Tst_ListOneOrMoreQuestionsForSelection (Test.NumQsts,mysql_res); + Tst_ListOneOrMoreQuestionsForSelection (Games,Test.NumQsts,mysql_res); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); } else /* Show the form again */ - Tst_ShowFormRequestSelectTestsForGame (&Test); + Tst_ShowFormRequestSelectTestsForGame (Games,&Test); /***** Destroy test *****/ Tst_TstDestructor (&Test); @@ -2926,7 +2929,8 @@ static void Tst_WriteQuestionListing (struct Tst_Test *Test,unsigned NumQst) /*************** List for selection one or more test questions ***************/ /*****************************************************************************/ -static void Tst_ListOneOrMoreQuestionsForSelection (unsigned NumQsts, +static void Tst_ListOneOrMoreQuestionsForSelection (struct Gam_Games *Games, + unsigned NumQsts, MYSQL_RES *mysql_res) { extern const char *Hlp_ASSESSMENT_Games_questions; @@ -2950,7 +2954,7 @@ static void Tst_ListOneOrMoreQuestionsForSelection (unsigned NumQsts, /***** Begin form *****/ Frm_StartForm (ActAddTstQstToGam); - Gam_PutParams (&Gbl); + Gam_PutParams (Games); /***** Write the heading *****/ HTM_TABLE_BeginWideMarginPadding (2); diff --git a/swad_test.h b/swad_test.h index 3d5a1e98..42002c3c 100644 --- a/swad_test.h +++ b/swad_test.h @@ -166,10 +166,10 @@ void Tst_WriteQstStem (const char *Stem,const char *ClassStem,bool Visible); void Tst_WriteQstFeedback (const char *Feedback,const char *ClassFeedback); void Tst_RequestEditTests (void); -void Tst_RequestSelectTestsForGame (void); +void Tst_RequestSelectTestsForGame (struct Gam_Games *Games); void Tst_ListQuestionsToEdit (void); -void Tst_ListQuestionsToSelect (void); +void Tst_ListQuestionsToSelect (struct Gam_Games *Games); void Tst_WriteParamEditQst (const struct Tst_Test *Test); unsigned Tst_GetNumAnswersQst (long QstCod);