2021-05-13 12:50:36 +02:00
|
|
|
|
// swad_attendance_database.c: control of attendance operations with database
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
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.
|
2024-02-07 00:40:28 +01:00
|
|
|
|
Copyright (C) 1999-2024 Antonio Ca<EFBFBD>as Vargas
|
2021-05-13 12:50:36 +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 **********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-11-09 00:38:11 +01:00
|
|
|
|
#define _GNU_SOURCE // For asprintf
|
2021-05-13 12:50:36 +02:00
|
|
|
|
#include <mysql/mysql.h> // To access MySQL databases
|
2021-11-09 00:38:11 +01:00
|
|
|
|
#include <stdio.h> // For asprintf
|
2021-11-24 21:20:25 +01:00
|
|
|
|
#include <stdlib.h> // For free
|
2021-05-13 12:50:36 +02:00
|
|
|
|
|
|
|
|
|
#include "swad_attendance.h"
|
|
|
|
|
#include "swad_attendance_database.h"
|
|
|
|
|
#include "swad_database.h"
|
|
|
|
|
#include "swad_error.h"
|
|
|
|
|
#include "swad_global.h"
|
2023-09-22 14:47:56 +02:00
|
|
|
|
#include "swad_hierarchy_type.h"
|
2021-11-09 13:08:08 +01:00
|
|
|
|
#include "swad_user_database.h"
|
2021-05-13 12:50:36 +02:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************** External global variables from others modules ***************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************************* Public variables ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned (*Att_DB_GetListAttEvents[Grp_NUM_WHICH_GROUPS]) (MYSQL_RES **mysql_res,
|
|
|
|
|
Dat_StartEndTime_t SelectedOrder,
|
|
|
|
|
Att_OrderNewestOldest_t OrderNewestOldest) =
|
|
|
|
|
{
|
2023-03-23 09:35:20 +01:00
|
|
|
|
[Grp_MY_GROUPS ] = Att_DB_GetListEventsMyGrps,
|
|
|
|
|
[Grp_ALL_GROUPS] = Att_DB_GetListEventsAllGrps,
|
2021-05-13 12:50:36 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************************** Private constants ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static const char *Att_DB_HiddenSubQuery[Rol_NUM_ROLES] =
|
|
|
|
|
{
|
|
|
|
|
[Rol_UNK ] = " AND Hidden='N'",
|
|
|
|
|
[Rol_GST ] = " AND Hidden='N'",
|
|
|
|
|
[Rol_USR ] = " AND Hidden='N'",
|
|
|
|
|
[Rol_STD ] = " AND Hidden='N'",
|
|
|
|
|
[Rol_NET ] = " AND Hidden='N'",
|
|
|
|
|
[Rol_TCH ] = "",
|
|
|
|
|
[Rol_DEG_ADM] = " AND Hidden='N'",
|
|
|
|
|
[Rol_CTR_ADM] = " AND Hidden='N'",
|
|
|
|
|
[Rol_INS_ADM] = " AND Hidden='N'",
|
|
|
|
|
[Rol_SYS_ADM] = "",
|
|
|
|
|
};
|
2023-03-23 09:35:20 +01:00
|
|
|
|
|
2021-05-13 12:50:36 +02:00
|
|
|
|
static const char *Att_DB_OrderBySubQuery[Dat_NUM_START_END_TIME][Att_NUM_ORDERS_NEWEST_OLDEST] =
|
|
|
|
|
{
|
2021-09-18 18:22:26 +02:00
|
|
|
|
[Dat_STR_TIME][Att_NEWEST_FIRST] = "StartTime DESC,"
|
|
|
|
|
"EndTime DESC,"
|
|
|
|
|
"Title DESC",
|
|
|
|
|
[Dat_STR_TIME][Att_OLDEST_FIRST] = "StartTime,"
|
|
|
|
|
"EndTime,"
|
|
|
|
|
"Title",
|
|
|
|
|
[Dat_END_TIME][Att_NEWEST_FIRST] = "EndTime DESC,"
|
2023-03-23 09:35:20 +01:00
|
|
|
|
"StartTime DESC,"
|
|
|
|
|
"Title DESC",
|
2021-09-18 18:22:26 +02:00
|
|
|
|
[Dat_END_TIME][Att_OLDEST_FIRST] = "EndTime,"
|
2023-03-23 09:35:20 +01:00
|
|
|
|
"StartTime,"
|
|
|
|
|
"Title",
|
2021-05-13 12:50:36 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************** Get list of attendance events in my groups *****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
unsigned Att_DB_GetListEventsMyGrps (MYSQL_RES **mysql_res,
|
|
|
|
|
Dat_StartEndTime_t SelectedOrder,
|
|
|
|
|
Att_OrderNewestOldest_t OrderNewestOldest)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get attendance events",
|
|
|
|
|
"SELECT AttCod"
|
|
|
|
|
" FROM att_events"
|
|
|
|
|
" WHERE CrsCod=%ld"
|
|
|
|
|
"%s"
|
|
|
|
|
" AND (AttCod NOT IN"
|
|
|
|
|
" (SELECT AttCod"
|
|
|
|
|
" FROM att_groups)"
|
|
|
|
|
" OR"
|
|
|
|
|
" AttCod IN"
|
|
|
|
|
" (SELECT att_groups.AttCod"
|
|
|
|
|
" FROM grp_users,"
|
|
|
|
|
"att_groups"
|
|
|
|
|
" WHERE grp_users.UsrCod=%ld"
|
|
|
|
|
" AND att_groups.GrpCod=grp_users.GrpCod))"
|
|
|
|
|
" ORDER BY %s",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CRS].HieCod,
|
2021-05-13 12:50:36 +02:00
|
|
|
|
Att_DB_HiddenSubQuery[Gbl.Usrs.Me.Role.Logged],
|
|
|
|
|
Gbl.Usrs.Me.UsrDat.UsrCod,
|
|
|
|
|
Att_DB_OrderBySubQuery[SelectedOrder][OrderNewestOldest]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Get list of all attendance events *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
unsigned Att_DB_GetListEventsAllGrps (MYSQL_RES **mysql_res,
|
|
|
|
|
Dat_StartEndTime_t SelectedOrder,
|
|
|
|
|
Att_OrderNewestOldest_t OrderNewestOldest)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get attendance events",
|
|
|
|
|
"SELECT AttCod"
|
|
|
|
|
" FROM att_events"
|
|
|
|
|
" WHERE CrsCod=%ld%s"
|
|
|
|
|
" ORDER BY %s",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CRS].HieCod,
|
2021-05-13 12:50:36 +02:00
|
|
|
|
Att_DB_HiddenSubQuery[Gbl.Usrs.Me.Role.Logged],
|
|
|
|
|
Att_DB_OrderBySubQuery[SelectedOrder][OrderNewestOldest]);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-08 19:16:51 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Get list of all attendance events *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
unsigned Att_DB_GetAllEventsData (MYSQL_RES **mysql_res,long CrsCod)
|
2021-11-08 19:16:51 +01:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get attendance events",
|
2023-03-22 11:00:48 +01:00
|
|
|
|
"SELECT AttCod," // row[0]
|
|
|
|
|
"CrsCod," // row[1]
|
|
|
|
|
"Hidden," // row[2]
|
|
|
|
|
"UsrCod," // row[3]
|
|
|
|
|
"UNIX_TIMESTAMP(StartTime) AS ST," // row[4]
|
|
|
|
|
"UNIX_TIMESTAMP(EndTime) AS ET," // row[5]
|
|
|
|
|
"NOW() BETWEEN StartTime AND EndTime," // row[6]
|
|
|
|
|
"CommentTchVisible," // row[7]
|
|
|
|
|
"Title," // row[8]
|
|
|
|
|
"Txt" // row[9]
|
2021-11-08 19:16:51 +01:00
|
|
|
|
" FROM att_events"
|
|
|
|
|
" WHERE CrsCod=%d"
|
|
|
|
|
" ORDER BY ST DESC,"
|
|
|
|
|
"ET DESC,"
|
|
|
|
|
"Title DESC",
|
|
|
|
|
CrsCod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-13 12:50:36 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************** Get attendance event data using its code *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
unsigned Att_DB_GetEventDataByCod (MYSQL_RES **mysql_res,long AttCod)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get attendance event data",
|
|
|
|
|
"SELECT AttCod," // row[0]
|
|
|
|
|
"CrsCod," // 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]
|
|
|
|
|
"CommentTchVisible," // row[7]
|
|
|
|
|
"Title" // row[8]
|
|
|
|
|
" FROM att_events"
|
|
|
|
|
" WHERE AttCod=%ld",
|
|
|
|
|
AttCod);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-20 00:06:38 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************** Get attendance event title from database ******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-04-06 22:39:26 +02:00
|
|
|
|
void Att_DB_GetEventTitle (long AttCod,char *Title,size_t TitleSize)
|
2022-09-20 00:06:38 +02:00
|
|
|
|
{
|
2023-04-06 22:39:26 +02:00
|
|
|
|
DB_QuerySELECTString (Title,TitleSize,"can not get attendance event title",
|
2022-09-20 00:06:38 +02:00
|
|
|
|
"SELECT Title" // row[0]
|
|
|
|
|
" FROM att_events"
|
|
|
|
|
" WHERE AttCod=%ld"
|
|
|
|
|
" AND CrsCod=%ld", // Extra check
|
|
|
|
|
AttCod,
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CRS].HieCod);
|
2022-09-20 00:06:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-13 12:50:36 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************** Get attendance event text from database *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
void Att_DB_GetEventDescription (long AttCod,char Description[Cns_MAX_BYTES_TEXT + 1])
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
DB_QuerySELECTString (Description,Cns_MAX_BYTES_TEXT,"can not get attendance event text",
|
2022-09-20 00:06:38 +02:00
|
|
|
|
"SELECT Txt" // row[0]
|
2021-05-13 12:50:36 +02:00
|
|
|
|
" FROM att_events"
|
|
|
|
|
" WHERE AttCod=%ld"
|
2022-09-20 00:06:38 +02:00
|
|
|
|
" AND CrsCod=%ld", // Extra check
|
2021-05-13 12:50:36 +02:00
|
|
|
|
AttCod,
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CRS].HieCod);
|
2021-05-13 12:50:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***** Check if the title or the folder of an attendance event exists ********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
bool Att_DB_CheckIfSimilarEventExists (const char *Field,const char *Value,long AttCod)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
2021-11-05 23:41:26 +01:00
|
|
|
|
return
|
|
|
|
|
DB_QueryEXISTS ("can not check similar attendance events",
|
|
|
|
|
"SELECT EXISTS"
|
|
|
|
|
"(SELECT *"
|
|
|
|
|
" FROM att_events"
|
|
|
|
|
" WHERE CrsCod=%ld"
|
|
|
|
|
" AND %s='%s'"
|
|
|
|
|
" AND AttCod<>%ld)",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CRS].HieCod,
|
2021-11-05 23:41:26 +01:00
|
|
|
|
Field,Value,
|
|
|
|
|
AttCod);
|
2021-05-13 12:50:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Create a new attendance event *************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
long Att_DB_CreateEvent (const struct Att_Event *Event,const char *Description)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
2023-09-11 17:41:31 +02:00
|
|
|
|
extern const char HidVis_YN[HidVis_NUM_HIDDEN_VISIBLE];
|
|
|
|
|
|
2021-05-13 12:50:36 +02:00
|
|
|
|
return
|
|
|
|
|
DB_QueryINSERTandReturnCode ("can not create new attendance event",
|
|
|
|
|
"INSERT INTO att_events"
|
|
|
|
|
" (CrsCod,Hidden,UsrCod,"
|
|
|
|
|
"StartTime,EndTime,"
|
|
|
|
|
"CommentTchVisible,Title,Txt)"
|
|
|
|
|
" VALUES"
|
|
|
|
|
" (%ld,'%c',%ld,"
|
|
|
|
|
"FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld),"
|
|
|
|
|
"'%c','%s','%s')",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CRS].HieCod,
|
2023-09-11 17:41:31 +02:00
|
|
|
|
HidVis_YN[Event->HiddenOrVisible],
|
2021-05-13 12:50:36 +02:00
|
|
|
|
Gbl.Usrs.Me.UsrDat.UsrCod,
|
2021-10-20 16:46:34 +02:00
|
|
|
|
Event->TimeUTC[Dat_STR_TIME],
|
|
|
|
|
Event->TimeUTC[Dat_END_TIME],
|
2021-05-13 12:50:36 +02:00
|
|
|
|
Event->CommentTchVisible ? 'Y' :
|
|
|
|
|
'N',
|
|
|
|
|
Event->Title,
|
|
|
|
|
Description);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Update the data of an attendance event *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
void Att_DB_UpdateEvent (const struct Att_Event *Event,const char *Description)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
2023-09-11 17:41:31 +02:00
|
|
|
|
extern const char HidVis_YN[HidVis_NUM_HIDDEN_VISIBLE];
|
|
|
|
|
|
2021-05-13 12:50:36 +02:00
|
|
|
|
DB_QueryUPDATE ("can not update attendance event",
|
|
|
|
|
"UPDATE att_events"
|
|
|
|
|
" SET Hidden='%c',"
|
|
|
|
|
"StartTime=FROM_UNIXTIME(%ld),"
|
|
|
|
|
"EndTime=FROM_UNIXTIME(%ld),"
|
|
|
|
|
"CommentTchVisible='%c',"
|
|
|
|
|
"Title='%s',"
|
|
|
|
|
"Txt='%s'"
|
|
|
|
|
" WHERE AttCod=%ld"
|
|
|
|
|
" AND CrsCod=%ld", // Extra check
|
2023-09-11 17:41:31 +02:00
|
|
|
|
HidVis_YN[Event->HiddenOrVisible],
|
2021-10-20 16:46:34 +02:00
|
|
|
|
Event->TimeUTC[Dat_STR_TIME],
|
|
|
|
|
Event->TimeUTC[Dat_END_TIME],
|
2021-05-13 12:50:36 +02:00
|
|
|
|
Event->CommentTchVisible ? 'Y' :
|
|
|
|
|
'N',
|
|
|
|
|
Event->Title,
|
|
|
|
|
Description,
|
|
|
|
|
Event->AttCod,
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CRS].HieCod);
|
2021-05-13 12:50:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************** Hide/unhide an attendance event **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-09-09 15:58:55 +02:00
|
|
|
|
void Att_DB_HideOrUnhideEvent (long AttCod,
|
|
|
|
|
HidVis_HiddenOrVisible_t HiddenOrVisible)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
2023-09-11 17:41:31 +02:00
|
|
|
|
extern const char HidVis_YN[HidVis_NUM_HIDDEN_VISIBLE];
|
|
|
|
|
|
2021-10-24 16:55:47 +02:00
|
|
|
|
DB_QueryUPDATE ("can not hide/unhide assignment",
|
2021-05-13 12:50:36 +02:00
|
|
|
|
"UPDATE att_events"
|
2021-10-24 16:55:47 +02:00
|
|
|
|
" SET Hidden='%c'"
|
2021-05-13 12:50:36 +02:00
|
|
|
|
" WHERE AttCod=%ld"
|
|
|
|
|
" AND CrsCod=%ld",
|
2023-09-11 17:41:31 +02:00
|
|
|
|
HidVis_YN[HiddenOrVisible],
|
2021-05-13 12:50:36 +02:00
|
|
|
|
AttCod,
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CRS].HieCod);
|
2021-05-13 12:50:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Create group of an attendance event **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Att_DB_CreateGroup (long AttCod,long GrpCod)
|
|
|
|
|
{
|
|
|
|
|
DB_QueryINSERT ("can not associate a group to an attendance event",
|
|
|
|
|
"INSERT INTO att_groups"
|
|
|
|
|
" (AttCod,GrpCod)"
|
|
|
|
|
" VALUES"
|
|
|
|
|
" (%ld,%ld)",
|
|
|
|
|
AttCod,
|
|
|
|
|
GrpCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************ Get group codes associated to an attendance event **************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned Att_DB_GetGrpCodsAssociatedToEvent (MYSQL_RES **mysql_res,long AttCod)
|
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get groups of an attendance event",
|
|
|
|
|
"SELECT GrpCod" // row[0]
|
|
|
|
|
" FROM att_groups"
|
2021-11-08 19:16:51 +01:00
|
|
|
|
" WHERE AttCod=%ld",
|
2021-05-13 12:50:36 +02:00
|
|
|
|
AttCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************** Get groups associated to an attendance event ***************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned Att_DB_GetGroupsAssociatedToEvent (MYSQL_RES **mysql_res,long AttCod)
|
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get groups of an attendance event",
|
|
|
|
|
"SELECT grp_types.GrpTypName," // row[0]
|
|
|
|
|
"grp_groups.GrpName," // row[1]
|
|
|
|
|
"roo_rooms.ShortName" // row[2]
|
|
|
|
|
" FROM (att_groups,"
|
|
|
|
|
"grp_groups,"
|
|
|
|
|
"grp_types)"
|
|
|
|
|
" LEFT JOIN roo_rooms"
|
|
|
|
|
" ON grp_groups.RooCod=roo_rooms.RooCod"
|
|
|
|
|
" WHERE att_groups.AttCod=%ld"
|
|
|
|
|
" AND att_groups.GrpCod=grp_groups.GrpCod"
|
|
|
|
|
" AND grp_groups.GrpTypCod=grp_types.GrpTypCod"
|
|
|
|
|
" ORDER BY grp_types.GrpTypName,"
|
|
|
|
|
"grp_groups.GrpName",
|
|
|
|
|
AttCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-10-30 13:28:48 +02:00
|
|
|
|
/*************** Remove one group from all attendance events *****************/
|
2021-05-13 12:50:36 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Att_DB_RemoveGroup (long GrpCod)
|
|
|
|
|
{
|
2021-10-30 13:28:48 +02:00
|
|
|
|
/***** Remove group from all attendance events *****/
|
2021-05-13 12:50:36 +02:00
|
|
|
|
DB_QueryDELETE ("can not remove group from the associations"
|
|
|
|
|
" between attendance events and groups",
|
|
|
|
|
"DELETE FROM att_groups"
|
|
|
|
|
" WHERE GrpCod=%ld",
|
|
|
|
|
GrpCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-10-30 13:28:48 +02:00
|
|
|
|
/********** Remove groups of one type from all attendance events *************/
|
2021-05-13 12:50:36 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Att_DB_RemoveGroupsOfType (long GrpTypCod)
|
|
|
|
|
{
|
2021-10-30 13:28:48 +02:00
|
|
|
|
/***** Remove group from all attendance events *****/
|
2021-05-13 12:50:36 +02:00
|
|
|
|
DB_QueryDELETE ("can not remove groups of a type from the associations"
|
|
|
|
|
" between attendance events and groups",
|
|
|
|
|
"DELETE FROM att_groups"
|
|
|
|
|
" USING grp_groups,"
|
|
|
|
|
"att_groups"
|
|
|
|
|
" WHERE grp_groups.GrpTypCod=%ld"
|
|
|
|
|
" AND grp_groups.GrpCod=att_groups.GrpCod",
|
|
|
|
|
GrpTypCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Remove groups of an attendance event *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
void Att_DB_RemoveGrpsAssociatedToAnEvent (long AttCod)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove the groups"
|
|
|
|
|
" associated to an attendance event",
|
|
|
|
|
"DELETE FROM att_groups"
|
|
|
|
|
" WHERE AttCod=%ld",
|
|
|
|
|
AttCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******* Get number of students from a list who attended to an event *********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
unsigned Att_DB_GetNumStdsTotalWhoAreInEvent (long AttCod)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QueryCOUNT ("can not get number of students registered in an event",
|
|
|
|
|
"SELECT COUNT(*)"
|
|
|
|
|
" FROM att_users"
|
|
|
|
|
" WHERE AttCod=%ld"
|
|
|
|
|
" AND Present='Y'",
|
|
|
|
|
AttCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********** Get number of users from a list in an attendance event ***********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
unsigned Att_DB_GetNumStdsFromListWhoAreInEvent (long AttCod,const char *SubQueryUsrs)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QueryCOUNT ("can not get number of students from a list"
|
|
|
|
|
" who are registered in an event",
|
|
|
|
|
"SELECT COUNT(*)"
|
|
|
|
|
" FROM att_users"
|
|
|
|
|
" WHERE AttCod=%ld"
|
|
|
|
|
" AND UsrCod IN (%s)"
|
|
|
|
|
" AND Present='Y'",
|
|
|
|
|
AttCod,SubQueryUsrs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Check if a user attended to an event ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// Return if user is in table
|
|
|
|
|
|
|
|
|
|
bool Att_DB_CheckIfUsrIsInTableAttUsr (long AttCod,long UsrCod,bool *Present)
|
|
|
|
|
{
|
|
|
|
|
char StrPresent[1 + 1];
|
|
|
|
|
|
|
|
|
|
/***** Check if a user is registered in an event in database *****/
|
|
|
|
|
DB_QuerySELECTString (StrPresent,1,"can not check if a user"
|
|
|
|
|
" is already registered in an event",
|
|
|
|
|
"SELECT Present"
|
|
|
|
|
" FROM att_users"
|
|
|
|
|
" WHERE AttCod=%ld"
|
|
|
|
|
" AND UsrCod=%ld",
|
|
|
|
|
AttCod,
|
|
|
|
|
UsrCod);
|
|
|
|
|
if (StrPresent[0])
|
|
|
|
|
{
|
|
|
|
|
*Present = (StrPresent[0] == 'Y');
|
|
|
|
|
return true; // User is in table
|
|
|
|
|
}
|
|
|
|
|
*Present = false;
|
|
|
|
|
return false; // User is not in table
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********** Get if a student attended to an event and get comments ***********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned Att_DB_GetPresentAndComments (MYSQL_RES **mysql_res,long AttCod,long UsrCod)
|
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get if a student"
|
|
|
|
|
" is already registered in an event",
|
|
|
|
|
"SELECT Present," // row[0]
|
|
|
|
|
"CommentStd," // row[1]
|
|
|
|
|
"CommentTch" // row[2]
|
|
|
|
|
" FROM att_users"
|
|
|
|
|
" WHERE AttCod=%ld"
|
|
|
|
|
" AND UsrCod=%ld",
|
|
|
|
|
AttCod,
|
|
|
|
|
UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-09 00:38:11 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********** Return a list with the users in an attendance event *************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
unsigned Att_DB_GetListUsrsInEvent (MYSQL_RES **mysql_res,
|
|
|
|
|
long AttCod,bool AttEventIsAsociatedToGrps)
|
2021-11-09 00:38:11 +01:00
|
|
|
|
{
|
|
|
|
|
char *SubQuery;
|
|
|
|
|
unsigned NumUsrs;
|
|
|
|
|
|
|
|
|
|
/***** Query list of attendance users *****/
|
|
|
|
|
if (AttEventIsAsociatedToGrps)
|
|
|
|
|
{
|
|
|
|
|
// Event for one or more groups
|
|
|
|
|
// Subquery: list of users in groups of this attendance event...
|
|
|
|
|
// ...who have no entry in attendance list of users
|
|
|
|
|
if (asprintf (&SubQuery,"SELECT DISTINCT "
|
|
|
|
|
"grp_users.UsrCod AS UsrCod," // row[0]
|
|
|
|
|
"'N' AS Present" // row[1]
|
|
|
|
|
" FROM att_groups,"
|
|
|
|
|
"grp_groups,"
|
|
|
|
|
"grp_types,"
|
|
|
|
|
"crs_users,"
|
|
|
|
|
"grp_users"
|
|
|
|
|
" WHERE att_groups.AttCod=%ld"
|
|
|
|
|
" AND att_groups.GrpCod=grp_groups.GrpCod"
|
|
|
|
|
" AND grp_groups.GrpTypCod=grp_types.GrpTypCod"
|
|
|
|
|
" AND grp_types.CrsCod=crs_users.CrsCod"
|
|
|
|
|
" AND crs_users.Role=%u"
|
|
|
|
|
" AND crs_users.UsrCod=grp_users.UsrCod"
|
|
|
|
|
" AND grp_users.GrpCod=att_groups.GrpCod"
|
|
|
|
|
" AND grp_users.UsrCod NOT IN"
|
|
|
|
|
" (SELECT UsrCod"
|
|
|
|
|
" FROM att_users"
|
|
|
|
|
" WHERE AttCod=%ld)",
|
|
|
|
|
AttCod,
|
|
|
|
|
(unsigned) Rol_STD,
|
|
|
|
|
AttCod) < 0)
|
|
|
|
|
Err_NotEnoughMemoryExit ();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Event for the whole course
|
|
|
|
|
// Subquery: list of users in the course of this attendance event...
|
|
|
|
|
// ...who have no entry in attendance list of users
|
|
|
|
|
if (asprintf (&SubQuery,"SELECT crs_users.UsrCod AS UsrCod," // row[0]
|
|
|
|
|
"'N' AS Present" // row[1]
|
|
|
|
|
" FROM att_events,"
|
|
|
|
|
"crs_users"
|
|
|
|
|
" WHERE att_events.AttCod=%ld"
|
|
|
|
|
" AND att_events.CrsCod=crs_users.CrsCod"
|
|
|
|
|
" AND crs_users.Role=%u"
|
|
|
|
|
" AND crs_users.UsrCod NOT IN"
|
|
|
|
|
" (SELECT UsrCod"
|
|
|
|
|
" FROM att_users"
|
|
|
|
|
" WHERE AttCod=%ld)",
|
|
|
|
|
AttCod,
|
|
|
|
|
(unsigned) Rol_STD,
|
|
|
|
|
AttCod) < 0)
|
|
|
|
|
Err_NotEnoughMemoryExit ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Query: list of users in attendance list + rest of users (subquery)
|
|
|
|
|
NumUsrs = (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get users in an attendance event",
|
|
|
|
|
"SELECT u.UsrCod," // row[0]
|
|
|
|
|
"u.Present" // row[1]
|
|
|
|
|
" FROM (SELECT UsrCod,"
|
|
|
|
|
"Present"
|
|
|
|
|
" FROM att_users"
|
|
|
|
|
" WHERE AttCod=%ld"
|
|
|
|
|
" UNION %s) AS u,"
|
|
|
|
|
"usr_data"
|
|
|
|
|
" WHERE u.UsrCod=usr_data.UsrCod"
|
|
|
|
|
" ORDER BY usr_data.Surname1,"
|
|
|
|
|
"usr_data.Surname2,"
|
|
|
|
|
"usr_data.FirstName",
|
|
|
|
|
AttCod,
|
|
|
|
|
SubQuery);
|
|
|
|
|
|
|
|
|
|
free (SubQuery);
|
|
|
|
|
|
|
|
|
|
return NumUsrs;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-13 12:50:36 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********* Register a user in an attendance event changing comments **********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
void Att_DB_RegUsrInEventChangingComments (long AttCod,long UsrCod,
|
|
|
|
|
bool Present,
|
|
|
|
|
const char *CommentStd,
|
|
|
|
|
const char *CommentTch)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
/***** Register user as assistant to an event in database *****/
|
|
|
|
|
DB_QueryREPLACE ("can not register user in an event",
|
|
|
|
|
"REPLACE INTO att_users"
|
|
|
|
|
" (AttCod,UsrCod,Present,CommentStd,CommentTch)"
|
|
|
|
|
" VALUES"
|
|
|
|
|
" (%ld,%ld,'%c','%s','%s')",
|
|
|
|
|
AttCod,
|
|
|
|
|
UsrCod,
|
|
|
|
|
Present ? 'Y' :
|
|
|
|
|
'N',
|
|
|
|
|
CommentStd,
|
|
|
|
|
CommentTch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************** Set user as present in an attendance event *****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Att_DB_SetUsrAsPresent (long AttCod,long UsrCod)
|
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not set user as present in an event",
|
|
|
|
|
"UPDATE att_users"
|
|
|
|
|
" SET Present='Y'"
|
|
|
|
|
" WHERE AttCod=%ld"
|
|
|
|
|
" AND UsrCod=%ld",
|
|
|
|
|
AttCod,
|
|
|
|
|
UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-09 13:08:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************** Set users as present in an attendance event ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Att_DB_SetUsrsAsPresent (long AttCod,const char *ListUsrs,bool SetOthersAsAbsent)
|
|
|
|
|
{
|
|
|
|
|
const char *Ptr;
|
|
|
|
|
char LongStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1];
|
2022-09-24 18:30:26 +02:00
|
|
|
|
struct Usr_Data UsrDat;
|
2021-11-09 13:08:08 +01:00
|
|
|
|
unsigned NumCodsInList;
|
|
|
|
|
char *SubQueryAllUsrs = NULL;
|
|
|
|
|
char SubQueryOneUsr[1 + Cns_MAX_DECIMAL_DIGITS_LONG + 1];
|
|
|
|
|
bool Present;
|
|
|
|
|
size_t Length = 0; // Initialized to avoid warning
|
|
|
|
|
unsigned NumUsrsPresent = 0;
|
|
|
|
|
|
|
|
|
|
/***** Initialize structure with user's data *****/
|
|
|
|
|
Usr_UsrDataConstructor (&UsrDat);
|
|
|
|
|
|
|
|
|
|
/***** Build list of present users *****/
|
|
|
|
|
if (SetOthersAsAbsent)
|
|
|
|
|
{
|
|
|
|
|
/***** Count number of codes in list *****/
|
|
|
|
|
for (Ptr = ListUsrs, NumCodsInList = 0;
|
|
|
|
|
*Ptr;
|
|
|
|
|
NumCodsInList++)
|
|
|
|
|
/* Find next string in text until comma (leading and trailing spaces are removed) */
|
|
|
|
|
Str_GetNextStringUntilComma (&Ptr,LongStr,Cns_MAX_DECIMAL_DIGITS_LONG);
|
|
|
|
|
|
|
|
|
|
/***** Allocate subquery used to mark not present users as absent *****/
|
|
|
|
|
Length = 256 + NumCodsInList * (1 + Cns_MAX_DECIMAL_DIGITS_LONG + 1) - 1;
|
|
|
|
|
if ((SubQueryAllUsrs = malloc (Length + 1)) == NULL)
|
|
|
|
|
Err_NotEnoughMemoryExit ();
|
|
|
|
|
SubQueryAllUsrs[0] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Ptr = ListUsrs;
|
|
|
|
|
*Ptr;
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
/* Find next string in text until comma
|
|
|
|
|
(leading and trailing spaces are removed) */
|
|
|
|
|
Str_GetNextStringUntilComma (&Ptr,LongStr,Cns_MAX_DECIMAL_DIGITS_LONG);
|
|
|
|
|
if ((UsrDat.UsrCod = Str_ConvertStrCodToLongCod (LongStr)) > 0)
|
|
|
|
|
if (Usr_DB_ChkIfUsrCodExists (UsrDat.UsrCod))
|
|
|
|
|
// The user must belong to course,
|
|
|
|
|
// but it's not necessary he/she belongs to groups associated to the event
|
2024-04-19 12:49:42 +02:00
|
|
|
|
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat) == Usr_BELONG)
|
2021-11-09 13:08:08 +01:00
|
|
|
|
{
|
|
|
|
|
/* Mark user as present */
|
|
|
|
|
if (Att_DB_CheckIfUsrIsInTableAttUsr (AttCod,UsrDat.UsrCod,&Present)) // User is in table att_users
|
|
|
|
|
{
|
|
|
|
|
if (!Present) // If already present ==> nothing to do
|
|
|
|
|
/***** Set user as present in database *****/
|
|
|
|
|
Att_DB_SetUsrAsPresent (AttCod,UsrDat.UsrCod);
|
|
|
|
|
}
|
|
|
|
|
else // User is not in table att_users
|
2023-03-23 09:35:20 +01:00
|
|
|
|
Att_DB_RegUsrInEventChangingComments (AttCod,UsrDat.UsrCod,true,"","");
|
2021-11-09 13:08:08 +01:00
|
|
|
|
|
|
|
|
|
/* Add this user to query used to mark not present users as absent */
|
|
|
|
|
if (SetOthersAsAbsent)
|
|
|
|
|
{
|
|
|
|
|
if (!NumUsrsPresent) // Begin building subquery
|
|
|
|
|
snprintf (SubQueryAllUsrs,Length," AND UsrCod NOT IN (%ld",
|
|
|
|
|
UsrDat.UsrCod);
|
|
|
|
|
else // Continue building subquery
|
|
|
|
|
{
|
|
|
|
|
snprintf (SubQueryOneUsr,sizeof (SubQueryOneUsr),",%ld",
|
|
|
|
|
UsrDat.UsrCod);
|
|
|
|
|
Str_Concat (SubQueryAllUsrs,SubQueryOneUsr,Length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NumUsrsPresent++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NumUsrsPresent) // End building subquery
|
|
|
|
|
Str_Concat (SubQueryAllUsrs,")",Length);
|
|
|
|
|
|
|
|
|
|
/***** Mark not present users as absent in table of users *****/
|
|
|
|
|
if (SetOthersAsAbsent)
|
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not set other users as absent",
|
|
|
|
|
"UPDATE att_users"
|
|
|
|
|
" SET Present='N'"
|
|
|
|
|
" WHERE AttCod=%ld"
|
|
|
|
|
"%s",
|
|
|
|
|
AttCod,
|
|
|
|
|
SubQueryAllUsrs);
|
|
|
|
|
|
|
|
|
|
/* Free memory for subquery string */
|
|
|
|
|
free (SubQueryAllUsrs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Free memory used for user's data *****/
|
|
|
|
|
Usr_UsrDataDestructor (&UsrDat);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-13 12:50:36 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************** Remove a user from an event **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
void Att_DB_RemoveUsrFromEvent (long AttCod,long UsrCod)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove student from an event",
|
|
|
|
|
"DELETE FROM att_users"
|
|
|
|
|
" WHERE AttCod=%ld"
|
|
|
|
|
" AND UsrCod=%ld",
|
|
|
|
|
AttCod,UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************ Remove users absent without comments from an event *************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
void Att_DB_RemoveUsrsAbsentWithoutCommentsFromEvent (long AttCod)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
/***** Clean table att_users *****/
|
|
|
|
|
DB_QueryDELETE ("can not remove users absent"
|
|
|
|
|
" without comments from an event",
|
|
|
|
|
"DELETE FROM att_users"
|
|
|
|
|
" WHERE AttCod=%ld"
|
|
|
|
|
" AND Present='N'"
|
|
|
|
|
" AND CommentStd=''"
|
|
|
|
|
" AND CommentTch=''",
|
|
|
|
|
AttCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********** Remove all users registered in an attendance event **************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
void Att_DB_RemoveAllUsrsFromAnEvent (long AttCod)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove attendance event",
|
|
|
|
|
"DELETE FROM att_users"
|
|
|
|
|
" WHERE AttCod=%ld",
|
|
|
|
|
AttCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-10-30 13:28:48 +02:00
|
|
|
|
/*** Remove one user from all attendance events where he/she is registered ***/
|
2021-05-13 12:50:36 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
void Att_DB_RemoveUsrFromAllEvents (long UsrCod)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove user from all attendance events",
|
|
|
|
|
"DELETE FROM att_users"
|
|
|
|
|
" WHERE UsrCod=%ld",
|
|
|
|
|
UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-10-30 13:28:48 +02:00
|
|
|
|
/************* Remove one student from all attendance events *****************/
|
2021-05-13 12:50:36 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
void Att_DB_RemoveUsrFromCrsEvents (long UsrCod,long CrsCod)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove user from attendance events of a course",
|
|
|
|
|
"DELETE FROM att_users"
|
|
|
|
|
" USING att_events,"
|
|
|
|
|
"att_users"
|
|
|
|
|
" WHERE att_events.CrsCod=%ld"
|
|
|
|
|
" AND att_events.AttCod=att_users.AttCod"
|
|
|
|
|
" AND att_users.UsrCod=%ld",
|
|
|
|
|
CrsCod,UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********************** Remove an attendance event **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
void Att_DB_RemoveEventFromCurrentCrs (long AttCod)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove attendance event",
|
|
|
|
|
"DELETE FROM att_events"
|
|
|
|
|
" WHERE AttCod=%ld AND CrsCod=%ld",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
AttCod,Gbl.Hierarchy.Node[Hie_CRS].HieCod);
|
2021-05-13 12:50:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************* Remove users in all attendance events of a course *************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2024-02-09 00:22:59 +01:00
|
|
|
|
void Att_DB_RemoveUsrsFromCrsEvents (long HieCod)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove users registered"
|
|
|
|
|
" in attendance events of a course",
|
|
|
|
|
"DELETE FROM att_users"
|
|
|
|
|
" USING att_events,"
|
|
|
|
|
"att_users"
|
|
|
|
|
" WHERE att_events.CrsCod=%ld"
|
|
|
|
|
" AND att_events.AttCod=att_users.AttCod",
|
2024-02-09 00:22:59 +01:00
|
|
|
|
HieCod);
|
2021-05-13 12:50:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************ Remove groups in all attendance events of a course *************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2024-02-09 00:22:59 +01:00
|
|
|
|
void Att_DB_RemoveGrpsAssociatedToCrsEvents (long HieCod)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove all groups associated"
|
|
|
|
|
" to attendance events of a course",
|
|
|
|
|
"DELETE FROM att_groups"
|
|
|
|
|
" USING att_events,"
|
|
|
|
|
"att_groups"
|
|
|
|
|
" WHERE att_events.CrsCod=%ld"
|
|
|
|
|
" AND att_events.AttCod=att_groups.AttCod",
|
2024-02-09 00:22:59 +01:00
|
|
|
|
HieCod);
|
2021-05-13 12:50:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************** Remove all attendance events of a course ******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2024-02-09 00:22:59 +01:00
|
|
|
|
void Att_DB_RemoveCrsEvents (long HieCod)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove all attendance events of a course",
|
|
|
|
|
"DELETE FROM att_events"
|
|
|
|
|
" WHERE CrsCod=%ld",
|
2024-02-09 00:22:59 +01:00
|
|
|
|
HieCod);
|
2021-05-13 12:50:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************** Get number of attendance events in a course *****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2024-02-09 00:22:59 +01:00
|
|
|
|
unsigned Att_DB_GetNumEventsInCrs (long HieCod)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
|
|
|
|
/***** Get number of attendance events in a course from database *****/
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QueryCOUNT ("can not get number of attendance events in course",
|
|
|
|
|
"SELECT COUNT(*)"
|
|
|
|
|
" FROM att_events"
|
|
|
|
|
" WHERE CrsCod=%ld",
|
2024-02-09 00:22:59 +01:00
|
|
|
|
HieCod);
|
2021-05-13 12:50:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************** Get number of courses with attendance events ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// Returns the number of courses with attendance events
|
2021-10-30 13:28:48 +02:00
|
|
|
|
// in this location (all the platform, the current degree or the current course)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
|
2023-09-22 14:47:56 +02:00
|
|
|
|
unsigned Att_DB_GetNumCoursesWithEvents (Hie_Level_t Level)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
2023-07-11 19:12:24 +02:00
|
|
|
|
switch (Level)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
2023-09-22 14:47:56 +02:00
|
|
|
|
case Hie_SYS:
|
2021-05-13 12:50:36 +02:00
|
|
|
|
return DB_QueryCOUNT ("can not get number of courses with attendance events",
|
|
|
|
|
"SELECT COUNT(DISTINCT CrsCod)"
|
|
|
|
|
" FROM att_events"
|
|
|
|
|
" WHERE CrsCod>0");
|
2023-09-22 14:47:56 +02:00
|
|
|
|
case Hie_INS:
|
2021-05-13 12:50:36 +02:00
|
|
|
|
return DB_QueryCOUNT ("can not get number of courses with attendance events",
|
|
|
|
|
"SELECT COUNT(DISTINCT att_events.CrsCod)"
|
|
|
|
|
" FROM ctr_centers,"
|
|
|
|
|
"deg_degrees,"
|
|
|
|
|
"crs_courses,"
|
|
|
|
|
"att_events"
|
|
|
|
|
" WHERE ctr_centers.InsCod=%ld"
|
|
|
|
|
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
|
|
|
|
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
|
|
|
|
" AND crs_courses.CrsCod=att_events.CrsCod",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_INS].HieCod);
|
|
|
|
|
case Hie_CTR:
|
2021-05-13 12:50:36 +02:00
|
|
|
|
return DB_QueryCOUNT ("can not get number of courses with attendance events",
|
|
|
|
|
"SELECT COUNT(DISTINCT att_events.CrsCod)"
|
|
|
|
|
" FROM deg_degrees,"
|
|
|
|
|
"crs_courses,"
|
|
|
|
|
"att_events"
|
|
|
|
|
" WHERE deg_degrees.CtrCod=%ld"
|
|
|
|
|
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
|
|
|
|
" AND crs_courses.CrsCod=att_events.CrsCod",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CTR].HieCod);
|
|
|
|
|
case Hie_DEG:
|
2021-05-13 12:50:36 +02:00
|
|
|
|
return DB_QueryCOUNT ("can not get number of courses with attendance events",
|
|
|
|
|
"SELECT COUNT(DISTINCT att_events.CrsCod)"
|
|
|
|
|
" FROM crs_courses,"
|
|
|
|
|
"att_events"
|
|
|
|
|
" WHERE crs_courses.DegCod=%ld"
|
|
|
|
|
" AND crs_courses.CrsCod=att_events.CrsCod",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_DEG].HieCod);
|
|
|
|
|
case Hie_CRS:
|
2021-05-13 12:50:36 +02:00
|
|
|
|
return DB_QueryCOUNT ("can not get number of courses with attendance events",
|
|
|
|
|
"SELECT COUNT(DISTINCT CrsCod)"
|
|
|
|
|
" FROM att_events"
|
|
|
|
|
" WHERE CrsCod=%ld",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CRS].HieCod);
|
2021-05-13 12:50:36 +02:00
|
|
|
|
default:
|
2023-07-11 19:12:24 +02:00
|
|
|
|
Err_WrongHierarchyLevelExit ();
|
2021-05-13 12:50:36 +02:00
|
|
|
|
return 0; // Not reached
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Get number of attendance events ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-09-22 14:47:56 +02:00
|
|
|
|
unsigned Att_DB_GetNumEvents (MYSQL_RES **mysql_res,Hie_Level_t Level)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
2023-07-11 19:12:24 +02:00
|
|
|
|
switch (Level)
|
2021-05-13 12:50:36 +02:00
|
|
|
|
{
|
2023-09-22 14:47:56 +02:00
|
|
|
|
case Hie_SYS:
|
2021-05-13 12:50:36 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of attendance events",
|
|
|
|
|
"SELECT COUNT(*)," // row[0]
|
|
|
|
|
"SUM(NumNotif)" // row[1]
|
|
|
|
|
" FROM att_events"
|
|
|
|
|
" WHERE CrsCod>0");
|
2023-09-22 14:47:56 +02:00
|
|
|
|
case Hie_INS:
|
2021-05-13 12:50:36 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of attendance events",
|
|
|
|
|
"SELECT COUNT(*)," // row[0]
|
|
|
|
|
"SUM(att_events.NumNotif)" // row[1]
|
|
|
|
|
" FROM ctr_centers,"
|
|
|
|
|
"deg_degrees,"
|
|
|
|
|
"crs_courses,"
|
|
|
|
|
"att_events"
|
|
|
|
|
" WHERE ctr_centers.InsCod=%ld"
|
|
|
|
|
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
|
|
|
|
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
|
|
|
|
" AND crs_courses.CrsCod=att_events.CrsCod",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_INS].HieCod);
|
|
|
|
|
case Hie_CTR:
|
2021-05-13 12:50:36 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of attendance events",
|
|
|
|
|
"SELECT COUNT(*)," // row[0]
|
|
|
|
|
"SUM(att_events.NumNotif)" // row[1]
|
|
|
|
|
" FROM deg_degrees,"
|
|
|
|
|
"crs_courses,"
|
|
|
|
|
"att_events"
|
|
|
|
|
" WHERE deg_degrees.CtrCod=%ld"
|
|
|
|
|
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
|
|
|
|
" AND crs_courses.CrsCod=att_events.CrsCod",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CTR].HieCod);
|
|
|
|
|
case Hie_DEG:
|
2021-05-13 12:50:36 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of attendance events",
|
|
|
|
|
"SELECT COUNT(*)," // row[0]
|
|
|
|
|
"SUM(att_events.NumNotif)" // row[1]
|
|
|
|
|
" FROM crs_courses,"
|
|
|
|
|
"att_events"
|
|
|
|
|
" WHERE crs_courses.DegCod=%ld"
|
|
|
|
|
" AND crs_courses.CrsCod=att_events.CrsCod",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_DEG].HieCod);
|
|
|
|
|
case Hie_CRS:
|
2021-05-13 12:50:36 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of attendance events",
|
|
|
|
|
"SELECT COUNT(*)," // row[0]
|
|
|
|
|
"SUM(NumNotif)" // row[1]
|
|
|
|
|
" FROM att_events"
|
|
|
|
|
" WHERE CrsCod=%ld",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CRS].HieCod);
|
2021-05-13 12:50:36 +02:00
|
|
|
|
default:
|
2023-07-11 19:12:24 +02:00
|
|
|
|
Err_WrongHierarchyLevelExit ();
|
2021-05-13 12:50:36 +02:00
|
|
|
|
return 0; // Not reached
|
|
|
|
|
}
|
|
|
|
|
}
|