Version 14.85

This commit is contained in:
Antonio Cañas Vargas 2015-03-11 12:38:47 +01:00
parent 43425e4aa1
commit 91e3111909
10 changed files with 143 additions and 46 deletions

View File

@ -1176,6 +1176,7 @@ CREATE TABLE IF NOT EXISTS usr_figures (
UsrCod INT NOT NULL,
FirstClickTime DATETIME NOT NULL,
NumClicks INT NOT NULL DEFAULT -1,
NumForPst INT NOT NULL DEFAULT -1,
NumMsgSnt INT NOT NULL DEFAULT -1,
PRIMARY KEY(UsrCod));
--

View File

@ -947,6 +947,7 @@ Users:
793. ActSeePubPrf Show a public user's profile
---. ActCal1stClkTim Calculate first click time from log and store into user's figures
---. ActCalNumClk Calculate number of clicks from log and store into user's figures
---. ActCalNumForPst Calculate number of clicks from log and store into user's figures
---. ActCalNumMsgSnt Calculate number of messages sent from log and store into user's figures
Messages:
794. ActSeeNtf Show my recent notifications
@ -2330,6 +2331,7 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] =
/* ActSeePubPrf */{1402,-1,TabUsr,ActReqPubPrf ,0x1FF,0x1FF,0x1FF,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Usr_GetUsrCodAndShowUserProfile,NULL},
/* ActCal1stClkTim */{1405,-1,TabUsr,ActReqPubPrf ,0x1FF,0x1FF,0x1FF,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Usr_CalculateFirstClickTime ,NULL},
/* ActCalNumClk */{1406,-1,TabUsr,ActReqPubPrf ,0x1FF,0x1FF,0x1FF,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Usr_CalculateNumClicks ,NULL},
/* ActCalNumForPst */{1408,-1,TabUsr,ActReqPubPrf ,0x1FF,0x1FF,0x1FF,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Usr_CalculateNumForPst ,NULL},
/* ActCalNumMsgSnt */{1407,-1,TabUsr,ActReqPubPrf ,0x1FF,0x1FF,0x1FF,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Usr_CalculateNumMsgSnt ,NULL},
// TabMsg ******************************************************************
@ -4068,6 +4070,7 @@ Act_Action_t Act_FromActCodToAction[1+Act_MAX_ACTION_COD] = // Do not reuse uniq
ActCal1stClkTim, // #1405
ActCalNumClk, // #1406
ActCalNumMsgSnt, // #1407
ActCalNumForPst, // #1408
};
/*****************************************************************************/

View File

@ -69,9 +69,9 @@ typedef enum
typedef int Act_Action_t; // Must be a signed type, because -1 is used to indicate obsolete action
#define Act_NUM_ACTIONS (7+52+15+90+73+68+204+184+103+168+28+77)
#define Act_NUM_ACTIONS (7+52+15+90+73+68+204+184+104+168+28+77)
#define Act_MAX_ACTION_COD 1407
#define Act_MAX_ACTION_COD 1408
#define Act_MAX_OPTIONS_IN_MENU_PER_TAB 20
@ -982,7 +982,8 @@ typedef int Act_Action_t; // Must be a signed type, because -1 is used to indica
#define ActSeePubPrf (ActChgNumRowFooGrp+100)
#define ActCal1stClkTim (ActChgNumRowFooGrp+101)
#define ActCalNumClk (ActChgNumRowFooGrp+102)
#define ActCalNumMsgSnt (ActChgNumRowFooGrp+103)
#define ActCalNumForPst (ActChgNumRowFooGrp+103)
#define ActCalNumMsgSnt (ActChgNumRowFooGrp+104)
/*****************************************************************************/
/******************************* Messages tab ********************************/

View File

