mirror of https://github.com/acanas/swad-core.git
Version 20.73: May 10, 2021 New module swad_agenda_database for database queries related to agenda.
This commit is contained in:
parent
39dc3d39a3
commit
701a479e04
4
Makefile
4
Makefile
|
@ -27,8 +27,8 @@
|
|||
###############################################################################
|
||||
|
||||
OBJS = swad_account.o swad_account_database.o swad_action.o swad_agenda.o \
|
||||
swad_alert.o swad_announcement.o swad_API.o swad_assignment.o \
|
||||
swad_attendance.o \
|
||||
swad_agenda_database.o swad_alert.o swad_announcement.o swad_API.o \
|
||||
swad_assignment.o swad_attendance.o \
|
||||
swad_banner.o swad_box.o swad_building.o swad_button.o \
|
||||
swad_calendar.o swad_call_for_exam.o swad_center.o \
|
||||
swad_center_config.o swad_chat.o swad_config.o swad_connected.o \
|
||||
|
|
112
swad_account.c
112
swad_account.c
|
@ -29,7 +29,7 @@
|
|||
|
||||
#include "swad_account.h"
|
||||
#include "swad_account_database.h"
|
||||
#include "swad_agenda.h"
|
||||
#include "swad_agenda_database.h"
|
||||
#include "swad_announcement.h"
|
||||
#include "swad_attendance.h"
|
||||
#include "swad_box.h"
|
||||
|
@ -157,23 +157,23 @@ static void Acc_ShowFormCheckIfIHaveAccount (const char *Title)
|
|||
NULL,NULL,
|
||||
Hlp_PROFILE_SignUp,Box_NOT_CLOSABLE);
|
||||
|
||||
/***** Help alert *****/
|
||||
Ale_ShowAlert (Ale_INFO,Txt_If_you_think_you_may_have_been_registered_);
|
||||
/***** Help alert *****/
|
||||
Ale_ShowAlert (Ale_INFO,Txt_If_you_think_you_may_have_been_registered_);
|
||||
|
||||
/***** Form to request user's ID for possible account already created *****/
|
||||
Frm_BeginForm (ActChkUsrAcc);
|
||||
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
|
||||
HTM_TxtColonNBSP (Txt_ID);
|
||||
HTM_INPUT_TEXT ("ID",ID_MAX_CHARS_USR_ID,"",HTM_DONT_SUBMIT_ON_CHANGE,
|
||||
"size=\"18\" required=\"required\"");
|
||||
HTM_LABEL_End ();
|
||||
Btn_PutCreateButtonInline (Txt_Check);
|
||||
Frm_EndForm ();
|
||||
/***** Form to request user's ID for possible account already created *****/
|
||||
Frm_BeginForm (ActChkUsrAcc);
|
||||
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
|
||||
HTM_TxtColonNBSP (Txt_ID);
|
||||
HTM_INPUT_TEXT ("ID",ID_MAX_CHARS_USR_ID,"",HTM_DONT_SUBMIT_ON_CHANGE,
|
||||
"size=\"18\" required=\"required\"");
|
||||
HTM_LABEL_End ();
|
||||
Btn_PutCreateButtonInline (Txt_Check);
|
||||
Frm_EndForm ();
|
||||
|
||||
/***** Form to skip this step *****/
|
||||
Frm_BeginForm (ActCreMyAcc);
|
||||
Btn_PutConfirmButton (Txt_Skip_this_step);
|
||||
Frm_EndForm ();
|
||||
/***** Form to skip this step *****/
|
||||
Frm_BeginForm (ActCreMyAcc);
|
||||
Btn_PutConfirmButton (Txt_Skip_this_step);
|
||||
Frm_EndForm ();
|
||||
|
||||
/***** End box *****/
|
||||
Box_BoxEnd ();
|
||||
|
@ -199,9 +199,9 @@ void Acc_CheckIfEmptyAccountExists (void)
|
|||
|
||||
/***** Contextual menu *****/
|
||||
Mnu_ContextMenuBegin ();
|
||||
Usr_PutLinkToLogin ();
|
||||
Pwd_PutLinkToSendNewPasswd ();
|
||||
Lan_PutLinkToChangeLanguage ();
|
||||
Usr_PutLinkToLogin ();
|
||||
Pwd_PutLinkToSendNewPasswd ();
|
||||
Lan_PutLinkToChangeLanguage ();
|
||||
Mnu_ContextMenuEnd ();
|
||||
|
||||
/***** Get new user's ID from form *****/
|
||||
|
@ -341,9 +341,9 @@ void Acc_ShowFormCreateMyAccount (void)
|
|||
{
|
||||
/***** Contextual menu *****/
|
||||
Mnu_ContextMenuBegin ();
|
||||
Usr_PutLinkToLogin ();
|
||||
Pwd_PutLinkToSendNewPasswd ();
|
||||
Lan_PutLinkToChangeLanguage ();
|
||||
Usr_PutLinkToLogin ();
|
||||
Pwd_PutLinkToSendNewPasswd ();
|
||||
Lan_PutLinkToChangeLanguage ();
|
||||
Mnu_ContextMenuEnd ();
|
||||
|
||||
/**** Show form to create a new account *****/
|
||||
|
@ -374,46 +374,50 @@ static void Acc_ShowFormRequestNewAccountWithParams (const char NewNickWithoutAr
|
|||
NULL,NULL,
|
||||
Hlp_PROFILE_SignUp,Box_NOT_CLOSABLE,2);
|
||||
|
||||
/***** Nickname *****/
|
||||
if (NewNickWithoutArr[0])
|
||||
snprintf (NewNickWithArr,sizeof (NewNickWithArr),"@%s",
|
||||
NewNickWithoutArr);
|
||||
else
|
||||
NewNickWithArr[0] = '\0';
|
||||
HTM_TR_Begin (NULL);
|
||||
/***** Nickname *****/
|
||||
/* Begin table row */
|
||||
HTM_TR_Begin (NULL);
|
||||
|
||||
/* Label */
|
||||
Frm_LabelColumn ("RT","NewNick",Txt_Nickname);
|
||||
/* Label */
|
||||
Frm_LabelColumn ("RT","NewNick",Txt_Nickname);
|
||||
|
||||
/* Data */
|
||||
HTM_TD_Begin ("class=\"LT\"");
|
||||
HTM_INPUT_TEXT ("NewNick",1 + Nck_MAX_CHARS_NICK_WITHOUT_ARROBA,
|
||||
NewNickWithArr,HTM_DONT_SUBMIT_ON_CHANGE,
|
||||
"id=\"NewNick\" size=\"18\" placeholder=\"%s\""
|
||||
" required=\"required\"",
|
||||
Txt_HELP_nickname);
|
||||
HTM_TD_End ();
|
||||
/* Data */
|
||||
HTM_TD_Begin ("class=\"LT\"");
|
||||
if (NewNickWithoutArr[0])
|
||||
snprintf (NewNickWithArr,sizeof (NewNickWithArr),"@%s",
|
||||
NewNickWithoutArr);
|
||||
else
|
||||
NewNickWithArr[0] = '\0';
|
||||
HTM_INPUT_TEXT ("NewNick",1 + Nck_MAX_CHARS_NICK_WITHOUT_ARROBA,
|
||||
NewNickWithArr,HTM_DONT_SUBMIT_ON_CHANGE,
|
||||
"id=\"NewNick\" size=\"18\" placeholder=\"%s\""
|
||||
" required=\"required\"",
|
||||
Txt_HELP_nickname);
|
||||
HTM_TD_End ();
|
||||
|
||||
HTM_TR_End ();
|
||||
/* End table row */
|
||||
HTM_TR_End ();
|
||||
|
||||
/***** Email *****/
|
||||
HTM_TR_Begin (NULL);
|
||||
/***** Email *****/
|
||||
/* Begin table row */
|
||||
HTM_TR_Begin (NULL);
|
||||
|
||||
/* Label */
|
||||
Frm_LabelColumn ("RT","NewEmail",Txt_Email);
|
||||
/* Label */
|
||||
Frm_LabelColumn ("RT","NewEmail",Txt_Email);
|
||||
|
||||
/* Data */
|
||||
HTM_TD_Begin ("class=\"LT\"");
|
||||
HTM_INPUT_EMAIL ("NewEmail",Cns_MAX_CHARS_EMAIL_ADDRESS,NewEmail,
|
||||
"id=\"NewEmail\" size=\"18\" placeholder=\"%s\""
|
||||
" required=\"required\"",
|
||||
Txt_HELP_email);
|
||||
HTM_TD_End ();
|
||||
/* Data */
|
||||
HTM_TD_Begin ("class=\"LT\"");
|
||||
HTM_INPUT_EMAIL ("NewEmail",Cns_MAX_CHARS_EMAIL_ADDRESS,NewEmail,
|
||||
"id=\"NewEmail\" size=\"18\" placeholder=\"%s\""
|
||||
" required=\"required\"",
|
||||
Txt_HELP_email);
|
||||
HTM_TD_End ();
|
||||
|
||||
HTM_TR_End ();
|
||||
/* End table row */
|
||||
HTM_TR_End ();
|
||||
|
||||
/***** Password *****/
|
||||
Pwd_PutFormToGetNewPasswordOnce ();
|
||||
/***** Password *****/
|
||||
Pwd_PutFormToGetNewPasswordOnce ();
|
||||
|
||||
/***** End table, send button and end box *****/
|
||||
Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_account);
|
||||
|
|
|
@ -25,37 +25,10 @@
|
|||
/*********************************** Headers *********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
// #include <string.h> // For string functions
|
||||
|
||||
#include "swad_account.h"
|
||||
#include "swad_account_database.h"
|
||||
// #include "swad_agenda.h"
|
||||
// #include "swad_announcement.h"
|
||||
// #include "swad_attendance.h"
|
||||
// #include "swad_box.h"
|
||||
#include "swad_calendar.h"
|
||||
// #include "swad_database.h"
|
||||
// #include "swad_duplicate.h"
|
||||
// #include "swad_enrolment.h"
|
||||
// #include "swad_error.h"
|
||||
// #include "swad_exam_print.h"
|
||||
// #include "swad_follow.h"
|
||||
// #include "swad_form.h"
|
||||
// #include "swad_forum.h"
|
||||
#include "swad_global.h"
|
||||
// #include "swad_HTML.h"
|
||||
// #include "swad_ID.h"
|
||||
// #include "swad_language.h"
|
||||
// #include "swad_match.h"
|
||||
// #include "swad_message.h"
|
||||
// #include "swad_nickname.h"
|
||||
// #include "swad_notification.h"
|
||||
// #include "swad_parameter.h"
|
||||
// #include "swad_profile.h"
|
||||
// #include "swad_project.h"
|
||||
// #include "swad_report.h"
|
||||
// #include "swad_test_print.h"
|
||||
// #include "swad_timeline.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************************** Public constants *****************************/
|
||||
|
@ -131,7 +104,6 @@ bool Acc_DB_CheckIfEmailAlreadyExists (const char NewEmail[Cns_MAX_BYTES_EMAIL_A
|
|||
NewEmail) != 0); // An email of another user is the same that my email
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************************** Create new user ******************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -145,10 +117,8 @@ void Acc_DB_CreateNewUsr (struct UsrData *UsrDat)
|
|||
extern const char *Usr_StringsSexDB[Usr_NUM_SEXS];
|
||||
char BirthdayStrDB[Usr_BIRTHDAY_STR_DB_LENGTH + 1];
|
||||
|
||||
/***** Create birthday string *****/
|
||||
Usr_CreateBirthdayStrDB (UsrDat,BirthdayStrDB); // It can include start and ending apostrophes
|
||||
|
||||
/***** Create new user *****/
|
||||
Usr_CreateBirthdayStrDB (UsrDat,BirthdayStrDB); // It can include start and ending apostrophes
|
||||
UsrDat->UsrCod =
|
||||
DB_QueryINSERTandReturnCode ("can not create user",
|
||||
"INSERT INTO usr_data"
|
||||
|
|
941
swad_agenda.c
941
swad_agenda.c
File diff suppressed because it is too large
Load Diff
|
@ -91,6 +91,15 @@ struct Agd_Agenda
|
|||
unsigned CurrentPage;
|
||||
};
|
||||
|
||||
#define Agd_NUM_AGENDA_TYPES 4
|
||||
typedef enum
|
||||
{
|
||||
Agd_MY_AGENDA_TODAY,
|
||||
Agd_MY_AGENDA,
|
||||
Agd_ANOTHER_AGENDA_TODAY,
|
||||
Agd_ANOTHER_AGENDA,
|
||||
} Agd_AgendaType_t;
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Public prototypes *****************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -125,12 +134,6 @@ void Agd_MakeEventPublic (void);
|
|||
|
||||
void Agd_ReceiveFormEvent (void);
|
||||
|
||||
void Agd_DB_RemoveUsrEvents (long UsrCod);
|
||||
unsigned Agd_GetNumEventsFromUsr (long UsrCod);
|
||||
|
||||
unsigned Agd_GetNumUsrsWithEvents (Hie_Lvl_Level_t Scope);
|
||||
unsigned Agd_GetNumEvents (Hie_Lvl_Level_t Scope);
|
||||
|
||||
void Agd_PrintAgdQRCode (void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,555 @@
|
|||
// swad_agenda_database.c: user's agenda (personal organizer) operations with database
|
||||
|
||||
/*
|
||||
SWAD (Shared Workspace At a Distance),
|
||||
is a web platform developed at the University of Granada (Spain),
|
||||
and used to support university teaching.
|
||||
|
||||
This file is part of SWAD core.
|
||||
Copyright (C) 1999-2021 Antonio Cañas Vargas
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General 3 License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
/********************************* Headers ***********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define _GNU_SOURCE // For asprintf
|
||||
// #include <linux/limits.h> // For PATH_MAX
|
||||
// #include <stddef.h> // For NULL
|
||||
#include <stdio.h> // For asprintf
|
||||
// #include <stdlib.h> // For calloc
|
||||
// #include <string.h> // For string functions
|
||||
|
||||
#include "swad_agenda.h"
|
||||
#include "swad_agenda_database.h"
|
||||
// #include "swad_box.h"
|
||||
#include "swad_database.h"
|
||||
// #include "swad_date.h"
|
||||
#include "swad_error.h"
|
||||
// #include "swad_form.h"
|
||||
#include "swad_global.h"
|
||||
// #include "swad_group.h"
|
||||
// #include "swad_HTML.h"
|
||||
// #include "swad_notification.h"
|
||||
// #include "swad_pagination.h"
|
||||
// #include "swad_parameter.h"
|
||||
// #include "swad_photo.h"
|
||||
// #include "swad_privacy.h"
|
||||
// #include "swad_QR.h"
|
||||
// #include "swad_setting.h"
|
||||
// #include "swad_string.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/************** External global variables from others modules ****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
extern struct Globals Gbl;
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Private constants *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************************* Private types *******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Private variables *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Private prototypes ****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************* Get list of agenda events *************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define Agd_MAX_BYTES_SUBQUERY 128
|
||||
|
||||
unsigned Agd_DB_GetListEvents (MYSQL_RES **mysql_res,
|
||||
const struct Agd_Agenda *Agenda,
|
||||
Agd_AgendaType_t AgendaType)
|
||||
{
|
||||
char *UsrSubQuery;
|
||||
char Past__FutureEventsSubQuery[Agd_MAX_BYTES_SUBQUERY + 1];
|
||||
char PrivatPublicEventsSubQuery[Agd_MAX_BYTES_SUBQUERY + 1];
|
||||
char HiddenVisiblEventsSubQuery[Agd_MAX_BYTES_SUBQUERY + 1];
|
||||
static const char *OrderBySubQuery[Dat_NUM_START_END_TIME] =
|
||||
{
|
||||
[Dat_START_TIME] = "StartTime,EndTime,Event,Location",
|
||||
[Dat_END_TIME ] = "EndTime,StartTime,Event,Location",
|
||||
};
|
||||
unsigned NumEvents;
|
||||
|
||||
/***** Get list of events from database *****/
|
||||
/* Build events subqueries */
|
||||
switch (AgendaType)
|
||||
{
|
||||
case Agd_MY_AGENDA_TODAY:
|
||||
case Agd_MY_AGENDA:
|
||||
if (asprintf (&UsrSubQuery,"UsrCod=%ld",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
|
||||
Err_NotEnoughMemoryExit ();
|
||||
if (AgendaType == Agd_MY_AGENDA_TODAY)
|
||||
Str_Copy (Past__FutureEventsSubQuery,
|
||||
" AND DATE(StartTime)<=CURDATE()"
|
||||
" AND DATE(EndTime)>=CURDATE()",
|
||||
sizeof (Past__FutureEventsSubQuery) - 1); // Today events
|
||||
else
|
||||
switch (Agenda->Past__FutureEvents)
|
||||
{
|
||||
case (1 << Agd_PAST___EVENTS):
|
||||
Str_Copy (Past__FutureEventsSubQuery,
|
||||
" AND DATE(StartTime)<=CURDATE()",
|
||||
sizeof (Past__FutureEventsSubQuery) - 1); // Past and today events
|
||||
break;
|
||||
case (1 << Agd_FUTURE_EVENTS):
|
||||
Str_Copy (Past__FutureEventsSubQuery,
|
||||
" AND DATE(EndTime)>=CURDATE()",
|
||||
sizeof (Past__FutureEventsSubQuery) - 1); // Today and future events
|
||||
break;
|
||||
default:
|
||||
Past__FutureEventsSubQuery[0] = '\0'; // All events
|
||||
break;
|
||||
}
|
||||
switch (Agenda->PrivatPublicEvents)
|
||||
{
|
||||
case (1 << Agd_PRIVAT_EVENTS):
|
||||
Str_Copy (PrivatPublicEventsSubQuery," AND Public='N'",
|
||||
sizeof (PrivatPublicEventsSubQuery) - 1); // Private events
|
||||
break;
|
||||
case (1 << Agd_PUBLIC_EVENTS):
|
||||
Str_Copy (PrivatPublicEventsSubQuery," AND Public='Y'",
|
||||
sizeof (PrivatPublicEventsSubQuery) - 1); // Public events
|
||||
break;
|
||||
default:
|
||||
PrivatPublicEventsSubQuery[0] = '\0'; // All events
|
||||
break;
|
||||
}
|
||||
switch (Agenda->HiddenVisiblEvents)
|
||||
{
|
||||
case (1 << Agd_HIDDEN_EVENTS):
|
||||
Str_Copy (HiddenVisiblEventsSubQuery," AND Hidden='Y'",
|
||||
sizeof (HiddenVisiblEventsSubQuery) - 1); // Hidden events
|
||||
break;
|
||||
case (1 << Agd_VISIBL_EVENTS):
|
||||
Str_Copy (HiddenVisiblEventsSubQuery," AND Hidden='N'",
|
||||
sizeof (HiddenVisiblEventsSubQuery) - 1); // Visible events
|
||||
break;
|
||||
default:
|
||||
HiddenVisiblEventsSubQuery[0] = '\0'; // All events
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Agd_ANOTHER_AGENDA_TODAY:
|
||||
case Agd_ANOTHER_AGENDA:
|
||||
if (asprintf (&UsrSubQuery,"UsrCod=%ld",
|
||||
Gbl.Usrs.Other.UsrDat.UsrCod) < 0)
|
||||
Err_NotEnoughMemoryExit ();
|
||||
if (AgendaType == Agd_ANOTHER_AGENDA_TODAY)
|
||||
Str_Copy (Past__FutureEventsSubQuery,
|
||||
" AND DATE(StartTime)<=CURDATE()"
|
||||
" AND DATE(EndTime)>=CURDATE()",
|
||||
sizeof (Past__FutureEventsSubQuery) - 1); // Today events
|
||||
else
|
||||
Str_Copy (Past__FutureEventsSubQuery,
|
||||
" AND DATE(EndTime)>=CURDATE()",
|
||||
sizeof (Past__FutureEventsSubQuery) - 1); // Today and future events
|
||||
Str_Copy (PrivatPublicEventsSubQuery," AND Public='Y'",
|
||||
sizeof (PrivatPublicEventsSubQuery) - 1); // Public events
|
||||
Str_Copy (HiddenVisiblEventsSubQuery," AND Hidden='N'",
|
||||
sizeof (HiddenVisiblEventsSubQuery) - 1); // Visible events
|
||||
}
|
||||
|
||||
/* Make query */
|
||||
NumEvents = (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get agenda events",
|
||||
"SELECT AgdCod" // row[0]
|
||||
" FROM agd_agendas"
|
||||
" WHERE %s%s%s%s"
|
||||
" ORDER BY %s",
|
||||
UsrSubQuery,
|
||||
Past__FutureEventsSubQuery,
|
||||
PrivatPublicEventsSubQuery,
|
||||
HiddenVisiblEventsSubQuery,
|
||||
OrderBySubQuery[Agenda->SelectedOrder]);
|
||||
|
||||
/* Free allocated memory for subquery */
|
||||
free (UsrSubQuery);
|
||||
|
||||
return NumEvents;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** Get event data using its code ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Agd_DB_GetDataOfEventByCod (MYSQL_RES **mysql_res,
|
||||
const struct Agd_Event *AgdEvent)
|
||||
{
|
||||
/***** Get data of event from database *****/
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get agenda event data",
|
||||
"SELECT AgdCod," // row[0]
|
||||
"Public," // row[1]
|
||||
"Hidden," // row[2]
|
||||
"UNIX_TIMESTAMP(StartTime)," // row[3]
|
||||
"UNIX_TIMESTAMP(EndTime)," // row[4]
|
||||
"NOW()>EndTime," // row[5] Past event?
|
||||
"NOW()<StartTime," // row[6] Future event?
|
||||
"Event," // row[7]
|
||||
"Location" // row[8]
|
||||
" FROM agd_agendas"
|
||||
" WHERE AgdCod=%ld"
|
||||
" AND UsrCod=%ld",
|
||||
AgdEvent->AgdCod,
|
||||
AgdEvent->UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** Get event text from database ************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Agd_DB_GetEventTxt (const struct Agd_Event *AgdEvent,
|
||||
char Txt[Cns_MAX_BYTES_TEXT + 1])
|
||||
{
|
||||
DB_QuerySELECTString (Txt,Cns_MAX_BYTES_TEXT,"can not get event text",
|
||||
"SELECT Txt"
|
||||
" FROM agd_agendas"
|
||||
" WHERE AgdCod=%ld"
|
||||
" AND UsrCod=%ld",
|
||||
AgdEvent->AgdCod,
|
||||
AgdEvent->UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************* Remove event from database ************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Agd_DB_RemoveEvent (const struct Agd_Event *AgdEvent)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove event",
|
||||
"DELETE FROM agd_agendas"
|
||||
" WHERE AgdCod=%ld"
|
||||
" AND UsrCod=%ld",
|
||||
AgdEvent->AgdCod,
|
||||
AgdEvent->UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************** Create a new event *******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
long Agd_DB_CreateEvent (const struct Agd_Event *AgdEvent,const char *Txt)
|
||||
{
|
||||
/***** Create a new event *****/
|
||||
return
|
||||
DB_QueryINSERTandReturnCode ("can not create new event",
|
||||
"INSERT INTO agd_agendas"
|
||||
" (UsrCod,StartTime,EndTime,"
|
||||
"Event,Location,Txt)"
|
||||
" VALUES"
|
||||
" (%ld,FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld),"
|
||||
"'%s','%s','%s')",
|
||||
AgdEvent->UsrCod,
|
||||
AgdEvent->TimeUTC[Dat_START_TIME],
|
||||
AgdEvent->TimeUTC[Dat_END_TIME ],
|
||||
AgdEvent->Event,
|
||||
AgdEvent->Location,
|
||||
Txt);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************ Update an existing event ***************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Agd_DB_UpdateEvent (const struct Agd_Event *AgdEvent,const char *Txt)
|
||||
{
|
||||
/***** Update the data of the event *****/
|
||||
DB_QueryUPDATE ("can not update event",
|
||||
"UPDATE agd_agendas"
|
||||
" SET StartTime=FROM_UNIXTIME(%ld),"
|
||||
"EndTime=FROM_UNIXTIME(%ld),"
|
||||
"Event='%s',"
|
||||
"Location='%s',"
|
||||
"Txt='%s'"
|
||||
" WHERE AgdCod=%ld"
|
||||
" AND UsrCod=%ld",
|
||||
AgdEvent->TimeUTC[Dat_START_TIME],
|
||||
AgdEvent->TimeUTC[Dat_END_TIME ],
|
||||
AgdEvent->Event,
|
||||
AgdEvent->Location,
|
||||
Txt,
|
||||
AgdEvent->AgdCod,
|
||||
AgdEvent->UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************** Set an existing event as hidden/not hidden *****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Agd_DB_HideEvent (const struct Agd_Event *AgdEvent)
|
||||
{
|
||||
DB_QueryUPDATE ("can not hide event",
|
||||
"UPDATE agd_agendas"
|
||||
" SET Hidden='Y'"
|
||||
" WHERE AgdCod=%ld"
|
||||
" AND UsrCod=%ld",
|
||||
AgdEvent->AgdCod,
|
||||
AgdEvent->UsrCod);
|
||||
}
|
||||
|
||||
void Agd_DB_UnhideEvent (const struct Agd_Event *AgdEvent)
|
||||
{
|
||||
DB_QueryUPDATE ("can not unhide event",
|
||||
"UPDATE agd_agendas"
|
||||
" SET Hidden='N'"
|
||||
" WHERE AgdCod=%ld"
|
||||
" AND UsrCod=%ld",
|
||||
AgdEvent->AgdCod,
|
||||
AgdEvent->UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************** Set an existing event as public/private *******************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Agd_DB_MakeEventPublic (const struct Agd_Event *AgdEvent)
|
||||
{
|
||||
DB_QueryUPDATE ("can not make event public",
|
||||
"UPDATE agd_agendas"
|
||||
" SET Public='Y'"
|
||||
" WHERE AgdCod=%ld"
|
||||
" AND UsrCod=%ld",
|
||||
AgdEvent->AgdCod,
|
||||
AgdEvent->UsrCod);
|
||||
}
|
||||
|
||||
void Agd_DB_MakeEventPrivate (const struct Agd_Event *AgdEvent)
|
||||
{
|
||||
DB_QueryUPDATE ("can not make event private",
|
||||
"UPDATE agd_agendas"
|
||||
" SET Public='N'"
|
||||
" WHERE AgdCod=%ld"
|
||||
" AND UsrCod=%ld",
|
||||
AgdEvent->AgdCod,
|
||||
AgdEvent->UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************** Remove all the events of a user **********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Agd_DB_RemoveUsrEvents (long UsrCod)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove all the events of a user",
|
||||
"DELETE FROM agd_agendas"
|
||||
" WHERE UsrCod=%ld",
|
||||
UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************* Get number of events from a user **********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Agd_DB_GetNumEventsFromUsr (long UsrCod)
|
||||
{
|
||||
/***** Get number of events in a course from database *****/
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of events from user",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM agd_agendas"
|
||||
" WHERE UsrCod=%ld",
|
||||
UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************** Get number of users with events **********************/
|
||||
/*****************************************************************************/
|
||||
// Returns the number of users with events in a given scope
|
||||
|
||||
unsigned Agd_DB_GetNumUsrsWithEvents (Hie_Lvl_Level_t Scope)
|
||||
{
|
||||
/***** Get number of users with events from database *****/
|
||||
switch (Scope)
|
||||
{
|
||||
case Hie_Lvl_SYS:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of users with events",
|
||||
"SELECT COUNT(DISTINCT UsrCod)"
|
||||
" FROM agd_agendas"
|
||||
" WHERE UsrCod>0");
|
||||
case Hie_Lvl_CTY:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of users with events",
|
||||
"SELECT COUNT(DISTINCT agd_agendas.UsrCod)"
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"crs_users,"
|
||||
"agd_agendas"
|
||||
" WHERE ins_instits.CtyCod=%ld"
|
||||
" AND ins_instits.InsCod=ctr_centers.InsCod"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
||||
" AND crs_users.UsrCod=agd_agendas.UsrCod",
|
||||
Gbl.Hierarchy.Cty.CtyCod);
|
||||
case Hie_Lvl_INS:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of users with events",
|
||||
"SELECT COUNT(DISTINCT agd_agendas.UsrCod)"
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"crs_users,"
|
||||
"agd_agendas"
|
||||
" WHERE ctr_centers.InsCod=%ld"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
||||
" AND crs_users.UsrCod=agd_agendas.UsrCod",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
case Hie_Lvl_CTR:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of users with events",
|
||||
"SELECT COUNT(DISTINCT agd_agendas.UsrCod)"
|
||||
" FROM deg_degrees,"
|
||||
"crs_courses,"
|
||||
"crs_users,"
|
||||
"agd_agendas"
|
||||
" WHERE deg_degrees.CtrCod=%ld"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
||||
" AND crs_users.UsrCod=agd_agendas.UsrCod",
|
||||
Gbl.Hierarchy.Ctr.CtrCod);
|
||||
case Hie_Lvl_DEG:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of users with events",
|
||||
"SELECT COUNT(DISTINCT agd_agendas.UsrCod)"
|
||||
" FROM crs_courses,"
|
||||
"crs_users,"
|
||||
"agd_agendas"
|
||||
" WHERE crs_courses.DegCod=%ld"
|
||||
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
||||
" AND crs_users.UsrCod=agd_agendas.UsrCod",
|
||||
Gbl.Hierarchy.Deg.DegCod);
|
||||
case Hie_Lvl_CRS:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of users with events",
|
||||
"SELECT COUNT(DISTINCT agd_agendas.UsrCod)"
|
||||
" FROM crs_users,"
|
||||
"agd_agendas"
|
||||
" WHERE crs_users.CrsCod=%ld"
|
||||
" AND crs_users.UsrCod=agd_agendas.UsrCod",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
default:
|
||||
Err_WrongScopeExit ();
|
||||
return 0; // Not reached
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************************** Get number of events ****************************/
|
||||
/*****************************************************************************/
|
||||
// Returns the number of events in a given scope
|
||||
|
||||
unsigned Agd_DB_GetNumEvents (Hie_Lvl_Level_t Scope)
|
||||
{
|
||||
/***** Get number of events from database *****/
|
||||
switch (Scope)
|
||||
{
|
||||
case Hie_Lvl_SYS:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of events",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM agd_agendas"
|
||||
" WHERE UsrCod>0");
|
||||
case Hie_Lvl_CTY:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of events",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM (SELECT DISTINCT crs_users.UsrCod"
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"crs_users"
|
||||
" WHERE ins_instits.CtyCod=%ld"
|
||||
" AND ins_instits.InsCod=ctr_centers.InsCod"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=crs_users.CrsCod) AS users,"
|
||||
"agd_agendas"
|
||||
" WHERE users.UsrCod=agd_agendas.UsrCod",
|
||||
Gbl.Hierarchy.Cty.CtyCod);
|
||||
case Hie_Lvl_INS:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of events",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM (SELECT DISTINCT crs_users.UsrCod"
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"crs_users"
|
||||
" WHERE ctr_centers.InsCod=%ld"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=crs_users.CrsCod) AS users,"
|
||||
"agd_agendas"
|
||||
" WHERE users.UsrCod=agd_agendas.UsrCod",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
case Hie_Lvl_CTR:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of events",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM (SELECT DISTINCT crs_users.UsrCod"
|
||||
" FROM deg_degrees,"
|
||||
"crs_courses,"
|
||||
"crs_users"
|
||||
" WHERE deg_degrees.CtrCod=%ld"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=crs_users.CrsCod) AS users,"
|
||||
"agd_agendas"
|
||||
" WHERE users.UsrCod=agd_agendas.UsrCod",
|
||||
Gbl.Hierarchy.Ctr.CtrCod);
|
||||
case Hie_Lvl_DEG:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of events",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM (SELECT DISTINCT crs_users.UsrCod"
|
||||
" FROM crs_courses,"
|
||||
"crs_users"
|
||||
" WHERE crs_courses.DegCod=%ld"
|
||||
" AND crs_courses.CrsCod=crs_users.CrsCod) AS users,"
|
||||
"agd_agendas"
|
||||
" WHERE users.UsrCod=agd_agendas.UsrCod",
|
||||
Gbl.Hierarchy.Deg.DegCod);
|
||||
case Hie_Lvl_CRS:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of events",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM crs_users,"
|
||||
"agd_agendas"
|
||||
" WHERE crs_users.CrsCod=%ld"
|
||||
" AND crs_users.UsrCod=agd_agendas.UsrCod",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
default:
|
||||
Err_WrongScopeExit ();
|
||||
return 0; // Not reached
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
// swad_agenda_database.h: user's agenda (personal organizer) operations with database
|
||||
|
||||
#ifndef _SWAD_AGD_DB
|
||||
#define _SWAD_AGD_DB
|
||||
/*
|
||||
SWAD (Shared Workspace At a Distance in Spanish),
|
||||
is a web platform developed at the University of Granada (Spain),
|
||||
and used to support university teaching.
|
||||
|
||||
This file is part of SWAD core.
|
||||
Copyright (C) 1999-2021 Antonio Cañas Vargas
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
/********************************* Headers ***********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#include "swad_agenda.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************** Public types and constants ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Public prototypes *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Agd_DB_GetListEvents (MYSQL_RES **mysql_res,
|
||||
const struct Agd_Agenda *Agenda,
|
||||
Agd_AgendaType_t AgendaType);
|
||||
|
||||
unsigned Agd_DB_GetDataOfEventByCod (MYSQL_RES **mysql_res,
|
||||
const struct Agd_Event *AgdEvent);
|
||||
void Agd_DB_GetEventTxt (const struct Agd_Event *AgdEvent,
|
||||
char Txt[Cns_MAX_BYTES_TEXT + 1]);
|
||||
|
||||
void Agd_DB_RemoveEvent (const struct Agd_Event *AgdEvent);
|
||||
|
||||
long Agd_DB_CreateEvent (const struct Agd_Event *AgdEvent,const char *Txt);
|
||||
void Agd_DB_UpdateEvent (const struct Agd_Event *AgdEvent,const char *Txt);
|
||||
void Agd_DB_HideEvent (const struct Agd_Event *AgdEvent);
|
||||
void Agd_DB_UnhideEvent (const struct Agd_Event *AgdEvent);
|
||||
void Agd_DB_MakeEventPublic (const struct Agd_Event *AgdEvent);
|
||||
void Agd_DB_MakeEventPrivate (const struct Agd_Event *AgdEvent);
|
||||
|
||||
void Agd_DB_RemoveUsrEvents (long UsrCod);
|
||||
|
||||
unsigned Agd_DB_GetNumEventsFromUsr (long UsrCod);
|
||||
|
||||
unsigned Agd_DB_GetNumUsrsWithEvents (Hie_Lvl_Level_t Scope);
|
||||
|
||||
unsigned Agd_DB_GetNumEvents (Hie_Lvl_Level_t Scope);
|
||||
|
||||
#endif
|
|
@ -600,13 +600,14 @@ TODO: Salvador Romero Cort
|
|||
|
||||
TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria.
|
||||
*/
|
||||
#define Log_PLATFORM_VERSION "SWAD 20.72 (2021-05-10)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 20.73 (2021-05-10)"
|
||||
#define CSS_FILE "swad20.45.css"
|
||||
#define JS_FILE "swad20.69.1.js"
|
||||
/*
|
||||
TODO: Rename CENTRE to CENTER in help wiki.
|
||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||
|
||||
Version 20.73: May 10, 2021 New module swad_agenda_database for database queries related to agenda. (310474 lines)
|
||||
Version 20.72: May 10, 2021 New module swad_account_database for database queries related to user's account. (310328 lines)
|
||||
Version 20.71: May 10, 2021 New module swad_media_database for database queries related to media. (310080 lines)
|
||||
Version 20.70: May 07, 2021 New module swad_follow_database for database queries related to following/followers. (309943 lines)
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include <string.h> // For string functions
|
||||
|
||||
#include "swad_action.h"
|
||||
#include "swad_agenda.h"
|
||||
#include "swad_agenda_database.h"
|
||||
#include "swad_box.h"
|
||||
#include "swad_database.h"
|
||||
#include "swad_error.h"
|
||||
|
@ -4968,10 +4968,10 @@ static void Fig_GetAndShowAgendasStats (void)
|
|||
HTM_TR_End ();
|
||||
|
||||
/***** Number of agenda events *****/
|
||||
NumEvents = Agd_GetNumEvents (Gbl.Scope.Current);
|
||||
NumEvents = Agd_DB_GetNumEvents (Gbl.Scope.Current);
|
||||
|
||||
/***** Number of users with agenda events *****/
|
||||
NumUsrs = Agd_GetNumUsrsWithEvents (Gbl.Scope.Current);
|
||||
NumUsrs = Agd_DB_GetNumUsrsWithEvents (Gbl.Scope.Current);
|
||||
|
||||
/***** Get total number of users in current scope *****/
|
||||
NumUsrsTotal = Usr_GetTotalNumberOfUsers ();
|
||||
|
|
Loading…
Reference in New Issue