mirror of https://github.com/acanas/swad-core.git
Version 21.36: Oct 18, 2021 New module swad_setting_database for database queries related to user's settings / preferences.
This commit is contained in:
parent
aa77769927
commit
42d013dcd3
5
Makefile
5
Makefile
|
@ -79,9 +79,8 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
|
||||||
swad_report_database.o swad_role.o swad_role_database.o swad_room.o \
|
swad_report_database.o swad_role.o swad_role_database.o swad_room.o \
|
||||||
swad_room_database.o swad_RSS.o \
|
swad_room_database.o swad_RSS.o \
|
||||||
swad_scope.o swad_search.o swad_session.o swad_session_database.o \
|
swad_scope.o swad_search.o swad_session.o swad_session_database.o \
|
||||||
swad_setting.o swad_statistic.o swad_string.o swad_survey.o \
|
swad_setting.o swad_setting_database.o swad_statistic.o swad_string.o \
|
||||||
swad_syllabus.o \
|
swad_survey.o swad_syllabus.o swad_system_config.o \
|
||||||
swad_system_config.o \
|
|
||||||
swad_tab.o swad_tag.o swad_test.o swad_test_config.o \
|
swad_tab.o swad_tag.o swad_test.o swad_test_config.o \
|
||||||
swad_test_import.o swad_test_print.o swad_test_visibility.o \
|
swad_test_import.o swad_test_print.o swad_test_visibility.o \
|
||||||
swad_theme.o \
|
swad_theme.o \
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
#include "swad_report.h"
|
#include "swad_report.h"
|
||||||
#include "swad_session_database.h"
|
#include "swad_session_database.h"
|
||||||
#include "swad_setting.h"
|
#include "swad_setting.h"
|
||||||
|
#include "swad_setting_database.h"
|
||||||
#include "swad_test_print.h"
|
#include "swad_test_print.h"
|
||||||
#include "swad_timeline.h"
|
#include "swad_timeline.h"
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
#include "swad_project_database.h"
|
#include "swad_project_database.h"
|
||||||
#include "swad_role.h"
|
#include "swad_role.h"
|
||||||
#include "swad_setting.h"
|
#include "swad_setting.h"
|
||||||
|
#include "swad_setting_database.h"
|
||||||
#include "swad_string.h"
|
#include "swad_string.h"
|
||||||
#include "swad_timeline.h"
|
#include "swad_timeline.h"
|
||||||
#include "swad_timeline_note.h"
|
#include "swad_timeline_note.h"
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "swad_HTML.h"
|
#include "swad_HTML.h"
|
||||||
#include "swad_parameter.h"
|
#include "swad_parameter.h"
|
||||||
#include "swad_setting.h"
|
#include "swad_setting.h"
|
||||||
|
#include "swad_setting_database.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/************** External global variables from others modules ****************/
|
/************** External global variables from others modules ****************/
|
||||||
|
|
|
@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
|
||||||
|
|
||||||
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
|
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
|
||||||
*/
|
*/
|
||||||
#define Log_PLATFORM_VERSION "SWAD 21.35.1 (2021-10-18)"
|
#define Log_PLATFORM_VERSION "SWAD 21.36 (2021-10-18)"
|
||||||
#define CSS_FILE "swad20.45.css"
|
#define CSS_FILE "swad20.45.css"
|
||||||
#define JS_FILE "swad20.69.1.js"
|
#define JS_FILE "swad20.69.1.js"
|
||||||
/*
|
/*
|
||||||
TODO: Rename CENTRE to CENTER in help wiki.
|
TODO: Rename CENTRE to CENTER in help wiki.
|
||||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||||
|
|
||||||
|
Version 21.36: Oct 18, 2021 New module swad_setting_database for database queries related to user's settings / preferences. (320253 lines)
|
||||||
Version 21.35.1: Oct 18, 2021 Queries moved to module swad_file_database. (320175 lines)
|
Version 21.35.1: Oct 18, 2021 Queries moved to module swad_file_database. (320175 lines)
|
||||||
Version 21.35: Oct 18, 2021 New module swad_file_database for database queries related to files. (320171 lines)
|
Version 21.35: Oct 18, 2021 New module swad_file_database for database queries related to files. (320171 lines)
|
||||||
Version 21.34: Oct 15, 2021 New module swad_session_database for database queries related to sessions. (320081 lines)
|
Version 21.34: Oct 15, 2021 New module swad_session_database for database queries related to sessions. (320081 lines)
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
#include "swad_record_database.h"
|
#include "swad_record_database.h"
|
||||||
#include "swad_search.h"
|
#include "swad_search.h"
|
||||||
#include "swad_setting.h"
|
#include "swad_setting.h"
|
||||||
|
#include "swad_setting_database.h"
|
||||||
#include "swad_survey.h"
|
#include "swad_survey.h"
|
||||||
#include "swad_test.h"
|
#include "swad_test.h"
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "swad_HTML.h"
|
#include "swad_HTML.h"
|
||||||
#include "swad_parameter.h"
|
#include "swad_parameter.h"
|
||||||
#include "swad_setting.h"
|
#include "swad_setting.h"
|
||||||
|
#include "swad_setting_database.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/************** External global variables from others modules ****************/
|
/************** External global variables from others modules ****************/
|
||||||
|
|
|
@ -61,6 +61,7 @@
|
||||||
#include "swad_role.h"
|
#include "swad_role.h"
|
||||||
#include "swad_role_database.h"
|
#include "swad_role_database.h"
|
||||||
#include "swad_setting.h"
|
#include "swad_setting.h"
|
||||||
|
#include "swad_setting_database.h"
|
||||||
#include "swad_test_print.h"
|
#include "swad_test_print.h"
|
||||||
#include "swad_user.h"
|
#include "swad_user.h"
|
||||||
|
|
||||||
|
|
|
@ -25,24 +25,9 @@
|
||||||
/********************************* Headers ***********************************/
|
/********************************* Headers ***********************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
// #include <ctype.h> // For isprint, isspace, etc.
|
|
||||||
// #include <dirent.h> // For scandir, etc.
|
|
||||||
// #include <errno.h> // For errno
|
|
||||||
// #include <linux/limits.h> // For PATH_MAX
|
|
||||||
// #include <stddef.h> // For NULL
|
|
||||||
// #include <stdio.h> // For FILE,fprintf
|
|
||||||
// #include <stdlib.h> // For exit, system, free, etc.
|
|
||||||
// #include <string.h> // For string functions
|
|
||||||
// #include <sys/stat.h> // For mkdir
|
|
||||||
// #include <sys/types.h> // For mkdir
|
|
||||||
// #include <unistd.h> // For unlink
|
|
||||||
|
|
||||||
// #include "swad_config.h"
|
|
||||||
#include "swad_database.h"
|
#include "swad_database.h"
|
||||||
// #include "swad_error.h"
|
|
||||||
#include "swad_global.h"
|
#include "swad_global.h"
|
||||||
#include "swad_file_database.h"
|
#include "swad_file_database.h"
|
||||||
// #include "swad_string.h"
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/************** External global variables from others modules ****************/
|
/************** External global variables from others modules ****************/
|
||||||
|
|
|
@ -28,9 +28,6 @@
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
#include <linux/limits.h> // For PATH_MAX
|
#include <linux/limits.h> // For PATH_MAX
|
||||||
// #include <stdbool.h> // For boolean type
|
|
||||||
// #include <stdio.h> // For FILE
|
|
||||||
// #include <time.h> // For time_t
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/************************** Public types and constants ***********************/
|
/************************** Public types and constants ***********************/
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "swad_layout.h"
|
#include "swad_layout.h"
|
||||||
#include "swad_parameter.h"
|
#include "swad_parameter.h"
|
||||||
#include "swad_setting.h"
|
#include "swad_setting.h"
|
||||||
|
#include "swad_setting_database.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/************** External global variables from others modules ****************/
|
/************** External global variables from others modules ****************/
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "swad_HTML.h"
|
#include "swad_HTML.h"
|
||||||
#include "swad_language.h"
|
#include "swad_language.h"
|
||||||
#include "swad_setting.h"
|
#include "swad_setting.h"
|
||||||
|
#include "swad_setting_database.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/*************** External global variables from others modules ***************/
|
/*************** External global variables from others modules ***************/
|
||||||
|
|
|
@ -61,6 +61,7 @@
|
||||||
#include "swad_notification.h"
|
#include "swad_notification.h"
|
||||||
#include "swad_parameter.h"
|
#include "swad_parameter.h"
|
||||||
#include "swad_setting.h"
|
#include "swad_setting.h"
|
||||||
|
#include "swad_setting_database.h"
|
||||||
#include "swad_tab.h"
|
#include "swad_tab.h"
|
||||||
#include "swad_theme.h"
|
#include "swad_theme.h"
|
||||||
#include "swad_timeline.h"
|
#include "swad_timeline.h"
|
||||||
|
@ -1448,7 +1449,7 @@ void Lay_RefreshNotifsAndConnected (void)
|
||||||
else if (!(Gbl.PID % 101))
|
else if (!(Gbl.PID % 101))
|
||||||
Brw_DB_RemoveExpiredExpandedFolders (); // Remove old expanded folders (from all users)
|
Brw_DB_RemoveExpiredExpandedFolders (); // Remove old expanded folders (from all users)
|
||||||
else if (!(Gbl.PID % 103))
|
else if (!(Gbl.PID % 103))
|
||||||
Set_RemoveOldSettingsFromIP (); // Remove old settings from IP
|
Set_DB_RemoveOldSettingsFromIP (); // Remove old settings from IP
|
||||||
else if (!(Gbl.PID % 107))
|
else if (!(Gbl.PID % 107))
|
||||||
Log_DB_RemoveOldEntriesRecentLog (); // Remove old entries in recent log table, it's a slow query
|
Log_DB_RemoveOldEntriesRecentLog (); // Remove old entries in recent log table, it's a slow query
|
||||||
else if (!(Gbl.PID % 109))
|
else if (!(Gbl.PID % 109))
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "swad_menu.h"
|
#include "swad_menu.h"
|
||||||
#include "swad_parameter.h"
|
#include "swad_parameter.h"
|
||||||
#include "swad_setting.h"
|
#include "swad_setting.h"
|
||||||
|
#include "swad_setting_database.h"
|
||||||
#include "swad_tab.h"
|
#include "swad_tab.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -61,6 +61,7 @@
|
||||||
#include "swad_notification_database.h"
|
#include "swad_notification_database.h"
|
||||||
#include "swad_parameter.h"
|
#include "swad_parameter.h"
|
||||||
#include "swad_setting.h"
|
#include "swad_setting.h"
|
||||||
|
#include "swad_setting_database.h"
|
||||||
#include "swad_survey.h"
|
#include "swad_survey.h"
|
||||||
#include "swad_timeline.h"
|
#include "swad_timeline.h"
|
||||||
#include "swad_timeline_database.h"
|
#include "swad_timeline_database.h"
|
||||||
|
|
|
@ -55,6 +55,7 @@
|
||||||
#include "swad_photo_database.h"
|
#include "swad_photo_database.h"
|
||||||
#include "swad_privacy.h"
|
#include "swad_privacy.h"
|
||||||
#include "swad_setting.h"
|
#include "swad_setting.h"
|
||||||
|
#include "swad_setting_database.h"
|
||||||
#include "swad_statistic.h"
|
#include "swad_statistic.h"
|
||||||
#include "swad_theme.h"
|
#include "swad_theme.h"
|
||||||
#include "swad_user.h"
|
#include "swad_user.h"
|
||||||
|
|
|
@ -59,6 +59,7 @@
|
||||||
#include "swad_role.h"
|
#include "swad_role.h"
|
||||||
#include "swad_role_type.h"
|
#include "swad_role_type.h"
|
||||||
#include "swad_setting.h"
|
#include "swad_setting.h"
|
||||||
|
#include "swad_setting_database.h"
|
||||||
#include "swad_theme.h"
|
#include "swad_theme.h"
|
||||||
#include "swad_timeline.h"
|
#include "swad_timeline.h"
|
||||||
#include "swad_timeline_database.h"
|
#include "swad_timeline_database.h"
|
||||||
|
|
|
@ -25,20 +25,10 @@
|
||||||
/************************************ Headers ********************************/
|
/************************************ Headers ********************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
// #include <mysql/mysql.h> // To access MySQL databases
|
|
||||||
// #include <stddef.h> // For NULL
|
|
||||||
// #include <stdio.h> // For sprintf
|
|
||||||
// #include <string.h> // For string functions
|
|
||||||
|
|
||||||
#include "swad_config.h"
|
#include "swad_config.h"
|
||||||
// #include "swad_connected_database.h"
|
|
||||||
#include "swad_database.h"
|
#include "swad_database.h"
|
||||||
// #include "swad_error.h"
|
|
||||||
#include "swad_global.h"
|
#include "swad_global.h"
|
||||||
#include "swad_pagination.h"
|
#include "swad_pagination.h"
|
||||||
// #include "swad_parameter.h"
|
|
||||||
// #include "swad_session_database.h"
|
|
||||||
// #include "swad_timeline_database.h"
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/***************************** Private constants *****************************/
|
/***************************** Private constants *****************************/
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
/********************************* Headers ***********************************/
|
/********************************* Headers ***********************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
// #include "swad_action.h"
|
|
||||||
#include "swad_pagination.h"
|
#include "swad_pagination.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
389
swad_setting.c
389
swad_setting.c
|
@ -47,6 +47,7 @@
|
||||||
#include "swad_parameter.h"
|
#include "swad_parameter.h"
|
||||||
#include "swad_privacy.h"
|
#include "swad_privacy.h"
|
||||||
#include "swad_setting.h"
|
#include "swad_setting.h"
|
||||||
|
#include "swad_setting_database.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/*************** External global variables from others modules ***************/
|
/*************** External global variables from others modules ***************/
|
||||||
|
@ -64,7 +65,6 @@ extern struct Globals Gbl;
|
||||||
|
|
||||||
static void Set_PutIconsToSelectSideCols (void);
|
static void Set_PutIconsToSelectSideCols (void);
|
||||||
static void Set_PutIconsSideColumns (__attribute__((unused)) void *Args);
|
static void Set_PutIconsSideColumns (__attribute__((unused)) void *Args);
|
||||||
static void Set_UpdateSideColsOnUsrDataTable (void);
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/***************************** Edit settings ******************************/
|
/***************************** Edit settings ******************************/
|
||||||
|
@ -138,56 +138,41 @@ void Set_EditSettings (void)
|
||||||
|
|
||||||
void Set_GetSettingsFromIP (void)
|
void Set_GetSettingsFromIP (void)
|
||||||
{
|
{
|
||||||
unsigned NumRows;
|
|
||||||
MYSQL_RES *mysql_res;
|
MYSQL_RES *mysql_res;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
|
|
||||||
if (Gbl.IP[0])
|
if (Gbl.IP[0])
|
||||||
{
|
{
|
||||||
/***** Get settings from database *****/
|
/***** Get settings from database *****/
|
||||||
NumRows = (unsigned)
|
if (Set_DB_GetSettingsFromIP (&mysql_res) != 1)
|
||||||
DB_QuerySELECT (&mysql_res,"can not get settings",
|
Err_ShowErrorAndExit ("Internal error while getting settings.");
|
||||||
"SELECT FirstDayOfWeek," // row[0]
|
|
||||||
"DateFormat," // row[1]
|
/***** Get settings from database *****/
|
||||||
"Theme," // row[2]
|
row = mysql_fetch_row (mysql_res);
|
||||||
"IconSet," // row[3]
|
|
||||||
"Menu," // row[4]
|
/* Get first day of week (row[0]) */
|
||||||
"SideCols" // row[5]
|
Gbl.Prefs.FirstDayOfWeek = Cal_GetFirstDayOfWeekFromStr (row[0]);
|
||||||
" FROM set_ip_settings"
|
|
||||||
" WHERE IP='%s'",
|
/* Get date format (row[1]) */
|
||||||
Gbl.IP);
|
Gbl.Prefs.DateFormat = Dat_GetDateFormatFromStr (row[1]);
|
||||||
if (NumRows)
|
|
||||||
|
/* 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 (NumRows != 1)
|
if (Gbl.Prefs.SideCols > Lay_SHOW_BOTH_COLUMNS)
|
||||||
Err_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;
|
Gbl.Prefs.SideCols = Cfg_DEFAULT_COLUMNS;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
Gbl.Prefs.SideCols = Cfg_DEFAULT_COLUMNS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,57 +182,12 @@ void Set_GetSettingsFromIP (void)
|
||||||
|
|
||||||
void Set_SetSettingsFromIP (void)
|
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 *****/
|
/***** Update settings from current IP in database *****/
|
||||||
DB_QueryREPLACE ("can not store settings from current IP address",
|
Set_DB_UpdateSettingsFromIP ();
|
||||||
"REPLACE INTO set_ip_settings"
|
|
||||||
" (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 I am logged, update my settings in database for all my IP's *****/
|
||||||
if (Gbl.Usrs.Me.Logged)
|
if (Gbl.Usrs.Me.Logged)
|
||||||
DB_QueryUPDATE ("can not update your settings",
|
Set_DB_UpdateMySettingsFromIP ();
|
||||||
"UPDATE set_ip_settings"
|
|
||||||
" 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 set_ip_settings"
|
|
||||||
" WHERE LastChange<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
|
|
||||||
Cfg_TIME_TO_DELETE_IP_PREFS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -265,24 +205,24 @@ static void Set_PutIconsToSelectSideCols (void)
|
||||||
Box_BoxBegin (NULL,Txt_Columns,
|
Box_BoxBegin (NULL,Txt_Columns,
|
||||||
Set_PutIconsSideColumns,NULL,
|
Set_PutIconsSideColumns,NULL,
|
||||||
Hlp_PROFILE_Settings_columns,Box_NOT_CLOSABLE);
|
Hlp_PROFILE_Settings_columns,Box_NOT_CLOSABLE);
|
||||||
Set_BeginSettingsHead ();
|
Set_BeginSettingsHead ();
|
||||||
Set_BeginOneSettingSelector ();
|
Set_BeginOneSettingSelector ();
|
||||||
for (SideCols = 0;
|
for (SideCols = 0;
|
||||||
SideCols <= Lay_SHOW_BOTH_COLUMNS;
|
SideCols <= Lay_SHOW_BOTH_COLUMNS;
|
||||||
SideCols++)
|
SideCols++)
|
||||||
{
|
{
|
||||||
HTM_DIV_Begin ("class=\"%s\"",SideCols == Gbl.Prefs.SideCols ? "PREF_ON" :
|
HTM_DIV_Begin ("class=\"%s\"",SideCols == Gbl.Prefs.SideCols ? "PREF_ON" :
|
||||||
"PREF_OFF");
|
"PREF_OFF");
|
||||||
Frm_BeginForm (ActChgCol);
|
Frm_BeginForm (ActChgCol);
|
||||||
Par_PutHiddenParamUnsigned (NULL,"SideCols",SideCols);
|
Par_PutHiddenParamUnsigned (NULL,"SideCols",SideCols);
|
||||||
snprintf (Icon,sizeof (Icon),"layout%u%u_32x20.gif",
|
snprintf (Icon,sizeof (Icon),"layout%u%u_32x20.gif",
|
||||||
SideCols >> 1,SideCols & 1);
|
SideCols >> 1,SideCols & 1);
|
||||||
Ico_PutSettingIconLink (Icon,Txt_LAYOUT_SIDE_COLUMNS[SideCols]);
|
Ico_PutSettingIconLink (Icon,Txt_LAYOUT_SIDE_COLUMNS[SideCols]);
|
||||||
Frm_EndForm ();
|
Frm_EndForm ();
|
||||||
HTM_DIV_End ();
|
HTM_DIV_End ();
|
||||||
}
|
}
|
||||||
Set_EndOneSettingSelector ();
|
Set_EndOneSettingSelector ();
|
||||||
Set_EndSettingsHead ();
|
Set_EndSettingsHead ();
|
||||||
Box_BoxEnd ();
|
Box_BoxEnd ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,42 +247,12 @@ void Set_ChangeSideCols (void)
|
||||||
|
|
||||||
/***** Store side colums in database *****/
|
/***** Store side colums in database *****/
|
||||||
if (Gbl.Usrs.Me.Logged)
|
if (Gbl.Usrs.Me.Logged)
|
||||||
Set_UpdateSideColsOnUsrDataTable ();
|
Set_DB_UpdateMySettingsAboutSideCols ();
|
||||||
|
|
||||||
/***** Set settings from current IP *****/
|
/***** Set settings from current IP *****/
|
||||||
Set_SetSettingsFromIP ();
|
Set_SetSettingsFromIP ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/**************** Update my language to the current language *****************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void Set_DB_UpdateMySettingsAboutLanguage (void)
|
|
||||||
{
|
|
||||||
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
|
|
||||||
|
|
||||||
DB_QueryUPDATE ("can not update your language",
|
|
||||||
"UPDATE usr_data"
|
|
||||||
" SET Language='%s'"
|
|
||||||
" WHERE UsrCod=%ld",
|
|
||||||
Lan_STR_LANG_ID[Gbl.Prefs.Language],
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/************** 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 *****************/
|
/************** Get parameter used to show/hide side columns *****************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -355,124 +265,6 @@ unsigned Set_GetParamSideCols (void)
|
||||||
Cfg_DEFAULT_COLUMNS);
|
Cfg_DEFAULT_COLUMNS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/******************** Update my settings about date format *******************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void Set_DB_UpdateMySettingsAboutDateFormat (Dat_Format_t DateFormat)
|
|
||||||
{
|
|
||||||
DB_QueryUPDATE ("can not update your setting about date format",
|
|
||||||
"UPDATE usr_data"
|
|
||||||
" SET DateFormat=%u"
|
|
||||||
" WHERE UsrCod=%ld",
|
|
||||||
(unsigned) DateFormat,
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/***************** Update my settings about first day of week ****************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void Set_DB_UpdateMySettingsAboutFirstDayOfWeek (unsigned FirstDayOfWeek)
|
|
||||||
{
|
|
||||||
DB_QueryUPDATE ("can not update your setting about first day of week",
|
|
||||||
"UPDATE usr_data"
|
|
||||||
" SET FirstDayOfWeek=%u"
|
|
||||||
" WHERE UsrCod=%ld",
|
|
||||||
FirstDayOfWeek,
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/********************* Update my settings about icon set *********************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void Set_DB_UpdateMySettingsAboutIconSet (const char *IconSetId)
|
|
||||||
{
|
|
||||||
DB_QueryUPDATE ("can not update your setting about icon set",
|
|
||||||
"UPDATE usr_data"
|
|
||||||
" SET IconSet='%s'"
|
|
||||||
" WHERE UsrCod=%ld",
|
|
||||||
IconSetId,
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/***************** Update my settings about first day of week ****************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void Set_DB_UpdateMySettingsAboutMenu (Mnu_Menu_t Menu)
|
|
||||||
{
|
|
||||||
DB_QueryUPDATE ("can not update your setting about menu",
|
|
||||||
"UPDATE usr_data"
|
|
||||||
" SET Menu=%u"
|
|
||||||
" WHERE UsrCod=%ld",
|
|
||||||
(unsigned) Menu,
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/***************** Update my settings about photo visibility *****************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void Set_DB_UpdateMySettingsAboutPhoto (void)
|
|
||||||
{
|
|
||||||
extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY];
|
|
||||||
|
|
||||||
DB_QueryUPDATE ("can not update user's settings",
|
|
||||||
"UPDATE usr_data"
|
|
||||||
" SET PhotoVisibility='%s'"
|
|
||||||
" WHERE UsrCod=%ld",
|
|
||||||
Pri_VisibilityDB[Gbl.Usrs.Me.UsrDat.PhotoVisibility],
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/************ Update my settings about public profile visibility *************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void Set_DB_UpdateMySettingsAboutBasicProfile (void)
|
|
||||||
{
|
|
||||||
extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY];
|
|
||||||
|
|
||||||
DB_QueryUPDATE ("can not update your setting"
|
|
||||||
" 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Set_DB_UpdateMySettingsAboutExtendedProfile (void)
|
|
||||||
{
|
|
||||||
extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY];
|
|
||||||
|
|
||||||
DB_QueryUPDATE ("can not update your setting"
|
|
||||||
" about public profile visibility",
|
|
||||||
"UPDATE usr_data"
|
|
||||||
" SET ExPrfVisibility='%s'"
|
|
||||||
" WHERE UsrCod=%ld",
|
|
||||||
Pri_VisibilityDB[Gbl.Usrs.Me.UsrDat.ExPrfVisibility],
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/******************* Update my settings about notify events ******************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void Set_DB_UpdateMySettingsAboutNotifyEvents (void)
|
|
||||||
{
|
|
||||||
DB_QueryUPDATE ("can not update user's settings",
|
|
||||||
"UPDATE usr_data"
|
|
||||||
" SET NotifNtfEvents=%u,"
|
|
||||||
"EmailNtfEvents=%u"
|
|
||||||
" WHERE UsrCod=%ld",
|
|
||||||
Gbl.Usrs.Me.UsrDat.NtfEvents.CreateNotif,
|
|
||||||
Gbl.Usrs.Me.UsrDat.NtfEvents.SendEmail,
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/*********** Head to select one or several settings using icons **************/
|
/*********** Head to select one or several settings using icons **************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -505,86 +297,3 @@ void Set_EndOneSettingSelector (void)
|
||||||
{
|
{
|
||||||
HTM_DIV_End ();
|
HTM_DIV_End ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/************ Register last prefs in current course in database **************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void Set_DB_InsertUsrInCrsSettings (long UsrCod,long CrsCod)
|
|
||||||
{
|
|
||||||
extern const char *Usr_StringsUsrListTypeInDB[Usr_NUM_USR_LIST_TYPES];
|
|
||||||
|
|
||||||
DB_QueryINSERT ("can not register user in course",
|
|
||||||
"INSERT INTO crs_user_settings"
|
|
||||||
" (UsrCod,CrsCod,"
|
|
||||||
"LastDowGrpCod,LastComGrpCod,LastAssGrpCod,"
|
|
||||||
"NumAccTst,LastAccTst,NumQstsLastTst,"
|
|
||||||
"UsrListType,ColsClassPhoto,ListWithPhotos)"
|
|
||||||
" VALUES"
|
|
||||||
" (%ld,%ld,"
|
|
||||||
"-1,-1,-1,"
|
|
||||||
"0,FROM_UNIXTIME(%ld),0,"
|
|
||||||
"'%s',%u,'%c')",
|
|
||||||
UsrCod,
|
|
||||||
CrsCod,
|
|
||||||
(long) (time_t) 0, // The user never accessed to tests in this course
|
|
||||||
Usr_StringsUsrListTypeInDB[Usr_SHOW_USRS_TYPE_DEFAULT],
|
|
||||||
Usr_CLASS_PHOTO_COLS_DEF,
|
|
||||||
Usr_LIST_WITH_PHOTOS_DEF ? 'Y' :
|
|
||||||
'N');
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/******** Update the group of my last access to a file browser zone **********/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void Set_DB_UpdateGrpLastAccZone (const char *FieldNameDB,long GrpCod)
|
|
||||||
{
|
|
||||||
DB_QueryUPDATE ("can not update the group of the last access to a file browser",
|
|
||||||
"UPDATE crs_user_settings"
|
|
||||||
" SET %s=%ld"
|
|
||||||
" WHERE UsrCod=%ld"
|
|
||||||
" AND CrsCod=%ld",
|
|
||||||
FieldNameDB,GrpCod,
|
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
|
||||||
Gbl.Hierarchy.Crs.CrsCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/****************** Remove a user from a courses setting *********************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void Set_DB_RemUsrFromCrsSettings (long UsrCod,long CrsCod)
|
|
||||||
{
|
|
||||||
DB_QueryDELETE ("can not remove a user from a course",
|
|
||||||
"DELETE FROM crs_user_settings"
|
|
||||||
" WHERE UsrCod=%ld"
|
|
||||||
" AND CrsCod=%ld",
|
|
||||||
UsrCod,
|
|
||||||
CrsCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/***************** Remove a user from all courses settings *******************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void Set_DB_RemUsrFromAllCrssSettings (long UsrCod)
|
|
||||||
{
|
|
||||||
DB_QueryDELETE ("can not remove a user from all courses",
|
|
||||||
"DELETE FROM crs_user_settings"
|
|
||||||
" WHERE UsrCod=%ld",
|
|
||||||
UsrCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/*************** Remove all users from settings in a course ******************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void Set_DB_RemAllUsrsFromCrsSettings (long CrsCod)
|
|
||||||
{
|
|
||||||
DB_QueryDELETE ("can not remove users from a course settings",
|
|
||||||
"DELETE FROM crs_user_settings"
|
|
||||||
" WHERE CrsCod=%ld",
|
|
||||||
CrsCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -45,32 +45,13 @@ void Set_EditSettings (void);
|
||||||
|
|
||||||
void Set_GetSettingsFromIP (void);
|
void Set_GetSettingsFromIP (void);
|
||||||
void Set_SetSettingsFromIP (void);
|
void Set_SetSettingsFromIP (void);
|
||||||
void Set_RemoveOldSettingsFromIP (void);
|
|
||||||
|
|
||||||
void Set_ChangeSideCols (void);
|
void Set_ChangeSideCols (void);
|
||||||
unsigned Set_GetParamSideCols (void);
|
unsigned Set_GetParamSideCols (void);
|
||||||
|
|
||||||
void Set_DB_UpdateMySettingsAboutLanguage (void);
|
|
||||||
void Set_DB_UpdateMySettingsAboutDateFormat (Dat_Format_t DateFormat);
|
|
||||||
void Set_DB_UpdateMySettingsAboutFirstDayOfWeek (unsigned FirstDayOfWeek);
|
|
||||||
void Set_DB_UpdateMySettingsAboutIconSet (const char *IconSetId);
|
|
||||||
void Set_DB_UpdateMySettingsAboutMenu (Mnu_Menu_t Menu);
|
|
||||||
void Set_DB_UpdateMySettingsAboutPhoto (void);
|
|
||||||
void Set_DB_UpdateMySettingsAboutBasicProfile (void);
|
|
||||||
void Set_DB_UpdateMySettingsAboutExtendedProfile (void);
|
|
||||||
void Set_DB_UpdateMySettingsAboutNotifyEvents (void);
|
|
||||||
|
|
||||||
void Set_BeginSettingsHead (void);
|
void Set_BeginSettingsHead (void);
|
||||||
void Set_EndSettingsHead (void);
|
void Set_EndSettingsHead (void);
|
||||||
void Set_BeginOneSettingSelector (void);
|
void Set_BeginOneSettingSelector (void);
|
||||||
void Set_EndOneSettingSelector (void);
|
void Set_EndOneSettingSelector (void);
|
||||||
|
|
||||||
void Set_DB_InsertUsrInCrsSettings (long UsrCod,long CrsCod);
|
|
||||||
|
|
||||||
void Set_DB_UpdateGrpLastAccZone (const char *FieldNameDB,long GrpCod);
|
|
||||||
|
|
||||||
void Set_DB_RemUsrFromCrsSettings (long UsrCod,long CrsCod);
|
|
||||||
void Set_DB_RemUsrFromAllCrssSettings (long UsrCod);
|
|
||||||
void Set_DB_RemAllUsrsFromCrsSettings (long CrsCod);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,357 @@
|
||||||
|
// swad_setting.c: user's settings / preferences, operations with database
|
||||||
|
|
||||||
|
/*
|
||||||
|
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-2021 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 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 "swad_database.h"
|
||||||
|
#include "swad_global.h"
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*************** External global variables from others modules ***************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
extern struct Globals Gbl;
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************************** Private constants *****************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************************** Private prototypes ****************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
/**************** Update my language to the current language *****************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_UpdateMySettingsAboutLanguage (void)
|
||||||
|
{
|
||||||
|
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
|
||||||
|
|
||||||
|
DB_QueryUPDATE ("can not update your language",
|
||||||
|
"UPDATE usr_data"
|
||||||
|
" SET Language='%s'"
|
||||||
|
" WHERE UsrCod=%ld",
|
||||||
|
Lan_STR_LANG_ID[Gbl.Prefs.Language],
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************** Update layout of side colums on user data table **************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_UpdateMySettingsAboutSideCols (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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******************** Update my settings about date format *******************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_UpdateMySettingsAboutDateFormat (Dat_Format_t DateFormat)
|
||||||
|
{
|
||||||
|
DB_QueryUPDATE ("can not update your setting about date format",
|
||||||
|
"UPDATE usr_data"
|
||||||
|
" SET DateFormat=%u"
|
||||||
|
" WHERE UsrCod=%ld",
|
||||||
|
(unsigned) DateFormat,
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************** Update my settings about first day of week ****************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_UpdateMySettingsAboutFirstDayOfWeek (unsigned FirstDayOfWeek)
|
||||||
|
{
|
||||||
|
DB_QueryUPDATE ("can not update your setting about first day of week",
|
||||||
|
"UPDATE usr_data"
|
||||||
|
" SET FirstDayOfWeek=%u"
|
||||||
|
" WHERE UsrCod=%ld",
|
||||||
|
FirstDayOfWeek,
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/********************* Update my settings about icon set *********************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_UpdateMySettingsAboutIconSet (const char *IconSetId)
|
||||||
|
{
|
||||||
|
DB_QueryUPDATE ("can not update your setting about icon set",
|
||||||
|
"UPDATE usr_data"
|
||||||
|
" SET IconSet='%s'"
|
||||||
|
" WHERE UsrCod=%ld",
|
||||||
|
IconSetId,
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************** Update my settings about first day of week ****************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_UpdateMySettingsAboutMenu (Mnu_Menu_t Menu)
|
||||||
|
{
|
||||||
|
DB_QueryUPDATE ("can not update your setting about menu",
|
||||||
|
"UPDATE usr_data"
|
||||||
|
" SET Menu=%u"
|
||||||
|
" WHERE UsrCod=%ld",
|
||||||
|
(unsigned) Menu,
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************** Update my settings about photo visibility *****************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_UpdateMySettingsAboutPhoto (void)
|
||||||
|
{
|
||||||
|
extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY];
|
||||||
|
|
||||||
|
DB_QueryUPDATE ("can not update user's settings",
|
||||||
|
"UPDATE usr_data"
|
||||||
|
" SET PhotoVisibility='%s'"
|
||||||
|
" WHERE UsrCod=%ld",
|
||||||
|
Pri_VisibilityDB[Gbl.Usrs.Me.UsrDat.PhotoVisibility],
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************ Update my settings about public profile visibility *************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_UpdateMySettingsAboutBasicProfile (void)
|
||||||
|
{
|
||||||
|
extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY];
|
||||||
|
|
||||||
|
DB_QueryUPDATE ("can not update your setting"
|
||||||
|
" 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Set_DB_UpdateMySettingsAboutExtendedProfile (void)
|
||||||
|
{
|
||||||
|
extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY];
|
||||||
|
|
||||||
|
DB_QueryUPDATE ("can not update your setting"
|
||||||
|
" about public profile visibility",
|
||||||
|
"UPDATE usr_data"
|
||||||
|
" SET ExPrfVisibility='%s'"
|
||||||
|
" WHERE UsrCod=%ld",
|
||||||
|
Pri_VisibilityDB[Gbl.Usrs.Me.UsrDat.ExPrfVisibility],
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******************* Update my settings about notify events ******************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_UpdateMySettingsAboutNotifyEvents (void)
|
||||||
|
{
|
||||||
|
DB_QueryUPDATE ("can not update user's settings",
|
||||||
|
"UPDATE usr_data"
|
||||||
|
" SET NotifNtfEvents=%u,"
|
||||||
|
"EmailNtfEvents=%u"
|
||||||
|
" WHERE UsrCod=%ld",
|
||||||
|
Gbl.Usrs.Me.UsrDat.NtfEvents.CreateNotif,
|
||||||
|
Gbl.Usrs.Me.UsrDat.NtfEvents.SendEmail,
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************ Register last prefs in current course in database **************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_InsertUsrInCrsSettings (long UsrCod,long CrsCod)
|
||||||
|
{
|
||||||
|
extern const char *Usr_StringsUsrListTypeInDB[Usr_NUM_USR_LIST_TYPES];
|
||||||
|
|
||||||
|
DB_QueryINSERT ("can not register user in course",
|
||||||
|
"INSERT INTO crs_user_settings"
|
||||||
|
" (UsrCod,CrsCod,"
|
||||||
|
"LastDowGrpCod,LastComGrpCod,LastAssGrpCod,"
|
||||||
|
"NumAccTst,LastAccTst,NumQstsLastTst,"
|
||||||
|
"UsrListType,ColsClassPhoto,ListWithPhotos)"
|
||||||
|
" VALUES"
|
||||||
|
" (%ld,%ld,"
|
||||||
|
"-1,-1,-1,"
|
||||||
|
"0,FROM_UNIXTIME(%ld),0,"
|
||||||
|
"'%s',%u,'%c')",
|
||||||
|
UsrCod,
|
||||||
|
CrsCod,
|
||||||
|
(long) (time_t) 0, // The user never accessed to tests in this course
|
||||||
|
Usr_StringsUsrListTypeInDB[Usr_SHOW_USRS_TYPE_DEFAULT],
|
||||||
|
Usr_CLASS_PHOTO_COLS_DEF,
|
||||||
|
Usr_LIST_WITH_PHOTOS_DEF ? 'Y' :
|
||||||
|
'N');
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******** Update the group of my last access to a file browser zone **********/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_UpdateGrpLastAccZone (const char *FieldNameDB,long GrpCod)
|
||||||
|
{
|
||||||
|
DB_QueryUPDATE ("can not update the group of the last access to a file browser",
|
||||||
|
"UPDATE crs_user_settings"
|
||||||
|
" SET %s=%ld"
|
||||||
|
" WHERE UsrCod=%ld"
|
||||||
|
" AND CrsCod=%ld",
|
||||||
|
FieldNameDB,GrpCod,
|
||||||
|
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||||
|
Gbl.Hierarchy.Crs.CrsCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/****************** Remove a user from a courses setting *********************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_RemUsrFromCrsSettings (long UsrCod,long CrsCod)
|
||||||
|
{
|
||||||
|
DB_QueryDELETE ("can not remove a user from a course",
|
||||||
|
"DELETE FROM crs_user_settings"
|
||||||
|
" WHERE UsrCod=%ld"
|
||||||
|
" AND CrsCod=%ld",
|
||||||
|
UsrCod,
|
||||||
|
CrsCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************** Remove a user from all courses settings *******************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_RemUsrFromAllCrssSettings (long UsrCod)
|
||||||
|
{
|
||||||
|
DB_QueryDELETE ("can not remove a user from all courses",
|
||||||
|
"DELETE FROM crs_user_settings"
|
||||||
|
" WHERE UsrCod=%ld",
|
||||||
|
UsrCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*************** Remove all users from settings in a course ******************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_RemAllUsrsFromCrsSettings (long CrsCod)
|
||||||
|
{
|
||||||
|
DB_QueryDELETE ("can not remove users from a course settings",
|
||||||
|
"DELETE FROM crs_user_settings"
|
||||||
|
" WHERE CrsCod=%ld",
|
||||||
|
CrsCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/**************** Update settings from current IP in database ****************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_UpdateSettingsFromIP (void)
|
||||||
|
{
|
||||||
|
extern const char *The_ThemeId[The_NUM_THEMES];
|
||||||
|
extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS];
|
||||||
|
|
||||||
|
DB_QueryREPLACE ("can not store settings from current IP address",
|
||||||
|
"REPLACE INTO set_ip_settings"
|
||||||
|
" (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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*************** Update my settings from current IP in database **************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_UpdateMySettingsFromIP (void)
|
||||||
|
{
|
||||||
|
extern const char *The_ThemeId[The_NUM_THEMES];
|
||||||
|
extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS];
|
||||||
|
|
||||||
|
DB_QueryUPDATE ("can not update your settings",
|
||||||
|
"UPDATE set_ip_settings"
|
||||||
|
" 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******************** Get settings changed from current IP *******************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Set_DB_GetSettingsFromIP (MYSQL_RES **mysql_res)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get settings",
|
||||||
|
"SELECT FirstDayOfWeek," // row[0]
|
||||||
|
"DateFormat," // row[1]
|
||||||
|
"Theme," // row[2]
|
||||||
|
"IconSet," // row[3]
|
||||||
|
"Menu," // row[4]
|
||||||
|
"SideCols" // row[5]
|
||||||
|
" FROM set_ip_settings"
|
||||||
|
" WHERE IP='%s'",
|
||||||
|
Gbl.IP);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*********************** Remove old settings from IP *************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Set_DB_RemoveOldSettingsFromIP (void)
|
||||||
|
{
|
||||||
|
/***** Remove old settings *****/
|
||||||
|
DB_QueryDELETE ("can not remove old settings",
|
||||||
|
"DELETE LOW_PRIORITY FROM set_ip_settings"
|
||||||
|
" WHERE LastChange<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
|
||||||
|
Cfg_TIME_TO_DELETE_IP_PREFS);
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
// swad_setting_database.h: user's settings / preferences, operations with database
|
||||||
|
|
||||||
|
#ifndef _SWAD_SET_DB
|
||||||
|
#define _SWAD_SET_DB
|
||||||
|
/*
|
||||||
|
SWAD (Shared Workspace At a Distance in Spanish),
|
||||||
|
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-2021 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 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 ***********************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************************** Public constants ******************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******************************* Public types ********************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************************** Public prototypes *****************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
//--------------------------- Global user settings ----------------------------
|
||||||
|
void Set_DB_UpdateMySettingsAboutLanguage (void);
|
||||||
|
void Set_DB_UpdateMySettingsAboutSideCols (void);
|
||||||
|
void Set_DB_UpdateMySettingsAboutDateFormat (Dat_Format_t DateFormat);
|
||||||
|
void Set_DB_UpdateMySettingsAboutFirstDayOfWeek (unsigned FirstDayOfWeek);
|
||||||
|
void Set_DB_UpdateMySettingsAboutIconSet (const char *IconSetId);
|
||||||
|
void Set_DB_UpdateMySettingsAboutMenu (Mnu_Menu_t Menu);
|
||||||
|
void Set_DB_UpdateMySettingsAboutPhoto (void);
|
||||||
|
void Set_DB_UpdateMySettingsAboutBasicProfile (void);
|
||||||
|
void Set_DB_UpdateMySettingsAboutExtendedProfile (void);
|
||||||
|
void Set_DB_UpdateMySettingsAboutNotifyEvents (void);
|
||||||
|
|
||||||
|
//-------------------- User settings in the current course --------------------
|
||||||
|
void Set_DB_InsertUsrInCrsSettings (long UsrCod,long CrsCod);
|
||||||
|
|
||||||
|
void Set_DB_UpdateGrpLastAccZone (const char *FieldNameDB,long GrpCod);
|
||||||
|
|
||||||
|
void Set_DB_RemUsrFromCrsSettings (long UsrCod,long CrsCod);
|
||||||
|
void Set_DB_RemUsrFromAllCrssSettings (long UsrCod);
|
||||||
|
void Set_DB_RemAllUsrsFromCrsSettings (long CrsCod);
|
||||||
|
|
||||||
|
//------------------- IP settings (when no user logged) -----------------------
|
||||||
|
void Set_DB_UpdateSettingsFromIP (void);
|
||||||
|
void Set_DB_UpdateMySettingsFromIP (void);
|
||||||
|
|
||||||
|
unsigned Set_DB_GetSettingsFromIP (MYSQL_RES **mysql_res);
|
||||||
|
|
||||||
|
void Set_DB_RemoveOldSettingsFromIP (void);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue