swad-core/swad_banner.c

1197 lines
39 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_banner.c: banners
/*
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.
2020-01-01 14:53:57 +01:00
Copyright (C) 1999-2020 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 ***********************************/
/*****************************************************************************/
2019-12-29 12:39:00 +01:00
#include <stddef.h> // For NULL
2014-12-01 23:55:08 +01:00
#include <stdlib.h> // For calloc
#include <string.h> // For string functions
#include "swad_banner.h"
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2014-12-01 23:55:08 +01:00
#include "swad_constant.h"
#include "swad_database.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2018-12-08 16:43:13 +01:00
#include "swad_language.h"
2014-12-01 23:55:08 +01:00
#include "swad_parameter.h"
#include "swad_photo.h"
2020-04-06 17:16:31 +02:00
// struct Ban_Banners Ban_Banners;
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
2020-04-06 17:16:31 +02:00
struct Ban_Banners
{
unsigned Num; // Number of banners
2020-04-08 03:06:45 +02:00
struct Ban_Banner *Lst; // List of banners
2020-04-06 17:16:31 +02:00
long BanCodToEdit; // Used as parameter in contextual links
long BanCodClicked; // Banned clicked, used to log it
};
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static struct Ban_Banner *Ban_EditingBan;
2020-04-06 17:16:31 +02:00
static long Ban_BanCodClicked;
2019-04-09 14:46:32 +02:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Ban_SetEditingBanner (struct Ban_Banner *Ban);
static struct Ban_Banner *Ban_GetEditingBanner (void);
2020-04-06 17:16:31 +02:00
static void Ban_WriteListOfBanners (const struct Ban_Banners *Banners);
2020-04-08 03:06:45 +02:00
static void Ban_PutIconsListingBanners (void *Banners);
2018-11-16 00:24:44 +01:00
static void Ban_PutIconToEditBanners (void);
2020-04-06 17:16:31 +02:00
static void Ban_EditBannersInternal (struct Ban_Banners *Banners,
2020-04-08 03:06:45 +02:00
const struct Ban_Banner *Ban);
2020-04-06 17:16:31 +02:00
static void Ban_GetListBanners (struct Ban_Banners *Banners,
MYSQL_RES **mysql_res,unsigned long NumRows);
static void Ban_FreeListBanners (struct Ban_Banners *Banners);
2018-11-16 00:24:44 +01:00
2020-04-08 03:06:45 +02:00
static void Ban_PutIconsEditingBanners (void *Banners);
2018-11-16 00:24:44 +01:00
2020-04-06 17:16:31 +02:00
static void Ban_ListBannersForEdition (struct Ban_Banners *Banners);
static void Ban_PutParamBanCodToEdit (void *BanCod);
2014-12-01 23:55:08 +01:00
static void Ban_PutParamBanCod (long BanCod);
2020-04-08 03:06:45 +02:00
static void Ban_ShowOrHideBanner (struct Ban_Banner *Ban,bool Hide);
2017-03-09 11:16:17 +01:00
2020-04-08 03:06:45 +02:00
static void Ban_RenameBanner (struct Ban_Banner *Ban,
2020-04-06 17:16:31 +02:00
Cns_ShrtOrFullName_t ShrtOrFullName);
2014-12-01 23:55:08 +01:00
static bool Ban_CheckIfBannerNameExists (const char *FieldName,const char *Name,long BanCod);
2018-10-27 22:08:01 +02:00
static void Ban_UpdateBanNameDB (long BanCod,const char *FieldName,
const char *NewBanName);
2017-03-09 11:16:17 +01:00
2020-04-08 03:06:45 +02:00
static void Ban_PutFormToCreateBanner (const struct Ban_Banner *Ban);
2014-12-01 23:55:08 +01:00
static void Ban_PutHeadBanners (void);
2020-04-08 03:06:45 +02:00
static void Ban_CreateBanner (const struct Ban_Banner *Ban);
2014-12-01 23:55:08 +01:00
2020-04-06 17:16:31 +02:00
static void Ban_SetBanCodClicked (long BanCod);
static void Ban_ResetBanners (struct Ban_Banners *Banners);
2020-04-08 03:06:45 +02:00
static void Ban_ResetBanner (struct Ban_Banner *Ban);
2020-04-06 17:16:31 +02:00
/*****************************************************************************/
/************************** Access to editing banner *************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Ban_SetEditingBanner (struct Ban_Banner *Ban)
2020-04-06 17:16:31 +02:00
{
Ban_EditingBan = Ban;
}
2020-04-08 03:06:45 +02:00
static struct Ban_Banner *Ban_GetEditingBanner (void)
2020-04-06 17:16:31 +02:00
{
return Ban_EditingBan;
}
2019-04-09 14:46:32 +02:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-03-27 10:13:34 +02:00
/***************************** List all banners ******************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
void Ban_SeeBanners (void)
{
2016-11-28 10:04:44 +01:00
extern const char *Hlp_SYSTEM_Banners;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Banners;
2017-03-27 10:13:34 +02:00
extern const char *Txt_No_banners;
2017-03-27 13:38:10 +02:00
extern const char *Txt_New_banner;
2020-04-06 17:16:31 +02:00
struct Ban_Banners Banners;
2018-10-30 13:59:37 +01:00
MYSQL_RES *mysql_res;
unsigned long NumRows;
2014-12-01 23:55:08 +01:00
2020-04-06 17:16:31 +02:00
/***** Reset banners *****/
Ban_ResetBanners (&Banners);
2014-12-01 23:55:08 +01:00
/***** Get list of banners *****/
2018-10-30 13:59:37 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get banners",
"SELECT BanCod,Hidden,ShortName,FullName,Img,WWW"
" FROM banners"
" WHERE Hidden='N'"
" ORDER BY ShortName");
2020-04-06 17:16:31 +02:00
Ban_GetListBanners (&Banners,&mysql_res,NumRows);
2014-12-01 23:55:08 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_Banners,
2020-04-08 03:06:45 +02:00
Ban_PutIconsListingBanners,&Banners,
2017-06-12 15:03:29 +02:00
Hlp_SYSTEM_Banners,Box_NOT_CLOSABLE);
2017-03-27 10:13:34 +02:00
2017-06-12 14:16:33 +02:00
/***** Write all banners *****/
2020-04-06 17:16:31 +02:00
if (Banners.Num) // There are banners
Ban_WriteListOfBanners (&Banners);
2017-03-27 10:13:34 +02:00
else // No banners created
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_INFO,Txt_No_banners);
2017-03-27 10:13:34 +02:00
/***** Button to create banner *****/
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
2017-03-27 10:13:34 +02:00
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActEdiBan);
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButton (Txt_New_banner);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-03-27 10:13:34 +02:00
}
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2017-03-27 10:13:34 +02:00
/***** Free list of banners *****/
2020-04-06 17:16:31 +02:00
Ban_FreeListBanners (&Banners);
2017-03-27 10:13:34 +02:00
}
/*****************************************************************************/
/*************************** Write list of banners ***************************/
/*****************************************************************************/
2020-04-06 17:16:31 +02:00
static void Ban_WriteListOfBanners (const struct Ban_Banners *Banners)
2017-03-27 10:13:34 +02:00
{
unsigned NumBan;
/***** List start *****/
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("class=\"LIST_LEFT\"");
2014-12-01 23:55:08 +01:00
/***** Write all the banners *****/
for (NumBan = 0;
2020-04-06 17:16:31 +02:00
NumBan < Banners->Num;
2014-12-01 23:55:08 +01:00
NumBan++)
2019-10-26 22:49:13 +02:00
{
2014-12-01 23:55:08 +01:00
/* Write data of this banner */
2019-10-26 22:49:13 +02:00
HTM_LI_Begin (NULL);
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"%s\" title=\"%s\" class=\"DAT\" target=\"_blank\"",
2020-04-06 17:16:31 +02:00
Banners->Lst[NumBan].WWW,
Banners->Lst[NumBan].FullName);
HTM_IMG (Cfg_URL_BANNER_PUBLIC,Banners->Lst[NumBan].Img,Banners->Lst[NumBan].FullName,
2019-10-30 22:31:03 +01:00
"class=\"BANNER\"");
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-10-26 22:49:13 +02:00
HTM_LI_End ();
}
2014-12-01 23:55:08 +01:00
2017-03-27 10:13:34 +02:00
/***** List end *****/
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2018-11-16 00:24:44 +01:00
/***************** Put contextual icons in list of banners *******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Ban_PutIconsListingBanners (void *Banners)
2014-12-01 23:55:08 +01:00
{
2020-04-08 03:06:45 +02:00
if (Banners) // Not used
2020-03-26 02:54:30 +01:00
{
/***** Put icon to view banners *****/
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
Ban_PutIconToEditBanners ();
2018-11-16 00:24:44 +01:00
2020-03-26 02:54:30 +01:00
/***** Put icon to view links *****/
Lnk_PutIconToViewLinks ();
}
2018-11-16 00:24:44 +01:00
}
/*****************************************************************************/
/************************* Put an icon to edit banners ***********************/
/*****************************************************************************/
static void Ban_PutIconToEditBanners (void)
{
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToEdit (ActEdiBan,NULL,
NULL,NULL);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************** Put forms to edit banners ************************/
/*****************************************************************************/
void Ban_EditBanners (void)
2019-04-09 14:46:32 +02:00
{
2020-04-06 17:16:31 +02:00
struct Ban_Banners Banners;
2020-04-08 03:06:45 +02:00
struct Ban_Banner Ban;
2019-04-09 14:46:32 +02:00
2020-04-06 17:16:31 +02:00
/***** Reset banners *****/
Ban_ResetBanners (&Banners);
/***** Reset banner *****/
Ban_ResetBanner (&Ban);
2019-04-09 14:46:32 +02:00
2020-04-06 17:16:31 +02:00
/***** Edit banners *****/
Ban_EditBannersInternal (&Banners,&Ban);
2019-04-09 14:46:32 +02:00
}
2020-04-06 17:16:31 +02:00
static void Ban_EditBannersInternal (struct Ban_Banners *Banners,
2020-04-08 03:06:45 +02:00
const struct Ban_Banner *Ban)
2014-12-01 23:55:08 +01:00
{
2017-06-03 17:53:51 +02:00
extern const char *Hlp_SYSTEM_Banners_edit;
extern const char *Txt_Banners;
2018-10-30 13:59:37 +01:00
MYSQL_RES *mysql_res;
unsigned long NumRows;
2017-06-03 17:53:51 +02:00
2014-12-01 23:55:08 +01:00
/***** Get list of banners *****/
2018-10-30 13:59:37 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get banners",
"SELECT BanCod,Hidden,ShortName,FullName,Img,WWW"
" FROM banners ORDER BY ShortName");
2020-04-06 17:16:31 +02:00
Ban_GetListBanners (Banners,&mysql_res,NumRows);
2014-12-01 23:55:08 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_Banners,
2020-04-08 03:06:45 +02:00
Ban_PutIconsEditingBanners,Banners,
2017-06-12 15:03:29 +02:00
Hlp_SYSTEM_Banners_edit,Box_NOT_CLOSABLE);
2017-06-03 17:53:51 +02:00
2014-12-01 23:55:08 +01:00
/***** Put a form to create a new banner *****/
2020-04-06 17:16:31 +02:00
Ban_PutFormToCreateBanner (Ban);
2014-12-01 23:55:08 +01:00
/***** Forms to edit current banners *****/
2020-04-06 17:16:31 +02:00
if (Banners->Num)
Ban_ListBannersForEdition (Banners);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2017-06-03 17:53:51 +02:00
2014-12-01 23:55:08 +01:00
/***** Free list of banners *****/
2020-04-06 17:16:31 +02:00
Ban_FreeListBanners (Banners);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************************** List all the banners ***************************/
/*****************************************************************************/
2020-04-06 17:16:31 +02:00
static void Ban_GetListBanners (struct Ban_Banners *Banners,
MYSQL_RES **mysql_res,unsigned long NumRows)
2014-12-01 23:55:08 +01:00
{
MYSQL_ROW row;
unsigned NumBan;
2020-04-08 03:06:45 +02:00
struct Ban_Banner *Ban;
2014-12-01 23:55:08 +01:00
2018-10-30 13:59:37 +01:00
/***** Get banners from database *****/
if (NumRows) // Banners found...
2014-12-01 23:55:08 +01:00
{
2020-04-06 17:16:31 +02:00
Banners->Num = (unsigned) NumRows;
2014-12-01 23:55:08 +01:00
2018-10-30 13:59:37 +01:00
/***** Create list with banners *****/
2020-04-08 03:06:45 +02:00
if ((Banners->Lst = (struct Ban_Banner *)
calloc (NumRows,sizeof (struct Ban_Banner))) == NULL)
2018-10-30 13:59:37 +01:00
Lay_NotEnoughMemoryExit ();
2014-12-01 23:55:08 +01:00
2018-10-30 13:59:37 +01:00
/***** Get the banners *****/
for (NumBan = 0;
2020-04-06 17:16:31 +02:00
NumBan < Banners->Num;
2018-10-30 13:59:37 +01:00
NumBan++)
{
2020-04-06 17:16:31 +02:00
Ban = &(Banners->Lst[NumBan]);
2014-12-01 23:55:08 +01:00
2018-10-30 13:59:37 +01:00
/* Get next banner */
row = mysql_fetch_row (*mysql_res);
2014-12-01 23:55:08 +01:00
2018-10-30 13:59:37 +01:00
/* Get banner code (row[0]) */
if ((Ban->BanCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of banner.");
2014-12-01 23:55:08 +01:00
2018-10-30 13:59:37 +01:00
/* Get if banner is hidden (row[1]) */
Ban->Hidden = (row[1][0] == 'Y');
2014-12-01 23:55:08 +01:00
2018-10-30 13:59:37 +01:00
/* Get the short name of the banner (row[2]) */
Str_Copy (Ban->ShrtName,row[2],
Ban_MAX_BYTES_SHRT_NAME);
2014-12-01 23:55:08 +01:00
2018-10-30 13:59:37 +01:00
/* Get the full name of the banner (row[3]) */
Str_Copy (Ban->FullName,row[3],
Ban_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
2018-10-30 13:59:37 +01:00
/* Get the image of the banner (row[4]) */
Str_Copy (Ban->Img,row[4],
Ban_MAX_BYTES_IMAGE);
2014-12-01 23:55:08 +01:00
2018-10-30 13:59:37 +01:00
/* Get the URL of the banner (row[5]) */
Str_Copy (Ban->WWW,row[5],
Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
}
}
2018-10-30 13:59:37 +01:00
else
2020-04-06 17:16:31 +02:00
Banners->Num = 0;
2018-10-30 13:59:37 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (mysql_res);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************************** Get banner full name ****************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
void Ban_GetDataOfBannerByCod (struct Ban_Banner *Ban)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
/***** Clear data *****/
2016-09-07 18:48:10 +02:00
Ban->Hidden = false;
2016-10-28 10:03:37 +02:00
Ban->ShrtName[0] = Ban->FullName[0] = Ban->Img[0] = Ban->WWW[0] = '\0';
2014-12-01 23:55:08 +01:00
/***** Check if banner code is correct *****/
if (Ban->BanCod > 0)
{
/***** Get data of a banner from database *****/
2018-10-30 13:59:37 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a banner",
"SELECT Hidden,ShortName,FullName,Img,WWW"
" FROM banners WHERE BanCod=%ld",
Ban->BanCod);
2014-12-01 23:55:08 +01:00
if (NumRows) // Banner found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);
2015-02-08 14:29:44 +01:00
/* Get if the banner is hidden (row[0]) */
2016-09-07 18:48:10 +02:00
Ban->Hidden = (row[0][0] == 'Y');
2014-12-01 23:55:08 +01:00
2015-02-08 14:29:44 +01:00
/* Get the short name of the banner (row[1]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Ban->ShrtName,row[1],
2017-03-07 01:56:41 +01:00
Ban_MAX_BYTES_SHRT_NAME);
2014-12-01 23:55:08 +01:00
2015-02-08 14:29:44 +01:00
/* Get the full name of the banner (row[2]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Ban->FullName,row[2],
2017-03-07 01:56:41 +01:00
Ban_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
2015-02-08 14:29:44 +01:00
/* Get the image of the banner (row[3]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Ban->Img,row[3],
2017-03-07 01:56:41 +01:00
Ban_MAX_BYTES_IMAGE);
2015-02-08 14:29:44 +01:00
/* Get the URL of the banner (row[4]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Ban->WWW,row[4],
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
}
/*****************************************************************************/
/*************************** Free list of banners ****************************/
/*****************************************************************************/
2020-04-06 17:16:31 +02:00
static void Ban_FreeListBanners (struct Ban_Banners *Banners)
2014-12-01 23:55:08 +01:00
{
2020-04-06 17:16:31 +02:00
if (Banners->Lst)
2014-12-01 23:55:08 +01:00
{
/***** Free memory used by the list of banners *****/
2020-04-06 17:16:31 +02:00
free (Banners->Lst);
Banners->Lst = NULL;
Banners->Num = 0;
2014-12-01 23:55:08 +01:00
}
}
2017-06-03 17:53:51 +02:00
/*****************************************************************************/
/**************** Put contextual icons in edition of banners *****************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Ban_PutIconsEditingBanners (void *Banners)
2017-06-03 17:53:51 +02:00
{
2020-04-08 03:06:45 +02:00
if (Banners) // Not used
2020-03-26 02:54:30 +01:00
{
/***** Put icon to view banners *****/
Ban_PutIconToViewBanners ();
2018-11-16 00:24:44 +01:00
2020-03-26 02:54:30 +01:00
/***** Put icon to view links *****/
Lnk_PutIconToViewLinks ();
}
2018-11-16 00:24:44 +01:00
}
/*****************************************************************************/
/************************* Put icon to view banners **************************/
/*****************************************************************************/
void Ban_PutIconToViewBanners (void)
{
extern const char *Txt_Banners;
2020-03-26 02:54:30 +01:00
Lay_PutContextualLinkOnlyIcon (ActSeeBan,NULL,
NULL,NULL,
2019-01-12 03:00:59 +01:00
"flag.svg",
Txt_Banners);
2017-06-03 17:53:51 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*************************** List all the banners ****************************/
/*****************************************************************************/
2020-04-06 17:16:31 +02:00
static void Ban_ListBannersForEdition (struct Ban_Banners *Banners)
2014-12-01 23:55:08 +01:00
{
unsigned NumBan;
2020-04-08 03:06:45 +02:00
struct Ban_Banner *Ban;
2019-04-20 22:18:38 +02:00
char *Anchor = NULL;
2014-12-01 23:55:08 +01:00
2019-10-20 22:00:28 +02:00
/***** Begin table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWidePadding (2);
2014-12-01 23:55:08 +01:00
/***** Table head *****/
Ban_PutHeadBanners ();
/***** Write all the banners *****/
for (NumBan = 0;
2020-04-06 17:16:31 +02:00
NumBan < Banners->Num;
2014-12-01 23:55:08 +01:00
NumBan++)
{
2020-04-06 17:16:31 +02:00
Ban = &Banners->Lst[NumBan];
Banners->BanCodToEdit = Ban->BanCod;
2014-12-01 23:55:08 +01:00
2019-04-20 22:18:38 +02:00
/* Set anchor string */
Frm_SetAnchorStr (Ban->BanCod,&Anchor);
2014-12-01 23:55:08 +01:00
/* Put icon to remove banner */
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 23:02:50 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BM\"");
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToRemove (ActRemBan,
2020-04-06 17:16:31 +02:00
Ban_PutParamBanCodToEdit,&Banners->BanCodToEdit);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Put icon to hide/show banner */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BM\"");
2019-04-20 12:31:43 +02:00
if (Ban->Hidden)
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToUnhide (ActShoBan,Anchor,
2020-04-06 17:16:31 +02:00
Ban_PutParamBanCodToEdit,&Banners->BanCodToEdit);
2019-04-20 12:31:43 +02:00
else
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToHide (ActHidBan,Anchor,
2020-04-06 17:16:31 +02:00
Ban_PutParamBanCodToEdit,&Banners->BanCodToEdit);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Banner code */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM\"",
2019-10-10 23:14:13 +02:00
Ban->Hidden ? "DAT_LIGHT" :
"DAT");
2019-10-26 01:56:36 +02:00
HTM_ARTICLE_Begin (Anchor);
2019-11-10 13:38:17 +01:00
HTM_Long (Ban->BanCod);
2019-10-26 01:56:36 +02:00
HTM_ARTICLE_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Banner short name */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CM\"");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRenBanSho);
2020-04-06 17:16:31 +02:00
Ban_PutParamBanCodToEdit (&Banners->BanCodToEdit);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("ShortName",Ban_MAX_CHARS_SHRT_NAME,Ban->ShrtName,true,
"class=\"INPUT_SHORT_NAME\"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Banner full name */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CM\"");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRenBanFul);
2020-04-06 17:16:31 +02:00
Ban_PutParamBanCodToEdit (&Banners->BanCodToEdit);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("FullName",Ban_MAX_CHARS_FULL_NAME,Ban->FullName,true,
"class=\"INPUT_FULL_NAME\"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Banner image */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CM\"");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgBanImg);
2020-04-06 17:16:31 +02:00
Ban_PutParamBanCodToEdit (&Banners->BanCodToEdit);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("Img",Ban_MAX_CHARS_IMAGE,Ban->Img,true,
"size=\"12\"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Banner WWW */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CM\"");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgBanWWW);
2020-04-06 17:16:31 +02:00
Ban_PutParamBanCodToEdit (&Banners->BanCodToEdit);
2019-11-04 12:25:48 +01:00
HTM_INPUT_URL ("WWW",Ban->WWW,true,
2019-12-19 11:00:14 +01:00
"class=\"INPUT_WWW_NARROW\" required=\"required\"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 23:02:50 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-04-20 22:18:38 +02:00
/* Free anchor string */
Frm_FreeAnchorStr (Anchor);
2014-12-01 23:55:08 +01:00
}
2017-06-03 17:53:51 +02:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Write parameter with code of banner *********************/
/*****************************************************************************/
2020-04-06 17:16:31 +02:00
static void Ban_PutParamBanCodToEdit (void *BanCod)
2019-04-20 12:31:43 +02:00
{
2020-04-06 17:16:31 +02:00
if (BanCod)
Ban_PutParamBanCod (*((long *) BanCod));
2019-04-20 12:31:43 +02:00
}
2014-12-01 23:55:08 +01:00
static void Ban_PutParamBanCod (long BanCod)
{
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamLong (NULL,"BanCod",BanCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Get parameter with code of banner **********************/
/*****************************************************************************/
long Ban_GetParamBanCod (void)
{
2017-01-28 20:32:50 +01:00
/***** Get code of banner *****/
return Par_GetParToLong ("BanCod");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************************* Remove a banner *****************************/
/*****************************************************************************/
void Ban_RemoveBanner (void)
{
extern const char *Txt_Banner_X_removed;
2020-04-08 03:06:45 +02:00
struct Ban_Banner Ban;
2019-04-09 14:46:32 +02:00
2020-04-06 17:16:31 +02:00
/***** Reset banner *****/
Ban_ResetBanner (&Ban);
2014-12-01 23:55:08 +01:00
/***** Get banner code *****/
2020-04-06 17:16:31 +02:00
if ((Ban.BanCod = Ban_GetParamBanCod ()) == -1L)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Code of banner is missing.");
/***** Get data of the banner from database *****/
2020-04-06 17:16:31 +02:00
Ban_GetDataOfBannerByCod (&Ban);
2014-12-01 23:55:08 +01:00
/***** Remove banner *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove a banner",
"DELETE FROM banners WHERE BanCod=%ld",
2020-04-06 17:16:31 +02:00
Ban.BanCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-04-09 14:46:32 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Banner_X_removed,
2020-04-06 17:16:31 +02:00
Ban.ShrtName);
/***** Set editing banner to use ot in a posterior function *****/
Ban_SetEditingBanner (&Ban);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************************** Show a hidden banner ***************************/
/*****************************************************************************/
void Ban_ShowBanner (void)
{
2020-04-08 03:06:45 +02:00
struct Ban_Banner Ban;
2020-04-06 17:16:31 +02:00
/***** Reset banner *****/
Ban_ResetBanner (&Ban);
2019-04-09 14:46:32 +02:00
2014-12-01 23:55:08 +01:00
/***** Set banner as visible *****/
2020-04-06 17:16:31 +02:00
Ban_ShowOrHideBanner (&Ban,false);
/***** Set editing banner to use ot in a posterior function *****/
Ban_SetEditingBanner (&Ban);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************************** Hide a visible banner **************************/
/*****************************************************************************/
void Ban_HideBanner (void)
{
2020-04-08 03:06:45 +02:00
struct Ban_Banner Ban;
2020-04-06 17:16:31 +02:00
/***** Reset banner *****/
Ban_ResetBanner (&Ban);
2019-04-09 14:46:32 +02:00
2014-12-01 23:55:08 +01:00
/***** Set banner as hidden *****/
2020-04-06 17:16:31 +02:00
Ban_ShowOrHideBanner (&Ban,true);
/***** Set editing banner to use ot in a posterior function *****/
Ban_SetEditingBanner (&Ban);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Change hiddeness of banner in the database ******************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Ban_ShowOrHideBanner (struct Ban_Banner *Ban,bool Hide)
2014-12-01 23:55:08 +01:00
{
/***** Get banner code *****/
2020-04-06 17:16:31 +02:00
if ((Ban->BanCod = Ban_GetParamBanCod ()) == -1L)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Code of banner is missing.");
/***** Get data of the banner from database *****/
2020-04-06 17:16:31 +02:00
Ban_GetDataOfBannerByCod (Ban);
2014-12-01 23:55:08 +01:00
/***** Mark file as hidden/visible in database *****/
2020-04-06 17:16:31 +02:00
if (Ban->Hidden != Hide)
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not change status of a banner in database",
"UPDATE banners SET Hidden='%c'"
" WHERE BanCod=%ld",
Hide ? 'Y' :
'N',
2020-04-06 17:16:31 +02:00
Ban->BanCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Change the short name of a banner *********************/
/*****************************************************************************/
void Ban_RenameBannerShort (void)
{
2020-04-08 03:06:45 +02:00
struct Ban_Banner Ban;
2020-04-06 17:16:31 +02:00
/***** Reset banner *****/
Ban_ResetBanner (&Ban);
2019-04-09 14:46:32 +02:00
/***** Rename banner *****/
2020-04-06 17:16:31 +02:00
Ban_RenameBanner (&Ban,Cns_SHRT_NAME);
/***** Set editing banner to use ot in a posterior function *****/
Ban_SetEditingBanner (&Ban);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Change the full name of a banner **********************/
/*****************************************************************************/
void Ban_RenameBannerFull (void)
{
2020-04-08 03:06:45 +02:00
struct Ban_Banner Ban;
2020-04-06 17:16:31 +02:00
/***** Reset banner *****/
Ban_ResetBanner (&Ban);
2019-04-09 14:46:32 +02:00
/***** Rename banner *****/
2020-04-06 17:16:31 +02:00
Ban_RenameBanner (&Ban,Cns_FULL_NAME);
/***** Set editing banner to use ot in a posterior function *****/
Ban_SetEditingBanner (&Ban);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Change the name of a banner *************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Ban_RenameBanner (struct Ban_Banner *Ban,
2020-04-06 17:16:31 +02:00
Cns_ShrtOrFullName_t ShrtOrFullName)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_The_banner_X_already_exists;
extern const char *Txt_The_banner_X_has_been_renamed_as_Y;
extern const char *Txt_The_name_of_the_banner_X_has_not_changed;
const char *ParamName = NULL; // Initialized to avoid warning
const char *FieldName = NULL; // Initialized to avoid warning
2017-03-07 01:56:41 +01:00
unsigned MaxBytes = 0; // Initialized to avoid warning
2014-12-01 23:55:08 +01:00
char *CurrentBanName = NULL; // Initialized to avoid warning
2017-03-07 01:56:41 +01:00
char NewBanName[Ban_MAX_BYTES_FULL_NAME + 1];
2014-12-01 23:55:08 +01:00
2016-10-28 10:03:37 +02:00
switch (ShrtOrFullName)
2014-12-01 23:55:08 +01:00
{
2016-10-28 10:03:37 +02:00
case Cns_SHRT_NAME:
2014-12-01 23:55:08 +01:00
ParamName = "ShortName";
FieldName = "ShortName";
2017-03-07 01:56:41 +01:00
MaxBytes = Ban_MAX_BYTES_SHRT_NAME;
2020-04-06 17:16:31 +02:00
CurrentBanName = Ban->ShrtName;
2014-12-01 23:55:08 +01:00
break;
case Cns_FULL_NAME:
ParamName = "FullName";
FieldName = "FullName";
2017-03-07 01:56:41 +01:00
MaxBytes = Ban_MAX_BYTES_FULL_NAME;
2020-04-06 17:16:31 +02:00
CurrentBanName = Ban->FullName;
2014-12-01 23:55:08 +01:00
break;
}
/***** Get parameters from form *****/
/* Get the code of the banner */
2020-04-06 17:16:31 +02:00
if ((Ban->BanCod = Ban_GetParamBanCod ()) == -1L)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Code of banner is missing.");
/* Get the new name for the banner */
2017-03-07 01:56:41 +01:00
Par_GetParToText (ParamName,NewBanName,MaxBytes);
2014-12-01 23:55:08 +01:00
2019-04-09 14:46:32 +02:00
/***** Get banner data from the database *****/
2020-04-06 17:16:31 +02:00
Ban_GetDataOfBannerByCod (Ban);
2014-12-01 23:55:08 +01:00
/***** Check if new name is empty *****/
if (!NewBanName[0])
2019-12-20 00:30:54 +01:00
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
2014-12-01 23:55:08 +01:00
else
{
2019-01-02 15:10:51 +01:00
/***** Check if old and new names are the same
(this happens when return is pressed without changes) *****/
2014-12-01 23:55:08 +01:00
if (strcmp (CurrentBanName,NewBanName)) // Different names
{
/***** If banner was in database... *****/
2020-04-06 17:16:31 +02:00
if (Ban_CheckIfBannerNameExists (ParamName,NewBanName,Ban->BanCod))
2019-04-09 14:46:32 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_banner_X_already_exists,
NewBanName);
2014-12-01 23:55:08 +01:00
else
{
/* Update the table changing old name by new name */
2020-04-06 17:16:31 +02:00
Ban_UpdateBanNameDB (Ban->BanCod,FieldName,NewBanName);
2014-12-01 23:55:08 +01:00
2017-03-09 11:16:17 +01:00
/* Write message to show the change made */
2019-04-09 14:46:32 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_banner_X_has_been_renamed_as_Y,
CurrentBanName,NewBanName);
2014-12-01 23:55:08 +01:00
}
}
else // The same name
2019-04-09 14:46:32 +02:00
Ale_CreateAlert (Ale_INFO,NULL,
Txt_The_name_of_the_banner_X_has_not_changed,
CurrentBanName);
2014-12-01 23:55:08 +01:00
}
2019-04-09 14:46:32 +02:00
/***** Update name *****/
2017-01-17 03:10:43 +01:00
Str_Copy (CurrentBanName,NewBanName,
2017-03-07 01:56:41 +01:00
MaxBytes);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Check if the name of banner exists ********************/
/*****************************************************************************/
static bool Ban_CheckIfBannerNameExists (const char *FieldName,const char *Name,long BanCod)
{
/***** Get number of banners with a name from database *****/
2018-11-03 13:13:11 +01:00
return (DB_QueryCOUNT ("can not check if the name of a banner"
" already existed",
"SELECT COUNT(*) FROM banners"
" WHERE %s='%s' AND BanCod<>%ld",
FieldName,Name,BanCod) != 0);
2014-12-01 23:55:08 +01:00
}
2017-03-09 11:16:17 +01:00
/*****************************************************************************/
/***************** Update banner name in table of banners ********************/
/*****************************************************************************/
2018-10-27 22:08:01 +02:00
static void Ban_UpdateBanNameDB (long BanCod,const char *FieldName,
const char *NewBanName)
2017-03-09 11:16:17 +01:00
{
/***** Update banner changing old name by new name *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the name of a banner",
"UPDATE banners SET %s='%s' WHERE BanCod=%ld",
FieldName,NewBanName,BanCod);
2017-03-09 11:16:17 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*********************** Change the image of a banner ************************/
/*****************************************************************************/
void Ban_ChangeBannerImg (void)
{
extern const char *Txt_The_new_image_is_X;
extern const char *Txt_You_can_not_leave_the_image_empty;
2020-04-08 03:06:45 +02:00
struct Ban_Banner Ban;
2017-03-07 01:56:41 +01:00
char NewImg[Ban_MAX_BYTES_IMAGE + 1];
2014-12-01 23:55:08 +01:00
2020-04-06 17:16:31 +02:00
/***** Reset banner *****/
Ban_ResetBanner (&Ban);
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Get the code of the banner */
2020-04-06 17:16:31 +02:00
if ((Ban.BanCod = Ban_GetParamBanCod ()) == -1L)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Code of banner is missing.");
/* Get the new WWW for the banner */
2017-03-07 01:56:41 +01:00
Par_GetParToText ("Img",NewImg,Ban_MAX_BYTES_IMAGE);
2014-12-01 23:55:08 +01:00
2019-04-09 14:46:32 +02:00
/***** Get banner data from the database *****/
2020-04-06 17:16:31 +02:00
Ban_GetDataOfBannerByCod (&Ban);
2019-04-09 14:46:32 +02:00
2014-12-01 23:55:08 +01:00
/***** Check if new image is empty *****/
if (NewImg[0])
{
/* Update the table changing old image by new image */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the image of a banner",
"UPDATE banners SET Img='%s' WHERE BanCod=%ld",
2020-04-06 17:16:31 +02:00
NewImg,Ban.BanCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-04-09 14:46:32 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_new_image_is_X,
NewImg);
2014-12-01 23:55:08 +01:00
}
else
2019-04-09 14:46:32 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_can_not_leave_the_image_empty);
2014-12-01 23:55:08 +01:00
2019-04-09 14:46:32 +02:00
/***** Update image *****/
2020-04-06 17:16:31 +02:00
Str_Copy (Ban.Img,NewImg,
2017-03-07 01:56:41 +01:00
Ban_MAX_BYTES_IMAGE);
2020-04-06 17:16:31 +02:00
/***** Set editing banner to use ot in a posterior function *****/
Ban_SetEditingBanner (&Ban);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Change the WWW of a banner **************************/
/*****************************************************************************/
void Ban_ChangeBannerWWW (void)
{
extern const char *Txt_The_new_web_address_is_X;
2020-04-08 03:06:45 +02:00
struct Ban_Banner Ban;
2017-03-07 01:56:41 +01:00
char NewWWW[Cns_MAX_BYTES_WWW + 1];
2014-12-01 23:55:08 +01:00
2020-04-06 17:16:31 +02:00
/***** Reset banner *****/
Ban_ResetBanner (&Ban);
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Get the code of the banner */
2020-04-06 17:16:31 +02:00
if ((Ban.BanCod = Ban_GetParamBanCod ()) == -1L)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Code of banner is missing.");
/* Get the new WWW for the banner */
2017-03-07 01:56:41 +01:00
Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
2019-04-09 14:46:32 +02:00
/***** Get banner data from the database *****/
2020-04-06 17:16:31 +02:00
Ban_GetDataOfBannerByCod (&Ban);
2019-04-09 14:46:32 +02:00
2014-12-01 23:55:08 +01:00
/***** Check if new WWW is empty *****/
if (NewWWW[0])
{
/* Update the table changing old WWW by new WWW */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the web of a banner",
"UPDATE banners SET WWW='%s' WHERE BanCod=%ld",
2020-04-06 17:16:31 +02:00
NewWWW,Ban.BanCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-04-09 14:46:32 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_new_web_address_is_X,
NewWWW);
2014-12-01 23:55:08 +01:00
}
else
2019-12-20 00:30:54 +01:00
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
2014-12-01 23:55:08 +01:00
2019-04-09 14:46:32 +02:00
/***** Update web *****/
2020-04-06 17:16:31 +02:00
Str_Copy (Ban.WWW,NewWWW,
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2020-04-06 17:16:31 +02:00
/***** Set editing banner to use ot in a posterior function *****/
Ban_SetEditingBanner (&Ban);
2019-04-09 14:46:32 +02:00
}
/*****************************************************************************/
/********* Show alerts after changing a banner and continue editing **********/
/*****************************************************************************/
void Ban_ContEditAfterChgBan (void)
{
2020-04-06 17:16:31 +02:00
struct Ban_Banners Banners;
2020-04-08 03:06:45 +02:00
struct Ban_Banner *Ban = Ban_GetEditingBanner ();
2020-04-06 17:16:31 +02:00
/***** Reset banners *****/
Ban_ResetBanners (&Banners);
2019-04-09 14:46:32 +02:00
/***** Write message to show the change made *****/
Ale_ShowAlerts (NULL);
/***** Show the form again *****/
2020-04-06 17:16:31 +02:00
Ban_EditBannersInternal (&Banners,Ban);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Put a form to create a new banner *********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Ban_PutFormToCreateBanner (const struct Ban_Banner *Ban)
2014-12-01 23:55:08 +01:00
{
2016-11-28 10:04:44 +01:00
extern const char *Hlp_SYSTEM_Banners_edit;
2014-12-01 23:55:08 +01:00
extern const char *Txt_New_banner;
extern const char *Txt_Create_banner;
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActNewBan);
2014-12-01 23:55:08 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2020-03-26 02:54:30 +01:00
Box_BoxTableBegin (NULL,Txt_New_banner,
NULL,NULL,
2017-06-12 15:03:29 +02:00
Hlp_SYSTEM_Banners_edit,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
/***** Write heading *****/
Ban_PutHeadBanners ();
/***** Banner code *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 23:02:50 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BM\"");
HTM_TD_End ();
2019-10-07 23:02:50 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"BM\"");
HTM_TD_End ();
2019-10-07 23:02:50 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Empty (1);
2014-12-01 23:55:08 +01:00
/***** Banner short name *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CM\"");
2020-04-06 17:16:31 +02:00
HTM_INPUT_TEXT ("ShortName",Ban_MAX_CHARS_SHRT_NAME,Ban->ShrtName,false,
2019-11-03 18:22:11 +01:00
"class=\"INPUT_SHORT_NAME\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Banner full name *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CM\"");
2020-04-06 17:16:31 +02:00
HTM_INPUT_TEXT ("FullName",Ban_MAX_CHARS_FULL_NAME,Ban->FullName,false,
2019-11-03 18:22:11 +01:00
"class=\"INPUT_FULL_NAME\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Banner image *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CM\"");
2020-04-06 17:16:31 +02:00
HTM_INPUT_TEXT ("Img",Ban_MAX_CHARS_IMAGE,Ban->Img,false,
2019-11-03 18:22:11 +01:00
"size=\"12\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Banner WWW *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"CM\"");
2020-04-06 17:16:31 +02:00
HTM_INPUT_URL ("WWW",Ban->WWW,false,
2019-12-19 11:00:14 +01:00
"class=\"INPUT_WWW_NARROW\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 23:02:50 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End table, send button and end box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_banner);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write header with fields of a banner *******************/
/*****************************************************************************/
static void Ban_PutHeadBanners (void)
{
extern const char *Txt_Code;
2015-02-04 20:03:23 +01:00
extern const char *Txt_Short_name;
extern const char *Txt_Full_name;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Image;
extern const char *Txt_WWW;
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-11 01:02:51 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"BM",NULL);
HTM_TH (1,1,"BM",NULL);
HTM_TH (1,1,"RM",Txt_Code);
HTM_TH (1,1,"LM",Txt_Short_name);
HTM_TH (1,1,"LM",Txt_Full_name);
HTM_TH (1,1,"LM",Txt_Image);
HTM_TH (1,1,"LM",Txt_WWW);
2019-10-11 01:02:51 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Receive form to create a new banner *********************/
/*****************************************************************************/
void Ban_RecFormNewBanner (void)
{
extern const char *Txt_The_banner_X_already_exists;
extern const char *Txt_You_must_specify_the_image_of_the_new_banner;
extern const char *Txt_You_must_specify_the_URL_of_the_new_banner;
2019-04-09 14:46:32 +02:00
extern const char *Txt_Created_new_banner_X;
2014-12-01 23:55:08 +01:00
extern const char *Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_banner;
2020-04-08 03:06:45 +02:00
struct Ban_Banner Ban;
2014-12-01 23:55:08 +01:00
2020-04-06 17:16:31 +02:00
/***** Reset banner *****/
Ban_ResetBanner (&Ban);
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Get banner short name */
2020-04-06 17:16:31 +02:00
Par_GetParToText ("ShortName",Ban.ShrtName,Ban_MAX_BYTES_SHRT_NAME);
2014-12-01 23:55:08 +01:00
/* Get banner full name */
2020-04-06 17:16:31 +02:00
Par_GetParToText ("FullName",Ban.FullName,Ban_MAX_BYTES_FULL_NAME);
2014-12-01 23:55:08 +01:00
/* Get banner image */
2020-04-06 17:16:31 +02:00
Par_GetParToText ("Img",Ban.Img,Ban_MAX_BYTES_IMAGE);
2014-12-01 23:55:08 +01:00
/* Get banner URL */
2020-04-06 17:16:31 +02:00
Par_GetParToText ("WWW",Ban.WWW,Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
2020-04-06 17:16:31 +02:00
if (Ban.ShrtName[0] &&
Ban.FullName[0]) // If there's a banner name
2014-12-01 23:55:08 +01:00
{
/***** If name of banner was in database... *****/
2020-04-06 17:16:31 +02:00
if (Ban_CheckIfBannerNameExists ("ShortName",Ban.ShrtName,-1L))
2019-04-09 14:46:32 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_banner_X_already_exists,
2020-04-06 17:16:31 +02:00
Ban.ShrtName);
else if (Ban_CheckIfBannerNameExists ("FullName",Ban.FullName,-1L))
2019-04-09 14:46:32 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_banner_X_already_exists,
2020-04-06 17:16:31 +02:00
Ban.FullName);
else if (!Ban.Img[0])
2019-04-09 14:46:32 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_must_specify_the_image_of_the_new_banner);
2020-04-06 17:16:31 +02:00
else if (!Ban.WWW[0])
2019-04-09 14:46:32 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_must_specify_the_URL_of_the_new_banner);
2014-12-01 23:55:08 +01:00
else // Add new banner to database
2019-04-09 14:46:32 +02:00
{
2020-04-06 17:16:31 +02:00
Ban_CreateBanner (&Ban);
2019-04-09 14:46:32 +02:00
Ale_CreateAlert (Ale_SUCCESS,Txt_Created_new_banner_X,
2020-04-06 17:16:31 +02:00
Ban.ShrtName);
2019-04-09 14:46:32 +02:00
}
2014-12-01 23:55:08 +01:00
}
else // If there is not a banner name
2019-04-09 14:46:32 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_banner);
2020-04-06 17:16:31 +02:00
/***** Set editing banner to use ot in a posterior function *****/
Ban_SetEditingBanner (&Ban);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************************** Create a new banner ****************************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Ban_CreateBanner (const struct Ban_Banner *Ban)
2014-12-01 23:55:08 +01:00
{
/***** Create a new banner *****/
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not create banner",
"INSERT INTO banners"
" (Hidden,ShortName,FullName,Img,WWW)"
" VALUES"
" ('N','%s','%s','%s','%s')",
Ban->ShrtName,Ban->FullName,Ban->Img,Ban->WWW);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************* Write menu with some banners **********************/
/*****************************************************************************/
void Ban_WriteMenuWithBanners (void)
{
2020-04-06 17:16:31 +02:00
struct Ban_Banners Banners;
2018-10-30 13:59:37 +01:00
MYSQL_RES *mysql_res;
unsigned long NumRows;
2014-12-01 23:55:08 +01:00
unsigned NumBan;
2020-04-06 17:16:31 +02:00
/***** Reset banners *****/
Ban_ResetBanners (&Banners);
2014-12-01 23:55:08 +01:00
/***** Get random banner *****/
2018-10-19 01:27:29 +02:00
// The banner(s) will change once in a while
2018-10-30 13:59:37 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get banners",
"SELECT BanCod,Hidden,ShortName,FullName,Img,WWW"
" FROM banners"
" WHERE Hidden='N'"
" ORDER BY RAND(%lu) LIMIT %u",
(unsigned long) (Gbl.StartExecutionTimeUTC / Cfg_TIME_TO_CHANGE_BANNER),
Cfg_NUMBER_OF_BANNERS);
2020-04-06 17:16:31 +02:00
Ban_GetListBanners (&Banners,&mysql_res,NumRows);
2014-12-01 23:55:08 +01:00
/***** Write all the banners *****/
for (NumBan = 0;
2020-04-06 17:16:31 +02:00
NumBan < Banners.Num;
2014-12-01 23:55:08 +01:00
NumBan++)
{
/* Write data of this banner */
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"CM\"");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActClkBan);
2020-04-06 17:16:31 +02:00
Ban_PutParamBanCod (Banners.Lst[NumBan].BanCod);
Par_PutHiddenParamString (NULL,"URL",Banners.Lst[NumBan].WWW);
HTM_INPUT_IMAGE (Cfg_URL_BANNER_PUBLIC,Banners.Lst[NumBan].Img,
Banners.Lst[NumBan].FullName,"BANNER");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
}
/***** Free list of banners *****/
2020-04-06 17:16:31 +02:00
Ban_FreeListBanners (&Banners);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************* Go to a banner when clicked ***********************/
/*****************************************************************************/
void Ban_ClickOnBanner (void)
{
2020-04-08 03:06:45 +02:00
struct Ban_Banner Ban;
2014-12-01 23:55:08 +01:00
/***** Get banner code *****/
if ((Ban.BanCod = Ban_GetParamBanCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of banner is missing.");
/***** Get data of the banner from database *****/
Ban_GetDataOfBannerByCod (&Ban);
/***** Set banner clicked in order to log it *****/
2020-04-06 17:16:31 +02:00
Ban_SetBanCodClicked (Ban.BanCod);
2014-12-01 23:55:08 +01:00
/***** Download the file *****/
fprintf (stdout,"Location: %s\n\n",Ban.WWW);
2015-10-16 02:24:29 +02:00
// TODO: Put headers Content-type and Content-disposition:
// See: http://stackoverflow.com/questions/381954/how-do-i-fix-firefox-trying-to-save-image-as-htm
// http://elouai.com/force-download.php
2014-12-01 23:55:08 +01:00
Gbl.Layout.HTMLStartWritten =
2015-11-27 21:24:24 +01:00
Gbl.Layout.DivsEndWritten =
2014-12-01 23:55:08 +01:00
Gbl.Layout.HTMLEndWritten = true; // Don't write HTML at all
}
2019-04-09 14:46:32 +02:00
2020-04-06 17:16:31 +02:00
static void Ban_SetBanCodClicked (long BanCod)
{
Ban_BanCodClicked = BanCod;
}
2019-04-09 14:46:32 +02:00
2020-04-06 17:16:31 +02:00
long Ban_GetBanCodClicked (void)
2019-04-09 14:46:32 +02:00
{
2020-04-06 17:16:31 +02:00
return Ban_BanCodClicked;
}
2019-04-09 14:46:32 +02:00
2020-04-06 17:16:31 +02:00
/*****************************************************************************/
/******************************* Reset banners *******************************/
/*****************************************************************************/
2019-04-09 14:46:32 +02:00
2020-04-06 17:16:31 +02:00
static void Ban_ResetBanners (struct Ban_Banners *Banners)
{
Banners->Num = 0;
Banners->Lst = NULL;
Banners->BanCodToEdit = -1L;
Banners->BanCodClicked = 0L;
2019-04-09 14:46:32 +02:00
}
2020-04-06 17:16:31 +02:00
/*****************************************************************************/
/************************* Reset banner/destructor **********************/
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Ban_ResetBanner (struct Ban_Banner *Ban)
2019-04-09 14:46:32 +02:00
{
2020-04-06 17:16:31 +02:00
/***** Reset banner *****/
Ban->BanCod = -1L;
Ban->Hidden = true;
Ban->ShrtName[0] = '\0';
Ban->FullName[0] = '\0';
Ban->Img[0] = '\0';
Ban->WWW[0] = '\0';
2019-04-09 14:46:32 +02:00
}