Version 21.22: Oct 04, 2021 Queries related to notifications moved to other modules.

This commit is contained in:
acanas 2021-10-04 14:36:35 +02:00
parent 73e5e67df0
commit c529b1b8e8
30 changed files with 525 additions and 390 deletions

View File

@ -25,9 +25,10 @@
/*********************************** Headers *********************************/
/*****************************************************************************/
#include "swad_database.h"
#include "swad_admin.h"
#include "swad_admin_database.h"
#include "swad_database.h"
#include "swad_global.h"
/*****************************************************************************/
/****************************** Public constants *****************************/
@ -71,6 +72,28 @@ void Adm_DB_InsertAdmin (long UsrCod,HieLvl_Level_t Scope,long Cod)
Cod);
}
/*****************************************************************************/
/********** Get all admin codes above the current course, except me **********/
/*****************************************************************************/
unsigned Adm_DB_GetAdmsCurrentScopeExceptMe (MYSQL_RES **mysql_res)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get admins from current scope",
"SELECT UsrCod"
" FROM usr_admins"
" WHERE (Scope='%s'"
" OR (Scope='%s' AND Cod=%ld)"
" OR (Scope='%s' AND Cod=%ld)"
" OR (Scope='%s' AND Cod=%ld))"
" AND UsrCod<>%ld",
Sco_GetDBStrFromScope (HieLvl_SYS),
Sco_GetDBStrFromScope (HieLvl_INS),Gbl.Hierarchy.Ins.InsCod,
Sco_GetDBStrFromScope (HieLvl_CTR),Gbl.Hierarchy.Ctr.CtrCod,
Sco_GetDBStrFromScope (HieLvl_DEG),Gbl.Hierarchy.Deg.DegCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/***** Remove user as administrator of an institution, center or degree ******/
/*****************************************************************************/

View File

@ -42,6 +42,9 @@
/*****************************************************************************/
void Adm_DB_InsertAdmin (long UsrCod,HieLvl_Level_t Scope,long Cod);
unsigned Adm_DB_GetAdmsCurrentScopeExceptMe (MYSQL_RES **mysql_res);
void Adm_DB_RemAdmin (long UsrCod,HieLvl_Level_t Scope,long Cod);
void Adm_DB_RemUsrAsAdmin (long UsrCod);
void Adm_DB_RemAdmins (HieLvl_Level_t Scope,long Cod);

View File

@ -461,7 +461,6 @@ void Asg_DB_RemoveCrsAssignments (long CrsCod)
void Asg_DB_UpdateNumUsrsNotifiedByEMailAboutAssignment (long AsgCod,
unsigned NumUsrsToBeNotifiedByEMail)
{
/***** Update number of users notified *****/
DB_QueryUPDATE ("can not update the number of notifs. of an assignment",
"UPDATE asg_assignments"
" SET NumNotif=NumNotif+%u"
@ -470,6 +469,41 @@ void Asg_DB_UpdateNumUsrsNotifiedByEMailAboutAssignment (long AsgCod,
AsgCod);
}
/*****************************************************************************/
/********** Get all user codes belonging to an assignment, except me *********/
/*****************************************************************************/
unsigned Asg_DB_GetUsrsFromAssignmentExceptMe (MYSQL_RES **mysql_res,long AsgCod)
{
// 1. If the assignment is available for the whole course ==> get all users enroled in the course except me
// 2. If the assignment is available only for some groups ==> get all users who belong to any of the groups except me
// Cases 1 and 2 are mutually exclusive, so the union returns the case 1 or 2
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get users to be notified",
"(SELECT crs_users.UsrCod"
" FROM asg_assignments,"
"crs_users"
" WHERE asg_assignments.AsgCod=%ld"
" AND asg_assignments.AsgCod NOT IN"
" (SELECT AsgCod"
" FROM asg_groups"
" WHERE AsgCod=%ld)"
" AND asg_assignments.CrsCod=crs_users.CrsCod"
" AND crs_users.UsrCod<>%ld)"
" UNION "
"(SELECT DISTINCT grp_users.UsrCod"
" FROM asg_groups,"
"grp_users"
" WHERE asg_groups.AsgCod=%ld"
" AND asg_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod<>%ld)",
AsgCod,
AsgCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
AsgCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/****************** Get number of courses with assignments *******************/
/*****************************************************************************/

View File

@ -75,6 +75,7 @@ void Asg_DB_RemoveCrsAssignments (long CrsCod);
void Asg_DB_UpdateNumUsrsNotifiedByEMailAboutAssignment (long AsgCod,
unsigned NumUsrsToBeNotifiedByEMail);
unsigned Asg_DB_GetUsrsFromAssignmentExceptMe (MYSQL_RES **mysql_res,long AsgCod);
unsigned Asg_DB_GetNumCoursesWithAssignments (HieLvl_Level_t Scope);

View File

@ -151,7 +151,7 @@ void Cal_ChangeFirstDayOfWeek (void)
/***** Store icon first day of week database *****/
if (Gbl.Usrs.Me.Logged)
Set_DB_ChangeFirstDayOfWeek (Gbl.Prefs.FirstDayOfWeek);
Set_DB_UpdateMySettingsAboutFirstDayOfWeek (Gbl.Prefs.FirstDayOfWeek);
/***** Set settings from current IP *****/
Set_SetSettingsFromIP ();

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.2 (2021-10-01)"
#define Log_PLATFORM_VERSION "SWAD 21.22 (2021-10-04)"
#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.22: Oct 04, 2021 Queries related to notifications moved to other modules. (318058 lines)
Version 21.21.2: Oct 01, 2021 Queries moved to module swad_notification_database. (317963 lines)
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)

View File

@ -106,6 +106,40 @@ unsigned Enr_DB_GetUsrsFromCurrentCrs (MYSQL_RES **mysql_res)
Gbl.Hierarchy.Crs.CrsCod);
}
/*****************************************************************************/
/******* Get all user codes belonging to the current course, except me *******/
/*****************************************************************************/
unsigned Enr_DB_GetUsrsFromCurrentCrsExceptMe (MYSQL_RES **mysql_res)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get users from current course",
"SELECT UsrCod"
" FROM crs_users"
" WHERE CrsCod=%ld"
" AND UsrCod<>%ld",
Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/***** Get all teachers codes belonging to the current course, except me *****/
/*****************************************************************************/
unsigned Enr_DB_GetTchsFromCurrentCrsExceptMe (MYSQL_RES **mysql_res)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get teachers from current course",
"SELECT UsrCod"
" FROM crs_users"
" WHERE CrsCod=%ld"
" AND UsrCod<>%ld"
" AND Role=%u", // Teachers only
Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH);
}
/*****************************************************************************/
/************************** Remove user from course **************************/
/*****************************************************************************/

View File

