diff --git a/swad_agenda.c b/swad_agenda.c index 8e47ebe8..9897a11f 100644 --- a/swad_agenda.c +++ b/swad_agenda.c @@ -1269,8 +1269,8 @@ void Agd_HideEvent (void) AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod; Agd_GetDataOfEventByCod (&AgdEvent); - /***** Set event private *****/ - Agd_DB_HideEvent (&AgdEvent); + /***** Hide event *****/ + Agd_DB_HideOrUnhideEvent (AgdEvent.AgdCod,AgdEvent.UsrCod,true); /***** Show events again *****/ Agd_ShowMyAgenda (&Agenda); @@ -1299,8 +1299,8 @@ void Agd_UnhideEvent (void) AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod; Agd_GetDataOfEventByCod (&AgdEvent); - /***** Set event public *****/ - Agd_DB_UnhideEvent (&AgdEvent); + /***** Unhide event *****/ + Agd_DB_HideOrUnhideEvent (AgdEvent.AgdCod,AgdEvent.UsrCod,false); /***** Show events again *****/ Agd_ShowMyAgenda (&Agenda); diff --git a/swad_agenda_database.c b/swad_agenda_database.c index 84db168e..4436beb2 100644 --- a/swad_agenda_database.c +++ b/swad_agenda_database.c @@ -289,29 +289,20 @@ void Agd_DB_UpdateEvent (const struct Agd_Event *AgdEvent,const char *Txt) } /*****************************************************************************/ -/**************** Set an existing event as hidden/not hidden *****************/ +/*************************** Hide/unhide an event ****************************/ /*****************************************************************************/ -void Agd_DB_HideEvent (const struct Agd_Event *AgdEvent) +void Agd_DB_HideOrUnhideEvent (long AgdCod,long UsrCod,bool Hide) { - DB_QueryUPDATE ("can not hide event", + DB_QueryUPDATE ("can not hide/unhide event", "UPDATE agd_agendas" - " SET Hidden='Y'" + " SET Hidden='%c'" " WHERE AgdCod=%ld" " AND UsrCod=%ld", - AgdEvent->AgdCod, - AgdEvent->UsrCod); - } - -void Agd_DB_UnhideEvent (const struct Agd_Event *AgdEvent) - { - DB_QueryUPDATE ("can not unhide event", - "UPDATE agd_agendas" - " SET Hidden='N'" - " WHERE AgdCod=%ld" - " AND UsrCod=%ld", - AgdEvent->AgdCod, - AgdEvent->UsrCod); + Hide ? 'Y' : + 'N', + AgdCod, + UsrCod); } /*****************************************************************************/ diff --git a/swad_agenda_database.h b/swad_agenda_database.h index 33a14c3d..2975b517 100644 --- a/swad_agenda_database.h +++ b/swad_agenda_database.h @@ -52,8 +52,7 @@ void Agd_DB_RemoveEvent (const struct Agd_Event *AgdEvent); long Agd_DB_CreateEvent (const struct Agd_Event *AgdEvent,const char *Txt); void Agd_DB_UpdateEvent (const struct Agd_Event *AgdEvent,const char *Txt); -void Agd_DB_HideEvent (const struct Agd_Event *AgdEvent); -void Agd_DB_UnhideEvent (const struct Agd_Event *AgdEvent); +void Agd_DB_HideOrUnhideEvent (long AgdCod,long UsrCod,bool Hide); void Agd_DB_MakeEventPublic (const struct Agd_Event *AgdEvent); void Agd_DB_MakeEventPrivate (const struct Agd_Event *AgdEvent); diff --git a/swad_assignment.c b/swad_assignment.c index 8e9a79c4..c0a8e398 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -1029,7 +1029,7 @@ void Asg_HideAssignment (void) Asg_GetDataOfAssignmentByCod (&Asg); /***** Hide assignment *****/ - Asg_DB_HideAssignment (Asg.AsgCod); + Asg_DB_HideOrUnhideAssignment (Asg.AsgCod,true); /***** Show all assignments again *****/ Asg_ShowAllAssignments (&Assignments); @@ -1060,7 +1060,7 @@ void Asg_UnhideAssignment (void) Asg_GetDataOfAssignmentByCod (&Asg); /***** Unhide assignment *****/ - Asg_DB_UnhideAssignment (Asg.AsgCod); + Asg_DB_HideOrUnhideAssignment (Asg.AsgCod,false); /***** Show all assignments again *****/ Asg_ShowAllAssignments (&Assignments); diff --git a/swad_assignment_database.c b/swad_assignment_database.c index 3e5f7cf2..6c57b8df 100644 --- a/swad_assignment_database.c +++ b/swad_assignment_database.c @@ -278,27 +278,18 @@ void Asg_DB_UpdateAssignment (const struct Asg_Assignment *Asg,const char *Txt) } /*****************************************************************************/ -/************************** Hide/unhide an assignment ************************/ +/************************* Hide/unhide an assignment *************************/ /*****************************************************************************/ -void Asg_DB_HideAssignment (long AsgCod) +void Asg_DB_HideOrUnhideAssignment (long AsgCod,bool Hide) { - DB_QueryUPDATE ("can not hide assignment", + DB_QueryUPDATE ("can not hide/unhide assignment", "UPDATE asg_assignments" - " SET Hidden='Y'" - " WHERE AsgCod=%ld" - " AND CrsCod=%ld", // Extra check - AsgCod, - Gbl.Hierarchy.Crs.CrsCod); - } - -void Asg_DB_UnhideAssignment (long AsgCod) - { - DB_QueryUPDATE ("can not unhide assignment", - "UPDATE asg_assignments" - " SET Hidden='N'" + " SET Hidden='%c'" " WHERE AsgCod=%ld" " AND CrsCod=%ld", + Hide ? 'Y' : + 'N', AsgCod, Gbl.Hierarchy.Crs.CrsCod); } diff --git a/swad_assignment_database.h b/swad_assignment_database.h index dd468570..f253b877 100644 --- a/swad_assignment_database.h +++ b/swad_assignment_database.h @@ -57,8 +57,7 @@ bool Asg_DB_CheckIfSimilarAssignmentExists (const char *Field,const char *Value, long Asg_DB_CreateAssignment (const struct Asg_Assignment *Asg,const char *Txt); void Asg_DB_UpdateAssignment (const struct Asg_Assignment *Asg,const char *Txt); -void Asg_DB_HideAssignment (long AsgCod); -void Asg_DB_UnhideAssignment (long AsgCod); +void Asg_DB_HideOrUnhideAssignment (long AsgCod,bool Hide); void Asg_DB_RemoveAssignment (long AsgCod); diff --git a/swad_attendance.c b/swad_attendance.c index 5379ac96..cd88ca37 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -932,7 +932,7 @@ void Att_HideAttEvent (void) Att_GetDataOfAttEventByCodAndCheckCrs (&Event); /***** Hide attendance event *****/ - Att_DB_HideAttEvent (Event.AttCod); + Att_DB_HideOrUnhideAttEvent (Event.AttCod,true); /***** Show attendance events again *****/ Att_SeeAttEvents (); @@ -954,7 +954,7 @@ void Att_UnhideAttEvent (void) Att_GetDataOfAttEventByCodAndCheckCrs (&Event); /***** Unhide attendance event *****/ - Att_DB_UnhideAttEvent (Event.AttCod); + Att_DB_HideOrUnhideAttEvent (Event.AttCod,false); /***** Show attendance events again *****/ Att_SeeAttEvents (); diff --git a/swad_attendance_database.c b/swad_attendance_database.c index 04556a32..a97bde54 100644 --- a/swad_attendance_database.c +++ b/swad_attendance_database.c @@ -261,24 +261,15 @@ void Att_DB_UpdateAttEvent (const struct Att_Event *Event,const char *Descriptio /********************** Hide/unhide an attendance event **********************/ /*****************************************************************************/ -void Att_DB_HideAttEvent (long AttCod) +void Att_DB_HideOrUnhideAttEvent (long AttCod,bool Hide) { - DB_QueryUPDATE ("can not hide attendance event", + DB_QueryUPDATE ("can not hide/unhide assignment", "UPDATE att_events" - " SET Hidden='Y'" - " WHERE AttCod=%ld" - " AND CrsCod=%ld", // Extra check - AttCod, - Gbl.Hierarchy.Crs.CrsCod); - } - -void Att_DB_UnhideAttEvent (long AttCod) - { - DB_QueryUPDATE ("can not unhide attendance event", - "UPDATE att_events" - " SET Hidden='N'" + " SET Hidden='%c'" " WHERE AttCod=%ld" " AND CrsCod=%ld", + Hide ? 'Y' : + 'N', AttCod, Gbl.Hierarchy.Crs.CrsCod); } diff --git a/swad_attendance_database.h b/swad_attendance_database.h index 7ca5a7bf..83682104 100644 --- a/swad_attendance_database.h +++ b/swad_attendance_database.h @@ -54,8 +54,7 @@ bool Att_DB_CheckIfSimilarAttEventExists (const char *Field,const char *Value,lo long Att_DB_CreateAttEvent (const struct Att_Event *Event,const char *Description); void Att_DB_UpdateAttEvent (const struct Att_Event *Event,const char *Description); -void Att_DB_HideAttEvent (long AttCod); -void Att_DB_UnhideAttEvent (long AttCod); +void Att_DB_HideOrUnhideAttEvent (long AttCod,bool Hide); void Att_DB_CreateGroup (long AttCod,long GrpCod); unsigned Att_DB_GetGrpCodsAssociatedToEvent (MYSQL_RES **mysql_res,long AttCod); diff --git a/swad_banner.c b/swad_banner.c index 136f0063..bc284fbd 100644 --- a/swad_banner.c +++ b/swad_banner.c @@ -613,7 +613,7 @@ static void Ban_ShowOrHideBanner (struct Ban_Banner *Ban,bool Hide) /***** Mark file as hidden/visible in database *****/ if (Ban->Hidden != Hide) - Ban_DB_ShowOrHideBanner (Ban->BanCod,Hide); + Ban_DB_HideOrUnhideBanner (Ban->BanCod,Hide); } /*****************************************************************************/ diff --git a/swad_banner_database.c b/swad_banner_database.c index 45fc276e..e1632f4b 100644 --- a/swad_banner_database.c +++ b/swad_banner_database.c @@ -167,12 +167,12 @@ void Ban_DB_CreateBanner (const struct Ban_Banner *Ban) } /*****************************************************************************/ -/************************* Change hiddeness of banner ************************/ +/**************************** Hide/unhide a banner ***************************/ /*****************************************************************************/ -void Ban_DB_ShowOrHideBanner (long BanCod,bool Hide) +void Ban_DB_HideOrUnhideBanner (long BanCod,bool Hide) { - DB_QueryUPDATE ("can not change status of a banner in database", + DB_QueryUPDATE ("can not hide/unhide banner", "UPDATE ban_banners" " SET Hidden='%c'" " WHERE BanCod=%ld", diff --git a/swad_banner_database.h b/swad_banner_database.h index 0251565e..afa1d5d3 100644 --- a/swad_banner_database.h +++ b/swad_banner_database.h @@ -46,7 +46,7 @@ unsigned Ban_DB_GetDataOfBannerByCod (MYSQL_RES **mysql_res,long BanCod); bool Ban_DB_CheckIfBannerNameExists (const char *FieldName,const char *Name,long BanCod); void Ban_DB_CreateBanner (const struct Ban_Banner *Ban); -void Ban_DB_ShowOrHideBanner (long BanCod,bool Hide); +void Ban_DB_HideOrUnhideBanner (long BanCod,bool Hide); void Ban_DB_UpdateBanName (long BanCod,const char *FieldName, const char *NewBanName); void Ban_DB_UpdateBanImg (long BanCod, diff --git a/swad_browser.c b/swad_browser.c index 99b1b1fe..a268f967 100644 --- a/swad_browser.c +++ b/swad_browser.c @@ -7741,7 +7741,7 @@ void Brw_SetDocumentAsVisible (void) /***** Change file to visible *****/ if (Brw_CheckIfFileOrFolderIsSetAsHiddenInDB (Gbl.FileBrowser.FilFolLnk.Type, Gbl.FileBrowser.FilFolLnk.Full)) - Brw_DB_ChangeFileOrFolderHidden (Gbl.FileBrowser.FilFolLnk.Full,false); + Brw_DB_HideOrUnhideFileOrFolder (Gbl.FileBrowser.FilFolLnk.Full,false); /***** Remove the affected clipboards *****/ Brw_DB_RemoveAffectedClipboards (Gbl.FileBrowser.Type, @@ -7765,7 +7765,7 @@ void Brw_SetDocumentAsHidden (void) set it as hidden *****/ if (!Brw_CheckIfFileOrFolderIsSetAsHiddenInDB (Gbl.FileBrowser.FilFolLnk.Type, Gbl.FileBrowser.FilFolLnk.Full)) - Brw_DB_ChangeFileOrFolderHidden (Gbl.FileBrowser.FilFolLnk.Full,true); + Brw_DB_HideOrUnhideFileOrFolder (Gbl.FileBrowser.FilFolLnk.Full,true); /***** Remove the affected clipboards *****/ Brw_DB_RemoveAffectedClipboards (Gbl.FileBrowser.Type, diff --git a/swad_browser_database.c b/swad_browser_database.c index 459d0a27..965897ec 100644 --- a/swad_browser_database.c +++ b/swad_browser_database.c @@ -2264,24 +2264,24 @@ unsigned Brw_DB_GetNumFileViewsUsr (long UsrCod) } /*****************************************************************************/ -/***************** Change hiddeness of file in the database ******************/ +/************************ Hide/unhide file or folder *************************/ /*****************************************************************************/ -void Brw_DB_ChangeFileOrFolderHidden (const char Path[PATH_MAX + 1],bool IsHidden) +void Brw_DB_HideOrUnhideFileOrFolder (const char Path[PATH_MAX + 1],bool Hide) { long Cod = Brw_GetCodForFileBrowser (); long ZoneUsrCod = Brw_GetZoneUsrCodForFileBrowser (); /***** Mark file as hidden/unhidden in database *****/ - DB_QueryUPDATE ("can not change status of a file in database", + DB_QueryUPDATE ("can not hide/unhide file/folder", "UPDATE brw_files" " SET Hidden='%c'" " WHERE FileBrowser=%u" " AND Cod=%ld" " AND ZoneUsrCod=%ld" " AND Path='%s'", - IsHidden ? 'Y' : - 'N', + Hide ? 'Y' : + 'N', (unsigned) Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type], Cod, ZoneUsrCod, diff --git a/swad_browser_database.h b/swad_browser_database.h index 1a5b1752..497140ab 100644 --- a/swad_browser_database.h +++ b/swad_browser_database.h @@ -104,7 +104,7 @@ unsigned Brw_DB_GetFileViewsFromNonLoggedUsrs (long FilCod); unsigned Brw_DB_GetNumFileViewsUsr (long UsrCod); //------------------------------- Hidden files -------------------------------- -void Brw_DB_ChangeFileOrFolderHidden (const char Path[PATH_MAX + 1],bool IsHidden); +void Brw_DB_HideOrUnhideFileOrFolder (const char Path[PATH_MAX + 1],bool Hide); unsigned Brw_DB_CheckIfFileOrFolderIsSetAsHiddenUsingPath (MYSQL_RES **mysql_res, const char *Path); bool Brw_DB_CheckIfFileOrFolderIsSetAsHiddenUsingMetadata (const struct FileMetadata *FileMetadata); diff --git a/swad_changelog.h b/swad_changelog.h index 032d7a28..5ee08bfa 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. */ -#define Log_PLATFORM_VERSION "SWAD 21.39.2 (2021-10-22)" +#define Log_PLATFORM_VERSION "SWAD 21.40 (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.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) Version 21.39: Oct 21, 2021 Fixed bug in nicknames. Reported by Ana Ollarves Reyes. (320487 lines) diff --git a/swad_exam.c b/swad_exam.c index 34c53ee2..a5b52f6f 100644 --- a/swad_exam.c +++ b/swad_exam.c @@ -1255,7 +1255,7 @@ static void Exa_HideUnhideExam (bool Hide) Exams.ExaCod = Exam.ExaCod; /***** Unhide exam *****/ - Exa_DB_HideUnhideExam (Exam.ExaCod,Hide); + Exa_DB_HideOrUnhideExam (Exam.ExaCod,Hide); /***** Show exams again *****/ Exa_ListAllExams (&Exams); diff --git a/swad_exam_database.c b/swad_exam_database.c index 64eede85..f17234e3 100644 --- a/swad_exam_database.c +++ b/swad_exam_database.c @@ -115,12 +115,12 @@ void Exa_DB_UpdateExam (const struct Exa_Exam *Exam,const char *Txt) } /*****************************************************************************/ -/***************************** Hide/unhide exam ******************************/ +/*************************** Hide/unhide an exam *****************************/ /*****************************************************************************/ -void Exa_DB_HideUnhideExam (long ExaCod,bool Hide) +void Exa_DB_HideOrUnhideExam (long ExaCod,bool Hide) { - DB_QueryUPDATE ("can not hide exam", + DB_QueryUPDATE ("can not hide/unhide exam", "UPDATE exa_exams" " SET Hidden='%c'" " WHERE ExaCod=%ld", @@ -767,7 +767,6 @@ long Exa_DB_GetSetCodFromSetInd (long ExaCod,unsigned SetInd) unsigned Exa_DB_GetMaxSetIndexInExam (long ExaCod) { - /***** Get maximum set index in an exam from database *****/ return DB_QuerySELECTUnsigned ("can not get max set index", "SELECT MAX(SetInd)" " FROM exa_sets" diff --git a/swad_exam_database.h b/swad_exam_database.h index 793f6ce7..019d5f9f 100644 --- a/swad_exam_database.h +++ b/swad_exam_database.h @@ -44,7 +44,7 @@ //---------------------------- Exams ------------------------------------------ long Exa_DB_CreateExam (const struct Exa_Exam *Exam,const char *Txt); void Exa_DB_UpdateExam (const struct Exa_Exam *Exam,const char *Txt); -void Exa_DB_HideUnhideExam (long ExaCod,bool Hide); +void Exa_DB_HideOrUnhideExam (long ExaCod,bool Hide); unsigned Exa_DB_GetListExams (MYSQL_RES **mysql_res,Exa_Order_t SelectedOrder); unsigned Exa_DB_GetDataOfExamByCod (MYSQL_RES **mysql_res,long ExaCod); unsigned Exa_DB_GetExamStartEnd (MYSQL_RES **mysql_res,long ExaCod); diff --git a/swad_game.c b/swad_game.c index 4b96293a..af95dce3 100644 --- a/swad_game.c +++ b/swad_game.c @@ -1187,7 +1187,7 @@ void Gam_HideGame (void) Err_NoPermissionExit (); /***** Hide game *****/ - Gam_DB_HideGame (Game.GamCod); + Gam_DB_HideOrUnhideGame (Game.GamCod,true); /***** Show games again *****/ Gam_ListAllGames (&Games); @@ -1218,7 +1218,7 @@ void Gam_UnhideGame (void) Err_NoPermissionExit (); /***** Unhide game *****/ - Gam_DB_UnhideGame (Game.GamCod); + Gam_DB_HideOrUnhideGame (Game.GamCod,false); /***** Show games again *****/ Gam_ListAllGames (&Games); diff --git a/swad_game_database.c b/swad_game_database.c index 9c239068..e0f8a717 100644 --- a/swad_game_database.c +++ b/swad_game_database.c @@ -109,28 +109,17 @@ void Gam_DB_UpdateGame (const struct Gam_Game *Game,const char *Txt) } /*****************************************************************************/ -/********************************** Hide a game ******************************/ +/*************************** Hide/unhide a game ******************************/ /*****************************************************************************/ -void Gam_DB_HideGame (long GamCod) +void Gam_DB_HideOrUnhideGame (long GamCod,bool Hide) { - DB_QueryUPDATE ("can not hide game", + DB_QueryUPDATE ("can not hide/unhide game", "UPDATE gam_games" - " SET Hidden='Y'" - " WHERE GamCod=%ld", - GamCod); - } - -/*****************************************************************************/ -/******************************** Unhide a game ******************************/ -/*****************************************************************************/ - -void Gam_DB_UnhideGame (long GamCod) - { - DB_QueryUPDATE ("can not show game", - "UPDATE gam_games" - " SET Hidden='N'" + " SET Hidden='%c'" " WHERE GamCod=%ld", + Hide ? 'Y' : + 'N', GamCod); } diff --git a/swad_game_database.h b/swad_game_database.h index e338926d..48a176d8 100644 --- a/swad_game_database.h +++ b/swad_game_database.h @@ -40,8 +40,7 @@ //--------------------------------- Games ------------------------------------- long Gam_DB_CreateGame (const struct Gam_Game *Game,const char *Txt); void Gam_DB_UpdateGame (const struct Gam_Game *Game,const char *Txt); -void Gam_DB_HideGame (long GamCod); -void Gam_DB_UnhideGame (long GamCod); +void Gam_DB_HideOrUnhideGame (long GamCod,bool Hide); unsigned Gam_DB_GetListGames (MYSQL_RES **mysql_res,Gam_Order_t SelectedOrder); unsigned Gam_DB_GetDataOfGameByCod (MYSQL_RES **mysql_res,long GamCod); diff --git a/swad_program.c b/swad_program.c index 72b4d24a..a10efa72 100644 --- a/swad_program.c +++ b/swad_program.c @@ -166,7 +166,7 @@ static long Prg_GetParamItmCod (void); static unsigned Prg_GetNumItemFromItmCod (long ItmCod); -static void Prg_HideUnhideItem (char YN); +static void Prg_HideOrUnhideItem (bool Hide); static void Prg_MoveUpDownItem (Prg_MoveUpDown_t UpDown); static bool Prg_ExchangeItemRanges (int NumItemTop,int NumItemBottom); @@ -1205,15 +1205,15 @@ void Prg_RemoveItem (void) void Prg_HideItem (void) { - Prg_HideUnhideItem ('Y'); + Prg_HideOrUnhideItem (true); } void Prg_UnhideItem (void) { - Prg_HideUnhideItem ('N'); + Prg_HideOrUnhideItem (false); } -static void Prg_HideUnhideItem (char YN) +static void Prg_HideOrUnhideItem (bool Hide) { struct Prg_Item Item; struct Prg_ItemRange ToHighlight; @@ -1228,7 +1228,7 @@ static void Prg_HideUnhideItem (char YN) Err_WrongItemExit (); /***** Hide/unhide program item *****/ - Prg_DB_HideUnhideItem (Item.Hierarchy.ItmCod,YN); + Prg_DB_HideOrUnhideItem (Item.Hierarchy.ItmCod,Hide); /***** Show program items highlighting subtree *****/ Prg_SetItemRangeWithAllChildren (Prg_GetNumItemFromItmCod (Item.Hierarchy.ItmCod), diff --git a/swad_program_database.c b/swad_program_database.c index 005c2918..03c20311 100644 --- a/swad_program_database.c +++ b/swad_program_database.c @@ -100,18 +100,19 @@ void Prg_DB_UpdateItem (const struct Prg_Item *Item,const char *Txt) } /*****************************************************************************/ -/************************* Hide/unhide program item **************************/ +/************************* Hide/unhide a program item *************************/ /*****************************************************************************/ -void Prg_DB_HideUnhideItem (long ItmCod,char YN) +void Prg_DB_HideOrUnhideItem (long ItmCod,bool Hide) { - DB_QueryUPDATE ("can not change program item", + DB_QueryUPDATE ("can not hide/unhide program item", "UPDATE prg_items" " SET Hidden='%c'" " WHERE ItmCod=%ld" " AND CrsCod=%ld", // Extra check - YN, - ItmCod, + Hide ? 'Y' : + 'N', + ItmCod, Gbl.Hierarchy.Crs.CrsCod); } diff --git a/swad_program_database.h b/swad_program_database.h index f58b542b..c1ddfd70 100644 --- a/swad_program_database.h +++ b/swad_program_database.h @@ -40,7 +40,7 @@ long Prg_DB_InsertItem (const struct Prg_Item *Item,const char *Txt); void Prg_DB_UpdateItem (const struct Prg_Item *Item,const char *Txt); -void Prg_DB_HideUnhideItem (long ItmCod,char YN); +void Prg_DB_HideOrUnhideItem (long ItmCod,bool Hide); void Prg_DB_UpdateIndexRange (long Diff,long Begin,long End); void Prg_DB_LockTable (void); void Prg_DB_UnlockTable (void); diff --git a/swad_project.c b/swad_project.c index 513bc18b..7210fa90 100644 --- a/swad_project.c +++ b/swad_project.c @@ -3113,7 +3113,7 @@ void Prj_HideProject (void) /***** Hide project *****/ if (Prj_CheckIfICanEditProject (&Prj)) - Prj_DB_HideUnhideProject (Prj.PrjCod,'Y'); + Prj_DB_HideOrUnhideProject (Prj.PrjCod,true); else Err_NoPermissionExit (); @@ -3149,7 +3149,7 @@ void Prj_UnhideProject (void) /***** Unhide project *****/ if (Prj_CheckIfICanEditProject (&Prj)) - Prj_DB_HideUnhideProject (Prj.PrjCod,'N'); + Prj_DB_HideOrUnhideProject (Prj.PrjCod,false); else Err_NoPermissionExit (); diff --git a/swad_project_database.c b/swad_project_database.c index cbc42bcd..cd20b787 100644 --- a/swad_project_database.c +++ b/swad_project_database.c @@ -201,14 +201,15 @@ void Prj_DB_AddUsrToPrj (long PrjCod,Prj_RoleInProject_t RoleInProject,long UsrC /****************************** Hide a project *******************************/ /*****************************************************************************/ -void Prj_DB_HideUnhideProject (long PrjCod,char YN) +void Prj_DB_HideOrUnhideProject (long PrjCod,bool Hide) { - DB_QueryUPDATE ("can not hide project", + DB_QueryUPDATE ("can not hide/unhide project", "UPDATE prj_projects" " SET Hidden='%c'" " WHERE PrjCod=%ld" " AND CrsCod=%ld", // Extra check - YN, + Hide ? 'Y' : + 'N', PrjCod, Gbl.Hierarchy.Crs.CrsCod); } diff --git a/swad_project_database.h b/swad_project_database.h index 01a433bf..89fdc09d 100644 --- a/swad_project_database.h +++ b/swad_project_database.h @@ -43,7 +43,7 @@ void Prj_DB_UnlockProjectEdition (long PrjCod); long Prj_DB_CreateProject (const struct Prj_Project *Prj); void Prj_DB_UpdateProject (const struct Prj_Project *Prj); void Prj_DB_AddUsrToPrj (long PrjCod,Prj_RoleInProject_t RoleInProject,long UsrCod); -void Prj_DB_HideUnhideProject (long PrjCod,char YN); +void Prj_DB_HideOrUnhideProject (long PrjCod,bool Hide); unsigned Prj_DB_GetListProjects (MYSQL_RES **mysql_res, const struct Prj_Projects *Projects, diff --git a/swad_survey.c b/swad_survey.c index b4e28624..22f12696 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -66,12 +66,6 @@ extern struct Globals Gbl; #define Svy_MAX_BYTES_LIST_ANSWER_TYPES (Svy_NUM_ANS_TYPES * (Cns_MAX_DECIMAL_DIGITS_UINT + 1)) -const char *Svy_StrAnswerTypesDB[Svy_NUM_ANS_TYPES] = - { - [Svy_ANS_UNIQUE_CHOICE ] = "unique_choice", - [Svy_ANS_MULTIPLE_CHOICE] = "multiple_choice", - }; - #define Svy_MAX_ANSWERS_PER_QUESTION 10 struct Svy_Question // Must be initialized to 0 before using it @@ -138,11 +132,10 @@ static void Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (struct Svy_Survey *Svy); static void Svy_ShowFormEditOneQst (struct Svy_Surveys *Surveys, long SvyCod,struct Svy_Question *SvyQst, - char Txt[Cns_MAX_BYTES_TEXT + 1]); + char Stem[Cns_MAX_BYTES_TEXT + 1]); static void Svy_InitQst (struct Svy_Question *SvyQst); static void Svy_PutParamQstCod (long QstCod); static long Svy_GetParamQstCod (void); -static Svy_AnswerType_t Svy_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeBD); static bool Svy_AllocateTextChoiceAnswer (struct Svy_Question *SvyQst,unsigned NumAns); static void Svy_FreeTextChoiceAnswers (struct Svy_Question *SvyQst,unsigned NumAnswers); static void Svy_FreeTextChoiceAnswer (struct Svy_Question *SvyQst,unsigned NumAns); @@ -150,6 +143,9 @@ static void Svy_FreeTextChoiceAnswer (struct Svy_Question *SvyQst,unsigned NumAn static unsigned Svy_GetNextQuestionIndexInSvy (long SvyCod); static void Svy_ListSvyQuestions (struct Svy_Surveys *Surveys, struct Svy_Survey *Svy); +static void Svy_GetDataOfQstFromRow (struct Svy_Question *SvyQst, + char Stem[Cns_MAX_BYTES_TEXT + 1], + MYSQL_ROW row); static void Svy_PutParamsToEditQuestion (void *Surveys); static void Svy_PutIconToAddNewQuestion (void *Surveys); static void Svy_PutButtonToCreateNewQuestion (struct Svy_Surveys *Surveys); @@ -505,7 +501,7 @@ static void Svy_ShowOneSurvey (struct Svy_Surveys *Surveys, (Svy.Status.Open ? "DATE_GREEN_LIGHT" : "DATE_RED_LIGHT"), Gbl.RowEvenOdd); - Dat_WriteLocalDateHMSFromUTC (Id,Svy.TimeUTC[Svy_START_TIME], + Dat_WriteLocalDateHMSFromUTC (Id,Svy.TimeUTC[Dat_STR_TIME], Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK, true,true,true,0x7); HTM_TD_End (); @@ -529,7 +525,7 @@ static void Svy_ShowOneSurvey (struct Svy_Surveys *Surveys, (Svy.Status.Open ? "DATE_GREEN_LIGHT" : "DATE_RED_LIGHT"), Gbl.RowEvenOdd); - Dat_WriteLocalDateHMSFromUTC (Id,Svy.TimeUTC[Svy_END_TIME], + Dat_WriteLocalDateHMSFromUTC (Id,Svy.TimeUTC[Dat_END_TIME], Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK, true,false,true,0x7); HTM_TD_End (); @@ -1300,15 +1296,15 @@ void Svy_GetDataOfSurveyByCod (struct Svy_Survey *Svy) else { /* Initialize to empty survey */ - Svy->SvyCod = -1L; - Svy->Scope = HieLvl_UNK; - Svy->Roles = 0; - Svy->UsrCod = -1L; - Svy->TimeUTC[Svy_START_TIME] = - Svy->TimeUTC[Svy_END_TIME ] = (time_t) 0; - Svy->Title[0] = '\0'; - Svy->NumQsts = 0; - Svy->NumUsrs = 0; + Svy->SvyCod = -1L; + Svy->Scope = HieLvl_UNK; + Svy->Roles = 0; + Svy->UsrCod = -1L; + Svy->TimeUTC[Dat_STR_TIME] = + Svy->TimeUTC[Dat_END_TIME] = (time_t) 0; + Svy->Title[0] = '\0'; + Svy->NumQsts = 0; + Svy->NumUsrs = 0; Svy->Status.Visible = true; Svy->Status.Open = false; Svy->Status.IAmLoggedWithAValidRoleToAnswer = false; @@ -1609,11 +1605,7 @@ void Svy_HideSurvey (void) Err_NoPermissionExit (); /***** Hide survey *****/ - DB_QueryUPDATE ("can not hide survey", - "UPDATE svy_surveys" - " SET Hidden='Y'" - " WHERE SvyCod=%ld", - Svy.SvyCod); + Svy_DB_HideOrUnhideSurvey (Svy.SvyCod,true); /***** Show surveys again *****/ Svy_ListAllSurveys (&Surveys); @@ -1646,11 +1638,7 @@ void Svy_UnhideSurvey (void) Err_NoPermissionExit (); /***** Show survey *****/ - DB_QueryUPDATE ("can not show survey", - "UPDATE svy_surveys" - " SET Hidden='N'" - " WHERE SvyCod=%ld", - Svy.SvyCod); + Svy_DB_HideOrUnhideSurvey (Svy.SvyCod,false); /***** Show surveys again *****/ Svy_ListAllSurveys (&Surveys); @@ -1706,8 +1694,8 @@ void Svy_RequestCreatOrEditSvy (void) Svy.Scope = HieLvl_UNK; Svy.Roles = (1 << Rol_STD); Svy.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod; - Svy.TimeUTC[Svy_START_TIME] = Gbl.StartExecutionTimeUTC; - Svy.TimeUTC[Svy_END_TIME ] = Gbl.StartExecutionTimeUTC + (24 * 60 * 60); // +24 hours + Svy.TimeUTC[Dat_STR_TIME] = Gbl.StartExecutionTimeUTC; + Svy.TimeUTC[Dat_END_TIME] = Gbl.StartExecutionTimeUTC + (24 * 60 * 60); // +24 hours Svy.Title[0] = '\0'; Svy.NumQsts = 0; Svy.NumUsrs = 0; @@ -2078,10 +2066,10 @@ void Svy_ReceiveFormSurvey (void) Par_GetParToHTML ("Txt",Txt,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous) /***** Adjust dates *****/ - if (NewSvy.TimeUTC[Svy_START_TIME] == 0) - NewSvy.TimeUTC[Svy_START_TIME] = Gbl.StartExecutionTimeUTC; - if (NewSvy.TimeUTC[Svy_END_TIME] == 0) - NewSvy.TimeUTC[Svy_END_TIME] = NewSvy.TimeUTC[Svy_START_TIME] + 24 * 60 * 60; // +24 hours + if (NewSvy.TimeUTC[Dat_STR_TIME] == 0) + NewSvy.TimeUTC[Dat_STR_TIME] = Gbl.StartExecutionTimeUTC; + if (NewSvy.TimeUTC[Dat_END_TIME] == 0) + NewSvy.TimeUTC[Dat_END_TIME] = NewSvy.TimeUTC[Dat_STR_TIME] + 24 * 60 * 60; // +24 hours /***** Get users who can answer this survey *****/ NewSvy.Roles = Rol_GetSelectedRoles (); @@ -2138,24 +2126,7 @@ static void Svy_CreateSurvey (struct Svy_Survey *Svy,const char *Txt) extern const char *Txt_Created_new_survey_X; /***** Create a new survey *****/ - Svy->SvyCod = - DB_QueryINSERTandReturnCode ("can not create new survey", - "INSERT INTO svy_surveys" - " (Scope,Cod,Hidden,Roles,UsrCod," - "StartTime,EndTime," - "Title,Txt)" - " VALUES" - " ('%s',%ld,'N',%u,%ld," - "FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld)," - "'%s','%s')", - Sco_GetDBStrFromScope (Svy->Scope), - Svy->Cod, - Svy->Roles, - Gbl.Usrs.Me.UsrDat.UsrCod, - Svy->TimeUTC[Svy_START_TIME], - Svy->TimeUTC[Svy_END_TIME ], - Svy->Title, - Txt); + Svy->SvyCod = Svy_DB_CreateSurvey (Svy,Txt); /***** Create groups *****/ if (Gbl.Crs.Grps.LstGrpsSel.NumGrps) @@ -2175,24 +2146,7 @@ static void Svy_UpdateSurvey (struct Svy_Survey *Svy,const char *Txt) extern const char *Txt_The_survey_has_been_modified; /***** Update the data of the survey *****/ - DB_QueryUPDATE ("can not update survey", - "UPDATE svy_surveys" - " SET Scope='%s'," - "Cod=%ld," - "Roles=%u," - "StartTime=FROM_UNIXTIME(%ld)," - "EndTime=FROM_UNIXTIME(%ld)," - "Title='%s'," - "Txt='%s'" - " WHERE SvyCod=%ld", - Sco_GetDBStrFromScope (Svy->Scope), - Svy->Cod, - Svy->Roles, - Svy->TimeUTC[Svy_START_TIME], - Svy->TimeUTC[Svy_END_TIME ], - Svy->Title, - Txt, - Svy->SvyCod); + Svy_DB_UpdateSurvey (Svy,Txt); /***** Update groups *****/ /* Remove old groups */ @@ -2218,14 +2172,7 @@ static void Svy_CreateGrps (long SvyCod) for (NumGrpSel = 0; NumGrpSel < Gbl.Crs.Grps.LstGrpsSel.NumGrps; NumGrpSel++) - /* Create group */ - DB_QueryINSERT ("can not associate a group to a survey", - "INSERT INTO svy_groups" - " (SvyCod,GrpCod)" - " VALUES" - " (%ld,%ld)", - SvyCod, - Gbl.Crs.Grps.LstGrpsSel.GrpCods[NumGrpSel]); + Svy_DB_CreateGrp (SvyCod,Gbl.Crs.Grps.LstGrpsSel.GrpCods[NumGrpSel]); } /*****************************************************************************/ @@ -2240,36 +2187,25 @@ static void Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (struct Svy_Survey *Svy) extern const char *Txt_The_whole_course; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRow; - unsigned long NumRows; + unsigned NumGrps; + unsigned NumGrp; /***** Get groups associated to a survey from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get groups of a survey", - "SELECT grp_types.GrpTypName," // row[0] - "grp_groups.GrpName" // row[1] - " FROM svy_groups," - "grp_groups," - "grp_types" - " WHERE svy_groups.SvyCod=%ld" - " AND svy_groups.GrpCod=grp_groups.GrpCod" - " AND grp_groups.GrpTypCod=grp_types.GrpTypCod" - " ORDER BY grp_types.GrpTypName," - "grp_groups.GrpName", - Svy->SvyCod); + NumGrps = Svy_DB_GetGrpNamesAssociatedToSvy (&mysql_res,Svy->SvyCod); /***** Write heading *****/ HTM_DIV_Begin ("class=\"%s\"",Svy->Status.Visible ? "ASG_GRP" : "ASG_GRP_LIGHT"); - HTM_TxtColonNBSP (NumRows == 1 ? Txt_Group : + HTM_TxtColonNBSP (NumGrps == 1 ? Txt_Group : Txt_Groups); /***** Write groups *****/ - if (NumRows) // Groups found... + if (NumGrps) // Groups found... { /* Get and write the group types and names */ - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + for (NumGrp = 0; + NumGrp < NumGrps; + NumGrp++) { /* Get next group */ row = mysql_fetch_row (mysql_res); @@ -2277,12 +2213,12 @@ static void Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (struct Svy_Survey *Svy) /* Write group type name and group name */ HTM_TxtF ("%s %s",row[0],row[1]); - if (NumRows >= 2) + if (NumGrps >= 2) { - if (NumRow == NumRows - 2) + if (NumGrp == NumGrps - 2) HTM_TxtF (" %s ",Txt_and); - if (NumRows >= 3) - if (NumRow < NumRows - 2) + if (NumGrps >= 3) + if (NumGrp < NumGrps - 2) HTM_Txt (", "); } } @@ -2303,64 +2239,20 @@ static void Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (struct Svy_Survey *Svy) void Svy_RemoveSurveys (HieLvl_Level_t Scope,long Cod) { - /***** Remove all the users in course surveys *****/ - DB_QueryDELETE ("can not remove users" - " who had answered surveys in a place on the hierarchy", - "DELETE FROM svy_users" - " USING svy_surveys," - "svy_users" - " WHERE svy_surveys.Scope='%s'" - " AND svy_surveys.Cod=%ld" - " AND svy_surveys.SvyCod=svy_users.SvyCod", - Sco_GetDBStrFromScope (Scope), - Cod); + /***** Remove all users in surveys *****/ + Svy_DB_RemoveUsrsWhoHaveAnsweredSvysIn (Scope,Cod); - /***** Remove all the answers in course surveys *****/ - DB_QueryDELETE ("can not remove answers of surveys" - " in a place on the hierarchy", - "DELETE FROM svy_answers" - " USING svy_surveys," - "svy_questions," - "svy_answers" - " WHERE svy_surveys.Scope='%s'" - " AND svy_surveys.Cod=%ld" - " AND svy_surveys.SvyCod=svy_questions.SvyCod" - " AND svy_questions.QstCod=svy_answers.QstCod", - Sco_GetDBStrFromScope (Scope), - Cod); + /***** Remove all answers in surveys *****/ + Svy_DB_RemoveAnswersSvysIn (Scope,Cod); - /***** Remove all the questions in course surveys *****/ - DB_QueryDELETE ("can not remove questions of surveys" - " in a place on the hierarchy", - "DELETE FROM svy_questions" - " USING svy_surveys," - "svy_questions" - " WHERE svy_surveys.Scope='%s'" - " AND svy_surveys.Cod=%ld" - " AND svy_surveys.SvyCod=svy_questions.SvyCod", - Sco_GetDBStrFromScope (Scope), - Cod); + /***** Remove all questions in surveys *****/ + Svy_DB_RemoveQstsSvysIn (Scope,Cod); - /***** Remove groups *****/ - DB_QueryDELETE ("can not remove all the groups" - " associated to surveys of a course", - "DELETE FROM svy_groups" - " USING svy_surveys," - "svy_groups" - " WHERE svy_surveys.Scope='%s'" - " AND svy_surveys.Cod=%ld" - " AND svy_surveys.SvyCod=svy_groups.SvyCod", - Sco_GetDBStrFromScope (Scope), - Cod); + /***** Remove all groups *****/ + Svy_DB_RemoveGrpsSvysIn (Scope,Cod); - /***** Remove course surveys *****/ - DB_QueryDELETE ("can not remove all the surveys" - " in a place on the hierarchy", - "DELETE FROM svy_surveys" - " WHERE Scope='%s'" - " AND Cod=%ld", - Sco_GetDBStrFromScope (Scope), - Cod); + /***** Remove all surveys *****/ + Svy_DB_RemoveSvysIn (Scope,Cod); } /*****************************************************************************/ @@ -2372,7 +2264,7 @@ void Svy_RequestEditQuestion (void) struct Svy_Surveys Surveys; struct Svy_Question SvyQst; long SvyCod; - char Txt[Cns_MAX_BYTES_TEXT + 1]; + char Stem[Cns_MAX_BYTES_TEXT + 1]; /***** Reset surveys *****/ Svy_ResetSurveys (&Surveys); @@ -2381,7 +2273,7 @@ void Svy_RequestEditQuestion (void) Svy_InitQst (&SvyQst); /***** Initialize text to empty string *****/ - Txt[0] = '\0'; + Stem[0] = '\0'; /***** Get survey code *****/ if ((SvyCod = Svy_GetParamSvyCod ()) <= 0) @@ -2396,7 +2288,7 @@ void Svy_RequestEditQuestion (void) Surveys.CurrentPage = Pag_GetParamPagNum (Pag_SURVEYS); /***** Show form to create a new question in this survey *****/ - Svy_ShowFormEditOneQst (&Surveys,SvyCod,&SvyQst,Txt); + Svy_ShowFormEditOneQst (&Surveys,SvyCod,&SvyQst,Stem); /***** Show current survey *****/ Svy_ShowOneSurvey (&Surveys,SvyCod,true); @@ -2408,7 +2300,7 @@ void Svy_RequestEditQuestion (void) static void Svy_ShowFormEditOneQst (struct Svy_Surveys *Surveys, long SvyCod,struct Svy_Question *SvyQst, - char Txt[Cns_MAX_BYTES_TEXT + 1]) + char Stem[Cns_MAX_BYTES_TEXT + 1]) { extern const char *Hlp_ASSESSMENT_Surveys_questions; extern const char *The_ClassFormInBox[The_NUM_THEMES]; @@ -2430,28 +2322,14 @@ static void Svy_ShowFormEditOneQst (struct Svy_Surveys *Surveys, { if ((SvyQst->QstCod > 0)) // If parameter QstCod received ==> question already exists in the database { - /***** Get the type of answer and the stem from the database *****/ - /* Get the question from database */ - DB_QuerySELECT (&mysql_res,"can not get a question", - "SELECT QstInd," // row[0] - "AnsType," // row[1] - "Stem" // row[2] - " FROM svy_questions" - " WHERE QstCod=%ld" - " AND SvyCod=%ld", - SvyQst->QstCod, - SvyCod); - - row = mysql_fetch_row (mysql_res); - - /* Get question index inside survey (row[0]) */ - SvyQst->QstInd = Str_ConvertStrToUnsigned (row[0]); - - /* Get the type of answer (row[1]) */ - SvyQst->AnswerType = Svy_ConvertFromStrAnsTypDBToAnsTyp (row[1]); - - /* Get the stem of the question from the database (row[2]) */ - Str_Copy (Txt,row[2],Cns_MAX_BYTES_TEXT); + /***** Get question data from database *****/ + if (Svy_DB_GetQstDataByCod (&mysql_res,SvyQst->QstCod,SvyCod)) + { + row = mysql_fetch_row (mysql_res); + Svy_GetDataOfQstFromRow (SvyQst,Stem,row); + } + else + Err_WrongQuestionExit (); /* Free structure that stores the query result */ DB_FreeMySQLResult (&mysql_res); @@ -2514,7 +2392,7 @@ static void Svy_ShowFormEditOneQst (struct Svy_Surveys *Surveys, /* Data */ HTM_TD_Begin ("class=\"LT\""); HTM_TEXTAREA_Begin ("id=\"Txt\" name=\"Txt\" cols=\"60\" rows=\"4\""); - HTM_Txt (Txt); + HTM_Txt (Stem); HTM_TEXTAREA_End (); HTM_TD_End (); @@ -2638,23 +2516,6 @@ static long Svy_GetParamQstCod (void) return Par_GetParToLong ("QstCod"); } -/*****************************************************************************/ -/*********** Convert a string with the answer type to answer type ************/ -/*****************************************************************************/ - -static Svy_AnswerType_t Svy_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeBD) - { - Svy_AnswerType_t AnsType; - - for (AnsType = (Svy_AnswerType_t) 0; - AnsType <= (Svy_AnswerType_t) (Svy_NUM_ANS_TYPES - 1); - AnsType++) - if (!strcmp (StrAnsTypeBD,Svy_StrAnswerTypesDB[AnsType])) - return AnsType; - - return (Svy_AnswerType_t) 0; - } - /*****************************************************************************/ /******************* Allocate memory for a choice answer *********************/ /*****************************************************************************/ @@ -2713,7 +2574,7 @@ void Svy_ReceiveQst (void) struct Svy_Surveys Surveys; struct Svy_Question SvyQst; long SvyCod; - char Txt[Cns_MAX_BYTES_TEXT + 1]; + char Stem[Cns_MAX_BYTES_TEXT + 1]; unsigned NumAns; char AnsStr[8 + 10 + 1]; unsigned NumLastAns; @@ -2742,7 +2603,7 @@ void Svy_ReceiveQst (void) (unsigned long) Svy_ANSWER_TYPE_DEFAULT); /* Get question text */ - Par_GetParToHTML ("Txt",Txt,Cns_MAX_BYTES_TEXT); + Par_GetParToHTML ("Txt",Stem,Cns_MAX_BYTES_TEXT); /* Get the texts of the answers */ for (NumAns = 0; @@ -2757,7 +2618,7 @@ void Svy_ReceiveQst (void) } /***** Make sure that stem and answer are not empty *****/ - if (Txt[0]) + if (Stem[0]) { if (SvyQst.AnsChoice[0].Text[0]) // If the first answer has been filled { @@ -2798,37 +2659,19 @@ void Svy_ReceiveQst (void) } if (Error) - Svy_ShowFormEditOneQst (&Surveys,SvyCod,&SvyQst,Txt); + Svy_ShowFormEditOneQst (&Surveys,SvyCod,&SvyQst,Stem); else { /***** Form is received OK ==> insert question and answer in the database *****/ if (SvyQst.QstCod < 0) // It's a new question { SvyQst.QstInd = Svy_GetNextQuestionIndexInSvy (SvyCod); - - /* Insert question in the table of questions */ - SvyQst.QstCod = - DB_QueryINSERTandReturnCode ("can not create question", - "INSERT INTO svy_questions" - " (SvyCod,QstInd,AnsType,Stem)" - " VALUES" - " (%ld,%u,'%s','%s')", - SvyCod,SvyQst.QstInd, - Svy_StrAnswerTypesDB[SvyQst.AnswerType], - Txt); + SvyQst.QstCod = Svy_DB_CreateQuestion (SvyCod,SvyQst.QstInd, + SvyQst.AnswerType,Stem); } else // It's an existing question /* Update question */ - DB_QueryUPDATE ("can not update question", - "UPDATE svy_questions" - " SET Stem='%s'," - "AnsType='%s'" - " WHERE QstCod=%ld" - " AND SvyCod=%ld", - Txt, - Svy_StrAnswerTypesDB[SvyQst.AnswerType], - SvyQst.QstCod, - SvyCod); + Svy_DB_UpdateQuestion (SvyCod,SvyQst.QstCod,SvyQst.AnswerType,Stem); /* Insert, update or delete answers in the answers table */ for (NumAns = 0; @@ -2838,34 +2681,18 @@ void Svy_ReceiveQst (void) { if (SvyQst.AnsChoice[NumAns].Text[0]) // Answer is not empty /* Update answer text */ - DB_QueryUPDATE ("can not update answer", - "UPDATE svy_answers" - " SET Answer='%s'" - " WHERE QstCod=%ld" - " AND AnsInd=%u", - SvyQst.AnsChoice[NumAns].Text, - SvyQst.QstCod,NumAns); - else // Answer is empty + Svy_DB_UpdateAnswerText (SvyQst.QstCod,NumAns, + SvyQst.AnsChoice[NumAns].Text); + else // Answer is empty /* Delete answer from database */ - DB_QueryDELETE ("can not delete answer", - "DELETE FROM svy_answers" - " WHERE QstCod=%ld" - " AND AnsInd=%u", - SvyQst.QstCod, - NumAns); + Svy_DB_RemoveAnswerQst (SvyQst.QstCod,NumAns); } else // If this answer does not exist... { if (SvyQst.AnsChoice[NumAns].Text[0]) // Answer is not empty /* Create answer into database */ - DB_QueryINSERT ("can not create answer", - "INSERT INTO svy_answers" - " (QstCod,AnsInd,NumUsrs,Answer)" - " VALUES" - " (%ld,%u,0,'%s')", - SvyQst.QstCod, - NumAns, - SvyQst.AnsChoice[NumAns].Text); + Svy_DB_CreateAnswer (SvyQst.QstCod,NumAns, + SvyQst.AnsChoice[NumAns].Text); } /***** List the questions of this survey, including the new one just inserted into the database *****/ @@ -2889,20 +2716,16 @@ static unsigned Svy_GetNextQuestionIndexInSvy (long SvyCod) MYSQL_ROW row; unsigned QstInd = 0; - /***** Get number of surveys with a field value from database *****/ - DB_QuerySELECT (&mysql_res,"can not get last question index", - "SELECT MAX(QstInd)" // row[0] - " FROM svy_questions" - " WHERE SvyCod=%ld", - SvyCod); - - /***** Get number of users *****/ - row = mysql_fetch_row (mysql_res); - if (row[0]) // There are questions + /***** Get last question index *****/ + if (Svy_DB_GetLastQstInd (&mysql_res,SvyCod)) { - if (sscanf (row[0],"%u",&QstInd) != 1) - Err_ShowErrorAndExit ("Error when getting last question index."); - QstInd++; + row = mysql_fetch_row (mysql_res); + if (row[0]) // There are questions + { + if (sscanf (row[0],"%u",&QstInd) != 1) + Err_WrongQuestionIndexExit (); + QstInd++; + } } /***** Free structure that stores the query result *****/ @@ -2931,6 +2754,7 @@ static void Svy_ListSvyQuestions (struct Svy_Surveys *Surveys, unsigned NumQsts; unsigned NumQst; struct Svy_Question SvyQst; + char Stem[Cns_MAX_BYTES_TEXT + 1]; bool Editing = (Gbl.Action.Act == ActEdiOneSvy || Gbl.Action.Act == ActEdiOneSvyQst || Gbl.Action.Act == ActRcvSvyQst); @@ -2976,14 +2800,12 @@ static void Svy_ListSvyQuestions (struct Svy_Surveys *Surveys, { Gbl.RowEvenOdd = (int) (NumQst % 2); - row = mysql_fetch_row (mysql_res); - /* Initialize question to zero */ Svy_InitQst (&SvyQst); - /* row[0] holds the code of the question */ - if (sscanf (row[0],"%ld",&(SvyQst.QstCod)) != 1) - Err_WrongQuestionExit (); + /* Get question data from row */ + row = mysql_fetch_row (mysql_res); + Svy_GetDataOfQstFromRow (&SvyQst,Stem,row); HTM_TR_Begin (NULL); @@ -3006,21 +2828,19 @@ static void Svy_ListSvyQuestions (struct Svy_Surveys *Surveys, HTM_TD_End (); } - /* Write index of question inside survey (row[1]) */ + /* Write index of question inside survey */ HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd); - SvyQst.QstInd = Str_ConvertStrToUnsigned (row[1]); HTM_Unsigned (SvyQst.QstInd + 1); HTM_TD_End (); /* Write the question type (row[2]) */ HTM_TD_Begin ("class=\"DAT_SMALL CT COLOR%u\"",Gbl.RowEvenOdd); - SvyQst.AnswerType = Svy_ConvertFromStrAnsTypDBToAnsTyp (row[2]); HTM_Txt (Txt_SURVEY_STR_ANSWER_TYPES[SvyQst.AnswerType]); HTM_TD_End (); - /* Write the stem (row[3]) and the answers of this question */ + /* Write the stem and the answers of this question */ HTM_TD_Begin ("class=\"DAT LT COLOR%u\"",Gbl.RowEvenOdd); - Svy_WriteQstStem (row[3]); + Svy_WriteQstStem (Stem); Svy_WriteAnswersOfAQst (Svy,&SvyQst,PutFormAnswerSurvey); HTM_TD_End (); @@ -3054,6 +2874,28 @@ static void Svy_ListSvyQuestions (struct Svy_Surveys *Surveys, Box_BoxEnd (); } +/*****************************************************************************/ +/************************* Get question data from row ************************/ +/*****************************************************************************/ + +static void Svy_GetDataOfQstFromRow (struct Svy_Question *SvyQst, + char Stem[Cns_MAX_BYTES_TEXT + 1], + MYSQL_ROW row) + { + /***** Get the code of the question (row[0]) *****/ + if (sscanf (row[0],"%ld",&(SvyQst->QstCod)) != 1) + Err_WrongQuestionExit (); + + /***** Get the index of the question inside the survey (row[1]) *****/ + SvyQst->QstInd = Str_ConvertStrToUnsigned (row[1]); + + /***** Get the answer type (row[2]) *****/ + SvyQst->AnswerType = Svy_DB_ConvertFromStrAnsTypDBToAnsTyp (row[2]); + + /***** Get the stem of the question from the database (row[2]) *****/ + Str_Copy (Stem,row[2],Cns_MAX_BYTES_TEXT); + } + /*****************************************************************************/ /******************** Put parameters to edit a question **********************/ /*****************************************************************************/ diff --git a/swad_survey.h b/swad_survey.h index a1cb849c..e0d1dcb6 100644 --- a/swad_survey.h +++ b/swad_survey.h @@ -36,12 +36,6 @@ #define Svy_MAX_CHARS_SURVEY_TITLE (128 - 1) // 127 #define Svy_MAX_BYTES_SURVEY_TITLE ((Svy_MAX_CHARS_SURVEY_TITLE + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 2047 -#define Svy_NUM_DATES 2 -typedef enum - { - Svy_START_TIME = 0, - Svy_END_TIME = 1, - } Svy_StartOrEndTime_t; #define Svy_ORDER_DEFAULT Dat_STR_TIME struct Svy_Surveys @@ -63,7 +57,7 @@ struct Svy_Survey unsigned Roles; // Example: if survey can be made by students, Roles == (1 << Rol_STD) long UsrCod; char Title[Svy_MAX_BYTES_SURVEY_TITLE + 1]; - time_t TimeUTC[Svy_NUM_DATES]; + time_t TimeUTC[Dat_NUM_START_END_TIME]; unsigned NumQsts; // Number of questions in the survey unsigned NumUsrs; // Number of distinct users who have already answered the survey struct diff --git a/swad_survey_database.c b/swad_survey_database.c index 95839797..e9bd4f32 100644 --- a/swad_survey_database.c +++ b/swad_survey_database.c @@ -30,7 +30,7 @@ // #include // For NULL #include // For asprintf #include // For free -// #include // For string functions +#include // For string functions // #include "swad_attendance.h" // #include "swad_box.h" @@ -61,6 +61,12 @@ extern struct Globals Gbl; /***************************** Private constants *****************************/ /*****************************************************************************/ +const char *Svy_DB_StrAnswerTypes[Svy_NUM_ANS_TYPES] = + { + [Svy_ANS_UNIQUE_CHOICE ] = "unique_choice", + [Svy_ANS_MULTIPLE_CHOICE] = "multiple_choice", + }; + /*****************************************************************************/ /******************************* Private types *******************************/ /*****************************************************************************/ @@ -73,6 +79,73 @@ extern struct Globals Gbl; /***************************** Private prototypes ****************************/ /*****************************************************************************/ +/*****************************************************************************/ +/*************************** Create a new survey *****************************/ +/*****************************************************************************/ + +long Svy_DB_CreateSurvey (const struct Svy_Survey *Svy,const char *Txt) + { + return + DB_QueryINSERTandReturnCode ("can not create new survey", + "INSERT INTO svy_surveys" + " (Scope,Cod,Hidden,Roles,UsrCod," + "StartTime,EndTime," + "Title,Txt)" + " VALUES" + " ('%s',%ld,'N',%u,%ld," + "FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld)," + "'%s','%s')", + Sco_GetDBStrFromScope (Svy->Scope), + Svy->Cod, + Svy->Roles, + Gbl.Usrs.Me.UsrDat.UsrCod, + Svy->TimeUTC[Dat_STR_TIME], + Svy->TimeUTC[Dat_END_TIME], + Svy->Title, + Txt); + } + +/*****************************************************************************/ +/************************* Update an existing survey *************************/ +/*****************************************************************************/ + +void Svy_DB_UpdateSurvey (const struct Svy_Survey *Svy,const char *Txt) + { + DB_QueryUPDATE ("can not update survey", + "UPDATE svy_surveys" + " SET Scope='%s'," + "Cod=%ld," + "Roles=%u," + "StartTime=FROM_UNIXTIME(%ld)," + "EndTime=FROM_UNIXTIME(%ld)," + "Title='%s'," + "Txt='%s'" + " WHERE SvyCod=%ld", + Sco_GetDBStrFromScope (Svy->Scope), + Svy->Cod, + Svy->Roles, + Svy->TimeUTC[Dat_STR_TIME], + Svy->TimeUTC[Dat_END_TIME], + Svy->Title, + Txt, + Svy->SvyCod); + } + +/*****************************************************************************/ +/****************************** Hide a project *******************************/ +/*****************************************************************************/ + +void Svy_DB_HideOrUnhideSurvey (long SvyCod,bool Hide) + { + DB_QueryUPDATE ("can not hide/unhide survey", + "UPDATE svy_surveys" + " SET Hidden='%c'" + " WHERE SvyCod=%ld", + Hide ? 'Y' : + 'N', + SvyCod); + } + /*****************************************************************************/ /*********** Update number of users notified in table of surveys *************/ /*****************************************************************************/ @@ -634,6 +707,58 @@ void Svy_DB_RemoveSvy (long SvyCod) SvyCod); } +/*****************************************************************************/ +/************* Remove all surveys of a place on the hierarchy **************/ +/************* (country, institution, center, degree or course) **************/ +/*****************************************************************************/ + +void Svy_DB_RemoveSvysIn (HieLvl_Level_t Scope,long Cod) + { + DB_QueryDELETE ("can not remove all the surveys" + " in a place on the hierarchy", + "DELETE FROM svy_surveys" + " WHERE Scope='%s'" + " AND Cod=%ld", + Sco_GetDBStrFromScope (Scope), + Cod); + } + +/*****************************************************************************/ +/************************ Create groups of a survey **************************/ +/*****************************************************************************/ + +void Svy_DB_CreateGrp (long SvyCod,long GrpCod) + { + DB_QueryINSERT ("can not associate a group to a survey", + "INSERT INTO svy_groups" + " (SvyCod,GrpCod)" + " VALUES" + " (%ld,%ld)", + SvyCod, + GrpCod); + } + +/*****************************************************************************/ +/****************** Get group names associated to a survey *******************/ +/*****************************************************************************/ + +unsigned Svy_DB_GetGrpNamesAssociatedToSvy (MYSQL_RES **mysql_res,long SvyCod) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get groups of a survey", + "SELECT grp_types.GrpTypName," // row[0] + "grp_groups.GrpName" // row[1] + " FROM svy_groups," + "grp_groups," + "grp_types" + " WHERE svy_groups.SvyCod=%ld" + " AND svy_groups.GrpCod=grp_groups.GrpCod" + " AND grp_groups.GrpTypCod=grp_types.GrpTypCod" + " ORDER BY grp_types.GrpTypName," + "grp_groups.GrpName", + SvyCod); + } + /*****************************************************************************/ /************ Check if I belong to any of the groups of a survey *************/ /*****************************************************************************/ @@ -658,18 +783,6 @@ bool Svy_DB_CheckIfICanDoThisSurveyBasedOnGrps (long SvyCod) Gbl.Usrs.Me.UsrDat.UsrCod) != 0); } -/*****************************************************************************/ -/************************* Remove groups of a survey *************************/ -/*****************************************************************************/ - -void Svy_DB_RemoveGrpsAssociatedToSurvey (long SvyCod) - { - DB_QueryDELETE ("can not remove the groups associated to a survey", - "DELETE FROM svy_groups" - " WHERE SvyCod=%ld", - SvyCod); - } - /*****************************************************************************/ /*************** Remove groups of one type from all the surveys **************/ /*****************************************************************************/ @@ -701,6 +814,77 @@ void Svy_DB_RemoveGroup (long GrpCod) GrpCod); } +/*****************************************************************************/ +/************************* Remove groups of a survey *************************/ +/*****************************************************************************/ + +void Svy_DB_RemoveGrpsAssociatedToSurvey (long SvyCod) + { + DB_QueryDELETE ("can not remove the groups associated to a survey", + "DELETE FROM svy_groups" + " WHERE SvyCod=%ld", + SvyCod); + } + +/*****************************************************************************/ +/********** Remove groups of all surveys of a place on the hierarchy *********/ +/********** (country, institution, center, degree or course) *********/ +/*****************************************************************************/ + +void Svy_DB_RemoveGrpsSvysIn (HieLvl_Level_t Scope,long Cod) + { + DB_QueryDELETE ("can not remove all the groups" + " associated to surveys of a course", + "DELETE FROM svy_groups" + " USING svy_surveys," + "svy_groups" + " WHERE svy_surveys.Scope='%s'" + " AND svy_surveys.Cod=%ld" + " AND svy_surveys.SvyCod=svy_groups.SvyCod", + Sco_GetDBStrFromScope (Scope), + Cod); + } + +/*****************************************************************************/ +/*************************** Create a new question ***************************/ +/*****************************************************************************/ + +long Svy_DB_CreateQuestion (long SvyCod,unsigned QstInd, + Svy_AnswerType_t AnswerType, + const char Stem[Cns_MAX_BYTES_TEXT + 1]) + { + return + DB_QueryINSERTandReturnCode ("can not create question", + "INSERT INTO svy_questions" + " (SvyCod,QstInd,AnsType,Stem)" + " VALUES" + " (%ld,%u,'%s','%s')", + SvyCod, + QstInd, + Svy_DB_StrAnswerTypes[AnswerType], + Stem); + } + +/*****************************************************************************/ +/************************ Create an existing question ************************/ +/*****************************************************************************/ + +void Svy_DB_UpdateQuestion (long SvyCod,long QstCod, + Svy_AnswerType_t AnswerType, + const char Stem[Cns_MAX_BYTES_TEXT + 1]) + { + DB_QueryUPDATE ("can not update question", + "UPDATE svy_questions" + " SET Stem='%s'," + "AnsType='%s'" + " WHERE QstCod=%ld" + " AND SvyCod=%ld", // Extra check + Stem, + Svy_DB_StrAnswerTypes[AnswerType], + QstCod, + SvyCod); + } + /*****************************************************************************/ /*********** Change indexes of questions greater than a given one ************/ /*****************************************************************************/ @@ -763,6 +947,24 @@ unsigned Svy_DB_GetSurveyQsts (MYSQL_RES **mysql_res,long SvyCod) SvyCod); } +/*****************************************************************************/ +/************ Get question data from question code in a survey ***************/ +/*****************************************************************************/ + +unsigned Svy_DB_GetQstDataByCod (MYSQL_RES **mysql_res,long QstCod,long SvyCod) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get a question", + "SELECT QstInd," // row[0] + "AnsType," // row[1] + "Stem" // row[2] + " FROM svy_questions" + " WHERE QstCod=%ld" + " AND SvyCod=%ld", // Extra check + QstCod, + SvyCod); + } + /*****************************************************************************/ /************ Get question index from question code in a survey **************/ /*****************************************************************************/ @@ -776,6 +978,20 @@ unsigned Svy_DB_GetQstIndFromQstCod (long QstCod) QstCod); } +/*****************************************************************************/ +/*********************** Get last question index *****************************/ +/*****************************************************************************/ + +unsigned Svy_DB_GetLastQstInd (MYSQL_RES **mysql_res,long SvyCod) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get last question index", + "SELECT MAX(QstInd)" // row[0] + " FROM svy_questions" + " WHERE SvyCod=%ld", + SvyCod); + } + /*****************************************************************************/ /****************************** Remove a question ****************************/ /*****************************************************************************/ @@ -800,6 +1016,57 @@ void Svy_DB_RemoveQstsSvy (long SvyCod) SvyCod); } +/*****************************************************************************/ +/******** Remove questions in all surveys of a place on the hierarchy ********/ +/******** (country, institution, center, degree or course) ********/ +/*****************************************************************************/ + +void Svy_DB_RemoveQstsSvysIn (HieLvl_Level_t Scope,long Cod) + { + DB_QueryDELETE ("can not remove questions of surveys" + " in a place on the hierarchy", + "DELETE FROM svy_questions" + " USING svy_surveys," + "svy_questions" + " WHERE svy_surveys.Scope='%s'" + " AND svy_surveys.Cod=%ld" + " AND svy_surveys.SvyCod=svy_questions.SvyCod", + Sco_GetDBStrFromScope (Scope), + Cod); + } + +/*****************************************************************************/ +/******************************* Create answer *******************************/ +/*****************************************************************************/ + +void Svy_DB_CreateAnswer (long QstCod,unsigned AnsInd,const char *Text) + { + DB_QueryINSERT ("can not create answer", + "INSERT INTO svy_answers" + " (QstCod,AnsInd,NumUsrs,Answer)" + " VALUES" + " (%ld,%u,0,'%s')", + QstCod, + AnsInd, + Text); + } + +/*****************************************************************************/ +/**************************** Update answer text *****************************/ +/*****************************************************************************/ + +void Svy_DB_UpdateAnswerText (long QstCod,unsigned AnsInd,const char *Text) + { + DB_QueryUPDATE ("can not update answer", + "UPDATE svy_answers" + " SET Answer='%s'" + " WHERE QstCod=%ld" + " AND AnsInd=%u", + Text, + QstCod, + AnsInd); + } + /*****************************************************************************/ /********************** Reset all answers in a survey ************************/ /*****************************************************************************/ @@ -871,6 +1138,37 @@ unsigned Svy_DB_GetAnswersQst (MYSQL_RES **mysql_res,long QstCod) return NumAnswers; } +/*****************************************************************************/ +/*********** Convert a string with the answer type to answer type ************/ +/*****************************************************************************/ + +Svy_AnswerType_t Svy_DB_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeDB) + { + Svy_AnswerType_t AnsType; + + for (AnsType = (Svy_AnswerType_t) 0; + AnsType <= (Svy_AnswerType_t) (Svy_NUM_ANS_TYPES - 1); + AnsType++) + if (!strcmp (StrAnsTypeDB,Svy_DB_StrAnswerTypes[AnsType])) + return AnsType; + + return (Svy_AnswerType_t) 0; + } + +/*****************************************************************************/ +/********************** Remove an answer from a question *********************/ +/*****************************************************************************/ + +void Svy_DB_RemoveAnswerQst (long QstCod,unsigned AnsInd) + { + DB_QueryDELETE ("can not delete answer", + "DELETE FROM svy_answers" + " WHERE QstCod=%ld" + " AND AnsInd=%u", + QstCod, + AnsInd); + } + /*****************************************************************************/ /********************* Remove answers of a survey question *******************/ /*****************************************************************************/ @@ -898,6 +1196,27 @@ void Svy_DB_RemoveAnswersSvy (long SvyCod) SvyCod); } +/*****************************************************************************/ +/********* Remove answers to all surveys of a place on the hierarchy *********/ +/********* (country, institution, center, degree or course) *********/ +/*****************************************************************************/ + +void Svy_DB_RemoveAnswersSvysIn (HieLvl_Level_t Scope,long Cod) + { + DB_QueryDELETE ("can not remove answers of surveys" + " in a place on the hierarchy", + "DELETE FROM svy_answers" + " USING svy_surveys," + "svy_questions," + "svy_answers" + " WHERE svy_surveys.Scope='%s'" + " AND svy_surveys.Cod=%ld" + " AND svy_surveys.SvyCod=svy_questions.SvyCod" + " AND svy_questions.QstCod=svy_answers.QstCod", + Sco_GetDBStrFromScope (Scope), + Cod); + } + /*****************************************************************************/ /***************** Register that I have answered this survey *****************/ /*****************************************************************************/ @@ -943,7 +1262,7 @@ unsigned Svy_DB_GetNumUsrsWhoHaveAnsweredSvy (long SvyCod) } /*****************************************************************************/ -/******************** Remove all the users in this survey ********************/ +/********************** Remove all users in this survey **********************/ /*****************************************************************************/ void Svy_DB_RemoveUsrsWhoHaveAnsweredSvy (long SvyCod) @@ -953,3 +1272,22 @@ void Svy_DB_RemoveUsrsWhoHaveAnsweredSvy (long SvyCod) " WHERE SvyCod=%ld", SvyCod); } + +/*****************************************************************************/ +/************ Remove all the surveys of a place on the hierarchy *************/ +/************ (country, institution, center, degree or course) *************/ +/*****************************************************************************/ + +void Svy_DB_RemoveUsrsWhoHaveAnsweredSvysIn (HieLvl_Level_t Scope,long Cod) + { + DB_QueryDELETE ("can not remove users" + " who had answered surveys in a place on the hierarchy", + "DELETE FROM svy_users" + " USING svy_surveys," + "svy_users" + " WHERE svy_surveys.Scope='%s'" + " AND svy_surveys.Cod=%ld" + " AND svy_surveys.SvyCod=svy_users.SvyCod", + Sco_GetDBStrFromScope (Scope), + Cod); + } diff --git a/swad_survey_database.h b/swad_survey_database.h index cc820b58..288418b1 100644 --- a/swad_survey_database.h +++ b/swad_survey_database.h @@ -41,8 +41,12 @@ /*****************************************************************************/ //-------------------------------- Surveys ------------------------------------ +long Svy_DB_CreateSurvey (const struct Svy_Survey *Svy,const char *Txt); +void Svy_DB_UpdateSurvey (const struct Svy_Survey *Svy,const char *Txt); +void Svy_DB_HideOrUnhideSurvey (long SvyCod,bool Hide); void Svy_DB_UpdateNumUsrsNotifiedByEMailAboutSurvey (long SvyCod, unsigned NumUsrsToBeNotifiedByEMail); + unsigned Svy_DB_GetListSurveys (MYSQL_RES **mysql_res, unsigned ScopesAllowed, unsigned HiddenAllowed, @@ -57,34 +61,53 @@ double Svy_DB_GetNumQstsPerCrsSurvey (HieLvl_Level_t Scope); unsigned Svy_DB_GetUsrsFromSurveyExceptMe (MYSQL_RES **mysql_res,long SvyCod); void Svy_DB_RemoveSvy (long SvyCod); +void Svy_DB_RemoveSvysIn (HieLvl_Level_t Scope,long Cod); //---------------------------- Surveys groups --------------------------------- +void Svy_DB_CreateGrp (long SvyCod,long GrpCod); + +unsigned Svy_DB_GetGrpNamesAssociatedToSvy (MYSQL_RES **mysql_res,long SvyCod); bool Svy_DB_CheckIfICanDoThisSurveyBasedOnGrps (long SvyCod); -void Svy_DB_RemoveGrpsAssociatedToSurvey (long SvyCod); void Svy_DB_RemoveGroupsOfType (long GrpTypCod); void Svy_DB_RemoveGroup (long GrpCod); +void Svy_DB_RemoveGrpsAssociatedToSurvey (long SvyCod); +void Svy_DB_RemoveGrpsSvysIn (HieLvl_Level_t Scope,long Cod); //--------------------------- Surveys questions ------------------------------- +long Svy_DB_CreateQuestion (long SvyCod,unsigned QstInd, + Svy_AnswerType_t AnswerType, + const char Stem[Cns_MAX_BYTES_TEXT + 1]); +void Svy_DB_UpdateQuestion (long SvyCod,long QstCod, + Svy_AnswerType_t AnswerType, + const char Stem[Cns_MAX_BYTES_TEXT + 1]); void Svy_DB_ChangeIndexesQsts (long SvyCod,unsigned QstInd); unsigned Svy_DB_GetNumQstsSvy (long SvyCod); unsigned Svy_DB_GetSurveyQstsCodes (MYSQL_RES **mysql_res,long SvyCod); unsigned Svy_DB_GetSurveyQsts (MYSQL_RES **mysql_res,long SvyCod); +unsigned Svy_DB_GetQstDataByCod (MYSQL_RES **mysql_res,long QstCod,long SvyCod); unsigned Svy_DB_GetQstIndFromQstCod (long QstCod); +unsigned Svy_DB_GetLastQstInd (MYSQL_RES **mysql_res,long SvyCod); void Svy_DB_RemoveQst (long QstCod); void Svy_DB_RemoveQstsSvy (long SvyCod); +void Svy_DB_RemoveQstsSvysIn (HieLvl_Level_t Scope,long Cod); //---------------------------- Surveys answers -------------------------------- +void Svy_DB_CreateAnswer (long QstCod,unsigned AnsInd,const char *Text); +void Svy_DB_UpdateAnswerText (long QstCod,unsigned AnsInd,const char *Text); void Svy_DB_ResetAnswersSvy (long SvyCod); void Svy_DB_IncreaseAnswer (long QstCod,unsigned AnsInd); bool Svy_DB_CheckIfAnswerExists (long QstCod,unsigned AnsInd); unsigned Svy_DB_GetAnswersQst (MYSQL_RES **mysql_res,long QstCod); +Svy_AnswerType_t Svy_DB_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeDB); +void Svy_DB_RemoveAnswerQst (long QstCod,unsigned AnsInd); void Svy_DB_RemoveAnswersQst (long QstCod); void Svy_DB_RemoveAnswersSvy (long SvyCod); +void Svy_DB_RemoveAnswersSvysIn (HieLvl_Level_t Scope,long Cod); //--------------------- Users who have answered surveys ----------------------- void Svy_DB_RegisterIHaveAnsweredSvy (long SvyCod); @@ -93,5 +116,6 @@ bool Svy_DB_CheckIfIHaveAnsweredSvy (long SvyCod); unsigned Svy_DB_GetNumUsrsWhoHaveAnsweredSvy (long SvyCod); void Svy_DB_RemoveUsrsWhoHaveAnsweredSvy (long SvyCod); +void Svy_DB_RemoveUsrsWhoHaveAnsweredSvysIn (HieLvl_Level_t Scope,long Cod); #endif