diff --git a/Makefile b/Makefile index e6308c34..9dc79378 100644 --- a/Makefile +++ b/Makefile @@ -27,8 +27,8 @@ ############################################################################### OBJS = swad_account.o swad_account_database.o swad_action.o swad_agenda.o \ - swad_alert.o swad_announcement.o swad_API.o swad_assignment.o \ - swad_attendance.o \ + swad_agenda_database.o swad_alert.o swad_announcement.o swad_API.o \ + swad_assignment.o swad_attendance.o \ swad_banner.o swad_box.o swad_building.o swad_button.o \ swad_calendar.o swad_call_for_exam.o swad_center.o \ swad_center_config.o swad_chat.o swad_config.o swad_connected.o \ diff --git a/swad_account.c b/swad_account.c index e6f21903..c77f20c9 100644 --- a/swad_account.c +++ b/swad_account.c @@ -29,7 +29,7 @@ #include "swad_account.h" #include "swad_account_database.h" -#include "swad_agenda.h" +#include "swad_agenda_database.h" #include "swad_announcement.h" #include "swad_attendance.h" #include "swad_box.h" @@ -157,23 +157,23 @@ static void Acc_ShowFormCheckIfIHaveAccount (const char *Title) NULL,NULL, Hlp_PROFILE_SignUp,Box_NOT_CLOSABLE); - /***** Help alert *****/ - Ale_ShowAlert (Ale_INFO,Txt_If_you_think_you_may_have_been_registered_); + /***** Help alert *****/ + Ale_ShowAlert (Ale_INFO,Txt_If_you_think_you_may_have_been_registered_); - /***** Form to request user's ID for possible account already created *****/ - Frm_BeginForm (ActChkUsrAcc); - HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]); - HTM_TxtColonNBSP (Txt_ID); - HTM_INPUT_TEXT ("ID",ID_MAX_CHARS_USR_ID,"",HTM_DONT_SUBMIT_ON_CHANGE, - "size=\"18\" required=\"required\""); - HTM_LABEL_End (); - Btn_PutCreateButtonInline (Txt_Check); - Frm_EndForm (); + /***** Form to request user's ID for possible account already created *****/ + Frm_BeginForm (ActChkUsrAcc); + HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]); + HTM_TxtColonNBSP (Txt_ID); + HTM_INPUT_TEXT ("ID",ID_MAX_CHARS_USR_ID,"",HTM_DONT_SUBMIT_ON_CHANGE, + "size=\"18\" required=\"required\""); + HTM_LABEL_End (); + Btn_PutCreateButtonInline (Txt_Check); + Frm_EndForm (); - /***** Form to skip this step *****/ - Frm_BeginForm (ActCreMyAcc); - Btn_PutConfirmButton (Txt_Skip_this_step); - Frm_EndForm (); + /***** Form to skip this step *****/ + Frm_BeginForm (ActCreMyAcc); + Btn_PutConfirmButton (Txt_Skip_this_step); + Frm_EndForm (); /***** End box *****/ Box_BoxEnd (); @@ -199,9 +199,9 @@ void Acc_CheckIfEmptyAccountExists (void) /***** Contextual menu *****/ Mnu_ContextMenuBegin (); - Usr_PutLinkToLogin (); - Pwd_PutLinkToSendNewPasswd (); - Lan_PutLinkToChangeLanguage (); + Usr_PutLinkToLogin (); + Pwd_PutLinkToSendNewPasswd (); + Lan_PutLinkToChangeLanguage (); Mnu_ContextMenuEnd (); /***** Get new user's ID from form *****/ @@ -341,9 +341,9 @@ void Acc_ShowFormCreateMyAccount (void) { /***** Contextual menu *****/ Mnu_ContextMenuBegin (); - Usr_PutLinkToLogin (); - Pwd_PutLinkToSendNewPasswd (); - Lan_PutLinkToChangeLanguage (); + Usr_PutLinkToLogin (); + Pwd_PutLinkToSendNewPasswd (); + Lan_PutLinkToChangeLanguage (); Mnu_ContextMenuEnd (); /**** Show form to create a new account *****/ @@ -374,46 +374,50 @@ static void Acc_ShowFormRequestNewAccountWithParams (const char NewNickWithoutAr NULL,NULL, Hlp_PROFILE_SignUp,Box_NOT_CLOSABLE,2); - /***** Nickname *****/ - if (NewNickWithoutArr[0]) - snprintf (NewNickWithArr,sizeof (NewNickWithArr),"@%s", - NewNickWithoutArr); - else - NewNickWithArr[0] = '\0'; - HTM_TR_Begin (NULL); + /***** Nickname *****/ + /* Begin table row */ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT","NewNick",Txt_Nickname); + /* Label */ + Frm_LabelColumn ("RT","NewNick",Txt_Nickname); - /* Data */ - HTM_TD_Begin ("class=\"LT\""); - HTM_INPUT_TEXT ("NewNick",1 + Nck_MAX_CHARS_NICK_WITHOUT_ARROBA, - NewNickWithArr,HTM_DONT_SUBMIT_ON_CHANGE, - "id=\"NewNick\" size=\"18\" placeholder=\"%s\"" - " required=\"required\"", - Txt_HELP_nickname); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"LT\""); + if (NewNickWithoutArr[0]) + snprintf (NewNickWithArr,sizeof (NewNickWithArr),"@%s", + NewNickWithoutArr); + else + NewNickWithArr[0] = '\0'; + HTM_INPUT_TEXT ("NewNick",1 + Nck_MAX_CHARS_NICK_WITHOUT_ARROBA, + NewNickWithArr,HTM_DONT_SUBMIT_ON_CHANGE, + "id=\"NewNick\" size=\"18\" placeholder=\"%s\"" + " required=\"required\"", + Txt_HELP_nickname); + HTM_TD_End (); - HTM_TR_End (); + /* End table row */ + HTM_TR_End (); - /***** Email *****/ - HTM_TR_Begin (NULL); + /***** Email *****/ + /* Begin table row */ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT","NewEmail",Txt_Email); + /* Label */ + Frm_LabelColumn ("RT","NewEmail",Txt_Email); - /* Data */ - HTM_TD_Begin ("class=\"LT\""); - HTM_INPUT_EMAIL ("NewEmail",Cns_MAX_CHARS_EMAIL_ADDRESS,NewEmail, - "id=\"NewEmail\" size=\"18\" placeholder=\"%s\"" - " required=\"required\"", - Txt_HELP_email); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"LT\""); + HTM_INPUT_EMAIL ("NewEmail",Cns_MAX_CHARS_EMAIL_ADDRESS,NewEmail, + "id=\"NewEmail\" size=\"18\" placeholder=\"%s\"" + " required=\"required\"", + Txt_HELP_email); + HTM_TD_End (); - HTM_TR_End (); + /* End table row */ + HTM_TR_End (); - /***** Password *****/ - Pwd_PutFormToGetNewPasswordOnce (); + /***** Password *****/ + Pwd_PutFormToGetNewPasswordOnce (); /***** End table, send button and end box *****/ Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_account); diff --git a/swad_account_database.c b/swad_account_database.c index 70539564..b4511d82 100644 --- a/swad_account_database.c +++ b/swad_account_database.c @@ -25,37 +25,10 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ -// #include // For string functions - #include "swad_account.h" #include "swad_account_database.h" -// #include "swad_agenda.h" -// #include "swad_announcement.h" -// #include "swad_attendance.h" -// #include "swad_box.h" #include "swad_calendar.h" -// #include "swad_database.h" -// #include "swad_duplicate.h" -// #include "swad_enrolment.h" -// #include "swad_error.h" -// #include "swad_exam_print.h" -// #include "swad_follow.h" -// #include "swad_form.h" -// #include "swad_forum.h" #include "swad_global.h" -// #include "swad_HTML.h" -// #include "swad_ID.h" -// #include "swad_language.h" -// #include "swad_match.h" -// #include "swad_message.h" -// #include "swad_nickname.h" -// #include "swad_notification.h" -// #include "swad_parameter.h" -// #include "swad_profile.h" -// #include "swad_project.h" -// #include "swad_report.h" -// #include "swad_test_print.h" -// #include "swad_timeline.h" /*****************************************************************************/ /****************************** Public constants *****************************/ @@ -131,7 +104,6 @@ bool Acc_DB_CheckIfEmailAlreadyExists (const char NewEmail[Cns_MAX_BYTES_EMAIL_A NewEmail) != 0); // An email of another user is the same that my email } - /*****************************************************************************/ /****************************** Create new user ******************************/ /*****************************************************************************/ @@ -145,10 +117,8 @@ void Acc_DB_CreateNewUsr (struct UsrData *UsrDat) extern const char *Usr_StringsSexDB[Usr_NUM_SEXS]; char BirthdayStrDB[Usr_BIRTHDAY_STR_DB_LENGTH + 1]; - /***** Create birthday string *****/ - Usr_CreateBirthdayStrDB (UsrDat,BirthdayStrDB); // It can include start and ending apostrophes - /***** Create new user *****/ + Usr_CreateBirthdayStrDB (UsrDat,BirthdayStrDB); // It can include start and ending apostrophes UsrDat->UsrCod = DB_QueryINSERTandReturnCode ("can not create user", "INSERT INTO usr_data" diff --git a/swad_agenda.c b/swad_agenda.c index 5a55c6ac..681bde57 100644 --- a/swad_agenda.c +++ b/swad_agenda.c @@ -33,6 +33,7 @@ #include // For string functions #include "swad_agenda.h" +#include "swad_agenda_database.h" #include "swad_box.h" #include "swad_database.h" #include "swad_date.h" @@ -68,15 +69,6 @@ static const char *ParamHiddenVisiblName = "HiddenVisibl"; /******************************* Private types *******************************/ /*****************************************************************************/ -#define Agd_NUM_AGENDA_TYPES 4 -typedef enum - { - Agd_MY_AGENDA_TODAY, - Agd_MY_AGENDA, - Agd_ANOTHER_AGENDA_TODAY, - Agd_ANOTHER_AGENDA, - } Agd_AgendaType_t; - /*****************************************************************************/ /***************************** Private variables *****************************/ /*****************************************************************************/ @@ -132,11 +124,6 @@ static void Agd_GetDataOfEventByCod (struct Agd_Event *AgdEvent); static void Agd_FreeListEvents (struct Agd_Agenda *Agenda); -static void Agd_GetEventTxtFromDB (struct Agd_Event *AgdEvent, - char Txt[Cns_MAX_BYTES_TEXT + 1]); -static void Agd_CreateEvent (struct Agd_Event *AgdEvent,const char *Txt); -static void Agd_UpdateEvent (struct Agd_Event *AgdEvent,const char *Txt); - /*****************************************************************************/ /*************************** Reset agenda context ****************************/ /*****************************************************************************/ @@ -203,18 +190,18 @@ static void Agd_ShowMyAgenda (struct Agd_Agenda *Agenda) Agd_PutIconsMyFullAgenda,Agenda, Hlp_PROFILE_Agenda,Box_NOT_CLOSABLE); - /***** Put forms to choice which events to show *****/ - Set_BeginSettingsHead (); - Agd_ShowFormToSelPast__FutureEvents (Agenda); - Agd_ShowFormToSelPrivatPublicEvents (Agenda); - Agd_ShowFormToSelHiddenVisiblEvents (Agenda); - Set_EndSettingsHead (); + /***** Put forms to choice which events to show *****/ + Set_BeginSettingsHead (); + Agd_ShowFormToSelPast__FutureEvents (Agenda); + Agd_ShowFormToSelPrivatPublicEvents (Agenda); + Agd_ShowFormToSelHiddenVisiblEvents (Agenda); + Set_EndSettingsHead (); - /***** Show the current events in the user's agenda *****/ - Agd_ShowEventsToday (Agenda,Agd_MY_AGENDA_TODAY); + /***** Show the current events in the user's agenda *****/ + Agd_ShowEventsToday (Agenda,Agd_MY_AGENDA_TODAY); - /***** Show all my events *****/ - Agd_ShowEvents (Agenda,Agd_MY_AGENDA); + /***** Show all my events *****/ + Agd_ShowEvents (Agenda,Agd_MY_AGENDA); /***** End box *****/ Box_BoxEnd (); @@ -242,16 +229,16 @@ static void Agd_ShowFormToSelPast__FutureEvents (const struct Agd_Agenda *Agenda HTM_DIV_Begin ("class=\"%s\"", (Agenda->Past__FutureEvents & (1 << PstFut)) ? "PREF_ON" : "PREF_OFF"); - Frm_BeginForm (ActSeeMyAgd); - Agd_PutParamsMyAgenda (Agenda->Past__FutureEvents ^ (1 << PstFut), // Toggle - Agenda->PrivatPublicEvents, - Agenda->HiddenVisiblEvents, - Agenda->SelectedOrder, - Agenda->CurrentPage, - -1L); - Ico_PutSettingIconLink (Icon[PstFut], - Txt_AGENDA_PAST___FUTURE_EVENTS[PstFut]); - Frm_EndForm (); + Frm_BeginForm (ActSeeMyAgd); + Agd_PutParamsMyAgenda (Agenda->Past__FutureEvents ^ (1 << PstFut), // Toggle + Agenda->PrivatPublicEvents, + Agenda->HiddenVisiblEvents, + Agenda->SelectedOrder, + Agenda->CurrentPage, + -1L); + Ico_PutSettingIconLink (Icon[PstFut], + Txt_AGENDA_PAST___FUTURE_EVENTS[PstFut]); + Frm_EndForm (); HTM_DIV_End (); } Set_EndOneSettingSelector (); @@ -279,16 +266,16 @@ static void Agd_ShowFormToSelPrivatPublicEvents (const struct Agd_Agenda *Agenda HTM_DIV_Begin ("class=\"%s\"", (Agenda->PrivatPublicEvents & (1 << PrvPub)) ? "PREF_ON" : "PREF_OFF"); - Frm_BeginForm (ActSeeMyAgd); - Agd_PutParamsMyAgenda (Agenda->Past__FutureEvents, - Agenda->PrivatPublicEvents ^ (1 << PrvPub), // Toggle - Agenda->HiddenVisiblEvents, - Agenda->SelectedOrder, - Agenda->CurrentPage, - -1L); - Ico_PutSettingIconLink (Icon[PrvPub], - Txt_AGENDA_PRIVAT_PUBLIC_EVENTS[PrvPub]); - Frm_EndForm (); + Frm_BeginForm (ActSeeMyAgd); + Agd_PutParamsMyAgenda (Agenda->Past__FutureEvents, + Agenda->PrivatPublicEvents ^ (1 << PrvPub), // Toggle + Agenda->HiddenVisiblEvents, + Agenda->SelectedOrder, + Agenda->CurrentPage, + -1L); + Ico_PutSettingIconLink (Icon[PrvPub], + Txt_AGENDA_PRIVAT_PUBLIC_EVENTS[PrvPub]); + Frm_EndForm (); HTM_DIV_End (); } Set_EndOneSettingSelector (); @@ -316,16 +303,16 @@ static void Agd_ShowFormToSelHiddenVisiblEvents (const struct Agd_Agenda *Agenda HTM_DIV_Begin ("class=\"%s\"", (Agenda->HiddenVisiblEvents & (1 << HidVis)) ? "PREF_ON" : "PREF_OFF"); - Frm_BeginForm (ActSeeMyAgd); - Agd_PutParamsMyAgenda (Agenda->Past__FutureEvents, - Agenda->PrivatPublicEvents, - Agenda->HiddenVisiblEvents ^ (1 << HidVis), // Toggle - Agenda->SelectedOrder, - Agenda->CurrentPage, - -1L); - Ico_PutSettingIconLink (Icon[HidVis], - Txt_AGENDA_HIDDEN_VISIBL_EVENTS[HidVis]); - Frm_EndForm (); + Frm_BeginForm (ActSeeMyAgd); + Agd_PutParamsMyAgenda (Agenda->Past__FutureEvents, + Agenda->PrivatPublicEvents, + Agenda->HiddenVisiblEvents ^ (1 << HidVis), // Toggle + Agenda->SelectedOrder, + Agenda->CurrentPage, + -1L); + Ico_PutSettingIconLink (Icon[HidVis], + Txt_AGENDA_HIDDEN_VISIBL_EVENTS[HidVis]); + Frm_EndForm (); HTM_DIV_End (); } Set_EndOneSettingSelector (); @@ -419,11 +406,11 @@ void Agd_ShowUsrAgenda (void) Hlp_PROFILE_Agenda_public_agenda,Box_NOT_CLOSABLE); Str_FreeString (); - /***** Show the current events in the user's agenda *****/ - Agd_ShowEventsToday (&Agenda,Agd_ANOTHER_AGENDA_TODAY); + /***** Show the current events in the user's agenda *****/ + Agd_ShowEventsToday (&Agenda,Agd_ANOTHER_AGENDA_TODAY); - /***** Show all the visible events in the user's agenda *****/ - Agd_ShowEvents (&Agenda,Agd_ANOTHER_AGENDA); + /***** Show all the visible events in the user's agenda *****/ + Agd_ShowEvents (&Agenda,Agd_ANOTHER_AGENDA); /***** End box *****/ Box_BoxEnd (); @@ -473,11 +460,11 @@ void Agd_ShowOtherAgendaAfterLogIn (void) Hlp_PROFILE_Agenda_public_agenda,Box_NOT_CLOSABLE); Str_FreeString (); - /***** Show the current events in the user's agenda *****/ - Agd_ShowEventsToday (&Agenda,Agd_ANOTHER_AGENDA_TODAY); + /***** Show the current events in the user's agenda *****/ + Agd_ShowEventsToday (&Agenda,Agd_ANOTHER_AGENDA_TODAY); - /***** Show all the visible events in the user's agenda *****/ - Agd_ShowEvents (&Agenda,Agd_ANOTHER_AGENDA); + /***** Show all the visible events in the user's agenda *****/ + Agd_ShowEvents (&Agenda,Agd_ANOTHER_AGENDA); /***** End box *****/ Box_BoxEnd (); @@ -534,14 +521,14 @@ static void Agd_ShowEvents (struct Agd_Agenda *Agenda, /***** Begin table *****/ HTM_TABLE_BeginWideMarginPadding (2); - /***** Table head *****/ - Agd_WriteHeaderListEvents (Agenda,AgendaType); + /***** Table head *****/ + Agd_WriteHeaderListEvents (Agenda,AgendaType); - /***** Write all the events *****/ - for (NumEvent = Pagination.FirstItemVisible; - NumEvent <= Pagination.LastItemVisible; - NumEvent++) - Agd_ShowOneEvent (Agenda,AgendaType,Agenda->LstAgdCods[NumEvent - 1]); + /***** Write all the events *****/ + for (NumEvent = Pagination.FirstItemVisible; + NumEvent <= Pagination.LastItemVisible; + NumEvent++) + Agd_ShowOneEvent (Agenda,AgendaType,Agenda->LstAgdCods[NumEvent - 1]); /***** End table *****/ HTM_TABLE_End (); @@ -603,14 +590,14 @@ static void Agd_ShowEventsToday (struct Agd_Agenda *Agenda, break; } - /***** Table head *****/ - Agd_WriteHeaderListEvents (Agenda,AgendaType); + /***** Table head *****/ + Agd_WriteHeaderListEvents (Agenda,AgendaType); - /***** Write all the events *****/ - for (NumEvent = 0; - NumEvent < Agenda->Num; - NumEvent++) - Agd_ShowOneEvent (Agenda,AgendaType,Agenda->LstAgdCods[NumEvent]); + /***** Write all the events *****/ + for (NumEvent = 0; + NumEvent < Agenda->Num; + NumEvent++) + Agd_ShowOneEvent (Agenda,AgendaType,Agenda->LstAgdCods[NumEvent]); /***** End table and box *****/ Box_BoxTableEnd (); @@ -636,46 +623,48 @@ static void Agd_WriteHeaderListEvents (const struct Agd_Agenda *Agenda, /***** Table head *****/ HTM_TR_Begin (NULL); - for (Order = Dat_START_TIME; - Order <= Dat_END_TIME; - Order++) - { - HTM_TH_Begin (1,1,"LM"); - switch (AgendaType) + for (Order = Dat_START_TIME; + Order <= Dat_END_TIME; + Order++) { - case Agd_MY_AGENDA_TODAY: - case Agd_MY_AGENDA: - Frm_BeginForm (ActSeeMyAgd); - Pag_PutHiddenParamPagNum (Pag_MY_AGENDA,Agenda->CurrentPage); - break; - case Agd_ANOTHER_AGENDA_TODAY: - case Agd_ANOTHER_AGENDA: - Frm_BeginForm (ActSeeUsrAgd); - Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod); - Pag_PutHiddenParamPagNum (Pag_ANOTHER_AGENDA,Agenda->CurrentPage); - break; + HTM_TH_Begin (1,1,"LM"); + switch (AgendaType) + { + case Agd_MY_AGENDA_TODAY: + case Agd_MY_AGENDA: + Frm_BeginForm (ActSeeMyAgd); + Pag_PutHiddenParamPagNum (Pag_MY_AGENDA,Agenda->CurrentPage); + break; + case Agd_ANOTHER_AGENDA_TODAY: + case Agd_ANOTHER_AGENDA: + Frm_BeginForm (ActSeeUsrAgd); + Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod); + Pag_PutHiddenParamPagNum (Pag_ANOTHER_AGENDA,Agenda->CurrentPage); + break; + } + Agd_PutParamsMyAgenda (Agenda->Past__FutureEvents, + Agenda->PrivatPublicEvents, + Agenda->HiddenVisiblEvents, + Order, + Agenda->CurrentPage, + -1L); + + HTM_BUTTON_SUBMIT_Begin (Txt_START_END_TIME_HELP[Order],"BT_LINK TIT_TBL",NULL); + if (Order == Agenda->SelectedOrder) + HTM_U_Begin (); + + HTM_Txt (Txt_START_END_TIME[Order]); + + if (Order == Agenda->SelectedOrder) + HTM_U_End (); + HTM_BUTTON_End (); + + Frm_EndForm (); + HTM_TH_End (); } - Agd_PutParamsMyAgenda (Agenda->Past__FutureEvents, - Agenda->PrivatPublicEvents, - Agenda->HiddenVisiblEvents, - Order, - Agenda->CurrentPage, - -1L); - HTM_BUTTON_SUBMIT_Begin (Txt_START_END_TIME_HELP[Order],"BT_LINK TIT_TBL",NULL); - if (Order == Agenda->SelectedOrder) - HTM_U_Begin (); - HTM_Txt (Txt_START_END_TIME[Order]); - if (Order == Agenda->SelectedOrder) - HTM_U_End (); - HTM_BUTTON_End (); - - Frm_EndForm (); - HTM_TH_End (); - } - - HTM_TH (1,1,"LM",Txt_Event); - HTM_TH (1,1,"LM",Txt_Location); + HTM_TH (1,1,"LM",Txt_Event); + HTM_TH (1,1,"LM",Txt_Location); HTM_TR_End (); } @@ -767,6 +756,7 @@ static void Agd_PutButtonToCreateNewEvent (const struct Agd_Agenda *Agenda) { extern const char *Txt_New_event; + /***** Begin form *****/ Frm_BeginForm (ActFrmNewEvtMyAgd); Agd_PutParamsMyAgenda (Agenda->Past__FutureEvents, Agenda->PrivatPublicEvents, @@ -774,7 +764,11 @@ static void Agd_PutButtonToCreateNewEvent (const struct Agd_Agenda *Agenda) Agenda->SelectedOrder, Agenda->CurrentPage, -1L); - Btn_PutConfirmButton (Txt_New_event); + + /***** Confirm button *****/ + Btn_PutConfirmButton (Txt_New_event); + + /***** End form *****/ Frm_EndForm (); } @@ -815,74 +809,73 @@ static void Agd_ShowOneEvent (struct Agd_Agenda *Agenda, /***** Write first row of data of this event *****/ HTM_TR_Begin (NULL); - /* Start/end date/time */ - UniqueId++; - for (StartEndTime = (Dat_StartEndTime_t) 0; - StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1); - StartEndTime++) - { - if (asprintf (&Id,"agd_date_%u_%u",(unsigned) StartEndTime,UniqueId) < 0) - Err_NotEnoughMemoryExit (); - HTM_TD_Begin ("id=\"%s\" class=\"%s LB COLOR%u\"", - Id, - AgdEvent.Hidden ? Dat_TimeStatusClassHidden[AgdEvent.TimeStatus] : - Dat_TimeStatusClassVisible[AgdEvent.TimeStatus], + /* Start/end date/time */ + UniqueId++; + for (StartEndTime = (Dat_StartEndTime_t) 0; + StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1); + StartEndTime++) + { + if (asprintf (&Id,"agd_date_%u_%u",(unsigned) StartEndTime,UniqueId) < 0) + Err_NotEnoughMemoryExit (); + HTM_TD_Begin ("id=\"%s\" class=\"%s LB COLOR%u\"", + Id, + AgdEvent.Hidden ? Dat_TimeStatusClassHidden[AgdEvent.TimeStatus] : + Dat_TimeStatusClassVisible[AgdEvent.TimeStatus], + Gbl.RowEvenOdd); + Dat_WriteLocalDateHMSFromUTC (Id,AgdEvent.TimeUTC[StartEndTime], + Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK, + true,true,true,0x6); + HTM_TD_End (); + free (Id); + } + + /* Event */ + HTM_TD_Begin ("class=\"%s LT COLOR%u\"", + AgdEvent.Hidden ? "ASG_TITLE_LIGHT" : + "ASG_TITLE", Gbl.RowEvenOdd); - Dat_WriteLocalDateHMSFromUTC (Id,AgdEvent.TimeUTC[StartEndTime], - Gbl.Prefs.DateFormat,Dat_SEPARATOR_BREAK, - true,true,true,0x6); + HTM_ARTICLE_Begin (Anchor); + HTM_Txt (AgdEvent.Event); + HTM_ARTICLE_End (); HTM_TD_End (); - free (Id); - } - /* Event */ - HTM_TD_Begin ("class=\"%s LT COLOR%u\"", - AgdEvent.Hidden ? "ASG_TITLE_LIGHT" : - "ASG_TITLE", - Gbl.RowEvenOdd); - HTM_ARTICLE_Begin (Anchor); - HTM_Txt (AgdEvent.Event); - HTM_ARTICLE_End (); - HTM_TD_End (); - - /* Location */ - HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd); - HTM_DIV_Begin ("class=\"%s\"",AgdEvent.Hidden ? "ASG_TITLE_LIGHT" : - "ASG_TITLE"); - HTM_Txt (AgdEvent.Location); - HTM_DIV_End (); - HTM_TD_End (); + /* Location */ + HTM_TD_Begin ("class=\"LT COLOR%u\"",Gbl.RowEvenOdd); + HTM_DIV_Begin ("class=\"%s\"",AgdEvent.Hidden ? "ASG_TITLE_LIGHT" : + "ASG_TITLE"); + HTM_Txt (AgdEvent.Location); + HTM_DIV_End (); + HTM_TD_End (); HTM_TR_End (); /***** Write second row of data of this event *****/ HTM_TR_Begin (NULL); - HTM_TD_Begin ("colspan=\"2\" class=\"LT COLOR%u\"",Gbl.RowEvenOdd); - switch (AgendaType) - { - case Agd_MY_AGENDA_TODAY: - case Agd_MY_AGENDA: - /* Forms to remove/edit this event */ - Agd_PutFormsToRemEditOneEvent (Agenda,&AgdEvent,Anchor); - break; - default: - break; - } - HTM_TD_End (); + HTM_TD_Begin ("colspan=\"2\" class=\"LT COLOR%u\"",Gbl.RowEvenOdd); + switch (AgendaType) + { + case Agd_MY_AGENDA_TODAY: + case Agd_MY_AGENDA: + /* Forms to remove/edit this event */ + Agd_PutFormsToRemEditOneEvent (Agenda,&AgdEvent,Anchor); + break; + default: + break; + } + HTM_TD_End (); - /* Text of the event */ - Agd_GetEventTxtFromDB (&AgdEvent,Txt); - Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - Txt,Cns_MAX_BYTES_TEXT,false); // Convert from HTML to recpectful HTML - Str_InsertLinks (Txt,Cns_MAX_BYTES_TEXT,60); // Insert links - - HTM_TD_Begin ("colspan=\"2\" class=\"LT COLOR%u\"",Gbl.RowEvenOdd); - HTM_DIV_Begin ("class=\"PAR %s\"",AgdEvent.Hidden ? "DAT_LIGHT" : - "DAT"); - HTM_Txt (Txt); - HTM_DIV_End (); - HTM_TD_End (); + /* Text of the event */ + HTM_TD_Begin ("colspan=\"2\" class=\"LT COLOR%u\"",Gbl.RowEvenOdd); + HTM_DIV_Begin ("class=\"PAR %s\"",AgdEvent.Hidden ? "DAT_LIGHT" : + "DAT"); + Agd_DB_GetEventTxt (&AgdEvent,Txt); + Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, + Txt,Cns_MAX_BYTES_TEXT,false); // Convert from HTML to recpectful HTML + Str_InsertLinks (Txt,Cns_MAX_BYTES_TEXT,60); // Insert links + HTM_Txt (Txt); + HTM_DIV_End (); + HTM_TD_End (); HTM_TR_End (); @@ -1045,24 +1038,13 @@ static void Agd_GetParamEventOrder (struct Agd_Agenda *Agenda) static void Agd_GetListEvents (struct Agd_Agenda *Agenda, Agd_AgendaType_t AgendaType) { - char *UsrSubQuery; - char Past__FutureEventsSubQuery[Agd_MAX_BYTES_SUBQUERY + 1]; - char PrivatPublicEventsSubQuery[Agd_MAX_BYTES_SUBQUERY + 1]; - char HiddenVisiblEventsSubQuery[Agd_MAX_BYTES_SUBQUERY + 1]; - static const char *OrderBySubQuery[Dat_NUM_START_END_TIME] = - { - [Dat_START_TIME] = "StartTime,EndTime,Event,Location", - [Dat_END_TIME ] = "EndTime,StartTime,Event,Location", - }; MYSQL_RES *mysql_res; unsigned NumEvent; - bool DoQuery = true; /***** Initialize list of events *****/ Agd_FreeListEvents (Agenda); - /***** Get list of events from database *****/ - /* Build events subqueries */ + /***** Trivial check: anything to get from database? *****/ switch (AgendaType) { case Agd_MY_AGENDA_TODAY: @@ -1070,122 +1052,36 @@ static void Agd_GetListEvents (struct Agd_Agenda *Agenda, if (Agenda->Past__FutureEvents == 0 || Agenda->PrivatPublicEvents == 0 || Agenda->HiddenVisiblEvents == 0) // All selectors are off - DoQuery = false; // Nothing to get from database - else { - if (asprintf (&UsrSubQuery,"UsrCod=%ld", - Gbl.Usrs.Me.UsrDat.UsrCod) < 0) - Err_NotEnoughMemoryExit (); - if (AgendaType == Agd_MY_AGENDA_TODAY) - Str_Copy (Past__FutureEventsSubQuery, - " AND DATE(StartTime)<=CURDATE()" - " AND DATE(EndTime)>=CURDATE()", - sizeof (Past__FutureEventsSubQuery) - 1); // Today events - else - switch (Agenda->Past__FutureEvents) - { - case (1 << Agd_PAST___EVENTS): - Str_Copy (Past__FutureEventsSubQuery, - " AND DATE(StartTime)<=CURDATE()", - sizeof (Past__FutureEventsSubQuery) - 1); // Past and today events - break; - case (1 << Agd_FUTURE_EVENTS): - Str_Copy (Past__FutureEventsSubQuery, - " AND DATE(EndTime)>=CURDATE()", - sizeof (Past__FutureEventsSubQuery) - 1); // Today and future events - break; - default: - Past__FutureEventsSubQuery[0] = '\0'; // All events - break; - } - switch (Agenda->PrivatPublicEvents) - { - case (1 << Agd_PRIVAT_EVENTS): - Str_Copy (PrivatPublicEventsSubQuery," AND Public='N'", - sizeof (PrivatPublicEventsSubQuery) - 1); // Private events - break; - case (1 << Agd_PUBLIC_EVENTS): - Str_Copy (PrivatPublicEventsSubQuery," AND Public='Y'", - sizeof (PrivatPublicEventsSubQuery) - 1); // Public events - break; - default: - PrivatPublicEventsSubQuery[0] = '\0'; // All events - break; - } - switch (Agenda->HiddenVisiblEvents) - { - case (1 << Agd_HIDDEN_EVENTS): - Str_Copy (HiddenVisiblEventsSubQuery," AND Hidden='Y'", - sizeof (HiddenVisiblEventsSubQuery) - 1); // Hidden events - break; - case (1 << Agd_VISIBL_EVENTS): - Str_Copy (HiddenVisiblEventsSubQuery," AND Hidden='N'", - sizeof (HiddenVisiblEventsSubQuery) - 1); // Visible events - break; - default: - HiddenVisiblEventsSubQuery[0] = '\0'; // All events - break; - } + // Nothing to get from database + Agenda->LstIsRead = true; + return; } break; - case Agd_ANOTHER_AGENDA_TODAY: - case Agd_ANOTHER_AGENDA: - if (asprintf (&UsrSubQuery,"UsrCod=%ld", - Gbl.Usrs.Other.UsrDat.UsrCod) < 0) - Err_NotEnoughMemoryExit (); - if (AgendaType == Agd_ANOTHER_AGENDA_TODAY) - Str_Copy (Past__FutureEventsSubQuery, - " AND DATE(StartTime)<=CURDATE()" - " AND DATE(EndTime)>=CURDATE()", - sizeof (Past__FutureEventsSubQuery) - 1); // Today events - else - Str_Copy (Past__FutureEventsSubQuery, - " AND DATE(EndTime)>=CURDATE()", - sizeof (Past__FutureEventsSubQuery) - 1); // Today and future events - Str_Copy (PrivatPublicEventsSubQuery," AND Public='Y'", - sizeof (PrivatPublicEventsSubQuery) - 1); // Public events - Str_Copy (HiddenVisiblEventsSubQuery," AND Hidden='N'", - sizeof (HiddenVisiblEventsSubQuery) - 1); // Visible events + default: + break; } - if (DoQuery) + /***** Get list of events from database *****/ + if ((Agenda->Num = Agd_DB_GetListEvents (&mysql_res,Agenda,AgendaType))) // Events found... { - /* Make query */ - Agenda->Num = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get agenda events", - "SELECT AgdCod" // row[0] - " FROM agd_agendas" - " WHERE %s%s%s%s" - " ORDER BY %s", - UsrSubQuery, - Past__FutureEventsSubQuery, - PrivatPublicEventsSubQuery, - HiddenVisiblEventsSubQuery, - OrderBySubQuery[Agenda->SelectedOrder]); + /***** Create list of events *****/ + if ((Agenda->LstAgdCods = calloc ((size_t) Agenda->Num, + sizeof (*Agenda->LstAgdCods))) == NULL) + Err_NotEnoughMemoryExit (); - /* Free allocated memory for subquery */ - free (UsrSubQuery); - - if (Agenda->Num) // Events found... - { - /***** Create list of events *****/ - if ((Agenda->LstAgdCods = calloc ((size_t) Agenda->Num, - sizeof (*Agenda->LstAgdCods))) == NULL) - Err_NotEnoughMemoryExit (); - - /***** Get the events codes *****/ - for (NumEvent = 0; - NumEvent < Agenda->Num; - NumEvent++) - /* Get next event code */ - if ((Agenda->LstAgdCods[NumEvent] = DB_GetNextCode (mysql_res)) < 0) - Err_WrongEventExit (); - } - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); + /***** Get the events codes *****/ + for (NumEvent = 0; + NumEvent < Agenda->Num; + NumEvent++) + /* Get next event code */ + if ((Agenda->LstAgdCods[NumEvent] = DB_GetNextCode (mysql_res)) < 0) + Err_WrongEventExit (); } + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + Agenda->LstIsRead = true; } @@ -1199,21 +1095,7 @@ static void Agd_GetDataOfEventByCod (struct Agd_Event *AgdEvent) MYSQL_ROW row; /***** Get data of event from database *****/ - if (DB_QuerySELECT (&mysql_res,"can not get agenda event data", - "SELECT AgdCod," // row[0] - "Public," // row[1] - "Hidden," // row[2] - "UNIX_TIMESTAMP(StartTime)," // row[3] - "UNIX_TIMESTAMP(EndTime)," // row[4] - "NOW()>EndTime," // row[5] Past event? - "NOW()AgdCod, - AgdEvent->UsrCod)) // Event found... + if (Agd_DB_GetDataOfEventByCod (&mysql_res,AgdEvent)) // Event found... { /* Get row: row[0] AgdCod @@ -1252,14 +1134,14 @@ static void Agd_GetDataOfEventByCod (struct Agd_Event *AgdEvent) else { /***** Clear all event data *****/ - AgdEvent->AgdCod = -1L; - AgdEvent->Public = false; - AgdEvent->Hidden = false; + AgdEvent->AgdCod = -1L; + AgdEvent->Public = false; + AgdEvent->Hidden = false; AgdEvent->TimeUTC[Dat_START_TIME] = AgdEvent->TimeUTC[Dat_END_TIME ] = (time_t) 0; - AgdEvent->TimeStatus = Dat_FUTURE; - AgdEvent->Event[0] = '\0'; - AgdEvent->Location[0] = '\0'; + AgdEvent->TimeStatus = Dat_FUTURE; + AgdEvent->Event[0] = '\0'; + AgdEvent->Location[0] = '\0'; } /***** Free structure that stores the query result *****/ @@ -1282,23 +1164,6 @@ static void Agd_FreeListEvents (struct Agd_Agenda *Agenda) } } -/*****************************************************************************/ -/*********************** Get event text from database ************************/ -/*****************************************************************************/ - -static void Agd_GetEventTxtFromDB (struct Agd_Event *AgdEvent, - char Txt[Cns_MAX_BYTES_TEXT + 1]) - { - /***** Get text of event from database *****/ - DB_QuerySELECTString (Txt,Cns_MAX_BYTES_TEXT,"can not get event text", - "SELECT Txt" - " FROM agd_agendas" - " WHERE AgdCod=%ld" - " AND UsrCod=%ld", - AgdEvent->AgdCod, - AgdEvent->UsrCod); - } - /*****************************************************************************/ /******************** Get parameter with code of event ***********************/ /*****************************************************************************/ @@ -1371,12 +1236,7 @@ void Agd_RemoveEvent (void) Agd_GetDataOfEventByCod (&AgdEvent); /***** Remove event *****/ - DB_QueryDELETE ("can not remove event", - "DELETE FROM agd_agendas" - " WHERE AgdCod=%ld" - " AND UsrCod=%ld", - AgdEvent.AgdCod, - AgdEvent.UsrCod); + Agd_DB_RemoveEvent (&AgdEvent); /***** Write message to show the change made *****/ Ale_ShowAlert (Ale_SUCCESS,Txt_Event_X_removed, @@ -1410,13 +1270,7 @@ void Agd_HideEvent (void) Agd_GetDataOfEventByCod (&AgdEvent); /***** Set event private *****/ - DB_QueryUPDATE ("can not hide event", - "UPDATE agd_agendas" - " SET Hidden='Y'" - " WHERE AgdCod=%ld" - " AND UsrCod=%ld", - AgdEvent.AgdCod, - AgdEvent.UsrCod); + Agd_DB_HideEvent (&AgdEvent); /***** Show events again *****/ Agd_ShowMyAgenda (&Agenda); @@ -1446,13 +1300,7 @@ void Agd_UnhideEvent (void) Agd_GetDataOfEventByCod (&AgdEvent); /***** Set event public *****/ - DB_QueryUPDATE ("can not show event", - "UPDATE agd_agendas" - " SET Hidden='N'" - " WHERE AgdCod=%ld" - " AND UsrCod=%ld", - AgdEvent.AgdCod, - AgdEvent.UsrCod); + Agd_DB_UnhideEvent (&AgdEvent); /***** Show events again *****/ Agd_ShowMyAgenda (&Agenda); @@ -1483,13 +1331,7 @@ void Agd_MakeEventPrivate (void) Agd_GetDataOfEventByCod (&AgdEvent); /***** Make event private *****/ - DB_QueryUPDATE ("can not make event private", - "UPDATE agd_agendas" - " SET Public='N'" - " WHERE AgdCod=%ld" - " AND UsrCod=%ld", - AgdEvent.AgdCod, - AgdEvent.UsrCod); + Agd_DB_MakeEventPrivate (&AgdEvent); /***** Write message to show the change made *****/ Ale_ShowAlert (Ale_SUCCESS,Txt_Event_X_is_now_private, @@ -1524,13 +1366,7 @@ void Agd_MakeEventPublic (void) Agd_GetDataOfEventByCod (&AgdEvent); /***** Make event public *****/ - DB_QueryUPDATE ("can not make event public", - "UPDATE agd_agendas" - " SET Public='Y'" - " WHERE AgdCod=%ld" - " AND UsrCod=%ld", - AgdEvent.AgdCod, - AgdEvent.UsrCod); + Agd_DB_MakeEventPublic (&AgdEvent); /***** Write message to show the change made *****/ Ale_ShowAlert (Ale_SUCCESS,Txt_Event_X_is_now_visible_to_users_of_your_courses, @@ -1592,7 +1428,7 @@ void Agd_RequestCreatOrEditEvent (void) Agd_GetDataOfEventByCod (&AgdEvent); /* Get text of the event from database */ - Agd_GetEventTxtFromDB (&AgdEvent,Txt); + Agd_DB_GetEventTxt (&AgdEvent,Txt); } /***** Begin form *****/ @@ -1608,75 +1444,81 @@ void Agd_RequestCreatOrEditEvent (void) } Agd_PutCurrentParamsMyAgenda (&Agenda); - /***** Begin box and table *****/ - if (ItsANewEvent) - Box_BoxTableBegin (NULL,Txt_New_event, - NULL,NULL, - Hlp_PROFILE_Agenda_new_event,Box_NOT_CLOSABLE,2); - else - Box_BoxTableBegin (NULL,Txt_Edit_event, - NULL,NULL, - Hlp_PROFILE_Agenda_edit_event,Box_NOT_CLOSABLE,2); + /***** Begin box and table *****/ + if (ItsANewEvent) + Box_BoxTableBegin (NULL,Txt_New_event, + NULL,NULL, + Hlp_PROFILE_Agenda_new_event,Box_NOT_CLOSABLE,2); + else + Box_BoxTableBegin (NULL,Txt_Edit_event, + NULL,NULL, + Hlp_PROFILE_Agenda_edit_event,Box_NOT_CLOSABLE,2); - /***** Event *****/ - HTM_TR_Begin (NULL); + /***** Event *****/ + /* Begin table row */ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT","Event",Txt_Event); + /* Label */ + Frm_LabelColumn ("RT","Event",Txt_Event); - /* Data */ - HTM_TD_Begin ("class=\"LT\""); - HTM_INPUT_TEXT ("Event",Agd_MAX_CHARS_EVENT,AgdEvent.Event, - HTM_DONT_SUBMIT_ON_CHANGE, - "id=\"Event\" required=\"required\"" - " class=\"TITLE_DESCRIPTION_WIDTH\""); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"LT\""); + HTM_INPUT_TEXT ("Event",Agd_MAX_CHARS_EVENT,AgdEvent.Event, + HTM_DONT_SUBMIT_ON_CHANGE, + "id=\"Event\" required=\"required\"" + " class=\"TITLE_DESCRIPTION_WIDTH\""); + HTM_TD_End (); - HTM_TR_End (); + /* End table row */ + HTM_TR_End (); - /***** Location *****/ - HTM_TR_Begin (NULL); + /***** Location *****/ + /* Begin table row */ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT","Location",Txt_Location); + /* Label */ + Frm_LabelColumn ("RT","Location",Txt_Location); - /* Data */ - HTM_TD_Begin ("class=\"LT\""); - HTM_INPUT_TEXT ("Location",Agd_MAX_CHARS_LOCATION,AgdEvent.Location, - HTM_DONT_SUBMIT_ON_CHANGE, - "id=\"Location\" required=\"required\"" - " class=\"TITLE_DESCRIPTION_WIDTH\""); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"LT\""); + HTM_INPUT_TEXT ("Location",Agd_MAX_CHARS_LOCATION,AgdEvent.Location, + HTM_DONT_SUBMIT_ON_CHANGE, + "id=\"Location\" required=\"required\"" + " class=\"TITLE_DESCRIPTION_WIDTH\""); + HTM_TD_End (); - HTM_TR_End (); + /* End table row */ + HTM_TR_End (); - /***** Start and end dates *****/ - Dat_PutFormStartEndClientLocalDateTimes (AgdEvent.TimeUTC, - Dat_FORM_SECONDS_OFF, - SetHMS); + /***** Start and end dates *****/ + Dat_PutFormStartEndClientLocalDateTimes (AgdEvent.TimeUTC, + Dat_FORM_SECONDS_OFF, + SetHMS); - /***** Text *****/ - HTM_TR_Begin (NULL); + /***** Text *****/ + /* Begin table row */ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT","Txt",Txt_Description); + /* Label */ + Frm_LabelColumn ("RT","Txt",Txt_Description); - /* Data */ - HTM_TD_Begin ("class=\"LT\""); - HTM_TEXTAREA_Begin ("id=\"Txt\" name=\"Txt\" rows=\"5\"" - " class=\"TITLE_DESCRIPTION_WIDTH\""); - if (!ItsANewEvent) - HTM_Txt (Txt); - HTM_TEXTAREA_End (); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"LT\""); + HTM_TEXTAREA_Begin ("id=\"Txt\" name=\"Txt\" rows=\"5\"" + " class=\"TITLE_DESCRIPTION_WIDTH\""); + if (!ItsANewEvent) + HTM_Txt (Txt); + HTM_TEXTAREA_End (); + HTM_TD_End (); - HTM_TR_End (); + /* End table row */ + HTM_TR_End (); - /***** End table, send button and end box *****/ - if (ItsANewEvent) - Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_event); - else - Box_BoxTableWithButtonEnd (Btn_CONFIRM_BUTTON,Txt_Save_changes); + /***** End table, send button and end box *****/ + if (ItsANewEvent) + Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_event); + else + Box_BoxTableWithButtonEnd (Btn_CONFIRM_BUTTON,Txt_Save_changes); /***** End form *****/ Frm_EndForm (); @@ -1750,7 +1592,7 @@ void Agd_ReceiveFormEvent (void) { if (ItsANewEvent) { - Agd_CreateEvent (&AgdEvent,EventTxt); // Add new event to database + AgdEvent.AgdCod = Agd_DB_CreateEvent (&AgdEvent,EventTxt); // Add new event to database /***** Write success message *****/ Ale_ShowAlert (Ale_SUCCESS,Txt_Created_new_event_X, @@ -1758,7 +1600,7 @@ void Agd_ReceiveFormEvent (void) } else { - Agd_UpdateEvent (&AgdEvent,EventTxt); + Agd_DB_UpdateEvent (&AgdEvent,EventTxt); /***** Write success message *****/ Ale_ShowAlert (Ale_SUCCESS,Txt_The_event_has_been_modified); @@ -1775,259 +1617,6 @@ void Agd_ReceiveFormEvent (void) Agd_RequestCreatOrEditEvent (); } -/*****************************************************************************/ -/************************** Create a new event *******************************/ -/*****************************************************************************/ - -static void Agd_CreateEvent (struct Agd_Event *AgdEvent,const char *Txt) - { - /***** Create a new event *****/ - AgdEvent->AgdCod = - DB_QueryINSERTandReturnCode ("can not create new event", - "INSERT INTO agd_agendas" - " (UsrCod,StartTime,EndTime," - "Event,Location,Txt)" - " VALUES" - " (%ld,FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld)," - "'%s','%s','%s')", - AgdEvent->UsrCod, - AgdEvent->TimeUTC[Dat_START_TIME], - AgdEvent->TimeUTC[Dat_END_TIME ], - AgdEvent->Event, - AgdEvent->Location, - Txt); - } - -/*****************************************************************************/ -/************************ Update an existing event ***************************/ -/*****************************************************************************/ - -static void Agd_UpdateEvent (struct Agd_Event *AgdEvent,const char *Txt) - { - /***** Update the data of the event *****/ - DB_QueryUPDATE ("can not update event", - "UPDATE agd_agendas" - " SET StartTime=FROM_UNIXTIME(%ld)," - "EndTime=FROM_UNIXTIME(%ld)," - "Event='%s'," - "Location='%s'," - "Txt='%s'" - " WHERE AgdCod=%ld" - " AND UsrCod=%ld", - AgdEvent->TimeUTC[Dat_START_TIME], - AgdEvent->TimeUTC[Dat_END_TIME ], - AgdEvent->Event, - AgdEvent->Location, - Txt, - AgdEvent->AgdCod, - AgdEvent->UsrCod); - } - -/*****************************************************************************/ -/********************** Remove all the events of a user **********************/ -/*****************************************************************************/ - -void Agd_DB_RemoveUsrEvents (long UsrCod) - { - DB_QueryDELETE ("can not remove all the events of a user", - "DELETE FROM agd_agendas" - " WHERE UsrCod=%ld", - UsrCod); - } - -/*****************************************************************************/ -/********************* Get number of events from a user **********************/ -/*****************************************************************************/ - -unsigned Agd_GetNumEventsFromUsr (long UsrCod) - { - /***** Get number of events in a course from database *****/ - return (unsigned) - DB_QueryCOUNT ("can not get number of events from user", - "SELECT COUNT(*)" - " FROM agd_agendas" - " WHERE UsrCod=%ld", - UsrCod); - } - -/*****************************************************************************/ -/********************** Get number of users with events **********************/ -/*****************************************************************************/ -// Returns the number of users with events in a given scope - -unsigned Agd_GetNumUsrsWithEvents (Hie_Lvl_Level_t Scope) - { - /***** Get number of users with events from database *****/ - switch (Scope) - { - case Hie_Lvl_SYS: - return (unsigned) - DB_QueryCOUNT ("can not get number of users with events", - "SELECT COUNT(DISTINCT UsrCod)" - " FROM agd_agendas" - " WHERE UsrCod>0"); - case Hie_Lvl_CTY: - return (unsigned) - DB_QueryCOUNT ("can not get number of users with events", - "SELECT COUNT(DISTINCT agd_agendas.UsrCod)" - " FROM ins_instits," - "ctr_centers," - "deg_degrees," - "crs_courses," - "crs_users," - "agd_agendas" - " WHERE ins_instits.CtyCod=%ld" - " AND ins_instits.InsCod=ctr_centers.InsCod" - " AND ctr_centers.CtrCod=deg_degrees.CtrCod" - " AND deg_degrees.DegCod=crs_courses.DegCod" - " AND crs_courses.CrsCod=crs_users.CrsCod" - " AND crs_users.UsrCod=agd_agendas.UsrCod", - Gbl.Hierarchy.Cty.CtyCod); - case Hie_Lvl_INS: - return (unsigned) - DB_QueryCOUNT ("can not get number of users with events", - "SELECT COUNT(DISTINCT agd_agendas.UsrCod)" - " FROM ctr_centers," - "deg_degrees," - "crs_courses," - "crs_users," - "agd_agendas" - " WHERE ctr_centers.InsCod=%ld" - " AND ctr_centers.CtrCod=deg_degrees.CtrCod" - " AND deg_degrees.DegCod=crs_courses.DegCod" - " AND crs_courses.CrsCod=crs_users.CrsCod" - " AND crs_users.UsrCod=agd_agendas.UsrCod", - Gbl.Hierarchy.Ins.InsCod); - case Hie_Lvl_CTR: - return (unsigned) - DB_QueryCOUNT ("can not get number of users with events", - "SELECT COUNT(DISTINCT agd_agendas.UsrCod)" - " FROM deg_degrees," - "crs_courses," - "crs_users," - "agd_agendas" - " WHERE deg_degrees.CtrCod=%ld" - " AND deg_degrees.DegCod=crs_courses.DegCod" - " AND crs_courses.CrsCod=crs_users.CrsCod" - " AND crs_users.UsrCod=agd_agendas.UsrCod", - Gbl.Hierarchy.Ctr.CtrCod); - case Hie_Lvl_DEG: - return (unsigned) - DB_QueryCOUNT ("can not get number of users with events", - "SELECT COUNT(DISTINCT agd_agendas.UsrCod)" - " FROM crs_courses," - "crs_users," - "agd_agendas" - " WHERE crs_courses.DegCod=%ld" - " AND crs_courses.CrsCod=crs_users.CrsCod" - " AND crs_users.UsrCod=agd_agendas.UsrCod", - Gbl.Hierarchy.Deg.DegCod); - case Hie_Lvl_CRS: - return (unsigned) - DB_QueryCOUNT ("can not get number of users with events", - "SELECT COUNT(DISTINCT agd_agendas.UsrCod)" - " FROM crs_users," - "agd_agendas" - " WHERE crs_users.CrsCod=%ld" - " AND crs_users.UsrCod=agd_agendas.UsrCod", - Gbl.Hierarchy.Crs.CrsCod); - default: - Err_WrongScopeExit (); - return 0; // Not reached - } - } - -/*****************************************************************************/ -/*************************** Get number of events ****************************/ -/*****************************************************************************/ -// Returns the number of events in a given scope - -unsigned Agd_GetNumEvents (Hie_Lvl_Level_t Scope) - { - /***** Get number of events from database *****/ - switch (Scope) - { - case Hie_Lvl_SYS: - return (unsigned) - DB_QueryCOUNT ("can not get number of events", - "SELECT COUNT(*)" - " FROM agd_agendas" - " WHERE UsrCod>0"); - case Hie_Lvl_CTY: - return (unsigned) - DB_QueryCOUNT ("can not get number of events", - "SELECT COUNT(*)" - " FROM (SELECT DISTINCT crs_users.UsrCod" - " FROM ins_instits," - "ctr_centers," - "deg_degrees," - "crs_courses," - "crs_users" - " WHERE ins_instits.CtyCod=%ld" - " AND ins_instits.InsCod=ctr_centers.InsCod" - " AND ctr_centers.CtrCod=deg_degrees.CtrCod" - " AND deg_degrees.DegCod=crs_courses.DegCod" - " AND crs_courses.CrsCod=crs_users.CrsCod) AS users," - "agd_agendas" - " WHERE users.UsrCod=agd_agendas.UsrCod", - Gbl.Hierarchy.Cty.CtyCod); - case Hie_Lvl_INS: - return (unsigned) - DB_QueryCOUNT ("can not get number of events", - "SELECT COUNT(*)" - " FROM (SELECT DISTINCT crs_users.UsrCod" - " FROM ctr_centers," - "deg_degrees," - "crs_courses," - "crs_users" - " WHERE ctr_centers.InsCod=%ld" - " AND ctr_centers.CtrCod=deg_degrees.CtrCod" - " AND deg_degrees.DegCod=crs_courses.DegCod" - " AND crs_courses.CrsCod=crs_users.CrsCod) AS users," - "agd_agendas" - " WHERE users.UsrCod=agd_agendas.UsrCod", - Gbl.Hierarchy.Ins.InsCod); - case Hie_Lvl_CTR: - return (unsigned) - DB_QueryCOUNT ("can not get number of events", - "SELECT COUNT(*)" - " FROM (SELECT DISTINCT crs_users.UsrCod" - " FROM deg_degrees," - "crs_courses," - "crs_users" - " WHERE deg_degrees.CtrCod=%ld" - " AND deg_degrees.DegCod=crs_courses.DegCod" - " AND crs_courses.CrsCod=crs_users.CrsCod) AS users," - "agd_agendas" - " WHERE users.UsrCod=agd_agendas.UsrCod", - Gbl.Hierarchy.Ctr.CtrCod); - case Hie_Lvl_DEG: - return (unsigned) - DB_QueryCOUNT ("can not get number of events", - "SELECT COUNT(*)" - " FROM (SELECT DISTINCT crs_users.UsrCod" - " FROM crs_courses," - "crs_users" - " WHERE crs_courses.DegCod=%ld" - " AND crs_courses.CrsCod=crs_users.CrsCod) AS users," - "agd_agendas" - " WHERE users.UsrCod=agd_agendas.UsrCod", - Gbl.Hierarchy.Deg.DegCod); - case Hie_Lvl_CRS: - return (unsigned) - DB_QueryCOUNT ("can not get number of events", - "SELECT COUNT(*)" - " FROM crs_users," - "agd_agendas" - " WHERE crs_users.CrsCod=%ld" - " AND crs_users.UsrCod=agd_agendas.UsrCod", - Gbl.Hierarchy.Crs.CrsCod); - default: - Err_WrongScopeExit (); - return 0; // Not reached - } - } - /*****************************************************************************/ /************************** Show an agenda QR code ***************************/ /*****************************************************************************/ @@ -2043,8 +1632,8 @@ void Agd_PrintAgdQRCode (void) NULL,Box_NOT_CLOSABLE); Str_FreeString (); - /***** Print QR code ****/ - QR_PrintQRCode (); + /***** Print QR code ****/ + QR_PrintQRCode (); /***** End box *****/ Box_BoxEnd (); diff --git a/swad_agenda.h b/swad_agenda.h index f2cbd63d..bd7dcf6d 100644 --- a/swad_agenda.h +++ b/swad_agenda.h @@ -91,6 +91,15 @@ struct Agd_Agenda unsigned CurrentPage; }; +#define Agd_NUM_AGENDA_TYPES 4 +typedef enum + { + Agd_MY_AGENDA_TODAY, + Agd_MY_AGENDA, + Agd_ANOTHER_AGENDA_TODAY, + Agd_ANOTHER_AGENDA, + } Agd_AgendaType_t; + /*****************************************************************************/ /***************************** Public prototypes *****************************/ /*****************************************************************************/ @@ -125,12 +134,6 @@ void Agd_MakeEventPublic (void); void Agd_ReceiveFormEvent (void); -void Agd_DB_RemoveUsrEvents (long UsrCod); -unsigned Agd_GetNumEventsFromUsr (long UsrCod); - -unsigned Agd_GetNumUsrsWithEvents (Hie_Lvl_Level_t Scope); -unsigned Agd_GetNumEvents (Hie_Lvl_Level_t Scope); - void Agd_PrintAgdQRCode (void); #endif diff --git a/swad_agenda_database.c b/swad_agenda_database.c new file mode 100644 index 00000000..f61d389e --- /dev/null +++ b/swad_agenda_database.c @@ -0,0 +1,555 @@ +// swad_agenda_database.c: user's agenda (personal organizer) 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 3 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 . +*/ +/*****************************************************************************/ +/********************************* Headers ***********************************/ +/*****************************************************************************/ + +#define _GNU_SOURCE // For asprintf +// #include // For PATH_MAX +// #include // For NULL +#include // For asprintf +// #include // For calloc +// #include // For string functions + +#include "swad_agenda.h" +#include "swad_agenda_database.h" +// #include "swad_box.h" +#include "swad_database.h" +// #include "swad_date.h" +#include "swad_error.h" +// #include "swad_form.h" +#include "swad_global.h" +// #include "swad_group.h" +// #include "swad_HTML.h" +// #include "swad_notification.h" +// #include "swad_pagination.h" +// #include "swad_parameter.h" +// #include "swad_photo.h" +// #include "swad_privacy.h" +// #include "swad_QR.h" +// #include "swad_setting.h" +// #include "swad_string.h" + +/*****************************************************************************/ +/************** External global variables from others modules ****************/ +/*****************************************************************************/ + +extern struct Globals Gbl; + +/*****************************************************************************/ +/***************************** Private constants *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/******************************* Private types *******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private variables *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private prototypes ****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/************************* Get list of agenda events *************************/ +/*****************************************************************************/ + +#define Agd_MAX_BYTES_SUBQUERY 128 + +unsigned Agd_DB_GetListEvents (MYSQL_RES **mysql_res, + const struct Agd_Agenda *Agenda, + Agd_AgendaType_t AgendaType) + { + char *UsrSubQuery; + char Past__FutureEventsSubQuery[Agd_MAX_BYTES_SUBQUERY + 1]; + char PrivatPublicEventsSubQuery[Agd_MAX_BYTES_SUBQUERY + 1]; + char HiddenVisiblEventsSubQuery[Agd_MAX_BYTES_SUBQUERY + 1]; + static const char *OrderBySubQuery[Dat_NUM_START_END_TIME] = + { + [Dat_START_TIME] = "StartTime,EndTime,Event,Location", + [Dat_END_TIME ] = "EndTime,StartTime,Event,Location", + }; + unsigned NumEvents; + + /***** Get list of events from database *****/ + /* Build events subqueries */ + switch (AgendaType) + { + case Agd_MY_AGENDA_TODAY: + case Agd_MY_AGENDA: + if (asprintf (&UsrSubQuery,"UsrCod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod) < 0) + Err_NotEnoughMemoryExit (); + if (AgendaType == Agd_MY_AGENDA_TODAY) + Str_Copy (Past__FutureEventsSubQuery, + " AND DATE(StartTime)<=CURDATE()" + " AND DATE(EndTime)>=CURDATE()", + sizeof (Past__FutureEventsSubQuery) - 1); // Today events + else + switch (Agenda->Past__FutureEvents) + { + case (1 << Agd_PAST___EVENTS): + Str_Copy (Past__FutureEventsSubQuery, + " AND DATE(StartTime)<=CURDATE()", + sizeof (Past__FutureEventsSubQuery) - 1); // Past and today events + break; + case (1 << Agd_FUTURE_EVENTS): + Str_Copy (Past__FutureEventsSubQuery, + " AND DATE(EndTime)>=CURDATE()", + sizeof (Past__FutureEventsSubQuery) - 1); // Today and future events + break; + default: + Past__FutureEventsSubQuery[0] = '\0'; // All events + break; + } + switch (Agenda->PrivatPublicEvents) + { + case (1 << Agd_PRIVAT_EVENTS): + Str_Copy (PrivatPublicEventsSubQuery," AND Public='N'", + sizeof (PrivatPublicEventsSubQuery) - 1); // Private events + break; + case (1 << Agd_PUBLIC_EVENTS): + Str_Copy (PrivatPublicEventsSubQuery," AND Public='Y'", + sizeof (PrivatPublicEventsSubQuery) - 1); // Public events + break; + default: + PrivatPublicEventsSubQuery[0] = '\0'; // All events + break; + } + switch (Agenda->HiddenVisiblEvents) + { + case (1 << Agd_HIDDEN_EVENTS): + Str_Copy (HiddenVisiblEventsSubQuery," AND Hidden='Y'", + sizeof (HiddenVisiblEventsSubQuery) - 1); // Hidden events + break; + case (1 << Agd_VISIBL_EVENTS): + Str_Copy (HiddenVisiblEventsSubQuery," AND Hidden='N'", + sizeof (HiddenVisiblEventsSubQuery) - 1); // Visible events + break; + default: + HiddenVisiblEventsSubQuery[0] = '\0'; // All events + break; + } + break; + case Agd_ANOTHER_AGENDA_TODAY: + case Agd_ANOTHER_AGENDA: + if (asprintf (&UsrSubQuery,"UsrCod=%ld", + Gbl.Usrs.Other.UsrDat.UsrCod) < 0) + Err_NotEnoughMemoryExit (); + if (AgendaType == Agd_ANOTHER_AGENDA_TODAY) + Str_Copy (Past__FutureEventsSubQuery, + " AND DATE(StartTime)<=CURDATE()" + " AND DATE(EndTime)>=CURDATE()", + sizeof (Past__FutureEventsSubQuery) - 1); // Today events + else + Str_Copy (Past__FutureEventsSubQuery, + " AND DATE(EndTime)>=CURDATE()", + sizeof (Past__FutureEventsSubQuery) - 1); // Today and future events + Str_Copy (PrivatPublicEventsSubQuery," AND Public='Y'", + sizeof (PrivatPublicEventsSubQuery) - 1); // Public events + Str_Copy (HiddenVisiblEventsSubQuery," AND Hidden='N'", + sizeof (HiddenVisiblEventsSubQuery) - 1); // Visible events + } + + /* Make query */ + NumEvents = (unsigned) + DB_QuerySELECT (mysql_res,"can not get agenda events", + "SELECT AgdCod" // row[0] + " FROM agd_agendas" + " WHERE %s%s%s%s" + " ORDER BY %s", + UsrSubQuery, + Past__FutureEventsSubQuery, + PrivatPublicEventsSubQuery, + HiddenVisiblEventsSubQuery, + OrderBySubQuery[Agenda->SelectedOrder]); + + /* Free allocated memory for subquery */ + free (UsrSubQuery); + + return NumEvents; + } + +/*****************************************************************************/ +/*********************** Get event data using its code ***********************/ +/*****************************************************************************/ + +unsigned Agd_DB_GetDataOfEventByCod (MYSQL_RES **mysql_res, + const struct Agd_Event *AgdEvent) + { + /***** Get data of event from database *****/ + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get agenda event data", + "SELECT AgdCod," // row[0] + "Public," // row[1] + "Hidden," // row[2] + "UNIX_TIMESTAMP(StartTime)," // row[3] + "UNIX_TIMESTAMP(EndTime)," // row[4] + "NOW()>EndTime," // row[5] Past event? + "NOW()AgdCod, + AgdEvent->UsrCod); + } + +/*****************************************************************************/ +/*********************** Get event text from database ************************/ +/*****************************************************************************/ + +void Agd_DB_GetEventTxt (const struct Agd_Event *AgdEvent, + char Txt[Cns_MAX_BYTES_TEXT + 1]) + { + DB_QuerySELECTString (Txt,Cns_MAX_BYTES_TEXT,"can not get event text", + "SELECT Txt" + " FROM agd_agendas" + " WHERE AgdCod=%ld" + " AND UsrCod=%ld", + AgdEvent->AgdCod, + AgdEvent->UsrCod); + } + +/*****************************************************************************/ +/************************* Remove event from database ************************/ +/*****************************************************************************/ + +void Agd_DB_RemoveEvent (const struct Agd_Event *AgdEvent) + { + DB_QueryDELETE ("can not remove event", + "DELETE FROM agd_agendas" + " WHERE AgdCod=%ld" + " AND UsrCod=%ld", + AgdEvent->AgdCod, + AgdEvent->UsrCod); + } + +/*****************************************************************************/ +/************************** Create a new event *******************************/ +/*****************************************************************************/ + +long Agd_DB_CreateEvent (const struct Agd_Event *AgdEvent,const char *Txt) + { + /***** Create a new event *****/ + return + DB_QueryINSERTandReturnCode ("can not create new event", + "INSERT INTO agd_agendas" + " (UsrCod,StartTime,EndTime," + "Event,Location,Txt)" + " VALUES" + " (%ld,FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld)," + "'%s','%s','%s')", + AgdEvent->UsrCod, + AgdEvent->TimeUTC[Dat_START_TIME], + AgdEvent->TimeUTC[Dat_END_TIME ], + AgdEvent->Event, + AgdEvent->Location, + Txt); + } + +/*****************************************************************************/ +/************************ Update an existing event ***************************/ +/*****************************************************************************/ + +void Agd_DB_UpdateEvent (const struct Agd_Event *AgdEvent,const char *Txt) + { + /***** Update the data of the event *****/ + DB_QueryUPDATE ("can not update event", + "UPDATE agd_agendas" + " SET StartTime=FROM_UNIXTIME(%ld)," + "EndTime=FROM_UNIXTIME(%ld)," + "Event='%s'," + "Location='%s'," + "Txt='%s'" + " WHERE AgdCod=%ld" + " AND UsrCod=%ld", + AgdEvent->TimeUTC[Dat_START_TIME], + AgdEvent->TimeUTC[Dat_END_TIME ], + AgdEvent->Event, + AgdEvent->Location, + Txt, + AgdEvent->AgdCod, + AgdEvent->UsrCod); + } + +/*****************************************************************************/ +/**************** Set an existing event as hidden/not hidden *****************/ +/*****************************************************************************/ + +void Agd_DB_HideEvent (const struct Agd_Event *AgdEvent) + { + DB_QueryUPDATE ("can not hide event", + "UPDATE agd_agendas" + " SET Hidden='Y'" + " 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); + } + +/*****************************************************************************/ +/***************** Set an existing event as public/private *******************/ +/*****************************************************************************/ + +void Agd_DB_MakeEventPublic (const struct Agd_Event *AgdEvent) + { + DB_QueryUPDATE ("can not make event public", + "UPDATE agd_agendas" + " SET Public='Y'" + " WHERE AgdCod=%ld" + " AND UsrCod=%ld", + AgdEvent->AgdCod, + AgdEvent->UsrCod); + } + +void Agd_DB_MakeEventPrivate (const struct Agd_Event *AgdEvent) + { + DB_QueryUPDATE ("can not make event private", + "UPDATE agd_agendas" + " SET Public='N'" + " WHERE AgdCod=%ld" + " AND UsrCod=%ld", + AgdEvent->AgdCod, + AgdEvent->UsrCod); + } + +/*****************************************************************************/ +/********************** Remove all the events of a user **********************/ +/*****************************************************************************/ + +void Agd_DB_RemoveUsrEvents (long UsrCod) + { + DB_QueryDELETE ("can not remove all the events of a user", + "DELETE FROM agd_agendas" + " WHERE UsrCod=%ld", + UsrCod); + } + +/*****************************************************************************/ +/********************* Get number of events from a user **********************/ +/*****************************************************************************/ + +unsigned Agd_DB_GetNumEventsFromUsr (long UsrCod) + { + /***** Get number of events in a course from database *****/ + return (unsigned) + DB_QueryCOUNT ("can not get number of events from user", + "SELECT COUNT(*)" + " FROM agd_agendas" + " WHERE UsrCod=%ld", + UsrCod); + } + +/*****************************************************************************/ +/********************** Get number of users with events **********************/ +/*****************************************************************************/ +// Returns the number of users with events in a given scope + +unsigned Agd_DB_GetNumUsrsWithEvents (Hie_Lvl_Level_t Scope) + { + /***** Get number of users with events from database *****/ + switch (Scope) + { + case Hie_Lvl_SYS: + return (unsigned) + DB_QueryCOUNT ("can not get number of users with events", + "SELECT COUNT(DISTINCT UsrCod)" + " FROM agd_agendas" + " WHERE UsrCod>0"); + case Hie_Lvl_CTY: + return (unsigned) + DB_QueryCOUNT ("can not get number of users with events", + "SELECT COUNT(DISTINCT agd_agendas.UsrCod)" + " FROM ins_instits," + "ctr_centers," + "deg_degrees," + "crs_courses," + "crs_users," + "agd_agendas" + " WHERE ins_instits.CtyCod=%ld" + " AND ins_instits.InsCod=ctr_centers.InsCod" + " AND ctr_centers.CtrCod=deg_degrees.CtrCod" + " AND deg_degrees.DegCod=crs_courses.DegCod" + " AND crs_courses.CrsCod=crs_users.CrsCod" + " AND crs_users.UsrCod=agd_agendas.UsrCod", + Gbl.Hierarchy.Cty.CtyCod); + case Hie_Lvl_INS: + return (unsigned) + DB_QueryCOUNT ("can not get number of users with events", + "SELECT COUNT(DISTINCT agd_agendas.UsrCod)" + " FROM ctr_centers," + "deg_degrees," + "crs_courses," + "crs_users," + "agd_agendas" + " WHERE ctr_centers.InsCod=%ld" + " AND ctr_centers.CtrCod=deg_degrees.CtrCod" + " AND deg_degrees.DegCod=crs_courses.DegCod" + " AND crs_courses.CrsCod=crs_users.CrsCod" + " AND crs_users.UsrCod=agd_agendas.UsrCod", + Gbl.Hierarchy.Ins.InsCod); + case Hie_Lvl_CTR: + return (unsigned) + DB_QueryCOUNT ("can not get number of users with events", + "SELECT COUNT(DISTINCT agd_agendas.UsrCod)" + " FROM deg_degrees," + "crs_courses," + "crs_users," + "agd_agendas" + " WHERE deg_degrees.CtrCod=%ld" + " AND deg_degrees.DegCod=crs_courses.DegCod" + " AND crs_courses.CrsCod=crs_users.CrsCod" + " AND crs_users.UsrCod=agd_agendas.UsrCod", + Gbl.Hierarchy.Ctr.CtrCod); + case Hie_Lvl_DEG: + return (unsigned) + DB_QueryCOUNT ("can not get number of users with events", + "SELECT COUNT(DISTINCT agd_agendas.UsrCod)" + " FROM crs_courses," + "crs_users," + "agd_agendas" + " WHERE crs_courses.DegCod=%ld" + " AND crs_courses.CrsCod=crs_users.CrsCod" + " AND crs_users.UsrCod=agd_agendas.UsrCod", + Gbl.Hierarchy.Deg.DegCod); + case Hie_Lvl_CRS: + return (unsigned) + DB_QueryCOUNT ("can not get number of users with events", + "SELECT COUNT(DISTINCT agd_agendas.UsrCod)" + " FROM crs_users," + "agd_agendas" + " WHERE crs_users.CrsCod=%ld" + " AND crs_users.UsrCod=agd_agendas.UsrCod", + Gbl.Hierarchy.Crs.CrsCod); + default: + Err_WrongScopeExit (); + return 0; // Not reached + } + } + +/*****************************************************************************/ +/*************************** Get number of events ****************************/ +/*****************************************************************************/ +// Returns the number of events in a given scope + +unsigned Agd_DB_GetNumEvents (Hie_Lvl_Level_t Scope) + { + /***** Get number of events from database *****/ + switch (Scope) + { + case Hie_Lvl_SYS: + return (unsigned) + DB_QueryCOUNT ("can not get number of events", + "SELECT COUNT(*)" + " FROM agd_agendas" + " WHERE UsrCod>0"); + case Hie_Lvl_CTY: + return (unsigned) + DB_QueryCOUNT ("can not get number of events", + "SELECT COUNT(*)" + " FROM (SELECT DISTINCT crs_users.UsrCod" + " FROM ins_instits," + "ctr_centers," + "deg_degrees," + "crs_courses," + "crs_users" + " WHERE ins_instits.CtyCod=%ld" + " AND ins_instits.InsCod=ctr_centers.InsCod" + " AND ctr_centers.CtrCod=deg_degrees.CtrCod" + " AND deg_degrees.DegCod=crs_courses.DegCod" + " AND crs_courses.CrsCod=crs_users.CrsCod) AS users," + "agd_agendas" + " WHERE users.UsrCod=agd_agendas.UsrCod", + Gbl.Hierarchy.Cty.CtyCod); + case Hie_Lvl_INS: + return (unsigned) + DB_QueryCOUNT ("can not get number of events", + "SELECT COUNT(*)" + " FROM (SELECT DISTINCT crs_users.UsrCod" + " FROM ctr_centers," + "deg_degrees," + "crs_courses," + "crs_users" + " WHERE ctr_centers.InsCod=%ld" + " AND ctr_centers.CtrCod=deg_degrees.CtrCod" + " AND deg_degrees.DegCod=crs_courses.DegCod" + " AND crs_courses.CrsCod=crs_users.CrsCod) AS users," + "agd_agendas" + " WHERE users.UsrCod=agd_agendas.UsrCod", + Gbl.Hierarchy.Ins.InsCod); + case Hie_Lvl_CTR: + return (unsigned) + DB_QueryCOUNT ("can not get number of events", + "SELECT COUNT(*)" + " FROM (SELECT DISTINCT crs_users.UsrCod" + " FROM deg_degrees," + "crs_courses," + "crs_users" + " WHERE deg_degrees.CtrCod=%ld" + " AND deg_degrees.DegCod=crs_courses.DegCod" + " AND crs_courses.CrsCod=crs_users.CrsCod) AS users," + "agd_agendas" + " WHERE users.UsrCod=agd_agendas.UsrCod", + Gbl.Hierarchy.Ctr.CtrCod); + case Hie_Lvl_DEG: + return (unsigned) + DB_QueryCOUNT ("can not get number of events", + "SELECT COUNT(*)" + " FROM (SELECT DISTINCT crs_users.UsrCod" + " FROM crs_courses," + "crs_users" + " WHERE crs_courses.DegCod=%ld" + " AND crs_courses.CrsCod=crs_users.CrsCod) AS users," + "agd_agendas" + " WHERE users.UsrCod=agd_agendas.UsrCod", + Gbl.Hierarchy.Deg.DegCod); + case Hie_Lvl_CRS: + return (unsigned) + DB_QueryCOUNT ("can not get number of events", + "SELECT COUNT(*)" + " FROM crs_users," + "agd_agendas" + " WHERE crs_users.CrsCod=%ld" + " AND crs_users.UsrCod=agd_agendas.UsrCod", + Gbl.Hierarchy.Crs.CrsCod); + default: + Err_WrongScopeExit (); + return 0; // Not reached + } + } diff --git a/swad_agenda_database.h b/swad_agenda_database.h new file mode 100644 index 00000000..dd10a32c --- /dev/null +++ b/swad_agenda_database.h @@ -0,0 +1,66 @@ +// swad_agenda_database.h: user's agenda (personal organizer) operations with database + +#ifndef _SWAD_AGD_DB +#define _SWAD_AGD_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 . +*/ +/*****************************************************************************/ +/********************************* Headers ***********************************/ +/*****************************************************************************/ + +#include "swad_agenda.h" + +/*****************************************************************************/ +/************************** Public types and constants ***********************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Public prototypes *****************************/ +/*****************************************************************************/ + +unsigned Agd_DB_GetListEvents (MYSQL_RES **mysql_res, + const struct Agd_Agenda *Agenda, + Agd_AgendaType_t AgendaType); + +unsigned Agd_DB_GetDataOfEventByCod (MYSQL_RES **mysql_res, + const struct Agd_Event *AgdEvent); +void Agd_DB_GetEventTxt (const struct Agd_Event *AgdEvent, + char Txt[Cns_MAX_BYTES_TEXT + 1]); + +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_MakeEventPublic (const struct Agd_Event *AgdEvent); +void Agd_DB_MakeEventPrivate (const struct Agd_Event *AgdEvent); + +void Agd_DB_RemoveUsrEvents (long UsrCod); + +unsigned Agd_DB_GetNumEventsFromUsr (long UsrCod); + +unsigned Agd_DB_GetNumUsrsWithEvents (Hie_Lvl_Level_t Scope); + +unsigned Agd_DB_GetNumEvents (Hie_Lvl_Level_t Scope); + +#endif diff --git a/swad_changelog.h b/swad_changelog.h index d7c4e901..da21999f 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -600,13 +600,14 @@ TODO: Salvador Romero Cort TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria. */ -#define Log_PLATFORM_VERSION "SWAD 20.72 (2021-05-10)" +#define Log_PLATFORM_VERSION "SWAD 20.73 (2021-05-10)" #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 20.73: May 10, 2021 New module swad_agenda_database for database queries related to agenda. (310474 lines) Version 20.72: May 10, 2021 New module swad_account_database for database queries related to user's account. (310328 lines) Version 20.71: May 10, 2021 New module swad_media_database for database queries related to media. (310080 lines) Version 20.70: May 07, 2021 New module swad_follow_database for database queries related to following/followers. (309943 lines) diff --git a/swad_figure.c b/swad_figure.c index 6b722599..45c0fb38 100644 --- a/swad_figure.c +++ b/swad_figure.c @@ -31,7 +31,7 @@ #include // For string functions #include "swad_action.h" -#include "swad_agenda.h" +#include "swad_agenda_database.h" #include "swad_box.h" #include "swad_database.h" #include "swad_error.h" @@ -4968,10 +4968,10 @@ static void Fig_GetAndShowAgendasStats (void) HTM_TR_End (); /***** Number of agenda events *****/ - NumEvents = Agd_GetNumEvents (Gbl.Scope.Current); + NumEvents = Agd_DB_GetNumEvents (Gbl.Scope.Current); /***** Number of users with agenda events *****/ - NumUsrs = Agd_GetNumUsrsWithEvents (Gbl.Scope.Current); + NumUsrs = Agd_DB_GetNumUsrsWithEvents (Gbl.Scope.Current); /***** Get total number of users in current scope *****/ NumUsrsTotal = Usr_GetTotalNumberOfUsers ();