Version 21.24: Oct 05, 2021 New module swad_photo_database for database queries related to users' photos.

This commit is contained in:
acanas 2021-10-05 00:54:19 +02:00
parent 399fdea65a
commit fd5f6f97a8
10 changed files with 361 additions and 167 deletions

View File

@ -70,8 +70,9 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
swad_nickname_database.o swad_notice.o swad_notice_database.o \
swad_notification.o swad_notification_database.o \
swad_pagination.o swad_parameter.o swad_password.o \
swad_password_database.o swad_photo.o swad_place.o swad_plugin.o \
swad_privacy.o swad_profile.o swad_program.o swad_project.o \
swad_password_database.o swad_photo.o swad_photo_database.o \
swad_place.o swad_plugin.o swad_privacy.o swad_profile.o swad_program.o \
swad_project.o \
swad_QR.o \
swad_record.o swad_report.o swad_role.o swad_room.o swad_RSS.o \
swad_scope.o swad_search.o swad_session.o swad_setting.o \

View File

@ -60,6 +60,7 @@
#include "swad_notification.h"
#include "swad_notification_database.h"
#include "swad_parameter.h"
#include "swad_photo_database.h"
#include "swad_profile.h"
#include "swad_project.h"
#include "swad_report.h"

View File

@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
*/
#define Log_PLATFORM_VERSION "SWAD 21.23 (2021-10-04)"
#define Log_PLATFORM_VERSION "SWAD 21.24 (2021-10-05)"
#define CSS_FILE "swad20.45.css"
#define JS_FILE "swad20.69.1.js"
/*
TODO: Rename CENTRE to CENTER in help wiki.
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
Version 21.24: Oct 05, 2021 New module swad_photo_database for database queries related to users' photos. (318352 lines)
Version 21.23: Oct 04, 2021 New module swad_password_database for database queries related to passwords. (318197 lines)
Version 21.22: Oct 04, 2021 Queries related to notifications moved to other modules. (318066 lines)
Version 21.21.2: Oct 01, 2021 Queries moved to module swad_notification_database. (317963 lines)

View File

@ -48,6 +48,7 @@
#include "swad_HTML.h"
#include "swad_logo.h"
#include "swad_message.h"
#include "swad_photo_database.h"
#include "swad_survey.h"
/*****************************************************************************/

View File

