swad-core/swad_menu.c

502 lines
13 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.
2019-01-07 21:52:19 +01:00
Copyright (C) 1999-2019 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 ***********************************/
/*****************************************************************************/
2019-02-18 14:41:46 +01:00
#include <stdio.h> // For fprintf, etc.
2015-01-02 12:57:26 +01:00
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2015-01-02 12:57:26 +01:00
#include "swad_database.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"
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;
/*****************************************************************************/
2015-01-04 15:48:24 +01:00
/****************************** Private constants ****************************/
2015-01-02 12:57:26 +01:00
/*****************************************************************************/
#define MAX_MENU_ID 16
const char *Mnu_MenuId[Mnu_NUM_MENUS] =
{
"horizontal",
"vertical",
};
const char *Mnu_MenuNames[Mnu_NUM_MENUS] =
{
"Horizontal",
"Vertical",
};
const char *Mnu_MenuIcons[Mnu_NUM_MENUS] =
{
2019-01-10 15:26:33 +01:00
"ellipsis-h.svg",
"ellipsis-v.svg",
2015-01-02 12:57:26 +01:00
};
2015-12-08 01:47:48 +01:00
// Actions not initialized are 0 by default
const Act_Action_t Mnu_MenuActions[Tab_NUM_TABS][Act_MAX_OPTIONS_IN_MENU_PER_TAB] =
{
2016-12-15 02:22:47 +01:00
// TabUnk *******************
2015-12-08 01:47:48 +01:00
{
2016-12-15 02:22:47 +01:00
0, // 0
0, // 1
0, // 2
0, // 3
0, // 4
0, // 5
0, // 6
0, // 7
0, // 8
0, // 9
0, // 10
2017-02-08 23:25:29 +01:00
0, // 11
2017-10-03 00:09:06 +02:00
0, // 12
2015-12-08 01:47:48 +01:00
},
2019-04-01 11:15:38 +02:00
// TabStr *******************
2019-02-14 19:22:38 +01:00
{
2019-02-14 19:52:41 +01:00
ActFrmLogIn, // 0
2019-02-15 13:39:37 +01:00
ActReqSch, // 1
2019-02-15 00:57:23 +01:00
ActSeeSocTmlGbl, // 2
ActSeeSocPrf, // 3
2019-02-15 13:39:37 +01:00
ActSeeCal, // 4
2019-02-15 09:44:30 +01:00
ActSeeNtf, // 5
2019-02-14 19:22:38 +01:00
0, // 6
0, // 7
0, // 8
0, // 9
0, // 10
0, // 11
0, // 12
},
2016-12-15 02:22:47 +01:00
// TabSys *******************
2015-12-08 01:47:48 +01:00
{
2019-02-15 00:57:23 +01:00
ActSeeCty, // 0
ActSeePen, // 1
ActSeeLnk, // 2
ActLstPlg, // 3
ActSetUp, // 4
2019-02-15 09:44:30 +01:00
0, // 5
2019-02-15 00:57:23 +01:00
0, // 6
2018-10-11 21:00:20 +02:00
0, // 7
2017-03-27 01:21:10 +02:00
0, // 8
2017-03-27 00:48:50 +02:00
0, // 9
2017-03-24 20:07:29 +01:00
0, // 10
2017-02-08 23:25:29 +01:00
0, // 11
2017-10-03 00:09:06 +02:00
0, // 12
2015-12-08 01:47:48 +01:00
},
2016-12-15 02:22:47 +01:00
// TabCty *******************
2015-12-08 01:47:48 +01:00
{
2019-02-15 01:29:46 +01:00
ActSeeCtyInf, // 0
ActSeeIns, // 1
2019-02-15 10:50:30 +01:00
0, // 2
2019-02-15 01:29:46 +01:00
0, // 3
2016-12-15 02:22:47 +01:00
0, // 4
0, // 5
0, // 6
0, // 7
0, // 8
0, // 9
0, // 10
2017-02-08 23:25:29 +01:00
0, // 11
2017-10-03 00:09:06 +02:00
0, // 12
2015-12-08 01:47:48 +01:00
},
2016-12-15 02:22:47 +01:00
// TabIns *******************
2015-12-08 01:47:48 +01:00
{
2019-02-15 01:29:46 +01:00
ActSeeInsInf, // 0
ActSeeCtr, // 1
ActSeePlc, // 2
ActSeeDpt, // 3
2019-02-15 10:50:30 +01:00
ActSeeHld, // 4
2019-02-15 01:29:46 +01:00
0, // 5
2017-03-25 19:44:33 +01:00
0, // 6
2017-02-08 23:25:29 +01:00
0, // 7
2016-12-15 02:22:47 +01:00
0, // 8
0, // 9
0, // 10
2017-02-08 23:25:29 +01:00
0, // 11
2017-10-03 00:09:06 +02:00
0, // 12
2015-12-08 01:47:48 +01:00
},
2016-12-15 02:22:47 +01:00
// TabCtr *******************
2015-12-08 01:47:48 +01:00
{
2019-02-15 01:29:46 +01:00
ActSeeCtrInf, // 0
ActSeeDeg, // 1
ActSeeCla, // 2
2019-02-15 10:50:30 +01:00
0, // 3
2019-02-15 01:29:46 +01:00
0, // 4
2016-12-15 02:22:47 +01:00
0, // 5
0, // 6
0, // 7
0, // 8
0, // 9
0, // 10
2017-02-08 23:25:29 +01:00
0, // 11
2017-10-03 00:09:06 +02:00
0, // 12
2015-12-08 01:47:48 +01:00
},
2016-12-15 02:22:47 +01:00
// TabDeg *******************
2015-12-08 01:47:48 +01:00
{
2019-02-15 01:29:46 +01:00
ActSeeDegInf, // 0
ActSeeCrs, // 1
2019-02-15 10:50:30 +01:00
0, // 2
2019-02-15 01:29:46 +01:00
0, // 3
2017-02-08 23:25:29 +01:00
0, // 4
2016-12-15 02:22:47 +01:00
0, // 5
0, // 6
0, // 7
0, // 8
0, // 9
0, // 10
2017-02-08 23:25:29 +01:00
0, // 11
2017-10-03 00:09:06 +02:00
0, // 12
2015-12-08 01:47:48 +01:00
},
2016-12-15 02:22:47 +01:00
// TabCrs *******************
2015-12-08 01:47:48 +01:00
{
2019-02-15 01:29:46 +01:00
ActSeeCrsInf, // 0
ActSeeTchGui, // 1
ActSeeSyl, // 2
ActSeeBib, // 3
ActSeeFAQ, // 4
ActSeeCrsLnk, // 5
ActSeeCrsTT, // 6
2019-02-15 10:50:30 +01:00
0, // 7
2019-02-15 01:29:46 +01:00
0, // 8
2017-02-08 23:25:29 +01:00
0, // 9
0, // 10
0, // 11
2017-10-03 00:09:06 +02:00
0, // 12
2015-12-08 01:47:48 +01:00
},
2016-12-15 02:22:47 +01:00
// TabAss *******************
2015-12-08 01:47:48 +01:00
{
2016-12-15 02:22:47 +01:00
ActSeeAss, // 0
ActSeeAsg, // 1
2017-09-17 16:58:09 +02:00
ActSeePrj, // 2
ActReqTst, // 3
ActSeeAllGam, // 4
ActSeeAllSvy, // 5
ActSeeAllExaAnn, // 6
2017-02-08 23:25:29 +01:00
0, // 7
2016-12-15 02:22:47 +01:00
0, // 8
0, // 9
0, // 10
2017-02-08 23:25:29 +01:00
0, // 11
2017-10-03 00:09:06 +02:00
0, // 12
2017-02-08 23:25:29 +01:00
},
// TabFil *******************
{
ActSeeAdmDocIns, // 0
ActAdmShaIns, // 1
ActSeeAdmDocCtr, // 2
ActAdmShaCtr, // 3
ActSeeAdmDocDeg, // 4
ActAdmShaDeg, // 5
ActSeeAdmDocCrsGrp, // 6
ActAdmTchCrsGrp, // 7
ActAdmShaCrsGrp, // 8
ActAdmAsgWrkUsr, // 9
ActReqAsgWrkCrs, // 10
ActSeeAdmMrk, // 11
2017-10-03 00:09:06 +02:00
ActAdmBrf, // 12
2015-12-08 01:47:48 +01:00
},
2016-12-15 02:22:47 +01:00
// TabUsr *******************
2015-12-08 01:47:48 +01:00
{
2016-12-15 02:22:47 +01:00
ActReqSelGrp, // 0
ActLstStd, // 1
ActLstTch, // 2
ActLstOth, // 3
ActSeeAtt, // 4
ActReqSignUp, // 5
ActSeeSignUpReq, // 6
ActLstCon, // 7
0, // 8
0, // 9
0, // 10
2017-02-08 23:25:29 +01:00
0, // 11
2017-10-03 00:09:06 +02:00
0, // 12
2015-12-28 12:55:08 +01:00
},
2016-12-15 02:22:47 +01:00
// TabMsg *******************
2015-12-08 01:47:48 +01:00
{
2019-02-14 23:03:47 +01:00
ActSeeAnn, // 0
ActSeeAllNot, // 1
2019-02-15 00:21:51 +01:00
ActSeeFor, // 2
ActSeeChtRms, // 3
ActReqMsgUsr, // 4
ActSeeRcvMsg, // 5
ActSeeSntMsg, // 6
2019-04-11 21:37:11 +02:00
ActReqMaiUsr, // 7
2016-12-15 02:22:47 +01:00
0, // 8
0, // 9
0, // 10
2017-02-08 23:25:29 +01:00
0, // 11
2017-10-03 00:09:06 +02:00
0, // 12
2015-12-08 01:47:48 +01:00
},
2017-12-19 18:41:19 +01:00
// TabAna *******************
2015-12-08 01:47:48 +01:00
{
2017-04-27 10:15:07 +02:00
ActReqUseGbl, // 0
ActSeePhoDeg, // 1
ActReqStaCrs, // 2
ActReqAccGbl, // 3
ActReqMyUsgRep, // 4
ActMFUAct, // 5
0, // 6
2016-12-15 02:22:47 +01:00
0, // 7
0, // 8
0, // 9
0, // 10
2017-02-08 23:25:29 +01:00
0, // 11
2017-10-03 00:09:06 +02:00
0, // 12
2015-12-08 01:47:48 +01:00
},
2016-12-15 02:22:47 +01:00
// TabPrf *******************
2015-12-08 01:47:48 +01:00
{
2019-02-14 19:52:41 +01:00
ActFrmRolSes, // 0
ActMyCrs, // 1
ActSeeMyTT, // 2
ActSeeMyAgd, // 3
ActFrmMyAcc, // 4
ActReqEdiRecSha, // 5
2019-03-26 11:53:21 +01:00
ActReqEdiSet, // 6
2019-02-14 19:52:41 +01:00
0, // 7
2017-10-03 00:09:06 +02:00
0, // 8
2016-12-15 02:22:47 +01:00
0, // 9
0, // 10
2017-02-08 23:25:29 +01:00
0, // 11
2017-10-03 00:09:06 +02:00
0, // 12
2015-12-08 01:47:48 +01:00
},
};
2016-11-07 13:21:36 +01:00
/*****************************************************************************/
/****************************** Private prototypes ***************************/
/*****************************************************************************/
static void Mnu_PutIconsMenu (void);
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];
2015-01-04 14:49:32 +01:00
unsigned NumOptInMenu;
Act_Action_t NumAct;
const char *Title;
bool IsTheSelectedAction;
2015-11-29 22:06:22 +01:00
/***** Menu start *****/
2016-12-18 19:50:33 +01:00
fprintf (Gbl.F.Out,"<nav class=\"MENU_LIST_CONTAINER\">"
2015-12-01 00:38:22 +01:00
"<ul class=\"MENU_LIST\">");
2015-11-29 22:06:22 +01:00
2015-01-04 14:49:32 +01:00
/***** Loop to write all options in menu. Each row holds an option *****/
for (NumOptInMenu = 0;
NumOptInMenu < Act_MAX_OPTIONS_IN_MENU_PER_TAB;
NumOptInMenu++)
{
2016-01-17 15:10:54 +01:00
NumAct = Mnu_MenuActions[Gbl.Action.Tab][NumOptInMenu];
2015-01-04 14:49:32 +01:00
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))
{
2018-04-24 13:21:53 +02:00
IsTheSelectedAction = (NumAct == Act_GetSuperAction (Gbl.Action.Act));
2015-01-04 14:49:32 +01:00
Title = Act_GetSubtitleAction (NumAct);
2017-06-12 14:16:33 +02:00
/***** Start element *****/
2015-11-29 22:06:22 +01:00
fprintf (Gbl.F.Out,"<li class=\"MENU_LIST_ITEM\">");
2015-01-04 14:49:32 +01:00
2017-06-12 14:16:33 +02:00
/***** Start container used to highlight this option *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"%s\"",
IsTheSelectedAction ? "MENU_OPT_ON" :
"MENU_OPT_OFF");
2015-01-04 14:49:32 +01:00
2019-10-20 22:00:28 +02:00
/***** Begin form and link *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (NumAct);
2019-02-20 17:18:13 +01:00
Frm_LinkFormSubmit (Title,The_ClassTxtMenu[Gbl.Prefs.Theme],NULL);
2015-11-29 20:03:44 +01:00
2015-01-04 14:49:32 +01:00
/***** Icon *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"MENU_ICO\" style=\"background-image:url('%s/%s');\"",
Gbl.Prefs.URLIconSet,
Act_GetIcon (NumAct));
2015-01-04 14:49:32 +01:00
/***** Text *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"MENU_TEXT %s\"",The_ClassTxtMenu[Gbl.Prefs.Theme]);
2019-10-23 21:12:40 +02:00
fprintf (Gbl.F.Out,"%s",Txt_MENU_TITLE[Gbl.Action.Tab][NumOptInMenu]);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2015-01-04 14:49:32 +01:00
2017-06-12 14:16:33 +02:00
/***** End link and form *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
fprintf (Gbl.F.Out,"</a>");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-01-04 14:49:32 +01:00
2017-06-12 14:16:33 +02:00
/***** End container used to highlight this option *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2015-01-04 14:49:32 +01:00
2017-06-12 14:16:33 +02:00
/***** End element *****/
2015-01-04 14:49:32 +01:00
fprintf (Gbl.F.Out,"</li>");
}
}
2015-11-29 22:06:22 +01:00
/***** Menu end *****/
fprintf (Gbl.F.Out,"</ul>"
2016-12-18 19:50:33 +01:00
"</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;
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;
2017-06-10 21:38:10 +02:00
Box_StartBox (NULL,Txt_Menu,Mnu_PutIconsMenu,
2019-03-26 11:53:21 +01:00
Hlp_PROFILE_Settings_menu,Box_NOT_CLOSABLE);
Set_StartSettingsHead ();
Set_StartOneSettingSelector ();
2015-01-02 12:57:26 +01:00
for (Menu = (Mnu_Menu_t) 0;
Menu < Mnu_NUM_MENUS;
Menu++)
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"%s\"",Menu == Gbl.Prefs.Menu ? "PREF_ON" :
"PREF_OFF");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgMnu);
2015-01-02 12:57:26 +01:00
Par_PutHiddenParamUnsigned ("Menu",(unsigned) Menu);
2019-03-26 11:53:21 +01:00
Ico_PutSettingIconLink (Mnu_MenuIcons[Menu],Txt_MENU_NAMES[Menu]);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2015-01-02 12:57:26 +01:00
}
2019-03-26 11:53:21 +01:00
Set_EndOneSettingSelector ();
Set_EndSettingsHead ();
2017-06-10 21:38:10 +02:00
Box_EndBox ();
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
/*****************************************************************************/
static void Mnu_PutIconsMenu (void)
{
/***** Put icon to show a figure *****/
2019-02-12 14:46:14 +01:00
Gbl.Figures.FigureType = Fig_MENUS;
Fig_PutIconToShowFigure ();
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)
2019-03-26 11:53:21 +01:00
DB_QueryUPDATE ("can not update your setting about menu",
2018-11-03 12:16:40 +01:00
"UPDATE usr_data SET Menu=%u WHERE UsrCod=%ld",
(unsigned) Gbl.Prefs.Menu,Gbl.Usrs.Me.UsrDat.UsrCod);
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 ();
}