Version 21.26: Oct 06, 2021 New module swad_plugin_database for database queries related to plugins.

This commit is contained in:
acanas 2021-10-06 21:38:15 +02:00
parent 8e32be35d2
commit a2a80443ea
8 changed files with 334 additions and 127 deletions

View File

@ -71,8 +71,8 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.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_photo_database.o \
swad_place.o swad_place_database.o swad_plugin.o swad_privacy.o \
swad_profile.o swad_program.o swad_project.o \
swad_place.o swad_place_database.o swad_plugin.o swad_plugin_database.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

@ -602,14 +602,15 @@ 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.25 (2021-10-05)"
#define Log_PLATFORM_VERSION "SWAD 21.26 (2021-10-06)"
#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.25: Oct 05, 2021 New module swad_place_database for database queries related to place. (318514 lines)
Version 21.26: Oct 06, 2021 New module swad_plugin_database for database queries related to plugins. (318680 lines)
Version 21.25: Oct 05, 2021 New module swad_place_database for database queries related to places. (318514 lines)
Version 21.24.1: Oct 05, 2021 Queries moved to module swad_photo_database. (318406 lines)
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)

View File

@ -25,20 +25,8 @@
/********************************** Headers **********************************/
/*****************************************************************************/
// #include <stddef.h> // For NULL
// #include <stdlib.h> // For calloc
// #include <string.h> // For string functions
// #include "swad_box.h"
// #include "swad_center_database.h"
// #include "swad_constant.h"
#include "swad_database.h"
// #include "swad_error.h"
// #include "swad_form.h"
#include "swad_global.h"
// #include "swad_HTML.h"
// #include "swad_language.h"
// #include "swad_parameter.h"
#include "swad_place.h"
/*****************************************************************************/

View File

@ -28,7 +28,6 @@
/*****************************************************************************/
#include "swad_place.h"
// #include "swad_string.h"
/*****************************************************************************/
/************************** Public types and constants ***********************/

View File

