swad-core/swad_menu.c

405 lines
12 KiB
C
Raw Normal View History

2015-01-04 15:48:24 +01:00
// swad_menu.c: menu (horizontal or vertical) selection
2015-01-02 12:57:26 +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.
2021-02-09 12:43:45 +01:00
Copyright (C) 1999-2021 Antonio Ca<EFBFBD>as Vargas
2015-01-02 12:57:26 +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 ***********************************/
/*****************************************************************************/
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2015-01-02 12:57:26 +01:00
#include "swad_database.h"
2020-04-14 17:15:17 +02:00
#include "swad_figure.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2015-01-02 12:57:26 +01:00
#include "swad_global.h"
2019-10-23 20:07:56 +02:00
#include "swad_HTML.h"
2015-01-02 12:57:26 +01:00
#include "swad_layout.h"
#include "swad_menu.h"
#include "swad_parameter.h"
2019-03-26 11:53:21 +01:00
#include "swad_setting.h"
#include "swad_setting_database.h"
2015-01-04 15:48:24 +01:00
#include "swad_tab.h"
2015-01-02 12:57:26 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
2019-11-21 16:47:07 +01:00
/******************************* Public constants ****************************/
2015-01-02 12:57:26 +01:00
/*****************************************************************************/
2019-11-21 16:47:07 +01:00
const char *Mnu_MenuIcons[Mnu_NUM_MENUS] =
2015-01-02 12:57:26 +01:00
{
2019-11-21 16:47:07 +01:00
[Mnu_MENU_HORIZONTAL] = "ellipsis-h.svg",
[Mnu_MENU_VERTICAL ] = "ellipsis-v.svg",
2015-01-02 12:57:26 +01:00
};
2019-11-21 16:47:07 +01:00
/*****************************************************************************/
/****************************** Private constants ****************************/
/*****************************************************************************/
2015-01-02 12:57:26 +01:00
2019-11-21 16:47:07 +01:00
#define MAX_MENU_ID 16
2015-01-02 12:57:26 +01:00
2015-12-08 01:47:48 +01:00
// Actions not initialized are 0 by default
2019-11-21 16:47:07 +01:00
static const Act_Action_t Mnu_MenuActions[Tab_NUM_TABS][Act_MAX_OPTIONS_IN_MENU_PER_TAB] =
2019-11-21 21:07:47 +01:00
{
[TabUnk] = {
},
[TabStr] = {
[ 0] = ActFrmLogIn,
[ 1] = ActReqSch,
[ 2] = ActSeeGblTL,
2019-11-21 21:07:47 +01:00
[ 3] = ActSeeSocPrf,
[ 4] = ActSeeCal,
[ 5] = ActSeeNtf,
},
[TabSys] = {
2020-01-08 23:49:04 +01:00
[ 0] = ActSeeSysInf,
[ 1] = ActSeeCty,
[ 2] = ActSeePen,
[ 3] = ActSeeLnk,
[ 4] = ActLstPlg,
2020-01-30 20:47:00 +01:00
[ 5] = ActMtn,
2019-11-21 21:07:47 +01:00
},
[TabCty] = {
[ 0] = ActSeeCtyInf,
[ 1] = ActSeeIns,
},
[TabIns] = {
[ 0] = ActSeeInsInf,
[ 1] = ActSeeCtr,
[ 2] = ActSeePlc,
[ 3] = ActSeeDpt,
[ 4] = ActSeeHld,
},
[TabCtr] = {
[ 0] = ActSeeCtrInf,
[ 1] = ActSeeDeg,
2020-04-14 22:45:10 +02:00
[ 2] = ActSeeBld,
[ 3] = ActSeeRoo,
2019-11-21 21:07:47 +01:00
},
[TabDeg] = {
[ 0] = ActSeeDegInf,
[ 1] = ActSeeCrs,
},
[TabCrs] = {
[ 0] = ActSeeCrsInf,
2020-02-20 23:48:48 +01:00
[ 1] = ActSeePrg,
2020-02-20 00:32:07 +01:00
[ 2] = ActSeeTchGui,
[ 3] = ActSeeSyl,
[ 4] = ActSeeBib,
[ 5] = ActSeeFAQ,
[ 6] = ActSeeCrsLnk,
[ 7] = ActSeeCrsTT,
2019-11-21 21:07:47 +01:00
},
[TabAss] = {
[ 0] = ActSeeAss,
[ 1] = ActSeeAsg,
[ 2] = ActSeePrj,
2020-05-16 14:01:51 +02:00
[ 3] = ActSeeAllExaAnn,
[ 4] = ActEdiTstQst,
[ 5] = ActReqTst,
[ 6] = ActSeeAllExa,
[ 7] = ActSeeAllGam,
[ 8] = ActSeeAllSvy,
2019-11-21 21:07:47 +01:00
},
[TabFil] = {
[ 0] = ActSeeAdmDocIns,
[ 1] = ActAdmShaIns,
[ 2] = ActSeeAdmDocCtr,
[ 3] = ActAdmShaCtr,
[ 4] = ActSeeAdmDocDeg,
[ 5] = ActAdmShaDeg,
[ 6] = ActSeeAdmDocCrsGrp,
[ 7] = ActAdmTchCrsGrp,
[ 8] = ActAdmShaCrsGrp,
[ 9] = ActAdmAsgWrkUsr,
[10] = ActReqAsgWrkCrs,
[11] = ActSeeAdmMrk,
[12] = ActAdmBrf,
},
[TabUsr] = {
[ 0] = ActReqSelGrp,
[ 1] = ActLstStd,
[ 2] = ActLstTch,
[ 3] = ActLstOth,
[ 4] = ActSeeAtt,
[ 5] = ActReqSignUp,
[ 6] = ActSeeSignUpReq,
[ 7] = ActLstCon,
2015-12-08 01:47:48 +01:00
},
2019-11-21 21:07:47 +01:00
[TabMsg] = {
[ 0] = ActSeeAnn,
[ 1] = ActSeeAllNot,
[ 2] = ActSeeFor,
[ 3] = ActSeeChtRms,
2020-09-26 17:20:01 +02:00
[ 4] = ActSeeRcvMsg,
2020-09-26 01:02:15 +02:00
[ 5] = ActReqMaiUsr,
2019-11-21 21:07:47 +01:00
},
[TabAna] = {
[ 0] = ActReqUseGbl,
[ 1] = ActSeePhoDeg,
[ 2] = ActReqStaCrs,
[ 3] = ActReqAccGbl,
[ 4] = ActReqMyUsgRep,
[ 5] = ActMFUAct,
},
[TabPrf] = {
[ 0] = ActFrmRolSes,
[ 1] = ActMyCrs,
[ 2] = ActSeeMyTT,
[ 3] = ActSeeMyAgd,
[ 4] = ActFrmMyAcc,
[ 5] = ActReqEdiRecSha,
[ 6] = ActReqEdiSet,
},
};
2015-12-08 01:47:48 +01:00
2016-11-07 13:21:36 +01:00
/*****************************************************************************/
/****************************** Private prototypes ***************************/
/*****************************************************************************/
2020-04-08 03:41:05 +02:00
static void Mnu_PutIconsMenu (__attribute__((unused)) void *Args);
2016-11-07 13:21:36 +01:00
2015-12-08 01:47:48 +01:00
/*****************************************************************************/
/******* When I change to another tab, go to the first option allowed ********/
/*****************************************************************************/
Act_Action_t Mnu_GetFirstActionAvailableInCurrentTab (void)
{
unsigned NumOptInMenu;
Act_Action_t Action;
/* Change current action to the first allowed action in current tab */
for (NumOptInMenu = 0;
NumOptInMenu < Act_MAX_OPTIONS_IN_MENU_PER_TAB;
NumOptInMenu++)
{
2016-01-17 15:10:54 +01:00
if ((Action = Mnu_MenuActions[Gbl.Action.Tab][NumOptInMenu]) == 0)
2015-12-08 01:47:48 +01:00
return ActUnk;
if (Act_CheckIfIHavePermissionToExecuteAction (Action))
return Action;
}
return ActUnk;
}
2015-01-04 14:49:32 +01:00
/*****************************************************************************/
2015-11-29 18:32:57 +01:00
/******************* Write horizontal menu of current tab ********************/
2015-01-04 14:49:32 +01:00
/*****************************************************************************/
2015-11-29 22:06:22 +01:00
void Mnu_WriteMenuThisTab (void)
2015-01-04 14:49:32 +01:00
{
2019-02-20 17:18:13 +01:00
extern const char *The_ClassTxtMenu[The_NUM_THEMES];
2015-01-04 15:48:24 +01:00
extern const char *Txt_MENU_TITLE[Tab_NUM_TABS][Act_MAX_OPTIONS_IN_MENU_PER_TAB];
static const char *ClassIcoMenu[Ico_NUM_ICON_SETS][The_NUM_THEMES] =
{
[Ico_ICON_SET_AWESOME][The_THEME_WHITE ] = " MENU_ICO_WHITE",
[Ico_ICON_SET_AWESOME][The_THEME_GREY ] = " MENU_ICO_GREY",
[Ico_ICON_SET_AWESOME][The_THEME_PURPLE] = " MENU_ICO_PURPLE",
[Ico_ICON_SET_AWESOME][The_THEME_BLUE ] = " MENU_ICO_BLUE",
[Ico_ICON_SET_AWESOME][The_THEME_YELLOW] = " MENU_ICO_YELLOW",
[Ico_ICON_SET_AWESOME][The_THEME_PINK ] = " MENU_ICO_PINK",
[Ico_ICON_SET_AWESOME][The_THEME_DARK ] = " MENU_ICO_DARK",
[Ico_ICON_SET_NUVOLA ][The_THEME_WHITE ] = "",
[Ico_ICON_SET_NUVOLA ][The_THEME_GREY ] = "",
[Ico_ICON_SET_NUVOLA ][The_THEME_PURPLE] = "",
[Ico_ICON_SET_NUVOLA ][The_THEME_BLUE ] = "",
[Ico_ICON_SET_NUVOLA ][The_THEME_YELLOW] = "",
[Ico_ICON_SET_NUVOLA ][The_THEME_PINK ] = "",
[Ico_ICON_SET_NUVOLA ][The_THEME_DARK ] = "",
};
2015-01-04 14:49:32 +01:00
unsigned NumOptInMenu;
Act_Action_t NumAct;
const char *Title;
bool IsTheSelectedAction;
/***** Begin container *****/
2019-12-13 00:36:01 +01:00
HTM_Txt ("<nav class=\"MENU_LIST_CONT\">");
2015-11-29 22:06:22 +01:00
/***** Begin option list *****/
HTM_UL_Begin ("class=\"MENU_LIST\"");
/***** Loop to write all options in menu. Each row holds an option *****/
for (NumOptInMenu = 0;
NumOptInMenu < Act_MAX_OPTIONS_IN_MENU_PER_TAB;
NumOptInMenu++)
{
NumAct = Mnu_MenuActions[Gbl.Action.Tab][NumOptInMenu];
if (NumAct == 0) // At the end of each tab, actions are initialized to 0, so 0 marks the end of the menu
break;
if (Act_CheckIfIHavePermissionToExecuteAction (NumAct))
{
IsTheSelectedAction = (NumAct == Act_GetSuperAction (Gbl.Action.Act));
Title = Act_GetSubtitleAction (NumAct);
/***** Begin option *****/
HTM_LI_Begin ("class=\"MENU_LIST_ITEM\"");
/***** Begin form *****/
Frm_BeginForm (NumAct);
/***** Begin link *****/
HTM_BUTTON_OnSubmit_Begin (Title,
IsTheSelectedAction ? "BT_LINK MENU_OPT_ON" :
"BT_LINK MENU_OPT_OFF",
NULL);
/***** Icon and text *****/
HTM_DIV_Begin ("class=\"MENU_ICO_TXT\"");
HTM_DIV_Begin ("class=\"MENU_ICO%s\" style=\"background-image:url('%s/%s');\"",
ClassIcoMenu[Gbl.Prefs.IconSet][Gbl.Prefs.Theme],
Gbl.Prefs.URLIconSet,
Act_GetIcon (NumAct));
HTM_DIV_End ();
HTM_DIV_Begin ("class=\"MENU_TXT %s\"",
The_ClassTxtMenu[Gbl.Prefs.Theme]);
HTM_Txt (Txt_MENU_TITLE[Gbl.Action.Tab][NumOptInMenu]);
HTM_DIV_End ();
HTM_DIV_End ();
/***** End link *****/
HTM_BUTTON_End ();
/***** End form *****/
Frm_EndForm ();
/***** End option *****/
HTM_LI_End ();
}
}
/***** End option list *****/
HTM_UL_End ();
/***** End container *****/
2019-11-11 00:15:44 +01:00
HTM_Txt ("</nav>");
2015-01-04 14:49:32 +01:00
}
2015-01-02 12:57:26 +01:00
/*****************************************************************************/
/************* Put icons to select menu (horizontal or vertical) *************/
/*****************************************************************************/
void Mnu_PutIconsToSelectMenu (void)
{
2019-03-26 11:53:21 +01:00
extern const char *Hlp_PROFILE_Settings_menu;
extern const char *The_ClassPrefOn[The_NUM_THEMES];
2015-01-02 12:57:26 +01:00
extern const char *Txt_Menu;
extern const char *Txt_MENU_NAMES[Mnu_NUM_MENUS];
Mnu_Menu_t Menu;
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_Menu,
2020-04-08 03:41:05 +02:00
Mnu_PutIconsMenu,NULL,
2019-03-26 11:53:21 +01:00
Hlp_PROFILE_Settings_menu,Box_NOT_CLOSABLE);
Set_BeginSettingsHead ();
Set_BeginOneSettingSelector ();
for (Menu = (Mnu_Menu_t) 0;
Menu <= (Mnu_Menu_t) (Mnu_NUM_MENUS - 1);
Menu++)
{
if (Menu == Gbl.Prefs.Menu)
HTM_DIV_Begin ("class=\"PREF_ON %s\"",The_ClassPrefOn[Gbl.Prefs.Theme]);
else
HTM_DIV_Begin ("class=\"PREF_OFF\"");
Frm_BeginForm (ActChgMnu);
Par_PutHiddenParamUnsigned (NULL,"Menu",(unsigned) Menu);
Ico_PutSettingIconLink (Mnu_MenuIcons[Menu],Ico_BLACK,
Txt_MENU_NAMES[Menu]);
Frm_EndForm ();
HTM_DIV_End ();
}
Set_EndOneSettingSelector ();
Set_EndSettingsHead ();
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-11-07 13:21:36 +01:00
}
/*****************************************************************************/
2019-03-26 11:53:21 +01:00
/******************* Put contextual icons in menu setting ********************/
2016-11-07 13:21:36 +01:00
/*****************************************************************************/
2020-04-08 03:41:05 +02:00
static void Mnu_PutIconsMenu (__attribute__((unused)) void *Args)
2016-11-07 13:21:36 +01:00
{
2020-04-08 03:41:05 +02:00
/***** Put icon to show a figure *****/
Fig_PutIconToShowFigure (Fig_MENUS);
2015-01-02 12:57:26 +01:00
}
/*****************************************************************************/
/******************************** Change menu ********************************/
/*****************************************************************************/
void Mnu_ChangeMenu (void)
{
/***** Get param with menu *****/
Gbl.Prefs.Menu = Mnu_GetParamMenu ();
/***** Store menu in database *****/
if (Gbl.Usrs.Me.Logged)
Set_DB_UpdateMySettingsAboutMenu (Gbl.Prefs.Menu);
2015-01-02 12:57:26 +01:00
2019-03-26 11:53:21 +01:00
/***** Set settings from current IP *****/
Set_SetSettingsFromIP ();
2015-01-02 12:57:26 +01:00
}
/*****************************************************************************/
/************************* Get parameter with menu ***************************/
/*****************************************************************************/
Mnu_Menu_t Mnu_GetParamMenu (void)
{
2017-01-29 21:41:08 +01:00
return (Mnu_Menu_t)
Par_GetParToUnsignedLong ("Menu",
0,
Mnu_NUM_MENUS - 1,
(unsigned long) Mnu_MENU_DEFAULT);
2015-01-02 12:57:26 +01:00
}
2017-05-04 11:03:44 +02:00
/*****************************************************************************/
/*************************** Get menu from string ****************************/
/*****************************************************************************/
Mnu_Menu_t Mnu_GetMenuFromStr (const char *Str)
{
unsigned UnsignedNum;
if (sscanf (Str,"%u",&UnsignedNum) == 1)
if (UnsignedNum < Mnu_NUM_MENUS)
return (Mnu_Menu_t) UnsignedNum;
return Mnu_MENU_DEFAULT;
}
2019-10-24 09:46:20 +02:00
/*****************************************************************************/
/******************************** Context menu *******************************/
/*****************************************************************************/
void Mnu_ContextMenuBegin (void)
{
HTM_DIV_Begin ("class=\"CONTEXT_MENU\"");
}
void Mnu_ContextMenuEnd (void)
{
HTM_DIV_End ();
}