");
if (Gbl.Prefs.Menu == Mnu_MENU_VERTICAL)
@@ -382,7 +382,7 @@ static void Lay_WriteEndOfPage (void)
/* Right bar used to expand-contract central zone */
fprintf (Gbl.F.Out,"
");
}
@@ -657,7 +657,7 @@ static void Lay_WritePageTopHeading (void)
if (Gbl.Usrs.Me.Logged)
Usr_WriteLoggedUsrHead ();
else
- Prf_PutSelectorToSelectLanguage ();
+ Pre_PutSelectorToSelectLanguage ();
fprintf (Gbl.F.Out,""
""
""
@@ -1191,7 +1191,7 @@ void Lay_RefreshNotifsAndConnected (void)
else if (!(Gbl.PID % 1013)) // Do this only one of 1013 times (1013 is prime)
Brw_RemoveExpiredExpandedFolders (); // Remove old expanded folders (from all users)
else if (!(Gbl.PID % 1019)) // Do this only one of 1019 times (1019 is prime)
- Prf_RemoveOldPrefsFromIP (); // Remove old preferences from IP
+ Pre_RemoveOldPrefsFromIP (); // Remove old preferences from IP
else if (!(Gbl.PID % 1021)) // Do this only one of 1021 times (1021 is prime)
Sta_RemoveOldEntriesRecentLog (); // Remove old entries in recent log table, it's a slow query
@@ -1466,7 +1466,7 @@ void Lay_ChangeLayout (void)
}
/***** Set preferences from current IP *****/
- Prf_SetPrefsFromIP ();
+ Pre_SetPrefsFromIP ();
}
/*****************************************************************************/
diff --git a/swad_menu.c b/swad_menu.c
index 10a93800..5e8a5ee4 100644
--- a/swad_menu.c
+++ b/swad_menu.c
@@ -352,7 +352,7 @@ void Mnu_ChangeMenu (void)
}
/***** Set preferences from current IP *****/
- Prf_SetPrefsFromIP ();
+ Pre_SetPrefsFromIP ();
}
/*****************************************************************************/
diff --git a/swad_message.c b/swad_message.c
index 7e882854..f8a5a702 100644
--- a/swad_message.c
+++ b/swad_message.c
@@ -42,6 +42,7 @@
#include "swad_notification.h"
#include "swad_parameter.h"
#include "swad_photo.h"
+#include "swad_profile.h"
#include "swad_user.h"
/*****************************************************************************/
@@ -1185,7 +1186,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 (Gbl.Usrs.Me.UsrDat.UsrCod);
+ Prf_IncrementNumMsgSntUsr (Gbl.Usrs.Me.UsrDat.UsrCod);
return MsgCod;
}
diff --git a/swad_network.c b/swad_network.c
index 46dce87a..70c5fce6 100644
--- a/swad_network.c
+++ b/swad_network.c
@@ -30,6 +30,7 @@
#include "swad_database.h"
#include "swad_global.h"
#include "swad_parameter.h"
+#include "swad_profile.h"
#include "swad_theme.h"
/*****************************************************************************/
@@ -134,13 +135,15 @@ const char *Net_TitleWebsAndSocialNetworks[Net_NUM_WEBS_AND_SOCIAL_NETWORKS] =
/***************************** Private prototypes ****************************/
/*****************************************************************************/
+static void Net_ShowAWebOrSocialNet (const char *URL,
+ const char *Icon,const char *Title);
static void Net_GetMyWebsAndSocialNetsFromForm (void);
/*****************************************************************************/
/************************** Show webs / social networks **********************/
/*****************************************************************************/
-void Net_ShowWebsAndSocialNets (long UsrCod)
+void Net_ShowWebsAndSocialNets (const struct UsrData *UsrDat)
{
char Query[256];
MYSQL_RES *mysql_res;
@@ -148,8 +151,14 @@ void Net_ShowWebsAndSocialNets (long UsrCod)
Net_WebsAndSocialNetworks_t NumURL;
char URL[Cns_MAX_BYTES_URL+1];
+ /***** Start container *****/
fprintf (Gbl.F.Out,"
");
+ /***** Show link to public profile *****/
+ Net_ShowAWebOrSocialNet (Prf_GetURLPublicProfile (URL,UsrDat->Nickname),
+ "swad",Cfg_PLATFORM_PAGE_TITLE);
+
+ /***** Show the rest of webs / social networks *****/
for (NumURL = (Net_WebsAndSocialNetworks_t) 0;
NumURL < Net_NUM_WEBS_AND_SOCIAL_NETWORKS;
NumURL++)
@@ -157,38 +166,49 @@ void Net_ShowWebsAndSocialNets (long UsrCod)
/***** Get user's web / social network from database *****/
sprintf (Query,"SELECT URL FROM usr_webs"
" WHERE UsrCod='%ld' AND Web='%s'",
- UsrCod,
- Net_WebsAndSocialNetworksDB[NumURL]);
+ UsrDat->UsrCod,Net_WebsAndSocialNetworksDB[NumURL]);
- /***** Check number of rows in result *****/
+ /***** Check if exists the web / social network for this user *****/
if (DB_QuerySELECT (Query,&mysql_res,"can not get user's web / social network"))
{
- /***** Get URL *****/
+ /* Get URL */
row = mysql_fetch_row (mysql_res);
strncpy (URL,row[0],Cns_MAX_BYTES_URL);
URL[Cns_MAX_BYTES_URL] = '\0';
- /***** Write link and icon *****/
- fprintf (Gbl.F.Out,"
");
+
+ /***** Number of courses in which the user is teacher or student *****/
+ if ((NumCrssUsrIsTeacher = Usr_GetNumCrssOfUsrWithARole (UsrDat->UsrCod,Rol_ROLE_TEACHER)))
+ {
+ NumTchs = Usr_GetNumUsrsInCrssOfAUsr (UsrDat->UsrCod,Rol_ROLE_TEACHER,Rol_ROLE_TEACHER);
+ NumStds = Usr_GetNumUsrsInCrssOfAUsr (UsrDat->UsrCod,Rol_ROLE_TEACHER,Rol_ROLE_STUDENT);
+ fprintf (Gbl.F.Out,"
");
+
+ /***** Number of posts in forums *****/
+ fprintf (Gbl.F.Out,"
"
+ "
"
+ "%s"
+ "
"
+ "
",
+ The_ClassFormul[Gbl.Prefs.Theme],
+ Txt_Forums);
+ if (UsrFigures.NumForPst >= 0)
+ {
+ fprintf (Gbl.F.Out,"%ld %s",
+ UsrFigures.NumForPst,
+ (UsrFigures.NumForPst == 1) ? Txt_post :
+ Txt_posts);
+ if (UsrFigures.NumDays >= 0)
+ {
+ fprintf (Gbl.F.Out," ");
+ Str_WriteFloatNum ((float) UsrFigures.NumForPst /
+ (float) (UsrFigures.NumDays + 1));
+ fprintf (Gbl.F.Out," / %s",Txt_day);
+ }
+ }
+ else // Number of forum posts is unknown
+ {
+ /***** Button to fetch and store number of forum posts *****/
+ Act_FormStart (ActCalNumForPst);
+ Usr_PutParamOtherUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Act_LinkFormSubmitAnimated (Txt_Calculate,The_ClassFormul[Gbl.Prefs.Theme],
+ "calculate4","calculating4");
+ Lay_PutCalculateIcon (Txt_Calculate,Txt_Calculate,
+ "calculate4","calculating4");
+ Act_FormEnd ();
+ }
+ fprintf (Gbl.F.Out,"
"
+ "
");
+
+ /***** Number of messages sent *****/
+ fprintf (Gbl.F.Out,"
"
+ "
"
+ "%s"
+ "
"
+ "
",
+ The_ClassFormul[Gbl.Prefs.Theme],
+ Txt_Messages);
+ if (UsrFigures.NumMsgSnt >= 0)
+ {
+ fprintf (Gbl.F.Out,"%ld %s",
+ UsrFigures.NumMsgSnt,
+ (UsrFigures.NumMsgSnt == 1) ? Txt_message :
+ Txt_messages);
+ if (UsrFigures.NumDays >= 0)
+ {
+ fprintf (Gbl.F.Out," ");
+ Str_WriteFloatNum ((float) UsrFigures.NumMsgSnt /
+ (float) (UsrFigures.NumDays + 1));
+ fprintf (Gbl.F.Out," / %s",Txt_day);
+ }
+ }
+ else // Number of clicks is unknown
+ {
+ /***** Button to fetch and store number of messages sent *****/
+ Act_FormStart (ActCalNumMsgSnt);
+ Usr_PutParamOtherUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Act_LinkFormSubmitAnimated (Txt_Calculate,The_ClassFormul[Gbl.Prefs.Theme],
+ "calculate5","calculating5");
+ Lay_PutCalculateIcon (Txt_Calculate,Txt_Calculate,
+ "calculate5","calculating5");
+ Act_FormEnd ();
+ }
+ fprintf (Gbl.F.Out,"
"
+ "
");
+
+ /***** End of table *****/
+ fprintf (Gbl.F.Out,"
");
+ }
+
+/*****************************************************************************/
+/********************** Select values on user's figures **********************/
+/*****************************************************************************/
+
+static void Prf_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
+ {
+ char Query[512];
+ MYSQL_RES *mysql_res;
+ MYSQL_ROW row;
+ unsigned NumRows;
+
+ /***** Get user's figures from database *****/
+ sprintf (Query,"SELECT DATE_FORMAT(FirstClickTime,'%%Y%%m%%d%%H%%i%%S'),"
+ "DATEDIFF(NOW(),FirstClickTime),"
+ "NumClicks,NumFileViews,NumForPst,NumMsgSnt"
+ " FROM usr_figures WHERE UsrCod='%ld'",
+ UsrCod);
+ if ((NumRows = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get user's figures")))
+ {
+ /***** Get user's figures *****/
+ row = mysql_fetch_row (mysql_res);
+
+ /* Get first click (row[0] holds the start date in YYYYMMDDHHMMSS format) */
+ if (!(Dat_GetDateTimeFromYYYYMMDDHHMMSS (&(UsrFigures->FirstClickTime),row[0])))
+ Lay_ShowErrorAndExit ("Error when reading first click time.");
+
+ /* Get number of days since first click (row[1]) */
+ if (UsrFigures->FirstClickTime.Date.Year)
+ {
+ if (sscanf (row[1],"%d",&UsrFigures->NumDays) != 1)
+ UsrFigures->NumDays = -1;
+ }
+ else
+ UsrFigures->NumDays = -1;
+
+ /* Get number of clicks (row[2]) */
+ if (sscanf (row[2],"%ld",&UsrFigures->NumClicks) != 1)
+ UsrFigures->NumClicks = -1L;
+
+ /* Get number of file views (row[3]) */
+ if (sscanf (row[3],"%ld",&UsrFigures->NumFileViews) != 1)
+ UsrFigures->NumFileViews = -1L;
+
+ /* Get number of forum posts (row[4]) */
+ if (sscanf (row[4],"%ld",&UsrFigures->NumForPst) != 1)
+ UsrFigures->NumForPst = -1L;
+
+ /* Get number of messages sent (row[5]) */
+ if (sscanf (row[5],"%ld",&UsrFigures->NumMsgSnt) != 1)
+ UsrFigures->NumMsgSnt = -1L;
+ }
+ else
+ /***** Return special user's figures indicating "not present" *****/
+ Prf_ResetUsrFigures (UsrFigures);
+
+ /***** Free structure that stores the query result *****/
+ DB_FreeMySQLResult (&mysql_res);
+ }
+
+/*****************************************************************************/
+/********** Get ranking of a user according to the number of clicks **********/
+/*****************************************************************************/
+
+static unsigned long Prf_GetRankingNumClicks (long UsrCod)
+ {
+ char Query[128];
+
+ /***** Select number of rows with number of clicks
+ greater than the clicks of this user *****/
+ sprintf (Query,"SELECT COUNT(*)+1 FROM usr_figures"
+ " WHERE UsrCod<>'%ld'" // Really not necessary here
+ " AND NumClicks>"
+ "(SELECT NumClicks FROM usr_figures WHERE UsrCod='%ld')",
+ UsrCod,UsrCod);
+ return DB_QueryCOUNT (Query,"can not get ranking using number of clicks");
+ }
+
+/*****************************************************************************/
+/******************* Get number of users with number of clicks ***************/
+/*****************************************************************************/
+
+static unsigned long Prf_GetNumUsrsWithNumClicks (void)
+ {
+ char Query[128];
+
+ /***** Select number of rows with values already calculated *****/
+ sprintf (Query,"SELECT COUNT(*) FROM usr_figures WHERE NumClicks>='0'");
+ return DB_QueryCOUNT (Query,"can not get number of users with number of clicks");
+ }
+
+/*****************************************************************************/
+/****** Get ranking of a user according to the number of clicks per day ******/
+/*****************************************************************************/
+
+static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
+ {
+ char Query[512];
+
+ /***** Select number of rows with number of clicks per day
+ greater than the clicks per day of this user *****/
+ sprintf (Query,"SELECT COUNT(*)+1 FROM"
+ " (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
+ " AS NumClicksPerDay"
+ " FROM usr_figures"
+ " WHERE UsrCod<>'%ld'" // Necessary because the following comparison is not exact in floating point
+ " AND NumClicks>='0' AND UNIX_TIMESTAMP(FirstClickTime)>'0')"
+ " AS TableNumClicksPerDay"
+ " WHERE NumClicksPerDay>"
+ "(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
+ " FROM usr_figures"
+ " WHERE UsrCod='%ld'"
+ " AND NumClicks>='0' AND UNIX_TIMESTAMP(FirstClickTime)>'0')",
+ UsrCod,UsrCod);
+ return DB_QueryCOUNT (Query,"can not get ranking using number of clicks per day");
+ }
+
+/*****************************************************************************/
+/************** Get number of users with number of clicks per day ************/
+/*****************************************************************************/
+
+static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void)
+ {
+ char Query[128];
+
+ /***** Select number of rows with values already calculated *****/
+ sprintf (Query,"SELECT COUNT(*) FROM usr_figures"
+ " WHERE NumClicks>='0' AND UNIX_TIMESTAMP(FirstClickTime)>'0'");
+ return DB_QueryCOUNT (Query,"can not get number of users with number of clicks per day");
+ }
+
+/*****************************************************************************/
+/********* Calculate first click time and show user's profile again **********/
+/*****************************************************************************/
+
+void Prf_CalculateFirstClickTime (void)
+ {
+ /***** Get user's code *****/
+ Usr_GetParamOtherUsrCodEncrypted ();
+
+ /***** Get first click time from log and store as user's figure *****/
+ Prf_GetFirstClickFromLogAndStoreAsUsrFigure (Gbl.Usrs.Other.UsrDat.UsrCod);
+
+ /***** Show user's profile again *****/
+ Prf_ShowUserProfile ();
+ }
+
+/*****************************************************************************/
+/*** Get first click of a user from log table and store in user's figures ****/
+/*****************************************************************************/
+
+static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod)
+ {
+ char Query[256];
+ MYSQL_RES *mysql_res;
+ MYSQL_ROW row;
+ struct UsrFigures UsrFigures;
+
+ if (Usr_ChkIfUsrCodExists (UsrCod))
+ {
+ /***** Reset user's figures *****/
+ Prf_ResetUsrFigures (&UsrFigures);
+
+ /***** Get first click from log table *****/
+ sprintf (Query,"SELECT DATE_FORMAT("
+ "(SELECT MIN(ClickTime) FROM log WHERE UsrCod='%ld')"
+ ",'%%Y%%m%%d%%H%%i%%S')",
+ UsrCod);
+ if (DB_QuerySELECT (Query,&mysql_res,"can not get user's first click"))
+ {
+ /* Get first click */
+ row = mysql_fetch_row (mysql_res);
+
+ /* Get first click (row[0] holds the start date in YYYYMMDDHHMMSS format) */
+ if (row[0]) // It is NULL when user never logged
+ if (!(Dat_GetDateTimeFromYYYYMMDDHHMMSS (&(UsrFigures.FirstClickTime),row[0])))
+ Lay_ShowErrorAndExit ("Error when reading first click time.");
+ }
+ /* Free structure that stores the query result */
+ DB_FreeMySQLResult (&mysql_res);
+
+ /***** Update first click time in user's figures *****/
+ if (Prf_CheckIfUsrFiguresExists (UsrCod))
+ {
+ sprintf (Query,"UPDATE usr_figures SET FirstClickTime='%s'"
+ " WHERE UsrCod='%ld'",
+ UsrFigures.FirstClickTime.YYYYMMDDHHMMSS,UsrCod);
+ DB_QueryUPDATE (Query,"can not update user's figures");
+ }
+ else // User entry does not exist
+ Prf_CreateUsrFigures (UsrCod,&UsrFigures);
+ }
+ }
+
+/*****************************************************************************/
+/********* Calculate number of clicks and show user's profile again **********/
+/*****************************************************************************/
+
+void Prf_CalculateNumClicks (void)
+ {
+ /***** Get user's code *****/
+ Usr_GetParamOtherUsrCodEncrypted ();
+
+ /***** Get number of clicks and store as user's figure *****/
+ Prf_GetNumClicksAndStoreAsUsrFigure (Gbl.Usrs.Other.UsrDat.UsrCod);
+
+ /***** Show user's profile again *****/
+ Prf_ShowUserProfile ();
+ }
+
+/*****************************************************************************/
+/* Get number of clicks of a user from log table and store in user's figures */
+/*****************************************************************************/
+
+static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod)
+ {
+ char Query[256];
+ struct UsrFigures UsrFigures;
+
+ if (Usr_ChkIfUsrCodExists (UsrCod))
+ {
+ /***** Reset user's figures *****/
+ Prf_ResetUsrFigures (&UsrFigures);
+
+ /***** Get number of clicks from database *****/
+ sprintf (Query,"SELECT COUNT(*) FROM log WHERE UsrCod='%ld'",
+ UsrCod);
+ UsrFigures.NumClicks = (long) DB_QueryCOUNT (Query,"can not get number of clicks");
+
+ /***** Update number of clicks in user's figures *****/
+ if (Prf_CheckIfUsrFiguresExists (UsrCod))
+ {
+ sprintf (Query,"UPDATE usr_figures SET NumClicks='%ld'"
+ " WHERE UsrCod='%ld'",
+ UsrFigures.NumClicks,UsrCod);
+ DB_QueryUPDATE (Query,"can not update user's figures");
+ }
+ else // User entry does not exist
+ Prf_CreateUsrFigures (UsrCod,&UsrFigures);
+ }
+ }
+
+/*****************************************************************************/
+/******* Calculate number of file views and show user's profile again *******/
+/*****************************************************************************/
+
+void Prf_CalculateNumFileViews (void)
+ {
+ /***** Get user's code *****/
+ Usr_GetParamOtherUsrCodEncrypted ();
+
+ /***** Get number of file views and store as user's figure *****/
+ Prf_GetNumFileViewsAndStoreAsUsrFigure (Gbl.Usrs.Other.UsrDat.UsrCod);
+
+ /***** Show user's profile again *****/
+ Prf_ShowUserProfile ();
+ }
+
+/*****************************************************************************/
+/**** Get number of file views sent by a user and store in user's figures ****/
+/*****************************************************************************/
+
+static void Prf_GetNumFileViewsAndStoreAsUsrFigure (long UsrCod)
+ {
+ char Query[256];
+ struct UsrFigures UsrFigures;
+
+ if (Usr_ChkIfUsrCodExists (UsrCod))
+ {
+ /***** Reset user's figures *****/
+ Prf_ResetUsrFigures (&UsrFigures);
+
+ /***** Get number of file views from database *****/
+ UsrFigures.NumFileViews = Brw_GetNumFileViewsUsr (UsrCod);
+
+ /***** Update number of file views in user's figures *****/
+ if (Prf_CheckIfUsrFiguresExists (UsrCod))
+ {
+ sprintf (Query,"UPDATE usr_figures SET NumFileViews='%ld'"
+ " WHERE UsrCod='%ld'",
+ UsrFigures.NumFileViews,UsrCod);
+ DB_QueryUPDATE (Query,"can not update user's figures");
+ }
+ else // User entry does not exist
+ Prf_CreateUsrFigures (UsrCod,&UsrFigures);
+ }
+ }
+
+/*****************************************************************************/
+/******* Calculate number of forum posts and show user's profile again *******/
+/*****************************************************************************/
+
+void Prf_CalculateNumForPst (void)
+ {
+ /***** Get user's code *****/
+ Usr_GetParamOtherUsrCodEncrypted ();
+
+ /***** Get number of forum posts and store as user's figure *****/
+ Prf_GetNumForPstAndStoreAsUsrFigure (Gbl.Usrs.Other.UsrDat.UsrCod);
+
+ /***** Show user's profile again *****/
+ Prf_ShowUserProfile ();
+ }
+
+/*****************************************************************************/
+/**** Get number of forum posts sent by a user and store in user's figures ***/
+/*****************************************************************************/
+
+static void Prf_GetNumForPstAndStoreAsUsrFigure (long UsrCod)
+ {
+ char Query[256];
+ struct UsrFigures UsrFigures;
+
+ if (Usr_ChkIfUsrCodExists (UsrCod))
+ {
+ /***** Reset user's figures *****/
+ Prf_ResetUsrFigures (&UsrFigures);
+
+ /***** Get number of forum posts from database *****/
+ UsrFigures.NumForPst = For_GetNumPostsUsr (UsrCod);
+
+ /***** Update number of forum posts in user's figures *****/
+ if (Prf_CheckIfUsrFiguresExists (UsrCod))
+ {
+ sprintf (Query,"UPDATE usr_figures SET NumForPst='%ld'"
+ " WHERE UsrCod='%ld'",
+ UsrFigures.NumForPst,UsrCod);
+ DB_QueryUPDATE (Query,"can not update user's figures");
+ }
+ else // User entry does not exist
+ Prf_CreateUsrFigures (UsrCod,&UsrFigures);
+ }
+ }
+
+/*****************************************************************************/
+/****** Calculate number of messages sent and show user's profile again ******/
+/*****************************************************************************/
+
+void Prf_CalculateNumMsgSnt (void)
+ {
+ /***** Get user's code *****/
+ Usr_GetParamOtherUsrCodEncrypted ();
+
+ /***** Get number of messages sent and store as user's figure *****/
+ Prf_GetNumMsgSntAndStoreAsUsrFigure (Gbl.Usrs.Other.UsrDat.UsrCod);
+
+ /***** Show user's profile again *****/
+ Prf_ShowUserProfile ();
+ }
+
+/*****************************************************************************/
+/***** Get number of messages sent by a user and store in user's figures *****/
+/*****************************************************************************/
+
+static void Prf_GetNumMsgSntAndStoreAsUsrFigure (long UsrCod)
+ {
+ char Query[256];
+ struct UsrFigures UsrFigures;
+
+ if (Usr_ChkIfUsrCodExists (UsrCod))
+ {
+ /***** Reset user's figures *****/
+ Prf_ResetUsrFigures (&UsrFigures);
+
+ /***** Get number of messages sent from database *****/
+ UsrFigures.NumMsgSnt = Msg_GetNumMsgsSentByUsr (UsrCod);
+
+ /***** Update number of messages sent in user's figures *****/
+ if (Prf_CheckIfUsrFiguresExists (UsrCod))
+ {
+ sprintf (Query,"UPDATE usr_figures SET NumMsgSnt='%ld'"
+ " WHERE UsrCod='%ld'",
+ UsrFigures.NumMsgSnt,UsrCod);
+ DB_QueryUPDATE (Query,"can not update user's figures");
+ }
+ else // User entry does not exist
+ Prf_CreateUsrFigures (UsrCod,&UsrFigures);
+ }
+ }
+
+/*****************************************************************************/
+/********************** Reset values of user's figures ***********************/
+/*****************************************************************************/
+
+static void Prf_ResetUsrFigures (struct UsrFigures *UsrFigures)
+ {
+ Dat_GetDateTimeFromYYYYMMDDHHMMSS (&(UsrFigures->FirstClickTime),"00000000000000"); // unknown first click time or user never logged
+ UsrFigures->NumDays = -1; // not applicable
+ UsrFigures->NumClicks = -1L; // unknown number of clicks
+ UsrFigures->NumFileViews = -1L; // unknown number of file views
+ UsrFigures->NumForPst = -1L; // unknown number of forum posts
+ UsrFigures->NumMsgSnt = -1L; // unknown number of messages sent
+ }
+
+/*****************************************************************************/
+/***** Get number of messages sent by a user and store in user's figures *****/
+/*****************************************************************************/
+
+static void Prf_CreateUsrFigures (long UsrCod,const struct UsrFigures *UsrFigures)
+ {
+ char Query[256];
+
+ /***** Create user's figures *****/
+ sprintf (Query,"INSERT INTO usr_figures (UsrCod,FirstClickTime,NumClicks,NumFileViews,NumForPst,NumMsgSnt)"
+ " VALUES ('%ld','%s','%ld','%ld','%ld','%ld')",
+ UsrCod,
+ UsrFigures->FirstClickTime.YYYYMMDDHHMMSS, // 0 ==> unknown first click time or user never logged
+ UsrFigures->NumClicks, // -1L ==> unknown number of clicks
+ UsrFigures->NumFileViews, // -1L ==> unknown number of file views
+ UsrFigures->NumForPst, // -1L ==> unknown number of forum posts
+ UsrFigures->NumMsgSnt); // -1L ==> unknown number of messages sent
+ DB_QueryINSERT (Query,"can not create user's figures");
+ }
+
+/*****************************************************************************/
+/**************************** Remove user's figures **************************/
+/*****************************************************************************/
+
+void Prf_RemoveUsrFigures (long UsrCod)
+ {
+ char Query[128];
+
+ /***** Remove user's figures *****/
+ sprintf (Query,"DELETE FROM usr_figures WHERE UsrCod='%ld'",
+ UsrCod);
+ DB_QueryDELETE (Query,"can not delete user's figures");
+ }
+
+/*****************************************************************************/
+/*** Check if it exists an entry for this user in table of user's figures ****/
+/*****************************************************************************/
+
+static bool Prf_CheckIfUsrFiguresExists (long UsrCod)
+ {
+ char Query[128];
+
+ sprintf (Query,"SELECT COUNT(*) FROM usr_figures WHERE UsrCod='%ld'",
+ UsrCod);
+ return (DB_QueryCOUNT (Query,"can not get user's first click") != 0);
+ }
+
+/*****************************************************************************/
+/*************** Increment number of clicks made by a user *******************/
+/*****************************************************************************/
+
+void Prf_IncrementNumClicksUsr (long UsrCod)
+ {
+ char Query[256];
+
+ /***** 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",
+ UsrCod);
+ DB_QueryINSERT (Query,"can not increment user's clicks");
+ }
+
+/*****************************************************************************/
+/************** Increment number of file views sent by a user ****************/
+/*****************************************************************************/
+
+void Prf_IncrementNumFileViewsUsr (long UsrCod)
+ {
+ char Query[256];
+
+ /***** Increment number of file views *****/
+ // If NumFileViews < 0 ==> not yet calculated, so do nothing
+ sprintf (Query,"UPDATE IGNORE usr_figures SET NumFileViews=NumFileViews+1"
+ " WHERE UsrCod='%ld' AND NumFileViews>=0",
+ UsrCod);
+ DB_QueryINSERT (Query,"can not increment user's file views");
+ }
+
+/*****************************************************************************/
+/************* Increment number of forum posts sent by a user ****************/
+/*****************************************************************************/
+
+void Prf_IncrementNumForPstUsr (long UsrCod)
+ {
+ char Query[256];
+
+ /***** 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 Prf_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",
+ UsrCod);
+ DB_QueryINSERT (Query,"can not increment user's messages sent");
+ }
diff --git a/swad_profile.h b/swad_profile.h
new file mode 100644
index 00000000..63045f56
--- /dev/null
+++ b/swad_profile.h
@@ -0,0 +1,57 @@
+// swad_profile.h: user's public profile
+
+#ifndef _SWAD_PRF
+#define _SWAD_PRF
+/*
+ SWAD (Shared Workspace At a Distance in Spanish),
+ 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ñas Vargas
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public 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 .
+*/
+/*****************************************************************************/
+/********************************** Headers **********************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/****************************** Public constants *****************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/******************************** Public types *******************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/****************************** Public prototypes ****************************/
+/*****************************************************************************/
+
+char *Prf_GetURLPublicProfile (char *URL,const char *NicknameWithoutArroba);
+void Prf_RequestUserProfile (void);
+void Prf_GetUsrCodAndShowUserProfile (void);
+void Prf_ChangeProfileVisibility (void);
+void Prf_CalculateFirstClickTime (void);
+void Prf_CalculateNumClicks (void);
+void Prf_CalculateNumFileViews (void);
+void Prf_CalculateNumForPst (void);
+void Prf_CalculateNumMsgSnt (void);
+void Prf_RemoveUsrFigures (long UsrCod);
+void Prf_IncrementNumClicksUsr (long UsrCod);
+void Prf_IncrementNumFileViewsUsr (long UsrCod);
+void Prf_IncrementNumForPstUsr (long UsrCod);
+void Prf_IncrementNumMsgSntUsr (long UsrCod);
+
+#endif
diff --git a/swad_profile.o b/swad_profile.o
new file mode 100644
index 00000000..e9e1faf4
Binary files /dev/null and b/swad_profile.o differ
diff --git a/swad_record.c b/swad_record.c
index 6635c768..daba8acb 100644
--- a/swad_record.c
+++ b/swad_record.c
@@ -2030,8 +2030,6 @@ void Rec_ShowSharedUsrRecord (Rec_RecordViewType_t TypeOfView,
extern const char *Txt_First_name;
extern const char *Txt_Country;
extern const char *Txt_Another_country;
- extern const char *Txt_Shortcut;
- extern const char *Txt_STR_LANG_ID[Txt_NUM_LANGUAGES];
extern const char *Txt_Place_of_origin;
extern const char *Txt_Date_of_birth;
extern const char *Txt_Institution;
@@ -2045,7 +2043,7 @@ void Rec_ShowSharedUsrRecord (Rec_RecordViewType_t TypeOfView,
unsigned RecordWidth = Rec_WIDTH_SHARE_RECORD_BIG;
char StrRecordWidth[10+1];
unsigned FrameWidth = 10;
- unsigned Col1Width = 140;
+ unsigned Col1Width = 130;
unsigned Col2Width;
unsigned Col3Width = 160;
unsigned Cols1and2Width;
@@ -2379,7 +2377,7 @@ void Rec_ShowSharedUsrRecord (Rec_RecordViewType_t TypeOfView,
/***** User's nickname *****/
fprintf (Gbl.F.Out,"
");
-
- /***** Number of courses in which the user is teacher or student *****/
- if ((NumCrssUsrIsTeacher = Usr_GetNumCrssOfUsrWithARole (UsrDat->UsrCod,Rol_ROLE_TEACHER)))
- {
- NumTchs = Usr_GetNumUsrsInCrssOfAUsr (UsrDat->UsrCod,Rol_ROLE_TEACHER,Rol_ROLE_TEACHER);
- NumStds = Usr_GetNumUsrsInCrssOfAUsr (UsrDat->UsrCod,Rol_ROLE_TEACHER,Rol_ROLE_STUDENT);
- fprintf (Gbl.F.Out,"
");
-
- /***** Number of posts in forums *****/
- fprintf (Gbl.F.Out,"
"
- "
"
- "%s"
- "
"
- "
",
- The_ClassFormul[Gbl.Prefs.Theme],
- Txt_Forums);
- if (UsrFigures.NumForPst >= 0)
- {
- fprintf (Gbl.F.Out,"%ld %s",
- UsrFigures.NumForPst,
- (UsrFigures.NumForPst == 1) ? Txt_post :
- Txt_posts);
- if (UsrFigures.NumDays >= 0)
- {
- fprintf (Gbl.F.Out," ");
- Str_WriteFloatNum ((float) UsrFigures.NumForPst /
- (float) (UsrFigures.NumDays + 1));
- fprintf (Gbl.F.Out," / %s",Txt_day);
- }
- }
- else // Number of forum posts is unknown
- {
- /***** Button to fetch and store number of forum posts *****/
- Act_FormStart (ActCalNumForPst);
- Usr_PutParamOtherUsrCodEncrypted (UsrDat->EncryptedUsrCod);
- Act_LinkFormSubmitAnimated (Txt_Calculate,The_ClassFormul[Gbl.Prefs.Theme],
- "calculate4","calculating4");
- Lay_PutCalculateIcon (Txt_Calculate,Txt_Calculate,
- "calculate4","calculating4");
- Act_FormEnd ();
- }
- fprintf (Gbl.F.Out,"
"
- "
");
-
- /***** Number of messages sent *****/
- fprintf (Gbl.F.Out,"
"
- "
"
- "%s"
- "
"
- "
",
- The_ClassFormul[Gbl.Prefs.Theme],
- Txt_Messages);
- if (UsrFigures.NumMsgSnt >= 0)
- {
- fprintf (Gbl.F.Out,"%ld %s",
- UsrFigures.NumMsgSnt,
- (UsrFigures.NumMsgSnt == 1) ? Txt_message :
- Txt_messages);
- if (UsrFigures.NumDays >= 0)
- {
- fprintf (Gbl.F.Out," ");
- Str_WriteFloatNum ((float) UsrFigures.NumMsgSnt /
- (float) (UsrFigures.NumDays + 1));
- fprintf (Gbl.F.Out," / %s",Txt_day);
- }
- }
- else // Number of clicks is unknown
- {
- /***** Button to fetch and store number of messages sent *****/
- Act_FormStart (ActCalNumMsgSnt);
- Usr_PutParamOtherUsrCodEncrypted (UsrDat->EncryptedUsrCod);
- Act_LinkFormSubmitAnimated (Txt_Calculate,The_ClassFormul[Gbl.Prefs.Theme],
- "calculate5","calculating5");
- Lay_PutCalculateIcon (Txt_Calculate,Txt_Calculate,
- "calculate5","calculating5");
- Act_FormEnd ();
- }
- fprintf (Gbl.F.Out,"
"
- "
");
-
- /***** End of table *****/
- fprintf (Gbl.F.Out,"
");
- }
-
-/*****************************************************************************/
-/********************** Select values on user's figures **********************/
-/*****************************************************************************/
-
-static void Usr_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
- {
- char Query[512];
- MYSQL_RES *mysql_res;
- MYSQL_ROW row;
- unsigned NumRows;
-
- /***** Get user's figures from database *****/
- sprintf (Query,"SELECT DATE_FORMAT(FirstClickTime,'%%Y%%m%%d%%H%%i%%S'),"
- "DATEDIFF(NOW(),FirstClickTime),"
- "NumClicks,NumFileViews,NumForPst,NumMsgSnt"
- " FROM usr_figures WHERE UsrCod='%ld'",
- UsrCod);
- if ((NumRows = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get user's figures")))
- {
- /***** Get user's figures *****/
- row = mysql_fetch_row (mysql_res);
-
- /* Get first click (row[0] holds the start date in YYYYMMDDHHMMSS format) */
- if (!(Dat_GetDateTimeFromYYYYMMDDHHMMSS (&(UsrFigures->FirstClickTime),row[0])))
- Lay_ShowErrorAndExit ("Error when reading first click time.");
-
- /* Get number of days since first click (row[1]) */
- if (UsrFigures->FirstClickTime.Date.Year)
- {
- if (sscanf (row[1],"%d",&UsrFigures->NumDays) != 1)
- UsrFigures->NumDays = -1;
- }
- else
- UsrFigures->NumDays = -1;
-
- /* Get number of clicks (row[2]) */
- if (sscanf (row[2],"%ld",&UsrFigures->NumClicks) != 1)
- UsrFigures->NumClicks = -1L;
-
- /* Get number of file views (row[3]) */
- if (sscanf (row[3],"%ld",&UsrFigures->NumFileViews) != 1)
- UsrFigures->NumFileViews = -1L;
-
- /* Get number of forum posts (row[4]) */
- if (sscanf (row[4],"%ld",&UsrFigures->NumForPst) != 1)
- UsrFigures->NumForPst = -1L;
-
- /* Get number of messages sent (row[5]) */
- if (sscanf (row[5],"%ld",&UsrFigures->NumMsgSnt) != 1)
- UsrFigures->NumMsgSnt = -1L;
- }
- else
- /***** Return special user's figures indicating "not present" *****/
- Usr_ResetUsrFigures (UsrFigures);
-
- /***** Free structure that stores the query result *****/
- DB_FreeMySQLResult (&mysql_res);
- }
-
-/*****************************************************************************/
-/********** Get ranking of a user according to the number of clicks **********/
-/*****************************************************************************/
-
-static unsigned long Usr_GetRankingNumClicks (long UsrCod)
- {
- char Query[128];
-
- /***** Select number of rows with number of clicks
- greater than the clicks of this user *****/
- sprintf (Query,"SELECT COUNT(*)+1 FROM usr_figures"
- " WHERE UsrCod<>'%ld'" // Really not necessary here
- " AND NumClicks>"
- "(SELECT NumClicks FROM usr_figures WHERE UsrCod='%ld')",
- UsrCod,UsrCod);
- return DB_QueryCOUNT (Query,"can not get ranking using number of clicks");
- }
-
-/*****************************************************************************/
-/******************* Get number of users with number of clicks ***************/
-/*****************************************************************************/
-
-static unsigned long Usr_GetNumUsrsWithNumClicks (void)
- {
- char Query[128];
-
- /***** Select number of rows with values already calculated *****/
- sprintf (Query,"SELECT COUNT(*) FROM usr_figures WHERE NumClicks>='0'");
- return DB_QueryCOUNT (Query,"can not get number of users with number of clicks");
- }
-
-/*****************************************************************************/
-/****** Get ranking of a user according to the number of clicks per day ******/
-/*****************************************************************************/
-
-static unsigned long Usr_GetRankingNumClicksPerDay (long UsrCod)
- {
- char Query[512];
-
- /***** Select number of rows with number of clicks per day
- greater than the clicks per day of this user *****/
- sprintf (Query,"SELECT COUNT(*)+1 FROM"
- " (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
- " AS NumClicksPerDay"
- " FROM usr_figures"
- " WHERE UsrCod<>'%ld'" // Necessary because the following comparison is not exact in floating point
- " AND NumClicks>='0' AND UNIX_TIMESTAMP(FirstClickTime)>'0')"
- " AS TableNumClicksPerDay"
- " WHERE NumClicksPerDay>"
- "(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
- " FROM usr_figures"
- " WHERE UsrCod='%ld'"
- " AND NumClicks>='0' AND UNIX_TIMESTAMP(FirstClickTime)>'0')",
- UsrCod,UsrCod);
- return DB_QueryCOUNT (Query,"can not get ranking using number of clicks per day");
- }
-
-/*****************************************************************************/
-/************** Get number of users with number of clicks per day ************/
-/*****************************************************************************/
-
-static unsigned long Usr_GetNumUsrsWithNumClicksPerDay (void)
- {
- char Query[128];
-
- /***** Select number of rows with values already calculated *****/
- sprintf (Query,"SELECT COUNT(*) FROM usr_figures"
- " WHERE NumClicks>='0' AND UNIX_TIMESTAMP(FirstClickTime)>'0'");
- return DB_QueryCOUNT (Query,"can not get number of users with number of clicks per day");
- }
-
-/*****************************************************************************/
-/********* Calculate first click time and show user's profile again **********/
-/*****************************************************************************/
-
-void Usr_CalculateFirstClickTime (void)
- {
- /***** Get user's code *****/
- Usr_GetParamOtherUsrCodEncrypted ();
-
- /***** Get first click time from log and store as user's figure *****/
- Usr_GetFirstClickFromLogAndStoreAsUsrFigure (Gbl.Usrs.Other.UsrDat.UsrCod);
-
- /***** Show user's profile again *****/
- Usr_ShowUserProfile ();
- }
-
-/*****************************************************************************/
-/*** Get first click of a user from log table and store in user's figures ****/
-/*****************************************************************************/
-
-static void Usr_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod)
- {
- char Query[256];
- MYSQL_RES *mysql_res;
- MYSQL_ROW row;
- struct UsrFigures UsrFigures;
-
- if (Usr_ChkIfUsrCodExists (UsrCod))
- {
- /***** Reset user's figures *****/
- Usr_ResetUsrFigures (&UsrFigures);
-
- /***** Get first click from log table *****/
- sprintf (Query,"SELECT DATE_FORMAT("
- "(SELECT MIN(ClickTime) FROM log WHERE UsrCod='%ld')"
- ",'%%Y%%m%%d%%H%%i%%S')",
- UsrCod);
- if (DB_QuerySELECT (Query,&mysql_res,"can not get user's first click"))
- {
- /* Get first click */
- row = mysql_fetch_row (mysql_res);
-
- /* Get first click (row[0] holds the start date in YYYYMMDDHHMMSS format) */
- if (row[0]) // It is NULL when user never logged
- if (!(Dat_GetDateTimeFromYYYYMMDDHHMMSS (&(UsrFigures.FirstClickTime),row[0])))
- Lay_ShowErrorAndExit ("Error when reading first click time.");
- }
- /* Free structure that stores the query result */
- DB_FreeMySQLResult (&mysql_res);
-
- /***** Update first click time in user's figures *****/
- if (Usr_CheckIfUsrFiguresExists (UsrCod))
- {
- sprintf (Query,"UPDATE usr_figures SET FirstClickTime='%s'"
- " WHERE UsrCod='%ld'",
- UsrFigures.FirstClickTime.YYYYMMDDHHMMSS,UsrCod);
- DB_QueryUPDATE (Query,"can not update user's figures");
- }
- else // User entry does not exist
- Usr_CreateUsrFigures (UsrCod,&UsrFigures);
- }
- }
-
-/*****************************************************************************/
-/********* Calculate number of clicks and show user's profile again **********/
-/*****************************************************************************/
-
-void Usr_CalculateNumClicks (void)
- {
- /***** Get user's code *****/
- Usr_GetParamOtherUsrCodEncrypted ();
-
- /***** Get number of clicks and store as user's figure *****/
- Usr_GetNumClicksAndStoreAsUsrFigure (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 */
-/*****************************************************************************/
-
-static void Usr_GetNumClicksAndStoreAsUsrFigure (long UsrCod)
- {
- char Query[256];
- struct UsrFigures UsrFigures;
-
- if (Usr_ChkIfUsrCodExists (UsrCod))
- {
- /***** Reset user's figures *****/
- Usr_ResetUsrFigures (&UsrFigures);
-
- /***** Get number of clicks from database *****/
- sprintf (Query,"SELECT COUNT(*) FROM log WHERE UsrCod='%ld'",
- UsrCod);
- UsrFigures.NumClicks = (long) DB_QueryCOUNT (Query,"can not get number of clicks");
-
- /***** Update number of clicks in user's figures *****/
- if (Usr_CheckIfUsrFiguresExists (UsrCod))
- {
- sprintf (Query,"UPDATE usr_figures SET NumClicks='%ld'"
- " WHERE UsrCod='%ld'",
- UsrFigures.NumClicks,UsrCod);
- DB_QueryUPDATE (Query,"can not update user's figures");
- }
- else // User entry does not exist
- Usr_CreateUsrFigures (UsrCod,&UsrFigures);
- }
- }
-
-/*****************************************************************************/
-/******* Calculate number of file views and show user's profile again *******/
-/*****************************************************************************/
-
-void Usr_CalculateNumFileViews (void)
- {
- /***** Get user's code *****/
- Usr_GetParamOtherUsrCodEncrypted ();
-
- /***** Get number of file views and store as user's figure *****/
- Usr_GetNumFileViewsAndStoreAsUsrFigure (Gbl.Usrs.Other.UsrDat.UsrCod);
-
- /***** Show user's profile again *****/
- Usr_ShowUserProfile ();
- }
-
-/*****************************************************************************/
-/**** Get number of file views sent by a user and store in user's figures ****/
-/*****************************************************************************/
-
-static void Usr_GetNumFileViewsAndStoreAsUsrFigure (long UsrCod)
- {
- char Query[256];
- struct UsrFigures UsrFigures;
-
- if (Usr_ChkIfUsrCodExists (UsrCod))
- {
- /***** Reset user's figures *****/
- Usr_ResetUsrFigures (&UsrFigures);
-
- /***** Get number of file views from database *****/
- UsrFigures.NumFileViews = Brw_GetNumFileViewsUsr (UsrCod);
-
- /***** Update number of file views in user's figures *****/
- if (Usr_CheckIfUsrFiguresExists (UsrCod))
- {
- sprintf (Query,"UPDATE usr_figures SET NumFileViews='%ld'"
- " WHERE UsrCod='%ld'",
- UsrFigures.NumFileViews,UsrCod);
- DB_QueryUPDATE (Query,"can not update user's figures");
- }
- else // User entry does not exist
- Usr_CreateUsrFigures (UsrCod,&UsrFigures);
- }
- }
-
-/*****************************************************************************/
-/******* 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];
- struct UsrFigures UsrFigures;
-
- if (Usr_ChkIfUsrCodExists (UsrCod))
- {
- /***** Reset user's figures *****/
- Usr_ResetUsrFigures (&UsrFigures);
-
- /***** Get number of forum posts from database *****/
- UsrFigures.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'",
- UsrFigures.NumForPst,UsrCod);
- DB_QueryUPDATE (Query,"can not update user's figures");
- }
- else // User entry does not exist
- Usr_CreateUsrFigures (UsrCod,&UsrFigures);
- }
- }
-
-/*****************************************************************************/
-/****** Calculate number of messages sent and show user's profile again ******/
-/*****************************************************************************/
-
-void Usr_CalculateNumMsgSnt (void)
- {
- /***** Get user's code *****/
- Usr_GetParamOtherUsrCodEncrypted ();
-
- /***** 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 messages sent by a user and store in user's figures *****/
-/*****************************************************************************/
-
-static void Usr_GetNumMsgSntAndStoreAsUsrFigure (long UsrCod)
- {
- char Query[256];
- struct UsrFigures UsrFigures;
-
- if (Usr_ChkIfUsrCodExists (UsrCod))
- {
- /***** Reset user's figures *****/
- Usr_ResetUsrFigures (&UsrFigures);
-
- /***** Get number of messages sent from database *****/
- UsrFigures.NumMsgSnt = Msg_GetNumMsgsSentByUsr (UsrCod);
-
- /***** Update number of messages sent in user's figures *****/
- if (Usr_CheckIfUsrFiguresExists (UsrCod))
- {
- sprintf (Query,"UPDATE usr_figures SET NumMsgSnt='%ld'"
- " WHERE UsrCod='%ld'",
- UsrFigures.NumMsgSnt,UsrCod);
- DB_QueryUPDATE (Query,"can not update user's figures");
- }
- else // User entry does not exist
- Usr_CreateUsrFigures (UsrCod,&UsrFigures);
- }
- }
-
-/*****************************************************************************/
-/********************** Reset values of user's figures ***********************/
-/*****************************************************************************/
-
-static void Usr_ResetUsrFigures (struct UsrFigures *UsrFigures)
- {
- Dat_GetDateTimeFromYYYYMMDDHHMMSS (&(UsrFigures->FirstClickTime),"00000000000000"); // unknown first click time or user never logged
- UsrFigures->NumDays = -1; // not applicable
- UsrFigures->NumClicks = -1L; // unknown number of clicks
- UsrFigures->NumFileViews = -1L; // unknown number of file views
- UsrFigures->NumForPst = -1L; // unknown number of forum posts
- UsrFigures->NumMsgSnt = -1L; // unknown number of messages sent
- }
-
-/*****************************************************************************/
-/***** Get number of messages sent by a user and store in user's figures *****/
-/*****************************************************************************/
-
-static void Usr_CreateUsrFigures (long UsrCod,const struct UsrFigures *UsrFigures)
- {
- char Query[256];
-
- /***** Create user's figures *****/
- sprintf (Query,"INSERT INTO usr_figures (UsrCod,FirstClickTime,NumClicks,NumFileViews,NumForPst,NumMsgSnt)"
- " VALUES ('%ld','%s','%ld','%ld','%ld','%ld')",
- UsrCod,
- UsrFigures->FirstClickTime.YYYYMMDDHHMMSS, // 0 ==> unknown first click time or user never logged
- UsrFigures->NumClicks, // -1L ==> unknown number of clicks
- UsrFigures->NumFileViews, // -1L ==> unknown number of file views
- UsrFigures->NumForPst, // -1L ==> unknown number of forum posts
- UsrFigures->NumMsgSnt); // -1L ==> unknown number of messages sent
- DB_QueryINSERT (Query,"can not create user's figures");
- }
-
-/*****************************************************************************/
-/**************************** Remove user's figures **************************/
-/*****************************************************************************/
-
-void Usr_RemoveUsrFigures (long UsrCod)
- {
- char Query[128];
-
- /***** Remove user's figures *****/
- sprintf (Query,"DELETE FROM usr_figures WHERE UsrCod='%ld'",
- UsrCod);
- DB_QueryDELETE (Query,"can not delete user's figures");
- }
-
-/*****************************************************************************/
-/*** Check if it exists an entry for this user in table of user's figures ****/
-/*****************************************************************************/
-
-static bool Usr_CheckIfUsrFiguresExists (long UsrCod)
- {
- char Query[128];
-
- sprintf (Query,"SELECT COUNT(*) FROM usr_figures WHERE UsrCod='%ld'",
- UsrCod);
- return (DB_QueryCOUNT (Query,"can not get user's first click") != 0);
- }
-
-/*****************************************************************************/
-/*************** Increment number of clicks made by a user *******************/
-/*****************************************************************************/
-
-void Usr_IncrementNumClicksUsr (long UsrCod)
- {
- char Query[256];
-
- /***** 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",
- UsrCod);
- DB_QueryINSERT (Query,"can not increment user's clicks");
- }
-
-/*****************************************************************************/
-/************** Increment number of file views sent by a user ****************/
-/*****************************************************************************/
-
-void Usr_IncrementNumFileViewsUsr (long UsrCod)
- {
- char Query[256];
-
- /***** Increment number of file views *****/
- // If NumFileViews < 0 ==> not yet calculated, so do nothing
- sprintf (Query,"UPDATE IGNORE usr_figures SET NumFileViews=NumFileViews+1"
- " WHERE UsrCod='%ld' AND NumFileViews>=0",
- UsrCod);
- DB_QueryINSERT (Query,"can not increment user's file views");
- }
-
-/*****************************************************************************/
-/************* Increment number of forum posts sent by a user ****************/
-/*****************************************************************************/
-
-void Usr_IncrementNumForPstUsr (long UsrCod)
- {
- char Query[256];
-
- /***** 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",
- UsrCod);
- DB_QueryINSERT (Query,"can not increment user's messages sent");
- }
diff --git a/swad_user.h b/swad_user.h
index b13a80e0..5b655b3c 100644
--- a/swad_user.h
+++ b/swad_user.h
@@ -210,6 +210,8 @@ void Usr_RestrictLengthAndWriteName (struct UsrData *UsrDat,unsigned MaxChars);
bool Usr_CheckIfUsrIsAdm (long UsrCod,Sco_Scope_t Scope,long Cod);
bool Usr_CheckIfUsrIsSuperuser (long UsrCod);
+unsigned Usr_GetNumCrssOfUsrWithARole (long UsrCod,Rol_Role_t Role);
+unsigned Usr_GetNumUsrsInCrssOfAUsr (long UsrCod,Rol_Role_t UsrRole,Rol_Role_t OthersRole);
bool Usr_CheckIfUsrSharesAnyOfMyCrs (long UsrCod);
bool Usr_CheckIfUsrSharesAnyOfMyCrsWithDifferentRole (long UsrCod);
void Usr_GetMyInstitutions (void);
@@ -324,18 +326,4 @@ void Usr_ShowWarningNoUsersFound (Rol_Role_t Role);
void Usr_GetAndShowNumUsrsInPlatform (Rol_Role_t Role);
-void Usr_RequestUserProfile (void);
-void Usr_GetUsrCodAndShowUserProfile (void);
-void Usr_ChangeProfileVisibility (void);
-void Usr_CalculateFirstClickTime (void);
-void Usr_CalculateNumClicks (void);
-void Usr_CalculateNumFileViews (void);
-void Usr_CalculateNumForPst (void);
-void Usr_CalculateNumMsgSnt (void);
-void Usr_RemoveUsrFigures (long UsrCod);
-void Usr_IncrementNumClicksUsr (long UsrCod);
-void Usr_IncrementNumFileViewsUsr (long UsrCod);
-void Usr_IncrementNumForPstUsr (long UsrCod);
-void Usr_IncrementNumMsgSntUsr (long UsrCod);
-
#endif