Version 16.217

This commit is contained in:
Antonio Cañas Vargas 2017-05-18 20:40:57 +02:00
parent 489c687c77
commit dbb475d30e
6 changed files with 62 additions and 33 deletions

View File

@ -233,13 +233,14 @@
/****************************** Public constants *****************************/ /****************************** 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 CSS_FILE "swad16.209.3.css"
#define JS_FILE "swad16.206.3.js" #define JS_FILE "swad16.206.3.js"
// 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 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.216: May 18, 2017 Role visitor is renamed as role user. (218867 lines)
Version 16.215.4: May 18, 2017 Changed layout of assignments. Version 16.215.4: May 18, 2017 Changed layout of assignments.
Removed alert with number of users notified via email. (218868 lines) Removed alert with number of users notified via email. (218868 lines)

View File

@ -79,13 +79,19 @@ unsigned Rol_GetNumAvailableRoles (void)
/************ Get maximum role of a user in all his/her courses **************/ /************ 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)) if (Roles & (1 << Rol_TCH))
return Rol_TCH; return Rol_TCH;
/* Not a teacher. Check then if user is a student in any course */
if (Roles & (1 << Rol_STD)) if (Roles & (1 << Rol_STD))
return 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]; char Query[256];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; 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) if (CrsCod > 0)
{ {
@ -207,14 +213,10 @@ Rol_Role_t Rol_GetRoleInCrs (long CrsCod,long UsrCod)
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
Role = Rol_ConvertUnsignedStrToRole (row[0]); Role = Rol_ConvertUnsignedStrToRole (row[0]);
} }
else // User does not belong to the course
Role = Rol_UNK;
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
} }
else // No course
Role = Rol_UNK;
return Role; return Role;
} }
@ -264,8 +266,9 @@ Rol_Role_t Rol_ConvertUnsignedStrToRole (const char *UnsignedStr)
unsigned UnsignedNum; unsigned UnsignedNum;
if (sscanf (UnsignedStr,"%u",&UnsignedNum) == 1) if (sscanf (UnsignedStr,"%u",&UnsignedNum) == 1)
return (UnsignedNum >= Rol_NUM_ROLES) ? Rol_UNK : if (UnsignedNum < Rol_NUM_ROLES)
(Rol_Role_t) UnsignedNum; return (Rol_Role_t) UnsignedNum;
return Rol_UNK; return Rol_UNK;
} }

View File

@ -38,7 +38,7 @@
/*****************************************************************************/ /*****************************************************************************/
unsigned Rol_GetNumAvailableRoles (void); 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_GetMyMaxRoleInIns (long InsCod);
Rol_Role_t Rol_GetMyMaxRoleInCtr (long CtrCod); Rol_Role_t Rol_GetMyMaxRoleInCtr (long CtrCod);
Rol_Role_t Rol_GetMyMaxRoleInDeg (long DegCod); Rol_Role_t Rol_GetMyMaxRoleInDeg (long DegCod);

View File

