mirror of https://github.com/acanas/swad-core.git
Version 21.54.8: Nov 09, 2021 Queries moved from API module to database modules.
This commit is contained in:
parent
1dd26f6a4a
commit
1ecd8ecf48
84
swad_API.c
84
swad_API.c
|
@ -2800,13 +2800,6 @@ int swad__sendAttendanceUsers (struct soap *soap,
|
|||
{
|
||||
int ReturnCode;
|
||||
struct Att_Event Event;
|
||||
const char *Ptr;
|
||||
char LongStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1];
|
||||
struct UsrData UsrDat;
|
||||
unsigned NumCodsInList;
|
||||
char *SubQueryAllUsrs = NULL;
|
||||
char SubQueryOneUsr[1 + Cns_MAX_DECIMAL_DIGITS_LONG + 1];
|
||||
size_t Length = 0; // Initialized to avoid warning
|
||||
|
||||
/***** Initializations *****/
|
||||
API_Set_gSOAP_RuntimeEnv (soap);
|
||||
|
@ -2844,83 +2837,12 @@ int swad__sendAttendanceUsers (struct soap *soap,
|
|||
"Request forbidden",
|
||||
"Requester must be a teacher");
|
||||
|
||||
/***** Initialize structure with user's data *****/
|
||||
Usr_UsrDataConstructor (&UsrDat);
|
||||
/***** Set users as present *****/
|
||||
Att_DB_SetUsrsAsPresent (Event.AttCod,users,setOthersAsAbsent);
|
||||
|
||||
/***** Purge absent users without comments from table *****/
|
||||
if (setOthersAsAbsent)
|
||||
{
|
||||
/* Count number of codes in list */
|
||||
for (Ptr = users, 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)
|
||||
return soap_receiver_fault (soap,
|
||||
"Not enough memory",
|
||||
"Not enough memory to store list of users");
|
||||
SubQueryAllUsrs[0] = '\0';
|
||||
}
|
||||
|
||||
for (Ptr = users;
|
||||
*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
|
||||
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat))
|
||||
{
|
||||
/* Mark user as present */
|
||||
Att_RegUsrInAttEventNotChangingComments (Event.AttCod,UsrDat.UsrCod);
|
||||
|
||||
/* Add this user to query used to mark not present users as absent */
|
||||
if (setOthersAsAbsent)
|
||||
{
|
||||
if (sendAttendanceUsersOut->numUsers)
|
||||
{
|
||||
snprintf (SubQueryOneUsr,sizeof (SubQueryOneUsr),",%ld",
|
||||
UsrDat.UsrCod);
|
||||
Str_Concat (SubQueryAllUsrs,SubQueryOneUsr,Length);
|
||||
}
|
||||
else
|
||||
snprintf (SubQueryAllUsrs,Length," AND UsrCod NOT IN (%ld",
|
||||
UsrDat.UsrCod);
|
||||
}
|
||||
|
||||
sendAttendanceUsersOut->numUsers++;
|
||||
}
|
||||
}
|
||||
|
||||
if (setOthersAsAbsent)
|
||||
{
|
||||
/* Mark not present users as absent in table of users */
|
||||
if (sendAttendanceUsersOut->numUsers)
|
||||
Str_Concat (SubQueryAllUsrs,")",Length);
|
||||
|
||||
DB_QueryUPDATE ("can not set other users as absent",
|
||||
"UPDATE att_users"
|
||||
" SET Present='N'"
|
||||
" WHERE AttCod=%ld"
|
||||
"%s",
|
||||
Event.AttCod,
|
||||
SubQueryAllUsrs);
|
||||
|
||||
/* Free memory for subquery string */
|
||||
free (SubQueryAllUsrs);
|
||||
|
||||
/* Clean attendance users table */
|
||||
Att_DB_RemoveUsrsAbsentWithoutCommentsFromAttEvent (Event.AttCod);
|
||||
}
|
||||
|
||||
/***** Free memory used for user's data *****/
|
||||
Usr_UsrDataDestructor (&UsrDat);
|
||||
|
||||
sendAttendanceUsersOut->success = 1;
|
||||
|
||||
|
|
|
@ -2161,25 +2161,6 @@ static bool Att_CheckIfUsrIsPresentInAttEventAndGetComments (long AttCod,long Us
|
|||
return Present;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******* Register a user in an attendance event not changing comments ********/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Att_RegUsrInAttEventNotChangingComments (long AttCod,long UsrCod)
|
||||
{
|
||||
bool Present;
|
||||
|
||||
/***** Check if user is already in table att_users (present or not) *****/
|
||||
if (Att_DB_CheckIfUsrIsInTableAttUsr (AttCod,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,UsrCod);
|
||||
}
|
||||
else // User is not in table att_users
|
||||
Att_DB_RegUsrInAttEventChangingComments (AttCod,UsrCod,true,"","");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********** Request listing attendance of users to several events ************/
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -103,8 +103,6 @@ void Att_SeeOneAttEvent (void);
|
|||
void Att_RegisterMeAsStdInAttEvent (void);
|
||||
void Att_RegisterStudentsInAttEvent (void);
|
||||
|
||||
void Att_RegUsrInAttEventNotChangingComments (long AttCod,long UsrCod);
|
||||
|
||||
void Att_ReqListUsrsAttendanceCrs (void);
|
||||
void Att_ListMyAttendanceCrs (void);
|
||||
void Att_PrintMyAttendanceCrs (void);
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "swad_error.h"
|
||||
#include "swad_global.h"
|
||||
#include "swad_hierarchy_level.h"
|
||||
#include "swad_user_database.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************** External global variables from others modules ***************/
|
||||
|
@ -598,6 +599,105 @@ void Att_DB_SetUsrAsPresent (long AttCod,long UsrCod)
|
|||
UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************** 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];
|
||||
struct UsrData UsrDat;
|
||||
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
|
||||
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat))
|
||||
{
|
||||
/* 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
|
||||
Att_DB_RegUsrInAttEventChangingComments (AttCod,UsrDat.UsrCod,true,"","");
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************** Remove a user from an event **************************/
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -74,6 +74,7 @@ void Att_DB_RegUsrInAttEventChangingComments (long AttCod,long UsrCod,
|
|||
const char *CommentStd,
|
||||
const char *CommentTch);
|
||||
void Att_DB_SetUsrAsPresent (long AttCod,long UsrCod);
|
||||
void Att_DB_SetUsrsAsPresent (long AttCod,const char *ListUsrs,bool SetOthersAsAbsent);
|
||||
void Att_DB_RemoveUsrFromAttEvent (long AttCod,long UsrCod);
|
||||
void Att_DB_RemoveUsrsAbsentWithoutCommentsFromAttEvent (long AttCod);
|
||||
|
||||
|
|
|
@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
|
|||
|
||||
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
|
||||
*/
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.54.7 (2021-11-09)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.54.8 (2021-11-09)"
|
||||
#define CSS_FILE "swad20.45.css"
|
||||
#define JS_FILE "swad20.69.1.js"
|
||||
/*
|
||||
TODO: Rename CENTRE to CENTER in help wiki.
|
||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||
|
||||
Version 21.54.8: Nov 09, 2021 Queries moved from API module to database modules. (322175 lines)
|
||||
Version 21.54.7: Nov 09, 2021 Queries moved from API module to database modules. (322175 lines)
|
||||
Version 21.54.6: Nov 09, 2021 Code refactoring in notifications. (322164 lines)
|
||||
Version 21.54.5: Nov 09, 2021 Queries moved from API module to database modules. (322185 lines)
|
||||
|
|
Loading…
Reference in New Issue