// 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. Copyright (C) 1999-2023 Antonio Caņas Vargas 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 . */ /*****************************************************************************/ /********************************* Headers ***********************************/ /*****************************************************************************/ #include "swad_action_list.h" #include "swad_form.h" #include "swad_global.h" #include "swad_hierarchy_level.h" #include "swad_HTML.h" #include "swad_parameter.h" #include "swad_tab.h" /*****************************************************************************/ /************** External global variables from others modules ****************/ /*****************************************************************************/ extern struct Globals Gbl; /*****************************************************************************/ /***************************** Private prototypes ****************************/ /*****************************************************************************/ static bool Tab_CheckIfICanViewTab (Tab_Tab_t Tab); static const char *Tab_GetIcon (Tab_Tab_t Tab); /*****************************************************************************/ /**************** Draw tabs with the current tab highlighted *****************/ /*****************************************************************************/ void Tab_DrawTabs (void) { extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS]; extern const char *Txt_TABS_TXT[Tab_NUM_TABS]; extern const char *Txt_TABS_TXT[Tab_NUM_TABS]; Tab_Tab_t NumTab; bool ICanViewTab; char URLIconSet[PATH_MAX + 1]; static const char *ClassIcoTab[Ico_NUM_ICON_SETS] = { [Ico_ICON_SET_AWESOME] = "TAB_ICO", [Ico_ICON_SET_NUVOLA ] = NULL, }; /***** Begin tabs container *****/ HTM_DIV_Begin ("class=\"HEAD_ROW_3_%s\"",The_GetSuffix ()); HTM_Txt (""); HTM_DIV_End (); } /*****************************************************************************/ /************************* Check if I can view a tab *************************/ /*****************************************************************************/ static bool Tab_CheckIfICanViewTab (Tab_Tab_t Tab) { switch (Tab) { case TabUnk: return false; case TabSys: return (Gbl.Hierarchy.Cty.CtyCod <= 0); // No country selected case TabCty: return (Gbl.Hierarchy.Cty.CtyCod > 0 && // Country selected Gbl.Hierarchy.Ins.InsCod <= 0); // No institution selected case TabIns: return (Gbl.Hierarchy.Ins.InsCod > 0 && // Institution selected Gbl.Hierarchy.Ctr.CtrCod <= 0); // No center selected case TabCtr: return (Gbl.Hierarchy.Ctr.CtrCod > 0 && // Center selected Gbl.Hierarchy.Deg.DegCod <= 0); // No degree selected case TabDeg: return (Gbl.Hierarchy.Deg.DegCod > 0 && // Degree selected Gbl.Hierarchy.Crs.CrsCod <= 0); // No course selected case TabCrs: return (Gbl.Hierarchy.Level == HieLvl_CRS); // Course selected case TabAss: return (Gbl.Hierarchy.Level == HieLvl_CRS || // Course selected Gbl.Usrs.Me.Role.Logged >= Rol_STD); // I belong to course or I am an admin case TabFil: return (Gbl.Hierarchy.Ins.InsCod > 0 || // Institution selected Gbl.Usrs.Me.Logged); // I'm logged default: return true; } } /*****************************************************************************/ /********************** Get icon associated to an action *********************/ /*****************************************************************************/ static const char *Tab_GetIcon (Tab_Tab_t NumTab) { static const char *Tab_TabIcons[Tab_NUM_TABS] = { [TabUnk] = NULL, [TabStr] = "house-user", [TabSys] = "sitemap", [TabCty] = "globe-americas", [TabIns] = "university", [TabCtr] = "building", [TabDeg] = "graduation-cap", [TabCrs] = "chalkboard-teacher", [TabAss] = "check", [TabFil] = "folder-open", [TabUsr] = "users", [TabMsg] = "comment", [TabAna] = "chart-bar", [TabPrf] = "user", }; if (NumTab < (Tab_Tab_t) 1 || NumTab > (Tab_Tab_t) (Tab_NUM_TABS - 1)) return NULL; return Ico_GetIcon (Tab_TabIcons[NumTab]); } /*****************************************************************************/ /*************** Set current tab depending on current action *****************/ /*****************************************************************************/ void Tab_SetCurrentTab (void) { Gbl.Action.Tab = Act_GetTab (Gbl.Action.Act); /***** Change action and tab if country, institution, center or degree are incompatible with the current tab *****/ switch (Gbl.Action.Tab) { case TabCty: if (Gbl.Hierarchy.Cty.CtyCod <= 0) // No country selected { Gbl.Action.Act = ActSeeCty; Gbl.Action.Tab = Act_GetTab (Gbl.Action.Act); } break; case TabIns: if (Gbl.Hierarchy.Ins.InsCod <= 0) // No institution selected { if (Gbl.Hierarchy.Cty.CtyCod > 0) // Country selected, but no institution selected Gbl.Action.Act = ActSeeIns; else // No country selected Gbl.Action.Act = ActSeeCty; Gbl.Action.Tab = Act_GetTab (Gbl.Action.Act); } break; case TabCtr: if (Gbl.Hierarchy.Ctr.CtrCod <= 0) // No center selected { if (Gbl.Hierarchy.Ins.InsCod > 0) // Institution selected, but no center selected Gbl.Action.Act = ActSeeCtr; else if (Gbl.Hierarchy.Cty.CtyCod > 0) // Country selected, but no institution selected Gbl.Action.Act = ActSeeIns; else // No country selected Gbl.Action.Act = ActSeeCty; Gbl.Action.Tab = Act_GetTab (Gbl.Action.Act); } break; case TabDeg: if (Gbl.Hierarchy.Deg.DegCod <= 0) // No degree selected { if (Gbl.Hierarchy.Ctr.CtrCod > 0) // Center selected, but no degree selected Gbl.Action.Act = ActSeeDeg; else if (Gbl.Hierarchy.Ins.InsCod > 0) // Institution selected, but no center selected Gbl.Action.Act = ActSeeCtr; else if (Gbl.Hierarchy.Cty.CtyCod > 0) // Country selected, but no institution selected Gbl.Action.Act = ActSeeIns; else // No country selected Gbl.Action.Act = ActSeeCty; Gbl.Action.Tab = Act_GetTab (Gbl.Action.Act); } break; default: break; } Tab_DisableIncompatibleTabs (); } /*****************************************************************************/ /************************** Disable incompatible tabs ************************/ /*****************************************************************************/ void Tab_DisableIncompatibleTabs (void) { /***** Set country, institution, center, degree and course depending on the current tab. This will disable tabs incompatible with the current one. *****/ switch (Gbl.Action.Tab) { case TabSys: Gbl.Hierarchy.Cty.CtyCod = -1L; /* falls through */ /* no break */ case TabCty: Gbl.Hierarchy.Ins.InsCod = -1L; /* falls through */ /* no break */ case TabIns: Gbl.Hierarchy.Ctr.CtrCod = -1L; /* falls through */ /* no break */ case TabCtr: Gbl.Hierarchy.Deg.DegCod = -1L; /* falls through */ /* no break */ case TabDeg: Gbl.Hierarchy.Crs.CrsCod = -1L; break; default: break; } }