Version 21.21.1: Oct 01, 2021 Queries moved to module swad_notification_database.

This commit is contained in:
acanas 2021-10-01 09:11:58 +02:00
parent f70122f854
commit 0b87fdd951
24 changed files with 487 additions and 442 deletions

View File

@ -58,6 +58,7 @@
#include "swad_nickname.h"
#include "swad_nickname_database.h"
#include "swad_notification.h"
#include "swad_notification_database.h"
#include "swad_parameter.h"
#include "swad_profile.h"
#include "swad_project.h"

View File

@ -44,6 +44,7 @@
#include "swad_group_database.h"
#include "swad_HTML.h"
#include "swad_notification.h"
#include "swad_notification_database.h"
#include "swad_pagination.h"
#include "swad_parameter.h"
#include "swad_photo.h"
@ -521,7 +522,7 @@ static void Asg_ShowOneAssignment (struct Asg_Assignments *Assignments,
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
/***** Mark possible notification as seen *****/
Ntf_MarkNotifAsSeen (Ntf_EVENT_ASSIGNMENT,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_ASSIGNMENT,
AsgCod,Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}

View File

@ -59,6 +59,7 @@
#include "swad_mark.h"
#include "swad_mark_database.h"
#include "swad_notification.h"
#include "swad_notification_database.h"
#include "swad_parameter.h"
#include "swad_photo.h"
#include "swad_profile.h"
@ -8156,19 +8157,19 @@ void Brw_ShowFileMetadata (void)
case Brw_SHOW_DOC_GRP:
case Brw_ADMI_DOC_CRS:
case Brw_ADMI_DOC_GRP:
Ntf_MarkNotifAsSeen (Ntf_EVENT_DOCUMENT_FILE,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_DOCUMENT_FILE,
FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
break;
case Brw_ADMI_TCH_CRS:
case Brw_ADMI_TCH_GRP:
Ntf_MarkNotifAsSeen (Ntf_EVENT_TEACHERS_FILE,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_TEACHERS_FILE,
FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
break;
case Brw_ADMI_SHR_CRS:
case Brw_ADMI_SHR_GRP:
Ntf_MarkNotifAsSeen (Ntf_EVENT_SHARED_FILE,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_SHARED_FILE,
FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
break;
@ -8176,7 +8177,7 @@ void Brw_ShowFileMetadata (void)
case Brw_SHOW_MRK_GRP:
case Brw_ADMI_MRK_CRS:
case Brw_ADMI_MRK_GRP:
Ntf_MarkNotifAsSeen (Ntf_EVENT_MARKS_FILE,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_MARKS_FILE,
FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
break;
@ -8306,19 +8307,19 @@ void Brw_DownloadFile (void)
case Brw_SHOW_DOC_GRP:
case Brw_ADMI_DOC_CRS:
case Brw_ADMI_DOC_GRP:
Ntf_MarkNotifAsSeen (Ntf_EVENT_DOCUMENT_FILE,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_DOCUMENT_FILE,
FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
break;
case Brw_ADMI_TCH_CRS:
case Brw_ADMI_TCH_GRP:
Ntf_MarkNotifAsSeen (Ntf_EVENT_TEACHERS_FILE,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_TEACHERS_FILE,
FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
break;
case Brw_ADMI_SHR_CRS:
case Brw_ADMI_SHR_GRP:
Ntf_MarkNotifAsSeen (Ntf_EVENT_SHARED_FILE,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_SHARED_FILE,
FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
break;
@ -8326,7 +8327,7 @@ void Brw_DownloadFile (void)
case Brw_SHOW_MRK_GRP:
case Brw_ADMI_MRK_CRS:
case Brw_ADMI_MRK_GRP:
Ntf_MarkNotifAsSeen (Ntf_EVENT_MARKS_FILE,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_MARKS_FILE,
FileMetadata.FilCod,Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
break;

View File

@ -45,6 +45,7 @@
#include "swad_HTML.h"
#include "swad_logo.h"
#include "swad_notification.h"
#include "swad_notification_database.h"
#include "swad_parameter.h"
#include "swad_QR.h"
#include "swad_RSS.h"
@ -550,7 +551,7 @@ void Cfe_ListCallsForExamsSee (void)
Cfe_ListCallsForExams (&CallsForExams,Cfe_NORMAL_VIEW);
/***** Mark possible notifications as seen *****/
Ntf_MarkNotifAsSeen (Ntf_EVENT_CALL_FOR_EXAM,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_CALL_FOR_EXAM,
-1L,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.21 (2021-09-30)"
#define Log_PLATFORM_VERSION "SWAD 21.21.1 (2021-10-01)"
#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.21.1: Oct 01, 2021 Queries moved to module swad_notification_database. (317938 lines)
Version 21.21: Sep 30, 2021 New module swad_notice_database for database queries related to notices. (317901 lines)
Version 21.20.1: Sep 30, 2021 Code refactoring related to nicknames. (317756 lines)
Version 21.20: Sep 30, 2021 New module swad_nickname_database for database queries related to nicknames. (317751 lines)

View File

@ -55,6 +55,7 @@
#include "swad_message.h"
#include "swad_notice.h"
#include "swad_notice_database.h"
#include "swad_notification_database.h"
#include "swad_project.h"
#include "swad_search.h"
#include "swad_setting.h"
@ -1785,7 +1786,7 @@ static void Crs_EmptyCourseCompletely (long CrsCod)
/***** Set all the notifications from the course as removed,
except notifications about new messages *****/
Ntf_MarkNotifInCrsAsRemoved (-1L,CrsCod);
Ntf_DB_MarkNotifInCrsAsRemoved (-1L,CrsCod);
/***** Remove information of the course ****/
/* Remove information of the course */

View File

@ -54,6 +54,7 @@
#include "swad_message.h"
#include "swad_message_database.h"
#include "swad_notification.h"
#include "swad_notification_database.h"
#include "swad_parameter.h"
#include "swad_photo.h"
#include "swad_role.h"
@ -316,9 +317,9 @@ static void Enr_NotifyAfterEnrolment (struct UsrData *UsrDat,Rol_Role_t NewRole)
Enr_RemUsrEnrolmentRequestInCrs (UsrDat->UsrCod,Gbl.Hierarchy.Crs.CrsCod);
/***** Remove old enrolment notifications before inserting the new one ******/
Ntf_MarkNotifToOneUsrAsRemoved (Ntf_EVENT_ENROLMENT_STD,-1,UsrDat->UsrCod);
Ntf_MarkNotifToOneUsrAsRemoved (Ntf_EVENT_ENROLMENT_NET,-1,UsrDat->UsrCod);
Ntf_MarkNotifToOneUsrAsRemoved (Ntf_EVENT_ENROLMENT_TCH,-1,UsrDat->UsrCod);
Ntf_DB_MarkNotifToOneUsrAsRemoved (Ntf_EVENT_ENROLMENT_STD,-1,UsrDat->UsrCod);
Ntf_DB_MarkNotifToOneUsrAsRemoved (Ntf_EVENT_ENROLMENT_NET,-1,UsrDat->UsrCod);
Ntf_DB_MarkNotifToOneUsrAsRemoved (Ntf_EVENT_ENROLMENT_TCH,-1,UsrDat->UsrCod);
/***** Create new notification ******/
CreateNotif = (UsrDat->NtfEvents.CreateNotif & (1 << NotifyEvent));
@ -446,7 +447,7 @@ void Enr_ReqAcceptRegisterInCrs (void)
Err_WrongRoleExit ();
break;
}
Ntf_MarkNotifAsSeen (NotifyEvent,-1L,Gbl.Hierarchy.Crs.CrsCod,
Ntf_DB_MarkNotifAsSeen (NotifyEvent,-1L,Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
@ -2341,7 +2342,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
HTM_TR_End ();
/***** Mark possible notification as seen *****/
Ntf_MarkNotifAsSeen (Ntf_EVENT_ENROLMENT_REQUEST,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_ENROLMENT_REQUEST,
ReqCod,Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
@ -2795,9 +2796,9 @@ void Enr_AcceptRegisterMeInCrs (void)
/***** Mark all notifications about enrolment (as student or as teacher)
in current course as removed *****/
Ntf_MarkNotifToOneUsrAsRemoved (Ntf_EVENT_ENROLMENT_STD,-1L,
Ntf_DB_MarkNotifToOneUsrAsRemoved (Ntf_EVENT_ENROLMENT_STD,-1L,
Gbl.Usrs.Me.UsrDat.UsrCod);
Ntf_MarkNotifToOneUsrAsRemoved (Ntf_EVENT_ENROLMENT_TCH,-1L,
Ntf_DB_MarkNotifToOneUsrAsRemoved (Ntf_EVENT_ENROLMENT_TCH,-1L,
Gbl.Usrs.Me.UsrDat.UsrCod);
/***** Confirmation message *****/
@ -3230,7 +3231,7 @@ static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat,
/***** Set all the notifications for this user in this course as removed,
except notifications about new messages *****/
Ntf_MarkNotifInCrsAsRemoved (UsrDat->UsrCod,Crs->CrsCod);
Ntf_DB_MarkNotifInCrsAsRemoved (UsrDat->UsrCod,Crs->CrsCod);
/***** Remove user from the tables of courses-users *****/
Set_DB_RemUsrFromCrsSettings (UsrDat->UsrCod,Crs->CrsCod);

View File

@ -57,6 +57,7 @@
#include "swad_message_database.h"
#include "swad_network.h"
#include "swad_notice.h"
#include "swad_notification_database.h"
#include "swad_privacy.h"
#include "swad_profile.h"
#include "swad_program.h"

View File

@ -38,6 +38,7 @@
#include "swad_global.h"
#include "swad_HTML.h"
#include "swad_notification.h"
#include "swad_notification_database.h"
#include "swad_photo.h"
#include "swad_privacy.h"
#include "swad_profile.h"
@ -613,7 +614,7 @@ static void Fol_ListFollowersUsr (struct UsrData *UsrDat)
/***** If it's me, mark possible notification as seen *****/
ItsMe = Usr_ItsMe (UsrDat->UsrCod);
if (ItsMe)
Ntf_MarkNotifAsSeen (Ntf_EVENT_FOLLOWER,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_FOLLOWER,
-1L,-1L,
Gbl.Usrs.Me.UsrDat.UsrCod);
}

View File

@ -49,6 +49,7 @@
#include "swad_logo.h"
#include "swad_message.h"
#include "swad_notification.h"
#include "swad_notification_database.h"
#include "swad_pagination.h"
#include "swad_parameter.h"
#include "swad_profile.h"
@ -776,7 +777,7 @@ static void For_ShowPostsOfAThread (struct For_Forums *Forums,
{
case For_FORUM_COURSE_TCHS:
case For_FORUM_COURSE_USRS:
Ntf_MarkNotifAsSeen (Ntf_EVENT_FORUM_POST_COURSE,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_FORUM_POST_COURSE,
Forums->PstCod,Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
break;
@ -784,7 +785,7 @@ static void For_ShowPostsOfAThread (struct For_Forums *Forums,
break;
}
if (Thread.NumMyPosts)
Ntf_MarkNotifAsSeen (Ntf_EVENT_FORUM_REPLY,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_FORUM_REPLY,
Forums->PstCod,-1L,
Gbl.Usrs.Me.UsrDat.UsrCod);
}

View File

@ -52,6 +52,7 @@
#include "swad_message_database.h"
#include "swad_nickname_database.h"
#include "swad_notification.h"
#include "swad_notification_database.h"
#include "swad_pagination.h"
#include "swad_parameter.h"
#include "swad_photo.h"
@ -1209,7 +1210,7 @@ void Msg_ExpRecMsg (void)
Msg_DB_ExpandRcvMsg (Messages.ExpandedMsgCod);
/***** Mark possible notification as seen *****/
Ntf_MarkNotifAsSeen (Ntf_EVENT_MESSAGE,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_MESSAGE,
Messages.ExpandedMsgCod,-1L,
Gbl.Usrs.Me.UsrDat.UsrCod);
@ -1343,7 +1344,7 @@ static void Msg_MoveRcvMsgToDeleted (long MsgCod,long UsrCod)
Msg_DB_MoveMsgContentToDeleted (MsgCod);
/***** Mark possible notifications as removed *****/
Ntf_MarkNotifToOneUsrAsRemoved (Ntf_EVENT_MESSAGE,MsgCod,UsrCod);
Ntf_DB_MarkNotifToOneUsrAsRemoved (Ntf_EVENT_MESSAGE,MsgCod,UsrCod);
}
/*****************************************************************************/

View File

@ -43,6 +43,7 @@
#include "swad_notice.h"
#include "swad_notice_database.h"
#include "swad_notification.h"
#include "swad_notification_database.h"
#include "swad_parameter.h"
#include "swad_RSS.h"
#include "swad_timeline.h"
@ -430,7 +431,7 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing,long HighlightNotCod)
DB_FreeMySQLResult (&mysql_res);
/***** Mark possible notification as seen *****/
Ntf_MarkNotifAsSeen (Ntf_EVENT_NOTICE,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_NOTICE,
-1L,Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}

View File

@ -90,7 +90,7 @@ const char *Ntf_WSNotifyEvents[Ntf_NUM_NOTIFY_EVENTS] =
/* Assessment tab */
[Ntf_EVENT_ASSIGNMENT ] = "assignment",
[Ntf_EVENT_SURVEY ] = "survey",
[Ntf_EVENT_CALL_FOR_EXAM] = "examAnnouncement",
[Ntf_EVENT_CALL_FOR_EXAM ] = "examAnnouncement",
/* Files tab */
[Ntf_EVENT_DOCUMENT_FILE ] = "documentFile",
[Ntf_EVENT_TEACHERS_FILE ] = "teachersFile",
@ -128,7 +128,7 @@ static const Act_Action_t Ntf_DefaultActions[Ntf_NUM_NOTIFY_EVENTS] =
/* Assessment tab */
[Ntf_EVENT_ASSIGNMENT ] = ActSeeAsg,
[Ntf_EVENT_SURVEY ] = ActSeeAllSvy,
[Ntf_EVENT_CALL_FOR_EXAM] = ActSeeAllExaAnn,
[Ntf_EVENT_CALL_FOR_EXAM ] = ActSeeAllExaAnn,
/* Files tab */
[Ntf_EVENT_DOCUMENT_FILE ] = ActSeeAdmDocCrsGrp,
[Ntf_EVENT_TEACHERS_FILE ] = ActAdmTchCrsGrp,
@ -171,7 +171,7 @@ static const char *Ntf_ParamNotifMeAboutNotifyEvents[Ntf_NUM_NOTIFY_EVENTS] =
/* Assessment tab */
[Ntf_EVENT_ASSIGNMENT ] = "NotifyNtfEventAssignment",
[Ntf_EVENT_SURVEY ] = "NotifyNtfEventSurvey",
[Ntf_EVENT_CALL_FOR_EXAM] = "NotifyNtfEventExamAnnouncement",
[Ntf_EVENT_CALL_FOR_EXAM ] = "NotifyNtfEventExamAnnouncement",
/* Files tab */
[Ntf_EVENT_DOCUMENT_FILE ] = "NotifyNtfEventDocumentFile",
[Ntf_EVENT_TEACHERS_FILE ] = "NotifyNtfEventTeachersFile",
@ -210,7 +210,7 @@ static const char *Ntf_ParamEmailMeAboutNotifyEvents[Ntf_NUM_NOTIFY_EVENTS] =
/* Assessment tab */
[Ntf_EVENT_ASSIGNMENT ] = "EmailNtfEventAssignment",
[Ntf_EVENT_SURVEY ] = "EmailNtfEventSurvey",
[Ntf_EVENT_CALL_FOR_EXAM] = "EmailNtfEventExamAnnouncement",
[Ntf_EVENT_CALL_FOR_EXAM ] = "EmailNtfEventExamAnnouncement",
/* Files tab */
[Ntf_EVENT_DOCUMENT_FILE ] = "EmailNtfEventDocumentFile",
[Ntf_EVENT_TEACHERS_FILE ] = "EmailNtfEventTeachersFile",
@ -249,7 +249,7 @@ static const char *Ntf_Icons[Ntf_NUM_NOTIFY_EVENTS] =
/* Assessment tab */
[Ntf_EVENT_ASSIGNMENT ] = "edit.svg",
[Ntf_EVENT_SURVEY ] = "poll.svg",
[Ntf_EVENT_CALL_FOR_EXAM] = "bullhorn.svg",
[Ntf_EVENT_CALL_FOR_EXAM ] = "bullhorn.svg",
/* Files tab */
[Ntf_EVENT_DOCUMENT_FILE ] = "file.svg",
[Ntf_EVENT_TEACHERS_FILE ] = "file.svg",
@ -283,7 +283,6 @@ static bool Ntf_StartFormGoToAction (Ntf_NotifyEvent_t NotifyEvent,
const struct For_Forums *Forums);
static void Ntf_PutHiddenParamNotifyEvent (Ntf_NotifyEvent_t NotifyEvent);
static void Ntf_DB_UpdateMyLastAccessToNotifications (void);
static void Ntf_SendPendingNotifByEMailToOneUsr (struct UsrData *ToUsrDat,unsigned *NumNotif,unsigned *NumMails);
static void Ntf_GetNumNotifSent (long DegCod,long CrsCod,
Ntf_NotifyEvent_t NotifyEvent,
@ -293,8 +292,6 @@ static void Ntf_UpdateNumNotifSent (long DegCod,long CrsCod,
unsigned NumEvents,unsigned NumMails);
static void Ntf_GetParamsNotifyEvents (void);
static unsigned Ntf_DB_GetNumberOfAllMyUnseenNtfs (void);
static unsigned Ntf_DB_GetNumberOfMyNewUnseenNtfs (void);
/*****************************************************************************/
/*************************** Show my notifications ***************************/
@ -321,7 +318,6 @@ void Ntf_ShowMyNotifications (void)
extern const char *Txt_NOTIFICATION_STATUS[Ntf_NUM_STATUS_TXT];
extern const char *Txt_You_have_no_notifications;
extern const char *Txt_You_have_no_unread_notifications;
char SubQuery[128];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumNotif;
@ -346,44 +342,24 @@ void Ntf_ShowMyNotifications (void)
/***** Get my notifications from database *****/
AllNotifications = Ntf_GetAllNotificationsFromForm ();
if (AllNotifications)
SubQuery[0] = '\0';
else
sprintf (SubQuery," AND (Status&%u)=0",
Ntf_STATUS_BIT_READ |
Ntf_STATUS_BIT_REMOVED);
NumNotifications = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get your notifications",
"SELECT NotifyEvent," // row[0]
"FromUsrCod," // row[1]
"InsCod," // row[2]
"CtrCod," // row[3]
"DegCod," // row[4]
"CrsCod," // row[5]
"Cod," // row[6]
"UNIX_TIMESTAMP(TimeNotif)," // row[7]
"Status" // row[8]
" FROM ntf_notifications"
" WHERE ToUsrCod=%ld%s"
" ORDER BY TimeNotif DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,SubQuery);
NumNotifications = Ntf_DB_GetMyNotifications (&mysql_res,AllNotifications);
/***** Contextual menu *****/
Mnu_ContextMenuBegin ();
Ntf_WriteFormAllNotifications (AllNotifications); // Show all notifications
if (NumNotifications) // TODO: Show message only when I don't have notificacions at all
Lay_PutContextualLinkIconText (ActMrkNtfSee,NULL,
NULL,NULL,
"eye.svg",
Txt_Mark_all_NOTIFICATIONS_as_read); // Mark notifications as read
Lay_PutContextualLinkIconText (ActReqEdiSet,Ntf_NOTIFICATIONS_ID,
NULL,NULL,
"cog.svg",
Txt_Settings); // Change notification settings
Lay_PutContextualLinkIconText (ActSeeMai,NULL,
NULL,NULL,
"envelope.svg",
Txt_Domains); // View allowed mail domains
Ntf_WriteFormAllNotifications (AllNotifications); // Show all notifications
if (NumNotifications) // TODO: Show message only when I don't have notificacions at all
Lay_PutContextualLinkIconText (ActMrkNtfSee,NULL,
NULL,NULL,
"eye.svg",
Txt_Mark_all_NOTIFICATIONS_as_read); // Mark notifications as read
Lay_PutContextualLinkIconText (ActReqEdiSet,Ntf_NOTIFICATIONS_ID,
NULL,NULL,
"cog.svg",
Txt_Settings); // Change notification settings
Lay_PutContextualLinkIconText (ActSeeMai,NULL,
NULL,NULL,
"envelope.svg",
Txt_Domains); // View allowed mail domains
Mnu_ContextMenuEnd ();
/***** Begin box *****/
@ -605,7 +581,8 @@ void Ntf_ShowMyNotifications (void)
HTM_TD_Begin ("colspan=\"2\"");
HTM_TD_End ();
HTM_TD_Begin ("colspan=\"4\" class=\"DAT LT\" style=\"padding-bottom:12px;\"");
HTM_TD_Begin ("colspan=\"4\" class=\"DAT LT\""
" style=\"padding-bottom:12px;\"");
HTM_Txt (SummaryStr);
HTM_TD_End ();
@ -916,134 +893,6 @@ void Ntf_GetNotifSummaryAndContent (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
}
}
/*****************************************************************************/
/********************** Set possible notification as seen ********************/
/*****************************************************************************/
void Ntf_MarkNotifAsSeen (Ntf_NotifyEvent_t NotifyEvent,long Cod,long CrsCod,long ToUsrCod)
{
/***** Set notification as seen by me *****/
if (ToUsrCod > 0) // If the user code is specified
{
if (Cod > 0) // Set only one notification
// for the user as seen
DB_QueryUPDATE ("can not set notification(s) as seen",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld"
" AND NotifyEvent=%u"
" AND Cod=%ld",
(unsigned) Ntf_STATUS_BIT_READ,
ToUsrCod,
(unsigned) NotifyEvent,
Cod);
else if (CrsCod > 0) // Set all notifications of this type
// in the current course for the user as seen
DB_QueryUPDATE ("can not set notification(s) as seen",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld"
" AND NotifyEvent=%u"
" AND CrsCod=%ld",
(unsigned) Ntf_STATUS_BIT_READ,
ToUsrCod,
(unsigned) NotifyEvent,
Gbl.Hierarchy.Crs.CrsCod);
else // Set all notifications of this type
// for the user as seen
DB_QueryUPDATE ("can not set notification(s) as seen",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld"
" AND NotifyEvent=%u",
(unsigned) Ntf_STATUS_BIT_READ,
ToUsrCod,
(unsigned) NotifyEvent);
}
}
/*****************************************************************************/
/******************* Set possible notifications as removed *******************/
/*****************************************************************************/
void Ntf_DB_MarkNotifAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod)
{
DB_QueryUPDATE ("can not set notification(s) as removed",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE NotifyEvent=%u"
" AND Cod=%ld",
(unsigned) Ntf_STATUS_BIT_REMOVED,
(unsigned) NotifyEvent,
Cod);
}
/*****************************************************************************/
/******************** Set possible notification as removed *******************/
/*****************************************************************************/
void Ntf_MarkNotifToOneUsrAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod,long ToUsrCod)
{
/***** Set notification as removed *****/
if (Cod > 0) // Set only one notification as removed
DB_QueryUPDATE ("can not set notification(s) as removed",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld"
" AND NotifyEvent=%u"
" AND Cod=%ld",
(unsigned) Ntf_STATUS_BIT_REMOVED,
ToUsrCod,
(unsigned) NotifyEvent,
Cod);
else // Set all notifications of this type,
// in the current course for the user, as removed
DB_QueryUPDATE ("can not set notification(s) as removed",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld"
" AND NotifyEvent=%u"
" AND CrsCod=%ld",
(unsigned) Ntf_STATUS_BIT_REMOVED,
ToUsrCod,
(unsigned) NotifyEvent,
Gbl.Hierarchy.Crs.CrsCod);
}
/*****************************************************************************/
/*********** Set possible notifications from a course as removed *************/
/*****************************************************************************/
// This function should be called when a course is removed
// because notifications from this course will not be available after course removing.
// However, notifications about new messages should not be removed
// because the messages will remain available
void Ntf_MarkNotifInCrsAsRemoved (long ToUsrCod,long CrsCod)
{
/***** Set all notifications from the course as removed,
except notifications about new messages *****/
if (ToUsrCod > 0) // If the user code is specified
DB_QueryUPDATE ("can not set notification(s) as removed",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld"
" AND CrsCod=%ld"
" AND NotifyEvent<>%u", // messages will remain available
(unsigned) Ntf_STATUS_BIT_REMOVED,
ToUsrCod,
CrsCod,
(unsigned) Ntf_EVENT_MESSAGE);
else // User code not specified ==> any user
DB_QueryUPDATE ("can not set notification(s) as removed",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE CrsCod=%ld"
" AND NotifyEvent<>%u", // messages will remain available
(unsigned) Ntf_STATUS_BIT_REMOVED,
CrsCod,
(unsigned) Ntf_EVENT_MESSAGE);
}
/*****************************************************************************/
/*********** Mark possible notifications of one file as removed **************/
/*****************************************************************************/
@ -1150,34 +999,6 @@ void Ntf_MarkNotifChildrenOfFolderAsRemoved (const char *Path)
}
}
/*****************************************************************************/
/******* Set all possible notifications of files in a group as removed *******/
/*****************************************************************************/
void Ntf_DB_MarkNotifFilesInGroupAsRemoved (long GrpCod)
{
/***** Set notifications as removed *****/
DB_QueryUPDATE ("can not set notification(s) as removed",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE NotifyEvent IN (%u,%u,%u,%u)"
" AND Cod IN"
" (SELECT FilCod"
" FROM brw_files"
" WHERE FileBrowser IN (%u,%u,%u,%u)"
" AND Cod=%ld)",
(unsigned) Ntf_STATUS_BIT_REMOVED,
(unsigned) Ntf_EVENT_DOCUMENT_FILE,
(unsigned) Ntf_EVENT_TEACHERS_FILE,
(unsigned) Ntf_EVENT_SHARED_FILE,
(unsigned) Ntf_EVENT_MARKS_FILE,
(unsigned) Brw_ADMI_DOC_GRP,
(unsigned) Brw_ADMI_TCH_GRP,
(unsigned) Brw_ADMI_SHR_GRP,
(unsigned) Brw_ADMI_MRK_GRP,
GrpCod);
}
/*****************************************************************************/
/********** Get a list with user's codes of all users to be notified *********/
/********** about an event, and notify them *********/
@ -1524,48 +1345,6 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
return NumUsrsToBeNotifiedByEMail;
}
/*****************************************************************************/
/************** 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)
{
/***** Store notify event *****/
DB_QueryINSERT ("can not create new notification event",
"INSERT INTO ntf_notifications"
" (NotifyEvent,ToUsrCod,FromUsrCod,"
"InsCod,CtrCod,DegCod,CrsCod,Cod,TimeNotif,Status)"
" VALUES"
" (%u,%ld,%ld,"
"%ld,%ld,%ld,%ld,%ld,NOW(),%u)",
(unsigned) NotifyEvent,
UsrDat->UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
InsCod,
CtrCod,
DegCod,
CrsCod,
Cod,
(unsigned) Status);
}
/*****************************************************************************/
/*************** Reset my number of new notifications to 0 *******************/
/*****************************************************************************/
static void Ntf_DB_UpdateMyLastAccessToNotifications (void)
{
/***** Reset to 0 my number of new notifications *****/
DB_QueryUPDATE ("can not update last access to notifications",
"UPDATE usr_last"
" SET LastAccNotif=NOW()"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/***************** Send all pending notifications by email *******************/
/*****************************************************************************/
@ -1582,21 +1361,7 @@ void Ntf_SendPendingNotifByEMailToAllUsrs (void)
unsigned NumTotalMails = 0;
/***** Get users who must be notified from database ******/
// (Status & Ntf_STATUS_BIT_EMAIL) &&
// !(Status & Ntf_STATUS_BIT_SENT) &&
// !(Status & (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED))
if ((NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users who must be notified",
"SELECT DISTINCT ToUsrCod"
" FROM ntf_notifications"
" WHERE TimeNotif<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)"
" AND (Status & %u)<>0"
" AND (Status & %u)=0"
" AND (Status & %u)=0",
Cfg_TIME_TO_SEND_PENDING_NOTIF,
(unsigned) Ntf_STATUS_BIT_EMAIL,
(unsigned) Ntf_STATUS_BIT_SENT,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)))) // Events found
if ((NumUsrs = Ntf_DB_GetUsrsWhoMustBeNotified (&mysql_res)))
{
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
@ -2130,8 +1895,8 @@ void Ntf_WriteNumberOfNewNtfs (void)
unsigned NumNewNtfs = 0;
/***** Get my number of unseen notifications *****/
if ((NumUnseenNtfs = Ntf_DB_GetNumberOfAllMyUnseenNtfs ()))
NumNewNtfs = Ntf_DB_GetNumberOfMyNewUnseenNtfs ();
if ((NumUnseenNtfs = Ntf_DB_GetNumAllMyUnseenNtfs ()))
NumNewNtfs = Ntf_DB_GetNumMyNewUnseenNtfs ();
/***** Begin form *****/
Frm_BeginFormId (ActSeeNewNtf,"form_ntf");
@ -2165,141 +1930,3 @@ void Ntf_WriteNumberOfNewNtfs (void)
/***** End form *****/
Frm_EndForm ();
}
/*****************************************************************************/
/************* Get the number of (all) my unseen notifications ***************/
/*****************************************************************************/
static unsigned Ntf_DB_GetNumberOfAllMyUnseenNtfs (void)
{
/***** Get number of places with a name from database *****/
return (unsigned)
DB_QueryCOUNT ("can not get number of unseen notifications",
"SELECT COUNT(*)"
" FROM ntf_notifications"
" WHERE ToUsrCod=%ld"
" AND (Status & %u)=0",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED));
}
/*****************************************************************************/
/************** Get the number of my new unseen notifications ****************/
/*****************************************************************************/
static unsigned Ntf_DB_GetNumberOfMyNewUnseenNtfs (void)
{
/***** Get number of places with a name from database *****/
return (unsigned)
DB_QueryCOUNT ("can not get number of unseen notifications",
"SELECT COUNT(*)"
" FROM ntf_notifications"
" WHERE ToUsrCod=%ld"
" AND (Status & %u)=0"
" AND TimeNotif>FROM_UNIXTIME(%ld)",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED),
Gbl.Usrs.Me.UsrLast.LastAccNotif);
}
/*****************************************************************************/
/**************** Remove all notifications made to a user ********************/
/*****************************************************************************/
void Ntf_DB_RemoveUsrNtfs (long ToUsrCod)
{
DB_QueryDELETE ("can not remove notifications of a user",
"DELETE LOW_PRIORITY FROM ntf_notifications"
" WHERE ToUsrCod=%ld",
ToUsrCod);
}
/*****************************************************************************/
/****************** Get number of notifications by email *********************/
/*****************************************************************************/
unsigned Ntf_DB_GetNumNotifs (MYSQL_RES **mysql_res,Ntf_NotifyEvent_t NotifyEvent)
{
switch (Gbl.Scope.Current)
{
case HieLvl_SYS:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get the number"
" of notifications by email",
"SELECT SUM(NumEvents)," // row[0]
"SUM(NumMails)" // row[1]
" FROM sta_notifications"
" WHERE NotifyEvent=%u",
(unsigned) NotifyEvent);
case HieLvl_CTY:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get the number"
" of notifications by email",
"SELECT SUM(sta_notifications.NumEvents)," // row[0]
"SUM(sta_notifications.NumMails)" // row[1]
" FROM ins_instits,"
"ctr_centers,"
"deg_degrees,"
"sta_notifications"
" WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=sta_notifications.DegCod"
" AND sta_notifications.NotifyEvent=%u",
Gbl.Hierarchy.Cty.CtyCod,
(unsigned) NotifyEvent);
case HieLvl_INS:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get the number"
" of notifications by email",
"SELECT SUM(sta_notifications.NumEvents)," // row[0]
"SUM(sta_notifications.NumMails)" // row[1]
" FROM ctr_centers,"
"deg_degrees,"
"sta_notifications"
" WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=sta_notifications.DegCod"
" AND sta_notifications.NotifyEvent=%u",
Gbl.Hierarchy.Ins.InsCod,
(unsigned) NotifyEvent);
case HieLvl_CTR:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get the number"
" of notifications by email",
"SELECT SUM(sta_notifications.NumEvents)," // row[0]
"SUM(sta_notifications.NumMails)" // row[1]
" FROM deg_degrees,"
"sta_notifications"
" WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=sta_notifications.DegCod"
" AND sta_notifications.NotifyEvent=%u",
Gbl.Hierarchy.Ctr.CtrCod,
(unsigned) NotifyEvent);
case HieLvl_DEG:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get the number"
" of notifications by email",
"SELECT SUM(NumEvents)," // row[0]
"SUM(NumMails)" // row[1]
" FROM sta_notifications"
" WHERE DegCod=%ld"
" AND NotifyEvent=%u",
Gbl.Hierarchy.Deg.DegCod,
(unsigned) NotifyEvent);
case HieLvl_CRS:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get the number"
" of notifications by email",
"SELECT SUM(NumEvents)," // row[0]
"SUM(NumMails)" // row[1]
" FROM sta_notifications"
" WHERE CrsCod=%ld"
" AND NotifyEvent=%u",
Gbl.Hierarchy.Crs.CrsCod,
(unsigned) NotifyEvent);
default:
Err_WrongScopeExit ();
return 0; // Not reached
}
}

