Version 21.12: Sep 22, 2021 New module swad_link_database for database queries related to institutional links.

This commit is contained in:
acanas 2021-09-22 13:20:57 +02:00
parent ddf9d0dfdc
commit ebc93b6c27
9 changed files with 624 additions and 457 deletions

View File

@ -59,7 +59,8 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
swad_indicator_database.o swad_info.o swad_info_database.o \
swad_institution.o swad_institution_config.o \
swad_institution_database.o \
swad_language.o swad_layout.o swad_link.o swad_log.o swad_logo.o \
swad_language.o swad_layout.o swad_link.o swad_link_database.o \
swad_log.o swad_logo.o \
swad_MAC.o swad_mail.o swad_main.o swad_maintenance.o swad_map.o \
swad_mark.o swad_match.o swad_match_print.o swad_match_result.o \
swad_media.o swad_media_database.o swad_menu.o swad_message.o \

View File

@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
*/
#define Log_PLATFORM_VERSION "SWAD 21.11.1 (2021-09-22)"
#define Log_PLATFORM_VERSION "SWAD 21.12 (2021-09-22)"
#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.12: Sep 22, 2021 New module swad_link_database for database queries related to institutional links. (316361 lines)
Version 21.11.1: Sep 22, 2021 Queries moved to module swad_info_database. (316237 lines)
Version 21.11: Sep 22, 2021 New module swad_info_database for database queries related to course information. (316228 lines)
Version 21.10.1: Sep 21, 2021 Fixed bugs in roles. Reported by Javier Fernández Baldomero and Carmen García Miranda. (316111 lines)

View File

@ -196,18 +196,11 @@ void Lan_ChangeLanguage (void)
void Lan_UpdateMyLanguageToCurrentLanguage (void)
{
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
/***** Set my language to the current language *****/
Gbl.Usrs.Me.UsrDat.Prefs.Language = Gbl.Prefs.Language;
/***** Update my language in database *****/
DB_QueryUPDATE ("can not update your language",
"UPDATE usr_data"
" SET Language='%s'"
" WHERE UsrCod=%ld",
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Gbl.Usrs.Me.UsrDat.UsrCod);
Set_DB_UpdateMySettingsAboutLanguage ();
}
/*****************************************************************************/

View File

