mirror of https://github.com/acanas/swad-core.git
Version 21.41: Oct 24, 2021 New module swad_tag_database for database queries related to question tags.
This commit is contained in:
parent
2f208d16b0
commit
00302bea7d
8
Makefile
8
Makefile
|
@ -82,10 +82,10 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
|
|||
swad_setting.o swad_setting_database.o swad_statistic.o \
|
||||
swad_statistic_database.o swad_string.o swad_survey.o \
|
||||
swad_survey_database.o swad_syllabus.o swad_system_config.o \
|
||||
swad_tab.o swad_tag.o swad_test.o swad_test_config.o \
|
||||
swad_test_import.o swad_test_print.o swad_test_visibility.o \
|
||||
swad_theme.o \
|
||||
swad_timeline.o swad_timeline_comment.o swad_timeline_database.o \
|
||||
swad_tab.o swad_tag.o swad_tag_database.o swad_test.o \
|
||||
swad_test_config.o swad_test_import.o swad_test_print.o \
|
||||
swad_test_visibility.o swad_theme.o swad_timeline.o \
|
||||
swad_timeline_comment.o swad_timeline_database.o \
|
||||
swad_timeline_favourite.o swad_timeline_form.o swad_timeline_note.o \
|
||||
swad_timeline_notification.o swad_timeline_post.o \
|
||||
swad_timeline_publication.o swad_timeline_share.o \
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
/********************************* Headers ***********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define _GNU_SOURCE // For asprintf
|
||||
#include <stdio.h> // For asprintf
|
||||
|
||||
#include "swad_center.h"
|
||||
#include "swad_center_config.h"
|
||||
#include "swad_database.h"
|
||||
|
@ -615,6 +618,118 @@ void Ctr_DB_UpdateCtrStatus (long CtrCod,Ctr_Status_t NewStatus)
|
|||
CtrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********** Check if any of the centers in an institution has map ************/
|
||||
/*****************************************************************************/
|
||||
|
||||
bool Ctr_DB_GetIfMapIsAvailableInIns (long InsCod)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
bool MapIsAvailable = false;
|
||||
|
||||
/***** Get if any center in current institution has a coordinate set
|
||||
(coordinates 0, 0 means not set ==> don't show map) *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get if map is available",
|
||||
"SELECT EXISTS" // row[0]
|
||||
"(SELECT *"
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND (Latitude<>0"
|
||||
" OR"
|
||||
" Longitude<>0))",
|
||||
InsCod))
|
||||
{
|
||||
/* Get if map is available */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
MapIsAvailable = (row[0][0] == '1');
|
||||
}
|
||||
|
||||
/* Free structure that stores the query result */
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
||||
return MapIsAvailable;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********* Get average coordinates of centers in current institution *********/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ctr_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get average coordinates of centers with both coordinates set
|
||||
(coordinates 0, 0 means not set ==> don't show map) *****/
|
||||
if (asprintf (&Query,
|
||||
"SELECT AVG(Latitude)," // row[0]
|
||||
"AVG(Longitude)," // row[1]
|
||||
"GREATEST(MAX(Latitude)-MIN(Latitude),"
|
||||
"MAX(Longitude)-MIN(Longitude))" // row[2]
|
||||
" FROM ctr_centers"
|
||||
" WHERE Latitude<>0"
|
||||
" AND Longitude<>0") < 0)
|
||||
Err_NotEnoughMemoryExit ();
|
||||
Map_GetCoordAndZoom (Coord,Zoom,Query);
|
||||
free (Query);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********* Get average coordinates of centers in current institution *********/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ctr_DB_GetCoordAndZoomInCurrentIns (struct Map_Coordinates *Coord,unsigned *Zoom)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get average coordinates of centers of current institution
|
||||
with both coordinates set
|
||||
(coordinates 0, 0 means not set ==> don't show map) *****/
|
||||
if (asprintf (&Query,
|
||||
"SELECT AVG(Latitude)," // row[0]
|
||||
"AVG(Longitude)," // row[1]
|
||||
"GREATEST(MAX(Latitude)-MIN(Latitude),"
|
||||
"MAX(Longitude)-MIN(Longitude))" // row[2]
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND Latitude<>0"
|
||||
" AND Longitude<>0",
|
||||
Gbl.Hierarchy.Ins.InsCod) < 0)
|
||||
Err_NotEnoughMemoryExit ();
|
||||
Map_GetCoordAndZoom (Coord,Zoom,Query);
|
||||
free (Query);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************* Get centres which have coordinates **********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Ctr_DB_GetCtrsWithCoords (MYSQL_RES **mysql_res)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get centers with coordinates",
|
||||
"SELECT CtrCod"
|
||||
" FROM ctr_centers"
|
||||
" WHERE ctr_centers.Latitude<>0"
|
||||
" AND ctr_centers.Longitude<>0");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******** Get centres which have coordinates in current institution **********/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Ctr_DB_GetCtrsWithCoordsInCurrentIns (MYSQL_RES **mysql_res)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get centers with coordinates",
|
||||
"SELECT CtrCod" // row[0]
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND Latitude<>0"
|
||||
" AND Longitude<>0",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************************** Remove a center ******************************/
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -80,6 +80,13 @@ void Ctr_DB_UpdateCtrCoordinate (long CtrCod,
|
|||
const char *CoordField,double NewCoord);
|
||||
void Ctr_DB_UpdateCtrStatus (long CtrCod,Ctr_Status_t NewStatus);
|
||||
|
||||
|
||||
bool Ctr_DB_GetIfMapIsAvailableInIns (long InsCod);
|
||||
void Ctr_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom);
|
||||
void Ctr_DB_GetCoordAndZoomInCurrentIns (struct Map_Coordinates *Coord,unsigned *Zoom);
|
||||
unsigned Ctr_DB_GetCtrsWithCoords (MYSQL_RES **mysql_res);
|
||||
unsigned Ctr_DB_GetCtrsWithCoordsInCurrentIns (MYSQL_RES **mysql_res);
|
||||
|
||||
void Ctr_DB_RemoveCenter (long CtrCod);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -602,13 +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.40 (2021-10-24)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.41 (2021-10-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.41: Oct 24, 2021 New module swad_tag_database for database queries related to question tags. (320721 lines)
|
||||
Version 21.40.1: Oct 24, 2021 Queries moved to module swad_center_database. (320621 lines)
|
||||
Version 21.40: Oct 24, 2021 Queries moved to module swad_survey_database. (320673 lines)
|
||||
Version 21.39.2: Oct 22, 2021 Fixed bug in settings. (320544 lines)
|
||||
Version 21.39.1: Oct 21, 2021 Queries moved to module swad_survey_database. (320540 lines)
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "swad_admin_database.h"
|
||||
#include "swad_browser_database.h"
|
||||
#include "swad_center_database.h"
|
||||
#include "swad_database.h"
|
||||
#include "swad_department.h"
|
||||
#include "swad_enrolment_database.h"
|
||||
|
@ -1972,7 +1973,7 @@ static void Ins_FormToGoToMap (struct Ins_Instit *Ins)
|
|||
{
|
||||
extern const char *Txt_Map;
|
||||
|
||||
if (Ins_DB_GetIfMapIsAvailable (Ins->InsCod))
|
||||
if (Ctr_DB_GetIfMapIsAvailableInIns (Ins->InsCod))
|
||||
{
|
||||
Ins_EditingIns = Ins; // Used to pass parameter with the code of the institution
|
||||
Lay_PutContextualLinkOnlyIcon (ActSeeInsInf,NULL,
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <stdio.h> // For asprintf
|
||||
#include <stdlib.h> // For free
|
||||
|
||||
#include "swad_center_database.h"
|
||||
#include "swad_database.h"
|
||||
#include "swad_department_database.h"
|
||||
#include "swad_error.h"
|
||||
|
@ -273,14 +274,14 @@ static void InsCfg_Map (void)
|
|||
HTM_SCRIPT_Begin (NULL,NULL);
|
||||
|
||||
/* Let's create a map with pretty Mapbox Streets tiles */
|
||||
Ins_DB_GetCoordAndZoom (&InsAvgCoord,&Zoom);
|
||||
Ctr_DB_GetCoordAndZoomInCurrentIns (&InsAvgCoord,&Zoom);
|
||||
Map_CreateMap (InsCfg_MAP_CONTAINER_ID,&InsAvgCoord,Zoom);
|
||||
|
||||
/* Add Mapbox Streets tile layer to our map */
|
||||
Map_AddTileLayer ();
|
||||
|
||||
/* Get centers with coordinates */
|
||||
NumCtrs = Ins_DB_GetCtrsWithCoordsInCurrentIns (&mysql_res);
|
||||
NumCtrs = Ctr_DB_GetCtrsWithCoordsInCurrentIns (&mysql_res);
|
||||
|
||||
/* Add a marker and a popup for each center */
|
||||
for (NumCtr = 0;
|
||||
|
|
|
@ -753,81 +753,6 @@ unsigned Ins_DB_GetNumInnsWithUsrs (Rol_Role_t Role,
|
|||
SubQuery,(unsigned) Role);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********** Check if any of the centers in an institution has map ************/
|
||||
/*****************************************************************************/
|
||||
|
||||
bool Ins_DB_GetIfMapIsAvailable (long InsCod)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
bool MapIsAvailable = false;
|
||||
|
||||
/***** Get if any center in current institution has a coordinate set
|
||||
(coordinates 0, 0 means not set ==> don't show map) *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get if map is available",
|
||||
"SELECT EXISTS" // row[0]
|
||||
"(SELECT *"
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND (Latitude<>0"
|
||||
" OR"
|
||||
" Longitude<>0))",
|
||||
InsCod))
|
||||
{
|
||||
/* Get if map is available */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
MapIsAvailable = (row[0][0] == '1');
|
||||
}
|
||||
|
||||
/* Free structure that stores the query result */
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
||||
return MapIsAvailable;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********* Get average coordinates of centers in current institution *********/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ins_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get average coordinates of centers of current institution
|
||||
with both coordinates set
|
||||
(coordinates 0, 0 means not set ==> don't show map) *****/
|
||||
if (asprintf (&Query,
|
||||
"SELECT AVG(Latitude)," // row[0]
|
||||
"AVG(Longitude)," // row[1]
|
||||
"GREATEST(MAX(Latitude)-MIN(Latitude),"
|
||||
"MAX(Longitude)-MIN(Longitude))" // row[2]
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND Latitude<>0"
|
||||
" AND Longitude<>0",
|
||||
Gbl.Hierarchy.Ins.InsCod) < 0)
|
||||
Err_NotEnoughMemoryExit ();
|
||||
Map_GetCoordAndZoom (Coord,Zoom,Query);
|
||||
free (Query);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******** Get centres which have coordinates in current institution **********/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Ins_DB_GetCtrsWithCoordsInCurrentIns (MYSQL_RES **mysql_res)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get centers with coordinates",
|
||||
"SELECT CtrCod" // row[0]
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND Latitude<>0"
|
||||
" AND Longitude<>0",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Remove institution ****************************/
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -80,10 +80,6 @@ unsigned Ins_DB_GetNumInssWithCrss (HieLvl_Level_t Scope,long Cod);
|
|||
unsigned Ins_DB_GetNumInnsWithUsrs (Rol_Role_t Role,
|
||||
HieLvl_Level_t Scope,long Cod);
|
||||
|
||||
bool Ins_DB_GetIfMapIsAvailable (long InsCod);
|
||||
void Ins_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom);
|
||||
unsigned Ins_DB_GetCtrsWithCoordsInCurrentIns (MYSQL_RES **mysql_res);
|
||||
|
||||
void Ins_DB_RemoveInstitution (long InsCod);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -25,39 +25,9 @@
|
|||
/********************************* Headers ***********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
// #define _GNU_SOURCE // For asprintf
|
||||
// #include <linux/limits.h> // For PATH_MAX
|
||||
// #include <math.h> // For log10, floor, ceil, modf, sqrt...
|
||||
// #include <stddef.h> // For NULL
|
||||
// #include <stdio.h> // For asprintf
|
||||
// #include <stdlib.h> // For system, getenv, etc.
|
||||
// #include <string.h> // For string functions
|
||||
// #include <sys/wait.h> // For the macro WEXITSTATUS
|
||||
// #include <unistd.h> // For unlink
|
||||
|
||||
// #include "swad_action.h"
|
||||
// #include "swad_box.h"
|
||||
// #include "swad_browser.h"
|
||||
// #include "swad_config.h"
|
||||
#include "swad_database.h"
|
||||
// #include "swad_enrolment.h"
|
||||
// #include "swad_error.h"
|
||||
// #include "swad_file.h"
|
||||
// #include "swad_follow.h"
|
||||
// #include "swad_form.h"
|
||||
#include "swad_global.h"
|
||||
// #include "swad_hierarchy.h"
|
||||
// #include "swad_hierarchy_level.h"
|
||||
// #include "swad_HTML.h"
|
||||
// #include "swad_logo.h"
|
||||
// #include "swad_parameter.h"
|
||||
// #include "swad_photo.h"
|
||||
#include "swad_photo_database.h"
|
||||
// #include "swad_privacy.h"
|
||||
// #include "swad_setting.h"
|
||||
// #include "swad_statistic.h"
|
||||
// #include "swad_theme.h"
|
||||
// #include "swad_user.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/************** External global variables from others modules ****************/
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
|
||||
#include "swad_cryptography.h"
|
||||
#include "swad_photo.h"
|
||||
// #include "swad_user.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************* Public types and constants ************************/
|
||||
|
|
|
@ -25,23 +25,9 @@
|
|||
/*********************************** Headers *********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
// #include <stdlib.h> // For free
|
||||
// #include <sys/stat.h> // For mkdir
|
||||
// #include <sys/types.h> // For mkdir
|
||||
|
||||
// #include "swad_box.h"
|
||||
// #include "swad_browser_database.h"
|
||||
#include "swad_database.h"
|
||||
// #include "swad_error.h"
|
||||
// #include "swad_form.h"
|
||||
// #include "swad_global.h"
|
||||
// #include "swad_hierarchy_level.h"
|
||||
// #include "swad_HTML.h"
|
||||
// #include "swad_ID.h"
|
||||
// #include "swad_profile.h"
|
||||
#include "swad_report.h"
|
||||
#include "swad_report_database.h"
|
||||
// #include "swad_tab.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************************** Public constants *****************************/
|
||||
|
|
|
@ -29,9 +29,6 @@
|
|||
|
||||
#include <mysql/mysql.h> // To access MySQL databases
|
||||
|
||||
// #include "swad_indicator.h"
|
||||
// #include "swad_photo.h"
|
||||
// #include "swad_user.h"
|
||||
#include "swad_statistic.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -26,28 +26,13 @@
|
|||
/*****************************************************************************/
|
||||
|
||||
#define _GNU_SOURCE // For asprintf
|
||||
// #include <linux/limits.h> // For PATH_MAX
|
||||
// #include <stddef.h> // For NULL
|
||||
#include <stdio.h> // For asprintf
|
||||
#include <stdlib.h> // For free
|
||||
#include <string.h> // For string functions
|
||||
|
||||
// #include "swad_attendance.h"
|
||||
// #include "swad_box.h"
|
||||
#include "swad_database.h"
|
||||
#include "swad_error.h"
|
||||
// #include "swad_figure.h"
|
||||
// #include "swad_form.h"
|
||||
#include "swad_global.h"
|
||||
// #include "swad_group.h"
|
||||
// #include "swad_group_database.h"
|
||||
// #include "swad_HTML.h"
|
||||
// #include "swad_notification.h"
|
||||
// #include "swad_notification_database.h"
|
||||
// #include "swad_pagination.h"
|
||||
// #include "swad_parameter.h"
|
||||
// #include "swad_role.h"
|
||||
// #include "swad_setting.h"
|
||||
#include "swad_survey.h"
|
||||
#include "swad_survey_database.h"
|
||||
|
||||
|
|
|
@ -106,8 +106,7 @@ struct LstItemsSyllabus Syl_LstItemsSyllabus;
|
|||
static unsigned Syl_GetParamItemNumber (void);
|
||||
|
||||
static void Syl_SetSyllabusTypeFromAction (struct Syl_Syllabus *Syllabus);
|
||||
static void Syl_ShowSyllabus (struct Syl_Syllabus *Syllabus,
|
||||
bool PutIconToEdit);
|
||||
static void Syl_ShowSyllabus (struct Syl_Syllabus *Syllabus);
|
||||
static void Syl_ShowRowSyllabus (struct Syl_Syllabus *Syllabus,unsigned NumItem,
|
||||
int Level,int *CodItem,const char *Text,bool NewItem);
|
||||
static void Syl_PutFormItemSyllabus (struct Syl_Syllabus *Syllabus,
|
||||
|
@ -222,11 +221,6 @@ bool Syl_CheckSyllabus (struct Syl_Syllabus *Syllabus,long CrsCod)
|
|||
|
||||
bool Syl_CheckAndEditSyllabus (struct Syl_Syllabus *Syllabus)
|
||||
{
|
||||
extern const Act_Action_t Inf_ActionsSeeInfo[Inf_NUM_TYPES];
|
||||
extern const char *Txt_Done;
|
||||
bool ICanEdit;
|
||||
bool PutIconToEdit;
|
||||
|
||||
/***** Set syllabus type depending on current action *****/
|
||||
Syl_SetSyllabusTypeFromAction (Syllabus);
|
||||
|
||||
|
@ -252,24 +246,8 @@ bool Syl_CheckAndEditSyllabus (struct Syl_Syllabus *Syllabus)
|
|||
|
||||
if (Syllabus->EditionIsActive || Syl_LstItemsSyllabus.NumItems)
|
||||
{
|
||||
ICanEdit = Gbl.Usrs.Me.Role.Logged == Rol_TCH ||
|
||||
Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM;
|
||||
PutIconToEdit = ICanEdit && !Syllabus->EditionIsActive;
|
||||
|
||||
/***** Write the current syllabus *****/
|
||||
Syl_ShowSyllabus (Syllabus,PutIconToEdit);
|
||||
|
||||
if (Syllabus->EditionIsActive)
|
||||
{
|
||||
/***** Button to view *****/
|
||||
Frm_BeginForm (Inf_ActionsSeeInfo[Gbl.Crs.Info.Type]);
|
||||
Btn_PutConfirmButton (Txt_Done);
|
||||
Frm_EndForm ();
|
||||
}
|
||||
|
||||
/***** End box *****/
|
||||
Box_BoxEnd ();
|
||||
|
||||
Syl_ShowSyllabus (Syllabus);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -527,12 +505,13 @@ int Syl_ReadLevelItemSyllabus (void)
|
|||
/***************** Show a syllabus of lectures or practicals *****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Syl_ShowSyllabus (struct Syl_Syllabus *Syllabus,
|
||||
bool PutIconToEdit)
|
||||
static void Syl_ShowSyllabus (struct Syl_Syllabus *Syllabus)
|
||||
{
|
||||
extern const Act_Action_t Inf_ActionsSeeInfo[Inf_NUM_TYPES];
|
||||
extern const char *Txt_INFO_TITLE[Inf_NUM_TYPES];
|
||||
extern const char *Hlp_COURSE_Syllabus_edit;
|
||||
extern const char *Hlp_COURSE_Syllabus;
|
||||
extern const char *Txt_Done;
|
||||
unsigned NumItem;
|
||||
int i;
|
||||
int NumButtons = Syllabus->EditionIsActive ? 5 :
|
||||
|
@ -541,6 +520,9 @@ static void Syl_ShowSyllabus (struct Syl_Syllabus *Syllabus,
|
|||
Gbl.Action.Act == ActModIteSylLec || Gbl.Action.Act == ActModIteSylPra ||
|
||||
Gbl.Action.Act == ActRgtIteSylLec || Gbl.Action.Act == ActRgtIteSylPra ||
|
||||
Gbl.Action.Act == ActLftIteSylLec || Gbl.Action.Act == ActLftIteSylPra);
|
||||
bool ICanEdit = Gbl.Usrs.Me.Role.Logged == Rol_TCH ||
|
||||
Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM;
|
||||
bool PutIconToEdit = ICanEdit && !Syllabus->EditionIsActive;
|
||||
|
||||
/***** Begin box and table *****/
|
||||
if (PutIconToEdit)
|
||||
|
@ -593,6 +575,17 @@ static void Syl_ShowSyllabus (struct Syl_Syllabus *Syllabus,
|
|||
|
||||
/***** End table *****/
|
||||
HTM_TABLE_End ();
|
||||
|
||||
if (Syllabus->EditionIsActive)
|
||||
{
|
||||
/***** Button to view *****/
|
||||
Frm_BeginForm (Inf_ActionsSeeInfo[Gbl.Crs.Info.Type]);
|
||||
Btn_PutConfirmButton (Txt_Done);
|
||||
Frm_EndForm ();
|
||||
}
|
||||
|
||||
/***** End box *****/
|
||||
Box_BoxEnd ();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <string.h> // For string functions
|
||||
|
||||
#include "swad_box.h"
|
||||
#include "swad_center_database.h"
|
||||
#include "swad_config.h"
|
||||
#include "swad_course.h"
|
||||
#include "swad_database.h"
|
||||
|
@ -68,7 +69,6 @@
|
|||
|
||||
static void SysCfg_Configuration (bool PrintView);
|
||||
static void SysCfg_PutIconToPrint (__attribute__((unused)) void *Args);
|
||||
static void SysCfg_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom);
|
||||
static void SysCfg_Map (void);
|
||||
static void SysCfg_Platform (void);
|
||||
static void SysCfg_Shortcut (bool PrintView);
|
||||
|
@ -193,29 +193,6 @@ static void SysCfg_PutIconToPrint (__attribute__((unused)) void *Args)
|
|||
NULL,NULL);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********* Get average coordinates of centers in current institution *********/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void SysCfg_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get average coordinates of centers with both coordinates set
|
||||
(coordinates 0, 0 means not set ==> don't show map) *****/
|
||||
if (asprintf (&Query,
|
||||
"SELECT AVG(Latitude)," // row[0]
|
||||
"AVG(Longitude)," // row[1]
|
||||
"GREATEST(MAX(Latitude)-MIN(Latitude),"
|
||||
"MAX(Longitude)-MIN(Longitude))" // row[2]
|
||||
" FROM ctr_centers"
|
||||
" WHERE Latitude<>0"
|
||||
" AND Longitude<>0") < 0)
|
||||
Err_NotEnoughMemoryExit ();
|
||||
Map_GetCoordAndZoom (Coord,Zoom,Query);
|
||||
free (Query);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************************** Draw country map *****************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -246,19 +223,14 @@ static void SysCfg_Map (void)
|
|||
HTM_SCRIPT_Begin (NULL,NULL);
|
||||
|
||||
/* Let's create a map with pretty Mapbox Streets tiles */
|
||||
SysCfg_GetCoordAndZoom (&CtyAvgCoord,&Zoom);
|
||||
Ctr_DB_GetCoordAndZoom (&CtyAvgCoord,&Zoom);
|
||||
Map_CreateMap (SysCfg_MAP_CONTAINER_ID,&CtyAvgCoord,Zoom);
|
||||
|
||||
/* Add Mapbox Streets tile layer to our map */
|
||||
Map_AddTileLayer ();
|
||||
|
||||
/* Get centers with coordinates */
|
||||
NumCtrs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get centers with coordinates",
|
||||
"SELECT CtrCod"
|
||||
" FROM ctr_centers"
|
||||
" WHERE ctr_centers.Latitude<>0"
|
||||
" AND ctr_centers.Longitude<>0");
|
||||
NumCtrs = Ctr_DB_GetCtrsWithCoords (&mysql_res);
|
||||
|
||||
/* Add a marker and a popup for each center */
|
||||
for (NumCtr = 0;
|
||||
|
|
176
swad_tag.c
176
swad_tag.c
|
@ -36,6 +36,7 @@
|
|||
#include "swad_form.h"
|
||||
#include "swad_global.h"
|
||||
#include "swad_tag.h"
|
||||
#include "swad_tag_database.h"
|
||||
#include "swad_theme.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -64,13 +65,8 @@ extern struct Globals Gbl;
|
|||
/***************************** Private prototypes ****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Tag_EnableOrDisableTag (long TagCod,bool TagHidden);
|
||||
|
||||
static long Tag_GetParamTagCode (void);
|
||||
|
||||
static long Tag_GetTagCodFromTagTxt (const char *TagTxt);
|
||||
static long Tag_CreateNewTag (long CrsCod,const char *TagTxt);
|
||||
|
||||
static void Tag_PutIconEnable (long TagCod,const char *TagTxt);
|
||||
static void Tag_PutIconDisable (long TagCod,const char *TagTxt);
|
||||
|
||||
|
@ -121,57 +117,6 @@ void Tag_PutIconToEditTags (void)
|
|||
Txt_Edit_tags);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************* Check if current course has test tags *******************/
|
||||
/*****************************************************************************/
|
||||
// Return the number of rows of the result
|
||||
|
||||
bool Tag_CheckIfCurrentCrsHasTestTags (void)
|
||||
{
|
||||
/***** Get available tags from database *****/
|
||||
return (DB_QueryCOUNT ("can not check if course has tags",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM tst_tags"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********* Get all (enabled or disabled) test tags for this course ***********/
|
||||
/*****************************************************************************/
|
||||
// Return the number of rows of the result
|
||||
|
||||
unsigned Tag_GetAllTagsFromCurrentCrs (MYSQL_RES **mysql_res)
|
||||
{
|
||||
/***** Get available tags from database *****/
|
||||
return (unsigned) DB_QuerySELECT (mysql_res,"can not get available tags",
|
||||
"SELECT TagCod," // row[0]
|
||||
"TagTxt," // row[1]
|
||||
"TagHidden" // row[2]
|
||||
" FROM tst_tags"
|
||||
" WHERE CrsCod=%ld"
|
||||
" ORDER BY TagTxt",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************** Get enabled test tags for this course ****************/
|
||||
/*****************************************************************************/
|
||||
// Return the number of rows of the result
|
||||
|
||||
unsigned Tag_GetEnabledTagsFromThisCrs (MYSQL_RES **mysql_res)
|
||||
{
|
||||
/***** Get available not hidden tags from database *****/
|
||||
return (unsigned) DB_QuerySELECT (mysql_res,"can not get available enabled tags",
|
||||
"SELECT TagCod," // row[0]
|
||||
"TagTxt" // row[1]
|
||||
" FROM tst_tags"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND TagHidden='N'"
|
||||
" ORDER BY TagTxt",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************************* Enable a test tag ***************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -181,7 +126,7 @@ void Tag_EnableTag (void)
|
|||
long TagCod = Tag_GetParamTagCode ();
|
||||
|
||||
/***** Change tag status to enabled *****/
|
||||
Tag_EnableOrDisableTag (TagCod,false);
|
||||
Tag_DB_EnableOrDisableTag (TagCod,false);
|
||||
|
||||
/***** Show again the form to edit tags *****/
|
||||
Tag_ShowFormEditTags ();
|
||||
|
@ -196,31 +141,12 @@ void Tag_DisableTag (void)
|
|||
long TagCod = Tag_GetParamTagCode ();
|
||||
|
||||
/***** Change tag status to disabled *****/
|
||||
Tag_EnableOrDisableTag (TagCod,true);
|
||||
Tag_DB_EnableOrDisableTag (TagCod,true);
|
||||
|
||||
/***** Show again the form to edit tags *****/
|
||||
Tag_ShowFormEditTags ();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********** Change visibility of an existing tag into tst_tags table *********/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Tag_EnableOrDisableTag (long TagCod,bool TagHidden)
|
||||
{
|
||||
/***** Insert new tag into tst_tags table *****/
|
||||
DB_QueryUPDATE ("can not update the visibility of a tag",
|
||||
"UPDATE tst_tags"
|
||||
" SET TagHidden='%c',"
|
||||
"ChangeTime=NOW()"
|
||||
" WHERE TagCod=%ld"
|
||||
" AND CrsCod=%ld",
|
||||
TagHidden ? 'Y' :
|
||||
'N',
|
||||
TagCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************* Get parameter with tag code ***********************/
|
||||
/*****************************************************************************/
|
||||
|
@ -273,7 +199,7 @@ void Tag_RenameTag (void)
|
|||
// are not the same (case insensitively)
|
||||
/* Check if the new tag text is equal to any of the tags
|
||||
already present in the database */
|
||||
if ((ExistingTagCod = Tag_GetTagCodFromTagTxt (NewTagTxt)) > 0)
|
||||
if ((ExistingTagCod = Tag_DB_GetTagCodFromTagTxt (NewTagTxt)) > 0)
|
||||
// The new tag was already in database
|
||||
ComplexRenaming = true;
|
||||
|
||||
|
@ -286,7 +212,7 @@ void Tag_RenameTag (void)
|
|||
- If the new tag did not exist for a question ==>
|
||||
change old tag to new tag in tst_question_tags *****/
|
||||
/* Get tag code of the old tag */
|
||||
if ((OldTagCod = Tag_GetTagCodFromTagTxt (OldTagTxt)) <= 0)
|
||||
if ((OldTagCod = Tag_DB_GetTagCodFromTagTxt (OldTagTxt)) <= 0)
|
||||
Err_WrongTagExit ();
|
||||
|
||||
/* Create a temporary table with all the question codes
|
||||
|
@ -361,22 +287,6 @@ void Tag_RenameTag (void)
|
|||
Tag_ShowFormEditTags ();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************** Check if this tag exists for current course ***************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static long Tag_GetTagCodFromTagTxt (const char *TagTxt)
|
||||
{
|
||||
/***** Get tag code from database *****/
|
||||
return DB_QuerySELECTCode ("can not get tag",
|
||||
"SELECT TagCod"
|
||||
" FROM tst_tags"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND TagTxt='%s'",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
TagTxt);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** Insert tags in the tags table ***********************/
|
||||
/*****************************************************************************/
|
||||
|
@ -384,51 +294,27 @@ static long Tag_GetTagCodFromTagTxt (const char *TagTxt)
|
|||
void Tag_InsertTagsIntoDB (long QstCod,const struct Tag_Tags *Tags)
|
||||
{
|
||||
unsigned NumTag;
|
||||
unsigned TagIdx;
|
||||
unsigned TagInd;
|
||||
long TagCod;
|
||||
|
||||
/***** For each tag... *****/
|
||||
for (NumTag = 0, TagIdx = 0;
|
||||
TagIdx < Tags->Num;
|
||||
for (NumTag = 0, TagInd = 0;
|
||||
TagInd < Tags->Num;
|
||||
NumTag++)
|
||||
if (Tags->Txt[NumTag][0])
|
||||
{
|
||||
/***** Check if this tag exists for current course *****/
|
||||
if ((TagCod = Tag_GetTagCodFromTagTxt (Tags->Txt[NumTag])) < 0)
|
||||
if ((TagCod = Tag_DB_GetTagCodFromTagTxt (Tags->Txt[NumTag])) < 0)
|
||||
/* This tag is new for current course. Add it to tags table */
|
||||
TagCod = Tag_CreateNewTag (Gbl.Hierarchy.Crs.CrsCod,Tags->Txt[NumTag]);
|
||||
TagCod = Tag_DB_CreateNewTag (Gbl.Hierarchy.Crs.CrsCod,Tags->Txt[NumTag]);
|
||||
|
||||
/***** Insert tag in tst_question_tags *****/
|
||||
DB_QueryINSERT ("can not create tag",
|
||||
"INSERT INTO tst_question_tags"
|
||||
" (QstCod,TagCod,TagInd)"
|
||||
" VALUES"
|
||||
" (%ld,%ld,%u)",
|
||||
QstCod,
|
||||
TagCod,
|
||||
TagIdx);
|
||||
Tag_DB_AddTagToQst (QstCod,TagCod,TagInd);
|
||||
|
||||
TagIdx++;
|
||||
TagInd++;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************* Insert new tag into tst_tags table ********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static long Tag_CreateNewTag (long CrsCod,const char *TagTxt)
|
||||
{
|
||||
/***** Insert new tag into tst_tags table *****/
|
||||
return
|
||||
DB_QueryINSERTandReturnCode ("can not create new tag",
|
||||
"INSERT INTO tst_tags"
|
||||
" (CrsCod,ChangeTime,TagTxt,TagHidden)"
|
||||
" VALUES"
|
||||
" (%ld,NOW(),'%s','Y')", // Hidden by default
|
||||
CrsCod,
|
||||
TagTxt);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************* Show a form to select test tags ***********************/
|
||||
/*****************************************************************************/
|
||||
|
@ -464,7 +350,9 @@ void Tag_ShowFormSelTags (const struct Tag_Tags *Tags,
|
|||
HTM_TD_Begin ("class=\"LT\"");
|
||||
|
||||
HTM_TABLE_BeginPadding (2);
|
||||
|
||||
HTM_TR_Begin (NULL);
|
||||
|
||||
if (!ShowOnlyEnabledTags)
|
||||
HTM_TD_Empty (1);
|
||||
|
||||
|
@ -530,6 +418,7 @@ void Tag_ShowFormSelTags (const struct Tag_Tags *Tags,
|
|||
|
||||
HTM_TABLE_End ();
|
||||
HTM_TD_End ();
|
||||
|
||||
HTM_TR_End ();
|
||||
}
|
||||
|
||||
|
@ -549,7 +438,7 @@ void Tag_ShowFormEditTags (void)
|
|||
long TagCod;
|
||||
|
||||
/***** Get current tags in current course *****/
|
||||
if ((NumTags = Tag_GetAllTagsFromCurrentCrs (&mysql_res)))
|
||||
if ((NumTags = Tag_DB_GetAllTagsFromCurrentCrs (&mysql_res)))
|
||||
{
|
||||
/***** Begin box and table *****/
|
||||
Box_BoxTableBegin (NULL,Txt_Tags,
|
||||
|
@ -638,36 +527,3 @@ static void Tag_PutIconDisable (long TagCod,const char *TagTxt)
|
|||
Frm_EndForm ();
|
||||
HTM_TD_End ();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************** Remove tags from a question **********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Tag_RemTagsFromQst (long QstCod)
|
||||
{
|
||||
/***** Remove tags *****/
|
||||
DB_QueryDELETE ("can not remove the tags of a question",
|
||||
"DELETE FROM tst_question_tags"
|
||||
" WHERE QstCod=%ld",
|
||||
QstCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************** Remove unused tags in a course ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Tag_RemoveUnusedTagsFromCrs (long CrsCod)
|
||||
{
|
||||
/***** Remove unused tags from tst_tags *****/
|
||||
DB_QueryDELETE ("can not remove unused tags",
|
||||
"DELETE FROM tst_tags"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND TagCod NOT IN"
|
||||
" (SELECT DISTINCT tst_question_tags.TagCod"
|
||||
" FROM tst_questions,"
|
||||
"tst_question_tags"
|
||||
" WHERE tst_questions.CrsCod=%ld"
|
||||
" AND tst_questions.QstCod=tst_question_tags.QstCod)",
|
||||
CrsCod,
|
||||
CrsCod);
|
||||
}
|
||||
|
|
|
@ -61,10 +61,6 @@ void Tag_FreeTagsList (struct Tag_Tags *Tags);
|
|||
|
||||
void Tag_PutIconToEditTags (void);
|
||||
|
||||
bool Tag_CheckIfCurrentCrsHasTestTags (void);
|
||||
unsigned Tag_GetAllTagsFromCurrentCrs (MYSQL_RES **mysql_res);
|
||||
unsigned Tag_GetEnabledTagsFromThisCrs (MYSQL_RES **mysql_res);
|
||||
|
||||
void Tag_EnableTag (void);
|
||||
void Tag_DisableTag (void);
|
||||
void Tag_RenameTag (void);
|
||||
|
@ -76,7 +72,4 @@ void Tag_ShowFormSelTags (const struct Tag_Tags *Tags,
|
|||
bool ShowOnlyEnabledTags);
|
||||
void Tag_ShowFormEditTags (void);
|
||||
|
||||
void Tag_RemTagsFromQst (long QstCod);
|
||||
void Tag_RemoveUnusedTagsFromCrs (long CrsCod);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,218 @@
|
|||
// swad_tag_database.c: tags for questions, 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 <mysql/mysql.h> // To access MySQL databases
|
||||
// #include <stdbool.h> // For boolean type
|
||||
// #include <stdlib.h> // For free
|
||||
// #include <string.h> // For string functions
|
||||
|
||||
// #include "swad_action.h"
|
||||
#include "swad_database.h"
|
||||
// #include "swad_error.h"
|
||||
// #include "swad_form.h"
|
||||
#include "swad_global.h"
|
||||
// #include "swad_tag.h"
|
||||
#include "swad_tag_database.h"
|
||||
// #include "swad_theme.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Public constants ******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************************** Private constants ******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************************* Private types *******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/************** External global variables from others modules ****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
extern struct Globals Gbl;
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************* Private global variables **************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Private prototypes ****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************* Insert new tag into tst_tags table ********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
long Tag_DB_CreateNewTag (long CrsCod,const char *TagTxt)
|
||||
{
|
||||
/***** Insert new tag into tst_tags table *****/
|
||||
return
|
||||
DB_QueryINSERTandReturnCode ("can not create new tag",
|
||||
"INSERT INTO tst_tags"
|
||||
" (CrsCod,ChangeTime,TagTxt,TagHidden)"
|
||||
" VALUES"
|
||||
" (%ld,NOW(),'%s','Y')", // Hidden by default
|
||||
CrsCod,
|
||||
TagTxt);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************************** Add tag to a question ***************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Tag_DB_AddTagToQst (long QstCod,long TagCod,unsigned TagInd)
|
||||
{
|
||||
DB_QueryINSERT ("can not create tag",
|
||||
"INSERT INTO tst_question_tags"
|
||||
" (QstCod,TagCod,TagInd)"
|
||||
" VALUES"
|
||||
" (%ld,%ld,%u)",
|
||||
QstCod,
|
||||
TagCod,
|
||||
TagInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********** Change visibility of an existing tag into tst_tags table *********/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Tag_DB_EnableOrDisableTag (long TagCod,bool TagHidden)
|
||||
{
|
||||
/***** Insert new tag into tst_tags table *****/
|
||||
DB_QueryUPDATE ("can not update the visibility of a tag",
|
||||
"UPDATE tst_tags"
|
||||
" SET TagHidden='%c',"
|
||||
"ChangeTime=NOW()"
|
||||
" WHERE TagCod=%ld"
|
||||
" AND CrsCod=%ld",
|
||||
TagHidden ? 'Y' :
|
||||
'N',
|
||||
TagCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********* Get all (enabled or disabled) test tags for this course ***********/
|
||||
/*****************************************************************************/
|
||||
// Return the number of rows of the result
|
||||
|
||||
unsigned Tag_DB_GetAllTagsFromCurrentCrs (MYSQL_RES **mysql_res)
|
||||
{
|
||||
/***** Get available tags from database *****/
|
||||
return (unsigned) DB_QuerySELECT (mysql_res,"can not get available tags",
|
||||
"SELECT TagCod," // row[0]
|
||||
"TagTxt," // row[1]
|
||||
"TagHidden" // row[2]
|
||||
" FROM tst_tags"
|
||||
" WHERE CrsCod=%ld"
|
||||
" ORDER BY TagTxt",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************** Get enabled test tags for this course ****************/
|
||||
/*****************************************************************************/
|
||||
// Return the number of rows of the result
|
||||
|
||||
unsigned Tag_DB_GetEnabledTagsFromThisCrs (MYSQL_RES **mysql_res)
|
||||
{
|
||||
/***** Get available not hidden tags from database *****/
|
||||
return (unsigned) DB_QuerySELECT (mysql_res,"can not get available enabled tags",
|
||||
"SELECT TagCod," // row[0]
|
||||
"TagTxt" // row[1]
|
||||
" FROM tst_tags"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND TagHidden='N'"
|
||||
" ORDER BY TagTxt",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************* Check if current course has test tags *******************/
|
||||
/*****************************************************************************/
|
||||
// Return the number of rows of the result
|
||||
|
||||
bool Tag_DB_CheckIfCurrentCrsHasTestTags (void)
|
||||
{
|
||||
/***** Get available tags from database *****/
|
||||
return (DB_QueryCOUNT ("can not check if course has tags",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM tst_tags"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************** Check if this tag exists for current course ***************/
|
||||
/*****************************************************************************/
|
||||
|
||||
long Tag_DB_GetTagCodFromTagTxt (const char *TagTxt)
|
||||
{
|
||||
/***** Get tag code from database *****/
|
||||
return DB_QuerySELECTCode ("can not get tag",
|
||||
"SELECT TagCod"
|
||||
" FROM tst_tags"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND TagTxt='%s'",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
TagTxt);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************** Remove tags from a question **********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Tag_DB_RemTagsFromQst (long QstCod)
|
||||
{
|
||||
/***** Remove tags *****/
|
||||
DB_QueryDELETE ("can not remove the tags of a question",
|
||||
"DELETE FROM tst_question_tags"
|
||||
" WHERE QstCod=%ld",
|
||||
QstCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************** Remove unused tags in a course ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Tag_DB_RemoveUnusedTagsFromCrs (long CrsCod)
|
||||
{
|
||||
/***** Remove unused tags from tst_tags *****/
|
||||
DB_QueryDELETE ("can not remove unused tags",
|
||||
"DELETE FROM tst_tags"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND TagCod NOT IN"
|
||||
" (SELECT DISTINCT tst_question_tags.TagCod"
|
||||
" FROM tst_questions,"
|
||||
"tst_question_tags"
|
||||
" WHERE tst_questions.CrsCod=%ld"
|
||||
" AND tst_questions.QstCod=tst_question_tags.QstCod)",
|
||||
CrsCod,
|
||||
CrsCod);
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
// swad_tag_database.h: tags for questions, operations with database
|
||||
|
||||
#ifndef _SWAD_TAG_DB
|
||||
#define _SWAD_TAG_DB
|
||||
/*
|
||||
SWAD (Shared Workspace At a Distance in Spanish),
|
||||
is a web platform developed at the University of Granada (Spain),
|
||||
and used to support university teaching.
|
||||
|
||||
This file is part of SWAD core.
|
||||
Copyright (C) 1999-2021 Antonio Cañas Vargas
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
/********************************* Headers ***********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <mysql/mysql.h> // To access MySQL databases
|
||||
#include <stdbool.h> // For boolean type
|
||||
// #include "swad_string.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Public constants ******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************************* Public types ********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Public prototypes *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
long Tag_DB_CreateNewTag (long CrsCod,const char *TagTxt);
|
||||
void Tag_DB_AddTagToQst (long QstCod,long TagCod,unsigned TagInd);
|
||||
|
||||
void Tag_DB_EnableOrDisableTag (long TagCod,bool TagHidden);
|
||||
|
||||
unsigned Tag_DB_GetAllTagsFromCurrentCrs (MYSQL_RES **mysql_res);
|
||||
unsigned Tag_DB_GetEnabledTagsFromThisCrs (MYSQL_RES **mysql_res);
|
||||
bool Tag_DB_CheckIfCurrentCrsHasTestTags (void);
|
||||
long Tag_DB_GetTagCodFromTagTxt (const char *TagTxt);
|
||||
|
||||
void Tag_DB_RemTagsFromQst (long QstCod);
|
||||
void Tag_DB_RemoveUnusedTagsFromCrs (long CrsCod);
|
||||
|
||||
#endif
|
23
swad_test.c
23
swad_test.c
|
@ -52,12 +52,13 @@
|
|||
#include "swad_match.h"
|
||||
#include "swad_media.h"
|
||||
#include "swad_parameter.h"
|
||||
#include "swad_theme.h"
|
||||
#include "swad_tag_database.h"
|
||||
#include "swad_test.h"
|
||||
#include "swad_test_config.h"
|
||||
#include "swad_test_import.h"
|
||||
#include "swad_test_print.h"
|
||||
#include "swad_test_visibility.h"
|
||||
#include "swad_theme.h"
|
||||
#include "swad_user.h"
|
||||
#include "swad_xml.h"
|
||||
|
||||
|
@ -304,7 +305,7 @@ static void Tst_ShowFormRequestTest (struct Tst_Test *Test)
|
|||
Hlp_ASSESSMENT_Tests,Box_NOT_CLOSABLE);
|
||||
|
||||
/***** Get tags *****/
|
||||
if ((Test->Tags.Num = Tag_GetEnabledTagsFromThisCrs (&mysql_res)) != 0)
|
||||
if ((Test->Tags.Num = Tag_DB_GetEnabledTagsFromThisCrs (&mysql_res)) != 0)
|
||||
{
|
||||
/***** Check if minimum date-time of next access to test is older than now *****/
|
||||
if (Tst_CheckIfNextTstAllowed ())
|
||||
|
@ -1013,7 +1014,7 @@ static void Tst_ShowFormRequestEditTests (struct Tst_Test *Test)
|
|||
Hlp_ASSESSMENT_Questions_editing_questions,Box_NOT_CLOSABLE);
|
||||
|
||||
/***** Get tags already present in the table of questions *****/
|
||||
if ((Test->Tags.Num = Tag_GetAllTagsFromCurrentCrs (&mysql_res)))
|
||||
if ((Test->Tags.Num = Tag_DB_GetAllTagsFromCurrentCrs (&mysql_res)))
|
||||
{
|
||||
Frm_BeginForm (ActLstTstQst);
|
||||
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Tst_DEFAULT_ORDER);
|
||||
|
@ -1111,7 +1112,7 @@ static void Tst_ShowFormRequestSelectTestsForSet (struct Exa_Exams *Exams,
|
|||
Hlp_ASSESSMENT_Exams_questions,Box_NOT_CLOSABLE);
|
||||
|
||||
/***** Get tags already present in the table of questions *****/
|
||||
if ((Test->Tags.Num = Tag_GetAllTagsFromCurrentCrs (&mysql_res)))
|
||||
if ((Test->Tags.Num = Tag_DB_GetAllTagsFromCurrentCrs (&mysql_res)))
|
||||
{
|
||||
Frm_BeginForm (ActLstTstQstForSet);
|
||||
ExaSet_PutParamsOneSet (Exams);
|
||||
|
@ -1173,7 +1174,7 @@ static void Tst_ShowFormRequestSelectTestsForGame (struct Gam_Games *Games,
|
|||
Hlp_ASSESSMENT_Games_questions,Box_NOT_CLOSABLE);
|
||||
|
||||
/***** Get tags already present in the table of questions *****/
|
||||
if ((Test->Tags.Num = Tag_GetAllTagsFromCurrentCrs (&mysql_res)))
|
||||
if ((Test->Tags.Num = Tag_DB_GetAllTagsFromCurrentCrs (&mysql_res)))
|
||||
{
|
||||
Frm_BeginForm (ActGamLstTstQst);
|
||||
Gam_PutParams (Games);
|
||||
|
@ -1391,7 +1392,7 @@ bool Tst_CheckIfCourseHaveTestsAndPluggableIsUnknown (void)
|
|||
|
||||
/***** Get if current course has tests from database *****/
|
||||
if (TstCfg_GetConfigPluggable () == TstCfg_PLUGGABLE_UNKNOWN)
|
||||
return Tag_CheckIfCurrentCrsHasTestTags (); // Return true if course has tests
|
||||
return Tag_DB_CheckIfCurrentCrsHasTestTags (); // Return true if course has tests
|
||||
|
||||
return false; // Pluggable is not unknown
|
||||
}
|
||||
|
@ -3262,7 +3263,7 @@ static void Tst_PutFormEditOneQst (struct Tst_Question *Question)
|
|||
HTM_TR_End ();
|
||||
|
||||
/***** Get tags already existing for questions in current course *****/
|
||||
NumTags = Tag_GetAllTagsFromCurrentCrs (&mysql_res);
|
||||
NumTags = Tag_DB_GetAllTagsFromCurrentCrs (&mysql_res);
|
||||
|
||||
/***** Write the tags *****/
|
||||
HTM_TR_Begin (NULL);
|
||||
|
@ -4852,8 +4853,8 @@ static void Tst_RemoveOneQstFromDB (long CrsCod,long QstCod)
|
|||
/***** Remove the question from all the tables *****/
|
||||
/* Remove answers and tags from this test question */
|
||||
Tst_RemAnsFromQst (QstCod);
|
||||
Tag_RemTagsFromQst (QstCod);
|
||||
Tag_RemoveUnusedTagsFromCrs (CrsCod);
|
||||
Tag_DB_RemTagsFromQst (QstCod);
|
||||
Tag_DB_RemoveUnusedTagsFromCrs (CrsCod);
|
||||
|
||||
/* Remove the question itself */
|
||||
DB_QueryDELETE ("can not remove a question",
|
||||
|
@ -4953,7 +4954,7 @@ void Tst_InsertOrUpdateQstTagsAnsIntoDB (struct Tst_Question *Question)
|
|||
Tag_InsertTagsIntoDB (Question->QstCod,&Question->Tags);
|
||||
|
||||
/***** Remove unused tags in current course *****/
|
||||
Tag_RemoveUnusedTagsFromCrs (Gbl.Hierarchy.Crs.CrsCod);
|
||||
Tag_DB_RemoveUnusedTagsFromCrs (Gbl.Hierarchy.Crs.CrsCod);
|
||||
|
||||
/***** Insert answers in the answers table *****/
|
||||
Tst_InsertAnswersIntoDB (Question);
|
||||
|
@ -5026,7 +5027,7 @@ static void Tst_InsertOrUpdateQstIntoDB (struct Tst_Question *Question)
|
|||
|
||||
/* Remove answers and tags from this test question */
|
||||
Tst_RemAnsFromQst (Question->QstCod);
|
||||
Tag_RemTagsFromQst (Question->QstCod);
|
||||
Tag_DB_RemTagsFromQst (Question->QstCod);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue