mirror of
https://github.com/acanas/swad-core.git
synced 2024-09-22 00:00:40 +02:00
239 lines
8.6 KiB
C
239 lines
8.6 KiB
C
// swad_photo_shape.h: User photo shape
|
|
|
|
/*
|
|
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.
|
|
Copyright (C) 1999-2021 Antonio Cañas Vargas
|
|
|
|
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 ***********************************/
|
|
/*****************************************************************************/
|
|
|
|
#define _GNU_SOURCE // For asprintf
|
|
#include <stddef.h> // For NULL
|
|
#include <stdio.h> // For asprintf
|
|
|
|
#include "swad_action.h"
|
|
#include "swad_config.h"
|
|
#include "swad_error.h"
|
|
#include "swad_figure.h"
|
|
#include "swad_form.h"
|
|
#include "swad_global.h"
|
|
#include "swad_photo_shape.h"
|
|
#include "swad_setting_database.h"
|
|
#include "swad_user_database.h"
|
|
|
|
/*****************************************************************************/
|
|
/************** External global variables from others modules ****************/
|
|
/*****************************************************************************/
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
/*****************************************************************************/
|
|
/***************************** Private prototypes ****************************/
|
|
/*****************************************************************************/
|
|
|
|
static void PhoSha_PutIconsPhotoShape (__attribute__((unused)) void *Args);
|
|
|
|
/*****************************************************************************/
|
|
/******************* Put icons to select user photo shape ********************/
|
|
/*****************************************************************************/
|
|
|
|
void PhoSha_PutIconsToSelectPhotoShape (void)
|
|
{
|
|
extern const char *Hlp_PROFILE_Settings_user_photos;
|
|
extern const char *Ico_ClassColor[Ico_NUM_COLORS][The_NUM_THEMES];
|
|
extern const char *Txt_User_photos;
|
|
extern const char *Txt_PHOTO_SHAPES[PhoSha_NUM_SHAPES];
|
|
static const char *ClassPhoto[PhoSha_NUM_SHAPES] =
|
|
{
|
|
[PhoSha_SHAPE_CIRCLE ] = "ICO_HIGHLIGHT PHOTOC15x20B",
|
|
[PhoSha_SHAPE_ELLIPSE ] = "ICO_HIGHLIGHT PHOTOE15x20B",
|
|
[PhoSha_SHAPE_OVAL ] = "ICO_HIGHLIGHT PHOTOO15x20B",
|
|
[PhoSha_SHAPE_RECTANGLE] = "ICO_HIGHLIGHT PHOTOR15x20B",
|
|
};
|
|
PhoSha_Shape_t Shape;
|
|
|
|
Box_BoxBegin (NULL,Txt_User_photos,
|
|
PhoSha_PutIconsPhotoShape,NULL,
|
|
Hlp_PROFILE_Settings_user_photos,Box_NOT_CLOSABLE);
|
|
Set_BeginSettingsHead ();
|
|
Set_BeginOneSettingSelector ();
|
|
for (Shape = (PhoSha_Shape_t) 0;
|
|
Shape <= (PhoSha_Shape_t) (PhoSha_NUM_SHAPES - 1);
|
|
Shape++)
|
|
{
|
|
if (Shape == Gbl.Prefs.PhotoShape)
|
|
HTM_DIV_Begin ("class=\"PREF_ON PREF_ON_%s\"",
|
|
The_GetSuffix ());
|
|
else
|
|
HTM_DIV_Begin ("class=\"PREF_OFF\"");
|
|
Frm_BeginForm (ActChgUsrPho);
|
|
Par_PutHiddenParamUnsigned (NULL,"PhotoShape",Shape);
|
|
HTM_INPUT_IMAGE (Cfg_URL_ICON_PUBLIC,"user.svg",
|
|
Txt_PHOTO_SHAPES[Shape],
|
|
"class=\"%s %s\"",
|
|
ClassPhoto[Shape],
|
|
Ico_ClassColor[Ico_BLACK][Gbl.Prefs.Theme]);
|
|
Frm_EndForm ();
|
|
HTM_DIV_End ();
|
|
}
|
|
Set_EndOneSettingSelector ();
|
|
Set_EndSettingsHead ();
|
|
Box_BoxEnd ();
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
/************** Put contextual icons in side-columns setting *****************/
|
|
/*****************************************************************************/
|
|
|
|
static void PhoSha_PutIconsPhotoShape (__attribute__((unused)) void *Args)
|
|
{
|
|
/***** Put icon to show a figure *****/
|
|
Fig_PutIconToShowFigure (Fig_PHOTO_SHAPES);
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
/************************** Change user photo shape **************************/
|
|
/*****************************************************************************/
|
|
|
|
void PhoSha_ChangePhotoShape (void)
|
|
{
|
|
/***** Get param with user photo shape *****/
|
|
Gbl.Prefs.PhotoShape = PhoSha_GetParamPhotoShape ();
|
|
|
|
/***** Store side colums in database *****/
|
|
if (Gbl.Usrs.Me.Logged)
|
|
Set_DB_UpdateMySettingsAboutPhotoShape ();
|
|
|
|
/***** Set settings from current IP *****/
|
|
Set_SetSettingsFromIP ();
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
/************** Get parameter used to change user photo shape ****************/
|
|
/*****************************************************************************/
|
|
|
|
PhoSha_Shape_t PhoSha_GetParamPhotoShape (void)
|
|
{
|
|
return (PhoSha_Shape_t) Par_GetParToUnsignedLong ("PhotoShape",
|
|
(PhoSha_Shape_t) 0,
|
|
(PhoSha_Shape_t) (PhoSha_NUM_SHAPES - 1),
|
|
PhoSha_SHAPE_DEFAULT);
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
/*********************** Get photo shape from string *************************/
|
|
/*****************************************************************************/
|
|
|
|
PhoSha_Shape_t PhoSha_GetShapeFromStr (const char *Str)
|
|
{
|
|
unsigned UnsignedNum;
|
|
|
|
if (sscanf (Str,"%u",&UnsignedNum) == 1)
|
|
if (UnsignedNum < PhoSha_NUM_SHAPES)
|
|
return (PhoSha_Shape_t) UnsignedNum;
|
|
|
|
return PhoSha_SHAPE_DEFAULT;
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
/****** Get and show number of users who have chosen a user photo shape ******/
|
|
/*****************************************************************************/
|
|
|
|
void PhoSha_GetAndShowNumUsrsPerPhotoShape (void)
|
|
{
|
|
extern const char *Hlp_ANALYTICS_Figures_user_photos;
|
|
extern const char *Ico_ClassColor[Ico_NUM_COLORS][The_NUM_THEMES];
|
|
extern const char *Txt_FIGURE_TYPES[Fig_NUM_FIGURES];
|
|
extern const char *Txt_User_photos;
|
|
extern const char *Txt_Number_of_users;
|
|
extern const char *Txt_PERCENT_of_users;
|
|
extern const char *Txt_PHOTO_SHAPES[PhoSha_NUM_SHAPES];
|
|
static const char *ClassPhoto[PhoSha_NUM_SHAPES] =
|
|
{
|
|
[PhoSha_SHAPE_CIRCLE ] = "PHOTOC15x20B",
|
|
[PhoSha_SHAPE_ELLIPSE ] = "PHOTOE15x20B",
|
|
[PhoSha_SHAPE_OVAL ] = "PHOTOO15x20B",
|
|
[PhoSha_SHAPE_RECTANGLE] = "PHOTOR15x20B",
|
|
};
|
|
PhoSha_Shape_t Shape;
|
|
char *SubQuery;
|
|
unsigned NumUsrs[PhoSha_NUM_SHAPES];
|
|
unsigned NumUsrsTotal = 0;
|
|
|
|
/***** Begin box and table *****/
|
|
Box_BoxTableBegin (NULL,Txt_FIGURE_TYPES[Fig_PHOTO_SHAPES],
|
|
NULL,NULL,
|
|
Hlp_ANALYTICS_Figures_user_photos,Box_NOT_CLOSABLE,2);
|
|
|
|
/***** Heading row *****/
|
|
HTM_TR_Begin (NULL);
|
|
HTM_TH (Txt_User_photos ,HTM_HEAD_CENTER);
|
|
HTM_TH (Txt_Number_of_users ,HTM_HEAD_RIGHT);
|
|
HTM_TH (Txt_PERCENT_of_users,HTM_HEAD_RIGHT);
|
|
HTM_TR_End ();
|
|
|
|
/***** For each user photo shape... *****/
|
|
for (Shape = (PhoSha_Shape_t) 0;
|
|
Shape <= (PhoSha_Shape_t) (PhoSha_NUM_SHAPES - 1);
|
|
Shape++)
|
|
{
|
|
/* Get the number of users who have chosen this layout of columns from database */
|
|
if (asprintf (&SubQuery,"usr_data.PhotoShape=%u",
|
|
(unsigned) Shape) < 0)
|
|
Err_NotEnoughMemoryExit ();
|
|
NumUsrs[Shape] = Usr_DB_GetNumUsrsWhoChoseAnOption (SubQuery);
|
|
free (SubQuery);
|
|
|
|
/* Update total number of users */
|
|
NumUsrsTotal += NumUsrs[Shape];
|
|
}
|
|
|
|
/***** Write number of users who have chosen this user photo shape *****/
|
|
for (Shape = (PhoSha_Shape_t) 0;
|
|
Shape <= (PhoSha_Shape_t) (PhoSha_NUM_SHAPES - 1);
|
|
Shape++)
|
|
{
|
|
HTM_TR_Begin (NULL);
|
|
|
|
HTM_TD_Begin ("class=\"CM\"");
|
|
HTM_IMG (Cfg_URL_ICON_PUBLIC,"user.svg",Txt_PHOTO_SHAPES[Shape],
|
|
"class=\"%s %s\"",
|
|
ClassPhoto[Shape],
|
|
Ico_ClassColor[Ico_BLACK][Gbl.Prefs.Theme]);
|
|
HTM_TD_End ();
|
|
|
|
HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ());
|
|
HTM_Unsigned (NumUsrs[Shape]);
|
|
HTM_TD_End ();
|
|
|
|
HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ());
|
|
HTM_Percentage (NumUsrsTotal ? (double) NumUsrs[Shape] * 100.0 /
|
|
(double) NumUsrsTotal :
|
|
0.0);
|
|
HTM_TD_End ();
|
|
|
|
HTM_TR_End ();
|
|
}
|
|
|
|
/***** End table and box *****/
|
|
Box_BoxTableEnd ();
|
|
}
|