Version 14.132.1

This commit is contained in:
Antonio Cañas Vargas 2015-09-16 19:22:32 +02:00
parent c12147e22d
commit cb1736819c
9 changed files with 94 additions and 50 deletions

View File

@ -98,11 +98,12 @@
/****************************** Public constants *****************************/ /****************************** 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: // 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 // 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) Version 14.132: Sep 16, 2015 Changes in user enrollment. (184416 lines)
4 changes necessary in database: 4 changes necessary in database:
UPDATE actions SET Obsolete='Y' WHERE ActCod='375'; UPDATE actions SET Obsolete='Y' WHERE ActCod='375';

View File

@ -797,7 +797,7 @@ bool Enr_PutActionsRegRemOneUsr (bool ItsMe)
/***** Check if the other user belongs to the current course *****/ /***** Check if the other user belongs to the current course *****/
if (Gbl.CurrentCrs.Crs.CrsCod > 0) 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) 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 *****/ /***** Register user in current course in database *****/
if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected 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); Enr_ModifyRoleInCurrentCrs (UsrDat,RegRemRole,Cns_QUIET);
else else
Enr_RegisterUsrInCurrentCrs (UsrDat,RegRemRole,Cns_QUIET, 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_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 */ /* User already belongs to this course */
sprintf (Gbl.Message,Txt_THE_USER_X_is_already_enrolled_in_the_course_Y, 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_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 */ /* User already belongs to this course */
sprintf (Gbl.Message,Txt_THE_USER_X_is_already_enrolled_in_the_course_Y, 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]); DesiredRole = Rol_ConvertUnsignedStrToRole (row[3]);
if (UsrExists) if (UsrExists)
UsrBelongsToCrs = Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod,Crs.CrsCod); UsrBelongsToCrs = Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod,Crs.CrsCod,false);
else else
UsrBelongsToCrs = false; 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 if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected
{ {
/* Check if this user belongs to the current course */ /* 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); Gbl.Usrs.Other.UsrDat.Accepted = Usr_GetIfUserHasAcceptedEnrollmentInCurrentCrs (Gbl.Usrs.Other.UsrDat.UsrCod);
if (Gbl.Usrs.Other.UsrDat.Accepted) if (Gbl.Usrs.Other.UsrDat.Accepted)
@ -3218,7 +3218,7 @@ void Enr_CreateNewUsr (void)
/***** Register user in current course in database *****/ /***** Register user in current course in database *****/
if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected 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); Enr_ModifyRoleInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,Cns_VERBOSE);
else else
Enr_RegisterUsrInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,Cns_VERBOSE, Enr_RegisterUsrInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,Cns_VERBOSE,
@ -3282,7 +3282,7 @@ void Enr_ModifyUsr (void)
NewRole = Rec_GetRoleFromRecordForm (); NewRole = Rec_GetRoleFromRecordForm ();
/***** Register user in current course in database *****/ /***** 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); Enr_ModifyRoleInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,Cns_VERBOSE);
else else
Enr_RegisterUsrInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,Cns_VERBOSE, 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_Remove_user_from_this_course;
extern const char *Txt_User_not_found_or_you_do_not_have_permission_; 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, sprintf (Gbl.Message,
ItsMe ? Txt_Do_you_really_want_to_be_removed_from_the_course_X : 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_; extern const char *Txt_User_not_found_or_you_do_not_have_permission_;
char Query[1024]; 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 *****/ /***** Remove user from all the attendance events in course *****/
Att_RemoveUsrFromCrsAttEvents (UsrDat->UsrCod,Crs->CrsCod); Att_RemoveUsrFromCrsAttEvents (UsrDat->UsrCod,Crs->CrsCod);

View File

@ -2938,7 +2938,7 @@ static void Brw_ShowFileBrowsersAsgWrkCrs (void)
Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat); Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // Get user's data from database 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); ZIP_CreateDirCompressionUsr (&UsrDat);
} }
@ -2967,7 +2967,7 @@ static void Brw_ShowFileBrowsersAsgWrkCrs (void)
Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat); Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) // Get of the database the data of the user 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 *****/ /***** Show a row with the data of the owner of the works *****/
fprintf (Gbl.F.Out,"<tr>"); fprintf (Gbl.F.Out,"<tr>");

View File

