Version 16.91.6

This commit is contained in:
Antonio Cañas Vargas 2016-12-09 00:44:15 +01:00
parent ead250562c
commit 438a192895
2 changed files with 72 additions and 100 deletions

View File

@ -94,10 +94,9 @@ static void Agd_PutFormsToRemEditOneEvent (struct AgendaEvent *AgdEvent);
static void Agd_PutParams (void); static void Agd_PutParams (void);
static void Agd_GetListEvents (Agd_AgendaType_t AgendaType); static void Agd_GetListEvents (Agd_AgendaType_t AgendaType);
static void Agd_GetDataOfEventByCod (struct AgendaEvent *AgdEvent); static void Agd_GetDataOfEventByCod (struct AgendaEvent *AgdEvent);
static void Agd_GetDataOfEvent (struct AgendaEvent *AgdEvent,const char *Query);
static void Agd_GetEventTxtFromDB (struct AgendaEvent *AgdEvent,char *Txt); static void Agd_GetEventTxtFromDB (struct AgendaEvent *AgdEvent,char *Txt);
static void Agd_PutParamAgdCod (long AgdCod); static void Agd_PutParamAgdCod (long AgdCod);
static bool Agd_CheckIfSimilarEventExists (const char *Field,const char *Value,long AgdCod); static bool Agd_CheckIfSimilarEventExists (struct AgendaEvent *AgdEvent);
static void Agd_CreateEvent (struct AgendaEvent *AgdEvent,const char *Txt); static void Agd_CreateEvent (struct AgendaEvent *AgdEvent,const char *Txt);
static void Agd_UpdateEvent (struct AgendaEvent *AgdEvent,const char *Txt); static void Agd_UpdateEvent (struct AgendaEvent *AgdEvent,const char *Txt);
@ -858,9 +857,11 @@ static void Agd_GetListEvents (Agd_AgendaType_t AgendaType)
static void Agd_GetDataOfEventByCod (struct AgendaEvent *AgdEvent) static void Agd_GetDataOfEventByCod (struct AgendaEvent *AgdEvent)
{ {
char Query[512]; char Query[512];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
/***** Build query *****/ /***** Build query *****/
sprintf (Query,"SELECT AgdCod,UsrCod,Public,Hidden," sprintf (Query,"SELECT AgdCod,Public,Hidden,"
"UNIX_TIMESTAMP(StartTime)," "UNIX_TIMESTAMP(StartTime),"
"UNIX_TIMESTAMP(EndTime)," "UNIX_TIMESTAMP(EndTime),"
"NOW()>EndTime," // Past event? "NOW()>EndTime," // Past event?
@ -870,78 +871,59 @@ static void Agd_GetDataOfEventByCod (struct AgendaEvent *AgdEvent)
" WHERE AgdCod='%ld' AND UsrCod='%ld'", " WHERE AgdCod='%ld' AND UsrCod='%ld'",
AgdEvent->AgdCod,AgdEvent->UsrCod); AgdEvent->AgdCod,AgdEvent->UsrCod);
/***** Get data of event *****/
Agd_GetDataOfEvent (AgdEvent,Query);
}
/*****************************************************************************/
/****************************** Get event data *******************************/
/*****************************************************************************/
static void Agd_GetDataOfEvent (struct AgendaEvent *AgdEvent,const char *Query)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
/***** Clear all event data *****/
AgdEvent->AgdCod = -1L;
AgdEvent->UsrCod = -1L;
AgdEvent->Public = false;
AgdEvent->Hidden = false;
AgdEvent->TimeUTC[Agd_START_TIME] =
AgdEvent->TimeUTC[Agd_END_TIME ] = (time_t) 0;
AgdEvent->TimeStatus = Dat_FUTURE;
AgdEvent->Event[0] = '\0';
AgdEvent->Location[0] = '\0';
/***** Get data of event from database *****/ /***** Get data of event from database *****/
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get agenda event data"); if (DB_QuerySELECT (Query,&mysql_res,"can not get agenda event data")) // Event found...
if (NumRows) // Event found...
{ {
/* Get row: /* Get row:
row[0] AgdCod row[0] AgdCod
row[1] UsrCod row[1] Public
row[2] Public row[2] Hidden
row[3] Hidden row[3] UNIX_TIMESTAMP(StartTime)
row[4] UNIX_TIMESTAMP(StartTime) row[4] UNIX_TIMESTAMP(EndTime)
row[5] UNIX_TIMESTAMP(EndTime) row[5] NOW()>EndTime // Past event?
row[6] NOW()>EndTime // Past event? row[6] NOW()<StartTime // Future event?
row[7] NOW()<StartTime // Future event? row[7] Event
row[8] Event row[8] Location
row[9] Location
*/ */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
/* Get code of the event (row[0]) */ /* Get code of the event (row[0]) */
AgdEvent->AgdCod = Str_ConvertStrCodToLongCod (row[0]); AgdEvent->AgdCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get author of the event (row[1]) */ /* Get whether the event is public or not (row[1]) */
AgdEvent->UsrCod = Str_ConvertStrCodToLongCod (row[1]); AgdEvent->Public = (row[1][0] == 'Y');
/* Get whether the event is public or not (row[2]) */ /* Get whether the event is hidden or not (row[2]) */
AgdEvent->Public = (row[2][0] == 'Y'); AgdEvent->Hidden = (row[2][0] == 'Y');
/* Get whether the event is hidden or not (row[3]) */ /* Get start date (row[3] holds the start UTC time) */
AgdEvent->Hidden = (row[3][0] == 'Y'); AgdEvent->TimeUTC[Agd_START_TIME] = Dat_GetUNIXTimeFromStr (row[3]);
/* Get start date (row[4] holds the start UTC time) */ /* Get end date (row[4] holds the end UTC time) */
AgdEvent->TimeUTC[Agd_START_TIME] = Dat_GetUNIXTimeFromStr (row[4]); AgdEvent->TimeUTC[Agd_END_TIME ] = Dat_GetUNIXTimeFromStr (row[4]);
/* Get end date (row[5] holds the end UTC time) */ /* Get whether the event is past, present or future (row(5), row[6]) */
AgdEvent->TimeUTC[Agd_END_TIME ] = Dat_GetUNIXTimeFromStr (row[5]); AgdEvent->TimeStatus = ((row[5][0] == '1') ? Dat_PAST :
((row[6][0] == '1') ? Dat_FUTURE :
/* Get whether the event is past, present or futur (row(6), row[7]) */
AgdEvent->TimeStatus = ((row[6][0] == '1') ? Dat_PAST :
((row[7][0] == '1') ? Dat_FUTURE :
Dat_PRESENT)); Dat_PRESENT));
/* Get the event (row[8]) */ /* Get the event (row[7]) */
strcpy (AgdEvent->Event,row[8]); strcpy (AgdEvent->Event,row[7]);
/* Get the event (row[9]) */ /* Get the event (row[8]) */
strcpy (AgdEvent->Location,row[9]); strcpy (AgdEvent->Location,row[8]);
}
else
{
/***** Clear all event data *****/
AgdEvent->AgdCod = -1L;
AgdEvent->Public = false;
AgdEvent->Hidden = false;
AgdEvent->TimeUTC[Agd_START_TIME] =
AgdEvent->TimeUTC[Agd_END_TIME ] = (time_t) 0;
AgdEvent->TimeStatus = Dat_FUTURE;
AgdEvent->Event[0] = '\0';
AgdEvent->Location[0] = '\0';
} }
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
@ -1075,12 +1057,12 @@ void Agd_RemoveEvent (void)
/***** Get data of the event from database *****/ /***** Get data of the event from database *****/
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod; AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
Agd_GetDataOfEventByCod (&AgdEvent); // Inside this function, the course is checked to be the current one Agd_GetDataOfEventByCod (&AgdEvent);
/***** Remove event *****/ /***** Remove event *****/
sprintf (Query,"DELETE FROM agendas" sprintf (Query,"DELETE FROM agendas"
" WHERE AgdCod='%ld' AND UsrCod='%ld'", " WHERE AgdCod='%ld' AND UsrCod='%ld'",
AgdEvent.AgdCod,Gbl.Usrs.Me.UsrDat.UsrCod); AgdEvent.AgdCod,AgdEvent.UsrCod);
DB_QueryDELETE (Query,"can not remove event"); DB_QueryDELETE (Query,"can not remove event");
/***** Write message to show the change made *****/ /***** Write message to show the change made *****/
@ -1112,7 +1094,7 @@ void Agd_HideEvent (void)
/***** Set event private *****/ /***** Set event private *****/
sprintf (Query,"UPDATE agendas SET Hidden='Y'" sprintf (Query,"UPDATE agendas SET Hidden='Y'"
" WHERE AgdCod='%ld' AND UsrCod='%ld'", " WHERE AgdCod='%ld' AND UsrCod='%ld'",
AgdEvent.AgdCod,Gbl.Usrs.Me.UsrDat.UsrCod); AgdEvent.AgdCod,AgdEvent.UsrCod);
DB_QueryUPDATE (Query,"can not hide event"); DB_QueryUPDATE (Query,"can not hide event");
/***** Write message to show the change made *****/ /***** Write message to show the change made *****/
@ -1144,7 +1126,7 @@ void Agd_UnhideEvent (void)
/***** Set event public *****/ /***** Set event public *****/
sprintf (Query,"UPDATE agendas SET Hidden='N'" sprintf (Query,"UPDATE agendas SET Hidden='N'"
" WHERE AgdCod='%ld' AND UsrCod='%ld'", " WHERE AgdCod='%ld' AND UsrCod='%ld'",
AgdEvent.AgdCod,Gbl.Usrs.Me.UsrDat.UsrCod); AgdEvent.AgdCod,AgdEvent.UsrCod);
DB_QueryUPDATE (Query,"can not show event"); DB_QueryUPDATE (Query,"can not show event");
/***** Write message to show the change made *****/ /***** Write message to show the change made *****/
@ -1177,7 +1159,7 @@ void Agd_MakeEventPrivate (void)
/***** Make event private *****/ /***** Make event private *****/
sprintf (Query,"UPDATE agendas SET Public='N'" sprintf (Query,"UPDATE agendas SET Public='N'"
" WHERE AgdCod='%ld' AND UsrCod='%ld'", " WHERE AgdCod='%ld' AND UsrCod='%ld'",
AgdEvent.AgdCod,Gbl.Usrs.Me.UsrDat.UsrCod); AgdEvent.AgdCod,AgdEvent.UsrCod);
DB_QueryUPDATE (Query,"can not make event private"); DB_QueryUPDATE (Query,"can not make event private");
/***** Write message to show the change made *****/ /***** Write message to show the change made *****/
@ -1209,7 +1191,7 @@ void Agd_MakeEventPublic (void)
/***** Make event public *****/ /***** Make event public *****/
sprintf (Query,"UPDATE agendas SET Public='Y'" sprintf (Query,"UPDATE agendas SET Public='Y'"
" WHERE AgdCod='%ld' AND UsrCod='%ld'", " WHERE AgdCod='%ld' AND UsrCod='%ld'",
AgdEvent.AgdCod,Gbl.Usrs.Me.UsrDat.UsrCod); AgdEvent.AgdCod,AgdEvent.UsrCod);
DB_QueryUPDATE (Query,"can not make event public"); DB_QueryUPDATE (Query,"can not make event public");
/***** Write message to show the change made *****/ /***** Write message to show the change made *****/
@ -1225,14 +1207,14 @@ void Agd_MakeEventPublic (void)
/*********** Check if the title or the folder of an event exists *************/ /*********** Check if the title or the folder of an event exists *************/
/*****************************************************************************/ /*****************************************************************************/
static bool Agd_CheckIfSimilarEventExists (const char *Field,const char *Value,long AgdCod) static bool Agd_CheckIfSimilarEventExists (struct AgendaEvent *AgdEvent)
{ {
char Query[512]; char Query[256+Agd_MAX_LENGTH_EVENT];
/***** Get number of events with a field value from database *****/ /***** Get number of events with a field value from database *****/
sprintf (Query,"SELECT COUNT(*) FROM agendas" sprintf (Query,"SELECT COUNT(*) FROM agendas"
" WHERE UsrCod='%ld' AND %s='%s' AND AgdCod<>'%ld'", " WHERE UsrCod='%ld' AND Event='%s' AND AgdCod<>'%ld'",
Gbl.Usrs.Me.UsrDat.UsrCod,Field,Value,AgdCod); AgdEvent->UsrCod,AgdEvent->Event,AgdEvent->AgdCod);
return (DB_QueryCOUNT (Query,"can not get similar events") != 0); return (DB_QueryCOUNT (Query,"can not get similar events") != 0);
} }
@ -1264,11 +1246,11 @@ void Agd_RequestCreatOrEditEvent (void)
ItsANewEvent = ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L); ItsANewEvent = ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L);
/***** Get from the database the data of the event *****/ /***** Get from the database the data of the event *****/
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
if (ItsANewEvent) if (ItsANewEvent)
{ {
/* Initialize to empty event */ /* Initialize to empty event */
AgdEvent.AgdCod = -1L; AgdEvent.AgdCod = -1L;
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
AgdEvent.TimeUTC[Agd_START_TIME] = Gbl.StartExecutionTimeUTC; AgdEvent.TimeUTC[Agd_START_TIME] = Gbl.StartExecutionTimeUTC;
AgdEvent.TimeUTC[Agd_END_TIME ] = Gbl.StartExecutionTimeUTC + (2 * 60 * 60); // +2 hours AgdEvent.TimeUTC[Agd_END_TIME ] = Gbl.StartExecutionTimeUTC + (2 * 60 * 60); // +2 hours
AgdEvent.TimeStatus = Dat_FUTURE; AgdEvent.TimeStatus = Dat_FUTURE;
@ -1277,8 +1259,6 @@ void Agd_RequestCreatOrEditEvent (void)
} }
else else
{ {
AgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
/* Get data of the event from database */ /* Get data of the event from database */
Agd_GetDataOfEventByCod (&AgdEvent); Agd_GetDataOfEventByCod (&AgdEvent);
@ -1376,58 +1356,49 @@ void Agd_RecFormEvent (void)
extern const char *Txt_You_must_specify_the_title_of_the_event; extern const char *Txt_You_must_specify_the_title_of_the_event;
extern const char *Txt_Created_new_event_X; extern const char *Txt_Created_new_event_X;
extern const char *Txt_The_event_has_been_modified; extern const char *Txt_The_event_has_been_modified;
struct AgendaEvent OldAgdEvent; struct AgendaEvent AgdEvent;
struct AgendaEvent NewAgdEvent;
bool ItsANewEvent; bool ItsANewEvent;
bool NewEventIsCorrect = true; bool NewEventIsCorrect = true;
char Txt[Cns_MAX_BYTES_TEXT+1]; char Txt[Cns_MAX_BYTES_TEXT+1];
/***** Get the code of the event *****/ /***** Get the code of the event *****/
ItsANewEvent = ((NewAgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L); ItsANewEvent = ((AgdEvent.AgdCod = Agd_GetParamAgdCod ()) == -1L);
if (!ItsANewEvent)
{
/* Get data of the old (current) event from database */
OldAgdEvent.AgdCod = NewAgdEvent.AgdCod;
OldAgdEvent.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
Agd_GetDataOfEventByCod (&OldAgdEvent);
}
/***** Get start/end date-times *****/ /***** Get start/end date-times *****/
NewAgdEvent.TimeUTC[Agd_START_TIME] = Dat_GetTimeUTCFromForm ("StartTimeUTC"); AgdEvent.TimeUTC[Agd_START_TIME] = Dat_GetTimeUTCFromForm ("StartTimeUTC");
NewAgdEvent.TimeUTC[Agd_END_TIME ] = Dat_GetTimeUTCFromForm ("EndTimeUTC" ); AgdEvent.TimeUTC[Agd_END_TIME ] = Dat_GetTimeUTCFromForm ("EndTimeUTC" );
/***** Get event *****/ /***** Get event *****/
Par_GetParToText ("Location",NewAgdEvent.Location,Agd_MAX_LENGTH_LOCATION); Par_GetParToText ("Location",AgdEvent.Location,Agd_MAX_LENGTH_LOCATION);
/***** Get event *****/ /***** Get event *****/
Par_GetParToText ("Event",NewAgdEvent.Event,Agd_MAX_LENGTH_EVENT); Par_GetParToText ("Event",AgdEvent.Event,Agd_MAX_LENGTH_EVENT);
/***** Get text *****/ /***** Get text *****/
Par_GetParToHTML ("Txt",Txt,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous) Par_GetParToHTML ("Txt",Txt,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous)
/***** Adjust dates *****/ /***** Adjust dates *****/
if (NewAgdEvent.TimeUTC[Agd_START_TIME] == 0) if (AgdEvent.TimeUTC[Agd_START_TIME] == 0)
NewAgdEvent.TimeUTC[Agd_START_TIME] = Gbl.StartExecutionTimeUTC; AgdEvent.TimeUTC[Agd_START_TIME] = Gbl.StartExecutionTimeUTC;
if (NewAgdEvent.TimeUTC[Agd_END_TIME] == 0) if (AgdEvent.TimeUTC[Agd_END_TIME] == 0)
NewAgdEvent.TimeUTC[Agd_END_TIME] = NewAgdEvent.TimeUTC[Agd_START_TIME] + 2*60*60; // +2 hours AgdEvent.TimeUTC[Agd_END_TIME] = AgdEvent.TimeUTC[Agd_START_TIME] + 2*60*60; // +2 hours
/***** Check if event is correct *****/ /***** Check if event is correct *****/
if (!NewAgdEvent.Location[0]) // If there is no event if (!AgdEvent.Location[0]) // If there is no event
{ {
NewEventIsCorrect = false; NewEventIsCorrect = false;
Lay_ShowAlert (Lay_WARNING,Txt_You_must_specify_the_title_of_the_event); Lay_ShowAlert (Lay_WARNING,Txt_You_must_specify_the_title_of_the_event);
} }
/***** Check if event is correct *****/ /***** Check if event is correct *****/
if (NewAgdEvent.Event[0]) // If there's event if (AgdEvent.Event[0]) // If there's event
{ {
/* If title of event was in database... */ /* If title of event was in database... */
if (Agd_CheckIfSimilarEventExists ("Event",NewAgdEvent.Event,NewAgdEvent.AgdCod)) if (Agd_CheckIfSimilarEventExists (&AgdEvent))
{ {
NewEventIsCorrect = false; NewEventIsCorrect = false;
sprintf (Gbl.Message,Txt_Already_existed_an_event_with_the_title_X, sprintf (Gbl.Message,Txt_Already_existed_an_event_with_the_title_X,
NewAgdEvent.Event); AgdEvent.Event);
Lay_ShowAlert (Lay_WARNING,Gbl.Message); Lay_ShowAlert (Lay_WARNING,Gbl.Message);
} }
} }
@ -1442,15 +1413,15 @@ void Agd_RecFormEvent (void)
{ {
if (ItsANewEvent) if (ItsANewEvent)
{ {
Agd_CreateEvent (&NewAgdEvent,Txt); // Add new event to database Agd_CreateEvent (&AgdEvent,Txt); // Add new event to database
/***** Write success message *****/ /***** Write success message *****/
sprintf (Gbl.Message,Txt_Created_new_event_X,NewAgdEvent.Event); sprintf (Gbl.Message,Txt_Created_new_event_X,AgdEvent.Event);
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
} }
else else
{ {
Agd_UpdateEvent (&NewAgdEvent,Txt); Agd_UpdateEvent (&AgdEvent,Txt);
/***** Write success message *****/ /***** Write success message *****/
Lay_ShowAlert (Lay_SUCCESS,Txt_The_event_has_been_modified); Lay_ShowAlert (Lay_SUCCESS,Txt_The_event_has_been_modified);
@ -1481,7 +1452,7 @@ static void Agd_CreateEvent (struct AgendaEvent *AgdEvent,const char *Txt)
" VALUES" " VALUES"
" ('%ld',FROM_UNIXTIME('%ld'),FROM_UNIXTIME('%ld')," " ('%ld',FROM_UNIXTIME('%ld'),FROM_UNIXTIME('%ld'),"
"'%s','%s','%s')", "'%s','%s','%s')",
Gbl.Usrs.Me.UsrDat.UsrCod, AgdEvent->UsrCod,
AgdEvent->TimeUTC[Agd_START_TIME], AgdEvent->TimeUTC[Agd_START_TIME],
AgdEvent->TimeUTC[Agd_END_TIME ], AgdEvent->TimeUTC[Agd_END_TIME ],
AgdEvent->Event, AgdEvent->Event,
@ -1507,7 +1478,7 @@ static void Agd_UpdateEvent (struct AgendaEvent *AgdEvent,const char *Txt)
AgdEvent->TimeUTC[Agd_START_TIME], AgdEvent->TimeUTC[Agd_START_TIME],
AgdEvent->TimeUTC[Agd_END_TIME ], AgdEvent->TimeUTC[Agd_END_TIME ],
AgdEvent->Event,AgdEvent->Location,Txt, AgdEvent->Event,AgdEvent->Location,Txt,
AgdEvent->AgdCod,Gbl.Usrs.Me.UsrDat.UsrCod); AgdEvent->AgdCod,AgdEvent->UsrCod);
DB_QueryUPDATE (Query,"can not update event"); DB_QueryUPDATE (Query,"can not update event");
} }

View File

@ -185,13 +185,14 @@
/****************************** Public constants *****************************/ /****************************** Public constants *****************************/
/*****************************************************************************/ /*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 16.91.5 (2016-12-08)" #define Log_PLATFORM_VERSION "SWAD 16.91.6 (2016-12-09)"
#define CSS_FILE "swad16.86.5.css" #define CSS_FILE "swad16.86.5.css"
#define JS_FILE "swad16.90.2.js" #define JS_FILE "swad16.90.2.js"
// Number of lines (includes comments but not blank lines) has been got with the following command: // Number of lines (includes comments but not blank lines) has been got with the following command:
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1 // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1
/* /*
Version 16.91.6: Dec 09, 2016 Code refactoring in agenda. (210128 lines)
Version 16.91.5: Dec 08, 2016 Removed author in agenda events. (210148 lines) Version 16.91.5: Dec 08, 2016 Removed author in agenda events. (210148 lines)
Version 16.91.4: Dec 07, 2016 Default ordering in agendas is start date. (210189 lines) Version 16.91.4: Dec 07, 2016 Default ordering in agendas is start date. (210189 lines)
Version 16.91.3: Dec 07, 2016 Dates in agendas are ordered from old to new. (210188 lines) Version 16.91.3: Dec 07, 2016 Dates in agendas are ordered from old to new. (210188 lines)