swad-core/swad_theme.c

342 lines
8.8 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.
2017-01-13 01:51:23 +01:00
Copyright (C) 1999-2017 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 <stdio.h> // For fprintf, etc.
#include <string.h>
#include "swad_config.h"
#include "swad_database.h"
#include "swad_global.h"
#include "swad_layout.h"
#include "swad_parameter.h"
#include "swad_preference.h"
#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",
"blue",
"yellow",
};
const char *The_ThemeNames[The_NUM_THEMES] =
{
"White",
"Grey",
"Blue",
"Yellow",
};
const char *The_TabOnBgColors[The_NUM_THEMES] =
{
2015-09-04 19:26:08 +02:00
"TAB_ON_WHITE",
"TAB_ON_GREY",
"TAB_ON_BLUE",
"TAB_ON_YELLOW",
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",
"TAB_OFF_BLUE",
"TAB_OFF_YELLOW",
2014-12-01 23:55:08 +01:00
};
const char *The_ClassSeparator[The_NUM_THEMES] =
{
"WHITE_SEPARA",
"GREY_SEPARA",
"BLUE_SEPARA",
"YELLOW_SEPARA",
};
const char *The_ClassHead[The_NUM_THEMES] =
{
"WHITE_HEAD",
"GREY_HEAD",
"BLUE_HEAD",
"YELLOW_HEAD",
};
2016-03-22 01:26:00 +01:00
const char *The_ClassTagline[The_NUM_THEMES] =
{
"WHITE_TAGLINE",
"GREY_TAGLINE",
"BLUE_TAGLINE",
"YELLOW_TAGLINE",
};
2014-12-01 23:55:08 +01:00
const char *The_ClassNotif[The_NUM_THEMES] =
{
"WHITE_NOTIF",
"GREY_NOTIF",
"BLUE_NOTIF",
"YELLOW_NOTIF",
};
const char *The_ClassUsr[The_NUM_THEMES] =
{
"WHITE_USR",
"GREY_USR",
"BLUE_USR",
"YELLOW_USR",
};
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",
"BC_BLUE",
"BC_YELLOW",
2014-12-01 23:55:08 +01:00
};
const char *The_ClassCourse[The_NUM_THEMES] =
{
"WHITE_COURSE",
"GREY_COURSE",
"BLUE_COURSE",
"YELLOW_COURSE",
};
2015-11-30 01:13:00 +01:00
const char *The_ClassTxtMenuOff[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
"WHITE_MENU_OFF",
"GREY_MENU_OFF",
"BLUE_MENU_OFF",
"YELLOW_MENU_OFF",
};
2015-11-30 01:13:00 +01:00
const char *The_ClassTxtMenuOn[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
"WHITE_MENU_ON",
"GREY_MENU_ON",
"BLUE_MENU_ON",
"YELLOW_MENU_ON",
};
2015-11-30 01:13:00 +01:00
const char *The_ClassTxtTabOff[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
"WHITE_TAB_OFF",
"GREY_TAB_OFF",
"BLUE_TAB_OFF",
"YELLOW_TAB_OFF",
};
2015-11-30 01:13:00 +01:00
const char *The_ClassTxtTabOn[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
"WHITE_TAB_ON",
"GREY_TAB_ON",
"BLUE_TAB_ON",
"YELLOW_TAB_ON",
};
const char *The_ClassTitleAction[The_NUM_THEMES] =
{
"WHITE_TITLE_ACTION",
"GREY_TITLE_ACTION",
"BLUE_TITLE_ACTION",
"YELLOW_TITLE_ACTION",
};
const char *The_ClassSubtitleAction[The_NUM_THEMES] =
{
"WHITE_SUBTITLE_ACTION",
"GREY_SUBTITLE_ACTION",
"BLUE_SUBTITLE_ACTION",
"YELLOW_SUBTITLE_ACTION",
};
const char *The_ClassTitle[The_NUM_THEMES] =
{
"WHITE_TITLE",
"GREY_TITLE",
"BLUE_TITLE",
"YELLOW_TITLE",
};
2015-07-27 21:25:45 +02:00
const char *The_ClassForm[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
2015-01-01 14:34:06 +01:00
"WHITE_FORM",
"GREY_FORM",
"BLUE_FORM",
"YELLOW_FORM",
2014-12-01 23:55:08 +01:00
};
2015-07-28 00:16:09 +02:00
2015-12-25 22:05:28 +01:00
const char *The_ClassFormDark[The_NUM_THEMES] =
{
"WHITE_FORM_DARK",
"GREY_FORM_DARK",
"BLUE_FORM_DARK",
"YELLOW_FORM_DARK",
};
2015-07-27 21:25:45 +02:00
const char *The_ClassFormNoWrap[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
2015-01-01 14:34:06 +01:00
"WHITE_FORM_NOWRAP",
"GREY_FORM_NOWRAP",
"BLUE_FORM_NOWRAP",
"YELLOW_FORM_NOWRAP",
2014-12-01 23:55:08 +01:00
};
2015-07-28 00:16:09 +02:00
2015-07-27 21:25:45 +02:00
const char *The_ClassFormBold[The_NUM_THEMES] =
2014-12-01 23:55:08 +01:00
{
2015-01-01 14:34:06 +01:00
"WHITE_FORM_BOLD",
"GREY_FORM_BOLD",
"BLUE_FORM_BOLD",
"YELLOW_FORM_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)
{
2016-11-13 01:21:35 +01:00
extern const char *Hlp_PROFILE_Preferences_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;
2017-06-10 20:56:50 +02:00
Lay_StartRoundFrame (NULL,Txt_Theme_SKIN,The_PutIconsTheme,
Hlp_PROFILE_Preferences_theme,
false); // Not closable
2016-12-23 22:19:03 +01:00
fprintf (Gbl.F.Out,"<div class=\"PREF_CONTAINER\">");
2014-12-01 23:55:08 +01:00
for (Theme = (The_Theme_t) 0;
Theme < The_NUM_THEMES;
Theme++)
{
2016-12-23 22:19:03 +01:00
fprintf (Gbl.F.Out,"<div class=\"%s\">",
2015-11-22 00:52:55 +01:00
Theme == Gbl.Prefs.Theme ? "PREF_ON" :
"PREF_OFF");
2014-12-01 23:55:08 +01:00
Act_FormStart (ActChgThe);
Par_PutHiddenParamString ("Theme",The_ThemeId[Theme]);
2015-01-04 01:51:07 +01:00
fprintf (Gbl.F.Out,"<input type=\"image\""
" src=\"%s/%s/%s/theme_32x20.gif\" alt=\"%s\""
2016-12-24 13:46:29 +01:00
" title=\"%s\" class=\"ICO40x25B\" />",
2014-12-01 23:55:08 +01:00
Gbl.Prefs.IconsURL,
Cfg_ICON_FOLDER_THEMES,
The_ThemeId[Theme],
The_ThemeNames[Theme],
The_ThemeNames[Theme]);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
2016-12-23 22:19:03 +01:00
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
}
2016-12-23 22:19:03 +01:00
fprintf (Gbl.F.Out,"</div>");
2016-11-07 13:04:47 +01:00
Lay_EndRoundFrame ();
}
/*****************************************************************************/
/***************** Put contextual icons in theme preference ******************/
/*****************************************************************************/
static void The_PutIconsTheme (void)
{
/***** Put icon to show a figure *****/
Gbl.Stat.FigureType = Sta_THEMES;
Sta_PutIconToShowFigure ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************************* Change theme ******************************/
/*****************************************************************************/
void The_ChangeTheme (void)
{
char Query[512];
/***** Get param theme *****/
Gbl.Prefs.Theme = The_GetParamTheme ();
sprintf (Gbl.Prefs.PathTheme,"%s/%s/%s",
Gbl.Prefs.IconsURL,Cfg_ICON_FOLDER_THEMES,The_ThemeId[Gbl.Prefs.Theme]);
/***** Store theme in database *****/
if (Gbl.Usrs.Me.Logged)
{
2015-11-21 20:23:28 +01:00
sprintf (Query,"UPDATE usr_data SET Theme='%s'"
2017-03-24 01:09:27 +01:00
" WHERE UsrCod=%ld",
2014-12-01 23:55:08 +01:00
The_ThemeId[Gbl.Prefs.Theme],Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE (Query,"can not update your preference about theme");
}
/***** Set preferences from current IP *****/
2015-03-14 17:39:04 +01:00
Pre_SetPrefsFromIP ();
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;
}