@ -128,24 +128,26 @@ bool Pho_CheckIfICanChangeOtherUsrPhoto (const struct UsrData *UsrDat)
if (UsrDat->UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // It's me if (UsrDat->UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // It's me
return true; 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) switch (Gbl.Usrs.Me.LoggedRole)
{ {
case Rol_TEACHER: case Rol_TEACHER:
/* If I am a teacher in current course, /* 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; return UsrDat->Accepted;
case Rol_DEG_ADM: case Rol_DEG_ADM:
/* If I am an administrator of current degree, /* If I am an administrator of current degree,
I only can change the photo of users from current degree */ I only can change the photo of users from current degree */
return Usr_CheckIfUsrBelongsToDeg (UsrDat->UsrCod,Gbl.CurrentDeg.Deg.DegCod); return Usr_CheckIfUsrBelongsToDeg (UsrDat->UsrCod,Gbl.CurrentDeg.Deg.DegCod,true);
// TODO: Only confirmed users?
case Rol_CTR_ADM: case Rol_CTR_ADM:
// TODO: Implement /* If I am an administrator of current centre,
return false; 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: case Rol_INS_ADM:
// TODO: Implement /* If I am an administrator of current institution,
return false; 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: case Rol_SYS_ADM:
return true; return true;
default: default:

View File

@ -1071,7 +1071,7 @@ void Rec_ListRecordsStdsCrs (void)
Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat); Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // Get from the database the data of the student 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); 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); Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat); Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // Get from the database the data of the student 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); UsrDat.Accepted = Usr_GetIfUserHasAcceptedEnrollmentInCurrentCrs (UsrDat.UsrCod);

View File

@ -6041,7 +6041,7 @@ void Tst_ShowUsrsTestResults (void)
Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat); Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) // Get of the database the data of the user 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 *****/ /***** Show the result of test exams *****/
Tst_ShowResultsOfTestExams (&Gbl.Usrs.Other.UsrDat); Tst_ShowResultsOfTestExams (&Gbl.Usrs.Other.UsrDat);
} }

View File

@ -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 *********************/ /******************* 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]; char Query[512];
MYSQL_RES *mysql_res; const char *SubQuery;
MYSQL_ROW row;
unsigned NumRows;
/***** Get is a user belongs to a degree from database *****/ /***** Get is a user belongs to a degree from database *****/
SubQuery = (CountOnlyAcceptedCourses ? " AND crs_usr.Accepted='Y'" :
"");
sprintf (Query,"SELECT COUNT(DISTINCT courses.DegCod)" sprintf (Query,"SELECT COUNT(DISTINCT courses.DegCod)"
" FROM crs_usr,courses" " FROM crs_usr,courses"
" WHERE crs_usr.UsrCod='%ld' AND courses.DegCod='%ld'" " WHERE crs_usr.UsrCod='%ld'%s"
" AND crs_usr.CrsCod=courses.CrsCod", " AND crs_usr.CrsCod=courses.CrsCod"
UsrCod,DegCod); " AND courses.DegCod='%ld'",
DB_QuerySELECT (Query,&mysql_res,"can not check if a user belongs to a degree"); UsrCod,SubQuery,DegCod);
return (DB_QueryCOUNT (Query,"can not check if a user belongs to a degree") != 0);
/***** 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);
} }
/*****************************************************************************/ /*****************************************************************************/
/******************** Check if a user belongs to a course ********************/ /******************** 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 user code or course code not valid... *****/
if (UsrCod <= 0 || if (UsrCod <= 0 ||
@ -1053,9 +1090,11 @@ bool Usr_CheckIfUsrBelongsToCrs (long UsrCod,long CrsCod)
return false; return false;
/***** Get if a user belongs to a course from database *****/ /***** Get if a user belongs to a course from database *****/
SubQuery = (CountOnlyAcceptedCourses ? " AND crs_usr.Accepted='Y'" :
"");
sprintf (Query,"SELECT COUNT(*) FROM crs_usr" sprintf (Query,"SELECT COUNT(*) FROM crs_usr"
" WHERE CrsCod='%ld' AND UsrCod='%ld'", " WHERE CrsCod='%ld' AND UsrCod='%ld'%s",
CrsCod,UsrCod); CrsCod,UsrCod,SubQuery);
return (DB_QueryCOUNT (Query,"can not check if a user belongs to a course") != 0); return (DB_QueryCOUNT (Query,"can not check if a user belongs to a course") != 0);
} }

View File

@ -220,8 +220,10 @@ void Usr_GetMyInstitutions (void);
void Usr_GetMyCentres (void); void Usr_GetMyCentres (void);
void Usr_GetMyDegrees (void); void Usr_GetMyDegrees (void);
void Usr_GetMyCourses (void); void Usr_GetMyCourses (void);
bool Usr_CheckIfUsrBelongsToDeg (long UsrCod,long DegCod); bool Usr_CheckIfUsrBelongsToIns (long UsrCod,long InsCod,bool CountOnlyAcceptedCourses);
bool Usr_CheckIfUsrBelongsToCrs (long UsrCod,long CrsCod); 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_CheckIfIBelongToIns (long InsCod);
bool Usr_CheckIfIBelongToCtr (long CtrCod); bool Usr_CheckIfIBelongToCtr (long CtrCod);
bool Usr_CheckIfIBelongToDeg (long DegCod); bool Usr_CheckIfIBelongToDeg (long DegCod);

View File

@ -2459,7 +2459,7 @@ int swad__sendAttendanceUsers (struct soap *soap,
if (Usr_ChkIfUsrCodExists (UsrCod)) if (Usr_ChkIfUsrCodExists (UsrCod))
// The user must belong to course, // The user must belong to course,
// but it's not necessary he/she belongs to groups associated to the event // 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 */ /* Mark user as present */
Att_RegUsrInAttEventNotChangingComments (Att.AttCod,UsrCod); Att_RegUsrInAttEventNotChangingComments (Att.AttCod,UsrCod);