Version 21.15: Sep 24, 2021 New module swad_mark_database for database queries related to files of marks.

This commit is contained in:
acanas 2021-09-24 00:37:11 +02:00
parent 2216fe7be5
commit b1bc902f24
10 changed files with 226 additions and 89 deletions

View File

@ -62,8 +62,8 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
swad_language.o swad_layout.o swad_link.o swad_link_database.o \
swad_log.o swad_log_database.o swad_logo.o \
swad_MAC.o swad_mail.o swad_mail_database.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_maintenance.o swad_map.o swad_mark.o swad_mark_database.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 swad_MFU.o \
swad_network.o swad_nickname.o swad_notice.o swad_notification.o \
swad_notification_database.o swad_pagination.o swad_parameter.o \

View File

@ -25,6 +25,8 @@
/********************************* Headers ***********************************/
/*****************************************************************************/
#include <stdlib.h> // For free
#include "swad_database.h"
#include "swad_error.h"
#include "swad_ID.h"

View File

@ -57,6 +57,7 @@
#include "swad_ID.h"
#include "swad_logo.h"
#include "swad_mark.h"
#include "swad_mark_database.h"
#include "swad_notification.h"
#include "swad_parameter.h"
#include "swad_photo.h"
@ -6560,7 +6561,7 @@ static bool Brw_PasteTreeIntoFolder (unsigned LevelOrg,
struct stat FileStatus;
struct dirent **FileList;
bool AdminMarks;
struct MarksProperties Marks;
struct Mrk_Properties Marks;
int NumFile;
int NumFiles;
unsigned NumLevls;
@ -7330,7 +7331,7 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType)
bool FileIsValid = true;
long FilCod = -1L; // Code of new file in database
struct FileMetadata FileMetadata;
struct MarksProperties Marks;
struct Mrk_Properties Marks;
char FileNameToShow[NAME_MAX + 1];
bool UploadSucessful = false;

View File

