Version 21.30: Oct 12, 2021 New module swad_record_database for database queries related to records.

This commit is contained in:
acanas 2021-10-12 22:13:16 +02:00
parent b8644f7c2b
commit fa8ea3bf3b
13 changed files with 413 additions and 179 deletions

View File

@ -75,7 +75,8 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
swad_privacy.o swad_profile.o swad_profile_database.o swad_program.o \
swad_program_database.o swad_project.o swad_project_database.o \
swad_QR.o \
swad_record.o swad_report.o swad_role.o swad_room.o swad_RSS.o \
swad_record.o swad_record_database.o swad_report.o swad_role.o \
swad_room.o swad_RSS.o \
swad_scope.o swad_search.o swad_session.o swad_setting.o \
swad_statistic.o swad_string.o swad_survey.o swad_syllabus.o \
swad_system_config.o \

View File

@ -117,13 +117,13 @@ void QR_ImageQRCode (const char *QRString)
HTM_DIV_Begin ("class=\"CM\" style=\"margin:0 auto; width:%upx;\"",
QR_CODE_SIZE);
if (asprintf (&URL,"https://chart.googleapis.com/chart?cht=qr&chs=%ux%u&chl=%s",
QR_CODE_SIZE,QR_CODE_SIZE,QRString) < 0)
Err_NotEnoughMemoryExit ();
HTM_IMG (URL,NULL,QRString,
"style=\"width:%upx;height:%upx;border:1px dashed silver;\"",
QR_CODE_SIZE,QR_CODE_SIZE);
free (URL);
if (asprintf (&URL,"https://chart.googleapis.com/chart?cht=qr&amp;chs=%ux%u&amp;chl=%s",
QR_CODE_SIZE,QR_CODE_SIZE,QRString) < 0)
Err_NotEnoughMemoryExit ();
HTM_IMG (URL,NULL,QRString,
"style=\"width:%upx;height:%upx;border:1px dashed silver;\"",
QR_CODE_SIZE,QR_CODE_SIZE);
free (URL);
HTM_DIV_End ();
}
@ -167,14 +167,14 @@ void QR_ExamAnnnouncement (void)
/***** Show QR code with direct link to the exam announcement *****/
HTM_DIV_Begin ("class=\"CM\"");
if (asprintf (&URL,"https://chart.googleapis.com/chart?cht=qr&amp;chs=%ux%u&amp;chl=%s/?crs=%ld%%26act=%ld",
300,300,
Cfg_URL_SWAD_CGI,Gbl.Hierarchy.Crs.CrsCod,
Act_GetActCod (ActSeeAllExaAnn)) < 0)
Err_NotEnoughMemoryExit ();
HTM_IMG (URL,NULL,Txt_Link_to_call_for_exam,
"style=\"width:250px;height:250px;\"");
free (URL);
if (asprintf (&URL,"https://chart.googleapis.com/chart?cht=qr&amp;chs=%ux%u&amp;chl=%s/?crs=%ld%%26act=%ld",
300,300,
Cfg_URL_SWAD_CGI,Gbl.Hierarchy.Crs.CrsCod,
Act_GetActCod (ActSeeAllExaAnn)) < 0)
Err_NotEnoughMemoryExit ();
HTM_IMG (URL,NULL,Txt_Link_to_call_for_exam,
"style=\"width:250px;height:250px;\"");
free (URL);
HTM_DIV_End ();
}

View File

@ -64,6 +64,7 @@
#include "swad_profile.h"
#include "swad_profile_database.h"
#include "swad_project.h"
#include "swad_record_database.h"
#include "swad_report.h"
#include "swad_setting.h"
#include "swad_test_print.h"

View File

