Version18.93

This commit is contained in:
Antonio Cañas Vargas 2019-04-01 23:15:17 +02:00
parent cd04ddb7ea
commit f37095da1c
20 changed files with 380 additions and 249 deletions

View File

@ -1412,8 +1412,8 @@ CREATE TABLE IF NOT EXISTS usr_IDs (
CREATE TABLE IF NOT EXISTS usr_last ( CREATE TABLE IF NOT EXISTS usr_last (
UsrCod INT NOT NULL, UsrCod INT NOT NULL,
WhatToSearch TINYINT NOT NULL DEFAULT 0, WhatToSearch TINYINT NOT NULL DEFAULT 0,
LastCrs INT NOT NULL DEFAULT -1, LastSco ENUM('Unk','Sys','Cty','Ins','Ctr','Deg','Crs') NOT NULL DEFAULT 'Unk',
LastTab TINYINT NOT NULL, LastCod INT NOT NULL DEFAULT -1,
LastAct INT NOT NULL DEFAULT -1, LastAct INT NOT NULL DEFAULT -1,
LastRole TINYINT NOT NULL DEFAULT 0, LastRole TINYINT NOT NULL DEFAULT 0,
LastTime DATETIME NOT NULL, LastTime DATETIME NOT NULL,

View File

@ -5180,6 +5180,7 @@ void Act_AdjustCurrentAction (void)
bool IAmATeacherInAnyCrs; bool IAmATeacherInAnyCrs;
bool JustAfterLogin = Gbl.Action.Act == ActLogIn || bool JustAfterLogin = Gbl.Action.Act == ActLogIn ||
Gbl.Action.Act == ActLogInLan || Gbl.Action.Act == ActLogInLan ||
Gbl.Action.Act == ActLogInNew ||
Gbl.Action.Act == ActAnnSee; Gbl.Action.Act == ActAnnSee;
/***** Don't adjust anything when: /***** Don't adjust anything when:

View File

@ -464,10 +464,18 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf ps2pdf source.ps destination.pdf
*/ */
#define Log_PLATFORM_VERSION "SWAD 18.92.3 (2019-04-01)" #define Log_PLATFORM_VERSION "SWAD 18.93 (2019-04-01)"
#define CSS_FILE "swad18.92.css" #define CSS_FILE "swad18.92.css"
#define JS_FILE "swad18.92.js" #define JS_FILE "swad18.92.js"
/* /*
Version 18.93: Apr 01, 2019 When a user logs in, hierarchy, action and role are got from database. (241533 lines)
5 changes necessary in database:
ALTER TABLE usr_last ADD COLUMN LastSco ENUM('Unk','Sys','Cty','Ins','Ctr','Deg','Crs') NOT NULL DEFAULT 'Unk' AFTER LastCrs;
ALTER TABLE usr_last ADD COLUMN LastCod INT NOT NULL DEFAULT -1 AFTER LastSco;
UPDATE usr_last SET LastSco='Crs',LastCod=LastCrs WHERE LastCrs>0;
ALTER TABLE usr_last DROP COLUMN LastCrs;
ALTER TABLE usr_last DROP COLUMN LastTab;
Version 18.92.3: Apr 01, 2019 Last action and role are saved in database. (241410 lines) Version 18.92.3: Apr 01, 2019 Last action and role are saved in database. (241410 lines)
2 changes necessary in database: 2 changes necessary in database:
ALTER TABLE usr_last ADD COLUMN LastAct INT NOT NULL DEFAULT -1 AFTER LastTab; ALTER TABLE usr_last ADD COLUMN LastAct INT NOT NULL DEFAULT -1 AFTER LastTab;

View File

@ -2970,26 +2970,26 @@ mysql> DESCRIBE usr_IDs;
/***** Table usr_last *****/ /***** Table usr_last *****/
/* /*
mysql> DESCRIBE usr_last; mysql> DESCRIBE usr_last;
+--------------+------------+------+-----+---------+-------+ +--------------+-------------------------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra | | Field | Type | Null | Key | Default | Extra |
+--------------+------------+------+-----+---------+-------+ +--------------+-------------------------------------------------+------+-----+---------+-------+
| UsrCod | int(11) | NO | PRI | NULL | | | UsrCod | int(11) | NO | PRI | NULL | |
| WhatToSearch | tinyint(4) | NO | | 0 | | | WhatToSearch | tinyint(4) | NO | | 0 | |
| LastCrs | int(11) | NO | | -1 | | | LastSco | enum('Unk','Sys','Cty','Ins','Ctr','Deg','Crs') | NO | | Unk | |
| LastTab | tinyint(4) | NO | | NULL | | | LastCod | int(11) | NO | | -1 | |
| LastAct | int(11) | NO | | -1 | | | LastAct | int(11) | NO | | -1 | |
| LastRole | tinyint(4) | NO | | 0 | | | LastRole | tinyint(4) | NO | | 0 | |
| LastTime | datetime | NO | MUL | NULL | | | LastTime | datetime | NO | MUL | NULL | |
| LastAccNotif | datetime | NO | | NULL | | | LastAccNotif | datetime | NO | | NULL | |
| TimelineUsrs | tinyint(4) | NO | | 0 | | | TimelineUsrs | tinyint(4) | NO | | 0 | |
+--------------+------------+------+-----+---------+-------+ +--------------+-------------------------------------------------+------+-----+---------+-------+
9 rows in set (0.00 sec) 9 rows in set (0.01 sec)
*/ */
DB_CreateTable ("CREATE TABLE IF NOT EXISTS usr_last (" DB_CreateTable ("CREATE TABLE IF NOT EXISTS usr_last ("
"UsrCod INT NOT NULL," "UsrCod INT NOT NULL,"
"WhatToSearch TINYINT NOT NULL DEFAULT 0," "WhatToSearch TINYINT NOT NULL DEFAULT 0,"
"LastCrs INT NOT NULL DEFAULT -1," "LastSco ENUM('Unk','Sys','Cty','Ins','Ctr','Deg','Crs') NOT NULL DEFAULT 'Unk',"
"LastTab TINYINT NOT NULL," "LastCod INT NOT NULL DEFAULT -1,"
"LastAct INT NOT NULL DEFAULT -1," "LastAct INT NOT NULL DEFAULT -1,"
"LastRole TINYINT NOT NULL DEFAULT 0," "LastRole TINYINT NOT NULL DEFAULT 0,"
"LastTime DATETIME NOT NULL," "LastTime DATETIME NOT NULL,"

View File

@ -128,7 +128,6 @@ static void Deg_PutParamGoToDeg (void);
void Deg_SeeDegWithPendingCrss (void) void Deg_SeeDegWithPendingCrss (void)
{ {
extern const char *Hlp_SYSTEM_Hierarchy_pending; extern const char *Hlp_SYSTEM_Hierarchy_pending;
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
extern const char *Txt_Degrees_with_pending_courses; extern const char *Txt_Degrees_with_pending_courses;
extern const char *Txt_Degree; extern const char *Txt_Degree;
extern const char *Txt_Courses_ABBREVIATION; extern const char *Txt_Courses_ABBREVIATION;
@ -153,7 +152,8 @@ void Deg_SeeDegWithPendingCrss (void)
" AND (courses.Status & %u)<>0" " AND (courses.Status & %u)<>0"
" AND courses.DegCod=degrees.DegCod" " AND courses.DegCod=degrees.DegCod"
" GROUP BY courses.DegCod ORDER BY degrees.ShortName", " GROUP BY courses.DegCod ORDER BY degrees.ShortName",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG], Gbl.Usrs.Me.UsrDat.UsrCod,
Sco_GetDBStrFromScope (Sco_SCOPE_DEG),
(unsigned) Crs_STATUS_BIT_PENDING); (unsigned) Crs_STATUS_BIT_PENDING);
break; break;
case Rol_SYS_ADM: case Rol_SYS_ADM:
@ -1838,7 +1838,6 @@ long Deg_GetInsCodOfDegreeByCod (long DegCod)
void Deg_RemoveDegreeCompletely (long DegCod) void Deg_RemoveDegreeCompletely (long DegCod)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRow,NumRows; unsigned long NumRow,NumRows;
@ -1890,7 +1889,7 @@ void Deg_RemoveDegreeCompletely (long DegCod)
/***** Remove administrators of this degree *****/ /***** Remove administrators of this degree *****/
DB_QueryDELETE ("can not remove administrators of a degree", DB_QueryDELETE ("can not remove administrators of a degree",
"DELETE FROM admin WHERE Scope='%s' AND Cod=%ld", "DELETE FROM admin WHERE Scope='%s' AND Cod=%ld",
Sco_ScopeDB[Sco_SCOPE_DEG],DegCod); Sco_GetDBStrFromScope (Sco_SCOPE_DEG),DegCod);
/***** Remove the degree *****/ /***** Remove the degree *****/
DB_QueryDELETE ("can not remove a degree", DB_QueryDELETE ("can not remove a degree",
@ -2406,7 +2405,6 @@ unsigned Deg_GetNumDegsWithUsrs (Rol_Role_t Role,const char *SubQuery)
void Hie_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan) void Hie_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
extern const char *Txt_all_degrees; extern const char *Txt_all_degrees;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
@ -2443,10 +2441,10 @@ void Hie_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan)
" AND admin.Scope='%s'" " AND admin.Scope='%s'"
" AND admin.Cod=degrees.DegCod)" " AND admin.Cod=degrees.DegCod)"
" ORDER BY S,FullName", " ORDER BY S,FullName",
(unsigned) Sco_SCOPE_SYS,UsrCod,Sco_ScopeDB[Sco_SCOPE_SYS], (unsigned) Sco_SCOPE_SYS,UsrCod,Sco_GetDBStrFromScope (Sco_SCOPE_SYS),
(unsigned) Sco_SCOPE_INS,UsrCod,Sco_ScopeDB[Sco_SCOPE_INS], (unsigned) Sco_SCOPE_INS,UsrCod,Sco_GetDBStrFromScope (Sco_SCOPE_INS),
(unsigned) Sco_SCOPE_CTR,UsrCod,Sco_ScopeDB[Sco_SCOPE_CTR], (unsigned) Sco_SCOPE_CTR,UsrCod,Sco_GetDBStrFromScope (Sco_SCOPE_CTR),
(unsigned) Sco_SCOPE_DEG,UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG]); (unsigned) Sco_SCOPE_DEG,UsrCod,Sco_GetDBStrFromScope (Sco_SCOPE_DEG));
if (NumRows) if (NumRows)
/***** Get the list of degrees *****/ /***** Get the list of degrees *****/
for (NumRow = 1; for (NumRow = 1;

View File

@ -2236,7 +2236,6 @@ void Enr_UpdateEnrolmentRequests (void)
static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected) static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{ {
extern const char *Hlp_USERS_Requests; extern const char *Hlp_USERS_Requests;
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
extern const char *The_ClassFormInBox[The_NUM_THEMES]; extern const char *The_ClassFormInBox[The_NUM_THEMES];
extern const char *Txt_Enrolment_requests; extern const char *Txt_Enrolment_requests;
extern const char *Txt_Scope; extern const char *Txt_Scope;
@ -2358,7 +2357,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND courses.CrsCod=crs_usr_requests.CrsCod" " AND courses.CrsCod=crs_usr_requests.CrsCod"
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_GetDBStrFromScope (Sco_SCOPE_DEG),
RolesSelected); RolesSelected);
break; break;
case Rol_CTR_ADM: case Rol_CTR_ADM:
@ -2377,7 +2376,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND courses.CrsCod=crs_usr_requests.CrsCod" " AND courses.CrsCod=crs_usr_requests.CrsCod"
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_CTR], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_GetDBStrFromScope (Sco_SCOPE_CTR),
RolesSelected); RolesSelected);
break; break;
case Rol_INS_ADM: case Rol_INS_ADM:
@ -2397,7 +2396,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND courses.CrsCod=crs_usr_requests.CrsCod" " AND courses.CrsCod=crs_usr_requests.CrsCod"
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_INS], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_GetDBStrFromScope (Sco_SCOPE_INS),
RolesSelected); RolesSelected);
break; break;
case Rol_SYS_ADM: case Rol_SYS_ADM:
@ -2466,7 +2465,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND courses.CrsCod=crs_usr_requests.CrsCod" " AND courses.CrsCod=crs_usr_requests.CrsCod"
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_GetDBStrFromScope (Sco_SCOPE_DEG),
Gbl.CurrentCty.Cty.CtyCod, Gbl.CurrentCty.Cty.CtyCod,
RolesSelected); RolesSelected);
break; break;
@ -2489,7 +2488,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND courses.CrsCod=crs_usr_requests.CrsCod" " AND courses.CrsCod=crs_usr_requests.CrsCod"
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_CTR], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_GetDBStrFromScope (Sco_SCOPE_CTR),
Gbl.CurrentCty.Cty.CtyCod, Gbl.CurrentCty.Cty.CtyCod,
RolesSelected); RolesSelected);
break; break;
@ -2512,7 +2511,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND courses.CrsCod=crs_usr_requests.CrsCod" " AND courses.CrsCod=crs_usr_requests.CrsCod"
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_INS], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_GetDBStrFromScope (Sco_SCOPE_INS),
Gbl.CurrentCty.Cty.CtyCod, Gbl.CurrentCty.Cty.CtyCod,
RolesSelected); RolesSelected);
break; break;
@ -2586,7 +2585,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND courses.CrsCod=crs_usr_requests.CrsCod" " AND courses.CrsCod=crs_usr_requests.CrsCod"
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_GetDBStrFromScope (Sco_SCOPE_DEG),
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
RolesSelected); RolesSelected);
break; break;
@ -2608,7 +2607,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND courses.CrsCod=crs_usr_requests.CrsCod" " AND courses.CrsCod=crs_usr_requests.CrsCod"
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_CTR], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_GetDBStrFromScope (Sco_SCOPE_CTR),
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
RolesSelected); RolesSelected);
break; break;
@ -2680,7 +2679,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND courses.CrsCod=crs_usr_requests.CrsCod" " AND courses.CrsCod=crs_usr_requests.CrsCod"
" AND ((1<<crs_usr_requests.Role)&%u)<>0" " AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC", " ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG], Gbl.Usrs.Me.UsrDat.UsrCod,Sco_GetDBStrFromScope (Sco_SCOPE_DEG),
Gbl.CurrentCtr.Ctr.CtrCod, Gbl.CurrentCtr.Ctr.CtrCod,
RolesSelected); RolesSelected);
break; break;
@ -3399,7 +3398,6 @@ static void Enr_AddAdm (Sco_Scope_t Scope,long Cod,const char *InsCtrDegName)
static void Enr_RegisterAdmin (struct UsrData *UsrDat,Sco_Scope_t Scope,long Cod,const char *InsCtrDegName) static void Enr_RegisterAdmin (struct UsrData *UsrDat,Sco_Scope_t Scope,long Cod,const char *InsCtrDegName)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
extern const char *Txt_THE_USER_X_is_already_an_administrator_of_Y; extern const char *Txt_THE_USER_X_is_already_an_administrator_of_Y;
extern const char *Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y; extern const char *Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y;
@ -3415,7 +3413,7 @@ static void Enr_RegisterAdmin (struct UsrData *UsrDat,Sco_Scope_t Scope,long Cod
" (UsrCod,Scope,Cod)" " (UsrCod,Scope,Cod)"
" VALUES" " VALUES"
" (%ld,'%s',%ld)", " (%ld,'%s',%ld)",
UsrDat->UsrCod,Sco_ScopeDB[Scope],Cod); UsrDat->UsrCod,Sco_GetDBStrFromScope (Scope),Cod);
Ale_ShowAlert (Ale_SUCCESS,Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y, Ale_ShowAlert (Ale_SUCCESS,Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y,
UsrDat->FullName,InsCtrDegName); UsrDat->FullName,InsCtrDegName);
@ -4242,7 +4240,6 @@ static void Enr_AskIfRemAdm (bool ItsMe,Sco_Scope_t Scope,
static void Enr_EffectivelyRemAdm (struct UsrData *UsrDat,Sco_Scope_t Scope, static void Enr_EffectivelyRemAdm (struct UsrData *UsrDat,Sco_Scope_t Scope,
long Cod,const char *InsCtrDegName) long Cod,const char *InsCtrDegName)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
extern const char *Txt_THE_USER_X_has_been_removed_as_administrator_of_Y; extern const char *Txt_THE_USER_X_has_been_removed_as_administrator_of_Y;
extern const char *Txt_THE_USER_X_is_not_an_administrator_of_Y; extern const char *Txt_THE_USER_X_is_not_an_administrator_of_Y;
@ -4252,7 +4249,7 @@ static void Enr_EffectivelyRemAdm (struct UsrData *UsrDat,Sco_Scope_t Scope,
DB_QueryDELETE ("can not remove an administrator", DB_QueryDELETE ("can not remove an administrator",
"DELETE FROM admin" "DELETE FROM admin"
" WHERE UsrCod=%ld AND Scope='%s' AND Cod=%ld", " WHERE UsrCod=%ld AND Scope='%s' AND Cod=%ld",
UsrDat->UsrCod,Sco_ScopeDB[Scope],Cod); UsrDat->UsrCod,Sco_GetDBStrFromScope (Scope),Cod);
Ale_ShowAlert (Ale_SUCCESS,Txt_THE_USER_X_has_been_removed_as_administrator_of_Y, Ale_ShowAlert (Ale_SUCCESS,Txt_THE_USER_X_has_been_removed_as_administrator_of_Y,
UsrDat->FullName,InsCtrDegName); UsrDat->FullName,InsCtrDegName);

View File

@ -877,7 +877,6 @@ static void Gam_PutParams (void)
void Gam_GetListGames (void) void Gam_GetListGames (void)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
char *SubQuery[Sco_NUM_SCOPES]; char *SubQuery[Sco_NUM_SCOPES];
static const char *OrderBySubQuery[Gam_NUM_ORDERS] = static const char *OrderBySubQuery[Gam_NUM_ORDERS] =
{ {
@ -918,7 +917,7 @@ void Gam_GetListGames (void)
if (asprintf (&SubQuery[Scope],"%s(Scope='%s' AND Cod=%ld%s)", if (asprintf (&SubQuery[Scope],"%s(Scope='%s' AND Cod=%ld%s)",
SubQueryFilled ? " OR " : SubQueryFilled ? " OR " :
"", "",
Sco_ScopeDB[Scope],Cods[Scope], Sco_GetDBStrFromScope (Scope),Cods[Scope],
(HiddenAllowed & 1 << Scope) ? "" : (HiddenAllowed & 1 << Scope) ? "" :
" AND Hidden='N'") < 0) " AND Hidden='N'") < 0)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
@ -949,7 +948,7 @@ void Gam_GetListGames (void)
")", ")",
SubQueryFilled ? " OR " : SubQueryFilled ? " OR " :
"", "",
Sco_ScopeDB[Sco_SCOPE_CRS],Cods[Sco_SCOPE_CRS], Sco_GetDBStrFromScope (Sco_SCOPE_CRS),Cods[Sco_SCOPE_CRS],
(HiddenAllowed & 1 << Sco_SCOPE_CRS) ? "" : (HiddenAllowed & 1 << Sco_SCOPE_CRS) ? "" :
" AND Hidden='N'", " AND Hidden='N'",
Gbl.Usrs.Me.UsrDat.UsrCod) < 0) Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
@ -960,7 +959,7 @@ void Gam_GetListGames (void)
if (asprintf (&SubQuery[Sco_SCOPE_CRS],"%s(Scope='%s' AND Cod=%ld%s)", if (asprintf (&SubQuery[Sco_SCOPE_CRS],"%s(Scope='%s' AND Cod=%ld%s)",
SubQueryFilled ? " OR " : SubQueryFilled ? " OR " :
"", "",
Sco_ScopeDB[Sco_SCOPE_CRS],Cods[Sco_SCOPE_CRS], Sco_GetDBStrFromScope (Sco_SCOPE_CRS),Cods[Sco_SCOPE_CRS],
(HiddenAllowed & 1 << Sco_SCOPE_CRS) ? "" : (HiddenAllowed & 1 << Sco_SCOPE_CRS) ? "" :
" AND Hidden='N'") < 0) " AND Hidden='N'") < 0)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
@ -1707,14 +1706,12 @@ void Gam_UnhideGame (void)
static bool Gam_CheckIfSimilarGameExists (struct Game *Game) static bool Gam_CheckIfSimilarGameExists (struct Game *Game)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
/***** Get number of games with a field value from database *****/ /***** Get number of games with a field value from database *****/
return (DB_QueryCOUNT ("can not get similar games", return (DB_QueryCOUNT ("can not get similar games",
"SELECT COUNT(*) FROM games" "SELECT COUNT(*) FROM games"
" WHERE Scope='%s' AND Cod=%ld" " WHERE Scope='%s' AND Cod=%ld"
" AND Title='%s' AND GamCod<>%ld", " AND Title='%s' AND GamCod<>%ld",
Sco_ScopeDB[Game->Scope],Game->Cod, Sco_GetDBStrFromScope (Game->Scope),Game->Cod,
Game->Title,Game->GamCod) != 0); Game->Title,Game->GamCod) != 0);
} }
@ -2172,7 +2169,6 @@ void Gam_RecFormGame (void)
static void Gam_CreateGame (struct Game *Game,const char *Txt) static void Gam_CreateGame (struct Game *Game,const char *Txt)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
extern const char *Txt_Created_new_game_X; extern const char *Txt_Created_new_game_X;
/***** Create a new game *****/ /***** Create a new game *****/
@ -2184,7 +2180,7 @@ static void Gam_CreateGame (struct Game *Game,const char *Txt)
" ('%s',%ld,'N',%u,%ld," " ('%s',%ld,'N',%u,%ld,"
"FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld)," "FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld),"
"'%s','%s')", "'%s','%s')",
Sco_ScopeDB[Game->Scope],Game->Cod, Sco_GetDBStrFromScope (Game->Scope),Game->Cod,
Game->Roles, Game->Roles,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Game->TimeUTC[Gam_START_TIME], Game->TimeUTC[Gam_START_TIME],
@ -2207,7 +2203,6 @@ static void Gam_CreateGame (struct Game *Game,const char *Txt)
static void Gam_UpdateGame (struct Game *Game,const char *Txt) static void Gam_UpdateGame (struct Game *Game,const char *Txt)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
extern const char *Txt_The_game_has_been_modified; extern const char *Txt_The_game_has_been_modified;
/***** Update the data of the game *****/ /***** Update the data of the game *****/
@ -2218,7 +2213,7 @@ static void Gam_UpdateGame (struct Game *Game,const char *Txt)
"EndTime=FROM_UNIXTIME(%ld)," "EndTime=FROM_UNIXTIME(%ld),"
"Title='%s',Txt='%s'" "Title='%s',Txt='%s'"
" WHERE GamCod=%ld", " WHERE GamCod=%ld",
Sco_ScopeDB[Game->Scope],Game->Cod, Sco_GetDBStrFromScope (Game->Scope),Game->Cod,
Game->Roles, Game->Roles,
Game->TimeUTC[Gam_START_TIME], Game->TimeUTC[Gam_START_TIME],
Game->TimeUTC[Gam_END_TIME ], Game->TimeUTC[Gam_END_TIME ],
@ -2398,8 +2393,6 @@ static void Gam_GetAndWriteNamesOfGrpsAssociatedToGame (struct Game *Game)
void Gam_RemoveGames (Sco_Scope_t Scope,long Cod) void Gam_RemoveGames (Sco_Scope_t Scope,long Cod)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
/***** Remove all the users in course games *****/ /***** Remove all the users in course games *****/
DB_QueryDELETE ("can not remove users who had answered games" DB_QueryDELETE ("can not remove users who had answered games"
" in a place on the hierarchy", " in a place on the hierarchy",
@ -2407,7 +2400,7 @@ void Gam_RemoveGames (Sco_Scope_t Scope,long Cod)
" USING games,gam_users" " USING games,gam_users"
" WHERE games.Scope='%s' AND games.Cod=%ld" " WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_users.GamCod", " AND games.GamCod=gam_users.GamCod",
Sco_ScopeDB[Scope],Cod); Sco_GetDBStrFromScope (Scope),Cod);
/***** Remove all the answers in course games *****/ /***** Remove all the answers in course games *****/
DB_QueryDELETE ("can not remove answers of games" DB_QueryDELETE ("can not remove answers of games"
@ -2417,7 +2410,7 @@ void Gam_RemoveGames (Sco_Scope_t Scope,long Cod)
" WHERE games.Scope='%s' AND games.Cod=%ld" " WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_questions.GamCod" " AND games.GamCod=gam_questions.GamCod"
" AND gam_questions.QstCod=gam_answers.QstCod", " AND gam_questions.QstCod=gam_answers.QstCod",
Sco_ScopeDB[Scope],Cod); Sco_GetDBStrFromScope (Scope),Cod);
/***** Remove all the questions in course games *****/ /***** Remove all the questions in course games *****/
DB_QueryDELETE ("can not remove questions of games" DB_QueryDELETE ("can not remove questions of games"
@ -2426,7 +2419,7 @@ void Gam_RemoveGames (Sco_Scope_t Scope,long Cod)
" USING games,gam_questions" " USING games,gam_questions"
" WHERE games.Scope='%s' AND games.Cod=%ld" " WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_questions.GamCod", " AND games.GamCod=gam_questions.GamCod",
Sco_ScopeDB[Scope],Cod); Sco_GetDBStrFromScope (Scope),Cod);
/***** Remove groups *****/ /***** Remove groups *****/
DB_QueryDELETE ("can not remove all the groups" DB_QueryDELETE ("can not remove all the groups"
@ -2435,12 +2428,12 @@ void Gam_RemoveGames (Sco_Scope_t Scope,long Cod)
" USING games,gam_grp" " USING games,gam_grp"
" WHERE games.Scope='%s' AND games.Cod=%ld" " WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_grp.GamCod", " AND games.GamCod=gam_grp.GamCod",
Sco_ScopeDB[Scope],Cod); Sco_GetDBStrFromScope (Scope),Cod);
/***** Remove course games *****/ /***** Remove course games *****/
DB_QueryDELETE ("can not remove all the games in a place on the hierarchy", DB_QueryDELETE ("can not remove all the games in a place on the hierarchy",
"DELETE FROM games WHERE Scope='%s' AND Cod=%ld", "DELETE FROM games WHERE Scope='%s' AND Cod=%ld",
Sco_ScopeDB[Scope],Cod); Sco_GetDBStrFromScope (Scope),Cod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3796,7 +3789,6 @@ static unsigned Gam_GetNumUsrsWhoHaveAnsweredGame (long GamCod)
unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope) unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumCourses; unsigned NumCourses;
@ -3809,7 +3801,7 @@ unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope)
"SELECT COUNT(DISTINCT Cod)" "SELECT COUNT(DISTINCT Cod)"
" FROM games" " FROM games"
" WHERE Scope='%s'", " WHERE Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of courses with games", DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
@ -3822,7 +3814,7 @@ unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope)
" AND courses.CrsCod=games.Cod" " AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'", " AND games.Scope='%s'",
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_QuerySELECT (&mysql_res,"can not get number of courses with games", DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
@ -3834,7 +3826,7 @@ unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope)
" AND courses.CrsCod=games.Cod" " AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'", " AND games.Scope='%s'",
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of courses with games", DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
@ -3844,7 +3836,7 @@ unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope)
" AND courses.CrsCod=games.Cod" " AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'", " AND games.Scope='%s'",
Gbl.CurrentCtr.Ctr.CtrCod, Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of courses with games", DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
@ -3854,14 +3846,14 @@ unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope)
" AND courses.CrsCod=games.Cod" " AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'", " AND games.Scope='%s'",
Gbl.CurrentDeg.Deg.DegCod, Gbl.CurrentDeg.Deg.DegCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of courses with games", DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
"SELECT COUNT(DISTINCT Cod)" "SELECT COUNT(DISTINCT Cod)"
" FROM games" " FROM games"
" WHERE Scope='%s' AND Cod=%ld", " WHERE Scope='%s' AND Cod=%ld",
Sco_ScopeDB[Sco_SCOPE_CRS], Sco_GetDBStrFromScope (Sco_SCOPE_CRS),
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
@ -3887,7 +3879,6 @@ unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope)
unsigned Gam_GetNumGames (Sco_Scope_t Scope) unsigned Gam_GetNumGames (Sco_Scope_t Scope)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumGames; unsigned NumGames;
@ -3900,7 +3891,7 @@ unsigned Gam_GetNumGames (Sco_Scope_t Scope)
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM games" " FROM games"
" WHERE Scope='%s'", " WHERE Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of games", DB_QuerySELECT (&mysql_res,"can not get number of games",
@ -3913,7 +3904,7 @@ unsigned Gam_GetNumGames (Sco_Scope_t Scope)
" AND courses.CrsCod=games.Cod" " AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'", " AND games.Scope='%s'",
Gbl.CurrentCty.Cty.CtyCod, Gbl.CurrentCty.Cty.CtyCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_QuerySELECT (&mysql_res,"can not get number of games", DB_QuerySELECT (&mysql_res,"can not get number of games",
@ -3925,7 +3916,7 @@ unsigned Gam_GetNumGames (Sco_Scope_t Scope)
" AND courses.CrsCod=games.Cod" " AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'", " AND games.Scope='%s'",
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of games", DB_QuerySELECT (&mysql_res,"can not get number of games",
@ -3936,7 +3927,7 @@ unsigned Gam_GetNumGames (Sco_Scope_t Scope)
" AND courses.CrsCod=games.Cod" " AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'", " AND games.Scope='%s'",
Gbl.CurrentCtr.Ctr.CtrCod, Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of games", DB_QuerySELECT (&mysql_res,"can not get number of games",
@ -3946,7 +3937,7 @@ unsigned Gam_GetNumGames (Sco_Scope_t Scope)
" AND courses.CrsCod=games.Cod" " AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'", " AND games.Scope='%s'",
Gbl.CurrentDeg.Deg.DegCod, Gbl.CurrentDeg.Deg.DegCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of games", DB_QuerySELECT (&mysql_res,"can not get number of games",
@ -3954,7 +3945,7 @@ unsigned Gam_GetNumGames (Sco_Scope_t Scope)
" FROM games" " FROM games"
" WHERE games.Scope='%s'" " WHERE games.Scope='%s'"
" AND CrsCod=%ld", " AND CrsCod=%ld",
Sco_ScopeDB[Sco_SCOPE_CRS], Sco_GetDBStrFromScope (Sco_SCOPE_CRS),
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
@ -3979,7 +3970,6 @@ unsigned Gam_GetNumGames (Sco_Scope_t Scope)
float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope) float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
float NumQstsPerGame; float NumQstsPerGame;
@ -3995,7 +3985,7 @@ float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
" WHERE games.Scope='%s'" " WHERE games.Scope='%s'"
" AND games.GamCod=gam_questions.GamCod" " AND games.GamCod=gam_questions.GamCod"
" GROUP BY gam_questions.GamCod) AS NumQstsTable", " GROUP BY gam_questions.GamCod) AS NumQstsTable",
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of questions per game", DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
@ -4011,7 +4001,7 @@ float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
" AND games.GamCod=gam_questions.GamCod" " AND games.GamCod=gam_questions.GamCod"
" GROUP BY gam_questions.GamCod) AS NumQstsTable", " GROUP BY gam_questions.GamCod) AS NumQstsTable",
Gbl.CurrentCty.Cty.CtyCod, Gbl.CurrentCty.Cty.CtyCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_QuerySELECT (&mysql_res,"can not get number of questions per game", DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
@ -4026,7 +4016,7 @@ float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
" AND games.GamCod=gam_questions.GamCod" " AND games.GamCod=gam_questions.GamCod"
" GROUP BY gam_questions.GamCod) AS NumQstsTable", " GROUP BY gam_questions.GamCod) AS NumQstsTable",
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of questions per game", DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
@ -4040,7 +4030,7 @@ float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
" AND games.GamCod=gam_questions.GamCod" " AND games.GamCod=gam_questions.GamCod"
" GROUP BY gam_questions.GamCod) AS NumQstsTable", " GROUP BY gam_questions.GamCod) AS NumQstsTable",
Gbl.CurrentCtr.Ctr.CtrCod, Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of questions per game", DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
@ -4053,7 +4043,7 @@ float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
" AND games.GamCod=gam_questions.GamCod" " AND games.GamCod=gam_questions.GamCod"
" GROUP BY gam_questions.GamCod) AS NumQstsTable", " GROUP BY gam_questions.GamCod) AS NumQstsTable",
Gbl.CurrentDeg.Deg.DegCod, Gbl.CurrentDeg.Deg.DegCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of questions per game", DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
@ -4063,7 +4053,7 @@ float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
" WHERE games.Scope='%s' AND games.Cod=%ld" " WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_questions.GamCod" " AND games.GamCod=gam_questions.GamCod"
" GROUP BY gam_questions.GamCod) AS NumQstsTable", " GROUP BY gam_questions.GamCod) AS NumQstsTable",
Sco_ScopeDB[Sco_SCOPE_CRS],Gbl.CurrentCrs.Crs.CrsCod); Sco_GetDBStrFromScope (Sco_SCOPE_CRS),Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();

View File

@ -242,6 +242,9 @@ void Gbl_InitializeGlobals (void)
Gbl.CurrentCrs.Info.ShowMsgMustBeRead = 0; Gbl.CurrentCrs.Info.ShowMsgMustBeRead = 0;
Gbl.CurrentCrs.Notices.HighlightNotCod = -1L; // No notice highlighted Gbl.CurrentCrs.Notices.HighlightNotCod = -1L; // No notice highlighted
Gbl.Hierarchy.Scope = Sco_SCOPE_UNK;
Gbl.Hierarchy.Cod = -1L;
Gbl.Inss.Num = 0; Gbl.Inss.Num = 0;
Gbl.Inss.Lst = NULL; Gbl.Inss.Lst = NULL;
Gbl.Inss.SelectedOrder = Ins_ORDER_DEFAULT; Gbl.Inss.SelectedOrder = Ins_ORDER_DEFAULT;

View File

@ -450,6 +450,11 @@ struct Globals
Sco_Scope_t Default; Sco_Scope_t Default;
unsigned Allowed; unsigned Allowed;
} Scope; } Scope;
struct
{
Sco_Scope_t Scope;
long Cod;
} Hierarchy;
struct struct
{ {
struct Country Cty; struct Country Cty;

View File

@ -448,6 +448,83 @@ void Hie_WriteBigNameCtyInsCtrDegCrs (void)
"</h1>"); "</h1>");
} }
/*****************************************************************************/
/***** Set current hierarchy depending on course code, degree code, etc. *****/
/*****************************************************************************/
void Hie_SetCurrentHierarchy (void)
{
if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected
{
Gbl.Hierarchy.Scope = Sco_SCOPE_CRS;
Gbl.Hierarchy.Cod = Gbl.CurrentCrs.Crs.CrsCod;
}
else if (Gbl.CurrentDeg.Deg.DegCod > 0) // Degree selected
{
Gbl.Hierarchy.Scope = Sco_SCOPE_DEG;
Gbl.Hierarchy.Cod = Gbl.CurrentDeg.Deg.DegCod;
}
else if (Gbl.CurrentCtr.Ctr.CtrCod > 0) // Centre selected
{
Gbl.Hierarchy.Scope = Sco_SCOPE_CTR;
Gbl.Hierarchy.Cod = Gbl.CurrentCtr.Ctr.CtrCod;
}
else if (Gbl.CurrentIns.Ins.InsCod > 0) // Institution selected
{
Gbl.Hierarchy.Scope = Sco_SCOPE_INS;
Gbl.Hierarchy.Cod = Gbl.CurrentIns.Ins.InsCod;
}
else if (Gbl.CurrentCty.Cty.CtyCod > 0) // Country selected
{
Gbl.Hierarchy.Scope = Sco_SCOPE_CTY;
Gbl.Hierarchy.Cod = Gbl.CurrentCty.Cty.CtyCod;
}
else
{
Gbl.Hierarchy.Scope = Sco_SCOPE_SYS;
Gbl.Hierarchy.Cod = -1L;
}
}
/*****************************************************************************/
/**************** Copy last hierarchy to current hierarchy *******************/
/*****************************************************************************/
void Hie_SetHierarchyFromUsrLastHierarchy (void)
{
/***** Initialize all codes to -1 *****/
Gbl.CurrentCty.Cty.CtyCod =
Gbl.CurrentIns.Ins.InsCod =
Gbl.CurrentCtr.Ctr.CtrCod =
Gbl.CurrentDeg.Deg.DegCod =
Gbl.CurrentCrs.Crs.CrsCod = -1L;
/***** Copy last hierarchy scope and code to current hierarchy *****/
switch (Gbl.Usrs.Me.UsrLast.LastHie.Scope)
{
case Sco_SCOPE_CTY: // Country
Gbl.CurrentCty.Cty.CtyCod = Gbl.Usrs.Me.UsrLast.LastHie.Cod;
break;
case Sco_SCOPE_INS: // Institution
Gbl.CurrentIns.Ins.InsCod = Gbl.Usrs.Me.UsrLast.LastHie.Cod;
break;
case Sco_SCOPE_CTR: // Centre
Gbl.CurrentCtr.Ctr.CtrCod = Gbl.Usrs.Me.UsrLast.LastHie.Cod;
break;
case Sco_SCOPE_DEG: // Degree
Gbl.CurrentDeg.Deg.DegCod = Gbl.Usrs.Me.UsrLast.LastHie.Cod;
break;
case Sco_SCOPE_CRS: // Course
Gbl.CurrentCrs.Crs.CrsCod = Gbl.Usrs.Me.UsrLast.LastHie.Cod;
break;
default:
break;
}
/****** Initialize again current course, degree, centre... ******/
Hie_InitHierarchy ();
}
/*****************************************************************************/ /*****************************************************************************/
/**** Initialize current country, institution, centre, degree and course *****/ /**** Initialize current country, institution, centre, degree and course *****/
/*****************************************************************************/ /*****************************************************************************/
@ -533,6 +610,9 @@ void Hie_InitHierarchy (void)
} }
} }
/***** Set current hierarchy depending on course code, degree code, etc. *****/
Hie_SetCurrentHierarchy ();
/***** Initialize default fields for edition to current values *****/ /***** Initialize default fields for edition to current values *****/
Gbl.Inss.EditingIns.CtyCod = Gbl.CurrentCty.Cty.CtyCod; Gbl.Inss.EditingIns.CtyCod = Gbl.CurrentCty.Cty.CtyCod;
Gbl.Ctrs.EditingCtr.InsCod = Gbl.Ctrs.EditingCtr.InsCod =

