Version 23.76.1: Apr 19, 2024 Code refactoring related to don't belong/belong.

This commit is contained in:
acanas 2024-04-19 12:49:42 +02:00
parent 9309bf9580
commit 15046b8aff
24 changed files with 334 additions and 314 deletions

View File

@ -1401,8 +1401,8 @@ void Asg_ReceiveAssignment (void)
/***** Get folder name where to send works of the assignment *****/
Par_GetParText ("Folder",Assignments.Asg.Folder,Brw_MAX_BYTES_FOLDER);
Assignments.Asg.SendWork = (Assignments.Asg.Folder[0]) ? Asg_SEND_WORK :
Asg_DONT_SEND_WORK;
Assignments.Asg.SendWork = Assignments.Asg.Folder[0] ? Asg_SEND_WORK :
Asg_DONT_SEND_WORK;
/***** Get assignment text *****/
Par_GetParHTML ("Txt",Description,Cns_MAX_BYTES_TEXT); // Store in HTML format (not rigorous)

View File

@ -659,7 +659,7 @@ void Att_DB_SetUsrsAsPresent (long AttCod,const char *ListUsrs,bool SetOthersAsA
if (Usr_DB_ChkIfUsrCodExists (UsrDat.UsrCod))
// The user must belong to course,
// but it's not necessary he/she belongs to groups associated to the event
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat))
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat) == Usr_BELONG)
{
/* Mark user as present */
if (Att_DB_CheckIfUsrIsInTableAttUsr (AttCod,UsrDat.UsrCod,&Present)) // User is in table att_users

View File

@ -766,25 +766,26 @@ unsigned Ctr_DB_GetMyCtrs (MYSQL_RES **mysql_res,long PrtCod)
/******************* Check if a user belongs to a center *********************/
/*****************************************************************************/
bool Ctr_DB_CheckIfUsrBelongsToCtr (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses)
Usr_Belong_t Ctr_DB_CheckIfUsrBelongsToCtr (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses)
{
const char *SubQuery = (CountOnlyAcceptedCourses ? " AND crs_users.Accepted='Y'" : // Only if user accepted
"");
return (DB_QueryCOUNT ("can not check if a user belongs to a center",
"SELECT COUNT(DISTINCT deg_degrees.CtrCod)"
" FROM crs_users,"
"crs_courses,"
"deg_degrees"
" WHERE crs_users.UsrCod=%ld"
"%s"
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod"
" AND deg_degrees.CtrCod=%ld",
UsrCod,
SubQuery,
HieCod) != 0);
return DB_QueryCOUNT ("can not check if a user belongs to a center",
"SELECT COUNT(DISTINCT deg_degrees.CtrCod)"
" FROM crs_users,"
"crs_courses,"
"deg_degrees"
" WHERE crs_users.UsrCod=%ld"
"%s"
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod"
" AND deg_degrees.CtrCod=%ld",
UsrCod,
SubQuery,
HieCod) ? Usr_BELONG :
Usr_DONT_BELONG;
}
/*****************************************************************************/

View File

@ -88,8 +88,8 @@ unsigned Ctr_DB_GetCtrsWithCoords (MYSQL_RES **mysql_res);
unsigned Ctr_DB_GetCtrsWithCoordsInCurrentIns (MYSQL_RES **mysql_res);
unsigned Ctr_DB_GetMyCtrs (MYSQL_RES **mysql_res,long PrtCod);
bool Ctr_DB_CheckIfUsrBelongsToCtr (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses);
Usr_Belong_t Ctr_DB_CheckIfUsrBelongsToCtr (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses);
unsigned Ctr_DB_GetNumUsrsWhoClaimToBelongToCtr (long HieCod);
void Ctr_DB_RemoveCenter (long HieCod);

View File

@ -633,10 +633,11 @@ Me sale este error, no s
"can npt create received message (duplicated entry '243218-2160773' for key 'UsrCod_MsgCod')
*/
#define Log_PLATFORM_VERSION "SWAD 23.76 (2024-04-19)"
#define Log_PLATFORM_VERSION "SWAD 23.76.1 (2024-04-19)"
#define CSS_FILE "swad23.67.2.css"
#define JS_FILE "swad23.53.6.js"
/*
Version 23.76.1: Apr 19, 2024 Code refactoring related to don't belong/belong. (335570 lines)
Version 23.76: Apr 19, 2024 Code refactoring related to don't belong/belong. (335550 lines)
Version 23.75: Apr 13, 2024 Code refactoring related to closed/open. (335484 lines)
Copy the following icons to icon public directory:

View File

@ -1550,19 +1550,19 @@ void Crs_ContEditAfterChgCrs (void)
PutButtonToRequestRegistration = true;
break;
case Rol_USR:
PutButtonToRequestRegistration = !Hie_CheckIfUsrBelongsTo (Hie_CRS,
PutButtonToRequestRegistration = (Hie_CheckIfUsrBelongsTo (Hie_CRS,
Gbl.Usrs.Me.UsrDat.UsrCod,
Crs_EditingCrs->HieCod,
false);
false) == Usr_DONT_BELONG);
break;
case Rol_STD:
case Rol_NET:
case Rol_TCH:
if (Crs_EditingCrs->HieCod != Gbl.Hierarchy.Node[Hie_CRS].HieCod)
PutButtonToRequestRegistration = !Hie_CheckIfUsrBelongsTo (Hie_CRS,
PutButtonToRequestRegistration = (Hie_CheckIfUsrBelongsTo (Hie_CRS,
Gbl.Usrs.Me.UsrDat.UsrCod,
Crs_EditingCrs->HieCod,
false);
false) == Usr_DONT_BELONG);
break;
default:
break;

View File

@ -828,8 +828,8 @@ unsigned Deg_DB_GetUsrMainDeg (MYSQL_RES **mysql_res,long UsrCod)
/******************* Check if a user belongs to a degree *********************/
/*****************************************************************************/
bool Deg_DB_CheckIfUsrBelongsToDeg (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses)
Usr_Belong_t Deg_DB_CheckIfUsrBelongsToDeg (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses)
{
const char *SubQuery = (CountOnlyAcceptedCourses ? " AND crs_users.Accepted='Y'" : // Only if user accepted
"");
@ -846,7 +846,8 @@ bool Deg_DB_CheckIfUsrBelongsToDeg (long UsrCod,long HieCod,
" AND crs_courses.DegCod=%ld)",
UsrCod,
SubQuery,
HieCod);
HieCod) ? Usr_BELONG :
Usr_DONT_BELONG;
}
/*****************************************************************************/

