Version 23.21: Oct 03, 2023 User's hierarchy is allocated dinamically.

This commit is contained in:
acanas 2023-10-03 00:25:57 +02:00
parent c5ac52920c
commit f30a240011
17 changed files with 157 additions and 145 deletions

View File

@ -1776,29 +1776,33 @@ void Ctr_GetMyCenters (void)
if (!Gbl.Usrs.Me.MyCtrs.Filled)
{
Gbl.Usrs.Me.MyCtrs.Num = 0;
Gbl.Usrs.Me.MyCtrs.Ctrs = NULL;
/***** Get my centers from database *****/
NumCtrs = Ctr_DB_GetCtrsFromUsr (&mysql_res,
Gbl.Usrs.Me.UsrDat.UsrCod,-1L);
for (NumCtr = 0;
NumCtr < NumCtrs;
NumCtr++)
{
/* Get next center */
row = mysql_fetch_row (mysql_res);
/* Get center code */
if ((CtrCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
if (NumCtrs)
{
if ((Gbl.Usrs.Me.MyCtrs.Ctrs = malloc (NumCtrs *
sizeof (*Gbl.Usrs.Me.MyCtrs.Ctrs))) == NULL)
Err_NotEnoughMemoryExit ();
for (NumCtr = 0;
NumCtr < NumCtrs;
NumCtr++)
{
if (Gbl.Usrs.Me.MyCtrs.Num == Ctr_MAX_CENTERS_PER_USR)
Err_ShowErrorAndExit ("Maximum number of centers of a user exceeded.");
/* Get next center */
row = mysql_fetch_row (mysql_res);
Gbl.Usrs.Me.MyCtrs.Ctrs[Gbl.Usrs.Me.MyCtrs.Num].CtrCod = CtrCod;
Gbl.Usrs.Me.MyCtrs.Ctrs[Gbl.Usrs.Me.MyCtrs.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]);
/* Get center code */
if ((CtrCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
{
Gbl.Usrs.Me.MyCtrs.Ctrs[Gbl.Usrs.Me.MyCtrs.Num].HieCod = CtrCod;
Gbl.Usrs.Me.MyCtrs.Ctrs[Gbl.Usrs.Me.MyCtrs.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]);
Gbl.Usrs.Me.MyCtrs.Num++;
Gbl.Usrs.Me.MyCtrs.Num++;
}
}
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
@ -1818,6 +1822,10 @@ void Ctr_FreeMyCenters (void)
{
/***** Reset list *****/
Gbl.Usrs.Me.MyCtrs.Filled = false;
if (Gbl.Usrs.Me.MyCtrs.Num &&
Gbl.Usrs.Me.MyCtrs.Ctrs)
free (Gbl.Usrs.Me.MyCtrs.Ctrs);
Gbl.Usrs.Me.MyCtrs.Ctrs = NULL;
Gbl.Usrs.Me.MyCtrs.Num = 0;
}
}
@ -1837,7 +1845,7 @@ bool Ctr_CheckIfIBelongToCtr (long CtrCod)
for (NumMyCtr = 0;
NumMyCtr < Gbl.Usrs.Me.MyCtrs.Num;
NumMyCtr++)
if (Gbl.Usrs.Me.MyCtrs.Ctrs[NumMyCtr].CtrCod == CtrCod)
if (Gbl.Usrs.Me.MyCtrs.Ctrs[NumMyCtr].HieCod == CtrCod)
return true;
return false;
}

View File

@ -36,12 +36,6 @@
#include "swad_map.h"
#include "swad_role_type.h"
/*****************************************************************************/
/************************** Public types and constants ***********************/
/*****************************************************************************/
#define Ctr_MAX_CENTERS_PER_USR 10 // Used in list of my centers
/*****************************************************************************/
/****************************** Public prototypes ****************************/
/*****************************************************************************/

View File

@ -632,10 +632,11 @@ TODO: Francisco Javier Fern
Me sale este error, no si por no recordar yo la sintaxis apropiada para mandar a varios destinatarios. ¿No era así?
"can npt create received message (duplicated entry '243218-2160773' for key 'UsrCod_MsgCod')
*/
#define Log_PLATFORM_VERSION "SWAD 23.20.1 (2023-10-02)"
#define Log_PLATFORM_VERSION "SWAD 23.21 (2023-10-03)"
#define CSS_FILE "swad23.16.1.css"
#define JS_FILE "swad22.49.js"
/*
Version 23.21: Oct 03, 2023 User's hierarchy is allocated dinamically. (336598 lines)
Version 23.20.1: Oct 02, 2023 Fixed minor CSS issue in games and exams. (336576 lines)
Version 23.20: Sep 29, 2023 Removed button to change between view and edit mode in in file browser. (336571 lines)
Version 23.19.1: Sep 29, 2023 Code refactoring in file browser. (336609 lines)

View File

@ -175,7 +175,7 @@ void Cht_ShowListOfAvailableChatRooms (void)
NumMyDeg++)
{
/* Get data of this degree */
Deg.HieCod = Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod;
Deg.HieCod = Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].HieCod;
if (!Deg_GetDegreeDataByCod (&Deg))
Err_WrongDegreeExit ();
@ -362,9 +362,10 @@ void Cht_WriteParsRoomCodeAndNames (const char *RoomCode,const char *RoomShrtNam
/******************************* Enter a chat room ***************************/
/*****************************************************************************/
#define Cht_MAX_BYTES_ROOM_CODES ((2 + Deg_MAX_DEGREES_PER_USR + Crs_MAX_COURSES_PER_USR) * Cht_MAX_BYTES_ROOM_CODE)
#define Cht_MAX_BYTES_ROOM_SHRT_NAMES ((2 + Deg_MAX_DEGREES_PER_USR + Crs_MAX_COURSES_PER_USR) * Cht_MAX_BYTES_ROOM_SHRT_NAME)
#define Cht_MAX_BYTES_ROOM_FULL_NAMES ((2 + Deg_MAX_DEGREES_PER_USR + Crs_MAX_COURSES_PER_USR) * Cht_MAX_BYTES_ROOM_FULL_NAME)
// TODO: Max. bytes should be allocated dinamycally depending on number of degrees and courses
#define Cht_MAX_BYTES_ROOM_CODES (100 * Cht_MAX_BYTES_ROOM_CODE)
#define Cht_MAX_BYTES_ROOM_SHRT_NAMES (100 * Cht_MAX_BYTES_ROOM_SHRT_NAME)
#define Cht_MAX_BYTES_ROOM_FULL_NAMES (100 * Cht_MAX_BYTES_ROOM_FULL_NAME)
void Cht_OpenChatWindow (void)
{
@ -386,9 +387,9 @@ void Cht_OpenChatWindow (void)
char ThisRoomCode[Cht_MAX_BYTES_ROOM_CODE + 1];
char ThisRoomShortName[Cht_MAX_BYTES_ROOM_SHRT_NAME + 1];
char ThisRoomFullName [Cht_MAX_BYTES_ROOM_FULL_NAME + 1];
char ListRoomCodes [Cht_MAX_BYTES_ROOM_CODES + 1];
char ListRoomCodes [Cht_MAX_BYTES_ROOM_CODES + 1];
char ListRoomShrtNames[Cht_MAX_BYTES_ROOM_SHRT_NAMES + 1];
char ListRoomFullNames [Cht_MAX_BYTES_ROOM_FULL_NAMES + 1];
char ListRoomFullNames[Cht_MAX_BYTES_ROOM_FULL_NAMES + 1];
FILE *FileChat;
FILE *FileOut = Fil_GetOutputFile ();
@ -470,14 +471,14 @@ void Cht_OpenChatWindow (void)
NumMyDeg++)
{
snprintf (ThisRoomCode,sizeof (ThisRoomCode),"DEG_%ld",
Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod);
Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].HieCod);
if (strcmp (RoomCode,ThisRoomCode))
{
Str_Concat (ListRoomCodes,"|#",sizeof (ListRoomCodes) - 1);
Str_Concat (ListRoomCodes,ThisRoomCode,sizeof (ListRoomCodes) - 1);
/* Get data of this degree */
Deg.HieCod = Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod;
Deg.HieCod = Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].HieCod;
Deg_GetDegreeDataByCod (&Deg);
snprintf (ThisRoomShortName,sizeof (ThisRoomShortName),"%s",
@ -497,14 +498,14 @@ void Cht_OpenChatWindow (void)
NumMyCrs++)
{
snprintf (ThisRoomCode,sizeof (ThisRoomCode),"CRS_%ld",
Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod);
Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].HieCod);
if (strcmp (RoomCode,ThisRoomCode))
{
Str_Concat (ListRoomCodes,"|#",sizeof (ListRoomCodes) - 1);
Str_Concat (ListRoomCodes,ThisRoomCode,sizeof (ListRoomCodes) - 1);
/* Get data of this course */
Crs.HieCod = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod;
Crs.HieCod = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].HieCod;
Crs_GetCourseDataByCod (&Crs);
snprintf (ThisRoomShortName,sizeof (ThisRoomShortName),

View File

@ -1790,28 +1790,32 @@ void Cty_GetMyCountrs (void)
if (!Gbl.Usrs.Me.MyCtys.Filled)
{
Gbl.Usrs.Me.MyCtys.Num = 0;
Gbl.Usrs.Me.MyCtys.Ctys = NULL;
/***** Get my institutions from database *****/
NumCtys = Cty_DB_GetCtysFromUsr (&mysql_res,Gbl.Usrs.Me.UsrDat.UsrCod);
for (NumCty = 0;
NumCty < NumCtys;
NumCty++)
{
/* Get next country */
row = mysql_fetch_row (mysql_res);
/* Get country code */
if ((CtyCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
if (NumCtys)
{
if ((Gbl.Usrs.Me.MyCtys.Ctys = malloc (NumCtys *
sizeof (*Gbl.Usrs.Me.MyCtys.Ctys))) == NULL)
Err_NotEnoughMemoryExit ();
for (NumCty = 0;
NumCty < NumCtys;
NumCty++)
{
if (Gbl.Usrs.Me.MyCtys.Num == Cty_MAX_COUNTRS_PER_USR)
Err_ShowErrorAndExit ("Maximum number of countries of a user exceeded.");
/* Get next country */
row = mysql_fetch_row (mysql_res);
Gbl.Usrs.Me.MyCtys.Ctys[Gbl.Usrs.Me.MyCtys.Num].CtyCod = CtyCod;
Gbl.Usrs.Me.MyCtys.Ctys[Gbl.Usrs.Me.MyCtys.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]);
/* Get country code */
if ((CtyCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
{
Gbl.Usrs.Me.MyCtys.Ctys[Gbl.Usrs.Me.MyCtys.Num].HieCod = CtyCod;
Gbl.Usrs.Me.MyCtys.Ctys[Gbl.Usrs.Me.MyCtys.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]);
Gbl.Usrs.Me.MyCtys.Num++;
Gbl.Usrs.Me.MyCtys.Num++;
}
}
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
@ -1831,7 +1835,11 @@ void Cty_FreeMyCountrs (void)
{
/***** Reset list *****/
Gbl.Usrs.Me.MyCtys.Filled = false;
Gbl.Usrs.Me.MyCtys.Num = 0;
if (Gbl.Usrs.Me.MyCtys.Num &&
Gbl.Usrs.Me.MyCtys.Ctys)
free (Gbl.Usrs.Me.MyCtys.Ctys);
Gbl.Usrs.Me.MyCtys.Ctys = NULL;
Gbl.Usrs.Me.MyCtys.Num = 0;
}
}
@ -1850,7 +1858,7 @@ bool Cty_CheckIfIBelongToCty (long CtyCod)
for (NumMyCty = 0;
NumMyCty < Gbl.Usrs.Me.MyCtys.Num;
NumMyCty++)
if (Gbl.Usrs.Me.MyCtys.Ctys[NumMyCty].CtyCod == CtyCod)
if (Gbl.Usrs.Me.MyCtys.Ctys[NumMyCty].HieCod == CtyCod)
return true;
return false;
}

View File

@ -40,8 +40,6 @@
/************************** Public types and constants ***********************/
/*****************************************************************************/
#define Cty_MAX_COUNTRS_PER_USR 10 // Used in list of my countries
#define Cty_MAX_CHARS_NAME (48 - 1) // 47
#define Cty_MAX_BYTES_NAME ((Cty_MAX_CHARS_NAME + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 767

View File

@ -600,8 +600,8 @@ void Crs_WriteSelectorMyCoursesInBreadcrumb (void)
NumMyCrs < Gbl.Usrs.Me.MyCrss.Num;
NumMyCrs++)
{
CrsCod = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod;
DegCod = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].DegCod;
CrsCod = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].HieCod;
DegCod = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].PrtCod;
Crs_DB_GetShortNamesByCod (CrsCod,CrsShortName,DegShortName);

View File

@ -40,8 +40,6 @@
/***************************** Public constants ******************************/
/*****************************************************************************/
#define Crs_MAX_COURSES_PER_USR 100 // Used in list of my courses and list of distinct courses in sent or received messages
#define Crs_MIN_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS 6
#define Crs_DEF_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS 12
#define Crs_MAX_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_CRSS 60

View File

@ -1658,29 +1658,33 @@ void Deg_GetMyDegrees (void)
if (!Gbl.Usrs.Me.MyDegs.Filled)
{
Gbl.Usrs.Me.MyDegs.Num = 0;
Gbl.Usrs.Me.MyDegs.Degs = NULL;
/***** Get my degrees from database *****/
NumDegs = Deg_DB_GetDegsFromUsr (&mysql_res,
Gbl.Usrs.Me.UsrDat.UsrCod,-1L);
for (NumDeg = 0;
NumDeg < NumDegs;
NumDeg++)
{
/* Get next degree */
row = mysql_fetch_row (mysql_res);
/* Get degree code */
if ((DegCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
if (NumDegs)
{
if ((Gbl.Usrs.Me.MyDegs.Degs = malloc (NumDegs *
sizeof (*Gbl.Usrs.Me.MyDegs.Degs))) == NULL)
Err_NotEnoughMemoryExit ();
for (NumDeg = 0;
NumDeg < NumDegs;
NumDeg++)
{
if (Gbl.Usrs.Me.MyDegs.Num == Deg_MAX_DEGREES_PER_USR)
Err_ShowErrorAndExit ("Maximum number of degrees of a user exceeded.");
/* Get next degree */
row = mysql_fetch_row (mysql_res);
Gbl.Usrs.Me.MyDegs.Degs[Gbl.Usrs.Me.MyDegs.Num].DegCod = DegCod;
Gbl.Usrs.Me.MyDegs.Degs[Gbl.Usrs.Me.MyDegs.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]);
/* Get degree code */
if ((DegCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
{
Gbl.Usrs.Me.MyDegs.Degs[Gbl.Usrs.Me.MyDegs.Num].HieCod = DegCod;
Gbl.Usrs.Me.MyDegs.Degs[Gbl.Usrs.Me.MyDegs.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]);
Gbl.Usrs.Me.MyDegs.Num++;
Gbl.Usrs.Me.MyDegs.Num++;
}
}
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
@ -1700,6 +1704,10 @@ void Deg_FreeMyDegrees (void)
{
/***** Reset list *****/
Gbl.Usrs.Me.MyDegs.Filled = false;
if (Gbl.Usrs.Me.MyDegs.Num &&
Gbl.Usrs.Me.MyDegs.Degs)
free (Gbl.Usrs.Me.MyDegs.Degs);
Gbl.Usrs.Me.MyDegs.Degs = NULL;
Gbl.Usrs.Me.MyDegs.Num = 0;
}
}
@ -1719,7 +1727,7 @@ bool Deg_CheckIfIBelongToDeg (long DegCod)
for (NumMyDeg = 0;
NumMyDeg < Gbl.Usrs.Me.MyDegs.Num;
NumMyDeg++)
if (Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod == DegCod)
if (Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].HieCod == DegCod)
return true;
return false;
}

View File

@ -42,8 +42,6 @@
#define Deg_MAX_YEARS_PER_DEGREE 12 // Max number of academic years per degree
#define Deg_MAX_DEGREES_PER_USR 20 // Used in list of my degrees
/*****************************************************************************/
/***************************** Public prototypes *****************************/
/*****************************************************************************/

View File

@ -3248,27 +3248,33 @@ void Enr_GetMyCourses (void)
Enr_DB_CreateTmpTableMyCourses ();
/***** Get my courses from database *****/
Gbl.Usrs.Me.MyCrss.Num = 0;
Gbl.Usrs.Me.MyCrss.Crss = NULL;
NumCrss = Enr_DB_GetMyCourses (&mysql_res);
for (NumCrs = 0;
NumCrs < NumCrss;
NumCrs++)
if (NumCrss)
{
/* Get next course */
row = mysql_fetch_row (mysql_res);
/* Get course code (row[0]) */
if ((CrsCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
if ((Gbl.Usrs.Me.MyCrss.Crss = malloc (NumCrss *
sizeof (*Gbl.Usrs.Me.MyCrss.Crss))) == NULL)
Err_NotEnoughMemoryExit ();
for (NumCrs = 0;
NumCrs < NumCrss;
NumCrs++)
{
if (Gbl.Usrs.Me.MyCrss.Num == Crs_MAX_COURSES_PER_USR)
Err_ShowErrorAndExit ("Maximum number of courses of a user exceeded.");
/* Get next course */
row = mysql_fetch_row (mysql_res);
Gbl.Usrs.Me.MyCrss.Crss[Gbl.Usrs.Me.MyCrss.Num].CrsCod = CrsCod;
/* Get course code (row[0]) */
if ((CrsCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
{
Gbl.Usrs.Me.MyCrss.Crss[Gbl.Usrs.Me.MyCrss.Num].HieCod = CrsCod;
/* Get role (row[1]) and degree code (row[2]) */
Gbl.Usrs.Me.MyCrss.Crss[Gbl.Usrs.Me.MyCrss.Num].Role = Rol_ConvertUnsignedStrToRole (row[1]);
Gbl.Usrs.Me.MyCrss.Crss[Gbl.Usrs.Me.MyCrss.Num].DegCod = Str_ConvertStrCodToLongCod (row[2]);
/* Get role (row[1]) and degree code (row[2]) */
Gbl.Usrs.Me.MyCrss.Crss[Gbl.Usrs.Me.MyCrss.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]);
Gbl.Usrs.Me.MyCrss.Crss[Gbl.Usrs.Me.MyCrss.Num].PrtCod = Str_ConvertStrCodToLongCod (row[2]);
Gbl.Usrs.Me.MyCrss.Num++;
Gbl.Usrs.Me.MyCrss.Num++;
}
}
}
@ -3289,6 +3295,9 @@ void Enr_FreeMyCourses (void)
{
/***** Reset list *****/
Gbl.Usrs.Me.MyCrss.Filled = false;
if (Gbl.Usrs.Me.MyCrss.Num &&
Gbl.Usrs.Me.MyCrss.Crss)
free (Gbl.Usrs.Me.MyCrss.Crss);
Gbl.Usrs.Me.MyCrss.Num = 0;
/***** Remove temporary table with my courses *****/
@ -3311,7 +3320,7 @@ bool Enr_CheckIfIBelongToCrs (long CrsCod)
for (NumMyCrs = 0;
NumMyCrs < Gbl.Usrs.Me.MyCrss.Num;
NumMyCrs++)
if (Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod == CrsCod)
if (Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].HieCod == CrsCod)
return true;
return false;

View File

@ -1317,7 +1317,7 @@ void For_ShowForumList (struct For_Forums *Forums)
NumMyIns < Gbl.Usrs.Me.MyInss.Num;
NumMyIns++)
{
InsCod = Gbl.Usrs.Me.MyInss.Inss[NumMyIns].InsCod;
InsCod = Gbl.Usrs.Me.MyInss.Inss[NumMyIns].HieCod;
/* Links to forums of this institution */
For_WriteLinksToInsForums (Forums,

View File

@ -137,52 +137,31 @@ struct Globals
{
bool Filled; // My institutions are already filled?
unsigned Num;
struct
{
long CtyCod;
Rol_Role_t MaxRole;
} Ctys[Cty_MAX_COUNTRS_PER_USR];
struct Hie_MyNode *Ctys;
} MyCtys;
struct
{
bool Filled; // My institutions are already filled?
unsigned Num;
struct
{
long InsCod;
Rol_Role_t MaxRole;
} Inss[Ins_MAX_INSTITS_PER_USR];
struct Hie_MyNode *Inss;
} MyInss;
struct
{
bool Filled; // My centers are already filled?
unsigned Num;
struct
{
long CtrCod;
Rol_Role_t MaxRole;
} Ctrs[Ctr_MAX_CENTERS_PER_USR];
struct Hie_MyNode *Ctrs;
} MyCtrs;
struct
{
bool Filled; // My degrees are already filled?
unsigned Num;
struct
{
long DegCod;
Rol_Role_t MaxRole;
} Degs[Deg_MAX_DEGREES_PER_USR];
struct Hie_MyNode *Degs;
} MyDegs;
struct
{
bool Filled; // My courses are already filled?
unsigned Num;
struct
{
long CrsCod;
Rol_Role_t Role;
long DegCod;
} Crss[Crs_MAX_COURSES_PER_USR];
struct Hie_MyNode *Crss;
} MyCrss;
Set_ShowUsrsType_t ListType; // My preference about user's list type
unsigned NumFollowers; // Number of users who follow me

View File

@ -28,6 +28,7 @@
/*****************************************************************************/
#include "swad_constant.h"
#include "swad_role_type.h"
#include "swad_string.h"
/*****************************************************************************/
@ -77,6 +78,13 @@ typedef enum
#define Hie_MAX_CHARS_FULL_NAME (128 - 1) // 127
#define Hie_MAX_BYTES_FULL_NAME ((Hie_MAX_CHARS_FULL_NAME + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 2047
struct Hie_MyNode
{
long HieCod; // Course/degree/center/institution/country code
long PrtCod; // Parent code
Rol_Role_t MaxRole; // Role in course or maximum role in degree/center/institution/country
};
struct Hie_Node
{
long HieCod; // Course/degree/center/institution/country code

View File

@ -1699,29 +1699,33 @@ void Ins_GetMyInstits (void)
if (!Gbl.Usrs.Me.MyInss.Filled)
{
Gbl.Usrs.Me.MyInss.Num = 0;
Gbl.Usrs.Me.MyInss.Inss = NULL;
/***** Get my institutions from database *****/
NumInss = Ins_DB_GetInssFromUsr (&mysql_res,
Gbl.Usrs.Me.UsrDat.UsrCod,-1L);
for (NumIns = 0;
NumIns < NumInss;
NumIns++)
{
/* Get next institution */
row = mysql_fetch_row (mysql_res);
/* Get institution code */
if ((InsCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
if (NumInss)
{
if ((Gbl.Usrs.Me.MyInss.Inss = malloc (NumInss *
sizeof (*Gbl.Usrs.Me.MyInss.Inss))) == NULL)
Err_NotEnoughMemoryExit ();
for (NumIns = 0;
NumIns < NumInss;
NumIns++)
{
if (Gbl.Usrs.Me.MyInss.Num == Ins_MAX_INSTITS_PER_USR)
Err_ShowErrorAndExit ("Maximum number of institutions of a user exceeded.");
/* Get next institution */
row = mysql_fetch_row (mysql_res);
Gbl.Usrs.Me.MyInss.Inss[Gbl.Usrs.Me.MyInss.Num].InsCod = InsCod;
Gbl.Usrs.Me.MyInss.Inss[Gbl.Usrs.Me.MyInss.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]);
/* Get institution code */
if ((InsCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
{
Gbl.Usrs.Me.MyInss.Inss[Gbl.Usrs.Me.MyInss.Num].HieCod = InsCod;
Gbl.Usrs.Me.MyInss.Inss[Gbl.Usrs.Me.MyInss.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]);
Gbl.Usrs.Me.MyInss.Num++;
Gbl.Usrs.Me.MyInss.Num++;
}
}
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
@ -1741,7 +1745,11 @@ void Ins_FreeMyInstits (void)
{
/***** Reset list *****/
Gbl.Usrs.Me.MyInss.Filled = false;
Gbl.Usrs.Me.MyInss.Num = 0;
if (Gbl.Usrs.Me.MyInss.Num &&
Gbl.Usrs.Me.MyInss.Inss)
free (Gbl.Usrs.Me.MyInss.Inss);
Gbl.Usrs.Me.MyInss.Inss = NULL;
Gbl.Usrs.Me.MyInss.Num = 0;
}
}
@ -1760,7 +1768,7 @@ bool Ins_CheckIfIBelongToIns (long InsCod)
for (NumMyIns = 0;
NumMyIns < Gbl.Usrs.Me.MyInss.Num;
NumMyIns++)
if (Gbl.Usrs.Me.MyInss.Inss[NumMyIns].InsCod == InsCod)
if (Gbl.Usrs.Me.MyInss.Inss[NumMyIns].HieCod == InsCod)
return true;
return false;
}

View File

@ -32,12 +32,6 @@
#include "swad_figure_cache.h"
#include "swad_role_type.h"
/*****************************************************************************/
/************************ Public types and constants *************************/
/*****************************************************************************/
#define Ins_MAX_INSTITS_PER_USR 10 // Used in list of my institutions
/*****************************************************************************/
/***************************** Public prototypes *****************************/
/*****************************************************************************/

View File

@ -263,7 +263,7 @@ Rol_Role_t Rol_GetMyMaxRoleInIns (long InsCod)
for (NumMyIns = 0;
NumMyIns < Gbl.Usrs.Me.MyInss.Num;
NumMyIns++)
if (Gbl.Usrs.Me.MyInss.Inss[NumMyIns].InsCod == InsCod)
if (Gbl.Usrs.Me.MyInss.Inss[NumMyIns].HieCod == InsCod)
return Gbl.Usrs.Me.MyInss.Inss[NumMyIns].MaxRole;
return Rol_GST;
}
@ -287,7 +287,7 @@ Rol_Role_t Rol_GetMyMaxRoleInCtr (long CtrCod)
for (NumMyCtr = 0;
NumMyCtr < Gbl.Usrs.Me.MyCtrs.Num;
NumMyCtr++)
if (Gbl.Usrs.Me.MyCtrs.Ctrs[NumMyCtr].CtrCod == CtrCod)
if (Gbl.Usrs.Me.MyCtrs.Ctrs[NumMyCtr].HieCod == CtrCod)
return Gbl.Usrs.Me.MyCtrs.Ctrs[NumMyCtr].MaxRole;
return Rol_GST;
}
@ -313,7 +313,7 @@ Rol_Role_t Rol_GetMyMaxRoleInDeg (long DegCod)
for (NumMyDeg = 0;
NumMyDeg < Gbl.Usrs.Me.MyDegs.Num;
NumMyDeg++)
if (Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod == DegCod)
if (Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].HieCod == DegCod)
return Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].MaxRole;
return Rol_GST;
}
@ -349,9 +349,9 @@ Rol_Role_t Rol_GetMyRoleInCrs (long CrsCod)
for (NumMyCrs = 0, Role = Rol_UNK;
NumMyCrs < Gbl.Usrs.Me.MyCrss.Num;
NumMyCrs++)
if (Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod == CrsCod)
if (Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].HieCod == CrsCod)
{
Role = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].Role;
Role = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].MaxRole;
break;
}