");
/***** Number of courses in which the user is teacher or student *****/
if ((NumCrssUsrIsTeacher = Usr_GetNumCrssOfUsrWithARole (UsrDat->UsrCod,Rol_TEACHER)))
{
NumTchs = Usr_GetNumUsrsInCrssOfAUsr (UsrDat->UsrCod,Rol_TEACHER,Rol_TEACHER);
NumStds = Usr_GetNumUsrsInCrssOfAUsr (UsrDat->UsrCod,Rol_TEACHER,Rol_STUDENT);
fprintf (Gbl.F.Out,""
""
" "
" | "
""
"%u %s (%u %s + %u %s)"
""
" | "
"
",
Gbl.Prefs.IconsURL,
Txt_ROLES_SINGUL_Abc[Rol_TEACHER][UsrDat->Sex],
Txt_ROLES_SINGUL_Abc[Rol_TEACHER][UsrDat->Sex],
NumCrssUsrIsTeacher,
(NumCrssUsrIsTeacher == 1) ? Txt_course :
Txt_courses,
NumTchs,
Txt_teachers_ABBREVIATION,
NumStds,
Txt_students_ABBREVIATION);
}
if ((NumCrssUsrIsStudent = Usr_GetNumCrssOfUsrWithARole (UsrDat->UsrCod,Rol_STUDENT)))
{
NumTchs = Usr_GetNumUsrsInCrssOfAUsr (UsrDat->UsrCod,Rol_STUDENT,Rol_TEACHER);
NumStds = Usr_GetNumUsrsInCrssOfAUsr (UsrDat->UsrCod,Rol_STUDENT,Rol_STUDENT);
fprintf (Gbl.F.Out,""
""
" "
" | "
""
"%u %s (%u %s + %u %s)"
""
" | "
"
",
Gbl.Prefs.IconsURL,
Txt_ROLES_SINGUL_Abc[Rol_STUDENT][UsrDat->Sex],
Txt_ROLES_SINGUL_Abc[Rol_STUDENT][UsrDat->Sex],
NumCrssUsrIsStudent,
(NumCrssUsrIsStudent == 1) ? Txt_course :
Txt_courses,
NumTchs,
Txt_teachers_ABBREVIATION,
NumStds,
Txt_students_ABBREVIATION);
}
/***** Number of files currently published *****/
if ((NumFiles = Brw_GetNumFilesUsr (UsrDat->UsrCod)))
NumPublicFiles = Brw_GetNumPublicFilesUsr (UsrDat->UsrCod);
else
NumPublicFiles = 0;
fprintf (Gbl.F.Out,""
""
" "
" | "
""
"%u %s (%u %s)"
""
" | "
"
",
Gbl.Prefs.IconsURL,
Txt_Files,
Txt_Files,
NumFiles,
(NumFiles == 1) ? Txt_file :
Txt_files,
NumPublicFiles,Txt_public_FILES);
/***** Get figures *****/
Prf_GetUsrFigures (UsrDat->UsrCod,&UsrFigures);
/* First click time */
fprintf (Gbl.F.Out,""
""
" "
" | "
"",
Gbl.Prefs.IconsURL,
Txt_From_TIME,
Txt_From_TIME);
if (UsrFigures.FirstClickTime.Date.Year)
{
Dat_WriteDate (UsrFigures.FirstClickTime.Date.YYYYMMDD);
if (UsrFigures.NumDays > 0)
fprintf (Gbl.F.Out," (%d %s)",
UsrFigures.NumDays,
(UsrFigures.NumDays == 1) ? Txt_day :
Txt_days);
}
else // First click time is unknown or user never logged
{
/***** Button to fetch and store first click time *****/
Act_FormStart (ActCal1stClkTim);
Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
Act_LinkFormSubmitAnimated (Txt_Calculate,The_ClassFormBold[Gbl.Prefs.Theme]);
Lay_PutCalculateIconWithText (Txt_Calculate,Txt_Calculate);
Act_FormEnd ();
}
fprintf (Gbl.F.Out," | "
"
");
UsrIsBannedFromRanking = Usr_CheckIfUsrBanned (UsrDat->UsrCod);
if (!UsrIsBannedFromRanking)
{
/* Number of clicks */
fprintf (Gbl.F.Out,""
""
" "
" | "
"",
Gbl.Prefs.IconsURL,
Txt_Clicks,
Txt_Clicks);
if (UsrFigures.NumClicks >= 0)
{
fprintf (Gbl.F.Out,"%ld %s ",
UsrFigures.NumClicks,Txt_clicks);
Prf_ShowRanking (Prf_GetRankingFigure (UsrDat->UsrCod,"NumClicks"),
Prf_GetNumUsrsWithFigure ("NumClicks"));
if (UsrFigures.NumDays > 0)
{
fprintf (Gbl.F.Out," (");
Str_WriteFloatNum ((float) UsrFigures.NumClicks /
(float) UsrFigures.NumDays);
fprintf (Gbl.F.Out," / %s ",Txt_day);
Prf_ShowRanking (Prf_GetRankingNumClicksPerDay (UsrDat->UsrCod),
Prf_GetNumUsrsWithNumClicksPerDay ());
fprintf (Gbl.F.Out,")");
}
}
else // Number of clicks is unknown
{
/***** Button to fetch and store number of clicks *****/
Act_FormStart (ActCalNumClk);
Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
Act_LinkFormSubmitAnimated (Txt_Calculate,The_ClassFormBold[Gbl.Prefs.Theme]);
Lay_PutCalculateIconWithText (Txt_Calculate,Txt_Calculate);
Act_FormEnd ();
}
fprintf (Gbl.F.Out," | "
"
");
/***** Number of file views *****/
fprintf (Gbl.F.Out,""
""
" "
" | "
"",
Gbl.Prefs.IconsURL,
Txt_Downloads,
Txt_Downloads);
if (UsrFigures.NumFileViews >= 0)
{
fprintf (Gbl.F.Out,"%ld %s ",
UsrFigures.NumFileViews,
(UsrFigures.NumFileViews == 1) ? Txt_download :
Txt_downloads);
Prf_ShowRanking (Prf_GetRankingFigure (UsrDat->UsrCod,"NumFileViews"),
Prf_GetNumUsrsWithFigure ("NumFileViews"));
if (UsrFigures.NumDays > 0)
{
fprintf (Gbl.F.Out," (");
Str_WriteFloatNum ((float) UsrFigures.NumFileViews /
(float) UsrFigures.NumDays);
fprintf (Gbl.F.Out," / %s)",Txt_day);
}
}
else // Number of file views is unknown
{
/***** Button to fetch and store number of file views *****/
Act_FormStart (ActCalNumFilVie);
Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
Act_LinkFormSubmitAnimated (Txt_Calculate,The_ClassFormBold[Gbl.Prefs.Theme]);
Lay_PutCalculateIconWithText (Txt_Calculate,Txt_Calculate);
Act_FormEnd ();
}
fprintf (Gbl.F.Out," | "
"
");
/***** Number of posts in forums *****/
fprintf (Gbl.F.Out,""
""
" "
" | "
"",
Gbl.Prefs.IconsURL,
Txt_Forums,
Txt_Forums);
if (UsrFigures.NumForPst >= 0)
{
fprintf (Gbl.F.Out,"%ld %s ",
UsrFigures.NumForPst,
(UsrFigures.NumForPst == 1) ? Txt_post :
Txt_posts);
Prf_ShowRanking (Prf_GetRankingFigure (UsrDat->UsrCod,"NumForPst"),
Prf_GetNumUsrsWithFigure ("NumForPst"));
if (UsrFigures.NumDays > 0)
{
fprintf (Gbl.F.Out," (");
Str_WriteFloatNum ((float) UsrFigures.NumForPst /
(float) UsrFigures.NumDays);
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_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
Act_LinkFormSubmitAnimated (Txt_Calculate,The_ClassFormBold[Gbl.Prefs.Theme]);
Lay_PutCalculateIconWithText (Txt_Calculate,Txt_Calculate);
Act_FormEnd ();
}
fprintf (Gbl.F.Out," | "
"
");
/***** Number of messages sent *****/
fprintf (Gbl.F.Out,""
""
" "
" | "
"",
Gbl.Prefs.IconsURL,
Txt_Messages,
Txt_Messages);
if (UsrFigures.NumMsgSnt >= 0)
{
fprintf (Gbl.F.Out,"%ld %s ",
UsrFigures.NumMsgSnt,
(UsrFigures.NumMsgSnt == 1) ? Txt_message :
Txt_messages);
Prf_ShowRanking (Prf_GetRankingFigure (UsrDat->UsrCod,"NumMsgSnt"),
Prf_GetNumUsrsWithFigure ("NumMsgSnt"));
if (UsrFigures.NumDays > 0)
{
fprintf (Gbl.F.Out," (");
Str_WriteFloatNum ((float) UsrFigures.NumMsgSnt /
(float) UsrFigures.NumDays);
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_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
Act_LinkFormSubmitAnimated (Txt_Calculate,The_ClassFormBold[Gbl.Prefs.Theme]);
Lay_PutCalculateIconWithText (Txt_Calculate,Txt_Calculate);
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)+1,"
"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_GetRankingFigure (long UsrCod,const char *FieldName)
{
char Query[256];
/***** Select number of rows with figure
greater than the figure of this user *****/
sprintf (Query,"SELECT COUNT(*)+1 FROM usr_figures"
" WHERE UsrCod<>'%ld'" // Really not necessary here
" AND %s>"
"(SELECT %s FROM usr_figures WHERE UsrCod='%ld')",
UsrCod,FieldName,FieldName,UsrCod);
return DB_QueryCOUNT (Query,"can not get ranking using a figure");
}
/*****************************************************************************/
/********************* Get number of users with a figure *********************/
/*****************************************************************************/
static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName)
{
char Query[128];
/***** Select number of rows with values already calculated *****/
sprintf (Query,"SELECT COUNT(*) FROM usr_figures WHERE %s>='0'",
FieldName);
return DB_QueryCOUNT (Query,"can not get number of users with a figure");
}
/*****************************************************************************/
/****** 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");
}
/*****************************************************************************/
/************************* Show position in ranking **************************/
/*****************************************************************************/
static void Prf_ShowRanking (unsigned long Rank,unsigned long NumUsrs)
{
extern const char *The_ClassForm[The_NUM_THEMES];
extern const char *Txt_of_PART_OF_A_TOTAL;
/***** Part of a total and end container *****/
sprintf (Gbl.Title,"#%lu %s %lu",
Rank,Txt_of_PART_OF_A_TOTAL,NumUsrs);
/***** Rank in form to go to ranking *****/
Act_FormStart (ActSeeUseGbl);
Sco_PutParamScope (Sco_SCOPE_SYS);
Par_PutHiddenParamUnsigned ("UseStatType",(unsigned) Sta_USERS_RANKING);
Act_LinkFormSubmit (Gbl.Title,The_ClassForm[Gbl.Prefs.Theme]);
fprintf (Gbl.F.Out,"#%lu",Rank);
Act_FormEnd ();
}
/*****************************************************************************/
/********* 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_GetUsrDatAndShowUserProfile ();
}
/*****************************************************************************/
/*** 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_full 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_GetUsrDatAndShowUserProfile ();
}
/*****************************************************************************/
/* 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_full 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_GetUsrDatAndShowUserProfile ();
}
/*****************************************************************************/
/**** 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_GetUsrDatAndShowUserProfile ();
}
/*****************************************************************************/
/**** 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_GetUsrDatAndShowUserProfile ();
}
/*****************************************************************************/
/***** 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);
}
}
/*****************************************************************************/
/******************* Create user's figures for a new user ********************/
/*****************************************************************************/
void Prf_CreateNewUsrFigures (long UsrCod)
{
struct UsrFigures UsrFigures;
/***** Reset user's figures *****/
Prf_ResetUsrFigures (&UsrFigures);
/***** Create user's figures *****/
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[512];
/***** 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");
}
/*****************************************************************************/
/******** Get and show ranking of users attending to number of clicks ********/
/*****************************************************************************/
void Prf_GetAndShowRankingClicks (void)
{
Prf_GetAndShowRankingFigure ("NumClicks");
}
void Prf_GetAndShowRankingFileViews (void)
{
Prf_GetAndShowRankingFigure ("NumFileViews");
}
void Prf_GetAndShowRankingForPst (void)
{
Prf_GetAndShowRankingFigure ("NumForPst");
}
void Prf_GetAndShowRankingMsgSnt (void)
{
Prf_GetAndShowRankingFigure ("NumMsgSnt");
}
static void Prf_GetAndShowRankingFigure (const char *FieldName)
{
char Query[1024];
/***** Get ranking from database *****/
switch (Gbl.Scope.Current)
{
case Sco_SCOPE_SYS:
sprintf (Query,"SELECT UsrCod,%s"
" FROM usr_figures"
" WHERE %s>='0'"
" AND UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY %s DESC,UsrCod LIMIT 100",
FieldName,
FieldName,FieldName);
break;
case Sco_SCOPE_CTY:
sprintf (Query,"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM institutions,centres,degrees,courses,crs_usr,usr_figures"
" WHERE institutions.CtyCod='%ld'"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.%s>='0'"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
Gbl.CurrentCty.Cty.CtyCod,
FieldName,FieldName);
break;
case Sco_SCOPE_INS:
sprintf (Query,"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM centres,degrees,courses,crs_usr,usr_figures"
" WHERE centres.InsCod='%ld'"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.%s>='0'"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
Gbl.CurrentIns.Ins.InsCod,
FieldName,FieldName);
break;
case Sco_SCOPE_CTR:
sprintf (Query,"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM degrees,courses,crs_usr,usr_figures"
" WHERE degrees.CtrCod='%ld'"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.%s>='0'"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
Gbl.CurrentCtr.Ctr.CtrCod,
FieldName,FieldName);
break;
case Sco_SCOPE_DEG:
sprintf (Query,"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM courses,crs_usr,usr_figures"
" WHERE courses.DegCod='%ld'"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.%s>='0'"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
Gbl.CurrentDeg.Deg.DegCod,
FieldName,FieldName);
break;
case Sco_SCOPE_CRS:
sprintf (Query,"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM crs_usr,usr_figures"
" WHERE crs_usr.CrsCod='%ld'"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.%s>='0'"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
Gbl.CurrentCrs.Crs.CrsCod,
FieldName,FieldName);
break;
default:
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
Prf_ShowRankingFigure (Query);
}
void Prf_ShowRankingFigure (const char *Query)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs;
unsigned NumUsr;
unsigned Rank;
struct UsrData UsrDat;
long FigureHigh = LONG_MAX;
long Figure;
NumUsrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get ranking");
if (NumUsrs)
{
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
fprintf (Gbl.F.Out,"