swad-core/swad_theme.c

419 lines
14 KiB
C
Raw Normal View History

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.
2021-02-09 12:43:45 +01:00
Copyright (C) 1999-2021 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 **********************************/
/*****************************************************************************/
#include <string.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"
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"
2014-12-01 23:55:08 +01:00
#include "swad_theme.h"
/*****************************************************************************/
/*************** 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",
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",
2014-12-01 23:55:08 +01:00
};
const char *The_TabOnBgColors[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "TAB_ON_WHITE",
[The_THEME_GREY ] = "TAB_ON_GREY",
[The_THEME_PURPLE] = "TAB_ON_PURPLE",
[The_THEME_BLUE ] = "TAB_ON_BLUE",
[The_THEME_YELLOW] = "TAB_ON_YELLOW",
[The_THEME_PINK ] = "TAB_ON_PINK",
2014-12-01 23:55:08 +01:00
};
2019-11-22 01:04:03 +01:00
2014-12-01 23:55:08 +01:00
const char *The_TabOffBgColors[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "TAB_OFF_WHITE",
[The_THEME_GREY ] = "TAB_OFF_GREY",
[The_THEME_PURPLE] = "TAB_OFF_PURPLE",
[The_THEME_BLUE ] = "TAB_OFF_BLUE",
[The_THEME_YELLOW] = "TAB_OFF_YELLOW",
[The_THEME_PINK ] = "TAB_OFF_PINK",
2014-12-01 23:55:08 +01:00
};
2016-03-22 01:26:00 +01:00
const char *The_ClassTagline[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "BT_LINK TAGLINE_WHITE",
[The_THEME_GREY ] = "BT_LINK TAGLINE_GREY",
[The_THEME_PURPLE] = "BT_LINK TAGLINE_PURPLE",
[The_THEME_BLUE ] = "BT_LINK TAGLINE_BLUE",
[The_THEME_YELLOW] = "BT_LINK TAGLINE_YELLOW",
[The_THEME_PINK ] = "BT_LINK TAGLINE_PINK",
2016-03-22 01:26:00 +01:00
};
2014-12-01 23:55:08 +01:00
const char *The_ClassNotif[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "BT_LINK NOTIF_WHITE",
[The_THEME_GREY ] = "BT_LINK NOTIF_GREY",
[The_THEME_PURPLE] = "BT_LINK NOTIF_PURPLE",
[The_THEME_BLUE ] = "BT_LINK NOTIF_BLUE",
[The_THEME_YELLOW] = "BT_LINK NOTIF_YELLOW",
[The_THEME_PINK ] = "BT_LINK NOTIF_PINK",
2014-12-01 23:55:08 +01:00
};
const char *The_ClassUsr[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "USR_WHITE",
[The_THEME_GREY ] = "USR_GREY",
[The_THEME_PURPLE] = "USR_PURPLE",
[The_THEME_BLUE ] = "USR_BLUE",
[The_THEME_YELLOW] = "USR_YELLOW",
[The_THEME_PINK ] = "USR_PINK",
2014-12-01 23:55:08 +01:00
};
2015-11-30 12:58:19 +01:00
const char *The_ClassBreadcrumb[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "BC_WHITE",
[The_THEME_GREY ] = "BC_GREY",
[The_THEME_PURPLE] = "BC_PURPLE",
[The_THEME_BLUE ] = "BC_BLUE",
[The_THEME_YELLOW] = "BC_YELLOW",
[The_THEME_PINK ] = "BC_PINK",
2014-12-01 23:55:08 +01:00
};
const char *The_ClassCourse[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "MAIN_TITLE_WHITE",
[The_THEME_GREY ] = "MAIN_TITLE_GREY",
[The_THEME_PURPLE] = "MAIN_TITLE_PURPLE",
[The_THEME_BLUE ] = "MAIN_TITLE_BLUE",
[The_THEME_YELLOW] = "MAIN_TITLE_YELLOW",
[The_THEME_PINK ] = "MAIN_TITLE_PINK",
2014-12-01 23:55:08 +01:00
};
2019-02-20 17:18:13 +01:00
const char *The_ClassTxtMenu[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "MENU_TXT_WHITE",
[The_THEME_GREY ] = "MENU_TXT_GREY",
[The_THEME_PURPLE] = "MENU_TXT_PURPLE",
[The_THEME_BLUE ] = "MENU_TXT_BLUE",
[The_THEME_YELLOW] = "MENU_TXT_YELLOW",
[The_THEME_PINK ] = "MENU_TXT_PINK",
2014-12-01 23:55:08 +01:00
};
2015-11-30 01:13:00 +01:00
const char *The_ClassTxtTabOff[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "TAB_OFF_TXT_WHITE",
[The_THEME_GREY ] = "TAB_OFF_TXT_GREY",
[The_THEME_PURPLE] = "TAB_OFF_TXT_PURPLE",
[The_THEME_BLUE ] = "TAB_OFF_TXT_BLUE",
[The_THEME_YELLOW] = "TAB_OFF_TXT_YELLOW",
[The_THEME_PINK ] = "TAB_OFF_TXT_PINK",
2014-12-01 23:55:08 +01:00
};
2015-11-30 01:13:00 +01:00
const char *The_ClassTxtTabOn[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "TAB_ON_TXT_WHITE",
[The_THEME_GREY ] = "TAB_ON_TXT_GREY",
[The_THEME_PURPLE] = "TAB_ON_TXT_PURPLE",
[The_THEME_BLUE ] = "TAB_ON_TXT_BLUE",
[The_THEME_YELLOW] = "TAB_ON_TXT_YELLOW",
[The_THEME_PINK ] = "TAB_ON_TXT_PINK",
2014-12-01 23:55:08 +01:00
};
const char *The_ClassTitleAction[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "TITLE_ACTION_WHITE",
[The_THEME_GREY ] = "TITLE_ACTION_GREY",
[The_THEME_PURPLE] = "TITLE_ACTION_PURPLE",
[The_THEME_BLUE ] = "TITLE_ACTION_BLUE",
[The_THEME_YELLOW] = "TITLE_ACTION_YELLOW",
[The_THEME_PINK ] = "TITLE_ACTION_PINK",
2014-12-01 23:55:08 +01:00
};
const char *The_ClassSubtitleAction[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "SUBTITLE_ACTION_WHITE",
[The_THEME_GREY ] = "SUBTITLE_ACTION_GREY",
[The_THEME_PURPLE] = "SUBTITLE_ACTION_PURPLE",
[The_THEME_BLUE ] = "SUBTITLE_ACTION_BLUE",
[The_THEME_YELLOW] = "SUBTITLE_ACTION_YELLOW",
[The_THEME_PINK ] = "SUBTITLE_ACTION_PINK",
2014-12-01 23:55:08 +01:00
};
const char *The_ClassTitle[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "TITLE_WHITE",
[The_THEME_GREY ] = "TITLE_GREY",
[The_THEME_PURPLE] = "TITLE_PURPLE",
[The_THEME_BLUE ] = "TITLE_BLUE",
[The_THEME_YELLOW] = "TITLE_YELLOW",
[The_THEME_PINK ] = "TITLE_PINK",
2014-12-01 23:55:08 +01:00
};
2019-11-18 14:21:01 +01:00
const char *The_ClassFormLinkInBox[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "BT_LINK FORM_IN_WHITE",
[The_THEME_GREY ] = "BT_LINK FORM_IN_GREY",
[The_THEME_PURPLE] = "BT_LINK FORM_IN_PURPLE",
[The_THEME_BLUE ] = "BT_LINK FORM_IN_BLUE",
[The_THEME_YELLOW] = "BT_LINK FORM_IN_YELLOW",
[The_THEME_PINK ] = "BT_LINK FORM_IN_PINK",
2019-11-18 14:21:01 +01:00
};
2019-11-22 01:04:03 +01:00
2019-02-22 21:47:50 +01:00
const char *The_ClassFormInBox[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "FORM_IN_WHITE",
[The_THEME_GREY ] = "FORM_IN_GREY",
[The_THEME_PURPLE] = "FORM_IN_PURPLE",
[The_THEME_BLUE ] = "FORM_IN_BLUE",
[The_THEME_YELLOW] = "FORM_IN_YELLOW",
[The_THEME_PINK ] = "FORM_IN_PINK",
2014-12-01 23:55:08 +01:00
};
2015-07-28 00:16:09 +02:00
2019-11-18 14:21:01 +01:00
const char *The_ClassFormLinkInBoxBold[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "BT_LINK FORM_IN_WHITE BOLD",
[The_THEME_GREY ] = "BT_LINK FORM_IN_GREY BOLD",
[The_THEME_PURPLE] = "BT_LINK FORM_IN_PURPLE BOLD",
[The_THEME_BLUE ] = "BT_LINK FORM_IN_BLUE BOLD",
[The_THEME_YELLOW] = "BT_LINK FORM_IN_YELLOW BOLD",
[The_THEME_PINK ] = "BT_LINK FORM_IN_PINK BOLD",
2019-11-18 14:21:01 +01:00
};
2019-11-22 01:04:03 +01:00
2019-02-22 21:47:50 +01:00
const char *The_ClassFormInBoxBold[The_NUM_THEMES] =
2015-12-25 22:05:28 +01:00
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "FORM_IN_WHITE BOLD",
[The_THEME_GREY ] = "FORM_IN_GREY BOLD",
[The_THEME_PURPLE] = "FORM_IN_PURPLE BOLD",
[The_THEME_BLUE ] = "FORM_IN_BLUE BOLD",
[The_THEME_YELLOW] = "FORM_IN_YELLOW BOLD",
[The_THEME_PINK ] = "FORM_IN_PINK BOLD",
2015-12-25 22:05:28 +01:00
};
2019-11-18 17:59:02 +01:00
const char *The_ClassFormLinkInBoxNoWrap[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "BT_LINK FORM_IN_WHITE NOWRAP",
[The_THEME_GREY ] = "BT_LINK FORM_IN_GREY NOWRAP",
[The_THEME_PURPLE] = "BT_LINK FORM_IN_PURPLE NOWRAP",
[The_THEME_BLUE ] = "BT_LINK FORM_IN_BLUE NOWRAP",
[The_THEME_YELLOW] = "BT_LINK FORM_IN_YELLOW NOWRAP",
[The_THEME_PINK ] = "BT_LINK FORM_IN_PINK NOWRAP",
2019-11-18 17:59:02 +01:00
};
2019-11-22 01:04:03 +01:00
2019-02-22 21:47:50 +01:00
const char *The_ClassFormInBoxNoWrap[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "FORM_IN_WHITE NOWRAP",
[The_THEME_GREY ] = "FORM_IN_GREY NOWRAP",
[The_THEME_PURPLE] = "FORM_IN_PURPLE NOWRAP",
[The_THEME_BLUE ] = "FORM_IN_BLUE NOWRAP",
[The_THEME_YELLOW] = "FORM_IN_YELLOW NOWRAP",
[The_THEME_PINK ] = "FORM_IN_PINK NOWRAP",
2014-12-01 23:55:08 +01:00
};
2015-07-28 00:16:09 +02:00
2019-11-18 14:21:01 +01:00
const char *The_ClassFormLinkOutBox[The_NUM_THEMES] =
2019-11-18 08:38:34 +01:00
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "BT_LINK FORM_OUT_WHITE",
[The_THEME_GREY ] = "BT_LINK FORM_OUT_GREY",
[The_THEME_PURPLE] = "BT_LINK FORM_OUT_PURPLE",
[The_THEME_BLUE ] = "BT_LINK FORM_OUT_BLUE",
[The_THEME_YELLOW] = "BT_LINK FORM_OUT_YELLOW",
[The_THEME_PINK ] = "BT_LINK FORM_OUT_PINK",
2019-11-18 11:23:48 +01:00
};
2019-11-18 08:38:34 +01:00
2019-02-22 21:47:50 +01:00
const char *The_ClassFormOutBox[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "FORM_OUT_WHITE",
[The_THEME_GREY ] = "FORM_OUT_GREY",
[The_THEME_PURPLE] = "FORM_OUT_PURPLE",
[The_THEME_BLUE ] = "FORM_OUT_BLUE",
[The_THEME_YELLOW] = "FORM_OUT_YELLOW",
[The_THEME_PINK ] = "FORM_OUT_PINK",
2019-02-22 21:47:50 +01:00
};
2019-11-18 14:21:01 +01:00
const char *The_ClassFormLinkOutBoxBold[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "BT_LINK FORM_OUT_WHITE BOLD",
[The_THEME_GREY ] = "BT_LINK FORM_OUT_GREY BOLD",
[The_THEME_PURPLE] = "BT_LINK FORM_OUT_PURPLE BOLD",
[The_THEME_BLUE ] = "BT_LINK FORM_OUT_BLUE BOLD",
[The_THEME_YELLOW] = "BT_LINK FORM_OUT_YELLOW BOLD",
[The_THEME_PINK ] = "BT_LINK FORM_OUT_PINK BOLD",
2019-11-18 14:21:01 +01:00
};
2019-02-22 21:47:50 +01:00
const char *The_ClassFormOutBoxBold[The_NUM_THEMES] =
{
2019-11-22 01:04:03 +01:00
[The_THEME_WHITE ] = "FORM_OUT_WHITE BOLD",
[The_THEME_GREY ] = "FORM_OUT_GREY BOLD",
[The_THEME_PURPLE] = "FORM_OUT_PURPLE BOLD",
[The_THEME_BLUE ] = "FORM_OUT_BLUE BOLD",
[The_THEME_YELLOW] = "FORM_OUT_YELLOW BOLD",
[The_THEME_PINK ] = "FORM_OUT_PINK BOLD",
2014-12-01 23:55:08 +01:00
};
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
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_Theme_SKIN,
2020-04-08 03:41:05 +02:00
The_PutIconsTheme,NULL,
2019-03-26 11:53:21 +01:00
Hlp_PROFILE_Settings_theme,Box_NOT_CLOSABLE);
Set_BeginSettingsHead ();
Set_BeginOneSettingSelector ();
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++)
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"%s\"",Theme == Gbl.Prefs.Theme ? "PREF_ON" :
"PREF_OFF");
Frm_BeginForm (ActChgThe);
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamString (NULL,"Theme",The_ThemeId[Theme]);
snprintf (Icon,sizeof (Icon),"%s/%s/theme_32x20.gif",
Cfg_ICON_FOLDER_THEMES,The_ThemeId[Theme]);
2019-03-26 11:53:21 +01:00
Ico_PutSettingIconLink (Icon,The_ThemeNames[Theme]);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
}
2019-03-26 11:53:21 +01:00
Set_EndOneSettingSelector ();
Set_EndSettingsHead ();
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)
{
2018-10-04 21:57:25 +02:00
char Path[PATH_MAX + 1 +
NAME_MAX + 1 +
NAME_MAX + 1];
2014-12-01 23:55:08 +01:00
/***** Get param theme *****/
Gbl.Prefs.Theme = The_GetParamTheme ();
snprintf (Path,sizeof (Path),"%s/%s",
Cfg_URL_ICON_THEMES_PUBLIC,The_ThemeId[Gbl.Prefs.Theme]);
Str_Copy (Gbl.Prefs.URLTheme,Path,sizeof (Gbl.Prefs.URLTheme) - 1);
2014-12-01 23:55:08 +01:00
/***** Store theme in database *****/
if (Gbl.Usrs.Me.Logged)
2019-03-26 11:53:21 +01:00
DB_QueryUPDATE ("can not update your setting about theme",
"UPDATE usr_data"
" SET Theme='%s'"
2018-11-03 12:16:40 +01:00
" WHERE UsrCod=%ld",
2019-02-20 17:18:13 +01:00
The_ThemeId[Gbl.Prefs.Theme],
Gbl.Usrs.Me.UsrDat.UsrCod);
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 ***************************/
/*****************************************************************************/
The_Theme_t The_GetParamTheme (void)
{
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;
2017-03-08 14:12:33 +01:00
Par_GetParToText ("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;
return The_THEME_UNKNOWN;
}
/*****************************************************************************/
/**************************** 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;
return The_THEME_UNKNOWN;
}