@ -47,6 +47,8 @@ void Enr_DB_InsertUsrInCurrentCrs (long UsrCod,long CrsCod,Rol_Role_t NewRole,
void Enr_DB_AcceptUsrInCrs (long UsrCod,long CrsCod);
unsigned Enr_DB_GetUsrsFromCurrentCrs (MYSQL_RES **mysql_res);
unsigned Enr_DB_GetUsrsFromCurrentCrsExceptMe (MYSQL_RES **mysql_res);
unsigned Enr_DB_GetTchsFromCurrentCrsExceptMe (MYSQL_RES **mysql_res);
void Enr_DB_RemUsrFromCrs (long UsrCod,long CrsCod);
void Enr_DB_RemUsrFromAllCrss (long UsrCod);

View File

@ -364,6 +364,24 @@ unsigned For_DB_GetThreadAndNumPostsGivenPstCod (MYSQL_RES **mysql_res,long PstC
PstCod);
}
/*****************************************************************************/
/************* Get all publisher codes in a thread, except me ****************/
/*****************************************************************************/
unsigned For_DB_GetPublishersInThreadExceptMe (MYSQL_RES **mysql_res,long PstCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get publishers in thread",
"SELECT DISTINCT(UsrCod)"
" FROM for_posts"
" WHERE ThrCod=(SELECT ThrCod"
" FROM for_posts"
" WHERE PstCod=%ld)"
" AND UsrCod<>%ld",
PstCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/********************* Remove post from forum posts table ********************/
/*****************************************************************************/

View File

@ -58,6 +58,7 @@ unsigned For_DB_GetForumTypeAndLocationOfAPost (MYSQL_RES **mysql_res,long PstCo
unsigned For_DB_GetNumPostsUsr (long UsrCod);
unsigned For_DB_GetPostsOfAThread (MYSQL_RES **mysql_res,long ThrCod);
unsigned For_DB_GetThreadAndNumPostsGivenPstCod (MYSQL_RES **mysql_res,long PstCod);
unsigned For_DB_GetPublishersInThreadExceptMe (MYSQL_RES **mysql_res,long PstCod);
void For_DB_RemovePst (long PstCod);
void For_DB_RemoveThreadPsts (long ThrCod);

View File

@ -306,6 +306,46 @@ unsigned Grp_DB_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod)
GrpTypCod);
}
/*****************************************************************************/
/******** Get all user codes belonging to the current group, except me *******/
/*****************************************************************************/
unsigned Grp_DB_GetUsrsFromCurrentGrpExceptMe (MYSQL_RES **mysql_res)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get users from current group",
"SELECT UsrCod"
" FROM grp_users"
" WHERE GrpCod=%ld"
" AND UsrCod<>%ld",
Gbl.Crs.Grps.GrpCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/****** Get all teacher codes belonging to the current group, except me ******/
/*****************************************************************************/
unsigned Grp_DB_GetTchsFromCurrentGrpExceptMe (MYSQL_RES **mysql_res)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get teachers from current group",
"SELECT grp_users.UsrCod"
" FROM grp_users,"
"grp_groups,"
"grp_types,"
"crs_users"
" WHERE grp_users.GrpCod=%ld"
" AND grp_users.UsrCod<>%ld"
" AND grp_users.GrpCod=grp_groups.GrpCod"
" AND grp_groups.GrpTypCod=grp_types.GrpTypCod"
" AND grp_types.CrsCod=crs_users.CrsCod"
" AND crs_users.Role=%u", // Teachers only
Gbl.Crs.Grps.GrpCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH);
}
/*****************************************************************************/
/********* Check if I belong to any groups of a given type I belong **********/
/*****************************************************************************/

View File

@ -59,6 +59,8 @@ bool Grp_DB_CheckIfGrpNameExistsForGrpTyp (long GrpTypCod,const char *GrpName,lo
unsigned Grp_DB_CountNumUsrsInGrp (Rol_Role_t Role,long GrpCod);
unsigned Grp_DB_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod);
unsigned Grp_DB_GetUsrsFromCurrentGrpExceptMe (MYSQL_RES **mysql_res);
unsigned Grp_DB_GetTchsFromCurrentGrpExceptMe (MYSQL_RES **mysql_res);
bool Grp_DB_CheckIfIBelongToGrpsOfType (long GrpTypCod);
bool Grp_DB_CheckIfIBelongToGrp (long GrpCod);

View File

@ -165,7 +165,7 @@ void Ico_ChangeIconSet (void)
/***** Store icon set in database *****/
if (Gbl.Usrs.Me.Logged)
Set_DB_ChangeIconSet (Ico_IconSetId[Gbl.Prefs.IconSet]);
Set_DB_UpdateMySettingsAboutIconSet (Ico_IconSetId[Gbl.Prefs.IconSet]);
/***** Set settings from current IP *****/
Set_SetSettingsFromIP ();

View File

@ -129,7 +129,7 @@ int main (void)
Fil_CreateFileForHTMLOutput ();
/***** Remove old (expired) sessions *****/
Ses_RemoveExpiredSessions ();
Ses_DB_RemoveExpiredSessions ();
/***** Remove old users from connected list *****/
Con_DB_RemoveOldConnected ();

View File

@ -329,7 +329,7 @@ void Mnu_ChangeMenu (void)
/***** Store menu in database *****/
if (Gbl.Usrs.Me.Logged)
Set_DB_ChangeMenu (Gbl.Prefs.Menu);
Set_DB_UpdateMySettingsAboutMenu (Gbl.Prefs.Menu);
/***** Set settings from current IP *****/
Set_SetSettingsFromIP ();

View File

