2019-03-26 11:53:37 +01:00
|
|
|
|
// swad_setting.c: user's settings / preferences
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
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.
|
2021-02-09 12:43:45 +01:00
|
|
|
|
Copyright (C) 1999-2021 Antonio Ca<EFBFBD>as Vargas
|
2019-03-26 11:53:37 +01:00
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General Public 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 <stdbool.h> // For boolean type
|
2019-12-29 12:39:00 +01:00
|
|
|
|
#include <stddef.h> // For NULL
|
2019-03-26 11:53:37 +01:00
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "swad_box.h"
|
|
|
|
|
#include "swad_calendar.h"
|
|
|
|
|
#include "swad_config.h"
|
|
|
|
|
#include "swad_cookie.h"
|
|
|
|
|
#include "swad_database.h"
|
|
|
|
|
#include "swad_date.h"
|
2020-04-14 17:15:17 +02:00
|
|
|
|
#include "swad_figure.h"
|
2019-03-26 11:53:37 +01:00
|
|
|
|
#include "swad_form.h"
|
|
|
|
|
#include "swad_global.h"
|
2019-10-23 20:07:56 +02:00
|
|
|
|
#include "swad_HTML.h"
|
2019-03-26 11:53:37 +01:00
|
|
|
|
#include "swad_language.h"
|
|
|
|
|
#include "swad_layout.h"
|
|
|
|
|
#include "swad_notification.h"
|
|
|
|
|
#include "swad_menu.h"
|
|
|
|
|
#include "swad_parameter.h"
|
|
|
|
|
#include "swad_privacy.h"
|
|
|
|
|
#include "swad_setting.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************** External global variables from others modules ***************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private constants *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private prototypes ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Set_PutIconsToSelectSideCols (void);
|
2020-04-08 03:41:05 +02:00
|
|
|
|
static void Set_PutIconsSideColumns (__attribute__((unused)) void *Args);
|
2019-03-26 11:53:37 +01:00
|
|
|
|
static void Set_UpdateSideColsOnUsrDataTable (void);
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Edit settings ******************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Set_EditSettings (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Hlp_PROFILE_Settings_internationalization;
|
|
|
|
|
extern const char *Hlp_PROFILE_Settings_design;
|
|
|
|
|
extern const char *Txt_Internationalization;
|
|
|
|
|
extern const char *Txt_Design;
|
|
|
|
|
|
|
|
|
|
/***** Internationalization: language, first day of week, date format *****/
|
2020-03-26 02:54:30 +01:00
|
|
|
|
Box_BoxBegin (NULL,Txt_Internationalization,
|
|
|
|
|
NULL,NULL,
|
2019-03-26 11:53:37 +01:00
|
|
|
|
Hlp_PROFILE_Settings_internationalization,Box_NOT_CLOSABLE);
|
2019-10-24 00:04:40 +02:00
|
|
|
|
|
|
|
|
|
HTM_DIV_Begin ("class=\"FRAME_INLINE\"");
|
2019-03-26 11:53:37 +01:00
|
|
|
|
Lan_PutBoxToSelectLanguage (); // 1. Language
|
2019-10-23 20:07:56 +02:00
|
|
|
|
HTM_DIV_End ();
|
2019-10-24 00:04:40 +02:00
|
|
|
|
|
|
|
|
|
HTM_DIV_Begin ("class=\"FRAME_INLINE\"");
|
2019-03-26 11:53:37 +01:00
|
|
|
|
Cal_PutIconsToSelectFirstDayOfWeek (); // 2. First day of week
|
2019-10-23 20:07:56 +02:00
|
|
|
|
HTM_DIV_End ();
|
2019-10-24 00:04:40 +02:00
|
|
|
|
|
|
|
|
|
HTM_DIV_Begin ("class=\"FRAME_INLINE\"");
|
2019-03-26 11:53:37 +01:00
|
|
|
|
Dat_PutBoxToSelectDateFormat (); // 3. Date format
|
2019-10-23 20:07:56 +02:00
|
|
|
|
HTM_DIV_End ();
|
2019-10-24 00:04:40 +02:00
|
|
|
|
|
2019-10-25 22:48:34 +02:00
|
|
|
|
Box_BoxEnd ();
|
2019-03-26 11:53:37 +01:00
|
|
|
|
|
|
|
|
|
/***** Design: icon set, menu, theme, side columns *****/
|
2020-03-26 02:54:30 +01:00
|
|
|
|
Box_BoxBegin (NULL,Txt_Design,
|
|
|
|
|
NULL,NULL,
|
2019-03-26 11:53:37 +01:00
|
|
|
|
Hlp_PROFILE_Settings_design,Box_NOT_CLOSABLE);
|
2019-10-24 00:04:40 +02:00
|
|
|
|
|
|
|
|
|
HTM_DIV_Begin ("class=\"FRAME_INLINE\"");
|
2019-03-26 11:53:37 +01:00
|
|
|
|
Ico_PutIconsToSelectIconSet (); // 4. Icon set
|
2019-10-23 20:07:56 +02:00
|
|
|
|
HTM_DIV_End ();
|
2019-10-24 00:04:40 +02:00
|
|
|
|
|
|
|
|
|
HTM_DIV_Begin ("class=\"FRAME_INLINE\"");
|
2019-03-26 11:53:37 +01:00
|
|
|
|
Mnu_PutIconsToSelectMenu (); // 5. Menu
|
2019-10-23 20:07:56 +02:00
|
|
|
|
HTM_DIV_End ();
|
2019-10-24 00:04:40 +02:00
|
|
|
|
|
|
|
|
|
HTM_DIV_Begin ("class=\"FRAME_INLINE\"");
|
2019-03-26 11:53:37 +01:00
|
|
|
|
The_PutIconsToSelectTheme (); // 6. Theme
|
2019-10-23 20:07:56 +02:00
|
|
|
|
HTM_DIV_End ();
|
2019-10-24 00:04:40 +02:00
|
|
|
|
|
|
|
|
|
HTM_DIV_Begin ("class=\"FRAME_INLINE\"");
|
2019-03-26 11:53:37 +01:00
|
|
|
|
Set_PutIconsToSelectSideCols (); // 7. Side columns
|
2019-10-23 20:07:56 +02:00
|
|
|
|
HTM_DIV_End ();
|
2019-10-24 00:04:40 +02:00
|
|
|
|
|
2019-10-25 22:48:34 +02:00
|
|
|
|
Box_BoxEnd ();
|
2019-03-26 11:53:37 +01:00
|
|
|
|
|
|
|
|
|
if (Gbl.Usrs.Me.Logged)
|
|
|
|
|
{
|
|
|
|
|
/***** Form to set my settings on privacy *****/
|
|
|
|
|
Pri_EditMyPrivacy ();
|
|
|
|
|
|
|
|
|
|
/***** Form to set my settings on cookies *****/
|
|
|
|
|
Coo_EditMyPrefsOnCookies ();
|
|
|
|
|
|
|
|
|
|
/***** Automatic email to notify of new events *****/
|
|
|
|
|
Ntf_PutFormChangeNotifSentByEMail ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Get settings changed from current IP *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Set_GetSettingsFromIP (void)
|
|
|
|
|
{
|
|
|
|
|
unsigned long NumRows;
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
|
|
|
|
|
if (Gbl.IP[0])
|
|
|
|
|
{
|
|
|
|
|
/***** Get settings from database *****/
|
|
|
|
|
NumRows = DB_QuerySELECT (&mysql_res,"can not get settings",
|
|
|
|
|
"SELECT FirstDayOfWeek,DateFormat,Theme,IconSet,Menu,SideCols"
|
|
|
|
|
" FROM IP_prefs WHERE IP='%s'",
|
|
|
|
|
Gbl.IP);
|
|
|
|
|
if (NumRows)
|
|
|
|
|
{
|
|
|
|
|
if (NumRows != 1)
|
|
|
|
|
Lay_ShowErrorAndExit ("Internal error while getting settings.");
|
|
|
|
|
|
|
|
|
|
/***** Get settings from database *****/
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
|
|
|
|
|
|
|
|
|
/* Get first day of week (row[0]) */
|
|
|
|
|
Gbl.Prefs.FirstDayOfWeek = Cal_GetFirstDayOfWeekFromStr (row[0]);
|
|
|
|
|
|
|
|
|
|
/* Get date format (row[1]) */
|
|
|
|
|
Gbl.Prefs.DateFormat = Dat_GetDateFormatFromStr (row[1]);
|
|
|
|
|
|
|
|
|
|
/* Get theme (row[2]) */
|
|
|
|
|
Gbl.Prefs.Theme = The_GetThemeFromStr (row[2]);
|
|
|
|
|
|
|
|
|
|
/* Get icon set (row[3]) */
|
|
|
|
|
Gbl.Prefs.IconSet = Ico_GetIconSetFromStr (row[3]);
|
|
|
|
|
|
|
|
|
|
/* Get menu (row[4]) */
|
|
|
|
|
Gbl.Prefs.Menu = Mnu_GetMenuFromStr (row[4]);
|
|
|
|
|
|
|
|
|
|
/* Get if user wants to show side columns (row[5]) */
|
|
|
|
|
if (sscanf (row[5],"%u",&Gbl.Prefs.SideCols) == 1)
|
|
|
|
|
{
|
|
|
|
|
if (Gbl.Prefs.SideCols > Lay_SHOW_BOTH_COLUMNS)
|
|
|
|
|
Gbl.Prefs.SideCols = Cfg_DEFAULT_COLUMNS;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Gbl.Prefs.SideCols = Cfg_DEFAULT_COLUMNS;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************ Set settings from current IP ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Set_SetSettingsFromIP (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *The_ThemeId[The_NUM_THEMES];
|
|
|
|
|
extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS];
|
|
|
|
|
|
|
|
|
|
/***** Update settings from current IP in database *****/
|
|
|
|
|
DB_QueryREPLACE ("can not store settings from current IP address",
|
|
|
|
|
"REPLACE INTO IP_prefs"
|
|
|
|
|
" (IP,UsrCod,LastChange,"
|
|
|
|
|
"FirstDayOfWeek,DateFormat,Theme,IconSet,Menu,SideCols)"
|
|
|
|
|
" VALUES"
|
|
|
|
|
" ('%s',%ld,NOW(),"
|
|
|
|
|
"%u,%u,'%s','%s',%u,%u)",
|
|
|
|
|
Gbl.IP,Gbl.Usrs.Me.UsrDat.UsrCod,
|
|
|
|
|
Gbl.Prefs.FirstDayOfWeek,
|
|
|
|
|
(unsigned) Gbl.Prefs.DateFormat,
|
|
|
|
|
The_ThemeId[Gbl.Prefs.Theme],
|
|
|
|
|
Ico_IconSetId[Gbl.Prefs.IconSet],
|
|
|
|
|
(unsigned) Gbl.Prefs.Menu,
|
|
|
|
|
Gbl.Prefs.SideCols);
|
|
|
|
|
|
|
|
|
|
/***** If a user is logged, update its settings in database for all its IP's *****/
|
|
|
|
|
if (Gbl.Usrs.Me.Logged)
|
|
|
|
|
DB_QueryUPDATE ("can not update your settings",
|
|
|
|
|
"UPDATE IP_prefs"
|
|
|
|
|
" SET FirstDayOfWeek=%u,DateFormat=%u,"
|
|
|
|
|
"Theme='%s',IconSet='%s',Menu=%u,SideCols=%u"
|
|
|
|
|
" WHERE UsrCod=%ld",
|
|
|
|
|
Gbl.Prefs.FirstDayOfWeek,
|
|
|
|
|
(unsigned) Gbl.Prefs.DateFormat,
|
|
|
|
|
The_ThemeId[Gbl.Prefs.Theme],
|
|
|
|
|
Ico_IconSetId[Gbl.Prefs.IconSet],
|
|
|
|
|
(unsigned) Gbl.Prefs.Menu,
|
|
|
|
|
Gbl.Prefs.SideCols,
|
|
|
|
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********************** Remove old settings from IP *************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Set_RemoveOldSettingsFromIP (void)
|
|
|
|
|
{
|
|
|
|
|
/***** Remove old settings *****/
|
|
|
|
|
DB_QueryDELETE ("can not remove old settings",
|
|
|
|
|
"DELETE LOW_PRIORITY FROM IP_prefs"
|
|
|
|
|
" WHERE LastChange<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
|
|
|
|
|
Cfg_TIME_TO_DELETE_IP_PREFS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************ Put icons to select the layout of the side columns *************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Set_PutIconsToSelectSideCols (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Hlp_PROFILE_Settings_columns;
|
|
|
|
|
extern const char *Txt_Columns;
|
|
|
|
|
extern const char *Txt_LAYOUT_SIDE_COLUMNS[4];
|
|
|
|
|
unsigned SideCols;
|
|
|
|
|
char Icon[32 + 1];
|
|
|
|
|
|
2020-03-26 02:54:30 +01:00
|
|
|
|
Box_BoxBegin (NULL,Txt_Columns,
|
2020-04-08 03:41:05 +02:00
|
|
|
|
Set_PutIconsSideColumns,NULL,
|
2019-03-26 11:53:37 +01:00
|
|
|
|
Hlp_PROFILE_Settings_columns,Box_NOT_CLOSABLE);
|
2021-03-02 16:47:58 +01:00
|
|
|
|
Set_BeginSettingsHead ();
|
|
|
|
|
Set_BeginOneSettingSelector ();
|
2019-03-26 11:53:37 +01:00
|
|
|
|
for (SideCols = 0;
|
|
|
|
|
SideCols <= Lay_SHOW_BOTH_COLUMNS;
|
|
|
|
|
SideCols++)
|
|
|
|
|
{
|
2019-10-24 00:04:40 +02:00
|
|
|
|
HTM_DIV_Begin ("class=\"%s\"",SideCols == Gbl.Prefs.SideCols ? "PREF_ON" :
|
|
|
|
|
"PREF_OFF");
|
2021-03-02 00:54:26 +01:00
|
|
|
|
Frm_BeginForm (ActChgCol);
|
2019-11-03 13:19:32 +01:00
|
|
|
|
Par_PutHiddenParamUnsigned (NULL,"SideCols",SideCols);
|
2021-02-15 16:25:55 +01:00
|
|
|
|
snprintf (Icon,sizeof (Icon),"layout%u%u_32x20.gif",
|
2019-03-26 11:53:37 +01:00
|
|
|
|
SideCols >> 1,SideCols & 1);
|
|
|
|
|
Ico_PutSettingIconLink (Icon,Txt_LAYOUT_SIDE_COLUMNS[SideCols]);
|
|
|
|
|
Frm_EndForm ();
|
2019-10-23 20:07:56 +02:00
|
|
|
|
HTM_DIV_End ();
|
2019-03-26 11:53:37 +01:00
|
|
|
|
}
|
|
|
|
|
Set_EndOneSettingSelector ();
|
|
|
|
|
Set_EndSettingsHead ();
|
2019-10-25 22:48:34 +02:00
|
|
|
|
Box_BoxEnd ();
|
2019-03-26 11:53:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** Put contextual icons in side-columns setting *****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-08 03:41:05 +02:00
|
|
|
|
static void Set_PutIconsSideColumns (__attribute__((unused)) void *Args)
|
2019-03-26 11:53:37 +01:00
|
|
|
|
{
|
2020-04-08 03:41:05 +02:00
|
|
|
|
/***** Put icon to show a figure *****/
|
|
|
|
|
Fig_PutIconToShowFigure (Fig_SIDE_COLUMNS);
|
2019-03-26 11:53:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********************** Change layout of side columns ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Set_ChangeSideCols (void)
|
|
|
|
|
{
|
|
|
|
|
/***** Get param side-columns *****/
|
|
|
|
|
Gbl.Prefs.SideCols = Set_GetParamSideCols ();
|
|
|
|
|
|
|
|
|
|
/***** Store side colums in database *****/
|
|
|
|
|
if (Gbl.Usrs.Me.Logged)
|
|
|
|
|
Set_UpdateSideColsOnUsrDataTable ();
|
|
|
|
|
|
|
|
|
|
/***** Set settings from current IP *****/
|
|
|
|
|
Set_SetSettingsFromIP ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** Update layout of side colums on user data table **************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Set_UpdateSideColsOnUsrDataTable (void)
|
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not update your setting about side columns",
|
|
|
|
|
"UPDATE usr_data SET SideCols=%u"
|
|
|
|
|
" WHERE UsrCod=%ld",
|
|
|
|
|
Gbl.Prefs.SideCols,Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** Get parameter used to show/hide side columns *****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned Set_GetParamSideCols (void)
|
|
|
|
|
{
|
|
|
|
|
return (unsigned) Par_GetParToUnsignedLong ("SideCols",
|
|
|
|
|
0,
|
|
|
|
|
Lay_SHOW_BOTH_COLUMNS,
|
|
|
|
|
Cfg_DEFAULT_COLUMNS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********** Head to select one or several settings using icons **************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*
|
|
|
|
|
+-- Container for several pref. selectors ---+
|
|
|
|
|
| +One pref.selector+ +One pref.selector+ |
|
|
|
|
|
| | +-----+ +-----+ | | +-----+ +-----+ | |
|
|
|
|
|
| | |Icon | |Icon | | | |Icon | |Icon | | |
|
|
|
|
|
| | |opt.A| |opt.B| | | |opt.A| |opt.B| | |
|
|
|
|
|
| | +-----+ +-----+ | | +-----+ +-----+ | |
|
|
|
|
|
| +-----------------+ +-----------------+ |
|
|
|
|
|
+--------------------------------------------+
|
|
|
|
|
*/
|
2021-03-02 16:47:58 +01:00
|
|
|
|
void Set_BeginSettingsHead (void)
|
2019-03-26 11:53:37 +01:00
|
|
|
|
{
|
2019-12-13 00:36:01 +01:00
|
|
|
|
HTM_DIV_Begin ("class=\"PREF_CONTS\"");
|
2019-03-26 11:53:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Set_EndSettingsHead (void)
|
|
|
|
|
{
|
2019-10-23 20:07:56 +02:00
|
|
|
|
HTM_DIV_End ();
|
2019-03-26 11:53:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 16:47:58 +01:00
|
|
|
|
void Set_BeginOneSettingSelector (void)
|
2019-03-26 11:53:37 +01:00
|
|
|
|
{
|
2019-12-13 00:36:01 +01:00
|
|
|
|
HTM_DIV_Begin ("class=\"PREF_CONT\"");
|
2019-03-26 11:53:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Set_EndOneSettingSelector (void)
|
|
|
|
|
{
|
2019-10-23 20:07:56 +02:00
|
|
|
|
HTM_DIV_End ();
|
2019-03-26 11:53:37 +01:00
|
|
|
|
}
|