swad-core/swad_theme.c

321 lines
7.9 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.
2015-01-01 14:34:06 +01:00
Copyright (C) 1999-2015 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;
const char *Lay_LayoutIcons[Lay_NUM_LAYOUTS];
/*****************************************************************************/
/******************************** Private constants **************************/
/*****************************************************************************/
#define MAX_THEME_ID 16
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] =
{
"#F7F6F5",
"#F7F6F5",
"#E8F3F6",
"#FFFA85",
};
const char *The_TabOffBgColors[The_NUM_THEMES] =
{
"#D4D4D4",
"#D4D4D4",
"#CAE1E8",
"#FDC469",
};
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",
};
const char *The_ClassCurrentTime[The_NUM_THEMES] =
{
"WHITE_CUR_TIME",
"GREY_CUR_TIME",
"BLUE_CUR_TIME",
"YELLOW_CUR_TIME",
};
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",
};
const char *The_ClassDegree[The_NUM_THEMES] =
{
"WHITE_DEGREE",
"GREY_DEGREE",
"BLUE_DEGREE",
"YELLOW_DEGREE",
};
const char *The_ClassCourse[The_NUM_THEMES] =
{
"WHITE_COURSE",
"GREY_COURSE",
"BLUE_COURSE",
"YELLOW_COURSE",
};
const char *The_ClassConnected[The_NUM_THEMES] =
{
"WHITE_CONNECTED",
"GREY_CONNECTED",
"BLUE_CONNECTED",
"YELLOW_CONNECTED",
};
const char *The_ClassMenuOff[The_NUM_THEMES] =
{
"WHITE_MENU_OFF",
"GREY_MENU_OFF",
"BLUE_MENU_OFF",
"YELLOW_MENU_OFF",
};
const char *The_ClassMenuOn[The_NUM_THEMES] =
{
"WHITE_MENU_ON",
"GREY_MENU_ON",
"BLUE_MENU_ON",
"YELLOW_MENU_ON",
};
const char *The_ClassTabOff[The_NUM_THEMES] =
{
"WHITE_TAB_OFF",
"GREY_TAB_OFF",
"BLUE_TAB_OFF",
"YELLOW_TAB_OFF",
};
const char *The_ClassTabOn[The_NUM_THEMES] =
{
"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",
};
const char *The_ClassFormul[The_NUM_THEMES] =
{
2015-01-01 14:34:06 +01:00
"WHITE_FORM",
"GREY_FORM",
"BLUE_FORM",
"YELLOW_FORM",
2014-12-01 23:55:08 +01:00
};
const char *The_ClassFormulNB[The_NUM_THEMES] =
{
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
};
const char *The_ClassFormulB[The_NUM_THEMES] =
{
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
};
/*****************************************************************************/
/************************ Put icons to select a theme ***********************/
/*****************************************************************************/
void The_PutIconsToSelectTheme (void)
{
The_Theme_t Theme;
2014-12-21 19:43:39 +01:00
fprintf (Gbl.F.Out,"<table class=\"CELLS_PAD_1\">"
2014-12-01 23:55:08 +01:00
"<tr>");
for (Theme = (The_Theme_t) 0;
Theme < The_NUM_THEMES;
Theme++)
{
2014-12-23 22:47:09 +01:00
fprintf (Gbl.F.Out,"<td class=\"%s\" style=\"text-align:center;\">",
2014-12-01 23:55:08 +01:00
Theme == Gbl.Prefs.Theme ? "LAYOUT_ON" :
"LAYOUT_OFF");
Act_FormStart (ActChgThe);
Par_PutHiddenParamString ("Theme",The_ThemeId[Theme]);
fprintf (Gbl.F.Out,"<input type=\"image\" src=\"%s/%s/%s/theme_32x20.gif\""
2014-12-29 13:26:39 +01:00
" alt=\"%s\" title=\"%s\" style=\"display:block;"
" width:32px; height:20px;\" />"
2014-12-01 23:55:08 +01:00
"</form>"
"</td>",
Gbl.Prefs.IconsURL,
Cfg_ICON_FOLDER_THEMES,
The_ThemeId[Theme],
The_ThemeNames[Theme],
The_ThemeNames[Theme]);
}
fprintf (Gbl.F.Out,"</tr>"
"</table>");
}
/*****************************************************************************/
/********************************* 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)
{
sprintf (Query,"UPDATE usr_data SET Theme='%s' WHERE UsrCod='%ld'",
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 *****/
Prf_SetPrefsFromIP ();
}
/*****************************************************************************/
/***************************** Get parameter theme ***************************/
/*****************************************************************************/
The_Theme_t The_GetParamTheme (void)
{
char ThemeId[MAX_THEME_ID+1];
The_Theme_t Theme;
Par_GetParToText ("Theme",ThemeId,MAX_THEME_ID);
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;
}