@ -1334,12 +1334,14 @@ void Lay_PutContextualCheckbox (Act_Action_t NextAction,
if (FuncParams)
FuncParams ();
/***** Begin container and label *****/
/***** Begin container *****/
HTM_DIV_Begin ("class=\"CONTEXT_OPT %s %s\" title=\"%s\"",
Checked ? "CHECKBOX_CHECKED" :
"CHECKBOX_UNCHECKED",
The_ClassFormOutBoxBold[Gbl.Prefs.Theme],
Title);
/***** Begin label *****/
HTM_LABEL_Begin (NULL);
/****** Checkbox *****/
@ -1355,8 +1357,10 @@ void Lay_PutContextualCheckbox (Act_Action_t NextAction,
if (Text[0])
HTM_TxtF (" %s",Text);
/***** End label and container *****/
/***** End label *****/
HTM_LABEL_End ();
/***** End container *****/
HTM_DIV_End ();
/***** End form *****/
@ -1544,6 +1548,7 @@ void Lay_WriteHeaderClassPhoto (bool PrintView,bool DrawingClassPhoto,
/***** Begin table *****/
HTM_TABLE_BeginWidePadding (10);
HTM_TR_Begin (NULL);
/***** First column: institution logo *****/
@ -1605,8 +1610,9 @@ void Lay_WriteHeaderClassPhoto (bool PrintView,bool DrawingClassPhoto,
}
HTM_TD_End ();
/***** End table *****/
HTM_TR_End ();
/***** End table *****/
HTM_TABLE_End ();
}
@ -1726,7 +1732,9 @@ void Lay_BeginHTMLFile (FILE *File,const char *Title)
"<head>\n"
"<meta http-equiv=\"Content-Type\""
" content=\"text/html;charset=windows-1252\" />\n"
"<title>%s</title>\n"
"<title>"
"%s"
"</title>\n"
"</head>\n",
Lan_STR_LANG_ID[Gbl.Prefs.Language], // Language
Title); // Page title

View File

@ -39,6 +39,7 @@
#include "swad_HTML.h"
#include "swad_language.h"
#include "swad_link.h"
#include "swad_link_database.h"
#include "swad_parameter.h"
/*****************************************************************************/
@ -72,16 +73,15 @@ static void Lnk_WriteListOfLinks (void);
static void Lnk_EditLinksInternal (void);
static void Lnk_PutIconsEditingLinks (__attribute__((unused)) void *Args);
static void Lnk_GetDataOfLink (MYSQL_RES *mysql_res,struct Link *Lnk);
static void Lnk_ListLinksForEdition (void);
static void Lnk_PutParamLnkCod (void *LnkCod);
static void Lnk_RenameLink (Cns_ShrtOrFullName_t ShrtOrFullName);
static bool Lnk_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod);
static void Lnk_UpdateLnkNameDB (long LnkCod,const char *FieldName,const char *NewLnkName);
static void Lnk_PutFormToCreateLink (void);
static void Lnk_PutHeadLinks (void);
static void Lnk_CreateLink (struct Link *Lnk);
static void Lnk_EditingLinkConstructor (void);
static void Lnk_EditingLinkDestructor (void);
@ -173,6 +173,7 @@ void Lnk_WriteMenuWithInstitutionalLinks (void)
Frm_EndForm ();
Lnk_WriteListOfLinks ();
HTM_DIV_End ();
}
@ -287,23 +288,12 @@ void Lnk_PutIconToViewLinks (void)
void Lnk_GetListLinks (void)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumLnk;
struct Link *Lnk;
if (Gbl.DB.DatabaseIsOpen)
{
/***** Get institutional links from database *****/
Gbl.Links.Num = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutional links",
"SELECT LnkCod," // row[0]
"ShortName," // row[1]
"FullName," // row[2]
"WWW" // row[3]
" FROM lnk_links"
" ORDER BY ShortName");
if (Gbl.Links.Num) // Places found...
if ((Gbl.Links.Num = Lnk_DB_GetLinks (&mysql_res))) // Links found...
{
/***** Create list with places *****/
if ((Gbl.Links.Lst = calloc ((size_t) Gbl.Links.Num,
@ -314,22 +304,8 @@ void Lnk_GetListLinks (void)
for (NumLnk = 0;
NumLnk < Gbl.Links.Num;
NumLnk++)
{
Lnk = &(Gbl.Links.Lst[NumLnk]);
/* Get next link */
row = mysql_fetch_row (mysql_res);
/* Get link code (row[0]) */
if ((Lnk->LnkCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongLinkExit ();
/* Get the short name (row[0]), the full name (row[1])
and de URL (row[2]) of the link */
Str_Copy (Lnk->ShrtName,row[1],sizeof (Lnk->ShrtName) - 1);
Str_Copy (Lnk->FullName,row[2],sizeof (Lnk->FullName) - 1);
Str_Copy (Lnk->WWW ,row[3],sizeof (Lnk->WWW ) - 1);
}
Lnk_GetDataOfLink (mysql_res,&(Gbl.Links.Lst[NumLnk]));
}
/***** Free structure that stores the query result *****/
@ -344,38 +320,43 @@ void Lnk_GetListLinks (void)
void Lnk_GetDataOfLinkByCod (struct Link *Lnk)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
/***** Clear data *****/
Lnk->ShrtName[0] = Lnk->FullName[0] = Lnk->WWW[0] = '\0';
Lnk->ShrtName[0] =
Lnk->FullName[0] =
Lnk->WWW[0] = '\0';
/***** Check if link code is correct *****/
if (Lnk->LnkCod > 0)
{
/***** Get data of an institutional link from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get data of an institutional link",
"SELECT ShortName," // row[0]
"FullName," // row[1]
"WWW" // row[2]
" FROM lnk_links"
" WHERE LnkCod=%ld",
Lnk->LnkCod)) // Link found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get the short name (row[0]), the full name (row[1])
and de URL (row[2]) of the link */
Str_Copy (Lnk->ShrtName,row[0],sizeof (Lnk->ShrtName) - 1);
Str_Copy (Lnk->FullName,row[1],sizeof (Lnk->FullName) - 1);
Str_Copy (Lnk->WWW ,row[2],sizeof (Lnk->WWW ) - 1);
}
if (Lnk_DB_GetDataOfLinkByCod (&mysql_res,Lnk->LnkCod)) // Link found...
Lnk_GetDataOfLink (mysql_res,Lnk);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
}
/*****************************************************************************/
/**************************** Get data of link *******************************/
/*****************************************************************************/
static void Lnk_GetDataOfLink (MYSQL_RES *mysql_res,struct Link *Lnk)
{
MYSQL_ROW row;
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
/***** Get the short name (row[0]),
the full name (row[1])
and the URL (row[2]) of the link *****/
Str_Copy (Lnk->ShrtName,row[0],sizeof (Lnk->ShrtName) - 1);
Str_Copy (Lnk->FullName,row[1],sizeof (Lnk->FullName) - 1);
Str_Copy (Lnk->WWW ,row[2],sizeof (Lnk->WWW ) - 1);
}
/*****************************************************************************/
/**************************** Free list of links *****************************/
/*****************************************************************************/
@ -501,10 +482,7 @@ void Lnk_RemoveLink (void)
Lnk_GetDataOfLinkByCod (Lnk_EditingLnk);
/***** Remove link *****/
DB_QueryDELETE ("can not remove an institutional link",
"DELETE FROM lnk_links"
" WHERE LnkCod=%ld",
Lnk_EditingLnk->LnkCod);
Lnk_DB_RemoveLink (Lnk_EditingLnk->LnkCod);
/***** Write message to show the change made *****/
Ale_CreateAlert (Ale_SUCCESS,NULL,
@ -588,14 +566,14 @@ static void Lnk_RenameLink (Cns_ShrtOrFullName_t ShrtOrFullName)
if (strcmp (CurrentLnkName,NewLnkName)) // Different names
{
/***** If link was in database... *****/
if (Lnk_CheckIfLinkNameExists (ParamName,NewLnkName,Lnk_EditingLnk->LnkCod))
if (Lnk_DB_CheckIfLinkNameExists (ParamName,NewLnkName,Lnk_EditingLnk->LnkCod))
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_link_X_already_exists,
NewLnkName);
else
{
/* Update the table changing old name by new name */
Lnk_UpdateLnkNameDB (Lnk_EditingLnk->LnkCod,FieldName,NewLnkName);
Lnk_DB_UpdateLnkName (Lnk_EditingLnk->LnkCod,FieldName,NewLnkName);
/* Write message to show the change made */
Ale_CreateAlert (Ale_SUCCESS,NULL,
@ -615,37 +593,6 @@ static void Lnk_RenameLink (Cns_ShrtOrFullName_t ShrtOrFullName)
Str_Copy (CurrentLnkName,NewLnkName,MaxBytes);
}
/*****************************************************************************/
/********************** Check if the name of link exists *********************/
/*****************************************************************************/
static bool Lnk_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod)
{
/***** Get number of links with a name from database *****/
return (DB_QueryCOUNT ("can not check if the name of an institutional link"
" already existed",
"SELECT COUNT(*)"
" FROM lnk_links"
" WHERE %s='%s'"
" AND LnkCod<>%ld",
FieldName,Name,LnkCod) != 0);
}
/*****************************************************************************/
/************ Update link name in table of institutional links ***************/
/*****************************************************************************/
static void Lnk_UpdateLnkNameDB (long LnkCod,const char *FieldName,const char *NewLnkName)
{
/***** Update institutional link changing old name by new name */
DB_QueryUPDATE ("can not update the name of an institutional link",
"UPDATE lnk_links"
" SET %s='%s'"
" WHERE LnkCod=%ld",
FieldName,NewLnkName,
LnkCod);
}
/*****************************************************************************/
/**************** Change the WWW of an institutional link ********************/
/*****************************************************************************/
@ -673,12 +620,7 @@ void Lnk_ChangeLinkWWW (void)
if (NewWWW[0])
{
/***** Update the table changing old WWW by new WWW *****/
DB_QueryUPDATE ("can not update the web of an institutional link",
"UPDATE lnk_links"
" SET WWW='%s'"
" WHERE LnkCod=%ld",
NewWWW,
Lnk_EditingLnk->LnkCod);
Lnk_DB_UpdateLnkWWW (Lnk_EditingLnk->LnkCod,NewWWW);
/***** Message to show the change made *****/
Ale_CreateAlert (Ale_SUCCESS,NULL,
@ -816,11 +758,11 @@ void Lnk_ReceiveFormNewLink (void)
Lnk_EditingLnk->FullName[0]) // If there's a link name
{
/***** If name of link was in database... *****/
if (Lnk_CheckIfLinkNameExists ("ShortName",Lnk_EditingLnk->ShrtName,-1L))
if (Lnk_DB_CheckIfLinkNameExists ("ShortName",Lnk_EditingLnk->ShrtName,-1L))
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_link_X_already_exists,
Lnk_EditingLnk->ShrtName);
else if (Lnk_CheckIfLinkNameExists ("FullName",Lnk_EditingLnk->FullName,-1L))
else if (Lnk_DB_CheckIfLinkNameExists ("FullName",Lnk_EditingLnk->FullName,-1L))
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_link_X_already_exists,
Lnk_EditingLnk->FullName);
@ -829,7 +771,7 @@ void Lnk_ReceiveFormNewLink (void)
Txt_You_must_specify_the_URL_of_the_new_link);
else // Add new link to database
{
Lnk_CreateLink (Lnk_EditingLnk);
Lnk_DB_CreateLink (Lnk_EditingLnk);
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Created_new_link_X,
Lnk_EditingLnk->ShrtName);
@ -840,23 +782,6 @@ void Lnk_ReceiveFormNewLink (void)
Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_link);
}
/*****************************************************************************/
/**************************** Create a new link ******************************/
/*****************************************************************************/
static void Lnk_CreateLink (struct Link *Lnk)
{
/***** Create a new link *****/
DB_QueryINSERT ("can not create institutional link",
"INSERT INTO lnk_links"
" (ShortName,FullName,WWW)"
" VALUES"
" ('%s','%s','%s')",
Lnk->ShrtName,
Lnk->FullName,
Lnk->WWW);
}
/*****************************************************************************/
/************************* Place constructor/destructor **********************/
/*****************************************************************************/

170
swad_link_database.c Normal file
View File

@ -0,0 +1,170 @@
// swad_link_database.c: institutional links, 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 <stddef.h> // For NULL
// #include <stdlib.h> // For calloc
// #include <string.h> // For string functions
// #include "swad_banner.h"
// #include "swad_box.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_link.h"
#include "swad_link_database.h"
// #include "swad_parameter.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
// extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
/*****************************************************************************/
/**************************** Create a new link ******************************/
/*****************************************************************************/
void Lnk_DB_CreateLink (const struct Link *Lnk)
{
DB_QueryINSERT ("can not create institutional link",
"INSERT INTO lnk_links"
" (ShortName,FullName,WWW)"
" VALUES"
" ('%s','%s','%s')",
Lnk->ShrtName,
Lnk->FullName,
Lnk->WWW);
}
/*****************************************************************************/
/************ Update link name in table of institutional links ***************/
/*****************************************************************************/
void Lnk_DB_UpdateLnkName (long LnkCod,const char *FieldName,const char *NewLnkName)
{
DB_QueryUPDATE ("can not update the name of an institutional link",
"UPDATE lnk_links"
" SET %s='%s'"
" WHERE LnkCod=%ld",
FieldName,NewLnkName,
LnkCod);
}
/*****************************************************************************/
/****************** Update link changing old WWW by new WWW ******************/
/*****************************************************************************/
void Lnk_DB_UpdateLnkWWW (long LnkCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1])
{
DB_QueryUPDATE ("can not update the web of an institutional link",
"UPDATE lnk_links"
" SET WWW='%s'"
" WHERE LnkCod=%ld",
NewWWW,
LnkCod);
}
/*****************************************************************************/
/************************** Get institutional links **************************/
/*****************************************************************************/
unsigned Lnk_DB_GetLinks (MYSQL_RES **mysql_res)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get institutional links",
"SELECT LnkCod," // row[0]
"ShortName," // row[1]
"FullName," // row[2]
"WWW" // row[3]
" FROM lnk_links"
" ORDER BY ShortName");
}
/*****************************************************************************/
/**************************** Get link full name *****************************/
/*****************************************************************************/
unsigned Lnk_DB_GetDataOfLinkByCod (MYSQL_RES **mysql_res,long LnkCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get data of an institutional link",
"SELECT ShortName," // row[0]
"FullName," // row[1]
"WWW" // row[2]
" FROM lnk_links"
" WHERE LnkCod=%ld",
LnkCod);
}
/*****************************************************************************/
/********************** Check if the name of link exists *********************/
/*****************************************************************************/
bool Lnk_DB_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod)
{
return (DB_QueryCOUNT ("can not check if the name of an institutional link"
" already existed",
"SELECT COUNT(*)"
" FROM lnk_links"
" WHERE %s='%s'"
" AND LnkCod<>%ld",
FieldName,Name,
LnkCod) != 0);
}
/*****************************************************************************/
/******************************* Remove a link *******************************/
/*****************************************************************************/
void Lnk_DB_RemoveLink (long LnkCod)
{
DB_QueryDELETE ("can not remove an institutional link",
"DELETE FROM lnk_links"
" WHERE LnkCod=%ld",
LnkCod);
}