@ -46,6 +46,7 @@ TODO: Check if web service is called from an authorized IP.
#include "swad_language.h"
#include "swad_parameter.h"
#include "swad_plugin.h"
#include "swad_plugin_database.h"
#include "swad_session.h"
/*****************************************************************************/
@ -79,8 +80,6 @@ static void Plg_PutParamPlgCod (void *PlgCod);
static void Plg_GetListPlugins (void);
static void Plg_PutFormToCreatePlugin (void);
static void Plg_PutHeadPlugins (void);
static bool Plg_DB_CheckIfPluginNameExists (const char *Name,long PlgCod);
static void Plg_DB_CreatePlugin (struct Plugin *Plg);
static void Plg_EditingPluginConstructor (void);
static void Plg_EditingPluginDestructor (void);
@ -230,20 +229,7 @@ static void Plg_GetListPlugins (void)
struct Plugin *Plg;
/***** Get plugins from database *****/
Gbl.Plugins.Num = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get plugins",
"SELECT PlgCod," // row[0]
"Name," // row[1]
"Description," // row[2]
"Logo," // row[3]
"AppKey," // row[4]
"URL," // row[5]
"IP" // row[6]
" FROM plg_plugins"
" ORDER BY Name");
/***** Count number of rows in result *****/
if (Gbl.Plugins.Num) // Plugins found...
if ((Gbl.Plugins.Num = Plg_DB_GetListPlugins (&mysql_res))) // Plugins found...
{
/***** Create list with plugins *****/
if ((Gbl.Plugins.Lst = calloc ((size_t) Gbl.Plugins.Num,
@ -302,16 +288,7 @@ bool Plg_GetDataOfPluginByCod (struct Plugin *Plg)
// Plg->PlgCod > 0
/***** Get data of a plugin from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get data of a plugin",
"SELECT Name," // row[0]
"Description," // row[1]
"Logo," // row[2]
"AppKey," // row[3]
"URL," // row[4]
"IP" // row[5]
" FROM plg_plugins"
" WHERE PlgCod=%ld",
Plg->PlgCod)) // Plugin found...
if (Plg_DB_GetDataOfPluginByCod (&mysql_res,Plg->PlgCod)) // Plugin found...
{
PluginFound = true;
@ -502,10 +479,7 @@ void Plg_RemovePlugin (void)
Plg_GetDataOfPluginByCod (Plg_EditingPlg);
/***** Remove plugin *****/
DB_QueryDELETE ("can not remove a plugin",
"DELETE FROM plg_plugins"
" WHERE PlgCod=%ld",
Plg_EditingPlg->PlgCod);
Plg_DB_RemovePlugin (Plg_EditingPlg->PlgCod);
/***** Write message to show the change made *****/
Ale_CreateAlert (Ale_SUCCESS,NULL,
@ -553,14 +527,9 @@ void Plg_RenamePlugin (void)
else
{
/* Update the table changing old name by new name */
DB_QueryUPDATE ("can not update the name of a plugin",
"UPDATE plg_plugins"
" SET Name='%s'"
" WHERE PlgCod=%ld",
NewPlgName,
Plg_EditingPlg->PlgCod);
Plg_DB_ChangeName (Plg_EditingPlg->PlgCod,NewPlgName);
/***** Write message to show the change made *****/
/* Write message to show the change made */
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_plugin_X_has_been_renamed_as_Y,
Plg_EditingPlg->Name,NewPlgName);
@ -578,22 +547,6 @@ void Plg_RenamePlugin (void)
Str_Copy (Plg_EditingPlg->Name,NewPlgName,sizeof (Plg_EditingPlg->Name) - 1);
}
/*****************************************************************************/
/******************** Check if the name of plugin exists *********************/
/*****************************************************************************/
static bool Plg_DB_CheckIfPluginNameExists (const char *Name,long PlgCod)
{
/***** Get number of plugins with a name from database *****/
return (DB_QueryCOUNT ("can not check if the name of a plugin"
" already existed",
"SELECT COUNT(*)"
" FROM plg_plugins"
" WHERE Name='%s'"
" AND PlgCod<>%ld",
Name,PlgCod) != 0);
}
/*****************************************************************************/
/******************* Change the description of a plugin **********************/
/*****************************************************************************/
@ -621,14 +574,9 @@ void Plg_ChangePlgDescription (void)
if (NewDescription[0])
{
/* Update the table changing old description by new description */
DB_QueryUPDATE ("can not update the description of a plugin",
"UPDATE plg_plugins"
" SET Description='%s'"
" WHERE PlgCod=%ld",
NewDescription,
Plg_EditingPlg->PlgCod);
Plg_DB_ChangeDescription (Plg_EditingPlg->PlgCod,NewDescription);
/***** Write message to show the change made *****/
/* Write message to show the change made */
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_new_description_is_X,
NewDescription);
@ -668,14 +616,9 @@ void Plg_ChangePlgLogo (void)
if (NewLogo[0])
{
/* Update the table changing old logo by new logo */
DB_QueryUPDATE ("can not update the logo of a plugin",
"UPDATE plg_plugins"
" SET Logo='%s'"
" WHERE PlgCod=%ld",
NewLogo,
Plg_EditingPlg->PlgCod);
Plg_DB_ChangeLogo (Plg_EditingPlg->PlgCod,NewLogo);
/***** Write message to show the change made *****/
/* Write message to show the change made */
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_new_logo_is_X,
NewLogo);
@ -693,7 +636,7 @@ void Plg_ChangePlgLogo (void)
void Plg_ChangePlgAppKey (void)
{
extern const char *Txt_The_new_logo_is_X; // TODO: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
extern const char *Txt_The_new_application_key_is_X;
char NewAppKey[Plg_MAX_BYTES_PLUGIN_APP_KEY + 1];
/***** Plugin constructor *****/
@ -714,16 +657,11 @@ void Plg_ChangePlgAppKey (void)
if (NewAppKey[0])
{
/* Update the table changing old application key by new application key */
DB_QueryUPDATE ("can not update the application key of a plugin",
"UPDATE plg_plugins"
" SET AppKey='%s'"
" WHERE PlgCod=%ld",
NewAppKey,
Plg_EditingPlg->PlgCod);
Plg_DB_ChangeAppKey (Plg_EditingPlg->PlgCod,NewAppKey);
/***** Write message to show the change made *****/
/* Write message to show the change made */
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_new_logo_is_X, // TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Txt_The_new_application_key_is_X,
NewAppKey);
}
else
@ -760,14 +698,9 @@ void Plg_ChangePlgURL (void)
if (NewURL[0])
{
/* Update the table changing old WWW by new WWW */
DB_QueryUPDATE ("can not update the URL of a plugin",
"UPDATE plg_plugins"
" SET URL='%s'"
" WHERE PlgCod=%ld",
NewURL,
Plg_EditingPlg->PlgCod);
Plg_DB_ChangeURL (Plg_EditingPlg->PlgCod,NewURL);
/***** Write message to show the change made *****/
/* Write message to show the change made */
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_new_URL_is_X,
NewURL);
@ -806,14 +739,9 @@ void Plg_ChangePlgIP (void)
if (NewIP[0])
{
/* Update the table changing old IP by new IP */
DB_QueryUPDATE ("can not update the IP address of a plugin",
"UPDATE plg_plugins"
" SET IP='%s'"
" WHERE PlgCod=%ld",
NewIP,
Plg_EditingPlg->PlgCod);
Plg_DB_ChangeIP (Plg_EditingPlg->PlgCod,NewIP);
/***** Write message to show the change made *****/
/* Write message to show the change made */
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_new_IP_address_is_X,
NewIP);
@ -1018,26 +946,6 @@ void Plg_ReceiveFormNewPlg (void)
Txt_You_must_specify_the_name_and_the_description_of_the_new_plugin);
}
/*****************************************************************************/
/***************************** Create a new plugin ***************************/
/*****************************************************************************/
static void Plg_DB_CreatePlugin (struct Plugin *Plg)
{
/***** Create a new plugin *****/
DB_QueryINSERT ("can not create plugin",
"INSERT INTO plg_plugins"
" (Name,Description,Logo,AppKey,URL,IP)"
" VALUES"
" ('%s','%s','%s','%s','%s','%s')",
Plg->Name,
Plg->Description,
Plg->Logo,
Plg->AppKey,
Plg->URL,
Plg->IP);
}
/*****************************************************************************/
/************************ Plugin constructor/destructor **********************/
/*****************************************************************************/

224
swad_plugin_database.c Normal file
View File

@ -0,0 +1,224 @@
// swad_plugin_database.c: plugins called from SWAD using web services, 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 ***********************************/
/*****************************************************************************/
#include "swad_database.h"
#include "swad_plugin_database.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Create a new plugin ***************************/
/*****************************************************************************/
void Plg_DB_CreatePlugin (const struct Plugin *Plg)
{
DB_QueryINSERT ("can not create plugin",
"INSERT INTO plg_plugins"
" (Name,Description,Logo,AppKey,URL,IP)"
" VALUES"
" ('%s','%s','%s','%s','%s','%s')",
Plg->Name,
Plg->Description,
Plg->Logo,
Plg->AppKey,
Plg->URL,
Plg->IP);
}
/*****************************************************************************/
/******************************* Rename a plugin *****************************/
/*****************************************************************************/
void Plg_DB_ChangeName (long PlgCod,
const char NewPlgName[Plg_MAX_BYTES_PLUGIN_NAME + 1])
{
DB_QueryUPDATE ("can not update the name of a plugin",
"UPDATE plg_plugins"
" SET Name='%s'"
" WHERE PlgCod=%ld",
NewPlgName,
PlgCod);
}
/*****************************************************************************/
/******************* Change the description of a plugin **********************/
/*****************************************************************************/
void Plg_DB_ChangeDescription (long PlgCod,
const char NewDescription[Plg_MAX_BYTES_PLUGIN_DESCRIPTION + 1])
{
DB_QueryUPDATE ("can not update the description of a plugin",
"UPDATE plg_plugins"
" SET Description='%s'"
" WHERE PlgCod=%ld",
NewDescription,
PlgCod);
}
/*****************************************************************************/
/*********************** Change the logo of a plugin *************************/
/*****************************************************************************/
void Plg_DB_ChangeLogo (long PlgCod,
const char NewLogo[Plg_MAX_BYTES_PLUGIN_LOGO + 1])
{
DB_QueryUPDATE ("can not update the logo of a plugin",
"UPDATE plg_plugins"
" SET Logo='%s'"
" WHERE PlgCod=%ld",
NewLogo,
PlgCod);
}
/*****************************************************************************/
/***************** Change the application key of a plugin ********************/
/*****************************************************************************/
void Plg_DB_ChangeAppKey (long PlgCod,
const char NewAppKey[Plg_MAX_BYTES_PLUGIN_APP_KEY + 1])
{
DB_QueryUPDATE ("can not update the application key of a plugin",
"UPDATE plg_plugins"
" SET AppKey='%s'"
" WHERE PlgCod=%ld",
NewAppKey,
PlgCod);
}
/*****************************************************************************/
/************************* Change the URL of a plugin ************************/
/*****************************************************************************/
void Plg_DB_ChangeURL (long PlgCod,
const char NewURL[Cns_MAX_BYTES_WWW + 1])
{
DB_QueryUPDATE ("can not update the URL of a plugin",
"UPDATE plg_plugins"
" SET URL='%s'"
" WHERE PlgCod=%ld",
NewURL,
PlgCod);
}
/*****************************************************************************/
/************************** Change the IP of a plugin ************************/
/*****************************************************************************/
void Plg_DB_ChangeIP (long PlgCod,
const char NewIP[Cns_MAX_BYTES_IP + 1])
{
DB_QueryUPDATE ("can not update the IP address of a plugin",
"UPDATE plg_plugins"
" SET IP='%s'"
" WHERE PlgCod=%ld",
NewIP,
PlgCod);
}
/*****************************************************************************/
/************************* Get list of current plugins ***********************/
/*****************************************************************************/
unsigned Plg_DB_GetListPlugins (MYSQL_RES **mysql_res)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get plugins",
"SELECT PlgCod," // row[0]
"Name," // row[1]
"Description," // row[2]
"Logo," // row[3]
"AppKey," // row[4]
"URL," // row[5]
"IP" // row[6]
" FROM plg_plugins"
" ORDER BY Name");
}
/*****************************************************************************/
/*************************** Get data of a plugin ****************************/
/*****************************************************************************/
unsigned Plg_DB_GetDataOfPluginByCod (MYSQL_RES **mysql_res,long PlgCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get data of a plugin",
"SELECT Name," // row[0]
"Description," // row[1]
"Logo," // row[2]
"AppKey," // row[3]
"URL," // row[4]
"IP" // row[5]
" FROM plg_plugins"
" WHERE PlgCod=%ld",
PlgCod);
}
/*****************************************************************************/
/******************** Check if the name of plugin exists *********************/
/*****************************************************************************/
bool Plg_DB_CheckIfPluginNameExists (const char *Name,long PlgCod)
{
/***** Get number of plugins with a name from database *****/
return (DB_QueryCOUNT ("can not check if the name of a plugin"
" already existed",
"SELECT COUNT(*)"
" FROM plg_plugins"
" WHERE Name='%s'"
" AND PlgCod<>%ld",
Name,
PlgCod) != 0);
}
/*****************************************************************************/
/******************************* Remove a plugin *****************************/
/*****************************************************************************/
void Plg_DB_RemovePlugin (long PlgCod)
{
DB_QueryDELETE ("can not remove a plugin",
"DELETE FROM plg_plugins"
" WHERE PlgCod=%ld",
PlgCod);
}