View File

@ -121,19 +121,10 @@ void Ntf_GetNotifSummaryAndContent (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
Ntf_NotifyEvent_t NotifyEvent,
long Cod,long CrsCod,long UsrCod,
bool GetContent);
void Ntf_MarkNotifAsSeen (Ntf_NotifyEvent_t NotifyEvent,long Cod,long CrsCod,long ToUsrCod);
void Ntf_DB_MarkNotifAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod);
void Ntf_MarkNotifToOneUsrAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod,long ToUsrCod);
void Ntf_MarkNotifInCrsAsRemoved (long ToUsrCod,long CrsCod);
void Ntf_MarkNotifOneFileAsRemoved (const char *Path);
void Ntf_MarkNotifChildrenOfFolderAsRemoved (const char *Path);
void Ntf_DB_MarkNotifFilesInGroupAsRemoved (long GrpCod);
unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod);
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_SendPendingNotifByEMailToAllUsrs (void);
Ntf_NotifyEvent_t Ntf_GetNotifyEventFromStr (const char *Str);
void Ntf_MarkAllNotifAsSeen (void);
@ -141,8 +132,5 @@ void Ntf_PutFormChangeNotifSentByEMail (void);
void Ntf_ChangeNotifyEvents (void);
void Ntf_WriteNumberOfNewNtfs (void);
void Ntf_DB_RemoveUsrNtfs (long ToUsrCod);
unsigned Ntf_DB_GetNumNotifs (MYSQL_RES **mysql_res,Ntf_NotifyEvent_t NotifyEvent);
#endif

