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.
|
|
|
|
|
Copyright (C) 1999-2015 Antonio Ca<EFBFBD>as Vargas
|
|
|
|
|
|
|
|
|
|
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"
|
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
|
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 */
|
2015-12-31 14:25:28 +01:00
|
|
|
|
ActSeeSocAct, // Soc_NOTE_SOCIAL_POST (action not used)
|
|
|
|
|
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 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 14:25:28 +01:00
|
|
|
|
Soc_SocialNote_t SocialNote;
|
2015-12-30 12:40:13 +01:00
|
|
|
|
long UsrCod;
|
|
|
|
|
long CtyCod;
|
|
|
|
|
long InsCod;
|
|
|
|
|
long CtrCod;
|
|
|
|
|
long DegCod;
|
|
|
|
|
long CrsCod;
|
|
|
|
|
long Cod;
|
|
|
|
|
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 ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-12-30 18:36:10 +01:00
|
|
|
|
static unsigned long Soc_ShowTimeline (const char *Query,Act_Action_t UpdateAction);
|
2015-12-31 14:25:28 +01:00
|
|
|
|
static Soc_SocialNote_t Soc_GetSocialNoteFromDB (const char *Str);
|
|
|
|
|
static void Soc_WriteSocialNote (const struct SocialNote *Soc,
|
2015-12-30 16:33:36 +01:00
|
|
|
|
struct UsrData *UsrDat,
|
|
|
|
|
bool PutIconRemove);
|
2015-12-31 14:25:28 +01:00
|
|
|
|
static void Soc_WriteNoteDate (time_t TimeUTC);
|
|
|
|
|
static void Soc_StartFormGoToAction (Soc_SocialNote_t SocialNote,
|
2015-12-29 13:18:25 +01:00
|
|
|
|
long CrsCod,long Cod);
|
2015-12-31 14:25:28 +01:00
|
|
|
|
static void Soc_GetNoteSummary (const struct SocialNote *Soc,
|
|
|
|
|
char *SummaryStr,unsigned MaxChars);
|
2015-12-28 19:23:42 +01:00
|
|
|
|
|
2015-12-30 12:40:13 +01:00
|
|
|
|
static void Soc_PutLinkToWriteANewPost (void);
|
|
|
|
|
static void Soc_GetAndWriteSocialPost (long PstCod);
|
|
|
|
|
|
2015-12-31 14:47:22 +01:00
|
|
|
|
static void Soc_PutFormToRemoveSocialNote (long NotCod);
|
|
|
|
|
static void Soc_PutHiddenParamNotCod (long NotCod);
|
|
|
|
|
static long Soc_GetParamNotCod (void);
|
2015-12-31 14:25:28 +01:00
|
|
|
|
static void Soc_GetDataOfSocialNoteByCod (struct SocialNote *Soc);
|
|
|
|
|
static void Soc_GetDataOfSocialNoteFromRow (MYSQL_ROW row,struct SocialNote *Soc);
|
2015-12-29 23:44:28 +01:00
|
|
|
|
|
2015-12-29 14:24:37 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********** Show social activity (timeline) of a selected user **************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Soc_ShowUsrTimeline (long UsrCod)
|
|
|
|
|
{
|
|
|
|
|
char Query[512];
|
|
|
|
|
|
|
|
|
|
/***** Build query to show timeline including the users I am following *****/
|
2015-12-31 14:47:22 +01:00
|
|
|
|
sprintf (Query,"SELECT NotCod,SocialNote,UsrCod,"
|
2015-12-29 14:24:37 +01:00
|
|
|
|
"CtyCod,InsCod,CtrCod,DegCod,CrsCod,"
|
2015-12-31 14:25:28 +01:00
|
|
|
|
"Cod,UNIX_TIMESTAMP(TimeNote)"
|
|
|
|
|
" FROM social_notes"
|
2015-12-29 14:24:37 +01:00
|
|
|
|
" WHERE UsrCod='%ld'"
|
2015-12-31 14:47:22 +01:00
|
|
|
|
" ORDER BY NotCod DESC LIMIT 10",
|
2015-12-29 14:24:37 +01:00
|
|
|
|
UsrCod);
|
|
|
|
|
|
|
|
|
|
/***** Show timeline *****/
|
2015-12-30 18:36:10 +01:00
|
|
|
|
Soc_ShowTimeline (Query,ActUnk);
|
2015-12-29 14:24:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***** Show social activity (timeline) including all the users I follow ******/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Soc_ShowFollowingTimeline (void)
|
|
|
|
|
{
|
|
|
|
|
char Query[512];
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/***** Link to write a new social post (public comment) *****/
|
2015-12-30 00:58:25 +01:00
|
|
|
|
if (Gbl.CurrentAct != ActReqSocPst)
|
|
|
|
|
Soc_PutLinkToWriteANewPost ();
|
|
|
|
|
|
2015-12-29 14:57:38 +01:00
|
|
|
|
/***** Show warning if I do not follow anyone *****/
|
|
|
|
|
if (!Fol_GetNumFollowing (Gbl.Usrs.Me.UsrDat.UsrCod))
|
2015-12-29 14:24:37 +01:00
|
|
|
|
Lay_ShowAlert (Lay_INFO,"Usted no sigue a ningún usuario."); // Need translation!!!
|
2015-12-29 14:57:38 +01:00
|
|
|
|
|
|
|
|
|
/***** Build query to show timeline including the users I am following *****/
|
2015-12-31 14:47:22 +01:00
|
|
|
|
sprintf (Query,"SELECT NotCod,SocialNote,UsrCod,"
|
2015-12-29 14:57:38 +01:00
|
|
|
|
"CtyCod,InsCod,CtrCod,DegCod,CrsCod,"
|
2015-12-31 14:25:28 +01:00
|
|
|
|
"Cod,UNIX_TIMESTAMP(TimeNote)"
|
|
|
|
|
" FROM social_notes"
|
2015-12-29 14:57:38 +01:00
|
|
|
|
" WHERE UsrCod IN"
|
|
|
|
|
" (SELECT '%ld'"
|
|
|
|
|
" UNION"
|
|
|
|
|
" SELECT FollowedCod FROM usr_follow WHERE FollowerCod='%ld')"
|
2015-12-31 14:47:22 +01:00
|
|
|
|
" ORDER BY NotCod DESC LIMIT 10",
|
2015-12-29 14:57:38 +01:00
|
|
|
|
Gbl.Usrs.Me.UsrDat.UsrCod,
|
|
|
|
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
|
|
|
|
|
|
|
|
/***** Show timeline *****/
|
2015-12-30 18:36:10 +01:00
|
|
|
|
if (!Soc_ShowTimeline (Query,ActSeeSocAct))
|
2015-12-29 14:57:38 +01:00
|
|
|
|
Lay_ShowAlert (Lay_INFO,"No hay actividad pública."); // Need translation!!!
|
2015-12-29 14:24:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-28 19:23:42 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********************** Show social activity (timeline) *********************/
|
|
|
|
|
/*****************************************************************************/
|
2015-12-30 18:36:10 +01:00
|
|
|
|
// UpdateAction == ActUnk ==> no form to update is displayed
|
2015-12-28 19:23:42 +01:00
|
|
|
|
|
2015-12-30 18:36:10 +01:00
|
|
|
|
static unsigned long Soc_ShowTimeline (const char *Query,Act_Action_t UpdateAction)
|
2015-12-28 19:23:42 +01:00
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Public_activity;
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
2015-12-31 14:25:28 +01:00
|
|
|
|
unsigned long NumNotes;
|
|
|
|
|
unsigned long NumNote;
|
|
|
|
|
struct SocialNote Soc;
|
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 14:25:28 +01:00
|
|
|
|
NumNotes = DB_QuerySELECT (Query,&mysql_res,"can not get social notes");
|
2015-12-28 19:23:42 +01:00
|
|
|
|
|
|
|
|
|
/***** List my timeline *****/
|
2015-12-31 14:25:28 +01:00
|
|
|
|
if (NumNotes) // Notes found
|
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 *****/
|
|
|
|
|
if (UpdateAction != ActUnk)
|
|
|
|
|
Act_PutLinkToUpdateAction (UpdateAction);
|
|
|
|
|
|
|
|
|
|
/***** 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 14:25:28 +01:00
|
|
|
|
/***** List notes one by one *****/
|
|
|
|
|
for (NumNote = 0;
|
|
|
|
|
NumNote < NumNotes;
|
|
|
|
|
NumNote++)
|
2015-12-28 19:23:42 +01:00
|
|
|
|
{
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/* Get next social note */
|
2015-12-28 19:23:42 +01:00
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
2015-12-31 14:25:28 +01:00
|
|
|
|
Soc_GetDataOfSocialNoteFromRow (row,&Soc);
|
2015-12-28 19:23:42 +01:00
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/* Write row for this social note */
|
|
|
|
|
Soc_WriteSocialNote (&Soc,&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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Free structure that stores the query result *****/
|
|
|
|
|
DB_FreeMySQLResult (&mysql_res);
|
2015-12-29 14:24:37 +01:00
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
return NumNotes;
|
2015-12-28 19:23:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2015-12-31 14:47:22 +01:00
|
|
|
|
/****** Get social note type from string number coming from database *********/
|
2015-12-28 19:23:42 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
static Soc_SocialNote_t Soc_GetSocialNoteFromDB (const char *Str)
|
2015-12-28 19:23:42 +01:00
|
|
|
|
{
|
|
|
|
|
unsigned UnsignedNum;
|
|
|
|
|
|
|
|
|
|
if (sscanf (Str,"%u",&UnsignedNum) == 1)
|
2015-12-31 14:25:28 +01:00
|
|
|
|
if (UnsignedNum < Soc_NUM_SOCIAL_NOTES)
|
|
|
|
|
return (Soc_SocialNote_t) UnsignedNum;
|
2015-12-28 19:23:42 +01:00
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
return Soc_NOTE_UNKNOWN;
|
2015-12-28 19:23:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-30 16:33:36 +01:00
|
|
|
|
/*****************************************************************************/
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/**************************** Write social note ******************************/
|
2015-12-30 16:33:36 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
static void Soc_WriteSocialNote (const struct SocialNote *Soc,
|
2015-12-30 16:33:36 +01:00
|
|
|
|
struct UsrData *UsrDat,
|
|
|
|
|
bool PutIconRemove)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
extern const char *Txt_Country;
|
|
|
|
|
struct Country Cty;
|
|
|
|
|
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 */
|
|
|
|
|
UsrDat->UsrCod = Soc->UsrCod;
|
|
|
|
|
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (UsrDat);
|
|
|
|
|
|
|
|
|
|
/* Get country data */
|
|
|
|
|
Cty.CtyCod = Soc->CtyCod;
|
|
|
|
|
Cty_GetDataOfCountryByCod (&Cty,Cty_GET_BASIC_DATA);
|
|
|
|
|
|
|
|
|
|
/* Get institution data */
|
|
|
|
|
Ins.InsCod = Soc->InsCod;
|
|
|
|
|
Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA);
|
|
|
|
|
|
|
|
|
|
/* Get centre data */
|
|
|
|
|
Ctr.CtrCod = Soc->CtrCod;
|
|
|
|
|
Ctr_GetDataOfCentreByCod (&Ctr);
|
|
|
|
|
|
|
|
|
|
/* Get degree data */
|
|
|
|
|
Deg.DegCod = Soc->DegCod;
|
|
|
|
|
Deg_GetDataOfDegreeByCod (&Deg);
|
|
|
|
|
|
|
|
|
|
/* Get course data */
|
|
|
|
|
Crs.CrsCod = Soc->CrsCod;
|
|
|
|
|
Crs_GetDataOfCourseByCod (&Crs);
|
|
|
|
|
|
|
|
|
|
/* Get forum type of the post */
|
2015-12-31 14:25:28 +01:00
|
|
|
|
if (Soc->SocialNote == Soc_NOTE_FORUM_POST)
|
2015-12-30 16:33:36 +01:00
|
|
|
|
{
|
|
|
|
|
Gbl.Forum.ForumType = For_GetForumTypeOfAPost (Soc->Cod);
|
|
|
|
|
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 *****/
|
|
|
|
|
fprintf (Gbl.F.Out,"<li>");
|
|
|
|
|
|
|
|
|
|
/***** 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>");
|
|
|
|
|
|
|
|
|
|
/***** Right: author's name, time and summary *****/
|
|
|
|
|
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 14:25:28 +01:00
|
|
|
|
Soc_WriteNoteDate (Soc->DateTimeUTC);
|
2015-12-30 16:33:36 +01:00
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
if (Soc->SocialNote == Soc_NOTE_SOCIAL_POST)
|
2015-12-30 16:33:36 +01:00
|
|
|
|
{
|
|
|
|
|
/* Write post content */
|
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"DAT\">");
|
|
|
|
|
Soc_GetAndWriteSocialPost (Soc->Cod);
|
|
|
|
|
fprintf (Gbl.F.Out,"</div>");
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/* Write form to remove this note */
|
2015-12-30 16:33:36 +01:00
|
|
|
|
if (PutIconRemove &&
|
|
|
|
|
Gbl.Usrs.Me.Logged &&
|
|
|
|
|
UsrDat->UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // I am the author
|
2015-12-31 14:47:22 +01:00
|
|
|
|
Soc_PutFormToRemoveSocialNote (Soc->NotCod);
|
2015-12-30 16:33:36 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/* Write note type and location */
|
2015-12-30 16:33:36 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"<div>");
|
2015-12-31 14:25:28 +01:00
|
|
|
|
Soc_StartFormGoToAction (Soc->SocialNote,Crs.CrsCod,Soc->Cod);
|
|
|
|
|
Act_LinkFormSubmit (Txt_SOCIAL_NOTE[Soc->SocialNote],
|
2015-12-30 16:33:36 +01:00
|
|
|
|
The_ClassForm[Gbl.Prefs.Theme]);
|
|
|
|
|
fprintf (Gbl.F.Out,"%s</a>",
|
2015-12-31 14:25:28 +01:00
|
|
|
|
Txt_SOCIAL_NOTE[Soc->SocialNote]);
|
2015-12-30 16:33:36 +01:00
|
|
|
|
Act_FormEnd ();
|
|
|
|
|
fprintf (Gbl.F.Out,"</div>");
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
if (Soc->SocialNote == Soc_NOTE_FORUM_POST)
|
2015-12-30 16:33:36 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
|
|
|
|
|
Txt_Forum,ForumName);
|
|
|
|
|
else if (Crs.CrsCod > 0)
|
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
|
|
|
|
|
Txt_Course,Crs.ShortName);
|
|
|
|
|
else if (Deg.DegCod > 0)
|
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
|
|
|
|
|
Txt_Degree,Deg.ShortName);
|
|
|
|
|
else if (Ctr.CtrCod > 0)
|
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
|
|
|
|
|
Txt_Centre,Ctr.ShortName);
|
|
|
|
|
else if (Ins.InsCod > 0)
|
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
|
|
|
|
|
Txt_Institution,Ins.ShortName);
|
|
|
|
|
else if (Cty.CtyCod > 0)
|
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s: %s</div>",
|
|
|
|
|
Txt_Country,Cty.Name[Gbl.Prefs.Language]);
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/* Write content of the note */
|
|
|
|
|
Soc_GetNoteSummary (Soc,SummaryStr,Soc_MAX_BYTES_SUMMARY);
|
2015-12-30 16:33:36 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"DAT\">%s</div>",SummaryStr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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,' ','%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
|
|
|
|
}
|
|
|
|
|
|
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 14:25:28 +01:00
|
|
|
|
static void Soc_StartFormGoToAction (Soc_SocialNote_t SocialNote,
|
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 *****/
|
|
|
|
|
switch (SocialNote)
|
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 14:25:28 +01:00
|
|
|
|
switch (SocialNote)
|
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:
|
|
|
|
|
Act_FormStart (Soc_DefaultActions[SocialNote]);
|
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 14:25:28 +01:00
|
|
|
|
Act_FormStart (Soc_DefaultActions[SocialNote]);
|
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 14:25:28 +01:00
|
|
|
|
static void Soc_GetNoteSummary (const struct SocialNote *Soc,
|
|
|
|
|
char *SummaryStr,unsigned MaxChars)
|
2015-12-28 19:23:42 +01:00
|
|
|
|
{
|
|
|
|
|
SummaryStr[0] = '\0';
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
switch (Soc->SocialNote)
|
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-30 16:33:36 +01:00
|
|
|
|
Brw_GetSummaryAndContentOrSharedFile (SummaryStr,NULL,Soc->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-30 16:33:36 +01:00
|
|
|
|
Exa_GetSummaryAndContentExamAnnouncement (SummaryStr,NULL,Soc->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-30 16:33:36 +01:00
|
|
|
|
For_GetSummaryAndContentForumPst (SummaryStr,NULL,Soc->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-30 20:11:50 +01:00
|
|
|
|
Not_GetSummaryAndContentNotice (SummaryStr,NULL,Soc->Cod,MaxChars,false);
|
|
|
|
|
break;
|
2015-12-28 19:23:42 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-28 20:46:48 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2015-12-31 14:47:22 +01:00
|
|
|
|
/********************* Store a social note into database *********************/
|
2015-12-28 20:46:48 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
void Soc_StoreSocialNote (Soc_SocialNote_t SocialNote,long Cod)
|
2015-12-28 20:46:48 +01:00
|
|
|
|
{
|
|
|
|
|
char Query[512];
|
|
|
|
|
long CtyCod;
|
|
|
|
|
long InsCod;
|
|
|
|
|
long CtrCod;
|
|
|
|
|
long DegCod;
|
|
|
|
|
long CrsCod;
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
if (SocialNote == Soc_NOTE_FORUM_POST)
|
2015-12-28 20:46:48 +01:00
|
|
|
|
{
|
|
|
|
|
// CtyCod = Gbl.Forum.Cty.CtyCod;
|
|
|
|
|
// InsCod = Gbl.Forum.Ins.InsCod;
|
|
|
|
|
// CtrCod = Gbl.Forum.Ctr.CtrCod;
|
|
|
|
|
// DegCod = Gbl.Forum.Deg.DegCod;
|
|
|
|
|
// CrsCod = Gbl.Forum.Crs.CrsCod;
|
|
|
|
|
CtyCod = -1L;
|
|
|
|
|
InsCod = -1L;
|
|
|
|
|
CtrCod = -1L;
|
|
|
|
|
DegCod = -1L;
|
|
|
|
|
CrsCod = -1L;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CtyCod = Gbl.CurrentCty.Cty.CtyCod;
|
|
|
|
|
InsCod = Gbl.CurrentIns.Ins.InsCod;
|
|
|
|
|
CtrCod = Gbl.CurrentCtr.Ctr.CtrCod;
|
|
|
|
|
DegCod = Gbl.CurrentDeg.Deg.DegCod;
|
|
|
|
|
CrsCod = Gbl.CurrentCrs.Crs.CrsCod;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/***** Store social note *****/
|
|
|
|
|
sprintf (Query,"INSERT INTO social_notes (SocialNote,UsrCod,"
|
2015-12-28 20:46:48 +01:00
|
|
|
|
"CtyCod,InsCod,CtrCod,DegCod,CrsCod,"
|
2015-12-31 14:25:28 +01:00
|
|
|
|
"Cod,TimeNote)"
|
2015-12-28 20:46:48 +01:00
|
|
|
|
" VALUES ('%u','%ld',"
|
|
|
|
|
"'%ld','%ld','%ld','%ld','%ld',"
|
|
|
|
|
"'%ld',NOW())",
|
2015-12-31 14:25:28 +01:00
|
|
|
|
(unsigned) SocialNote,Gbl.Usrs.Me.UsrDat.UsrCod,
|
2015-12-28 20:46:48 +01:00
|
|
|
|
CtyCod,InsCod,CtrCod,DegCod,CrsCod,
|
|
|
|
|
Cod);
|
2015-12-31 14:25:28 +01:00
|
|
|
|
DB_QueryINSERT (Query,"can not create new 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 *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Soc_PutLinkToWriteANewPost (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_New_comment;
|
|
|
|
|
|
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
|
|
|
|
|
Lay_PutContextualLink (ActReqSocPst,NULL,"write64x64.gif",
|
|
|
|
|
Txt_New_comment,Txt_New_comment);
|
|
|
|
|
fprintf (Gbl.F.Out,"</div>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Form to write a new public comment ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Soc_FormSocialPost (void)
|
|
|
|
|
{
|
|
|
|
|
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 */
|
|
|
|
|
Act_FormStart (ActRcvSocPst);
|
|
|
|
|
|
|
|
|
|
/* 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 ();
|
|
|
|
|
|
|
|
|
|
/***** Write current timeline *****/
|
|
|
|
|
Soc_ShowFollowingTimeline ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Receive and store a new public post *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Soc_ReceiveSocialPost (void)
|
|
|
|
|
{
|
|
|
|
|
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 */
|
|
|
|
|
Soc_StoreSocialNote (Soc_NOTE_SOCIAL_POST,PstCod);
|
2015-12-30 12:40:13 +01:00
|
|
|
|
|
|
|
|
|
/***** Write current timeline *****/
|
|
|
|
|
Soc_ShowFollowingTimeline ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************** 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 *****/
|
2015-12-31 14:25:28 +01:00
|
|
|
|
sprintf (Query,"SELECT Content FROM social_posts WHERE PstCod='%ld'",
|
2015-12-30 12:40:13 +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)
|
|
|
|
|
{
|
|
|
|
|
/***** 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-30 02:08:08 +01:00
|
|
|
|
/*****************************************************************************/
|
2015-12-31 14:47:22 +01:00
|
|
|
|
/*********************** Form to remove social note **************************/
|
2015-12-30 02:08:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-12-31 14:47:22 +01:00
|
|
|
|
static void Soc_PutFormToRemoveSocialNote (long NotCod)
|
2015-12-30 02:08:08 +01:00
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Remove;
|
|
|
|
|
|
|
|
|
|
/***** Form to remove social post *****/
|
2015-12-31 14:25:28 +01:00
|
|
|
|
Act_FormStart (ActReqRemSocNot);
|
2015-12-31 14:47:22 +01:00
|
|
|
|
Soc_PutHiddenParamNotCod (NotCod);
|
2015-12-30 02:08:08 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_OPT ICON_HIGHLIGHT\">"
|
|
|
|
|
"<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 14:47:22 +01:00
|
|
|
|
/************** Put parameter with the code of a social note *****************/
|
2015-12-30 02:08:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-12-31 14:47:22 +01:00
|
|
|
|
static void Soc_PutHiddenParamNotCod (long NotCod)
|
2015-12-30 02:08:08 +01:00
|
|
|
|
{
|
2015-12-31 14:47:22 +01:00
|
|
|
|
Par_PutHiddenParamLong ("NotCod",NotCod);
|
2015-12-30 02:08:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-30 12:40:13 +01:00
|
|
|
|
/*****************************************************************************/
|
2015-12-31 14:47:22 +01:00
|
|
|
|
/************** Get parameter with the code of a social note *****************/
|
2015-12-30 12:40:13 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-12-31 14:47:22 +01:00
|
|
|
|
static long Soc_GetParamNotCod (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 14:47:22 +01:00
|
|
|
|
long NotCod;
|
2015-12-30 12:40:13 +01:00
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/* Get social note code */
|
2015-12-31 14:47:22 +01:00
|
|
|
|
Par_GetParToText ("NotCod",LongStr,1+10);
|
|
|
|
|
if (sscanf (LongStr,"%ld",&NotCod) != 1)
|
2015-12-31 14:25:28 +01:00
|
|
|
|
Lay_ShowErrorAndExit ("Wrong code of social note.");
|
2015-12-30 12:40:13 +01:00
|
|
|
|
|
2015-12-31 14:47:22 +01:00
|
|
|
|
return NotCod;
|
2015-12-30 12:40:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-30 02:08:08 +01:00
|
|
|
|
/*****************************************************************************/
|
2015-12-31 14:47:22 +01:00
|
|
|
|
/******************* Request the removal of a social note ********************/
|
2015-12-30 16:33:36 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
void Soc_RequestRemovalSocialNote (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 14:25:28 +01:00
|
|
|
|
struct SocialNote Soc;
|
2015-12-30 16:33:36 +01:00
|
|
|
|
bool ICanRemove;
|
|
|
|
|
struct UsrData UsrDat;
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/***** Get the code of the social note to remove *****/
|
2015-12-31 14:47:22 +01:00
|
|
|
|
Soc.NotCod = Soc_GetParamNotCod ();
|
2015-12-30 16:33:36 +01:00
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/***** Get data of social note *****/
|
|
|
|
|
Soc_GetDataOfSocialNoteByCod (&Soc);
|
2015-12-30 16:33:36 +01:00
|
|
|
|
|
|
|
|
|
ICanRemove = (Gbl.Usrs.Me.Logged &&
|
|
|
|
|
Soc.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod &&
|
2015-12-31 14:25:28 +01:00
|
|
|
|
Soc.SocialNote == Soc_NOTE_SOCIAL_POST);
|
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 */
|
2015-12-31 14:25:28 +01:00
|
|
|
|
Act_FormStart (ActRemSocNot);
|
2015-12-31 14:47:22 +01:00
|
|
|
|
Soc_PutHiddenParamNotCod (Soc.NotCod);
|
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 14:25:28 +01:00
|
|
|
|
Soc_WriteSocialNote (&Soc,&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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Write timeline again *****/
|
|
|
|
|
Soc_ShowFollowingTimeline ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2015-12-31 14:47:22 +01:00
|
|
|
|
/*************************** Remove a social note ****************************/
|
2015-12-30 02:08:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
void Soc_RemoveSocialNote (void)
|
2015-12-30 02:08:08 +01:00
|
|
|
|
{
|
2015-12-30 16:33:36 +01:00
|
|
|
|
extern const char *Txt_Comment_removed;
|
2015-12-31 14:25:28 +01:00
|
|
|
|
struct SocialNote Soc;
|
2015-12-30 12:40:13 +01:00
|
|
|
|
bool ICanRemove;
|
|
|
|
|
char Query[128];
|
2015-12-30 02:08:08 +01:00
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/***** Get the code of the social note to remove *****/
|
2015-12-31 14:47:22 +01:00
|
|
|
|
Soc.NotCod = Soc_GetParamNotCod ();
|
2015-12-30 12:40:13 +01:00
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/***** Get data of social note *****/
|
|
|
|
|
Soc_GetDataOfSocialNoteByCod (&Soc);
|
2015-12-30 12:40:13 +01:00
|
|
|
|
|
|
|
|
|
ICanRemove = (Gbl.Usrs.Me.Logged &&
|
|
|
|
|
Soc.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod &&
|
2015-12-31 14:25:28 +01:00
|
|
|
|
Soc.SocialNote == Soc_NOTE_SOCIAL_POST);
|
2015-12-30 12:40:13 +01:00
|
|
|
|
if (ICanRemove)
|
|
|
|
|
{
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/***** Remove social note *****/
|
2015-12-31 14:47:22 +01:00
|
|
|
|
sprintf (Query,"DELETE FROM social_notes WHERE NotCod='%ld'",
|
|
|
|
|
Soc.NotCod);
|
2015-12-31 14:25:28 +01:00
|
|
|
|
DB_QueryDELETE (Query,"can not remove a social note");
|
2015-12-30 12:40:13 +01:00
|
|
|
|
|
|
|
|
|
/***** Remove social post *****/
|
2015-12-31 14:25:28 +01:00
|
|
|
|
if (Soc.SocialNote == Soc_NOTE_SOCIAL_POST)
|
2015-12-30 12:40:13 +01:00
|
|
|
|
{
|
2015-12-31 14:25:28 +01:00
|
|
|
|
sprintf (Query,"DELETE FROM social_posts WHERE PstCod='%ld'",
|
|
|
|
|
Soc.Cod);
|
2015-12-30 12:40:13 +01:00
|
|
|
|
DB_QueryDELETE (Query,"can not remove a social post");
|
|
|
|
|
}
|
2015-12-30 16:33:36 +01:00
|
|
|
|
|
|
|
|
|
/***** Message of success *****/
|
|
|
|
|
Lay_ShowAlert (Lay_SUCCESS,Txt_Comment_removed);
|
2015-12-30 12:40:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Write timeline after removing *****/
|
2015-12-30 02:08:08 +01:00
|
|
|
|
Soc_ShowFollowingTimeline ();
|
|
|
|
|
}
|
2015-12-30 12:40:13 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Get assignment data using its code **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
static void Soc_GetDataOfSocialNoteByCod (struct SocialNote *Soc)
|
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 *****/
|
2015-12-31 14:47:22 +01:00
|
|
|
|
sprintf (Query,"SELECT NotCod,SocialNote,UsrCod,"
|
2015-12-30 12:40:13 +01:00
|
|
|
|
"CtyCod,InsCod,CtrCod,DegCod,CrsCod,"
|
2015-12-31 14:25:28 +01:00
|
|
|
|
"Cod,UNIX_TIMESTAMP(TimeNote)"
|
|
|
|
|
" FROM social_notes"
|
2015-12-31 14:47:22 +01:00
|
|
|
|
" WHERE NotCod='%ld'",
|
|
|
|
|
Soc->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 14:25:28 +01:00
|
|
|
|
Soc_GetDataOfSocialNoteFromRow (row,Soc);
|
2015-12-30 12:40:13 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/***** Reset fields of social note *****/
|
|
|
|
|
Soc->SocialNote = Soc_NOTE_UNKNOWN;
|
2015-12-30 12:40:13 +01:00
|
|
|
|
Soc->UsrCod = -1L;
|
|
|
|
|
Soc->CtyCod =
|
|
|
|
|
Soc->InsCod =
|
|
|
|
|
Soc->CtrCod =
|
|
|
|
|
Soc->DegCod =
|
|
|
|
|
Soc->CrsCod = -1L;
|
|
|
|
|
Soc->Cod = -1L;
|
|
|
|
|
Soc->DateTimeUTC = (time_t) 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-30 16:33:36 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Get assignment data using its code **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
static void Soc_GetDataOfSocialNoteFromRow (MYSQL_ROW row,struct SocialNote *Soc)
|
2015-12-30 16:33:36 +01:00
|
|
|
|
{
|
|
|
|
|
/* Get social code (row[0]) */
|
2015-12-31 14:47:22 +01:00
|
|
|
|
Soc->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]) */
|
|
|
|
|
Soc->SocialNote = Soc_GetSocialNoteFromDB ((const char *) row[1]);
|
2015-12-30 16:33:36 +01:00
|
|
|
|
|
|
|
|
|
/* Get (from) user code (row[2]) */
|
|
|
|
|
Soc->UsrCod = Str_ConvertStrCodToLongCod (row[2]);
|
|
|
|
|
|
|
|
|
|
/* Get country code (row[3]) */
|
|
|
|
|
Soc->CtyCod = Str_ConvertStrCodToLongCod (row[3]);
|
|
|
|
|
|
|
|
|
|
/* Get institution code (row[4]) */
|
|
|
|
|
Soc->InsCod = Str_ConvertStrCodToLongCod (row[4]);
|
|
|
|
|
|
|
|
|
|
/* Get centre code (row[5]) */
|
|
|
|
|
Soc->CtrCod = Str_ConvertStrCodToLongCod (row[5]);
|
|
|
|
|
|
|
|
|
|
/* Get degree code (row[6]) */
|
|
|
|
|
Soc->DegCod = Str_ConvertStrCodToLongCod (row[6]);
|
|
|
|
|
|
|
|
|
|
/* Get course code (row[7]) */
|
|
|
|
|
Soc->CrsCod = Str_ConvertStrCodToLongCod (row[7]);
|
|
|
|
|
|
|
|
|
|
/* Get file/post... code (row[8]) */
|
|
|
|
|
Soc->Cod = Str_ConvertStrCodToLongCod (row[8]);
|
|
|
|
|
|
2015-12-31 14:25:28 +01:00
|
|
|
|
/* Get time of the note (row[9]) */
|
2015-12-30 16:33:36 +01:00
|
|
|
|
Soc->DateTimeUTC = Dat_GetUNIXTimeFromStr (row[9]);
|
|
|
|
|
}
|