From af3e9c48bf63a9f58b376ee6714be06f40c00f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Wed, 30 Nov 2016 22:49:48 +0100 Subject: [PATCH] Version 16.80 --- Makefile | 2 +- swad_action.c | 9 +- swad_action.h | 181 ++++--- swad_agenda.c | 1292 +++++++++++++++++++++++++++++++++++++++++++- swad_agenda.h | 70 ++- swad_changelog.h | 6 +- swad_global.h | 2 +- swad_location.c | 1325 ---------------------------------------------- swad_location.h | 98 ---- swad_menu.c | 1 - swad_text.c | 46 +- 11 files changed, 1433 insertions(+), 1599 deletions(-) delete mode 100644 swad_location.c delete mode 100644 swad_location.h diff --git a/Makefile b/Makefile index c1d5498c4..27ff17615 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ OBJS = swad_account.o swad_action.o swad_agenda.o swad_announcement.o \ swad_help.o swad_hierarchy.o swad_holiday.o \ swad_icon.o swad_ID.o swad_image.o swad_indicator.o \ swad_info.o swad_institution.o \ - swad_layout.o swad_link.o swad_location.o swad_logo.o \ + swad_layout.o swad_link.o swad_logo.o \ swad_mail.o swad_main.o swad_mark.o swad_menu.o swad_message.o \ swad_MFU.o \ swad_network.o swad_nickname.o swad_notice.o swad_notification.o \ diff --git a/swad_action.c b/swad_action.c index bf30463b0..ec2da27a3 100644 --- a/swad_action.c +++ b/swad_action.c @@ -49,7 +49,6 @@ #include "swad_global.h" #include "swad_ID.h" #include "swad_indicator.h" -#include "swad_location.h" #include "swad_mail.h" #include "swad_mark.h" #include "swad_MFU.h" @@ -1327,8 +1326,7 @@ Profile: 1140. ActFrmRolSes Show form to log out and to change current role in this session 1141. ActMyCrs Select one of my courses 1142. ActSeeMyTT Show the timetable of all courses of the logged user - 1143. ActSeeMyAgd Show my agenda (personal organizer) - 1144. ActSeeMyLoc Show my locations + 1144. ActSeeMyLoc Show my agenda (personal organizer) 1145. ActFrmMyAcc Show form to the creation or change of user's account 1146. ActReqEdiRecCom Request the edition of the record with the personal data of the user 1147. ActEdiPrf Show forms to edit preferences @@ -2776,8 +2774,7 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActFrmRolSes */{ 843, 1,TabPrf,ActFrmRolSes ,0x1FE,0x1FE,0x1FE,Act_CONT_NORM,Act_THIS_WINDOW,NULL ,Usr_WriteFormLogout ,"keyuser64x64.gif" }, /* ActMyCrs */{ 987, 2,TabPrf,ActMyCrs ,0x1FE,0x1FE,0x1FE,Act_CONT_NORM,Act_THIS_WINDOW,NULL ,Crs_ReqSelectOneOfMyCourses ,"mygroups64x64.gif" }, /* ActSeeMyTT */{ 408, 3,TabPrf,ActSeeMyTT ,0x1FE,0x1FE,0x1FE,Act_CONT_NORM,Act_THIS_WINDOW,NULL ,TT_ShowClassTimeTable ,"clock64x64.gif" }, - /* ActSeeMyAgd */{1581, 4,TabPrf,ActSeeMyAgd ,0x100,0x100,0x100,Act_CONT_NORM,Act_THIS_WINDOW,NULL ,Agd_ShowMyAgenda ,"date64x64.gif" }, - /* ActSeeMyLoc */{1602, 5,TabPrf,ActSeeMyLoc ,0x100,0x100,0x100,Act_CONT_NORM,Act_THIS_WINDOW,NULL ,Loc_SeeLocations ,"mapmarker64x64.png" }, + /* ActSeeMyLoc */{1602, 5,TabPrf,ActSeeMyLoc ,0x100,0x100,0x100,Act_CONT_NORM,Act_THIS_WINDOW,NULL ,Loc_SeeLocations ,"date64x64.gif" }, /* ActFrmMyAcc */{ 36, 6,TabPrf,ActFrmMyAcc ,0x1FF,0x1FF,0x1FF,Act_CONT_NORM,Act_THIS_WINDOW,NULL ,Acc_ShowFormMyAccount ,"arroba64x64.gif" }, /* ActReqEdiRecCom */{ 285, 7,TabPrf,ActReqEdiRecCom ,0x1FE,0x1FE,0x1FE,Act_CONT_NORM,Act_THIS_WINDOW,NULL ,Rec_ShowFormMySharedRecord ,"card64x64.gif" }, /* ActEdiPrf */{ 673, 8,TabPrf,ActEdiPrf ,0x1FF,0x1FF,0x1FF,Act_CONT_NORM,Act_THIS_WINDOW,NULL ,Pre_EditPrefs ,"heart64x64.gif" }, @@ -4473,7 +4470,7 @@ Act_Action_t Act_FromActCodToAction[1+Act_MAX_ACTION_COD] = // Do not reuse uniq ActLstDupUsr, // #1578 ActLstSimUsr, // #1579 ActRemDupUsr, // #1580 - ActSeeMyAgd, // #1581 + -1, // #1581 (obsolete action) ActSeeMyUsgRep, // #1582 -1, // #1583 (obsolete action) ActChkUsrAcc, // #1584 diff --git a/swad_action.h b/swad_action.h index f2de761ea..9ee2c05e7 100644 --- a/swad_action.h +++ b/swad_action.h @@ -55,7 +55,7 @@ typedef enum typedef int Act_Action_t; // Must be a signed type, because -1 is used to indicate obsolete action -#define Act_NUM_ACTIONS (1+9+51+14+93+73+70+249+186+155+172+36+31+94) +#define Act_NUM_ACTIONS (1+9+51+14+93+73+70+249+186+155+172+36+31+93) #define Act_MAX_ACTION_COD 1610 @@ -1366,107 +1366,106 @@ typedef int Act_Action_t; // Must be a signed type, because -1 is used to indica #define ActFrmRolSes (ActSeeMyUsgRep+ 2) #define ActMyCrs (ActSeeMyUsgRep+ 3) #define ActSeeMyTT (ActSeeMyUsgRep+ 4) -#define ActSeeMyAgd (ActSeeMyUsgRep+ 5) -#define ActSeeMyLoc (ActSeeMyUsgRep+ 6) -#define ActFrmMyAcc (ActSeeMyUsgRep+ 7) -#define ActReqEdiRecCom (ActSeeMyUsgRep+ 8) -#define ActEdiPrf (ActSeeMyUsgRep+ 9) -#define ActAdmBrf (ActSeeMyUsgRep+10) +#define ActSeeMyLoc (ActSeeMyUsgRep+ 5) +#define ActFrmMyAcc (ActSeeMyUsgRep+ 6) +#define ActReqEdiRecCom (ActSeeMyUsgRep+ 7) +#define ActEdiPrf (ActSeeMyUsgRep+ 8) +#define ActAdmBrf (ActSeeMyUsgRep+ 9) // Secondary actions -#define ActReqSndNewPwd (ActSeeMyUsgRep+11) -#define ActSndNewPwd (ActSeeMyUsgRep+12) -#define ActLogOut (ActSeeMyUsgRep+13) -#define ActAutUsrInt (ActSeeMyUsgRep+14) -#define ActAutUsrNew (ActSeeMyUsgRep+15) -#define ActAutUsrChgLan (ActSeeMyUsgRep+16) -#define ActAnnSee (ActSeeMyUsgRep+17) -#define ActChgMyRol (ActSeeMyUsgRep+18) -#define ActFrmNewLoc (ActSeeMyUsgRep+19) -#define ActEdiOneLoc (ActSeeMyUsgRep+20) -#define ActNewLoc (ActSeeMyUsgRep+21) -#define ActChgLoc (ActSeeMyUsgRep+22) -#define ActReqRemLoc (ActSeeMyUsgRep+23) -#define ActRemLoc (ActSeeMyUsgRep+24) -#define ActHidLoc (ActSeeMyUsgRep+25) -#define ActShoLoc (ActSeeMyUsgRep+26) -#define ActChkUsrAcc (ActSeeMyUsgRep+27) -#define ActCreUsrAcc (ActSeeMyUsgRep+28) -#define ActRemID_Me (ActSeeMyUsgRep+29) -#define ActNewIDMe (ActSeeMyUsgRep+30) -#define ActRemOldNic (ActSeeMyUsgRep+31) -#define ActChgNic (ActSeeMyUsgRep+32) -#define ActRemMaiMe (ActSeeMyUsgRep+33) -#define ActNewMaiMe (ActSeeMyUsgRep+34) -#define ActCnfMai (ActSeeMyUsgRep+35) -#define ActFrmChgMyPwd (ActSeeMyUsgRep+36) -#define ActChgPwd (ActSeeMyUsgRep+37) -#define ActReqRemMyAcc (ActSeeMyUsgRep+38) -#define ActRemMyAcc (ActSeeMyUsgRep+39) +#define ActReqSndNewPwd (ActSeeMyUsgRep+10) +#define ActSndNewPwd (ActSeeMyUsgRep+11) +#define ActLogOut (ActSeeMyUsgRep+12) +#define ActAutUsrInt (ActSeeMyUsgRep+13) +#define ActAutUsrNew (ActSeeMyUsgRep+14) +#define ActAutUsrChgLan (ActSeeMyUsgRep+15) +#define ActAnnSee (ActSeeMyUsgRep+16) +#define ActChgMyRol (ActSeeMyUsgRep+17) +#define ActFrmNewLoc (ActSeeMyUsgRep+18) +#define ActEdiOneLoc (ActSeeMyUsgRep+19) +#define ActNewLoc (ActSeeMyUsgRep+20) +#define ActChgLoc (ActSeeMyUsgRep+21) +#define ActReqRemLoc (ActSeeMyUsgRep+22) +#define ActRemLoc (ActSeeMyUsgRep+23) +#define ActHidLoc (ActSeeMyUsgRep+24) +#define ActShoLoc (ActSeeMyUsgRep+25) +#define ActChkUsrAcc (ActSeeMyUsgRep+26) +#define ActCreUsrAcc (ActSeeMyUsgRep+27) +#define ActRemID_Me (ActSeeMyUsgRep+28) +#define ActNewIDMe (ActSeeMyUsgRep+29) +#define ActRemOldNic (ActSeeMyUsgRep+30) +#define ActChgNic (ActSeeMyUsgRep+31) +#define ActRemMaiMe (ActSeeMyUsgRep+32) +#define ActNewMaiMe (ActSeeMyUsgRep+33) +#define ActCnfMai (ActSeeMyUsgRep+34) +#define ActFrmChgMyPwd (ActSeeMyUsgRep+35) +#define ActChgPwd (ActSeeMyUsgRep+36) +#define ActReqRemMyAcc (ActSeeMyUsgRep+37) +#define ActRemMyAcc (ActSeeMyUsgRep+38) -#define ActChgMyData (ActSeeMyUsgRep+40) +#define ActChgMyData (ActSeeMyUsgRep+39) -#define ActReqMyPho (ActSeeMyUsgRep+41) -#define ActDetMyPho (ActSeeMyUsgRep+42) -#define ActUpdMyPho (ActSeeMyUsgRep+43) -#define ActReqRemMyPho (ActSeeMyUsgRep+44) -#define ActRemMyPho (ActSeeMyUsgRep+45) +#define ActReqMyPho (ActSeeMyUsgRep+40) +#define ActDetMyPho (ActSeeMyUsgRep+41) +#define ActUpdMyPho (ActSeeMyUsgRep+42) +#define ActReqRemMyPho (ActSeeMyUsgRep+43) +#define ActRemMyPho (ActSeeMyUsgRep+44) -#define ActEdiPri (ActSeeMyUsgRep+46) -#define ActChgPriPho (ActSeeMyUsgRep+47) -#define ActChgPriPrf (ActSeeMyUsgRep+48) +#define ActEdiPri (ActSeeMyUsgRep+45) +#define ActChgPriPho (ActSeeMyUsgRep+46) +#define ActChgPriPrf (ActSeeMyUsgRep+47) -#define ActReqEdiMyIns (ActSeeMyUsgRep+49) -#define ActChgCtyMyIns (ActSeeMyUsgRep+50) -#define ActChgMyIns (ActSeeMyUsgRep+51) -#define ActChgMyCtr (ActSeeMyUsgRep+52) -#define ActChgMyDpt (ActSeeMyUsgRep+53) -#define ActChgMyOff (ActSeeMyUsgRep+54) -#define ActChgMyOffPho (ActSeeMyUsgRep+55) +#define ActReqEdiMyIns (ActSeeMyUsgRep+48) +#define ActChgCtyMyIns (ActSeeMyUsgRep+49) +#define ActChgMyIns (ActSeeMyUsgRep+50) +#define ActChgMyCtr (ActSeeMyUsgRep+51) +#define ActChgMyDpt (ActSeeMyUsgRep+52) +#define ActChgMyOff (ActSeeMyUsgRep+53) +#define ActChgMyOffPho (ActSeeMyUsgRep+54) -#define ActReqEdiMyNet (ActSeeMyUsgRep+56) -#define ActChgMyNet (ActSeeMyUsgRep+57) +#define ActReqEdiMyNet (ActSeeMyUsgRep+55) +#define ActChgMyNet (ActSeeMyUsgRep+56) -#define ActChgThe (ActSeeMyUsgRep+58) -#define ActReqChgLan (ActSeeMyUsgRep+59) -#define ActChgLan (ActSeeMyUsgRep+60) -#define ActChg1stDay (ActSeeMyUsgRep+61) -#define ActChgCol (ActSeeMyUsgRep+62) -#define ActHidLftCol (ActSeeMyUsgRep+63) -#define ActHidRgtCol (ActSeeMyUsgRep+64) -#define ActShoLftCol (ActSeeMyUsgRep+65) -#define ActShoRgtCol (ActSeeMyUsgRep+66) -#define ActChgIco (ActSeeMyUsgRep+67) -#define ActChgMnu (ActSeeMyUsgRep+68) -#define ActChgNtfPrf (ActSeeMyUsgRep+69) +#define ActChgThe (ActSeeMyUsgRep+57) +#define ActReqChgLan (ActSeeMyUsgRep+58) +#define ActChgLan (ActSeeMyUsgRep+59) +#define ActChg1stDay (ActSeeMyUsgRep+60) +#define ActChgCol (ActSeeMyUsgRep+61) +#define ActHidLftCol (ActSeeMyUsgRep+62) +#define ActHidRgtCol (ActSeeMyUsgRep+63) +#define ActShoLftCol (ActSeeMyUsgRep+64) +#define ActShoRgtCol (ActSeeMyUsgRep+65) +#define ActChgIco (ActSeeMyUsgRep+66) +#define ActChgMnu (ActSeeMyUsgRep+67) +#define ActChgNtfPrf (ActSeeMyUsgRep+68) -#define ActPrnUsrQR (ActSeeMyUsgRep+70) +#define ActPrnUsrQR (ActSeeMyUsgRep+69) -#define ActPrnMyTT (ActSeeMyUsgRep+71) -#define ActEdiTut (ActSeeMyUsgRep+72) -#define ActChgTut (ActSeeMyUsgRep+73) -#define ActChgMyTT1stDay (ActSeeMyUsgRep+74) +#define ActPrnMyTT (ActSeeMyUsgRep+70) +#define ActEdiTut (ActSeeMyUsgRep+71) +#define ActChgTut (ActSeeMyUsgRep+72) +#define ActChgMyTT1stDay (ActSeeMyUsgRep+73) -#define ActReqRemFilBrf (ActSeeMyUsgRep+75) -#define ActRemFilBrf (ActSeeMyUsgRep+76) -#define ActRemFolBrf (ActSeeMyUsgRep+77) -#define ActCopBrf (ActSeeMyUsgRep+78) -#define ActPasBrf (ActSeeMyUsgRep+79) -#define ActRemTreBrf (ActSeeMyUsgRep+80) -#define ActFrmCreBrf (ActSeeMyUsgRep+81) -#define ActCreFolBrf (ActSeeMyUsgRep+82) -#define ActCreLnkBrf (ActSeeMyUsgRep+83) -#define ActRenFolBrf (ActSeeMyUsgRep+84) -#define ActRcvFilBrfDZ (ActSeeMyUsgRep+85) -#define ActRcvFilBrfCla (ActSeeMyUsgRep+86) -#define ActExpBrf (ActSeeMyUsgRep+87) -#define ActConBrf (ActSeeMyUsgRep+88) -#define ActZIPBrf (ActSeeMyUsgRep+89) -#define ActReqDatBrf (ActSeeMyUsgRep+90) -#define ActChgDatBrf (ActSeeMyUsgRep+91) -#define ActDowBrf (ActSeeMyUsgRep+92) +#define ActReqRemFilBrf (ActSeeMyUsgRep+74) +#define ActRemFilBrf (ActSeeMyUsgRep+75) +#define ActRemFolBrf (ActSeeMyUsgRep+76) +#define ActCopBrf (ActSeeMyUsgRep+77) +#define ActPasBrf (ActSeeMyUsgRep+78) +#define ActRemTreBrf (ActSeeMyUsgRep+79) +#define ActFrmCreBrf (ActSeeMyUsgRep+80) +#define ActCreFolBrf (ActSeeMyUsgRep+81) +#define ActCreLnkBrf (ActSeeMyUsgRep+82) +#define ActRenFolBrf (ActSeeMyUsgRep+83) +#define ActRcvFilBrfDZ (ActSeeMyUsgRep+84) +#define ActRcvFilBrfCla (ActSeeMyUsgRep+85) +#define ActExpBrf (ActSeeMyUsgRep+86) +#define ActConBrf (ActSeeMyUsgRep+87) +#define ActZIPBrf (ActSeeMyUsgRep+88) +#define ActReqDatBrf (ActSeeMyUsgRep+89) +#define ActChgDatBrf (ActSeeMyUsgRep+90) +#define ActDowBrf (ActSeeMyUsgRep+91) -#define ActReqRemOldBrf (ActSeeMyUsgRep+93) -#define ActRemOldBrf (ActSeeMyUsgRep+94) +#define ActReqRemOldBrf (ActSeeMyUsgRep+92) +#define ActRemOldBrf (ActSeeMyUsgRep+93) /*****************************************************************************/ /******************************** Public types *******************************/ diff --git a/swad_agenda.c b/swad_agenda.c index 0d25e11b9..799ad6447 100644 --- a/swad_agenda.c +++ b/swad_agenda.c @@ -22,50 +22,1300 @@ along with this program. If not, see . */ /*****************************************************************************/ -/*********************************** Headers *********************************/ +/********************************* Headers ***********************************/ /*****************************************************************************/ -// #include // For boolean type -// #include // For sprintf -// #include // For string functions +#include // For PATH_MAX +#include // For NULL +#include // For calloc +#include // For string functions -// #include "swad_database.h" -// #include "swad_follow.h" -// #include "swad_global.h" -// #include "swad_notification.h" -// #include "swad_profile.h" -// #include "swad_user.h" +#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" /*****************************************************************************/ -/****************************** Public constants *****************************/ +/************** External global variables from others modules ****************/ /*****************************************************************************/ +extern struct Globals Gbl; + /*****************************************************************************/ /***************************** Private constants *****************************/ /*****************************************************************************/ /*****************************************************************************/ -/****************************** Internal types *******************************/ +/******************************* Private types *******************************/ /*****************************************************************************/ /*****************************************************************************/ -/************** External global variables from others modules ****************/ -/*****************************************************************************/ - -// extern struct Globals Gbl; - -/*****************************************************************************/ -/************************* Internal global variables *************************/ +/***************************** Private variables *****************************/ /*****************************************************************************/ /*****************************************************************************/ /***************************** Private prototypes ****************************/ /*****************************************************************************/ +static void Loc_ShowAllLocations (void); +static bool Loc_CheckIfICanCreateLocations (void); +static void Loc_PutIconsListLocations (void); +static void Loc_PutIconToCreateNewLoc (void); +static void Loc_PutButtonToCreateNewLoc (void); +static void Loc_PutParamsToCreateNewLoc (void); +static void Loc_ShowOneLocation (long LocCod); +static void Loc_WriteLocAuthor (struct Location *Loc); +static void Loc_GetParamLocOrderType (void); + +static void Loc_PutFormsToRemEditOneLoc (long LocCod,bool Hidden); +static void Loc_PutParams (void); +static void Loc_GetDataOfLocation (struct Location *Loc,const char *Query); +static void Loc_GetLocationTxtFromDB (long LocCod,char *Txt); +static void Loc_PutParamLocCod (long LocCod); +static bool Loc_CheckIfSimilarLocationExists (const char *Field,const char *Value,long LocCod); +static void Loc_CreateLocation (struct Location *Loc,const char *Txt); +static void Loc_UpdateLocation (struct Location *Loc,const char *Txt); + /*****************************************************************************/ -/******************** Show my agenda (personal organizer) ********************/ +/************************* List all the locations ****************************/ /*****************************************************************************/ -void Agd_ShowMyAgenda (void) +void Loc_SeeLocations (void) { + /***** Get parameters *****/ + Loc_GetParamLocOrderType (); + Grp_GetParamWhichGrps (); + Pag_GetParamPagNum (Pag_ASSIGNMENTS); + + /***** Show all the locations *****/ + Loc_ShowAllLocations (); + } + +/*****************************************************************************/ +/************************* Show all the locations ****************************/ +/*****************************************************************************/ + +static void Loc_ShowAllLocations (void) + { + extern const char *Hlp_PROFILE_Location; + extern const char *Txt_Agenda; + 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_Location; + extern const char *Txt_Event; + extern const char *Txt_No_locations; + Loc_Order_t Order; + struct Pagination Pagination; + unsigned NumLoc; + + /***** Get list of locations *****/ + Loc_GetListLocations (); + + /***** Compute variables related to pagination *****/ + Pagination.NumItems = Gbl.Usrs.Me.Locs.Num; + Pagination.CurrentPage = (int) Gbl.Pag.CurrentPage; + Pag_CalculatePagination (&Pagination); + Gbl.Pag.CurrentPage = (unsigned) Pagination.CurrentPage; + + /***** Write links to pages *****/ + if (Pagination.MoreThanOnePage) + Pag_WriteLinksToPagesCentered (Pag_ASSIGNMENTS,0,&Pagination); + + /***** Start frame *****/ + Lay_StartRoundFrame ("100%",Txt_Agenda, + Loc_PutIconsListLocations,Hlp_PROFILE_Location); + + if (Gbl.Usrs.Me.Locs.Num) + { + /***** Table head *****/ + fprintf (Gbl.F.Out,"" + ""); + for (Order = Loc_ORDER_BY_START_DATE; + Order <= Loc_ORDER_BY_END_DATE; + Order++) + { + fprintf (Gbl.F.Out,""); + } + fprintf (Gbl.F.Out,"" + "" + "", + Txt_Location, + Txt_Event); + + /***** Write all the locations *****/ + for (NumLoc = Pagination.FirstItemVisible; + NumLoc <= Pagination.LastItemVisible; + NumLoc++) + Loc_ShowOneLocation (Gbl.Usrs.Me.Locs.LstLocCods[NumLoc - 1]); + + /***** End table *****/ + fprintf (Gbl.F.Out,"
"); + Act_FormStart (ActSeeMyLoc); + Grp_PutParamWhichGrps (); + Pag_PutHiddenParamPagNum (Gbl.Pag.CurrentPage); + Par_PutHiddenParamUnsigned ("Order",(unsigned) Order); + Act_LinkFormSubmit (Txt_ASG_ATT_OR_SVY_HELP_ORDER[Order],"TIT_TBL",NULL); + if (Order == Gbl.Usrs.Me.Locs.SelectedOrderType) + fprintf (Gbl.F.Out,""); + fprintf (Gbl.F.Out,"%s",Txt_ASG_ATT_OR_SVY_ORDER[Order]); + if (Order == Gbl.Usrs.Me.Locs.SelectedOrderType) + fprintf (Gbl.F.Out,""); + fprintf (Gbl.F.Out,""); + Act_FormEnd (); + fprintf (Gbl.F.Out,"" + "%s" + "" + "%s" + "
"); + } + else // No locations created + Lay_ShowAlert (Lay_INFO,Txt_No_locations); + + /***** Button to create a new location *****/ + if (Loc_CheckIfICanCreateLocations ()) + Loc_PutButtonToCreateNewLoc (); + + /***** End frame *****/ + Lay_EndRoundFrame (); + + /***** Write again links to pages *****/ + if (Pagination.MoreThanOnePage) + Pag_WriteLinksToPagesCentered (Pag_ASSIGNMENTS,0,&Pagination); + + /***** Free list of locations *****/ + Loc_FreeListLocations (); + } + +/*****************************************************************************/ +/********************* Check if I can create locations ***********************/ +/*****************************************************************************/ + +static bool Loc_CheckIfICanCreateLocations (void) + { + return (bool) (Gbl.Usrs.Me.LoggedRole == Rol_TEACHER || + Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM); + } + +/*****************************************************************************/ +/**************** Put contextual icons in list of locations ******************/ +/*****************************************************************************/ + +static void Loc_PutIconsListLocations (void) + { + /***** Put icon to create a new location *****/ + if (Loc_CheckIfICanCreateLocations ()) + Loc_PutIconToCreateNewLoc (); + } + +/*****************************************************************************/ +/******************** Put icon to create a new location **********************/ +/*****************************************************************************/ + +static void Loc_PutIconToCreateNewLoc (void) + { + extern const char *Txt_New_event; + + /***** Put form to create a new location *****/ + Lay_PutContextualLink (ActFrmNewLoc,Loc_PutParamsToCreateNewLoc, + "plus64x64.png", + Txt_New_event,NULL, + NULL); + } + +/*****************************************************************************/ +/******************* Put button to create a new location *********************/ +/*****************************************************************************/ + +static void Loc_PutButtonToCreateNewLoc (void) + { + extern const char *Txt_New_event; + + Act_FormStart (ActFrmNewLoc); + Loc_PutParamsToCreateNewLoc (); + Lay_PutConfirmButton (Txt_New_event); + Act_FormEnd (); + } + +/*****************************************************************************/ +/****************** Put parameters to create a new location ******************/ +/*****************************************************************************/ + +static void Loc_PutParamsToCreateNewLoc (void) + { + Loc_PutHiddenParamLocOrderType (); + Grp_PutParamWhichGrps (); + Pag_PutHiddenParamPagNum (Gbl.Pag.CurrentPage); + } + +/*****************************************************************************/ +/**************************** Show one location ******************************/ +/*****************************************************************************/ + +static void Loc_ShowOneLocation (long LocCod) + { + extern const char *Txt_Today; + static unsigned UniqueId = 0; + struct Location Loc; + char Txt[Cns_MAX_BYTES_TEXT+1]; + + /***** Get data of this location *****/ + Loc.LocCod = LocCod; + Loc_GetDataOfLocationByCod (&Loc); + + /***** Write first row of data of this location *****/ + /* Start date/time */ + UniqueId++; + fprintf (Gbl.F.Out,"" + "" + "" + "", + UniqueId, + Loc.Hidden ? (Loc.Open ? "DATE_GREEN_LIGHT" : + "DATE_RED_LIGHT") : + (Loc.Open ? "DATE_GREEN" : + "DATE_RED"), + Gbl.RowEvenOdd, + UniqueId,Loc.TimeUTC[Loc_START_TIME],Txt_Today); + + /* End date/time */ + UniqueId++; + fprintf (Gbl.F.Out,"" + "" + "", + UniqueId, + Loc.Hidden ? (Loc.Open ? "DATE_GREEN_LIGHT" : + "DATE_RED_LIGHT") : + (Loc.Open ? "DATE_GREEN" : + "DATE_RED"), + Gbl.RowEvenOdd, + UniqueId,Loc.TimeUTC[Loc_END_TIME],Txt_Today); + + /* Location */ + fprintf (Gbl.F.Out,"" + "
%s
", + Gbl.RowEvenOdd, + Loc.Hidden ? "ASG_TITLE_LIGHT" : + "ASG_TITLE", + Loc.Location); + fprintf (Gbl.F.Out,""); + + /* Event */ + fprintf (Gbl.F.Out,"" + "
%s
", + Gbl.RowEvenOdd, + Loc.Hidden ? "ASG_TITLE_LIGHT" : + "ASG_TITLE", + Loc.Event); + fprintf (Gbl.F.Out,"" + ""); + + /***** Write second row of data of this location *****/ + fprintf (Gbl.F.Out,"" + "", + Gbl.RowEvenOdd); + + /* Author of the location */ + Loc_WriteLocAuthor (&Loc); + + /* Forms to remove/edit this location */ + switch (Gbl.Usrs.Me.LoggedRole) + { + case Rol_TEACHER: + case Rol_SYS_ADM: + Loc_PutFormsToRemEditOneLoc (Loc.LocCod,Loc.Hidden); + break; + default: + break; + } + fprintf (Gbl.F.Out,""); + + /* Text of the location */ + Loc_GetLocationTxtFromDB (Loc.LocCod,Txt); + 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,"", + Gbl.RowEvenOdd); + + fprintf (Gbl.F.Out,"

