Version 21.54.5: Nov 09, 2021 Queries moved from API module to database modules.

This commit is contained in:
acanas 2021-11-09 09:20:54 +01:00
parent eaad863026
commit 387244eed4
13 changed files with 85 additions and 123 deletions

View File

@ -124,6 +124,7 @@ cp -f /home/acanas/swad/swad/swad /var/www/cgi-bin/
#include "swad_message_database.h"
#include "swad_nickname_database.h"
#include "swad_notice.h"
#include "swad_notice_database.h"
#include "swad_notification.h"
#include "swad_notification_database.h"
#include "swad_password.h"
@ -269,7 +270,10 @@ static void API_GetLstGrpsSel (const char *Groups);
static int API_GetMyLanguage (struct soap *soap);
static int API_SendMessageToUsr (long OriginalMsgCod,long SenderUsrCod,long ReplyUsrCod,long RecipientUsrCod,bool NotifyByEmail,const char *Subject,const char *Content);
static int API_SendMessageToUsr (long OriginalMsgCod,
long ReplyUsrCod,long RecipientUsrCod,
bool NotifyByEmail,
const char *Subject,const char *Content);
static int API_GetTstTags (struct soap *soap,
long CrsCod,struct swad__getTestsOutput *getTestsOut);
@ -3356,7 +3360,6 @@ int swad__sendMessage (struct soap *soap,
/* Send message to this user */
if ((ReturnCode = API_SendMessageToUsr ((long) messageCode,
Gbl.Usrs.Me.UsrDat.UsrCod,
ReplyUsrCod,
Gbl.Usrs.Other.UsrDat.UsrCod,
NotifyByEmail,
@ -3385,80 +3388,45 @@ int swad__sendMessage (struct soap *soap,
/*****************************************************************************/
/************************* Send a message to one user ************************/
/*****************************************************************************/
/*
API_SendMessageToUsr ((long) messageCode,
Gbl.Usrs.Me.UsrDat.UsrCod,ReplyUsrCod,Gbl.Usrs.Other.UsrDat.UsrCod,
NotifyByEmail,subject,body)) != SOAP_OK)
*/
static int API_SendMessageToUsr (long OriginalMsgCod,
long SenderUsrCod,long ReplyUsrCod,long RecipientUsrCod,
long ReplyUsrCod,long RecipientUsrCod,
bool NotifyByEmail,
const char *Subject,const char *Content)
{
static bool MsgAlreadyInserted = false;
static long NewMsgCod;
static long MsgCod;
/***** Create message *****/
if (!MsgAlreadyInserted) // The message is inserted only once in the table of messages sent
{
/***** Insert message subject and body in the database *****/
/* Get the code of the inserted item */
NewMsgCod =
DB_QueryINSERTandReturnCode ("can not create message",
"INSERT INTO msg_content"
" (Subject,Content,MedCod)"
" VALUES"
" ('%s','%s',-1)",
Subject,
Content);
MsgCod = Msg_DB_CreateNewMsg (Subject,Content,
-1L); // No media content
/* Insert message in sent messages */
DB_QueryINSERT ("can not create message",
"INSERT INTO msg_snt"
" (MsgCod,CrsCod,UsrCod,Expanded,CreatTime)"
" VALUES"
" (%ld,-1,%ld,'N',NOW())",
NewMsgCod,
SenderUsrCod);
Msg_DB_CreateSntMsg (MsgCod,
-1L); // No origin course
MsgAlreadyInserted = true;
}
/***** Insert message received in the database *****/
DB_QueryINSERT ("can not create received message",
"INSERT INTO msg_rcv"
" (MsgCod,UsrCod,Notified,Open,Replied,Expanded)"
" VALUES"
" (%ld,%ld,'%c','N','N','N')",
NewMsgCod,
RecipientUsrCod,
NotifyByEmail ? 'Y' :
'N');
Msg_DB_CreateRcvMsg (MsgCod,RecipientUsrCod,NotifyByEmail);
/***** Create notification for this recipient.
If this recipient wants to receive notifications by email, activate the sending of a notification *****/
DB_QueryINSERT ("can not create new notification event",
"INSERT INTO ntf_notifications"
" (NotifyEvent,ToUsrCod,FromUsrCod,InsCod,DegCod,CrsCod,Cod,TimeNotif,Status)"
" VALUES"
" (%u,%ld,%ld,-1,-1,-1,%ld,NOW(),%u)",
(unsigned) Ntf_EVENT_MESSAGE,
RecipientUsrCod,
SenderUsrCod,
NewMsgCod,
(unsigned) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0));
If this recipient wants to receive notifications by email,
activate the sending of a notification *****/
Ntf_DB_StoreNotifyEventToUsr (Ntf_EVENT_MESSAGE,RecipientUsrCod,MsgCod,
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0),
-1L,-1L,-1L,-1L);
/***** If this recipient is the original sender of a message been replied... *****/
if (RecipientUsrCod == ReplyUsrCod)
/***** ...then update received message setting Replied field to true *****/
DB_QueryUPDATE ("can not update a received message",
"UPDATE msg_rcv"
" SET Replied='Y'"
" WHERE MsgCod=%ld"
" AND UsrCod=%ld",
OriginalMsgCod,
SenderUsrCod);
Msg_DB_SetRcvMsgAsReplied (OriginalMsgCod);
return SOAP_OK;
}
@ -3512,15 +3480,7 @@ int swad__sendNotice (struct soap *soap,
/***** Insert notice in the database *****/
/* Get the code of the inserted item */
NotCod =
DB_QueryINSERTandReturnCode ("can not create message",
"INSERT INTO not_notices"
" (CrsCod,UsrCod,CreatTime,Content,Status)"
" VALUES"
" (%ld,%ld,NOW(),'%s',%u)",
Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
body,(unsigned) Not_ACTIVE_NOTICE);
NotCod = Not_DB_InsertNotice (body);
/***** Create notifications *****/
// TODO: create notifications

View File

@ -523,8 +523,8 @@ static void Asg_ShowOneAssignment (struct Asg_Assignments *Assignments,
/***** Mark possible notification as seen *****/
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_ASSIGNMENT,
AsgCod,Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
AsgCod,Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/

View File

@ -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.4 (2021-11-09)"
#define Log_PLATFORM_VERSION "SWAD 21.54.5 (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.5: Nov 09, 2021 Queries moved from API module to database modules. (322185 lines)
Version 21.54.4: Nov 09, 2021 Queries moved from API module to database modules. (322222 lines)
Version 21.54.3: Nov 08, 2021 Queries moved from API module to database modules. (322095 lines)
Version 21.54.2: Nov 08, 2021 Queries moved to module swad_user_database and other modules. (322054 lines)

View File

@ -112,7 +112,8 @@ extern struct Globals Gbl;
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static void Enr_NotifyAfterEnrolment (struct UsrData *UsrDat,Rol_Role_t NewRole);
static void Enr_NotifyAfterEnrolment (const struct UsrData *UsrDat,
Rol_Role_t NewRole);
static void Enr_ReqAdminUsrs (Rol_Role_t Role);
static void Enr_ShowFormRegRemSeveralUsrs (Rol_Role_t Role);
@ -297,7 +298,8 @@ void Enr_RegisterUsrInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole,
/********* Create notification after register user in current course *********/
/*****************************************************************************/
static void Enr_NotifyAfterEnrolment (struct UsrData *UsrDat,Rol_Role_t NewRole)
static void Enr_NotifyAfterEnrolment (const struct UsrData *UsrDat,
Rol_Role_t NewRole)
{
bool CreateNotif;
bool NotifyByEmail;
@ -334,13 +336,13 @@ static void Enr_NotifyAfterEnrolment (struct UsrData *UsrDat,Rol_Role_t NewRole)
NotifyByEmail = CreateNotif && !ItsMe &&
(UsrDat->NtfEvents.SendEmail & (1 << NotifyEvent));
if (CreateNotif)
Ntf_DB_StoreNotifyEventToOneUser (NotifyEvent,UsrDat,-1L,
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0),
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ctr.CtrCod,
Gbl.Hierarchy.Deg.DegCod,
Gbl.Hierarchy.Crs.CrsCod);
Ntf_DB_StoreNotifyEventToUsr (NotifyEvent,UsrDat->UsrCod,-1L,
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0),
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ctr.CtrCod,
Gbl.Hierarchy.Deg.DegCod,
Gbl.Hierarchy.Crs.CrsCod);
}
/*****************************************************************************/

View File

@ -97,8 +97,8 @@ static void Fol_PutHiddenParSelectedUsrsCods (void *SelectedUsrs);
static void Fol_GetFollowedFromSelectedUsrs (unsigned *NumFollowed,
unsigned *NumNotFollowed);
static void Fol_FollowUsr (struct UsrData *UsrDat);
static void Fol_UnfollowUsr (struct UsrData *UsrDat);
static void Fol_FollowUsr (const struct UsrData *UsrDat);
static void Fol_UnfollowUsr (const struct UsrData *UsrDat);
/*****************************************************************************/
/********************** Put link to show users to follow **********************/
@ -1098,7 +1098,7 @@ void Fol_UnfollowUsrs (void)
/******************************** Follow user ********************************/
/*****************************************************************************/
static void Fol_FollowUsr (struct UsrData *UsrDat)
static void Fol_FollowUsr (const struct UsrData *UsrDat)
{
bool CreateNotif;
bool NotifyByEmail;
@ -1124,20 +1124,20 @@ static void Fol_FollowUsr (struct UsrData *UsrDat)
If this followed wants to receive notifications by email,
activate the sending of a notification *****/
if (CreateNotif)
Ntf_DB_StoreNotifyEventToOneUser (Ntf_EVENT_FOLLOWER,UsrDat,Gbl.Usrs.Me.UsrDat.UsrCod,
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0),
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ctr.CtrCod,
Gbl.Hierarchy.Deg.DegCod,
Gbl.Hierarchy.Crs.CrsCod);
Ntf_DB_StoreNotifyEventToUsr (Ntf_EVENT_FOLLOWER,UsrDat->UsrCod,Gbl.Usrs.Me.UsrDat.UsrCod,
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0),
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ctr.CtrCod,
Gbl.Hierarchy.Deg.DegCod,
Gbl.Hierarchy.Crs.CrsCod);
}
/*****************************************************************************/
/******************************* Unfollow user *******************************/
/*****************************************************************************/
static void Fol_UnfollowUsr (struct UsrData *UsrDat)
static void Fol_UnfollowUsr (const struct UsrData *UsrDat)
{
/***** Avoid wrong cases *****/
if (Gbl.Usrs.Me.UsrDat.UsrCod <= 0 ||

View File

@ -844,13 +844,13 @@ void Msg_RecMsgFromUsr (void)
If this recipient wants to receive notifications by -mail,
activate the sending of a notification *****/
if (CreateNotif)
Ntf_DB_StoreNotifyEventToOneUser (Ntf_EVENT_MESSAGE,&UsrDstData,NewMsgCod,
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0),
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ctr.CtrCod,
Gbl.Hierarchy.Deg.DegCod,
Gbl.Hierarchy.Crs.CrsCod);
Ntf_DB_StoreNotifyEventToUsr (Ntf_EVENT_MESSAGE,UsrDstData.UsrCod,NewMsgCod,
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0),
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ctr.CtrCod,
Gbl.Hierarchy.Deg.DegCod,
Gbl.Hierarchy.Crs.CrsCod);
/***** Show an alert indicating that the message has been sent successfully *****/
Ale_ShowAlert (Ale_SUCCESS,NotifyByEmail ? Txt_message_sent_to_X_notified_by_email :
@ -1274,7 +1274,7 @@ static long Msg_InsertNewMsg (const char *Subject,const char *Content,
MsgCod = Msg_DB_CreateNewMsg (Subject,Content,Media->MedCod);
/***** Insert message in sent messages *****/
Msg_DB_CreateSntMsg (MsgCod);
Msg_DB_CreateSntMsg (MsgCod,Gbl.Hierarchy.Crs.CrsCod);
/***** Increment number of messages sent by me *****/
Prf_DB_IncrementNumMsgSntUsr (Gbl.Usrs.Me.UsrDat.UsrCod);

View File

@ -76,7 +76,7 @@ long Msg_DB_CreateNewMsg (const char *Subject,const char *Content,long MedCod)
/************* Insert a message in the table of sent messages ****************/
/*****************************************************************************/
void Msg_DB_CreateSntMsg (long MsgCod)
void Msg_DB_CreateSntMsg (long MsgCod,long CrsCod)
{
DB_QueryINSERT ("can not create sent message",
"INSERT INTO msg_snt"
@ -84,7 +84,7 @@ void Msg_DB_CreateSntMsg (long MsgCod)
" VALUES"
" (%ld,%ld,%ld,'N',NOW())",
MsgCod,
Gbl.Hierarchy.Crs.CrsCod,
CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}

View File

@ -47,7 +47,7 @@
/*****************************************************************************/
long Msg_DB_CreateNewMsg (const char *Subject,const char *Content,long MedCod);
void Msg_DB_CreateSntMsg (long MsgCod);
void Msg_DB_CreateSntMsg (long MsgCod,long CrsCod);
void Msg_DB_CreateRcvMsg (long MsgCod,long UsrCod,bool NotifyByEmail);
void Msg_DB_SetRcvMsgAsReplied (long MsgCod);
void Msg_DB_ExpandSntMsg (long MsgCod);

View File

@ -1173,14 +1173,15 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
{
if ((UsrDat.NtfEvents.SendEmail & NotifyEventMask)) // Send notification by email
{
Ntf_DB_StoreNotifyEventToOneUser (NotifyEvent,&UsrDat,Cod,
(Ntf_Status_t) Ntf_STATUS_BIT_EMAIL,
InsCod,CtrCod,DegCod,CrsCod);
Ntf_DB_StoreNotifyEventToUsr (NotifyEvent,UsrDat.UsrCod,Cod,
(Ntf_Status_t) Ntf_STATUS_BIT_EMAIL,
InsCod,CtrCod,DegCod,CrsCod);
NumUsrsToBeNotifiedByEMail++;
}
else // Don't send notification by email
Ntf_DB_StoreNotifyEventToOneUser (NotifyEvent,&UsrDat,Cod,(Ntf_Status_t) 0,
InsCod,CtrCod,DegCod,CrsCod);
Ntf_DB_StoreNotifyEventToUsr (NotifyEvent,UsrDat.UsrCod,Cod,
(Ntf_Status_t) 0,
InsCod,CtrCod,DegCod,CrsCod);
}
}

View File

@ -52,10 +52,9 @@ extern struct Globals Gbl;
/************** Store a notify event to one user into database ***************/
/*****************************************************************************/
void Ntf_DB_StoreNotifyEventToOneUser (Ntf_NotifyEvent_t NotifyEvent,
struct UsrData *UsrDat,
long Cod,Ntf_Status_t Status,
long InsCod,long CtrCod,long DegCod,long CrsCod)
void Ntf_DB_StoreNotifyEventToUsr (Ntf_NotifyEvent_t NotifyEvent,
long ToUsrCod,long Cod,Ntf_Status_t Status,
long InsCod,long CtrCod,long DegCod,long CrsCod)
{
DB_QueryINSERT ("can not create new notification event",
"INSERT INTO ntf_notifications"
@ -65,7 +64,7 @@ void Ntf_DB_StoreNotifyEventToOneUser (Ntf_NotifyEvent_t NotifyEvent,
" (%u,%ld,%ld,"
"%ld,%ld,%ld,%ld,%ld,NOW(),%u)",
(unsigned) NotifyEvent,
UsrDat->UsrCod,
ToUsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
InsCod,
CtrCod,

View File

@ -42,10 +42,9 @@
/****************************** Public prototypes ****************************/
/*****************************************************************************/
void Ntf_DB_StoreNotifyEventToOneUser (Ntf_NotifyEvent_t NotifyEvent,
struct UsrData *UsrDat,
long Cod,Ntf_Status_t Status,
long InsCod,long CtrCod,long DegCod,long CrsCod);
void Ntf_DB_StoreNotifyEventToUsr (Ntf_NotifyEvent_t NotifyEvent,
long ToUsrCod,long Cod,Ntf_Status_t Status,
long InsCod,long CtrCod,long DegCod,long CrsCod);
void Ntf_DB_UpdateMyLastAccessToNotifications (void);
void Ntf_DB_MarkAllMyNotifAsSeen (void);
void Ntf_DB_MarkPendingNtfsAsSent (long ToUsrCod);

View File

@ -757,13 +757,13 @@ void Str_AnalyzeTxtAndStoreNotifyEventToMentionedUsrs (long PubCod,const char *T
if (CreateNotif)
{
NotifyByEmail = (UsrDat.NtfEvents.SendEmail & (1 << Ntf_EVENT_TL_MENTION));
Ntf_DB_StoreNotifyEventToOneUser (Ntf_EVENT_TL_MENTION,&UsrDat,PubCod,
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0),
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ctr.CtrCod,
Gbl.Hierarchy.Deg.DegCod,
Gbl.Hierarchy.Crs.CrsCod);
Ntf_DB_StoreNotifyEventToUsr (Ntf_EVENT_TL_MENTION,UsrDat.UsrCod,PubCod,
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0),
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ctr.CtrCod,
Gbl.Hierarchy.Deg.DegCod,
Gbl.Hierarchy.Crs.CrsCod);
}
}
}

View File

@ -87,13 +87,13 @@ void Tml_Ntf_CreateNotifToAuthor (long AuthorCod,long PubCod,
If this author wants to receive notifications by email,
activate the sending of a notification *****/
if (CreateNotif)
Ntf_DB_StoreNotifyEventToOneUser (NotifyEvent,&UsrDat,PubCod,
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0),
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ctr.CtrCod,
Gbl.Hierarchy.Deg.DegCod,
Gbl.Hierarchy.Crs.CrsCod);
Ntf_DB_StoreNotifyEventToUsr (NotifyEvent,UsrDat.UsrCod,PubCod,
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0),
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ctr.CtrCod,
Gbl.Hierarchy.Deg.DegCod,
Gbl.Hierarchy.Crs.CrsCod);
}
/***** Free memory used for user's data *****/