swad-core/swad_social.c

4994 lines
174 KiB
C
Raw Normal View History

2015-12-31 14:25:28 +01:00
// swad_social.c: social networking (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.
2017-01-13 01:51:23 +01:00
Copyright (C) 1999-2017 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 *********************************/
/*****************************************************************************/
#include <linux/limits.h> // For PATH_MAX
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
#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"
2015-12-28 19:23:42 +01:00
#include "swad_global.h"
2016-04-08 16:37:59 +02:00
#include "swad_image.h"
2015-12-28 19:23:42 +01:00
#include "swad_layout.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"
2015-12-28 19:23:42 +01:00
#include "swad_social.h"
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
2016-04-10 14:09:50 +02:00
#define Soc_WIDTH_TIMELINE "560px"
#define Soc_MAX_SHARERS_FAVERS_SHOWN 7 // Maximum number of users shown who have share/fav a social note
2016-01-11 00:27:04 +01:00
2016-04-10 14:09:50 +02:00
#define Soc_MAX_CHARS_IN_POST 1000
2016-01-15 02:41:55 +01:00
2016-01-11 00:27:04 +01:00
// Number of recent publishings got and shown the first time, before refreshing
2016-01-17 01:50:43 +01:00
#define Soc_MAX_NEW_PUBS_TO_GET_AND_SHOW 10000 // Unlimited
2016-01-17 15:10:54 +01:00
#define Soc_MAX_REC_PUBS_TO_GET_AND_SHOW 20 // Recent publishings to show (first time)
#define Soc_MAX_OLD_PUBS_TO_GET_AND_SHOW 20 // IMPORTANT: If you change this number,
// set also this constant to the new value
// in JavaScript function readOldTimelineData
2016-01-10 16:57:02 +01:00
2016-01-14 01:39:02 +01:00
typedef enum
{
Soc_TIMELINE_USR, // Show the timeline of a user
Soc_TIMELINE_GBL, // Show the timeline of the users follwed by me
} Soc_TimelineUsrOrGbl_t;
2016-01-10 16:57:02 +01:00
typedef enum
{
2016-01-13 00:45:16 +01:00
Soc_GET_ONLY_NEW_PUBS, // New publishings are retrieved via AJAX
// automatically from time to time
2016-01-17 01:50:43 +01:00
Soc_GET_RECENT_TIMELINE, // Recent timeline is shown when user clicks on action menu,...
// or after editing timeline
2016-01-13 00:45:16 +01:00
Soc_GET_ONLY_OLD_PUBS, // Old publishings are retrieved via AJAX
// when user clicks on link at bottom of timeline
2016-01-10 16:57:02 +01:00
} Soc_WhatToGetFromTimeline_t;
2015-12-28 19:23:42 +01:00
2016-04-08 16:37:59 +02:00
// Social images will be saved with:
// - maximum width of Soc_IMAGE_SAVED_MAX_HEIGHT
// - maximum height of Soc_IMAGE_SAVED_MAX_HEIGHT
// - maintaining the original aspect ratio (aspect ratio recommended: 3:2)
#define Soc_IMAGE_SAVED_MAX_WIDTH 768
#define Soc_IMAGE_SAVED_MAX_HEIGHT 512
2016-04-12 22:28:15 +02:00
#define Soc_IMAGE_SAVED_QUALITY 50 // 1 to 100
// in social posts, the quality is low in order to speed up the loading of images
2016-04-08 16:37:59 +02:00
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
/****************************** Internal types *******************************/
/*****************************************************************************/
2015-12-31 14:25:28 +01:00
struct SocialNote
2015-12-30 12:40:13 +01:00
{
2015-12-31 14:47:22 +01:00
long NotCod;
2015-12-31 18:40:45 +01:00
Soc_NoteType_t NoteType;
2016-01-08 14:08:33 +01:00
long UsrCod;
2016-01-03 17:34:06 +01:00
long HieCod; // Hierarchy code (institution/centre/degree/course)
long Cod; // Code of file, forum post, notice,...
bool Unavailable; // File, forum post, notice,... unavailable (removed)
2015-12-30 12:40:13 +01:00
time_t DateTimeUTC;
2016-01-04 16:10:27 +01:00
unsigned NumShared; // Number of times (users) this note has been shared
2016-01-19 00:50:35 +01:00
unsigned NumFavs; // Number of times (users) this note has been favourited
2015-12-30 12:40:13 +01:00
};
2016-01-08 01:53:37 +01:00
struct SocialComment
{
2016-01-25 12:32:13 +01:00
long PubCod;
2016-01-08 14:08:33 +01:00
long UsrCod;
2016-01-08 01:53:37 +01:00
long NotCod; // Note code
time_t DateTimeUTC;
2016-01-19 12:54:27 +01:00
unsigned NumFavs; // Number of times (users) this comment has been favourited
2017-01-17 03:10:43 +01:00
char Content[Cns_MAX_BYTES_LONG_TEXT + 1];
2016-04-08 23:30:43 +02:00
struct Image Image;
2016-01-08 01:53:37 +01:00
};
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/************************* Internal global variables *************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2016-01-15 14:46:44 +01:00
static void Soc_ShowTimelineGblHighlightingNot (long NotCod);
static void Soc_ShowTimelineUsrHighlightingNot (long NotCod);
2016-01-14 01:39:02 +01:00
static void Soc_GetAndShowOldTimeline (Soc_TimelineUsrOrGbl_t TimelineUsrOrGbl);
static void Soc_BuildQueryToGetTimeline (Soc_TimelineUsrOrGbl_t TimelineUsrOrGbl,
Soc_WhatToGetFromTimeline_t WhatToGetFromTimeline,
char *Query);
2016-01-10 16:57:02 +01:00
static long Soc_GetPubCodFromSession (const char *FieldName);
2016-01-10 03:10:40 +01:00
static void Soc_UpdateLastPubCodIntoSession (void);
2016-01-10 16:57:02 +01:00
static void Soc_UpdateFirstPubCodIntoSession (long FirstPubCod);
2016-01-13 00:24:26 +01:00
static void Soc_DropTemporaryTablesUsedToQueryTimeline (void);
2016-01-10 03:10:40 +01:00
2016-01-15 14:46:44 +01:00
static void Soc_ShowTimeline (const char *Query,const char *Title,
long NotCodToHighlight);
2016-11-07 10:40:27 +01:00
static void Soc_PutIconsTimeline (void);
2017-02-24 03:38:18 +01:00
2017-02-24 10:34:21 +01:00
static void Soc_FormStart (Act_Action_t ActionGbl,Act_Action_t ActionUsr);
2017-02-24 03:38:18 +01:00
static void Soc_PutFormWhichUsrs (void);
2017-02-24 10:34:21 +01:00
static void Soc_PutParamWhichUsrs (void);
2017-02-24 03:38:18 +01:00
static void Soc_GetParamsWhichUsrs (void);
2017-02-24 11:01:28 +01:00
static void Soc_ShowWarningYouDontFollowAnyUser (void);
2016-01-15 14:46:44 +01:00
static void Soc_InsertNewPubsInTimeline (const char *Query);
2016-01-10 16:57:02 +01:00
static void Soc_ShowOldPubsInTimeline (const char *Query);
2016-01-10 03:10:40 +01:00
2015-12-31 18:40:45 +01:00
static void Soc_GetDataOfSocialPublishingFromRow (MYSQL_ROW row,struct SocialPublishing *SocPub);
2016-01-10 14:27:35 +01:00
static void Soc_PutLinkToViewNewPublishings (void);
static void Soc_PutLinkToViewOldPublishings (void);
2016-01-11 19:28:43 +01:00
static void Soc_WriteSocialNote (const struct SocialNote *SocNot,
2016-01-19 21:07:52 +01:00
Soc_TopMessage_t TopMessage,long UsrCod,
2016-01-15 14:46:44 +01:00
bool Highlight,
bool ShowNoteAlone);
2016-01-19 21:07:52 +01:00
static void Soc_WriteTopMessage (Soc_TopMessage_t TopMessage,long UsrCod);
2017-03-05 18:17:24 +01:00
static void Soc_WriteAuthorNote (const struct UsrData *UsrDat);
2016-01-08 01:53:37 +01:00
static void Soc_WriteDateTime (time_t TimeUTC);
2016-01-02 01:56:48 +01:00
static void Soc_GetAndWriteSocialPost (long PstCod);
2016-01-04 10:27:32 +01:00
static void Soc_PutFormGoToAction (const struct SocialNote *SocNot);
2015-12-31 18:40:45 +01:00
static void Soc_GetNoteSummary (const struct SocialNote *SocNot,
2017-03-08 14:12:33 +01:00
char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1]);
2016-01-01 20:19:43 +01:00
static void Soc_PublishSocialNoteInTimeline (struct SocialPublishing *SocPub);
2015-12-28 19:23:42 +01:00
2016-01-15 10:48:49 +01:00
static void Soc_PutFormToWriteNewPost (void);
2016-04-08 02:16:23 +02:00
static void Soc_PutTextarea (const char *Placeholder,
const char *ClassTextArea,const char *ClassImgTit);
2016-01-15 10:48:49 +01:00
2016-01-15 14:46:44 +01:00
static long Soc_ReceiveSocialPost (void);
2015-12-30 12:40:13 +01:00
2017-03-07 01:56:41 +01:00
static void Soc_PutIconToToggleCommentSocialNote (const char UniqueId[Act_MAX_BYTES_ID]);
2016-01-19 02:08:44 +01:00
static void Soc_PutIconCommentDisabled (void);
2016-01-11 19:28:43 +01:00
static void Soc_PutHiddenFormToWriteNewCommentToSocialNote (long NotCod,
2017-03-07 01:56:41 +01:00
const char IdNewComment[Act_MAX_BYTES_ID]);
2016-01-08 02:55:18 +01:00
static unsigned long Soc_GetNumCommentsInSocialNote (long NotCod);
2016-01-20 02:35:27 +01:00
static void Soc_WriteCommentsInSocialNote (const struct SocialNote *SocNot);
2016-01-08 02:55:18 +01:00
static void Soc_WriteSocialComment (struct SocialComment *SocCom,
2016-01-19 21:07:52 +01:00
Soc_TopMessage_t TopMessage,long UsrCod,
2016-01-11 00:53:21 +01:00
bool ShowCommentAlone);
2016-01-13 17:47:22 +01:00
static void Soc_WriteAuthorComment (struct UsrData *UsrDat);
2016-01-19 12:54:27 +01:00
2016-01-25 12:32:13 +01:00
static void Soc_PutFormToRemoveComment (long PubCod);
static void Soc_PutFormToFavSocialComment (long PubCod);
2016-01-19 00:50:35 +01:00
2016-01-05 21:30:10 +01:00
static void Soc_PutDisabledIconShare (unsigned NumShared);
2016-01-19 00:50:35 +01:00
static void Soc_PutDisabledIconFav (unsigned NumFavs);
2016-01-05 21:30:10 +01:00
static void Soc_PutFormToShareSocialNote (long NotCod);
2016-01-19 00:50:35 +01:00
static void Soc_PutFormToFavSocialNote (long NotCod);
static void Soc_PutFormToUnshareSocialNote (long NotCod);
static void Soc_PutFormToUnfavSocialNote (long NotCod);
2016-01-25 12:32:13 +01:00
static void Soc_PutFormToUnfavSocialComment (long PubCod);
2016-01-19 00:50:35 +01:00
2016-01-11 19:28:43 +01:00
static void Soc_PutFormToRemoveSocialPublishing (long NotCod);
2016-01-08 01:53:37 +01:00
2016-01-25 14:40:57 +01:00
static void Soc_PutHiddenParamNotCod (long NotCod);
2016-01-05 21:30:10 +01:00
static long Soc_GetParamNotCod (void);
2016-01-25 12:32:13 +01:00
static long Soc_GetParamPubCod (void);
2016-01-01 20:19:43 +01:00
2016-01-16 02:01:14 +01:00
static long Soc_ReceiveComment (void);
2016-01-11 01:46:33 +01:00
2016-01-15 15:01:11 +01:00
static long Soc_ShareSocialNote (void);
2016-01-19 00:50:35 +01:00
static long Soc_FavSocialNote (void);
2016-01-19 12:54:27 +01:00
static long Soc_FavSocialComment (void);
2016-01-25 18:57:37 +01:00
static void Soc_CreateNotifToAuthor (long AuthorCod,long PubCod,
Ntf_NotifyEvent_t NotifyEvent);
2016-01-19 00:50:35 +01:00
2016-01-16 01:37:37 +01:00
static long Soc_UnshareSocialNote (void);
2016-01-19 00:50:35 +01:00
static long Soc_UnfavSocialNote (void);
2016-01-19 12:54:27 +01:00
static long Soc_UnfavSocialComment (void);
2016-01-02 01:56:48 +01:00
2016-01-08 01:53:37 +01:00
static void Soc_RequestRemovalSocialNote (void);
2017-04-28 12:52:58 +02:00
static void Soc_PutParamsRemoveSocialNote (void);
2016-01-07 00:42:35 +01:00
static void Soc_RemoveSocialNote (void);
2016-04-08 20:21:33 +02:00
static void Soc_RemoveImgFileFromSocialPost (long PstCod);
2016-01-08 01:53:37 +01:00
static void Soc_RemoveASocialNoteFromDB (struct SocialNote *SocNot);
2016-01-25 20:28:33 +01:00
static long Soc_GetNotCodOfSocialPublishing (long PubCod);
2016-01-24 14:26:35 +01:00
static long Soc_GetPubCodOfOriginalSocialNote (long NotCod);
2016-01-08 01:53:37 +01:00
static void Soc_RequestRemovalSocialComment (void);
2017-04-28 12:38:05 +02:00
static void Soc_PutParamsRemoveSocialCommment (void);
2016-01-08 01:53:37 +01:00
static void Soc_RemoveSocialComment (void);
2016-04-08 23:30:43 +02:00
static void Soc_RemoveImgFileFromSocialComment (long PubCod);
2016-01-08 01:53:37 +01:00
static void Soc_RemoveASocialCommentFromDB (struct SocialComment *SocCom);
2016-01-01 20:19:43 +01:00
2016-01-24 13:46:57 +01:00
static bool Soc_CheckIfNoteIsSharedByUsr (long NotCod,long UsrCod);
static bool Soc_CheckIfNoteIsFavedByUsr (long NotCod,long UsrCod);
2016-01-25 12:32:13 +01:00
static bool Soc_CheckIfCommIsFavedByUsr (long PubCod,long UsrCod);
2016-01-19 00:50:35 +01:00
2016-01-19 21:07:52 +01:00
static unsigned Soc_UpdateNumTimesANoteHasBeenShared (struct SocialNote *SocNot);
static unsigned Soc_GetNumTimesANoteHasBeenFav (struct SocialNote *SocNot);
static unsigned Soc_GetNumTimesACommHasBeenFav (struct SocialComment *SocCom);
2016-01-19 00:50:35 +01:00
2016-01-04 14:49:10 +01:00
static void Soc_ShowUsrsWhoHaveSharedSocialNote (const struct SocialNote *SocNot);
2016-01-19 01:12:20 +01:00
static void Soc_ShowUsrsWhoHaveMarkedSocialNoteAsFav (const struct SocialNote *SocNot);
2016-01-19 21:07:52 +01:00
static void Soc_ShowUsrsWhoHaveMarkedSocialCommAsFav (const struct SocialComment *SocCom);
2016-01-19 01:31:35 +01:00
static void Soc_ShowSharersOrFavers (unsigned NumUsrs,const char *Query);
2016-01-08 01:53:37 +01:00
2016-01-19 21:07:52 +01:00
static void Soc_GetDataOfSocialNotByCod (struct SocialNote *SocNot);
static void Soc_GetDataOfSocialComByCod (struct SocialComment *SocCom);
2016-01-08 01:53:37 +01:00
static void Soc_GetDataOfSocialPublishingFromRow (MYSQL_ROW row,struct SocialPublishing *SocPub);
2015-12-31 18:40:45 +01:00
static void Soc_GetDataOfSocialNoteFromRow (MYSQL_ROW row,struct SocialNote *SocNot);
2016-01-11 20:54:14 +01:00
static Soc_PubType_t Soc_GetPubTypeFromStr (const char *Str);
2016-01-04 11:58:36 +01:00
static Soc_NoteType_t Soc_GetNoteTypeFromStr (const char *Str);
2016-01-08 01:53:37 +01:00
static void Soc_GetDataOfSocialCommentFromRow (MYSQL_ROW row,struct SocialComment *SocCom);
2016-01-05 04:54:00 +01:00
static void Soc_ResetSocialNote (struct SocialNote *SocNot);
2016-01-08 01:53:37 +01:00
static void Soc_ResetSocialComment (struct SocialComment *SocCom);
2015-12-29 23:44:28 +01:00
2016-01-17 01:50:43 +01:00
static void Soc_ClearTimelineThisSession (void);
static void Soc_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
/*****************************************************************************/
2016-01-15 14:46:44 +01:00
/***** Show social activity (timeline) including all the users I follow ******/
2015-12-29 14:24:37 +01:00
/*****************************************************************************/
2017-02-24 03:38:18 +01:00
void Soc_ShowTimelineGbl1 (void)
{
/***** Mark all my notifications about timeline as seen *****/
Soc_MarkMyNotifAsSeen ();
/***** Get which users *****/
Soc_GetParamsWhichUsrs ();
}
void Soc_ShowTimelineGbl2 (void)
2015-12-29 14:24:37 +01:00
{
2016-01-25 14:40:57 +01:00
long PubCod;
struct SocialNote SocNot;
struct UsrData UsrDat;
Ntf_NotifyEvent_t NotifyEvent;
2016-01-25 17:23:14 +01:00
const Soc_TopMessage_t TopMessages[Ntf_NUM_NOTIFY_EVENTS] =
{
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_UNKNOWN
/* Course tab */
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_DOCUMENT_FILE
2016-04-22 09:47:25 +02:00
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_TEACHERS_FILE
2016-01-25 17:23:14 +01:00
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_SHARED_FILE
/* Assessment tab */
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_ASSIGNMENT
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_EXAM_ANNOUNCEMENT
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_MARKS_FILE
/* Users tab */
2017-03-30 11:20:06 +02:00
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_ENROLMENT_STUDENT
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_ENROLMENT_TEACHER
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_ENROLMENT_REQUEST
2016-01-25 17:23:14 +01:00
/* Social tab */
Soc_TOP_MESSAGE_COMMENTED, // Ntf_EVENT_TIMELINE_COMMENT
Soc_TOP_MESSAGE_FAVED, // Ntf_EVENT_TIMELINE_FAV
Soc_TOP_MESSAGE_SHARED, // Ntf_EVENT_TIMELINE_SHARE
Soc_TOP_MESSAGE_MENTIONED, // Ntf_EVENT_TIMELINE_MENTION
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_FOLLOWER
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_FORUM_POST_COURSE
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_FORUM_REPLY
/* Messages tab */
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_NOTICE
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_MESSAGE
/* Statistics tab */
Soc_TOP_MESSAGE_NONE, // Ntf_EVENT_SURVEY
/* Profile tab */
};
2016-01-25 14:40:57 +01:00
/***** Initialize social note code to -1 ==> no highlighted note *****/
SocNot.NotCod = -1L;
/***** Get parameter with the code of a social publishing *****/
// This parameter is optional. It can be provided by a notification.
// If > 0 ==> the social note is shown highlighted above the timeline
PubCod = Soc_GetParamPubCod ();
if (PubCod > 0)
/***** Get code of social note from database *****/
2016-01-25 20:28:33 +01:00
SocNot.NotCod = Soc_GetNotCodOfSocialPublishing (PubCod);
2016-01-25 14:40:57 +01:00
if (SocNot.NotCod > 0)
{
/* Get who did the action (publishing, commenting, faving, sharing, mentioning) */
Usr_GetParamOtherUsrCodEncrypted (&UsrDat);
/* Get what he/she did */
NotifyEvent = Ntf_GetParamNotifyEvent ();
/***** Show the social note highlighted *****/
Soc_GetDataOfSocialNotByCod (&SocNot);
Soc_WriteSocialNote (&SocNot,
2016-01-25 17:23:14 +01:00
TopMessages[NotifyEvent],UsrDat.UsrCod,
2016-01-25 14:40:57 +01:00
true,true);
}
/***** Show timeline with possible highlighted note *****/
Soc_ShowTimelineGblHighlightingNot (SocNot.NotCod);
2016-01-15 14:46:44 +01:00
}
static void Soc_ShowTimelineGblHighlightingNot (long NotCod)
{
2017-02-27 19:52:04 +01:00
extern const char *Txt_Timeline;
2016-01-17 01:50:43 +01:00
char Query[1024];
2015-12-29 14:24:37 +01:00
2016-01-15 14:46:44 +01:00
/***** Build query to get timeline *****/
Soc_BuildQueryToGetTimeline (Soc_TIMELINE_GBL,
2016-01-14 01:39:02 +01:00
Soc_GET_RECENT_TIMELINE,
Query);
2015-12-29 14:24:37 +01:00
/***** Show timeline *****/
2017-02-27 19:52:04 +01:00
Soc_ShowTimeline (Query,Txt_Timeline,NotCod);
2016-01-14 01:39:02 +01:00
/***** Drop temporary tables *****/
Soc_DropTemporaryTablesUsedToQueryTimeline ();
2015-12-29 14:24:37 +01:00
}
/*****************************************************************************/
2016-01-15 14:46:44 +01:00
/*********** Show social activity (timeline) of a selected user **************/
2015-12-29 14:24:37 +01:00
/*****************************************************************************/
2016-01-15 14:46:44 +01:00
void Soc_ShowTimelineUsr (void)
2015-12-29 14:24:37 +01:00
{
2016-01-15 14:46:44 +01:00
Soc_ShowTimelineUsrHighlightingNot (-1L);
}
2015-12-29 14:24:37 +01:00
2016-01-15 14:46:44 +01:00
static void Soc_ShowTimelineUsrHighlightingNot (long NotCod)
{
2017-02-27 19:52:04 +01:00
extern const char *Txt_Timeline_OF_A_USER;
2016-01-17 01:50:43 +01:00
char Query[1024];
2016-01-08 10:27:58 +01:00
2016-01-15 14:46:44 +01:00
/***** Build query to show timeline with publishings of a unique user *****/
Soc_BuildQueryToGetTimeline (Soc_TIMELINE_USR,
2016-01-14 01:39:02 +01:00
Soc_GET_RECENT_TIMELINE,
Query);
2016-01-10 03:10:40 +01:00
/***** Show timeline *****/
2017-02-27 19:52:04 +01:00
sprintf (Gbl.Title,Txt_Timeline_OF_A_USER,Gbl.Usrs.Other.UsrDat.FirstName);
2016-01-15 14:46:44 +01:00
Soc_ShowTimeline (Query,Gbl.Title,NotCod);
2016-01-10 03:10:40 +01:00
2016-01-13 00:24:26 +01:00
/***** Drop temporary tables *****/
Soc_DropTemporaryTablesUsedToQueryTimeline ();
2016-01-10 03:10:40 +01:00
}
/*****************************************************************************/
2016-01-14 01:39:02 +01:00
/********** Refresh new publishings in social timeline via AJAX **************/
/*****************************************************************************/
void Soc_RefreshNewTimelineGbl (void)
2016-01-10 03:10:40 +01:00
{
2016-01-17 01:50:43 +01:00
char Query[1024];
2016-01-10 03:10:40 +01:00
2017-02-06 01:23:33 +01:00
if (Gbl.Session.IsOpen) // If session has been closed, do not write anything
{
/***** Send, before the HTML, the refresh time *****/
fprintf (Gbl.F.Out,"%lu|",
Cfg_TIME_TO_REFRESH_SOCIAL_TIMELINE);
2016-01-10 03:10:40 +01:00
2017-02-24 03:38:18 +01:00
/***** Get which users *****/
Soc_GetParamsWhichUsrs ();
2017-02-06 01:23:33 +01:00
/***** Build query to get timeline *****/
Soc_BuildQueryToGetTimeline (Soc_TIMELINE_GBL,
Soc_GET_ONLY_NEW_PUBS,
Query);
2016-01-10 03:10:40 +01:00
2017-02-06 01:23:33 +01:00
/***** Show new timeline *****/
Soc_InsertNewPubsInTimeline (Query);
/***** Drop temporary tables *****/
Soc_DropTemporaryTablesUsedToQueryTimeline ();
}
2016-01-14 01:39:02 +01:00
/***** All the output is made, so don't write anymore *****/
Gbl.Layout.DivsEndWritten = Gbl.Layout.HTMLEndWritten = true;
}
/*****************************************************************************/
2017-02-24 03:38:18 +01:00
/************ View old publishings in social timeline via AJAX ***************/
2016-01-14 01:39:02 +01:00
/*****************************************************************************/
2016-01-15 14:46:44 +01:00
void Soc_RefreshOldTimelineGbl (void)
2016-01-14 01:39:02 +01:00
{
2017-02-24 03:38:18 +01:00
/***** Get which users *****/
Soc_GetParamsWhichUsrs ();
/***** Show old publishings *****/
2016-01-15 14:46:44 +01:00
Soc_GetAndShowOldTimeline (Soc_TIMELINE_GBL);
2016-01-14 01:39:02 +01:00
}
void Soc_RefreshOldTimelineUsr (void)
{
2017-02-17 10:17:39 +01:00
/***** Get user whom profile is displayed *****/
if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) // Existing user
/***** If user exists, show old publishings *****/
2016-01-14 01:39:02 +01:00
Soc_GetAndShowOldTimeline (Soc_TIMELINE_USR);
}
2016-01-10 14:27:35 +01:00
/*****************************************************************************/
2016-01-14 01:39:02 +01:00
/**************** Get and show old publishings in timeline *******************/
2016-01-10 14:27:35 +01:00
/*****************************************************************************/
2016-01-14 01:39:02 +01:00
static void Soc_GetAndShowOldTimeline (Soc_TimelineUsrOrGbl_t TimelineUsrOrGbl)
2016-01-10 14:27:35 +01:00
{
2016-01-17 01:50:43 +01:00
char Query[1024];
2016-01-10 14:27:35 +01:00
/***** Build query to get timeline *****/
2016-01-14 01:39:02 +01:00
Soc_BuildQueryToGetTimeline (TimelineUsrOrGbl,
Soc_GET_ONLY_OLD_PUBS,
Query);
2016-01-10 14:27:35 +01:00
2016-01-10 16:57:02 +01:00
/***** Show old timeline *****/
Soc_ShowOldPubsInTimeline (Query);
2016-01-10 14:27:35 +01:00
2016-01-13 00:24:26 +01:00
/***** Drop temporary tables *****/
Soc_DropTemporaryTablesUsedToQueryTimeline ();
2016-01-14 01:39:02 +01:00
/***** All the output is made, so don't write anymore *****/
Gbl.Layout.DivsEndWritten = Gbl.Layout.HTMLEndWritten = true;
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
2016-01-25 23:00:22 +01:00
void Soc_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 ************************/
/*****************************************************************************/
2016-01-17 01:50:43 +01:00
// Query must have space for at least 1024 chars
2016-01-10 03:10:40 +01:00
2017-03-08 01:21:21 +01:00
#define Soc_MAX_BYTES_SUBQUERY_ALREADY_EXISTS (256 - 1)
2017-01-15 22:58:26 +01:00
2016-01-14 01:39:02 +01:00
static void Soc_BuildQueryToGetTimeline (Soc_TimelineUsrOrGbl_t TimelineUsrOrGbl,
Soc_WhatToGetFromTimeline_t WhatToGetFromTimeline,
char *Query)
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];
2017-03-08 01:21:21 +01:00
char SubQueryAlreadyExists[Soc_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;
unsigned NumPub;
long PubCod;
long NotCod;
2016-01-17 21:22:01 +01:00
const unsigned MaxPubsToGet[3] =
{
Soc_MAX_NEW_PUBS_TO_GET_AND_SHOW, // Soc_GET_ONLY_NEW_PUBS
Soc_MAX_REC_PUBS_TO_GET_AND_SHOW, // Soc_GET_RECENT_TIMELINE
Soc_MAX_OLD_PUBS_TO_GET_AND_SHOW, // Soc_GET_ONLY_OLD_PUBS
};
2016-01-10 16:57:02 +01:00
2016-01-13 00:45:16 +01:00
/***** Clear social timeline for this session in database *****/
if (WhatToGetFromTimeline == Soc_GET_RECENT_TIMELINE)
2016-01-17 01:50:43 +01:00
Soc_ClearTimelineThisSession ();
2016-01-13 00:45:16 +01:00
2016-01-13 00:24:26 +01:00
/***** Drop temporary tables *****/
Soc_DropTemporaryTablesUsedToQueryTimeline ();
2016-01-17 01:50:43 +01:00
/***** Create temporary table with publishing codes *****/
sprintf (Query,"CREATE TEMPORARY TABLE pub_codes "
2016-01-17 19:56:56 +01:00
"(PubCod BIGINT NOT NULL,UNIQUE INDEX(PubCod)) ENGINE=MEMORY");
2016-01-17 01:50:43 +01:00
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not create temporary table");
/***** Create temporary table with notes got in this execution *****/
sprintf (Query,"CREATE TEMPORARY TABLE not_codes "
2016-01-17 19:56:56 +01:00
"(NotCod BIGINT NOT NULL,INDEX(NotCod)) ENGINE=MEMORY");
2016-01-17 01:50:43 +01:00
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not create temporary table");
/***** Create temporary table with notes already present in timeline for this session *****/
sprintf (Query,"CREATE TEMPORARY TABLE current_timeline "
2016-01-17 19:56:56 +01:00
"(NotCod BIGINT NOT NULL,INDEX(NotCod)) ENGINE=MEMORY"
2016-01-17 01:50:43 +01:00
" SELECT NotCod FROM social_timelines WHERE SessionId='%s'",
Gbl.Session.Id);
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not create temporary table");
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)
{
case Soc_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;
2017-02-24 03:38:18 +01:00
case Soc_TIMELINE_GBL: // Show the global timeline
switch (Gbl.Social.WhichUsrs)
{
case Soc_FOLLOWED: // Show the timeline of the users I follow
sprintf (Query,"CREATE TEMPORARY TABLE publishers "
"(UsrCod INT NOT NULL,UNIQUE INDEX(UsrCod)) ENGINE=MEMORY"
2017-03-24 01:09:27 +01:00
" SELECT %ld AS UsrCod"
2017-02-24 03:38:18 +01:00
" UNION"
" SELECT FollowedCod AS UsrCod"
2017-03-24 01:09:27 +01:00
" FROM usr_follow WHERE FollowerCod=%ld",
2017-02-24 03:38:18 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not create temporary table");
sprintf (SubQueryPublishers,"social_pubs.PublisherCod=publishers.UsrCod AND ");
break;
case Soc_ALL_USRS: // Show the timeline of all users
SubQueryPublishers[0] = '\0';
break;
}
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)
{
case Soc_TIMELINE_USR: // Show the timeline of a user
2016-01-17 02:25:59 +01:00
switch (WhatToGetFromTimeline)
{
case Soc_GET_ONLY_NEW_PUBS:
2016-01-17 02:49:39 +01:00
case Soc_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"
2017-01-15 22:58:26 +01:00
" (SELECT NotCod FROM not_codes)",
2017-03-08 01:21:21 +01:00
Soc_MAX_BYTES_SUBQUERY_ALREADY_EXISTS);
2016-01-17 02:25:59 +01:00
break;
case Soc_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"
2017-01-15 22:58:26 +01:00
" (SELECT NotCod FROM current_timeline)",
2017-03-08 01:21:21 +01:00
Soc_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-17 01:50:43 +01:00
case Soc_TIMELINE_GBL: // Show the timeline of the users I follow
2016-01-17 02:25:59 +01:00
switch (WhatToGetFromTimeline)
{
case Soc_GET_ONLY_NEW_PUBS:
2016-01-17 02:49:39 +01:00
case Soc_GET_RECENT_TIMELINE:
2017-01-15 22:58:26 +01:00
Str_Copy (SubQueryAlreadyExists,
2017-02-24 03:38:18 +01:00
" social_pubs.NotCod NOT IN"
2017-01-15 22:58:26 +01:00
" (SELECT NotCod FROM not_codes)",
2017-03-08 01:21:21 +01:00
Soc_MAX_BYTES_SUBQUERY_ALREADY_EXISTS);
2016-01-17 02:25:59 +01:00
break;
case Soc_GET_ONLY_OLD_PUBS:
2017-01-15 22:58:26 +01:00
Str_Copy (SubQueryAlreadyExists,
2017-02-24 03:38:18 +01:00
" social_pubs.NotCod NOT IN"
2017-01-15 22:58:26 +01:00
" (SELECT NotCod FROM current_timeline)",
2017-03-08 01:21:21 +01:00
Soc_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
2016-01-17 20:06:25 +01:00
/***** Get the publishings in timeline *****/
2016-01-17 21:22:01 +01:00
/* Initialize range of pubs:
social_pubs
_____
|_____|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)
{
case Soc_GET_ONLY_NEW_PUBS: // Get the publishings (without limit) newer than LastPubCod
/* This query is made via AJAX automatically from time to time */
RangePubsToGet.Bottom = Soc_GetPubCodFromSession ("LastPubCod");
break;
case Soc_GET_RECENT_TIMELINE: // Get some limited recent publishings
/* This is the first query to get initial timeline shown
==> no notes yet in current timeline table */
break;
case Soc_GET_ONLY_OLD_PUBS: // Get some limited publishings older than FirstPubCod
/* This query is made via AJAX
when I click in link to get old publishings */
RangePubsToGet.Top = Soc_GetPubCodFromSession ("FirstPubCod");
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
the publishings and notes in a loop. In each iteration,
2016-01-17 21:22:01 +01:00
we get the more recent publishing (original, shared or commment)
2016-01-27 13:20:08 +01:00
of every set of publishings corresponding to the same note,
2016-01-17 21:22:01 +01:00
checking that the note is not already retrieved.
After getting a publishing, its note code is stored
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,
i.e more recent publishing (original, shared or commment),
of every set of publishings corresponding to the same note:
2016-01-17 01:50:43 +01:00
"SELECT MAX(PubCod) AS NewestPubCod FROM social_pubs ...
" 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.
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++)
{
2016-01-17 21:22:01 +01:00
/* Create subqueries with range of publishings to get from social_pubs */
if (RangePubsToGet.Bottom > 0)
2017-02-24 03:38:18 +01:00
switch (TimelineUsrOrGbl)
{
case Soc_TIMELINE_USR: // Show the timeline of a user
2017-03-24 01:09:27 +01:00
sprintf (SubQueryRangeBottom,"PubCod>%ld AND ",RangePubsToGet.Bottom);
2017-02-24 03:38:18 +01:00
break;
case Soc_TIMELINE_GBL: // Show the global timeline
switch (Gbl.Social.WhichUsrs)
{
case Soc_FOLLOWED: // Show the timeline of the users I follow
2017-03-24 01:09:27 +01:00
sprintf (SubQueryRangeBottom,"social_pubs.PubCod>%ld AND ",RangePubsToGet.Bottom);
2017-02-24 03:38:18 +01:00
break;
case Soc_ALL_USRS: // Show the timeline of all users
2017-03-24 01:09:27 +01:00
sprintf (SubQueryRangeBottom,"PubCod>%ld AND ",RangePubsToGet.Bottom);
2017-02-24 03:38:18 +01:00
break;
}
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)
{
case Soc_TIMELINE_USR: // Show the timeline of a user
2017-03-24 01:09:27 +01:00
sprintf (SubQueryRangeTop,"PubCod<%ld AND ",RangePubsToGet.Top);
2017-02-24 03:38:18 +01:00
break;
case Soc_TIMELINE_GBL: // Show the global timeline
switch (Gbl.Social.WhichUsrs)
{
case Soc_FOLLOWED: // Show the timeline of the users I follow
2017-03-24 01:09:27 +01:00
sprintf (SubQueryRangeTop,"social_pubs.PubCod<%ld AND ",RangePubsToGet.Top);
2017-02-24 03:38:18 +01:00
break;
case Soc_ALL_USRS: // Show the timeline of all users
2017-03-24 01:09:27 +01:00
sprintf (SubQueryRangeTop,"PubCod<%ld AND ",RangePubsToGet.Top);
2017-02-24 03:38:18 +01:00
break;
}
break;
}
2016-01-17 21:22:01 +01:00
else
SubQueryRangeTop[0] = '\0';
/* Select the most recent publishing from social_pubs */
2016-01-17 01:50:43 +01:00
switch (TimelineUsrOrGbl)
{
case Soc_TIMELINE_USR: // Show the timeline of a user
sprintf (Query,"SELECT PubCod,NotCod FROM social_pubs"
2016-01-17 21:22:01 +01:00
" WHERE %s%s%s%s"
2016-01-17 01:50:43 +01:00
" ORDER BY PubCod DESC LIMIT 1",
2016-01-17 21:22:01 +01:00
SubQueryRangeBottom,SubQueryRangeTop,
2016-01-17 01:50:43 +01:00
SubQueryPublishers,
SubQueryAlreadyExists);
break;
2017-02-24 03:38:18 +01:00
case Soc_TIMELINE_GBL: // Show the global timeline
switch (Gbl.Social.WhichUsrs)
{
case Soc_FOLLOWED: // Show the timeline of the users I follow
sprintf (Query,"SELECT PubCod,NotCod FROM social_pubs,publishers"
" WHERE %s%s%s%s"
" ORDER BY social_pubs.PubCod DESC LIMIT 1",
SubQueryRangeBottom,SubQueryRangeTop,
SubQueryPublishers,
SubQueryAlreadyExists);
break;
case Soc_ALL_USRS: // Show the timeline of all users
sprintf (Query,"SELECT PubCod,NotCod FROM social_pubs"
" WHERE %s%s%s"
" ORDER BY PubCod DESC LIMIT 1",
SubQueryRangeBottom,SubQueryRangeTop,
SubQueryAlreadyExists);
break;
}
2016-01-17 01:50:43 +01:00
break;
}
if (DB_QuerySELECT (Query,&mysql_res,"can not get publishing") == 1)
{
2016-01-25 14:40:57 +01:00
/* Get code of social publishing */
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
PubCod = -1L;
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
if (PubCod > 0)
{
2017-03-24 01:09:27 +01:00
sprintf (Query,"INSERT INTO pub_codes SET PubCod=%ld",PubCod);
2016-01-17 01:50:43 +01:00
DB_QueryINSERT (Query,"can not store publishing code");
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
/* Get social note code (row[1]) */
NotCod = Str_ConvertStrCodToLongCod (row[1]);
2017-03-24 01:09:27 +01:00
sprintf (Query,"INSERT INTO not_codes SET NotCod=%ld",NotCod);
2016-01-17 01:50:43 +01:00
DB_QueryINSERT (Query,"can not store note code");
2017-03-24 01:09:27 +01:00
sprintf (Query,"INSERT INTO current_timeline SET NotCod=%ld",NotCod);
2016-01-17 01:50:43 +01:00
DB_QueryINSERT (Query,"can not store note code");
}
2016-01-17 21:22:01 +01:00
else // Nothing got ==> abort loop
2016-01-17 01:50:43 +01:00
break; // Last publishing
2016-01-10 03:10:40 +01:00
}
2016-01-08 10:27:58 +01:00
2016-01-10 03:10:40 +01:00
/***** Update last publishing code into session for next refresh *****/
2016-01-10 16:57:02 +01:00
// Do this inmediately after getting the publishings codes...
// ...in order to not lose publishings
2016-01-10 03:10:40 +01:00
Soc_UpdateLastPubCodIntoSession ();
2016-01-17 01:50:43 +01:00
/***** Add notes just retrieved to current timeline for this session *****/
Soc_AddNotesJustRetrievedToTimelineThisSession ();
2016-01-08 10:27:58 +01:00
/***** Build query to show timeline including the users I am following *****/
2016-01-11 20:54:14 +01:00
sprintf (Query,"SELECT PubCod,NotCod,PublisherCod,PubType,UNIX_TIMESTAMP(TimePublish)"
2016-01-12 19:18:56 +01:00
" FROM social_pubs WHERE PubCod IN "
2016-01-17 01:50:43 +01:00
"(SELECT PubCod FROM pub_codes)"
2016-01-08 10:27:58 +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
/*****************************************************************************/
2016-01-10 16:57:02 +01:00
/********* Get last/first social publishing 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
2016-01-10 16:57:02 +01:00
static long Soc_GetPubCodFromSession (const char *FieldName)
2016-01-10 03:10:40 +01:00
{
2017-03-13 14:22:36 +01:00
char Query[128 + Ses_BYTES_SESSION_ID];
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
2016-01-10 16:57:02 +01:00
/***** Get last publishing code from database *****/
sprintf (Query,"SELECT %s FROM sessions WHERE SessionId='%s'",
FieldName,Gbl.Session.Id);
if (DB_QuerySELECT (Query,&mysql_res,"can not get publishing code from session") != 1)
Lay_ShowErrorAndExit ("Error when getting publishing code from session.");
2016-01-10 03:10:40 +01:00
/***** Get last publishing code *****/
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
/*****************************************************************************/
2016-01-10 03:10:40 +01:00
/*********************** Update last publishing code *************************/
2016-01-09 21:55:06 +01:00
/*****************************************************************************/
2016-01-10 03:10:40 +01:00
static void Soc_UpdateLastPubCodIntoSession (void)
2016-01-09 21:55:06 +01:00
{
2017-03-13 14:22:36 +01:00
char Query[256 + Ses_BYTES_SESSION_ID];
2016-01-10 03:10:40 +01:00
/***** Update last publishing code *****/
sprintf (Query,"UPDATE sessions"
2016-05-03 14:54:12 +02:00
" SET LastPubCod=(SELECT IFNULL(MAX(PubCod),0) FROM social_pubs)"
2016-01-10 03:10:40 +01:00
" WHERE SessionId='%s'",
Gbl.Session.Id);
2016-01-10 16:57:02 +01:00
DB_QueryUPDATE (Query,"can not update last publishing code into session");
}
/*****************************************************************************/
/*********************** Update first publishing code ************************/
/*****************************************************************************/
static void Soc_UpdateFirstPubCodIntoSession (long FirstPubCod)
{
2017-03-13 14:22:36 +01:00
char Query[128 + Ses_BYTES_SESSION_ID];
2016-01-10 16:57:02 +01:00
/***** Update last publishing code *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"UPDATE sessions SET FirstPubCod=%ld WHERE SessionId='%s'",
2016-01-10 16:57:02 +01:00
FirstPubCod,Gbl.Session.Id);
DB_QueryUPDATE (Query,"can not update first publishing code into session");
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
/*****************************************************************************/
2016-01-13 00:24:26 +01:00
static void Soc_DropTemporaryTablesUsedToQueryTimeline (void)
2016-01-09 15:00:14 +01:00
{
2016-01-10 03:10:40 +01:00
char Query[128];
2016-01-13 00:24:26 +01:00
sprintf (Query,"DROP TEMPORARY TABLE IF EXISTS"
2016-01-17 01:50:43 +01:00
" pub_codes,not_codes,publishers,current_timeline");
2016-01-10 03:10:40 +01:00
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not remove temporary tables");
2016-01-09 15:00:14 +01:00
}
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
/*********************** Show social activity (timeline) *********************/
/*****************************************************************************/
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
*/
2016-01-15 14:46:44 +01:00
static void Soc_ShowTimeline (const char *Query,const char *Title,
long NotCodToHighlight)
2015-12-28 19:23:42 +01:00
{
2017-02-28 01:24:25 +01:00
extern const char *Hlp_SOCIAL_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;
struct SocialPublishing SocPub;
struct SocialNote SocNot;
2017-02-24 03:38:18 +01:00
bool GlobalTimeline = (Gbl.Usrs.Other.UsrDat.UsrCod <= 0);
2015-12-28 19:23:42 +01:00
2016-01-12 19:43:17 +01:00
/***** Get publishings from database *****/
2016-01-11 00:27:04 +01:00
NumPubsGot = DB_QuerySELECT (Query,&mysql_res,"can not get timeline");
2015-12-28 19:23:42 +01:00
2016-01-12 14:17:47 +01:00
/***** Start frame *****/
2016-11-13 21:13:28 +01:00
Lay_StartRoundFrame (Soc_WIDTH_TIMELINE,Title,
2017-02-28 01:24:25 +01:00
Soc_PutIconsTimeline,Hlp_SOCIAL_Timeline);
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)
Soc_PutFormWhichUsrs ();
2016-01-12 14:17:47 +01:00
/***** Form to write a new post *****/
2017-02-24 03:38:18 +01:00
if (GlobalTimeline ||
2016-01-12 14:17:47 +01:00
Gbl.Usrs.Other.UsrDat.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // It's me
2016-01-15 10:48:49 +01:00
Soc_PutFormToWriteNewPost ();
2016-01-08 15:08:30 +01:00
2016-01-14 14:24:20 +01:00
/***** New publishings refreshed dynamically via AJAX *****/
2017-02-24 03:38:18 +01:00
if (GlobalTimeline)
2016-01-14 14:24:20 +01:00
{
/* Link to view new publishings via AJAX */
Soc_PutLinkToViewNewPublishings ();
2016-01-09 15:00:14 +01:00
2016-01-14 15:12:42 +01:00
/* Hidden list where insert just received (not visible) publishings via AJAX */
fprintf (Gbl.F.Out,"<ul id=\"just_now_timeline_list\"></ul>");
/* Hidden list where insert new (not visible) publishings via AJAX */
2016-01-14 14:24:20 +01:00
fprintf (Gbl.F.Out,"<ul id=\"new_timeline_list\"></ul>");
}
2016-01-10 14:27:35 +01:00
2016-01-12 14:17:47 +01:00
/***** List recent publishings in timeline *****/
fprintf (Gbl.F.Out,"<ul id=\"timeline_list\" class=\"LIST_LEFT\">");
2016-01-17 01:50:43 +01:00
2016-01-12 14:17:47 +01:00
for (NumPub = 0;
2016-01-17 01:50:43 +01:00
NumPub < NumPubsGot;
2016-01-12 14:17:47 +01:00
NumPub++)
{
/* Get data of social publishing */
row = mysql_fetch_row (mysql_res);
Soc_GetDataOfSocialPublishingFromRow (row,&SocPub);
2015-12-28 19:23:42 +01:00
2016-01-12 14:17:47 +01:00
/* Get data of social note */
SocNot.NotCod = SocPub.NotCod;
2016-01-19 21:07:52 +01:00
Soc_GetDataOfSocialNotByCod (&SocNot);
2016-01-05 04:54:00 +01:00
2016-01-12 14:17:47 +01:00
/* Write social note */
2016-01-19 00:50:35 +01:00
Soc_WriteSocialNote (&SocNot,
SocPub.TopMessage,SocPub.PublisherCod,
2016-01-17 01:50:43 +01:00
SocNot.NotCod == NotCodToHighlight,
false);
2016-01-12 14:17:47 +01:00
}
fprintf (Gbl.F.Out,"</ul>");
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);
2016-01-12 14:17:47 +01:00
/***** Store first publishing code into session *****/
Soc_UpdateFirstPubCodIntoSession (SocPub.PubCod);
2016-01-10 16:57:02 +01:00
2016-01-17 01:50:43 +01:00
if (NumPubsGot == Soc_MAX_REC_PUBS_TO_GET_AND_SHOW)
2016-01-12 14:17:47 +01:00
{
/***** Link to view old publishings via AJAX *****/
Soc_PutLinkToViewOldPublishings ();
2016-01-10 14:27:35 +01:00
2016-01-12 14:17:47 +01:00
/***** Hidden list where insert old publishings via AJAX *****/
fprintf (Gbl.F.Out,"<ul id=\"old_timeline_list\"></ul>");
}
2016-01-10 14:27:35 +01:00
2016-01-12 14:17:47 +01:00
/***** End frame *****/
Lay_EndRoundFrame ();
2016-01-10 03:10:40 +01:00
}
2016-11-07 10:40:27 +01:00
/*****************************************************************************/
/********************* Put contextual icons in timeline **********************/
/*****************************************************************************/
static void Soc_PutIconsTimeline (void)
{
/***** Put icon to show a figure *****/
Gbl.Stat.FigureType = Sta_SOCIAL_ACTIVITY;
Sta_PutIconToShowFigure ();
}
2017-02-24 10:34:21 +01:00
/*****************************************************************************/
/***************** Start a form in global or user timeline *******************/
/*****************************************************************************/
static void Soc_FormStart (Act_Action_t ActionGbl,Act_Action_t ActionUsr)
{
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
Act_FormStartAnchor (ActionUsr,"timeline");
Usr_PutParamOtherUsrCodEncrypted ();
}
else
{
Act_FormStart (ActionGbl);
Soc_PutParamWhichUsrs ();
}
}
2017-02-24 03:38:18 +01:00
/*****************************************************************************/
/******** Put form to select users whom public activity is displayed *********/
/*****************************************************************************/
static void Soc_PutFormWhichUsrs (void)
{
extern const char *Txt_TIMELINE_WHICH_USERS[Soc_NUM_WHICH_USRS];
Soc_WhichUsrs_t WhichUsrs;
/***** Form to select which users I want to see in timeline:
- only the users I follow
- all users *****/
Act_FormStart (ActSeeSocTmlGbl);
fprintf (Gbl.F.Out,"<div class=\"SEL_BELOW_TITLE\">"
"<ul>");
for (WhichUsrs = (Soc_WhichUsrs_t) 0;
WhichUsrs < Soc_NUM_WHICH_USRS;
WhichUsrs++)
{
fprintf (Gbl.F.Out,"<li>"
"<label>"
"<input type=\"radio\" name=\"WhichUsrs\""
" value=\"%u\"",
(unsigned) WhichUsrs);
if (WhichUsrs == Gbl.Social.WhichUsrs)
fprintf (Gbl.F.Out," checked=\"checked\"");
fprintf (Gbl.F.Out," onclick=\"document.getElementById('%s').submit();\" />"
"%s"
"</label>"
"</li>",
Gbl.Form.Id,Txt_TIMELINE_WHICH_USERS[WhichUsrs]);
}
fprintf (Gbl.F.Out,"</ul>"
"</div>");
Act_FormEnd ();
2017-02-24 11:01:28 +01:00
/***** Show warning if I do not follow anyone *****/
if (Gbl.Social.WhichUsrs == Soc_FOLLOWED)
Soc_ShowWarningYouDontFollowAnyUser ();
2017-02-24 03:38:18 +01:00
}
2017-02-24 10:34:21 +01:00
/*****************************************************************************/
/***** Put hidden parameter with which users to view in global timeline ******/
/*****************************************************************************/
static void Soc_PutParamWhichUsrs (void)
{
Par_PutHiddenParamUnsigned ("WhichUsrs",Gbl.Social.WhichUsrs);
}
2017-02-24 03:38:18 +01:00
/*****************************************************************************/
/********* Get parameter with which users to view in global timeline *********/
/*****************************************************************************/
static void Soc_GetParamsWhichUsrs (void)
{
/***** Get which users I want to see *****/
Gbl.Social.WhichUsrs = (Soc_WhichUsrs_t)
Par_GetParToUnsignedLong ("WhichUsrs",
0,
Soc_NUM_WHICH_USRS - 1,
(unsigned long) Soc_DEFAULT_WHICH_USRS);
}
2017-02-24 11:01:28 +01:00
/*****************************************************************************/
/********* Get parameter with which users to view in global timeline *********/
/*****************************************************************************/
static void Soc_ShowWarningYouDontFollowAnyUser (void)
{
extern const char *Txt_You_dont_follow_any_user;
/***** Check if I follow someone *****/
if (!Fol_GetNumFollowing (Gbl.Usrs.Me.UsrDat.UsrCod))
{
/***** Show warning if I do not follow anyone *****/
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_You_dont_follow_any_user);
2017-02-24 11:01:28 +01:00
/***** Put link to show users to follow *****/
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
Fol_PutLinkWhoToFollow ();
fprintf (Gbl.F.Out,"</div>");
}
}
2016-01-10 03:10:40 +01:00
/*****************************************************************************/
2016-01-10 16:57:02 +01:00
/********** Show new social activity (new publishings in timeline) ***********/
2016-01-10 03:10:40 +01:00
/*****************************************************************************/
2016-01-10 16:57:02 +01:00
// The publishings are inserted as list elements of a hidden list
2016-01-09 21:55:06 +01:00
2016-01-15 14:46:44 +01:00
static void Soc_InsertNewPubsInTimeline (const 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;
struct SocialPublishing SocPub;
struct SocialNote SocNot;
2016-01-10 16:57:02 +01:00
/***** Get new publishings timeline from database *****/
2016-01-11 00:27:04 +01:00
NumPubsGot = DB_QuerySELECT (Query,&mysql_res,"can not get timeline");
2016-01-10 03:10:40 +01:00
2016-01-11 00:27:04 +01:00
/***** List new publishings 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++)
{
/* Get data of social publishing */
row = mysql_fetch_row (mysql_res);
Soc_GetDataOfSocialPublishingFromRow (row,&SocPub);
/* Get data of social note */
SocNot.NotCod = SocPub.NotCod;
2016-01-19 21:07:52 +01:00
Soc_GetDataOfSocialNotByCod (&SocNot);
2016-01-10 03:10:40 +01:00
/* Write social note */
2016-01-19 00:50:35 +01:00
Soc_WriteSocialNote (&SocNot,
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
}
/*****************************************************************************/
/********** Show old social activity (old publishings in timeline) ***********/
/*****************************************************************************/
// The publishings are inserted as list elements of a hidden list
static void Soc_ShowOldPubsInTimeline (const char *Query)
{
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;
struct SocialPublishing SocPub;
struct SocialNote SocNot;
/***** Get old publishings timeline from database *****/
2016-01-11 00:27:04 +01:00
NumPubsGot = DB_QuerySELECT (Query,&mysql_res,"can not get timeline");
2016-01-10 16:57:02 +01:00
2016-01-17 01:50:43 +01:00
/***** List old publishings in timeline *****/
for (NumPub = 0;
NumPub < NumPubsGot;
NumPub++)
2016-01-10 16:57:02 +01:00
{
2016-01-17 01:50:43 +01:00
/* Get data of social publishing */
row = mysql_fetch_row (mysql_res);
Soc_GetDataOfSocialPublishingFromRow (row,&SocPub);
2016-01-12 20:58:19 +01:00
2016-01-17 01:50:43 +01:00
/* Get data of social note */
SocNot.NotCod = SocPub.NotCod;
2016-01-19 21:07:52 +01:00
Soc_GetDataOfSocialNotByCod (&SocNot);
2016-01-10 16:57:02 +01:00
2016-01-17 01:50:43 +01:00
/* Write social note */
2016-01-19 00:50:35 +01:00
Soc_WriteSocialNote (&SocNot,
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
/***** Store first publishing code into session *****/
Soc_UpdateFirstPubCodIntoSession (SocPub.PubCod);
2015-12-28 19:23:42 +01:00
}
2016-01-09 19:06:01 +01:00
/*****************************************************************************/
2016-01-09 20:11:44 +01:00
/***************** Put link to view new publishings in timeline **************/
2016-01-09 19:06:01 +01:00
/*****************************************************************************/
2016-01-10 14:27:35 +01:00
static void Soc_PutLinkToViewNewPublishings (void)
2016-01-09 19:06:01 +01:00
{
2016-01-09 20:11:44 +01:00
extern const char *The_ClassFormBold[The_NUM_THEMES];
extern const char *Txt_See_new_activity;
2016-01-09 19:06:01 +01:00
2016-01-10 14:27:35 +01:00
/***** Link to view (show hidden) new publishings *****/
2016-01-09 20:11:44 +01:00
// div is hidden. When new posts arrive to the client via AJAX, div is shown
2016-01-09 19:06:01 +01:00
fprintf (Gbl.F.Out,"<div id=\"view_new_posts_container\""
2016-01-09 20:11:44 +01:00
" class=\"SOCIAL_PUB VERY_LIGHT_BLUE\""
2016-01-09 19:06:01 +01:00
" style=\"display:none;\">"
"<a href=\"\" class=\"%s\""
2016-01-10 14:27:35 +01:00
" onclick=\"moveNewTimelineToTimeline();return false;\" />"
2016-01-09 20:11:44 +01:00
"%s (<span id=\"view_new_posts_count\">0</span>)"
"</a>"
2016-01-09 19:06:01 +01:00
"</div>",
2016-01-09 20:11:44 +01:00
The_ClassFormBold[Gbl.Prefs.Theme],
Txt_See_new_activity);
2016-01-09 19:06:01 +01:00
}
2016-01-10 14:27:35 +01:00
/*****************************************************************************/
/***************** Put link to view old publishings in timeline **************/
/*****************************************************************************/
static void Soc_PutLinkToViewOldPublishings (void)
{
extern const char *The_ClassFormBold[The_NUM_THEMES];
extern const char *Txt_See_more;
2016-01-27 13:20:08 +01:00
/***** Animated link to view old publishings *****/
2016-01-10 14:27:35 +01:00
fprintf (Gbl.F.Out,"<div id=\"view_old_posts_container\""
" class=\"SOCIAL_PUB VERY_LIGHT_BLUE\">"
2016-01-27 13:20:08 +01:00
"<a 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;\">"
"<img id=\"get_old_timeline\""
" src=\"%s/recycle16x16.gif\" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-01-27 13:20:08 +01:00
"<img id=\"getting_old_timeline\""
" src=\"%s/working16x16.gif\" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" style=\"display:none;\" />" // Animated icon hidden
2016-01-27 13:20:08 +01:00
"&nbsp;%s"
2016-01-10 14:27:35 +01:00
"</a>"
"</div>",
The_ClassFormBold[Gbl.Prefs.Theme],
2016-01-27 13:20:08 +01:00
Gbl.Prefs.IconsURL,Txt_See_more,Txt_See_more,
Gbl.Prefs.IconsURL,Txt_See_more,Txt_See_more,
2016-01-10 14:27:35 +01:00
Txt_See_more);
}
2015-12-30 16:33:36 +01:00
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
/***************************** Write social note *****************************/
2015-12-30 16:33:36 +01:00
/*****************************************************************************/
2016-01-14 02:43:46 +01:00
// All forms in this function and nested functions must have unique identifiers
2015-12-30 16:33:36 +01:00
2016-01-11 19:28:43 +01:00
static void Soc_WriteSocialNote (const struct SocialNote *SocNot,
2016-01-19 21:07:52 +01:00
Soc_TopMessage_t TopMessage,long UsrCod,
2016-01-16 02:16:12 +01:00
bool Highlight, // Highlight social note
2016-01-15 14:46:44 +01:00
bool ShowNoteAlone) // Social 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;
2016-01-05 04:54:00 +01:00
bool IAmTheAuthor = false;
2016-01-24 13:46:57 +01:00
bool IAmASharerOfThisSocNot = false;
bool IAmAFaverOfThisSocNot = false;
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];
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;
2017-03-07 01:56:41 +01:00
char IdNewComment[Act_MAX_BYTES_ID];
2015-12-30 16:33:36 +01:00
2016-01-11 19:28:43 +01:00
/***** Start frame ****/
2016-01-11 00:53:21 +01:00
if (ShowNoteAlone)
2016-01-05 21:30:10 +01:00
{
2016-11-12 22:00:50 +01:00
Lay_StartRoundFrame (Soc_WIDTH_TIMELINE,NULL,NULL,NULL);
2016-01-05 21:30:10 +01:00
fprintf (Gbl.F.Out,"<ul class=\"LIST_LEFT\">");
}
2015-12-30 16:33:36 +01:00
/***** Start list item *****/
2016-01-02 14:56:38 +01:00
fprintf (Gbl.F.Out,"<li");
2016-01-15 14:46:44 +01:00
if (!ShowNoteAlone || Highlight)
{
fprintf (Gbl.F.Out," class=\"");
if (!ShowNoteAlone)
fprintf (Gbl.F.Out," SOCIAL_PUB");
if (Highlight)
fprintf (Gbl.F.Out," SOCIAL_NEW_PUB");
fprintf (Gbl.F.Out,"\"");
}
2016-01-02 14:56:38 +01:00
fprintf (Gbl.F.Out,">");
2015-12-30 16:33:36 +01:00
2016-01-11 19:28:43 +01:00
if (SocNot->NotCod <= 0 ||
SocNot->NoteType == Soc_NOTE_UNKNOWN ||
SocNot->UsrCod <= 0)
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_ERROR,"Error in social 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 *****/
2016-01-19 21:07:52 +01:00
Soc_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;
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat);
if (Gbl.Usrs.Me.Logged)
{
IAmTheAuthor = (UsrDat.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod);
2016-01-24 13:46:57 +01:00
if (!IAmTheAuthor)
{
IAmASharerOfThisSocNot = Soc_CheckIfNoteIsSharedByUsr (SocNot->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
IAmAFaverOfThisSocNot = Soc_CheckIfNoteIsFavedByUsr (SocNot->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
2016-01-05 04:54:00 +01:00
}
2015-12-30 16:33:36 +01:00
2016-01-05 04:54:00 +01:00
/***** Left: write author's photo *****/
2016-01-20 15:19:02 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_NOTE_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,
2016-01-20 02:35:27 +01:00
"PHOTO42x56",Pho_ZOOM,true); // Use unique id
2016-01-05 04:54:00 +01:00
fprintf (Gbl.F.Out,"</div>");
2015-12-30 16:33:36 +01:00
2016-01-05 04:54:00 +01:00
/***** Right: author's name, time, summary and buttons *****/
2016-01-20 15:19:02 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_NOTE_RIGHT_CONTAINER\">");
2015-12-30 16:33:36 +01:00
2016-01-05 04:54:00 +01:00
/* Write author's full name and nickname */
2016-01-13 17:47:22 +01:00
Soc_WriteAuthorNote (&UsrDat);
2015-12-30 16:33:36 +01:00
2016-01-05 04:54:00 +01:00
/* Write date and time */
2016-01-08 01:53:37 +01:00
Soc_WriteDateTime (SocNot->DateTimeUTC);
2016-01-02 17:07:58 +01:00
2016-01-05 04:54:00 +01:00
/* Write content of the note */
if (SocNot->NoteType == Soc_NOTE_SOCIAL_POST)
/* Write post content */
Soc_GetAndWriteSocialPost (SocNot->Cod);
else
{
/* Get location in hierarchy */
if (!SocNot->Unavailable)
switch (SocNot->NoteType)
{
case Soc_NOTE_INS_DOC_PUB_FILE:
case Soc_NOTE_INS_SHA_PUB_FILE:
/* Get institution data */
Ins.InsCod = SocNot->HieCod;
Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA);
break;
case Soc_NOTE_CTR_DOC_PUB_FILE:
case Soc_NOTE_CTR_SHA_PUB_FILE:
/* Get centre data */
Ctr.CtrCod = SocNot->HieCod;
Ctr_GetDataOfCentreByCod (&Ctr);
break;
case Soc_NOTE_DEG_DOC_PUB_FILE:
case Soc_NOTE_DEG_SHA_PUB_FILE:
/* Get degree data */
Deg.DegCod = SocNot->HieCod;
Deg_GetDataOfDegreeByCod (&Deg);
break;
case Soc_NOTE_CRS_DOC_PUB_FILE:
case Soc_NOTE_CRS_SHA_PUB_FILE:
case Soc_NOTE_EXAM_ANNOUNCEMENT:
case Soc_NOTE_NOTICE:
/* Get course data */
Crs.CrsCod = SocNot->HieCod;
Crs_GetDataOfCourseByCod (&Crs);
break;
case Soc_NOTE_FORUM_POST:
/* Get forum type of the post */
2017-04-18 01:25:44 +02:00
For_GetForumTypeAndLocationOfAPost (SocNot->Cod,&Gbl.Forum.ForumSelected);
For_SetForumName (&Gbl.Forum.ForumSelected,
2017-04-17 11:57:55 +02:00
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 */
Soc_PutFormGoToAction (SocNot);
/* Write location in hierarchy */
if (!SocNot->Unavailable)
switch (SocNot->NoteType)
{
case Soc_NOTE_INS_DOC_PUB_FILE:
case Soc_NOTE_INS_SHA_PUB_FILE:
/* Write location (institution) in hierarchy */
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
2016-10-28 10:03:37 +02:00
Txt_Institution,Ins.ShrtName);
2016-01-05 04:54:00 +01:00
break;
case Soc_NOTE_CTR_DOC_PUB_FILE:
case Soc_NOTE_CTR_SHA_PUB_FILE:
/* Write location (centre) in hierarchy */
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
2016-10-28 10:03:37 +02:00
Txt_Centre,Ctr.ShrtName);
2016-01-05 04:54:00 +01:00
break;
case Soc_NOTE_DEG_DOC_PUB_FILE:
case Soc_NOTE_DEG_SHA_PUB_FILE:
/* Write location (degree) in hierarchy */
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
2016-10-28 10:03:37 +02:00
Txt_Degree,Deg.ShrtName);
2016-01-05 04:54:00 +01:00
break;
case Soc_NOTE_CRS_DOC_PUB_FILE:
case Soc_NOTE_CRS_SHA_PUB_FILE:
case Soc_NOTE_EXAM_ANNOUNCEMENT:
case Soc_NOTE_NOTICE:
/* Write location (course) in hierarchy */
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
2016-10-28 10:03:37 +02:00
Txt_Course,Crs.ShrtName);
2016-01-05 04:54:00 +01:00
break;
case Soc_NOTE_FORUM_POST:
/* Write forum name */
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
Txt_Forum,ForumName);
break;
default:
break;
}
2015-12-30 16:33:36 +01:00
2016-01-05 04:54:00 +01:00
/* Write note summary */
2017-03-06 13:01:16 +01:00
Soc_GetNoteSummary (SocNot,SummaryStr);
2016-01-05 04:54:00 +01:00
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s</div>",SummaryStr);
}
2016-01-20 02:35:27 +01:00
/* End of right part */
fprintf (Gbl.F.Out,"</div>");
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_BOTTOM_LEFT\">");
2016-01-11 19:28:43 +01:00
/* Create unique id for new comment */
2016-04-14 14:21:38 +02:00
Act_SetUniqueId (IdNewComment);
2016-01-11 19:28:43 +01:00
2016-01-08 02:55:18 +01:00
/* Get number of comments in this social note */
NumComments = Soc_GetNumCommentsInSocialNote (SocNot->NotCod);
/* Put icon to add a comment */
2016-01-20 02:35:27 +01:00
// if (NumComments || SocNot->Unavailable) // Unavailable social notes can not be commented
if (SocNot->Unavailable) // Unavailable social notes can not be commented
2016-01-19 02:08:44 +01:00
Soc_PutIconCommentDisabled ();
else
2016-01-20 19:23:11 +01:00
Soc_PutIconToToggleCommentSocialNote (IdNewComment);
2016-01-07 00:42:35 +01:00
2016-01-20 02:35:27 +01:00
fprintf (Gbl.F.Out,"</div>");
2015-12-30 16:33:36 +01:00
2016-01-20 02:35:27 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_BOTTOM_RIGHT\">"
2016-11-14 10:05:41 +01:00
"<div class=\"SOCIAL_ICOS_FAV_SHA_REM\">");
2016-01-04 14:49:10 +01:00
2016-01-19 00:50:35 +01:00
/* Put icon to mark this social note as favourite */
if (IAmTheAuthor) // I am the author
Soc_PutDisabledIconFav (SocNot->NumFavs);
2016-01-24 13:46:57 +01:00
else if (IAmAFaverOfThisSocNot) // I have favourited this social note
2016-01-19 00:50:35 +01:00
/* Put icon to unfav this publishing */
Soc_PutFormToUnfavSocialNote (SocNot->NotCod);
else // I am not the author and I am not a sharer
{
if (SocNot->Unavailable) // Unavailable social notes can not be favourited
Soc_PutDisabledIconFav (SocNot->NumFavs);
else
/* Put icon to share this publishing */
Soc_PutFormToFavSocialNote (SocNot->NotCod);
}
2016-01-19 01:12:20 +01:00
/* Show who have marked this social note as favourite */
Soc_ShowUsrsWhoHaveMarkedSocialNoteAsFav (SocNot);
2016-01-20 02:35:27 +01:00
/* Put icons to share/unshare */
if (IAmTheAuthor) // I am the author
Soc_PutDisabledIconShare (SocNot->NumShared);
2016-01-24 13:46:57 +01:00
else if (IAmASharerOfThisSocNot) // I am a sharer of this social note,
// but not the author ==> I have shared this social note
2016-01-20 02:35:27 +01:00
/* Put icon to unshare this publishing */
Soc_PutFormToUnshareSocialNote (SocNot->NotCod);
else // I am not the author and I am not a sharer
{
if (SocNot->Unavailable) // Unavailable social notes can not be shared
Soc_PutDisabledIconShare (SocNot->NumShared);
else
/* Put icon to share this publishing */
Soc_PutFormToShareSocialNote (SocNot->NotCod);
}
/* Show who have shared this social note */
Soc_ShowUsrsWhoHaveSharedSocialNote (SocNot);
2016-01-19 00:50:35 +01:00
/* Put icon to remove this social note */
2016-01-17 02:49:39 +01:00
if (IAmTheAuthor)
2016-01-11 19:28:43 +01:00
Soc_PutFormToRemoveSocialPublishing (SocNot->NotCod);
2016-01-04 11:58:36 +01:00
2016-01-20 02:35:27 +01:00
/* End of icon bar */
fprintf (Gbl.F.Out,"</div>");
2016-01-11 00:53:21 +01:00
/* Show comments */
2016-01-11 19:28:43 +01:00
if (NumComments)
2016-01-20 02:35:27 +01:00
Soc_WriteCommentsInSocialNote (SocNot);
/* End of bottom right */
fprintf (Gbl.F.Out,"</div>");
2016-01-11 19:28:43 +01:00
/* Put hidden form to write a new comment */
Soc_PutHiddenFormToWriteNewCommentToSocialNote (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 *****/
fprintf (Gbl.F.Out,"</li>");
2016-01-05 21:30:10 +01:00
2016-01-11 19:28:43 +01:00
/***** End frame ****/
2016-01-11 00:53:21 +01:00
if (ShowNoteAlone)
2016-01-05 21:30:10 +01:00
{
fprintf (Gbl.F.Out,"</ul>");
Lay_EndRoundFrame ();
}
2015-12-30 16:33:36 +01:00
}
2016-01-13 12:59:23 +01:00
/*****************************************************************************/
/*************** Write sharer/commenter if distinct to author ****************/
/*****************************************************************************/
2016-01-14 02:43:46 +01:00
// All forms in this function and nested functions must have unique identifiers
2016-01-13 12:59:23 +01:00
2016-01-19 21:07:52 +01:00
static void Soc_WriteTopMessage (Soc_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;
2016-01-25 16:25:10 +01:00
extern const char *Txt_SOCIAL_NOTE_TOP_MESSAGES[Soc_NUM_TOP_MESSAGES];
2016-01-13 12:59:23 +01:00
struct UsrData UsrDat;
2017-02-17 01:59:58 +01:00
bool ItsMe = (Gbl.Usrs.Me.Logged &&
UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod);
2016-01-13 12:59:23 +01:00
2016-01-19 00:50:35 +01:00
if (TopMessage != Soc_TOP_MESSAGE_NONE)
{
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;
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // Really we only need EncryptedUsrCod and FullName
2016-01-13 12:59:23 +01:00
{
2016-01-19 00:50:35 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_TOP_CONTAINER SOCIAL_TOP_PUBLISHER\">");
/***** Show user's name inside form to go to user's public profile *****/
2017-02-17 06:32:57 +01:00
Act_FormStartUnique (ActSeeOthPubPrf);
Usr_PutParamUsrCodEncrypted (UsrDat.EncryptedUsrCod);
Act_LinkFormSubmitUnique (ItsMe ? Txt_My_public_profile :
Txt_Another_user_s_profile,
"SOCIAL_TOP_PUBLISHER");
2016-01-19 00:50:35 +01:00
fprintf (Gbl.F.Out,"%s</a>",UsrDat.FullName);
Act_FormEnd ();
2016-01-13 12:59:23 +01:00
2016-01-19 00:50:35 +01:00
/***** Show action made *****/
2016-01-25 17:23:14 +01:00
fprintf (Gbl.F.Out," %s:</div>",
Txt_SOCIAL_NOTE_TOP_MESSAGES[TopMessage]);
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
/*****************************************************************************/
2016-01-27 13:20:08 +01:00
/************ Write name and nickname of author of a social note *************/
2016-01-13 14:54:18 +01:00
/*****************************************************************************/
2016-01-14 02:43:46 +01:00
// All forms in this function and nested functions must have unique identifiers
2016-01-13 14:54:18 +01:00
2017-03-05 18:17:24 +01:00
static void Soc_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;
bool ItsMe = (Gbl.Usrs.Me.Logged &&
UsrDat->UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod);
2016-01-13 14:54:18 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_RIGHT_AUTHOR\">");
/***** Show user's name inside form to go to user's public profile *****/
2017-02-17 06:32:57 +01:00
Act_FormStartUnique (ActSeeOthPubPrf);
Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
Act_LinkFormSubmitUnique (ItsMe ? Txt_My_public_profile :
Txt_Another_user_s_profile,
"DAT_N_BOLD");
2016-01-13 14:54:18 +01:00
fprintf (Gbl.F.Out,"%s</a>",UsrDat->FullName);
Act_FormEnd ();
/***** Show user's nickname inside form to go to user's public profile *****/
2017-02-17 06:32:57 +01:00
Act_FormStartUnique (ActSeeOthPubPrf);
Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
Act_LinkFormSubmitUnique (ItsMe ? Txt_My_public_profile :
Txt_Another_user_s_profile,
"DAT_LIGHT");
2016-01-13 14:54:18 +01:00
fprintf (Gbl.F.Out," @%s</a>",UsrDat->Nickname);
Act_FormEnd ();
fprintf (Gbl.F.Out,"</div>");
}
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
2015-12-31 14:47:22 +01:00
/**************** Write the date of creation of a social note ****************/
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
// TimeUTC holds UTC date and time in UNIX format (seconds since 1970)
2016-01-08 01:53:37 +01:00
static void Soc_WriteDateTime (time_t TimeUTC)
2015-12-28 19:23:42 +01:00
{
2015-12-29 11:35:01 +01:00
extern const char *Txt_Today;
2017-03-07 01:56:41 +01:00
char IdDateTime[Act_MAX_BYTES_ID];
2015-12-28 19:23:42 +01:00
2016-01-11 19:28:43 +01:00
/***** Create unique Id *****/
2016-04-14 14:21:38 +02:00
Act_SetUniqueId (IdDateTime);
2016-01-10 23:00:15 +01:00
/***** Container where the date-time is written *****/
2016-01-20 09:33:45 +01:00
fprintf (Gbl.F.Out,"<div id=\"%s\" class=\"SOCIAL_RIGHT_TIME DAT_LIGHT\">"
"</div>",
2016-01-11 19:28:43 +01:00
IdDateTime);
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
2015-12-28 19:23:42 +01:00
fprintf (Gbl.F.Out,"<script type=\"text/javascript\">"
2017-05-04 17:06:26 +02:00
"writeLocalDateHMSFromUTC('%s',%ld,"
2017-05-05 09:41:56 +02:00
"%u,',&nbsp;','%s',true,false,0x6);"
2015-12-28 19:23:42 +01:00
"</script>",
2017-05-04 17:06:26 +02:00
IdDateTime,(long) TimeUTC,
(unsigned) Gbl.Prefs.DateFormat,Txt_Today);
2015-12-28 19:23:42 +01:00
}
2016-01-02 01:56:48 +01:00
/*****************************************************************************/
/***************** Get from database and write public post *******************/
/*****************************************************************************/
static void Soc_GetAndWriteSocialPost (long PstCod)
{
2016-04-08 16:37:59 +02:00
char Query[256];
2016-01-02 01:56:48 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
2017-01-17 03:10:43 +01:00
char Content[Cns_MAX_BYTES_LONG_TEXT + 1];
2016-04-08 16:37:59 +02:00
struct Image Image;
/***** Initialize image *****/
2016-04-08 23:30:43 +02:00
Img_ImageConstructor (&Image);
2016-01-02 01:56:48 +01:00
/***** Get social post from database *****/
2016-04-15 02:33:16 +02:00
sprintf (Query,"SELECT Content,ImageName,ImageTitle,ImageURL"
2017-03-24 01:09:27 +01:00
" FROM social_posts WHERE PstCod=%ld",
2016-01-02 01:56:48 +01:00
PstCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get the content of a social post");
/***** 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]) *****/
2017-01-17 03:10:43 +01:00
Str_Copy (Content,row[0],
Cns_MAX_BYTES_LONG_TEXT);
2016-04-08 16:37:59 +02:00
2016-04-15 02:33:16 +02:00
/****** Get image name (row[1]), title (row[2]) and URL (row[3]) *****/
Img_GetImageNameTitleAndURLFromRow (row[1],row[2],row[3],&Image);
2016-01-02 01:56:48 +01:00
}
else
Content[0] = '\0';
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Write content *****/
2016-04-15 14:30:28 +02:00
if (Content[0])
{
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_TXT\">");
Msg_WriteMsgContent (Content,Cns_MAX_BYTES_LONG_TEXT,true,false);
fprintf (Gbl.F.Out,"</div>");
}
2016-04-08 16:37:59 +02:00
/***** Show image *****/
2016-04-15 14:30:28 +02:00
Img_ShowImage (&Image,"SOCIAL_POST_IMG_CONTAINER","SOCIAL_POST_IMG");
2016-04-08 16:37:59 +02:00
2016-04-08 23:30:43 +02:00
/***** Free image *****/
Img_ImageDestructor (&Image);
2016-01-02 01:56:48 +01:00
}
2015-12-29 13:18:25 +01:00
/*****************************************************************************/
2015-12-31 14:25:28 +01:00
/********* Put form to go to an action depending on the social note **********/
2015-12-29 13:18:25 +01:00
/*****************************************************************************/
2016-01-14 02:43:46 +01:00
// All forms in this function and nested functions must have unique identifiers
2015-12-29 13:18:25 +01:00
2016-01-04 10:27:32 +01:00
static void Soc_PutFormGoToAction (const struct SocialNote *SocNot)
2015-12-29 13:18:25 +01:00
{
extern const Act_Action_t For_ActionsSeeFor[For_NUM_TYPES_FORUM];
2016-01-08 14:08:33 +01:00
extern const char *The_ClassFormBold[The_NUM_THEMES];
2016-01-11 20:54:14 +01:00
extern const char *Txt_SOCIAL_NOTE[Soc_NUM_NOTE_TYPES];
2016-01-03 01:54:19 +01:00
extern const char *Txt_not_available;
2016-01-08 14:08:33 +01:00
char Class[64];
2016-01-25 18:57:37 +01:00
const Act_Action_t Soc_DefaultActions[Soc_NUM_NOTE_TYPES] =
{
ActUnk, // Soc_NOTE_UNKNOWN
/* Institution tab */
ActReqDatSeeDocIns, // Soc_NOTE_INS_DOC_PUB_FILE
ActReqDatShaIns, // Soc_NOTE_INS_SHA_PUB_FILE
/* Centre tab */
ActReqDatSeeDocCtr, // Soc_NOTE_CTR_DOC_PUB_FILE
ActReqDatShaCtr, // Soc_NOTE_CTR_SHA_PUB_FILE
/* Degree tab */
ActReqDatSeeDocDeg, // Soc_NOTE_DEG_DOC_PUB_FILE
ActReqDatShaDeg, // Soc_NOTE_DEG_SHA_PUB_FILE
/* Course tab */
ActReqDatSeeDocCrs, // Soc_NOTE_CRS_DOC_PUB_FILE
ActReqDatShaCrs, // Soc_NOTE_CRS_SHA_PUB_FILE
/* Assessment tab */
2016-06-03 10:37:00 +02:00
ActSeeOneExaAnn, // Soc_NOTE_EXAM_ANNOUNCEMENT
2016-01-25 18:57:37 +01:00
/* Users tab */
/* Social tab */
ActUnk, // Soc_NOTE_SOCIAL_POST (action not used)
ActSeeFor, // Soc_NOTE_FORUM_POST
/* Messages tab */
2016-06-01 19:34:44 +02:00
ActSeeOneNot, // Soc_NOTE_NOTICE
2016-01-25 18:57:37 +01:00
/* Statistics tab */
/* Profile tab */
};
const char *Soc_Icons[Soc_NUM_NOTE_TYPES] =
{
NULL, // Soc_NOTE_UNKNOWN
/* Institution tab */
"file64x64.gif", // Soc_NOTE_INS_DOC_PUB_FILE
"file64x64.gif", // Soc_NOTE_INS_SHA_PUB_FILE
/* Centre tab */
"file64x64.gif", // Soc_NOTE_CTR_DOC_PUB_FILE
"file64x64.gif", // Soc_NOTE_CTR_SHA_PUB_FILE
/* Degree tab */
"file64x64.gif", // Soc_NOTE_DEG_DOC_PUB_FILE
"file64x64.gif", // Soc_NOTE_DEG_SHA_PUB_FILE
/* Course tab */
"file64x64.gif", // Soc_NOTE_CRS_DOC_PUB_FILE
"file64x64.gif", // Soc_NOTE_CRS_SHA_PUB_FILE
/* Assessment tab */
2016-02-04 01:13:49 +01:00
"announce64x64.gif", // Soc_NOTE_EXAM_ANNOUNCEMENT
2016-01-25 18:57:37 +01:00
/* Users tab */
/* Social tab */
NULL, // Soc_NOTE_SOCIAL_POST (icon not used)
"forum64x64.gif", // Soc_NOTE_FORUM_POST
/* Messages tab */
2016-11-21 01:20:19 +01:00
"notice64x64.png", // Soc_NOTE_NOTICE
2016-01-25 18:57:37 +01:00
/* Statistics tab */
/* Profile tab */
};
2015-12-29 13:18:25 +01:00
2016-01-27 13:20:08 +01:00
if (SocNot->Unavailable || // File/notice... pointed by this social 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 *****/
2016-04-08 23:30:43 +02:00
fprintf (Gbl.F.Out,"<div class=\"DAT_LIGHT\">%s",
2016-01-04 02:08:16 +01:00
Txt_SOCIAL_NOTE[SocNot->NoteType]);
2016-01-03 19:30:59 +01:00
if (SocNot->Unavailable)
fprintf (Gbl.F.Out," (%s)",Txt_not_available);
2016-04-08 23:30:43 +02:00
fprintf (Gbl.F.Out,"</div>");
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
{
2016-04-08 23:30:43 +02:00
fprintf (Gbl.F.Out,"<div>");
2016-01-03 19:30:59 +01:00
/***** Parameters depending on the type of note *****/
switch (SocNot->NoteType)
2016-01-03 01:13:57 +01:00
{
2016-01-03 19:30:59 +01:00
case Soc_NOTE_INS_DOC_PUB_FILE:
case Soc_NOTE_INS_SHA_PUB_FILE:
2016-01-14 10:31:09 +01:00
Act_FormStartUnique (Soc_DefaultActions[SocNot->NoteType]);
2016-01-04 10:27:32 +01:00
Brw_PutHiddenParamFilCod (SocNot->Cod);
if (SocNot->HieCod != Gbl.CurrentIns.Ins.InsCod) // Not the current institution
Ins_PutParamInsCod (SocNot->HieCod); // Go to another institution
break;
2016-01-03 19:30:59 +01:00
case Soc_NOTE_CTR_DOC_PUB_FILE:
case Soc_NOTE_CTR_SHA_PUB_FILE:
2016-01-14 10:31:09 +01:00
Act_FormStartUnique (Soc_DefaultActions[SocNot->NoteType]);
2016-01-04 10:27:32 +01:00
Brw_PutHiddenParamFilCod (SocNot->Cod);
if (SocNot->HieCod != Gbl.CurrentCtr.Ctr.CtrCod) // Not the current centre
Ctr_PutParamCtrCod (SocNot->HieCod); // Go to another centre
break;
2016-01-03 19:30:59 +01:00
case Soc_NOTE_DEG_DOC_PUB_FILE:
case Soc_NOTE_DEG_SHA_PUB_FILE:
2016-01-14 10:31:09 +01:00
Act_FormStartUnique (Soc_DefaultActions[SocNot->NoteType]);
2016-01-04 10:27:32 +01:00
Brw_PutHiddenParamFilCod (SocNot->Cod);
if (SocNot->HieCod != Gbl.CurrentDeg.Deg.DegCod) // Not the current degree
Deg_PutParamDegCod (SocNot->HieCod); // Go to another degree
break;
2016-01-03 19:30:59 +01:00
case Soc_NOTE_CRS_DOC_PUB_FILE:
case Soc_NOTE_CRS_SHA_PUB_FILE:
2016-01-14 10:31:09 +01:00
Act_FormStartUnique (Soc_DefaultActions[SocNot->NoteType]);
2016-01-04 10:27:32 +01:00
Brw_PutHiddenParamFilCod (SocNot->Cod);
if (SocNot->HieCod != Gbl.CurrentCrs.Crs.CrsCod) // Not the current course
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
case Soc_NOTE_EXAM_ANNOUNCEMENT:
2016-01-14 10:31:09 +01:00
Act_FormStartUnique (Soc_DefaultActions[SocNot->NoteType]);
2016-06-03 10:37:00 +02:00
Exa_PutHiddenParamExaCod (SocNot->Cod);
2016-01-04 10:27:32 +01:00
if (SocNot->HieCod != Gbl.CurrentCrs.Crs.CrsCod) // Not the current course
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
case Soc_NOTE_SOCIAL_POST: // Not applicable
return;
2016-01-03 19:30:59 +01:00
case Soc_NOTE_FORUM_POST:
2017-04-18 01:25:44 +02:00
Act_FormStartUnique (For_ActionsSeeFor[Gbl.Forum.ForumSelected.Type]);
2017-04-18 16:44:44 +02:00
For_PutAllHiddenParamsForum (1, // Page of threads = first
1, // Page of posts = first
Gbl.Forum.ForumSet,
2017-04-18 13:17:40 +02:00
Gbl.Forum.ThreadsOrder,
2017-04-18 01:25:44 +02:00
Gbl.Forum.ForumSelected.Location,
Gbl.Forum.ForumSelected.ThrCod,
-1L);
2016-01-04 10:27:32 +01:00
if (SocNot->HieCod != Gbl.CurrentCrs.Crs.CrsCod) // Not the current course
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
case Soc_NOTE_NOTICE:
2016-01-14 10:31:09 +01:00
Act_FormStartUnique (Soc_DefaultActions[SocNot->NoteType]);
2016-01-05 04:54:00 +01:00
Not_PutHiddenParamNotCod (SocNot->Cod);
if (SocNot->HieCod != Gbl.CurrentCrs.Crs.CrsCod) // Not the current course
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
2016-01-04 10:27:32 +01:00
/***** Link and end form *****/
2016-11-14 10:05:41 +01:00
sprintf (Class,"%s ICO_HIGHLIGHT",The_ClassFormBold[Gbl.Prefs.Theme]);
2016-01-14 10:31:09 +01:00
Act_LinkFormSubmitUnique (Txt_SOCIAL_NOTE[SocNot->NoteType],Class);
2016-01-08 14:08:33 +01:00
fprintf (Gbl.F.Out,"<img src=\"%s/%s\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-01-08 14:08:33 +01:00
"&nbsp;%s"
"</a>",
Gbl.Prefs.IconsURL,Soc_Icons[SocNot->NoteType],
Txt_SOCIAL_NOTE[SocNot->NoteType],
Txt_SOCIAL_NOTE[SocNot->NoteType],
Txt_SOCIAL_NOTE[SocNot->NoteType]);
2016-01-04 10:27:32 +01:00
Act_FormEnd ();
2016-04-08 23:30:43 +02:00
fprintf (Gbl.F.Out,"</div>");
2016-01-02 17:07:58 +01:00
}
2015-12-29 13:18:25 +01:00
}
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
2015-12-31 14:47:22 +01:00
/******************* Get social note summary and content *********************/
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
static void Soc_GetNoteSummary (const struct SocialNote *SocNot,
2017-03-08 14:12:33 +01:00
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
{
2015-12-31 14:25:28 +01:00
case Soc_NOTE_UNKNOWN:
2015-12-28 19:23:42 +01:00
break;
2015-12-31 14:25:28 +01:00
case Soc_NOTE_INS_DOC_PUB_FILE:
case Soc_NOTE_INS_SHA_PUB_FILE:
case Soc_NOTE_CTR_DOC_PUB_FILE:
case Soc_NOTE_CTR_SHA_PUB_FILE:
case Soc_NOTE_DEG_DOC_PUB_FILE:
case Soc_NOTE_DEG_SHA_PUB_FILE:
case Soc_NOTE_CRS_DOC_PUB_FILE:
case Soc_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;
2015-12-31 14:25:28 +01:00
case Soc_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;
2015-12-31 14:25:28 +01:00
case Soc_NOTE_SOCIAL_POST:
2015-12-30 16:33:36 +01:00
// Not applicable
2015-12-28 19:23:42 +01:00
break;
2015-12-31 14:25:28 +01:00
case Soc_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;
2015-12-31 14:25:28 +01:00
case Soc_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
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
/************** Store and publish a social 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
2016-01-25 11:43:14 +01:00
void Soc_StoreAndPublishSocialNote (Soc_NoteType_t NoteType,long Cod,struct SocialPublishing *SocPub)
2015-12-28 20:46:48 +01:00
{
2016-01-02 13:21:25 +01:00
char Query[256];
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
{
2016-01-02 13:21:25 +01:00
case Soc_NOTE_INS_DOC_PUB_FILE:
case Soc_NOTE_INS_SHA_PUB_FILE:
HieCod = Gbl.CurrentIns.Ins.InsCod;
break;
case Soc_NOTE_CTR_DOC_PUB_FILE:
case Soc_NOTE_CTR_SHA_PUB_FILE:
HieCod = Gbl.CurrentCtr.Ctr.CtrCod;
break;
case Soc_NOTE_DEG_DOC_PUB_FILE:
case Soc_NOTE_DEG_SHA_PUB_FILE:
HieCod = Gbl.CurrentDeg.Deg.DegCod;
break;
case Soc_NOTE_CRS_DOC_PUB_FILE:
case Soc_NOTE_CRS_SHA_PUB_FILE:
case Soc_NOTE_EXAM_ANNOUNCEMENT:
case Soc_NOTE_NOTICE:
HieCod = Gbl.CurrentCrs.Crs.CrsCod;
break;
default:
HieCod = -1L;
break;
2015-12-28 20:46:48 +01:00
}
2015-12-31 14:25:28 +01:00
/***** Store social note *****/
2016-01-02 13:21:25 +01:00
sprintf (Query,"INSERT INTO social_notes"
2016-06-04 17:17:57 +02:00
" (NoteType,Cod,UsrCod,HieCod,Unavailable,TimeNote)"
2017-03-13 13:17:53 +01:00
" VALUES"
2017-03-24 01:09:27 +01:00
" (%u,%ld,%ld,%ld,'N',NOW())",
2016-06-04 17:17:57 +02:00
(unsigned) NoteType,Cod,Gbl.Usrs.Me.UsrDat.UsrCod,HieCod);
2016-01-25 11:43:14 +01:00
SocPub->NotCod = DB_QueryINSERTandReturnCode (Query,"can not create new social note");
2016-01-01 20:19:43 +01:00
/***** Publish social note in timeline *****/
2016-01-25 11:43:14 +01:00
SocPub->PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod;
SocPub->PubType = Soc_PUB_ORIGINAL_NOTE;
Soc_PublishSocialNoteInTimeline (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
/*****************************************************************************/
/********************** Mark a social note as unavailable ********************/
/*****************************************************************************/
void Soc_MarkSocialNoteAsUnavailableUsingNotCod (long NotCod)
{
char Query[256];
/***** Mark the social note as unavailable *****/
sprintf (Query,"UPDATE social_notes SET Unavailable='Y'"
2017-03-24 01:09:27 +01:00
" WHERE NotCod=%ld",
2016-01-03 19:30:59 +01:00
NotCod);
DB_QueryUPDATE (Query,"can not mark social note as unavailable");
}
void Soc_MarkSocialNoteAsUnavailableUsingNoteTypeAndCod (Soc_NoteType_t NoteType,long Cod)
{
char Query[256];
/***** Mark the social note as unavailable *****/
sprintf (Query,"UPDATE social_notes SET Unavailable='Y'"
2017-03-24 01:09:27 +01:00
" WHERE NoteType=%u AND Cod=%ld",
2016-01-03 19:30:59 +01:00
(unsigned) NoteType,Cod);
DB_QueryUPDATE (Query,"can not mark social note as unavailable");
}
2016-01-04 01:56:28 +01:00
/*****************************************************************************/
2016-01-22 12:05:25 +01:00
/************** Mark social notes of one file as unavailable *****************/
2016-01-04 01:56:28 +01:00
/*****************************************************************************/
2016-01-22 12:05:25 +01:00
void Soc_MarkSocialNoteOneFileAsUnavailable (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;
Soc_NoteType_t NoteType;
switch (FileBrowser)
{
case Brw_ADMI_DOCUM_INS:
case Brw_ADMI_SHARE_INS:
case Brw_ADMI_DOCUM_CTR:
case Brw_ADMI_SHARE_CTR:
case Brw_ADMI_DOCUM_DEG:
case Brw_ADMI_SHARE_DEG:
case Brw_ADMI_DOCUM_CRS:
case Brw_ADMI_SHARE_CRS:
/***** Get file code *****/
FilCod = Brw_GetFilCodByPath (Path,true); // Only if file is public
if (FilCod > 0)
{
/***** Mark possible social note as unavailable *****/
switch (FileBrowser)
{
case Brw_ADMI_DOCUM_INS:
NoteType = Soc_NOTE_INS_DOC_PUB_FILE;
break;
case Brw_ADMI_SHARE_INS:
NoteType = Soc_NOTE_INS_SHA_PUB_FILE;
break;
case Brw_ADMI_DOCUM_CTR:
NoteType = Soc_NOTE_CTR_DOC_PUB_FILE;
break;
case Brw_ADMI_SHARE_CTR:
NoteType = Soc_NOTE_CTR_SHA_PUB_FILE;
break;
case Brw_ADMI_DOCUM_DEG:
NoteType = Soc_NOTE_DEG_DOC_PUB_FILE;
break;
case Brw_ADMI_SHARE_DEG:
NoteType = Soc_NOTE_DEG_SHA_PUB_FILE;
break;
case Brw_ADMI_DOCUM_CRS:
NoteType = Soc_NOTE_CRS_DOC_PUB_FILE;
break;
case Brw_ADMI_SHARE_CRS:
NoteType = Soc_NOTE_CRS_SHA_PUB_FILE;
break;
default:
return;
}
Soc_MarkSocialNoteAsUnavailableUsingNoteTypeAndCod (NoteType,FilCod);
}
break;
default:
break;
}
}
/*****************************************************************************/
/** Mark possible social notes involving children of a folder as unavailable */
/*****************************************************************************/
void Soc_MarkSocialNotesChildrenOfFolderAsUnavailable (const char *Path)
{
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 ();
char Query[512];
Soc_NoteType_t NoteType;
switch (FileBrowser)
{
case Brw_ADMI_DOCUM_INS:
case Brw_ADMI_SHARE_INS:
case Brw_ADMI_DOCUM_CTR:
case Brw_ADMI_SHARE_CTR:
case Brw_ADMI_DOCUM_DEG:
case Brw_ADMI_SHARE_DEG:
case Brw_ADMI_DOCUM_CRS:
case Brw_ADMI_SHARE_CRS:
/***** Mark possible social note as unavailable *****/
switch (FileBrowser)
{
case Brw_ADMI_DOCUM_INS:
NoteType = Soc_NOTE_INS_DOC_PUB_FILE;
break;
case Brw_ADMI_SHARE_INS:
NoteType = Soc_NOTE_INS_SHA_PUB_FILE;
break;
case Brw_ADMI_DOCUM_CTR:
NoteType = Soc_NOTE_CTR_DOC_PUB_FILE;
break;
case Brw_ADMI_SHARE_CTR:
NoteType = Soc_NOTE_CTR_SHA_PUB_FILE;
break;
case Brw_ADMI_DOCUM_DEG:
NoteType = Soc_NOTE_DEG_DOC_PUB_FILE;
break;
case Brw_ADMI_SHARE_DEG:
NoteType = Soc_NOTE_DEG_SHA_PUB_FILE;
break;
case Brw_ADMI_DOCUM_CRS:
NoteType = Soc_NOTE_CRS_DOC_PUB_FILE;
break;
case Brw_ADMI_SHARE_CRS:
NoteType = Soc_NOTE_CRS_SHA_PUB_FILE;
break;
default:
return;
}
sprintf (Query,"UPDATE social_notes SET Unavailable='Y'"
2017-03-24 01:09:27 +01:00
" WHERE NoteType=%u AND Cod IN"
2016-01-04 01:56:28 +01:00
" (SELECT FilCod FROM files"
2017-03-24 01:09:27 +01:00
" WHERE FileBrowser=%u AND Cod=%ld"
2016-01-04 01:56:28 +01:00
" AND Path LIKE '%s/%%' AND Public='Y')", // Only public files
(unsigned) NoteType,
(unsigned) FileBrowser,Cod,
Path);
DB_QueryUPDATE (Query,"can not mark social notes as unavailable");
break;
default:
break;
}
}
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
/***************** Put contextual link to write a new post *******************/
/*****************************************************************************/
2016-01-04 02:54:04 +01:00
// SocPub->PubCod is set
2016-01-01 20:19:43 +01:00
static void Soc_PublishSocialNoteInTimeline (struct SocialPublishing *SocPub)
{
char Query[256];
/***** Publish social note in timeline *****/
2016-01-12 19:18:56 +01:00
sprintf (Query,"INSERT INTO social_pubs"
2016-01-11 20:54:14 +01:00
" (NotCod,PublisherCod,PubType,TimePublish)"
2015-12-31 18:40:45 +01:00
" VALUES"
2017-03-24 01:09:27 +01:00
" (%ld,%ld,%u,NOW())",
2016-01-11 20:54:14 +01:00
SocPub->NotCod,
SocPub->PublisherCod,
(unsigned) SocPub->PubType);
2016-01-04 02:54:04 +01:00
SocPub->PubCod = DB_QueryINSERTandReturnCode (Query,"can not publish social note");
2015-12-28 20:46:48 +01:00
}
2015-12-30 02:08:08 +01:00
2015-12-30 12:40:13 +01:00
/*****************************************************************************/
2016-01-08 15:08:30 +01:00
/****************** Form to write a new social publishing ********************/
2015-12-30 12:40:13 +01:00
/*****************************************************************************/
2016-01-15 10:48:49 +01:00
static void Soc_PutFormToWriteNewPost (void)
2015-12-30 12:40:13 +01:00
{
2016-01-15 11:41:45 +01:00
extern const char *Txt_New_SOCIAL_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 *****/
fprintf (Gbl.F.Out,"<ul class=\"LIST_LEFT\">"
2016-01-09 20:11:44 +01:00
"<li>");
2016-01-08 15:08:30 +01:00
2016-01-20 14:07:15 +01:00
/***** Left: write author's photo (my photo) *****/
2016-01-20 15:19:02 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_NOTE_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,
2016-01-20 02:35:27 +01:00
"PHOTO42x56",Pho_ZOOM,false);
2015-12-30 12:40:13 +01:00
fprintf (Gbl.F.Out,"</div>");
2016-01-02 01:56:48 +01:00
2016-01-08 15:08:30 +01:00
/***** Right: author's name, time, summary and buttons *****/
2016-01-20 15:19:02 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_NOTE_RIGHT_CONTAINER\">");
2016-01-02 01:56:48 +01:00
2016-01-08 15:08:30 +01:00
/* Write author's full name and nickname */
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_RIGHT_AUTHOR\">"
"<span class=\"DAT_N_BOLD\">%s</span>"
"<span class=\"DAT_LIGHT\"> @%s</span>"
"</div>",
2017-03-05 18:17:24 +01:00
Gbl.Usrs.Me.UsrDat.FullName,Gbl.Usrs.Me.UsrDat.Nickname);
2016-01-02 01:56:48 +01:00
2017-02-24 10:34:21 +01:00
/***** Form to write the post *****/
/* Start container */
2016-01-20 02:35:27 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_FORM_NEW_POST\">");
2015-12-30 12:40:13 +01:00
/* Start form to write the post */
2017-02-24 10:34:21 +01:00
Soc_FormStart (ActRcvSocPstGbl,ActRcvSocPstUsr);
2015-12-30 12:40:13 +01:00
2017-02-24 10:34:21 +01:00
/* Textarea and button */
2016-04-08 02:16:23 +02:00
Soc_PutTextarea (Txt_New_SOCIAL_post,
2016-04-15 14:30:28 +02:00
"SOCIAL_TEXTAREA_POST","SOCIAL_POST_IMG_TIT_URL");
2015-12-30 12:40:13 +01:00
2017-02-24 10:34:21 +01:00
/* End form */
2015-12-30 12:40:13 +01:00
Act_FormEnd ();
2017-02-24 10:34:21 +01:00
/* End container */
2016-01-08 15:08:30 +01:00
fprintf (Gbl.F.Out,"</div>");
2016-01-09 15:00:14 +01:00
/***** End list *****/
fprintf (Gbl.F.Out,"</li>"
"</ul>");
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 ***/
/*****************************************************************************/
2016-04-08 02:16:23 +02:00
static void Soc_PutTextarea (const char *Placeholder,
const char *ClassTextArea,const char *ClassImgTit)
2016-01-15 10:48:49 +01:00
{
extern const char *Txt_Post;
2017-03-07 01:56:41 +01:00
char IdDivImgButton[Act_MAX_BYTES_ID];
2016-01-15 10:48:49 +01:00
2016-04-08 17:38:24 +02:00
/***** Set unique id for the hidden div *****/
2016-04-14 14:21:38 +02:00
Act_SetUniqueId (IdDivImgButton);
2016-01-15 10:48:49 +01:00
/***** Textarea to write the content *****/
fprintf (Gbl.F.Out,"<textarea name=\"Content\" rows=\"1\" maxlength=\"%u\""
2016-01-15 11:41:45 +01:00
" placeholder=\"%s&hellip;\""
2016-01-20 14:07:15 +01:00
" class=\"%s\""
2016-04-08 20:21:33 +02:00
" onfocus=\"expandTextarea(this,'%s','5');\">"
2016-01-15 10:48:49 +01:00
"</textarea>",
Soc_MAX_CHARS_IN_POST,
2016-01-20 14:07:15 +01:00
Placeholder,ClassTextArea,
2016-04-08 20:21:33 +02:00
IdDivImgButton);
2016-04-08 17:38:24 +02:00
/***** Start concealable div *****/
fprintf (Gbl.F.Out,"<div id=\"%s\" style=\"display:none;\">",
IdDivImgButton);
/***** Help on editor *****/
Lay_HelpPlainEditor ();
2016-01-15 10:48:49 +01:00
2016-04-08 16:37:59 +02:00
/***** Attached image (optional) *****/
2016-04-14 21:33:24 +02:00
Img_PutImageUploader (-1,ClassImgTit);
2016-04-08 02:16:23 +02:00
2016-04-08 17:38:24 +02:00
/***** Submit button *****/
2016-01-17 21:46:01 +01:00
fprintf (Gbl.F.Out,"<button type=\"submit\""
" class=\"BT_SUBMIT_INLINE BT_CREATE\">"
2016-01-15 10:48:49 +01:00
"%s"
2016-04-08 20:21:33 +02:00
"</button>",
2016-01-15 10:48:49 +01:00
Txt_Post);
2016-04-08 17:38:24 +02:00
/***** End hidden div *****/
fprintf (Gbl.F.Out,"</div>");
2016-01-15 10:48:49 +01:00
}
2015-12-30 12:40:13 +01:00
/*****************************************************************************/
/******************* Receive and store a new public post *********************/
/*****************************************************************************/
2016-01-02 01:56:48 +01:00
void Soc_ReceiveSocialPostGbl (void)
{
2016-01-15 14:46:44 +01:00
long NotCod;
2016-01-02 01:56:48 +01:00
/***** Receive and store social post *****/
2016-01-15 14:46:44 +01:00
NotCod = Soc_ReceiveSocialPost ();
2016-01-02 01:56:48 +01:00
/***** Write updated timeline after publishing (global) *****/
2016-01-15 14:46:44 +01:00
Soc_ShowTimelineGblHighlightingNot (NotCod);
2016-01-02 01:56:48 +01:00
}
void Soc_ReceiveSocialPostUsr (void)
{
2016-01-15 14:46:44 +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 *****/
fprintf (Gbl.F.Out,"<section id=\"timeline\">");
2016-01-02 01:56:48 +01:00
/***** Receive and store social post *****/
2016-01-15 14:46:44 +01:00
NotCod = Soc_ReceiveSocialPost ();
2016-01-02 01:56:48 +01:00
/***** Write updated timeline after publishing (user) *****/
2016-01-15 14:46:44 +01:00
Soc_ShowTimelineUsrHighlightingNot (NotCod);
2016-01-02 02:33:23 +01:00
/***** End section *****/
fprintf (Gbl.F.Out,"</section>");
2016-01-02 01:56:48 +01:00
}
2016-01-15 14:46:44 +01:00
// Returns the code of the social note just created
static long Soc_ReceiveSocialPost (void)
2015-12-30 12:40:13 +01:00
{
2017-01-28 15:58:46 +01:00
char Content[Cns_MAX_BYTES_LONG_TEXT + 1];
2016-04-08 16:37:59 +02:00
struct Image Image;
char *Query;
2015-12-30 12:40:13 +01:00
long PstCod;
2016-01-25 11:43:14 +01:00
struct SocialPublishing SocPub;
2015-12-30 12:40:13 +01:00
2016-01-15 14:46:44 +01:00
/***** Get the content of the new post *****/
2015-12-30 12:40:13 +01:00
Par_GetParAndChangeFormat ("Content",Content,Cns_MAX_BYTES_LONG_TEXT,
Str_TO_RIGOROUS_HTML,true);
2016-04-08 23:30:43 +02:00
/***** Initialize image *****/
Img_ImageConstructor (&Image);
2016-04-08 16:37:59 +02:00
/***** Get attached image (action, file and title) *****/
2016-04-14 19:19:55 +02:00
Image.Width = Soc_IMAGE_SAVED_MAX_WIDTH;
Image.Height = Soc_IMAGE_SAVED_MAX_HEIGHT;
Image.Quality = Soc_IMAGE_SAVED_QUALITY;
2016-04-14 21:33:24 +02:00
Img_GetImageFromForm (-1,&Image,NULL);
2016-04-08 16:37:59 +02:00
if (Content[0] || // Text not empty
Image.Name[0]) // An image is attached
2016-01-09 15:00:14 +01:00
{
2016-04-08 16:37:59 +02:00
/***** Allocate space for query *****/
if ((Query = malloc (256 +
strlen (Content) +
2017-03-13 14:22:36 +01:00
Img_BYTES_NAME +
Img_MAX_BYTES_TITLE +
Cns_MAX_BYTES_WWW)) == NULL)
2016-04-08 16:37:59 +02:00
Lay_ShowErrorAndExit ("Not enough memory to store database query.");
/***** Check if image is received and processed *****/
if (Image.Action == Img_ACTION_NEW_IMAGE && // Upload new image
Image.Status == Img_FILE_PROCESSED) // The new image received has been processed
/* Move processed image to definitive directory */
Img_MoveImageToDefinitiveDirectory (&Image);
2016-01-11 01:30:23 +01:00
/***** Publish *****/
2016-01-09 15:00:14 +01:00
/* Insert post content in the database */
2017-03-13 13:17:53 +01:00
sprintf (Query,"INSERT INTO social_posts"
" (Content,ImageName,ImageTitle,ImageURL)"
" VALUES"
" ('%s','%s','%s','%s')",
2016-04-08 16:37:59 +02:00
Content,
Image.Name,
(Image.Name[0] && // Save image title only if image attached
2016-04-15 02:33:16 +02:00
Image.Title) ? Image.Title : "",
(Image.Name[0] && // Save image URL only if image attached
Image.URL ) ? Image.URL : "");
2016-01-09 15:00:14 +01:00
PstCod = DB_QueryINSERTandReturnCode (Query,"can not create post");
2015-12-30 12:40:13 +01:00
2016-01-09 15:00:14 +01:00
/* Insert post in social notes */
2016-01-25 11:43:14 +01:00
Soc_StoreAndPublishSocialNote (Soc_NOTE_SOCIAL_POST,PstCod,&SocPub);
2016-04-08 16:37:59 +02:00
/***** Free space used for query *****/
free ((void *) Query);
2016-01-25 11:43:14 +01:00
/***** Analyze content and store notifications about mentions *****/
Str_AnalyzeTxtAndStoreNotifyEventToMentionedUsrs (SocPub.PubCod,Content);
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 *****/
Img_ImageDestructor (&Image);
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
/*****************************************************************************/
2016-01-08 14:08:33 +01:00
/****** Put an icon to toggle on/off the form to comment a social note *******/
2016-01-07 00:42:35 +01:00
/*****************************************************************************/
2017-03-07 01:56:41 +01:00
static void Soc_PutIconToToggleCommentSocialNote (const char UniqueId[Act_MAX_BYTES_ID])
2016-01-07 00:42:35 +01:00
{
extern const char *Txt_Comment;
2016-01-08 14:08:33 +01:00
/***** Link to toggle on/off the form to comment a social note *****/
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_ICO_COMMENT ICO_HIGHLIGHT\">"
2016-01-20 19:23:11 +01:00
"<a href=\"\""
" onclick=\"toggleDisplay('%s');return false;\" />"
"<img src=\"%s/write64x64.gif\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-01-20 19:23:11 +01:00
"</a>"
"</div>",
UniqueId,
Gbl.Prefs.IconsURL,
Txt_Comment,Txt_Comment);
2016-01-07 11:31:36 +01:00
}
2016-01-19 02:08:44 +01:00
/*****************************************************************************/
/****** Put an icon to toggle on/off the form to comment a social note *******/
/*****************************************************************************/
static void Soc_PutIconCommentDisabled (void)
{
extern const char *Txt_Comment;
/***** Disabled icon to comment a social note *****/
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_ICO_COMMENT_DISABLED\">"
2016-01-19 02:08:44 +01:00
"<img src=\"%s/write64x64.gif\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-01-19 02:08:44 +01:00
"</div>",
Gbl.Prefs.IconsURL,
Txt_Comment,Txt_Comment);
}
2016-01-08 15:08:30 +01:00
/*****************************************************************************/
/******************* Form to comment a social publishing *********************/
/*****************************************************************************/
2016-01-14 02:43:46 +01:00
// All forms in this function and nested functions must have unique identifiers
2016-01-08 15:08:30 +01:00
2016-01-11 19:28:43 +01:00
static void Soc_PutHiddenFormToWriteNewCommentToSocialNote (long NotCod,
2017-03-07 01:56:41 +01:00
const char IdNewComment[Act_MAX_BYTES_ID])
2016-01-08 15:08:30 +01:00
{
2016-01-15 11:41:45 +01:00
extern const char *Txt_New_SOCIAL_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 *****/
2016-01-11 19:28:43 +01:00
fprintf (Gbl.F.Out,"<div id=\"%s\""
2016-01-20 14:07:15 +01:00
" class=\"SOCIAL_FORM_NEW_COMMENT\""
2016-01-08 15:08:30 +01:00
" style=\"display:none;\">",
2016-01-15 10:48:49 +01:00
IdNewComment);
2016-01-08 15:08:30 +01:00
2016-01-20 14:07:15 +01:00
/***** Left: write author's photo (my photo) *****/
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_COMMENT_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
fprintf (Gbl.F.Out,"</div>");
/***** Right: form to write the comment *****/
2017-02-24 10:34:21 +01:00
/* Start right container */
2016-01-20 14:07:15 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_COMMENT_RIGHT_CONTAINER\">");
2017-02-24 10:34:21 +01:00
/* Start form to write the post */
Soc_FormStart (ActRcvSocComGbl,ActRcvSocComUsr);
2016-01-11 19:28:43 +01:00
Soc_PutHiddenParamNotCod (NotCod);
2016-01-08 15:08:30 +01:00
2017-02-24 10:34:21 +01:00
/* Textarea and button */
2016-04-08 02:16:23 +02:00
Soc_PutTextarea (Txt_New_SOCIAL_comment,
2016-04-15 14:30:28 +02:00
"SOCIAL_TEXTAREA_COMMENT","SOCIAL_COMMENT_IMG_TIT_URL");
2016-01-08 15:08:30 +01:00
2017-02-24 10:34:21 +01:00
/* End form */
2016-01-08 15:08:30 +01:00
Act_FormEnd ();
2017-02-24 10:34:21 +01:00
/* End right container */
2016-01-20 14:07:15 +01:00
fprintf (Gbl.F.Out,"</div>");
2016-01-08 15:08:30 +01:00
/***** End container *****/
fprintf (Gbl.F.Out,"</div>");
}
2016-01-08 02:55:18 +01:00
/*****************************************************************************/
/****************** Get number of comments in a social note ******************/
/*****************************************************************************/
static unsigned long Soc_GetNumCommentsInSocialNote (long NotCod)
{
char Query[128];
2016-01-12 19:18:56 +01:00
sprintf (Query,"SELECT COUNT(*) FROM social_pubs"
2017-03-24 01:09:27 +01:00
" WHERE NotCod=%ld AND PubType=%u",
2016-01-12 01:56:58 +01:00
NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
2016-01-08 02:55:18 +01:00
return DB_QueryCOUNT (Query,"can not get number of comments in a social note");
}
2016-01-07 11:31:36 +01:00
/*****************************************************************************/
/******************* Form to comment a social publishing *********************/
/*****************************************************************************/
2016-01-14 02:43:46 +01:00
// All forms in this function and nested functions must have unique identifiers
2016-01-07 11:31:36 +01:00
2016-01-20 02:35:27 +01:00
static void Soc_WriteCommentsInSocialNote (const struct SocialNote *SocNot)
2016-01-07 15:19:54 +01:00
{
2017-03-13 14:22:36 +01:00
char Query[1024];
2016-01-07 15:19:54 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-01-11 19:28:43 +01:00
unsigned long NumComments;
2016-01-07 15:19:54 +01:00
unsigned long NumCom;
2016-01-08 01:53:37 +01:00
struct SocialComment SocCom;
2016-01-07 15:19:54 +01:00
2016-01-11 19:28:43 +01:00
/***** Get comments of this social note from database *****/
2016-01-12 19:18:56 +01:00
sprintf (Query,"SELECT social_pubs.PubCod,social_pubs.PublisherCod,"
"social_pubs.NotCod,"
"UNIX_TIMESTAMP(social_pubs.TimePublish),"
2016-04-08 23:30:43 +02:00
"social_comments.Content,"
2016-04-15 02:33:16 +02:00
"social_comments.ImageName,"
"social_comments.ImageTitle,"
"social_comments.ImageURL"
2016-01-12 19:24:29 +01:00
" FROM social_pubs,social_comments"
2017-03-24 01:09:27 +01:00
" WHERE social_pubs.NotCod=%ld"
" AND social_pubs.PubType=%u"
2016-01-25 12:32:13 +01:00
" AND social_pubs.PubCod=social_comments.PubCod"
2016-01-12 19:18:56 +01:00
" ORDER BY social_pubs.PubCod",
2016-01-15 14:05:40 +01:00
SocNot->NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
2016-01-11 19:28:43 +01:00
NumComments = DB_QuerySELECT (Query,&mysql_res,"can not get social comments");
2016-01-08 02:55:18 +01:00
2016-01-11 19:28:43 +01:00
/***** List comments *****/
if (NumComments) // Comments to this social note found
{
/***** Start list *****/
2016-01-20 14:07:15 +01:00
fprintf (Gbl.F.Out,"<ul class=\"LIST_LEFT\">");
2016-01-07 15:19:54 +01:00
2016-01-11 19:28:43 +01:00
/***** List comments one by one *****/
for (NumCom = 0;
NumCom < NumComments;
NumCom++)
{
2016-04-08 23:30:43 +02:00
/* Initialize image */
Img_ImageConstructor (&SocCom.Image);
2016-01-11 19:28:43 +01:00
/* Get data of social comment */
row = mysql_fetch_row (mysql_res);
Soc_GetDataOfSocialCommentFromRow (row,&SocCom);
2016-01-11 00:53:21 +01:00
2016-01-11 19:28:43 +01:00
/* Write social comment */
2016-01-19 21:07:52 +01:00
Soc_WriteSocialComment (&SocCom,
Soc_TOP_MESSAGE_NONE,-1L,
false);
2016-04-08 23:30:43 +02:00
/* Free image */
Img_ImageDestructor (&SocCom.Image);
2016-01-11 00:53:21 +01:00
}
2016-01-11 19:28:43 +01:00
/***** End list *****/
fprintf (Gbl.F.Out,"</ul>");
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
}
2016-01-08 02:55:18 +01:00
/*****************************************************************************/
/**************************** Write social comment ***************************/
/*****************************************************************************/
2016-01-14 02:43:46 +01:00
// All forms in this function and nested functions must have unique identifiers
2016-01-08 02:55:18 +01:00
static void Soc_WriteSocialComment (struct SocialComment *SocCom,
2016-01-19 21:07:52 +01:00
Soc_TopMessage_t TopMessage,long UsrCod,
2016-01-11 00:53:21 +01:00
bool ShowCommentAlone) // Social 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;
2016-01-24 13:46:57 +01:00
bool IAmAFaverOfThisSocCom = false;
2016-01-08 02:55:18 +01:00
bool ShowPhoto = false;
2017-01-28 15:58:46 +01:00
char PhotoURL[PATH_MAX + 1];
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
{
2016-11-12 22:00:50 +01:00
Lay_StartRoundFrame (Soc_WIDTH_TIMELINE,NULL,NULL,NULL);
2016-01-20 15:19:02 +01:00
/***** Write sharer/commenter if distinct to author *****/
Soc_WriteTopMessage (TopMessage,UsrCod);
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_NOTE_LEFT_PHOTO\">"
2016-01-08 02:55:18 +01:00
"</div>"
2016-01-20 15:19:02 +01:00
"<div class=\"SOCIAL_NOTE_RIGHT_CONTAINER\">"
2016-01-08 02:55:18 +01:00
"<ul class=\"LIST_LEFT\">");
}
/***** Start list item *****/
fprintf (Gbl.F.Out,"<li");
2016-01-11 00:53:21 +01:00
if (!ShowCommentAlone)
2016-01-08 02:55:18 +01:00
fprintf (Gbl.F.Out," class=\"SOCIAL_COMMENT\"");
fprintf (Gbl.F.Out,">");
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)
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_ERROR,"Error in social comment.");
2016-01-08 02:55:18 +01:00
else
{
/***** Get author's data *****/
Usr_UsrDataConstructor (&UsrDat);
UsrDat.UsrCod = SocCom->UsrCod;
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat);
IAmTheAuthor = (Gbl.Usrs.Me.Logged &&
UsrDat.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod);
2016-01-24 13:46:57 +01:00
if (!IAmTheAuthor)
2016-01-25 12:32:13 +01:00
IAmAFaverOfThisSocCom = Soc_CheckIfCommIsFavedByUsr (SocCom->PubCod,
2016-01-24 13:46:57 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod);
2016-01-08 02:55:18 +01:00
/***** Left: write author's photo *****/
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_COMMENT_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
2016-01-08 02:55:18 +01:00
fprintf (Gbl.F.Out,"</div>");
2016-04-08 23:30:43 +02:00
/***** Right: author's name, time, content, image and buttons *****/
2016-01-08 02:55:18 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_COMMENT_RIGHT_CONTAINER\">");
/* Write author's full name and nickname */
2016-01-13 17:47:22 +01:00
Soc_WriteAuthorComment (&UsrDat);
2016-01-08 02:55:18 +01:00
/* Write date and time */
Soc_WriteDateTime (SocCom->DateTimeUTC);
/* Write content of the social comment */
2016-01-19 02:08:44 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_TXT\">");
2016-01-08 02:55:18 +01:00
Msg_WriteMsgContent (SocCom->Content,Cns_MAX_BYTES_LONG_TEXT,true,false);
fprintf (Gbl.F.Out,"</div>");
2016-04-08 23:30:43 +02:00
/* Show image */
2016-04-15 14:30:28 +02:00
Img_ShowImage (&SocCom->Image,"SOCIAL_COMMENT_IMG_CONTAINER","SOCIAL_COMMENT_IMG");
2016-04-08 23:30:43 +02:00
2016-01-19 12:54:27 +01:00
/* Put icon to mark this social comment as favourite */
if (IAmTheAuthor) // I am the author
Soc_PutDisabledIconFav (SocCom->NumFavs);
2016-01-24 13:46:57 +01:00
else if (IAmAFaverOfThisSocCom) // I have favourited this social note
2016-01-19 12:54:27 +01:00
/* Put icon to unfav this publishing */
2016-01-25 12:32:13 +01:00
Soc_PutFormToUnfavSocialComment (SocCom->PubCod);
2016-01-19 12:54:27 +01:00
else // I am not the author and I am not a favouriter
/* Put icon to mark this social comment as favourite */
2016-01-25 12:32:13 +01:00
Soc_PutFormToFavSocialComment (SocCom->PubCod);
2016-01-19 12:54:27 +01:00
/* Show who have marked this social comment as favourite */
2016-01-19 21:07:52 +01:00
Soc_ShowUsrsWhoHaveMarkedSocialCommAsFav (SocCom);
2016-01-19 12:54:27 +01:00
2016-01-08 02:55:18 +01:00
/* Put icon to remove this social comment */
2016-01-11 00:53:21 +01:00
if (IAmTheAuthor && !ShowCommentAlone)
2016-01-25 12:32:13 +01:00
Soc_PutFormToRemoveComment (SocCom->PubCod);
2016-01-08 02:55:18 +01:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
/***** End list item *****/
fprintf (Gbl.F.Out,"</li>");
2016-01-11 00:53:21 +01:00
if (ShowCommentAlone)
2016-01-08 02:55:18 +01:00
{
fprintf (Gbl.F.Out,"</ul>"
2016-01-20 15:19:02 +01:00
"</div>"); // SOCIAL_NOTE_RIGHT_CONTAINER
2016-01-08 02:55:18 +01:00
Lay_EndRoundFrame ();
}
}
2016-01-13 17:47:22 +01:00
/*****************************************************************************/
2016-01-27 13:20:08 +01:00
/****** Write name and nickname of author of a comment to a social note ******/
2016-01-13 17:47:22 +01:00
/*****************************************************************************/
2016-01-14 02:43:46 +01:00
// All forms in this function and nested functions must have unique identifiers
2016-01-13 17:47:22 +01:00
static void Soc_WriteAuthorComment (struct UsrData *UsrDat)
{
2017-02-17 01:59:58 +01:00
extern const char *Txt_My_public_profile;
extern const char *Txt_Another_user_s_profile;
bool ItsMe = (Gbl.Usrs.Me.Logged &&
UsrDat->UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod);
2016-01-13 17:47:22 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_COMMENT_RIGHT_AUTHOR\">");
/***** Show user's name inside form to go to user's public profile *****/
2017-02-17 06:32:57 +01:00
Act_FormStartUnique (ActSeeOthPubPrf);
Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
Act_LinkFormSubmitUnique (ItsMe ? Txt_My_public_profile :
Txt_Another_user_s_profile,
"DAT_BOLD");
2016-01-13 17:47:22 +01:00
fprintf (Gbl.F.Out,"%s</a>",UsrDat->FullName);
Act_FormEnd ();
/***** Show user's nickname inside form to go to user's public profile *****/
2017-02-17 06:32:57 +01:00
Act_FormStartUnique (ActSeeOthPubPrf);
Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
Act_LinkFormSubmitUnique (ItsMe ? Txt_My_public_profile :
Txt_Another_user_s_profile,
"DAT_LIGHT");
2016-01-13 17:47:22 +01:00
fprintf (Gbl.F.Out," @%s</a>",UsrDat->Nickname);
Act_FormEnd ();
fprintf (Gbl.F.Out,"</div>");
}
2016-01-07 16:45:35 +01:00
/*****************************************************************************/
2016-01-08 01:53:37 +01:00
/********************** Form to remove social comment ************************/
2016-01-07 16:45:35 +01:00
/*****************************************************************************/
2016-01-14 02:43:46 +01:00
// All forms in this function and nested functions must have unique identifiers
2016-01-07 16:45:35 +01:00
2016-01-25 12:32:13 +01:00
static void Soc_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
2016-01-08 01:53:37 +01:00
/***** Form to remove social publishing *****/
2017-02-24 10:34:21 +01:00
Soc_FormStart (ActReqRemSocComGbl,ActReqRemSocComUsr);
2016-01-25 12:32:13 +01:00
Soc_PutHiddenParamPubCod (PubCod);
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_ICO_REMOVE ICO_HIGHLIGHT\">"
2016-01-08 01:53:37 +01:00
"<input type=\"image\""
" src=\"%s/remove-on64x64.png\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-01-08 01:53:37 +01:00
"</div>",
Gbl.Prefs.IconsURL,
Txt_Remove,
Txt_Remove);
Act_FormEnd ();
2016-01-07 16:45:35 +01:00
}
2016-01-19 12:54:27 +01:00
/*****************************************************************************/
/***************** Form to mark a social comment as favourite ****************/
/*****************************************************************************/
// All forms in this function and nested functions must have unique identifiers
2016-01-25 12:32:13 +01:00
static void Soc_PutFormToFavSocialComment (long PubCod)
2016-01-19 12:54:27 +01:00
{
extern const char *Txt_Mark_as_favourite;
/***** Form to mark social comment as favourite *****/
2017-02-24 10:34:21 +01:00
Soc_FormStart (ActFavSocComGbl,ActFavSocComUsr);
2016-01-25 12:32:13 +01:00
Soc_PutHiddenParamPubCod (PubCod);
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_ICO_FAV ICO_HIGHLIGHT\">"
2016-01-19 12:54:27 +01:00
"<input type=\"image\""
" src=\"%s/fav64x64.png\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-01-19 12:54:27 +01:00
"</div>",
Gbl.Prefs.IconsURL,
Txt_Mark_as_favourite,Txt_Mark_as_favourite);
Act_FormEnd ();
}
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
/*****************************************************************************/
2016-01-05 21:30:10 +01:00
static void Soc_PutDisabledIconShare (unsigned NumShared)
2016-01-04 11:58:36 +01:00
{
2016-01-16 02:54:13 +01:00
extern const char *Txt_SOCIAL_NOTE_Shared_by_X_USERS;
extern const char *Txt_SOCIAL_NOTE_Not_shared_by_anyone;
2016-01-05 21:30:10 +01:00
2016-01-05 21:58:25 +01:00
if (NumShared)
2016-01-16 02:54:13 +01:00
sprintf (Gbl.Title,Txt_SOCIAL_NOTE_Shared_by_X_USERS,NumShared);
2016-01-05 21:58:25 +01:00
else
2017-01-15 22:58:26 +01:00
Str_Copy (Gbl.Title,Txt_SOCIAL_NOTE_Not_shared_by_anyone,
Lay_MAX_BYTES_TITLE);
2016-01-04 11:58:36 +01:00
2016-01-05 04:54:00 +01:00
/***** Disabled icon to share *****/
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_ICO_SHARE_DISABLED\">"
2016-01-04 11:58:36 +01:00
"<img src=\"%s/share64x64.png\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-01-04 11:58:36 +01:00
"</div>",
Gbl.Prefs.IconsURL,
2016-01-05 21:30:10 +01:00
Gbl.Title,Gbl.Title);
2016-01-04 11:58:36 +01:00
}
2016-01-19 00:50:35 +01:00
/*****************************************************************************/
/****************** Put disabled icon to mark as favourite *******************/
/*****************************************************************************/
static void Soc_PutDisabledIconFav (unsigned NumFavs)
{
extern const char *Txt_SOCIAL_NOTE_Favourited_by_X_USERS;
extern const char *Txt_SOCIAL_NOTE_Not_favourited_by_anyone;
if (NumFavs)
sprintf (Gbl.Title,Txt_SOCIAL_NOTE_Favourited_by_X_USERS,NumFavs);
else
2017-01-15 22:58:26 +01:00
Str_Copy (Gbl.Title,Txt_SOCIAL_NOTE_Not_favourited_by_anyone,
Lay_MAX_BYTES_TITLE);
2016-01-19 00:50:35 +01:00
/***** Disabled icon to mark as favourite *****/
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_ICO_FAV_DISABLED\">"
2016-01-19 00:50:35 +01:00
"<img src=\"%s/fav64x64.png\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-01-19 00:50:35 +01:00
"</div>",
Gbl.Prefs.IconsURL,
Gbl.Title,Gbl.Title);
}
2015-12-30 02:08:08 +01:00
/*****************************************************************************/
2016-01-04 02:54:04 +01:00
/************************* Form to share social note *************************/
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2016-01-14 02:43:46 +01:00
// All forms in this function and nested functions must have unique identifiers
2016-01-01 20:19:43 +01:00
2016-01-05 21:30:10 +01:00
static void Soc_PutFormToShareSocialNote (long NotCod)
2016-01-01 20:19:43 +01:00
{
extern const char *Txt_Share;
2016-01-04 02:54:04 +01:00
/***** Form to share social note *****/
2017-02-24 10:34:21 +01:00
Soc_FormStart (ActShaSocNotGbl,ActShaSocNotUsr);
2016-01-05 21:30:10 +01:00
Soc_PutHiddenParamNotCod (NotCod);
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_ICO_SHARE ICO_HIGHLIGHT\">"
2016-01-01 20:19:43 +01:00
"<input type=\"image\""
" src=\"%s/share64x64.png\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-01-01 20:19:43 +01:00
"</div>",
Gbl.Prefs.IconsURL,
2016-01-19 02:08:44 +01:00
Txt_Share,Txt_Share);
2016-01-01 20:19:43 +01:00
Act_FormEnd ();
}
/*****************************************************************************/
2016-01-19 00:50:35 +01:00
/******************* Form to mark a social note as favourite *****************/
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2016-01-14 02:43:46 +01:00
// All forms in this function and nested functions must have unique identifiers
2016-01-01 20:19:43 +01:00
2016-01-19 00:50:35 +01:00
static void Soc_PutFormToFavSocialNote (long NotCod)
{
extern const char *Txt_Mark_as_favourite;
/***** Form to mark social note as favourite *****/
2017-02-24 10:34:21 +01:00
Soc_FormStart (ActFavSocNotGbl,ActFavSocNotUsr);
2016-01-19 00:50:35 +01:00
Soc_PutHiddenParamNotCod (NotCod);
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_ICO_FAV ICO_HIGHLIGHT\">"
2016-01-19 00:50:35 +01:00
"<input type=\"image\""
" src=\"%s/fav64x64.png\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-01-19 00:50:35 +01:00
"</div>",
Gbl.Prefs.IconsURL,
Txt_Mark_as_favourite,Txt_Mark_as_favourite);
Act_FormEnd ();
}
/*****************************************************************************/
/*************** Form to unshare (stop sharing) social note ******************/
/*****************************************************************************/
// All forms in this function and nested functions must have unique identifiers
static void Soc_PutFormToUnshareSocialNote (long NotCod)
2016-01-01 20:19:43 +01:00
{
2016-01-19 02:08:44 +01:00
extern const char *Txt_SOCIAL_NOTE_Shared;
2016-01-01 20:19:43 +01:00
/***** Form to share social publishing *****/
2017-02-24 10:34:21 +01:00
Soc_FormStart (ActUnsSocNotGbl,ActUnsSocNotUsr);
2016-01-11 19:28:43 +01:00
Soc_PutHiddenParamNotCod (NotCod);
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_ICO_SHARE ICO_HIGHLIGHT\">"
2016-01-01 20:19:43 +01:00
"<input type=\"image\""
" src=\"%s/shared64x64.png\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-01-01 20:19:43 +01:00
"</div>",
Gbl.Prefs.IconsURL,
2016-01-19 02:08:44 +01:00
Txt_SOCIAL_NOTE_Shared,Txt_SOCIAL_NOTE_Shared);
2016-01-01 20:19:43 +01:00
Act_FormEnd ();
}
2016-01-19 00:50:35 +01:00
/*****************************************************************************/
/*********** Form to unfav (remove mark as favourite) social note ************/
/*****************************************************************************/
// All forms in this function and nested functions must have unique identifiers
static void Soc_PutFormToUnfavSocialNote (long NotCod)
{
2016-01-19 02:08:44 +01:00
extern const char *Txt_SOCIAL_NOTE_Favourite;
2016-01-19 00:50:35 +01:00
2016-01-19 21:07:52 +01:00
/***** Form to unfav social note *****/
2017-02-24 10:34:21 +01:00
Soc_FormStart (ActUnfSocNotGbl,ActUnfSocNotUsr);
2016-01-19 00:50:35 +01:00
Soc_PutHiddenParamNotCod (NotCod);
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_ICO_FAV ICO_HIGHLIGHT\">"
2016-01-19 00:50:35 +01:00
"<input type=\"image\""
" src=\"%s/faved64x64.png\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-01-19 00:50:35 +01:00
"</div>",
Gbl.Prefs.IconsURL,
2016-01-19 02:08:44 +01:00
Txt_SOCIAL_NOTE_Favourite,Txt_SOCIAL_NOTE_Favourite);
2016-01-19 00:50:35 +01:00
Act_FormEnd ();
}
2016-01-19 21:07:52 +01:00
/*****************************************************************************/
/********* Form to unfav (remove mark as favourite) social comment ***********/
/*****************************************************************************/
// All forms in this function and nested functions must have unique identifiers
2016-01-25 12:32:13 +01:00
static void Soc_PutFormToUnfavSocialComment (long PubCod)
2016-01-19 21:07:52 +01:00
{
extern const char *Txt_SOCIAL_NOTE_Favourite;
/***** Form to unfav social comment *****/
2017-02-24 10:34:21 +01:00
Soc_FormStart (ActUnfSocComGbl,ActUnfSocComUsr);
2016-01-25 12:32:13 +01:00
Soc_PutHiddenParamPubCod (PubCod);
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_ICO_FAV ICO_HIGHLIGHT\">"
2016-01-19 21:07:52 +01:00
"<input type=\"image\""
" src=\"%s/faved64x64.png\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-01-19 21:07:52 +01:00
"</div>",
Gbl.Prefs.IconsURL,
Txt_SOCIAL_NOTE_Favourite,Txt_SOCIAL_NOTE_Favourite);
Act_FormEnd ();
}
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
/******************** Form to remove social publishing ***********************/
2015-12-30 02:08:08 +01:00
/*****************************************************************************/
2016-01-14 02:43:46 +01:00
// All forms in this function and nested functions must have unique identifiers
2015-12-30 02:08:08 +01:00
2016-01-11 19:28:43 +01:00
static void Soc_PutFormToRemoveSocialPublishing (long NotCod)
2015-12-30 02:08:08 +01:00
{
extern const char *Txt_Remove;
2015-12-31 18:40:45 +01:00
/***** Form to remove social publishing *****/
2017-02-24 10:34:21 +01:00
Soc_FormStart (ActReqRemSocPubGbl,ActReqRemSocPubUsr);
2016-01-11 19:28:43 +01:00
Soc_PutHiddenParamNotCod (NotCod);
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_ICO_REMOVE ICO_HIGHLIGHT\">"
2015-12-30 02:08:08 +01:00
"<input type=\"image\""
" src=\"%s/remove-on64x64.png\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2015-12-30 02:08:08 +01:00
"</div>",
Gbl.Prefs.IconsURL,
Txt_Remove,
Txt_Remove);
Act_FormEnd ();
}
2016-01-05 21:30:10 +01:00
/*****************************************************************************/
/************** Put parameter with the code of a social note *****************/
/*****************************************************************************/
2016-01-25 14:40:57 +01:00
static void Soc_PutHiddenParamNotCod (long NotCod)
2016-01-05 21:30:10 +01:00
{
Par_PutHiddenParamLong ("NotCod",NotCod);
}
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2016-01-25 12:32:13 +01:00
/*********** Put parameter with the code of a social publishing **************/
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2016-01-25 14:40:57 +01:00
void Soc_PutHiddenParamPubCod (long PubCod)
2016-01-08 01:53:37 +01:00
{
2016-01-25 12:32:13 +01:00
Par_PutHiddenParamLong ("PubCod",PubCod);
2016-01-08 01:53:37 +01:00
}
2016-01-05 21:30:10 +01:00
/*****************************************************************************/
/************** Get parameter with the code of a social note *****************/
/*****************************************************************************/
static long Soc_GetParamNotCod (void)
{
2017-01-28 20:32:50 +01:00
/***** Get social note code *****/
return Par_GetParToLong ("NotCod");
2016-01-05 21:30:10 +01:00
}
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2016-01-25 12:32:13 +01:00
/************ Get parameter with the code of a social publishing *************/
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2016-01-25 12:32:13 +01:00
static long Soc_GetParamPubCod (void)
2016-01-08 01:53:37 +01:00
{
2017-01-28 20:32:50 +01:00
/***** Get social comment code *****/
return Par_GetParToLong ("PubCod");
2016-01-08 01:53:37 +01:00
}
2016-01-07 00:42:35 +01:00
/*****************************************************************************/
/*************************** Comment a social note ***************************/
/*****************************************************************************/
2016-01-07 14:21:21 +01:00
void Soc_ReceiveCommentGbl (void)
2016-01-07 00:42:35 +01:00
{
2016-01-16 02:01:14 +01:00
long NotCod;
2016-01-07 14:21:21 +01:00
/***** Receive comment in a social note *****/
2016-01-16 02:01:14 +01:00
NotCod = Soc_ReceiveComment ();
2016-01-07 00:42:35 +01:00
/***** Write updated timeline after commenting (global) *****/
2016-01-16 02:01:14 +01:00
Soc_ShowTimelineGblHighlightingNot (NotCod);
2016-01-07 00:42:35 +01:00
}
2016-01-07 14:21:21 +01:00
void Soc_ReceiveCommentUsr (void)
2016-01-07 00:42:35 +01:00
{
2016-01-16 02:01:14 +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 *****/
fprintf (Gbl.F.Out,"<section id=\"timeline\">");
2016-01-07 14:21:21 +01:00
/***** Receive comment in a social note *****/
2016-01-16 02:01:14 +01:00
NotCod = Soc_ReceiveComment ();
2016-01-07 00:42:35 +01:00
/***** Write updated timeline after commenting (user) *****/
2016-01-16 02:01:14 +01:00
Soc_ShowTimelineUsrHighlightingNot (NotCod);
2016-01-07 00:42:35 +01:00
/***** End section *****/
fprintf (Gbl.F.Out,"</section>");
}
2016-01-16 02:01:14 +01:00
static long Soc_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;
2017-01-28 15:58:46 +01:00
char Content[Cns_MAX_BYTES_LONG_TEXT + 1];
2016-04-08 23:30:43 +02:00
struct Image Image;
char *Query;
2016-01-07 14:21:21 +01:00
struct SocialNote SocNot;
2016-01-12 01:56:58 +01:00
struct SocialPublishing SocPub;
2016-01-07 14:21:21 +01:00
2016-01-11 01:30:23 +01:00
/***** Get data of social note *****/
2016-01-11 19:28:43 +01:00
SocNot.NotCod = Soc_GetParamNotCod ();
2016-01-19 21:07:52 +01:00
Soc_GetDataOfSocialNotByCod (&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 *****/
2016-01-15 14:05:40 +01:00
Par_GetParAndChangeFormat ("Content",Content,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 *****/
Img_ImageConstructor (&Image);
/***** Get attached image (action, file and title) *****/
2016-04-14 19:19:55 +02:00
Image.Width = Soc_IMAGE_SAVED_MAX_WIDTH;
Image.Height = Soc_IMAGE_SAVED_MAX_HEIGHT;
Image.Quality = Soc_IMAGE_SAVED_QUALITY;
2016-04-14 21:33:24 +02:00
Img_GetImageFromForm (-1,&Image,NULL);
2016-04-08 23:30:43 +02:00
if (Content[0] || // Text not empty
Image.Name[0]) // An image is attached
2016-01-11 01:46:33 +01:00
{
2016-04-08 23:30:43 +02:00
/***** Allocate space for query *****/
if ((Query = malloc (256 +
strlen (Content) +
2017-03-13 14:22:36 +01:00
Img_BYTES_NAME +
Img_MAX_BYTES_TITLE +
Cns_MAX_BYTES_WWW)) == NULL)
2016-04-08 23:30:43 +02:00
Lay_ShowErrorAndExit ("Not enough memory to store database query.");
/***** Check if image is received and processed *****/
if (Image.Action == Img_ACTION_NEW_IMAGE && // Upload new image
Image.Status == Img_FILE_PROCESSED) // The new image received has been processed
/* Move processed image to definitive directory */
Img_MoveImageToDefinitiveDirectory (&Image);
2016-01-16 02:54:13 +01:00
/***** Publish *****/
/* Insert into publishings */
SocPub.NotCod = SocNot.NotCod;
SocPub.PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod;
SocPub.PubType = Soc_PUB_COMMENT_TO_NOTE;
Soc_PublishSocialNoteInTimeline (&SocPub); // Set SocPub.PubCod
/* Insert comment content in the database */
2016-04-08 23:30:43 +02:00
sprintf (Query,"INSERT INTO social_comments"
2016-04-15 02:33:16 +02:00
" (PubCod,Content,ImageName,ImageTitle,ImageURL)"
2017-03-13 13:17:53 +01:00
" VALUES"
2017-03-24 01:09:27 +01:00
" (%ld,'%s','%s','%s','%s')",
2016-01-16 02:54:13 +01:00
SocPub.PubCod,
2016-04-08 23:30:43 +02:00
Content,
Image.Name,
(Image.Name[0] && // Save image title only if image attached
2016-04-15 02:33:16 +02:00
Image.Title) ? Image.Title : "",
(Image.Name[0] && // Save image URL only if image attached
Image.URL ) ? Image.URL : "");
2016-01-16 02:54:13 +01:00
DB_QueryINSERT (Query,"can not store comment content");
2016-04-08 23:30:43 +02:00
/***** Free space used for query *****/
free ((void *) Query);
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 *****/
Str_AnalyzeTxtAndStoreNotifyEventToMentionedUsrs (SocPub.PubCod,Content);
2016-01-16 02:54:13 +01:00
/***** Show the social note just commented *****/
2016-01-19 00:50:35 +01:00
Soc_WriteSocialNote (&SocNot,
Soc_TOP_MESSAGE_COMMENTED,Gbl.Usrs.Me.UsrDat.UsrCod,
true,true);
2016-01-11 01:46:33 +01:00
}
2016-04-08 23:30:43 +02:00
/***** Free image *****/
Img_ImageDestructor (&Image);
2016-01-11 01:46:33 +01:00
}
2016-01-11 02:15:23 +01:00
else
2017-05-11 23:45:46 +02: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
/*****************************************************************************/
2016-01-04 02:54:04 +01:00
/**************************** Share a social note ****************************/
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2016-01-04 02:54:04 +01:00
void Soc_ShareSocialNoteGbl (void)
2016-01-02 01:56:48 +01:00
{
2016-01-15 15:01:11 +01:00
long NotCod;
2016-01-04 02:54:04 +01:00
/***** Share social note *****/
2016-01-15 15:01:11 +01:00
NotCod = Soc_ShareSocialNote ();
2016-01-02 01:56:48 +01:00
/***** Write updated timeline after sharing (global) *****/
2016-01-15 15:01:11 +01:00
Soc_ShowTimelineGblHighlightingNot (NotCod);
2016-01-02 01:56:48 +01:00
}
2016-01-04 02:54:04 +01:00
void Soc_ShareSocialNoteUsr (void)
2016-01-02 01:56:48 +01:00
{
2016-01-15 15:01:11 +01:00
long NotCod;
2016-01-02 01:56:48 +01:00
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
2016-01-04 02:54:04 +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 *****/
fprintf (Gbl.F.Out,"<section id=\"timeline\">");
2016-01-04 02:54:04 +01:00
/***** Share social note *****/
2016-01-15 15:01:11 +01:00
NotCod = Soc_ShareSocialNote ();
2016-01-02 01:56:48 +01:00
/***** Write updated timeline after sharing (user) *****/
2016-01-15 15:01:11 +01:00
Soc_ShowTimelineUsrHighlightingNot (NotCod);
2016-01-02 02:33:23 +01:00
/***** End section *****/
fprintf (Gbl.F.Out,"</section>");
2016-01-02 01:56:48 +01:00
}
2016-01-15 15:01:11 +01:00
static long Soc_ShareSocialNote (void)
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;
2016-01-02 14:56:38 +01:00
struct SocialNote SocNot;
2016-01-04 02:54:04 +01:00
struct SocialPublishing SocPub;
2016-01-25 20:28:33 +01:00
long OriginalPubCod;
2016-01-01 20:19:43 +01:00
2016-01-02 14:56:38 +01:00
/***** Get data of social note *****/
2016-01-25 14:40:57 +01:00
SocNot.NotCod = Soc_GetParamNotCod ();
2016-01-19 21:07:52 +01:00
Soc_GetDataOfSocialNotByCod (&SocNot);
2016-01-02 14:56:38 +01:00
2016-01-11 09:59:36 +01:00
if (SocNot.NotCod > 0)
2016-01-01 20:19:43 +01:00
{
2016-01-24 13:46:57 +01:00
if (Gbl.Usrs.Me.Logged &&
SocNot.UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) // I am not the author
if (!Soc_CheckIfNoteIsSharedByUsr (SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod)) // Not yet shared by me
{
/***** Share (publish social note in timeline) *****/
SocPub.NotCod = SocNot.NotCod;
SocPub.PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod;
SocPub.PubType = Soc_PUB_SHARED_NOTE;
Soc_PublishSocialNoteInTimeline (&SocPub); // Set SocPub.PubCod
/* Update number of times this social note is shared */
SocNot.NumShared = Soc_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 ***/
2016-01-25 20:28:33 +01:00
OriginalPubCod = Soc_GetPubCodOfOriginalSocialNote (SocNot.NotCod);
if (OriginalPubCod > 0)
Soc_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-11 09:59:36 +01:00
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
2016-01-15 15:01:11 +01:00
return SocNot.NotCod;
2016-01-01 20:19:43 +01:00
}
2016-01-19 00:50:35 +01:00
/*****************************************************************************/
/********************** Mark a social note as favourite **********************/
/*****************************************************************************/
void Soc_FavSocialNoteGbl (void)
{
long NotCod;
/***** Mark social note as favourite *****/
NotCod = Soc_FavSocialNote ();
/***** Write updated timeline after marking as favourite (global) *****/
Soc_ShowTimelineGblHighlightingNot (NotCod);
}
void Soc_FavSocialNoteUsr (void)
{
long NotCod;
/***** 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-19 00:50:35 +01:00
/***** Start section *****/
fprintf (Gbl.F.Out,"<section id=\"timeline\">");
/***** Mark social note as favourite *****/
NotCod = Soc_FavSocialNote ();
/***** Write updated timeline after marking as favourite (user) *****/
Soc_ShowTimelineUsrHighlightingNot (NotCod);
/***** End section *****/
fprintf (Gbl.F.Out,"</section>");
}
static long Soc_FavSocialNote (void)
{
extern const char *Txt_The_original_post_no_longer_exists;
2016-01-23 01:38:55 +01:00
char Query[256];
2016-01-19 00:50:35 +01:00
struct SocialNote SocNot;
2016-01-25 20:28:33 +01:00
long OriginalPubCod;
2016-01-19 00:50:35 +01:00
/***** Get data of social note *****/
2016-01-25 14:40:57 +01:00
SocNot.NotCod = Soc_GetParamNotCod ();
2016-01-19 21:07:52 +01:00
Soc_GetDataOfSocialNotByCod (&SocNot);
2016-01-19 00:50:35 +01:00
if (SocNot.NotCod > 0)
{
2016-01-24 13:46:57 +01:00
if (Gbl.Usrs.Me.Logged &&
SocNot.UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) // I am not the author
if (!Soc_CheckIfNoteIsFavedByUsr (SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod)) // I have not yet favourited the note
2016-01-23 01:38:55 +01:00
{
2016-01-24 13:46:57 +01:00
/***** Mark as favourite in database *****/
sprintf (Query,"INSERT IGNORE INTO social_notes_fav"
2017-03-13 13:17:53 +01:00
" (NotCod,UsrCod,TimeFav)"
" VALUES"
2017-03-24 01:09:27 +01:00
" (%ld,%ld,NOW())",
2016-01-24 13:46:57 +01:00
SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryINSERT (Query,"can not favourite social note");
/* Update number of times this social note is favourited */
SocNot.NumFavs = Soc_GetNumTimesANoteHasBeenFav (&SocNot);
/**** Create notification about favourite post
for the author of the post ***/
2016-01-25 20:28:33 +01:00
OriginalPubCod = Soc_GetPubCodOfOriginalSocialNote (SocNot.NotCod);
if (OriginalPubCod > 0)
Soc_CreateNotifToAuthor (SocNot.UsrCod,OriginalPubCod,Ntf_EVENT_TIMELINE_FAV);
2016-01-23 01:38:55 +01:00
2016-01-24 13:46:57 +01:00
/***** Show the social note just favourited *****/
Soc_WriteSocialNote (&SocNot,
2016-01-25 14:40:57 +01:00
Soc_TOP_MESSAGE_FAVED,Gbl.Usrs.Me.UsrDat.UsrCod,
2016-01-24 13:46:57 +01:00
true,true);
}
2016-01-19 00:50:35 +01:00
}
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
2016-01-19 00:50:35 +01:00
return SocNot.NotCod;
}
2016-01-19 12:54:27 +01:00
/*****************************************************************************/
/********************* Mark a social comment as favourite ********************/
/*****************************************************************************/
void Soc_FavSocialCommentGbl (void)
{
long NotCod;
/***** Mark social comment as favourite *****/
NotCod = Soc_FavSocialComment ();
/***** Write updated timeline after marking as favourite (global) *****/
Soc_ShowTimelineGblHighlightingNot (NotCod);
}
void Soc_FavSocialCommentUsr (void)
{
long NotCod;
/***** 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-19 12:54:27 +01:00
/***** Start section *****/
fprintf (Gbl.F.Out,"<section id=\"timeline\">");
/***** Mark social comment as favourite *****/
NotCod = Soc_FavSocialComment ();
/***** Write updated timeline after marking as favourite (user) *****/
Soc_ShowTimelineUsrHighlightingNot (NotCod);
/***** End section *****/
fprintf (Gbl.F.Out,"</section>");
}
static long Soc_FavSocialComment (void)
{
2016-01-19 21:07:52 +01:00
extern const char *Txt_The_comment_no_longer_exists;
2016-01-19 12:54:27 +01:00
struct SocialComment SocCom;
char Query[256];
2016-04-08 23:30:43 +02:00
/***** Initialize image *****/
Img_ImageConstructor (&SocCom.Image);
2016-01-25 14:40:57 +01:00
/***** Get data of social comment *****/
2016-01-25 12:32:13 +01:00
SocCom.PubCod = Soc_GetParamPubCod ();
2016-01-19 21:07:52 +01:00
Soc_GetDataOfSocialComByCod (&SocCom);
2016-01-19 12:54:27 +01:00
2016-01-25 12:32:13 +01:00
if (SocCom.PubCod > 0)
2016-01-19 12:54:27 +01:00
{
2016-01-24 13:46:57 +01:00
if (Gbl.Usrs.Me.Logged &&
SocCom.UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) // I am not the author
2016-01-25 12:32:13 +01:00
if (!Soc_CheckIfCommIsFavedByUsr (SocCom.PubCod,
2016-01-24 13:46:57 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod)) // I have not yet favourited the comment
{
/***** Mark as favourite in database *****/
sprintf (Query,"INSERT IGNORE INTO social_comments_fav"
2017-03-13 13:17:53 +01:00
" (PubCod,UsrCod,TimeFav)"
" VALUES"
2017-03-24 01:09:27 +01:00
" (%ld,%ld,NOW())",
2016-01-25 12:32:13 +01:00
SocCom.PubCod,
2016-01-24 13:46:57 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryINSERT (Query,"can not favourite social comment");
/* Update number of times this social comment is favourited */
SocCom.NumFavs = Soc_GetNumTimesACommHasBeenFav (&SocCom);
/**** Create notification about favourite post
for the author of the post ***/
2016-01-25 18:57:37 +01:00
Soc_CreateNotifToAuthor (SocCom.UsrCod,SocCom.PubCod,Ntf_EVENT_TIMELINE_FAV);
2016-01-24 13:46:57 +01:00
/***** Show the social comment just favourited *****/
Soc_WriteSocialComment (&SocCom,
2016-01-25 14:40:57 +01:00
Soc_TOP_MESSAGE_FAVED,Gbl.Usrs.Me.UsrDat.UsrCod,
2016-01-24 13:46:57 +01:00
true);
}
2016-01-19 12:54:27 +01:00
}
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists);
2016-01-19 12:54:27 +01:00
2016-04-08 23:30:43 +02:00
/***** Free image *****/
Img_ImageDestructor (&SocCom.Image);
2016-01-19 12:54:27 +01:00
return SocCom.NotCod;
}
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
/*****************************************************************************/
2016-01-25 18:57:37 +01:00
static void Soc_CreateNotifToAuthor (long AuthorCod,long PubCod,
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;
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat))
{
2016-11-16 23:19:52 +01:00
/***** This fav must be notified by email? *****/
2016-01-25 18:57:37 +01:00
CreateNotif = (UsrDat.Prefs.NotifNtfEvents & (1 << NotifyEvent));
2016-01-23 01:38:55 +01:00
NotifyByEmail = CreateNotif &&
2016-01-25 18:57:37 +01:00
(UsrDat.Prefs.EmailNtfEvents & (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 :
0));
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2016-01-16 01:37:37 +01:00
/***************** Unshare a previously shared social note *******************/
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2016-01-16 01:37:37 +01:00
void Soc_UnshareSocialNoteGbl (void)
2016-01-02 01:56:48 +01:00
{
2016-01-16 01:37:37 +01:00
long NotCod;
/***** Unshare a previously shared social note *****/
NotCod = Soc_UnshareSocialNote ();
2016-01-02 01:56:48 +01:00
/***** Write updated timeline after unsharing (global) *****/
2016-01-16 01:37:37 +01:00
Soc_ShowTimelineGblHighlightingNot (NotCod);
2016-01-02 01:56:48 +01:00
}
2016-01-16 01:37:37 +01:00
void Soc_UnshareSocialNoteUsr (void)
2016-01-02 01:56:48 +01:00
{
2016-01-16 01:37:37 +01:00
long NotCod;
2016-01-02 01:56:48 +01:00
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
2016-01-19 00:50: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 *****/
fprintf (Gbl.F.Out,"<section id=\"timeline\">");
2016-01-16 01:37:37 +01:00
/***** Unshare a previously shared social note *****/
NotCod = Soc_UnshareSocialNote ();
2016-01-02 01:56:48 +01:00
/***** Write updated timeline after unsharing (user) *****/
2016-01-16 01:37:37 +01:00
Soc_ShowTimelineUsrHighlightingNot (NotCod);
2016-01-02 02:33:23 +01:00
/***** End section *****/
fprintf (Gbl.F.Out,"</section>");
2016-01-02 01:56:48 +01:00
}
2016-01-16 01:37:37 +01:00
static long Soc_UnshareSocialNote (void)
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-19 12:54:27 +01:00
char Query[256];
2016-01-24 13:46:57 +01:00
struct SocialNote SocNot;
2016-01-25 20:28:33 +01:00
long OriginalPubCod;
2016-01-01 20:19:43 +01:00
/***** Get data of social note *****/
2016-01-11 19:28:43 +01:00
SocNot.NotCod = Soc_GetParamNotCod ();
2016-01-19 21:07:52 +01:00
Soc_GetDataOfSocialNotByCod (&SocNot);
2016-01-01 20:19:43 +01:00
2016-01-24 13:46:57 +01:00
if (SocNot.NotCod > 0)
2016-01-01 20:19:43 +01:00
{
2016-01-24 13:46:57 +01:00
if (SocNot.NumShared &&
Gbl.Usrs.Me.Logged &&
SocNot.UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) // I am not the author
if (Soc_CheckIfNoteIsSharedByUsr (SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod)) // I am a sharer
{
2016-01-24 14:26:35 +01:00
/***** Delete social publishing from database *****/
sprintf (Query,"DELETE FROM social_pubs"
2017-03-24 01:09:27 +01:00
" WHERE NotCod=%ld"
" AND PublisherCod=%ld"
" AND PubType=%u",
2016-01-24 14:26:35 +01:00
SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Soc_PUB_SHARED_NOTE);
DB_QueryDELETE (Query,"can not remove a social publishing");
2016-01-24 13:46:57 +01:00
/***** Update number of times this social note is shared *****/
SocNot.NumShared = Soc_UpdateNumTimesANoteHasBeenShared (&SocNot);
2016-01-25 11:53:20 +01:00
/***** Mark possible notifications on this social note as removed *****/
2016-01-25 20:28:33 +01:00
OriginalPubCod = Soc_GetPubCodOfOriginalSocialNote (SocNot.NotCod);
if (OriginalPubCod > 0)
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_SHARE,OriginalPubCod);
2016-01-25 11:53:20 +01:00
2016-01-24 13:46:57 +01:00
/***** Show the social note corresponding
to the publishing just unshared *****/
Soc_WriteSocialNote (&SocNot,
Soc_TOP_MESSAGE_UNSHARED,Gbl.Usrs.Me.UsrDat.UsrCod,
true,true);
}
2016-01-01 20:19:43 +01:00
}
2016-01-24 13:46:57 +01:00
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
2016-01-16 01:37:37 +01:00
return SocNot.NotCod;
2016-01-01 20:19:43 +01:00
}
2016-01-19 00:50:35 +01:00
/*****************************************************************************/
/******* Stop marking as favourite a previously favourited social note *******/
/*****************************************************************************/
void Soc_UnfavSocialNoteGbl (void)
{
long NotCod;
/***** Stop marking as favourite a previously favourited social note *****/
NotCod = Soc_UnfavSocialNote ();
/***** Write updated timeline after unfav (global) *****/
Soc_ShowTimelineGblHighlightingNot (NotCod);
}
void Soc_UnfavSocialNoteUsr (void)
{
long NotCod;
/***** 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-19 00:50:35 +01:00
/***** Start section *****/
fprintf (Gbl.F.Out,"<section id=\"timeline\">");
2016-01-19 12:54:27 +01:00
/***** Unfav a social note previously marked as favourite *****/
2016-01-19 00:50:35 +01:00
NotCod = Soc_UnfavSocialNote ();
/***** Write updated timeline after unfav (user) *****/
Soc_ShowTimelineUsrHighlightingNot (NotCod);
/***** End section *****/
fprintf (Gbl.F.Out,"</section>");
}
static long Soc_UnfavSocialNote (void)
{
2016-01-24 13:46:57 +01:00
extern const char *Txt_The_original_post_no_longer_exists;
2016-01-19 00:50:35 +01:00
struct SocialNote SocNot;
char Query[256];
2016-01-25 20:28:33 +01:00
long OriginalPubCod;
2016-01-19 00:50:35 +01:00
/***** Get data of social note *****/
SocNot.NotCod = Soc_GetParamNotCod ();
2016-01-19 21:07:52 +01:00
Soc_GetDataOfSocialNotByCod (&SocNot);
2016-01-19 00:50:35 +01:00
2016-01-24 13:46:57 +01:00
if (SocNot.NotCod > 0)
2016-01-19 00:50:35 +01:00
{
2016-01-24 13:46:57 +01:00
if (SocNot.NumFavs &&
Gbl.Usrs.Me.Logged &&
SocNot.UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) // I am not the author
if (Soc_CheckIfNoteIsFavedByUsr (SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod)) // I have favourited the note
{
/***** Delete the mark as favourite from database *****/
sprintf (Query,"DELETE FROM social_notes_fav"
2017-03-24 01:09:27 +01:00
" WHERE NotCod=%ld AND UsrCod=%ld",
2016-01-24 13:46:57 +01:00
SocNot.NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryDELETE (Query,"can not unfavourite social note");
/***** Update number of times this social note is favourited *****/
SocNot.NumFavs = Soc_GetNumTimesANoteHasBeenFav (&SocNot);
2016-01-25 12:00:10 +01:00
/***** Mark possible notifications on this social note as removed *****/
2016-01-25 20:28:33 +01:00
OriginalPubCod = Soc_GetPubCodOfOriginalSocialNote (SocNot.NotCod);
if (OriginalPubCod > 0)
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_FAV,OriginalPubCod);
2016-01-25 12:00:10 +01:00
2016-01-24 13:46:57 +01:00
/***** Show the social note just unfavourited *****/
Soc_WriteSocialNote (&SocNot,
2016-01-25 14:40:57 +01:00
Soc_TOP_MESSAGE_UNFAVED,Gbl.Usrs.Me.UsrDat.UsrCod,
2016-01-24 13:46:57 +01:00
true,true);
}
2016-01-19 00:50:35 +01:00
}
2016-01-24 13:46:57 +01:00
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists);
2016-01-19 00:50:35 +01:00
return SocNot.NotCod;
}
2016-01-19 12:54:27 +01:00
/*****************************************************************************/
/***** Stop marking as favourite a previously favourited social comment *****/
/*****************************************************************************/
void Soc_UnfavSocialCommentGbl (void)
{
long NotCod;
/***** Stop marking as favourite a previously favourited social comment *****/
NotCod = Soc_UnfavSocialComment ();
/***** Write updated timeline after unfav (global) *****/
Soc_ShowTimelineGblHighlightingNot (NotCod);
}
void Soc_UnfavSocialCommentUsr (void)
{
long NotCod;
/***** 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-19 12:54:27 +01:00
/***** Start section *****/
fprintf (Gbl.F.Out,"<section id=\"timeline\">");
/***** Unfav a social comment previously marked as favourite *****/
NotCod = Soc_UnfavSocialComment ();
/***** Write updated timeline after unfav (user) *****/
Soc_ShowTimelineUsrHighlightingNot (NotCod);
/***** End section *****/
fprintf (Gbl.F.Out,"</section>");
}
static long Soc_UnfavSocialComment (void)
{
2016-01-24 13:46:57 +01:00
extern const char *Txt_The_comment_no_longer_exists;
2016-01-19 12:54:27 +01:00
struct SocialComment SocCom;
char Query[256];
2016-04-08 23:30:43 +02:00
/***** Initialize image *****/
Img_ImageConstructor (&SocCom.Image);
2016-01-19 12:54:27 +01:00
/***** Get data of social comment *****/
2016-01-25 12:32:13 +01:00
SocCom.PubCod = Soc_GetParamPubCod ();
2016-01-19 21:07:52 +01:00
Soc_GetDataOfSocialComByCod (&SocCom);
2016-01-19 12:54:27 +01:00
2016-01-25 12:32:13 +01:00
if (SocCom.PubCod > 0)
2016-01-19 12:54:27 +01:00
{
2016-01-24 13:46:57 +01:00
if (SocCom.NumFavs &&
Gbl.Usrs.Me.Logged &&
SocCom.UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) // I am not the author
2016-01-25 12:32:13 +01:00
if (Soc_CheckIfCommIsFavedByUsr (SocCom.PubCod,
2016-01-24 13:46:57 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod)) // I have favourited the comment
{
/***** Delete the mark as favourite from database *****/
sprintf (Query,"DELETE FROM social_comments_fav"
2017-03-24 01:09:27 +01:00
" WHERE PubCod=%ld AND UsrCod=%ld",
2016-01-25 12:32:13 +01:00
SocCom.PubCod,
2016-01-24 13:46:57 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryDELETE (Query,"can not unfavourite social comment");
/***** Update number of times this social comment is favourited *****/
SocCom.NumFavs = Soc_GetNumTimesACommHasBeenFav (&SocCom);
2016-01-25 12:00:10 +01:00
/***** Mark possible notifications on this social comment as removed *****/
2016-01-25 12:32:13 +01:00
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_FAV,SocCom.PubCod);
2016-01-25 12:00:10 +01:00
2016-01-24 13:46:57 +01:00
/***** Show the social comment just unfavourited *****/
Soc_WriteSocialComment (&SocCom,
2016-01-25 14:40:57 +01:00
Soc_TOP_MESSAGE_UNFAVED,Gbl.Usrs.Me.UsrDat.UsrCod,
2016-01-24 13:46:57 +01:00
true);
}
2016-01-19 12:54:27 +01:00
}
2016-01-24 13:46:57 +01:00
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists);
2016-01-19 12:54:27 +01:00
2016-04-08 23:30:43 +02:00
/***** Free image *****/
Img_ImageDestructor (&SocCom.Image);
2016-01-19 12:54:27 +01:00
return SocCom.NotCod;
}
2015-12-30 02:08:08 +01:00
/*****************************************************************************/
2016-01-08 01:53:37 +01:00
/******************* Request the removal of a social note ********************/
2015-12-30 16:33:36 +01:00
/*****************************************************************************/
2016-01-08 01:53:37 +01:00
void Soc_RequestRemSocialNoteGbl (void)
2016-01-02 01:56:48 +01:00
{
2016-01-08 01:53:37 +01:00
/***** Request the removal of social note *****/
Soc_RequestRemovalSocialNote ();
2016-01-02 01:56:48 +01:00
/***** Write timeline again (global) *****/
2017-02-24 03:38:18 +01:00
Soc_ShowTimelineGbl2 ();
2016-01-02 01:56:48 +01:00
}
2016-01-08 01:53:37 +01:00
void Soc_RequestRemSocialNoteUsr (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 *****/
fprintf (Gbl.F.Out,"<section id=\"timeline\">");
2016-01-08 01:53:37 +01:00
/***** Request the removal of social note *****/
Soc_RequestRemovalSocialNote ();
2016-01-02 01:56:48 +01:00
/***** Write timeline again (user) *****/
Soc_ShowTimelineUsr ();
2016-01-02 02:33:23 +01:00
/***** End section *****/
fprintf (Gbl.F.Out,"</section>");
2016-01-02 01:56:48 +01:00
}
2016-01-08 01:53:37 +01:00
static void Soc_RequestRemovalSocialNote (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;
2015-12-31 18:40:45 +01:00
struct SocialNote SocNot;
2015-12-30 16:33:36 +01:00
2015-12-31 14:25:28 +01:00
/***** Get data of social note *****/
2016-01-11 19:28:43 +01:00
SocNot.NotCod = Soc_GetParamNotCod ();
2016-01-19 21:07:52 +01:00
Soc_GetDataOfSocialNotByCod (&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
{
2016-01-24 13:46:57 +01:00
if (Gbl.Usrs.Me.Logged &&
SocNot.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // I am the author of this note
2016-01-02 01:56:48 +01:00
{
2017-04-28 12:52:58 +02:00
/***** Show question and button to remove social note *****/
/* 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
/* Show social note */
2016-01-19 00:50:35 +01:00
Soc_WriteSocialNote (&SocNot,
2016-01-24 13:46:57 +01:00
Soc_TOP_MESSAGE_NONE,-1L,
false,true);
2016-01-05 21:30:10 +01:00
2017-04-28 12:52:58 +02:00
/* End alert */
Gbl.Social.NotCod = SocNot.NotCod; // Social note to be removed
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
2017-05-11 23:45:46 +02:00
Ale_ShowAlertAndButton2 (ActRemSocPubUsr,"timeline",
2017-04-28 12:52:58 +02:00
Soc_PutParamsRemoveSocialNote,
Lay_REMOVE_BUTTON,Txt_Remove);
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlertAndButton2 (ActRemSocPubGbl,NULL,
2017-04-28 12:52:58 +02:00
Soc_PutParamsRemoveSocialNote,
Lay_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
2017-05-11 23:45:46 +02: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
/*****************************************************************************/
/****************** Put parameters to remove a social note *******************/
/*****************************************************************************/
static void Soc_PutParamsRemoveSocialNote (void)
{
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
Usr_PutParamOtherUsrCodEncrypted ();
else
Soc_PutParamWhichUsrs ();
Soc_PutHiddenParamNotCod (Gbl.Social.NotCod);
}
2015-12-30 16:33:36 +01:00
/*****************************************************************************/
2016-01-07 00:42:35 +01:00
/*************************** Remove a social note ****************************/
2015-12-30 02:08:08 +01:00
/*****************************************************************************/
2016-01-08 01:53:37 +01:00
void Soc_RemoveSocialNoteGbl (void)
2016-01-02 01:56:48 +01:00
{
2016-01-07 00:42:35 +01:00
/***** Remove a social note *****/
Soc_RemoveSocialNote ();
2016-01-02 01:56:48 +01:00
/***** Write updated timeline after removing (global) *****/
2017-02-24 03:38:18 +01:00
Soc_ShowTimelineGbl2 ();
2016-01-02 01:56:48 +01:00
}
2016-01-08 01:53:37 +01:00
void Soc_RemoveSocialNoteUsr (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 *****/
fprintf (Gbl.F.Out,"<section id=\"timeline\">");
2016-01-07 00:42:35 +01:00
/***** Remove a social note *****/
Soc_RemoveSocialNote ();
2016-01-02 01:56:48 +01:00
/***** Write updated timeline after removing (user) *****/
Soc_ShowTimelineUsr ();
2016-01-02 02:33:23 +01:00
/***** End section *****/
fprintf (Gbl.F.Out,"</section>");
2016-01-02 01:56:48 +01:00
}
2016-01-07 00:42:35 +01:00
static void Soc_RemoveSocialNote (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;
2016-01-16 02:54:13 +01:00
extern const char *Txt_Post_removed;
2015-12-31 18:40:45 +01:00
struct SocialNote SocNot;
2015-12-30 02:08:08 +01:00
2015-12-31 14:25:28 +01:00
/***** Get data of social note *****/
2016-01-11 19:28:43 +01:00
SocNot.NotCod = Soc_GetParamNotCod ();
2016-01-19 21:07:52 +01:00
Soc_GetDataOfSocialNotByCod (&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
{
2016-01-24 13:46:57 +01:00
if (Gbl.Usrs.Me.Logged &&
SocNot.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // I am the author of this note
{
2016-04-08 20:21:33 +02:00
if (SocNot.NoteType == Soc_NOTE_SOCIAL_POST)
/***** Remove image file associated to social post *****/
Soc_RemoveImgFileFromSocialPost (SocNot.Cod);
/***** Delete social note from database *****/
2016-01-24 13:46:57 +01:00
Soc_RemoveASocialNoteFromDB (&SocNot);
2015-12-30 16:33:36 +01:00
2016-01-24 13:46:57 +01:00
/***** Message of success *****/
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_SUCCESS,Txt_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
2017-05-11 23:45:46 +02: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-01-01 20:19:43 +01:00
/*****************************************************************************/
2016-04-08 20:21:33 +02:00
/************** Remove one file associated to a social post ******************/
/*****************************************************************************/
static void Soc_RemoveImgFileFromSocialPost (long PstCod)
{
char Query[128];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
/***** Get name of image associated to a social post from database *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT ImageName FROM social_posts WHERE PstCod=%ld",
2016-04-08 20:21:33 +02:00
PstCod);
if (DB_QuerySELECT (Query,&mysql_res,"can not get image"))
{
/***** Get image name (row[0]) *****/
row = mysql_fetch_row (mysql_res);
/***** Remove image file *****/
Img_RemoveImageFile (row[0]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
2016-01-08 01:53:37 +01:00
/******************* Remove a social note from database **********************/
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2016-01-08 01:53:37 +01:00
static void Soc_RemoveASocialNoteFromDB (struct SocialNote *SocNot)
2016-01-01 20:19:43 +01:00
{
2016-01-25 18:57:37 +01:00
char Query[512];
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;
2016-01-24 14:26:35 +01:00
2016-01-25 18:57:37 +01:00
/***** Mark possible notifications on the publishings
2016-01-24 14:26:35 +01:00
of this social note as removed *****/
2016-01-25 20:28:33 +01:00
/* Mark notifications of the original social note as removed */
PubCod = Soc_GetPubCodOfOriginalSocialNote (SocNot->NotCod);
if (PubCod > 0)
{
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_COMMENT,PubCod);
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_FAV ,PubCod);
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_SHARE ,PubCod);
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_MENTION,PubCod);
}
2016-01-24 14:26:35 +01:00
2016-01-25 20:28:33 +01:00
/* Get comments of this social note */
sprintf (Query,"SELECT PubCod FROM social_pubs"
2017-03-24 01:09:27 +01:00
" WHERE NotCod=%ld AND PubType=%u",
2016-01-25 20:28:33 +01:00
SocNot->NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
NumComments = DB_QuerySELECT (Query,&mysql_res,"can not get social comments");
/* For each comment... */
for (NumCom = 0;
NumCom < NumComments;
NumCom++)
2016-01-24 14:26:35 +01:00
{
/* Get code of social comment **/
row = mysql_fetch_row (mysql_res);
PubCod = Str_ConvertStrCodToLongCod (row[0]);
/* Mark notifications as removed */
if (PubCod > 0)
{
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_COMMENT,PubCod);
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_FAV ,PubCod);
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_MENTION,PubCod);
}
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
2016-01-01 20:19:43 +01:00
2016-01-20 15:19:02 +01:00
/***** Remove favs *****/
/* Remove favs for all comments in this note */
2016-01-20 14:29:42 +01:00
sprintf (Query,"DELETE FROM social_comments_fav"
2016-01-20 15:19:02 +01:00
" USING social_pubs,social_comments_fav"
2017-03-24 01:09:27 +01:00
" WHERE social_pubs.NotCod=%ld"
" AND social_pubs.PubType=%u"
2016-01-25 12:32:13 +01:00
" AND social_pubs.PubCod=social_comments_fav.PubCod",
2016-01-20 15:19:02 +01:00
SocNot->NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
2016-01-20 14:29:42 +01:00
DB_QueryDELETE (Query,"can not remove favs for social note");
2016-01-20 15:19:02 +01:00
/* Remove favs for this note */
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM social_notes_fav WHERE NotCod=%ld",
2016-01-19 09:34:01 +01:00
SocNot->NotCod);
DB_QueryDELETE (Query,"can not remove favs for social note");
2016-01-12 01:56:58 +01:00
/***** Remove content of the comments of this social note *****/
2016-01-12 19:24:29 +01:00
sprintf (Query,"DELETE FROM social_comments"
" USING social_pubs,social_comments"
2017-03-24 01:09:27 +01:00
" WHERE social_pubs.NotCod=%ld"
" AND social_pubs.PubType=%u"
2016-01-25 12:32:13 +01:00
" AND social_pubs.PubCod=social_comments.PubCod",
2016-01-12 01:56:58 +01:00
SocNot->NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
DB_QueryDELETE (Query,"can not remove social comments");
2016-01-06 22:16:08 +01:00
/***** Remove all the social publishings of this note *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM social_pubs WHERE NotCod=%ld",
2016-01-11 14:42:54 +01:00
SocNot->NotCod);
2016-01-01 20:19:43 +01:00
DB_QueryDELETE (Query,"can not remove a social publishing");
2016-01-06 22:16:08 +01:00
/***** Remove social note *****/
sprintf (Query,"DELETE FROM social_notes"
2017-03-24 01:09:27 +01:00
" WHERE NotCod=%ld"
" AND UsrCod=%ld", // Extra check: I am the author
2016-01-06 22:16:08 +01:00
SocNot->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryDELETE (Query,"can not remove a social note");
2016-01-02 14:36:34 +01:00
2016-01-06 22:16:08 +01:00
if (SocNot->NoteType == Soc_NOTE_SOCIAL_POST)
2016-01-01 20:19:43 +01:00
{
2016-01-06 22:16:08 +01:00
/***** Remove social post *****/
sprintf (Query,"DELETE FROM social_posts"
2017-03-24 01:09:27 +01:00
" WHERE PstCod=%ld",
2016-01-06 22:16:08 +01:00
SocNot->Cod);
DB_QueryDELETE (Query,"can not remove a social post");
2016-01-01 20:19:43 +01:00
}
2016-01-06 22:16:08 +01:00
/***** Reset social note *****/
Soc_ResetSocialNote (SocNot);
2016-01-01 20:19:43 +01:00
}
2016-01-25 20:28:33 +01:00
/*****************************************************************************/
/******************* Get code of social note of a publishing *****************/
/*****************************************************************************/
static long Soc_GetNotCodOfSocialPublishing (long PubCod)
{
char Query[128];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long NotCod = -1L;
/***** Get code of social note from database *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT NotCod FROM social_pubs WHERE PubCod=%ld",
2016-01-25 20:28:33 +01:00
PubCod);
if (DB_QuerySELECT (Query,&mysql_res,"can not get code of social note") == 1) // Result should have a unique row
{
/* Get code of social note */
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
/*****************************************************************************/
2016-01-24 14:26:35 +01:00
/************ Get code of social publishing of the original note *************/
/*****************************************************************************/
static long Soc_GetPubCodOfOriginalSocialNote (long NotCod)
{
char Query[256];
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
/***** Get code of social publishing of the original note *****/
sprintf (Query,"SELECT PubCod FROM social_pubs"
2017-03-24 01:09:27 +01:00
" WHERE NotCod=%ld AND PubType=%u",
2016-01-24 14:26:35 +01:00
NotCod,(unsigned) Soc_PUB_ORIGINAL_NOTE);
if (DB_QuerySELECT (Query,&mysql_res,"can not get code of social publishing") == 1) // Result should have a unique row
{
/* Get code of social publishing (row[0]) */
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
}
/*****************************************************************************/
2016-01-08 01:53:37 +01:00
/************* Request the removal of a comment in a social note *************/
/*****************************************************************************/
void Soc_RequestRemSocialComGbl (void)
{
/***** Request the removal of comment in social note *****/
Soc_RequestRemovalSocialComment ();
/***** Write timeline again (global) *****/
2017-02-24 03:38:18 +01:00
Soc_ShowTimelineGbl2 ();
2016-01-08 01:53:37 +01:00
}
void Soc_RequestRemSocialComUsr (void)
{
/***** 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 *****/
fprintf (Gbl.F.Out,"<section id=\"timeline\">");
/***** Request the removal of comment in social note *****/
Soc_RequestRemovalSocialComment ();
/***** Write timeline again (user) *****/
Soc_ShowTimelineUsr ();
/***** End section *****/
fprintf (Gbl.F.Out,"</section>");
}
static void Soc_RequestRemovalSocialComment (void)
{
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;
struct SocialComment SocCom;
2016-04-08 23:30:43 +02:00
/***** Initialize image *****/
Img_ImageConstructor (&SocCom.Image);
2016-01-08 01:53:37 +01:00
/***** Get data of social comment *****/
2016-01-25 14:40:57 +01:00
SocCom.PubCod = Soc_GetParamPubCod ();
2016-01-19 21:07:52 +01:00
Soc_GetDataOfSocialComByCod (&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
{
2016-01-24 13:46:57 +01:00
if (Gbl.Usrs.Me.Logged &&
SocCom.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // I am the author of this comment
2016-01-08 01:53:37 +01:00
{
2017-04-28 12:38:05 +02:00
/***** Show question and button to remove social comment *****/
/* 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
2016-01-24 13:46:57 +01:00
/* Show social comment */
Soc_WriteSocialComment (&SocCom,
Soc_TOP_MESSAGE_NONE,-1L,
true);
2017-04-28 12:38:05 +02:00
/* End alert */
2017-04-28 12:52:58 +02:00
Gbl.Social.PubCod = SocCom.PubCod; // Social publishing to be removed
2017-04-28 12:38:05 +02:00
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
2017-05-11 23:45:46 +02:00
Ale_ShowAlertAndButton2 (ActRemSocComUsr,"timeline",
2017-04-28 12:38:05 +02:00
Soc_PutParamsRemoveSocialCommment,
Lay_REMOVE_BUTTON,Txt_Remove);
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlertAndButton2 (ActRemSocComGbl,NULL,
2017-04-28 12:38:05 +02:00
Soc_PutParamsRemoveSocialCommment,
Lay_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
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists);
2016-04-08 23:30:43 +02:00
/***** Free image *****/
Img_ImageDestructor (&SocCom.Image);
2016-01-08 01:53:37 +01:00
}
2017-04-28 12:38:05 +02:00
/*****************************************************************************/
/***************** Put parameters to remove a social comment *****************/
/*****************************************************************************/
static void Soc_PutParamsRemoveSocialCommment (void)
{
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
Usr_PutParamOtherUsrCodEncrypted ();
else
Soc_PutParamWhichUsrs ();
Soc_PutHiddenParamPubCod (Gbl.Social.PubCod);
}
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
/************************** Remove a social comment **************************/
/*****************************************************************************/
void Soc_RemoveSocialComGbl (void)
{
/***** Remove a social comment *****/
Soc_RemoveSocialComment ();
/***** Write updated timeline after removing (global) *****/
2017-02-24 03:38:18 +01:00
Soc_ShowTimelineGbl2 ();
2016-01-08 01:53:37 +01:00
}
void Soc_RemoveSocialComUsr (void)
{
/***** 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 *****/
fprintf (Gbl.F.Out,"<section id=\"timeline\">");
/***** Remove a social comment *****/
Soc_RemoveSocialComment ();
/***** Write updated timeline after removing (user) *****/
Soc_ShowTimelineUsr ();
/***** End section *****/
fprintf (Gbl.F.Out,"</section>");
}
static void Soc_RemoveSocialComment (void)
{
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;
2016-01-08 01:53:37 +01:00
struct SocialComment SocCom;
2016-04-08 23:30:43 +02:00
/***** Initialize image *****/
Img_ImageConstructor (&SocCom.Image);
2016-01-08 01:53:37 +01:00
/***** Get data of social comment *****/
2016-01-25 14:40:57 +01:00
SocCom.PubCod = Soc_GetParamPubCod ();
2016-01-19 21:07:52 +01:00
Soc_GetDataOfSocialComByCod (&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
{
2016-01-24 13:46:57 +01:00
if (Gbl.Usrs.Me.Logged &&
SocCom.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // I am the author of this comment
{
2016-04-08 23:30:43 +02:00
/***** Remove image file associated to social post *****/
Soc_RemoveImgFileFromSocialComment (SocCom.PubCod);
2016-01-24 13:46:57 +01:00
/***** Delete social comment from database *****/
Soc_RemoveASocialCommentFromDB (&SocCom);
2016-01-08 01:53:37 +01:00
2016-01-24 13:46:57 +01:00
/***** Message of success *****/
2017-05-11 23:45:46 +02: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
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists);
2016-04-08 23:30:43 +02:00
/***** Free image *****/
Img_ImageDestructor (&SocCom.Image);
}
/*****************************************************************************/
/************* Remove one file associated to a social comment ****************/
/*****************************************************************************/
static void Soc_RemoveImgFileFromSocialComment (long PubCod)
{
char Query[128];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
/***** Get name of image associated to a social post from database *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"SELECT ImageName FROM social_comments WHERE PubCod=%ld",
2016-04-08 23:30:43 +02:00
PubCod);
if (DB_QuerySELECT (Query,&mysql_res,"can not get image"))
{
/***** Get image name (row[0]) *****/
row = mysql_fetch_row (mysql_res);
/***** Remove image file *****/
Img_RemoveImageFile (row[0]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-01-08 01:53:37 +01:00
}
/*****************************************************************************/
/****************** Remove a social comment from database ********************/
/*****************************************************************************/
static void Soc_RemoveASocialCommentFromDB (struct SocialComment *SocCom)
{
char Query[128];
2016-01-24 14:48:08 +01:00
/***** Mark possible notifications on this comment as removed *****/
2016-01-25 12:32:13 +01:00
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_COMMENT,SocCom->PubCod);
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_FAV ,SocCom->PubCod);
Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_MENTION,SocCom->PubCod);
2016-01-24 14:48:08 +01:00
2016-01-20 14:29:42 +01:00
/***** Remove favs for this comment *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM social_comments_fav WHERE PubCod=%ld",
2016-01-25 12:32:13 +01:00
SocCom->PubCod);
2016-01-20 14:29:42 +01:00
DB_QueryDELETE (Query,"can not remove favs for social comment");
2016-01-08 01:53:37 +01:00
/***** Remove content of this social comment *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM social_comments WHERE PubCod=%ld",
2016-01-25 12:32:13 +01:00
SocCom->PubCod);
2016-01-08 01:53:37 +01:00
DB_QueryDELETE (Query,"can not remove a social comment");
/***** Remove this social comment *****/
2016-01-12 19:18:56 +01:00
sprintf (Query,"DELETE FROM social_pubs"
2017-03-24 01:09:27 +01:00
" WHERE PubCod=%ld"
" AND PublisherCod=%ld" // Extra check: I am the author
" AND PubType=%u", // Extra check: it's a comment
2016-01-25 12:32:13 +01:00
SocCom->PubCod,
2016-01-12 01:56:58 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Soc_PUB_COMMENT_TO_NOTE);
2016-01-08 01:53:37 +01:00
DB_QueryDELETE (Query,"can not remove a social comment");
/***** Reset social comment *****/
Soc_ResetSocialComment (SocCom);
}
2016-01-08 10:13:28 +01:00
/*****************************************************************************/
2016-01-11 14:42:54 +01:00
/********** Remove all the social content of a user from database ************/
2016-01-08 10:13:28 +01:00
/*****************************************************************************/
void Soc_RemoveUsrSocialContent (long UsrCod)
{
char Query[512];
2016-01-20 14:29:42 +01:00
/***** Remove favs for comments *****/
/* Remove all favs made by this user in any social comment */
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM social_comments_fav WHERE UsrCod=%ld",
2016-01-20 14:29:42 +01:00
UsrCod);
DB_QueryDELETE (Query,"can not remove favs");
/* Remove all favs for all comments of this user */
sprintf (Query,"DELETE FROM social_comments_fav"
2016-01-20 15:19:02 +01:00
" USING social_pubs,social_comments_fav"
2017-03-24 01:09:27 +01:00
" WHERE social_pubs.PublisherCod=%ld" // Author of the comment
" AND social_pubs.PubType=%u"
2016-01-25 12:32:13 +01:00
" AND social_pubs.PubCod=social_comments_fav.PubCod",
2016-01-20 15:19:02 +01:00
UsrCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
2016-01-20 14:29:42 +01:00
DB_QueryDELETE (Query,"can not remove favs");
/* Remove all favs for all comments in all the social notes of the user */
sprintf (Query,"DELETE FROM social_comments_fav"
2016-01-20 15:19:02 +01:00
" USING social_notes,social_pubs,social_comments_fav"
2017-03-24 01:09:27 +01:00
" WHERE social_notes.UsrCod=%ld" // Author of the note
2016-01-20 15:19:02 +01:00
" AND social_notes.NotCod=social_pubs.NotCod"
2017-03-24 01:09:27 +01:00
" AND social_pubs.PubType=%u"
2016-01-25 12:32:13 +01:00
" AND social_pubs.PubCod=social_comments_fav.PubCod",
2016-01-20 15:19:02 +01:00
UsrCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
2016-01-20 14:29:42 +01:00
DB_QueryDELETE (Query,"can not remove social comments");
/***** Remove favs for notes *****/
2016-01-19 09:34:01 +01:00
/* Remove all favs made by this user in any social note */
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM social_notes_fav WHERE UsrCod=%ld",
2016-01-19 09:34:01 +01:00
UsrCod);
2016-01-20 14:29:42 +01:00
DB_QueryDELETE (Query,"can not remove favs");
2016-01-19 09:34:01 +01:00
/* Remove all favs for all notes of this user */
sprintf (Query,"DELETE FROM social_notes_fav"
" USING social_notes,social_notes_fav"
2017-03-24 01:09:27 +01:00
" WHERE social_notes.UsrCod=%ld" // Author of the note
2016-01-19 09:34:01 +01:00
" AND social_notes.NotCod=social_notes_fav.NotCod",
UsrCod);
2016-01-20 14:29:42 +01:00
DB_QueryDELETE (Query,"can not remove favs");
2016-01-19 09:34:01 +01:00
2016-01-08 10:13:28 +01:00
/***** Remove social comments *****/
/* Remove content of all the comments in all the social notes of the user */
2016-01-12 19:24:29 +01:00
sprintf (Query,"DELETE FROM social_comments"
2016-01-20 15:19:02 +01:00
" USING social_notes,social_pubs,social_comments"
2017-03-24 01:09:27 +01:00
" WHERE social_notes.UsrCod=%ld"
2016-01-20 15:19:02 +01:00
" AND social_notes.NotCod=social_pubs.NotCod"
2017-03-24 01:09:27 +01:00
" AND social_pubs.PubType=%u"
2016-01-25 12:32:13 +01:00
" AND social_pubs.PubCod=social_comments.PubCod",
2016-01-12 01:56:58 +01:00
UsrCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
2016-01-08 10:13:28 +01:00
DB_QueryDELETE (Query,"can not remove social comments");
2016-01-12 01:56:58 +01:00
/* Remove all the comments from any user in any social note of the user */
2016-01-12 19:18:56 +01:00
sprintf (Query,"DELETE FROM social_pubs"
2016-01-20 15:19:02 +01:00
" USING social_notes,social_pubs"
2017-03-24 01:09:27 +01:00
" WHERE social_notes.UsrCod=%ld"
2016-01-20 15:19:02 +01:00
" AND social_notes.NotCod=social_pubs.NotCod"
2017-03-24 01:09:27 +01:00
" AND social_pubs.PubType=%u",
2016-01-12 01:56:58 +01:00
UsrCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
2016-01-08 10:13:28 +01:00
DB_QueryDELETE (Query,"can not remove social comments");
/* Remove content of all the comments of the user in any social note */
2016-01-12 19:24:29 +01:00
sprintf (Query,"DELETE FROM social_comments"
" USING social_pubs,social_comments"
2017-03-24 01:09:27 +01:00
" WHERE social_pubs.PublisherCod=%ld"
" AND social_pubs.PubType=%u"
2016-01-25 12:32:13 +01:00
" AND social_pubs.PubCod=social_comments.PubCod",
2016-01-12 01:56:58 +01:00
UsrCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
2016-01-08 10:13:28 +01:00
DB_QueryDELETE (Query,"can not remove social comments");
/***** Remove all the social posts of the user *****/
sprintf (Query,"DELETE FROM social_posts"
" WHERE PstCod IN"
" (SELECT Cod FROM social_notes"
2017-03-24 01:09:27 +01:00
" WHERE UsrCod=%ld AND NoteType=%u)",
2016-01-08 10:13:28 +01:00
UsrCod,(unsigned) Soc_NOTE_SOCIAL_POST);
DB_QueryDELETE (Query,"can not remove social posts");
2016-01-12 01:56:58 +01:00
/***** Remove all the social publishings of any user authored by the user *****/
2016-01-12 19:18:56 +01:00
sprintf (Query,"DELETE FROM social_pubs"
" USING social_notes,social_pubs"
2017-03-24 01:09:27 +01:00
" WHERE social_notes.UsrCod=%ld"
2016-01-12 19:18:56 +01:00
" AND social_notes.NotCod=social_pubs.NotCod",
2016-01-11 14:42:54 +01:00
UsrCod);
DB_QueryDELETE (Query,"can not remove social publishings");
2016-01-12 01:56:58 +01:00
/***** Remove all the social publishings of the user *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM social_pubs WHERE PublisherCod=%ld",
2016-01-11 14:42:54 +01:00
UsrCod);
2016-01-08 10:13:28 +01:00
DB_QueryDELETE (Query,"can not remove social publishings");
/***** Remove all the social notes of the user *****/
2017-03-24 01:09:27 +01:00
sprintf (Query,"DELETE FROM social_notes WHERE UsrCod=%ld",
2016-01-08 10:13:28 +01:00
UsrCod);
DB_QueryDELETE (Query,"can not remove social notes");
}
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2016-01-04 17:36:28 +01:00
/**************** Check if a user has published a social note ****************/
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2016-01-24 13:46:57 +01:00
static bool Soc_CheckIfNoteIsSharedByUsr (long NotCod,long UsrCod)
2016-01-01 20:19:43 +01:00
{
2016-01-11 20:54:14 +01:00
char Query[256];
2016-01-01 20:19:43 +01:00
2016-01-12 19:18:56 +01:00
sprintf (Query,"SELECT COUNT(*) FROM social_pubs"
2017-03-24 01:09:27 +01:00
" WHERE NotCod=%ld AND PublisherCod=%ld AND PubType=%u",
2016-01-24 13:46:57 +01:00
NotCod,UsrCod,(unsigned) Soc_PUB_SHARED_NOTE);
return (DB_QueryCOUNT (Query,"can not check if a user has shared a social note") != 0);
2016-01-01 20:19:43 +01:00
}
2016-01-19 00:50:35 +01:00
/*****************************************************************************/
/*************** Check if a user has favourited a social note ****************/
/*****************************************************************************/
2016-01-24 13:46:57 +01:00
static bool Soc_CheckIfNoteIsFavedByUsr (long NotCod,long UsrCod)
2016-01-19 00:50:35 +01:00
{
char Query[256];
sprintf (Query,"SELECT COUNT(*) FROM social_notes_fav"
2017-03-24 01:09:27 +01:00
" WHERE NotCod=%ld AND UsrCod=%ld",
2016-01-19 00:50:35 +01:00
NotCod,UsrCod);
return (DB_QueryCOUNT (Query,"can not check if a user has favourited a social note") != 0);
}
2016-01-19 12:54:27 +01:00
/*****************************************************************************/
/************* Check if a user has favourited a social comment ***************/
/*****************************************************************************/
2016-01-25 12:32:13 +01:00
static bool Soc_CheckIfCommIsFavedByUsr (long PubCod,long UsrCod)
2016-01-19 12:54:27 +01:00
{
char Query[256];
sprintf (Query,"SELECT COUNT(*) FROM social_comments_fav"
2017-03-24 01:09:27 +01:00
" WHERE PubCod=%ld AND UsrCod=%ld",
2016-01-25 12:32:13 +01:00
PubCod,UsrCod);
2016-01-19 12:54:27 +01:00
return (DB_QueryCOUNT (Query,"can not check if a user has favourited a social comment") != 0);
}
2016-01-04 11:58:36 +01:00
/*****************************************************************************/
2016-01-19 21:07:52 +01:00
/******* Get number of times a social note has been shared in timeline *******/
2016-01-04 11:58:36 +01:00
/*****************************************************************************/
2016-01-19 21:07:52 +01:00
static unsigned Soc_UpdateNumTimesANoteHasBeenShared (struct SocialNote *SocNot)
2016-01-04 11:58:36 +01:00
{
2016-01-11 20:54:14 +01:00
char Query[256];
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 *****/
2016-01-12 19:18:56 +01:00
sprintf (Query,"SELECT COUNT(*) FROM social_pubs"
2017-03-24 01:09:27 +01:00
" WHERE NotCod=%ld"
" AND PublisherCod<>%ld"
" AND PubType=%u",
2016-01-04 14:49:10 +01:00
SocNot->NotCod,
2016-01-11 20:54:14 +01:00
SocNot->UsrCod, // The author
(unsigned) Soc_PUB_SHARED_NOTE);
2016-01-19 21:07:52 +01:00
return (unsigned) DB_QueryCOUNT (Query,"can not get number of times a note has been shared");
2016-01-04 14:49:10 +01:00
}
2016-01-19 00:50:35 +01:00
/*****************************************************************************/
2016-01-19 21:07:52 +01:00
/*********** Get number of times a social note has been favourited ***********/
2016-01-19 00:50:35 +01:00
/*****************************************************************************/
2016-01-19 21:07:52 +01:00
static unsigned Soc_GetNumTimesANoteHasBeenFav (struct SocialNote *SocNot)
2016-01-19 00:50:35 +01:00
{
char Query[256];
/***** Get number of times (users) this note has been favourited *****/
sprintf (Query,"SELECT COUNT(*) FROM social_notes_fav"
2017-03-24 01:09:27 +01:00
" WHERE NotCod=%ld"
" AND UsrCod<>%ld", // Extra check
2016-01-19 00:50:35 +01:00
SocNot->NotCod,
SocNot->UsrCod); // The author
2016-01-19 21:07:52 +01:00
return (unsigned) DB_QueryCOUNT (Query,"can not get number of times a note has been favourited");
}
/*****************************************************************************/
/********* Get number of times a social comment has been favourited **********/
/*****************************************************************************/
static unsigned Soc_GetNumTimesACommHasBeenFav (struct SocialComment *SocCom)
{
char Query[256];
/***** Get number of times (users) this comment has been favourited *****/
sprintf (Query,"SELECT COUNT(*) FROM social_comments_fav"
2017-03-24 01:09:27 +01:00
" WHERE PubCod=%ld"
" AND UsrCod<>%ld", // Extra check
2016-01-25 12:32:13 +01:00
SocCom->PubCod,
2016-01-19 21:07:52 +01:00
SocCom->UsrCod); // The author
return (unsigned) DB_QueryCOUNT (Query,"can not get number of times a comment has been favourited");
2016-01-19 00:50:35 +01:00
}
2016-01-04 14:49:10 +01:00
/*****************************************************************************/
/**************** Show users who have shared this social note ****************/
/*****************************************************************************/
static void Soc_ShowUsrsWhoHaveSharedSocialNote (const struct SocialNote *SocNot)
{
char Query[256];
2016-01-19 01:31:35 +01:00
/***** Get users who have shared this note *****/
2016-01-19 21:07:52 +01:00
sprintf (Query,"SELECT PublisherCod FROM social_pubs"
2017-03-24 01:09:27 +01:00
" WHERE NotCod=%ld"
" AND PublisherCod<>%ld"
" AND PubType=%u"
2016-01-19 01:31:35 +01:00
" ORDER BY PubCod LIMIT %u",
SocNot->NotCod,
SocNot->UsrCod,
(unsigned) Soc_PUB_SHARED_NOTE,
Soc_MAX_SHARERS_FAVERS_SHOWN);
Soc_ShowSharersOrFavers (SocNot->NumShared,Query);
}
2016-01-04 14:49:10 +01:00
2016-01-19 01:31:35 +01:00
/*****************************************************************************/
/********* Show users who have marked this social note as favourite **********/
/*****************************************************************************/
2016-01-04 14:49:10 +01:00
2016-01-19 01:31:35 +01:00
static void Soc_ShowUsrsWhoHaveMarkedSocialNoteAsFav (const struct SocialNote *SocNot)
{
char Query[256];
2016-01-04 14:49:10 +01:00
2016-01-19 21:07:52 +01:00
/***** Get users who have marked this note as favourite *****/
sprintf (Query,"SELECT UsrCod FROM social_notes_fav"
2017-03-24 01:09:27 +01:00
" WHERE NotCod=%ld"
" AND UsrCod<>%ld" // Extra check
2016-01-19 09:23:55 +01:00
" ORDER BY FavCod LIMIT %u",
2016-01-19 01:31:35 +01:00
SocNot->NotCod,
SocNot->UsrCod,
Soc_MAX_SHARERS_FAVERS_SHOWN);
Soc_ShowSharersOrFavers (SocNot->NumFavs,Query);
2016-01-04 11:58:36 +01:00
}
2016-01-19 21:07:52 +01:00
/*****************************************************************************/
/********* Show users who have marked this social note as favourite **********/
/*****************************************************************************/
static void Soc_ShowUsrsWhoHaveMarkedSocialCommAsFav (const struct SocialComment *SocCom)
{
char Query[256];
/***** Get users who have marked this comment as favourite *****/
sprintf (Query,"SELECT UsrCod FROM social_comments_fav"
2017-03-24 01:09:27 +01:00
" WHERE PubCod=%ld"
" AND UsrCod<>%ld" // Extra check
2016-01-19 21:07:52 +01:00
" ORDER BY FavCod LIMIT %u",
2016-01-25 12:32:13 +01:00
SocCom->PubCod,
2016-01-19 21:07:52 +01:00
SocCom->UsrCod,
Soc_MAX_SHARERS_FAVERS_SHOWN);
Soc_ShowSharersOrFavers (SocCom->NumFavs,Query);
}
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
/*****************************************************************************/
// All forms in this function and nested functions must have unique identifiers
2016-01-19 01:31:35 +01:00
static void Soc_ShowSharersOrFavers (unsigned NumUsrs,const char *Query)
2016-01-19 01:12:20 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-01-19 01:31:35 +01:00
unsigned NumFirstUsrs;
2016-01-19 01:12:20 +01:00
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
/***** Show number of users who have marked this social note as favourite *****/
fprintf (Gbl.F.Out,"<span class=\"SOCIAL_NUM_SHARES_FAVS\"> %u</span>",
2016-01-19 01:31:35 +01:00
NumUsrs);
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
{
2016-01-19 01:31:35 +01:00
/***** Get list of users from database *****/
NumFirstUsrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get users");
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 *****/
row = mysql_fetch_row (mysql_res);
/* Get user's code (row[0]) */
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/***** Get user's data and show user's photo *****/
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat))
{
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_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,
2016-01-20 09:33:45 +01:00
"PHOTO15x20",Pho_ZOOM,true); // Use unique id
2016-01-19 01:12:20 +01:00
fprintf (Gbl.F.Out,"</div>");
NumUsrsShown++;
}
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
2016-01-23 01:38:55 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-01-19 01:31:35 +01:00
if (NumUsrs > NumUsrsShown)
2016-01-19 01:12:20 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_SHARER\">"
"<img src=\"%s/ellipsis32x32.gif\""
" alt=\"%u\" title=\"%u\""
2016-11-14 10:05:41 +01:00
" class=\"ICO20x20\" />"
2016-01-19 01:12:20 +01:00
"</div>",
Gbl.Prefs.IconsURL,
2016-01-19 01:31:35 +01:00
NumUsrs - NumUsrsShown,
NumUsrs - NumUsrsShown);
2016-01-19 01:12:20 +01:00
}
}
2015-12-31 18:40:45 +01:00
/*****************************************************************************/
/**************** Get data of social note using its code *********************/
/*****************************************************************************/
2016-01-19 21:07:52 +01:00
static void Soc_GetDataOfSocialNotByCod (struct SocialNote *SocNot)
2015-12-30 12:40:13 +01:00
{
char Query[256];
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
{
2016-01-11 02:15:23 +01:00
/***** Get data of social note from database *****/
2016-01-11 20:54:14 +01:00
sprintf (Query,"SELECT NotCod,NoteType,Cod,UsrCod,HieCod,Unavailable,UNIX_TIMESTAMP(TimeNote)"
2016-01-11 02:15:23 +01:00
" FROM social_notes"
2017-03-24 01:09:27 +01:00
" WHERE NotCod=%ld",
2016-01-11 02:15:23 +01:00
SocNot->NotCod);
if (DB_QuerySELECT (Query,&mysql_res,"can not get data of social note"))
{
/***** Get data of social note *****/
row = mysql_fetch_row (mysql_res);
Soc_GetDataOfSocialNoteFromRow (row,SocNot);
}
else
/***** Reset fields of social note *****/
Soc_ResetSocialNote (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
2015-12-31 14:25:28 +01:00
/***** Reset fields of social note *****/
2016-01-05 04:54:00 +01:00
Soc_ResetSocialNote (SocNot);
2015-12-30 12:40:13 +01:00
}
2015-12-30 16:33:36 +01:00
/*****************************************************************************/
2016-01-08 01:53:37 +01:00
/*************** Get data of social comment using its code *******************/
/*****************************************************************************/
2016-01-19 21:07:52 +01:00
static void Soc_GetDataOfSocialComByCod (struct SocialComment *SocCom)
2016-01-08 01:53:37 +01:00
{
2017-03-13 14:22:36 +01:00
char Query[1024];
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
{
2016-01-11 02:15:23 +01:00
/***** Get data of social comment from database *****/
2016-01-12 19:18:56 +01:00
sprintf (Query,"SELECT social_pubs.PubCod,social_pubs.PublisherCod,"
"social_pubs.NotCod,"
"UNIX_TIMESTAMP(social_pubs.TimePublish),"
2016-04-08 23:30:43 +02:00
"social_comments.Content,"
2016-04-15 02:33:16 +02:00
"social_comments.ImageName,"
"social_comments.ImageTitle,"
2016-04-16 18:21:06 +02:00
"social_comments.ImageURL"
2016-01-12 19:24:29 +01:00
" FROM social_pubs,social_comments"
2017-03-24 01:09:27 +01:00
" WHERE social_pubs.PubCod=%ld"
" AND social_pubs.PubType=%u"
2016-01-25 12:32:13 +01:00
" AND social_pubs.PubCod=social_comments.PubCod",
SocCom->PubCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
2016-01-11 02:15:23 +01:00
if (DB_QuerySELECT (Query,&mysql_res,"can not get data of social comment"))
{
/***** Get data of social comment *****/
row = mysql_fetch_row (mysql_res);
Soc_GetDataOfSocialCommentFromRow (row,SocCom);
}
else
/***** Reset fields of social comment *****/
Soc_ResetSocialComment (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
/***** Reset fields of social comment *****/
Soc_ResetSocialComment (SocCom);
}
/*****************************************************************************/
/************** Get data of social publishing using its code *****************/
/*****************************************************************************/
static void Soc_GetDataOfSocialPublishingFromRow (MYSQL_ROW row,struct SocialPublishing *SocPub)
{
2016-01-25 17:23:14 +01:00
const Soc_TopMessage_t TopMessages[Soc_NUM_PUB_TYPES] =
{
Soc_TOP_MESSAGE_NONE, // Soc_PUB_UNKNOWN
2016-01-25 21:48:08 +01:00
Soc_TOP_MESSAGE_NONE, // Soc_PUB_ORIGINAL_NOTE
2016-01-25 17:23:14 +01:00
Soc_TOP_MESSAGE_SHARED, // Soc_PUB_SHARED_NOTE
Soc_TOP_MESSAGE_COMMENTED, // Soc_PUB_COMMENT_TO_NOTE
};
2016-01-19 21:07:52 +01:00
/***** Get code of social publishing (row[0]) *****/
2016-01-08 01:53:37 +01:00
SocPub->PubCod = Str_ConvertStrCodToLongCod (row[0]);
2016-01-19 21:07:52 +01:00
/***** Get social 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]);
2016-01-19 21:07:52 +01:00
/***** Get type of publishing (row[3]) *****/
2016-01-11 20:54:14 +01:00
SocPub->PubType = Soc_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
}
/*****************************************************************************/
/******************** Get data of social note from row ***********************/
2015-12-30 16:33:36 +01:00
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
static void Soc_GetDataOfSocialNoteFromRow (MYSQL_ROW row,struct SocialNote *SocNot)
2015-12-30 16:33:36 +01:00
{
2016-01-19 21:07:52 +01:00
/***** Get social 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]) *****/
2016-01-04 11:58:36 +01:00
SocNot->NoteType = Soc_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
/***** Get number of times this social note has been shared *****/
SocNot->NumShared = Soc_UpdateNumTimesANoteHasBeenShared (SocNot);
/***** Get number of times this social note has been favourited *****/
SocNot->NumFavs = Soc_GetNumTimesANoteHasBeenFav (SocNot);
2015-12-31 18:40:45 +01:00
}
2016-01-11 20:54:14 +01:00
/*****************************************************************************/
/**** Get social publishing type from string number coming from database *****/
/*****************************************************************************/
static Soc_PubType_t Soc_GetPubTypeFromStr (const char *Str)
{
unsigned UnsignedNum;
if (sscanf (Str,"%u",&UnsignedNum) == 1)
if (UnsignedNum < Soc_NUM_PUB_TYPES)
return (Soc_PubType_t) UnsignedNum;
return Soc_PUB_UNKNOWN;
}
2015-12-31 18:40:45 +01:00
/*****************************************************************************/
/****** Get social note type from string number coming from database *********/
/*****************************************************************************/
2016-01-04 11:58:36 +01:00
static Soc_NoteType_t Soc_GetNoteTypeFromStr (const char *Str)
2015-12-31 18:40:45 +01:00
{
unsigned UnsignedNum;
if (sscanf (Str,"%u",&UnsignedNum) == 1)
2016-01-11 20:54:14 +01:00
if (UnsignedNum < Soc_NUM_NOTE_TYPES)
2015-12-31 18:40:45 +01:00
return (Soc_NoteType_t) UnsignedNum;
return Soc_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
/*****************************************************************************/
/****************** Get data of social comment from row **********************/
/*****************************************************************************/
static void Soc_GetDataOfSocialCommentFromRow (MYSQL_ROW row,struct SocialComment *SocCom)
{
2016-04-08 23:30:43 +02:00
/*
row[0]: PubCod
row[1]: PublisherCod
row[2]: NotCod
row[3]: TimePublish
row[4]: Content
row[5]: ImageName
row[6]: ImageTitle
2016-04-15 02:33:16 +02:00
row[7]: ImageURL
2016-04-08 23:30:43 +02:00
*/
2016-01-19 21:07:52 +01:00
/***** Get code of social 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]);
2016-01-19 21:07:52 +01:00
/***** Get code of social 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]);
2016-01-19 21:07:52 +01:00
/***** Get content (row[4]) *****/
2017-01-17 03:10:43 +01:00
Str_Copy (SocCom->Content,row[4],
Cns_MAX_BYTES_LONG_TEXT);
2016-01-19 21:07:52 +01:00
/***** Get number of times this comment has been favourited *****/
SocCom->NumFavs = Soc_GetNumTimesACommHasBeenFav (SocCom);
2016-04-08 23:30:43 +02:00
2016-04-15 02:33:16 +02:00
/****** Get image name (row[5]), title (row[6]) and URL (row[7]) *****/
Img_GetImageNameTitleAndURLFromRow (row[5],row[6],row[7],&SocCom->Image);
2016-01-08 01:53:37 +01:00
}
2016-01-05 04:54:00 +01:00
/*****************************************************************************/
/*********************** Reset fields of social note *************************/
/*****************************************************************************/
static void Soc_ResetSocialNote (struct SocialNote *SocNot)
{
2016-01-11 02:15:23 +01:00
SocNot->NotCod = -1L;
2016-01-05 04:54:00 +01:00
SocNot->NoteType = Soc_NOTE_UNKNOWN;
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
/*****************************************************************************/
/********************** Reset fields of social comment ***********************/
/*****************************************************************************/
static void Soc_ResetSocialComment (struct SocialComment *SocCom)
{
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;
SocCom->Content[0] = '\0';
}
2016-01-11 19:28:43 +01:00
2016-01-12 20:58:19 +01:00
/*****************************************************************************/
/**************** Clear unused old social timelines in database **************/
/*****************************************************************************/
void Soc_ClearOldTimelinesDB (void)
{
char Query[256];
/***** Remove social timelines for expired sessions *****/
sprintf (Query,"DELETE LOW_PRIORITY FROM social_timelines"
" WHERE SessionId NOT IN (SELECT SessionId FROM sessions)");
DB_QueryDELETE (Query,"can not remove old social timelines");
}
2016-01-12 19:43:17 +01:00
/*****************************************************************************/
/************* Clear social timeline for this session in database ************/
/*****************************************************************************/
2016-01-17 01:50:43 +01:00
static void Soc_ClearTimelineThisSession (void)
2016-01-12 19:43:17 +01:00
{
2017-03-13 14:22:36 +01:00
char Query[128 + Ses_BYTES_SESSION_ID];
2016-01-12 19:43:17 +01:00
/***** Remove social timeline for this session *****/
sprintf (Query,"DELETE FROM social_timelines WHERE SessionId='%s'",
Gbl.Session.Id);
DB_QueryDELETE (Query,"can not remove social timeline");
}
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
/*****************************************************************************/
2016-01-17 01:50:43 +01:00
static void Soc_AddNotesJustRetrievedToTimelineThisSession (void)
2016-01-12 20:58:19 +01:00
{
2017-03-13 14:22:36 +01:00
char Query[256 + Ses_BYTES_SESSION_ID];
2016-01-12 20:58:19 +01:00
2017-03-13 13:17:53 +01:00
sprintf (Query,"INSERT IGNORE INTO social_timelines"
" (SessionId,NotCod)"
2016-01-17 02:25:59 +01:00
" SELECT DISTINCTROW '%s',NotCod FROM not_codes",
2016-01-17 01:50:43 +01:00
Gbl.Session.Id);
2016-06-04 17:17:57 +02:00
DB_QueryINSERT (Query,"can not insert social notes in timeline");
2016-01-12 20:58:19 +01:00
}
2016-01-22 12:05:25 +01:00
/*****************************************************************************/
/******************* Get notification of a new social post *******************/
/*****************************************************************************/
2017-03-08 14:12:33 +01:00
void Soc_GetNotifSocialPublishing (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
2017-03-06 13:01:16 +01:00
char **ContentStr,
long PubCod,bool GetContent)
2016-01-22 12:05:25 +01:00
{
2016-01-23 01:38:55 +01:00
char Query[256];
2016-01-22 12:05:25 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-01-23 01:38:55 +01:00
struct SocialPublishing SocPub;
struct SocialNote SocNot;
2017-01-17 03:10:43 +01:00
char Content[Cns_MAX_BYTES_LONG_TEXT + 1];
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 *****/
SocPub.PubType = Soc_PUB_UNKNOWN;
2017-03-06 13:01:16 +01:00
SummaryStr[0] = '\0'; // Return nothing on error
2016-01-23 01:38:55 +01:00
Content[0] = '\0';
2016-01-22 12:05:25 +01:00
2016-01-23 01:38:55 +01:00
/***** Get summary and content from social post from database *****/
sprintf (Query,"SELECT PubCod,NotCod,PublisherCod,PubType,UNIX_TIMESTAMP(TimePublish)"
2017-03-24 01:09:27 +01:00
" FROM social_pubs WHERE PubCod=%ld",
2016-01-23 01:38:55 +01:00
PubCod);
if (DB_QuerySELECT (Query,&mysql_res,"can not get data of social publishing") == 1) // Result should have a unique row
2016-01-22 12:05:25 +01:00
{
2016-01-23 01:38:55 +01:00
/* Get data of social publishing */
2016-01-22 12:05:25 +01:00
row = mysql_fetch_row (mysql_res);
2016-01-23 01:38:55 +01:00
Soc_GetDataOfSocialPublishingFromRow (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)
{
case Soc_PUB_UNKNOWN:
break;
case Soc_PUB_ORIGINAL_NOTE:
case Soc_PUB_SHARED_NOTE:
/* Get data of social note */
SocNot.NotCod = SocPub.NotCod;
Soc_GetDataOfSocialNotByCod (&SocNot);
if (SocNot.NoteType == Soc_NOTE_SOCIAL_POST)
{
/***** Get content of social post from database *****/
2016-04-08 23:30:43 +02:00
// TODO: What happens if content is empty and an image is attached?
2016-01-23 01:38:55 +01:00
sprintf (Query,"SELECT Content FROM social_posts"
2017-03-24 01:09:27 +01:00
" WHERE PstCod=%ld",
2016-01-23 01:38:55 +01:00
SocNot.Cod);
if (DB_QuerySELECT (Query,&mysql_res,"can not get the content of a social post") == 1) // Result should have a unique row
{
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
/****** Get content (row[0]) *****/
2017-01-17 03:10:43 +01:00
Str_Copy (Content,row[0],
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
{
Length = strlen (Content);
if ((*ContentStr = (char *) malloc (Length + 1)) != NULL)
2016-01-28 13:14:16 +01:00
{
2017-01-17 03:10:43 +01:00
Str_Copy (*ContentStr,Content,
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 *****/
2017-03-08 14:12:33 +01:00
Str_LimitLengthHTMLStr (Content,Ntf_MAX_BYTES_SUMMARY);
2017-01-17 03:10:43 +01:00
Str_Copy (SummaryStr,Content,
2017-03-08 14:12:33 +01:00
Ntf_MAX_BYTES_SUMMARY);
2016-01-23 01:38:55 +01:00
}
else
2017-03-06 13:01:16 +01:00
Soc_GetNoteSummary (&SocNot,SummaryStr);
2016-01-23 01:38:55 +01:00
break;
case Soc_PUB_COMMENT_TO_NOTE:
/***** Get content of social post from database *****/
2016-04-08 23:30:43 +02:00
// TODO: What happens if content is empty and an image is attached?
2016-01-23 01:38:55 +01:00
sprintf (Query,"SELECT Content FROM social_comments"
2017-03-24 01:09:27 +01:00
" WHERE PubCod=%ld",
2016-01-23 01:38:55 +01:00
SocPub.PubCod);
if (DB_QuerySELECT (Query,&mysql_res,"can not get the content of a comment to a social note") == 1) // Result should have a unique row
{
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
/****** Get content (row[0]) *****/
2017-01-17 03:10:43 +01:00
Str_Copy (Content,row[0],
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
{
Length = strlen (Content);
if ((*ContentStr = (char *) malloc (Length + 1)) != NULL)
2016-01-28 13:14:16 +01:00
{
2017-01-17 03:10:43 +01:00
Str_Copy (*ContentStr,Content,
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 *****/
2017-03-08 14:12:33 +01:00
Str_LimitLengthHTMLStr (Content,Ntf_MAX_BYTES_SUMMARY);
2017-01-17 03:10:43 +01:00
Str_Copy (SummaryStr,Content,
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
/*****************************************************************************/
/*** Create a notification about mention for any nickname in a publishing ****/
/*****************************************************************************/
/*
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;
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);
2016-01-25 11:43:14 +01:00
if ((UsrDat.UsrCod = Nck_GetUsrCodFromNickname (UsrDat.Nickname)) > 0)
if (UsrDat.UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) // It's not me
{
/* Get user's data */
Usr_GetAllUsrDataFromUsrCod (&UsrDat);
/* Create notification for the mentioned user *****/
CreateNotif = (UsrDat.Prefs.NotifNtfEvents & (1 << Ntf_EVENT_TIMELINE_MENTION));
if (CreateNotif)
{
NotifyByEmail = (UsrDat.Prefs.EmailNtfEvents & (1 << Ntf_EVENT_TIMELINE_MENTION));
Ntf_StoreNotifyEventToOneUser (Ntf_EVENT_TIMELINE_MENTION,&UsrDat,PubCod,
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0));
}
}
}
}
/* The next char is not the start of a nickname */
else // Character != '@'
Ptr++;
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}