View File

@ -26,6 +26,8 @@
/*****************************************************************************/
#include "swad_database.h"
#include "swad_error.h"
#include "swad_global.h"
#include "swad_notification_database.h"
/*****************************************************************************/
@ -46,6 +48,201 @@ extern struct Globals Gbl;
/***************************** Private prototypes ****************************/
/*****************************************************************************/
/*****************************************************************************/
/************** 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)
{
DB_QueryINSERT ("can not create new notification event",
"INSERT INTO ntf_notifications"
" (NotifyEvent,ToUsrCod,FromUsrCod,"
"InsCod,CtrCod,DegCod,CrsCod,Cod,TimeNotif,Status)"
" VALUES"
" (%u,%ld,%ld,"
"%ld,%ld,%ld,%ld,%ld,NOW(),%u)",
(unsigned) NotifyEvent,
UsrDat->UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
InsCod,
CtrCod,
DegCod,
CrsCod,
Cod,
(unsigned) Status);
}
/*****************************************************************************/
/***************** Update my last access to notifications ********************/
/*****************************************************************************/
void Ntf_DB_UpdateMyLastAccessToNotifications (void)
{
DB_QueryUPDATE ("can not update last access to notifications",
"UPDATE usr_last"
" SET LastAccNotif=NOW()"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/********************** Set possible notification as seen ********************/
/*****************************************************************************/
void Ntf_DB_MarkNotifAsSeen (Ntf_NotifyEvent_t NotifyEvent,long Cod,long CrsCod,long ToUsrCod)
{
/***** Set notification as seen by me *****/
if (ToUsrCod > 0) // If the user code is specified
{
if (Cod > 0) // Set only one notification
// for the user as seen
DB_QueryUPDATE ("can not set notification(s) as seen",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld"
" AND NotifyEvent=%u"
" AND Cod=%ld",
(unsigned) Ntf_STATUS_BIT_READ,
ToUsrCod,
(unsigned) NotifyEvent,
Cod);
else if (CrsCod > 0) // Set all notifications of this type
// in the current course for the user as seen
DB_QueryUPDATE ("can not set notification(s) as seen",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld"
" AND NotifyEvent=%u"
" AND CrsCod=%ld",
(unsigned) Ntf_STATUS_BIT_READ,
ToUsrCod,
(unsigned) NotifyEvent,
Gbl.Hierarchy.Crs.CrsCod);
else // Set all notifications of this type
// for the user as seen
DB_QueryUPDATE ("can not set notification(s) as seen",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld"
" AND NotifyEvent=%u",
(unsigned) Ntf_STATUS_BIT_READ,
ToUsrCod,
(unsigned) NotifyEvent);
}
}
/*****************************************************************************/
/******************** Set possible notification as removed *******************/
/*****************************************************************************/
void Ntf_DB_MarkNotifToOneUsrAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod,long ToUsrCod)
{
/***** Set notification as removed *****/
if (Cod > 0) // Set only one notification as removed
DB_QueryUPDATE ("can not set notification(s) as removed",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld"
" AND NotifyEvent=%u"
" AND Cod=%ld",
(unsigned) Ntf_STATUS_BIT_REMOVED,
ToUsrCod,
(unsigned) NotifyEvent,
Cod);
else // Set all notifications of this type,
// in the current course for the user, as removed
DB_QueryUPDATE ("can not set notification(s) as removed",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld"
" AND NotifyEvent=%u"
" AND CrsCod=%ld",
(unsigned) Ntf_STATUS_BIT_REMOVED,
ToUsrCod,
(unsigned) NotifyEvent,
Gbl.Hierarchy.Crs.CrsCod);
}
/*****************************************************************************/
/*********** Set possible notifications from a course as removed *************/
/*****************************************************************************/
// This function should be called when a course is removed
// because notifications from this course will not be available after course removing.
// However, notifications about new messages should not be removed
// because the messages will remain available
void Ntf_DB_MarkNotifInCrsAsRemoved (long ToUsrCod,long CrsCod)
{
/***** Set all notifications from the course as removed,
except notifications about new messages *****/
if (ToUsrCod > 0) // If the user code is specified
DB_QueryUPDATE ("can not set notification(s) as removed",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld"
" AND CrsCod=%ld"
" AND NotifyEvent<>%u", // messages will remain available
(unsigned) Ntf_STATUS_BIT_REMOVED,
ToUsrCod,
CrsCod,
(unsigned) Ntf_EVENT_MESSAGE);
else // User code not specified ==> any user
DB_QueryUPDATE ("can not set notification(s) as removed",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE CrsCod=%ld"
" AND NotifyEvent<>%u", // messages will remain available
(unsigned) Ntf_STATUS_BIT_REMOVED,
CrsCod,
(unsigned) Ntf_EVENT_MESSAGE);
}
/*****************************************************************************/
/******************* Set possible notifications as removed *******************/
/*****************************************************************************/
void Ntf_DB_MarkNotifAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod)
{
DB_QueryUPDATE ("can not set notification(s) as removed",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE NotifyEvent=%u"
" AND Cod=%ld",
(unsigned) Ntf_STATUS_BIT_REMOVED,
(unsigned) NotifyEvent,
Cod);
}
/*****************************************************************************/
/******* Set all possible notifications of files in a group as removed *******/
/*****************************************************************************/
void Ntf_DB_MarkNotifFilesInGroupAsRemoved (long GrpCod)
{
DB_QueryUPDATE ("can not set notification(s) as removed",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE NotifyEvent IN (%u,%u,%u,%u)"
" AND Cod IN"
" (SELECT FilCod"
" FROM brw_files"
" WHERE FileBrowser IN (%u,%u,%u,%u)"
" AND Cod=%ld)",
(unsigned) Ntf_STATUS_BIT_REMOVED,
(unsigned) Ntf_EVENT_DOCUMENT_FILE,
(unsigned) Ntf_EVENT_TEACHERS_FILE,
(unsigned) Ntf_EVENT_SHARED_FILE,
(unsigned) Ntf_EVENT_MARKS_FILE,
(unsigned) Brw_ADMI_DOC_GRP,
(unsigned) Brw_ADMI_TCH_GRP,
(unsigned) Brw_ADMI_SHR_GRP,
(unsigned) Brw_ADMI_MRK_GRP,
GrpCod);
}
/*****************************************************************************/
/************ Set possible notifications of children as removed **************/
/*****************************************************************************/
@ -70,3 +267,198 @@ void Ntf_DB_MarkNotifChildrenOfFolderAsRemoved (Ntf_NotifyEvent_t NotifyEvent,
Cod,
Path);
}
/*****************************************************************************/
/*************************** Get my notifications ***************************/
/*****************************************************************************/
unsigned Ntf_DB_GetMyNotifications (MYSQL_RES **mysql_res,bool AllNotifications)
{
char SubQuery[128];
/***** Get my notifications from database *****/
if (AllNotifications)
SubQuery[0] = '\0';
else
sprintf (SubQuery," AND (Status&%u)=0",
Ntf_STATUS_BIT_READ |
Ntf_STATUS_BIT_REMOVED);
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get your notifications",
"SELECT NotifyEvent," // row[0]
"FromUsrCod," // row[1]
"InsCod," // row[2]
"CtrCod," // row[3]
"DegCod," // row[4]
"CrsCod," // row[5]
"Cod," // row[6]
"UNIX_TIMESTAMP(TimeNotif)," // row[7]
"Status" // row[8]
" FROM ntf_notifications"
" WHERE ToUsrCod=%ld"
"%s"
" ORDER BY TimeNotif DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,
SubQuery);
}
/*****************************************************************************/
/************* Get the number of (all) my unseen notifications ***************/
/*****************************************************************************/
unsigned Ntf_DB_GetNumAllMyUnseenNtfs (void)
{
return (unsigned)
DB_QueryCOUNT ("can not get number of unseen notifications",
"SELECT COUNT(*)"
" FROM ntf_notifications"
" WHERE ToUsrCod=%ld"
" AND (Status & %u)=0",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED));
}
/*****************************************************************************/
/************** Get the number of my new unseen notifications ****************/
/*****************************************************************************/
unsigned Ntf_DB_GetNumMyNewUnseenNtfs (void)
{
return (unsigned)
DB_QueryCOUNT ("can not get number of unseen notifications",
"SELECT COUNT(*)"
" FROM ntf_notifications"
" WHERE ToUsrCod=%ld"
" AND (Status & %u)=0"
" AND TimeNotif>FROM_UNIXTIME(%ld)",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED),
Gbl.Usrs.Me.UsrLast.LastAccNotif);
}
/*****************************************************************************/
/********************** Get users who must be notified ***********************/
/*****************************************************************************/
unsigned Ntf_DB_GetUsrsWhoMustBeNotified (MYSQL_RES **mysql_res)
{
// (Status & Ntf_STATUS_BIT_EMAIL) &&
// !(Status & Ntf_STATUS_BIT_SENT) &&
// !(Status & (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED))
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get users who must be notified",
"SELECT DISTINCT ToUsrCod"
" FROM ntf_notifications"
" WHERE TimeNotif<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)"
" AND (Status & %u)<>0"
" AND (Status & %u)=0"
" AND (Status & %u)=0",
Cfg_TIME_TO_SEND_PENDING_NOTIF,
(unsigned) Ntf_STATUS_BIT_EMAIL,
(unsigned) Ntf_STATUS_BIT_SENT,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED));
}
/*****************************************************************************/
/****************** Get number of notifications by email *********************/
/*****************************************************************************/
unsigned Ntf_DB_GetNumNotifs (MYSQL_RES **mysql_res,Ntf_NotifyEvent_t NotifyEvent)
{
switch (Gbl.Scope.Current)
{
case HieLvl_SYS:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get the number"
" of notifications by email",
"SELECT SUM(NumEvents)," // row[0]
"SUM(NumMails)" // row[1]
" FROM sta_notifications"
" WHERE NotifyEvent=%u",
(unsigned) NotifyEvent);
case HieLvl_CTY:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get the number"
" of notifications by email",
"SELECT SUM(sta_notifications.NumEvents)," // row[0]
"SUM(sta_notifications.NumMails)" // row[1]
" FROM ins_instits,"
"ctr_centers,"
"deg_degrees,"
"sta_notifications"
" WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=sta_notifications.DegCod"
" AND sta_notifications.NotifyEvent=%u",
Gbl.Hierarchy.Cty.CtyCod,
(unsigned) NotifyEvent);
case HieLvl_INS:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get the number"
" of notifications by email",
"SELECT SUM(sta_notifications.NumEvents)," // row[0]
"SUM(sta_notifications.NumMails)" // row[1]
" FROM ctr_centers,"
"deg_degrees,"
"sta_notifications"
" WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=sta_notifications.DegCod"
" AND sta_notifications.NotifyEvent=%u",
Gbl.Hierarchy.Ins.InsCod,
(unsigned) NotifyEvent);
case HieLvl_CTR:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get the number"
" of notifications by email",
"SELECT SUM(sta_notifications.NumEvents)," // row[0]
"SUM(sta_notifications.NumMails)" // row[1]
" FROM deg_degrees,"
"sta_notifications"
" WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=sta_notifications.DegCod"
" AND sta_notifications.NotifyEvent=%u",
Gbl.Hierarchy.Ctr.CtrCod,
(unsigned) NotifyEvent);
case HieLvl_DEG:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get the number"
" of notifications by email",
"SELECT SUM(NumEvents)," // row[0]
"SUM(NumMails)" // row[1]
" FROM sta_notifications"
" WHERE DegCod=%ld"
" AND NotifyEvent=%u",
Gbl.Hierarchy.Deg.DegCod,
(unsigned) NotifyEvent);
case HieLvl_CRS:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get the number"
" of notifications by email",
"SELECT SUM(NumEvents)," // row[0]
"SUM(NumMails)" // row[1]
" FROM sta_notifications"
" WHERE CrsCod=%ld"
" AND NotifyEvent=%u",
Gbl.Hierarchy.Crs.CrsCod,
(unsigned) NotifyEvent);
default:
Err_WrongScopeExit ();
return 0; // Not reached
}
}
/*****************************************************************************/
/**************** Remove all notifications made to a user ********************/
/*****************************************************************************/
void Ntf_DB_RemoveUsrNtfs (long ToUsrCod)
{
DB_QueryDELETE ("can not remove notifications of a user",
"DELETE LOW_PRIORITY FROM ntf_notifications"
" WHERE ToUsrCod=%ld",
ToUsrCod);
}

