2014-12-01 23:55:08 +01:00
|
|
|
|
// swad_theme.c: themes (colour layouts)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
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.
|
2024-02-07 00:40:28 +01:00
|
|
|
|
Copyright (C) 1999-2024 Antonio Ca<EFBFBD>as Vargas
|
2014-12-01 23:55:08 +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 **********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2022-01-03 02:47:16 +01:00
|
|
|
|
#define _GNU_SOURCE // For asprintf
|
|
|
|
|
#include <stdio.h> // For asprintf
|
2022-04-25 18:27:24 +02:00
|
|
|
|
#include <stdlib.h> // For free
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2022-11-06 18:11:10 +01:00
|
|
|
|
#include "swad_action_list.h"
|
2017-06-10 21:38:10 +02:00
|
|
|
|
#include "swad_box.h"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include "swad_config.h"
|
|
|
|
|
#include "swad_database.h"
|
2022-01-03 02:47:16 +01:00
|
|
|
|
#include "swad_error.h"
|
2020-04-14 17:15:17 +02:00
|
|
|
|
#include "swad_figure.h"
|
2018-11-09 20:47:39 +01:00
|
|
|
|
#include "swad_form.h"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include "swad_global.h"
|
2019-10-23 20:07:56 +02:00
|
|
|
|
#include "swad_HTML.h"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include "swad_layout.h"
|
|
|
|
|
#include "swad_parameter.h"
|
2019-03-26 11:53:21 +01:00
|
|
|
|
#include "swad_setting.h"
|
2021-10-24 20:32:09 +02:00
|
|
|
|
#include "swad_setting_database.h"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include "swad_theme.h"
|
2022-01-03 02:47:16 +01:00
|
|
|
|
#include "swad_user_database.h"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************** External global variables from others modules ***************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************************** Private constants **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-03-08 14:12:33 +01:00
|
|
|
|
#define The_MAX_BYTES_THEME_ID 16
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
const char *The_ThemeId[The_NUM_THEMES] =
|
|
|
|
|
{
|
2019-11-22 01:04:03 +01:00
|
|
|
|
[The_THEME_WHITE ] = "white",
|
|
|
|
|
[The_THEME_GREY ] = "grey",
|
|
|
|
|
[The_THEME_PURPLE] = "purple",
|
|
|
|
|
[The_THEME_BLUE ] = "blue",
|
|
|
|
|
[The_THEME_YELLOW] = "yellow",
|
|
|
|
|
[The_THEME_PINK ] = "pink",
|
2021-12-08 14:37:34 +01:00
|
|
|
|
[The_THEME_DARK ] = "dark",
|
2014-12-01 23:55:08 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const char *The_ThemeNames[The_NUM_THEMES] =
|
|
|
|
|
{
|
2019-11-22 01:04:03 +01:00
|
|
|
|
[The_THEME_WHITE ] = "White",
|
|
|
|
|
[The_THEME_GREY ] = "Grey",
|
|
|
|
|
[The_THEME_PURPLE] = "Purple",
|
|
|
|
|
[The_THEME_BLUE ] = "Blue",
|
|
|
|
|
[The_THEME_YELLOW] = "Yellow",
|
|
|
|
|
[The_THEME_PINK ] = "Pink",
|
2021-12-08 14:37:34 +01:00
|
|
|
|
[The_THEME_DARK ] = "Dark",
|
|
|
|
|
};
|
|
|
|
|
|
2016-11-07 13:04:47 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************************** Private prototypes ***************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-08 03:41:05 +02:00
|
|
|
|
static void The_PutIconsTheme (__attribute__((unused)) void *Args);
|
2016-11-07 13:04:47 +01:00
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************ Put icons to select a theme ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void The_PutIconsToSelectTheme (void)
|
|
|
|
|
{
|
2019-03-26 11:53:21 +01:00
|
|
|
|
extern const char *Hlp_PROFILE_Settings_theme;
|
2015-01-01 15:50:45 +01:00
|
|
|
|
extern const char *Txt_Theme_SKIN;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
The_Theme_t Theme;
|
2019-01-12 03:00:59 +01:00
|
|
|
|
char Icon[PATH_MAX + 1];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2024-01-29 09:45:28 +01:00
|
|
|
|
Box_BoxBegin (Txt_Theme_SKIN,The_PutIconsTheme,NULL,
|
2019-03-26 11:53:21 +01:00
|
|
|
|
Hlp_PROFILE_Settings_theme,Box_NOT_CLOSABLE);
|
2024-01-29 09:45:28 +01:00
|
|
|
|
|
2021-10-24 20:32:09 +02:00
|
|
|
|
Set_BeginSettingsHead ();
|
|
|
|
|
Set_BeginOneSettingSelector ();
|
|
|
|
|
for (Theme = (The_Theme_t) 0;
|
|
|
|
|
Theme <= (The_Theme_t) (The_NUM_THEMES - 1);
|
|
|
|
|
Theme++)
|
|
|
|
|
{
|
2022-04-25 19:45:05 +02:00
|
|
|
|
Set_BeginPref (Theme == Gbl.Prefs.Theme);
|
|
|
|
|
Frm_BeginForm (ActChgThe);
|
2023-03-07 09:55:39 +01:00
|
|
|
|
Par_PutParString (NULL,"Theme",The_ThemeId[Theme]);
|
2022-04-25 19:45:05 +02:00
|
|
|
|
snprintf (Icon,sizeof (Icon),"%s/%s/theme_32x20.gif",
|
|
|
|
|
Cfg_ICON_FOLDER_THEMES,The_ThemeId[Theme]);
|
|
|
|
|
Ico_PutSettingIconLink (Icon,Ico_UNCHANGED,The_ThemeNames[Theme]);
|
|
|
|
|
Frm_EndForm ();
|
|
|
|
|
Set_EndPref ();
|
2021-10-24 20:32:09 +02:00
|
|
|
|
}
|
|
|
|
|
Set_EndOneSettingSelector ();
|
|
|
|
|
Set_EndSettingsHead ();
|
2024-01-29 09:45:28 +01:00
|
|
|
|
|
2019-10-25 22:48:34 +02:00
|
|
|
|
Box_BoxEnd ();
|
2016-11-07 13:04:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2019-03-26 11:53:21 +01:00
|
|
|
|
/****************** Put contextual icons in theme setting ********************/
|
2016-11-07 13:04:47 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-08 03:41:05 +02:00
|
|
|
|
static void The_PutIconsTheme (__attribute__((unused)) void *Args)
|
2016-11-07 13:04:47 +01:00
|
|
|
|
{
|
2020-04-08 03:41:05 +02:00
|
|
|
|
/***** Put icon to show a figure *****/
|
|
|
|
|
Fig_PutIconToShowFigure (Fig_THEMES);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************************* Change theme ******************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void The_ChangeTheme (void)
|
|
|
|
|
{
|
|
|
|
|
/***** Get param theme *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Gbl.Prefs.Theme = The_GetParTheme ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Store theme in database *****/
|
|
|
|
|
if (Gbl.Usrs.Me.Logged)
|
2021-10-24 20:32:09 +02:00
|
|
|
|
Set_DB_UpdateMySettingsAboutTheme (The_ThemeId[Gbl.Prefs.Theme]);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2019-03-26 11:53:21 +01:00
|
|
|
|
/***** Set settings from current IP *****/
|
|
|
|
|
Set_SetSettingsFromIP ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Get parameter theme ***************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-10 00:13:55 +01:00
|
|
|
|
The_Theme_t The_GetParTheme (void)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2017-03-08 14:12:33 +01:00
|
|
|
|
char ThemeId[The_MAX_BYTES_THEME_ID + 1];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
The_Theme_t Theme;
|
|
|
|
|
|
2023-03-07 09:55:39 +01:00
|
|
|
|
Par_GetParText ("Theme",ThemeId,The_MAX_BYTES_THEME_ID);
|
2019-12-15 20:02:34 +01:00
|
|
|
|
for (Theme = (The_Theme_t) 0;
|
|
|
|
|
Theme <= (The_Theme_t) (The_NUM_THEMES - 1);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Theme++)
|
|
|
|
|
if (!strcmp (ThemeId,The_ThemeId[Theme]))
|
|
|
|
|
return Theme;
|
|
|
|
|
|
2021-12-02 08:39:18 +01:00
|
|
|
|
return The_THEME_DEFAULT;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************************** Get theme from string **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
The_Theme_t The_GetThemeFromStr (const char *Str)
|
|
|
|
|
{
|
|
|
|
|
The_Theme_t Theme;
|
|
|
|
|
|
2019-12-15 20:02:34 +01:00
|
|
|
|
for (Theme = (The_Theme_t) 0;
|
|
|
|
|
Theme <= (The_Theme_t) (The_NUM_THEMES - 1);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Theme++)
|
|
|
|
|
if (!strcasecmp (Str,The_ThemeId[Theme]))
|
|
|
|
|
return Theme;
|
|
|
|
|
|
2021-12-02 08:39:18 +01:00
|
|
|
|
return The_THEME_DEFAULT;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
2021-12-20 22:43:32 +01:00
|
|
|
|
|
2022-04-05 01:00:24 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Get theme name for CSS class suffix *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static const char *The_CSS_Suffix[The_NUM_THEMES] =
|
|
|
|
|
{
|
|
|
|
|
[The_THEME_WHITE ] = "WHITE",
|
|
|
|
|
[The_THEME_GREY ] = "GREY",
|
|
|
|
|
[The_THEME_PURPLE] = "PURPLE",
|
|
|
|
|
[The_THEME_BLUE ] = "BLUE",
|
|
|
|
|
[The_THEME_YELLOW] = "YELLOW",
|
|
|
|
|
[The_THEME_PINK ] = "PINK",
|
|
|
|
|
[The_THEME_DARK ] = "DARK",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const char *The_GetSuffix (void)
|
|
|
|
|
{
|
|
|
|
|
return The_CSS_Suffix[Gbl.Prefs.Theme];
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-20 22:43:32 +01:00
|
|
|
|
/*****************************************************************************/
|
2022-03-19 02:05:53 +01:00
|
|
|
|
/******** Get background colors for rows depending on selected theme *********/
|
2021-12-20 22:43:32 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2022-09-13 20:26:58 +02:00
|
|
|
|
static unsigned The_RowEvenOdd[3] = // To alternate row colors in listings
|
2022-09-02 23:57:38 +02:00
|
|
|
|
{
|
|
|
|
|
0,
|
2022-09-13 20:26:58 +02:00
|
|
|
|
0,
|
|
|
|
|
0,
|
2022-09-02 23:57:38 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const char *The_ClassColorRows[2][The_NUM_THEMES] =
|
|
|
|
|
{
|
|
|
|
|
[0][The_THEME_WHITE ] = "COLOR0_WHITE",
|
|
|
|
|
[0][The_THEME_GREY ] = "COLOR0_GREY",
|
|
|
|
|
[0][The_THEME_PURPLE] = "COLOR0_PURPLE",
|
|
|
|
|
[0][The_THEME_BLUE ] = "COLOR0_BLUE",
|
|
|
|
|
[0][The_THEME_YELLOW] = "COLOR0_YELLOW",
|
|
|
|
|
[0][The_THEME_PINK ] = "COLOR0_PINK",
|
|
|
|
|
[0][The_THEME_DARK ] = "COLOR0_DARK",
|
|
|
|
|
|
|
|
|
|
[1][The_THEME_WHITE ] = "COLOR1_WHITE",
|
|
|
|
|
[1][The_THEME_GREY ] = "COLOR1_GREY",
|
|
|
|
|
[1][The_THEME_PURPLE] = "COLOR1_PURPLE",
|
|
|
|
|
[1][The_THEME_BLUE ] = "COLOR1_BLUE",
|
|
|
|
|
[1][The_THEME_YELLOW] = "COLOR1_YELLOW",
|
|
|
|
|
[1][The_THEME_PINK ] = "COLOR1_PINK",
|
|
|
|
|
[1][The_THEME_DARK ] = "COLOR1_DARK",
|
|
|
|
|
};
|
2022-03-24 01:18:19 +01:00
|
|
|
|
|
2022-03-19 02:05:53 +01:00
|
|
|
|
const char *The_GetColorRows (void)
|
2021-12-20 22:43:32 +01:00
|
|
|
|
{
|
2022-09-14 23:16:03 +02:00
|
|
|
|
return The_GetColorRows1 (0);
|
2022-09-02 23:57:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 20:26:58 +02:00
|
|
|
|
const char *The_GetColorRows1 (unsigned Level)
|
2022-09-02 23:57:38 +02:00
|
|
|
|
{
|
2022-09-13 20:26:58 +02:00
|
|
|
|
return The_ClassColorRows[The_RowEvenOdd[Level]][Gbl.Prefs.Theme];
|
2022-09-02 23:57:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void The_ResetRowColor (void)
|
|
|
|
|
{
|
2022-09-14 23:16:03 +02:00
|
|
|
|
The_ResetRowColor1 (0);
|
2022-09-02 23:57:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 20:26:58 +02:00
|
|
|
|
void The_ResetRowColor1 (unsigned Level)
|
2022-09-02 23:57:38 +02:00
|
|
|
|
{
|
2022-09-13 20:26:58 +02:00
|
|
|
|
The_RowEvenOdd[Level] = 0;
|
2022-03-24 01:18:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void The_ChangeRowColor (void)
|
|
|
|
|
{
|
2022-09-14 23:16:03 +02:00
|
|
|
|
The_ChangeRowColor1 (0);
|
2022-09-02 23:57:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 20:26:58 +02:00
|
|
|
|
void The_ChangeRowColor1 (unsigned Level)
|
2022-09-02 23:57:38 +02:00
|
|
|
|
{
|
2022-09-13 20:26:58 +02:00
|
|
|
|
The_RowEvenOdd[Level] = 1 - The_RowEvenOdd[Level];
|
2021-12-20 22:43:32 +01:00
|
|
|
|
}
|
2022-01-03 02:47:16 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********** Get and show number of users who have chosen a theme *************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void The_GetAndShowNumUsrsPerTheme (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Hlp_ANALYTICS_Figures_theme;
|
|
|
|
|
extern const char *The_ThemeId[The_NUM_THEMES];
|
|
|
|
|
extern const char *The_ThemeNames[The_NUM_THEMES];
|
|
|
|
|
extern const char *Txt_FIGURE_TYPES[Fig_NUM_FIGURES];
|
|
|
|
|
extern const char *Txt_Theme_SKIN;
|
|
|
|
|
extern const char *Txt_Number_of_users;
|
|
|
|
|
extern const char *Txt_PERCENT_of_users;
|
|
|
|
|
The_Theme_t Theme;
|
|
|
|
|
char *SubQuery;
|
|
|
|
|
char *URL;
|
|
|
|
|
unsigned NumUsrs[The_NUM_THEMES];
|
|
|
|
|
unsigned NumUsrsTotal = 0;
|
|
|
|
|
|
|
|
|
|
/***** Begin box and table *****/
|
2024-01-29 08:47:21 +01:00
|
|
|
|
Box_BoxTableBegin (Txt_FIGURE_TYPES[Fig_THEMES],NULL,NULL,
|
2022-01-03 02:47:16 +01:00
|
|
|
|
Hlp_ANALYTICS_Figures_theme,Box_NOT_CLOSABLE,2);
|
|
|
|
|
|
|
|
|
|
/***** Heading row *****/
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
HTM_TH (Txt_Theme_SKIN ,HTM_HEAD_LEFT);
|
|
|
|
|
HTM_TH (Txt_Number_of_users ,HTM_HEAD_RIGHT);
|
|
|
|
|
HTM_TH (Txt_PERCENT_of_users,HTM_HEAD_RIGHT);
|
|
|
|
|
HTM_TR_End ();
|
|
|
|
|
|
|
|
|
|
/***** For each theme... *****/
|
|
|
|
|
for (Theme = (The_Theme_t) 0;
|
|
|
|
|
Theme <= (The_Theme_t) (The_NUM_THEMES - 1);
|
|
|
|
|
Theme++)
|
|
|
|
|
{
|
|
|
|
|
/* Get number of users who have chosen this theme from database */
|
|
|
|
|
if (asprintf (&SubQuery,"usr_data.Theme='%s'",
|
|
|
|
|
The_ThemeId[Theme]) < 0)
|
|
|
|
|
Err_NotEnoughMemoryExit ();
|
|
|
|
|
NumUsrs[Theme] = Usr_DB_GetNumUsrsWhoChoseAnOption (SubQuery);
|
|
|
|
|
free (SubQuery);
|
|
|
|
|
|
|
|
|
|
/* Update total number of users */
|
|
|
|
|
NumUsrsTotal += NumUsrs[Theme];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Write number of users who have chosen each theme *****/
|
|
|
|
|
for (Theme = (The_Theme_t) 0;
|
|
|
|
|
Theme <= (The_Theme_t) (The_NUM_THEMES - 1);
|
|
|
|
|
Theme++)
|
|
|
|
|
{
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
|
|
|
|
|
HTM_TD_Begin ("class=\"CM\"");
|
|
|
|
|
if (asprintf (&URL,"%s/%s",
|
|
|
|
|
Cfg_URL_ICON_THEMES_PUBLIC,The_ThemeId[Theme]) < 0)
|
|
|
|
|
Err_NotEnoughMemoryExit ();
|
|
|
|
|
HTM_IMG (URL,"theme_32x20.gif",The_ThemeNames[Theme],
|
|
|
|
|
"style=\"width:40px;height:25px;\"");
|
|
|
|
|
free (URL);
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
2023-10-11 22:45:34 +02:00
|
|
|
|
HTM_TD_Unsigned (NumUsrs[Theme]);
|
|
|
|
|
HTM_TD_Percentage (NumUsrs[Theme],NumUsrsTotal);
|
2022-01-03 02:47:16 +01:00
|
|
|
|
|
|
|
|
|
HTM_TR_End ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** End table and box *****/
|
|
|
|
|
Box_BoxTableEnd ();
|
|
|
|
|
}
|