swad-core/swad_follow.c

1218 lines
42 KiB
C
Raw Normal View History

2015-03-18 01:06:43 +01:00
// swad_follow.c: user's followers and followed
/*
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-2024 Antonio Ca<EFBFBD>as Vargas
2015-03-18 01:06:43 +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 *********************************/
/*****************************************************************************/
#define _GNU_SOURCE // For asprintf
2015-10-16 02:24:29 +02:00
#include <stdbool.h> // For boolean type
#include <stdio.h> // For asprintf
2015-03-24 00:01:40 +01:00
#include <string.h> // For string functions
2015-03-18 01:06:43 +01:00
#include "swad_action_list.h"
#include "swad_alert.h"
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2015-03-18 01:06:43 +01:00
#include "swad_database.h"
#include "swad_error.h"
2020-04-14 17:15:17 +02:00
#include "swad_figure.h"
2015-03-18 01:06:43 +01:00
#include "swad_follow.h"
#include "swad_follow_database.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2015-03-18 01:06:43 +01:00
#include "swad_global.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2015-03-24 00:01:40 +01:00
#include "swad_notification.h"
#include "swad_notification_database.h"
#include "swad_parameter.h"
2020-04-14 17:15:17 +02:00
#include "swad_photo.h"
2016-12-09 13:59:33 +01:00
#include "swad_privacy.h"
2015-03-18 02:11:23 +01:00
#include "swad_profile.h"
2015-03-18 01:06:43 +01:00
#include "swad_user.h"
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
2015-12-12 19:47:10 +01:00
#define Fol_NUM_COLUMNS_FOLLOW 3
2015-03-19 12:32:45 +01:00
2017-05-25 13:43:54 +02:00
#define Fol_FOLLOW_SECTION_ID "follow_section"
2015-03-18 01:06:43 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2020-04-08 18:18:46 +02:00
static void Fol_PutIconsWhoToFollow (__attribute__((unused)) void *Args);
2016-03-24 13:50:57 +01:00
static void Fol_PutIconToUpdateWhoToFollow (void);
2016-03-24 13:40:05 +01:00
static void Fol_ShowNumberOfFollowingOrFollowers (const struct Usr_Data *UsrDat,
2015-03-21 19:55:00 +01:00
unsigned NumUsrs,
Act_Action_t Action,
const char *Title);
2016-06-12 19:55:33 +02:00
static void Fol_ListFollowingUsr (struct Usr_Data *UsrDat);
static void Fol_ListFollowersUsr (struct Usr_Data *UsrDat);
2016-06-12 19:55:33 +02:00
static void Fol_ShowFollowedOrFollower (struct Usr_Data *UsrDat);
static void Fol_WriteRowUsrToFollowOnRightColumn (struct Usr_Data *UsrDat);
2017-02-16 20:22:13 +01:00
static void Fol_PutInactiveIconToFollowUnfollow (void);
static void Fol_PutIconToFollow (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1]);
static void Fol_PutIconToUnfollow (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1]);
2015-03-19 00:28:37 +01:00
2019-04-22 10:10:21 +02:00
static void Fol_RequestFollowUsrs (Act_Action_t NextAction);
static void Fol_RequestUnfollowUsrs (Act_Action_t NextAction);
static void Fol_PutParSelectedUsrsCods (void *SelectedUsrs);
2019-03-12 01:46:40 +01:00
static void Fol_GetFollowedFromSelectedUsrs (unsigned *NumFollowed,
unsigned *NumNotFollowed);
static void Fol_FollowUsr (const struct Usr_Data *UsrDat);
static void Fol_UnfollowUsr (const struct Usr_Data *UsrDat);
2019-03-12 01:46:40 +01:00
2016-01-27 22:31:36 +01:00
/*****************************************************************************/
2016-01-27 23:40:16 +01:00
/********************** Put link to show users to follow **********************/
2016-01-27 22:31:36 +01:00
/*****************************************************************************/
void Fol_PutLinkWhoToFollow (void)
{
extern const char *Txt_Who_to_follow;
2020-03-26 02:54:30 +01:00
Lay_PutContextualLinkIconText (ActSeeSocPrf,NULL,
NULL,NULL,
"user-plus.svg",Ico_BLACK,
Txt_Who_to_follow,NULL);
2016-01-27 22:31:36 +01:00
}
/*****************************************************************************/
2017-02-16 20:22:13 +01:00
/****************** Show several users to follow on main zone ****************/
2016-01-27 22:31:36 +01:00
/*****************************************************************************/
2017-02-16 20:22:13 +01:00
#define Fol_MAX_USRS_TO_FOLLOW_MAIN_ZONE (Fol_NUM_COLUMNS_FOLLOW * 3)
void Fol_SuggestUsrsToFollowOnMainZone (void)
2016-01-27 22:31:36 +01:00
{
2019-03-12 21:25:55 +01:00
extern const char *Hlp_START_Profiles_who_to_follow;
2016-01-28 21:31:11 +01:00
extern const char *Txt_Who_to_follow;
2016-01-27 23:28:53 +01:00
extern const char *Txt_No_user_to_whom_you_can_follow_Try_again_later;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs;
unsigned NumUsr;
struct Usr_Data UsrDat;
2016-01-27 23:04:27 +01:00
2019-10-24 09:46:20 +02:00
/***** Contextual menu *****/
Mnu_ContextMenuBegin ();
Prf_PutLinkMyPublicProfile (); // My public profile
Prf_PutLinkReqAnotherUsrProfile (); // Request another user's profile
2019-10-24 09:46:20 +02:00
Mnu_ContextMenuEnd ();
2016-01-29 00:41:52 +01:00
2017-02-16 17:58:37 +01:00
/***** Get users *****/
if ((NumUsrs = Fol_DB_GetUsrsToFollow (Fol_MAX_USRS_TO_FOLLOW_MAIN_ZONE,
Fol_SUGGEST_ANY_USER,
&mysql_res)))
2017-02-16 17:58:37 +01:00
{
/***** Begin box *****/
Box_BoxBegin (Txt_Who_to_follow,Fol_PutIconsWhoToFollow,NULL,
Hlp_START_Profiles_who_to_follow,Box_NOT_CLOSABLE);
2017-02-16 17:58:37 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
2017-02-16 17:58:37 +01:00
/***** List users *****/
for (NumUsr = 0;
NumUsr < NumUsrs;
NumUsr++)
{
/***** Get user *****/
row = mysql_fetch_row (mysql_res);
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/***** Show user *****/
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS))
Fol_ShowFollowedOrFollower (&UsrDat);
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
2017-02-16 17:58:37 +01:00
/***** End box *****/
Box_BoxEnd ();
2017-02-16 17:58:37 +01:00
}
else
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_INFO,Txt_No_user_to_whom_you_can_follow_Try_again_later);
2017-02-16 17:58:37 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2017-02-16 20:22:13 +01:00
/*****************************************************************************/
/**************** Show several users to follow on right column ***************/
/*****************************************************************************/
#define Fol_MAX_USRS_TO_FOLLOW_RIGHT_COLUMN 3
void Fol_SuggestUsrsToFollowOnRightColumn (void)
2017-02-16 20:22:13 +01:00
{
extern const char *Txt_No_user_to_whom_you_can_follow_Try_again_later;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs;
unsigned NumUsr;
struct Usr_Data UsrDat;
2017-02-16 20:22:13 +01:00
/***** Get users *****/
if ((NumUsrs = Fol_DB_GetUsrsToFollow (Fol_MAX_USRS_TO_FOLLOW_RIGHT_COLUMN,
Fol_SUGGEST_ONLY_USERS_WITH_PHOTO,
&mysql_res)))
2017-02-16 20:22:13 +01:00
{
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
2017-02-16 20:22:13 +01:00
/***** Begin table *****/
HTM_TABLE_Begin (NULL);
2017-02-16 20:22:13 +01:00
/***** List users *****/
for (NumUsr = 0;
NumUsr < NumUsrs;
NumUsr++)
{
/***** Get user *****/
row = mysql_fetch_row (mysql_res);
2017-02-16 20:22:13 +01:00
/* Get user's code (row[0]) */
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
2017-02-16 20:22:13 +01:00
/***** Show user *****/
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS))
Fol_WriteRowUsrToFollowOnRightColumn (&UsrDat);
}
2017-02-16 20:22:13 +01:00
/***** End table *****/
HTM_TABLE_End ();
2017-02-16 20:22:13 +01:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
/***** Link to suggest more users to follow *****/
Lay_PutContextualLinkOnlyIcon (ActSeeSocPrf,NULL,
NULL,NULL,
"ellipsis-h.svg",Ico_BLACK);
2017-02-16 20:22:13 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2016-11-07 10:45:03 +01:00
/*****************************************************************************/
/****************** Put contextual icons in "who to follow" ******************/
/*****************************************************************************/
2020-04-08 18:18:46 +02:00
static void Fol_PutIconsWhoToFollow (__attribute__((unused)) void *Args)
2016-11-07 10:45:03 +01:00
{
2020-04-08 18:18:46 +02:00
/***** Put icon to update who to follow *****/
Fol_PutIconToUpdateWhoToFollow ();
2016-11-07 10:45:03 +01:00
2020-04-08 18:18:46 +02:00
/***** Put icon to show a figure *****/
Fig_PutIconToShowFigure (Fig_FOLLOW);
2016-11-07 10:45:03 +01:00
}
2016-03-24 13:40:05 +01:00
/*****************************************************************************/
/********************* Put icon to update who to follow **********************/
/*****************************************************************************/
2016-03-24 13:50:57 +01:00
static void Fol_PutIconToUpdateWhoToFollow (void)
2016-03-24 13:40:05 +01:00
{
Ico_PutContextualIconToUpdate (ActSeeSocPrf,NULL,
NULL,NULL);
2016-03-24 13:40:05 +01:00
}
2015-12-29 14:24:37 +01:00
/*****************************************************************************/
/*************************** Get number of followed **************************/
/*****************************************************************************/
2019-02-22 14:04:54 +01:00
void Fol_FlushCacheFollow (void)
2015-12-29 14:24:37 +01:00
{
Gbl.Cache.Follow.Valid = false;
2015-12-29 14:24:37 +01:00
}
2019-02-22 14:04:54 +01:00
void Fol_GetNumFollow (long UsrCod,
unsigned *NumFollowing,unsigned *NumFollowers)
2015-12-29 14:24:37 +01:00
{
2019-02-22 14:04:54 +01:00
/***** 1. Fast check: trivial cases *****/
if (UsrCod <= 0)
{
*NumFollowing = *NumFollowers = 0;
return;
}
/***** 2. Fast check: Is number of following already calculated? *****/
if (Gbl.Cache.Follow.Valid &&
UsrCod == Gbl.Cache.Follow.UsrCod)
2019-02-22 14:04:54 +01:00
{
*NumFollowing = Gbl.Cache.Follow.NumFollowing;
*NumFollowers = Gbl.Cache.Follow.NumFollowers;
return;
}
/***** 3. Slow check: Get number of following/followers from database *****/
Gbl.Cache.Follow.UsrCod = UsrCod;
*NumFollowing = Gbl.Cache.Follow.NumFollowing = Fol_DB_GetNumFollowing (UsrCod);
*NumFollowers = Gbl.Cache.Follow.NumFollowers = Fol_DB_GetNumFollowers (UsrCod);
Gbl.Cache.Follow.Valid = true;
2015-12-29 14:24:37 +01:00
}
2015-03-19 00:28:37 +01:00
/*****************************************************************************/
/**************** Show following and followers of a user *********************/
/*****************************************************************************/
void Fol_ShowFollowingAndFollowers (const struct Usr_Data *UsrDat,
2015-12-29 19:40:38 +01:00
unsigned NumFollowing,unsigned NumFollowers,
bool UsrFollowsMe,bool IFollowUsr)
2015-03-19 00:28:37 +01:00
{
2015-12-29 20:39:06 +01:00
extern const char *Txt_FOLLOWS_YOU;
2015-03-19 00:28:37 +01:00
extern const char *Txt_Following;
extern const char *Txt_Followers;
/***** Begin section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_Begin (Fol_FOLLOW_SECTION_ID);
2015-03-19 00:28:37 +01:00
/***** Followed users *****/
HTM_DIV_Begin ("id=\"following_side\"");
HTM_DIV_Begin ("class=\"FOLLOW_SIDE\"");
2015-12-29 19:40:38 +01:00
/* User follows me? */
HTM_DIV_Begin ("id=\"follows_me\" class=\"DAT_LIGHT_%s\"",
The_GetSuffix ());
if (UsrFollowsMe)
HTM_Txt (Txt_FOLLOWS_YOU);
HTM_DIV_End ();
2015-03-21 19:55:00 +01:00
/* Number of followed */
Fol_ShowNumberOfFollowingOrFollowers (UsrDat,
NumFollowing,
ActSeeFlg,Txt_Following);
2015-12-29 19:40:38 +01:00
/* End following side */
HTM_DIV_End ();
HTM_DIV_End ();
2015-12-29 19:40:38 +01:00
/***** Followers *****/
HTM_DIV_Begin ("id=\"followers_side\"");
HTM_DIV_Begin ("class=\"FOLLOW_SIDE\"");
/* Number of followers */
Fol_ShowNumberOfFollowingOrFollowers (UsrDat,
NumFollowers,
ActSeeFlr,Txt_Followers);
/* I follow user? */
HTM_DIV_Begin ("id=\"follow_usr\"");
if (Gbl.Usrs.Me.Logged && // Logged
Usr_ItsMe (UsrDat->UsrCod) == Usr_OTHER) // Not me!
{
Frm_BeginForm (IFollowUsr ? ActUnfUsr :
ActFolUsr);
Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_INPUT_IMAGE (Cfg_URL_ICON_PUBLIC,
IFollowUsr ? "user-check.svg" :
"user-plus.svg",
Act_GetActionText (IFollowUsr ? ActUnfUsr :
ActFolUsr),
"class=\"ICO_HIGHLIGHT ICO40x40\"");
Frm_EndForm ();
}
HTM_DIV_End ();
2015-03-21 19:55:00 +01:00
/* End followers side */
HTM_DIV_End ();
HTM_DIV_End ();
2015-12-29 19:40:38 +01:00
2015-12-12 19:47:10 +01:00
/***** End section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_End ();
2015-03-21 19:55:00 +01:00
}
/*****************************************************************************/
/**************** Show following and followers of a user *********************/
/*****************************************************************************/
static void Fol_ShowNumberOfFollowingOrFollowers (const struct Usr_Data *UsrDat,
2015-03-21 19:55:00 +01:00
unsigned NumUsrs,
Act_Action_t Action,
const char *Title)
{
/***** Begin container *****/
HTM_DIV_Begin ("class=\"FOLLOW_BOX %s\"",
(Gbl.Action.Act == Action) ? "FOLLOW_NUM_B" :
"FOLLOW_NUM");
2015-03-21 19:55:00 +01:00
/***** Number *****/
if (NumUsrs)
{
/* Form to list users */
Frm_BeginFormAnchor (Action,Fol_FOLLOW_SECTION_ID);
Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_BUTTON_Submit_Begin (Title,"class=\"BT_LINK\"");
}
HTM_Unsigned (NumUsrs);
if (NumUsrs)
{
HTM_BUTTON_End ();
Frm_EndForm ();
}
2015-03-19 00:28:37 +01:00
/***** Text *****/
HTM_DIV_Begin ("class=\"FORM_OUT_%s%s\"",
The_GetSuffix (),
(Gbl.Action.Act == Action) ? " BOLD" :
"");
if (NumUsrs)
{
/* Form to list users */
Frm_BeginFormAnchor (Action,Fol_FOLLOW_SECTION_ID);
Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_BUTTON_Submit_Begin (Title,"class=\"BT_LINK\"");
}
HTM_Txt (Title);
if (NumUsrs)
{
HTM_BUTTON_End ();
Frm_EndForm ();
}
HTM_DIV_End ();
2015-12-12 19:47:10 +01:00
/***** End container *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2015-03-19 00:28:37 +01:00
}
2015-03-19 01:59:08 +01:00
/*****************************************************************************/
/***************************** List followed users ***************************/
/*****************************************************************************/
void Fol_ListFollowing (void)
2016-06-12 19:55:33 +02:00
{
/***** Get user to view user he/she follows *****/
Usr_GetParOtherUsrCodEncryptedAndGetListIDs ();
2016-06-12 19:55:33 +02:00
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS))
2016-06-12 19:55:33 +02:00
Fol_ListFollowingUsr (&Gbl.Usrs.Other.UsrDat);
else
2019-03-09 20:12:44 +01:00
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
2016-06-12 19:55:33 +02:00
}
else // If user not specified, view my profile
Fol_ListFollowingUsr (&Gbl.Usrs.Me.UsrDat);
}
static void Fol_ListFollowingUsr (struct Usr_Data *UsrDat)
2015-03-19 01:59:08 +01:00
{
2016-01-28 21:38:24 +01:00
extern const char *Txt_Following;
2015-03-19 01:59:08 +01:00
MYSQL_RES *mysql_res;
unsigned NumUsrs;
unsigned NumUsr;
struct Usr_Data FollowingUsrDat;
2015-03-19 01:59:08 +01:00
2016-06-12 19:55:33 +02:00
/***** Show user's profile *****/
if (Prf_ShowUsrProfile (UsrDat))
2015-03-19 01:59:08 +01:00
{
/***** Get list of following *****/
NumUsrs = Fol_DB_GetListFollowing (UsrDat->UsrCod,&mysql_res);
2018-10-31 09:40:43 +01:00
2016-06-12 19:55:33 +02:00
if (NumUsrs)
2015-03-19 01:59:08 +01:00
{
2016-06-12 19:55:33 +02:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&FollowingUsrDat);
/***** Begin box *****/
Box_BoxBegin (Txt_Following,NULL,NULL,NULL,Box_NOT_CLOSABLE);
2016-06-12 19:55:33 +02:00
for (NumUsr = 0;
NumUsr < NumUsrs;
NumUsr++)
{
/***** Get user's code *****/
FollowingUsrDat.UsrCod = DB_GetNextCode (mysql_res);
2016-06-12 19:55:33 +02:00
/***** Show user *****/
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&FollowingUsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS))
Fol_ShowFollowedOrFollower (&FollowingUsrDat);
}
2015-03-19 01:59:08 +01:00
/***** End box *****/
Box_BoxEnd ();
2016-06-12 19:55:33 +02:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&FollowingUsrDat);
2015-03-19 01:59:08 +01:00
}
2016-06-12 19:55:33 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2015-03-19 01:59:08 +01:00
}
else
2019-03-09 20:12:44 +01:00
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
2015-03-19 01:59:08 +01:00
}
/*****************************************************************************/
/******************************* List followers ******************************/
/*****************************************************************************/
void Fol_ListFollowers (void)
2016-06-12 19:55:33 +02:00
{
/***** Get user to view user he/she follows *****/
Usr_GetParOtherUsrCodEncryptedAndGetListIDs ();
2016-06-12 19:55:33 +02:00
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS))
2016-06-12 19:55:33 +02:00
Fol_ListFollowersUsr (&Gbl.Usrs.Other.UsrDat);
else
2019-03-09 20:12:44 +01:00
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
2016-06-12 19:55:33 +02:00
}
else // If user not specified, view my profile
Fol_ListFollowersUsr (&Gbl.Usrs.Me.UsrDat);
}
static void Fol_ListFollowersUsr (struct Usr_Data *UsrDat)
2015-03-19 01:59:08 +01:00
{
2016-01-28 21:38:24 +01:00
extern const char *Txt_Followers;
2015-03-19 01:59:08 +01:00
MYSQL_RES *mysql_res;
unsigned NumUsrs;
unsigned NumUsr;
struct Usr_Data FollowerUsrDat;
2015-03-19 01:59:08 +01:00
2016-06-12 19:55:33 +02:00
/***** Show user's profile *****/
if (Prf_ShowUsrProfile (UsrDat))
2015-03-19 01:59:08 +01:00
{
/***** Get list of followers *****/
if ((NumUsrs = Fol_DB_GetListFollowers (UsrDat->UsrCod,&mysql_res)))
2015-03-19 01:59:08 +01:00
{
2016-06-12 19:55:33 +02:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&FollowerUsrDat);
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
Box_BoxBegin (Txt_Followers,NULL,NULL,NULL,Box_NOT_CLOSABLE);
2016-06-12 19:55:33 +02:00
for (NumUsr = 0;
NumUsr < NumUsrs;
NumUsr++)
{
/***** Get user's code *****/
FollowerUsrDat.UsrCod = DB_GetNextCode (mysql_res);
2016-06-12 19:55:33 +02:00
/***** Show user *****/
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&FollowerUsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS))
Fol_ShowFollowedOrFollower (&FollowerUsrDat);
}
2015-03-19 01:59:08 +01:00
/***** End box *****/
Box_BoxEnd ();
2015-03-24 00:01:40 +01:00
2016-06-12 19:55:33 +02:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&FollowerUsrDat);
2015-03-19 01:59:08 +01:00
}
2016-06-12 19:55:33 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** If it's me, mark possible notification as seen *****/
if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME)
Ntf_DB_MarkNotifsAsSeen (Ntf_EVENT_FOLLOWER);
2015-03-19 01:59:08 +01:00
}
else
2019-03-09 20:12:44 +01:00
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
2015-03-19 01:59:08 +01:00
}
/*****************************************************************************/
2015-12-12 02:01:20 +01:00
/************************* Show followed or follower *************************/
2015-03-19 01:59:08 +01:00
/*****************************************************************************/
static void Fol_ShowFollowedOrFollower (struct Usr_Data *UsrDat)
2015-03-19 01:59:08 +01:00
{
2017-02-17 01:59:58 +01:00
extern const char *Txt_Another_user_s_profile;
static const char *ClassPhoto[PhoSha_NUM_SHAPES] =
{
[PhoSha_SHAPE_CIRCLE ] = "PHOTOC60x80",
[PhoSha_SHAPE_ELLIPSE ] = "PHOTOE60x80",
[PhoSha_SHAPE_OVAL ] = "PHOTOO60x80",
[PhoSha_SHAPE_RECTANGLE] = "PHOTOR60x80",
};
Usr_Can_t ICanView = Pri_CheckIfICanView (UsrDat->BaPrfVisibility,UsrDat);
2015-03-19 01:59:08 +01:00
HTM_DIV_Begin ("class=\"FOLLOW_USR\"");
2015-03-19 01:59:08 +01:00
/***** Show user's photo *****/
HTM_DIV_Begin ("class=\"FOLLOW_PHOTO\"");
if (ICanView == Usr_CAN)
Pho_ShowUsrPhotoIfAllowed (UsrDat,
ClassPhoto[Gbl.Prefs.PhotoShape],Pho_ZOOM);
HTM_DIV_End ();
2016-01-29 00:41:52 +01:00
/***** Show user's name and icon to follow/unfollow *****/
HTM_DIV_Begin ("class=\"FOLLOW_TXT\"");
if (ICanView == Usr_CAN)
{
/* Put form to go to public profile */
Frm_BeginForm (ActSeeOthPubPrf);
Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_DIV_Begin ("class=\"LT FOLLOW_TXT_NAME DAT_%s\"", // Limited width
The_GetSuffix ());
HTM_BUTTON_Submit_Begin (Txt_Another_user_s_profile,
"class=\"BT_LINK LT\"");
Usr_WriteFirstNameBRSurnames (UsrDat);
HTM_BUTTON_End ();
HTM_DIV_End ();
Frm_EndForm ();
}
if (!Gbl.Usrs.Me.Logged || // Not logged
Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) // It's me
/* Inactive icon to follow/unfollow */
Fol_PutInactiveIconToFollowUnfollow ();
else // It's not me
{
/* Put form to follow / unfollow */
if (Fol_DB_CheckUsrIsFollowerOf (Gbl.Usrs.Me.UsrDat.UsrCod,
UsrDat->UsrCod)) // I follow user
/* Form to unfollow */
Fol_PutIconToUnfollow (UsrDat->EnUsrCod);
else if (ICanView == Usr_CAN) // I do not follow this user and I can follow
/* Form to follow */
Fol_PutIconToFollow (UsrDat->EnUsrCod);
}
HTM_DIV_End ();
HTM_DIV_End ();
2015-03-19 01:59:08 +01:00
}
2017-02-16 20:22:13 +01:00
/*****************************************************************************/
/********************* Write the name of a connected user ********************/
/*****************************************************************************/
static void Fol_WriteRowUsrToFollowOnRightColumn (struct Usr_Data *UsrDat)
2017-02-16 20:22:13 +01:00
{
2017-02-17 01:59:58 +01:00
extern const char *Txt_Another_user_s_profile;
static const char *ClassPhoto[PhoSha_NUM_SHAPES] =
{
[PhoSha_SHAPE_CIRCLE ] = "PHOTOC21x28",
[PhoSha_SHAPE_ELLIPSE ] = "PHOTOE21x28",
[PhoSha_SHAPE_OVAL ] = "PHOTOO21x28",
[PhoSha_SHAPE_RECTANGLE] = "PHOTOR21x28",
};
Usr_Can_t ICanView = Pri_CheckIfICanView (UsrDat->BaPrfVisibility,UsrDat);
2017-02-16 20:22:13 +01:00
/***** Show user's photo *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2017-02-16 20:22:13 +01:00
HTM_TD_Begin ("class=\"CON_PHOTO %s\"",The_GetColorRows ());
if (ICanView == Usr_CAN)
Pho_ShowUsrPhotoIfAllowed (UsrDat,
ClassPhoto[Gbl.Prefs.PhotoShape],Pho_ZOOM);
HTM_TD_End ();
/***** User's name *****/
HTM_TD_Begin ("class=\"CON_NAME_FOLLOW %s\"",
The_GetColorRows ());
if (ICanView == Usr_CAN)
{
/* Put form to go to public profile */
Frm_BeginForm (ActSeeOthPubPrf);
Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_DIV_Begin ("class=\"CON_NAME_FOLLOW CON_CRS LT\""); // Limited width
HTM_BUTTON_Submit_Begin (Txt_Another_user_s_profile,
"class=\"LT BT_LINK\"");
Usr_WriteFirstNameBRSurnames (UsrDat);
HTM_BUTTON_End ();
HTM_DIV_End ();
Frm_EndForm ();
}
HTM_TD_End ();
/***** Icon to follow *****/
HTM_TD_Begin ("class=\"CON_ICON_FOLLOW RM %s\"",
The_GetColorRows ());
if (!Gbl.Usrs.Me.Logged || // Not logged
Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) // It's me
/* Inactive icon to follow/unfollow */
Fol_PutInactiveIconToFollowUnfollow ();
else // It's not me
{
/* Put form to follow / unfollow */
if (Fol_DB_CheckUsrIsFollowerOf (Gbl.Usrs.Me.UsrDat.UsrCod,
UsrDat->UsrCod)) // I follow user
/* Form to unfollow */
Fol_PutIconToUnfollow (UsrDat->EnUsrCod);
else if (ICanView == Usr_CAN) // I do not follow this user and I can follow
/* Form to follow */
Fol_PutIconToFollow (UsrDat->EnUsrCod);
}
HTM_TD_End ();
2017-02-16 20:22:13 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2017-02-16 20:22:13 +01:00
The_ChangeRowColor ();
2017-02-16 20:22:13 +01:00
}
/*****************************************************************************/
/************* Put inactive icon to follow/unfollow another user *************/
2017-02-16 20:22:13 +01:00
/*****************************************************************************/
static void Fol_PutInactiveIconToFollowUnfollow (void)
{
/***** Inactive icon to follow/unfollow *****/
HTM_DIV_Begin ("class=\"FOLLOW_TXT_ICO ICO_HIDDEN\"");
Ico_PutIcon ("user.svg",Ico_BLACK,"","ICO16x16");
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2017-02-16 20:22:13 +01:00
}
/*****************************************************************************/
2019-11-18 14:21:01 +01:00
/*********************** Put icon to follow another user *********************/
2017-02-16 20:22:13 +01:00
/*****************************************************************************/
static void Fol_PutIconToFollow (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1])
2017-02-16 20:22:13 +01:00
{
Frm_BeginForm (ActFolUsr);
Usr_PutParUsrCodEncrypted (EncryptedUsrCod);
HTM_INPUT_IMAGE (Cfg_URL_ICON_PUBLIC,"user-plus.svg",
Act_GetActionText (ActFolUsr),
"class=\"FOLLOW_TXT_ICO ICO16x16 ICO_%s_%s ICO_HIGHLIGHT\"",
Ico_GetPreffix (Ico_BLACK),The_GetSuffix ());
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-02-16 20:22:13 +01:00
}
/*****************************************************************************/
/********************** Put icon to unfollow another user ********************/
/*****************************************************************************/
static void Fol_PutIconToUnfollow (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1])
2017-02-16 20:22:13 +01:00
{
Frm_BeginForm (ActUnfUsr);
Usr_PutParUsrCodEncrypted (EncryptedUsrCod);
HTM_INPUT_IMAGE (Cfg_URL_ICON_PUBLIC,"user-check.svg",
Act_GetActionText (ActUnfUsr),
"class=\"FOLLOW_TXT_ICO ICO_HIGHLIGHT ICO16x16\"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-02-16 20:22:13 +01:00
}
2015-03-18 01:06:43 +01:00
/*****************************************************************************/
/***************************** Follow another user ***************************/
/*****************************************************************************/
2017-02-17 02:42:00 +01:00
void Fol_FollowUsr1 (void)
2015-03-18 01:06:43 +01:00
{
2015-03-19 01:59:08 +01:00
/***** Get user to be followed *****/
if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ())
2015-03-18 01:06:43 +01:00
{
2019-03-12 01:46:40 +01:00
// Follow only if I do not follow him/her
if (!Fol_DB_CheckUsrIsFollowerOf (Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Other.UsrDat.UsrCod))
2019-03-12 01:46:40 +01:00
Fol_FollowUsr (&Gbl.Usrs.Other.UsrDat);
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_SUCCESS,NULL,""); // Txt not used
2015-03-18 01:06:43 +01:00
}
else
2019-03-09 20:12:44 +01:00
Ale_CreateAlertUserNotFoundOrYouDoNotHavePermission ();
2017-02-17 02:42:00 +01:00
}
2015-03-18 02:11:23 +01:00
2017-02-17 02:42:00 +01:00
void Fol_FollowUsr2 (void)
{
2019-03-09 20:12:44 +01:00
if (Ale_GetTypeOfLastAlert () == Ale_SUCCESS)
2019-03-10 00:34:16 +01:00
{
2017-02-17 02:42:00 +01:00
/***** Show user's profile again *****/
if (!Prf_ShowUsrProfile (&Gbl.Usrs.Other.UsrDat))
2019-03-10 00:34:16 +01:00
/* 1) I had permission to follow the user and I've just follow him/her
2) User restricted permission, so now I can not view his/her profile
3) Now I can not view his/her profile ==> show users I follow */
Fol_ListFollowingUsr (&Gbl.Usrs.Me.UsrDat); // List users I follow
}
else
2019-03-09 20:12:44 +01:00
Ale_ShowAlerts (NULL);
2015-03-18 01:06:43 +01:00
}
/*****************************************************************************/
/***************************** Unfollow another user *************************/
/*****************************************************************************/
2017-02-17 02:42:00 +01:00
void Fol_UnfollowUsr1 (void)
2015-03-18 01:06:43 +01:00
{
2015-03-19 01:59:08 +01:00
/***** Get user to be unfollowed *****/
if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ())
2015-03-18 01:06:43 +01:00
{
2015-03-19 12:47:05 +01:00
// Unfollow only if I follow him/her
if (Fol_DB_CheckUsrIsFollowerOf (Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Other.UsrDat.UsrCod))
2019-03-12 01:46:40 +01:00
Fol_UnfollowUsr (&Gbl.Usrs.Other.UsrDat);
2019-02-22 14:04:54 +01:00
2019-03-09 20:12:44 +01:00
Ale_CreateAlert (Ale_SUCCESS,NULL,""); // Txt not used
2017-02-17 02:42:00 +01:00
}
else
2019-03-09 20:12:44 +01:00
Ale_CreateAlertUserNotFoundOrYouDoNotHavePermission ();
2017-02-17 02:42:00 +01:00
}
void Fol_UnfollowUsr2 (void)
{
/***** Get user to be unfollowed *****/
2019-03-09 20:12:44 +01:00
if (Ale_GetTypeOfLastAlert () == Ale_SUCCESS)
2017-02-17 02:42:00 +01:00
{
2015-03-18 02:11:23 +01:00
/***** Show user's profile again *****/
if (!Prf_ShowUsrProfile (&Gbl.Usrs.Other.UsrDat)) // I can not view user's profile
2016-06-12 19:55:33 +02:00
/* 1) I followed a user when I had permission
2) User restricted permission, so now I can not view his/her profile
3) Now I can not view his/her profile ==> show users I follow */
2016-09-28 13:12:11 +02:00
Fol_ListFollowingUsr (&Gbl.Usrs.Me.UsrDat); // List users I follow
2015-03-18 01:06:43 +01:00
}
else
2019-03-09 20:12:44 +01:00
Ale_ShowAlerts (NULL);
2015-03-18 01:06:43 +01:00
}
2015-03-23 10:35:15 +01:00
2019-03-12 01:46:40 +01:00
/*****************************************************************************/
/***************** Request follow/unfollow several users *********************/
/*****************************************************************************/
void Fol_ReqFollowStds (void)
2019-03-12 01:46:40 +01:00
{
2019-04-22 10:10:21 +02:00
Fol_RequestFollowUsrs (ActFolSevStd);
2019-03-12 01:46:40 +01:00
}
void Fol_ReqFollowTchs (void)
2019-03-12 01:46:40 +01:00
{
2019-04-22 10:10:21 +02:00
Fol_RequestFollowUsrs (ActFolSevTch);
2019-03-12 01:46:40 +01:00
}
2019-04-22 10:10:21 +02:00
static void Fol_RequestFollowUsrs (Act_Action_t NextAction)
2019-03-12 01:46:40 +01:00
{
extern const char *Txt_Follow;
extern const char *Txt_Do_you_want_to_follow_the_selected_user_whom_you_do_not_follow_yet;
extern const char *Txt_Do_you_want_to_follow_the_X_selected_users_whom_you_do_not_follow_yet;
unsigned NumFollowed;
unsigned NumNotFollowed;
// List of selected users is already got
/***** Go through list of selected users
getting the number of followed and not followed ****/
Fol_GetFollowedFromSelectedUsrs (&NumFollowed,&NumNotFollowed);
/***** Show question to confirm ****/
if (NumNotFollowed)
{
if (NumNotFollowed == 1)
Ale_ShowAlertAndButton (NextAction,NULL,NULL,
Fol_PutParSelectedUsrsCods,&Gbl.Usrs.Selected,
2019-03-12 01:46:40 +01:00
Btn_CREATE_BUTTON,Txt_Follow,
Ale_QUESTION,Txt_Do_you_want_to_follow_the_selected_user_whom_you_do_not_follow_yet);
else
Ale_ShowAlertAndButton (NextAction,NULL,NULL,
Fol_PutParSelectedUsrsCods,&Gbl.Usrs.Selected,
2019-03-12 01:46:40 +01:00
Btn_CREATE_BUTTON,Txt_Follow,
Ale_QUESTION,Txt_Do_you_want_to_follow_the_X_selected_users_whom_you_do_not_follow_yet,
NumNotFollowed);
}
/***** Free memory used by list of selected users' codes *****/
2019-11-15 03:34:48 +01:00
Usr_FreeListsSelectedEncryptedUsrsCods (&Gbl.Usrs.Selected);
2019-03-12 01:46:40 +01:00
}
void Fol_ReqUnfollowStds (void)
2019-03-12 01:46:40 +01:00
{
2019-04-22 10:10:21 +02:00
Fol_RequestUnfollowUsrs (ActUnfSevStd);
2019-03-12 01:46:40 +01:00
}
void Fol_ReqUnfollowTchs (void)
2019-03-12 01:46:40 +01:00
{
2019-04-22 10:10:21 +02:00
Fol_RequestUnfollowUsrs (ActUnfSevTch);
2019-03-12 01:46:40 +01:00
}
2019-04-22 10:10:21 +02:00
static void Fol_RequestUnfollowUsrs (Act_Action_t NextAction)
2019-03-12 01:46:40 +01:00
{
extern const char *Txt_Do_you_want_to_stop_following_the_selected_user_whom_you_follow;
extern const char *Txt_Do_you_want_to_stop_following_the_X_selected_users_whom_you_follow;
extern const char *Txt_Unfollow;
unsigned NumFollowed;
unsigned NumNotFollowed;
// List of selected users is already got
/***** Go through list of selected users
getting the number of followed and not followed ****/
Fol_GetFollowedFromSelectedUsrs (&NumFollowed,&NumNotFollowed);
/***** Show question to confirm ****/
if (NumFollowed)
{
if (NumFollowed == 1)
Ale_ShowAlertAndButton (NextAction,NULL,NULL,
Fol_PutParSelectedUsrsCods,&Gbl.Usrs.Selected,
2019-03-12 01:46:40 +01:00
Btn_CREATE_BUTTON,Txt_Unfollow,
Ale_QUESTION,Txt_Do_you_want_to_stop_following_the_selected_user_whom_you_follow);
else
Ale_ShowAlertAndButton (NextAction,NULL,NULL,
Fol_PutParSelectedUsrsCods,&Gbl.Usrs.Selected,
2019-03-12 01:46:40 +01:00
Btn_CREATE_BUTTON,Txt_Unfollow,
Ale_QUESTION,Txt_Do_you_want_to_stop_following_the_X_selected_users_whom_you_follow,
NumFollowed);
}
/***** Free memory used by list of selected users' codes *****/
2019-11-15 03:34:48 +01:00
Usr_FreeListsSelectedEncryptedUsrsCods (&Gbl.Usrs.Selected);
}
static void Fol_PutParSelectedUsrsCods (void *SelectedUsrs)
2019-11-15 03:34:48 +01:00
{
2020-04-08 18:18:46 +02:00
if (SelectedUsrs)
Usr_PutParSelectedUsrsCods ((struct Usr_SelectedUsrs *) SelectedUsrs);
2019-03-12 01:46:40 +01:00
}
/*****************************************************************************/
/**** Go through the list getting the number of followed and not followed ****/
/*****************************************************************************/
static void Fol_GetFollowedFromSelectedUsrs (unsigned *NumFollowed,
unsigned *NumNotFollowed)
{
2019-04-11 23:15:40 +02:00
extern const char *Txt_Selected_users_X_Followed_Y_Not_followed_Z;
struct Usr_Data UsrDat;
2019-03-12 01:46:40 +01:00
const char *Ptr;
unsigned NumUsrs = 0;
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Check users to know if I follow them *****/
*NumFollowed = 0;
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
Par_GetNextStrUntilSeparParMult (&Ptr,UsrDat.EnUsrCod,
2019-03-12 01:46:40 +01:00
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (Gbl.Usrs.Me.UsrDat.UsrCod != UsrDat.UsrCod) // Skip me
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS)) // Get from the database the data of the student
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat))
2019-03-12 01:46:40 +01:00
{
/* Check if I follow this user, and update number of users */
if (Fol_DB_CheckUsrIsFollowerOf (Gbl.Usrs.Me.UsrDat.UsrCod,
UsrDat.UsrCod)) // I follow user
2019-03-12 01:46:40 +01:00
(*NumFollowed)++;
NumUsrs++;
}
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
/***** Show alert ****/
*NumNotFollowed = NumUsrs - *NumFollowed;
2019-04-11 23:15:40 +02:00
Ale_ShowAlert (Ale_INFO,Txt_Selected_users_X_Followed_Y_Not_followed_Z,
2019-03-12 01:46:40 +01:00
NumUsrs,*NumFollowed,*NumNotFollowed);
}
/*****************************************************************************/
/********************** Follow/unfollow several users ************************/
/*****************************************************************************/
void Fol_FollowUsrs ()
{
extern const char *Txt_You_have_followed_one_user;
extern const char *Txt_You_have_followed_X_users;
const char *Ptr;
struct Usr_Data UsrDat;
2019-03-12 01:46:40 +01:00
unsigned NumFollowed = 0;
/***** Get list of selected users if not already got *****/
2019-11-15 03:34:48 +01:00
Usr_GetListsSelectedEncryptedUsrsCods (&Gbl.Usrs.Selected);
2019-03-12 01:46:40 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Check users to know if I follow them *****/
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
Par_GetNextStrUntilSeparParMult (&Ptr,UsrDat.EnUsrCod,
2019-03-12 01:46:40 +01:00
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (Gbl.Usrs.Me.UsrDat.UsrCod != UsrDat.UsrCod) // Skip me
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat, // Get user's data from database
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS))
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat))
2019-03-12 01:46:40 +01:00
/* If I don't follow this user ==> follow him/her */
if (!Fol_DB_CheckUsrIsFollowerOf (Gbl.Usrs.Me.UsrDat.UsrCod,
UsrDat.UsrCod))
2019-03-12 01:46:40 +01:00
{
Fol_FollowUsr (&UsrDat);
NumFollowed++;
}
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
/***** Free memory used by list of selected users' codes *****/
2019-11-15 03:34:48 +01:00
Usr_FreeListsSelectedEncryptedUsrsCods (&Gbl.Usrs.Selected);
2019-03-12 01:46:40 +01:00
/***** Show alert *****/
if (NumFollowed == 1)
Ale_ShowAlert (Ale_SUCCESS,Txt_You_have_followed_one_user);
else
Ale_ShowAlert (Ale_SUCCESS,Txt_You_have_followed_X_users,
NumFollowed);
}
void Fol_UnfollowUsrs (void)
{
extern const char *Txt_You_have_stopped_following_one_user;
extern const char *Txt_You_have_stopped_following_X_users;
const char *Ptr;
struct Usr_Data UsrDat;
2019-03-12 01:46:40 +01:00
unsigned NumUnfollowed = 0;
/***** Get list of selected users if not already got *****/
2019-11-15 03:34:48 +01:00
Usr_GetListsSelectedEncryptedUsrsCods (&Gbl.Usrs.Selected);
2019-03-12 01:46:40 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Check users to know if I follow them *****/
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
Par_GetNextStrUntilSeparParMult (&Ptr,UsrDat.EnUsrCod,
2019-03-12 01:46:40 +01:00
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (Gbl.Usrs.Me.UsrDat.UsrCod != UsrDat.UsrCod) // Skip me
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat, // Get user's data from database
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS))
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat))
2019-03-12 01:46:40 +01:00
/* If I follow this user ==> unfollow him/her */
if (Fol_DB_CheckUsrIsFollowerOf (Gbl.Usrs.Me.UsrDat.UsrCod,
UsrDat.UsrCod))
2019-03-12 01:46:40 +01:00
{
Fol_UnfollowUsr (&UsrDat);
NumUnfollowed++;
}
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
/***** Free memory used by list of selected users' codes *****/
2019-11-15 03:34:48 +01:00
Usr_FreeListsSelectedEncryptedUsrsCods (&Gbl.Usrs.Selected);
2019-03-12 01:46:40 +01:00
/***** Show alert *****/
if (NumUnfollowed == 1)
Ale_ShowAlert (Ale_SUCCESS,Txt_You_have_stopped_following_one_user);
else
Ale_ShowAlert (Ale_SUCCESS,Txt_You_have_stopped_following_X_users,
NumUnfollowed);
}
/*****************************************************************************/
/******************************** Follow user ********************************/
/*****************************************************************************/
static void Fol_FollowUsr (const struct Usr_Data *UsrDat)
2019-03-12 01:46:40 +01:00
{
bool CreateNotif;
bool NotifyByEmail;
/***** Avoid wrong cases *****/
if (Gbl.Usrs.Me.UsrDat.UsrCod <= 0 ||
UsrDat->UsrCod <= 0 ||
Gbl.Usrs.Me.UsrDat.UsrCod == UsrDat->UsrCod) // Skip me
return;
/***** Follow user in database *****/
Fol_DB_FollowUsr (UsrDat->UsrCod);
2019-03-12 01:46:40 +01:00
/***** Flush cache *****/
Fol_FlushCacheFollow ();
/***** This follow must be notified by email? *****/
2019-03-19 13:22:14 +01:00
CreateNotif = (UsrDat->NtfEvents.CreateNotif & (1 << Ntf_EVENT_FOLLOWER));
2019-03-12 01:46:40 +01:00
NotifyByEmail = CreateNotif &&
2019-03-19 13:22:14 +01:00
(UsrDat->NtfEvents.SendEmail & (1 << Ntf_EVENT_FOLLOWER));
2019-03-12 01:46:40 +01:00
/***** Create notification for this followed.
If this followed wants to receive notifications by email,
activate the sending of a notification *****/
if (CreateNotif)
Ntf_DB_StoreNotifyEventToUsr (Ntf_EVENT_FOLLOWER,UsrDat->UsrCod,Gbl.Usrs.Me.UsrDat.UsrCod,
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0),
Gbl.Hierarchy.Node[Hie_INS].HieCod,
Gbl.Hierarchy.Node[Hie_CTR].HieCod,
Gbl.Hierarchy.Node[Hie_DEG].HieCod,
Gbl.Hierarchy.Node[Hie_CRS].HieCod);
2019-03-12 01:46:40 +01:00
}
/*****************************************************************************/
/******************************* Unfollow user *******************************/
/*****************************************************************************/
static void Fol_UnfollowUsr (const struct Usr_Data *UsrDat)
2019-03-12 01:46:40 +01:00
{
/***** Avoid wrong cases *****/
if (Gbl.Usrs.Me.UsrDat.UsrCod <= 0 ||
UsrDat->UsrCod <= 0 ||
Gbl.Usrs.Me.UsrDat.UsrCod == UsrDat->UsrCod) // Skip me
return;
/***** Unfollow user in database *****/
Fol_DB_UnfollowUsr (UsrDat->UsrCod);
2019-03-12 01:46:40 +01:00
/***** Flush cache *****/
Fol_FlushCacheFollow ();
}
2015-03-23 10:35:15 +01:00
/*****************************************************************************/
/****** Get and show ranking of users attending to number of followers *******/
/*****************************************************************************/
void Fol_GetAndShowRankingFollowers (void)
{
2018-11-01 19:23:52 +01:00
MYSQL_RES *mysql_res;
unsigned NumUsrs;
2018-11-01 19:23:52 +01:00
2015-03-23 10:35:15 +01:00
/***** Get ranking from database *****/
NumUsrs = Fol_DB_GetRankingFollowers (&mysql_res);
2018-11-01 19:23:52 +01:00
/***** Show ranking *****/
2018-11-01 19:23:52 +01:00
Prf_ShowRankingFigure (&mysql_res,NumUsrs);
2015-03-23 10:35:15 +01:00
}
2015-03-24 00:01:40 +01:00
/*****************************************************************************/
/********************* Get notification of a new follower ********************/
/*****************************************************************************/
2017-03-08 14:12:33 +01:00
void Fol_GetNotifFollower (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
2017-01-15 22:58:26 +01:00
char **ContentStr)
2015-03-24 00:01:40 +01:00
{
2017-03-06 13:01:16 +01:00
SummaryStr[0] = '\0'; // Return nothing on error
2015-03-24 00:01:40 +01:00
if ((*ContentStr = malloc (1)))
2017-01-13 10:49:56 +01:00
*ContentStr[0] = '\0';
2015-03-24 00:01:40 +01:00
}
2015-12-12 02:01:20 +01:00
/*****************************************************************************/
/*********************** Remove user from user follow ************************/
/*****************************************************************************/
void Fol_RemoveUsrFromUsrFollow (long UsrCod)
{
/***** Remove user from followers and followed *****/
Fol_DB_RemoveUsrFromUsrFollow (UsrCod);
2019-02-22 14:04:54 +01:00
/***** Flush cache *****/
Fol_FlushCacheFollow ();
2015-12-12 02:01:20 +01:00
}
/*****************************************************************************/
/************** Get and show number of following and followers ***************/
/*****************************************************************************/
void Fol_GetAndShowFollowStats (void)
{
extern const char *Hlp_ANALYTICS_Figures_followed_followers;
extern const char *Txt_FIGURE_TYPES[Fig_NUM_FIGURES];
extern const char *Txt_Users;
extern const char *Txt_Number_of_users;
extern const char *Txt_PERCENT_of_users;
extern const char *Txt_Followed;
extern const char *Txt_Followers;
extern const char *Txt_FollowPerFollow[2];
unsigned Fol;
unsigned NumUsrsTotal;
unsigned NumUsrs;
double Average;
/***** Begin box and table *****/
Box_BoxTableBegin (Txt_FIGURE_TYPES[Fig_FOLLOW],NULL,NULL,
Hlp_ANALYTICS_Figures_followed_followers,Box_NOT_CLOSABLE,2);
/***** Heading row *****/
HTM_TR_Begin (NULL);
HTM_TH (Txt_Users ,HTM_HEAD_LEFT);
HTM_TH (Txt_Number_of_users ,HTM_HEAD_RIGHT);
HTM_TH (Txt_PERCENT_of_users,HTM_HEAD_RIGHT);
HTM_TR_End ();
/***** Get total number of users *****/
NumUsrsTotal = Usr_GetTotalNumberOfUsers ();
/***** Get total number of following/followers from database *****/
for (Fol = 0;
Fol < 2;
Fol++)
{
NumUsrs = Fol_DB_GetNumFollowinFollowers (Fol);
/***** Write number of followed / followers *****/
HTM_TR_Begin (NULL);
HTM_TD_Txt_Left (Fol == 0 ? Txt_Followed :
Txt_Followers);
HTM_TD_Unsigned (NumUsrs);
HTM_TD_Percentage (NumUsrs,NumUsrsTotal);
HTM_TR_End ();
}
/***** Write number of followed/followers per follower/followed *****/
for (Fol = 0;
Fol < 2;
Fol++)
{
Average = Fol_DB_GetNumFollowedPerFollower (Fol);
/***** Write number of followed per follower *****/
HTM_TR_Begin (NULL);
HTM_TD_Txt_Left (Txt_FollowPerFollow[Fol]);
HTM_TD_Double2Decimals (Average);
HTM_TD_Empty (1);
HTM_TR_End ();
}
/***** End table and box *****/
Box_BoxTableEnd ();
}