View File

@ -43,8 +43,26 @@
/****************************** 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_UpdateMyLastAccessToNotifications (void);
void Ntf_DB_MarkNotifAsSeen (Ntf_NotifyEvent_t NotifyEvent,long Cod,long CrsCod,long ToUsrCod);
void Ntf_DB_MarkNotifToOneUsrAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod,long ToUsrCod);
void Ntf_DB_MarkNotifInCrsAsRemoved (long ToUsrCod,long CrsCod);
void Ntf_DB_MarkNotifAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod);
void Ntf_DB_MarkNotifFilesInGroupAsRemoved (long GrpCod);
void Ntf_DB_MarkNotifChildrenOfFolderAsRemoved (Ntf_NotifyEvent_t NotifyEvent,
Brw_FileBrowser_t FileBrowser,
long Cod,const char *Path);
unsigned Ntf_DB_GetMyNotifications (MYSQL_RES **mysql_res,bool AllNotifications);
unsigned Ntf_DB_GetNumAllMyUnseenNtfs (void);
unsigned Ntf_DB_GetNumMyNewUnseenNtfs (void);
unsigned Ntf_DB_GetUsrsWhoMustBeNotified (MYSQL_RES **mysql_res);
unsigned Ntf_DB_GetNumNotifs (MYSQL_RES **mysql_res,Ntf_NotifyEvent_t NotifyEvent);
void Ntf_DB_RemoveUsrNtfs (long ToUsrCod);
#endif

View File

@ -49,6 +49,7 @@
#include "swad_network.h"
#include "swad_nickname.h"
#include "swad_notification.h"
#include "swad_notification_database.h"
#include "swad_parameter.h"
#include "swad_photo.h"
#include "swad_privacy.h"
@ -283,7 +284,7 @@ void Prf_GetUsrDatAndShowUserProfile (void)
/***** If it's not me, mark possible notification as seen *****/
ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
if (!ItsMe) // Not me
Ntf_MarkNotifAsSeen (Ntf_EVENT_FOLLOWER,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_FOLLOWER,
Gbl.Usrs.Other.UsrDat.UsrCod,-1L,
Gbl.Usrs.Me.UsrDat.UsrCod);
}

