swad-core/swad_agenda.c

1919 lines
67 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.
2019-01-07 21:52:19 +01:00
Copyright (C) 1999-2019 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
#include <linux/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
2016-11-30 22:49:48 +01:00
#include "swad_agenda.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"
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"
#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"
2017-06-11 20:09:59 +02:00
#include "swad_table.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 *****************************/
/*****************************************************************************/
2017-03-21 14:36:22 +01:00
static const char *ParamPast__FutureName = "Past__Future";
static const char *ParamPrivatPublicName = "PrivatPublic";
static const char *ParamHiddenVisiblName = "HiddenVisibl";
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
2016-11-30 22:49:48 +01:00
/******************************* Private types *******************************/
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
2017-03-21 14:52:07 +01:00
#define Agd_NUM_AGENDA_TYPES 4
2016-12-02 00:24:16 +01:00
typedef enum
{
2017-03-21 14:52:07 +01:00
Agd_MY_AGENDA_TODAY,
Agd_MY_AGENDA,
Agd_ANOTHER_AGENDA_TODAY,
Agd_ANOTHER_AGENDA,
2016-12-02 00:24:16 +01:00
} Agd_AgendaType_t;
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
2016-11-30 22:49:48 +01:00
/***************************** Private variables *****************************/
/*****************************************************************************/
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
2016-11-30 22:49:48 +01:00
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2017-03-21 14:36:22 +01:00
static void Agd_ShowFormToSelPast__FutureEvents (void);
static void Agd_ShowFormToSelPrivatPublicEvents (void);
static void Agd_ShowFormToSelHiddenVisiblEvents (void);
static void Agd_PutHiddenParamPast__FutureEvents (unsigned Past__FutureEvents);
static void Agd_PutHiddenParamPrivatPublicEvents (unsigned PrivatPublicEvents);
static void Agd_PutHiddenParamHiddenVisiblEvents (unsigned HiddenVisiblEvents);
static void Agd_GetParamsPast__FutureEvents (void);
static void Agd_GetParamsPrivatPublicEvents (void);
static void Agd_GetParamsHiddenVisiblEvents (void);
2017-03-21 00:57:11 +01:00
2016-12-02 00:24:16 +01:00
static void Agd_ShowEvents (Agd_AgendaType_t AgendaType);
2016-12-06 21:08:28 +01:00
static void Agd_ShowEventsToday (Agd_AgendaType_t AgendaType);
2016-12-06 03:10:06 +01:00
static void Agd_WriteHeaderListEvents (Agd_AgendaType_t AgendaType);
2016-12-02 00:24:16 +01:00
2016-12-06 21:08:28 +01:00
static void Agd_PutIconsMyFullAgenda (void);
static void Agd_PutIconsMyPublicAgenda (void);
2016-12-01 00:53:50 +01:00
static void Agd_PutIconToCreateNewEvent (void);
2016-12-06 21:08:28 +01:00
static void Agd_PutIconToViewEditMyFullAgenda (void);
2016-12-05 03:16:25 +01:00
static void Agd_PutIconToShowQR (void);
2016-12-09 14:50:21 +01:00
static void Agd_PutIconsOtherPublicAgenda (void);
2016-12-06 21:08:28 +01:00
2016-12-01 00:53:50 +01:00
static void Agd_PutButtonToCreateNewEvent (void);
2016-12-02 00:24:16 +01:00
static void Agd_ShowOneEvent (Agd_AgendaType_t AgendaType,long AgdCod);
2017-01-29 12:42:19 +01:00
static void Agd_GetParamEventOrder (void);
2016-12-01 00:53:50 +01:00
2016-12-03 19:22:06 +01:00
static void Agd_PutFormsToRemEditOneEvent (struct AgendaEvent *AgdEvent);
2017-03-21 14:36:22 +01:00
2017-04-13 20:09:22 +02:00
static void Agd_PutCurrentParamsMyAgenda (void);
2017-03-21 14:36:22 +01:00
static void Agd_GetParams (Agd_AgendaType_t AgendaType);
2016-12-02 00:24:16 +01:00
static void Agd_GetListEvents (Agd_AgendaType_t AgendaType);
static void Agd_GetDataOfEventByCod (struct AgendaEvent *AgdEvent);
2017-01-17 03:10:43 +01:00
static void Agd_GetEventTxtFromDB (struct AgendaEvent *AgdEvent,
char Txt[Cns_MAX_BYTES_TEXT + 1]);
2016-12-01 00:53:50 +01:00
static void Agd_CreateEvent (struct AgendaEvent *AgdEvent,const char *Txt);
static void Agd_UpdateEvent (struct AgendaEvent *AgdEvent,const char *Txt);
/*****************************************************************************/
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
{
/***** Form to log in *****/
2016-12-05 13:26:12 +01:00
Usr_WriteFormLogin (ActLogInUsrAgd,Agd_PutParamAgd);
}
void Agd_PutParamAgd (void)
{
2017-01-28 15:58:46 +01:00
char Nickname[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
2016-12-05 13:26:12 +01:00
2018-10-17 01:08:42 +02:00
snprintf (Nickname,sizeof (Nickname),
"@%s",
Gbl.Usrs.Other.UsrDat.Nickname);
2016-12-05 13:26:12 +01:00
Par_PutHiddenParamString ("agd",Nickname);
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
/*****************************************************************************/
2016-12-06 21:26:02 +01:00
void Agd_ShowMyAgenda (void)
2016-12-04 04:22:36 +01:00
{
2016-12-06 21:26:02 +01:00
extern const char *Hlp_PROFILE_Agenda;
extern const char *Txt_My_agenda;
2017-03-21 14:36:22 +01:00
/***** Get parameters *****/
2017-03-21 14:52:07 +01:00
Agd_GetParams (Agd_MY_AGENDA);
2017-03-21 14:36:22 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2017-06-11 22:26:40 +02:00
Box_StartBox ("100%",Txt_My_agenda,Agd_PutIconsMyFullAgenda,
2017-06-12 15:03:29 +02:00
Hlp_PROFILE_Agenda,Box_NOT_CLOSABLE);
2016-12-06 21:26:02 +01:00
2017-03-21 00:57:11 +01:00
/***** Put forms to choice which events to show *****/
2019-03-26 11:53:21 +01:00
Set_StartSettingsHead ();
2017-03-21 14:36:22 +01:00
Agd_ShowFormToSelPast__FutureEvents ();
Agd_ShowFormToSelPrivatPublicEvents ();
Agd_ShowFormToSelHiddenVisiblEvents ();
2019-03-26 11:53:21 +01:00
Set_EndSettingsHead ();
2017-03-21 00:57:11 +01:00
2016-12-06 21:26:02 +01:00
/***** Show the current events in the user's agenda *****/
2017-03-21 14:52:07 +01:00
Agd_ShowEventsToday (Agd_MY_AGENDA_TODAY);
2016-12-06 21:26:02 +01:00
/***** Show all my events *****/
2017-03-21 14:52:07 +01:00
Agd_ShowEvents (Agd_MY_AGENDA);
2016-12-06 21:26:02 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ();
2016-12-06 21:26:02 +01:00
}
2017-03-21 00:57:11 +01:00
/*****************************************************************************/
/*************** Show form to select past / future events ********************/
/*****************************************************************************/
2017-03-21 14:36:22 +01:00
static void Agd_ShowFormToSelPast__FutureEvents (void)
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-01-11 02:55:01 +01:00
"calendar-minus.svg", // Agd_PAST___EVENTS
"calendar-plus.svg", // Agd_FUTURE_EVENTS
2017-03-21 00:57:11 +01:00
};
2019-03-26 11:53:21 +01:00
Set_StartOneSettingSelector ();
2017-03-21 14:36:22 +01:00
for (PstFut = Agd_PAST___EVENTS;
2017-03-21 00:57:11 +01:00
PstFut <= Agd_FUTURE_EVENTS;
PstFut++)
{
fprintf (Gbl.F.Out,"<div class=\"%s\">",
2017-03-21 14:36:22 +01:00
(Gbl.Agenda.Past__FutureEvents & (1 << PstFut)) ? "PREF_ON" :
"PREF_OFF");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeMyAgd);
2017-04-13 20:09:22 +02:00
Agd_PutParamsMyAgenda (Gbl.Agenda.Past__FutureEvents ^ (1 << PstFut), // Toggle
Gbl.Agenda.PrivatPublicEvents,
Gbl.Agenda.HiddenVisiblEvents,
Gbl.Agenda.CurrentPage,
-1L);
2019-03-26 11:53:21 +01:00
Ico_PutSettingIconLink (Icon[PstFut],
2019-01-12 03:00:59 +01:00
Txt_AGENDA_PAST___FUTURE_EVENTS[PstFut]);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-03-21 00:57:11 +01:00
fprintf (Gbl.F.Out,"</div>");
}
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 ******************/
/*****************************************************************************/
2017-03-21 14:36:22 +01:00
static void Agd_ShowFormToSelPrivatPublicEvents (void)
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;
2019-02-21 21:12:04 +01:00
static const char *Icon[2] =
2017-03-21 00:57:11 +01:00
{
2019-01-11 02:55:01 +01:00
"lock.svg", // Agd_PRIVAT_EVENTS
2019-01-12 19:46:33 +01:00
"unlock.svg", // Agd_PUBLIC_EVENTS
2017-03-21 00:57:11 +01:00
};
2019-03-26 11:53:21 +01:00
Set_StartOneSettingSelector ();
2017-03-21 14:36:22 +01:00
for (PrvPub = Agd_PRIVAT_EVENTS;
PrvPub <= Agd_PUBLIC_EVENTS;
2017-03-21 00:57:11 +01:00
PrvPub++)
{
fprintf (Gbl.F.Out,"<div class=\"%s\">",
2017-03-21 14:36:22 +01:00
(Gbl.Agenda.PrivatPublicEvents & (1 << PrvPub)) ? "PREF_ON" :
"PREF_OFF");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeMyAgd);
2017-04-13 20:09:22 +02:00
Agd_PutParamsMyAgenda (Gbl.Agenda.Past__FutureEvents,
Gbl.Agenda.PrivatPublicEvents ^ (1 << PrvPub), // Toggle
Gbl.Agenda.HiddenVisiblEvents,
Gbl.Agenda.CurrentPage,
-1L);
2019-03-26 11:53:21 +01:00
Ico_PutSettingIconLink (Icon[PrvPub],
2019-01-12 03:00:59 +01:00
Txt_AGENDA_PRIVAT_PUBLIC_EVENTS[PrvPub]);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-03-21 00:57:11 +01:00
fprintf (Gbl.F.Out,"</div>");
}
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 *******************/
/*****************************************************************************/
2017-03-21 14:36:22 +01:00
static void Agd_ShowFormToSelHiddenVisiblEvents (void)
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;
2019-02-21 21:12:04 +01:00
static const char *Icon[2] =
2017-03-21 00:57:11 +01:00
{
2019-01-10 15:26:33 +01:00
"eye-slash.svg", // Agd_HIDDEN_EVENTS
"eye.svg", // Agd_VISIBL_EVENTS
2017-03-21 00:57:11 +01:00
};
2019-03-26 11:53:21 +01:00
Set_StartOneSettingSelector ();
2017-03-21 14:36:22 +01:00
for (HidVis = Agd_HIDDEN_EVENTS;
HidVis <= Agd_VISIBL_EVENTS;
2017-03-21 00:57:11 +01:00
HidVis++)
{
fprintf (Gbl.F.Out,"<div class=\"%s\">",
2017-03-21 14:36:22 +01:00
(Gbl.Agenda.HiddenVisiblEvents & (1 << HidVis)) ? "PREF_ON" :
"PREF_OFF");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeMyAgd);
2017-04-13 20:09:22 +02:00
Agd_PutParamsMyAgenda (Gbl.Agenda.Past__FutureEvents,
Gbl.Agenda.PrivatPublicEvents,
Gbl.Agenda.HiddenVisiblEvents ^ (1 << HidVis), // Toggle
Gbl.Agenda.CurrentPage,
-1L);
2019-03-26 11:53:21 +01:00
Ico_PutSettingIconLink (Icon[HidVis],
2019-01-12 03:00:59 +01:00
Txt_AGENDA_HIDDEN_VISIBL_EVENTS[HidVis]);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-03-21 00:57:11 +01:00
fprintf (Gbl.F.Out,"</div>");
}
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
/*****************************************************************************/
2017-03-21 14:36:22 +01:00
static void Agd_PutHiddenParamPast__FutureEvents (unsigned Past__FutureEvents)
2017-03-21 00:57:11 +01:00
{
2017-03-21 14:36:22 +01:00
Par_PutHiddenParamUnsigned (ParamPast__FutureName,Past__FutureEvents);
2017-03-21 00:57:11 +01:00
}
2017-03-21 14:36:22 +01:00
static void Agd_PutHiddenParamPrivatPublicEvents (unsigned PrivatPublicEvents)
2017-03-21 00:57:11 +01:00
{
2017-03-21 14:36:22 +01:00
Par_PutHiddenParamUnsigned (ParamPrivatPublicName,PrivatPublicEvents);
}
2017-03-21 00:57:11 +01:00
2017-03-21 14:36:22 +01:00
static void Agd_PutHiddenParamHiddenVisiblEvents (unsigned HiddenVisiblEvents)
{
Par_PutHiddenParamUnsigned (ParamHiddenVisiblName,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
/*****************************************************************************/
2017-03-21 14:36:22 +01:00
static void Agd_GetParamsPast__FutureEvents (void)
2017-03-21 00:57:11 +01:00
{
2017-03-21 14:36:22 +01:00
Gbl.Agenda.Past__FutureEvents = (unsigned) Par_GetParToUnsignedLong (ParamPast__FutureName,
0,
(1 << Agd_PAST___EVENTS) |
(1 << Agd_FUTURE_EVENTS),
Agd_DEFAULT_PAST___EVENTS |
Agd_DEFAULT_FUTURE_EVENTS);
}
2017-03-21 00:57:11 +01:00
2017-03-21 14:36:22 +01:00
static void Agd_GetParamsPrivatPublicEvents (void)
{
Gbl.Agenda.PrivatPublicEvents = (unsigned) Par_GetParToUnsignedLong (ParamPrivatPublicName,
0,
(1 << Agd_PRIVAT_EVENTS) |
(1 << Agd_PUBLIC_EVENTS),
Agd_DEFAULT_PRIVAT_EVENTS |
Agd_DEFAULT_PUBLIC_EVENTS);
}
static void Agd_GetParamsHiddenVisiblEvents (void)
{
Gbl.Agenda.HiddenVisiblEvents = (unsigned) Par_GetParToUnsignedLong (ParamHiddenVisiblName,
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;
bool ItsMe;
2016-12-09 13:59:33 +01:00
bool Error = true;
2016-11-30 22:49:48 +01:00
2016-12-02 00:24:16 +01:00
/***** Get user *****/
if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
2016-12-09 13:59:33 +01:00
if (Usr_CheckIfICanViewUsrAgenda (&Gbl.Usrs.Other.UsrDat))
{
Error = false;
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2018-10-17 01:08:42 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
Txt_Public_agenda_USER,
Gbl.Usrs.Other.UsrDat.FullName);
2018-10-10 23:56:42 +02:00
ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
2017-06-10 21:38:10 +02:00
Box_StartBox ("100%",Gbl.Title,
2017-06-11 22:26:40 +02:00
ItsMe ? Agd_PutIconsMyPublicAgenda :
Agd_PutIconsOtherPublicAgenda,
2017-06-12 15:03:29 +02:00
Hlp_PROFILE_Agenda_public_agenda,Box_NOT_CLOSABLE);
2016-12-09 13:59:33 +01:00
/***** Show the current events in the user's agenda *****/
2017-03-21 14:52:07 +01:00
Agd_ShowEventsToday (Agd_ANOTHER_AGENDA_TODAY);
2016-12-09 13:59:33 +01:00
/***** Show all the visible events in the user's agenda *****/
2017-03-21 14:52:07 +01:00
Agd_ShowEvents (Agd_ANOTHER_AGENDA);
2016-12-09 13:59:33 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ();
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];
2016-12-06 21:26:02 +01:00
bool ItsMe;
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 */
2019-03-19 13:22:14 +01:00
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS)) // Existing user
2016-12-06 21:26:02 +01:00
{
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2018-10-17 01:08:42 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
Txt_Public_agenda_USER,
Gbl.Usrs.Other.UsrDat.FullName);
2018-10-10 23:56:42 +02:00
ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
2017-06-10 21:38:10 +02:00
Box_StartBox ("100%",Gbl.Title,
2017-06-11 22:26:40 +02:00
ItsMe ? Agd_PutIconToViewEditMyFullAgenda :
Agd_PutIconsOtherPublicAgenda,
2017-06-12 15:03:29 +02:00
Hlp_PROFILE_Agenda_public_agenda,Box_NOT_CLOSABLE);
2016-12-06 03:10:06 +01:00
2016-12-06 21:26:02 +01:00
/***** Show the current events in the user's agenda *****/
2017-03-21 14:52:07 +01:00
Agd_ShowEventsToday (Agd_ANOTHER_AGENDA_TODAY);
2016-12-06 03:10:06 +01:00
2016-12-06 21:26:02 +01:00
/***** Show all the visible events in the user's agenda *****/
2017-03-21 14:52:07 +01:00
Agd_ShowEvents (Agd_ANOTHER_AGENDA);
2016-12-06 03:10:06 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ();
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 ***************************/
/*****************************************************************************/
static void Agd_ShowEvents (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;
2016-11-30 22:49:48 +01:00
struct Pagination Pagination;
2016-12-02 00:24:16 +01:00
unsigned NumEvent;
Pag_WhatPaginate_t WhatPaginate[Agd_NUM_AGENDA_TYPES] =
{
2017-03-21 14:52:07 +01:00
Pag_MY_AGENDA, // Agd_MY_AGENDA_TODAY, not used
Pag_MY_AGENDA, // Agd_MY_AGENDA
Pag_ANOTHER_AGENDA, // Agd_ANOTHER_AGENDA_TODAY, not used
Pag_ANOTHER_AGENDA, // Agd_ANOTHER_AGENDA
2016-12-02 00:24:16 +01:00
};
/***** Get parameters *****/
2017-03-21 14:36:22 +01:00
Agd_GetParams (AgendaType);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get list of events *****/
2016-12-02 00:24:16 +01:00
Agd_GetListEvents (AgendaType);
2016-11-30 22:49:48 +01:00
/***** Compute variables related to pagination *****/
2016-12-02 00:24:16 +01:00
Pagination.NumItems = Gbl.Agenda.Num;
2017-04-13 20:09:22 +02:00
Pagination.CurrentPage = (int) Gbl.Agenda.CurrentPage;
2016-11-30 22:49:48 +01:00
Pag_CalculatePagination (&Pagination);
2017-04-13 20:09:22 +02:00
Gbl.Agenda.CurrentPage = (unsigned) Pagination.CurrentPage;
2016-11-30 22:49:48 +01:00
/***** Write links to pages *****/
if (Pagination.MoreThanOnePage)
2017-04-17 11:57:55 +02:00
Pag_WriteLinksToPagesCentered (WhatPaginate[AgendaType],
0,
&Pagination);
2016-11-30 22:49:48 +01:00
2016-12-02 00:24:16 +01:00
if (Gbl.Agenda.Num)
2016-11-30 22:49:48 +01:00
{
2016-12-06 03:10:06 +01:00
/***** Start table *****/
2017-06-11 20:09:59 +02:00
Tbl_StartTableWideMargin (2);
2016-12-06 03:10:06 +01:00
2016-11-30 22:49:48 +01:00
/***** Table head *****/
2016-12-06 03:10:06 +01:00
Agd_WriteHeaderListEvents (AgendaType);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Write all the events *****/
2016-12-02 00:24:16 +01:00
for (NumEvent = Pagination.FirstItemVisible;
NumEvent <= Pagination.LastItemVisible;
NumEvent++)
Agd_ShowOneEvent (AgendaType,Gbl.Agenda.LstAgdCods[NumEvent - 1]);
2016-11-30 22:49:48 +01:00
/***** End table *****/
2017-06-11 20:09:59 +02:00
Tbl_EndTable ();
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 *****/
if (Pagination.MoreThanOnePage)
2017-04-17 11:57:55 +02:00
Pag_WriteLinksToPagesCentered (WhatPaginate[AgendaType],
0,
&Pagination);
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)
2016-12-01 00:53:50 +01:00
Agd_PutButtonToCreateNewEvent ();
2016-11-30 22:49:48 +01:00
2016-12-06 03:10:06 +01:00
/***** Free list of events *****/
Agd_FreeListEvents ();
}
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
/*****************************************************************************/
2016-12-06 21:08:28 +01:00
static void Agd_ShowEventsToday (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 *****/
2017-03-21 14:36:22 +01:00
Agd_GetParams (AgendaType);
2016-12-06 03:10:06 +01:00
/***** Get list of events *****/
Agd_GetListEvents (AgendaType);
if (Gbl.Agenda.Num)
{
2017-06-12 14:16:33 +02:00
/***** Start 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:
2017-06-11 22:26:40 +02:00
Box_StartBoxTableShadow (NULL,Txt_Today,NULL,
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:
2017-06-11 22:26:40 +02:00
Box_StartBoxTableShadow (NULL,Txt_Today,NULL,
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 (AgendaType);
/***** Write all the events *****/
for (NumEvent = 0;
NumEvent < Gbl.Agenda.Num;
NumEvent++)
Agd_ShowOneEvent (AgendaType,Gbl.Agenda.LstAgdCods[NumEvent]);
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2017-06-10 21:38:10 +02:00
Box_EndBoxTable ();
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 *****/
Agd_FreeListEvents ();
2016-11-30 22:49:48 +01:00
}
2016-12-05 23:13:58 +01:00
/*****************************************************************************/
/*************** Put contextual icon to view/edit my agenda ******************/
/*****************************************************************************/
2016-12-06 03:10:06 +01:00
static void Agd_WriteHeaderListEvents (Agd_AgendaType_t AgendaType)
{
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;
Agd_Order_t Order;
/***** Table head *****/
fprintf (Gbl.F.Out,"<tr>");
for (Order = Agd_ORDER_BY_START_DATE;
Order <= Agd_ORDER_BY_END_DATE;
Order++)
{
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE\">");
switch (AgendaType)
{
2017-03-21 14:52:07 +01:00
case Agd_MY_AGENDA_TODAY:
case Agd_MY_AGENDA:
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeMyAgd);
2017-04-13 20:09:22 +02:00
Pag_PutHiddenParamPagNum (Pag_MY_AGENDA,Gbl.Agenda.CurrentPage);
2016-12-06 03:10:06 +01:00
break;
2017-03-21 14:52:07 +01:00
case Agd_ANOTHER_AGENDA_TODAY:
case Agd_ANOTHER_AGENDA:
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeUsrAgd);
2016-12-06 21:26:02 +01:00
Usr_PutParamOtherUsrCodEncrypted ();
2017-04-13 20:09:22 +02:00
Pag_PutHiddenParamPagNum (Pag_ANOTHER_AGENDA,Gbl.Agenda.CurrentPage);
2016-12-06 21:26:02 +01:00
break;
2016-12-06 03:10:06 +01:00
}
Par_PutHiddenParamUnsigned ("Order",(unsigned) Order);
2018-11-09 20:47:39 +01:00
Frm_LinkFormSubmit (Txt_START_END_TIME_HELP[Order],"TIT_TBL",NULL);
2017-01-29 12:42:19 +01:00
if (Order == Gbl.Agenda.SelectedOrder)
2016-12-06 03:10:06 +01:00
fprintf (Gbl.F.Out,"<u>");
2016-12-15 00:39:52 +01:00
fprintf (Gbl.F.Out,"%s",Txt_START_END_TIME[Order]);
2017-01-29 12:42:19 +01:00
if (Order == Gbl.Agenda.SelectedOrder)
2016-12-06 03:10:06 +01:00
fprintf (Gbl.F.Out,"</u>");
fprintf (Gbl.F.Out,"</a>");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-12-06 03:10:06 +01:00
fprintf (Gbl.F.Out,"</th>");
}
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE\">"
"%s"
"</th>"
"<th class=\"LEFT_MIDDLE\">"
"%s"
"</th>"
"</tr>",
Txt_Event,
Txt_Location);
}
/*****************************************************************************/
2016-12-06 21:08:28 +01:00
/********************** Put contextual icons in agenda ***********************/
2016-12-06 03:10:06 +01:00
/*****************************************************************************/
2016-12-06 21:08:28 +01:00
static void Agd_PutIconsMyFullAgenda (void)
2016-12-05 23:13:58 +01:00
{
2016-12-06 21:08:28 +01:00
/***** Put icon to create a new event *****/
Agd_PutIconToCreateNewEvent ();
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
2016-12-06 21:08:28 +01:00
static void Agd_PutIconsMyPublicAgenda (void)
2016-12-05 03:16:25 +01:00
{
2016-12-06 21:08:28 +01:00
/***** Put icon to view/edit my full agenda *****/
Agd_PutIconToViewEditMyFullAgenda ();
2016-12-05 03:16:25 +01:00
/***** Put icon to show QR code *****/
Agd_PutIconToShowQR ();
}
2016-12-01 00:53:50 +01:00
static void Agd_PutIconToCreateNewEvent (void)
2016-11-30 22:49:48 +01:00
{
extern const char *Txt_New_event;
2016-12-01 00:53:50 +01:00
/***** Put form to create a new event *****/
2017-03-21 14:36:22 +01:00
Gbl.Agenda.AgdCodToEdit = -1L;
2019-01-10 15:26:33 +01:00
Ico_PutContextualIconToAdd (ActFrmNewEvtMyAgd,NULL,
Agd_PutCurrentParamsMyAgenda,
Txt_New_event);
2016-11-30 22:49:48 +01:00
}
2016-12-06 21:08:28 +01:00
static void Agd_PutIconToViewEditMyFullAgenda (void)
{
2017-06-11 19:13:28 +02:00
Ico_PutContextualIconToEdit (ActSeeMyAgd,NULL);
2016-12-06 21:08:28 +01:00
}
2016-12-05 03:16:25 +01:00
static void Agd_PutIconToShowQR (void)
{
2017-03-07 01:56:41 +01:00
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
2018-10-17 01:08:42 +02:00
snprintf (URL,sizeof (URL),
"%s/%s?agd=@%s",
Cfg_URL_SWAD_CGI,
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Gbl.Prefs.Language],
2018-10-17 01:08:42 +02:00
Gbl.Usrs.Me.UsrDat.Nickname);
2016-12-05 09:50:35 +01:00
Gbl.QR.Str = URL;
2018-10-18 08:56:00 +02:00
QR_PutLinkToPrintQRCode (ActPrnAgdQR,QR_PutParamQRString);
2016-12-05 03:16:25 +01:00
}
2016-12-09 14:50:21 +01:00
static void Agd_PutIconsOtherPublicAgenda (void)
{
2017-02-17 01:59:58 +01:00
extern const char *Txt_Another_user_s_profile;
2016-12-09 14:50:21 +01:00
extern const char *Txt_View_record_for_this_course;
extern const char *Txt_View_record_and_office_hours;
/***** 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_PutParamOtherUsrCodEncrypted,
"user.svg",
Txt_Another_user_s_profile);
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_PutParamOtherUsrCodEncrypted,
"card.svg",
Txt_View_record_for_this_course);
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_PutParamOtherUsrCodEncrypted,
"card.svg",
Txt_View_record_and_office_hours);
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
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
static void Agd_PutButtonToCreateNewEvent (void)
2016-11-30 22:49:48 +01:00
{
extern const char *Txt_New_event;
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActFrmNewEvtMyAgd);
2017-04-13 20:09:22 +02:00
Agd_PutParamsMyAgenda (Gbl.Agenda.Past__FutureEvents,
Gbl.Agenda.PrivatPublicEvents,
Gbl.Agenda.HiddenVisiblEvents,
Gbl.Agenda.CurrentPage,
-1L);
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButton (Txt_New_event);
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
/*****************************************************************************/
2016-12-02 00:24:16 +01:00
static void Agd_ShowOneEvent (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];
2016-11-30 22:49:48 +01:00
extern const char *Txt_Today;
static unsigned UniqueId = 0;
2016-12-01 00:53:50 +01:00
struct AgendaEvent AgdEvent;
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
2016-12-01 00:53:50 +01:00
/***** Write first row of data of this event *****/
2016-11-30 22:49:48 +01:00
/* Start date/time */
UniqueId++;
fprintf (Gbl.F.Out,"<tr>"
2016-12-12 23:10:11 +01:00
"<td id=\"agd_date_start_%u\" class=\"%s LEFT_BOTTOM COLOR%u\">"
2016-11-30 22:49:48 +01:00
"<script type=\"text/javascript\">"
2017-05-04 17:06:26 +02:00
"writeLocalDateHMSFromUTC('agd_date_start_%u',%ld,"
2017-05-05 09:41:56 +02:00
"%u,'<br />','%s',true,true,0x6);"
2016-11-30 22:49:48 +01:00
"</script>"
"</td>",
UniqueId,
2016-12-03 19:22:06 +01:00
AgdEvent.Hidden ? Dat_TimeStatusClassHidden[AgdEvent.TimeStatus] :
Dat_TimeStatusClassVisible[AgdEvent.TimeStatus],
2016-11-30 22:49:48 +01:00
Gbl.RowEvenOdd,
2017-05-04 17:06:26 +02:00
UniqueId,AgdEvent.TimeUTC[Agd_START_TIME],
(unsigned) Gbl.Prefs.DateFormat,Txt_Today);
2016-11-30 22:49:48 +01:00
/* End date/time */
UniqueId++;
2016-12-12 23:10:11 +01:00
fprintf (Gbl.F.Out,"<td id=\"agd_date_end_%u\" class=\"%s LEFT_BOTTOM COLOR%u\">"
2016-11-30 22:49:48 +01:00
"<script type=\"text/javascript\">"
2017-05-04 17:06:26 +02:00
"writeLocalDateHMSFromUTC('agd_date_end_%u',%ld,"
2017-05-05 09:41:56 +02:00
"%u,'<br />','%s',false,true,0x6);"
2016-11-30 22:49:48 +01:00
"</script>"
"</td>",
UniqueId,
2016-12-03 19:22:06 +01:00
AgdEvent.Hidden ? Dat_TimeStatusClassHidden[AgdEvent.TimeStatus] :
Dat_TimeStatusClassVisible[AgdEvent.TimeStatus],
2016-11-30 22:49:48 +01:00
Gbl.RowEvenOdd,
2016-12-12 19:29:16 +01:00
UniqueId,AgdEvent.TimeUTC[Agd_END_TIME],
2017-05-04 17:06:26 +02:00
(unsigned) Gbl.Prefs.DateFormat,Txt_Today);
2016-11-30 22:49:48 +01:00
2016-11-30 22:59:02 +01:00
/* Event */
2016-11-30 22:49:48 +01:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_TOP COLOR%u\">"
2016-11-30 22:59:02 +01:00
"<div class=\"%s\">%s</div>"
"</td>",
2016-11-30 22:49:48 +01:00
Gbl.RowEvenOdd,
2016-12-03 19:22:06 +01:00
AgdEvent.Hidden ? "ASG_TITLE_LIGHT" :
"ASG_TITLE",
2016-12-01 00:53:50 +01:00
AgdEvent.Event);
2016-11-30 22:49:48 +01:00
2016-12-12 19:29:16 +01:00
/* Location */
2016-11-30 22:49:48 +01:00
fprintf (Gbl.F.Out,"<td class=\"LEFT_TOP COLOR%u\">"
2016-11-30 22:59:02 +01:00
"<div class=\"%s\">%s</div>"
"</td>"
"</tr>",
2016-11-30 22:49:48 +01:00
Gbl.RowEvenOdd,
2016-12-03 19:22:06 +01:00
AgdEvent.Hidden ? "ASG_TITLE_LIGHT" :
"ASG_TITLE",
2016-12-01 00:53:50 +01:00
AgdEvent.Location);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Write second row of data of this event *****/
2016-11-30 22:49:48 +01:00
fprintf (Gbl.F.Out,"<tr>"
"<td colspan=\"2\" class=\"LEFT_TOP COLOR%u\">",
Gbl.RowEvenOdd);
2016-12-01 00:53:50 +01:00
/* Forms to remove/edit this event */
2016-12-06 19:14:58 +01:00
switch (AgendaType)
{
2017-03-21 14:52:07 +01:00
case Agd_MY_AGENDA_TODAY:
case Agd_MY_AGENDA:
2016-12-06 19:14:58 +01:00
Agd_PutFormsToRemEditOneEvent (&AgdEvent);
break;
2016-12-06 21:08:28 +01:00
default:
break;
2016-12-06 19:14:58 +01:00
}
2016-12-02 00:24:16 +01:00
2016-11-30 22:49:48 +01:00
fprintf (Gbl.F.Out,"</td>");
2016-12-01 00:53:50 +01:00
/* Text of the event */
2016-12-02 00:24:16 +01:00
Agd_GetEventTxtFromDB (&AgdEvent,Txt);
2016-11-30 22:49:48 +01:00
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
2016-12-12 23:10:11 +01:00
fprintf (Gbl.F.Out,"<td colspan=\"2\" class=\"LEFT_TOP COLOR%u\">"
2017-10-24 11:26:01 +02:00
"<div class=\"PAR %s\">%s</div>"
2016-11-30 22:49:48 +01:00
"</td>"
"</tr>",
2016-12-12 23:10:11 +01:00
Gbl.RowEvenOdd,
2016-12-03 19:22:06 +01:00
AgdEvent.Hidden ? "DAT_LIGHT" :
"DAT",
2016-11-30 22:49:48 +01:00
Txt);
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/******************* Put a link (form) to edit one event *********************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-03 19:22:06 +01:00
static void Agd_PutFormsToRemEditOneEvent (struct AgendaEvent *AgdEvent)
2016-11-30 22:49:48 +01:00
{
2016-12-01 19:28:52 +01:00
extern const char *Txt_Event_private_click_to_make_it_visible_to_the_users_of_your_courses;
extern const char *Txt_Event_visible_to_the_users_of_your_courses_click_to_make_it_private;
2016-11-30 22:49:48 +01:00
2016-12-03 19:22:06 +01:00
Gbl.Agenda.AgdCodToEdit = AgdEvent->AgdCod; // Used as parameter in contextual links
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Put form to remove event *****/
2017-06-11 19:13:28 +02:00
Ico_PutContextualIconToRemove (ActReqRemEvtMyAgd,Agd_PutCurrentParamsMyAgenda);
2016-11-30 22:49:48 +01:00
2016-12-03 19:22:06 +01:00
/***** Put form to hide/show event *****/
if (AgdEvent->Hidden)
2019-03-25 19:05:10 +01:00
Ico_PutContextualIconToUnhide (ActShoEvtMyAgd,NULL,Agd_PutCurrentParamsMyAgenda);
2016-12-03 19:22:06 +01:00
else
2019-03-25 19:05:10 +01:00
Ico_PutContextualIconToHide (ActHidEvtMyAgd,NULL,Agd_PutCurrentParamsMyAgenda);
2016-12-03 19:22:06 +01:00
2016-12-01 00:53:50 +01:00
/***** Put form to edit event *****/
2017-06-11 19:13:28 +02:00
Ico_PutContextualIconToEdit (ActEdiOneEvtMyAgd,Agd_PutCurrentParamsMyAgenda);
2016-11-30 22:49:48 +01:00
2016-12-03 19:22:06 +01:00
/***** Put form 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_PutCurrentParamsMyAgenda,
2019-01-12 19:46:33 +01:00
"unlock.svg",
2019-01-12 03:00:59 +01:00
Txt_Event_visible_to_the_users_of_your_courses_click_to_make_it_private);
2016-12-06 19:50:32 +01:00
else
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (ActPubEvtMyAgd,NULL,
Agd_PutCurrentParamsMyAgenda,
"lock.svg",
Txt_Event_private_click_to_make_it_visible_to_the_users_of_your_courses);
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
/*****************************************************************************/
2017-04-13 20:09:22 +02:00
static void Agd_PutCurrentParamsMyAgenda (void)
2016-11-30 22:49:48 +01:00
{
2017-04-13 20:09:22 +02:00
Agd_PutParamsMyAgenda (Gbl.Agenda.Past__FutureEvents,
Gbl.Agenda.PrivatPublicEvents,
Gbl.Agenda.HiddenVisiblEvents,
Gbl.Agenda.CurrentPage,
Gbl.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. */
2017-04-13 20:09:22 +02:00
void Agd_PutParamsMyAgenda (unsigned Past__FutureEvents,
unsigned PrivatPublicEvents,
unsigned HiddenVisiblEvents,
unsigned NumPage,
long AgdCodToEdit)
2017-03-21 14:36:22 +01:00
{
if (Past__FutureEvents != (Agd_DEFAULT_PAST___EVENTS |
Agd_DEFAULT_FUTURE_EVENTS))
Agd_PutHiddenParamPast__FutureEvents (Past__FutureEvents);
if (PrivatPublicEvents != (Agd_DEFAULT_PRIVAT_EVENTS |
Agd_DEFAULT_PUBLIC_EVENTS))
Agd_PutHiddenParamPrivatPublicEvents (PrivatPublicEvents);
if (HiddenVisiblEvents != (Agd_DEFAULT_HIDDEN_EVENTS |
Agd_DEFAULT_VISIBL_EVENTS))
Agd_PutHiddenParamHiddenVisiblEvents (HiddenVisiblEvents);
2017-04-13 20:09:22 +02:00
if (Gbl.Agenda.SelectedOrder != Agd_ORDER_DEFAULT)
Par_PutHiddenParamUnsigned ("Order",(unsigned) Gbl.Agenda.SelectedOrder);
if (NumPage > 1)
Pag_PutHiddenParamPagNum (Pag_MY_AGENDA,NumPage);
2017-03-21 14:36:22 +01:00
if (AgdCodToEdit > 0)
Par_PutHiddenParamLong ("AgdCod",AgdCodToEdit);
}
/*****************************************************************************/
/********** Get parameter with the type or order in list of events ***********/
/*****************************************************************************/
static void Agd_GetParams (Agd_AgendaType_t AgendaType)
{
Pag_WhatPaginate_t WhatPaginate[Agd_NUM_AGENDA_TYPES] =
{
2017-03-21 14:52:07 +01:00
Pag_MY_AGENDA, // Agd_MY_AGENDA_TODAY, not used
Pag_MY_AGENDA, // Agd_MY_AGENDA
Pag_ANOTHER_AGENDA, // Agd_ANOTHER_AGENDA_TODAY, not used
Pag_ANOTHER_AGENDA, // Agd_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
{
Agd_GetParamsPast__FutureEvents ();
Agd_GetParamsPrivatPublicEvents ();
Agd_GetParamsHiddenVisiblEvents ();
}
Agd_GetParamEventOrder ();
2017-04-13 20:09:22 +02:00
Gbl.Agenda.CurrentPage = Pag_GetParamPagNum (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_PutHiddenParamEventsOrder (void)
{
if (Gbl.Agenda.SelectedOrder != Agd_ORDER_DEFAULT)
Par_PutHiddenParamUnsigned ("Order",(unsigned) Gbl.Agenda.SelectedOrder);
}
/*****************************************************************************/
/********** Get parameter with the type or order in list of events ***********/
/*****************************************************************************/
static void Agd_GetParamEventOrder (void)
{
static bool AlreadyGot = false;
if (!AlreadyGot)
{
Gbl.Agenda.SelectedOrder = (Agd_Order_t)
Par_GetParToUnsignedLong ("Order",
0,
Agd_NUM_ORDERS - 1,
(unsigned long) Agd_ORDER_DEFAULT);
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
2016-12-02 00:24:16 +01:00
static void Agd_GetListEvents (Agd_AgendaType_t AgendaType)
2016-11-30 22:49:48 +01:00
{
2018-10-30 01:00:46 +01:00
char *UsrSubQuery;
2017-03-22 01:14:48 +01:00
char Past__FutureEventsSubQuery[Agd_MAX_BYTES_SUBQUERY];
char PrivatPublicEventsSubQuery[Agd_MAX_BYTES_SUBQUERY];
char HiddenVisiblEventsSubQuery[Agd_MAX_BYTES_SUBQUERY];
2019-01-03 15:25:18 +01:00
static const char *OrderBySubQuery[Agd_NUM_ORDERS] =
{
"StartTime,EndTime,Event,Location", // Agd_ORDER_BY_START_DATE
"EndTime,StartTime,Event,Location", // Agd_ORDER_BY_END_DATE
};
2016-11-30 22:49:48 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
2016-12-02 00:24:16 +01:00
unsigned NumEvent;
2017-03-22 01:14:48 +01:00
bool DoQuery = true;
2016-11-30 22:49:48 +01:00
2017-03-22 01:14:48 +01:00
/***** Initialize list of events *****/
Agd_FreeListEvents ();
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get list of events from database *****/
2017-03-22 01:14:48 +01:00
/* Build events subqueries */
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:
2017-03-22 01:14:48 +01:00
if (Gbl.Agenda.Past__FutureEvents == 0 ||
Gbl.Agenda.PrivatPublicEvents == 0 ||
Gbl.Agenda.HiddenVisiblEvents == 0) // All selectors are off
DoQuery = false; // Nothing to get from database
else
2017-03-21 16:45:26 +01:00
{
2018-10-30 01:00:46 +01:00
if (asprintf (&UsrSubQuery,"UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
2017-03-22 01:14:48 +01:00
if (AgendaType == Agd_MY_AGENDA_TODAY)
Str_Copy (Past__FutureEventsSubQuery,
" AND DATE(StartTime)<=CURDATE()"
" AND DATE(EndTime)>=CURDATE()",
Agd_MAX_BYTES_SUBQUERY); // Today events
else
switch (Gbl.Agenda.Past__FutureEvents)
{
case (1 << Agd_PAST___EVENTS):
Str_Copy (Past__FutureEventsSubQuery,
" AND DATE(StartTime)<=CURDATE()",
Agd_MAX_BYTES_SUBQUERY); // Past and today events
break;
case (1 << Agd_FUTURE_EVENTS):
Str_Copy (Past__FutureEventsSubQuery,
" AND DATE(EndTime)>=CURDATE()",
Agd_MAX_BYTES_SUBQUERY); // Today and future events
break;
default:
Past__FutureEventsSubQuery[0] = '\0'; // All events
break;
}
switch (Gbl.Agenda.PrivatPublicEvents)
{
case (1 << Agd_PRIVAT_EVENTS):
Str_Copy (PrivatPublicEventsSubQuery," AND Public='N'",
Agd_MAX_BYTES_SUBQUERY); // Private events
break;
case (1 << Agd_PUBLIC_EVENTS):
Str_Copy (PrivatPublicEventsSubQuery," AND Public='Y'",
Agd_MAX_BYTES_SUBQUERY); // Public events
break;
default:
PrivatPublicEventsSubQuery[0] = '\0'; // All events
break;
}
switch (Gbl.Agenda.HiddenVisiblEvents)
{
case (1 << Agd_HIDDEN_EVENTS):
Str_Copy (HiddenVisiblEventsSubQuery," AND Hidden='Y'",
Agd_MAX_BYTES_SUBQUERY); // Hidden events
break;
case (1 << Agd_VISIBL_EVENTS):
Str_Copy (HiddenVisiblEventsSubQuery," AND Hidden='N'",
Agd_MAX_BYTES_SUBQUERY); // Visible events
break;
default:
HiddenVisiblEventsSubQuery[0] = '\0'; // All events
break;
}
2017-03-21 16:45:26 +01:00
}
2016-12-06 21:26:02 +01:00
break;
2017-03-21 14:52:07 +01:00
case Agd_ANOTHER_AGENDA_TODAY:
case Agd_ANOTHER_AGENDA:
2018-10-30 01:00:46 +01:00
if (asprintf (&UsrSubQuery,"UsrCod=%ld",
Gbl.Usrs.Other.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
2017-03-22 01:14:48 +01:00
if (AgendaType == Agd_ANOTHER_AGENDA_TODAY)
Str_Copy (Past__FutureEventsSubQuery,
" AND DATE(StartTime)<=CURDATE()"
" AND DATE(EndTime)>=CURDATE()",
Agd_MAX_BYTES_SUBQUERY); // Today events
else
Str_Copy (Past__FutureEventsSubQuery,
" AND DATE(EndTime)>=CURDATE()",
Agd_MAX_BYTES_SUBQUERY); // Today and future events
Str_Copy (PrivatPublicEventsSubQuery," AND Public='Y'",
Agd_MAX_BYTES_SUBQUERY); // Public events
Str_Copy (HiddenVisiblEventsSubQuery," AND Hidden='N'",
Agd_MAX_BYTES_SUBQUERY); // Visible events
2016-12-02 00:24:16 +01:00
}
2016-11-30 22:49:48 +01:00
2017-03-22 01:14:48 +01:00
if (DoQuery)
2016-11-30 22:49:48 +01:00
{
2019-01-03 15:25:18 +01:00
/* Make query */
2018-10-30 09:02:14 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get agenda events",
"SELECT AgdCod FROM agendas"
" WHERE %s%s%s%s"
" ORDER BY %s",
UsrSubQuery,
Past__FutureEventsSubQuery,
PrivatPublicEventsSubQuery,
HiddenVisiblEventsSubQuery,
2019-01-03 15:25:18 +01:00
OrderBySubQuery[Gbl.Agenda.SelectedOrder]);
2017-03-22 01:14:48 +01:00
2019-01-03 15:25:18 +01:00
/* Free allocated memory for subquery */
2018-10-30 01:00:46 +01:00
free ((void *) UsrSubQuery);
2017-03-22 01:14:48 +01:00
if (NumRows) // Events found...
{
Gbl.Agenda.Num = (unsigned) NumRows;
2016-11-30 22:49:48 +01:00
2017-03-22 01:14:48 +01:00
/***** Create list of events *****/
if ((Gbl.Agenda.LstAgdCods = (long *) calloc (NumRows,sizeof (long))) == NULL)
2018-10-18 20:06:54 +02:00
Lay_NotEnoughMemoryExit ();
2017-03-22 01:14:48 +01:00
/***** Get the events codes *****/
for (NumEvent = 0;
NumEvent < Gbl.Agenda.Num;
NumEvent++)
{
/* Get next event code */
row = mysql_fetch_row (mysql_res);
if ((Gbl.Agenda.LstAgdCods[NumEvent] = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Error: wrong event code.");
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-11-30 22:49:48 +01:00
}
else
2016-12-02 00:24:16 +01:00
Gbl.Agenda.Num = 0;
2016-11-30 22:49:48 +01:00
2016-12-02 00:24:16 +01:00
Gbl.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
/*****************************************************************************/
2016-12-02 00:24:16 +01:00
static void Agd_GetDataOfEventByCod (struct AgendaEvent *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 *****/
2018-10-30 09:02:14 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get agenda event data",
"SELECT AgdCod,Public,Hidden,"
"UNIX_TIMESTAMP(StartTime),"
"UNIX_TIMESTAMP(EndTime),"
2019-02-13 13:32:11 +01:00
"NOW()>EndTime," // Past event?
2018-10-30 09:02:14 +01:00
"NOW()<StartTime," // Future event?
"Event,Location"
" FROM agendas"
" WHERE AgdCod=%ld AND UsrCod=%ld",
AgdEvent->AgdCod,AgdEvent->UsrCod)) // 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
2016-12-09 00:44:15 +01:00
/* Get whether the event is public or not (row[1]) */
AgdEvent->Public = (row[1][0] == 'Y');
2016-11-30 22:49:48 +01:00
2016-12-09 00:44:15 +01:00
/* Get whether the event is hidden or not (row[2]) */
AgdEvent->Hidden = (row[2][0] == 'Y');
2016-11-30 22:49:48 +01:00
2016-12-09 00:44:15 +01:00
/* Get start date (row[3] holds the start UTC time) */
AgdEvent->TimeUTC[Agd_START_TIME] = Dat_GetUNIXTimeFromStr (row[3]);
2016-11-30 22:49:48 +01:00
2016-12-09 00:44:15 +01:00
/* Get end date (row[4] holds the end UTC time) */
AgdEvent->TimeUTC[Agd_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
2016-12-09 00:44:15 +01:00
/* Get the event (row[7]) */
2017-01-17 03:10:43 +01:00
Str_Copy (AgdEvent->Event,row[7],
2017-03-07 01:56:41 +01:00
Agd_MAX_BYTES_EVENT);
2016-12-03 19:22:06 +01:00
2016-12-09 00:44:15 +01:00
/* Get the event (row[8]) */
2017-01-17 03:10:43 +01:00
Str_Copy (AgdEvent->Location,row[8],
2017-03-07 01:56:41 +01:00
Agd_MAX_BYTES_LOCATION);
2016-12-09 00:44:15 +01:00
}
else
{
/***** Clear all event data *****/
AgdEvent->AgdCod = -1L;
AgdEvent->Public = false;
AgdEvent->Hidden = false;
AgdEvent->TimeUTC[Agd_START_TIME] =
AgdEvent->TimeUTC[Agd_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
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
void Agd_FreeListEvents (void)
2016-11-30 22:49:48 +01:00
{
2016-12-02 00:24:16 +01:00
if (Gbl.Agenda.LstIsRead && Gbl.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 *****/
2016-12-02 00:24:16 +01:00
free ((void *) Gbl.Agenda.LstAgdCods);
Gbl.Agenda.LstAgdCods = NULL;
Gbl.Agenda.Num = 0;
Gbl.Agenda.LstIsRead = false;
2016-11-30 22:49:48 +01:00
}
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/*********************** Get event text from database ************************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2017-01-17 03:10:43 +01:00
static void Agd_GetEventTxtFromDB (struct AgendaEvent *AgdEvent,
char Txt[Cns_MAX_BYTES_TEXT + 1])
2016-11-30 22:49:48 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
2016-12-01 00:53:50 +01:00
/***** Get text of event from database *****/
2018-10-30 09:02:14 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get event text",
"SELECT Txt FROM agendas"
" WHERE AgdCod=%ld AND UsrCod=%ld",
AgdEvent->AgdCod,AgdEvent->UsrCod);
2016-11-30 22:49:48 +01:00
/***** The result of the query must have one row or none *****/
if (NumRows == 1)
{
/* Get info text */
row = mysql_fetch_row (mysql_res);
2017-01-17 03:10:43 +01:00
Str_Copy (Txt,row[0],
Cns_MAX_BYTES_TEXT);
2016-11-30 22:49:48 +01:00
}
else
Txt[0] = '\0';
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
if (NumRows > 1)
2016-12-01 00:53:50 +01:00
Lay_ShowErrorAndExit ("Error when getting event text.");
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/******************** Get parameter with code of event ***********************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
long Agd_GetParamAgdCod (void)
2016-11-30 22:49:48 +01:00
{
2017-01-28 20:32:50 +01:00
/***** Get code of event *****/
return Par_GetParToLong ("AgdCod");
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;
struct AgendaEvent AgdEvent;
2016-11-30 22:49:48 +01:00
/***** Get parameters *****/
2017-03-21 14:52:07 +01:00
Agd_GetParams (Agd_MY_AGENDA);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get event code *****/
if ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of event is missing.");
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 *****/
2017-05-11 21:53:37 +02:00
Gbl.Agenda.AgdCodToEdit = AgdEvent.AgdCod;
2019-02-17 01:14:55 +01:00
Ale_ShowAlertAndButton (ActRemEvtMyAgd,NULL,NULL,
2017-05-25 14:25:22 +02:00
Agd_PutCurrentParamsMyAgenda,
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 *****/
2016-12-02 00:24:16 +01:00
Agd_ShowMyAgenda ();
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;
2016-12-01 00:53:50 +01:00
struct AgendaEvent AgdEvent;
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get event code *****/
if ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of event is missing.");
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 *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove event",
"DELETE FROM agendas WHERE AgdCod=%ld AND UsrCod=%ld",
AgdEvent.AgdCod,AgdEvent.UsrCod);
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 *****/
2016-12-02 00:24:16 +01:00
Agd_ShowMyAgenda ();
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
{
2016-12-03 19:22:06 +01:00
extern const char *Txt_Event_X_is_now_hidden;
2016-12-01 00:53:50 +01:00
struct AgendaEvent AgdEvent;
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get event code *****/
if ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of event is missing.");
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 17:34:07 +01:00
/***** Set event private *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not hide event",
"UPDATE agendas SET Hidden='Y'"
" WHERE AgdCod=%ld AND UsrCod=%ld",
AgdEvent.AgdCod,AgdEvent.UsrCod);
2016-12-03 19:22:06 +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_hidden,
2019-02-15 23:38:44 +01:00
AgdEvent.Event);
2016-12-03 19:22:06 +01:00
/***** Show events again *****/
Agd_ShowMyAgenda ();
}
/*****************************************************************************/
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
{
extern const char *Txt_Event_X_is_now_visible;
struct AgendaEvent AgdEvent;
/***** Get event code *****/
if ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of event is missing.");
/***** Get data of the event from database *****/
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
Agd_GetDataOfEventByCod (&AgdEvent);
/***** Set event public *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not show event",
"UPDATE agendas SET Hidden='N'"
" WHERE AgdCod=%ld AND UsrCod=%ld",
AgdEvent.AgdCod,AgdEvent.UsrCod);
2016-12-03 19:22:06 +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,
2019-02-15 23:38:44 +01:00
AgdEvent.Event);
2016-12-03 19:22:06 +01:00
/***** Show events again *****/
Agd_ShowMyAgenda ();
}
/*****************************************************************************/
/****************************** Make event private ***************************/
/*****************************************************************************/
void Agd_MakeEventPrivate (void)
{
extern const char *Txt_Event_X_is_now_private;
struct AgendaEvent AgdEvent;
/***** Get event code *****/
if ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of event is missing.");
/***** Get data of the event from database *****/
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
Agd_GetDataOfEventByCod (&AgdEvent);
/***** Make event private *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not make event private",
"UPDATE agendas SET Public='N'"
" WHERE AgdCod=%ld AND UsrCod=%ld",
AgdEvent.AgdCod,AgdEvent.UsrCod);
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 *****/
2016-12-02 00:24:16 +01:00
Agd_ShowMyAgenda ();
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;
2016-12-01 00:53:50 +01:00
struct AgendaEvent AgdEvent;
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get event code *****/
if ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of event is missing.");
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 *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not make event public",
"UPDATE agendas SET Public='Y'"
" WHERE AgdCod=%ld AND UsrCod=%ld",
AgdEvent.AgdCod,AgdEvent.UsrCod);
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 *****/
2016-12-02 00:24:16 +01:00
Agd_ShowMyAgenda ();
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;
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
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;
2016-12-01 00:53:50 +01:00
struct AgendaEvent AgdEvent;
bool ItsANewEvent;
2017-01-17 03:10:43 +01:00
char Txt[Cns_MAX_BYTES_TEXT + 1];
2016-11-30 22:49:48 +01:00
/***** Get parameters *****/
2017-03-21 14:52:07 +01:00
Agd_GetParams (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 = Agd_GetParamAgdCod ()) == -1L);
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;
2016-12-02 10:45:53 +01:00
AgdEvent.TimeUTC[Agd_START_TIME] = Gbl.StartExecutionTimeUTC;
AgdEvent.TimeUTC[Agd_END_TIME ] = Gbl.StartExecutionTimeUTC + (2 * 60 * 60); // +2 hours
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 */
2016-12-02 00:24:16 +01:00
Agd_GetEventTxtFromDB (&AgdEvent,Txt);
2016-11-30 22:49:48 +01:00
}
/***** Start form *****/
2016-12-01 00:53:50 +01:00
if (ItsANewEvent)
2017-03-21 14:36:22 +01:00
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActNewEvtMyAgd);
2017-03-21 14:36:22 +01:00
Gbl.Agenda.AgdCodToEdit = -1L;
}
2016-11-30 22:49:48 +01:00
else
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgEvtMyAgd);
2017-03-21 14:36:22 +01:00
Gbl.Agenda.AgdCodToEdit = AgdEvent.AgdCod;
2016-11-30 22:49:48 +01:00
}
2017-04-13 20:09:22 +02:00
Agd_PutCurrentParamsMyAgenda ();
2016-11-30 22:49:48 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box and table *****/
2017-06-11 22:26:40 +02:00
if (ItsANewEvent)
Box_StartBoxTable (NULL,Txt_New_event,NULL,
2017-06-12 15:03:29 +02:00
Hlp_PROFILE_Agenda_new_event,Box_NOT_CLOSABLE,2);
2017-06-11 22:26:40 +02:00
else
Box_StartBoxTable (NULL,Txt_Edit_event,NULL,
2017-06-12 15:03:29 +02:00
Hlp_PROFILE_Agenda_edit_event,Box_NOT_CLOSABLE,2);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Event *****/
2016-11-30 22:49:48 +01:00
fprintf (Gbl.F.Out,"<tr>"
2016-12-20 21:46:59 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"Event\" class=\"%s\">%s:</label>"
2016-11-30 22:49:48 +01:00
"</td>"
"<td class=\"LEFT_MIDDLE\">"
2016-12-20 21:46:59 +01:00
"<input type=\"text\" id=\"Event\" name=\"Event\""
2016-11-30 22:49:48 +01:00
" size=\"45\" maxlength=\"%u\" value=\"%s\""
" required=\"required\" />"
"</td>"
"</tr>",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2016-12-01 00:53:50 +01:00
Txt_Event,
2017-03-07 01:56:41 +01:00
Agd_MAX_CHARS_EVENT,AgdEvent.Event);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Location *****/
2016-11-30 22:49:48 +01:00
fprintf (Gbl.F.Out,"<tr>"
2016-12-20 21:46:59 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"Location\" class=\"%s\">%s:</label>"
2016-11-30 22:49:48 +01:00
"</td>"
"<td class=\"LEFT_MIDDLE\">"
2016-12-20 21:46:59 +01:00
"<input type=\"text\" id=\"Location\" name=\"Location\""
2016-11-30 22:49:48 +01:00
" size=\"45\" maxlength=\"%u\" value=\"%s\""
" required=\"required\" />"
"</td>"
"</tr>",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2016-12-01 00:53:50 +01:00
Txt_Location,
2017-03-07 01:56:41 +01:00
Agd_MAX_CHARS_LOCATION,AgdEvent.Location);
2016-11-30 22:49:48 +01:00
/***** Start and end dates *****/
2016-12-03 20:08:01 +01:00
Dat_PutFormStartEndClientLocalDateTimes (AgdEvent.TimeUTC,
Dat_FORM_SECONDS_OFF);
2016-11-30 22:49:48 +01:00
/***** Text *****/
fprintf (Gbl.F.Out,"<tr>"
2016-12-20 21:46:59 +01:00
"<td class=\"RIGHT_TOP\">"
"<label for=\"Txt\" class=\"%s\">%s:</label>"
2016-11-30 22:49:48 +01:00
"</td>"
"<td class=\"LEFT_TOP\">"
2016-12-20 21:46:59 +01:00
"<textarea id=\"Txt\" name=\"Txt\""
" cols=\"60\" rows=\"10\">",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2016-11-30 22:49:48 +01:00
Txt_Description);
2016-12-01 00:53:50 +01:00
if (!ItsANewEvent)
2016-11-30 22:49:48 +01:00
fprintf (Gbl.F.Out,"%s",Txt);
fprintf (Gbl.F.Out,"</textarea>"
"</td>"
"</tr>");
2017-06-12 14:16:33 +02:00
/***** End table, send button and end box *****/
2016-12-01 00:53:50 +01:00
if (ItsANewEvent)
2017-06-11 19:02:40 +02:00
Box_EndBoxTableWithButton (Btn_CREATE_BUTTON,Txt_Create_event);
2016-11-30 22:49:48 +01:00
else
2019-02-18 18:27:45 +01:00
Box_EndBoxTableWithButton (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 *****/
2016-12-06 03:10:06 +01:00
Agd_ShowMyAgenda ();
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
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
void Agd_RecFormEvent (void)
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
extern const char *Txt_You_must_specify_the_title_of_the_event;
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;
2016-12-09 00:44:15 +01:00
struct AgendaEvent 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
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 *****/
2016-12-09 00:44:15 +01:00
ItsANewEvent = ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L);
2016-11-30 22:49:48 +01:00
/***** Get start/end date-times *****/
2016-12-09 00:44:15 +01:00
AgdEvent.TimeUTC[Agd_START_TIME] = Dat_GetTimeUTCFromForm ("StartTimeUTC");
AgdEvent.TimeUTC[Agd_END_TIME ] = Dat_GetTimeUTCFromForm ("EndTimeUTC" );
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get event *****/
2017-03-07 01:56:41 +01:00
Par_GetParToText ("Location",AgdEvent.Location,Agd_MAX_BYTES_LOCATION);
2016-11-30 22:49:48 +01:00
/***** Get event *****/
2017-03-07 01:56:41 +01:00
Par_GetParToText ("Event",AgdEvent.Event,Agd_MAX_BYTES_EVENT);
2016-11-30 22:49:48 +01:00
/***** Get text *****/
2019-02-15 21:09:18 +01:00
Par_GetParToHTML ("Txt",EventTxt,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous)
2016-11-30 22:49:48 +01:00
/***** Adjust dates *****/
2016-12-09 00:44:15 +01:00
if (AgdEvent.TimeUTC[Agd_START_TIME] == 0)
AgdEvent.TimeUTC[Agd_START_TIME] = Gbl.StartExecutionTimeUTC;
if (AgdEvent.TimeUTC[Agd_END_TIME] == 0)
2017-01-28 15:58:46 +01:00
AgdEvent.TimeUTC[Agd_END_TIME] = AgdEvent.TimeUTC[Agd_START_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;
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_specify_the_title_of_the_event);
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;
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_must_specify_the_title_of_the_event);
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
{
2019-02-15 21:09:18 +01:00
Agd_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
{
2019-02-15 21:09:18 +01:00
Agd_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 *****/
2016-12-02 00:24:16 +01:00
Agd_ShowMyAgenda ();
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-01 00:53:50 +01:00
/************************** Create a new event *******************************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
static void Agd_CreateEvent (struct AgendaEvent *AgdEvent,const char *Txt)
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
/***** Create a new event *****/
2018-11-03 01:45:36 +01:00
AgdEvent->AgdCod =
DB_QueryINSERTandReturnCode ("can not create new event",
"INSERT INTO agendas"
" (UsrCod,StartTime,EndTime,Event,Location,Txt)"
" VALUES"
" (%ld,FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld),"
"'%s','%s','%s')",
AgdEvent->UsrCod,
AgdEvent->TimeUTC[Agd_START_TIME],
AgdEvent->TimeUTC[Agd_END_TIME ],
AgdEvent->Event,
AgdEvent->Location,
Txt);
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/************************ Update an existing event ***************************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
static void Agd_UpdateEvent (struct AgendaEvent *AgdEvent,const char *Txt)
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
/***** Update the data of the event *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update event",
"UPDATE agendas SET "
"StartTime=FROM_UNIXTIME(%ld),"
"EndTime=FROM_UNIXTIME(%ld),"
"Event='%s',Location='%s',Txt='%s'"
" WHERE AgdCod=%ld AND UsrCod=%ld",
AgdEvent->TimeUTC[Agd_START_TIME],
AgdEvent->TimeUTC[Agd_END_TIME ],
AgdEvent->Event,AgdEvent->Location,Txt,
AgdEvent->AgdCod,AgdEvent->UsrCod);
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/********************** Remove all the events of a user **********************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
void Agd_RemoveUsrEvents (long UsrCod)
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
/***** Remove events *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove all the events of a user",
"DELETE FROM agendas WHERE UsrCod=%ld",
UsrCod);
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/********************* Get number of events from a user **********************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
unsigned Agd_GetNumEventsFromUsr (long UsrCod)
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
/***** Get number of events in a course from database *****/
2018-11-03 13:13:11 +01:00
return (unsigned) DB_QueryCOUNT ("can not get number of events from user",
"SELECT COUNT(*) FROM agendas"
" WHERE UsrCod=%ld",
UsrCod);
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/********************** Get number of users with events **********************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
// Returns the number of users with events in a given scope
2016-11-30 22:49:48 +01:00
2019-04-03 20:57:04 +02:00
unsigned Agd_GetNumUsrsWithEvents (Hie_Level_t Scope)
2016-11-30 22:49:48 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs;
2016-12-01 00:53:50 +01:00
/***** Get number of courses with events from database *****/
2016-11-30 22:49:48 +01:00
switch (Scope)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of users with events",
"SELECT COUNT(DISTINCT UsrCod)"
" FROM agendas"
" WHERE UsrCod>0");
2016-11-30 22:49:48 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of users with events",
"SELECT COUNT(DISTINCT agendas.UsrCod)"
" FROM institutions,centres,degrees,courses,crs_usr,agendas"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod);
2016-11-30 22:49:48 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of users with events",
"SELECT COUNT(DISTINCT agendas.UsrCod)"
" FROM centres,degrees,courses,crs_usr,agendas"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod);
2016-11-30 22:49:48 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of users with events",
"SELECT COUNT(DISTINCT agendas.UsrCod)"
" FROM degrees,courses,crs_usr,agendas"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod);
2016-11-30 22:49:48 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of users with events",
"SELECT COUNT(DISTINCT agendas.UsrCod)"
" FROM courses,crs_usr,agendas"
" WHERE courses.DegCod=%ld"
" AND courses.Status=0"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod);
2016-11-30 22:49:48 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of users with events",
"SELECT COUNT(DISTINCT agendas.UsrCod)"
" FROM crs_usr,agendas"
" WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.UsrCod=agendas.UsrCod",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2016-11-30 22:49:48 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2016-11-30 22:49:48 +01:00
break;
}
/***** Get number of users *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumUsrs) != 1)
2016-12-01 00:53:50 +01:00
Lay_ShowErrorAndExit ("Error when getting number of users with events.");
2016-11-30 22:49:48 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumUsrs;
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/*************************** Get number of events ****************************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
// Returns the number of events in a given scope
2016-11-30 22:49:48 +01:00
2019-04-03 20:57:04 +02:00
unsigned Agd_GetNumEvents (Hie_Level_t Scope)
2016-11-30 22:49:48 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-12-01 00:53:50 +01:00
unsigned NumEvents;
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get number of events from database *****/
2016-11-30 22:49:48 +01:00
switch (Scope)
{
2019-04-03 20:57:04 +02:00
case Hie_SYS:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of events",
"SELECT COUNT(*)"
" FROM agendas"
" WHERE UsrCod>0");
2016-11-30 22:49:48 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTY:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of events",
"SELECT COUNT(*)"
" FROM institutions,centres,degrees,courses,crs_usr,agendas"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Cty.CtyCod);
2016-11-30 22:49:48 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_INS:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of events",
"SELECT COUNT(*)"
" FROM centres,degrees,courses,crs_usr,agendas"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ins.InsCod);
2016-11-30 22:49:48 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CTR:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of events",
"SELECT COUNT(*)"
" FROM degrees,courses,crs_usr,agendas"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Ctr.CtrCod);
2016-11-30 22:49:48 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_DEG:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of events",
"SELECT COUNT(*)"
" FROM courses,crs_usr,agendas"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
2019-04-03 20:57:04 +02:00
Gbl.Hierarchy.Deg.DegCod);
2016-11-30 22:49:48 +01:00
break;
2019-04-03 20:57:04 +02:00
case Hie_CRS:
2018-10-30 09:02:14 +01:00
DB_QuerySELECT (&mysql_res,"can not get number of events",
"SELECT COUNT(*)"
" FROM crs_usr,agendas"
" WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.UsrCod=agendas.UsrCod",
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Crs.CrsCod);
2016-11-30 22:49:48 +01:00
break;
default:
2018-10-24 23:03:11 +02:00
Lay_WrongScopeExit ();
2016-11-30 22:49:48 +01:00
break;
}
2016-12-01 00:53:50 +01:00
/***** Get number of events *****/
2016-11-30 22:49:48 +01:00
row = mysql_fetch_row (mysql_res);
2016-12-01 00:53:50 +01:00
if (sscanf (row[0],"%u",&NumEvents) != 1)
Lay_ShowErrorAndExit ("Error when getting number of events.");
2016-11-30 22:49:48 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-12-01 00:53:50 +01:00
return NumEvents;
2016-07-07 00:21:10 +02: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;
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2018-10-17 01:08:42 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
Txt_Where_s_USER,
Gbl.Usrs.Me.UsrDat.FullName);
2017-06-10 21:38:10 +02:00
Box_StartBox (NULL,Gbl.Title,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE);
2016-12-07 00:41:36 +01:00
/***** Print QR code ****/
QR_PrintQRCode ();
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ();
2016-12-07 00:41:36 +01:00
}