Version 21.11: Sep 22, 2021 New module swad_info_database for database queries related to course information.

This commit is contained in:
acanas 2021-09-22 00:18:08 +02:00
parent 61385a0565
commit babcd3df60
10 changed files with 617 additions and 468 deletions

View File

@ -56,8 +56,9 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
swad_hierarchy_config.o swad_hierarchy_database.o swad_holiday.o \
swad_holiday_database.o swad_HTML.o \
swad_icon.o swad_ID.o swad_ID_database.o swad_indicator.o \
swad_indicator_database.o swad_info.o swad_institution.o \
swad_institution_config.o swad_institution_database.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_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 \

View File

@ -602,16 +602,15 @@ TODO: FIX BUG, URGENT! En las fechas como par
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
*/
#define Log_PLATFORM_VERSION "SWAD 21.10 (2021-09-20)"
#define Log_PLATFORM_VERSION "SWAD 21.11 (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
TODO: Un profesor no puede confirmar DNIs
TODO: Al cambiar un estudiante en una asignatura, dice que el rol ha cambiado de desconocido a estudiante
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)
Version 21.10: Sep 20, 2021 New module swad_indicator_database for database queries related to course indicators. (316112 lines)
Version 21.9.1: Sep 20, 2021 Queries moved to module swad_browser_database. (316023 lines)
Version 21.9: Sep 20, 2021 New module swad_ID_database for database queries related to user's IDs. (316021 lines)

View File

@ -3204,7 +3204,7 @@ static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat,
Grp_RemUsrFromAllGrpsInCrs (UsrDat->UsrCod,Crs->CrsCod);
/***** Remove user's status about reading of course information *****/
Inf_RemoveUsrFromCrsInfoRead (UsrDat->UsrCod,Crs->CrsCod);
Inf_DB_RemoveUsrFromCrsInfoRead (UsrDat->UsrCod,Crs->CrsCod);
/***** Remove important production of this user in course *****/
if (RemoveUsrWorks == Enr_REMOVE_USR_PRODUCTION)

View File

@ -25,25 +25,12 @@
/********************************* Headers ***********************************/
/*****************************************************************************/
// #include <stddef.h> // For NULL
#include <mysql/mysql.h> // To access MySQL databases
// #include "swad_action.h"
// #include "swad_assignment_database.h"
// #include "swad_box.h"
// #include "swad_browser_database.h"
#include "swad_database.h"
// #include "swad_department.h"
#include "swad_error.h"
// #include "swad_form.h"
// #include "swad_forum_database.h"
#include "swad_global.h"
// #include "swad_hierarchy_level.h"
// #include "swad_HTML.h"
#include "swad_indicator.h"
// #include "swad_message.h"
// #include "swad_parameter.h"
// #include "swad_theme.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/

View File

