swad-core/swad_theme.c

419 lines
11 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.
2019-01-07 21:52:19 +01:00
Copyright (C) 1999-2019 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 **********************************/
/*****************************************************************************/
2019-02-18 14:41:46 +01:00
#include <stdio.h> // For fprintf, etc.
2014-12-01 23:55:08 +01:00
#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"
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] =
{
"white",
"grey",
2019-02-20 17:18:13 +01:00
"purple",
2014-12-01 23:55:08 +01:00
"blue",
"yellow",
2019-02-20 17:18:13 +01:00
"pink",
2014-12-01 23:55:08 +01:00
};
const char *The_ThemeNames[The_NUM_THEMES] =
{
"White",
"Grey",
2019-02-20 17:18:13 +01:00
"Purple",
2014-12-01 23:55:08 +01:00
"Blue",
"Yellow",
2019-02-20 17:18:13 +01:00
"Pink",
2014-12-01 23:55:08 +01:00
};
const char *The_TabOnBgColors[The_NUM_THEMES] =
{
2015-09-04 19:26:08 +02:00
"TAB_ON_WHITE",
"TAB_ON_GREY",
2019-02-20 17:18:13 +01:00
"TAB_ON_PURPLE",
2015-09-04 19:26:08 +02:00
"TAB_ON_BLUE",
"TAB_ON_YELLOW",
2019-02-20 17:18:13 +01:00
"TAB_ON_PINK",
2014-12-01 23:55:08 +01:00
};
const char *The_TabOffBgColors[The_NUM_THEMES] =
{
2015-09-04 19:26:08 +02:00
"TAB_OFF_WHITE",
"TAB_OFF_GREY",
2019-02-20 17:18:13 +01:00
"TAB_OFF_PURPLE",
2015-09-04 19:26:08 +02:00
"TAB_OFF_BLUE",
"TAB_OFF_YELLOW",
2019-02-20 17:18:13 +01:00
"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-18 14:21:01 +01:00
"BT_LINK TAGLINE_WHITE",
"BT_LINK TAGLINE_GREY",
"BT_LINK TAGLINE_PURPLE",
"BT_LINK TAGLINE_BLUE",
"BT_LINK TAGLINE_YELLOW",
"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-18 09:20:44 +01:00
"BT_LINK NOTIF_WHITE",
"BT_LINK NOTIF_GREY",
"BT_LINK NOTIF_PURPLE",
"BT_LINK NOTIF_BLUE",
"BT_LINK NOTIF_YELLOW",
"BT_LINK NOTIF_PINK",
2014-12-01 23:55:08 +01:00
};
const char *The_ClassUsr[The_NUM_THEMES] =
{
2019-02-20 17:18:13 +01:00
"USR_WHITE",
"USR_GREY",
"USR_PURPLE",
"USR_BLUE",
"USR_YELLOW",
"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
{
2015-12-26 12:40:21 +01:00
"BC_WHITE",
"BC_GREY",
2019-02-20 17:18:13 +01:00
"BC_PURPLE",
2015-12-26 12:40:21 +01:00
"BC_BLUE",
"BC_YELLOW",
2019-02-20 17:18:13 +01:00
"BC_PINK",
2014-12-01 23:55:08 +01:00
};
const char *The_ClassCourse[The_NUM_THEMES] =
{
2019-02-20 17:18:13 +01:00
"MAIN_TITLE_WHITE",
"MAIN_TITLE_GREY",
"MAIN_TITLE_PURPLE",
"MAIN_TITLE_BLUE",
"MAIN_TITLE_YELLOW",
"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-02-20 17:18:13 +01:00
"MENU_TXT_WHITE",
"MENU_TXT_GREY",
"MENU_TXT_PURPLE",
"MENU_TXT_BLUE",
"MENU_TXT_YELLOW",
"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-02-20 17:18:13 +01:00
"TAB_OFF_TXT_WHITE",
"TAB_OFF_TXT_GREY",
"TAB_OFF_TXT_PURPLE",
"TAB_OFF_TXT_BLUE",
"TAB_OFF_TXT_YELLOW",
"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-02-20 17:18:13 +01:00
"TAB_ON_TXT_WHITE",
"TAB_ON_TXT_GREY",
"TAB_ON_TXT_PURPLE",
"TAB_ON_TXT_BLUE",
"TAB_ON_TXT_YELLOW",
"TAB_ON_TXT_PINK",
2014-12-01 23:55:08 +01:00
};
const char *The_ClassTitleAction[The_NUM_THEMES] =
{
2019-02-20 17:18:13 +01:00
"TITLE_ACTION_WHITE",
"TITLE_ACTION_GREY",
"TITLE_ACTION_PURPLE",
"TITLE_ACTION_BLUE",
"TITLE_ACTION_YELLOW",
"TITLE_ACTION_PINK",
2014-12-01 23:55:08 +01:00
};
const char *The_ClassSubtitleAction[The_NUM_THEMES] =
{
2019-02-20 17:18:13 +01:00
"SUBTITLE_ACTION_WHITE",
"SUBTITLE_ACTION_GREY",
"SUBTITLE_ACTION_PURPLE",
"SUBTITLE_ACTION_BLUE",
"SUBTITLE_ACTION_YELLOW",
"SUBTITLE_ACTION_PINK",
2014-12-01 23:55:08 +01:00
};
const char *The_ClassTitle[The_NUM_THEMES] =
{
2019-02-20 17:18:13 +01:00
"TITLE_WHITE",
"TITLE_GREY",
"TITLE_PURPLE",
"TITLE_BLUE",
"TITLE_YELLOW",
"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] =
{
"BT_LINK FORM_IN_WHITE",
"BT_LINK FORM_IN_GREY",
"BT_LINK FORM_IN_PURPLE",
"BT_LINK FORM_IN_BLUE",
"BT_LINK FORM_IN_YELLOW",
"BT_LINK FORM_IN_PINK",
};
2019-02-22 21:47:50 +01:00
const char *The_ClassFormInBox[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
2019-02-22 21:47:50 +01:00
"FORM_IN_WHITE",
"FORM_IN_GREY",
"FORM_IN_PURPLE",
"FORM_IN_BLUE",
"FORM_IN_YELLOW",
"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] =
{
"BT_LINK FORM_IN_WHITE BOLD",
"BT_LINK FORM_IN_GREY BOLD",
"BT_LINK FORM_IN_PURPLE BOLD",
"BT_LINK FORM_IN_BLUE BOLD",
"BT_LINK FORM_IN_YELLOW BOLD",
"BT_LINK FORM_IN_PINK BOLD",
};
2019-02-22 21:47:50 +01:00
const char *The_ClassFormInBoxBold[The_NUM_THEMES] =
2015-12-25 22:05:28 +01:00
{
2019-02-22 21:47:50 +01:00
"FORM_IN_WHITE BOLD",
"FORM_IN_GREY BOLD",
"FORM_IN_PURPLE BOLD",
"FORM_IN_BLUE BOLD",
"FORM_IN_YELLOW BOLD",
"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] =
{
"BT_LINK FORM_IN_WHITE NOWRAP",
"BT_LINK FORM_IN_GREY NOWRAP",
"BT_LINK FORM_IN_PURPLE NOWRAP",
"BT_LINK FORM_IN_BLUE NOWRAP",
"BT_LINK FORM_IN_YELLOW NOWRAP",
"BT_LINK FORM_IN_PINK NOWRAP",
};
2019-02-22 21:47:50 +01:00
const char *The_ClassFormInBoxNoWrap[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
2019-02-22 21:47:50 +01:00
"FORM_IN_WHITE NOWRAP",
"FORM_IN_GREY NOWRAP",
"FORM_IN_PURPLE NOWRAP",
"FORM_IN_BLUE NOWRAP",
"FORM_IN_YELLOW NOWRAP",
"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-18 14:21:01 +01:00
"BT_LINK FORM_OUT_WHITE",
"BT_LINK FORM_OUT_GREY",
"BT_LINK FORM_OUT_PURPLE",
"BT_LINK FORM_OUT_BLUE",
"BT_LINK FORM_OUT_YELLOW",
"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-02-22 21:47:50 +01:00
"FORM_OUT_WHITE",
"FORM_OUT_GREY",
"FORM_OUT_PURPLE",
"FORM_OUT_BLUE",
"FORM_OUT_YELLOW",
"FORM_OUT_PINK",
};
2019-11-18 14:21:01 +01:00
const char *The_ClassFormLinkOutBoxBold[The_NUM_THEMES] =
{
"BT_LINK FORM_OUT_WHITE BOLD",
"BT_LINK FORM_OUT_GREY BOLD",
"BT_LINK FORM_OUT_PURPLE BOLD",
"BT_LINK FORM_OUT_BLUE BOLD",
"BT_LINK FORM_OUT_YELLOW BOLD",
"BT_LINK FORM_OUT_PINK BOLD",
};
2019-02-22 21:47:50 +01:00
const char *The_ClassFormOutBoxBold[The_NUM_THEMES] =
{
"FORM_OUT_WHITE BOLD",
"FORM_OUT_GREY BOLD",
"FORM_OUT_PURPLE BOLD",
"FORM_OUT_BLUE BOLD",
"FORM_OUT_YELLOW BOLD",
"FORM_OUT_PINK BOLD",
2014-12-01 23:55:08 +01:00
};
2016-11-07 13:04:47 +01:00
/*****************************************************************************/
/****************************** Private prototypes ***************************/
/*****************************************************************************/
static void The_PutIconsTheme (void);
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
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,Txt_Theme_SKIN,The_PutIconsTheme,
2019-03-26 11:53:21 +01:00
Hlp_PROFILE_Settings_theme,Box_NOT_CLOSABLE);
Set_StartSettingsHead ();
Set_StartOneSettingSelector ();
2014-12-01 23:55:08 +01:00
for (Theme = (The_Theme_t) 0;
Theme < The_NUM_THEMES;
Theme++)
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"%s\"",Theme == Gbl.Prefs.Theme ? "PREF_ON" :
"PREF_OFF");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgThe);
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamString (NULL,"Theme",The_ThemeId[Theme]);
2019-01-12 03:00:59 +01:00
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
/*****************************************************************************/
static void The_PutIconsTheme (void)
{
/***** Put icon to show a figure *****/
2019-02-12 14:46:14 +01:00
Gbl.Figures.FigureType = Fig_THEMES;
Fig_PutIconToShowFigure ();
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 ();
2018-10-18 02:02:32 +02:00
snprintf (Path,sizeof (Path),
2019-03-20 01:36:36 +01:00
"%s/%s",
Cfg_URL_ICON_THEMES_PUBLIC,
2018-10-18 02:02:32 +02:00
The_ThemeId[Gbl.Prefs.Theme]);
2019-01-09 01:41:54 +01:00
Str_Copy (Gbl.Prefs.URLTheme,Path,
2018-10-04 21:57:25 +02:00
PATH_MAX);
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",
2018-11-03 12:16:40 +01:00
"UPDATE usr_data SET Theme='%s'"
" 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);
2014-12-01 23:55:08 +01:00
for (Theme = (The_Theme_t) 0;
Theme < The_NUM_THEMES;
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;
for (Theme = (The_Theme_t) 0;
Theme < The_NUM_THEMES;
Theme++)
if (!strcasecmp (Str,The_ThemeId[Theme]))
return Theme;
return The_THEME_UNKNOWN;
}