mirror of https://github.com/acanas/swad-core.git
Version 16.217
This commit is contained in:
parent
489c687c77
commit
dbb475d30e
|
@ -233,13 +233,14 @@
|
|||
/****************************** Public constants *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define Log_PLATFORM_VERSION "SWAD 16.216 (2017-05-18)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 16.217 (2017-05-18)"
|
||||
#define CSS_FILE "swad16.209.3.css"
|
||||
#define JS_FILE "swad16.206.3.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.217: May 18, 2017 Role user is the default when no course is selected. (218887 lines)
|
||||
Version 16.216: May 18, 2017 Role visitor is renamed as role user. (218867 lines)
|
||||
Version 16.215.4: May 18, 2017 Changed layout of assignments.
|
||||
Removed alert with number of users notified via email. (218868 lines)
|
||||
|
|
21
swad_role.c
21
swad_role.c
|
@ -79,13 +79,19 @@ unsigned Rol_GetNumAvailableRoles (void)
|
|||
/************ Get maximum role of a user in all his/her courses **************/
|
||||
/*****************************************************************************/
|
||||
|
||||
Rol_Role_t Rol_GetMaxRole (unsigned Roles)
|
||||
Rol_Role_t Rol_GetMaxRoleInCrss (unsigned Roles)
|
||||
{
|
||||
/***** User's role in one of her/his course can be ROL_STD or ROL_TCH *****/
|
||||
/* Check first if user is a teacher in any course */
|
||||
if (Roles & (1 << Rol_TCH))
|
||||
return Rol_TCH;
|
||||
|
||||
/* Not a teacher. Check then if user is a student in any course */
|
||||
if (Roles & (1 << Rol_STD))
|
||||
return Rol_STD;
|
||||
return Rol_GST;
|
||||
|
||||
/* Not a teacher or student */
|
||||
return Rol_GST; // Guest means that this user is not registered in any course
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -193,7 +199,7 @@ Rol_Role_t Rol_GetRoleInCrs (long CrsCod,long UsrCod)
|
|||
char Query[256];
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
Rol_Role_t Role;
|
||||
Rol_Role_t Role = Rol_UNK; // Default role (if no course selected or user don't belong to it)
|
||||
|
||||
if (CrsCod > 0)
|
||||
{
|
||||
|
@ -207,14 +213,10 @@ Rol_Role_t Rol_GetRoleInCrs (long CrsCod,long UsrCod)
|
|||
row = mysql_fetch_row (mysql_res);
|
||||
Role = Rol_ConvertUnsignedStrToRole (row[0]);
|
||||
}
|
||||
else // User does not belong to the course
|
||||
Role = Rol_UNK;
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
}
|
||||
else // No course
|
||||
Role = Rol_UNK;
|
||||
|
||||
return Role;
|
||||
}
|
||||
|
@ -264,8 +266,9 @@ Rol_Role_t Rol_ConvertUnsignedStrToRole (const char *UnsignedStr)
|
|||
unsigned UnsignedNum;
|
||||
|
||||
if (sscanf (UnsignedStr,"%u",&UnsignedNum) == 1)
|
||||
return (UnsignedNum >= Rol_NUM_ROLES) ? Rol_UNK :
|
||||
(Rol_Role_t) UnsignedNum;
|
||||
if (UnsignedNum < Rol_NUM_ROLES)
|
||||
return (Rol_Role_t) UnsignedNum;
|
||||
|
||||
return Rol_UNK;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
/*****************************************************************************/
|
||||
|
||||
unsigned Rol_GetNumAvailableRoles (void);
|
||||
Rol_Role_t Rol_GetMaxRole (unsigned Roles);
|
||||
Rol_Role_t Rol_GetMaxRoleInCrss (unsigned Roles);
|
||||
Rol_Role_t Rol_GetMyMaxRoleInIns (long InsCod);
|
||||
Rol_Role_t Rol_GetMyMaxRoleInCtr (long CtrCod);
|
||||
Rol_Role_t Rol_GetMyMaxRoleInDeg (long DegCod);
|
||||
|
|
|
@ -1019,7 +1019,7 @@ static void Svy_SetAllowedAndHiddenScopes (unsigned *ScopesAllowed,
|
|||
if (Usr_CheckIfIBelongToDeg (Gbl.CurrentDeg.Deg.DegCod))
|
||||
{
|
||||
*ScopesAllowed |= 1 << Sco_SCOPE_DEG;
|
||||
if (Usr_CheckIfIBelongToCrs (Gbl.CurrentCrs.Crs.CrsCod))
|
||||
if (Usr_CheckIfIBelongToCurrentCrs ())
|
||||
*ScopesAllowed |= 1 << Sco_SCOPE_CRS;
|
||||
}
|
||||
}
|
||||
|
@ -1041,7 +1041,7 @@ static void Svy_SetAllowedAndHiddenScopes (unsigned *ScopesAllowed,
|
|||
if (Usr_CheckIfIBelongToDeg (Gbl.CurrentDeg.Deg.DegCod))
|
||||
{
|
||||
*ScopesAllowed |= 1 << Sco_SCOPE_DEG;
|
||||
if (Usr_CheckIfIBelongToCrs (Gbl.CurrentCrs.Crs.CrsCod))
|
||||
if (Usr_CheckIfIBelongToCurrentCrs ())
|
||||
{
|
||||
*ScopesAllowed |= 1 << Sco_SCOPE_CRS;
|
||||
*HiddenAllowed |= 1 << Sco_SCOPE_CRS; // A teacher can view hidden course surveys
|
||||
|
|
50
swad_user.c
50
swad_user.c
|
@ -489,7 +489,8 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat)
|
|||
Pwd_BYTES_ENCRYPTED_PASSWORD);
|
||||
|
||||
/* Get roles */
|
||||
UsrDat->RoleInCurrentCrsDB = Rol_GetRoleInCrs (Gbl.CurrentCrs.Crs.CrsCod,UsrDat->UsrCod);
|
||||
UsrDat->RoleInCurrentCrsDB = Rol_GetRoleInCrs (Gbl.CurrentCrs.Crs.CrsCod,
|
||||
UsrDat->UsrCod);
|
||||
UsrDat->Roles = -1; // Force roles to be got from database
|
||||
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat);
|
||||
if (UsrDat->RoleInCurrentCrsDB == Rol_UNK)
|
||||
|
@ -1777,6 +1778,25 @@ bool Usr_CheckIfIBelongToCrs (long CrsCod)
|
|||
return false;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************** Check if I belong to current course ********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
bool Usr_CheckIfIBelongToCurrentCrs (void)
|
||||
{
|
||||
/***** Fast check: Is no course selected *****/
|
||||
if (Gbl.CurrentCrs.Crs.CrsCod <= 0)
|
||||
return false;
|
||||
|
||||
/***** Fast check: Is course selected and I am student or teacher *****/
|
||||
if (Gbl.Usrs.Me.UsrDat.RoleInCurrentCrsDB == Rol_STD ||
|
||||
Gbl.Usrs.Me.UsrDat.RoleInCurrentCrsDB == Rol_TCH)
|
||||
return true;
|
||||
|
||||
/***** Slow check: query database *****/
|
||||
return Usr_CheckIfIBelongToCrs (Gbl.CurrentCrs.Crs.CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************** Get the countries of a user from database ******************/
|
||||
/*****************************************************************************/
|
||||
|
@ -2825,7 +2845,7 @@ static void Usr_ShowAlertThereAreMoreThanOneUsr (void)
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**** Check if users exists, if his password is correct, get his data... *****/
|
||||
/** Check if users exists, if her/his password is correct, get her/his data **/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Usr_SetUsrRoleAndPrefs (void)
|
||||
|
@ -2877,15 +2897,19 @@ static void Usr_SetUsrRoleAndPrefs (void)
|
|||
Hie_InitHierarchy ();
|
||||
|
||||
/* Get again my role in this course */
|
||||
Gbl.Usrs.Me.UsrDat.RoleInCurrentCrsDB = Rol_GetRoleInCrs (Gbl.CurrentCrs.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
Gbl.Usrs.Me.UsrDat.RoleInCurrentCrsDB = Rol_GetRoleInCrs (Gbl.CurrentCrs.Crs.CrsCod,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
}
|
||||
}
|
||||
|
||||
// In this point Gbl.Usrs.Me.UsrDat.RoleInCurrentCrsDB is set
|
||||
|
||||
/***** Set the user's role I am logged *****/
|
||||
Rol_GetRolesInAllCrssIfNotYetGot (&Gbl.Usrs.Me.UsrDat); // Get my roles if not yet got
|
||||
Gbl.Usrs.Me.MaxRole = Rol_GetMaxRole ((unsigned) Gbl.Usrs.Me.UsrDat.Roles);
|
||||
Gbl.Usrs.Me.MaxRole = Rol_GetMaxRoleInCrss ((unsigned) Gbl.Usrs.Me.UsrDat.Roles);
|
||||
Gbl.Usrs.Me.LoggedRole = (Gbl.Usrs.Me.RoleFromSession == Rol_UNK) ? // If no logged role retrieved from session...
|
||||
Gbl.Usrs.Me.MaxRole : // ...set current logged role to maximum role in database
|
||||
((Gbl.Usrs.Me.UsrDat.RoleInCurrentCrsDB == Rol_UNK) ? Rol_USR :
|
||||
Gbl.Usrs.Me.UsrDat.RoleInCurrentCrsDB) :
|
||||
Gbl.Usrs.Me.RoleFromSession; // Get logged role from session
|
||||
|
||||
/***** Construct the path to my directory *****/
|
||||
|
@ -2916,16 +2940,13 @@ static void Usr_SetUsrRoleAndPrefs (void)
|
|||
}
|
||||
|
||||
/***** Check if I belong to current course *****/
|
||||
if (Gbl.CurrentCrs.Crs.CrsCod > 0)
|
||||
Gbl.Usrs.Me.IBelongToCurrentCrs = Usr_CheckIfIBelongToCrs (Gbl.CurrentCrs.Crs.CrsCod);
|
||||
else
|
||||
Gbl.Usrs.Me.IBelongToCurrentCrs = false;
|
||||
if (Gbl.Usrs.Me.IBelongToCurrentCrs)
|
||||
Gbl.Usrs.Me.UsrDat.Accepted = false;
|
||||
if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected
|
||||
if ((Gbl.Usrs.Me.IBelongToCurrentCrs = Usr_CheckIfIBelongToCurrentCrs ()))
|
||||
Gbl.Usrs.Me.UsrDat.Accepted = Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
true);
|
||||
else
|
||||
Gbl.Usrs.Me.UsrDat.Accepted = false;
|
||||
|
||||
/***** Check if I belong to current degree *****/
|
||||
if (Gbl.CurrentDeg.Deg.DegCod > 0)
|
||||
|
@ -2970,8 +2991,11 @@ static void Usr_SetUsrRoleAndPrefs (void)
|
|||
else
|
||||
Gbl.Usrs.Me.AvailableRoles = (1 << Rol_GST);
|
||||
}
|
||||
else // No course selected
|
||||
Gbl.Usrs.Me.AvailableRoles = (1 << Gbl.Usrs.Me.MaxRole);
|
||||
else if (Gbl.Usrs.Me.MaxRole >= Rol_STD)
|
||||
Gbl.Usrs.Me.AvailableRoles = (1 << Rol_USR);
|
||||
else
|
||||
Gbl.Usrs.Me.AvailableRoles = (1 << Rol_GST);
|
||||
|
||||
if (ICanBeInsAdm)
|
||||
Gbl.Usrs.Me.AvailableRoles |= (1 << Rol_INS_ADM);
|
||||
if (ICanBeCtrAdm)
|
||||
|
|
|
@ -276,6 +276,7 @@ bool Usr_CheckIfIBelongToIns (long InsCod);
|
|||
bool Usr_CheckIfIBelongToCtr (long CtrCod);
|
||||
bool Usr_CheckIfIBelongToDeg (long DegCod);
|
||||
bool Usr_CheckIfIBelongToCrs (long CrsCod);
|
||||
bool Usr_CheckIfIBelongToCurrentCrs (void);
|
||||
|
||||
unsigned Usr_GetCtysFromUsr (long UsrCod,MYSQL_RES **mysql_res);
|
||||
unsigned long Usr_GetInssFromUsr (long UsrCod,long CtyCod,MYSQL_RES **mysql_res);
|
||||
|
|
Loading…
Reference in New Issue