@ -41,6 +41,7 @@
#include "swad_global.h"
#include "swad_HTML.h"
#include "swad_info.h"
#include "swad_info_database.h"
#include "swad_parameter.h"
#include "swad_string.h"
@ -97,16 +98,6 @@ static void (*Inf_FormsForEditionTypes[Inf_NUM_SOURCES])(Inf_Src_t InfoSrc) =
[Inf_URL ] = Inf_FormToSendURL,
};
static const char *Inf_NamesInDBForInfoSrc[Inf_NUM_SOURCES] =
{
[Inf_NONE ] = "none",
[Inf_EDITOR ] = "editor",
[Inf_PLAIN_TEXT] = "plain_text",
[Inf_RICH_TEXT ] = "rich_text",
[Inf_PAGE ] = "page",
[Inf_URL ] = "URL",
};
static const Act_Action_t Inf_ActionsEditInfo[Inf_NUM_TYPES] =
{
[Inf_INTRODUCTION ] = ActEdiCrsInf,
@ -236,18 +227,6 @@ static const Act_Action_t Inf_ActionsRcvRchTxtInfo[Inf_NUM_TYPES] =
[Inf_ASSESSMENT ] = ActRcvRchTxtAss,
};
static const char *Inf_NamesInDBForInfoType[Inf_NUM_TYPES] =
{
[Inf_INTRODUCTION ] = "intro", // TODO: Change this to "introduction"!
[Inf_TEACHING_GUIDE] = "description", // TODO: Change this to "guide"!
[Inf_LECTURES ] = "theory", // TODO: Change this to "lectures"!
[Inf_PRACTICALS ] = "practices", // TODO: Change this to "practicals"!
[Inf_BIBLIOGRAPHY ] = "bibliography",
[Inf_FAQ ] = "FAQ",
[Inf_LINKS ] = "links",
[Inf_ASSESSMENT ] = "assessment",
};
/***** Help *****/
extern const char *Hlp_COURSE_Information_textual_information;
extern const char *Hlp_COURSE_Guide;
@ -273,11 +252,8 @@ static void Inf_PutButtonToEditInfo (void);
static void Inf_PutIconToViewInfo (void *Type);
static void Inf_PutCheckboxForceStdsToReadInfo (bool MustBeRead,bool Disabled);
static void Inf_PutCheckboxConfirmIHaveReadInfo (void);
static bool Inf_CheckIfIHaveReadInfo (void);
static bool Inf_GetMustBeReadFromForm (void);
static bool Inf_GetIfIHaveReadFromForm (void);
static void Inf_SetForceReadIntoDB (bool MustBeRead);
static void Inf_SetIHaveReadIntoDB (bool IHaveRead);
static bool Inf_CheckPage (long CrsCod,Inf_Type_t InfoType);
static bool Inf_CheckAndShowPage (void);
@ -293,7 +269,6 @@ static bool Inf_CheckIfInfoAvailable (struct Syl_Syllabus *Syllabus,
Inf_Src_t InfoSrc);
static void Inf_AsignInfoType (struct Inf_Info *Info,
struct Syl_Syllabus *Syllabus);
static void Inf_SetInfoTxtIntoDB (const char *InfoTxtHTML,const char *InfoTxtMD);
static bool Inf_CheckPlainTxt (long CrsCod,Inf_Type_t InfoType);
static bool Inf_CheckAndShowPlainTxt (void);
@ -488,7 +463,7 @@ static void Inf_PutCheckboxForceStdsToReadInfo (bool MustBeRead,bool Disabled)
static void Inf_PutCheckboxConfirmIHaveReadInfo (void)
{
extern const char *Txt_I_have_read_this_information;
bool IHaveRead = Inf_CheckIfIHaveReadInfo ();
bool IHaveRead = Inf_DB_CheckIfIHaveReadInfo ();
Lay_PutContextualCheckbox (Inf_ActionsIHaveReadInfo[Gbl.Crs.Info.Type],
NULL,
@ -498,24 +473,6 @@ static void Inf_PutCheckboxConfirmIHaveReadInfo (void)
Txt_I_have_read_this_information);
}
/*****************************************************************************/
/******************** Check I have read a course info ************************/
/*****************************************************************************/
static bool Inf_CheckIfIHaveReadInfo (void)
{
/***** Get if info source is already stored in database *****/
return (DB_QueryCOUNT ("can not get if I have read course info",
"SELECT COUNT(*)"
" FROM crs_info_read"
" WHERE UsrCod=%ld"
" AND CrsCod=%ld"
" AND InfoType='%s'",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Hierarchy.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.Crs.Info.Type]) != 0);
}
/*****************************************************************************/
/********* Get if students must read any info about current course ***********/
/*****************************************************************************/
@ -558,7 +515,7 @@ bool Inf_GetIfIMustReadAnyCrsInfoInThisCrs (void)
row = mysql_fetch_row (mysql_res);
/* Get info type (row[0]) */
InfoType = Inf_ConvertFromStrDBToInfoType (row[0]);
InfoType = Inf_DB_ConvertFromStrDBToInfoType (row[0]);
Gbl.Crs.Info.MustBeRead[InfoType] = true;
}
@ -630,7 +587,7 @@ void Inf_ChangeForceReadInfo (void)
Inf_AsignInfoType (&Gbl.Crs.Info,&Syllabus);
/***** Set status (if info must be read or not) into database *****/
Inf_SetForceReadIntoDB (MustBeRead);
Inf_DB_SetForceRead (MustBeRead);
/***** Write message of success *****/
Ale_ShowAlert (Ale_SUCCESS,
@ -659,7 +616,7 @@ void Inf_ChangeIHaveReadInfo (void)
Inf_AsignInfoType (&Gbl.Crs.Info,&Syllabus);
/***** Set status (if I have read or not a information) into database *****/
Inf_SetIHaveReadIntoDB (IHaveRead);
Inf_DB_SetIHaveRead (IHaveRead);
/***** Write message of success *****/
Ale_ShowAlert (Ale_SUCCESS,
@ -688,57 +645,11 @@ static bool Inf_GetIfIHaveReadFromForm (void)
return Par_GetParToBool ("IHaveRead");
}
/*****************************************************************************/
/***************** Set if students must read course info *********************/
/*****************************************************************************/
static void Inf_SetForceReadIntoDB (bool MustBeRead)
{
/***** Insert or replace info source for a specific type of course information *****/
DB_QueryUPDATE ("can not update if info must be read",
"UPDATE crs_info_src"
" SET MustBeRead='%c'"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
MustBeRead ? 'Y' :
'N',
Gbl.Hierarchy.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.Crs.Info.Type]);
}
/*****************************************************************************/
/********************* Set if I have read course info ************************/
/*****************************************************************************/
static void Inf_SetIHaveReadIntoDB (bool IHaveRead)
{
if (IHaveRead)
/***** Insert I have read course information *****/
DB_QueryREPLACE ("can not set that I have read course info",
"REPLACE INTO crs_info_read"
" (UsrCod,CrsCod,InfoType)"
" VALUES"
" (%ld,%ld,'%s')",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Hierarchy.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.Crs.Info.Type]);
else
/***** Remove I have read course information *****/
DB_QueryDELETE ("can not set that I have not read course info",
"DELETE FROM crs_info_read"
" WHERE UsrCod=%ld"
" AND CrsCod=%ld"
" AND InfoType='%s'",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Hierarchy.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.Crs.Info.Type]);
}
/*****************************************************************************/
/********* Remove user's status about reading of course information **********/
/*****************************************************************************/
void Inf_RemoveUsrFromCrsInfoRead (long UsrCod,long CrsCod)
void Inf_DB_RemoveUsrFromCrsInfoRead (long UsrCod,long CrsCod)
{
/***** Remove user's status about reading of course information *****/
DB_QueryDELETE ("can not set that I have not read course info",
@ -993,7 +904,7 @@ void Inf_SetInfoSrc (void)
Inf_AsignInfoType (&Gbl.Crs.Info,&Syllabus);
/***** Set info source into database *****/
Inf_SetInfoSrcIntoDB (InfoSrcSelected);
Inf_DB_SetInfoSrc (InfoSrcSelected);
/***** Show the selected info *****/
Inf_ShowInfo ();
@ -1049,7 +960,7 @@ void Inf_FormsToSelSendInfo (void)
!InfoAvailable[FromDB.Src])
{
FromDB.Src = Inf_NONE;
Inf_SetInfoSrcIntoDB (Inf_NONE);
Inf_DB_SetInfoSrc (Inf_NONE);
}
/***** Form to choice between alternatives *****/
@ -1071,7 +982,6 @@ void Inf_FormsToSelSendInfo (void)
else
HTM_TD_Begin ("class=\"DAT LT\"");
Frm_BeginForm (Inf_ActionsSelecInfoSrc[Gbl.Crs.Info.Type]);
HTM_INPUT_RADIO ("InfoSrc",InfoSrc != FromDB.Src &&
(InfoSrc == Inf_NONE ||
InfoAvailable[InfoSrc]), // Info available for this source
@ -1411,54 +1321,6 @@ Inf_Src_t Inf_GetInfoSrcFromForm (void)
(unsigned long) Inf_NONE);
}
/*****************************************************************************/
/********* Set info source for a type of course info from database ***********/
/*****************************************************************************/
void Inf_SetInfoSrcIntoDB (Inf_Src_t InfoSrc)
{
/***** Get if info source is already stored in database *****/
if (DB_QueryCOUNT ("can not get if info source is already stored in database",
"SELECT COUNT(*)"
" FROM crs_info_src"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
Gbl.Hierarchy.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.Crs.Info.Type]))
// Info is already stored in database, so update it
{ // Update info source
if (InfoSrc == Inf_NONE)
DB_QueryUPDATE ("can not update info source",
"UPDATE crs_info_src"
" SET InfoSrc='%s',"
"MustBeRead='N'"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
Inf_NamesInDBForInfoSrc[Inf_NONE],
Gbl.Hierarchy.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.Crs.Info.Type]);
else // MustBeRead remains unchanged
DB_QueryUPDATE ("can not update info source",
"UPDATE crs_info_src"
" SET InfoSrc='%s'"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
Inf_NamesInDBForInfoSrc[InfoSrc],
Gbl.Hierarchy.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.Crs.Info.Type]);
}
else // Info is not stored in database, so insert it
DB_QueryINSERT ("can not insert info source",
"INSERT INTO crs_info_src"
" (CrsCod,InfoType,InfoSrc,MustBeRead)"
" VALUES"
" (%ld,'%s','%s','N')",
Gbl.Hierarchy.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.Crs.Info.Type],
Inf_NamesInDBForInfoSrc[InfoSrc]);
}
/*****************************************************************************/
/***** Get and check info source for a type of course info from database *****/
/*****************************************************************************/
@ -1470,19 +1332,13 @@ Inf_Src_t Inf_GetInfoSrcFromDB (long CrsCod,Inf_Type_t InfoType)
Inf_Src_t InfoSrc;
/***** Get info source for a specific type of info from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get info source",
"SELECT InfoSrc" // row[0]
" FROM crs_info_src"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
CrsCod,
Inf_NamesInDBForInfoType[InfoType]))
if (Inf_DB_GetInfoSrc (&mysql_res,CrsCod,InfoType))
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get info source (row[0]) */
InfoSrc = Inf_ConvertFromStrDBToInfoSrc (row[0]);
InfoSrc = Inf_DB_ConvertFromStrDBToInfoSrc (row[0]);
}
else
InfoSrc = Inf_NONE;
@ -1499,7 +1355,7 @@ Inf_Src_t Inf_GetInfoSrcFromDB (long CrsCod,Inf_Type_t InfoType)
void Inf_GetAndCheckInfoSrcFromDB (struct Syl_Syllabus *Syllabus,
long CrsCod,
Inf_Type_t Type,
Inf_Type_t InfoType,
struct Inf_FromDB *FromDB)
{
MYSQL_RES *mysql_res;
@ -1510,20 +1366,13 @@ void Inf_GetAndCheckInfoSrcFromDB (struct Syl_Syllabus *Syllabus,
FromDB->MustBeRead = false;
/***** Get info source for a specific type of info from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get info source",
"SELECT InfoSrc," // row[0]
"MustBeRead" // row[1]
" FROM crs_info_src"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
CrsCod,
Inf_NamesInDBForInfoType[Type]) == 1)
if (Inf_DB_GetInfoSrcAndMustBeRead (&mysql_res,CrsCod,InfoType) == 1)
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get info source (row[0]) and if students must read info (row[1]) */
FromDB->Src = Inf_ConvertFromStrDBToInfoSrc (row[0]);
FromDB->Src = Inf_DB_ConvertFromStrDBToInfoSrc (row[0]);
FromDB->MustBeRead = (row[1][0] == 'Y');
}
@ -1536,7 +1385,7 @@ void Inf_GetAndCheckInfoSrcFromDB (struct Syl_Syllabus *Syllabus,
case Inf_NONE:
break;
case Inf_EDITOR:
switch (Type)
switch (InfoType)
{
case Inf_LECTURES:
Syllabus->WhichSyllabus = Syl_LECTURES;
@ -1559,19 +1408,19 @@ void Inf_GetAndCheckInfoSrcFromDB (struct Syl_Syllabus *Syllabus,
}
break;
case Inf_PLAIN_TEXT:
if (!Inf_CheckPlainTxt (CrsCod,Type))
if (!Inf_CheckPlainTxt (CrsCod,InfoType))
FromDB->Src = Inf_NONE;
break;
case Inf_RICH_TEXT:
if (!Inf_CheckRichTxt (CrsCod,Type))
if (!Inf_CheckRichTxt (CrsCod,InfoType))
FromDB->Src = Inf_NONE;
break;
case Inf_PAGE:
if (!Inf_CheckPage (CrsCod,Type))
if (!Inf_CheckPage (CrsCod,InfoType))
FromDB->Src = Inf_NONE;
break;
case Inf_URL:
if (!Inf_CheckURL (CrsCod,Type))
if (!Inf_CheckURL (CrsCod,InfoType))
FromDB->Src = Inf_NONE;
break;
}
@ -1580,58 +1429,6 @@ void Inf_GetAndCheckInfoSrcFromDB (struct Syl_Syllabus *Syllabus,
FromDB->MustBeRead = false;
}
/*****************************************************************************/
/*** Convert a string with info type in database to a Inf_InfoType_t value ***/
/*****************************************************************************/
Inf_Type_t Inf_ConvertFromStrDBToInfoType (const char *StrInfoTypeDB)
{
Inf_Type_t InfoType;
for (InfoType = (Inf_Type_t) 0;
InfoType <= (Inf_Type_t) (Inf_NUM_TYPES - 1);
InfoType++)
if (!strcmp (StrInfoTypeDB,Inf_NamesInDBForInfoType[InfoType]))
return InfoType;
return (Inf_Type_t) 0;
}
/*****************************************************************************/
/** Convert a string with info source in database to a Inf_InfoSrc_t value ***/
/*****************************************************************************/
Inf_Src_t Inf_ConvertFromStrDBToInfoSrc (const char *StrInfoSrcDB)
{
Inf_Src_t InfoSrc;
for (InfoSrc = (Inf_Src_t) 0;
InfoSrc <= (Inf_Src_t) (Inf_NUM_SOURCES - 1);
InfoSrc++)
if (!strcmp (StrInfoSrcDB,Inf_NamesInDBForInfoSrc[InfoSrc]))
return InfoSrc;
return Inf_NONE;
}
/*****************************************************************************/
/********** Set info text for a type of course info from database ************/
/*****************************************************************************/
static void Inf_SetInfoTxtIntoDB (const char *InfoTxtHTML,const char *InfoTxtMD)
{
/***** Insert or replace info source for a specific type of course information *****/
DB_QueryREPLACE ("can not update info text",
"REPLACE INTO crs_info_txt"
" (CrsCod,InfoType,InfoTxtHTML,InfoTxtMD)"
" VALUES"
" (%ld,'%s','%s','%s')",
Gbl.Hierarchy.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.Crs.Info.Type],
InfoTxtHTML,
InfoTxtMD);
}
/*****************************************************************************/
/********** Get info text for a type of course info from database ************/
/*****************************************************************************/
@ -1645,14 +1442,7 @@ void Inf_GetInfoTxtFromDB (long CrsCod,Inf_Type_t InfoType,
/***** Get info source for a specific type of course information
(bibliography, FAQ, links or evaluation) from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get info text",
"SELECT InfoTxtHTML," // row[0]
"InfoTxtMD" // row[1]
" FROM crs_info_txt"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
CrsCod,
Inf_NamesInDBForInfoType[InfoType]) == 1)
if (Inf_DB_GetInfoTxt (&mysql_res,CrsCod,InfoType) == 1)
{
/* Get info text */
row = mysql_fetch_row (mysql_res);
@ -2041,10 +1831,10 @@ void Inf_RecAndChangePlainTxtInfo (void)
Txt_MarkdownFormat,Cns_MAX_BYTES_LONG_TEXT,true); // Store a copy in Markdown format
/***** Update text of course info in database *****/
Inf_SetInfoTxtIntoDB (Txt_HTMLFormat,Txt_MarkdownFormat);
Inf_DB_SetInfoTxt (Txt_HTMLFormat,Txt_MarkdownFormat);
/***** Change info source to "plain text" in database *****/
Inf_SetInfoSrcIntoDB (Txt_HTMLFormat[0] ? Inf_PLAIN_TEXT :
Inf_DB_SetInfoSrc (Txt_HTMLFormat[0] ? Inf_PLAIN_TEXT :
Inf_NONE);
if (Txt_HTMLFormat[0])
/***** Show the updated info *****/
@ -2080,10 +1870,10 @@ void Inf_RecAndChangeRichTxtInfo (void)
Txt_MarkdownFormat,Cns_MAX_BYTES_LONG_TEXT,true); // Store a copy in Markdown format
/***** Update text of course info in database *****/
Inf_SetInfoTxtIntoDB (Txt_HTMLFormat,Txt_MarkdownFormat);
Inf_DB_SetInfoTxt (Txt_HTMLFormat,Txt_MarkdownFormat);
/***** Change info source to "rich text" in database *****/
Inf_SetInfoSrcIntoDB (Txt_HTMLFormat[0] ? Inf_RICH_TEXT :
Inf_DB_SetInfoSrc (Txt_HTMLFormat[0] ? Inf_RICH_TEXT :
Inf_NONE);
if (Txt_HTMLFormat[0])
/***** Show the updated info *****/
@ -2137,7 +1927,7 @@ void Inf_ReceiveURLInfo (void)
if (URLIsOK)
{
/***** Change info source to URL in database *****/
Inf_SetInfoSrcIntoDB (Inf_URL);
Inf_DB_SetInfoSrc (Inf_URL);
/***** Show the updated info *****/
Inf_ShowInfo ();
@ -2145,7 +1935,7 @@ void Inf_ReceiveURLInfo (void)
else
{
/***** Change info source to none in database *****/
Inf_SetInfoSrcIntoDB (Inf_NONE);
Inf_DB_SetInfoSrc (Inf_NONE);
/***** Show again the form to select and send course info *****/
Inf_FormsToSelSendInfo ();
@ -2274,7 +2064,7 @@ void Inf_ReceivePagInfo (void)
if (FileIsOK)
{
/***** Change info source to page in database *****/
Inf_SetInfoSrcIntoDB (Inf_PAGE);
Inf_DB_SetInfoSrc (Inf_PAGE);
/***** Show the updated info *****/
Inf_ShowInfo ();
@ -2282,7 +2072,7 @@ void Inf_ReceivePagInfo (void)
else
{
/***** Change info source to none in database *****/
Inf_SetInfoSrcIntoDB (Inf_NONE);
Inf_DB_SetInfoSrc (Inf_NONE);
/***** Show again the form to select and send course info *****/
Inf_FormsToSelSendInfo ();

View File

@ -1,4 +1,4 @@
// swad_info.c: info about course
// swad_info.h: info about course
#ifndef _SWAD_INF
#define _SWAD_INF
@ -88,7 +88,7 @@ void Inf_WriteMsgYouMustReadInfo (void);
void Inf_ChangeForceReadInfo (void);
void Inf_ChangeIHaveReadInfo (void);
bool Inf_GetIfIMustReadAnyCrsInfoInThisCrs (void);
void Inf_RemoveUsrFromCrsInfoRead (long UsrCod,long CrsCod);
void Inf_DB_RemoveUsrFromCrsInfoRead (long UsrCod,long CrsCod);
void Inf_BuildPathPage (long CrsCod,Inf_Type_t InfoType,char PathDir[PATH_MAX + 1]);
void Inf_WriteURLIntoTxtBuffer (char TxtBuffer[Cns_MAX_BYTES_WWW + 1]);
void Inf_SetInfoSrc (void);
@ -99,14 +99,11 @@ void Inf_FormToEnterRichTextEditor (Inf_Src_t InfoSrc);
void Inf_FormToSendPage (Inf_Src_t InfoSrc);
void Inf_FormToSendURL (Inf_Src_t InfoSrc);
Inf_Src_t Inf_GetInfoSrcFromForm (void);
void Inf_SetInfoSrcIntoDB (Inf_Src_t InfoSrc);
Inf_Src_t Inf_GetInfoSrcFromDB (long CrsCod,Inf_Type_t InfoType);
void Inf_GetAndCheckInfoSrcFromDB (struct Syl_Syllabus *Syllabus,
long CrsCod,
Inf_Type_t Type,
Inf_Type_t InfoType,
struct Inf_FromDB *FromDB);
Inf_Type_t Inf_ConvertFromStrDBToInfoType (const char *StrInfoTypeDB);
Inf_Src_t Inf_ConvertFromStrDBToInfoSrc (const char *StrInfoSrcDB);
void Inf_GetInfoTxtFromDB (long CrsCod,Inf_Type_t InfoType,
char InfoTxtHTML[Cns_MAX_BYTES_LONG_TEXT + 1],

303
swad_info_database.c Normal file
View File

@ -0,0 +1,303 @@
// swad_info_database.c: info about course, 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 <limits.h> // For maximum values
// #include <linux/limits.h> // For PATH_MAX, NAME_MAX
// #include <stddef.h> // For NULL
// #include <stdlib.h> // For getenv, etc
// #include <stdsoap2.h> // For SOAP_OK and soap functions
#include <string.h> // For string functions
// #include <unistd.h> // For unlink
// #include "swad_action.h"
// #include "swad_box.h"
#include "swad_database.h"
// #include "swad_error.h"
// #include "swad_form.h"
#include "swad_global.h"
// #include "swad_HTML.h"
// #include "swad_info.h"
// #include "swad_parameter.h"
// #include "swad_string.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/****************************** Private types ********************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
static const char *Inf_DB_NamesForInfoType[Inf_NUM_TYPES] =
{
[Inf_INTRODUCTION ] = "intro", // TODO: Change this to "introduction"!
[Inf_TEACHING_GUIDE] = "description", // TODO: Change this to "guide"!
[Inf_LECTURES ] = "theory", // TODO: Change this to "lectures"!
[Inf_PRACTICALS ] = "practices", // TODO: Change this to "practicals"!
[Inf_BIBLIOGRAPHY ] = "bibliography",
[Inf_FAQ ] = "FAQ",
[Inf_LINKS ] = "links",
[Inf_ASSESSMENT ] = "assessment",
};
static const char *Inf_DB_NamesForInfoSrc[Inf_NUM_SOURCES] =
{
[Inf_NONE ] = "none",
[Inf_EDITOR ] = "editor",
[Inf_PLAIN_TEXT] = "plain_text",
[Inf_RICH_TEXT ] = "rich_text",
[Inf_PAGE ] = "page",
[Inf_URL ] = "URL",
};
/*****************************************************************************/
/**************************** Private prototypes *****************************/
/*****************************************************************************/
/*****************************************************************************/
/*** Convert a string with info type in database to a Inf_InfoType_t value ***/
/*****************************************************************************/
Inf_Type_t Inf_DB_ConvertFromStrDBToInfoType (const char *StrInfoTypeDB)
{
Inf_Type_t InfoType;
for (InfoType = (Inf_Type_t) 0;
InfoType <= (Inf_Type_t) (Inf_NUM_TYPES - 1);
InfoType++)
if (!strcmp (StrInfoTypeDB,Inf_DB_NamesForInfoType[InfoType]))
return InfoType;
return (Inf_Type_t) 0;
}
/*****************************************************************************/
/********* Set info source for a type of course info from database ***********/
/*****************************************************************************/
void Inf_DB_SetInfoSrc (Inf_Src_t InfoSrc)
{
/***** Get if info source is already stored in database *****/
if (DB_QueryCOUNT ("can not get if info source is already stored in database",
"SELECT COUNT(*)"
" FROM crs_info_src"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
Gbl.Hierarchy.Crs.CrsCod,
Inf_DB_NamesForInfoType[Gbl.Crs.Info.Type]))
// Info is already stored in database, so update it
{ // Update info source
if (InfoSrc == Inf_NONE)
DB_QueryUPDATE ("can not update info source",
"UPDATE crs_info_src"
" SET InfoSrc='%s',"
"MustBeRead='N'"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
Inf_DB_NamesForInfoSrc[Inf_NONE],
Gbl.Hierarchy.Crs.CrsCod,
Inf_DB_NamesForInfoType[Gbl.Crs.Info.Type]);
else // MustBeRead remains unchanged
DB_QueryUPDATE ("can not update info source",
"UPDATE crs_info_src"
" SET InfoSrc='%s'"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
Inf_DB_NamesForInfoSrc[InfoSrc],
Gbl.Hierarchy.Crs.CrsCod,
Inf_DB_NamesForInfoType[Gbl.Crs.Info.Type]);
}
else // Info is not stored in database, so insert it
DB_QueryINSERT ("can not insert info source",
"INSERT INTO crs_info_src"
" (CrsCod,InfoType,InfoSrc,MustBeRead)"
" VALUES"
" (%ld,'%s','%s','N')",
Gbl.Hierarchy.Crs.CrsCod,
Inf_DB_NamesForInfoType[Gbl.Crs.Info.Type],
Inf_DB_NamesForInfoSrc[InfoSrc]);
}
/*****************************************************************************/
/***************** Get info source for a type of course info *****************/
/*****************************************************************************/
unsigned Inf_DB_GetInfoSrc (MYSQL_RES **mysql_res,
long CrsCod,Inf_Type_t InfoType)
{
/***** Get info source for a specific type of info from database *****/
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get info source",
"SELECT InfoSrc" // row[0]
" FROM crs_info_src"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
CrsCod,
Inf_DB_NamesForInfoType[InfoType]);
}
/*****************************************************************************/
/*** Get info source and wether info must be read for a type of course info **/
/*****************************************************************************/
unsigned Inf_DB_GetInfoSrcAndMustBeRead (MYSQL_RES **mysql_res,
long CrsCod,Inf_Type_t InfoType)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get info source",
"SELECT InfoSrc," // row[0]
"MustBeRead" // row[1]
" FROM crs_info_src"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
CrsCod,
Inf_DB_NamesForInfoType[InfoType]);
}
/*****************************************************************************/
/** Convert a string with info source in database to a Inf_InfoSrc_t value ***/
/*****************************************************************************/
Inf_Src_t Inf_DB_ConvertFromStrDBToInfoSrc (const char *StrInfoSrcDB)
{
Inf_Src_t InfoSrc;
for (InfoSrc = (Inf_Src_t) 0;
InfoSrc <= (Inf_Src_t) (Inf_NUM_SOURCES - 1);
InfoSrc++)
if (!strcmp (StrInfoSrcDB,Inf_DB_NamesForInfoSrc[InfoSrc]))
return InfoSrc;
return Inf_NONE;
}
/*****************************************************************************/
/********** Set info text for a type of course info from database ************/
/*****************************************************************************/
void Inf_DB_SetInfoTxt (const char *InfoTxtHTML,const char *InfoTxtMD)
{
/***** Insert or replace info source for a specific type of course information *****/
DB_QueryREPLACE ("can not update info text",
"REPLACE INTO crs_info_txt"
" (CrsCod,InfoType,InfoTxtHTML,InfoTxtMD)"
" VALUES"
" (%ld,'%s','%s','%s')",
Gbl.Hierarchy.Crs.CrsCod,
Inf_DB_NamesForInfoType[Gbl.Crs.Info.Type],
InfoTxtHTML,
InfoTxtMD);
}
/*****************************************************************************/
/********** Get info text for a type of course info from database ************/
/*****************************************************************************/
unsigned Inf_DB_GetInfoTxt (MYSQL_RES **mysql_res,
long CrsCod,Inf_Type_t InfoType)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get info text",
"SELECT InfoTxtHTML," // row[0]
"InfoTxtMD" // row[1]
" FROM crs_info_txt"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
CrsCod,
Inf_DB_NamesForInfoType[InfoType]);
}
/*****************************************************************************/
/***************** Set if students must read course info *********************/
/*****************************************************************************/
void Inf_DB_SetForceRead (bool MustBeRead)
{
DB_QueryUPDATE ("can not update if info must be read",
"UPDATE crs_info_src"
" SET MustBeRead='%c'"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
MustBeRead ? 'Y' :
'N',
Gbl.Hierarchy.Crs.CrsCod,
Inf_DB_NamesForInfoType[Gbl.Crs.Info.Type]);
}
/*****************************************************************************/
/********************* Set if I have read course info ************************/
/*****************************************************************************/
void Inf_DB_SetIHaveRead (bool IHaveRead)
{
if (IHaveRead)
/***** Insert I have read course information *****/
DB_QueryREPLACE ("can not set that I have read course info",
"REPLACE INTO crs_info_read"
" (UsrCod,CrsCod,InfoType)"
" VALUES"
" (%ld,%ld,'%s')",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Hierarchy.Crs.CrsCod,
Inf_DB_NamesForInfoType[Gbl.Crs.Info.Type]);
else
/***** Remove I have read course information *****/
DB_QueryDELETE ("can not set that I have not read course info",
"DELETE FROM crs_info_read"
" WHERE UsrCod=%ld"
" AND CrsCod=%ld"
" AND InfoType='%s'",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Hierarchy.Crs.CrsCod,
Inf_DB_NamesForInfoType[Gbl.Crs.Info.Type]);
}
/*****************************************************************************/
/******************** Check I have read a course info ************************/
/*****************************************************************************/
bool Inf_DB_CheckIfIHaveReadInfo (void)
{
return (DB_QueryCOUNT ("can not get if I have read course info",
"SELECT COUNT(*)"
" FROM crs_info_read"
" WHERE UsrCod=%ld"
" AND CrsCod=%ld"
" AND InfoType='%s'",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Hierarchy.Crs.CrsCod,
Inf_DB_NamesForInfoType[Gbl.Crs.Info.Type]) != 0);
}

71
swad_info_database.h Normal file
View File

@ -0,0 +1,71 @@
// swad_info_database.h: info about course, operations with database
#ifndef _SWAD_INF_DB
#define _SWAD_INF_DB
/*
SWAD (Shared Workspace At a Distance in Spanish),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
Copyright (C) 1999-2021 Antonio Cañas Vargas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
// #include <stdbool.h> // For boolean type
// #include "swad_constant.h"
#include "swad_info.h"
// #include "swad_syllabus.h"
/*****************************************************************************/
/***************************** Public constants ******************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Public types ********************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Public prototypes *****************************/
/*****************************************************************************/
//------------------------------- Info type -----------------------------------
Inf_Type_t Inf_DB_ConvertFromStrDBToInfoType (const char *StrInfoTypeDB);
//------------------------------ Info source ----------------------------------
void Inf_DB_SetInfoSrc (Inf_Src_t InfoSrc);
unsigned Inf_DB_GetInfoSrc (MYSQL_RES **mysql_res,
long CrsCod,Inf_Type_t InfoType);
unsigned Inf_DB_GetInfoSrcAndMustBeRead (MYSQL_RES **mysql_res,
long CrsCod,Inf_Type_t InfoType);
Inf_Src_t Inf_DB_ConvertFromStrDBToInfoSrc (const char *StrInfoSrcDB);
//------------------------------- Info text -----------------------------------
void Inf_DB_SetInfoTxt (const char *InfoTxtHTML,const char *InfoTxtMD);
unsigned Inf_DB_GetInfoTxt (MYSQL_RES **mysql_res,
long CrsCod,Inf_Type_t InfoType);
//------------------------- Info read by students? ----------------------------
void Inf_DB_SetForceRead (bool MustBeRead);
void Inf_DB_SetIHaveRead (bool IHaveRead);
bool Inf_DB_CheckIfIHaveReadInfo (void);
#endif

View File

@ -42,6 +42,7 @@
#include "swad_forum.h"
#include "swad_global.h"
#include "swad_HTML.h"
#include "swad_info_database.h"
#include "swad_parameter.h"
#include "swad_string.h"
#include "swad_xml.h"
@ -964,7 +965,7 @@ void Syl_RemoveItemSyllabus (void)
/***** We are editing a syllabus with the internal editor,
so change info source to internal editor in database *****/
Inf_SetInfoSrcIntoDB (Syl_LstItemsSyllabus.NumItems ? Inf_EDITOR :
Inf_DB_SetInfoSrc (Syl_LstItemsSyllabus.NumItems ? Inf_EDITOR :
Inf_NONE);
/***** Show the updated syllabus to continue editing it *****/
@ -1070,7 +1071,7 @@ static void Syl_ChangePlaceItemSyllabus (Syl_ChangePosItem_t UpOrDownPos)
/***** We are editing a syllabus with the internal editor,
so change info source to internal editor in database *****/
Inf_SetInfoSrcIntoDB (Syl_LstItemsSyllabus.NumItems ? Inf_EDITOR :
Inf_DB_SetInfoSrc (Syl_LstItemsSyllabus.NumItems ? Inf_EDITOR :
Inf_NONE);
/***** Show the updated syllabus to continue editing it *****/
@ -1239,7 +1240,7 @@ static void Syl_ChangeLevelItemSyllabus (Syl_ChangeLevelItem_t IncreaseOrDecreas
/***** We are editing a syllabus with the internal editor,
so change info source to internal editor in database *****/
Inf_SetInfoSrcIntoDB (Syl_LstItemsSyllabus.NumItems ? Inf_EDITOR :
Inf_DB_SetInfoSrc (Syl_LstItemsSyllabus.NumItems ? Inf_EDITOR :
Inf_NONE);
/***** Show the updated syllabus to continue editing it *****/
@ -1310,7 +1311,7 @@ void Syl_InsertItemSyllabus (void)
/***** We are editing a syllabus with the internal editor,
so change info source to internal editor in database *****/
Inf_SetInfoSrcIntoDB (Syl_LstItemsSyllabus.NumItems ? Inf_EDITOR :
Inf_DB_SetInfoSrc (Syl_LstItemsSyllabus.NumItems ? Inf_EDITOR :
Inf_NONE);
/***** Show the updated syllabus to continue editing it *****/
@ -1362,7 +1363,7 @@ void Syl_ModifyItemSyllabus (void)
/***** We are editing a syllabus with the internal editor,
so change info source to internal editor in database *****/
Inf_SetInfoSrcIntoDB (Syl_LstItemsSyllabus.NumItems ? Inf_EDITOR :
Inf_DB_SetInfoSrc (Syl_LstItemsSyllabus.NumItems ? Inf_EDITOR :
Inf_NONE);
/***** Show the updated syllabus to continue editing it *****/

View File

@ -3031,7 +3031,7 @@ bool Usr_GetParamOtherUsrCodEncryptedAndGetUsrData (void)
/***** Check if user exists and get her/his data *****/
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CURRENT_CRS))
Usr_GET_ROLE_IN_CURRENT_CRS))
// Existing user
return true;