swad-core/swad_agenda.c

1371 lines
49 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-2016 Antonio Ca<EFBFBD>as Vargas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General 3 License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
2016-11-30 22:49:48 +01:00
/********************************* Headers ***********************************/
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
2016-11-30 22:49:48 +01:00
#include <linux/limits.h> // For PATH_MAX
#include <linux/stddef.h> // For NULL
#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"
#include "swad_database.h"
#include "swad_global.h"
#include "swad_group.h"
#include "swad_notification.h"
#include "swad_pagination.h"
#include "swad_parameter.h"
#include "swad_photo.h"
#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 *****************************/
/*****************************************************************************/
/*****************************************************************************/
2016-11-30 22:49:48 +01:00
/******************************* Private types *******************************/
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
2016-12-02 00:24:16 +01:00
#define Agd_NUM_AGENDA_TYPES 2
typedef enum
{
Agd_USR_AGENDA,
Agd_MY_AGENDA,
} 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 ****************************/
/*****************************************************************************/
2016-12-02 00:24:16 +01:00
static void Agd_ShowEvents (Agd_AgendaType_t AgendaType);
2016-12-01 00:53:50 +01:00
static void Agd_PutIconToCreateNewEvent (void);
static void Agd_PutButtonToCreateNewEvent (void);
static void Agd_PutParamsToCreateNewEvent (void);
2016-12-02 00:24:16 +01:00
static void Agd_ShowOneEvent (Agd_AgendaType_t AgendaType,long AgdCod);
2016-12-01 00:53:50 +01:00
static void Agd_WriteEventAuthor (struct AgendaEvent *AgdEvent);
static void Agd_GetParamEventOrderType (void);
2016-12-03 17:34:07 +01:00
static void Agd_PutFormsToRemEditOneEvent (long AgdCod,bool Public);
2016-12-01 00:53:50 +01:00
static void Agd_PutParams (void);
2016-12-02 00:24:16 +01:00
static void Agd_GetListEvents (Agd_AgendaType_t AgendaType);
static void Agd_GetDataOfEventByCod (struct AgendaEvent *AgdEvent);
2016-12-01 00:53:50 +01:00
static void Agd_GetDataOfEvent (struct AgendaEvent *AgdEvent,const char *Query);
2016-12-02 00:24:16 +01:00
static void Agd_GetEventTxtFromDB (struct AgendaEvent *AgdEvent,char *Txt);
2016-12-01 00:53:50 +01:00
static void Agd_PutParamAgdCod (long AgdCod);
static bool Agd_CheckIfSimilarEventExists (const char *Field,const char *Value,long AgdCod);
static void Agd_CreateEvent (struct AgendaEvent *AgdEvent,const char *Txt);
static void Agd_UpdateEvent (struct AgendaEvent *AgdEvent,const char *Txt);
/*****************************************************************************/
2016-12-02 00:24:16 +01:00
/************************ Show another user's agenda *************************/
2016-12-01 00:53:50 +01:00
/*****************************************************************************/
2016-12-02 00:24:16 +01:00
void Agd_ShowUsrAgenda (void)
2016-11-30 22:49:48 +01:00
{
2016-12-02 00:24:16 +01:00
extern const char *Txt_User_not_found_or_you_do_not_have_permission_;
2016-11-30 22:49:48 +01:00
2016-12-02 00:24:16 +01:00
/***** Get user *****/
if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
/***** Show all the visible events in the user's agenda *****/
Agd_ShowEvents (Agd_USR_AGENDA);
else
Lay_ShowAlert (Lay_WARNING,Txt_User_not_found_or_you_do_not_have_permission_);
2016-11-30 22:49:48 +01:00
}
2016-07-07 00:21:10 +02:00
/*****************************************************************************/
2016-12-02 00:24:16 +01:00
/******************************* Show my agenda ******************************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-02 00:24:16 +01:00
void Agd_ShowMyAgenda (void)
{
/***** Show all my events *****/
Agd_ShowEvents (Agd_MY_AGENDA);
}
/*****************************************************************************/
/*************************** 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-02 00:58:07 +01:00
extern const char *Txt_Agenda_USER;
2016-12-02 00:24:16 +01:00
extern const char *Txt_My_agenda;
2016-11-30 22:49:48 +01:00
extern const char *Txt_ASG_ATT_OR_SVY_HELP_ORDER[2];
extern const char *Txt_ASG_ATT_OR_SVY_ORDER[2];
extern const char *Txt_Event;
2016-11-30 22:59:02 +01:00
extern const char *Txt_Location;
2016-12-01 00:53:50 +01:00
extern const char *Txt_No_events;
2016-12-02 10:45:53 +01:00
Agd_Order_t Order;
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] =
{
Pag_USR_AGENDA,
Pag_MY_AGENDA,
};
/***** Get parameters *****/
Agd_GetParamEventOrderType ();
Pag_GetParamPagNum (WhatPaginate[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;
2016-11-30 22:49:48 +01:00
Pagination.CurrentPage = (int) Gbl.Pag.CurrentPage;
Pag_CalculatePagination (&Pagination);
Gbl.Pag.CurrentPage = (unsigned) Pagination.CurrentPage;
/***** Write links to pages *****/
if (Pagination.MoreThanOnePage)
2016-12-02 00:24:16 +01:00
Pag_WriteLinksToPagesCentered (WhatPaginate[AgendaType],0,&Pagination);
2016-11-30 22:49:48 +01:00
/***** Start frame *****/
2016-12-02 00:58:07 +01:00
switch (AgendaType)
{
case Agd_USR_AGENDA:
sprintf (Gbl.Title,Txt_Agenda_USER,Gbl.Usrs.Other.UsrDat.FullName); // TODO: Need translation!!!!!
Lay_StartRoundFrame ("100%",Gbl.Title,
NULL,
Hlp_PROFILE_Agenda); // TODO: Change
break;
case Agd_MY_AGENDA:
Lay_StartRoundFrame ("100%",Txt_My_agenda,
Agd_PutIconToCreateNewEvent,
Hlp_PROFILE_Agenda);
break;
}
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
{
/***** Table head *****/
fprintf (Gbl.F.Out,"<table class=\"FRAME_TBL_MARGIN CELLS_PAD_2\">"
"<tr>");
2016-12-02 10:45:53 +01:00
for (Order = Agd_ORDER_BY_START_DATE;
Order <= Agd_ORDER_BY_END_DATE;
2016-11-30 22:49:48 +01:00
Order++)
{
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE\">");
2016-12-02 00:24:16 +01:00
switch (AgendaType)
{
case Agd_USR_AGENDA:
Act_FormStart (ActSeeUsrAgd);
Usr_PutParamOtherUsrCodEncrypted ();
break;
case Agd_MY_AGENDA:
Act_FormStart (ActSeeMyAgd);
break;
}
2016-11-30 22:49:48 +01:00
Pag_PutHiddenParamPagNum (Gbl.Pag.CurrentPage);
Par_PutHiddenParamUnsigned ("Order",(unsigned) Order);
Act_LinkFormSubmit (Txt_ASG_ATT_OR_SVY_HELP_ORDER[Order],"TIT_TBL",NULL);
2016-12-02 00:24:16 +01:00
if (Order == Gbl.Agenda.SelectedOrderType)
2016-11-30 22:49:48 +01:00
fprintf (Gbl.F.Out,"<u>");
fprintf (Gbl.F.Out,"%s",Txt_ASG_ATT_OR_SVY_ORDER[Order]);
2016-12-02 00:24:16 +01:00
if (Order == Gbl.Agenda.SelectedOrderType)
2016-11-30 22:49:48 +01:00
fprintf (Gbl.F.Out,"</u>");
fprintf (Gbl.F.Out,"</a>");
Act_FormEnd ();
fprintf (Gbl.F.Out,"</th>");
}
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE\">"
"%s"
"</th>"
"<th class=\"LEFT_MIDDLE\">"
"%s"
"</th>"
"</tr>",
2016-11-30 22:59:02 +01:00
Txt_Event,
Txt_Location);
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 *****/
fprintf (Gbl.F.Out,"</table>");
}
2016-12-01 00:53:50 +01:00
else // No events created
Lay_ShowAlert (Lay_INFO,Txt_No_events);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Button to create a new event *****/
2016-12-02 00:24:16 +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
/***** End frame *****/
Lay_EndRoundFrame ();
/***** Write again links to pages *****/
if (Pagination.MoreThanOnePage)
2016-12-02 00:24:16 +01:00
Pag_WriteLinksToPagesCentered (WhatPaginate[AgendaType],0,&Pagination);
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-01 00:53:50 +01:00
/********************** Put icon to create a new event ***********************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
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 *****/
2016-12-01 01:39:06 +01:00
Lay_PutContextualLink (ActFrmNewEvtMyAgd,Agd_PutParamsToCreateNewEvent,
2016-11-30 22:49:48 +01:00
"plus64x64.png",
Txt_New_event,NULL,
NULL);
}
/*****************************************************************************/
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;
2016-12-01 01:39:06 +01:00
Act_FormStart (ActFrmNewEvtMyAgd);
2016-12-01 00:53:50 +01:00
Agd_PutParamsToCreateNewEvent ();
2016-11-30 22:49:48 +01:00
Lay_PutConfirmButton (Txt_New_event);
Act_FormEnd ();
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/******************** Put parameters to create a new event *******************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
static void Agd_PutParamsToCreateNewEvent (void)
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
Agd_PutHiddenParamEventsOrderType ();
2016-11-30 22:49:48 +01:00
Pag_PutHiddenParamPagNum (Gbl.Pag.CurrentPage);
}
/*****************************************************************************/
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;
2016-11-30 22:49:48 +01:00
char Txt[Cns_MAX_BYTES_TEXT+1];
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)
{
case Agd_USR_AGENDA:
AgdEvent.UsrCod = Gbl.Usrs.Other.UsrDat.UsrCod;
break;
case Agd_MY_AGENDA:
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
break;
}
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-02 00:24:16 +01:00
"<td id=\"agd_date_start_%u\" class=\"%s LEFT_TOP COLOR%u\">"
2016-11-30 22:49:48 +01:00
"<script type=\"text/javascript\">"
2016-12-02 00:24:16 +01:00
"writeLocalDateHMSFromUTC('agd_date_start_%u',%ld,'<br />','%s');"
2016-11-30 22:49:48 +01:00
"</script>"
"</td>",
UniqueId,
2016-12-03 17:34:07 +01:00
AgdEvent.Public ? Dat_TimeStatusClassVisible[AgdEvent.TimeStatus] :
Dat_TimeStatusClassHidden[AgdEvent.TimeStatus],
2016-11-30 22:49:48 +01:00
Gbl.RowEvenOdd,
2016-12-02 10:45:53 +01:00
UniqueId,AgdEvent.TimeUTC[Agd_START_TIME],Txt_Today);
2016-11-30 22:49:48 +01:00
/* End date/time */
UniqueId++;
2016-12-02 00:24:16 +01:00
fprintf (Gbl.F.Out,"<td id=\"agd_date_end_%u\" class=\"%s LEFT_TOP COLOR%u\">"
2016-11-30 22:49:48 +01:00
"<script type=\"text/javascript\">"
2016-12-02 00:24:16 +01:00
"writeLocalDateHMSFromUTC('agd_date_end_%u',%ld,'<br />','%s');"
2016-11-30 22:49:48 +01:00
"</script>"
"</td>",
UniqueId,
2016-12-03 17:34:07 +01:00
AgdEvent.Public ? Dat_TimeStatusClassVisible[AgdEvent.TimeStatus] :
Dat_TimeStatusClassHidden[AgdEvent.TimeStatus],
2016-11-30 22:49:48 +01:00
Gbl.RowEvenOdd,
2016-12-02 10:45:53 +01:00
UniqueId,AgdEvent.TimeUTC[Agd_END_TIME],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 17:34:07 +01:00
AgdEvent.Public ? "ASG_TITLE" :
"ASG_TITLE_LIGHT",
2016-12-01 00:53:50 +01:00
AgdEvent.Event);
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,"<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 17:34:07 +01:00
AgdEvent.Public ? "ASG_TITLE" :
"ASG_TITLE_LIGHT",
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
/* Author of the event */
Agd_WriteEventAuthor (&AgdEvent);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/* Forms to remove/edit this event */
2016-12-02 00:24:16 +01:00
if (AgendaType == Agd_MY_AGENDA)
2016-12-03 17:34:07 +01:00
Agd_PutFormsToRemEditOneEvent (AgdEvent.AgdCod,AgdEvent.Public);
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
fprintf (Gbl.F.Out,"<td colspan=\"2\" class=\"LEFT_TOP COLOR%u\">",
Gbl.RowEvenOdd);
fprintf (Gbl.F.Out,"<p class=\"%s\">"
"%s"
"</p>"
"</td>"
"</tr>",
2016-12-03 17:34:07 +01:00
AgdEvent.Public ? "DAT" :
"DAT_LIGHT",
2016-11-30 22:49:48 +01:00
Txt);
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/*********************** Write the author of an event ************************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
static void Agd_WriteEventAuthor (struct AgendaEvent *AgdEvent)
2016-11-30 22:49:48 +01:00
{
bool ShowPhoto = false;
char PhotoURL[PATH_MAX+1];
char FirstName[Usr_MAX_BYTES_NAME+1];
char Surnames[2*(Usr_MAX_BYTES_NAME+1)];
struct UsrData UsrDat;
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Get data of author *****/
2016-12-01 00:53:50 +01:00
UsrDat.UsrCod = AgdEvent->UsrCod;
2016-11-30 22:49:48 +01:00
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat))
ShowPhoto = Pho_ShowUsrPhotoIsAllowed (&UsrDat,PhotoURL);
/***** Show photo *****/
Pho_ShowUsrPhoto (&UsrDat,ShowPhoto ? PhotoURL :
NULL,
"PHOTO15x20",Pho_ZOOM,false);
/***** Write name *****/
strcpy (FirstName,UsrDat.FirstName);
strcpy (Surnames,UsrDat.Surname1);
if (UsrDat.Surname2[0])
{
strcat (Surnames," ");
strcat (Surnames,UsrDat.Surname2);
}
Str_LimitLengthHTMLStr (FirstName,9);
Str_LimitLengthHTMLStr (Surnames,9);
fprintf (Gbl.F.Out,"<span class=\"%s\">%s %s</span>",
2016-12-03 17:34:07 +01:00
AgdEvent->Public ? "MSG_AUT" :
"MSG_AUT_LIGHT",
2016-11-30 22:49:48 +01:00
FirstName,Surnames);
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/********* Get parameter with the type or order in list of events ************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
static void Agd_GetParamEventOrderType (void)
2016-11-30 22:49:48 +01:00
{
char UnsignedStr[10+1];
unsigned UnsignedNum;
Par_GetParToText ("Order",UnsignedStr,10);
if (sscanf (UnsignedStr,"%u",&UnsignedNum) == 1)
2016-12-02 10:45:53 +01:00
Gbl.Agenda.SelectedOrderType = (Agd_Order_t) UnsignedNum;
2016-11-30 22:49:48 +01:00
else
2016-12-02 10:45:53 +01:00
Gbl.Agenda.SelectedOrderType = Agd_DEFAULT_ORDER_TYPE;
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/****** Put a hidden parameter with the type of order in list of events ******/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
void Agd_PutHiddenParamEventsOrderType (void)
2016-11-30 22:49:48 +01:00
{
2016-12-02 00:24:16 +01:00
Par_PutHiddenParamUnsigned ("Order",(unsigned) Gbl.Agenda.SelectedOrderType);
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
/*****************************************************************************/
2016-12-03 17:34:07 +01:00
static void Agd_PutFormsToRemEditOneEvent (long AgdCod,bool Public)
2016-11-30 22:49:48 +01:00
{
extern const char *Txt_Remove;
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
extern const char *Txt_Edit;
fprintf (Gbl.F.Out,"<div>");
2016-12-02 00:24:16 +01:00
Gbl.Agenda.AgdCodToEdit = 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 *****/
2016-12-01 01:39:06 +01:00
Lay_PutContextualLink (ActReqRemEvtMyAgd,Agd_PutParams,
2016-11-30 22:49:48 +01:00
"remove-on64x64.png",
Txt_Remove,NULL,
NULL);
2016-12-01 00:53:50 +01:00
/***** Put form to edit event *****/
2016-12-01 01:39:06 +01:00
Lay_PutContextualLink (ActEdiOneEvtMyAgd,Agd_PutParams,
2016-11-30 22:49:48 +01:00
"edit64x64.png",
Txt_Edit,NULL,
NULL);
2016-12-03 17:34:07 +01:00
/***** Put form to hide/show event *****/
if (Gbl.Usrs.Me.AvailableRoles & (1 << Rol_TEACHER)) // I am a teacher in some courses
{
if (Public)
Lay_PutContextualLink (ActHidEvtMyAgd,Agd_PutParams,
"open_on16x16.gif",
Txt_Event_visible_to_the_users_of_your_courses_click_to_make_it_private,NULL,
NULL);
else
Lay_PutContextualLink (ActShoEvtMyAgd,Agd_PutParams,
"closed_on16x16.gif",
Txt_Event_private_click_to_make_it_visible_to_the_users_of_your_courses,NULL,
NULL);
}
2016-11-30 22:49:48 +01:00
fprintf (Gbl.F.Out,"</div>");
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/********************** Params used to edit an event *************************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
static void Agd_PutParams (void)
2016-11-30 22:49:48 +01:00
{
2016-12-02 00:24:16 +01:00
Agd_PutParamAgdCod (Gbl.Agenda.AgdCodToEdit);
2016-12-01 00:53:50 +01:00
Agd_PutHiddenParamEventsOrderType ();
2016-11-30 22:49:48 +01:00
Pag_PutHiddenParamPagNum (Gbl.Pag.CurrentPage);
}
/*****************************************************************************/
2016-12-02 00:24:16 +01:00
/************************* Get list of agenda events *************************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-02 00:24:16 +01:00
static void Agd_GetListEvents (Agd_AgendaType_t AgendaType)
2016-11-30 22:49:48 +01:00
{
char OrderBySubQuery[256];
char Query[2048];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
2016-12-02 00:24:16 +01:00
unsigned NumEvent;
2016-11-30 22:49:48 +01:00
2016-12-02 00:24:16 +01:00
if (Gbl.Agenda.LstIsRead)
2016-12-01 00:53:50 +01:00
Agd_FreeListEvents ();
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get list of events from database *****/
2016-12-02 00:24:16 +01:00
switch (Gbl.Agenda.SelectedOrderType)
2016-11-30 22:49:48 +01:00
{
2016-12-02 10:45:53 +01:00
case Agd_ORDER_BY_START_DATE:
2016-11-30 22:49:48 +01:00
sprintf (OrderBySubQuery,"StartTime DESC,EndTime DESC,Location DESC,Event DESC");
break;
2016-12-02 10:45:53 +01:00
case Agd_ORDER_BY_END_DATE:
2016-11-30 22:49:48 +01:00
sprintf (OrderBySubQuery,"EndTime DESC,StartTime DESC,Location DESC,Event DESC");
break;
}
2016-12-02 00:24:16 +01:00
switch (AgendaType)
{
case Agd_USR_AGENDA:
sprintf (Query,"SELECT AgdCod"
" FROM agendas"
2016-12-03 17:34:07 +01:00
" WHERE UsrCod='%ld' AND Public='Y'"
" AND EndTime>NOW()" // Only present and future events
2016-12-02 00:24:16 +01:00
" ORDER BY %s",
Gbl.Usrs.Other.UsrDat.UsrCod,OrderBySubQuery);
break;
case Agd_MY_AGENDA:
sprintf (Query,"SELECT AgdCod"
" FROM agendas"
" WHERE UsrCod='%ld'"
" ORDER BY %s",
Gbl.Usrs.Me.UsrDat.UsrCod,OrderBySubQuery);
break;
}
2016-12-01 00:53:50 +01:00
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get agenda events");
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
if (NumRows) // Events found...
2016-11-30 22:49:48 +01:00
{
2016-12-02 00:24:16 +01:00
Gbl.Agenda.Num = (unsigned) NumRows;
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Create list of events *****/
2016-12-02 00:24:16 +01:00
if ((Gbl.Agenda.LstAgdCods = (long *) calloc (NumRows,sizeof (long))) == NULL)
2016-12-01 00:53:50 +01:00
Lay_ShowErrorAndExit ("Not enough memory to store list of agenda events.");
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get the events codes *****/
2016-12-02 00:24:16 +01:00
for (NumEvent = 0;
NumEvent < Gbl.Agenda.Num;
NumEvent++)
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
/* Get next event code */
2016-11-30 22:49:48 +01:00
row = mysql_fetch_row (mysql_res);
2016-12-02 00:24:16 +01:00
if ((Gbl.Agenda.LstAgdCods[NumEvent] = Str_ConvertStrCodToLongCod (row[0])) < 0)
2016-12-01 00:53:50 +01:00
Lay_ShowErrorAndExit ("Error: wrong event code.");
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
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
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
{
char Query[1024];
/***** Build query *****/
2016-12-03 17:34:07 +01:00
sprintf (Query,"SELECT AgdCod,UsrCod,Public,"
2016-11-30 22:49:48 +01:00
"UNIX_TIMESTAMP(StartTime),"
"UNIX_TIMESTAMP(EndTime),"
2016-12-02 10:45:53 +01:00
"NOW()>EndTime," // Past event?
"NOW()<StartTime," // Future event?
2016-12-01 01:39:06 +01:00
"Event,Location"
" FROM agendas"
2016-12-01 00:53:50 +01:00
" WHERE AgdCod='%ld' AND UsrCod='%ld'",
2016-12-02 00:24:16 +01:00
AgdEvent->AgdCod,AgdEvent->UsrCod);
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Get data of event *****/
Agd_GetDataOfEvent (AgdEvent,Query);
2016-11-30 22:49:48 +01:00
}
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
/****************************** Get event data *******************************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
static void Agd_GetDataOfEvent (struct AgendaEvent *AgdEvent,const char *Query)
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
/***** Clear all event data *****/
AgdEvent->AgdCod = -1L;
AgdEvent->UsrCod = -1L;
2016-12-03 17:34:07 +01:00
AgdEvent->Public = false;
2016-12-02 10:45:53 +01:00
AgdEvent->TimeUTC[Agd_START_TIME] =
AgdEvent->TimeUTC[Agd_END_TIME ] = (time_t) 0;
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
2016-12-01 00:53:50 +01:00
/***** Get data of event from database *****/
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get agenda event data");
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
if (NumRows) // Event found...
2016-11-30 22:49:48 +01:00
{
2016-12-02 10:45:53 +01:00
/* Get row:
row[0] AgdCod
row[1] UsrCod
2016-12-03 17:34:07 +01:00
row[2] Public
2016-12-02 10:45:53 +01:00
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-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-01 00:53:50 +01:00
/* Get author of the event (row[1]) */
AgdEvent->UsrCod = Str_ConvertStrCodToLongCod (row[1]);
2016-11-30 22:49:48 +01:00
2016-12-03 17:34:07 +01:00
/* Get whether the event is public or not (row[2]) */
AgdEvent->Public = (row[2][0] == 'Y');
2016-11-30 22:49:48 +01:00
/* Get start date (row[3] holds the start UTC time) */
2016-12-02 10:45:53 +01:00
AgdEvent->TimeUTC[Agd_START_TIME] = Dat_GetUNIXTimeFromStr (row[3]);
2016-11-30 22:49:48 +01:00
/* Get end date (row[4] holds the end UTC time) */
2016-12-02 10:45:53 +01:00
AgdEvent->TimeUTC[Agd_END_TIME ] = Dat_GetUNIXTimeFromStr (row[4]);
2016-11-30 22:49:48 +01:00
2016-12-02 10:45:53 +01:00
/* Get whether the event is past, present or futur (row(5), row[6]) */
AgdEvent->TimeStatus = ((row[5][0] == '1') ? Dat_PAST :
((row[6][0] == '1') ? Dat_FUTURE :
Dat_PRESENT));
2016-11-30 22:49:48 +01:00
/* Get the event (row[7]) */
2016-12-02 10:45:53 +01:00
strcpy (AgdEvent->Event,row[7]);
/* Get the event (row[8]) */
strcpy (AgdEvent->Location,row[8]);
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
/*****************************************************************************/
2016-12-02 00:24:16 +01:00
static void Agd_GetEventTxtFromDB (struct AgendaEvent *AgdEvent,char *Txt)
2016-11-30 22:49:48 +01:00
{
char Query[512];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
2016-12-01 00:53:50 +01:00
/***** Get text of event from database *****/
2016-12-01 01:39:06 +01:00
sprintf (Query,"SELECT Txt FROM agendas"
2016-12-01 00:53:50 +01:00
" WHERE AgdCod='%ld' AND UsrCod='%ld'",
2016-12-02 00:24:16 +01:00
AgdEvent->AgdCod,AgdEvent->UsrCod);
2016-12-01 00:53:50 +01:00
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get event text");
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);
strcpy (Txt,row[0]);
}
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
/******************* Write parameter with code of event **********************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
static void Agd_PutParamAgdCod (long AgdCod)
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
Par_PutHiddenParamLong ("AgdCod",AgdCod);
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
{
char LongStr[1+10+1];
2016-12-01 00:53:50 +01:00
/***** Get parameter with code of event *****/
Par_GetParToText ("AgdCod",LongStr,1+10);
2016-11-30 22:49:48 +01:00
return Str_ConvertStrCodToLongCod (LongStr);
}
/*****************************************************************************/
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 *****/
2016-12-01 00:53:50 +01:00
Agd_GetParamEventOrderType ();
2016-12-02 00:24:16 +01:00
Pag_GetParamPagNum (Pag_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
/***** Button of confirmation of removing *****/
2016-12-01 01:39:06 +01:00
Act_FormStart (ActRemEvtMyAgd);
2016-12-01 00:53:50 +01:00
Agd_PutParamAgdCod (AgdEvent.AgdCod);
Agd_PutHiddenParamEventsOrderType ();
2016-11-30 22:49:48 +01:00
Pag_PutHiddenParamPagNum (Gbl.Pag.CurrentPage);
/***** Ask for confirmation of removing *****/
2016-12-01 00:53:50 +01:00
sprintf (Gbl.Message,Txt_Do_you_really_want_to_remove_the_event_X,
AgdEvent.Event);
2016-11-30 22:49:48 +01:00
Lay_ShowAlert (Lay_WARNING,Gbl.Message);
2016-12-01 00:53:50 +01:00
Lay_PutRemoveButton (Txt_Remove_event);
2016-11-30 22:49:48 +01:00
Act_FormEnd ();
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-11-30 22:49:48 +01:00
char Query[512];
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); // Inside this function, the course is checked to be the current one
2016-11-30 22:49:48 +01:00
2016-12-01 00:53:50 +01:00
/***** Remove event *****/
2016-12-01 01:39:06 +01:00
sprintf (Query,"DELETE FROM agendas"
2016-12-01 00:53:50 +01:00
" WHERE AgdCod='%ld' AND UsrCod='%ld'",
AgdEvent.AgdCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryDELETE (Query,"can not remove event");
2016-11-30 22:49:48 +01:00
/***** Write message to show the change made *****/
2016-12-01 01:39:06 +01:00
sprintf (Gbl.Message,Txt_Event_X_removed,AgdEvent.Event);
2016-11-30 22:49:48 +01:00
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
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 17:34:07 +01:00
/****************************** Set event private ****************************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-03 17:34:07 +01:00
void Agd_SetEventPrivate (void)
2016-11-30 22:49:48 +01:00
{
2016-12-01 16:49:12 +01:00
extern const char *Txt_Event_X_is_now_private;
2016-11-30 22:49:48 +01:00
char Query[512];
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 *****/
sprintf (Query,"UPDATE agendas SET Public='N'"
2016-12-01 00:53:50 +01:00
" WHERE AgdCod='%ld' AND UsrCod='%ld'",
AgdEvent.AgdCod,Gbl.Usrs.Me.UsrDat.UsrCod);
2016-12-03 17:34:07 +01:00
DB_QueryUPDATE (Query,"can not set event as private");
2016-11-30 22:49:48 +01:00
/***** Write message to show the change made *****/
2016-12-01 16:49:12 +01:00
sprintf (Gbl.Message,Txt_Event_X_is_now_private,AgdEvent.Event);
2016-11-30 22:49:48 +01:00
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
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 17:34:07 +01:00
/********* Set event public (make it visible to users of my courses) *********/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-03 17:34:07 +01:00
void Agd_SetEventPublic (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 16:49:12 +01:00
char Query[256];
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 public *****/
sprintf (Query,"UPDATE agendas SET Public='Y'"
2016-12-01 00:53:50 +01:00
" WHERE AgdCod='%ld' AND UsrCod='%ld'",
AgdEvent.AgdCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE (Query,"can not show event");
2016-11-30 22:49:48 +01:00
/***** Write message to show the change made *****/
2016-12-01 19:28:52 +01:00
sprintf (Gbl.Message,Txt_Event_X_is_now_visible_to_users_of_your_courses,
2016-12-01 16:49:12 +01:00
AgdEvent.Event);
2016-11-30 22:49:48 +01:00
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
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
/*********** Check if the title or the folder of an event exists *************/
2016-11-30 22:49:48 +01:00
/*****************************************************************************/
2016-12-01 00:53:50 +01:00
static bool Agd_CheckIfSimilarEventExists (const char *Field,const char *Value,long AgdCod)
2016-11-30 22:49:48 +01:00
{
char Query[512];
2016-12-01 00:53:50 +01:00
/***** Get number of events with a field value from database *****/
2016-12-01 01:39:06 +01:00
sprintf (Query,"SELECT COUNT(*) FROM agendas"
2016-12-01 00:53:50 +01:00
" WHERE UsrCod='%ld' AND %s='%s' AND AgdCod<>'%ld'",
Gbl.Usrs.Me.UsrDat.UsrCod,Field,Value,AgdCod);
return (DB_QueryCOUNT (Query,"can not get similar events") != 0);
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 *The_ClassForm[The_NUM_THEMES];
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;
extern const char *Txt_Save;
2016-12-01 00:53:50 +01:00
struct AgendaEvent AgdEvent;
bool ItsANewEvent;
2016-11-30 22:49:48 +01:00
char Txt[Cns_MAX_BYTES_TEXT+1];
/***** Get parameters *****/
2016-12-01 00:53:50 +01:00
Agd_GetParamEventOrderType ();
2016-12-02 00:24:16 +01:00
Pag_GetParamPagNum (Pag_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 *****/
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.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
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-02 00:24:16 +01:00
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
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)
2016-12-01 01:39:06 +01:00
Act_FormStart (ActNewEvtMyAgd);
2016-11-30 22:49:48 +01:00
else
{
2016-12-01 01:39:06 +01:00
Act_FormStart (ActChgEvtMyAgd);
2016-12-01 00:53:50 +01:00
Agd_PutParamAgdCod (AgdEvent.AgdCod);
2016-11-30 22:49:48 +01:00
}
2016-12-01 00:53:50 +01:00
Agd_PutHiddenParamEventsOrderType ();
2016-11-30 22:49:48 +01:00
Pag_PutHiddenParamPagNum (Gbl.Pag.CurrentPage);
/***** Table start *****/
Lay_StartRoundFrameTable (NULL,
2016-12-01 00:53:50 +01:00
ItsANewEvent ? Txt_New_event :
Txt_Edit_event,
2016-11-30 22:49:48 +01:00
NULL,
2016-12-01 00:53:50 +01:00
ItsANewEvent ? Hlp_PROFILE_Agenda_new_event :
Hlp_PROFILE_Agenda_edit_event,
2016-11-30 22:49:48 +01:00
2);
2016-12-01 00:53:50 +01:00
/***** Event *****/
2016-11-30 22:49:48 +01:00
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"%s RIGHT_MIDDLE\">"
"%s:"
"</td>"
"<td class=\"LEFT_MIDDLE\">"
2016-12-01 00:53:50 +01:00
"<input type=\"text\" name=\"Event\""
2016-11-30 22:49:48 +01:00
" size=\"45\" maxlength=\"%u\" value=\"%s\""
" required=\"required\" />"
"</td>"
"</tr>",
The_ClassForm[Gbl.Prefs.Theme],
2016-12-01 00:53:50 +01:00
Txt_Event,
2016-12-02 10:45:53 +01:00
Agd_MAX_LENGTH_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>"
"<td class=\"%s RIGHT_MIDDLE\">"
"%s:"
"</td>"
"<td class=\"LEFT_MIDDLE\">"
2016-12-01 00:53:50 +01:00
"<input type=\"text\" name=\"Location\""
2016-11-30 22:49:48 +01:00
" size=\"45\" maxlength=\"%u\" value=\"%s\""
" required=\"required\" />"
"</td>"
"</tr>",
The_ClassForm[Gbl.Prefs.Theme],
2016-12-01 00:53:50 +01:00
Txt_Location,
2016-12-02 10:45:53 +01:00
Agd_MAX_LENGTH_LOCATION,AgdEvent.Location);
2016-11-30 22:49:48 +01:00
/***** Start and end dates *****/
2016-12-01 00:53:50 +01:00
Dat_PutFormStartEndClientLocalDateTimes (AgdEvent.TimeUTC);
2016-11-30 22:49:48 +01:00
/***** Text *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"%s RIGHT_TOP\">"
"%s:"
"</td>"
"<td class=\"LEFT_TOP\">"
"<textarea name=\"Txt\" cols=\"60\" rows=\"10\">",
The_ClassForm[Gbl.Prefs.Theme],
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>");
2016-12-01 00:53:50 +01:00
/***** New event *****/
if (ItsANewEvent)
2016-11-30 22:49:48 +01:00
Lay_EndRoundFrameTableWithButton (Lay_CREATE_BUTTON,Txt_Create_event);
else
Lay_EndRoundFrameTableWithButton (Lay_CONFIRM_BUTTON,Txt_Save);
Act_FormEnd ();
2016-12-01 00:53:50 +01:00
/***** Show current events, if any *****/
2016-12-02 00:24:16 +01:00
Agd_ShowEvents (Agd_MY_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
/*****************************************************************************/
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_Already_existed_an_event_with_the_title_X;
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-02 00:24:16 +01:00
struct AgendaEvent OldAgdEvent;
struct AgendaEvent NewAgdEvent;
2016-12-01 00:53:50 +01:00
bool ItsANewEvent;
bool NewEventIsCorrect = true;
2016-11-30 22:49:48 +01:00
char Txt[Cns_MAX_BYTES_TEXT+1];
2016-12-01 00:53:50 +01:00
/***** Get the code of the event *****/
2016-12-02 00:24:16 +01:00
ItsANewEvent = ((NewAgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L);
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
{
2016-12-01 00:53:50 +01:00
/* Get data of the old (current) event from database */
2016-12-02 00:24:16 +01:00
OldAgdEvent.AgdCod = NewAgdEvent.AgdCod;
OldAgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
Agd_GetDataOfEventByCod (&OldAgdEvent);
2016-11-30 22:49:48 +01:00
}
/***** Get start/end date-times *****/
2016-12-02 10:45:53 +01:00
NewAgdEvent.TimeUTC[Agd_START_TIME] = Dat_GetTimeUTCFromForm ("StartTimeUTC");
NewAgdEvent.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 *****/
2016-12-02 10:45:53 +01:00
Par_GetParToText ("Location",NewAgdEvent.Location,Agd_MAX_LENGTH_LOCATION);
2016-11-30 22:49:48 +01:00
/***** Get event *****/
2016-12-02 10:45:53 +01:00
Par_GetParToText ("Event",NewAgdEvent.Event,Agd_MAX_LENGTH_EVENT);
2016-11-30 22:49:48 +01:00
/***** Get text *****/
Par_GetParToHTML ("Txt",Txt,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous)
/***** Adjust dates *****/
2016-12-02 10:45:53 +01:00
if (NewAgdEvent.TimeUTC[Agd_START_TIME] == 0)
NewAgdEvent.TimeUTC[Agd_START_TIME] = Gbl.StartExecutionTimeUTC;
if (NewAgdEvent.TimeUTC[Agd_END_TIME] == 0)
NewAgdEvent.TimeUTC[Agd_END_TIME] = NewAgdEvent.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-02 00:24:16 +01:00
if (!NewAgdEvent.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;
Lay_ShowAlert (Lay_WARNING,Txt_You_must_specify_the_title_of_the_event);
2016-11-30 22:49:48 +01:00
}
/***** Check if event is correct *****/
2016-12-02 00:24:16 +01:00
if (NewAgdEvent.Event[0]) // If there's event
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
/* If title of event was in database... */
2016-12-02 00:24:16 +01:00
if (Agd_CheckIfSimilarEventExists ("Event",NewAgdEvent.Event,NewAgdEvent.AgdCod))
2016-11-30 22:49:48 +01:00
{
2016-12-01 00:53:50 +01:00
NewEventIsCorrect = false;
sprintf (Gbl.Message,Txt_Already_existed_an_event_with_the_title_X,
2016-12-02 00:24:16 +01:00
NewAgdEvent.Event);
2016-11-30 22:49:48 +01:00
Lay_ShowAlert (Lay_WARNING,Gbl.Message);
}
}
else // If there is no event
{
2016-12-01 00:53:50 +01:00
NewEventIsCorrect = false;
Lay_ShowAlert (Lay_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
{
2016-12-02 00:24:16 +01:00
Agd_CreateEvent (&NewAgdEvent,Txt); // Add new event to database
2016-11-30 22:49:48 +01:00
/***** Write success message *****/
2016-12-02 00:24:16 +01:00
sprintf (Gbl.Message,Txt_Created_new_event_X,NewAgdEvent.Event);
2016-11-30 22:49:48 +01:00
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
}
else
{
2016-12-02 00:24:16 +01:00
Agd_UpdateEvent (&NewAgdEvent,Txt);
2016-11-30 22:49:48 +01:00
/***** Write success message *****/
Lay_ShowAlert (Lay_SUCCESS,Txt_The_event_has_been_modified);
}
/* 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
{
char Query[1024+Cns_MAX_BYTES_TEXT];
2016-12-01 00:53:50 +01:00
/***** Create a new event *****/
2016-12-01 01:39:06 +01:00
sprintf (Query,"INSERT INTO agendas"
" (UsrCod,StartTime,EndTime,Event,Location,Txt)"
2016-11-30 22:49:48 +01:00
" VALUES"
" ('%ld',FROM_UNIXTIME('%ld'),FROM_UNIXTIME('%ld'),"
"'%s','%s','%s')",
Gbl.Usrs.Me.UsrDat.UsrCod,
2016-12-02 10:45:53 +01:00
AgdEvent->TimeUTC[Agd_START_TIME],
AgdEvent->TimeUTC[Agd_END_TIME ],
2016-12-01 00:53:50 +01:00
AgdEvent->Event,
2016-12-01 01:39:06 +01:00
AgdEvent->Location,
2016-11-30 22:49:48 +01:00
Txt);
2016-12-01 00:53:50 +01:00
AgdEvent->AgdCod = DB_QueryINSERTandReturnCode (Query,"can not create new event");
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
{
char Query[1024+Cns_MAX_BYTES_TEXT];
2016-12-01 00:53:50 +01:00
/***** Update the data of the event *****/
2016-12-01 01:39:06 +01:00
sprintf (Query,"UPDATE agendas SET "
2016-11-30 22:49:48 +01:00
"StartTime=FROM_UNIXTIME('%ld'),"
"EndTime=FROM_UNIXTIME('%ld'),"
2016-12-01 01:39:06 +01:00
"Event='%s',Location='%s',Txt='%s'"
2016-12-01 00:53:50 +01:00
" WHERE AgdCod='%ld' AND UsrCod='%ld'",
2016-12-02 10:45:53 +01:00
AgdEvent->TimeUTC[Agd_START_TIME],
AgdEvent->TimeUTC[Agd_END_TIME ],
2016-12-01 01:39:06 +01:00
AgdEvent->Event,AgdEvent->Location,Txt,
2016-12-01 00:53:50 +01:00
AgdEvent->AgdCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE (Query,"can not update event");
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
{
char Query[128];
2016-12-01 00:53:50 +01:00
/***** Remove events *****/
2016-12-01 01:39:06 +01:00
sprintf (Query,"DELETE FROM agendas WHERE UsrCod='%ld'",UsrCod);
2016-12-01 00:53:50 +01:00
DB_QueryDELETE (Query,"can not remove all the events of a user");
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
{
char Query[128];
2016-12-01 00:53:50 +01:00
/***** Get number of events in a course from database *****/
2016-12-01 01:39:06 +01:00
sprintf (Query,"SELECT COUNT(*) FROM agendas WHERE UsrCod='%ld'",
2016-11-30 22:49:48 +01:00
UsrCod);
2016-12-01 00:53:50 +01:00
return (unsigned) DB_QueryCOUNT (Query,"can not get number of events from user");
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
2016-12-01 00:53:50 +01:00
unsigned Agd_GetNumUsrsWithEvents (Sco_Scope_t Scope)
2016-11-30 22:49:48 +01:00
{
char Query[1024];
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)
{
case Sco_SCOPE_SYS:
sprintf (Query,"SELECT COUNT(DISTINCT UsrCod)"
2016-12-01 01:39:06 +01:00
" FROM agendas"
2016-11-30 22:49:48 +01:00
" WHERE UsrCod>'0'");
break;
case Sco_SCOPE_CTY:
2016-12-01 01:39:06 +01:00
sprintf (Query,"SELECT COUNT(DISTINCT agendas.UsrCod)"
" FROM institutions,centres,degrees,courses,crs_usr,agendas"
2016-11-30 22:49:48 +01:00
" 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"
2016-12-01 01:39:06 +01:00
" AND crs_usr.UsrCod=agendas.UsrCod",
2016-11-30 22:49:48 +01:00
Gbl.CurrentCty.Cty.CtyCod);
break;
case Sco_SCOPE_INS:
2016-12-01 01:39:06 +01:00
sprintf (Query,"SELECT COUNT(DISTINCT agendas.UsrCod)"
" FROM centres,degrees,courses,crs_usr,agendas"
2016-11-30 22:49:48 +01:00
" WHERE centres.InsCod='%ld'"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=crs_usr.CrsCod"
2016-12-01 01:39:06 +01:00
" AND crs_usr.UsrCod=agendas.UsrCod",
2016-11-30 22:49:48 +01:00
Gbl.CurrentIns.Ins.InsCod);
break;
case Sco_SCOPE_CTR:
2016-12-01 01:39:06 +01:00
sprintf (Query,"SELECT COUNT(DISTINCT agendas.UsrCod)"
" FROM degrees,courses,crs_usr,agendas"
2016-11-30 22:49:48 +01:00
" WHERE degrees.CtrCod='%ld'"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=crs_usr.CrsCod"
2016-12-01 01:39:06 +01:00
" AND crs_usr.UsrCod=agendas.UsrCod",
2016-11-30 22:49:48 +01:00
Gbl.CurrentCtr.Ctr.CtrCod);
break;
case Sco_SCOPE_DEG:
2016-12-01 01:39:06 +01:00
sprintf (Query,"SELECT COUNT(DISTINCT agendas.UsrCod)"
" FROM courses,crs_usr,agendas"
2016-11-30 22:49:48 +01:00
" WHERE courses.DegCod='%ld'"
" AND courses.Status=0"
" AND courses.CrsCod=crs_usr.CrsCod"
2016-12-01 01:39:06 +01:00
" AND crs_usr.UsrCod=agendas.UsrCod",
2016-11-30 22:49:48 +01:00
Gbl.CurrentDeg.Deg.DegCod);
break;
case Sco_SCOPE_CRS:
2016-12-01 01:39:06 +01:00
sprintf (Query,"SELECT COUNT(DISTINCT agendas.UsrCod)"
" FROM crs_usr,agendas"
2016-11-30 22:49:48 +01:00
" WHERE crs_usr.CrsCod='%ld'"
2016-12-01 01:39:06 +01:00
" AND crs_usr.UsrCod=agendas.UsrCod",
2016-11-30 22:49:48 +01:00
Gbl.CurrentCrs.Crs.CrsCod);
break;
default:
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
2016-12-01 00:53:50 +01:00
DB_QuerySELECT (Query,&mysql_res,"can not get number of users with events");
2016-11-30 22:49:48 +01:00
/***** 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
2016-12-01 00:53:50 +01:00
unsigned Agd_GetNumEvents (Sco_Scope_t Scope)
2016-11-30 22:49:48 +01:00
{
char Query[1024];
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)
{
case Sco_SCOPE_SYS:
sprintf (Query,"SELECT COUNT(*)"
2016-12-01 01:39:06 +01:00
" FROM agendas"
2016-11-30 22:49:48 +01:00
" WHERE UsrCod>'0'");
break;
case Sco_SCOPE_CTY:
sprintf (Query,"SELECT COUNT(*)"
2016-12-01 01:39:06 +01:00
" FROM institutions,centres,degrees,courses,crs_usr,agendas"
2016-11-30 22:49:48 +01:00
" 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"
2016-12-01 01:39:06 +01:00
" AND crs_usr.UsrCod=agendas.UsrCod",
2016-11-30 22:49:48 +01:00
Gbl.CurrentCty.Cty.CtyCod);
break;
case Sco_SCOPE_INS:
sprintf (Query,"SELECT COUNT(*)"
2016-12-01 01:39:06 +01:00
" FROM centres,degrees,courses,crs_usr,agendas"
2016-11-30 22:49:48 +01:00
" WHERE centres.InsCod='%ld'"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
2016-12-01 01:39:06 +01:00
" AND crs_usr.UsrCod=agendas.UsrCod",
2016-11-30 22:49:48 +01:00
Gbl.CurrentIns.Ins.InsCod);
break;
case Sco_SCOPE_CTR:
sprintf (Query,"SELECT COUNT(*)"
2016-12-01 01:39:06 +01:00
" FROM degrees,courses,crs_usr,agendas"
2016-11-30 22:49:48 +01:00
" WHERE degrees.CtrCod='%ld'"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
2016-12-01 01:39:06 +01:00
" AND crs_usr.UsrCod=agendas.UsrCod",
2016-11-30 22:49:48 +01:00
Gbl.CurrentCtr.Ctr.CtrCod);
break;
case Sco_SCOPE_DEG:
sprintf (Query,"SELECT COUNT(*)"
2016-12-01 01:39:06 +01:00
" FROM courses,crs_usr,agendas"
2016-11-30 22:49:48 +01:00
" WHERE courses.DegCod='%ld'"
" AND courses.CrsCod=crs_usr.CrsCod"
2016-12-01 01:39:06 +01:00
" AND crs_usr.UsrCod=agendas.UsrCod",
2016-11-30 22:49:48 +01:00
Gbl.CurrentDeg.Deg.DegCod);
break;
case Sco_SCOPE_CRS:
sprintf (Query,"SELECT COUNT(*)"
2016-12-01 01:39:06 +01:00
" FROM crs_usr,agendas"
2016-11-30 22:49:48 +01:00
" WHERE crs_usr.CrsCod='%ld'"
2016-12-01 01:39:06 +01:00
" AND crs_usr.UsrCod=agendas.UsrCod",
2016-11-30 22:49:48 +01:00
Gbl.CurrentCrs.Crs.CrsCod);
break;
default:
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
2016-12-01 00:53:50 +01:00
DB_QuerySELECT (Query,&mysql_res,"can not get number of events");
2016-11-30 22:49:48 +01:00
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
}