Version 22.55: Oct 28, 2022 Code refactoring in degree types.

This commit is contained in:
acanas 2022-10-28 20:07:14 +02:00
parent 03ed699c83
commit 870f496b24
9 changed files with 188 additions and 108 deletions

View File

@ -362,7 +362,7 @@ const struct Act_Actions Act_Actions[Act_NUM_ACTIONS] =
[ActChgCtrPhoAtt ] = {1159,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,CtrCfg_ChangeCtrPhotoAttr ,NULL}, [ActChgCtrPhoAtt ] = {1159,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,CtrCfg_ChangeCtrPhotoAttr ,NULL},
[ActSeeDegTyp ] = {1013,-1,TabUnk,ActSeeDeg , 0, 0, 0,0x3C7, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,DegTyp_SeeDegreeTypesInDegTab ,NULL}, [ActSeeDegTyp ] = {1013,-1,TabUnk,ActSeeDeg , 0, 0, 0,0x3C7, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,DegTyp_SeeDegreeTypesInDegTab ,NULL},
[ActEdiDegTyp ] = { 573,-1,TabUnk,ActSeeDeg , 0, 0, 0,0x200, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,DegTyp_EditDegreeTypes ,NULL}, [ActEdiDegTyp ] = { 573,-1,TabUnk,ActSeeDeg , 0, 0, 0,0x200, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,DegTyp_GetAndEditDegreeTypes ,NULL},
[ActNewDegTyp ] = { 537,-1,TabUnk,ActSeeDeg , 0, 0, 0,0x200, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,DegTyp_ReceiveFormNewDegreeType,DegTyp_ContEditAfterChgDegTyp ,NULL}, [ActNewDegTyp ] = { 537,-1,TabUnk,ActSeeDeg , 0, 0, 0,0x200, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,DegTyp_ReceiveFormNewDegreeType,DegTyp_ContEditAfterChgDegTyp ,NULL},
[ActRemDegTyp ] = { 545,-1,TabUnk,ActSeeDeg , 0, 0, 0,0x200, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,DegTyp_RemoveDegreeType ,DegTyp_ContEditAfterChgDegTyp ,NULL}, [ActRemDegTyp ] = { 545,-1,TabUnk,ActSeeDeg , 0, 0, 0,0x200, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,DegTyp_RemoveDegreeType ,DegTyp_ContEditAfterChgDegTyp ,NULL},
[ActRenDegTyp ] = { 538,-1,TabUnk,ActSeeDeg , 0, 0, 0,0x200, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,DegTyp_RenameDegreeType ,DegTyp_ContEditAfterChgDegTyp ,NULL}, [ActRenDegTyp ] = { 538,-1,TabUnk,ActSeeDeg , 0, 0, 0,0x200, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,DegTyp_RenameDegreeType ,DegTyp_ContEditAfterChgDegTyp ,NULL},

View File

