Version 18.7.37

This commit is contained in:
Antonio Cañas Vargas 2018-10-24 01:01:16 +02:00
parent c81df21f57
commit 41a6f927ab
2 changed files with 343 additions and 283 deletions

View File

@ -355,11 +355,12 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf ps2pdf source.ps destination.pdf
*/ */
#define Log_PLATFORM_VERSION "SWAD 18.7.37 (2018-10-23)" #define Log_PLATFORM_VERSION "SWAD 18.7.38 (2018-10-24)"
#define CSS_FILE "swad18.4.css" #define CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js" #define JS_FILE "swad17.17.1.js"
/* /*
Version 18.7.37: Oct 23, 2018 Some sprintf for database queries changed by asprintf. (237926 lines) Version 18.7.38: Oct 24, 2018 Some sprintf for database queries changed by asprintf. (237986 lines)
Version 18.7.37: Oct 24, 2018 Some sprintf for database queries changed by asprintf. (237926 lines)
Version 18.7.36: Oct 23, 2018 Some sprintf for database queries changed by asprintf. (237905 lines) Version 18.7.36: Oct 23, 2018 Some sprintf for database queries changed by asprintf. (237905 lines)
Version 18.7.35: Oct 23, 2018 Some sprintf for database queries changed by asprintf. (237876 lines) Version 18.7.35: Oct 23, 2018 Some sprintf for database queries changed by asprintf. (237876 lines)
Version 18.7.34: Oct 22, 2018 Some sprintf for database queries changed by asprintf. (237814 lines) Version 18.7.34: Oct 22, 2018 Some sprintf for database queries changed by asprintf. (237814 lines)

View File

@ -25,7 +25,9 @@
/********************************* Headers ***********************************/ /********************************* Headers ***********************************/
/*****************************************************************************/ /*****************************************************************************/
#define _GNU_SOURCE // For asprintf
#include <linux/stddef.h> // For NULL #include <linux/stddef.h> // For NULL
#include <stdio.h> // For asprintf
#include <stdlib.h> // For system #include <stdlib.h> // For system
#include <string.h> #include <string.h>
#include <sys/wait.h> // For the macro WEXITSTATUS #include <sys/wait.h> // For the macro WEXITSTATUS
@ -320,7 +322,7 @@ void Ntf_ShowMyNotifications (void)
extern const char *Txt_NOTIFICATION_STATUS[Ntf_NUM_STATUS_TXT]; 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_notifications;
extern const char *Txt_You_have_no_unread_notifications; extern const char *Txt_You_have_no_unread_notifications;
char Query[512]; char *Query;
char SubQuery[128]; char SubQuery[128];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
@ -353,13 +355,14 @@ void Ntf_ShowMyNotifications (void)
sprintf (SubQuery," AND (Status&%u)=0", sprintf (SubQuery," AND (Status&%u)=0",
Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_READ |
Ntf_STATUS_BIT_REMOVED); Ntf_STATUS_BIT_REMOVED);
sprintf (Query,"SELECT NotifyEvent,FromUsrCod,InsCod,CtrCod,DegCod,CrsCod," if (asprintf (&Query,"SELECT NotifyEvent,FromUsrCod,InsCod,CtrCod,DegCod,CrsCod,"
"Cod,UNIX_TIMESTAMP(TimeNotif),Status" "Cod,UNIX_TIMESTAMP(TimeNotif),Status"
" FROM notif" " FROM notif"
" WHERE ToUsrCod=%ld%s" " WHERE ToUsrCod=%ld%s"
" ORDER BY TimeNotif DESC", " ORDER BY TimeNotif DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,SubQuery); Gbl.Usrs.Me.UsrDat.UsrCod,SubQuery) < 0)
NumNotifications = DB_QuerySELECT (Query,&mysql_res,"can not get your notifications"); Lay_NotEnoughMemoryExit ();
NumNotifications = DB_QuerySELECT_free (Query,&mysql_res,"can not get your notifications");
/***** Contextual links *****/ /***** Contextual links *****/
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">"); fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
@ -943,27 +946,36 @@ void Ntf_GetNotifSummaryAndContent (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
void Ntf_MarkNotifAsSeen (Ntf_NotifyEvent_t NotifyEvent,long Cod,long CrsCod,long ToUsrCod) void Ntf_MarkNotifAsSeen (Ntf_NotifyEvent_t NotifyEvent,long Cod,long CrsCod,long ToUsrCod)
{ {
char Query[256]; char *Query;
/***** Set notification as seen by me *****/ /***** Set notification as seen by me *****/
if (ToUsrCod > 0) // If the user code is specified if (ToUsrCod > 0) // If the user code is specified
{ {
if (Cod > 0) // Set only one notification for the user as seen if (Cod > 0) // Set only one notification for the user as seen
sprintf (Query,"UPDATE notif SET Status=(Status | %u)" {
" WHERE ToUsrCod=%ld AND NotifyEvent=%u AND Cod=%ld", if (asprintf (&Query,"UPDATE notif SET Status=(Status | %u)"
(unsigned) Ntf_STATUS_BIT_READ, " WHERE ToUsrCod=%ld AND NotifyEvent=%u AND Cod=%ld",
ToUsrCod,(unsigned) NotifyEvent,Cod); (unsigned) Ntf_STATUS_BIT_READ,
ToUsrCod,(unsigned) NotifyEvent,Cod) < 0)
Lay_NotEnoughMemoryExit ();
}
else if (CrsCod > 0) // Set all notifications of this type in the current course for the user as seen else if (CrsCod > 0) // Set all notifications of this type in the current course for the user as seen
sprintf (Query,"UPDATE notif SET Status=(Status | %u)" {
" WHERE ToUsrCod=%ld AND NotifyEvent=%u AND CrsCod=%ld", if (asprintf (&Query,"UPDATE notif SET Status=(Status | %u)"
(unsigned) Ntf_STATUS_BIT_READ, " WHERE ToUsrCod=%ld AND NotifyEvent=%u AND CrsCod=%ld",
ToUsrCod,(unsigned) NotifyEvent,Gbl.CurrentCrs.Crs.CrsCod); (unsigned) Ntf_STATUS_BIT_READ,
ToUsrCod,(unsigned) NotifyEvent,Gbl.CurrentCrs.Crs.CrsCod) < 0)
Lay_NotEnoughMemoryExit ();
}
else // Set all notifications of this type for the user as seen else // Set all notifications of this type for the user as seen
sprintf (Query,"UPDATE notif SET Status=(Status | %u)" {
" WHERE ToUsrCod=%ld AND NotifyEvent=%u", if (asprintf (&Query,"UPDATE notif SET Status=(Status | %u)"
(unsigned) Ntf_STATUS_BIT_READ, " WHERE ToUsrCod=%ld AND NotifyEvent=%u",
ToUsrCod,(unsigned) NotifyEvent); (unsigned) Ntf_STATUS_BIT_READ,
DB_QueryUPDATE (Query,"can not set notification(s) as seen"); ToUsrCod,(unsigned) NotifyEvent) < 0)
Lay_NotEnoughMemoryExit ();
}
DB_QueryUPDATE_free (Query,"can not set notification(s) as seen");
} }
} }
@ -973,14 +985,15 @@ void Ntf_MarkNotifAsSeen (Ntf_NotifyEvent_t NotifyEvent,long Cod,long CrsCod,lon
void Ntf_MarkNotifAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod) void Ntf_MarkNotifAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod)
{ {
char Query[512]; char *Query;
/***** Set notification as removed *****/ /***** Set notification as removed *****/
sprintf (Query,"UPDATE notif SET Status=(Status | %u)" if (asprintf (&Query,"UPDATE notif SET Status=(Status | %u)"
" WHERE NotifyEvent=%u AND Cod=%ld", " WHERE NotifyEvent=%u AND Cod=%ld",
(unsigned) Ntf_STATUS_BIT_REMOVED, (unsigned) Ntf_STATUS_BIT_REMOVED,
(unsigned) NotifyEvent,Cod); (unsigned) NotifyEvent,Cod) < 0)
DB_QueryUPDATE (Query,"can not set notification(s) as removed"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not set notification(s) as removed");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -989,20 +1002,26 @@ void Ntf_MarkNotifAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod)
void Ntf_MarkNotifToOneUsrAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod,long ToUsrCod) void Ntf_MarkNotifToOneUsrAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod,long ToUsrCod)
{ {
char Query[512]; char *Query;
/***** Set notification as removed *****/ /***** Set notification as removed *****/
if (Cod > 0) // Set only one notification as removed if (Cod > 0) // Set only one notification as removed
sprintf (Query,"UPDATE notif SET Status=(Status | %u)" {
" WHERE ToUsrCod=%ld AND NotifyEvent=%u AND Cod=%ld", if (asprintf (&Query,"UPDATE notif SET Status=(Status | %u)"
(unsigned) Ntf_STATUS_BIT_REMOVED, " WHERE ToUsrCod=%ld AND NotifyEvent=%u AND Cod=%ld",
ToUsrCod,(unsigned) NotifyEvent,Cod); (unsigned) Ntf_STATUS_BIT_REMOVED,
ToUsrCod,(unsigned) NotifyEvent,Cod) < 0)
Lay_NotEnoughMemoryExit ();
}
else // Set all notifications of this type, in the current course for the user, as removed else // Set all notifications of this type, in the current course for the user, as removed
sprintf (Query,"UPDATE notif SET Status=(Status | %u)" {
" WHERE ToUsrCod=%ld AND NotifyEvent=%u AND CrsCod=%ld", if (asprintf (&Query,"UPDATE notif SET Status=(Status | %u)"
(unsigned) Ntf_STATUS_BIT_REMOVED, " WHERE ToUsrCod=%ld AND NotifyEvent=%u AND CrsCod=%ld",
ToUsrCod,(unsigned) NotifyEvent,Gbl.CurrentCrs.Crs.CrsCod); (unsigned) Ntf_STATUS_BIT_REMOVED,
DB_QueryUPDATE (Query,"can not set notification(s) as removed"); ToUsrCod,(unsigned) NotifyEvent,Gbl.CurrentCrs.Crs.CrsCod) < 0)
Lay_NotEnoughMemoryExit ();
}
DB_QueryUPDATE_free (Query,"can not set notification(s) as removed");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1015,25 +1034,31 @@ void Ntf_MarkNotifToOneUsrAsRemoved (Ntf_NotifyEvent_t NotifyEvent,long Cod,long
void Ntf_MarkNotifInCrsAsRemoved (long ToUsrCod,long CrsCod) void Ntf_MarkNotifInCrsAsRemoved (long ToUsrCod,long CrsCod)
{ {
char Query[256]; char *Query;
/***** Set all notifications from the course as removed, /***** Set all notifications from the course as removed,
except notifications about new messages *****/ except notifications about new messages *****/
if (ToUsrCod > 0) // If the user code is specified if (ToUsrCod > 0) // If the user code is specified
sprintf (Query,"UPDATE notif SET Status=(Status | %u)" {
" WHERE ToUsrCod=%ld" if (asprintf (&Query,"UPDATE notif SET Status=(Status | %u)"
" AND CrsCod=%ld" " WHERE ToUsrCod=%ld"
" AND NotifyEvent<>%u", // messages will remain available " AND CrsCod=%ld"
(unsigned) Ntf_STATUS_BIT_REMOVED, " AND NotifyEvent<>%u", // messages will remain available
ToUsrCod, (unsigned) Ntf_STATUS_BIT_REMOVED,
CrsCod,(unsigned) Ntf_EVENT_MESSAGE); ToUsrCod,
CrsCod,(unsigned) Ntf_EVENT_MESSAGE) < 0)
Lay_NotEnoughMemoryExit ();
}
else // User code not specified ==> any user else // User code not specified ==> any user
sprintf (Query,"UPDATE notif SET Status=(Status | %u)" {
" WHERE CrsCod=%ld" if (asprintf (&Query,"UPDATE notif SET Status=(Status | %u)"
" AND NotifyEvent<>%u", // messages will remain available " WHERE CrsCod=%ld"
(unsigned) Ntf_STATUS_BIT_REMOVED, " AND NotifyEvent<>%u", // messages will remain available
CrsCod,(unsigned) Ntf_EVENT_MESSAGE); (unsigned) Ntf_STATUS_BIT_REMOVED,
DB_QueryUPDATE (Query,"can not set notification(s) as removed"); CrsCod,(unsigned) Ntf_EVENT_MESSAGE) < 0)
Lay_NotEnoughMemoryExit ();
}
DB_QueryUPDATE_free (Query,"can not set notification(s) as removed");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1100,7 +1125,7 @@ void Ntf_MarkNotifChildrenOfFolderAsRemoved (const char *Path)
extern const Brw_FileBrowser_t Brw_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER]; extern const Brw_FileBrowser_t Brw_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER];
Brw_FileBrowser_t FileBrowser = Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type]; Brw_FileBrowser_t FileBrowser = Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type];
long Cod = Brw_GetCodForFiles (); long Cod = Brw_GetCodForFiles ();
char Query[512]; char *Query;
Ntf_NotifyEvent_t NotifyEvent; Ntf_NotifyEvent_t NotifyEvent;
switch (FileBrowser) switch (FileBrowser)
@ -1135,16 +1160,17 @@ void Ntf_MarkNotifChildrenOfFolderAsRemoved (const char *Path)
default: default:
return; return;
} }
sprintf (Query,"UPDATE notif SET Status=(Status | %u)" if (asprintf (&Query,"UPDATE notif SET Status=(Status | %u)"
" WHERE NotifyEvent=%u AND Cod IN" " WHERE NotifyEvent=%u AND Cod IN"
" (SELECT FilCod FROM files" " (SELECT FilCod FROM files"
" WHERE FileBrowser=%u AND Cod=%ld" " WHERE FileBrowser=%u AND Cod=%ld"
" AND Path LIKE '%s/%%')", " AND Path LIKE '%s/%%')",
(unsigned) Ntf_STATUS_BIT_REMOVED, (unsigned) Ntf_STATUS_BIT_REMOVED,
(unsigned) NotifyEvent, (unsigned) NotifyEvent,
(unsigned) FileBrowser,Cod, (unsigned) FileBrowser,Cod,
Path); Path) < 0)
DB_QueryUPDATE (Query,"can not set notification(s) as removed"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not set notification(s) as removed");
break; break;
default: default:
break; break;
@ -1157,24 +1183,25 @@ void Ntf_MarkNotifChildrenOfFolderAsRemoved (const char *Path)
void Ntf_MarkNotifFilesInGroupAsRemoved (long GrpCod) void Ntf_MarkNotifFilesInGroupAsRemoved (long GrpCod)
{ {
char Query[512]; char *Query;
/***** Set notifications as removed *****/ /***** Set notifications as removed *****/
sprintf (Query,"UPDATE notif SET Status=(Status | %u)" if (asprintf (&Query,"UPDATE notif SET Status=(Status | %u)"
" WHERE NotifyEvent IN (%u,%u,%u,%u) AND Cod IN" " WHERE NotifyEvent IN (%u,%u,%u,%u) AND Cod IN"
" (SELECT FilCod FROM files" " (SELECT FilCod FROM files"
" WHERE FileBrowser IN (%u,%u,%u,%u) AND Cod=%ld)", " WHERE FileBrowser IN (%u,%u,%u,%u) AND Cod=%ld)",
(unsigned) Ntf_STATUS_BIT_REMOVED, (unsigned) Ntf_STATUS_BIT_REMOVED,
(unsigned) Ntf_EVENT_DOCUMENT_FILE, (unsigned) Ntf_EVENT_DOCUMENT_FILE,
(unsigned) Ntf_EVENT_TEACHERS_FILE, (unsigned) Ntf_EVENT_TEACHERS_FILE,
(unsigned) Ntf_EVENT_SHARED_FILE, (unsigned) Ntf_EVENT_SHARED_FILE,
(unsigned) Ntf_EVENT_MARKS_FILE, (unsigned) Ntf_EVENT_MARKS_FILE,
(unsigned) Brw_ADMI_DOC_GRP, (unsigned) Brw_ADMI_DOC_GRP,
(unsigned) Brw_ADMI_TCH_GRP, (unsigned) Brw_ADMI_TCH_GRP,
(unsigned) Brw_ADMI_SHR_GRP, (unsigned) Brw_ADMI_SHR_GRP,
(unsigned) Brw_ADMI_MRK_GRP, (unsigned) Brw_ADMI_MRK_GRP,
GrpCod); GrpCod) < 0)
DB_QueryUPDATE (Query,"can not set notification(s) as removed"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not set notification(s) as removed");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1186,7 +1213,7 @@ void Ntf_MarkNotifFilesInGroupAsRemoved (long GrpCod)
unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
char Query[1024]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRow; unsigned long NumRow;
@ -1210,42 +1237,46 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
case Brw_ADMI_DOC_CRS: case Brw_ADMI_DOC_CRS:
case Brw_ADMI_SHR_CRS: case Brw_ADMI_SHR_CRS:
case Brw_ADMI_MRK_CRS: // Notify all users in course except me case Brw_ADMI_MRK_CRS: // Notify all users in course except me
sprintf (Query,"SELECT UsrCod FROM crs_usr" if (asprintf (&Query,"SELECT UsrCod FROM crs_usr"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND UsrCod<>%ld", " AND UsrCod<>%ld",
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Brw_ADMI_TCH_CRS: // Notify all teachers in course except me case Brw_ADMI_TCH_CRS: // Notify all teachers in course except me
sprintf (Query,"SELECT UsrCod FROM crs_usr" if (asprintf (&Query,"SELECT UsrCod FROM crs_usr"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND UsrCod<>%ld" " AND UsrCod<>%ld"
" AND Role=%u", // Notify teachers only " AND Role=%u", // Notify teachers only
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH); (unsigned) Rol_TCH) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Brw_ADMI_DOC_GRP: case Brw_ADMI_DOC_GRP:
case Brw_ADMI_SHR_GRP: case Brw_ADMI_SHR_GRP:
case Brw_ADMI_MRK_GRP: // Notify all users in group except me case Brw_ADMI_MRK_GRP: // Notify all users in group except me
sprintf (Query,"SELECT UsrCod FROM crs_grp_usr" if (asprintf (&Query,"SELECT UsrCod FROM crs_grp_usr"
" WHERE crs_grp_usr.GrpCod=%ld" " WHERE crs_grp_usr.GrpCod=%ld"
" AND crs_grp_usr.UsrCod<>%ld", " AND crs_grp_usr.UsrCod<>%ld",
Gbl.CurrentCrs.Grps.GrpCod, Gbl.CurrentCrs.Grps.GrpCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Brw_ADMI_TCH_GRP: // Notify all teachers in group except me case Brw_ADMI_TCH_GRP: // Notify all teachers in group except me
sprintf (Query,"SELECT crs_grp_usr.UsrCod" if (asprintf (&Query,"SELECT crs_grp_usr.UsrCod"
" FROM crs_grp_usr,crs_grp,crs_grp_types,crs_usr" " FROM crs_grp_usr,crs_grp,crs_grp_types,crs_usr"
" WHERE crs_grp_usr.GrpCod=%ld" " WHERE crs_grp_usr.GrpCod=%ld"
" AND crs_grp_usr.UsrCod<>%ld" " AND crs_grp_usr.UsrCod<>%ld"
" AND crs_grp_usr.GrpCod=crs_grp.GrpCod" " AND crs_grp_usr.GrpCod=crs_grp.GrpCod"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod" " AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
" AND crs_grp_types.CrsCod=crs_usr.CrsCod" " AND crs_grp_types.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u", // Notify teachers only " AND crs_usr.Role=%u", // Notify teachers only
Gbl.CurrentCrs.Grps.GrpCod, Gbl.CurrentCrs.Grps.GrpCod,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH); (unsigned) Rol_TCH) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
default: // This function should not be called in other cases default: // This function should not be called in other cases
return 0; return 0;
@ -1255,28 +1286,30 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
// 1. If the assignment is available for the whole course ==> get all users enroled in the course except me // 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 // 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 // Cases 1 and 2 are mutually exclusive, so the union returns the case 1 or 2
sprintf (Query,"(SELECT crs_usr.UsrCod" if (asprintf (&Query,"(SELECT crs_usr.UsrCod"
" FROM assignments,crs_usr" " FROM assignments,crs_usr"
" WHERE assignments.AsgCod=%ld" " WHERE assignments.AsgCod=%ld"
" AND assignments.AsgCod NOT IN" " AND assignments.AsgCod NOT IN"
" (SELECT AsgCod FROM asg_grp WHERE AsgCod=%ld)" " (SELECT AsgCod FROM asg_grp WHERE AsgCod=%ld)"
" AND assignments.CrsCod=crs_usr.CrsCod" " AND assignments.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod<>%ld)" " AND crs_usr.UsrCod<>%ld)"
" UNION " " UNION "
"(SELECT DISTINCT crs_grp_usr.UsrCod" "(SELECT DISTINCT crs_grp_usr.UsrCod"
" FROM asg_grp,crs_grp_usr" " FROM asg_grp,crs_grp_usr"
" WHERE asg_grp.AsgCod=%ld" " WHERE asg_grp.AsgCod=%ld"
" AND asg_grp.GrpCod=crs_grp_usr.GrpCod" " AND asg_grp.GrpCod=crs_grp_usr.GrpCod"
" AND crs_grp_usr.UsrCod<>%ld)", " AND crs_grp_usr.UsrCod<>%ld)",
Cod,Cod,Gbl.Usrs.Me.UsrDat.UsrCod, Cod,Cod,Gbl.Usrs.Me.UsrDat.UsrCod,
Cod,Gbl.Usrs.Me.UsrDat.UsrCod); Cod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Ntf_EVENT_EXAM_ANNOUNCEMENT: case Ntf_EVENT_EXAM_ANNOUNCEMENT:
case Ntf_EVENT_NOTICE: case Ntf_EVENT_NOTICE:
sprintf (Query,"SELECT UsrCod FROM crs_usr" if (asprintf (&Query,"SELECT UsrCod FROM crs_usr"
" WHERE CrsCod=%ld AND UsrCod<>%ld", " WHERE CrsCod=%ld AND UsrCod<>%ld",
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Ntf_EVENT_ENROLMENT_STD: // This function should not be called in this case 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 case Ntf_EVENT_ENROLMENT_NET: // This function should not be called in this case
@ -1284,38 +1317,45 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
return 0; return 0;
case Ntf_EVENT_ENROLMENT_REQUEST: case Ntf_EVENT_ENROLMENT_REQUEST:
if (Gbl.CurrentCrs.Crs.NumUsrs[Rol_TCH]) if (Gbl.CurrentCrs.Crs.NumUsrs[Rol_TCH])
{
// If this course has teachers ==> send notification to teachers // If this course has teachers ==> send notification to teachers
sprintf (Query,"SELECT UsrCod FROM crs_usr" if (asprintf (&Query,"SELECT UsrCod FROM crs_usr"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND UsrCod<>%ld" " AND UsrCod<>%ld"
" AND Role=%u", // Notify teachers only " AND Role=%u", // Notify teachers only
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH); (unsigned) Rol_TCH) < 0)
Lay_NotEnoughMemoryExit ();
}
else // Course without teachers else // Course without teachers
{
// If this course has no teachers // If this course has no teachers
// and I want to be a teacher (checked before calling this function // and I want to be a teacher (checked before calling this function
// to not send requests to be a student to admins) // to not send requests to be a student to admins)
// ==> send notification to administrators or superusers // ==> send notification to administrators or superusers
sprintf (Query,"SELECT UsrCod FROM admin" if (asprintf (&Query,"SELECT UsrCod FROM admin"
" WHERE (Scope='%s'" " WHERE (Scope='%s'"
" OR (Scope='%s' AND Cod=%ld)" " OR (Scope='%s' AND Cod=%ld)"
" OR (Scope='%s' AND Cod=%ld)" " OR (Scope='%s' AND Cod=%ld)"
" OR (Scope='%s' AND Cod=%ld))" " OR (Scope='%s' AND Cod=%ld))"
" AND UsrCod<>%ld", " AND UsrCod<>%ld",
Sco_ScopeDB[Sco_SCOPE_SYS], Sco_ScopeDB[Sco_SCOPE_SYS],
Sco_ScopeDB[Sco_SCOPE_INS],Gbl.CurrentIns.Ins.InsCod, Sco_ScopeDB[Sco_SCOPE_INS],Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CTR],Gbl.CurrentCtr.Ctr.CtrCod, Sco_ScopeDB[Sco_SCOPE_CTR],Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_DEG],Gbl.CurrentDeg.Deg.DegCod, Sco_ScopeDB[Sco_SCOPE_DEG],Gbl.CurrentDeg.Deg.DegCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
}
break; break;
case Ntf_EVENT_TIMELINE_COMMENT: // New comment to one of my social notes or comments case Ntf_EVENT_TIMELINE_COMMENT: // New comment to one of my social notes or comments
// Cod is the code of the social publishing // Cod is the code of the social publishing
sprintf (Query,"SELECT DISTINCT(PublisherCod) FROM social_pubs" if (asprintf (&Query,"SELECT DISTINCT(PublisherCod) FROM social_pubs"
" WHERE NotCod = (SELECT NotCod FROM social_pubs" " WHERE NotCod = (SELECT NotCod FROM social_pubs"
" WHERE PubCod=%ld)" " WHERE PubCod=%ld)"
" AND PublisherCod<>%ld", " AND PublisherCod<>%ld",
Cod,Gbl.Usrs.Me.UsrDat.UsrCod); Cod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Ntf_EVENT_TIMELINE_FAV: // New favourite to one of my social notes or comments case Ntf_EVENT_TIMELINE_FAV: // New favourite to one of my social notes or comments
case Ntf_EVENT_TIMELINE_SHARE: // New sharing of one of my social notes case Ntf_EVENT_TIMELINE_SHARE: // New sharing of one of my social notes
@ -1329,28 +1369,31 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
switch (ForumSelected.Type) switch (ForumSelected.Type)
{ {
case For_FORUM_COURSE_USRS: case For_FORUM_COURSE_USRS:
sprintf (Query,"SELECT UsrCod FROM crs_usr" if (asprintf (&Query,"SELECT UsrCod FROM crs_usr"
" WHERE CrsCod=%ld AND UsrCod<>%ld", " WHERE CrsCod=%ld AND UsrCod<>%ld",
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case For_FORUM_COURSE_TCHS: case For_FORUM_COURSE_TCHS:
sprintf (Query,"SELECT UsrCod FROM crs_usr" if (asprintf (&Query,"SELECT UsrCod FROM crs_usr"
" WHERE CrsCod=%ld AND Role=%u AND UsrCod<>%ld", " WHERE CrsCod=%ld AND Role=%u AND UsrCod<>%ld",
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
(unsigned) Rol_TCH, (unsigned) Rol_TCH,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
default: default:
return 0; return 0;
} }
break; break;
case Ntf_EVENT_FORUM_REPLY: case Ntf_EVENT_FORUM_REPLY:
sprintf (Query,"SELECT DISTINCT(UsrCod) FROM forum_post" if (asprintf (&Query,"SELECT DISTINCT(UsrCod) FROM forum_post"
" WHERE ThrCod = (SELECT ThrCod FROM forum_post" " WHERE ThrCod = (SELECT ThrCod FROM forum_post"
" WHERE PstCod=%ld)" " WHERE PstCod=%ld)"
" AND UsrCod<>%ld", " AND UsrCod<>%ld",
Cod,Gbl.Usrs.Me.UsrDat.UsrCod); Cod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Ntf_EVENT_MESSAGE: // This function should not be called in this case case Ntf_EVENT_MESSAGE: // This function should not be called in this case
return 0; return 0;
@ -1358,35 +1401,36 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
// 1. If the survey is available for the whole course ==> get users enroled in the course whose role is available in survey, except me // 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 // 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 // Cases 1 and 2 are mutually exclusive, so the union returns the case 1 or 2
sprintf (Query,"(SELECT crs_usr.UsrCod" if (asprintf (&Query,"(SELECT crs_usr.UsrCod"
" FROM surveys,crs_usr" " FROM surveys,crs_usr"
" WHERE surveys.SvyCod=%ld" " WHERE surveys.SvyCod=%ld"
" AND surveys.SvyCod NOT IN" " AND surveys.SvyCod NOT IN"
" (SELECT SvyCod FROM svy_grp WHERE SvyCod=%ld)" " (SELECT SvyCod FROM svy_grp WHERE SvyCod=%ld)"
" AND surveys.Scope='%s' AND surveys.Cod=crs_usr.CrsCod" " AND surveys.Scope='%s' AND surveys.Cod=crs_usr.CrsCod"
" AND crs_usr.UsrCod<>%ld" " AND crs_usr.UsrCod<>%ld"
" AND (surveys.Roles&(1<<crs_usr.Role))<>0)" " AND (surveys.Roles&(1<<crs_usr.Role))<>0)"
" UNION " " UNION "
"(SELECT DISTINCT crs_grp_usr.UsrCod" "(SELECT DISTINCT crs_grp_usr.UsrCod"
" FROM svy_grp,crs_grp_usr,surveys,crs_usr" " FROM svy_grp,crs_grp_usr,surveys,crs_usr"
" WHERE svy_grp.SvyCod=%ld" " WHERE svy_grp.SvyCod=%ld"
" AND svy_grp.GrpCod=crs_grp_usr.GrpCod" " AND svy_grp.GrpCod=crs_grp_usr.GrpCod"
" AND crs_grp_usr.UsrCod=crs_usr.UsrCod" " AND crs_grp_usr.UsrCod=crs_usr.UsrCod"
" AND crs_grp_usr.UsrCod<>%ld" " AND crs_grp_usr.UsrCod<>%ld"
" AND svy_grp.SvyCod=surveys.SvyCod" " AND svy_grp.SvyCod=surveys.SvyCod"
" AND surveys.Scope='%s' AND surveys.Cod=crs_usr.CrsCod" " AND surveys.Scope='%s' AND surveys.Cod=crs_usr.CrsCod"
" AND (surveys.Roles&(1<<crs_usr.Role))<>0)", " AND (surveys.Roles&(1<<crs_usr.Role))<>0)",
Cod, Cod,
Cod, Cod,
Sco_ScopeDB[Sco_SCOPE_CRS], Sco_ScopeDB[Sco_SCOPE_CRS],
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Cod, Cod,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
} }
if ((NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get users to be notified"))) // Users found if ((NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get users to be notified"))) // Users found
{ {
/***** Initialize structure with user's data *****/ /***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat); Usr_UsrDataConstructor (&UsrDat);
@ -1434,7 +1478,7 @@ void Ntf_StoreNotifyEventToOneUser (Ntf_NotifyEvent_t NotifyEvent,
struct UsrData *UsrDat, struct UsrData *UsrDat,
long Cod,Ntf_Status_t Status) long Cod,Ntf_Status_t Status)
{ {
char Query[512]; char *Query;
long InsCod; long InsCod;
long CtrCod; long CtrCod;
long DegCod; long DegCod;
@ -1475,15 +1519,16 @@ void Ntf_StoreNotifyEventToOneUser (Ntf_NotifyEvent_t NotifyEvent,
} }
/***** Store notify event *****/ /***** Store notify event *****/
sprintf (Query,"INSERT INTO notif" if (asprintf (&Query,"INSERT INTO notif"
" (NotifyEvent,ToUsrCod,FromUsrCod," " (NotifyEvent,ToUsrCod,FromUsrCod,"
"InsCod,CtrCod,DegCod,CrsCod,Cod,TimeNotif,Status)" "InsCod,CtrCod,DegCod,CrsCod,Cod,TimeNotif,Status)"
" VALUES" " VALUES"
" (%u,%ld,%ld," " (%u,%ld,%ld,"
"%ld,%ld,%ld,%ld,%ld,NOW(),%u)", "%ld,%ld,%ld,%ld,%ld,NOW(),%u)",
(unsigned) NotifyEvent,UsrDat->UsrCod,Gbl.Usrs.Me.UsrDat.UsrCod, (unsigned) NotifyEvent,UsrDat->UsrCod,Gbl.Usrs.Me.UsrDat.UsrCod,
InsCod,CtrCod,DegCod,CrsCod,Cod,(unsigned) Status); InsCod,CtrCod,DegCod,CrsCod,Cod,(unsigned) Status) < 0)
DB_QueryINSERT (Query,"can not create new notification event"); Lay_NotEnoughMemoryExit ();
DB_QueryINSERT_free (Query,"can not create new notification event");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1492,13 +1537,14 @@ void Ntf_StoreNotifyEventToOneUser (Ntf_NotifyEvent_t NotifyEvent,
static void Ntf_UpdateMyLastAccessToNotifications (void) static void Ntf_UpdateMyLastAccessToNotifications (void)
{ {
char Query[512]; char *Query;
/***** Reset to 0 my number of new received messages *****/ /***** Reset to 0 my number of new received messages *****/
sprintf (Query,"UPDATE usr_last SET LastAccNotif=NOW()" if (asprintf (&Query,"UPDATE usr_last SET LastAccNotif=NOW()"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
DB_QueryUPDATE (Query,"can not update last access to notifications"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update last access to notifications");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1507,7 +1553,7 @@ static void Ntf_UpdateMyLastAccessToNotifications (void)
void Ntf_SendPendingNotifByEMailToAllUsrs (void) void Ntf_SendPendingNotifByEMailToAllUsrs (void)
{ {
char Query[512]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRow,NumRows; unsigned long NumRow,NumRows;
@ -1519,14 +1565,15 @@ void Ntf_SendPendingNotifByEMailToAllUsrs (void)
/***** Get users who must be notified from database ******/ /***** 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)) // (Status & Ntf_STATUS_BIT_EMAIL) && !(Status & Ntf_STATUS_BIT_SENT) && !(Status & (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED))
sprintf (Query,"SELECT DISTINCT ToUsrCod FROM notif" if (asprintf (&Query,"SELECT DISTINCT ToUsrCod FROM notif"
" WHERE TimeNotif<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')" " WHERE TimeNotif<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')"
" AND (Status & %u)<>0 AND (Status & %u)=0 AND (Status & %u)=0", " AND (Status & %u)<>0 AND (Status & %u)=0 AND (Status & %u)=0",
Cfg_TIME_TO_SEND_PENDING_NOTIF, Cfg_TIME_TO_SEND_PENDING_NOTIF,
(unsigned) Ntf_STATUS_BIT_EMAIL, (unsigned) Ntf_STATUS_BIT_EMAIL,
(unsigned) Ntf_STATUS_BIT_SENT, (unsigned) Ntf_STATUS_BIT_SENT,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)); (unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)) < 0)
if ((NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get users who must be notified"))) // Events found Lay_NotEnoughMemoryExit ();
if ((NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get users who must be notified"))) // Events found
{ {
/***** Initialize structure with user's data *****/ /***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat); Usr_UsrDataConstructor (&UsrDat);
@ -1560,10 +1607,11 @@ void Ntf_SendPendingNotifByEMailToAllUsrs (void)
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
/***** Delete old notifications ******/ /***** Delete old notifications ******/
sprintf (Query,"DELETE LOW_PRIORITY FROM notif" if (asprintf (&Query,"DELETE LOW_PRIORITY FROM notif"
" WHERE TimeNotif<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')", " WHERE TimeNotif<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')",
Cfg_TIME_TO_DELETE_OLD_NOTIF); Cfg_TIME_TO_DELETE_OLD_NOTIF) < 0)
DB_QueryDELETE (Query,"can not remove old notifications"); Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove old notifications");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1582,7 +1630,7 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct UsrData *ToUsrDat,unsign
extern const char *Txt_TAB_Messages_NO_HTML[1 + Txt_NUM_LANGUAGES]; extern const char *Txt_TAB_Messages_NO_HTML[1 + Txt_NUM_LANGUAGES];
extern const char *Txt_Notifications_NO_HTML[1 + Txt_NUM_LANGUAGES]; extern const char *Txt_Notifications_NO_HTML[1 + Txt_NUM_LANGUAGES];
extern const char *Txt_If_you_no_longer_wish_to_receive_email_notifications_NO_HTML[1 + Txt_NUM_LANGUAGES]; extern const char *Txt_If_you_no_longer_wish_to_receive_email_notifications_NO_HTML[1 + Txt_NUM_LANGUAGES];
char Query[512]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRow; unsigned long NumRow;
@ -1609,13 +1657,16 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct UsrData *ToUsrDat,unsign
if (Mai_CheckIfUsrCanReceiveEmailNotif (ToUsrDat)) if (Mai_CheckIfUsrCanReceiveEmailNotif (ToUsrDat))
{ {
/***** Get pending notifications of this user from database ******/ /***** Get pending notifications of this user from database ******/
sprintf (Query,"SELECT NotifyEvent,FromUsrCod,InsCod,CtrCod,DegCod,CrsCod,Cod" if (asprintf (&Query,"SELECT NotifyEvent,FromUsrCod,InsCod,CtrCod,DegCod,CrsCod,Cod"
" FROM notif WHERE ToUsrCod=%ld" " FROM notif WHERE ToUsrCod=%ld"
" AND (Status & %u)<>0 AND (Status & %u)=0 AND (Status & %u)=0" " AND (Status & %u)<>0 AND (Status & %u)=0 AND (Status & %u)=0"
" ORDER BY TimeNotif,NotifyEvent", " ORDER BY TimeNotif,NotifyEvent",
ToUsrDat->UsrCod, ToUsrDat->UsrCod,
(unsigned) Ntf_STATUS_BIT_EMAIL,(unsigned) Ntf_STATUS_BIT_SENT,(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)); (unsigned) Ntf_STATUS_BIT_EMAIL,
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get pending notifications of a user"); (unsigned) Ntf_STATUS_BIT_SENT,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)) < 0)
Lay_NotEnoughMemoryExit ();
NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get pending notifications of a user");
if (NumRows) // Events found if (NumRows) // Events found
{ {
@ -1777,14 +1828,15 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct UsrData *ToUsrDat,unsign
} }
/***** Mark all the pending notifications of this user as 'sent' *****/ /***** Mark all the pending notifications of this user as 'sent' *****/
sprintf (Query,"UPDATE notif SET Status=(Status | %u)" if (asprintf (&Query,"UPDATE notif SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld" " WHERE ToUsrCod=%ld"
" AND (Status & %u)<>0 AND (Status & %u)=0 AND (Status & %u)=0", " AND (Status & %u)<>0 AND (Status & %u)=0 AND (Status & %u)=0",
(unsigned) Ntf_STATUS_BIT_SENT,ToUsrDat->UsrCod, (unsigned) Ntf_STATUS_BIT_SENT,ToUsrDat->UsrCod,
(unsigned) Ntf_STATUS_BIT_EMAIL, (unsigned) Ntf_STATUS_BIT_EMAIL,
(unsigned) Ntf_STATUS_BIT_SENT, (unsigned) Ntf_STATUS_BIT_SENT,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)); (unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)) < 0)
DB_QueryUPDATE (Query,"can not set pending notifications of a user as sent"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not set pending notifications of a user as sent");
} }
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
@ -1815,16 +1867,17 @@ static void Ntf_GetNumNotifSent (long DegCod,long CrsCod,
Ntf_NotifyEvent_t NotifyEvent, Ntf_NotifyEvent_t NotifyEvent,
unsigned *NumEvents,unsigned *NumMails) unsigned *NumEvents,unsigned *NumMails)
{ {
char Query[512]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned long NumRows;
/***** Get number of notifications sent by email from database *****/ /***** Get number of notifications sent by email from database *****/
sprintf (Query,"SELECT NumEvents,NumMails FROM sta_notif" if (asprintf (&Query,"SELECT NumEvents,NumMails FROM sta_notif"
" WHERE DegCod=%ld AND CrsCod=%ld AND NotifyEvent=%u", " WHERE DegCod=%ld AND CrsCod=%ld AND NotifyEvent=%u",
DegCod,CrsCod,(unsigned) NotifyEvent); DegCod,CrsCod,(unsigned) NotifyEvent) < 0)
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get number of notifications sent by email"); Lay_NotEnoughMemoryExit ();
NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get number of notifications sent by email");
/***** Get number of rows *****/ /***** Get number of rows *****/
if (NumRows) if (NumRows)
@ -1850,7 +1903,7 @@ static void Ntf_UpdateNumNotifSent (long DegCod,long CrsCod,
Ntf_NotifyEvent_t NotifyEvent, Ntf_NotifyEvent_t NotifyEvent,
unsigned NumEvents,unsigned NumMails) unsigned NumEvents,unsigned NumMails)
{ {
char Query[512]; char *Query;
unsigned CurrentNumEvents; unsigned CurrentNumEvents;
unsigned CurrentNumMails; unsigned CurrentNumMails;
@ -1858,14 +1911,15 @@ static void Ntf_UpdateNumNotifSent (long DegCod,long CrsCod,
Ntf_GetNumNotifSent (DegCod,CrsCod,NotifyEvent,&CurrentNumEvents,&CurrentNumMails); Ntf_GetNumNotifSent (DegCod,CrsCod,NotifyEvent,&CurrentNumEvents,&CurrentNumMails);
/***** Update number of users notified *****/ /***** Update number of users notified *****/
sprintf (Query,"REPLACE INTO sta_notif" if (asprintf (&Query,"REPLACE INTO sta_notif"
" (DegCod,CrsCod,NotifyEvent,NumEvents,NumMails)" " (DegCod,CrsCod,NotifyEvent,NumEvents,NumMails)"
" VALUES" " VALUES"
" (%ld,%ld,%u,%u,%u)", " (%ld,%ld,%u,%u,%u)",
DegCod,CrsCod,(unsigned) NotifyEvent, DegCod,CrsCod,(unsigned) NotifyEvent,
CurrentNumEvents + NumEvents, CurrentNumEvents + NumEvents,
CurrentNumMails + NumMails); CurrentNumMails + NumMails) < 0)
DB_QueryREPLACE (Query,"can not update the number of sent notifications"); Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not update the number of sent notifications");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1874,14 +1928,15 @@ static void Ntf_UpdateNumNotifSent (long DegCod,long CrsCod,
void Ntf_MarkAllNotifAsSeen (void) void Ntf_MarkAllNotifAsSeen (void)
{ {
char Query[256]; char *Query;
/***** Set all my notifications as seen *****/ /***** Set all my notifications as seen *****/
sprintf (Query,"UPDATE notif SET Status=(Status | %u)" if (asprintf (&Query,"UPDATE notif SET Status=(Status | %u)"
" WHERE ToUsrCod=%ld", " WHERE ToUsrCod=%ld",
(unsigned) Ntf_STATUS_BIT_READ, (unsigned) Ntf_STATUS_BIT_READ,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
DB_QueryUPDATE (Query,"can not set notification(s) as seen"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not set notification(s) as seen");
/***** Show my notifications again *****/ /***** Show my notifications again *****/
Ntf_ShowMyNotifications (); Ntf_ShowMyNotifications ();
@ -2002,19 +2057,20 @@ static void Ntf_GetParamsNotifyEvents (void)
void Ntf_ChangeNotifyEvents (void) void Ntf_ChangeNotifyEvents (void)
{ {
extern const char *Txt_Your_preferences_about_notifications_have_changed; extern const char *Txt_Your_preferences_about_notifications_have_changed;
char Query[512]; char *Query;
/***** Get param with whether notify me about events *****/ /***** Get param with whether notify me about events *****/
Ntf_GetParamsNotifyEvents (); Ntf_GetParamsNotifyEvents ();
/***** Store preferences about notify events *****/ /***** Store preferences about notify events *****/
sprintf (Query,"UPDATE usr_data" if (asprintf (&Query,"UPDATE usr_data"
" SET NotifNtfEvents=%u,EmailNtfEvents=%u" " SET NotifNtfEvents=%u,EmailNtfEvents=%u"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.Prefs.NotifNtfEvents, Gbl.Usrs.Me.UsrDat.Prefs.NotifNtfEvents,
Gbl.Usrs.Me.UsrDat.Prefs.EmailNtfEvents, Gbl.Usrs.Me.UsrDat.Prefs.EmailNtfEvents,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
DB_QueryUPDATE (Query,"can not update user's preferences"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update user's preferences");
/***** Show message *****/ /***** Show message *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_Your_preferences_about_notifications_have_changed); Ale_ShowAlert (Ale_SUCCESS,Txt_Your_preferences_about_notifications_have_changed);
@ -2075,14 +2131,15 @@ void Ntf_WriteNumberOfNewNtfs (void)
static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void) static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
{ {
char Query[512]; char *Query;
/***** Get number of places with a name from database *****/ /***** Get number of places with a name from database *****/
sprintf (Query,"SELECT COUNT(*) FROM notif" if (asprintf (&Query,"SELECT COUNT(*) FROM notif"
" WHERE ToUsrCod=%ld AND (Status & %u)=0", " WHERE ToUsrCod=%ld AND (Status & %u)=0",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)); (unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)) < 0)
return DB_QueryCOUNT (Query,"can not get number of unseen notifications"); Lay_NotEnoughMemoryExit ();
return DB_QueryCOUNT_free (Query,"can not get number of unseen notifications");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2091,16 +2148,17 @@ static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
static unsigned Ntf_GetNumberOfMyNewUnseenNtfs (void) static unsigned Ntf_GetNumberOfMyNewUnseenNtfs (void)
{ {
char Query[256]; char *Query;
/***** Get number of places with a name from database *****/ /***** Get number of places with a name from database *****/
sprintf (Query,"SELECT COUNT(*) FROM notif" if (asprintf (&Query,"SELECT COUNT(*) FROM notif"
" WHERE ToUsrCod=%ld AND (Status & %u)=0" " WHERE ToUsrCod=%ld AND (Status & %u)=0"
" AND TimeNotif>FROM_UNIXTIME(%ld)", " AND TimeNotif>FROM_UNIXTIME(%ld)",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED), (unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED),
Gbl.Usrs.Me.UsrLast.LastAccNotif); Gbl.Usrs.Me.UsrLast.LastAccNotif) < 0)
return DB_QueryCOUNT (Query,"can not get number of unseen notifications"); Lay_NotEnoughMemoryExit ();
return DB_QueryCOUNT_free (Query,"can not get number of unseen notifications");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2109,11 +2167,12 @@ static unsigned Ntf_GetNumberOfMyNewUnseenNtfs (void)
void Ntf_RemoveUsrNtfs (long ToUsrCod) void Ntf_RemoveUsrNtfs (long ToUsrCod)
{ {
char Query[256]; char *Query;
/***** Delete notifications of a user ******/ /***** Delete notifications of a user ******/
sprintf (Query,"DELETE LOW_PRIORITY FROM notif" if (asprintf (&Query,"DELETE LOW_PRIORITY FROM notif"
" WHERE ToUsrCod=%ld", " WHERE ToUsrCod=%ld",
ToUsrCod); ToUsrCod) < 0)
DB_QueryDELETE (Query,"can not remove notifications of a user"); Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove notifications of a user");
} }