2015-01-17 20:07:13 +01:00
|
|
|
|
// swad_tab.c: tabs drawing
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
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.
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Copyright (C) 1999-2023 Antonio Ca<EFBFBD>as Vargas
|
2015-01-17 20:07:13 +01:00
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General Public 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 ***********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2022-11-06 18:11:10 +01:00
|
|
|
|
#include "swad_action_list.h"
|
2018-11-09 20:47:39 +01:00
|
|
|
|
#include "swad_form.h"
|
2015-01-17 20:07:13 +01:00
|
|
|
|
#include "swad_global.h"
|
2023-09-22 14:47:56 +02:00
|
|
|
|
#include "swad_hierarchy_type.h"
|
2019-10-23 20:07:56 +02:00
|
|
|
|
#include "swad_HTML.h"
|
2015-01-17 20:07:13 +01:00
|
|
|
|
#include "swad_parameter.h"
|
|
|
|
|
#include "swad_tab.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** External global variables from others modules ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private prototypes ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-10-12 14:02:56 +02:00
|
|
|
|
static bool Tab_CheckIfICanViewTab (Tab_Tab_t Tab);
|
2019-01-09 01:41:54 +01:00
|
|
|
|
static const char *Tab_GetIcon (Tab_Tab_t Tab);
|
2015-01-17 20:07:13 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************** Draw tabs with the current tab highlighted *****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-11-27 13:45:39 +01:00
|
|
|
|
void Tab_DrawTabs (void)
|
2015-01-17 20:07:13 +01:00
|
|
|
|
{
|
2022-04-20 22:56:58 +02:00
|
|
|
|
extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS];
|
2016-12-28 17:22:25 +01:00
|
|
|
|
extern const char *Txt_TABS_TXT[Tab_NUM_TABS];
|
|
|
|
|
extern const char *Txt_TABS_TXT[Tab_NUM_TABS];
|
2016-10-12 14:02:56 +02:00
|
|
|
|
Tab_Tab_t NumTab;
|
2015-01-17 20:07:13 +01:00
|
|
|
|
bool ICanViewTab;
|
2022-04-20 22:56:58 +02:00
|
|
|
|
char URLIconSet[PATH_MAX + 1];
|
|
|
|
|
static const char *ClassIcoTab[Ico_NUM_ICON_SETS] =
|
2016-12-18 19:50:33 +01:00
|
|
|
|
{
|
2022-04-20 22:56:58 +02:00
|
|
|
|
[Ico_ICON_SET_AWESOME] = "TAB_ICO",
|
|
|
|
|
[Ico_ICON_SET_NUVOLA ] = NULL,
|
2021-12-15 00:47:29 +01:00
|
|
|
|
};
|
2016-12-18 19:50:33 +01:00
|
|
|
|
|
2021-07-08 15:00:17 +02:00
|
|
|
|
/***** Begin tabs container *****/
|
2022-04-20 22:56:58 +02:00
|
|
|
|
HTM_DIV_Begin ("class=\"HEAD_ROW_3_%s\"",The_GetSuffix ());
|
2021-07-08 15:00:17 +02:00
|
|
|
|
HTM_Txt ("<nav id=\"tabs\">");
|
|
|
|
|
HTM_UL_Begin ("class=\"TAB_LIST\"");
|
|
|
|
|
|
|
|
|
|
/***** Draw the tabs *****/
|
|
|
|
|
for (NumTab = (Tab_Tab_t) 1;
|
|
|
|
|
NumTab <= (Tab_Tab_t) (Tab_NUM_TABS - 1);
|
|
|
|
|
NumTab++)
|
|
|
|
|
{
|
|
|
|
|
ICanViewTab = Tab_CheckIfICanViewTab (NumTab);
|
|
|
|
|
|
|
|
|
|
/* If current tab is unknown, then activate the first one with access allowed */
|
|
|
|
|
if (Gbl.Action.Tab == TabUnk)
|
|
|
|
|
{
|
|
|
|
|
Gbl.Action.Tab = NumTab;
|
|
|
|
|
Tab_DisableIncompatibleTabs ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ICanViewTab) // Don't show the first hidden tabs
|
|
|
|
|
{
|
|
|
|
|
/* Form, icon (at top) and text (at bottom) of the tab */
|
2021-12-27 12:58:20 +01:00
|
|
|
|
HTM_LI_Begin ("class=\"%s%s\"",
|
|
|
|
|
NumTab == Gbl.Action.Tab ? "TAB_ON TAB_ON_" :
|
|
|
|
|
"TAB_OFF TAB_OFF_",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
The_GetSuffix ());
|
2021-07-08 15:00:17 +02:00
|
|
|
|
|
|
|
|
|
if (NumTab == Gbl.Action.Tab)
|
|
|
|
|
HTM_DIV_Begin (NULL); // This div must be present even in current tab in order to render properly the tab
|
|
|
|
|
else
|
|
|
|
|
HTM_DIV_Begin ("class=\"ICO_HIGHLIGHT\"");
|
|
|
|
|
|
|
|
|
|
Frm_BeginForm (ActMnu);
|
2023-03-07 09:55:39 +01:00
|
|
|
|
Par_PutParUnsigned (NULL,"NxtTab",(unsigned) NumTab);
|
2022-04-01 01:06:44 +02:00
|
|
|
|
HTM_BUTTON_Submit_Begin (Txt_TABS_TXT[NumTab],
|
|
|
|
|
"class=\"BT_LINK\"");
|
2022-04-20 22:56:58 +02:00
|
|
|
|
snprintf (URLIconSet,sizeof (URLIconSet),"%s/%s",
|
|
|
|
|
Cfg_URL_ICON_SETS_PUBLIC,Ico_IconSetId[Gbl.Prefs.IconSet]);
|
|
|
|
|
if (ClassIcoTab[Gbl.Prefs.IconSet])
|
|
|
|
|
HTM_IMG (URLIconSet,Tab_GetIcon (NumTab),Txt_TABS_TXT[NumTab],
|
|
|
|
|
"class=\"TAB_ICO %s_%s\"",
|
|
|
|
|
ClassIcoTab[Gbl.Prefs.IconSet],The_GetSuffix ());
|
|
|
|
|
else
|
|
|
|
|
HTM_IMG (URLIconSet,Tab_GetIcon (NumTab),Txt_TABS_TXT[NumTab],
|
|
|
|
|
"class=\"TAB_ICO\"");
|
2021-12-27 12:58:20 +01:00
|
|
|
|
HTM_DIV_Begin ("class=\"TAB_TXT TAB_%s_TXT_%s\"",
|
|
|
|
|
NumTab == Gbl.Action.Tab ? "ON" :
|
|
|
|
|
"OFF",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
The_GetSuffix ());
|
2021-07-08 15:00:17 +02:00
|
|
|
|
HTM_Txt (Txt_TABS_TXT[NumTab]);
|
|
|
|
|
HTM_DIV_End ();
|
|
|
|
|
HTM_BUTTON_End ();
|
|
|
|
|
Frm_EndForm ();
|
|
|
|
|
|
|
|
|
|
HTM_DIV_End ();
|
|
|
|
|
HTM_LI_End ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** End tabs container *****/
|
|
|
|
|
HTM_UL_End ();
|
|
|
|
|
HTM_Txt ("</nav>");
|
2019-10-23 20:07:56 +02:00
|
|
|
|
HTM_DIV_End ();
|
2015-01-17 20:07:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************* Check if I can view a tab *************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-10-12 14:02:56 +02:00
|
|
|
|
static bool Tab_CheckIfICanViewTab (Tab_Tab_t Tab)
|
2015-01-17 20:07:13 +01:00
|
|
|
|
{
|
|
|
|
|
switch (Tab)
|
|
|
|
|
{
|
|
|
|
|
case TabUnk:
|
|
|
|
|
return false;
|
|
|
|
|
case TabSys:
|
2023-09-26 00:14:32 +02:00
|
|
|
|
return (Gbl.Hierarchy.Level == Hie_SYS); // Institution selected
|
2015-01-17 20:07:13 +01:00
|
|
|
|
case TabCty:
|
2023-09-26 00:14:32 +02:00
|
|
|
|
return (Gbl.Hierarchy.Level == Hie_CTY); // Institution selected
|
2015-01-17 20:07:13 +01:00
|
|
|
|
case TabIns:
|
2023-09-26 00:14:32 +02:00
|
|
|
|
return (Gbl.Hierarchy.Level == Hie_INS); // Institution selected
|
2015-01-17 20:07:13 +01:00
|
|
|
|
case TabCtr:
|
2023-09-26 00:14:32 +02:00
|
|
|
|
return (Gbl.Hierarchy.Level == Hie_CTR); // Center selected
|
2015-01-17 20:07:13 +01:00
|
|
|
|
case TabDeg:
|
2023-09-26 00:14:32 +02:00
|
|
|
|
return (Gbl.Hierarchy.Level == Hie_DEG); // Degree selected
|
2015-01-17 20:07:13 +01:00
|
|
|
|
case TabCrs:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
return (Gbl.Hierarchy.Level == Hie_CRS); // Course selected
|
2017-04-29 21:32:04 +02:00
|
|
|
|
case TabAss:
|
2023-09-26 00:14:32 +02:00
|
|
|
|
return (Gbl.Hierarchy.Level == Hie_CRS && // Course selected
|
2017-10-03 00:09:06 +02:00
|
|
|
|
Gbl.Usrs.Me.Role.Logged >= Rol_STD); // I belong to course or I am an admin
|
2017-02-09 10:31:21 +01:00
|
|
|
|
case TabFil:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
return (Gbl.Hierarchy.Node[Hie_INS].HieCod > 0 || // Institution selected
|
2023-09-26 00:14:32 +02:00
|
|
|
|
Gbl.Usrs.Me.Logged); // I'm logged
|
2015-01-17 20:07:13 +01:00
|
|
|
|
default:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-09 01:41:54 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************** Get icon associated to an action *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static const char *Tab_GetIcon (Tab_Tab_t NumTab)
|
|
|
|
|
{
|
2019-11-22 01:04:03 +01:00
|
|
|
|
static const char *Tab_TabIcons[Tab_NUM_TABS] =
|
|
|
|
|
{
|
|
|
|
|
[TabUnk] = NULL,
|
2020-04-16 03:03:07 +02:00
|
|
|
|
[TabStr] = "house-user",
|
2019-11-22 01:04:03 +01:00
|
|
|
|
[TabSys] = "sitemap",
|
2021-12-22 00:20:06 +01:00
|
|
|
|
[TabCty] = "globe-americas",
|
2019-11-22 01:04:03 +01:00
|
|
|
|
[TabIns] = "university",
|
|
|
|
|
[TabCtr] = "building",
|
|
|
|
|
[TabDeg] = "graduation-cap",
|
2020-02-20 00:32:07 +01:00
|
|
|
|
[TabCrs] = "chalkboard-teacher",
|
2019-11-22 01:04:03 +01:00
|
|
|
|
[TabAss] = "check",
|
|
|
|
|
[TabFil] = "folder-open",
|
|
|
|
|
[TabUsr] = "users",
|
2020-09-26 01:02:15 +02:00
|
|
|
|
[TabMsg] = "comment",
|
2019-11-22 01:04:03 +01:00
|
|
|
|
[TabAna] = "chart-bar",
|
|
|
|
|
[TabPrf] = "user",
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-15 20:02:34 +01:00
|
|
|
|
if (NumTab < (Tab_Tab_t) 1 ||
|
|
|
|
|
NumTab > (Tab_Tab_t) (Tab_NUM_TABS - 1))
|
2019-01-09 01:41:54 +01:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return Ico_GetIcon (Tab_TabIcons[NumTab]);
|
|
|
|
|
}
|
2015-01-17 20:07:13 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************** Set current tab depending on current action *****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Tab_SetCurrentTab (void)
|
|
|
|
|
{
|
2018-04-24 13:21:53 +02:00
|
|
|
|
Gbl.Action.Tab = Act_GetTab (Gbl.Action.Act);
|
2015-01-17 20:07:13 +01:00
|
|
|
|
|
2021-03-07 21:21:04 +01:00
|
|
|
|
/***** Change action and tab if country, institution, center or degree
|
2015-01-17 20:07:13 +01:00
|
|
|
|
are incompatible with the current tab *****/
|
2016-01-17 15:10:54 +01:00
|
|
|
|
switch (Gbl.Action.Tab)
|
2015-01-17 20:07:13 +01:00
|
|
|
|
{
|
|
|
|
|
case TabCty:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
if (Gbl.Hierarchy.Node[Hie_CTY].HieCod <= 0) // No country selected
|
2020-01-08 23:49:04 +01:00
|
|
|
|
{
|
2016-01-17 15:10:54 +01:00
|
|
|
|
Gbl.Action.Act = ActSeeCty;
|
2020-01-08 23:49:04 +01:00
|
|
|
|
Gbl.Action.Tab = Act_GetTab (Gbl.Action.Act);
|
|
|
|
|
}
|
2015-01-17 20:07:13 +01:00
|
|
|
|
break;
|
|
|
|
|
case TabIns:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
if (Gbl.Hierarchy.Node[Hie_INS].HieCod <= 0) // No institution selected
|
2015-01-17 20:07:13 +01:00
|
|
|
|
{
|
2023-09-22 14:47:56 +02:00
|
|
|
|
if (Gbl.Hierarchy.Node[Hie_CTY].HieCod > 0) // Country selected, but no institution selected
|
2016-01-17 15:10:54 +01:00
|
|
|
|
Gbl.Action.Act = ActSeeIns;
|
2015-01-17 20:07:13 +01:00
|
|
|
|
else // No country selected
|
2016-01-17 15:10:54 +01:00
|
|
|
|
Gbl.Action.Act = ActSeeCty;
|
2020-01-08 23:49:04 +01:00
|
|
|
|
Gbl.Action.Tab = Act_GetTab (Gbl.Action.Act);
|
2015-01-17 20:07:13 +01:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case TabCtr:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
if (Gbl.Hierarchy.Node[Hie_CTR].HieCod <= 0) // No center selected
|
2015-01-17 20:07:13 +01:00
|
|
|
|
{
|
2023-09-22 14:47:56 +02:00
|
|
|
|
if (Gbl.Hierarchy.Node[Hie_INS].HieCod > 0) // Institution selected, but no center selected
|
2016-01-17 15:10:54 +01:00
|
|
|
|
Gbl.Action.Act = ActSeeCtr;
|
2023-09-22 14:47:56 +02:00
|
|
|
|
else if (Gbl.Hierarchy.Node[Hie_CTY].HieCod > 0) // Country selected, but no institution selected
|
2016-01-17 15:10:54 +01:00
|
|
|
|
Gbl.Action.Act = ActSeeIns;
|
2015-01-17 20:07:13 +01:00
|
|
|
|
else // No country selected
|
2016-01-17 15:10:54 +01:00
|
|
|
|
Gbl.Action.Act = ActSeeCty;
|
2020-01-08 23:49:04 +01:00
|
|
|
|
Gbl.Action.Tab = Act_GetTab (Gbl.Action.Act);
|
2015-01-17 20:07:13 +01:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case TabDeg:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
if (Gbl.Hierarchy.Node[Hie_DEG].HieCod <= 0) // No degree selected
|
2015-01-17 20:07:13 +01:00
|
|
|
|
{
|
2023-09-22 14:47:56 +02:00
|
|
|
|
if (Gbl.Hierarchy.Node[Hie_CTR].HieCod > 0) // Center selected, but no degree selected
|
2016-01-17 15:10:54 +01:00
|
|
|
|
Gbl.Action.Act = ActSeeDeg;
|
2023-09-22 14:47:56 +02:00
|
|
|
|
else if (Gbl.Hierarchy.Node[Hie_INS].HieCod > 0) // Institution selected, but no center selected
|
2016-01-17 15:10:54 +01:00
|
|
|
|
Gbl.Action.Act = ActSeeCtr;
|
2023-09-22 14:47:56 +02:00
|
|
|
|
else if (Gbl.Hierarchy.Node[Hie_CTY].HieCod > 0) // Country selected, but no institution selected
|
2016-01-17 15:10:54 +01:00
|
|
|
|
Gbl.Action.Act = ActSeeIns;
|
2015-01-17 20:07:13 +01:00
|
|
|
|
else // No country selected
|
2016-01-17 15:10:54 +01:00
|
|
|
|
Gbl.Action.Act = ActSeeCty;
|
2020-01-08 23:49:04 +01:00
|
|
|
|
Gbl.Action.Tab = Act_GetTab (Gbl.Action.Act);
|
2015-01-17 20:07:13 +01:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-10-20 22:58:11 +02:00
|
|
|
|
|
2015-01-17 20:07:13 +01:00
|
|
|
|
Tab_DisableIncompatibleTabs ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************** Disable incompatible tabs ************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Tab_DisableIncompatibleTabs (void)
|
|
|
|
|
{
|
2021-03-07 21:21:04 +01:00
|
|
|
|
/***** Set country, institution, center, degree and course depending on the current tab.
|
2015-01-17 20:07:13 +01:00
|
|
|
|
This will disable tabs incompatible with the current one. *****/
|
2016-01-17 15:10:54 +01:00
|
|
|
|
switch (Gbl.Action.Tab)
|
2015-01-17 20:07:13 +01:00
|
|
|
|
{
|
|
|
|
|
case TabSys:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CTY].HieCod = -1L;
|
2018-10-04 21:57:25 +02:00
|
|
|
|
/* falls through */
|
|
|
|
|
/* no break */
|
2015-01-17 20:07:13 +01:00
|
|
|
|
case TabCty:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_INS].HieCod = -1L;
|
2018-10-04 21:57:25 +02:00
|
|
|
|
/* falls through */
|
|
|
|
|
/* no break */
|
2015-01-17 20:07:13 +01:00
|
|
|
|
case TabIns:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CTR].HieCod = -1L;
|
2018-10-04 21:57:25 +02:00
|
|
|
|
/* falls through */
|
|
|
|
|
/* no break */
|
2015-01-17 20:07:13 +01:00
|
|
|
|
case TabCtr:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_DEG].HieCod = -1L;
|
2018-10-04 21:57:25 +02:00
|
|
|
|
/* falls through */
|
|
|
|
|
/* no break */
|
2015-01-17 20:07:13 +01:00
|
|
|
|
case TabDeg:
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CRS].HieCod = -1L;
|
2015-01-17 20:07:13 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|