swad-core/swad_exam_session.c

1316 lines
46 KiB
C
Raw Normal View History

2020-05-17 02:28:30 +02:00
// swad_exam_session.c: exam sessions (each ocurrence of an exam)
2020-04-20 01:26:46 +02:00
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
Copyright (C) 1999-2023 Antonio Ca<EFBFBD>as Vargas
2020-04-20 01:26:46 +02:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
#define _GNU_SOURCE // For asprintf
#include <linux/limits.h> // For PATH_MAX
#include <stddef.h> // For NULL
#include <stdio.h> // For asprintf
#include <stdlib.h> // For free
2020-04-20 01:26:46 +02:00
#include <string.h> // For string functions
#include "swad_action_list.h"
#include "swad_alert.h"
#include "swad_box.h"
2020-04-20 01:26:46 +02:00
#include "swad_database.h"
#include "swad_date.h"
#include "swad_error.h"
2020-04-20 01:26:46 +02:00
#include "swad_exam.h"
#include "swad_exam_database.h"
2020-05-13 12:53:27 +02:00
#include "swad_exam_print.h"
2020-04-20 01:26:46 +02:00
#include "swad_exam_result.h"
2020-05-17 02:28:30 +02:00
#include "swad_exam_session.h"
2020-05-07 02:22:57 +02:00
#include "swad_exam_set.h"
2020-05-05 21:49:00 +02:00
#include "swad_exam_type.h"
2020-04-20 01:26:46 +02:00
#include "swad_form.h"
#include "swad_global.h"
#include "swad_group_database.h"
2020-04-20 01:26:46 +02:00
#include "swad_HTML.h"
#include "swad_parameter_code.h"
2020-04-20 01:26:46 +02:00
#include "swad_role.h"
#include "swad_setting.h"
#include "swad_test.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_PutIconsInListOfSessions (void *Exams);
static void ExaSes_PutIconToCreateNewSession (struct Exa_Exams *Exams);
2020-04-20 01:26:46 +02:00
2020-05-17 02:28:30 +02:00
static void ExaSes_ListOneOrMoreSessions (struct Exa_Exams *Exams,
long SesCodToBeEdited,
2020-05-17 02:28:30 +02:00
unsigned NumSessions,
MYSQL_RES *mysql_res);
static void ExaSes_ListOneOrMoreSessionsHeading (bool ICanEditSessions);
static bool ExaSes_CheckIfICanEditSessions (void);
static bool ExaSes_CheckIfICanEditThisSession (long UsrCod);
2020-05-30 19:33:55 +02:00
static bool ExaSes_CheckIfVisibilityOfResultsCanBeChanged (const struct ExaSes_Session *Session);
2020-05-17 02:28:30 +02:00
static void ExaSes_ListOneOrMoreSessionsIcons (struct Exa_Exams *Exams,
const struct ExaSes_Session *Session,
const char *Anchor);
static void ExaSes_ListOneOrMoreSessionsAuthor (const struct ExaSes_Session *Session);
static void ExaSes_ListOneOrMoreSessionsTimes (const struct ExaSes_Session *Session,
unsigned UniqueId);
static void ExaSes_ListOneOrMoreSessionsTitleGrps (struct Exa_Exams *Exams,
const struct ExaSes_Session *Session,
const char *Anchor);
static void ExaSes_GetAndWriteNamesOfGrpsAssociatedToSession (const struct ExaSes_Session *Session);
static void ExaSes_ListOneOrMoreSessionsResult (struct Exa_Exams *Exams,
const struct ExaSes_Session *Session);
static void ExaSes_ListOneOrMoreSessionsResultStd (struct Exa_Exams *Exams,
const struct ExaSes_Session *Session);
static void ExaSes_ListOneOrMoreSessionsResultTch (struct Exa_Exams *Exams,
const struct ExaSes_Session *Session);
2020-04-20 01:26:46 +02:00
2020-05-17 02:28:30 +02:00
static void ExaSes_GetSessionDataFromRow (MYSQL_RES *mysql_res,
struct ExaSes_Session *Session);
2020-04-20 01:26:46 +02:00
2020-05-17 02:28:30 +02:00
static void ExaSes_PutFormSession (const struct ExaSes_Session *Session);
static void ExaSes_ShowLstGrpsToCreateSession (long SesCod);
2020-04-20 01:26:46 +02:00
2020-05-17 02:28:30 +02:00
static void ExaSes_CreateSession (struct ExaSes_Session *Session);
static void ExaSes_UpdateSession (struct ExaSes_Session *Session);
2020-05-06 01:43:48 +02:00
static void ExaSes_CreateGrpsAssociatedToExamSession (long SesCod,
const struct ListCodGrps *LstGrpsSel);
2020-05-06 01:43:48 +02:00
2020-04-23 23:09:28 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/***************************** Reset exam session ****************************/
2020-04-23 23:09:28 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
void ExaSes_ResetSession (struct ExaSes_Session *Session)
2020-04-23 23:09:28 +02:00
{
2020-05-05 20:09:28 +02:00
Dat_StartEndTime_t StartEndTime;
2020-04-23 23:09:28 +02:00
/***** Initialize to empty match *****/
2020-05-17 02:28:30 +02:00
Session->SesCod = -1L;
Session->ExaCod = -1L;
Session->UsrCod = -1L;
2020-05-05 20:09:28 +02:00
for (StartEndTime = (Dat_StartEndTime_t) 0;
StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
StartEndTime++)
2020-05-17 02:28:30 +02:00
Session->TimeUTC[StartEndTime] = (time_t) 0;
Session->Title[0] = '\0';
Session->Hidden = false;
Session->Open = false;
Session->ShowUsrResults = false;
2020-04-23 23:09:28 +02:00
};
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/************************ List the sessions of an exam ***********************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
void ExaSes_ListSessions (struct Exa_Exams *Exams,
2020-05-21 16:59:14 +02:00
struct ExaSes_Session *Session,
bool PutFormSession)
2020-04-20 01:26:46 +02:00
{
2020-05-17 02:28:30 +02:00
extern const char *Hlp_ASSESSMENT_Exams_sessions;
extern const char *Txt_Sessions;
2020-04-20 01:26:46 +02:00
MYSQL_RES *mysql_res;
2020-05-17 02:28:30 +02:00
unsigned NumSessions;
2020-04-20 01:26:46 +02:00
/***** Begin box *****/
2020-05-17 02:28:30 +02:00
Box_BoxBegin ("100%",Txt_Sessions,
ExaSes_PutIconsInListOfSessions,Exams,
Hlp_ASSESSMENT_Exams_sessions,Box_NOT_CLOSABLE);
2020-04-20 01:26:46 +02:00
/***** Select whether show only my groups or all groups *****/
2020-05-15 01:07:46 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
2020-04-20 01:26:46 +02:00
{
2020-05-15 01:07:46 +02:00
case Rol_NET:
case Rol_TCH:
case Rol_SYS_ADM:
if (Gbl.Crs.Grps.NumGrps)
{
Set_BeginSettingsHead ();
2020-05-15 01:07:46 +02:00
Grp_ShowFormToSelWhichGrps (ActSeeExa,
Exa_PutPars,Exams);
2020-05-15 01:07:46 +02:00
Set_EndSettingsHead ();
}
break;
default:
break;
2020-04-20 01:26:46 +02:00
}
2020-05-17 02:28:30 +02:00
/***** Show the table with the sessions *****/
if ((NumSessions = Exa_DB_GetSessions (&mysql_res,Exams->Exam.ExaCod)))
ExaSes_ListOneOrMoreSessions (Exams,
PutFormSession &&
Session->SesCod > 0 ? Session->SesCod :
-1L,
NumSessions,mysql_res);
2020-04-20 01:26:46 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2020-05-17 02:28:30 +02:00
/***** Put button to create a new exam session in this exam *****/
2020-04-20 01:26:46 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_NET:
case Rol_TCH:
case Rol_SYS_ADM:
if (PutFormSession && Session->SesCod <= 0)
2020-04-28 03:14:25 +02:00
{
2020-05-17 02:28:30 +02:00
/* Reset session */
ExaSes_ResetSession (Session);
Session->ExaCod = Exams->Exam.ExaCod;
Session->TimeUTC[Dat_STR_TIME] = Dat_GetStartExecutionTimeUTC (); // Now
Session->TimeUTC[Dat_END_TIME] = Session->TimeUTC[Dat_STR_TIME] + (1 * 60 * 60); // Now + 1 hour
Str_Copy (Session->Title,Exams->Exam.Title,sizeof (Session->Title) - 1);
2020-05-17 02:28:30 +02:00
/* Put form to create new session */
ExaSes_PutFormSession (Session); // Form to create session
2020-04-28 03:14:25 +02:00
}
2020-04-20 01:26:46 +02:00
else
ExaSes_PutButtonNewSession (Exams); // Button to create a new exam session
2020-04-20 01:26:46 +02:00
break;
default:
break;
}
/***** End box *****/
Box_BoxEnd ();
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/******************* Get exam session data using its code ********************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
void ExaSes_GetSessionDataByCod (struct ExaSes_Session *Session)
2020-04-20 01:26:46 +02:00
{
MYSQL_RES *mysql_res;
2020-05-06 12:47:36 +02:00
/***** Trivial check *****/
2020-05-17 02:28:30 +02:00
if (Session->SesCod <= 0)
2020-05-06 12:47:36 +02:00
{
2020-05-17 02:28:30 +02:00
/* Initialize to empty exam session */
ExaSes_ResetSession (Session);
2020-05-06 12:47:36 +02:00
return;
}
2020-05-17 02:28:30 +02:00
/***** Get exam data session from database *****/
if (Exa_DB_GetSessionDataByCod (&mysql_res,Session->SesCod)) // Session found...
2020-05-17 02:28:30 +02:00
/* Get exam session data from row */
ExaSes_GetSessionDataFromRow (mysql_res,Session);
2020-04-20 01:26:46 +02:00
else
2020-05-17 02:28:30 +02:00
/* Initialize to empty exam session */
ExaSes_ResetSession (Session);
2020-04-20 01:26:46 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/***************** Put icons in list of sessions of an exam ******************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_PutIconsInListOfSessions (void *Exams)
2020-04-20 01:26:46 +02:00
{
2020-05-17 02:28:30 +02:00
bool ICanEditSessions;
2020-04-20 01:26:46 +02:00
if (Exams)
{
2020-05-17 02:28:30 +02:00
/***** Put icon to create a new exam session in current exam *****/
ICanEditSessions = ExaSes_CheckIfICanEditSessions ();
if (ICanEditSessions)
ExaSes_PutIconToCreateNewSession ((struct Exa_Exams *) Exams);
2020-04-20 01:26:46 +02:00
}
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/******************* Put icon to create a new exam session *******************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_PutIconToCreateNewSession (struct Exa_Exams *Exams)
2020-04-20 01:26:46 +02:00
{
2020-05-18 02:15:10 +02:00
Ico_PutContextualIconToAdd (ActReqNewExaSes,ExaSes_NEW_SESSION_SECTION_ID,
Exa_PutPars,Exams);
2020-04-20 01:26:46 +02:00
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/********************** List exam sessions for edition ***********************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_ListOneOrMoreSessions (struct Exa_Exams *Exams,
long SesCodToBeEdited,
2020-05-17 02:28:30 +02:00
unsigned NumSessions,
MYSQL_RES *mysql_res)
2020-04-20 01:26:46 +02:00
{
2020-05-17 02:28:30 +02:00
unsigned NumSession;
2020-04-20 01:26:46 +02:00
unsigned UniqueId;
2020-05-05 20:09:28 +02:00
char *Anchor;
2020-05-17 02:28:30 +02:00
struct ExaSes_Session Session;
bool ICanEditSessions = ExaSes_CheckIfICanEditSessions ();
2020-04-20 01:26:46 +02:00
2020-04-28 12:34:56 +02:00
/***** Trivial check *****/
2020-05-17 02:28:30 +02:00
if (!NumSessions)
2020-04-28 12:34:56 +02:00
return;
2020-05-17 02:28:30 +02:00
/***** Reset session *****/
ExaSes_ResetSession (&Session);
2020-04-23 23:09:28 +02:00
/***** Begin table with sessions *****/
2020-04-20 01:26:46 +02:00
HTM_TABLE_BeginWidePadding (2);
/***** Write the heading *****/
ExaSes_ListOneOrMoreSessionsHeading (ICanEditSessions);
2020-04-20 01:26:46 +02:00
/***** Write rows *****/
for (NumSession = 0, UniqueId = 1, The_ResetRowColor ();
NumSession < NumSessions;
NumSession++, UniqueId++, The_ChangeRowColor ())
2020-04-20 01:26:46 +02:00
{
/***** Get exam session data from row *****/
ExaSes_GetSessionDataFromRow (mysql_res,&Session);
if (ExaSes_CheckIfICanListThisSessionBasedOnGrps (Session.SesCod))
{
/***** Build anchor string *****/
if (asprintf (&Anchor,"evt_%ld_%ld",Exams->Exam.ExaCod,Session.SesCod) < 0)
Err_NotEnoughMemoryExit ();
2020-04-20 01:26:46 +02:00
/***** Begin row for this exam session ****/
HTM_TR_Begin (NULL);
2020-04-20 01:26:46 +02:00
/* Icons */
if (ICanEditSessions)
ExaSes_ListOneOrMoreSessionsIcons (Exams,&Session,Anchor);
2020-04-20 01:26:46 +02:00
/* Session participant */
ExaSes_ListOneOrMoreSessionsAuthor (&Session);
2020-04-20 01:26:46 +02:00
/* Start/end date/time */
ExaSes_ListOneOrMoreSessionsTimes (&Session,UniqueId);
2020-04-20 01:26:46 +02:00
/* Title and groups */
ExaSes_ListOneOrMoreSessionsTitleGrps (Exams,&Session,Anchor);
2020-05-05 20:09:28 +02:00
/* Session result visible? */
ExaSes_ListOneOrMoreSessionsResult (Exams,&Session);
2020-05-05 20:09:28 +02:00
/***** End row for this session ****/
2020-05-05 21:49:00 +02:00
HTM_TR_End ();
/***** For to edit this session ****/
if (Session.SesCod == SesCodToBeEdited)
{
HTM_TR_Begin (NULL);
HTM_TD_Begin ("colspan=\"6\" class=\"CT %s\"",
The_GetColorRows ());
ExaSes_PutFormSession (&Session); // Form to edit existing session
HTM_TD_End ();
HTM_TR_End ();
}
/***** Free anchor string *****/
free (Anchor);
}
2020-04-20 01:26:46 +02:00
}
/***** End table with sessions *****/
2020-04-20 01:26:46 +02:00
HTM_TABLE_End ();
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/************* Put a column for exam session start and end times *************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_ListOneOrMoreSessionsHeading (bool ICanEditSessions)
2020-04-20 01:26:46 +02:00
{
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
extern const char *Txt_START_END_TIME[Dat_NUM_START_END_TIME];
2020-05-17 02:28:30 +02:00
extern const char *Txt_Session;
2020-04-20 01:26:46 +02:00
extern const char *Txt_Results;
/***** Begin row *****/
2020-04-20 01:26:46 +02:00
HTM_TR_Begin (NULL);
/***** Column for icons *****/
if (ICanEditSessions)
HTM_TH_Empty (1);
2020-04-20 01:26:46 +02:00
/***** The rest of columns *****/
HTM_TH (Txt_ROLES_SINGUL_Abc[Rol_TCH][Usr_SEX_UNKNOWN],HTM_HEAD_LEFT );
HTM_TH (Txt_START_END_TIME[Exa_ORDER_BY_START_DATE] ,HTM_HEAD_LEFT );
HTM_TH (Txt_START_END_TIME[Exa_ORDER_BY_END_DATE ] ,HTM_HEAD_LEFT );
HTM_TH (Txt_Session ,HTM_HEAD_LEFT );
HTM_TH (Txt_Results ,HTM_HEAD_CENTER);
2020-04-20 01:26:46 +02:00
/***** End row *****/
HTM_TR_End ();
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/********************** Check if I can edit sessions *************************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static bool ExaSes_CheckIfICanEditSessions (void)
2020-04-20 01:26:46 +02:00
{
static const bool ICanEditSessions[Rol_NUM_ROLES] =
2020-04-20 01:26:46 +02:00
{
[Rol_NET ] = true,
[Rol_TCH ] = true,
[Rol_SYS_ADM] = true,
};
return ICanEditSessions[Gbl.Usrs.Me.Role.Logged];
2020-04-20 01:26:46 +02:00
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/************ Check if I can edit (remove/resume) an exam session ************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
static bool ExaSes_CheckIfICanEditThisSession (long UsrCod)
2020-04-20 01:26:46 +02:00
{
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_NET:
return (UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod); // Only if I am the creator
2020-04-20 01:26:46 +02:00
case Rol_TCH:
case Rol_SYS_ADM:
return true;
default:
return false;
}
}
2020-05-30 19:33:55 +02:00
/*****************************************************************************/
/********** Check if visibility of session results can be changed ************/
/*****************************************************************************/
static bool ExaSes_CheckIfVisibilityOfResultsCanBeChanged (const struct ExaSes_Session *Session)
{
if (Session->ShowUsrResults || // Results are currently visible
Session->TimeUTC[Dat_END_TIME] < Dat_GetStartExecutionTimeUTC ()) // End of time is in the past
if (ExaSes_CheckIfICanEditThisSession (Session->UsrCod))
2020-05-30 19:33:55 +02:00
return true;
return false;
}
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
/************************* Put a column for icons ****************************/
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_ListOneOrMoreSessionsIcons (struct Exa_Exams *Exams,
2020-06-23 12:57:31 +02:00
const struct ExaSes_Session *Session,
const char *Anchor)
2020-04-20 01:26:46 +02:00
{
static Act_Action_t ActionHideUnhide[2] =
{
[false] = ActHidExaSes, // Visible ==> action to hide
[true ] = ActUnhExaSes, // Hidden ==> action to unhide
};
Exams->Exam.ExaCod = Session->ExaCod;
Exams->SesCod = Session->SesCod;
2020-05-05 20:09:28 +02:00
/***** Begin cell *****/
HTM_TD_Begin ("class=\"BT %s\"",The_GetColorRows ());
2020-05-05 20:09:28 +02:00
if (ExaSes_CheckIfICanEditThisSession (Session->UsrCod))
{
/***** Icon to remove the exam session *****/
Ico_PutContextualIconToRemove (ActReqRemExaSes,NULL,
ExaSes_PutParsEdit,Exams);
/***** Icon to hide/unhide the exam session *****/
Ico_PutContextualIconToHideUnhide (ActionHideUnhide,Anchor,
ExaSes_PutParsEdit,Exams,
Session->Hidden);
/***** Icon to edit the exam session *****/
Ico_PutContextualIconToEdit (ActEdiOneExaSes,Anchor,
ExaSes_PutParsEdit,Exams);
}
2020-04-20 01:26:46 +02:00
2020-05-05 21:49:00 +02:00
/***** End cell *****/
2020-04-20 01:26:46 +02:00
HTM_TD_End ();
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/********** Put a column for teacher who created the exam session ************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_ListOneOrMoreSessionsAuthor (const struct ExaSes_Session *Session)
2020-04-20 01:26:46 +02:00
{
2020-05-17 02:28:30 +02:00
/***** Session author (teacher) *****/
HTM_TD_Begin ("class=\"LT %s\"",The_GetColorRows ());
Usr_WriteAuthor1Line (Session->UsrCod,Session->Hidden);
2020-04-20 01:26:46 +02:00
HTM_TD_End ();
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/************* Put a column for exam session start and end times *************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_ListOneOrMoreSessionsTimes (const struct ExaSes_Session *Session,
unsigned UniqueId)
2020-04-20 01:26:46 +02:00
{
Dat_StartEndTime_t StartEndTime;
2020-05-05 20:09:28 +02:00
const char *Color;
2020-04-20 01:26:46 +02:00
char *Id;
for (StartEndTime = (Dat_StartEndTime_t) 0;
StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
StartEndTime++)
{
2020-05-17 02:28:30 +02:00
Color = Session->Open ? (Session->Hidden ? "DATE_GREEN_LIGHT":
"DATE_GREEN") :
(Session->Hidden ? "DATE_RED_LIGHT":
"DATE_RED");
2020-05-05 20:09:28 +02:00
2020-04-20 01:26:46 +02:00
if (asprintf (&Id,"exa_time_%u_%u",(unsigned) StartEndTime,UniqueId) < 0)
Err_NotEnoughMemoryExit ();
HTM_TD_Begin ("id=\"%s\" class=\"LT %s_%s %s\"",
Id,Color,The_GetSuffix (),The_GetColorRows ());
Dat_WriteLocalDateHMSFromUTC (Id,Session->TimeUTC[StartEndTime],
Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK,
true,true,true,0x6);
2020-04-20 01:26:46 +02:00
HTM_TD_End ();
free (Id);
}
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/************** Put a column for exam session title and grous ****************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_ListOneOrMoreSessionsTitleGrps (struct Exa_Exams *Exams,
2020-05-21 16:59:14 +02:00
const struct ExaSes_Session *Session,
const char *Anchor)
2020-04-20 01:26:46 +02:00
{
extern const char *Txt_Play;
extern const char *Txt_Resume;
HTM_TD_Begin ("class=\"LT %s\"",The_GetColorRows ());
2020-04-20 01:26:46 +02:00
/***** Session title *****/
HTM_ARTICLE_Begin (Anchor);
if (ExaSes_CheckIfICanAnswerThisSession (&Exams->Exam,Session))
{
Frm_BeginForm (ActSeeExaPrn);
Exa_PutPars (Exams);
ParCod_PutPar (ParCod_Ses,Session->SesCod);
HTM_BUTTON_Submit_Begin (Gbl.Usrs.Me.Role.Logged == Rol_STD ? Txt_Play :
Txt_Resume,
"class=\"LT BT_LINK %s_%s\"",
Session->Hidden ? "ASG_TITLE_LIGHT" :
"ASG_TITLE",
The_GetSuffix ());
HTM_Txt (Session->Title);
HTM_BUTTON_End ();
Frm_EndForm ();
}
else
{
HTM_SPAN_Begin ("class=\"%s_%s\"",
Session->Hidden ? "ASG_TITLE_LIGHT" :
"ASG_TITLE",
The_GetSuffix ());
HTM_Txt (Session->Title);
HTM_SPAN_End ();
}
HTM_ARTICLE_End ();
2020-04-20 01:26:46 +02:00
/***** Groups whose students can answer this exam session *****/
if (Gbl.Crs.Grps.NumGrps)
ExaSes_GetAndWriteNamesOfGrpsAssociatedToSession (Session);
2020-04-20 01:26:46 +02:00
HTM_TD_End ();
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/********* Get and write the names of the groups of an exam session **********/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_GetAndWriteNamesOfGrpsAssociatedToSession (const struct ExaSes_Session *Session)
2020-04-20 01:26:46 +02:00
{
extern const char *Txt_Group;
extern const char *Txt_Groups;
extern const char *Txt_and;
extern const char *Txt_The_whole_course;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumGrps;
unsigned NumGrp;
2020-04-20 01:26:46 +02:00
/***** Get groups *****/
NumGrps = Exa_DB_GetGrpsAssociatedToSes (&mysql_res,Session->SesCod);
2020-04-20 01:26:46 +02:00
/***** Write heading *****/
HTM_DIV_Begin ("class=\"%s_%s\"",
Session->Hidden ? "ASG_GRP_LIGHT":
"ASG_GRP",
The_GetSuffix ());
HTM_TxtColonNBSP (NumGrps == 1 ? Txt_Group :
Txt_Groups);
2020-04-20 01:26:46 +02:00
/***** Write groups *****/
if (NumGrps) // Groups found...
{
/* Get and write the group types and names */
for (NumGrp = 0;
NumGrp < NumGrps;
NumGrp++)
{
/* Get next group */
row = mysql_fetch_row (mysql_res);
/* Write group type name (row[0]) and group name (row[1]) */
HTM_TxtF ("%s&nbsp;%s",row[0],row[1]);
if (NumGrps >= 2)
{
if (NumGrp == NumGrps - 2)
HTM_TxtF (" %s ",Txt_and);
if (NumGrps >= 3)
if (NumGrp < NumGrps - 2)
HTM_Txt (", ");
}
}
}
else
HTM_TxtF ("%s&nbsp;%s",Txt_The_whole_course,Gbl.Hierarchy.Crs.ShrtName);
2020-04-20 01:26:46 +02:00
HTM_DIV_End ();
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/************ Put a column for visibility of exam session result *************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_ListOneOrMoreSessionsResult (struct Exa_Exams *Exams,
const struct ExaSes_Session *Session)
2020-04-20 01:26:46 +02:00
{
static void (*Function[Rol_NUM_ROLES]) (struct Exa_Exams *Exams,
const struct ExaSes_Session *Session) =
{
[Rol_STD ] = ExaSes_ListOneOrMoreSessionsResultStd,
[Rol_NET ] = ExaSes_ListOneOrMoreSessionsResultTch,
[Rol_TCH ] = ExaSes_ListOneOrMoreSessionsResultTch,
[Rol_SYS_ADM] = ExaSes_ListOneOrMoreSessionsResultTch,
};
HTM_TD_Begin ("class=\"CT DAT_%s %s\"",
The_GetSuffix (),The_GetColorRows ());
2020-04-20 01:26:46 +02:00
if (Function[Gbl.Usrs.Me.Role.Logged])
Function[Gbl.Usrs.Me.Role.Logged] (Exams,Session);
else
Err_WrongRoleExit ();
2020-04-20 01:26:46 +02:00
HTM_TD_End ();
}
2020-05-17 02:28:30 +02:00
static void ExaSes_ListOneOrMoreSessionsResultStd (struct Exa_Exams *Exams,
const struct ExaSes_Session *Session)
2020-04-20 01:26:46 +02:00
{
2020-05-17 02:28:30 +02:00
/***** Is exam session result visible or hidden? *****/
if (Session->ShowUsrResults)
2020-04-20 01:26:46 +02:00
{
/* Result is visible by me */
Exams->Exam.ExaCod = Session->ExaCod;
Exams->SesCod = Session->SesCod;
2020-05-18 02:15:10 +02:00
Lay_PutContextualLinkOnlyIcon (ActSeeMyExaResSes,ExaRes_RESULTS_BOX_ID,
ExaSes_PutParsEdit,Exams,
"trophy.svg",Ico_BLACK);
2020-04-20 01:26:46 +02:00
}
else
/* Result is forbidden to me */
Ico_PutIconNotVisible ();
}
2020-05-17 02:28:30 +02:00
static void ExaSes_ListOneOrMoreSessionsResultTch (struct Exa_Exams *Exams,
const struct ExaSes_Session *Session)
2020-04-20 01:26:46 +02:00
{
extern const char *Txt_Visible_results;
extern const char *Txt_Hidden_results;
Exams->Exam.ExaCod = Session->ExaCod;
Exams->SesCod = Session->SesCod;
2020-04-20 01:26:46 +02:00
2020-05-30 19:33:55 +02:00
/***** Show exam session results *****/
if (ExaSes_CheckIfICanEditThisSession (Session->UsrCod))
2020-05-18 22:59:07 +02:00
Lay_PutContextualLinkOnlyIcon (ActSeeUsrExaResSes,ExaRes_RESULTS_BOX_ID,
ExaSes_PutParsEdit,Exams,
"trophy.svg",Ico_BLACK);
2020-04-20 01:26:46 +02:00
2020-05-30 19:33:55 +02:00
/***** Check if visibility of session results can be changed *****/
if (ExaSes_CheckIfVisibilityOfResultsCanBeChanged (Session))
{
/***** Put form to change visibility of session results *****/
if (Session->ShowUsrResults)
Lay_PutContextualLinkOnlyIcon (ActChgVisExaRes,NULL,
ExaSes_PutParsEdit,Exams,
"eye.svg",Ico_GREEN);
else
Lay_PutContextualLinkOnlyIcon (ActChgVisExaRes,NULL,
ExaSes_PutParsEdit,Exams,
"eye-slash.svg",Ico_RED);
2020-04-20 01:26:46 +02:00
}
2020-05-30 19:33:55 +02:00
else // Don't put form
{
2020-05-30 19:33:55 +02:00
/***** Put icon showing the current visibility of session results *****/
if (Session->ShowUsrResults)
Ico_PutIconOff ("eye.svg" ,Ico_GREEN,Txt_Visible_results);
else
Ico_PutIconOff ("eye-slash.svg",Ico_RED ,Txt_Hidden_results);
}
2020-04-20 01:26:46 +02:00
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/***************** Toggle visibility of exam session results *****************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
void ExaSes_ToggleVisResultsSesUsr (void)
2020-04-20 01:26:46 +02:00
{
struct Exa_Exams Exams;
2020-05-17 02:28:30 +02:00
struct ExaSes_Session Session;
2020-04-20 01:26:46 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset exams context *****/
2020-04-22 03:48:38 +02:00
Exa_ResetExams (&Exams);
Exa_ResetExam (&Exams.Exam);
2020-05-17 02:28:30 +02:00
ExaSes_ResetSession (&Session);
2020-04-23 23:09:28 +02:00
2020-04-20 01:26:46 +02:00
/***** Get and check parameters *****/
ExaSes_GetAndCheckPars (&Exams,&Session);
2020-04-20 01:26:46 +02:00
2020-05-30 19:33:55 +02:00
/***** Check if visibility of session results can be changed *****/
if (!ExaSes_CheckIfVisibilityOfResultsCanBeChanged (&Session))
Err_NoPermissionExit ();
2020-04-20 01:26:46 +02:00
2020-05-17 02:28:30 +02:00
/***** Toggle visibility of exam session results *****/
Session.ShowUsrResults = !Session.ShowUsrResults;
Exa_DB_ToggleVisResultsSesUsr (&Session);
2020-04-20 01:26:46 +02:00
/***** Show current exam *****/
Exa_ShowOnlyOneExam (&Exams,&Session,
2020-05-17 02:28:30 +02:00
false); // Do not put form for session
2020-04-20 01:26:46 +02:00
}
/*****************************************************************************/
/******************** Get exam data from a database row **********************/
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_GetSessionDataFromRow (MYSQL_RES *mysql_res,
struct ExaSes_Session *Session)
2020-04-20 01:26:46 +02:00
{
MYSQL_ROW row;
Dat_StartEndTime_t StartEndTime;
/***** Get next row from result *****/
2020-04-20 01:26:46 +02:00
row = mysql_fetch_row (mysql_res);
/*
2020-05-17 02:28:30 +02:00
row[0] SesCod
2020-05-13 15:22:56 +02:00
row[1] ExaCod
row[2] Hidden
row[3] UsrCod
row[4] UNIX_TIMESTAMP(StartTime)
row[5] UNIX_TIMESTAMP(EndTime)
row[6] Open = NOW() BETWEEN StartTime AND EndTime
row[7] Title
row[8] ShowUsrResults
2020-04-20 01:26:46 +02:00
*/
2020-05-17 02:28:30 +02:00
/***** Get session data *****/
/* Code of the session (row[0]) */
if ((Session->SesCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongExamSessionExit ();
2020-04-20 01:26:46 +02:00
/* Code of the exam (row[1]) */
2020-05-17 02:28:30 +02:00
if ((Session->ExaCod = Str_ConvertStrCodToLongCod (row[1])) <= 0)
Err_WrongExamExit ();
2020-04-20 01:26:46 +02:00
2020-05-17 02:28:30 +02:00
/* Get whether the session is hidden (row[2]) */
Session->Hidden = (row[2][0] == 'Y');
2020-04-20 01:26:46 +02:00
2020-05-17 02:28:30 +02:00
/* Get session teacher (row[3]) */
Session->UsrCod = Str_ConvertStrCodToLongCod (row[3]);
2020-05-05 20:09:28 +02:00
/* Get start/end times (row[4], row[5] hold start/end UTC times) */
2020-04-20 01:26:46 +02:00
for (StartEndTime = (Dat_StartEndTime_t) 0;
StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
StartEndTime++)
2020-05-17 02:28:30 +02:00
Session->TimeUTC[StartEndTime] = Dat_GetUNIXTimeFromStr (row[4 + StartEndTime]);
2020-04-20 01:26:46 +02:00
2020-05-17 02:28:30 +02:00
/* Get whether the session is open or closed (row(6)) */
Session->Open = (row[6][0] == '1');
2020-05-07 01:14:50 +02:00
2020-05-17 02:28:30 +02:00
/* Get the title of the session (row[7]) */
2020-05-07 01:14:50 +02:00
if (row[7])
Str_Copy (Session->Title,row[7],sizeof (Session->Title) - 1);
2020-04-20 01:26:46 +02:00
else
2020-05-17 02:28:30 +02:00
Session->Title[0] = '\0';
2020-04-20 01:26:46 +02:00
2020-05-13 15:22:56 +02:00
/* Get whether to show user results or not (row(8)) */
2020-05-17 02:28:30 +02:00
Session->ShowUsrResults = (row[8][0] == 'Y');
2020-04-20 01:26:46 +02:00
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/********** Request the removal of an exam session (exam instance) ***********/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
void ExaSes_ReqRemSession (void)
2020-04-20 01:26:46 +02:00
{
2020-05-23 20:51:51 +02:00
extern const char *Txt_Do_you_really_want_to_remove_the_session_X;
extern const char *Txt_Remove_session;
2020-04-20 01:26:46 +02:00
struct Exa_Exams Exams;
2020-05-17 02:28:30 +02:00
struct ExaSes_Session Session;
2020-04-20 01:26:46 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset exams context *****/
2020-04-22 03:48:38 +02:00
Exa_ResetExams (&Exams);
Exa_ResetExam (&Exams.Exam);
2020-05-17 02:28:30 +02:00
ExaSes_ResetSession (&Session);
2020-04-23 23:09:28 +02:00
2020-04-20 01:26:46 +02:00
/***** Get and check parameters *****/
ExaSes_GetAndCheckPars (&Exams,&Session);
2020-04-20 01:26:46 +02:00
/***** Show question and button to remove question *****/
Exams.Exam.ExaCod = Session.ExaCod;
Exams.SesCod = Session.SesCod;
2020-05-18 02:15:10 +02:00
Ale_ShowAlertAndButton (ActRemExaSes,NULL,NULL,
ExaSes_PutParsEdit,&Exams,
2020-05-23 20:51:51 +02:00
Btn_REMOVE_BUTTON,Txt_Remove_session,
Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_session_X,
2020-05-17 02:28:30 +02:00
Session.Title);
2020-04-20 01:26:46 +02:00
/***** Show current exam *****/
Exa_ShowOnlyOneExam (&Exams,&Session,
2020-05-17 02:28:30 +02:00
false); // Do not put form for session
2020-04-20 01:26:46 +02:00
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/****************** Remove an exam session (exam instance) *******************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
void ExaSes_RemoveSession (void)
2020-04-20 01:26:46 +02:00
{
2020-05-17 02:28:30 +02:00
extern const char *Txt_Session_X_removed;
2020-04-20 01:26:46 +02:00
struct Exa_Exams Exams;
2020-05-17 02:28:30 +02:00
struct ExaSes_Session Session;
2020-04-20 01:26:46 +02:00
2020-04-23 23:09:28 +02:00
/***** Reset exams context *****/
2020-04-22 03:48:38 +02:00
Exa_ResetExams (&Exams);
Exa_ResetExam (&Exams.Exam);
2020-05-17 02:28:30 +02:00
ExaSes_ResetSession (&Session);
2020-04-23 23:09:28 +02:00
2020-04-20 01:26:46 +02:00
/***** Get and check parameters *****/
ExaSes_GetAndCheckPars (&Exams,&Session);
2020-04-20 01:26:46 +02:00
2020-05-17 02:28:30 +02:00
/***** Check if I can remove this exam session *****/
if (!ExaSes_CheckIfICanEditThisSession (Session.UsrCod))
Err_NoPermissionExit ();
2020-04-20 01:26:46 +02:00
/***** Remove questions of exams prints, and exam prints, in this session *****/
//* TODO: DO NOT REMOVE EXAMS PRINTS. Instead move them to tables of deleted prints
/* To delete orphan exam prints:
// DELETE FROM exa_print_questions WHERE PrnCod IN (SELECT PrnCod FROM exa_prints WHERE SesCod NOT IN (SELECT SesCod FROM exa_sessions));
// DELETE FROM exa_prints WHERE SesCod NOT IN (SELECT SesCod FROM exa_sessions);
*/
Exa_DB_RemovePrintQstsFromSes (Session.SesCod);
Exa_DB_RemoveAllPrintsFromSes (Session.SesCod);
2020-05-17 02:28:30 +02:00
/***** Remove the exam session from all database tables *****/
Exa_DB_RemoveSessionFromAllTables (Session.SesCod);
2020-04-20 01:26:46 +02:00
/***** Write message *****/
2020-05-17 02:28:30 +02:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Session_X_removed,
Session.Title);
2020-04-20 01:26:46 +02:00
2020-05-17 02:28:30 +02:00
/***** Get exam data again to update it after changes in session *****/
Exa_GetExamDataByCod (&Exams.Exam);
2020-05-07 01:14:50 +02:00
2020-04-20 01:26:46 +02:00
/***** Show current exam *****/
Exa_ShowOnlyOneExam (&Exams,&Session,
2020-05-17 02:28:30 +02:00
false); // Do not put form for session
2020-04-20 01:26:46 +02:00
}
/*****************************************************************************/
/******************************** Hide a session *****************************/
2020-05-05 20:09:28 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
void ExaSes_HideSession (void)
2020-05-05 20:09:28 +02:00
{
struct Exa_Exams Exams;
2020-05-17 02:28:30 +02:00
struct ExaSes_Session Session;
2020-05-05 20:09:28 +02:00
/***** Reset exams context *****/
Exa_ResetExams (&Exams);
Exa_ResetExam (&Exams.Exam);
2020-05-17 02:28:30 +02:00
ExaSes_ResetSession (&Session);
2020-05-05 20:09:28 +02:00
/***** Get and check parameters *****/
ExaSes_GetAndCheckPars (&Exams,&Session);
2020-05-05 20:09:28 +02:00
2020-05-17 02:28:30 +02:00
/***** Check if I can remove this exam session *****/
if (!ExaSes_CheckIfICanEditThisSession (Session.UsrCod))
Err_NoPermissionExit ();
2020-05-05 20:09:28 +02:00
2020-05-17 02:28:30 +02:00
/***** Hide session *****/
Exa_DB_HideUnhideSession (&Session,true);
2020-05-05 20:09:28 +02:00
/***** Show current exam *****/
Exa_ShowOnlyOneExam (&Exams,&Session,
2020-05-17 02:28:30 +02:00
false); // Do not put form for session
2020-05-05 20:09:28 +02:00
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/***************************** Unhide an session *****************************/
2020-05-05 20:09:28 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
void ExaSes_UnhideSession (void)
2020-05-05 20:09:28 +02:00
{
struct Exa_Exams Exams;
2020-05-17 02:28:30 +02:00
struct ExaSes_Session Session;
2020-05-05 20:09:28 +02:00
/***** Reset exams context *****/
Exa_ResetExams (&Exams);
Exa_ResetExam (&Exams.Exam);
2020-05-17 02:28:30 +02:00
ExaSes_ResetSession (&Session);
2020-05-05 20:09:28 +02:00
/***** Get and check parameters *****/
ExaSes_GetAndCheckPars (&Exams,&Session);
2020-05-05 20:09:28 +02:00
2020-05-17 02:28:30 +02:00
/***** Check if I can remove this exam session *****/
if (!ExaSes_CheckIfICanEditThisSession (Session.UsrCod))
Err_NoPermissionExit ();
2020-05-05 20:09:28 +02:00
2020-05-17 02:28:30 +02:00
/***** Unhide session *****/
Exa_DB_HideUnhideSession (&Session,false);
2020-05-05 20:09:28 +02:00
/***** Show current exam *****/
Exa_ShowOnlyOneExam (&Exams,&Session,
2020-05-17 02:28:30 +02:00
false); // Do not put form for session
2020-05-05 20:09:28 +02:00
}
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/******************* Params used to edit an exam session *********************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
void ExaSes_PutParsEdit (void *Exams)
2020-04-20 01:26:46 +02:00
{
if (Exams)
{
Exa_PutPars (Exams);
ParCod_PutPar (ParCod_Ses,((struct Exa_Exams *) Exams)->SesCod);
2020-04-20 01:26:46 +02:00
}
}
/*****************************************************************************/
/************************** Get and check parameters *************************/
/*****************************************************************************/
void ExaSes_GetAndCheckPars (struct Exa_Exams *Exams,
struct ExaSes_Session *Session)
2020-04-20 01:26:46 +02:00
{
/***** Get parameters *****/
Exa_GetPars (Exams,Exa_CHECK_EXA_COD);
Grp_GetParWhichGroups ();
Session->SesCod = ParCod_GetAndCheckPar (ParCod_Ses);
2020-04-25 01:36:53 +02:00
2020-05-15 01:07:46 +02:00
/***** Get exam data from database *****/
Exa_GetExamDataByCod (&Exams->Exam);
if (Exams->Exam.CrsCod != Gbl.Hierarchy.Crs.CrsCod)
Err_WrongExamExit ();
2020-04-20 01:26:46 +02:00
2020-05-15 01:07:46 +02:00
/***** Get set data from database *****/
ExaSes_GetSessionDataByCod (Session);
if (Session->ExaCod != Exams->Exam.ExaCod)
Err_WrongSetExit ();
2020-05-17 02:28:30 +02:00
Exams->SesCod = Session->SesCod;
2020-04-20 01:26:46 +02:00
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/* Put a big button to play exam session (start a new session) as a teacher **/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_PutFormSession (const struct ExaSes_Session *Session)
2020-04-20 01:26:46 +02:00
{
2020-05-17 02:28:30 +02:00
extern const char *Hlp_ASSESSMENT_Exams_sessions;
2020-05-18 22:59:07 +02:00
extern const char *Txt_New_session;
2020-04-20 01:26:46 +02:00
extern const char *Txt_Title;
2020-05-18 22:59:07 +02:00
extern const char *Txt_Create_session;
2020-04-28 03:14:25 +02:00
extern const char *Txt_Save_changes;
static const Dat_SetHMS SetHMS[Dat_NUM_START_END_TIME] =
{
[Dat_STR_TIME] = Dat_HMS_DO_NOT_SET,
[Dat_END_TIME] = Dat_HMS_DO_NOT_SET
2020-04-28 03:14:25 +02:00
};
2020-05-17 02:28:30 +02:00
bool ItsANewSession = Session->SesCod <= 0;
2020-04-20 01:26:46 +02:00
/***** Begin section for a new exam session *****/
2020-05-17 02:28:30 +02:00
HTM_SECTION_Begin (ExaSes_NEW_SESSION_SECTION_ID);
2020-04-20 01:26:46 +02:00
/***** Begin form *****/
Frm_BeginForm (ItsANewSession ? ActNewExaSes : // New session
ActChgExaSes); // Existing session
ParCod_PutPar (ParCod_Exa,Session->ExaCod);
if (!ItsANewSession) // Existing session
ParCod_PutPar (ParCod_Ses,Session->SesCod);
2020-05-06 01:43:48 +02:00
/***** Begin box and table *****/
Box_BoxTableBegin (NULL,ItsANewSession ? Txt_New_session :
Session->Title,
NULL,NULL,
Hlp_ASSESSMENT_Exams_sessions,Box_NOT_CLOSABLE,2);
2020-04-20 01:26:46 +02:00
/***** Session title *****/
HTM_TR_Begin (NULL);
2020-04-20 01:26:46 +02:00
/* Label */
Frm_LabelColumn ("RT","Title",Txt_Title);
2020-04-20 01:26:46 +02:00
/* Data */
HTM_TD_Begin ("class=\"LT\"");
HTM_INPUT_TEXT ("Title",ExaSes_MAX_CHARS_TITLE,Session->Title,
HTM_DONT_SUBMIT_ON_CHANGE,
"id=\"Title\" size=\"45\" class=\"INPUT_%s\""
" required=\"required\"",
The_GetSuffix ());
HTM_TD_End ();
2020-04-20 01:26:46 +02:00
HTM_TR_End ();
2020-04-20 01:26:46 +02:00
/***** Start and end dates *****/
Dat_PutFormStartEndClientLocalDateTimes (Session->TimeUTC,
Dat_FORM_SECONDS_OFF,
SetHMS);
2020-04-28 03:14:25 +02:00
/***** Groups *****/
ExaSes_ShowLstGrpsToCreateSession (Session->SesCod);
2020-04-20 01:26:46 +02:00
/***** End table, send button and end box *****/
if (ItsANewSession)
Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_session);
else
Box_BoxTableWithButtonEnd (Btn_CONFIRM_BUTTON,Txt_Save_changes);
2020-04-20 01:26:46 +02:00
/***** End form *****/
Frm_EndForm ();
2020-04-20 01:26:46 +02:00
2020-05-17 02:28:30 +02:00
/***** End section for a new exam session *****/
2020-04-20 01:26:46 +02:00
HTM_SECTION_End ();
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/************* Show list of groups to create a new exam session **************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_ShowLstGrpsToCreateSession (long SesCod)
2020-04-20 01:26:46 +02:00
{
extern const char *Txt_Groups;
extern const char *Txt_The_whole_course;
unsigned NumGrpTyp;
/***** Get list of groups types and groups in this course *****/
Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_ONLY_GROUP_TYPES_WITH_GROUPS);
if (Gbl.Crs.Grps.GrpTypes.NumGrpTypes)
2020-04-20 01:26:46 +02:00
{
/***** Begin box and table *****/
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"RT FORM_IN_%s\"",The_GetSuffix ());
HTM_TxtColon (Txt_Groups);
HTM_TD_End ();
HTM_TD_Begin ("class=\"LT\"");
Box_BoxTableBegin ("95%",NULL,
NULL,NULL,
NULL,Box_NOT_CLOSABLE,0);
/***** First row: checkbox to select the whole course *****/
HTM_TR_Begin (NULL);
HTM_TD_Begin ("colspan=\"7\" class=\"LM DAT_%s\"",
The_GetSuffix ());
HTM_LABEL_Begin (NULL);
HTM_INPUT_CHECKBOX ("WholeCrs",HTM_DONT_SUBMIT_ON_CHANGE,
"id=\"WholeCrs\" value=\"Y\"%s"
" onclick=\"uncheckChildren(this,'GrpCods')\"",
Grp_DB_CheckIfAssociatedToGrps ("exa_groups",
"SesCod",
SesCod) ? "" :
" checked=\"checked\"");
HTM_TxtF ("%s&nbsp;%s",Txt_The_whole_course,Gbl.Hierarchy.Crs.ShrtName);
HTM_LABEL_End ();
HTM_TD_End ();
HTM_TR_End ();
/***** List the groups for each group type *****/
for (NumGrpTyp = 0;
NumGrpTyp < Gbl.Crs.Grps.GrpTypes.NumGrpTypes;
NumGrpTyp++)
if (Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps)
Grp_ListGrpsToEditAsgAttSvyEvtMch (&Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp],
Grp_EXA_EVENT,SesCod);
/***** End table and box *****/
Box_BoxTableEnd ();
HTM_TD_End ();
2020-04-20 01:26:46 +02:00
HTM_TR_End ();
}
/***** Free list of groups types and groups in this course *****/
Grp_FreeListGrpTypesAndGrps ();
}
2020-04-28 03:14:25 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/******************** Put button to create a new session *********************/
2020-04-28 03:14:25 +02:00
/*****************************************************************************/
void ExaSes_PutButtonNewSession (struct Exa_Exams *Exams)
2020-04-28 03:14:25 +02:00
{
2020-05-18 22:59:07 +02:00
extern const char *Txt_New_session;
2020-04-28 03:14:25 +02:00
Frm_BeginFormAnchor (ActReqNewExaSes,ExaSes_NEW_SESSION_SECTION_ID);
Exa_PutPars (Exams);
Btn_PutConfirmButton (Txt_New_session);
2020-04-28 03:14:25 +02:00
Frm_EndForm ();
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/****************** Request the creation of a new session ********************/
2020-04-28 03:14:25 +02:00
/*****************************************************************************/
void ExaSes_ReqCreatOrEditSes (void)
2020-04-28 03:14:25 +02:00
{
struct Exa_Exams Exams;
2020-05-17 02:28:30 +02:00
struct ExaSes_Session Session;
bool ItsANewSession;
2020-04-28 03:14:25 +02:00
/***** Reset exams context *****/
Exa_ResetExams (&Exams);
Exa_ResetExam (&Exams.Exam);
2020-05-17 02:28:30 +02:00
ExaSes_ResetSession (&Session);
2020-04-28 03:14:25 +02:00
/***** Get parameters *****/
Exa_GetPars (&Exams,Exa_CHECK_EXA_COD);
Grp_GetParWhichGroups ();
Session.SesCod = ParCod_GetPar (ParCod_Ses);
2020-05-17 02:28:30 +02:00
ItsANewSession = (Session.SesCod <= 0);
2020-04-28 03:14:25 +02:00
/***** Get exam data from database *****/
Exa_GetExamDataByCod (&Exams.Exam);
if (Exams.Exam.CrsCod != Gbl.Hierarchy.Crs.CrsCod)
Err_WrongExamExit ();
2020-04-28 03:14:25 +02:00
2020-05-17 02:28:30 +02:00
/***** Get session data *****/
if (ItsANewSession)
/* Initialize to empty session */
ExaSes_ResetSession (&Session);
2020-05-05 21:49:00 +02:00
else
{
2020-05-17 02:28:30 +02:00
/* Get session data from database */
ExaSes_GetSessionDataByCod (&Session);
if (Exams.Exam.ExaCod != Session.ExaCod)
Err_WrongExamExit ();
2020-05-17 02:28:30 +02:00
Exams.SesCod = Session.SesCod;
2020-05-05 21:49:00 +02:00
}
2020-04-28 03:14:25 +02:00
/***** Show exam *****/
Exa_ShowOnlyOneExam (&Exams,&Session,
2020-05-17 02:28:30 +02:00
true); // Put form for session
2020-04-28 03:14:25 +02:00
}
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/****************** Create a new exam session (by a teacher) *****************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
void ExaSes_ReceiveFormSession (void)
2020-04-20 01:26:46 +02:00
{
2020-04-28 12:05:33 +02:00
extern const char *Txt_Created_new_event_X;
2020-05-06 01:43:48 +02:00
extern const char *Txt_The_event_has_been_modified;
2020-04-28 12:05:33 +02:00
struct Exa_Exams Exams;
2020-05-17 02:28:30 +02:00
struct ExaSes_Session Session;
bool ItsANewSession;
2020-04-28 12:05:33 +02:00
/***** Reset exams context *****/
Exa_ResetExams (&Exams);
Exa_ResetExam (&Exams.Exam);
2020-05-17 02:28:30 +02:00
ExaSes_ResetSession (&Session);
2020-04-20 01:26:46 +02:00
2020-05-06 01:43:48 +02:00
/***** Get main parameters *****/
Exa_GetPars (&Exams,Exa_CHECK_EXA_COD);
Grp_GetParWhichGroups ();
Session.SesCod = ParCod_GetPar (ParCod_Ses);
2020-05-17 02:28:30 +02:00
ItsANewSession = (Session.SesCod <= 0);
2020-05-06 01:43:48 +02:00
/***** Get exam data from database *****/
Exa_GetExamDataByCod (&Exams.Exam);
if (Exams.Exam.CrsCod != Gbl.Hierarchy.Crs.CrsCod)
Err_WrongExamExit ();
2020-05-06 01:43:48 +02:00
2020-05-17 02:28:30 +02:00
/***** Get session data from database *****/
if (ItsANewSession)
2020-05-10 15:23:11 +02:00
{
2020-05-17 02:28:30 +02:00
/* Initialize to empty session */
ExaSes_ResetSession (&Session);
Session.ExaCod = Exams.Exam.ExaCod;
2020-05-10 15:23:11 +02:00
}
2020-05-06 01:43:48 +02:00
else
{
2020-05-17 02:28:30 +02:00
/* Get session data from database */
ExaSes_GetSessionDataByCod (&Session);
if (Session.ExaCod != Exams.Exam.ExaCod)
Err_WrongExamExit ();
2020-05-17 02:28:30 +02:00
Exams.SesCod = Session.SesCod;
2020-05-06 01:43:48 +02:00
}
2020-04-20 01:26:46 +02:00
2020-05-06 01:43:48 +02:00
/***** Get parameters from form *****/
2020-05-17 02:28:30 +02:00
/* Get session title */
Par_GetParText ("Title",Session.Title,ExaSes_MAX_BYTES_TITLE);
2020-04-20 01:26:46 +02:00
2020-04-28 13:12:18 +02:00
/* Get start/end date-times */
Session.TimeUTC[Dat_STR_TIME] = Dat_GetTimeUTCFromForm (Dat_STR_TIME);
Session.TimeUTC[Dat_END_TIME] = Dat_GetTimeUTCFromForm (Dat_END_TIME);
2020-04-28 13:12:18 +02:00
2020-05-17 02:28:30 +02:00
/* Get groups associated to the session */
2020-04-20 01:26:46 +02:00
Grp_GetParCodsSeveralGrps ();
2020-05-17 02:28:30 +02:00
/***** Create/update session *****/
if (ItsANewSession)
ExaSes_CreateSession (&Session);
2020-05-06 01:43:48 +02:00
else
2020-05-30 19:33:55 +02:00
{
if (Session.TimeUTC[Dat_END_TIME] >= Dat_GetStartExecutionTimeUTC ()) // End of time is in the future
2020-05-30 19:33:55 +02:00
Session.ShowUsrResults = false; // Force results to be hidden
2020-05-17 02:28:30 +02:00
ExaSes_UpdateSession (&Session);
2020-05-30 19:33:55 +02:00
}
2020-04-20 01:26:46 +02:00
/***** Free memory for list of selected groups *****/
Grp_FreeListCodSelectedGrps ();
2020-04-28 12:05:33 +02:00
2020-05-06 01:43:48 +02:00
/***** Write success message *****/
2020-05-17 02:28:30 +02:00
if (ItsANewSession)
2020-05-06 01:43:48 +02:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Created_new_event_X,
2020-05-17 02:28:30 +02:00
Session.Title);
2020-05-06 01:43:48 +02:00
else
Ale_ShowAlert (Ale_SUCCESS,Txt_The_event_has_been_modified);
2020-04-28 12:05:33 +02:00
2020-05-17 02:28:30 +02:00
/***** Get exam data again to update it after changes in session *****/
Exa_GetExamDataByCod (&Exams.Exam);
2020-05-07 01:14:50 +02:00
2020-04-28 12:05:33 +02:00
/***** Show current exam *****/
Exa_ShowOnlyOneExam (&Exams,&Session,
2020-05-17 02:28:30 +02:00
false); // Do not put form for session
2020-04-20 01:26:46 +02:00
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/*************************** Create a new session ****************************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_CreateSession (struct ExaSes_Session *Session)
2020-04-20 01:26:46 +02:00
{
2020-05-17 02:28:30 +02:00
/***** Insert this new exam session into database *****/
Session->SesCod = Exa_DB_CreateSession (Session);
2020-04-20 01:26:46 +02:00
2020-05-17 02:28:30 +02:00
/***** Create groups associated to the exam session *****/
2020-04-20 01:26:46 +02:00
if (Gbl.Crs.Grps.LstGrpsSel.NumGrps)
ExaSes_CreateGrpsAssociatedToExamSession (Session->SesCod,&Gbl.Crs.Grps.LstGrpsSel);
2020-04-20 01:26:46 +02:00
}
2020-05-06 01:43:48 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/************************ Update an existing session *************************/
2020-05-06 01:43:48 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
static void ExaSes_UpdateSession (struct ExaSes_Session *Session)
2020-05-06 01:43:48 +02:00
{
2020-05-17 02:28:30 +02:00
/***** Insert this new exam session into database *****/
Exa_DB_UpdateSession (Session);
2020-05-06 01:43:48 +02:00
2020-05-17 02:28:30 +02:00
/***** Update groups associated to the exam session *****/
Exa_DB_RemoveAllGrpsFromSes (Session->SesCod); // Remove all groups associated to this session
2020-05-06 01:43:48 +02:00
if (Gbl.Crs.Grps.LstGrpsSel.NumGrps)
ExaSes_CreateGrpsAssociatedToExamSession (Session->SesCod,&Gbl.Crs.Grps.LstGrpsSel); // Associate new groups
2020-05-06 01:43:48 +02:00
}
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/*************** Create groups associated to an exam session *****************/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
static void ExaSes_CreateGrpsAssociatedToExamSession (long SesCod,
const struct ListCodGrps *LstGrpsSel)
2020-04-20 01:26:46 +02:00
{
unsigned NumGrpSel;
2020-05-17 02:28:30 +02:00
/***** Create groups associated to the exam session *****/
2020-04-20 01:26:46 +02:00
for (NumGrpSel = 0;
NumGrpSel < LstGrpsSel->NumGrps;
2020-04-20 01:26:46 +02:00
NumGrpSel++)
/* Create group */
Exa_DB_CreateGrpAssociatedToSes (SesCod,LstGrpsSel->GrpCods[NumGrpSel]);
2020-04-20 01:26:46 +02:00
}
/*****************************************************************************/
2020-05-17 02:28:30 +02:00
/******** Check if I belong to any of the groups of an exam session **********/
2020-04-20 01:26:46 +02:00
/*****************************************************************************/
2020-05-21 16:59:14 +02:00
bool ExaSes_CheckIfICanAnswerThisSession (const struct Exa_Exam *Exam,
const struct ExaSes_Session *Session)
2020-05-15 01:07:46 +02:00
{
2020-05-21 16:59:14 +02:00
/***** 1. Sessions in hidden exams are not accesible
2. Hidden or closed sessions are not accesible *****/
if (Exam->Hidden ||
Session->Hidden ||
!Session->Open)
2020-05-15 01:07:46 +02:00
return false;
2020-05-21 16:59:14 +02:00
/***** Exam is visible, session is visible and open ==>
==> I can answer this session if I can list it based on groups *****/
2020-05-17 02:28:30 +02:00
return ExaSes_CheckIfICanListThisSessionBasedOnGrps (Session->SesCod);
2020-05-15 01:07:46 +02:00
}
2020-05-17 02:28:30 +02:00
bool ExaSes_CheckIfICanListThisSessionBasedOnGrps (long SesCod)
2020-04-20 01:26:46 +02:00
{
2020-05-13 15:22:56 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_STD:
/***** Check if I belong to any of the groups
2020-05-17 02:28:30 +02:00
associated to the exam session *****/
return Exa_DB_CheckIfICanListThisSessionBasedOnGrps (SesCod);
2020-05-13 15:22:56 +02:00
case Rol_NET:
case Rol_TCH:
case Rol_SYS_ADM:
return true;
default:
return false;
}
2020-04-20 01:26:46 +02:00
}