@ -103,14 +103,19 @@
/****************************** Public constants *****************************/
/*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 14.84 (2015/03/10)"
#define Log_PLATFORM_VERSION "SWAD 14.85 (2015/03/11)"
// 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 14.85: Mar 11, 2015 Number of messages sent is stored in user's figures. (181457 lines)
2 changes necessary in database:
ALTER TABLE usr_figures ADD COLUMN NumForPst INT NOT NULL DEFAULT -1 AFTER NumClicks;
INSERT INTO actions (ActCod,Language,Obsolete,Txt) VALUES ('1408','es','N','Calcular número de mensajes en foros');
Version 14.84: Mar 10, 2015 Number of messages sent is stored in user's figures. (181374 lines)
2 changes necessary in database:
ALTER TABLE usr_figures ADD COLUMN NumMsgSnt INT NOT NULL DEFAULT -1;
ALTER TABLE usr_figures ADD COLUMN NumMsgSnt INT NOT NULL DEFAULT -1 AFTER NumClicks;
INSERT INTO actions (ActCod,Language,Obsolete,Txt) VALUES ('1407','es','N','Calcular número de mensajes enviados');
Version 14.83: Mar 10, 2015 New action to compute first click when not available in public profile. (181287 lines)

View File

@ -2346,14 +2346,16 @@ mysql> DESCRIBE usr_figures;
| UsrCod | int(11) | NO | PRI | NULL | |
| FirstClickTime | datetime | NO | | NULL | |
| NumClicks | int(11) | NO | | -1 | |
| NumForPst | int(11) | NO | | -1 | |
| NumMsgSnt | int(11) | NO | | -1 | |
+----------------+----------+------+-----+---------+-------+
4 rows in set (0.01 sec)
5 rows in set (0.00 sec)
*/
DB_CreateTable ("CREATE TABLE IF NOT EXISTS usr_figures ("
"UsrCod INT NOT NULL,"
"FirstClickTime DATETIME NOT NULL,"
"NumClicks INT NOT NULL DEFAULT -1,"
"NumForPst INT NOT NULL DEFAULT -1,"
"NumMsgSnt INT NOT NULL DEFAULT -1,"
"PRIMARY KEY(UsrCod))");

View File

@ -3819,6 +3819,9 @@ void For_RecForumPst (void)
For_UpdateThrFirstAndLastPst (ThrCod,PstCod,PstCod);
}
/***** Increment number of forum posts in my user's figures *****/
Usr_IncrementNumForPstUsr (Gbl.Usrs.Me.UsrDat.UsrCod);
/***** Write message of success *****/
Lay_ShowAlert (Lay_SUCCESS,Txt_Post_sent);
Lay_ShowAlert (Lay_INFO,Txt_Do_not_reload_this_page_because_the_post_will_be_sent_again_);

View File

@ -1185,7 +1185,7 @@ static long Msg_InsertNewMsg (const char *Subject,const char *Content)
DB_QueryINSERT (Query,"can not create message");
/***** Increment number of messages sent by me *****/
Usr_IncrementNumMsgSntUsr ();
Usr_IncrementNumMsgSntUsr (Gbl.Usrs.Me.UsrDat.UsrCod);
return MsgCod;
}

View File