View File

@ -83,8 +83,8 @@ void Deg_DB_UpdateDegStatus (long DegCod,Hie_Status_t NewStatus);
unsigned Deg_DB_GetMyDegs (MYSQL_RES **mysql_res,long HieCod);
unsigned Deg_DB_GetUsrMainDeg (MYSQL_RES **mysql_res,long UsrCod);
bool Deg_DB_CheckIfUsrBelongsToDeg (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses);
Usr_Belong_t Deg_DB_CheckIfUsrBelongsToDeg (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses);
void Deg_DB_RemoveDegTyp (long DegTypCod);
void Deg_DB_RemoveDeg (long DegCod);

View File

@ -114,7 +114,7 @@ static void Enr_PutActionsRegRemSeveralUsrs (void);
static void Enr_ReceiveUsrsCrs (Rol_Role_t Role);
static void Enr_PutActionModifyOneUsr (bool *OptionChecked,
bool UsrBelongsToCrs,Usr_MeOrOther_t MeOrOther);
Usr_Belong_t UsrBelongsToCrs,Usr_MeOrOther_t MeOrOther);
static void Enr_PutActionRegOneDegAdm (bool *OptionChecked);
static void Enr_PutActionRegOneCtrAdm (bool *OptionChecked);
static void Enr_PutActionRegOneInsAdm (bool *OptionChecked);
@ -1315,7 +1315,7 @@ static void Enr_ReceiveUsrsCrs (Rol_Role_t Role)
bool Enr_PutActionsRegRemOneUsr (Usr_MeOrOther_t MeOrOther)
{
bool OptionsShown = false;
bool UsrBelongsToCrs = false;
Usr_Belong_t UsrBelongsToCrs = Usr_DONT_BELONG;
bool UsrIsDegAdmin = false;
bool UsrIsCtrAdmin = false;
bool UsrIsInsAdmin = false;
@ -1390,7 +1390,7 @@ bool Enr_PutActionsRegRemOneUsr (Usr_MeOrOther_t MeOrOther)
}
/***** Remove user from the course *****/
if (UsrBelongsToCrs)
if (UsrBelongsToCrs == Usr_BELONG)
{
Enr_PutActionRemUsrFromCrs (&OptionChecked,MeOrOther);
OptionsShown = true;
@ -1445,18 +1445,18 @@ bool Enr_PutActionsRegRemOneUsr (Usr_MeOrOther_t MeOrOther)
/*****************************************************************************/
static void Enr_PutActionModifyOneUsr (bool *OptionChecked,
bool UsrBelongsToCrs,Usr_MeOrOther_t MeOrOther)
Usr_Belong_t UsrBelongsToCrs,Usr_MeOrOther_t MeOrOther)
{
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] =
const char *Txt[Usr_NUM_BELONG][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,
[Usr_DONT_BELONG][Usr_ME ] = Txt_Register_me_in_X,
[Usr_DONT_BELONG][Usr_OTHER] = Txt_Register_USER_in_the_course_X,
[Usr_BELONG ][Usr_ME ] = Txt_Modify_me_in_the_course_X,
[Usr_BELONG ][Usr_OTHER] = Txt_Modify_user_in_the_course_X,
};
Enr_RegRemOneUsrActionBegin (Enr_REGISTER_MODIFY_ONE_USR_IN_CRS,OptionChecked);
@ -1671,16 +1671,20 @@ static void Enr_RegisterUsr (struct Usr_Data *UsrDat,Rol_Role_t RegRemRole,
/***** Register user in current course in database *****/
if (Gbl.Hierarchy.Level == Hie_CRS) // Course selected
{
if (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat))
switch (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat))
{
if (RegRemRole != UsrDat->Roles.InCurrentCrs) // The role must be updated
/* Modify role */
Enr_ModifyRoleInCurrentCrs (UsrDat,RegRemRole);
case Usr_BELONG:
if (RegRemRole != UsrDat->Roles.InCurrentCrs) // The role must be updated
/* Modify role */
Enr_ModifyRoleInCurrentCrs (UsrDat,RegRemRole);
break;
case Usr_DONT_BELONG: // User does not belong to this course
default:
/* Register user */
Enr_RegisterUsrInCurrentCrs (UsrDat,RegRemRole,
Enr_SET_ACCEPTED_TO_FALSE);
break;
}
else // User does not belong to this course
/* Register user */
Enr_RegisterUsrInCurrentCrs (UsrDat,RegRemRole,
Enr_SET_ACCEPTED_TO_FALSE);
/***** Register user in the selected groups *****/
if (Gbl.Crs.Grps.NumGrps) // If there are groups in the course
@ -1955,47 +1959,47 @@ void Enr_AskIfRejectSignUp (void)
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS))
{
// User's data exist...
if (Enr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat))
{
/* User already belongs to this course */
Ale_ShowAlert (Ale_WARNING,Txt_THE_USER_X_is_already_enroled_in_the_course_Y,
Gbl.Usrs.Other.UsrDat.FullName,
Gbl.Hierarchy.Node[Hie_CRS].FullName);
Rec_ShowSharedRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
switch (Enr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat))
{
case Usr_BELONG:
/* User already belongs to this course */
Ale_ShowAlert (Ale_WARNING,Txt_THE_USER_X_is_already_enroled_in_the_course_Y,
Gbl.Usrs.Other.UsrDat.FullName,
Gbl.Hierarchy.Node[Hie_CRS].FullName);
Rec_ShowSharedRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
/* Remove inscription request because it has not sense */
Enr_RemUsrEnrolmentRequestInCrs (Gbl.Usrs.Other.UsrDat.UsrCod,
Gbl.Hierarchy.Node[Hie_CRS].HieCod);
/* Remove inscription request because it has not sense */
Enr_RemUsrEnrolmentRequestInCrs (Gbl.Usrs.Other.UsrDat.UsrCod,
Gbl.Hierarchy.Node[Hie_CRS].HieCod);
break;
case Usr_DONT_BELONG: // User does not belong to this course
default:
Role = Rol_DB_GetRequestedRole (Gbl.Hierarchy.Node[Hie_CRS].HieCod,
Gbl.Usrs.Other.UsrDat.UsrCod);
if (Role == Rol_STD ||
Role == Rol_NET ||
Role == Rol_TCH)
{
/***** Show question and button to reject user's enrolment request *****/
/* Begin alert */
Ale_ShowAlertAndButtonBegin (Ale_QUESTION,Txt_Do_you_really_want_to_reject_the_enrolment_request_,
Gbl.Usrs.Other.UsrDat.FullName,
Txt_ROLES_SINGUL_abc[Role][Gbl.Usrs.Other.UsrDat.Sex],
Gbl.Hierarchy.Node[Hie_CRS].FullName);
/* Show user's record */
Rec_ShowSharedRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
/* End alert */
Ale_ShowAlertAndButtonEnd (ActRejSignUp,NULL,NULL,
Usr_PutParOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EnUsrCod,
Btn_REMOVE_BUTTON,Txt_Reject);
}
else
Err_WrongRoleExit ();
break;
}
else // User does not belong to this course
{
Role = Rol_DB_GetRequestedRole (Gbl.Hierarchy.Node[Hie_CRS].HieCod,
Gbl.Usrs.Other.UsrDat.UsrCod);
if (Role == Rol_STD ||
Role == Rol_NET ||
Role == Rol_TCH)
{
/***** Show question and button to reject user's enrolment request *****/
/* Begin alert */
Ale_ShowAlertAndButtonBegin (Ale_QUESTION,Txt_Do_you_really_want_to_reject_the_enrolment_request_,
Gbl.Usrs.Other.UsrDat.FullName,
Txt_ROLES_SINGUL_abc[Role][Gbl.Usrs.Other.UsrDat.Sex],
Gbl.Hierarchy.Node[Hie_CRS].FullName);
/* Show user's record */
Rec_ShowSharedRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
/* End alert */
Ale_ShowAlertAndButtonEnd (ActRejSignUp,NULL,NULL,
Usr_PutParOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EnUsrCod,
Btn_REMOVE_BUTTON,Txt_Reject);
}
else
Err_WrongRoleExit ();
}
}
else
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
}
@ -2017,7 +2021,7 @@ void Enr_RejectSignUp (void)
Usr_DONT_GET_ROLE_IN_CRS))
{
// User's data exist...
if (Enr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat))
if (Enr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat) == Usr_BELONG)
{
/* User already belongs to this course */
Ale_ShowAlert (Ale_WARNING,Txt_THE_USER_X_is_already_enroled_in_the_course_Y,
@ -2119,7 +2123,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
struct Hie_Node Crs;
struct Usr_Data UsrDat;
bool UsrExists;
bool UsrBelongsToCrs;
Usr_Belong_t UsrBelongsToCrs;
Rol_Role_t DesiredRole;
static Act_Action_t NextAction[Rol_NUM_ROLES] =
{
@ -2230,10 +2234,10 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
Crs.HieCod,
false);
else
UsrBelongsToCrs = false;
UsrBelongsToCrs = Usr_DONT_BELONG;
if (UsrExists &&
!UsrBelongsToCrs &&
UsrBelongsToCrs == Usr_DONT_BELONG &&
(DesiredRole == Rol_STD ||
DesiredRole == Rol_NET ||
DesiredRole == Rol_TCH))
@ -2623,32 +2627,32 @@ static void Enr_ShowFormToEditOtherUsr (void)
{
/***** Show form to edit user *****/
if (Gbl.Hierarchy.Level == Hie_CRS) // Course selected
{
/* Check if this user belongs to the current course */
if (Enr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat))
switch (Enr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat))
{
Gbl.Usrs.Other.UsrDat.Accepted = Enr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
if (Gbl.Usrs.Other.UsrDat.Accepted)
Ale_ShowAlert (Ale_INFO,Txt_THE_USER_X_is_already_enroled_in_the_course_Y,
Gbl.Usrs.Other.UsrDat.FullName,
Gbl.Hierarchy.Node[Hie_CRS].FullName);
else // Enrolment not yet accepted
Ale_ShowAlert (Ale_INFO,Txt_THE_USER_X_is_in_the_course_Y_but_has_not_yet_accepted_the_enrolment,
case Usr_BELONG:
Gbl.Usrs.Other.UsrDat.Accepted = Enr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
if (Gbl.Usrs.Other.UsrDat.Accepted)
Ale_ShowAlert (Ale_INFO,Txt_THE_USER_X_is_already_enroled_in_the_course_Y,
Gbl.Usrs.Other.UsrDat.FullName,
Gbl.Hierarchy.Node[Hie_CRS].FullName);
else // Enrolment not yet accepted
Ale_ShowAlert (Ale_INFO,Txt_THE_USER_X_is_in_the_course_Y_but_has_not_yet_accepted_the_enrolment,
Gbl.Usrs.Other.UsrDat.FullName,
Gbl.Hierarchy.Node[Hie_CRS].FullName);
Rec_ShowOtherSharedRecordEditable ();
break;
case Usr_DONT_BELONG: // User does not belong to the current course
default:
Ale_ShowAlert (Ale_INFO,Txt_THE_USER_X_exists_in_Y_but_is_not_enroled_in_the_course_Z,
Gbl.Usrs.Other.UsrDat.FullName,
Cfg_PLATFORM_SHORT_NAME,
Gbl.Hierarchy.Node[Hie_CRS].FullName);
Rec_ShowOtherSharedRecordEditable ();
Rec_ShowOtherSharedRecordEditable ();
break;
}
else // User does not belong to the current course
{
Ale_ShowAlert (Ale_INFO,Txt_THE_USER_X_exists_in_Y_but_is_not_enroled_in_the_course_Z,
Gbl.Usrs.Other.UsrDat.FullName,
Cfg_PLATFORM_SHORT_NAME,
Gbl.Hierarchy.Node[Hie_CRS].FullName);
Rec_ShowOtherSharedRecordEditable ();
}
}
else // No course selected
{
Ale_ShowAlert (Ale_INFO,Txt_THE_USER_X_already_exists_in_Y,
@ -2817,34 +2821,36 @@ void Enr_CreateNewUsr1 (void)
/***** Register user in current course in database *****/
if (Gbl.Hierarchy.Level == Hie_CRS) // Course selected
{
if (Enr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat))
switch (Enr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat))
{
OldRole = Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs; // Remember old role before changing it
if (NewRole != OldRole) // The role must be updated
{
/* Modify role */
Enr_ModifyRoleInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole);
case Usr_BELONG:
OldRole = Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs; // Remember old role before changing it
if (NewRole != OldRole) // The role must be updated
{
/* Modify role */
Enr_ModifyRoleInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole);
/* Success message */
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_role_of_THE_USER_X_in_the_course_Y_has_changed_from_A_to_B,
Gbl.Usrs.Other.UsrDat.FullName,
Gbl.Hierarchy.Node[Hie_CRS].FullName,
Txt_ROLES_SINGUL_abc[OldRole][Gbl.Usrs.Other.UsrDat.Sex],
Txt_ROLES_SINGUL_abc[NewRole][Gbl.Usrs.Other.UsrDat.Sex]);
}
break;
case Usr_DONT_BELONG: // User does not belong to current course
default:
/* Register user */
Enr_RegisterUsrInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,
Enr_SET_ACCEPTED_TO_FALSE);
/* Success message */
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_role_of_THE_USER_X_in_the_course_Y_has_changed_from_A_to_B,
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_THE_USER_X_has_been_enroled_in_the_course_Y,
Gbl.Usrs.Other.UsrDat.FullName,
Gbl.Hierarchy.Node[Hie_CRS].FullName,
Txt_ROLES_SINGUL_abc[OldRole][Gbl.Usrs.Other.UsrDat.Sex],
Txt_ROLES_SINGUL_abc[NewRole][Gbl.Usrs.Other.UsrDat.Sex]);
}
}
else // User does not belong to current course
{
/* Register user */
Enr_RegisterUsrInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,
Enr_SET_ACCEPTED_TO_FALSE);
/* Success message */
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_THE_USER_X_has_been_enroled_in_the_course_Y,
Gbl.Usrs.Other.UsrDat.FullName,
Gbl.Hierarchy.Node[Hie_CRS].FullName);
Gbl.Hierarchy.Node[Hie_CRS].FullName);
break;
}
/***** Change user's groups *****/
@ -2928,34 +2934,36 @@ void Enr_ModifyUsr1 (void)
NewRole = Rec_GetRoleFromRecordForm ();
/***** Register user in current course in database *****/
if (Enr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat))
switch (Enr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat))
{
OldRole = Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs; // Remember old role before changing it
if (NewRole != OldRole) // The role must be updated
{
/* Modify role */
Enr_ModifyRoleInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole);
case Usr_BELONG:
OldRole = Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs; // Remember old role before changing it
if (NewRole != OldRole) // The role must be updated
{
/* Modify role */
Enr_ModifyRoleInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole);
/* Set success message */
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_role_of_THE_USER_X_in_the_course_Y_has_changed_from_A_to_B,
Gbl.Usrs.Other.UsrDat.FullName,
Gbl.Hierarchy.Node[Hie_CRS].FullName,
Txt_ROLES_SINGUL_abc[OldRole][Gbl.Usrs.Other.UsrDat.Sex],
Txt_ROLES_SINGUL_abc[NewRole][Gbl.Usrs.Other.UsrDat.Sex]);
}
break;
case Usr_DONT_BELONG: // User does not belong to current course
default:
/* Register user */
Enr_RegisterUsrInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,
Enr_SET_ACCEPTED_TO_FALSE);
/* Set success message */
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_role_of_THE_USER_X_in_the_course_Y_has_changed_from_A_to_B,
Txt_THE_USER_X_has_been_enroled_in_the_course_Y,
Gbl.Usrs.Other.UsrDat.FullName,
Gbl.Hierarchy.Node[Hie_CRS].FullName,
Txt_ROLES_SINGUL_abc[OldRole][Gbl.Usrs.Other.UsrDat.Sex],
Txt_ROLES_SINGUL_abc[NewRole][Gbl.Usrs.Other.UsrDat.Sex]);
}
}
else // User does not belong to current course
{
/* Register user */
Enr_RegisterUsrInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole,
Enr_SET_ACCEPTED_TO_FALSE);
/* Set success message */
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_THE_USER_X_has_been_enroled_in_the_course_Y,
Gbl.Usrs.Other.UsrDat.FullName,
Gbl.Hierarchy.Node[Hie_CRS].FullName);
Gbl.Hierarchy.Node[Hie_CRS].FullName);
break;
}
/***** Change user's groups *****/
@ -3113,34 +3121,38 @@ static void Enr_AskIfRemoveUsrFromCrs (struct Usr_Data *UsrDat)
[Usr_OTHER] = Txt_Remove_user_from_this_course
};
if (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat))
switch (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat))
{
MeOrOther = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
case Usr_BELONG:
MeOrOther = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
/***** Show question and button to remove user as administrator *****/
/* Begin alert */
Ale_ShowAlertAndButtonBegin (Ale_QUESTION,Question[MeOrOther],
Gbl.Hierarchy.Node[Hie_CRS].FullName);
/***** Show question and button to remove user as administrator *****/
/* Begin alert */
Ale_ShowAlertAndButtonBegin (Ale_QUESTION,Question[MeOrOther],
Gbl.Hierarchy.Node[Hie_CRS].FullName);
/* Show user's record */
Rec_ShowSharedRecordUnmodifiable (UsrDat);
/* Show user's record */
Rec_ShowSharedRecordUnmodifiable (UsrDat);
/* Show form to request confirmation */
if (!NextAction[UsrDat->Roles.InCurrentCrs])
Err_WrongRoleExit ();
Frm_BeginForm (NextAction[UsrDat->Roles.InCurrentCrs]);
Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod);
Pwd_AskForConfirmationOnDangerousAction ();
Btn_PutRemoveButton (TxtButton[MeOrOther]);
Frm_EndForm ();
/* Show form to request confirmation */
if (!NextAction[UsrDat->Roles.InCurrentCrs])
Err_WrongRoleExit ();
Frm_BeginForm (NextAction[UsrDat->Roles.InCurrentCrs]);
Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod);
Pwd_AskForConfirmationOnDangerousAction ();
Btn_PutRemoveButton (TxtButton[MeOrOther]);
Frm_EndForm ();
/* End alert */
Ale_ShowAlertAndButtonEnd (ActUnk,NULL,NULL,
NULL,NULL,
Btn_NO_BUTTON,NULL);
/* End alert */
Ale_ShowAlertAndButtonEnd (ActUnk,NULL,NULL,
NULL,NULL,
Btn_NO_BUTTON,NULL);
break;
case Usr_DONT_BELONG: // User does not belong to current course
default:
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
break;
}
else // User does not belong to current course
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
}
/*****************************************************************************/
@ -3154,86 +3166,90 @@ static void Enr_EffectivelyRemUsrFromCrs (struct Usr_Data *UsrDat,
{
extern const char *Txt_THE_USER_X_has_been_removed_from_the_course_Y;
if (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat))
switch (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat))
{
/***** Remove user from all attendance events in course *****/
Att_DB_RemoveUsrFromCrsEvents (UsrDat->UsrCod,Crs->HieCod);
case Usr_BELONG:
/***** Remove user from all attendance events in course *****/
Att_DB_RemoveUsrFromCrsEvents (UsrDat->UsrCod,Crs->HieCod);
/***** Remove user from all groups in course *****/
Grp_RemUsrFromAllGrpsInCrs (UsrDat->UsrCod,Crs->HieCod);
/***** Remove user from all groups in course *****/
Grp_RemUsrFromAllGrpsInCrs (UsrDat->UsrCod,Crs->HieCod);
/***** Remove user's status about reading of course information *****/
Inf_DB_RemoveUsrFromCrsInfoRead (UsrDat->UsrCod,Crs->HieCod);
/***** Remove user's status about reading of course information *****/
Inf_DB_RemoveUsrFromCrsInfoRead (UsrDat->UsrCod,Crs->HieCod);
/***** Remove important production of this user in course *****/
if (RemoveUsrWorks == Enr_REMOVE_USR_PRODUCTION)
{
/* Remove works zone in course */
Brw_RemoveUsrWorksInCrs (UsrDat,Crs);
/***** Remove important production of this user in course *****/
if (RemoveUsrWorks == Enr_REMOVE_USR_PRODUCTION)
{
/* Remove works zone in course */
Brw_RemoveUsrWorksInCrs (UsrDat,Crs);
/* Remove tests, exams and matches results made by user in course */
TstPrn_RemovePrintsMadeByUsrInCrs (UsrDat->UsrCod,Crs->HieCod);
Exa_DB_RemovePrintQstsMadeByUsrInCrs (UsrDat->UsrCod,Crs->HieCod);
Exa_DB_RemoveAllPrintsMadeByUsrInCrs (UsrDat->UsrCod,Crs->HieCod);
Mch_RemoveMatchesMadeByUsrInCrs (UsrDat->UsrCod,Crs->HieCod);
}
/* Remove tests, exams and matches results made by user in course */
TstPrn_RemovePrintsMadeByUsrInCrs (UsrDat->UsrCod,Crs->HieCod);
Exa_DB_RemovePrintQstsMadeByUsrInCrs (UsrDat->UsrCod,Crs->HieCod);
Exa_DB_RemoveAllPrintsMadeByUsrInCrs (UsrDat->UsrCod,Crs->HieCod);
Mch_RemoveMatchesMadeByUsrInCrs (UsrDat->UsrCod,Crs->HieCod);
}
/***** Remove fields of this user in its course record *****/
Rec_DB_RemoveAllFieldContentsFromUsrRecordInCrs (UsrDat->UsrCod,Crs->HieCod);
/***** Remove fields of this user in its course record *****/
Rec_DB_RemoveAllFieldContentsFromUsrRecordInCrs (UsrDat->UsrCod,Crs->HieCod);
/***** Remove some information about files in course and groups *****/
Brw_DB_RemoveSomeInfoAboutCrsUsrFiles (UsrDat->UsrCod,Crs->HieCod);
/***** Remove some information about files in course and groups *****/
Brw_DB_RemoveSomeInfoAboutCrsUsrFiles (UsrDat->UsrCod,Crs->HieCod);
/***** Set all notifications for this user in this course as removed,
except notifications about new messages *****/
Ntf_DB_MarkNotifInCrsAsRemoved (UsrDat->UsrCod,Crs->HieCod);
/***** Set all notifications for this user in this course as removed,
except notifications about new messages *****/
Ntf_DB_MarkNotifInCrsAsRemoved (UsrDat->UsrCod,Crs->HieCod);
/***** Remove user from the tables of courses-users *****/
Set_DB_RemUsrFromCrsSettings (UsrDat->UsrCod,Crs->HieCod);
Enr_DB_RemUsrFromCrs (UsrDat->UsrCod,Crs->HieCod);
/***** Remove user from the tables of courses-users *****/
Set_DB_RemUsrFromCrsSettings (UsrDat->UsrCod,Crs->HieCod);
Enr_DB_RemUsrFromCrs (UsrDat->UsrCod,Crs->HieCod);
/***** Flush caches *****/
Usr_FlushCachesUsr ();
/***** Flush caches *****/
Usr_FlushCachesUsr ();
/***** If it's me, change my roles *****/
switch (Usr_ItsMe (UsrDat->UsrCod))
{
case Usr_ME:
/* Now I don't belong to current course */
Gbl.Usrs.Me.IBelongToCurrent[Hie_CRS] = Usr_DONT_BELONG;
Gbl.Usrs.Me.UsrDat.Accepted = false;
/***** If it's me, change my roles *****/
switch (Usr_ItsMe (UsrDat->UsrCod))
{
case Usr_ME:
/* Now I don't belong to current course */
Gbl.Usrs.Me.IBelongToCurrent[Hie_CRS] = Usr_DONT_BELONG;
Gbl.Usrs.Me.UsrDat.Accepted = false;
/* Fill the list with the courses I belong to */
Gbl.Usrs.Me.Hierarchy[Hie_CRS].Filled = false;
Hie_GetMyHierarchy (Hie_CRS);
/* Fill the list with the courses I belong to */
Gbl.Usrs.Me.Hierarchy[Hie_CRS].Filled = false;
Hie_GetMyHierarchy (Hie_CRS);
/* 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 ();
break;
case Usr_OTHER:
/* Now he/she does not belong to current course */
UsrDat->Accepted = false;
UsrDat->Roles.InCurrentCrs = Rol_USR;
break;
}
Rol_SetMyRoles ();
break;
case Usr_OTHER:
/* Now he/she does not belong to current course */
UsrDat->Accepted = false;
UsrDat->Roles.InCurrentCrs = Rol_USR;
break;
}
if (QuietOrVerbose == Cns_VERBOSE)
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_THE_USER_X_has_been_removed_from_the_course_Y,
UsrDat->FullName,Crs->FullName);
if (QuietOrVerbose == Cns_VERBOSE)
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_THE_USER_X_has_been_removed_from_the_course_Y,
UsrDat->FullName,Crs->FullName);
break;
case Usr_DONT_BELONG: // User does not belong to course
default:
if (QuietOrVerbose == Cns_VERBOSE)
Ale_CreateAlertUserNotFoundOrYouDoNotHavePermission ();
break;
}
else // User does not belong to course
if (QuietOrVerbose == Cns_VERBOSE)
Ale_CreateAlertUserNotFoundOrYouDoNotHavePermission ();
}
/*****************************************************************************/
@ -3246,12 +3262,12 @@ void Enr_FlushCacheUsrBelongsToCurrentCrs (void)
Gbl.Cache.UsrBelongsToCurrentCrs.Valid = false;
}
bool Enr_CheckIfUsrBelongsToCurrentCrs (const struct Usr_Data *UsrDat)
Usr_Belong_t Enr_CheckIfUsrBelongsToCurrentCrs (const struct Usr_Data *UsrDat)
{
/***** 1. Fast check: Trivial cases *****/
if (UsrDat->UsrCod <= 0 ||
Gbl.Hierarchy.Node[Hie_CRS].HieCod <= 0)
return false;
return Usr_DONT_BELONG;
/***** 2. Fast check: If cached... *****/
if (Gbl.Cache.UsrBelongsToCurrentCrs.Valid &&
@ -3262,9 +3278,10 @@ bool Enr_CheckIfUsrBelongsToCurrentCrs (const struct Usr_Data *UsrDat)
if (UsrDat->Roles.InCurrentCrs != Rol_UNK)
{
Gbl.Cache.UsrBelongsToCurrentCrs.UsrCod = UsrDat->UsrCod;
Gbl.Cache.UsrBelongsToCurrentCrs.Belongs = UsrDat->Roles.InCurrentCrs == Rol_STD ||
UsrDat->Roles.InCurrentCrs == Rol_NET ||
UsrDat->Roles.InCurrentCrs == Rol_TCH;
Gbl.Cache.UsrBelongsToCurrentCrs.Belongs = (UsrDat->Roles.InCurrentCrs == Rol_STD ||
UsrDat->Roles.InCurrentCrs == Rol_NET ||
UsrDat->Roles.InCurrentCrs == Rol_TCH) ? Usr_BELONG :
Usr_DONT_BELONG;
Gbl.Cache.UsrBelongsToCurrentCrs.Valid = true;
return Gbl.Cache.UsrBelongsToCurrentCrs.Belongs;
}
@ -3303,9 +3320,9 @@ bool Enr_CheckIfUsrHasAcceptedInCurrentCrs (const struct Usr_Data *UsrDat)
/***** 3. Fast / slow check: Get if user belongs to current course
and has accepted *****/
Gbl.Cache.UsrHasAcceptedInCurrentCrs.UsrCod = UsrDat->UsrCod;
Gbl.Cache.UsrHasAcceptedInCurrentCrs.Accepted = Hie_CheckIfUsrBelongsTo (Hie_CRS,UsrDat->UsrCod,
Gbl.Hierarchy.Node[Hie_CRS].HieCod,
true);
Gbl.Cache.UsrHasAcceptedInCurrentCrs.Accepted = (Hie_CheckIfUsrBelongsTo (Hie_CRS,UsrDat->UsrCod,
Gbl.Hierarchy.Node[Hie_CRS].HieCod,
true) == Usr_BELONG);
Gbl.Cache.UsrHasAcceptedInCurrentCrs.Valid = true;
return Gbl.Cache.UsrHasAcceptedInCurrentCrs.Accepted;
}
@ -3340,7 +3357,7 @@ bool Enr_CheckIfUsrSharesAnyOfMyCrs (struct Usr_Data *UsrDat)
/***** 5. Fast check: Is course selected and we both belong to it? *****/
if (Gbl.Usrs.Me.IBelongToCurrent[Hie_CRS] == Usr_BELONG)
if (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat)) // Course selected and we both belong to it
if (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat) == Usr_BELONG) // Course selected and we both belong to it
{
Gbl.Cache.UsrSharesAnyOfMyCrs.UsrCod = UsrDat->UsrCod;
Gbl.Cache.UsrSharesAnyOfMyCrs.SharesAnyOfMyCrs = true;

View File

@ -140,7 +140,7 @@ void Enr_ModifyUsr1 (void);
void Enr_ModifyUsr2 (void);
void Enr_FlushCacheUsrBelongsToCurrentCrs (void);
bool Enr_CheckIfUsrBelongsToCurrentCrs (const struct Usr_Data *UsrDat);
Usr_Belong_t Enr_CheckIfUsrBelongsToCurrentCrs (const struct Usr_Data *UsrDat);
void Enr_FlushCacheUsrHasAcceptedInCurrentCrs (void);
bool Enr_CheckIfUsrHasAcceptedInCurrentCrs (const struct Usr_Data *UsrDat);
void Enr_FlushCacheUsrSharesAnyOfMyCrs (void);

View File

@ -158,8 +158,8 @@ unsigned Enr_DB_GetMyCoursesNames (MYSQL_RES **mysql_res)
/******************** Check if a user belongs to a course ********************/
/*****************************************************************************/
bool Enr_DB_CheckIfUsrBelongsToCrs (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses)
Usr_Belong_t Enr_DB_CheckIfUsrBelongsToCrs (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses)
{
const char *SubQuery = (CountOnlyAcceptedCourses ? " AND crs_users.Accepted='Y'" : // Only if user accepted
"");
@ -174,7 +174,8 @@ bool Enr_DB_CheckIfUsrBelongsToCrs (long UsrCod,long HieCod,
"%s)",
HieCod,
UsrCod,
SubQuery);
SubQuery) ? Usr_BELONG :
Usr_DONT_BELONG;
}
/*****************************************************************************/