@ -1019,7 +1019,7 @@ static void Svy_SetAllowedAndHiddenScopes (unsigned *ScopesAllowed,
if (Usr_CheckIfIBelongToDeg (Gbl.CurrentDeg.Deg.DegCod)) if (Usr_CheckIfIBelongToDeg (Gbl.CurrentDeg.Deg.DegCod))
{ {
*ScopesAllowed |= 1 << Sco_SCOPE_DEG; *ScopesAllowed |= 1 << Sco_SCOPE_DEG;
if (Usr_CheckIfIBelongToCrs (Gbl.CurrentCrs.Crs.CrsCod)) if (Usr_CheckIfIBelongToCurrentCrs ())
*ScopesAllowed |= 1 << Sco_SCOPE_CRS; *ScopesAllowed |= 1 << Sco_SCOPE_CRS;
} }
} }
@ -1041,7 +1041,7 @@ static void Svy_SetAllowedAndHiddenScopes (unsigned *ScopesAllowed,
if (Usr_CheckIfIBelongToDeg (Gbl.CurrentDeg.Deg.DegCod)) if (Usr_CheckIfIBelongToDeg (Gbl.CurrentDeg.Deg.DegCod))
{ {
*ScopesAllowed |= 1 << Sco_SCOPE_DEG; *ScopesAllowed |= 1 << Sco_SCOPE_DEG;
if (Usr_CheckIfIBelongToCrs (Gbl.CurrentCrs.Crs.CrsCod)) if (Usr_CheckIfIBelongToCurrentCrs ())
{ {
*ScopesAllowed |= 1 << Sco_SCOPE_CRS; *ScopesAllowed |= 1 << Sco_SCOPE_CRS;
*HiddenAllowed |= 1 << Sco_SCOPE_CRS; // A teacher can view hidden course surveys *HiddenAllowed |= 1 << Sco_SCOPE_CRS; // A teacher can view hidden course surveys

View File

@ -489,13 +489,14 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat)
Pwd_BYTES_ENCRYPTED_PASSWORD); Pwd_BYTES_ENCRYPTED_PASSWORD);
/* Get roles */ /* 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 UsrDat->Roles = -1; // Force roles to be got from database
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat); Rol_GetRolesInAllCrssIfNotYetGot (UsrDat);
if (UsrDat->RoleInCurrentCrsDB == Rol_UNK) if (UsrDat->RoleInCurrentCrsDB == Rol_UNK)
UsrDat->RoleInCurrentCrsDB = (UsrDat->Roles < (1 << Rol_STD)) ? UsrDat->RoleInCurrentCrsDB = (UsrDat->Roles < (1 << Rol_STD)) ?
Rol_GST : // User does not belong to any course Rol_GST : // User does not belong to any course
Rol_USR; // User belongs to some courses Rol_USR; // User belongs to some courses
/* Get name */ /* Get name */
Str_Copy (UsrDat->Surname1,row[2], Str_Copy (UsrDat->Surname1,row[2],
@ -1777,6 +1778,25 @@ bool Usr_CheckIfIBelongToCrs (long CrsCod)
return false; 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 ******************/ /**************** 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) static void Usr_SetUsrRoleAndPrefs (void)
@ -2877,16 +2897,20 @@ static void Usr_SetUsrRoleAndPrefs (void)
Hie_InitHierarchy (); Hie_InitHierarchy ();
/* Get again my role in this course */ /* 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 *****/ /***** Set the user's role I am logged *****/
Rol_GetRolesInAllCrssIfNotYetGot (&Gbl.Usrs.Me.UsrDat); // Get my roles if not yet got 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.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.RoleFromSession; // Get logged role from session Gbl.Usrs.Me.UsrDat.RoleInCurrentCrsDB) :
Gbl.Usrs.Me.RoleFromSession; // Get logged role from session
/***** Construct the path to my directory *****/ /***** Construct the path to my directory *****/
Usr_ConstructPathUsr (Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Usrs.Me.PathDir); Usr_ConstructPathUsr (Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Usrs.Me.PathDir);
@ -2916,16 +2940,13 @@ static void Usr_SetUsrRoleAndPrefs (void)
} }
/***** Check if I belong to current course *****/ /***** Check if I belong to current course *****/
if (Gbl.CurrentCrs.Crs.CrsCod > 0) Gbl.Usrs.Me.IBelongToCurrentCrs = false;
Gbl.Usrs.Me.IBelongToCurrentCrs = Usr_CheckIfIBelongToCrs (Gbl.CurrentCrs.Crs.CrsCod); Gbl.Usrs.Me.UsrDat.Accepted = false;
else if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected
Gbl.Usrs.Me.IBelongToCurrentCrs = false; if ((Gbl.Usrs.Me.IBelongToCurrentCrs = Usr_CheckIfIBelongToCurrentCrs ()))
if (Gbl.Usrs.Me.IBelongToCurrentCrs) Gbl.Usrs.Me.UsrDat.Accepted = Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Me.UsrDat.Accepted = Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.CurrentCrs.Crs.CrsCod,
Gbl.CurrentCrs.Crs.CrsCod, true);
true);
else
Gbl.Usrs.Me.UsrDat.Accepted = false;
/***** Check if I belong to current degree *****/ /***** Check if I belong to current degree *****/
if (Gbl.CurrentDeg.Deg.DegCod > 0) if (Gbl.CurrentDeg.Deg.DegCod > 0)
@ -2970,8 +2991,11 @@ static void Usr_SetUsrRoleAndPrefs (void)
else else
Gbl.Usrs.Me.AvailableRoles = (1 << Rol_GST); Gbl.Usrs.Me.AvailableRoles = (1 << Rol_GST);
} }
else // No course selected else if (Gbl.Usrs.Me.MaxRole >= Rol_STD)
Gbl.Usrs.Me.AvailableRoles = (1 << Gbl.Usrs.Me.MaxRole); Gbl.Usrs.Me.AvailableRoles = (1 << Rol_USR);
else
Gbl.Usrs.Me.AvailableRoles = (1 << Rol_GST);
if (ICanBeInsAdm) if (ICanBeInsAdm)
Gbl.Usrs.Me.AvailableRoles |= (1 << Rol_INS_ADM); Gbl.Usrs.Me.AvailableRoles |= (1 << Rol_INS_ADM);
if (ICanBeCtrAdm) if (ICanBeCtrAdm)

View File

@ -276,6 +276,7 @@ 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);
bool Usr_CheckIfIBelongToCrs (long CrsCod); bool Usr_CheckIfIBelongToCrs (long CrsCod);
bool Usr_CheckIfIBelongToCurrentCrs (void);
unsigned Usr_GetCtysFromUsr (long UsrCod,MYSQL_RES **mysql_res); unsigned Usr_GetCtysFromUsr (long UsrCod,MYSQL_RES **mysql_res);
unsigned long Usr_GetInssFromUsr (long UsrCod,long CtyCod,MYSQL_RES **mysql_res); unsigned long Usr_GetInssFromUsr (long UsrCod,long CtyCod,MYSQL_RES **mysql_res);