// swad_attendance.c: control of attendance
/*
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-2019 Antonio Caņas Vargas
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 .
*/
/*****************************************************************************/
/********************************** Headers **********************************/
/*****************************************************************************/
#include // For PATH_MAX
#include // For NULL
#include // To access MySQL databases
#include // For calloc
#include // For string functions
#include "swad_attendance.h"
#include "swad_box.h"
#include "swad_database.h"
#include "swad_form.h"
#include "swad_global.h"
#include "swad_group.h"
#include "swad_HTML.h"
#include "swad_ID.h"
#include "swad_pagination.h"
#include "swad_parameter.h"
#include "swad_photo.h"
#include "swad_QR.h"
#include "swad_setting.h"
/*****************************************************************************/
/*************** External global variables from others modules ***************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/****************************** Private constants ****************************/
/*****************************************************************************/
#define Att_ATTENDANCE_TABLE_ID "att_table"
#define Att_ATTENDANCE_DETAILS_ID "att_details"
/*****************************************************************************/
/******************************** Private types ******************************/
/*****************************************************************************/
typedef enum
{
Att_NORMAL_VIEW_ONLY_ME,
Att_NORMAL_VIEW_STUDENTS,
Att_PRINT_VIEW,
} Att_TypeOfView_t;
/*****************************************************************************/
/****************************** Private variables ****************************/
/*****************************************************************************/
/*****************************************************************************/
/****************************** Private prototypes ***************************/
/*****************************************************************************/
static void Att_ShowAllAttEvents (void);
static void Att_ParamsWhichGroupsToShow (void);
static void Att_PutIconsInListOfAttEvents (void);
static void Att_PutIconToCreateNewAttEvent (void);
static void Att_PutButtonToCreateNewAttEvent (void);
static void Att_PutParamsToCreateNewAttEvent (void);
static void Att_ShowOneAttEvent (struct AttendanceEvent *Att,bool ShowOnlyThisAttEventComplete);
static void Att_WriteAttEventAuthor (struct AttendanceEvent *Att);
static void Att_GetParamAttOrder (void);
static void Att_PutFormToListMyAttendance (void);
static void Att_PutFormToListStdsAttendance (void);
static void Att_PutFormToListStdsParams (void);
static void Att_PutFormsToRemEditOneAttEvent (const struct AttendanceEvent *Att,
const char *Anchor);
static void Att_PutParams (void);
static void Att_GetListAttEvents (Att_OrderNewestOldest_t OrderNewestOldest);
static void Att_GetDataOfAttEventByCodAndCheckCrs (struct AttendanceEvent *Att);
static void Att_ResetAttendanceEvent (struct AttendanceEvent *Att);
static void Att_GetAttEventDescriptionFromDB (long AttCod,char Description[Cns_MAX_BYTES_TEXT + 1]);
static bool Att_CheckIfSimilarAttEventExists (const char *Field,const char *Value,long AttCod);
static void Att_ShowLstGrpsToEditAttEvent (long AttCod);
static void Att_RemoveAllTheGrpsAssociatedToAnAttEvent (long AttCod);
static void Att_CreateGrps (long AttCod);
static void Att_GetAndWriteNamesOfGrpsAssociatedToAttEvent (struct AttendanceEvent *Att);
static void Att_RemoveAllUsrsFromAnAttEvent (long AttCod);
static void Att_RemoveAttEventFromCurrentCrs (long AttCod);
static void Att_ListAttOnlyMeAsStudent (struct AttendanceEvent *Att);
static void Att_ListAttStudents (struct AttendanceEvent *Att);
static void Att_WriteRowUsrToCallTheRoll (unsigned NumUsr,
struct UsrData *UsrDat,
struct AttendanceEvent *Att);
static void Att_PutLinkAttEvent (struct AttendanceEvent *AttEvent,
const char *Title,const char *Txt,
const char *LinkStyle);
static void Att_PutParamsCodGrps (long AttCod);
static void Att_GetNumStdsTotalWhoAreInAttEvent (struct AttendanceEvent *Att);
static unsigned Att_GetNumStdsFromAListWhoAreInAttEvent (long AttCod,long LstSelectedUsrCods[],unsigned NumUsrsInList);
static bool Att_CheckIfUsrIsInTableAttUsr (long AttCod,long UsrCod,bool *Present);
static bool Att_CheckIfUsrIsPresentInAttEvent (long AttCod,long UsrCod);
static bool Att_CheckIfUsrIsPresentInAttEventAndGetComments (long AttCod,long UsrCod,
char CommentStd[Cns_MAX_BYTES_TEXT + 1],
char CommentTch[Cns_MAX_BYTES_TEXT + 1]);
static void Att_RegUsrInAttEventChangingComments (long AttCod,long UsrCod,bool Present,
const char *CommentStd,const char *CommentTch);
static void Att_RemoveUsrFromAttEvent (long AttCod,long UsrCod);
static void Usr_ListOrPrintMyAttendanceCrs (Att_TypeOfView_t TypeOfView);
static void Usr_ListOrPrintUsrsAttendanceCrs (Att_TypeOfView_t TypeOfView);
static void Att_GetListSelectedUsrCods (unsigned NumUsrsInList,long **LstSelectedUsrCods);
static void Att_GetListSelectedAttCods (char **StrAttCodsSelected);
static void Att_PutIconsMyAttList (void);
static void Att_PutFormToPrintMyListParams (void);
static void Att_PutIconsStdsAttList (void);
static void Att_PutParamsToPrintStdsList (void);
static void Att_PutButtonToShowDetails (void);
static void Att_ListEventsToSelect (Att_TypeOfView_t TypeOfView);
static void Att_PutIconToEditAttEvents (void);
static void Att_PutIconToViewAttEvents (void);
static void Att_ListUsrsAttendanceTable (Att_TypeOfView_t TypeOfView,
unsigned NumUsrsInList,
long *LstSelectedUsrCods);
static void Att_WriteTableHeadSeveralAttEvents (void);
static void Att_WriteRowUsrSeveralAttEvents (unsigned NumUsr,struct UsrData *UsrDat);
static void Att_PutCheckOrCross (bool Present);
static void Att_ListStdsWithAttEventsDetails (unsigned NumUsrsInList,
long *LstSelectedUsrCods);
static void Att_ListAttEventsForAStd (unsigned NumUsr,struct UsrData *UsrDat);
/*****************************************************************************/
/********************** List all the attendance events ***********************/
/*****************************************************************************/
void Att_SeeAttEvents (void)
{
/***** Get parameters *****/
Att_GetParamAttOrder ();
Grp_GetParamWhichGrps ();
Gbl.AttEvents.CurrentPage = Pag_GetParamPagNum (Pag_ATT_EVENTS);
/***** Get list of attendance events *****/
Att_GetListAttEvents (Att_NEWEST_FIRST);
/***** Put link to show list of attendance *****/
if (Gbl.AttEvents.Num &&
Gbl.Usrs.Me.UsrDat.Nickname[0])
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_STD:
fprintf (Gbl.F.Out,"