swad-core/swad_plugin.c

1076 lines
37 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_plugin.c: plugins called from SWAD using web services
/*
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.
2018-04-24 13:21:53 +02:00
Copyright (C) 1999-2018 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/>.
*/
/*
TODO: Check if web service is called from an authorized IP.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
2018-10-24 10:45:28 +02:00
#define _GNU_SOURCE // For asprintf
2014-12-01 23:55:08 +01:00
#include <linux/stddef.h> // For NULL
2015-10-16 02:24:29 +02:00
#include <stdbool.h> // For boolean type
2018-10-24 10:45:28 +02:00
#include <stdio.h> // For asprintf, fprintf
2014-12-01 23:55:08 +01:00
#include <stdlib.h> // For calloc, free
#include <string.h>
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2014-12-01 23:55:08 +01:00
#include "swad_config.h"
#include "swad_constant.h"
#include "swad_cryptography.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"
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_plugin.h"
#include "swad_session.h"
#include "swad_web_service.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2016-03-19 00:48:58 +01:00
static void Plg_PutIconToEditPlugins (void);
2014-12-01 23:55:08 +01:00
static void Plg_ListPluginsForEdition (void);
static void Plg_PutParamPlgCod (long PlgCod);
static void Plg_GetListPlugins (void);
static void Plg_PutFormToCreatePlugin (void);
static void Plg_PutHeadPlugins (void);
static bool Plg_CheckIfPluginNameExists (const char *Name,long PlgCod);
static void Plg_CreatePlugin (struct Plugin *Plg);
/*****************************************************************************/
/************************** List available plugins ***************************/
/*****************************************************************************/
void Plg_ListPlugins (void)
{
extern const char *Txt_Option_under_development;
extern const char *Txt_Plugins;
extern const char *Txt_Plugin;
unsigned NumPlg;
struct Plugin *Plg;
2018-10-17 01:08:42 +02:00
char URL[Cns_MAX_BYTES_WWW + Cns_BYTES_SESSION_ID + 1];
2014-12-01 23:55:08 +01:00
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged != Rol_SYS_ADM)
2014-12-01 23:55:08 +01:00
{
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_Option_under_development);
2014-12-01 23:55:08 +01:00
return;
}
/***** Get list of plugins *****/
Plg_GetListPlugins ();
2017-06-11 22:26:40 +02:00
/***** Start box and table *****/
2017-06-10 21:38:10 +02:00
Box_StartBoxTable (NULL,Txt_Plugins,
2017-06-11 22:26:40 +02:00
Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM ? Plg_PutIconToEditPlugins :
NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
/***** Write table heading *****/
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-09-28 18:28:29 +02:00
"<th style=\"width:40px;\">"
2015-09-05 19:19:39 +02:00
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-23 22:47:09 +01:00
"%s"
2015-09-05 19:19:39 +02:00
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Plugin);
/***** Write all the plugins *****/
for (NumPlg = 0;
NumPlg < Gbl.Plugins.Num;
NumPlg++)
{
Plg = &(Gbl.Plugins.Lst[NumPlg]);
2018-10-18 02:02:32 +02:00
snprintf (URL,sizeof (URL),
"%s%s",
Plg->URL,Gbl.Session.Id);
2014-12-01 23:55:08 +01:00
/* Plugin logo */
2015-09-05 19:19:39 +02:00
// TODO: Change plugin icons to 32x32
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"<tr>"
2015-09-28 18:28:29 +02:00
"<td class=\"DAT LEFT_MIDDLE\" style=\"width:45px;\">"
2014-12-01 23:55:08 +01:00
"<a href=\"%s\" title=\"%s\" class=\"DAT\" target=\"_blank\">"
2015-07-22 13:49:39 +02:00
"<img src=\"%s/%s/%s24x24.gif\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO40x40\" />"
2014-12-01 23:55:08 +01:00
"</a>"
"</td>"
2015-08-24 11:25:20 +02:00
"<td class=\"DAT LEFT_MIDDLE\">"
2014-12-01 23:55:08 +01:00
"<a href=\"%s\" title=\"%s\" class=\"DAT\" target=\"_blank\">"
2014-12-23 22:47:09 +01:00
"%s"
"</a>"
"</td>"
2014-12-01 23:55:08 +01:00
"</tr>",
URL,Plg->Name,
2015-07-22 13:49:39 +02:00
Gbl.Prefs.IconsURL,Cfg_ICON_FOLDER_PLUGINS,Gbl.Plugins.Lst[NumPlg].Logo,
Plg->Name,Plg->Name,
2014-12-01 23:55:08 +01:00
URL,Plg->Name,
Plg->Name);
}
2017-06-11 22:26:40 +02:00
/***** End table and box *****/
2017-06-10 21:38:10 +02:00
Box_EndBoxTable ();
2014-12-01 23:55:08 +01:00
/***** Free list of plugins *****/
Plg_FreeListPlugins ();
}
/*****************************************************************************/
2016-03-19 00:48:58 +01:00
/*************************** Put icon to edit plugins ************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-03-19 00:48:58 +01:00
static void Plg_PutIconToEditPlugins (void)
2014-12-01 23:55:08 +01:00
{
2017-06-11 19:13:28 +02:00
Ico_PutContextualIconToEdit (ActEdiPlg,NULL);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************** Put forms to edit plugins ************************/
/*****************************************************************************/
void Plg_EditPlugins (void)
{
/***** Get list of plugins *****/
Plg_GetListPlugins ();
/***** Put a form to create a new plugin *****/
Plg_PutFormToCreatePlugin ();
/***** List current plugins *****/
if (Gbl.Plugins.Num)
Plg_ListPluginsForEdition ();
/***** Free list of plugins *****/
Plg_FreeListPlugins ();
}
/*****************************************************************************/
/************************* Get list of current plugins ***********************/
/*****************************************************************************/
static void Plg_GetListPlugins (void)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned NumPlg;
struct Plugin *Plg;
/***** Get plugins from database *****/
2018-11-01 19:23:52 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get plugins",
"SELECT PlgCod,Name,Description,Logo,AppKey,URL,IP"
" FROM plugins ORDER BY Name");
2014-12-01 23:55:08 +01:00
/***** Count number of rows in result *****/
if (NumRows) // Plugins found...
{
Gbl.Plugins.Num = (unsigned) NumRows;
/***** Create list with plugins *****/
if ((Gbl.Plugins.Lst = (struct Plugin *) calloc ((size_t) Gbl.Plugins.Num,sizeof (struct Plugin))) == NULL)
2018-10-18 20:06:54 +02:00
Lay_NotEnoughMemoryExit ();
2014-12-01 23:55:08 +01:00
/***** Get the plugins *****/
for (NumPlg = 0;
NumPlg < Gbl.Plugins.Num;
NumPlg++)
{
Plg = &(Gbl.Plugins.Lst[NumPlg]);
/* Get next plugin */
row = mysql_fetch_row (mysql_res);
/* Get plugin code (row[0]) */
if ((Plg->PlgCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of plugin.");
/* Get the name of the plugin (row[1]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->Name,row[1],
2017-03-08 01:21:21 +01:00
Plg_MAX_BYTES_PLUGIN_NAME);
2014-12-01 23:55:08 +01:00
/* Get the description of the plugin (row[2]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->Description,row[2],
2017-03-08 01:21:21 +01:00
Plg_MAX_BYTES_PLUGIN_DESCRIPTION);
2014-12-01 23:55:08 +01:00
/* Get the logo of the plugin (row[3]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->Logo,row[3],
2017-03-08 01:21:21 +01:00
Plg_MAX_BYTES_PLUGIN_LOGO);
2014-12-01 23:55:08 +01:00
/* Get the application key of the plugin (row[4]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->AppKey,row[4],
2017-03-08 01:21:21 +01:00
Plg_MAX_BYTES_PLUGIN_APP_KEY);
2014-12-01 23:55:08 +01:00
/* Get the URL of the plugin (row[5]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->URL,row[5],
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
/* Get the IP of the plugin (row[6]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->IP,row[6],
2017-03-07 11:03:05 +01:00
Cns_MAX_BYTES_IP);
2014-12-01 23:55:08 +01:00
}
}
else
Gbl.Plugins.Num = 0;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/*************************** Get data of a plugin ****************************/
/*****************************************************************************/
bool Plg_GetDataOfPluginByCod (struct Plugin *Plg)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
bool PluginFound;
/***** Clear data *****/
2017-03-13 13:43:37 +01:00
Plg->Name[0] =
Plg->Description[0] =
Plg->Logo[0] =
Plg->URL[0] =
Plg->IP[0] = '\0';
2014-12-01 23:55:08 +01:00
/***** Check if plugin code is correct *****/
if (Plg->PlgCod <= 0)
return false;
// Plg->PlgCod > 0
/***** Get data of a plugin from database *****/
2018-11-01 19:23:52 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a plugin",
"SELECT Name,Description,Logo,AppKey,URL,IP"
" FROM plugins"
" WHERE PlgCod=%ld",
Plg->PlgCod);
2014-12-01 23:55:08 +01:00
/***** Count number of rows in result *****/
if (NumRows) // Plugin found...
{
PluginFound = true;
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get the name of the plugin (row[0]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->Name,row[0],
2017-03-08 01:21:21 +01:00
Plg_MAX_BYTES_PLUGIN_NAME);
2014-12-01 23:55:08 +01:00
/* Get the description of the plugin (row[1]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->Description,row[1],
2017-03-08 01:21:21 +01:00
Plg_MAX_BYTES_PLUGIN_DESCRIPTION);
2014-12-01 23:55:08 +01:00
/* Get the logo of the plugin (row[2]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->Logo,row[2],
2017-03-08 01:21:21 +01:00
Plg_MAX_BYTES_PLUGIN_LOGO);
2014-12-01 23:55:08 +01:00
/* Get the application key of the plugin (row[3]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->AppKey,row[3],
2017-03-08 01:21:21 +01:00
Plg_MAX_BYTES_PLUGIN_APP_KEY);
2014-12-01 23:55:08 +01:00
/* Get the URL of the plugin (row[4]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->URL,row[4],
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
/* Get the IP of the plugin (row[5]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->IP,row[5],
2017-03-07 11:03:05 +01:00
Cns_MAX_BYTES_IP);
2014-12-01 23:55:08 +01:00
}
else
PluginFound = false;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return PluginFound;
}
/*****************************************************************************/
/*************************** Free list of plugins ****************************/
/*****************************************************************************/
void Plg_FreeListPlugins (void)
{
if (Gbl.Plugins.Lst)
{
/***** Free memory used by the list of plugins *****/
free ((void *) Gbl.Plugins.Lst);
Gbl.Plugins.Lst = NULL;
Gbl.Plugins.Num = 0;
}
}
/*****************************************************************************/
/**************************** List all the plugins ***************************/
/*****************************************************************************/
static void Plg_ListPluginsForEdition (void)
{
extern const char *Txt_Plugins;
unsigned NumPlg;
struct Plugin *Plg;
2017-06-12 14:16:33 +02:00
/***** Start box and table *****/
2017-06-11 22:26:40 +02:00
Box_StartBoxTable (NULL,Txt_Plugins,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE,2);
2017-06-12 14:16:33 +02:00
/***** Write heading *****/
2014-12-01 23:55:08 +01:00
Plg_PutHeadPlugins ();
/***** Write all the plugins *****/
for (NumPlg = 0;
NumPlg < Gbl.Plugins.Num;
NumPlg++)
{
Plg = &Gbl.Plugins.Lst[NumPlg];
/* Put icon to remove plugin */
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"BM\">");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRemPlg);
2014-12-01 23:55:08 +01:00
Plg_PutParamPlgCod (Plg->PlgCod);
2017-06-11 19:13:28 +02:00
Ico_PutIconRemove ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Plugin code */
2015-08-24 11:25:20 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
"%ld"
2014-12-23 22:47:09 +01:00
"</td>",
2014-12-01 23:55:08 +01:00
Plg->PlgCod);
/* Plugin logo */
2015-09-05 19:19:39 +02:00
// TODO: Change plugin icons to 32x32
2015-09-28 18:28:29 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\" style=\"width:45px;\">"
2015-07-22 13:49:39 +02:00
"<img src=\"%s/%s/%s24x24.gif\""
" alt=\"%s\" title=\"%s\""
2016-11-14 10:05:41 +01:00
" class=\"ICO40x40\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2014-12-29 21:35:12 +01:00
Gbl.Prefs.IconsURL,Cfg_ICON_FOLDER_PLUGINS,
2015-07-22 13:49:39 +02:00
Gbl.Plugins.Lst[NumPlg].Logo,
Gbl.Plugins.Lst[NumPlg].Name,
Gbl.Plugins.Lst[NumPlg].Name);
2014-12-01 23:55:08 +01:00
/* Plugin name */
2015-08-24 11:25:20 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRenPlg);
2014-12-01 23:55:08 +01:00
Plg_PutParamPlgCod (Plg->PlgCod);
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"Name\""
" size=\"10\" maxlength=\"%u\" value=\"%s\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 01:21:21 +01:00
Plg_MAX_CHARS_PLUGIN_NAME,Plg->Name,Gbl.Form.Id);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Plugin description */
2015-08-24 11:25:20 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgPlgDes);
2014-12-01 23:55:08 +01:00
Plg_PutParamPlgCod (Plg->PlgCod);
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"Description\""
" size=\"30\" maxlength=\"%u\" value=\"%s\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 01:21:21 +01:00
Plg_MAX_CHARS_PLUGIN_DESCRIPTION,Plg->Description,Gbl.Form.Id);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Plugin logo */
2015-08-24 11:25:20 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgPlgLog);
2014-12-01 23:55:08 +01:00
Plg_PutParamPlgCod (Plg->PlgCod);
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"Logo\""
" size=\"4\" maxlength=\"%u\" value=\"%s\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 01:21:21 +01:00
Plg_MAX_CHARS_PLUGIN_LOGO,Plg->Logo,Gbl.Form.Id);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Plugin application key */
2015-08-24 11:25:20 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgPlgAppKey);
2014-12-01 23:55:08 +01:00
Plg_PutParamPlgCod (Plg->PlgCod);
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"AppKey\""
" size=\"16\" maxlength=\"%u\" value=\"%s\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-08 01:21:21 +01:00
Plg_MAX_CHARS_PLUGIN_APP_KEY,Plg->AppKey,Gbl.Form.Id);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Plugin URL */
2015-08-24 11:25:20 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgPlgURL);
2014-12-01 23:55:08 +01:00
Plg_PutParamPlgCod (Plg->PlgCod);
2016-11-20 14:32:15 +01:00
fprintf (Gbl.F.Out,"<input type=\"url\" name=\"URL\""
2015-10-22 14:49:48 +02:00
" size=\"15\" maxlength=\"%u\" value=\"%s\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-07 01:56:41 +01:00
Cns_MAX_CHARS_WWW,Plg->URL,Gbl.Form.Id);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Plugin IP */
2015-08-24 11:25:20 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgPlgIP);
2014-12-01 23:55:08 +01:00
Plg_PutParamPlgCod (Plg->PlgCod);
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"IP\""
" size=\"10\" maxlength=\"%u\" value=\"%s\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-07 11:03:05 +01:00
Cns_MAX_CHARS_IP,Plg->IP,
Gbl.Form.Id);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2017-06-10 21:38:10 +02:00
Box_EndBoxTable ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Write parameter with code of plugin *********************/
/*****************************************************************************/
static void Plg_PutParamPlgCod (long PlgCod)
{
Par_PutHiddenParamLong ("PlgCod",PlgCod);
}
/*****************************************************************************/
/********************* Get parameter with code of plugin *********************/
/*****************************************************************************/
long Plg_GetParamPlgCod (void)
{
2017-01-28 20:32:50 +01:00
/***** Get code of plugin *****/
return Par_GetParToLong ("PlgCod");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************************* Remove a plugin *****************************/
/*****************************************************************************/
void Plg_RemovePlugin (void)
{
extern const char *Txt_Plugin_X_removed;
struct Plugin Plg;
/***** Get plugin code *****/
if ((Plg.PlgCod = Plg_GetParamPlgCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of plugin is missing.");
/***** Get data of the plugin from database *****/
Plg_GetDataOfPluginByCod (&Plg);
/***** Remove plugin *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove a plugin",
"DELETE FROM plugins WHERE PlgCod=%ld",
Plg.PlgCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_Plugin_X_removed,
Plg.Name);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
Plg_EditPlugins ();
}
/*****************************************************************************/
/************************ Change the name of a plugin ************************/
/*****************************************************************************/
void Plg_RenamePlugin (void)
{
extern const char *Txt_You_can_not_leave_the_name_of_the_plugin_X_empty;
extern const char *Txt_The_plugin_X_already_exists;
extern const char *Txt_The_plugin_X_has_been_renamed_as_Y;
extern const char *Txt_The_name_of_the_plugin_X_has_not_changed;
struct Plugin *Plg;
2017-03-08 01:21:21 +01:00
char NewPlgName[Plg_MAX_BYTES_PLUGIN_NAME + 1];
2014-12-01 23:55:08 +01:00
Plg = &Gbl.Plugins.EditingPlg;
/***** Get parameters from form *****/
/* Get the code of the plugin */
if ((Plg->PlgCod = Plg_GetParamPlgCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of plugin is missing.");
/* Get the new name for the plugin */
2017-03-08 01:21:21 +01:00
Par_GetParToText ("Name",NewPlgName,Plg_MAX_BYTES_PLUGIN_NAME);
2014-12-01 23:55:08 +01:00
/***** Get from the database the old name of the plugin *****/
Plg_GetDataOfPluginByCod (Plg);
/***** Check if new name is empty *****/
if (!NewPlgName[0])
{
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_You_can_not_leave_the_name_of_the_plugin_X_empty,
Plg->Name);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
else
{
/***** Check if old and new names are the same (this happens when user press enter with no changes in the form) *****/
if (strcmp (Plg->Name,NewPlgName)) // Different names
{
/***** If plugin was in database... *****/
if (Plg_CheckIfPluginNameExists (NewPlgName,Plg->PlgCod))
{
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_The_plugin_X_already_exists,
NewPlgName);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
else
{
/* Update the table changing old name by new name */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the name of a plugin",
"UPDATE plugins SET Name='%s' WHERE PlgCod=%ld",
NewPlgName,Plg->PlgCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_The_plugin_X_has_been_renamed_as_Y,
Plg->Name,NewPlgName);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
}
else // The same name
{
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_The_name_of_the_plugin_X_has_not_changed,
Plg->Name);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_INFO,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
}
/***** Show the form again *****/
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->Name,NewPlgName,
2017-03-08 01:21:21 +01:00
Plg_MAX_BYTES_PLUGIN_NAME);
2014-12-01 23:55:08 +01:00
Plg_EditPlugins ();
}
/*****************************************************************************/
/******************** Check if the name of plugin exists *********************/
/*****************************************************************************/
static bool Plg_CheckIfPluginNameExists (const char *Name,long PlgCod)
{
/***** Get number of plugins with a name from database *****/
2018-11-03 20:52:00 +01:00
return (DB_QueryCOUNT ("can not check if the name of a plugin"
" already existed",
"SELECT COUNT(*) FROM plugins"
" WHERE Name='%s' AND PlgCod<>%ld",
Name,PlgCod) != 0);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Change the description of a plugin **********************/
/*****************************************************************************/
void Plg_ChangePlgDescription (void)
{
extern const char *Txt_The_new_description_is_X;
extern const char *Txt_You_can_not_leave_the_description_empty;
struct Plugin *Plg;
2017-03-08 01:21:21 +01:00
char NewDescription[Plg_MAX_BYTES_PLUGIN_DESCRIPTION + 1];
2014-12-01 23:55:08 +01:00
Plg = &Gbl.Plugins.EditingPlg;
/***** Get parameters from form *****/
/* Get the code of the plugin */
if ((Plg->PlgCod = Plg_GetParamPlgCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of plugin is missing.");
/* Get the new description for the plugin */
2017-03-08 01:21:21 +01:00
Par_GetParToText ("Description",NewDescription,Plg_MAX_BYTES_PLUGIN_DESCRIPTION);
2014-12-01 23:55:08 +01:00
/***** Check if new description is empty *****/
if (NewDescription[0])
{
/* Update the table changing old description by new description */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the description of a plugin",
"UPDATE plugins SET Description='%s' WHERE PlgCod=%ld",
NewDescription,Plg->PlgCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_The_new_description_is_X,
NewDescription);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
else
2018-10-16 15:16:32 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_the_description_empty);
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->Description,NewDescription,
2017-03-08 01:21:21 +01:00
Plg_MAX_BYTES_PLUGIN_DESCRIPTION);
2014-12-01 23:55:08 +01:00
Plg_EditPlugins ();
}
/*****************************************************************************/
/************************ Change the logo of a plugin ************************/
/*****************************************************************************/
void Plg_ChangePlgLogo (void)
{
extern const char *Txt_The_new_logo_is_X;
extern const char *Txt_You_can_not_leave_the_logo_empty;
struct Plugin *Plg;
2017-03-08 01:21:21 +01:00
char NewLogo[Plg_MAX_BYTES_PLUGIN_LOGO + 1];
2014-12-01 23:55:08 +01:00
Plg = &Gbl.Plugins.EditingPlg;
/***** Get parameters from form *****/
/* Get the code of the plugin */
if ((Plg->PlgCod = Plg_GetParamPlgCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of plugin is missing.");
/* Get the new logo for the plugin */
2017-03-08 01:21:21 +01:00
Par_GetParToText ("Logo",NewLogo,Plg_MAX_BYTES_PLUGIN_LOGO);
2014-12-01 23:55:08 +01:00
/***** Check if new logo is empty *****/
if (NewLogo[0])
{
/* Update the table changing old logo by new logo */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the logo of a plugin",
"UPDATE plugins SET Logo='%s' WHERE PlgCod=%ld",
NewLogo,Plg->PlgCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_The_new_logo_is_X,
NewLogo);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_the_logo_empty);
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->Logo,NewLogo,
2017-03-08 01:21:21 +01:00
Plg_MAX_BYTES_PLUGIN_LOGO);
2014-12-01 23:55:08 +01:00
Plg_EditPlugins ();
}
/*****************************************************************************/
/****************** Change the application key of a plugin *******************/
/*****************************************************************************/
void Plg_ChangePlgAppKey (void)
{
extern const char *Txt_The_new_logo_is_X; // TODO: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
extern const char *Txt_You_can_not_leave_the_logo_empty;// TODO: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
struct Plugin *Plg;
2017-03-08 01:21:21 +01:00
char NewAppKey[Plg_MAX_BYTES_PLUGIN_APP_KEY + 1];
2014-12-01 23:55:08 +01:00
Plg = &Gbl.Plugins.EditingPlg;
/***** Get parameters from form *****/
/* Get the code of the plugin */
if ((Plg->PlgCod = Plg_GetParamPlgCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of plugin is missing.");
/* Get the new logo for the plugin */
2017-03-08 01:21:21 +01:00
Par_GetParToText ("AppKey",NewAppKey,Plg_MAX_BYTES_PLUGIN_APP_KEY);
2014-12-01 23:55:08 +01:00
/***** Check if new logo is empty *****/
if (NewAppKey[0])
{
/* Update the table changing old application key by new application key */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the application key of a plugin",
"UPDATE plugins SET AppKey='%s' WHERE PlgCod=%ld",
NewAppKey,Plg->PlgCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_The_new_logo_is_X, // TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
NewAppKey);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_the_logo_empty); // TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->AppKey,NewAppKey,
2017-03-08 01:21:21 +01:00
Plg_MAX_BYTES_PLUGIN_APP_KEY);
2014-12-01 23:55:08 +01:00
Plg_EditPlugins ();
}
/*****************************************************************************/
/************************ Change the URL of a plugin *************************/
/*****************************************************************************/
void Plg_ChangePlgURL (void)
{
extern const char *Txt_The_new_URL_is_X;
extern const char *Txt_You_can_not_leave_the_URL_empty;
struct Plugin *Plg;
2017-03-07 01:56:41 +01:00
char NewURL[Cns_MAX_BYTES_WWW + 1];
2014-12-01 23:55:08 +01:00
Plg = &Gbl.Plugins.EditingPlg;
/***** Get parameters from form *****/
/* Get the code of the plugin */
if ((Plg->PlgCod = Plg_GetParamPlgCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of plugin is missing.");
/* Get the new URL for the plugin */
2017-03-07 01:56:41 +01:00
Par_GetParToText ("URL",NewURL,Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
/***** Check if new URL is empty *****/
if (NewURL[0])
{
/* Update the table changing old WWW by new WWW */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the URL of a plugin",
"UPDATE plugins SET URL='%s' WHERE PlgCod=%ld",
NewURL,Plg->PlgCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_The_new_URL_is_X,
NewURL);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_the_URL_empty);
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->URL,NewURL,
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
Plg_EditPlugins ();
}
/*****************************************************************************/
/************************* Change the IP of a plugin *************************/
/*****************************************************************************/
void Plg_ChangePlgIP (void)
{
extern const char *Txt_The_new_IP_address_is_X;
extern const char *Txt_You_can_not_leave_the_IP_address_empty;
struct Plugin *Plg;
2017-03-07 11:03:05 +01:00
char NewIP[Cns_MAX_BYTES_IP + 1];
2014-12-01 23:55:08 +01:00
Plg = &Gbl.Plugins.EditingPlg;
/***** Get parameters from form *****/
/* Get the code of the plugin */
if ((Plg->PlgCod = Plg_GetParamPlgCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of plugin is missing.");
/* Get the new IP for the plugin */
2017-03-07 11:03:05 +01:00
Par_GetParToText ("IP",NewIP,Cns_MAX_BYTES_IP);
2014-12-01 23:55:08 +01:00
/***** Check if new IP is empty *****/
if (NewIP[0])
{
/* Update the table changing old IP by new IP */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the IP address of a plugin",
"UPDATE plugins SET IP='%s' WHERE PlgCod=%ld",
NewIP,Plg->PlgCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_The_new_IP_address_is_X,
NewIP);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
else
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_the_IP_address_empty);
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
2017-01-17 03:10:43 +01:00
Str_Copy (Plg->IP,NewIP,
2017-03-07 11:03:05 +01:00
Cns_MAX_BYTES_IP);
2014-12-01 23:55:08 +01:00
Plg_EditPlugins ();
}
/*****************************************************************************/
/********************* Put a form to create a new plugin *********************/
/*****************************************************************************/
static void Plg_PutFormToCreatePlugin (void)
{
extern const char *Txt_New_plugin;
extern const char *Txt_Name;
extern const char *Txt_Description;
extern const char *Txt_Logo;
extern const char *Txt_Application_key;
extern const char *Txt_URL;
extern const char *Txt_IP;
extern const char *Txt_Create_plugin;
struct Plugin *Plg;
Plg = &Gbl.Plugins.EditingPlg;
/***** Start form *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActNewPlg);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box and table *****/
2017-06-10 21:38:10 +02:00
Box_StartBoxTable (NULL,Txt_New_plugin,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
/***** Write heading *****/
fprintf (Gbl.F.Out,"<tr>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Name,
Txt_Description,
Txt_Logo,
Txt_Application_key,
Txt_URL,
Txt_IP);
/***** Plugin name *****/
2015-08-24 11:25:20 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"Name\""
2016-11-19 20:37:01 +01:00
" size=\"10\" maxlength=\"%u\" value=\"%s\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2017-03-08 01:21:21 +01:00
Plg_MAX_CHARS_PLUGIN_NAME,Plg->Name);
2014-12-01 23:55:08 +01:00
/***** Plugin description *****/
2015-08-24 11:25:20 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"Description\""
2016-11-19 20:37:01 +01:00
" size=\"30\" maxlength=\"%u\" value=\"%s\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2017-03-08 01:21:21 +01:00
Plg_MAX_CHARS_PLUGIN_DESCRIPTION,Plg->Description);
2014-12-01 23:55:08 +01:00
/***** Plugin logo *****/
2015-08-24 11:25:20 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"Logo\""
2016-11-19 20:37:01 +01:00
" size=\"4\" maxlength=\"%u\" value=\"%s\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2017-03-08 01:21:21 +01:00
Plg_MAX_CHARS_PLUGIN_LOGO,Plg->Logo);
2014-12-01 23:55:08 +01:00
/***** Plugin application key *****/
2015-08-24 11:25:20 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"AppKey\""
2016-11-19 20:37:01 +01:00
" size=\"16\" maxlength=\"%u\" value=\"%s\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2017-03-08 01:21:21 +01:00
Plg_MAX_CHARS_PLUGIN_APP_KEY,Plg->AppKey);
2014-12-01 23:55:08 +01:00
/***** Plugin URL *****/
2015-08-24 11:25:20 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
2016-11-20 14:32:15 +01:00
"<input type=\"url\" name=\"URL\""
2016-11-19 20:37:01 +01:00
" size=\"15\" maxlength=\"%u\" value=\"%s\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>",
2017-03-07 01:56:41 +01:00
Cns_MAX_CHARS_WWW,Plg->URL);
2014-12-01 23:55:08 +01:00
/***** Plugin IP address *****/
2015-08-24 11:25:20 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"IP\""
2016-11-19 20:37:01 +01:00
" size=\"10\" maxlength=\"%u\" value=\"%s\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>"
"</tr>",
2017-03-07 11:03:05 +01:00
Cns_MAX_CHARS_IP,Plg->IP);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End table, send button and end box *****/
2017-06-11 19:02:40 +02:00
Box_EndBoxTableWithButton (Btn_CREATE_BUTTON,Txt_Create_plugin);
2014-12-01 23:55:08 +01:00
2015-04-11 23:46:21 +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 plugin *******************/
/*****************************************************************************/
static void Plg_PutHeadPlugins (void)
{
extern const char *Txt_Code;
extern const char *Txt_Name;
extern const char *Txt_Description;
extern const char *Txt_Logo;
extern const char *Txt_Application_key;
extern const char *Txt_URL;
extern const char *Txt_IP;
fprintf (Gbl.F.Out,"<tr>"
2014-12-27 00:28:19 +01:00
"<th></th>"
2015-09-06 20:02:14 +02:00
"<th class=\"RIGHT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-28 18:28:29 +02:00
"<th style=\"width:35px;\"></th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2015-09-06 20:02:14 +02:00
"<th class=\"LEFT_MIDDLE\">"
2014-12-27 00:28:19 +01:00
"%s"
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Code,
Txt_Name,
Txt_Description,
Txt_Logo,
Txt_Application_key,
Txt_URL,
Txt_IP);
}
/*****************************************************************************/
/****************** Receive form to create a new plugin **********************/
/*****************************************************************************/
void Plg_RecFormNewPlg (void)
{
extern const char *Txt_The_plugin_X_already_exists;
extern const char *Txt_You_must_specify_the_logo_the_application_key_the_URL_and_the_IP_address_of_the_new_plugin;
extern const char *Txt_You_must_specify_the_name_and_the_description_of_the_new_plugin;
struct Plugin *Plg;
Plg = &Gbl.Plugins.EditingPlg;
/***** Get parameters from form *****/
/* Get plugin name */
2017-03-08 01:21:21 +01:00
Par_GetParToText ("Name",Plg->Name,Plg_MAX_BYTES_PLUGIN_NAME);
2014-12-01 23:55:08 +01:00
/* Get plugin description */
2017-03-08 01:21:21 +01:00
Par_GetParToText ("Description",Plg->Description,Plg_MAX_BYTES_PLUGIN_DESCRIPTION);
2014-12-01 23:55:08 +01:00
/* Get plugin logo */
2017-03-08 01:21:21 +01:00
Par_GetParToText ("Logo",Plg->Logo,Plg_MAX_BYTES_PLUGIN_LOGO);
2014-12-01 23:55:08 +01:00
/* Get plugin application key */
2017-03-08 01:21:21 +01:00
Par_GetParToText ("AppKey",Plg->AppKey,Plg_MAX_BYTES_PLUGIN_APP_KEY);
2014-12-01 23:55:08 +01:00
/* Get plugin URL */
2017-03-07 01:56:41 +01:00
Par_GetParToText ("URL",Plg->URL,Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
/* Get plugin IP address */
2017-03-07 11:03:05 +01:00
Par_GetParToText ("IP",Plg->IP,Cns_MAX_BYTES_IP);
2014-12-01 23:55:08 +01:00
if (Plg->Name[0]) // If there's a plugin name
{
if (Plg->Logo[0] && Plg->AppKey[0] && Plg->URL[0] && Plg->IP[0])
{
/***** If name of plugin was in database... *****/
if (Plg_CheckIfPluginNameExists (Plg->Name,-1L))
{
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_The_plugin_X_already_exists,
Plg->Name);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
else // Add new plugin to database
Plg_CreatePlugin (Plg);
}
else // If there is not a logo, a URL or a IP
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_specify_the_logo_the_application_key_the_URL_and_the_IP_address_of_the_new_plugin);
2014-12-01 23:55:08 +01:00
}
else // If there is not a plugin name
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_specify_the_name_and_the_description_of_the_new_plugin);
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
Plg_EditPlugins ();
}
/*****************************************************************************/
/***************************** Create a new plugin ***************************/
/*****************************************************************************/
static void Plg_CreatePlugin (struct Plugin *Plg)
{
extern const char *Txt_Created_new_plugin_X;
/***** Create a new plugin *****/
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not create plugin",
"INSERT INTO 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);
2014-12-01 23:55:08 +01:00
/***** Write success message *****/
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_Created_new_plugin_X,
Plg->Name);
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******** Function called when a web service if required by a plugin *********/
/*****************************************************************************/
void Plg_WebService (void)
{
/***** Call soap service *****/
Svc_WebService ();
/***** All the output is made, so don't write anymore *****/
2015-11-27 21:24:24 +01:00
Gbl.Layout.DivsEndWritten = Gbl.Layout.HTMLEndWritten = true;
2014-12-01 23:55:08 +01:00
}