@ -602,14 +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.29 (2021-10-11)"
#define Log_PLATFORM_VERSION "SWAD 21.30 (2021-10-12)"
#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.29: Oct 11, 2021 New module swad_peoject_database for database queries related to projects. (319208 lines)
Version 21.30: Oct 12, 2021 New module swad_record_database for database queries related to records. (319400 lines)
Version 21.29: Oct 11, 2021 New module swad_project_database for database queries related to projects. (319208 lines)
Version 21.28.1: Oct 10, 2021 Code refactoring in projects. (318975 lines)
Version 21.28: Oct 09, 2021 New module swad_program_database for database queries related to course program. (319013 lines)
Version 21.27.1: Oct 07, 2021 Queries moved to module swad_profile_database. (318855 lines)

View File

@ -57,6 +57,7 @@
#include "swad_notice_database.h"
#include "swad_notification_database.h"
#include "swad_project.h"
#include "swad_record_database.h"
#include "swad_search.h"
#include "swad_setting.h"
#include "swad_survey.h"

View File

@ -57,6 +57,7 @@
#include "swad_notification_database.h"
#include "swad_parameter.h"
#include "swad_photo.h"
#include "swad_record_database.h"
#include "swad_role.h"
#include "swad_setting.h"
#include "swad_test_print.h"
@ -3224,7 +3225,7 @@ static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat,
}
/***** Remove fields of this user in its course record *****/
Rec_DB_RemoveFieldsCrsRecordInCrs (UsrDat->UsrCod,Crs);
Rec_DB_RemoveFieldsCrsRecordInCrs (UsrDat->UsrCod,Crs->CrsCod);
/***** Remove some information about files in course and groups *****/
Brw_DB_RemoveSomeInfoAboutCrsUsrFiles (UsrDat->UsrCod,Crs->CrsCod);

View File