View File

@ -50,6 +50,9 @@ void Hie_SeePending (void);
void Hie_WriteMenuHierarchy (void); void Hie_WriteMenuHierarchy (void);
void Hie_WriteHierarchyInBreadcrumb (void); void Hie_WriteHierarchyInBreadcrumb (void);
void Hie_WriteBigNameCtyInsCtrDegCrs (void); void Hie_WriteBigNameCtyInsCtrDegCrs (void);
void Hie_SetCurrentHierarchy (void);
void Hie_SetHierarchyFromUsrLastHierarchy (void);
void Hie_InitHierarchy (void); void Hie_InitHierarchy (void);
void Hie_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan); void Hie_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan);

View File

@ -31,6 +31,7 @@
#include <unistd.h> // For sleep #include <unistd.h> // For sleep
#include "swad_action.h" #include "swad_action.h"
#include "swad_announcement.h"
#include "swad_config.h" #include "swad_config.h"
#include "swad_connected.h" #include "swad_connected.h"
#include "swad_database.h" #include "swad_database.h"
@ -41,6 +42,7 @@
#include "swad_notification.h" #include "swad_notification.h"
#include "swad_parameter.h" #include "swad_parameter.h"
#include "swad_setting.h" #include "swad_setting.h"
#include "swad_user.h"
/*****************************************************************************/ /*****************************************************************************/
/******************************** Constants **********************************/ /******************************** Constants **********************************/
@ -155,6 +157,21 @@ int main (void)
/***** Start writing HTML output *****/ /***** Start writing HTML output *****/
Lay_WriteStartOfPage (); Lay_WriteStartOfPage ();
/***** If I am been redirected from another action... *****/
switch (Gbl.Action.Original)
{
case ActLogIn:
case ActLogInNew:
case ActLogInLan:
Usr_WelcomeUsr ();
break;
case ActAnnSee:
Ann_MarkAnnouncementAsSeen ();
break;
default:
break;
}
/***** Make a processing or other depending on the action *****/ /***** Make a processing or other depending on the action *****/
FunctionPosteriori = Act_GetFunctionPosteriori (Gbl.Action.Act); FunctionPosteriori = Act_GetFunctionPosteriori (Gbl.Action.Act);
if (FunctionPosteriori != NULL) if (FunctionPosteriori != NULL)

