swad-core/swad_profile.c

1786 lines
64 KiB
C
Raw Normal View History

2015-03-14 17:39:04 +01:00
// swad_profile.c: user's public profile
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
2019-01-07 21:52:19 +01:00
Copyright (C) 1999-2019 Antonio Ca<EFBFBD>as Vargas
2015-03-14 17:39:04 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General 3 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 <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/*********************************** Headers *********************************/
/*****************************************************************************/
#include <linux/stddef.h> // For NULL
2016-11-08 00:58:32 +01:00
#include <string.h> // For string functions
2015-03-14 17:39:04 +01:00
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2015-03-14 17:39:04 +01:00
#include "swad_config.h"
#include "swad_database.h"
2015-03-19 00:28:37 +01:00
#include "swad_follow.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2015-03-14 17:39:04 +01:00
#include "swad_global.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2018-12-08 16:43:13 +01:00
#include "swad_language.h"
2016-01-04 16:45:43 +01:00
#include "swad_network.h"
2015-03-14 17:39:04 +01:00
#include "swad_nickname.h"
2016-01-20 21:18:38 +01:00
#include "swad_notification.h"
2015-03-14 17:39:04 +01:00
#include "swad_parameter.h"
#include "swad_privacy.h"
2015-03-18 02:11:23 +01:00
#include "swad_profile.h"
2015-03-14 17:39:04 +01:00
#include "swad_role.h"
2016-12-13 13:32:19 +01:00
#include "swad_role_type.h"
2019-03-26 11:53:21 +01:00
#include "swad_setting.h"
2015-03-14 17:39:04 +01:00
#include "swad_theme.h"
2019-03-12 21:25:55 +01:00
#include "swad_timeline.h"
2015-03-14 17:39:04 +01:00
#include "swad_user.h"
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/****************************** Internal types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/************************* Internal global variables *************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2019-03-06 23:52:04 +01:00
static void Prf_ShowTimeSinceFirstClick (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures);
2019-03-06 22:07:24 +01:00
static void Prf_ShowNumCrssWithRole (const struct UsrData *UsrDat,
Rol_Role_t Role);
2019-03-06 23:52:04 +01:00
static void Prf_ShowNumFilesCurrentlyPublished (const struct UsrData *UsrDat);
static void Prf_ShowNumClicks (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures);
static void Prf_ShowNumFileViews (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures);
static void Prf_ShowNumSocialPublications (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures);
static void Prf_ShowNumForumPosts (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures);
static void Prf_ShowNumMessagesSent (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures);
static void Prf_StartListItem (const char *Title,const char *Icon);
static void Prf_EndListItem (void);
2019-03-06 10:13:39 +01:00
static void Prf_PutLinkCalculateFigures (const char *EncryptedUsrCod);
2015-03-14 18:41:01 +01:00
2015-03-17 01:03:22 +01:00
static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName);
static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName);
2015-03-14 17:39:04 +01:00
static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod);
static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void);
2015-03-17 00:54:03 +01:00
static void Prf_ShowRanking (unsigned long Rank,unsigned long NumUsrs);
2015-03-14 18:41:01 +01:00
2015-03-14 17:39:04 +01:00
static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod);
static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod);
2019-03-06 10:13:39 +01:00
static void Prf_GetNumSocialPubsAndStoreAsUsrFigure (long UsrCod);
2015-03-14 17:39:04 +01:00
static void Prf_GetNumFileViewsAndStoreAsUsrFigure (long UsrCod);
2019-03-06 10:13:39 +01:00
static void Prf_GetNumForumPostsAndStoreAsUsrFigure (long UsrCod);
static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod);
2015-03-14 18:41:01 +01:00
2015-03-14 17:39:04 +01:00
static void Prf_ResetUsrFigures (struct UsrFigures *UsrFigures);
2016-11-08 00:58:32 +01:00
static void Prf_CreateUsrFigures (long UsrCod,const struct UsrFigures *UsrFigures,
bool CreatingMyOwnAccount);
2015-03-14 17:39:04 +01:00
static bool Prf_CheckIfUsrFiguresExists (long UsrCod);
2015-03-16 17:46:32 +01:00
static void Prf_GetAndShowRankingFigure (const char *FieldName);
2019-03-06 13:14:40 +01:00
static void Prf_ShowUsrInRanking (struct UsrData *UsrDat,unsigned Rank);
2015-03-16 17:46:32 +01:00
2016-02-06 13:45:33 +01:00
/*****************************************************************************/
/************* Suggest who to follow or request user's profile ***************/
/*****************************************************************************/
void Prf_SeeSocialProfiles (void)
{
if (Gbl.Usrs.Me.Logged)
2017-02-16 20:22:13 +01:00
Fol_SuggestUsrsToFollowMainZone ();
2016-02-06 13:45:33 +01:00
else
Prf_RequestUserProfile ();
}
2015-03-14 17:39:04 +01:00
/*****************************************************************************/
/************************** Get public profile URL ***************************/
/*****************************************************************************/
2018-10-18 02:02:32 +02:00
char *Prf_GetURLPublicProfile (char URL[Cns_MAX_BYTES_WWW + 1],
const char *NicknameWithoutArroba)
2015-03-14 17:39:04 +01:00
{
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2015-03-14 17:39:04 +01:00
/***** Build URL using nickname *****/
2018-10-18 02:02:32 +02:00
snprintf (URL,Cns_MAX_BYTES_WWW + 1,
"%s/%s?usr=@%s",
Cfg_URL_SWAD_CGI,
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Gbl.Prefs.Language],
2018-10-18 02:02:32 +02:00
NicknameWithoutArroba);
2015-03-14 17:39:04 +01:00
return URL;
}
2016-01-29 00:41:52 +01:00
/*****************************************************************************/
2017-02-17 01:59:58 +01:00
/******************** Put link to view my public profile *********************/
2016-01-29 00:41:52 +01:00
/*****************************************************************************/
2017-02-17 01:59:58 +01:00
void Prf_PutLinkMyPublicProfile (void)
2016-01-29 00:41:52 +01:00
{
2017-02-17 01:59:58 +01:00
extern const char *Txt_My_public_profile;
2016-01-29 00:41:52 +01:00
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkIconText (ActSeeOthPubPrf,NULL,
Usr_PutParamMyUsrCodEncrypted,
"user.svg",
Txt_My_public_profile);
2017-02-17 01:59:58 +01:00
}
/*****************************************************************************/
/***************** Put link to request another user's profile ****************/
/*****************************************************************************/
void Prf_PutLinkRequestAnotherUserProfile (void)
{
extern const char *Txt_Another_user_s_profile;
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkIconText (ActReqOthPubPrf,NULL,NULL,
"user.svg",
Txt_Another_user_s_profile);
2016-01-29 00:41:52 +01:00
}
2015-03-14 17:39:04 +01:00
/*****************************************************************************/
/************************** Request a user's profile *************************/
/*****************************************************************************/
void Prf_RequestUserProfile (void)
2015-03-14 18:41:01 +01:00
{
2019-03-12 21:25:55 +01:00
extern const char *Hlp_START_Profiles_view_public_profile;
2017-04-03 10:20:09 +02:00
extern const char *Txt_Another_user_s_profile;
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2017-04-03 10:20:09 +02:00
extern const char *Txt_Nickname;
extern const char *Txt_Continue;
2016-01-28 19:58:32 +01:00
if (Gbl.Usrs.Me.Logged)
2017-02-17 01:59:58 +01:00
{
2019-10-24 09:46:20 +02:00
/***** Contextual menu *****/
Mnu_ContextMenuBegin ();
Prf_PutLinkMyPublicProfile (); // My public profile
Fol_PutLinkWhoToFollow (); // Users to follow
Mnu_ContextMenuEnd ();
2017-02-17 01:59:58 +01:00
}
2016-01-27 22:31:36 +01:00
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeOthPubPrf);
2015-04-11 23:46:21 +02:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,Txt_Another_user_s_profile,NULL,
2019-03-12 21:25:55 +01:00
Hlp_START_Profiles_view_public_profile,Box_NOT_CLOSABLE);
2015-03-14 17:39:04 +01:00
/***** Form to request user's @nickname *****/
2017-04-03 10:20:09 +02:00
/* By default, the nickname is filled with my nickname
If no user logged ==> the nickname is empty */
2015-04-12 18:01:06 +02:00
fprintf (Gbl.F.Out,"<label class=\"%s\">"
2016-12-20 02:18:50 +01:00
"%s:&nbsp;"
2015-03-14 17:39:04 +01:00
"<input type=\"text\" name=\"usr\""
2016-12-20 02:18:50 +01:00
" size=\"18\" maxlength=\"%u\" value=\"@%s\" />"
"</label>",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2015-03-14 17:39:04 +01:00
Txt_Nickname,
2017-01-17 03:10:43 +01:00
Nck_MAX_BYTES_NICKNAME_FROM_FORM,
2017-04-03 10:20:09 +02:00
Gbl.Usrs.Me.UsrDat.Nickname);
2015-03-14 17:39:04 +01:00
2017-06-12 14:16:33 +02:00
/***** Send button and end box *****/
2017-06-11 19:02:40 +02:00
Box_EndBoxWithButton (Btn_CONFIRM_BUTTON,Txt_Continue);
2015-03-14 17:39:04 +01:00
2015-04-11 23:46:21 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-14 17:39:04 +01:00
}
2017-02-17 01:59:58 +01:00
/*****************************************************************************/
2017-02-17 06:32:57 +01:00
/******************** Get user and show a user's profile *********************/
2017-02-17 01:59:58 +01:00
/*****************************************************************************/
2017-02-17 06:32:57 +01:00
// Gbl.Usrs.Other.UsrDat.UsrCod may be already taken. If not ==> try to get it
2017-02-17 01:59:58 +01:00
2017-02-17 06:32:57 +01:00
void Prf_GetUsrDatAndShowUserProfile (void)
2017-02-17 01:59:58 +01:00
{
2018-10-10 23:56:42 +02:00
bool ItsMe;
2017-04-03 10:20:09 +02:00
bool ProfileShown = false;
2017-02-17 06:32:57 +01:00
/***** Get user's data *****/
if (Gbl.Usrs.Other.UsrDat.UsrCod <= 0)
Usr_GetParamOtherUsrCodEncryptedAndGetListIDs ();
2017-02-17 01:59:58 +01:00
2017-02-17 06:32:57 +01:00
/***** Show profile and timeline *****/
2019-03-19 13:22:14 +01:00
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS))
2017-02-17 06:32:57 +01:00
/* Show profile */
2017-04-03 10:20:09 +02:00
if (Prf_ShowUserProfile (&Gbl.Usrs.Other.UsrDat))
2017-02-17 06:32:57 +01:00
{
2017-04-03 10:20:09 +02:00
ProfileShown = true;
if (Gbl.Usrs.Me.Logged) // Timeline visible only by logged users
{
/* Show timeline */
2019-10-26 01:56:36 +02:00
HTM_SECTION_Begin (TL_TIMELINE_SECTION_ID);
2019-03-12 21:25:55 +01:00
TL_ShowTimelineUsr ();
2019-10-26 01:56:36 +02:00
HTM_SECTION_End ();
2017-04-03 10:20:09 +02:00
}
2017-02-17 06:32:57 +01:00
}
2017-04-03 10:20:09 +02:00
/***** If profile could not be shown... *****/
if (!ProfileShown)
2015-03-14 17:39:04 +01:00
{
2016-01-14 01:39:02 +01:00
/* Show error message */
2019-03-09 20:12:44 +01:00
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
2015-03-14 17:39:04 +01:00
2017-04-03 10:20:09 +02:00
/* Request a user's profile */
Prf_RequestUserProfile ();
2015-03-14 17:39:04 +01:00
}
2017-04-03 10:20:09 +02:00
/***** If it's not me, mark possible notification as seen *****/
2018-10-10 23:56:42 +02:00
ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
if (!ItsMe) // Not me
2017-04-03 10:20:09 +02:00
Ntf_MarkNotifAsSeen (Ntf_EVENT_FOLLOWER,
Gbl.Usrs.Other.UsrDat.UsrCod,-1L,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
2015-03-14 17:39:04 +01:00
2015-03-18 02:11:23 +01:00
/*****************************************************************************/
/*************************** Show a user's profile ***************************/
/*****************************************************************************/
// Return false on error
2016-06-12 19:55:33 +02:00
bool Prf_ShowUserProfile (struct UsrData *UsrDat)
2015-03-18 02:11:23 +01:00
{
2015-12-29 14:24:37 +01:00
unsigned NumFollowing;
unsigned NumFollowers;
2015-12-29 19:40:38 +01:00
bool UsrFollowsMe;
bool IFollowUsr;
2018-10-10 23:56:42 +02:00
bool ItsMe = Usr_ItsMe (UsrDat->UsrCod);
2015-12-29 14:24:37 +01:00
2017-04-03 10:20:09 +02:00
/***** Check if I can see the public profile *****/
2019-03-22 15:21:46 +01:00
if (Pri_ShowingIsAllowed (UsrDat->BaPrfVisibility,UsrDat))
2016-01-27 23:40:16 +01:00
{
2017-04-03 10:20:09 +02:00
if (Gbl.Usrs.Me.Logged)
{
2019-10-24 09:46:20 +02:00
/***** Contextual menu *****/
Mnu_ContextMenuBegin ();
2018-10-10 23:56:42 +02:00
if (ItsMe)
2019-10-24 09:46:20 +02:00
Prf_PutLinkRequestAnotherUserProfile (); // Request another user's profile
2018-10-10 23:56:42 +02:00
else // Not me
2019-10-24 09:46:20 +02:00
Prf_PutLinkMyPublicProfile (); // My public profile
Fol_PutLinkWhoToFollow (); // Users to follow
Mnu_ContextMenuEnd ();
2017-04-03 10:20:09 +02:00
}
2016-01-27 23:40:16 +01:00
2017-04-03 10:20:09 +02:00
/***** Shared record card *****/
2018-10-10 23:56:42 +02:00
if (!ItsMe && // If not me...
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Level == Hie_CRS) // ...and a course is selected
2015-03-18 02:11:23 +01:00
{
/* Get user's role in current course */
2017-06-20 14:43:26 +02:00
UsrDat->Roles.InCurrentCrs.Role = Rol_GetRoleUsrInCrs (UsrDat->UsrCod,
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2017-06-23 15:12:49 +02:00
UsrDat->Roles.InCurrentCrs.Valid = true;
2015-03-18 02:11:23 +01:00
2017-03-30 11:20:06 +02:00
/* Get if user has accepted enrolment in current course */
2017-06-09 15:04:02 +02:00
UsrDat->Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (UsrDat);
2015-03-18 02:11:23 +01:00
}
2017-05-09 20:56:02 +02:00
Rec_ShowSharedUsrRecord (Rec_SHA_RECORD_PUBLIC,UsrDat,NULL);
2015-03-18 02:11:23 +01:00
2019-03-22 15:21:46 +01:00
/***** Extended profile *****/
if (Pri_ShowingIsAllowed (UsrDat->ExPrfVisibility,UsrDat))
{
/***** Show details of user's profile *****/
Prf_ShowDetailsUserProfile (UsrDat);
/***** Count following and followers *****/
Fol_GetNumFollow (UsrDat->UsrCod,&NumFollowing,&NumFollowers);
UsrFollowsMe = false;
if (NumFollowing)
UsrFollowsMe = Fol_CheckUsrIsFollowerOf (UsrDat->UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
IFollowUsr = false;
if (NumFollowers)
IFollowUsr = Fol_CheckUsrIsFollowerOf (Gbl.Usrs.Me.UsrDat.UsrCod,
UsrDat->UsrCod);
/***** Show following and followers *****/
Fol_ShowFollowingAndFollowers (UsrDat,
NumFollowing,NumFollowers,
UsrFollowsMe,IFollowUsr);
}
2015-12-29 14:24:37 +01:00
2015-03-18 02:11:23 +01:00
return true;
}
return false;
}
2015-03-14 17:39:04 +01:00
/*****************************************************************************/
/******************** Change my public profile visibility ********************/
/*****************************************************************************/
2019-03-22 15:21:46 +01:00
void Prf_ChangeBasicProfileVis (void)
{
extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY];
/***** Get param with public/private photo *****/
2019-03-23 13:10:31 +01:00
Gbl.Usrs.Me.UsrDat.BaPrfVisibility = Pri_GetParamVisibility ("VisBasPrf",
Pri_BASIC_PROFILE_ALLOWED_VIS);
2019-03-22 15:21:46 +01:00
/***** Store public/private photo in database *****/
2019-03-26 11:53:21 +01:00
DB_QueryUPDATE ("can not update your setting"
2019-03-22 15:21:46 +01:00
" about public profile visibility",
"UPDATE usr_data SET BaPrfVisibility='%s'"
" WHERE UsrCod=%ld",
Pri_VisibilityDB[Gbl.Usrs.Me.UsrDat.BaPrfVisibility],
Gbl.Usrs.Me.UsrDat.UsrCod);
/***** Show form again *****/
2019-03-26 11:53:21 +01:00
Set_EditSettings ();
2019-03-22 15:21:46 +01:00
}
void Prf_ChangeExtendedProfileVis (void)
2015-03-14 17:39:04 +01:00
{
extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY];
/***** Get param with public/private photo *****/
2019-03-23 13:10:31 +01:00
Gbl.Usrs.Me.UsrDat.ExPrfVisibility = Pri_GetParamVisibility ("VisExtPrf",
Pri_EXTENDED_PROFILE_ALLOWED_VIS);
2015-03-14 17:39:04 +01:00
/***** Store public/private photo in database *****/
2019-03-26 11:53:21 +01:00
DB_QueryUPDATE ("can not update your setting"
2018-11-03 12:16:40 +01:00
" about public profile visibility",
2019-03-22 15:21:46 +01:00
"UPDATE usr_data SET ExPrfVisibility='%s'"
2018-11-03 12:16:40 +01:00
" WHERE UsrCod=%ld",
2019-03-22 15:21:46 +01:00
Pri_VisibilityDB[Gbl.Usrs.Me.UsrDat.ExPrfVisibility],
2018-11-03 12:16:40 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod);
2015-03-14 17:39:04 +01:00
/***** Show form again *****/
2019-03-26 11:53:21 +01:00
Set_EditSettings ();
2015-03-14 17:39:04 +01:00
}
/*****************************************************************************/
/********************** Show details of user's profile ***********************/
/*****************************************************************************/
2016-06-17 11:13:11 +02:00
void Prf_ShowDetailsUserProfile (const struct UsrData *UsrDat)
2015-03-14 17:39:04 +01:00
{
2015-03-29 01:06:00 +01:00
bool UsrIsBannedFromRanking;
2015-03-18 21:53:56 +01:00
struct UsrFigures UsrFigures;
2019-03-06 22:07:24 +01:00
Rol_Role_t Role;
2015-03-14 17:39:04 +01:00
2019-03-06 13:36:16 +01:00
/***** Get figures *****/
Prf_GetUsrFigures (UsrDat->UsrCod,&UsrFigures);
2019-03-06 23:52:04 +01:00
/***** Left list *****/
/* Start left list */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"PRF_FIG_LEFT_CONTAINER\"");
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("class=\"PRF_FIG_UL DAT_NOBR_N\"");
2015-09-28 18:28:29 +02:00
2019-03-06 23:52:04 +01:00
/* Time since first click */
Prf_ShowTimeSinceFirstClick (UsrDat,&UsrFigures);
2019-03-06 13:36:16 +01:00
2019-03-06 23:52:04 +01:00
/* Number of courses in which the user has a role */
2019-03-06 22:07:24 +01:00
for (Role = Rol_TCH;
Role >= Rol_STD;
Role--)
Prf_ShowNumCrssWithRole (UsrDat,Role);
2015-03-14 17:39:04 +01:00
2019-03-06 23:52:04 +01:00
/* Number of files currently published */
Prf_ShowNumFilesCurrentlyPublished (UsrDat);
2015-03-14 17:39:04 +01:00
2019-03-06 23:52:04 +01:00
/* End left list */
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2015-12-12 19:47:10 +01:00
2019-03-06 23:52:04 +01:00
/***** Right list *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"PRF_FIG_RIGHT_CONTAINER\"");
2015-12-12 19:47:10 +01:00
2015-03-29 01:06:00 +01:00
UsrIsBannedFromRanking = Usr_CheckIfUsrBanned (UsrDat->UsrCod);
if (!UsrIsBannedFromRanking)
2015-03-14 17:39:04 +01:00
{
2019-03-06 23:52:04 +01:00
/* Start right list */
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("class=\"PRF_FIG_UL DAT_NOBR_N\"");
2019-03-06 23:52:04 +01:00
2015-03-29 01:06:00 +01:00
/* Number of clicks */
2019-03-06 23:52:04 +01:00
Prf_ShowNumClicks (UsrDat,&UsrFigures);
2015-03-29 01:06:00 +01:00
2019-03-06 23:52:04 +01:00
/* Number of file views */
Prf_ShowNumFileViews (UsrDat,&UsrFigures);
/* Number of social publications */
Prf_ShowNumSocialPublications (UsrDat,&UsrFigures);
/* Number of posts in forums */
Prf_ShowNumForumPosts (UsrDat,&UsrFigures);
/* Number of messages sent */
Prf_ShowNumMessagesSent (UsrDat,&UsrFigures);
/* End right list */
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2015-03-14 17:39:04 +01:00
}
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2015-03-14 17:39:04 +01:00
}
2019-03-06 22:07:24 +01:00
/*****************************************************************************/
/************** Show time since first click in user's profile ****************/
/*****************************************************************************/
2019-03-06 23:52:04 +01:00
static void Prf_ShowTimeSinceFirstClick (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures)
2019-03-06 22:07:24 +01:00
{
extern const char *Txt_TIME_Since;
2019-03-07 00:42:52 +01:00
extern const char *Txt_year;
extern const char *Txt_years;
extern const char *Txt_month;
extern const char *Txt_months;
2019-03-06 22:07:24 +01:00
extern const char *Txt_day;
extern const char *Txt_days;
extern const char *Txt_Today;
char IdFirstClickTime[Frm_MAX_BYTES_ID + 1];
2019-03-07 00:42:52 +01:00
int NumYears;
int NumMonths;
2019-03-06 22:07:24 +01:00
2019-03-06 23:52:04 +01:00
/***** Time since first click *****/
Prf_StartListItem (Txt_TIME_Since,"clock.svg");
2019-03-06 22:07:24 +01:00
if (UsrFigures->FirstClickTimeUTC)
{
/* Create unique id */
Frm_SetUniqueId (IdFirstClickTime);
fprintf (Gbl.F.Out,"<span id=\"%s\"></span>",IdFirstClickTime);
if (UsrFigures->NumDays > 0)
2019-03-07 00:42:52 +01:00
{
fprintf (Gbl.F.Out,"&nbsp;(");
NumYears = UsrFigures->NumDays / 365;
if (NumYears)
fprintf (Gbl.F.Out,"%d&nbsp;%s",
NumYears,
(NumYears == 1) ? Txt_year :
Txt_years);
else // Less than one year
{
NumMonths = UsrFigures->NumDays / 30;
if (NumMonths)
fprintf (Gbl.F.Out,"%d&nbsp;%s",
NumMonths,
(NumMonths == 1) ? Txt_month :
Txt_months);
else // Less than one month
fprintf (Gbl.F.Out,"%d&nbsp;%s",
UsrFigures->NumDays,
(UsrFigures->NumDays == 1) ? Txt_day :
Txt_days);
}
fprintf (Gbl.F.Out,")");
}
2019-03-06 22:07:24 +01:00
fprintf (Gbl.F.Out,"<script type=\"text/javascript\">"
"writeLocalDateHMSFromUTC('%s',%ld,"
"%u,',&nbsp;','%s',true,false,0x6);"
"</script>",
IdFirstClickTime,(long) UsrFigures->FirstClickTimeUTC,
(unsigned) Gbl.Prefs.DateFormat,Txt_Today);
}
else // First click time is unknown or user never logged
/***** Button to fetch and store user's figures *****/
Prf_PutLinkCalculateFigures (UsrDat->EncryptedUsrCod);
2019-03-06 23:52:04 +01:00
Prf_EndListItem ();
2019-03-06 22:07:24 +01:00
}
/*****************************************************************************/
2019-03-06 23:52:04 +01:00
/*** Show number of courses in which the user has a role in user's profile ***/
2019-03-06 22:07:24 +01:00
/*****************************************************************************/
static void Prf_ShowNumCrssWithRole (const struct UsrData *UsrDat,
Rol_Role_t Role)
{
extern const char *Rol_Icons[Rol_NUM_ROLES];
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
extern const char *Txt_courses_ABBREVIATION;
extern const char *Txt_teachers_ABBREVIATION;
extern const char *Txt_students_ABBREVIATION;
unsigned NumCrss;
/***** Number of courses in which the user has a given role *****/
NumCrss = Usr_GetNumCrssOfUsrWithARole (UsrDat->UsrCod,Role);
2019-03-06 23:52:04 +01:00
Prf_StartListItem (Txt_ROLES_SINGUL_Abc[Role][UsrDat->Sex],Rol_Icons[Role]);
fprintf (Gbl.F.Out,"%u&nbsp;%s",
NumCrss,Txt_courses_ABBREVIATION);
2019-03-06 22:07:24 +01:00
if (NumCrss)
fprintf (Gbl.F.Out,"&nbsp;(%u&nbsp;%s/%u&nbsp;%s)",
Usr_GetNumUsrsInCrssOfAUsr (UsrDat->UsrCod,Role,
(1 << Rol_NET) |
(1 << Rol_TCH)),
Txt_teachers_ABBREVIATION,
Usr_GetNumUsrsInCrssOfAUsr (UsrDat->UsrCod,Role,
(1 << Rol_STD)),
Txt_students_ABBREVIATION);
2019-03-06 23:52:04 +01:00
Prf_EndListItem ();
}
/*****************************************************************************/
/******** Show number of files currently published in user's profile *********/
/*****************************************************************************/
static void Prf_ShowNumFilesCurrentlyPublished (const struct UsrData *UsrDat)
{
extern const char *Txt_Files_uploaded;
extern const char *Txt_file;
extern const char *Txt_files;
extern const char *Txt_public_FILES;
unsigned NumFiles;
unsigned NumPublicFiles;
/***** Number of files currently published *****/
if ((NumFiles = Brw_GetNumFilesUsr (UsrDat->UsrCod)))
NumPublicFiles = Brw_GetNumPublicFilesUsr (UsrDat->UsrCod);
else
NumPublicFiles = 0;
Prf_StartListItem (Txt_Files_uploaded,"file.svg");
fprintf (Gbl.F.Out,"%u&nbsp;%s&nbsp;(%u&nbsp;%s)",
NumFiles,(NumFiles == 1) ? Txt_file :
Txt_files,
NumPublicFiles,Txt_public_FILES);
Prf_EndListItem ();
}
/*****************************************************************************/
/****************** Show number of clicks in user's profile ******************/
/*****************************************************************************/
static void Prf_ShowNumClicks (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures)
{
extern const char *Txt_Clicks;
extern const char *Txt_clicks;
extern const char *Txt_day;
/***** Number of clicks *****/
Prf_StartListItem (Txt_Clicks,"mouse-pointer.svg");
if (UsrFigures->NumClicks >= 0)
{
fprintf (Gbl.F.Out,"%ld&nbsp;%s&nbsp;",
UsrFigures->NumClicks,Txt_clicks);
Prf_ShowRanking (Prf_GetRankingFigure (UsrDat->UsrCod,"NumClicks"),
Prf_GetNumUsrsWithFigure ("NumClicks"));
if (UsrFigures->NumDays > 0)
{
fprintf (Gbl.F.Out,"&nbsp;(");
2019-10-10 21:21:24 +02:00
Str_WriteFloatNumToFile (Gbl.F.Out,
2019-03-06 23:52:04 +01:00
(float) UsrFigures->NumClicks /
(float) UsrFigures->NumDays);
fprintf (Gbl.F.Out,"/%s&nbsp;",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 user's figures *****/
Prf_PutLinkCalculateFigures (UsrDat->EncryptedUsrCod);
Prf_EndListItem ();
}
/*****************************************************************************/
/*************** Show number of file views in user's profile *****************/
/*****************************************************************************/
static void Prf_ShowNumFileViews (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures)
{
extern const char *Txt_Downloads;
extern const char *Txt_download;
extern const char *Txt_downloads;
extern const char *Txt_day;
/***** Number of file views *****/
Prf_StartListItem (Txt_Downloads,"download.svg");
if (UsrFigures->NumFileViews >= 0)
{
fprintf (Gbl.F.Out,"%ld&nbsp;%s&nbsp;",
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,"&nbsp;(");
2019-10-10 21:21:24 +02:00
Str_WriteFloatNumToFile (Gbl.F.Out,
2019-03-06 23:52:04 +01:00
(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 user's figures *****/
Prf_PutLinkCalculateFigures (UsrDat->EncryptedUsrCod);
Prf_EndListItem ();
}
/*****************************************************************************/
/*********** Show number of social publications in user's profile ************/
/*****************************************************************************/
static void Prf_ShowNumSocialPublications (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures)
{
extern const char *Txt_Timeline;
2019-03-12 21:25:55 +01:00
extern const char *Txt_TIMELINE_post;
extern const char *Txt_TIMELINE_posts;
2019-03-06 23:52:04 +01:00
extern const char *Txt_day;
/***** Number of social publications *****/
Prf_StartListItem (Txt_Timeline,"comment-dots.svg");
if (UsrFigures->NumSocPub >= 0)
{
fprintf (Gbl.F.Out,"%ld&nbsp;%s&nbsp;",
UsrFigures->NumSocPub,
2019-03-12 21:25:55 +01:00
(UsrFigures->NumSocPub == 1) ? Txt_TIMELINE_post :
Txt_TIMELINE_posts);
2019-03-06 23:52:04 +01:00
Prf_ShowRanking (Prf_GetRankingFigure (UsrDat->UsrCod,"NumSocPub"),
Prf_GetNumUsrsWithFigure ("NumSocPub"));
if (UsrFigures->NumDays > 0)
{
fprintf (Gbl.F.Out,"&nbsp;(");
2019-10-10 21:21:24 +02:00
Str_WriteFloatNumToFile (Gbl.F.Out,
2019-03-06 23:52:04 +01:00
(float) UsrFigures->NumSocPub /
(float) UsrFigures->NumDays);
fprintf (Gbl.F.Out,"/%s)",Txt_day);
}
}
else // Number of social publications is unknown
/***** Button to fetch and store user's figures *****/
Prf_PutLinkCalculateFigures (UsrDat->EncryptedUsrCod);
Prf_EndListItem ();
}
/*****************************************************************************/
/*********** Show number of social publications in user's profile ************/
/*****************************************************************************/
static void Prf_ShowNumForumPosts (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures)
{
extern const char *Txt_Forums;
extern const char *Txt_FORUM_post;
extern const char *Txt_FORUM_posts;
extern const char *Txt_day;
/***** Number of posts in forums *****/
Prf_StartListItem (Txt_Forums,"comments.svg");
if (UsrFigures->NumForPst >= 0)
{
fprintf (Gbl.F.Out,"%ld&nbsp;%s&nbsp;",
UsrFigures->NumForPst,
(UsrFigures->NumForPst == 1) ? Txt_FORUM_post :
Txt_FORUM_posts);
Prf_ShowRanking (Prf_GetRankingFigure (UsrDat->UsrCod,"NumForPst"),
Prf_GetNumUsrsWithFigure ("NumForPst"));
if (UsrFigures->NumDays > 0)
{
fprintf (Gbl.F.Out,"&nbsp;(");
2019-10-10 21:21:24 +02:00
Str_WriteFloatNumToFile (Gbl.F.Out,
2019-03-06 23:52:04 +01:00
(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 user's figures *****/
Prf_PutLinkCalculateFigures (UsrDat->EncryptedUsrCod);
Prf_EndListItem ();
}
/*****************************************************************************/
/************** Show number of messages sent in user's profile ***************/
/*****************************************************************************/
static void Prf_ShowNumMessagesSent (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures)
{
extern const char *Txt_Messages;
extern const char *Txt_message;
extern const char *Txt_messages;
extern const char *Txt_day;
/***** Number of messages sent *****/
Prf_StartListItem (Txt_Messages,"envelope.svg");
if (UsrFigures->NumMsgSnt >= 0)
{
fprintf (Gbl.F.Out,"%ld&nbsp;%s&nbsp;",
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,"&nbsp;(");
2019-10-10 21:21:24 +02:00
Str_WriteFloatNumToFile (Gbl.F.Out,
2019-03-06 23:52:04 +01:00
(float) UsrFigures->NumMsgSnt /
(float) UsrFigures->NumDays);
fprintf (Gbl.F.Out,"/%s)",Txt_day);
}
}
else // Number of messages sent is unknown
/***** Button to fetch and store user's figures *****/
Prf_PutLinkCalculateFigures (UsrDat->EncryptedUsrCod);
Prf_EndListItem ();
}
/*****************************************************************************/
/****************** Start/end list item in user's profile ********************/
/*****************************************************************************/
static void Prf_StartListItem (const char *Title,const char *Icon)
{
fprintf (Gbl.F.Out,"<li title=\"%s\" class=\"PRF_FIG_LI\""
" style=\"background-image:url('%s/%s');\">",
Title,
2019-03-20 01:36:36 +01:00
Cfg_URL_ICON_PUBLIC,Icon);
2019-03-06 23:52:04 +01:00
}
static void Prf_EndListItem (void)
{
2019-03-06 22:07:24 +01:00
fprintf (Gbl.F.Out,"</li>");
}
2015-12-30 18:43:58 +01:00
/*****************************************************************************/
/******** Put contextual link with animated icon to update an action *********/
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
static void Prf_PutLinkCalculateFigures (const char *EncryptedUsrCod)
2015-12-30 18:43:58 +01:00
{
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormOutBoxBold[The_NUM_THEMES];
2015-12-30 18:43:58 +01:00
extern const char *Txt_Calculate;
2019-03-06 10:13:39 +01:00
Frm_StartForm (ActCalFig);
2015-12-30 18:43:58 +01:00
Usr_PutParamUsrCodEncrypted (EncryptedUsrCod);
2019-02-22 21:47:50 +01:00
Frm_LinkFormSubmitAnimated (Txt_Calculate,
The_ClassFormOutBoxBold[Gbl.Prefs.Theme],
NULL);
2019-01-12 19:46:33 +01:00
Ico_PutCalculateIconWithText (Txt_Calculate);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-12-30 18:43:58 +01:00
}
2015-03-14 17:39:04 +01:00
/*****************************************************************************/
/********************** Select values on user's figures **********************/
/*****************************************************************************/
2016-09-11 14:28:32 +02:00
void Prf_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
2015-03-14 17:39:04 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumRows;
/***** Get user's figures from database *****/
2018-11-01 19:23:52 +01:00
NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's figures",
2019-03-06 10:13:39 +01:00
"SELECT UNIX_TIMESTAMP(FirstClickTime)," // row[0]
"DATEDIFF(NOW(),FirstClickTime)+1," // row[1]
"NumClicks," // row[2]
"NumSocPub," // row[3]
"NumFileViews," // row[4]
"NumForPst," // row[5]
"NumMsgSnt" // row[6]
2018-11-01 19:23:52 +01:00
" FROM usr_figures WHERE UsrCod=%ld",
UsrCod);
if (NumRows)
2015-03-14 17:39:04 +01:00
{
/***** Get user's figures *****/
row = mysql_fetch_row (mysql_res);
2015-10-26 14:35:50 +01:00
/* Get first click (row[0] holds first click time UTC) */
UsrFigures->FirstClickTimeUTC = Dat_GetUNIXTimeFromStr (row[0]);
2015-03-14 17:39:04 +01:00
/* Get number of days since first click (row[1]) */
2015-10-26 14:35:50 +01:00
if (UsrFigures->FirstClickTimeUTC)
2015-03-14 17:39:04 +01:00
{
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;
2019-03-06 10:13:39 +01:00
/* Get number of social publications (row[3]) */
if (sscanf (row[3],"%ld",&UsrFigures->NumSocPub) != 1)
UsrFigures->NumSocPub = -1L;
/* Get number of file views (row[4]) */
if (sscanf (row[4],"%ld",&UsrFigures->NumFileViews) != 1)
2015-03-14 17:39:04 +01:00
UsrFigures->NumFileViews = -1L;
2019-03-06 10:13:39 +01:00
/* Get number of forum posts (row[5]) */
if (sscanf (row[5],"%ld",&UsrFigures->NumForPst) != 1)
2015-03-14 17:39:04 +01:00
UsrFigures->NumForPst = -1L;
2019-03-06 10:13:39 +01:00
/* Get number of messages sent (row[6]) */
if (sscanf (row[6],"%ld",&UsrFigures->NumMsgSnt) != 1)
2015-03-14 17:39:04 +01:00
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 **********/
/*****************************************************************************/
2015-03-17 01:03:22 +01:00
static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName)
2015-03-14 17:39:04 +01:00
{
2015-03-17 01:03:22 +01:00
/***** Select number of rows with figure
greater than the figure of this user *****/
2018-11-03 20:52:00 +01:00
return DB_QueryCOUNT ("can not get ranking using a figure",
"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);
2015-03-14 17:39:04 +01:00
}
/*****************************************************************************/
2015-03-17 01:03:22 +01:00
/********************* Get number of users with a figure *********************/
2015-03-14 17:39:04 +01:00
/*****************************************************************************/
2015-03-17 01:03:22 +01:00
static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName)
2015-03-14 17:39:04 +01:00
{
/***** Select number of rows with values already calculated *****/
2018-11-03 20:52:00 +01:00
return DB_QueryCOUNT ("can not get number of users with a figure",
2018-11-04 20:51:38 +01:00
"SELECT COUNT(*) FROM usr_figures"
" WHERE %s>=0",
2018-11-03 20:52:00 +01:00
FieldName);
2015-03-14 17:39:04 +01:00
}
/*****************************************************************************/
/****** Get ranking of a user according to the number of clicks per day ******/
/*****************************************************************************/
static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
{
/***** Select number of rows with number of clicks per day
greater than the clicks per day of this user *****/
2018-11-03 20:52:00 +01:00
return DB_QueryCOUNT ("can not get ranking using number of clicks per day",
"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 FirstClickTime>FROM_UNIXTIME(0))"
" AS TableNumClicksPerDay"
" WHERE NumClicksPerDay>"
"(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
" FROM usr_figures"
" WHERE UsrCod=%ld"
" AND NumClicks>0"
" AND FirstClickTime>FROM_UNIXTIME(0))",
UsrCod,UsrCod);
2015-03-14 17:39:04 +01:00
}
/*****************************************************************************/
/************** Get number of users with number of clicks per day ************/
/*****************************************************************************/
static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void)
{
/***** Select number of rows with values already calculated *****/
2018-11-03 20:52:00 +01:00
return DB_QueryCOUNT ("can not get number of users"
" with number of clicks per day",
"SELECT COUNT(*) FROM usr_figures"
" WHERE NumClicks>0"
" AND FirstClickTime>FROM_UNIXTIME(0)");
2015-03-14 17:39:04 +01:00
}
2015-03-17 00:54:03 +01:00
/*****************************************************************************/
/************************* Show position in ranking **************************/
/*****************************************************************************/
static void Prf_ShowRanking (unsigned long Rank,unsigned long NumUsrs)
{
2019-02-23 13:00:25 +01:00
extern const char *The_ClassFormOutBox[The_NUM_THEMES];
2015-03-17 00:54:03 +01:00
extern const char *Txt_of_PART_OF_A_TOTAL;
2015-03-18 20:34:00 +01:00
/***** Part of a total and end container *****/
2018-10-18 02:02:32 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
"#%lu %s %lu",
Rank,Txt_of_PART_OF_A_TOTAL,NumUsrs);
2015-03-17 00:54:03 +01:00
/***** Rank in form to go to ranking *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeUseGbl);
2019-04-03 20:57:04 +02:00
Sco_PutParamScope ("ScopeSta",Hie_SYS);
2019-02-12 14:46:14 +01:00
Par_PutHiddenParamUnsigned ("FigureType",(unsigned) Fig_USERS_RANKING);
2019-02-23 13:00:25 +01:00
Frm_LinkFormSubmit (Gbl.Title,The_ClassFormOutBox[Gbl.Prefs.Theme],NULL);
2015-03-17 02:01:30 +01:00
fprintf (Gbl.F.Out,"#%lu</a>",Rank);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-17 00:54:03 +01:00
}
2015-03-14 17:39:04 +01:00
/*****************************************************************************/
2016-10-03 18:16:05 +02:00
/********** Calculate user's figures and show user's profile again ***********/
2015-03-14 17:39:04 +01:00
/*****************************************************************************/
2016-10-03 18:16:05 +02:00
void Prf_CalculateFigures (void)
2015-03-14 17:39:04 +01:00
{
2016-10-03 18:16:05 +02:00
struct UsrFigures UsrFigures;
2015-03-14 17:39:04 +01:00
/***** Get user's code *****/
2016-01-25 14:40:57 +01:00
Usr_GetParamOtherUsrCodEncryptedAndGetListIDs ();
2015-03-14 17:39:04 +01:00
/***** Get first click time from log and store as user's figure *****/
2016-10-03 18:16:05 +02:00
Prf_GetUsrFigures (Gbl.Usrs.Other.UsrDat.UsrCod,&UsrFigures);
Prf_GetAndStoreAllUsrFigures (Gbl.Usrs.Other.UsrDat.UsrCod,&UsrFigures);
2015-03-14 17:39:04 +01:00
/***** Show user's profile again *****/
2015-03-18 02:11:23 +01:00
Prf_GetUsrDatAndShowUserProfile ();
2015-03-14 17:39:04 +01:00
}
2016-10-03 18:16:05 +02:00
/*****************************************************************************/
/*** Calculate and store all figures in user's profile not yet calculated ****/
/*****************************************************************************/
// Return true if any figure has been calculated and stored
bool Prf_GetAndStoreAllUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
{
bool UsrFiguresModified = false;
if (!UsrFigures->FirstClickTimeUTC)
{
/***** Get first click time from log and store as user's figure *****/
Prf_GetFirstClickFromLogAndStoreAsUsrFigure (UsrCod);
UsrFiguresModified = true;
}
if (UsrFigures->NumClicks < 0)
{
/***** Get number of clicks and store as user's figure *****/
Prf_GetNumClicksAndStoreAsUsrFigure (UsrCod);
UsrFiguresModified = true;
}
2019-03-06 10:13:39 +01:00
if (UsrFigures->NumSocPub < 0)
{
/***** Get number of social publications and store as user's figure *****/
Prf_GetNumSocialPubsAndStoreAsUsrFigure (UsrCod);
UsrFiguresModified = true;
}
2016-10-03 18:16:05 +02:00
if (UsrFigures->NumFileViews < 0)
{
/***** Get number of file views and store as user's figure *****/
Prf_GetNumFileViewsAndStoreAsUsrFigure (UsrCod);
UsrFiguresModified = true;
}
if (UsrFigures->NumForPst < 0)
{
/***** Get number of forum posts and store as user's figure *****/
2019-03-06 10:13:39 +01:00
Prf_GetNumForumPostsAndStoreAsUsrFigure (UsrCod);
2016-10-03 18:16:05 +02:00
UsrFiguresModified = true;
}
if (UsrFigures->NumMsgSnt < 0)
{
/***** Get number of messages sent and store as user's figure *****/
2019-03-06 10:13:39 +01:00
Prf_GetNumMessagesSentAndStoreAsUsrFigure (UsrCod);
2016-10-03 18:16:05 +02:00
UsrFiguresModified = true;
}
return UsrFiguresModified;
}
2015-03-14 17:39:04 +01:00
/*****************************************************************************/
/*** Get first click of a user from log table and store in user's figures ****/
/*****************************************************************************/
static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod)
{
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 *****/
2018-11-01 19:23:52 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get user's first click",
"SELECT UNIX_TIMESTAMP("
"(SELECT MIN(ClickTime) FROM log_full"
" WHERE UsrCod=%ld)"
")",
UsrCod))
2015-03-14 17:39:04 +01:00
{
/* Get first click */
row = mysql_fetch_row (mysql_res);
2015-10-26 14:35:50 +01:00
/* Get first click (row[0] holds the start date-time UTC) */
2015-03-14 17:39:04 +01:00
if (row[0]) // It is NULL when user never logged
2015-10-26 14:35:50 +01:00
UsrFigures.FirstClickTimeUTC = Dat_GetUNIXTimeFromStr (row[0]);
2015-03-14 17:39:04 +01:00
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
/***** Update first click time in user's figures *****/
if (Prf_CheckIfUsrFiguresExists (UsrCod))
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update user's figures",
"UPDATE usr_figures"
" SET FirstClickTime=FROM_UNIXTIME(%ld)"
" WHERE UsrCod=%ld",
(long) UsrFigures.FirstClickTimeUTC,UsrCod);
2015-03-14 17:39:04 +01:00
else // User entry does not exist
2016-11-08 00:58:32 +01:00
Prf_CreateUsrFigures (UsrCod,&UsrFigures,false);
2015-03-14 17:39:04 +01:00
}
}
/*****************************************************************************/
/* Get number of clicks of a user from log table and store in user's figures */
/*****************************************************************************/
static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod)
{
struct UsrFigures UsrFigures;
if (Usr_ChkIfUsrCodExists (UsrCod))
{
/***** Reset user's figures *****/
Prf_ResetUsrFigures (&UsrFigures);
/***** Get number of clicks from database *****/
2018-11-03 20:52:00 +01:00
UsrFigures.NumClicks =
(long) DB_QueryCOUNT ("can not get number of clicks",
2018-11-04 20:51:38 +01:00
"SELECT COUNT(*) FROM log_full"
" WHERE UsrCod=%ld",
2018-11-03 20:52:00 +01:00
UsrCod);
2015-03-14 17:39:04 +01:00
/***** Update number of clicks in user's figures *****/
if (Prf_CheckIfUsrFiguresExists (UsrCod))
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update user's figures",
"UPDATE usr_figures SET NumClicks=%ld"
" WHERE UsrCod=%ld",
UsrFigures.NumClicks,UsrCod);
2015-03-14 17:39:04 +01:00
else // User entry does not exist
2016-11-08 00:58:32 +01:00
Prf_CreateUsrFigures (UsrCod,&UsrFigures,false);
2015-03-14 17:39:04 +01:00
}
2019-03-06 10:13:39 +01:00
}
/*****************************************************************************/
/* Get number of social publications from a user and store in user's figures */
/*****************************************************************************/
static void Prf_GetNumSocialPubsAndStoreAsUsrFigure (long UsrCod)
{
struct UsrFigures UsrFigures;
if (Usr_ChkIfUsrCodExists (UsrCod))
{
/***** Reset user's figures *****/
Prf_ResetUsrFigures (&UsrFigures);
/***** Get number of forum posts from database *****/
2019-03-12 21:25:55 +01:00
UsrFigures.NumSocPub = TL_GetNumPubsUsr (UsrCod);
2019-03-06 10:13:39 +01:00
/***** Update number of forum posts in user's figures *****/
if (Prf_CheckIfUsrFiguresExists (UsrCod))
DB_QueryUPDATE ("can not update user's figures",
"UPDATE usr_figures SET NumSocPub=%ld"
" WHERE UsrCod=%ld",
UsrFigures.NumSocPub,UsrCod);
else // User entry does not exist
Prf_CreateUsrFigures (UsrCod,&UsrFigures,false);
}
}
2015-03-14 17:39:04 +01:00
/*****************************************************************************/
/**** Get number of file views sent by a user and store in user's figures ****/
/*****************************************************************************/
static void Prf_GetNumFileViewsAndStoreAsUsrFigure (long UsrCod)
{
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))
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update user's figures",
"UPDATE usr_figures SET NumFileViews=%ld"
" WHERE UsrCod=%ld",
UsrFigures.NumFileViews,UsrCod);
2015-03-14 17:39:04 +01:00
else // User entry does not exist
2016-11-08 00:58:32 +01:00
Prf_CreateUsrFigures (UsrCod,&UsrFigures,false);
2015-03-14 17:39:04 +01:00
}
2019-03-06 10:13:39 +01:00
}
2015-03-14 17:39:04 +01:00
/*****************************************************************************/
/**** Get number of forum posts sent by a user and store in user's figures ***/
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
static void Prf_GetNumForumPostsAndStoreAsUsrFigure (long UsrCod)
2015-03-14 17:39:04 +01:00
{
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))
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update user's figures",
"UPDATE usr_figures SET NumForPst=%ld"
" WHERE UsrCod=%ld",
UsrFigures.NumForPst,UsrCod);
2015-03-14 17:39:04 +01:00
else // User entry does not exist
2016-11-08 00:58:32 +01:00
Prf_CreateUsrFigures (UsrCod,&UsrFigures,false);
2015-03-14 17:39:04 +01:00
}
2019-03-06 10:13:39 +01:00
}
2015-03-14 17:39:04 +01:00
/*****************************************************************************/
/***** Get number of messages sent by a user and store in user's figures *****/
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod)
2015-03-14 17:39:04 +01:00
{
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))
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update user's figures",
"UPDATE usr_figures SET NumMsgSnt=%ld"
" WHERE UsrCod=%ld",
UsrFigures.NumMsgSnt,UsrCod);
2015-03-14 17:39:04 +01:00
else // User entry does not exist
2016-11-08 00:58:32 +01:00
Prf_CreateUsrFigures (UsrCod,&UsrFigures,false);
2015-03-14 17:39:04 +01:00
}
}
2015-03-28 18:34:08 +01:00
/*****************************************************************************/
/******************* Create user's figures for a new user ********************/
/*****************************************************************************/
2016-11-08 00:58:32 +01:00
void Prf_CreateNewUsrFigures (long UsrCod,bool CreatingMyOwnAccount)
2015-03-28 18:34:08 +01:00
{
struct UsrFigures UsrFigures;
/***** Reset user's figures *****/
Prf_ResetUsrFigures (&UsrFigures);
2016-11-08 00:58:32 +01:00
UsrFigures.NumClicks = 0; // set number of clicks to 0
2019-03-06 10:13:39 +01:00
UsrFigures.NumSocPub = 0; // set number of social publications to 0
2016-11-08 00:58:32 +01:00
UsrFigures.NumFileViews = 0; // set number of file views to 0
UsrFigures.NumForPst = 0; // set number of forum posts to 0
UsrFigures.NumMsgSnt = 0; // set number of messages sent to 0
2015-03-28 18:34:08 +01:00
/***** Create user's figures *****/
2016-11-08 00:58:32 +01:00
Prf_CreateUsrFigures (UsrCod,&UsrFigures,CreatingMyOwnAccount);
2015-03-28 18:34:08 +01:00
}
2015-03-14 17:39:04 +01:00
/*****************************************************************************/
/********************** Reset values of user's figures ***********************/
/*****************************************************************************/
static void Prf_ResetUsrFigures (struct UsrFigures *UsrFigures)
{
2015-10-26 14:35:50 +01:00
UsrFigures->FirstClickTimeUTC = (time_t) 0; // unknown first click time or user never logged
2016-11-08 00:58:32 +01:00
UsrFigures->NumDays = -1; // not applicable
UsrFigures->NumClicks = -1L; // unknown number of clicks
2019-03-06 10:13:39 +01:00
UsrFigures->NumSocPub = -1L; // unknown number of social publications
2016-11-08 00:58:32 +01:00
UsrFigures->NumFileViews = -1L; // unknown number of file views
UsrFigures->NumForPst = -1L; // unknown number of forum posts
UsrFigures->NumMsgSnt = -1L; // unknown number of messages sent
2015-03-14 17:39:04 +01:00
}
/*****************************************************************************/
/***** Get number of messages sent by a user and store in user's figures *****/
/*****************************************************************************/
2017-03-08 01:21:21 +01:00
#define Prf_MAX_BYTES_SUBQUERY_FIRST_CLICK_TIME (64 - 1)
2017-01-15 22:58:26 +01:00
2016-11-08 00:58:32 +01:00
static void Prf_CreateUsrFigures (long UsrCod,const struct UsrFigures *UsrFigures,
bool CreatingMyOwnAccount)
2015-03-14 17:39:04 +01:00
{
2017-03-08 01:21:21 +01:00
char SubQueryFirstClickTime[Prf_MAX_BYTES_SUBQUERY_FIRST_CLICK_TIME + 1];
2016-11-08 00:58:32 +01:00
if (CreatingMyOwnAccount)
2017-01-15 22:58:26 +01:00
// This is the first click
Str_Copy (SubQueryFirstClickTime,"NOW()",
2017-03-08 01:21:21 +01:00
Prf_MAX_BYTES_SUBQUERY_FIRST_CLICK_TIME);
2016-11-08 00:58:32 +01:00
else
2017-03-24 01:09:27 +01:00
sprintf (SubQueryFirstClickTime,"FROM_UNIXTIME(%ld)",
2016-11-08 00:58:32 +01:00
(long) UsrFigures->FirstClickTimeUTC); // 0 ==> unknown first click time or user never logged
2015-03-14 17:39:04 +01:00
/***** Create user's figures *****/
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not create user's figures",
"INSERT INTO usr_figures"
2019-03-06 10:13:39 +01:00
" (UsrCod,FirstClickTime,NumClicks,NumSocPub,NumFileViews,NumForPst,NumMsgSnt)"
2018-11-02 19:37:11 +01:00
" VALUES"
2019-03-06 10:13:39 +01:00
" (%ld,%s,%ld,%ld,%ld,%ld,%ld)",
2018-11-02 19:37:11 +01:00
UsrCod,
SubQueryFirstClickTime,
UsrFigures->NumClicks, // -1L ==> unknown number of clicks
2019-03-06 10:13:39 +01:00
UsrFigures->NumSocPub, // -1L ==> unknown number of social publications
2018-11-02 19:37:11 +01:00
UsrFigures->NumFileViews, // -1L ==> unknown number of file views
UsrFigures->NumForPst, // -1L ==> unknown number of forum posts
UsrFigures->NumMsgSnt); // -1L ==> unknown number of messages sent
2015-03-14 17:39:04 +01:00
}
/*****************************************************************************/
/**************************** Remove user's figures **************************/
/*****************************************************************************/
void Prf_RemoveUsrFigures (long UsrCod)
{
/***** Remove user's figures *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not delete user's figures",
"DELETE FROM usr_figures WHERE UsrCod=%ld",
UsrCod);
2015-03-14 17:39:04 +01:00
}
/*****************************************************************************/
/*** Check if it exists an entry for this user in table of user's figures ****/
/*****************************************************************************/
static bool Prf_CheckIfUsrFiguresExists (long UsrCod)
{
2018-11-03 20:52:00 +01:00
return (DB_QueryCOUNT ("can not get user's first click",
2018-11-04 20:51:38 +01:00
"SELECT COUNT(*) FROM usr_figures"
" WHERE UsrCod=%ld",
2018-11-03 20:52:00 +01:00
UsrCod) != 0);
2015-03-14 17:39:04 +01:00
}
/*****************************************************************************/
/*************** Increment number of clicks made by a user *******************/
/*****************************************************************************/
void Prf_IncrementNumClicksUsr (long UsrCod)
{
/***** Increment number of clicks *****/
// If NumClicks < 0 ==> not yet calculated, so do nothing
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not increment user's clicks",
"UPDATE IGNORE usr_figures SET NumClicks=NumClicks+1"
" WHERE UsrCod=%ld AND NumClicks>=0",
UsrCod);
2015-03-14 17:39:04 +01:00
}
2019-03-06 10:13:39 +01:00
/*****************************************************************************/
/********* Increment number of social publications sent by a user ************/
/*****************************************************************************/
void Prf_IncrementNumSocPubUsr (long UsrCod)
{
/***** Increment number of social publications *****/
// If NumSocPub < 0 ==> not yet calculated, so do nothing
DB_QueryINSERT ("can not increment user's social publications",
"UPDATE IGNORE usr_figures SET NumSocPub=NumSocPub+1"
" WHERE UsrCod=%ld AND NumSocPub>=0",
UsrCod);
}
2015-03-14 17:39:04 +01:00
/*****************************************************************************/
/************** Increment number of file views sent by a user ****************/
/*****************************************************************************/
void Prf_IncrementNumFileViewsUsr (long UsrCod)
{
/***** Increment number of file views *****/
// If NumFileViews < 0 ==> not yet calculated, so do nothing
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not increment user's file views",
"UPDATE IGNORE usr_figures SET NumFileViews=NumFileViews+1"
" WHERE UsrCod=%ld AND NumFileViews>=0",
UsrCod);
2015-03-14 17:39:04 +01:00
}
/*****************************************************************************/
/************* Increment number of forum posts sent by a user ****************/
/*****************************************************************************/
void Prf_IncrementNumForPstUsr (long UsrCod)
{
/***** Increment number of forum posts *****/
// If NumForPst < 0 ==> not yet calculated, so do nothing
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not increment user's forum posts",
"UPDATE IGNORE usr_figures SET NumForPst=NumForPst+1"
" WHERE UsrCod=%ld AND NumForPst>=0",
UsrCod);
2015-03-14 17:39:04 +01:00
}
/*****************************************************************************/
/*************** Increment number of messages sent by a user *****************/
/*****************************************************************************/
void Prf_IncrementNumMsgSntUsr (long UsrCod)
{
/***** Increment number of messages sent *****/
// If NumMsgSnt < 0 ==> not yet calculated, so do nothing
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not increment user's messages sent",
"UPDATE IGNORE usr_figures SET NumMsgSnt=NumMsgSnt+1"
" WHERE UsrCod=%ld AND NumMsgSnt>=0",
UsrCod);
2015-03-14 17:39:04 +01:00
}
2015-03-16 14:05:16 +01:00
/*****************************************************************************/
/******** Get and show ranking of users attending to number of clicks ********/
/*****************************************************************************/
void Prf_GetAndShowRankingClicks (void)
{
2015-03-16 17:46:32 +01:00
Prf_GetAndShowRankingFigure ("NumClicks");
}
2019-03-06 13:14:40 +01:00
void Prf_GetAndShowRankingSocPub (void)
{
Prf_GetAndShowRankingFigure ("NumSocPub");
}
2015-03-16 17:46:32 +01:00
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)
{
2018-11-01 19:23:52 +01:00
MYSQL_RES *mysql_res;
unsigned NumUsrs = 0; // Initialized to avoid warning
2015-03-16 14:05:16 +01:00
/***** Get ranking from database *****/
switch (Gbl.Scope.Current)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2018-11-01 19:23:52 +01:00
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT UsrCod,%s"
" FROM usr_figures"
2019-03-06 13:14:40 +01:00
" WHERE %s>0"
2018-11-01 19:23:52 +01:00
" AND UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY %s DESC,UsrCod LIMIT 100",
FieldName,
FieldName,FieldName);
2015-03-16 14:05:16 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2018-11-01 19:23:52 +01:00
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"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"
2019-03-06 13:14:40 +01:00
" AND usr_figures.%s>0"
2018-11-01 19:23:52 +01:00
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod,
2018-11-01 19:23:52 +01:00
FieldName,FieldName);
2015-03-16 14:05:16 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2018-11-01 19:23:52 +01:00
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"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"
2019-03-06 13:14:40 +01:00
" AND usr_figures.%s>0"
2018-11-01 19:23:52 +01:00
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod,
2018-11-01 19:23:52 +01:00
FieldName,FieldName);
2015-03-16 14:05:16 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2018-11-01 19:23:52 +01:00
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"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"
2019-03-06 13:14:40 +01:00
" AND usr_figures.%s>0"
2018-11-01 19:23:52 +01:00
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod,
2018-11-01 19:23:52 +01:00
FieldName,FieldName);
2015-03-16 14:05:16 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2018-11-01 19:23:52 +01:00
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"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"
2019-03-06 13:14:40 +01:00
" AND usr_figures.%s>0"
2018-11-01 19:23:52 +01:00
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod,
2018-11-01 19:23:52 +01:00
FieldName,FieldName);
2015-03-16 14:05:16 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2018-11-01 19:23:52 +01:00
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"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"
2019-03-06 13:14:40 +01:00
" AND usr_figures.%s>0"
2018-11-01 19:23:52 +01:00
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod,
2018-11-01 19:23:52 +01:00
FieldName,FieldName);
2015-03-16 14:05:16 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2015-03-16 14:05:16 +01:00
break;
}
2018-11-01 19:23:52 +01:00
Prf_ShowRankingFigure (&mysql_res,NumUsrs);
2015-03-23 10:35:15 +01:00
}
2018-11-01 19:23:52 +01:00
void Prf_ShowRankingFigure (MYSQL_RES **mysql_res,unsigned NumUsrs)
2015-03-23 10:35:15 +01:00
{
MYSQL_ROW row;
unsigned NumUsr;
unsigned Rank;
struct UsrData UsrDat;
long FigureHigh = LONG_MAX;
long Figure;
2015-03-16 14:05:16 +01:00
if (NumUsrs)
{
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
2019-10-23 19:05:05 +02:00
HTM_TABLE_Begin (NULL);
2015-03-16 14:05:16 +01:00
2015-03-17 14:51:58 +01:00
for (NumUsr = 1, Rank = 1, Gbl.RowEvenOdd = 0;
2015-03-17 02:40:35 +01:00
NumUsr <= NumUsrs;
2015-03-17 14:51:58 +01:00
NumUsr++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd)
2015-03-16 14:05:16 +01:00
{
/***** Get user and number of clicks *****/
2018-11-01 19:23:52 +01:00
row = mysql_fetch_row (*mysql_res);
2015-03-16 14:05:16 +01:00
/* Get user's code (row[0]) */
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
2019-03-19 13:22:14 +01:00
Usr_GetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS);
2015-03-16 14:05:16 +01:00
2015-03-16 17:46:32 +01:00
/* Get figure (row[1]) */
if (sscanf (row[1],"%ld",&Figure) != 1)
Lay_ShowErrorAndExit ("Error reading user's figure.");
if (Figure < FigureHigh)
{
2015-03-17 02:40:35 +01:00
Rank = NumUsr;
2015-03-16 17:46:32 +01:00
FigureHigh = Figure;
}
2015-03-16 14:05:16 +01:00
/***** Show row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-09 21:05:58 +02:00
2015-03-17 14:51:58 +01:00
Prf_ShowUsrInRanking (&UsrDat,Rank);
2019-10-10 23:14:13 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"RM COLOR%u\"",Gbl.RowEvenOdd);
2019-10-09 21:05:58 +02:00
fprintf (Gbl.F.Out,"%ld",Figure);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 20:17:29 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2015-03-16 14:05:16 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2015-03-16 14:05:16 +01:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
/***** Free structure that stores the query result *****/
2018-11-01 19:23:52 +01:00
DB_FreeMySQLResult (mysql_res);
2015-03-16 14:05:16 +01:00
}
/*****************************************************************************/
/**** Get and show ranking of users attending to number of clicks per day ****/
/*****************************************************************************/
void Prf_GetAndShowRankingClicksPerDay (void)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2018-11-01 19:23:52 +01:00
unsigned NumUsrs = 0; // Initialized to avoid warning
2015-03-16 14:05:16 +01:00
unsigned NumUsr;
2015-03-16 17:46:32 +01:00
unsigned Rank;
2015-03-16 14:05:16 +01:00
struct UsrData UsrDat;
2015-03-16 17:46:32 +01:00
float NumClicksPerDayHigh = (float) LONG_MAX;
2015-03-16 14:05:16 +01:00
float NumClicksPerDay;
/***** Get ranking from database *****/
switch (Gbl.Scope.Current)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2018-11-01 19:23:52 +01:00
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT UsrCod,"
"NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1) AS NumClicksPerDay"
" FROM usr_figures"
" WHERE NumClicks>0"
2018-11-03 20:52:00 +01:00
" AND FirstClickTime>FROM_UNIXTIME(0)"
2018-11-01 19:23:52 +01:00
" AND UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,UsrCod LIMIT 100");
2015-03-16 14:05:16 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2018-11-01 19:23:52 +01:00
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" 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.NumClicks>0"
2018-11-03 20:52:00 +01:00
" AND usr_figures.FirstClickTime>FROM_UNIXTIME(0)"
2018-11-01 19:23:52 +01:00
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod);
2015-03-16 14:05:16 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2018-11-01 19:23:52 +01:00
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" 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.NumClicks>0"
2018-11-03 20:52:00 +01:00
" AND usr_figures.FirstClickTime>FROM_UNIXTIME(0)"
2018-11-01 19:23:52 +01:00
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod);
2015-03-16 14:05:16 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2018-11-01 19:23:52 +01:00
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" 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.NumClicks>0"
2018-11-03 20:52:00 +01:00
" AND usr_figures.FirstClickTime>FROM_UNIXTIME(0)"
2018-11-01 19:23:52 +01:00
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod);
2015-03-16 14:05:16 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2018-11-01 19:23:52 +01:00
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" 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.NumClicks>0"
2018-11-03 20:52:00 +01:00
" AND usr_figures.FirstClickTime>FROM_UNIXTIME(0)"
2018-11-01 19:23:52 +01:00
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod);
2015-03-16 14:05:16 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2018-11-01 19:23:52 +01:00
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM crs_usr,usr_figures"
" WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0"
2018-11-03 20:52:00 +01:00
" AND usr_figures.FirstClickTime>FROM_UNIXTIME(0)"
2018-11-01 19:23:52 +01:00
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2015-03-16 14:05:16 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2015-03-16 14:05:16 +01:00
break;
}
2018-11-01 19:23:52 +01:00
2015-03-16 14:05:16 +01:00
if (NumUsrs)
{
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
2019-10-23 19:05:05 +02:00
HTM_TABLE_Begin (NULL);
2015-03-16 14:05:16 +01:00
2015-03-17 14:51:58 +01:00
for (NumUsr = 1, Rank = 1, Gbl.RowEvenOdd = 0;
2015-03-17 02:40:35 +01:00
NumUsr <= NumUsrs;
2015-03-17 14:51:58 +01:00
NumUsr++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd)
2015-03-16 14:05:16 +01:00
{
/***** Get user and number of clicks *****/
row = mysql_fetch_row (mysql_res);
/* Get user's code (row[0]) */
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
2019-03-19 13:22:14 +01:00
Usr_GetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS);
2015-03-16 14:05:16 +01:00
/* Get number of clicks per day (row[1]) */
NumClicksPerDay = Str_GetFloatNumFromStr (row[1]);
2015-03-16 17:46:32 +01:00
if (NumClicksPerDay < NumClicksPerDayHigh)
{
2015-03-17 02:40:35 +01:00
Rank = NumUsr;
2015-03-16 17:46:32 +01:00
NumClicksPerDayHigh = NumClicksPerDay;
}
2015-03-16 14:05:16 +01:00
/***** Show row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2015-03-17 14:51:58 +01:00
Prf_ShowUsrInRanking (&UsrDat,Rank);
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"RM COLOR%u\"",Gbl.RowEvenOdd);
2019-10-10 21:21:24 +02:00
Str_WriteFloatNumToFile (Gbl.F.Out,NumClicksPerDay);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
HTM_TR_End ();
2015-03-16 14:05:16 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2015-03-16 14:05:16 +01:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2015-03-16 17:46:32 +01:00
/*****************************************************************************/
/************** Show user's photo and nickname in ranking list ***************/
/*****************************************************************************/
2019-03-06 13:14:40 +01:00
static void Prf_ShowUsrInRanking (struct UsrData *UsrDat,unsigned Rank)
2015-03-16 17:46:32 +01:00
{
2017-02-17 01:59:58 +01:00
extern const char *Txt_Another_user_s_profile;
2015-03-16 17:46:32 +01:00
bool ShowPhoto;
2017-01-28 15:58:46 +01:00
char PhotoURL[PATH_MAX + 1];
2019-03-22 15:21:46 +01:00
bool Visible = Pri_ShowingIsAllowed (UsrDat->BaPrfVisibility,UsrDat);
2015-03-17 14:51:58 +01:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"RANK RM COLOR%u\"",Gbl.RowEvenOdd);
2019-10-09 21:05:58 +02:00
fprintf (Gbl.F.Out,"#%u",Rank);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-03-16 17:46:32 +01:00
2015-03-16 20:26:39 +01:00
/***** Check if I can see the public profile *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"RANK_PHOTO COLOR%u\"",Gbl.RowEvenOdd);
2015-03-17 14:51:58 +01:00
if (Visible)
2015-03-16 20:26:39 +01:00
{
/***** User's photo *****/
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (UsrDat,PhotoURL);
2015-03-16 20:26:39 +01:00
Pho_ShowUsrPhoto (UsrDat,ShowPhoto ? PhotoURL :
NULL,
2016-01-14 10:31:09 +01:00
"PHOTO30x40",Pho_ZOOM,false);
2015-03-17 14:51:58 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-03-17 14:51:58 +01:00
/***** Put form to go to public profile *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"COLOR%u\"",Gbl.RowEvenOdd);
2015-03-25 16:25:50 +01:00
if (Visible)
2015-03-17 14:51:58 +01:00
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeOthPubPrf);
2017-02-17 06:32:57 +01:00
Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"RANK_USR\""); // Limited width
2018-11-09 20:47:39 +01:00
Frm_LinkFormSubmit (Txt_Another_user_s_profile,"DAT_SMALL",NULL);
2017-03-05 15:12:48 +01:00
Usr_WriteFirstNameBRSurnames (UsrDat);
2019-10-23 20:07:56 +02:00
fprintf (Gbl.F.Out,"</a>");
HTM_DIV_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-16 20:26:39 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2015-03-16 17:46:32 +01:00
}