swad-core/swad_timeline.c

5451 lines
184 KiB
C
Raw Normal View History

2019-03-12 21:25:55 +01:00
// swad_timeline.c: social timeline
2015-12-28 19:23:42 +01:00
/*
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.
2020-01-01 14:53:57 +01:00
Copyright (C) 1999-2020 Antonio Ca<EFBFBD>as Vargas
2015-12-28 19:23:42 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General 3 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-02-24 15:15:43 +01:00
#define _GNU_SOURCE // For asprintf
2015-12-28 19:23:42 +01:00
#include <linux/limits.h> // For PATH_MAX
2019-02-24 15:15:43 +01:00
#include <stdio.h> // For asprintf
2015-12-28 20:46:48 +01:00
#include <stdlib.h> // For malloc and free
2015-12-29 23:44:28 +01:00
#include <string.h> // For string functions
2015-12-28 19:23:42 +01:00
#include <sys/types.h> // For time_t
2019-02-14 19:22:38 +01:00
#include "swad_announcement.h"
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2015-12-28 19:23:42 +01:00
#include "swad_constant.h"
#include "swad_database.h"
2015-12-29 02:09:50 +01:00
#include "swad_exam.h"
2015-12-29 14:24:37 +01:00
#include "swad_follow.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2015-12-28 19:23:42 +01:00
#include "swad_global.h"
2019-10-23 20:07:56 +02:00
#include "swad_HTML.h"
2015-12-28 19:23:42 +01:00
#include "swad_layout.h"
2019-03-02 21:49:11 +01:00
#include "swad_media.h"
2015-12-29 01:28:17 +01:00
#include "swad_notice.h"
2016-01-22 12:42:43 +01:00
#include "swad_notification.h"
2015-12-29 22:29:51 +01:00
#include "swad_parameter.h"
2016-01-02 01:56:48 +01:00
#include "swad_profile.h"
2019-03-26 11:53:21 +01:00
#include "swad_setting.h"
2019-03-12 21:25:55 +01:00
#include "swad_timeline.h"
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
2019-11-24 23:51:03 +01:00
/************************* Private constants and types ***********************/
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
2019-03-29 00:57:51 +01:00
#define TL_NUM_VISIBLE_COMMENTS 3 // Maximum number of comments visible before expanding them
2019-02-27 02:31:31 +01:00
2019-03-29 11:24:02 +01:00
#define TL_DEF_USRS_SHOWN 5 // Default maximum number of users shown who have share/fav a note
2019-03-29 00:57:51 +01:00
#define TL_MAX_USRS_SHOWN 1000 // Top maximum number of users shown who have share/fav a note
2016-01-11 00:27:04 +01:00
2019-03-29 00:57:51 +01:00
#define TL_MAX_CHARS_IN_POST 1000
#define TL_ICON_ELLIPSIS "ellipsis-h.svg"
#define TL_ICON_FAV "heart.svg"
#define TL_ICON_FAVED "heart-red.svg"
#define TL_ICON_SHARE "share-alt.svg"
#define TL_ICON_SHARED "share-alt-green.svg"
2016-01-15 02:41:55 +01:00
2016-01-14 01:39:02 +01:00
typedef enum
{
2019-03-12 21:25:55 +01:00
TL_TIMELINE_USR, // Show the timeline of a user
TL_TIMELINE_GBL, // Show the timeline of the users follwed by me
} TL_TimelineUsrOrGbl_t;
2016-01-14 01:39:02 +01:00
2019-11-22 01:04:03 +01:00
#define TL_NUM_WHAT_TO_GET_FROM_TIMELINE 3
2016-01-10 16:57:02 +01:00
typedef enum
{
2019-03-12 21:25:55 +01:00
TL_GET_ONLY_NEW_PUBS, // New publications are retrieved via AJAX
2016-01-13 00:45:16 +01:00
// automatically from time to time
2019-03-12 21:25:55 +01:00
TL_GET_RECENT_TIMELINE, // Recent timeline is shown when user clicks on action menu,...
2016-01-17 01:50:43 +01:00
// or after editing timeline
2019-03-12 21:25:55 +01:00
TL_GET_ONLY_OLD_PUBS, // Old publications are retrieved via AJAX
2016-01-13 00:45:16 +01:00
// when user clicks on link at bottom of timeline
2019-03-12 21:25:55 +01:00
} TL_WhatToGetFromTimeline_t;
2015-12-28 19:23:42 +01:00
2019-11-24 23:51:03 +01:00
struct PostContent
{
char Txt[Cns_MAX_BYTES_LONG_TEXT + 1];
struct Media Media;
};
/*
Timeline images will be saved with:
<EFBFBD> maximum width of TL_IMAGE_SAVED_MAX_HEIGHT
<EFBFBD> maximum height of TL_IMAGE_SAVED_MAX_HEIGHT
<EFBFBD> maintaining the original aspect ratio (aspect ratio recommended: 3:2)
*/
2019-03-12 21:25:55 +01:00
#define TL_IMAGE_SAVED_MAX_WIDTH 768
2020-02-13 22:33:31 +01:00
#define TL_IMAGE_SAVED_MAX_HEIGHT 768
#define TL_IMAGE_SAVED_QUALITY 90 // 1 to 100
2019-03-12 21:25:55 +01:00
// in timeline posts, the quality should not be high in order to speed up the loading of images
2016-04-08 16:37:59 +02:00
2019-11-24 23:51:03 +01:00
/*
The timeline is a set of publications.
A publication can be:
<EFBFBD> an original note
<EFBFBD> a shared note
<EFBFBD> a comment to a note
2019-11-25 23:18:08 +01:00
_____tl_pubs_____ _tl_comments_
| | | |
| Publication n |------------------------------------>| Comment p |
| (comment) | +----| (to note m) |
|_________________| ____tl_notes_____ | |_____________|
| | | | | | |
| Publication n-1 |-------->| Note m |<---+ | |
| (original note) | | (tl. post) | | ... |
|_________________| |_________________| |_____________|
| | | | | |
| | | Note m-1 | | Comment 1 |
| ... | | (public file) | +----| (to note 2) |
|_________________| |_________________| | |_____________|
| | | | |
| Publication 2 | | Note 2 |<---+
| (shared note) |----+ | (exam announc.) |
|_________________| | |_________________|
| | | | |
| Publication 1 | +--->| Note 1 |
| (original note) |-------->| (tl. post) |
|_________________| |_________________|
2019-11-24 23:51:03 +01:00
A note can be:
<EFBFBD> a timeline post
<EFBFBD> a public file
<EFBFBD> an exam announcement
<EFBFBD> a notice
<EFBFBD> a forum post
written by an author in a date-time.
*/
2015-12-28 19:23:42 +01:00
2019-03-12 21:25:55 +01:00
struct TL_Note
2015-12-30 12:40:13 +01:00
{
2015-12-31 14:47:22 +01:00
long NotCod;
2019-11-24 23:51:03 +01:00
TL_NoteType_t NoteType; // Timeline post, public file, exam announcement, notice, forum post...
long UsrCod; // Publisher
long HieCod; // Hierarchy code (institution/centre/degree/course)
long Cod; // Code of file, forum post, notice, timeline post...
bool Unavailable; // File, forum post, notice,... unavailable (removed)
2019-11-25 13:29:56 +01:00
time_t DateTimeUTC; // Date-time of publication in UTC time
2019-11-24 23:51:03 +01:00
unsigned NumShared; // Number of times (users) this note has been shared
unsigned NumFavs; // Number of times (users) this note has been favourited
2015-12-30 12:40:13 +01:00
};
2019-11-24 23:51:03 +01:00
/* A note can have comments attached to it.
__________________
|@author |
| Note |
|__________________|
|@author |
| Comment 1 |
|______________|
|@author |
| Comment 2 |
|______________|
| |
| ... |
|______________|
|@author |
| Comment n |
|______________|
*/
2019-03-12 21:25:55 +01:00
struct TL_Comment
2016-01-08 01:53:37 +01:00
{
2016-01-25 12:32:13 +01:00
long PubCod;
2019-11-24 23:51:03 +01:00
long UsrCod; // Publisher
long NotCod; // Note code to which this comment belongs
2019-11-25 13:29:56 +01:00
time_t DateTimeUTC; // Date-time of publication in UTC time
2019-11-24 23:51:03 +01:00
unsigned NumFavs; // Number of times (users) this comment has been favourited
struct PostContent Content;
2016-01-08 01:53:37 +01:00
};
2019-03-29 00:57:51 +01:00
2019-03-28 15:22:38 +01:00
typedef enum
{
2019-03-29 00:57:51 +01:00
TL_SHOW_A_FEW_USRS, // Show a few first favers/sharers
TL_SHOW_ALL_USRS, // Show all favers/sharers
} TL_HowMany_t;
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
2019-11-21 16:47:07 +01:00
/************************* Private global variables **************************/
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_ShowTimelineGblHighlightingNot (long NotCod);
static void TL_ShowTimelineUsrHighlightingNot (long NotCod);
2016-01-15 14:46:44 +01:00
2019-03-12 21:25:55 +01:00
static void TL_GetAndShowOldTimeline (TL_TimelineUsrOrGbl_t TimelineUsrOrGbl);
2016-01-14 01:39:02 +01:00
2019-03-12 21:25:55 +01:00
static void TL_BuildQueryToGetTimeline (char **Query,
2019-03-13 00:54:35 +01:00
TL_TimelineUsrOrGbl_t TimelineUsrOrGbl,
TL_WhatToGetFromTimeline_t WhatToGetFromTimeline);
2019-03-12 21:25:55 +01:00
static long TL_GetPubCodFromSession (const char *FieldName);
static void TL_UpdateLastPubCodIntoSession (void);
static void TL_UpdateFirstPubCodIntoSession (long FirstPubCod);
static void TL_DropTemporaryTablesUsedToQueryTimeline (void);
2016-01-10 03:10:40 +01:00
2019-03-12 21:25:55 +01:00
static void TL_ShowTimeline (char *Query,
2019-03-13 10:23:41 +01:00
const char *Title,long NotCodToHighlight);
2020-03-26 02:54:30 +01:00
static void TL_PutIconsTimeline (void *Args);
2017-02-24 03:38:18 +01:00
2019-03-12 21:25:55 +01:00
static void TL_FormStart (Act_Action_t ActionGbl,Act_Action_t ActionUsr);
static void TL_FormFavSha (Act_Action_t ActionGbl,Act_Action_t ActionUsr,
2019-03-13 10:23:41 +01:00
const char *ParamCod,
const char *Icon,const char *Title);
2017-02-24 10:34:21 +01:00
2019-11-12 00:31:41 +01:00
static void TL_PutFormWho (void);
static void TL_GetParamWho (void);
static Usr_Who_t TL_GetWhoFromDB (void);
2019-03-12 21:25:55 +01:00
static void TL_SaveWhichUsersInDB (void);
static void TL_ShowWarningYouDontFollowAnyUser (void);
static void TL_InsertNewPubsInTimeline (char *Query);
static void TL_ShowOldPubsInTimeline (char *Query);
static void TL_GetDataOfPublicationFromRow (MYSQL_ROW row,struct TL_Publication *SocPub);
static void TL_PutLinkToViewNewPublications (void);
static void TL_PutLinkToViewOldPublications (void);
static void TL_WriteNote (const struct TL_Note *SocNot,
TL_TopMessage_t TopMessage,long UsrCod,
bool Highlight,
bool ShowNoteAlone);
static void TL_WriteTopMessage (TL_TopMessage_t TopMessage,long UsrCod);
static void TL_WriteAuthorNote (const struct UsrData *UsrDat);
static void TL_WriteDateTime (time_t TimeUTC);
static void TL_GetAndWritePost (long PstCod);
2020-04-07 03:01:41 +02:00
static void TL_PutFormGoToAction (const struct TL_Note *SocNot,
const struct For_Forums *Forums);
2019-03-12 21:25:55 +01:00
static void TL_GetNoteSummary (const struct TL_Note *SocNot,
char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1]);
static void TL_PublishNoteInTimeline (struct TL_Publication *SocPub);
static void TL_PutFormToWriteNewPost (void);
2019-03-28 08:51:39 +01:00
static void TL_PutTextarea (const char *Placeholder,const char *ClassTextArea);
2016-01-15 10:48:49 +01:00
2019-03-12 21:25:55 +01:00
static long TL_ReceivePost (void);
2015-12-30 12:40:13 +01:00
2019-03-12 21:25:55 +01:00
static void TL_PutIconToToggleCommentNote (const char UniqueId[Frm_MAX_BYTES_ID + 1]);
static void TL_PutIconCommentDisabled (void);
static void TL_PutHiddenFormToWriteNewCommentToNote (long NotCod,
const char IdNewComment[Frm_MAX_BYTES_ID + 1]);
static unsigned long TL_GetNumCommentsInNote (long NotCod);
2019-11-18 08:38:34 +01:00
static void TL_WriteCommentsInNote (const struct TL_Note *SocNot,
unsigned NumComments);
static void TL_FormToShowHiddenComments (Act_Action_t ActionGbl,Act_Action_t ActionUsr,
long NotCod,
char IdComments[Frm_MAX_BYTES_ID + 1],
unsigned NumInitialComments);
static unsigned TL_WriteHiddenComments (long NotCod,
char IdComments[Frm_MAX_BYTES_ID + 1],
unsigned NumInitialCommentsToGet);
2019-03-12 21:25:55 +01:00
static void TL_WriteOneCommentInList (MYSQL_RES *mysql_res);
2019-11-18 08:38:34 +01:00
static void TL_LinkToShowOnlyLatestComments (const char IdComments[Frm_MAX_BYTES_ID + 1]);
static void TL_LinkToShowPreviousComments (const char IdComments[Frm_MAX_BYTES_ID + 1],
unsigned NumInitialComments);
2019-03-12 21:25:55 +01:00
static void TL_PutIconToToggleComments (const char *UniqueId,
2019-03-13 10:23:41 +01:00
const char *Icon,const char *Text);
2019-03-12 21:25:55 +01:00
static void TL_WriteComment (struct TL_Comment *SocCom,
TL_TopMessage_t TopMessage,long UsrCod,
bool ShowCommentAlone);
static void TL_WriteAuthorComment (struct UsrData *UsrDat);
2016-01-19 12:54:27 +01:00
2019-03-12 21:25:55 +01:00
static void TL_PutFormToRemoveComment (long PubCod);
2016-01-19 00:50:35 +01:00
2019-03-12 21:25:55 +01:00
static void TL_PutDisabledIconShare (unsigned NumShared);
static void TL_PutDisabledIconFav (unsigned NumFavs);
2016-01-19 00:50:35 +01:00
2019-03-29 00:57:51 +01:00
static void TL_PutFormToSeeAllSharersNote (const struct TL_Note *SocNot,
TL_HowMany_t HowMany);
static void TL_PutFormToShaNote (const struct TL_Note *SocNot);
static void TL_PutFormToUnsNote (const struct TL_Note *SocNot);
2019-03-28 15:22:38 +01:00
2019-03-29 00:57:51 +01:00
static void TL_PutFormToSeeAllFaversNote (const struct TL_Note *SocNot,
TL_HowMany_t HowMany);
2019-03-12 21:25:55 +01:00
static void TL_PutFormToFavNote (const struct TL_Note *SocNot);
2019-03-29 00:57:51 +01:00
static void TL_PutFormToUnfNote (const struct TL_Note *SocNot);
2019-03-28 15:22:38 +01:00
2019-03-29 00:57:51 +01:00
static void TL_PutFormToSeeAllFaversComment (const struct TL_Comment *SocCom,
TL_HowMany_t HowMany);
2019-03-28 19:44:59 +01:00
static void TL_PutFormToFavComment (const struct TL_Comment *SocCom);
2019-03-29 00:57:51 +01:00
static void TL_PutFormToUnfComment (const struct TL_Comment *SocCom);
2016-01-19 00:50:35 +01:00
2019-03-12 21:25:55 +01:00
static void TL_PutFormToRemovePublication (long NotCod);
2016-01-08 01:53:37 +01:00
2019-03-12 21:25:55 +01:00
static void TL_PutHiddenParamNotCod (long NotCod);
static long TL_GetParamNotCod (void);
static long TL_GetParamPubCod (void);
2016-01-01 20:19:43 +01:00
2019-03-12 21:25:55 +01:00
static long TL_ReceiveComment (void);
2016-01-11 01:46:33 +01:00
2019-03-29 00:57:51 +01:00
static void TL_PutFormToShaUnsNote (const struct TL_Note *SocNot,
TL_HowMany_t HowMany);
2019-03-28 19:44:59 +01:00
static void TL_ShaNote (struct TL_Note *SocNot);
static void TL_UnsNote (struct TL_Note *SocNot);
2019-03-29 00:57:51 +01:00
static void TL_PutFormToFavUnfNote (const struct TL_Note *SocNot,
TL_HowMany_t HowMany);
2019-03-12 21:25:55 +01:00
static void TL_FavNote (struct TL_Note *SocNot);
2019-03-28 19:44:59 +01:00
static void TL_UnfNote (struct TL_Note *SocNot);
2019-03-28 18:03:42 +01:00
2019-03-29 00:57:51 +01:00
static void TL_PutFormToFavUnfComment (const struct TL_Comment *SocCom,
TL_HowMany_t HowMany);
2019-03-12 21:25:55 +01:00
static void TL_FavComment (struct TL_Comment *SocCom);
2019-03-28 19:44:59 +01:00
static void TL_UnfComment (struct TL_Comment *SocCom);
2019-03-28 18:03:42 +01:00
2019-03-12 21:25:55 +01:00
static void TL_CreateNotifToAuthor (long AuthorCod,long PubCod,
2019-03-13 10:23:41 +01:00
Ntf_NotifyEvent_t NotifyEvent);
2016-01-19 00:50:35 +01:00
2019-03-12 21:25:55 +01:00
static void TL_RequestRemovalNote (void);
2020-03-26 02:54:30 +01:00
static void TL_PutParamsRemoveNote (void *Args);
2019-03-12 21:25:55 +01:00
static void TL_RemoveNote (void);
2019-03-18 15:42:22 +01:00
static void TL_RemoveNoteMediaAndDBEntries (struct TL_Note *SocNot);
2019-03-12 21:25:55 +01:00
static long TL_GetNotCodOfPublication (long PubCod);
static long TL_GetPubCodOfOriginalNote (long NotCod);
static void TL_RequestRemovalComment (void);
2020-03-26 02:54:30 +01:00
static void TL_PutParamsRemoveCommment (void *Args);
2019-03-12 21:25:55 +01:00
static void TL_RemoveComment (void);
2019-03-18 15:42:22 +01:00
static void TL_RemoveCommentMediaAndDBEntries (long PubCod);
2019-03-12 21:25:55 +01:00
static bool TL_CheckIfNoteIsSharedByUsr (long NotCod,long UsrCod);
static bool TL_CheckIfNoteIsFavedByUsr (long NotCod,long UsrCod);
static bool TL_CheckIfCommIsFavedByUsr (long PubCod,long UsrCod);
static void TL_UpdateNumTimesANoteHasBeenShared (struct TL_Note *SocNot);
static void TL_GetNumTimesANoteHasBeenFav (struct TL_Note *SocNot);
static void TL_GetNumTimesACommHasBeenFav (struct TL_Comment *SocCom);
2019-03-28 15:22:38 +01:00
static void TL_ShowUsrsWhoHaveSharedNote (const struct TL_Note *SocNot,
2019-03-29 00:57:51 +01:00
TL_HowMany_t HowMany);
2019-03-28 15:22:38 +01:00
static void TL_ShowUsrsWhoHaveMarkedNoteAsFav (const struct TL_Note *SocNot,
2019-03-29 00:57:51 +01:00
TL_HowMany_t HowMany);
2019-03-28 15:22:38 +01:00
static void TL_ShowUsrsWhoHaveMarkedCommAsFav (const struct TL_Comment *SocCom,
2019-03-29 00:57:51 +01:00
TL_HowMany_t HowMany);
static void TL_ShowNumSharersOrFavers (unsigned NumUsrs);
2019-03-12 21:25:55 +01:00
static void TL_ShowSharersOrFavers (MYSQL_RES **mysql_res,
2019-03-13 10:23:41 +01:00
unsigned NumUsrs,unsigned NumFirstUsrs);
2016-01-08 01:53:37 +01:00
2019-03-12 21:25:55 +01:00
static void TL_GetDataOfNoteByCod (struct TL_Note *SocNot);
static void TL_GetDataOfCommByCod (struct TL_Comment *SocCom);
2016-01-08 01:53:37 +01:00
2019-03-12 21:25:55 +01:00
static void TL_GetDataOfPublicationFromRow (MYSQL_ROW row,struct TL_Publication *SocPub);
static void TL_GetDataOfNoteFromRow (MYSQL_ROW row,struct TL_Note *SocNot);
static TL_PubType_t TL_GetPubTypeFromStr (const char *Str);
static TL_NoteType_t TL_GetNoteTypeFromStr (const char *Str);
static void TL_GetDataOfCommentFromRow (MYSQL_ROW row,struct TL_Comment *SocCom);
2016-01-08 01:53:37 +01:00
2019-03-12 21:25:55 +01:00
static void TL_ResetNote (struct TL_Note *SocNot);
static void TL_ResetComment (struct TL_Comment *SocCom);
2015-12-29 23:44:28 +01:00
2019-03-12 21:25:55 +01:00
static void TL_ClearTimelineThisSession (void);
static void TL_AddNotesJustRetrievedToTimelineThisSession (void);
2016-01-12 19:43:17 +01:00
2016-01-25 11:43:14 +01:00
static void Str_AnalyzeTxtAndStoreNotifyEventToMentionedUsrs (long PubCod,const char *Txt);
2015-12-29 14:24:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************** Show timeline including all the users I follow ***************/
2015-12-29 14:24:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_ShowTimelineGbl1 (void)
2017-02-24 03:38:18 +01:00
{
/***** Mark all my notifications about timeline as seen *****/
2019-03-12 21:25:55 +01:00
TL_MarkMyNotifAsSeen ();
2017-02-24 03:38:18 +01:00
/***** Get which users *****/
2019-11-12 00:31:41 +01:00
TL_GetParamWho ();
2019-02-21 20:04:05 +01:00
/***** Save which users in database *****/
if (Gbl.Action.Act == ActSeeSocTmlGbl) // Only in action to see global timeline
2019-03-12 21:25:55 +01:00
TL_SaveWhichUsersInDB ();
2017-02-24 03:38:18 +01:00
}
2019-03-12 21:25:55 +01:00
void TL_ShowTimelineGbl2 (void)
2015-12-29 14:24:37 +01:00
{
2016-01-25 14:40:57 +01:00
long PubCod;
2019-03-12 21:25:55 +01:00
struct TL_Note SocNot;
2016-01-25 14:40:57 +01:00
struct UsrData UsrDat;
Ntf_NotifyEvent_t NotifyEvent;
2019-11-21 11:39:30 +01:00
static const TL_TopMessage_t TopMessages[Ntf_NUM_NOTIFY_EVENTS] =
2016-01-25 17:23:14 +01:00
{
2019-11-20 01:47:22 +01:00
[Ntf_EVENT_UNKNOWN ] = TL_TOP_MESSAGE_NONE,
/* Start tab */
[Ntf_EVENT_TIMELINE_COMMENT ] = TL_TOP_MESSAGE_COMMENTED,
[Ntf_EVENT_TIMELINE_FAV ] = TL_TOP_MESSAGE_FAVED,
[Ntf_EVENT_TIMELINE_SHARE ] = TL_TOP_MESSAGE_SHARED,
[Ntf_EVENT_TIMELINE_MENTION ] = TL_TOP_MESSAGE_MENTIONED,
[Ntf_EVENT_FOLLOWER ] = TL_TOP_MESSAGE_NONE,
/* System tab */
/* Country tab */
/* Institution tab */
/* Centre tab */
/* Degree tab */
2016-01-25 17:23:14 +01:00
/* Course tab */
/* Assessment tab */
2019-11-20 01:47:22 +01:00
[Ntf_EVENT_ASSIGNMENT ] = TL_TOP_MESSAGE_NONE,
[Ntf_EVENT_SURVEY ] = TL_TOP_MESSAGE_NONE,
[Ntf_EVENT_EXAM_ANNOUNCEMENT] = TL_TOP_MESSAGE_NONE,
/* Files tab */
[Ntf_EVENT_DOCUMENT_FILE ] = TL_TOP_MESSAGE_NONE,
[Ntf_EVENT_TEACHERS_FILE ] = TL_TOP_MESSAGE_NONE,
[Ntf_EVENT_SHARED_FILE ] = TL_TOP_MESSAGE_NONE,
[Ntf_EVENT_MARKS_FILE ] = TL_TOP_MESSAGE_NONE,
/* Users tab */
[Ntf_EVENT_ENROLMENT_STD ] = TL_TOP_MESSAGE_NONE,
[Ntf_EVENT_ENROLMENT_NET ] = TL_TOP_MESSAGE_NONE,
[Ntf_EVENT_ENROLMENT_TCH ] = TL_TOP_MESSAGE_NONE,
[Ntf_EVENT_ENROLMENT_REQUEST] = TL_TOP_MESSAGE_NONE,
2016-01-25 17:23:14 +01:00
/* Messages tab */
2019-11-20 01:47:22 +01:00
[Ntf_EVENT_NOTICE ] = TL_TOP_MESSAGE_NONE,
[Ntf_EVENT_FORUM_POST_COURSE] = TL_TOP_MESSAGE_NONE,
[Ntf_EVENT_FORUM_REPLY ] = TL_TOP_MESSAGE_NONE,
[Ntf_EVENT_MESSAGE ] = TL_TOP_MESSAGE_NONE,
/* Analytics tab */
2016-01-25 17:23:14 +01:00
/* Profile tab */
};
2016-01-25 14:40:57 +01:00
2019-03-12 21:25:55 +01:00
/***** Initialize note code to -1 ==> no highlighted note *****/
2016-01-25 14:40:57 +01:00
SocNot.NotCod = -1L;
2019-03-12 21:25:55 +01:00
/***** Get parameter with the code of a publication *****/
2016-01-25 14:40:57 +01:00
// This parameter is optional. It can be provided by a notification.
2019-03-12 21:25:55 +01:00
// If > 0 ==> the note is shown highlighted above the timeline
PubCod = TL_GetParamPubCod ();
2016-01-25 14:40:57 +01:00
if (PubCod > 0)
2019-03-12 21:25:55 +01:00
/***** Get code of note from database *****/
SocNot.NotCod = TL_GetNotCodOfPublication (PubCod);
2016-01-25 14:40:57 +01:00
if (SocNot.NotCod > 0)
{
2019-11-25 13:29:56 +01:00
/* Get who did the action (publication, commenting, faving, sharing, mentioning) */
2016-01-25 14:40:57 +01:00
Usr_GetParamOtherUsrCodEncrypted (&UsrDat);
/* Get what he/she did */
NotifyEvent = Ntf_GetParamNotifyEvent ();
2019-03-12 21:25:55 +01:00
/***** Show the note highlighted *****/
TL_GetDataOfNoteByCod (&SocNot);
TL_WriteNote (&SocNot,
2019-03-13 00:54:35 +01:00
TopMessages[NotifyEvent],UsrDat.UsrCod,
true,true);
2016-01-25 14:40:57 +01:00
}
/***** Show timeline with possible highlighted note *****/
2019-03-12 21:25:55 +01:00
TL_ShowTimelineGblHighlightingNot (SocNot.NotCod);
2016-01-15 14:46:44 +01:00
}
2019-03-12 21:25:55 +01:00
static void TL_ShowTimelineGblHighlightingNot (long NotCod)
2016-01-15 14:46:44 +01:00
{
2017-02-27 19:52:04 +01:00
extern const char *Txt_Timeline;
2018-10-30 03:29:40 +01:00
char *Query = NULL;
2015-12-29 14:24:37 +01:00
2016-01-15 14:46:44 +01:00
/***** Build query to get timeline *****/
2019-03-12 21:25:55 +01:00
TL_BuildQueryToGetTimeline (&Query,
2019-03-13 00:54:35 +01:00
TL_TIMELINE_GBL,
TL_GET_RECENT_TIMELINE);
2015-12-29 14:24:37 +01:00
/***** Show timeline *****/
2019-03-12 21:25:55 +01:00
TL_ShowTimeline (Query,Txt_Timeline,NotCod);
2016-01-14 01:39:02 +01:00
/***** Drop temporary tables *****/
2019-03-12 21:25:55 +01:00
TL_DropTemporaryTablesUsedToQueryTimeline ();
2015-12-29 14:24:37 +01:00
}
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********************* Show timeline of a selected user **********************/
2015-12-29 14:24:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_ShowTimelineUsr (void)
2015-12-29 14:24:37 +01:00
{
2019-03-12 21:25:55 +01:00
TL_ShowTimelineUsrHighlightingNot (-1L);
2016-01-15 14:46:44 +01:00
}
2015-12-29 14:24:37 +01:00
2019-03-12 21:25:55 +01:00
static void TL_ShowTimelineUsrHighlightingNot (long NotCod)
2016-01-15 14:46:44 +01:00
{
2017-02-27 19:52:04 +01:00
extern const char *Txt_Timeline_OF_A_USER;
2018-10-30 03:29:40 +01:00
char *Query = NULL;
2016-01-08 10:27:58 +01:00
2019-03-06 10:13:39 +01:00
/***** Build query to show timeline with publications of a unique user *****/
2019-03-12 21:25:55 +01:00
TL_BuildQueryToGetTimeline (&Query,
2019-03-13 00:54:35 +01:00
TL_TIMELINE_USR,
TL_GET_RECENT_TIMELINE);
2016-01-10 03:10:40 +01:00
/***** Show timeline *****/
2019-12-30 21:47:07 +01:00
TL_ShowTimeline (Query,Str_BuildStringStr (Txt_Timeline_OF_A_USER,
Gbl.Usrs.Other.UsrDat.FirstName),
2019-12-30 18:08:31 +01:00
NotCod);
2019-12-30 21:47:07 +01:00
Str_FreeString ();
2016-01-10 03:10:40 +01:00
2016-01-13 00:24:26 +01:00
/***** Drop temporary tables *****/
2019-03-12 21:25:55 +01:00
TL_DropTemporaryTablesUsedToQueryTimeline ();
2016-01-10 03:10:40 +01:00
}
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************** Refresh new publications in timeline via AJAX ****************/
2016-01-14 01:39:02 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_RefreshNewTimelineGbl (void)
2016-01-10 03:10:40 +01:00
{
2018-10-30 03:29:40 +01:00
char *Query = NULL;
2017-02-06 01:23:33 +01:00
if (Gbl.Session.IsOpen) // If session has been closed, do not write anything
{
2017-02-24 03:38:18 +01:00
/***** Get which users *****/
2019-11-12 00:31:41 +01:00
TL_GetParamWho ();
2017-02-24 03:38:18 +01:00
2017-02-06 01:23:33 +01:00
/***** Build query to get timeline *****/
2019-03-12 21:25:55 +01:00
TL_BuildQueryToGetTimeline (&Query,
2019-03-13 00:54:35 +01:00
TL_TIMELINE_GBL,
TL_GET_ONLY_NEW_PUBS);
2016-01-10 03:10:40 +01:00
2017-02-06 01:23:33 +01:00
/***** Show new timeline *****/
2019-03-12 21:25:55 +01:00
TL_InsertNewPubsInTimeline (Query);
2017-02-06 01:23:33 +01:00
/***** Drop temporary tables *****/
2019-03-12 21:25:55 +01:00
TL_DropTemporaryTablesUsedToQueryTimeline ();
2017-02-06 01:23:33 +01:00
}
2016-01-14 01:39:02 +01:00
}
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/**************** View old publications in timeline via AJAX *****************/
2016-01-14 01:39:02 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_RefreshOldTimelineGbl (void)
2016-01-14 01:39:02 +01:00
{
2017-02-24 03:38:18 +01:00
/***** Get which users *****/
2019-11-12 00:31:41 +01:00
TL_GetParamWho ();
2017-02-24 03:38:18 +01:00
2019-03-06 10:13:39 +01:00
/***** Show old publications *****/
2019-03-12 21:25:55 +01:00
TL_GetAndShowOldTimeline (TL_TIMELINE_GBL);
2016-01-14 01:39:02 +01:00
}
2019-03-12 21:25:55 +01:00
void TL_RefreshOldTimelineUsr (void)
2016-01-14 01:39:02 +01:00
{
2017-02-17 10:17:39 +01:00
/***** Get user whom profile is displayed *****/
if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) // Existing user
2019-03-06 10:13:39 +01:00
/***** If user exists, show old publications *****/
2019-03-12 21:25:55 +01:00
TL_GetAndShowOldTimeline (TL_TIMELINE_USR);
2016-01-14 01:39:02 +01:00
}
2016-01-10 14:27:35 +01:00
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
/**************** Get and show old publications in timeline ******************/
2016-01-10 14:27:35 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_GetAndShowOldTimeline (TL_TimelineUsrOrGbl_t TimelineUsrOrGbl)
2016-01-10 14:27:35 +01:00
{
2018-10-30 03:29:40 +01:00
char *Query = NULL;
2016-01-10 14:27:35 +01:00
/***** Build query to get timeline *****/
2019-03-12 21:25:55 +01:00
TL_BuildQueryToGetTimeline (&Query,
2019-03-13 00:54:35 +01:00
TimelineUsrOrGbl,
TL_GET_ONLY_OLD_PUBS);
2016-01-10 14:27:35 +01:00
2016-01-10 16:57:02 +01:00
/***** Show old timeline *****/
2019-03-12 21:25:55 +01:00
TL_ShowOldPubsInTimeline (Query);
2016-01-10 14:27:35 +01:00
2016-01-13 00:24:26 +01:00
/***** Drop temporary tables *****/
2019-03-12 21:25:55 +01:00
TL_DropTemporaryTablesUsedToQueryTimeline ();
2016-01-10 14:27:35 +01:00
}
2016-01-25 21:48:08 +01:00
/*****************************************************************************/
/************ Mark all my notifications about timeline as seen ***************/
/*****************************************************************************/
2017-02-24 03:38:18 +01:00
// Must be executed as a priori function
2016-01-25 21:48:08 +01:00
2019-03-12 21:25:55 +01:00
void TL_MarkMyNotifAsSeen (void)
2016-01-25 21:48:08 +01:00
{
Ntf_MarkNotifAsSeen (Ntf_EVENT_TIMELINE_COMMENT,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
Ntf_MarkNotifAsSeen (Ntf_EVENT_TIMELINE_FAV ,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
Ntf_MarkNotifAsSeen (Ntf_EVENT_TIMELINE_SHARE ,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
Ntf_MarkNotifAsSeen (Ntf_EVENT_TIMELINE_MENTION,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
}
2016-01-10 03:10:40 +01:00
/*****************************************************************************/
/************************ Build query to get timeline ************************/
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
#define TL_MAX_BYTES_SUBQUERY_ALREADY_EXISTS (256 - 1)
2017-01-15 22:58:26 +01:00
2019-03-12 21:25:55 +01:00
static void TL_BuildQueryToGetTimeline (char **Query,
2019-03-13 00:54:35 +01:00
TL_TimelineUsrOrGbl_t TimelineUsrOrGbl,
TL_WhatToGetFromTimeline_t WhatToGetFromTimeline)
2016-01-10 03:10:40 +01:00
{
2016-01-14 01:39:02 +01:00
char SubQueryPublishers[128];
2016-01-17 21:22:01 +01:00
char SubQueryRangeBottom[128];
char SubQueryRangeTop[128];
2019-03-12 21:25:55 +01:00
char SubQueryAlreadyExists[TL_MAX_BYTES_SUBQUERY_ALREADY_EXISTS + 1];
2016-01-17 21:22:01 +01:00
struct
{
long Top;
long Bottom;
} RangePubsToGet;
2016-01-17 01:50:43 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2018-11-01 21:59:42 +01:00
unsigned NumPubs;
2016-01-17 01:50:43 +01:00
unsigned NumPub;
long PubCod;
long NotCod;
2019-11-22 01:04:03 +01:00
static const unsigned MaxPubsToGet[TL_NUM_WHAT_TO_GET_FROM_TIMELINE] =
2016-01-17 21:22:01 +01:00
{
2019-11-22 01:04:03 +01:00
[TL_GET_ONLY_NEW_PUBS ] = TL_MAX_NEW_PUBS_TO_GET_AND_SHOW,
[TL_GET_RECENT_TIMELINE] = TL_MAX_REC_PUBS_TO_GET_AND_SHOW,
[TL_GET_ONLY_OLD_PUBS ] = TL_MAX_OLD_PUBS_TO_GET_AND_SHOW,
2016-01-17 21:22:01 +01:00
};
2016-01-10 16:57:02 +01:00
2019-03-12 21:25:55 +01:00
/***** Clear timeline for this session in database *****/
if (WhatToGetFromTimeline == TL_GET_RECENT_TIMELINE)
TL_ClearTimelineThisSession ();
2016-01-13 00:45:16 +01:00
2016-01-13 00:24:26 +01:00
/***** Drop temporary tables *****/
2019-03-12 21:25:55 +01:00
TL_DropTemporaryTablesUsedToQueryTimeline ();
2016-01-13 00:24:26 +01:00
2019-03-06 10:13:39 +01:00
/***** Create temporary table with publication codes *****/
2018-11-02 22:41:02 +01:00
DB_Query ("can not create temporary table",
2019-11-25 13:29:56 +01:00
"CREATE TEMPORARY TABLE tl_pub_codes "
2018-11-02 22:41:02 +01:00
"(PubCod BIGINT NOT NULL,UNIQUE INDEX(PubCod)) ENGINE=MEMORY");
2016-01-17 01:50:43 +01:00
/***** Create temporary table with notes got in this execution *****/
2018-11-02 22:41:02 +01:00
DB_Query ("can not create temporary table",
2019-11-25 13:29:56 +01:00
"CREATE TEMPORARY TABLE tl_not_codes "
2018-11-02 22:41:02 +01:00
"(NotCod BIGINT NOT NULL,INDEX(NotCod)) ENGINE=MEMORY");
2016-01-17 01:50:43 +01:00
/***** Create temporary table with notes already present in timeline for this session *****/
2018-11-02 22:41:02 +01:00
DB_Query ("can not create temporary table",
2019-11-25 13:29:56 +01:00
"CREATE TEMPORARY TABLE tl_current_timeline "
2018-11-02 22:41:02 +01:00
"(NotCod BIGINT NOT NULL,INDEX(NotCod)) ENGINE=MEMORY"
2019-11-25 13:29:56 +01:00
" SELECT NotCod FROM tl_timelines WHERE SessionId='%s'",
2018-11-02 22:41:02 +01:00
Gbl.Session.Id);
2016-01-17 01:50:43 +01:00
2016-01-17 19:56:56 +01:00
/***** Create temporary table and subquery with potential publishers *****/
2016-01-14 01:39:02 +01:00
switch (TimelineUsrOrGbl)
{
2019-03-12 21:25:55 +01:00
case TL_TIMELINE_USR: // Show the timeline of a user
2017-03-24 01:09:27 +01:00
sprintf (SubQueryPublishers,"PublisherCod=%ld AND ",
2016-01-14 01:39:02 +01:00
Gbl.Usrs.Other.UsrDat.UsrCod);
2016-01-17 19:56:56 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_TIMELINE_GBL: // Show the global timeline
2019-11-12 00:31:41 +01:00
switch (Gbl.Timeline.Who)
2017-02-24 03:38:18 +01:00
{
2019-11-12 00:31:41 +01:00
case Usr_WHO_ME: // Show my timeline
sprintf (SubQueryPublishers,"PublisherCod=%ld AND ",
Gbl.Usrs.Me.UsrDat.UsrCod);
break;
case Usr_WHO_FOLLOWED: // Show the timeline of the users I follow
2018-11-02 22:41:02 +01:00
DB_Query ("can not create temporary table",
2019-11-25 13:29:56 +01:00
"CREATE TEMPORARY TABLE tl_publishers "
2018-11-02 22:41:02 +01:00
"(UsrCod INT NOT NULL,UNIQUE INDEX(UsrCod)) ENGINE=MEMORY"
" SELECT %ld AS UsrCod"
" UNION"
" SELECT FollowedCod AS UsrCod"
" FROM usr_follow WHERE FollowerCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
2018-10-29 12:31:24 +01:00
2019-11-25 13:29:56 +01:00
sprintf (SubQueryPublishers,
"tl_pubs.PublisherCod=tl_publishers.UsrCod AND ");
2017-02-24 03:38:18 +01:00
break;
2019-11-12 00:31:41 +01:00
case Usr_WHO_ALL: // Show the timeline of all users
2017-02-24 03:38:18 +01:00
SubQueryPublishers[0] = '\0';
break;
2019-02-21 20:04:05 +01:00
default:
Lay_ShowErrorAndExit ("Wrong parameter which users.");
break;
2017-02-24 03:38:18 +01:00
}
2016-01-17 19:56:56 +01:00
break;
}
2016-01-17 01:50:43 +01:00
2016-01-17 19:56:56 +01:00
/***** Create subquery to get only notes not present in timeline *****/
switch (TimelineUsrOrGbl)
{
2019-03-12 21:25:55 +01:00
case TL_TIMELINE_USR: // Show the timeline of a user
2016-01-17 02:25:59 +01:00
switch (WhatToGetFromTimeline)
{
2019-03-12 21:25:55 +01:00
case TL_GET_ONLY_NEW_PUBS:
case TL_GET_RECENT_TIMELINE:
2017-01-15 22:58:26 +01:00
Str_Copy (SubQueryAlreadyExists,
2017-02-24 03:38:18 +01:00
" NotCod NOT IN"
2019-11-25 13:29:56 +01:00
" (SELECT NotCod FROM tl_not_codes)",
2019-03-12 21:25:55 +01:00
TL_MAX_BYTES_SUBQUERY_ALREADY_EXISTS);
2016-01-17 02:25:59 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_GET_ONLY_OLD_PUBS:
2017-01-15 22:58:26 +01:00
Str_Copy (SubQueryAlreadyExists,
2017-02-24 03:38:18 +01:00
" NotCod NOT IN"
2019-11-25 13:29:56 +01:00
" (SELECT NotCod FROM tl_current_timeline)",
2019-03-12 21:25:55 +01:00
TL_MAX_BYTES_SUBQUERY_ALREADY_EXISTS);
2016-01-17 02:25:59 +01:00
break;
}
2016-01-14 01:39:02 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_TIMELINE_GBL: // Show the timeline of the users I follow
2016-01-17 02:25:59 +01:00
switch (WhatToGetFromTimeline)
{
2019-03-12 21:25:55 +01:00
case TL_GET_ONLY_NEW_PUBS:
case TL_GET_RECENT_TIMELINE:
2017-01-15 22:58:26 +01:00
Str_Copy (SubQueryAlreadyExists,
2019-11-25 13:29:56 +01:00
" tl_pubs.NotCod NOT IN"
" (SELECT NotCod FROM tl_not_codes)",
2019-03-12 21:25:55 +01:00
TL_MAX_BYTES_SUBQUERY_ALREADY_EXISTS);
2016-01-17 02:25:59 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_GET_ONLY_OLD_PUBS:
2017-01-15 22:58:26 +01:00
Str_Copy (SubQueryAlreadyExists,
2019-11-25 13:29:56 +01:00
" tl_pubs.NotCod NOT IN"
" (SELECT NotCod FROM tl_current_timeline)",
2019-03-12 21:25:55 +01:00
TL_MAX_BYTES_SUBQUERY_ALREADY_EXISTS);
2016-01-17 02:25:59 +01:00
break;
}
2016-01-14 01:39:02 +01:00
break;
}
2016-01-13 00:24:26 +01:00
2019-03-06 10:13:39 +01:00
/***** Get the publications in timeline *****/
2016-01-17 21:22:01 +01:00
/* Initialize range of pubs:
2019-11-25 13:29:56 +01:00
tl_pubs
2016-01-17 21:22:01 +01:00
_____
|_____|11
|_____|10
_|_____| 9 <-- RangePubsToGet.Top
Get / |_____| 8
pubs | |_____| 7
from < |_____| 6
this | |_____| 5
range \_|_____| 4
|_____| 3 <-- RangePubsToGet.Bottom
|_____| 2
|_____| 1
0
*/
2016-01-18 10:36:30 +01:00
RangePubsToGet.Top = 0; // +Infinite
RangePubsToGet.Bottom = 0; // -Infinite
2016-01-17 21:22:01 +01:00
switch (WhatToGetFromTimeline)
{
2019-03-12 21:25:55 +01:00
case TL_GET_ONLY_NEW_PUBS: // Get the publications (without limit) newer than LastPubCod
2016-01-17 21:22:01 +01:00
/* This query is made via AJAX automatically from time to time */
2019-03-12 21:25:55 +01:00
RangePubsToGet.Bottom = TL_GetPubCodFromSession ("LastPubCod");
2016-01-17 21:22:01 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_GET_RECENT_TIMELINE: // Get some limited recent publications
2016-01-17 21:22:01 +01:00
/* This is the first query to get initial timeline shown
==> no notes yet in current timeline table */
break;
2019-03-12 21:25:55 +01:00
case TL_GET_ONLY_OLD_PUBS: // Get some limited publications older than FirstPubCod
2016-01-17 21:22:01 +01:00
/* This query is made via AJAX
2019-03-06 10:13:39 +01:00
when I click in link to get old publications */
2019-03-12 21:25:55 +01:00
RangePubsToGet.Top = TL_GetPubCodFromSession ("FirstPubCod");
2016-01-17 21:22:01 +01:00
break;
}
2016-01-17 01:50:43 +01:00
/*
2016-01-17 20:06:25 +01:00
With the current approach, we select one by one
2019-03-06 10:13:39 +01:00
the publications and notes in a loop. In each iteration,
we get the more recent publication (original, shared or commment)
of every set of publications corresponding to the same note,
2016-01-17 21:22:01 +01:00
checking that the note is not already retrieved.
2019-03-06 10:13:39 +01:00
After getting a publication, its note code is stored
2016-01-17 21:22:01 +01:00
in order to not get it again.
2016-01-17 20:06:25 +01:00
As an alternative, we tried to get the maximum PubCod,
2019-03-06 10:13:39 +01:00
i.e more recent publication (original, shared or commment),
of every set of publications corresponding to the same note:
2019-11-25 13:29:56 +01:00
"SELECT MAX(PubCod) AS NewestPubCod FROM tl_pubs ...
2016-01-17 01:50:43 +01:00
" GROUP BY NotCod ORDER BY NewestPubCod DESC LIMIT ..."
2016-01-17 20:06:25 +01:00
but this query is slow (several seconds) with a big table.
2019-11-24 23:51:03 +01:00
*/
2019-03-20 01:36:36 +01:00
2016-01-17 01:50:43 +01:00
for (NumPub = 0;
2016-01-17 21:22:01 +01:00
NumPub < MaxPubsToGet[WhatToGetFromTimeline];
2016-01-17 01:50:43 +01:00
NumPub++)
{
2019-11-25 13:29:56 +01:00
/* Create subqueries with range of publications to get from tl_pubs */
2016-01-17 21:22:01 +01:00
if (RangePubsToGet.Bottom > 0)
2017-02-24 03:38:18 +01:00
switch (TimelineUsrOrGbl)
{
2019-03-12 21:25:55 +01:00
case TL_TIMELINE_USR: // Show the timeline of a user
2019-03-13 00:54:35 +01:00
sprintf (SubQueryRangeBottom,"PubCod>%ld AND ",
RangePubsToGet.Bottom);
2017-02-24 03:38:18 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_TIMELINE_GBL: // Show the global timeline
2019-11-12 00:31:41 +01:00
switch (Gbl.Timeline.Who)
2017-02-24 03:38:18 +01:00
{
2019-11-12 00:31:41 +01:00
case Usr_WHO_ME: // Show my timeline
case Usr_WHO_ALL: // Show the timeline of all users
sprintf (SubQueryRangeBottom,"PubCod>%ld AND ",
2019-03-12 21:25:55 +01:00
RangePubsToGet.Bottom);
2017-02-24 03:38:18 +01:00
break;
2019-11-12 00:31:41 +01:00
case Usr_WHO_FOLLOWED:// Show the timeline of the users I follow
2019-11-25 13:29:56 +01:00
sprintf (SubQueryRangeBottom,"tl_pubs.PubCod>%ld AND ",
2019-03-12 21:25:55 +01:00
RangePubsToGet.Bottom);
2017-02-24 03:38:18 +01:00
break;
2019-02-21 20:04:05 +01:00
default:
Lay_ShowErrorAndExit ("Wrong parameter which users.");
break;
2017-02-24 03:38:18 +01:00
}
break;
}
2016-01-17 21:22:01 +01:00
else
SubQueryRangeBottom[0] = '\0';
2017-02-24 03:38:18 +01:00
2016-01-17 21:22:01 +01:00
if (RangePubsToGet.Top > 0)
2017-02-24 03:38:18 +01:00
switch (TimelineUsrOrGbl)
{
2019-03-12 21:25:55 +01:00
case TL_TIMELINE_USR: // Show the timeline of a user
2019-03-13 00:54:35 +01:00
sprintf (SubQueryRangeTop,"PubCod<%ld AND ",
RangePubsToGet.Top);
2017-02-24 03:38:18 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_TIMELINE_GBL: // Show the global timeline
2019-11-12 00:31:41 +01:00
switch (Gbl.Timeline.Who)
2017-02-24 03:38:18 +01:00
{
2019-11-12 00:31:41 +01:00
case Usr_WHO_ME: // Show my timeline
case Usr_WHO_ALL: // Show the timeline of all users
sprintf (SubQueryRangeTop,"PubCod<%ld AND ",
2019-03-12 21:25:55 +01:00
RangePubsToGet.Top);
2017-02-24 03:38:18 +01:00
break;
2019-11-12 00:31:41 +01:00
case Usr_WHO_FOLLOWED:// Show the timeline of the users I follow
2019-11-25 13:29:56 +01:00
sprintf (SubQueryRangeTop,"tl_pubs.PubCod<%ld AND ",
2019-03-12 21:25:55 +01:00
RangePubsToGet.Top);
2017-02-24 03:38:18 +01:00
break;
2019-02-21 20:04:05 +01:00
default:
Lay_ShowErrorAndExit ("Wrong parameter which users.");
break;
2017-02-24 03:38:18 +01:00
}
break;
}
2016-01-17 21:22:01 +01:00
else
SubQueryRangeTop[0] = '\0';
2019-11-25 13:29:56 +01:00
/* Select the most recent publication from tl_pubs */
2018-11-09 20:47:39 +01:00
NumPubs = 0; // Initialized to avoid warning
2016-01-17 01:50:43 +01:00
switch (TimelineUsrOrGbl)
{
2019-03-12 21:25:55 +01:00
case TL_TIMELINE_USR: // Show the timeline of a user
2018-11-01 21:59:42 +01:00
NumPubs =
2019-03-06 10:13:39 +01:00
(unsigned) DB_QuerySELECT (&mysql_res,"can not get publication",
2019-03-12 21:25:55 +01:00
"SELECT PubCod,NotCod"
2019-11-25 13:29:56 +01:00
" FROM tl_pubs"
2018-11-01 21:59:42 +01:00
" WHERE %s%s%s%s"
" ORDER BY PubCod DESC LIMIT 1",
SubQueryRangeBottom,SubQueryRangeTop,
SubQueryPublishers,
SubQueryAlreadyExists);
2016-01-17 01:50:43 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_TIMELINE_GBL: // Show the global timeline
2019-11-12 00:31:41 +01:00
switch (Gbl.Timeline.Who)
2017-02-24 03:38:18 +01:00
{
2019-11-12 00:31:41 +01:00
case Usr_WHO_ME: // Show my timeline
NumPubs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get publication",
"SELECT PubCod,NotCod"
2019-11-25 13:29:56 +01:00
" FROM tl_pubs"
2019-11-12 00:31:41 +01:00
" WHERE %s%s%s%s"
" ORDER BY PubCod DESC LIMIT 1",
SubQueryRangeBottom,SubQueryRangeTop,
SubQueryPublishers,
SubQueryAlreadyExists);
break;
case Usr_WHO_FOLLOWED: // Show the timeline of the users I follow
2018-11-01 21:59:42 +01:00
NumPubs =
2019-03-06 10:13:39 +01:00
(unsigned) DB_QuerySELECT (&mysql_res,"can not get publication",
2019-03-12 21:25:55 +01:00
"SELECT PubCod,NotCod"
2019-11-25 13:29:56 +01:00
" FROM tl_pubs,tl_publishers"
2018-11-01 21:59:42 +01:00
" WHERE %s%s%s%s"
2019-11-25 13:29:56 +01:00
" ORDER BY tl_pubs.PubCod DESC LIMIT 1",
2018-11-01 21:59:42 +01:00
SubQueryRangeBottom,SubQueryRangeTop,
SubQueryPublishers,
SubQueryAlreadyExists);
2017-02-24 03:38:18 +01:00
break;
2019-11-12 00:31:41 +01:00
case Usr_WHO_ALL: // Show the timeline of all users
2018-11-01 21:59:42 +01:00
NumPubs =
2019-03-06 10:13:39 +01:00
(unsigned) DB_QuerySELECT (&mysql_res,"can not get publication",
2019-03-12 21:25:55 +01:00
"SELECT PubCod,NotCod"
2019-11-25 13:29:56 +01:00
" FROM tl_pubs"
2018-11-01 21:59:42 +01:00
" WHERE %s%s%s"
" ORDER BY PubCod DESC LIMIT 1",
SubQueryRangeBottom,SubQueryRangeTop,
SubQueryAlreadyExists);
2017-02-24 03:38:18 +01:00
break;
2019-02-21 20:04:05 +01:00
default:
Lay_ShowErrorAndExit ("Wrong parameter which users.");
break;
2017-02-24 03:38:18 +01:00
}
2016-01-17 01:50:43 +01:00
break;
}
2018-11-01 21:59:42 +01:00
if (NumPubs == 1)
2016-01-17 01:50:43 +01:00
{
2019-03-12 21:25:55 +01:00
/* Get code of publication */
2016-01-17 01:50:43 +01:00
row = mysql_fetch_row (mysql_res);
PubCod = Str_ConvertStrCodToLongCod (row[0]);
2016-01-23 01:38:55 +01:00
}
else
2018-11-09 21:02:52 +01:00
{
row = NULL;
2016-01-23 01:38:55 +01:00
PubCod = -1L;
2018-11-09 21:02:52 +01:00
}
2016-01-23 01:38:55 +01:00
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
if (PubCod > 0)
{
2019-03-06 10:13:39 +01:00
DB_QueryINSERT ("can not store publication code",
2019-11-25 13:29:56 +01:00
"INSERT INTO tl_pub_codes SET PubCod=%ld",
2018-11-02 19:37:11 +01:00
PubCod);
2016-01-17 21:22:01 +01:00
RangePubsToGet.Top = PubCod; // Narrow the range for the next iteration
2016-01-17 01:50:43 +01:00
2019-03-12 21:25:55 +01:00
/* Get note code (row[1]) */
2018-11-09 21:02:52 +01:00
if (row)
{
NotCod = Str_ConvertStrCodToLongCod (row[1]);
DB_QueryINSERT ("can not store note code",
2019-11-25 13:29:56 +01:00
"INSERT INTO tl_not_codes SET NotCod=%ld",
2018-11-09 21:02:52 +01:00
NotCod);
DB_QueryINSERT ("can not store note code",
2019-11-25 13:29:56 +01:00
"INSERT INTO tl_current_timeline SET NotCod=%ld",
2018-11-09 21:02:52 +01:00
NotCod);
}
2016-01-17 01:50:43 +01:00
}
2016-01-17 21:22:01 +01:00
else // Nothing got ==> abort loop
2019-03-06 10:13:39 +01:00
break; // Last publication
2016-01-10 03:10:40 +01:00
}
2016-01-08 10:27:58 +01:00
2019-03-06 10:13:39 +01:00
/***** Update last publication code into session for next refresh *****/
// Do this inmediately after getting the publications codes...
// ...in order to not lose publications
2019-03-12 21:25:55 +01:00
TL_UpdateLastPubCodIntoSession ();
2016-01-10 03:10:40 +01:00
2016-01-17 01:50:43 +01:00
/***** Add notes just retrieved to current timeline for this session *****/
2019-03-12 21:25:55 +01:00
TL_AddNotesJustRetrievedToTimelineThisSession ();
2016-01-17 01:50:43 +01:00
2016-01-08 10:27:58 +01:00
/***** Build query to show timeline including the users I am following *****/
2019-03-09 20:12:44 +01:00
DB_BuildQuery (Query,
"SELECT PubCod," // row[0]
"NotCod," // row[1]
"PublisherCod," // row[2]
"PubType," // row[3]
"UNIX_TIMESTAMP(TimePublish)" // row[4]
2019-11-25 13:29:56 +01:00
" FROM tl_pubs"
2019-03-09 20:12:44 +01:00
" WHERE PubCod IN "
"(SELECT PubCod"
2019-11-25 13:29:56 +01:00
" FROM tl_pub_codes)"
2019-03-09 20:12:44 +01:00
" ORDER BY PubCod DESC");
2016-01-10 03:10:40 +01:00
}
2016-01-08 10:27:58 +01:00
2016-01-10 03:10:40 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************* Get last/first publication code stored in session *************/
2016-01-10 03:10:40 +01:00
/*****************************************************************************/
2016-01-10 16:57:02 +01:00
// FieldName can be:
// "LastPubCod"
// "FirstPubCod"
2016-01-08 10:27:58 +01:00
2019-03-12 21:25:55 +01:00
static long TL_GetPubCodFromSession (const char *FieldName)
2016-01-10 03:10:40 +01:00
{
2019-03-04 14:36:29 +01:00
extern const char *Txt_The_session_has_expired;
2016-01-10 03:10:40 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-01-10 16:57:02 +01:00
long PubCod;
2016-01-10 03:10:40 +01:00
2019-03-06 10:13:39 +01:00
/***** Get last publication code from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get publication code from session",
2019-03-13 00:54:35 +01:00
"SELECT %s FROM sessions"
" WHERE SessionId='%s'",
2018-11-01 21:59:42 +01:00
FieldName,Gbl.Session.Id) != 1)
2019-03-04 14:36:29 +01:00
Lay_ShowErrorAndExit (Txt_The_session_has_expired);
2016-01-10 03:10:40 +01:00
2019-03-06 10:13:39 +01:00
/***** Get last publication code *****/
2016-01-10 03:10:40 +01:00
row = mysql_fetch_row (mysql_res);
2016-01-10 16:57:02 +01:00
if (sscanf (row[0],"%ld",&PubCod) != 1)
PubCod = 0;
2016-01-10 03:10:40 +01:00
2016-01-23 01:38:55 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-01-10 16:57:02 +01:00
return PubCod;
2015-12-29 14:24:37 +01:00
}
2016-01-09 21:55:06 +01:00
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
/*********************** Update last publication code ************************/
2016-01-09 21:55:06 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_UpdateLastPubCodIntoSession (void)
2016-01-09 21:55:06 +01:00
{
2019-03-06 10:13:39 +01:00
/***** Update last publication code *****/
DB_QueryUPDATE ("can not update last publication code into session",
2018-11-03 12:16:40 +01:00
"UPDATE sessions"
" SET LastPubCod="
2019-11-25 13:29:56 +01:00
"(SELECT IFNULL(MAX(PubCod),0) FROM tl_pubs)"
2018-11-03 12:16:40 +01:00
" WHERE SessionId='%s'",
Gbl.Session.Id);
2016-01-10 16:57:02 +01:00
}
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
/*********************** Update first publication code ***********************/
2016-01-10 16:57:02 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_UpdateFirstPubCodIntoSession (long FirstPubCod)
2016-01-10 16:57:02 +01:00
{
2019-03-06 10:13:39 +01:00
/***** Update last publication code *****/
DB_QueryUPDATE ("can not update first publication code into session",
2018-11-03 12:16:40 +01:00
"UPDATE sessions SET FirstPubCod=%ld WHERE SessionId='%s'",
FirstPubCod,Gbl.Session.Id);
2016-01-09 21:55:06 +01:00
}
2016-01-09 15:00:14 +01:00
/*****************************************************************************/
2016-01-13 00:24:26 +01:00
/*************** Drop temporary tables used to query timeline ****************/
2016-01-09 15:00:14 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_DropTemporaryTablesUsedToQueryTimeline (void)
2016-01-09 15:00:14 +01:00
{
2018-11-02 22:41:02 +01:00
DB_Query ("can not remove temporary tables",
2019-11-25 13:29:56 +01:00
"DROP TEMPORARY TABLE IF EXISTS "
"tl_pub_codes,"
"tl_not_codes,"
"tl_publishers,"
"tl_current_timeline");
2016-01-09 15:00:14 +01:00
}
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************************* Show timeline *******************************/
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
2016-01-17 21:22:01 +01:00
/* _____
/ |_____| just_now_timeline_list (Posts retrieved automatically
| |_____| via AJAX from time to time.
| |_____| They are transferred inmediately
2016-01-17 19:56:56 +01:00
| | to new_timeline_list.)
2016-01-17 21:22:01 +01:00
Hidden < __v__
| |_____| new_timeline_list (Posts retrieved but hidden.
| |_____| When user clicks to view them,
| |_____| they are transferred
\ |_____| to visible timeline_list.)
2016-01-17 19:56:56 +01:00
|
2016-01-17 21:22:01 +01:00
__v__
/ |_____| timeline_list (Posts visible on page)
| |_____|
Visible | |_____|
on < |_____|
page | |_____|
| |_____|
\ |_____|
2016-01-17 19:56:56 +01:00
^
2016-01-17 21:22:01 +01:00
__|__
/ |_____| old_timeline_list (Posts just retrieved via AJAX
| |_____| when user clicks "see more".
| |_____| They are transferred inmediately
Hidden < |_____| to timeline_list.)
| |_____|
| |_____|
\ |_____|
2016-01-17 19:56:56 +01:00
*/
2019-03-12 21:25:55 +01:00
static void TL_ShowTimeline (char *Query,
2019-03-13 10:23:41 +01:00
const char *Title,long NotCodToHighlight)
2015-12-28 19:23:42 +01:00
{
2019-03-12 21:25:55 +01:00
extern const char *Hlp_START_Timeline;
2015-12-28 19:23:42 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-01-11 00:27:04 +01:00
unsigned long NumPubsGot;
2015-12-31 18:40:45 +01:00
unsigned long NumPub;
2019-03-12 21:25:55 +01:00
struct TL_Publication SocPub;
struct TL_Note SocNot;
2017-02-24 03:38:18 +01:00
bool GlobalTimeline = (Gbl.Usrs.Other.UsrDat.UsrCod <= 0);
2018-10-10 23:56:42 +02:00
bool ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
2015-12-28 19:23:42 +01:00
2019-03-06 10:13:39 +01:00
/***** Get publications from database *****/
2018-11-14 23:40:56 +01:00
NumPubsGot = DB_QuerySELECT (&mysql_res,"can not get timeline",
"%s",
Query);
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Title,
2020-03-27 14:56:54 +01:00
TL_PutIconsTimeline,&Gbl,
2019-03-12 21:25:55 +01:00
Hlp_START_Timeline,Box_NOT_CLOSABLE);
2015-12-30 18:36:10 +01:00
2017-02-24 03:38:18 +01:00
/***** Put form to select users whom public activity is displayed *****/
if (GlobalTimeline)
2019-11-12 00:31:41 +01:00
TL_PutFormWho ();
2017-02-24 03:38:18 +01:00
2016-01-12 14:17:47 +01:00
/***** Form to write a new post *****/
2018-10-10 14:03:06 +02:00
if (GlobalTimeline || ItsMe)
2019-03-12 21:25:55 +01:00
TL_PutFormToWriteNewPost ();
2016-01-08 15:08:30 +01:00
2019-03-06 10:13:39 +01:00
/***** New publications refreshed dynamically via AJAX *****/
2017-02-24 03:38:18 +01:00
if (GlobalTimeline)
2016-01-14 14:24:20 +01:00
{
2019-03-06 10:13:39 +01:00
/* Link to view new publications via AJAX */
2019-03-12 21:25:55 +01:00
TL_PutLinkToViewNewPublications ();
2016-01-09 15:00:14 +01:00
2019-03-06 10:13:39 +01:00
/* Hidden list where insert just received (not visible) publications via AJAX */
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("id=\"just_now_timeline_list\" class=\"TL_LIST\"");
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2016-01-14 15:12:42 +01:00
2019-03-06 10:13:39 +01:00
/* Hidden list where insert new (not visible) publications via AJAX */
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("id=\"new_timeline_list\" class=\"TL_LIST\"");
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2016-01-14 14:24:20 +01:00
}
2016-01-10 14:27:35 +01:00
2019-03-06 10:13:39 +01:00
/***** List recent publications in timeline *****/
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("id=\"timeline_list\" class=\"TL_LIST\"");
2016-01-17 01:50:43 +01:00
2018-11-09 20:47:39 +01:00
for (NumPub = 0, SocPub.PubCod = 0;
2016-01-17 01:50:43 +01:00
NumPub < NumPubsGot;
2016-01-12 14:17:47 +01:00
NumPub++)
{
2019-03-12 21:25:55 +01:00
/* Get data of publication */
2016-01-12 14:17:47 +01:00
row = mysql_fetch_row (mysql_res);
2019-03-12 21:25:55 +01:00
TL_GetDataOfPublicationFromRow (row,&SocPub);
2015-12-28 19:23:42 +01:00
2019-03-12 21:25:55 +01:00
/* Get data of note */
2016-01-12 14:17:47 +01:00
SocNot.NotCod = SocPub.NotCod;
2019-03-12 21:25:55 +01:00
TL_GetDataOfNoteByCod (&SocNot);
2016-01-05 04:54:00 +01:00
2019-03-12 21:25:55 +01:00
/* Write note */
TL_WriteNote (&SocNot,
2019-03-13 00:54:35 +01:00
SocPub.TopMessage,SocPub.PublisherCod,
SocNot.NotCod == NotCodToHighlight,
false);
2016-01-12 14:17:47 +01:00
}
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2015-12-30 18:36:10 +01:00
2016-01-23 01:38:55 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2019-03-06 10:13:39 +01:00
/***** Store first publication code into session *****/
2019-03-12 21:25:55 +01:00
TL_UpdateFirstPubCodIntoSession (SocPub.PubCod);
2016-01-10 16:57:02 +01:00
2019-03-12 21:25:55 +01:00
if (NumPubsGot == TL_MAX_REC_PUBS_TO_GET_AND_SHOW)
2016-01-12 14:17:47 +01:00
{
2019-03-06 10:13:39 +01:00
/***** Link to view old publications via AJAX *****/
2019-03-12 21:25:55 +01:00
TL_PutLinkToViewOldPublications ();
2016-01-10 14:27:35 +01:00
2019-03-06 10:13:39 +01:00
/***** Hidden list where insert old publications via AJAX *****/
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("id=\"old_timeline_list\" class=\"TL_LIST\"");
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2016-01-12 14:17:47 +01:00
}
2016-01-10 14:27:35 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-01-10 03:10:40 +01:00
}
2016-11-07 10:40:27 +01:00
/*****************************************************************************/
/********************* Put contextual icons in timeline **********************/
/*****************************************************************************/
2020-03-26 02:54:30 +01:00
static void TL_PutIconsTimeline (void *Args)
2016-11-07 10:40:27 +01:00
{
2020-03-26 02:54:30 +01:00
if (Args)
/***** Put icon to show a figure *****/
2020-04-06 23:18:02 +02:00
Fig_PutIconToShowFigure (Fig_TIMELINE);
2016-11-07 10:40:27 +01:00
}
2017-02-24 10:34:21 +01:00
/*****************************************************************************/
/***************** Start a form in global or user timeline *******************/
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_FormStart (Act_Action_t ActionGbl,Act_Action_t ActionUsr)
2017-02-24 10:34:21 +01:00
{
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
2018-11-09 20:47:39 +01:00
Frm_StartFormAnchor (ActionUsr,"timeline");
2020-03-27 14:56:54 +01:00
Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
2017-02-24 10:34:21 +01:00
}
else
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActionGbl);
2019-11-12 00:31:41 +01:00
Usr_PutHiddenParamWho (Gbl.Timeline.Who);
2017-02-24 10:34:21 +01:00
}
}
2019-02-25 03:14:27 +01:00
/*****************************************************************************/
/******* Form to fav/unfav or share/unshare in global or user timeline *******/
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_FormFavSha (Act_Action_t ActionGbl,Act_Action_t ActionUsr,
2019-03-13 10:23:41 +01:00
const char *ParamCod,
const char *Icon,const char *Title)
2019-02-25 03:14:27 +01:00
{
char *OnSubmit;
2019-03-29 11:24:02 +01:00
/*
+---------------------------------------------------------------------------+
| div which content will be updated (parent of parent of form) |
| +---------------------+ +-------+ +-------------------------------------+ |
| | div (parent of form)| | div | | div for users | |
| | +-----------------+ | | for | | +------+ +------+ +------+ +------+ | |
| | | this form | | | num. | | | | | | | | | form | | |
| | | +-------------+ | | | of | | | user | | user | | user | | to | | |
| | | | fav icon | | | | users | | | 1 | | 2 | | 3 | | show | | |
| | | +-------------+ | | | | | | | | | | | | all | | |
| | +-----------------+ | | | | +------+ +------+ +------+ +------+ | |
| +---------------------+ +-------+ +-------------------------------------+ |
+---------------------------------------------------------------------------+
*/
2019-03-12 21:25:55 +01:00
/***** Form and icon to mark note as favourite *****/
2019-02-25 03:14:27 +01:00
/* Form with icon */
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
2019-03-29 11:24:02 +01:00
if (asprintf (&OnSubmit,"updateDivFaversSharers(this,"
2019-02-25 03:14:27 +01:00
"'act=%ld&ses=%s&%s&OtherUsrCod=%s');"
" return false;", // return false is necessary to not submit form
Act_GetActCod (ActionUsr),
Gbl.Session.Id,
ParamCod,
Gbl.Usrs.Other.UsrDat.EncryptedUsrCod) < 0)
Lay_NotEnoughMemoryExit ();
Frm_StartFormUniqueAnchorOnSubmit (ActUnk,"timeline",OnSubmit);
}
else
{
2019-03-29 11:24:02 +01:00
if (asprintf (&OnSubmit,"updateDivFaversSharers(this,"
2019-02-25 03:14:27 +01:00
"'act=%ld&ses=%s&%s');"
" return false;", // return false is necessary to not submit form
Act_GetActCod (ActionGbl),
Gbl.Session.Id,
ParamCod) < 0)
Lay_NotEnoughMemoryExit ();
Frm_StartFormUniqueAnchorOnSubmit (ActUnk,NULL,OnSubmit);
}
Ico_PutIconLink (Icon,Title);
Frm_EndForm ();
2019-12-13 23:38:29 +01:00
/* Free allocated memory */
2019-11-06 19:45:20 +01:00
free (OnSubmit);
2019-02-25 03:14:27 +01:00
}
2017-02-24 03:38:18 +01:00
/*****************************************************************************/
2019-02-21 21:12:04 +01:00
/******** Show form to select users whom public activity is displayed ********/
2017-02-24 03:38:18 +01:00
/*****************************************************************************/
2019-11-12 00:31:41 +01:00
static void TL_PutFormWho (void)
2017-02-24 03:38:18 +01:00
{
2019-11-12 00:31:41 +01:00
Usr_Who_t Who;
unsigned Mask = 1 << Usr_WHO_ME |
1 << Usr_WHO_FOLLOWED |
1 << Usr_WHO_ALL;
2017-02-24 03:38:18 +01:00
2019-03-26 11:53:21 +01:00
/***** Setting selector for which users *****/
Set_StartSettingsHead ();
Set_StartOneSettingSelector ();
2019-11-12 00:31:41 +01:00
for (Who = (Usr_Who_t) 0;
Who <= (Usr_Who_t) (Usr_NUM_WHO - 1);
Who++)
if (Mask & (1 << Who))
{
HTM_DIV_Begin ("class=\"%s\"",
Who == Gbl.Timeline.Who ? "PREF_ON" :
"PREF_OFF");
Frm_StartForm (ActSeeSocTmlGbl);
Par_PutHiddenParamUnsigned (NULL,"Who",(unsigned) Who);
Usr_PutWhoIcon (Who);
Frm_EndForm ();
HTM_DIV_End ();
}
2019-03-26 11:53:21 +01:00
Set_EndOneSettingSelector ();
Set_EndSettingsHead ();
2017-02-24 11:01:28 +01:00
/***** Show warning if I do not follow anyone *****/
2019-11-12 00:31:41 +01:00
if (Gbl.Timeline.Who == Usr_WHO_FOLLOWED)
2019-03-12 21:25:55 +01:00
TL_ShowWarningYouDontFollowAnyUser ();
2017-02-24 03:38:18 +01:00
}
/*****************************************************************************/
/********* Get parameter with which users to view in global timeline *********/
/*****************************************************************************/
2019-11-12 00:31:41 +01:00
static void TL_GetParamWho (void)
2017-02-24 03:38:18 +01:00
{
/***** Get which users I want to see *****/
2019-11-12 00:31:41 +01:00
Gbl.Timeline.Who = Usr_GetHiddenParamWho ();
/***** If parameter Who is not present, get it from database *****/
if (Gbl.Timeline.Who == Usr_WHO_UNKNOWN)
Gbl.Timeline.Who = TL_GetWhoFromDB ();
/***** If parameter Who is unknown, set it to default *****/
if (Gbl.Timeline.Who == Usr_WHO_UNKNOWN)
Gbl.Timeline.Who = TL_DEFAULT_WHO;
2019-02-21 20:04:05 +01:00
}
/*****************************************************************************/
/********** Get user's last data from database giving a user's code **********/
/*****************************************************************************/
2019-11-12 00:31:41 +01:00
static Usr_Who_t TL_GetWhoFromDB (void)
2019-02-21 20:04:05 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned UnsignedNum;
2019-11-12 00:31:41 +01:00
Usr_Who_t Who = Usr_WHO_UNKNOWN;
2019-02-21 20:04:05 +01:00
/***** Get which users from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get timeline users from user's last data",
"SELECT TimelineUsrs" // row[0]
" FROM usr_last WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod) == 1)
{
row = mysql_fetch_row (mysql_res);
2019-11-12 00:31:41 +01:00
/* Get who */
2019-02-21 20:04:05 +01:00
if (sscanf (row[0],"%u",&UnsignedNum) == 1)
2019-11-12 00:31:41 +01:00
if (UnsignedNum < Usr_NUM_WHO)
Who = (Usr_Who_t) UnsignedNum;
2019-02-21 20:04:05 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2019-11-12 00:31:41 +01:00
return Who;
2019-02-21 20:04:05 +01:00
}
/*****************************************************************************/
/********************** Save which users into database ***********************/
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_SaveWhichUsersInDB (void)
2019-02-21 20:04:05 +01:00
{
if (Gbl.Usrs.Me.Logged)
{
2019-11-12 00:31:41 +01:00
if (Gbl.Timeline.Who == Usr_WHO_UNKNOWN)
Gbl.Timeline.Who = TL_DEFAULT_WHO;
2019-02-21 20:04:05 +01:00
/***** Update which users in database *****/
2019-11-12 00:31:41 +01:00
// Who is stored in usr_last for next time I log in
2019-02-21 20:04:05 +01:00
DB_QueryUPDATE ("can not update timeline users in user's last data",
2019-04-01 11:15:38 +02:00
"UPDATE usr_last SET TimelineUsrs=%u"
" WHERE UsrCod=%ld",
2019-11-12 00:31:41 +01:00
(unsigned) Gbl.Timeline.Who,
2019-02-21 20:04:05 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod);
}
2017-02-24 03:38:18 +01:00
}
2017-02-24 11:01:28 +01:00
/*****************************************************************************/
/********* Get parameter with which users to view in global timeline *********/
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_ShowWarningYouDontFollowAnyUser (void)
2017-02-24 11:01:28 +01:00
{
extern const char *Txt_You_dont_follow_any_user;
2019-02-22 14:04:54 +01:00
unsigned NumFollowing;
unsigned NumFollowers;
2017-02-24 11:01:28 +01:00
/***** Check if I follow someone *****/
2019-02-22 14:04:54 +01:00
Fol_GetNumFollow (Gbl.Usrs.Me.UsrDat.UsrCod,&NumFollowing,&NumFollowers);
if (!NumFollowing)
2017-02-24 11:01:28 +01:00
{
/***** Show warning if I do not follow anyone *****/
2019-02-16 18:25:41 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_dont_follow_any_user);
2017-02-24 11:01:28 +01:00
2019-10-24 09:46:20 +02:00
/***** Contextual menu *****/
Mnu_ContextMenuBegin ();
Fol_PutLinkWhoToFollow (); // Users to follow
Mnu_ContextMenuEnd ();
2017-02-24 11:01:28 +01:00
}
}
2016-01-10 03:10:40 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************* Show new publications in timeline ***********************/
2016-01-10 03:10:40 +01:00
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
// The publications are inserted as list elements of a hidden list
2016-01-09 21:55:06 +01:00
2019-03-12 21:25:55 +01:00
static void TL_InsertNewPubsInTimeline (char *Query)
2016-01-10 03:10:40 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-01-11 00:27:04 +01:00
unsigned long NumPubsGot;
2016-01-10 03:10:40 +01:00
unsigned long NumPub;
2019-03-12 21:25:55 +01:00
struct TL_Publication SocPub;
struct TL_Note SocNot;
2016-01-10 03:10:40 +01:00
2019-03-06 10:13:39 +01:00
/***** Get new publications timeline from database *****/
2018-11-14 23:40:56 +01:00
NumPubsGot = DB_QuerySELECT (&mysql_res,"can not get timeline",
"%s",
Query);
2016-01-10 03:10:40 +01:00
2019-03-06 10:13:39 +01:00
/***** List new publications timeline *****/
2016-01-10 03:10:40 +01:00
for (NumPub = 0;
2016-01-11 00:27:04 +01:00
NumPub < NumPubsGot;
2016-01-10 03:10:40 +01:00
NumPub++)
{
2019-03-12 21:25:55 +01:00
/* Get data of publication */
2016-01-10 03:10:40 +01:00
row = mysql_fetch_row (mysql_res);
2019-03-12 21:25:55 +01:00
TL_GetDataOfPublicationFromRow (row,&SocPub);
2016-01-10 03:10:40 +01:00
2019-03-12 21:25:55 +01:00
/* Get data of note */
2016-01-10 03:10:40 +01:00
SocNot.NotCod = SocPub.NotCod;
2019-03-12 21:25:55 +01:00
TL_GetDataOfNoteByCod (&SocNot);
2016-01-10 03:10:40 +01:00
2019-03-12 21:25:55 +01:00
/* Write note */
TL_WriteNote (&SocNot,
2019-03-13 00:54:35 +01:00
SocPub.TopMessage,SocPub.PublisherCod,
false,false);
2016-01-10 03:10:40 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-01-10 16:57:02 +01:00
}
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********************* Show old publications in timeline *********************/
2016-01-10 16:57:02 +01:00
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
// The publications are inserted as list elements of a hidden list
2016-01-10 16:57:02 +01:00
2019-03-12 21:25:55 +01:00
static void TL_ShowOldPubsInTimeline (char *Query)
2016-01-10 16:57:02 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-01-11 00:27:04 +01:00
unsigned long NumPubsGot;
2016-01-10 16:57:02 +01:00
unsigned long NumPub;
2019-03-12 21:25:55 +01:00
struct TL_Publication SocPub;
struct TL_Note SocNot;
2016-01-10 16:57:02 +01:00
2019-03-06 10:13:39 +01:00
/***** Get old publications timeline from database *****/
2018-11-14 23:40:56 +01:00
NumPubsGot = DB_QuerySELECT (&mysql_res,"can not get timeline",
"%s",
Query);
2016-01-10 16:57:02 +01:00
2019-03-06 10:13:39 +01:00
/***** List old publications in timeline *****/
2018-11-09 20:47:39 +01:00
for (NumPub = 0, SocPub.PubCod = 0;
2016-01-17 01:50:43 +01:00
NumPub < NumPubsGot;
NumPub++)
2016-01-10 16:57:02 +01:00
{
2019-03-12 21:25:55 +01:00
/* Get data of publication */
2016-01-17 01:50:43 +01:00
row = mysql_fetch_row (mysql_res);
2019-03-12 21:25:55 +01:00
TL_GetDataOfPublicationFromRow (row,&SocPub);
2016-01-12 20:58:19 +01:00
2019-03-12 21:25:55 +01:00
/* Get data of note */
2016-01-17 01:50:43 +01:00
SocNot.NotCod = SocPub.NotCod;
2019-03-12 21:25:55 +01:00
TL_GetDataOfNoteByCod (&SocNot);
2016-01-10 16:57:02 +01:00
2019-03-12 21:25:55 +01:00
/* Write note */
TL_WriteNote (&SocNot,
2019-03-13 00:54:35 +01:00
SocPub.TopMessage,SocPub.PublisherCod,
false,false);
2016-01-10 16:57:02 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-01-23 01:38:55 +01:00
2019-03-06 10:13:39 +01:00
/***** Store first publication code into session *****/
2019-03-12 21:25:55 +01:00
TL_UpdateFirstPubCodIntoSession (SocPub.PubCod);
2015-12-28 19:23:42 +01:00
}
2016-01-09 19:06:01 +01:00
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
/***************** Put link to view new publications in timeline *************/
2016-01-09 19:06:01 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_PutLinkToViewNewPublications (void)
2016-01-09 19:06:01 +01:00
{
2019-02-24 15:15:43 +01:00
extern const char *The_ClassFormInBoxBold[The_NUM_THEMES];
2016-01-09 20:11:44 +01:00
extern const char *Txt_See_new_activity;
2016-01-09 19:06:01 +01:00
2019-03-06 10:13:39 +01:00
/***** Link to view (show hidden) new publications *****/
2016-01-09 20:11:44 +01:00
// div is hidden. When new posts arrive to the client via AJAX, div is shown
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"view_new_posts_container\""
" class=\"TL_WIDTH TL_SEP VERY_LIGHT_BLUE\""
" style=\"display:none;\"");
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"\" class=\"%s\""
" onclick=\"moveNewTimelineToTimeline();return false;\"",
The_ClassFormInBoxBold[Gbl.Prefs.Theme]);
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%s (",Txt_See_new_activity);
2019-11-07 10:24:00 +01:00
HTM_SPAN_Begin ("id=\"view_new_posts_count\"");
2019-11-10 13:51:07 +01:00
HTM_Unsigned (0);
2019-11-07 10:24:00 +01:00
HTM_SPAN_End ();
2019-11-10 13:51:07 +01:00
HTM_Txt (")");
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-09 19:06:01 +01:00
}
2016-01-10 14:27:35 +01:00
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
/***************** Put link to view old publications in timeline *************/
2016-01-10 14:27:35 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_PutLinkToViewOldPublications (void)
2016-01-10 14:27:35 +01:00
{
2019-02-24 15:15:43 +01:00
extern const char *The_ClassFormInBoxBold[The_NUM_THEMES];
2016-01-10 14:27:35 +01:00
extern const char *Txt_See_more;
2019-03-06 10:13:39 +01:00
/***** Animated link to view old publications *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"view_old_posts_container\""
" class=\"TL_WIDTH TL_SEP VERY_LIGHT_BLUE\"");
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"\" class=\"%s\" onclick=\""
"document.getElementById('get_old_timeline').style.display='none';" // Icon to be hidden on click
"document.getElementById('getting_old_timeline').style.display='';" // Icon to be shown on click
"refreshOldTimeline();"
"return false;\"",
The_ClassFormInBoxBold[Gbl.Prefs.Theme]);
2019-10-30 00:42:01 +01:00
HTM_IMG (Cfg_URL_ICON_PUBLIC,"recycle16x16.gif","Txt_See_more",
2019-10-30 22:31:03 +01:00
"class=\"ICO20x20\" id=\"get_old_timeline\"");
2019-10-30 00:42:01 +01:00
HTM_IMG (Cfg_URL_ICON_PUBLIC,"working16x16.gif",Txt_See_more,
2019-10-30 22:31:03 +01:00
"class=\"ICO20x20\" style=\"display:none;\" id=\"getting_old_timeline\""); // Animated icon hidden
2019-10-30 00:42:01 +01:00
HTM_IMG (Cfg_URL_ICON_PUBLIC,"recycle16x16.gif","Txt_See_more",
2019-10-30 22:31:03 +01:00
"class=\"ICO20x20\" style=\"display:none;\" id=\"get_old_timeline\"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%s",Txt_See_more);
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-10 14:27:35 +01:00
}
2015-12-30 16:33:36 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************************** Write note *********************************/
2015-12-30 16:33:36 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_WriteNote (const struct TL_Note *SocNot,
TL_TopMessage_t TopMessage,long UsrCod,
bool Highlight, // Highlight note
bool ShowNoteAlone) // Note is shown alone, not in a list
2015-12-30 16:33:36 +01:00
{
extern const char *Txt_Forum;
extern const char *Txt_Course;
extern const char *Txt_Degree;
extern const char *Txt_Centre;
extern const char *Txt_Institution;
2016-01-02 14:56:38 +01:00
struct UsrData UsrDat;
2019-03-28 19:55:40 +01:00
bool IAmTheAuthor;
2016-10-28 10:03:37 +02:00
struct Instit Ins;
2015-12-30 16:33:36 +01:00
struct Centre Ctr;
struct Degree Deg;
struct Course Crs;
bool ShowPhoto = false;
2017-01-28 15:58:46 +01:00
char PhotoURL[PATH_MAX + 1];
2020-04-07 03:01:41 +02:00
struct For_Forums Forums;
2017-01-13 10:49:56 +01:00
char ForumName[For_MAX_BYTES_FORUM_NAME + 1];
2017-03-08 14:12:33 +01:00
char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1];
2016-01-08 02:55:18 +01:00
unsigned NumComments;
2018-11-09 20:47:39 +01:00
char IdNewComment[Frm_MAX_BYTES_ID + 1];
2019-02-25 02:02:10 +01:00
static unsigned NumDiv = 0; // Used to create unique div id for fav and shared
NumDiv++;
2015-12-30 16:33:36 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box ****/
2016-01-11 00:53:21 +01:00
if (ShowNoteAlone)
2016-01-05 21:30:10 +01:00
{
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,NULL,
NULL,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_CLOSABLE);
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("class=\"TL_LIST\"");
2016-01-05 21:30:10 +01:00
}
2015-12-30 16:33:36 +01:00
/***** Start list item *****/
2019-10-26 22:49:13 +02:00
HTM_LI_Begin ("class=\"%s\"",
ShowNoteAlone ? (Highlight ? "TL_WIDTH TL_NEW_PUB" :
"TL_WIDTH") :
(Highlight ? "TL_WIDTH TL_SEP TL_NEW_PUB" :
"TL_WIDTH TL_SEP"));
2015-12-30 16:33:36 +01:00
2016-01-11 19:28:43 +01:00
if (SocNot->NotCod <= 0 ||
2019-03-12 21:25:55 +01:00
SocNot->NoteType == TL_NOTE_UNKNOWN ||
2016-01-11 19:28:43 +01:00
SocNot->UsrCod <= 0)
2019-03-12 21:25:55 +01:00
Ale_ShowAlert (Ale_ERROR,"Error in note.");
2016-01-05 04:54:00 +01:00
else
{
/***** Initialize location in hierarchy *****/
Ins.InsCod = -1L;
Ctr.CtrCod = -1L;
Deg.DegCod = -1L;
Crs.CrsCod = -1L;
2016-01-13 02:03:56 +01:00
/***** Write sharer/commenter if distinct to author *****/
2019-03-12 21:25:55 +01:00
TL_WriteTopMessage (TopMessage,UsrCod);
2016-01-13 12:59:23 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
2016-01-13 02:03:56 +01:00
/***** Get author data *****/
2016-01-05 04:54:00 +01:00
UsrDat.UsrCod = SocNot->UsrCod;
2019-03-19 13:22:14 +01:00
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS);
2019-03-28 19:55:40 +01:00
IAmTheAuthor = Usr_ItsMe (UsrDat.UsrCod);
2015-12-30 16:33:36 +01:00
2016-01-05 04:54:00 +01:00
/***** Left: write author's photo *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_LEFT_PHOTO\"");
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (&UsrDat,PhotoURL);
2016-01-05 04:54:00 +01:00
Pho_ShowUsrPhoto (&UsrDat,ShowPhoto ? PhotoURL :
NULL,
2019-03-29 11:24:02 +01:00
"PHOTO45x60",Pho_ZOOM,true); // Use unique id
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2015-12-30 16:33:36 +01:00
2016-01-05 04:54:00 +01:00
/***** Right: author's name, time, summary and buttons *****/
2019-11-20 10:17:42 +01:00
/* Begin right container */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_RIGHT_CONT TL_RIGHT_WIDTH\"");
2015-12-30 16:33:36 +01:00
2019-11-20 10:17:42 +01:00
/* Write author's full name and date-time */
2019-03-12 21:25:55 +01:00
TL_WriteAuthorNote (&UsrDat);
TL_WriteDateTime (SocNot->DateTimeUTC);
2016-01-02 17:07:58 +01:00
2016-01-05 04:54:00 +01:00
/* Write content of the note */
2019-03-12 21:25:55 +01:00
if (SocNot->NoteType == TL_NOTE_POST)
2016-01-05 04:54:00 +01:00
/* Write post content */
2019-03-12 21:25:55 +01:00
TL_GetAndWritePost (SocNot->Cod);
2016-01-05 04:54:00 +01:00
else
{
2020-04-07 03:01:41 +02:00
/* Reset forums */
For_ResetForums (&Forums);
2016-01-05 04:54:00 +01:00
/* Get location in hierarchy */
if (!SocNot->Unavailable)
switch (SocNot->NoteType)
{
2019-03-12 21:25:55 +01:00
case TL_NOTE_INS_DOC_PUB_FILE:
case TL_NOTE_INS_SHA_PUB_FILE:
2016-01-05 04:54:00 +01:00
/* Get institution data */
Ins.InsCod = SocNot->HieCod;
2020-01-07 00:09:30 +01:00
Ins_GetDataOfInstitutionByCod (&Ins);
2016-01-05 04:54:00 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_CTR_DOC_PUB_FILE:
case TL_NOTE_CTR_SHA_PUB_FILE:
2016-01-05 04:54:00 +01:00
/* Get centre data */
Ctr.CtrCod = SocNot->HieCod;
2020-01-05 02:18:20 +01:00
Ctr_GetDataOfCentreByCod (&Ctr);
2016-01-05 04:54:00 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_DEG_DOC_PUB_FILE:
case TL_NOTE_DEG_SHA_PUB_FILE:
2016-01-05 04:54:00 +01:00
/* Get degree data */
Deg.DegCod = SocNot->HieCod;
2020-01-05 12:52:03 +01:00
Deg_GetDataOfDegreeByCod (&Deg);
2016-01-05 04:54:00 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_CRS_DOC_PUB_FILE:
case TL_NOTE_CRS_SHA_PUB_FILE:
case TL_NOTE_EXAM_ANNOUNCEMENT:
case TL_NOTE_NOTICE:
2016-01-05 04:54:00 +01:00
/* Get course data */
Crs.CrsCod = SocNot->HieCod;
2020-01-05 14:09:28 +01:00
Crs_GetDataOfCourseByCod (&Crs);
2016-01-05 04:54:00 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_FORUM_POST:
2016-01-05 04:54:00 +01:00
/* Get forum type of the post */
2020-04-07 03:01:41 +02:00
For_GetForumTypeAndLocationOfAPost (SocNot->Cod,&Forums.ForumSelected);
For_SetForumName (&Forums.ForumSelected,ForumName,Gbl.Prefs.Language,false); // Set forum name in recipient's language
2016-01-05 04:54:00 +01:00
break;
default:
break;
}
/* Write note type */
2020-04-07 03:01:41 +02:00
TL_PutFormGoToAction (SocNot,&Forums);
2016-01-05 04:54:00 +01:00
/* Write location in hierarchy */
if (!SocNot->Unavailable)
switch (SocNot->NoteType)
{
2019-03-12 21:25:55 +01:00
case TL_NOTE_INS_DOC_PUB_FILE:
case TL_NOTE_INS_SHA_PUB_FILE:
2016-01-05 04:54:00 +01:00
/* Write location (institution) in hierarchy */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_LOC\"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:&nbsp;%s",Txt_Institution,Ins.ShrtName);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-05 04:54:00 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_CTR_DOC_PUB_FILE:
case TL_NOTE_CTR_SHA_PUB_FILE:
2016-01-05 04:54:00 +01:00
/* Write location (centre) in hierarchy */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_LOC\"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:&nbsp;%s",Txt_Centre,Ctr.ShrtName);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-05 04:54:00 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_DEG_DOC_PUB_FILE:
case TL_NOTE_DEG_SHA_PUB_FILE:
2016-01-05 04:54:00 +01:00
/* Write location (degree) in hierarchy */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_LOC\"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:&nbsp;%s",Txt_Degree,Deg.ShrtName);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-05 04:54:00 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_CRS_DOC_PUB_FILE:
case TL_NOTE_CRS_SHA_PUB_FILE:
case TL_NOTE_EXAM_ANNOUNCEMENT:
case TL_NOTE_NOTICE:
2016-01-05 04:54:00 +01:00
/* Write location (course) in hierarchy */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_LOC\"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:&nbsp;%s",Txt_Course,Crs.ShrtName);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-05 04:54:00 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_FORUM_POST:
2016-01-05 04:54:00 +01:00
/* Write forum name */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_LOC\"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:&nbsp;%s",Txt_Forum,ForumName);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-05 04:54:00 +01:00
break;
default:
break;
}
2015-12-30 16:33:36 +01:00
2016-01-05 04:54:00 +01:00
/* Write note summary */
2019-03-12 21:25:55 +01:00
TL_GetNoteSummary (SocNot,SummaryStr);
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_TXT\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (SummaryStr);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-05 04:54:00 +01:00
}
2019-11-20 10:17:42 +01:00
/* End right container */
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-20 02:35:27 +01:00
2019-11-20 10:17:42 +01:00
/***** Buttons and comments *****/
2016-01-11 19:28:43 +01:00
/* Create unique id for new comment */
2018-11-09 20:47:39 +01:00
Frm_SetUniqueId (IdNewComment);
2016-01-11 19:28:43 +01:00
2019-03-12 21:25:55 +01:00
/* Get number of comments in this note */
NumComments = TL_GetNumCommentsInNote (SocNot->NotCod);
2016-01-08 02:55:18 +01:00
/* Put icon to add a comment */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_BOTTOM_LEFT\"");
2019-03-12 21:25:55 +01:00
if (SocNot->Unavailable) // Unavailable notes can not be commented
TL_PutIconCommentDisabled ();
2016-01-19 02:08:44 +01:00
else
2019-03-12 21:25:55 +01:00
TL_PutIconToToggleCommentNote (IdNewComment);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2015-12-30 16:33:36 +01:00
2019-03-29 11:24:02 +01:00
/* Start container for buttons and comments */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_BOTTOM_RIGHT TL_RIGHT_WIDTH\"");
2016-01-04 14:49:10 +01:00
2019-03-29 11:24:02 +01:00
/* Start foot container */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_FOOT TL_RIGHT_WIDTH\"");
2019-03-29 00:57:51 +01:00
2019-03-29 15:12:51 +01:00
/* Foot column 1: Fav zone */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"fav_not_%s_%u\" class=\"TL_FAV_NOT TL_FAV_NOT_WIDTH\"",
Gbl.UniqueNameEncrypted,NumDiv);
2019-03-29 01:23:33 +01:00
TL_PutFormToFavUnfNote (SocNot,TL_SHOW_A_FEW_USRS);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-19 00:50:35 +01:00
2019-03-29 15:12:51 +01:00
/* Foot column 2: Share zone */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"sha_not_%s_%u\" class=\"TL_SHA_NOT TL_SHA_NOT_WIDTH\"",
Gbl.UniqueNameEncrypted,NumDiv);
2019-03-29 01:23:33 +01:00
TL_PutFormToShaUnsNote (SocNot,TL_SHOW_A_FEW_USRS);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-20 02:35:27 +01:00
2019-03-29 15:12:51 +01:00
/* Foot column 3: Icon to remove this note */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_REM\"");
2016-01-17 02:49:39 +01:00
if (IAmTheAuthor)
2019-03-12 21:25:55 +01:00
TL_PutFormToRemovePublication (SocNot->NotCod);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-03-29 00:57:51 +01:00
2019-03-29 11:24:02 +01:00
/* End foot container */
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-20 02:35:27 +01:00
2019-11-20 10:17:42 +01:00
/* Comments */
2016-01-11 19:28:43 +01:00
if (NumComments)
2019-11-18 08:38:34 +01:00
TL_WriteCommentsInNote (SocNot,NumComments);
2016-01-20 02:35:27 +01:00
2019-03-29 11:24:02 +01:00
/* End container for buttons and comments */
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-11 19:28:43 +01:00
/* Put hidden form to write a new comment */
2019-03-12 21:25:55 +01:00
TL_PutHiddenFormToWriteNewCommentToNote (SocNot->NotCod,IdNewComment);
2016-01-07 11:31:36 +01:00
2016-01-05 04:54:00 +01:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
2015-12-30 16:33:36 +01:00
/***** End list item *****/
2019-10-26 22:49:13 +02:00
HTM_LI_End ();
2016-01-05 21:30:10 +01:00
2017-06-12 14:16:33 +02:00
/***** End box ****/
2016-01-11 00:53:21 +01:00
if (ShowNoteAlone)
2016-01-05 21:30:10 +01:00
{
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-01-05 21:30:10 +01:00
}
2015-12-30 16:33:36 +01:00
}
2016-01-13 12:59:23 +01:00
/*****************************************************************************/
/*************** Write sharer/commenter if distinct to author ****************/
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_WriteTopMessage (TL_TopMessage_t TopMessage,long UsrCod)
2016-01-13 12:59:23 +01:00
{
2017-02-17 01:59:58 +01:00
extern const char *Txt_My_public_profile;
extern const char *Txt_Another_user_s_profile;
2019-03-12 21:25:55 +01:00
extern const char *Txt_TIMELINE_NOTE_TOP_MESSAGES[TL_NUM_TOP_MESSAGES];
2016-01-13 12:59:23 +01:00
struct UsrData UsrDat;
2018-10-10 23:56:42 +02:00
bool ItsMe = Usr_ItsMe (UsrCod);
2016-01-13 12:59:23 +01:00
2019-03-12 21:25:55 +01:00
if (TopMessage != TL_TOP_MESSAGE_NONE)
2016-01-19 00:50:35 +01:00
{
2017-02-17 06:32:57 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
2017-02-17 01:59:58 +01:00
2017-02-17 06:32:57 +01:00
/***** Get user's data *****/
UsrDat.UsrCod = UsrCod;
2019-03-19 13:22:14 +01:00
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS)) // Really we only need EncryptedUsrCod and FullName
2016-01-13 12:59:23 +01:00
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_TOP_CONT TL_TOP_PUBLISHER TL_WIDTH\"");
2016-01-19 00:50:35 +01:00
/***** Show user's name inside form to go to user's public profile *****/
2018-11-09 20:47:39 +01:00
Frm_StartFormUnique (ActSeeOthPubPrf);
2017-02-17 06:32:57 +01:00
Usr_PutParamUsrCodEncrypted (UsrDat.EncryptedUsrCod);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (ItsMe ? Txt_My_public_profile :
2019-11-20 11:04:54 +01:00
Txt_Another_user_s_profile,
"BT_LINK TL_TOP_PUBLISHER",NULL);
2019-11-10 12:36:37 +01:00
HTM_Txt (UsrDat.FullName);
2019-11-18 20:12:10 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-01-13 12:59:23 +01:00
2016-01-19 00:50:35 +01:00
/***** Show action made *****/
2019-11-11 00:15:44 +01:00
HTM_TxtF (" %s:",Txt_TIMELINE_NOTE_TOP_MESSAGES[TopMessage]);
2019-10-24 00:04:40 +02:00
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-13 12:59:23 +01:00
}
2016-01-19 00:50:35 +01:00
2017-02-17 06:32:57 +01:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
2016-01-19 00:50:35 +01:00
}
2016-01-13 12:59:23 +01:00
}
2016-01-13 14:54:18 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/*************** Write name and nickname of author of a note *****************/
2016-01-13 14:54:18 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_WriteAuthorNote (const struct UsrData *UsrDat)
2016-01-13 14:54:18 +01:00
{
2017-02-17 01:59:58 +01:00
extern const char *Txt_My_public_profile;
extern const char *Txt_Another_user_s_profile;
2018-10-10 23:56:42 +02:00
bool ItsMe = Usr_ItsMe (UsrDat->UsrCod);
2016-01-13 14:54:18 +01:00
/***** Show user's name inside form to go to user's public profile *****/
2018-11-09 20:47:39 +01:00
Frm_StartFormUnique (ActSeeOthPubPrf);
2017-02-17 06:32:57 +01:00
Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (ItsMe ? Txt_My_public_profile :
2019-11-20 11:04:54 +01:00
Txt_Another_user_s_profile,
"BT_LINK TL_RIGHT_AUTHOR TL_RIGHT_AUTHOR_WIDTH DAT_N_BOLD",
NULL);
2019-11-10 12:36:37 +01:00
HTM_Txt (UsrDat->FullName);
2019-11-18 20:12:10 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-01-13 14:54:18 +01:00
}
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************* Write the date of creation of a note ********************/
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
// TimeUTC holds UTC date and time in UNIX format (seconds since 1970)
2019-03-12 21:25:55 +01:00
static void TL_WriteDateTime (time_t TimeUTC)
2015-12-28 19:23:42 +01:00
{
2018-11-09 20:47:39 +01:00
char IdDateTime[Frm_MAX_BYTES_ID + 1];
2015-12-28 19:23:42 +01:00
2016-01-11 19:28:43 +01:00
/***** Create unique Id *****/
2018-11-09 20:47:39 +01:00
Frm_SetUniqueId (IdDateTime);
2016-01-10 23:00:15 +01:00
/***** Container where the date-time is written *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"%s\" class=\"TL_RIGHT_TIME DAT_LIGHT\"",IdDateTime);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-10 23:00:15 +01:00
/***** Script to write date and time in browser local time *****/
// This must be out of the div where the output is written
// because it will be evaluated in a loop in JavaScript
2019-11-01 23:35:55 +01:00
Dat_WriteLocalDateHMSFromUTC (IdDateTime,TimeUTC,
2019-11-02 12:10:58 +01:00
Gbl.Prefs.DateFormat,Dat_SEPARATOR_COMMA,
2019-11-02 11:45:41 +01:00
true,true,false,0x6);
2015-12-28 19:23:42 +01:00
}
2016-01-02 01:56:48 +01:00
/*****************************************************************************/
/***************** Get from database and write public post *******************/
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_GetAndWritePost (long PstCod)
2016-01-02 01:56:48 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
2019-11-24 23:51:03 +01:00
struct PostContent Content;
2016-04-08 16:37:59 +02:00
/***** Initialize image *****/
2019-11-24 23:51:03 +01:00
Med_MediaConstructor (&Content.Media);
2016-01-02 01:56:48 +01:00
2019-03-12 21:25:55 +01:00
/***** Get post from database *****/
2018-11-01 21:59:42 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get the content"
2019-03-12 21:25:55 +01:00
" of a post",
2019-11-25 09:06:27 +01:00
"SELECT Txt," // row[0]
2019-03-18 15:42:22 +01:00
"MedCod" // row[1]
2019-11-25 13:29:56 +01:00
" FROM tl_posts"
2019-03-12 21:25:55 +01:00
" WHERE PstCod=%ld",
2018-11-01 21:59:42 +01:00
PstCod);
2016-01-02 01:56:48 +01:00
/***** Result should have a unique row *****/
if (NumRows == 1)
{
2016-01-27 13:20:08 +01:00
row = mysql_fetch_row (mysql_res);
2016-04-08 16:37:59 +02:00
/****** Get content (row[0]) *****/
2019-11-24 23:51:03 +01:00
Str_Copy (Content.Txt,row[0],
2017-01-17 03:10:43 +01:00
Cns_MAX_BYTES_LONG_TEXT);
2016-04-08 16:37:59 +02:00
2019-03-18 15:42:22 +01:00
/***** Get media (row[1]) *****/
2019-11-24 23:51:03 +01:00
Content.Media.MedCod = Str_ConvertStrCodToLongCod (row[1]);
Med_GetMediaDataByCod (&Content.Media);
2016-01-02 01:56:48 +01:00
}
else
2019-11-24 23:51:03 +01:00
Content.Txt[0] = '\0';
2016-01-02 01:56:48 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Write content *****/
2019-11-24 23:51:03 +01:00
if (Content.Txt[0])
2016-04-15 14:30:28 +02:00
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_TXT\"");
2019-11-24 23:51:03 +01:00
Msg_WriteMsgContent (Content.Txt,Cns_MAX_BYTES_LONG_TEXT,true,false);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-04-15 14:30:28 +02:00
}
2016-04-08 16:37:59 +02:00
/***** Show image *****/
2019-11-24 23:51:03 +01:00
Med_ShowMedia (&Content.Media,"TL_PST_MED_CONT TL_RIGHT_WIDTH",
"TL_PST_MED TL_RIGHT_WIDTH");
2016-04-08 16:37:59 +02:00
2016-04-08 23:30:43 +02:00
/***** Free image *****/
2019-11-24 23:51:03 +01:00
Med_MediaDestructor (&Content.Media);
2016-01-02 01:56:48 +01:00
}
2015-12-29 13:18:25 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************* Put form to go to an action depending on the note *************/
2015-12-29 13:18:25 +01:00
/*****************************************************************************/
2020-04-07 03:01:41 +02:00
static void TL_PutFormGoToAction (const struct TL_Note *SocNot,
const struct For_Forums *Forums)
2015-12-29 13:18:25 +01:00
{
extern const Act_Action_t For_ActionsSeeFor[For_NUM_TYPES_FORUM];
2019-03-20 02:18:30 +01:00
extern const char *The_ClassFormInBoxBold[The_NUM_THEMES];
2019-03-12 21:25:55 +01:00
extern const char *Txt_TIMELINE_NOTE[TL_NUM_NOTE_TYPES];
2016-01-03 01:54:19 +01:00
extern const char *Txt_not_available;
2019-03-25 19:05:10 +01:00
char *Anchor = NULL;
2019-11-21 11:39:30 +01:00
static const Act_Action_t TL_DefaultActions[TL_NUM_NOTE_TYPES] =
2016-01-25 18:57:37 +01:00
{
2019-11-21 11:39:30 +01:00
[TL_NOTE_UNKNOWN ] = ActUnk,
/* Start tab */
[TL_NOTE_POST ] = ActUnk, // action not used
2016-01-25 18:57:37 +01:00
/* Institution tab */
2019-11-21 11:39:30 +01:00
[TL_NOTE_INS_DOC_PUB_FILE ] = ActReqDatSeeDocIns,
[TL_NOTE_INS_SHA_PUB_FILE ] = ActReqDatShaIns,
2016-01-25 18:57:37 +01:00
/* Centre tab */
2019-11-21 11:39:30 +01:00
[TL_NOTE_CTR_DOC_PUB_FILE ] = ActReqDatSeeDocCtr,
[TL_NOTE_CTR_SHA_PUB_FILE ] = ActReqDatShaCtr,
2016-01-25 18:57:37 +01:00
/* Degree tab */
2019-11-21 11:39:30 +01:00
[TL_NOTE_DEG_DOC_PUB_FILE ] = ActReqDatSeeDocDeg,
[TL_NOTE_DEG_SHA_PUB_FILE ] = ActReqDatShaDeg,
2016-01-25 18:57:37 +01:00
/* Course tab */
2019-11-21 11:39:30 +01:00
[TL_NOTE_CRS_DOC_PUB_FILE ] = ActReqDatSeeDocCrs,
[TL_NOTE_CRS_SHA_PUB_FILE ] = ActReqDatShaCrs,
2016-01-25 18:57:37 +01:00
/* Assessment tab */
2019-11-21 11:39:30 +01:00
[TL_NOTE_EXAM_ANNOUNCEMENT] = ActSeeOneExaAnn,
2016-01-25 18:57:37 +01:00
/* Users tab */
/* Messages tab */
2019-11-21 11:39:30 +01:00
[TL_NOTE_NOTICE ] = ActSeeOneNot,
[TL_NOTE_FORUM_POST ] = ActSeeFor,
/* Analytics tab */
2016-01-25 18:57:37 +01:00
/* Profile tab */
};
2019-11-21 11:39:30 +01:00
static const char *TL_Icons[TL_NUM_NOTE_TYPES] =
2016-01-25 18:57:37 +01:00
{
2019-11-21 11:39:30 +01:00
[TL_NOTE_UNKNOWN ] = NULL,
/* Start tab */
[TL_NOTE_POST ] = NULL, // icon not used
2016-01-25 18:57:37 +01:00
/* Institution tab */
2019-11-21 11:39:30 +01:00
[TL_NOTE_INS_DOC_PUB_FILE ] = "file.svg",
[TL_NOTE_INS_SHA_PUB_FILE ] = "file.svg",
2016-01-25 18:57:37 +01:00
/* Centre tab */
2019-11-21 11:39:30 +01:00
[TL_NOTE_CTR_DOC_PUB_FILE ] = "file.svg",
[TL_NOTE_CTR_SHA_PUB_FILE ] = "file.svg",
2016-01-25 18:57:37 +01:00
/* Degree tab */
2019-11-21 11:39:30 +01:00
[TL_NOTE_DEG_DOC_PUB_FILE ] = "file.svg",
[TL_NOTE_DEG_SHA_PUB_FILE ] = "file.svg",
2016-01-25 18:57:37 +01:00
/* Course tab */
2019-11-21 11:39:30 +01:00
[TL_NOTE_CRS_DOC_PUB_FILE ] = "file.svg",
[TL_NOTE_CRS_SHA_PUB_FILE ] = "file.svg",
2016-01-25 18:57:37 +01:00
/* Assessment tab */
2019-11-21 11:39:30 +01:00
[TL_NOTE_EXAM_ANNOUNCEMENT] = "bullhorn.svg",
2016-01-25 18:57:37 +01:00
/* Users tab */
/* Messages tab */
2019-11-21 11:39:30 +01:00
[TL_NOTE_NOTICE ] = "sticky-note.svg",
[TL_NOTE_FORUM_POST ] = "comments.svg",
/* Analytics tab */
2016-01-25 18:57:37 +01:00
/* Profile tab */
};
2015-12-29 13:18:25 +01:00
2019-03-12 21:25:55 +01:00
if (SocNot->Unavailable || // File/notice... pointed by this note is unavailable
2016-01-14 10:31:09 +01:00
Gbl.Form.Inside) // Inside another form
2015-12-29 13:18:25 +01:00
{
2016-01-03 19:30:59 +01:00
/***** Do not put form *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_FORM_OFF\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_TIMELINE_NOTE[SocNot->NoteType]);
2016-01-03 19:30:59 +01:00
if (SocNot->Unavailable)
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;(%s)",Txt_not_available);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2015-12-29 13:18:25 +01:00
}
2016-01-03 19:30:59 +01:00
else // Not inside another form
2016-01-02 17:07:58 +01:00
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_FORM\"");
2016-04-08 23:30:43 +02:00
2019-11-18 20:12:10 +01:00
/***** Start form with parameters depending on the type of note *****/
2016-01-03 19:30:59 +01:00
switch (SocNot->NoteType)
2016-01-03 01:13:57 +01:00
{
2019-03-12 21:25:55 +01:00
case TL_NOTE_INS_DOC_PUB_FILE:
case TL_NOTE_INS_SHA_PUB_FILE:
Frm_StartFormUnique (TL_DefaultActions[SocNot->NoteType]);
2016-01-04 10:27:32 +01:00
Brw_PutHiddenParamFilCod (SocNot->Cod);
2019-04-03 20:57:04 +02:00
if (SocNot->HieCod != Gbl.Hierarchy.Ins.InsCod) // Not the current institution
2016-01-04 10:27:32 +01:00
Ins_PutParamInsCod (SocNot->HieCod); // Go to another institution
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_CTR_DOC_PUB_FILE:
case TL_NOTE_CTR_SHA_PUB_FILE:
Frm_StartFormUnique (TL_DefaultActions[SocNot->NoteType]);
2016-01-04 10:27:32 +01:00
Brw_PutHiddenParamFilCod (SocNot->Cod);
2019-04-03 20:57:04 +02:00
if (SocNot->HieCod != Gbl.Hierarchy.Ctr.CtrCod) // Not the current centre
2016-01-04 10:27:32 +01:00
Ctr_PutParamCtrCod (SocNot->HieCod); // Go to another centre
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_DEG_DOC_PUB_FILE:
case TL_NOTE_DEG_SHA_PUB_FILE:
Frm_StartFormUnique (TL_DefaultActions[SocNot->NoteType]);
2016-01-04 10:27:32 +01:00
Brw_PutHiddenParamFilCod (SocNot->Cod);
2019-04-03 20:57:04 +02:00
if (SocNot->HieCod != Gbl.Hierarchy.Deg.DegCod) // Not the current degree
2016-01-04 10:27:32 +01:00
Deg_PutParamDegCod (SocNot->HieCod); // Go to another degree
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_CRS_DOC_PUB_FILE:
case TL_NOTE_CRS_SHA_PUB_FILE:
Frm_StartFormUnique (TL_DefaultActions[SocNot->NoteType]);
2016-01-04 10:27:32 +01:00
Brw_PutHiddenParamFilCod (SocNot->Cod);
2019-04-04 10:45:15 +02:00
if (SocNot->HieCod != Gbl.Hierarchy.Crs.CrsCod) // Not the current course
2016-01-04 10:27:32 +01:00
Crs_PutParamCrsCod (SocNot->HieCod); // Go to another course
2016-01-03 19:30:59 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_EXAM_ANNOUNCEMENT:
2019-04-20 21:11:44 +02:00
Frm_SetAnchorStr (SocNot->Cod,&Anchor);
2019-03-25 19:05:10 +01:00
Frm_StartFormUniqueAnchor (TL_DefaultActions[SocNot->NoteType],
Anchor); // Locate on this specific exam
2019-04-20 21:11:44 +02:00
Frm_FreeAnchorStr (Anchor);
2016-06-03 10:37:00 +02:00
Exa_PutHiddenParamExaCod (SocNot->Cod);
2019-04-04 10:45:15 +02:00
if (SocNot->HieCod != Gbl.Hierarchy.Crs.CrsCod) // Not the current course
2016-01-04 10:27:32 +01:00
Crs_PutParamCrsCod (SocNot->HieCod); // Go to another course
2016-01-03 19:30:59 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_POST: // Not applicable
2016-01-05 04:54:00 +01:00
return;
2019-03-12 21:25:55 +01:00
case TL_NOTE_FORUM_POST:
2020-04-07 03:01:41 +02:00
Frm_StartFormUnique (For_ActionsSeeFor[Forums->ForumSelected.Type]);
2017-04-18 16:44:44 +02:00
For_PutAllHiddenParamsForum (1, // Page of threads = first
1, // Page of posts = first
2020-04-07 03:01:41 +02:00
Forums->ForumSet,
Forums->ThreadsOrder,
Forums->ForumSelected.Location,
Forums->ForumSelected.ThrCod,
2017-04-18 01:25:44 +02:00
-1L);
2019-04-04 10:45:15 +02:00
if (SocNot->HieCod != Gbl.Hierarchy.Crs.CrsCod) // Not the current course
2016-01-04 10:27:32 +01:00
Crs_PutParamCrsCod (SocNot->HieCod); // Go to another course
2016-01-03 19:30:59 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_NOTICE:
2019-04-20 21:11:44 +02:00
Frm_SetAnchorStr (SocNot->Cod,&Anchor);
2019-03-25 19:05:10 +01:00
Frm_StartFormUniqueAnchor (TL_DefaultActions[SocNot->NoteType],
Anchor);
2019-04-20 21:11:44 +02:00
Frm_FreeAnchorStr (Anchor);
2016-01-05 04:54:00 +01:00
Not_PutHiddenParamNotCod (SocNot->Cod);
2019-04-04 10:45:15 +02:00
if (SocNot->HieCod != Gbl.Hierarchy.Crs.CrsCod) // Not the current course
2016-01-05 04:54:00 +01:00
Crs_PutParamCrsCod (SocNot->HieCod); // Go to another course
2016-01-03 19:30:59 +01:00
break;
2016-01-05 04:54:00 +01:00
default: // Not applicable
return;
2016-01-03 01:13:57 +01:00
}
2016-01-03 19:30:59 +01:00
2019-11-18 20:12:10 +01:00
/***** Icon and link to go to action *****/
2019-12-30 21:47:07 +01:00
HTM_BUTTON_SUBMIT_Begin (Txt_TIMELINE_NOTE[SocNot->NoteType],
Str_BuildStringStr ("BT_LINK %s ICO_HIGHLIGHT",
The_ClassFormInBoxBold[Gbl.Prefs.Theme]),
NULL);
2019-10-29 21:41:54 +01:00
Ico_PutIcon (TL_Icons[SocNot->NoteType],Txt_TIMELINE_NOTE[SocNot->NoteType],"CONTEXT_ICO_x16");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%s",Txt_TIMELINE_NOTE[SocNot->NoteType]);
2019-11-18 20:12:10 +01:00
HTM_BUTTON_End ();
2019-12-30 21:47:07 +01:00
Str_FreeString ();
2019-11-18 20:12:10 +01:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-04-08 23:30:43 +02:00
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-02 17:07:58 +01:00
}
2015-12-29 13:18:25 +01:00
}
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********************** Get note summary and content *************************/
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_GetNoteSummary (const struct TL_Note *SocNot,
char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1])
2015-12-28 19:23:42 +01:00
{
SummaryStr[0] = '\0';
2015-12-31 18:40:45 +01:00
switch (SocNot->NoteType)
2015-12-28 19:23:42 +01:00
{
2019-03-12 21:25:55 +01:00
case TL_NOTE_UNKNOWN:
2015-12-28 19:23:42 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_INS_DOC_PUB_FILE:
case TL_NOTE_INS_SHA_PUB_FILE:
case TL_NOTE_CTR_DOC_PUB_FILE:
case TL_NOTE_CTR_SHA_PUB_FILE:
case TL_NOTE_DEG_DOC_PUB_FILE:
case TL_NOTE_DEG_SHA_PUB_FILE:
case TL_NOTE_CRS_DOC_PUB_FILE:
case TL_NOTE_CRS_SHA_PUB_FILE:
2017-03-06 13:01:16 +01:00
Brw_GetSummaryAndContentOfFile (SummaryStr,NULL,SocNot->Cod,false);
2015-12-28 19:23:42 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_EXAM_ANNOUNCEMENT:
2017-03-06 13:01:16 +01:00
Exa_GetSummaryAndContentExamAnnouncement (SummaryStr,NULL,SocNot->Cod,false);
2015-12-28 19:23:42 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_POST:
2015-12-30 16:33:36 +01:00
// Not applicable
2015-12-28 19:23:42 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_FORUM_POST:
2017-03-06 13:01:16 +01:00
For_GetSummaryAndContentForumPst (SummaryStr,NULL,SocNot->Cod,false);
2015-12-28 19:23:42 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_NOTICE:
2017-03-06 13:01:16 +01:00
Not_GetSummaryAndContentNotice (SummaryStr,NULL,SocNot->Cod,false);
2015-12-30 20:11:50 +01:00
break;
2015-12-28 19:23:42 +01:00
}
}
2015-12-28 20:46:48 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/***************** Store and publish a note into database ********************/
2015-12-28 20:46:48 +01:00
/*****************************************************************************/
2016-01-15 14:46:44 +01:00
// Return the code of the new note just created
2015-12-28 20:46:48 +01:00
2019-03-12 21:25:55 +01:00
void TL_StoreAndPublishNote (TL_NoteType_t NoteType,long Cod,struct TL_Publication *SocPub)
2015-12-28 20:46:48 +01:00
{
2016-01-02 13:21:25 +01:00
long HieCod; // Hierarchy code (institution/centre/degree/course)
2015-12-28 20:46:48 +01:00
2016-01-02 13:21:25 +01:00
switch (NoteType)
2015-12-28 20:46:48 +01:00
{
2019-03-12 21:25:55 +01:00
case TL_NOTE_INS_DOC_PUB_FILE:
case TL_NOTE_INS_SHA_PUB_FILE:
2019-04-03 20:57:04 +02:00
HieCod = Gbl.Hierarchy.Ins.InsCod;
2016-01-02 13:21:25 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_CTR_DOC_PUB_FILE:
case TL_NOTE_CTR_SHA_PUB_FILE:
2019-04-03 20:57:04 +02:00
HieCod = Gbl.Hierarchy.Ctr.CtrCod;
2016-01-02 13:21:25 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_DEG_DOC_PUB_FILE:
case TL_NOTE_DEG_SHA_PUB_FILE:
2019-04-03 20:57:04 +02:00
HieCod = Gbl.Hierarchy.Deg.DegCod;
2016-01-02 13:21:25 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_NOTE_CRS_DOC_PUB_FILE:
case TL_NOTE_CRS_SHA_PUB_FILE:
case TL_NOTE_EXAM_ANNOUNCEMENT:
case TL_NOTE_NOTICE:
2019-04-04 10:45:15 +02:00
HieCod = Gbl.Hierarchy.Crs.CrsCod;
2016-01-02 13:21:25 +01:00
break;
default:
HieCod = -1L;
break;
2015-12-28 20:46:48 +01:00
}
2019-03-12 21:25:55 +01:00
/***** Store note *****/
2018-11-03 01:45:36 +01:00
SocPub->NotCod =
2019-03-12 21:25:55 +01:00
DB_QueryINSERTandReturnCode ("can not create new note",
2019-11-25 13:29:56 +01:00
"INSERT INTO tl_notes"
2018-11-03 01:45:36 +01:00
" (NoteType,Cod,UsrCod,HieCod,Unavailable,TimeNote)"
" VALUES"
" (%u,%ld,%ld,%ld,'N',NOW())",
(unsigned) NoteType,
Cod,Gbl.Usrs.Me.UsrDat.UsrCod,HieCod);
2016-01-01 20:19:43 +01:00
2019-03-12 21:25:55 +01:00
/***** Publish note in timeline *****/
2016-01-25 11:43:14 +01:00
SocPub->PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod;
2019-03-12 21:25:55 +01:00
SocPub->PubType = TL_PUB_ORIGINAL_NOTE;
TL_PublishNoteInTimeline (SocPub);
2016-01-01 20:19:43 +01:00
}
2015-12-31 18:40:45 +01:00
2016-01-03 19:30:59 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************************* Mark a note as unavailable ************************/
2016-01-03 19:30:59 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_MarkNoteAsUnavailableUsingNotCod (long NotCod)
2016-01-03 19:30:59 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Mark the note as unavailable *****/
DB_QueryUPDATE ("can not mark note as unavailable",
2019-11-25 13:29:56 +01:00
"UPDATE tl_notes SET Unavailable='Y'"
2018-11-03 12:16:40 +01:00
" WHERE NotCod=%ld",
NotCod);
2016-01-03 19:30:59 +01:00
}
2019-03-12 21:25:55 +01:00
void TL_MarkNoteAsUnavailableUsingNoteTypeAndCod (TL_NoteType_t NoteType,long Cod)
2016-01-03 19:30:59 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Mark the note as unavailable *****/
DB_QueryUPDATE ("can not mark note as unavailable",
2019-11-25 13:29:56 +01:00
"UPDATE tl_notes SET Unavailable='Y'"
2018-11-03 12:16:40 +01:00
" WHERE NoteType=%u AND Cod=%ld",
(unsigned) NoteType,Cod);
2016-01-03 19:30:59 +01:00
}
2016-01-04 01:56:28 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/****************** Mark notes of one file as unavailable ********************/
2016-01-04 01:56:28 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_MarkNoteOneFileAsUnavailable (const char *Path)
2016-01-04 01:56:28 +01:00
{
extern const Brw_FileBrowser_t Brw_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER];
Brw_FileBrowser_t FileBrowser = Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type];
long FilCod;
2019-03-12 21:25:55 +01:00
TL_NoteType_t NoteType;
2016-01-04 01:56:28 +01:00
switch (FileBrowser)
{
2017-10-08 00:51:49 +02:00
case Brw_ADMI_DOC_INS:
case Brw_ADMI_SHR_INS:
case Brw_ADMI_DOC_CTR:
case Brw_ADMI_SHR_CTR:
case Brw_ADMI_DOC_DEG:
case Brw_ADMI_SHR_DEG:
case Brw_ADMI_DOC_CRS:
case Brw_ADMI_SHR_CRS:
2016-01-04 01:56:28 +01:00
/***** Get file code *****/
FilCod = Brw_GetFilCodByPath (Path,true); // Only if file is public
if (FilCod > 0)
{
2019-03-12 21:25:55 +01:00
/***** Mark possible note as unavailable *****/
2016-01-04 01:56:28 +01:00
switch (FileBrowser)
{
2017-10-08 00:51:49 +02:00
case Brw_ADMI_DOC_INS:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_INS_DOC_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
2017-10-08 00:51:49 +02:00
case Brw_ADMI_SHR_INS:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_INS_SHA_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
2017-10-08 00:51:49 +02:00
case Brw_ADMI_DOC_CTR:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_CTR_DOC_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
2017-10-08 00:51:49 +02:00
case Brw_ADMI_SHR_CTR:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_CTR_SHA_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
2017-10-08 00:51:49 +02:00
case Brw_ADMI_DOC_DEG:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_DEG_DOC_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
2017-10-08 00:51:49 +02:00
case Brw_ADMI_SHR_DEG:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_DEG_SHA_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
2017-10-08 00:51:49 +02:00
case Brw_ADMI_DOC_CRS:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_CRS_DOC_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
2017-10-08 00:51:49 +02:00
case Brw_ADMI_SHR_CRS:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_CRS_SHA_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
default:
return;
}
2019-03-12 21:25:55 +01:00
TL_MarkNoteAsUnavailableUsingNoteTypeAndCod (NoteType,FilCod);
2016-01-04 01:56:28 +01:00
}
break;
default:
break;
}
}
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/***** Mark possible notes involving children of a folder as unavailable *****/
2016-01-04 01:56:28 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_MarkNotesChildrenOfFolderAsUnavailable (const char *Path)
2016-01-04 01:56:28 +01:00
{
extern const Brw_FileBrowser_t Brw_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER];
Brw_FileBrowser_t FileBrowser = Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type];
long Cod = Brw_GetCodForFiles ();
2019-03-12 21:25:55 +01:00
TL_NoteType_t NoteType;
2016-01-04 01:56:28 +01:00
switch (FileBrowser)
{
2017-10-08 00:51:49 +02:00
case Brw_ADMI_DOC_INS:
case Brw_ADMI_SHR_INS:
case Brw_ADMI_DOC_CTR:
case Brw_ADMI_SHR_CTR:
case Brw_ADMI_DOC_DEG:
case Brw_ADMI_SHR_DEG:
case Brw_ADMI_DOC_CRS:
case Brw_ADMI_SHR_CRS:
2019-03-12 21:25:55 +01:00
/***** Mark possible note as unavailable *****/
2016-01-04 01:56:28 +01:00
switch (FileBrowser)
{
2017-10-08 00:51:49 +02:00
case Brw_ADMI_DOC_INS:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_INS_DOC_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
2017-10-08 00:51:49 +02:00
case Brw_ADMI_SHR_INS:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_INS_SHA_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
2017-10-08 00:51:49 +02:00
case Brw_ADMI_DOC_CTR:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_CTR_DOC_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
2017-10-08 00:51:49 +02:00
case Brw_ADMI_SHR_CTR:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_CTR_SHA_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
2017-10-08 00:51:49 +02:00
case Brw_ADMI_DOC_DEG:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_DEG_DOC_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
2017-10-08 00:51:49 +02:00
case Brw_ADMI_SHR_DEG:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_DEG_SHA_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
2017-10-08 00:51:49 +02:00
case Brw_ADMI_DOC_CRS:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_CRS_DOC_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
2017-10-08 00:51:49 +02:00
case Brw_ADMI_SHR_CRS:
2019-03-12 21:25:55 +01:00
NoteType = TL_NOTE_CRS_SHA_PUB_FILE;
2016-01-04 01:56:28 +01:00
break;
default:
return;
}
2019-03-12 21:25:55 +01:00
DB_QueryUPDATE ("can not mark notes as unavailable",
2019-11-25 13:29:56 +01:00
"UPDATE tl_notes SET Unavailable='Y'"
2018-11-03 12:16:40 +01:00
" WHERE NoteType=%u AND Cod IN"
" (SELECT FilCod FROM files"
" WHERE FileBrowser=%u AND Cod=%ld"
" AND Path LIKE '%s/%%' AND Public='Y')", // Only public files
(unsigned) NoteType,
(unsigned) FileBrowser,Cod,
Path);
2016-01-04 01:56:28 +01:00
break;
default:
break;
}
}
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************************* Publish note in timeline **************************/
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
// SocPub->PubCod is set by the function
2016-01-01 20:19:43 +01:00
2019-03-12 21:25:55 +01:00
static void TL_PublishNoteInTimeline (struct TL_Publication *SocPub)
2016-01-01 20:19:43 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Publish note in timeline *****/
2018-11-03 01:45:36 +01:00
SocPub->PubCod =
2019-03-12 21:25:55 +01:00
DB_QueryINSERTandReturnCode ("can not publish note",
2019-11-25 13:29:56 +01:00
"INSERT INTO tl_pubs"
2018-11-03 01:45:36 +01:00
" (NotCod,PublisherCod,PubType,TimePublish)"
" VALUES"
" (%ld,%ld,%u,NOW())",
SocPub->NotCod,
SocPub->PublisherCod,
(unsigned) SocPub->PubType);
2019-03-06 10:13:39 +01:00
2019-03-12 21:25:55 +01:00
/***** Increment number of publications in user's figures *****/
2019-03-06 10:13:39 +01:00
Prf_IncrementNumSocPubUsr (SocPub->PublisherCod);
2015-12-28 20:46:48 +01:00
}
2015-12-30 02:08:08 +01:00
2015-12-30 12:40:13 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********************** Form to write a new publication **********************/
2015-12-30 12:40:13 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_PutFormToWriteNewPost (void)
2015-12-30 12:40:13 +01:00
{
2019-03-12 21:25:55 +01:00
extern const char *Txt_New_TIMELINE_post;
2016-01-08 15:08:30 +01:00
bool ShowPhoto;
2017-01-15 22:58:26 +01:00
char PhotoURL[PATH_MAX + 1];
2015-12-30 12:40:13 +01:00
2016-01-09 15:00:14 +01:00
/***** Start list *****/
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("class=\"TL_LIST\"");
2019-10-26 22:49:13 +02:00
HTM_LI_Begin ("class=\"TL_WIDTH\"");
2016-01-08 15:08:30 +01:00
2016-01-20 14:07:15 +01:00
/***** Left: write author's photo (my photo) *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_LEFT_PHOTO\"");
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (&Gbl.Usrs.Me.UsrDat,PhotoURL);
2016-01-08 15:08:30 +01:00
Pho_ShowUsrPhoto (&Gbl.Usrs.Me.UsrDat,ShowPhoto ? PhotoURL :
NULL,
2019-03-29 11:24:02 +01:00
"PHOTO45x60",Pho_ZOOM,false);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-02 01:56:48 +01:00
2019-11-20 10:17:42 +01:00
/***** Right: author's name, time, textarea *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_RIGHT_CONT TL_RIGHT_WIDTH\"");
2016-01-02 01:56:48 +01:00
2019-11-20 10:17:42 +01:00
/* Author name */
TL_WriteAuthorNote (&Gbl.Usrs.Me.UsrDat);
2019-11-07 10:24:00 +01:00
2019-11-20 10:17:42 +01:00
/* Form to write the post */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_FORM_NEW_PST TL_RIGHT_WIDTH\"");
2019-03-12 21:25:55 +01:00
TL_FormStart (ActRcvSocPstGbl,ActRcvSocPstUsr);
2019-11-20 10:17:42 +01:00
TL_PutTextarea (Txt_New_TIMELINE_post,"TL_PST_TEXTAREA TL_RIGHT_WIDTH");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-11-20 10:17:42 +01:00
HTM_DIV_End ();
2015-12-30 12:40:13 +01:00
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-08 15:08:30 +01:00
2016-01-09 15:00:14 +01:00
/***** End list *****/
2019-10-26 22:49:13 +02:00
HTM_LI_End ();
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2015-12-30 12:40:13 +01:00
}
2016-01-15 10:48:49 +01:00
/*****************************************************************************/
/*** Put textarea and button inside a form to submit a new post or comment ***/
/*****************************************************************************/
2019-03-28 08:51:39 +01:00
static void TL_PutTextarea (const char *Placeholder,const char *ClassTextArea)
2016-01-15 10:48:49 +01:00
{
extern const char *Txt_Post;
2018-11-09 20:47:39 +01:00
char IdDivImgButton[Frm_MAX_BYTES_ID + 1];
2016-01-15 10:48:49 +01:00
2016-04-08 17:38:24 +02:00
/***** Set unique id for the hidden div *****/
2018-11-09 20:47:39 +01:00
Frm_SetUniqueId (IdDivImgButton);
2016-01-15 10:48:49 +01:00
/***** Textarea to write the content *****/
2019-11-24 23:51:03 +01:00
HTM_TEXTAREA_Begin ("name=\"Txt\" rows=\"1\" maxlength=\"%u\""
2019-10-31 17:42:05 +01:00
" placeholder=\"%s&hellip;\" class=\"%s\""
" onfocus=\"expandTextarea(this,'%s','6');\"",
TL_MAX_CHARS_IN_POST,
Placeholder,ClassTextArea,
IdDivImgButton);
HTM_TEXTAREA_End ();
2016-04-08 17:38:24 +02:00
/***** Start concealable div *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"%s\" style=\"display:none;\"",IdDivImgButton);
2016-04-08 17:38:24 +02:00
/***** Help on editor *****/
Lay_HelpPlainEditor ();
2016-01-15 10:48:49 +01:00
2016-04-08 16:37:59 +02:00
/***** Attached image (optional) *****/
2019-03-28 08:32:47 +01:00
Med_PutMediaUploader (-1,"TL_MED_INPUT_WIDTH");
2016-04-08 02:16:23 +02:00
2016-04-08 17:38:24 +02:00
/***** Submit button *****/
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (NULL,"BT_SUBMIT_INLINE BT_CREATE",NULL);
2019-11-11 00:15:44 +01:00
HTM_Txt (Txt_Post);
HTM_BUTTON_End ();
2016-04-08 17:38:24 +02:00
/***** End hidden div *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-15 10:48:49 +01:00
}
2015-12-30 12:40:13 +01:00
/*****************************************************************************/
/******************* Receive and store a new public post *********************/
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_ReceivePostUsr (void)
2016-01-02 01:56:48 +01:00
{
2019-12-05 15:47:23 +01:00
long NotCod;
2016-01-02 01:56:48 +01:00
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
2016-01-15 14:46:44 +01:00
/***** Show user's profile *****/
2016-06-12 19:55:33 +02:00
Prf_ShowUserProfile (&Gbl.Usrs.Other.UsrDat);
2016-01-02 01:56:48 +01:00
2016-01-02 02:33:23 +01:00
/***** Start section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_Begin (TL_TIMELINE_SECTION_ID);
2016-01-02 02:33:23 +01:00
2019-03-29 01:23:33 +01:00
/***** Receive and store post, and
write updated timeline after publication (user) *****/
2019-12-05 15:47:23 +01:00
NotCod = TL_ReceivePost ();
TL_ShowTimelineUsrHighlightingNot (NotCod);
2016-01-02 02:33:23 +01:00
/***** End section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_End ();
2016-01-02 01:56:48 +01:00
}
2019-03-29 01:23:33 +01:00
void TL_ReceivePostGbl (void)
{
long NotCod;
/***** Receive and store post *****/
NotCod = TL_ReceivePost ();
/***** Write updated timeline after publication (global) *****/
TL_ShowTimelineGblHighlightingNot (NotCod);
}
2019-03-12 21:25:55 +01:00
// Returns the code of the note just created
static long TL_ReceivePost (void)
2015-12-30 12:40:13 +01:00
{
2019-11-24 23:51:03 +01:00
struct PostContent Content;
2015-12-30 12:40:13 +01:00
long PstCod;
2019-03-12 21:25:55 +01:00
struct TL_Publication SocPub;
2015-12-30 12:40:13 +01:00
2016-01-15 14:46:44 +01:00
/***** Get the content of the new post *****/
2019-11-24 23:51:03 +01:00
Par_GetParAndChangeFormat ("Txt",Content.Txt,Cns_MAX_BYTES_LONG_TEXT,
2015-12-30 12:40:13 +01:00
Str_TO_RIGOROUS_HTML,true);
2016-04-08 23:30:43 +02:00
/***** Initialize image *****/
2019-11-24 23:51:03 +01:00
Med_MediaConstructor (&Content.Media);
2016-04-08 23:30:43 +02:00
2016-04-08 16:37:59 +02:00
/***** Get attached image (action, file and title) *****/
2019-11-24 23:51:03 +01:00
Content.Media.Width = TL_IMAGE_SAVED_MAX_WIDTH;
Content.Media.Height = TL_IMAGE_SAVED_MAX_HEIGHT;
Content.Media.Quality = TL_IMAGE_SAVED_QUALITY;
2020-03-17 00:35:11 +01:00
Med_GetMediaFromForm (-1L,-1L,-1,&Content.Media,NULL,NULL);
2019-03-17 14:47:58 +01:00
Ale_ShowAlerts (NULL);
2016-04-08 16:37:59 +02:00
2019-11-24 23:51:03 +01:00
if (Content.Txt[0] || // Text not empty
Content.Media.Status == Med_PROCESSED) // A media is attached
2016-01-09 15:00:14 +01:00
{
2019-03-19 11:20:29 +01:00
/***** Store media in filesystem and database *****/
2019-11-24 23:51:03 +01:00
Med_RemoveKeepOrStoreMedia (-1L,&Content.Media);
2019-03-18 15:42:22 +01:00
2016-01-11 01:30:23 +01:00
/***** Publish *****/
2016-01-09 15:00:14 +01:00
/* Insert post content in the database */
2018-11-03 01:45:36 +01:00
PstCod =
DB_QueryINSERTandReturnCode ("can not create post",
2019-11-25 13:29:56 +01:00
"INSERT INTO tl_posts"
2019-11-25 09:06:27 +01:00
" (Txt,MedCod)"
2018-11-03 01:45:36 +01:00
" VALUES"
2019-03-18 15:42:22 +01:00
" ('%s',%ld)",
2019-11-24 23:51:03 +01:00
Content.Txt,
Content.Media.MedCod);
2015-12-30 12:40:13 +01:00
2019-03-12 21:25:55 +01:00
/* Insert post in notes */
TL_StoreAndPublishNote (TL_NOTE_POST,PstCod,&SocPub);
2016-01-25 11:43:14 +01:00
/***** Analyze content and store notifications about mentions *****/
2019-11-24 23:51:03 +01:00
Str_AnalyzeTxtAndStoreNotifyEventToMentionedUsrs (SocPub.PubCod,Content.Txt);
2016-01-09 15:00:14 +01:00
}
2016-04-08 23:30:43 +02:00
else // Text and image are empty
2016-01-25 11:43:14 +01:00
SocPub.NotCod = -1L;
2016-01-15 14:46:44 +01:00
2016-04-08 23:30:43 +02:00
/***** Free image *****/
2019-11-24 23:51:03 +01:00
Med_MediaDestructor (&Content.Media);
2016-04-08 16:37:59 +02:00
2016-01-25 11:43:14 +01:00
return SocPub.NotCod;
2015-12-30 12:40:13 +01:00
}
2016-01-07 00:42:35 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********* Put an icon to toggle on/off the form to comment a note ***********/
2016-01-07 00:42:35 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_PutIconToToggleCommentNote (const char UniqueId[Frm_MAX_BYTES_ID + 1])
2016-01-07 00:42:35 +01:00
{
extern const char *Txt_Comment;
2019-03-12 21:25:55 +01:00
/***** Link to toggle on/off the form to comment a note *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"%s_ico\" class=\"TL_ICO_COM_OFF\"",UniqueId);
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"\" onclick=\"toggleNewComment ('%s');return false;\"",
UniqueId);
2020-03-10 22:30:42 +01:00
Ico_PutIcon ("comment-regular.svg",Txt_Comment,"CONTEXT_ICO_16x16");
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-07 11:31:36 +01:00
}
2016-01-19 02:08:44 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********** Put an icon to toggle on/off the form to comment a note **********/
2016-01-19 02:08:44 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_PutIconCommentDisabled (void)
2016-01-19 02:08:44 +01:00
{
extern const char *Txt_Comment;
2019-03-12 21:25:55 +01:00
/***** Disabled icon to comment a note *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_ICO_COM_OFF TL_ICO_DISABLED\"");
2019-10-29 21:41:54 +01:00
Ico_PutIcon ("edit.svg",Txt_Comment,"ICO16x16");
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-19 02:08:44 +01:00
}
2016-01-08 15:08:30 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********************** Form to comment a publication ************************/
2016-01-08 15:08:30 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_PutHiddenFormToWriteNewCommentToNote (long NotCod,
const char IdNewComment[Frm_MAX_BYTES_ID + 1])
2016-01-08 15:08:30 +01:00
{
2019-03-12 21:25:55 +01:00
extern const char *Txt_New_TIMELINE_comment;
2016-01-20 14:07:15 +01:00
bool ShowPhoto = false;
2017-01-28 15:58:46 +01:00
char PhotoURL[PATH_MAX + 1];
2016-01-15 11:41:45 +01:00
2016-01-08 15:08:30 +01:00
/***** Start container *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"%s\" class=\"TL_FORM_NEW_COM TL_RIGHT_WIDTH\""
" style=\"display:none;\"",
IdNewComment);
2016-01-08 15:08:30 +01:00
2016-01-20 14:07:15 +01:00
/***** Left: write author's photo (my photo) *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_COM_PHOTO\"");
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (&Gbl.Usrs.Me.UsrDat,PhotoURL);
2016-01-20 14:07:15 +01:00
Pho_ShowUsrPhoto (&Gbl.Usrs.Me.UsrDat,ShowPhoto ? PhotoURL :
NULL,
"PHOTO30x40",Pho_ZOOM,true); // Use unique id
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-20 14:07:15 +01:00
/***** Right: form to write the comment *****/
2017-02-24 10:34:21 +01:00
/* Start right container */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_COM_CONT TL_COMM_WIDTH\"");
2016-01-20 14:07:15 +01:00
2019-10-20 22:00:28 +02:00
/* Begin form to write the post */
2019-03-12 21:25:55 +01:00
TL_FormStart (ActRcvSocComGbl,ActRcvSocComUsr);
TL_PutHiddenParamNotCod (NotCod);
2016-01-08 15:08:30 +01:00
2017-02-24 10:34:21 +01:00
/* Textarea and button */
2019-03-12 21:25:55 +01:00
TL_PutTextarea (Txt_New_TIMELINE_comment,
2019-03-29 15:12:51 +01:00
"TL_COM_TEXTAREA TL_COMM_WIDTH");
2016-01-08 15:08:30 +01:00
2017-02-24 10:34:21 +01:00
/* End form */
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-01-08 15:08:30 +01:00
2017-02-24 10:34:21 +01:00
/* End right container */
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-20 14:07:15 +01:00
2016-01-08 15:08:30 +01:00
/***** End container *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-08 15:08:30 +01:00
}
2016-01-08 02:55:18 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********************* Get number of comments in a note **********************/
2016-01-08 02:55:18 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static unsigned long TL_GetNumCommentsInNote (long NotCod)
2016-01-08 02:55:18 +01:00
{
2019-03-12 21:25:55 +01:00
return DB_QueryCOUNT ("can not get number of comments in a note",
2019-11-25 13:29:56 +01:00
"SELECT COUNT(*) FROM tl_pubs"
2018-11-03 20:52:00 +01:00
" WHERE NotCod=%ld AND PubType=%u",
2019-03-12 21:25:55 +01:00
NotCod,(unsigned) TL_PUB_COMMENT_TO_NOTE);
2016-01-08 02:55:18 +01:00
}
2016-01-07 11:31:36 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/*********************** Write comments in a note ****************************/
2016-01-07 11:31:36 +01:00
/*****************************************************************************/
2019-11-18 08:38:34 +01:00
static void TL_WriteCommentsInNote (const struct TL_Note *SocNot,
unsigned NumComments)
2016-01-07 15:19:54 +01:00
{
MYSQL_RES *mysql_res;
2019-11-18 08:38:34 +01:00
unsigned NumInitialComments;
unsigned NumFinalCommentsToGet;
unsigned NumFinalCommentsGot;
unsigned NumCom;
2019-02-27 02:31:31 +01:00
char IdComments[Frm_MAX_BYTES_ID + 1];
2016-01-07 15:19:54 +01:00
2019-11-18 08:38:34 +01:00
/***** Compute how many initial comments will be hidden
and how many final comments will be visible *****/
// Never hide only one comment
// So, the number of comments initially hidden must be 0 or >= 2
if (NumComments <= TL_NUM_VISIBLE_COMMENTS + 1)
2016-01-11 19:28:43 +01:00
{
2019-11-18 08:38:34 +01:00
NumInitialComments = 0;
NumFinalCommentsToGet = NumComments;
}
else
{
NumInitialComments = NumComments - TL_NUM_VISIBLE_COMMENTS;
NumFinalCommentsToGet = TL_NUM_VISIBLE_COMMENTS;
}
2016-01-11 00:53:21 +01:00
2019-11-18 08:38:34 +01:00
/***** Get last comments of this note from database *****/
NumFinalCommentsGot = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get comments",
"SELECT * FROM "
"("
2019-11-25 13:29:56 +01:00
"SELECT tl_pubs.PubCod," // row[0]
"tl_pubs.PublisherCod," // row[1]
"tl_pubs.NotCod," // row[2]
2019-11-18 08:38:34 +01:00
"UNIX_TIMESTAMP("
2019-11-25 13:29:56 +01:00
"tl_pubs.TimePublish)," // row[3]
"tl_comments.Txt," // row[4]
"tl_comments.MedCod" // row[5]
" FROM tl_pubs,tl_comments"
" WHERE tl_pubs.NotCod=%ld"
" AND tl_pubs.PubType=%u"
" AND tl_pubs.PubCod=tl_comments.PubCod"
" ORDER BY tl_pubs.PubCod DESC LIMIT %u"
2019-11-18 08:38:34 +01:00
") AS comments"
" ORDER BY PubCod",
SocNot->NotCod,(unsigned) TL_PUB_COMMENT_TO_NOTE,
NumFinalCommentsToGet);
2019-02-27 13:11:19 +01:00
2019-11-18 08:38:34 +01:00
/*
Before clicking "See prev..." --> After clicking "See prev..."
_________________________________ _________________________________
| div con_<id> | | div con_<id> |
| (hidden) | | (visible) |
| _____________________________ | | _____________________________ |
| | v See only the latest | | | | v See only the latest | |
| |_____________________________| | | |_____________________________| |
|_________________________________| |_________________________________|
_________________________________ _________________________________
| div <id> | | div <id> updated |
| which content | | _____________________________ |
| will be updated via AJAX | | | ul com_<id> | |
| (parent of parent of form) | | | _________________________ | |
| | | | | li (comment 1) | | |
| | | | |_________________________| | |
| | | | | ... | | |
| | | | |_________________________| | |
| | | | | li (comment n) | | |
| | --> | | |_________________________| | |
| | | |_____________________________| |
| _____________________________ | | _____________________________ |
| | div exp_<id> | | | | div exp_<id> | |
| | _________________________ | | | | (hidden) | |
| | | form | | | | | | |
| | | _____________________ | | | | | _____________________ | |
| | | | ^ See prev.comments | | | | | | | ^ See prev.comments | | |
| | | |_____________________| | | | | | |_____________________| | |
| | |_________________________| | | | | | |
| |_____________________________| | | |_____________________________| |
|_________________________________| |_________________________________|
_________________________________ _________________________________
| ul com_<id> | | ul com_<id> |
| _________________________ | | _________________________ |
| | li (comment 1) | | | | li (comment 1) | |
| |_________________________| | | |_________________________| |
| | ... | | | | ... | |
| |_________________________| | | |_________________________| |
| | li (comment n) | | | | li (comment n) | |
| |_________________________| | | |_________________________| |
|_________________________________| |_________________________________|
*/
/***** Link to show initial hidden comments *****/
if (NumInitialComments)
{
/***** Create unique id for list of hidden comments *****/
Frm_SetUniqueId (IdComments);
/***** Link (initially hidden) to show only the latest comments *****/
TL_LinkToShowOnlyLatestComments (IdComments);
/***** Div which content will be updated via AJAX *****/
HTM_DIV_Begin ("id=\"%s\" class=\"TL_RIGHT_WIDTH\"",IdComments);
TL_FormToShowHiddenComments (ActShoHidSocComGbl,ActShoHidSocComUsr,
SocNot->NotCod,
IdComments,
NumInitialComments);
HTM_DIV_End ();
}
/***** List final visible comments *****/
if (NumFinalCommentsGot)
{
HTM_UL_Begin ("class=\"TL_LIST\"");
for (NumCom = 0;
NumCom < NumFinalCommentsGot;
2019-02-27 13:11:19 +01:00
NumCom++)
2019-03-12 21:25:55 +01:00
TL_WriteOneCommentInList (mysql_res);
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2016-01-07 15:19:54 +01:00
}
2016-01-11 19:28:43 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-01-07 15:19:54 +01:00
}
2019-11-18 08:38:34 +01:00
/*****************************************************************************/
/********** Form to show hidden coments in global or user timeline ***********/
/*****************************************************************************/
static void TL_FormToShowHiddenComments (Act_Action_t ActionGbl,Act_Action_t ActionUsr,
long NotCod,
char IdComments[Frm_MAX_BYTES_ID + 1],
unsigned NumInitialComments)
{
2019-11-18 14:21:01 +01:00
extern const char *The_ClassFormLinkInBox[The_NUM_THEMES];
2019-11-18 08:38:34 +01:00
extern const char *Txt_See_the_previous_X_COMMENTS;
char *OnSubmit;
HTM_DIV_Begin ("id=\"exp_%s\" class=\"TL_EXPAND_COM TL_RIGHT_WIDTH\"",
IdComments);
/***** Form and icon-text to show hidden comments *****/
/* Start form */
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
if (asprintf (&OnSubmit,"toggleComments('%s');"
"updateDivHiddenComments(this,"
"'act=%ld&ses=%s&NotCod=%ld&IdComments=%s&NumHidCom=%u&OtherUsrCod=%s');"
" return false;", // return false is necessary to not submit form
IdComments,
Act_GetActCod (ActionUsr),
Gbl.Session.Id,
NotCod,
IdComments,
NumInitialComments,
Gbl.Usrs.Other.UsrDat.EncryptedUsrCod) < 0)
Lay_NotEnoughMemoryExit ();
Frm_StartFormUniqueAnchorOnSubmit (ActUnk,"timeline",OnSubmit);
}
else
{
if (asprintf (&OnSubmit,"toggleComments('%s');"
"updateDivHiddenComments(this,"
"'act=%ld&ses=%s&NotCod=%ld&IdComments=%s&NumHidCom=%u');"
" return false;", // return false is necessary to not submit form
IdComments,
Act_GetActCod (ActionGbl),
Gbl.Session.Id,
NotCod,
IdComments,
NumInitialComments) < 0)
Lay_NotEnoughMemoryExit ();
Frm_StartFormUniqueAnchorOnSubmit (ActUnk,NULL,OnSubmit);
}
/* Put icon and text with link to show the first hidden comments */
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (NULL,The_ClassFormLinkInBox[Gbl.Prefs.Theme],NULL);
2019-12-30 18:49:52 +01:00
Ico_PutIconTextLink ("angle-up.svg",
2019-12-30 21:47:07 +01:00
Str_BuildStringLong (Txt_See_the_previous_X_COMMENTS,
(long) NumInitialComments));
Str_FreeString ();
2019-11-18 08:38:34 +01:00
HTM_BUTTON_End ();
/* End form */
Frm_EndForm ();
2019-12-13 23:38:29 +01:00
/* Free allocated memory */
2019-11-18 08:38:34 +01:00
free (OnSubmit);
HTM_DIV_End ();
}
/*****************************************************************************/
/********************** Write hidden comments via AJAX ***********************/
/*****************************************************************************/
void TL_ShowHiddenCommentsUsr (void)
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
/***** Show hidden comments *****/
TL_ShowHiddenCommentsGbl ();
}
void TL_ShowHiddenCommentsGbl (void)
{
long NotCod;
char IdComments[Frm_MAX_BYTES_ID + 1];
unsigned NumInitialCommentsToGet;
unsigned NumInitialCommentsGot;
/***** Get parameters *****/
/* Get note code */
NotCod = TL_GetParamNotCod ();
/* Get identifier */
Par_GetParToText ("IdComments",IdComments,Frm_MAX_BYTES_ID);
/* Get number of comments to get */
NumInitialCommentsToGet = (unsigned) Par_GetParToLong ("NumHidCom");
/***** Write HTML inside DIV with hidden comments *****/
NumInitialCommentsGot = TL_WriteHiddenComments (NotCod,IdComments,NumInitialCommentsToGet);
/***** Link to show the first comments *****/
TL_LinkToShowPreviousComments (IdComments,NumInitialCommentsGot);
}
/*****************************************************************************/
/**************************** Write hidden comments **************************/
/*****************************************************************************/
// Returns the number of comments got
static unsigned TL_WriteHiddenComments (long NotCod,
char IdComments[Frm_MAX_BYTES_ID + 1],
unsigned NumInitialCommentsToGet)
{
MYSQL_RES *mysql_res;
unsigned long NumInitialCommentsGot;
unsigned long NumCom;
/***** Get comments of this note from database *****/
NumInitialCommentsGot = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get comments",
2019-11-25 13:29:56 +01:00
"SELECT tl_pubs.PubCod," // row[0]
"tl_pubs.PublisherCod," // row[1]
"tl_pubs.NotCod," // row[2]
2019-11-18 08:38:34 +01:00
"UNIX_TIMESTAMP("
2019-11-25 13:29:56 +01:00
"tl_pubs.TimePublish)," // row[3]
"tl_comments.Txt," // row[4]
"tl_comments.MedCod" // row[5]
" FROM tl_pubs,tl_comments"
" WHERE tl_pubs.NotCod=%ld"
" AND tl_pubs.PubType=%u"
" AND tl_pubs.PubCod=tl_comments.PubCod"
" ORDER BY tl_pubs.PubCod"
2019-11-18 08:38:34 +01:00
" LIMIT %lu",
NotCod,(unsigned) TL_PUB_COMMENT_TO_NOTE,
NumInitialCommentsToGet);
/***** List with comments *****/
HTM_UL_Begin ("id=\"com_%s\" class=\"TL_LIST\"",IdComments);
for (NumCom = 0;
NumCom < NumInitialCommentsGot;
NumCom++)
TL_WriteOneCommentInList (mysql_res);
HTM_UL_End ();
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumInitialCommentsGot;
}
/*****************************************************************************/
/************************* Write a comment in list ***************************/
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_WriteOneCommentInList (MYSQL_RES *mysql_res)
2019-02-27 02:31:31 +01:00
{
MYSQL_ROW row;
2019-03-12 21:25:55 +01:00
struct TL_Comment SocCom;
2019-02-27 02:31:31 +01:00
/***** Initialize image *****/
2019-11-24 23:51:03 +01:00
Med_MediaConstructor (&SocCom.Content.Media);
2019-02-27 02:31:31 +01:00
2019-03-12 21:25:55 +01:00
/***** Get data of comment *****/
2019-02-27 02:31:31 +01:00
row = mysql_fetch_row (mysql_res);
2019-03-12 21:25:55 +01:00
TL_GetDataOfCommentFromRow (row,&SocCom);
2019-02-27 02:31:31 +01:00
2019-03-12 21:25:55 +01:00
/***** Write comment *****/
TL_WriteComment (&SocCom,
2019-03-28 18:03:42 +01:00
TL_TOP_MESSAGE_NONE,-1L,
false); // Not alone
2019-02-27 02:31:31 +01:00
/***** Free image *****/
2019-11-24 23:51:03 +01:00
Med_MediaDestructor (&SocCom.Content.Media);
2019-02-27 02:31:31 +01:00
}
2019-11-18 08:38:34 +01:00
/*****************************************************************************/
/****************** Link to show only the latest comments ********************/
/*****************************************************************************/
static void TL_LinkToShowOnlyLatestComments (const char IdComments[Frm_MAX_BYTES_ID + 1])
{
extern const char *Txt_See_only_the_latest_COMMENTS;
/***** Icon and text to show only the latest comments ****/
HTM_DIV_Begin ("id=\"con_%s\" class=\"TL_EXPAND_COM TL_RIGHT_WIDTH\""
" style=\"display:none;\"", // Hidden
IdComments);
TL_PutIconToToggleComments (IdComments,"angle-down.svg",
Txt_See_only_the_latest_COMMENTS);
HTM_DIV_End ();
}
/*****************************************************************************/
/********************* Link to show the first comments ***********************/
/*****************************************************************************/
static void TL_LinkToShowPreviousComments (const char IdComments[Frm_MAX_BYTES_ID + 1],
unsigned NumInitialComments)
{
extern const char *Txt_See_the_previous_X_COMMENTS;
/***** Icon and text to show only the latest comments ****/
HTM_DIV_Begin ("id=\"exp_%s\" class=\"TL_EXPAND_COM TL_RIGHT_WIDTH\""
" style=\"display:none;\"", // Hidden
IdComments);
2019-12-30 18:49:52 +01:00
TL_PutIconToToggleComments (IdComments,"angle-up.svg",
2019-12-30 21:47:07 +01:00
Str_BuildStringLong (Txt_See_the_previous_X_COMMENTS,
(long) NumInitialComments));
Str_FreeString ();
2019-11-18 08:38:34 +01:00
HTM_DIV_End ();
}
2019-02-27 02:31:31 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********** Put an icon to toggle on/off comments in a publication ***********/
2019-02-27 02:31:31 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_PutIconToToggleComments (const char *UniqueId,
2019-03-13 10:23:41 +01:00
const char *Icon,const char *Text)
2019-02-27 02:31:31 +01:00
{
2019-11-20 10:17:42 +01:00
extern const char *The_ClassFormLinkInBox[The_NUM_THEMES];
char *OnClick;
if (asprintf (&OnClick,"toggleComments('%s')",UniqueId) < 0)
Lay_NotEnoughMemoryExit ();
2019-02-27 02:31:31 +01:00
2019-03-02 21:49:11 +01:00
/***** Link to toggle on/off some divs *****/
2019-11-20 10:17:42 +01:00
HTM_BUTTON_BUTTON_Begin (Text,The_ClassFormLinkInBox[Gbl.Prefs.Theme],OnClick);
2019-02-27 02:31:31 +01:00
Ico_PutIconTextLink (Icon,Text);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_End ();
free (OnClick);
2019-02-27 02:31:31 +01:00
}
2016-01-08 02:55:18 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************************** Write comment ******************************/
2016-01-08 02:55:18 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_WriteComment (struct TL_Comment *SocCom,
TL_TopMessage_t TopMessage,long UsrCod,
bool ShowCommentAlone) // Comment is shown alone, not in a list
2016-01-08 02:55:18 +01:00
{
extern const char *Txt_Forum;
extern const char *Txt_Course;
extern const char *Txt_Degree;
extern const char *Txt_Centre;
extern const char *Txt_Institution;
struct UsrData UsrDat;
bool IAmTheAuthor;
bool ShowPhoto = false;
2017-01-28 15:58:46 +01:00
char PhotoURL[PATH_MAX + 1];
2019-02-25 02:02:10 +01:00
static unsigned NumDiv = 0; // Used to create unique div id for fav
NumDiv++;
2016-01-08 02:55:18 +01:00
2016-01-11 00:53:21 +01:00
if (ShowCommentAlone)
2016-01-08 02:55:18 +01:00
{
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,NULL,
NULL,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE);
2016-01-20 15:19:02 +01:00
/***** Write sharer/commenter if distinct to author *****/
2019-03-12 21:25:55 +01:00
TL_WriteTopMessage (TopMessage,UsrCod);
2016-01-20 15:19:02 +01:00
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_LEFT_PHOTO\"");
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_RIGHT_CONT TL_RIGHT_WIDTH\"");
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("class=\"LIST_LEFT\"");
2016-01-08 02:55:18 +01:00
}
/***** Start list item *****/
2019-10-26 22:49:13 +02:00
if (ShowCommentAlone)
HTM_LI_Begin (NULL);
else
HTM_LI_Begin ("class=\"TL_COM\"");
2016-01-08 02:55:18 +01:00
2016-01-25 12:32:13 +01:00
if (SocCom->PubCod <= 0 ||
2016-01-08 02:55:18 +01:00
SocCom->NotCod <= 0 ||
SocCom->UsrCod <= 0)
2019-03-12 21:25:55 +01:00
Ale_ShowAlert (Ale_ERROR,"Error in comment.");
2016-01-08 02:55:18 +01:00
else
{
/***** Get author's data *****/
Usr_UsrDataConstructor (&UsrDat);
UsrDat.UsrCod = SocCom->UsrCod;
2019-03-19 13:22:14 +01:00
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS);
2019-03-28 18:03:42 +01:00
IAmTheAuthor = Usr_ItsMe (UsrDat.UsrCod);
2016-01-08 02:55:18 +01:00
/***** Left: write author's photo *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_COM_PHOTO\"");
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (&UsrDat,PhotoURL);
2016-01-08 02:55:18 +01:00
Pho_ShowUsrPhoto (&UsrDat,ShowPhoto ? PhotoURL :
NULL,
2016-01-14 10:31:09 +01:00
"PHOTO30x40",Pho_ZOOM,true); // Use unique id
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-08 02:55:18 +01:00
2016-04-08 23:30:43 +02:00
/***** Right: author's name, time, content, image and buttons *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_COM_CONT TL_COMM_WIDTH\"");
2016-01-08 02:55:18 +01:00
/* Write author's full name and nickname */
2019-03-12 21:25:55 +01:00
TL_WriteAuthorComment (&UsrDat);
2016-01-08 02:55:18 +01:00
/* Write date and time */
2019-03-12 21:25:55 +01:00
TL_WriteDateTime (SocCom->DateTimeUTC);
2016-01-08 02:55:18 +01:00
2019-03-12 21:25:55 +01:00
/* Write content of the comment */
2019-11-24 23:51:03 +01:00
if (SocCom->Content.Txt[0])
2019-03-29 11:24:02 +01:00
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_TXT\"");
2019-11-24 23:51:03 +01:00
Msg_WriteMsgContent (SocCom->Content.Txt,Cns_MAX_BYTES_LONG_TEXT,true,false);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-03-29 11:24:02 +01:00
}
2016-01-08 02:55:18 +01:00
2016-04-08 23:30:43 +02:00
/* Show image */
2019-11-24 23:51:03 +01:00
Med_ShowMedia (&SocCom->Content.Media,"TL_COM_MED_CONT TL_COMM_WIDTH",
"TL_COM_MED TL_COMM_WIDTH");
2016-04-08 23:30:43 +02:00
2019-03-29 11:24:02 +01:00
/* Start foot container */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_FOOT TL_COMM_WIDTH\"");
2019-03-29 00:57:51 +01:00
2019-03-29 11:24:02 +01:00
/* Fav zone */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"fav_com_%s_%u\" class=\"TL_FAV_COM TL_FAV_WIDTH\"",
Gbl.UniqueNameEncrypted,NumDiv);
2019-03-29 01:23:33 +01:00
TL_PutFormToFavUnfComment (SocCom,TL_SHOW_A_FEW_USRS);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-19 12:54:27 +01:00
2019-03-12 21:25:55 +01:00
/* Put icon to remove this comment */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_REM\"");
2016-01-11 00:53:21 +01:00
if (IAmTheAuthor && !ShowCommentAlone)
2019-03-12 21:25:55 +01:00
TL_PutFormToRemoveComment (SocCom->PubCod);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-08 02:55:18 +01:00
2019-03-29 11:24:02 +01:00
/* End foot container */
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-03-29 00:57:51 +01:00
2016-01-08 02:55:18 +01:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
/***** End list item *****/
2019-10-26 22:49:13 +02:00
HTM_LI_End ();
2016-01-08 02:55:18 +01:00
2016-01-11 00:53:21 +01:00
if (ShowCommentAlone)
2016-01-08 02:55:18 +01:00
{
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-01-08 02:55:18 +01:00
}
}
2016-01-13 17:47:22 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********* Write name and nickname of author of a comment to a note **********/
2016-01-13 17:47:22 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_WriteAuthorComment (struct UsrData *UsrDat)
2016-01-13 17:47:22 +01:00
{
2017-02-17 01:59:58 +01:00
extern const char *Txt_My_public_profile;
extern const char *Txt_Another_user_s_profile;
2018-10-10 23:56:42 +02:00
bool ItsMe = Usr_ItsMe (UsrDat->UsrCod);
2016-01-13 17:47:22 +01:00
/***** Show user's name inside form to go to user's public profile *****/
2018-11-09 20:47:39 +01:00
Frm_StartFormUnique (ActSeeOthPubPrf);
2017-02-17 06:32:57 +01:00
Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (ItsMe ? Txt_My_public_profile :
2019-11-20 11:04:54 +01:00
Txt_Another_user_s_profile,
"BT_LINK TL_COM_AUTHOR TL_COMM_AUTHOR_WIDTH DAT_BOLD",NULL);
2019-11-10 12:36:37 +01:00
HTM_Txt (UsrDat->FullName);
2019-11-18 20:12:10 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-01-13 17:47:22 +01:00
}
2016-01-07 16:45:35 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************************* Form to remove comment ****************************/
2016-01-07 16:45:35 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_PutFormToRemoveComment (long PubCod)
2016-01-07 16:45:35 +01:00
{
2016-01-08 01:53:37 +01:00
extern const char *Txt_Remove;
2016-01-07 16:45:35 +01:00
2019-03-12 21:25:55 +01:00
/***** Form to remove publication *****/
TL_FormStart (ActReqRemSocComGbl,ActReqRemSocComUsr);
TL_PutHiddenParamPubCod (PubCod);
2019-03-29 00:57:51 +01:00
Ico_PutIconLink ("trash.svg",Txt_Remove);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-01-07 16:45:35 +01:00
}
2016-01-04 11:58:36 +01:00
/*****************************************************************************/
2016-01-05 04:54:00 +01:00
/*********************** Put disabled icon to share **************************/
2016-01-04 11:58:36 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_PutDisabledIconShare (unsigned NumShared)
2016-01-04 11:58:36 +01:00
{
2019-03-12 21:25:55 +01:00
extern const char *Txt_TIMELINE_NOTE_Shared_by_X_USERS;
extern const char *Txt_TIMELINE_NOTE_Not_shared_by_anyone;
2016-01-05 21:30:10 +01:00
2019-12-30 18:08:31 +01:00
/***** Disabled icon to share *****/
2016-01-05 21:58:25 +01:00
if (NumShared)
2019-12-30 18:08:31 +01:00
{
Ico_PutDivIcon ("TL_ICO_DISABLED",TL_ICON_SHARE,
2019-12-30 21:47:07 +01:00
Str_BuildStringLong (Txt_TIMELINE_NOTE_Shared_by_X_USERS,
(long) NumShared));
Str_FreeString ();
2019-12-30 18:08:31 +01:00
}
2016-01-05 21:58:25 +01:00
else
2019-12-30 18:08:31 +01:00
Ico_PutDivIcon ("TL_ICO_DISABLED",TL_ICON_SHARE,
Txt_TIMELINE_NOTE_Not_shared_by_anyone);
2016-01-04 11:58:36 +01:00
}
2016-01-19 00:50:35 +01:00
/*****************************************************************************/
/****************** Put disabled icon to mark as favourite *******************/
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_PutDisabledIconFav (unsigned NumFavs)
2016-01-19 00:50:35 +01:00
{
2019-03-12 21:25:55 +01:00
extern const char *Txt_TIMELINE_NOTE_Favourited_by_X_USERS;
extern const char *Txt_TIMELINE_NOTE_Not_favourited_by_anyone;
2016-01-19 00:50:35 +01:00
2019-12-30 18:08:31 +01:00
/***** Disabled icon to mark as favourite *****/
2016-01-19 00:50:35 +01:00
if (NumFavs)
2019-12-30 18:08:31 +01:00
{
Ico_PutDivIcon ("TL_ICO_DISABLED",TL_ICON_FAV,
2019-12-30 21:47:07 +01:00
Str_BuildStringLong (Txt_TIMELINE_NOTE_Favourited_by_X_USERS,
(long) NumFavs));
Str_FreeString ();
2019-12-30 18:08:31 +01:00
}
2016-01-19 00:50:35 +01:00
else
2019-12-30 18:08:31 +01:00
Ico_PutDivIcon ("TL_ICO_DISABLED",TL_ICON_FAV,
Txt_TIMELINE_NOTE_Not_favourited_by_anyone);
2016-01-19 00:50:35 +01:00
}
2015-12-30 02:08:08 +01:00
/*****************************************************************************/
2019-03-28 15:22:38 +01:00
/*********************** Form to share/unshare note **************************/
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2019-03-29 00:57:51 +01:00
static void TL_PutFormToSeeAllSharersNote (const struct TL_Note *SocNot,
TL_HowMany_t HowMany)
2019-03-28 15:22:38 +01:00
{
2019-03-29 00:57:51 +01:00
extern const char *Txt_View_all_USERS;
2019-11-08 01:10:32 +01:00
char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1];
2019-03-28 15:22:38 +01:00
2019-03-29 00:57:51 +01:00
switch (HowMany)
{
case TL_SHOW_A_FEW_USRS:
/***** Form and icon to mark note as favourite *****/
sprintf (ParamCod,"NotCod=%ld",SocNot->NotCod);
TL_FormFavSha (ActAllShaSocNotGbl,ActAllShaSocNotUsr,ParamCod,
TL_ICON_ELLIPSIS,Txt_View_all_USERS);
break;
case TL_SHOW_ALL_USRS:
Ico_PutIconOff (TL_ICON_ELLIPSIS,Txt_View_all_USERS);
break;
}
2019-03-28 15:22:38 +01:00
}
2019-03-29 00:57:51 +01:00
static void TL_PutFormToShaNote (const struct TL_Note *SocNot)
2016-01-01 20:19:43 +01:00
{
extern const char *Txt_Share;
2019-11-08 01:10:32 +01:00
char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1];
2016-01-01 20:19:43 +01:00
2019-03-12 21:25:55 +01:00
/***** Form and icon to mark note as favourite *****/
2019-02-25 03:14:27 +01:00
sprintf (ParamCod,"NotCod=%ld",SocNot->NotCod);
2019-03-12 21:25:55 +01:00
TL_FormFavSha (ActShaSocNotGbl,ActShaSocNotUsr,ParamCod,
2019-03-29 00:57:51 +01:00
TL_ICON_SHARE,Txt_Share);
2016-01-01 20:19:43 +01:00
}
2019-03-29 00:57:51 +01:00
static void TL_PutFormToUnsNote (const struct TL_Note *SocNot)
2019-02-24 21:45:46 +01:00
{
2019-03-12 21:25:55 +01:00
extern const char *Txt_TIMELINE_NOTE_Shared;
2019-11-08 01:10:32 +01:00
char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1];
2019-02-24 21:45:46 +01:00
2019-03-12 21:25:55 +01:00
/***** Form and icon to mark note as favourite *****/
2019-02-25 03:14:27 +01:00
sprintf (ParamCod,"NotCod=%ld",SocNot->NotCod);
2019-03-12 21:25:55 +01:00
TL_FormFavSha (ActUnsSocNotGbl,ActUnsSocNotUsr,ParamCod,
2019-03-29 00:57:51 +01:00
TL_ICON_SHARED,Txt_TIMELINE_NOTE_Shared);
2019-02-24 21:45:46 +01:00
}
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2019-03-28 15:22:38 +01:00
/************************** Form to fav/unfav note ***************************/
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2019-03-29 00:57:51 +01:00
static void TL_PutFormToSeeAllFaversNote (const struct TL_Note *SocNot,
TL_HowMany_t HowMany)
2019-03-28 15:22:38 +01:00
{
2019-03-29 00:57:51 +01:00
extern const char *Txt_View_all_USERS;
2019-11-08 01:10:32 +01:00
char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1];
2019-03-28 15:22:38 +01:00
2019-03-29 00:57:51 +01:00
switch (HowMany)
{
case TL_SHOW_A_FEW_USRS:
/***** Form and icon to mark note as favourite *****/
sprintf (ParamCod,"NotCod=%ld",SocNot->NotCod);
TL_FormFavSha (ActAllFavSocNotGbl,ActAllFavSocNotUsr,ParamCod,
TL_ICON_ELLIPSIS,Txt_View_all_USERS);
break;
case TL_SHOW_ALL_USRS:
Ico_PutIconOff (TL_ICON_ELLIPSIS,Txt_View_all_USERS);
break;
}
2019-03-28 15:22:38 +01:00
}
2019-03-12 21:25:55 +01:00
static void TL_PutFormToFavNote (const struct TL_Note *SocNot)
2019-02-23 13:00:25 +01:00
{
extern const char *Txt_Mark_as_favourite;
2019-11-08 01:10:32 +01:00
char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1];
2019-02-23 13:00:25 +01:00
2019-03-12 21:25:55 +01:00
/***** Form and icon to mark note as favourite *****/
2019-02-25 03:14:27 +01:00
sprintf (ParamCod,"NotCod=%ld",SocNot->NotCod);
2019-03-12 21:25:55 +01:00
TL_FormFavSha (ActFavSocNotGbl,ActFavSocNotUsr,ParamCod,
2019-03-29 00:57:51 +01:00
TL_ICON_FAV,Txt_Mark_as_favourite);
2019-02-23 13:00:25 +01:00
}
2019-03-29 00:57:51 +01:00
static void TL_PutFormToUnfNote (const struct TL_Note *SocNot)
2019-02-23 13:00:25 +01:00
{
2019-03-12 21:25:55 +01:00
extern const char *Txt_TIMELINE_NOTE_Favourite;
2019-11-08 01:10:32 +01:00
char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1];
2019-02-23 13:00:25 +01:00
2019-03-12 21:25:55 +01:00
/***** Form and icon to unfav (remove mark as favourite) note *****/
2019-02-25 03:14:27 +01:00
sprintf (ParamCod,"NotCod=%ld",SocNot->NotCod);
2019-03-12 21:25:55 +01:00
TL_FormFavSha (ActUnfSocNotGbl,ActUnfSocNotUsr,ParamCod,
2019-03-29 00:57:51 +01:00
TL_ICON_FAVED,Txt_TIMELINE_NOTE_Favourite);
2016-01-19 00:50:35 +01:00
}
/*****************************************************************************/
2019-03-28 15:22:38 +01:00
/************************** Form to fav/unfav comment ************************/
2016-01-19 00:50:35 +01:00
/*****************************************************************************/
2019-03-29 00:57:51 +01:00
static void TL_PutFormToSeeAllFaversComment (const struct TL_Comment *SocCom,
TL_HowMany_t HowMany)
2019-03-28 15:22:38 +01:00
{
2019-03-29 00:57:51 +01:00
extern const char *Txt_View_all_USERS;
2019-11-08 01:10:32 +01:00
char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1];
2019-03-28 15:22:38 +01:00
2019-03-29 00:57:51 +01:00
switch (HowMany)
{
case TL_SHOW_A_FEW_USRS:
/***** Form and icon to mark comment as favourite *****/
sprintf (ParamCod,"PubCod=%ld",SocCom->PubCod);
TL_FormFavSha (ActAllFavSocComGbl,ActAllFavSocComUsr,ParamCod,
TL_ICON_ELLIPSIS,Txt_View_all_USERS);
break;
case TL_SHOW_ALL_USRS:
Ico_PutIconOff (TL_ICON_ELLIPSIS,Txt_View_all_USERS);
break;
}
2019-03-28 15:22:38 +01:00
}
2019-03-28 19:44:59 +01:00
static void TL_PutFormToFavComment (const struct TL_Comment *SocCom)
2016-01-01 20:19:43 +01:00
{
2019-02-24 21:45:46 +01:00
extern const char *Txt_Mark_as_favourite;
2019-11-08 01:10:32 +01:00
char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1];
2019-02-24 21:45:46 +01:00
2019-03-12 21:25:55 +01:00
/***** Form and icon to mark comment as favourite *****/
2019-02-25 03:14:27 +01:00
sprintf (ParamCod,"PubCod=%ld",SocCom->PubCod);
2019-03-12 21:25:55 +01:00
TL_FormFavSha (ActFavSocComGbl,ActFavSocComUsr,ParamCod,
2019-03-29 00:57:51 +01:00
TL_ICON_FAV,Txt_Mark_as_favourite);
2016-01-01 20:19:43 +01:00
}
2019-03-29 00:57:51 +01:00
static void TL_PutFormToUnfComment (const struct TL_Comment *SocCom)
2016-01-19 21:07:52 +01:00
{
2019-03-12 21:25:55 +01:00
extern const char *Txt_TIMELINE_NOTE_Favourite;
2019-11-08 01:10:32 +01:00
char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1];
2016-01-19 21:07:52 +01:00
2019-03-12 21:25:55 +01:00
/***** Form and icon to unfav (remove mark as favourite) comment *****/
2019-02-25 03:14:27 +01:00
sprintf (ParamCod,"PubCod=%ld",SocCom->PubCod);
2019-03-12 21:25:55 +01:00
TL_FormFavSha (ActUnfSocComGbl,ActUnfSocComUsr,ParamCod,
2019-03-29 00:57:51 +01:00
TL_ICON_FAVED,Txt_TIMELINE_NOTE_Favourite);
2016-01-19 21:07:52 +01:00
}
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************************ Form to remove publication *************************/
2015-12-30 02:08:08 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_PutFormToRemovePublication (long NotCod)
2015-12-30 02:08:08 +01:00
{
extern const char *Txt_Remove;
2019-03-12 21:25:55 +01:00
/***** Form to remove publication *****/
TL_FormStart (ActReqRemSocPubGbl,ActReqRemSocPubUsr);
TL_PutHiddenParamNotCod (NotCod);
2019-03-29 00:57:51 +01:00
Ico_PutIconLink ("trash.svg",Txt_Remove);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-12-30 02:08:08 +01:00
}
2016-01-05 21:30:10 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/****************** Put parameter with the code of a note ********************/
2016-01-05 21:30:10 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_PutHiddenParamNotCod (long NotCod)
2016-01-05 21:30:10 +01:00
{
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamLong (NULL,"NotCod",NotCod);
2016-01-05 21:30:10 +01:00
}
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/*************** Put parameter with the code of a publication ****************/
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_PutHiddenParamPubCod (long PubCod)
2016-01-08 01:53:37 +01:00
{
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamLong (NULL,"PubCod",PubCod);
2016-01-08 01:53:37 +01:00
}
2016-01-05 21:30:10 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/****************** Get parameter with the code of a note ********************/
2016-01-05 21:30:10 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static long TL_GetParamNotCod (void)
2016-01-05 21:30:10 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Get note code *****/
2017-01-28 20:32:50 +01:00
return Par_GetParToLong ("NotCod");
2016-01-05 21:30:10 +01:00
}
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/**************** Get parameter with the code of a publication ***************/
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static long TL_GetParamPubCod (void)
2016-01-08 01:53:37 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Get comment code *****/
2017-01-28 20:32:50 +01:00
return Par_GetParToLong ("PubCod");
2016-01-08 01:53:37 +01:00
}
2016-01-07 00:42:35 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************************* Comment a note ******************************/
2016-01-07 00:42:35 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_ReceiveCommentUsr (void)
2016-01-07 00:42:35 +01:00
{
2019-12-05 15:47:23 +01:00
long NotCod;
2016-01-07 00:42:35 +01:00
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
/***** Show user's profile *****/
2016-06-12 19:55:33 +02:00
Prf_ShowUserProfile (&Gbl.Usrs.Other.UsrDat);
2016-01-07 00:42:35 +01:00
/***** Start section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_Begin (TL_TIMELINE_SECTION_ID);
2016-01-07 00:42:35 +01:00
2019-03-29 01:23:33 +01:00
/***** Receive comment in a note
and write updated timeline after commenting (user) *****/
2019-12-05 15:47:23 +01:00
NotCod = TL_ReceiveComment ();
TL_ShowTimelineUsrHighlightingNot (NotCod);
2016-01-07 00:42:35 +01:00
/***** End section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_End ();
2016-01-07 00:42:35 +01:00
}
2019-03-29 01:23:33 +01:00
void TL_ReceiveCommentGbl (void)
{
long NotCod;
/***** Receive comment in a note *****/
NotCod = TL_ReceiveComment ();
/***** Write updated timeline after commenting (global) *****/
TL_ShowTimelineGblHighlightingNot (NotCod);
}
2019-03-12 21:25:55 +01:00
static long TL_ReceiveComment (void)
2016-01-07 00:42:35 +01:00
{
2016-01-11 09:59:36 +01:00
extern const char *Txt_The_original_post_no_longer_exists;
2019-11-24 23:51:03 +01:00
struct PostContent Content;
2019-03-12 21:25:55 +01:00
struct TL_Note SocNot;
struct TL_Publication SocPub;
2016-01-07 14:21:21 +01:00
2019-03-12 21:25:55 +01:00
/***** Get data of note *****/
SocNot.NotCod = TL_GetParamNotCod ();
TL_GetDataOfNoteByCod (&SocNot);
2016-01-07 14:21:21 +01:00
2016-01-11 02:15:23 +01:00
if (SocNot.NotCod > 0)
2016-01-09 15:00:14 +01:00
{
2016-01-11 02:15:23 +01:00
/***** Get the content of the comment *****/
2019-11-24 23:51:03 +01:00
Par_GetParAndChangeFormat ("Txt",Content.Txt,Cns_MAX_BYTES_LONG_TEXT,
2016-01-11 02:15:23 +01:00
Str_TO_RIGOROUS_HTML,true);
2016-04-08 23:30:43 +02:00
/***** Initialize image *****/
2019-11-24 23:51:03 +01:00
Med_MediaConstructor (&Content.Media);
2016-04-08 23:30:43 +02:00
/***** Get attached image (action, file and title) *****/
2019-11-24 23:51:03 +01:00
Content.Media.Width = TL_IMAGE_SAVED_MAX_WIDTH;
Content.Media.Height = TL_IMAGE_SAVED_MAX_HEIGHT;
Content.Media.Quality = TL_IMAGE_SAVED_QUALITY;
2020-03-17 00:35:11 +01:00
Med_GetMediaFromForm (-1L,-1L,-1,&Content.Media,NULL,NULL);
2019-03-17 14:47:58 +01:00
Ale_ShowAlerts (NULL);
2016-04-08 23:30:43 +02:00
2019-11-24 23:51:03 +01:00
if (Content.Txt[0] || // Text not empty
Content.Media.Status == Med_PROCESSED) // A media is attached
2016-01-11 01:46:33 +01:00
{
2019-03-19 11:20:29 +01:00
/***** Store media in filesystem and database *****/
2019-11-24 23:51:03 +01:00
Med_RemoveKeepOrStoreMedia (-1L,&Content.Media);
2019-03-18 15:42:22 +01:00
2016-01-16 02:54:13 +01:00
/***** Publish *****/
2019-03-06 10:13:39 +01:00
/* Insert into publications */
2016-01-16 02:54:13 +01:00
SocPub.NotCod = SocNot.NotCod;
SocPub.PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod;
2019-03-12 21:25:55 +01:00
SocPub.PubType = TL_PUB_COMMENT_TO_NOTE;
TL_PublishNoteInTimeline (&SocPub); // Set SocPub.PubCod
2016-01-16 02:54:13 +01:00
/* Insert comment content in the database */
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not store comment content",
2019-11-25 13:29:56 +01:00
"INSERT INTO tl_comments"
2019-11-25 09:06:27 +01:00
" (PubCod,Txt,MedCod)"
2018-11-02 19:37:11 +01:00
" VALUES"
2019-03-18 15:42:22 +01:00
" (%ld,'%s',%ld)",
2018-11-02 19:37:11 +01:00
SocPub.PubCod,
2019-11-24 23:51:03 +01:00
Content.Txt,
Content.Media.MedCod);
2016-04-08 23:30:43 +02:00
2016-01-25 11:43:14 +01:00
/***** Store notifications about the new comment *****/
2016-01-23 19:11:07 +01:00
Ntf_StoreNotifyEventsToAllUsrs (Ntf_EVENT_TIMELINE_COMMENT,SocPub.PubCod);
2016-01-22 12:55:28 +01:00
2016-01-25 11:43:14 +01:00
/***** Analyze content and store notifications about mentions *****/
2019-11-24 23:51:03 +01:00
Str_AnalyzeTxtAndStoreNotifyEventToMentionedUsrs (SocPub.PubCod,Content.Txt);
2016-01-11 01:46:33 +01:00
}
2016-04-08 23:30:43 +02:00
/***** Free image *****/
2019-11-24 23:51:03 +01:00
Med_MediaDestructor (&Content.Media);
2016-01-11 01:46:33 +01:00
}
2016-01-11 02:15:23 +01:00
else
2019-02-16 18:25:41 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
2016-01-16 02:01:14 +01:00
return SocNot.NotCod;
2016-01-11 01:46:33 +01:00
}
2016-01-11 01:30:23 +01:00
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************************** Share a note *******************************/
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2019-03-29 01:23:33 +01:00
void TL_ShowAllSharersNoteUsr (void)
2019-03-28 15:22:38 +01:00
{
2019-03-29 01:23:33 +01:00
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
2019-03-28 15:22:38 +01:00
2019-03-29 01:23:33 +01:00
/***** Show all sharers *****/
TL_ShowAllSharersNoteGbl ();
2019-03-28 15:22:38 +01:00
}
2019-03-29 01:23:33 +01:00
void TL_ShowAllSharersNoteGbl (void)
2019-03-28 15:22:38 +01:00
{
struct TL_Note SocNot;
/***** Get data of note *****/
SocNot.NotCod = TL_GetParamNotCod ();
TL_GetDataOfNoteByCod (&SocNot);
/***** Write HTML inside DIV with form to share/unshare *****/
2019-03-29 01:23:33 +01:00
TL_PutFormToShaUnsNote (&SocNot,TL_SHOW_ALL_USRS);
2019-03-28 15:22:38 +01:00
}
2019-03-29 01:23:33 +01:00
void TL_ShaNoteUsr (void)
2016-01-02 01:56:48 +01:00
{
2019-03-29 01:23:33 +01:00
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
2016-01-15 15:01:11 +01:00
2019-03-12 21:25:55 +01:00
/***** Share note *****/
2019-03-29 01:23:33 +01:00
TL_ShaNoteGbl ();
2016-01-02 01:56:48 +01:00
}
2019-03-29 01:23:33 +01:00
void TL_ShaNoteGbl (void)
2016-01-02 01:56:48 +01:00
{
2019-03-12 21:25:55 +01:00
struct TL_Note SocNot;
2016-01-15 15:01:11 +01:00
2019-03-12 21:25:55 +01:00
/***** Share note *****/
2019-03-28 19:44:59 +01:00
TL_ShaNote (&SocNot);
2016-01-02 01:56:48 +01:00
2019-02-25 02:02:10 +01:00
/***** Write HTML inside DIV with form to unshare *****/
2019-03-29 01:23:33 +01:00
TL_PutFormToShaUnsNote (&SocNot,TL_SHOW_A_FEW_USRS);
2016-01-02 01:56:48 +01:00
}
2019-03-29 00:57:51 +01:00
static void TL_PutFormToShaUnsNote (const struct TL_Note *SocNot,
TL_HowMany_t HowMany)
2019-03-28 19:44:59 +01:00
{
2019-03-28 19:55:40 +01:00
bool IAmTheAuthor;
bool IAmASharerOfThisSocNot;
/***** Put form to share/unshare this note *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_ICO\"");
2019-03-28 19:55:40 +01:00
IAmTheAuthor = Usr_ItsMe (SocNot->UsrCod);
if (SocNot->Unavailable || // Unavailable notes can not be shared
IAmTheAuthor) // I am the author
/* Put disabled icon */
TL_PutDisabledIconShare (SocNot->NumShared);
else // Available and I am not the author
{
/* Put icon to share/unshare */
IAmASharerOfThisSocNot = TL_CheckIfNoteIsSharedByUsr (SocNot->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
if (IAmASharerOfThisSocNot) // I have shared this note
2019-03-29 00:57:51 +01:00
TL_PutFormToUnsNote (SocNot);
2019-03-28 19:55:40 +01:00
else // I have not shared this note
2019-03-29 00:57:51 +01:00
TL_PutFormToShaNote (SocNot);
2019-03-28 19:55:40 +01:00
}
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-03-28 19:44:59 +01:00
2019-03-28 19:55:40 +01:00
/***** Show who have shared this note *****/
2019-03-29 00:57:51 +01:00
TL_ShowUsrsWhoHaveSharedNote (SocNot,HowMany);
2019-03-28 19:44:59 +01:00
}
static void TL_ShaNote (struct TL_Note *SocNot)
2016-01-01 20:19:43 +01:00
{
2016-01-11 09:59:36 +01:00
extern const char *Txt_The_original_post_no_longer_exists;
2019-03-12 21:25:55 +01:00
struct TL_Publication SocPub;
2018-10-10 23:56:42 +02:00
bool ItsMe;
2016-01-25 20:28:33 +01:00
long OriginalPubCod;
2016-01-01 20:19:43 +01:00
2019-03-12 21:25:55 +01:00
/***** Get data of note *****/
SocNot->NotCod = TL_GetParamNotCod ();
TL_GetDataOfNoteByCod (SocNot);
2016-01-02 14:56:38 +01:00
2019-02-25 02:02:10 +01:00
if (SocNot->NotCod > 0)
2016-01-01 20:19:43 +01:00
{
2019-02-25 02:02:10 +01:00
ItsMe = Usr_ItsMe (SocNot->UsrCod);
2018-10-10 23:56:42 +02:00
if (Gbl.Usrs.Me.Logged && !ItsMe) // I am not the author
2019-03-12 21:25:55 +01:00
if (!TL_CheckIfNoteIsSharedByUsr (SocNot->NotCod,
2016-01-24 13:46:57 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod)) // Not yet shared by me
{
2019-03-12 21:25:55 +01:00
/***** Share (publish note in timeline) *****/
2019-02-25 02:02:10 +01:00
SocPub.NotCod = SocNot->NotCod;
2016-01-24 13:46:57 +01:00
SocPub.PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod;
2019-03-12 21:25:55 +01:00
SocPub.PubType = TL_PUB_SHARED_NOTE;
TL_PublishNoteInTimeline (&SocPub); // Set SocPub.PubCod
2016-01-24 13:46:57 +01:00
2019-03-12 21:25:55 +01:00
/* Update number of times this note is shared */
TL_UpdateNumTimesANoteHasBeenShared (SocNot);
2016-01-25 11:43:14 +01:00
2016-01-25 18:57:37 +01:00
/**** Create notification about shared post
for the author of the post ***/
2019-03-12 21:25:55 +01:00
OriginalPubCod = TL_GetPubCodOfOriginalNote (SocNot->NotCod);
2016-01-25 20:28:33 +01:00
if (OriginalPubCod > 0)
2019-03-12 21:25:55 +01:00
TL_CreateNotifToAuthor (SocNot->UsrCod,OriginalPubCod,Ntf_EVENT_TIMELINE_SHARE);
2016-01-24 13:46:57 +01:00
}
2016-01-01 20:19:43 +01:00
}
}
2016-01-19 00:50:35 +01:00
/*****************************************************************************/
2019-03-28 19:44:59 +01:00
/********************** Mark/unmark a note as favourite **********************/
2016-01-19 00:50:35 +01:00
/*****************************************************************************/
2019-03-29 01:23:33 +01:00
void TL_ShowAllFaversNoteUsr (void)
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
/***** Show all favers *****/
TL_ShowAllFaversNoteGbl ();
}
2019-03-28 15:22:38 +01:00
void TL_ShowAllFaversNoteGbl (void)
{
struct TL_Note SocNot;
/***** Get data of note *****/
SocNot.NotCod = TL_GetParamNotCod ();
TL_GetDataOfNoteByCod (&SocNot);
/***** Write HTML inside DIV with form to fav/unfav *****/
2019-03-29 01:23:33 +01:00
TL_PutFormToFavUnfNote (&SocNot,TL_SHOW_ALL_USRS);
2019-03-28 15:22:38 +01:00
}
2019-03-29 01:23:33 +01:00
void TL_FavNoteUsr (void)
2019-03-28 15:22:38 +01:00
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
2019-03-29 01:23:33 +01:00
/***** Mark note as favourite *****/
TL_FavNoteGbl ();
2019-03-28 15:22:38 +01:00
}
2019-03-12 21:25:55 +01:00
void TL_FavNoteGbl (void)
2019-02-23 13:00:25 +01:00
{
2019-03-12 21:25:55 +01:00
struct TL_Note SocNot;
2019-02-24 15:15:43 +01:00
2019-03-12 21:25:55 +01:00
/***** Mark note as favourite *****/
TL_FavNote (&SocNot);
2019-02-24 15:15:43 +01:00
/***** Write HTML inside DIV with form to unfav *****/
2019-03-29 01:23:33 +01:00
TL_PutFormToFavUnfNote (&SocNot,TL_SHOW_A_FEW_USRS);
2019-02-23 13:00:25 +01:00
}
2019-03-29 01:23:33 +01:00
void TL_UnfNoteUsr (void)
2016-01-19 00:50:35 +01:00
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
2019-03-29 01:23:33 +01:00
/***** Unfav a note previously marked as favourite *****/
TL_UnfNoteGbl ();
2019-03-28 19:44:59 +01:00
}
void TL_UnfNoteGbl (void)
{
struct TL_Note SocNot;
/***** Stop marking as favourite a previously favourited note *****/
TL_UnfNote (&SocNot);
/***** Write HTML inside DIV with form to fav *****/
2019-03-29 01:23:33 +01:00
TL_PutFormToFavUnfNote (&SocNot,TL_SHOW_A_FEW_USRS);
2016-01-19 00:50:35 +01:00
}
2019-03-29 00:57:51 +01:00
static void TL_PutFormToFavUnfNote (const struct TL_Note *SocNot,
TL_HowMany_t HowMany)
2019-03-28 19:44:59 +01:00
{
bool IAmTheAuthor;
bool IAmAFaverOfThisSocNot;
/***** Put form to fav/unfav this note *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_ICO\"");
2019-03-28 19:44:59 +01:00
IAmTheAuthor = Usr_ItsMe (SocNot->UsrCod);
if (SocNot->Unavailable || // Unavailable notes can not be favourited
IAmTheAuthor) // I am the author
/* Put disabled icon */
TL_PutDisabledIconFav (SocNot->NumFavs);
else // Available and I am not the author
{
/* Put icon to fav/unfav */
IAmAFaverOfThisSocNot = TL_CheckIfNoteIsFavedByUsr (SocNot->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
if (IAmAFaverOfThisSocNot) // I have favourited this note
2019-03-29 00:57:51 +01:00
TL_PutFormToUnfNote (SocNot);
2019-03-28 19:44:59 +01:00
else // I am not a faver of this note
TL_PutFormToFavNote (SocNot);
}
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-03-28 19:44:59 +01:00
/***** Show who have marked this note as favourite *****/
2019-03-29 00:57:51 +01:00
TL_ShowUsrsWhoHaveMarkedNoteAsFav (SocNot,HowMany);
2019-03-28 19:44:59 +01:00
}
2019-03-12 21:25:55 +01:00
static void TL_FavNote (struct TL_Note *SocNot)
2019-02-23 13:00:25 +01:00
{
bool ItsMe;
long OriginalPubCod;
2019-03-12 21:25:55 +01:00
/***** Get data of note *****/
SocNot->NotCod = TL_GetParamNotCod ();
TL_GetDataOfNoteByCod (SocNot);
2019-02-23 13:00:25 +01:00
2019-02-24 15:15:43 +01:00
if (SocNot->NotCod > 0)
2019-02-23 13:00:25 +01:00
{
2019-02-24 15:15:43 +01:00
ItsMe = Usr_ItsMe (SocNot->UsrCod);
2019-02-23 13:00:25 +01:00
if (Gbl.Usrs.Me.Logged && !ItsMe) // I am not the author
2019-03-12 21:25:55 +01:00
if (!TL_CheckIfNoteIsFavedByUsr (SocNot->NotCod,
2019-03-28 15:22:38 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod)) // I have not yet favourited the note
2019-02-23 13:00:25 +01:00
{
/***** Mark as favourite in database *****/
2019-03-12 21:25:55 +01:00
DB_QueryINSERT ("can not favourite note",
2019-11-25 13:29:56 +01:00
"INSERT IGNORE INTO tl_notes_fav"
2019-02-23 13:00:25 +01:00
" (NotCod,UsrCod,TimeFav)"
" VALUES"
" (%ld,%ld,NOW())",
2019-02-24 15:15:43 +01:00
SocNot->NotCod,
2019-02-23 13:00:25 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod);
2019-03-12 21:25:55 +01:00
/***** Update number of times this note is favourited *****/
TL_GetNumTimesANoteHasBeenFav (SocNot);
2019-02-23 13:00:25 +01:00
2019-02-24 21:45:46 +01:00
/***** Create notification about favourite post
for the author of the post *****/
2019-03-12 21:25:55 +01:00
OriginalPubCod = TL_GetPubCodOfOriginalNote (SocNot->NotCod);
2019-02-23 13:00:25 +01:00
if (OriginalPubCod > 0)
2019-03-12 21:25:55 +01:00
TL_CreateNotifToAuthor (SocNot->UsrCod,OriginalPubCod,Ntf_EVENT_TIMELINE_FAV);
2019-02-23 13:00:25 +01:00
}
}
}
2019-03-28 19:44:59 +01:00
static void TL_UnfNote (struct TL_Note *SocNot)
{
long OriginalPubCod;
bool ItsMe;
/***** Get data of note *****/
SocNot->NotCod = TL_GetParamNotCod ();
TL_GetDataOfNoteByCod (SocNot);
if (SocNot->NotCod > 0)
{
ItsMe = Usr_ItsMe (SocNot->UsrCod);
if (SocNot->NumFavs &&
Gbl.Usrs.Me.Logged && !ItsMe) // I am not the author
if (TL_CheckIfNoteIsFavedByUsr (SocNot->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod)) // I have favourited the note
{
/***** Delete the mark as favourite from database *****/
DB_QueryDELETE ("can not unfavourite note",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_notes_fav"
2019-03-28 19:44:59 +01:00
" WHERE NotCod=%ld AND UsrCod=%ld",
SocNot->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
/***** Update number of times this note is favourited *****/
TL_GetNumTimesANoteHasBeenFav (SocNot);
/***** Mark possible notifications on this note as removed *****/
OriginalPubCod = TL_GetPubCodOfOriginalNote (SocNot->NotCod);
if (OriginalPubCod > 0)
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_FAV,OriginalPubCod);
}
}
}
2016-01-19 12:54:27 +01:00
/*****************************************************************************/
2019-03-28 18:03:42 +01:00
/********************* Mark/unmark a comment as favourite ************************/
2016-01-19 12:54:27 +01:00
/*****************************************************************************/
2019-03-29 01:23:33 +01:00
void TL_ShowAllFaversComUsr (void)
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
/***** Show all favers *****/
TL_ShowAllFaversComGbl ();
}
2019-03-28 15:22:38 +01:00
void TL_ShowAllFaversComGbl (void)
{
struct TL_Comment SocCom;
/***** Get data of comment *****/
2019-11-24 23:51:03 +01:00
Med_MediaConstructor (&SocCom.Content.Media);
2019-03-28 15:22:38 +01:00
SocCom.PubCod = TL_GetParamPubCod ();
TL_GetDataOfCommByCod (&SocCom);
2019-11-24 23:51:03 +01:00
Med_MediaDestructor (&SocCom.Content.Media);
2019-03-28 15:22:38 +01:00
/***** Write HTML inside DIV with form to fav/unfav *****/
2019-03-29 01:23:33 +01:00
TL_PutFormToFavUnfComment (&SocCom,TL_SHOW_ALL_USRS);
2019-03-28 15:22:38 +01:00
}
2019-03-29 01:23:33 +01:00
void TL_FavCommentUsr (void)
2019-03-28 15:22:38 +01:00
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
2019-03-29 01:23:33 +01:00
/***** Mark comment as favourite *****/
TL_FavCommentGbl ();
2019-03-28 15:22:38 +01:00
}
2019-03-12 21:25:55 +01:00
void TL_FavCommentGbl (void)
2016-01-19 12:54:27 +01:00
{
2019-03-12 21:25:55 +01:00
struct TL_Comment SocCom;
2019-02-24 19:33:38 +01:00
2019-03-12 21:25:55 +01:00
/***** Mark comment as favourite *****/
TL_FavComment (&SocCom);
2016-01-19 12:54:27 +01:00
2019-02-24 19:33:38 +01:00
/***** Write HTML inside DIV with form to unfav *****/
2019-03-29 01:23:33 +01:00
TL_PutFormToFavUnfComment (&SocCom,TL_SHOW_A_FEW_USRS);
2016-01-19 12:54:27 +01:00
}
2019-03-29 01:23:33 +01:00
void TL_UnfCommentUsr (void)
2016-01-19 12:54:27 +01:00
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
2019-03-29 01:23:33 +01:00
/***** Unfav a comment previously marked as favourite *****/
TL_UnfCommentGbl ();
2019-03-28 18:03:42 +01:00
}
2019-03-28 19:44:59 +01:00
void TL_UnfCommentGbl (void)
2019-03-28 18:03:42 +01:00
{
struct TL_Comment SocCom;
/***** Stop marking as favourite a previously favourited comment *****/
2019-03-28 19:44:59 +01:00
TL_UnfComment (&SocCom);
2019-03-28 18:03:42 +01:00
/***** Write HTML inside DIV with form to fav *****/
2019-03-29 01:23:33 +01:00
TL_PutFormToFavUnfComment (&SocCom,TL_SHOW_A_FEW_USRS);
2016-01-19 12:54:27 +01:00
}
2019-03-29 00:57:51 +01:00
static void TL_PutFormToFavUnfComment (const struct TL_Comment *SocCom,
TL_HowMany_t HowMany)
2019-03-28 18:03:42 +01:00
{
bool IAmTheAuthor;
bool IAmAFaverOfThisSocCom;
2019-03-28 19:44:59 +01:00
/***** Put form to fav/unfav this comment *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_ICO\"");
2019-03-28 18:03:42 +01:00
IAmTheAuthor = Usr_ItsMe (SocCom->UsrCod);
if (IAmTheAuthor) // I am the author
/* Put disabled icon */
TL_PutDisabledIconFav (SocCom->NumFavs);
else // I am not the author
{
/* Put icon to mark this comment as favourite */
IAmAFaverOfThisSocCom = TL_CheckIfCommIsFavedByUsr (SocCom->PubCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
if (IAmAFaverOfThisSocCom) // I have favourited this comment
/* Put icon to unfav this publication and list of users */
2019-03-29 00:57:51 +01:00
TL_PutFormToUnfComment (SocCom);
2019-03-28 18:03:42 +01:00
else // I am not a favouriter
/* Put icon to fav this publication and list of users */
TL_PutFormToFavComment (SocCom);
}
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-03-28 18:03:42 +01:00
2019-03-28 19:44:59 +01:00
/***** Show who have marked this comment as favourite *****/
2019-03-29 00:57:51 +01:00
TL_ShowUsrsWhoHaveMarkedCommAsFav (SocCom,HowMany);
2019-03-28 18:03:42 +01:00
}
2019-03-12 21:25:55 +01:00
static void TL_FavComment (struct TL_Comment *SocCom)
2016-01-19 12:54:27 +01:00
{
2019-03-28 18:03:42 +01:00
bool IAmTheAuthor;
2016-01-19 12:54:27 +01:00
2016-04-08 23:30:43 +02:00
/***** Initialize image *****/
2019-11-24 23:51:03 +01:00
Med_MediaConstructor (&SocCom->Content.Media);
2016-04-08 23:30:43 +02:00
2019-03-12 21:25:55 +01:00
/***** Get data of comment *****/
SocCom->PubCod = TL_GetParamPubCod ();
TL_GetDataOfCommByCod (SocCom);
2016-01-19 12:54:27 +01:00
2019-02-24 19:33:38 +01:00
if (SocCom->PubCod > 0)
2016-01-19 12:54:27 +01:00
{
2019-03-28 18:03:42 +01:00
IAmTheAuthor = Usr_ItsMe (SocCom->UsrCod);
if (!IAmTheAuthor) // I am not the author
2019-03-12 21:25:55 +01:00
if (!TL_CheckIfCommIsFavedByUsr (SocCom->PubCod,
2019-03-28 15:22:38 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod)) // I have not yet favourited the comment
2016-01-24 13:46:57 +01:00
{
/***** Mark as favourite in database *****/
2019-03-12 21:25:55 +01:00
DB_QueryINSERT ("can not favourite comment",
2019-11-25 13:29:56 +01:00
"INSERT IGNORE INTO tl_comments_fav"
2018-11-02 19:37:11 +01:00
" (PubCod,UsrCod,TimeFav)"
" VALUES"
" (%ld,%ld,NOW())",
2019-02-24 19:33:38 +01:00
SocCom->PubCod,
2018-11-02 19:37:11 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod);
2016-01-24 13:46:57 +01:00
2019-03-12 21:25:55 +01:00
/* Update number of times this comment is favourited */
TL_GetNumTimesACommHasBeenFav (SocCom);
2016-01-24 13:46:57 +01:00
/**** Create notification about favourite post
for the author of the post ***/
2019-03-12 21:25:55 +01:00
TL_CreateNotifToAuthor (SocCom->UsrCod,SocCom->PubCod,Ntf_EVENT_TIMELINE_FAV);
2016-01-24 13:46:57 +01:00
}
2016-01-19 12:54:27 +01:00
}
2016-04-08 23:30:43 +02:00
/***** Free image *****/
2019-11-24 23:51:03 +01:00
Med_MediaDestructor (&SocCom->Content.Media);
2016-01-19 12:54:27 +01:00
}
2019-03-28 19:44:59 +01:00
static void TL_UnfComment (struct TL_Comment *SocCom)
2019-03-28 18:03:42 +01:00
{
bool IAmTheAuthor;
/***** Initialize image *****/
2019-11-24 23:51:03 +01:00
Med_MediaConstructor (&SocCom->Content.Media);
2019-03-28 18:03:42 +01:00
/***** Get data of comment *****/
SocCom->PubCod = TL_GetParamPubCod ();
TL_GetDataOfCommByCod (SocCom);
if (SocCom->PubCod > 0)
{
IAmTheAuthor = Usr_ItsMe (SocCom->UsrCod);
if (SocCom->NumFavs &&
!IAmTheAuthor) // I am not the author
if (TL_CheckIfCommIsFavedByUsr (SocCom->PubCod,
Gbl.Usrs.Me.UsrDat.UsrCod)) // I have favourited the comment
{
/***** Delete the mark as favourite from database *****/
DB_QueryDELETE ("can not unfavourite comment",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_comments_fav"
2019-03-28 18:03:42 +01:00
" WHERE PubCod=%ld AND UsrCod=%ld",
SocCom->PubCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
/***** Update number of times this comment is favourited *****/
TL_GetNumTimesACommHasBeenFav (SocCom);
/***** Mark possible notifications on this comment as removed *****/
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_FAV,SocCom->PubCod);
}
}
/***** Free image *****/
2019-11-24 23:51:03 +01:00
Med_MediaDestructor (&SocCom->Content.Media);
2019-03-28 18:03:42 +01:00
}
2016-01-23 01:38:55 +01:00
/*****************************************************************************/
2016-01-25 18:57:37 +01:00
/*********** Create a notification for the author of a post/comment **********/
2016-01-23 01:38:55 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_CreateNotifToAuthor (long AuthorCod,long PubCod,
2019-03-13 10:23:41 +01:00
Ntf_NotifyEvent_t NotifyEvent)
2016-01-23 01:38:55 +01:00
{
struct UsrData UsrDat;
bool CreateNotif;
bool NotifyByEmail;
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
UsrDat.UsrCod = AuthorCod;
2019-03-19 13:22:14 +01:00
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS))
2016-01-23 01:38:55 +01:00
{
2016-11-16 23:19:52 +01:00
/***** This fav must be notified by email? *****/
2019-03-19 13:22:14 +01:00
CreateNotif = (UsrDat.NtfEvents.CreateNotif & (1 << NotifyEvent));
2016-01-23 01:38:55 +01:00
NotifyByEmail = CreateNotif &&
2019-03-19 13:22:14 +01:00
(UsrDat.NtfEvents.SendEmail & (1 << NotifyEvent));
2016-01-23 01:38:55 +01:00
/***** Create notification for the author of the post.
2016-11-16 23:19:52 +01:00
If this author wants to receive notifications by email,
2016-01-23 01:38:55 +01:00
activate the sending of a notification *****/
if (CreateNotif)
2016-01-25 18:57:37 +01:00
Ntf_StoreNotifyEventToOneUser (NotifyEvent,&UsrDat,PubCod,
2016-01-23 01:38:55 +01:00
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
2020-04-07 03:01:41 +02:00
0),
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ctr.CtrCod,
Gbl.Hierarchy.Deg.DegCod,
Gbl.Hierarchy.Crs.CrsCod);
2016-01-23 01:38:55 +01:00
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************** Unshare a previously shared note ***********************/
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2019-03-29 01:23:33 +01:00
void TL_UnsNoteUsr (void)
2016-01-02 01:56:48 +01:00
{
2019-03-29 01:23:33 +01:00
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
2016-01-16 01:37:37 +01:00
2019-03-12 21:25:55 +01:00
/***** Unshare note *****/
2019-03-29 01:23:33 +01:00
TL_UnsNoteGbl ();
2016-01-02 01:56:48 +01:00
}
2019-03-29 01:23:33 +01:00
void TL_UnsNoteGbl (void)
2016-01-02 01:56:48 +01:00
{
2019-03-12 21:25:55 +01:00
struct TL_Note SocNot;
2016-01-16 01:37:37 +01:00
2019-03-29 01:23:33 +01:00
/***** Unshare note *****/
2019-03-28 19:44:59 +01:00
TL_UnsNote (&SocNot);
2016-01-02 02:33:23 +01:00
2019-02-25 02:02:10 +01:00
/***** Write HTML inside DIV with form to share *****/
2019-03-29 01:23:33 +01:00
TL_PutFormToShaUnsNote (&SocNot,TL_SHOW_A_FEW_USRS);
2016-01-02 01:56:48 +01:00
}
2019-03-28 19:44:59 +01:00
static void TL_UnsNote (struct TL_Note *SocNot)
2016-01-01 20:19:43 +01:00
{
2016-01-24 13:46:57 +01:00
extern const char *Txt_The_original_post_no_longer_exists;
2016-01-25 20:28:33 +01:00
long OriginalPubCod;
2018-10-10 23:56:42 +02:00
bool ItsMe;
2016-01-01 20:19:43 +01:00
2019-03-12 21:25:55 +01:00
/***** Get data of note *****/
SocNot->NotCod = TL_GetParamNotCod ();
TL_GetDataOfNoteByCod (SocNot);
2016-01-01 20:19:43 +01:00
2019-02-25 02:02:10 +01:00
if (SocNot->NotCod > 0)
2016-01-01 20:19:43 +01:00
{
2019-02-25 02:02:10 +01:00
ItsMe = Usr_ItsMe (SocNot->UsrCod);
if (SocNot->NumShared &&
2018-10-10 23:56:42 +02:00
Gbl.Usrs.Me.Logged && !ItsMe) // I am not the author
2019-03-12 21:25:55 +01:00
if (TL_CheckIfNoteIsSharedByUsr (SocNot->NotCod,
2016-01-24 13:46:57 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod)) // I am a sharer
{
2019-03-12 21:25:55 +01:00
/***** Delete publication from database *****/
DB_QueryDELETE ("can not remove a publication",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_pubs"
2018-11-02 22:00:31 +01:00
" WHERE NotCod=%ld"
" AND PublisherCod=%ld"
" AND PubType=%u",
2019-02-25 02:02:10 +01:00
SocNot->NotCod,
2018-11-02 22:00:31 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod,
2019-03-12 21:25:55 +01:00
(unsigned) TL_PUB_SHARED_NOTE);
2016-01-24 13:46:57 +01:00
2019-03-12 21:25:55 +01:00
/***** Update number of times this note is shared *****/
TL_UpdateNumTimesANoteHasBeenShared (SocNot);
2016-01-24 13:46:57 +01:00
2019-03-12 21:25:55 +01:00
/***** Mark possible notifications on this note as removed *****/
OriginalPubCod = TL_GetPubCodOfOriginalNote (SocNot->NotCod);
2016-01-25 20:28:33 +01:00
if (OriginalPubCod > 0)
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_SHARE,OriginalPubCod);
2016-01-24 13:46:57 +01:00
}
2016-01-01 20:19:43 +01:00
}
}
2015-12-30 02:08:08 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/*********************** Request the removal of a note ***********************/
2015-12-30 16:33:36 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_RequestRemNoteUsr (void)
2016-01-02 01:56:48 +01:00
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
2016-01-08 01:53:37 +01:00
/***** Show user's profile *****/
2016-06-12 19:55:33 +02:00
Prf_ShowUserProfile (&Gbl.Usrs.Other.UsrDat);
2016-01-02 01:56:48 +01:00
2016-01-02 02:33:23 +01:00
/***** Start section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_Begin (TL_TIMELINE_SECTION_ID);
2016-01-02 02:33:23 +01:00
2019-03-12 21:25:55 +01:00
/***** Request the removal of note *****/
TL_RequestRemovalNote ();
2016-01-02 01:56:48 +01:00
/***** Write timeline again (user) *****/
2019-03-12 21:25:55 +01:00
TL_ShowTimelineUsr ();
2016-01-02 02:33:23 +01:00
/***** End section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_End ();
2016-01-02 01:56:48 +01:00
}
2019-03-29 01:23:33 +01:00
void TL_RequestRemNoteGbl (void)
{
/***** Request the removal of note *****/
TL_RequestRemovalNote ();
/***** Write timeline again (global) *****/
TL_ShowTimelineGbl2 ();
}
2019-03-12 21:25:55 +01:00
static void TL_RequestRemovalNote (void)
2015-12-30 16:33:36 +01:00
{
2016-01-24 13:46:57 +01:00
extern const char *Txt_The_original_post_no_longer_exists;
2016-01-16 02:16:12 +01:00
extern const char *Txt_Do_you_really_want_to_remove_the_following_post;
2015-12-30 16:33:36 +01:00
extern const char *Txt_Remove;
2019-03-12 21:25:55 +01:00
struct TL_Note SocNot;
2018-10-10 23:56:42 +02:00
bool ItsMe;
2015-12-30 16:33:36 +01:00
2019-03-12 21:25:55 +01:00
/***** Get data of note *****/
SocNot.NotCod = TL_GetParamNotCod ();
TL_GetDataOfNoteByCod (&SocNot);
2015-12-30 16:33:36 +01:00
2016-01-24 13:46:57 +01:00
if (SocNot.NotCod > 0)
2015-12-30 16:33:36 +01:00
{
2018-10-10 23:56:42 +02:00
ItsMe = Usr_ItsMe (SocNot.UsrCod);
if (ItsMe) // I am the author of this note
2016-01-02 01:56:48 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Show question and button to remove note *****/
2017-04-28 12:52:58 +02:00
/* Start alert */
2017-05-11 23:45:46 +02:00
Ale_ShowAlertAndButton1 (Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_following_post);
2016-01-05 21:30:10 +01:00
2019-03-12 21:25:55 +01:00
/* Show note */
TL_WriteNote (&SocNot,
2019-03-13 00:54:35 +01:00
TL_TOP_MESSAGE_NONE,-1L,
false,true);
2016-01-05 21:30:10 +01:00
2017-04-28 12:52:58 +02:00
/* End alert */
2019-03-12 21:25:55 +01:00
Gbl.Timeline.NotCod = SocNot.NotCod; // Note to be removed
2017-04-28 12:52:58 +02:00
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
2017-05-25 14:25:22 +02:00
Ale_ShowAlertAndButton2 (ActRemSocPubUsr,"timeline",NULL,
2020-03-27 14:56:54 +01:00
TL_PutParamsRemoveNote,&Gbl,
2017-06-11 19:02:40 +02:00
Btn_REMOVE_BUTTON,Txt_Remove);
2017-04-28 12:52:58 +02:00
else
2017-05-25 14:25:22 +02:00
Ale_ShowAlertAndButton2 (ActRemSocPubGbl,NULL,NULL,
2020-03-27 14:56:54 +01:00
TL_PutParamsRemoveNote,&Gbl,
2017-06-11 19:02:40 +02:00
Btn_REMOVE_BUTTON,Txt_Remove);
2016-01-04 17:36:28 +01:00
}
2015-12-30 16:33:36 +01:00
}
2016-01-24 13:46:57 +01:00
else
2019-02-16 18:25:41 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
2015-12-30 16:33:36 +01:00
}
2017-04-28 12:52:58 +02:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********************* Put parameters to remove a note ***********************/
2017-04-28 12:52:58 +02:00
/*****************************************************************************/
2020-03-26 02:54:30 +01:00
static void TL_PutParamsRemoveNote (void *Args)
2017-04-28 12:52:58 +02:00
{
2020-03-26 02:54:30 +01:00
if (Args)
{
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
2020-03-27 14:56:54 +01:00
Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
2020-03-26 02:54:30 +01:00
else
Usr_PutHiddenParamWho (Gbl.Timeline.Who);
TL_PutHiddenParamNotCod (Gbl.Timeline.NotCod);
}
2017-04-28 12:52:58 +02:00
}
2015-12-30 16:33:36 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************************* Remove a note *******************************/
2015-12-30 02:08:08 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_RemoveNoteUsr (void)
2016-01-02 01:56:48 +01:00
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
2016-01-07 00:42:35 +01:00
/***** Show user's profile *****/
2016-06-12 19:55:33 +02:00
Prf_ShowUserProfile (&Gbl.Usrs.Other.UsrDat);
2016-01-02 01:56:48 +01:00
2016-01-02 02:33:23 +01:00
/***** Start section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_Begin (TL_TIMELINE_SECTION_ID);
2016-01-02 02:33:23 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove a note *****/
TL_RemoveNote ();
2016-01-02 01:56:48 +01:00
/***** Write updated timeline after removing (user) *****/
2019-03-12 21:25:55 +01:00
TL_ShowTimelineUsr ();
2016-01-02 02:33:23 +01:00
/***** End section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_End ();
2016-01-02 01:56:48 +01:00
}
2019-03-29 01:23:33 +01:00
void TL_RemoveNoteGbl (void)
{
/***** Remove a note *****/
TL_RemoveNote ();
/***** Write updated timeline after removing (global) *****/
TL_ShowTimelineGbl2 ();
}
2019-03-12 21:25:55 +01:00
static void TL_RemoveNote (void)
2015-12-30 02:08:08 +01:00
{
2016-01-24 13:46:57 +01:00
extern const char *Txt_The_original_post_no_longer_exists;
2019-03-14 09:43:42 +01:00
extern const char *Txt_TIMELINE_Post_removed;
2019-03-12 21:25:55 +01:00
struct TL_Note SocNot;
2018-10-10 23:56:42 +02:00
bool ItsMe;
2015-12-30 02:08:08 +01:00
2019-03-12 21:25:55 +01:00
/***** Get data of note *****/
SocNot.NotCod = TL_GetParamNotCod ();
TL_GetDataOfNoteByCod (&SocNot);
2015-12-30 12:40:13 +01:00
2016-01-24 13:46:57 +01:00
if (SocNot.NotCod > 0)
2015-12-30 12:40:13 +01:00
{
2018-10-10 23:56:42 +02:00
ItsMe = Usr_ItsMe (SocNot.UsrCod);
if (ItsMe) // I am the author of this note
2016-01-24 13:46:57 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Delete note from database *****/
2019-03-18 15:42:22 +01:00
TL_RemoveNoteMediaAndDBEntries (&SocNot);
/***** Reset note *****/
TL_ResetNote (&SocNot);
2015-12-30 16:33:36 +01:00
2016-01-24 13:46:57 +01:00
/***** Message of success *****/
2019-03-14 09:43:42 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_TIMELINE_Post_removed);
2016-01-24 13:46:57 +01:00
}
2015-12-30 12:40:13 +01:00
}
2016-01-24 13:46:57 +01:00
else
2019-02-16 18:25:41 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
2015-12-30 02:08:08 +01:00
}
2015-12-30 12:40:13 +01:00
2016-04-08 20:21:33 +02:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/*********************** Remove a note from database *************************/
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2019-03-18 15:42:22 +01:00
static void TL_RemoveNoteMediaAndDBEntries (struct TL_Note *SocNot)
2016-01-01 20:19:43 +01:00
{
2016-01-24 14:26:35 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long PubCod;
2016-01-25 20:28:33 +01:00
unsigned long NumComments;
unsigned long NumCom;
2019-03-19 11:32:22 +01:00
long MedCod;
2016-01-24 14:26:35 +01:00
2019-03-18 15:42:22 +01:00
/***** Remove comments associated to this note *****/
2019-03-12 21:25:55 +01:00
/* Get comments of this note */
NumComments = DB_QuerySELECT (&mysql_res,"can not get comments",
"SELECT PubCod"
2019-11-25 13:29:56 +01:00
" FROM tl_pubs"
2018-11-01 21:59:42 +01:00
" WHERE NotCod=%ld AND PubType=%u",
SocNot->NotCod,
2019-03-12 21:25:55 +01:00
(unsigned) TL_PUB_COMMENT_TO_NOTE);
2016-01-25 20:28:33 +01:00
/* For each comment... */
for (NumCom = 0;
NumCom < NumComments;
NumCom++)
2016-01-24 14:26:35 +01:00
{
2019-03-12 21:25:55 +01:00
/* Get code of comment **/
2016-01-24 14:26:35 +01:00
row = mysql_fetch_row (mysql_res);
PubCod = Str_ConvertStrCodToLongCod (row[0]);
2019-03-18 15:42:22 +01:00
/* Remove media associated to comment
and delete comment from database */
TL_RemoveCommentMediaAndDBEntries (PubCod);
2016-01-24 14:26:35 +01:00
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
2016-01-01 20:19:43 +01:00
2019-03-18 15:42:22 +01:00
/***** Remove media associated to post *****/
if (SocNot->NoteType == TL_NOTE_POST)
{
2019-03-19 11:32:22 +01:00
/* Remove media associated to a post from database */
if (DB_QuerySELECT (&mysql_res,"can not get media",
2019-03-18 19:35:23 +01:00
"SELECT MedCod" // row[0]
2019-11-25 13:29:56 +01:00
" FROM tl_posts"
2019-03-18 19:35:23 +01:00
" WHERE PstCod=%ld",
2019-03-19 11:32:22 +01:00
SocNot->Cod) == 1) // Result should have a unique row
{
/* Get media code */
row = mysql_fetch_row (mysql_res);
MedCod = Str_ConvertStrCodToLongCod (row[0]);
2019-03-18 19:35:23 +01:00
2019-03-19 11:32:22 +01:00
/* Remove media */
Med_RemoveMedia (MedCod);
}
2019-03-18 15:42:22 +01:00
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
}
/***** Mark possible notifications on the publications
of this note as removed *****/
/* Mark notifications of the original note as removed */
PubCod = TL_GetPubCodOfOriginalNote (SocNot->NotCod);
if (PubCod > 0)
{
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_FAV ,PubCod);
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_SHARE ,PubCod);
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_MENTION,PubCod);
}
2016-01-20 14:29:42 +01:00
2019-03-18 15:42:22 +01:00
/***** Remove favs for this note *****/
2019-03-12 21:25:55 +01:00
DB_QueryDELETE ("can not remove favs for note",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_notes_fav"
2019-03-12 21:25:55 +01:00
" WHERE NotCod=%ld",
2018-11-02 22:00:31 +01:00
SocNot->NotCod);
2016-01-19 09:34:01 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove all the publications of this note *****/
DB_QueryDELETE ("can not remove a publication",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_pubs"
2019-03-12 21:25:55 +01:00
" WHERE NotCod=%ld",
2018-11-02 22:00:31 +01:00
SocNot->NotCod);
2016-01-01 20:19:43 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove note *****/
DB_QueryDELETE ("can not remove a note",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_notes"
2018-11-02 22:00:31 +01:00
" WHERE NotCod=%ld"
" AND UsrCod=%ld", // Extra check: I am the author
SocNot->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
2016-01-02 14:36:34 +01:00
2019-03-12 21:25:55 +01:00
if (SocNot->NoteType == TL_NOTE_POST)
/***** Remove post *****/
DB_QueryDELETE ("can not remove a post",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_posts"
2019-03-12 21:25:55 +01:00
" WHERE PstCod=%ld",
2018-11-02 22:00:31 +01:00
SocNot->Cod);
2016-01-01 20:19:43 +01:00
}
2016-01-25 20:28:33 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/*********************** Get code of note of a publication *******************/
2016-01-25 20:28:33 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static long TL_GetNotCodOfPublication (long PubCod)
2016-01-25 20:28:33 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long NotCod = -1L;
2019-03-12 21:25:55 +01:00
/***** Get code of note from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get code of note",
2019-11-25 13:29:56 +01:00
"SELECT NotCod FROM tl_pubs"
2019-03-12 21:25:55 +01:00
" WHERE PubCod=%ld",
2018-11-01 21:59:42 +01:00
PubCod) == 1) // Result should have a unique row
2016-01-25 20:28:33 +01:00
{
2019-03-12 21:25:55 +01:00
/* Get code of note */
2016-01-25 20:28:33 +01:00
row = mysql_fetch_row (mysql_res);
NotCod = Str_ConvertStrCodToLongCod (row[0]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NotCod;
}
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/*************** Get code of publication of the original note ****************/
2016-01-24 14:26:35 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static long TL_GetPubCodOfOriginalNote (long NotCod)
2016-01-24 14:26:35 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-01-25 20:28:33 +01:00
long OriginalPubCod = -1L;
2016-01-24 14:26:35 +01:00
2019-03-12 21:25:55 +01:00
/***** Get code of publication of the original note *****/
if (DB_QuerySELECT (&mysql_res,"can not get code of publication",
2019-11-25 13:29:56 +01:00
"SELECT PubCod FROM tl_pubs"
2018-11-01 21:59:42 +01:00
" WHERE NotCod=%ld AND PubType=%u",
2019-03-12 21:25:55 +01:00
NotCod,(unsigned) TL_PUB_ORIGINAL_NOTE) == 1) // Result should have a unique row
2016-01-24 14:26:35 +01:00
{
2019-03-12 21:25:55 +01:00
/* Get code of publication (row[0]) */
2016-01-24 14:26:35 +01:00
row = mysql_fetch_row (mysql_res);
2016-01-25 20:28:33 +01:00
OriginalPubCod = Str_ConvertStrCodToLongCod (row[0]);
2016-01-24 14:26:35 +01:00
}
2016-01-25 20:28:33 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return OriginalPubCod;
2016-01-24 14:26:35 +01:00
}
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/**************** Request the removal of a comment in a note *****************/
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_RequestRemComUsr (void)
2016-01-08 01:53:37 +01:00
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
/***** Show user's profile *****/
2016-06-12 19:55:33 +02:00
Prf_ShowUserProfile (&Gbl.Usrs.Other.UsrDat);
2016-01-08 01:53:37 +01:00
/***** Start section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_Begin (TL_TIMELINE_SECTION_ID);
2016-01-08 01:53:37 +01:00
2019-03-12 21:25:55 +01:00
/***** Request the removal of comment in note *****/
TL_RequestRemovalComment ();
2016-01-08 01:53:37 +01:00
/***** Write timeline again (user) *****/
2019-03-12 21:25:55 +01:00
TL_ShowTimelineUsr ();
2016-01-08 01:53:37 +01:00
/***** End section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_End ();
2016-01-08 01:53:37 +01:00
}
2019-03-29 01:23:33 +01:00
void TL_RequestRemComGbl (void)
{
/***** Request the removal of comment in note *****/
TL_RequestRemovalComment ();
/***** Write timeline again (global) *****/
TL_ShowTimelineGbl2 ();
}
2019-03-12 21:25:55 +01:00
static void TL_RequestRemovalComment (void)
2016-01-08 01:53:37 +01:00
{
2016-01-24 13:46:57 +01:00
extern const char *Txt_The_comment_no_longer_exists;
2016-01-08 01:53:37 +01:00
extern const char *Txt_Do_you_really_want_to_remove_the_following_comment;
extern const char *Txt_Remove;
2019-03-12 21:25:55 +01:00
struct TL_Comment SocCom;
2018-10-10 23:56:42 +02:00
bool ItsMe;
2016-01-08 01:53:37 +01:00
2016-04-08 23:30:43 +02:00
/***** Initialize image *****/
2019-11-24 23:51:03 +01:00
Med_MediaConstructor (&SocCom.Content.Media);
2016-04-08 23:30:43 +02:00
2019-03-12 21:25:55 +01:00
/***** Get data of comment *****/
SocCom.PubCod = TL_GetParamPubCod ();
TL_GetDataOfCommByCod (&SocCom);
2016-01-08 01:53:37 +01:00
2016-01-25 12:32:13 +01:00
if (SocCom.PubCod > 0)
2016-01-08 01:53:37 +01:00
{
2018-10-10 23:56:42 +02:00
ItsMe = Usr_ItsMe (SocCom.UsrCod);
if (ItsMe) // I am the author of this comment
2016-01-08 01:53:37 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Show question and button to remove comment *****/
2017-04-28 12:38:05 +02:00
/* Start alert */
2017-05-11 23:45:46 +02:00
Ale_ShowAlertAndButton1 (Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_following_comment);
2016-01-08 01:53:37 +01:00
2019-03-12 21:25:55 +01:00
/* Show comment */
TL_WriteComment (&SocCom,
2019-03-28 18:03:42 +01:00
TL_TOP_MESSAGE_NONE,-1L,
true); // Alone
2016-01-24 13:46:57 +01:00
2017-04-28 12:38:05 +02:00
/* End alert */
2019-03-12 21:25:55 +01:00
Gbl.Timeline.PubCod = SocCom.PubCod; // Publication to be removed
2017-04-28 12:38:05 +02:00
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
2017-05-25 14:25:22 +02:00
Ale_ShowAlertAndButton2 (ActRemSocComUsr,"timeline",NULL,
2020-03-27 14:56:54 +01:00
TL_PutParamsRemoveCommment,&Gbl,
2017-06-11 19:02:40 +02:00
Btn_REMOVE_BUTTON,Txt_Remove);
2017-04-28 12:38:05 +02:00
else
2017-05-25 14:25:22 +02:00
Ale_ShowAlertAndButton2 (ActRemSocComGbl,NULL,NULL,
2020-03-27 14:56:54 +01:00
TL_PutParamsRemoveCommment,&Gbl,
2017-06-11 19:02:40 +02:00
Btn_REMOVE_BUTTON,Txt_Remove);
2016-01-24 13:46:57 +01:00
}
2016-01-08 01:53:37 +01:00
}
2016-01-24 13:46:57 +01:00
else
2019-02-16 18:25:41 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists);
2016-04-08 23:30:43 +02:00
/***** Free image *****/
2019-11-24 23:51:03 +01:00
Med_MediaDestructor (&SocCom.Content.Media);
2016-01-08 01:53:37 +01:00
}
2017-04-28 12:38:05 +02:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************** Put parameters to remove a comment *********************/
2017-04-28 12:38:05 +02:00
/*****************************************************************************/
2020-03-26 02:54:30 +01:00
static void TL_PutParamsRemoveCommment (void *Args)
2017-04-28 12:38:05 +02:00
{
2020-03-26 02:54:30 +01:00
if (Args)
{
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
2020-03-27 14:56:54 +01:00
Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
2020-03-26 02:54:30 +01:00
else
Usr_PutHiddenParamWho (Gbl.Timeline.Who);
TL_PutHiddenParamPubCod (Gbl.Timeline.PubCod);
}
2017-04-28 12:38:05 +02:00
}
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/***************************** Remove a comment ******************************/
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_RemoveComUsr (void)
2016-01-08 01:53:37 +01:00
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
/***** Show user's profile *****/
2016-06-12 19:55:33 +02:00
Prf_ShowUserProfile (&Gbl.Usrs.Other.UsrDat);
2016-01-08 01:53:37 +01:00
/***** Start section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_Begin (TL_TIMELINE_SECTION_ID);
2016-01-08 01:53:37 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove a comment *****/
TL_RemoveComment ();
2016-01-08 01:53:37 +01:00
/***** Write updated timeline after removing (user) *****/
2019-03-12 21:25:55 +01:00
TL_ShowTimelineUsr ();
2016-01-08 01:53:37 +01:00
/***** End section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_End ();
2016-01-08 01:53:37 +01:00
}
2019-03-29 01:23:33 +01:00
void TL_RemoveComGbl (void)
{
/***** Remove a comment *****/
TL_RemoveComment ();
/***** Write updated timeline after removing (global) *****/
TL_ShowTimelineGbl2 ();
}
2019-03-12 21:25:55 +01:00
static void TL_RemoveComment (void)
2016-01-08 01:53:37 +01:00
{
2016-01-24 13:46:57 +01:00
extern const char *Txt_The_comment_no_longer_exists;
2016-01-16 02:54:13 +01:00
extern const char *Txt_Comment_removed;
2019-03-12 21:25:55 +01:00
struct TL_Comment SocCom;
2018-10-10 23:56:42 +02:00
bool ItsMe;
2016-01-08 01:53:37 +01:00
2016-04-08 23:30:43 +02:00
/***** Initialize image *****/
2019-11-24 23:51:03 +01:00
Med_MediaConstructor (&SocCom.Content.Media);
2016-04-08 23:30:43 +02:00
2019-03-12 21:25:55 +01:00
/***** Get data of comment *****/
SocCom.PubCod = TL_GetParamPubCod ();
TL_GetDataOfCommByCod (&SocCom);
2016-01-08 01:53:37 +01:00
2016-01-25 12:32:13 +01:00
if (SocCom.PubCod > 0)
2016-01-08 01:53:37 +01:00
{
2018-10-10 23:56:42 +02:00
ItsMe = Usr_ItsMe (SocCom.UsrCod);
if (ItsMe) // I am the author of this comment
2016-01-24 13:46:57 +01:00
{
2019-03-18 15:42:22 +01:00
/***** Remove media associated to comment
and delete comment from database *****/
TL_RemoveCommentMediaAndDBEntries (SocCom.PubCod);
2016-04-08 23:30:43 +02:00
2019-03-18 15:42:22 +01:00
/***** Reset fields of comment *****/
TL_ResetComment (&SocCom);
2016-01-08 01:53:37 +01:00
2016-01-24 13:46:57 +01:00
/***** Message of success *****/
2019-02-16 18:25:41 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Comment_removed);
2016-01-24 13:46:57 +01:00
}
2016-01-08 01:53:37 +01:00
}
2016-01-24 13:46:57 +01:00
else
2019-02-16 18:25:41 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists);
2016-04-08 23:30:43 +02:00
/***** Free image *****/
2019-11-24 23:51:03 +01:00
Med_MediaDestructor (&SocCom.Content.Media);
2016-04-08 23:30:43 +02:00
}
/*****************************************************************************/
2019-03-18 15:42:22 +01:00
/*************** Remove comment media and database entries *******************/
2016-04-08 23:30:43 +02:00
/*****************************************************************************/
2019-03-18 15:42:22 +01:00
static void TL_RemoveCommentMediaAndDBEntries (long PubCod)
2016-04-08 23:30:43 +02:00
{
MYSQL_RES *mysql_res;
2019-03-19 11:32:22 +01:00
MYSQL_ROW row;
long MedCod;;
2016-04-08 23:30:43 +02:00
2019-03-18 15:42:22 +01:00
/***** Remove media associated to comment *****/
2019-03-19 11:32:22 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT MedCod" // row[0]
2019-11-25 13:29:56 +01:00
" FROM tl_comments"
2019-03-19 11:32:22 +01:00
" WHERE PubCod=%ld",
PubCod) == 1) // Result should have a unique row
{
/* Get media code */
row = mysql_fetch_row (mysql_res);
MedCod = Str_ConvertStrCodToLongCod (row[0]);
/* Remove media */
Med_RemoveMedia (MedCod);
}
2016-04-08 23:30:43 +02:00
2019-03-18 15:42:22 +01:00
/* Free structure that stores the query result */
2016-04-08 23:30:43 +02:00
DB_FreeMySQLResult (&mysql_res);
2016-01-08 01:53:37 +01:00
2016-01-24 14:48:08 +01:00
/***** Mark possible notifications on this comment as removed *****/
2019-03-18 15:42:22 +01:00
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_COMMENT,PubCod);
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_FAV ,PubCod);
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_MENTION,PubCod);
2016-01-24 14:48:08 +01:00
2016-01-20 14:29:42 +01:00
/***** Remove favs for this comment *****/
2019-03-12 21:25:55 +01:00
DB_QueryDELETE ("can not remove favs for comment",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_comments_fav"
2019-03-12 21:25:55 +01:00
" WHERE PubCod=%ld",
2019-03-18 15:42:22 +01:00
PubCod);
2016-01-20 14:29:42 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove content of this comment *****/
DB_QueryDELETE ("can not remove a comment",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_comments"
2019-03-12 21:25:55 +01:00
" WHERE PubCod=%ld",
2019-03-18 15:42:22 +01:00
PubCod);
2016-01-08 01:53:37 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove this comment *****/
DB_QueryDELETE ("can not remove a comment",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_pubs"
2018-11-02 22:00:31 +01:00
" WHERE PubCod=%ld"
" AND PublisherCod=%ld" // Extra check: I am the author
" AND PubType=%u", // Extra check: it's a comment
2019-03-18 15:42:22 +01:00
PubCod,
2018-11-02 22:00:31 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod,
2019-03-12 21:25:55 +01:00
(unsigned) TL_PUB_COMMENT_TO_NOTE);
2016-01-08 01:53:37 +01:00
}
2016-01-08 10:13:28 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************* Remove all the content of a user from database ****************/
2016-01-08 10:13:28 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_RemoveUsrContent (long UsrCod)
2016-01-08 10:13:28 +01:00
{
2016-01-20 14:29:42 +01:00
/***** Remove favs for comments *****/
2019-03-12 21:25:55 +01:00
/* Remove all favs made by this user in any comment */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove favs",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_comments_fav"
2019-03-12 21:25:55 +01:00
" WHERE UsrCod=%ld",
2018-11-02 22:00:31 +01:00
UsrCod);
2016-01-20 14:29:42 +01:00
/* Remove all favs for all comments of this user */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove favs",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_comments_fav"
" USING tl_pubs,tl_comments_fav"
" WHERE tl_pubs.PublisherCod=%ld" // Author of the comment
" AND tl_pubs.PubType=%u"
" AND tl_pubs.PubCod=tl_comments_fav.PubCod",
2019-03-12 21:25:55 +01:00
UsrCod,(unsigned) TL_PUB_COMMENT_TO_NOTE);
2016-01-20 14:29:42 +01:00
2019-03-12 21:25:55 +01:00
/* Remove all favs for all comments in all the notes of the user */
DB_QueryDELETE ("can not remove comments",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_comments_fav"
" USING tl_notes,tl_pubs,tl_comments_fav"
" WHERE tl_notes.UsrCod=%ld" // Author of the note
" AND tl_notes.NotCod=tl_pubs.NotCod"
" AND tl_pubs.PubType=%u"
" AND tl_pubs.PubCod=tl_comments_fav.PubCod",
2019-03-12 21:25:55 +01:00
UsrCod,(unsigned) TL_PUB_COMMENT_TO_NOTE);
2016-01-20 14:29:42 +01:00
/***** Remove favs for notes *****/
2019-03-12 21:25:55 +01:00
/* Remove all favs made by this user in any note */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove favs",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_notes_fav"
2019-03-12 21:25:55 +01:00
" WHERE UsrCod=%ld",
2018-11-02 22:00:31 +01:00
UsrCod);
2016-01-19 09:34:01 +01:00
/* Remove all favs for all notes of this user */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove favs",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_notes_fav"
" USING tl_notes,tl_notes_fav"
" WHERE tl_notes.UsrCod=%ld" // Author of the note
" AND tl_notes.NotCod=tl_notes_fav.NotCod",
2018-11-02 22:00:31 +01:00
UsrCod);
2016-01-19 09:34:01 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove comments *****/
/* Remove content of all the comments in all the notes of the user */
DB_QueryDELETE ("can not remove comments",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_comments"
" USING tl_notes,tl_pubs,tl_comments"
" WHERE tl_notes.UsrCod=%ld"
" AND tl_notes.NotCod=tl_pubs.NotCod"
" AND tl_pubs.PubType=%u"
" AND tl_pubs.PubCod=tl_comments.PubCod",
2019-03-12 21:25:55 +01:00
UsrCod,(unsigned) TL_PUB_COMMENT_TO_NOTE);
2016-01-08 10:13:28 +01:00
2019-03-12 21:25:55 +01:00
/* Remove all the comments from any user in any note of the user */
DB_QueryDELETE ("can not remove comments",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_pubs"
" USING tl_notes,tl_pubs"
" WHERE tl_notes.UsrCod=%ld"
" AND tl_notes.NotCod=tl_pubs.NotCod"
" AND tl_pubs.PubType=%u",
2019-03-12 21:25:55 +01:00
UsrCod,(unsigned) TL_PUB_COMMENT_TO_NOTE);
2016-01-08 10:13:28 +01:00
2019-03-12 21:25:55 +01:00
/* Remove content of all the comments of the user in any note */
DB_QueryDELETE ("can not remove comments",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_comments"
" USING tl_pubs,tl_comments"
" WHERE tl_pubs.PublisherCod=%ld"
" AND tl_pubs.PubType=%u"
" AND tl_pubs.PubCod=tl_comments.PubCod",
2019-03-12 21:25:55 +01:00
UsrCod,(unsigned) TL_PUB_COMMENT_TO_NOTE);
2016-01-08 10:13:28 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove all the posts of the user *****/
DB_QueryDELETE ("can not remove posts",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_posts"
2018-11-02 22:00:31 +01:00
" WHERE PstCod IN"
2019-11-25 13:29:56 +01:00
" (SELECT Cod FROM tl_notes"
2018-11-02 22:00:31 +01:00
" WHERE UsrCod=%ld AND NoteType=%u)",
2019-03-12 21:25:55 +01:00
UsrCod,(unsigned) TL_NOTE_POST);
2016-01-08 10:13:28 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove all the publications of any user authored by the user *****/
DB_QueryDELETE ("can not remove publications",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_pubs"
" USING tl_notes,tl_pubs"
" WHERE tl_notes.UsrCod=%ld"
" AND tl_notes.NotCod=tl_pubs.NotCod",
2018-11-02 22:00:31 +01:00
UsrCod);
2016-01-11 14:42:54 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove all the publications of the user *****/
DB_QueryDELETE ("can not remove publications",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_pubs"
2019-03-12 21:25:55 +01:00
" WHERE PublisherCod=%ld",
2018-11-02 22:00:31 +01:00
UsrCod);
2016-01-08 10:13:28 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove all the notes of the user *****/
DB_QueryDELETE ("can not remove notes",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_notes"
2019-03-12 21:25:55 +01:00
" WHERE UsrCod=%ld",
2018-11-02 22:00:31 +01:00
UsrCod);
2016-01-08 10:13:28 +01:00
}
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/****************** Check if a user has published a note *********************/
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static bool TL_CheckIfNoteIsSharedByUsr (long NotCod,long UsrCod)
2016-01-01 20:19:43 +01:00
{
2019-03-12 21:25:55 +01:00
return (DB_QueryCOUNT ("can not check if a user has shared a note",
2019-11-25 13:29:56 +01:00
"SELECT COUNT(*) FROM tl_pubs"
2018-11-03 20:52:00 +01:00
" WHERE NotCod=%ld"
" AND PublisherCod=%ld"
" AND PubType=%u",
NotCod,
UsrCod,
2019-03-12 21:25:55 +01:00
(unsigned) TL_PUB_SHARED_NOTE) != 0);
2016-01-01 20:19:43 +01:00
}
2016-01-19 00:50:35 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/****************** Check if a user has favourited a note ********************/
2016-01-19 00:50:35 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static bool TL_CheckIfNoteIsFavedByUsr (long NotCod,long UsrCod)
2016-01-19 00:50:35 +01:00
{
2018-11-03 20:52:00 +01:00
return (DB_QueryCOUNT ("can not check if a user"
2019-03-12 21:25:55 +01:00
" has favourited a note",
2019-11-25 13:29:56 +01:00
"SELECT COUNT(*) FROM tl_notes_fav"
2018-11-03 20:52:00 +01:00
" WHERE NotCod=%ld AND UsrCod=%ld",
NotCod,UsrCod) != 0);
2016-01-19 00:50:35 +01:00
}
2016-01-19 12:54:27 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/**************** Check if a user has favourited a comment *******************/
2016-01-19 12:54:27 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static bool TL_CheckIfCommIsFavedByUsr (long PubCod,long UsrCod)
2016-01-19 12:54:27 +01:00
{
2018-11-03 20:52:00 +01:00
return (DB_QueryCOUNT ("can not check if a user"
2019-03-12 21:25:55 +01:00
" has favourited a comment",
2019-11-25 13:29:56 +01:00
"SELECT COUNT(*) FROM tl_comments_fav"
2018-11-03 20:52:00 +01:00
" WHERE PubCod=%ld AND UsrCod=%ld",
PubCod,UsrCod) != 0);
2016-01-19 12:54:27 +01:00
}
2016-01-04 11:58:36 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********** Get number of times a note has been shared in timeline ***********/
2016-01-04 11:58:36 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_UpdateNumTimesANoteHasBeenShared (struct TL_Note *SocNot)
2016-01-04 11:58:36 +01:00
{
2016-01-04 14:49:10 +01:00
/***** Get number of times (users) this note has been shared *****/
2019-02-25 02:02:10 +01:00
SocNot->NumShared =
2018-11-03 20:52:00 +01:00
(unsigned) DB_QueryCOUNT ("can not get number of times"
" a note has been shared",
2019-11-25 13:29:56 +01:00
"SELECT COUNT(*) FROM tl_pubs"
2018-11-03 20:52:00 +01:00
" WHERE NotCod=%ld"
" AND PublisherCod<>%ld"
" AND PubType=%u",
SocNot->NotCod,
SocNot->UsrCod, // The author
2019-03-12 21:25:55 +01:00
(unsigned) TL_PUB_SHARED_NOTE);
2016-01-04 14:49:10 +01:00
}
2016-01-19 00:50:35 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/*************** Get number of times a note has been favourited **************/
2016-01-19 00:50:35 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_GetNumTimesANoteHasBeenFav (struct TL_Note *SocNot)
2016-01-19 00:50:35 +01:00
{
/***** Get number of times (users) this note has been favourited *****/
2019-02-24 19:33:38 +01:00
SocNot->NumFavs =
2018-11-03 20:52:00 +01:00
(unsigned) DB_QueryCOUNT ("can not get number of times"
" a note has been favourited",
2019-11-25 13:29:56 +01:00
"SELECT COUNT(*) FROM tl_notes_fav"
2018-11-03 20:52:00 +01:00
" WHERE NotCod=%ld"
" AND UsrCod<>%ld", // Extra check
SocNot->NotCod,
SocNot->UsrCod); // The author
2016-01-19 21:07:52 +01:00
}
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************ Get number of times a comment has been favourited **************/
2016-01-19 21:07:52 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_GetNumTimesACommHasBeenFav (struct TL_Comment *SocCom)
2016-01-19 21:07:52 +01:00
{
/***** Get number of times (users) this comment has been favourited *****/
2019-02-24 19:33:38 +01:00
SocCom->NumFavs =
2018-11-03 20:52:00 +01:00
(unsigned) DB_QueryCOUNT ("can not get number of times"
" a comment has been favourited",
2019-11-25 13:29:56 +01:00
"SELECT COUNT(*) FROM tl_comments_fav"
2018-11-03 20:52:00 +01:00
" WHERE PubCod=%ld"
" AND UsrCod<>%ld", // Extra check
SocCom->PubCod,
SocCom->UsrCod); // The author
2016-01-19 00:50:35 +01:00
}
2016-01-04 14:49:10 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************* Show users who have shared this note ********************/
2016-01-04 14:49:10 +01:00
/*****************************************************************************/
2019-03-28 15:22:38 +01:00
static void TL_ShowUsrsWhoHaveSharedNote (const struct TL_Note *SocNot,
2019-03-29 00:57:51 +01:00
TL_HowMany_t HowMany)
2016-01-04 14:49:10 +01:00
{
2018-11-01 21:59:42 +01:00
MYSQL_RES *mysql_res;
unsigned NumFirstUsrs = 0;
2016-01-19 01:31:35 +01:00
/***** Get users who have shared this note *****/
2018-10-30 03:29:40 +01:00
if (SocNot->NumShared)
2018-11-01 21:59:42 +01:00
NumFirstUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get users",
2019-11-25 13:29:56 +01:00
"SELECT PublisherCod FROM tl_pubs"
2018-11-01 21:59:42 +01:00
" WHERE NotCod=%ld"
" AND PublisherCod<>%ld"
" AND PubType=%u"
" ORDER BY PubCod LIMIT %u",
SocNot->NotCod,
SocNot->UsrCod,
2019-03-12 21:25:55 +01:00
(unsigned) TL_PUB_SHARED_NOTE,
2019-03-29 00:57:51 +01:00
HowMany == TL_SHOW_A_FEW_USRS ? TL_DEF_USRS_SHOWN :
TL_MAX_USRS_SHOWN);
2018-11-01 21:59:42 +01:00
/***** Show users *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_NUM_USRS\"");
2019-03-29 00:57:51 +01:00
TL_ShowNumSharersOrFavers (SocNot->NumShared);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-03-29 00:57:51 +01:00
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_USRS\"");
2019-03-12 21:25:55 +01:00
TL_ShowSharersOrFavers (&mysql_res,SocNot->NumShared,NumFirstUsrs);
2019-03-28 15:22:38 +01:00
if (NumFirstUsrs < SocNot->NumShared)
2019-03-29 00:57:51 +01:00
TL_PutFormToSeeAllSharersNote (SocNot,HowMany);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2018-11-01 21:59:42 +01:00
/***** Free structure that stores the query result *****/
if (SocNot->NumShared)
DB_FreeMySQLResult (&mysql_res);
2016-01-19 01:31:35 +01:00
}
2016-01-04 14:49:10 +01:00
2016-01-19 01:31:35 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************ Show users who have marked this note as favourite **************/
2016-01-19 01:31:35 +01:00
/*****************************************************************************/
2016-01-04 14:49:10 +01:00
2019-03-28 15:22:38 +01:00
static void TL_ShowUsrsWhoHaveMarkedNoteAsFav (const struct TL_Note *SocNot,
2019-03-29 00:57:51 +01:00
TL_HowMany_t HowMany)
2016-01-19 01:31:35 +01:00
{
2018-11-01 21:59:42 +01:00
MYSQL_RES *mysql_res;
unsigned NumFirstUsrs = 0;
2016-01-19 21:07:52 +01:00
/***** Get users who have marked this note as favourite *****/
2018-10-30 03:29:40 +01:00
if (SocNot->NumFavs)
2019-02-24 15:15:43 +01:00
{
2018-11-01 21:59:42 +01:00
/***** Get list of users from database *****/
NumFirstUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get users",
2019-11-25 13:29:56 +01:00
"SELECT UsrCod FROM tl_notes_fav"
2018-11-01 21:59:42 +01:00
" WHERE NotCod=%ld"
" AND UsrCod<>%ld" // Extra check
" ORDER BY FavCod LIMIT %u",
SocNot->NotCod,
SocNot->UsrCod,
2019-03-29 00:57:51 +01:00
HowMany == TL_SHOW_A_FEW_USRS ? TL_DEF_USRS_SHOWN :
TL_MAX_USRS_SHOWN);
2019-02-24 15:15:43 +01:00
}
2018-11-01 21:59:42 +01:00
/***** Show users *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_NUM_USRS\"");
2019-03-29 00:57:51 +01:00
TL_ShowNumSharersOrFavers (SocNot->NumFavs);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-03-28 15:22:38 +01:00
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_USRS\"");
2019-03-29 00:57:51 +01:00
TL_ShowSharersOrFavers (&mysql_res,SocNot->NumFavs,NumFirstUsrs);
if (NumFirstUsrs < SocNot->NumFavs) // Not all are shown
TL_PutFormToSeeAllFaversNote (SocNot,HowMany);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2018-11-01 21:59:42 +01:00
/***** Free structure that stores the query result *****/
if (SocNot->NumFavs)
DB_FreeMySQLResult (&mysql_res);
2016-01-04 11:58:36 +01:00
}
2016-01-19 21:07:52 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************ Show users who have marked this note as favourite **************/
2016-01-19 21:07:52 +01:00
/*****************************************************************************/
2019-03-28 15:22:38 +01:00
static void TL_ShowUsrsWhoHaveMarkedCommAsFav (const struct TL_Comment *SocCom,
2019-03-29 00:57:51 +01:00
TL_HowMany_t HowMany)
2016-01-19 21:07:52 +01:00
{
2018-11-01 21:59:42 +01:00
MYSQL_RES *mysql_res;
unsigned NumFirstUsrs = 0;
2016-01-19 21:07:52 +01:00
/***** Get users who have marked this comment as favourite *****/
2018-10-30 03:29:40 +01:00
if (SocCom->NumFavs)
2018-11-01 21:59:42 +01:00
/***** Get list of users from database *****/
NumFirstUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get users",
2019-11-25 13:29:56 +01:00
"SELECT UsrCod FROM tl_comments_fav"
2018-11-01 21:59:42 +01:00
" WHERE PubCod=%ld"
" AND UsrCod<>%ld" // Extra check
" ORDER BY FavCod LIMIT %u",
SocCom->PubCod,
SocCom->UsrCod,
2019-03-29 00:57:51 +01:00
HowMany == TL_SHOW_A_FEW_USRS ? TL_DEF_USRS_SHOWN :
TL_MAX_USRS_SHOWN);
2018-11-01 21:59:42 +01:00
/***** Show users *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_NUM_USRS\"");
2019-03-29 00:57:51 +01:00
TL_ShowNumSharersOrFavers (SocCom->NumFavs);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-03-29 00:57:51 +01:00
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_USRS\"");
2019-03-12 21:25:55 +01:00
TL_ShowSharersOrFavers (&mysql_res,SocCom->NumFavs,NumFirstUsrs);
2019-03-28 15:22:38 +01:00
if (NumFirstUsrs < SocCom->NumFavs)
2019-03-29 00:57:51 +01:00
TL_PutFormToSeeAllFaversComment (SocCom,HowMany);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2018-11-01 21:59:42 +01:00
/***** Free structure that stores the query result *****/
if (SocCom->NumFavs)
DB_FreeMySQLResult (&mysql_res);
2016-01-19 21:07:52 +01:00
}
2016-01-19 01:12:20 +01:00
/*****************************************************************************/
2016-01-19 12:54:27 +01:00
/************************ Show sharers or favouriters ************************/
2016-01-19 01:12:20 +01:00
/*****************************************************************************/
2019-03-29 00:57:51 +01:00
static void TL_ShowNumSharersOrFavers (unsigned NumUsrs)
{
/***** Show number of users who have marked this note as favourite *****/
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%u",NumUsrs);
2019-03-29 00:57:51 +01:00
}
2019-03-12 21:25:55 +01:00
static void TL_ShowSharersOrFavers (MYSQL_RES **mysql_res,
2019-03-13 10:23:41 +01:00
unsigned NumUsrs,unsigned NumFirstUsrs)
2016-01-19 01:12:20 +01:00
{
MYSQL_ROW row;
unsigned NumUsr;
unsigned NumUsrsShown = 0;
struct UsrData UsrDat;
bool ShowPhoto;
2017-01-28 15:58:46 +01:00
char PhotoURL[PATH_MAX + 1];
2016-01-19 01:12:20 +01:00
2016-01-19 01:31:35 +01:00
if (NumUsrs)
2016-01-19 01:12:20 +01:00
{
2018-11-01 21:59:42 +01:00
/***** A list of users has been got from database *****/
2016-01-19 01:31:35 +01:00
if (NumFirstUsrs)
2016-01-19 01:12:20 +01:00
{
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** List users *****/
for (NumUsr = 0;
2016-01-19 01:31:35 +01:00
NumUsr < NumFirstUsrs;
2016-01-19 01:12:20 +01:00
NumUsr++)
{
/***** Get user *****/
2018-11-01 21:59:42 +01:00
row = mysql_fetch_row (*mysql_res);
2016-01-19 01:12:20 +01:00
/* Get user's code (row[0]) */
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/***** Get user's data and show user's photo *****/
2019-03-19 13:22:14 +01:00
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS))
2016-01-19 01:12:20 +01:00
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_SHARER\"");
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (&UsrDat,PhotoURL);
2016-01-19 01:12:20 +01:00
Pho_ShowUsrPhoto (&UsrDat,ShowPhoto ? PhotoURL :
NULL,
2019-02-24 15:15:43 +01:00
"PHOTO12x16",Pho_ZOOM,true); // Use unique id
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-19 01:12:20 +01:00
NumUsrsShown++;
}
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
}
}
2015-12-31 18:40:45 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************** Get data of note using its code ************************/
2015-12-31 18:40:45 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_GetDataOfNoteByCod (struct TL_Note *SocNot)
2015-12-30 12:40:13 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-01-11 02:15:23 +01:00
if (SocNot->NotCod > 0)
2015-12-30 12:40:13 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Get data of note from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get data of note",
2018-11-01 21:59:42 +01:00
"SELECT NotCod," // row[0]
"NoteType," // row[1]
"Cod," // row[2]
"UsrCod," // row[3]
"HieCod," // row[4]
"Unavailable," // row[5]
"UNIX_TIMESTAMP(TimeNote)" // row[6]
2019-11-25 13:29:56 +01:00
" FROM tl_notes"
2018-11-01 21:59:42 +01:00
" WHERE NotCod=%ld",
SocNot->NotCod))
2016-01-11 02:15:23 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Get data of note *****/
2016-01-11 02:15:23 +01:00
row = mysql_fetch_row (mysql_res);
2019-03-12 21:25:55 +01:00
TL_GetDataOfNoteFromRow (row,SocNot);
2016-01-11 02:15:23 +01:00
}
else
2019-03-12 21:25:55 +01:00
/***** Reset fields of note *****/
TL_ResetNote (SocNot);
2016-01-23 01:38:55 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2015-12-30 12:40:13 +01:00
}
else
2019-03-12 21:25:55 +01:00
/***** Reset fields of note *****/
TL_ResetNote (SocNot);
2015-12-30 12:40:13 +01:00
}
2015-12-30 16:33:36 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************* Get data of comment using its code **********************/
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_GetDataOfCommByCod (struct TL_Comment *SocCom)
2016-01-08 01:53:37 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-01-25 12:32:13 +01:00
if (SocCom->PubCod > 0)
2016-01-08 01:53:37 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Get data of comment from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get data of comment",
2019-11-25 13:29:56 +01:00
"SELECT tl_pubs.PubCod," // row[0]
"tl_pubs.PublisherCod," // row[1]
"tl_pubs.NotCod," // row[2]
"UNIX_TIMESTAMP(tl_pubs.TimePublish)," // row[3]
"tl_comments.Txt," // row[4]
"tl_comments.MedCod" // row[5]
" FROM tl_pubs,tl_comments"
" WHERE tl_pubs.PubCod=%ld"
" AND tl_pubs.PubType=%u"
" AND tl_pubs.PubCod=tl_comments.PubCod",
2019-03-12 21:25:55 +01:00
SocCom->PubCod,(unsigned) TL_PUB_COMMENT_TO_NOTE))
2016-01-11 02:15:23 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Get data of comment *****/
2016-01-11 02:15:23 +01:00
row = mysql_fetch_row (mysql_res);
2019-03-12 21:25:55 +01:00
TL_GetDataOfCommentFromRow (row,SocCom);
2016-01-11 02:15:23 +01:00
}
else
2019-03-12 21:25:55 +01:00
/***** Reset fields of comment *****/
TL_ResetComment (SocCom);
2016-01-23 01:38:55 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-01-08 01:53:37 +01:00
}
else
2019-03-12 21:25:55 +01:00
/***** Reset fields of comment *****/
TL_ResetComment (SocCom);
2016-01-08 01:53:37 +01:00
}
/*****************************************************************************/
2019-11-25 13:29:56 +01:00
/***************** Get data of publication using its code ********************/
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_GetDataOfPublicationFromRow (MYSQL_ROW row,struct TL_Publication *SocPub)
2016-01-08 01:53:37 +01:00
{
2019-11-22 01:04:03 +01:00
static const TL_TopMessage_t TopMessages[TL_NUM_PUB_TYPES] =
2016-01-25 17:23:14 +01:00
{
2019-11-22 01:04:03 +01:00
[TL_PUB_UNKNOWN ] = TL_TOP_MESSAGE_NONE,
[TL_PUB_ORIGINAL_NOTE ] = TL_TOP_MESSAGE_NONE,
[TL_PUB_SHARED_NOTE ] = TL_TOP_MESSAGE_SHARED,
[TL_PUB_COMMENT_TO_NOTE] = TL_TOP_MESSAGE_COMMENTED,
2016-01-25 17:23:14 +01:00
};
2019-03-12 21:25:55 +01:00
/***** Get code of publication (row[0]) *****/
2016-01-08 01:53:37 +01:00
SocPub->PubCod = Str_ConvertStrCodToLongCod (row[0]);
2019-03-12 21:25:55 +01:00
/***** Get note code (row[1]) *****/
2016-01-08 01:53:37 +01:00
SocPub->NotCod = Str_ConvertStrCodToLongCod (row[1]);
2016-01-19 21:07:52 +01:00
/***** Get publisher's code (row[2]) *****/
2016-01-08 01:53:37 +01:00
SocPub->PublisherCod = Str_ConvertStrCodToLongCod (row[2]);
2019-03-06 10:13:39 +01:00
/***** Get type of publication (row[3]) *****/
2019-03-12 21:25:55 +01:00
SocPub->PubType = TL_GetPubTypeFromStr ((const char *) row[3]);
2016-01-25 17:23:14 +01:00
SocPub->TopMessage = TopMessages[SocPub->PubType];
2016-01-11 20:54:14 +01:00
2016-01-19 21:07:52 +01:00
/***** Get time of the note (row[4]) *****/
2016-01-11 20:54:14 +01:00
SocPub->DateTimeUTC = Dat_GetUNIXTimeFromStr (row[4]);
2016-01-08 01:53:37 +01:00
}
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************************ Get data of note from row **************************/
2015-12-30 16:33:36 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_GetDataOfNoteFromRow (MYSQL_ROW row,struct TL_Note *SocNot)
2015-12-30 16:33:36 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Get code (row[0]) *****/
2016-01-02 14:36:34 +01:00
SocNot->NotCod = Str_ConvertStrCodToLongCod (row[0]);
2015-12-30 16:33:36 +01:00
2016-01-19 21:07:52 +01:00
/***** Get note type (row[1]) *****/
2019-03-12 21:25:55 +01:00
SocNot->NoteType = TL_GetNoteTypeFromStr ((const char *) row[1]);
2015-12-30 16:33:36 +01:00
2016-01-19 21:07:52 +01:00
/***** Get file/post... code (row[2]) *****/
2016-01-11 20:54:14 +01:00
SocNot->Cod = Str_ConvertStrCodToLongCod (row[2]);
2015-12-30 16:33:36 +01:00
2016-01-19 21:07:52 +01:00
/***** Get (from) user code (row[3]) *****/
2016-01-11 20:54:14 +01:00
SocNot->UsrCod = Str_ConvertStrCodToLongCod (row[3]);
2015-12-30 16:33:36 +01:00
2016-01-19 21:07:52 +01:00
/***** Get hierarchy code (row[4]) *****/
2016-01-11 20:54:14 +01:00
SocNot->HieCod = Str_ConvertStrCodToLongCod (row[4]);
2015-12-30 16:33:36 +01:00
2016-01-19 21:07:52 +01:00
/***** File/post... unavailable (row[5]) *****/
2016-09-07 18:48:10 +02:00
SocNot->Unavailable = (row[5][0] == 'Y');
2016-01-03 17:34:06 +01:00
2016-01-19 21:07:52 +01:00
/***** Get time of the note (row[6]) *****/
2016-01-03 17:34:06 +01:00
SocNot->DateTimeUTC = Dat_GetUNIXTimeFromStr (row[6]);
2016-01-19 21:07:52 +01:00
2019-03-12 21:25:55 +01:00
/***** Get number of times this note has been shared *****/
TL_UpdateNumTimesANoteHasBeenShared (SocNot);
2016-01-19 21:07:52 +01:00
2019-03-12 21:25:55 +01:00
/***** Get number of times this note has been favourited *****/
TL_GetNumTimesANoteHasBeenFav (SocNot);
2015-12-31 18:40:45 +01:00
}
2016-01-11 20:54:14 +01:00
/*****************************************************************************/
2019-11-25 13:29:56 +01:00
/******* Get publication type from string number coming from database ********/
2016-01-11 20:54:14 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static TL_PubType_t TL_GetPubTypeFromStr (const char *Str)
2016-01-11 20:54:14 +01:00
{
unsigned UnsignedNum;
if (sscanf (Str,"%u",&UnsignedNum) == 1)
2019-03-12 21:25:55 +01:00
if (UnsignedNum < TL_NUM_PUB_TYPES)
return (TL_PubType_t) UnsignedNum;
2016-01-11 20:54:14 +01:00
2019-03-12 21:25:55 +01:00
return TL_PUB_UNKNOWN;
2016-01-11 20:54:14 +01:00
}
2015-12-31 18:40:45 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********* Get note type from string number coming from database *************/
2015-12-31 18:40:45 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static TL_NoteType_t TL_GetNoteTypeFromStr (const char *Str)
2015-12-31 18:40:45 +01:00
{
unsigned UnsignedNum;
if (sscanf (Str,"%u",&UnsignedNum) == 1)
2019-03-12 21:25:55 +01:00
if (UnsignedNum < TL_NUM_NOTE_TYPES)
return (TL_NoteType_t) UnsignedNum;
2015-12-31 18:40:45 +01:00
2019-03-12 21:25:55 +01:00
return TL_NOTE_UNKNOWN;
2015-12-30 16:33:36 +01:00
}
2016-01-05 04:54:00 +01:00
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********************** Get data of comment from row *************************/
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_GetDataOfCommentFromRow (MYSQL_ROW row,struct TL_Comment *SocCom)
2016-01-08 01:53:37 +01:00
{
2016-04-08 23:30:43 +02:00
/*
row[0]: PubCod
row[1]: PublisherCod
row[2]: NotCod
row[3]: TimePublish
2019-11-25 09:06:27 +01:00
row[4]: Txt
2019-03-18 15:42:22 +01:00
row[5]: MedCod
2016-04-08 23:30:43 +02:00
*/
2019-03-12 21:25:55 +01:00
/***** Get code of comment (row[0]) *****/
2016-01-25 12:32:13 +01:00
SocCom->PubCod = Str_ConvertStrCodToLongCod (row[0]);
2016-01-08 01:53:37 +01:00
2016-01-19 21:07:52 +01:00
/***** Get (from) user code (row[1]) *****/
2016-01-08 01:53:37 +01:00
SocCom->UsrCod = Str_ConvertStrCodToLongCod (row[1]);
2019-03-12 21:25:55 +01:00
/***** Get code of note (row[2]) *****/
2016-01-08 01:53:37 +01:00
SocCom->NotCod = Str_ConvertStrCodToLongCod (row[2]);
2016-01-19 21:07:52 +01:00
/***** Get time of the note (row[3]) *****/
2016-01-08 01:53:37 +01:00
SocCom->DateTimeUTC = Dat_GetUNIXTimeFromStr (row[3]);
2019-11-24 23:51:03 +01:00
/***** Get text content (row[4]) *****/
Str_Copy (SocCom->Content.Txt,row[4],
2017-01-17 03:10:43 +01:00
Cns_MAX_BYTES_LONG_TEXT);
2016-01-19 21:07:52 +01:00
/***** Get number of times this comment has been favourited *****/
2019-03-12 21:25:55 +01:00
TL_GetNumTimesACommHasBeenFav (SocCom);
2016-04-08 23:30:43 +02:00
2019-11-24 23:51:03 +01:00
/***** Get media content (row[5]) *****/
SocCom->Content.Media.MedCod = Str_ConvertStrCodToLongCod (row[5]);
Med_GetMediaDataByCod (&SocCom->Content.Media);
2016-01-08 01:53:37 +01:00
}
2016-01-05 04:54:00 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/*************************** Reset fields of note ****************************/
2016-01-05 04:54:00 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_ResetNote (struct TL_Note *SocNot)
2016-01-05 04:54:00 +01:00
{
2016-01-11 02:15:23 +01:00
SocNot->NotCod = -1L;
2019-03-12 21:25:55 +01:00
SocNot->NoteType = TL_NOTE_UNKNOWN;
2016-01-05 04:54:00 +01:00
SocNot->UsrCod = -1L;
SocNot->HieCod = -1L;
SocNot->Cod = -1L;
SocNot->Unavailable = false;
SocNot->DateTimeUTC = (time_t) 0;
SocNot->NumShared = 0;
}
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************************** Reset fields of comment **************************/
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_ResetComment (struct TL_Comment *SocCom)
2016-01-08 01:53:37 +01:00
{
2016-01-25 12:32:13 +01:00
SocCom->PubCod = -1L;
2016-01-08 01:53:37 +01:00
SocCom->UsrCod = -1L;
SocCom->NotCod = -1L;
SocCom->DateTimeUTC = (time_t) 0;
2019-11-24 23:51:03 +01:00
SocCom->Content.Txt[0] = '\0';
2016-01-08 01:53:37 +01:00
}
2016-01-11 19:28:43 +01:00
2016-01-12 20:58:19 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************* Clear unused old timelines in database ******************/
2016-01-12 20:58:19 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_ClearOldTimelinesDB (void)
2016-01-12 20:58:19 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Remove timelines for expired sessions *****/
DB_QueryDELETE ("can not remove old timelines",
2019-11-25 13:29:56 +01:00
"DELETE LOW_PRIORITY FROM tl_timelines"
2018-11-02 22:00:31 +01:00
" WHERE SessionId NOT IN (SELECT SessionId FROM sessions)");
2016-01-12 20:58:19 +01:00
}
2016-01-12 19:43:17 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/**************** Clear timeline for this session in database ****************/
2016-01-12 19:43:17 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_ClearTimelineThisSession (void)
2016-01-12 19:43:17 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Remove timeline for this session *****/
DB_QueryDELETE ("can not remove timeline",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_timelines"
2019-03-12 21:25:55 +01:00
" WHERE SessionId='%s'",
2018-11-02 22:00:31 +01:00
Gbl.Session.Id);
2016-01-12 19:43:17 +01:00
}
2016-01-12 20:58:19 +01:00
/*****************************************************************************/
2016-01-17 01:50:43 +01:00
/****** Add just retrieved notes to current timeline for this session ********/
2016-01-12 20:58:19 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_AddNotesJustRetrievedToTimelineThisSession (void)
2016-01-12 20:58:19 +01:00
{
2019-03-12 21:25:55 +01:00
DB_QueryINSERT ("can not insert notes in timeline",
2019-11-25 13:29:56 +01:00
"INSERT IGNORE INTO tl_timelines"
2018-11-02 19:37:11 +01:00
" (SessionId,NotCod)"
2019-11-25 13:29:56 +01:00
" SELECT DISTINCTROW '%s',NotCod FROM tl_not_codes",
2018-11-02 19:37:11 +01:00
Gbl.Session.Id);
2016-01-12 20:58:19 +01:00
}
2016-01-22 12:05:25 +01:00
/*****************************************************************************/
2019-11-25 13:29:56 +01:00
/***************** Get notification of a new publication *********************/
2016-01-22 12:05:25 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
char **ContentStr,
long PubCod,bool GetContent)
2016-01-22 12:05:25 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2019-03-12 21:25:55 +01:00
struct TL_Publication SocPub;
struct TL_Note SocNot;
2019-11-24 23:51:03 +01:00
struct PostContent Content;
2017-01-15 22:58:26 +01:00
size_t Length;
2016-01-28 13:14:16 +01:00
bool ContentCopied = false;
2016-01-22 12:05:25 +01:00
2016-01-23 01:38:55 +01:00
/***** Return nothing on error *****/
2019-03-12 21:25:55 +01:00
SocPub.PubType = TL_PUB_UNKNOWN;
2017-03-06 13:01:16 +01:00
SummaryStr[0] = '\0'; // Return nothing on error
2019-11-24 23:51:03 +01:00
Content.Txt[0] = '\0';
2016-01-22 12:05:25 +01:00
2019-03-12 21:25:55 +01:00
/***** Get summary and content from post from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get data of publication",
2018-11-01 21:59:42 +01:00
"SELECT PubCod," // row[0]
"NotCod," // row[1]
"PublisherCod," // row[2]
"PubType," // row[3]
"UNIX_TIMESTAMP(TimePublish)" // row[4]
2019-11-25 13:29:56 +01:00
" FROM tl_pubs WHERE PubCod=%ld",
2018-11-01 21:59:42 +01:00
PubCod) == 1) // Result should have a unique row
2016-01-22 12:05:25 +01:00
{
2019-03-12 21:25:55 +01:00
/* Get data of publication */
2016-01-22 12:05:25 +01:00
row = mysql_fetch_row (mysql_res);
2019-03-12 21:25:55 +01:00
TL_GetDataOfPublicationFromRow (row,&SocPub);
2016-01-22 12:05:25 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-01-23 01:38:55 +01:00
/***** Get summary and content *****/
switch (SocPub.PubType)
{
2019-03-12 21:25:55 +01:00
case TL_PUB_UNKNOWN:
2016-01-23 01:38:55 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_PUB_ORIGINAL_NOTE:
case TL_PUB_SHARED_NOTE:
/* Get data of note */
2016-01-23 01:38:55 +01:00
SocNot.NotCod = SocPub.NotCod;
2019-03-12 21:25:55 +01:00
TL_GetDataOfNoteByCod (&SocNot);
2016-01-23 01:38:55 +01:00
2019-03-12 21:25:55 +01:00
if (SocNot.NoteType == TL_NOTE_POST)
2016-01-23 01:38:55 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Get content of post from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get the content of a post",
2019-11-25 09:06:27 +01:00
"SELECT Txt" // row[0]
2019-11-25 13:29:56 +01:00
" FROM tl_posts"
2018-11-01 21:59:42 +01:00
" WHERE PstCod=%ld",
SocNot.Cod) == 1) // Result should have a unique row
2016-01-23 01:38:55 +01:00
{
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
/****** Get content (row[0]) *****/
2019-11-24 23:51:03 +01:00
Str_Copy (Content.Txt,row[0],
2017-01-17 03:10:43 +01:00
Cns_MAX_BYTES_LONG_TEXT);
2016-01-23 01:38:55 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-01-28 13:14:16 +01:00
/***** Copy content string *****/
if (GetContent)
2017-01-15 22:58:26 +01:00
{
2019-11-24 23:51:03 +01:00
Length = strlen (Content.Txt);
2017-01-15 22:58:26 +01:00
if ((*ContentStr = (char *) malloc (Length + 1)) != NULL)
2016-01-28 13:14:16 +01:00
{
2019-11-24 23:51:03 +01:00
Str_Copy (*ContentStr,Content.Txt,
2017-01-17 03:10:43 +01:00
Length);
2016-01-28 13:14:16 +01:00
ContentCopied = true;
}
2017-01-15 22:58:26 +01:00
}
2016-01-28 13:14:16 +01:00
2016-01-23 01:38:55 +01:00
/***** Copy summary string *****/
2019-11-24 23:51:03 +01:00
Str_LimitLengthHTMLStr (Content.Txt,Ntf_MAX_CHARS_SUMMARY);
Str_Copy (SummaryStr,Content.Txt,
2017-03-08 14:12:33 +01:00
Ntf_MAX_BYTES_SUMMARY);
2016-01-23 01:38:55 +01:00
}
else
2019-03-12 21:25:55 +01:00
TL_GetNoteSummary (&SocNot,SummaryStr);
2016-01-23 01:38:55 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_PUB_COMMENT_TO_NOTE:
/***** Get content of post from database *****/
2018-11-01 21:59:42 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get the content"
2019-03-12 21:25:55 +01:00
" of a comment to a note",
2019-11-25 09:06:27 +01:00
"SELECT Txt" // row[0]
2019-11-25 13:29:56 +01:00
" FROM tl_comments"
2018-11-01 21:59:42 +01:00
" WHERE PubCod=%ld",
SocPub.PubCod) == 1) // Result should have a unique row
2016-01-23 01:38:55 +01:00
{
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
/****** Get content (row[0]) *****/
2019-11-24 23:51:03 +01:00
Str_Copy (Content.Txt,row[0],
2017-01-17 03:10:43 +01:00
Cns_MAX_BYTES_LONG_TEXT);
2016-01-23 01:38:55 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-01-28 13:14:16 +01:00
/***** Copy content string *****/
if (GetContent)
2017-01-15 22:58:26 +01:00
{
2019-11-24 23:51:03 +01:00
Length = strlen (Content.Txt);
2017-01-15 22:58:26 +01:00
if ((*ContentStr = (char *) malloc (Length + 1)) != NULL)
2016-01-28 13:14:16 +01:00
{
2019-11-24 23:51:03 +01:00
Str_Copy (*ContentStr,Content.Txt,
2017-01-17 03:10:43 +01:00
Length);
2016-01-28 13:14:16 +01:00
ContentCopied = true;
}
2017-01-15 22:58:26 +01:00
}
2016-01-28 13:14:16 +01:00
2016-01-23 01:38:55 +01:00
/***** Copy summary string *****/
2019-11-24 23:51:03 +01:00
Str_LimitLengthHTMLStr (Content.Txt,Ntf_MAX_CHARS_SUMMARY);
Str_Copy (SummaryStr,Content.Txt,
2017-03-08 14:12:33 +01:00
Ntf_MAX_BYTES_SUMMARY);
2016-01-23 01:38:55 +01:00
break;
}
2016-01-28 13:14:16 +01:00
/***** Create empty content string if nothing copied *****/
if (GetContent && !ContentCopied)
if ((*ContentStr = (char *) malloc (1)) != NULL)
(*ContentStr)[0] = '\0';
2016-01-22 12:05:25 +01:00
}
2016-01-28 13:14:16 +01:00
2016-01-25 11:43:14 +01:00
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
/*** Create a notification about mention for any nickname in a publication ***/
2016-01-25 11:43:14 +01:00
/*****************************************************************************/
/*
Example: "The user @rms says..."
^ ^
PtrStart ___| |___ PtrEnd
Length = 3
*/
static void Str_AnalyzeTxtAndStoreNotifyEventToMentionedUsrs (long PubCod,const char *Txt)
{
const char *Ptr;
bool IsNickname;
struct
{
const char *PtrStart;
const char *PtrEnd;
size_t Length; // Length of the nickname
} Nickname;
struct UsrData UsrDat;
2018-10-10 23:56:42 +02:00
bool ItsMe;
2016-01-25 11:43:14 +01:00
bool CreateNotif;
bool NotifyByEmail;
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Find nicknames and create notifications *****/
for (Ptr = Txt;
*Ptr;)
/* Check if the next char is the start of a nickname */
if ((int) *Ptr == (int) '@')
{
/* Find nickname end */
Ptr++; // Points to first character after @
Nickname.PtrStart = Ptr;
/* A nick can have digits, letters and '_' */
for (;
*Ptr;
Ptr++)
if (!((*Ptr >= 'a' && *Ptr <= 'z') ||
(*Ptr >= 'A' && *Ptr <= 'Z') ||
(*Ptr >= '0' && *Ptr <= '9') ||
(*Ptr == '_')))
break;
/* Calculate length of this nickname */
Nickname.PtrEnd = Ptr - 1;
Nickname.Length = (size_t) (Ptr - Nickname.PtrStart);
/* A nick (without arroba) must have a number of characters
2017-03-07 01:56:41 +01:00
Nck_MIN_BYTES_NICKNAME_WITHOUT_ARROBA <= Length <= Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA */
IsNickname = (Nickname.Length >= Nck_MIN_BYTES_NICKNAME_WITHOUT_ARROBA &&
Nickname.Length <= Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA);
2016-01-25 11:43:14 +01:00
if (IsNickname)
{
/* Copy nickname */
2017-02-17 10:53:43 +01:00
strncpy (UsrDat.Nickname,Nickname.PtrStart,Nickname.Length);
2019-03-15 15:25:31 +01:00
UsrDat.Nickname[Nickname.Length] = '\0';
2016-01-25 11:43:14 +01:00
if ((UsrDat.UsrCod = Nck_GetUsrCodFromNickname (UsrDat.Nickname)) > 0)
2018-10-10 23:56:42 +02:00
{
ItsMe = Usr_ItsMe (UsrDat.UsrCod);
if (!ItsMe) // Not me
2016-01-25 11:43:14 +01:00
{
/* Get user's data */
2019-03-19 13:22:14 +01:00
Usr_GetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS);
2016-01-25 11:43:14 +01:00
/* Create notification for the mentioned user *****/
2019-03-19 13:22:14 +01:00
CreateNotif = (UsrDat.NtfEvents.CreateNotif & (1 << Ntf_EVENT_TIMELINE_MENTION));
2016-01-25 11:43:14 +01:00
if (CreateNotif)
{
2019-03-19 13:22:14 +01:00
NotifyByEmail = (UsrDat.NtfEvents.SendEmail & (1 << Ntf_EVENT_TIMELINE_MENTION));
2016-01-25 11:43:14 +01:00
Ntf_StoreNotifyEventToOneUser (Ntf_EVENT_TIMELINE_MENTION,&UsrDat,PubCod,
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
2020-04-07 03:01:41 +02:00
0),
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ctr.CtrCod,
Gbl.Hierarchy.Deg.DegCod,
Gbl.Hierarchy.Crs.CrsCod);
2016-01-25 11:43:14 +01:00
}
}
2018-10-10 23:56:42 +02:00
}
2016-01-25 11:43:14 +01:00
}
}
/* The next char is not the start of a nickname */
else // Character != '@'
Ptr++;
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
2019-03-06 10:13:39 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/****************** Get number of publications from a user *******************/
2019-03-06 10:13:39 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
unsigned long TL_GetNumPubsUsr (long UsrCod)
2019-03-06 10:13:39 +01:00
{
/***** Get number of posts from a user from database *****/
2019-03-12 21:25:55 +01:00
return DB_QueryCOUNT ("can not get number of publications from a user",
2019-11-25 13:29:56 +01:00
"SELECT COUNT(*) FROM tl_pubs"
2019-03-06 10:13:39 +01:00
" WHERE PublisherCod=%ld",
UsrCod);
}