From 5d1eca20fdc7171393aa3efde205fe175bea4acd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Sat, 17 Dec 2016 21:36:57 +0100 Subject: [PATCH] Version 16.103.23 --- swad_changelog.h | 3 +- swad_enrollment.c | 116 ++++++++++++++++++++++++++-------------------- swad_enrollment.h | 4 +- 3 files changed, 70 insertions(+), 53 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index b3a832f97..385d1c39a 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -190,13 +190,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.103.2 (2016-12-17)" +#define Log_PLATFORM_VERSION "SWAD 16.103.3 (2016-12-17)" #define CSS_FILE "swad16.103.1.css" #define JS_FILE "swad16.101.js" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1 /* + Version 16.103.3: Dec 17, 2016 Code refactoring in user enrollment. (211149 lines) Version 16.103.2: Dec 17, 2016 Code refactoring in user enrollment. (211133 lines) Version 16.103.1: Dec 16, 2016 Changes in layout of tabs. (211123 lines) Version 16.103: Dec 16, 2016 Contextual help on course info. (211130 lines) diff --git a/swad_enrollment.c b/swad_enrollment.c index cf9992176..16bb32e32 100644 --- a/swad_enrollment.c +++ b/swad_enrollment.c @@ -166,54 +166,34 @@ void Enr_PutLinkToRequestSignUp (void) /***************** Modify the role of a user in a course *********************/ /*****************************************************************************/ -void Enr_ModifyRoleInCurrentCrs (struct UsrData *UsrDat, - Rol_Role_t NewRole, - Cns_QuietOrVerbose_t QuietOrVerbose) +void Enr_ModifyRoleInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole) { - 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]; char Query[256]; - Rol_Role_t OldRole; - /***** Change user's role if different *****/ - OldRole = Rol_GetRoleInCrs (Gbl.CurrentCrs.Crs.CrsCod,UsrDat->UsrCod); - if (NewRole != OldRole) // The role must be updated + /***** Check if user's role is allowed *****/ + switch (NewRole) { - /***** Check if user's role is allowed *****/ - switch (NewRole) - { - case Rol_STUDENT: - case Rol_TEACHER: - break; - default: - Lay_ShowErrorAndExit ("Wrong role."); - } - - /***** Update the role of a user in a course *****/ - sprintf (Query,"UPDATE crs_usr SET Role='%u'" - " WHERE CrsCod='%ld' AND UsrCod='%ld'", - (unsigned) NewRole,Gbl.CurrentCrs.Crs.CrsCod,UsrDat->UsrCod); - DB_QueryUPDATE (Query,"can not modify user's role in course"); - - /***** Create notification for this user. - If this user wants to receive notifications by email, - activate the sending of a notification *****/ - Enr_NotifyAfterEnrollment (UsrDat,NewRole); - - /***** Show info message *****/ - if (QuietOrVerbose == Cns_VERBOSE) - { - sprintf (Gbl.Message,Txt_The_role_of_THE_USER_X_in_the_course_Y_has_changed_from_A_to_B, - UsrDat->FullName,Gbl.CurrentCrs.Crs.FullName, - Txt_ROLES_SINGUL_abc[OldRole][UsrDat->Sex], - Txt_ROLES_SINGUL_abc[NewRole][UsrDat->Sex]); - Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); - } - - UsrDat->RoleInCurrentCrsDB = NewRole; - UsrDat->Roles = -1; // Force roles to be got from database - Rol_GetRolesInAllCrssIfNotYetGot (UsrDat); // Get roles + case Rol_STUDENT: + case Rol_TEACHER: + break; + default: + Lay_ShowErrorAndExit ("Wrong role."); } + + /***** Update the role of a user in a course *****/ + sprintf (Query,"UPDATE crs_usr SET Role='%u'" + " WHERE CrsCod='%ld' AND UsrCod='%ld'", + (unsigned) NewRole,Gbl.CurrentCrs.Crs.CrsCod,UsrDat->UsrCod); + DB_QueryUPDATE (Query,"can not modify user's role in course"); + + /***** Create notification for this user. + If this user wants to receive notifications by email, + activate the sending of a notification *****/ + Enr_NotifyAfterEnrollment (UsrDat,NewRole); + + UsrDat->RoleInCurrentCrsDB = NewRole; + UsrDat->Roles = -1; // Force roles to be got from database + Rol_GetRolesInAllCrssIfNotYetGot (UsrDat); // Get roles } /*****************************************************************************/ @@ -1635,8 +1615,12 @@ static void Enr_RegisterUsr (struct UsrData *UsrDat,Rol_Role_t RegRemRole, { if (Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod, Gbl.CurrentCrs.Crs.CrsCod, - false)) // User does belong to current course, modify his/her role - Enr_ModifyRoleInCurrentCrs (UsrDat,RegRemRole,Cns_QUIET); + false)) // User does belong to current course + { + if (RegRemRole != UsrDat->RoleInCurrentCrsDB) // The role must be updated + /* Modify role */ + Enr_ModifyRoleInCurrentCrs (UsrDat,RegRemRole); + } else /* Register user */ Enr_RegisterUsrInCurrentCrs (UsrDat,RegRemRole, @@ -3466,8 +3450,11 @@ void Enr_AcceptRegisterMeInCrs (void) void Enr_CreateNewUsr (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_enrolled_in_the_course_Y; extern const char *Txt_The_ID_X_is_not_valid; + Rol_Role_t OldRole; Rol_Role_t NewRole; /***** Get user's ID from form *****/ @@ -3496,8 +3483,22 @@ void Enr_CreateNewUsr (void) { if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod, Gbl.CurrentCrs.Crs.CrsCod, - false)) // User does belong to current course, modify his/her role - Enr_ModifyRoleInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,Cns_VERBOSE); + false)) // User does belong to current course + { + OldRole = Gbl.Usrs.Other.UsrDat.RoleInCurrentCrsDB; // Remember old role before changing it + if (NewRole != OldRole) // The role must be updated + { + /* Modify role */ + Enr_ModifyRoleInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole); + + /* Show success message */ + sprintf (Gbl.Message,Txt_The_role_of_THE_USER_X_in_the_course_Y_has_changed_from_A_to_B, + Gbl.Usrs.Other.UsrDat.FullName,Gbl.CurrentCrs.Crs.FullName, + Txt_ROLES_SINGUL_abc[OldRole][Gbl.Usrs.Other.UsrDat.Sex], + Txt_ROLES_SINGUL_abc[NewRole][Gbl.Usrs.Other.UsrDat.Sex]); + Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); + } + } else { /* Register user */ @@ -3533,12 +3534,15 @@ void Enr_CreateNewUsr (void) void Enr_ModifyUsr (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_enrolled_in_the_course_Y; extern const char *Txt_User_not_found_or_you_do_not_have_permission_; char UnsignedStr[10+1]; unsigned UnsignedNum; bool ItsMe; Enr_RegRemOneUsrAction_t RegRemAction; + Rol_Role_t OldRole; Rol_Role_t NewRole; bool Error = false; @@ -3571,8 +3575,22 @@ void Enr_ModifyUsr (void) /***** Register user in current course in database *****/ if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod, Gbl.CurrentCrs.Crs.CrsCod, - false)) // User does belong to current course, modify his/her role - Enr_ModifyRoleInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,Cns_VERBOSE); + false)) // User does belong to current course + { + OldRole = Gbl.Usrs.Other.UsrDat.RoleInCurrentCrsDB; // Remember old role before changing it + if (NewRole != OldRole) // The role must be updated + { + /* Modify role */ + Enr_ModifyRoleInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole); + + /* Show success message */ + sprintf (Gbl.Message,Txt_The_role_of_THE_USER_X_in_the_course_Y_has_changed_from_A_to_B, + Gbl.Usrs.Other.UsrDat.FullName,Gbl.CurrentCrs.Crs.FullName, + Txt_ROLES_SINGUL_abc[OldRole][Gbl.Usrs.Other.UsrDat.Sex], + Txt_ROLES_SINGUL_abc[NewRole][Gbl.Usrs.Other.UsrDat.Sex]); + Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); + } + } else { /* Register user */ diff --git a/swad_enrollment.h b/swad_enrollment.h index 68ea1a028..6bb0af380 100644 --- a/swad_enrollment.h +++ b/swad_enrollment.h @@ -72,9 +72,7 @@ void Enr_PutButtonToEnrollStudents (void); void Enr_PutLinkToRequestSignUp (void); -void Enr_ModifyRoleInCurrentCrs (struct UsrData *UsrDat, - Rol_Role_t NewRole, - Cns_QuietOrVerbose_t QuietOrVerbose); +void Enr_ModifyRoleInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole); void Enr_RegisterUsrInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole, Enr_KeepOrSetAccepted_t KeepOrSetAccepted);