View File

@ -1167,7 +1167,6 @@ void Ntf_MarkNotifFilesInGroupAsRemoved (long GrpCod)
unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRow; unsigned long NumRow;
@ -1303,10 +1302,10 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
" OR (Scope='%s' AND Cod=%ld)" " OR (Scope='%s' AND Cod=%ld)"
" OR (Scope='%s' AND Cod=%ld))" " OR (Scope='%s' AND Cod=%ld))"
" AND UsrCod<>%ld", " AND UsrCod<>%ld",
Sco_ScopeDB[Sco_SCOPE_SYS], Sco_GetDBStrFromScope (Sco_SCOPE_SYS),
Sco_ScopeDB[Sco_SCOPE_INS],Gbl.CurrentIns.Ins.InsCod, Sco_GetDBStrFromScope (Sco_SCOPE_INS),Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CTR],Gbl.CurrentCtr.Ctr.CtrCod, Sco_GetDBStrFromScope (Sco_SCOPE_CTR),Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_DEG],Gbl.CurrentDeg.Deg.DegCod, Sco_GetDBStrFromScope (Sco_SCOPE_DEG),Gbl.CurrentDeg.Deg.DegCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
} }
break; break;
@ -1390,11 +1389,11 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
" AND (surveys.Roles&(1<<crs_usr.Role))<>0)", " AND (surveys.Roles&(1<<crs_usr.Role))<>0)",
Cod, Cod,
Cod, Cod,
Sco_ScopeDB[Sco_SCOPE_CRS], Sco_GetDBStrFromScope (Sco_SCOPE_CRS),
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Cod, Cod,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
} }

