2014-12-01 23:55:08 +01:00
|
|
|
|
// swad_mark.c: marks
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
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.
|
2021-02-09 12:43:45 +01:00
|
|
|
|
Copyright (C) 1999-2021 Antonio Ca<EFBFBD>as Vargas
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General Public License as
|
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************************** Headers **********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2018-10-18 02:02:32 +02:00
|
|
|
|
#define _GNU_SOURCE // For asprintf
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include <linux/limits.h> // For PATH_MAX
|
|
|
|
|
#include <malloc.h> // For malloc
|
2019-12-29 12:39:00 +01:00
|
|
|
|
#include <stddef.h> // For NULL
|
2018-10-18 02:02:32 +02:00
|
|
|
|
#include <stdio.h> // For asprintf
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include <string.h> // For string functions
|
|
|
|
|
#include <unistd.h> // For unlink
|
|
|
|
|
|
|
|
|
|
#include "swad_database.h"
|
2021-11-03 11:35:21 +01:00
|
|
|
|
#include "swad_enrolment_database.h"
|
2021-04-26 15:27:27 +02:00
|
|
|
|
#include "swad_error.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"
|
2021-06-17 19:39:08 +02:00
|
|
|
|
#include "swad_group_database.h"
|
2021-05-27 23:30:16 +02:00
|
|
|
|
#include "swad_hierarchy_level.h"
|
2019-10-23 19:05:05 +02:00
|
|
|
|
#include "swad_HTML.h"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include "swad_ID.h"
|
|
|
|
|
#include "swad_mark.h"
|
2021-09-24 00:37:11 +02:00
|
|
|
|
#include "swad_mark_database.h"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include "swad_notification.h"
|
|
|
|
|
#include "swad_parameter.h"
|
|
|
|
|
#include "swad_string.h"
|
|
|
|
|
#include "swad_user.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** External global variables from others modules ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2019-11-21 16:47:07 +01:00
|
|
|
|
/***************************** Private constants *****************************/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-09-24 00:37:11 +02:00
|
|
|
|
static const char *Mrk_HeadOrFootStr[2] = // Names of fields in forms
|
2019-11-21 16:47:07 +01:00
|
|
|
|
{
|
|
|
|
|
"Header",
|
|
|
|
|
"Footer",
|
|
|
|
|
};
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2015-02-27 13:12:57 +01:00
|
|
|
|
#define Mrk_MAX_BYTES_IN_CELL_CONTENT 1024 // Cell of a table containing one or several user's IDs
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
2019-11-21 16:47:07 +01:00
|
|
|
|
/**************************** Private prototypes *****************************/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-09-24 00:37:11 +02:00
|
|
|
|
static void Mrk_GetNumRowsHeaderAndFooter (struct Mrk_Properties *Marks);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
static void Mrk_ChangeNumRowsHeaderOrFooter (Brw_HeadOrFoot_t HeaderOrFooter);
|
2015-02-27 13:12:57 +01:00
|
|
|
|
static bool Mrk_CheckIfCellContainsOnlyIDs (const char *CellContent);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
static bool Mrk_GetUsrMarks (FILE *FileUsrMarks,struct UsrData *UsrDat,
|
|
|
|
|
const char *PathFileAllMarks,
|
2021-09-24 00:37:11 +02:00
|
|
|
|
struct Mrk_Properties *Marks);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********* Write number of header and footer rows of a file of marks *********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2019-04-25 14:39:51 +02:00
|
|
|
|
void Mrk_GetAndWriteNumRowsHeaderAndFooter (void)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2019-02-22 21:47:50 +01:00
|
|
|
|
extern const char *The_ClassFormInBoxNoWrap[The_NUM_THEMES];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
extern const char *Txt_TABLE_Header;
|
|
|
|
|
extern const char *Txt_TABLE_Footer;
|
2021-09-24 00:37:11 +02:00
|
|
|
|
struct Mrk_Properties Marks;
|
2019-11-08 01:10:32 +01:00
|
|
|
|
char StrHeadOrFoot[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2019-04-25 14:39:51 +02:00
|
|
|
|
if (Gbl.FileBrowser.FilFolLnk.Type == Brw_IS_FOLDER)
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_ColouredEmpty (2);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
else // File or link
|
|
|
|
|
{
|
|
|
|
|
/***** Get number of rows in header or footer *****/
|
|
|
|
|
Mrk_GetNumRowsHeaderAndFooter (&Marks);
|
|
|
|
|
|
|
|
|
|
/***** Write the number of rows of header *****/
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"%s RT COLOR%u\"",
|
2019-10-10 23:14:13 +02:00
|
|
|
|
The_ClassFormInBoxNoWrap[Gbl.Prefs.Theme],
|
|
|
|
|
Gbl.RowEvenOdd);
|
2021-07-08 15:00:17 +02:00
|
|
|
|
Frm_BeginForm (Gbl.Crs.Grps.GrpCod > 0 ? ActChgNumRowHeaGrp : // Group zone
|
|
|
|
|
ActChgNumRowHeaCrs); // Course zone
|
|
|
|
|
Brw_PutImplicitParamsFileBrowser (&Gbl.FileBrowser.FilFolLnk);
|
|
|
|
|
HTM_LABEL_Begin (NULL);
|
|
|
|
|
HTM_TxtF (" %s: ",Txt_TABLE_Header);
|
|
|
|
|
snprintf (StrHeadOrFoot,sizeof (StrHeadOrFoot),"%u",Marks.Header);
|
|
|
|
|
HTM_INPUT_TEXT (Mrk_HeadOrFootStr[Brw_HEADER],Cns_MAX_DECIMAL_DIGITS_UINT,StrHeadOrFoot,
|
|
|
|
|
HTM_SUBMIT_ON_CHANGE,
|
|
|
|
|
"size=\"1\" class=\"LST_EDIT_ROWS COLOR%u\"",
|
|
|
|
|
Gbl.RowEvenOdd);
|
|
|
|
|
HTM_LABEL_End ();
|
|
|
|
|
Frm_EndForm ();
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Write the number of rows of footer *****/
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"%s RT COLOR%u\"",
|
2019-10-10 23:14:13 +02:00
|
|
|
|
The_ClassFormInBoxNoWrap[Gbl.Prefs.Theme],
|
|
|
|
|
Gbl.RowEvenOdd);
|
2021-07-08 15:00:17 +02:00
|
|
|
|
Frm_BeginForm (Gbl.Crs.Grps.GrpCod > 0 ? ActChgNumRowFooGrp : // Group zone
|
|
|
|
|
ActChgNumRowFooCrs); // Course zone
|
|
|
|
|
Brw_PutImplicitParamsFileBrowser (&Gbl.FileBrowser.FilFolLnk);
|
|
|
|
|
HTM_LABEL_Begin (NULL);
|
|
|
|
|
HTM_TxtF (" %s: ",Txt_TABLE_Footer);
|
|
|
|
|
snprintf (StrHeadOrFoot,sizeof (StrHeadOrFoot),"%u",Marks.Footer);
|
|
|
|
|
HTM_INPUT_TEXT (Mrk_HeadOrFootStr[Brw_FOOTER],Cns_MAX_DECIMAL_DIGITS_UINT,StrHeadOrFoot,
|
|
|
|
|
HTM_SUBMIT_ON_CHANGE,
|
|
|
|
|
"size=\"1\" class=\"LST_EDIT_ROWS COLOR%u\"",
|
|
|
|
|
Gbl.RowEvenOdd);
|
|
|
|
|
HTM_LABEL_End ();
|
|
|
|
|
Frm_EndForm ();
|
2019-10-23 19:05:05 +02:00
|
|
|
|
HTM_TD_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******** Get number of rows of header and of footer of a file of marks ******/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-09-24 00:37:11 +02:00
|
|
|
|
static void Mrk_GetNumRowsHeaderAndFooter (struct Mrk_Properties *Marks)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
|
|
|
|
|
/***** Get number of rows of header and footer from database *****/
|
2017-11-13 00:09:57 +01:00
|
|
|
|
/* 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. */
|
2021-09-24 00:37:11 +02:00
|
|
|
|
if (Mrk_DB_GetNumRowsHeaderAndFooter (&mysql_res) == 1)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
/***** Get number of header and footer rows *****/
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
|
|
|
|
|
|
|
|
|
/* Header (row[0]) */
|
|
|
|
|
if (sscanf (row[0],"%u",&(Marks->Header)) != 1)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongNumberOfRowsExit ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Footer (row[1]) */
|
|
|
|
|
if (sscanf (row[1],"%u",&(Marks->Footer)) != 1)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongNumberOfRowsExit ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
2017-11-13 00:09:57 +01:00
|
|
|
|
else // Unknown numbers of header and footer rows
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Marks->Header =
|
|
|
|
|
Marks->Footer = 0;
|
|
|
|
|
|
|
|
|
|
/***** Free structure that stores the query result *****/
|
|
|
|
|
DB_FreeMySQLResult (&mysql_res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********* Change the number of rows of header of a file of marks ************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Mrk_ChangeNumRowsHeader (void)
|
|
|
|
|
{
|
|
|
|
|
Mrk_ChangeNumRowsHeaderOrFooter (Brw_HEADER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********** Change the number of rows of footer of a file of marks ***********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Mrk_ChangeNumRowsFooter (void)
|
|
|
|
|
{
|
|
|
|
|
Mrk_ChangeNumRowsHeaderOrFooter (Brw_FOOTER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***** Change the number of rows of header or footer of a file of marks ******/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Mrk_ChangeNumRowsHeaderOrFooter (Brw_HeadOrFoot_t HeaderOrFooter)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_The_number_of_rows_is_now_X;
|
2019-11-08 01:10:32 +01:00
|
|
|
|
char UnsignedStr[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
unsigned NumRows;
|
|
|
|
|
|
|
|
|
|
/***** Get parameters related to file browser *****/
|
|
|
|
|
Brw_GetParAndInitFileBrowser ();
|
|
|
|
|
|
|
|
|
|
/***** Get the number of rows of the header or footer of the table of marks *****/
|
2019-11-08 01:10:32 +01:00
|
|
|
|
Par_GetParToText (Mrk_HeadOrFootStr[HeaderOrFooter],UnsignedStr,Cns_MAX_DECIMAL_DIGITS_UINT);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
if (sscanf (UnsignedStr,"%u",&NumRows) == 1)
|
|
|
|
|
{
|
|
|
|
|
/***** Update properties of marks in the database *****/
|
2021-09-24 00:37:11 +02:00
|
|
|
|
Mrk_DB_ChangeNumRowsHeaderOrFooter (HeaderOrFooter,NumRows);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Write message of success *****/
|
2019-02-16 17:20:05 +01:00
|
|
|
|
Ale_ShowAlert (Ale_SUCCESS,Txt_The_number_of_rows_is_now_X,
|
|
|
|
|
NumRows);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongNumberOfRowsExit ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Show again the file browser *****/
|
|
|
|
|
Brw_ShowAgainFileBrowserOrWorks ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************ Receive a new file of marks ************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// Returns true if the format of the HTML file of marks is correct
|
|
|
|
|
// Returns true if the format of the HTML file of marks is wrong
|
2017-05-10 10:25:01 +02:00
|
|
|
|
// Gbl.Alert.Txt will contain feedback text
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2021-09-24 00:37:11 +02:00
|
|
|
|
bool Mrk_CheckFileOfMarks (const char *Path,struct Mrk_Properties *Marks)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
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;
|
2017-01-28 15:58:46 +01:00
|
|
|
|
char CellContent[Mrk_MAX_BYTES_IN_CELL_CONTENT + 1];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
FILE *FileAllMarks;
|
2015-02-27 13:12:57 +01:00
|
|
|
|
bool EndOfHead = false;
|
|
|
|
|
bool EndOfTable = false;
|
|
|
|
|
bool FileIsCorrect = true;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
unsigned NumRowsStds = 0;
|
|
|
|
|
|
|
|
|
|
Marks->Header = Marks->Footer = 0;
|
|
|
|
|
|
|
|
|
|
/***** Open file with the table of marks *****/
|
|
|
|
|
if ((FileAllMarks = fopen (Path,"rb")))
|
|
|
|
|
{
|
|
|
|
|
/***** Check if there is a table in the received file ******/
|
|
|
|
|
if (Str_FindStrInFile (FileAllMarks,"<table",Str_NO_SKIP_HTML_COMMENTS))
|
|
|
|
|
{
|
|
|
|
|
// There is a table
|
|
|
|
|
Str_FindStrInFile (FileAllMarks,">",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
|
|
|
|
|
// Only one table is allowed
|
|
|
|
|
if (Str_FindStrInFile (FileAllMarks,"<table",Str_NO_SKIP_HTML_COMMENTS))
|
|
|
|
|
{
|
2019-03-09 20:12:44 +01:00
|
|
|
|
Ale_CreateAlert (Ale_WARNING,NULL,
|
|
|
|
|
Txt_There_are_more_than_one_table_in_the_file_of_marks);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
FileIsCorrect = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Return to table start */
|
|
|
|
|
rewind (FileAllMarks);
|
|
|
|
|
Str_FindStrInFile (FileAllMarks,"<table",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
Str_FindStrInFile (FileAllMarks,">",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
|
|
|
|
|
/* We assume that the structure of the table has several rows of header until the first row of students is found,
|
|
|
|
|
then it has a number of rows of students, including some dummy rows without students,
|
|
|
|
|
and finally it has several rows of footer from the last row of students until the end of the table */
|
2015-02-27 13:12:57 +01:00
|
|
|
|
|
|
|
|
|
/***** Count rows of header *****/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
while (!EndOfHead)
|
|
|
|
|
if (Str_FindStrInFile (FileAllMarks,"<tr",Str_NO_SKIP_HTML_COMMENTS)) // Go to the next row
|
|
|
|
|
{
|
2015-02-27 13:12:57 +01:00
|
|
|
|
// All user's IDs must be in the first column of the row
|
|
|
|
|
Str_GetCellFromHTMLTableSkipComments (FileAllMarks,CellContent,Mrk_MAX_BYTES_IN_CELL_CONTENT);
|
|
|
|
|
|
|
|
|
|
/* Check if only user's IDs
|
|
|
|
|
or other stuff found in this table cell */
|
|
|
|
|
if (Mrk_CheckIfCellContainsOnlyIDs (CellContent))
|
|
|
|
|
{
|
|
|
|
|
// Only user's IDs found in this cell
|
|
|
|
|
EndOfHead = true;
|
|
|
|
|
NumRowsStds++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
// Other stuff found ==> continue in header
|
|
|
|
|
Marks->Header++;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
EndOfHead = true; // No more rows
|
|
|
|
|
|
2015-02-27 13:12:57 +01:00
|
|
|
|
/***** Count rows of students and rows of footer *****/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
while (!EndOfTable)
|
|
|
|
|
if (Str_FindStrInFile (FileAllMarks,"<tr",Str_NO_SKIP_HTML_COMMENTS)) // Go to the next row
|
|
|
|
|
{
|
2015-02-27 13:12:57 +01:00
|
|
|
|
// All user's IDs must be in the first column of the row
|
|
|
|
|
Str_GetCellFromHTMLTableSkipComments (FileAllMarks,CellContent,Mrk_MAX_BYTES_IN_CELL_CONTENT);
|
|
|
|
|
|
|
|
|
|
/* Check if only user's IDs
|
|
|
|
|
or other stuff found in this table cell */
|
|
|
|
|
if (Mrk_CheckIfCellContainsOnlyIDs (CellContent))
|
|
|
|
|
{
|
|
|
|
|
// Only user's IDs found in this cell
|
2014-12-01 23:55:08 +01:00
|
|
|
|
NumRowsStds++;
|
|
|
|
|
Marks->Footer = 0;
|
2015-02-27 13:12:57 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
// Other stuff found ==> continue in header
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Marks->Footer++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
EndOfTable = true; // No more rows
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-09 20:12:44 +01:00
|
|
|
|
Ale_CreateAlert (Ale_WARNING,NULL,
|
|
|
|
|
Txt_Table_not_found_in_the_file_of_marks);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
FileIsCorrect = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** The file of marks is no more necessary. Close it. *****/
|
|
|
|
|
fclose (FileAllMarks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FileIsCorrect;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 13:12:57 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******* Check if only user's IDs or other stuff found in a table cell *******/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static bool Mrk_CheckIfCellContainsOnlyIDs (const char *CellContent)
|
|
|
|
|
{
|
2017-03-07 01:56:41 +01:00
|
|
|
|
char UsrIDFromTable[ID_MAX_BYTES_USR_ID + 1];
|
2015-02-27 13:12:57 +01:00
|
|
|
|
const char *Ptr = CellContent;
|
|
|
|
|
bool UsrIDFound = false;
|
|
|
|
|
bool StuffNotUsrIDFound = false;
|
|
|
|
|
|
|
|
|
|
/***** Get strings in this table cell
|
|
|
|
|
and check if they look like user's IDs or not *****/
|
|
|
|
|
while (*Ptr && !StuffNotUsrIDFound)
|
|
|
|
|
{
|
|
|
|
|
/* Find next string in text until space, comma or semicolon (leading and trailing spaces are removed) */
|
2017-03-07 01:56:41 +01:00
|
|
|
|
Str_GetNextStringUntilSeparator (&Ptr,UsrIDFromTable,ID_MAX_BYTES_USR_ID);
|
2015-02-27 13:12:57 +01:00
|
|
|
|
|
|
|
|
|
// Users' IDs are always stored internally in capitals and without leading zeros
|
|
|
|
|
Str_RemoveLeadingZeros (UsrIDFromTable);
|
|
|
|
|
Str_ConvertToUpperText (UsrIDFromTable);
|
2015-03-20 14:30:28 +01:00
|
|
|
|
if (UsrIDFromTable[0]) // Something found
|
|
|
|
|
{
|
|
|
|
|
if (ID_CheckIfUsrIDIsValid (UsrIDFromTable))
|
|
|
|
|
UsrIDFound = true;
|
|
|
|
|
else
|
|
|
|
|
StuffNotUsrIDFound = true;
|
|
|
|
|
}
|
2015-02-27 13:12:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Check if only user's IDs
|
|
|
|
|
or other stuff found in this table cell *****/
|
|
|
|
|
return (UsrIDFound && !StuffNotUsrIDFound);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************************** Show the marks of a user ************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static bool Mrk_GetUsrMarks (FILE *FileUsrMarks,struct UsrData *UsrDat,
|
|
|
|
|
const char *PathFileAllMarks,
|
2021-09-24 00:37:11 +02:00
|
|
|
|
struct Mrk_Properties *Marks)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_THE_USER_X_is_not_found_in_the_file_of_marks;
|
|
|
|
|
unsigned Row;
|
2017-01-28 15:58:46 +01:00
|
|
|
|
char CellContent[Mrk_MAX_BYTES_IN_CELL_CONTENT + 1];
|
2015-02-27 13:12:57 +01:00
|
|
|
|
const char *Ptr;
|
2017-03-07 01:56:41 +01:00
|
|
|
|
char UsrIDFromTable[ID_MAX_BYTES_USR_ID + 1];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
FILE *FileAllMarks;
|
|
|
|
|
unsigned NumID;
|
2015-02-27 13:12:57 +01:00
|
|
|
|
bool UsrIDFound;
|
|
|
|
|
bool EndOfTable;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2015-02-27 13:12:57 +01:00
|
|
|
|
/***** Open HTML file with the table of marks *****/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
if (!(FileAllMarks = fopen (PathFileAllMarks,"rb")))
|
|
|
|
|
{ // Can't open the file with the table of marks
|
2019-03-09 20:12:44 +01:00
|
|
|
|
Ale_CreateAlert (Ale_ERROR,NULL,
|
|
|
|
|
"Can not open file of marks.");
|
2014-12-01 23:55:08 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Check if it exists a user's ID in the first column of the table of marks *****/
|
|
|
|
|
/* Jump to table start */
|
|
|
|
|
Str_FindStrInFile (FileAllMarks,"<table",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
Str_FindStrInFile (FileAllMarks,">",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
|
|
|
|
|
/* Skip header */
|
|
|
|
|
for (Row = 1;
|
|
|
|
|
Row <= Marks->Header;
|
|
|
|
|
Row++)
|
|
|
|
|
Str_FindStrInFile (FileAllMarks,"<tr",Str_NO_SKIP_HTML_COMMENTS); // Go to the next row
|
|
|
|
|
|
|
|
|
|
/* Get user's IDs from table row by row until footer */
|
|
|
|
|
UsrIDFound = EndOfTable = false;
|
|
|
|
|
while (!UsrIDFound && !EndOfTable)
|
|
|
|
|
if (Str_FindStrInFile (FileAllMarks,"<tr",Str_NO_SKIP_HTML_COMMENTS)) // Go to the next row
|
|
|
|
|
{
|
2015-02-27 13:12:57 +01:00
|
|
|
|
// All user's IDs must be in the first column of the row
|
|
|
|
|
Str_GetCellFromHTMLTableSkipComments (FileAllMarks,CellContent,Mrk_MAX_BYTES_IN_CELL_CONTENT);
|
|
|
|
|
|
|
|
|
|
/* Get user's IDs */
|
|
|
|
|
Ptr = CellContent;
|
|
|
|
|
while (*Ptr && !UsrIDFound)
|
|
|
|
|
{
|
2020-01-23 17:08:57 +01:00
|
|
|
|
/* Find next string in text until separator (leading and trailing spaces are removed) */
|
2017-03-07 01:56:41 +01:00
|
|
|
|
Str_GetNextStringUntilSeparator (&Ptr,UsrIDFromTable,ID_MAX_BYTES_USR_ID);
|
2015-02-27 13:12:57 +01:00
|
|
|
|
|
|
|
|
|
// Users' IDs are always stored internally in capitals and without leading zeros
|
|
|
|
|
Str_RemoveLeadingZeros (UsrIDFromTable);
|
|
|
|
|
Str_ConvertToUpperText (UsrIDFromTable);
|
2016-06-13 20:15:31 +02:00
|
|
|
|
|
2015-02-27 13:12:57 +01:00
|
|
|
|
if (ID_CheckIfUsrIDIsValid (UsrIDFromTable))
|
|
|
|
|
// A valid user's ID is found in the first column of table, and stored in UsrIDFromTable.
|
2021-10-30 13:28:48 +02:00
|
|
|
|
// Compare UsrIDFromTable with all confirmed user's IDs in list
|
2015-02-27 13:12:57 +01:00
|
|
|
|
for (NumID = 0;
|
|
|
|
|
NumID < UsrDat->IDs.Num && !UsrIDFound;
|
|
|
|
|
NumID++)
|
|
|
|
|
if (UsrDat->IDs.List[NumID].Confirmed)
|
|
|
|
|
if (!strcasecmp (UsrDat->IDs.List[NumID].ID,UsrIDFromTable))
|
|
|
|
|
UsrIDFound = true;
|
|
|
|
|
}
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
EndOfTable = true; // No more rows
|
|
|
|
|
|
|
|
|
|
if (UsrIDFound)
|
|
|
|
|
{
|
|
|
|
|
/***** Write all until the header (included) *****/
|
|
|
|
|
/* Go to start of file */
|
|
|
|
|
rewind (FileAllMarks);
|
|
|
|
|
|
|
|
|
|
/* Write until table start */
|
|
|
|
|
Str_WriteUntilStrFoundInFileIncludingStr (FileUsrMarks,FileAllMarks,"<table",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
Str_WriteUntilStrFoundInFileIncludingStr (FileUsrMarks,FileAllMarks,">",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
|
|
|
|
|
/* Write header */
|
|
|
|
|
for (Row = 1;
|
|
|
|
|
Row <= Marks->Header;
|
|
|
|
|
Row++)
|
|
|
|
|
Str_WriteUntilStrFoundInFileIncludingStr (FileUsrMarks,FileAllMarks,"</tr>",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
|
|
|
|
|
/****** Write the row corresponding to the student *****/
|
|
|
|
|
/* Find user's ID */
|
|
|
|
|
UsrIDFound = EndOfTable = false;
|
|
|
|
|
while (!UsrIDFound && !EndOfTable)
|
|
|
|
|
if (Str_FindStrInFile (FileAllMarks,"<tr",Str_NO_SKIP_HTML_COMMENTS)) // Go to the next row
|
|
|
|
|
{
|
2015-02-27 13:12:57 +01:00
|
|
|
|
// All user's IDs must be in the first column of the row
|
|
|
|
|
Str_GetCellFromHTMLTableSkipComments (FileAllMarks,CellContent,Mrk_MAX_BYTES_IN_CELL_CONTENT);
|
|
|
|
|
|
|
|
|
|
/* Get user's IDs */
|
|
|
|
|
Ptr = CellContent;
|
|
|
|
|
while (*Ptr && !UsrIDFound)
|
|
|
|
|
{
|
|
|
|
|
/* Find next string in text until comma or semicolon (leading and trailing spaces are removed) */
|
2017-03-07 01:56:41 +01:00
|
|
|
|
Str_GetNextStringUntilSeparator (&Ptr,UsrIDFromTable,ID_MAX_BYTES_USR_ID);
|
2015-02-27 13:12:57 +01:00
|
|
|
|
|
|
|
|
|
// Users' IDs are always stored internally in capitals and without leading zeros
|
|
|
|
|
Str_RemoveLeadingZeros (UsrIDFromTable);
|
|
|
|
|
Str_ConvertToUpperText (UsrIDFromTable);
|
|
|
|
|
if (ID_CheckIfUsrIDIsValid (UsrIDFromTable))
|
|
|
|
|
// A valid user's ID is found in the first column of table, and stored in UsrIDFromTable.
|
2021-10-30 13:28:48 +02:00
|
|
|
|
// Compare UsrIDFromTable with all confirmed user's IDs in list
|
2015-02-27 13:12:57 +01:00
|
|
|
|
for (NumID = 0;
|
|
|
|
|
NumID < UsrDat->IDs.Num && !UsrIDFound;
|
|
|
|
|
NumID++)
|
|
|
|
|
if (UsrDat->IDs.List[NumID].Confirmed)
|
|
|
|
|
if (!strcasecmp (UsrDat->IDs.List[NumID].ID,UsrIDFromTable))
|
|
|
|
|
UsrIDFound = true;
|
|
|
|
|
}
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
EndOfTable = true; // No more rows
|
|
|
|
|
|
|
|
|
|
if (UsrIDFound) // This should happen always, because the check was already made
|
|
|
|
|
{
|
|
|
|
|
/* Find backward until "<tr" */
|
|
|
|
|
Str_FindStrInFileBack (FileAllMarks,"<tr",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
|
|
|
|
|
/* Write until "</tr>" */
|
|
|
|
|
Str_WriteUntilStrFoundInFileIncludingStr (FileUsrMarks,FileAllMarks,"</tr>",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
|
|
|
|
|
/***** Write the footer and all until the end *****/
|
|
|
|
|
/* Find the footer of the table */
|
|
|
|
|
Str_FindStrInFile (FileAllMarks,"</table>",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
Str_FindStrInFileBack (FileAllMarks,"</table>",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
|
|
|
|
|
for (Row = 1;
|
|
|
|
|
Row <= Marks->Footer;
|
|
|
|
|
Row++)
|
|
|
|
|
Str_FindStrInFileBack (FileAllMarks,"<tr",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
|
|
|
|
|
/* Write the footer of the table */
|
|
|
|
|
for (Row = 1;
|
|
|
|
|
Row <= Marks->Footer;
|
|
|
|
|
Row++)
|
|
|
|
|
Str_WriteUntilStrFoundInFileIncludingStr (FileUsrMarks,FileAllMarks,"</tr>",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
|
|
|
|
|
/* Write the end */
|
|
|
|
|
Str_FindStrInFile (FileAllMarks,"</table>",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
Str_FindStrInFileBack (FileAllMarks,"</table>",Str_NO_SKIP_HTML_COMMENTS);
|
|
|
|
|
Fil_FastCopyOfOpenFiles (FileAllMarks,FileUsrMarks);
|
|
|
|
|
|
|
|
|
|
/***** The file of marks is no longer needed. Close it. *****/
|
|
|
|
|
fclose (FileAllMarks);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** User's ID not found in table *****/
|
|
|
|
|
fclose (FileAllMarks);
|
2019-03-09 20:12:44 +01:00
|
|
|
|
Ale_CreateAlert (Ale_WARNING,NULL,
|
|
|
|
|
Txt_THE_USER_X_is_not_found_in_the_file_of_marks,
|
|
|
|
|
UsrDat->FullName);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************************** Show the marks of a user ************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Mrk_ShowMyMarks (void)
|
|
|
|
|
{
|
2021-09-24 00:37:11 +02:00
|
|
|
|
struct Mrk_Properties Marks;
|
2017-01-28 15:58:46 +01:00
|
|
|
|
char FileNameUsrMarks[PATH_MAX + 1];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
FILE *FileUsrMarks;
|
2018-10-04 21:57:25 +02:00
|
|
|
|
char PathPrivate[PATH_MAX + 1 +
|
|
|
|
|
PATH_MAX + 1];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
struct UsrData *UsrDat;
|
|
|
|
|
bool UsrIsOK = true;
|
|
|
|
|
|
|
|
|
|
/***** Get parameters related to file browser *****/
|
|
|
|
|
Brw_GetParAndInitFileBrowser ();
|
|
|
|
|
|
|
|
|
|
/***** Get the path of the file of marks *****/
|
2019-04-25 14:39:51 +02:00
|
|
|
|
Brw_SetFullPathInTree ();
|
2021-02-15 16:25:55 +01:00
|
|
|
|
snprintf (PathPrivate,sizeof (PathPrivate),"%s/%s",
|
2018-10-18 02:02:32 +02:00
|
|
|
|
Gbl.FileBrowser.Priv.PathAboveRootFolder,
|
2019-04-25 14:39:51 +02:00
|
|
|
|
Gbl.FileBrowser.FilFolLnk.Full);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Get number of rows of header or footer *****/
|
|
|
|
|
Mrk_GetNumRowsHeaderAndFooter (&Marks);
|
|
|
|
|
|
|
|
|
|
/***** Set the student whose marks will be shown *****/
|
2017-06-04 18:18:54 +02:00
|
|
|
|
if (Gbl.Usrs.Me.Role.Logged == Rol_STD) // If I am logged as student...
|
2016-06-30 18:14:09 +02:00
|
|
|
|
UsrDat = &Gbl.Usrs.Me.UsrDat; // ...use my list of IDs
|
2017-05-22 14:52:11 +02:00
|
|
|
|
else // If I am logged as non-editing teacher, teacher or admin
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
/* Select a random student from the course */
|
2019-04-04 10:45:15 +02:00
|
|
|
|
if (Gbl.Crs.Grps.GrpCod > 0) // Group zone
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2021-06-17 13:26:25 +02:00
|
|
|
|
if (Grp_DB_CountNumUsrsInGrp (Rol_STD,Gbl.Crs.Grps.GrpCod)) // If there are students in this group
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2021-11-03 11:35:21 +01:00
|
|
|
|
Gbl.Usrs.Other.UsrDat.UsrCod = Grp_DB_GetRamdomStdFromGrp (Gbl.Crs.Grps.GrpCod);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
UsrDat = &Gbl.Usrs.Other.UsrDat;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
UsrIsOK = false;
|
|
|
|
|
}
|
2020-01-23 17:08:57 +01:00
|
|
|
|
else // Course zone
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2021-11-03 23:37:01 +01:00
|
|
|
|
if (Enr_GetNumUsrsInCrss (HieLvl_CRS,Gbl.Hierarchy.Crs.CrsCod,
|
2020-01-08 23:49:04 +01:00
|
|
|
|
1 << Rol_STD)) // If there are students in this course
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2021-11-03 11:35:21 +01:00
|
|
|
|
Gbl.Usrs.Other.UsrDat.UsrCod = Enr_DB_GetRamdomStdFromCrs (Gbl.Hierarchy.Crs.CrsCod);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
UsrDat = &Gbl.Usrs.Other.UsrDat;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
UsrIsOK = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (UsrIsOK)
|
|
|
|
|
{
|
|
|
|
|
/***** Get list of user's IDs *****/
|
2021-04-24 15:10:07 +02:00
|
|
|
|
Usr_GetAllUsrDataFromUsrCod (UsrDat,
|
|
|
|
|
Usr_DONT_GET_PREFS,
|
|
|
|
|
Usr_DONT_GET_ROLE_IN_CURRENT_CRS);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Create temporal file to store my marks (in HTML) *****/
|
|
|
|
|
/* If the private directory does not exist, create it */
|
2019-03-20 01:36:36 +01:00
|
|
|
|
Fil_CreateDirIfNotExists (Cfg_PATH_MARK_PRIVATE);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Create a new temporary file *****/
|
2021-02-15 16:25:55 +01:00
|
|
|
|
snprintf (FileNameUsrMarks,sizeof (FileNameUsrMarks),"%s/%s.html",
|
2019-03-20 01:36:36 +01:00
|
|
|
|
Cfg_PATH_MARK_PRIVATE,Gbl.UniqueNameEncrypted);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
if ((FileUsrMarks = fopen (FileNameUsrMarks,"wb")) == NULL)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_ShowErrorAndExit ("Can not open file for my marks.");
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Show my marks *****/
|
|
|
|
|
if (Mrk_GetUsrMarks (FileUsrMarks,UsrDat,PathPrivate,&Marks))
|
|
|
|
|
{
|
|
|
|
|
fclose (FileUsrMarks);
|
|
|
|
|
if ((FileUsrMarks = fopen (FileNameUsrMarks,"rb")) == NULL)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_ShowErrorAndExit ("Can not open file with my marks.");
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2021-07-08 15:00:17 +02:00
|
|
|
|
/* Begin HTML output */
|
2017-05-08 19:15:54 +02:00
|
|
|
|
/* Do not write charset here.
|
|
|
|
|
Instead, delegate to the meta directive
|
|
|
|
|
(example: <meta http-equiv=Content-Type content="text/html; charset=utf-8">)
|
|
|
|
|
that is typically included in the HTML document header. */
|
2019-11-11 00:15:44 +01:00
|
|
|
|
HTM_Txt ("Content-type: text/html\r\n\r\n"); // Two \r\n are necessary
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Gbl.Layout.HTMLStartWritten = true;
|
|
|
|
|
|
|
|
|
|
/* Copy HTML to output file */
|
|
|
|
|
Fil_FastCopyOfOpenFiles (FileUsrMarks,Gbl.F.Out);
|
|
|
|
|
fclose (FileUsrMarks);
|
|
|
|
|
|
2015-11-27 21:24:24 +01:00
|
|
|
|
Gbl.Layout.DivsEndWritten = Gbl.Layout.HTMLEndWritten = true;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
else // Problems in table of marks or user's ID not found
|
|
|
|
|
{
|
|
|
|
|
fclose (FileUsrMarks);
|
2019-03-09 20:12:44 +01:00
|
|
|
|
Ale_ShowAlerts (NULL);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unlink (FileNameUsrMarks); // File with marks is no longer necessary
|
|
|
|
|
}
|
2017-05-29 21:34:43 +02:00
|
|
|
|
else
|
|
|
|
|
/***** Show warning indicating no students found *****/
|
|
|
|
|
Usr_ShowWarningNoUsersFound (Rol_STD);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Put my marks into a notification ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-03-08 14:12:33 +01:00
|
|
|
|
void Mrk_GetNotifMyMarks (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
|
2017-01-13 10:49:56 +01:00
|
|
|
|
char **ContentStr,
|
2017-03-06 13:01:16 +01:00
|
|
|
|
long MrkCod,long UsrCod,bool GetContent)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
struct UsrData UsrDat;
|
2015-01-25 02:07:04 +01:00
|
|
|
|
unsigned UnsignedNum;
|
|
|
|
|
Brw_FileBrowser_t FileBrowser;
|
|
|
|
|
long Cod;
|
2016-01-02 17:07:58 +01:00
|
|
|
|
long InsCod; // Not applicable here
|
|
|
|
|
long CtrCod; // Not applicable here
|
|
|
|
|
long DegCod; // Not applicable here
|
2014-12-01 23:55:08 +01:00
|
|
|
|
long CrsCod;
|
|
|
|
|
long GrpCod;
|
2021-09-24 00:37:11 +02:00
|
|
|
|
struct Mrk_Properties Marks;
|
2017-01-17 03:10:43 +01:00
|
|
|
|
char FullPathInTreeFromDBMarksTable[PATH_MAX + 1];
|
|
|
|
|
char PathUntilFileName[PATH_MAX + 1];
|
|
|
|
|
char FileName[NAME_MAX + 1];
|
2019-12-19 01:42:24 +01:00
|
|
|
|
char PathMarks[PATH_MAX + 1 + Cns_MAX_DECIMAL_DIGITS_LONG + 1 + 3 + 1 + Cns_MAX_DECIMAL_DIGITS_LONG + 1 + PATH_MAX + 1];
|
2017-01-17 03:10:43 +01:00
|
|
|
|
char FileNameUsrMarks[PATH_MAX + 1];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
FILE *FileUsrMarks;
|
2017-01-13 10:49:56 +01:00
|
|
|
|
size_t SizeOfMyMarks;
|
|
|
|
|
size_t Length;
|
|
|
|
|
size_t i;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
char *Ptr;
|
|
|
|
|
|
|
|
|
|
SummaryStr[0] = '\0'; // Return nothing on error
|
|
|
|
|
|
|
|
|
|
/***** Initialize structure with user's data *****/
|
|
|
|
|
Usr_UsrDataConstructor (&UsrDat);
|
|
|
|
|
|
|
|
|
|
/***** Get user's ID from user's code *****/
|
|
|
|
|
UsrDat.UsrCod = UsrCod;
|
|
|
|
|
ID_GetListIDsFromUsrCod (&UsrDat);
|
|
|
|
|
|
2021-09-24 00:37:11 +02:00
|
|
|
|
/***** Get marks data from database *****/
|
|
|
|
|
if (Mrk_DB_GetDataOfMarksByCod (&mysql_res,MrkCod) == 1) // Result should have a unique row
|
2018-10-22 19:15:56 +02:00
|
|
|
|
{
|
|
|
|
|
/***** Get data of this file of marks *****/
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2018-10-22 19:15:56 +02:00
|
|
|
|
/* Get file browser type in database (row[0]) */
|
|
|
|
|
FileBrowser = Brw_UNKNOWN;
|
|
|
|
|
if (sscanf (row[0],"%u",&UnsignedNum) == 1)
|
|
|
|
|
if (UnsignedNum < Brw_NUM_TYPES_FILE_BROWSER)
|
|
|
|
|
FileBrowser = (Brw_FileBrowser_t) UnsignedNum;
|
|
|
|
|
|
|
|
|
|
/* Course/group code (row[1]) */
|
|
|
|
|
Cod = Str_ConvertStrCodToLongCod (row[1]);
|
|
|
|
|
Brw_GetCrsGrpFromFileMetadata (FileBrowser,Cod,
|
|
|
|
|
&InsCod,&CtrCod,&DegCod,&CrsCod,&GrpCod);
|
|
|
|
|
|
|
|
|
|
/* Path (row[2]) */
|
|
|
|
|
Str_Copy (FullPathInTreeFromDBMarksTable,row[2],
|
2021-02-15 16:25:55 +01:00
|
|
|
|
sizeof (FullPathInTreeFromDBMarksTable) - 1);
|
2018-10-22 19:15:56 +02:00
|
|
|
|
Str_SplitFullPathIntoPathAndFileName (FullPathInTreeFromDBMarksTable,
|
|
|
|
|
PathUntilFileName,
|
|
|
|
|
FileName);
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (SummaryStr,FileName,Cns_MAX_BYTES_TEXT);
|
2018-10-22 19:15:56 +02:00
|
|
|
|
|
|
|
|
|
if (GetContent)
|
|
|
|
|
{
|
|
|
|
|
/* Header (row[3]) */
|
|
|
|
|
if (sscanf (row[3],"%u",&(Marks.Header)) != 1)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongNumberOfRowsExit ();
|
2018-10-22 19:15:56 +02:00
|
|
|
|
|
|
|
|
|
/* Footer (row[4]) */
|
|
|
|
|
if (sscanf (row[4],"%u",&(Marks.Footer)) != 1)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongNumberOfRowsExit ();
|
2018-10-22 19:15:56 +02:00
|
|
|
|
|
|
|
|
|
if (UsrDat.IDs.Num)
|
|
|
|
|
{
|
|
|
|
|
if (GrpCod > 0)
|
2021-02-15 16:25:55 +01:00
|
|
|
|
snprintf (PathMarks,sizeof (PathMarks),"%s/%ld/grp/%ld/%s",
|
2019-03-20 01:36:36 +01:00
|
|
|
|
Cfg_PATH_CRS_PRIVATE,CrsCod,GrpCod,
|
2018-10-22 19:15:56 +02:00
|
|
|
|
FullPathInTreeFromDBMarksTable);
|
|
|
|
|
else
|
2021-02-15 16:25:55 +01:00
|
|
|
|
snprintf (PathMarks,sizeof (PathMarks),"%s/%ld/%s",
|
2019-03-20 01:36:36 +01:00
|
|
|
|
Cfg_PATH_CRS_PRIVATE,CrsCod,
|
2018-10-22 19:15:56 +02:00
|
|
|
|
FullPathInTreeFromDBMarksTable);
|
|
|
|
|
|
|
|
|
|
/***** Create temporal file to store my marks (in HTML) *****/
|
|
|
|
|
/* If the private directory does not exist, create it */
|
2019-03-20 01:36:36 +01:00
|
|
|
|
Fil_CreateDirIfNotExists (Cfg_PATH_MARK_PRIVATE);
|
2018-10-22 19:15:56 +02:00
|
|
|
|
|
|
|
|
|
/* Create a new temporary file *****/
|
2021-02-15 16:25:55 +01:00
|
|
|
|
snprintf (FileNameUsrMarks,sizeof (FileNameUsrMarks),"%s/%s.html",
|
2019-03-20 01:36:36 +01:00
|
|
|
|
Cfg_PATH_MARK_PRIVATE,Gbl.UniqueNameEncrypted);
|
2018-10-22 19:15:56 +02:00
|
|
|
|
if ((FileUsrMarks = fopen (FileNameUsrMarks,"wb")))
|
|
|
|
|
{
|
|
|
|
|
/***** Get user's marks *****/
|
|
|
|
|
if (Mrk_GetUsrMarks (FileUsrMarks,&UsrDat,PathMarks,&Marks))
|
|
|
|
|
{
|
|
|
|
|
SizeOfMyMarks = (size_t) ftell (FileUsrMarks);
|
|
|
|
|
fclose (FileUsrMarks);
|
|
|
|
|
|
|
|
|
|
Length = 9 + SizeOfMyMarks + 3;
|
2021-02-15 16:25:55 +01:00
|
|
|
|
if ((*ContentStr = malloc (Length + 1)))
|
2018-10-22 19:15:56 +02:00
|
|
|
|
{
|
|
|
|
|
/* 9 starting chars */
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (*ContentStr,"<![CDATA[",9);
|
2018-10-22 19:15:56 +02:00
|
|
|
|
|
|
|
|
|
/* Content */
|
|
|
|
|
Ptr = (*ContentStr) + 9;
|
|
|
|
|
if ((FileUsrMarks = fopen (FileNameUsrMarks,"rb")))
|
|
|
|
|
{
|
|
|
|
|
for (i = 0;
|
|
|
|
|
i < SizeOfMyMarks;
|
|
|
|
|
i++)
|
|
|
|
|
*Ptr++ = (char) fgetc (FileUsrMarks);
|
|
|
|
|
fclose (FileUsrMarks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 3 ending chars */
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (Ptr,"]]>",3);
|
2018-10-22 19:15:56 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fclose (FileUsrMarks);
|
|
|
|
|
if (asprintf (ContentStr,"<![CDATA[%s]]>",
|
2019-03-09 20:12:44 +01:00
|
|
|
|
Ale_GetTextOfLastAlert ()) < 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NotEnoughMemoryExit ();
|
2019-03-09 20:12:44 +01:00
|
|
|
|
Ale_ResetAllAlerts ();
|
2018-10-22 19:15:56 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (asprintf (ContentStr,"<![CDATA[%s]]>",
|
2019-03-09 20:12:44 +01:00
|
|
|
|
"Can not open file of marks.") < 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NotEnoughMemoryExit ();
|
2018-10-22 19:15:56 +02:00
|
|
|
|
}
|
|
|
|
|
unlink (FileNameUsrMarks); // File with marks is no longer necessary
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (asprintf (ContentStr,"<![CDATA[%s]]>",
|
2019-03-09 20:12:44 +01:00
|
|
|
|
"User's IDs not found!") < 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NotEnoughMemoryExit ();
|
2018-10-22 19:15:56 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Free structure that stores the query result *****/
|
|
|
|
|
DB_FreeMySQLResult (&mysql_res);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Free memory used for user's data *****/
|
|
|
|
|
Usr_UsrDataDestructor (&UsrDat);
|
|
|
|
|
}
|