2021-05-18 14:40:34 +02:00
|
|
|
|
// swad_banner_database.c: banners 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.
|
2024-02-07 00:40:28 +01:00
|
|
|
|
Copyright (C) 1999-2024 Antonio Ca<EFBFBD>as Vargas
|
2021-05-18 14:40:34 +02: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 "swad_banner.h"
|
|
|
|
|
#include "swad_banner_database.h"
|
|
|
|
|
#include "swad_config.h"
|
|
|
|
|
#include "swad_database.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************** Get list of all banners **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned Ban_DB_GetAllBanners (MYSQL_RES **mysql_res)
|
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get banners",
|
|
|
|
|
"SELECT BanCod," // row[0]
|
|
|
|
|
"Hidden," // row[1]
|
|
|
|
|
"ShortName," // row[2]
|
|
|
|
|
"FullName," // row[3]
|
|
|
|
|
"Img," // row[4]
|
|
|
|
|
"WWW" // row[5]
|
|
|
|
|
" FROM ban_banners"
|
|
|
|
|
" ORDER BY ShortName");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************** Get list of visible banners **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned Ban_DB_GetVisibleBanners (MYSQL_RES **mysql_res)
|
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get banners",
|
|
|
|
|
"SELECT BanCod," // row[0]
|
|
|
|
|
"Hidden," // row[1]
|
|
|
|
|
"ShortName," // row[2]
|
|
|
|
|
"FullName," // row[3]
|
|
|
|
|
"Img," // row[4]
|
|
|
|
|
"WWW" // row[5]
|
|
|
|
|
" FROM ban_banners"
|
|
|
|
|
" WHERE Hidden='N'"
|
|
|
|
|
" ORDER BY ShortName");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************** Get list of visible banners **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned Ban_DB_GetRandomBanners (MYSQL_RES **mysql_res)
|
|
|
|
|
{
|
|
|
|
|
// The banner(s) will change once in a while
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get banners",
|
|
|
|
|
"SELECT BanCod," // row[0]
|
|
|
|
|
"Hidden," // row[1]
|
|
|
|
|
"ShortName," // row[2]
|
|
|
|
|
"FullName," // row[3]
|
|
|
|
|
"Img," // row[4]
|
|
|
|
|
"WWW" // row[5]
|
|
|
|
|
" FROM ban_banners"
|
|
|
|
|
" WHERE Hidden='N'"
|
|
|
|
|
" ORDER BY RAND(%lu)"
|
|
|
|
|
" LIMIT %u",
|
2022-10-19 01:04:19 +02:00
|
|
|
|
(unsigned long) (Dat_GetStartExecutionTimeUTC () /
|
2021-05-18 14:40:34 +02:00
|
|
|
|
Cfg_TIME_TO_CHANGE_BANNER),
|
|
|
|
|
Cfg_NUMBER_OF_BANNERS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Get data of a banner from database ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
unsigned Ban_DB_GetBannerDataByCod (MYSQL_RES **mysql_res,long BanCod)
|
2021-05-18 14:40:34 +02:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get data of a banner",
|
2023-03-22 11:34:06 +01:00
|
|
|
|
"SELECT BanCod," // row[0]
|
|
|
|
|
"Hidden," // row[1]
|
|
|
|
|
"ShortName," // row[2]
|
|
|
|
|
"FullName," // row[3]
|
|
|
|
|
"Img," // row[4]
|
|
|
|
|
"WWW" // row[5]
|
2021-05-18 14:40:34 +02:00
|
|
|
|
" FROM ban_banners"
|
|
|
|
|
" WHERE BanCod=%ld",
|
|
|
|
|
BanCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Check if the name of banner exists ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-10-10 10:51:21 +02:00
|
|
|
|
bool Ban_DB_CheckIfBannerNameExists (const char *FldName,const char *Name,long Cod,
|
|
|
|
|
__attribute__((unused)) long PrtCod,
|
|
|
|
|
__attribute__((unused)) unsigned Year)
|
2021-05-18 14:40:34 +02:00
|
|
|
|
{
|
2021-11-05 23:41:26 +01:00
|
|
|
|
return
|
|
|
|
|
DB_QueryEXISTS ("can not check if the name of a banner already existed",
|
|
|
|
|
"SELECT EXISTS"
|
|
|
|
|
"(SELECT *"
|
|
|
|
|
" FROM ban_banners"
|
|
|
|
|
" WHERE %s='%s'"
|
|
|
|
|
" AND BanCod<>%ld)",
|
2023-03-10 00:13:55 +01:00
|
|
|
|
FldName,Name,
|
2023-10-10 10:51:21 +02:00
|
|
|
|
Cod);
|
2021-05-18 14:40:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************************** Create a new banner ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Ban_DB_CreateBanner (const struct Ban_Banner *Ban)
|
|
|
|
|
{
|
|
|
|
|
/***** Create a new banner *****/
|
|
|
|
|
DB_QueryINSERT ("can not create banner",
|
|
|
|
|
"INSERT INTO ban_banners"
|
|
|
|
|
" (Hidden,ShortName,FullName,Img,WWW)"
|
|
|
|
|
" VALUES"
|
|
|
|
|
" ('N','%s','%s','%s','%s')",
|
|
|
|
|
Ban->ShrtName,
|
|
|
|
|
Ban->FullName,
|
|
|
|
|
Ban->Img,
|
|
|
|
|
Ban->WWW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-10-24 16:55:47 +02:00
|
|
|
|
/**************************** Hide/unhide a banner ***************************/
|
2021-05-18 14:40:34 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-06-06 22:18:31 +02:00
|
|
|
|
void Ban_DB_HideOrUnhideBanner (long BanCod,HidVis_HiddenOrVisible_t HiddenOrVisible)
|
2021-05-18 14:40:34 +02:00
|
|
|
|
{
|
2023-09-11 17:41:31 +02:00
|
|
|
|
extern const char HidVis_YN[HidVis_NUM_HIDDEN_VISIBLE];
|
|
|
|
|
|
2021-10-24 16:55:47 +02:00
|
|
|
|
DB_QueryUPDATE ("can not hide/unhide banner",
|
2021-05-18 14:40:34 +02:00
|
|
|
|
"UPDATE ban_banners"
|
|
|
|
|
" SET Hidden='%c'"
|
|
|
|
|
" WHERE BanCod=%ld",
|
2023-09-11 17:41:31 +02:00
|
|
|
|
HidVis_YN[HiddenOrVisible],
|
2021-05-18 14:40:34 +02:00
|
|
|
|
BanCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************** Update banner name in table of banners ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-10-11 09:55:06 +02:00
|
|
|
|
void Ban_DB_UpdateBanName (long BanCod,
|
|
|
|
|
const char *FldName,const char *NewBanName)
|
2021-05-18 14:40:34 +02:00
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not update the name of a banner",
|
|
|
|
|
"UPDATE ban_banners"
|
|
|
|
|
" SET %s='%s'"
|
|
|
|
|
" WHERE BanCod=%ld",
|
2023-03-10 00:13:55 +01:00
|
|
|
|
FldName,NewBanName,
|
2021-05-18 14:40:34 +02:00
|
|
|
|
BanCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** Update the table changing old image by new image *************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Ban_DB_UpdateBanImg (long BanCod,
|
|
|
|
|
const char NewImg[Ban_MAX_BYTES_IMAGE + 1])
|
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not update the image of a banner",
|
|
|
|
|
"UPDATE ban_banners"
|
|
|
|
|
" SET Img='%s'"
|
|
|
|
|
" WHERE BanCod=%ld",
|
|
|
|
|
NewImg,
|
|
|
|
|
BanCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************** Update the table changing old WWW by new WWW ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Ban_DB_UpdateBanWWW (long BanCod,
|
|
|
|
|
const char NewWWW[Cns_MAX_BYTES_WWW + 1])
|
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not update the web of a banner",
|
|
|
|
|
"UPDATE ban_banners"
|
|
|
|
|
" SET WWW='%s'"
|
|
|
|
|
" WHERE BanCod=%ld",
|
|
|
|
|
NewWWW,
|
|
|
|
|
BanCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************************* Remove a banner *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Ban_DB_RemoveBanner (long BanCod)
|
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove a banner",
|
|
|
|
|
"DELETE FROM ban_banners"
|
|
|
|
|
" WHERE BanCod=%ld",
|
|
|
|
|
BanCod);
|
|
|
|
|
}
|