View File

@ -93,10 +93,25 @@ void Rol_SetMyRoles (void)
/***** 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.Role.Max = Rol_GetMaxRoleInCrss ((unsigned) Gbl.Usrs.Me.UsrDat.Roles.InCrss); Gbl.Usrs.Me.Role.Max = Rol_GetMaxRoleInCrss ((unsigned) Gbl.Usrs.Me.UsrDat.Roles.InCrss);
Gbl.Usrs.Me.Role.Logged = (Gbl.Usrs.Me.Role.FromSession == Rol_UNK) ? // If no logged role retrieved from session...
((Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role == Rol_UNK) ? Rol_USR : /***** Set the user's role I am logged *****/
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role) : // My logged role is retrieved in this order from:
Gbl.Usrs.Me.Role.FromSession; // Get logged role from session // 1. It may have been retrieved from last data stored in database just after login
// 2. If it is not known, it will be retrieved from current session
// 3. If a course is selected, it will be retrieved from my role in this course
// 4. If none of the former options is satisfied, it will be set to user role
if (Gbl.Usrs.Me.Role.Logged == Rol_UNK) // No role from last data
{
if (Gbl.Usrs.Me.Role.FromSession == Rol_UNK) // No role from session
{
if (Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role == Rol_UNK) // No role in current course
Gbl.Usrs.Me.Role.Logged = Rol_USR; // User
else
Gbl.Usrs.Me.Role.Logged = Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role; // Role in current course
}
else
Gbl.Usrs.Me.Role.Logged = Gbl.Usrs.Me.Role.FromSession; // Role from session
}
/***** Check if I am administrator of current institution/centre/degree *****/ /***** Check if I am administrator of current institution/centre/degree *****/
if (Gbl.CurrentIns.Ins.InsCod > 0) if (Gbl.CurrentIns.Ins.InsCod > 0)
@ -191,8 +206,9 @@ void Rol_SetMyRoles (void)
if (Usr_CheckIfUsrIsSuperuser (Gbl.Usrs.Me.UsrDat.UsrCod)) if (Usr_CheckIfUsrIsSuperuser (Gbl.Usrs.Me.UsrDat.UsrCod))
Gbl.Usrs.Me.Role.Available |= (1 << Rol_SYS_ADM); Gbl.Usrs.Me.Role.Available |= (1 << Rol_SYS_ADM);
/***** Check if the role I am logged is now available for me *****/ /***** Check if the role I am logged is now available for me (it's not forbidden) *****/
if (!(Gbl.Usrs.Me.Role.Available & (1 << Gbl.Usrs.Me.Role.Logged))) // Current type I am logged is not available for me if (!(Gbl.Usrs.Me.Role.Available &
(1 << Gbl.Usrs.Me.Role.Logged))) // Current type I am logged is not available for me
/* Set the lowest role available for me */ /* Set the lowest role available for me */
for (Gbl.Usrs.Me.Role.Logged = Rol_UNK; for (Gbl.Usrs.Me.Role.Logged = Rol_UNK;
Gbl.Usrs.Me.Role.Logged <= (Rol_Role_t) (Rol_NUM_ROLES - 1); Gbl.Usrs.Me.Role.Logged <= (Rol_Role_t) (Rol_NUM_ROLES - 1);

View File

@ -36,17 +36,6 @@
/****************************** Public constants *****************************/ /****************************** Public constants *****************************/
/*****************************************************************************/ /*****************************************************************************/
const char *Sco_ScopeDB[Sco_NUM_SCOPES] =
{
"Unk", // Sco_SCOPE_UNK
"Sys", // Sco_SCOPE_SYS
"Cty", // Sco_SCOPE_CTY
"Ins", // Sco_SCOPE_INS
"Ctr", // Sco_SCOPE_CTR
"Deg", // Sco_SCOPE_DEG
"Crs", // Sco_SCOPE_CRS
};
/*****************************************************************************/ /*****************************************************************************/
/***************************** Internal constants ****************************/ /***************************** Internal constants ****************************/
/*****************************************************************************/ /*****************************************************************************/
@ -334,8 +323,31 @@ Sco_Scope_t Sco_GetScopeFromDBStr (const char *ScopeDBStr)
for (Scope = Sco_SCOPE_UNK; for (Scope = Sco_SCOPE_UNK;
Scope < Sco_NUM_SCOPES; Scope < Sco_NUM_SCOPES;
Scope++) Scope++)
if (!strcmp (Sco_ScopeDB[Scope],ScopeDBStr)) if (!strcmp (Sco_GetDBStrFromScope (Scope),ScopeDBStr))
return Scope; return Scope;
return Sco_SCOPE_UNK; return Sco_SCOPE_UNK;
} }
/*****************************************************************************/
/*********************** Get scope from database string **********************/
/*****************************************************************************/
const char *Sco_GetDBStrFromScope (Sco_Scope_t Scope)
{
static const char *Sco_ScopeDB[Sco_NUM_SCOPES] =
{
"Unk", // Sco_SCOPE_UNK
"Sys", // Sco_SCOPE_SYS
"Cty", // Sco_SCOPE_CTY
"Ins", // Sco_SCOPE_INS
"Ctr", // Sco_SCOPE_CTR
"Deg", // Sco_SCOPE_DEG
"Crs", // Sco_SCOPE_CRS
};
if (Scope >= Sco_NUM_SCOPES)
Scope = Sco_SCOPE_UNK;
return Sco_ScopeDB[Scope];
}