View File

@ -38,6 +38,7 @@
#include "swad_form.h"
#include "swad_global.h"
#include "swad_ID.h"
#include "swad_notification_database.h"
#include "swad_parameter.h"
#include "swad_string.h"

View File

@ -43,6 +43,7 @@
#include "swad_group_database.h"
#include "swad_HTML.h"
#include "swad_notification.h"
#include "swad_notification_database.h"
#include "swad_pagination.h"
#include "swad_parameter.h"
#include "swad_role.h"
@ -719,7 +720,7 @@ static void Svy_ShowOneSurvey (struct Svy_Surveys *Surveys,
/***** Mark possible notification as seen *****/
if (Svy.Scope == HieLvl_CRS) // Only course surveys are notified
Ntf_MarkNotifAsSeen (Ntf_EVENT_SURVEY,
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_SURVEY,
SvyCod,Svy.Cod,
Gbl.Usrs.Me.UsrDat.UsrCod);

View File

@ -34,6 +34,7 @@
#include "swad_forum.h"
#include "swad_global.h"
#include "swad_message.h"
#include "swad_notification_database.h"
#include "swad_photo.h"
#include "swad_profile.h"
#include "swad_timeline.h"

View File

@ -27,6 +27,7 @@
#include "swad_database.h"
#include "swad_global.h"
#include "swad_notification_database.h"
#include "swad_timeline.h"
#include "swad_timeline_database.h"
#include "swad_timeline_favourite.h"

View File

@ -39,6 +39,7 @@
#include "swad_global.h"
#include "swad_hierarchy.h"
#include "swad_notice.h"
#include "swad_notification_database.h"
#include "swad_photo.h"
#include "swad_profile.h"
#include "swad_timeline.h"

View File

@ -29,6 +29,7 @@
#include <string.h> // For string functions
#include "swad_global.h"
#include "swad_notification_database.h"
#include "swad_timeline.h"
#include "swad_timeline_database.h"
#include "swad_timeline_note.h"
@ -216,8 +217,8 @@ void Tml_Ntf_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
void Tml_Ntf_MarkMyNotifAsSeen (void)
{
Ntf_MarkNotifAsSeen (Ntf_EVENT_TL_COMMENT,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
Ntf_MarkNotifAsSeen (Ntf_EVENT_TL_FAV ,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
Ntf_MarkNotifAsSeen (Ntf_EVENT_TL_SHARE ,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
Ntf_MarkNotifAsSeen (Ntf_EVENT_TL_MENTION,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_TL_COMMENT,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_TL_FAV ,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_TL_SHARE ,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_TL_MENTION,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
}

View File

@ -27,6 +27,7 @@
#include "swad_database.h"
#include "swad_global.h"
#include "swad_notification_database.h"
#include "swad_timeline.h"
#include "swad_timeline_database.h"
#include "swad_timeline_notification.h"