" + "%s" + "

" + "" + "", + Loc.Hidden ? "DAT_LIGHT" : + "DAT", + Txt); + + Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd; + } + +/*****************************************************************************/ +/********************** Write the author of a location ***********************/ +/*****************************************************************************/ + +static void Loc_WriteLocAuthor (struct Location *Loc) + { + 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 *****/ + UsrDat.UsrCod = Loc->UsrCod; + 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,"%s %s", + Loc->Hidden ? "MSG_AUT_LIGHT" : + "MSG_AUT", + FirstName,Surnames); + + /***** Free memory used for user's data *****/ + Usr_UsrDataDestructor (&UsrDat); + } + +/*****************************************************************************/ +/******** Get parameter with the type or order in list of locations **********/ +/*****************************************************************************/ + +static void Loc_GetParamLocOrderType (void) + { + char UnsignedStr[10+1]; + unsigned UnsignedNum; + + Par_GetParToText ("Order",UnsignedStr,10); + if (sscanf (UnsignedStr,"%u",&UnsignedNum) == 1) + Gbl.Usrs.Me.Locs.SelectedOrderType = (Loc_Order_t) UnsignedNum; + else + Gbl.Usrs.Me.Locs.SelectedOrderType = Loc_DEFAULT_ORDER_TYPE; + } + +/*****************************************************************************/ +/**** Put a hidden parameter with the type of order in list of locations *****/ +/*****************************************************************************/ + +void Loc_PutHiddenParamLocOrderType (void) + { + Par_PutHiddenParamUnsigned ("Order",(unsigned) Gbl.Usrs.Me.Locs.SelectedOrderType); + } + +/*****************************************************************************/ +/****************** Put a link (form) to edit one location *******************/ +/*****************************************************************************/ + +static void Loc_PutFormsToRemEditOneLoc (long LocCod,bool Hidden) + { + extern const char *Txt_Remove; + extern const char *Txt_Show; + extern const char *Txt_Hide; + extern const char *Txt_Edit; + + fprintf (Gbl.F.Out,"
"); + + Gbl.Usrs.Me.Locs.LocCodToEdit = LocCod; // Used as parameter in contextual links + + /***** Put form to remove location *****/ + Lay_PutContextualLink (ActReqRemLoc,Loc_PutParams, + "remove-on64x64.png", + Txt_Remove,NULL, + NULL); + + /***** Put form to hide/show location *****/ + if (Hidden) + Lay_PutContextualLink (ActShoLoc,Loc_PutParams, + "eye-slash-on64x64.png", + Txt_Show,NULL, + NULL); + else + Lay_PutContextualLink (ActHidLoc,Loc_PutParams, + "eye-on64x64.png", + Txt_Hide,NULL, + NULL); + + /***** Put form to edit location *****/ + Lay_PutContextualLink (ActEdiOneLoc,Loc_PutParams, + "edit64x64.png", + Txt_Edit,NULL, + NULL); + + fprintf (Gbl.F.Out,"
"); + } + +/*****************************************************************************/ +/********************* Params used to edit a location ************************/ +/*****************************************************************************/ + +static void Loc_PutParams (void) + { + Loc_PutParamLocCod (Gbl.Usrs.Me.Locs.LocCodToEdit); + Loc_PutHiddenParamLocOrderType (); + Grp_PutParamWhichGrps (); + Pag_PutHiddenParamPagNum (Gbl.Pag.CurrentPage); + } + +/*****************************************************************************/ +/************************* List all the locations ****************************/ +/*****************************************************************************/ + +void Loc_GetListLocations (void) + { + char HiddenSubQuery[256]; + char OrderBySubQuery[256]; + char Query[2048]; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned long NumRows; + unsigned NumLoc; + + if (Gbl.Usrs.Me.Locs.LstIsRead) + Loc_FreeListLocations (); + + /***** Get list of locations from database *****/ + switch (Gbl.Usrs.Me.LoggedRole) + { + case Rol_TEACHER: + case Rol_SYS_ADM: + HiddenSubQuery[0] = '\0'; + break; + default: + sprintf (HiddenSubQuery,"AND Hidden='N'"); + break; + } + switch (Gbl.Usrs.Me.Locs.SelectedOrderType) + { + case Loc_ORDER_BY_START_DATE: + sprintf (OrderBySubQuery,"StartTime DESC,EndTime DESC,Location DESC,Event DESC"); + break; + case Loc_ORDER_BY_END_DATE: + sprintf (OrderBySubQuery,"EndTime DESC,StartTime DESC,Location DESC,Event DESC"); + break; + } + sprintf (Query,"SELECT LocCod" + " FROM locations" + " WHERE UsrCod='%ld'%s" + " ORDER BY %s", + Gbl.Usrs.Me.UsrDat.UsrCod,HiddenSubQuery,OrderBySubQuery); + NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get locations"); + + if (NumRows) // Locations found... + { + Gbl.Usrs.Me.Locs.Num = (unsigned) NumRows; + + /***** Create list of locations *****/ + if ((Gbl.Usrs.Me.Locs.LstLocCods = (long *) calloc (NumRows,sizeof (long))) == NULL) + Lay_ShowErrorAndExit ("Not enough memory to store list of locations."); + + /***** Get the locations codes *****/ + for (NumLoc = 0; + NumLoc < Gbl.Usrs.Me.Locs.Num; + NumLoc++) + { + /* Get next location code */ + row = mysql_fetch_row (mysql_res); + if ((Gbl.Usrs.Me.Locs.LstLocCods[NumLoc] = Str_ConvertStrCodToLongCod (row[0])) < 0) + Lay_ShowErrorAndExit ("Error: wrong location code."); + } + } + else + Gbl.Usrs.Me.Locs.Num = 0; + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + + Gbl.Usrs.Me.Locs.LstIsRead = true; + } + +/*****************************************************************************/ +/******************** Get location data using its code ***********************/ +/*****************************************************************************/ + +void Loc_GetDataOfLocationByCod (struct Location *Loc) + { + char Query[1024]; + + /***** Build query *****/ + sprintf (Query,"SELECT LocCod,UsrCod,Hidden," + "UNIX_TIMESTAMP(StartTime)," + "UNIX_TIMESTAMP(EndTime)," + "NOW() BETWEEN StartTime AND EndTime," + "Location,Event" + " FROM locations" + " WHERE LocCod='%ld' AND UsrCod='%ld'", + Loc->LocCod,Gbl.Usrs.Me.UsrDat.UsrCod); + + /***** Get data of location *****/ + Loc_GetDataOfLocation (Loc,Query); + } + +/*****************************************************************************/ +/*************************** Get location data *******************************/ +/*****************************************************************************/ + +static void Loc_GetDataOfLocation (struct Location *Loc,const char *Query) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned long NumRows; + + /***** Clear all location data *****/ + Loc->LocCod = -1L; + Loc->UsrCod = -1L; + Loc->Hidden = false; + Loc->TimeUTC[Loc_START_TIME] = + Loc->TimeUTC[Loc_END_TIME ] = (time_t) 0; + Loc->Open = false; + Loc->Location[0] = '\0'; + Loc->Event[0] = '\0'; + + /***** Get data of location from database *****/ + NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get location data"); + + if (NumRows) // Location found... + { + /* Get row */ + row = mysql_fetch_row (mysql_res); + + /* Get code of the location (row[0]) */ + Loc->LocCod = Str_ConvertStrCodToLongCod (row[0]); + + /* Get author of the location (row[1]) */ + Loc->UsrCod = Str_ConvertStrCodToLongCod (row[1]); + + /* Get whether the location is hidden or not (row[2]) */ + Loc->Hidden = (row[2][0] == 'Y'); + + /* Get start date (row[3] holds the start UTC time) */ + Loc->TimeUTC[Loc_START_TIME] = Dat_GetUNIXTimeFromStr (row[3]); + + /* Get end date (row[4] holds the end UTC time) */ + Loc->TimeUTC[Loc_END_TIME ] = Dat_GetUNIXTimeFromStr (row[4]); + + /* Get whether the location is open or closed (row(5)) */ + Loc->Open = (row[5][0] == '1'); + + /* Get the location (row[6]) */ + strcpy (Loc->Location,row[6]); + + /* Get the event (row[7]) */ + strcpy (Loc->Event,row[7]); + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + } + +/*****************************************************************************/ +/************************** Free list of locations ***************************/ +/*****************************************************************************/ + +void Loc_FreeListLocations (void) + { + if (Gbl.Usrs.Me.Locs.LstIsRead && Gbl.Usrs.Me.Locs.LstLocCods) + { + /***** Free memory used by the list of locations *****/ + free ((void *) Gbl.Usrs.Me.Locs.LstLocCods); + Gbl.Usrs.Me.Locs.LstLocCods = NULL; + Gbl.Usrs.Me.Locs.Num = 0; + Gbl.Usrs.Me.Locs.LstIsRead = false; + } + } + +/*****************************************************************************/ +/********************* Get location text from database ***********************/ +/*****************************************************************************/ + +static void Loc_GetLocationTxtFromDB (long LocCod,char *Txt) + { + char Query[512]; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned long NumRows; + + /***** Get text of location from database *****/ + sprintf (Query,"SELECT Txt FROM locations" + " WHERE LocCod='%ld' AND UsrCod='%ld'", + LocCod,Gbl.Usrs.Me.UsrDat.UsrCod); + NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get location text"); + + /***** 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) + Lay_ShowErrorAndExit ("Error when getting location text."); + } + +/*****************************************************************************/ +/****************** Write parameter with code of location ********************/ +/*****************************************************************************/ + +static void Loc_PutParamLocCod (long LocCod) + { + Par_PutHiddenParamLong ("LocCod",LocCod); + } + +/*****************************************************************************/ +/******************* Get parameter with code of location *********************/ +/*****************************************************************************/ + +long Loc_GetParamLocCod (void) + { + char LongStr[1+10+1]; + + /***** Get parameter with code of location *****/ + Par_GetParToText ("LocCod",LongStr,1+10); + return Str_ConvertStrCodToLongCod (LongStr); + } + +/*****************************************************************************/ +/************* Ask for confirmation of removing of a location ****************/ +/*****************************************************************************/ + +void Loc_AskRemLocation (void) + { + extern const char *Txt_Do_you_really_want_to_remove_the_location_X; + extern const char *Txt_Remove_location; + struct Location Loc; + + /***** Get parameters *****/ + Loc_GetParamLocOrderType (); + Grp_GetParamWhichGrps (); + Pag_GetParamPagNum (Pag_ASSIGNMENTS); + + /***** Get location code *****/ + if ((Loc.LocCod = Loc_GetParamLocCod ()) == -1L) + Lay_ShowErrorAndExit ("Code of location is missing."); + + /***** Get data of the location from database *****/ + Loc_GetDataOfLocationByCod (&Loc); + + /***** Button of confirmation of removing *****/ + Act_FormStart (ActRemLoc); + Loc_PutParamLocCod (Loc.LocCod); + Loc_PutHiddenParamLocOrderType (); + Grp_PutParamWhichGrps (); + Pag_PutHiddenParamPagNum (Gbl.Pag.CurrentPage); + + /***** Ask for confirmation of removing *****/ + sprintf (Gbl.Message,Txt_Do_you_really_want_to_remove_the_location_X, + Loc.Event); + Lay_ShowAlert (Lay_WARNING,Gbl.Message); + Lay_PutRemoveButton (Txt_Remove_location); + Act_FormEnd (); + + /***** Show locations again *****/ + Loc_SeeLocations (); + } + +/*****************************************************************************/ +/***************************** Remove a location *****************************/ +/*****************************************************************************/ + +void Loc_RemoveLocation (void) + { + extern const char *Txt_Location_X_removed; + char Query[512]; + struct Location Loc; + + /***** Get location code *****/ + if ((Loc.LocCod = Loc_GetParamLocCod ()) == -1L) + Lay_ShowErrorAndExit ("Code of location is missing."); + + /***** Get data of the location from database *****/ + Loc_GetDataOfLocationByCod (&Loc); // Inside this function, the course is checked to be the current one + + /***** Remove location *****/ + sprintf (Query,"DELETE FROM locations" + " WHERE LocCod='%ld' AND UsrCod='%ld'", + Loc.LocCod,Gbl.Usrs.Me.UsrDat.UsrCod); + DB_QueryDELETE (Query,"can not remove location"); + + /***** Write message to show the change made *****/ + sprintf (Gbl.Message,Txt_Location_X_removed,Loc.Event); + Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); + + /***** Show locations again *****/ + Loc_SeeLocations (); + } + +/*****************************************************************************/ +/****************************** Hide a location ******************************/ +/*****************************************************************************/ + +void Loc_HideLocation (void) + { + extern const char *Txt_Event_X_is_now_hidden; + char Query[512]; + struct Location Loc; + + /***** Get location code *****/ + if ((Loc.LocCod = Loc_GetParamLocCod ()) == -1L) + Lay_ShowErrorAndExit ("Code of location is missing."); + + /***** Get data of the location from database *****/ + Loc_GetDataOfLocationByCod (&Loc); + + /***** Hide location *****/ + sprintf (Query,"UPDATE locations SET Hidden='Y'" + " WHERE LocCod='%ld' AND UsrCod='%ld'", + Loc.LocCod,Gbl.Usrs.Me.UsrDat.UsrCod); + DB_QueryUPDATE (Query,"can not hide location"); + + /***** Write message to show the change made *****/ + sprintf (Gbl.Message,Txt_Event_X_is_now_hidden,Loc.Event); + Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); + + /***** Show locations again *****/ + Loc_SeeLocations (); + } + +/*****************************************************************************/ +/****************************** Show a location ******************************/ +/*****************************************************************************/ + +void Loc_ShowLocation (void) + { + extern const char *Txt_Event_X_is_now_visible; + char Query[512]; + struct Location Loc; + + /***** Get location code *****/ + if ((Loc.LocCod = Loc_GetParamLocCod ()) == -1L) + Lay_ShowErrorAndExit ("Code of location is missing."); + + /***** Get data of the location from database *****/ + Loc_GetDataOfLocationByCod (&Loc); + + /***** Hide location *****/ + sprintf (Query,"UPDATE locations SET Hidden='N'" + " WHERE LocCod='%ld' AND UsrCod='%ld'", + Loc.LocCod,Gbl.Usrs.Me.UsrDat.UsrCod); + DB_QueryUPDATE (Query,"can not show location"); + + /***** Write message to show the change made *****/ + sprintf (Gbl.Message,Txt_Event_X_is_now_visible,Loc.Event); + Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); + + /***** Show locations again *****/ + Loc_SeeLocations (); + } + +/*****************************************************************************/ +/********* Check if the title or the folder of a location exists *************/ +/*****************************************************************************/ + +static bool Loc_CheckIfSimilarLocationExists (const char *Field,const char *Value,long LocCod) + { + char Query[512]; + + /***** Get number of locations with a field value from database *****/ + sprintf (Query,"SELECT COUNT(*) FROM locations" + " WHERE UsrCod='%ld' AND %s='%s' AND LocCod<>'%ld'", + Gbl.Usrs.Me.UsrDat.UsrCod,Field,Value,LocCod); + return (DB_QueryCOUNT (Query,"can not get similar locations") != 0); + } + +/*****************************************************************************/ +/******************* Put a form to create a new location *********************/ +/*****************************************************************************/ + +void Loc_RequestCreatOrEditLoc (void) + { + extern const char *Hlp_PROFILE_Location_new_location; + extern const char *Hlp_PROFILE_Location_edit_location; + extern const char *The_ClassForm[The_NUM_THEMES]; + extern const char *Txt_New_event; + extern const char *Txt_Edit_location; + 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; + struct Location Loc; + bool ItsANewLocation; + char Txt[Cns_MAX_BYTES_TEXT+1]; + + /***** Get parameters *****/ + Loc_GetParamLocOrderType (); + Grp_GetParamWhichGrps (); + Pag_GetParamPagNum (Pag_ASSIGNMENTS); + + /***** Get the code of the location *****/ + ItsANewLocation = ((Loc.LocCod = Loc_GetParamLocCod ()) == -1L); + + /***** Get from the database the data of the location *****/ + if (ItsANewLocation) + { + /* Initialize to empty location */ + Loc.LocCod = -1L; + Loc.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod; + Loc.TimeUTC[Loc_START_TIME] = Gbl.StartExecutionTimeUTC; + Loc.TimeUTC[Loc_END_TIME ] = Gbl.StartExecutionTimeUTC + (2 * 60 * 60); // +2 hours + Loc.Open = true; + Loc.Location[0] = '\0'; + Loc.Event[0] = '\0'; + } + else + { + /* Get data of the location from database */ + Loc_GetDataOfLocationByCod (&Loc); + + /* Get text of the location from database */ + Loc_GetLocationTxtFromDB (Loc.LocCod,Txt); + } + + /***** Start form *****/ + if (ItsANewLocation) + Act_FormStart (ActNewLoc); + else + { + Act_FormStart (ActChgLoc); + Loc_PutParamLocCod (Loc.LocCod); + } + Loc_PutHiddenParamLocOrderType (); + Grp_PutParamWhichGrps (); + Pag_PutHiddenParamPagNum (Gbl.Pag.CurrentPage); + + /***** Table start *****/ + Lay_StartRoundFrameTable (NULL, + ItsANewLocation ? Txt_New_event : + Txt_Edit_location, + NULL, + ItsANewLocation ? Hlp_PROFILE_Location_new_location : + Hlp_PROFILE_Location_edit_location, + 2); + + /***** Location *****/ + fprintf (Gbl.F.Out,"" + "" + "%s:" + "" + "" + "" + "" + "", + The_ClassForm[Gbl.Prefs.Theme], + Txt_Location, + Loc_MAX_LENGTH_LOCATION,Loc.Location); + + /***** Event *****/ + fprintf (Gbl.F.Out,"" + "" + "%s:" + "" + "" + "" + "" + "", + The_ClassForm[Gbl.Prefs.Theme], + Txt_Event, + Loc_MAX_LENGTH_EVENT,Loc.Event); + + /***** Start and end dates *****/ + Dat_PutFormStartEndClientLocalDateTimes (Loc.TimeUTC); + + /***** Text *****/ + fprintf (Gbl.F.Out,"" + "" + "%s:" + "" + "" + "" + "" + ""); + + /***** New location *****/ + if (ItsANewLocation) + Lay_EndRoundFrameTableWithButton (Lay_CREATE_BUTTON,Txt_Create_event); + else + Lay_EndRoundFrameTableWithButton (Lay_CONFIRM_BUTTON,Txt_Save); + Act_FormEnd (); + + /***** Show current locations, if any *****/ + Loc_ShowAllLocations (); + } + +/*****************************************************************************/ +/******************** Receive form to create a new location ******************/ +/*****************************************************************************/ + +void Loc_RecFormLocation (void) + { + extern const char *Txt_Already_existed_a_location_with_the_title_X; + extern const char *Txt_You_must_specify_the_title_of_the_location; + extern const char *Txt_Created_new_location_X; + extern const char *Txt_The_event_has_been_modified; + struct Location OldLoc; + struct Location NewLoc; + bool ItsANewLocation; + bool NewLocationIsCorrect = true; + char Txt[Cns_MAX_BYTES_TEXT+1]; + + /***** Get the code of the location *****/ + ItsANewLocation = ((NewLoc.LocCod = Loc_GetParamLocCod ()) == -1L); + + if (!ItsANewLocation) + { + /* Get data of the old (current) location from database */ + OldLoc.LocCod = NewLoc.LocCod; + Loc_GetDataOfLocationByCod (&OldLoc); + } + + /***** Get start/end date-times *****/ + NewLoc.TimeUTC[Loc_START_TIME] = Dat_GetTimeUTCFromForm ("StartTimeUTC"); + NewLoc.TimeUTC[Loc_END_TIME ] = Dat_GetTimeUTCFromForm ("EndTimeUTC" ); + + /***** Get location *****/ + Par_GetParToText ("Location",NewLoc.Location,Loc_MAX_LENGTH_LOCATION); + + /***** Get event *****/ + Par_GetParToText ("Event",NewLoc.Event,Loc_MAX_LENGTH_EVENT); + + /***** Get text *****/ + Par_GetParToHTML ("Txt",Txt,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous) + + /***** Adjust dates *****/ + if (NewLoc.TimeUTC[Loc_START_TIME] == 0) + NewLoc.TimeUTC[Loc_START_TIME] = Gbl.StartExecutionTimeUTC; + if (NewLoc.TimeUTC[Loc_END_TIME] == 0) + NewLoc.TimeUTC[Loc_END_TIME] = NewLoc.TimeUTC[Loc_START_TIME] + 2*60*60; // +2 hours + + /***** Check if location is correct *****/ + if (!NewLoc.Location[0]) // If there is no location + { + NewLocationIsCorrect = false; + Lay_ShowAlert (Lay_WARNING,Txt_You_must_specify_the_title_of_the_location); + } + + /***** Check if event is correct *****/ + if (NewLoc.Event[0]) // If there's event + { + /* If title of location was in database... */ + if (Loc_CheckIfSimilarLocationExists ("Event",NewLoc.Event,NewLoc.LocCod)) + { + NewLocationIsCorrect = false; + sprintf (Gbl.Message,Txt_Already_existed_a_location_with_the_title_X, + NewLoc.Event); + Lay_ShowAlert (Lay_WARNING,Gbl.Message); + } + } + else // If there is no event + { + NewLocationIsCorrect = false; + Lay_ShowAlert (Lay_WARNING,Txt_You_must_specify_the_title_of_the_location); + } + + /***** Create a new location or update an existing one *****/ + if (NewLocationIsCorrect) + { + if (ItsANewLocation) + { + Loc_CreateLocation (&NewLoc,Txt); // Add new location to database + + /***** Write success message *****/ + sprintf (Gbl.Message,Txt_Created_new_location_X,NewLoc.Event); + Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); + } + else + { + Loc_UpdateLocation (&NewLoc,Txt); + + /***** Write success message *****/ + Lay_ShowAlert (Lay_SUCCESS,Txt_The_event_has_been_modified); + } + + /* Free memory for list of selected groups */ + Grp_FreeListCodSelectedGrps (); + + /***** Show locations again *****/ + Loc_SeeLocations (); + } + else + // TODO: The form should be filled with partial data, now is always empty + Loc_RequestCreatOrEditLoc (); + } + +/*****************************************************************************/ +/************************* Create a new location *****************************/ +/*****************************************************************************/ + +static void Loc_CreateLocation (struct Location *Loc,const char *Txt) + { + char Query[1024+Cns_MAX_BYTES_TEXT]; + + /***** Create a new location *****/ + sprintf (Query,"INSERT INTO locations" + " (UsrCod,StartTime,EndTime,Location,Event,Txt)" + " VALUES" + " ('%ld',FROM_UNIXTIME('%ld'),FROM_UNIXTIME('%ld')," + "'%s','%s','%s')", + Gbl.Usrs.Me.UsrDat.UsrCod, + Loc->TimeUTC[Loc_START_TIME], + Loc->TimeUTC[Loc_END_TIME ], + Loc->Location, + Loc->Event, + Txt); + Loc->LocCod = DB_QueryINSERTandReturnCode (Query,"can not create new location"); + } + +/*****************************************************************************/ +/********************** Update an existing location **************************/ +/*****************************************************************************/ + +static void Loc_UpdateLocation (struct Location *Loc,const char *Txt) + { + char Query[1024+Cns_MAX_BYTES_TEXT]; + + /***** Update the data of the location *****/ + sprintf (Query,"UPDATE locations SET " + "StartTime=FROM_UNIXTIME('%ld')," + "EndTime=FROM_UNIXTIME('%ld')," + "Location='%s',Event='%s',Txt='%s'" + " WHERE LocCod='%ld' AND UsrCod='%ld'", + Loc->TimeUTC[Loc_START_TIME], + Loc->TimeUTC[Loc_END_TIME ], + Loc->Location,Loc->Event,Txt, + Loc->LocCod,Gbl.Usrs.Me.UsrDat.UsrCod); + DB_QueryUPDATE (Query,"can not update location"); + } + +/*****************************************************************************/ +/******************** Remove all the locations of a user *********************/ +/*****************************************************************************/ + +void Loc_RemoveUsrLocations (long UsrCod) + { + char Query[128]; + + /***** Remove locations *****/ + sprintf (Query,"DELETE FROM locations WHERE UsrCod='%ld'",UsrCod); + DB_QueryDELETE (Query,"can not remove all the locations of a user"); + } + +/*****************************************************************************/ +/******************* Get number of locations from a user *********************/ +/*****************************************************************************/ + +unsigned Loc_GetNumLocationsFromUsr (long UsrCod) + { + char Query[128]; + + /***** Get number of locations in a course from database *****/ + sprintf (Query,"SELECT COUNT(*) FROM locations WHERE UsrCod='%ld'", + UsrCod); + return (unsigned) DB_QueryCOUNT (Query,"can not get number of locations from user"); + } + +/*****************************************************************************/ +/******************** Get number of users with locations *********************/ +/*****************************************************************************/ +// Returns the number of users with locations in a given scope + +unsigned Loc_GetNumUsrsWithLocations (Sco_Scope_t Scope) + { + char Query[1024]; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned NumUsrs; + + /***** Get number of courses with locations from database *****/ + switch (Scope) + { + case Sco_SCOPE_SYS: + sprintf (Query,"SELECT COUNT(DISTINCT UsrCod)" + " FROM locations" + " WHERE UsrCod>'0'"); + break; + case Sco_SCOPE_CTY: + sprintf (Query,"SELECT COUNT(DISTINCT locations.UsrCod)" + " FROM institutions,centres,degrees,courses,crs_usr,locations" + " 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=locations.UsrCod", + Gbl.CurrentCty.Cty.CtyCod); + break; + case Sco_SCOPE_INS: + sprintf (Query,"SELECT COUNT(DISTINCT locations.UsrCod)" + " FROM centres,degrees,courses,crs_usr,locations" + " 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=locations.UsrCod", + Gbl.CurrentIns.Ins.InsCod); + break; + case Sco_SCOPE_CTR: + sprintf (Query,"SELECT COUNT(DISTINCT locations.UsrCod)" + " FROM degrees,courses,crs_usr,locations" + " WHERE degrees.CtrCod='%ld'" + " AND degrees.DegCod=courses.DegCod" + " AND courses.Status=0" + " AND courses.CrsCod=crs_usr.CrsCod" + " AND crs_usr.UsrCod=locations.UsrCod", + Gbl.CurrentCtr.Ctr.CtrCod); + break; + case Sco_SCOPE_DEG: + sprintf (Query,"SELECT COUNT(DISTINCT locations.UsrCod)" + " FROM courses,crs_usr,locations" + " WHERE courses.DegCod='%ld'" + " AND courses.Status=0" + " AND courses.CrsCod=crs_usr.CrsCod" + " AND crs_usr.UsrCod=locations.UsrCod", + Gbl.CurrentDeg.Deg.DegCod); + break; + case Sco_SCOPE_CRS: + sprintf (Query,"SELECT COUNT(DISTINCT locations.UsrCod)" + " FROM crs_usr,locations" + " WHERE crs_usr.CrsCod='%ld'" + " AND crs_usr.UsrCod=locations.UsrCod", + Gbl.CurrentCrs.Crs.CrsCod); + break; + default: + Lay_ShowErrorAndExit ("Wrong scope."); + break; + } + DB_QuerySELECT (Query,&mysql_res,"can not get number of users with locations"); + + /***** 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 locations."); + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + + return NumUsrs; + } + +/*****************************************************************************/ +/************************* Get number of locations ***************************/ +/*****************************************************************************/ +// Returns the number of locations in a given scope + +unsigned Loc_GetNumLocations (Sco_Scope_t Scope) + { + char Query[1024]; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned NumLocations; + + /***** Get number of locations from database *****/ + switch (Scope) + { + case Sco_SCOPE_SYS: + sprintf (Query,"SELECT COUNT(*)" + " FROM locations" + " WHERE UsrCod>'0'"); + break; + case Sco_SCOPE_CTY: + sprintf (Query,"SELECT COUNT(*)" + " FROM institutions,centres,degrees,courses,crs_usr,locations" + " 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=locations.UsrCod", + Gbl.CurrentCty.Cty.CtyCod); + break; + case Sco_SCOPE_INS: + sprintf (Query,"SELECT COUNT(*)" + " FROM centres,degrees,courses,crs_usr,locations" + " WHERE centres.InsCod='%ld'" + " AND centres.CtrCod=degrees.CtrCod" + " AND degrees.DegCod=courses.DegCod" + " AND courses.CrsCod=crs_usr.CrsCod" + " AND crs_usr.UsrCod=locations.UsrCod", + Gbl.CurrentIns.Ins.InsCod); + break; + case Sco_SCOPE_CTR: + sprintf (Query,"SELECT COUNT(*)" + " FROM degrees,courses,crs_usr,locations" + " WHERE degrees.CtrCod='%ld'" + " AND degrees.DegCod=courses.DegCod" + " AND courses.CrsCod=crs_usr.CrsCod" + " AND crs_usr.UsrCod=locations.UsrCod", + Gbl.CurrentCtr.Ctr.CtrCod); + break; + case Sco_SCOPE_DEG: + sprintf (Query,"SELECT COUNT(*)" + " FROM courses,crs_usr,locations" + " WHERE courses.DegCod='%ld'" + " AND courses.CrsCod=crs_usr.CrsCod" + " AND crs_usr.UsrCod=locations.UsrCod", + Gbl.CurrentDeg.Deg.DegCod); + break; + case Sco_SCOPE_CRS: + sprintf (Query,"SELECT COUNT(*)" + " FROM crs_usr,locations" + " WHERE crs_usr.CrsCod='%ld'" + " AND crs_usr.UsrCod=locations.UsrCod", + Gbl.CurrentCrs.Crs.CrsCod); + break; + default: + Lay_ShowErrorAndExit ("Wrong scope."); + break; + } + DB_QuerySELECT (Query,&mysql_res,"can not get number of locations"); + + /***** Get number of locations *****/ + row = mysql_fetch_row (mysql_res); + if (sscanf (row[0],"%u",&NumLocations) != 1) + Lay_ShowErrorAndExit ("Error when getting number of locations."); + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + + return NumLocations; } diff --git a/swad_agenda.h b/swad_agenda.h index 393b0b325..97c27f9a0 100644 --- a/swad_agenda.h +++ b/swad_agenda.h @@ -24,25 +24,75 @@ along with this program. If not, see . */ /*****************************************************************************/ -/********************************** Headers **********************************/ +/********************************* Headers ***********************************/ /*****************************************************************************/ -// #include // For malloc - -// #include "swad_user.h" +#include "swad_date.h" +#include "swad_user.h" /*****************************************************************************/ -/****************************** Public constants *****************************/ +/************************** Public types and constants ***********************/ /*****************************************************************************/ -/*****************************************************************************/ -/******************************** Public types *******************************/ -/*****************************************************************************/ +#define Loc_MAX_LENGTH_LOCATION 255 +#define Loc_MAX_LENGTH_EVENT 255 + +#define Loc_MAX_LENGTH_FOLDER 32 + +#define Loc_NUM_TYPES_SEND_WORK 2 +typedef enum + { + Loc_DO_NOT_SEND_WORK = 0, + Loc_SEND_WORK = 1, + } Loc_SendWork_t; + +#define Loc_NUM_DATES 2 +typedef enum + { + Loc_START_TIME = 0, + Loc_END_TIME = 1, + } Loc_StartOrEndTime_t; + +struct Location + { + long LocCod; + bool Hidden; + long UsrCod; + time_t TimeUTC[Loc_NUM_DATES]; + bool Open; + char Location[Loc_MAX_LENGTH_LOCATION+1]; + char Event[Loc_MAX_LENGTH_EVENT+1]; + }; + +typedef enum + { + Loc_ORDER_BY_START_DATE = 0, + Loc_ORDER_BY_END_DATE = 1, + } Loc_Order_t; + +#define Loc_DEFAULT_ORDER_TYPE Loc_ORDER_BY_START_DATE /*****************************************************************************/ -/****************************** Public prototypes ****************************/ +/***************************** Public prototypes *****************************/ /*****************************************************************************/ -void Agd_ShowMyAgenda (void); +void Loc_SeeLocations (void); +void Loc_PutHiddenParamLocOrderType (void); +void Loc_RequestCreatOrEditLoc (void); +void Loc_GetListLocations (void); +void Loc_GetDataOfLocationByCod (struct Location *Loc); +void Loc_FreeListLocations (void); + +long Loc_GetParamLocCod (void); +void Loc_AskRemLocation (void); +void Loc_RemoveLocation (void); +void Loc_HideLocation (void); +void Loc_ShowLocation (void); +void Loc_RecFormLocation (void); +void Loc_RemoveUsrLocations (long UsrCod); +unsigned Loc_GetNumLocationsFromUsr (long UsrCod); + +unsigned Loc_GetNumUsrsWithLocations (Sco_Scope_t Scope); +unsigned Loc_GetNumLocations (Sco_Scope_t Scope); #endif diff --git a/swad_changelog.h b/swad_changelog.h index c5cfce6f2..6de078aaf 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -183,13 +183,17 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.79.2 (2016-11-30)" +#define Log_PLATFORM_VERSION "SWAD 16.80 (2016-11-30)" #define CSS_FILE "swad16.69.css" #define JS_FILE "swad16.46.1.js" // 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 /* + Version 16.80: Nov 30, 2016 Changed location to agenda. (209428 lines) + 1 change necessary in database: +UPDATE actions SET Obsolete='Y' WHERE ActCod='1581'; + Version 16.79.2: Nov 30, 2016 Changed location to event in agenda. (209566 lines) Version 16.79.1: Nov 30, 2016 Changed location to event in agenda. (209559 lines) Version 16.79: Nov 30, 2016 In locations, split Title into Event (What?) and Location (Where?). (209534 lines) diff --git a/swad_global.h b/swad_global.h index 9a6c6a7f1..8887b33bf 100644 --- a/swad_global.h +++ b/swad_global.h @@ -32,6 +32,7 @@ #include // For tz #include // To access MySQL databases +#include "swad_agenda.h" #include "swad_assignment.h" #include "swad_attendance.h" #include "swad_banner.h" @@ -53,7 +54,6 @@ #include "swad_institution.h" #include "swad_layout.h" #include "swad_link.h" -#include "swad_location.h" #include "swad_mail.h" #include "swad_mark.h" #include "swad_message.h" diff --git a/swad_location.c b/swad_location.c deleted file mode 100644 index eef3c1efb..000000000 --- a/swad_location.c +++ /dev/null @@ -1,1325 +0,0 @@ -// swad_location.c: teacher's location - -/* - 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ñ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 . -*/ -/*****************************************************************************/ -/********************************* Headers ***********************************/ -/*****************************************************************************/ - -#include // For PATH_MAX -#include // For NULL -#include // For calloc -#include // For string functions - -#include "swad_location.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" - -/*****************************************************************************/ -/************** External global variables from others modules ****************/ -/*****************************************************************************/ - -extern struct Globals Gbl; - -/*****************************************************************************/ -/***************************** Private constants *****************************/ -/*****************************************************************************/ - -/*****************************************************************************/ -/******************************* Private types *******************************/ -/*****************************************************************************/ - -/*****************************************************************************/ -/***************************** Private variables *****************************/ -/*****************************************************************************/ - -/*****************************************************************************/ -/***************************** Private prototypes ****************************/ -/*****************************************************************************/ - -static void Loc_ShowAllLocations (void); -static bool Loc_CheckIfICanCreateLocations (void); -static void Loc_PutIconsListLocations (void); -static void Loc_PutIconToCreateNewLoc (void); -static void Loc_PutButtonToCreateNewLoc (void); -static void Loc_PutParamsToCreateNewLoc (void); -static void Loc_ShowOneLocation (long LocCod); -static void Loc_WriteLocAuthor (struct Location *Loc); -static void Loc_GetParamLocOrderType (void); - -static void Loc_PutFormsToRemEditOneLoc (long LocCod,bool Hidden); -static void Loc_PutParams (void); -static void Loc_GetDataOfLocation (struct Location *Loc,const char *Query); -static void Loc_GetLocationTxtFromDB (long LocCod,char *Txt); -static void Loc_PutParamLocCod (long LocCod); -static bool Loc_CheckIfSimilarLocationExists (const char *Field,const char *Value,long LocCod); -static void Loc_CreateLocation (struct Location *Loc,const char *Txt); -static void Loc_UpdateLocation (struct Location *Loc,const char *Txt); - -/*****************************************************************************/ -/************************* List all the locations ****************************/ -/*****************************************************************************/ - -void Loc_SeeLocations (void) - { - /***** Get parameters *****/ - Loc_GetParamLocOrderType (); - Grp_GetParamWhichGrps (); - Pag_GetParamPagNum (Pag_ASSIGNMENTS); - - /***** Show all the locations *****/ - Loc_ShowAllLocations (); - } - -/*****************************************************************************/ -/************************* Show all the locations ****************************/ -/*****************************************************************************/ - -static void Loc_ShowAllLocations (void) - { - extern const char *Hlp_PROFILE_Location; - extern const char *Txt_Agenda; - 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_Location; - extern const char *Txt_Event; - extern const char *Txt_No_locations; - Loc_Order_t Order; - struct Pagination Pagination; - unsigned NumLoc; - - /***** Get list of locations *****/ - Loc_GetListLocations (); - - /***** Compute variables related to pagination *****/ - Pagination.NumItems = Gbl.Usrs.Me.Locs.Num; - Pagination.CurrentPage = (int) Gbl.Pag.CurrentPage; - Pag_CalculatePagination (&Pagination); - Gbl.Pag.CurrentPage = (unsigned) Pagination.CurrentPage; - - /***** Write links to pages *****/ - if (Pagination.MoreThanOnePage) - Pag_WriteLinksToPagesCentered (Pag_ASSIGNMENTS,0,&Pagination); - - /***** Start frame *****/ - Lay_StartRoundFrame ("100%",Txt_Agenda, - Loc_PutIconsListLocations,Hlp_PROFILE_Location); - - if (Gbl.Usrs.Me.Locs.Num) - { - /***** Table head *****/ - fprintf (Gbl.F.Out,"" - ""); - for (Order = Loc_ORDER_BY_START_DATE; - Order <= Loc_ORDER_BY_END_DATE; - Order++) - { - fprintf (Gbl.F.Out,""); - } - fprintf (Gbl.F.Out,"" - "" - "", - Txt_Location, - Txt_Event); - - /***** Write all the locations *****/ - for (NumLoc = Pagination.FirstItemVisible; - NumLoc <= Pagination.LastItemVisible; - NumLoc++) - Loc_ShowOneLocation (Gbl.Usrs.Me.Locs.LstLocCods[NumLoc - 1]); - - /***** End table *****/ - fprintf (Gbl.F.Out,"
"); - Act_FormStart (ActSeeMyLoc); - Grp_PutParamWhichGrps (); - Pag_PutHiddenParamPagNum (Gbl.Pag.CurrentPage); - Par_PutHiddenParamUnsigned ("Order",(unsigned) Order); - Act_LinkFormSubmit (Txt_ASG_ATT_OR_SVY_HELP_ORDER[Order],"TIT_TBL",NULL); - if (Order == Gbl.Usrs.Me.Locs.SelectedOrderType) - fprintf (Gbl.F.Out,""); - fprintf (Gbl.F.Out,"%s",Txt_ASG_ATT_OR_SVY_ORDER[Order]); - if (Order == Gbl.Usrs.Me.Locs.SelectedOrderType) - fprintf (Gbl.F.Out,""); - fprintf (Gbl.F.Out,""); - Act_FormEnd (); - fprintf (Gbl.F.Out,"" - "%s" - "" - "%s" - "
"); - } - else // No locations created - Lay_ShowAlert (Lay_INFO,Txt_No_locations); - - /***** Button to create a new location *****/ - if (Loc_CheckIfICanCreateLocations ()) - Loc_PutButtonToCreateNewLoc (); - - /***** End frame *****/ - Lay_EndRoundFrame (); - - /***** Write again links to pages *****/ - if (Pagination.MoreThanOnePage) - Pag_WriteLinksToPagesCentered (Pag_ASSIGNMENTS,0,&Pagination); - - /***** Free list of locations *****/ - Loc_FreeListLocations (); - } - -/*****************************************************************************/ -/********************* Check if I can create locations ***********************/ -/*****************************************************************************/ - -static bool Loc_CheckIfICanCreateLocations (void) - { - return (bool) (Gbl.Usrs.Me.LoggedRole == Rol_TEACHER || - Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM); - } - -/*****************************************************************************/ -/**************** Put contextual icons in list of locations ******************/ -/*****************************************************************************/ - -static void Loc_PutIconsListLocations (void) - { - /***** Put icon to create a new location *****/ - if (Loc_CheckIfICanCreateLocations ()) - Loc_PutIconToCreateNewLoc (); - - /***** Put icon to show a figure *****/ - Gbl.Stat.FigureType = Sta_ASSIGNMENTS; - Sta_PutIconToShowFigure (); - } - -/*****************************************************************************/ -/******************** Put icon to create a new location **********************/ -/*****************************************************************************/ - -static void Loc_PutIconToCreateNewLoc (void) - { - extern const char *Txt_New_event; - - /***** Put form to create a new location *****/ - Lay_PutContextualLink (ActFrmNewLoc,Loc_PutParamsToCreateNewLoc, - "plus64x64.png", - Txt_New_event,NULL, - NULL); - } - -/*****************************************************************************/ -/******************* Put button to create a new location *********************/ -/*****************************************************************************/ - -static void Loc_PutButtonToCreateNewLoc (void) - { - extern const char *Txt_New_event; - - Act_FormStart (ActFrmNewLoc); - Loc_PutParamsToCreateNewLoc (); - Lay_PutConfirmButton (Txt_New_event); - Act_FormEnd (); - } - -/*****************************************************************************/ -/****************** Put parameters to create a new location ******************/ -/*****************************************************************************/ - -static void Loc_PutParamsToCreateNewLoc (void) - { - Loc_PutHiddenParamLocOrderType (); - Grp_PutParamWhichGrps (); - Pag_PutHiddenParamPagNum (Gbl.Pag.CurrentPage); - } - -/*****************************************************************************/ -/**************************** Show one location ******************************/ -/*****************************************************************************/ - -static void Loc_ShowOneLocation (long LocCod) - { - extern const char *Txt_Today; - static unsigned UniqueId = 0; - struct Location Loc; - char Txt[Cns_MAX_BYTES_TEXT+1]; - - /***** Get data of this location *****/ - Loc.LocCod = LocCod; - Loc_GetDataOfLocationByCod (&Loc); - - /***** Write first row of data of this location *****/ - /* Start date/time */ - UniqueId++; - fprintf (Gbl.F.Out,"" - "" - "" - "", - UniqueId, - Loc.Hidden ? (Loc.Open ? "DATE_GREEN_LIGHT" : - "DATE_RED_LIGHT") : - (Loc.Open ? "DATE_GREEN" : - "DATE_RED"), - Gbl.RowEvenOdd, - UniqueId,Loc.TimeUTC[Loc_START_TIME],Txt_Today); - - /* End date/time */ - UniqueId++; - fprintf (Gbl.F.Out,"" - "" - "", - UniqueId, - Loc.Hidden ? (Loc.Open ? "DATE_GREEN_LIGHT" : - "DATE_RED_LIGHT") : - (Loc.Open ? "DATE_GREEN" : - "DATE_RED"), - Gbl.RowEvenOdd, - UniqueId,Loc.TimeUTC[Loc_END_TIME],Txt_Today); - - /* Location */ - fprintf (Gbl.F.Out,"" - "
%s
", - Gbl.RowEvenOdd, - Loc.Hidden ? "ASG_TITLE_LIGHT" : - "ASG_TITLE", - Loc.Location); - fprintf (Gbl.F.Out,""); - - /* Event */ - fprintf (Gbl.F.Out,"" - "
%s
", - Gbl.RowEvenOdd, - Loc.Hidden ? "ASG_TITLE_LIGHT" : - "ASG_TITLE", - Loc.Event); - fprintf (Gbl.F.Out,"" - ""); - - /***** Write second row of data of this location *****/ - fprintf (Gbl.F.Out,"" - "", - Gbl.RowEvenOdd); - - /* Author of the location */ - Loc_WriteLocAuthor (&Loc); - - /* Forms to remove/edit this location */ - switch (Gbl.Usrs.Me.LoggedRole) - { - case Rol_TEACHER: - case Rol_SYS_ADM: - Loc_PutFormsToRemEditOneLoc (Loc.LocCod,Loc.Hidden); - break; - default: - break; - } - fprintf (Gbl.F.Out,""); - - /* Text of the location */ - Loc_GetLocationTxtFromDB (Loc.LocCod,Txt); - 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,"", - Gbl.RowEvenOdd); - - fprintf (Gbl.F.Out,"

