diff --git a/sql/swad.sql b/sql/swad.sql index cc765c82f..0c7164b77 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -924,7 +924,7 @@ CREATE TABLE IF NOT EXISTS social_notes ( Unavailable ENUM('N','Y') NOT NULL DEFAULT 'N', TimeNote DATETIME NOT NULL, UNIQUE INDEX(NotCod), - INDEX(SocialNote), + UNIQUE INDEX(NoteType,Cod), INDEX(UsrCod), INDEX(TimeNote)); -- diff --git a/swad_changelog.h b/swad_changelog.h index 52f75fa67..f59001c7c 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -118,13 +118,22 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.93.4 (2016-01-03)" +#define Log_PLATFORM_VERSION "SWAD 15.93.5 (2016-01-03)" #define CSS_FILE "swad15.88.1.css" #define JS_FILE "swad15.77.7.js" // 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.93.5: Jan 03, 2016 Social notes are marked as unavailable when a notice is removed. (190406 lines) + 6 changes necessary in database: +CREATE UNIQUE INDEX NotCod ON social_notes (NotCod); +DROP INDEX SocCod ON social_notes; +DROP INDEX TimeEvent ON social_notes; +CREATE INDEX TimeNote ON social_notes (TimeNote); +DROP INDEX SocialEvent ON social_notes; +CREATE UNIQUE INDEX NoteTypeCod ON social_notes (NoteType,Cod); + Version 15.93.4: Jan 03, 2016 Changes in links to actions in social timeline. New field Unavailable in table of social notes. (190354 lines) 1 change necessary in database: diff --git a/swad_database.c b/swad_database.c index c9eab8502..4c04c71dc 100644 --- a/swad_database.c +++ b/swad_database.c @@ -1960,7 +1960,7 @@ mysql> DESCRIBE social_notes; "Unavailable ENUM('N','Y') NOT NULL DEFAULT 'N'," "TimeNote DATETIME NOT NULL," "UNIQUE INDEX(NotCod)," - "INDEX(NoteType)," + "UNIQUE INDEX(NoteType,Cod)," "INDEX(UsrCod)," "INDEX(TimeNote))"); diff --git a/swad_notice.c b/swad_notice.c index 8a2d6be6a..17c41a724 100644 --- a/swad_notice.c +++ b/swad_notice.c @@ -332,6 +332,9 @@ void Not_RemoveNotice (void) /***** Mark possible notifications as removed *****/ Ntf_SetNotifAsRemoved (Ntf_EVENT_NOTICE,NotCod); + /***** Mark possible social note as unavailable *****/ + Soc_MarkSocialNoteAsUnavailableUsingNoteTypeAndCod (Soc_NOTE_NOTICE,NotCod); + /***** Update RSS of current course *****/ RSS_UpdateRSSFileForACrs (&Gbl.CurrentCrs.Crs); } diff --git a/swad_notification.c b/swad_notification.c index edfed73ef..ddc26126f 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -818,7 +818,7 @@ void Ntf_GetNotifSummaryAndContent (char *SummaryStr,char **ContentStr,Ntf_Notif void Ntf_SetNotifAsSeen (Ntf_NotifyEvent_t NotifyEvent,long Cod,long ToUsrCod) { - char Query[512]; + char Query[256]; /***** Set notification as seen by me *****/ if (ToUsrCod > 0) // If the user code is specified diff --git a/swad_social.c b/swad_social.c index 803c42ca5..d6636f75a 100644 --- a/swad_social.c +++ b/swad_social.c @@ -132,11 +132,11 @@ extern struct Globals Gbl; static void Soc_ShowTimeline (const char *Query,Act_Action_t UpdateAction); static void Soc_GetDataOfSocialPublishingFromRow (MYSQL_ROW row,struct SocialPublishing *SocPub); static void Soc_WriteSocialNote (const struct SocialPublishing *SocPub, - const struct SocialNote *SocNot, + struct SocialNote *SocNot, bool WritingTimeline,bool LastInList); static void Soc_WriteNoteDate (time_t TimeUTC); static void Soc_GetAndWriteSocialPost (long PstCod); -static void Soc_PutFormGoToAction (const struct SocialNote *SocNot,long CrsCod); +static void Soc_PutFormGoToAction (struct SocialNote *SocNot,long CrsCod); static void Soc_GetNoteSummary (const struct SocialNote *SocNot, char *SummaryStr,unsigned MaxChars); static void Soc_PublishSocialNoteInTimeline (struct SocialPublishing *SocPub); @@ -344,9 +344,11 @@ static void Soc_GetDataOfSocialPublishingFromRow (MYSQL_ROW row,struct SocialPub /*****************************************************************************/ /***************************** Write social note *****************************/ /*****************************************************************************/ +// Pointer SocNot is not const because the field Unavailable... +// ...can be marked as true inside this function static void Soc_WriteSocialNote (const struct SocialPublishing *SocPub, - const struct SocialNote *SocNot, + struct SocialNote *SocNot, bool WritingTimeline,bool LastInList) { extern const char *Txt_Forum; @@ -608,7 +610,7 @@ static void Soc_GetAndWriteSocialPost (long PstCod) /********* Put form to go to an action depending on the social note **********/ /*****************************************************************************/ -static void Soc_PutFormGoToAction (const struct SocialNote *SocNot,long CrsCod) +static void Soc_PutFormGoToAction (struct SocialNote *SocNot,long CrsCod) { extern const Act_Action_t For_ActionsSeeFor[For_NUM_TYPES_FORUM]; extern const char *The_ClassForm[The_NUM_THEMES]; @@ -620,77 +622,93 @@ static void Soc_PutFormGoToAction (const struct SocialNote *SocNot,long CrsCod) long DegCod = -1L; long GrpCod = -1L; - /***** Parameters depending on the type of note *****/ - switch (SocNot->NoteType) + if (SocNot->Unavailable || // File/notice... pointer by this social note is unavailable + Gbl.InsideForm) // Inside another form { - 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: - FileMetadata.FilCod = SocNot->Cod; - if (FileMetadata.FilCod > 0) - { - Brw_GetFileMetadataByCod (&FileMetadata); - if (FileMetadata.FilCod > 0) // Found - Brw_GetCrsGrpFromFileMetadata (FileMetadata.FileBrowser,FileMetadata.Cod, - &InsCod,&CtrCod,&DegCod,&CrsCod,&GrpCod); - } - if (FileMetadata.FilCod > 0) - { + /***** Do not put form *****/ + fprintf (Gbl.F.Out,"%s",Txt_SOCIAL_NOTE[SocNot->NoteType]); + if (SocNot->Unavailable) + fprintf (Gbl.F.Out," (%s)",Txt_not_available); + } + else // Not inside another form + { + /***** Parameters depending on the type of note *****/ + switch (SocNot->NoteType) + { + 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: + FileMetadata.FilCod = SocNot->Cod; + if (FileMetadata.FilCod > 0) + { + Brw_GetFileMetadataByCod (&FileMetadata); + if (FileMetadata.FilCod > 0) // Found + Brw_GetCrsGrpFromFileMetadata (FileMetadata.FileBrowser,FileMetadata.Cod, + &InsCod,&CtrCod,&DegCod,&CrsCod,&GrpCod); + } + if (FileMetadata.FilCod > 0) + { + Act_FormStart (Soc_DefaultActions[SocNot->NoteType]); + Brw_PutHiddenParamFilCod (FileMetadata.FilCod); + } + else + { + Soc_MarkSocialNoteAsUnavailableUsingNotCod (SocNot->NotCod); + SocNot->Unavailable = true; + } + break; + case Soc_NOTE_NOTICE: Act_FormStart (Soc_DefaultActions[SocNot->NoteType]); - Brw_PutHiddenParamFilCod (FileMetadata.FilCod); + Not_PutHiddenParamNotCod (SocNot->Cod); + break; + case Soc_NOTE_FORUM_POST: + Act_FormStart (For_ActionsSeeFor[Gbl.Forum.ForumType]); + For_PutAllHiddenParamsForum (); + break; + default: + Act_FormStart (Soc_DefaultActions[SocNot->NoteType]); + break; + } + + if (SocNot->Unavailable) + fprintf (Gbl.F.Out,"%s (%s)", + Txt_SOCIAL_NOTE[SocNot->NoteType],Txt_not_available); + else + { + /***** Parameter to go to another place in hierarchy *****/ + if (CrsCod > 0) // Course specified + { + if (CrsCod != Gbl.CurrentCrs.Crs.CrsCod) // Not the current course + Crs_PutParamCrsCod (CrsCod); // Go to another course + } + else if (DegCod > 0) // Degree specified + { + if (DegCod != Gbl.CurrentDeg.Deg.DegCod) // Not the current degree + Deg_PutParamDegCod (DegCod); // Go to another degree + } + else if (CtrCod > 0) // Centre specified + { + if (CtrCod != Gbl.CurrentCtr.Ctr.CtrCod) // Not the current centre + Ctr_PutParamCtrCod (CtrCod); // Go to another centre + } + else if (InsCod > 0) // Institution specified + { + if (InsCod != Gbl.CurrentIns.Ins.InsCod) // Not the current institution + Ins_PutParamInsCod (InsCod); // Go to another institution } - break; - case Soc_NOTE_NOTICE: - Act_FormStart (Soc_DefaultActions[SocNot->NoteType]); - Not_PutHiddenParamNotCod (SocNot->Cod); - break; - case Soc_NOTE_FORUM_POST: - Act_FormStart (For_ActionsSeeFor[Gbl.Forum.ForumType]); - For_PutAllHiddenParamsForum (); - break; - default: - Act_FormStart (Soc_DefaultActions[SocNot->NoteType]); - break; - } - if (Gbl.InsideForm) - { - /***** Parameter to go to another place in hierarchy *****/ - if (CrsCod > 0) // Course specified - { - if (CrsCod != Gbl.CurrentCrs.Crs.CrsCod) // Not the current course - Crs_PutParamCrsCod (CrsCod); // Go to another course + /***** Link and end form *****/ + Act_LinkFormSubmit (Txt_SOCIAL_NOTE[SocNot->NoteType], + The_ClassForm[Gbl.Prefs.Theme]); + fprintf (Gbl.F.Out,"%s",Txt_SOCIAL_NOTE[SocNot->NoteType]); + Act_FormEnd (); } - else if (DegCod > 0) // Degree specified - { - if (DegCod != Gbl.CurrentDeg.Deg.DegCod) // Not the current degree - Deg_PutParamDegCod (DegCod); // Go to another degree - } - else if (CtrCod > 0) // Centre specified - { - if (CtrCod != Gbl.CurrentCtr.Ctr.CtrCod) // Not the current centre - Ctr_PutParamCtrCod (CtrCod); // Go to another centre - } - else if (InsCod > 0) // Institution specified - { - if (InsCod != Gbl.CurrentIns.Ins.InsCod) // Not the current institution - Ins_PutParamInsCod (InsCod); // Go to another institution - } - - /***** Link and end form *****/ - Act_LinkFormSubmit (Txt_SOCIAL_NOTE[SocNot->NoteType], - The_ClassForm[Gbl.Prefs.Theme]); - fprintf (Gbl.F.Out,"%s",Txt_SOCIAL_NOTE[SocNot->NoteType]); - Act_FormEnd (); } - else // Not inside a form - fprintf (Gbl.F.Out,"%s (%s)", - Txt_SOCIAL_NOTE[SocNot->NoteType],Txt_not_available); } /*****************************************************************************/ @@ -779,6 +797,32 @@ void Soc_StoreAndPublishSocialNote (Soc_NoteType_t NoteType,long Cod) Soc_PublishSocialNoteInTimeline (&SocPub); } +/*****************************************************************************/ +/********************** Mark a social note as unavailable ********************/ +/*****************************************************************************/ + +void Soc_MarkSocialNoteAsUnavailableUsingNotCod (long NotCod) + { + char Query[256]; + + /***** Mark the social note as unavailable *****/ + sprintf (Query,"UPDATE social_notes SET Unavailable='Y'" + " WHERE NotCod='%ld'", + NotCod); + DB_QueryUPDATE (Query,"can not mark social note as unavailable"); + } + +void Soc_MarkSocialNoteAsUnavailableUsingNoteTypeAndCod (Soc_NoteType_t NoteType,long Cod) + { + char Query[256]; + + /***** Mark the social note as unavailable *****/ + sprintf (Query,"UPDATE social_notes SET Unavailable='Y'" + " WHERE NoteType='%u' AND Cod='%ld'", + (unsigned) NoteType,Cod); + DB_QueryUPDATE (Query,"can not mark social note as unavailable"); + } + /*****************************************************************************/ /***************** Put contextual link to write a new post *******************/ /*****************************************************************************/ @@ -1282,6 +1326,8 @@ static void Soc_RequestRemovalSocialPublishing (void) else Act_FormStart (ActRemSocPubGbl); Soc_PutHiddenParamPubCod (SocPub.PubCod); + + /* Warning message */ Lay_ShowAlert (Lay_WARNING,Txt_Do_you_really_want_to_remove_the_following_comment); /* Show social note */ diff --git a/swad_social.h b/swad_social.h index cca500988..133b608bc 100644 --- a/swad_social.h +++ b/swad_social.h @@ -85,6 +85,8 @@ void Soc_ShowTimelineUsr (void); void Soc_ShowTimelineGbl (void); void Soc_StoreAndPublishSocialNote (Soc_NoteType_t NoteType,long Cod); +void Soc_MarkSocialNoteAsUnavailableUsingNotCod (long NotCod); +void Soc_MarkSocialNoteAsUnavailableUsingNoteTypeAndCod (Soc_NoteType_t NoteType,long Cod); void Soc_FormSocialPostGbl (void); void Soc_FormSocialPostUsr (void);