66
swad_plugin_database.h Normal file
View File

@ -0,0 +1,66 @@
// swad_plugin_database.h: plugins called from SWAD using web services, operations with database
#ifndef _SWAD_PLG_DB
#define _SWAD_PLG_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 <stdbool.h> // For boolean type
#include "swad_plugin.h"
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Public types ********************************/
/*****************************************************************************/
/*****************************************************************************/
/****************************** Public prototypes ****************************/
/*****************************************************************************/
void Plg_DB_CreatePlugin (const struct Plugin *Plg);
void Plg_DB_ChangeName (long PlgCod,
const char NewPlgName[Plg_MAX_BYTES_PLUGIN_NAME + 1]);
void Plg_DB_ChangeDescription (long PlgCod,
const char NewDescription[Plg_MAX_BYTES_PLUGIN_DESCRIPTION + 1]);
void Plg_DB_ChangeLogo (long PlgCod,
const char NewLogo[Plg_MAX_BYTES_PLUGIN_LOGO + 1]);
void Plg_DB_ChangeAppKey (long PlgCod,
const char NewAppKey[Plg_MAX_BYTES_PLUGIN_APP_KEY + 1]);
void Plg_DB_ChangeURL (long PlgCod,
const char NewURL[Cns_MAX_BYTES_WWW + 1]);
void Plg_DB_ChangeIP (long PlgCod,
const char NewIP[Cns_MAX_BYTES_IP + 1]);
unsigned Plg_DB_GetListPlugins (MYSQL_RES **mysql_res);
unsigned Plg_DB_GetDataOfPluginByCod (MYSQL_RES **mysql_res,long PlgCod);
bool Plg_DB_CheckIfPluginNameExists (const char *Name,long PlgCod);
void Plg_DB_RemovePlugin (long PlgCod);
#endif