52
swad_link_database.h Normal file
View File

@ -0,0 +1,52 @@
// swad_link_database.h: institutional links, operations with database
#ifndef _SWAD_LNK_DB
#define _SWAD_LNK_DB
/*
SWAD (Shared Workspace At a Distance in Spanish),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
Copyright (C) 1999-2021 Antonio Cañas Vargas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
#include <mysql/mysql.h> // To access MySQL databases
#include "swad_link.h"
/*****************************************************************************/
/************************** Public types and constants ***********************/
/*****************************************************************************/
/*****************************************************************************/
/****************************** Public prototypes ****************************/
/*****************************************************************************/
void Lnk_DB_CreateLink (const struct Link *Lnk);
void Lnk_DB_UpdateLnkName (long LnkCod,const char *FieldName,const char *NewLnkName);
void Lnk_DB_UpdateLnkWWW (long LnkCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]);
unsigned Lnk_DB_GetLinks (MYSQL_RES **mysql_res);
unsigned Lnk_DB_GetDataOfLinkByCod (MYSQL_RES **mysql_res,long LnkCod);
bool Lnk_DB_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod);
void Lnk_DB_RemoveLink (long LnkCod);
#endif

View File

@ -313,6 +313,22 @@ void Set_ChangeSideCols (void)
Set_SetSettingsFromIP ();
}
/*****************************************************************************/
/**************** Update my language to the current language *****************/
/*****************************************************************************/
void Set_DB_UpdateMySettingsAboutLanguage (void)
{
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
DB_QueryUPDATE ("can not update your language",
"UPDATE usr_data"
" SET Language='%s'"
" WHERE UsrCod=%ld",
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/************** Update layout of side colums on user data table **************/
/*****************************************************************************/

View File

@ -50,6 +50,7 @@ void Set_RemoveOldSettingsFromIP (void);
void Set_ChangeSideCols (void);
unsigned Set_GetParamSideCols (void);
void Set_DB_UpdateMySettingsAboutLanguage (void);
void Set_DB_UpdateMySettingsAboutDateFormat (Dat_Format_t DateFormat);
void Set_DB_ChangeFirstDayOfWeek (unsigned FirstDayOfWeek);
void Set_DB_ChangeIconSet (const char *IconSetId);