diff --git a/swad_API.c b/swad_API.c index 841947cb..9bd2bcd6 100644 --- a/swad_API.c +++ b/swad_API.c @@ -3248,7 +3248,7 @@ int swad__sendMessage (struct soap *soap, Usr_DONT_GET_ROLE_IN_CURRENT_CRS)) { /* This received message must be notified by email? */ - NotifyByEmail = (!Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod) && + NotifyByEmail = (Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod) == Usr_OTHER && (Gbl.Usrs.Other.UsrDat.NtfEvents.SendEmail & (1 << Ntf_EVENT_MESSAGE))); /* Send message to this user */ diff --git a/swad_ID.c b/swad_ID.c index ce41fa19..a59b9602 100644 --- a/swad_ID.c +++ b/swad_ID.c @@ -75,13 +75,13 @@ static bool ID_CheckIfUsrIDIsValidUsingMinDigits (const char *UsrID,unsigned Min static void ID_PutLinkToConfirmID (struct Usr_Data *UsrDat,unsigned NumID, const char *Anchor); -static void ID_ShowFormChangeUsrID (bool ItsMe,bool IShouldFillInID); +static void ID_ShowFormChangeUsrID (Usr_MeOrOther_t MeOrOther,bool IShouldFillInID); static void ID_PutParsRemoveMyID (void *ID); static void ID_PutParsRemoveOtherID (void *ID); -static void ID_RemoveUsrID (const struct Usr_Data *UsrDat,bool ItsMe); -static void ID_NewUsrID (const struct Usr_Data *UsrDat,bool ItsMe); +static void ID_RemoveUsrID (const struct Usr_Data *UsrDat,Usr_MeOrOther_t MeOrOther); +static void ID_ChangeUsrID (const struct Usr_Data *UsrDat,Usr_MeOrOther_t MeOrOther); /*****************************************************************************/ /********************** Get list of IDs of a user ****************************/ @@ -346,7 +346,8 @@ void ID_WriteUsrIDs (struct Usr_Data *UsrDat,const char *Anchor) bool ID_ICanSeeOtherUsrIDs (const struct Usr_Data *UsrDat) { - if (Usr_ItsMe (UsrDat->UsrCod)) + /***** Fast check: It's me? *****/ + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) return true; /***** Check if I have permission to see another user's IDs *****/ @@ -457,7 +458,7 @@ void ID_ShowFormChangeMyID (bool IShouldFillInID) Hlp_PROFILE_Account,Box_NOT_CLOSABLE); /***** Show form to change ID *****/ - ID_ShowFormChangeUsrID (true, // ItsMe + ID_ShowFormChangeUsrID (Usr_ME, IShouldFillInID); /***** End box *****/ @@ -487,7 +488,7 @@ void ID_ShowFormChangeOtherUsrID (void) Hlp_PROFILE_Account,Box_NOT_CLOSABLE); /***** Show form to change ID *****/ - ID_ShowFormChangeUsrID (false, // ItsMe + ID_ShowFormChangeUsrID (Usr_OTHER, false); // IShouldFillInID /***** End box *****/ @@ -501,7 +502,7 @@ void ID_ShowFormChangeOtherUsrID (void) /*********************** Show form to change my user's ID ********************/ /*****************************************************************************/ -static void ID_ShowFormChangeUsrID (bool ItsMe,bool IShouldFillInID) +static void ID_ShowFormChangeUsrID (Usr_MeOrOther_t MeOrOther,bool IShouldFillInID) { extern const char *Hlp_PROFILE_Account; extern const char *Txt_Please_fill_in_your_ID; @@ -516,22 +517,41 @@ static void ID_ShowFormChangeUsrID (bool ItsMe,bool IShouldFillInID) static const struct { Act_Action_t Remove; - Act_Action_t New; + Act_Action_t Change; } NextAction[Rol_NUM_ROLES] = { - [Rol_UNK ] = {ActRemID_Oth,ActNewID_Oth}, - [Rol_GST ] = {ActRemID_Oth,ActNewID_Oth}, - [Rol_USR ] = {ActRemID_Oth,ActNewID_Oth}, - [Rol_STD ] = {ActRemID_Std,ActNewID_Std}, - [Rol_NET ] = {ActRemID_Tch,ActNewID_Tch}, - [Rol_TCH ] = {ActRemID_Tch,ActNewID_Tch}, - [Rol_DEG_ADM] = {ActRemID_Oth,ActNewID_Oth}, - [Rol_CTR_ADM] = {ActRemID_Oth,ActNewID_Oth}, - [Rol_INS_ADM] = {ActRemID_Oth,ActNewID_Oth}, - [Rol_SYS_ADM] = {ActRemID_Oth,ActNewID_Oth}, + [Rol_UNK ] = {ActRemID_Oth,ActChgID_Oth}, + [Rol_GST ] = {ActRemID_Oth,ActChgID_Oth}, + [Rol_USR ] = {ActRemID_Oth,ActChgID_Oth}, + [Rol_STD ] = {ActRemID_Std,ActChgID_Std}, + [Rol_NET ] = {ActRemID_Tch,ActChgID_Tch}, + [Rol_TCH ] = {ActRemID_Tch,ActChgID_Tch}, + [Rol_DEG_ADM] = {ActRemID_Oth,ActChgID_Oth}, + [Rol_CTR_ADM] = {ActRemID_Oth,ActChgID_Oth}, + [Rol_INS_ADM] = {ActRemID_Oth,ActChgID_Oth}, + [Rol_SYS_ADM] = {ActRemID_Oth,ActChgID_Oth}, + }; + static const struct Usr_Data *UsrDat[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = &Gbl.Usrs.Me.UsrDat, + [Usr_OTHER] = &Gbl.Usrs.Other.UsrDat + }; + static void (*FuncParsRemove[Usr_NUM_ME_OR_OTHER]) (void *ID) = + { + [Usr_ME ] = ID_PutParsRemoveMyID, + [Usr_OTHER] = ID_PutParsRemoveOtherID + }; + struct + { + Act_Action_t Remove; + Act_Action_t Change; + } ActID[Rol_NUM_ROLES] = + { + [Usr_ME ] = {.Remove = ActRemMyID, + .Change = ActChgMyID}, + [Usr_OTHER] = {.Remove = NextAction[Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs].Remove, + .Change = NextAction[Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs].Change} }; - const struct Usr_Data *UsrDat = (ItsMe ? &Gbl.Usrs.Me.UsrDat : - &Gbl.Usrs.Other.UsrDat); /***** Show possible alerts *****/ Ale_ShowAlerts (ID_ID_SECTION_ID); @@ -545,7 +565,7 @@ static void ID_ShowFormChangeUsrID (bool ItsMe,bool IShouldFillInID) /***** List existing user's IDs *****/ for (NumID = 0; - NumID < UsrDat->IDs.Num; + NumID < UsrDat[MeOrOther]->IDs.Num; NumID++) { if (NumID == 0) @@ -561,46 +581,41 @@ static void ID_ShowFormChangeUsrID (bool ItsMe,bool IShouldFillInID) else // NumID >= 1 HTM_BR (); - if (UsrDat->IDs.Num > 1) // I have two or more IDs + if (UsrDat[MeOrOther]->IDs.Num > 1) // I have two or more IDs { - if (ItsMe && UsrDat->IDs.List[NumID].Confirmed) // I can not remove my confirmed IDs + if (MeOrOther == Usr_ME && + UsrDat[MeOrOther]->IDs.List[NumID].Confirmed) // I can not remove my confirmed IDs /* Put disabled icon to remove user's ID */ Ico_PutIconRemovalNotAllowed (); - else // I can remove - { + else // I can remove /* Form to remove user's ID */ - if (ItsMe) - Ico_PutContextualIconToRemove (ActRemMyID,ID_ID_SECTION_ID, - ID_PutParsRemoveMyID,UsrDat->IDs.List[NumID].ID); - else - Ico_PutContextualIconToRemove (NextAction[UsrDat->Roles.InCurrentCrs].Remove,ID_ID_SECTION_ID, - ID_PutParsRemoveOtherID,UsrDat->IDs.List[NumID].ID); - } + Ico_PutContextualIconToRemove (ActID[MeOrOther].Remove,ID_ID_SECTION_ID, + FuncParsRemove[MeOrOther],UsrDat[MeOrOther]->IDs.List[NumID].ID); } /* User's ID */ - if (asprintf (&Title,UsrDat->IDs.List[NumID].Confirmed ? Txt_ID_X_confirmed : - Txt_ID_X_not_confirmed, - UsrDat->IDs.List[NumID].ID) < 0) + if (asprintf (&Title,UsrDat[MeOrOther]->IDs.List[NumID].Confirmed ? Txt_ID_X_confirmed : + Txt_ID_X_not_confirmed, + UsrDat[MeOrOther]->IDs.List[NumID].ID) < 0) Err_NotEnoughMemoryExit (); HTM_SPAN_Begin ("class=\"%s\" title=\"%s\"", - UsrDat->IDs.List[NumID].Confirmed ? "USR_ID_C" : - "USR_ID_NC", + UsrDat[MeOrOther]->IDs.List[NumID].Confirmed ? "USR_ID_C" : + "USR_ID_NC", Title); free (Title); - HTM_Txt (UsrDat->IDs.List[NumID].ID); - HTM_Txt (UsrDat->IDs.List[NumID].Confirmed ? "✓" : + HTM_Txt (UsrDat[MeOrOther]->IDs.List[NumID].ID); + HTM_Txt (UsrDat[MeOrOther]->IDs.List[NumID].Confirmed ? "✓" : ""); HTM_SPAN_End (); - if (NumID == UsrDat->IDs.Num - 1) + if (NumID == UsrDat[MeOrOther]->IDs.Num - 1) { HTM_TD_End (); HTM_TR_End (); } } - if (UsrDat->IDs.Num < ID_MAX_IDS_PER_USER) + if (UsrDat[MeOrOther]->IDs.Num < ID_MAX_IDS_PER_USER) { /***** Write help text *****/ HTM_TR_Begin (NULL); @@ -617,22 +632,18 @@ static void ID_ShowFormChangeUsrID (bool ItsMe,bool IShouldFillInID) /* Label */ Frm_LabelColumn ("REC_C1_BOT RT","NewID", - UsrDat->IDs.Num ? Txt_Another_ID : // A new user's ID - Txt_ID); // The first user's ID + UsrDat[MeOrOther]->IDs.Num ? Txt_Another_ID : // A new user's ID + Txt_ID); // The first user's ID /* Data */ HTM_TD_Begin ("class=\"REC_C2_BOT LT DAT_%s\"", The_GetSuffix ()); - if (ItsMe) - Frm_BeginFormAnchor (ActChgMyID,ID_ID_SECTION_ID); - else - { - Frm_BeginFormAnchor (NextAction[UsrDat->Roles.InCurrentCrs].New,ID_ID_SECTION_ID); - Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod); - } + Frm_BeginFormAnchor (ActID[MeOrOther].Change,ID_ID_SECTION_ID); + if (MeOrOther == Usr_OTHER) + Usr_PutParUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod); HTM_INPUT_TEXT ("NewID",ID_MAX_BYTES_USR_ID, - UsrDat->IDs.Num ? UsrDat->IDs.List[UsrDat->IDs.Num - 1].ID : - "", // Show the most recent ID + UsrDat[MeOrOther]->IDs.Num ? UsrDat[MeOrOther]->IDs.List[UsrDat[MeOrOther]->IDs.Num - 1].ID : + "", // Show the most recent ID HTM_DONT_SUBMIT_ON_CHANGE, "id=\"NewID\" class=\"INPUT_%s\" size=\"18\"", The_GetSuffix ()); @@ -712,7 +723,7 @@ void ID_RemoveOtherUsrID (void) /***************************** Remove user's ID ******************************/ /*****************************************************************************/ -static void ID_RemoveUsrID (const struct Usr_Data *UsrDat,bool ItsMe) +static void ID_RemoveUsrID (const struct Usr_Data *UsrDat,Usr_MeOrOther_t MeOrOther) { extern const char *Txt_ID_X_removed; extern const char *Txt_You_can_not_delete_this_ID; @@ -729,11 +740,18 @@ static void ID_RemoveUsrID (const struct Usr_Data *UsrDat,bool ItsMe) if (UsrDat->IDs.Num < 2) // One unique ID ICanRemove = false; - else if (ItsMe) - // I can remove my ID only if it is not confirmed - ICanRemove = !ID_DB_CheckIfConfirmed (UsrDat->UsrCod,UsrID); else - ICanRemove = true; + switch (MeOrOther) + { + case Usr_ME: + // I can remove my ID only if it is not confirmed + ICanRemove = !ID_DB_CheckIfConfirmed (UsrDat->UsrCod,UsrID); + break; + case Usr_OTHER: + default: + ICanRemove = true; + break; + } if (ICanRemove) { @@ -760,7 +778,7 @@ static void ID_RemoveUsrID (const struct Usr_Data *UsrDat,bool ItsMe) void ID_NewMyUsrID (void) { /***** New user's ID *****/ - ID_NewUsrID (&Gbl.Usrs.Me.UsrDat, + ID_ChangeUsrID (&Gbl.Usrs.Me.UsrDat, true); // It's me /***** Update list of IDs *****/ @@ -771,19 +789,19 @@ void ID_NewMyUsrID (void) } /*****************************************************************************/ -/********************* New user's ID for another user ************************/ +/************************* Change another user's ID **************************/ /*****************************************************************************/ -void ID_NewOtherUsrID (void) +void ID_ChangeOtherUsrID (void) { /***** Get other user's code from form and get user's data *****/ if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ()) { if (Usr_ICanEditOtherUsr (&Gbl.Usrs.Other.UsrDat)) { - /***** New user's ID *****/ - ID_NewUsrID (&Gbl.Usrs.Other.UsrDat, - Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)); + /***** Change user's ID *****/ + ID_ChangeUsrID (&Gbl.Usrs.Other.UsrDat, + Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)); /***** Update list of IDs *****/ ID_GetListIDsFromUsrCod (&Gbl.Usrs.Other.UsrDat); @@ -799,10 +817,10 @@ void ID_NewOtherUsrID (void) } /*****************************************************************************/ -/***************************** New user's ID *********************************/ +/***************************** Change user's ID ******************************/ /*****************************************************************************/ -static void ID_NewUsrID (const struct Usr_Data *UsrDat,bool ItsMe) +static void ID_ChangeUsrID (const struct Usr_Data *UsrDat,Usr_MeOrOther_t MeOrOther) { extern const char *Txt_The_ID_X_matches_one_of_the_existing; extern const char *Txt_The_ID_X_has_been_confirmed; @@ -836,7 +854,7 @@ static void ID_NewUsrID (const struct Usr_Data *UsrDat,bool ItsMe) if (AlreadyExists) // This new ID was already associated to this user { - if (ItsMe || UsrDat->IDs.List[NumIDFound].Confirmed) + if (MeOrOther == Usr_ME || UsrDat->IDs.List[NumIDFound].Confirmed) Ale_CreateAlert (Ale_WARNING,ID_ID_SECTION_ID, Txt_The_ID_X_matches_one_of_the_existing, NewID); @@ -859,7 +877,7 @@ static void ID_NewUsrID (const struct Usr_Data *UsrDat,bool ItsMe) /***** Save this new ID *****/ // It's me ==> ID not confirmed // Not me ==> ID confirmed - ID_DB_InsertANewUsrID (UsrDat->UsrCod,NewID,!ItsMe); + ID_DB_InsertANewUsrID (UsrDat->UsrCod,NewID,MeOrOther == Usr_OTHER); Ale_CreateAlert (Ale_SUCCESS,ID_ID_SECTION_ID, Txt_The_ID_X_has_been_registered_successfully, @@ -895,7 +913,7 @@ void ID_ConfirmOtherUsrID (void) /***** Get other user's code from form and get user's data *****/ ICanConfirm = false; if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ()) - if (!Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)) // Not me + if (Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod) == Usr_OTHER) // Not me { /* If user is a student in current course, check if he/she has accepted */ diff --git a/swad_ID.h b/swad_ID.h index 0fabf03b..1d2adaa8 100644 --- a/swad_ID.h +++ b/swad_ID.h @@ -78,7 +78,7 @@ void ID_ShowFormChangeOtherUsrID (void); void ID_RemoveMyUsrID (void); void ID_RemoveOtherUsrID (void); void ID_NewMyUsrID (void); -void ID_NewOtherUsrID (void); +void ID_ChangeOtherUsrID (void); void ID_ConfirmOtherUsrID (void); diff --git a/swad_account.c b/swad_account.c index 3e9f088f..bdc6d6b1 100644 --- a/swad_account.c +++ b/swad_account.c @@ -75,6 +75,7 @@ #include "swad_setting_database.h" #include "swad_test_print.h" #include "swad_timeline.h" +#include "swad_user.h" #include "swad_user_database.h" /*****************************************************************************/ @@ -98,7 +99,7 @@ static void Acc_CreateNewEncryptedUsrCod (struct Usr_Data *UsrDat); static void Acc_PutParsToRemoveMyAccount (void *EncryptedUsrCod); -static void Acc_AskIfRemoveUsrAccount (bool ItsMe); +static void Acc_AskIfRemoveUsrAccount (Usr_MeOrOther_t MeOrOther); static void Acc_AskIfRemoveOtherUsrAccount (void); static void Acc_RemoveUsrBriefcase (struct Usr_Data *UsrDat); @@ -832,12 +833,12 @@ void Acc_GetUsrCodAndRemUsrGbl (void) void Acc_ReqRemAccountOrRemAccount (Acc_ReqOrRemUsr_t RequestOrRemove) { - bool ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); + Usr_MeOrOther_t MeOrOther = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); switch (RequestOrRemove) { case Acc_REQUEST_REMOVE_USR: // Ask if eliminate completely the user from the platform - Acc_AskIfRemoveUsrAccount (ItsMe); + Acc_AskIfRemoveUsrAccount (MeOrOther); break; case Acc_REMOVE_USR: // Eliminate completely the user from the platform if (Pwd_GetConfirmationOnDangerousAction ()) @@ -848,7 +849,7 @@ void Acc_ReqRemAccountOrRemAccount (Acc_ReqOrRemUsr_t RequestOrRemove) Msg_DB_MoveUnusedMsgsContentToDeleted (); } else - Acc_AskIfRemoveUsrAccount (ItsMe); + Acc_AskIfRemoveUsrAccount (MeOrOther); break; } } @@ -859,27 +860,33 @@ void Acc_ReqRemAccountOrRemAccount (Acc_ReqOrRemUsr_t RequestOrRemove) bool Acc_CheckIfICanEliminateAccount (long UsrCod) { - bool ItsMe = Usr_ItsMe (UsrCod); + Usr_MeOrOther_t MeOrOther = Usr_ItsMe (UsrCod); // A user logged as superuser can eliminate any user except her/him // Other users only can eliminate themselves - return (( ItsMe && // It's me - (Gbl.Usrs.Me.Role.Available & (1 << Rol_SYS_ADM)) == 0) // I can not be system admin - || - (!ItsMe && // It's not me - Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)); // I am logged as system admin + switch (MeOrOther) + { + case Usr_ME: + return (Gbl.Usrs.Me.Role.Available & (1 << Rol_SYS_ADM)) == 0; // I can not be system admin + case Usr_OTHER: + default: + return Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM; // I am logged as system admin + } } /*****************************************************************************/ /*********** Ask if really wanted to eliminate completely a user *************/ /*****************************************************************************/ -static void Acc_AskIfRemoveUsrAccount (bool ItsMe) +static void Acc_AskIfRemoveUsrAccount (Usr_MeOrOther_t MeOrOther) { - if (ItsMe) - Acc_AskIfRemoveMyAccount (); - else - Acc_AskIfRemoveOtherUsrAccount (); + static void (*FuncAskIfRemoveUsrAccount[Usr_NUM_ME_OR_OTHER]) (void) = + { + [Usr_ME ] = Acc_AskIfRemoveMyAccount, + [Usr_OTHER] = Acc_AskIfRemoveOtherUsrAccount + }; + + FuncAskIfRemoveUsrAccount[MeOrOther] (); } void Acc_AskIfRemoveMyAccount (void) @@ -1128,13 +1135,19 @@ void Acc_PutIconToChangeUsrAccount (struct Usr_Data *UsrDat) }; /***** Link for changing the account *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) - Lay_PutContextualLinkOnlyIcon (ActFrmMyAcc,NULL, - NULL,NULL, - "at.svg",Ico_BLACK); - else // Not me - if (Usr_ICanEditOtherUsr (UsrDat)) - Lay_PutContextualLinkOnlyIcon (NextAction[UsrDat->Roles.InCurrentCrs],NULL, - Rec_PutParUsrCodEncrypted,NULL, - "at.svg",Ico_BLACK); + switch (Usr_ItsMe (UsrDat->UsrCod)) + { + case Usr_ME: + Lay_PutContextualLinkOnlyIcon (ActFrmMyAcc,NULL, + NULL,NULL, + "at.svg",Ico_BLACK); + break; + case Usr_OTHER: + default: + if (Usr_ICanEditOtherUsr (UsrDat)) + Lay_PutContextualLinkOnlyIcon (NextAction[UsrDat->Roles.InCurrentCrs],NULL, + Rec_PutParUsrCodEncrypted,NULL, + "at.svg",Ico_BLACK); + break; + } } diff --git a/swad_action_list.c b/swad_action_list.c index 76679189..ee3a4566 100644 --- a/swad_action_list.c +++ b/swad_action_list.c @@ -1463,9 +1463,9 @@ const struct Act_Actions ActLst_Actions[ActLst_NUM_ACTIONS] = [ActDetStdPho ] = {1436,-1,TabUnk,ActLstStd ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_DATA,Act_BRW_1ST_TAB,NULL ,Pho_RecOtherUsrPhotoDetFaces ,NULL}, [ActDetTchPho ] = {1437,-1,TabUnk,ActLstTch ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_DATA,Act_BRW_1ST_TAB,NULL ,Pho_RecOtherUsrPhotoDetFaces ,NULL}, - [ActUpdOthPho ] = {1438,-1,TabUnk,ActLstOth ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,Pho_UpdateUsrPhoto1 ,Pho_UpdateUsrPhoto2 ,NULL}, - [ActUpdStdPho ] = {1439,-1,TabUnk,ActLstStd ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,Pho_UpdateUsrPhoto1 ,Pho_UpdateUsrPhoto2 ,NULL}, - [ActUpdTchPho ] = {1440,-1,TabUnk,ActLstTch ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,Pho_UpdateUsrPhoto1 ,Pho_UpdateUsrPhoto2 ,NULL}, + [ActChgOthPho ] = {1438,-1,TabUnk,ActLstOth ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,Pho_ChangeUsrPhoto1 ,Pho_ChangeUsrPhoto2 ,NULL}, + [ActChgStdPho ] = {1439,-1,TabUnk,ActLstStd ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,Pho_ChangeUsrPhoto1 ,Pho_ChangeUsrPhoto2 ,NULL}, + [ActChgTchPho ] = {1440,-1,TabUnk,ActLstTch ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,Pho_ChangeUsrPhoto1 ,Pho_ChangeUsrPhoto2 ,NULL}, [ActReqRemOthPho ] = {1574,-1,TabUnk,ActLstOth ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Pho_ReqRemUsrPhoto ,NULL}, [ActReqRemStdPho ] = {1575,-1,TabUnk,ActLstStd ,0x3E0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Pho_ReqRemUsrPhoto ,NULL}, @@ -1515,19 +1515,19 @@ const struct Act_Actions ActLst_Actions[ActLst_NUM_ACTIONS] = [ActFrmAccStd ] = {1736,-1,TabUnk,ActLstStd ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Acc_ShowFormChgOtherUsrAccount ,NULL}, [ActFrmAccTch ] = {1737,-1,TabUnk,ActLstTch ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Acc_ShowFormChgOtherUsrAccount ,NULL}, - [ActRemOldNicOth ] = {1738,-1,TabUnk,ActLstOth ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Nck_RemoveOtherUsrNick ,NULL}, - [ActRemOldNicStd ] = {1739,-1,TabUnk,ActLstStd ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Nck_RemoveOtherUsrNick ,NULL}, - [ActRemOldNicTch ] = {1740,-1,TabUnk,ActLstTch ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Nck_RemoveOtherUsrNick ,NULL}, - [ActChgNicOth ] = {1741,-1,TabUnk,ActLstOth ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Nck_UpdateOtherUsrNick ,NULL}, - [ActChgNicStd ] = {1742,-1,TabUnk,ActLstStd ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Nck_UpdateOtherUsrNick ,NULL}, - [ActChgNicTch ] = {1743,-1,TabUnk,ActLstTch ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Nck_UpdateOtherUsrNick ,NULL}, + [ActRemNicOth ] = {1738,-1,TabUnk,ActLstOth ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Nck_RemoveOtherUsrNick ,NULL}, + [ActRemNicStd ] = {1739,-1,TabUnk,ActLstStd ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Nck_RemoveOtherUsrNick ,NULL}, + [ActRemNicTch ] = {1740,-1,TabUnk,ActLstTch ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Nck_RemoveOtherUsrNick ,NULL}, + [ActChgNicOth ] = {1741,-1,TabUnk,ActLstOth ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Nck_ChangeOtherUsrNick ,NULL}, + [ActChgNicStd ] = {1742,-1,TabUnk,ActLstStd ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Nck_ChangeOtherUsrNick ,NULL}, + [ActChgNicTch ] = {1743,-1,TabUnk,ActLstTch ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Nck_ChangeOtherUsrNick ,NULL}, [ActRemID_Oth ] = {1450,-1,TabUnk,ActLstOth ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,ID_RemoveOtherUsrID ,NULL}, [ActRemID_Std ] = {1451,-1,TabUnk,ActLstStd ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,ID_RemoveOtherUsrID ,NULL}, [ActRemID_Tch ] = {1452,-1,TabUnk,ActLstTch ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,ID_RemoveOtherUsrID ,NULL}, - [ActNewID_Oth ] = {1453,-1,TabUnk,ActLstOth ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,ID_NewOtherUsrID ,NULL}, - [ActNewID_Std ] = {1454,-1,TabUnk,ActLstStd ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,ID_NewOtherUsrID ,NULL}, - [ActNewID_Tch ] = {1455,-1,TabUnk,ActLstTch ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,ID_NewOtherUsrID ,NULL}, + [ActChgID_Oth ] = {1453,-1,TabUnk,ActLstOth ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,ID_ChangeOtherUsrID ,NULL}, + [ActChgID_Std ] = {1454,-1,TabUnk,ActLstStd ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,ID_ChangeOtherUsrID ,NULL}, + [ActChgID_Tch ] = {1455,-1,TabUnk,ActLstTch ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,ID_ChangeOtherUsrID ,NULL}, [ActChgPwdOth ] = {1467,-1,TabUnk,ActLstOth ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,Pwd_UpdateOtherUsrPwd ,Acc_ShowFormChgOtherUsrAccount ,NULL}, [ActChgPwdStd ] = {1468,-1,TabUnk,ActLstStd ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,Pwd_UpdateOtherUsrPwd ,Acc_ShowFormChgOtherUsrAccount ,NULL}, @@ -1536,9 +1536,9 @@ const struct Act_Actions ActLst_Actions[ActLst_NUM_ACTIONS] = [ActRemMaiOth ] = {1478,-1,TabUnk,ActLstOth ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Mai_RemoveOtherUsrEmail ,NULL}, [ActRemMaiStd ] = {1479,-1,TabUnk,ActLstStd ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Mai_RemoveOtherUsrEmail ,NULL}, [ActRemMaiTch ] = {1480,-1,TabUnk,ActLstTch ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Mai_RemoveOtherUsrEmail ,NULL}, - [ActNewMaiOth ] = {1481,-1,TabUnk,ActLstOth ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Mai_NewOtherUsrEmail ,NULL}, - [ActNewMaiStd ] = {1482,-1,TabUnk,ActLstStd ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Mai_NewOtherUsrEmail ,NULL}, - [ActNewMaiTch ] = {1483,-1,TabUnk,ActLstTch ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Mai_NewOtherUsrEmail ,NULL}, + [ActChgMaiOth ] = {1481,-1,TabUnk,ActLstOth ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Mai_ChangeOtherUsrEmail ,NULL}, + [ActChgMaiStd ] = {1482,-1,TabUnk,ActLstStd ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Mai_ChangeOtherUsrEmail ,NULL}, + [ActChgMaiTch ] = {1483,-1,TabUnk,ActLstTch ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Mai_ChangeOtherUsrEmail ,NULL}, [ActRemStdCrs ] = {1462,-1,TabUnk,ActLstStd ,0x3F8,0x3C0, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Enr_RemUsrFromCrs1 ,Enr_RemUsrFromCrs2 ,NULL}, [ActRemNETCrs ] = {1647,-1,TabUnk,ActLstTch ,0x3F0,0x3C0, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Enr_RemUsrFromCrs1 ,Enr_RemUsrFromCrs2 ,NULL}, @@ -3329,9 +3329,9 @@ Act_Action_t ActLst_FromActCodToAction[1 + ActLst_MAX_ACTION_COD] = // Do not re ActDetOthPho, // #1435 ActDetStdPho, // #1436 ActDetTchPho, // #1437 - ActUpdOthPho, // #1438 - ActUpdStdPho, // #1439 - ActUpdTchPho, // #1440 + ActChgOthPho, // #1438 + ActChgStdPho, // #1439 + ActChgTchPho, // #1440 ActRemOthPho, // #1441 ActRemStdPho, // #1442 ActRemTchPho, // #1443 @@ -3344,9 +3344,9 @@ Act_Action_t ActLst_FromActCodToAction[1 + ActLst_MAX_ACTION_COD] = // Do not re ActRemID_Oth, // #1450 ActRemID_Std, // #1451 ActRemID_Tch, // #1452 - ActNewID_Oth, // #1453 - ActNewID_Std, // #1454 - ActNewID_Tch, // #1455 + ActChgID_Oth, // #1453 + ActChgID_Std, // #1454 + ActChgID_Tch, // #1455 ActReqAccEnrStd, // #1456 ActReqAccEnrTch, // #1457 ActAccEnrStd, // #1458 @@ -3372,9 +3372,9 @@ Act_Action_t ActLst_FromActCodToAction[1 + ActLst_MAX_ACTION_COD] = // Do not re ActRemMaiOth, // #1478 ActRemMaiStd, // #1479 ActRemMaiTch, // #1480 - ActNewMaiOth, // #1481 - ActNewMaiStd, // #1482 - ActNewMaiTch, // #1483 + ActChgMaiOth, // #1481 + ActChgMaiStd, // #1482 + ActChgMaiTch, // #1483 ActChg1stDay, // #1484 -1, // #1485 (obsolete action) ActChgCrsTT1stDay, // #1486 @@ -3629,9 +3629,9 @@ Act_Action_t ActLst_FromActCodToAction[1 + ActLst_MAX_ACTION_COD] = // Do not re ActFrmAccOth, // #1735 ActFrmAccStd, // #1736 ActFrmAccTch, // #1737 - ActRemOldNicOth, // #1738 - ActRemOldNicStd, // #1739 - ActRemOldNicTch, // #1740 + ActRemNicOth, // #1738 + ActRemNicStd, // #1739 + ActRemNicTch, // #1740 ActChgNicOth, // #1741 ActChgNicStd, // #1742 ActChgNicTch, // #1743 diff --git a/swad_action_list.h b/swad_action_list.h index 50aeae7f..82eb289e 100644 --- a/swad_action_list.h +++ b/swad_action_list.h @@ -1370,15 +1370,16 @@ #define ActDetOthPho (ActRemOldBrf + 94) #define ActDetStdPho (ActRemOldBrf + 95) #define ActDetTchPho (ActRemOldBrf + 96) -#define ActUpdOthPho (ActRemOldBrf + 97) -#define ActUpdStdPho (ActRemOldBrf + 98) -#define ActUpdTchPho (ActRemOldBrf + 99) +#define ActChgOthPho (ActRemOldBrf + 97) +#define ActChgStdPho (ActRemOldBrf + 98) +#define ActChgTchPho (ActRemOldBrf + 99) #define ActReqRemOthPho (ActRemOldBrf + 100) #define ActReqRemStdPho (ActRemOldBrf + 101) #define ActReqRemTchPho (ActRemOldBrf + 102) #define ActRemOthPho (ActRemOldBrf + 103) #define ActRemStdPho (ActRemOldBrf + 104) #define ActRemTchPho (ActRemOldBrf + 105) + #define ActCreOth (ActRemOldBrf + 106) #define ActCreStd (ActRemOldBrf + 107) #define ActCreNET (ActRemOldBrf + 108) @@ -1417,9 +1418,9 @@ #define ActFrmAccStd (ActRemOldBrf + 136) #define ActFrmAccTch (ActRemOldBrf + 137) -#define ActRemOldNicOth (ActRemOldBrf + 138) -#define ActRemOldNicStd (ActRemOldBrf + 139) -#define ActRemOldNicTch (ActRemOldBrf + 140) +#define ActRemNicOth (ActRemOldBrf + 138) +#define ActRemNicStd (ActRemOldBrf + 139) +#define ActRemNicTch (ActRemOldBrf + 140) #define ActChgNicOth (ActRemOldBrf + 141) #define ActChgNicStd (ActRemOldBrf + 142) #define ActChgNicTch (ActRemOldBrf + 143) @@ -1427,18 +1428,20 @@ #define ActRemID_Oth (ActRemOldBrf + 144) #define ActRemID_Std (ActRemOldBrf + 145) #define ActRemID_Tch (ActRemOldBrf + 146) -#define ActNewID_Oth (ActRemOldBrf + 147) -#define ActNewID_Std (ActRemOldBrf + 148) -#define ActNewID_Tch (ActRemOldBrf + 149) +#define ActChgID_Oth (ActRemOldBrf + 147) +#define ActChgID_Std (ActRemOldBrf + 148) +#define ActChgID_Tch (ActRemOldBrf + 149) + #define ActChgPwdOth (ActRemOldBrf + 150) #define ActChgPwdStd (ActRemOldBrf + 151) #define ActChgPwdTch (ActRemOldBrf + 152) + #define ActRemMaiOth (ActRemOldBrf + 153) #define ActRemMaiStd (ActRemOldBrf + 154) #define ActRemMaiTch (ActRemOldBrf + 155) -#define ActNewMaiOth (ActRemOldBrf + 156) -#define ActNewMaiStd (ActRemOldBrf + 157) -#define ActNewMaiTch (ActRemOldBrf + 158) +#define ActChgMaiOth (ActRemOldBrf + 156) +#define ActChgMaiStd (ActRemOldBrf + 157) +#define ActChgMaiTch (ActRemOldBrf + 158) #define ActRemStdCrs (ActRemOldBrf + 159) #define ActRemNETCrs (ActRemOldBrf + 160) diff --git a/swad_admin.c b/swad_admin.c index c22ed5cc..bd4e2931 100644 --- a/swad_admin.c +++ b/swad_admin.c @@ -75,7 +75,7 @@ static void Adm_RegisterAdmin (struct Usr_Data *UsrDat, static void Adm_ReqRemOrRemAdm (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr, HieLvl_Level_t Scope,long Cod, const char *InsCtrDegName); -static void Adm_AskIfRemAdm (bool ItsMe,HieLvl_Level_t Scope, +static void Adm_AskIfRemAdm (Usr_MeOrOther_t MeOrOther,HieLvl_Level_t Scope, const char *InsCtrDegName); static void Adm_EffectivelyRemAdm (struct Usr_Data *UsrDat, HieLvl_Level_t Scope,long Cod, @@ -345,7 +345,7 @@ static void Adm_ReqRemOrRemAdm (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr, const char *InsCtrDegName) { extern const char *Txt_THE_USER_X_is_not_an_administrator_of_Y; - bool ItsMe; + Usr_MeOrOther_t MeOrOther; bool ICanRemove; if (Cod > 0) @@ -354,8 +354,8 @@ static void Adm_ReqRemOrRemAdm (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr, if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ()) { /* Check if it's forbidden to remove an administrator */ - ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); - ICanRemove = (ItsMe || + MeOrOther = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); + ICanRemove = (MeOrOther == Usr_ME || (Scope == HieLvl_DEG && Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM) || (Scope == HieLvl_CTR && Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM) || (Scope == HieLvl_INS && Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)); @@ -367,7 +367,7 @@ static void Adm_ReqRemOrRemAdm (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr, switch (ReqDelOrDelUsr) { case Enr_REQUEST_REMOVE_USR: // Ask if remove administrator from current institution - Adm_AskIfRemAdm (ItsMe,Scope,InsCtrDegName); + Adm_AskIfRemAdm (MeOrOther,Scope,InsCtrDegName); break; case Enr_REMOVE_USR: // Remove administrator from current institution Adm_EffectivelyRemAdm (&Gbl.Usrs.Other.UsrDat,Scope, @@ -391,14 +391,14 @@ static void Adm_ReqRemOrRemAdm (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr, /** Ask if really wanted to remove an administrator from current institution */ /*****************************************************************************/ -static void Adm_AskIfRemAdm (bool ItsMe,HieLvl_Level_t Scope, +static void Adm_AskIfRemAdm (Usr_MeOrOther_t MeOrOther,HieLvl_Level_t Scope, const char *InsCtrDegName) { extern const char *Txt_Do_you_really_want_to_be_removed_as_an_administrator_of_X; extern const char *Txt_Do_you_really_want_to_remove_the_following_user_as_an_administrator_of_X; extern const char *Txt_Remove_me_as_an_administrator; extern const char *Txt_Remove_USER_as_an_administrator; - static const Act_Action_t Enr_ActRemAdm[HieLvl_NUM_LEVELS] = + static const Act_Action_t ActRemAdm[HieLvl_NUM_LEVELS] = { [HieLvl_UNK] = ActUnk, [HieLvl_SYS] = ActUnk, @@ -408,24 +408,30 @@ static void Adm_AskIfRemAdm (bool ItsMe,HieLvl_Level_t Scope, [HieLvl_DEG] = ActRemAdmDeg, [HieLvl_CRS] = ActUnk, }; + const char *Question[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = Txt_Do_you_really_want_to_be_removed_as_an_administrator_of_X, + [Usr_OTHER] = Txt_Do_you_really_want_to_remove_the_following_user_as_an_administrator_of_X, + }; + const char *TxtButton[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = Txt_Remove_me_as_an_administrator, + [Usr_OTHER] = Txt_Remove_USER_as_an_administrator, + }; if (Usr_DB_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod)) { /***** Show question and button to remove user as administrator *****/ /* Begin alert */ - Ale_ShowAlertAndButton1 (Ale_QUESTION,ItsMe ? Txt_Do_you_really_want_to_be_removed_as_an_administrator_of_X : - Txt_Do_you_really_want_to_remove_the_following_user_as_an_administrator_of_X, - InsCtrDegName); + Ale_ShowAlertAndButton1 (Ale_QUESTION,Question[MeOrOther],InsCtrDegName); /* Show user's record */ Rec_ShowSharedRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat); /* End alert */ - Ale_ShowAlertAndButton2 (Enr_ActRemAdm[Scope],NULL,NULL, + Ale_ShowAlertAndButton2 (ActRemAdm[Scope],NULL,NULL, Usr_PutParOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EnUsrCod, - Btn_REMOVE_BUTTON, - ItsMe ? Txt_Remove_me_as_an_administrator : - Txt_Remove_USER_as_an_administrator); + Btn_REMOVE_BUTTON,TxtButton[MeOrOther]); } else Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission (); diff --git a/swad_agenda.c b/swad_agenda.c index 79302675..f2588210 100644 --- a/swad_agenda.c +++ b/swad_agenda.c @@ -377,8 +377,18 @@ void Agd_ShowUsrAgenda (void) extern const char *Txt_Public_agenda_USER; struct Agd_Agenda Agenda; bool Error = true; - bool ItsMe; + Usr_MeOrOther_t MeOrOther; char *Title; + static struct Usr_Data *UsrDat[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = &Gbl.Usrs.Me.UsrDat, + [Usr_OTHER] = &Gbl.Usrs.Other.UsrDat, + }; + static void (*FuncPutIcons[Usr_NUM_ME_OR_OTHER]) (void *EncryptedUsrCod) = + { + [Usr_ME ] = Agd_PutIconsMyPublicAgenda, + [Usr_OTHER] = Agd_PutIconsOtherPublicAgenda, + }; /***** Get user *****/ if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ()) @@ -390,16 +400,11 @@ void Agd_ShowUsrAgenda (void) Agd_ResetAgenda (&Agenda); /***** Begin box *****/ - ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); - if (asprintf (&Title,Txt_Public_agenda_USER, - ItsMe ? Gbl.Usrs.Me.UsrDat.FullName : - Gbl.Usrs.Other.UsrDat.FullName) < 0) + MeOrOther = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); + if (asprintf (&Title,Txt_Public_agenda_USER,UsrDat[MeOrOther]->FullName) < 0) Err_NotEnoughMemoryExit (); Box_BoxBegin ("100%",Title, - ItsMe ? Agd_PutIconsMyPublicAgenda : - Agd_PutIconsOtherPublicAgenda, - ItsMe ? Gbl.Usrs.Me.UsrDat.EnUsrCod : - Gbl.Usrs.Other.UsrDat.EnUsrCod, + FuncPutIcons[MeOrOther],UsrDat[MeOrOther]->EnUsrCod, Hlp_PROFILE_Agenda_public_agenda,Box_NOT_CLOSABLE); free (Title); @@ -428,8 +433,18 @@ void Agd_ShowOtherAgendaAfterLogIn (void) extern const char *Txt_Public_agenda_USER; extern const char *Txt_Switching_to_LANGUAGE[1 + Lan_NUM_LANGUAGES]; struct Agd_Agenda Agenda; - bool ItsMe; + Usr_MeOrOther_t MeOrOther; char *Title; + static struct Usr_Data *UsrDat[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = &Gbl.Usrs.Me.UsrDat, + [Usr_OTHER] = &Gbl.Usrs.Other.UsrDat, + }; + static void (*FuncPutIcons[Usr_NUM_ME_OR_OTHER]) (void *EncryptedUsrCod) = + { + [Usr_ME ] = Agd_PutIconToViewEditMyFullAgenda, + [Usr_OTHER] = Agd_PutIconsOtherPublicAgenda, + }; if (Gbl.Usrs.Me.Logged) { @@ -445,16 +460,11 @@ void Agd_ShowOtherAgendaAfterLogIn (void) Agd_ResetAgenda (&Agenda); /***** Begin box *****/ - ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); - if (asprintf (&Title,Txt_Public_agenda_USER, - ItsMe ? Gbl.Usrs.Me.UsrDat.FullName : - Gbl.Usrs.Other.UsrDat.FullName) < 0) + MeOrOther = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); + if (asprintf (&Title,Txt_Public_agenda_USER,UsrDat[MeOrOther]->FullName) < 0) Err_NotEnoughMemoryExit (); Box_BoxBegin ("100%",Title, - ItsMe ? Agd_PutIconToViewEditMyFullAgenda : - Agd_PutIconsOtherPublicAgenda, - ItsMe ? Gbl.Usrs.Me.UsrDat.EnUsrCod : - Gbl.Usrs.Other.UsrDat.EnUsrCod, + FuncPutIcons[MeOrOther],UsrDat[MeOrOther]->EnUsrCod, Hlp_PROFILE_Agenda_public_agenda,Box_NOT_CLOSABLE); free (Title); diff --git a/swad_attendance.c b/swad_attendance.c index 803c7041..1c770a95 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -1715,7 +1715,7 @@ static void Att_WriteRowUsrToCallTheRoll (unsigned NumUsr, { case Rol_STD: // A student can see only her/his attendance - if (!Usr_ItsMe (UsrDat->UsrCod)) + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_OTHER) Err_ShowErrorAndExit ("Wrong call."); ICanChangeStdAttendance = false; ICanEditStdComment = Event->Open; // Attendance event is open diff --git a/swad_changelog.h b/swad_changelog.h index 2bb33c53..aa259ab2 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -629,10 +629,11 @@ TODO: Emilce Barrera Mesa: Podr TODO: Emilce Barrera Mesa: Mis estudiantes presentan muchas dificultades a la hora de poner la foto porque la plataforma es muy exigente respecto al fondo de la imagen. */ -#define Log_PLATFORM_VERSION "SWAD 22.89.1 (2023-04-04)" +#define Log_PLATFORM_VERSION "SWAD 22.90 (2023-04-04)" #define CSS_FILE "swad22.88.css" #define JS_FILE "swad22.49.js" /* + Version 22.90: Apr 04, 2023 Code refactoring checking user. (338807 lines) Version 22.89.1: Apr 04, 2023 Code refactoring in projects configuration. (338622 lines) Version 22.89: Apr 01, 2023 New module swad_project_config for projects configuration. (338613 lines) Version 22.88: Mar 31, 2023 Code refactoring in resources. (338538 lines) diff --git a/swad_connected.c b/swad_connected.c index aff55428..05019b87 100644 --- a/swad_connected.c +++ b/swad_connected.c @@ -561,28 +561,32 @@ static void Con_WriteRowConnectedUsrOnRightColumn (Rol_Role_t Role) }; const char *ClassTxt; long UsrCod; - bool ItsMe; + Usr_MeOrOther_t MeOrOther; struct Usr_Data *UsrDat; struct Usr_Data OtherUsrDat; /***** Get user's code from list *****/ UsrCod = Gbl.Usrs.Connected.Lst[Gbl.Usrs.Connected.NumUsr].UsrCod; - ItsMe = Usr_ItsMe (UsrCod); + MeOrOther = Usr_ItsMe (UsrCod); - if (ItsMe) - UsrDat = &Gbl.Usrs.Me.UsrDat; - else + switch (MeOrOther) { - /***** Initialize structure with user's data *****/ - OtherUsrDat.UsrCod = UsrCod; - Usr_UsrDataConstructor (&OtherUsrDat); + case Usr_ME: + UsrDat = &Gbl.Usrs.Me.UsrDat; + break; + case Usr_OTHER: + default: + /***** Initialize structure with user's data *****/ + OtherUsrDat.UsrCod = UsrCod; + Usr_UsrDataConstructor (&OtherUsrDat); - /***** Get user's data *****/ - Usr_GetAllUsrDataFromUsrCod (&OtherUsrDat, - Usr_DONT_GET_PREFS, - Usr_DONT_GET_ROLE_IN_CURRENT_CRS); + /***** Get user's data *****/ + Usr_GetAllUsrDataFromUsrCod (&OtherUsrDat, + Usr_DONT_GET_PREFS, + Usr_DONT_GET_ROLE_IN_CURRENT_CRS); - UsrDat = &OtherUsrDat; + UsrDat = &OtherUsrDat; + break; } HTM_TR_Begin (NULL); @@ -623,9 +627,16 @@ static void Con_WriteRowConnectedUsrOnRightColumn (Rol_Role_t Role) HTM_TR_End (); - if (!ItsMe) - /***** Free memory used for user's data *****/ - Usr_UsrDataDestructor (&OtherUsrDat); + switch (MeOrOther) + { + case Usr_ME: + break; + case Usr_OTHER: + default: + /***** Free memory used for user's data *****/ + Usr_UsrDataDestructor (&OtherUsrDat); + break; + } The_ChangeRowColor (); } diff --git a/swad_duplicate.c b/swad_duplicate.c index 747d338c..c5128f68 100644 --- a/swad_duplicate.c +++ b/swad_duplicate.c @@ -73,7 +73,7 @@ void Dup_ReportUsrAsPossibleDuplicate (void) { /* Check if it's allowed to me to report users as possible duplicatedr */ if (Gbl.Usrs.Me.Role.Logged >= Rol_TCH && - !Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)) + Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod) == Usr_OTHER) { /***** Insert possible duplicate into database *****/ Dup_DB_AddUsrToDuplicated (Gbl.Usrs.Other.UsrDat.UsrCod); diff --git a/swad_enrolment.c b/swad_enrolment.c index c01a21be..02f2d259 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -114,16 +114,16 @@ static void Enr_PutActionsRegRemSeveralUsrs (void); static void Enr_ReceiveFormUsrsCrs (Rol_Role_t Role); static void Enr_PutActionModifyOneUsr (bool *OptionChecked, - bool UsrBelongsToCrs,bool ItsMe); + bool UsrBelongsToCrs,Usr_MeOrOther_t MeOrOther); static void Enr_PutActionRegOneDegAdm (bool *OptionChecked); static void Enr_PutActionRegOneCtrAdm (bool *OptionChecked); static void Enr_PutActionRegOneInsAdm (bool *OptionChecked); static void Enr_PutActionRepUsrAsDup (bool *OptionChecked); -static void Enr_PutActionRemUsrFromCrs (bool *OptionChecked,bool ItsMe); -static void Enr_PutActionRemUsrAsDegAdm (bool *OptionChecked,bool ItsMe); -static void Enr_PutActionRemUsrAsCtrAdm (bool *OptionChecked,bool ItsMe); -static void Enr_PutActionRemUsrAsInsAdm (bool *OptionChecked,bool ItsMe); -static void Enr_PutActionRemUsrAcc (bool *OptionChecked,bool ItsMe); +static void Enr_PutActionRemUsrFromCrs (bool *OptionChecked,Usr_MeOrOther_t MeOrOther); +static void Enr_PutActionRemUsrAsDegAdm (bool *OptionChecked,Usr_MeOrOther_t MeOrOther); +static void Enr_PutActionRemUsrAsCtrAdm (bool *OptionChecked,Usr_MeOrOther_t MeOrOther); +static void Enr_PutActionRemUsrAsInsAdm (bool *OptionChecked,Usr_MeOrOther_t MeOrOther); +static void Enr_PutActionRemUsrAcc (bool *OptionChecked,Usr_MeOrOther_t MeOrOther); static void Enr_RegRemOneUsrActionBegin (Enr_RegRemOneUsrAction_t RegRemOneUsrAction, bool *OptionChecked); static void Enr_RegRemOneUsrActionEnd (void); @@ -315,7 +315,7 @@ static void Enr_NotifyAfterEnrolment (const struct Usr_Data *UsrDat, /***** Create new notification ******/ CreateNotif = (UsrDat->NtfEvents.CreateNotif & (1 << NotifyEvent[NewRole])); - NotifyByEmail = CreateNotif && !Usr_ItsMe (UsrDat->UsrCod) && + NotifyByEmail = CreateNotif && Usr_ItsMe (UsrDat->UsrCod) == Usr_OTHER && (UsrDat->NtfEvents.SendEmail & (1 << NotifyEvent[NewRole])); if (CreateNotif) Ntf_DB_StoreNotifyEventToUsr (NotifyEvent[NewRole],UsrDat->UsrCod,-1L, @@ -1306,7 +1306,7 @@ static void Enr_ReceiveFormUsrsCrs (Rol_Role_t Role) /*****************************************************************************/ // Returns true if at least one action can be shown -bool Enr_PutActionsRegRemOneUsr (bool ItsMe) +bool Enr_PutActionsRegRemOneUsr (Usr_MeOrOther_t MeOrOther) { bool OptionsShown = false; bool UsrBelongsToCrs = false; @@ -1347,7 +1347,7 @@ bool Enr_PutActionsRegRemOneUsr (bool ItsMe) /***** Register user in course / Modify user's data *****/ if (Gbl.Hierarchy.Level == HieLvl_CRS && Gbl.Usrs.Me.Role.Logged >= Rol_STD) { - Enr_PutActionModifyOneUsr (&OptionChecked,UsrBelongsToCrs,ItsMe); + Enr_PutActionModifyOneUsr (&OptionChecked,UsrBelongsToCrs,MeOrOther); OptionsShown = true; } @@ -1380,7 +1380,7 @@ bool Enr_PutActionsRegRemOneUsr (bool ItsMe) } /***** Report user as possible duplicate *****/ - if (!ItsMe && Gbl.Usrs.Me.Role.Logged >= Rol_TCH) + if (MeOrOther == Usr_OTHER && Gbl.Usrs.Me.Role.Logged >= Rol_TCH) { Enr_PutActionRepUsrAsDup (&OptionChecked); OptionsShown = true; @@ -1389,7 +1389,7 @@ bool Enr_PutActionsRegRemOneUsr (bool ItsMe) /***** Remove user from the course *****/ if (UsrBelongsToCrs) { - Enr_PutActionRemUsrFromCrs (&OptionChecked,ItsMe); + Enr_PutActionRemUsrFromCrs (&OptionChecked,MeOrOther); OptionsShown = true; } @@ -1399,24 +1399,27 @@ bool Enr_PutActionsRegRemOneUsr (bool ItsMe) { if (Gbl.Hierarchy.Ins.InsCod > 0) /***** Remove user as an administrator of the degree *****/ - if (UsrIsDegAdmin && (ItsMe || Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM)) + if (UsrIsDegAdmin && + (MeOrOther == Usr_ME || Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM)) { - Enr_PutActionRemUsrAsDegAdm (&OptionChecked,ItsMe); + Enr_PutActionRemUsrAsDegAdm (&OptionChecked,MeOrOther); OptionsShown = true; } /***** Remove user as an administrator of the center *****/ - if (UsrIsCtrAdmin && (ItsMe || Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM)) + if (UsrIsCtrAdmin && + (MeOrOther == Usr_ME || Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM)) { - Enr_PutActionRemUsrAsCtrAdm (&OptionChecked,ItsMe); + Enr_PutActionRemUsrAsCtrAdm (&OptionChecked,MeOrOther); OptionsShown = true; } } /***** Remove user as an administrator of the institution *****/ - if (UsrIsInsAdmin && (ItsMe || Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)) + if (UsrIsInsAdmin && + (MeOrOther == Usr_ME || Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)) { - Enr_PutActionRemUsrAsInsAdm (&OptionChecked,ItsMe); + Enr_PutActionRemUsrAsInsAdm (&OptionChecked,MeOrOther); OptionsShown = true; } } @@ -1424,7 +1427,7 @@ bool Enr_PutActionsRegRemOneUsr (bool ItsMe) /***** Eliminate user completely from platform *****/ if (Acc_CheckIfICanEliminateAccount (Gbl.Usrs.Other.UsrDat.UsrCod)) { - Enr_PutActionRemUsrAcc (&OptionChecked,ItsMe); + Enr_PutActionRemUsrAcc (&OptionChecked,MeOrOther); OptionsShown = true; } @@ -1439,19 +1442,22 @@ bool Enr_PutActionsRegRemOneUsr (bool ItsMe) /*****************************************************************************/ static void Enr_PutActionModifyOneUsr (bool *OptionChecked, - bool UsrBelongsToCrs,bool ItsMe) + bool UsrBelongsToCrs,Usr_MeOrOther_t MeOrOther) { - extern const char *Txt_Modify_me_in_the_course_X; - extern const char *Txt_Modify_user_in_the_course_X; extern const char *Txt_Register_me_in_X; extern const char *Txt_Register_USER_in_the_course_X; + extern const char *Txt_Modify_me_in_the_course_X; + extern const char *Txt_Modify_user_in_the_course_X; + const char *Txt[2][Usr_NUM_ME_OR_OTHER] = + { + [false][Usr_ME ] = Txt_Register_me_in_X, + [false][Usr_OTHER] = Txt_Register_USER_in_the_course_X, + [true ][Usr_ME ] = Txt_Modify_me_in_the_course_X, + [true ][Usr_OTHER] = Txt_Modify_user_in_the_course_X, + }; Enr_RegRemOneUsrActionBegin (Enr_REGISTER_MODIFY_ONE_USR_IN_CRS,OptionChecked); - HTM_TxtF (UsrBelongsToCrs ? (ItsMe ? Txt_Modify_me_in_the_course_X : - Txt_Modify_user_in_the_course_X) : - (ItsMe ? Txt_Register_me_in_X : - Txt_Register_USER_in_the_course_X), - Gbl.Hierarchy.Crs.ShrtName); + HTM_TxtF (Txt[UsrBelongsToCrs][MeOrOther],Gbl.Hierarchy.Crs.ShrtName); Enr_RegRemOneUsrActionEnd (); } @@ -1514,15 +1520,18 @@ static void Enr_PutActionRepUsrAsDup (bool *OptionChecked) /****************** Put action to remove user from course ********************/ /*****************************************************************************/ -static void Enr_PutActionRemUsrFromCrs (bool *OptionChecked,bool ItsMe) +static void Enr_PutActionRemUsrFromCrs (bool *OptionChecked,Usr_MeOrOther_t MeOrOther) { extern const char *Txt_Remove_me_from_THE_COURSE_X; extern const char *Txt_Remove_USER_from_THE_COURSE_X; + const char *Txt[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = Txt_Remove_me_from_THE_COURSE_X, + [Usr_OTHER] = Txt_Remove_USER_from_THE_COURSE_X, + }; Enr_RegRemOneUsrActionBegin (Enr_REMOVE_ONE_USR_FROM_CRS,OptionChecked); - HTM_TxtF (ItsMe ? Txt_Remove_me_from_THE_COURSE_X : - Txt_Remove_USER_from_THE_COURSE_X, - Gbl.Hierarchy.Crs.ShrtName); + HTM_TxtF (Txt[MeOrOther],Gbl.Hierarchy.Crs.ShrtName); Enr_RegRemOneUsrActionEnd (); } @@ -1530,15 +1539,18 @@ static void Enr_PutActionRemUsrFromCrs (bool *OptionChecked,bool ItsMe) /***************** Put action to remove user as degree admin *****************/ /*****************************************************************************/ -static void Enr_PutActionRemUsrAsDegAdm (bool *OptionChecked,bool ItsMe) +static void Enr_PutActionRemUsrAsDegAdm (bool *OptionChecked,Usr_MeOrOther_t MeOrOther) { extern const char *Txt_Remove_me_as_an_administrator_of_the_degree_X; extern const char *Txt_Remove_USER_as_an_administrator_of_the_degree_X; + const char *Txt[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = Txt_Remove_me_as_an_administrator_of_the_degree_X, + [Usr_OTHER] = Txt_Remove_USER_as_an_administrator_of_the_degree_X, + }; Enr_RegRemOneUsrActionBegin (Enr_REMOVE_ONE_DEGREE_ADMIN,OptionChecked); - HTM_TxtF (ItsMe ? Txt_Remove_me_as_an_administrator_of_the_degree_X : - Txt_Remove_USER_as_an_administrator_of_the_degree_X, - Gbl.Hierarchy.Deg.ShrtName); + HTM_TxtF (Txt[MeOrOther],Gbl.Hierarchy.Deg.ShrtName); Enr_RegRemOneUsrActionEnd (); } @@ -1546,15 +1558,18 @@ static void Enr_PutActionRemUsrAsDegAdm (bool *OptionChecked,bool ItsMe) /***************** Put action to remove user as center admin *****************/ /*****************************************************************************/ -static void Enr_PutActionRemUsrAsCtrAdm (bool *OptionChecked,bool ItsMe) +static void Enr_PutActionRemUsrAsCtrAdm (bool *OptionChecked,Usr_MeOrOther_t MeOrOther) { extern const char *Txt_Remove_me_as_an_administrator_of_the_center_X; extern const char *Txt_Remove_USER_as_an_administrator_of_the_center_X; + const char *Txt[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = Txt_Remove_me_as_an_administrator_of_the_center_X, + [Usr_OTHER] = Txt_Remove_USER_as_an_administrator_of_the_center_X, + }; Enr_RegRemOneUsrActionBegin (Enr_REMOVE_ONE_CENTER_ADMIN,OptionChecked); - HTM_TxtF (ItsMe ? Txt_Remove_me_as_an_administrator_of_the_center_X : - Txt_Remove_USER_as_an_administrator_of_the_center_X, - Gbl.Hierarchy.Ctr.ShrtName); + HTM_TxtF (Txt[MeOrOther],Gbl.Hierarchy.Ctr.ShrtName); Enr_RegRemOneUsrActionEnd (); } @@ -1562,15 +1577,18 @@ static void Enr_PutActionRemUsrAsCtrAdm (bool *OptionChecked,bool ItsMe) /************** Put action to remove user as institution admin ***************/ /*****************************************************************************/ -static void Enr_PutActionRemUsrAsInsAdm (bool *OptionChecked,bool ItsMe) +static void Enr_PutActionRemUsrAsInsAdm (bool *OptionChecked,Usr_MeOrOther_t MeOrOther) { extern const char *Txt_Remove_me_as_an_administrator_of_the_institution_X; extern const char *Txt_Remove_USER_as_an_administrator_of_the_institution_X; + const char *Txt[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = Txt_Remove_me_as_an_administrator_of_the_institution_X, + [Usr_OTHER] = Txt_Remove_USER_as_an_administrator_of_the_institution_X, + }; Enr_RegRemOneUsrActionBegin (Enr_REMOVE_ONE_INSTITUTION_ADMIN,OptionChecked); - HTM_TxtF (ItsMe ? Txt_Remove_me_as_an_administrator_of_the_institution_X : - Txt_Remove_USER_as_an_administrator_of_the_institution_X, - Gbl.Hierarchy.Ins.ShrtName); + HTM_TxtF (Txt[MeOrOther],Gbl.Hierarchy.Ins.ShrtName); Enr_RegRemOneUsrActionEnd (); } @@ -1578,14 +1596,18 @@ static void Enr_PutActionRemUsrAsInsAdm (bool *OptionChecked,bool ItsMe) /********************* Put action to remove user account *********************/ /*****************************************************************************/ -static void Enr_PutActionRemUsrAcc (bool *OptionChecked,bool ItsMe) +static void Enr_PutActionRemUsrAcc (bool *OptionChecked,Usr_MeOrOther_t MeOrOther) { extern const char *Txt_Eliminate_my_user_account; extern const char *Txt_Eliminate_user_account; + const char *Txt[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = Txt_Eliminate_my_user_account, + [Usr_OTHER] = Txt_Eliminate_user_account, + }; Enr_RegRemOneUsrActionBegin (Enr_ELIMINATE_ONE_USR_FROM_PLATFORM,OptionChecked); - HTM_Txt (ItsMe ? Txt_Eliminate_my_user_account : - Txt_Eliminate_user_account); + HTM_Txt (Txt[MeOrOther]); Enr_RegRemOneUsrActionEnd (); } @@ -2698,7 +2720,7 @@ static bool Enr_CheckIfICanRemUsrFromCrs (void) case Rol_STD: case Rol_NET: // A student or non-editing teacher can remove herself/himself - return Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); + return Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod) == Usr_ME; case Rol_TCH: case Rol_DEG_ADM: case Rol_CTR_ADM: @@ -2846,7 +2868,7 @@ void Enr_ModifyUsr1 (void) extern const char *Txt_The_role_of_THE_USER_X_in_the_course_Y_has_changed_from_A_to_B; extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; extern const char *Txt_THE_USER_X_has_been_enroled_in_the_course_Y; - bool ItsMe; + Usr_MeOrOther_t MeOrOther; Rol_Role_t OldRole; Rol_Role_t NewRole; static const Act_Action_t Action[Rol_NUM_ROLES] = @@ -2860,7 +2882,7 @@ void Enr_ModifyUsr1 (void) /***** Get user from form *****/ if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ()) { - ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); + MeOrOther = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); /***** Get the action to do *****/ Gbl.Usrs.RegRemAction = (Enr_RegRemOneUsrAction_t) @@ -2871,7 +2893,7 @@ void Enr_ModifyUsr1 (void) switch (Gbl.Usrs.RegRemAction) { case Enr_REGISTER_MODIFY_ONE_USR_IN_CRS: - if (ItsMe || Gbl.Usrs.Me.Role.Logged >= Rol_TCH) + if (MeOrOther == Usr_ME || Gbl.Usrs.Me.Role.Logged >= Rol_TCH) { /***** Get user's name from record form *****/ if (Usr_ICanChangeOtherUsrData (&Gbl.Usrs.Other.UsrDat)) @@ -2918,15 +2940,19 @@ void Enr_ModifyUsr1 (void) /***** Change user's groups *****/ if (Gbl.Crs.Grps.NumGrps) // This course has groups? - { - if (ItsMe) - Grp_ChangeMyGrps (Cns_QUIET); - else - Grp_ChangeOtherUsrGrps (); - } + switch (MeOrOther) + { + case Usr_ME: + Grp_ChangeMyGrps (Cns_QUIET); + break; + case Usr_OTHER: + default: + Grp_ChangeOtherUsrGrps (); + break; + } /***** If it's me, change my roles *****/ - if (ItsMe) + if (MeOrOther == Usr_ME) { Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs = Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs; Gbl.Usrs.Me.UsrDat.Roles.InCrss = Gbl.Usrs.Other.UsrDat.Roles.InCrss; @@ -2956,23 +2982,23 @@ void Enr_ModifyUsr1 (void) Ale_CreateAlertUserNotFoundOrYouDoNotHavePermission (); break; case Enr_REPORT_USR_AS_POSSIBLE_DUPLICATE: - if (ItsMe || Gbl.Usrs.Me.Role.Logged < Rol_TCH) + if (MeOrOther == Usr_ME || Gbl.Usrs.Me.Role.Logged < Rol_TCH) Ale_CreateAlertUserNotFoundOrYouDoNotHavePermission (); break; case Enr_REMOVE_ONE_USR_FROM_CRS: - if (!ItsMe && Gbl.Usrs.Me.Role.Logged < Rol_TCH) + if (MeOrOther == Usr_OTHER && Gbl.Usrs.Me.Role.Logged < Rol_TCH) Ale_CreateAlertUserNotFoundOrYouDoNotHavePermission (); break; case Enr_REMOVE_ONE_DEGREE_ADMIN: - if (!ItsMe && Gbl.Usrs.Me.Role.Logged < Rol_CTR_ADM) + if (MeOrOther == Usr_OTHER && Gbl.Usrs.Me.Role.Logged < Rol_CTR_ADM) Ale_CreateAlertUserNotFoundOrYouDoNotHavePermission (); break; case Enr_REMOVE_ONE_CENTER_ADMIN: - if (!ItsMe && Gbl.Usrs.Me.Role.Logged < Rol_INS_ADM) + if (MeOrOther == Usr_OTHER && Gbl.Usrs.Me.Role.Logged < Rol_INS_ADM) Ale_CreateAlertUserNotFoundOrYouDoNotHavePermission (); break; case Enr_REMOVE_ONE_INSTITUTION_ADMIN: - if (!ItsMe && Gbl.Usrs.Me.Role.Logged != Rol_SYS_ADM) + if (MeOrOther == Usr_OTHER && Gbl.Usrs.Me.Role.Logged != Rol_SYS_ADM) Ale_CreateAlertUserNotFoundOrYouDoNotHavePermission (); break; case Enr_ELIMINATE_ONE_USR_FROM_PLATFORM: @@ -3050,23 +3076,31 @@ static void Enr_AskIfRemoveUsrFromCrs (struct Usr_Data *UsrDat) extern const char *Txt_Do_you_really_want_to_remove_the_following_user_from_the_course_X; extern const char *Txt_Remove_me_from_this_course; extern const char *Txt_Remove_user_from_this_course; - bool ItsMe; + Usr_MeOrOther_t MeOrOther; static const Act_Action_t NextAction[Rol_NUM_ROLES] = { [Rol_STD] = ActRemStdCrs, [Rol_NET] = ActRemNETCrs, [Rol_TCH] = ActRemTchCrs, }; + const char *Question[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = Txt_Do_you_really_want_to_be_removed_from_the_course_X, + [Usr_OTHER] = Txt_Do_you_really_want_to_remove_the_following_user_from_the_course_X + }; + const char *TxtButton[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = Txt_Remove_me_from_this_course, + [Usr_OTHER] = Txt_Remove_user_from_this_course + }; if (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat)) { - ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); + MeOrOther = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); /***** Show question and button to remove user as administrator *****/ /* Begin alert */ - Ale_ShowAlertAndButton1 (Ale_QUESTION,ItsMe ? Txt_Do_you_really_want_to_be_removed_from_the_course_X : - Txt_Do_you_really_want_to_remove_the_following_user_from_the_course_X, - Gbl.Hierarchy.Crs.FullName); + Ale_ShowAlertAndButton1 (Ale_QUESTION,Question[MeOrOther],Gbl.Hierarchy.Crs.FullName); /* Show user's record */ Rec_ShowSharedRecordUnmodifiable (UsrDat); @@ -3077,8 +3111,7 @@ static void Enr_AskIfRemoveUsrFromCrs (struct Usr_Data *UsrDat) Frm_BeginForm (NextAction[UsrDat->Roles.InCurrentCrs]); Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod); Pwd_AskForConfirmationOnDangerousAction (); - Btn_PutRemoveButton (ItsMe ? Txt_Remove_me_from_this_course : - Txt_Remove_user_from_this_course); + Btn_PutRemoveButton (TxtButton[MeOrOther]); Frm_EndForm (); /* End alert */ @@ -3143,33 +3176,35 @@ static void Enr_EffectivelyRemUsrFromCrs (struct Usr_Data *UsrDat, Usr_FlushCachesUsr (); /***** If it's me, change my roles *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) + switch (Usr_ItsMe (UsrDat->UsrCod)) { - /* Now I don't belong to current course */ - Gbl.Usrs.Me.IBelongToCurrentCrs = - Gbl.Usrs.Me.UsrDat.Accepted = false; + case Usr_ME: + /* Now I don't belong to current course */ + Gbl.Usrs.Me.IBelongToCurrentCrs = + Gbl.Usrs.Me.UsrDat.Accepted = false; - /* Fill the list with the courses I belong to */ - Gbl.Usrs.Me.MyCrss.Filled = false; - Enr_GetMyCourses (); + /* Fill the list with the courses I belong to */ + Gbl.Usrs.Me.MyCrss.Filled = false; + Enr_GetMyCourses (); - /* Set my roles */ - Gbl.Usrs.Me.Role.FromSession = - Gbl.Usrs.Me.Role.Logged = - Gbl.Usrs.Me.Role.LoggedBeforeCloseSession = - Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs = - UsrDat->Roles.InCurrentCrs = Rol_UNK; + /* Set my roles */ + Gbl.Usrs.Me.Role.FromSession = + Gbl.Usrs.Me.Role.Logged = + Gbl.Usrs.Me.Role.LoggedBeforeCloseSession = + Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs = + UsrDat->Roles.InCurrentCrs = Rol_UNK; - Gbl.Usrs.Me.UsrDat.Roles.InCrss = - UsrDat->Roles.InCrss = -1; // not yet filled/calculated + Gbl.Usrs.Me.UsrDat.Roles.InCrss = + UsrDat->Roles.InCrss = -1; // not yet filled/calculated - Rol_SetMyRoles (); - } - else // Not me - { - /* Now he/she does not belong to current course */ - UsrDat->Accepted = false; - UsrDat->Roles.InCurrentCrs = Rol_USR; + Rol_SetMyRoles (); + break; + case Usr_OTHER: + default: + /* Now he/she does not belong to current course */ + UsrDat->Accepted = false; + UsrDat->Roles.InCurrentCrs = Rol_USR; + break; } if (QuietOrVerbose == Cns_VERBOSE) @@ -3405,7 +3440,7 @@ bool Enr_CheckIfUsrSharesAnyOfMyCrs (struct Usr_Data *UsrDat) return false; /***** 3. Fast check: It's me? *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) return true; /***** 4. Fast check: Is already calculated if user shares any course with me? *****/ diff --git a/swad_enrolment.h b/swad_enrolment.h index f1f42ae8..47d3260a 100644 --- a/swad_enrolment.h +++ b/swad_enrolment.h @@ -101,7 +101,7 @@ void Enr_ReceiveFormAdminStds (void); void Enr_ReceiveFormAdminNonEditTchs (void); void Enr_ReceiveFormAdminTchs (void); -bool Enr_PutActionsRegRemOneUsr (bool ItsMe); +bool Enr_PutActionsRegRemOneUsr (Usr_MeOrOther_t MeOrOther); void Enr_PutLinkToAdminSeveralUsrs (Rol_Role_t Role); void Enr_AskRemAllStdsThisCrs (void); diff --git a/swad_exam_result.c b/swad_exam_result.c index fd73902d..1a3f73ac 100644 --- a/swad_exam_result.c +++ b/swad_exam_result.c @@ -1408,10 +1408,10 @@ static void ExaRes_CheckIfICanViewResult (const struct Exa_Exam *Exam, { case Rol_STD: // Depends on visibility of exam, session and result (eye icons) - ICanView->Result = (Usr_ItsMe (UsrCod) && // The result is mine - !Exam->Hidden && // The exam is visible - !Session->Hidden && // The session is visible - Session->ShowUsrResults); // The results of the session are visible to users + ICanView->Result = (Usr_ItsMe (UsrCod) == Usr_ME && // The result is mine + !Exam->Hidden && // The exam is visible + !Session->Hidden && // The session is visible + Session->ShowUsrResults); // The results of the session are visible to users // Whether I belong or not to groups of session is not checked here... // ...because I should be able to see old exams made in old groups to which I belonged diff --git a/swad_follow.c b/swad_follow.c index 7dd88b99..a50104b7 100644 --- a/swad_follow.c +++ b/swad_follow.c @@ -353,8 +353,8 @@ void Fol_ShowFollowingAndFollowers (const struct Usr_Data *UsrDat, /* I follow user? */ HTM_DIV_Begin ("id=\"follow_usr\""); - if (Gbl.Usrs.Me.Logged && // Logged - !Usr_ItsMe (UsrDat->UsrCod)) // Not me! + if (Gbl.Usrs.Me.Logged && // Logged + Usr_ItsMe (UsrDat->UsrCod) == Usr_OTHER) // Not me! { Frm_BeginForm (IFollowUsr ? ActUnfUsr : ActFolUsr); @@ -585,7 +585,7 @@ static void Fol_ListFollowersUsr (struct Usr_Data *UsrDat) DB_FreeMySQLResult (&mysql_res); /***** If it's me, mark possible notification as seen *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) Ntf_DB_MarkNotifsAsSeen (Ntf_EVENT_FOLLOWER); } else @@ -633,8 +633,8 @@ static void Fol_ShowFollowedOrFollower (struct Usr_Data *UsrDat) Frm_EndForm (); } - if (!Gbl.Usrs.Me.Logged || // Not logged - Usr_ItsMe (UsrDat->UsrCod)) // It's me + if (!Gbl.Usrs.Me.Logged || // Not logged + Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) // It's me /* Inactive icon to follow/unfollow */ Fol_PutInactiveIconToFollowUnfollow (); else // It's not me @@ -698,8 +698,8 @@ static void Fol_WriteRowUsrToFollowOnRightColumn (struct Usr_Data *UsrDat) /***** Icon to follow *****/ HTM_TD_Begin ("class=\"CON_ICON_FOLLOW RM %s\"", The_GetColorRows ()); - if (!Gbl.Usrs.Me.Logged || // Not logged - Usr_ItsMe (UsrDat->UsrCod)) // It's me + if (!Gbl.Usrs.Me.Logged || // Not logged + Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) // It's me /* Inactive icon to follow/unfollow */ Fol_PutInactiveIconToFollowUnfollow (); else // It's not me diff --git a/swad_forum.c b/swad_forum.c index 6fa9f2ed..7102d2ba 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -971,7 +971,7 @@ static void For_ShowAForumPost (struct For_Forums *Forums, /***** Form to remove post *****/ if (LastPst) - if (Usr_ItsMe (UsrDat.UsrCod)) + if (Usr_ItsMe (UsrDat.UsrCod) == Usr_ME) // Post can be removed if post is the last (without answers) and it's mine Ico_PutContextualIconToRemove (For_ActionsDelPstFor[Forums->Forum.Type], PstNum == 1 ? For_FORUM_THREADS_SECTION_ID : // First and unique post in thread @@ -2914,7 +2914,7 @@ void For_RemovePost (void) Err_WrongPostExit (); /* Check if I am the author of the message */ - if (!Usr_ItsMe (UsrDat.UsrCod)) + if (Usr_ItsMe (UsrDat.UsrCod) == Usr_OTHER) Err_NoPermissionExit (); /* Check if the message is the last message in the thread */ diff --git a/swad_group.c b/swad_group.c index 06e52ee4..049ca393 100644 --- a/swad_group.c +++ b/swad_group.c @@ -1173,7 +1173,7 @@ void Grp_RemUsrFromAllGrpsInCrs (long UsrCod,long CrsCod) /***** Flush caches *****/ Grp_FlushCacheUsrSharesAnyOfMyGrpsInCurrentCrs (); - if (Usr_ItsMe (UsrCod)) + if (Usr_ItsMe (UsrCod) == Usr_ME) Grp_FlushCacheIBelongToGrp (); } @@ -1188,7 +1188,7 @@ void Grp_RemUsrFromAllGrps (long UsrCod) /***** Flush caches *****/ Grp_FlushCacheUsrSharesAnyOfMyGrpsInCurrentCrs (); - if (Usr_ItsMe (UsrCod)) + if (Usr_ItsMe (UsrCod) == Usr_ME) Grp_FlushCacheIBelongToGrp (); } @@ -1203,7 +1203,7 @@ static void Grp_RemoveUsrFromGroup (long UsrCod,long GrpCod) /***** Flush caches *****/ Grp_FlushCacheUsrSharesAnyOfMyGrpsInCurrentCrs (); - if (Usr_ItsMe (UsrCod)) + if (Usr_ItsMe (UsrCod) == Usr_ME) Grp_FlushCacheIBelongToGrp (); } @@ -3051,7 +3051,7 @@ bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct Usr_Data *UsrDat) return false; /***** 5. Fast check: It's me? *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) return true; /***** 6. Fast check: Is already calculated if user shares diff --git a/swad_mail.c b/swad_mail.c index 0a06b98f..89bf1dba 100644 --- a/swad_mail.c +++ b/swad_mail.c @@ -99,14 +99,14 @@ static void Mai_PutHeadMailDomains (void); static void Mai_PutFormToSelectUsrsToListEmails (__attribute__((unused)) void *Args); static void Mai_ListEmails (__attribute__((unused)) void *Args); -static void Mai_ShowFormChangeUsrEmail (bool ItsMe, +static void Mai_ShowFormChangeUsrEmail (Usr_MeOrOther_t MeOrOther, bool IMustFillInEmail, bool IShouldConfirmEmail); static void Mai_PutParsRemoveMyEmail (void *Email); static void Mai_PutParsRemoveOtherEmail (void *Email); static void Mai_RemoveEmail (struct Usr_Data *UsrDat); -static void Mai_NewUsrEmail (struct Usr_Data *UsrDat,bool ItsMe); +static void Mai_ChangeUsrEmail (struct Usr_Data *UsrDat,Usr_MeOrOther_t MeOrOther); static void Mai_InsertMailKey (const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1], const char MailKey[Mai_LENGTH_EMAIL_CONFIRM_KEY + 1]); @@ -1032,7 +1032,7 @@ void Mai_ShowFormChangeMyEmail (bool IMustFillInEmail,bool IShouldConfirmEmail) Hlp_PROFILE_Account,Box_NOT_CLOSABLE); /***** Show form to change email *****/ - Mai_ShowFormChangeUsrEmail (true, // ItsMe + Mai_ShowFormChangeUsrEmail (Usr_ME, IMustFillInEmail, IShouldConfirmEmail); @@ -1063,7 +1063,7 @@ void Mai_ShowFormChangeOtherUsrEmail (void) Hlp_PROFILE_Account,Box_NOT_CLOSABLE); /***** Show form to change email *****/ - Mai_ShowFormChangeUsrEmail (false, // ItsMe + Mai_ShowFormChangeUsrEmail (Usr_OTHER, false, // IMustFillInEmail false); // IShouldConfirmEmail @@ -1078,7 +1078,7 @@ void Mai_ShowFormChangeOtherUsrEmail (void) /********************** Show form to change user's email *********************/ /*****************************************************************************/ -static void Mai_ShowFormChangeUsrEmail (bool ItsMe, +static void Mai_ShowFormChangeUsrEmail (Usr_MeOrOther_t MeOrOther, bool IMustFillInEmail, bool IShouldConfirmEmail) { @@ -1102,22 +1102,41 @@ static void Mai_ShowFormChangeUsrEmail (bool ItsMe, static const struct { Act_Action_t Remove; - Act_Action_t New; + Act_Action_t Change; } NextAction[Rol_NUM_ROLES] = { - [Rol_UNK ] = {ActRemMaiOth,ActNewMaiOth}, - [Rol_GST ] = {ActRemMaiOth,ActNewMaiOth}, - [Rol_USR ] = {ActRemMaiOth,ActNewMaiOth}, - [Rol_STD ] = {ActRemMaiStd,ActNewMaiStd}, - [Rol_NET ] = {ActRemMaiTch,ActNewMaiTch}, - [Rol_TCH ] = {ActRemMaiTch,ActNewMaiTch}, - [Rol_DEG_ADM] = {ActRemMaiOth,ActNewMaiOth}, - [Rol_CTR_ADM] = {ActRemMaiOth,ActNewMaiOth}, - [Rol_INS_ADM] = {ActRemMaiOth,ActNewMaiOth}, - [Rol_SYS_ADM] = {ActRemMaiOth,ActNewMaiOth}, + [Rol_UNK ] = {ActRemMaiOth,ActChgMaiOth}, + [Rol_GST ] = {ActRemMaiOth,ActChgMaiOth}, + [Rol_USR ] = {ActRemMaiOth,ActChgMaiOth}, + [Rol_STD ] = {ActRemMaiStd,ActChgMaiStd}, + [Rol_NET ] = {ActRemMaiTch,ActChgMaiTch}, + [Rol_TCH ] = {ActRemMaiTch,ActChgMaiTch}, + [Rol_DEG_ADM] = {ActRemMaiOth,ActChgMaiOth}, + [Rol_CTR_ADM] = {ActRemMaiOth,ActChgMaiOth}, + [Rol_INS_ADM] = {ActRemMaiOth,ActChgMaiOth}, + [Rol_SYS_ADM] = {ActRemMaiOth,ActChgMaiOth}, + }; + static const struct Usr_Data *UsrDat[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = &Gbl.Usrs.Me.UsrDat, + [Usr_OTHER] = &Gbl.Usrs.Other.UsrDat + }; + static void (*FuncParsRemove[Usr_NUM_ME_OR_OTHER]) (void *ID) = + { + [Usr_ME ] = Mai_PutParsRemoveMyEmail, + [Usr_OTHER] = Mai_PutParsRemoveOtherEmail + }; + struct + { + Act_Action_t Remove; + Act_Action_t Change; + } ActMail[Rol_NUM_ROLES] = + { + [Usr_ME ] = {.Remove = ActRemMyMai, + .Change = ActChgMyMai}, + [Usr_OTHER] = {.Remove = NextAction[Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs].Remove, + .Change = NextAction[Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs].Change} }; - const struct Usr_Data *UsrDat = (ItsMe ? &Gbl.Usrs.Me.UsrDat : - &Gbl.Usrs.Other.UsrDat); /***** Show possible alerts *****/ Ale_ShowAlerts (Mai_EMAIL_SECTION_ID); @@ -1129,7 +1148,7 @@ static void Mai_ShowFormChangeUsrEmail (bool ItsMe, Ale_ShowAlert (Ale_WARNING,Txt_Please_confirm_your_email_address); /***** Get my emails *****/ - NumEmails = Mai_DB_GetMyEmails (&mysql_res,UsrDat->UsrCod); + NumEmails = Mai_DB_GetMyEmails (&mysql_res,UsrDat[MeOrOther]->UsrCod); /***** Begin table *****/ HTM_TABLE_BeginWidePadding (2); @@ -1167,12 +1186,8 @@ static void Mai_ShowFormChangeUsrEmail (bool ItsMe, } /* Form to remove email */ - if (ItsMe) - Ico_PutContextualIconToRemove (ActRemMyMai,Mai_EMAIL_SECTION_ID, - Mai_PutParsRemoveMyEmail,row[0]); - else - Ico_PutContextualIconToRemove (NextAction[UsrDat->Roles.InCurrentCrs].Remove,Mai_EMAIL_SECTION_ID, - Mai_PutParsRemoveOtherEmail,row[0]); + Ico_PutContextualIconToRemove (ActMail[MeOrOther].Remove,Mai_EMAIL_SECTION_ID, + FuncParsRemove[MeOrOther],row[0]); /* Email */ HTM_Txt (row[0]); @@ -1187,19 +1202,15 @@ static void Mai_ShowFormChangeUsrEmail (bool ItsMe, } /* Form to change user's email */ - if (NumEmail > 1 || (ItsMe && !Confirmed)) + if (NumEmail > 1 || (MeOrOther == Usr_ME && !Confirmed)) { HTM_BR (); - if (ItsMe) - Frm_BeginFormAnchor (ActChgMyMai,Mai_EMAIL_SECTION_ID); - else - { - Frm_BeginFormAnchor (NextAction[UsrDat->Roles.InCurrentCrs].New,Mai_EMAIL_SECTION_ID); - Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod); - } + Frm_BeginFormAnchor (ActMail[MeOrOther].Change,Mai_EMAIL_SECTION_ID); + if (MeOrOther == Usr_OTHER) + Usr_PutParUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod); Par_PutParString (NULL,"NewEmail",row[0]); - Btn_PutConfirmButtonInline ((ItsMe && NumEmail == 1) ? Txt_Confirm_email : - Txt_Use_this_email); + Btn_PutConfirmButtonInline ((MeOrOther == Usr_ME && NumEmail == 1) ? Txt_Confirm_email : + Txt_Use_this_email); Frm_EndForm (); } @@ -1224,19 +1235,15 @@ static void Mai_ShowFormChangeUsrEmail (bool ItsMe, /* Data */ HTM_TD_Begin ("class=\"REC_C2_BOT LT DAT_%s\"", The_GetSuffix ()); - if (ItsMe) - Frm_BeginFormAnchor (ActChgMyMai,Mai_EMAIL_SECTION_ID); - else - { - Frm_BeginFormAnchor (NextAction[UsrDat->Roles.InCurrentCrs].New,Mai_EMAIL_SECTION_ID); - Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod); - } - HTM_INPUT_EMAIL ("NewEmail",Cns_MAX_CHARS_EMAIL_ADDRESS,Gbl.Usrs.Me.UsrDat.Email, + Frm_BeginFormAnchor (ActMail[MeOrOther].Change,Mai_EMAIL_SECTION_ID); + if (MeOrOther == Usr_OTHER) + Usr_PutParUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod); + HTM_INPUT_EMAIL ("NewEmail",Cns_MAX_CHARS_EMAIL_ADDRESS,UsrDat[MeOrOther]->Email, "id=\"NewEmail\" class=\"INPUT_%s\" size=\"18\"", The_GetSuffix ()); HTM_BR (); Btn_PutCreateButtonInline (NumEmails ? Txt_Change_email : // User already has an email address - Txt_Save_changes); // User has no email address yet + Txt_Save_changes); // User has no email address yet Frm_EndForm (); HTM_TD_End (); @@ -1334,7 +1341,7 @@ static void Mai_RemoveEmail (struct Usr_Data *UsrDat) void May_NewMyUsrEmail (void) { /***** Remove user's email *****/ - Mai_NewUsrEmail (&Gbl.Usrs.Me.UsrDat, + Mai_ChangeUsrEmail (&Gbl.Usrs.Me.UsrDat, true); // It's me /***** Show my account again *****/ @@ -1342,19 +1349,19 @@ void May_NewMyUsrEmail (void) } /*****************************************************************************/ -/********************* New user's email for another user *********************/ +/************************ Change another user's email ************************/ /*****************************************************************************/ -void Mai_NewOtherUsrEmail (void) +void Mai_ChangeOtherUsrEmail (void) { /***** Get other user's code from form and get user's data *****/ if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ()) { if (Usr_ICanEditOtherUsr (&Gbl.Usrs.Other.UsrDat)) { - /***** New user's ID *****/ - Mai_NewUsrEmail (&Gbl.Usrs.Other.UsrDat, - Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)); + /***** Change user's ID *****/ + Mai_ChangeUsrEmail (&Gbl.Usrs.Other.UsrDat, + Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)); /***** Show form again *****/ Acc_ShowFormChgOtherUsrAccount (); @@ -1367,10 +1374,10 @@ void Mai_NewOtherUsrEmail (void) } /*****************************************************************************/ -/************************* Update my email address ***************************/ +/*************************** Change email address ****************************/ /*****************************************************************************/ -static void Mai_NewUsrEmail (struct Usr_Data *UsrDat,bool ItsMe) +static void Mai_ChangeUsrEmail (struct Usr_Data *UsrDat,Usr_MeOrOther_t MeOrOther) { extern const char *Txt_The_email_address_X_matches_one_previously_registered; extern const char *Txt_The_email_address_X_has_been_registered_successfully; @@ -1405,7 +1412,7 @@ static void Mai_NewUsrEmail (struct Usr_Data *UsrDat,bool ItsMe) /***** Send message via email to confirm the new email address *****/ - if (ItsMe) + if (MeOrOther == Usr_ME) Mai_SendMailMsgToConfirmEmail (); } else @@ -1656,7 +1663,7 @@ void Mai_WriteFootNoteEMail (FILE *FileMail,Lan_Language_t Language) bool Mai_ICanSeeOtherUsrEmail (const struct Usr_Data *UsrDat) { /***** I can see my email *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) return true; /***** Check if I have permission to see another user's email *****/ diff --git a/swad_mail.h b/swad_mail.h index 230d3239..824fff77 100644 --- a/swad_mail.h +++ b/swad_mail.h @@ -86,7 +86,7 @@ void Mai_RemoveMyUsrEmail (void); void Mai_RemoveOtherUsrEmail (void); void May_NewMyUsrEmail (void); -void Mai_NewOtherUsrEmail (void); +void Mai_ChangeOtherUsrEmail (void); bool Mai_UpdateEmailInDB (const struct Usr_Data *UsrDat,const char NewEmail[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]); diff --git a/swad_match_result.c b/swad_match_result.c index 65d61e60..9e897a02 100644 --- a/swad_match_result.c +++ b/swad_match_result.c @@ -1306,7 +1306,7 @@ static void MchRes_CheckIfICanSeeMatchResult (const struct Gam_Game *Game, // Depends on visibility of game and result (eye icons) ICanView->Result = (!Game->Hidden && // The game is visible Match->Status.ShowUsrResults && // The results of the match are visible to users - Usr_ItsMe (UsrCod)); // The result is mine + Usr_ItsMe (UsrCod) == Usr_ME); // The result is mine // Whether I belong or not to groups of match is not checked here... // ...because I should be able to see old matches made in old groups to which I belonged diff --git a/swad_nickname.c b/swad_nickname.c index a7f32d8e..ae87ffc3 100644 --- a/swad_nickname.c +++ b/swad_nickname.c @@ -56,12 +56,12 @@ const char *Nck_NICKNAME_SECTION_ID = "nickname_section"; /***************************** Private prototypes ****************************/ /*****************************************************************************/ -static void Nck_ShowFormChangeUsrNickname (bool ItsMe, +static void Nck_ShowFormChangeUsrNickname (Usr_MeOrOther_t MeOrOther, bool IMustFillNickname); static void Nck_PutParsRemoveMyNick (void *Nick); static void Nck_PutParsRemoveOtherNick (void *Nick); -static void Nck_UpdateUsrNick (struct Usr_Data *UsrDat); +static void Nck_ChangeUsrNick (struct Usr_Data *UsrDat); /*****************************************************************************/ /********* Check whether a nickname (with initial arroba) if valid ***********/ @@ -130,7 +130,7 @@ long Nck_GetUsrCodFromNickname (const char *NickWithArr) void Nck_ShowFormChangeMyNickname (bool IMustFillNickname) { - Nck_ShowFormChangeUsrNickname (true, // ItsMe + Nck_ShowFormChangeUsrNickname (Usr_ME, IMustFillNickname); } @@ -140,7 +140,7 @@ void Nck_ShowFormChangeMyNickname (bool IMustFillNickname) void Nck_ShowFormChangeOtherUsrNickname (void) { - Nck_ShowFormChangeUsrNickname (false, // ItsMe + Nck_ShowFormChangeUsrNickname (Usr_OTHER, false); // IMustFillNickname } @@ -148,7 +148,7 @@ void Nck_ShowFormChangeOtherUsrNickname (void) /*********************** Show form to change my nickname *********************/ /*****************************************************************************/ -static void Nck_ShowFormChangeUsrNickname (bool ItsMe, +static void Nck_ShowFormChangeUsrNickname (Usr_MeOrOther_t MeOrOther, bool IMustFillNickname) { extern const char *Hlp_PROFILE_Account; @@ -166,16 +166,16 @@ static void Nck_ShowFormChangeUsrNickname (bool ItsMe, Act_Action_t Change; } NextAction[Rol_NUM_ROLES] = { - [Rol_UNK ] = {ActRemOldNicOth,ActChgNicOth}, - [Rol_GST ] = {ActRemOldNicOth,ActChgNicOth}, - [Rol_USR ] = {ActRemOldNicOth,ActChgNicOth}, - [Rol_STD ] = {ActRemOldNicStd,ActChgNicStd}, - [Rol_NET ] = {ActRemOldNicTch,ActChgNicTch}, - [Rol_TCH ] = {ActRemOldNicTch,ActChgNicTch}, - [Rol_DEG_ADM] = {ActRemOldNicOth,ActChgNicOth}, - [Rol_CTR_ADM] = {ActRemOldNicOth,ActChgNicOth}, - [Rol_INS_ADM] = {ActRemOldNicOth,ActChgNicOth}, - [Rol_SYS_ADM] = {ActRemOldNicOth,ActChgNicOth}, + [Rol_UNK ] = {ActRemNicOth,ActChgNicOth}, + [Rol_GST ] = {ActRemNicOth,ActChgNicOth}, + [Rol_USR ] = {ActRemNicOth,ActChgNicOth}, + [Rol_STD ] = {ActRemNicStd,ActChgNicStd}, + [Rol_NET ] = {ActRemNicTch,ActChgNicTch}, + [Rol_TCH ] = {ActRemNicTch,ActChgNicTch}, + [Rol_DEG_ADM] = {ActRemNicOth,ActChgNicOth}, + [Rol_CTR_ADM] = {ActRemNicOth,ActChgNicOth}, + [Rol_INS_ADM] = {ActRemNicOth,ActChgNicOth}, + [Rol_SYS_ADM] = {ActRemNicOth,ActChgNicOth}, }; MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -183,14 +183,33 @@ static void Nck_ShowFormChangeUsrNickname (bool ItsMe, unsigned NumNicks; unsigned NumNick; char NickWithArr[Nck_MAX_BYTES_NICK_WITH_ARROBA + 1]; - const struct Usr_Data *UsrDat = (ItsMe ? &Gbl.Usrs.Me.UsrDat : - &Gbl.Usrs.Other.UsrDat); + static struct Usr_Data *UsrDat[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = &Gbl.Usrs.Me.UsrDat, + [Usr_OTHER] = &Gbl.Usrs.Other.UsrDat + }; + static void (*FuncParsRemove[Usr_NUM_ME_OR_OTHER]) (void *ID) = + { + [Usr_ME ] = Nck_PutParsRemoveMyNick, + [Usr_OTHER] = Nck_PutParsRemoveOtherNick + }; + struct + { + Act_Action_t Remove; + Act_Action_t Change; + } ActNck[Rol_NUM_ROLES] = + { + [Usr_ME ] = {.Remove = ActRemMyNck, + .Change = ActChgMyNck}, + [Usr_OTHER] = {.Remove = NextAction[Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs].Remove, + .Change = NextAction[Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs].Change} + }; /***** Begin section *****/ HTM_SECTION_Begin (Nck_NICKNAME_SECTION_ID); /***** Get my nicknames *****/ - NumNicks = Nck_DB_GetUsrNicknames (&mysql_res,UsrDat->UsrCod); + NumNicks = Nck_DB_GetUsrNicknames (&mysql_res,UsrDat[MeOrOther]->UsrCod); /***** Begin box *****/ snprintf (StrRecordWidth,sizeof (StrRecordWidth),"%upx",Rec_RECORD_WIDTH); @@ -242,34 +261,25 @@ static void Nck_ShowFormChangeUsrNickname (bool ItsMe, } /* Form to remove old nickname */ - if (ItsMe) - Ico_PutContextualIconToRemove (ActRemMyNck,Nck_NICKNAME_SECTION_ID, - Nck_PutParsRemoveMyNick,row[0]); - else - Ico_PutContextualIconToRemove (NextAction[UsrDat->Roles.InCurrentCrs].Remove,Nck_NICKNAME_SECTION_ID, - Nck_PutParsRemoveOtherNick,row[0]); + Ico_PutContextualIconToRemove (ActNck[MeOrOther].Remove,Nck_NICKNAME_SECTION_ID, + FuncParsRemove[MeOrOther],row[0]); } /* Nickname */ HTM_TxtF ("@%s",row[0]); /* Link to QR code */ - if (NumNick == 1 && UsrDat->Nickname[0]) + if (NumNick == 1 && UsrDat[MeOrOther]->Nickname[0]) QR_PutLinkToPrintQRCode (ActPrnUsrQR, - Usr_PutParMyUsrCodEncrypted,Gbl.Usrs.Me.UsrDat.EnUsrCod); + Usr_PutParOtherUsrCodEncrypted,UsrDat[MeOrOther]->EnUsrCod); /* Form to change the nickname */ if (NumNick > 1) { HTM_BR (); - if (ItsMe) - Frm_BeginFormAnchor (ActChgMyNck,Nck_NICKNAME_SECTION_ID); - else - { - Frm_BeginFormAnchor (NextAction[UsrDat->Roles.InCurrentCrs].Change,Nck_NICKNAME_SECTION_ID); - Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod); - } - + Frm_BeginFormAnchor (ActNck[MeOrOther].Change,Nck_NICKNAME_SECTION_ID); + if (MeOrOther == Usr_OTHER) + Usr_PutParUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod); snprintf (NickWithArr,sizeof (NickWithArr),"@%s",row[0]); Par_PutParString (NULL,"NewNick",NickWithArr); // Nickname Btn_PutConfirmButtonInline (Txt_Use_this_nickname); @@ -297,15 +307,11 @@ static void Nck_ShowFormChangeUsrNickname (bool ItsMe, /* Data */ HTM_TD_Begin ("class=\"REC_C2_BOT LT DAT_%s\"", The_GetSuffix ()); - if (ItsMe) - Frm_BeginFormAnchor (ActChgMyNck,Nck_NICKNAME_SECTION_ID); - else - { - Frm_BeginFormAnchor (NextAction[UsrDat->Roles.InCurrentCrs].Change,Nck_NICKNAME_SECTION_ID); - Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod); - } + Frm_BeginFormAnchor (ActNck[MeOrOther].Change,Nck_NICKNAME_SECTION_ID); + if (MeOrOther == Usr_OTHER) + Usr_PutParUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod); snprintf (NickWithArr,sizeof (NickWithArr),"@%s", - Gbl.Usrs.Me.UsrDat.Nickname); + UsrDat[MeOrOther]->Nickname); HTM_INPUT_TEXT ("NewNick",1 + Nck_MAX_CHARS_NICK_WITHOUT_ARROBA, NickWithArr,HTM_DONT_SUBMIT_ON_CHANGE, "id=\"NewNick\" class=\"INPUT_%s\"" @@ -416,25 +422,25 @@ void Nck_RemoveOtherUsrNick (void) void Nck_UpdateMyNick (void) { /***** Update my nickname *****/ - Nck_UpdateUsrNick (&Gbl.Usrs.Me.UsrDat); + Nck_ChangeUsrNick (&Gbl.Usrs.Me.UsrDat); /***** Show my account again *****/ Acc_ShowFormChgMyAccount (); } /*****************************************************************************/ -/*********************** Update another user's nickname **********************/ +/*********************** Change another user's nickname **********************/ /*****************************************************************************/ -void Nck_UpdateOtherUsrNick (void) +void Nck_ChangeOtherUsrNick (void) { /***** Get user whose nick must be changed *****/ if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ()) { if (Usr_ICanEditOtherUsr (&Gbl.Usrs.Other.UsrDat)) { - /***** Update my nickname *****/ - Nck_UpdateUsrNick (&Gbl.Usrs.Other.UsrDat); + /***** Update user's nickname *****/ + Nck_ChangeUsrNick (&Gbl.Usrs.Other.UsrDat); /***** Show user's account again *****/ Acc_ShowFormChgOtherUsrAccount (); @@ -447,10 +453,10 @@ void Nck_UpdateOtherUsrNick (void) } /*****************************************************************************/ -/*************************** Update user's nickname **************************/ +/*************************** Change user's nickname **************************/ /*****************************************************************************/ -static void Nck_UpdateUsrNick (struct Usr_Data *UsrDat) +static void Nck_ChangeUsrNick (struct Usr_Data *UsrDat) { extern const char *Txt_The_nickname_matches_the_one_you_had_previously_registered; extern const char *Txt_The_nickname_had_been_registered_by_another_user; diff --git a/swad_nickname.h b/swad_nickname.h index 7d20e82c..575eca6e 100644 --- a/swad_nickname.h +++ b/swad_nickname.h @@ -49,6 +49,6 @@ void Nck_RemoveMyNick (void); void Nck_RemoveOtherUsrNick (void); void Nck_UpdateMyNick (void); -void Nck_UpdateOtherUsrNick (void); +void Nck_ChangeOtherUsrNick (void); #endif diff --git a/swad_photo.c b/swad_photo.c index 85b09861..3e9349e1 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -94,10 +94,11 @@ static void Pho_ReqOtherUsrPhoto (void); static void Pho_ReqPhoto (const struct Usr_Data *UsrDat); -static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct Usr_Data *UsrDat); +static bool Pho_ReceivePhotoAndDetectFaces (Usr_MeOrOther_t MeOrOther, + const struct Usr_Data *UsrDat); -static void Pho_UpdatePhoto1 (struct Usr_Data *UsrDat); -static void Pho_UpdatePhoto2 (void); +static void Pho_ChangePhoto1 (struct Usr_Data *UsrDat); +static void Pho_ChangePhoto2 (void); static long Pho_GetDegWithAvgPhotoLeastRecentlyUpdated (void); static long Pho_GetTimeAvgPhotoWasComputed (long DegCod); @@ -143,7 +144,7 @@ static void Pho_ComputePhotoSize (const struct Pho_DegPhotos *DegPhotos, bool Pho_ICanChangeOtherUsrPhoto (struct Usr_Data *UsrDat) { /***** I can change my photo *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) return true; /***** Check if I have permission to change user's photo *****/ @@ -188,15 +189,21 @@ void Pho_PutIconToChangeUsrPhoto (struct Usr_Data *UsrDat) }; /***** Link for changing / uploading the photo *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) - Lay_PutContextualLinkOnlyIcon (ActReqMyPho,NULL, - NULL,NULL, - "camera.svg",Ico_BLACK); - else // Not me - if (Pho_ICanChangeOtherUsrPhoto (UsrDat)) - Lay_PutContextualLinkOnlyIcon (NextAction[UsrDat->Roles.InCurrentCrs],NULL, - Rec_PutParUsrCodEncrypted,NULL, - "camera.svg",Ico_BLACK); + switch (Usr_ItsMe (UsrDat->UsrCod)) + { + case Usr_ME: + Lay_PutContextualLinkOnlyIcon (ActReqMyPho,NULL, + NULL,NULL, + "camera.svg",Ico_BLACK); + break; + case Usr_OTHER: + default: + if (Pho_ICanChangeOtherUsrPhoto (UsrDat)) + Lay_PutContextualLinkOnlyIcon (NextAction[UsrDat->Roles.InCurrentCrs],NULL, + Rec_PutParUsrCodEncrypted,NULL, + "camera.svg",Ico_BLACK); + break; + } } /*****************************************************************************/ @@ -277,7 +284,6 @@ static void Pho_ReqPhoto (const struct Usr_Data *UsrDat) extern const char *Txt_Photo; extern const char *Txt_You_can_send_a_file_with_an_image_in_JPEG_format_; extern const char *Txt_File_with_the_photo; - bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); static const Act_Action_t NextAction[Rol_NUM_ROLES] = { [Rol_UNK ] = ActDetOthPho, @@ -291,20 +297,29 @@ static void Pho_ReqPhoto (const struct Usr_Data *UsrDat) [Rol_INS_ADM] = ActDetOthPho, [Rol_SYS_ADM] = ActDetOthPho, }; + static void (*FunctionToDrawContextualIcons[Usr_NUM_ME_OR_OTHER]) (void *Args) = + { + [Usr_ME ] = Pho_PutIconToReqRemMyPhoto, + [Usr_OTHER] = Pho_PutIconToReqRemOtherUsrPhoto + }; + Usr_MeOrOther_t MeOrOther = Usr_ItsMe (UsrDat->UsrCod); /***** Begin box *****/ Box_BoxBegin (NULL,Txt_Photo, - ItsMe ? Pho_PutIconToReqRemMyPhoto : - Pho_PutIconToReqRemOtherUsrPhoto,NULL, + FunctionToDrawContextualIcons[MeOrOther],NULL, Hlp_PROFILE_Photo,Box_NOT_CLOSABLE); /***** Begin form *****/ - if (ItsMe) - Frm_BeginForm (ActDetMyPho); - else - { - Frm_BeginForm (NextAction[Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs]); - Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod); + switch (MeOrOther) + { + case Usr_ME: + Frm_BeginForm (ActDetMyPho); + break; + case Usr_OTHER: + default: + Frm_BeginForm (NextAction[Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs]); + Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod); + break; } /***** Show help message *****/ @@ -344,12 +359,18 @@ void Pho_SendPhotoUsr (void) return; } - if (Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)) - /***** Form to send my photo *****/ - Pho_ReqMyPhoto (); - else // Not me - /***** Form to send another user's photo *****/ - Pho_ReqOtherUsrPhoto (); + switch (Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)) + { + case Usr_ME: + /***** Form to send my photo *****/ + Pho_ReqMyPhoto (); + break; + case Usr_OTHER: + default: + /***** Form to send another user's photo *****/ + Pho_ReqOtherUsrPhoto (); + break; + } } /*****************************************************************************/ @@ -555,7 +576,8 @@ void Pho_RemoveUsrPhoto (void) /*****************************************************************************/ // Return false if no "green" faces detected -static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct Usr_Data *UsrDat) +static bool Pho_ReceivePhotoAndDetectFaces (Usr_MeOrOther_t MeOrOther, + const struct Usr_Data *UsrDat) { extern const char *Txt_The_file_is_not_X; extern const char *Txt_Could_not_detect_any_face_in_front_position_; @@ -593,16 +615,21 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct Usr_Data *Us char StrFileName[NAME_MAX + 1]; static const Act_Action_t NextAction[Rol_NUM_ROLES] = { - [Rol_UNK ] = ActUpdOthPho, - [Rol_GST ] = ActUpdOthPho, - [Rol_USR ] = ActUpdOthPho, - [Rol_STD ] = ActUpdStdPho, - [Rol_NET ] = ActUpdTchPho, - [Rol_TCH ] = ActUpdTchPho, - [Rol_DEG_ADM] = ActUpdOthPho, - [Rol_CTR_ADM] = ActUpdOthPho, - [Rol_INS_ADM] = ActUpdOthPho, - [Rol_SYS_ADM] = ActUpdOthPho, + [Rol_UNK ] = ActChgOthPho, + [Rol_GST ] = ActChgOthPho, + [Rol_USR ] = ActChgOthPho, + [Rol_STD ] = ActChgStdPho, + [Rol_NET ] = ActChgTchPho, + [Rol_TCH ] = ActChgTchPho, + [Rol_DEG_ADM] = ActChgOthPho, + [Rol_CTR_ADM] = ActChgOthPho, + [Rol_INS_ADM] = ActChgOthPho, + [Rol_SYS_ADM] = ActChgOthPho, + }; + Act_Action_t ActChgPho[Rol_NUM_ROLES] = + { + [Usr_ME ] = ActUpdMyPho, + [Usr_OTHER] = NextAction[Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs] }; char ErrorTxt[256]; char *Icon; @@ -683,15 +710,11 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct Usr_Data *Us if (BackgroundCode == 1) { snprintf (FormId,sizeof (FormId),"photo_%u",++NumFaces.Green); - if (ItsMe) - Frm_BeginFormId (ActUpdMyPho,FormId); - else - { - Frm_BeginFormId (NextAction[Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs],FormId); - Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod); - } + Frm_BeginFormId (ActChgPho[MeOrOther],FormId); + if (MeOrOther == Usr_OTHER) + Usr_PutParUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod); Par_PutParString (NULL,"FileName",StrFileName); - Frm_EndForm (); + Frm_EndForm (); } else NumFaces.Red++; @@ -789,7 +812,7 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct Usr_Data *Us void Pho_UpdateMyPhoto1 (void) { - Pho_UpdatePhoto1 (&Gbl.Usrs.Me.UsrDat); + Pho_ChangePhoto1 (&Gbl.Usrs.Me.UsrDat); /***** The link to my photo is not valid now, so build it again before writing the web page *****/ Gbl.Usrs.Me.MyPhotoExists = Pho_BuildLinkToPhoto (&Gbl.Usrs.Me.UsrDat,Gbl.Usrs.Me.PhotoURL); @@ -797,38 +820,38 @@ void Pho_UpdateMyPhoto1 (void) void Pho_UpdateMyPhoto2 (void) { - Pho_UpdatePhoto2 (); + Pho_ChangePhoto2 (); /***** Show my record and other data *****/ Rec_ShowMySharedRecordAndMore (); } /*****************************************************************************/ -/*********************** Update another user's photo *************************/ +/*********************** Change another user's photo *************************/ /*****************************************************************************/ -void Pho_UpdateUsrPhoto1 (void) +void Pho_ChangeUsrPhoto1 (void) { /***** Get user's code from form and user's data *****/ if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ()) - Pho_UpdatePhoto1 (&Gbl.Usrs.Other.UsrDat); + Pho_ChangePhoto1 (&Gbl.Usrs.Other.UsrDat); else Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission (); } -void Pho_UpdateUsrPhoto2 (void) +void Pho_ChangeUsrPhoto2 (void) { - Pho_UpdatePhoto2 (); + Pho_ChangePhoto2 (); /***** Show another user's record card *****/ Rec_ShowPublicSharedRecordOtherUsr (); } /*****************************************************************************/ -/*************** Update a user's photo with a selected face ******************/ +/*************** Change a user's photo with a selected face ******************/ /*****************************************************************************/ -static void Pho_UpdatePhoto1 (struct Usr_Data *UsrDat) +static void Pho_ChangePhoto1 (struct Usr_Data *UsrDat) { extern const char *Txt_Photo_has_been_updated; char PathPhotoTmp[PATH_MAX + 1]; // Full name (including path and .jpg) of the temporary file with the selected face @@ -862,7 +885,7 @@ static void Pho_UpdatePhoto1 (struct Usr_Data *UsrDat) "Error updating photo."); } -static void Pho_UpdatePhoto2 (void) +static void Pho_ChangePhoto2 (void) { extern const char *Txt_PHOTO_PROCESSING_CAPTIONS[3]; unsigned NumPhoto; diff --git a/swad_photo.h b/swad_photo.h index 5ae80ff2..e7b0a534 100644 --- a/swad_photo.h +++ b/swad_photo.h @@ -110,8 +110,8 @@ void Pho_RemoveUsrPhoto (void); void Pho_UpdateMyPhoto1 (void); void Pho_UpdateMyPhoto2 (void); -void Pho_UpdateUsrPhoto1 (void); -void Pho_UpdateUsrPhoto2 (void); +void Pho_ChangeUsrPhoto1 (void); +void Pho_ChangeUsrPhoto2 (void); unsigned Pho_UpdateMyClicksWithoutPhoto (void); diff --git a/swad_privacy.c b/swad_privacy.c index 103771b9..70b1de14 100644 --- a/swad_privacy.c +++ b/swad_privacy.c @@ -256,7 +256,7 @@ Pri_Visibility_t Pri_GetParVisibility (const char *ParName, bool Pri_ShowingIsAllowed (Pri_Visibility_t Visibility,struct Usr_Data *UsrDat) { /***** I always can see my things *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) return true; /***** System admins always can see others' profiles *****/ diff --git a/swad_profile.c b/swad_profile.c index 076745e0..62aa37b1 100644 --- a/swad_profile.c +++ b/swad_profile.c @@ -109,7 +109,8 @@ static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod); static void Prf_ResetUsrFigures (struct Prf_UsrFigures *UsrFigures); static void Prf_GetAndShowRankingFigure (const char *FldName); -static void Prf_ShowUsrInRanking (struct Usr_Data *UsrDat,unsigned Rank,bool ItsMe); +static void Prf_ShowUsrInRanking (struct Usr_Data *UsrDat,unsigned Rank, + Usr_MeOrOther_t MeOrOther); /*****************************************************************************/ /************* Suggest who to follow or request user's profile ***************/ @@ -265,7 +266,7 @@ void Prf_GetUsrDatAndShowUserProfile (void) } /***** If it's not me, mark possible notification as seen *****/ - if (!Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)) // Not me + if (Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod) == Usr_OTHER) // Not me Ntf_DB_MarkNotifAsSeenUsingCod (Ntf_EVENT_FOLLOWER, Gbl.Usrs.Other.UsrDat.UsrCod); } @@ -277,11 +278,16 @@ void Prf_GetUsrDatAndShowUserProfile (void) bool Prf_ShowUserProfile (struct Usr_Data *UsrDat) { + static void (*PutLinkToUsrProfile[Usr_NUM_ME_OR_OTHER]) (void) = + { + [Usr_ME ] = Prf_PutLinkRequestAnotherUserProfile, // Request another user's profile + [Usr_OTHER] = Prf_PutLinkMyPublicProfile // My public profile + }; unsigned NumFollowing; unsigned NumFollowers; bool UsrFollowsMe; bool IFollowUsr; - bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); + Usr_MeOrOther_t MeOrOther = Usr_ItsMe (UsrDat->UsrCod); /***** Check if I can see the public profile *****/ if (Pri_ShowingIsAllowed (UsrDat->BaPrfVisibility,UsrDat)) @@ -290,16 +296,13 @@ bool Prf_ShowUserProfile (struct Usr_Data *UsrDat) { /***** Contextual menu *****/ Mnu_ContextMenuBegin (); - if (ItsMe) - Prf_PutLinkRequestAnotherUserProfile (); // Request another user's profile - else // Not me - Prf_PutLinkMyPublicProfile (); // My public profile - Fol_PutLinkWhoToFollow (); // Users to follow + PutLinkToUsrProfile[MeOrOther] (); // Public profile + Fol_PutLinkWhoToFollow (); // Users to follow Mnu_ContextMenuEnd (); } /***** Shared record card *****/ - if (!ItsMe && // If not me... + if (MeOrOther == Usr_OTHER && // If not me... Gbl.Hierarchy.Level == HieLvl_CRS) // ...and a course is selected { /* Get user's role in current course */ @@ -1170,11 +1173,16 @@ static void Prf_GetAndShowRankingFigure (const char *FldName) void Prf_ShowRankingFigure (MYSQL_RES **mysql_res,unsigned NumUsrs) { + static const char *Class[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = "DAT_SMALL_STRONG", + [Usr_OTHER] = "DAT_SMALL" + }; MYSQL_ROW row; unsigned NumUsr; unsigned Rank; struct Usr_Data UsrDat; - bool ItsMe; + Usr_MeOrOther_t MeOrOther; long FigureHigh = LONG_MAX; long Figure; @@ -1197,7 +1205,6 @@ void Prf_ShowRankingFigure (MYSQL_RES **mysql_res,unsigned NumUsrs) Usr_GetAllUsrDataFromUsrCod (&UsrDat, Usr_DONT_GET_PREFS, Usr_DONT_GET_ROLE_IN_CURRENT_CRS); - ItsMe = Usr_ItsMe (UsrDat.UsrCod); /* Get figure (row[1]) */ if (sscanf (row[1],"%ld",&Figure) != 1) @@ -1211,10 +1218,10 @@ void Prf_ShowRankingFigure (MYSQL_RES **mysql_res,unsigned NumUsrs) /***** Show row *****/ HTM_TR_Begin (NULL); - Prf_ShowUsrInRanking (&UsrDat,Rank,ItsMe); + MeOrOther = Usr_ItsMe (UsrDat.UsrCod); + Prf_ShowUsrInRanking (&UsrDat,Rank,MeOrOther); HTM_TD_Begin ("class=\"RM %s_%s %s\"", - ItsMe ? "DAT_SMALL_STRONG" : - "DAT_SMALL", + Class[MeOrOther], The_GetSuffix (), The_GetColorRows ()); HTM_Long (Figure); @@ -1238,13 +1245,18 @@ void Prf_ShowRankingFigure (MYSQL_RES **mysql_res,unsigned NumUsrs) void Prf_GetAndShowRankingClicksPerDay (void) { + static const char *Class[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = "DAT_SMALL_STRONG", + [Usr_OTHER] = "DAT_SMALL" + }; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumUsrs = 0; // Initialized to avoid warning unsigned NumUsr; unsigned Rank; struct Usr_Data UsrDat; - bool ItsMe; + Usr_MeOrOther_t MeOrOther; double NumClicksPerDayHigh = (double) LONG_MAX; double NumClicksPerDay; @@ -1268,7 +1280,6 @@ void Prf_GetAndShowRankingClicksPerDay (void) Usr_GetAllUsrDataFromUsrCod (&UsrDat, Usr_DONT_GET_PREFS, Usr_DONT_GET_ROLE_IN_CURRENT_CRS); - ItsMe = Usr_ItsMe (UsrDat.UsrCod); /* Get average number of clicks per day (row[1]) */ NumClicksPerDay = Str_GetDoubleFromStr (row[1]); @@ -1280,10 +1291,9 @@ void Prf_GetAndShowRankingClicksPerDay (void) /***** Show row *****/ HTM_TR_Begin (NULL); - Prf_ShowUsrInRanking (&UsrDat,Rank,ItsMe); - HTM_TD_Begin ("class=\"RM %s_%s %s\"", - ItsMe ? "DAT_SMALL_STRONG" : - "DAT_SMALL", + MeOrOther = Usr_ItsMe (UsrDat.UsrCod); + Prf_ShowUsrInRanking (&UsrDat,Rank,MeOrOther); + HTM_TD_Begin ("class=\"RM %s_%s %s\"",Class[MeOrOther], The_GetSuffix (), The_GetColorRows ()); HTM_DoubleFewDigits (NumClicksPerDay); @@ -1305,9 +1315,15 @@ void Prf_GetAndShowRankingClicksPerDay (void) /************** Show user's photo and nickname in ranking list ***************/ /*****************************************************************************/ -static void Prf_ShowUsrInRanking (struct Usr_Data *UsrDat,unsigned Rank,bool ItsMe) +static void Prf_ShowUsrInRanking (struct Usr_Data *UsrDat,unsigned Rank, + Usr_MeOrOther_t MeOrOther) { extern const char *Txt_Another_user_s_profile; + static const char *Class[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = "DAT_SMALL_STRONG", + [Usr_OTHER] = "DAT_SMALL" + }; static const char *ClassPhoto[PhoSha_NUM_SHAPES] = { [PhoSha_SHAPE_CIRCLE ] = "PHOTOC30x40", @@ -1318,8 +1334,7 @@ static void Prf_ShowUsrInRanking (struct Usr_Data *UsrDat,unsigned Rank,bool Its bool Visible = Pri_ShowingIsAllowed (UsrDat->BaPrfVisibility,UsrDat); HTM_TD_Begin ("class=\"RM %s_%s %s\"", - ItsMe ? "DAT_SMALL_STRONG" : - "DAT_SMALL", + Class[MeOrOther], The_GetSuffix (), The_GetColorRows ()); HTM_TxtF ("#%u",Rank); @@ -1335,8 +1350,7 @@ static void Prf_ShowUsrInRanking (struct Usr_Data *UsrDat,unsigned Rank,bool Its /***** Put form to go to public profile *****/ HTM_TD_Begin ("class=\"RANK_USR %s_%s %s\"", // Limited width - ItsMe ? "DAT_SMALL_STRONG" : - "DAT_SMALL", + Class[MeOrOther], The_GetSuffix (), The_GetColorRows ()); if (Visible) diff --git a/swad_project.c b/swad_project.c index 1b0a1c32..82c5882e 100644 --- a/swad_project.c +++ b/swad_project.c @@ -2962,7 +2962,7 @@ static void Prj_AddUsrsToProject (Prj_RoleInProject_t RoleInPrj) Prj_DB_AddUsrToPrj (Projects.Prj.PrjCod,RoleInPrj,Gbl.Usrs.Other.UsrDat.UsrCod); /* Flush cache */ - if (Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)) + if (Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod) == Usr_ME) Prj_FlushCacheMyRolesInProject (); /* Show success alert */ @@ -3027,6 +3027,11 @@ static void Prj_ReqRemUsrFromPrj (struct Prj_Projects *Projects, [Prj_ROLE_TUT] = ActRemTutPrj, // Tutor [Prj_ROLE_EVL] = ActRemEvlPrj, // Evaluator }; + const char *Question[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = Txt_Do_you_really_want_to_be_removed_as_a_X_from_the_project_Y, + [Usr_OTHER] = Txt_Do_you_really_want_to_remove_the_following_user_as_a_X_from_the_project_Y + }; char *TxtButton; /***** Allocate memory for the project *****/ @@ -3046,8 +3051,7 @@ static void Prj_ReqRemUsrFromPrj (struct Prj_Projects *Projects, { /***** Show question and button to remove user as a role from project *****/ /* Begin alert */ - Ale_ShowAlertAndButton1 (Ale_QUESTION,Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod) ? Txt_Do_you_really_want_to_be_removed_as_a_X_from_the_project_Y : - Txt_Do_you_really_want_to_remove_the_following_user_as_a_X_from_the_project_Y, + Ale_ShowAlertAndButton1 (Ale_QUESTION,Question[Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)], Txt_PROJECT_ROLES_SINGUL_abc[RoleInPrj][Gbl.Usrs.Other.UsrDat.Sex], Projects->Prj.Title); @@ -3127,7 +3131,7 @@ static void Prj_RemUsrFromPrj (Prj_RoleInProject_t RoleInPrj) Prj_DB_RemoveUsrFromPrj (Projects.Prj.PrjCod,RoleInPrj,Gbl.Usrs.Other.UsrDat.UsrCod); /***** Flush cache *****/ - if (Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)) + if (Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod) == Usr_ME) Prj_FlushCacheMyRolesInProject (); /***** Show success alert *****/ @@ -4528,7 +4532,7 @@ void Prj_RemoveUsrFromProjects (long UsrCod) Prj_DB_RemoveUsrFromProjects (UsrCod); /***** Flush cache *****/ - if (Usr_ItsMe (UsrCod)) + if (Usr_ItsMe (UsrCod) == Usr_ME) Prj_FlushCacheMyRolesInProject (); } diff --git a/swad_record.c b/swad_record.c index 9815bf31..8004d911 100644 --- a/swad_record.c +++ b/swad_record.c @@ -128,8 +128,8 @@ static void Rec_ShowMyCrsRecordUpdated (void); static bool Rec_CheckIfICanEditField (Rec_VisibilityRecordFields_t Visibility); static void Rec_PutIconsCommands (__attribute__((unused)) void *Args); -static void Rec_PutParsMyTsts (__attribute__((unused)) void *Args); -static void Rec_PutParsStdTsts (__attribute__((unused)) void *Args); +static void Rec_PutParsMyResults (__attribute__((unused)) void *Args); +static void Rec_PutParsStdResults (__attribute__((unused)) void *Args); static void Rec_PutParsWorks (__attribute__((unused)) void *Args); static void Rec_PutParsStudent (__attribute__((unused)) void *Args); static void Rec_PutParsMsgUsr (__attribute__((unused)) void *Args); @@ -1014,7 +1014,7 @@ static void Rec_ShowRecordOneStdCrs (void) switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: - if (Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)) + if (Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod) == Usr_ME) { HTM_DIV_Begin ("class=\"REC_RIGHT\""); Rec_ShowCrsRecord (Rec_CRS_MY_RECORD_AS_STUDENT_FORM,&Gbl.Usrs.Other.UsrDat,NULL); @@ -1143,7 +1143,7 @@ static void Rec_ListRecordsStds (Rec_SharedRecordViewType_t ShaTypeOfView, Gbl.Usrs.Me.Role.Logged == Rol_TCH || Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || (Gbl.Usrs.Me.Role.Logged == Rol_STD && // I am student in this course... - Usr_ItsMe (UsrDat.UsrCod))) // ...and it's me + Usr_ItsMe (UsrDat.UsrCod) == Usr_ME)) // ...and it's me { HTM_DIV_Begin ("class=\"REC_RIGHT\""); Rec_ShowCrsRecord (CrsTypeOfView,&UsrDat,RecordSectionId); @@ -1590,7 +1590,7 @@ static void Rec_ShowCrsRecord (Rec_CourseRecordViewType_t TypeOfView, switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: // I am a student - if (Usr_ItsMe (UsrDat->UsrCod)) + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) { switch (TypeOfView) { @@ -2037,7 +2037,7 @@ void Rec_ShowSharedUsrRecord (Rec_SharedRecordViewType_t TypeOfView, [Rol_SYS_ADM] = NULL, }; char StrRecordWidth[Cns_MAX_DECIMAL_DIGITS_UINT + 1]; - bool ItsMe; + Usr_MeOrOther_t MeOrOther; bool IAmLoggedAsTeacherOrSysAdm; bool CountryForm; bool ICanEdit; @@ -2052,12 +2052,12 @@ void Rec_ShowSharedUsrRecord (Rec_SharedRecordViewType_t TypeOfView, Act_Action_t NextAction; /***** Initializations *****/ - ItsMe = Usr_ItsMe (UsrDat->UsrCod); + MeOrOther = Usr_ItsMe (UsrDat->UsrCod); IAmLoggedAsTeacherOrSysAdm = (Gbl.Usrs.Me.Role.Logged == Rol_NET || // My current role is non-editing teacher Gbl.Usrs.Me.Role.Logged == Rol_TCH || // My current role is teacher Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM); // My current role is system admin CountryForm = (TypeOfView == Rec_SHA_MY_RECORD_FORM); - ShowData = (ItsMe || + ShowData = (MeOrOther == Usr_ME || Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM || UsrDat->Accepted); ShowIDRows = (TypeOfView != Rec_SHA_RECORD_PUBLIC); @@ -2265,19 +2265,21 @@ void Rec_ShowSharedUsrRecord (Rec_SharedRecordViewType_t TypeOfView, case Rec_SHA_OTHER_EXISTING_USR_FORM: /***** Show list of groups to register/remove me/user *****/ if (Gbl.Crs.Grps.NumGrps) // This course has groups? - { - if (ItsMe) + switch (MeOrOther) { - // Don't show groups if I don't belong to course - if (Gbl.Usrs.Me.IBelongToCurrentCrs) - Grp_ShowLstGrpsToChgMyGrps (); + case Usr_ME: + // Don't show groups if I don't belong to course + if (Gbl.Usrs.Me.IBelongToCurrentCrs) + Grp_ShowLstGrpsToChgMyGrps (); + break; + case Usr_OTHER: + default: + Grp_ShowLstGrpsToChgOtherUsrsGrps (UsrDat->UsrCod); + break; } - else // Not me - Grp_ShowLstGrpsToChgOtherUsrsGrps (UsrDat->UsrCod); - } /***** Which action, register or removing? *****/ - if (Enr_PutActionsRegRemOneUsr (ItsMe)) + if (Enr_PutActionsRegRemOneUsr (MeOrOther)) Btn_PutConfirmButton (Txt_Confirm); Frm_EndForm (); @@ -2300,7 +2302,7 @@ void Rec_ShowSharedUsrRecord (Rec_SharedRecordViewType_t TypeOfView, static void Rec_PutIconsCommands (__attribute__((unused)) void *Args) { - bool ItsMe = Usr_ItsMe (Rec_Record.UsrDat->UsrCod); + Usr_MeOrOther_t MeOrOther = Usr_ItsMe (Rec_Record.UsrDat->UsrCod); bool ICanViewUsrProfile; bool RecipientHasBannedMe; static const Act_Action_t NextAction[Rol_NUM_ROLES] = @@ -2316,6 +2318,56 @@ static void Rec_PutIconsCommands (__attribute__((unused)) void *Args) [Rol_INS_ADM] = ActReqMdfOth, [Rol_SYS_ADM] = ActReqMdfOth, }; + static Act_Action_t ActSeeAgd[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = ActSeeMyAgd, + [Usr_OTHER] = ActSeeUsrAgd, + }; + static Act_Action_t ActSeeTstResCrs[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = ActSeeMyTstResCrs, + [Usr_OTHER] = ActSeeUsrTstResCrs, + }; + static Act_Action_t ActSeeExaResCrs[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = ActSeeMyExaResCrs, + [Usr_OTHER] = ActSeeUsrExaResCrs, + }; + static Act_Action_t ActSeeMchResCrs[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = ActSeeMyMchResCrs, + [Usr_OTHER] = ActSeeUsrMchResCrs, + }; + static Act_Action_t ActAdmAsgWrk[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = ActAdmAsgWrkUsr, + [Usr_OTHER] = ActAdmAsgWrkCrs, // Not me, I am not a student in current course + }; + static Act_Action_t ActSeeLstAtt[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = ActSeeLstMyAtt, + [Usr_OTHER] = ActSeeLstUsrAtt, + }; + static void (*FuncPutParsAgd[Usr_NUM_ME_OR_OTHER]) (void *Args) = + { + [Usr_ME ] = NULL, + [Usr_OTHER] = Rec_PutParUsrCodEncrypted, + }; + static void (*FuncPutParsResults[Usr_NUM_ME_OR_OTHER]) (void *Args) = + { + [Usr_ME ] = Rec_PutParsMyResults, + [Usr_OTHER] = Rec_PutParsStdResults, + }; + static void (*FuncPutParsAdmAsgWrk[Usr_NUM_ME_OR_OTHER]) (void *Args) = + { + [Usr_ME ] = NULL, + [Usr_OTHER] = Rec_PutParsWorks, // Not me, I am not a student in current course + }; + static void (*FuncPutParsSeeLstAtt[Usr_NUM_ME_OR_OTHER]) (void *Args) = + { + [Usr_ME ] = NULL, + [Usr_OTHER] = Rec_PutParsStudent, + }; if (!Frm_CheckIfInside () && // Only if not inside another form Act_GetBrowserTab (Gbl.Action.Act) == Act_BRW_1ST_TAB && // Only in main browser tab @@ -2327,13 +2379,14 @@ static void Rec_PutIconsCommands (__attribute__((unused)) void *Args) /***** Begin container *****/ HTM_DIV_Begin ("class=\"FRAME_ICO\""); - if (ItsMe) - /***** Button to edit my record card *****/ + /***** Button to edit my record card *****/ + if (MeOrOther == Usr_ME) Lay_PutContextualLinkOnlyIcon (ActReqEdiRecSha,NULL, NULL,NULL, "pen.svg",Ico_BLACK); + + /***** Button to view user's profile *****/ if (ICanViewUsrProfile) - /***** Button to view user's profile *****/ Lay_PutContextualLinkOnlyIcon (ActSeeOthPubPrf,NULL, Rec_PutParUsrCodEncrypted,NULL, "user.svg",Ico_BLACK); @@ -2345,22 +2398,19 @@ static void Rec_PutIconsCommands (__attribute__((unused)) void *Args) Rec_PutParUsrCodEncrypted,NULL, "address-card.svg",Ico_BLACK); else if (Usr_CheckIfICanViewRecordTch (Rec_Record.UsrDat)) + /* View teacher's record card and timetable */ Lay_PutContextualLinkOnlyIcon (ActSeeRecOneTch,NULL, Rec_PutParUsrCodEncrypted,NULL, "address-card.svg",Ico_BLACK); /***** Button to view user's agenda *****/ - if (ItsMe) - Lay_PutContextualLinkOnlyIcon (ActSeeMyAgd,NULL, - NULL,NULL, - "calendar.svg",Ico_BLACK); - else if (Usr_CheckIfICanViewUsrAgenda (Rec_Record.UsrDat)) - Lay_PutContextualLinkOnlyIcon (ActSeeUsrAgd,NULL, - Rec_PutParUsrCodEncrypted,NULL, + if (Usr_CheckIfICanViewUsrAgenda (Rec_Record.UsrDat)) + Lay_PutContextualLinkOnlyIcon (ActSeeAgd[MeOrOther],NULL, + FuncPutParsAgd[MeOrOther],NULL, "calendar.svg",Ico_BLACK); /***** Button to admin user *****/ - if (ItsMe || + if (MeOrOther == Usr_ME || Gbl.Usrs.Me.Role.Logged == Rol_TCH || Gbl.Usrs.Me.Role.Logged == Rol_DEG_ADM || Gbl.Usrs.Me.Role.Logged == Rol_CTR_ADM || @@ -2377,63 +2427,31 @@ static void Rec_PutIconsCommands (__attribute__((unused)) void *Args) /***** Buttons to view student's test, exam and match results *****/ if (Usr_CheckIfICanViewTstExaMchResult (Rec_Record.UsrDat)) { - if (ItsMe) - { - /* My test results in course */ - Lay_PutContextualLinkOnlyIcon (ActSeeMyTstResCrs,NULL, - Rec_PutParsMyTsts,NULL, - "check.svg",Ico_BLACK); - /* My exam results in course */ - Lay_PutContextualLinkOnlyIcon (ActSeeMyExaResCrs,NULL, - Rec_PutParsMyTsts,NULL, - "file-signature.svg",Ico_BLACK); - /* My match results in course */ - Lay_PutContextualLinkOnlyIcon (ActSeeMyMchResCrs,NULL, - Rec_PutParsMyTsts,NULL, - "gamepad.svg",Ico_BLACK); - } - else // Not me - { - /* User's test results in course */ - Lay_PutContextualLinkOnlyIcon (ActSeeUsrTstResCrs,NULL, - Rec_PutParsStdTsts,NULL, - "check.svg",Ico_BLACK); - /* User's exam results in course */ - Lay_PutContextualLinkOnlyIcon (ActSeeUsrExaResCrs,NULL, - Rec_PutParsStdTsts,NULL, - "file-signature.svg",Ico_BLACK); - /* User's match results in course */ - Lay_PutContextualLinkOnlyIcon (ActSeeUsrMchResCrs,NULL, - Rec_PutParsStdTsts,NULL, - "gamepad.svg",Ico_BLACK); - } + /* Test results in course */ + Lay_PutContextualLinkOnlyIcon (ActSeeTstResCrs[MeOrOther],NULL, + FuncPutParsResults[MeOrOther],NULL, + "check.svg",Ico_BLACK); + /* Exam results in course */ + Lay_PutContextualLinkOnlyIcon (ActSeeExaResCrs[MeOrOther],NULL, + FuncPutParsResults[MeOrOther],NULL, + "file-signature.svg",Ico_BLACK); + /* Match results in course */ + Lay_PutContextualLinkOnlyIcon (ActSeeMchResCrs[MeOrOther],NULL, + FuncPutParsResults[MeOrOther],NULL, + "gamepad.svg",Ico_BLACK); } /***** Button to view student's assignments and works *****/ if (Usr_CheckIfICanViewAsgWrk (Rec_Record.UsrDat)) - { - if (ItsMe) - Lay_PutContextualLinkOnlyIcon (ActAdmAsgWrkUsr,NULL, - NULL,NULL, - "folder-open.svg",Ico_BLACK); - else // Not me, I am not a student in current course - Lay_PutContextualLinkOnlyIcon (ActAdmAsgWrkCrs,NULL, - Rec_PutParsWorks,NULL, - "folder-open.svg",Ico_BLACK); - } + Lay_PutContextualLinkOnlyIcon (ActAdmAsgWrk[MeOrOther],NULL, + FuncPutParsAdmAsgWrk[MeOrOther],NULL, + "folder-open.svg",Ico_BLACK); /***** Button to view student's attendance *****/ if (Usr_CheckIfICanViewAtt (Rec_Record.UsrDat)) - { - if (ItsMe) - Lay_PutContextualLinkOnlyIcon (ActSeeLstMyAtt,NULL, - NULL,NULL, - "calendar-check.svg",Ico_BLACK); - else // Not me - Lay_PutContextualLinkOnlyIcon (ActSeeLstUsrAtt,NULL, - Rec_PutParsStudent,NULL, - "calendar-check.svg",Ico_BLACK); - } + Lay_PutContextualLinkOnlyIcon (ActSeeLstAtt[MeOrOther],NULL, + FuncPutParsSeeLstAtt[MeOrOther],NULL, + "calendar-check.svg",Ico_BLACK); } } @@ -2450,7 +2468,7 @@ static void Rec_PutIconsCommands (__attribute__((unused)) void *Args) "envelope.svg",Ico_BLACK); /***** Button to follow / unfollow *****/ - if (!ItsMe) // Not me + if (MeOrOther == Usr_OTHER) // Not me { if (Fol_DB_CheckUsrIsFollowerOf (Gbl.Usrs.Me.UsrDat.UsrCod, Rec_Record.UsrDat->UsrCod)) @@ -2480,13 +2498,13 @@ void Rec_PutParUsrCodEncrypted (__attribute__((unused)) void *Args) Usr_PutParUsrCodEncrypted (Rec_Record.UsrDat->EnUsrCod); } -static void Rec_PutParsMyTsts (__attribute__((unused)) void *Args) +static void Rec_PutParsMyResults (__attribute__((unused)) void *Args) { Dat_SetIniEndDatesToPastAndNow (); Dat_WriteParsIniEndDates (); } -static void Rec_PutParsStdTsts (__attribute__((unused)) void *Args) +static void Rec_PutParsStdResults (__attribute__((unused)) void *Args) { Rec_PutParsStudent (NULL); Dat_SetIniEndDatesToPastAndNow (); @@ -2615,7 +2633,11 @@ static void Rec_ShowNickname (struct Usr_Data *UsrDat,bool PutFormLinks) { extern const char *Txt_My_public_profile; extern const char *Txt_Another_user_s_profile; - bool ItsMe; + const char *Title[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = Txt_My_public_profile, + [Usr_OTHER] = Txt_Another_user_s_profile + }; HTM_TD_Begin ("class=\"REC_C2_MID LB\""); HTM_DIV_Begin ("class=\"REC_NICK\""); @@ -2624,11 +2646,9 @@ static void Rec_ShowNickname (struct Usr_Data *UsrDat,bool PutFormLinks) if (PutFormLinks) { /* Put form to go to public profile */ - ItsMe = Usr_ItsMe (UsrDat->UsrCod); Frm_BeginForm (ActSeeOthPubPrf); Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod); - HTM_BUTTON_Submit_Begin (ItsMe ? Txt_My_public_profile : - Txt_Another_user_s_profile, + HTM_BUTTON_Submit_Begin (Title[Usr_ItsMe (UsrDat->UsrCod)], "class=\"BT_LINK\""); } HTM_TxtF ("@%s",UsrDat->Nickname); diff --git a/swad_string.c b/swad_string.c index 5ff45c50..745c0630 100644 --- a/swad_string.c +++ b/swad_string.c @@ -340,7 +340,7 @@ void Str_AnalyzeTxtAndStoreNotifyEventToMentionedUsrs (long PubCod,const char *T UsrDat.Nickname[Nickname.Length] = '\0'; if ((UsrDat.UsrCod = Nck_GetUsrCodFromNickname (UsrDat.Nickname)) > 0) - if (!Usr_ItsMe (UsrDat.UsrCod)) // Not me + if (Usr_ItsMe (UsrDat.UsrCod) == Usr_OTHER) // Not me { /* Get user's data */ Usr_GetAllUsrDataFromUsrCod (&UsrDat, diff --git a/swad_test_print.c b/swad_test_print.c index 48fd62d1..ded35abc 100644 --- a/swad_test_print.c +++ b/swad_test_print.c @@ -162,7 +162,7 @@ static void TstPrn_PutFormToSelectUsrsToViewUsrsPrints (__attribute__((unused)) static void TstPrn_ShowUsrsPrints (__attribute__((unused)) void *Args); static void TstPrn_ShowHeaderPrints (Usr_MeOrOther_t MeOrOther); static void TstPrn_ShowUsrPrints (struct Usr_Data *UsrDat); -static void TstPrn_ShowPrintsSummaryRow (bool ItsMe, +static void TstPrn_ShowPrintsSummaryRow (Usr_MeOrOther_t MeOrOther, unsigned NumPrints, struct TstPrn_NumQuestions *NumTotalQsts, double TotalScore); @@ -2024,7 +2024,8 @@ static void TstPrn_ShowUsrPrints (struct Usr_Data *UsrDat) } /***** Write totals for this user *****/ - TstPrn_ShowPrintsSummaryRow (Usr_ItsMe (UsrDat->UsrCod),NumPrintsVisibleByTchs, + TstPrn_ShowPrintsSummaryRow (Usr_ItsMe (UsrDat->UsrCod), + NumPrintsVisibleByTchs, &NumTotalQsts,TotalScore); } else @@ -2072,7 +2073,7 @@ static void TstPrn_ShowUsrPrints (struct Usr_Data *UsrDat) /****************** Show row with summary of user's tess *********************/ /*****************************************************************************/ -static void TstPrn_ShowPrintsSummaryRow (bool ItsMe, +static void TstPrn_ShowPrintsSummaryRow (Usr_MeOrOther_t MeOrOther, unsigned NumPrints, struct TstPrn_NumQuestions *NumTotalQsts, double TotalScore) @@ -2083,7 +2084,7 @@ static void TstPrn_ShowPrintsSummaryRow (bool ItsMe, switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: - ICanViewTotalScore = ItsMe && + ICanViewTotalScore = MeOrOther == Usr_ME && TstVis_IsVisibleTotalScore (TstCfg_GetConfigVisibility ()); break; case Rol_NET: @@ -2091,7 +2092,7 @@ static void TstPrn_ShowPrintsSummaryRow (bool ItsMe, case Rol_DEG_ADM: case Rol_CTR_ADM: case Rol_INS_ADM: - ICanViewTotalScore = ItsMe || + ICanViewTotalScore = MeOrOther == Usr_ME || NumPrints; break; case Rol_SYS_ADM: @@ -2414,7 +2415,7 @@ static void TstRes_CheckIfICanSeePrintResult (const struct TstPrn_Print *Print, case Rol_STD: // Depends on whether the print is sent or not // if the print is not sent ==> I can not view results - ICanView->Result = Print->Sent && Usr_ItsMe (UsrCod); + ICanView->Result = Print->Sent && Usr_ItsMe (UsrCod) == Usr_ME; if (ICanView->Result) // Depends on 5 visibility icons associated to tests @@ -2431,7 +2432,8 @@ static void TstRes_CheckIfICanSeePrintResult (const struct TstPrn_Print *Print, // if the print is not sent ==> I can not view results // if teachers are not allowed ==> I can not view results (except if the print is mine) ICanView->Result = - ICanView->Score = Print->Sent && (Print->AllowTeachers || Usr_ItsMe (UsrCod)); + ICanView->Score = Print->Sent && + (Print->AllowTeachers || Usr_ItsMe (UsrCod) == Usr_ME); break; case Rol_SYS_ADM: ICanView->Result = diff --git a/swad_text_action.c b/swad_text_action.c index 449adc06..28d2563e 100644 --- a/swad_text_action.c +++ b/swad_text_action.c @@ -26742,7 +26742,7 @@ const char *Txt_Actions[ActLst_NUM_ACTIONS] = "Send teacher's photo and detect faces on it" // Çeviri lazim! #endif , - [ActUpdOthPho] = + [ActChgOthPho] = #if L==1 // ca "Update a user's photo" // Necessita traducció #elif L==2 // de @@ -26765,7 +26765,7 @@ const char *Txt_Actions[ActLst_NUM_ACTIONS] = "Update a user's photo" // Çeviri lazim! #endif , - [ActUpdStdPho] = + [ActChgStdPho] = #if L==1 // ca "Update a student's photo" // Necessita traducció #elif L==2 // de @@ -26788,7 +26788,7 @@ const char *Txt_Actions[ActLst_NUM_ACTIONS] = "Update a student's photo" // Çeviri lazim! #endif , - [ActUpdTchPho] = + [ActChgTchPho] = #if L==1 // ca "Update a teacher's photo" // Necessita traducció #elif L==2 // de @@ -27685,7 +27685,7 @@ const char *Txt_Actions[ActLst_NUM_ACTIONS] = "Forms to the change a teacher's account" // Çeviri lazim! #endif , - [ActRemOldNicOth] = + [ActRemNicOth] = #if L==1 // ca "Remove user's nickname" // Necessita traducció #elif L==2 // de @@ -27708,7 +27708,7 @@ const char *Txt_Actions[ActLst_NUM_ACTIONS] = "Remove user's nickname" // Çeviri lazim! #endif , - [ActRemOldNicStd] = + [ActRemNicStd] = #if L==1 // ca "Remove student's nickname" // Necessita traducció #elif L==2 // de @@ -27731,7 +27731,7 @@ const char *Txt_Actions[ActLst_NUM_ACTIONS] = "Remove student's nickname" // Çeviri lazim! #endif , - [ActRemOldNicTch] = + [ActRemNicTch] = #if L==1 // ca "Remove teacher's nickname" // Necessita traducció #elif L==2 // de @@ -27892,7 +27892,7 @@ const char *Txt_Actions[ActLst_NUM_ACTIONS] = "Remove teacher's ID" // Çeviri lazim! #endif , - [ActNewID_Oth] = + [ActChgID_Oth] = #if L==1 // ca "Create new user's ID" // Necessita traducció #elif L==2 // de @@ -27915,7 +27915,7 @@ const char *Txt_Actions[ActLst_NUM_ACTIONS] = "Create new user's ID" // Çeviri lazim! #endif , - [ActNewID_Std] = + [ActChgID_Std] = #if L==1 // ca "Create new student's ID" // Necessita traducció #elif L==2 // de @@ -27938,7 +27938,7 @@ const char *Txt_Actions[ActLst_NUM_ACTIONS] = "Create new student's ID" // Çeviri lazim! #endif , - [ActNewID_Tch] = + [ActChgID_Tch] = #if L==1 // ca "Create new teacher's ID" // Necessita traducció #elif L==2 // de @@ -28099,7 +28099,7 @@ const char *Txt_Actions[ActLst_NUM_ACTIONS] = "Remove teacher's email" // Çeviri lazim! #endif , - [ActNewMaiOth] = + [ActChgMaiOth] = #if L==1 // ca "Create new user's email" // Necessita traducció #elif L==2 // de @@ -28122,7 +28122,7 @@ const char *Txt_Actions[ActLst_NUM_ACTIONS] = "Create new user's email" // Çeviri lazim! #endif , - [ActNewMaiStd] = + [ActChgMaiStd] = #if L==1 // ca "Create new student's email" // Necessita traducció #elif L==2 // de @@ -28145,7 +28145,7 @@ const char *Txt_Actions[ActLst_NUM_ACTIONS] = "Create new student's email" // Çeviri lazim! #endif , - [ActNewMaiTch] = + [ActChgMaiTch] = #if L==1 // ca "Create new teacher's email" // Necessita traducció #elif L==2 // de diff --git a/swad_timeline.c b/swad_timeline.c index e55a1a44..f6f3fbf1 100644 --- a/swad_timeline.c +++ b/swad_timeline.c @@ -427,7 +427,7 @@ static void Tml_ShowTimeline (struct Tml_Timeline *Timeline, TmlWho_PutFormWho (Timeline); /***** Form to write a new post *****/ - if (GlobalTimeline || Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)) + if (GlobalTimeline || Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod) == Usr_ME) TmlPst_PutPhotoAndFormToWriteNewPost (Timeline); /***** New publications refreshed dynamically via AJAX *****/ diff --git a/swad_timeline_comment.c b/swad_timeline_comment.c index 1f5cb2c8..aa0570d0 100644 --- a/swad_timeline_comment.c +++ b/swad_timeline_comment.c @@ -615,6 +615,11 @@ static void TmlCom_WriteAuthorName (const struct Usr_Data *UsrDat) // Author { extern const char *Txt_My_public_profile; extern const char *Txt_Another_user_s_profile; + const char *Title[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = Txt_My_public_profile, + [Usr_OTHER] = Txt_Another_user_s_profile, + }; /***** Show user's name inside form to go to user's public profile *****/ /* Begin form */ @@ -622,8 +627,7 @@ static void TmlCom_WriteAuthorName (const struct Usr_Data *UsrDat) // Author Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod); /* Author's name */ - HTM_BUTTON_Submit_Begin (Usr_ItsMe (UsrDat->UsrCod) ? Txt_My_public_profile : - Txt_Another_user_s_profile, + HTM_BUTTON_Submit_Begin (Title[Usr_ItsMe (UsrDat->UsrCod)], "class=\"Tml_COM_AUTHOR Tml_COM_AUTHOR_WIDTH BT_LINK DAT_%s BOLD\"", The_GetSuffix ()); HTM_Txt (UsrDat->FullName); @@ -678,7 +682,7 @@ static void TmlCom_WriteButtons (const struct Tml_Timeline *Timeline, /***** Foot column 2: icon to remove this comment *****/ HTM_DIV_Begin ("class=\"Tml_REM\""); - if (Usr_ItsMe (UsrDat->UsrCod)) // I am the author + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) // I am the author TmlCom_PutFormToRemoveComm (Timeline,Com->PubCod); HTM_DIV_End (); @@ -990,8 +994,8 @@ static void TmlCom_RemoveComm (void) return; } - /***** Trivial check 2: only if I am the author of this comment *****/ - if (!Usr_ItsMe (Com.UsrCod)) + /***** Trivial check 2: only if I am the author of this comment? *****/ + if (Usr_ItsMe (Com.UsrCod) == Usr_OTHER) { Med_MediaDestructor (&Com.Content.Media); Err_NoPermission (); diff --git a/swad_timeline_note.c b/swad_timeline_note.c index 4f0e2e02..b3918a13 100644 --- a/swad_timeline_note.c +++ b/swad_timeline_note.c @@ -351,6 +351,11 @@ void TmlNot_WriteAuthorName (const struct Usr_Data *UsrDat, { extern const char *Txt_My_public_profile; extern const char *Txt_Another_user_s_profile; + const char *Title[Usr_NUM_ME_OR_OTHER] = + { + [Usr_ME ] = Txt_My_public_profile, + [Usr_OTHER] = Txt_Another_user_s_profile, + }; /***** Show user's name inside form to go to user's public profile *****/ /* Begin form */ @@ -358,8 +363,7 @@ void TmlNot_WriteAuthorName (const struct Usr_Data *UsrDat, Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod); /* Author's name */ - HTM_BUTTON_Submit_Begin (Usr_ItsMe (UsrDat->UsrCod) ? Txt_My_public_profile : - Txt_Another_user_s_profile, + HTM_BUTTON_Submit_Begin (Title[Usr_ItsMe (UsrDat->UsrCod)], "class=\"%s\"",Class); HTM_Txt (UsrDat->FullName); HTM_BUTTON_End (); @@ -847,7 +851,7 @@ static void TmlNot_WriteFavShaRem (const struct Tml_Timeline *Timeline, /***** Foot column 3: icon to remove this note *****/ HTM_DIV_Begin ("class=\"Tml_REM\""); - if (Usr_ItsMe (UsrDat->UsrCod)) // I am the author + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) // I am the author TmlNot_PutFormToRemoveNote (Timeline,Not->NotCod); HTM_DIV_End (); @@ -1115,8 +1119,8 @@ static void TmlNot_RemoveNote (void) return; } - /***** Trivial check 2: Am I the author of this note *****/ - if (!Usr_ItsMe (Not.UsrCod)) + /***** Trivial check 2: Am I the author of this note? *****/ + if (Usr_ItsMe (Not.UsrCod) == Usr_OTHER) { Err_NoPermission (); return; diff --git a/swad_timeline_user.c b/swad_timeline_user.c index 4ee0d380..6b4e613a 100644 --- a/swad_timeline_user.c +++ b/swad_timeline_user.c @@ -292,10 +292,16 @@ void TmlUsr_PutIconFavSha (TmlUsr_FavSha_t FavSha, HTM_DIV_Begin ("class=\"Tml_ICO\""); /* Icon to fav/unfav or share/unshare this note/comment */ - if (Usr_ItsMe (UsrCod)) // I am the author ==> I can not fav/unfav or share/unshare - TmlUsr_PutDisabledIconFavSha (FavSha,NumUsrs); - else // I am not the author - TmlFrm_PutFormToFavUnfShaUns (FavSha,Cod); + switch (Usr_ItsMe (UsrCod)) + { + case Usr_ME: // I am the author ==> I can not fav/unfav or share/unshare + TmlUsr_PutDisabledIconFavSha (FavSha,NumUsrs); + break; + case Usr_OTHER: // I am not the author + default: + TmlFrm_PutFormToFavUnfShaUns (FavSha,Cod); + break; + } /* End container */ HTM_DIV_End (); @@ -385,7 +391,7 @@ bool TmlUsr_CheckIfICanFavSha (long Cod,long UsrCod) /***** Trivial check 2: I must be logged I can not fav/share my own notes/comments *****/ - if (!Gbl.Usrs.Me.Logged || Usr_ItsMe (UsrCod)) + if (!Gbl.Usrs.Me.Logged || Usr_ItsMe (UsrCod) == Usr_ME) { Err_NoPermission (); return false; @@ -411,7 +417,7 @@ bool TmlUsr_CheckIfICanRemove (long Cod,long UsrCod) /***** Trivial check 2: I must be logged I can only remove my own notes/comments *****/ - if (!Gbl.Usrs.Me.Logged || !Usr_ItsMe (UsrCod)) + if (!Gbl.Usrs.Me.Logged || Usr_ItsMe (UsrCod) == Usr_OTHER) { Err_NoPermission (); return false; diff --git a/swad_user.c b/swad_user.c index f5efc409..2e40183b 100644 --- a/swad_user.c +++ b/swad_user.c @@ -426,10 +426,11 @@ void Usr_FreeListUsrCods (struct Usr_ListUsrCods *ListUsrCods) /************************ Check if I am a given user *************************/ /*****************************************************************************/ -bool Usr_ItsMe (long UsrCod) +Usr_MeOrOther_t Usr_ItsMe (long UsrCod) { - return Gbl.Usrs.Me.Logged && - (UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod); + return (Gbl.Usrs.Me.Logged && + UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) ? Usr_ME : + Usr_OTHER; } /*****************************************************************************/ @@ -768,7 +769,7 @@ bool Usr_CheckIfUsrIsSuperuser (long UsrCod) bool Usr_ICanChangeOtherUsrData (const struct Usr_Data *UsrDat) { /***** I can change my data *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) return true; /***** Check if I have permission to see another user's IDs *****/ @@ -801,7 +802,7 @@ bool Usr_ICanChangeOtherUsrData (const struct Usr_Data *UsrDat) bool Usr_ICanEditOtherUsr (const struct Usr_Data *UsrDat) { /***** I can edit me *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) return true; switch (Gbl.Usrs.Me.Role.Logged) @@ -868,7 +869,7 @@ bool Usr_CheckIfICanViewRecordStd (const struct Usr_Data *UsrDat) return false; /***** 7. Fast check: It's me? *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) return true; /***** 8. Fast / slow check: Does he/she belong to the current course? *****/ @@ -941,7 +942,7 @@ bool Usr_CheckIfICanViewTstExaMchResult (const struct Usr_Data *UsrDat) return false; /***** 6. Fast check: It's me? *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) return true; /***** 7. Fast check: Does he/she belong to the current course? *****/ @@ -992,7 +993,7 @@ bool Usr_CheckIfICanViewAsgWrk (const struct Usr_Data *UsrDat) return false; /***** 7. Fast check: It's me? *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) return true; /***** 8. Fast / slow check depending on roles *****/ @@ -1034,7 +1035,7 @@ bool Usr_CheckIfICanViewAtt (const struct Usr_Data *UsrDat) return false; /***** 6. Fast check: It's me? *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) return true; /***** 7. Fast / slow check depending on roles *****/ @@ -1060,7 +1061,7 @@ bool Usr_CheckIfICanViewUsrAgenda (struct Usr_Data *UsrDat) return false; /***** 2. Fast check: It's me? *****/ - if (Usr_ItsMe (UsrDat->UsrCod)) + if (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME) return true; /***** 3. Fast check: Am I logged as system admin? *****/ @@ -2466,7 +2467,7 @@ static void Usr_WriteRowTchAllData (struct Usr_Data *UsrDat) struct Ins_Instit Ins; struct Ctr_Center Ctr; struct Dpt_Department Dpt; - bool ShowData = (Usr_ItsMe (UsrDat->UsrCod) || UsrDat->Accepted || + bool ShowData = (Usr_ItsMe (UsrDat->UsrCod) == Usr_ME || UsrDat->Accepted || Gbl.Usrs.Me.Role.Logged == Rol_DEG_ADM || Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM); diff --git a/swad_user.h b/swad_user.h index 72bf1dee..2cf7b55d 100644 --- a/swad_user.h +++ b/swad_user.h @@ -137,6 +137,7 @@ typedef enum } Usr_ListUsrsOption_t; #define Usr_LIST_USRS_DEFAULT_OPTION Usr_OPTION_RECORDS +#define Usr_NUM_ME_OR_OTHER 2 typedef enum { Usr_ME, @@ -287,7 +288,7 @@ void Usr_GetAllUsrDataFromUsrCod (struct Usr_Data *UsrDat, Usr_GetRoleInCurrentCrs_t GetRoleInCurrentCrs); void Usr_AllocateListUsrCods (struct Usr_ListUsrCods *ListUsrCods); void Usr_FreeListUsrCods (struct Usr_ListUsrCods *ListUsrCods); -bool Usr_ItsMe (long UsrCod); +Usr_MeOrOther_t Usr_ItsMe (long UsrCod); void Usr_GetUsrCodFromEncryptedUsrCod (struct Usr_Data *UsrDat); void Usr_GetUsrDataFromUsrCod (struct Usr_Data *UsrDat, Usr_GetPrefs_t GetPrefs,