View File

@ -44,8 +44,8 @@ unsigned Enr_DB_GetMyCrss (MYSQL_RES **mysql_res,long PrtCod);
void Enr_DB_DropTmpTableMyCourses (void);
unsigned Enr_DB_GetMyCoursesNames (MYSQL_RES **mysql_res);
bool Enr_DB_CheckIfUsrBelongsToCrs (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses);
Usr_Belong_t Enr_DB_CheckIfUsrBelongsToCrs (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses);
bool Enr_DB_CheckIfUsrSharesAnyOfMyCrs (long UsrCod);
bool Enr_DB_CheckIfUsrSharesAnyOfMyCrsWithDifferentRole (long UsrCod);
long Enr_DB_GetRamdomStdFromCrs (long HieCod);

View File

@ -927,7 +927,7 @@ static void Fol_GetFollowedFromSelectedUsrs (unsigned *NumFollowed,
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS)) // Get from the database the data of the student
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat))
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat) == Usr_BELONG)
{
/* Check if I follow this user, and update number of users */
if (Fol_DB_CheckUsrIsFollowerOf (Gbl.Usrs.Me.UsrDat.UsrCod,
@ -975,7 +975,7 @@ void Fol_FollowUsrs ()
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat, // Get user's data from database
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS))
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat))
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat) == Usr_BELONG)
/* If I don't follow this user ==> follow him/her */
if (!Fol_DB_CheckUsrIsFollowerOf (Gbl.Usrs.Me.UsrDat.UsrCod,
UsrDat.UsrCod))
@ -1024,7 +1024,7 @@ void Fol_UnfollowUsrs (void)
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat, // Get user's data from database
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS))
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat))
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat) == Usr_BELONG)
/* If I follow this user ==> unfollow him/her */
if (Fol_DB_CheckUsrIsFollowerOf (Gbl.Usrs.Me.UsrDat.UsrCod,
UsrDat.UsrCod))

