"
""
"%s:"
" | "
""
""
" | "
"
");
/***** New event *****/
if (ItsANewEvent)
Lay_EndRoundFrameTableWithButton (Lay_CREATE_BUTTON,Txt_Create_event);
else
Lay_EndRoundFrameTableWithButton (Lay_CONFIRM_BUTTON,Txt_Save);
Act_FormEnd ();
/***** Show current events, if any *****/
Agd_ShowMyAgenda ();
}
/*****************************************************************************/
/********************* Receive form to create a new event ********************/
/*****************************************************************************/
void Agd_RecFormEvent (void)
{
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;
extern const char *Txt_The_event_has_been_modified;
struct AgendaEvent AgdEvent;
bool ItsANewEvent;
bool NewEventIsCorrect = true;
char Txt[Cns_MAX_BYTES_TEXT+1];
/***** Set author of the event *****/
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
/***** Get the code of the event *****/
ItsANewEvent = ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L);
/***** Get start/end date-times *****/
AgdEvent.TimeUTC[Agd_START_TIME] = Dat_GetTimeUTCFromForm ("StartTimeUTC");
AgdEvent.TimeUTC[Agd_END_TIME ] = Dat_GetTimeUTCFromForm ("EndTimeUTC" );
/***** Get event *****/
Par_GetParToText ("Location",AgdEvent.Location,Agd_MAX_LENGTH_LOCATION);
/***** Get event *****/
Par_GetParToText ("Event",AgdEvent.Event,Agd_MAX_LENGTH_EVENT);
/***** Get text *****/
Par_GetParToHTML ("Txt",Txt,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous)
/***** Adjust dates *****/
if (AgdEvent.TimeUTC[Agd_START_TIME] == 0)
AgdEvent.TimeUTC[Agd_START_TIME] = Gbl.StartExecutionTimeUTC;
if (AgdEvent.TimeUTC[Agd_END_TIME] == 0)
AgdEvent.TimeUTC[Agd_END_TIME] = AgdEvent.TimeUTC[Agd_START_TIME] + 2*60*60; // +2 hours
/***** Check if event is correct *****/
if (!AgdEvent.Location[0]) // If there is no event
{
NewEventIsCorrect = false;
Lay_ShowAlert (Lay_WARNING,Txt_You_must_specify_the_title_of_the_event);
}
/***** Check if event is correct *****/
if (AgdEvent.Event[0]) // If there's event
{
/* If title of event was in database... */
if (Agd_CheckIfSimilarEventExists (&AgdEvent))
{
NewEventIsCorrect = false;
sprintf (Gbl.Message,Txt_Already_existed_an_event_with_the_title_X,
AgdEvent.Event);
Lay_ShowAlert (Lay_WARNING,Gbl.Message);
}
}
else // If there is no event
{
NewEventIsCorrect = false;
Lay_ShowAlert (Lay_WARNING,Txt_You_must_specify_the_title_of_the_event);
}
/***** Create a new event or update an existing one *****/
if (NewEventIsCorrect)
{
if (ItsANewEvent)
{
Agd_CreateEvent (&AgdEvent,Txt); // Add new event to database
/***** Write success message *****/
sprintf (Gbl.Message,Txt_Created_new_event_X,AgdEvent.Event);
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
}
else
{
Agd_UpdateEvent (&AgdEvent,Txt);
/***** Write success message *****/
Lay_ShowAlert (Lay_SUCCESS,Txt_The_event_has_been_modified);
}
/* Free memory for list of selected groups */
Grp_FreeListCodSelectedGrps ();
/***** Show events again *****/
Agd_ShowMyAgenda ();
}
else
// TODO: The form should be filled with partial data, now is always empty
Agd_RequestCreatOrEditEvent ();
}
/*****************************************************************************/
/*********** Check if the title or the folder of an event exists *************/
/*****************************************************************************/
static bool Agd_CheckIfSimilarEventExists (struct AgendaEvent *AgdEvent)
{
char Query[256+Agd_MAX_LENGTH_EVENT];
/***** Get number of events with a field value from database *****/
sprintf (Query,"SELECT COUNT(*) FROM agendas"
" WHERE UsrCod='%ld' AND Event='%s' AND AgdCod<>'%ld'",
AgdEvent->UsrCod,AgdEvent->Event,AgdEvent->AgdCod);
return (DB_QueryCOUNT (Query,"can not get similar events") != 0);
}
/*****************************************************************************/
/************************** Create a new event *******************************/
/*****************************************************************************/
static void Agd_CreateEvent (struct AgendaEvent *AgdEvent,const char *Txt)
{
char Query[1024+Cns_MAX_BYTES_TEXT];
/***** Create a new event *****/
sprintf (Query,"INSERT INTO agendas"
" (UsrCod,StartTime,EndTime,Event,Location,Txt)"
" VALUES"
" ('%ld',FROM_UNIXTIME('%ld'),FROM_UNIXTIME('%ld'),"
"'%s','%s','%s')",
AgdEvent->UsrCod,
AgdEvent->TimeUTC[Agd_START_TIME],
AgdEvent->TimeUTC[Agd_END_TIME ],
AgdEvent->Event,
AgdEvent->Location,
Txt);
AgdEvent->AgdCod = DB_QueryINSERTandReturnCode (Query,"can not create new event");
}
/*****************************************************************************/
/************************ Update an existing event ***************************/
/*****************************************************************************/
static void Agd_UpdateEvent (struct AgendaEvent *AgdEvent,const char *Txt)
{
char Query[1024+Cns_MAX_BYTES_TEXT];
/***** Update the data of the event *****/
sprintf (Query,"UPDATE agendas SET "
"StartTime=FROM_UNIXTIME('%ld'),"
"EndTime=FROM_UNIXTIME('%ld'),"
"Event='%s',Location='%s',Txt='%s'"
" WHERE AgdCod='%ld' AND UsrCod='%ld'",
AgdEvent->TimeUTC[Agd_START_TIME],
AgdEvent->TimeUTC[Agd_END_TIME ],
AgdEvent->Event,AgdEvent->Location,Txt,
AgdEvent->AgdCod,AgdEvent->UsrCod);
DB_QueryUPDATE (Query,"can not update event");
}
/*****************************************************************************/
/********************** Remove all the events of a user **********************/
/*****************************************************************************/
void Agd_RemoveUsrEvents (long UsrCod)
{
char Query[128];
/***** Remove events *****/
sprintf (Query,"DELETE FROM agendas WHERE UsrCod='%ld'",UsrCod);
DB_QueryDELETE (Query,"can not remove all the events of a user");
}
/*****************************************************************************/
/********************* Get number of events from a user **********************/
/*****************************************************************************/
unsigned Agd_GetNumEventsFromUsr (long UsrCod)
{
char Query[128];
/***** Get number of events in a course from database *****/
sprintf (Query,"SELECT COUNT(*) FROM agendas WHERE UsrCod='%ld'",
UsrCod);
return (unsigned) DB_QueryCOUNT (Query,"can not get number of events from user");
}
/*****************************************************************************/
/********************** Get number of users with events **********************/
/*****************************************************************************/
// Returns the number of users with events in a given scope
unsigned Agd_GetNumUsrsWithEvents (Sco_Scope_t Scope)
{
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs;
/***** Get number of courses with events from database *****/
switch (Scope)
{
case Sco_SCOPE_SYS:
sprintf (Query,"SELECT COUNT(DISTINCT UsrCod)"
" FROM agendas"
" WHERE UsrCod>'0'");
break;
case Sco_SCOPE_CTY:
sprintf (Query,"SELECT COUNT(DISTINCT agendas.UsrCod)"
" FROM institutions,centres,degrees,courses,crs_usr,agendas"
" WHERE institutions.CtyCod='%ld'"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
Gbl.CurrentCty.Cty.CtyCod);
break;
case Sco_SCOPE_INS:
sprintf (Query,"SELECT COUNT(DISTINCT agendas.UsrCod)"
" FROM centres,degrees,courses,crs_usr,agendas"
" WHERE centres.InsCod='%ld'"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
Gbl.CurrentIns.Ins.InsCod);
break;
case Sco_SCOPE_CTR:
sprintf (Query,"SELECT COUNT(DISTINCT agendas.UsrCod)"
" FROM degrees,courses,crs_usr,agendas"
" WHERE degrees.CtrCod='%ld'"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
Gbl.CurrentCtr.Ctr.CtrCod);
break;
case Sco_SCOPE_DEG:
sprintf (Query,"SELECT COUNT(DISTINCT agendas.UsrCod)"
" FROM courses,crs_usr,agendas"
" WHERE courses.DegCod='%ld'"
" AND courses.Status=0"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
Gbl.CurrentDeg.Deg.DegCod);
break;
case Sco_SCOPE_CRS:
sprintf (Query,"SELECT COUNT(DISTINCT agendas.UsrCod)"
" FROM crs_usr,agendas"
" WHERE crs_usr.CrsCod='%ld'"
" AND crs_usr.UsrCod=agendas.UsrCod",
Gbl.CurrentCrs.Crs.CrsCod);
break;
default:
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
DB_QuerySELECT (Query,&mysql_res,"can not get number of users with events");
/***** Get number of users *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumUsrs) != 1)
Lay_ShowErrorAndExit ("Error when getting number of users with events.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumUsrs;
}
/*****************************************************************************/
/*************************** Get number of events ****************************/
/*****************************************************************************/
// Returns the number of events in a given scope
unsigned Agd_GetNumEvents (Sco_Scope_t Scope)
{
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumEvents;
/***** Get number of events from database *****/
switch (Scope)
{
case Sco_SCOPE_SYS:
sprintf (Query,"SELECT COUNT(*)"
" FROM agendas"
" WHERE UsrCod>'0'");
break;
case Sco_SCOPE_CTY:
sprintf (Query,"SELECT COUNT(*)"
" FROM institutions,centres,degrees,courses,crs_usr,agendas"
" WHERE institutions.CtyCod='%ld'"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
Gbl.CurrentCty.Cty.CtyCod);
break;
case Sco_SCOPE_INS:
sprintf (Query,"SELECT COUNT(*)"
" FROM centres,degrees,courses,crs_usr,agendas"
" WHERE centres.InsCod='%ld'"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
Gbl.CurrentIns.Ins.InsCod);
break;
case Sco_SCOPE_CTR:
sprintf (Query,"SELECT COUNT(*)"
" FROM degrees,courses,crs_usr,agendas"
" WHERE degrees.CtrCod='%ld'"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
Gbl.CurrentCtr.Ctr.CtrCod);
break;
case Sco_SCOPE_DEG:
sprintf (Query,"SELECT COUNT(*)"
" FROM courses,crs_usr,agendas"
" WHERE courses.DegCod='%ld'"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=agendas.UsrCod",
Gbl.CurrentDeg.Deg.DegCod);
break;
case Sco_SCOPE_CRS:
sprintf (Query,"SELECT COUNT(*)"
" FROM crs_usr,agendas"
" WHERE crs_usr.CrsCod='%ld'"
" AND crs_usr.UsrCod=agendas.UsrCod",
Gbl.CurrentCrs.Crs.CrsCod);
break;
default:
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
DB_QuerySELECT (Query,&mysql_res,"can not get number of events");
/***** Get number of events *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumEvents) != 1)
Lay_ShowErrorAndExit ("Error when getting number of events.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumEvents;
}
/*****************************************************************************/
/************************** Show an agenda QR code ***************************/
/*****************************************************************************/
void Agd_PrintAgdQRCode (void)
{
extern const char *Txt_Where_s_USER;
/***** Start frame *****/
sprintf (Gbl.Title,Txt_Where_s_USER,Gbl.Usrs.Me.UsrDat.FullName);
Lay_StartRoundFrame (NULL,Gbl.Title,NULL,NULL);
/***** Print QR code ****/
QR_PrintQRCode ();
/***** End frame *****/
Lay_EndRoundFrame ();
}