@ -3622,8 +3622,6 @@ void Prj_ReceiveFormProject (void)
static void Prj_CreateProject (struct Prj_Project *Prj)
{
extern const char *Prj_Proposal_DB[Prj_NUM_PROPOSAL_TYPES];
/***** Set dates to now *****/
Prj->CreatTime =
Prj->ModifTime = Gbl.StartExecutionTimeUTC;
@ -3644,8 +3642,6 @@ static void Prj_CreateProject (struct Prj_Project *Prj)
static void Prj_UpdateProject (struct Prj_Project *Prj)
{
extern const char *Prj_Proposal_DB[Prj_NUM_PROPOSAL_TYPES];
/***** Adjust date of last edition to now *****/
Prj->ModifTime = Gbl.StartExecutionTimeUTC;

View File

@ -56,6 +56,7 @@
#include "swad_privacy.h"
#include "swad_QR.h"
#include "swad_record.h"
#include "swad_record_database.h"
#include "swad_role.h"
#include "swad_setting.h"
#include "swad_timetable.h"
@ -690,14 +691,7 @@ static void Rec_GetFieldByCod (long FieldCod,char Name[Rec_MAX_BYTES_NAME_FIELD
unsigned Vis;
/***** Get a field of a record in a course from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get a field of a record in a course",
"SELECT FieldName," // row[0]
"NumLines," // row[1]
"Visibility" // row[2]
" FROM crs_record_fields"
" WHERE CrsCod=%ld"
" AND FieldCod=%ld",
Gbl.Hierarchy.Crs.CrsCod,FieldCod) != 1)
if (Rec_DB_GetFieldByCod (&mysql_res,Gbl.Hierarchy.Crs.CrsCod,FieldCod) != 1)
Err_WrongRecordFieldExit ();
/***** Get the field *****/
@ -772,12 +766,7 @@ void Rec_RenameField (void)
else
{
/* Update the table of fields changing then old name by the new one */
DB_QueryUPDATE ("can not update name of field of record",
"UPDATE crs_record_fields"
" SET FieldName='%s'"
" WHERE FieldCod=%ld",
NewFieldName,
Gbl.Crs.Records.Field.FieldCod);
Rec_DB_UpdateCrsRecordFieldName (Gbl.Crs.Records.Field.FieldCod,NewFieldName);
/***** Write message to show the change made *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_The_record_field_X_has_been_renamed_as_Y,
@ -829,13 +818,8 @@ void Rec_ChangeLinesField (void)
Gbl.Crs.Records.Field.Name);
else
{
/***** Update of the table of fields changing the old maximum of students by the new one *****/
DB_QueryUPDATE ("can not update the number of lines of a record field",
"UPDATE crs_record_fields"
" SET NumLines=%u"
" WHERE FieldCod=%ld",
NewNumLines,
Gbl.Crs.Records.Field.FieldCod);
/***** Update of the table of fields changing the old number of lines by the new one *****/
Rec_DB_UpdateCrsRecordFieldNumLines (Gbl.Crs.Records.Field.FieldCod,NewNumLines);
/***** Write message to show the change made *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_From_now_on_the_number_of_editing_lines_of_the_field_X_is_Y,
@ -879,13 +863,8 @@ void Rec_ChangeVisibilityField (void)
Gbl.Crs.Records.Field.Name);
else
{
/***** Update of the table of fields changing the old visibility by the new *****/
DB_QueryUPDATE ("can not update the visibility of a record field",
"UPDATE crs_record_fields"
" SET Visibility=%u"
" WHERE FieldCod=%ld",
(unsigned) NewVisibility,
Gbl.Crs.Records.Field.FieldCod);
/***** Update the table of fields changing the old visibility by the new *****/
Rec_DB_UpdateCrsRecordFieldVisibility (Gbl.Crs.Records.Field.FieldCod,NewVisibility);
/***** Write message to show the change made *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_RECORD_FIELD_VISIBILITY_MSG[NewVisibility],
@ -1812,8 +1791,9 @@ static void Rec_ShowCrsRecord (Rec_CourseRecordViewType_t TypeOfView,
HTM_TD_End ();
/* Get the text of the field */
if (Rec_DB_GetFieldFromCrsRecord (&mysql_res,UsrDat->UsrCod,
Gbl.Crs.Records.LstFields.Lst[NumField].FieldCod))
if (Rec_DB_GetFieldFromCrsRecord (&mysql_res,
Gbl.Crs.Records.LstFields.Lst[NumField].FieldCod,
UsrDat->UsrCod))
{
ThisFieldHasText = true;
row = mysql_fetch_row (mysql_res);
@ -1869,22 +1849,6 @@ static void Rec_ShowCrsRecord (Rec_CourseRecordViewType_t TypeOfView,
Box_BoxTableEnd ();
}
/*****************************************************************************/
/************** Get the text of a field of a record of course ****************/
/*****************************************************************************/
unsigned Rec_DB_GetFieldFromCrsRecord (MYSQL_RES **mysql_res,long UsrCod,long FieldCod)
{
return DB_QuerySELECT (mysql_res,"can not get the text"
" of a field of a record",
"SELECT Txt" // row[0]
" FROM crs_records"
" WHERE FieldCod=%ld"
" AND UsrCod=%ld",
FieldCod,
UsrCod);
}
/*****************************************************************************/
/****************** Get the fields of the record from form *******************/
/*****************************************************************************/
@ -1922,71 +1886,30 @@ void Rec_UpdateCrsRecord (long UsrCod)
if (Rec_CheckIfICanEditField (Gbl.Crs.Records.LstFields.Lst[NumField].Visibility))
{
/***** Check if already exists this field for this user in database *****/
FieldAlreadyExists = (Rec_DB_GetFieldFromCrsRecord (&mysql_res,UsrCod,
Gbl.Crs.Records.LstFields.Lst[NumField].FieldCod) != 0);
FieldAlreadyExists = (Rec_DB_GetFieldFromCrsRecord (&mysql_res,
Gbl.Crs.Records.LstFields.Lst[NumField].FieldCod,
UsrCod) != 0);
DB_FreeMySQLResult (&mysql_res);
if (FieldAlreadyExists)
{
if (Gbl.Crs.Records.LstFields.Lst[NumField].Text[0])
/***** Update text of the field of record course *****/
DB_QueryUPDATE ("can not update field of record",
"UPDATE crs_records"
" SET Txt='%s'"
" WHERE UsrCod=%ld"
" AND FieldCod=%ld",
Gbl.Crs.Records.LstFields.Lst[NumField].Text,
UsrCod,
Gbl.Crs.Records.LstFields.Lst[NumField].FieldCod);
/***** Update text of the field of course record *****/
Rec_DB_UpdateCrsRecordField (Gbl.Crs.Records.LstFields.Lst[NumField].FieldCod,
UsrCod,
Gbl.Crs.Records.LstFields.Lst[NumField].Text);
else
/***** Remove text of the field of record course *****/
DB_QueryDELETE ("can not remove field of record",
"DELETE FROM crs_records"
" WHERE UsrCod=%ld"
" AND FieldCod=%ld",
UsrCod,
Gbl.Crs.Records.LstFields.Lst[NumField].FieldCod);
/***** Remove text of the field of course record *****/
Rec_DB_RemoveCrsRecordField (Gbl.Crs.Records.LstFields.Lst[NumField].FieldCod,
UsrCod);
}
else if (Gbl.Crs.Records.LstFields.Lst[NumField].Text[0])
/***** Insert text field of record course *****/
DB_QueryINSERT ("can not create field of record",
"INSERT INTO crs_records"
" (FieldCod,UsrCod,Txt)"
" VALUES"
" (%ld,%ld,'%s')",
Gbl.Crs.Records.LstFields.Lst[NumField].FieldCod,
UsrCod,
Gbl.Crs.Records.LstFields.Lst[NumField].Text);
/***** Insert text field of course record *****/
Rec_DB_CreateCrsRecordField (Gbl.Crs.Records.LstFields.Lst[NumField].FieldCod,
UsrCod,
Gbl.Crs.Records.LstFields.Lst[NumField].Text);
}
}
/*****************************************************************************/
/************ Remove fields of record of a user in current course ************/
/*****************************************************************************/
void Rec_DB_RemoveFieldsCrsRecordInCrs (long UsrCod,struct Crs_Course *Crs)
{
DB_QueryDELETE ("can not remove user's record in a course",
"DELETE FROM crs_records"
" WHERE UsrCod=%ld"
" AND FieldCod IN"
" (SELECT FieldCod"
" FROM crs_record_fields"
" WHERE CrsCod=%ld)",
UsrCod,Crs->CrsCod);
}
/*****************************************************************************/
/************* Remove fields of record of a user in all courses **************/
/*****************************************************************************/
void Rec_DB_RemoveFieldsCrsRecordAll (long UsrCod)
{
DB_QueryDELETE ("can not remove user's records in all courses",
"DELETE FROM crs_records"
" WHERE UsrCod=%ld",
UsrCod);
}
/*****************************************************************************/
/*************** Show my record in the course already updated ****************/
/*****************************************************************************/
@ -2622,8 +2545,8 @@ static void Rec_PutIconsCommands (__attribute__((unused)) void *Args)
Rec_PutParamUsrCodEncrypted,NULL);
/***** Button to send a message *****/
RecipientHasBannedMe = Msg_DB_CheckIfUsrIsBanned (Gbl.Usrs.Me.UsrDat.UsrCod, // From:
Gbl.Record.UsrDat->UsrCod); // To:
RecipientHasBannedMe = Msg_DB_CheckIfUsrIsBanned (Gbl.Usrs.Me.UsrDat.UsrCod, // From:
Gbl.Record.UsrDat->UsrCod); // To:
if (!RecipientHasBannedMe)
Lay_PutContextualLinkOnlyIcon (ActReqMsgUsr,NULL,
Rec_PutParamsMsgUsr,NULL,
@ -2936,12 +2859,12 @@ static void Rec_ShowRole (struct UsrData *UsrDat,
HTM_TD_Begin ("class=\"REC_C2_BOT DAT_N LM\"");
switch (TypeOfView)
{
case Rec_SHA_SIGN_UP_IN_CRS_FORM: // I want to apply for enrolment
case Rec_SHA_SIGN_UP_IN_CRS_FORM: // I want to apply for enrolment
/***** Set default role *****/
if (UsrDat->UsrCod == Gbl.Hierarchy.Crs.RequesterUsrCod || // Creator of the course
(UsrDat->Roles.InCrss & (1 << Rol_TCH))) // Teacher in other courses
(UsrDat->Roles.InCrss & (1 << Rol_TCH))) // Teacher in other courses
DefaultRoleInForm = Rol_TCH; // Request sign up as a teacher
else if ((UsrDat->Roles.InCrss & (1 << Rol_NET))) // Non-editing teacher in other courses
else if ((UsrDat->Roles.InCrss & (1 << Rol_NET))) // Non-editing teacher in other courses
DefaultRoleInForm = Rol_NET; // Request sign up as a non-editing teacher
else
DefaultRoleInForm = Rol_STD; // Request sign up as a student
@ -2960,7 +2883,7 @@ static void Rec_ShowRole (struct UsrData *UsrDat,
}
HTM_SELECT_End ();
break;
case Rec_SHA_OTHER_EXISTING_USR_FORM: // The other user already exists in the platform
case Rec_SHA_OTHER_EXISTING_USR_FORM: // The other user already exists in the platform
if (Gbl.Hierarchy.Level == HieLvl_CRS) // Course selected
{
/***** Set default role *****/
@ -3046,7 +2969,7 @@ static void Rec_ShowRole (struct UsrData *UsrDat,
DefaultRoleInForm = (UsrDat->Roles.InCrss & ((1 << Rol_STD) |
(1 << Rol_NET) |
(1 << Rol_TCH))) ? Rol_USR : // If user belongs to any course
Rol_GST; // If user don't belong to any course
Rol_GST; // If user don't belong to any course
/***** Selector of role *****/
HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE,
@ -3597,7 +3520,7 @@ static void Rec_ShowOffice (struct UsrData *UsrDat,bool ShowData)
}
/*****************************************************************************/
/*************************** Show user's office phone ******************************/
/************************ Show user's office phone ***************************/
/*****************************************************************************/
static void Rec_ShowOfficePhone (struct UsrData *UsrDat,bool ShowData)
@ -4209,12 +4132,7 @@ void Rec_UpdateMyOffice (void)
Par_GetParToText ("Office",Gbl.Usrs.Me.UsrDat.Tch.Office,Usr_MAX_BYTES_ADDRESS);
/***** Update office *****/
DB_QueryUPDATE ("can not update office",
"UPDATE usr_data"
" SET Office='%s'"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.Tch.Office,
Gbl.Usrs.Me.UsrDat.UsrCod);
Usr_DB_UpdateMyOffice ();
/***** Show form again *****/
Rec_ShowMySharedRecordAndMore ();
@ -4230,40 +4148,8 @@ void Rec_UpdateMyOfficePhone (void)
Par_GetParToText ("OfficePhone",Gbl.Usrs.Me.UsrDat.Tch.OfficePhone,Usr_MAX_BYTES_PHONE);
/***** Update office phone *****/
DB_QueryUPDATE ("can not update office phone",
"UPDATE usr_data"
" SET OfficePhone='%s'"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.Tch.OfficePhone,
Gbl.Usrs.Me.UsrDat.UsrCod);
Usr_DB_UpdateMyOfficePhone ();
/***** Show form again *****/
Rec_ShowMySharedRecordAndMore ();
}
/*****************************************************************************/
/******************** Remove content of course record cards ******************/
/*****************************************************************************/
void Rec_DB_RemoveCrsRecordContents (long CrsCod)
{
DB_QueryDELETE ("can not remove content of cards in a course",
"DELETE FROM crs_records"
" USING crs_record_fields,"
"crs_records"
" WHERE crs_record_fields.CrsCod=%ld"
" AND crs_record_fields.FieldCod=crs_records.FieldCod",
CrsCod);
}
/*****************************************************************************/
/************ Remove definition of fields in course record cards *************/
/*****************************************************************************/
void Rec_DB_RemoveCrsRecordFields (long CrsCod)
{
DB_QueryDELETE ("can not remove fields of cards in a course",
"DELETE FROM crs_record_fields"
" WHERE CrsCod=%ld",
CrsCod);
}

View File

@ -150,11 +150,8 @@ void Rec_ListRecordsTchsPrint (void);
void Rec_UpdateAndShowMyCrsRecord (void);
void Rec_UpdateAndShowOtherCrsRecord (void);
unsigned Rec_DB_GetFieldFromCrsRecord (MYSQL_RES **mysql_res,long UsrCod,long FieldCod);
void Rec_GetFieldsCrsRecordFromForm (void);
void Rec_UpdateCrsRecord (long UsrCod);
void Rec_DB_RemoveFieldsCrsRecordInCrs (long UsrCod,struct Crs_Course *Crs);
void Rec_DB_RemoveFieldsCrsRecordAll (long UsrCod);
void Rec_AllocMemFieldsRecordsCrs (void);
void Rec_FreeMemFieldsRecordsCrs (void);
@ -180,7 +177,4 @@ void Rec_UpdateMyDepartment (void);
void Rec_UpdateMyOffice (void);
void Rec_UpdateMyOfficePhone (void);
void Rec_DB_RemoveCrsRecordContents (long CrsCod);
void Rec_DB_RemoveCrsRecordFields (long CrsCod);
#endif

257
swad_record_database.c Normal file
View File

@ -0,0 +1,257 @@
// swad_record_database.c: users' record cards, 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 ***********************************/
/*****************************************************************************/
// #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 calloc
// #include <string.h>
// #include "swad_account.h"
// #include "swad_account_database.h"
// #include "swad_action.h"
// #include "swad_box.h"
// #include "swad_config.h"
#include "swad_database.h"
// #include "swad_department.h"
// #include "swad_enrolment_database.h"
// #include "swad_error.h"
// #include "swad_follow_database.h"
// #include "swad_form.h"
// #include "swad_global.h"
// #include "swad_hierarchy_level.h"
// #include "swad_HTML.h"
// #include "swad_ID.h"
// #include "swad_logo.h"
// #include "swad_message.h"
// #include "swad_message_database.h"
// #include "swad_network.h"
// #include "swad_parameter.h"
// #include "swad_photo.h"
// #include "swad_privacy.h"
// #include "swad_QR.h"
// #include "swad_record.h"
#include "swad_record_database.h"
// #include "swad_role.h"
// #include "swad_setting.h"
// #include "swad_timetable.h"
// #include "swad_user.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
// extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
/*****************************************************************************/
/********************* Insert text field of course record ********************/
/*****************************************************************************/
void Rec_DB_CreateCrsRecordField (long FieldCod,long UsrCod,const char *Text)
{
DB_QueryINSERT ("can not create field of record",
"INSERT INTO crs_records"
" (FieldCod,UsrCod,Txt)"
" VALUES"
" (%ld,%ld,'%s')",
FieldCod,
UsrCod,
Text);
}
/*****************************************************************************/
/********************* Update text field of course record ********************/
/*****************************************************************************/
void Rec_DB_UpdateCrsRecordField (long FieldCod,long UsrCod,const char *Text)
{
DB_QueryUPDATE ("can not update field of record",
"UPDATE crs_records"
" SET Txt='%s'"
" WHERE UsrCod=%ld"
" AND FieldCod=%ld",
Text,
UsrCod,
FieldCod);
}
/*****************************************************************************/
/******** Update course record field changing the old name by the new ********/
/*****************************************************************************/
void Rec_DB_UpdateCrsRecordFieldName (long FieldCod,const char NewFieldName[Rec_MAX_BYTES_NAME_FIELD + 1])
{
DB_QueryUPDATE ("can not update name of field of record",
"UPDATE crs_record_fields"
" SET FieldName='%s'"
" WHERE FieldCod=%ld",
NewFieldName,
FieldCod);
}
/*****************************************************************************/
/*** Update course record field changing the old number of lines by the new **/
/*****************************************************************************/
void Rec_DB_UpdateCrsRecordFieldNumLines (long FieldCod,unsigned NewNumLines)
{
DB_QueryUPDATE ("can not update the number of lines of a record field",
"UPDATE crs_record_fields"
" SET NumLines=%u"
" WHERE FieldCod=%ld",
NewNumLines,
FieldCod);
}
/*****************************************************************************/
/***** Update course record field changing the old visibility by the new *****/
/*****************************************************************************/
void Rec_DB_UpdateCrsRecordFieldVisibility (long FieldCod,Rec_VisibilityRecordFields_t NewVisibility)
{
DB_QueryUPDATE ("can not update the visibility of a record field",
"UPDATE crs_record_fields"
" SET Visibility=%u"
" WHERE FieldCod=%ld",
(unsigned) NewVisibility,
FieldCod);
}
/*****************************************************************************/
/************** Get the data of a field of records from its code *************/
/*****************************************************************************/
unsigned Rec_DB_GetFieldByCod (MYSQL_RES **mysql_res,long CrsCod,long FieldCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get a field of a record in a course",
"SELECT FieldName," // row[0]
"NumLines," // row[1]
"Visibility" // row[2]
" FROM crs_record_fields"
" WHERE CrsCod=%ld"
" AND FieldCod=%ld",
CrsCod,
FieldCod);
}
/*****************************************************************************/
/************** Get the text of a field of a record of course ****************/
/*****************************************************************************/
unsigned Rec_DB_GetFieldFromCrsRecord (MYSQL_RES **mysql_res,
long FieldCod,long UsrCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get the text"
" of a field of a record",
"SELECT Txt" // row[0]
" FROM crs_records"
" WHERE FieldCod=%ld"
" AND UsrCod=%ld",
FieldCod,
UsrCod);
}
/*****************************************************************************/
/******************* Remove text of field of course record *******************/
/*****************************************************************************/
void Rec_DB_RemoveCrsRecordField (long FieldCod,long UsrCod)
{
DB_QueryDELETE ("can not remove field of record",
"DELETE FROM crs_records"
" WHERE UsrCod=%ld"
" AND FieldCod=%ld",
UsrCod,
FieldCod);
}
/*****************************************************************************/
/************ Remove fields of record of a user in current course ************/
/*****************************************************************************/
void Rec_DB_RemoveFieldsCrsRecordInCrs (long UsrCod,long CrsCod)
{
DB_QueryDELETE ("can not remove user's record in a course",
"DELETE FROM crs_records"
" WHERE UsrCod=%ld"
" AND FieldCod IN"
" (SELECT FieldCod"
" FROM crs_record_fields"
" WHERE CrsCod=%ld)",
UsrCod,
CrsCod);
}
/*****************************************************************************/
/************* Remove fields of record of a user in all courses **************/
/*****************************************************************************/
void Rec_DB_RemoveFieldsCrsRecordAll (long UsrCod)
{
DB_QueryDELETE ("can not remove user's records in all courses",
"DELETE FROM crs_records"
" WHERE UsrCod=%ld",
UsrCod);
}
/*****************************************************************************/
/******************** Remove content of course record cards ******************/
/*****************************************************************************/
void Rec_DB_RemoveCrsRecordContents (long CrsCod)
{
DB_QueryDELETE ("can not remove content of cards in a course",
"DELETE FROM crs_records"
" USING crs_record_fields,"
"crs_records"
" WHERE crs_record_fields.CrsCod=%ld"
" AND crs_record_fields.FieldCod=crs_records.FieldCod",
CrsCod);
}
/*****************************************************************************/
/************ Remove definition of fields in course record cards *************/
/*****************************************************************************/
void Rec_DB_RemoveCrsRecordFields (long CrsCod)
{
DB_QueryDELETE ("can not remove fields of cards in a course",
"DELETE FROM crs_record_fields"
" WHERE CrsCod=%ld",
CrsCod);
}

63
swad_record_database.h Normal file
View File

@ -0,0 +1,63 @@
// swad_record_database.h: users' record cards, operations with database
#ifndef _SWAD_REC_DB
#define _SWAD_REC_DB
/*
SWAD (Shared Workspace At a Distance in Spanish),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
Copyright (C) 1999-2021 Antonio Cañas Vargas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
// #include <mysql/mysql.h> // To access MySQL databases
#include "swad_record.h"
// #include "swad_user.h"
/*****************************************************************************/
/***************************** Public constants ******************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Public types ********************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Public prototypes *****************************/
/*****************************************************************************/
void Rec_DB_CreateCrsRecordField (long FieldCod,long UsrCod,const char *Text);
void Rec_DB_UpdateCrsRecordField (long FieldCod,long UsrCod,const char *Text);
void Rec_DB_UpdateCrsRecordFieldName (long FieldCod,const char NewFieldName[Rec_MAX_BYTES_NAME_FIELD + 1]);
void Rec_DB_UpdateCrsRecordFieldNumLines (long FieldCod,unsigned NewNumLines);
void Rec_DB_UpdateCrsRecordFieldVisibility (long FieldCod,Rec_VisibilityRecordFields_t NewVisibility);
unsigned Rec_DB_GetFieldByCod (MYSQL_RES **mysql_res,long CrsCod,long FieldCod);
unsigned Rec_DB_GetFieldFromCrsRecord (MYSQL_RES **mysql_res,
long FieldCod,long UsrCod);
void Rec_DB_RemoveCrsRecordField (long FieldCod,long UsrCod);
void Rec_DB_RemoveFieldsCrsRecordInCrs (long UsrCod,long CrsCod);
void Rec_DB_RemoveFieldsCrsRecordAll (long UsrCod);
void Rec_DB_RemoveCrsRecordContents (long CrsCod);
void Rec_DB_RemoveCrsRecordFields (long CrsCod);
#endif

View File

@ -73,6 +73,7 @@
#include "swad_privacy.h"
#include "swad_QR.h"
#include "swad_record.h"
#include "swad_record_database.h"
#include "swad_role.h"
#include "swad_setting.h"
#include "swad_tab.h"
@ -3914,8 +3915,9 @@ static void Usr_WriteRowStdAllData (struct UsrData *UsrDat,char *GroupNames)
NumField++)
{
/* Get the text of the field */
if (Rec_DB_GetFieldFromCrsRecord (&mysql_res,UsrDat->UsrCod,
Gbl.Crs.Records.LstFields.Lst[NumField].FieldCod))
if (Rec_DB_GetFieldFromCrsRecord (&mysql_res,
Gbl.Crs.Records.LstFields.Lst[NumField].FieldCod,
UsrDat->UsrCod))
{
row = mysql_fetch_row (mysql_res);
Str_Copy (Text,row[0],sizeof (Text) - 1);
@ -10506,3 +10508,31 @@ bool Usr_DB_FindStrInUsrsNames (const char *Str)
Str,
Str) != 0);
}
/*****************************************************************************/
/******************************* Update my office ****************************/
/*****************************************************************************/
void Usr_DB_UpdateMyOffice (void)
{
DB_QueryUPDATE ("can not update office",
"UPDATE usr_data"
" SET Office='%s'"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.Tch.Office,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
/***************************** Update my office phone ************************/
/*****************************************************************************/
void Usr_DB_UpdateMyOfficePhone (void)
{
DB_QueryUPDATE ("can not update office phone",
"UPDATE usr_data"
" SET OfficePhone='%s'"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.Tch.OfficePhone,
Gbl.Usrs.Me.UsrDat.UsrCod);
}

View File

@ -558,4 +558,7 @@ unsigned Usr_DB_GetNumUsrsWhoChoseAnOption (const char *SubQuery);
bool Usr_DB_FindStrInUsrsNames (const char *Str);
void Usr_DB_UpdateMyOffice (void);
void Usr_DB_UpdateMyOfficePhone (void);
#endif