swad-core/swad_menu.c

372 lines
10 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.
2016-01-01 20:19:43 +01:00
Copyright (C) 1999-2016 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 ***********************************/
/*****************************************************************************/
#include <stdio.h> // For fprintf, etc.
#include "swad_database.h"
#include "swad_global.h"
#include "swad_layout.h"
#include "swad_menu.h"
#include "swad_parameter.h"
#include "swad_preference.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] =
{
"horizontal",
"vertical",
};
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] =
{
// TabUnk **********
{
},
// TabSys **********
{
ActSysReqSch,
ActSeeCty,
ActSeePen,
ActReqRemOldCrs,
ActSeeDegTyp,
ActSeeMai,
ActSeeBan,
ActSeeLnk,
ActLstPlg,
ActSetUp,
},
// TabCty **********
{
ActCtyReqSch,
ActSeeCtyInf,
ActSeeIns,
},
// TabIns **********
{
ActInsReqSch,
ActSeeInsInf,
ActSeeCtr,
ActSeeDpt,
ActSeePlc,
ActSeeHld,
ActSeeAdmDocIns,
2016-01-02 17:07:58 +01:00
ActAdmShaIns,
2015-12-08 01:47:48 +01:00
},
// TabCtr **********
{
ActCtrReqSch,
ActSeeCtrInf,
ActSeeDeg,
ActSeeAdmDocCtr,
2016-01-02 17:07:58 +01:00
ActAdmShaCtr,
2015-12-08 01:47:48 +01:00
},
// TabDeg **********
{
ActDegReqSch,
ActSeeDegInf,
ActSeeCrs,
ActSeeAdmDocDeg,
2016-01-02 17:07:58 +01:00
ActAdmShaDeg,
2015-12-08 01:47:48 +01:00
},
// TabCrs **********
{
ActCrsReqSch,
ActSeeCrsInf,
ActSeeTchGui,
ActSeeSyl,
2015-12-29 13:18:25 +01:00
ActSeeAdmDocCrsGrp,
2016-04-22 09:47:25 +02:00
ActAdmTchCrsGrp,
2015-12-29 13:18:25 +01:00
ActAdmShaCrsGrp,
2015-12-08 01:47:48 +01:00
ActSeeCrsTT,
ActSeeBib,
ActSeeFAQ,
ActSeeCrsLnk,
},
// TabAss **********
{
ActSeeAss,
ActSeeAsg,
ActAdmAsgWrkUsr,
ActReqAsgWrkCrs,
ActReqTst,
ActSeeCal,
2016-06-01 19:34:44 +02:00
ActSeeAllExaAnn,
2015-12-08 01:47:48 +01:00
ActSeeAdmMrk,
},
// TabUsr **********
{
ActReqSelGrp,
ActLstStd,
ActLstTch,
ActLstOth,
ActSeeAtt,
ActReqSignUp,
ActSeeSignUpReq,
ActLstCon,
2015-12-28 12:55:08 +01:00
},
// TabSoc **********
{
2016-01-02 01:56:48 +01:00
ActSeeSocTmlGbl,
2016-02-06 13:45:33 +01:00
ActSeeSocPrf,
2015-12-30 20:11:50 +01:00
ActSeeFor,
2015-12-28 12:55:08 +01:00
ActSeeChtRms,
2015-12-08 01:47:48 +01:00
},
// TabMsg **********
{
ActSeeNtf,
ActSeeAnn,
2016-06-01 19:34:44 +02:00
ActSeeAllNot,
2015-12-08 01:47:48 +01:00
ActReqMsgUsr,
ActSeeRcvMsg,
ActSeeSntMsg,
ActMaiStd,
},
// TabSta **********
{
ActSeeAllSvy,
ActReqUseGbl,
ActSeePhoDeg,
ActReqStaCrs,
ActReqAccGbl,
2016-10-03 13:04:49 +02:00
ActReqMyUsgRep,
2015-12-08 01:47:48 +01:00
},
// TabPrf **********
{
ActFrmLogIn,
2016-03-01 03:16:29 +01:00
ActFrmRolSes,
2015-12-08 01:47:48 +01:00
ActMyCrs,
ActSeeMyTT,
2016-07-07 00:20:31 +02:00
ActSeeMyAgd,
2016-10-12 14:02:56 +02:00
ActFrmMyAcc,
2015-12-08 01:47:48 +01:00
ActReqEdiRecCom,
ActEdiPrf,
ActAdmBrf,
ActMFUAct,
},
};
/*****************************************************************************/
/******* 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
{
2016-04-23 23:39:07 +02:00
extern struct Act_Actions Act_Actions[Act_NUM_ACTIONS];
2015-11-30 01:13:00 +01:00
extern const char *The_ClassTxtMenuOn[The_NUM_THEMES];
extern const char *The_ClassTxtMenuOff[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 *****/
2015-12-01 00:38:22 +01:00
fprintf (Gbl.F.Out,"<div class=\"MENU_LIST_CONTAINER\">"
"<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))
{
2016-01-17 15:10:54 +01:00
IsTheSelectedAction = (NumAct == Act_Actions[Gbl.Action.Act].SuperAction);
2015-01-04 14:49:32 +01:00
Title = Act_GetSubtitleAction (NumAct);
/***** Start of 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
/***** Start of container used to highlight this option *****/
2015-11-29 18:32:57 +01:00
fprintf (Gbl.F.Out,"<div class=\"%s\">",
2015-11-30 01:13:00 +01:00
IsTheSelectedAction ? "MENU_OPT_ON" :
"MENU_OPT_OFF");
2015-01-04 14:49:32 +01:00
/***** Start of form and link *****/
Act_FormStart (NumAct);
2015-12-01 02:34:32 +01:00
Act_LinkFormSubmit (Title,
IsTheSelectedAction ? The_ClassTxtMenuOn[Gbl.Prefs.Theme] :
2016-07-01 17:13:41 +02:00
The_ClassTxtMenuOff[Gbl.Prefs.Theme],NULL);
2015-11-29 20:03:44 +01:00
2015-01-04 14:49:32 +01:00
/***** Icon *****/
2015-11-30 01:13:00 +01:00
fprintf (Gbl.F.Out,"<div class=\"MENU_ICON\""
2015-12-28 15:44:56 +01:00
" style=\"background-image:url('%s/%s/%s');\">",
2015-01-13 14:19:08 +01:00
Gbl.Prefs.PathIconSet,Cfg_ICON_ACTION,
2015-01-04 14:49:32 +01:00
Act_Actions[NumAct].Icon);
/***** Text *****/
2015-11-30 01:13:00 +01:00
fprintf (Gbl.F.Out,"<div class=\"MENU_TEXT %s\">"
"%s"
"</div>",
IsTheSelectedAction ? The_ClassTxtMenuOn[Gbl.Prefs.Theme] :
The_ClassTxtMenuOff[Gbl.Prefs.Theme],
2016-01-17 15:10:54 +01:00
Txt_MENU_TITLE[Gbl.Action.Tab][NumOptInMenu]);
2015-01-04 14:49:32 +01:00
/***** End of link and form *****/
fprintf (Gbl.F.Out,"</div>"
2015-03-13 00:16:02 +01:00
"</a>");
2015-11-29 18:32:57 +01:00
Act_FormEnd ();
2015-01-04 14:49:32 +01:00
/***** End of container used to highlight this option *****/
2015-11-29 18:32:57 +01:00
fprintf (Gbl.F.Out,"</div>");
2015-01-04 14:49:32 +01:00
/***** End of element *****/
fprintf (Gbl.F.Out,"</li>");
}
}
2015-11-29 22:06:22 +01:00
/***** Menu end *****/
fprintf (Gbl.F.Out,"</ul>"
2015-11-30 01:13:00 +01:00
"</div>");
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)
{
extern const char *Txt_Menu;
extern const char *Txt_MENU_NAMES[Mnu_NUM_MENUS];
Mnu_Menu_t Menu;
2015-11-30 11:00:53 +01:00
Lay_StartRoundFrameTable (NULL,0,Txt_Menu);
2015-01-02 12:57:26 +01:00
fprintf (Gbl.F.Out,"<tr>");
for (Menu = (Mnu_Menu_t) 0;
Menu < Mnu_NUM_MENUS;
Menu++)
{
fprintf (Gbl.F.Out,"<td class=\"%s\">",
2015-11-22 00:52:55 +01:00
Menu == Gbl.Prefs.Menu ? "PREF_ON" :
"PREF_OFF");
2015-01-02 12:57:26 +01:00
Act_FormStart (ActChgMnu);
Par_PutHiddenParamUnsigned ("Menu",(unsigned) Menu);
fprintf (Gbl.F.Out,"<input type=\"image\" src=\"%s/%s32x32.gif\""
2015-12-13 12:51:41 +01:00
" alt=\"%s\" title=\"%s\" class=\"ICON40x40B\""
2015-03-13 00:16:02 +01:00
" style=\"margin:0 auto;\" />",
2015-01-02 12:57:26 +01:00
Gbl.Prefs.IconsURL,
Mnu_MenuIcons[Menu],
Txt_MENU_NAMES[Menu],
Txt_MENU_NAMES[Menu]);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
fprintf (Gbl.F.Out,"</td>");
2015-01-02 12:57:26 +01:00
}
fprintf (Gbl.F.Out,"</tr>");
2015-04-12 18:01:06 +02:00
Lay_EndRoundFrameTable ();
2015-01-02 12:57:26 +01:00
}
/*****************************************************************************/
/******************************** Change menu ********************************/
/*****************************************************************************/
void Mnu_ChangeMenu (void)
{
char Query[512];
/***** Get param with menu *****/
Gbl.Prefs.Menu = Mnu_GetParamMenu ();
/***** Store menu in database *****/
if (Gbl.Usrs.Me.Logged)
{
sprintf (Query,"UPDATE usr_data SET Menu='%u' WHERE UsrCod='%ld'",
(unsigned) Gbl.Prefs.Menu,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE (Query,"can not update your preference about menu");
}
/***** Set preferences from current IP *****/
2015-03-14 17:39:04 +01:00
Pre_SetPrefsFromIP ();
2015-01-02 12:57:26 +01:00
}
/*****************************************************************************/
/************************* Get parameter with menu ***************************/
/*****************************************************************************/
Mnu_Menu_t Mnu_GetParamMenu (void)
{
char UnsignedStr[1+10+1];
unsigned UnsignedNum;
Par_GetParToText ("Menu",UnsignedStr,1+10);
if (sscanf (UnsignedStr,"%u",&UnsignedNum) == 1)
if (UnsignedNum < Mnu_NUM_MENUS)
return (Mnu_Menu_t) UnsignedNum;
2015-11-30 01:13:00 +01:00
return Mnu_MENU_DEFAULT;
2015-01-02 12:57:26 +01:00
}