2021-03-07 21:21:04 +01:00
|
|
|
|
// swad_scope.c: scope (platform, center, degree, course...)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
SWAD (Shared Workspace At a Distance),
|
|
|
|
|
is a web platform developed at the University of Granada (Spain),
|
|
|
|
|
and used to support university teaching.
|
|
|
|
|
|
|
|
|
|
This file is part of SWAD core.
|
2024-02-07 00:40:28 +01:00
|
|
|
|
Copyright (C) 1999-2024 Antonio Ca<EFBFBD>as Vargas
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General 3 License as
|
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********************************** Headers *********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-11-23 00:44:39 +01:00
|
|
|
|
#include <string.h> // For string functions
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include "swad_config.h"
|
2021-04-26 15:27:27 +02:00
|
|
|
|
#include "swad_error.h"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include "swad_global.h"
|
2019-11-05 08:46:38 +01:00
|
|
|
|
#include "swad_HTML.h"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include "swad_parameter.h"
|
|
|
|
|
#include "swad_scope.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** External global variables from others modules ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/** Put a selector to choice between ranges when getting users for listing ***/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2024-06-07 10:44:31 +02:00
|
|
|
|
void Sco_PutSelectorScope (const char *ParName,HTM_Attributes_t Attributes)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2023-11-06 12:36:05 +01:00
|
|
|
|
extern const char *Txt_HIERARCHY_SINGUL_Abc[Hie_NUM_LEVELS];
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Hie_Level_t Level;
|
2019-11-06 08:59:15 +01:00
|
|
|
|
unsigned ScopeUnsigned;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
bool WriteScope;
|
|
|
|
|
|
2024-06-07 10:44:31 +02:00
|
|
|
|
HTM_SELECT_Begin (Attributes,NULL,
|
2024-01-24 18:00:22 +01:00
|
|
|
|
"id=\"%s\" name=\"%s\""
|
2024-01-30 15:08:53 +01:00
|
|
|
|
" class=\"Frm_C2_INPUT INPUT_%s\"",
|
2023-03-10 00:13:55 +01:00
|
|
|
|
ParName,ParName,The_GetSuffix ());
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2023-09-22 14:47:56 +02:00
|
|
|
|
for (Level = (Hie_Level_t) 1;
|
|
|
|
|
Level <= (Hie_Level_t) (Hie_NUM_LEVELS - 1);
|
2023-07-11 19:12:24 +02:00
|
|
|
|
Level++)
|
|
|
|
|
if ((Gbl.Scope.Allowed & (1 << Level)))
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2021-11-09 14:41:13 +01:00
|
|
|
|
/* Don't put forbidden options in selectable list */
|
|
|
|
|
WriteScope = false;
|
2023-07-11 19:12:24 +02:00
|
|
|
|
switch (Level)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2023-09-22 14:47:56 +02:00
|
|
|
|
case Hie_SYS:
|
2021-11-09 14:41:13 +01:00
|
|
|
|
WriteScope = true;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
2023-09-22 14:47:56 +02:00
|
|
|
|
case Hie_CTY:
|
|
|
|
|
case Hie_INS:
|
|
|
|
|
case Hie_CTR:
|
|
|
|
|
case Hie_DEG:
|
|
|
|
|
case Hie_CRS:
|
2023-09-26 00:14:32 +02:00
|
|
|
|
if (Gbl.Hierarchy.Node[Level].HieCod > 0)
|
2021-11-09 14:41:13 +01:00
|
|
|
|
WriteScope = true;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-11-09 14:41:13 +01:00
|
|
|
|
|
|
|
|
|
if (WriteScope)
|
|
|
|
|
{
|
|
|
|
|
/***** Write allowed option *****/
|
2023-07-11 19:12:24 +02:00
|
|
|
|
ScopeUnsigned = (unsigned) Level;
|
2023-05-18 12:54:43 +02:00
|
|
|
|
HTM_OPTION (HTM_Type_UNSIGNED,&ScopeUnsigned,
|
2024-06-07 10:44:31 +02:00
|
|
|
|
(Level == Gbl.Scope.Current) ? HTM_SELECTED :
|
|
|
|
|
HTM_NO_ATTR,
|
2023-05-18 12:54:43 +02:00
|
|
|
|
"%s: %s",
|
2023-11-06 12:36:05 +01:00
|
|
|
|
Txt_HIERARCHY_SINGUL_Abc[Level],
|
2023-09-19 22:27:20 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Level].ShrtName);
|
2021-11-09 14:41:13 +01:00
|
|
|
|
}
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-05 08:46:38 +01:00
|
|
|
|
HTM_SELECT_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2016-11-27 14:10:31 +01:00
|
|
|
|
/********************** Put hidden parameter scope ***************************/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-07-11 19:12:24 +02:00
|
|
|
|
void Sco_PutParCurrentScope (void *Level)
|
2019-04-11 09:55:35 +02:00
|
|
|
|
{
|
2023-07-11 19:12:24 +02:00
|
|
|
|
if (Level)
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Sco_PutParScope ("ScopeUsr",*((Hie_Level_t *) Level));
|
2019-04-11 09:55:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 14:47:56 +02:00
|
|
|
|
void Sco_PutParScope (const char *ParName,Hie_Level_t Level)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2023-07-11 19:12:24 +02:00
|
|
|
|
Par_PutParUnsigned (NULL,ParName,(unsigned) Level);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2016-11-27 14:10:31 +01:00
|
|
|
|
/*************************** Get parameter scope *****************************/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-09-28 19:33:41 +02:00
|
|
|
|
void Sco_GetScope (const char *ParName,Hie_Level_t DefaultScope)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2017-01-29 12:42:19 +01:00
|
|
|
|
/***** Get parameter with scope *****/
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Scope.Current = (Hie_Level_t)
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Par_GetParUnsignedLong (ParName,
|
|
|
|
|
0,
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Hie_NUM_LEVELS - 1,
|
|
|
|
|
(unsigned long) Hie_UNK);
|
2016-11-27 14:10:31 +01:00
|
|
|
|
|
|
|
|
|
/***** Adjust scope avoiding impossible or forbidden scopes *****/
|
2023-09-28 19:33:41 +02:00
|
|
|
|
Sco_AdjustScope (DefaultScope);
|
2016-11-27 14:10:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********** Adjust scope avoiding impossible or forbidden scopes ************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-09-28 19:33:41 +02:00
|
|
|
|
void Sco_AdjustScope (Hie_Level_t DefaultScope)
|
2016-11-27 14:10:31 +01:00
|
|
|
|
{
|
2023-09-26 00:14:32 +02:00
|
|
|
|
Hie_Level_t Level;
|
|
|
|
|
|
2016-11-27 14:10:31 +01:00
|
|
|
|
/***** Is scope is unknow, use default scope *****/
|
2023-09-22 14:47:56 +02:00
|
|
|
|
if (Gbl.Scope.Current == Hie_UNK)
|
2023-09-28 19:33:41 +02:00
|
|
|
|
Gbl.Scope.Current = DefaultScope;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2016-06-24 20:34:58 +02:00
|
|
|
|
/***** Avoid impossible scopes *****/
|
2023-09-26 00:14:32 +02:00
|
|
|
|
for (Level = Hie_CRS;
|
|
|
|
|
Level >= Hie_CTY;
|
|
|
|
|
Level--)
|
|
|
|
|
if (Gbl.Scope.Current == Level && Gbl.Hierarchy.Node[Level].HieCod <= 0)
|
|
|
|
|
Gbl.Scope.Current = Level - 1; // Go up to parent level
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2016-06-24 20:34:58 +02:00
|
|
|
|
/***** Avoid forbidden scopes *****/
|
|
|
|
|
if ((Gbl.Scope.Allowed & (1 << Gbl.Scope.Current)) == 0)
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Scope.Current = Hie_UNK;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Set allowed scopes when listing guests *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-09-28 19:33:41 +02:00
|
|
|
|
void Sco_SetAllowedScopesForListingGuests (void)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2017-06-04 18:18:54 +02:00
|
|
|
|
switch (Gbl.Usrs.Me.Role.Logged)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2015-04-07 21:44:24 +02:00
|
|
|
|
case Rol_SYS_ADM:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Scope.Allowed = 1 << Hie_SYS;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Gbl.Scope.Allowed = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************** Set allowed scopes when listing students *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-09-28 19:33:41 +02:00
|
|
|
|
void Sco_SetAllowedScopesForListingStudents (void)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2017-06-04 18:18:54 +02:00
|
|
|
|
switch (Gbl.Usrs.Me.Role.Logged)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2017-05-18 19:13:41 +02:00
|
|
|
|
case Rol_STD:
|
2017-05-22 20:37:46 +02:00
|
|
|
|
case Rol_NET:
|
2017-05-18 19:13:41 +02:00
|
|
|
|
case Rol_TCH:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Scope.Allowed = 1 << Hie_CRS;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
2015-04-07 21:44:24 +02:00
|
|
|
|
case Rol_DEG_ADM:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Scope.Allowed = 1 << Hie_DEG |
|
|
|
|
|
1 << Hie_CRS;
|
2015-09-20 19:20:05 +02:00
|
|
|
|
break;
|
|
|
|
|
case Rol_CTR_ADM:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Scope.Allowed = 1 << Hie_CTR |
|
|
|
|
|
1 << Hie_DEG |
|
|
|
|
|
1 << Hie_CRS;
|
2015-09-20 19:20:05 +02:00
|
|
|
|
break;
|
|
|
|
|
case Rol_INS_ADM:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Scope.Allowed = 1 << Hie_INS |
|
|
|
|
|
1 << Hie_CTR |
|
|
|
|
|
1 << Hie_DEG |
|
|
|
|
|
1 << Hie_CRS;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
2015-04-07 21:44:24 +02:00
|
|
|
|
case Rol_SYS_ADM:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Scope.Allowed = 1 << Hie_SYS |
|
|
|
|
|
1 << Hie_CTY |
|
|
|
|
|
1 << Hie_INS |
|
|
|
|
|
1 << Hie_CTR |
|
|
|
|
|
1 << Hie_DEG |
|
|
|
|
|
1 << Hie_CRS;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Gbl.Scope.Allowed = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-23 00:44:39 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2016-10-27 15:06:11 +02:00
|
|
|
|
/*********************** Get scope from unsigned string **********************/
|
2015-11-23 00:44:39 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Hie_Level_t Sco_GetScopeFromUnsignedStr (const char *UnsignedStr)
|
2015-11-23 00:44:39 +01:00
|
|
|
|
{
|
|
|
|
|
unsigned UnsignedNum;
|
|
|
|
|
|
|
|
|
|
if (sscanf (UnsignedStr,"%u",&UnsignedNum) == 1)
|
2023-09-22 14:47:56 +02:00
|
|
|
|
if (UnsignedNum < Hie_NUM_LEVELS)
|
|
|
|
|
return (Hie_Level_t) UnsignedNum;
|
2015-11-23 00:44:39 +01:00
|
|
|
|
|
2023-09-22 14:47:56 +02:00
|
|
|
|
return Hie_UNK;
|
2015-11-23 00:44:39 +01:00
|
|
|
|
}
|
2016-10-27 15:06:11 +02:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2023-07-11 19:12:24 +02:00
|
|
|
|
/***************** Get hierarchy level from database string ******************/
|
2016-10-27 15:06:11 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Hie_Level_t Hie_GetLevelFromDBStr (const char *LevelDBStr)
|
2016-10-27 15:06:11 +02:00
|
|
|
|
{
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Hie_Level_t Level;
|
2016-10-27 15:06:11 +02:00
|
|
|
|
|
2023-09-22 14:47:56 +02:00
|
|
|
|
for (Level = (Hie_Level_t) 0;
|
|
|
|
|
Level <= (Hie_Level_t) (Hie_NUM_LEVELS - 1);
|
2023-07-11 19:12:24 +02:00
|
|
|
|
Level++)
|
|
|
|
|
if (!strcmp (Hie_GetDBStrFromLevel (Level),LevelDBStr))
|
|
|
|
|
return Level;
|
2016-10-27 15:06:11 +02:00
|
|
|
|
|
2023-09-22 14:47:56 +02:00
|
|
|
|
return Hie_UNK;
|
2016-10-27 15:06:11 +02:00
|
|
|
|
}
|
2019-04-01 23:15:17 +02:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2023-07-11 19:12:24 +02:00
|
|
|
|
/****************** Get database string from hierarchy level *****************/
|
2019-04-01 23:15:17 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-09-22 14:47:56 +02:00
|
|
|
|
const char *Hie_GetDBStrFromLevel (Hie_Level_t Level)
|
2019-04-01 23:15:17 +02:00
|
|
|
|
{
|
2023-09-22 14:47:56 +02:00
|
|
|
|
static const char *Sco_ScopeDB[Hie_NUM_LEVELS] =
|
2019-04-01 23:15:17 +02:00
|
|
|
|
{
|
2023-09-22 14:47:56 +02:00
|
|
|
|
[Hie_UNK] = "Unk",
|
|
|
|
|
[Hie_SYS] = "Sys",
|
|
|
|
|
[Hie_CTY] = "Cty",
|
|
|
|
|
[Hie_INS] = "Ins",
|
|
|
|
|
[Hie_CTR] = "Ctr",
|
|
|
|
|
[Hie_DEG] = "Deg",
|
|
|
|
|
[Hie_CRS] = "Crs",
|
2019-04-01 23:15:17 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-09-22 14:47:56 +02:00
|
|
|
|
if (Level >= Hie_NUM_LEVELS)
|
|
|
|
|
Level = Hie_UNK;
|
2019-04-01 23:15:17 +02:00
|
|
|
|
|
2023-07-11 19:12:24 +02:00
|
|
|
|
return Sco_ScopeDB[Level];
|
2019-04-01 23:15:17 +02:00
|
|
|
|
}
|
2021-09-10 10:19:46 +02:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2023-07-11 19:12:24 +02:00
|
|
|
|
/************************** Get current hierarchy code ***********************/
|
2021-09-10 10:19:46 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-07-11 19:12:24 +02:00
|
|
|
|
long Hie_GetCurrentCod (void)
|
2021-09-10 10:19:46 +02:00
|
|
|
|
{
|
|
|
|
|
switch (Gbl.Scope.Current)
|
|
|
|
|
{
|
2023-09-22 14:47:56 +02:00
|
|
|
|
case Hie_SYS:
|
|
|
|
|
case Hie_CTY:
|
|
|
|
|
case Hie_INS:
|
|
|
|
|
case Hie_CTR:
|
|
|
|
|
case Hie_DEG:
|
|
|
|
|
case Hie_CRS:
|
2023-09-20 10:36:07 +02:00
|
|
|
|
return Gbl.Hierarchy.Node[Gbl.Scope.Current].HieCod;
|
2021-09-10 10:19:46 +02:00
|
|
|
|
default:
|
2023-07-11 19:12:24 +02:00
|
|
|
|
Err_WrongHierarchyLevelExit ();
|
2021-09-10 10:19:46 +02:00
|
|
|
|
return -1L; // Not reached
|
|
|
|
|
}
|
|
|
|
|
}
|