swad-core/swad_icon.c

159 lines
5.4 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_icon.c: icon selection
/*
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_icon.h"
#include "swad_layout.h"
#include "swad_parameter.h"
#include "swad_preference.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/******************************** Private constants **************************/
/*****************************************************************************/
#define MAX_ICON_SET_ID 16
const char *Ico_IconSetId[Ico_NUM_ICON_SETS] =
{
"awesome",
"nuvola",
};
const char *Ico_IconSetNames[Ico_NUM_ICON_SETS] =
{
"Awesome",
"Nuvola",
};
/*****************************************************************************/
/************************ Put icons to select a IconSet **********************/
/*****************************************************************************/
void Ico_PutIconsToSelectIconSet (void)
{
Ico_IconSet_t IconSet;
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 (IconSet = (Ico_IconSet_t) 0;
IconSet < Ico_NUM_ICON_SETS;
IconSet++)
{
2014-12-23 01:36:58 +01:00
fprintf (Gbl.F.Out,"<td class=\"%s\" style=\"text-align:center;\">",
2014-12-01 23:55:08 +01:00
IconSet == Gbl.Prefs.IconSet ? "LAYOUT_ON" :
"LAYOUT_OFF");
Act_FormStart (ActChgIco);
Par_PutHiddenParamString ("IconSet",Ico_IconSetId[IconSet]);
fprintf (Gbl.F.Out,"<input type=\"image\" src=\"%s/%s/%s/%s/heart32x32.gif\""
" alt=\"%s\" title=\"%s\" class=\"ICON32x32\" />"
"</form>"
"</td>",
Gbl.Prefs.IconsURL,
Cfg_ICON_FOLDER_ICON_SETS,
Ico_IconSetId[IconSet],
Cfg_ICON_ACTION_32x32,
Ico_IconSetNames[IconSet],
Ico_IconSetNames[IconSet]);
}
fprintf (Gbl.F.Out,"</tr>"
"</table>");
}
/*****************************************************************************/
/***************************** Change icon set *******************************/
/*****************************************************************************/
void Ico_ChangeIconSet (void)
{
char Query[512];
/***** Get param with icon set *****/
Gbl.Prefs.IconSet = Ico_GetParamIconSet ();
sprintf (Gbl.Prefs.PathIconSet,"%s/%s/%s",
Gbl.Prefs.IconsURL,Cfg_ICON_FOLDER_ICON_SETS,
Ico_IconSetId[Gbl.Prefs.IconSet]);
/***** Store icon set in database *****/
if (Gbl.Usrs.Me.Logged)
{
sprintf (Query,"UPDATE usr_data SET IconSet='%s' WHERE UsrCod='%ld'",
Ico_IconSetId[Gbl.Prefs.IconSet],
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE (Query,"can not update your preference about icon set");
}
/***** Set preferences from current IP *****/
Prf_SetPrefsFromIP ();
}
/*****************************************************************************/
/*********************** Get parameter with icon set *************************/
/*****************************************************************************/
Ico_IconSet_t Ico_GetParamIconSet (void)
{
char IconSetId[MAX_ICON_SET_ID+1];
Ico_IconSet_t IconSet;
Par_GetParToText ("IconSet",IconSetId,MAX_ICON_SET_ID);
for (IconSet = (Ico_IconSet_t) 0;
IconSet < Ico_NUM_ICON_SETS;
IconSet++)
if (!strcmp (IconSetId,Ico_IconSetId[IconSet]))
return IconSet;
return Ico_ICON_SET_UNKNOWN;
}
/*****************************************************************************/
/************************* Get icon set from string **************************/
/*****************************************************************************/
Ico_IconSet_t Ico_GetIconSetFromStr (const char *Str)
{
Ico_IconSet_t IconSet;
for (IconSet = (Ico_IconSet_t) 0;
IconSet < Ico_NUM_ICON_SETS;
IconSet++)
if (!strcasecmp (Str,Ico_IconSetId[IconSet]))
return IconSet;
return Ico_ICON_SET_UNKNOWN;
}