@ -346,7 +346,7 @@ void Sta_LogAccess (const char *Comments)
/***** Increment my number of clicks *****/
if (Gbl.Usrs.Me.UsrDat.UsrCod > 0)
Usr_IncrementNumClicksUsr ();
Usr_IncrementNumClicksUsr (Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/

View File

@ -95,6 +95,7 @@ struct UsrFigures
{
struct DateTime FirstClickTime; // 0 ==> unknown first click time of user never logged
long NumClicks; // -1L ==> unknown number of clicks
long NumForPst; // -1L ==> unknown number of forum posts
long NumMsgSnt; // -1L ==> unknown number of messages sent
};
@ -184,8 +185,9 @@ static float Usr_GetNumUsrsPerCrs (Rol_Role_t Role);
static void Usr_ShowUserProfile (void);
static void Usr_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures);
static void Usr_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod);
static void Usr_GetNumClicksFromLogAndStoreAsUsrFigure (long UsrCod);
static void Usr_GetNumMsgSntFromLogAndStoreAsUsrFigure (long UsrCod);
static void Usr_GetNumClicksAndStoreAsUsrFigure (long UsrCod);
static void Usr_GetNumForPstAndStoreAsUsrFigure (long UsrCod);
static void Usr_GetNumMsgSntAndStoreAsUsrFigure (long UsrCod);
static bool Usr_CheckIfUsrFiguresExists (long UsrCod);
/*****************************************************************************/
@ -7744,14 +7746,22 @@ void Usr_ShowDetailsUserProfile (const struct UsrData *UsrDat)
"%s:"
"</td>"
"<td class=\"DAT\""
" style=\"text-align:left; vertical-align:middle;\">"
"%u"
"</a>"
"</td>"
"</tr>",
" style=\"text-align:left; vertical-align:middle;\">",
The_ClassFormul[Gbl.Prefs.Theme],
Txt_Forum_posts,
For_GetNumPostsUsr (UsrDat->UsrCod));
Txt_Forum_posts);
if (UsrFigures.NumForPst >= 0)
fprintf (Gbl.F.Out,"%ld",UsrFigures.NumForPst);
else // Number of forum posts is unknown
{
/***** Button to fetch and store number of forum posts *****/
Act_FormStart (ActCalNumForPst);
Usr_PutParamOtherUsrCodEncrypted (UsrDat->EncryptedUsrCod);
Act_LinkFormSubmit (Txt_Calculate,The_ClassFormul[Gbl.Prefs.Theme]);
Lay_PutSendIcon ("recycle",Txt_Calculate,Txt_Calculate);
fprintf (Gbl.F.Out,"</form>");
}
fprintf (Gbl.F.Out,"</td>"
"</tr>");
/***** Number of messages sent *****/
fprintf (Gbl.F.Out,"<tr>"
@ -7793,7 +7803,8 @@ static void Usr_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
unsigned NumRows;
/***** Get user's code from database *****/
sprintf (Query,"SELECT DATE_FORMAT(FirstClickTime,'%%Y%%m%%d%%H%%i%%S'),NumClicks,NumMsgSnt"
sprintf (Query,"SELECT DATE_FORMAT(FirstClickTime,'%%Y%%m%%d%%H%%i%%S'),"
"NumClicks,NumForPst,NumMsgSnt"
" FROM usr_figures WHERE UsrCod='%ld'",
UsrCod);
if ((NumRows = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get user's figures")))
@ -7805,12 +7816,16 @@ static void Usr_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
if (!(Dat_GetDateTimeFromYYYYMMDDHHMMSS (&(UsrFigures->FirstClickTime),row[0])))
Lay_ShowErrorAndExit ("Error when reading first click time.");
/* Get number of clicks */
/* Get number of clicks (row[1]) */
if (sscanf (row[1],"%ld",&UsrFigures->NumClicks) != 1)
UsrFigures->NumClicks = -1L;
/* Get number of messages sent */
if (sscanf (row[2],"%ld",&UsrFigures->NumMsgSnt) != 1)
/* Get number of forum posts (row[2]) */
if (sscanf (row[2],"%ld",&UsrFigures->NumForPst) != 1)
UsrFigures->NumForPst = -1L;
/* Get number of messages sent (row[3]) */
if (sscanf (row[3],"%ld",&UsrFigures->NumMsgSnt) != 1)
UsrFigures->NumMsgSnt = -1L;
}
else
@ -7819,6 +7834,7 @@ static void Usr_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
if (!(Dat_GetDateTimeFromYYYYMMDDHHMMSS (&(UsrFigures->FirstClickTime),"00000000000000")))
Lay_ShowErrorAndExit ("Error when reading first click time.");
UsrFigures->NumClicks = -1L;
UsrFigures->NumForPst = -1L;
UsrFigures->NumMsgSnt = -1L;
}
@ -7886,8 +7902,8 @@ static void Usr_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod)
}
else // User entry does not exist
{
sprintf (Query,"INSERT INTO usr_figures (UsrCod,FirstClickTime,NumClicks,NumMsgSnt)"
" VALUES ('%ld','%s','-1','-1')",
sprintf (Query,"INSERT INTO usr_figures (UsrCod,FirstClickTime,NumClicks,NumForPst,NumMsgSnt)"
" VALUES ('%ld','%s','-1','-1','-1')",
UsrCod,FirstClickTime.YYYYMMDDHHMMSS);
DB_QueryINSERT (Query,"can not create user's figures");
}
@ -7904,8 +7920,8 @@ void Usr_CalculateNumClicks (void)
/***** Get user's code *****/
Usr_GetParamOtherUsrCodEncrypted ();
/***** Get number of clicks from log and store as user's figure *****/
Usr_GetNumClicksFromLogAndStoreAsUsrFigure (Gbl.Usrs.Other.UsrDat.UsrCod);
/***** Get number of clicks and store as user's figure *****/
Usr_GetNumClicksAndStoreAsUsrFigure (Gbl.Usrs.Other.UsrDat.UsrCod);
/***** Show user's profile again *****/
Usr_ShowUserProfile ();
@ -7915,7 +7931,7 @@ void Usr_CalculateNumClicks (void)
/* Get number of clicks of a user from log table and store in user's figures */
/*****************************************************************************/
static void Usr_GetNumClicksFromLogAndStoreAsUsrFigure (long UsrCod)
static void Usr_GetNumClicksAndStoreAsUsrFigure (long UsrCod)
{
char Query[256];
unsigned long NumClicks;
@ -7937,14 +7953,62 @@ static void Usr_GetNumClicksFromLogAndStoreAsUsrFigure (long UsrCod)
}
else // User entry does not exist
{
sprintf (Query,"INSERT INTO usr_figures (UsrCod,FirstClickTime,NumClicks,NumMsgSnt)"
" VALUES ('%ld','00000000000000','%ld','-1')",
sprintf (Query,"INSERT INTO usr_figures (UsrCod,FirstClickTime,NumClicks,NumForPst,NumMsgSnt)"
" VALUES ('%ld','00000000000000','%ld','-1','-1')",
UsrCod,NumClicks);
DB_QueryINSERT (Query,"can not create user's figures");
}
}
}
/*****************************************************************************/
/******* Calculate number of forum posts and show user's profile again *******/
/*****************************************************************************/
void Usr_CalculateNumForPst (void)
{
/***** Get user's code *****/
Usr_GetParamOtherUsrCodEncrypted ();
/***** Get number of forum posts and store as user's figure *****/
Usr_GetNumForPstAndStoreAsUsrFigure (Gbl.Usrs.Other.UsrDat.UsrCod);
/***** Show user's profile again *****/
Usr_ShowUserProfile ();
}
/*****************************************************************************/
/**** Get number of forum posts sent by a user and store in user's figures ***/
/*****************************************************************************/
static void Usr_GetNumForPstAndStoreAsUsrFigure (long UsrCod)
{
char Query[256];
unsigned long NumForPst;
if (Usr_ChkIfUsrCodExists (UsrCod))
{
/***** Get number of forum posts from database *****/
NumForPst = For_GetNumPostsUsr (UsrCod);
/***** Update number of forum posts in user's figures *****/
if (Usr_CheckIfUsrFiguresExists (UsrCod))
{
sprintf (Query,"UPDATE usr_figures SET NumForPst='%ld'"
" WHERE UsrCod='%ld'",
NumForPst,UsrCod);
DB_QueryUPDATE (Query,"can not update user's figures");
}
else // User entry does not exist
{
sprintf (Query,"INSERT INTO usr_figures (UsrCod,FirstClickTime,NumClicks,NumForPst,NumMsgSnt)"
" VALUES ('%ld','00000000000000','-1','%ld','-1')",
UsrCod,NumForPst);
DB_QueryINSERT (Query,"can not create user's figures");
}
}
}
/*****************************************************************************/
/****** Calculate number of messages sent and show user's profile again ******/
/*****************************************************************************/
@ -7954,28 +8018,28 @@ void Usr_CalculateNumMsgSnt (void)
/***** Get user's code *****/
Usr_GetParamOtherUsrCodEncrypted ();
/***** Get number of clicks from log and store as user's figure *****/
Usr_GetNumMsgSntFromLogAndStoreAsUsrFigure (Gbl.Usrs.Other.UsrDat.UsrCod);
/***** Get number of messages sent and store as user's figure *****/
Usr_GetNumMsgSntAndStoreAsUsrFigure (Gbl.Usrs.Other.UsrDat.UsrCod);
/***** Show user's profile again *****/
Usr_ShowUserProfile ();
}
/*****************************************************************************/
/* Get number of clicks of a user from log table and store in user's figures */
/***** Get number of messages sent by a user and store in user's figures *****/
/*****************************************************************************/
static void Usr_GetNumMsgSntFromLogAndStoreAsUsrFigure (long UsrCod)
static void Usr_GetNumMsgSntAndStoreAsUsrFigure (long UsrCod)
{
char Query[256];
unsigned long NumMsgSnt;
if (Usr_ChkIfUsrCodExists (UsrCod))
{
/***** Get number of clicks from database *****/
/***** Get number of messages sent from database *****/
NumMsgSnt = Msg_GetNumMsgsSentByUsr (UsrCod);
/***** Update number of clicks in user's figures *****/
/***** Update number of messages sent in user's figures *****/
if (Usr_CheckIfUsrFiguresExists (UsrCod))
{
sprintf (Query,"UPDATE usr_figures SET NumMsgSnt='%ld'"
@ -7985,8 +8049,8 @@ static void Usr_GetNumMsgSntFromLogAndStoreAsUsrFigure (long UsrCod)
}
else // User entry does not exist
{
sprintf (Query,"INSERT INTO usr_figures (UsrCod,FirstClickTime,NumClicks,NumMsgSnt)"
" VALUES ('%ld','00000000000000','-1','%ld')",
sprintf (Query,"INSERT INTO usr_figures (UsrCod,FirstClickTime,NumClicks,NumForPst,NumMsgSnt)"
" VALUES ('%ld','00000000000000','-1','-1','-1','%ld')",
UsrCod,NumMsgSnt);
DB_QueryINSERT (Query,"can not create user's figures");
}
@ -8007,33 +8071,49 @@ static bool Usr_CheckIfUsrFiguresExists (long UsrCod)
}
/*****************************************************************************/
/********************** Select values on user's figures **********************/
/*************** Increment number of clicks made by a user *******************/
/*****************************************************************************/
void Usr_IncrementNumClicksUsr (void)
void Usr_IncrementNumClicksUsr (long UsrCod)
{
char Query[256];
/***** Increment my number of clicks *****/
/***** Increment number of clicks *****/
// If NumClicks < 0 ==> not yet calculated, so do nothing
sprintf (Query,"UPDATE IGNORE usr_figures SET NumClicks=NumClicks+1"
" WHERE UsrCod='%ld' AND NumClicks>=0",
Gbl.Usrs.Me.UsrDat.UsrCod);
UsrCod);
DB_QueryINSERT (Query,"can not increment user's clicks");
}
/*****************************************************************************/
/********************** Select values on user's figures **********************/
/************* Increment number of forum posts sent by a user ****************/
/*****************************************************************************/
void Usr_IncrementNumMsgSntUsr (void)
void Usr_IncrementNumForPstUsr (long UsrCod)
{
char Query[256];
/***** Increment my number of messages sent *****/
/***** Increment number of forum posts *****/
// If NumForPst < 0 ==> not yet calculated, so do nothing
sprintf (Query,"UPDATE IGNORE usr_figures SET NumForPst=NumForPst+1"
" WHERE UsrCod='%ld' AND NumForPst>=0",
UsrCod);
DB_QueryINSERT (Query,"can not increment user's forum posts");
}
/*****************************************************************************/
/*************** Increment number of messages sent by a user *****************/
/*****************************************************************************/
void Usr_IncrementNumMsgSntUsr (long UsrCod)
{
char Query[256];
/***** Increment number of messages sent *****/
// If NumMsgSnt < 0 ==> not yet calculated, so do nothing
sprintf (Query,"UPDATE IGNORE usr_figures SET NumMsgSnt=NumMsgSnt+1"
" WHERE UsrCod='%ld' AND NumMsgSnt>=0",
Gbl.Usrs.Me.UsrDat.UsrCod);
UsrCod);
DB_QueryINSERT (Query,"can not increment user's messages sent");
}

View File

@ -330,8 +330,10 @@ void Usr_ChangeProfileVisibility (void);
void Usr_ShowDetailsUserProfile (const struct UsrData *UsrDat);
void Usr_CalculateFirstClickTime (void);
void Usr_CalculateNumClicks (void);
void Usr_CalculateNumForPst (void);
void Usr_CalculateNumMsgSnt (void);
void Usr_IncrementNumClicksUsr (void);
void Usr_IncrementNumMsgSntUsr (void);
void Usr_IncrementNumClicksUsr (long UsrCod);
void Usr_IncrementNumForPstUsr (long UsrCod);
void Usr_IncrementNumMsgSntUsr (long UsrCod);
#endif