From 264394d5d6c98c0ae750485c0f61443cf27ce031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Mon, 18 Feb 2019 14:41:46 +0100 Subject: [PATCH] Version 18.49 --- swad_ID.c | 2 - swad_MFU.c | 2 - swad_RSS.c | 2 - swad_action.c | 375 ++++++++++++++++++-------------------------- swad_action.h | 62 ++++---- swad_attendance.c | 2 - swad_calendar.c | 2 - swad_centre.c | 2 - swad_changelog.h | 10 +- swad_chat.c | 2 - swad_connected.c | 3 +- swad_date.c | 2 - swad_degree.c | 3 +- swad_degree_type.c | 3 +- swad_department.c | 2 - swad_duplicate.c | 3 - swad_follow.c | 2 - swad_group.c | 170 ++++++++------------ swad_group.h | 2 +- swad_holiday.c | 2 - swad_icon.c | 2 - swad_info.c | 2 - swad_institution.c | 2 - swad_language.c | 5 +- swad_link.c | 2 - swad_mail.c | 2 - swad_menu.c | 5 +- swad_network.c | 2 - swad_nickname.c | 2 - swad_notice.c | 2 - swad_notification.c | 4 +- swad_pagination.c | 2 - swad_photo.c | 2 - swad_place.c | 2 - swad_plugin.c | 3 +- swad_preference.c | 3 +- swad_profile.c | 2 - swad_record.c | 2 - swad_search.c | 3 +- swad_test_import.c | 2 - swad_text.c | 4 +- swad_theme.c | 3 +- swad_user.c | 2 - 43 files changed, 265 insertions(+), 448 deletions(-) diff --git a/swad_ID.c b/swad_ID.c index 12828902b..8a952bfd7 100644 --- a/swad_ID.c +++ b/swad_ID.c @@ -25,10 +25,8 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For isalnum, isdigit, etc. #include // For boolean type -#include // For asprintf #include // For exit, system, malloc, free, rand, etc. #include // For string functions diff --git a/swad_MFU.c b/swad_MFU.c index 0a9be2499..378945315 100644 --- a/swad_MFU.c +++ b/swad_MFU.c @@ -25,9 +25,7 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // To access MySQL databases -#include // For asprintf #include // For malloc and free #include // For string functions diff --git a/swad_RSS.c b/swad_RSS.c index 49d8b073c..ec532ee8c 100644 --- a/swad_RSS.c +++ b/swad_RSS.c @@ -25,10 +25,8 @@ /********************************** Headers **********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For PATH_MAX #include // For NULL -#include // For asprintf #include #include "swad_changelog.h" diff --git a/swad_action.c b/swad_action.c index ee27475c2..7fc72ac58 100644 --- a/swad_action.c +++ b/swad_action.c @@ -1488,7 +1488,7 @@ Profile: 1289. ActSeeMyAgd Show my full agenda (personal organizer) 1290. ActFrmMyAcc Show form to the creation or change of user's account 1291. ActReqEdiRecSha Request the edition of the record with the personal data of the user - 1292. ActEdiPrf Show forms to edit preferences + 1292. ActReqEdiPrf Show forms to edit preferences 1300. ActChgMyRol Change type of logged user @@ -1525,10 +1525,6 @@ Profile: 1329. ActReqRemMyPho Request the removal of my photo 1330. ActRemMyPho Remove my photo - 1331. ActEdiPri Edit my privacy - 1332. ActChgPriPho Change privacy of my photo - 1333. ActChgPriPrf Change privacy of my public profile - 1335. ActChgCtyMyIns Change the country of my institution 1336. ActChgMyIns Change my institution 1337. ActChgMyCtr Change my centre @@ -1551,6 +1547,8 @@ Profile: 1352. ActShoRgtCol Show right side column 1353. ActChgIco Change icon set 1354. ActChgMnu Change menu + 1332. ActChgPriPho Change privacy of my photo + 1333. ActChgPriPrf Change privacy of my public profile 1355. ActChgNtfPrf Change whether to notify by email new messages 1356. ActPrnUsrQR Show my QR code ready to print @@ -3060,7 +3058,7 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActSeeMyAgd */{1602, 3,TabPrf,ActSeeMyAgd ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Agd_ShowMyAgenda ,"calendar" }, /* ActFrmMyAcc */{ 36, 4,TabPrf,ActFrmMyAcc ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Acc_ShowFormMyAccount ,"at" }, /* ActReqEdiRecSha */{ 285, 5,TabPrf,ActReqEdiRecSha ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Rec_ShowMySharedRecordAndMore ,"card" }, - /* ActEdiPrf */{ 673, 6,TabPrf,ActEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Pre_EditPrefs ,"cog" }, + /* ActReqEdiPrf */{ 673, 6,TabPrf,ActReqEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Pre_EditPrefs ,"cog" }, // Actions not in menu: /* ActChgMyRol */{ 589,-1,TabUnk,ActFrmRolSes ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,Rol_ChangeMyRole ,Usr_ShowFormsLogoutAndRole ,NULL}, @@ -3103,10 +3101,6 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActReqRemMyPho */{1577,-1,TabUnk,ActReqEdiRecSha ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Pho_ReqRemoveMyPhoto ,NULL}, /* ActRemMyPho */{ 428,-1,TabUnk,ActReqEdiRecSha ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,Pho_RemoveMyPhoto1 ,Pho_RemoveMyPhoto2 ,NULL}, - /* ActEdiPri */{1403,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Pre_EditPrefs ,NULL}, - /* ActChgPriPho */{ 774,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Pho_ChangePhotoVisibility ,NULL}, - /* ActChgPriPrf */{1404,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Prf_ChangeProfileVisibility ,NULL}, - /* ActChgCtyMyIns */{1166,-1,TabUnk,ActReqEdiRecSha ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Rec_ChgCountryOfMyInstitution ,NULL}, /* ActChgMyIns */{1167,-1,TabUnk,ActReqEdiRecSha ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Rec_UpdateMyInstitution ,NULL}, /* ActChgMyCtr */{1168,-1,TabUnk,ActReqEdiRecSha ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Rec_UpdateMyCentre ,NULL}, @@ -3117,19 +3111,21 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActReqEdiMyNet */{1172,-1,TabUnk,ActReqEdiRecSha ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Rec_ShowMySharedRecordAndMore ,NULL}, /* ActChgMyNet */{1173,-1,TabUnk,ActReqEdiRecSha ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Net_UpdateMyWebsAndSocialNets ,NULL}, - /* ActChgThe */{ 841,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,The_ChangeTheme ,Pre_EditPrefs ,NULL}, - /* ActReqChgLan */{ 992,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Lan_AskChangeLanguage ,NULL}, - /* ActChgLan */{ 654,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Lan_ChangeLanguage ,Pre_EditPrefs ,NULL}, - /* ActChg1stDay */{1484,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Cal_ChangeFirstDayOfWeek ,Pre_EditPrefs ,NULL}, - /* ActChgDatFmt */{1638,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Dat_ChangeDateFormat ,Pre_EditPrefs ,NULL}, - /* ActChgCol */{ 674,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Pre_ChangeSideCols ,Pre_EditPrefs ,NULL}, - /* ActHidLftCol */{ 668,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Pre_HideLeftCol ,Pre_EditPrefs ,NULL}, - /* ActHidRgtCol */{ 669,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Pre_HideRightCol ,Pre_EditPrefs ,NULL}, - /* ActShoLftCol */{ 670,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Pre_ShowLeftCol ,Pre_EditPrefs ,NULL}, - /* ActShoRgtCol */{ 671,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Pre_ShowRightCol ,Pre_EditPrefs ,NULL}, - /* ActChgIco */{1092,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Ico_ChangeIconSet ,Pre_EditPrefs ,NULL}, - /* ActChgMnu */{1243,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Mnu_ChangeMenu ,Pre_EditPrefs ,NULL}, - /* ActChgNtfPrf */{ 775,-1,TabUnk,ActEdiPrf ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,Ntf_ChangeNotifyEvents ,Pre_EditPrefs ,NULL}, + /* ActChgThe */{ 841,-1,TabUnk,ActReqEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,The_ChangeTheme ,Pre_EditPrefs ,NULL}, + /* ActReqChgLan */{ 992,-1,TabUnk,ActReqEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Lan_AskChangeLanguage ,NULL}, + /* ActChgLan */{ 654,-1,TabUnk,ActReqEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Lan_ChangeLanguage ,Pre_EditPrefs ,NULL}, + /* ActChg1stDay */{1484,-1,TabUnk,ActReqEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Cal_ChangeFirstDayOfWeek ,Pre_EditPrefs ,NULL}, + /* ActChgDatFmt */{1638,-1,TabUnk,ActReqEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Dat_ChangeDateFormat ,Pre_EditPrefs ,NULL}, + /* ActChgCol */{ 674,-1,TabUnk,ActReqEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Pre_ChangeSideCols ,Pre_EditPrefs ,NULL}, + /* ActHidLftCol */{ 668,-1,TabUnk,ActReqEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Pre_HideLeftCol ,Pre_EditPrefs ,NULL}, + /* ActHidRgtCol */{ 669,-1,TabUnk,ActReqEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Pre_HideRightCol ,Pre_EditPrefs ,NULL}, + /* ActShoLftCol */{ 670,-1,TabUnk,ActReqEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Pre_ShowLeftCol ,Pre_EditPrefs ,NULL}, + /* ActShoRgtCol */{ 671,-1,TabUnk,ActReqEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Pre_ShowRightCol ,Pre_EditPrefs ,NULL}, + /* ActChgIco */{1092,-1,TabUnk,ActReqEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Ico_ChangeIconSet ,Pre_EditPrefs ,NULL}, + /* ActChgMnu */{1243,-1,TabUnk,ActReqEdiPrf ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_1ST_TAB,Mnu_ChangeMenu ,Pre_EditPrefs ,NULL}, + /* ActChgPriPho */{ 774,-1,TabUnk,ActReqEdiPrf ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Pho_ChangePhotoVisibility ,NULL}, + /* ActChgPriPrf */{1404,-1,TabUnk,ActReqEdiPrf ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Prf_ChangeProfileVisibility ,NULL}, + /* ActChgNtfPrf */{ 775,-1,TabUnk,ActReqEdiPrf ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,Ntf_ChangeNotifyEvents ,Pre_EditPrefs ,NULL}, /* ActPrnUsrQR */{1022,-1,TabUnk,ActFrmMyAcc ,0x3F8,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,0x3C7,Act_CONT_NORM,Act_BRW_NEW_TAB,NULL ,Usr_PrintUsrQRCode ,NULL}, @@ -3814,7 +3810,7 @@ Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD] = // Do not reuse un ActShoLftCol, // #670 ActShoRgtCol, // #671 -1, // #672 (obsolete action) - ActEdiPrf, // #673 + ActReqEdiPrf, // #673 ActChgCol, // #674 ActSeeDpt, // #675 ActSeeCtr, // #676 @@ -4544,7 +4540,7 @@ Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD] = // Do not reuse un ActDowShaIns, // #1400 ActReqOthPubPrf, // #1401 ActSeeOthPubPrf, // #1402 - ActEdiPri, // #1403 + -1, // #1403 (obsolete action) ActChgPriPrf, // #1404 ActCal1stClkTim, // #1405 ActCalNumClk, // #1406 @@ -5128,238 +5124,177 @@ void Act_AdjustActionWhenNoUsrLogged (void) void Act_AdjustCurrentAction (void) { - bool IAmATeacher; + bool IAmATeacherInAnyCrs; + bool JustAfterLogin = Gbl.Action.Act == ActLogIn || + Gbl.Action.Act == ActLogInLan || + Gbl.Action.Act == ActAnnSee; - /***** Don't adjust anything when current action is not a menu option *****/ - // if (Gbl.Action.Act != Act_GetSuperAction (Gbl.Action.Act)) // It is not a menu option - // return; + /***** Don't adjust anything when current action is not a menu option + (except some actions just after login) *****/ + if (!JustAfterLogin && // Not just after login + Gbl.Action.Act != Act_GetSuperAction (Gbl.Action.Act)) // It is not a menu option + return; - /***** Don't adjust anything when refreshing users or on a web service *****/ + /***** Don't adjust anything when: + - refreshing users + - web service *****/ if (Gbl.Action.UsesAJAX || Gbl.WebService.IsWebService) return; - /***** If I have no password in database, - the only action possible is show a form to change my account *****/ + /***** Adjustment 1: + ------------- + If I have no password in database, + the only action possible + is to show a form to change my account *****/ if (!Gbl.Usrs.Me.UsrDat.Password[0]) { - switch (Gbl.Action.Act) - { - /* Action to log out */ - case ActLogOut: - /* Actions related with my account */ - case ActFrmMyAcc: case ActChgMyPwd: case ActChgMyNck: case ActChgMyMai: - break; - default: - Gbl.Action.Act = ActFrmMyAcc; - Tab_SetCurrentTab (); - return; - } + Gbl.Action.Act = ActFrmMyAcc; + Tab_SetCurrentTab (); + return; } - /***** Just after login, check if my password seems good *****/ + /***** Adjustment 2: + ------------- + Just after login, check if my password seems good. + If my password is not enough secure, + the only action possible + is to show a form to change my account *****/ if (Gbl.Action.Act == ActLogIn) if (!Pwd_FastCheckIfPasswordSeemsGood (Gbl.Usrs.Me.LoginPlainPassword)) - /* If my login password is not enough secure, - the only action possible is show a form to change my account */ { Gbl.Action.Act = ActFrmMyAcc; Tab_SetCurrentTab (); return; } - /***** If I have no nickname or email in database, - the only action possible is show a form to change my account *****/ + /***** Adjustment 3: + ------------- + If I have no nickname or email in database, + the only action possible + is to show a form to change my account *****/ if (!Gbl.Usrs.Me.UsrDat.Nickname[0] || !Gbl.Usrs.Me.UsrDat.Email[0]) { - switch (Gbl.Action.Act) - { - /* Action to log out */ - case ActLogOut: - /* Actions related with my account */ - case ActFrmMyAcc: case ActChgMyPwd: case ActChgMyNck: case ActChgMyMai: - break; - default: - Gbl.Action.Act = ActFrmMyAcc; - Tab_SetCurrentTab (); - return; - } + Gbl.Action.Act = ActFrmMyAcc; + Tab_SetCurrentTab (); + return; } - /***** If I haven't filled my sex, first name, surname 1 or country, - the only action possible is to show a form to change my common record *****/ + /***** Check if I am a teacher in any course *****/ + Rol_GetRolesInAllCrssIfNotYetGot (&Gbl.Usrs.Me.UsrDat); + IAmATeacherInAnyCrs = (Gbl.Usrs.Me.UsrDat.Roles.InCrss & ((1 << Rol_NET) | // I am a non-editing teacher... + (1 << Rol_TCH))); // ...or a teacher in any course + + /***** Adjustment 4: + ------------- + If I haven't filled + - my sex + - my first name + - my surname 1 + - my country + - my institution + or if I'm a teacher and I haven't filled + - my centre + - my department, + the only action possible + is to show a form to change my shared record card *****/ if ( Gbl.Usrs.Me.UsrDat.Sex == Usr_SEX_UNKNOWN || !Gbl.Usrs.Me.UsrDat.FirstName[0] || - !Gbl.Usrs.Me.UsrDat.Surname1[0] || - Gbl.Usrs.Me.UsrDat.CtyCod <= 0) - switch (Gbl.Action.Act) + !Gbl.Usrs.Me.UsrDat.Surname1 [0] || + Gbl.Usrs.Me.UsrDat.CtyCod <= 0 || + Gbl.Usrs.Me.UsrDat.InsCod < 0 || + (IAmATeacherInAnyCrs && (Gbl.Usrs.Me.UsrDat.Tch.CtrCod < 0 || + Gbl.Usrs.Me.UsrDat.Tch.DptCod < 0))) { - /* Action to log out */ - case ActLogOut: - /* Actions related with my account */ - case ActFrmMyAcc: case ActChgMyPwd: case ActChgMyNck: case ActChgMyMai: - /* Actions related with my record card */ - case ActReqEdiRecSha: case ActChgMyData: case ActChgCtyMyIns: case ActChgMyIns: - break; - default: - Gbl.Action.Act = ActReqEdiRecSha; - Tab_SetCurrentTab (); - return; + Gbl.Action.Act = ActReqEdiRecSha; + Tab_SetCurrentTab (); + return; } - /***** Check if I am a teacher *****/ - Rol_GetRolesInAllCrssIfNotYetGot (&Gbl.Usrs.Me.UsrDat); - IAmATeacher = (Gbl.Usrs.Me.UsrDat.Roles.InCrss & ((1 << Rol_NET) | // I am a non-editing teacher... - (1 << Rol_TCH))); // ...or a teacher in any course - - /***** If I haven't filled my institution, - or if I'm a teacher and I haven't filled my centre or department, - the only action possible is to show a form to change my common record *****/ - if (Gbl.Usrs.Me.UsrDat.InsCod < 0 || - (IAmATeacher && (Gbl.Usrs.Me.UsrDat.Tch.CtrCod < 0 || - Gbl.Usrs.Me.UsrDat.Tch.DptCod < 0))) - switch (Gbl.Action.Act) - { - /* Action to log out */ - case ActLogOut: - /* Actions related with my account */ - case ActFrmMyAcc: case ActChgMyPwd: case ActChgMyNck: case ActChgMyMai: - /* Actions related with my record card */ - case ActReqEdiRecSha: case ActChgMyData: case ActChgCtyMyIns: case ActChgMyIns: - break; - default: - Gbl.Action.Act = ActReqEdiRecSha; - Tab_SetCurrentTab (); - return; - } - - /***** If any of my preferences about privacy is unknown *****/ + /***** Adjustment 5: + ------------- + If any of my preferences about privacy is unknown + the only action possible + is to show a form to change my preferences *****/ if (Gbl.Usrs.Me.UsrDat.PhotoVisibility == Pri_VISIBILITY_UNKNOWN || Gbl.Usrs.Me.UsrDat.ProfileVisibility == Pri_VISIBILITY_UNKNOWN) - switch (Gbl.Action.Act) { - /* Action to log out */ - case ActLogOut: - /* Actions related with my account */ - case ActFrmMyAcc: case ActChgMyPwd: case ActChgMyNck: case ActChgMyMai: - /* Actions related with my record card */ - case ActReqEdiRecSha: case ActChgMyData: case ActChgCtyMyIns: case ActChgMyIns: - /* Action to edit privacy */ - case ActEdiPri: - break; - default: - Gbl.Action.Act = ActEdiPri; - Tab_SetCurrentTab (); - return; + Gbl.Action.Act = ActReqEdiPrf; + Tab_SetCurrentTab (); + return; } /***** If I belong to current course *****/ if (Gbl.Usrs.Me.IBelongToCurrentCrs) { - /***** If I have not accepted the enrolment, - the only action possible is show a form to ask for enrolment *****/ - if (!Gbl.Usrs.Me.UsrDat.Accepted && Gbl.Action.Act != ActLogOut) + /***** Adjustment 6: + ------------- + If I have not accepted my enrolment in the current course, + the only action possible + is to show a form to ask for enrolment *****/ + if (!Gbl.Usrs.Me.UsrDat.Accepted) { switch (Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role) { case Rol_STD: - switch (Gbl.Action.Act) - { - /* Actions related with enrolment as student */ - case ActReqAccEnrStd: case ActAccEnrStd: case ActRemMe_Std: - return; - default: - Gbl.Action.Act = ActReqAccEnrStd; - Tab_SetCurrentTab (); - return; - } + Gbl.Action.Act = ActReqAccEnrStd; break; case Rol_NET: - switch (Gbl.Action.Act) - { - /* Actions related with enrolment as non-editing teacher */ - case ActReqAccEnrNET: case ActAccEnrNET: case ActRemMe_NET: - return; - default: - Gbl.Action.Act = ActReqAccEnrNET; - Tab_SetCurrentTab (); - return; - } + Gbl.Action.Act = ActReqAccEnrNET; break; case Rol_TCH: - switch (Gbl.Action.Act) - { - /* Actions related with enrolment as teacher */ - case ActReqAccEnrTch: case ActAccEnrTch: case ActRemMe_Tch: - return; - default: - Gbl.Action.Act = ActReqAccEnrTch; - Tab_SetCurrentTab (); - return; - } + Gbl.Action.Act = ActReqAccEnrTch; break; default: break; } + Tab_SetCurrentTab (); + return; } - /***** Depending on the role I am logged... *****/ + /***** Depending on the role I am logged in the current course... *****/ switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: - switch (Gbl.Action.Act) - { - case ActLogInNew: - case ActMnu: - /* Action to log out */ - case ActLogOut: - /* Actions related with my account */ - case ActFrmMyAcc: case ActChgMyPwd: case ActChgMyNck: case ActChgMyMai: - /* Actions related with my record card */ - case ActReqEdiRecSha: case ActChgMyData: case ActChgCtyMyIns: case ActChgMyIns: - /* Action to edit privacy */ - case ActEdiPri: - /* Actions related with my group registration */ - case ActReqSelGrp: case ActChgGrp: - case ActReqMdfOneStd: // A student use this action to remove him/herself from current course - /* Actions allowed in order to students could see/print timetable before register in groups */ - case ActSeeCrsTT: case ActPrnCrsTT: case ActChgCrsTT1stDay: - break; - default: - /* If there are some group types with groups in wich I must register, - the the only action possible is show a form to register in groups */ - if (Grp_GetIfAnyMandatoryGrpTypIsAvailable ()) // This query may be slow + /* Action allowed for students to see/print + the timetable before registering in groups */ + if (Gbl.Action.Act == ActSeeCrsTT) + return; + + /***** Adjustment 7: + ------------- + If there are some group types + with available groups in which I must register, + the only action possible + is show a form to register in groups *****/ + if (Grp_GetIfAnyMandatoryGrpTypIsAvailable (-1L)) // This query may be slow + { + Gbl.Action.Act = ActReqSelGrp; + Tab_SetCurrentTab (); + return; + } + + /***** Adjustment 8: + ------------- + If I have no photo + and current action is not available for unknown users, + then update number of clicks without photo. + If limit of clicks is reached, + the only action possible + is to show a form to send my photo *****/ + if (!Gbl.Usrs.Me.MyPhotoExists) + if (!(Act_Actions[Gbl.Action.Act].PermissionCrsIfIBelong & (1 << Rol_UNK))) + if ((Gbl.Usrs.Me.NumAccWithoutPhoto = + Pho_UpdateMyClicksWithoutPhoto ()) > Pho_MAX_CLICKS_WITHOUT_PHOTO) { - Gbl.Action.Act = ActReqSelGrp; + /* If limit of clicks has been reached, + the only action possible is show a form to send my photo */ + Gbl.Action.Act = ActReqMyPho; Tab_SetCurrentTab (); return; } - /* If I have no photo, and current action is not available for unknown users, - then update number of clicks without photo */ - if (!Gbl.Usrs.Me.MyPhotoExists) - if (!(Act_Actions[Gbl.Action.Act].PermissionCrsIfIBelong & (1 << Rol_UNK))) // If current action is not available for unknown users... - switch (Gbl.Action.Act) - { - /* Actions related to sending my photo */ - case ActReqMyPho: case ActDetMyPho: case ActUpdMyPho: - break; - default: - if ((Gbl.Usrs.Me.NumAccWithoutPhoto = - Pho_UpdateMyClicksWithoutPhoto ()) > Pho_MAX_CLICKS_WITHOUT_PHOTO) - { - /* If limit of clicks has been reached, - the only action possible is show a form to send my photo */ - Gbl.Action.Act = ActReqMyPho; - Tab_SetCurrentTab (); - return; - } - break; - } - break; - } - /***** Check if it is mandatory to read any information about course *****/ if (Gbl.Action.Act == ActMnu) // Do the following check sometimes, for example when the user changes the current tab Gbl.CurrentCrs.Info.ShowMsgMustBeRead = Inf_GetIfIMustReadAnyCrsInfoInThisCrs (); @@ -5367,38 +5302,28 @@ void Act_AdjustCurrentAction (void) case Rol_NET: break; case Rol_TCH: - switch (Gbl.Action.Act) - { - /* Actions related with test configuration */ - case ActCfgTst: case ActRcvCfgTst: - break; - default: - /***** If current course has tests and pluggable is unknown, - the only action possible is configure tests *****/ - if (Tst_CheckIfCourseHaveTestsAndPluggableIsUnknown ()) - { - Gbl.Action.Act = ActCfgTst; - Tab_SetCurrentTab (); - return; - } - break; - } + /***** Adjustment 9: + ------------- + If current course has tests and pluggable is unknown, + the only action possible is configure tests *****/ + if (Tst_CheckIfCourseHaveTestsAndPluggableIsUnknown ()) + { + Gbl.Action.Act = ActCfgTst; + Tab_SetCurrentTab (); + return; + } break; default: break; } } - /***** Just after login with all checks OK ==> go to timeline *****/ - switch (Gbl.Action.Act) + /***** Adjustment 10: + -------------- + Just after login with all checks OK ==> go to timeline *****/ + if (JustAfterLogin) { - case ActLogIn: - case ActLogInLan: - case ActAnnSee: - Gbl.Action.Act = ActSeeSocTmlGbl; - Tab_SetCurrentTab (); - return; - default: - break; + Gbl.Action.Act = ActSeeSocTmlGbl; + Tab_SetCurrentTab (); } } diff --git a/swad_action.h b/swad_action.h index b4206351a..ae2535a40 100644 --- a/swad_action.h +++ b/swad_action.h @@ -61,7 +61,7 @@ typedef enum typedef signed int Act_Action_t; // Must be a signed type, because -1 is used to indicate obsolete action -#define Act_NUM_ACTIONS (1 + 8 + 59 + 38 + 12 + 42 + 36 + 19 + 110 + 157 + 437 + 165 + 168 + 15 + 66) +#define Act_NUM_ACTIONS (1 + 8 + 59 + 38 + 12 + 42 + 36 + 19 + 110 + 157 + 437 + 165 + 168 + 15 + 65) #define Act_MAX_ACTION_COD 1752 @@ -1522,7 +1522,7 @@ typedef signed int Act_Action_t; // Must be a signed type, because -1 is used to #define ActSeeMyAgd (ActSeeMyUsgRep + 4) #define ActFrmMyAcc (ActSeeMyUsgRep + 5) #define ActReqEdiRecSha (ActSeeMyUsgRep + 6) -#define ActEdiPrf (ActSeeMyUsgRep + 7) +#define ActReqEdiPrf (ActSeeMyUsgRep + 7) // Secondary actions #define ActChgMyRol (ActSeeMyUsgRep + 8) #define ActFrmNewEvtMyAgd (ActSeeMyUsgRep + 9) @@ -1558,40 +1558,38 @@ typedef signed int Act_Action_t; // Must be a signed type, because -1 is used to #define ActReqRemMyPho (ActSeeMyUsgRep + 36) #define ActRemMyPho (ActSeeMyUsgRep + 37) -#define ActEdiPri (ActSeeMyUsgRep + 38) -#define ActChgPriPho (ActSeeMyUsgRep + 39) -#define ActChgPriPrf (ActSeeMyUsgRep + 40) +#define ActChgCtyMyIns (ActSeeMyUsgRep + 38) +#define ActChgMyIns (ActSeeMyUsgRep + 39) +#define ActChgMyCtr (ActSeeMyUsgRep + 40) +#define ActChgMyDpt (ActSeeMyUsgRep + 41) +#define ActChgMyOff (ActSeeMyUsgRep + 42) +#define ActChgMyOffPho (ActSeeMyUsgRep + 43) -#define ActChgCtyMyIns (ActSeeMyUsgRep + 41) -#define ActChgMyIns (ActSeeMyUsgRep + 42) -#define ActChgMyCtr (ActSeeMyUsgRep + 43) -#define ActChgMyDpt (ActSeeMyUsgRep + 44) -#define ActChgMyOff (ActSeeMyUsgRep + 45) -#define ActChgMyOffPho (ActSeeMyUsgRep + 46) +#define ActReqEdiMyNet (ActSeeMyUsgRep + 44) +#define ActChgMyNet (ActSeeMyUsgRep + 45) -#define ActReqEdiMyNet (ActSeeMyUsgRep + 47) -#define ActChgMyNet (ActSeeMyUsgRep + 48) +#define ActChgThe (ActSeeMyUsgRep + 46) +#define ActReqChgLan (ActSeeMyUsgRep + 47) +#define ActChgLan (ActSeeMyUsgRep + 48) +#define ActChg1stDay (ActSeeMyUsgRep + 49) +#define ActChgDatFmt (ActSeeMyUsgRep + 50) +#define ActChgCol (ActSeeMyUsgRep + 51) +#define ActHidLftCol (ActSeeMyUsgRep + 52) +#define ActHidRgtCol (ActSeeMyUsgRep + 53) +#define ActShoLftCol (ActSeeMyUsgRep + 54) +#define ActShoRgtCol (ActSeeMyUsgRep + 55) +#define ActChgIco (ActSeeMyUsgRep + 56) +#define ActChgMnu (ActSeeMyUsgRep + 67) +#define ActChgPriPho (ActSeeMyUsgRep + 58) +#define ActChgPriPrf (ActSeeMyUsgRep + 59) +#define ActChgNtfPrf (ActSeeMyUsgRep + 60) -#define ActChgThe (ActSeeMyUsgRep + 49) -#define ActReqChgLan (ActSeeMyUsgRep + 50) -#define ActChgLan (ActSeeMyUsgRep + 51) -#define ActChg1stDay (ActSeeMyUsgRep + 52) -#define ActChgDatFmt (ActSeeMyUsgRep + 53) -#define ActChgCol (ActSeeMyUsgRep + 54) -#define ActHidLftCol (ActSeeMyUsgRep + 55) -#define ActHidRgtCol (ActSeeMyUsgRep + 56) -#define ActShoLftCol (ActSeeMyUsgRep + 57) -#define ActShoRgtCol (ActSeeMyUsgRep + 58) -#define ActChgIco (ActSeeMyUsgRep + 59) -#define ActChgMnu (ActSeeMyUsgRep + 60) -#define ActChgNtfPrf (ActSeeMyUsgRep + 61) +#define ActPrnUsrQR (ActSeeMyUsgRep + 61) -#define ActPrnUsrQR (ActSeeMyUsgRep + 62) - -#define ActPrnMyTT (ActSeeMyUsgRep + 63) -#define ActEdiTut (ActSeeMyUsgRep + 64) -#define ActChgTut (ActSeeMyUsgRep + 65) -#define ActChgMyTT1stDay (ActSeeMyUsgRep + 66) +#define ActPrnMyTT (ActSeeMyUsgRep + 62) +#define ActEdiTut (ActSeeMyUsgRep + 63) +#define ActChgTut (ActSeeMyUsgRep + 64) +#define ActChgMyTT1stDay (ActSeeMyUsgRep + 65) /*****************************************************************************/ /******************************** Public types *******************************/ diff --git a/swad_attendance.c b/swad_attendance.c index cb64b0c07..82fd45b65 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -25,11 +25,9 @@ /********************************** Headers **********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For PATH_MAX #include // For NULL #include // To access MySQL databases -#include // For asprintf #include // For calloc #include // For string functions diff --git a/swad_calendar.c b/swad_calendar.c index 3dc460490..2f1cb403d 100644 --- a/swad_calendar.c +++ b/swad_calendar.c @@ -25,8 +25,6 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf -#include // For asprintf #include // For string functions #include "swad_box.h" diff --git a/swad_centre.c b/swad_centre.c index 12b55e0ee..8c31dee83 100644 --- a/swad_centre.c +++ b/swad_centre.c @@ -25,10 +25,8 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For NULL #include // For boolean type -#include // For asprintf #include // For calloc #include // For string functions #include // For the macro WEXITSTATUS diff --git a/swad_changelog.h b/swad_changelog.h index f1576ed23..287607cc9 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -382,6 +382,7 @@ OPTIMIZE TABLE debug; */ // TODO: Editar todas mis webs al mismo tiempo poniendo al final un botón "Guardar cambios" +// TODO: Chequear login para ver agenda desde código QR /*****************************************************************************/ /****************************** Public constants *****************************/ @@ -402,11 +403,16 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.48.1 (2019-02-18)" +#define Log_PLATFORM_VERSION "SWAD 18.49 (2019-02-18)" #define CSS_FILE "swad18.41.1.css" #define JS_FILE "swad18.32.1.js" /* - Version 18.48.1: Feb 18, 2019 Optimization on query about available mandatory group types. (237548 lines) + Version 18.49: Feb 18, 2019 Optimizations adjusting actions. + Fixed bug in query about available mandatory group types. (237378 lines) + 1 change necessary in database: +UPDATE actions SET Obsolete='Y' WHERE ActCod='1403'; + + Version 18.48.1: Feb 18, 2019 Optimization in query about available mandatory group types. (237548 lines) Version 18.48: Feb 18, 2019 Fixed bugs in actions related to account. Fixed bug related with groups. (237589 lines) 1 change necessary in database: diff --git a/swad_chat.c b/swad_chat.c index a80edb96c..19f9567b5 100644 --- a/swad_chat.c +++ b/swad_chat.c @@ -25,10 +25,8 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For NULL #include // For boolean type -#include // For asprintf #include #include "swad_box.h" diff --git a/swad_connected.c b/swad_connected.c index 24a749394..5357b690b 100644 --- a/swad_connected.c +++ b/swad_connected.c @@ -25,11 +25,10 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For maximum values #include // For PATH_MAX #include // For NULL -#include // For fprintf, asprintf +#include // For fprintf #include // For string functions #include "swad_box.h" diff --git a/swad_date.c b/swad_date.c index 5b0b98cb2..de0edba70 100644 --- a/swad_date.c +++ b/swad_date.c @@ -25,8 +25,6 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf -#include // For asprintf #include // For string functions #include // For time functions (mktime...) diff --git a/swad_degree.c b/swad_degree.c index c743a64e1..6bd1da34c 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -25,11 +25,10 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For isprint, isspace, etc. #include // For NULL #include // For boolean type -#include // For fprintf, asprintf, etc. +#include // For fprintf, etc. #include // For exit, system, calloc, free, etc. #include // For string functions #include // To access MySQL databases diff --git a/swad_degree_type.c b/swad_degree_type.c index e3a24cd22..b53c95746 100644 --- a/swad_degree_type.c +++ b/swad_degree_type.c @@ -25,11 +25,10 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For isprint, isspace, etc. #include // For NULL #include // For boolean type -#include // For fprintf, asprintf, etc. +#include // For fprintf, etc. #include // For exit, system, calloc, free, etc. #include // For string functions #include // To access MySQL databases diff --git a/swad_department.c b/swad_department.c index 6027d52d9..9bad392ff 100644 --- a/swad_department.c +++ b/swad_department.c @@ -25,10 +25,8 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For NULL #include // For boolean type -#include // For asprintf #include // For calloc #include // For string functions diff --git a/swad_duplicate.c b/swad_duplicate.c index aad6dd819..64e5e1df9 100644 --- a/swad_duplicate.c +++ b/swad_duplicate.c @@ -25,9 +25,6 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf -#include // For asprintf - #include "swad_account.h" #include "swad_box.h" #include "swad_database.h" diff --git a/swad_follow.c b/swad_follow.c index c09d133bc..220f3046f 100644 --- a/swad_follow.c +++ b/swad_follow.c @@ -25,9 +25,7 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For boolean type -#include // For asprintf #include // For string functions #include "swad_box.h" diff --git a/swad_group.c b/swad_group.c index 1bc1eb518..d7463de7e 100644 --- a/swad_group.c +++ b/swad_group.c @@ -130,8 +130,7 @@ static void Grp_GetDataOfGroupTypeByCod (struct GroupType *GrpTyp); static bool Grp_GetMultipleEnrolmentOfAGroupType (long GrpTypCod); static long Grp_GetTypeOfGroupOfAGroup (long GrpCod); static unsigned long Grp_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod); -static long Grp_GetFirstCodGrpIBelongTo (long GrpTypCod); -static bool Grp_GetIfGrpTypIsAvailable (long GrpTypCod); +static bool Grp_CheckIfIBelongToGrpsOfType (long GrpTypCod); static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,long UsrCod, struct ListCodGrps *LstGrps); static bool Grp_CheckIfGrpIsInList (long GrpCod,struct ListCodGrps *LstGrps); @@ -1897,9 +1896,12 @@ static void Grp_ShowWarningToStdsToChangeGrps (void) NumGrpTyp++) { GrpTyp = &Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp]; - if (GrpTyp->NumGrps) // If there are groups of this type - if (Grp_GetFirstCodGrpIBelongTo (GrpTyp->GrpTypCod) < 0) // If I don't belong to any group - if (Grp_GetIfGrpTypIsAvailable (GrpTyp->GrpTypCod)) // If there is any group of this type available + // If there are groups of this type... + if (GrpTyp->NumGrps) + // If I don't belong to any group + if (!Grp_CheckIfIBelongToGrpsOfType (GrpTyp->GrpTypCod)) // Fast check (not necesary, but avoid slow check) + // If there is any group of this type available + if (Grp_GetIfAnyMandatoryGrpTypIsAvailable (GrpTyp->GrpTypCod)) // Slow check { if (GrpTyp->MandatoryEnrolment) Ale_ShowAlert (Ale_WARNING,GrpTyp->MultipleEnrolment ? Txt_You_have_to_register_compulsorily_at_least_in_one_group_of_type_X : @@ -3347,42 +3349,23 @@ static unsigned long Grp_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTyp } /*****************************************************************************/ -/**** Get the first code of group of cierto type al that pert. a student *****/ +/********* Check if I belong to any groups of a given type I belong **********/ /*****************************************************************************/ -// Return -GrpTypCod if I don't belong to any group of type GrpTypCod -static long Grp_GetFirstCodGrpIBelongTo (long GrpTypCod) +static bool Grp_CheckIfIBelongToGrpsOfType (long GrpTypCod) { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned long NumRows; - long CodGrpIBelong; + unsigned long NumGrps; /***** Get a group which I belong to from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not check if you belong to a group", - "SELECT crs_grp.GrpCod" - " FROM crs_grp,crs_grp_usr" - " WHERE crs_grp.GrpTypCod=%ld" - " AND crs_grp.GrpCod=crs_grp_usr.GrpCod" - " AND crs_grp_usr.UsrCod=%ld", // I belong - GrpTypCod,Gbl.Usrs.Me.UsrDat.UsrCod); + NumGrps = DB_QueryCOUNT ("can not check if you belong to a group type", + "SELECT COUNT(crs_grp.GrpCod)" + " FROM crs_grp,crs_grp_usr" + " WHERE crs_grp.GrpTypCod=%ld" + " AND crs_grp.GrpCod=crs_grp_usr.GrpCod" + " AND crs_grp_usr.UsrCod=%ld", // I belong + GrpTypCod,Gbl.Usrs.Me.UsrDat.UsrCod); - /***** Get the group *****/ - if (NumRows == 0) - CodGrpIBelong = -GrpTypCod; - else // If there are more than a group, only get the first one - { - row = mysql_fetch_row (mysql_res); - - /* Get the code of group (row[0]) */ - if ((CodGrpIBelong = Str_ConvertStrCodToLongCod (row[0])) < 0) - Lay_ShowErrorAndExit ("Wrong code of group."); - } - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - - return CodGrpIBelong; + return (NumGrps != 0); } /*****************************************************************************/ @@ -3498,10 +3481,27 @@ bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat) /*****************************************************************************/ /**** Query if any mandatory group in this course is open and has vacants ****/ /*****************************************************************************/ +// If GrpTypCod > 0 ==> restrict to the given group type, mandatory or not +// If GrpTypCod <= 0 ==> all mandatory group types in the current course -bool Grp_GetIfAnyMandatoryGrpTypIsAvailable (void) +bool Grp_GetIfAnyMandatoryGrpTypIsAvailable (long GrpTypCod) { unsigned NumGrpTypes; + char *SubQueryGrpTypes; + + if (GrpTypCod > 0) // restrict to the given group type, mandatory or not + { + if (asprintf (&SubQueryGrpTypes,"crs_grp_types.GrpTypCod=%ld", + GrpTypCod) < 0) + Lay_NotEnoughMemoryExit (); + } + else // all mandatory group types in the current course + { + if (asprintf (&SubQueryGrpTypes,"crs_grp_types.CrsCod=%ld" + " AND crs_grp_types.Mandatory='Y'", + Gbl.CurrentCrs.Crs.CrsCod) < 0) + Lay_NotEnoughMemoryExit (); + } /***** Get the number of types of group in this course with one or more open groups with vacants, from database *****/ @@ -3510,104 +3510,60 @@ bool Grp_GetIfAnyMandatoryGrpTypIsAvailable (void) "SELECT COUNT(GrpTypCod) FROM " "(" - // Available groups with students + // Available mandatory groups with students + "SELECT GrpTypCod FROM" + " (" "SELECT crs_grp_types.GrpTypCod AS GrpTypCod," "COUNT(*) AS NumStudents," "crs_grp.MaxStudents as MaxStudents" " FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr" - " WHERE crs_grp_types.CrsCod=%ld" // In this course + " WHERE %s" // Which group types? " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" " AND crs_grp.Open='Y'" // Open - " AND crs_grp.MaxStudents > 0" // Admits students + " AND crs_grp.MaxStudents>0" // Admits students " AND crs_grp_types.CrsCod=crs_usr.CrsCod" " AND crs_grp.GrpCod=crs_grp_usr.GrpCod" " AND crs_grp_usr.UsrCod=crs_usr.UsrCod" - " AND crs_usr.Role=%u" // With some student + " AND crs_usr.Role=%u" // Student " GROUP BY crs_grp.GrpCod" " HAVING NumStudents 0" // Admits students - " AND crs_grp.GrpCod NOT IN" // Only if empty + " AND crs_grp.MaxStudents>0" // Admits students + // ...without students + " AND crs_grp.GrpCod NOT IN" " (SELECT crs_grp_usr.GrpCod" " FROM crs_usr,crs_grp_usr" " WHERE crs_usr.CrsCod=%ld" - " AND crs_usr.Role=%u" + " AND crs_usr.Role=%u" // Student " AND crs_usr.UsrCod=crs_grp_usr.UsrCod)" - ") AS available_grp_types", + ") AS available_grp_types" - Gbl.CurrentCrs.Crs.CrsCod,(unsigned) Rol_STD, - Gbl.CurrentCrs.Crs.CrsCod, - Gbl.CurrentCrs.Crs.CrsCod,(unsigned) Rol_STD); - - return (NumGrpTypes != 0); - } - -/*****************************************************************************/ -/********** Query if any group of a type is open and has vacants *************/ -/*****************************************************************************/ - -static bool Grp_GetIfGrpTypIsAvailable (long GrpTypCod) - { - unsigned NumGrpTypes; - - /***** Get the number of types of group (0 or 1) of a type - with one or more open groups with vacants, from database *****/ - NumGrpTypes = - (unsigned) DB_QueryCOUNT ("can not check if a type of group has available groups", - "SELECT COUNT(GrpTypCod) FROM " - "(" - - // Available groups with students - "SELECT crs_grp_types.GrpTypCod AS GrpTypCod," - "COUNT(*) AS NumStudents," - "crs_grp.MaxStudents as MaxStudents" - " FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr" - " WHERE crs_grp_types.GrpTypCod=%ld" // Of this type + // ...to which I don't belong + " WHERE GrpTypCod NOT IN" + " (SELECT crs_grp_types.GrpTypCod" + " FROM crs_grp_types,crs_grp,crs_grp_usr" + " WHERE %s" // Which group types? " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" - " AND crs_grp.Open='Y'" // Open - " AND crs_grp.MaxStudents > 0" // Admits students - " AND crs_grp_types.CrsCod=crs_usr.CrsCod" " AND crs_grp.GrpCod=crs_grp_usr.GrpCod" - " AND crs_grp_usr.UsrCod=crs_usr.UsrCod" - " AND crs_usr.Role=%u" // With some student - " GROUP BY crs_grp.GrpCod" - " HAVING NumStudents 0" // Admits students - " AND crs_grp.GrpCod NOT IN" // Only if empty - " (SELECT crs_grp_usr.GrpCod" - " FROM crs_grp_types,crs_usr,crs_grp_usr" - " WHERE crs_grp_types.GrpTypCod=%ld" - " AND crs_grp_types.CrsCod=crs_usr.CrsCod" - " AND crs_usr.Role=%u" - " AND crs_usr.UsrCod=crs_grp_usr.UsrCod)" - - ") AS available_grp_types", - - GrpTypCod,(unsigned) Rol_STD, - GrpTypCod, - GrpTypCod,(unsigned) Rol_STD); + /***** Free allocated memory for subquery *****/ + free ((void *) SubQueryGrpTypes); return (NumGrpTypes != 0); } diff --git a/swad_group.h b/swad_group.h index d33638055..9953fa61c 100644 --- a/swad_group.h +++ b/swad_group.h @@ -186,7 +186,7 @@ bool Grp_GetIfIBelongToGrp (long GrpCod); void Grp_FlushCacheUsrSharesAnyOfMyGrpsInCurrentCrs (void); bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat); -bool Grp_GetIfAnyMandatoryGrpTypIsAvailable (void); +bool Grp_GetIfAnyMandatoryGrpTypIsAvailable (long GrpTypCod); void Grp_GetLstCodGrpsWithFileZonesIBelong (struct ListCodGrps *LstGrps); void Grp_GetNamesGrpsStdBelongsTo (long GrpTypCod,long UsrCod,char *GrpNames); diff --git a/swad_holiday.c b/swad_holiday.c index 71c997d65..24c55a77f 100644 --- a/swad_holiday.c +++ b/swad_holiday.c @@ -25,9 +25,7 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For NULL -#include // For asprintf #include // For calloc #include // For string functions diff --git a/swad_icon.c b/swad_icon.c index 909df45cc..fe8beb1f5 100644 --- a/swad_icon.c +++ b/swad_icon.c @@ -25,8 +25,6 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf -#include // For asprintf, fprintf, etc. #include #include "swad_box.h" diff --git a/swad_info.c b/swad_info.c index 4612b7fe8..20dffc766 100644 --- a/swad_info.c +++ b/swad_info.c @@ -25,11 +25,9 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For maximum values #include // For PATH_MAX, NAME_MAX #include // For NULL -#include // For asprintf #include // For getenv, etc #include // For SOAP_OK and soap functions #include // For string functions diff --git a/swad_institution.c b/swad_institution.c index 1a03bdcc7..b415bb87e 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -25,9 +25,7 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For NULL -#include // For asprintf #include // For calloc #include // For string functions diff --git a/swad_language.c b/swad_language.c index 796a8cf44..1166475f2 100644 --- a/swad_language.c +++ b/swad_language.c @@ -25,9 +25,6 @@ /********************************** Headers **********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf -#include // For asprintf - #include "swad_box.h" #include "swad_database.h" #include "swad_form.h" @@ -77,7 +74,7 @@ static void Lan_PutParamLanguage (void); void Lan_PutLinkToChangeLanguage (void) { - Lay_PutContextualLinkIconText (ActEdiPrf,NULL,NULL, + Lay_PutContextualLinkIconText (ActReqEdiPrf,NULL,NULL, "globe.svg", "Change language"); } diff --git a/swad_link.c b/swad_link.c index c2d6e5a61..5dcb56a61 100644 --- a/swad_link.c +++ b/swad_link.c @@ -25,9 +25,7 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For NULL -#include // For asprintf #include // For calloc #include // For string functions diff --git a/swad_mail.c b/swad_mail.c index 3a5e12966..edb3f8b16 100644 --- a/swad_mail.c +++ b/swad_mail.c @@ -25,9 +25,7 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For NULL -#include // For asprintf #include // For calloc #include // For string functions #include // For the macro WEXITSTATUS diff --git a/swad_menu.c b/swad_menu.c index 644b4aa33..2c1ffb118 100644 --- a/swad_menu.c +++ b/swad_menu.c @@ -25,8 +25,7 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf -#include // For asprintf, fprintf, etc. +#include // For fprintf, etc. #include "swad_box.h" #include "swad_database.h" @@ -287,7 +286,7 @@ const Act_Action_t Mnu_MenuActions[Tab_NUM_TABS][Act_MAX_OPTIONS_IN_MENU_PER_TAB ActSeeMyAgd, // 3 ActFrmMyAcc, // 4 ActReqEdiRecSha, // 5 - ActEdiPrf, // 6 + ActReqEdiPrf, // 6 0, // 7 0, // 8 0, // 9 diff --git a/swad_network.c b/swad_network.c index 5f3f17ee7..58573122d 100644 --- a/swad_network.c +++ b/swad_network.c @@ -25,8 +25,6 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf -#include // For asprintf #include #include "swad_box.h" diff --git a/swad_nickname.c b/swad_nickname.c index 734481638..8b7eb9916 100644 --- a/swad_nickname.c +++ b/swad_nickname.c @@ -25,8 +25,6 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf -#include // For asprintf #include // For string functions #include "swad_account.h" diff --git a/swad_notice.c b/swad_notice.c index bc67a125e..32f6e03cb 100644 --- a/swad_notice.c +++ b/swad_notice.c @@ -25,10 +25,8 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For PATH_MAX #include // For NULL -#include // For asprintf #include // For exit, system, malloc, calloc, free, etc. #include diff --git a/swad_notification.c b/swad_notification.c index 40ea6318c..07cba6b6c 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -25,9 +25,7 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For NULL -#include // For asprintf #include // For system #include #include // For the macro WEXITSTATUS @@ -373,7 +371,7 @@ void Ntf_ShowMyNotifications (void) Txt_Mark_all_NOTIFICATIONS_as_read); /* Put form to change notification preferences */ - Lay_PutContextualLinkIconText (ActEdiPrf,NULL,NULL, + Lay_PutContextualLinkIconText (ActReqEdiPrf,NULL,NULL, "cog.svg", Txt_Settings); diff --git a/swad_pagination.c b/swad_pagination.c index e7d719a52..f883ac1c0 100644 --- a/swad_pagination.c +++ b/swad_pagination.c @@ -25,9 +25,7 @@ /********************************** Headers **********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For NULL -#include // For asprintf #include "swad_action.h" #include "swad_database.h" diff --git a/swad_photo.c b/swad_photo.c index d6525ca8e..e70c97efc 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -25,11 +25,9 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For PATH_MAX #include // For NULL #include // For log10, floor, ceil, modf, sqrt... -#include // For asprintf #include // For system, getenv, etc. #include // For string functions #include // For the macro WEXITSTATUS diff --git a/swad_place.c b/swad_place.c index 8303e5050..5da5c1e5d 100644 --- a/swad_place.c +++ b/swad_place.c @@ -25,9 +25,7 @@ /********************************** Headers **********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For NULL -#include // For asprintf #include // For calloc #include // For string functions diff --git a/swad_plugin.c b/swad_plugin.c index 83cb00573..0d0024ac7 100644 --- a/swad_plugin.c +++ b/swad_plugin.c @@ -28,10 +28,9 @@ TODO: Check if web service is called from an authorized IP. /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For NULL #include // For boolean type -#include // For asprintf, fprintf +#include // For fprintf #include // For calloc, free #include diff --git a/swad_preference.c b/swad_preference.c index c67d34113..80b6318df 100644 --- a/swad_preference.c +++ b/swad_preference.c @@ -25,10 +25,9 @@ /********************************** Headers **********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For NULL #include // For boolean type -#include // For asprintf, fprintf, etc. +#include // For fprintf, etc. #include #include "swad_box.h" diff --git a/swad_profile.c b/swad_profile.c index 9d9346478..f1137f9a0 100644 --- a/swad_profile.c +++ b/swad_profile.c @@ -25,9 +25,7 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For NULL -#include // For asprintf #include // For string functions #include "swad_box.h" diff --git a/swad_record.c b/swad_record.c index 122072e94..fc642f2c0 100644 --- a/swad_record.c +++ b/swad_record.c @@ -25,10 +25,8 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For PATH_MAX #include // For NULL -#include // For asprintf #include // For calloc #include diff --git a/swad_search.c b/swad_search.c index 52bf0bb55..79272ed2e 100644 --- a/swad_search.c +++ b/swad_search.c @@ -25,8 +25,7 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf -#include // For fprintf, asprintf... +#include // For fprintf... #include // For string functions... #include "swad_box.h" diff --git a/swad_test_import.c b/swad_test_import.c index 4356db42e..046c20494 100644 --- a/swad_test_import.c +++ b/swad_test_import.c @@ -25,8 +25,6 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf -#include // For asprintf #include // For exit, system, malloc, free, etc #include // For string functions #include // For mkdir diff --git a/swad_text.c b/swad_text.c index 88dde8fc7..95dc3e6af 100644 --- a/swad_text.c +++ b/swad_text.c @@ -19476,7 +19476,7 @@ const char *Txt_MENU_TITLE[Tab_NUM_TABS][Act_MAX_OPTIONS_IN_MENU_PER_TAB] = "Cartão" #endif , - // 6: ActEdiPrf + // 6: ActReqEdiPrf #if L==1 // ca "Configuració" #elif L==2 // de @@ -21343,7 +21343,7 @@ const char *Txt_MENU_SUBTITLE[Tab_NUM_TABS][Act_MAX_OPTIONS_IN_MENU_PER_TAB] = "Cartão" #endif , - // 6: ActEdiPrf + // 6: ActReqEdiPrf #if L==1 // ca "Les meves preferències (idioma, colors, notificacions …)" #elif L==2 // de diff --git a/swad_theme.c b/swad_theme.c index ff19447d5..08c13c9c3 100644 --- a/swad_theme.c +++ b/swad_theme.c @@ -25,8 +25,7 @@ /********************************** Headers **********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf -#include // For fprintf, asprintf, etc. +#include // For fprintf, etc. #include #include "swad_box.h" diff --git a/swad_user.c b/swad_user.c index 2a293dc11..177e4f34b 100644 --- a/swad_user.c +++ b/swad_user.c @@ -25,12 +25,10 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For isalnum, isdigit, etc. #include // For maximum values #include // For PATH_MAX #include // For NULL -#include // For asprintf #include // For exit, system, malloc, free, rand, etc. #include // For string functions #include // For the macro WEXITSTATUS