swad-core/swad_social.c

1518 lines
51 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.
2016-01-01 20:19:43 +01:00
Copyright (C) 1999-2016 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"
#include "swad_layout.h"
2015-12-29 01:28:17 +01:00
#include "swad_notice.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 *****************************/
/*****************************************************************************/
2015-12-29 01:28:17 +01:00
#define Soc_MAX_BYTES_SUMMARY 100
2016-01-01 20:35:43 +01:00
#define Soc_NUM_PUBS_IN_TIMELINE 100
2015-12-28 19:23:42 +01:00
2015-12-31 14:25:28 +01:00
static const Act_Action_t Soc_DefaultActions[Soc_NUM_SOCIAL_NOTES] =
2015-12-29 13:18:25 +01:00
{
2015-12-31 14:25:28 +01:00
ActUnk, // Soc_NOTE_UNKNOWN
2015-12-29 13:18:25 +01:00
/* Institution tab */
2015-12-31 14:25:28 +01:00
ActSeeDocIns, // Soc_NOTE_INS_DOC_PUB_FILE
ActAdmComIns, // Soc_NOTE_INS_SHA_PUB_FILE
2015-12-29 13:18:25 +01:00
/* Centre tab */
2015-12-31 14:25:28 +01:00
ActSeeDocCtr, // Soc_NOTE_CTR_DOC_PUB_FILE
ActAdmComCtr, // Soc_NOTE_CTR_SHA_PUB_FILE
2015-12-29 13:18:25 +01:00
/* Degree tab */
2015-12-31 14:25:28 +01:00
ActSeeDocDeg, // Soc_NOTE_DEG_DOC_PUB_FILE
ActAdmComDeg, // Soc_NOTE_DEG_SHA_PUB_FILE
2015-12-29 13:18:25 +01:00
/* Course tab */
2015-12-31 14:25:28 +01:00
ActSeeDocCrs, // Soc_NOTE_CRS_DOC_PUB_FILE
ActAdmShaCrs, // Soc_NOTE_CRS_SHA_PUB_FILE
2015-12-29 13:18:25 +01:00
/* Assessment tab */
2015-12-31 14:25:28 +01:00
ActSeeExaAnn, // Soc_NOTE_EXAM_ANNOUNCEMENT
2015-12-29 13:18:25 +01:00
/* Users tab */
/* Social tab */
2016-01-02 14:36:34 +01:00
ActUnk, // Soc_NOTE_SOCIAL_POST (action not used)
2015-12-31 14:25:28 +01:00
ActSeeFor, // Soc_NOTE_FORUM_POST
2015-12-29 13:18:25 +01:00
/* Messages tab */
2015-12-31 14:25:28 +01:00
ActShoNot, // Soc_NOTE_NOTICE
2015-12-29 13:18:25 +01:00
/* Statistics tab */
/* Profile tab */
};
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
/****************************** Internal types *******************************/
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
struct SocialPublishing
{
long PubCod;
long AuthorCod;
long PublisherCod;
long NotCod;
time_t DateTimeUTC;
};
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;
2015-12-30 12:40:13 +01:00
long UsrCod;
2016-01-02 13:21:25 +01:00
long HieCod; // Hierarchy code (institution/centre/degree/course)
long Cod; // Code of file, forum post, notice,...
2015-12-30 12:40:13 +01:00
time_t DateTimeUTC;
};
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-01 21:18:44 +01:00
static void Soc_ShowTimeline (const char *Query,Act_Action_t UpdateAction);
2015-12-31 18:40:45 +01:00
static void Soc_GetDataOfSocialPublishingFromRow (MYSQL_ROW row,struct SocialPublishing *SocPub);
static void Soc_WriteSocialNote (const struct SocialPublishing *SocPub,
const struct SocialNote *SocNot,
struct UsrData *UsrDat,
bool PutIconRemove);
2015-12-31 14:25:28 +01:00
static void Soc_WriteNoteDate (time_t TimeUTC);
2016-01-02 01:56:48 +01:00
static void Soc_GetAndWriteSocialPost (long PstCod);
2015-12-31 18:40:45 +01:00
static void Soc_StartFormGoToAction (Soc_NoteType_t NoteType,
2015-12-29 13:18:25 +01:00
long CrsCod,long Cod);
2015-12-31 18:40:45 +01:00
static void Soc_GetNoteSummary (const struct SocialNote *SocNot,
2015-12-31 14:25:28 +01:00
char *SummaryStr,unsigned MaxChars);
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-02 01:56:48 +01:00
static void Soc_PutLinkToWriteANewPost (Act_Action_t Action,void (*FuncParams) ());
static void Soc_FormSocialPost (void);
static void Soc_ReceiveSocialPost (void);
2015-12-30 12:40:13 +01:00
2016-01-01 20:19:43 +01:00
static void Soc_PutFormToShareSocialPublishing (long PubCod);
static void Soc_PutFormToUnshareSocialPublishing (long PubCod);
2015-12-31 18:40:45 +01:00
static void Soc_PutFormToRemoveSocialPublishing (long PubCod);
static void Soc_PutHiddenParamPubCod (long NotCod);
static long Soc_GetParamPubCod (void);
2016-01-01 20:19:43 +01:00
2016-01-02 01:56:48 +01:00
static void Soc_ShareSocialPublishing (void);
static void Soc_UnshareSocialPublishing (void);
2016-01-02 14:36:34 +01:00
static void Soc_UnshareASocialPublishingFromDB (const struct SocialNote *SocNot);
2016-01-02 01:56:48 +01:00
static void Soc_RequestRemovalSocialPublishing (void);
static void Soc_RemoveSocialPublishing (void);
2016-01-02 14:36:34 +01:00
static void Soc_RemoveASocialPublishingFromDB (const struct SocialPublishing *SocPub,
2016-01-01 20:19:43 +01:00
const struct SocialNote *SocNot);
2016-01-02 14:36:34 +01:00
static void Soc_CheckAndDeleteASocialNoteFromDB (const struct SocialNote *SocNot);
2016-01-01 20:19:43 +01:00
static bool Soc_CheckIfNoteIsYetPublishedByMe (long NotCod);
2015-12-31 18:40:45 +01:00
static unsigned long Soc_GetNumPubsOfANote (long NotCod);
static void Soc_GetDataOfSocialPublishingByCod (struct SocialPublishing *SocPub);
static void Soc_GetDataOfSocialNoteByCod (struct SocialNote *SocNot);
static void Soc_GetDataOfSocialNoteFromRow (MYSQL_ROW row,struct SocialNote *SocNot);
static Soc_NoteType_t Soc_GetSocialNoteFromDB (const char *Str);
2015-12-29 23:44:28 +01:00
2015-12-29 14:24:37 +01:00
/*****************************************************************************/
/*********** Show social activity (timeline) of a selected user **************/
/*****************************************************************************/
2016-01-02 01:56:48 +01:00
void Soc_ShowTimelineUsr (void)
2015-12-29 14:24:37 +01:00
{
char Query[512];
2016-01-01 21:42:04 +01:00
/***** Link to write a new social post (public comment) *****/
2016-01-02 01:56:48 +01:00
if (Gbl.Usrs.Other.UsrDat.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod && // It's me
Gbl.CurrentAct != ActReqSocPstUsr) // Not writing a new post
Soc_PutLinkToWriteANewPost (ActReqSocPstUsr,Usr_PutParamOtherUsrCodEncrypted);
2016-01-01 21:42:04 +01:00
2015-12-31 18:40:45 +01:00
/***** Build query to show timeline with publishing of a unique user *****/
2016-01-01 20:19:43 +01:00
sprintf (Query,"SELECT PubCod,AuthorCod,PublisherCod,NotCod,UNIX_TIMESTAMP(TimePublish)"
2015-12-31 18:40:45 +01:00
" FROM social_timeline"
" WHERE PublisherCod='%ld'"
2016-01-01 20:35:43 +01:00
" ORDER BY PubCod DESC LIMIT %u",
2016-01-02 01:56:48 +01:00
Gbl.Usrs.Other.UsrDat.UsrCod,
2016-01-01 20:35:43 +01:00
Soc_NUM_PUBS_IN_TIMELINE);
2015-12-29 14:24:37 +01:00
/***** Show timeline *****/
2016-01-02 01:56:48 +01:00
Soc_ShowTimeline (Query,ActSeePubPrf);
2015-12-29 14:24:37 +01:00
}
/*****************************************************************************/
/***** Show social activity (timeline) including all the users I follow ******/
/*****************************************************************************/
2016-01-02 01:56:48 +01:00
void Soc_ShowTimelineGbl (void)
2015-12-29 14:24:37 +01:00
{
2016-01-01 21:18:44 +01:00
extern const char *Txt_You_dont_follow_any_user;
2015-12-29 14:24:37 +01:00
char Query[512];
2015-12-31 14:25:28 +01:00
/***** Link to write a new social post (public comment) *****/
2016-01-02 01:56:48 +01:00
if (Gbl.CurrentAct != ActReqSocPstGbl) // Not writing a new post
Soc_PutLinkToWriteANewPost (ActReqSocPstGbl,NULL);
2015-12-30 00:58:25 +01:00
2016-01-01 21:18:44 +01:00
/***** If I follow someone... *****/
if (Fol_GetNumFollowing (Gbl.Usrs.Me.UsrDat.UsrCod))
{
/***** Create temporary table with publishing codes *****/
sprintf (Query,"DROP TEMPORARY TABLE IF EXISTS pub_cods");
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not remove temporary tables");
sprintf (Query,"CREATE TEMPORARY TABLE pub_cods (PubCod BIGINT NOT NULL,UNIQUE INDEX(PubCod)) ENGINE=MEMORY"
" SELECT MIN(PubCod) AS PubCod"
" FROM social_timeline"
" WHERE PublisherCod IN"
" (SELECT '%ld'"
" UNION"
" SELECT FollowedCod FROM usr_follow WHERE FollowerCod='%ld')"
" GROUP BY NotCod"
" ORDER BY PubCod DESC LIMIT %u",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
Soc_NUM_PUBS_IN_TIMELINE);
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not create temporary table");
/***** Build query to show timeline including the users I am following *****/
sprintf (Query,"SELECT PubCod,AuthorCod,PublisherCod,NotCod,UNIX_TIMESTAMP(TimePublish)"
" FROM social_timeline WHERE PubCod IN "
"(SELECT PubCod FROM pub_cods)"
" ORDER BY PubCod DESC");
/***** Show timeline *****/
2016-01-02 01:56:48 +01:00
Soc_ShowTimeline (Query,ActSeeSocTmlGbl);
2016-01-01 21:18:44 +01:00
/***** Drop temporary table with publishing codes *****/
sprintf (Query,"DROP TEMPORARY TABLE IF EXISTS pub_cods");
if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not remove temporary tables");
}
else // I do not follow anyone
/***** Show warning if I do not follow anyone *****/
Lay_ShowAlert (Lay_INFO,Txt_You_dont_follow_any_user);
2015-12-29 14:24:37 +01:00
}
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
/*********************** Show social activity (timeline) *********************/
/*****************************************************************************/
2016-01-01 21:18:44 +01:00
static void Soc_ShowTimeline (const char *Query,Act_Action_t UpdateAction)
2015-12-28 19:23:42 +01:00
{
2016-01-02 02:49:21 +01:00
extern const char *The_ClassFormBold[The_NUM_THEMES];
2015-12-28 19:23:42 +01:00
extern const char *Txt_Public_activity;
2016-01-02 02:49:21 +01:00
extern const char *Txt_Update;
2016-01-01 21:18:44 +01:00
extern const char *Txt_No_public_activity;
2015-12-28 19:23:42 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2015-12-31 18:40:45 +01:00
unsigned long NumPublishings;
unsigned long NumPub;
struct SocialPublishing SocPub;
struct SocialNote SocNot;
2015-12-28 19:23:42 +01:00
struct UsrData UsrDat;
2015-12-29 14:24:37 +01:00
/***** Get timeline from database *****/
2015-12-31 18:40:45 +01:00
NumPublishings = DB_QuerySELECT (Query,&mysql_res,"can not get social notes");
2015-12-28 19:23:42 +01:00
/***** List my timeline *****/
2015-12-31 18:40:45 +01:00
if (NumPublishings) // Publishings found in timeline
2015-12-28 19:23:42 +01:00
{
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
2015-12-30 18:36:10 +01:00
/***** Start frame *****/
2015-12-29 14:24:37 +01:00
Lay_StartRoundFrame ("560px",Txt_Public_activity);
2015-12-30 18:36:10 +01:00
/***** Form to update timeline *****/
2016-01-02 02:49:21 +01:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
Act_FormStartAnchor (UpdateAction,"timeline");
Usr_PutParamOtherUsrCodEncrypted ();
}
else
Act_FormStart (UpdateAction);
Act_LinkFormSubmitAnimated (Txt_Update,The_ClassFormBold[Gbl.Prefs.Theme]);
Lay_PutCalculateIconWithText (Txt_Update,Txt_Update);
Act_FormEnd ();
fprintf (Gbl.F.Out,"</div>");
2015-12-30 18:36:10 +01:00
/***** Start list *****/
2015-12-28 20:46:48 +01:00
fprintf (Gbl.F.Out,"<ul class=\"LIST_LEFT\">");
2015-12-28 19:23:42 +01:00
2015-12-31 18:40:45 +01:00
/***** List publishings in timeline one by one *****/
for (NumPub = 0;
NumPub < NumPublishings;
NumPub++)
2015-12-28 19:23:42 +01:00
{
2015-12-31 18:40:45 +01:00
/* Get next social publishing */
2015-12-28 19:23:42 +01:00
row = mysql_fetch_row (mysql_res);
2015-12-31 18:40:45 +01:00
Soc_GetDataOfSocialPublishingFromRow (row,&SocPub);
2015-12-28 19:23:42 +01:00
2015-12-31 18:40:45 +01:00
/* Get and write social note */
SocNot.NotCod = SocPub.NotCod;
Soc_GetDataOfSocialNoteByCod (&SocNot);
Soc_WriteSocialNote (&SocPub,&SocNot,&UsrDat,true);
2015-12-28 19:23:42 +01:00
}
2015-12-30 18:36:10 +01:00
/***** End list *****/
2015-12-28 19:23:42 +01:00
fprintf (Gbl.F.Out,"</ul>");
2015-12-30 18:36:10 +01:00
/***** End frame *****/
2015-12-28 19:23:42 +01:00
Lay_EndRoundFrame ();
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
2016-01-01 21:18:44 +01:00
else // No publishing found in timeline
Lay_ShowAlert (Lay_INFO,Txt_No_public_activity);
2015-12-28 19:23:42 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
/************** Get data of social publishing using its code *****************/
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
static void Soc_GetDataOfSocialPublishingFromRow (MYSQL_ROW row,struct SocialPublishing *SocPub)
2015-12-28 19:23:42 +01:00
{
2015-12-31 18:40:45 +01:00
/* Get social publishing code (row[0]) */
2016-01-02 14:36:34 +01:00
SocPub->PubCod = Str_ConvertStrCodToLongCod (row[0]);
2015-12-28 19:23:42 +01:00
2015-12-31 18:40:45 +01:00
/* Get author's code (row[1]) */
2016-01-02 14:36:34 +01:00
SocPub->AuthorCod = Str_ConvertStrCodToLongCod (row[1]);
2015-12-28 19:23:42 +01:00
2015-12-31 18:40:45 +01:00
/* Get publisher's code (row[2]) */
SocPub->PublisherCod = Str_ConvertStrCodToLongCod (row[2]);
/* Get social note code (row[3]) */
2016-01-02 14:36:34 +01:00
SocPub->NotCod = Str_ConvertStrCodToLongCod (row[3]);
2015-12-31 18:40:45 +01:00
/* Get time of the note (row[4]) */
2016-01-02 14:36:34 +01:00
SocPub->DateTimeUTC = Dat_GetUNIXTimeFromStr (row[4]);
2015-12-28 19:23:42 +01:00
}
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
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
static void Soc_WriteSocialNote (const struct SocialPublishing *SocPub,
const struct SocialNote *SocNot,
struct UsrData *UsrDat,
bool PutIconRemove)
2015-12-30 16:33:36 +01:00
{
extern const char *The_ClassForm[The_NUM_THEMES];
2015-12-31 14:25:28 +01:00
extern const char *Txt_SOCIAL_NOTE[Soc_NUM_SOCIAL_NOTES];
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;
struct Institution Ins;
struct Centre Ctr;
struct Degree Deg;
struct Course Crs;
bool ShowPhoto = false;
char PhotoURL[PATH_MAX+1];
char ForumName[512];
char SummaryStr[Cns_MAX_BYTES_TEXT+1];
/***** Get details *****/
/* Get author data */
2015-12-31 18:40:45 +01:00
UsrDat->UsrCod = SocNot->UsrCod;
2015-12-30 16:33:36 +01:00
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (UsrDat);
/* Get forum type of the post */
2015-12-31 18:40:45 +01:00
if (SocNot->NoteType == Soc_NOTE_FORUM_POST)
2015-12-30 16:33:36 +01:00
{
2015-12-31 18:40:45 +01:00
Gbl.Forum.ForumType = For_GetForumTypeOfAPost (SocNot->Cod);
2015-12-30 16:33:36 +01:00
For_SetForumName (Gbl.Forum.ForumType,
&Ins,
&Ctr,
&Deg,
&Crs,
ForumName,Gbl.Prefs.Language,false); // Set forum name in recipient's language
Gbl.Forum.Ins.InsCod = Ins.InsCod;
Gbl.Forum.Ctr.CtrCod = Ctr.CtrCod;
Gbl.Forum.Deg.DegCod = Deg.DegCod;
Gbl.Forum.Crs.CrsCod = Crs.CrsCod;
}
/***** Start list item *****/
2016-01-01 20:35:43 +01:00
fprintf (Gbl.F.Out,"<li class=\"SOCIAL_PUB\">");
2015-12-30 16:33:36 +01:00
/***** Left: write author's photo *****/
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_LEFT_PHOTO\">");
ShowPhoto = Pho_ShowUsrPhotoIsAllowed (UsrDat,PhotoURL);
Pho_ShowUsrPhoto (UsrDat,ShowPhoto ? PhotoURL :
NULL,
"PHOTO60x80",Pho_ZOOM);
fprintf (Gbl.F.Out,"</div>");
2016-01-02 14:36:34 +01:00
/***** Right: author's name, time, summary and buttons *****/
2015-12-30 16:33:36 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_RIGHT_CONTAINER\">");
/* Write author's full name and nickname */
Str_LimitLengthHTMLStr (UsrDat->FullName,20);
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_RIGHT_AUTHOR\">"
"<span class=\"DAT_N_BOLD\">%s</span>"
"<span class=\"DAT_LIGHT\"> @%s</span>"
"</div>",
UsrDat->FullName,UsrDat->Nickname);
/* Write date and time */
2015-12-31 18:40:45 +01:00
Soc_WriteNoteDate (SocNot->DateTimeUTC);
2015-12-30 16:33:36 +01:00
2016-01-02 14:36:34 +01:00
/* Write content of the note */
2015-12-31 18:40:45 +01:00
if (SocNot->NoteType == Soc_NOTE_SOCIAL_POST)
2015-12-30 16:33:36 +01:00
{
/* Write post content */
fprintf (Gbl.F.Out,"<div class=\"DAT\">");
2015-12-31 18:40:45 +01:00
Soc_GetAndWriteSocialPost (SocNot->Cod);
2015-12-30 16:33:36 +01:00
fprintf (Gbl.F.Out,"</div>");
}
else
{
2016-01-02 13:21:25 +01:00
/* Write note type and location-hierarchy */
2015-12-30 16:33:36 +01:00
fprintf (Gbl.F.Out,"<div>");
2015-12-31 18:40:45 +01:00
Soc_StartFormGoToAction (SocNot->NoteType,Crs.CrsCod,SocNot->Cod);
Act_LinkFormSubmit (Txt_SOCIAL_NOTE[SocNot->NoteType],
2015-12-30 16:33:36 +01:00
The_ClassForm[Gbl.Prefs.Theme]);
fprintf (Gbl.F.Out,"%s</a>",
2015-12-31 18:40:45 +01:00
Txt_SOCIAL_NOTE[SocNot->NoteType]);
2015-12-30 16:33:36 +01:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</div>");
2016-01-02 13:21:25 +01:00
switch (SocNot->NoteType)
2016-01-02 14:36:34 +01:00
{
2016-01-02 13:21:25 +01:00
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);
2016-01-02 14:36:34 +01:00
/* Write location (institution) in hierarchy */
2016-01-02 13:21:25 +01:00
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
Txt_Institution,Ins.ShortName);
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);
2016-01-02 14:36:34 +01:00
/* Write location (centre) in hierarchy */
2016-01-02 13:21:25 +01:00
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
Txt_Centre,Ctr.ShortName);
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);
2016-01-02 14:36:34 +01:00
/* Write location (degree) in hierarchy */
2016-01-02 13:21:25 +01:00
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
Txt_Degree,Deg.ShortName);
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);
2016-01-02 14:36:34 +01:00
/* Write location (course) in hierarchy */
2016-01-02 13:21:25 +01:00
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
Txt_Course,Crs.ShortName);
break;
case Soc_NOTE_FORUM_POST:
2016-01-02 14:36:34 +01:00
/* Write forum name */
2016-01-02 13:21:25 +01:00
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
Txt_Forum,ForumName);
break;
default:
break;
2016-01-02 14:36:34 +01:00
}
2015-12-30 16:33:36 +01:00
2016-01-02 14:36:34 +01:00
/* Write note summary */
2015-12-31 18:40:45 +01:00
Soc_GetNoteSummary (SocNot,SummaryStr,Soc_MAX_BYTES_SUMMARY);
2015-12-30 16:33:36 +01:00
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s</div>",SummaryStr);
}
2016-01-02 14:36:34 +01:00
/* Put icons to share/unshare/remove */
if (Gbl.Usrs.Me.Logged)
{
if (UsrDat->UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // I am the author
{
if (PutIconRemove)
/* Put icon to remove this publishing */
Soc_PutFormToRemoveSocialPublishing (SocPub->PubCod);
}
else // I am not the author
{
if (Soc_CheckIfNoteIsYetPublishedByMe (SocNot->NotCod))
// I have yet published this social note
/* Put icon to unshare this publishing */
Soc_PutFormToUnshareSocialPublishing (SocPub->PubCod);
else
// I have not yet published this social note
/* Put icon to share this publishing */
Soc_PutFormToShareSocialPublishing (SocPub->PubCod);
}
}
2015-12-30 16:33:36 +01:00
/* End of right part */
fprintf (Gbl.F.Out,"</div>");
/***** End list item *****/
fprintf (Gbl.F.Out,"</li>");
}
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)
2015-12-31 14:25:28 +01:00
static void Soc_WriteNoteDate (time_t TimeUTC)
2015-12-28 19:23:42 +01:00
{
2015-12-29 11:35:01 +01:00
extern const char *Txt_Today;
2015-12-28 19:23:42 +01:00
static unsigned UniqueId = 0;
UniqueId++;
/***** Start cell *****/
2015-12-29 02:09:50 +01:00
fprintf (Gbl.F.Out,"<div id=\"date_%u\" class=\"SOCIAL_RIGHT_TIME DAT_LIGHT\""
2015-12-28 20:46:48 +01:00
" style=\"display:inline-block;\">",
2015-12-28 19:23:42 +01:00
UniqueId);
/***** Write date and time *****/
fprintf (Gbl.F.Out,"<script type=\"text/javascript\">"
2015-12-29 11:35:01 +01:00
"writeLocalDateTimeFromUTC('date_%u',%ld,'&nbsp;','%s');"
2015-12-28 19:23:42 +01:00
"</script>",
2015-12-29 11:35:01 +01:00
UniqueId,(long) TimeUTC,Txt_Today);
2015-12-28 19:23:42 +01:00
/***** End cell *****/
2015-12-28 20:46:48 +01:00
fprintf (Gbl.F.Out,"</div>");
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)
{
char Query[128];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
char Content[Cns_MAX_BYTES_LONG_TEXT+1];
/***** Get social post from database *****/
sprintf (Query,"SELECT Content FROM social_posts WHERE PstCod='%ld'",
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)
{
/***** Get number of rows *****/
row = mysql_fetch_row (mysql_res);
/****** Get content (row[0]) *****/
strncpy (Content,row[0],Cns_MAX_BYTES_LONG_TEXT);
Content[Cns_MAX_BYTES_LONG_TEXT] = '\0';
}
else
Content[0] = '\0';
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Write content *****/
Msg_WriteMsgContent (Content,Cns_MAX_BYTES_LONG_TEXT,true,false);
}
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
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
static void Soc_StartFormGoToAction (Soc_NoteType_t NoteType,
2015-12-29 13:18:25 +01:00
long CrsCod,long Cod)
{
extern const Act_Action_t For_ActionsSeeFor[For_NUM_TYPES_FORUM];
struct FileMetadata FileMetadata;
long GrpCod = -1L;
char PathUntilFileName[PATH_MAX+1];
char FileName[NAME_MAX+1];
Act_Action_t Action = ActUnk; // Initialized to avoid warning
2015-12-31 14:25:28 +01:00
/***** Parameters depending on the type of note *****/
2015-12-31 18:40:45 +01:00
switch (NoteType)
2015-12-29 13:18:25 +01:00
{
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:
2015-12-29 13:18:25 +01:00
if (Cod > 0) // File code
{
FileMetadata.FilCod = Cod;
Brw_GetFileMetadataByCod (&FileMetadata);
Brw_GetCrsGrpFromFileMetadata (FileMetadata.FileBrowser,FileMetadata.Cod,&CrsCod,&GrpCod);
Str_SplitFullPathIntoPathAndFileName (FileMetadata.Path,
PathUntilFileName,
FileName);
}
2015-12-31 18:40:45 +01:00
switch (NoteType)
2015-12-29 13:18:25 +01:00
{
2015-12-31 14:25:28 +01:00
case Soc_NOTE_INS_DOC_PUB_FILE:
2015-12-29 13:18:25 +01:00
Action = (Cod > 0) ? ActReqDatSeeDocIns : ActSeeDocIns;
break;
2015-12-31 14:25:28 +01:00
case Soc_NOTE_INS_SHA_PUB_FILE:
2015-12-29 13:18:25 +01:00
Action = (Cod > 0) ? ActReqDatShaIns : ActAdmComIns;
break;
2015-12-31 14:25:28 +01:00
case Soc_NOTE_CTR_DOC_PUB_FILE:
2015-12-29 13:18:25 +01:00
Action = (Cod > 0) ? ActReqDatSeeDocCtr : ActSeeDocCtr;
break;
2015-12-31 14:25:28 +01:00
case Soc_NOTE_CTR_SHA_PUB_FILE:
2015-12-29 13:18:25 +01:00
Action = (Cod > 0) ? ActReqDatShaCtr : ActAdmComCtr;
break;
2015-12-31 14:25:28 +01:00
case Soc_NOTE_DEG_DOC_PUB_FILE:
2015-12-29 13:18:25 +01:00
Action = (Cod > 0) ? ActReqDatSeeDocDeg : ActSeeDocDeg;
break;
2015-12-31 14:25:28 +01:00
case Soc_NOTE_DEG_SHA_PUB_FILE:
2015-12-29 13:18:25 +01:00
Action = (Cod > 0) ? ActReqDatShaDeg : ActAdmComDeg;
break;
2015-12-31 14:25:28 +01:00
case Soc_NOTE_CRS_DOC_PUB_FILE:
2015-12-29 13:18:25 +01:00
Action = (Cod > 0) ? ActReqDatSeeDocCrs : ActSeeDocCrs;
break;
2015-12-31 14:25:28 +01:00
case Soc_NOTE_CRS_SHA_PUB_FILE:
2015-12-29 13:18:25 +01:00
Action = (Cod > 0) ? ActReqDatShaCrs : ActAdmShaCrs;
break;
default: // Not aplicable here
break;
}
Act_FormStart (Action);
Grp_PutParamGrpCod (-1L);
if (Cod > 0) // File code
Brw_PutParamsPathAndFile (Brw_IS_FILE,PathUntilFileName,FileName);
break;
2015-12-31 14:25:28 +01:00
case Soc_NOTE_NOTICE:
2015-12-31 18:40:45 +01:00
Act_FormStart (Soc_DefaultActions[NoteType]);
2015-12-29 13:18:25 +01:00
Not_PutHiddenParamNotCod (Cod);
break;
2015-12-31 14:25:28 +01:00
case Soc_NOTE_FORUM_POST:
2015-12-29 13:18:25 +01:00
Act_FormStart (For_ActionsSeeFor[Gbl.Forum.ForumType]);
For_PutAllHiddenParamsForum ();
break;
default:
2015-12-31 18:40:45 +01:00
Act_FormStart (Soc_DefaultActions[NoteType]);
2015-12-29 13:18:25 +01:00
break;
}
/***** Parameter to go to another course *****/
if (CrsCod > 0 && // Course specified
CrsCod != Gbl.CurrentCrs.Crs.CrsCod) // Not the current course
Crs_PutParamCrsCod (CrsCod); // Go to another course
}
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,
2015-12-31 14:25:28 +01:00
char *SummaryStr,unsigned MaxChars)
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:
2015-12-31 18:40:45 +01:00
Brw_GetSummaryAndContentOrSharedFile (SummaryStr,NULL,SocNot->Cod,MaxChars,false);
2015-12-28 19:23:42 +01:00
break;
2015-12-31 14:25:28 +01:00
case Soc_NOTE_EXAM_ANNOUNCEMENT:
2015-12-31 18:40:45 +01:00
Exa_GetSummaryAndContentExamAnnouncement (SummaryStr,NULL,SocNot->Cod,MaxChars,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:
2015-12-31 18:40:45 +01:00
For_GetSummaryAndContentForumPst (SummaryStr,NULL,SocNot->Cod,MaxChars,false);
2015-12-28 19:23:42 +01:00
break;
2015-12-31 14:25:28 +01:00
case Soc_NOTE_NOTICE:
2015-12-31 18:40:45 +01:00
Not_GetSummaryAndContentNotice (SummaryStr,NULL,SocNot->Cod,MaxChars,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
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
void Soc_StoreAndPublishSocialNote (Soc_NoteType_t NoteType,long Cod)
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)
2016-01-01 20:19:43 +01:00
struct SocialPublishing SocPub;
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"
" (NoteType,UsrCod,HieCod,Cod,TimeNote)"
" VALUES ('%u','%ld','%ld','%ld',NOW())",
(unsigned) NoteType,Gbl.Usrs.Me.UsrDat.UsrCod,HieCod,Cod);
2016-01-01 20:19:43 +01:00
SocPub.NotCod = DB_QueryINSERTandReturnCode (Query,"can not create new social note");
/***** Publish social note in timeline *****/
SocPub.AuthorCod =
SocPub.PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod;
Soc_PublishSocialNoteInTimeline (&SocPub);
}
2015-12-31 18:40:45 +01:00
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
/***************** Put contextual link to write a new post *******************/
/*****************************************************************************/
static void Soc_PublishSocialNoteInTimeline (struct SocialPublishing *SocPub)
{
char Query[256];
/***** Publish social note in timeline *****/
2015-12-31 18:40:45 +01:00
sprintf (Query,"INSERT INTO social_timeline"
" (AuthorCod,PublisherCod,NotCod,TimePublish)"
" VALUES"
" ('%ld','%ld','%ld',NOW())",
2016-01-01 20:19:43 +01:00
SocPub->AuthorCod,SocPub->PublisherCod,SocPub->NotCod);
2015-12-31 18:40:45 +01:00
DB_QueryINSERT (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
/*****************************************************************************/
/***************** Put contextual link to write a new post *******************/
/*****************************************************************************/
2016-01-02 01:56:48 +01:00
static void Soc_PutLinkToWriteANewPost (Act_Action_t Action,void (*FuncParams) ())
2015-12-30 12:40:13 +01:00
{
extern const char *Txt_New_comment;
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
2016-01-02 02:33:23 +01:00
Lay_PutContextualLinkAnchor (Action,"timeline",
FuncParams,
"write64x64.gif",
Txt_New_comment,Txt_New_comment);
2015-12-30 12:40:13 +01:00
fprintf (Gbl.F.Out,"</div>");
}
/*****************************************************************************/
/****************** Form to write a new public comment ***********************/
/*****************************************************************************/
2016-01-02 01:56:48 +01:00
void Soc_FormSocialPostGbl (void)
{
/***** Form to write a new public comment *****/
Soc_FormSocialPost ();
/***** Write current timeline (global) *****/
Soc_ShowTimelineGbl ();
}
void Soc_FormSocialPostUsr (void)
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
/***** Show user's profile *****/
Prf_ShowUserProfile ();
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
/***** Form to write a new public comment *****/
Soc_FormSocialPost ();
/***** Write current timeline (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
}
static void Soc_FormSocialPost (void)
2015-12-30 12:40:13 +01:00
{
extern const char *Txt_New_comment;
extern const char *Txt_Send_comment;
/***** Form to write a new public comment *****/
/* Start frame */
Lay_StartRoundFrame ("560px",Txt_New_comment);
/* Start form to write the post */
2016-01-02 01:56:48 +01:00
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
2016-01-02 02:33:23 +01:00
Act_FormStartAnchor (ActRcvSocPstUsr,"timeline");
2016-01-02 01:56:48 +01:00
Usr_PutParamOtherUsrCodEncrypted ();
}
else
Act_FormStart (ActRcvSocPstGbl);
2015-12-30 12:40:13 +01:00
/* Content of new post */
fprintf (Gbl.F.Out,"<textarea name=\"Content\" cols=\"50\" rows=\"5\">"
"</textarea>");
2015-12-30 17:27:11 +01:00
Lay_HelpPlainEditor ();
2015-12-30 12:40:13 +01:00
/* Send button */
Lay_PutCreateButton (Txt_Send_comment);
/* End form */
Act_FormEnd ();
/* End frame */
Lay_EndRoundFrame ();
}
/*****************************************************************************/
/******************* Receive and store a new public post *********************/
/*****************************************************************************/
2016-01-02 01:56:48 +01:00
void Soc_ReceiveSocialPostGbl (void)
{
/***** Receive and store social post *****/
Soc_ReceiveSocialPost ();
/***** Write updated timeline after publishing (global) *****/
Soc_ShowTimelineGbl ();
}
void Soc_ReceiveSocialPostUsr (void)
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
/***** Show user's profile *****/
Prf_ShowUserProfile ();
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 *****/
Soc_ReceiveSocialPost ();
/***** Write updated timeline after publishing (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
}
static void Soc_ReceiveSocialPost (void)
2015-12-30 12:40:13 +01:00
{
char Content[Cns_MAX_BYTES_LONG_TEXT+1];
char Query[128+Cns_MAX_BYTES_LONG_TEXT];
long PstCod;
/***** Get and store new post *****/
/* Get the content of the post */
Par_GetParAndChangeFormat ("Content",Content,Cns_MAX_BYTES_LONG_TEXT,
Str_TO_RIGOROUS_HTML,true);
/* Insert post content in the database */
2015-12-31 14:25:28 +01:00
sprintf (Query,"INSERT INTO social_posts (Content) VALUES ('%s')",
2015-12-30 12:40:13 +01:00
Content);
PstCod = DB_QueryINSERTandReturnCode (Query,"can not create post");
2015-12-31 14:25:28 +01:00
/* Insert post in social notes */
2015-12-31 18:40:45 +01:00
Soc_StoreAndPublishSocialNote (Soc_NOTE_SOCIAL_POST,PstCod);
2015-12-30 12:40:13 +01:00
}
2015-12-30 02:08:08 +01:00
/*****************************************************************************/
2016-01-01 20:19:43 +01:00
/********************* Form to share social publishing ***********************/
/*****************************************************************************/
static void Soc_PutFormToShareSocialPublishing (long PubCod)
{
extern const char *Txt_Share;
/***** Form to share social publishing *****/
2016-01-02 01:56:48 +01:00
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
2016-01-02 02:33:23 +01:00
Act_FormStartAnchor (ActShaSocPubUsr,"timeline");
2016-01-02 01:56:48 +01:00
Usr_PutParamOtherUsrCodEncrypted ();
}
else
Act_FormStart (ActShaSocPubGbl);
2016-01-01 20:19:43 +01:00
Soc_PutHiddenParamPubCod (PubCod);
2016-01-01 20:35:43 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_ICON ICON_HIGHLIGHT\">"
2016-01-01 20:19:43 +01:00
"<input type=\"image\""
" src=\"%s/share64x64.png\""
" alt=\"%s\" title=\"%s\""
" class=\"ICON20x20\" />"
"</div>",
Gbl.Prefs.IconsURL,
Txt_Share,
Txt_Share);
Act_FormEnd ();
}
/*****************************************************************************/
/************ Form to unshare (stop sharing) social publishing ***************/
/*****************************************************************************/
static void Soc_PutFormToUnshareSocialPublishing (long PubCod)
{
2016-01-02 14:36:34 +01:00
extern const char *Txt_SOCIAL_PUBLISHING_Shared;
2016-01-01 20:19:43 +01:00
/***** Form to share social publishing *****/
2016-01-02 01:56:48 +01:00
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
2016-01-02 02:33:23 +01:00
Act_FormStartAnchor (ActUnsSocPubUsr,"timeline");
2016-01-02 01:56:48 +01:00
Usr_PutParamOtherUsrCodEncrypted ();
}
else
Act_FormStart (ActUnsSocPubGbl);
2016-01-01 20:19:43 +01:00
Soc_PutHiddenParamPubCod (PubCod);
2016-01-01 20:35:43 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_ICON ICON_HIGHLIGHT\">"
2016-01-01 20:19:43 +01:00
"<input type=\"image\""
" src=\"%s/shared64x64.png\""
" alt=\"%s\" title=\"%s\""
" class=\"ICON20x20\" />"
"</div>",
Gbl.Prefs.IconsURL,
2016-01-02 14:36:34 +01:00
Txt_SOCIAL_PUBLISHING_Shared,
Txt_SOCIAL_PUBLISHING_Shared);
2016-01-01 20:19:43 +01:00
Act_FormEnd ();
}
/*****************************************************************************/
/******************** Form to remove social publishing ***********************/
2015-12-30 02:08:08 +01:00
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
static void Soc_PutFormToRemoveSocialPublishing (long PubCod)
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 *****/
2016-01-02 01:56:48 +01:00
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
2016-01-02 02:33:23 +01:00
Act_FormStartAnchor (ActReqRemSocPubUsr,"timeline");
2016-01-02 01:56:48 +01:00
Usr_PutParamOtherUsrCodEncrypted ();
}
else
Act_FormStart (ActReqRemSocPubGbl);
2015-12-31 18:40:45 +01:00
Soc_PutHiddenParamPubCod (PubCod);
2016-01-01 20:35:43 +01:00
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_ICON ICON_HIGHLIGHT\">"
2015-12-30 02:08:08 +01:00
"<input type=\"image\""
" src=\"%s/remove-on64x64.png\""
" alt=\"%s\" title=\"%s\""
" class=\"ICON20x20\" />"
"</div>",
Gbl.Prefs.IconsURL,
Txt_Remove,
Txt_Remove);
Act_FormEnd ();
}
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
/*********** Put parameter with the code of a social publishing **************/
2015-12-30 02:08:08 +01:00
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
static void Soc_PutHiddenParamPubCod (long PubCod)
2015-12-30 02:08:08 +01:00
{
2015-12-31 18:40:45 +01:00
Par_PutHiddenParamLong ("PubCod",PubCod);
2015-12-30 02:08:08 +01:00
}
2015-12-30 12:40:13 +01:00
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
/*********** Get parameter with the code of a social publishing **************/
2015-12-30 12:40:13 +01:00
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
static long Soc_GetParamPubCod (void)
2015-12-30 12:40:13 +01:00
{
2015-12-31 14:25:28 +01:00
char LongStr[1+10+1]; // String that holds the social note code
2015-12-31 18:40:45 +01:00
long PubCod;
2015-12-30 12:40:13 +01:00
2015-12-31 14:25:28 +01:00
/* Get social note code */
2015-12-31 18:40:45 +01:00
Par_GetParToText ("PubCod",LongStr,1+10);
if (sscanf (LongStr,"%ld",&PubCod) != 1)
Lay_ShowErrorAndExit ("Wrong code of social publishing.");
2015-12-30 12:40:13 +01:00
2015-12-31 18:40:45 +01:00
return PubCod;
2015-12-30 12:40:13 +01:00
}
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
/************************* Share a social publishing *************************/
/*****************************************************************************/
2016-01-02 01:56:48 +01:00
void Soc_ShareSocialPubGbl (void)
{
/***** Share social publishing *****/
Soc_ShareSocialPublishing ();
/***** Write updated timeline after sharing (global) *****/
Soc_ShowTimelineGbl ();
}
void Soc_ShareSocialPubUsr (void)
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
/***** Show user's profile *****/
Prf_ShowUserProfile ();
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
/***** Share social publishing *****/
Soc_ShareSocialPublishing ();
/***** Write updated timeline after sharing (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
}
static void Soc_ShareSocialPublishing (void)
2016-01-01 20:19:43 +01:00
{
2016-01-02 14:36:34 +01:00
extern const char *Txt_SOCIAL_PUBLISHING_Shared;
2016-01-01 20:19:43 +01:00
struct SocialPublishing SocPub;
bool ICanShare;
bool IHavePublishedThisNote;
/***** Get the code of the social publishing to share *****/
SocPub.PubCod = Soc_GetParamPubCod ();
/***** Get data of social publishing *****/
Soc_GetDataOfSocialPublishingByCod (&SocPub);
ICanShare = (Gbl.Usrs.Me.Logged &&
SocPub.AuthorCod != Gbl.Usrs.Me.UsrDat.UsrCod); // I am not the author
if (ICanShare)
{
/***** Check if I have yet shared this social note *****/
IHavePublishedThisNote = Soc_CheckIfNoteIsYetPublishedByMe (SocPub.NotCod);
if (!IHavePublishedThisNote)
{
/***** Share (publish social note in timeline) *****/
SocPub.PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod;
Soc_PublishSocialNoteInTimeline (&SocPub);
/***** Message of success *****/
2016-01-02 14:36:34 +01:00
Lay_ShowAlert (Lay_SUCCESS,Txt_SOCIAL_PUBLISHING_Shared);
2016-01-01 20:19:43 +01:00
}
}
}
/*****************************************************************************/
/************** Unshare a previously shared social publishing ****************/
/*****************************************************************************/
2016-01-02 01:56:48 +01:00
void Soc_UnshareSocialPubGbl (void)
{
/***** Unshare a previously shared social publishing *****/
Soc_UnshareSocialPublishing ();
/***** Write updated timeline after unsharing (global) *****/
Soc_ShowTimelineGbl ();
}
void Soc_UnshareSocialPubUsr (void)
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
/***** Show user's profile *****/
Prf_ShowUserProfile ();
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
/***** Unshare a previously shared social publishing *****/
Soc_UnshareSocialPublishing ();
/***** Write updated timeline after unsharing (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
}
static void Soc_UnshareSocialPublishing (void)
2016-01-01 20:19:43 +01:00
{
2016-01-02 14:36:34 +01:00
extern const char *Txt_SOCIAL_PUBLISHING_Unshared;
2016-01-01 20:19:43 +01:00
struct SocialPublishing SocPub;
struct SocialNote SocNot;
bool ICanUnshare;
/***** Get the code of the social publishing to unshare *****/
SocPub.PubCod = Soc_GetParamPubCod ();
/***** Get data of social publishing *****/
Soc_GetDataOfSocialPublishingByCod (&SocPub);
/***** Get data of social note *****/
SocNot.NotCod = SocPub.NotCod;
Soc_GetDataOfSocialNoteByCod (&SocNot);
ICanUnshare = (Gbl.Usrs.Me.Logged &&
2016-01-02 14:36:34 +01:00
SocPub.AuthorCod != Gbl.Usrs.Me.UsrDat.UsrCod); // I have shared the note
2016-01-01 20:19:43 +01:00
if (ICanUnshare)
{
2016-01-02 14:36:34 +01:00
/***** Delete social publishing from database *****/
Soc_UnshareASocialPublishingFromDB (&SocNot);
2016-01-01 20:19:43 +01:00
2016-01-02 14:36:34 +01:00
/***** Message of success *****/
Lay_ShowAlert (Lay_SUCCESS,Txt_SOCIAL_PUBLISHING_Unshared);
2016-01-01 20:19:43 +01:00
}
}
2016-01-02 14:36:34 +01:00
/*****************************************************************************/
/**************** Unshare a social publishing from database ******************/
/*****************************************************************************/
static void Soc_UnshareASocialPublishingFromDB (const struct SocialNote *SocNot)
{
char Query[128];
/***** Remove social publishing *****/
sprintf (Query,"DELETE FROM social_timeline"
" WHERE NotCod='%ld'"
" AND PublisherCod='%ld'" // I have share this note
" AND AuthorCod<>'%ld'", // I am not the author
SocNot->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryDELETE (Query,"can not remove a social publishing");
/***** Check if this was the unique publishing of this note.
If so, remove the note *****/
Soc_CheckAndDeleteASocialNoteFromDB (SocNot);
}
2015-12-30 02:08:08 +01:00
/*****************************************************************************/
2016-01-02 01:56:48 +01:00
/**************** Request the removal of a social publishing *****************/
2015-12-30 16:33:36 +01:00
/*****************************************************************************/
2016-01-02 01:56:48 +01:00
void Soc_RequestRemSocialPubGbl (void)
{
/***** Request the removal of social publishing *****/
Soc_RequestRemovalSocialPublishing ();
/***** Write timeline again (global) *****/
Soc_ShowTimelineGbl ();
}
void Soc_RequestRemSocialPubUsr (void)
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
/***** Show user's profile *****/
Prf_ShowUserProfile ();
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
/***** Request the removal of social publishing *****/
Soc_RequestRemovalSocialPublishing ();
/***** 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
}
static void Soc_RequestRemovalSocialPublishing (void)
2015-12-30 16:33:36 +01:00
{
extern const char *Txt_Do_you_really_want_to_remove_the_following_comment;
extern const char *Txt_Remove;
2015-12-31 18:40:45 +01:00
struct SocialPublishing SocPub;
struct SocialNote SocNot;
2015-12-30 16:33:36 +01:00
bool ICanRemove;
struct UsrData UsrDat;
2015-12-31 18:40:45 +01:00
/***** Get the code of the social publishing to remove *****/
SocPub.PubCod = Soc_GetParamPubCod ();
/***** Get data of social publishing *****/
Soc_GetDataOfSocialPublishingByCod (&SocPub);
2015-12-30 16:33:36 +01:00
2015-12-31 14:25:28 +01:00
/***** Get data of social note *****/
2015-12-31 18:40:45 +01:00
SocNot.NotCod = SocPub.NotCod;
Soc_GetDataOfSocialNoteByCod (&SocNot);
2015-12-30 16:33:36 +01:00
ICanRemove = (Gbl.Usrs.Me.Logged &&
2016-01-02 14:36:34 +01:00
SocPub.PublisherCod == Gbl.Usrs.Me.UsrDat.UsrCod);
2015-12-30 16:33:36 +01:00
if (ICanRemove)
{
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Form to ask for confirmation to remove this social post *****/
/* Start form */
2016-01-02 01:56:48 +01:00
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
2016-01-02 02:33:23 +01:00
Act_FormStartAnchor (ActRemSocPubUsr,"timeline");
2016-01-02 01:56:48 +01:00
Usr_PutParamOtherUsrCodEncrypted ();
}
else
Act_FormStart (ActRemSocPubGbl);
2015-12-31 18:40:45 +01:00
Soc_PutHiddenParamPubCod (SocPub.PubCod);
2015-12-30 16:33:36 +01:00
Lay_ShowAlert (Lay_WARNING,Txt_Do_you_really_want_to_remove_the_following_comment);
2015-12-31 14:25:28 +01:00
/* Show social note */
2015-12-30 16:33:36 +01:00
Lay_StartRoundFrame ("560px",NULL);
fprintf (Gbl.F.Out,"<ul class=\"LIST_LEFT\">");
2015-12-31 18:40:45 +01:00
Soc_WriteSocialNote (&SocPub,&SocNot,&UsrDat,false);
2015-12-30 16:33:36 +01:00
fprintf (Gbl.F.Out,"</ul>");
Lay_EndRoundFrame ();
/* End form */
Lay_PutRemoveButton (Txt_Remove);
Act_FormEnd ();
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
}
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
/************************ Remove a social publishing *************************/
2015-12-30 02:08:08 +01:00
/*****************************************************************************/
2016-01-02 01:56:48 +01:00
void Soc_RemoveSocialPubGbl (void)
{
/***** Remove a social publishing *****/
Soc_RemoveSocialPublishing ();
/***** Write updated timeline after removing (global) *****/
Soc_ShowTimelineGbl ();
}
void Soc_RemoveSocialPubUsr (void)
{
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
/***** Show user's profile *****/
Prf_ShowUserProfile ();
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
/***** Remove a social publishing *****/
Soc_RemoveSocialPublishing ();
/***** 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
}
static void Soc_RemoveSocialPublishing (void)
2015-12-30 02:08:08 +01:00
{
2016-01-02 14:36:34 +01:00
extern const char *Txt_SOCIAL_PUBLISHING_Removed;
2015-12-31 18:40:45 +01:00
struct SocialPublishing SocPub;
struct SocialNote SocNot;
2015-12-30 12:40:13 +01:00
bool ICanRemove;
2015-12-30 02:08:08 +01:00
2015-12-31 18:40:45 +01:00
/***** Get the code of the social publishing to remove *****/
SocPub.PubCod = Soc_GetParamPubCod ();
/***** Get data of social publishing *****/
Soc_GetDataOfSocialPublishingByCod (&SocPub);
2015-12-30 12:40:13 +01:00
2015-12-31 14:25:28 +01:00
/***** Get data of social note *****/
2015-12-31 18:40:45 +01:00
SocNot.NotCod = SocPub.NotCod;
Soc_GetDataOfSocialNoteByCod (&SocNot);
2015-12-30 12:40:13 +01:00
ICanRemove = (Gbl.Usrs.Me.Logged &&
2016-01-02 14:36:34 +01:00
SocPub.PublisherCod == Gbl.Usrs.Me.UsrDat.UsrCod);
2015-12-30 12:40:13 +01:00
if (ICanRemove)
{
2016-01-01 20:19:43 +01:00
/***** Delete social publishing from database *****/
2016-01-02 14:36:34 +01:00
Soc_RemoveASocialPublishingFromDB (&SocPub,&SocNot);
2015-12-30 16:33:36 +01:00
/***** Message of success *****/
2016-01-02 14:36:34 +01:00
Lay_ShowAlert (Lay_SUCCESS,Txt_SOCIAL_PUBLISHING_Removed);
2015-12-30 12:40:13 +01:00
}
2015-12-30 02:08:08 +01:00
}
2015-12-30 12:40:13 +01:00
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
/**************** Delete a social publishing from database *******************/
/*****************************************************************************/
2016-01-02 14:36:34 +01:00
static void Soc_RemoveASocialPublishingFromDB (const struct SocialPublishing *SocPub,
2016-01-01 20:19:43 +01:00
const struct SocialNote *SocNot)
{
char Query[128];
/***** Remove social publishing *****/
2016-01-02 14:36:34 +01:00
sprintf (Query,"DELETE FROM social_timeline"
" WHERE PubCod='%ld'"
" AND NotCod='%ld'" // Extra check: this is the note
" AND PublisherCod='%ld'" // Extra check: I have published this note
" AND AuthorCod='%ld'", // Extra check: I am the author
SocPub->PubCod,
SocNot->NotCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
2016-01-01 20:19:43 +01:00
DB_QueryDELETE (Query,"can not remove a social publishing");
2016-01-02 14:36:34 +01:00
/***** Check if this was the unique publishing of this note.
If so, remove the note *****/
Soc_CheckAndDeleteASocialNoteFromDB (SocNot);
}
/*****************************************************************************/
/**** Check if deletion is possible and delete a social note from database ***/
/*****************************************************************************/
2016-01-01 20:19:43 +01:00
2016-01-02 14:36:34 +01:00
static void Soc_CheckAndDeleteASocialNoteFromDB (const struct SocialNote *SocNot)
{
char Query[128];
unsigned long NumPubs;
/***** Count number of times this note is published *****/
NumPubs = Soc_GetNumPubsOfANote (SocNot->NotCod);
if (NumPubs == 0) // There are no publishings of this note
2016-01-01 20:19:43 +01:00
{
/***** Remove social note *****/
sprintf (Query,"DELETE FROM social_notes WHERE NotCod='%ld'",
SocNot->NotCod);
DB_QueryDELETE (Query,"can not remove a social note");
/***** Remove social post *****/
if (SocNot->NoteType == Soc_NOTE_SOCIAL_POST)
{
sprintf (Query,"DELETE FROM social_posts WHERE PstCod='%ld'",
SocNot->Cod);
DB_QueryDELETE (Query,"can not remove a social post");
}
}
}
/*****************************************************************************/
/***** Check if I have published a social note (I authored or shared it) *****/
/*****************************************************************************/
static bool Soc_CheckIfNoteIsYetPublishedByMe (long NotCod)
{
char Query[128];
sprintf (Query,"SELECT COUNT(*) FROM social_timeline"
" WHERE NotCod='%ld' AND PublisherCod='%ld'",
NotCod,Gbl.Usrs.Me.UsrDat.UsrCod);
return (DB_QueryCOUNT (Query,"can not check if you have published a social note") != 0);
}
2015-12-30 12:40:13 +01:00
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
/*********** Get number of publishings in timeline of a note code ************/
/*****************************************************************************/
static unsigned long Soc_GetNumPubsOfANote (long NotCod)
{
char Query[128];
sprintf (Query,"SELECT COUNT(*) FROM social_timeline WHERE NotCod='%ld'",
NotCod);
return DB_QueryCOUNT (Query,"can not get number of publishing of a note");
}
/*****************************************************************************/
/********* Get data of social publishing in timeline using its code **********/
2015-12-30 12:40:13 +01:00
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
static void Soc_GetDataOfSocialPublishingByCod (struct SocialPublishing *SocPub)
{
char Query[256];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
/***** Get data of social publishing from database *****/
sprintf (Query,"SELECT PubCod,AuthorCod,PublisherCod,NotCod,UNIX_TIMESTAMP(TimePublish)"
" FROM social_timeline"
" WHERE PubCod='%ld'",
SocPub->PubCod);
2016-01-02 14:36:34 +01:00
if (DB_QuerySELECT (Query,&mysql_res,"can not get data of social publishing"))
2015-12-31 18:40:45 +01:00
{
/***** Get social note *****/
row = mysql_fetch_row (mysql_res);
Soc_GetDataOfSocialPublishingFromRow (row,SocPub);
}
else
{
/***** Reset fields of social publishing *****/
SocPub->AuthorCod = -1L;
SocPub->PublisherCod = -1L;
SocPub->NotCod = -1L;
SocPub->DateTimeUTC = (time_t) 0;
}
}
/*****************************************************************************/
/**************** Get data of social note using its code *********************/
/*****************************************************************************/
static void Soc_GetDataOfSocialNoteByCod (struct SocialNote *SocNot)
2015-12-30 12:40:13 +01:00
{
char Query[256];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2015-12-31 14:25:28 +01:00
/***** Get data of social note from database *****/
2016-01-02 13:21:25 +01:00
sprintf (Query,"SELECT NotCod,NoteType,UsrCod,HieCod,Cod,UNIX_TIMESTAMP(TimeNote)"
2015-12-31 14:25:28 +01:00
" FROM social_notes"
2015-12-31 14:47:22 +01:00
" WHERE NotCod='%ld'",
2015-12-31 18:40:45 +01:00
SocNot->NotCod);
2015-12-31 14:25:28 +01:00
if (DB_QuerySELECT (Query,&mysql_res,"can not get data of social note"))
2015-12-30 12:40:13 +01:00
{
2015-12-31 14:25:28 +01:00
/***** Get social note *****/
2015-12-30 12:40:13 +01:00
row = mysql_fetch_row (mysql_res);
2015-12-31 18:40:45 +01:00
Soc_GetDataOfSocialNoteFromRow (row,SocNot);
2015-12-30 12:40:13 +01:00
}
else
{
2015-12-31 14:25:28 +01:00
/***** Reset fields of social note *****/
2015-12-31 18:40:45 +01:00
SocNot->NoteType = Soc_NOTE_UNKNOWN;
SocNot->UsrCod = -1L;
2016-01-02 13:21:25 +01:00
SocNot->HieCod = -1L;
2015-12-31 18:40:45 +01:00
SocNot->Cod = -1L;
SocNot->DateTimeUTC = (time_t) 0;
2015-12-30 12:40:13 +01:00
}
}
2015-12-30 16:33:36 +01:00
/*****************************************************************************/
2015-12-31 18:40:45 +01:00
/*************** Get data of social note using its code **********************/
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
{
/* 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
2015-12-31 14:25:28 +01:00
/* Get note type (row[1]) */
2016-01-02 14:36:34 +01:00
SocNot->NoteType = Soc_GetSocialNoteFromDB ((const char *) row[1]);
2015-12-30 16:33:36 +01:00
/* Get (from) user code (row[2]) */
2016-01-02 14:36:34 +01:00
SocNot->UsrCod = Str_ConvertStrCodToLongCod (row[2]);
2015-12-30 16:33:36 +01:00
2016-01-02 13:21:25 +01:00
/* Get hierarchy code (row[3]) */
2016-01-02 14:36:34 +01:00
SocNot->HieCod = Str_ConvertStrCodToLongCod (row[3]);
2015-12-30 16:33:36 +01:00
2016-01-02 13:21:25 +01:00
/* Get file/post... code (row[4]) */
2016-01-02 14:36:34 +01:00
SocNot->Cod = Str_ConvertStrCodToLongCod (row[4]);
2015-12-30 16:33:36 +01:00
2016-01-02 13:21:25 +01:00
/* Get time of the note (row[5]) */
SocNot->DateTimeUTC = Dat_GetUNIXTimeFromStr (row[5]);
2015-12-31 18:40:45 +01:00
}
/*****************************************************************************/
/****** Get social note type from string number coming from database *********/
/*****************************************************************************/
static Soc_NoteType_t Soc_GetSocialNoteFromDB (const char *Str)
{
unsigned UnsignedNum;
if (sscanf (Str,"%u",&UnsignedNum) == 1)
if (UnsignedNum < Soc_NUM_SOCIAL_NOTES)
return (Soc_NoteType_t) UnsignedNum;
return Soc_NOTE_UNKNOWN;
2015-12-30 16:33:36 +01:00
}