From cb1736819c7fc18f3eda51a682fe32f17d4a1c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Wed, 16 Sep 2015 19:22:32 +0200 Subject: [PATCH] Version 14.132.1 --- swad_changelog.h | 3 +- swad_enrollment.c | 20 +++++------ swad_file_browser.c | 4 +-- swad_photo.c | 18 +++++----- swad_record.c | 4 +-- swad_test.c | 2 +- swad_user.c | 85 +++++++++++++++++++++++++++++++++------------ swad_user.h | 6 ++-- swad_web_service.c | 2 +- 9 files changed, 94 insertions(+), 50 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index d7d264779..4074beaf9 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -98,11 +98,12 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 14.132 (2015/09/16)" +#define Log_PLATFORM_VERSION "SWAD 14.132.1 (2015/09/16)" // 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 14.132.1: Sep 16, 2015 Changes in user enrollment. (184458 lines) Version 14.132: Sep 16, 2015 Changes in user enrollment. (184416 lines) 4 changes necessary in database: UPDATE actions SET Obsolete='Y' WHERE ActCod='375'; diff --git a/swad_enrollment.c b/swad_enrollment.c index 625f8de10..e2a4129c3 100644 --- a/swad_enrollment.c +++ b/swad_enrollment.c @@ -797,7 +797,7 @@ bool Enr_PutActionsRegRemOneUsr (bool ItsMe) /***** Check if the other user belongs to the current course *****/ if (Gbl.CurrentCrs.Crs.CrsCod > 0) - UsrBelongsToCrs = Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod); + UsrBelongsToCrs = Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod,false); if (Gbl.CurrentIns.Ins.InsCod > 0) { @@ -1609,7 +1609,7 @@ static void Enr_RegisterUsr (struct UsrData *UsrDat,Rol_Role_t RegRemRole, /***** Register user in current course in database *****/ if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected { - if (Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod,Gbl.CurrentCrs.Crs.CrsCod)) // User does belong to current course, modify his/her role + 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); else Enr_RegisterUsrInCurrentCrs (UsrDat,RegRemRole,Cns_QUIET, @@ -1982,7 +1982,7 @@ void Enr_AskIfRejectSignUp (void) if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) // If user's data exist... { - if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod)) + if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod,false)) { /* User already belongs to this course */ sprintf (Gbl.Message,Txt_THE_USER_X_is_already_enrolled_in_the_course_Y, @@ -2037,7 +2037,7 @@ void Enr_RejectSignUp (void) if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) // If user's data exist... { - if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod)) + if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod,false)) { /* User already belongs to this course */ sprintf (Gbl.Message,Txt_THE_USER_X_is_already_enrolled_in_the_course_Y, @@ -2406,7 +2406,7 @@ void Enr_ShowEnrollmentRequests (void) DesiredRole = Rol_ConvertUnsignedStrToRole (row[3]); if (UsrExists) - UsrBelongsToCrs = Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod,Crs.CrsCod); + UsrBelongsToCrs = Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod,Crs.CrsCod,false); else UsrBelongsToCrs = false; @@ -2751,7 +2751,7 @@ static void Enr_AskIfRegRemUsr (struct ListUsrCods *ListUsrCods,Rol_Role_t Role) if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected { /* Check if this user belongs to the current course */ - if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod)) + if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod,false)) { Gbl.Usrs.Other.UsrDat.Accepted = Usr_GetIfUserHasAcceptedEnrollmentInCurrentCrs (Gbl.Usrs.Other.UsrDat.UsrCod); if (Gbl.Usrs.Other.UsrDat.Accepted) @@ -3218,7 +3218,7 @@ void Enr_CreateNewUsr (void) /***** Register user in current course in database *****/ if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected { - if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod)) // User does belong to current course, modify his/her role + 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); else Enr_RegisterUsrInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,Cns_VERBOSE, @@ -3282,7 +3282,7 @@ void Enr_ModifyUsr (void) NewRole = Rec_GetRoleFromRecordForm (); /***** Register user in current course in database *****/ - if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod)) // User does belong to current course, modify his/her role + 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); else Enr_RegisterUsrInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,Cns_VERBOSE, @@ -3398,7 +3398,7 @@ static void Enr_AskIfRemoveUsrFromCrs (struct UsrData *UsrDat,bool ItsMe) extern const char *Txt_Remove_user_from_this_course; extern const char *Txt_User_not_found_or_you_do_not_have_permission_; - if (Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod,Gbl.CurrentCrs.Crs.CrsCod)) + if (Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod,Gbl.CurrentCrs.Crs.CrsCod,false)) { sprintf (Gbl.Message, ItsMe ? Txt_Do_you_really_want_to_be_removed_from_the_course_X : @@ -3432,7 +3432,7 @@ static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat,struct Course * extern const char *Txt_User_not_found_or_you_do_not_have_permission_; char Query[1024]; - if (Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod,Crs->CrsCod)) // User belongs to the course + if (Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod,Crs->CrsCod,false)) // User belongs to the course { /***** Remove user from all the attendance events in course *****/ Att_RemoveUsrFromCrsAttEvents (UsrDat->UsrCod,Crs->CrsCod); diff --git a/swad_file_browser.c b/swad_file_browser.c index eb007eb4e..c162591f2 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -2938,7 +2938,7 @@ static void Brw_ShowFileBrowsersAsgWrkCrs (void) Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat); if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // Get user's data from database - if (Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod)) + if (Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod,false)) ZIP_CreateDirCompressionUsr (&UsrDat); } @@ -2967,7 +2967,7 @@ static void Brw_ShowFileBrowsersAsgWrkCrs (void) Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat); if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) // Get of the database the data of the user - if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod)) + if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod,false)) { /***** Show a row with the data of the owner of the works *****/ fprintf (Gbl.F.Out,""); diff --git a/swad_photo.c b/swad_photo.c index 7d733720e..487685d69 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -128,24 +128,26 @@ bool Pho_CheckIfICanChangeOtherUsrPhoto (const struct UsrData *UsrDat) if (UsrDat->UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // It's me return true; - /* Check if I have permission to change user's photo */ + /* Check if I have permission to change user's photo + Only users who have accepted registration in courses are counted */ switch (Gbl.Usrs.Me.LoggedRole) { case Rol_TEACHER: /* If I am a teacher in current course, - I only can change the photo of confirmed students or teachers from current course */ + I only can change the photo of users from current course */ return UsrDat->Accepted; case Rol_DEG_ADM: /* If I am an administrator of current degree, I only can change the photo of users from current degree */ - return Usr_CheckIfUsrBelongsToDeg (UsrDat->UsrCod,Gbl.CurrentDeg.Deg.DegCod); - // TODO: Only confirmed users? + return Usr_CheckIfUsrBelongsToDeg (UsrDat->UsrCod,Gbl.CurrentDeg.Deg.DegCod,true); case Rol_CTR_ADM: - // TODO: Implement - return false; + /* If I am an administrator of current centre, + I only can change the photo of users from current centre */ + return Usr_CheckIfUsrBelongsToCtr (UsrDat->UsrCod,Gbl.CurrentCtr.Ctr.CtrCod,true); case Rol_INS_ADM: - // TODO: Implement - return false; + /* If I am an administrator of current institution, + I only can change the photo of users from current institution */ + return Usr_CheckIfUsrBelongsToIns (UsrDat->UsrCod,Gbl.CurrentIns.Ins.InsCod,true); case Rol_SYS_ADM: return true; default: diff --git a/swad_record.c b/swad_record.c index ee8b629ad..f20ed1e59 100644 --- a/swad_record.c +++ b/swad_record.c @@ -1071,7 +1071,7 @@ void Rec_ListRecordsStdsCrs (void) Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat); if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // Get from the database the data of the student - if (Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod)) + if (Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod,false)) { UsrDat.Accepted = Usr_GetIfUserHasAcceptedEnrollmentInCurrentCrs (UsrDat.UsrCod); @@ -1240,7 +1240,7 @@ void Rec_ListRecordsTchsCrs (void) Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat); if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // Get from the database the data of the student - if (Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod)) + if (Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod,false)) { UsrDat.Accepted = Usr_GetIfUserHasAcceptedEnrollmentInCurrentCrs (UsrDat.UsrCod); diff --git a/swad_test.c b/swad_test.c index 21f9ffb00..4e305c842 100644 --- a/swad_test.c +++ b/swad_test.c @@ -6041,7 +6041,7 @@ void Tst_ShowUsrsTestResults (void) Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat); if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) // Get of the database the data of the user - if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod)) + if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod,false)) /***** Show the result of test exams *****/ Tst_ShowResultsOfTestExams (&Gbl.Usrs.Other.UsrDat); } diff --git a/swad_user.c b/swad_user.c index 37cd39148..ef5c2b8de 100644 --- a/swad_user.c +++ b/swad_user.c @@ -1009,43 +1009,80 @@ void Usr_GetMyCourses (void) } } +/*****************************************************************************/ +/**************** Check if a user belongs to an institution ******************/ +/*****************************************************************************/ + +bool Usr_CheckIfUsrBelongsToIns (long UsrCod,long InsCod,bool CountOnlyAcceptedCourses) + { + char Query[512]; + const char *SubQuery; + + /***** Get is a user belongs to an institution from database *****/ + SubQuery = (CountOnlyAcceptedCourses ? " AND crs_usr.Accepted='Y'" : + ""); + sprintf (Query,"SELECT COUNT(DISTINCT centres.InsCod)" + " FROM crs_usr,courses,degrees,centres" + " WHERE crs_usr.UsrCod='%ld'%s" + " AND crs_usr.CrsCod=courses.CrsCod" + " AND courses.DegCod=degrees.DegCod" + " AND degrees.CtrCod=institutions.CtrCod" + " AND centres.InsCod='%ld'", + UsrCod,SubQuery,InsCod); + return (DB_QueryCOUNT (Query,"can not check if a user belongs to an institution") != 0); + } + +/*****************************************************************************/ +/******************* Check if a user belongs to a centre *********************/ +/*****************************************************************************/ + +bool Usr_CheckIfUsrBelongsToCtr (long UsrCod,long CtrCod,bool CountOnlyAcceptedCourses) + { + char Query[512]; + const char *SubQuery; + + /***** Get is a user belongs to a centre from database *****/ + SubQuery = (CountOnlyAcceptedCourses ? " AND crs_usr.Accepted='Y'" : + ""); + sprintf (Query,"SELECT COUNT(DISTINCT degrees.CtrCod)" + " FROM crs_usr,courses,degrees" + " WHERE crs_usr.UsrCod='%ld'%s" + " AND crs_usr.CrsCod=courses.CrsCod" + " AND courses.DegCod=degrees.DegCod" + " AND degrees.CtrCod='%ld'", + UsrCod,SubQuery,CtrCod); + return (DB_QueryCOUNT (Query,"can not check if a user belongs to a centre") != 0); + } + /*****************************************************************************/ /******************* Check if a user belongs to a degree *********************/ /*****************************************************************************/ -bool Usr_CheckIfUsrBelongsToDeg (long UsrCod,long DegCod) +bool Usr_CheckIfUsrBelongsToDeg (long UsrCod,long DegCod,bool CountOnlyAcceptedCourses) { char Query[512]; - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned NumRows; + const char *SubQuery; /***** Get is a user belongs to a degree from database *****/ + SubQuery = (CountOnlyAcceptedCourses ? " AND crs_usr.Accepted='Y'" : + ""); sprintf (Query,"SELECT COUNT(DISTINCT courses.DegCod)" - " FROM crs_usr,courses" - " WHERE crs_usr.UsrCod='%ld' AND courses.DegCod='%ld'" - " AND crs_usr.CrsCod=courses.CrsCod", - UsrCod,DegCod); - DB_QuerySELECT (Query,&mysql_res,"can not check if a user belongs to a degree"); - - /***** Get number of rows *****/ - row = mysql_fetch_row (mysql_res); - if (sscanf (row[0],"%u",&NumRows) != 1) - Lay_ShowErrorAndExit ("Error when checking if a user belongs to a degree."); - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - - return (NumRows > 0); + " FROM crs_usr,courses" + " WHERE crs_usr.UsrCod='%ld'%s" + " AND crs_usr.CrsCod=courses.CrsCod" + " AND courses.DegCod='%ld'", + UsrCod,SubQuery,DegCod); + return (DB_QueryCOUNT (Query,"can not check if a user belongs to a degree") != 0); } /*****************************************************************************/ /******************** Check if a user belongs to a course ********************/ /*****************************************************************************/ -bool Usr_CheckIfUsrBelongsToCrs (long UsrCod,long CrsCod) +bool Usr_CheckIfUsrBelongsToCrs (long UsrCod,long CrsCod,bool CountOnlyAcceptedCourses) { - char Query[256]; + char Query[512]; + const char *SubQuery; /***** If user code or course code not valid... *****/ if (UsrCod <= 0 || @@ -1053,9 +1090,11 @@ bool Usr_CheckIfUsrBelongsToCrs (long UsrCod,long CrsCod) return false; /***** Get if a user belongs to a course from database *****/ + SubQuery = (CountOnlyAcceptedCourses ? " AND crs_usr.Accepted='Y'" : + ""); sprintf (Query,"SELECT COUNT(*) FROM crs_usr" - " WHERE CrsCod='%ld' AND UsrCod='%ld'", - CrsCod,UsrCod); + " WHERE CrsCod='%ld' AND UsrCod='%ld'%s", + CrsCod,UsrCod,SubQuery); return (DB_QueryCOUNT (Query,"can not check if a user belongs to a course") != 0); } diff --git a/swad_user.h b/swad_user.h index ed594352b..2c56d1931 100644 --- a/swad_user.h +++ b/swad_user.h @@ -220,8 +220,10 @@ void Usr_GetMyInstitutions (void); void Usr_GetMyCentres (void); void Usr_GetMyDegrees (void); void Usr_GetMyCourses (void); -bool Usr_CheckIfUsrBelongsToDeg (long UsrCod,long DegCod); -bool Usr_CheckIfUsrBelongsToCrs (long UsrCod,long CrsCod); +bool Usr_CheckIfUsrBelongsToIns (long UsrCod,long InsCod,bool CountOnlyAcceptedCourses); +bool Usr_CheckIfUsrBelongsToCtr (long UsrCod,long CtrCod,bool CountOnlyAcceptedCourses); +bool Usr_CheckIfUsrBelongsToDeg (long UsrCod,long DegCod,bool CountOnlyAcceptedCourses); +bool Usr_CheckIfUsrBelongsToCrs (long UsrCod,long CrsCod,bool CountOnlyAcceptedCourses); bool Usr_CheckIfIBelongToIns (long InsCod); bool Usr_CheckIfIBelongToCtr (long CtrCod); bool Usr_CheckIfIBelongToDeg (long DegCod); diff --git a/swad_web_service.c b/swad_web_service.c index 380fe0f27..e1704a52a 100644 --- a/swad_web_service.c +++ b/swad_web_service.c @@ -2459,7 +2459,7 @@ int swad__sendAttendanceUsers (struct soap *soap, if (Usr_ChkIfUsrCodExists (UsrCod)) // The user must belong to course, // but it's not necessary he/she belongs to groups associated to the event - if (Usr_CheckIfUsrBelongsToCrs (UsrCod,Gbl.CurrentCrs.Crs.CrsCod)) + if (Usr_CheckIfUsrBelongsToCrs (UsrCod,Gbl.CurrentCrs.Crs.CrsCod,false)) { /* Mark user as present */ Att_RegUsrInAttEventNotChangingComments (Att.AttCod,UsrCod);