@ -52,6 +52,7 @@
#include "swad_logo.h"
#include "swad_parameter.h"
#include "swad_photo.h"
#include "swad_photo_database.h"
#include "swad_privacy.h"
#include "swad_setting.h"
#include "swad_statistic.h"
@ -105,7 +106,6 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct UsrData *Usr
static void Pho_UpdatePhoto1 (struct UsrData *UsrDat);
static void Pho_UpdatePhoto2 (void);
static void Pho_DB_ClearPhotoName (long UsrCod);
static long Pho_GetDegWithAvgPhotoLeastRecentlyUpdated (void);
static long Pho_GetTimeAvgPhotoWasComputed (long DegCod);
@ -129,14 +129,10 @@ static void Pho_PutLinkToCalculateDegreeStats (const struct Pho_DegPhotos *DegPh
static void Pho_GetMaxStdsPerDegree (struct Pho_DegPhotos *DegPhotos);
static void Pho_ShowOrPrintClassPhotoDegrees (struct Pho_DegPhotos *DegPhotos,
Pho_AvgPhotoSeeOrPrint_t SeeOrPrint);
static void Pho_GetNumStdsInDegree (long DegCod,Usr_Sex_t Sex,int *NumStds,int *NumStdsWithPhoto);
static void Pho_ShowOrPrintListDegrees (struct Pho_DegPhotos *DegPhotos,
Pho_AvgPhotoSeeOrPrint_t SeeOrPrint);
static unsigned long Pho_DB_QueryDegrees (Pho_HowOrderDegrees_t HowOrderDegrees,
MYSQL_RES **mysql_res);
static void Pho_GetNumStdsInDegree (long DegCod,Usr_Sex_t Sex,int *NumStds,int *NumStdsWithPhoto);
static void Pho_DB_UpdateDegStats (long DegCod,Usr_Sex_t Sex,
unsigned NumStds,unsigned NumStdsWithPhoto,
long TimeToComputeAvgPhoto);
static void Pho_ShowDegreeStat (int NumStds,int NumStdsWithPhoto);
static void Pho_ShowDegreeAvgPhotoAndStat (const struct Deg_Degree *Deg,
const struct Pho_DegPhotos *DegPhotos,
@ -939,12 +935,7 @@ unsigned Pho_UpdateMyClicksWithoutPhoto (void)
unsigned NumClicks;
/***** Get number of clicks without photo from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get number of clicks"
" without photo",
"SELECT NumClicks" // row[0]
" FROM usr_clicks_without_photo"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod)) // The user exists ==> update number of clicks without photo
if (Pho_DB_GetMyClicksWithoutPhoto (&mysql_res)) // The user exists ==> update number of clicks without photo
{
/* Get current number of clicks */
row = mysql_fetch_row (mysql_res);
@ -953,23 +944,14 @@ unsigned Pho_UpdateMyClicksWithoutPhoto (void)
/* Update number of clicks */
if (NumClicks <= Pho_MAX_CLICKS_WITHOUT_PHOTO)
{
DB_QueryUPDATE ("can not update number of clicks without photo",
"UPDATE usr_clicks_without_photo"
" SET NumClicks=NumClicks+1"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod);
Pho_DB_IncrMyClicksWithoutPhoto ();
NumClicks++;
}
}
else // The user does not exist ==> add him/her
{
/* Add the user, with one access */
DB_QueryINSERT ("can not create number of clicks without photo",
"INSERT INTO usr_clicks_without_photo"
" (UsrCod,NumClicks)"
" VALUES"
" (%ld,1)",
Gbl.Usrs.Me.UsrDat.UsrCod);
Pho_DB_InitMyClicksWithoutPhoto ();
NumClicks = 1;
}
@ -980,18 +962,6 @@ unsigned Pho_UpdateMyClicksWithoutPhoto (void)
return NumClicks;
}
/*****************************************************************************/
/******** Remove user from table with number of clicks without photo *********/
/*****************************************************************************/
void Pho_DB_RemoveUsrFromTableClicksWithoutPhoto (long UsrCod)
{
DB_QueryDELETE ("can not remove a user from the list of users without photo",
"DELETE FROM usr_clicks_without_photo"
" WHERE UsrCod=%ld",
UsrCod);
}
/*****************************************************************************/
/********************* Show a user's photo if allowed ************************/
/*****************************************************************************/
@ -1296,20 +1266,6 @@ bool Pho_RemovePhoto (struct UsrData *UsrDat)
}
}
/*****************************************************************************/
/****************** Clear photo name of an user in database ******************/
/*****************************************************************************/
static void Pho_DB_ClearPhotoName (long UsrCod)
{
/***** Clear photo name in user's data *****/
DB_QueryUPDATE ("can not clear the name of a user's photo",
"UPDATE usr_data"
" SET Photo=''"
" WHERE UsrCod=%ld",
UsrCod);
}
/*****************************************************************************/
/***************** Update photo name of an user in database ******************/
/*****************************************************************************/
@ -1319,12 +1275,7 @@ void Pho_UpdatePhotoName (struct UsrData *UsrDat)
char PathPublPhoto[PATH_MAX + 1];
/***** Update photo name in database *****/
DB_QueryUPDATE ("can not update the name of a user's photo",
"UPDATE usr_data"
" SET Photo='%s'"
" WHERE UsrCod=%ld",
Gbl.UniqueNameEncrypted,
UsrDat->UsrCod);
Pho_DB_UpdatePhotoName (UsrDat->UsrCod,Gbl.UniqueNameEncrypted);
/***** Remove the old symbolic link to photo *****/
snprintf (PathPublPhoto,sizeof (PathPublPhoto),"%s/%s.jpg",
@ -1341,19 +1292,12 @@ void Pho_UpdatePhotoName (struct UsrData *UsrDat)
void Pho_ChangePhotoVisibility (void)
{
extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY];
/***** Get param with public/private photo *****/
Gbl.Usrs.Me.UsrDat.PhotoVisibility = Pri_GetParamVisibility ("VisPho",
Pri_PHOTO_ALLOWED_VIS);
/***** Store public/private photo in database *****/
DB_QueryUPDATE ("can not update your setting about photo visibility",
"UPDATE usr_data"
" SET PhotoVisibility='%s'"
" WHERE UsrCod=%ld",
Pri_VisibilityDB[Gbl.Usrs.Me.UsrDat.PhotoVisibility],
Gbl.Usrs.Me.UsrDat.UsrCod);
Set_DB_UpdateMySettingsAboutPhoto ();
/***** Show form again *****/
Set_EditSettings ();
@ -1477,19 +1421,6 @@ static long Pho_GetDegWithAvgPhotoLeastRecentlyUpdated (void)
return DegCod;
}
/*****************************************************************************/
/* Delete all the degrees in sta_degrees table not present in degrees table **/
/*****************************************************************************/
void Pho_DB_RemoveObsoleteStatDegrees (void)
{
DB_QueryDELETE ("can not remove old degrees from stats",
"DELETE FROM sta_degrees"
" WHERE DegCod NOT IN"
" (SELECT DegCod"
" FROM deg_degrees)");
}
/*****************************************************************************/
/***************** Get time when average photo was computed ******************/
/*****************************************************************************/
@ -2131,9 +2062,7 @@ static void Pho_ShowOrPrintClassPhotoDegrees (struct Pho_DegPhotos *DegPhotos,
bool TRIsOpen = false;
/***** Get degrees from database *****/
NumDegs = Pho_DB_QueryDegrees (DegPhotos->HowOrderDegrees,&mysql_res);
if (NumDegs) // Degrees with students found
if ((NumDegs = Pho_DB_QueryDegrees (&mysql_res,DegPhotos->HowOrderDegrees))) // Degrees with students found
{
/***** Form to select type of list used to display degree photos *****/
if (SeeOrPrint == Pho_DEGREES_SEE)
@ -2213,9 +2142,7 @@ static void Pho_ShowOrPrintListDegrees (struct Pho_DegPhotos *DegPhotos,
Usr_Sex_t Sex;
/***** Get degrees from database *****/
NumDegs = Pho_DB_QueryDegrees (DegPhotos->HowOrderDegrees,&mysql_res);
if (NumDegs) // Degrees with students found
if ((NumDegs = Pho_DB_QueryDegrees (&mysql_res,DegPhotos->HowOrderDegrees))) // Degrees with students found
{
/***** Class photo start *****/
if (SeeOrPrint == Pho_DEGREES_SEE)
@ -2299,62 +2226,6 @@ static void Pho_ShowOrPrintListDegrees (struct Pho_DegPhotos *DegPhotos,
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/****** Build a query to get the degrees ordered by different criteria *******/
/*****************************************************************************/
static unsigned long Pho_DB_QueryDegrees (Pho_HowOrderDegrees_t HowOrderDegrees,
MYSQL_RES **mysql_res)
{
switch (HowOrderDegrees)
{
case Pho_NUMBER_OF_STUDENTS:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY sta_degrees.NumStds DESC,"
"sta_degrees.NumStdsWithPhoto DESC,"
"deg_degrees.ShortName");
case Pho_NUMBER_OF_PHOTOS:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY sta_degrees.NumStdsWithPhoto DESC,"
"sta_degrees.NumStds DESC,"
"deg_degrees.ShortName");
case Pho_PERCENT:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY sta_degrees.NumStdsWithPhoto/"
"sta_degrees.NumStds DESC,"
"deg_degrees.ShortName");
case Pho_DEGREE_NAME:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY deg_degrees.ShortName");
}
return 0;
}
/*****************************************************************************/
/*** Get number of students and number of students with photo in a degree ****/
/*****************************************************************************/
@ -2389,29 +2260,6 @@ static void Pho_GetNumStdsInDegree (long DegCod,Usr_Sex_t Sex,int *NumStds,int *
}
}
/*****************************************************************************/
/*********************** Update statistics of a degree ***********************/
/*****************************************************************************/
static void Pho_DB_UpdateDegStats (long DegCod,Usr_Sex_t Sex,
unsigned NumStds,unsigned NumStdsWithPhoto,
long TimeToComputeAvgPhotoInMicroseconds)
{
extern const char *Usr_StringsSexDB[Usr_NUM_SEXS];
DB_QueryREPLACE ("can not save stats of a degree",
"REPLACE INTO sta_degrees"
" (DegCod,Sex,NumStds,NumStdsWithPhoto,"
"TimeAvgPhoto,TimeToComputeAvgPhoto)"
" VALUES"
" (%ld,'%s',%u,%u,NOW(),%ld)",
DegCod,
Usr_StringsSexDB[Sex],
NumStds,
NumStdsWithPhoto,
TimeToComputeAvgPhotoInMicroseconds);
}
/*****************************************************************************/
/******************* Show the average photo of a degree **********************/
/*****************************************************************************/

View File

@ -114,7 +114,6 @@ void Pho_UpdateUsrPhoto1 (void);
void Pho_UpdateUsrPhoto2 (void);
unsigned Pho_UpdateMyClicksWithoutPhoto (void);
void Pho_DB_RemoveUsrFromTableClicksWithoutPhoto (long UsrCod);
void Pho_ShowUsrPhotoIfAllowed (struct UsrData *UsrDat,
const char *ClassPhoto,Pho_Zoom_t Zoom,
@ -133,7 +132,6 @@ void Pho_UpdatePhotoName (struct UsrData *UsrDat);
void Pho_ChangePhotoVisibility (void);
void Pho_CalcPhotoDegree (void);
void Pho_DB_RemoveObsoleteStatDegrees (void);
void Pho_ShowPhotoDegree (void);
void Pho_PrintPhotoDegree (void);

263
swad_photo_database.c Normal file
View File

@ -0,0 +1,263 @@
// swad_photo_database.c: Users' photos management, operations with database
/*
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 <linux/limits.h> // For PATH_MAX
// #include <math.h> // For log10, floor, ceil, modf, sqrt...
// #include <stddef.h> // For NULL
// #include <stdio.h> // For asprintf
// #include <stdlib.h> // For system, getenv, etc.
// #include <string.h> // For string functions
// #include <sys/wait.h> // For the macro WEXITSTATUS
// #include <unistd.h> // For unlink
// #include "swad_action.h"
// #include "swad_box.h"
// #include "swad_browser.h"
// #include "swad_config.h"
#include "swad_database.h"
// #include "swad_enrolment.h"
// #include "swad_error.h"
// #include "swad_file.h"
// #include "swad_follow.h"
// #include "swad_form.h"
#include "swad_global.h"
// #include "swad_hierarchy.h"
// #include "swad_hierarchy_level.h"
// #include "swad_HTML.h"
// #include "swad_logo.h"
// #include "swad_parameter.h"
// #include "swad_photo.h"
#include "swad_photo_database.h"
// #include "swad_privacy.h"
// #include "swad_setting.h"
// #include "swad_statistic.h"
// #include "swad_theme.h"
// #include "swad_user.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
/*****************************************************************************/
/****************** Clear photo name of an user in database ******************/
/*****************************************************************************/
void Pho_DB_ClearPhotoName (long UsrCod)
{
DB_QueryUPDATE ("can not clear the name of a user's photo",
"UPDATE usr_data"
" SET Photo=''"
" WHERE UsrCod=%ld",
UsrCod);
}
/*****************************************************************************/
/***************** Update photo name of an user in database ******************/
/*****************************************************************************/
void Pho_DB_UpdatePhotoName (long UsrCod,
const char UniqueNameEncrypted[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1])
{
DB_QueryUPDATE ("can not update the name of a user's photo",
"UPDATE usr_data"
" SET Photo='%s'"
" WHERE UsrCod=%ld",
UniqueNameEncrypted,
UsrCod);
}
/*****************************************************************************/
/*************** Initialize my number of clicks without photo ****************/
/*****************************************************************************/
void Pho_DB_InitMyClicksWithoutPhoto (void)
{
DB_QueryINSERT ("can not create number of clicks without photo",
"INSERT INTO usr_clicks_without_photo"
" (UsrCod,NumClicks)"
" VALUES"
" (%ld,1)",
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/*************** Increment my number of clicks without photo *****************/
/*****************************************************************************/
void Pho_DB_IncrMyClicksWithoutPhoto (void)
{
DB_QueryUPDATE ("can not update number of clicks without photo",
"UPDATE usr_clicks_without_photo"
" SET NumClicks=NumClicks+1"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/************ Get number of clicks without photo from database ***************/
/*****************************************************************************/
unsigned Pho_DB_GetMyClicksWithoutPhoto (MYSQL_RES **mysql_res)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get number of clicks without photo",
"SELECT NumClicks" // row[0]
" FROM usr_clicks_without_photo"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/******** Remove user from table with number of clicks without photo *********/
/*****************************************************************************/
void Pho_DB_RemoveUsrFromTableClicksWithoutPhoto (long UsrCod)
{
DB_QueryDELETE ("can not remove a user from the list of users without photo",
"DELETE FROM usr_clicks_without_photo"
" WHERE UsrCod=%ld",
UsrCod);
}
/*****************************************************************************/
/*********************** Update statistics of a degree ***********************/
/*****************************************************************************/
void Pho_DB_UpdateDegStats (long DegCod,Usr_Sex_t Sex,
unsigned NumStds,unsigned NumStdsWithPhoto,
long TimeToComputeAvgPhotoInMicroseconds)
{
extern const char *Usr_StringsSexDB[Usr_NUM_SEXS];
DB_QueryREPLACE ("can not save stats of a degree",
"REPLACE INTO sta_degrees"
" (DegCod,Sex,NumStds,NumStdsWithPhoto,"
"TimeAvgPhoto,TimeToComputeAvgPhoto)"
" VALUES"
" (%ld,'%s',%u,%u,NOW(),%ld)",
DegCod,
Usr_StringsSexDB[Sex],
NumStds,
NumStdsWithPhoto,
TimeToComputeAvgPhotoInMicroseconds);
}
/*****************************************************************************/
/****** Build a query to get the degrees ordered by different criteria *******/
/*****************************************************************************/
unsigned Pho_DB_QueryDegrees (MYSQL_RES **mysql_res,
Pho_HowOrderDegrees_t HowOrderDegrees)
{
switch (HowOrderDegrees)
{
case Pho_NUMBER_OF_STUDENTS:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,"
"sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY sta_degrees.NumStds DESC,"
"sta_degrees.NumStdsWithPhoto DESC,"
"deg_degrees.ShortName");
case Pho_NUMBER_OF_PHOTOS:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,"
"sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY sta_degrees.NumStdsWithPhoto DESC,"
"sta_degrees.NumStds DESC,"
"deg_degrees.ShortName");
case Pho_PERCENT:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,"
"sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY sta_degrees.NumStdsWithPhoto/"
"sta_degrees.NumStds DESC,"
"deg_degrees.ShortName");
case Pho_DEGREE_NAME:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,"
"sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY deg_degrees.ShortName");
}
return 0;
}
/*****************************************************************************/
/* Delete all the degrees in sta_degrees table not present in degrees table **/
/*****************************************************************************/
void Pho_DB_RemoveObsoleteStatDegrees (void)
{
DB_QueryDELETE ("can not remove old degrees from stats",
"DELETE FROM sta_degrees"
" WHERE DegCod NOT IN"
" (SELECT DegCod"
" FROM deg_degrees)");
}

64
swad_photo_database.h Normal file
View File

@ -0,0 +1,64 @@
// swad_photo_database.h: Users' photos management, operations with database
#ifndef _SWAD_PHO_DB
#define _SWAD_PHO_DB
/*
SWAD (Shared Workspace At a Distance in Spanish),
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 ***********************************/
/*****************************************************************************/
#include <mysql/mysql.h> // To access MySQL databases
#include "swad_cryptography.h"
#include "swad_photo.h"
// #include "swad_user.h"
/*****************************************************************************/
/************************* Public types and constants ************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Public prototypes *****************************/
/*****************************************************************************/
void Pho_DB_ClearPhotoName (long UsrCod);
void Pho_DB_UpdatePhotoName (long UsrCod,
const char UniqueNameEncrypted[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1]);
//-------------------------- Clicks without photo -----------------------------
void Pho_DB_InitMyClicksWithoutPhoto (void);
void Pho_DB_IncrMyClicksWithoutPhoto (void);
unsigned Pho_DB_GetMyClicksWithoutPhoto (MYSQL_RES **mysql_res);
void Pho_DB_RemoveUsrFromTableClicksWithoutPhoto (long UsrCod);
//------------------------ Statistics about degrees ---------------------------
void Pho_DB_UpdateDegStats (long DegCod,Usr_Sex_t Sex,
unsigned NumStds,unsigned NumStdsWithPhoto,
long TimeToComputeAvgPhotoInMicroseconds);
unsigned Pho_DB_QueryDegrees (MYSQL_RES **mysql_res,
Pho_HowOrderDegrees_t HowOrderDegrees);
void Pho_DB_RemoveObsoleteStatDegrees (void);
#endif

View File

@ -411,6 +411,22 @@ void Set_DB_UpdateMySettingsAboutMenu (Mnu_Menu_t Menu)
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/***************** Update my settings about photo visibility *****************/
/*****************************************************************************/
void Set_DB_UpdateMySettingsAboutPhoto (void)
{
extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY];
DB_QueryUPDATE ("can not update user's settings",
"UPDATE usr_data"
" SET PhotoVisibility='%s'"
" WHERE UsrCod=%ld",
Pri_VisibilityDB[Gbl.Usrs.Me.UsrDat.PhotoVisibility],
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/******************* Update my settings about notify events ******************/
/*****************************************************************************/

View File

@ -55,6 +55,7 @@ void Set_DB_UpdateMySettingsAboutDateFormat (Dat_Format_t DateFormat);
void Set_DB_UpdateMySettingsAboutFirstDayOfWeek (unsigned FirstDayOfWeek);
void Set_DB_UpdateMySettingsAboutIconSet (const char *IconSetId);
void Set_DB_UpdateMySettingsAboutMenu (Mnu_Menu_t Menu);
void Set_DB_UpdateMySettingsAboutPhoto (void);
void Set_DB_UpdateMySettingsAboutNotifyEvents (void);
void Set_BeginSettingsHead (void);