2021-02-11 13:27:44 +01:00
|
|
|
|
// swad_timeline_who.c: select users whom timeline is displayed
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
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.
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Copyright (C) 1999-2023 Antonio Ca<EFBFBD>as Vargas
|
2021-02-11 13:27:44 +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 *********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2022-11-06 18:11:10 +01:00
|
|
|
|
#include "swad_action_list.h"
|
2022-10-19 18:07:49 +02:00
|
|
|
|
#include "swad_alert.h"
|
2021-02-11 13:27:44 +01:00
|
|
|
|
#include "swad_database.h"
|
|
|
|
|
#include "swad_follow.h"
|
|
|
|
|
#include "swad_global.h"
|
2021-02-11 13:40:52 +01:00
|
|
|
|
#include "swad_parameter.h"
|
2021-02-11 13:27:44 +01:00
|
|
|
|
#include "swad_setting.h"
|
|
|
|
|
#include "swad_timeline.h"
|
2021-03-01 16:54:18 +01:00
|
|
|
|
#include "swad_timeline_database.h"
|
2021-02-11 13:40:52 +01:00
|
|
|
|
#include "swad_timeline_who.h"
|
2021-02-11 13:27:44 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** External global variables from others modules ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************* Private global variables **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-11-12 01:12:15 +01:00
|
|
|
|
Usr_Who_t Tml_GlobalWho;
|
2021-02-11 13:27:44 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private prototypes ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
static Usr_Who_t TmlWho_GetWhoFromDB (void);
|
2021-02-11 13:27:44 +01:00
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
static void TmlWho_SetGlobalWho (Usr_Who_t Who);
|
2021-02-11 13:27:44 +01:00
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
static void TmlWho_ShowWarningYouDontFollowAnyUser (void);
|
2021-02-11 13:27:44 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******** Show form to select users whom public activity is displayed ********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void TmlWho_PutFormWho (struct Tml_Timeline *Timeline)
|
2021-02-11 13:27:44 +01:00
|
|
|
|
{
|
|
|
|
|
Usr_Who_t Who;
|
|
|
|
|
unsigned Mask = 1 << Usr_WHO_ME |
|
|
|
|
|
1 << Usr_WHO_FOLLOWED |
|
|
|
|
|
1 << Usr_WHO_ALL;
|
|
|
|
|
|
|
|
|
|
/***** Setting selector for which users *****/
|
2021-03-02 16:47:58 +01:00
|
|
|
|
Set_BeginSettingsHead ();
|
|
|
|
|
Set_BeginOneSettingSelector ();
|
|
|
|
|
for (Who = (Usr_Who_t) 0;
|
|
|
|
|
Who <= (Usr_Who_t) (Usr_NUM_WHO - 1);
|
|
|
|
|
Who++)
|
|
|
|
|
if (Mask & (1 << Who))
|
|
|
|
|
{
|
2022-04-25 19:45:05 +02:00
|
|
|
|
Set_BeginPref (Who == Timeline->Who);
|
|
|
|
|
Frm_BeginForm (ActSeeGblTL);
|
2023-03-07 09:55:39 +01:00
|
|
|
|
Par_PutParUnsigned (NULL,"Who",(unsigned) Who);
|
2022-04-25 19:45:05 +02:00
|
|
|
|
Usr_PutWhoIcon (Who);
|
|
|
|
|
Frm_EndForm ();
|
|
|
|
|
Set_EndPref ();
|
2021-03-02 16:47:58 +01:00
|
|
|
|
}
|
|
|
|
|
Set_EndOneSettingSelector ();
|
2021-02-11 13:27:44 +01:00
|
|
|
|
Set_EndSettingsHead ();
|
|
|
|
|
|
|
|
|
|
/***** Show warning if I do not follow anyone *****/
|
|
|
|
|
if (Timeline->Who == Usr_WHO_FOLLOWED)
|
2021-12-31 14:51:44 +01:00
|
|
|
|
TmlWho_ShowWarningYouDontFollowAnyUser ();
|
2021-02-11 13:27:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********* Get parameter with which users to view in global timeline *********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-10 00:13:55 +01:00
|
|
|
|
void TmlWho_GetParWho (void)
|
2021-02-11 13:27:44 +01:00
|
|
|
|
{
|
|
|
|
|
Usr_Who_t Who;
|
|
|
|
|
|
|
|
|
|
/***** Get which users I want to see *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Who = Usr_GetParWho ();
|
2021-02-11 13:27:44 +01:00
|
|
|
|
|
|
|
|
|
/***** If parameter Who is not present, get it from database *****/
|
|
|
|
|
if (Who == Usr_WHO_UNKNOWN)
|
2021-12-31 14:51:44 +01:00
|
|
|
|
Who = TmlWho_GetWhoFromDB ();
|
2021-02-11 13:27:44 +01:00
|
|
|
|
|
|
|
|
|
/***** If parameter Who is unknown, set it to default *****/
|
|
|
|
|
if (Who == Usr_WHO_UNKNOWN)
|
2021-12-31 14:51:44 +01:00
|
|
|
|
Who = TmlWho_DEFAULT_WHO;
|
2021-02-11 13:27:44 +01:00
|
|
|
|
|
|
|
|
|
/***** Set global variable *****/
|
2021-12-31 14:51:44 +01:00
|
|
|
|
TmlWho_SetGlobalWho (Who);
|
2021-02-11 13:27:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********* Get which users to view in global timeline from database **********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
static Usr_Who_t TmlWho_GetWhoFromDB (void)
|
2021-02-11 13:27:44 +01:00
|
|
|
|
{
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
unsigned UnsignedNum;
|
|
|
|
|
Usr_Who_t Who = Usr_WHO_UNKNOWN;
|
|
|
|
|
|
|
|
|
|
/***** Get which users from database *****/
|
2021-03-04 17:47:08 +01:00
|
|
|
|
if (Tml_DB_GetWho (&mysql_res) == 1)
|
2021-02-11 13:27:44 +01:00
|
|
|
|
{
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
|
|
|
|
|
|
|
|
|
/* Get who */
|
|
|
|
|
if (sscanf (row[0],"%u",&UnsignedNum) == 1)
|
|
|
|
|
if (UnsignedNum < Usr_NUM_WHO)
|
|
|
|
|
Who = (Usr_Who_t) UnsignedNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Free structure that stores the query result *****/
|
|
|
|
|
DB_FreeMySQLResult (&mysql_res);
|
|
|
|
|
|
|
|
|
|
return Who;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******** Save which users to view in global timeline into database **********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void TmlWho_SaveWhoInDB (struct Tml_Timeline *Timeline)
|
2021-02-11 13:27:44 +01:00
|
|
|
|
{
|
2021-02-23 09:17:09 +01:00
|
|
|
|
if (Gbl.Usrs.Me.Logged) // Save only if I am logged
|
2021-02-11 13:27:44 +01:00
|
|
|
|
{
|
|
|
|
|
if (Timeline->Who == Usr_WHO_UNKNOWN)
|
2021-12-31 14:51:44 +01:00
|
|
|
|
Timeline->Who = TmlWho_DEFAULT_WHO;
|
2021-02-11 13:27:44 +01:00
|
|
|
|
|
|
|
|
|
/***** Update which users in database *****/
|
|
|
|
|
// Who is stored in usr_last for next time I log in
|
2021-03-04 17:47:08 +01:00
|
|
|
|
Tml_DB_UpdateWho (Timeline->Who);
|
2021-02-11 13:27:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**** Set/get global variable with which users to view in global timeline ****/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
static void TmlWho_SetGlobalWho (Usr_Who_t Who)
|
2021-02-11 13:27:44 +01:00
|
|
|
|
{
|
2021-11-12 01:12:15 +01:00
|
|
|
|
Tml_GlobalWho = Who;
|
2021-02-11 13:27:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
Usr_Who_t TmlWho_GetGlobalWho (void)
|
2021-02-11 13:27:44 +01:00
|
|
|
|
{
|
2021-11-12 01:12:15 +01:00
|
|
|
|
return Tml_GlobalWho;
|
2021-02-11 13:27:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********* Get parameter with which users to view in global timeline *********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
static void TmlWho_ShowWarningYouDontFollowAnyUser (void)
|
2021-02-11 13:27:44 +01:00
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_You_dont_follow_any_user;
|
|
|
|
|
unsigned NumFollowing;
|
|
|
|
|
unsigned NumFollowers;
|
|
|
|
|
|
|
|
|
|
/***** Check if I follow someone *****/
|
|
|
|
|
Fol_GetNumFollow (Gbl.Usrs.Me.UsrDat.UsrCod,&NumFollowing,&NumFollowers);
|
|
|
|
|
if (!NumFollowing)
|
|
|
|
|
{
|
|
|
|
|
/***** Show warning if I do not follow anyone *****/
|
|
|
|
|
Ale_ShowAlert (Ale_WARNING,Txt_You_dont_follow_any_user);
|
|
|
|
|
|
|
|
|
|
/***** Contextual menu *****/
|
|
|
|
|
Mnu_ContextMenuBegin ();
|
2021-03-02 16:47:58 +01:00
|
|
|
|
Fol_PutLinkWhoToFollow (); // Users to follow
|
2021-02-11 13:27:44 +01:00
|
|
|
|
Mnu_ContextMenuEnd ();
|
|
|
|
|
}
|
|
|
|
|
}
|