Version 16.111.15

This commit is contained in:
Antonio Cañas Vargas 2016-12-30 01:20:49 +01:00
parent ff0a98979f
commit 5a85869fd8
6 changed files with 114 additions and 121 deletions

View File

@ -189,13 +189,14 @@
/****************************** Public constants *****************************/
/*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 16.111.14 (2016-12-29)"
#define Log_PLATFORM_VERSION "SWAD 16.111.15 (2016-12-30)"
#define CSS_FILE "swad16.111.5.css"
#define JS_FILE "swad16.101.js"
// Number of lines (includes comments but not blank lines) has been got with the following command:
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1
/*
Version 16.111.15:Dec 30, 2016 Fixed minor bug in forums, reported by Coverity. (211182 lines)
Version 16.111.14:Dec 29, 2016 Fixed bug in attendance events. (211189 lines)
Version 16.111.13:Dec 29, 2016 Fixed bug in attendance events, reported by Coverity. (211173 lines)
Version 16.111.12:Dec 29, 2016 Fixed minor bug in groups, reported by Coverity. (? lines)

View File

@ -2044,10 +2044,9 @@ bool Crs_GetDataOfCourseByCod (struct Course *Crs)
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
bool CrsFound = false;
/***** Reset course data *****/
/***** Clear data *****/
Crs->DegCod = -1L;
Crs->Year = 0;
Crs->Status = (Crs_Status_t) 0;
@ -2058,26 +2057,26 @@ bool Crs_GetDataOfCourseByCod (struct Course *Crs)
Crs->NumTchs = 0;
Crs->NumUsrs = 0;
/***** Check if course code is correct *****/
if (Crs->CrsCod > 0)
{
/***** Get data of a course from database *****/
sprintf (Query,"SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
" FROM courses WHERE CrsCod='%ld'",
Crs->CrsCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get data of a course");
if (NumRows == 1) // Course found
if (DB_QuerySELECT (Query,&mysql_res,"can not get data of a course")) // Course found...
{
/***** Get data of the course *****/
row = mysql_fetch_row (mysql_res);
Crs_GetDataOfCourseFromRow (Crs,row);
/* Set return value */
CrsFound = true;
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return CrsFound;
}

View File

@ -1677,57 +1677,40 @@ bool Deg_GetDataOfDegreeByCod (struct Degree *Deg)
char Query[1024];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
bool DegFound = false;
if (Deg->DegCod <= 0)
/***** Clear data *****/
Deg->CtrCod = -1L;
Deg->DegTypCod = -1L;
Deg->Status = (Deg_Status_t) 0;
Deg->RequesterUsrCod = -1L;
Deg->ShrtName[0] = '\0';
Deg->FullName[0] = '\0';
Deg->WWW[0] = '\0';
Deg->LstCrss = NULL;
/***** Check if degree code is correct *****/
if (Deg->DegCod > 0)
{
Deg->DegCod = -1L;
Deg->CtrCod = -1L;
Deg->DegTypCod = -1L;
Deg->Status = (Deg_Status_t) 0;
Deg->RequesterUsrCod = -1L;
Deg->ShrtName[0] = '\0';
Deg->FullName[0] = '\0';
Deg->WWW[0] = '\0';
Deg->LstCrss = NULL;
return false;
/***** Get data of a degree from database *****/
sprintf (Query,"SELECT DegCod,CtrCod,DegTypCod,Status,RequesterUsrCod,"
"ShortName,FullName,WWW"
" FROM degrees WHERE DegCod ='%ld'",
Deg->DegCod);
if (DB_QuerySELECT (Query,&mysql_res,"can not get data of a degree")) // Degree found...
{
/***** Get data of degree *****/
row = mysql_fetch_row (mysql_res);
Deg_GetDataOfDegreeFromRow (Deg,row);
/* Set return value */
DegFound = true;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/***** Get data of a degree from database *****/
sprintf (Query,"SELECT DegCod,CtrCod,DegTypCod,Status,RequesterUsrCod,"
"ShortName,FullName,WWW"
" FROM degrees WHERE DegCod ='%ld'",
Deg->DegCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get data of a degree");
if (NumRows == 1)
{
/***** Get data of degree *****/
row = mysql_fetch_row (mysql_res);
Deg_GetDataOfDegreeFromRow (Deg,row);
DegFound = true;
}
else if (NumRows == 0)
{
Deg->DegCod = -1L;
Deg->CtrCod = -1L;
Deg->DegTypCod = -1L;
Deg->Status = (Deg_Status_t) 0;
Deg->RequesterUsrCod = -1L;
Deg->ShrtName[0] = '\0';
Deg->FullName[0] = '\0';
Deg->WWW[0] = '\0';
Deg->LstCrss = NULL;
return false;
}
else if (NumRows > 1)
Lay_ShowErrorAndExit ("Degree repeated in database.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return DegFound;
}

View File

@ -405,13 +405,18 @@ static bool For_GetIfForumPstExists (long PstCod)
static bool For_GetIfPstIsEnabled (long PstCod)
{
char Query[512];
char Query[128];
/***** Get if post is disabled from database *****/
sprintf (Query,"SELECT COUNT(*) FROM forum_disabled_post"
" WHERE PstCod='%ld'",
PstCod);
return (DB_QueryCOUNT (Query,"can not check if a post of a forum is disabled") == 0); // Post is enabled if it does not appear in table of disabled posts
if (PstCod > 0)
{
/***** Get if post is disabled from database *****/
sprintf (Query,"SELECT COUNT(*) FROM forum_disabled_post"
" WHERE PstCod='%ld'",
PstCod);
return (DB_QueryCOUNT (Query,"can not check if a post of a forum is disabled") == 0); // Post is enabled if it does not appear in table of disabled posts
}
else
return false;
}
/*****************************************************************************/
@ -3565,6 +3570,12 @@ void For_GetThrData (struct ForumThread *Thr)
Lay_ShowErrorAndExit ("Error when getting data of a thread of a forum.");
row = mysql_fetch_row (mysql_res);
/***** Get the code of the first post in this thread (row[0]) *****/
//Thr->PstCod[For_FIRST_MSG] = Str_ConvertStrCodToLongCod (row[0]);
/***** Get the code of the last post in this thread (row[1]) *****/
//Thr->PstCod[For_LAST_MSG ] = Str_ConvertStrCodToLongCod (row[1]);
/***** Get the code of the first message in this thread (row[0]) *****/
if (sscanf (row[0],"%ld",&(Thr->PstCod[For_FIRST_MSG])) != 1)
Lay_ShowErrorAndExit ("Wrong code of post.");
@ -3573,16 +3584,16 @@ void For_GetThrData (struct ForumThread *Thr)
if (sscanf (row[1],"%ld",&(Thr->PstCod[For_LAST_MSG])) != 1)
Lay_ShowErrorAndExit ("Wrong code of post.");
/***** Get the author of the first message in this thread (row[2]) *****/
/***** Get the author of the first post in this thread (row[2]) *****/
Thr->UsrCod[For_FIRST_MSG] = Str_ConvertStrCodToLongCod (row[2]);
/***** Get the author of the last message in this thread (row[3]) *****/
Thr->UsrCod[For_LAST_MSG] = Str_ConvertStrCodToLongCod (row[3]);
/***** Get the author of the last post in this thread (row[3]) *****/
Thr->UsrCod[For_LAST_MSG ] = Str_ConvertStrCodToLongCod (row[3]);
/***** Get the date of the first message in this thread (row[4]) *****/
/***** Get the date of the first post in this thread (row[4]) *****/
Thr->WriteTime[For_FIRST_MSG] = Dat_GetUNIXTimeFromStr (row[4]);
/***** Get the date of the last message in this thread (row[5]) *****/
/***** Get the date of the last post in this thread (row[5]) *****/
Thr->WriteTime[For_LAST_MSG ] = Dat_GetUNIXTimeFromStr (row[5]);
/***** Get the subject of this thread (row[6]) *****/
@ -3598,7 +3609,8 @@ void For_GetThrData (struct ForumThread *Thr)
for (Order = For_FIRST_MSG;
Order <= For_LAST_MSG;
Order++)
Thr->Enabled[Order] = For_GetIfPstIsEnabled (Thr->PstCod[Order]);
// Thr->Enabled[Order] = For_GetIfPstIsEnabled (Thr->PstCod[Order]);
Thr->Enabled[Order] = true;
/***** Get number of posts in this thread *****/
Thr->NumPosts = For_GetNumPstsInThr (Thr->ThrCod);

View File

@ -1085,7 +1085,7 @@ bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins,
char Query[256];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
bool InsFound;
bool InsFound = false;
/***** Clear data *****/
Ins->CtyCod = -1L;
@ -1099,67 +1099,62 @@ bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins,
Ins->NumUsrs = 0;
/***** Check if institution code is correct *****/
if (Ins->InsCod <= 0)
return false;
// Ins->InsCod > 0
/***** Get data of an institution from database *****/
sprintf (Query,"SELECT CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW"
" FROM institutions WHERE InsCod='%ld'",
Ins->InsCod);
/***** Count number of rows in result *****/
if (DB_QuerySELECT (Query,&mysql_res,"can not get data of an institution")) // Institution found...
if (Ins->InsCod > 0)
{
InsFound = true;
/***** Get data of an institution from database *****/
sprintf (Query,"SELECT CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW"
" FROM institutions WHERE InsCod='%ld'",
Ins->InsCod);
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get country code (row[0]) */
Ins->CtyCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get centre status (row[1]) */
if (sscanf (row[1],"%u",&(Ins->Status)) != 1)
Lay_ShowErrorAndExit ("Wrong institution status.");
/* Get requester user's code (row[2]) */
Ins->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[2]);
/* Get the short name of the institution (row[3]) */
strcpy (Ins->ShrtName,row[3]);
/* Get the full name of the institution (row[4]) */
strncpy (Ins->FullName,row[4],Ins_MAX_LENGTH_INSTIT_FULL_NAME);
Ins->FullName[Ins_MAX_LENGTH_INSTIT_FULL_NAME] = '\0';
/* Get the URL of the institution (row[5]) */
strcpy (Ins->WWW,row[5]);
/* Get extra data */
if (GetExtraData == Ins_GET_EXTRA_DATA)
/***** Count number of rows in result *****/
if (DB_QuerySELECT (Query,&mysql_res,"can not get data of an institution")) // Institution found...
{
/* Get number of centres in this institution */
Ins->NumCtrs = Ctr_GetNumCtrsInIns (Ins->InsCod);
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get number of departments in this institution */
Ins->NumDpts = Dpt_GetNumberOfDepartmentsInInstitution (Ins->InsCod);
/* Get country code (row[0]) */
Ins->CtyCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get number of degrees in this institution */
Ins->NumDegs = Deg_GetNumDegsInIns (Ins->InsCod);
/* Get centre status (row[1]) */
if (sscanf (row[1],"%u",&(Ins->Status)) != 1)
Lay_ShowErrorAndExit ("Wrong institution status.");
/* Get number of users in courses of this institution */
Ins->NumUsrs = Usr_GetNumUsrsInCrssOfIns (Rol_UNKNOWN,Ins->InsCod); // Here Rol_UNKNOWN means "all users"
/* Get requester user's code (row[2]) */
Ins->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[2]);
/* Get the short name of the institution (row[3]) */
strcpy (Ins->ShrtName,row[3]);
/* Get the full name of the institution (row[4]) */
strncpy (Ins->FullName,row[4],Ins_MAX_LENGTH_INSTIT_FULL_NAME);
Ins->FullName[Ins_MAX_LENGTH_INSTIT_FULL_NAME] = '\0';
/* Get the URL of the institution (row[5]) */
strcpy (Ins->WWW,row[5]);
/* Get extra data */
if (GetExtraData == Ins_GET_EXTRA_DATA)
{
/* Get number of centres in this institution */
Ins->NumCtrs = Ctr_GetNumCtrsInIns (Ins->InsCod);
/* Get number of departments in this institution */
Ins->NumDpts = Dpt_GetNumberOfDepartmentsInInstitution (Ins->InsCod);
/* Get number of degrees in this institution */
Ins->NumDegs = Deg_GetNumDegsInIns (Ins->InsCod);
/* Get number of users in courses of this institution */
Ins->NumUsrs = Usr_GetNumUsrsInCrssOfIns (Rol_UNKNOWN,Ins->InsCod); // Here Rol_UNKNOWN means "all users"
}
/* Set return value */
InsFound = true;
}
}
else
{
Ins->InsCod = -1L;
InsFound = false;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return InsFound;
}

View File

@ -2304,6 +2304,9 @@ long Str_ConvertStrCodToLongCod (const char *Str)
{
long Code;
if (!Str)
return -1L;
if (Str[0] == '\0')
return -1L;