View File

@ -291,13 +291,13 @@ struct Globals
long UsrCod;
long HieCod;
bool CountOnlyAcceptedCourses;
bool Belongs;
Usr_Belong_t Belongs;
bool Valid;
} UsrBelongsTo[Hie_NUM_LEVELS];
struct
{
long UsrCod;
bool Belongs;
Usr_Belong_t Belongs;
bool Valid;
} UsrBelongsToCurrentCrs;
struct

View File

@ -3101,7 +3101,7 @@ bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct Usr_Data *UsrDat)
return Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.Shares;
/***** 7. Fast / slow check: Does he/she belong to the current course? *****/
if (!Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat))
if (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat) == Usr_DONT_BELONG)
{
Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.UsrCod = UsrDat->UsrCod;
Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.Shares = false;

View File

@ -1036,11 +1036,11 @@ void Hie_FlushCacheUsrBelongsTo (Hie_Level_t Level)
/******************** Check if a user belongs to a course ********************/
/*****************************************************************************/
bool Hie_CheckIfUsrBelongsTo (Hie_Level_t Level,long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses)
Usr_Belong_t Hie_CheckIfUsrBelongsTo (Hie_Level_t Level,long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses)
{
static bool (*FunctionToGetIfUsrBelongsToFromDB[Hie_NUM_LEVELS]) (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses) =
static Usr_Belong_t (*FunctionToGetIfUsrBelongsToFromDB[Hie_NUM_LEVELS]) (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses) =
{
[Hie_INS] = Ins_DB_CheckIfUsrBelongsToIns,
[Hie_CTR] = Ctr_DB_CheckIfUsrBelongsToCtr,
@ -1055,7 +1055,7 @@ bool Hie_CheckIfUsrBelongsTo (Hie_Level_t Level,long UsrCod,long HieCod,
/***** 1. Fast check: Trivial cases *****/
if (UsrCod <= 0 ||
HieCod <= 0)
return false;
return Usr_DONT_BELONG;
/***** 2. Fast check: If cached... *****/
if (Gbl.Cache.UsrBelongsTo[Level].Valid &&

View File

@ -70,8 +70,8 @@ void Hie_GetMyHierarchy (Hie_Level_t Level);
Usr_Belong_t Hie_CheckIfIBelongTo (Hie_Level_t Level,long HieCod);
void Hie_FlushCacheUsrBelongsTo (Hie_Level_t Level);
bool Hie_CheckIfUsrBelongsTo (Hie_Level_t Level,long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses);
Usr_Belong_t Hie_CheckIfUsrBelongsTo (Hie_Level_t Level,long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses);
//-------------------------------- Figures ------------------------------------
void Hie_GetAndShowHierarchyStats (void);

View File

@ -807,27 +807,28 @@ unsigned Ins_DB_GetMyInss (MYSQL_RES **mysql_res,long PrtCod)
/**************** Check if a user belongs to an institution ******************/
/*****************************************************************************/
bool Ins_DB_CheckIfUsrBelongsToIns (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses)
Usr_Belong_t Ins_DB_CheckIfUsrBelongsToIns (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses)
{
const char *SubQuery = (CountOnlyAcceptedCourses ? " AND crs_users.Accepted='Y'" : // Only if user accepted
"");
return (DB_QueryCOUNT ("can not check if a user belongs to an institution",
"SELECT COUNT(DISTINCT ctr_centers.InsCod)"
" FROM crs_users,"
"crs_courses,"
"deg_degrees,"
"ctr_centers"
" WHERE crs_users.UsrCod=%ld"
"%s"
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod"
" AND deg_degrees.CtrCod=ctr_centers.CtrCod"
" AND ctr_centers.InsCod=%ld",
UsrCod,
SubQuery,
HieCod) != 0);
return DB_QueryCOUNT ("can not check if a user belongs to an institution",
"SELECT COUNT(DISTINCT ctr_centers.InsCod)"
" FROM crs_users,"
"crs_courses,"
"deg_degrees,"
"ctr_centers"
" WHERE crs_users.UsrCod=%ld"
"%s"
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod"
" AND deg_degrees.CtrCod=ctr_centers.CtrCod"
" AND ctr_centers.InsCod=%ld",
UsrCod,
SubQuery,
HieCod) ? Usr_BELONG :
Usr_DONT_BELONG;
}
/*****************************************************************************/

View File

@ -79,8 +79,8 @@ unsigned Ins_DB_GetNumInnsWithUsrs (Rol_Role_t Role,
Hie_Level_t Level,long HieCod);
unsigned Ins_DB_GetMyInss (MYSQL_RES **mysql_res,long HieCod);
bool Ins_DB_CheckIfUsrBelongsToIns (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses);
Usr_Belong_t Ins_DB_CheckIfUsrBelongsToIns (long UsrCod,long HieCod,
bool CountOnlyAcceptedCourses);
unsigned Ins_DB_GetNumUsrsWhoClaimToBelongToIns (long HieCod);
void Ins_DB_RemoveInstitution (long HieCod);

View File

@ -1698,30 +1698,30 @@ Usr_Can_t Mai_ICanSeeOtherUsrEmail (const struct Usr_Data *UsrDat)
case Rol_TCH:
/* If I am a teacher in the current course,
I can see the email of confirmed students and teachers */
return (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat) && // A user belonging to the current course
UsrDat->Accepted) ? Usr_CAN : // who accepted registration
return (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat) == Usr_BELONG && // A user belonging to the current course
UsrDat->Accepted) ? Usr_CAN : // who accepted registration
Usr_CAN_NOT;
case Rol_DEG_ADM:
/* If I am an administrator of current degree,
I only can see the user's email of users from current degree */
return Hie_CheckIfUsrBelongsTo (Hie_DEG,UsrDat->UsrCod,
Gbl.Hierarchy.Node[Hie_DEG].HieCod,
true) ? Usr_CAN : // count only accepted courses
Usr_CAN_NOT;
return (Hie_CheckIfUsrBelongsTo (Hie_DEG,UsrDat->UsrCod,
Gbl.Hierarchy.Node[Hie_DEG].HieCod,
true) == Usr_BELONG) ? Usr_CAN : // count only accepted courses
Usr_CAN_NOT;
case Rol_CTR_ADM:
/* If I am an administrator of current center,
I only can see the user's email of users from current center */
return Hie_CheckIfUsrBelongsTo (Hie_CTR,UsrDat->UsrCod,
Gbl.Hierarchy.Node[Hie_CTR].HieCod,
true) ? Usr_CAN : // count only accepted courses
Usr_CAN_NOT;
return (Hie_CheckIfUsrBelongsTo (Hie_CTR,UsrDat->UsrCod,
Gbl.Hierarchy.Node[Hie_CTR].HieCod,
true) == Usr_BELONG) ? Usr_CAN : // count only accepted courses
Usr_CAN_NOT;
case Rol_INS_ADM:
/* If I am an administrator of current institution,
I only can see the user's email of users from current institution */
return Hie_CheckIfUsrBelongsTo (Hie_INS,UsrDat->UsrCod,
Gbl.Hierarchy.Node[Hie_INS].HieCod,
true) ? Usr_CAN : // count only accepted courses
Usr_CAN_NOT;
return (Hie_CheckIfUsrBelongsTo (Hie_INS,UsrDat->UsrCod,
Gbl.Hierarchy.Node[Hie_INS].HieCod,
true) == Usr_BELONG) ? Usr_CAN : // count only accepted courses
Usr_CAN_NOT;
case Rol_SYS_ADM:
return Usr_CAN;
default:

View File

@ -1113,7 +1113,7 @@ static void Rec_ListRecordsStds (Rec_SharedRecordViewType_t ShaTypeOfView,
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat, // Get student's data from database
Usr_DONT_GET_PREFS,
Usr_GET_ROLE_IN_CRS))
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat))
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat) == Usr_BELONG)
{
/* Check if this user has accepted
his/her inscription in the current course */
@ -1326,7 +1326,7 @@ static void Rec_ListRecordsTchs (Rec_SharedRecordViewType_t TypeOfView)
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat, // Get teacher's data from database
Usr_DONT_GET_PREFS,
Usr_GET_ROLE_IN_CRS))
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat))
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat) == Usr_BELONG)
{
/* Check if this user has accepted
his/her inscription in the current course */

View File

@ -128,9 +128,7 @@ void Rol_SetMyRoles (void)
/***** Check if I belong to current course *****/
if (Gbl.Hierarchy.Level == Hie_CRS) // Course selected
{
Gbl.Usrs.Me.IBelongToCurrent[Hie_CRS] =
Enr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Me.UsrDat) ? Usr_BELONG :
Usr_DONT_BELONG;
Gbl.Usrs.Me.IBelongToCurrent[Hie_CRS] = Enr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Me.UsrDat);
switch (Gbl.Usrs.Me.IBelongToCurrent[Hie_CRS])
{
case Usr_BELONG:

View File

@ -820,7 +820,7 @@ Usr_Can_t Usr_CheckIfICanEditOtherUsr (const struct Usr_Data *UsrDat)
I only can edit users from current degree who have accepted */
if (Hie_CheckIfUsrBelongsTo (Hie_DEG,UsrDat->UsrCod,
Gbl.Hierarchy.Node[Hie_DEG].HieCod,
true)) // count only accepted courses
true) == Usr_BELONG) // count only accepted courses
// Degree admins can't edit superusers' data
if (!Usr_CheckIfUsrIsSuperuser (UsrDat->UsrCod))
return Usr_CAN;
@ -830,7 +830,7 @@ Usr_Can_t Usr_CheckIfICanEditOtherUsr (const struct Usr_Data *UsrDat)
I only can edit from current center who have accepted */
if (Hie_CheckIfUsrBelongsTo (Hie_CTR,UsrDat->UsrCod,
Gbl.Hierarchy.Node[Hie_CTR].HieCod,
true)) // count only accepted courses
true) == Usr_BELONG) // count only accepted courses
// Center admins can't edit superusers' data
if (!Usr_CheckIfUsrIsSuperuser (UsrDat->UsrCod))
return Usr_CAN;
@ -840,7 +840,7 @@ Usr_Can_t Usr_CheckIfICanEditOtherUsr (const struct Usr_Data *UsrDat)
I only can edit from current institution who have accepted */
if (Hie_CheckIfUsrBelongsTo (Hie_INS,UsrDat->UsrCod,
Gbl.Hierarchy.Node[Hie_INS].HieCod,
true)) // count only accepted courses
true) == Usr_BELONG) // count only accepted courses
// Institution admins can't edit superusers' data
if (!Usr_CheckIfUsrIsSuperuser (UsrDat->UsrCod))
return Usr_CAN;
@ -887,7 +887,7 @@ Usr_Can_t Usr_CheckIfICanViewRecordStd (const struct Usr_Data *UsrDat)
return Usr_CAN;
/***** 8. Fast / slow check: Does he/she belong to the current course? *****/
if (!Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat))
if (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat) == Usr_DONT_BELONG)
return Usr_CAN_NOT;
/***** 9. Fast / slow check depending on roles *****/
@ -962,7 +962,7 @@ Usr_Can_t Usr_CheckIfICanViewTstExaMchResult (const struct Usr_Data *UsrDat)
return Usr_CAN;
/***** 7. Fast check: Does he/she belong to the current course? *****/
if (!Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat))
if (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat) == Usr_DONT_BELONG)
return Usr_CAN_NOT;
/***** 8. Fast / slow check depending on roles *****/
@ -998,7 +998,7 @@ Usr_Can_t Usr_CheckIfICanViewAsgWrk (const struct Usr_Data *UsrDat)
/***** 4. Fast check: Does he/she belong to the current course? *****/
// Only users beloging to course can have files in assignments/works
if (!Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat))
if (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat) == Usr_DONT_BELONG)
return Usr_CAN_NOT;
/***** 5. Fast check: Am I a system admin? *****/

View File

@ -152,7 +152,7 @@ void ZIP_CreateZIPAsgWrk (void)
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat, // Get user's data from database
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS))
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat))
if (Enr_CheckIfUsrBelongsToCurrentCrs (&UsrDat) == Usr_BELONG)
ZIP_CreateDirCompressionUsr (&UsrDat);
}