@ -114,6 +114,12 @@ typedef enum
Brw_ICON_EDIT = 2
} Brw_IconViewEdit_t;
typedef enum
{
Brw_HEADER = 0,
Brw_FOOTER = 1,
} Brw_HeadOrFoot_t;
struct FilFolLnk
{
char Full[PATH_MAX + 1]; // Full path = Path/Name

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.14.1 (2021-09-23)"
#define Log_PLATFORM_VERSION "SWAD 21.15 (2021-09-24)"
#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.15: Sep 24, 2021 New module swad_mark_database for database queries related to files of marks. (316792 lines)
Version 21.14.1: Sep 23, 2021 Queries moved to module swad_mail_database. (316687 lines)
Version 21.14: Sep 22, 2021 New module swad_mail_database for database queries related to mail domains. (316594 lines)
Version 21.13: Sep 22, 2021 New module swad_log_database for database queries related to access logs. (316510 lines)

View File

@ -27,6 +27,7 @@
#define _GNU_SOURCE // For asprintf
#include <stdio.h> // For asprintf
#include <stdlib.h> // For free
#include "swad_database.h"
#include "swad_error.h"

View File

@ -42,6 +42,7 @@
#include "swad_HTML.h"
#include "swad_ID.h"
#include "swad_mark.h"
#include "swad_mark_database.h"
#include "swad_notification.h"
#include "swad_parameter.h"
#include "swad_string.h"
@ -57,17 +58,11 @@ extern struct Globals Gbl;
/******************************* Private types *******************************/
/*****************************************************************************/
typedef enum
{
Brw_HEADER = 0,
Brw_FOOTER = 1,
} Brw_HeadOrFoot_t;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
static const char *Mrk_HeadOrFootStr[2] = // Names of columns in database, so don't change!
static const char *Mrk_HeadOrFootStr[2] = // Names of fields in forms
{
"Header",
"Footer",
@ -79,31 +74,12 @@ static const char *Mrk_HeadOrFootStr[2] = // Names of columns in database, so do
/**************************** Private prototypes *****************************/
/*****************************************************************************/
static void Mrk_GetNumRowsHeaderAndFooter (struct MarksProperties *Marks);
static void Mrk_GetNumRowsHeaderAndFooter (struct Mrk_Properties *Marks);
static void Mrk_ChangeNumRowsHeaderOrFooter (Brw_HeadOrFoot_t HeaderOrFooter);
static bool Mrk_CheckIfCellContainsOnlyIDs (const char *CellContent);
static bool Mrk_GetUsrMarks (FILE *FileUsrMarks,struct UsrData *UsrDat,
const char *PathFileAllMarks,
struct MarksProperties *Marks);
/*****************************************************************************/
/****************** Add a new entry of marks into database *******************/
/*****************************************************************************/
void Mrk_DB_AddMarks (long FilCod,struct MarksProperties *Marks)
{
/***** Add file of marks to the database *****/
DB_QueryINSERT ("can not add properties of marks to database",
"INSERT INTO mrk_marks"
" (FilCod,%s,%s)"
" VALUES"
" (%ld,%u,%u)",
Mrk_HeadOrFootStr[Brw_HEADER],
Mrk_HeadOrFootStr[Brw_FOOTER],
FilCod,
Marks->Header,
Marks->Footer);
}
struct Mrk_Properties *Marks);
/*****************************************************************************/
/********* Write number of header and footer rows of a file of marks *********/
@ -114,7 +90,7 @@ void Mrk_GetAndWriteNumRowsHeaderAndFooter (void)
extern const char *The_ClassFormInBoxNoWrap[The_NUM_THEMES];
extern const char *Txt_TABLE_Header;
extern const char *Txt_TABLE_Footer;
struct MarksProperties Marks;
struct Mrk_Properties Marks;
char StrHeadOrFoot[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
if (Gbl.FileBrowser.FilFolLnk.Type == Brw_IS_FOLDER)
@ -166,10 +142,8 @@ void Mrk_GetAndWriteNumRowsHeaderAndFooter (void)
/******** Get number of rows of header and of footer of a file of marks ******/
/*****************************************************************************/
static void Mrk_GetNumRowsHeaderAndFooter (struct MarksProperties *Marks)
static void Mrk_GetNumRowsHeaderAndFooter (struct Mrk_Properties *Marks)
{
extern const Brw_FileBrowser_t Brw_DB_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER];
long Cod = Brw_GetCodForFileBrowser ();
MYSQL_RES *mysql_res;
MYSQL_ROW row;
@ -177,23 +151,7 @@ static void Mrk_GetNumRowsHeaderAndFooter (struct MarksProperties *Marks)
/* There should be a single file in database.
If, due to an error, there is more than one file,
get the number of rows of the more recent file. */
if (DB_QuerySELECT (&mysql_res,"can not get the number of rows"
" in header and footer",
"SELECT mrk_marks.%s," // row[0]
"mrk_marks.%s" // row[1]
" FROM brw_files,"
"mrk_marks"
" WHERE brw_files.FileBrowser=%u"
" AND brw_files.Cod=%ld"
" AND brw_files.Path='%s'"
" AND brw_files.FilCod=mrk_marks.FilCod"
" ORDER BY brw_files.FilCod DESC"
" LIMIT 1", // On duplicate entries, get the more recent
Mrk_HeadOrFootStr[Brw_HEADER],
Mrk_HeadOrFootStr[Brw_FOOTER],
(unsigned) Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Cod,
Gbl.FileBrowser.FilFolLnk.Full) == 1)
if (Mrk_DB_GetNumRowsHeaderAndFooter (&mysql_res) == 1)
{
/***** Get number of header and footer rows *****/
row = mysql_fetch_row (mysql_res);
@ -238,10 +196,8 @@ void Mrk_ChangeNumRowsFooter (void)
static void Mrk_ChangeNumRowsHeaderOrFooter (Brw_HeadOrFoot_t HeaderOrFooter)
{
extern const Brw_FileBrowser_t Brw_DB_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER];
extern const char *Txt_The_number_of_rows_is_now_X;
char UnsignedStr[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
long Cod;
unsigned NumRows;
/***** Get parameters related to file browser *****/
@ -252,19 +208,7 @@ static void Mrk_ChangeNumRowsHeaderOrFooter (Brw_HeadOrFoot_t HeaderOrFooter)
if (sscanf (UnsignedStr,"%u",&NumRows) == 1)
{
/***** Update properties of marks in the database *****/
Cod = Brw_GetCodForFileBrowser ();
DB_QueryUPDATE ("can not update properties of marks",
"UPDATE mrk_marks,"
"brw_files"
" SET mrk_marks.%s=%u"
" WHERE brw_files.FileBrowser=%u"
" AND brw_files.Cod=%ld"
" AND brw_files.Path='%s'"
" AND brw_files.FilCod=mrk_marks.FilCod",
Mrk_HeadOrFootStr[HeaderOrFooter],NumRows,
(unsigned) Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Cod,
Gbl.FileBrowser.FilFolLnk.Full);
Mrk_DB_ChangeNumRowsHeaderOrFooter (HeaderOrFooter,NumRows);
/***** Write message of success *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_The_number_of_rows_is_now_X,
@ -284,7 +228,7 @@ static void Mrk_ChangeNumRowsHeaderOrFooter (Brw_HeadOrFoot_t HeaderOrFooter)
// Returns true if the format of the HTML file of marks is wrong
// Gbl.Alert.Txt will contain feedback text
bool Mrk_CheckFileOfMarks (const char *Path,struct MarksProperties *Marks)
bool Mrk_CheckFileOfMarks (const char *Path,struct Mrk_Properties *Marks)
{
extern const char *Txt_There_are_more_than_one_table_in_the_file_of_marks;
extern const char *Txt_Table_not_found_in_the_file_of_marks;
@ -424,7 +368,7 @@ static bool Mrk_CheckIfCellContainsOnlyIDs (const char *CellContent)
static bool Mrk_GetUsrMarks (FILE *FileUsrMarks,struct UsrData *UsrDat,
const char *PathFileAllMarks,
struct MarksProperties *Marks)
struct Mrk_Properties *Marks)
{
extern const char *Txt_THE_USER_X_is_not_found_in_the_file_of_marks;
unsigned Row;
@ -587,7 +531,7 @@ static bool Mrk_GetUsrMarks (FILE *FileUsrMarks,struct UsrData *UsrDat,
void Mrk_ShowMyMarks (void)
{
struct MarksProperties Marks;
struct Mrk_Properties Marks;
char FileNameUsrMarks[PATH_MAX + 1];
FILE *FileUsrMarks;
char PathPrivate[PATH_MAX + 1 +
@ -706,7 +650,7 @@ void Mrk_GetNotifMyMarks (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
long DegCod; // Not applicable here
long CrsCod;
long GrpCod;
struct MarksProperties Marks;
struct Mrk_Properties Marks;
char FullPathInTreeFromDBMarksTable[PATH_MAX + 1];
char PathUntilFileName[PATH_MAX + 1];
char FileName[NAME_MAX + 1];
@ -727,19 +671,8 @@ void Mrk_GetNotifMyMarks (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
UsrDat.UsrCod = UsrCod;
ID_GetListIDsFromUsrCod (&UsrDat);
/***** Get subject of message from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get the number of rows"
" in header and footer",
"SELECT brw_files.FileBrowser," // row[0]
"brw_files.Cod," // row[1]
"brw_files.Path," // row[2]
"mrk_marks.Header," // row[3]
"mrk_marks.Footer" // row[4]
" FROM brw_files,"
"mrk_marks"
" WHERE brw_files.FilCod=%ld"
" AND brw_files.FilCod=mrk_marks.FilCod",
MrkCod) == 1) // Result should have a unique row
/***** Get marks data from database *****/
if (Mrk_DB_GetDataOfMarksByCod (&mysql_res,MrkCod) == 1) // Result should have a unique row
{
/***** Get data of this file of marks *****/
row = mysql_fetch_row (mysql_res);

View File

@ -35,7 +35,7 @@
/******************************* Public types ********************************/
/*****************************************************************************/
struct MarksProperties
struct Mrk_Properties
{
unsigned Header;
unsigned Footer;
@ -45,12 +45,11 @@ struct MarksProperties
/***************************** Public prototypes *****************************/
/*****************************************************************************/
void Mrk_DB_AddMarks (long FilCod,struct MarksProperties *Marks);
void Mrk_GetAndWriteNumRowsHeaderAndFooter (void);
void Mrk_ChangeNumRowsHeader (void);
void Mrk_ChangeNumRowsFooter (void);
bool Mrk_CheckFileOfMarks (const char *Path,struct MarksProperties *Marks);
bool Mrk_CheckFileOfMarks (const char *Path,struct Mrk_Properties *Marks);
void Mrk_ShowMyMarks (void);
void Mrk_GetNotifMyMarks (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
char **ContentStr,

148
swad_mark_database.c Normal file
View File

@ -0,0 +1,148 @@
// swad_mark_database.c: marks 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_browser.h"
#include "swad_database.h"
#include "swad_global.h"
#include "swad_mark_database.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
static const char *Mrk_DB_HeadOrFootStr[2] = // Names of columns in database, so don't change!
{
"Header",
"Footer",
};
/*****************************************************************************/
/**************************** Private prototypes *****************************/
/*****************************************************************************/
/*****************************************************************************/
/****************** Add a new entry of marks into database *******************/
/*****************************************************************************/
void Mrk_DB_AddMarks (long FilCod,const struct Mrk_Properties *Marks)
{
DB_QueryINSERT ("can not add properties of marks to database",
"INSERT INTO mrk_marks"
" (FilCod,%s,%s)"
" VALUES"
" (%ld,%u,%u)",
Mrk_DB_HeadOrFootStr[Brw_HEADER],
Mrk_DB_HeadOrFootStr[Brw_FOOTER],
FilCod,
Marks->Header,
Marks->Footer);
}
/*****************************************************************************/
/***** Change the number of rows of header or footer of a file of marks ******/
/*****************************************************************************/
void Mrk_DB_ChangeNumRowsHeaderOrFooter (Brw_HeadOrFoot_t HeaderOrFooter,unsigned NumRows)
{
extern const Brw_FileBrowser_t Brw_DB_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER];
DB_QueryUPDATE ("can not update properties of marks",
"UPDATE mrk_marks,"
"brw_files"
" SET mrk_marks.%s=%u"
" WHERE brw_files.FileBrowser=%u"
" AND brw_files.Cod=%ld"
" AND brw_files.Path='%s'"
" AND brw_files.FilCod=mrk_marks.FilCod",
Mrk_DB_HeadOrFootStr[HeaderOrFooter],NumRows,
(unsigned) Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Brw_GetCodForFileBrowser (),
Gbl.FileBrowser.FilFolLnk.Full);
}
/*****************************************************************************/
/*********************** Get marks data from database ************************/
/*****************************************************************************/
unsigned Mrk_DB_GetDataOfMarksByCod (MYSQL_RES **mysql_res,long MrkCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get the number of rows"
" in header and footer",
"SELECT brw_files.FileBrowser," // row[0]
"brw_files.Cod," // row[1]
"brw_files.Path," // row[2]
"mrk_marks.Header," // row[3]
"mrk_marks.Footer" // row[4]
" FROM brw_files,"
"mrk_marks"
" WHERE brw_files.FilCod=%ld"
" AND brw_files.FilCod=mrk_marks.FilCod",
MrkCod);
}
/*****************************************************************************/
/******** Get number of rows of header and of footer of a file of marks ******/
/*****************************************************************************/
unsigned Mrk_DB_GetNumRowsHeaderAndFooter (MYSQL_RES **mysql_res)
{
extern const Brw_FileBrowser_t Brw_DB_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER];
/***** Get number of rows of header and footer from database *****/
/* There should be a single file in database.
If, due to an error, there is more than one file,
get the number of rows of the more recent file. */
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get the number of rows"
" in header and footer",
"SELECT mrk_marks.%s," // row[0]
"mrk_marks.%s" // row[1]
" FROM brw_files,"
"mrk_marks"
" WHERE brw_files.FileBrowser=%u"
" AND brw_files.Cod=%ld"
" AND brw_files.Path='%s'"
" AND brw_files.FilCod=mrk_marks.FilCod"
" ORDER BY brw_files.FilCod DESC"
" LIMIT 1", // On duplicate entries, get the more recent
Mrk_DB_HeadOrFootStr[Brw_HEADER],
Mrk_DB_HeadOrFootStr[Brw_FOOTER],
(unsigned) Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Brw_GetCodForFileBrowser (),
Gbl.FileBrowser.FilFolLnk.Full);
}

46
swad_mark_database.h Normal file
View File

@ -0,0 +1,46 @@
// swad_marks_database.h: marks operations with database
#ifndef _SWAD_MRK_DB
#define _SWAD_MRK_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 "swad_mark.h"
/*****************************************************************************/
/******************************* Public types ********************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Public prototypes *****************************/
/*****************************************************************************/
void Mrk_DB_AddMarks (long FilCod,const struct Mrk_Properties *Marks);
void Mrk_DB_ChangeNumRowsHeaderOrFooter (Brw_HeadOrFoot_t HeaderOrFooter,unsigned NumRows);
unsigned Mrk_DB_GetDataOfMarksByCod (MYSQL_RES **mysql_res,long MrkCod);
unsigned Mrk_DB_GetNumRowsHeaderAndFooter (MYSQL_RES **mysql_res);
#endif