" - "%s" - "

" - "" - "", - Loc.Hidden ? "DAT_LIGHT" : - "DAT", - Txt); - - Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd; - } - -/*****************************************************************************/ -/********************** Write the author of a location ***********************/ -/*****************************************************************************/ - -static void Loc_WriteLocAuthor (struct Location *Loc) - { - 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 *****/ - UsrDat.UsrCod = Loc->UsrCod; - 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,"%s %s", - Loc->Hidden ? "MSG_AUT_LIGHT" : - "MSG_AUT", - FirstName,Surnames); - - /***** Free memory used for user's data *****/ - Usr_UsrDataDestructor (&UsrDat); - } - -/*****************************************************************************/ -/******** Get parameter with the type or order in list of locations **********/ -/*****************************************************************************/ - -static void Loc_GetParamLocOrderType (void) - { - char UnsignedStr[10+1]; - unsigned UnsignedNum; - - Par_GetParToText ("Order",UnsignedStr,10); - if (sscanf (UnsignedStr,"%u",&UnsignedNum) == 1) - Gbl.Usrs.Me.Locs.SelectedOrderType = (Loc_Order_t) UnsignedNum; - else - Gbl.Usrs.Me.Locs.SelectedOrderType = Loc_DEFAULT_ORDER_TYPE; - } - -/*****************************************************************************/ -/**** Put a hidden parameter with the type of order in list of locations *****/ -/*****************************************************************************/ - -void Loc_PutHiddenParamLocOrderType (void) - { - Par_PutHiddenParamUnsigned ("Order",(unsigned) Gbl.Usrs.Me.Locs.SelectedOrderType); - } - -/*****************************************************************************/ -/****************** Put a link (form) to edit one location *******************/ -/*****************************************************************************/ - -static void Loc_PutFormsToRemEditOneLoc (long LocCod,bool Hidden) - { - extern const char *Txt_Remove; - extern const char *Txt_Show; - extern const char *Txt_Hide; - extern const char *Txt_Edit; - - fprintf (Gbl.F.Out,"
"); - - Gbl.Usrs.Me.Locs.LocCodToEdit = LocCod; // Used as parameter in contextual links - - /***** Put form to remove location *****/ - Lay_PutContextualLink (ActReqRemLoc,Loc_PutParams, - "remove-on64x64.png", - Txt_Remove,NULL, - NULL); - - /***** Put form to hide/show location *****/ - if (Hidden) - Lay_PutContextualLink (ActShoLoc,Loc_PutParams, - "eye-slash-on64x64.png", - Txt_Show,NULL, - NULL); - else - Lay_PutContextualLink (ActHidLoc,Loc_PutParams, - "eye-on64x64.png", - Txt_Hide,NULL, - NULL); - - /***** Put form to edit location *****/ - Lay_PutContextualLink (ActEdiOneLoc,Loc_PutParams, - "edit64x64.png", - Txt_Edit,NULL, - NULL); - - fprintf (Gbl.F.Out,"
"); - } - -/*****************************************************************************/ -/********************* Params used to edit a location ************************/ -/*****************************************************************************/ - -static void Loc_PutParams (void) - { - Loc_PutParamLocCod (Gbl.Usrs.Me.Locs.LocCodToEdit); - Loc_PutHiddenParamLocOrderType (); - Grp_PutParamWhichGrps (); - Pag_PutHiddenParamPagNum (Gbl.Pag.CurrentPage); - } - -/*****************************************************************************/ -/************************* List all the locations ****************************/ -/*****************************************************************************/ - -void Loc_GetListLocations (void) - { - char HiddenSubQuery[256]; - char OrderBySubQuery[256]; - char Query[2048]; - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned long NumRows; - unsigned NumLoc; - - if (Gbl.Usrs.Me.Locs.LstIsRead) - Loc_FreeListLocations (); - - /***** Get list of locations from database *****/ - switch (Gbl.Usrs.Me.LoggedRole) - { - case Rol_TEACHER: - case Rol_SYS_ADM: - HiddenSubQuery[0] = '\0'; - break; - default: - sprintf (HiddenSubQuery,"AND Hidden='N'"); - break; - } - switch (Gbl.Usrs.Me.Locs.SelectedOrderType) - { - case Loc_ORDER_BY_START_DATE: - sprintf (OrderBySubQuery,"StartTime DESC,EndTime DESC,Location DESC,Event DESC"); - break; - case Loc_ORDER_BY_END_DATE: - sprintf (OrderBySubQuery,"EndTime DESC,StartTime DESC,Location DESC,Event DESC"); - break; - } - sprintf (Query,"SELECT LocCod" - " FROM locations" - " WHERE UsrCod='%ld'%s" - " ORDER BY %s", - Gbl.Usrs.Me.UsrDat.UsrCod,HiddenSubQuery,OrderBySubQuery); - NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get locations"); - - if (NumRows) // Locations found... - { - Gbl.Usrs.Me.Locs.Num = (unsigned) NumRows; - - /***** Create list of locations *****/ - if ((Gbl.Usrs.Me.Locs.LstLocCods = (long *) calloc (NumRows,sizeof (long))) == NULL) - Lay_ShowErrorAndExit ("Not enough memory to store list of locations."); - - /***** Get the locations codes *****/ - for (NumLoc = 0; - NumLoc < Gbl.Usrs.Me.Locs.Num; - NumLoc++) - { - /* Get next location code */ - row = mysql_fetch_row (mysql_res); - if ((Gbl.Usrs.Me.Locs.LstLocCods[NumLoc] = Str_ConvertStrCodToLongCod (row[0])) < 0) - Lay_ShowErrorAndExit ("Error: wrong location code."); - } - } - else - Gbl.Usrs.Me.Locs.Num = 0; - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - - Gbl.Usrs.Me.Locs.LstIsRead = true; - } - -/*****************************************************************************/ -/******************** Get location data using its code ***********************/ -/*****************************************************************************/ - -void Loc_GetDataOfLocationByCod (struct Location *Loc) - { - char Query[1024]; - - /***** Build query *****/ - sprintf (Query,"SELECT LocCod,UsrCod,Hidden," - "UNIX_TIMESTAMP(StartTime)," - "UNIX_TIMESTAMP(EndTime)," - "NOW() BETWEEN StartTime AND EndTime," - "Location,Event" - " FROM locations" - " WHERE LocCod='%ld' AND UsrCod='%ld'", - Loc->LocCod,Gbl.Usrs.Me.UsrDat.UsrCod); - - /***** Get data of location *****/ - Loc_GetDataOfLocation (Loc,Query); - } - -/*****************************************************************************/ -/*************************** Get location data *******************************/ -/*****************************************************************************/ - -static void Loc_GetDataOfLocation (struct Location *Loc,const char *Query) - { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned long NumRows; - - /***** Clear all location data *****/ - Loc->LocCod = -1L; - Loc->UsrCod = -1L; - Loc->Hidden = false; - Loc->TimeUTC[Loc_START_TIME] = - Loc->TimeUTC[Loc_END_TIME ] = (time_t) 0; - Loc->Open = false; - Loc->Location[0] = '\0'; - Loc->Event[0] = '\0'; - - /***** Get data of location from database *****/ - NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get location data"); - - if (NumRows) // Location found... - { - /* Get row */ - row = mysql_fetch_row (mysql_res); - - /* Get code of the location (row[0]) */ - Loc->LocCod = Str_ConvertStrCodToLongCod (row[0]); - - /* Get author of the location (row[1]) */ - Loc->UsrCod = Str_ConvertStrCodToLongCod (row[1]); - - /* Get whether the location is hidden or not (row[2]) */ - Loc->Hidden = (row[2][0] == 'Y'); - - /* Get start date (row[3] holds the start UTC time) */ - Loc->TimeUTC[Loc_START_TIME] = Dat_GetUNIXTimeFromStr (row[3]); - - /* Get end date (row[4] holds the end UTC time) */ - Loc->TimeUTC[Loc_END_TIME ] = Dat_GetUNIXTimeFromStr (row[4]); - - /* Get whether the location is open or closed (row(5)) */ - Loc->Open = (row[5][0] == '1'); - - /* Get the location (row[6]) */ - strcpy (Loc->Location,row[6]); - - /* Get the event (row[7]) */ - strcpy (Loc->Event,row[7]); - } - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - } - -/*****************************************************************************/ -/************************** Free list of locations ***************************/ -/*****************************************************************************/ - -void Loc_FreeListLocations (void) - { - if (Gbl.Usrs.Me.Locs.LstIsRead && Gbl.Usrs.Me.Locs.LstLocCods) - { - /***** Free memory used by the list of locations *****/ - free ((void *) Gbl.Usrs.Me.Locs.LstLocCods); - Gbl.Usrs.Me.Locs.LstLocCods = NULL; - Gbl.Usrs.Me.Locs.Num = 0; - Gbl.Usrs.Me.Locs.LstIsRead = false; - } - } - -/*****************************************************************************/ -/********************* Get location text from database ***********************/ -/*****************************************************************************/ - -static void Loc_GetLocationTxtFromDB (long LocCod,char *Txt) - { - char Query[512]; - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned long NumRows; - - /***** Get text of location from database *****/ - sprintf (Query,"SELECT Txt FROM locations" - " WHERE LocCod='%ld' AND UsrCod='%ld'", - LocCod,Gbl.Usrs.Me.UsrDat.UsrCod); - NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get location text"); - - /***** 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) - Lay_ShowErrorAndExit ("Error when getting location text."); - } - -/*****************************************************************************/ -/****************** Write parameter with code of location ********************/ -/*****************************************************************************/ - -static void Loc_PutParamLocCod (long LocCod) - { - Par_PutHiddenParamLong ("LocCod",LocCod); - } - -/*****************************************************************************/ -/******************* Get parameter with code of location *********************/ -/*****************************************************************************/ - -long Loc_GetParamLocCod (void) - { - char LongStr[1+10+1]; - - /***** Get parameter with code of location *****/ - Par_GetParToText ("LocCod",LongStr,1+10); - return Str_ConvertStrCodToLongCod (LongStr); - } - -/*****************************************************************************/ -/************* Ask for confirmation of removing of a location ****************/ -/*****************************************************************************/ - -void Loc_AskRemLocation (void) - { - extern const char *Txt_Do_you_really_want_to_remove_the_location_X; - extern const char *Txt_Remove_location; - struct Location Loc; - - /***** Get parameters *****/ - Loc_GetParamLocOrderType (); - Grp_GetParamWhichGrps (); - Pag_GetParamPagNum (Pag_ASSIGNMENTS); - - /***** Get location code *****/ - if ((Loc.LocCod = Loc_GetParamLocCod ()) == -1L) - Lay_ShowErrorAndExit ("Code of location is missing."); - - /***** Get data of the location from database *****/ - Loc_GetDataOfLocationByCod (&Loc); - - /***** Button of confirmation of removing *****/ - Act_FormStart (ActRemLoc); - Loc_PutParamLocCod (Loc.LocCod); - Loc_PutHiddenParamLocOrderType (); - Grp_PutParamWhichGrps (); - Pag_PutHiddenParamPagNum (Gbl.Pag.CurrentPage); - - /***** Ask for confirmation of removing *****/ - sprintf (Gbl.Message,Txt_Do_you_really_want_to_remove_the_location_X, - Loc.Event); - Lay_ShowAlert (Lay_WARNING,Gbl.Message); - Lay_PutRemoveButton (Txt_Remove_location); - Act_FormEnd (); - - /***** Show locations again *****/ - Loc_SeeLocations (); - } - -/*****************************************************************************/ -/***************************** Remove a location *****************************/ -/*****************************************************************************/ - -void Loc_RemoveLocation (void) - { - extern const char *Txt_Location_X_removed; - char Query[512]; - struct Location Loc; - - /***** Get location code *****/ - if ((Loc.LocCod = Loc_GetParamLocCod ()) == -1L) - Lay_ShowErrorAndExit ("Code of location is missing."); - - /***** Get data of the location from database *****/ - Loc_GetDataOfLocationByCod (&Loc); // Inside this function, the course is checked to be the current one - - /***** Remove location *****/ - sprintf (Query,"DELETE FROM locations" - " WHERE LocCod='%ld' AND UsrCod='%ld'", - Loc.LocCod,Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryDELETE (Query,"can not remove location"); - - /***** Write message to show the change made *****/ - sprintf (Gbl.Message,Txt_Location_X_removed,Loc.Event); - Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); - - /***** Show locations again *****/ - Loc_SeeLocations (); - } - -/*****************************************************************************/ -/****************************** Hide a location ******************************/ -/*****************************************************************************/ - -void Loc_HideLocation (void) - { - extern const char *Txt_Event_X_is_now_hidden; - char Query[512]; - struct Location Loc; - - /***** Get location code *****/ - if ((Loc.LocCod = Loc_GetParamLocCod ()) == -1L) - Lay_ShowErrorAndExit ("Code of location is missing."); - - /***** Get data of the location from database *****/ - Loc_GetDataOfLocationByCod (&Loc); - - /***** Hide location *****/ - sprintf (Query,"UPDATE locations SET Hidden='Y'" - " WHERE LocCod='%ld' AND UsrCod='%ld'", - Loc.LocCod,Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryUPDATE (Query,"can not hide location"); - - /***** Write message to show the change made *****/ - sprintf (Gbl.Message,Txt_Event_X_is_now_hidden,Loc.Event); - Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); - - /***** Show locations again *****/ - Loc_SeeLocations (); - } - -/*****************************************************************************/ -/****************************** Show a location ******************************/ -/*****************************************************************************/ - -void Loc_ShowLocation (void) - { - extern const char *Txt_Event_X_is_now_visible; - char Query[512]; - struct Location Loc; - - /***** Get location code *****/ - if ((Loc.LocCod = Loc_GetParamLocCod ()) == -1L) - Lay_ShowErrorAndExit ("Code of location is missing."); - - /***** Get data of the location from database *****/ - Loc_GetDataOfLocationByCod (&Loc); - - /***** Hide location *****/ - sprintf (Query,"UPDATE locations SET Hidden='N'" - " WHERE LocCod='%ld' AND UsrCod='%ld'", - Loc.LocCod,Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryUPDATE (Query,"can not show location"); - - /***** Write message to show the change made *****/ - sprintf (Gbl.Message,Txt_Event_X_is_now_visible,Loc.Event); - Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); - - /***** Show locations again *****/ - Loc_SeeLocations (); - } - -/*****************************************************************************/ -/********* Check if the title or the folder of a location exists *************/ -/*****************************************************************************/ - -static bool Loc_CheckIfSimilarLocationExists (const char *Field,const char *Value,long LocCod) - { - char Query[512]; - - /***** Get number of locations with a field value from database *****/ - sprintf (Query,"SELECT COUNT(*) FROM locations" - " WHERE UsrCod='%ld' AND %s='%s' AND LocCod<>'%ld'", - Gbl.Usrs.Me.UsrDat.UsrCod,Field,Value,LocCod); - return (DB_QueryCOUNT (Query,"can not get similar locations") != 0); - } - -/*****************************************************************************/ -/******************* Put a form to create a new location *********************/ -/*****************************************************************************/ - -void Loc_RequestCreatOrEditLoc (void) - { - extern const char *Hlp_PROFILE_Location_new_location; - extern const char *Hlp_PROFILE_Location_edit_location; - extern const char *The_ClassForm[The_NUM_THEMES]; - extern const char *Txt_New_event; - extern const char *Txt_Edit_location; - 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; - struct Location Loc; - bool ItsANewLocation; - char Txt[Cns_MAX_BYTES_TEXT+1]; - - /***** Get parameters *****/ - Loc_GetParamLocOrderType (); - Grp_GetParamWhichGrps (); - Pag_GetParamPagNum (Pag_ASSIGNMENTS); - - /***** Get the code of the location *****/ - ItsANewLocation = ((Loc.LocCod = Loc_GetParamLocCod ()) == -1L); - - /***** Get from the database the data of the location *****/ - if (ItsANewLocation) - { - /* Initialize to empty location */ - Loc.LocCod = -1L; - Loc.UsrCod = Gbl.Usrs.Me.UsrDat.UsrCod; - Loc.TimeUTC[Loc_START_TIME] = Gbl.StartExecutionTimeUTC; - Loc.TimeUTC[Loc_END_TIME ] = Gbl.StartExecutionTimeUTC + (2 * 60 * 60); // +2 hours - Loc.Open = true; - Loc.Location[0] = '\0'; - Loc.Event[0] = '\0'; - } - else - { - /* Get data of the location from database */ - Loc_GetDataOfLocationByCod (&Loc); - - /* Get text of the location from database */ - Loc_GetLocationTxtFromDB (Loc.LocCod,Txt); - } - - /***** Start form *****/ - if (ItsANewLocation) - Act_FormStart (ActNewLoc); - else - { - Act_FormStart (ActChgLoc); - Loc_PutParamLocCod (Loc.LocCod); - } - Loc_PutHiddenParamLocOrderType (); - Grp_PutParamWhichGrps (); - Pag_PutHiddenParamPagNum (Gbl.Pag.CurrentPage); - - /***** Table start *****/ - Lay_StartRoundFrameTable (NULL, - ItsANewLocation ? Txt_New_event : - Txt_Edit_location, - NULL, - ItsANewLocation ? Hlp_PROFILE_Location_new_location : - Hlp_PROFILE_Location_edit_location, - 2); - - /***** Location *****/ - fprintf (Gbl.F.Out,"" - "" - "%s:" - "" - "" - "" - "" - "", - The_ClassForm[Gbl.Prefs.Theme], - Txt_Location, - Loc_MAX_LENGTH_LOCATION,Loc.Location); - - /***** Event *****/ - fprintf (Gbl.F.Out,"" - "" - "%s:" - "" - "" - "" - "" - "", - The_ClassForm[Gbl.Prefs.Theme], - Txt_Event, - Loc_MAX_LENGTH_EVENT,Loc.Event); - - /***** Start and end dates *****/ - Dat_PutFormStartEndClientLocalDateTimes (Loc.TimeUTC); - - /***** Text *****/ - fprintf (Gbl.F.Out,"" - "" - "%s:" - "" - "" - "" - "" - ""); - - /***** New location *****/ - if (ItsANewLocation) - Lay_EndRoundFrameTableWithButton (Lay_CREATE_BUTTON,Txt_Create_event); - else - Lay_EndRoundFrameTableWithButton (Lay_CONFIRM_BUTTON,Txt_Save); - Act_FormEnd (); - - /***** Show current locations, if any *****/ - Loc_ShowAllLocations (); - } - -/*****************************************************************************/ -/******************** Receive form to create a new location ******************/ -/*****************************************************************************/ - -void Loc_RecFormLocation (void) - { - extern const char *Txt_Already_existed_a_location_with_the_title_X; - extern const char *Txt_You_must_specify_the_title_of_the_location; - extern const char *Txt_Created_new_location_X; - extern const char *Txt_The_event_has_been_modified; - struct Location OldLoc; - struct Location NewLoc; - bool ItsANewLocation; - bool NewLocationIsCorrect = true; - char Txt[Cns_MAX_BYTES_TEXT+1]; - - /***** Get the code of the location *****/ - ItsANewLocation = ((NewLoc.LocCod = Loc_GetParamLocCod ()) == -1L); - - if (!ItsANewLocation) - { - /* Get data of the old (current) location from database */ - OldLoc.LocCod = NewLoc.LocCod; - Loc_GetDataOfLocationByCod (&OldLoc); - } - - /***** Get start/end date-times *****/ - NewLoc.TimeUTC[Loc_START_TIME] = Dat_GetTimeUTCFromForm ("StartTimeUTC"); - NewLoc.TimeUTC[Loc_END_TIME ] = Dat_GetTimeUTCFromForm ("EndTimeUTC" ); - - /***** Get location *****/ - Par_GetParToText ("Location",NewLoc.Location,Loc_MAX_LENGTH_LOCATION); - - /***** Get event *****/ - Par_GetParToText ("Event",NewLoc.Event,Loc_MAX_LENGTH_EVENT); - - /***** Get text *****/ - Par_GetParToHTML ("Txt",Txt,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous) - - /***** Adjust dates *****/ - if (NewLoc.TimeUTC[Loc_START_TIME] == 0) - NewLoc.TimeUTC[Loc_START_TIME] = Gbl.StartExecutionTimeUTC; - if (NewLoc.TimeUTC[Loc_END_TIME] == 0) - NewLoc.TimeUTC[Loc_END_TIME] = NewLoc.TimeUTC[Loc_START_TIME] + 2*60*60; // +2 hours - - /***** Check if location is correct *****/ - if (!NewLoc.Location[0]) // If there is no location - { - NewLocationIsCorrect = false; - Lay_ShowAlert (Lay_WARNING,Txt_You_must_specify_the_title_of_the_location); - } - - /***** Check if event is correct *****/ - if (NewLoc.Event[0]) // If there's event - { - /* If title of location was in database... */ - if (Loc_CheckIfSimilarLocationExists ("Event",NewLoc.Event,NewLoc.LocCod)) - { - NewLocationIsCorrect = false; - sprintf (Gbl.Message,Txt_Already_existed_a_location_with_the_title_X, - NewLoc.Event); - Lay_ShowAlert (Lay_WARNING,Gbl.Message); - } - } - else // If there is no event - { - NewLocationIsCorrect = false; - Lay_ShowAlert (Lay_WARNING,Txt_You_must_specify_the_title_of_the_location); - } - - /***** Create a new location or update an existing one *****/ - if (NewLocationIsCorrect) - { - if (ItsANewLocation) - { - Loc_CreateLocation (&NewLoc,Txt); // Add new location to database - - /***** Write success message *****/ - sprintf (Gbl.Message,Txt_Created_new_location_X,NewLoc.Event); - Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); - } - else - { - Loc_UpdateLocation (&NewLoc,Txt); - - /***** Write success message *****/ - Lay_ShowAlert (Lay_SUCCESS,Txt_The_event_has_been_modified); - } - - /* Free memory for list of selected groups */ - Grp_FreeListCodSelectedGrps (); - - /***** Show locations again *****/ - Loc_SeeLocations (); - } - else - // TODO: The form should be filled with partial data, now is always empty - Loc_RequestCreatOrEditLoc (); - } - -/*****************************************************************************/ -/************************* Create a new location *****************************/ -/*****************************************************************************/ - -static void Loc_CreateLocation (struct Location *Loc,const char *Txt) - { - char Query[1024+Cns_MAX_BYTES_TEXT]; - - /***** Create a new location *****/ - sprintf (Query,"INSERT INTO locations" - " (UsrCod,StartTime,EndTime,Location,Event,Txt)" - " VALUES" - " ('%ld',FROM_UNIXTIME('%ld'),FROM_UNIXTIME('%ld')," - "'%s','%s','%s')", - Gbl.Usrs.Me.UsrDat.UsrCod, - Loc->TimeUTC[Loc_START_TIME], - Loc->TimeUTC[Loc_END_TIME ], - Loc->Location, - Loc->Event, - Txt); - Loc->LocCod = DB_QueryINSERTandReturnCode (Query,"can not create new location"); - } - -/*****************************************************************************/ -/********************** Update an existing location **************************/ -/*****************************************************************************/ - -static void Loc_UpdateLocation (struct Location *Loc,const char *Txt) - { - char Query[1024+Cns_MAX_BYTES_TEXT]; - - /***** Update the data of the location *****/ - sprintf (Query,"UPDATE locations SET " - "StartTime=FROM_UNIXTIME('%ld')," - "EndTime=FROM_UNIXTIME('%ld')," - "Location='%s',Event='%s',Txt='%s'" - " WHERE LocCod='%ld' AND UsrCod='%ld'", - Loc->TimeUTC[Loc_START_TIME], - Loc->TimeUTC[Loc_END_TIME ], - Loc->Location,Loc->Event,Txt, - Loc->LocCod,Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryUPDATE (Query,"can not update location"); - } - -/*****************************************************************************/ -/******************** Remove all the locations of a user *********************/ -/*****************************************************************************/ - -void Loc_RemoveUsrLocations (long UsrCod) - { - char Query[128]; - - /***** Remove locations *****/ - sprintf (Query,"DELETE FROM locations WHERE UsrCod='%ld'",UsrCod); - DB_QueryDELETE (Query,"can not remove all the locations of a user"); - } - -/*****************************************************************************/ -/******************* Get number of locations from a user *********************/ -/*****************************************************************************/ - -unsigned Loc_GetNumLocationsFromUsr (long UsrCod) - { - char Query[128]; - - /***** Get number of locations in a course from database *****/ - sprintf (Query,"SELECT COUNT(*) FROM locations WHERE UsrCod='%ld'", - UsrCod); - return (unsigned) DB_QueryCOUNT (Query,"can not get number of locations from user"); - } - -/*****************************************************************************/ -/******************** Get number of users with locations *********************/ -/*****************************************************************************/ -// Returns the number of users with locations in a given scope - -unsigned Loc_GetNumUsrsWithLocations (Sco_Scope_t Scope) - { - char Query[1024]; - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned NumUsrs; - - /***** Get number of courses with locations from database *****/ - switch (Scope) - { - case Sco_SCOPE_SYS: - sprintf (Query,"SELECT COUNT(DISTINCT UsrCod)" - " FROM locations" - " WHERE UsrCod>'0'"); - break; - case Sco_SCOPE_CTY: - sprintf (Query,"SELECT COUNT(DISTINCT locations.UsrCod)" - " FROM institutions,centres,degrees,courses,crs_usr,locations" - " 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=locations.UsrCod", - Gbl.CurrentCty.Cty.CtyCod); - break; - case Sco_SCOPE_INS: - sprintf (Query,"SELECT COUNT(DISTINCT locations.UsrCod)" - " FROM centres,degrees,courses,crs_usr,locations" - " 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=locations.UsrCod", - Gbl.CurrentIns.Ins.InsCod); - break; - case Sco_SCOPE_CTR: - sprintf (Query,"SELECT COUNT(DISTINCT locations.UsrCod)" - " FROM degrees,courses,crs_usr,locations" - " WHERE degrees.CtrCod='%ld'" - " AND degrees.DegCod=courses.DegCod" - " AND courses.Status=0" - " AND courses.CrsCod=crs_usr.CrsCod" - " AND crs_usr.UsrCod=locations.UsrCod", - Gbl.CurrentCtr.Ctr.CtrCod); - break; - case Sco_SCOPE_DEG: - sprintf (Query,"SELECT COUNT(DISTINCT locations.UsrCod)" - " FROM courses,crs_usr,locations" - " WHERE courses.DegCod='%ld'" - " AND courses.Status=0" - " AND courses.CrsCod=crs_usr.CrsCod" - " AND crs_usr.UsrCod=locations.UsrCod", - Gbl.CurrentDeg.Deg.DegCod); - break; - case Sco_SCOPE_CRS: - sprintf (Query,"SELECT COUNT(DISTINCT locations.UsrCod)" - " FROM crs_usr,locations" - " WHERE crs_usr.CrsCod='%ld'" - " AND crs_usr.UsrCod=locations.UsrCod", - Gbl.CurrentCrs.Crs.CrsCod); - break; - default: - Lay_ShowErrorAndExit ("Wrong scope."); - break; - } - DB_QuerySELECT (Query,&mysql_res,"can not get number of users with locations"); - - /***** 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 locations."); - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - - return NumUsrs; - } - -/*****************************************************************************/ -/************************* Get number of locations ***************************/ -/*****************************************************************************/ -// Returns the number of locations in a given scope - -unsigned Loc_GetNumLocations (Sco_Scope_t Scope) - { - char Query[1024]; - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned NumLocations; - - /***** Get number of locations from database *****/ - switch (Scope) - { - case Sco_SCOPE_SYS: - sprintf (Query,"SELECT COUNT(*)" - " FROM locations" - " WHERE UsrCod>'0'"); - break; - case Sco_SCOPE_CTY: - sprintf (Query,"SELECT COUNT(*)" - " FROM institutions,centres,degrees,courses,crs_usr,locations" - " 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=locations.UsrCod", - Gbl.CurrentCty.Cty.CtyCod); - break; - case Sco_SCOPE_INS: - sprintf (Query,"SELECT COUNT(*)" - " FROM centres,degrees,courses,crs_usr,locations" - " WHERE centres.InsCod='%ld'" - " AND centres.CtrCod=degrees.CtrCod" - " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=crs_usr.CrsCod" - " AND crs_usr.UsrCod=locations.UsrCod", - Gbl.CurrentIns.Ins.InsCod); - break; - case Sco_SCOPE_CTR: - sprintf (Query,"SELECT COUNT(*)" - " FROM degrees,courses,crs_usr,locations" - " WHERE degrees.CtrCod='%ld'" - " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=crs_usr.CrsCod" - " AND crs_usr.UsrCod=locations.UsrCod", - Gbl.CurrentCtr.Ctr.CtrCod); - break; - case Sco_SCOPE_DEG: - sprintf (Query,"SELECT COUNT(*)" - " FROM courses,crs_usr,locations" - " WHERE courses.DegCod='%ld'" - " AND courses.CrsCod=crs_usr.CrsCod" - " AND crs_usr.UsrCod=locations.UsrCod", - Gbl.CurrentDeg.Deg.DegCod); - break; - case Sco_SCOPE_CRS: - sprintf (Query,"SELECT COUNT(*)" - " FROM crs_usr,locations" - " WHERE crs_usr.CrsCod='%ld'" - " AND crs_usr.UsrCod=locations.UsrCod", - Gbl.CurrentCrs.Crs.CrsCod); - break; - default: - Lay_ShowErrorAndExit ("Wrong scope."); - break; - } - DB_QuerySELECT (Query,&mysql_res,"can not get number of locations"); - - /***** Get number of locations *****/ - row = mysql_fetch_row (mysql_res); - if (sscanf (row[0],"%u",&NumLocations) != 1) - Lay_ShowErrorAndExit ("Error when getting number of locations."); - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - - return NumLocations; - } diff --git a/swad_location.h b/swad_location.h deleted file mode 100644 index 4dc26245a..000000000 --- a/swad_location.h +++ /dev/null @@ -1,98 +0,0 @@ -// swad_location.h: teacher's location - -#ifndef _SWAD_LOC -#define _SWAD_LOC -/* - 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-2016 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 . -*/ -/*****************************************************************************/ -/********************************* Headers ***********************************/ -/*****************************************************************************/ - -#include "swad_date.h" -#include "swad_user.h" - -/*****************************************************************************/ -/************************** Public types and constants ***********************/ -/*****************************************************************************/ - -#define Loc_MAX_LENGTH_LOCATION 255 -#define Loc_MAX_LENGTH_EVENT 255 - -#define Loc_MAX_LENGTH_FOLDER 32 - -#define Loc_NUM_TYPES_SEND_WORK 2 -typedef enum - { - Loc_DO_NOT_SEND_WORK = 0, - Loc_SEND_WORK = 1, - } Loc_SendWork_t; - -#define Loc_NUM_DATES 2 -typedef enum - { - Loc_START_TIME = 0, - Loc_END_TIME = 1, - } Loc_StartOrEndTime_t; - -struct Location - { - long LocCod; - bool Hidden; - long UsrCod; - time_t TimeUTC[Loc_NUM_DATES]; - bool Open; - char Location[Loc_MAX_LENGTH_LOCATION+1]; - char Event[Loc_MAX_LENGTH_EVENT+1]; - }; - -typedef enum - { - Loc_ORDER_BY_START_DATE = 0, - Loc_ORDER_BY_END_DATE = 1, - } Loc_Order_t; - -#define Loc_DEFAULT_ORDER_TYPE Loc_ORDER_BY_START_DATE - -/*****************************************************************************/ -/***************************** Public prototypes *****************************/ -/*****************************************************************************/ - -void Loc_SeeLocations (void); -void Loc_PutHiddenParamLocOrderType (void); -void Loc_RequestCreatOrEditLoc (void); -void Loc_GetListLocations (void); -void Loc_GetDataOfLocationByCod (struct Location *Loc); -void Loc_FreeListLocations (void); - -long Loc_GetParamLocCod (void); -void Loc_AskRemLocation (void); -void Loc_RemoveLocation (void); -void Loc_HideLocation (void); -void Loc_ShowLocation (void); -void Loc_RecFormLocation (void); -void Loc_RemoveUsrLocations (long UsrCod); -unsigned Loc_GetNumLocationsFromUsr (long UsrCod); - -unsigned Loc_GetNumUsrsWithLocations (Sco_Scope_t Scope); -unsigned Loc_GetNumLocations (Sco_Scope_t Scope); - -#endif diff --git a/swad_menu.c b/swad_menu.c index a80c700dc..25d29aea6 100644 --- a/swad_menu.c +++ b/swad_menu.c @@ -186,7 +186,6 @@ const Act_Action_t Mnu_MenuActions[Tab_NUM_TABS][Act_MAX_OPTIONS_IN_MENU_PER_TAB ActFrmRolSes, ActMyCrs, ActSeeMyTT, - ActSeeMyAgd, ActSeeMyLoc, ActFrmMyAcc, ActReqEdiRecCom, diff --git a/swad_text.c b/swad_text.c index e0c48c515..c5c447321 100644 --- a/swad_text.c +++ b/swad_text.c @@ -19536,7 +19536,7 @@ const char *Txt_MENU_TITLE[Tab_NUM_TABS][Act_MAX_OPTIONS_IN_MENU_PER_TAB] = "Horário" #endif , - // ActSeeMyAgd + // ActSeeMyLoc #if L==1 "Agenda" #elif L==2 @@ -19555,27 +19555,6 @@ const char *Txt_MENU_TITLE[Tab_NUM_TABS][Act_MAX_OPTIONS_IN_MENU_PER_TAB] = "Pamiętnik" #elif L==9 "Agenda" -#endif - , - // ActSeeMyLoc -#if L==1 - "Ubicació" -#elif L==2 - "Standort" -#elif L==3 - "Location" -#elif L==4 - "Ubicación" -#elif L==5 - "Emplacement" -#elif L==6 - "Ubicación" // Okoteve traducción -#elif L==7 - "Posizione" -#elif L==8 - "Lokacja" -#elif L==9 - "Localização" #endif , // ActFrmMyAcc @@ -21430,7 +21409,7 @@ const char *Txt_MENU_SUBTITLE[Tab_NUM_TABS][Act_MAX_OPTIONS_IN_MENU_PER_TAB] = "Horário minha disciplinas" #endif , - // ActSeeMyAgd + // ActSeeMyLoc #if L==1 "Agenda" #elif L==2 @@ -21449,27 +21428,6 @@ const char *Txt_MENU_SUBTITLE[Tab_NUM_TABS][Act_MAX_OPTIONS_IN_MENU_PER_TAB] = "Pamiętnik" #elif L==9 "Agenda" -#endif - , - // ActSeeMyLoc -#if L==1 - "La meva ubicació" -#elif L==2 - "Mein Standort" -#elif L==3 - "My location" -#elif L==4 - "Mi ubicación" -#elif L==5 - "Mon emplacement" -#elif L==6 - "Mi ubicación" // Okoteve traducción -#elif L==7 - "La mia posizione" -#elif L==8 - "Moja lokacja" -#elif L==9 - "Minha localização" #endif , // ActFrmMyAcc