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.
|
2017-01-13 01:51:23 +01:00
|
|
|
|
Copyright (C) 1999-2017 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 ***********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <linux/limits.h> // For PATH_MAX
|
|
|
|
|
#include <linux/stddef.h> // For NULL
|
|
|
|
|
#include <stdlib.h> // For exit, system, malloc, calloc, free, etc.
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "swad_database.h"
|
|
|
|
|
#include "swad_global.h"
|
|
|
|
|
#include "swad_notice.h"
|
|
|
|
|
#include "swad_notification.h"
|
|
|
|
|
#include "swad_parameter.h"
|
|
|
|
|
#include "swad_RSS.h"
|
2015-12-29 01:28:17 +01:00
|
|
|
|
#include "swad_social.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)
|
|
|
|
|
|
|
|
|
|
const unsigned Not_ContainerWidth[Not_NUM_TYPES_LISTING] =
|
|
|
|
|
{
|
2015-11-27 22:58:11 +01:00
|
|
|
|
148, // Not_LIST_BRIEF_NOTICES
|
2015-09-28 18:28:29 +02:00
|
|
|
|
500, // Not_LIST_FULL_NOTICES
|
2014-12-01 23:55:08 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const unsigned Not_MaxCharsURLOnScreen[Not_NUM_TYPES_LISTING] =
|
|
|
|
|
{
|
|
|
|
|
15, // Not_LIST_BRIEF_NOTICES
|
|
|
|
|
50, // Not_LIST_FULL_NOTICES
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private prototypes ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-11-06 22:37:12 +01:00
|
|
|
|
static bool Not_CheckIfICanEditNotices (void);
|
2016-11-06 23:46:29 +01:00
|
|
|
|
static void Not_PutIconsListNotices (void);
|
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,
|
|
|
|
|
long NotCod,
|
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);
|
2016-12-11 20:28:58 +01:00
|
|
|
|
static void Not_PutParams (void);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
static long Not_GetParamNotCod (void);
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Write a new notice ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Not_ShowFormNotice (void)
|
|
|
|
|
{
|
2016-11-13 21:37:16 +01:00
|
|
|
|
extern const char *Hlp_MESSAGES_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 *****/
|
2016-12-27 13:56:44 +01:00
|
|
|
|
sprintf (Gbl.Message,Txt_The_notice_will_appear_as_a_yellow_note_,
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Gbl.CurrentCrs.Crs.FullName);
|
|
|
|
|
Lay_ShowAlert (Lay_INFO,Gbl.Message);
|
|
|
|
|
|
2015-04-11 17:33:14 +02:00
|
|
|
|
/***** Start form *****/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Act_FormStart (ActRcvNot);
|
2015-03-24 17:47:26 +01:00
|
|
|
|
|
|
|
|
|
/***** Start frame *****/
|
2016-12-27 13:56:44 +01:00
|
|
|
|
Lay_StartRoundFrame (NULL,Txt_New_notice,NULL,Hlp_MESSAGES_Notices);
|
2015-03-24 17:47:26 +01:00
|
|
|
|
|
|
|
|
|
/***** Message body *****/
|
2016-12-27 13:56:44 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"<textarea name=\"Content\" cols=\"30\" rows=\"10\""
|
|
|
|
|
" autofocus=\"autofocus\" required=\"required\">"
|
|
|
|
|
"</textarea>");
|
2015-03-24 17:47:26 +01:00
|
|
|
|
|
2015-04-11 23:46:21 +02:00
|
|
|
|
/***** Button to create notice and end frame *****/
|
2016-12-27 13:56:44 +01:00
|
|
|
|
Lay_EndRoundFrameWithButton (Lay_CREATE_BUTTON,Txt_Create_notice);
|
2015-03-24 17:47:26 +01:00
|
|
|
|
|
2015-04-11 17:33:14 +02:00
|
|
|
|
/***** End form *****/
|
2015-03-13 00:16:02 +01:00
|
|
|
|
Act_FormEnd ();
|
2015-11-03 21:58:51 +01:00
|
|
|
|
|
|
|
|
|
/***** Show all notices *****/
|
2016-11-06 22:37:12 +01:00
|
|
|
|
Not_ShowNotices (Not_LIST_FULL_NOTICES);
|
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;
|
2016-01-25 11:43:14 +01:00
|
|
|
|
struct SocialPublishing SocPub;
|
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 *****/
|
|
|
|
|
RSS_UpdateRSSFileForACrs (&Gbl.CurrentCrs.Crs);
|
|
|
|
|
|
|
|
|
|
/***** Write message of success *****/
|
|
|
|
|
Lay_ShowAlert (Lay_SUCCESS,Txt_Notice_created);
|
|
|
|
|
|
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);
|
|
|
|
|
Ntf_ShowAlertNumUsrsToBeNotifiedByEMail (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 *****/
|
2016-01-25 11:43:14 +01:00
|
|
|
|
Soc_StoreAndPublishSocialNote (Soc_NOTE_NOTICE,NotCod,&SocPub);
|
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)
|
|
|
|
|
{
|
2017-01-28 15:58:46 +01:00
|
|
|
|
char Query[256 + Cns_MAX_BYTES_TEXT];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Insert notice in the database *****/
|
|
|
|
|
sprintf (Query,"INSERT INTO notices (CrsCod,UsrCod,CreatTime,Content,Status)"
|
|
|
|
|
" VALUES ('%ld','%ld',NOW(),'%s','%u')",
|
|
|
|
|
Gbl.CurrentCrs.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod,Content,(unsigned) Not_ACTIVE_NOTICE);
|
|
|
|
|
return DB_QueryINSERTandReturnCode (Query,"can not create notice");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********** Update number of users notified in table of notices *************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Not_UpdateNumUsrsNotifiedByEMailAboutNotice (long NotCod,unsigned NumUsrsToBeNotifiedByEMail)
|
|
|
|
|
{
|
|
|
|
|
char Query[512];
|
|
|
|
|
|
|
|
|
|
/***** Update number of users notified *****/
|
|
|
|
|
sprintf (Query,"UPDATE notices SET NumNotif='%u' WHERE NotCod='%ld'",
|
|
|
|
|
NumUsrsToBeNotifiedByEMail,NotCod);
|
|
|
|
|
DB_QueryUPDATE (Query,"can not update the number of notifications of a notice");
|
|
|
|
|
}
|
|
|
|
|
|
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 *****/
|
|
|
|
|
Lay_ShowAlert (Lay_SUCCESS,Txt_Notice_removed);
|
|
|
|
|
|
|
|
|
|
/***** 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 highlighted notice *****/
|
|
|
|
|
if (Gbl.CurrentCrs.Notices.HighlightNotCod > 0)
|
2016-11-06 22:37:12 +01:00
|
|
|
|
Not_GetDataAndShowNotice (Gbl.CurrentCrs.Notices.HighlightNotCod);
|
2015-11-03 21:58:51 +01:00
|
|
|
|
|
|
|
|
|
/***** Show all notices *****/
|
2016-11-06 22:37:12 +01:00
|
|
|
|
Not_ShowNotices (Not_LIST_FULL_NOTICES);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************** Mark as hidden a notice that was active *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Not_HideActiveNotice (void)
|
|
|
|
|
{
|
|
|
|
|
char Query[256];
|
|
|
|
|
long NotCod;
|
|
|
|
|
|
|
|
|
|
/***** Get the code of the notice to hide *****/
|
|
|
|
|
NotCod = Not_GetParamNotCod ();
|
|
|
|
|
|
|
|
|
|
/***** Set notice as hidden *****/
|
|
|
|
|
sprintf (Query,"UPDATE notices SET Status='%u'"
|
|
|
|
|
" WHERE NotCod='%ld' AND CrsCod='%ld'",
|
|
|
|
|
(unsigned) Not_OBSOLETE_NOTICE,
|
|
|
|
|
NotCod,Gbl.CurrentCrs.Crs.CrsCod);
|
|
|
|
|
DB_QueryUPDATE (Query,"can not hide notice");
|
|
|
|
|
|
|
|
|
|
/***** Update RSS of current course *****/
|
|
|
|
|
RSS_UpdateRSSFileForACrs (&Gbl.CurrentCrs.Crs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Mark as active a notice that was hidden ******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Not_RevealHiddenNotice (void)
|
|
|
|
|
{
|
|
|
|
|
char Query[256];
|
|
|
|
|
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 *****/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
sprintf (Query,"UPDATE notices SET Status='%u'"
|
|
|
|
|
" WHERE NotCod='%ld' AND CrsCod='%ld'",
|
|
|
|
|
(unsigned) Not_ACTIVE_NOTICE,
|
|
|
|
|
NotCod,Gbl.CurrentCrs.Crs.CrsCod);
|
2015-11-01 20:21:59 +01:00
|
|
|
|
DB_QueryUPDATE (Query,"can not reveal notice");
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Update RSS of current course *****/
|
|
|
|
|
RSS_UpdateRSSFileForACrs (&Gbl.CurrentCrs.Crs);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
long NotCod;
|
|
|
|
|
|
|
|
|
|
/***** Get the code of the notice to remove *****/
|
|
|
|
|
NotCod = Not_GetParamNotCod ();
|
|
|
|
|
|
2016-11-14 10:30:33 +01:00
|
|
|
|
/***** Ask for confirmation to remove this notice *****/
|
2015-11-03 21:58:51 +01:00
|
|
|
|
Lay_ShowAlert (Lay_WARNING,Txt_Do_you_really_want_to_remove_the_following_notice);
|
2016-11-06 22:37:12 +01:00
|
|
|
|
Not_GetDataAndShowNotice (NotCod);
|
2016-11-14 10:30:33 +01:00
|
|
|
|
|
|
|
|
|
/***** Form to remove this notice *****/
|
|
|
|
|
Act_FormStart (ActRemNot);
|
|
|
|
|
Not_PutHiddenParamNotCod (NotCod);
|
2015-11-03 21:58:51 +01:00
|
|
|
|
Lay_PutRemoveButton (Txt_Remove);
|
|
|
|
|
Act_FormEnd ();
|
|
|
|
|
|
|
|
|
|
/***** Show all notices *****/
|
2016-11-06 22:37:12 +01:00
|
|
|
|
Not_ShowNotices (Not_LIST_FULL_NOTICES);
|
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
|
|
|
|
{
|
|
|
|
|
char Query[512];
|
|
|
|
|
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 */
|
|
|
|
|
sprintf (Query,"INSERT IGNORE INTO notices_deleted (NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif)"
|
|
|
|
|
" SELECT NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif"
|
|
|
|
|
" FROM notices"
|
|
|
|
|
" WHERE NotCod='%ld' AND CrsCod='%ld'",
|
|
|
|
|
NotCod,Gbl.CurrentCrs.Crs.CrsCod);
|
|
|
|
|
DB_QueryINSERT (Query,"can not remove notice");
|
|
|
|
|
|
|
|
|
|
/* Remove notice */
|
|
|
|
|
sprintf (Query,"DELETE FROM notices"
|
|
|
|
|
" WHERE NotCod='%ld' AND CrsCod='%ld'",
|
|
|
|
|
NotCod,Gbl.CurrentCrs.Crs.CrsCod);
|
|
|
|
|
DB_QueryDELETE (Query,"can not remove notice");
|
|
|
|
|
|
|
|
|
|
/***** 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 *****/
|
|
|
|
|
Soc_MarkSocialNoteAsUnavailableUsingNoteTypeAndCod (Soc_NOTE_NOTICE,NotCod);
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/***** Update RSS of current course *****/
|
|
|
|
|
RSS_UpdateRSSFileForACrs (&Gbl.CurrentCrs.Crs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2015-11-03 21:58:51 +01:00
|
|
|
|
/********************* Get notice to show highlighted ************************/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-06-03 10:37:00 +02:00
|
|
|
|
void Not_GetNotCodToHighlight (void)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
/***** Get the code of the notice to highlight *****/
|
|
|
|
|
Gbl.CurrentCrs.Notices.HighlightNotCod = Not_GetParamNotCod ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Show the notices ******************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-11-06 22:37:12 +01:00
|
|
|
|
void Not_ShowNotices (Not_Listing_t TypeNoticesListing)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2016-11-13 21:37:16 +01:00
|
|
|
|
extern const char *Hlp_MESSAGES_Notices;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
extern const char *Txt_All_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
|
|
|
|
char Query[512];
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
2017-01-28 15:58:46 +01:00
|
|
|
|
char StrWidth[10 + 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;
|
2015-10-26 14:49:42 +01:00
|
|
|
|
unsigned long NumNot;
|
|
|
|
|
unsigned long NumNotices;
|
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;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** A course must be selected (Gbl.CurrentCrs.Crs.CrsCod > 0) *****/
|
|
|
|
|
if (Gbl.CurrentCrs.Crs.CrsCod > 0)
|
|
|
|
|
{
|
|
|
|
|
/***** Get notices from database *****/
|
|
|
|
|
switch (TypeNoticesListing)
|
|
|
|
|
{
|
|
|
|
|
case Not_LIST_BRIEF_NOTICES:
|
2015-10-26 14:49:42 +01:00
|
|
|
|
sprintf (Query,"SELECT NotCod,UNIX_TIMESTAMP(CreatTime) AS F,UsrCod,Content,Status"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
" FROM notices"
|
|
|
|
|
" WHERE CrsCod='%ld' AND Status='%u'"
|
|
|
|
|
" ORDER BY CreatTime DESC",
|
|
|
|
|
Gbl.CurrentCrs.Crs.CrsCod,
|
|
|
|
|
(unsigned) Not_ACTIVE_NOTICE);
|
|
|
|
|
break;
|
|
|
|
|
case Not_LIST_FULL_NOTICES:
|
2015-10-26 14:49:42 +01:00
|
|
|
|
sprintf (Query,"SELECT NotCod,UNIX_TIMESTAMP(CreatTime) AS F,UsrCod,Content,Status"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
" FROM notices"
|
|
|
|
|
" WHERE CrsCod='%ld'"
|
|
|
|
|
" ORDER BY CreatTime DESC",
|
|
|
|
|
Gbl.CurrentCrs.Crs.CrsCod);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
NumNotices = DB_QuerySELECT (Query,&mysql_res,"can not get notices from database");
|
|
|
|
|
|
|
|
|
|
if (TypeNoticesListing == Not_LIST_FULL_NOTICES)
|
|
|
|
|
{
|
2016-03-21 15:10:00 +01:00
|
|
|
|
/***** Start frame *****/
|
|
|
|
|
sprintf (StrWidth,"%upx",
|
|
|
|
|
Not_ContainerWidth[Not_LIST_FULL_NOTICES] + 50);
|
|
|
|
|
Lay_StartRoundFrame (StrWidth,
|
|
|
|
|
Gbl.CurrentCrs.Notices.HighlightNotCod > 0 ? Txt_All_notices :
|
|
|
|
|
Txt_Notices,
|
2016-11-13 21:37:16 +01:00
|
|
|
|
Not_PutIconsListNotices,Hlp_MESSAGES_Notices);
|
2016-03-21 15:10:00 +01:00
|
|
|
|
if (!NumNotices)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Lay_ShowAlert (Lay_INFO,Txt_No_notices);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Show the notices *****/
|
|
|
|
|
for (NumNot = 0;
|
|
|
|
|
NumNot < NumNotices;
|
|
|
|
|
NumNot++)
|
|
|
|
|
{
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
|
|
|
|
|
2015-10-26 14:49:42 +01:00
|
|
|
|
/* Get notice code (row[0]) */
|
2014-12-01 23:55:08 +01:00
|
|
|
|
if (sscanf (row[0],"%ld",&NotCod) != 1)
|
|
|
|
|
Lay_ShowErrorAndExit ("Wrong code of notice.");
|
|
|
|
|
|
2015-10-26 14:49:42 +01:00
|
|
|
|
/* Get creation time (row[1] holds the UTC date-time) */
|
|
|
|
|
TimeUTC = Dat_GetUNIXTimeFromStr (row[1]);
|
|
|
|
|
|
|
|
|
|
/* Get user code (row[2]) */
|
2014-12-01 23:55:08 +01:00
|
|
|
|
UsrCod = Str_ConvertStrCodToLongCod (row[2]);
|
|
|
|
|
|
2015-10-26 14:49:42 +01:00
|
|
|
|
/* Get the content (row[3]) and insert links */
|
2017-01-17 03:10:43 +01:00
|
|
|
|
Str_Copy (Content,row[3],
|
|
|
|
|
Cns_MAX_BYTES_TEXT);
|
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[TypeNoticesListing]);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
if (TypeNoticesListing == Not_LIST_BRIEF_NOTICES)
|
|
|
|
|
Str_LimitLengthHTMLStr (Content,Not_MAX_CHARS_ON_NOTICE);
|
|
|
|
|
|
2015-10-26 14:49:42 +01:00
|
|
|
|
/* Get status of the notice (row[4]) */
|
2015-11-01 20:21:59 +01:00
|
|
|
|
Status = Not_OBSOLETE_NOTICE;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
if (sscanf (row[4],"%u",&UnsignedNum) == 1)
|
|
|
|
|
if (UnsignedNum < Not_NUM_STATUS)
|
2015-11-01 20:21:59 +01:00
|
|
|
|
Status = (Not_Status_t) UnsignedNum;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Draw the notice */
|
2015-11-01 18:54:10 +01:00
|
|
|
|
Not_DrawANotice (TypeNoticesListing,
|
2015-10-26 14:49:42 +01:00
|
|
|
|
NotCod,
|
2016-11-06 22:37:12 +01:00
|
|
|
|
TimeUTC,Content,UsrCod,Status);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-15 23:11:14 +01:00
|
|
|
|
switch (TypeNoticesListing)
|
|
|
|
|
{
|
|
|
|
|
case Not_LIST_BRIEF_NOTICES:
|
|
|
|
|
/***** Link to RSS file *****/
|
|
|
|
|
/* Create RSS file if not exists */
|
|
|
|
|
sprintf (PathRelRSSFile,"%s/%s/%ld/%s/%s",
|
|
|
|
|
Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_CRS,Gbl.CurrentCrs.Crs.CrsCod,Cfg_RSS_FOLDER,Cfg_RSS_FILE);
|
|
|
|
|
if (!Fil_CheckIfPathExists (PathRelRSSFile))
|
|
|
|
|
RSS_UpdateRSSFileForACrs (&Gbl.CurrentCrs.Crs);
|
|
|
|
|
|
|
|
|
|
/* Put a link to the RSS file */
|
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">"
|
|
|
|
|
"<a href=\"");
|
|
|
|
|
RSS_WriteRSSLink (Gbl.F.Out,Gbl.CurrentCrs.Crs.CrsCod);
|
|
|
|
|
fprintf (Gbl.F.Out,"\" target=\"_blank\">"
|
|
|
|
|
"<img src=\"%s/rss16x16.gif\""
|
|
|
|
|
" alt=\"RSS\" title=\"RSS\""
|
2016-11-14 10:05:41 +01:00
|
|
|
|
" class=\"ICO20x20\" />"
|
2016-03-15 23:11:14 +01:00
|
|
|
|
"</a>"
|
|
|
|
|
"</div>",
|
|
|
|
|
Gbl.Prefs.IconsURL);
|
|
|
|
|
break;
|
|
|
|
|
case Not_LIST_FULL_NOTICES:
|
2016-03-21 16:49:44 +01:00
|
|
|
|
/***** Button to add new notice *****/
|
2016-11-06 22:37:12 +01:00
|
|
|
|
if (Not_CheckIfICanEditNotices ())
|
2016-03-21 16:49:44 +01:00
|
|
|
|
Not_PutButtonToAddNewNotice ();
|
|
|
|
|
|
2016-03-21 15:10:00 +01:00
|
|
|
|
/***** End frame *****/
|
|
|
|
|
Lay_EndRoundFrame ();
|
2016-03-15 23:11:14 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Free structure that stores the query result *****/
|
|
|
|
|
DB_FreeMySQLResult (&mysql_res);
|
|
|
|
|
|
|
|
|
|
/***** Mark possible notification as seen *****/
|
2016-01-04 01:56:28 +01:00
|
|
|
|
Ntf_MarkNotifAsSeen (Ntf_EVENT_NOTICE,
|
2016-01-20 21:18:38 +01:00
|
|
|
|
-1L,Gbl.CurrentCrs.Crs.CrsCod,
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
return (bool) (Gbl.Usrs.Me.LoggedRole == Rol_TEACHER ||
|
|
|
|
|
Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-11-06 23:46:29 +01:00
|
|
|
|
static void Not_PutIconsListNotices (void)
|
2016-11-06 15:47:37 +01:00
|
|
|
|
{
|
|
|
|
|
/***** Put icon to add a new notice *****/
|
2016-11-06 22:37:12 +01:00
|
|
|
|
if (Not_CheckIfICanEditNotices ())
|
2016-11-06 15:47:37 +01:00
|
|
|
|
Not_PutIconToAddNewNotice ();
|
|
|
|
|
|
|
|
|
|
/***** Put icon to show a figure *****/
|
|
|
|
|
Gbl.Stat.FigureType = Sta_NOTICES;
|
|
|
|
|
Sta_PutIconToShowFigure ();
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
2016-07-01 16:32:42 +02:00
|
|
|
|
Lay_PutContextualLink (ActWriNot,NULL,
|
|
|
|
|
"plus64x64.png",
|
|
|
|
|
Txt_New_notice,NULL,
|
|
|
|
|
NULL);
|
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;
|
|
|
|
|
|
|
|
|
|
Act_FormStart (ActWriNot);
|
|
|
|
|
Lay_PutConfirmButton (Txt_New_notice);
|
|
|
|
|
Act_FormEnd ();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
char Query[512];
|
|
|
|
|
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 *****/
|
|
|
|
|
sprintf (Query,"SELECT UNIX_TIMESTAMP(CreatTime) AS F,UsrCod,Content,Status"
|
|
|
|
|
" FROM notices"
|
|
|
|
|
" WHERE NotCod='%ld' AND CrsCod='%ld'",
|
|
|
|
|
NotCod,
|
|
|
|
|
Gbl.CurrentCrs.Crs.CrsCod);
|
|
|
|
|
if (DB_QuerySELECT (Query,&mysql_res,"can not get notice from database"))
|
|
|
|
|
{
|
|
|
|
|
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*/
|
2017-01-17 03:10:43 +01:00
|
|
|
|
Str_Copy (Content,row[2],
|
|
|
|
|
Cns_MAX_BYTES_TEXT);
|
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,
|
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,
|
|
|
|
|
long NotCod,
|
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_NOTICE_Active_SINGULAR;
|
|
|
|
|
extern const char *Txt_NOTICE_Active_Mark_as_obsolete;
|
|
|
|
|
extern const char *Txt_NOTICE_Obsolete_SINGULAR;
|
|
|
|
|
extern const char *Txt_NOTICE_Obsolete_Mark_as_active;
|
|
|
|
|
extern const char *Txt_See_full_notice;
|
2015-12-29 11:35:01 +01:00
|
|
|
|
extern const char *Txt_Today;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
extern const char *Txt_Remove;
|
2015-11-01 14:11:46 +01:00
|
|
|
|
static const char *ContainerClass[Not_NUM_STATUS] =
|
|
|
|
|
{
|
|
|
|
|
"NOTICE_CONTAINER_ACTIVE", // Not_ACTIVE_NOTICE
|
|
|
|
|
"NOTICE_CONTAINER_OBSOLETE", // Not_OBSOLETE_NOTICE
|
|
|
|
|
};
|
|
|
|
|
static const char *DateClass[Not_NUM_STATUS] =
|
|
|
|
|
{
|
|
|
|
|
"NOTICE_DATE_ACTIVE", // Not_ACTIVE_NOTICE
|
|
|
|
|
"NOTICE_DATE_OBSOLETE", // Not_OBSOLETE_NOTICE
|
|
|
|
|
};
|
|
|
|
|
static const char *TextClass[Not_NUM_STATUS] =
|
|
|
|
|
{
|
|
|
|
|
"NOTICE_TEXT_ACTIVE", // Not_ACTIVE_NOTICE
|
|
|
|
|
"NOTICE_TEXT_OBSOLETE", // Not_OBSOLETE_NOTICE
|
|
|
|
|
};
|
|
|
|
|
static const char *AuthorClass[Not_NUM_STATUS] =
|
|
|
|
|
{
|
|
|
|
|
"NOTICE_AUTHOR_ACTIVE", // Not_ACTIVE_NOTICE
|
|
|
|
|
"NOTICE_AUTHOR_OBSOLETE", // Not_OBSOLETE_NOTICE
|
|
|
|
|
};
|
2015-10-26 14:49:42 +01:00
|
|
|
|
static unsigned UniqueId = 0;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
struct UsrData UsrDat;
|
|
|
|
|
|
2016-12-11 20:28:58 +01:00
|
|
|
|
Gbl.CurrentCrs.Notices.NotCod = NotCod; // Parameter for forms
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/***** Start yellow note *****/
|
2015-11-01 14:11:46 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"%s\" style=\"width:%upx;\">",
|
2015-11-01 20:21:59 +01:00
|
|
|
|
ContainerClass[Status],
|
2015-09-24 18:02:21 +02:00
|
|
|
|
Not_ContainerWidth[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 *****/
|
|
|
|
|
Lay_PutContextualLink (ActReqRemNot,Not_PutParams,
|
|
|
|
|
"remove-on64x64.png",
|
|
|
|
|
Txt_Remove,NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
/***** 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:
|
2016-12-11 20:28:58 +01:00
|
|
|
|
Lay_PutContextualLink (ActHidNot,Not_PutParams,
|
|
|
|
|
"eye-on64x64.png",
|
|
|
|
|
Txt_NOTICE_Active_Mark_as_obsolete,NULL,
|
|
|
|
|
NULL);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
|
|
|
|
case Not_OBSOLETE_NOTICE:
|
2016-12-11 20:28:58 +01:00
|
|
|
|
Lay_PutContextualLink (ActRevNot,Not_PutParams,
|
|
|
|
|
"eye-slash-on64x64.png",
|
|
|
|
|
Txt_NOTICE_Obsolete_Mark_as_active,NULL,
|
|
|
|
|
NULL);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2015-11-01 14:11:46 +01:00
|
|
|
|
Act_FormEnd ();
|
|
|
|
|
}
|
|
|
|
|
else // Don't put forms
|
|
|
|
|
/* 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:
|
|
|
|
|
fprintf (Gbl.F.Out,"<span title=\"%s\">"
|
2015-12-08 22:20:44 +01:00
|
|
|
|
"<img src=\"%s/eye-off64x64.png\""
|
2015-09-05 12:04:30 +02:00
|
|
|
|
" alt=\"%s\" title=\"%s\""
|
2016-11-14 10:05:41 +01:00
|
|
|
|
" class=\"ICO20x20\" />"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
"</span>",
|
|
|
|
|
Txt_NOTICE_Active_SINGULAR,
|
|
|
|
|
Gbl.Prefs.IconsURL,
|
2015-07-22 13:32:56 +02:00
|
|
|
|
Txt_NOTICE_Active_SINGULAR,
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Txt_NOTICE_Active_SINGULAR);
|
|
|
|
|
break;
|
|
|
|
|
case Not_OBSOLETE_NOTICE:
|
|
|
|
|
fprintf (Gbl.F.Out,"<span title=\"%s\">"
|
2015-12-08 22:20:44 +01:00
|
|
|
|
"<img src=\"%s/eye-slash-off64x64.png\""
|
2015-07-22 13:32:56 +02:00
|
|
|
|
" alt=\"%s\" title=\"%s\""
|
2016-11-14 10:05:41 +01:00
|
|
|
|
" class=\"ICO20x20\" />"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
"</span>",
|
|
|
|
|
Txt_NOTICE_Obsolete_SINGULAR,
|
|
|
|
|
Gbl.Prefs.IconsURL,
|
2015-07-22 13:32:56 +02:00
|
|
|
|
Txt_NOTICE_Obsolete_SINGULAR,
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Txt_NOTICE_Obsolete_SINGULAR);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-01 14:11:46 +01:00
|
|
|
|
/* Write the date */
|
2015-10-26 14:49:42 +01:00
|
|
|
|
UniqueId++;
|
2015-11-01 14:11:46 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"%s\">",
|
2015-11-01 20:21:59 +01:00
|
|
|
|
DateClass[Status]);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
if (TypeNoticesListing == Not_LIST_BRIEF_NOTICES)
|
|
|
|
|
{
|
|
|
|
|
/* Form to view full notice */
|
2016-06-01 19:34:44 +02:00
|
|
|
|
Act_FormStart (ActSeeOneNot);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Not_PutHiddenParamNotCod (NotCod);
|
2016-07-01 17:13:41 +02:00
|
|
|
|
Act_LinkFormSubmit (Txt_See_full_notice,DateClass[Status],NULL);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
2015-10-26 14:49:42 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"<span id=\"notice_date_%u\"></span>",
|
|
|
|
|
UniqueId);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
if (TypeNoticesListing == Not_LIST_BRIEF_NOTICES)
|
2015-03-13 00:16:02 +01:00
|
|
|
|
{
|
|
|
|
|
fprintf (Gbl.F.Out,"</a>");
|
|
|
|
|
Act_FormEnd ();
|
|
|
|
|
}
|
2015-10-26 14:49:42 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"<script type=\"text/javascript\">"
|
2016-12-12 23:10:11 +01:00
|
|
|
|
"writeLocalDateHMSFromUTC('notice_date_%u',"
|
|
|
|
|
"%ld,'<br />','%s',true,false,false);"
|
2015-10-26 14:49:42 +01:00
|
|
|
|
"</script>"
|
|
|
|
|
"</div>",
|
2015-12-29 11:35:01 +01:00
|
|
|
|
UniqueId,(long) TimeUTC,Txt_Today);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Write the content of the notice *****/
|
|
|
|
|
if (TypeNoticesListing == Not_LIST_BRIEF_NOTICES)
|
|
|
|
|
{
|
2016-12-11 20:28:58 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"NOTICE_TEXT_BRIEF\">%s</div>",Content);
|
2015-11-01 21:19:33 +01:00
|
|
|
|
|
2016-12-11 20:28:58 +01:00
|
|
|
|
/* Put form to view full notice */
|
2015-11-01 21:19:33 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"CENTER_MIDDLE\">");
|
2016-12-11 20:28:58 +01:00
|
|
|
|
Lay_PutContextualLink (ActSeeOneNot,Not_PutParams,
|
|
|
|
|
"ellipsis32x32.gif",
|
|
|
|
|
Txt_See_full_notice,NULL,
|
|
|
|
|
NULL);
|
2015-03-13 00:16:02 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"</div>");
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
2015-11-01 21:19:33 +01:00
|
|
|
|
else
|
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"%s\">%s</div>",
|
|
|
|
|
TextClass[Status],Content);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Write the author *****/
|
2015-11-01 14:11:46 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"%s\">",
|
2015-11-01 20:21:59 +01:00
|
|
|
|
AuthorClass[Status]);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Usr_UsrDataConstructor (&UsrDat);
|
|
|
|
|
UsrDat.UsrCod = UsrCod;
|
|
|
|
|
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // Get from the database the data of the autor
|
2015-12-30 12:40:13 +01:00
|
|
|
|
Usr_RestrictLengthAndWriteName (&UsrDat,16);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Usr_UsrDataDestructor (&UsrDat);
|
|
|
|
|
fprintf (Gbl.F.Out,"</div>");
|
|
|
|
|
|
2015-12-30 12:40:13 +01:00
|
|
|
|
/***** End yellow note *****/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"</div>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2015-12-29 01:28:17 +01:00
|
|
|
|
/******************* Get summary and content for a notice ********************/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// This function may be called inside a web service, so don't report error
|
|
|
|
|
|
2017-01-15 22:58:26 +01:00
|
|
|
|
void Not_GetSummaryAndContentNotice (char SummaryStr[Cns_MAX_BYTES_TEXT + 1],
|
|
|
|
|
char **ContentStr,long NotCod,
|
|
|
|
|
unsigned MaxChars,bool GetContent)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
char Query[512];
|
|
|
|
|
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 *****/
|
|
|
|
|
sprintf (Query,"SELECT Content FROM notices WHERE NotCod='%ld'",
|
|
|
|
|
NotCod);
|
|
|
|
|
if (!mysql_query (&Gbl.mysql,Query))
|
|
|
|
|
if ((mysql_res = mysql_store_result (&Gbl.mysql)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
/***** Result should have a unique row *****/
|
|
|
|
|
if (mysql_num_rows (mysql_res) == 1)
|
|
|
|
|
{
|
|
|
|
|
/***** Get sumary / content *****/
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
|
|
|
|
|
|
|
|
|
/***** Copy summary *****/
|
2017-01-17 03:10:43 +01:00
|
|
|
|
Str_Copy (SummaryStr,row[0],
|
|
|
|
|
Cns_MAX_BYTES_TEXT);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
if (MaxChars)
|
|
|
|
|
Str_LimitLengthHTMLStr (SummaryStr,MaxChars);
|
|
|
|
|
|
|
|
|
|
/***** Copy content *****/
|
|
|
|
|
if (GetContent)
|
|
|
|
|
{
|
2017-01-15 22:58:26 +01:00
|
|
|
|
Length = strlen (row[0]);
|
|
|
|
|
if ((*ContentStr = (char *) malloc (Length + 1)) == NULL)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Lay_ShowErrorAndExit ("Error allocating memory for notification content.");
|
2017-01-17 03:10:43 +01:00
|
|
|
|
Str_Copy (*ContentStr,row[0],
|
|
|
|
|
Length);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mysql_free_result (mysql_res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************************** Get number of notices ***************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// Returns the number of (active or obsolete) notices
|
|
|
|
|
// sent from this location (all the platform, current degree or current course)
|
|
|
|
|
|
2015-11-01 20:21:59 +01:00
|
|
|
|
unsigned Not_GetNumNotices (Sco_Scope_t Scope,Not_Status_t Status,unsigned *NumNotif)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
char Query[1024];
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
unsigned NumNotices;
|
|
|
|
|
|
|
|
|
|
/***** Get number of notices from database *****/
|
|
|
|
|
switch (Scope)
|
|
|
|
|
{
|
2015-02-01 20:17:24 +01:00
|
|
|
|
case Sco_SCOPE_SYS:
|
2014-12-01 23:55:08 +01:00
|
|
|
|
sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)"
|
|
|
|
|
" FROM notices"
|
|
|
|
|
" WHERE Status='%u'",
|
2015-11-01 20:21:59 +01:00
|
|
|
|
Status);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
2015-03-09 10:40:31 +01:00
|
|
|
|
case Sco_SCOPE_CTY:
|
|
|
|
|
sprintf (Query,"SELECT COUNT(*),SUM(notices.NumNotif)"
|
|
|
|
|
" FROM institutions,centres,degrees,courses,notices"
|
|
|
|
|
" WHERE institutions.CtyCod='%ld'"
|
|
|
|
|
" AND institutions.InsCod=centres.InsCod"
|
|
|
|
|
" AND centres.CtrCod=degrees.CtrCod"
|
|
|
|
|
" AND degrees.DegCod=courses.DegCod"
|
|
|
|
|
" AND courses.CrsCod=notices.CrsCod"
|
|
|
|
|
" AND notices.Status='%u'",
|
|
|
|
|
Gbl.CurrentCty.Cty.CtyCod,
|
2015-11-01 20:21:59 +01:00
|
|
|
|
Status);
|
2015-03-09 10:40:31 +01:00
|
|
|
|
break;
|
2015-02-01 20:17:24 +01:00
|
|
|
|
case Sco_SCOPE_INS:
|
2014-12-01 23:55:08 +01:00
|
|
|
|
sprintf (Query,"SELECT COUNT(*),SUM(notices.NumNotif)"
|
|
|
|
|
" FROM centres,degrees,courses,notices"
|
|
|
|
|
" WHERE centres.InsCod='%ld'"
|
|
|
|
|
" AND centres.CtrCod=degrees.CtrCod"
|
|
|
|
|
" AND degrees.DegCod=courses.DegCod"
|
|
|
|
|
" AND courses.CrsCod=notices.CrsCod"
|
|
|
|
|
" AND notices.Status='%u'",
|
|
|
|
|
Gbl.CurrentIns.Ins.InsCod,
|
2015-11-01 20:21:59 +01:00
|
|
|
|
Status);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
2015-02-01 20:17:24 +01:00
|
|
|
|
case Sco_SCOPE_CTR:
|
2014-12-01 23:55:08 +01:00
|
|
|
|
sprintf (Query,"SELECT COUNT(*),SUM(notices.NumNotif)"
|
|
|
|
|
" FROM degrees,courses,notices"
|
|
|
|
|
" WHERE degrees.CtrCod='%ld'"
|
|
|
|
|
" AND degrees.DegCod=courses.DegCod"
|
|
|
|
|
" AND courses.CrsCod=notices.CrsCod"
|
|
|
|
|
" AND notices.Status='%u'",
|
|
|
|
|
Gbl.CurrentCtr.Ctr.CtrCod,
|
2015-11-01 20:21:59 +01:00
|
|
|
|
Status);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
2015-02-01 20:17:24 +01:00
|
|
|
|
case Sco_SCOPE_DEG:
|
2014-12-01 23:55:08 +01:00
|
|
|
|
sprintf (Query,"SELECT COUNT(*),SUM(notices.NumNotif)"
|
|
|
|
|
" FROM courses,notices"
|
|
|
|
|
" WHERE courses.DegCod='%ld'"
|
|
|
|
|
" AND courses.CrsCod=notices.CrsCod"
|
|
|
|
|
" AND notices.Status='%u'",
|
|
|
|
|
Gbl.CurrentDeg.Deg.DegCod,
|
2015-11-01 20:21:59 +01:00
|
|
|
|
Status);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
2015-02-01 20:17:24 +01:00
|
|
|
|
case Sco_SCOPE_CRS:
|
2014-12-01 23:55:08 +01:00
|
|
|
|
sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)"
|
|
|
|
|
" FROM notices"
|
|
|
|
|
" WHERE CrsCod='%ld'"
|
|
|
|
|
" AND Status='%u'",
|
|
|
|
|
Gbl.CurrentCrs.Crs.CrsCod,
|
2015-11-01 20:21:59 +01:00
|
|
|
|
Status);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Lay_ShowErrorAndExit ("Wrong scope.");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
DB_QuerySELECT (Query,&mysql_res,"can not get number of notices");
|
|
|
|
|
|
|
|
|
|
/***** 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)
|
|
|
|
|
|
|
|
|
|
unsigned Not_GetNumNoticesDeleted (Sco_Scope_t Scope,unsigned *NumNotif)
|
|
|
|
|
{
|
|
|
|
|
char Query[1024];
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
unsigned NumNotices;
|
|
|
|
|
|
|
|
|
|
/***** Get number of notices from database *****/
|
|
|
|
|
switch (Scope)
|
|
|
|
|
{
|
2015-02-01 20:17:24 +01:00
|
|
|
|
case Sco_SCOPE_SYS:
|
2014-12-01 23:55:08 +01:00
|
|
|
|
sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)"
|
|
|
|
|
" FROM notices_deleted");
|
|
|
|
|
break;
|
2015-03-09 10:40:31 +01:00
|
|
|
|
case Sco_SCOPE_CTY:
|
|
|
|
|
sprintf (Query,"SELECT COUNT(*),SUM(notices_deleted.NumNotif)"
|
|
|
|
|
" FROM institutions,centres,degrees,courses,notices_deleted"
|
|
|
|
|
" WHERE institutions.CtyCod='%ld'"
|
|
|
|
|
" AND institutions.InsCod=centres.InsCod"
|
|
|
|
|
" AND centres.CtrCod=degrees.CtrCod"
|
|
|
|
|
" AND degrees.DegCod=courses.DegCod"
|
|
|
|
|
" AND courses.CrsCod=notices_deleted.CrsCod",
|
|
|
|
|
Gbl.CurrentCty.Cty.CtyCod);
|
|
|
|
|
break;
|
2015-02-01 20:17:24 +01:00
|
|
|
|
case Sco_SCOPE_INS:
|
2014-12-01 23:55:08 +01:00
|
|
|
|
sprintf (Query,"SELECT COUNT(*),SUM(notices_deleted.NumNotif)"
|
|
|
|
|
" FROM centres,degrees,courses,notices_deleted"
|
|
|
|
|
" WHERE centres.InsCod='%ld'"
|
|
|
|
|
" AND centres.CtrCod=degrees.CtrCod"
|
|
|
|
|
" AND degrees.DegCod=courses.DegCod"
|
|
|
|
|
" AND courses.CrsCod=notices_deleted.CrsCod",
|
|
|
|
|
Gbl.CurrentIns.Ins.InsCod);
|
|
|
|
|
break;
|
2015-02-01 20:17:24 +01:00
|
|
|
|
case Sco_SCOPE_CTR:
|
2014-12-01 23:55:08 +01:00
|
|
|
|
sprintf (Query,"SELECT COUNT(*),SUM(notices_deleted.NumNotif)"
|
|
|
|
|
" FROM degrees,courses,notices_deleted"
|
|
|
|
|
" WHERE degrees.CtrCod='%ld'"
|
|
|
|
|
" AND degrees.DegCod=courses.DegCod"
|
|
|
|
|
" AND courses.CrsCod=notices_deleted.CrsCod",
|
|
|
|
|
Gbl.CurrentCtr.Ctr.CtrCod);
|
|
|
|
|
break;
|
2015-02-01 20:17:24 +01:00
|
|
|
|
case Sco_SCOPE_DEG:
|
2014-12-01 23:55:08 +01:00
|
|
|
|
sprintf (Query,"SELECT COUNT(*),SUM(notices_deleted.NumNotif)"
|
|
|
|
|
" FROM courses,notices_deleted"
|
|
|
|
|
" WHERE courses.DegCod='%ld'"
|
|
|
|
|
" AND courses.CrsCod=notices_deleted.CrsCod",
|
|
|
|
|
Gbl.CurrentDeg.Deg.DegCod);
|
|
|
|
|
break;
|
2015-02-01 20:17:24 +01:00
|
|
|
|
case Sco_SCOPE_CRS:
|
2014-12-01 23:55:08 +01:00
|
|
|
|
sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)"
|
|
|
|
|
" FROM notices_deleted"
|
|
|
|
|
" WHERE CrsCod='%ld'",
|
|
|
|
|
Gbl.CurrentCrs.Crs.CrsCod);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Lay_ShowErrorAndExit ("Wrong scope.");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
DB_QuerySELECT (Query,&mysql_res,"can not get number of deleted notices");
|
|
|
|
|
|
|
|
|
|
/***** 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 *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-12-11 20:28:58 +01:00
|
|
|
|
static void Not_PutParams (void)
|
|
|
|
|
{
|
|
|
|
|
Not_PutHiddenParamNotCod (Gbl.CurrentCrs.Notices.NotCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************** 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
|
|
|
|
{
|
|
|
|
|
Par_PutHiddenParamLong ("NotCod",NotCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************** Get parameter with the code of a notice *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static long Not_GetParamNotCod (void)
|
|
|
|
|
{
|
|
|
|
|
long NotCod;
|
|
|
|
|
|
2017-01-28 20:32:50 +01:00
|
|
|
|
/***** Get notice code *****/
|
|
|
|
|
if ((NotCod = Par_GetParToLong ("NotCod")) <= 0)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Lay_ShowErrorAndExit ("Wrong code of notice.");
|
|
|
|
|
|
|
|
|
|
return NotCod;
|
|
|
|
|
}
|