From 7d177fbf05450da0144ec24dcff68923267ab649 Mon Sep 17 00:00:00 2001 From: acanas Date: Thu, 7 May 2020 01:14:50 +0200 Subject: [PATCH] Version19.214.1 --- swad_assignment.c | 36 ++++++++---- swad_changelog.h | 6 +- swad_exam.c | 18 +++--- swad_exam_event.c | 147 +++++++++++++++++++++++++--------------------- swad_exam_event.h | 2 +- swad_exam_type.h | 3 +- 6 files changed, 121 insertions(+), 91 deletions(-) diff --git a/swad_assignment.c b/swad_assignment.c index 5c0d92f5..10f16c60 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -753,11 +753,14 @@ void Asg_GetDataOfAssignmentByCod (struct Asg_Assignment *Asg) { /***** Build query *****/ NumRows = DB_QuerySELECT (&mysql_res,"can not get assignment data", - "SELECT AsgCod,Hidden,UsrCod," - "UNIX_TIMESTAMP(StartTime)," - "UNIX_TIMESTAMP(EndTime)," - "NOW() BETWEEN StartTime AND EndTime," - "Title,Folder" + "SELECT AsgCod," // row[0] + "Hidden," // row[1] + "UsrCod," // row[2] + "UNIX_TIMESTAMP(StartTime)," // row[3] + "UNIX_TIMESTAMP(EndTime)," // row[4] + "NOW() BETWEEN StartTime AND EndTime," // row[5] + "Title," // row[6] + "Folder" // row[7] " FROM assignments" " WHERE AsgCod=%ld AND CrsCod=%ld", Asg->AsgCod,Gbl.Hierarchy.Crs.CrsCod); @@ -786,11 +789,14 @@ void Asg_GetDataOfAssignmentByFolder (struct Asg_Assignment *Asg) { /***** Query database *****/ NumRows = DB_QuerySELECT (&mysql_res,"can not get assignment data", - "SELECT AsgCod,Hidden,UsrCod," - "UNIX_TIMESTAMP(StartTime)," - "UNIX_TIMESTAMP(EndTime)," - "NOW() BETWEEN StartTime AND EndTime," - "Title,Folder" + "SELECT AsgCod," // row[0] + "Hidden," // row[1] + "UsrCod," // row[2] + "UNIX_TIMESTAMP(StartTime)," // row[3] + "UNIX_TIMESTAMP(EndTime)," // row[4] + "NOW() BETWEEN StartTime AND EndTime," // row[5] + "Title," // row[6] + "Folder" // row[7] " FROM assignments" " WHERE CrsCod=%ld AND Folder='%s'", Gbl.Hierarchy.Crs.CrsCod,Asg->Folder); @@ -824,6 +830,16 @@ static void Asg_GetDataOfAssignment (struct Asg_Assignment *Asg, { /* Get row */ row = mysql_fetch_row (*mysql_res); + /* + row[0] AsgCod + row[1] Hidden + row[2] UsrCod + row[3] UNIX_TIMESTAMP(StartTime) + row[4] UNIX_TIMESTAMP(EndTime) + row[5] NOW() BETWEEN StartTime AND EndTime + row[6] Title + row[7] Folder + */ /* Get code of the assignment (row[0]) */ Asg->AsgCod = Str_ConvertStrCodToLongCod (row[0]); diff --git a/swad_changelog.h b/swad_changelog.h index 413d14ec..4cfa6e9e 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -548,12 +548,12 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.214 (2020-05-06)" +#define Log_PLATFORM_VERSION "SWAD 19.214.1 (2020-05-07)" #define CSS_FILE "swad19.193.1.css" #define JS_FILE "swad19.193.1.js" /* - Version 19.214.1: May 06, 2020 Change color of dates on current exam event. (? lines) - Version 19.214: May 05, 2020 New API function getLocations. (301568 lines) + Version 19.214.1: May 07, 2020 Change color of dates on current exam event. (301597 lines) + Version 19.214: May 06, 2020 New API function getLocations. (301568 lines) 1 change necessary in database: CREATE TABLE IF NOT EXISTS room_MAC (RooCod INT NOT NULL AUTO_INCREMENT,MAC BIGINT NOT NULL,UNIQUE INDEX(RooCod,MAC),UNIQUE INDEX(MAC,RooCod)); If you want to use MyISAM: diff --git a/swad_exam.c b/swad_exam.c index 6c93a414..7410a327 100644 --- a/swad_exam.c +++ b/swad_exam.c @@ -257,7 +257,7 @@ void Exa_ResetExam (struct Exa_Exam *Exam) Exam->NumSets = 0; Exam->NumQsts = 0; Exam->NumEvts = 0; - Exam->NumUnfinishedEvts = 0; + Exam->NumOpenEvts = 0; } /*****************************************************************************/ @@ -555,7 +555,7 @@ static void Exa_ShowOneExam (struct Exa_Exams *Exams, struct Exa_Exam *Exam,bool ShowOnlyThisExam) { extern const char *Txt_View_exam; - extern const char *Txt_Set_of_questions; + extern const char *Txt_Sets_of_questions; extern const char *Txt_Maximum_grade; extern const char *Txt_Result_visibility; extern const char *Txt_Events; @@ -598,10 +598,10 @@ static void Exa_ShowOneExam (struct Exa_Exams *Exams, { if (asprintf (&Id,"exa_date_%u_%u",(unsigned) StartEndTime,UniqueId) < 0) Lay_NotEnoughMemoryExit (); - Color = Exam->NumUnfinishedEvts ? (Exam->Hidden ? "DATE_GREEN_LIGHT": - "DATE_GREEN") : - (Exam->Hidden ? "DATE_RED_LIGHT": - "DATE_RED"); + Color = Exam->NumOpenEvts ? (Exam->Hidden ? "DATE_GREEN_LIGHT": + "DATE_GREEN") : + (Exam->Hidden ? "DATE_RED_LIGHT": + "DATE_RED"); if (ShowOnlyThisExam) HTM_TD_Begin ("id=\"%s\" class=\"%s LT\"", Id,Color); @@ -639,7 +639,7 @@ static void Exa_ShowOneExam (struct Exa_Exams *Exams, /* Number of questions, maximum grade, visibility of results */ HTM_DIV_Begin ("class=\"%s\"",Exam->Hidden ? "ASG_GRP_LIGHT" : "ASG_GRP"); - HTM_TxtColonNBSP (Txt_Set_of_questions); + HTM_TxtColonNBSP (Txt_Sets_of_questions); HTM_Unsigned (Exam->NumSets); HTM_BR (); HTM_TxtColonNBSP (Txt_Maximum_grade); @@ -1188,8 +1188,8 @@ void Exa_GetDataOfExamByCod (struct Exa_Exam *Exam) /* Get number of events */ Exam->NumEvts = ExaEvt_GetNumEventsInExam (Exam->ExaCod); - /* Get number of unfinished events */ - Exam->NumUnfinishedEvts = ExaEvt_GetNumUnfinishedEventsInExam (Exam->ExaCod); + /* Get number of open events */ + Exam->NumOpenEvts = ExaEvt_GetNumOpenEventsInExam (Exam->ExaCod); } else /* Initialize to empty exam */ diff --git a/swad_exam_event.c b/swad_exam_event.c index 1ec6a917..e6d9c221 100644 --- a/swad_exam_event.c +++ b/swad_exam_event.c @@ -273,6 +273,7 @@ void ExaEvt_ResetEvent (struct ExaEvt_Event *Event) Event->TimeUTC[StartEndTime] = (time_t) 0; Event->Title[0] = '\0'; Event->Hidden = false; + Event->Open = false; Event->Status.QstInd = 0; Event->Status.QstCod = -1L; Event->Status.QstStartTimeUTC = (time_t) 0; @@ -323,26 +324,28 @@ void ExaEvt_ListEvents (struct Exa_Exams *Exams, Lay_NotEnoughMemoryExit (); /* Make query */ - NumEvents = (unsigned) DB_QuerySELECT (&mysql_res,"can not get events", - "SELECT EvtCod," // row[ 0] - "ExaCod," // row[ 1] - "Hidden," // row[ 2] - "UsrCod," // row[ 3] - "UNIX_TIMESTAMP(StartTime)," // row[ 4] - "UNIX_TIMESTAMP(EndTime)," // row[ 5] - "Title," // row[ 6] - "QstInd," // row[ 7] - "QstCod," // row[ 8] - "Showing," // row[ 9] - "Countdown," // row[10] - "NumCols," // row[11] - "ShowQstResults," // row[12] - "ShowUsrResults" // row[13] - " FROM exa_events" - " WHERE ExaCod=%ld%s" - " ORDER BY EvtCod", - Exam->ExaCod, - SubQuery); + NumEvents = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get events", + "SELECT EvtCod," // row[ 0] + "ExaCod," // row[ 1] + "Hidden," // row[ 2] + "UsrCod," // row[ 3] + "UNIX_TIMESTAMP(StartTime)," // row[ 4] + "UNIX_TIMESTAMP(EndTime)," // row[ 5] + "NOW() BETWEEN StartTime AND EndTime," // row[ 6] + "Title," // row[ 7] + "QstInd," // row[ 8] + "QstCod," // row[ 9] + "Showing," // row[10] + "Countdown," // row[11] + "NumCols," // row[12] + "ShowQstResults," // row[13] + "ShowUsrResults" // row[14] + " FROM exa_events" + " WHERE ExaCod=%ld%s" + " ORDER BY EvtCod", + Exam->ExaCod, + SubQuery); /* Free allocated memory for subquery */ free (SubQuery); @@ -424,20 +427,21 @@ void ExaEvt_GetDataOfEventByCod (struct ExaEvt_Event *Event) /***** Get exam data event from database *****/ NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get events", - "SELECT EvtCod," // row[ 0] - "ExaCod," // row[ 1] - "Hidden," // row[ 2] - "UsrCod," // row[ 3] - "UNIX_TIMESTAMP(StartTime),"// row[ 4] - "UNIX_TIMESTAMP(EndTime)," // row[ 5] - "Title," // row[ 6] - "QstInd," // row[ 7] - "QstCod," // row[ 8] - "Showing," // row[ 9] - "Countdown," // row[10] - "NumCols," // row[11] - "ShowQstResults," // row[12] - "ShowUsrResults" // row[13] + "SELECT EvtCod," // row[ 0] + "ExaCod," // row[ 1] + "Hidden," // row[ 2] + "UsrCod," // row[ 3] + "UNIX_TIMESTAMP(StartTime)," // row[ 4] + "UNIX_TIMESTAMP(EndTime)," // row[ 5] + "NOW() BETWEEN StartTime AND EndTime," // row[ 6] + "Title," // row[ 7] + "QstInd," // row[ 8] + "QstCod," // row[ 9] + "Showing," // row[10] + "Countdown," // row[11] + "NumCols," // row[12] + "ShowQstResults," // row[13] + "ShowUsrResults" // row[14] " FROM exa_events" " WHERE EvtCod=%ld" " AND ExaCod IN" // Extra check @@ -708,12 +712,10 @@ static void ExaEvt_ListOneOrMoreEventsTimes (const struct ExaEvt_Event *Event,un StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1); StartEndTime++) { - Color = Event->Status.Showing == ExaEvt_END ? (Event->Hidden ? "DATE_GREEN_LIGHT": - "DATE_GREEN") : - (Event->Hidden ? "DATE_RED_LIGHT": - "DATE_RED"); - - + Color = Event->Open ? (Event->Hidden ? "DATE_GREEN_LIGHT": + "DATE_GREEN") : + (Event->Hidden ? "DATE_RED_LIGHT": + "DATE_RED"); if (asprintf (&Id,"exa_time_%u_%u",(unsigned) StartEndTime,UniqueId) < 0) Lay_NotEnoughMemoryExit (); @@ -1009,7 +1011,8 @@ static void ExaEvt_GetEventDataFromRow (MYSQL_RES *mysql_res, row[ 3] UsrCod row[ 4] UNIX_TIMESTAMP(StartTime) row[ 5] UNIX_TIMESTAMP(EndTime) - row[ 6] Title + row[ 6] Open = NOW() BETWEEN StartTime AND EndTime + row[ 7] Title */ /***** Get event data *****/ /* Code of the event (row[0]) */ @@ -1032,22 +1035,25 @@ static void ExaEvt_GetEventDataFromRow (MYSQL_RES *mysql_res, StartEndTime++) Event->TimeUTC[StartEndTime] = Dat_GetUNIXTimeFromStr (row[4 + StartEndTime]); - /* Get the title of the event (row[6]) */ - if (row[6]) - Str_Copy (Event->Title,row[6], + /* Get whether the event is open or closed (row(6)) */ + Event->Open = (row[6][0] == '1'); + + /* Get the title of the event (row[7]) */ + if (row[7]) + Str_Copy (Event->Title,row[7], ExaEvt_MAX_BYTES_TITLE); else Event->Title[0] = '\0'; /***** Get current event status *****/ /* - row[ 7] QstInd - row[ 8] QstCod - row[ 9] Showing - row[10] Countdown - row[11] NumCols - row[12] ShowQstResults - row[13] ShowUsrResults + row[ 8] QstInd + row[ 9] QstCod + row[10] Showing + row[11] Countdown + row[12] NumCols + row[13] ShowQstResults + row[14] ShowUsrResults */ /* Current question index (row[7]) */ Event->Status.QstInd = Str_ConvertStrToUnsigned (row[7]); @@ -1055,23 +1061,23 @@ static void ExaEvt_GetEventDataFromRow (MYSQL_RES *mysql_res, /* Current question code (row[8]) */ Event->Status.QstCod = Str_ConvertStrCodToLongCod (row[8]); - /* Get what to show (stem, answers, results) (row(9)) */ - Event->Status.Showing = ExaEvt_GetShowingFromStr (row[9]); + /* Get what to show (stem, answers, results) (row(10)) */ + Event->Status.Showing = ExaEvt_GetShowingFromStr (row[10]); - /* Get countdown (row[10]) */ - Event->Status.Countdown = Str_ConvertStrCodToLongCod (row[10]); + /* Get countdown (row[11]) */ + Event->Status.Countdown = Str_ConvertStrCodToLongCod (row[11]); - /* Get number of columns (row[11]) */ - LongNum = Str_ConvertStrCodToLongCod (row[11]); + /* Get number of columns (row[12]) */ + LongNum = Str_ConvertStrCodToLongCod (row[12]); Event->Status.NumCols = (LongNum <= 1 ) ? 1 : ((LongNum >= ExaEvt_MAX_COLS) ? ExaEvt_MAX_COLS : (unsigned) LongNum); - /* Get whether to show question results or not (row(12)) */ - Event->Status.ShowQstResults = (row[12][0] == 'Y'); + /* Get whether to show question results or not (row(13)) */ + Event->Status.ShowQstResults = (row[13][0] == 'Y'); - /* Get whether to show user results or not (row(13)) */ - Event->Status.ShowUsrResults = (row[13][0] == 'Y'); + /* Get whether to show user results or not (row(14)) */ + Event->Status.ShowUsrResults = (row[14][0] == 'Y'); /***** Get whether the exam event is being played or not *****/ if (Event->Status.Showing == ExaEvt_END) // Event over @@ -1161,6 +1167,9 @@ void ExaEvt_RemoveEvent (void) Ale_ShowAlert (Ale_SUCCESS,Txt_Event_X_removed, Event.Title); + /***** Get exam data again to update it after changes in event *****/ + Exa_GetDataOfExamByCod (&Exam); + /***** Show current exam *****/ Exa_ShowOnlyOneExam (&Exams,&Exam,&Event, false); // Do not put form for event @@ -1717,6 +1726,9 @@ void ExaEvt_ReceiveFormEvent (void) else Ale_ShowAlert (Ale_SUCCESS,Txt_The_event_has_been_modified); + /***** Get exam data again to update it after changes in event *****/ + Exa_GetDataOfExamByCod (&Exam); + /***** Show current exam *****/ Exa_ShowOnlyOneExam (&Exams,&Exam,&Event, false); // Do not put form for event @@ -2562,21 +2574,22 @@ unsigned ExaEvt_GetNumEventsInExam (long ExaCod) } /*****************************************************************************/ -/*************** Get number of unfinished events in an exam ******************/ +/****************** Get number of open events in an exam *********************/ /*****************************************************************************/ -unsigned ExaEvt_GetNumUnfinishedEventsInExam (long ExaCod) +unsigned ExaEvt_GetNumOpenEventsInExam (long ExaCod) { /***** Trivial check *****/ if (ExaCod < 0) // A non-existing exam... return 0; // ...has no events - /***** Get number of events in an exam from database *****/ + /***** Get number of open events in an exam from database *****/ return - (unsigned) DB_QueryCOUNT ("can not get number of unfinished events of an exam", + (unsigned) DB_QueryCOUNT ("can not get number of open events of an exam", "SELECT COUNT(*) FROM exa_events" - " WHERE ExaCod=%ld AND Showing<>'%s'", - ExaCod,ExaEvt_ShowingStringsDB[ExaEvt_END]); + " WHERE ExaCod=%ld" + " AND NOW() BETWEEN StartTime AND EndTime", + ExaCod); } /*****************************************************************************/ diff --git a/swad_exam_event.h b/swad_exam_event.h index 45f3b9c6..e926dc63 100644 --- a/swad_exam_event.h +++ b/swad_exam_event.h @@ -93,7 +93,7 @@ void ExaEvt_BackEvent (void); void ExaEvt_ForwardEvent (void); unsigned ExaEvt_GetNumEventsInExam (long ExaCod); -unsigned ExaEvt_GetNumUnfinishedEventsInExam (long ExaCod); +unsigned ExaEvt_GetNumOpenEventsInExam (long ExaCod); bool ExaEvt_CheckIfICanPlayThisEventBasedOnGrps (const struct ExaEvt_Event *Event); diff --git a/swad_exam_type.h b/swad_exam_type.h index c7705667..5844152a 100644 --- a/swad_exam_type.h +++ b/swad_exam_type.h @@ -96,7 +96,7 @@ struct Exa_Exam unsigned NumSets; // Number of sets in the exam unsigned NumQsts; // Number of questions in the exam unsigned NumEvts; // Number of events in the exam - unsigned NumUnfinishedEvts; // Number of unfinished events in the exam + unsigned NumOpenEvts; // Number of open events in the exam }; struct ExaSet_Set @@ -127,6 +127,7 @@ struct ExaEvt_Event time_t TimeUTC[Dat_NUM_START_END_TIME]; char Title[ExaEvt_MAX_BYTES_TITLE + 1]; bool Hidden; + bool Open; // If now is between start and end dates struct { unsigned QstInd; // 0 means that the exam has not started. First question has index 1.