swad-core/swad_degree_config.c

436 lines
15 KiB
C
Raw Permalink Normal View History

2019-12-29 13:13:09 +01:00
// swad_degree_config.c: configuration of current degree
/*
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-2024 Antonio Ca<EFBFBD>as Vargas
2019-12-29 13:13:09 +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 ***********************************/
/*****************************************************************************/
#define _GNU_SOURCE // For asprintf
2019-12-29 13:13:09 +01:00
#include <stdbool.h> // For boolean type
#include <stdio.h> // For asprintf
#include <stdlib.h> // For free
2019-12-29 13:13:09 +01:00
#include "swad_action_list.h"
#include "swad_alert.h"
#include "swad_box.h"
2019-12-29 15:10:34 +01:00
#include "swad_database.h"
2019-12-29 13:13:09 +01:00
#include "swad_degree_config.h"
#include "swad_degree_database.h"
#include "swad_error.h"
2019-12-29 13:13:09 +01:00
#include "swad_form.h"
#include "swad_global.h"
#include "swad_help.h"
2021-02-11 22:57:09 +01:00
#include "swad_hierarchy.h"
2019-12-29 20:11:57 +01:00
#include "swad_hierarchy_config.h"
#include "swad_hierarchy_type.h"
2019-12-29 13:13:09 +01:00
#include "swad_HTML.h"
#include "swad_logo.h"
#include "swad_parameter.h"
2019-12-29 13:13:09 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/**************************** Private prototypes *****************************/
/*****************************************************************************/
static void DegCfg_Configuration (Vie_ViewType_t ViewType);
2020-04-08 18:18:46 +02:00
static void DegCfg_PutIconsToPrintAndUpload (__attribute__((unused)) void *Args);
static void DegCfg_Center (Vie_ViewType_t ViewType,Frm_PutForm_t PutForm);
2019-12-29 13:13:09 +01:00
static void DegCfg_NumCrss (void);
/*****************************************************************************/
/****************** Show information of the current degree *******************/
/*****************************************************************************/
void DegCfg_ShowConfiguration (void)
{
DegCfg_Configuration (Vie_VIEW);
2019-12-29 13:13:09 +01:00
/***** Show help to enrol me *****/
Hlp_ShowHelpWhatWouldYouLikeToDo ();
}
/*****************************************************************************/
/****************** Print information of the current degree ******************/
/*****************************************************************************/
void DegCfg_PrintConfiguration (void)
{
DegCfg_Configuration (Vie_PRINT);
2019-12-29 13:13:09 +01:00
}
/*****************************************************************************/
/******************* Information of the current degree ***********************/
/*****************************************************************************/
static void DegCfg_Configuration (Vie_ViewType_t ViewType)
2019-12-29 13:13:09 +01:00
{
extern const char *Hlp_DEGREE_Information;
Hie_PutLink_t PutLink;
Frm_PutForm_t PutFormCtr;
Frm_PutForm_t PutFormName;
Frm_PutForm_t PutFormWWW;
2019-12-29 13:13:09 +01:00
/***** Trivial check *****/
if (Gbl.Hierarchy.Node[Hie_DEG].HieCod <= 0) // No degree selected
2019-12-29 13:13:09 +01:00
return;
/***** Initializations *****/
PutLink = (ViewType == Vie_VIEW &&
Gbl.Hierarchy.Node[Hie_DEG].WWW[0]) ? Hie_PUT_LINK :
Hie_DONT_PUT_LINK;
PutFormCtr = (ViewType == Vie_VIEW &&
Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM) ? Frm_PUT_FORM :
Frm_DONT_PUT_FORM;
PutFormName = (ViewType == Vie_VIEW &&
Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM) ? Frm_PUT_FORM :
Frm_DONT_PUT_FORM;
PutFormWWW = (ViewType == Vie_VIEW &&
Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM) ? Frm_PUT_FORM :
Frm_DONT_PUT_FORM;
2019-12-29 13:13:09 +01:00
/***** Begin box *****/
Box_BoxBegin (NULL,
ViewType == Vie_VIEW ? DegCfg_PutIconsToPrintAndUpload :
NULL,NULL,
ViewType == Vie_VIEW ? Hlp_DEGREE_Information :
NULL,Box_NOT_CLOSABLE);
/***** Title *****/
HieCfg_Title (PutLink,Hie_DEG);
2019-12-29 13:13:09 +01:00
/**************************** Left part ***********************************/
HTM_DIV_Begin ("class=\"HIE_CFG_LEFT\"");
2019-12-29 13:13:09 +01:00
/***** Begin table *****/
HTM_TABLE_BeginPadding (2);
2019-12-29 13:13:09 +01:00
/***** Center *****/
DegCfg_Center (ViewType,PutFormCtr);
2019-12-29 13:13:09 +01:00
/***** Degree name *****/
HieCfg_Name (PutFormName,Hie_DEG,Nam_FULL_NAME);
HieCfg_Name (PutFormName,Hie_DEG,Nam_SHRT_NAME);
2019-12-29 13:13:09 +01:00
/***** Degree WWW *****/
HieCfg_WWW (ViewType,PutFormWWW,ActChgDegWWWCfg,Gbl.Hierarchy.Node[Hie_DEG].WWW);
2019-12-29 13:13:09 +01:00
/***** Shortcut to the degree *****/
HieCfg_Shortcut (ViewType,ParCod_Deg,Gbl.Hierarchy.Node[Hie_DEG].HieCod);
2019-12-29 13:13:09 +01:00
switch (ViewType)
{
case Vie_VIEW:
/***** Number of courses *****/
DegCfg_NumCrss ();
/***** Number of users *****/
HieCfg_NumUsrsInCrss (Hie_DEG,Gbl.Hierarchy.Node[Hie_DEG].HieCod,Rol_TCH);
HieCfg_NumUsrsInCrss (Hie_DEG,Gbl.Hierarchy.Node[Hie_DEG].HieCod,Rol_NET);
HieCfg_NumUsrsInCrss (Hie_DEG,Gbl.Hierarchy.Node[Hie_DEG].HieCod,Rol_STD);
HieCfg_NumUsrsInCrss (Hie_DEG,Gbl.Hierarchy.Node[Hie_DEG].HieCod,Rol_UNK);
break;
case Vie_PRINT:
/***** QR code with link to the degree *****/
HieCfg_QR (ParCod_Deg,Gbl.Hierarchy.Node[Hie_DEG].HieCod);
break;
default:
Err_WrongTypeExit ();
}
2019-12-29 13:13:09 +01:00
/***** End table *****/
HTM_TABLE_End ();
/***** End of left part *****/
HTM_DIV_End ();
2019-12-29 13:13:09 +01:00
/***** End box *****/
Box_BoxEnd ();
}
/*****************************************************************************/
/************ Put contextual icons in configuration of a degree **************/
/*****************************************************************************/
2020-04-08 18:18:46 +02:00
static void DegCfg_PutIconsToPrintAndUpload (__attribute__((unused)) void *Args)
2019-12-29 13:13:09 +01:00
{
2020-04-08 18:18:46 +02:00
/***** Link to print info about degree *****/
Ico_PutContextualIconToPrint (ActPrnDegInf,NULL,NULL);
2020-04-08 18:18:46 +02:00
if (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM)
// Only degree admins, center admins, institution admins and system admins
2020-04-08 18:18:46 +02:00
// have permission to upload logo of the degree
/***** Link to upload logo of degree *****/
Lgo_PutIconToChangeLogo (Hie_DEG);
2019-12-29 13:13:09 +01:00
}
/*****************************************************************************/
/******************** Show center in degree configuration ********************/
2019-12-29 13:13:09 +01:00
/*****************************************************************************/
static void DegCfg_Center (Vie_ViewType_t ViewType,Frm_PutForm_t PutForm)
2019-12-29 13:13:09 +01:00
{
extern const char *Par_CodeStr[Par_NUM_PAR_COD];
extern const char *Txt_HIERARCHY_SINGUL_Abc[Hie_NUM_LEVELS];
2019-12-29 13:13:09 +01:00
unsigned NumCtr;
const struct Hie_Node *Ctr;
const char *Id[Frm_NUM_PUT_FORM] =
{
[Frm_DONT_PUT_FORM] = NULL,
[Frm_PUT_FORM ] = Par_CodeStr[ParCod_OthCtr],
};
2019-12-29 13:13:09 +01:00
/***** Center *****/
2019-12-29 13:13:09 +01:00
HTM_TR_Begin (NULL);
/* Label */
Frm_LabelColumn ("Frm_C1 RT",Id[PutForm],Txt_HIERARCHY_SINGUL_Abc[Hie_CTR]);
/* Data */
HTM_TD_Begin ("class=\"Frm_C2 LB DAT_%s\"",The_GetSuffix ());
switch (PutForm)
{
case Frm_DONT_PUT_FORM: // I can not move degree to another center
if (ViewType == Vie_VIEW)
{
Frm_BeginFormGoTo (ActSeeCtrInf);
ParCod_PutPar (ParCod_Ctr,Gbl.Hierarchy.Node[Hie_CTR].HieCod);
HTM_BUTTON_Submit_Begin (Str_BuildGoToTitle (Gbl.Hierarchy.Node[Hie_CTR].ShrtName),
"class=\"LB BT_LINK\"");
Str_FreeGoToTitle ();
}
Lgo_DrawLogo (Hie_CTR,&Gbl.Hierarchy.Node[Hie_CTR],"LM ICO20x20");
HTM_NBSP ();
HTM_Txt (Gbl.Hierarchy.Node[Hie_CTR].FullName);
if (ViewType == Vie_VIEW)
{
HTM_BUTTON_End ();
Frm_EndForm ();
}
break;
case Frm_PUT_FORM:
/* Get list of centers of the current institution */
Ctr_GetBasicListOfCenters (Gbl.Hierarchy.Node[Hie_INS].HieCod);
/* Put form to select center */
Frm_BeginForm (ActChgDegCtrCfg);
HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE,NULL,
"id=\"OthCtrCod\" name=\"OthCtrCod\""
" class=\"Frm_C2_INPUT INPUT_%s\"",
The_GetSuffix ());
for (NumCtr = 0;
NumCtr < Gbl.Hierarchy.List[Hie_INS].Num;
NumCtr++)
{
Ctr = &Gbl.Hierarchy.List[Hie_INS].Lst[NumCtr];
HTM_OPTION (HTM_Type_LONG,&Ctr->HieCod,
Ctr->HieCod == Gbl.Hierarchy.Node[Hie_CTR].HieCod ? HTM_OPTION_SELECTED :
HTM_OPTION_UNSELECTED,
HTM_OPTION_ENABLED,
"%s",Ctr->ShrtName);
}
HTM_SELECT_End ();
Frm_EndForm ();
/* Free list of centers */
Hie_FreeList (Hie_INS);
break;
}
HTM_TD_End ();
2019-12-29 13:13:09 +01:00
HTM_TR_End ();
}
/*****************************************************************************/
/************** Show number of courses in degree configuration ***************/
/*****************************************************************************/
static void DegCfg_NumCrss (void)
{
extern const char *Txt_HIERARCHY_PLURAL_Abc[Hie_NUM_LEVELS];
2019-12-29 13:13:09 +01:00
extern const char *Txt_Courses_of_DEGREE_X;
char *Title;
2019-12-29 13:13:09 +01:00
/***** Number of courses *****/
/* Begin table row */
2019-12-29 13:13:09 +01:00
HTM_TR_Begin (NULL);
/* Label */
Frm_LabelColumn ("Frm_C1 RT",NULL,Txt_HIERARCHY_PLURAL_Abc[Hie_CRS]);
/* Data */
HTM_TD_Begin ("class=\"Frm_C2 LB DAT_%s\"",The_GetSuffix ());
Frm_BeginFormGoTo (ActSeeCrs);
ParCod_PutPar (ParCod_Deg,Gbl.Hierarchy.Node[Hie_DEG].HieCod);
if (asprintf (&Title,Txt_Courses_of_DEGREE_X,
Gbl.Hierarchy.Node[Hie_DEG].ShrtName) < 0)
Err_NotEnoughMemoryExit ();
HTM_BUTTON_Submit_Begin (Title,"class=\"LB BT_LINK\"");
free (Title);
HTM_Unsigned (Hie_GetCachedNumNodesInHieLvl (Hie_CRS, // Number of courses...
Hie_DEG, // ...in degree
Gbl.Hierarchy.Node[Hie_DEG].HieCod));
HTM_BUTTON_End ();
Frm_EndForm ();
HTM_TD_End ();
2019-12-29 13:13:09 +01:00
/* End table row */
2019-12-29 13:13:09 +01:00
HTM_TR_End ();
}
2019-12-29 15:10:34 +01:00
/*****************************************************************************/
/************************ Change the center of a degree **********************/
2019-12-29 15:10:34 +01:00
/*****************************************************************************/
2019-12-29 16:21:42 +01:00
void DegCfg_ChangeDegCtr (void)
2019-12-29 15:10:34 +01:00
{
extern bool (*Hie_GetDataByCod[Hie_NUM_LEVELS]) (struct Hie_Node *Node);
extern const char *Txt_The_degree_X_has_been_moved_to_the_center_Y;
struct Hie_Node NewCtr;
const char *Names[Nam_NUM_SHRT_FULL_NAMES];
2019-12-29 15:10:34 +01:00
/***** Get parameter with center code *****/
NewCtr.HieCod = ParCod_GetAndCheckPar (ParCod_OthCtr);
2019-12-29 15:10:34 +01:00
/***** Check if center has changed *****/
if (NewCtr.HieCod != Gbl.Hierarchy.Node[Hie_DEG].PrtCod)
2019-12-29 15:10:34 +01:00
{
/***** Get data of new center *****/
Hie_GetDataByCod[Hie_CTR] (&NewCtr);
2019-12-29 15:10:34 +01:00
/***** Check if it already existed a degree with the same name in the new center *****/
Names[Nam_SHRT_NAME] = Gbl.Hierarchy.Node[Hie_DEG].ShrtName;
Names[Nam_FULL_NAME] = Gbl.Hierarchy.Node[Hie_DEG].FullName;
if (!Nam_CheckIfNameExists (Deg_DB_CheckIfDegNameExistsInCtr,
Names,
Gbl.Hierarchy.Node[Hie_DEG].HieCod,
NewCtr.HieCod,
0)) // Unused
2019-12-29 15:10:34 +01:00
{
/***** Update center in table of degrees *****/
Deg_DB_UpdateDegCtr (Gbl.Hierarchy.Node[Hie_DEG].HieCod,NewCtr.HieCod);
Gbl.Hierarchy.Node[Hie_DEG].PrtCod =
Gbl.Hierarchy.Node[Hie_CTR].HieCod = NewCtr.HieCod;
2019-12-29 15:10:34 +01:00
/***** Initialize again current course, degree, center... *****/
2019-12-29 15:10:34 +01:00
Hie_InitHierarchy ();
/***** Create alert to show the change made *****/
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_degree_X_has_been_moved_to_the_center_Y,
Names[Nam_FULL_NAME],
Gbl.Hierarchy.Node[Hie_CTR].FullName);
2019-12-29 15:10:34 +01:00
}
}
}
/*****************************************************************************/
/*************** Change the name of a degree in configuration ****************/
/*****************************************************************************/
void DegCfg_RenameDegreeShrt (void)
2019-12-29 15:10:34 +01:00
{
Deg_RenameDegree (&Gbl.Hierarchy.Node[Hie_DEG],Nam_SHRT_NAME);
2019-12-29 15:10:34 +01:00
}
2019-12-29 16:21:42 +01:00
void DegCfg_RenameDegreeFull (void)
2019-12-29 15:10:34 +01:00
{
Deg_RenameDegree (&Gbl.Hierarchy.Node[Hie_DEG],Nam_FULL_NAME);
2019-12-29 15:10:34 +01:00
}
/*****************************************************************************/
/************************* Change the WWW of a degree ************************/
/*****************************************************************************/
2019-12-29 16:21:42 +01:00
void DegCfg_ChangeDegWWW (void)
2019-12-29 15:10:34 +01:00
{
extern const char *Txt_The_new_web_address_is_X;
char NewWWW[WWW_MAX_BYTES_WWW + 1];
2019-12-29 15:10:34 +01:00
/***** Get parameters from form *****/
/* Get the new WWW for the degree */
Par_GetParText ("WWW",NewWWW,WWW_MAX_BYTES_WWW);
2019-12-29 15:10:34 +01:00
/***** Check if new WWW is empty *****/
if (NewWWW[0])
{
/***** Update the table changing old WWW by new WWW *****/
Deg_DB_UpdateDegWWW (Gbl.Hierarchy.Node[Hie_DEG].HieCod,NewWWW);
Str_Copy (Gbl.Hierarchy.Node[Hie_DEG].WWW,NewWWW,
sizeof (Gbl.Hierarchy.Node[Hie_DEG].WWW) - 1);
2019-12-29 15:10:34 +01:00
/***** Write message to show the change made *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_web_address_is_X,
NewWWW);
}
else
Ale_ShowAlertYouCanNotLeaveFieldEmpty ();
/***** Show the form again *****/
DegCfg_ShowConfiguration ();
}
/*****************************************************************************/
/*********** Show a form for sending a logo of the current degree ************/
/*****************************************************************************/
void DegCfg_ReqLogo (void)
{
Lgo_RequestLogo (Hie_DEG);
}
/*****************************************************************************/
/***************** Receive the logo of the current degree ********************/
/*****************************************************************************/
void DegCfg_ReceiveLogo (void)
{
Lgo_ReceiveLogo (Hie_DEG);
}
/*****************************************************************************/
/****************** Remove the logo of the current degree ********************/
/*****************************************************************************/
void DegCfg_RemoveLogo (void)
{
Lgo_RemoveLogo (Hie_DEG);
}
2019-12-29 15:10:34 +01:00
/*****************************************************************************/
/** Show message of success after changing a degree in degree configuration **/
/*****************************************************************************/
2019-12-29 16:21:42 +01:00
void DegCfg_ContEditAfterChgDeg (void)
2019-12-29 15:10:34 +01:00
{
/***** Write success / warning message *****/
Ale_ShowAlerts (NULL);
/***** Show the form again *****/
DegCfg_ShowConfiguration ();
}