swad-core/swad_agenda.c

1684 lines
56 KiB
C
Raw Normal View History

2016-07-07 00:21:10 +02:00
// swad_agenda.c: user's agenda (personal organizer)
/*
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-2023 Antonio Ca<EFBFBD>as Vargas
2016-07-07 00:21:10 +02:00
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 <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
2016-11-30 22:49:48 +01:00
/********************************* Headers ***********************************/
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
2018-10-18 21:32:06 +02:00
#define _GNU_SOURCE // For asprintf
2016-11-30 22:49:48 +01:00
#include <linux/limits.h> // For PATH_MAX
2019-12-29 12:39:00 +01:00
#include <stddef.h> // For NULL
2018-10-18 21:32:06 +02:00
#include <stdio.h> // For asprintf
2016-11-30 22:49:48 +01:00
#include <stdlib.h> // For calloc
#include <string.h> // For string functions
2016-07-07 00:21:10 +02:00
#include "swad_action_list.h"
2016-11-30 22:49:48 +01:00
#include "swad_agenda.h"
#include "swad_agenda_database.h"
#include "swad_autolink.h"
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2016-11-30 22:49:48 +01:00
#include "swad_database.h"
2020-04-28 13:12:18 +02:00
#include "swad_date.h"
#include "swad_error.h"
#include "swad_figure.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2016-11-30 22:49:48 +01:00
#include "swad_global.h"
#include "swad_group.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2016-11-30 22:49:48 +01:00
#include "swad_notification.h"
#include "swad_pagination.h"
#include "swad_parameter.h"
#include "swad_photo.h"
2016-12-09 14:50:21 +01:00
#include "swad_privacy.h"
2016-12-05 09:50:35 +01:00
#include "swad_QR.h"
2019-03-26 11:53:21 +01:00
#include "swad_setting.h"
2016-11-30 22:49:48 +01:00
#include "swad_string.h"
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
2016-11-30 22:49:48 +01:00
/************** External global variables from others modules ****************/
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
2016-11-30 22:49:48 +01:00
extern struct Globals Gbl;
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
static const char *ParPast__FutureName = "Past__Future";
static const char *ParPrivatPublicName = "PrivatPublic";
static const char *ParHiddenVisiblName = "HiddenVisibl";
2017-03-21 14:36:22 +01:00
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
2016-11-30 22:49:48 +01:00
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2020-04-12 14:42:32 +02:00
static void Agd_ResetAgenda (struct Agd_Agenda *Agenda);
static void Agd_ShowMyAgenda (struct Agd_Agenda *Agenda);
static void Agd_ShowFormToSelPast__FutureEvents (const struct Agd_Agenda *Agenda);
static void Agd_ShowFormToSelPrivatPublicEvents (const struct Agd_Agenda *Agenda);
static void Agd_ShowFormToSelHiddenVisiblEvents (const struct Agd_Agenda *Agenda);
2017-03-21 14:36:22 +01:00
static void Agd_PutParPast__FutureEvents (unsigned Past__FutureEvents);
static void Agd_PutParPrivatPublicEvents (unsigned PrivatPublicEvents);
static void Agd_PutParHiddenVisiblEvents (unsigned HiddenVisiblEvents);
static unsigned Agd_GetParsPast__FutureEvents (void);
static unsigned Agd_GetParsPrivatPublicEvents (void);
static unsigned Agd_GetParsHiddenVisiblEvents (void);
2017-03-21 00:57:11 +01:00
2020-04-12 14:42:32 +02:00
static void Agd_ShowEvents (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType);
static void Agd_ShowEventsToday (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType);
static void Agd_WriteHeaderListEvents (const struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType);
2016-12-02 00:24:16 +01:00
2020-03-26 02:54:30 +01:00
static void Agd_PutIconsMyFullAgenda (void *Agenda);
static void Agd_PutIconsMyPublicAgenda (void *EncryptedUsrCod);
static void Agd_PutIconToCreateNewEvent (void *Agenda);
static void Agd_PutIconToViewEditMyFullAgenda (void *EncryptedUsrCod);
2016-12-05 03:16:25 +01:00
static void Agd_PutIconToShowQR (void);
2020-03-26 02:54:30 +01:00
static void Agd_PutIconsOtherPublicAgenda (void *EncryptedUsrCod);
2016-12-06 21:08:28 +01:00
2020-04-12 14:42:32 +02:00
static void Agd_PutButtonToCreateNewEvent (const struct Agd_Agenda *Agenda);
static void Agd_ShowOneEvent (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType,long AgdCod);
static void Agd_GetParEventOrder (struct Agd_Agenda *Agenda);
2020-04-12 14:42:32 +02:00
static void Agd_PutFormsToRemEditOneEvent (struct Agd_Agenda *Agenda,
struct Agd_Event *AgdEvent,
2019-04-20 19:04:05 +02:00
const char *Anchor);
2017-03-21 14:36:22 +01:00
static void Agd_PutCurrentParsMyAgenda (void *Agenda);
static void Agd_GetPars (struct Agd_Agenda *Agenda,
2020-04-12 14:42:32 +02:00
Agd_AgendaType_t AgendaType);
2017-03-21 14:36:22 +01:00
2020-04-12 14:42:32 +02:00
static void Agd_GetListEvents (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType);
2020-04-08 03:06:45 +02:00
static void Agd_GetDataOfEventByCod (struct Agd_Event *AgdEvent);
2020-04-12 14:42:32 +02:00
static void Agd_FreeListEvents (struct Agd_Agenda *Agenda);
/*****************************************************************************/
/*************************** Reset agenda context ****************************/
/*****************************************************************************/
static void Agd_ResetAgenda (struct Agd_Agenda *Agenda)
{
Agenda->LstIsRead = false;
Agenda->Num = 0;
Agenda->LstAgdCods = NULL;
Agenda->Past__FutureEvents = Agd_DEFAULT_PAST___EVENTS |
Agd_DEFAULT_FUTURE_EVENTS;
Agenda->PrivatPublicEvents = Agd_DEFAULT_PRIVAT_EVENTS |
Agd_DEFAULT_PUBLIC_EVENTS;
Agenda->HiddenVisiblEvents = Agd_DEFAULT_HIDDEN_EVENTS |
Agd_DEFAULT_VISIBL_EVENTS;
Agenda->SelectedOrder = Agd_ORDER_DEFAULT;
Agenda->AgdCodToEdit = -1L;
Agenda->CurrentPage = 0;
}
2016-12-01 00:53:50 +01:00
/*****************************************************************************/
2016-12-04 04:22:36 +01:00
/********** Put form to log in and then show another user's agenda ***********/
2016-12-01 00:53:50 +01:00
/*****************************************************************************/
2016-12-04 04:22:36 +01:00
void Agd_PutFormLogInToShowUsrAgenda (void)
2016-12-04 03:50:25 +01:00
{
Usr_WriteFormLogin (ActLogInUsrAgd,Agd_PutParAgd);
2016-12-05 13:26:12 +01:00
}
void Agd_PutParAgd (void)
2016-12-05 13:26:12 +01:00
{
char NickWithArr[Nck_MAX_BYTES_NICK_WITH_ARROBA + 1];
2016-12-05 13:26:12 +01:00
snprintf (NickWithArr,sizeof (NickWithArr),"@%s",Gbl.Usrs.Other.UsrDat.Nickname);
Par_PutParString (NULL,"agd",NickWithArr);
2016-12-04 04:22:36 +01:00
}
/*****************************************************************************/
2016-12-06 21:26:02 +01:00
/******************************* Show my agenda ******************************/
2016-12-04 04:22:36 +01:00
/*****************************************************************************/
void Agd_GetParsAndShowMyAgenda (void)
2016-12-04 04:22:36 +01:00
{
2020-04-12 14:42:32 +02:00
struct Agd_Agenda Agenda;
/***** Reset agenda context *****/
Agd_ResetAgenda (&Agenda);
2016-12-06 21:26:02 +01:00
2017-03-21 14:36:22 +01:00
/***** Get parameters *****/
Agd_GetPars (&Agenda,Agd_MY_AGENDA);
2020-04-12 14:42:32 +02:00
/***** Show my agenda *****/
Agd_ShowMyAgenda (&Agenda);
}
static void Agd_ShowMyAgenda (struct Agd_Agenda *Agenda)
{
extern const char *Hlp_PROFILE_Agenda;
extern const char *Txt_My_agenda;
2017-03-21 14:36:22 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin ("100%",Txt_My_agenda,
2020-04-12 14:42:32 +02:00
Agd_PutIconsMyFullAgenda,Agenda,
2017-06-12 15:03:29 +02:00
Hlp_PROFILE_Agenda,Box_NOT_CLOSABLE);
2016-12-06 21:26:02 +01:00
/***** Put forms to choice which events to show *****/
Set_BeginSettingsHead ();
Agd_ShowFormToSelPast__FutureEvents (Agenda);
Agd_ShowFormToSelPrivatPublicEvents (Agenda);
Agd_ShowFormToSelHiddenVisiblEvents (Agenda);
Set_EndSettingsHead ();
2017-03-21 00:57:11 +01:00
/***** Show the current events in the user's agenda *****/
Agd_ShowEventsToday (Agenda,Agd_MY_AGENDA_TODAY);
2016-12-06 21:26:02 +01:00
/***** Show all my events *****/
Agd_ShowEvents (Agenda,Agd_MY_AGENDA);
2016-12-06 21:26:02 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-12-06 21:26:02 +01:00
}
2017-03-21 00:57:11 +01:00
/*****************************************************************************/
/*************** Show form to select past / future events ********************/
/*****************************************************************************/
2020-04-12 14:42:32 +02:00
static void Agd_ShowFormToSelPast__FutureEvents (const struct Agd_Agenda *Agenda)
2017-03-21 00:57:11 +01:00
{
2017-03-21 14:36:22 +01:00
extern const char *Txt_AGENDA_PAST___FUTURE_EVENTS[2];
Agd_Past__FutureEvents_t PstFut;
2019-02-21 21:12:04 +01:00
static const char *Icon[2] =
2017-03-21 00:57:11 +01:00
{
2019-11-20 17:53:51 +01:00
[Agd_PAST___EVENTS] = "calendar-minus.svg",
[Agd_FUTURE_EVENTS] = "calendar-plus.svg",
2017-03-21 00:57:11 +01:00
};
Set_BeginOneSettingSelector ();
for (PstFut = Agd_PAST___EVENTS;
2017-03-21 00:57:11 +01:00
PstFut <= Agd_FUTURE_EVENTS;
PstFut++)
{
Set_BeginPref ((Agenda->Past__FutureEvents & (1 << PstFut)));
Frm_BeginForm (ActSeeMyAgd);
Agd_PutParsMyAgenda (Agenda->Past__FutureEvents ^ (1 << PstFut), // Toggle
Agenda->PrivatPublicEvents,
Agenda->HiddenVisiblEvents,
Agenda->SelectedOrder,
Agenda->CurrentPage,
-1L);
Ico_PutSettingIconLink (Icon[PstFut],Ico_BLACK,
Txt_AGENDA_PAST___FUTURE_EVENTS[PstFut]);
Frm_EndForm ();
Set_EndPref ();
2017-03-21 00:57:11 +01:00
}
2019-03-26 11:53:21 +01:00
Set_EndOneSettingSelector ();
2017-03-21 00:57:11 +01:00
}
/*****************************************************************************/
/************** Show form to select private / public events ******************/
/*****************************************************************************/
2020-04-12 14:42:32 +02:00
static void Agd_ShowFormToSelPrivatPublicEvents (const struct Agd_Agenda *Agenda)
2017-03-21 00:57:11 +01:00
{
2017-03-21 14:36:22 +01:00
extern const char *Txt_AGENDA_PRIVAT_PUBLIC_EVENTS[2];
Agd_PrivatPublicEvents_t PrvPub;
static const struct
{
const char *Icon;
Ico_Color_t Color;
} Icon[2] =
2017-03-21 00:57:11 +01:00
{
[Agd_PRIVAT_EVENTS] = {"lock.svg" ,Ico_RED },
[Agd_PUBLIC_EVENTS] = {"unlock.svg",Ico_GREEN},
2017-03-21 00:57:11 +01:00
};
Set_BeginOneSettingSelector ();
for (PrvPub = Agd_PRIVAT_EVENTS;
2017-03-21 14:36:22 +01:00
PrvPub <= Agd_PUBLIC_EVENTS;
2017-03-21 00:57:11 +01:00
PrvPub++)
{
Set_BeginPref ((Agenda->PrivatPublicEvents & (1 << PrvPub)));
Frm_BeginForm (ActSeeMyAgd);
Agd_PutParsMyAgenda (Agenda->Past__FutureEvents,
Agenda->PrivatPublicEvents ^ (1 << PrvPub), // Toggle
Agenda->HiddenVisiblEvents,
Agenda->SelectedOrder,
Agenda->CurrentPage,
-1L);
Ico_PutSettingIconLink (Icon[PrvPub].Icon,Icon[PrvPub].Color,
Txt_AGENDA_PRIVAT_PUBLIC_EVENTS[PrvPub]);
Frm_EndForm ();
Set_EndPref ();
2017-03-21 00:57:11 +01:00
}
2019-03-26 11:53:21 +01:00
Set_EndOneSettingSelector ();
2017-03-21 00:57:11 +01:00
}
/*****************************************************************************/
/************* Show form to select hidden / visible events *******************/
/*****************************************************************************/
2020-04-12 14:42:32 +02:00
static void Agd_ShowFormToSelHiddenVisiblEvents (const struct Agd_Agenda *Agenda)
2017-03-21 00:57:11 +01:00
{
2017-03-21 14:36:22 +01:00
extern const char *Txt_AGENDA_HIDDEN_VISIBL_EVENTS[2];
Agd_HiddenVisiblEvents_t HidVis;
static const struct
{
const char *Icon;
Ico_Color_t Color;
} Icon[2] =
2017-03-21 00:57:11 +01:00
{
[Agd_HIDDEN_EVENTS] = {"eye-slash.svg",Ico_RED },
[Agd_VISIBL_EVENTS] = {"eye.svg" ,Ico_GREEN},
2017-03-21 00:57:11 +01:00
};
Set_BeginOneSettingSelector ();
for (HidVis = Agd_HIDDEN_EVENTS;
2017-03-21 14:36:22 +01:00
HidVis <= Agd_VISIBL_EVENTS;
2017-03-21 00:57:11 +01:00
HidVis++)
{
Set_BeginPref ((Agenda->HiddenVisiblEvents & (1 << HidVis)));
Frm_BeginForm (ActSeeMyAgd);
Agd_PutParsMyAgenda (Agenda->Past__FutureEvents,
Agenda->PrivatPublicEvents,
Agenda->HiddenVisiblEvents ^ (1 << HidVis), // Toggle
Agenda->SelectedOrder,
Agenda->CurrentPage,
-1L);
Ico_PutSettingIconLink (Icon[HidVis].Icon,Icon[HidVis].Color,
Txt_AGENDA_HIDDEN_VISIBL_EVENTS[HidVis]);
Frm_EndForm ();
Set_EndPref ();
2017-03-21 00:57:11 +01:00
}
2019-03-26 11:53:21 +01:00
Set_EndOneSettingSelector ();
2017-03-21 00:57:11 +01:00
}
/*****************************************************************************/
2017-03-21 14:36:22 +01:00
/************************ Put hidden params for events ***********************/
2017-03-21 00:57:11 +01:00
/*****************************************************************************/
static void Agd_PutParPast__FutureEvents (unsigned Past__FutureEvents)
2017-03-21 00:57:11 +01:00
{
Par_PutParUnsigned (NULL,ParPast__FutureName,Past__FutureEvents);
2017-03-21 00:57:11 +01:00
}
static void Agd_PutParPrivatPublicEvents (unsigned PrivatPublicEvents)
2017-03-21 00:57:11 +01:00
{
Par_PutParUnsigned (NULL,ParPrivatPublicName,PrivatPublicEvents);
2017-03-21 14:36:22 +01:00
}
2017-03-21 00:57:11 +01:00
static void Agd_PutParHiddenVisiblEvents (unsigned HiddenVisiblEvents)
2017-03-21 14:36:22 +01:00
{
Par_PutParUnsigned (NULL,ParHiddenVisiblName,HiddenVisiblEvents);
2017-03-21 00:57:11 +01:00
}
/*****************************************************************************/
2017-03-21 14:36:22 +01:00
/************************ Get hidden params for events ***********************/
2017-03-21 00:57:11 +01:00
/*****************************************************************************/
static unsigned Agd_GetParsPast__FutureEvents (void)
2017-03-21 00:57:11 +01:00
{
return (unsigned) Par_GetParUnsignedLong (ParPast__FutureName,
0,
(1 << Agd_PAST___EVENTS) |
(1 << Agd_FUTURE_EVENTS),
Agd_DEFAULT_PAST___EVENTS |
Agd_DEFAULT_FUTURE_EVENTS);
2017-03-21 14:36:22 +01:00
}
2017-03-21 00:57:11 +01:00
static unsigned Agd_GetParsPrivatPublicEvents (void)
2017-03-21 14:36:22 +01:00
{
return (unsigned) Par_GetParUnsignedLong (ParPrivatPublicName,
0,
(1 << Agd_PRIVAT_EVENTS) |
(1 << Agd_PUBLIC_EVENTS),
Agd_DEFAULT_PRIVAT_EVENTS |
Agd_DEFAULT_PUBLIC_EVENTS);
2017-03-21 14:36:22 +01:00
}
static unsigned Agd_GetParsHiddenVisiblEvents (void)
2017-03-21 14:36:22 +01:00
{
return (unsigned) Par_GetParUnsignedLong (ParHiddenVisiblName,
0,
(1 << Agd_HIDDEN_EVENTS) |
(1 << Agd_VISIBL_EVENTS),
Agd_DEFAULT_HIDDEN_EVENTS |
Agd_DEFAULT_VISIBL_EVENTS);
2017-03-21 00:57:11 +01:00
}
2016-12-04 03:50:25 +01:00
/*****************************************************************************/
/************************ Show another user's agenda *************************/
/*****************************************************************************/
2016-12-02 00:24:16 +01:00
void Agd_ShowUsrAgenda (void)
2016-11-30 22:49:48 +01:00
{
2016-12-07 10:16:39 +01:00
extern const char *Hlp_PROFILE_Agenda_public_agenda;
2016-12-06 03:10:06 +01:00
extern const char *Txt_Public_agenda_USER;
2020-04-12 14:42:32 +02:00
struct Agd_Agenda Agenda;
2016-12-09 13:59:33 +01:00
bool Error = true;
bool ItsMe;
char *Title;
2016-11-30 22:49:48 +01:00
2016-12-02 00:24:16 +01:00
/***** Get user *****/
if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ())
2016-12-09 13:59:33 +01:00
if (Usr_CheckIfICanViewUsrAgenda (&Gbl.Usrs.Other.UsrDat))
{
Error = false;
2020-04-12 14:42:32 +02:00
/***** Reset agenda context *****/
Agd_ResetAgenda (&Agenda);
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
if (asprintf (&Title,Txt_Public_agenda_USER,
ItsMe ? Gbl.Usrs.Me.UsrDat.FullName :
Gbl.Usrs.Other.UsrDat.FullName) < 0)
Err_NotEnoughMemoryExit ();
Box_BoxBegin ("100%",Title,
ItsMe ? Agd_PutIconsMyPublicAgenda :
Agd_PutIconsOtherPublicAgenda,
ItsMe ? Gbl.Usrs.Me.UsrDat.EnUsrCod :
Gbl.Usrs.Other.UsrDat.EnUsrCod,
Hlp_PROFILE_Agenda_public_agenda,Box_NOT_CLOSABLE);
free (Title);
2016-12-09 13:59:33 +01:00
/***** Show the current events in the user's agenda *****/
Agd_ShowEventsToday (&Agenda,Agd_ANOTHER_AGENDA_TODAY);
2016-12-09 13:59:33 +01:00
/***** Show all visible events in the user's agenda *****/
Agd_ShowEvents (&Agenda,Agd_ANOTHER_AGENDA);
2016-12-09 13:59:33 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-12-09 13:59:33 +01:00
}
if (Error)
2019-03-09 20:12:44 +01:00
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
2016-11-30 22:49:48 +01:00
}
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
2016-12-06 21:26:02 +01:00
/***************** Show another user's agenda after log in *******************/
2016-12-06 21:08:28 +01:00
/*****************************************************************************/
2016-12-06 21:26:02 +01:00
void Agd_ShowOtherAgendaAfterLogIn (void)
2016-12-06 21:08:28 +01:00
{
2016-12-07 10:16:39 +01:00
extern const char *Hlp_PROFILE_Agenda_public_agenda;
2018-12-09 10:46:57 +01:00
extern const unsigned Txt_Current_CGI_SWAD_Language;
2016-12-06 21:08:28 +01:00
extern const char *Txt_Public_agenda_USER;
2018-12-08 16:43:13 +01:00
extern const char *Txt_Switching_to_LANGUAGE[1 + Lan_NUM_LANGUAGES];
2020-04-12 14:42:32 +02:00
struct Agd_Agenda Agenda;
bool ItsMe;
char *Title;
2016-12-06 21:08:28 +01:00
2016-12-06 21:26:02 +01:00
if (Gbl.Usrs.Me.Logged)
{
2018-12-09 10:46:57 +01:00
if (Gbl.Usrs.Me.UsrDat.Prefs.Language == Txt_Current_CGI_SWAD_Language)
2016-12-06 21:26:02 +01:00
{
/***** Get user *****/
/* If nickname is correct, user code is already got from nickname */
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat, // Existing user
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CURRENT_CRS))
2016-12-06 21:26:02 +01:00
{
2020-04-12 14:42:32 +02:00
/***** Reset agenda context *****/
Agd_ResetAgenda (&Agenda);
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
if (asprintf (&Title,Txt_Public_agenda_USER,
ItsMe ? Gbl.Usrs.Me.UsrDat.FullName :
Gbl.Usrs.Other.UsrDat.FullName) < 0)
Err_NotEnoughMemoryExit ();
Box_BoxBegin ("100%",Title,
ItsMe ? Agd_PutIconToViewEditMyFullAgenda :
Agd_PutIconsOtherPublicAgenda,
ItsMe ? Gbl.Usrs.Me.UsrDat.EnUsrCod :
Gbl.Usrs.Other.UsrDat.EnUsrCod,
Hlp_PROFILE_Agenda_public_agenda,Box_NOT_CLOSABLE);
free (Title);
2016-12-06 03:10:06 +01:00
/***** Show the current events in the user's agenda *****/
Agd_ShowEventsToday (&Agenda,Agd_ANOTHER_AGENDA_TODAY);
2016-12-06 03:10:06 +01:00
/***** Show all visible events in the user's agenda *****/
Agd_ShowEvents (&Agenda,Agd_ANOTHER_AGENDA);
2016-12-06 03:10:06 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-12-06 21:26:02 +01:00
}
else
2019-03-09 20:12:44 +01:00
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
2016-12-06 21:26:02 +01:00
}
else
/* The current language is not my preferred language
==> change automatically to my language */
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_INFO,Txt_Switching_to_LANGUAGE[Gbl.Usrs.Me.UsrDat.Prefs.Language]);
2016-12-06 21:26:02 +01:00
}
2016-12-02 00:24:16 +01:00
}
/*****************************************************************************/
/*************************** Show events in agenda ***************************/
/*****************************************************************************/
2020-04-12 14:42:32 +02:00
static void Agd_ShowEvents (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType)
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
extern const char *Hlp_PROFILE_Agenda;
2016-12-03 23:48:03 +01:00
extern const char *Txt_Public_agenda_USER;
2016-12-02 00:24:16 +01:00
extern const char *Txt_My_agenda;
2016-12-01 00:53:50 +01:00
extern const char *Txt_No_events;
struct Pag_Pagination Pagination;
2016-12-02 00:24:16 +01:00
unsigned NumEvent;
2019-11-21 11:39:30 +01:00
static const Pag_WhatPaginate_t WhatPaginate[Agd_NUM_AGENDA_TYPES] =
2016-12-02 00:24:16 +01:00
{
2019-11-20 17:53:51 +01:00
[Agd_MY_AGENDA_TODAY ] = Pag_MY_AGENDA, // not used
[Agd_MY_AGENDA ] = Pag_MY_AGENDA,
[Agd_ANOTHER_AGENDA_TODAY] = Pag_ANOTHER_AGENDA, // not used
[Agd_ANOTHER_AGENDA ] = Pag_ANOTHER_AGENDA,
2016-12-02 00:24:16 +01:00
};
/***** Get parameters *****/
Agd_GetPars (Agenda,AgendaType);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get list of events *****/
2020-04-12 14:42:32 +02:00
Agd_GetListEvents (Agenda,AgendaType);
2016-11-30 22:49:48 +01:00
/***** Compute variables related to pagination *****/
2020-04-12 14:42:32 +02:00
Pagination.NumItems = Agenda->Num;
Pagination.CurrentPage = (int) Agenda->CurrentPage;
2016-11-30 22:49:48 +01:00
Pag_CalculatePagination (&Pagination);
2020-04-12 14:42:32 +02:00
Agenda->CurrentPage = (unsigned) Pagination.CurrentPage;
2016-11-30 22:49:48 +01:00
/***** Write links to pages *****/
2020-04-10 19:14:08 +02:00
Pag_WriteLinksToPagesCentered (WhatPaginate[AgendaType],&Pagination,
2020-04-12 14:42:32 +02:00
Agenda,-1L);
2016-11-30 22:49:48 +01:00
2020-04-12 14:42:32 +02:00
if (Agenda->Num)
2016-11-30 22:49:48 +01:00
{
2019-10-20 22:00:28 +02:00
/***** Begin table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWideMarginPadding (2);
2016-12-06 03:10:06 +01:00
/***** Table head *****/
Agd_WriteHeaderListEvents (Agenda,AgendaType);
2016-11-30 22:49:48 +01:00
/***** Write all events *****/
for (NumEvent = Pagination.FirstItemVisible, The_ResetRowColor ();
NumEvent <= Pagination.LastItemVisible;
NumEvent++, The_ChangeRowColor ())
Agd_ShowOneEvent (Agenda,AgendaType,Agenda->LstAgdCods[NumEvent - 1]);
2016-11-30 22:49:48 +01:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2016-11-30 22:49:48 +01:00
}
2016-12-06 03:10:06 +01:00
else
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_INFO,Txt_No_events);
2016-11-30 22:49:48 +01:00
2016-12-06 03:10:06 +01:00
/***** Write again links to pages *****/
2020-04-10 19:14:08 +02:00
Pag_WriteLinksToPagesCentered (WhatPaginate[AgendaType],&Pagination,
2020-04-12 14:42:32 +02:00
Agenda,-1L);
2016-12-06 03:10:06 +01:00
2016-12-01 00:53:50 +01:00
/***** Button to create a new event *****/
2017-03-21 14:52:07 +01:00
if (AgendaType == Agd_MY_AGENDA)
2020-04-12 14:42:32 +02:00
Agd_PutButtonToCreateNewEvent (Agenda);
2016-11-30 22:49:48 +01:00
2016-12-06 03:10:06 +01:00
/***** Free list of events *****/
2020-04-12 14:42:32 +02:00
Agd_FreeListEvents (Agenda);
2016-12-06 03:10:06 +01:00
}
2016-11-30 22:49:48 +01:00
2016-12-06 03:10:06 +01:00
/*****************************************************************************/
2016-12-06 21:08:28 +01:00
/************************ Show today events in agenda ************************/
2016-12-06 03:10:06 +01:00
/*****************************************************************************/
2020-04-12 14:42:32 +02:00
static void Agd_ShowEventsToday (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType)
2016-12-06 03:10:06 +01:00
{
extern const char *Hlp_PROFILE_Agenda;
2016-12-07 10:16:39 +01:00
extern const char *Hlp_PROFILE_Agenda_public_agenda;
2016-12-06 18:04:12 +01:00
extern const char *Txt_Today;
2016-12-06 03:10:06 +01:00
extern const char *Txt_Public_agenda_USER;
extern const char *Txt_My_agenda;
extern const char *Txt_No_events;
unsigned NumEvent;
/***** Get parameters *****/
Agd_GetPars (Agenda,AgendaType);
2016-12-06 03:10:06 +01:00
/***** Get list of events *****/
2020-04-12 14:42:32 +02:00
Agd_GetListEvents (Agenda,AgendaType);
2016-12-06 03:10:06 +01:00
2020-04-12 14:42:32 +02:00
if (Agenda->Num)
2016-12-06 03:10:06 +01:00
{
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2016-12-06 19:14:58 +01:00
switch (AgendaType)
{
2017-03-21 14:52:07 +01:00
case Agd_MY_AGENDA_TODAY:
2020-03-26 02:54:30 +01:00
Box_BoxTableShadowBegin (NULL,Txt_Today,
NULL,NULL,
2017-06-11 22:26:40 +02:00
Hlp_PROFILE_Agenda,
2);
2016-12-06 19:14:58 +01:00
break;
2017-03-21 14:52:07 +01:00
case Agd_ANOTHER_AGENDA_TODAY:
2020-03-26 02:54:30 +01:00
Box_BoxTableShadowBegin (NULL,Txt_Today,
NULL,NULL,
2017-06-11 22:26:40 +02:00
Hlp_PROFILE_Agenda_public_agenda,
2);
2016-12-06 21:26:02 +01:00
break;
2016-12-06 21:08:28 +01:00
default:
2016-12-06 19:14:58 +01:00
break;
}
2016-12-06 03:10:06 +01:00
/***** Table head *****/
Agd_WriteHeaderListEvents (Agenda,AgendaType);
2016-12-06 03:10:06 +01:00
/***** Write all events *****/
for (NumEvent = 0, The_ResetRowColor ();
NumEvent < Agenda->Num;
NumEvent++, The_ChangeRowColor ())
Agd_ShowOneEvent (Agenda,AgendaType,Agenda->LstAgdCods[NumEvent]);
2016-12-06 03:10:06 +01:00
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
2016-12-06 03:10:06 +01:00
}
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Free list of events *****/
2020-04-12 14:42:32 +02:00
Agd_FreeListEvents (Agenda);
2016-11-30 22:49:48 +01:00
}
2016-12-05 23:13:58 +01:00
/*****************************************************************************/
/*************** Put contextual icon to view/edit my agenda ******************/
/*****************************************************************************/
2020-04-12 14:42:32 +02:00
static void Agd_WriteHeaderListEvents (const struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType)
2016-12-06 03:10:06 +01:00
{
2016-12-15 00:39:52 +01:00
extern const char *Txt_START_END_TIME_HELP[2];
extern const char *Txt_START_END_TIME[Dat_NUM_START_END_TIME];
2016-12-06 03:10:06 +01:00
extern const char *Txt_Event;
extern const char *Txt_Location;
2020-04-05 22:53:58 +02:00
Dat_StartEndTime_t Order;
2016-12-06 03:10:06 +01:00
/***** Table head *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-11 01:02:51 +02:00
for (Order = (Dat_StartEndTime_t) 0;
Order <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
Order++)
2016-12-06 03:10:06 +01:00
{
HTM_TH_Begin (HTM_HEAD_LEFT);
switch (AgendaType)
{
case Agd_MY_AGENDA_TODAY:
case Agd_MY_AGENDA:
Frm_BeginForm (ActSeeMyAgd);
Pag_PutParPagNum (Pag_MY_AGENDA,Agenda->CurrentPage);
break;
case Agd_ANOTHER_AGENDA_TODAY:
case Agd_ANOTHER_AGENDA:
Frm_BeginForm (ActSeeUsrAgd);
Usr_PutParOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
Pag_PutParPagNum (Pag_ANOTHER_AGENDA,Agenda->CurrentPage);
break;
}
Agd_PutParsMyAgenda (Agenda->Past__FutureEvents,
Agenda->PrivatPublicEvents,
Agenda->HiddenVisiblEvents,
Order,
Agenda->CurrentPage,
-1L);
HTM_BUTTON_Submit_Begin (Txt_START_END_TIME_HELP[Order],
"class=\"BT_LINK\"");
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 ();
2016-12-06 03:10:06 +01:00
}
2019-10-11 01:02:51 +02:00
HTM_TH (Txt_Event ,HTM_HEAD_LEFT);
HTM_TH (Txt_Location,HTM_HEAD_LEFT);
2019-10-11 01:02:51 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2016-12-06 03:10:06 +01:00
}
/*****************************************************************************/
2016-12-06 21:08:28 +01:00
/********************** Put contextual icons in agenda ***********************/
2016-12-06 03:10:06 +01:00
/*****************************************************************************/
2020-03-26 02:54:30 +01:00
static void Agd_PutIconsMyFullAgenda (void *Agenda)
2016-12-05 23:13:58 +01:00
{
2016-12-06 21:08:28 +01:00
/***** Put icon to create a new event *****/
2020-03-26 02:54:30 +01:00
Agd_PutIconToCreateNewEvent (Agenda);
2016-12-05 23:13:58 +01:00
2016-12-06 21:08:28 +01:00
/***** Put icon to show QR code *****/
Agd_PutIconToShowQR ();
}
2016-12-05 03:16:25 +01:00
2020-03-26 02:54:30 +01:00
static void Agd_PutIconsMyPublicAgenda (void *EncryptedUsrCod)
2016-12-05 03:16:25 +01:00
{
2016-12-06 21:08:28 +01:00
/***** Put icon to view/edit my full agenda *****/
2020-03-26 02:54:30 +01:00
Agd_PutIconToViewEditMyFullAgenda (EncryptedUsrCod);
2016-12-05 03:16:25 +01:00
/***** Put icon to show QR code *****/
Agd_PutIconToShowQR ();
}
2020-03-26 02:54:30 +01:00
static void Agd_PutIconToCreateNewEvent (void *Agenda)
2016-11-30 22:49:48 +01:00
{
2020-04-12 14:42:32 +02:00
((struct Agd_Agenda *) Agenda)->AgdCodToEdit = -1L;
2019-01-10 15:26:33 +01:00
Ico_PutContextualIconToAdd (ActFrmNewEvtMyAgd,NULL,
Agd_PutCurrentParsMyAgenda,Agenda);
2016-11-30 22:49:48 +01:00
}
2020-03-26 02:54:30 +01:00
static void Agd_PutIconToViewEditMyFullAgenda (void *EncryptedUsrCod)
2016-12-06 21:08:28 +01:00
{
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToEdit (ActSeeMyAgd,NULL,
NULL,EncryptedUsrCod);
2016-12-06 21:08:28 +01:00
}
2016-12-05 03:16:25 +01:00
static void Agd_PutIconToShowQR (void)
{
char URL[Cns_MAX_BYTES_WWW + 1];
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2016-12-05 09:50:35 +01:00
snprintf (URL,sizeof (URL),"%s/%s?agd=@%s",
Cfg_URL_SWAD_CGI,Lan_STR_LANG_ID[Gbl.Prefs.Language],
2018-10-17 01:08:42 +02:00
Gbl.Usrs.Me.UsrDat.Nickname);
2020-03-26 02:54:30 +01:00
QR_PutLinkToPrintQRCode (ActPrnAgdQR,
QR_PutParQRString,URL);
2016-12-05 03:16:25 +01:00
}
2020-03-26 02:54:30 +01:00
static void Agd_PutIconsOtherPublicAgenda (void *EncryptedUsrCod)
2016-12-09 14:50:21 +01:00
{
/***** Button to view user's public profile *****/
2019-03-22 15:21:46 +01:00
if (Pri_ShowingIsAllowed (Gbl.Usrs.Other.UsrDat.BaPrfVisibility,
2017-02-17 01:59:58 +01:00
&Gbl.Usrs.Other.UsrDat))
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (ActSeeOthPubPrf,NULL,
Usr_PutParOtherUsrCodEncrypted,EncryptedUsrCod,
"user.svg",Ico_BLACK);
2016-12-09 14:50:21 +01:00
/***** Button to view user's record card *****/
if (Usr_CheckIfICanViewRecordStd (&Gbl.Usrs.Other.UsrDat))
/* View student's records: common record card and course record card */
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (ActSeeRecOneStd,NULL,
Usr_PutParOtherUsrCodEncrypted,EncryptedUsrCod,
"address-card.svg",Ico_BLACK);
2016-12-09 14:50:21 +01:00
else if (Usr_CheckIfICanViewRecordTch (&Gbl.Usrs.Other.UsrDat))
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (ActSeeRecOneTch,NULL,
Usr_PutParOtherUsrCodEncrypted,EncryptedUsrCod,
"address-card.svg",Ico_BLACK);
2016-12-09 14:50:21 +01:00
}
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/********************* Put button to create a new event **********************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2020-04-12 14:42:32 +02:00
static void Agd_PutButtonToCreateNewEvent (const struct Agd_Agenda *Agenda)
2016-11-30 22:49:48 +01:00
{
extern const char *Txt_New_event;
/***** Begin form *****/
Frm_BeginForm (ActFrmNewEvtMyAgd);
Agd_PutParsMyAgenda (Agenda->Past__FutureEvents,
Agenda->PrivatPublicEvents,
Agenda->HiddenVisiblEvents,
Agenda->SelectedOrder,
Agenda->CurrentPage,
-1L);
/***** Confirm button *****/
Btn_PutConfirmButton (Txt_New_event);
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/******************************* Show one event ******************************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2020-04-12 14:42:32 +02:00
static void Agd_ShowOneEvent (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType,long AgdCod)
2016-11-30 22:49:48 +01:00
{
2016-12-02 10:45:53 +01:00
extern const char *Dat_TimeStatusClassVisible[Dat_NUM_TIME_STATUS];
extern const char *Dat_TimeStatusClassHidden[Dat_NUM_TIME_STATUS];
2019-04-20 19:04:05 +02:00
char *Anchor = NULL;
2016-11-30 22:49:48 +01:00
static unsigned UniqueId = 0;
2019-11-01 22:53:39 +01:00
char *Id;
2020-04-08 03:06:45 +02:00
struct Agd_Event AgdEvent;
2019-09-27 00:30:05 +02:00
Dat_StartEndTime_t StartEndTime;
2017-01-28 15:58:46 +01:00
char Txt[Cns_MAX_BYTES_TEXT + 1];
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get data of this event *****/
AgdEvent.AgdCod = AgdCod;
2016-12-02 00:24:16 +01:00
switch (AgendaType)
{
2017-03-21 14:52:07 +01:00
case Agd_MY_AGENDA_TODAY:
case Agd_MY_AGENDA:
2016-12-02 00:24:16 +01:00
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
break;
2017-03-21 14:52:07 +01:00
case Agd_ANOTHER_AGENDA_TODAY:
case Agd_ANOTHER_AGENDA:
2016-12-06 21:26:02 +01:00
AgdEvent.UsrCod = Gbl.Usrs.Other.UsrDat.UsrCod;
break;
2016-12-02 00:24:16 +01:00
}
2016-12-01 00:53:50 +01:00
Agd_GetDataOfEventByCod (&AgdEvent);
2016-11-30 22:49:48 +01:00
2019-04-20 19:04:05 +02:00
/***** Set anchor string *****/
2019-04-20 21:11:44 +02:00
Frm_SetAnchorStr (AgdEvent.AgdCod,&Anchor);
2019-04-20 19:04:05 +02:00
2016-12-01 00:53:50 +01:00
/***** Write first row of data of this event *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2016-11-30 22:49:48 +01:00
/* 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=\"LB %s_%s %s\"",
Id,
AgdEvent.Hidden ? Dat_TimeStatusClassHidden[AgdEvent.TimeStatus] :
Dat_TimeStatusClassVisible[AgdEvent.TimeStatus],
The_GetSuffix (),
The_GetColorRows ());
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=\"LT %s\"",The_GetColorRows ());
HTM_ARTICLE_Begin (Anchor);
HTM_SPAN_Begin ("class=\"%s_%s\"",
AgdEvent.Hidden ? "ASG_TITLE_LIGHT" :
"ASG_TITLE",
The_GetSuffix ());
HTM_Txt (AgdEvent.Event);
HTM_SPAN_End ();
HTM_ARTICLE_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2016-11-30 22:49:48 +01:00
/* Location */
HTM_TD_Begin ("class=\"LT %s\"",The_GetColorRows ());
HTM_SPAN_Begin ("class=\"%s_%s\"",
AgdEvent.Hidden ? "ASG_TITLE_LIGHT" :
"ASG_TITLE",
The_GetSuffix ());
HTM_Txt (AgdEvent.Location);
HTM_SPAN_End ();
HTM_TD_End ();
2016-11-30 22:49:48 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-09-27 00:30:05 +02:00
2016-12-01 00:53:50 +01:00
/***** Write second row of data of this event *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2016-11-30 22:49:48 +01:00
HTM_TD_Begin ("colspan=\"2\" class=\"LT %s\"",The_GetColorRows ());
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 ();
2019-10-07 22:28:16 +02:00
/* Text of the event */
HTM_TD_Begin ("colspan=\"2\" class=\"LT %s\"",The_GetColorRows ());
HTM_DIV_Begin ("class=\"PAR %s_%s\"",
AgdEvent.Hidden ? "DAT_LIGHT" :
"DAT",
The_GetSuffix ());
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
ALn_InsertLinks (Txt,Cns_MAX_BYTES_TEXT,60); // Insert links
HTM_Txt (Txt);
HTM_DIV_End ();
HTM_TD_End ();
2019-10-07 22:28:16 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2016-11-30 22:49:48 +01:00
2019-04-20 19:04:05 +02:00
/***** Free anchor string *****/
2019-04-20 21:11:44 +02:00
Frm_FreeAnchorStr (Anchor);
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/******************* Put a link (form) to edit one event *********************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2020-04-12 14:42:32 +02:00
static void Agd_PutFormsToRemEditOneEvent (struct Agd_Agenda *Agenda,
struct Agd_Event *AgdEvent,
2019-04-20 19:04:05 +02:00
const char *Anchor)
2016-11-30 22:49:48 +01:00
{
static Act_Action_t ActionHideUnhide[2] =
{
[false] = ActHidEvtMyAgd, // Visible ==> action to hide
[true ] = ActUnhEvtMyAgd, // Hidden ==> action to unhide
};
2020-04-12 14:42:32 +02:00
Agenda->AgdCodToEdit = AgdEvent->AgdCod; // Used as parameter in contextual links
2016-11-30 22:49:48 +01:00
/***** Icon to remove event *****/
2020-10-13 22:34:31 +02:00
Ico_PutContextualIconToRemove (ActReqRemEvtMyAgd,NULL,
Agd_PutCurrentParsMyAgenda,Agenda);
2016-11-30 22:49:48 +01:00
/***** Icon to hide/unhide event *****/
Ico_PutContextualIconToHideUnhide (ActionHideUnhide,Anchor,
Agd_PutCurrentParsMyAgenda,Agenda,
AgdEvent->Hidden);
2016-12-03 19:22:06 +01:00
/***** Icon to edit event *****/
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToEdit (ActEdiOneEvtMyAgd,NULL,
Agd_PutCurrentParsMyAgenda,Agenda);
2016-11-30 22:49:48 +01:00
/***** Icon to make event public/private *****/
2016-12-06 19:50:32 +01:00
if (AgdEvent->Public)
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (ActPrvEvtMyAgd,NULL,
Agd_PutCurrentParsMyAgenda,Agenda,
"unlock.svg",Ico_GREEN);
2016-12-06 19:50:32 +01:00
else
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (ActPubEvtMyAgd,NULL,
Agd_PutCurrentParsMyAgenda,Agenda,
"lock.svg",Ico_RED);
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2017-04-13 20:09:22 +02:00
/****************** Parameters passed in my agenda forms *********************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
static void Agd_PutCurrentParsMyAgenda (void *Agenda)
2016-11-30 22:49:48 +01:00
{
2020-03-26 02:54:30 +01:00
if (Agenda)
Agd_PutParsMyAgenda (((struct Agd_Agenda *) Agenda)->Past__FutureEvents,
((struct Agd_Agenda *) Agenda)->PrivatPublicEvents,
((struct Agd_Agenda *) Agenda)->HiddenVisiblEvents,
((struct Agd_Agenda *) Agenda)->SelectedOrder,
((struct Agd_Agenda *) Agenda)->CurrentPage,
((struct Agd_Agenda *) Agenda)->AgdCodToEdit);
2017-03-21 14:36:22 +01:00
}
/* The following function is called
when one or more parameters must be passed explicitely.
Each parameter is passed only if its value is distinct to default. */
void Agd_PutParsMyAgenda (unsigned Past__FutureEvents,
2017-04-13 20:09:22 +02:00
unsigned PrivatPublicEvents,
unsigned HiddenVisiblEvents,
2020-04-05 22:53:58 +02:00
Dat_StartEndTime_t Order,
2017-04-13 20:09:22 +02:00
unsigned NumPage,
long AgdCodToEdit)
2017-03-21 14:36:22 +01:00
{
if (Past__FutureEvents != (Agd_DEFAULT_PAST___EVENTS |
Agd_DEFAULT_FUTURE_EVENTS))
Agd_PutParPast__FutureEvents (Past__FutureEvents);
2017-03-21 14:36:22 +01:00
if (PrivatPublicEvents != (Agd_DEFAULT_PRIVAT_EVENTS |
Agd_DEFAULT_PUBLIC_EVENTS))
Agd_PutParPrivatPublicEvents (PrivatPublicEvents);
2017-03-21 14:36:22 +01:00
if (HiddenVisiblEvents != (Agd_DEFAULT_HIDDEN_EVENTS |
Agd_DEFAULT_VISIBL_EVENTS))
Agd_PutParHiddenVisiblEvents (HiddenVisiblEvents);
2017-03-21 14:36:22 +01:00
2019-11-18 09:20:44 +01:00
if (Order != Agd_ORDER_DEFAULT)
Par_PutParOrder ((unsigned) Order);
2017-04-13 20:09:22 +02:00
if (NumPage > 1)
Pag_PutParPagNum (Pag_MY_AGENDA,NumPage);
2017-03-21 14:36:22 +01:00
ParCod_PutPar (ParCod_Agd,AgdCodToEdit);
2017-03-21 14:36:22 +01:00
}
/*****************************************************************************/
/********** Get parameter with the type or order in list of events ***********/
/*****************************************************************************/
static void Agd_GetPars (struct Agd_Agenda *Agenda,
2020-04-12 14:42:32 +02:00
Agd_AgendaType_t AgendaType)
2017-03-21 14:36:22 +01:00
{
2019-11-21 11:39:30 +01:00
static const Pag_WhatPaginate_t WhatPaginate[Agd_NUM_AGENDA_TYPES] =
2017-03-21 14:36:22 +01:00
{
2019-11-20 17:53:51 +01:00
[Agd_MY_AGENDA_TODAY ] = Pag_MY_AGENDA, // not used
[Agd_MY_AGENDA ] = Pag_MY_AGENDA,
[Agd_ANOTHER_AGENDA_TODAY] = Pag_ANOTHER_AGENDA, // not used
[Agd_ANOTHER_AGENDA ] = Pag_ANOTHER_AGENDA,
2017-03-21 14:36:22 +01:00
};
2017-03-21 14:52:07 +01:00
if (AgendaType == Agd_MY_AGENDA)
2017-03-21 14:36:22 +01:00
{
Agenda->Past__FutureEvents = Agd_GetParsPast__FutureEvents ();
Agenda->PrivatPublicEvents = Agd_GetParsPrivatPublicEvents ();
Agenda->HiddenVisiblEvents = Agd_GetParsHiddenVisiblEvents ();
2017-03-21 14:36:22 +01:00
}
Agd_GetParEventOrder (Agenda);
Agenda->CurrentPage = Pag_GetParPagNum (WhatPaginate[AgendaType]);
2017-03-21 14:36:22 +01:00
}
/*****************************************************************************/
/****** Put a hidden parameter with the type of order in list of events ******/
/*****************************************************************************/
void Agd_PutParEventsOrder (Dat_StartEndTime_t SelectedOrder)
2017-03-21 14:36:22 +01:00
{
2020-04-12 14:42:32 +02:00
if (SelectedOrder != Agd_ORDER_DEFAULT)
Par_PutParOrder ((unsigned) SelectedOrder);
2017-03-21 14:36:22 +01:00
}
/*****************************************************************************/
/********** Get parameter with the type or order in list of events ***********/
/*****************************************************************************/
static void Agd_GetParEventOrder (struct Agd_Agenda *Agenda)
2017-03-21 14:36:22 +01:00
{
static bool AlreadyGot = false;
if (!AlreadyGot)
{
2020-04-12 14:42:32 +02:00
Agenda->SelectedOrder = (Dat_StartEndTime_t)
Par_GetParUnsignedLong ("Order",
0,
Dat_NUM_START_END_TIME - 1,
(unsigned long) Agd_ORDER_DEFAULT);
2017-03-21 14:36:22 +01:00
AlreadyGot = true;
}
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2016-12-02 00:24:16 +01:00
/************************* Get list of agenda events *************************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2017-03-22 01:14:48 +01:00
#define Agd_MAX_BYTES_SUBQUERY 128
2020-04-12 14:42:32 +02:00
static void Agd_GetListEvents (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType)
2016-11-30 22:49:48 +01:00
{
MYSQL_RES *mysql_res;
2016-12-02 00:24:16 +01:00
unsigned NumEvent;
2016-11-30 22:49:48 +01:00
2017-03-22 01:14:48 +01:00
/***** Initialize list of events *****/
2020-04-12 14:42:32 +02:00
Agd_FreeListEvents (Agenda);
2016-11-30 22:49:48 +01:00
/***** Trivial check: anything to get from database? *****/
2016-12-02 00:24:16 +01:00
switch (AgendaType)
{
2017-03-21 14:52:07 +01:00
case Agd_MY_AGENDA_TODAY:
case Agd_MY_AGENDA:
2020-04-12 14:42:32 +02:00
if (Agenda->Past__FutureEvents == 0 ||
Agenda->PrivatPublicEvents == 0 ||
Agenda->HiddenVisiblEvents == 0) // All selectors are off
2017-03-21 16:45:26 +01:00
{
// Nothing to get from database
Agenda->LstIsRead = true;
return;
2017-03-21 16:45:26 +01:00
}
2016-12-06 21:26:02 +01:00
break;
default:
break;
2016-12-02 00:24:16 +01:00
}
2016-11-30 22:49:48 +01:00
/***** Get list of events from database *****/
if ((Agenda->Num = Agd_DB_GetListEvents (&mysql_res,Agenda,AgendaType))) // Events found...
2016-11-30 22:49:48 +01:00
{
/***** Create list of events *****/
if ((Agenda->LstAgdCods = calloc ((size_t) Agenda->Num,
sizeof (*Agenda->LstAgdCods))) == NULL)
Err_NotEnoughMemoryExit ();
2017-03-22 01:14:48 +01:00
/***** 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 ();
2016-11-30 22:49:48 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2020-04-12 14:42:32 +02:00
Agenda->LstIsRead = true;
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/*********************** Get event data using its code ***********************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2020-04-08 03:06:45 +02:00
static void Agd_GetDataOfEventByCod (struct Agd_Event *AgdEvent)
2016-11-30 22:49:48 +01:00
{
2016-12-09 00:44:15 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get data of event from database *****/
if (Agd_DB_GetDataOfEventByCod (&mysql_res,AgdEvent)) // Event found...
2016-11-30 22:49:48 +01:00
{
2016-12-02 10:45:53 +01:00
/* Get row:
row[0] AgdCod
2016-12-09 00:44:15 +01:00
row[1] Public
row[2] Hidden
row[3] UNIX_TIMESTAMP(StartTime)
row[4] UNIX_TIMESTAMP(EndTime)
row[5] NOW()>EndTime // Past event?
row[6] NOW()<StartTime // Future event?
row[7] Event
row[8] Location
2016-12-02 10:45:53 +01:00
*/
2016-11-30 22:49:48 +01:00
row = mysql_fetch_row (mysql_res);
2016-12-01 00:53:50 +01:00
/* Get code of the event (row[0]) */
AgdEvent->AgdCod = Str_ConvertStrCodToLongCod (row[0]);
2016-11-30 22:49:48 +01:00
/* Get whether the event is public or not (row[1])
and whether it is hidden or not (row[2]) */
2016-12-09 00:44:15 +01:00
AgdEvent->Public = (row[1][0] == 'Y');
AgdEvent->Hidden = (row[2][0] == 'Y');
2016-11-30 22:49:48 +01:00
/* Get start date (row[3]) and end date (row[4]) in UTC time */
AgdEvent->TimeUTC[Dat_STR_TIME] = Dat_GetUNIXTimeFromStr (row[3]);
AgdEvent->TimeUTC[Dat_END_TIME] = Dat_GetUNIXTimeFromStr (row[4]);
2016-11-30 22:49:48 +01:00
2016-12-09 00:44:15 +01:00
/* Get whether the event is past, present or future (row(5), row[6]) */
AgdEvent->TimeStatus = ((row[5][0] == '1') ? Dat_PAST :
((row[6][0] == '1') ? Dat_FUTURE :
2016-12-03 19:22:06 +01:00
Dat_PRESENT));
2016-12-02 10:45:53 +01:00
/* Get the event (row[7]) and its location (row[8]) */
Str_Copy (AgdEvent->Event ,row[7],sizeof (AgdEvent->Event ) - 1);
Str_Copy (AgdEvent->Location,row[8],sizeof (AgdEvent->Location) - 1);
2016-12-09 00:44:15 +01:00
}
else
{
/***** Clear all event data *****/
AgdEvent->AgdCod = -1L;
AgdEvent->Public = false;
AgdEvent->Hidden = false;
AgdEvent->TimeUTC[Dat_STR_TIME] =
AgdEvent->TimeUTC[Dat_END_TIME] = (time_t) 0;
AgdEvent->TimeStatus = Dat_FUTURE;
AgdEvent->Event[0] = '\0';
AgdEvent->Location[0] = '\0';
2016-11-30 22:49:48 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/*************************** Free list of events *****************************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2020-04-12 14:42:32 +02:00
static void Agd_FreeListEvents (struct Agd_Agenda *Agenda)
2016-11-30 22:49:48 +01:00
{
2020-04-12 14:42:32 +02:00
if (Agenda->LstIsRead && Agenda->LstAgdCods)
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
/***** Free memory used by the list of events *****/
2020-04-12 14:42:32 +02:00
free (Agenda->LstAgdCods);
Agenda->LstAgdCods = NULL;
Agenda->Num = 0;
Agenda->LstIsRead = false;
2016-11-30 22:49:48 +01:00
}
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/************** Ask for confirmation of removing of an event *****************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
void Agd_AskRemEvent (void)
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
extern const char *Txt_Do_you_really_want_to_remove_the_event_X;
extern const char *Txt_Remove_event;
2020-04-12 14:42:32 +02:00
struct Agd_Agenda Agenda;
2020-04-08 03:06:45 +02:00
struct Agd_Event AgdEvent;
2016-11-30 22:49:48 +01:00
2020-04-12 14:42:32 +02:00
/***** Reset agenda context *****/
Agd_ResetAgenda (&Agenda);
2016-11-30 22:49:48 +01:00
/***** Get parameters *****/
Agd_GetPars (&Agenda,Agd_MY_AGENDA);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get event code *****/
AgdEvent.AgdCod = ParCod_GetAndCheckPar (ParCod_Agd);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get data of the event from database *****/
2016-12-02 00:24:16 +01:00
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
2016-12-01 00:53:50 +01:00
Agd_GetDataOfEventByCod (&AgdEvent);
2016-11-30 22:49:48 +01:00
2017-04-28 10:44:28 +02:00
/***** Show question and button to remove event *****/
2020-04-12 14:42:32 +02:00
Agenda.AgdCodToEdit = AgdEvent.AgdCod;
2019-02-17 01:14:55 +01:00
Ale_ShowAlertAndButton (ActRemEvtMyAgd,NULL,NULL,
Agd_PutCurrentParsMyAgenda,&Agenda,
2019-02-17 01:14:55 +01:00
Btn_REMOVE_BUTTON,Txt_Remove_event,
Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_event_X,
AgdEvent.Event);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Show events again *****/
2020-04-12 14:42:32 +02:00
Agd_ShowMyAgenda (&Agenda);
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/****************************** Remove an event ******************************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
void Agd_RemoveEvent (void)
2016-11-30 22:49:48 +01:00
{
2016-12-01 01:39:06 +01:00
extern const char *Txt_Event_X_removed;
2020-04-12 14:42:32 +02:00
struct Agd_Agenda Agenda;
2020-04-08 03:06:45 +02:00
struct Agd_Event AgdEvent;
2016-11-30 22:49:48 +01:00
2020-04-12 14:42:32 +02:00
/***** Reset agenda context *****/
Agd_ResetAgenda (&Agenda);
/***** Get parameters *****/
Agd_GetPars (&Agenda,Agd_MY_AGENDA);
2020-04-12 14:42:32 +02:00
2016-12-01 00:53:50 +01:00
/***** Get event code *****/
AgdEvent.AgdCod = ParCod_GetAndCheckPar (ParCod_Agd);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get data of the event from database *****/
2016-12-02 00:24:16 +01:00
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
2016-12-09 00:44:15 +01:00
Agd_GetDataOfEventByCod (&AgdEvent);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Remove event *****/
Agd_DB_RemoveEvent (&AgdEvent);
2016-11-30 22:49:48 +01:00
/***** Write message to show the change made *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Event_X_removed,
2019-02-15 23:38:44 +01:00
AgdEvent.Event);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Show events again *****/
2020-04-12 14:42:32 +02:00
Agd_ShowMyAgenda (&Agenda);
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2016-12-03 19:22:06 +01:00
/********************************* Hide event ********************************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-03 19:22:06 +01:00
void Agd_HideEvent (void)
2016-11-30 22:49:48 +01:00
{
2020-04-12 14:42:32 +02:00
struct Agd_Agenda Agenda;
2020-04-08 03:06:45 +02:00
struct Agd_Event AgdEvent;
2016-11-30 22:49:48 +01:00
2020-04-12 14:42:32 +02:00
/***** Reset agenda context *****/
Agd_ResetAgenda (&Agenda);
/***** Get parameters *****/
Agd_GetPars (&Agenda,Agd_MY_AGENDA);
2020-04-12 14:42:32 +02:00
2016-12-01 00:53:50 +01:00
/***** Get event code *****/
AgdEvent.AgdCod = ParCod_GetAndCheckPar (ParCod_Agd);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get data of the event from database *****/
2016-12-02 00:24:16 +01:00
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
2016-12-01 00:53:50 +01:00
Agd_GetDataOfEventByCod (&AgdEvent);
2016-11-30 22:49:48 +01:00
/***** Hide event *****/
Agd_DB_HideOrUnhideEvent (AgdEvent.AgdCod,AgdEvent.UsrCod,true);
2016-12-03 19:22:06 +01:00
/***** Show events again *****/
2020-04-12 14:42:32 +02:00
Agd_ShowMyAgenda (&Agenda);
2016-12-03 19:22:06 +01:00
}
/*****************************************************************************/
2016-12-06 19:14:58 +01:00
/****************************** Unhide event *********************************/
2016-12-03 19:22:06 +01:00
/*****************************************************************************/
2016-12-06 19:14:58 +01:00
void Agd_UnhideEvent (void)
2016-12-03 19:22:06 +01:00
{
2020-04-12 14:42:32 +02:00
struct Agd_Agenda Agenda;
2020-04-08 03:06:45 +02:00
struct Agd_Event AgdEvent;
2016-12-03 19:22:06 +01:00
2020-04-12 14:42:32 +02:00
/***** Reset agenda context *****/
Agd_ResetAgenda (&Agenda);
/***** Get parameters *****/
Agd_GetPars (&Agenda,Agd_MY_AGENDA);
2020-04-12 14:42:32 +02:00
2016-12-03 19:22:06 +01:00
/***** Get event code *****/
AgdEvent.AgdCod = ParCod_GetAndCheckPar (ParCod_Agd);
2016-12-03 19:22:06 +01:00
/***** Get data of the event from database *****/
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
Agd_GetDataOfEventByCod (&AgdEvent);
/***** Unhide event *****/
Agd_DB_HideOrUnhideEvent (AgdEvent.AgdCod,AgdEvent.UsrCod,false);
2016-12-03 19:22:06 +01:00
/***** Show events again *****/
2020-04-12 14:42:32 +02:00
Agd_ShowMyAgenda (&Agenda);
2016-12-03 19:22:06 +01:00
}
/*****************************************************************************/
/****************************** Make event private ***************************/
/*****************************************************************************/
void Agd_MakeEventPrivate (void)
{
extern const char *Txt_Event_X_is_now_private;
2020-04-12 14:42:32 +02:00
struct Agd_Agenda Agenda;
2020-04-08 03:06:45 +02:00
struct Agd_Event AgdEvent;
2016-12-03 19:22:06 +01:00
2020-04-12 14:42:32 +02:00
/***** Reset agenda context *****/
Agd_ResetAgenda (&Agenda);
/***** Get parameters *****/
Agd_GetPars (&Agenda,Agd_MY_AGENDA);
2020-04-12 14:42:32 +02:00
2016-12-03 19:22:06 +01:00
/***** Get event code *****/
AgdEvent.AgdCod = ParCod_GetAndCheckPar (ParCod_Agd);
2016-12-03 19:22:06 +01:00
/***** Get data of the event from database *****/
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
Agd_GetDataOfEventByCod (&AgdEvent);
/***** Make event private *****/
Agd_DB_MakeEventPrivate (&AgdEvent);
2016-11-30 22:49:48 +01:00
/***** Write message to show the change made *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Event_X_is_now_private,
2019-02-15 23:38:44 +01:00
AgdEvent.Event);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Show events again *****/
2020-04-12 14:42:32 +02:00
Agd_ShowMyAgenda (&Agenda);
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2016-12-03 19:22:06 +01:00
/******** Make event public (make it visible to users of my courses) *********/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-03 19:22:06 +01:00
void Agd_MakeEventPublic (void)
2016-11-30 22:49:48 +01:00
{
2016-12-01 19:28:52 +01:00
extern const char *Txt_Event_X_is_now_visible_to_users_of_your_courses;
2020-04-12 14:42:32 +02:00
struct Agd_Agenda Agenda;
2020-04-08 03:06:45 +02:00
struct Agd_Event AgdEvent;
2016-11-30 22:49:48 +01:00
2020-04-12 14:42:32 +02:00
/***** Reset agenda context *****/
Agd_ResetAgenda (&Agenda);
/***** Get parameters *****/
Agd_GetPars (&Agenda,Agd_MY_AGENDA);
2020-04-12 14:42:32 +02:00
2016-12-01 00:53:50 +01:00
/***** Get event code *****/
AgdEvent.AgdCod = ParCod_GetAndCheckPar (ParCod_Agd);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get data of the event from database *****/
2016-12-02 00:24:16 +01:00
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
2016-12-01 00:53:50 +01:00
Agd_GetDataOfEventByCod (&AgdEvent);
2016-11-30 22:49:48 +01:00
2016-12-03 19:22:06 +01:00
/***** Make event public *****/
Agd_DB_MakeEventPublic (&AgdEvent);
2016-11-30 22:49:48 +01:00
/***** Write message to show the change made *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Event_X_is_now_visible_to_users_of_your_courses,
2019-02-15 23:38:44 +01:00
AgdEvent.Event);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Show events again *****/
2020-04-12 14:42:32 +02:00
Agd_ShowMyAgenda (&Agenda);
2016-11-30 22:49:48 +01:00
}
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/******************** Put a form to create a new event ***********************/
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
void Agd_RequestCreatOrEditEvent (void)
2016-07-07 00:21:10 +02:00
{
2016-12-01 00:53:50 +01:00
extern const char *Hlp_PROFILE_Agenda_new_event;
extern const char *Hlp_PROFILE_Agenda_edit_event;
2016-11-30 22:49:48 +01:00
extern const char *Txt_New_event;
2016-12-01 00:53:50 +01:00
extern const char *Txt_Edit_event;
2016-11-30 22:49:48 +01:00
extern const char *Txt_Location;
extern const char *Txt_Event;
extern const char *Txt_Description;
extern const char *Txt_Create_event;
2019-02-18 18:27:45 +01:00
extern const char *Txt_Save_changes;
2020-04-12 14:42:32 +02:00
struct Agd_Agenda Agenda;
2020-04-08 03:06:45 +02:00
struct Agd_Event AgdEvent;
2016-12-01 00:53:50 +01:00
bool ItsANewEvent;
2017-01-17 03:10:43 +01:00
char Txt[Cns_MAX_BYTES_TEXT + 1];
2020-02-26 19:35:33 +01:00
static const Dat_SetHMS SetHMS[Dat_NUM_START_END_TIME] =
{
[Dat_STR_TIME] = Dat_HMS_DO_NOT_SET,
[Dat_END_TIME] = Dat_HMS_DO_NOT_SET
2020-02-26 19:35:33 +01:00
};
2016-11-30 22:49:48 +01:00
2020-04-12 14:42:32 +02:00
/***** Reset agenda context *****/
Agd_ResetAgenda (&Agenda);
2016-11-30 22:49:48 +01:00
/***** Get parameters *****/
Agd_GetPars (&Agenda,Agd_MY_AGENDA);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get the code of the event *****/
ItsANewEvent = ((AgdEvent.AgdCod = ParCod_GetPar (ParCod_Agd)) <= 0);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get from the database the data of the event *****/
2016-12-09 00:44:15 +01:00
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
2016-12-01 00:53:50 +01:00
if (ItsANewEvent)
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
/* Initialize to empty event */
AgdEvent.AgdCod = -1L;
AgdEvent.TimeUTC[Dat_STR_TIME] = Dat_GetStartExecutionTimeUTC ();
AgdEvent.TimeUTC[Dat_END_TIME] = AgdEvent.TimeUTC[Dat_STR_TIME] + (2 * 60 * 60); // +2 hours
2016-12-02 10:45:53 +01:00
AgdEvent.TimeStatus = Dat_FUTURE;
2016-12-01 00:53:50 +01:00
AgdEvent.Event[0] = '\0';
AgdEvent.Location[0] = '\0';
2016-11-30 22:49:48 +01:00
}
else
{
2016-12-01 00:53:50 +01:00
/* Get data of the event from database */
Agd_GetDataOfEventByCod (&AgdEvent);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/* Get text of the event from database */
Agd_DB_GetEventTxt (&AgdEvent,Txt);
2016-11-30 22:49:48 +01:00
}
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2016-12-01 00:53:50 +01:00
if (ItsANewEvent)
2017-03-21 14:36:22 +01:00
{
Frm_BeginForm (ActNewEvtMyAgd);
2020-04-12 14:42:32 +02:00
Agenda.AgdCodToEdit = -1L;
2017-03-21 14:36:22 +01:00
}
2016-11-30 22:49:48 +01:00
else
{
Frm_BeginForm (ActChgEvtMyAgd);
2020-04-12 14:42:32 +02:00
Agenda.AgdCodToEdit = AgdEvent.AgdCod;
2016-11-30 22:49:48 +01:00
}
Agd_PutCurrentParsMyAgenda (&Agenda);
2016-11-30 22:49:48 +01:00
/***** 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 *****/
/* Begin table row */
HTM_TR_Begin (NULL);
/* 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\" class=\"TITLE_DESCRIPTION_WIDTH INPUT_%s\""
" required=\"required\"",
The_GetSuffix ());
HTM_TD_End ();
/* End table row */
HTM_TR_End ();
/***** Location *****/
/* Begin table row */
HTM_TR_Begin (NULL);
/* 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\" class=\"TITLE_DESCRIPTION_WIDTH INPUT_%s\""
" required=\"required\"",
The_GetSuffix ());
HTM_TD_End ();
/* End table row */
HTM_TR_End ();
/***** Start and end dates *****/
Dat_PutFormStartEndClientLocalDateTimes (AgdEvent.TimeUTC,
Dat_FORM_SECONDS_OFF,
SetHMS);
/***** Text *****/
/* Begin table row */
HTM_TR_Begin (NULL);
/* 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 INPUT_%s\"",
The_GetSuffix ());
if (!ItsANewEvent)
HTM_Txt (Txt);
HTM_TEXTAREA_End ();
HTM_TD_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);
2017-06-12 14:16:33 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Show current events, if any *****/
2020-04-12 14:42:32 +02:00
Agd_ShowMyAgenda (&Agenda);
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/********************* Receive form to create a new event ********************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2020-05-05 21:49:00 +02:00
void Agd_ReceiveFormEvent (void)
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
extern const char *Txt_Created_new_event_X;
2016-11-30 22:49:48 +01:00
extern const char *Txt_The_event_has_been_modified;
2020-04-12 14:42:32 +02:00
struct Agd_Agenda Agenda;
2020-04-08 03:06:45 +02:00
struct Agd_Event AgdEvent;
2016-12-01 00:53:50 +01:00
bool ItsANewEvent;
bool NewEventIsCorrect = true;
2019-02-15 21:09:18 +01:00
char EventTxt[Cns_MAX_BYTES_TEXT + 1];
2016-11-30 22:49:48 +01:00
2020-04-12 14:42:32 +02:00
/***** Reset agenda context *****/
Agd_ResetAgenda (&Agenda);
/***** Get parameters *****/
Agd_GetPars (&Agenda,Agd_MY_AGENDA);
2020-04-12 14:42:32 +02:00
2016-12-09 18:22:25 +01:00
/***** Set author of the event *****/
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
2016-12-01 00:53:50 +01:00
/***** Get the code of the event *****/
ItsANewEvent = ((AgdEvent.AgdCod = ParCod_GetPar (ParCod_Agd)) <= 0);
2016-11-30 22:49:48 +01:00
/***** Get start/end date-times *****/
AgdEvent.TimeUTC[Dat_STR_TIME] = Dat_GetTimeUTCFromForm (Dat_STR_TIME);
AgdEvent.TimeUTC[Dat_END_TIME] = Dat_GetTimeUTCFromForm (Dat_END_TIME);
2016-11-30 22:49:48 +01:00
2020-04-28 13:12:18 +02:00
/***** Get event location *****/
Par_GetParText ("Location",AgdEvent.Location,Agd_MAX_BYTES_LOCATION);
2016-11-30 22:49:48 +01:00
2020-04-28 13:12:18 +02:00
/***** Get event title *****/
Par_GetParText ("Event",AgdEvent.Event,Agd_MAX_BYTES_EVENT);
2016-11-30 22:49:48 +01:00
2020-04-28 13:12:18 +02:00
/***** Get event description *****/
Par_GetParHTML ("Txt",EventTxt,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous)
2016-11-30 22:49:48 +01:00
/***** Adjust dates *****/
if (AgdEvent.TimeUTC[Dat_STR_TIME] == 0)
AgdEvent.TimeUTC[Dat_STR_TIME] = Dat_GetStartExecutionTimeUTC ();
2020-04-28 13:12:18 +02:00
if (AgdEvent.TimeUTC[Dat_END_TIME] == 0)
AgdEvent.TimeUTC[Dat_END_TIME] = AgdEvent.TimeUTC[Dat_STR_TIME] + 2 * 60 * 60; // +2 hours
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Check if event is correct *****/
2016-12-09 00:44:15 +01:00
if (!AgdEvent.Location[0]) // If there is no event
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
NewEventIsCorrect = false;
Ale_ShowAlertYouMustSpecifyTheTitle ();
2016-11-30 22:49:48 +01:00
}
/***** Check if event is correct *****/
2017-03-22 01:39:43 +01:00
if (!AgdEvent.Event[0]) // If there is no event
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
NewEventIsCorrect = false;
Ale_ShowAlertYouMustSpecifyTheTitle ();
2016-11-30 22:49:48 +01:00
}
2016-12-01 00:53:50 +01:00
/***** Create a new event or update an existing one *****/
if (NewEventIsCorrect)
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
if (ItsANewEvent)
2016-11-30 22:49:48 +01:00
{
AgdEvent.AgdCod = Agd_DB_CreateEvent (&AgdEvent,EventTxt); // Add new event to database
2016-11-30 22:49:48 +01:00
/***** Write success message *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Created_new_event_X,
2019-02-15 23:38:44 +01:00
AgdEvent.Event);
2016-11-30 22:49:48 +01:00
}
else
{
Agd_DB_UpdateEvent (&AgdEvent,EventTxt);
2016-11-30 22:49:48 +01:00
/***** Write success message *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_The_event_has_been_modified);
2016-11-30 22:49:48 +01:00
}
/* Free memory for list of selected groups */
Grp_FreeListCodSelectedGrps ();
2016-12-01 00:53:50 +01:00
/***** Show events again *****/
2020-04-12 14:42:32 +02:00
Agd_ShowMyAgenda (&Agenda);
2016-11-30 22:49:48 +01:00
}
else
// TODO: The form should be filled with partial data, now is always empty
2016-12-01 00:53:50 +01:00
Agd_RequestCreatOrEditEvent ();
2016-11-30 22:49:48 +01:00
}
2016-12-07 00:41:36 +01:00
/*****************************************************************************/
/************************** Show an agenda QR code ***************************/
/*****************************************************************************/
void Agd_PrintAgdQRCode (void)
{
extern const char *Txt_Where_s_USER;
char *Title;
2016-12-07 00:41:36 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
if (asprintf (&Title,Txt_Where_s_USER,Gbl.Usrs.Me.UsrDat.FullName) < 0)
Err_NotEnoughMemoryExit ();
Box_BoxBegin (NULL,Title,NULL,NULL,NULL,Box_NOT_CLOSABLE);
free (Title);
2016-12-07 00:41:36 +01:00
/***** Print QR code ****/
QR_PrintQRCode ();
2016-12-07 00:41:36 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-12-07 00:41:36 +01:00
}
/*****************************************************************************/
/********* Get and show number of users who have chosen a language ***********/
/*****************************************************************************/
void Agd_GetAndShowAgendasStats (void)
{
extern const char *Hlp_ANALYTICS_Figures_agendas;
extern const char *Txt_FIGURE_TYPES[Fig_NUM_FIGURES];
extern const char *Txt_Number_of_events;
extern const char *Txt_Number_of_users;
extern const char *Txt_PERCENT_of_users;
extern const char *Txt_Number_of_events_per_user;
unsigned NumEvents;
unsigned NumUsrs;
unsigned NumUsrsTotal;
/***** Begin box and table *****/
Box_BoxTableBegin (NULL,Txt_FIGURE_TYPES[Fig_AGENDAS],
NULL,NULL,
Hlp_ANALYTICS_Figures_agendas,Box_NOT_CLOSABLE,2);
/***** Heading row *****/
HTM_TR_Begin (NULL);
HTM_TH (Txt_Number_of_events ,HTM_HEAD_RIGHT);
HTM_TH (Txt_Number_of_users ,HTM_HEAD_RIGHT);
HTM_TH (Txt_PERCENT_of_users ,HTM_HEAD_RIGHT);
HTM_TH (Txt_Number_of_events_per_user,HTM_HEAD_RIGHT);
HTM_TR_End ();
/***** Number of agenda events *****/
NumEvents = Agd_DB_GetNumEvents (Gbl.Scope.Current);
/***** Number of users with agenda events *****/
NumUsrs = Agd_DB_GetNumUsrsWithEvents (Gbl.Scope.Current);
/***** Get total number of users in current scope *****/
NumUsrsTotal = Usr_GetTotalNumberOfUsers ();
/***** Write number of users who have chosen each language *****/
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ());
HTM_Unsigned (NumEvents);
HTM_TD_End ();
HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ());
HTM_Unsigned (NumUsrs);
HTM_TD_End ();
HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ());
HTM_Percentage (NumUsrsTotal ? (double) NumUsrs * 100.0 /
(double) NumUsrsTotal :
0);
HTM_TD_End ();
HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ());
HTM_Double2Decimals (NumUsrs ? (double) NumEvents /
(double) NumUsrs :
0);
HTM_TD_End ();
HTM_TR_End ();
/***** End table and box *****/
Box_BoxTableEnd ();
}