View File

@ -64,5 +64,6 @@ void Sco_SetScopesForListingStudents (void);
Sco_Scope_t Sco_GetScopeFromUnsignedStr (const char *UnsignedStr); Sco_Scope_t Sco_GetScopeFromUnsignedStr (const char *UnsignedStr);
Sco_Scope_t Sco_GetScopeFromDBStr (const char *ScopeDBStr); Sco_Scope_t Sco_GetScopeFromDBStr (const char *ScopeDBStr);
const char *Sco_GetDBStrFromScope (Sco_Scope_t Scope);
#endif #endif

View File

@ -841,7 +841,6 @@ static void Svy_PutParams (void)
void Svy_GetListSurveys (void) void Svy_GetListSurveys (void)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
char *SubQuery[Sco_NUM_SCOPES]; char *SubQuery[Sco_NUM_SCOPES];
static const char *OrderBySubQuery[Svy_NUM_ORDERS] = static const char *OrderBySubQuery[Svy_NUM_ORDERS] =
{ {
@ -882,7 +881,7 @@ void Svy_GetListSurveys (void)
if (asprintf (&SubQuery[Scope],"%s(Scope='%s' AND Cod=%ld%s)", if (asprintf (&SubQuery[Scope],"%s(Scope='%s' AND Cod=%ld%s)",
SubQueryFilled ? " OR " : SubQueryFilled ? " OR " :
"", "",
Sco_ScopeDB[Scope],Cods[Scope], Sco_GetDBStrFromScope (Scope),Cods[Scope],
(HiddenAllowed & 1 << Scope) ? "" : (HiddenAllowed & 1 << Scope) ? "" :
" AND Hidden='N'") < 0) " AND Hidden='N'") < 0)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
@ -913,7 +912,7 @@ void Svy_GetListSurveys (void)
")", ")",
SubQueryFilled ? " OR " : SubQueryFilled ? " OR " :
"", "",
Sco_ScopeDB[Sco_SCOPE_CRS],Cods[Sco_SCOPE_CRS], Sco_GetDBStrFromScope (Sco_SCOPE_CRS),Cods[Sco_SCOPE_CRS],
(HiddenAllowed & 1 << Sco_SCOPE_CRS) ? "" : (HiddenAllowed & 1 << Sco_SCOPE_CRS) ? "" :
" AND Hidden='N'", " AND Hidden='N'",
Gbl.Usrs.Me.UsrDat.UsrCod) < 0) Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
@ -924,7 +923,7 @@ void Svy_GetListSurveys (void)
if (asprintf (&SubQuery[Sco_SCOPE_CRS],"%s(Scope='%s' AND Cod=%ld%s)", if (asprintf (&SubQuery[Sco_SCOPE_CRS],"%s(Scope='%s' AND Cod=%ld%s)",
SubQueryFilled ? " OR " : SubQueryFilled ? " OR " :
"", "",
Sco_ScopeDB[Sco_SCOPE_CRS],Cods[Sco_SCOPE_CRS], Sco_GetDBStrFromScope (Sco_SCOPE_CRS),Cods[Sco_SCOPE_CRS],
(HiddenAllowed & 1 << Sco_SCOPE_CRS) ? "" : (HiddenAllowed & 1 << Sco_SCOPE_CRS) ? "" :
" AND Hidden='N'") < 0) " AND Hidden='N'") < 0)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
@ -1752,14 +1751,12 @@ void Svy_UnhideSurvey (void)
static bool Svy_CheckIfSimilarSurveyExists (struct Survey *Svy) static bool Svy_CheckIfSimilarSurveyExists (struct Survey *Svy)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
/***** Get number of surveys with a field value from database *****/ /***** Get number of surveys with a field value from database *****/
return (DB_QueryCOUNT ("can not get similar surveys", return (DB_QueryCOUNT ("can not get similar surveys",
"SELECT COUNT(*) FROM surveys" "SELECT COUNT(*) FROM surveys"
" WHERE Scope='%s' AND Cod=%ld" " WHERE Scope='%s' AND Cod=%ld"
" AND Title='%s' AND SvyCod<>%ld", " AND Title='%s' AND SvyCod<>%ld",
Sco_ScopeDB[Svy->Scope],Svy->Cod, Sco_GetDBStrFromScope (Svy->Scope),Svy->Cod,
Svy->Title,Svy->SvyCod) != 0); Svy->Title,Svy->SvyCod) != 0);
} }
@ -2245,7 +2242,6 @@ static void Svy_UpdateNumUsrsNotifiedByEMailAboutSurvey (long SvyCod,
static void Svy_CreateSurvey (struct Survey *Svy,const char *Txt) static void Svy_CreateSurvey (struct Survey *Svy,const char *Txt)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
extern const char *Txt_Created_new_survey_X; extern const char *Txt_Created_new_survey_X;
/***** Create a new survey *****/ /***** Create a new survey *****/
@ -2257,7 +2253,7 @@ static void Svy_CreateSurvey (struct Survey *Svy,const char *Txt)
" ('%s',%ld,'N',%u,%ld," " ('%s',%ld,'N',%u,%ld,"
"FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld)," "FROM_UNIXTIME(%ld),FROM_UNIXTIME(%ld),"
"'%s','%s')", "'%s','%s')",
Sco_ScopeDB[Svy->Scope],Svy->Cod, Sco_GetDBStrFromScope (Svy->Scope),Svy->Cod,
Svy->Roles, Svy->Roles,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Svy->TimeUTC[Svy_START_TIME], Svy->TimeUTC[Svy_START_TIME],
@ -2280,7 +2276,6 @@ static void Svy_CreateSurvey (struct Survey *Svy,const char *Txt)
static void Svy_UpdateSurvey (struct Survey *Svy,const char *Txt) static void Svy_UpdateSurvey (struct Survey *Svy,const char *Txt)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
extern const char *Txt_The_survey_has_been_modified; extern const char *Txt_The_survey_has_been_modified;
/***** Update the data of the survey *****/ /***** Update the data of the survey *****/
@ -2291,7 +2286,7 @@ static void Svy_UpdateSurvey (struct Survey *Svy,const char *Txt)
"EndTime=FROM_UNIXTIME(%ld)," "EndTime=FROM_UNIXTIME(%ld),"
"Title='%s',Txt='%s'" "Title='%s',Txt='%s'"
" WHERE SvyCod=%ld", " WHERE SvyCod=%ld",
Sco_ScopeDB[Svy->Scope],Svy->Cod, Sco_GetDBStrFromScope (Svy->Scope),Svy->Cod,
Svy->Roles, Svy->Roles,
Svy->TimeUTC[Svy_START_TIME], Svy->TimeUTC[Svy_START_TIME],
Svy->TimeUTC[Svy_END_TIME ], Svy->TimeUTC[Svy_END_TIME ],
@ -2472,8 +2467,6 @@ static void Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (struct Survey *Svy)
void Svy_RemoveSurveys (Sco_Scope_t Scope,long Cod) void Svy_RemoveSurveys (Sco_Scope_t Scope,long Cod)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
/***** Remove all the users in course surveys *****/ /***** Remove all the users in course surveys *****/
DB_QueryDELETE ("can not remove users" DB_QueryDELETE ("can not remove users"
" who had answered surveys in a place on the hierarchy", " who had answered surveys in a place on the hierarchy",
@ -2481,7 +2474,7 @@ void Svy_RemoveSurveys (Sco_Scope_t Scope,long Cod)
" USING surveys,svy_users" " USING surveys,svy_users"
" WHERE surveys.Scope='%s' AND surveys.Cod=%ld" " WHERE surveys.Scope='%s' AND surveys.Cod=%ld"
" AND surveys.SvyCod=svy_users.SvyCod", " AND surveys.SvyCod=svy_users.SvyCod",
Sco_ScopeDB[Scope],Cod); Sco_GetDBStrFromScope (Scope),Cod);
/***** Remove all the answers in course surveys *****/ /***** Remove all the answers in course surveys *****/
DB_QueryDELETE ("can not remove answers of surveys" DB_QueryDELETE ("can not remove answers of surveys"
@ -2491,7 +2484,7 @@ void Svy_RemoveSurveys (Sco_Scope_t Scope,long Cod)
" WHERE surveys.Scope='%s' AND surveys.Cod=%ld" " WHERE surveys.Scope='%s' AND surveys.Cod=%ld"
" AND surveys.SvyCod=svy_questions.SvyCod" " AND surveys.SvyCod=svy_questions.SvyCod"
" AND svy_questions.QstCod=svy_answers.QstCod", " AND svy_questions.QstCod=svy_answers.QstCod",
Sco_ScopeDB[Scope],Cod); Sco_GetDBStrFromScope (Scope),Cod);
/***** Remove all the questions in course surveys *****/ /***** Remove all the questions in course surveys *****/
DB_QueryDELETE ("can not remove questions of surveys" DB_QueryDELETE ("can not remove questions of surveys"
@ -2500,7 +2493,7 @@ void Svy_RemoveSurveys (Sco_Scope_t Scope,long Cod)
" USING surveys,svy_questions" " USING surveys,svy_questions"
" WHERE surveys.Scope='%s' AND surveys.Cod=%ld" " WHERE surveys.Scope='%s' AND surveys.Cod=%ld"
" AND surveys.SvyCod=svy_questions.SvyCod", " AND surveys.SvyCod=svy_questions.SvyCod",
Sco_ScopeDB[Scope],Cod); Sco_GetDBStrFromScope (Scope),Cod);
/***** Remove groups *****/ /***** Remove groups *****/
DB_QueryDELETE ("can not remove all the groups" DB_QueryDELETE ("can not remove all the groups"
@ -2509,14 +2502,14 @@ void Svy_RemoveSurveys (Sco_Scope_t Scope,long Cod)
" USING surveys,svy_grp" " USING surveys,svy_grp"
" WHERE surveys.Scope='%s' AND surveys.Cod=%ld" " WHERE surveys.Scope='%s' AND surveys.Cod=%ld"
" AND surveys.SvyCod=svy_grp.SvyCod", " AND surveys.SvyCod=svy_grp.SvyCod",
Sco_ScopeDB[Scope],Cod); Sco_GetDBStrFromScope (Scope),Cod);
/***** Remove course surveys *****/ /***** Remove course surveys *****/
DB_QueryDELETE ("can not remove all the surveys" DB_QueryDELETE ("can not remove all the surveys"
" in a place on the hierarchy", " in a place on the hierarchy",
"DELETE FROM surveys" "DELETE FROM surveys"
" WHERE Scope='%s' AND Cod=%ld", " WHERE Scope='%s' AND Cod=%ld",
Sco_ScopeDB[Scope],Cod); Sco_GetDBStrFromScope (Scope),Cod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3774,7 +3767,6 @@ static unsigned Svy_GetNumUsrsWhoHaveAnsweredSvy (long SvyCod)
unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope) unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumCourses; unsigned NumCourses;
@ -3788,7 +3780,7 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope)
"SELECT COUNT(DISTINCT Cod)" "SELECT COUNT(DISTINCT Cod)"
" FROM surveys" " FROM surveys"
" WHERE Scope='%s'", " WHERE Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of courses" DB_QuerySELECT (&mysql_res,"can not get number of courses"
@ -3802,7 +3794,7 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope)
" AND courses.CrsCod=surveys.Cod" " AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'", " AND surveys.Scope='%s'",
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_QuerySELECT (&mysql_res,"can not get number of courses" DB_QuerySELECT (&mysql_res,"can not get number of courses"
@ -3815,7 +3807,7 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope)
" AND courses.CrsCod=surveys.Cod" " AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'", " AND surveys.Scope='%s'",
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of courses" DB_QuerySELECT (&mysql_res,"can not get number of courses"
@ -3827,7 +3819,7 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope)
" AND courses.CrsCod=surveys.Cod" " AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'", " AND surveys.Scope='%s'",
Gbl.CurrentCtr.Ctr.CtrCod, Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of courses" DB_QuerySELECT (&mysql_res,"can not get number of courses"
@ -3838,7 +3830,7 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope)
" AND courses.CrsCod=surveys.Cod" " AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'", " AND surveys.Scope='%s'",
Gbl.CurrentDeg.Deg.DegCod, Gbl.CurrentDeg.Deg.DegCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of courses" DB_QuerySELECT (&mysql_res,"can not get number of courses"
@ -3846,7 +3838,7 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope)
"SELECT COUNT(DISTINCT Cod)" "SELECT COUNT(DISTINCT Cod)"
" FROM surveys" " FROM surveys"
" WHERE Scope='%s' AND Cod=%ld", " WHERE Scope='%s' AND Cod=%ld",
Sco_ScopeDB[Sco_SCOPE_CRS], Sco_GetDBStrFromScope (Sco_SCOPE_CRS),
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
@ -3873,7 +3865,6 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope)
unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif) unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumSurveys; unsigned NumSurveys;
@ -3886,7 +3877,7 @@ unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
"SELECT COUNT(*),SUM(NumNotif)" "SELECT COUNT(*),SUM(NumNotif)"
" FROM surveys" " FROM surveys"
" WHERE Scope='%s'", " WHERE Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of surveys", DB_QuerySELECT (&mysql_res,"can not get number of surveys",
@ -3899,7 +3890,7 @@ unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
" AND courses.CrsCod=surveys.Cod" " AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'", " AND surveys.Scope='%s'",
Gbl.CurrentCty.Cty.CtyCod, Gbl.CurrentCty.Cty.CtyCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_QuerySELECT (&mysql_res,"can not get number of surveys", DB_QuerySELECT (&mysql_res,"can not get number of surveys",
@ -3911,7 +3902,7 @@ unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
" AND courses.CrsCod=surveys.Cod" " AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'", " AND surveys.Scope='%s'",
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of surveys", DB_QuerySELECT (&mysql_res,"can not get number of surveys",
@ -3922,7 +3913,7 @@ unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
" AND courses.CrsCod=surveys.Cod" " AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'", " AND surveys.Scope='%s'",
Gbl.CurrentCtr.Ctr.CtrCod, Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of surveys", DB_QuerySELECT (&mysql_res,"can not get number of surveys",
@ -3932,7 +3923,7 @@ unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
" AND courses.CrsCod=surveys.Cod" " AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'", " AND surveys.Scope='%s'",
Gbl.CurrentDeg.Deg.DegCod, Gbl.CurrentDeg.Deg.DegCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of surveys", DB_QuerySELECT (&mysql_res,"can not get number of surveys",
@ -3940,7 +3931,7 @@ unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
" FROM surveys" " FROM surveys"
" WHERE surveys.Scope='%s'" " WHERE surveys.Scope='%s'"
" AND CrsCod=%ld", " AND CrsCod=%ld",
Sco_ScopeDB[Sco_SCOPE_CRS], Sco_GetDBStrFromScope (Sco_SCOPE_CRS),
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
@ -3974,7 +3965,6 @@ unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope) float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
float NumQstsPerSurvey; float NumQstsPerSurvey;
@ -3991,7 +3981,7 @@ float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope)
" WHERE surveys.Scope='%s'" " WHERE surveys.Scope='%s'"
" AND surveys.SvyCod=svy_questions.SvyCod" " AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of questions" DB_QuerySELECT (&mysql_res,"can not get number of questions"
@ -4008,7 +3998,7 @@ float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope)
" AND surveys.SvyCod=svy_questions.SvyCod" " AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.CurrentCty.Cty.CtyCod, Gbl.CurrentCty.Cty.CtyCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_QuerySELECT (&mysql_res,"can not get number of questions" DB_QuerySELECT (&mysql_res,"can not get number of questions"
@ -4024,7 +4014,7 @@ float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope)
" AND surveys.SvyCod=svy_questions.SvyCod" " AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of questions" DB_QuerySELECT (&mysql_res,"can not get number of questions"
@ -4039,7 +4029,7 @@ float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope)
" AND surveys.SvyCod=svy_questions.SvyCod" " AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.CurrentCtr.Ctr.CtrCod, Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of questions" DB_QuerySELECT (&mysql_res,"can not get number of questions"
@ -4053,7 +4043,7 @@ float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope)
" AND surveys.SvyCod=svy_questions.SvyCod" " AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.CurrentDeg.Deg.DegCod, Gbl.CurrentDeg.Deg.DegCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_GetDBStrFromScope (Sco_SCOPE_CRS));
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of questions" DB_QuerySELECT (&mysql_res,"can not get number of questions"
@ -4064,7 +4054,7 @@ float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope)
" WHERE surveys.Scope='%s' AND surveys.Cod=%ld" " WHERE surveys.Scope='%s' AND surveys.Cod=%ld"
" AND surveys.SvyCod=svy_questions.SvyCod" " AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Sco_ScopeDB[Sco_SCOPE_CRS],Gbl.CurrentCrs.Crs.CrsCod); Sco_GetDBStrFromScope (Sco_SCOPE_CRS),Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();