@ -605,7 +605,7 @@ TODO: Fix bug: error al enviar un mensaje a dos recipientes, error on duplicate
TODO: Attach pdf files in multimedia. TODO: Attach pdf files in multimedia.
*/ */
#define Log_PLATFORM_VERSION "SWAD 22.54 (2022-10-28)" #define Log_PLATFORM_VERSION "SWAD 22.55 (2022-10-28)"
#define CSS_FILE "swad22.49.4.css" #define CSS_FILE "swad22.49.4.css"
#define JS_FILE "swad22.49.js" #define JS_FILE "swad22.49.js"
/* /*
@ -616,6 +616,7 @@ Que al subir un fichero por defecto est
Al subir cosas para los grupos, en documentos, resltar más los grupos porque no son conscientes... Al subir cosas para los grupos, en documentos, resltar más los grupos porque no son conscientes...
Exportar listas en CSV. Exportar listas en CSV.
Version 22.55: Oct 28, 2022 Code refactoring in degree types. (333694 lines)
Version 22.54: Oct 28, 2022 Code refactoring and bug fixing in institutional links. (333614 lines) Version 22.54: Oct 28, 2022 Code refactoring and bug fixing in institutional links. (333614 lines)
Version 22.53: Oct 28, 2022 Code refactoring in mail domains. (333607 lines) Version 22.53: Oct 28, 2022 Code refactoring in mail domains. (333607 lines)
Version 22.52: Oct 28, 2022 Code refactoring in plugins. (333589 lines) Version 22.52: Oct 28, 2022 Code refactoring in plugins. (333589 lines)

View File

@ -81,9 +81,9 @@ static struct Deg_Degree *Deg_EditingDeg = NULL; // Static variable to keep the
/**************************** Private prototypes *****************************/ /**************************** Private prototypes *****************************/
/*****************************************************************************/ /*****************************************************************************/
static void Deg_ListDegreesForEdition (void); static void Deg_ListDegreesForEdition (const struct DegTyp_DegTypes *DegTypes);
static bool Deg_CheckIfICanEditADegree (struct Deg_Degree *Deg); static bool Deg_CheckIfICanEditADegree (struct Deg_Degree *Deg);
static void Deg_PutFormToCreateDegree (void); static void Deg_PutFormToCreateDegree (const struct DegTyp_DegTypes *DegTypes);
static void Deg_PutHeadDegreesForSeeing (void); static void Deg_PutHeadDegreesForSeeing (void);
static void Deg_PutHeadDegreesForEdition (void); static void Deg_PutHeadDegreesForEdition (void);
@ -304,11 +304,11 @@ void Deg_ShowDegsOfCurrentCtr (void)
/********************* List current degrees for edition **********************/ /********************* List current degrees for edition **********************/
/*****************************************************************************/ /*****************************************************************************/
static void Deg_ListDegreesForEdition (void) static void Deg_ListDegreesForEdition (const struct DegTyp_DegTypes *DegTypes)
{ {
extern const char *Txt_DEGREE_STATUS[Hie_NUM_STATUS_TXT]; extern const char *Txt_DEGREE_STATUS[Hie_NUM_STATUS_TXT];
unsigned NumDeg; unsigned NumDeg;
struct DegreeType *DegTyp; struct DegTyp_DegreeType *DegTyp;
struct Deg_Degree *Deg; struct Deg_Degree *Deg;
unsigned NumDegTyp; unsigned NumDegTyp;
char WWW[Cns_MAX_BYTES_WWW + 1]; char WWW[Cns_MAX_BYTES_WWW + 1];
@ -406,10 +406,10 @@ static void Deg_ListDegreesForEdition (void)
" class=\"HIE_SEL_NARROW INPUT_%s\"", " class=\"HIE_SEL_NARROW INPUT_%s\"",
The_GetSuffix ()); The_GetSuffix ());
for (NumDegTyp = 0; for (NumDegTyp = 0;
NumDegTyp < Gbl.DegTypes.Num; NumDegTyp < DegTypes->Num;
NumDegTyp++) NumDegTyp++)
{ {
DegTyp = &Gbl.DegTypes.Lst[NumDegTyp]; DegTyp = &DegTypes->Lst[NumDegTyp];
HTM_OPTION (HTM_Type_LONG,&DegTyp->DegTypCod, HTM_OPTION (HTM_Type_LONG,&DegTyp->DegTypCod,
// Gbl.Hierarchy.Deg.DegCod > 0 && // Gbl.Hierarchy.Deg.DegCod > 0 &&
DegTyp->DegTypCod == Deg->DegTypCod,false, DegTyp->DegTypCod == Deg->DegTypCod,false,
@ -420,10 +420,10 @@ static void Deg_ListDegreesForEdition (void)
} }
else else
for (NumDegTyp = 0; for (NumDegTyp = 0;
NumDegTyp < Gbl.DegTypes.Num; NumDegTyp < DegTypes->Num;
NumDegTyp++) NumDegTyp++)
if (Gbl.DegTypes.Lst[NumDegTyp].DegTypCod == Deg->DegTypCod) if (DegTypes->Lst[NumDegTyp].DegTypCod == Deg->DegTypCod)
HTM_Txt (Gbl.DegTypes.Lst[NumDegTyp].DegTypName); HTM_Txt (DegTypes->Lst[NumDegTyp].DegTypName);
HTM_TD_End (); HTM_TD_End ();
/* Degree WWW */ /* Degree WWW */
@ -503,11 +503,11 @@ static bool Deg_CheckIfICanEditADegree (struct Deg_Degree *Deg)
/*********************** Put a form to create a new degree *******************/ /*********************** Put a form to create a new degree *******************/
/*****************************************************************************/ /*****************************************************************************/
static void Deg_PutFormToCreateDegree (void) static void Deg_PutFormToCreateDegree (const struct DegTyp_DegTypes *DegTypes)
{ {
extern const char *Txt_New_degree; extern const char *Txt_New_degree;
extern const char *Txt_Create_degree; extern const char *Txt_Create_degree;
struct DegreeType *DegTyp; struct DegTyp_DegreeType *DegTyp;
unsigned NumDegTyp; unsigned NumDegTyp;
/***** Begin form *****/ /***** Begin form *****/
@ -566,10 +566,10 @@ static void Deg_PutFormToCreateDegree (void)
" class=\"HIE_SEL_NARROW INPUT_%s\"", " class=\"HIE_SEL_NARROW INPUT_%s\"",
The_GetSuffix ()); The_GetSuffix ());
for (NumDegTyp = 0; for (NumDegTyp = 0;
NumDegTyp < Gbl.DegTypes.Num; NumDegTyp < DegTypes->Num;
NumDegTyp++) NumDegTyp++)
{ {
DegTyp = &Gbl.DegTypes.Lst[NumDegTyp]; DegTyp = &DegTypes->Lst[NumDegTyp];
HTM_OPTION (HTM_Type_LONG,&DegTyp->DegTypCod, HTM_OPTION (HTM_Type_LONG,&DegTyp->DegTypCod,
DegTyp->DegTypCod == Deg_EditingDeg->DegTypCod,false, DegTyp->DegTypCod == Deg_EditingDeg->DegTypCod,false,
"%s",DegTyp->DegTypName); "%s",DegTyp->DegTypName);
@ -794,7 +794,7 @@ static void Deg_ListOneDegreeForSeeing (struct Deg_Degree *Deg,unsigned NumDeg)
extern const char *Txt_DEGREE_With_courses; extern const char *Txt_DEGREE_With_courses;
extern const char *Txt_DEGREE_Without_courses; extern const char *Txt_DEGREE_Without_courses;
extern const char *Txt_DEGREE_STATUS[Hie_NUM_STATUS_TXT]; extern const char *Txt_DEGREE_STATUS[Hie_NUM_STATUS_TXT];
struct DegreeType DegTyp; struct DegTyp_DegreeType DegTyp;
const char *TxtClassNormal; const char *TxtClassNormal;
const char *TxtClassStrong; const char *TxtClassStrong;
const char *BgColor; const char *BgColor;
@ -891,14 +891,15 @@ static void Deg_EditDegreesInternal (void)
extern const char *Hlp_CENTER_Degrees; extern const char *Hlp_CENTER_Degrees;
extern const char *Txt_Degrees_of_CENTER_X; extern const char *Txt_Degrees_of_CENTER_X;
extern const char *Txt_No_types_of_degree; extern const char *Txt_No_types_of_degree;
struct DegTyp_DegTypes DegTypes;
char *Title; char *Title;
/***** Get list of degree types *****/
DegTyp_GetListDegreeTypes (&DegTypes,HieLvl_SYS,DegTyp_ORDER_BY_DEGREE_TYPE);
/***** Get list of degrees in the current center *****/ /***** Get list of degrees in the current center *****/
Deg_GetListDegsInCurrentCtr (); Deg_GetListDegsInCurrentCtr ();
/***** Get list of degree types *****/
DegTyp_GetListDegreeTypes (HieLvl_SYS,DegTyp_ORDER_BY_DEGREE_TYPE);
/***** Write menu to select country, institution and center *****/ /***** Write menu to select country, institution and center *****/
Hie_WriteMenuHierarchy (); Hie_WriteMenuHierarchy ();
@ -909,14 +910,14 @@ static void Deg_EditDegreesInternal (void)
Hlp_CENTER_Degrees,Box_NOT_CLOSABLE); Hlp_CENTER_Degrees,Box_NOT_CLOSABLE);
free (Title); free (Title);
if (Gbl.DegTypes.Num) if (Deg_DB_GetNumDegreeTypes (HieLvl_SYS))
{ {
/***** Put a form to create a new degree *****/ /***** Put a form to create a new degree *****/
Deg_PutFormToCreateDegree (); Deg_PutFormToCreateDegree (&DegTypes);
/***** Forms to edit current degrees *****/ /***** Forms to edit current degrees *****/
if (Gbl.Hierarchy.Degs.Num) if (Gbl.Hierarchy.Degs.Num)
Deg_ListDegreesForEdition (); Deg_ListDegreesForEdition (&DegTypes);
} }
else // No degree types else // No degree types
{ {
@ -925,17 +926,14 @@ static void Deg_EditDegreesInternal (void)
/***** Form to create the first degree type *****/ /***** Form to create the first degree type *****/
if (DegTyp_CheckIfICanCreateDegreeTypes ()) if (DegTyp_CheckIfICanCreateDegreeTypes ())
DegTyp_EditDegreeTypes (); DegTyp_EditDegreeTypes (&DegTypes);
} }
/***** End box *****/ /***** End box *****/
Box_BoxEnd (); Box_BoxEnd ();
/***** Free list of degree types *****/ /***** Free list of degree types *****/
DegTyp_FreeListDegreeTypes (); DegTyp_FreeListDegreeTypes (&DegTypes);
/***** Free list of degrees in the current center *****/
Deg_FreeListDegs (&Gbl.Hierarchy.Degs);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -73,6 +73,78 @@ void Deg_DB_CreateDegree (struct Deg_Degree *Deg,Hie_Status_t Status)
Deg->WWW); Deg->WWW);
} }
/*****************************************************************************/
/************************* Get number of degree types ************************/
/*****************************************************************************/
unsigned Deg_DB_GetNumDegreeTypes (HieLvl_Level_t Scope)
{
/***** Get number of types of degree from database *****/
switch (Scope)
{
case HieLvl_SYS:
return (unsigned)
DB_QueryCOUNT ("can not get types of degree",
"SELECT COUNT(*)"
" FROM deg_types");
case HieLvl_CTY:
/* Get only degree types with degrees in the current country */
return (unsigned)
DB_QueryCOUNT ("can not get types of degree",
"SELECT COUNT(deg_types.*)"
" FROM ins_instits,"
"ctr_centers,"
"deg_degrees,"
"deg_types"
" WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegTypCod=deg_types.DegTypCod"
" GROUP BY deg_degrees.DegTypCod",
Gbl.Hierarchy.Cty.CtyCod);
case HieLvl_INS:
/* Get only degree types with degrees in the current institution */
return (unsigned)
DB_QueryCOUNT ("can not get types of degree",
"SELECT COUNT(deg_types.*)"
" FROM ctr_centers,"
"deg_degrees,"
"deg_types"
" WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegTypCod=deg_types.DegTypCod"
" GROUP BY deg_degrees.DegTypCod",
Gbl.Hierarchy.Ins.InsCod);
case HieLvl_CTR:
/* Get only degree types with degrees in the current center */
return (unsigned)
DB_QueryCOUNT ("can not get types of degree",
"SELECT COUNT(deg_types.*)"
" FROM deg_degrees,"
"deg_types"
" WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegTypCod=deg_types.DegTypCod"
" GROUP BY deg_degrees.DegTypCod",
Gbl.Hierarchy.Ctr.CtrCod);
case HieLvl_DEG:
case HieLvl_CRS:
/* Get only degree types with degrees in the current degree */
return (unsigned)
DB_QueryCOUNT ("can not get types of degree",
"SELECT COUNT(deg_types.*)"
" FROM deg_degrees,"
"deg_types"
" FROM deg_degrees,"
"deg_types"
" WHERE deg_degrees.DegCod=%ld"
" AND deg_degrees.DegTypCod=deg_types.DegTypCod",
Gbl.Hierarchy.Deg.DegCod);
default:
Err_WrongScopeExit ();
return 0; // Not reached
}
}
/*****************************************************************************/ /*****************************************************************************/
/****************** Create a list with all degree types **********************/ /****************** Create a list with all degree types **********************/
/*****************************************************************************/ /*****************************************************************************/
@ -194,7 +266,7 @@ unsigned Deg_DB_GetDegreeTypes (MYSQL_RES **mysql_res,
/************** Get the name of a type of degree from database ***************/ /************** Get the name of a type of degree from database ***************/
/*****************************************************************************/ /*****************************************************************************/
void Deg_DB_GetDegTypeNameByCod (struct DegreeType *DegTyp) void Deg_DB_GetDegTypeNameByCod (struct DegTyp_DegreeType *DegTyp)
{ {
DB_QuerySELECTString (DegTyp->DegTypName,sizeof (DegTyp->DegTypName) - 1, DB_QuerySELECTString (DegTyp->DegTypName,sizeof (DegTyp->DegTypName) - 1,
"can not get the name of a type of degree", "can not get the name of a type of degree",

View File

@ -40,9 +40,10 @@
void Deg_DB_CreateDegreeType (const char DegTypName[DegTyp_MAX_BYTES_DEGREE_TYPE_NAME + 1]); void Deg_DB_CreateDegreeType (const char DegTypName[DegTyp_MAX_BYTES_DEGREE_TYPE_NAME + 1]);
void Deg_DB_CreateDegree (struct Deg_Degree *Deg,Hie_Status_t Status); void Deg_DB_CreateDegree (struct Deg_Degree *Deg,Hie_Status_t Status);
unsigned Deg_DB_GetNumDegreeTypes (HieLvl_Level_t Scope);
unsigned Deg_DB_GetDegreeTypes (MYSQL_RES **mysql_res, unsigned Deg_DB_GetDegreeTypes (MYSQL_RES **mysql_res,
HieLvl_Level_t Scope,DegTyp_Order_t Order); HieLvl_Level_t Scope,DegTyp_Order_t Order);
void Deg_DB_GetDegTypeNameByCod (struct DegreeType *DegTyp); void Deg_DB_GetDegTypeNameByCod (struct DegTyp_DegreeType *DegTyp);
unsigned Deg_DB_GetDataOfDegreeByCod (MYSQL_RES **mysql_res,long DegCod); unsigned Deg_DB_GetDataOfDegreeByCod (MYSQL_RES **mysql_res,long DegCod);
long Deg_DB_GetInsCodOfDegreeByCod (long DegCod); long Deg_DB_GetInsCodOfDegreeByCod (long DegCod);
long Deg_DB_GetCtrCodOfDegreeByCod (long DegCod); long Deg_DB_GetCtrCodOfDegreeByCod (long DegCod);

View File

@ -57,7 +57,7 @@ extern struct Globals Gbl;
/**************************** Private variables ******************************/ /**************************** Private variables ******************************/
/*****************************************************************************/ /*****************************************************************************/
static struct DegreeType *DegTyp_EditingDegTyp = NULL; // Static variable to keep the degree type being edited static struct DegTyp_DegreeType *DegTyp_EditingDegTyp = NULL; // Static variable to keep the degree type being edited
/*****************************************************************************/ /*****************************************************************************/
/*************************** Private prototypes ******************************/ /*************************** Private prototypes ******************************/
@ -67,17 +67,18 @@ static void DegTyp_SeeDegreeTypes (Act_Action_t NextAction,HieLvl_Level_t Scope,
DegTyp_Order_t DefaultOrder); DegTyp_Order_t DefaultOrder);
static DegTyp_Order_t DegTyp_GetParamDegTypOrder (DegTyp_Order_t DefaultOrder); static DegTyp_Order_t DegTyp_GetParamDegTypOrder (DegTyp_Order_t DefaultOrder);
static void DegTyp_ListDegreeTypes (Act_Action_t NextAction, static void DegTyp_ListDegreeTypes (const struct DegTyp_DegTypes *DegTypes,
Act_Action_t NextAction,
HieLvl_Level_t Scope, HieLvl_Level_t Scope,
DegTyp_Order_t SelectedOrder); DegTyp_Order_t SelectedOrder);
static void DegTyp_EditDegreeTypesInternal (void); static void DegTyp_EditDegreeTypesInternal (const struct DegTyp_DegTypes *DegTypes);
static void DegTyp_PutIconsEditingDegreeTypes (__attribute__((unused)) void *Args); static void DegTyp_PutIconsEditingDegreeTypes (__attribute__((unused)) void *Args);
static void DegTyp_ListDegreeTypesForSeeing (void); static void DegTyp_ListDegreeTypesForSeeing (const struct DegTyp_DegTypes *DegTypes);
static void DegTyp_PutIconsListingDegTypes (__attribute__((unused)) void *Args); static void DegTyp_PutIconsListingDegTypes (__attribute__((unused)) void *Args);
static void DegTyp_PutIconToEditDegTypes (__attribute__((unused)) void *Args); static void DegTyp_PutIconToEditDegTypes (__attribute__((unused)) void *Args);
static void DegTyp_ListDegreeTypesForEdition (void); static void DegTyp_ListDegreeTypesForEdition (const struct DegTyp_DegTypes *DegTypes);
static void DegTyp_PutFormToCreateDegreeType (void); static void DegTyp_PutFormToCreateDegreeType (void);
@ -100,11 +101,12 @@ static void DegTyp_EditingDegreeTypeDestructor (void);
void DegTyp_WriteSelectorDegreeTypes (long SelectedDegTypCod) void DegTyp_WriteSelectorDegreeTypes (long SelectedDegTypCod)
{ {
extern const char *Txt_Any_type_of_degree; extern const char *Txt_Any_type_of_degree;
struct DegTyp_DegTypes DegTypes;
unsigned NumDegTyp; unsigned NumDegTyp;
/***** Form to select degree types *****/ /***** Form to select degree types *****/
/* Get list of degree types */ /* Get list of degree types */
DegTyp_GetListDegreeTypes (HieLvl_SYS,DegTyp_ORDER_BY_DEGREE_TYPE); DegTyp_GetListDegreeTypes (&DegTypes,HieLvl_SYS,DegTyp_ORDER_BY_DEGREE_TYPE);
/* List degree types */ /* List degree types */
HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE,
@ -115,15 +117,15 @@ void DegTyp_WriteSelectorDegreeTypes (long SelectedDegTypCod)
SelectedDegTypCod == -1L,false, SelectedDegTypCod == -1L,false,
"%s",Txt_Any_type_of_degree); "%s",Txt_Any_type_of_degree);
for (NumDegTyp = 0; for (NumDegTyp = 0;
NumDegTyp < Gbl.DegTypes.Num; NumDegTyp < DegTypes.Num;
NumDegTyp++) NumDegTyp++)
HTM_OPTION (HTM_Type_LONG,&Gbl.DegTypes.Lst[NumDegTyp].DegTypCod, HTM_OPTION (HTM_Type_LONG,&DegTypes.Lst[NumDegTyp].DegTypCod,
Gbl.DegTypes.Lst[NumDegTyp].DegTypCod == SelectedDegTypCod,false, DegTypes.Lst[NumDegTyp].DegTypCod == SelectedDegTypCod,false,
"%s",Gbl.DegTypes.Lst[NumDegTyp].DegTypName); "%s",DegTypes.Lst[NumDegTyp].DegTypName);
HTM_SELECT_End (); HTM_SELECT_End ();
/***** Free list of degree types *****/ /***** Free list of degree types *****/
DegTyp_FreeListDegreeTypes (); DegTyp_FreeListDegreeTypes (&DegTypes);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -146,18 +148,19 @@ static void DegTyp_SeeDegreeTypes (Act_Action_t NextAction,HieLvl_Level_t Scope,
DegTyp_Order_t DefaultOrder) DegTyp_Order_t DefaultOrder)
{ {
DegTyp_Order_t SelectedOrder; DegTyp_Order_t SelectedOrder;
struct DegTyp_DegTypes DegTypes;
/***** Get parameter with the type of order in the list of degree types *****/ /***** Get parameter with the type of order in the list of degree types *****/
SelectedOrder = DegTyp_GetParamDegTypOrder (DefaultOrder); SelectedOrder = DegTyp_GetParamDegTypOrder (DefaultOrder);
/***** Get list of degree types *****/ /***** Get list of degree types *****/
DegTyp_GetListDegreeTypes (Scope,SelectedOrder); DegTyp_GetListDegreeTypes (&DegTypes,Scope,SelectedOrder);
/***** List degree types *****/ /***** List degree types *****/
DegTyp_ListDegreeTypes (NextAction,Scope,SelectedOrder); DegTyp_ListDegreeTypes (&DegTypes,NextAction,Scope,SelectedOrder);
/***** Free list of degree types *****/ /***** Free list of degree types *****/
DegTyp_FreeListDegreeTypes (); DegTyp_FreeListDegreeTypes (&DegTypes);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -179,7 +182,8 @@ static DegTyp_Order_t DegTyp_GetParamDegTypOrder (DegTyp_Order_t DefaultOrder)
// - center tab => NextAction = ActSeeDegTyp // - center tab => NextAction = ActSeeDegTyp
// - statistic tab => NextAction = ActSeeUseGbl // - statistic tab => NextAction = ActSeeUseGbl
static void DegTyp_ListDegreeTypes (Act_Action_t NextAction, static void DegTyp_ListDegreeTypes (const struct DegTyp_DegTypes *DegTypes,
Act_Action_t NextAction,
HieLvl_Level_t Scope, HieLvl_Level_t Scope,
DegTyp_Order_t SelectedOrder) DegTyp_Order_t SelectedOrder)
{ {
@ -207,7 +211,7 @@ static void DegTyp_ListDegreeTypes (Act_Action_t NextAction,
return; return;
} }
if (Gbl.DegTypes.Num) if (DegTypes->Num)
{ {
/***** Begin table *****/ /***** Begin table *****/
HTM_TABLE_BeginWideMarginPadding (2); HTM_TABLE_BeginWideMarginPadding (2);
@ -216,7 +220,7 @@ static void DegTyp_ListDegreeTypes (Act_Action_t NextAction,
DegTyp_PutHeadDegreeTypesForSeeing (NextAction,Scope,SelectedOrder); DegTyp_PutHeadDegreeTypesForSeeing (NextAction,Scope,SelectedOrder);
/***** List current degree types for seeing *****/ /***** List current degree types for seeing *****/
DegTyp_ListDegreeTypesForSeeing (); DegTyp_ListDegreeTypesForSeeing (DegTypes);
/***** End table *****/ /***** End table *****/
HTM_TABLE_End (); HTM_TABLE_End ();
@ -228,8 +232,8 @@ static void DegTyp_ListDegreeTypes (Act_Action_t NextAction,
if (DegTyp_CheckIfICanCreateDegreeTypes ()) if (DegTyp_CheckIfICanCreateDegreeTypes ())
{ {
Frm_BeginForm (ActEdiDegTyp); Frm_BeginForm (ActEdiDegTyp);
Btn_PutConfirmButton (Gbl.DegTypes.Num ? Txt_Create_another_type_of_degree : Btn_PutConfirmButton (DegTypes->Num ? Txt_Create_another_type_of_degree :
Txt_Create_type_of_degree); Txt_Create_type_of_degree);
Frm_EndForm (); Frm_EndForm ();
} }
@ -241,26 +245,27 @@ static void DegTyp_ListDegreeTypes (Act_Action_t NextAction,
/************************ Put forms to edit degree types *********************/ /************************ Put forms to edit degree types *********************/
/*****************************************************************************/ /*****************************************************************************/
void DegTyp_EditDegreeTypes (void) void DegTyp_GetAndEditDegreeTypes (void)
{
struct DegTyp_DegTypes DegTypes;
DegTyp_GetListDegreeTypes (&DegTypes,HieLvl_SYS,DegTyp_ORDER_BY_DEGREE_TYPE);
DegTyp_EditDegreeTypes (&DegTypes);
DegTyp_FreeListDegreeTypes (&DegTypes);
}
void DegTyp_EditDegreeTypes (const struct DegTyp_DegTypes *DegTypes)
{ {
/***** Degree type constructor *****/
DegTyp_EditingDegreeTypeConstructor (); DegTyp_EditingDegreeTypeConstructor ();
DegTyp_EditDegreeTypesInternal (DegTypes);
/***** Edit degree types *****/
DegTyp_EditDegreeTypesInternal ();
/***** Degree type destructor *****/
DegTyp_EditingDegreeTypeDestructor (); DegTyp_EditingDegreeTypeDestructor ();
} }
static void DegTyp_EditDegreeTypesInternal (void) static void DegTyp_EditDegreeTypesInternal (const struct DegTyp_DegTypes *DegTypes)
{ {
extern const char *Hlp_CENTER_DegreeTypes_edit; extern const char *Hlp_CENTER_DegreeTypes_edit;
extern const char *Txt_Types_of_degree; extern const char *Txt_Types_of_degree;
/***** Get list of degree types *****/
DegTyp_GetListDegreeTypes (HieLvl_SYS,DegTyp_ORDER_BY_DEGREE_TYPE);
/***** Begin box *****/ /***** Begin box *****/
Box_BoxBegin (NULL,Txt_Types_of_degree, Box_BoxBegin (NULL,Txt_Types_of_degree,
DegTyp_PutIconsEditingDegreeTypes,NULL, DegTyp_PutIconsEditingDegreeTypes,NULL,
@ -270,14 +275,11 @@ static void DegTyp_EditDegreeTypesInternal (void)
DegTyp_PutFormToCreateDegreeType (); DegTyp_PutFormToCreateDegreeType ();
/***** Forms to edit current degree types *****/ /***** Forms to edit current degree types *****/
if (Gbl.DegTypes.Num) if (DegTypes->Num)
DegTyp_ListDegreeTypesForEdition (); DegTyp_ListDegreeTypesForEdition (DegTypes);
/***** End box *****/ /***** End box *****/
Box_BoxEnd (); Box_BoxEnd ();
/***** Free list of degree types *****/
DegTyp_FreeListDegreeTypes ();
} }
/*****************************************************************************/ /*****************************************************************************/
@ -311,17 +313,17 @@ void DegTyp_PutIconToViewDegreeTypes (void)
/******************* List current degree types for seeing ********************/ /******************* List current degree types for seeing ********************/
/*****************************************************************************/ /*****************************************************************************/
static void DegTyp_ListDegreeTypesForSeeing (void) static void DegTyp_ListDegreeTypesForSeeing (const struct DegTyp_DegTypes *DegTypes)
{ {
unsigned NumDegTyp; unsigned NumDegTyp;
const char *BgColor; const char *BgColor;
/***** List degree types with forms for edition *****/ /***** List degree types with forms for edition *****/
for (NumDegTyp = 0, The_ResetRowColor (); for (NumDegTyp = 0, The_ResetRowColor ();
NumDegTyp < Gbl.DegTypes.Num; NumDegTyp < DegTypes->Num;
NumDegTyp++, The_ChangeRowColor ()) NumDegTyp++, The_ChangeRowColor ())
{ {
BgColor = (Gbl.DegTypes.Lst[NumDegTyp].DegTypCod == BgColor = (DegTypes->Lst[NumDegTyp].DegTypCod ==
Gbl.Hierarchy.Deg.DegTypCod) ? "BG_HIGHLIGHT" : Gbl.Hierarchy.Deg.DegTypCod) ? "BG_HIGHLIGHT" :
The_GetColorRows (); The_GetColorRows ();
@ -337,13 +339,13 @@ static void DegTyp_ListDegreeTypesForSeeing (void)
/* Name of degree type */ /* Name of degree type */
HTM_TD_Begin ("class=\"LM DAT_STRONG_%s %s\"", HTM_TD_Begin ("class=\"LM DAT_STRONG_%s %s\"",
The_GetSuffix (),BgColor); The_GetSuffix (),BgColor);
HTM_Txt (Gbl.DegTypes.Lst[NumDegTyp].DegTypName); HTM_Txt (DegTypes->Lst[NumDegTyp].DegTypName);
HTM_TD_End (); HTM_TD_End ();
/* Number of degrees of this type */ /* Number of degrees of this type */
HTM_TD_Begin ("class=\"RM DAT_STRONG_%s %s\"", HTM_TD_Begin ("class=\"RM DAT_STRONG_%s %s\"",
The_GetSuffix (),BgColor); The_GetSuffix (),BgColor);
HTM_Unsigned (Gbl.DegTypes.Lst[NumDegTyp].NumDegs); HTM_Unsigned (DegTypes->Lst[NumDegTyp].NumDegs);
HTM_TD_End (); HTM_TD_End ();
/* End table row */ /* End table row */
@ -383,7 +385,7 @@ static void DegTyp_PutIconToEditDegTypes (__attribute__((unused)) void *Args)
/******************* List current degree types for edition *******************/ /******************* List current degree types for edition *******************/
/*****************************************************************************/ /*****************************************************************************/
static void DegTyp_ListDegreeTypesForEdition (void) static void DegTyp_ListDegreeTypesForEdition (const struct DegTyp_DegTypes *DegTypes)
{ {
unsigned NumDegTyp; unsigned NumDegTyp;
@ -395,7 +397,7 @@ static void DegTyp_ListDegreeTypesForEdition (void)
/***** List degree types with forms for edition *****/ /***** List degree types with forms for edition *****/
for (NumDegTyp = 0; for (NumDegTyp = 0;
NumDegTyp < Gbl.DegTypes.Num; NumDegTyp < DegTypes->Num;
NumDegTyp++) NumDegTyp++)
{ {
/* Begin table row */ /* Begin table row */
@ -403,24 +405,25 @@ static void DegTyp_ListDegreeTypesForEdition (void)
/* Put icon to remove degree type */ /* Put icon to remove degree type */
HTM_TD_Begin ("class=\"BM\""); HTM_TD_Begin ("class=\"BM\"");
if (Gbl.DegTypes.Lst[NumDegTyp].NumDegs) // Degree type has degrees => deletion forbidden if (DegTypes->Lst[NumDegTyp].NumDegs) // Degree type has degrees => deletion forbidden
Ico_PutIconRemovalNotAllowed (); Ico_PutIconRemovalNotAllowed ();
else else
Ico_PutContextualIconToRemove (ActRemDegTyp,NULL, Ico_PutContextualIconToRemove (ActRemDegTyp,NULL,
DegTyp_PutParamOtherDegTypCod,&Gbl.DegTypes.Lst[NumDegTyp].DegTypCod); DegTyp_PutParamOtherDegTypCod,
&DegTypes->Lst[NumDegTyp].DegTypCod);
HTM_TD_End (); HTM_TD_End ();
/* Degree type code */ /* Degree type code */
HTM_TD_Begin ("class=\"DAT_%s CODE\"",The_GetSuffix ()); HTM_TD_Begin ("class=\"DAT_%s CODE\"",The_GetSuffix ());
HTM_Long (Gbl.DegTypes.Lst[NumDegTyp].DegTypCod); HTM_Long (DegTypes->Lst[NumDegTyp].DegTypCod);
HTM_TD_End (); HTM_TD_End ();
/* Name of degree type */ /* Name of degree type */
HTM_TD_Begin ("class=\"LM\""); HTM_TD_Begin ("class=\"LM\"");
Frm_BeginForm (ActRenDegTyp); Frm_BeginForm (ActRenDegTyp);
DegTyp_PutParamOtherDegTypCod (&Gbl.DegTypes.Lst[NumDegTyp].DegTypCod); DegTyp_PutParamOtherDegTypCod (&DegTypes->Lst[NumDegTyp].DegTypCod);
HTM_INPUT_TEXT ("DegTypName",DegTyp_MAX_CHARS_DEGREE_TYPE_NAME, HTM_INPUT_TEXT ("DegTypName",DegTyp_MAX_CHARS_DEGREE_TYPE_NAME,
Gbl.DegTypes.Lst[NumDegTyp].DegTypName, DegTypes->Lst[NumDegTyp].DegTypName,
HTM_SUBMIT_ON_CHANGE, HTM_SUBMIT_ON_CHANGE,
"size=\"25\" class=\"INPUT_%s\"" "size=\"25\" class=\"INPUT_%s\""
" required=\"required\"", " required=\"required\"",
@ -430,7 +433,7 @@ static void DegTyp_ListDegreeTypesForEdition (void)
/* Number of degrees of this type */ /* Number of degrees of this type */
HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ()); HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ());
HTM_Unsigned (Gbl.DegTypes.Lst[NumDegTyp].NumDegs); HTM_Unsigned (DegTypes->Lst[NumDegTyp].NumDegs);
HTM_TD_End (); HTM_TD_End ();
/* End table row */ /* End table row */
@ -586,41 +589,43 @@ static void DegTyp_PutHeadDegreeTypesForEdition (void)
/****************** Create a list with all degree types **********************/ /****************** Create a list with all degree types **********************/
/*****************************************************************************/ /*****************************************************************************/
void DegTyp_GetListDegreeTypes (HieLvl_Level_t Scope,DegTyp_Order_t Order) void DegTyp_GetListDegreeTypes (struct DegTyp_DegTypes *DegTypes,
HieLvl_Level_t Scope,DegTyp_Order_t Order)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumTyp; unsigned NumTyp;
/***** Get types of degree from database *****/ /***** Get types of degree from database *****/
Gbl.DegTypes.Num = Deg_DB_GetDegreeTypes (&mysql_res,Scope,Order); DegTypes->Num = Deg_DB_GetDegreeTypes (&mysql_res,Scope,Order);
DegTypes->Lst = NULL;
/***** Get degree types *****/ /***** Get degree types *****/
if (Gbl.DegTypes.Num) if (DegTypes->Num)
{ {
/***** Create a list of degree types *****/ /***** Create a list of degree types *****/
if ((Gbl.DegTypes.Lst = calloc (Gbl.DegTypes.Num, if ((DegTypes->Lst = calloc ((size_t) DegTypes->Num,
sizeof (*Gbl.DegTypes.Lst))) == NULL) sizeof (struct DegTyp_DegreeType))) == NULL)
Err_NotEnoughMemoryExit (); Err_NotEnoughMemoryExit ();
/***** Get degree types *****/ /***** Get degree types *****/
for (NumTyp = 0; for (NumTyp = 0;
NumTyp < Gbl.DegTypes.Num; NumTyp < DegTypes->Num;
NumTyp++) NumTyp++)
{ {
/* Get next degree type */ /* Get next degree type */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
/* Get degree type code (row[0]) */ /* Get degree type code (row[0]) */
if ((Gbl.DegTypes.Lst[NumTyp].DegTypCod = Str_ConvertStrCodToLongCod (row[0])) <= 0) if ((DegTypes->Lst[NumTyp].DegTypCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongDegTypExit (); Err_WrongDegTypExit ();
/* Get degree type name (row[1]) */ /* Get degree type name (row[1]) */
Str_Copy (Gbl.DegTypes.Lst[NumTyp].DegTypName,row[1], Str_Copy (DegTypes->Lst[NumTyp].DegTypName,row[1],
sizeof (Gbl.DegTypes.Lst[NumTyp].DegTypName) - 1); sizeof (DegTypes->Lst[NumTyp].DegTypName) - 1);
/* Number of degrees of this type (row[2]) */ /* Number of degrees of this type (row[2]) */
if (sscanf (row[2],"%u",&Gbl.DegTypes.Lst[NumTyp].NumDegs) != 1) if (sscanf (row[2],"%u",&DegTypes->Lst[NumTyp].NumDegs) != 1)
Err_ShowErrorAndExit ("Error when getting number of degrees of a type"); Err_ShowErrorAndExit ("Error when getting number of degrees of a type");
} }
} }
@ -633,14 +638,14 @@ void DegTyp_GetListDegreeTypes (HieLvl_Level_t Scope,DegTyp_Order_t Order)
/********* Free list of degree types and list of degrees of each type ********/ /********* Free list of degree types and list of degrees of each type ********/
/*****************************************************************************/ /*****************************************************************************/
void DegTyp_FreeListDegreeTypes (void) void DegTyp_FreeListDegreeTypes (struct DegTyp_DegTypes *DegTypes)
{ {
/***** Free memory used by the list of degree types *****/ /***** Free memory used by the list of degree types *****/
if (Gbl.DegTypes.Lst) if (DegTypes->Num && DegTypes->Lst)
{ {
free (Gbl.DegTypes.Lst); free (DegTypes->Lst);
Gbl.DegTypes.Lst = NULL; DegTypes->Lst = NULL;
Gbl.DegTypes.Num = 0; DegTypes->Num = 0;
} }
} }
@ -745,7 +750,7 @@ long DegTyp_GetAndCheckParamOtherDegTypCod (long MinCodAllowed)
/****************** Get data of a degree type from its code ******************/ /****************** Get data of a degree type from its code ******************/
/*****************************************************************************/ /*****************************************************************************/
bool DegTyp_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp) bool DegTyp_GetDataOfDegreeTypeByCod (struct DegTyp_DegreeType *DegTyp)
{ {
/***** Trivial check: code of degree type should be >= 0 *****/ /***** Trivial check: code of degree type should be >= 0 *****/
if (DegTyp->DegTypCod <= 0) if (DegTyp->DegTypCod <= 0)
@ -871,11 +876,15 @@ void DegTyp_RenameDegreeType (void)
void DegTyp_ContEditAfterChgDegTyp (void) void DegTyp_ContEditAfterChgDegTyp (void)
{ {
struct DegTyp_DegTypes DegTypes;
/***** Show possible delayed alerts *****/ /***** Show possible delayed alerts *****/
Ale_ShowAlerts (NULL); Ale_ShowAlerts (NULL);
/***** Show the form again *****/ /***** Show the form again *****/
DegTyp_EditDegreeTypesInternal (); DegTyp_GetListDegreeTypes (&DegTypes,HieLvl_SYS,DegTyp_ORDER_BY_DEGREE_TYPE);
DegTyp_EditDegreeTypesInternal (&DegTypes);
DegTyp_FreeListDegreeTypes (&DegTypes);
/***** Degree type destructor *****/ /***** Degree type destructor *****/
DegTyp_EditingDegreeTypeDestructor (); DegTyp_EditingDegreeTypeDestructor ();

View File

@ -40,13 +40,19 @@
/******************************* Public types ********************************/ /******************************* Public types ********************************/
/*****************************************************************************/ /*****************************************************************************/
struct DegreeType struct DegTyp_DegreeType
{ {
long DegTypCod; // Degree type code long DegTypCod; // Degree type code
char DegTypName[DegTyp_MAX_BYTES_DEGREE_TYPE_NAME + 1]; // Degree type name char DegTypName[DegTyp_MAX_BYTES_DEGREE_TYPE_NAME + 1]; // Degree type name
unsigned NumDegs; // Number of degrees of this type unsigned NumDegs; // Number of degrees of this type
}; };
struct DegTyp_DegTypes
{
unsigned Num; // Number of degree types
struct DegTyp_DegreeType *Lst; // List of degree types
};
#define DegTyp_NUM_ORDERS 2 #define DegTyp_NUM_ORDERS 2
typedef enum typedef enum
{ {
@ -62,14 +68,16 @@ void DegTyp_WriteSelectorDegreeTypes (long SelectedDegTypCod);
void DegTyp_SeeDegreeTypesInDegTab (void); void DegTyp_SeeDegreeTypesInDegTab (void);
void DegTyp_SeeDegreeTypesInStaTab (void); void DegTyp_SeeDegreeTypesInStaTab (void);
void DegTyp_EditDegreeTypes (void); void DegTyp_GetAndEditDegreeTypes (void);
void DegTyp_EditDegreeTypes (const struct DegTyp_DegTypes *DegTypes);
void DegTyp_PutIconToViewDegreeTypes (void); void DegTyp_PutIconToViewDegreeTypes (void);
bool DegTyp_CheckIfICanCreateDegreeTypes (void); bool DegTyp_CheckIfICanCreateDegreeTypes (void);
void DegTyp_GetListDegreeTypes (HieLvl_Level_t Scope,DegTyp_Order_t Order); void DegTyp_GetListDegreeTypes (struct DegTyp_DegTypes *DegTypes,
void DegTyp_FreeListDegreeTypes (void); HieLvl_Level_t Scope,DegTyp_Order_t Order);
void DegTyp_FreeListDegreeTypes (struct DegTyp_DegTypes *DegTypes);
void DegTyp_ReceiveFormNewDegreeType (void); void DegTyp_ReceiveFormNewDegreeType (void);
@ -77,7 +85,7 @@ void DegTyp_RemoveDegreeType (void);
long DegTyp_GetAndCheckParamOtherDegTypCod (long MinCodAllowed); long DegTyp_GetAndCheckParamOtherDegTypCod (long MinCodAllowed);
bool DegTyp_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp); bool DegTyp_GetDataOfDegreeTypeByCod (struct DegTyp_DegreeType *DegTyp);
void DegTyp_RenameDegreeType (void); void DegTyp_RenameDegreeType (void);
void DegTyp_ContEditAfterChgDegTyp (void); void DegTyp_ContEditAfterChgDegTyp (void);

View File

@ -191,9 +191,6 @@ void Gbl_InitializeGlobals (void)
Gbl.Hierarchy.Crs.ShrtName[0] = Gbl.Hierarchy.Crs.ShrtName[0] =
Gbl.Hierarchy.Crs.FullName[0] = '\0'; Gbl.Hierarchy.Crs.FullName[0] = '\0';
Gbl.DegTypes.Num = 0;
Gbl.DegTypes.Lst = NULL;
Gbl.Crs.Info.ShowMsgMustBeRead = 0; Gbl.Crs.Info.ShowMsgMustBeRead = 0;
Gbl.Crs.Notices.HighlightNotCod = -1L; // No notice highlighted Gbl.Crs.Notices.HighlightNotCod = -1L; // No notice highlighted
@ -314,7 +311,6 @@ void Gbl_Cleanup (void)
Grp_FreeListCodSelectedGrps (); Grp_FreeListCodSelectedGrps ();
Crs_FreeListCoursesInCurrentDegree (); Crs_FreeListCoursesInCurrentDegree ();
Deg_FreeListDegs (&Gbl.Hierarchy.Degs); Deg_FreeListDegs (&Gbl.Hierarchy.Degs);
DegTyp_FreeListDegreeTypes ();
Ins_FreeListInstitutions (); Ins_FreeListInstitutions ();
Ctr_FreeListCenters (); Ctr_FreeListCenters ();
Cty_FreeListCountries (); Cty_FreeListCountries ();

View File

@ -100,11 +100,6 @@ struct Globals
struct Crs_ListCourses Crss; // List of courses in current degree struct Crs_ListCourses Crss; // List of courses in current degree
struct Crs_Course Crs; // Current course. Aditional info about course is stored in Gbl.Crs. struct Crs_Course Crs; // Current course. Aditional info about course is stored in Gbl.Crs.
} Hierarchy; } Hierarchy;
struct
{
unsigned Num; // Number of degree types
struct DegreeType *Lst; // List of degree types
} DegTypes;
struct struct
{ {
Sch_WhatToSearch_t WhatToSearch; Sch_WhatToSearch_t WhatToSearch;