swad-core/swad_notice.c

1089 lines
37 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_notice.c: notices (yellow notes)
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
2021-02-09 12:43:45 +01:00
Copyright (C) 1999-2021 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
2019-03-25 19:05:10 +01:00
#define _GNU_SOURCE // For asprintf
2014-12-01 23:55:08 +01:00
#include <linux/limits.h> // For PATH_MAX
2019-12-29 12:39:00 +01:00
#include <stddef.h> // For NULL
2019-03-25 19:05:10 +01:00
#include <stdio.h> // For sscanf, asprintf, etc.
#include <stdlib.h> // For free
2014-12-01 23:55:08 +01:00
#include <string.h>
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2014-12-01 23:55:08 +01:00
#include "swad_database.h"
2020-04-14 17:15:17 +02:00
#include "swad_figure.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
2019-10-23 20:07:56 +02:00
#include "swad_HTML.h"
2014-12-01 23:55:08 +01:00
#include "swad_notice.h"
#include "swad_notification.h"
#include "swad_parameter.h"
#include "swad_RSS.h"
2019-03-12 21:25:55 +01:00
#include "swad_timeline.h"
#include "swad_timeline_database.h"
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
#define Not_MAX_CHARS_ON_NOTICE 40 // Maximum number of characters in notices (when not expanded)
2019-11-22 01:04:03 +01:00
static const unsigned Not_ContainerWidth[Not_NUM_TYPES_LISTING] =
2014-12-01 23:55:08 +01:00
{
2019-11-22 01:04:03 +01:00
[Not_LIST_BRIEF_NOTICES] = 148 + 50,
[Not_LIST_FULL_NOTICES ] = 500 + 50,
2014-12-01 23:55:08 +01:00
};
2019-11-22 01:04:03 +01:00
static const unsigned Not_MaxCharsURLOnScreen[Not_NUM_TYPES_LISTING] =
2014-12-01 23:55:08 +01:00
{
2019-11-22 01:04:03 +01:00
[Not_LIST_BRIEF_NOTICES] = 15,
[Not_LIST_FULL_NOTICES ] = 50,
2014-12-01 23:55:08 +01:00
};
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2016-11-06 22:37:12 +01:00
static bool Not_CheckIfICanEditNotices (void);
2020-04-08 19:42:03 +02:00
static void Not_PutIconsListNotices (__attribute__((unused)) void *Args);
2016-03-21 15:10:00 +01:00
static void Not_PutIconToAddNewNotice (void);
2016-03-21 16:49:44 +01:00
static void Not_PutButtonToAddNewNotice (void);
2016-11-06 22:37:12 +01:00
static void Not_GetDataAndShowNotice (long NotCod);
2014-12-01 23:55:08 +01:00
static void Not_DrawANotice (Not_Listing_t TypeNoticesListing,
2019-03-24 23:17:32 +01:00
long NotCod,bool Highlight,
2015-10-26 14:49:42 +01:00
time_t TimeUTC,
2014-12-01 23:55:08 +01:00
const char *Content,
long UsrCod,
2016-11-06 22:37:12 +01:00
Not_Status_t Status);
2014-12-01 23:55:08 +01:00
static long Not_InsertNoticeInDB (const char *Content);
static void Not_UpdateNumUsrsNotifiedByEMailAboutNotice (long NotCod,unsigned NumUsrsToBeNotifiedByEMail);
2020-04-08 19:42:03 +02:00
static void Not_PutParams (void *NotCod);
2014-12-01 23:55:08 +01:00
static long Not_GetParamNotCod (void);
/*****************************************************************************/
/***************************** Write a new notice ****************************/
/*****************************************************************************/
void Not_ShowFormNotice (void)
{
2020-09-26 17:20:01 +02:00
extern const char *Hlp_COMMUNICATION_Notices;
2016-12-27 13:56:44 +01:00
extern const char *Txt_The_notice_will_appear_as_a_yellow_note_;
2014-12-01 23:55:08 +01:00
extern const char *Txt_New_notice;
extern const char *Txt_Create_notice;
2015-11-03 21:58:51 +01:00
/***** Help message *****/
2019-02-16 18:11:52 +01:00
Ale_ShowAlert (Ale_INFO,Txt_The_notice_will_appear_as_a_yellow_note_,
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.FullName);
2014-12-01 23:55:08 +01:00
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
Frm_BeginForm (ActRcvNot);
2015-03-24 17:47:26 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_New_notice,
NULL,NULL,
2020-09-26 17:20:01 +02:00
Hlp_COMMUNICATION_Notices,Box_NOT_CLOSABLE);
2015-03-24 17:47:26 +01:00
/***** Message body *****/
2019-10-31 17:42:05 +01:00
HTM_TEXTAREA_Begin ("name=\"Content\" cols=\"30\" rows=\"10\""
" autofocus=\"autofocus\" required=\"required\"");
HTM_TEXTAREA_End ();
2015-03-24 17:47:26 +01:00
2017-06-12 14:16:33 +02:00
/***** Send button and end box *****/
2019-11-25 23:18:08 +01:00
Box_BoxWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_notice);
2015-03-24 17:47:26 +01:00
2015-04-11 17:33:14 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-11-03 21:58:51 +01:00
/***** Show all notices *****/
2019-03-24 23:17:32 +01:00
Not_ShowNotices (Not_LIST_FULL_NOTICES,
-1L); // No notice highlighted
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******* Receive a new notice from a form and store it in database ***********/
/*****************************************************************************/
void Not_ReceiveNotice (void)
{
extern const char *Txt_Notice_created;
long NotCod;
unsigned NumUsrsToBeNotifiedByEMail;
2017-01-28 15:58:46 +01:00
char Content[Cns_MAX_BYTES_TEXT + 1];
2014-12-01 23:55:08 +01:00
/***** Get the text of the notice *****/
Par_GetParAndChangeFormat ("Content",Content,Cns_MAX_BYTES_TEXT,
Str_TO_RIGOROUS_HTML,true);
/***** Create a new notice in database *****/
NotCod = Not_InsertNoticeInDB (Content);
/***** Update RSS of current course *****/
2019-04-04 10:45:15 +02:00
RSS_UpdateRSSFileForACrs (&Gbl.Hierarchy.Crs);
2014-12-01 23:55:08 +01:00
/***** Write message of success *****/
2019-02-16 18:11:52 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Notice_created);
2014-12-01 23:55:08 +01:00
2016-11-16 23:19:52 +01:00
/***** Notify by email about the new notice *****/
2014-12-01 23:55:08 +01:00
if ((NumUsrsToBeNotifiedByEMail = Ntf_StoreNotifyEventsToAllUsrs (Ntf_EVENT_NOTICE,NotCod)))
Not_UpdateNumUsrsNotifiedByEMailAboutNotice (NotCod,NumUsrsToBeNotifiedByEMail);
2015-12-29 01:28:17 +01:00
2015-12-31 14:25:28 +01:00
/***** Create a new social note about the new notice *****/
Tml_Not_StoreAndPublishNote (TL_NOTE_NOTICE,NotCod);
2019-03-24 23:17:32 +01:00
/***** Set notice to be highlighted *****/
2019-04-04 10:45:15 +02:00
Gbl.Crs.Notices.HighlightNotCod = NotCod;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Insert a notice in the table of notices *****************/
/*****************************************************************************/
// Return the code of the new inserted notice
static long Not_InsertNoticeInDB (const char *Content)
{
/***** Insert notice in the database *****/
2018-11-03 01:45:36 +01:00
return
DB_QueryINSERTandReturnCode ("can not create notice",
"INSERT INTO not_notices"
2018-11-03 01:45:36 +01:00
" (CrsCod,UsrCod,CreatTime,Content,Status)"
" VALUES"
" (%ld,%ld,NOW(),'%s',%u)",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-11-03 01:45:36 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod,
Content,
(unsigned) Not_ACTIVE_NOTICE);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********** Update number of users notified in table of notices *************/
/*****************************************************************************/
static void Not_UpdateNumUsrsNotifiedByEMailAboutNotice (long NotCod,unsigned NumUsrsToBeNotifiedByEMail)
{
/***** Update number of users notified *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the number of notifications of a notice",
"UPDATE not_notices"
" SET NumNotif=%u"
" WHERE NotCod=%ld",
NumUsrsToBeNotifiedByEMail,
NotCod);
2014-12-01 23:55:08 +01:00
}
2015-11-03 22:13:01 +01:00
/*****************************************************************************/
/******************* List notices after removing one of them *****************/
/*****************************************************************************/
void Not_ListNoticesAfterRemoval (void)
{
extern const char *Txt_Notice_removed;
/***** Message of success *****/
2019-02-16 18:11:52 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Notice_removed);
2015-11-03 22:13:01 +01:00
/***** List remaining notices *****/
Not_ListFullNotices ();
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******************************* List notices ********************************/
/*****************************************************************************/
2015-11-03 22:13:01 +01:00
void Not_ListFullNotices (void)
2014-12-01 23:55:08 +01:00
{
2015-11-03 21:58:51 +01:00
/***** Show all notices *****/
2019-03-24 23:17:32 +01:00
Not_ShowNotices (Not_LIST_FULL_NOTICES,
2019-04-04 10:45:15 +02:00
Gbl.Crs.Notices.HighlightNotCod); // Highlight notice
2019-03-24 23:17:32 +01:00
}
/*****************************************************************************/
/************************* Get highlighted notice code ***********************/
/*****************************************************************************/
void Not_GetHighLightedNotCod (void)
{
/***** Get notice to be highlighted *****/
2019-04-04 10:45:15 +02:00
Gbl.Crs.Notices.HighlightNotCod = Not_GetParamNotCod ();
2016-11-06 22:37:12 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************** Mark as hidden a notice that was active *******************/
/*****************************************************************************/
void Not_HideActiveNotice (void)
{
long NotCod;
/***** Get the code of the notice to hide *****/
NotCod = Not_GetParamNotCod ();
/***** Set notice as hidden *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not hide notice",
"UPDATE not_notices"
" SET Status=%u"
" WHERE NotCod=%ld"
" AND CrsCod=%ld",
2018-11-03 12:16:40 +01:00
(unsigned) Not_OBSOLETE_NOTICE,
NotCod,
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
/***** Update RSS of current course *****/
2019-04-04 10:45:15 +02:00
RSS_UpdateRSSFileForACrs (&Gbl.Hierarchy.Crs);
2019-03-24 23:17:32 +01:00
/***** Set notice to be highlighted *****/
2019-04-04 10:45:15 +02:00
Gbl.Crs.Notices.HighlightNotCod = NotCod;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Mark as active a notice that was hidden ******************/
/*****************************************************************************/
void Not_RevealHiddenNotice (void)
{
long NotCod;
2015-11-01 20:21:59 +01:00
/***** Get the code of the notice to reveal *****/
2014-12-01 23:55:08 +01:00
NotCod = Not_GetParamNotCod ();
2015-11-01 20:21:59 +01:00
/***** Set notice as active *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not reveal notice",
"UPDATE not_notices"
" SET Status=%u"
" WHERE NotCod=%ld"
" AND CrsCod=%ld",
2018-11-03 12:16:40 +01:00
(unsigned) Not_ACTIVE_NOTICE,
NotCod,
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
/***** Update RSS of current course *****/
2019-04-04 10:45:15 +02:00
RSS_UpdateRSSFileForACrs (&Gbl.Hierarchy.Crs);
2019-03-24 23:17:32 +01:00
/***** Set notice to be highlighted *****/
2019-04-04 10:45:15 +02:00
Gbl.Crs.Notices.HighlightNotCod = NotCod;
2014-12-01 23:55:08 +01:00
}
2015-11-03 21:58:51 +01:00
/*****************************************************************************/
/********************* Request the removal of a notice ***********************/
/*****************************************************************************/
void Not_RequestRemNotice (void)
{
extern const char *Txt_Do_you_really_want_to_remove_the_following_notice;
extern const char *Txt_Remove;
2019-03-24 23:17:32 +01:00
long NotCod;
2015-11-03 21:58:51 +01:00
/***** Get the code of the notice to remove *****/
2019-03-24 23:17:32 +01:00
NotCod = Not_GetParamNotCod ();
2015-11-03 21:58:51 +01:00
2017-04-28 12:17:22 +02:00
/***** Show question and button to remove this notice *****/
/* Begin alert */
2017-05-11 23:45:46 +02:00
Ale_ShowAlertAndButton1 (Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_following_notice);
2016-11-14 10:30:33 +01:00
2017-04-28 12:17:22 +02:00
/* Show notice */
2019-03-24 23:17:32 +01:00
Not_GetDataAndShowNotice (NotCod);
2017-04-28 12:17:22 +02:00
/* End alert */
2020-03-26 02:54:30 +01:00
Ale_ShowAlertAndButton2 (ActRemNot,NULL,NULL,
2020-04-08 19:42:03 +02:00
Not_PutParams,&NotCod,
2017-06-11 19:02:40 +02:00
Btn_REMOVE_BUTTON,Txt_Remove);
2015-11-03 21:58:51 +01:00
/***** Show all notices *****/
2019-03-24 23:17:32 +01:00
Not_ShowNotices (Not_LIST_FULL_NOTICES,
NotCod); // Highlight notice to be removed
2015-11-03 21:58:51 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2015-11-01 20:21:59 +01:00
/******************************* Remove a notice *****************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2015-11-03 21:58:51 +01:00
void Not_RemoveNotice (void)
2014-12-01 23:55:08 +01:00
{
long NotCod;
2015-11-03 21:58:51 +01:00
/***** Get the code of the notice to remove *****/
2014-12-01 23:55:08 +01:00
NotCod = Not_GetParamNotCod ();
/***** Remove notice *****/
/* Copy notice to table of deleted notices */
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not remove notice",
"INSERT IGNORE INTO not_deleted"
2018-11-02 19:37:11 +01:00
" (NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif)"
" SELECT NotCod,"
"CrsCod,"
"UsrCod,"
"CreatTime,"
"Content,"
"NumNotif"
" FROM not_notices"
" WHERE NotCod=%ld"
" AND CrsCod=%ld",
NotCod,
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
/* Remove notice */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove notice",
"DELETE FROM not_notices"
" WHERE NotCod=%ld"
" AND CrsCod=%ld",
NotCod,
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
/***** Mark possible notifications as removed *****/
2016-01-04 01:56:28 +01:00
Ntf_MarkNotifAsRemoved (Ntf_EVENT_NOTICE,NotCod);
2014-12-01 23:55:08 +01:00
2016-01-03 19:30:59 +01:00
/***** Mark possible social note as unavailable *****/
Tml_DB_MarkNoteAsUnavailable (TL_NOTE_NOTICE,NotCod);
2016-01-03 19:30:59 +01:00
2014-12-01 23:55:08 +01:00
/***** Update RSS of current course *****/
2019-04-04 10:45:15 +02:00
RSS_UpdateRSSFileForACrs (&Gbl.Hierarchy.Crs);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************************** Show the notices ******************************/
/*****************************************************************************/
2019-03-24 23:17:32 +01:00
void Not_ShowNotices (Not_Listing_t TypeNoticesListing,long HighlightNotCod)
2014-12-01 23:55:08 +01:00
{
2020-09-26 17:20:01 +02:00
extern const char *Hlp_COMMUNICATION_Notices;
2016-03-21 15:10:00 +01:00
extern const char *Txt_Notices;
2015-11-01 18:54:10 +01:00
extern const char *Txt_No_notices;
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2019-11-08 01:10:32 +01:00
char StrWidth[Cns_MAX_DECIMAL_DIGITS_UINT + 2 + 1];
2017-01-17 03:10:43 +01:00
char PathRelRSSFile[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
long NotCod;
unsigned NumNot;
unsigned NumNotices = 0; // Initialized to avoid warning
2017-01-17 03:10:43 +01:00
char Content[Cns_MAX_BYTES_TEXT + 1];
2015-10-26 14:49:42 +01:00
time_t TimeUTC;
2014-12-01 23:55:08 +01:00
long UsrCod;
unsigned UnsignedNum;
2015-11-01 20:21:59 +01:00
Not_Status_t Status;
2019-10-28 20:38:29 +01:00
char RSSLink[Cns_MAX_BYTES_WWW + 1];
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/***** Trivial check *****/
2021-02-11 22:57:09 +01:00
if (Gbl.Hierarchy.Level != Hie_Lvl_CRS) // No course selected
2019-04-03 20:57:04 +02:00
return;
/***** Get notices from database *****/
switch (TypeNoticesListing)
2014-12-01 23:55:08 +01:00
{
2019-04-03 20:57:04 +02:00
case Not_LIST_BRIEF_NOTICES:
NumNotices = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get notices from database",
"SELECT NotCod," // row[0]
"UNIX_TIMESTAMP(CreatTime) AS F," // row[1]
"UsrCod," // row[2]
"Content," // row[3]
"Status" // row[4]
" FROM not_notices"
" WHERE CrsCod=%ld"
" AND Status=%u"
" ORDER BY CreatTime DESC",
Gbl.Hierarchy.Crs.CrsCod,
(unsigned) Not_ACTIVE_NOTICE);
2019-04-03 20:57:04 +02:00
break;
case Not_LIST_FULL_NOTICES:
NumNotices = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get notices from database",
"SELECT NotCod," // row[0]
"UNIX_TIMESTAMP(CreatTime) AS F," // row[1]
"UsrCod," // row[2]
"Content," // row[3]
"Status" // row[4]
" FROM not_notices"
" WHERE CrsCod=%ld"
" ORDER BY CreatTime DESC",
Gbl.Hierarchy.Crs.CrsCod);
2019-04-03 20:57:04 +02:00
break;
}
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
if (TypeNoticesListing == Not_LIST_FULL_NOTICES)
{
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
snprintf (StrWidth,sizeof (StrWidth),"%upx",
2019-04-03 20:57:04 +02:00
Not_ContainerWidth[Not_LIST_FULL_NOTICES] + 50);
2020-03-26 02:54:30 +01:00
Box_BoxBegin (StrWidth,Txt_Notices,
2020-04-08 19:42:03 +02:00
Not_PutIconsListNotices,NULL,
2020-09-26 17:20:01 +02:00
Hlp_COMMUNICATION_Notices,Box_NOT_CLOSABLE);
2019-04-03 20:57:04 +02:00
if (!NumNotices)
Ale_ShowAlert (Ale_INFO,Txt_No_notices);
}
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/***** Show the notices *****/
for (NumNot = 0;
NumNot < NumNotices;
NumNot++)
{
row = mysql_fetch_row (mysql_res);
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/* Get notice code (row[0]) */
if (sscanf (row[0],"%ld",&NotCod) != 1)
Lay_WrongNoticeExit ();
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/* Get creation time (row[1] holds the UTC date-time) */
TimeUTC = Dat_GetUNIXTimeFromStr (row[1]);
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/* Get user code (row[2]) */
UsrCod = Str_ConvertStrCodToLongCod (row[2]);
/* Get the content (row[3]) and insert links */
Str_Copy (Content,row[3],sizeof (Content) - 1);
2020-05-25 17:53:13 +02:00
/* Inserting links is incompatible with limiting the length
==> don't insert links when limiting length */
switch (TypeNoticesListing)
{
case Not_LIST_BRIEF_NOTICES:
Str_LimitLengthHTMLStr (Content,Not_MAX_CHARS_ON_NOTICE);
break;
case Not_LIST_FULL_NOTICES:
Str_InsertLinks (Content,Cns_MAX_BYTES_TEXT,
Not_MaxCharsURLOnScreen[TypeNoticesListing]);
break;
}
2019-04-03 20:57:04 +02:00
/* Get status of the notice (row[4]) */
Status = Not_OBSOLETE_NOTICE;
if (sscanf (row[4],"%u",&UnsignedNum) == 1)
if (UnsignedNum < Not_NUM_STATUS)
Status = (Not_Status_t) UnsignedNum;
/* Draw the notice */
Not_DrawANotice (TypeNoticesListing,
NotCod,
(NotCod == HighlightNotCod), // Highlighted?
TimeUTC,Content,UsrCod,Status);
2014-12-01 23:55:08 +01:00
}
2019-04-03 20:57:04 +02:00
switch (TypeNoticesListing)
{
case Not_LIST_BRIEF_NOTICES:
/***** Link to RSS file *****/
/* Create RSS file if not exists */
snprintf (PathRelRSSFile,sizeof (PathRelRSSFile),"%s/%ld/%s/%s",
2019-04-03 20:57:04 +02:00
Cfg_PATH_CRS_PUBLIC,
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,Cfg_RSS_FOLDER,Cfg_RSS_FILE);
2019-04-03 20:57:04 +02:00
if (!Fil_CheckIfPathExists (PathRelRSSFile))
2019-04-04 10:45:15 +02:00
RSS_UpdateRSSFileForACrs (&Gbl.Hierarchy.Crs);
2019-04-03 20:57:04 +02:00
/* Put a link to the RSS file */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"CM\"");
2019-10-28 20:38:29 +01:00
RSS_BuildRSSLink (RSSLink,Gbl.Hierarchy.Crs.CrsCod);
HTM_A_Begin ("href=\"%s\" target=\"_blank\"",RSSLink);
2019-10-29 21:41:54 +01:00
Ico_PutIcon ("rss-square.svg","RSS","ICO16x16");
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-04-03 20:57:04 +02:00
break;
case Not_LIST_FULL_NOTICES:
/***** Button to add new notice *****/
if (Not_CheckIfICanEditNotices ())
Not_PutButtonToAddNewNotice ();
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2019-04-03 20:57:04 +02:00
break;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Mark possible notification as seen *****/
Ntf_MarkNotifAsSeen (Ntf_EVENT_NOTICE,
2019-04-04 10:45:15 +02:00
-1L,Gbl.Hierarchy.Crs.CrsCod,
2019-04-03 20:57:04 +02:00
Gbl.Usrs.Me.UsrDat.UsrCod);
2014-12-01 23:55:08 +01:00
}
2016-11-06 23:46:29 +01:00
/*****************************************************************************/
/*********************** Check if I can edit notices *************************/
/*****************************************************************************/
static bool Not_CheckIfICanEditNotices (void)
{
2017-06-04 18:18:54 +02:00
return (bool) (Gbl.Usrs.Me.Role.Logged == Rol_TCH ||
Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM);
2016-11-06 23:46:29 +01:00
}
2016-11-06 15:47:37 +01:00
/*****************************************************************************/
2016-11-06 21:19:25 +01:00
/****************** Put contextual icons in list of notices ******************/
2016-11-06 15:47:37 +01:00
/*****************************************************************************/
2020-04-08 19:42:03 +02:00
static void Not_PutIconsListNotices (__attribute__((unused)) void *Args)
2016-11-06 15:47:37 +01:00
{
2020-04-08 19:42:03 +02:00
/***** Put icon to add a new notice *****/
if (Not_CheckIfICanEditNotices ())
Not_PutIconToAddNewNotice ();
2016-11-06 15:47:37 +01:00
2020-04-08 19:42:03 +02:00
/***** Put icon to show a figure *****/
Fig_PutIconToShowFigure (Fig_NOTICES);
2016-11-06 15:47:37 +01:00
}
2016-03-21 15:10:00 +01:00
/*****************************************************************************/
/*********************** Put icon to add a new notice ************************/
/*****************************************************************************/
static void Not_PutIconToAddNewNotice (void)
{
extern const char *Txt_New_notice;
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToAdd (ActWriNot,NULL,
NULL,NULL,
2019-01-10 15:26:33 +01:00
Txt_New_notice);
2016-03-21 15:10:00 +01:00
}
2016-03-21 16:49:44 +01:00
/*****************************************************************************/
/********************** Put button to add a new notice ***********************/
/*****************************************************************************/
static void Not_PutButtonToAddNewNotice (void)
{
extern const char *Txt_New_notice;
Frm_BeginForm (ActWriNot);
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButton (Txt_New_notice);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-03-21 16:49:44 +01:00
}
2015-11-03 21:58:51 +01:00
/*****************************************************************************/
/******************** Get data of a notice and show it ***********************/
/*****************************************************************************/
2016-11-06 22:37:12 +01:00
static void Not_GetDataAndShowNotice (long NotCod)
2015-11-03 21:58:51 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2017-01-17 03:10:43 +01:00
char Content[Cns_MAX_BYTES_TEXT + 1];
2015-11-03 21:58:51 +01:00
time_t TimeUTC;
long UsrCod;
unsigned UnsignedNum;
Not_Status_t Status;
/***** Get notice data from database *****/
2018-11-01 13:03:25 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get notice from database",
"SELECT UNIX_TIMESTAMP(CreatTime) AS F," // row[0]
"UsrCod," // row[1]
"Content," // row[2]
"Status" // row[3]
" FROM not_notices"
" WHERE NotCod=%ld"
" AND CrsCod=%ld",
NotCod,
Gbl.Hierarchy.Crs.CrsCod))
2015-11-03 21:58:51 +01:00
{
row = mysql_fetch_row (mysql_res);
/* Get creation time (row[0] holds the UTC date-time) */
TimeUTC = Dat_GetUNIXTimeFromStr (row[0]);
/* Get user code (row[1]) */
UsrCod = Str_ConvertStrCodToLongCod (row[1]);
/* Get the content (row[2]) and insert links*/
Str_Copy (Content,row[2],sizeof (Content) - 1);
2016-01-25 00:19:21 +01:00
Str_InsertLinks (Content,Cns_MAX_BYTES_TEXT,
2017-01-15 18:02:52 +01:00
Not_MaxCharsURLOnScreen[Not_LIST_FULL_NOTICES]);
2015-11-03 21:58:51 +01:00
/* Get status of the notice (row[3]) */
Status = Not_OBSOLETE_NOTICE;
if (sscanf (row[3],"%u",&UnsignedNum) == 1)
if (UnsignedNum < Not_NUM_STATUS)
Status = (Not_Status_t) UnsignedNum;
/***** Draw the notice *****/
Not_DrawANotice (Not_LIST_FULL_NOTICES,
NotCod,
2019-03-24 23:17:32 +01:00
false, // Not highlighted
2016-11-06 22:37:12 +01:00
TimeUTC,Content,UsrCod,Status);
2015-11-03 21:58:51 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************* Draw a notice as a yellow note ************************/
/*****************************************************************************/
static void Not_DrawANotice (Not_Listing_t TypeNoticesListing,
2019-03-24 23:17:32 +01:00
long NotCod,bool Highlight,
2015-10-26 14:49:42 +01:00
time_t TimeUTC,
2014-12-01 23:55:08 +01:00
const char *Content,
long UsrCod,
2016-11-06 22:37:12 +01:00
Not_Status_t Status)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_See_full_notice;
2015-11-01 14:11:46 +01:00
static const char *ContainerClass[Not_NUM_STATUS] =
{
2019-12-13 00:36:01 +01:00
[Not_ACTIVE_NOTICE ] = "NOTICE_CONT_ACTIVE",
[Not_OBSOLETE_NOTICE] = "NOTICE_CONT_OBSOLETE",
2015-11-01 14:11:46 +01:00
};
2019-11-18 17:59:02 +01:00
static const char *ContainerWidthClass[Not_NUM_TYPES_LISTING] =
2019-10-15 15:23:38 +02:00
{
2019-12-13 00:36:01 +01:00
[Not_LIST_BRIEF_NOTICES] = "NOTICE_CONT_NARROW",
[Not_LIST_FULL_NOTICES ] = "NOTICE_CONT_WIDE",
2019-10-15 15:23:38 +02:00
};
2015-11-01 14:11:46 +01:00
static const char *DateClass[Not_NUM_STATUS] =
{
2019-11-21 01:27:17 +01:00
[Not_ACTIVE_NOTICE ] = "NOTICE_DATE_ACTIVE",
[Not_OBSOLETE_NOTICE] = "NOTICE_DATE_OBSOLETE",
2015-11-01 14:11:46 +01:00
};
static const char *TextClass[Not_NUM_STATUS] =
{
2019-11-21 01:27:17 +01:00
[Not_ACTIVE_NOTICE ] = "NOTICE_TEXT_ACTIVE",
[Not_OBSOLETE_NOTICE] = "NOTICE_TEXT_OBSOLETE",
2015-11-01 14:11:46 +01:00
};
static const char *AuthorClass[Not_NUM_STATUS] =
{
2019-11-21 01:27:17 +01:00
[Not_ACTIVE_NOTICE ] = "NOTICE_AUTHOR_ACTIVE",
[Not_OBSOLETE_NOTICE] = "NOTICE_AUTHOR_OBSOLETE",
2015-11-01 14:11:46 +01:00
};
2015-10-26 14:49:42 +01:00
static unsigned UniqueId = 0;
2019-11-01 22:53:39 +01:00
char *Id;
2014-12-01 23:55:08 +01:00
struct UsrData UsrDat;
2019-03-25 19:05:10 +01:00
char *Anchor = NULL;
2014-12-01 23:55:08 +01:00
2019-03-24 23:17:32 +01:00
/***** Build anchor string *****/
2019-04-20 21:11:44 +02:00
Frm_SetAnchorStr (NotCod,&Anchor);
2019-03-24 23:17:32 +01:00
2019-10-26 01:56:36 +02:00
/***** Begin article for this notice *****/
2019-03-24 23:17:32 +01:00
if (TypeNoticesListing == Not_LIST_FULL_NOTICES)
{
2019-10-26 01:56:36 +02:00
HTM_ARTICLE_Begin (Anchor);
2019-03-24 23:17:32 +01:00
if (Highlight)
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"NOTICE_HIGHLIGHT\"");
2019-03-24 23:17:32 +01:00
}
2016-12-11 20:28:58 +01:00
2014-12-01 23:55:08 +01:00
/***** Start yellow note *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"%s %s\"",
ContainerClass[Status],ContainerWidthClass[TypeNoticesListing]);
2014-12-01 23:55:08 +01:00
/***** Write the date in the top part of the yellow note *****/
/* Write symbol to indicate if notice is obsolete or active */
if (TypeNoticesListing == Not_LIST_FULL_NOTICES)
2016-11-06 22:37:12 +01:00
if (Not_CheckIfICanEditNotices ())
2015-11-01 14:11:46 +01:00
{
2016-12-11 20:28:58 +01:00
/***** Put form to remove announcement *****/
2020-10-13 22:34:31 +02:00
Ico_PutContextualIconToRemove (ActReqRemNot,NULL,
2020-04-08 19:42:03 +02:00
Not_PutParams,&NotCod);
2016-12-11 20:28:58 +01:00
/***** Put form to change the status of the notice *****/
2015-11-01 20:21:59 +01:00
switch (Status)
2014-12-01 23:55:08 +01:00
{
case Not_ACTIVE_NOTICE:
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToHide (ActHidNot,NULL,
2020-04-08 19:42:03 +02:00
Not_PutParams,&NotCod);
2014-12-01 23:55:08 +01:00
break;
case Not_OBSOLETE_NOTICE:
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToUnhide (ActRevNot,NULL,
2020-04-08 19:42:03 +02:00
Not_PutParams,&NotCod);
2014-12-01 23:55:08 +01:00
break;
}
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-11-01 14:11:46 +01:00
}
2014-12-01 23:55:08 +01:00
2015-11-01 14:11:46 +01:00
/* Write the date */
2015-10-26 14:49:42 +01:00
UniqueId++;
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"%s\"",DateClass[Status]);
2014-12-01 23:55:08 +01:00
if (TypeNoticesListing == Not_LIST_BRIEF_NOTICES)
{
/* Form to view full notice */
2019-03-24 23:17:32 +01:00
Frm_StartFormAnchor (ActSeeOneNot,Anchor);
2014-12-01 23:55:08 +01:00
Not_PutHiddenParamNotCod (NotCod);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (Txt_See_full_notice,"BT_LINK RT",NULL);
2014-12-01 23:55:08 +01:00
}
2019-11-01 22:53:39 +01:00
if (asprintf (&Id,"not_date_%u",UniqueId) < 0)
Lay_NotEnoughMemoryExit ();
2019-11-07 10:24:00 +01:00
HTM_SPAN_Begin ("id=\"%s\"",Id);
HTM_SPAN_End ();
2014-12-01 23:55:08 +01:00
if (TypeNoticesListing == Not_LIST_BRIEF_NOTICES)
2015-03-13 00:16:02 +01:00
{
2019-11-18 17:59:02 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-13 00:16:02 +01:00
}
2019-11-01 23:35:55 +01:00
Dat_WriteLocalDateHMSFromUTC (Id,TimeUTC,
2019-11-02 12:10:58 +01:00
Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK,
2019-11-02 11:45:41 +01:00
true,true,false,0x6);
2019-11-06 19:45:20 +01:00
free (Id);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
/***** Write the content of the notice *****/
if (TypeNoticesListing == Not_LIST_BRIEF_NOTICES)
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"NOTICE_TEXT_BRIEF\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Content);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2015-11-01 21:19:33 +01:00
2016-12-11 20:28:58 +01:00
/* Put form to view full notice */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"CM\"");
2020-03-26 02:54:30 +01:00
Lay_PutContextualLinkOnlyIcon (ActSeeOneNot,Anchor,
2020-04-08 19:42:03 +02:00
Not_PutParams,&NotCod,
2019-01-12 03:00:59 +01:00
"ellipsis-h.svg",
Txt_See_full_notice);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
}
2015-11-01 21:19:33 +01:00
else
2019-10-23 20:07:56 +02:00
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"%s\"",TextClass[Status]);
2019-11-10 12:36:37 +01:00
HTM_Txt (Content);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
}
2014-12-01 23:55:08 +01:00
/***** Write the author *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"NOTICE_AUTHOR %s\"", // Limited width
AuthorClass[Status]);
2014-12-01 23:55:08 +01:00
Usr_UsrDataConstructor (&UsrDat);
UsrDat.UsrCod = UsrCod;
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat, // Get author's data from database
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CURRENT_CRS))
2017-03-05 15:12:48 +01:00
Usr_WriteFirstNameBRSurnames (&UsrDat);
2014-12-01 23:55:08 +01:00
Usr_UsrDataDestructor (&UsrDat);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
2015-12-30 12:40:13 +01:00
/***** End yellow note *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-03-24 23:17:32 +01:00
/***** End article for this notice *****/
if (TypeNoticesListing == Not_LIST_FULL_NOTICES)
{
if (Highlight)
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-26 01:56:36 +02:00
HTM_ARTICLE_End ();
2019-03-24 23:17:32 +01:00
}
2019-03-25 19:05:10 +01:00
/***** Free anchor string *****/
2019-04-20 21:11:44 +02:00
Frm_FreeAnchorStr (Anchor);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2015-12-29 01:28:17 +01:00
/******************* Get summary and content for a notice ********************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-03-08 14:12:33 +01:00
void Not_GetSummaryAndContentNotice (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
2017-03-06 13:01:16 +01:00
char **ContentStr,
long NotCod,bool GetContent)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2017-01-15 22:58:26 +01:00
size_t Length;
2014-12-01 23:55:08 +01:00
SummaryStr[0] = '\0'; // Return nothing on error
/***** Get subject of message from database *****/
2018-11-01 13:03:25 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get content of notice",
"SELECT Content" // row[0]
" FROM not_notices"
" WHERE NotCod=%ld",
2018-11-01 13:03:25 +01:00
NotCod) == 1) // Result should have a unique row
2018-10-24 00:18:36 +02:00
{
/***** Get sumary / content *****/
row = mysql_fetch_row (mysql_res);
/***** Copy summary *****/
// TODO: Do only direct copy when a Subject of type VARCHAR(255) is available
if (strlen (row[0]) > Ntf_MAX_BYTES_SUMMARY)
{
2020-05-25 17:53:13 +02:00
/* Inserting links is incompatible with limiting the length
==> don't insert links */
2018-10-24 00:18:36 +02:00
strncpy (SummaryStr,row[0],
Ntf_MAX_BYTES_SUMMARY);
SummaryStr[Ntf_MAX_BYTES_SUMMARY] = '\0';
}
else
Str_Copy (SummaryStr,row[0],Ntf_MAX_BYTES_SUMMARY);
2018-10-24 00:18:36 +02:00
/***** Copy content *****/
if (GetContent)
{
Length = strlen (row[0]);
if ((*ContentStr = malloc (Length + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
Str_Copy (*ContentStr,row[0],Length);
2018-10-24 00:18:36 +02:00
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************************** Get number of notices ***************************/
/*****************************************************************************/
// Returns the number of (active or obsolete) notices
// sent from this location (all the platform, current degree or current course)
2021-02-11 22:57:09 +01:00
unsigned Not_GetNumNotices (Hie_Lvl_Level_t Scope,Not_Status_t Status,unsigned *NumNotif)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumNotices;
/***** Get number of notices from database *****/
switch (Scope)
{
2021-02-11 22:57:09 +01:00
case Hie_Lvl_SYS:
2018-11-01 13:03:25 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of notices",
"SELECT COUNT(*)," // row[0]
"SUM(NumNotif)" // row[1]
" FROM not_notices"
2018-11-01 13:03:25 +01:00
" WHERE Status=%u",
Status);
2014-12-01 23:55:08 +01:00
break;
2021-02-11 22:57:09 +01:00
case Hie_Lvl_CTY:
2018-11-01 13:03:25 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of notices",
"SELECT COUNT(*)," // row[0]
"SUM(not_notices.NumNotif)" // row[1]
" FROM ins_instits,"
"ctr_centers,"
"deg_degrees,"
"crs_courses,"
"not_notices"
" WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=not_notices.CrsCod"
" AND not_notices.Status=%u",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod,
2018-11-01 13:03:25 +01:00
Status);
2015-03-09 10:40:31 +01:00
break;
2021-02-11 22:57:09 +01:00
case Hie_Lvl_INS:
2018-11-01 13:03:25 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of notices",
"SELECT COUNT(*)," // row[0]
"SUM(not_notices.NumNotif)" // row[1]
" FROM ctr_centers,"
"deg_degrees,"
"crs_courses,"
"not_notices"
" WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=not_notices.CrsCod"
" AND not_notices.Status=%u",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod,
2018-11-01 13:03:25 +01:00
Status);
2014-12-01 23:55:08 +01:00
break;
2021-02-11 22:57:09 +01:00
case Hie_Lvl_CTR:
2018-11-01 13:03:25 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of notices",
"SELECT COUNT(*)," // row[0]
"SUM(not_notices.NumNotif)" // row[1]
" FROM deg_degrees,"
"crs_courses,"
"not_notices"
" WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=not_notices.CrsCod"
" AND not_notices.Status=%u",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod,
2018-11-01 13:03:25 +01:00
Status);
2014-12-01 23:55:08 +01:00
break;
2021-02-11 22:57:09 +01:00
case Hie_Lvl_DEG:
2018-11-01 13:03:25 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of notices",
"SELECT COUNT(*)," // row[0]
"SUM(not_notices.NumNotif)" // row[1]
" FROM crs_courses,"
"not_notices"
" WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=not_notices.CrsCod"
" AND not_notices.Status=%u",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod,
2018-11-01 13:03:25 +01:00
Status);
2014-12-01 23:55:08 +01:00
break;
2021-02-11 22:57:09 +01:00
case Hie_Lvl_CRS:
2018-11-01 13:03:25 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of notices",
"SELECT COUNT(*)," // row[0]
"SUM(NumNotif)" // row[1]
" FROM not_notices"
2018-11-01 13:03:25 +01:00
" WHERE CrsCod=%ld"
" AND Status=%u",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-11-01 13:03:25 +01:00
Status);
2014-12-01 23:55:08 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2014-12-01 23:55:08 +01:00
break;
}
/***** Get number of notices *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumNotices) != 1)
Lay_ShowErrorAndExit ("Error when getting number of notices.");
2016-11-16 23:19:52 +01:00
/***** Get number of notifications by email *****/
2014-12-01 23:55:08 +01:00
if (row[1])
{
if (sscanf (row[1],"%u",NumNotif) != 1)
Lay_ShowErrorAndExit ("Error when getting number of notifications of notices.");
}
else
*NumNotif = 0;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumNotices;
}
/*****************************************************************************/
/************************ Get number of deleted notices **********************/
/*****************************************************************************/
// Returns the number of deleted notices
// sent from this location (all the platform, current degree or current course)
2021-02-11 22:57:09 +01:00
unsigned Not_GetNumNoticesDeleted (Hie_Lvl_Level_t Scope,unsigned *NumNotif)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumNotices;
/***** Get number of notices from database *****/
switch (Scope)
{
2021-02-11 22:57:09 +01:00
case Hie_Lvl_SYS:
2018-11-01 13:03:25 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of deleted notices",
"SELECT COUNT(*)," // row[0]
"SUM(NumNotif)" // row[1]
" FROM not_deleted");
2014-12-01 23:55:08 +01:00
break;
2021-02-11 22:57:09 +01:00
case Hie_Lvl_CTY:
2018-11-01 13:03:25 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of deleted notices",
"SELECT COUNT(*)," // row[0]
"SUM(not_deleted.NumNotif)" // row[1]
" FROM ins_instits,"
"ctr_centers,"
"deg_degrees,"
"crs_courses,"
"not_deleted"
" WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=not_deleted.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod);
2015-03-09 10:40:31 +01:00
break;
2021-02-11 22:57:09 +01:00
case Hie_Lvl_INS:
2018-11-01 13:03:25 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of deleted notices",
"SELECT COUNT(*)," // row[0]
"SUM(not_deleted.NumNotif)" // row[1]
" FROM ctr_centers,"
"deg_degrees,"
"crs_courses,"
"not_deleted"
" WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=not_deleted.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod);
2014-12-01 23:55:08 +01:00
break;
2021-02-11 22:57:09 +01:00
case Hie_Lvl_CTR:
2018-11-01 13:03:25 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of deleted notices",
"SELECT COUNT(*)," // row[0]
"SUM(not_deleted.NumNotif)" // row[1]
" FROM deg_degrees,"
"crs_courses,"
"not_deleted"
" WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=not_deleted.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod);
2014-12-01 23:55:08 +01:00
break;
2021-02-11 22:57:09 +01:00
case Hie_Lvl_DEG:
2018-11-01 13:03:25 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of deleted notices",
"SELECT COUNT(*)," // row[0]
"SUM(not_deleted.NumNotif)" // row[1]
" FROM crs_courses,"
"not_deleted"
" WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=not_deleted.CrsCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod);
2014-12-01 23:55:08 +01:00
break;
2021-02-11 22:57:09 +01:00
case Hie_Lvl_CRS:
2018-11-01 13:03:25 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of deleted notices",
"SELECT COUNT(*)," // row[0]
"SUM(NumNotif)" // row[1]
" FROM not_deleted"
2018-11-01 13:03:25 +01:00
" WHERE CrsCod=%ld",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2014-12-01 23:55:08 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2014-12-01 23:55:08 +01:00
break;
}
/***** Get number of notices *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumNotices) != 1)
Lay_ShowErrorAndExit ("Error when getting number of deleted notices.");
2016-11-16 23:19:52 +01:00
/***** Get number of notifications by email *****/
2014-12-01 23:55:08 +01:00
if (row[1])
{
if (sscanf (row[1],"%u",NumNotif) != 1)
Lay_ShowErrorAndExit ("Error when getting number of notifications of deleted notices.");
}
else
*NumNotif = 0;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumNotices;
}
/*****************************************************************************/
/*************** Put parameter with the code of a notice *********************/
/*****************************************************************************/
2020-04-08 19:42:03 +02:00
static void Not_PutParams (void *NotCod)
2016-12-11 20:28:58 +01:00
{
2020-04-08 19:42:03 +02:00
if (NotCod)
Not_PutHiddenParamNotCod (*((long *) NotCod));
2016-12-11 20:28:58 +01:00
}
/*****************************************************************************/
/*************** Put parameter with the code of a notice *********************/
/*****************************************************************************/
2015-12-29 13:18:25 +01:00
void Not_PutHiddenParamNotCod (long NotCod)
2014-12-01 23:55:08 +01:00
{
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamLong (NULL,"NotCod",NotCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Get parameter with the code of a notice *********************/
/*****************************************************************************/
static long Not_GetParamNotCod (void)
{
2017-01-28 20:32:50 +01:00
/***** Get notice code *****/
2019-03-24 23:17:32 +01:00
return Par_GetParToLong ("NotCod");
2014-12-01 23:55:08 +01:00
}