View File

@ -370,20 +370,6 @@ void TL_ShowTimelineGbl2 (void)
TL_TOP_MESSAGE_NONE, // Ntf_EVENT_ENROLMENT_NET // TODO: Move to users tab (also necessary in database) !!!!!!!!! TL_TOP_MESSAGE_NONE, // Ntf_EVENT_ENROLMENT_NET // TODO: Move to users tab (also necessary in database) !!!!!!!!!
}; };
/***** If I am been redirected from another action... *****/
switch (Gbl.Action.Original)
{
case ActLogIn:
case ActLogInLan:
Usr_WelcomeUsr ();
break;
case ActAnnSee:
Ann_MarkAnnouncementAsSeen ();
break;
default:
break;
}
/***** Initialize note code to -1 ==> no highlighted note *****/ /***** Initialize note code to -1 ==> no highlighted note *****/
SocNot.NotCod = -1L; SocNot.NotCod = -1L;

View File

@ -364,10 +364,12 @@ void Usr_ResetUsrDataExceptUsrCodAndIDs (struct UsrData *UsrDat)
void Usr_ResetMyLastData (void) void Usr_ResetMyLastData (void)
{ {
Gbl.Usrs.Me.UsrLast.WhatToSearch = Sch_WHAT_TO_SEARCH_DEFAULT; Gbl.Usrs.Me.UsrLast.WhatToSearch = Sch_WHAT_TO_SEARCH_DEFAULT;
Gbl.Usrs.Me.UsrLast.LastCrs = -1L; Gbl.Usrs.Me.UsrLast.LastHie.Scope = Sco_SCOPE_UNK;
Gbl.Usrs.Me.UsrLast.LastTab = TabUnk; Gbl.Usrs.Me.UsrLast.LastHie.Cod = -1L;
Gbl.Usrs.Me.UsrLast.LastAccNotif = 0; Gbl.Usrs.Me.UsrLast.LastAct = ActUnk;
Gbl.Usrs.Me.UsrLast.LastRole = Rol_UNK;
Gbl.Usrs.Me.UsrLast.LastAccNotif = 0;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -760,8 +762,8 @@ static void Usr_GetMyLastData (void)
/***** Get user's last data from database *****/ /***** Get user's last data from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get user's last data", NumRows = DB_QuerySELECT (&mysql_res,"can not get user's last data",
"SELECT WhatToSearch," // row[0] "SELECT WhatToSearch," // row[0]
"LastCrs," // row[1] "LastSco," // row[1]
"LastTab," // row[2] "LastCod," // row[2]
"LastAct," // row[3] "LastAct," // row[3]
"LastRole," // row[4] "LastRole," // row[4]
"UNIX_TIMESTAMP(LastAccNotif)" // row[5] "UNIX_TIMESTAMP(LastAccNotif)" // row[5]
@ -788,21 +790,36 @@ static void Usr_GetMyLastData (void)
if (Gbl.Usrs.Me.UsrLast.WhatToSearch == Sch_SEARCH_UNKNOWN) if (Gbl.Usrs.Me.UsrLast.WhatToSearch == Sch_SEARCH_UNKNOWN)
Gbl.Usrs.Me.UsrLast.WhatToSearch = Sch_WHAT_TO_SEARCH_DEFAULT; Gbl.Usrs.Me.UsrLast.WhatToSearch = Sch_WHAT_TO_SEARCH_DEFAULT;
/* Get last course (row[1]) */ /* Get last hierarchy: scope (row[1]) and code (row[2]) */
Gbl.Usrs.Me.UsrLast.LastCrs = Str_ConvertStrCodToLongCod (row[1]); Gbl.Usrs.Me.UsrLast.LastHie.Scope = Sco_GetScopeFromDBStr (row[1]);
switch (Gbl.Usrs.Me.UsrLast.LastHie.Scope)
/* Get last tab (row[2]) */ {
Gbl.Usrs.Me.UsrLast.LastTab = TabStr; // By default, set last tab to the start tab case Sco_SCOPE_SYS: // System
if (sscanf (row[2],"%u",&UnsignedNum) == 1) Gbl.Usrs.Me.UsrLast.LastHie.Cod = -1L;
if (UnsignedNum >= 1 || break;
UnsignedNum <= Tab_NUM_TABS) case Sco_SCOPE_CTY: // Country
Gbl.Usrs.Me.UsrLast.LastTab = (Tab_Tab_t) UnsignedNum; case Sco_SCOPE_INS: // Institution
case Sco_SCOPE_CTR: // Centre
case Sco_SCOPE_DEG: // Degree
case Sco_SCOPE_CRS: // Course
Gbl.Usrs.Me.UsrLast.LastHie.Cod = Str_ConvertStrCodToLongCod (row[2]);
if (Gbl.Usrs.Me.UsrLast.LastHie.Cod <= 0)
{
Gbl.Usrs.Me.UsrLast.LastHie.Scope = Sco_SCOPE_UNK;
Gbl.Usrs.Me.UsrLast.LastHie.Cod = -1L;
}
break;
default:
Gbl.Usrs.Me.UsrLast.LastHie.Scope = Sco_SCOPE_UNK;
Gbl.Usrs.Me.UsrLast.LastHie.Cod = -1L;
break;
}
/* Get last action (row[3]) */ /* Get last action (row[3]) */
ActCod = Str_ConvertStrCodToLongCod (row[3]); ActCod = Str_ConvertStrCodToLongCod (row[3]);
Gbl.Usrs.Me.UsrLast.LastAct = Act_GetActionFromActCod (ActCod); Gbl.Usrs.Me.UsrLast.LastAct = Act_GetActionFromActCod (ActCod);
/* Get last rolw (row[4]) */ /* Get last role (row[4]) */
Gbl.Usrs.Me.UsrLast.LastRole = Rol_ConvertUnsignedStrToRole (row[4]); Gbl.Usrs.Me.UsrLast.LastRole = Rol_ConvertUnsignedStrToRole (row[4]);
/* Get last access to notifications (row[5]) */ /* Get last access to notifications (row[5]) */
@ -897,17 +914,11 @@ void Usr_FlushCachesUsr (void)
bool Usr_CheckIfUsrIsAdm (long UsrCod,Sco_Scope_t Scope,long Cod) bool Usr_CheckIfUsrIsAdm (long UsrCod,Sco_Scope_t Scope,long Cod)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; /***** Get if a user is administrator of a degree from database *****/
return (DB_QueryCOUNT ("can not check if a user is administrator",
if (Sco_ScopeDB[Scope]) "SELECT COUNT(*) FROM admin"
{ " WHERE UsrCod=%ld AND Scope='%s' AND Cod=%ld",
/***** Get if a user is administrator of a degree from database *****/ UsrCod,Sco_GetDBStrFromScope (Scope),Cod) != 0);
return (DB_QueryCOUNT ("can not check if a user is administrator",
"SELECT COUNT(*) FROM admin"
" WHERE UsrCod=%ld AND Scope='%s' AND Cod=%ld",
UsrCod,Sco_ScopeDB[Scope],Cod) != 0);
}
return false;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -922,8 +933,6 @@ void Usr_FlushCacheUsrIsSuperuser (void)
bool Usr_CheckIfUsrIsSuperuser (long UsrCod) bool Usr_CheckIfUsrIsSuperuser (long UsrCod)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
/***** 1. Fast check: Trivial case *****/ /***** 1. Fast check: Trivial case *****/
if (UsrCod <= 0) if (UsrCod <= 0)
return false; return false;
@ -938,7 +947,7 @@ bool Usr_CheckIfUsrIsSuperuser (long UsrCod)
(DB_QueryCOUNT ("can not check if a user is superuser", (DB_QueryCOUNT ("can not check if a user is superuser",
"SELECT COUNT(*) FROM admin" "SELECT COUNT(*) FROM admin"
" WHERE UsrCod=%ld AND Scope='%s'", " WHERE UsrCod=%ld AND Scope='%s'",
UsrCod,Sco_ScopeDB[Sco_SCOPE_SYS]) != 0); UsrCod,Sco_GetDBStrFromScope (Sco_SCOPE_SYS)) != 0);
return Gbl.Cache.UsrIsSuperuser.IsSuperuser; return Gbl.Cache.UsrIsSuperuser.IsSuperuser;
} }
@ -3093,19 +3102,8 @@ void Usr_ChkUsrAndGetUsrData (void)
/***** Adjust tab and action *****/ /***** Adjust tab and action *****/
if (!Gbl.Action.UsesAJAX) if (!Gbl.Action.UsesAJAX)
{ {
if (Gbl.Usrs.Me.Logged) if (!Gbl.Usrs.Me.Logged && // No user logged...
{ Gbl.Action.Act == ActUnk) // ...and unknown action
/***** Set default tab when unknown *****/
if (Gbl.Action.Tab == TabUnk)
{
// Don't adjust Gbl.Action.Act here
Gbl.Action.Tab = ((Gbl.Usrs.Me.UsrLast.LastTab == TabCrs) &&
(Gbl.CurrentCrs.Crs.CrsCod <= 0)) ? TabStr :
Gbl.Usrs.Me.UsrLast.LastTab;
Tab_DisableIncompatibleTabs ();
}
}
else if (Gbl.Action.Act == ActUnk) // No user logged and unknown action
Act_AdjustActionWhenNoUsrLogged (); Act_AdjustActionWhenNoUsrLogged ();
/***** When I change to another tab, go to: /***** When I change to another tab, go to:
@ -3125,13 +3123,6 @@ void Usr_ChkUsrAndGetUsrData (void)
Action; Action;
Tab_SetCurrentTab (); Tab_SetCurrentTab ();
} }
/***** Update last data for next time *****/
// if (Gbl.Usrs.Me.Logged)
// {
// Usr_UpdateMyLastData ();
// Crs_UpdateCrsLast ();
// }
} }
} }
@ -3339,6 +3330,12 @@ static void Usr_SetMyPrefsAndRoles (void)
extern const char *The_ThemeId[The_NUM_THEMES]; extern const char *The_ThemeId[The_NUM_THEMES];
extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS]; extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS];
char URL[PATH_MAX + 1]; char URL[PATH_MAX + 1];
bool GetActionAndRoleFromLastData;
Act_Action_t LastSuperAction;
bool JustAfterLogin = Gbl.Action.Act == ActLogIn ||
Gbl.Action.Act == ActLogInLan ||
Gbl.Action.Act == ActLogInNew ||
Gbl.Action.Act == ActAnnSee;
// In this point I am logged // In this point I am logged
@ -3374,29 +3371,54 @@ static void Usr_SetMyPrefsAndRoles (void)
/***** Get my last data *****/ /***** Get my last data *****/
Usr_GetMyLastData (); Usr_GetMyLastData ();
if (Gbl.Action.Act == ActLogIn || if (JustAfterLogin) // If I just logged in...
Gbl.Action.Act == ActLogInNew) // If I just logged in...
{ {
/***** WhatToSearch is stored in session, /***** WhatToSearch is stored in session,
but in login it is got from user's last data *****/ but in login it is got from user's last data *****/
Gbl.Search.WhatToSearch = Gbl.Usrs.Me.UsrLast.WhatToSearch; Gbl.Search.WhatToSearch = Gbl.Usrs.Me.UsrLast.WhatToSearch;
/***** If no course selected, go to my last visited course *****/ /***** Location in hierarchy and role are stored in session,
if (Gbl.CurrentCrs.Crs.CrsCod <= 0 && but in login the are got from user's last data *****/
Gbl.Usrs.Me.UsrLast.LastCrs > 0) if (Gbl.Hierarchy.Scope == Sco_SCOPE_SYS) // No country selected
{ {
Gbl.CurrentCrs.Crs.CrsCod = Gbl.Usrs.Me.UsrLast.LastCrs; /***** Copy last hierarchy to current hierarchy *****/
Hie_SetHierarchyFromUsrLastHierarchy ();
/* Initialize again current course, degree, centre... */ /* Course may have changed ==> get my role in current course again */
Hie_InitHierarchy (); if (Gbl.CurrentCrs.Crs.CrsCod > 0)
{
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role = Rol_GetRoleUsrInCrs (Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.CurrentCrs.Crs.CrsCod);
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Valid = true;
}
/* Get again my role in this course */ // Action and role will be got from last data
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role = Rol_GetRoleUsrInCrs (Gbl.Usrs.Me.UsrDat.UsrCod, GetActionAndRoleFromLastData = true;
Gbl.CurrentCrs.Crs.CrsCod); }
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Valid = true; else // Country (and may be institution, centre, degree or course) selected
} // Action and role will be got from last data
// only if I am in the same hierarchy location that the stored one
GetActionAndRoleFromLastData =
(Gbl.Hierarchy.Scope == Gbl.Usrs.Me.UsrLast.LastHie.Scope && // The same scope...
Gbl.Hierarchy.Cod == Gbl.Usrs.Me.UsrLast.LastHie.Cod); // ...and code in hierarchy
/***** Get action and role from last data *****/
if (GetActionAndRoleFromLastData)
{
/* Get action from last data */
LastSuperAction = Act_GetSuperAction (Gbl.Usrs.Me.UsrLast.LastAct);
if (LastSuperAction != ActUnk)
{
Gbl.Action.Act = LastSuperAction;
Tab_SetCurrentTab ();
}
/* Get role from last data */
Gbl.Usrs.Me.Role.Logged = Gbl.Usrs.Me.UsrLast.LastRole;
}
} }
/***** Set my roles *****/
Rol_SetMyRoles (); Rol_SetMyRoles ();
} }
@ -3494,10 +3516,10 @@ void Usr_UpdateMyLastData (void)
// WhatToSearch, LastAccNotif remain unchanged // WhatToSearch, LastAccNotif remain unchanged
DB_QueryUPDATE ("can not update last user's data", DB_QueryUPDATE ("can not update last user's data",
"UPDATE usr_last" "UPDATE usr_last"
" SET LastCrs=%ld,LastTab=%u,LastAct=%ld,LastRole=%u,LastTime=NOW()" " SET LastSco='%s',LastCod=%ld,LastAct=%ld,LastRole=%u,LastTime=NOW()"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod, Sco_GetDBStrFromScope (Gbl.Hierarchy.Scope),
(unsigned) Gbl.Action.Tab, Gbl.Hierarchy.Cod,
Act_GetActCod (Gbl.Action.Act), Act_GetActCod (Gbl.Action.Act),
(unsigned) Gbl.Usrs.Me.Role.Logged, (unsigned) Gbl.Usrs.Me.Role.Logged,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
@ -3514,13 +3536,13 @@ static void Usr_InsertMyLastData (void)
/***** Insert my last accessed course, tab and time of click in database *****/ /***** Insert my last accessed course, tab and time of click in database *****/
DB_QueryINSERT ("can not insert last user's data", DB_QueryINSERT ("can not insert last user's data",
"INSERT INTO usr_last" "INSERT INTO usr_last"
" (UsrCod,WhatToSearch,LastCrs,LastTab,LastAct,LastRole,LastTime,LastAccNotif)" " (UsrCod,WhatToSearch,LastSco,LastCod,LastAct,LastRole,LastTime,LastAccNotif)"
" VALUES" " VALUES"
" (%ld,%u,%ld,%u,%ld,%u,NOW(),FROM_UNIXTIME(%ld))", " (%ld,%u,'%s',%ld,%ld,%u,NOW(),FROM_UNIXTIME(%ld))",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Sch_SEARCH_ALL, (unsigned) Sch_SEARCH_ALL,
Gbl.CurrentCrs.Crs.CrsCod, Sco_GetDBStrFromScope (Gbl.Hierarchy.Scope),
(unsigned) Gbl.Action.Tab, Gbl.Hierarchy.Cod,
Act_GetActCod (Gbl.Action.Act), Act_GetActCod (Gbl.Action.Act),
(unsigned) Gbl.Usrs.Me.Role.Logged, (unsigned) Gbl.Usrs.Me.Role.Logged,
(long) (time_t) 0); // The user never accessed to notifications (long) (time_t) 0); // The user never accessed to notifications
@ -5004,7 +5026,6 @@ void Usr_DropTmpTableWithCandidateUsrs (void)
static void Usr_GetAdmsLst (Sco_Scope_t Scope) static void Usr_GetAdmsLst (Sco_Scope_t Scope)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
const char *QueryFields = const char *QueryFields =
"UsrCod," "UsrCod,"
"EncryptedUsrCod," "EncryptedUsrCod,"
@ -5074,10 +5095,10 @@ static void Usr_GetAdmsLst (Sco_Scope_t Scope)
" AND institutions.CtyCod=%ld)" " AND institutions.CtyCod=%ld)"
" ORDER BY Surname1,Surname2,FirstName,UsrCod", " ORDER BY Surname1,Surname2,FirstName,UsrCod",
QueryFields, QueryFields,
Sco_ScopeDB[Sco_SCOPE_SYS], Sco_GetDBStrFromScope (Sco_SCOPE_SYS),
Sco_ScopeDB[Sco_SCOPE_INS],Gbl.CurrentCty.Cty.CtyCod, Sco_GetDBStrFromScope (Sco_SCOPE_INS),Gbl.CurrentCty.Cty.CtyCod,
Sco_ScopeDB[Sco_SCOPE_CTR],Gbl.CurrentCty.Cty.CtyCod, Sco_GetDBStrFromScope (Sco_SCOPE_CTR),Gbl.CurrentCty.Cty.CtyCod,
Sco_ScopeDB[Sco_SCOPE_DEG],Gbl.CurrentCty.Cty.CtyCod); Sco_GetDBStrFromScope (Sco_SCOPE_DEG),Gbl.CurrentCty.Cty.CtyCod);
break; break;
case Sco_SCOPE_INS: // System admins, case Sco_SCOPE_INS: // System admins,
// admins of the current institution, // admins of the current institution,
@ -5103,10 +5124,10 @@ static void Usr_GetAdmsLst (Sco_Scope_t Scope)
" AND centres.InsCod=%ld)" " AND centres.InsCod=%ld)"
" ORDER BY Surname1,Surname2,FirstName,UsrCod", " ORDER BY Surname1,Surname2,FirstName,UsrCod",
QueryFields, QueryFields,
Sco_ScopeDB[Sco_SCOPE_SYS], Sco_GetDBStrFromScope (Sco_SCOPE_SYS),
Sco_ScopeDB[Sco_SCOPE_INS],Gbl.CurrentIns.Ins.InsCod, Sco_GetDBStrFromScope (Sco_SCOPE_INS),Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CTR],Gbl.CurrentIns.Ins.InsCod, Sco_GetDBStrFromScope (Sco_SCOPE_CTR),Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_DEG],Gbl.CurrentIns.Ins.InsCod); Sco_GetDBStrFromScope (Sco_SCOPE_DEG),Gbl.CurrentIns.Ins.InsCod);
break; break;
case Sco_SCOPE_CTR: // System admins, case Sco_SCOPE_CTR: // System admins,
// admins of the current institution, // admins of the current institution,
@ -5130,10 +5151,10 @@ static void Usr_GetAdmsLst (Sco_Scope_t Scope)
" AND degrees.CtrCod=%ld)" " AND degrees.CtrCod=%ld)"
" ORDER BY Surname1,Surname2,FirstName,UsrCod", " ORDER BY Surname1,Surname2,FirstName,UsrCod",
QueryFields, QueryFields,
Sco_ScopeDB[Sco_SCOPE_SYS], Sco_GetDBStrFromScope (Sco_SCOPE_SYS),
Sco_ScopeDB[Sco_SCOPE_INS],Gbl.CurrentIns.Ins.InsCod, Sco_GetDBStrFromScope (Sco_SCOPE_INS),Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CTR],Gbl.CurrentCtr.Ctr.CtrCod, Sco_GetDBStrFromScope (Sco_SCOPE_CTR),Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_DEG],Gbl.CurrentCtr.Ctr.CtrCod); Sco_GetDBStrFromScope (Sco_SCOPE_DEG),Gbl.CurrentCtr.Ctr.CtrCod);
break; break;
case Sco_SCOPE_DEG: // System admins case Sco_SCOPE_DEG: // System admins
// and admins of the current institution, centre or degree // and admins of the current institution, centre or degree
@ -5153,10 +5174,10 @@ static void Usr_GetAdmsLst (Sco_Scope_t Scope)
" WHERE Scope='%s' AND Cod=%ld)" " WHERE Scope='%s' AND Cod=%ld)"
" ORDER BY Surname1,Surname2,FirstName,UsrCod", " ORDER BY Surname1,Surname2,FirstName,UsrCod",
QueryFields, QueryFields,
Sco_ScopeDB[Sco_SCOPE_SYS], Sco_GetDBStrFromScope (Sco_SCOPE_SYS),
Sco_ScopeDB[Sco_SCOPE_INS],Gbl.CurrentIns.Ins.InsCod, Sco_GetDBStrFromScope (Sco_SCOPE_INS),Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CTR],Gbl.CurrentCtr.Ctr.CtrCod, Sco_GetDBStrFromScope (Sco_SCOPE_CTR),Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_DEG],Gbl.CurrentDeg.Deg.DegCod); Sco_GetDBStrFromScope (Sco_SCOPE_DEG),Gbl.CurrentDeg.Deg.DegCod);
break; break;
default: // not aplicable default: // not aplicable
Lay_WrongScopeExit (); Lay_WrongScopeExit ();

View File

@ -212,8 +212,12 @@ struct UsrData
struct UsrLast struct UsrLast
{ {
Sch_WhatToSearch_t WhatToSearch; // Search courses, teachers, documents...? Sch_WhatToSearch_t WhatToSearch; // Search courses, teachers, documents...?
long LastCrs; // long LastCrs;
Tab_Tab_t LastTab; struct
{
Sco_Scope_t Scope; // Course, degree, centre, etc.
long Cod; // Course code, degree code, centre code, etc.
} LastHie;
Act_Action_t LastAct; Act_Action_t LastAct;
Rol_Role_t LastRole; Rol_Role_t LastRole;
long LastAccNotif; long LastAccNotif;