swad-core/swad_degree_type.c

912 lines
32 KiB
C
Raw Normal View History

2016-03-20 16:30:52 +01:00
// swad_degree_type.c: degree types
/*
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
2016-03-20 16:30:52 +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 <ctype.h> // For isprint, isspace, etc.
#include <stdbool.h> // For boolean type
2019-12-29 12:39:00 +01:00
#include <stddef.h> // For NULL
2016-03-20 16:30:52 +01:00
#include <stdlib.h> // For exit, system, calloc, free, etc.
#include <string.h> // For string functions
#include <mysql/mysql.h> // To access MySQL databases
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2016-03-20 16:30:52 +01:00
#include "swad_config.h"
#include "swad_database.h"
#include "swad_degree.h"
#include "swad_degree_database.h"
2016-03-20 16:30:52 +01:00
#include "swad_degree_type.h"
#include "swad_error.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"
2016-03-20 16:30:52 +01:00
#include "swad_global.h"
#include "swad_hierarchy_level.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2016-03-20 16:30:52 +01:00
#include "swad_parameter.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
2019-04-08 12:01:08 +02:00
/**************************** Private variables ******************************/
2016-03-20 16:30:52 +01:00
/*****************************************************************************/
static struct DegreeType *DegTyp_EditingDegTyp = NULL; // Static variable to keep the degree type being edited
2019-04-08 12:01:08 +02:00
2016-03-20 16:30:52 +01:00
/*****************************************************************************/
2019-04-08 12:01:08 +02:00
/*************************** Private prototypes ******************************/
2016-03-20 16:30:52 +01:00
/*****************************************************************************/
static void DegTyp_SeeDegreeTypes (Act_Action_t NextAction,HieLvl_Level_t Scope,
DegTyp_Order_t DefaultOrder);
static DegTyp_Order_t DegTyp_GetParamDegTypOrder (DegTyp_Order_t DefaultOrder);
2017-03-24 01:09:27 +01:00
static void DegTyp_ListDegreeTypes (Act_Action_t NextAction,
HieLvl_Level_t Scope,
DegTyp_Order_t SelectedOrder);
2018-11-15 12:52:56 +01:00
static void DegTyp_EditDegreeTypesInternal (void);
static void DegTyp_PutIconsEditingDegreeTypes (__attribute__((unused)) void *Args);
2018-11-15 12:52:56 +01:00
static void DegTyp_ListDegreeTypesForSeeing (void);
static void DegTyp_PutIconsListingDegTypes (__attribute__((unused)) void *Args);
static void DegTyp_PutIconToEditDegTypes (__attribute__((unused)) void *Args);
static void DegTyp_ListDegreeTypesForEdition (void);
2016-03-20 16:30:52 +01:00
static void DegTyp_PutFormToCreateDegreeType (void);
2019-04-08 12:01:08 +02:00
static void DegTyp_PutHeadDegreeTypesForSeeing (Act_Action_t NextAction,
HieLvl_Level_t Scope,
DegTyp_Order_t SelectedOrder);
static void DegTyp_PutHeadDegreeTypesForEdition (void);
2016-03-20 16:30:52 +01:00
static void DegTyp_PutParamOtherDegTypCod (void *DegTypCod);
2016-03-20 16:30:52 +01:00
static void DegTyp_RemoveDegreeTypeCompletely (long DegTypCod);
2016-03-20 16:30:52 +01:00
static void DegTyp_EditingDegreeTypeConstructor (void);
static void DegTyp_EditingDegreeTypeDestructor (void);
2019-04-08 12:01:08 +02:00
2016-03-20 16:30:52 +01:00
/*****************************************************************************/
/************** Show selector of degree types for statistics *****************/
/*****************************************************************************/
void DegTyp_WriteSelectorDegreeTypes (long SelectedDegTypCod)
2016-03-20 16:30:52 +01:00
{
extern const char *The_ClassInput[The_NUM_THEMES];
2016-03-20 16:30:52 +01:00
extern const char *Txt_Any_type_of_degree;
unsigned NumDegTyp;
2016-06-09 17:56:57 +02:00
/***** Form to select degree types *****/
/* Get list of degree types */
DegTyp_GetListDegreeTypes (HieLvl_SYS,DegTyp_ORDER_BY_DEGREE_TYPE);
2016-03-20 16:30:52 +01:00
2016-06-09 17:56:57 +02:00
/* List degree types */
2020-04-27 03:16:55 +02:00
HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE,
"id=\"OthDegTypCod\" name=\"OthDegTypCod\" class=\"%s\"",
The_ClassInput[Gbl.Prefs.Theme]);
HTM_OPTION (HTM_Type_STRING,"-1",
SelectedDegTypCod == -1L,false,
"%s",Txt_Any_type_of_degree);
for (NumDegTyp = 0;
NumDegTyp < Gbl.DegTypes.Num;
NumDegTyp++)
HTM_OPTION (HTM_Type_LONG,&Gbl.DegTypes.Lst[NumDegTyp].DegTypCod,
Gbl.DegTypes.Lst[NumDegTyp].DegTypCod == SelectedDegTypCod,false,
"%s",Gbl.DegTypes.Lst[NumDegTyp].DegTypName);
2019-11-05 08:46:38 +01:00
HTM_SELECT_End ();
2016-03-20 16:30:52 +01:00
/***** Free list of degree types *****/
DegTyp_FreeListDegreeTypes ();
2016-03-20 16:30:52 +01:00
}
/*****************************************************************************/
/***************************** Show degree types *****************************/
/*****************************************************************************/
void DegTyp_SeeDegreeTypesInDegTab (void)
2017-03-24 12:23:42 +01:00
{
DegTyp_SeeDegreeTypes (ActSeeDegTyp,HieLvl_SYS,
DegTyp_ORDER_BY_DEGREE_TYPE); // Default order if not specified
2017-03-24 12:23:42 +01:00
}
void DegTyp_SeeDegreeTypesInStaTab (void)
2017-03-24 12:23:42 +01:00
{
DegTyp_SeeDegreeTypes (ActSeeUseGbl,Gbl.Scope.Current,
DegTyp_ORDER_BY_NUM_DEGREES); // Default order if not specified
2017-03-24 12:23:42 +01:00
}
static void DegTyp_SeeDegreeTypes (Act_Action_t NextAction,HieLvl_Level_t Scope,
DegTyp_Order_t DefaultOrder)
2016-03-20 16:30:52 +01:00
{
DegTyp_Order_t SelectedOrder;
2017-03-24 13:22:54 +01:00
2017-03-24 01:09:27 +01:00
/***** Get parameter with the type of order in the list of degree types *****/
SelectedOrder = DegTyp_GetParamDegTypOrder (DefaultOrder);
2017-03-24 01:09:27 +01:00
2016-03-20 16:30:52 +01:00
/***** Get list of degree types *****/
DegTyp_GetListDegreeTypes (Scope,SelectedOrder);
2016-03-20 16:30:52 +01:00
/***** List degree types *****/
DegTyp_ListDegreeTypes (NextAction,Scope,SelectedOrder);
2016-03-20 16:30:52 +01:00
/***** Free list of degree types *****/
DegTyp_FreeListDegreeTypes ();
2016-03-20 16:30:52 +01:00
}
2017-03-24 01:09:27 +01:00
/*****************************************************************************/
/******* Get parameter with the type or order in list of degree types ********/
/*****************************************************************************/
static DegTyp_Order_t DegTyp_GetParamDegTypOrder (DegTyp_Order_t DefaultOrder)
2017-03-24 01:09:27 +01:00
{
return (DegTyp_Order_t) Par_GetParToUnsignedLong ("Order",
0,
DegTyp_NUM_ORDERS - 1,
(unsigned long) DefaultOrder);
2017-03-24 01:09:27 +01:00
}
2016-03-20 16:30:52 +01:00
/*****************************************************************************/
/***************************** List degree types *****************************/
/*****************************************************************************/
2017-03-24 12:23:42 +01:00
// This function can be called from:
// - center tab => NextAction = ActSeeDegTyp
2017-03-26 17:32:19 +02:00
// - statistic tab => NextAction = ActSeeUseGbl
2016-03-20 16:30:52 +01:00
static void DegTyp_ListDegreeTypes (Act_Action_t NextAction,
HieLvl_Level_t Scope,
DegTyp_Order_t SelectedOrder)
2016-03-20 16:30:52 +01:00
{
extern const char *Hlp_CENTER_DegreeTypes;
2017-12-19 18:41:19 +01:00
extern const char *Hlp_ANALYTICS_Figures_types_of_degree;
2017-03-24 12:23:42 +01:00
extern const char *Txt_Types_of_degree;
2017-04-30 14:03:45 +02:00
extern const char *Txt_No_types_of_degree;
extern const char *Txt_Create_another_type_of_degree;
extern const char *Txt_Create_type_of_degree;
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2017-04-30 14:03:45 +02:00
switch (NextAction)
{
case ActSeeDegTyp:
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_Types_of_degree,
DegTyp_PutIconsListingDegTypes,NULL,
Hlp_CENTER_DegreeTypes,Box_NOT_CLOSABLE);
2017-04-30 14:03:45 +02:00
break;
case ActSeeUseGbl:
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_Types_of_degree,
DegTyp_PutIconToEditDegTypes,NULL,
2017-12-19 18:41:19 +01:00
Hlp_ANALYTICS_Figures_types_of_degree,Box_NOT_CLOSABLE);
2017-04-30 14:03:45 +02:00
break;
default: // Bad call
return;
}
2016-03-20 16:30:52 +01:00
2019-04-04 10:45:15 +02:00
if (Gbl.DegTypes.Num)
2017-03-24 12:23:42 +01:00
{
/***** Begin table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWideMarginPadding (2);
2017-03-24 12:23:42 +01:00
/***** Write heading *****/
DegTyp_PutHeadDegreeTypesForSeeing (NextAction,Scope,SelectedOrder);
/***** List current degree types for seeing *****/
DegTyp_ListDegreeTypesForSeeing ();
2017-03-24 12:23:42 +01:00
2017-04-30 14:03:45 +02:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2017-03-24 12:23:42 +01:00
}
2017-04-30 14:03:45 +02:00
else // No degree types created
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_INFO,Txt_No_types_of_degree);
2017-04-30 14:03:45 +02:00
/***** Button to create degree type *****/
if (DegTyp_CheckIfICanCreateDegreeTypes ())
2017-04-30 14:03:45 +02:00
{
Frm_BeginForm (ActEdiDegTyp);
Btn_PutConfirmButton (Gbl.DegTypes.Num ? Txt_Create_another_type_of_degree :
Txt_Create_type_of_degree);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-04-30 14:03:45 +02:00
}
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-03-20 16:30:52 +01:00
}
/*****************************************************************************/
/************************ Put forms to edit degree types *********************/
/*****************************************************************************/
void DegTyp_EditDegreeTypes (void)
2019-04-08 12:01:08 +02:00
{
/***** Degree type constructor *****/
DegTyp_EditingDegreeTypeConstructor ();
2019-04-08 12:01:08 +02:00
/***** Edit degree types *****/
DegTyp_EditDegreeTypesInternal ();
2019-04-08 12:01:08 +02:00
/***** Degree type destructor *****/
DegTyp_EditingDegreeTypeDestructor ();
2019-04-08 12:01:08 +02:00
}
static void DegTyp_EditDegreeTypesInternal (void)
2016-03-20 16:30:52 +01:00
{
extern const char *Hlp_CENTER_DegreeTypes_edit;
2017-04-30 14:03:45 +02:00
extern const char *Txt_Types_of_degree;
/***** Get list of degree types *****/
DegTyp_GetListDegreeTypes (HieLvl_SYS,DegTyp_ORDER_BY_DEGREE_TYPE);
2016-03-20 16:30:52 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_Types_of_degree,
DegTyp_PutIconsEditingDegreeTypes,NULL,
Hlp_CENTER_DegreeTypes_edit,Box_NOT_CLOSABLE);
2016-03-20 16:30:52 +01:00
/***** Put a form to create a new degree type *****/
DegTyp_PutFormToCreateDegreeType ();
2016-03-20 16:30:52 +01:00
/***** Forms to edit current degree types *****/
if (Gbl.DegTypes.Num)
DegTyp_ListDegreeTypesForEdition ();
2017-04-30 14:03:45 +02:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2017-04-30 14:03:45 +02:00
/***** Free list of degree types *****/
DegTyp_FreeListDegreeTypes ();
2016-03-20 16:30:52 +01:00
}
2018-11-15 12:52:56 +01:00
/*****************************************************************************/
/************ Put contextual icons when editing degree types *****************/
/*****************************************************************************/
static void DegTyp_PutIconsEditingDegreeTypes (__attribute__((unused)) void *Args)
2018-11-15 12:52:56 +01:00
{
2020-04-08 18:18:46 +02:00
/***** Put icon to view degree types *****/
DegTyp_PutIconToViewDegreeTypes ();
2018-11-15 12:52:56 +01:00
2020-04-08 18:18:46 +02:00
/***** Put icon to view degrees *****/
Deg_PutIconToViewDegrees ();
2018-11-15 12:52:56 +01:00
2020-04-08 18:18:46 +02:00
/***** Put icon to show a figure *****/
Fig_PutIconToShowFigure (Fig_DEGREE_TYPES);
2018-11-15 12:52:56 +01:00
}
/*****************************************************************************/
/******************* Put link (form) to view degree types ********************/
/*****************************************************************************/
void DegTyp_PutIconToViewDegreeTypes (void)
2018-11-15 12:52:56 +01:00
{
extern const char *Txt_Types_of_degree;
2020-03-26 02:54:30 +01:00
Lay_PutContextualLinkOnlyIcon (ActSeeDegTyp,NULL,
NULL,NULL,
"sitemap.svg",Ico_BLACK,
2019-01-12 03:00:59 +01:00
Txt_Types_of_degree);
2018-11-15 12:52:56 +01:00
}
2016-03-20 16:30:52 +01:00
/*****************************************************************************/
/******************* List current degree types for seeing ********************/
/*****************************************************************************/
static void DegTyp_ListDegreeTypesForSeeing (void)
2016-03-20 16:30:52 +01:00
{
extern const char *The_ClassBgHighlight[The_NUM_THEMES];
extern const char *The_ClassDatStrong[The_NUM_THEMES];
2016-03-20 16:30:52 +01:00
unsigned NumDegTyp;
const char *BgColor;
/***** List degree types with forms for edition *****/
for (NumDegTyp = 0;
2019-04-04 10:45:15 +02:00
NumDegTyp < Gbl.DegTypes.Num;
NumDegTyp++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd)
2016-03-20 16:30:52 +01:00
{
2019-04-04 10:45:15 +02:00
BgColor = (Gbl.DegTypes.Lst[NumDegTyp].DegTypCod ==
Gbl.Hierarchy.Deg.DegTypCod) ? The_ClassBgHighlight[Gbl.Prefs.Theme] :
2019-04-04 10:45:15 +02:00
Gbl.ColorRows[Gbl.RowEvenOdd];
2016-03-20 16:30:52 +01:00
/* Begin table row */
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-08 15:49:01 +02:00
/* Number of degree type in this list */
HTM_TD_Begin ("class=\"RM %s %s\"",
The_ClassDatStrong[Gbl.Prefs.Theme],BgColor);
HTM_Unsigned (NumDegTyp + 1);
HTM_TD_End ();
2017-03-24 01:09:27 +01:00
/* Name of degree type */
HTM_TD_Begin ("class=\"LM %s %s\"",
The_ClassDatStrong[Gbl.Prefs.Theme],BgColor);
HTM_Txt (Gbl.DegTypes.Lst[NumDegTyp].DegTypName);
HTM_TD_End ();
2016-03-20 16:30:52 +01:00
/* Number of degrees of this type */
HTM_TD_Begin ("class=\"RM %s %s\"",
The_ClassDatStrong[Gbl.Prefs.Theme],BgColor);
HTM_Unsigned (Gbl.DegTypes.Lst[NumDegTyp].NumDegs);
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
/* End table row */
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2016-03-20 16:30:52 +01:00
}
}
2017-03-24 13:58:35 +01:00
/*****************************************************************************/
/************** Put contextual icons in list of degree types *****************/
/*****************************************************************************/
static void DegTyp_PutIconsListingDegTypes (__attribute__((unused)) void *Args)
2017-03-24 13:58:35 +01:00
{
2020-04-08 13:40:21 +02:00
/***** Put icon to edit degree types *****/
DegTyp_PutIconToEditDegTypes (NULL);
2017-03-24 13:58:35 +01:00
2020-04-08 13:40:21 +02:00
/***** Put icon to view degrees *****/
Deg_PutIconToViewDegrees ();
2018-11-15 12:52:56 +01:00
2020-04-08 13:40:21 +02:00
/***** Put icon to show a figure *****/
Fig_PutIconToShowFigure (Fig_DEGREE_TYPES);
2017-03-24 13:58:35 +01:00
}
2016-03-20 16:30:52 +01:00
/*****************************************************************************/
/******************* Put link (form) to edit degree types ********************/
/*****************************************************************************/
static void DegTyp_PutIconToEditDegTypes (__attribute__((unused)) void *Args)
2016-03-20 16:30:52 +01:00
{
if (Gbl.Hierarchy.Level == HieLvl_CTR && // Only editable if center tab is visible
DegTyp_CheckIfICanCreateDegreeTypes ())
2020-04-08 13:40:21 +02:00
Ico_PutContextualIconToEdit (ActEdiDegTyp,NULL,
NULL,NULL);
2016-03-20 16:30:52 +01:00
}
/*****************************************************************************/
/******************* List current degree types for edition *******************/
/*****************************************************************************/
static void DegTyp_ListDegreeTypesForEdition (void)
2016-03-20 16:30:52 +01:00
{
extern const char *The_ClassDat[The_NUM_THEMES];
2016-03-20 16:30:52 +01:00
unsigned NumDegTyp;
/***** Begin table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWidePadding (2);
2016-03-20 16:30:52 +01:00
/***** Write heading *****/
DegTyp_PutHeadDegreeTypesForEdition ();
2019-10-07 00:05:24 +02:00
/***** List degree types with forms for edition *****/
for (NumDegTyp = 0;
NumDegTyp < Gbl.DegTypes.Num;
NumDegTyp++)
{
/* Begin table row */
HTM_TR_Begin (NULL);
/* Put icon to remove degree type */
HTM_TD_Begin ("class=\"BM\"");
if (Gbl.DegTypes.Lst[NumDegTyp].NumDegs) // Degree type has degrees => deletion forbidden
Ico_PutIconRemovalNotAllowed ();
else
Ico_PutContextualIconToRemove (ActRemDegTyp,NULL,
DegTyp_PutParamOtherDegTypCod,&Gbl.DegTypes.Lst[NumDegTyp].DegTypCod);
HTM_TD_End ();
/* Degree type code */
HTM_TD_Begin ("class=\"%s CODE\"",The_ClassDat[Gbl.Prefs.Theme]);
HTM_Long (Gbl.DegTypes.Lst[NumDegTyp].DegTypCod);
HTM_TD_End ();
/* Name of degree type */
HTM_TD_Begin ("class=\"LM\"");
Frm_BeginForm (ActRenDegTyp);
DegTyp_PutParamOtherDegTypCod (&Gbl.DegTypes.Lst[NumDegTyp].DegTypCod);
HTM_INPUT_TEXT ("DegTypName",DegTyp_MAX_CHARS_DEGREE_TYPE_NAME,
Gbl.DegTypes.Lst[NumDegTyp].DegTypName,
HTM_SUBMIT_ON_CHANGE,
"size=\"25\" required=\"required\"");
Frm_EndForm ();
HTM_TD_End ();
/* Number of degrees of this type */
HTM_TD_Begin ("class=\"%s RM\"",The_ClassDat[Gbl.Prefs.Theme]);
HTM_Unsigned (Gbl.DegTypes.Lst[NumDegTyp].NumDegs);
HTM_TD_End ();
/* End table row */
HTM_TR_End ();
}
2016-03-20 16:30:52 +01:00
2017-04-30 14:03:45 +02:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2017-04-30 14:03:45 +02:00
}
/*****************************************************************************/
/******************** Check if I can create degree types *********************/
/*****************************************************************************/
bool DegTyp_CheckIfICanCreateDegreeTypes (void)
2017-04-30 14:03:45 +02:00
{
2017-06-04 18:18:54 +02:00
return (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM);
2016-03-20 16:30:52 +01:00
}
/*****************************************************************************/
/******************** Put a form to create a new degree type *****************/
/*****************************************************************************/
static void DegTyp_PutFormToCreateDegreeType (void)
2016-03-20 16:30:52 +01:00
{
extern const char *The_ClassDat[The_NUM_THEMES];
2016-03-20 16:30:52 +01:00
extern const char *Txt_New_type_of_degree;
extern const char *Txt_Create_type_of_degree;
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
Frm_BeginForm (ActNewDegTyp);
2016-03-20 16:30:52 +01:00
/***** Begin box and table *****/
Box_BoxTableBegin (NULL,Txt_New_type_of_degree,
NULL,NULL,
NULL,Box_NOT_CLOSABLE,2);
2016-03-20 16:30:52 +01:00
/***** Write heading *****/
DegTyp_PutHeadDegreeTypesForEdition ();
2017-04-30 14:03:45 +02:00
/***** Begin table row *****/
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
/***** Column to remove degree type, disabled here *****/
HTM_TD_Begin ("class=\"BM\"");
HTM_TD_End ();
2017-04-30 14:03:45 +02:00
/***** Degree type code *****/
HTM_TD_Begin ("class=\"CODE\"");
HTM_TD_End ();
2016-03-20 16:30:52 +01:00
/***** Degree type name *****/
HTM_TD_Begin ("class=\"LM\"");
HTM_INPUT_TEXT ("DegTypName",DegTyp_MAX_CHARS_DEGREE_TYPE_NAME,DegTyp_EditingDegTyp->DegTypName,
HTM_DONT_SUBMIT_ON_CHANGE,
"size=\"25\" required=\"required\"");
HTM_TD_End ();
2016-03-20 16:30:52 +01:00
/***** Number of degrees of this degree type ****/
HTM_TD_Begin ("class=\"%s RM\"",The_ClassDat[Gbl.Prefs.Theme]);
HTM_Unsigned (0);
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
/***** End table row *****/
HTM_TR_End ();
2017-04-30 14:03:45 +02:00
/***** End table, send button and end box *****/
Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_type_of_degree);
2016-03-20 16:30:52 +01:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-03-20 16:30:52 +01:00
}
/*****************************************************************************/
/***************** Write header with fields of a degree type *****************/
/*****************************************************************************/
static void DegTyp_PutHeadDegreeTypesForSeeing (Act_Action_t NextAction,
HieLvl_Level_t Scope,
DegTyp_Order_t SelectedOrder)
2016-03-20 16:30:52 +01:00
{
extern const char *Txt_DEGREE_TYPES_HELP_ORDER[DegTyp_NUM_ORDERS];
extern const char *Txt_DEGREE_TYPES_ORDER[DegTyp_NUM_ORDERS];
DegTyp_Order_t Order;
2020-04-06 23:18:02 +02:00
struct Fig_Figures Figures;
2016-03-20 16:30:52 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2017-03-24 01:09:27 +01:00
HTM_TH_Empty (1);
for (Order = DegTyp_ORDER_BY_DEGREE_TYPE;
Order <= DegTyp_ORDER_BY_NUM_DEGREES;
Order++)
2020-04-06 23:18:02 +02:00
{
HTM_TH_Begin (1,1,Order == DegTyp_ORDER_BY_DEGREE_TYPE ? "TIT_TBL LM" :
"TIT_TBL RM");
/* Begin form to change order */
Frm_BeginForm (NextAction);
if (NextAction == ActSeeUseGbl)
{
Figures.Scope = Scope;
Figures.FigureType = Fig_DEGREE_TYPES;
Fig_PutHiddenParamFigures (&Figures);
}
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order);
/* Link with the head of this column */
HTM_BUTTON_OnSubmit_Begin (Txt_DEGREE_TYPES_HELP_ORDER[Order],
"BT_LINK",NULL);
if (Order == SelectedOrder)
HTM_U_Begin ();
HTM_Txt (Txt_DEGREE_TYPES_ORDER[Order]);
if (Order == SelectedOrder)
HTM_U_End ();
HTM_BUTTON_End ();
/* End form */
Frm_EndForm ();
HTM_TH_End ();
2020-04-06 23:18:02 +02:00
}
2017-03-24 01:09:27 +01:00
HTM_TR_End ();
2016-03-20 16:30:52 +01:00
}
/*****************************************************************************/
/***************** Write header with fields of a degree type *****************/
/*****************************************************************************/
static void DegTyp_PutHeadDegreeTypesForEdition (void)
2016-03-20 16:30:52 +01:00
{
extern const char *Txt_Code;
2016-03-20 16:55:34 +01:00
extern const char *Txt_Type_of_degree;
2016-03-20 16:30:52 +01:00
extern const char *Txt_Degrees;
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-11 15:36:50 +02:00
HTM_TH (1,1,NULL ,"BM");
HTM_TH (1,1,Txt_Code ,"CM");
HTM_TH (1,1,Txt_Type_of_degree,"CM");
HTM_TH (1,1,Txt_Degrees ,"RM");
2019-10-11 15:36:50 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2016-03-20 16:30:52 +01:00
}
/*****************************************************************************/
/****************** Create a list with all degree types **********************/
2016-03-20 16:30:52 +01:00
/*****************************************************************************/
void DegTyp_GetListDegreeTypes (HieLvl_Level_t Scope,DegTyp_Order_t Order)
2016-03-20 16:30:52 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumTyp;
2016-03-20 16:30:52 +01:00
/***** Get types of degree from database *****/
Gbl.DegTypes.Num = Deg_DB_GetDegreeTypes (&mysql_res,Scope,Order);
2016-03-20 16:30:52 +01:00
/***** Get degree types *****/
2019-04-04 10:45:15 +02:00
if (Gbl.DegTypes.Num)
2016-03-20 16:30:52 +01:00
{
/***** Create a list of degree types *****/
if ((Gbl.DegTypes.Lst = calloc (Gbl.DegTypes.Num,
sizeof (*Gbl.DegTypes.Lst))) == NULL)
Err_NotEnoughMemoryExit ();
2016-03-20 16:30:52 +01:00
/***** Get degree types *****/
for (NumTyp = 0;
NumTyp < Gbl.DegTypes.Num;
NumTyp++)
2016-03-20 16:30:52 +01:00
{
/* Get next degree type */
row = mysql_fetch_row (mysql_res);
/* Get degree type code (row[0]) */
if ((Gbl.DegTypes.Lst[NumTyp].DegTypCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongDegTypExit ();
2016-03-20 16:30:52 +01:00
/* Get degree type name (row[1]) */
Str_Copy (Gbl.DegTypes.Lst[NumTyp].DegTypName,row[1],
sizeof (Gbl.DegTypes.Lst[NumTyp].DegTypName) - 1);
2016-03-20 16:30:52 +01:00
/* Number of degrees of this type (row[2]) */
if (sscanf (row[2],"%u",&Gbl.DegTypes.Lst[NumTyp].NumDegs) != 1)
Err_ShowErrorAndExit ("Error when getting number of degrees of a type");
2016-03-20 16:30:52 +01:00
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/********* Free list of degree types and list of degrees of each type ********/
/*****************************************************************************/
void DegTyp_FreeListDegreeTypes (void)
2016-03-20 16:30:52 +01:00
{
/***** Free memory used by the list of degree types *****/
2019-04-04 10:45:15 +02:00
if (Gbl.DegTypes.Lst)
2016-03-20 16:30:52 +01:00
{
2019-11-06 19:45:20 +01:00
free (Gbl.DegTypes.Lst);
2019-04-04 10:45:15 +02:00
Gbl.DegTypes.Lst = NULL;
Gbl.DegTypes.Num = 0;
2016-03-20 16:30:52 +01:00
}
}
/*****************************************************************************/
/***************** Receive form to create a new degree type ******************/
/*****************************************************************************/
void DegTyp_ReceiveFormNewDegreeType (void)
2016-03-20 16:30:52 +01:00
{
extern const char *Txt_The_type_of_degree_X_already_exists;
2019-04-08 13:06:17 +02:00
extern const char *Txt_Created_new_type_of_degree_X;
2016-03-20 16:30:52 +01:00
extern const char *Txt_You_must_specify_the_name_of_the_new_type_of_degree;
2019-04-08 12:01:08 +02:00
/***** Degree type constructor *****/
DegTyp_EditingDegreeTypeConstructor ();
2016-03-20 16:30:52 +01:00
/***** Get parameters from form *****/
/* Get the name of degree type */
Par_GetParToText ("DegTypName",DegTyp_EditingDegTyp->DegTypName,DegTyp_MAX_BYTES_DEGREE_TYPE_NAME);
2016-03-20 16:30:52 +01:00
if (DegTyp_EditingDegTyp->DegTypName[0]) // If there's a degree type name
2016-03-20 16:30:52 +01:00
{
/***** If name of degree type was in database... *****/
if (Deg_DB_CheckIfDegreeTypeNameExists (DegTyp_EditingDegTyp->DegTypName,-1L))
2019-04-08 13:06:17 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_type_of_degree_X_already_exists,
DegTyp_EditingDegTyp->DegTypName);
2016-03-20 16:30:52 +01:00
else // Add new degree type to database
2019-04-08 13:06:17 +02:00
{
Deg_DB_CreateDegreeType (DegTyp_EditingDegTyp->DegTypName);
2019-04-08 13:06:17 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Created_new_type_of_degree_X,
DegTyp_EditingDegTyp->DegTypName);
2019-04-08 13:06:17 +02:00
}
2016-03-20 16:30:52 +01:00
}
else // If there is not a degree type name
2019-04-08 13:06:17 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_must_specify_the_name_of_the_new_type_of_degree);
2016-03-20 16:30:52 +01:00
}
/*****************************************************************************/
/**************************** Remove a degree type ***************************/
/*****************************************************************************/
void DegTyp_RemoveDegreeType (void)
2016-03-20 16:30:52 +01:00
{
extern const char *Txt_To_remove_a_type_of_degree_you_must_first_remove_all_degrees_of_that_type;
extern const char *Txt_Type_of_degree_X_removed;
2019-04-08 12:01:08 +02:00
/***** Degree type constructor *****/
DegTyp_EditingDegreeTypeConstructor ();
2016-03-20 16:30:52 +01:00
/***** Get the code of the degree type *****/
DegTyp_EditingDegTyp->DegTypCod = DegTyp_GetAndCheckParamOtherDegTypCod (1);
2016-03-20 16:30:52 +01:00
/***** Get data of the degree type from database *****/
if (!DegTyp_GetDataOfDegreeTypeByCod (DegTyp_EditingDegTyp))
Err_WrongDegTypExit ();
2016-03-20 16:30:52 +01:00
/***** Check if this degree type has degrees *****/
if (DegTyp_EditingDegTyp->NumDegs) // Degree type has degrees => don't remove
2019-04-08 13:06:17 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_To_remove_a_type_of_degree_you_must_first_remove_all_degrees_of_that_type);
2017-03-26 17:32:19 +02:00
else // Degree type has no degrees => remove it
2016-03-20 16:30:52 +01:00
{
/***** Remove degree type *****/
DegTyp_RemoveDegreeTypeCompletely (DegTyp_EditingDegTyp->DegTypCod);
2016-03-20 16:30:52 +01:00
/***** Write message to show the change made *****/
2019-04-08 13:06:17 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Type_of_degree_X_removed,
DegTyp_EditingDegTyp->DegTypName);
2016-03-20 16:30:52 +01:00
}
}
/*****************************************************************************/
/***************** Write parameter with code of degree type ******************/
/*****************************************************************************/
static void DegTyp_PutParamOtherDegTypCod (void *DegTypCod)
2016-03-20 16:30:52 +01:00
{
2020-10-13 22:34:31 +02:00
if (DegTypCod)
Par_PutHiddenParamLong (NULL,"OthDegTypCod",*((long *) DegTypCod));
2016-03-20 16:30:52 +01:00
}
/*****************************************************************************/
/******************* Get parameter with code of degree type ******************/
/*****************************************************************************/
long DegTyp_GetAndCheckParamOtherDegTypCod (long MinCodAllowed)
2016-03-20 16:30:52 +01:00
{
2017-05-31 21:05:59 +02:00
long DegTypCod;
/***** Get and check parameter with code of degree type *****/
if ((DegTypCod = Par_GetParToLong ("OthDegTypCod")) < MinCodAllowed)
Err_WrongDegTypExit ();
2017-05-31 21:05:59 +02:00
return DegTypCod;
2016-03-20 16:30:52 +01:00
}
/*****************************************************************************/
/****************** Get data of a degree type from its code ******************/
/*****************************************************************************/
bool DegTyp_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp)
2016-03-20 16:30:52 +01:00
{
/***** Trivial check: code of degree type should be >= 0 *****/
2016-03-20 16:30:52 +01:00
if (DegTyp->DegTypCod <= 0)
{
DegTyp->DegTypName[0] = '\0';
DegTyp->NumDegs = 0;
return false;
}
/***** Get the name of a type of degree from database *****/
Deg_DB_GetDegTypeNameByCod (DegTyp);
if (DegTyp->DegTypName[0])
2016-03-20 16:30:52 +01:00
{
/* Count number of degrees of this type */
DegTyp->NumDegs = Deg_DB_GetNumDegsOfType (DegTyp->DegTypCod);
return true;
2016-03-20 16:30:52 +01:00
}
DegTyp->DegTypName[0] = '\0';
DegTyp->NumDegs = 0;
return false;
2016-03-20 16:30:52 +01:00
}
/*****************************************************************************/
/******************** Remove a degree type and its degrees *******************/
/*****************************************************************************/
static void DegTyp_RemoveDegreeTypeCompletely (long DegTypCod)
2016-03-20 16:30:52 +01:00
{
MYSQL_RES *mysql_res;
unsigned NumDegs;
unsigned NumDeg;
2016-03-20 16:30:52 +01:00
long DegCod;
/***** Get degrees of a type from database *****/
NumDegs = Deg_DB_GetDegsOfType (&mysql_res,DegTypCod);
/***** Remove degrees ******/
for (NumDeg = 0;
NumDeg < NumDegs;
NumDeg++)
2016-03-20 16:30:52 +01:00
{
/* Get next degree */
if ((DegCod = DB_GetNextCode (mysql_res)) < 0)
Err_WrongDegreeExit ();
2016-03-20 16:30:52 +01:00
/* Remove degree */
Deg_RemoveDegreeCompletely (DegCod);
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
/***** Remove the degree type *****/
Deg_DB_RemoveDegTyp (DegTypCod);
2016-03-20 16:30:52 +01:00
}
/*****************************************************************************/
/**************************** Rename a degree type ***************************/
/*****************************************************************************/
void DegTyp_RenameDegreeType (void)
2016-03-20 16:30:52 +01:00
{
extern const char *Txt_The_type_of_degree_X_already_exists;
extern const char *Txt_The_type_of_degree_X_has_been_renamed_as_Y;
extern const char *Txt_The_name_of_the_type_of_degree_X_has_not_changed;
char NewNameDegTyp[DegTyp_MAX_BYTES_DEGREE_TYPE_NAME + 1];
2016-03-20 16:30:52 +01:00
2019-04-08 12:01:08 +02:00
/***** Degree type constructor *****/
DegTyp_EditingDegreeTypeConstructor ();
2016-03-20 16:30:52 +01:00
/***** Get parameters from form *****/
/* Get the code of the degree type */
DegTyp_EditingDegTyp->DegTypCod = DegTyp_GetAndCheckParamOtherDegTypCod (1);
2016-03-20 16:30:52 +01:00
/* Get the new name for the degree type */
Par_GetParToText ("DegTypName",NewNameDegTyp,DegTyp_MAX_BYTES_DEGREE_TYPE_NAME);
2016-03-20 16:30:52 +01:00
/***** Get from the database the old name of the degree type *****/
if (!DegTyp_GetDataOfDegreeTypeByCod (DegTyp_EditingDegTyp))
Err_WrongDegTypExit ();
2016-03-20 16:30:52 +01:00
/***** Check if new name is empty *****/
2019-12-20 00:30:54 +01:00
if (NewNameDegTyp[0])
2016-03-20 16:30:52 +01:00
{
2019-01-02 15:10:51 +01:00
/***** Check if old and new names are the same
(this happens when return is pressed without changes) *****/
if (strcmp (DegTyp_EditingDegTyp->DegTypName,NewNameDegTyp)) // Different names
2016-03-20 16:30:52 +01:00
{
/***** If degree type was in database... *****/
if (Deg_DB_CheckIfDegreeTypeNameExists (NewNameDegTyp,DegTyp_EditingDegTyp->DegTypCod))
2019-04-08 13:06:17 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_type_of_degree_X_already_exists,
NewNameDegTyp);
2016-03-20 16:30:52 +01:00
else
{
/* Update the table changing old name by new name */
Deg_DB_UpdateDegTypName (DegTyp_EditingDegTyp->DegTypCod,NewNameDegTyp);
2016-03-20 16:30:52 +01:00
/* Write message to show the change made */
2019-04-08 13:06:17 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_type_of_degree_X_has_been_renamed_as_Y,
DegTyp_EditingDegTyp->DegTypName,NewNameDegTyp);
2016-03-20 16:30:52 +01:00
}
2019-04-08 13:06:17 +02:00
2016-03-20 16:30:52 +01:00
}
else // The same name
2019-04-08 13:06:17 +02:00
Ale_CreateAlert (Ale_INFO,NULL,
Txt_The_name_of_the_type_of_degree_X_has_not_changed,
NewNameDegTyp);
2016-03-20 16:30:52 +01:00
}
2019-12-20 00:30:54 +01:00
else
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
2016-03-20 16:30:52 +01:00
2019-04-08 13:06:17 +02:00
/***** Set degree type name *****/
Str_Copy (DegTyp_EditingDegTyp->DegTypName,NewNameDegTyp,
sizeof (DegTyp_EditingDegTyp->DegTypName) - 1);
2016-03-20 16:30:52 +01:00
}
2019-04-08 12:01:08 +02:00
/*****************************************************************************/
2019-04-08 13:06:17 +02:00
/********** Show message of success after changing a degree type *************/
/*****************************************************************************/
void DegTyp_ContEditAfterChgDegTyp (void)
2019-04-08 13:06:17 +02:00
{
/***** Show possible delayed alerts *****/
Ale_ShowAlerts (NULL);
/***** Show the form again *****/
DegTyp_EditDegreeTypesInternal ();
2019-04-08 13:06:17 +02:00
/***** Degree type destructor *****/
DegTyp_EditingDegreeTypeDestructor ();
2019-04-08 13:06:17 +02:00
}
/*****************************************************************************/
2019-04-08 12:01:08 +02:00
/********************* Degree type constructor/destructor ********************/
/*****************************************************************************/
static void DegTyp_EditingDegreeTypeConstructor (void)
2019-04-08 12:01:08 +02:00
{
/***** Pointer must be NULL *****/
if (DegTyp_EditingDegTyp != NULL)
Err_WrongDegTypExit ();
2019-04-08 12:01:08 +02:00
/***** Allocate memory for degree type *****/
if ((DegTyp_EditingDegTyp = malloc (sizeof (*DegTyp_EditingDegTyp))) == NULL)
Err_NotEnoughMemoryExit ();
2019-04-08 12:01:08 +02:00
/***** Reset degree type *****/
DegTyp_EditingDegTyp->DegTypCod = -1L;
DegTyp_EditingDegTyp->DegTypName[0] = '\0';
DegTyp_EditingDegTyp->NumDegs = 0;
2019-04-08 12:01:08 +02:00
}
static void DegTyp_EditingDegreeTypeDestructor (void)
2019-04-08 12:01:08 +02:00
{
/***** Free memory used for degree type *****/
if (DegTyp_EditingDegTyp != NULL)
2019-04-08 12:01:08 +02:00
{
free (DegTyp_EditingDegTyp);
DegTyp_EditingDegTyp = NULL;
2019-04-08 12:01:08 +02:00
}
}