@ -1549,7 +1549,7 @@ static void Msg_ShowSntOrRcvMessages (struct Msg_Messages *Messages)
Messages->CurrentPage = (unsigned) Pagination.CurrentPage;
/***** Save my current page in order to show it next time I'll view my received/sent messages *****/
Pag_DB_SaveLastPageMsgIntoSession (WhatPaginate[Messages->TypeOfMessages],
Ses_DB_SaveLastPageMsgIntoSession (WhatPaginate[Messages->TypeOfMessages],
Messages->CurrentPage);
/***** Write links to pages *****/

View File

@ -32,6 +32,8 @@
#include <unistd.h> // For unlink
#include "swad_action.h"
#include "swad_admin_database.h"
#include "swad_assignment_database.h"
#include "swad_box.h"
#include "swad_browser_database.h"
#include "swad_call_for_exam.h"
@ -39,12 +41,15 @@
#include "swad_config.h"
#include "swad_database.h"
#include "swad_enrolment.h"
#include "swad_enrolment_database.h"
#include "swad_error.h"
#include "swad_figure.h"
#include "swad_follow.h"
#include "swad_form.h"
#include "swad_forum.h"
#include "swad_forum_database.h"
#include "swad_global.h"
#include "swad_group_database.h"
#include "swad_hierarchy.h"
#include "swad_hierarchy_level.h"
#include "swad_HTML.h"
@ -55,8 +60,10 @@
#include "swad_notification.h"
#include "swad_notification_database.h"
#include "swad_parameter.h"
#include "swad_setting.h"
#include "swad_survey.h"
#include "swad_timeline.h"
#include "swad_timeline_database.h"
#include "swad_timeline_notification.h"
#include "swad_timeline_publication.h"
@ -1033,97 +1040,29 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
case Brw_ADMI_DOC_CRS:
case Brw_ADMI_SHR_CRS:
case Brw_ADMI_MRK_CRS: // Notify all users in course except me
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod"
" FROM crs_users"
" WHERE CrsCod=%ld"
" AND UsrCod<>%ld",
Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
NumUsrs = Enr_DB_GetUsrsFromCurrentCrsExceptMe (&mysql_res);
break;
case Brw_ADMI_TCH_CRS: // Notify all teachers in course except me
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod"
" FROM crs_users"
" WHERE CrsCod=%ld"
" AND UsrCod<>%ld"
" AND Role=%u", // Notify teachers only
Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH);
NumUsrs = Enr_DB_GetTchsFromCurrentCrsExceptMe (&mysql_res);
break;
case Brw_ADMI_DOC_GRP:
case Brw_ADMI_SHR_GRP:
case Brw_ADMI_MRK_GRP: // Notify all users in group except me
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod"
" FROM grp_users"
" WHERE GrpCod=%ld"
" AND UsrCod<>%ld",
Gbl.Crs.Grps.GrpCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
NumUsrs = Grp_DB_GetUsrsFromCurrentGrpExceptMe (&mysql_res);
break;
case Brw_ADMI_TCH_GRP: // Notify all teachers in group except me
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT grp_users.UsrCod"
" FROM grp_users,"
"grp_groups,"
"grp_types,"
"crs_users"
" WHERE grp_users.GrpCod=%ld"
" AND grp_users.UsrCod<>%ld"
" AND grp_users.GrpCod=grp_groups.GrpCod"
" AND grp_groups.GrpTypCod=grp_types.GrpTypCod"
" AND grp_types.CrsCod=crs_users.CrsCod"
" AND crs_users.Role=%u", // Notify teachers only
Gbl.Crs.Grps.GrpCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH);
NumUsrs = Grp_DB_GetTchsFromCurrentGrpExceptMe (&mysql_res);
break;
default: // This function should not be called in other cases
return 0;
}
break;
case Ntf_EVENT_ASSIGNMENT:
// 1. If the assignment is available for the whole course ==> get all users enroled in the course except me
// 2. If the assignment is available only for some groups ==> get all users who belong to any of the groups except me
// Cases 1 and 2 are mutually exclusive, so the union returns the case 1 or 2
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"(SELECT crs_users.UsrCod"
" FROM asg_assignments,"
"crs_users"
" WHERE asg_assignments.AsgCod=%ld"
" AND asg_assignments.AsgCod NOT IN"
" (SELECT AsgCod"
" FROM asg_groups"
" WHERE AsgCod=%ld)"
" AND asg_assignments.CrsCod=crs_users.CrsCod"
" AND crs_users.UsrCod<>%ld)"
" UNION "
"(SELECT DISTINCT grp_users.UsrCod"
" FROM asg_groups,"
"grp_users"
" WHERE asg_groups.AsgCod=%ld"
" AND asg_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod<>%ld)",
Cod,Cod,Gbl.Usrs.Me.UsrDat.UsrCod,
Cod,Gbl.Usrs.Me.UsrDat.UsrCod);
NumUsrs = Asg_DB_GetUsrsFromAssignmentExceptMe (&mysql_res,Cod);
break;
case Ntf_EVENT_CALL_FOR_EXAM:
case Ntf_EVENT_NOTICE:
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod"
" FROM crs_users"
" WHERE CrsCod=%ld"
" AND UsrCod<>%ld",
Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
NumUsrs = Enr_DB_GetUsrsFromCurrentCrsExceptMe (&mysql_res);
break;
case Ntf_EVENT_ENROLMENT_STD: // This function should not be called in this case
case Ntf_EVENT_ENROLMENT_NET: // This function should not be called in this case
@ -1133,48 +1072,17 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
if (Usr_GetNumUsrsInCrss (HieLvl_CRS,Gbl.Hierarchy.Crs.CrsCod,
1 << Rol_TCH))
// If this course has teachers ==> send notification to teachers
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod"
" FROM crs_users"
" WHERE CrsCod=%ld"
" AND UsrCod<>%ld"
" AND Role=%u", // Notify teachers only
Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH);
NumUsrs = Enr_DB_GetTchsFromCurrentCrsExceptMe (&mysql_res);
else // Course without teachers
// If this course has no teachers
// and I want to be a teacher (checked before calling this function
// to not send requests to be a student to admins)
// ==> send notification to administrators or superusers
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod"
" FROM usr_admins"
" WHERE (Scope='%s'"
" OR (Scope='%s' AND Cod=%ld)"
" OR (Scope='%s' AND Cod=%ld)"
" OR (Scope='%s' AND Cod=%ld))"
" AND UsrCod<>%ld",
Sco_GetDBStrFromScope (HieLvl_SYS),
Sco_GetDBStrFromScope (HieLvl_INS),Gbl.Hierarchy.Ins.InsCod,
Sco_GetDBStrFromScope (HieLvl_CTR),Gbl.Hierarchy.Ctr.CtrCod,
Sco_GetDBStrFromScope (HieLvl_DEG),Gbl.Hierarchy.Deg.DegCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
NumUsrs = Adm_DB_GetAdmsCurrentScopeExceptMe (&mysql_res);
break;
case Ntf_EVENT_TL_COMMENT: // New comment to one of my social notes or comments
// Cod is the code of the social publishing
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT DISTINCT(PublisherCod)"
" FROM tml_pubs"
" WHERE NotCod=(SELECT NotCod"
" FROM tml_pubs"
" WHERE PubCod=%ld)"
" AND PublisherCod<>%ld",
Cod,
Gbl.Usrs.Me.UsrDat.UsrCod);
NumUsrs = Tml_DB_GetPublishersInNoteExceptMe (&mysql_res,Cod);
break;
case Ntf_EVENT_TL_FAV: // New favourite to one of my social notes or comments
case Ntf_EVENT_TL_SHARE: // New sharing of one of my social notes
@ -1189,84 +1097,23 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
switch (ForumSelected.Type)
{
case For_FORUM_COURSE_USRS:
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod"
" FROM crs_users"
" WHERE CrsCod=%ld"
" AND UsrCod<>%ld",
Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
NumUsrs = Enr_DB_GetUsrsFromCurrentCrsExceptMe (&mysql_res);
break;
case For_FORUM_COURSE_TCHS:
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod"
" FROM crs_users"
" WHERE CrsCod=%ld"
" AND Role=%u"
" AND UsrCod<>%ld",
Gbl.Hierarchy.Crs.CrsCod,
(unsigned) Rol_TCH,
Gbl.Usrs.Me.UsrDat.UsrCod);
NumUsrs = Enr_DB_GetTchsFromCurrentCrsExceptMe (&mysql_res);
break;
default:
return 0;
}
break;
case Ntf_EVENT_FORUM_REPLY:
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT DISTINCT(UsrCod)"
" FROM for_posts"
" WHERE ThrCod=(SELECT ThrCod"
" FROM for_posts"
" WHERE PstCod=%ld)"
" AND UsrCod<>%ld",
Cod,
Gbl.Usrs.Me.UsrDat.UsrCod);
// Cod is the code of the post
NumUsrs = For_DB_GetPublishersInThreadExceptMe (&mysql_res,Cod);
break;
case Ntf_EVENT_MESSAGE: // This function should not be called in this case
return 0;
case Ntf_EVENT_SURVEY: // Only surveys for a course are notified, not surveys for a degree or global
// 1. If the survey is available for the whole course ==> get users enroled in the course whose role is available in survey, except me
// 2. If the survey is available only for some groups ==> get users who belong to any of the groups and whose role is available in survey, except me
// Cases 1 and 2 are mutually exclusive, so the union returns the case 1 or 2
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"(SELECT crs_users.UsrCod"
" FROM svy_surveys,"
"crs_users"
" WHERE svy_surveys.SvyCod=%ld"
" AND svy_surveys.SvyCod NOT IN"
" (SELECT SvyCod"
" FROM svy_groups"
" WHERE SvyCod=%ld)"
" AND svy_surveys.Scope='%s'"
" AND svy_surveys.Cod=crs_users.CrsCod"
" AND crs_users.UsrCod<>%ld"
" AND (svy_surveys.Roles&(1<<crs_users.Role))<>0)"
" UNION "
"(SELECT DISTINCT grp_users.UsrCod"
" FROM svy_groups,"
"grp_users,"
"svy_surveys,"
"crs_users"
" WHERE svy_groups.SvyCod=%ld"
" AND svy_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod=crs_users.UsrCod"
" AND grp_users.UsrCod<>%ld"
" AND svy_groups.SvyCod=svy_surveys.SvyCod"
" AND svy_surveys.Scope='%s'"
" AND svy_surveys.Cod=crs_users.CrsCod"
" AND (svy_surveys.Roles&(1<<crs_users.Role))<>0)",
Cod,
Cod,
Sco_GetDBStrFromScope (HieLvl_CRS),
Gbl.Usrs.Me.UsrDat.UsrCod,
Cod,
Gbl.Usrs.Me.UsrDat.UsrCod,
Sco_GetDBStrFromScope (HieLvl_CRS));
NumUsrs = Svy_DB_GetUsrsFromSurveyExceptMe (&mysql_res,Cod);
break;
}
@ -1325,8 +1172,8 @@ 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_Status_t) Ntf_STATUS_BIT_EMAIL,
InsCod,CtrCod,DegCod,CrsCod);
NumUsrsToBeNotifiedByEMail++;
}
else // Don't send notification by email
@ -1635,17 +1482,7 @@ static void Ntf_GetNumNotifSent (long DegCod,long CrsCod,
MYSQL_ROW row;
/***** Get number of notifications sent by email from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get number of notifications"
" sent by email",
"SELECT NumEvents," // row[0]
"NumMails" // row[1]
" FROM sta_notifications"
" WHERE DegCod=%ld"
" AND CrsCod=%ld"
" AND NotifyEvent=%u",
DegCod,
CrsCod,
(unsigned) NotifyEvent))
if (Ntf_DB_GetNumNotifSent (&mysql_res,DegCod,CrsCod,NotifyEvent))
{
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",NumEvents) != 1)
@ -1661,7 +1498,7 @@ static void Ntf_GetNumNotifSent (long DegCod,long CrsCod,
}
/*****************************************************************************/
/******************** Update number of notify emails sent ********************/
/********** Update number of notifications and notify emails sent ************/
/*****************************************************************************/
static void Ntf_UpdateNumNotifSent (long DegCod,long CrsCod,
@ -1674,17 +1511,10 @@ static void Ntf_UpdateNumNotifSent (long DegCod,long CrsCod,
/***** Get number of events notified and number of mails sent *****/
Ntf_GetNumNotifSent (DegCod,CrsCod,NotifyEvent,&CurrentNumEvents,&CurrentNumMails);
/***** Update number of users notified *****/
DB_QueryREPLACE ("can not update the number of sent notifications",
"REPLACE INTO sta_notifications"
" (DegCod,CrsCod,NotifyEvent,NumEvents,NumMails)"
" VALUES"
" (%ld,%ld,%u,%u,%u)",
DegCod,
CrsCod,
(unsigned) NotifyEvent,
CurrentNumEvents + NumEvents,
CurrentNumMails + NumMails);
/***** Update number of notifications and notify emails sent *****/
Ntf_DB_UpdateNumNotifSent (DegCod,CrsCod,NotifyEvent,
CurrentNumEvents + NumEvents,
CurrentNumMails + NumMails);
}
/*****************************************************************************/
@ -1694,12 +1524,7 @@ static void Ntf_UpdateNumNotifSent (long DegCod,long CrsCod,
void Ntf_MarkAllNotifAsSeen (void)
{
/***** Set all my notifications as seen *****/
DB_QueryUPDATE ("can not set notification(s) as seen",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld",
(unsigned) Ntf_STATUS_BIT_READ,
Gbl.Usrs.Me.UsrDat.UsrCod);
Ntf_DB_MarkAllMyNotifAsSeen ();
/***** Show my notifications again *****/
Ntf_ShowMyNotifications ();
@ -1829,14 +1654,7 @@ void Ntf_ChangeNotifyEvents (void)
Ntf_GetParamsNotifyEvents ();
/***** Store settings about notify events *****/
DB_QueryUPDATE ("can not update user's settings",
"UPDATE usr_data"
" SET NotifNtfEvents=%u,"
"EmailNtfEvents=%u"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.NtfEvents.CreateNotif,
Gbl.Usrs.Me.UsrDat.NtfEvents.SendEmail,
Gbl.Usrs.Me.UsrDat.UsrCod);
Set_DB_UpdateMySettingsAboutNotifyEvents ();
/***** Show message *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_Your_settings_about_notifications_have_changed);

View File

@ -88,6 +88,20 @@ void Ntf_DB_UpdateMyLastAccessToNotifications (void)
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/******************** Mark all my notifications as seen **********************/
/*****************************************************************************/
void Ntf_DB_MarkAllMyNotifAsSeen (void)
{
DB_QueryUPDATE ("can not set notification(s) as seen",
"UPDATE ntf_notifications"
" SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld",
(unsigned) Ntf_STATUS_BIT_READ,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/********** Mark all the pending notifications of a user as 'sent' ***********/
/*****************************************************************************/
@ -288,6 +302,47 @@ void Ntf_DB_MarkNotifChildrenOfFolderAsRemoved (Ntf_NotifyEvent_t NotifyEvent,
Path);
}
/*****************************************************************************/
/******************** Update number of notify emails sent ********************/
/*****************************************************************************/
void Ntf_DB_UpdateNumNotifSent (long DegCod,long CrsCod,
Ntf_NotifyEvent_t NotifyEvent,
unsigned NumEvents,unsigned NumMails)
{
DB_QueryREPLACE ("can not update the number of sent notifications",
"REPLACE INTO sta_notifications"
" (DegCod,CrsCod,NotifyEvent,NumEvents,NumMails)"
" VALUES"
" (%ld,%ld,%u,%u,%u)",
DegCod,
CrsCod,
(unsigned) NotifyEvent,
NumEvents,
NumMails);
}
/*****************************************************************************/
/************* Get number of events notified and emails sent *****************/
/*****************************************************************************/
unsigned Ntf_DB_GetNumNotifSent (MYSQL_RES **mysql_res,
long DegCod,long CrsCod,
Ntf_NotifyEvent_t NotifyEvent)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get number of notifications"
" sent by email",
"SELECT NumEvents," // row[0]
"NumMails" // row[1]
" FROM sta_notifications"
" WHERE DegCod=%ld"
" AND CrsCod=%ld"
" AND NotifyEvent=%u",
DegCod,
CrsCod,
(unsigned) NotifyEvent);
}
/*****************************************************************************/
/*************************** Get my notifications ***************************/
/*****************************************************************************/

View File

@ -48,6 +48,7 @@ void Ntf_DB_StoreNotifyEventToOneUser (Ntf_NotifyEvent_t NotifyEvent,
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);
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);
@ -57,7 +58,13 @@ void Ntf_DB_MarkNotifFilesInGroupAsRemoved (long GrpCod);
void Ntf_DB_MarkNotifChildrenOfFolderAsRemoved (Ntf_NotifyEvent_t NotifyEvent,
Brw_FileBrowser_t FileBrowser,
long Cod,const char *Path);
void Ntf_DB_UpdateNumNotifSent (long DegCod,long CrsCod,
Ntf_NotifyEvent_t NotifyEvent,
unsigned NumEvents,unsigned NumMails);
unsigned Ntf_DB_GetNumNotifSent (MYSQL_RES **mysql_res,
long DegCod,long CrsCod,
Ntf_NotifyEvent_t NotifyEvent);
unsigned Ntf_DB_GetMyNotifications (MYSQL_RES **mysql_res,bool AllNotifications);
unsigned Ntf_DB_GetPendingNtfsToUsr (MYSQL_RES **mysql_res,long ToUsrCod);
unsigned Ntf_DB_GetNumAllMyUnseenNtfs (void);

View File

@ -173,123 +173,123 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
if (Subject)
{
HTM_DIV_Begin (NULL);
if (LinkToPagCurrent)
{
switch (WhatPaginate)
{
case Pag_ASSIGNMENTS:
Frm_BeginFormAnchor (ActSeeAsg,Pagination->Anchor);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Dat_PutHiddenParamOrder (((struct Asg_Assignments *) Context)->SelectedOrder);
WhichGroups = Grp_GetParamWhichGroups ();
Grp_PutParamWhichGroups (&WhichGroups);
break;
case Pag_PROJECTS:
Frm_BeginFormAnchor (ActSeePrj,Pagination->Anchor);
Prj_PutParams (&((struct Prj_Projects *) Context)->Filter,
((struct Prj_Projects *) Context)->SelectedOrder,
1,
Cod);
break;
case Pag_EXAMS:
Frm_BeginFormAnchor (ActSeeAllExa,Pagination->Anchor);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Dat_PutHiddenParamOrder (((struct Exa_Exams *) Context)->SelectedOrder);
WhichGroups = Grp_GetParamWhichGroups ();
Grp_PutParamWhichGroups (&WhichGroups);
break;
case Pag_GAMES:
Frm_BeginFormAnchor (ActSeeAllGam,Pagination->Anchor);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Dat_PutHiddenParamOrder (((struct Gam_Games *) Context)->SelectedOrder);
WhichGroups = Grp_GetParamWhichGroups ();
Grp_PutParamWhichGroups (&WhichGroups);
break;
case Pag_SURVEYS:
Frm_BeginFormAnchor (ActSeeAllSvy,Pagination->Anchor);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Dat_PutHiddenParamOrder (((struct Svy_Surveys *) Context)->SelectedOrder);
WhichGroups = Grp_GetParamWhichGroups ();
Grp_PutParamWhichGroups (&WhichGroups);
break;
case Pag_ATT_EVENTS:
Frm_BeginFormAnchor (ActSeeAtt,Pagination->Anchor);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Dat_PutHiddenParamOrder (((struct Att_Events *) Context)->SelectedOrder);
WhichGroups = Grp_GetParamWhichGroups ();
Grp_PutParamWhichGroups (&WhichGroups);
break;
case Pag_THREADS_FORUM:
Frm_BeginFormAnchor (For_ActionsSeeFor[((struct For_Forums *) Context)->Forum.Type],
Pagination->Anchor);
For_PutAllHiddenParamsForum (1, // Page of threads = first
1, // Page of posts = first
((struct For_Forums *) Context)->ForumSet,
((struct For_Forums *) Context)->ThreadsOrder,
((struct For_Forums *) Context)->Forum.Location,
-1L,
-1L);
break;
case Pag_POSTS_FORUM:
Frm_BeginFormAnchor (For_ActionsSeePstFor[((struct For_Forums *) Context)->Forum.Type],
Pagination->Anchor);
For_PutAllHiddenParamsForum (((struct For_Forums *) Context)->CurrentPageThrs, // Page of threads = current
1, // Page of posts = first
((struct For_Forums *) Context)->ForumSet,
((struct For_Forums *) Context)->ThreadsOrder,
((struct For_Forums *) Context)->Forum.Location,
Cod,
-1L);
break;
case Pag_MESSAGES_RECEIVED:
Frm_BeginFormAnchor (ActSeeRcvMsg,Pagination->Anchor);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Msg_PutHiddenParamsMsgsFilters ((struct Msg_Messages *) Context);
break;
case Pag_MESSAGES_SENT:
Frm_BeginFormAnchor (ActSeeSntMsg,Pagination->Anchor);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Msg_PutHiddenParamsMsgsFilters ((struct Msg_Messages *) Context);
break;
case Pag_MY_AGENDA:
Frm_BeginFormAnchor (ActSeeMyAgd,Pagination->Anchor);
Agd_PutParamsMyAgenda (((struct Agd_Agenda *) Context)->Past__FutureEvents,
((struct Agd_Agenda *) Context)->PrivatPublicEvents,
((struct Agd_Agenda *) Context)->HiddenVisiblEvents,
((struct Agd_Agenda *) Context)->SelectedOrder,
1,
Cod);
break;
case Pag_ANOTHER_AGENDA:
Frm_BeginFormAnchor (ActSeeUsrAgd,Pagination->Anchor);
Agd_PutHiddenParamEventsOrder (((struct Agd_Agenda *) Context)->SelectedOrder);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
break;
default:
break;
}
if (asprintf (&ClassLink,"BT_LINK LT %s",ClassTxt) < 0)
Err_NotEnoughMemoryExit ();
if (asprintf (&Title,Txt_Page_X_of_Y,1,Pagination->NumPags) < 0)
Err_NotEnoughMemoryExit ();
HTM_BUTTON_SUBMIT_Begin (Title,ClassLink,NULL);
free (Title);
free (ClassLink);
}
else
HTM_SPAN_Begin ("class=\"%s\"",ClassTxt);
if (FirstMsgEnabled)
HTM_Txt (Subject);
else
HTM_TxtF ("[%s]",Txt_FORUM_Post_banned);
if (LinkToPagCurrent)
{
HTM_BUTTON_End ();
Frm_EndForm ();
}
else
HTM_SPAN_End ();
if (LinkToPagCurrent)
{
switch (WhatPaginate)
{
case Pag_ASSIGNMENTS:
Frm_BeginFormAnchor (ActSeeAsg,Pagination->Anchor);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Dat_PutHiddenParamOrder (((struct Asg_Assignments *) Context)->SelectedOrder);
WhichGroups = Grp_GetParamWhichGroups ();
Grp_PutParamWhichGroups (&WhichGroups);
break;
case Pag_PROJECTS:
Frm_BeginFormAnchor (ActSeePrj,Pagination->Anchor);
Prj_PutParams (&((struct Prj_Projects *) Context)->Filter,
((struct Prj_Projects *) Context)->SelectedOrder,
1,
Cod);
break;
case Pag_EXAMS:
Frm_BeginFormAnchor (ActSeeAllExa,Pagination->Anchor);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Dat_PutHiddenParamOrder (((struct Exa_Exams *) Context)->SelectedOrder);
WhichGroups = Grp_GetParamWhichGroups ();
Grp_PutParamWhichGroups (&WhichGroups);
break;
case Pag_GAMES:
Frm_BeginFormAnchor (ActSeeAllGam,Pagination->Anchor);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Dat_PutHiddenParamOrder (((struct Gam_Games *) Context)->SelectedOrder);
WhichGroups = Grp_GetParamWhichGroups ();
Grp_PutParamWhichGroups (&WhichGroups);
break;
case Pag_SURVEYS:
Frm_BeginFormAnchor (ActSeeAllSvy,Pagination->Anchor);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Dat_PutHiddenParamOrder (((struct Svy_Surveys *) Context)->SelectedOrder);
WhichGroups = Grp_GetParamWhichGroups ();
Grp_PutParamWhichGroups (&WhichGroups);
break;
case Pag_ATT_EVENTS:
Frm_BeginFormAnchor (ActSeeAtt,Pagination->Anchor);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Dat_PutHiddenParamOrder (((struct Att_Events *) Context)->SelectedOrder);
WhichGroups = Grp_GetParamWhichGroups ();
Grp_PutParamWhichGroups (&WhichGroups);
break;
case Pag_THREADS_FORUM:
Frm_BeginFormAnchor (For_ActionsSeeFor[((struct For_Forums *) Context)->Forum.Type],
Pagination->Anchor);
For_PutAllHiddenParamsForum (1, // Page of threads = first
1, // Page of posts = first
((struct For_Forums *) Context)->ForumSet,
((struct For_Forums *) Context)->ThreadsOrder,
((struct For_Forums *) Context)->Forum.Location,
-1L,
-1L);
break;
case Pag_POSTS_FORUM:
Frm_BeginFormAnchor (For_ActionsSeePstFor[((struct For_Forums *) Context)->Forum.Type],
Pagination->Anchor);
For_PutAllHiddenParamsForum (((struct For_Forums *) Context)->CurrentPageThrs, // Page of threads = current
1, // Page of posts = first
((struct For_Forums *) Context)->ForumSet,
((struct For_Forums *) Context)->ThreadsOrder,
((struct For_Forums *) Context)->Forum.Location,
Cod,
-1L);
break;
case Pag_MESSAGES_RECEIVED:
Frm_BeginFormAnchor (ActSeeRcvMsg,Pagination->Anchor);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Msg_PutHiddenParamsMsgsFilters ((struct Msg_Messages *) Context);
break;
case Pag_MESSAGES_SENT:
Frm_BeginFormAnchor (ActSeeSntMsg,Pagination->Anchor);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Msg_PutHiddenParamsMsgsFilters ((struct Msg_Messages *) Context);
break;
case Pag_MY_AGENDA:
Frm_BeginFormAnchor (ActSeeMyAgd,Pagination->Anchor);
Agd_PutParamsMyAgenda (((struct Agd_Agenda *) Context)->Past__FutureEvents,
((struct Agd_Agenda *) Context)->PrivatPublicEvents,
((struct Agd_Agenda *) Context)->HiddenVisiblEvents,
((struct Agd_Agenda *) Context)->SelectedOrder,
1,
Cod);
break;
case Pag_ANOTHER_AGENDA:
Frm_BeginFormAnchor (ActSeeUsrAgd,Pagination->Anchor);
Agd_PutHiddenParamEventsOrder (((struct Agd_Agenda *) Context)->SelectedOrder);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
break;
default:
break;
}
if (asprintf (&ClassLink,"BT_LINK LT %s",ClassTxt) < 0)
Err_NotEnoughMemoryExit ();
if (asprintf (&Title,Txt_Page_X_of_Y,1,Pagination->NumPags) < 0)
Err_NotEnoughMemoryExit ();
HTM_BUTTON_SUBMIT_Begin (Title,ClassLink,NULL);
free (Title);
free (ClassLink);
}
else
HTM_SPAN_Begin ("class=\"%s\"",ClassTxt);
if (FirstMsgEnabled)
HTM_Txt (Subject);
else
HTM_TxtF ("[%s]",Txt_FORUM_Post_banned);
if (LinkToPagCurrent)
{
HTM_BUTTON_End ();
Frm_EndForm ();
}
else
HTM_SPAN_End ();
HTM_DIV_End ();
}
@ -399,14 +399,14 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
if (asprintf (&Title,Txt_Page_X_of_Y,1,Pagination->NumPags) < 0)
Err_NotEnoughMemoryExit ();
HTM_BUTTON_SUBMIT_Begin (Title,ClassLink,NULL);
HTM_Unsigned (1);
HTM_Unsigned (1);
HTM_BUTTON_End ();
free (Title);
Frm_EndForm ();
if (Pagination->LeftPage > 2)
{
HTM_SPAN_Begin ("class=\"%s\"",ClassTxt);
HTM_Txt ("&hellip;");
HTM_Txt ("&hellip;");
HTM_SPAN_End ();
}
}
@ -513,14 +513,14 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
Pagination->LeftPage,Pagination->NumPags) < 0)
Err_NotEnoughMemoryExit ();
HTM_BUTTON_SUBMIT_Begin (Title,ClassLink,NULL);
HTM_Unsigned (Pagination->LeftPage);
HTM_Unsigned (Pagination->LeftPage);
HTM_BUTTON_End ();
free (Title);
Frm_EndForm ();
if (Pagination->LeftPage < Pagination->StartPage - 1)
{
HTM_SPAN_Begin ("class=\"%s\"",ClassTxt);
HTM_Txt ("&hellip;");
HTM_Txt ("&hellip;");
HTM_SPAN_End ();
}
}
@ -535,7 +535,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
if (!LinkToPagCurrent && NumPage == Pagination->CurrentPage)
{
HTM_SPAN_Begin ("title=\"%s\" class=\"PAG_CUR %s\"",Title,ClassTxt);
HTM_Unsigned (NumPage);
HTM_Unsigned (NumPage);
HTM_SPAN_End ();
}
else
@ -635,7 +635,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
break;
}
HTM_BUTTON_SUBMIT_Begin (Title,ClassLink,NULL);
HTM_Unsigned (NumPage);
HTM_Unsigned (NumPage);
HTM_BUTTON_End ();
Frm_EndForm ();
}
@ -649,7 +649,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
if (Pagination->RightPage > Pagination->EndPage + 1)
{
HTM_SPAN_Begin ("class=\"%s\"",ClassTxt);
HTM_Txt ("&hellip;");
HTM_Txt ("&hellip;");
HTM_SPAN_End ();
}
switch (WhatPaginate)
@ -750,7 +750,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
Pagination->RightPage,Pagination->NumPags) < 0)
Err_NotEnoughMemoryExit ();
HTM_BUTTON_SUBMIT_Begin (Title,ClassLink,NULL);
HTM_Unsigned (Pagination->RightPage);
HTM_Unsigned (Pagination->RightPage);
HTM_BUTTON_End ();
free (Title);
Frm_EndForm ();
@ -762,7 +762,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
if (Pagination->NumPags > Pagination->RightPage + 1)
{
HTM_SPAN_Begin ("class=\"%s\"",ClassTxt);
HTM_Txt ("&hellip;");
HTM_Txt ("&hellip;");
HTM_SPAN_End ();
}
switch (WhatPaginate)
@ -863,7 +863,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
Pagination->NumPags,Pagination->NumPags) < 0)
Err_NotEnoughMemoryExit ();
HTM_BUTTON_SUBMIT_Begin (Title,ClassLink,NULL);
HTM_Unsigned (Pagination->NumPags);
HTM_Unsigned (Pagination->NumPags);
HTM_BUTTON_End ();
free (Title);
Frm_EndForm ();
@ -919,33 +919,12 @@ unsigned Pag_GetParamPagNum (Pag_WhatPaginate_t WhatPaginate)
return CurrentPage;
}
/*****************************************************************************/
/********* Save last page of received/sent messages into session *************/
/*****************************************************************************/
void Pag_DB_SaveLastPageMsgIntoSession (Pag_WhatPaginate_t WhatPaginate,unsigned NumPage)
{
/***** Save last page of received/sent messages *****/
DB_QueryUPDATE ("can not update last page of messages",
"UPDATE ses_sessions"
" SET %s=%u"
" WHERE SessionId='%s'",
WhatPaginate == Pag_MESSAGES_RECEIVED ? "LastPageMsgRcv" :
"LastPageMsgSnt",
NumPage,Gbl.Session.Id);
}
/*****************************************************************************/
/********* Get last page of received/sent messages stored in session *********/
/*****************************************************************************/
unsigned Pag_GetLastPageMsgFromSession (Pag_WhatPaginate_t WhatPaginate)
{
static const char *Field[Pag_NUM_WHAT_PAGINATE] =
{
[Pag_MESSAGES_RECEIVED] = "LastPageMsgRcv",
[Pag_MESSAGES_SENT ] = "LastPageMsgSnt",
};
unsigned NumPage;
switch (WhatPaginate)
@ -953,13 +932,7 @@ unsigned Pag_GetLastPageMsgFromSession (Pag_WhatPaginate_t WhatPaginate)
case Pag_MESSAGES_RECEIVED:
case Pag_MESSAGES_SENT:
/***** Get last page of received/sent messages from database *****/
NumPage = DB_QuerySELECTUnsigned ("can not get last page of messages",
"SELECT %s"
" FROM ses_sessions"
" WHERE SessionId='%s'",
Field[WhatPaginate],
Gbl.Session.Id);
if (NumPage == 0)
if ((NumPage = Ses_DB_GetLastPageMsgFromSession (WhatPaginate)) == 0)
return 1;
return NumPage;
default:

View File

@ -89,7 +89,6 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
void Pag_PutHiddenParamPagNum (Pag_WhatPaginate_t WhatPaginate,unsigned NumPage);
unsigned Pag_GetParamPagNum (Pag_WhatPaginate_t WhatPaginate);
void Pag_DB_SaveLastPageMsgIntoSession (Pag_WhatPaginate_t WhatPaginate,unsigned NumPage);
unsigned Pag_GetLastPageMsgFromSession (Pag_WhatPaginate_t WhatPaginate);
#endif

View File

@ -34,6 +34,7 @@
#include "swad_database.h"
#include "swad_error.h"
#include "swad_global.h"
#include "swad_pagination.h"
#include "swad_parameter.h"
#include "swad_timeline_database.h"
@ -214,12 +215,11 @@ void Ses_UpdateSessionDataInDB (void)
}
/*****************************************************************************/
/******************** Modify session last refresh in database ****************/
/******************** Update session last refresh in database ****************/
/*****************************************************************************/
void Ses_UpdateSessionLastRefreshInDB (void)
void Ses_DB_UpdateSessionLastRefresh (void)
{
/***** Update session in database *****/
DB_QueryUPDATE ("can not update session",
"UPDATE ses_sessions"
" SET LastRefresh=NOW()"
@ -248,7 +248,7 @@ static void Ses_RemoveSessionFromDB (void)
/*************************** Remove expired sessions *************************/
/*****************************************************************************/
void Ses_RemoveExpiredSessions (void)
void Ses_DB_RemoveExpiredSessions (void)
{
/***** Remove expired sessions *****/
/* A session expire
@ -560,3 +560,39 @@ void Ses_RemovePublicDirsFromExpiredSessions (void)
" (SELECT SessionId"
" FROM ses_sessions)");
}
/*****************************************************************************/
/********* Save last page of received/sent messages into session *************/
/*****************************************************************************/
void Ses_DB_SaveLastPageMsgIntoSession (Pag_WhatPaginate_t WhatPaginate,unsigned NumPage)
{
/***** Save last page of received/sent messages *****/
DB_QueryUPDATE ("can not update last page of messages",
"UPDATE ses_sessions"
" SET %s=%u"
" WHERE SessionId='%s'",
WhatPaginate == Pag_MESSAGES_RECEIVED ? "LastPageMsgRcv" :
"LastPageMsgSnt",
NumPage,Gbl.Session.Id);
}
/*****************************************************************************/
/********* Get last page of received/sent messages stored in session *********/
/*****************************************************************************/
unsigned Ses_DB_GetLastPageMsgFromSession (Pag_WhatPaginate_t WhatPaginate)
{
static const char *Field[Pag_NUM_WHAT_PAGINATE] =
{
[Pag_MESSAGES_RECEIVED] = "LastPageMsgRcv",
[Pag_MESSAGES_SENT ] = "LastPageMsgSnt",
};
return DB_QuerySELECTUnsigned ("can not get last page of messages",
"SELECT %s"
" FROM ses_sessions"
" WHERE SessionId='%s'",
Field[WhatPaginate],
Gbl.Session.Id);
}

View File

@ -28,6 +28,7 @@
/*****************************************************************************/
#include "swad_action.h"
#include "swad_pagination.h"
/*****************************************************************************/
/***************************** Public constants ******************************/
@ -43,8 +44,8 @@ bool Ses_CheckIfSessionExists (const char *IdSes);
void Ses_CloseSession (void);
void Ses_InsertSessionInDB (void);
void Ses_UpdateSessionDataInDB (void);
void Ses_UpdateSessionLastRefreshInDB (void);
void Ses_RemoveExpiredSessions (void);
void Ses_DB_UpdateSessionLastRefresh (void);
void Ses_DB_RemoveExpiredSessions (void);
void Ses_DB_RemoveUsrSessions (long UsrCod);
bool Ses_GetSessionData (void);
@ -60,4 +61,7 @@ void Ses_AddPublicDirToCache (const char *FullPathMediaPriv,
void Ses_RemovePublicDirsCache (void);
void Ses_RemovePublicDirsFromExpiredSessions (void);
void Ses_DB_SaveLastPageMsgIntoSession (Pag_WhatPaginate_t WhatPaginate,unsigned NumPage);
unsigned Ses_DB_GetLastPageMsgFromSession (Pag_WhatPaginate_t WhatPaginate);
#endif

View File

@ -373,7 +373,7 @@ void Set_DB_UpdateMySettingsAboutDateFormat (Dat_Format_t DateFormat)
/***************** Update my settings about first day of week ****************/
/*****************************************************************************/
void Set_DB_ChangeFirstDayOfWeek (unsigned FirstDayOfWeek)
void Set_DB_UpdateMySettingsAboutFirstDayOfWeek (unsigned FirstDayOfWeek)
{
DB_QueryUPDATE ("can not update your setting about first day of week",
"UPDATE usr_data"
@ -387,7 +387,7 @@ void Set_DB_ChangeFirstDayOfWeek (unsigned FirstDayOfWeek)
/********************* Update my settings about icon set *********************/
/*****************************************************************************/
void Set_DB_ChangeIconSet (const char *IconSetId)
void Set_DB_UpdateMySettingsAboutIconSet (const char *IconSetId)
{
DB_QueryUPDATE ("can not update your setting about icon set",
"UPDATE usr_data"
@ -401,7 +401,7 @@ void Set_DB_ChangeIconSet (const char *IconSetId)
/***************** Update my settings about first day of week ****************/
/*****************************************************************************/
void Set_DB_ChangeMenu (Mnu_Menu_t Menu)
void Set_DB_UpdateMySettingsAboutMenu (Mnu_Menu_t Menu)
{
DB_QueryUPDATE ("can not update your setting about menu",
"UPDATE usr_data"
@ -411,6 +411,22 @@ void Set_DB_ChangeMenu (Mnu_Menu_t Menu)
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/******************* Update my settings about notify events ******************/
/*****************************************************************************/
void Set_DB_UpdateMySettingsAboutNotifyEvents (void)
{
DB_QueryUPDATE ("can not update user's settings",
"UPDATE usr_data"
" SET NotifNtfEvents=%u,"
"EmailNtfEvents=%u"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.NtfEvents.CreateNotif,
Gbl.Usrs.Me.UsrDat.NtfEvents.SendEmail,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/*********** Head to select one or several settings using icons **************/
/*****************************************************************************/

View File

@ -52,9 +52,10 @@ unsigned Set_GetParamSideCols (void);
void Set_DB_UpdateMySettingsAboutLanguage (void);
void Set_DB_UpdateMySettingsAboutDateFormat (Dat_Format_t DateFormat);
void Set_DB_ChangeFirstDayOfWeek (unsigned FirstDayOfWeek);
void Set_DB_ChangeIconSet (const char *IconSetId);
void Set_DB_ChangeMenu (Mnu_Menu_t Menu);
void Set_DB_UpdateMySettingsAboutFirstDayOfWeek (unsigned FirstDayOfWeek);
void Set_DB_UpdateMySettingsAboutIconSet (const char *IconSetId);
void Set_DB_UpdateMySettingsAboutMenu (Mnu_Menu_t Menu);
void Set_DB_UpdateMySettingsAboutNotifyEvents (void);
void Set_BeginSettingsHead (void);
void Set_EndSettingsHead (void);

View File

@ -4241,3 +4241,49 @@ double Svy_GetNumQstsPerCrsSurvey (HieLvl_Level_t Scope)
return 0.0; // Not reached
}
}
/*****************************************************************************/
/************ Get all user codes belonging to a survey, except me ************/
/*****************************************************************************/
unsigned Svy_DB_GetUsrsFromSurveyExceptMe (MYSQL_RES **mysql_res,long SvyCod)
{
// 1. If the survey is available for the whole course ==> get users enroled in the course whose role is available in survey, except me
// 2. If the survey is available only for some groups ==> get users who belong to any of the groups and whose role is available in survey, except me
// Cases 1 and 2 are mutually exclusive, so the union returns the case 1 or 2
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get users to be notified",
"(SELECT crs_users.UsrCod"
" FROM svy_surveys,"
"crs_users"
" WHERE svy_surveys.SvyCod=%ld"
" AND svy_surveys.SvyCod NOT IN"
" (SELECT SvyCod"
" FROM svy_groups"
" WHERE SvyCod=%ld)"
" AND svy_surveys.Scope='%s'"
" AND svy_surveys.Cod=crs_users.CrsCod"
" AND crs_users.UsrCod<>%ld"
" AND (svy_surveys.Roles&(1<<crs_users.Role))<>0)"
" UNION "
"(SELECT DISTINCT grp_users.UsrCod"
" FROM svy_groups,"
"grp_users,"
"svy_surveys,"
"crs_users"
" WHERE svy_groups.SvyCod=%ld"
" AND svy_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod=crs_users.UsrCod"
" AND grp_users.UsrCod<>%ld"
" AND svy_groups.SvyCod=svy_surveys.SvyCod"
" AND svy_surveys.Scope='%s'"
" AND svy_surveys.Cod=crs_users.CrsCod"
" AND (svy_surveys.Roles&(1<<crs_users.Role))<>0)",
SvyCod,
SvyCod,
Sco_GetDBStrFromScope (HieLvl_CRS),
Gbl.Usrs.Me.UsrDat.UsrCod,
SvyCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
Sco_GetDBStrFromScope (HieLvl_CRS));
}

View File

@ -124,4 +124,6 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (HieLvl_Level_t Scope);
unsigned Svy_GetNumCrsSurveys (HieLvl_Level_t Scope,unsigned *NumNotif);
double Svy_GetNumQstsPerCrsSurvey (HieLvl_Level_t Scope);
unsigned Svy_DB_GetUsrsFromSurveyExceptMe (MYSQL_RES **mysql_res,long SvyCod);
#endif

View File

@ -1097,6 +1097,24 @@ unsigned Tml_DB_GetNumPubsUsr (long UsrCod)
UsrCod);
}
/*****************************************************************************/
/************** Get all publisher codes in a note, except me *****************/
/*****************************************************************************/
unsigned Tml_DB_GetPublishersInNoteExceptMe (MYSQL_RES **mysql_res,long PubCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get publishers of a note",
"SELECT DISTINCT(PublisherCod)"
" FROM tml_pubs"
" WHERE NotCod=(SELECT NotCod"
" FROM tml_pubs"
" WHERE PubCod=%ld)"
" AND PublisherCod<>%ld",
PubCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/********************* Insert new publication in database ********************/
/*****************************************************************************/

View File

@ -117,6 +117,7 @@ unsigned Tml_DB_GetDataOfPubByCod (long PubCod,MYSQL_RES **mysql_res);
long Tml_DB_GetNotCodFromPubCod (long PubCod);
long Tml_DB_GetPubCodFromSession (const char *FieldName);
unsigned Tml_DB_GetNumPubsUsr (long UsrCod);
unsigned Tml_DB_GetPublishersInNoteExceptMe (MYSQL_RES **mysql_res,long PubCod);
long Tml_DB_CreateNewPub (const struct Tml_Pub_Publication *Pub);
void Tml_DB_UpdateFirstPubCodInSession (long FirstPubCod);
void Tml_DB_UpdateLastPubCodInSession (void);

View File

@ -3105,7 +3105,7 @@ void Usr_ChkUsrAndGetUsrData (void)
Usr_SetMyPrefsAndRoles ();
if (Gbl.Action.IsAJAXAutoRefresh) // If refreshing ==> don't refresh LastTime in session
Ses_UpdateSessionLastRefreshInDB ();
Ses_DB_UpdateSessionLastRefresh ();
else
{
Act_AdjustCurrentAction ();