From 1b8da4590f8e1f14d3a0bd01f6db937fb5bab592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Mon, 28 Dec 2015 20:46:48 +0100 Subject: [PATCH] Version 15.77.1 --- css/swad15.75.css | 1 + sql/cambios.sql | 2 +- sql/swad.sql | 1 - swad_changelog.h | 5 ++- swad_database.c | 4 +- swad_forum.c | 12 ++++++ swad_social.c | 106 ++++++++++++++++++++++++++++++++++------------ swad_social.h | 2 + 8 files changed, 99 insertions(+), 34 deletions(-) diff --git a/css/swad15.75.css b/css/swad15.75.css index 810937f42..6946b231c 100644 --- a/css/swad15.75.css +++ b/css/swad15.75.css @@ -1341,6 +1341,7 @@ a:hover img.CENTRE_PHOTO_SHOW .PHOTO21x28 {width: 21px; height: 28px; vertical-align:middle; border-radius:2px;} .PHOTO30x40 {width: 30px; height: 40px; vertical-align:middle; border-radius:2px;} .PHOTO45x60 {width: 45px; height: 60px; vertical-align:middle; border-radius:3px;} +.PHOTO60x80 {width: 60px; height: 80px; vertical-align:middle; border-radius:3px;} .PHOTO93x124 {width: 93px; height:124px; vertical-align:middle; border-radius:4px;} .PHOTO186x248 {width:186px; height:248px; vertical-align:middle; border-radius:8px;} .IMG_USR diff --git a/sql/cambios.sql b/sql/cambios.sql index 131ba76b4..7c5dc5dbb 100644 --- a/sql/cambios.sql +++ b/sql/cambios.sql @@ -11188,4 +11188,4 @@ SELECT COUNT(DISTINCT crs_usr.UsrCod) FROM institutions,centres,degrees,courses, ----- SWAD 15.77 (2015/12/28) ----- CREATE TABLE IF NOT EXISTS social (SocCod BIGINT NOT NULL AUTO_INCREMENT,SocialEvent TINYINT NOT NULL,UsrCod INT NOT NULL,CtyCod INT NOT NULL DEFAULT -1,InsCod INT NOT NULL DEFAULT -1,CtrCod INT NOT NULL DEFAULT -1,DegCod INT NOT NULL DEFAULT -1,CrsCod INT NOT NULL DEFAULT -1,Cod INT NOT NULL DEFAULT -1,TimeEvent DATETIME NOT NULL,Status TINYINT NOT NULL DEFAULT 0,UNIQUE INDEX(SocCod),INDEX(SocialEvent),INDEX(UsrCod),INDEX(TimeEvent)); - +ALTER TABLE social DROP COLUMN Status; diff --git a/sql/swad.sql b/sql/swad.sql index aacb5f309..65db327c0 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -926,7 +926,6 @@ CREATE TABLE IF NOT EXISTS social ( CrsCod INT NOT NULL DEFAULT -1, Cod INT NOT NULL DEFAULT -1, TimeEvent DATETIME NOT NULL, - Status TINYINT NOT NULL DEFAULT 0, UNIQUE INDEX(SocCod), INDEX(SocialEvent), INDEX(UsrCod), diff --git a/swad_changelog.h b/swad_changelog.h index 8866c310b..d234d2c40 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -114,15 +114,16 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.77 (2015-12-28)" +#define Log_PLATFORM_VERSION "SWAD 15.77.1 (2015-12-28)" #define CSS_FILE "swad15.75.css" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1 /* + Version 15.77.1: Dec 28, 2015 Insert social event when posting in a global forum. (188342 lines) Version 15.77: Dec 28, 2015 New table in database for social activity. (188287 lines) 2 changes necessary in database: -CREATE TABLE IF NOT EXISTS social (SocCod BIGINT NOT NULL AUTO_INCREMENT,SocialEvent TINYINT NOT NULL,UsrCod INT NOT NULL,CtyCod INT NOT NULL DEFAULT -1,InsCod INT NOT NULL DEFAULT -1,CtrCod INT NOT NULL DEFAULT -1,DegCod INT NOT NULL DEFAULT -1,CrsCod INT NOT NULL DEFAULT -1,Cod INT NOT NULL DEFAULT -1,TimeEvent DATETIME NOT NULL,Status TINYINT NOT NULL DEFAULT 0,UNIQUE INDEX(SocCod),INDEX(SocialEvent),INDEX(UsrCod),INDEX(TimeEvent)); +CREATE TABLE IF NOT EXISTS social (SocCod BIGINT NOT NULL AUTO_INCREMENT,SocialEvent TINYINT NOT NULL,UsrCod INT NOT NULL,CtyCod INT NOT NULL DEFAULT -1,InsCod INT NOT NULL DEFAULT -1,CtrCod INT NOT NULL DEFAULT -1,DegCod INT NOT NULL DEFAULT -1,CrsCod INT NOT NULL DEFAULT -1,Cod INT NOT NULL DEFAULT -1,TimeEvent DATETIME NOT NULL,UNIQUE INDEX(SocCod),INDEX(SocialEvent),INDEX(UsrCod),INDEX(TimeEvent)); INSERT INTO actions (ActCod,Language,Obsolete,Txt) VALUES ('1490','es','N','Ver actividad social (timeline)'); Version 15.76.1: Dec 28, 2015 Refactoring in swad_database. (187926 lines) diff --git a/swad_database.c b/swad_database.c index 97c7630c3..92a749b86 100644 --- a/swad_database.c +++ b/swad_database.c @@ -1951,9 +1951,8 @@ mysql> DESCRIBE social; | CrsCod | int(11) | NO | | -1 | | | Cod | int(11) | NO | | -1 | | | TimeEvent | datetime | NO | MUL | NULL | | -| Status | tinyint(4) | NO | | 0 | | +-------------+------------+------+-----+---------+----------------+ -11 rows in set (0.00 sec) +10 rows in set (0.00 sec) */ DB_CreateTable ("CREATE TABLE IF NOT EXISTS social (" "SocCod BIGINT NOT NULL AUTO_INCREMENT," @@ -1966,7 +1965,6 @@ mysql> DESCRIBE social; "CrsCod INT NOT NULL DEFAULT -1," "Cod INT NOT NULL DEFAULT -1," "TimeEvent DATETIME NOT NULL," - "Status TINYINT NOT NULL DEFAULT 0," "UNIQUE INDEX(SocCod)," "INDEX(SocialEvent)," "INDEX(UsrCod)," diff --git a/swad_forum.c b/swad_forum.c index 9ea27c50f..f6e7cbe3f 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -41,6 +41,7 @@ #include "swad_notification.h" #include "swad_parameter.h" #include "swad_profile.h" +#include "swad_social.h" /*****************************************************************************/ /************** External global variables from others modules ****************/ @@ -3829,6 +3830,17 @@ void For_RecForumPst (void) Ntf_ShowAlertNumUsrsToBeNotifiedByEMail (NumUsrsToBeNotifiedByEMail); } + /***** Insert post into public social activity *****/ + switch (Gbl.Forum.ForumType) // Only if forum is public for any logged user + { + case For_FORUM_GLOBAL_USRS: + case For_FORUM_SWAD_USRS: + Soc_StoreSocialEvent (Soc_EVENT_FORUM_POST,PstCod); + break; + default: + break; + } + /***** Show again the posts of this thread of the forum *****/ For_ShowForumLevel2 (ThrCod); } diff --git a/swad_social.c b/swad_social.c index c415f4a52..63fab8e46 100644 --- a/swad_social.c +++ b/swad_social.c @@ -25,25 +25,15 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ -// #include // For NULL #include // For PATH_MAX +#include // For malloc and free #include // For time_t #include "swad_constant.h" -// #include "swad_config.h" #include "swad_database.h" -// #include "swad_follow.h" #include "swad_global.h" #include "swad_layout.h" -// #include "swad_nickname.h" -// #include "swad_parameter.h" -// #include "swad_privacy.h" -// #include "swad_profile.h" -// #include "swad_role.h" #include "swad_social.h" -// #include "swad_text.h" -// #include "swad_theme.h" -// #include "swad_user.h" /*****************************************************************************/ /****************************** Public constants *****************************/ @@ -108,7 +98,7 @@ void Soc_ShowSocialActivity (void) time_t DateTimeUTC; // Date-time of the event bool ShowPhoto = false; char PhotoURL[PATH_MAX+1]; - char SummaryStr[Soc_MAX_BYTES_SUMMARY+1]; + char *SummaryStr; /***** Get my timeline from database *****/ sprintf (Query,"SELECT SocialEvent,UsrCod," @@ -124,12 +114,16 @@ void Soc_ShowSocialActivity (void) /***** List my timeline *****/ if (NumEvents) // Events found { + /***** Allocate memory for the summary of the notification *****/ + if ((SummaryStr = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) + Lay_ShowErrorAndExit ("Not enough memory to store the summary of the notification."); + /***** Initialize structure with user's data *****/ Usr_UsrDataConstructor (&UsrDat); /***** List start *****/ Lay_StartRoundFrame (NULL,Txt_Public_activity); - fprintf (Gbl.F.Out,"
    "); + fprintf (Gbl.F.Out,"
      "); /***** List events one by one *****/ for (NumEvent = 0; @@ -192,20 +186,27 @@ void Soc_ShowSocialActivity (void) fprintf (Gbl.F.Out,"
    • "); /* Write author of the event */ + fprintf (Gbl.F.Out,"
      "); ShowPhoto = Pho_ShowUsrPhotoIsAllowed (&UsrDat,PhotoURL); Pho_ShowUsrPhoto (&UsrDat,ShowPhoto ? PhotoURL : NULL, - "PHOTO30x40",Pho_ZOOM); + "PHOTO60x80",Pho_ZOOM); + fprintf (Gbl.F.Out,"
      "); - fprintf (Gbl.F.Out,"%s", - UsrDat.FullName); + fprintf (Gbl.F.Out,"
      "); - /* Write event type */ - fprintf (Gbl.F.Out,"%u", + fprintf (Gbl.F.Out,"
      " + "%s @%s
      ", + UsrDat.FullName,UsrDat.Nickname); + + /* Write date and time */ + Soc_WriteEventDate (DateTimeUTC); + + /* Write event type and location */ + fprintf (Gbl.F.Out,"
      %u: ", (unsigned) SocialEvent); - /* Write location */ - fprintf (Gbl.F.Out,""); if (SocialEvent == Soc_EVENT_FORUM_POST) fprintf (Gbl.F.Out,"%s: %s",Txt_Forum,ForumName); else if (Crs.CrsCod > 0) @@ -218,15 +219,14 @@ void Soc_ShowSocialActivity (void) fprintf (Gbl.F.Out,"%s: %s",Txt_Institution,Ins.ShortName); else if (Cty.CtyCod > 0) fprintf (Gbl.F.Out,"%s: %s",Txt_Country,Cty.Name[Gbl.Prefs.Language]); - fprintf (Gbl.F.Out,""); - - /* Write date and time */ - Soc_WriteEventDate (DateTimeUTC); + fprintf (Gbl.F.Out,"
      "); /***** Write content of the event *****/ Soc_GetEventSummary (SocialEvent,Cod, SummaryStr,Soc_MAX_BYTES_SUMMARY); - fprintf (Gbl.F.Out,"%s",SummaryStr); + fprintf (Gbl.F.Out,"
      %s
      ",SummaryStr); + + fprintf (Gbl.F.Out,"
      "); } /***** List end *****/ @@ -235,6 +235,9 @@ void Soc_ShowSocialActivity (void) /***** Free memory used for user's data *****/ Usr_UsrDataDestructor (&UsrDat); + + /***** Free summary *****/ + free ((void *) SummaryStr); } else Lay_ShowAlert (Lay_INFO,"No events."); // Need translation!!!! @@ -270,7 +273,8 @@ static void Soc_WriteEventDate (time_t TimeUTC) UniqueId++; /***** Start cell *****/ - fprintf (Gbl.F.Out,"", + fprintf (Gbl.F.Out,"
      ", UniqueId); /***** Write date and time *****/ @@ -280,7 +284,7 @@ static void Soc_WriteEventDate (time_t TimeUTC) UniqueId,(long) TimeUTC); /***** End cell *****/ - fprintf (Gbl.F.Out,""); + fprintf (Gbl.F.Out,"
      "); } /*****************************************************************************/ @@ -365,3 +369,51 @@ static void Soc_GetEventSummary (Soc_SocialEvent_t SocialEvent,long Cod, break; } } + +/*****************************************************************************/ +/********************* Store a social event into database ********************/ +/*****************************************************************************/ + +void Soc_StoreSocialEvent (Soc_SocialEvent_t SocialEvent,long Cod) + { + char Query[512]; + long CtyCod; + long InsCod; + long CtrCod; + long DegCod; + long CrsCod; + + if (SocialEvent == Soc_EVENT_FORUM_POST) + { + // 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; + } + + /***** Store notify event *****/ + sprintf (Query,"INSERT INTO social (SocialEvent,UsrCod," + "CtyCod,InsCod,CtrCod,DegCod,CrsCod," + "Cod,TimeEvent)" + " VALUES ('%u','%ld'," + "'%ld','%ld','%ld','%ld','%ld'," + "'%ld',NOW())", + (unsigned) SocialEvent,Gbl.Usrs.Me.UsrDat.UsrCod, + CtyCod,InsCod,CtrCod,DegCod,CrsCod, + Cod); + DB_QueryINSERT (Query,"can not create new social event"); + } diff --git a/swad_social.h b/swad_social.h index 5c1f431a0..2fe8cdf40 100644 --- a/swad_social.h +++ b/swad_social.h @@ -84,4 +84,6 @@ typedef enum void Soc_ShowSocialActivity (void); +void Soc_StoreSocialEvent (Soc_SocialEvent_t SocialEvent,long Cod); + #endif