// 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.
Copyright (C) 1999-2019 Antonio Caņas Vargas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General 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 .
*/
/*****************************************************************************/
/*********************************** Headers *********************************/
/*****************************************************************************/
#include // For NULL
#include // For string functions
#include "swad_box.h"
#include "swad_config.h"
#include "swad_database.h"
#include "swad_follow.h"
#include "swad_form.h"
#include "swad_global.h"
#include "swad_HTML.h"
#include "swad_language.h"
#include "swad_network.h"
#include "swad_nickname.h"
#include "swad_notification.h"
#include "swad_parameter.h"
#include "swad_privacy.h"
#include "swad_profile.h"
#include "swad_role.h"
#include "swad_role_type.h"
#include "swad_setting.h"
#include "swad_theme.h"
#include "swad_timeline.h"
#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 ****************************/
/*****************************************************************************/
static void Prf_ShowTimeSinceFirstClick (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures);
static void Prf_ShowNumCrssWithRole (const struct UsrData *UsrDat,
Rol_Role_t Role);
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);
static void Prf_PutLinkCalculateFigures (const char *EncryptedUsrCod);
static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName);
static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName);
static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod);
static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void);
static void Prf_ShowRanking (unsigned long Rank,unsigned long NumUsrs);
static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod);
static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod);
static void Prf_GetNumSocialPubsAndStoreAsUsrFigure (long UsrCod);
static void Prf_GetNumFileViewsAndStoreAsUsrFigure (long UsrCod);
static void Prf_GetNumForumPostsAndStoreAsUsrFigure (long UsrCod);
static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod);
static void Prf_ResetUsrFigures (struct UsrFigures *UsrFigures);
static void Prf_CreateUsrFigures (long UsrCod,const struct UsrFigures *UsrFigures,
bool CreatingMyOwnAccount);
static bool Prf_CheckIfUsrFiguresExists (long UsrCod);
static void Prf_GetAndShowRankingFigure (const char *FieldName);
static void Prf_ShowUsrInRanking (struct UsrData *UsrDat,unsigned Rank);
/*****************************************************************************/
/************* Suggest who to follow or request user's profile ***************/
/*****************************************************************************/
void Prf_SeeSocialProfiles (void)
{
if (Gbl.Usrs.Me.Logged)
Fol_SuggestUsrsToFollowMainZone ();
else
Prf_RequestUserProfile ();
}
/*****************************************************************************/
/************************** Get public profile URL ***************************/
/*****************************************************************************/
char *Prf_GetURLPublicProfile (char URL[Cns_MAX_BYTES_WWW + 1],
const char *NicknameWithoutArroba)
{
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
/***** Build URL using nickname *****/
snprintf (URL,Cns_MAX_BYTES_WWW + 1,
"%s/%s?usr=@%s",
Cfg_URL_SWAD_CGI,
Lan_STR_LANG_ID[Gbl.Prefs.Language],
NicknameWithoutArroba);
return URL;
}
/*****************************************************************************/
/******************** Put link to view my public profile *********************/
/*****************************************************************************/
void Prf_PutLinkMyPublicProfile (void)
{
extern const char *Txt_My_public_profile;
Lay_PutContextualLinkIconText (ActSeeOthPubPrf,NULL,
Usr_PutParamMyUsrCodEncrypted,
"user.svg",
Txt_My_public_profile);
}
/*****************************************************************************/
/***************** Put link to request another user's profile ****************/
/*****************************************************************************/
void Prf_PutLinkRequestAnotherUserProfile (void)
{
extern const char *Txt_Another_user_s_profile;
Lay_PutContextualLinkIconText (ActReqOthPubPrf,NULL,NULL,
"user.svg",
Txt_Another_user_s_profile);
}
/*****************************************************************************/
/************************** Request a user's profile *************************/
/*****************************************************************************/
void Prf_RequestUserProfile (void)
{
extern const char *Hlp_START_Profiles_view_public_profile;
extern const char *Txt_Another_user_s_profile;
extern const char *The_ClassFormInBox[The_NUM_THEMES];
extern const char *Txt_Nickname;
extern const char *Txt_Continue;
if (Gbl.Usrs.Me.Logged)
{
/***** Put link to show my public profile and users to follow *****/
fprintf (Gbl.F.Out,"