diff --git a/swad_changelog.h b/swad_changelog.h index 42351412a..184e2ef9b 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -156,13 +156,15 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.47.19 (2016-11-07)" +#define Log_PLATFORM_VERSION "SWAD 16.48 (2016-11-07)" #define CSS_FILE "swad16.32.1.css" #define JS_FILE "swad16.46.1.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 16.48: Nov 07, 2016 Icon in messages to show figure (statistics). + Code refactoring in messages. (206418 lines) Version 16.47.19: Nov 07, 2016 Icon in forums to show figure (statistics). (206361 lines) Version 16.47.18: Nov 07, 2016 Icon in "who to follow" to show figure (statistics). (206350 lines) Version 16.47.17: Nov 07, 2016 Icon in public activity to show figure (statistics). (206337 lines) diff --git a/swad_global.h b/swad_global.h index 9a3477c80..55fd8c877 100644 --- a/swad_global.h +++ b/swad_global.h @@ -585,6 +585,8 @@ struct Globals } Forum; struct { + Msg_TypeOfMessages_t TypeOfMessages; + unsigned NumMsgs; int MsgId; char Subject[Cns_MAX_BYTES_SUBJECT+1]; unsigned NumCourses; diff --git a/swad_message.c b/swad_message.c index eb56d4844..440de6367 100644 --- a/swad_message.c +++ b/swad_message.c @@ -76,14 +76,15 @@ extern struct Globals Gbl; static void Msg_PutFormMsgUsrs (char *Content); -static void Msg_ShowSentOrReceivedMessages (Msg_TypeOfMessages_t TypeOfMessages); +static void Msg_ShowSentOrReceivedMessages (void); static unsigned long Msg_GetNumUsrsBannedByMe (void); static void Msg_PutLinkToViewBannedUsers(void); -static void Msg_ConstructQueryToSelectSentOrReceivedMsgs (char *Query,Msg_TypeOfMessages_t TypeOfMessages,long UsrCod, +static void Msg_ConstructQueryToSelectSentOrReceivedMsgs (char *Query,long UsrCod, long FilterCrsCod,const char *FilterFromToSubquery); -static char *Msg_WriteNumMsgs (Msg_TypeOfMessages_t TypeOfMessages, - unsigned NumMsgs,unsigned NumUnreadMsgs); +static char *Msg_WriteNumMsgs (unsigned NumUnreadMsgs); + +static void Msg_PutIconsListMsgs (void); static void Msg_PutIconToRemoveOneRcvMsg (void); static void Msg_PutIconToRemoveSevRcvMsgs (void); static void Msg_PutIconToRemoveOneSntMsg (void); @@ -91,7 +92,7 @@ static void Msg_PutIconToRemoveSevSntMsgs (void); static void Msg_ShowFormToShowOnlyUnreadMessages (void); static void Msg_GetParamOnlyUnreadMsgs (void); -static void Msg_ShowASentOrReceivedMessage (Msg_TypeOfMessages_t TypeOfMessages,long MsgNum,long MsgCod); +static void Msg_ShowASentOrReceivedMessage (long MsgNum,long MsgCod); static void Msg_GetStatusOfSentMsg (long MsgCod,bool *Expanded); static void Msg_GetStatusOfReceivedMsg (long MsgCod,bool *Open,bool *Replied,bool *Expanded); static long Msg_GetParamMsgCod (void); @@ -127,14 +128,14 @@ static void Msg_GetMsgSntData (long MsgCod,long *CrsCod,long *UsrCod, time_t *CreatTimeUTC,char *Subject,bool *Deleted); static void Msg_GetMsgContent (long MsgCod,char *Content,struct Image *Image); -static void Msg_WriteSentOrReceivedMsgSubject (Msg_TypeOfMessages_t TypeOfMessages,long MsgCod,const char *Subject,bool Open,bool Expanded); +static void Msg_WriteSentOrReceivedMsgSubject (long MsgCod,const char *Subject,bool Open,bool Expanded); static void Msg_WriteFormToReply (long MsgCod,long CrsCod, bool ThisCrs,bool Replied, const struct UsrData *UsrDat); static void Msg_WriteMsgFrom (struct UsrData *UsrDat,bool Deleted); -static void Msg_WriteMsgTo (Msg_TypeOfMessages_t TypeOfMessages,long MsgCod); +static void Msg_WriteMsgTo (long MsgCod); -static void Msg_PutFormToDeleteMessage (long MsgCod,Msg_TypeOfMessages_t TypeOfMessages); +static void Msg_PutFormToDeleteMessage (long MsgCod); static void Msg_PutFormToBanSender (struct UsrData *UsrDat); static void Msg_PutFormToUnbanSender (struct UsrData *UsrDat); @@ -1325,7 +1326,7 @@ static unsigned long Msg_DelSomeRecOrSntMsgsUsr (Msg_TypeOfMessages_t TypeOfMess long MsgCod; /***** Get some of the messages received or sent by this user from database *****/ - Msg_ConstructQueryToSelectSentOrReceivedMsgs (Query,TypeOfMessages,UsrCod,FilterCrsCod,FilterFromToSubquery); + Msg_ConstructQueryToSelectSentOrReceivedMsgs (Query,UsrCod,FilterCrsCod,FilterFromToSubquery); NumMsgs = DB_QuerySELECT (Query,&mysql_res,"can not get list of messages"); /***** Delete each message *****/ @@ -1615,7 +1616,8 @@ static unsigned Msg_GetNumUnreadMsgs (long FilterCrsCod,const char *FilterFromTo void Msg_ShowSntMsgs (void) { /***** Show the sent messages *****/ - Msg_ShowSentOrReceivedMessages (Msg_MESSAGES_SENT); + Gbl.Msg.TypeOfMessages = Msg_MESSAGES_SENT; + Msg_ShowSentOrReceivedMessages (); } /*****************************************************************************/ @@ -1633,14 +1635,15 @@ void Msg_ShowRecMsgs (void) } /***** Show the received messages *****/ - Msg_ShowSentOrReceivedMessages (Msg_MESSAGES_RECEIVED); + Gbl.Msg.TypeOfMessages = Msg_MESSAGES_RECEIVED; + Msg_ShowSentOrReceivedMessages (); } /*****************************************************************************/ /************************ Show sent or received messages *********************/ /*****************************************************************************/ -static void Msg_ShowSentOrReceivedMessages (Msg_TypeOfMessages_t TypeOfMessages) +static void Msg_ShowSentOrReceivedMessages (void) { extern const char *The_ClassFormBold[The_NUM_THEMES]; extern const char *Txt_Update_messages; @@ -1651,28 +1654,35 @@ static void Msg_ShowSentOrReceivedMessages (Msg_TypeOfMessages_t TypeOfMessages) unsigned long NumRow; unsigned long NumRows; unsigned long NumMsg = 0; // Initialized to avoid warning - unsigned NumMsgs; unsigned NumUnreadMsgs; struct Pagination Pagination; long MsgCod; + static const Pag_WhatPaginate_t WhatPaginate[Msg_NUM_TYPES_OF_MSGS] = + { + Pag_MESSAGES_RECEIVED, + Pag_MESSAGES_SENT + }; + static const Act_Action_t ActionSee[Msg_NUM_TYPES_OF_MSGS] = + { + ActSeeRcvMsg, + ActSeeSntMsg + }; /***** Get the page number *****/ - Pag_GetParamPagNum (TypeOfMessages == Msg_MESSAGES_RECEIVED ? Pag_MESSAGES_RECEIVED : - Pag_MESSAGES_SENT); + Pag_GetParamPagNum (WhatPaginate[Gbl.Msg.TypeOfMessages]); /***** Get other parameters *****/ Msg_GetParamMsgsCrsCod (); Msg_GetParamFilterFromTo (); Msg_GetParamFilterContent (); Msg_MakeFilterFromToSubquery (FilterFromToSubquery); - Msg_GetDistinctCoursesInMyMessages (TypeOfMessages); + Msg_GetDistinctCoursesInMyMessages (); /***** Form to see messages again *****/ - Act_FormStart (TypeOfMessages == Msg_MESSAGES_RECEIVED ? ActSeeRcvMsg : - ActSeeSntMsg); - Msg_ShowFormSelectCourseSentOrRecMsgs (TypeOfMessages); - Msg_ShowFormToFilterMsgs (TypeOfMessages); - if (TypeOfMessages == Msg_MESSAGES_RECEIVED) + Act_FormStart (ActionSee[Gbl.Msg.TypeOfMessages]); + Msg_ShowFormSelectCourseSentOrRecMsgs (); + Msg_ShowFormToFilterMsgs (); + if (Gbl.Msg.TypeOfMessages == Msg_MESSAGES_RECEIVED) { Msg_GetParamOnlyUnreadMsgs (); Msg_ShowFormToShowOnlyUnreadMessages (); @@ -1687,28 +1697,28 @@ static void Msg_ShowSentOrReceivedMessages (Msg_TypeOfMessages_t TypeOfMessages) Act_FormEnd (); - if (TypeOfMessages == Msg_MESSAGES_RECEIVED) - NumUnreadMsgs = Msg_GetNumUnreadMsgs (Gbl.Msg.FilterCrsCod,FilterFromToSubquery); - else - NumUnreadMsgs = 0; + switch (Gbl.Msg.TypeOfMessages) + { + case Msg_MESSAGES_RECEIVED: + NumUnreadMsgs = Msg_GetNumUnreadMsgs (Gbl.Msg.FilterCrsCod,FilterFromToSubquery); + break; + case Msg_MESSAGES_SENT: + NumUnreadMsgs = 0; + break; + } /***** Get messages from database *****/ - Msg_ConstructQueryToSelectSentOrReceivedMsgs (Query,TypeOfMessages,Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Msg.FilterCrsCod,FilterFromToSubquery); + Msg_ConstructQueryToSelectSentOrReceivedMsgs (Query,Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Msg.FilterCrsCod,FilterFromToSubquery); NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get messages"); - NumMsgs = (unsigned) NumRows; + Gbl.Msg.NumMsgs = (unsigned) NumRows; /***** Start frame with messages *****/ Lay_StartRoundFrame ("97%", - Msg_WriteNumMsgs (TypeOfMessages,NumMsgs,NumUnreadMsgs), - TypeOfMessages == Msg_MESSAGES_RECEIVED ? ((NumMsgs == 1) ? Msg_PutIconToRemoveOneRcvMsg : - ((NumMsgs > 1) ? Msg_PutIconToRemoveSevRcvMsgs : - NULL)) : - ((NumMsgs == 1) ? Msg_PutIconToRemoveOneSntMsg : - ((NumMsgs > 1) ? Msg_PutIconToRemoveSevSntMsgs : - NULL))); + Msg_WriteNumMsgs (NumUnreadMsgs), + Msg_PutIconsListMsgs); - if (NumMsgs) // If there are messages... + if (Gbl.Msg.NumMsgs) // If there are messages... { if (Gbl.Action.Act == ActExpRcvMsg) // Expanding a message, perhaps it is the result of following a link // from a notification of received message, so show the page where the message is inside @@ -1731,20 +1741,18 @@ static void Msg_ShowSentOrReceivedMessages (Msg_TypeOfMessages_t TypeOfMessages) } /***** Compute variables related to pagination *****/ - Pagination.NumItems = NumMsgs; + Pagination.NumItems = Gbl.Msg.NumMsgs; Pagination.CurrentPage = (int) Gbl.Pag.CurrentPage; Pag_CalculatePagination (&Pagination); Gbl.Pag.CurrentPage = (unsigned) Pagination.CurrentPage; /***** Save my current page in order to show it next time I'll view my received/sent messages *****/ - Pag_SaveLastPageMsgIntoSession (TypeOfMessages == Msg_MESSAGES_RECEIVED ? Pag_MESSAGES_RECEIVED : - Pag_MESSAGES_SENT, + Pag_SaveLastPageMsgIntoSession (WhatPaginate[Gbl.Msg.TypeOfMessages], Gbl.Pag.CurrentPage); /***** Write links to pages *****/ if (Pagination.MoreThanOnePage) - Pag_WriteLinksToPagesCentered (TypeOfMessages == Msg_MESSAGES_RECEIVED ? Pag_MESSAGES_RECEIVED : - Pag_MESSAGES_SENT, + Pag_WriteLinksToPagesCentered (WhatPaginate[Gbl.Msg.TypeOfMessages], 0,&Pagination); /***** Show received / sent messages in this page *****/ @@ -1761,15 +1769,14 @@ static void Msg_ShowSentOrReceivedMessages (Msg_TypeOfMessages_t TypeOfMessages) if (sscanf (row[0],"%ld",&MsgCod) != 1) Lay_ShowErrorAndExit ("Wrong code of message when listing the messages in a page."); NumMsg = NumRows - NumRow + 1; - Msg_ShowASentOrReceivedMessage (TypeOfMessages,NumMsg,MsgCod); + Msg_ShowASentOrReceivedMessage (NumMsg,MsgCod); } fprintf (Gbl.F.Out,""); /***** Write again links to pages *****/ if (Pagination.MoreThanOnePage) - Pag_WriteLinksToPagesCentered (TypeOfMessages == Msg_MESSAGES_RECEIVED ? Pag_MESSAGES_RECEIVED : - Pag_MESSAGES_SENT, + Pag_WriteLinksToPagesCentered (WhatPaginate[Gbl.Msg.TypeOfMessages], 0,&Pagination); } @@ -1812,7 +1819,7 @@ static void Msg_PutLinkToViewBannedUsers(void) /********* Generate a query to select messages received or sent **************/ /*****************************************************************************/ -static void Msg_ConstructQueryToSelectSentOrReceivedMsgs (char *Query,Msg_TypeOfMessages_t TypeOfMessages,long UsrCod, +static void Msg_ConstructQueryToSelectSentOrReceivedMsgs (char *Query,long UsrCod, long FilterCrsCod,const char *FilterFromToSubquery) { char SubQuery[Msg_MAX_LENGTH_MESSAGES_QUERY+1]; @@ -1823,7 +1830,7 @@ static void Msg_ConstructQueryToSelectSentOrReceivedMsgs (char *Query,Msg_TypeOf Query; if (FilterCrsCod > 0) // If origin course selected - switch (TypeOfMessages) + switch (Gbl.Msg.TypeOfMessages) { case Msg_MESSAGES_RECEIVED: StrUnreadMsg = (Gbl.Msg.ShowOnlyUnreadMsgs ? " AND msg_rcv.Open='N'" : @@ -1870,7 +1877,7 @@ static void Msg_ConstructQueryToSelectSentOrReceivedMsgs (char *Query,Msg_TypeOf break; } else // If no origin course selected - switch (TypeOfMessages) + switch (Gbl.Msg.TypeOfMessages) { case Msg_MESSAGES_RECEIVED: if (FilterFromToSubquery[0]) @@ -2256,8 +2263,7 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus) /*****************************************************************************/ // Fill Gbl.Title -static char *Msg_WriteNumMsgs (Msg_TypeOfMessages_t TypeOfMessages, - unsigned NumMsgs,unsigned NumUnreadMsgs) +static char *Msg_WriteNumMsgs (unsigned NumUnreadMsgs) { extern const char *Txt_message_received; extern const char *Txt_message_sent; @@ -2266,45 +2272,74 @@ static char *Msg_WriteNumMsgs (Msg_TypeOfMessages_t TypeOfMessages, extern const char *Txt_unread_MESSAGE; extern const char *Txt_unread_MESSAGES; - if (TypeOfMessages == Msg_MESSAGES_RECEIVED) + switch (Gbl.Msg.TypeOfMessages) { - if (NumMsgs == 1) - { - if (NumUnreadMsgs) - sprintf (Gbl.Title,"1 %s, 1 %s", - Txt_message_received,Txt_unread_MESSAGE); + case Msg_MESSAGES_RECEIVED: + if (Gbl.Msg.NumMsgs == 1) + { + if (NumUnreadMsgs) + sprintf (Gbl.Title,"1 %s, 1 %s", + Txt_message_received,Txt_unread_MESSAGE); + else + sprintf (Gbl.Title,"1 %s", + Txt_message_received); + } else + { + if (NumUnreadMsgs == 0) + sprintf (Gbl.Title,"%u %s", + Gbl.Msg.NumMsgs,Txt_messages_received); + else if (NumUnreadMsgs == 1) + sprintf (Gbl.Title,"%u %s, 1 %s", + Gbl.Msg.NumMsgs,Txt_messages_received, + Txt_unread_MESSAGE); + else + sprintf (Gbl.Title,"%u %s, %u %s", + Gbl.Msg.NumMsgs,Txt_messages_received, + NumUnreadMsgs,Txt_unread_MESSAGES); + } + break; + case Msg_MESSAGES_SENT: + if (Gbl.Msg.NumMsgs == 1) sprintf (Gbl.Title,"1 %s", - Txt_message_received); - } - else - { - if (NumUnreadMsgs == 0) - sprintf (Gbl.Title,"%u %s", - NumMsgs,Txt_messages_received); - else if (NumUnreadMsgs == 1) - sprintf (Gbl.Title,"%u %s, 1 %s", - NumMsgs,Txt_messages_received, - Txt_unread_MESSAGE); + Txt_message_sent); else - sprintf (Gbl.Title,"%u %s, %u %s", - NumMsgs,Txt_messages_received, - NumUnreadMsgs,Txt_unread_MESSAGES); - } - } - else // TypeOfMessages == Msg_MESSAGES_SENT - { - if (NumMsgs == 1) - sprintf (Gbl.Title,"1 %s", - Txt_message_sent); - else - sprintf (Gbl.Title,"%u %s", - NumMsgs,Txt_messages_sent); + sprintf (Gbl.Title,"%u %s", + Gbl.Msg.NumMsgs,Txt_messages_sent); + break; } return Gbl.Title; } +/*****************************************************************************/ +/***************** Put contextual icons in list of messages ******************/ +/*****************************************************************************/ + +static void Msg_PutIconsListMsgs (void) + { + /***** Put icons to remove messages *****/ + switch (Gbl.Msg.TypeOfMessages) + { + case Msg_MESSAGES_RECEIVED: + if (Gbl.Msg.NumMsgs == 1) + Msg_PutIconToRemoveOneRcvMsg (); + else if (Gbl.Msg.NumMsgs > 1) + Msg_PutIconToRemoveSevRcvMsgs (); + break; + case Msg_MESSAGES_SENT: + if (Gbl.Msg.NumMsgs == 1) + Msg_PutIconToRemoveOneSntMsg (); + else if (Gbl.Msg.NumMsgs > 1) + Msg_PutIconToRemoveSevSntMsgs (); + break; + } + + /***** Put icon to show a figure *****/ + Gbl.Stat.FigureType = Sta_MESSAGES; + Sta_PutIconToShowFigure (); + } + /*****************************************************************************/ /***************** Put icon to remove one received message *******************/ /*****************************************************************************/ @@ -2381,7 +2416,7 @@ void Msg_PutHiddenParamsMsgsFilters (void) /********************* Get dictinct courses in my messages *******************/ /*****************************************************************************/ -void Msg_GetDistinctCoursesInMyMessages (Msg_TypeOfMessages_t TypeOfMessages) +void Msg_GetDistinctCoursesInMyMessages (void) { char Query[512]; MYSQL_RES *mysql_res; @@ -2390,7 +2425,7 @@ void Msg_GetDistinctCoursesInMyMessages (Msg_TypeOfMessages_t TypeOfMessages) struct Course Crs; /***** Get distinct courses in my messages from database *****/ - switch (TypeOfMessages) + switch (Gbl.Msg.TypeOfMessages) { case Msg_MESSAGES_RECEIVED: sprintf (Query,"SELECT DISTINCT courses.CrsCod,courses.ShortName" @@ -2440,13 +2475,18 @@ void Msg_GetDistinctCoursesInMyMessages (Msg_TypeOfMessages_t TypeOfMessages) /********* Show form to select course for sent or received messages **********/ /*****************************************************************************/ -void Msg_ShowFormSelectCourseSentOrRecMsgs (Msg_TypeOfMessages_t TypeOfMessages) +void Msg_ShowFormSelectCourseSentOrRecMsgs (void) { extern const char *The_ClassForm[The_NUM_THEMES]; extern const char *Txt_Messages_received_from_A_COURSE; extern const char *Txt_Messages_sent_from_A_COURSE; extern const char *Txt_any_course; unsigned NumOriginCrs; + const char *TxtSelector[Msg_NUM_TYPES_OF_MSGS] = + { + Txt_Messages_received_from_A_COURSE, + Txt_Messages_sent_from_A_COURSE + }; /***** Course selection *****/ fprintf (Gbl.F.Out,"
"); @@ -2454,8 +2494,7 @@ void Msg_ShowFormSelectCourseSentOrRecMsgs (Msg_TypeOfMessages_t TypeOfMessages) "