View File

@ -49176,6 +49176,27 @@ const char *Txt_The_name_of_the_type_of_group_X_has_not_changed = // Warning: it
"O nome do tipo de grupo <strong>%s</strong> n&atilde;o foi alterado.";
#endif
const char *Txt_The_new_application_key_is_X = // Warning: it is very important to include %s in the following sentences
#if L==1 // ca
"La nova clau d'aplicaci&oacute; &eacute;s <strong>%s</strong>.";
#elif L==2 // de
"Der neue Anwendungsschl&uuml;ssel ist <strong>%s</strong>.";
#elif L==3 // en
"The new application key is <strong>%s</strong>.";
#elif L==4 // es
"La nueva clave de aplicaci&oacute;n es <strong>%s</strong>.";
#elif L==5 // fr
"La nouvelle cl&eacute; d'application est <strong>%s</strong>.";
#elif L==6 // gn
"La nueva clave de aplicaci&oacute;n es <strong>%s</strong>."; // Okoteve traducción
#elif L==7 // it
"La nuova chiave dell'applicazione &egrave; <strong>%s</strong>.";
#elif L==8 // pl
"Nowy klucz aplikacji to <strong>%s</strong>.";
#elif L==9 // pt
"A nova chave do aplicativo &eacute; <strong>%s</strong>.";
#endif
const char *Txt_The_new_IP_address_is_X = // Warning: it is very important to include %s in the following sentences
#if L==1 // ca
"La nueva direcci&oacute;n IP es <strong>%s</strong>."; // Necessita traduccio