Version 20.64: Apr 17, 2021 Optimizations in database selects.

This commit is contained in:
acanas 2021-04-17 01:08:48 +02:00
parent d3bc257ce5
commit d9a0fa9d4a
30 changed files with 1151 additions and 1135 deletions

View File

@ -154,21 +154,23 @@ static void RSS_WriteNotices (FILE *FileRSS,struct Crs_Course *Crs)
struct tm *tm; struct tm *tm;
time_t CreatTimeUTC; time_t CreatTimeUTC;
long NotCod; long NotCod;
unsigned long NumNot,NumNotices; unsigned NumNotices;
unsigned NumNot;
char Content[Cns_MAX_BYTES_TEXT + 1]; char Content[Cns_MAX_BYTES_TEXT + 1];
/***** Get active notices in course *****/ /***** Get active notices in course *****/
NumNotices = DB_QuerySELECT (&mysql_res,"can not get notices from database", NumNotices = (unsigned)
"SELECT NotCod," // row[0] DB_QuerySELECT (&mysql_res,"can not get notices from database",
"UNIX_TIMESTAMP(CreatTime) AS T," // row[1] "SELECT NotCod," // row[0]
"UsrCod," // row[2] "UNIX_TIMESTAMP(CreatTime) AS T," // row[1]
"Content" // row[3] "UsrCod," // row[2]
" FROM not_notices" "Content" // row[3]
" WHERE CrsCod=%ld" " FROM not_notices"
" AND Status=%u" " WHERE CrsCod=%ld"
" ORDER BY T DESC", " AND Status=%u"
Crs->CrsCod, " ORDER BY T DESC",
(unsigned) Not_ACTIVE_NOTICE); Crs->CrsCod,
(unsigned) Not_ACTIVE_NOTICE);
/***** Write items with notices *****/ /***** Write items with notices *****/
if (NumNotices) if (NumNotices)
@ -253,13 +255,13 @@ static void RSS_WriteCallsForExams (FILE *FileRSS,struct Crs_Course *Crs)
struct tm *tm; struct tm *tm;
time_t CallTimeUTC; time_t CallTimeUTC;
long ExaCod; long ExaCod;
unsigned long NumExa; unsigned NumExams;
unsigned long NumExams; unsigned NumExa;
if (Gbl.DB.DatabaseIsOpen) if (Gbl.DB.DatabaseIsOpen)
{ {
/***** Get exam announcements (only future exams) in current course from database *****/ /***** Get exam announcements (only future exams) in current course from database *****/
NumExams = NumExams = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get calls for exams", DB_QuerySELECT (&mysql_res,"can not get calls for exams",
"SELECT ExaCod," // row[0] "SELECT ExaCod," // row[0]
"UNIX_TIMESTAMP(CallDate) AS T," // row[1] "UNIX_TIMESTAMP(CallDate) AS T," // row[1]

View File

@ -600,13 +600,14 @@ TODO: Salvador Romero Cort
TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria. TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria.
*/ */
#define Log_PLATFORM_VERSION "SWAD 20.63 (2021-04-16)" #define Log_PLATFORM_VERSION "SWAD 20.64 (2021-04-17)"
#define CSS_FILE "swad20.45.css" #define CSS_FILE "swad20.45.css"
#define JS_FILE "swad20.6.2.js" #define JS_FILE "swad20.6.2.js"
/* /*
TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename CENTRE to CENTER in help wiki.
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
Version 20.64: Apr 17, 2021 Optimizations in database selects. (308518 lines)
Version 20.63: Apr 16, 2021 Optimizations in database selects. (308487 lines) Version 20.63: Apr 16, 2021 Optimizations in database selects. (308487 lines)
Version 20.62: Apr 15, 2021 Optimizations in database selects related to roles. (308574 lines) Version 20.62: Apr 15, 2021 Optimizations in database selects related to roles. (308574 lines)
Version 20.61: Apr 13, 2021 Optimizations in database selects. (308567 lines) Version 20.61: Apr 13, 2021 Optimizations in database selects. (308567 lines)

View File

@ -664,10 +664,10 @@ void Cty_WriteScriptGoogleGeochart (void)
static void Cty_GetParamCtyOrder (void) static void Cty_GetParamCtyOrder (void)
{ {
Gbl.Hierarchy.Ctys.SelectedOrder = (Cty_Order_t) Gbl.Hierarchy.Ctys.SelectedOrder = (Cty_Order_t)
Par_GetParToUnsignedLong ("Order", Par_GetParToUnsignedLong ("Order",
0, 0,
Cty_NUM_ORDERS - 1, Cty_NUM_ORDERS - 1,
(unsigned long) Cty_ORDER_DEFAULT); (unsigned long) Cty_ORDER_DEFAULT);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -591,7 +591,7 @@ void DT_GetListDegreeTypes (Hie_Lvl_Level_t Scope,DT_Order_t Order)
}; };
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRow; unsigned NumTyp;
/***** Get types of degree from database *****/ /***** Get types of degree from database *****/
switch (Scope) switch (Scope)
@ -709,23 +709,23 @@ void DT_GetListDegreeTypes (Hie_Lvl_Level_t Scope,DT_Order_t Order)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
/***** Get degree types *****/ /***** Get degree types *****/
for (NumRow = 0; for (NumTyp = 0;
NumRow < Gbl.DegTypes.Num; NumTyp < Gbl.DegTypes.Num;
NumRow++) 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[NumRow].DegTypCod = Str_ConvertStrCodToLongCod (row[0])) < 0) if ((Gbl.DegTypes.Lst[NumTyp].DegTypCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of type of degree."); Lay_ShowErrorAndExit ("Wrong code of type of degree.");
/* Get degree type name (row[1]) */ /* Get degree type name (row[1]) */
Str_Copy (Gbl.DegTypes.Lst[NumRow].DegTypName,row[1], Str_Copy (Gbl.DegTypes.Lst[NumTyp].DegTypName,row[1],
sizeof (Gbl.DegTypes.Lst[NumRow].DegTypName) - 1); sizeof (Gbl.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[NumRow].NumDegs) != 1) if (sscanf (row[2],"%u",&Gbl.DegTypes.Lst[NumTyp].NumDegs) != 1)
Lay_ShowErrorAndExit ("Error when getting number of degrees of a type"); Lay_ShowErrorAndExit ("Error when getting number of degrees of a type");
} }
} }

View File

@ -157,7 +157,9 @@ static void Fig_WriteRowStatsFileBrowsers3 (const char *NameOfFileZones,
struct Fig_SizeOfFileZones *SizeOfFileZones); struct Fig_SizeOfFileZones *SizeOfFileZones);
static void Fig_GetAndShowOERsStats (void); static void Fig_GetAndShowOERsStats (void);
static void Fig_GetNumberOfOERsFromDB (Hie_Lvl_Level_t Scope,Brw_License_t License,unsigned long NumFiles[2]); static void Fig_GetNumberOfOERsFromDB (Hie_Lvl_Level_t Scope,
Brw_License_t License,
unsigned long NumFiles[2]);
static void Fig_GetAndShowCourseProgramStats (void); // TODO: Change function from assignments to schedule static void Fig_GetAndShowCourseProgramStats (void); // TODO: Change function from assignments to schedule
@ -2958,7 +2960,9 @@ static void Fig_GetAndShowOERsStats (void)
/**************** Get the size of a file zone from database ******************/ /**************** Get the size of a file zone from database ******************/
/*****************************************************************************/ /*****************************************************************************/
static void Fig_GetNumberOfOERsFromDB (Hie_Lvl_Level_t Scope,Brw_License_t License,unsigned long NumFiles[2]) static void Fig_GetNumberOfOERsFromDB (Hie_Lvl_Level_t Scope,
Brw_License_t License,
unsigned long NumFiles[2])
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;

View File

@ -1359,7 +1359,7 @@ static void Brw_GetFileNameToShow (Brw_FileType_t FileType,
char FileNameToShow[NAME_MAX + 1]); char FileNameToShow[NAME_MAX + 1]);
static void Brw_WriteDatesAssignment (void); static void Brw_WriteDatesAssignment (void);
static void Brw_WriteFileSizeAndDate (struct FileMetadata *FileMetadata); static void Brw_WriteFileSizeAndDate (struct FileMetadata *FileMetadata);
static void Brw_WriteFileOrFolderPublisher (unsigned Level,unsigned long UsrCod); static void Brw_WriteFileOrFolderPublisher (unsigned Level,long UsrCod);
static void Brw_AskConfirmRemoveFolderNotEmpty (void); static void Brw_AskConfirmRemoveFolderNotEmpty (void);
static void Brw_WriteCurrentClipboard (void); static void Brw_WriteCurrentClipboard (void);
@ -1445,7 +1445,7 @@ static bool Brw_CheckIfICanModifyPrjDocFileOrFolder (void);
static bool Brw_CheckIfICanModifyPrjAssFileOrFolder (void); static bool Brw_CheckIfICanModifyPrjAssFileOrFolder (void);
static long Brw_GetPublisherOfSubtree (void); static long Brw_GetPublisherOfSubtree (void);
static void Brw_WriteRowDocData (unsigned long *NumDocsNotHidden,MYSQL_ROW row); static void Brw_WriteRowDocData (unsigned *NumDocsNotHidden,MYSQL_ROW row);
static void Brw_PutLinkToAskRemOldFiles (void); static void Brw_PutLinkToAskRemOldFiles (void);
static void Brw_RemoveOldFilesInBrowser (unsigned Months,struct Brw_NumObjects *Removed); static void Brw_RemoveOldFilesInBrowser (unsigned Months,struct Brw_NumObjects *Removed);
@ -6531,7 +6531,7 @@ static void Brw_WriteFileSizeAndDate (struct FileMetadata *FileMetadata)
/************** Write the user who published the file or folder **************/ /************** Write the user who published the file or folder **************/
/*****************************************************************************/ /*****************************************************************************/
static void Brw_WriteFileOrFolderPublisher (unsigned Level,unsigned long UsrCod) static void Brw_WriteFileOrFolderPublisher (unsigned Level,long UsrCod)
{ {
extern const char *Txt_Unknown_or_without_photo; extern const char *Txt_Unknown_or_without_photo;
bool ShowUsr = false; bool ShowUsr = false;
@ -11781,8 +11781,8 @@ void Brw_RemoveUsrWorksInAllCrss (struct UsrData *UsrDat)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumCrss; unsigned NumCrss;
unsigned long NumCrs; unsigned NumCrs;
unsigned NumCrssWorksRemoved = 0; unsigned NumCrssWorksRemoved = 0;
struct Crs_Course Crs; struct Crs_Course Crs;
@ -11871,7 +11871,7 @@ void Brw_GetSummaryAndContentOfFile (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
/**************************** List documents found ***************************/ /**************************** List documents found ***************************/
/*****************************************************************************/ /*****************************************************************************/
void Brw_ListDocsFound (MYSQL_RES **mysql_res,unsigned long NumDocs, void Brw_ListDocsFound (MYSQL_RES **mysql_res,unsigned NumDocs,
const char *TitleSingular,const char *TitlePlural) const char *TitleSingular,const char *TitlePlural)
{ {
extern const char *Txt_Institution; extern const char *Txt_Institution;
@ -11883,9 +11883,9 @@ void Brw_ListDocsFound (MYSQL_RES **mysql_res,unsigned long NumDocs,
extern const char *Txt_hidden_document; extern const char *Txt_hidden_document;
extern const char *Txt_hidden_documents; extern const char *Txt_hidden_documents;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumDoc; unsigned NumDoc;
unsigned long NumDocsNotHidden = 0; unsigned NumDocsNotHidden = 0;
unsigned long NumDocsHidden; unsigned NumDocsHidden;
/***** Query database *****/ /***** Query database *****/
if (NumDocs) if (NumDocs)
@ -11931,8 +11931,9 @@ void Brw_ListDocsFound (MYSQL_RES **mysql_res,unsigned long NumDocs,
HTM_TH_Begin (1,7,"CM"); HTM_TH_Begin (1,7,"CM");
HTM_Txt ("("); HTM_Txt ("(");
NumDocsHidden = NumDocs - NumDocsNotHidden; NumDocsHidden = NumDocs - NumDocsNotHidden;
HTM_TxtF ("%lu %s",NumDocsHidden,NumDocsHidden == 1 ? Txt_hidden_document : HTM_TxtF ("%u %s",
Txt_hidden_documents); NumDocsHidden,NumDocsHidden == 1 ? Txt_hidden_document :
Txt_hidden_documents);
HTM_Txt (")"); HTM_Txt (")");
HTM_TH_End (); HTM_TH_End ();
@ -11950,7 +11951,7 @@ void Brw_ListDocsFound (MYSQL_RES **mysql_res,unsigned long NumDocs,
/************ Write the data of a document (result of a query) ***************/ /************ Write the data of a document (result of a query) ***************/
/*****************************************************************************/ /*****************************************************************************/
static void Brw_WriteRowDocData (unsigned long *NumDocsNotHidden,MYSQL_ROW row) static void Brw_WriteRowDocData (unsigned *NumDocsNotHidden,MYSQL_ROW row)
{ {
extern const char *Txt_Documents_area; extern const char *Txt_Documents_area;
extern const char *Txt_Teachers_files_area; extern const char *Txt_Teachers_files_area;
@ -12023,7 +12024,7 @@ static void Brw_WriteRowDocData (unsigned long *NumDocsNotHidden,MYSQL_ROW row)
/***** Write number of document in this search *****/ /***** Write number of document in this search *****/
HTM_TD_Begin ("class=\"RT DAT %s\"",BgColor); HTM_TD_Begin ("class=\"RT DAT %s\"",BgColor);
HTM_UnsignedLong (++(*NumDocsNotHidden)); HTM_Unsigned (++(*NumDocsNotHidden));
HTM_TD_End (); HTM_TD_End ();
/***** Write institution logo, institution short name *****/ /***** Write institution logo, institution short name *****/

View File

@ -267,7 +267,7 @@ void Brw_GetSummaryAndContentOfFile (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
char **ContentStr, char **ContentStr,
long FilCod,bool GetContent); long FilCod,bool GetContent);
void Brw_ListDocsFound (MYSQL_RES **mysql_res,unsigned long NumDocs, void Brw_ListDocsFound (MYSQL_RES **mysql_res,unsigned NumDocs,
const char *TitleSingular,const char *TitlePlural); const char *TitleSingular,const char *TitlePlural);
void Brw_AskRemoveOldFiles (void); void Brw_AskRemoveOldFiles (void);

View File

@ -97,15 +97,16 @@ void Fir_PurgeFirewall (void)
void Fir_CheckFirewallAndExitIfBanned (void) void Fir_CheckFirewallAndExitIfBanned (void)
{ {
unsigned long NumCurrentBans; unsigned NumCurrentBans;
/***** Get number of current bans from database *****/ /***** Get number of current bans from database *****/
NumCurrentBans = DB_QueryCOUNT ("can not check firewall log", NumCurrentBans = (unsigned)
"SELECT COUNT(*)" DB_QueryCOUNT ("can not check firewall log",
" FROM fir_banned" "SELECT COUNT(*)"
" WHERE IP='%s'" " FROM fir_banned"
" AND UnbanTime>NOW()", " WHERE IP='%s'"
Gbl.IP); " AND UnbanTime>NOW()",
Gbl.IP);
/***** Exit with status 403 if banned *****/ /***** Exit with status 403 if banned *****/
/* RFC 6585 suggests "403 Forbidden", according to /* RFC 6585 suggests "403 Forbidden", according to
@ -130,16 +131,17 @@ void Fir_CheckFirewallAndExitIfBanned (void)
void Fir_CheckFirewallAndExitIfTooManyRequests (void) void Fir_CheckFirewallAndExitIfTooManyRequests (void)
{ {
unsigned long NumClicks; unsigned NumClicks;
/***** Get number of clicks from database *****/ /***** Get number of clicks from database *****/
NumClicks = DB_QueryCOUNT ("can not check firewall log", NumClicks = (unsigned)
"SELECT COUNT(*)" DB_QueryCOUNT ("can not check firewall log",
" FROM fir_log" "SELECT COUNT(*)"
" WHERE IP='%s'" " FROM fir_log"
" AND ClickTime>FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)", " WHERE IP='%s'"
Gbl.IP, " AND ClickTime>FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
Fw_CHECK_INTERVAL); Gbl.IP,
Fw_CHECK_INTERVAL);
/***** Exit with status 429 if too many connections *****/ /***** Exit with status 429 if too many connections *****/
/* RFC 6585 suggests "429 Too Many Requests", according to /* RFC 6585 suggests "429 Too Many Requests", according to

View File

@ -203,8 +203,8 @@ void Fol_SuggestUsrsToFollowMainZoneOnRightColumn (void)
extern const char *Txt_No_user_to_whom_you_can_follow_Try_again_later; extern const char *Txt_No_user_to_whom_you_can_follow_Try_again_later;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumUsrs; unsigned NumUsrs;
unsigned long NumUsr; unsigned NumUsr;
struct UsrData UsrDat; struct UsrData UsrDat;
/***** Get users *****/ /***** Get users *****/

View File

@ -933,7 +933,7 @@ static unsigned For_GetNumMyPstInThr (long ThrCod)
/*********************** Get number of posts from a user *********************/ /*********************** Get number of posts from a user *********************/
/*****************************************************************************/ /*****************************************************************************/
unsigned long For_GetNumPostsUsr (long UsrCod) unsigned For_GetNumPostsUsr (long UsrCod)
{ {
/***** Get number of posts from a user from database *****/ /***** Get number of posts from a user from database *****/
return DB_QueryCOUNT ("can not get number of forum posts from a user", return DB_QueryCOUNT ("can not get number of forum posts from a user",

View File

@ -122,7 +122,7 @@ void For_DisablePost (void);
void For_GetForumTypeAndLocationOfAPost (long PstCod,struct For_Forum *Forum); void For_GetForumTypeAndLocationOfAPost (long PstCod,struct For_Forum *Forum);
unsigned long For_GetNumPostsUsr (long UsrCod); unsigned For_GetNumPostsUsr (long UsrCod);
void For_RemoveUsrFromReadThrs (long UsrCod); void For_RemoveUsrFromReadThrs (long UsrCod);
void For_GetSummaryAndContentForumPst (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], void For_GetSummaryAndContentForumPst (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],

View File

@ -139,7 +139,7 @@ static unsigned Grp_CountNumGrpsInThisCrsOfType (long GrpTypCod);
static void Grp_GetDataOfGroupTypeByCod (struct GroupType *GrpTyp); static void Grp_GetDataOfGroupTypeByCod (struct GroupType *GrpTyp);
static bool Grp_GetMultipleEnrolmentOfAGroupType (long GrpTypCod); static bool Grp_GetMultipleEnrolmentOfAGroupType (long GrpTypCod);
static long Grp_GetTypeOfGroupOfAGroup (long GrpCod); static long Grp_GetTypeOfGroupOfAGroup (long GrpCod);
static unsigned long Grp_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod); static unsigned Grp_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod);
static bool Grp_CheckIfIBelongToGrpsOfType (long GrpTypCod); static bool Grp_CheckIfIBelongToGrpsOfType (long GrpTypCod);
static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,long UsrCod, static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,long UsrCod,
struct ListCodGrps *LstGrps); struct ListCodGrps *LstGrps);
@ -2369,7 +2369,7 @@ static void Grp_ListGrpsForMultipleSelection (struct GroupType *GrpTyp,
Role--) Role--)
{ {
HTM_TD_Begin ("class=\"DAT CM\""); HTM_TD_Begin ("class=\"DAT CM\"");
HTM_UnsignedLong (Grp_CountNumUsrsInNoGrpsOfType (Role,GrpTyp->GrpTypCod)); HTM_Unsigned (Grp_CountNumUsrsInNoGrpsOfType (Role,GrpTyp->GrpTypCod));
HTM_TD_End (); HTM_TD_End ();
} }
@ -3331,23 +3331,25 @@ unsigned Grp_CountNumUsrsInGrp (Rol_Role_t Role,long GrpCod)
/*** Count # of users of current course not belonging to groups of a type ****/ /*** Count # of users of current course not belonging to groups of a type ****/
/*****************************************************************************/ /*****************************************************************************/
static unsigned long Grp_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod) static unsigned Grp_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod)
{ {
/***** Get number of users not belonging to groups of a type ******/ /***** Get number of users not belonging to groups of a type ******/
return DB_QueryCOUNT ("can not get the number of users" return (unsigned)
" not belonging to groups of a type", DB_QueryCOUNT ("can not get the number of users"
"SELECT COUNT(UsrCod)" " not belonging to groups of a type",
" FROM crs_users" "SELECT COUNT(UsrCod)"
" WHERE CrsCod=%ld" " FROM crs_users"
" AND Role=%u" " WHERE CrsCod=%ld"
" AND UsrCod NOT IN" " AND Role=%u"
" (SELECT DISTINCT grp_users.UsrCod" " AND UsrCod NOT IN"
" FROM grp_groups," " (SELECT DISTINCT grp_users.UsrCod"
"grp_users" " FROM grp_groups,"
" WHERE grp_groups.GrpTypCod=%ld" "grp_users"
" AND grp_groups.GrpCod=grp_users.GrpCod)", " WHERE grp_groups.GrpTypCod=%ld"
Gbl.Hierarchy.Crs.CrsCod, " AND grp_groups.GrpCod=grp_users.GrpCod)",
(unsigned) Role,GrpTypCod); Gbl.Hierarchy.Crs.CrsCod,
(unsigned) Role,
GrpTypCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -375,8 +375,8 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing,long HighlightNotCod)
char StrWidth[Cns_MAX_DECIMAL_DIGITS_UINT + 2 + 1]; char StrWidth[Cns_MAX_DECIMAL_DIGITS_UINT + 2 + 1];
char PathRelRSSFile[PATH_MAX + 1]; char PathRelRSSFile[PATH_MAX + 1];
long NotCod; long NotCod;
unsigned long NumNot; unsigned NumNot;
unsigned long NumNotices = 0; // Initialized to avoid warning unsigned NumNotices = 0; // Initialized to avoid warning
char Content[Cns_MAX_BYTES_TEXT + 1]; char Content[Cns_MAX_BYTES_TEXT + 1];
time_t TimeUTC; time_t TimeUTC;
long UsrCod; long UsrCod;
@ -392,30 +392,32 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing,long HighlightNotCod)
switch (TypeNoticesListing) switch (TypeNoticesListing)
{ {
case Not_LIST_BRIEF_NOTICES: case Not_LIST_BRIEF_NOTICES:
NumNotices = DB_QuerySELECT (&mysql_res,"can not get notices from database", NumNotices = (unsigned)
"SELECT NotCod," // row[0] DB_QuerySELECT (&mysql_res,"can not get notices from database",
"UNIX_TIMESTAMP(CreatTime) AS F," // row[1] "SELECT NotCod," // row[0]
"UsrCod," // row[2] "UNIX_TIMESTAMP(CreatTime) AS F," // row[1]
"Content," // row[3] "UsrCod," // row[2]
"Status" // row[4] "Content," // row[3]
" FROM not_notices" "Status" // row[4]
" WHERE CrsCod=%ld" " FROM not_notices"
" AND Status=%u" " WHERE CrsCod=%ld"
" ORDER BY CreatTime DESC", " AND Status=%u"
Gbl.Hierarchy.Crs.CrsCod, " ORDER BY CreatTime DESC",
(unsigned) Not_ACTIVE_NOTICE); Gbl.Hierarchy.Crs.CrsCod,
(unsigned) Not_ACTIVE_NOTICE);
break; break;
case Not_LIST_FULL_NOTICES: case Not_LIST_FULL_NOTICES:
NumNotices = DB_QuerySELECT (&mysql_res,"can not get notices from database", NumNotices = (unsigned)
"SELECT NotCod," // row[0] DB_QuerySELECT (&mysql_res,"can not get notices from database",
"UNIX_TIMESTAMP(CreatTime) AS F," // row[1] "SELECT NotCod," // row[0]
"UsrCod," // row[2] "UNIX_TIMESTAMP(CreatTime) AS F," // row[1]
"Content," // row[3] "UsrCod," // row[2]
"Status" // row[4] "Content," // row[3]
" FROM not_notices" "Status" // row[4]
" WHERE CrsCod=%ld" " FROM not_notices"
" ORDER BY CreatTime DESC", " WHERE CrsCod=%ld"
Gbl.Hierarchy.Crs.CrsCod); " ORDER BY CreatTime DESC",
Gbl.Hierarchy.Crs.CrsCod);
break; break;
} }

View File

@ -319,8 +319,8 @@ void Ntf_ShowMyNotifications (void)
char SubQuery[128]; char SubQuery[128];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumNotif; unsigned NumNotif;
unsigned long NumNotifications; unsigned NumNotifications;
bool AllNotifications; bool AllNotifications;
Ntf_NotifyEvent_t NotifyEvent = (Ntf_NotifyEvent_t) 0; // Initialized to avoid warning Ntf_NotifyEvent_t NotifyEvent = (Ntf_NotifyEvent_t) 0; // Initialized to avoid warning
struct UsrData UsrDat; struct UsrData UsrDat;
@ -347,7 +347,7 @@ void Ntf_ShowMyNotifications (void)
sprintf (SubQuery," AND (Status&%u)=0", sprintf (SubQuery," AND (Status&%u)=0",
Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_READ |
Ntf_STATUS_BIT_REMOVED); Ntf_STATUS_BIT_REMOVED);
NumNotifications = NumNotifications = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get your notifications", DB_QuerySELECT (&mysql_res,"can not get your notifications",
"SELECT NotifyEvent," // row[0] "SELECT NotifyEvent," // row[0]
"FromUsrCod," // row[1] "FromUsrCod," // row[1]
@ -1192,8 +1192,8 @@ void Ntf_MarkNotifFilesInGroupAsRemoved (long GrpCod)
unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
unsigned long NumRow; unsigned NumUsrs = 0; // Initialized to avoid warning
unsigned long NumRows = 0; // Initialized to avoid warning unsigned NumUsr;
struct UsrData UsrDat; struct UsrData UsrDat;
struct For_Forum ForumSelected; struct For_Forum ForumSelected;
long InsCod; long InsCod;
@ -1217,56 +1217,56 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
case Brw_ADMI_DOC_CRS: case Brw_ADMI_DOC_CRS:
case Brw_ADMI_SHR_CRS: case Brw_ADMI_SHR_CRS:
case Brw_ADMI_MRK_CRS: // Notify all users in course except me case Brw_ADMI_MRK_CRS: // Notify all users in course except me
NumRows = DB_QuerySELECT (&mysql_res,"can not get users" NumUsrs = (unsigned)
" to be notified", DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod" // row[0] "SELECT UsrCod"
" FROM crs_users" " FROM crs_users"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND UsrCod<>%ld", " AND UsrCod<>%ld",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
break; break;
case Brw_ADMI_TCH_CRS: // Notify all teachers in course except me case Brw_ADMI_TCH_CRS: // Notify all teachers in course except me
NumRows = DB_QuerySELECT (&mysql_res,"can not get users" NumUsrs = (unsigned)
" to be notified", DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod" // row[0] "SELECT UsrCod"
" FROM crs_users" " FROM crs_users"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND UsrCod<>%ld" " AND UsrCod<>%ld"
" AND Role=%u", // Notify teachers only " AND Role=%u", // Notify teachers only
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH); (unsigned) Rol_TCH);
break; break;
case Brw_ADMI_DOC_GRP: case Brw_ADMI_DOC_GRP:
case Brw_ADMI_SHR_GRP: case Brw_ADMI_SHR_GRP:
case Brw_ADMI_MRK_GRP: // Notify all users in group except me case Brw_ADMI_MRK_GRP: // Notify all users in group except me
NumRows = DB_QuerySELECT (&mysql_res,"can not get users" NumUsrs = (unsigned)
" to be notified", DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod" // row[0] "SELECT UsrCod"
" FROM grp_users" " FROM grp_users"
" WHERE GrpCod=%ld" " WHERE GrpCod=%ld"
" AND UsrCod<>%ld", " AND UsrCod<>%ld",
Gbl.Crs.Grps.GrpCod, Gbl.Crs.Grps.GrpCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
break; break;
case Brw_ADMI_TCH_GRP: // Notify all teachers in group except me case Brw_ADMI_TCH_GRP: // Notify all teachers in group except me
NumRows = DB_QuerySELECT (&mysql_res,"can not get users" NumUsrs = (unsigned)
" to be notified", DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT grp_users.UsrCod" // row[0] "SELECT grp_users.UsrCod"
" FROM grp_users," " FROM grp_users,"
"grp_groups," "grp_groups,"
"grp_types," "grp_types,"
"crs_users" "crs_users"
" WHERE grp_users.GrpCod=%ld" " WHERE grp_users.GrpCod=%ld"
" AND grp_users.UsrCod<>%ld" " AND grp_users.UsrCod<>%ld"
" AND grp_users.GrpCod=grp_groups.GrpCod" " AND grp_users.GrpCod=grp_groups.GrpCod"
" AND grp_groups.GrpTypCod=grp_types.GrpTypCod" " AND grp_groups.GrpTypCod=grp_types.GrpTypCod"
" AND grp_types.CrsCod=crs_users.CrsCod" " AND grp_types.CrsCod=crs_users.CrsCod"
" AND crs_users.Role=%u", // Notify teachers only " AND crs_users.Role=%u", // Notify teachers only
Gbl.Crs.Grps.GrpCod, Gbl.Crs.Grps.GrpCod,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH); (unsigned) Rol_TCH);
break; break;
default: // This function should not be called in other cases default: // This function should not be called in other cases
return 0; return 0;
@ -1276,38 +1276,38 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
// 1. If the assignment is available for the whole course ==> get all users enroled in the course except me // 1. If the assignment is available for the whole course ==> get all users enroled in the course except me
// 2. If the assignment is available only for some groups ==> get all users who belong to any of the groups except me // 2. If the assignment is available only for some groups ==> get all users who belong to any of the groups except me
// Cases 1 and 2 are mutually exclusive, so the union returns the case 1 or 2 // Cases 1 and 2 are mutually exclusive, so the union returns the case 1 or 2
NumRows = DB_QuerySELECT (&mysql_res,"can not get users" NumUsrs = (unsigned)
" to be notified", DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"(SELECT crs_users.UsrCod" // row[0] "(SELECT crs_users.UsrCod"
" FROM asg_assignments," " FROM asg_assignments,"
"crs_users" "crs_users"
" WHERE asg_assignments.AsgCod=%ld" " WHERE asg_assignments.AsgCod=%ld"
" AND asg_assignments.AsgCod NOT IN" " AND asg_assignments.AsgCod NOT IN"
" (SELECT AsgCod" " (SELECT AsgCod"
" FROM asg_groups" " FROM asg_groups"
" WHERE AsgCod=%ld)" " WHERE AsgCod=%ld)"
" AND asg_assignments.CrsCod=crs_users.CrsCod" " AND asg_assignments.CrsCod=crs_users.CrsCod"
" AND crs_users.UsrCod<>%ld)" " AND crs_users.UsrCod<>%ld)"
" UNION " " UNION "
"(SELECT DISTINCT grp_users.UsrCod" "(SELECT DISTINCT grp_users.UsrCod"
" FROM asg_groups," " FROM asg_groups,"
"grp_users" "grp_users"
" WHERE asg_groups.AsgCod=%ld" " WHERE asg_groups.AsgCod=%ld"
" AND asg_groups.GrpCod=grp_users.GrpCod" " AND asg_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod<>%ld)", " AND grp_users.UsrCod<>%ld)",
Cod,Cod,Gbl.Usrs.Me.UsrDat.UsrCod, Cod,Cod,Gbl.Usrs.Me.UsrDat.UsrCod,
Cod,Gbl.Usrs.Me.UsrDat.UsrCod); Cod,Gbl.Usrs.Me.UsrDat.UsrCod);
break; break;
case Ntf_EVENT_CALL_FOR_EXAM: case Ntf_EVENT_CALL_FOR_EXAM:
case Ntf_EVENT_NOTICE: case Ntf_EVENT_NOTICE:
NumRows = DB_QuerySELECT (&mysql_res,"can not get users" NumUsrs = (unsigned)
" to be notified", DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod" // row[0] "SELECT UsrCod"
" FROM crs_users" " FROM crs_users"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND UsrCod<>%ld", " AND UsrCod<>%ld",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
break; break;
case Ntf_EVENT_ENROLMENT_STD: // This function should not be called in this case case Ntf_EVENT_ENROLMENT_STD: // This function should not be called in this case
case Ntf_EVENT_ENROLMENT_NET: // This function should not be called in this case case Ntf_EVENT_ENROLMENT_NET: // This function should not be called in this case
@ -1317,48 +1317,48 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
if (Usr_GetNumUsrsInCrss (Hie_Lvl_CRS,Gbl.Hierarchy.Crs.CrsCod, if (Usr_GetNumUsrsInCrss (Hie_Lvl_CRS,Gbl.Hierarchy.Crs.CrsCod,
1 << Rol_TCH)) 1 << Rol_TCH))
// If this course has teachers ==> send notification to teachers // If this course has teachers ==> send notification to teachers
NumRows = DB_QuerySELECT (&mysql_res,"can not get users" NumUsrs = (unsigned)
" to be notified", DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod" // row[0] "SELECT UsrCod"
" FROM crs_users" " FROM crs_users"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND UsrCod<>%ld" " AND UsrCod<>%ld"
" AND Role=%u", // Notify teachers only " AND Role=%u", // Notify teachers only
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH); (unsigned) Rol_TCH);
else // Course without teachers else // Course without teachers
// If this course has no teachers // If this course has no teachers
// and I want to be a teacher (checked before calling this function // and I want to be a teacher (checked before calling this function
// to not send requests to be a student to admins) // to not send requests to be a student to admins)
// ==> send notification to administrators or superusers // ==> send notification to administrators or superusers
NumRows = DB_QuerySELECT (&mysql_res,"can not get users" NumUsrs = (unsigned)
" to be notified", DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod" // row[0] "SELECT UsrCod"
" FROM usr_admins" " FROM usr_admins"
" WHERE (Scope='%s'" " WHERE (Scope='%s'"
" OR (Scope='%s' AND Cod=%ld)" " OR (Scope='%s' AND Cod=%ld)"
" OR (Scope='%s' AND Cod=%ld)" " OR (Scope='%s' AND Cod=%ld)"
" OR (Scope='%s' AND Cod=%ld))" " OR (Scope='%s' AND Cod=%ld))"
" AND UsrCod<>%ld", " AND UsrCod<>%ld",
Sco_GetDBStrFromScope (Hie_Lvl_SYS), Sco_GetDBStrFromScope (Hie_Lvl_SYS),
Sco_GetDBStrFromScope (Hie_Lvl_INS),Gbl.Hierarchy.Ins.InsCod, Sco_GetDBStrFromScope (Hie_Lvl_INS),Gbl.Hierarchy.Ins.InsCod,
Sco_GetDBStrFromScope (Hie_Lvl_CTR),Gbl.Hierarchy.Ctr.CtrCod, Sco_GetDBStrFromScope (Hie_Lvl_CTR),Gbl.Hierarchy.Ctr.CtrCod,
Sco_GetDBStrFromScope (Hie_Lvl_DEG),Gbl.Hierarchy.Deg.DegCod, Sco_GetDBStrFromScope (Hie_Lvl_DEG),Gbl.Hierarchy.Deg.DegCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
break; break;
case Ntf_EVENT_TL_COMMENT: // New comment to one of my social notes or comments case Ntf_EVENT_TL_COMMENT: // New comment to one of my social notes or comments
// Cod is the code of the social publishing // Cod is the code of the social publishing
NumRows = DB_QuerySELECT (&mysql_res,"can not get users" NumUsrs = (unsigned)
" to be notified", DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT DISTINCT(PublisherCod)" // row[0] "SELECT DISTINCT(PublisherCod)"
" FROM tml_pubs" " FROM tml_pubs"
" WHERE NotCod=(SELECT NotCod" " WHERE NotCod=(SELECT NotCod"
" FROM tml_pubs" " FROM tml_pubs"
" WHERE PubCod=%ld)" " WHERE PubCod=%ld)"
" AND PublisherCod<>%ld", " AND PublisherCod<>%ld",
Cod, Cod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
break; break;
case Ntf_EVENT_TL_FAV: // New favourite to one of my social notes or comments case Ntf_EVENT_TL_FAV: // New favourite to one of my social notes or comments
case Ntf_EVENT_TL_SHARE: // New sharing of one of my social notes case Ntf_EVENT_TL_SHARE: // New sharing of one of my social notes
@ -1373,42 +1373,42 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
switch (ForumSelected.Type) switch (ForumSelected.Type)
{ {
case For_FORUM_COURSE_USRS: case For_FORUM_COURSE_USRS:
NumRows = DB_QuerySELECT (&mysql_res,"can not get users" NumUsrs = (unsigned)
" to be notified", DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod" // row[0] "SELECT UsrCod"
" FROM crs_users" " FROM crs_users"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND UsrCod<>%ld", " AND UsrCod<>%ld",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
break; break;
case For_FORUM_COURSE_TCHS: case For_FORUM_COURSE_TCHS:
NumRows = DB_QuerySELECT (&mysql_res,"can not get users" NumUsrs = (unsigned)
" to be notified", DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT UsrCod" // row[0] "SELECT UsrCod"
" FROM crs_users" " FROM crs_users"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND Role=%u" " AND Role=%u"
" AND UsrCod<>%ld", " AND UsrCod<>%ld",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
(unsigned) Rol_TCH, (unsigned) Rol_TCH,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
break; break;
default: default:
return 0; return 0;
} }
break; break;
case Ntf_EVENT_FORUM_REPLY: case Ntf_EVENT_FORUM_REPLY:
NumRows = DB_QuerySELECT (&mysql_res,"can not get users" NumUsrs = (unsigned)
" to be notified", DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"SELECT DISTINCT(UsrCod)" // row[0] "SELECT DISTINCT(UsrCod)"
" FROM for_posts" " FROM for_posts"
" WHERE ThrCod=(SELECT ThrCod" " WHERE ThrCod=(SELECT ThrCod"
" FROM for_posts" " FROM for_posts"
" WHERE PstCod=%ld)" " WHERE PstCod=%ld)"
" AND UsrCod<>%ld", " AND UsrCod<>%ld",
Cod, Cod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
break; break;
case Ntf_EVENT_MESSAGE: // This function should not be called in this case case Ntf_EVENT_MESSAGE: // This function should not be called in this case
return 0; return 0;
@ -1416,41 +1416,41 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
// 1. If the survey is available for the whole course ==> get users enroled in the course whose role is available in survey, except me // 1. If the survey is available for the whole course ==> get users enroled in the course whose role is available in survey, except me
// 2. If the survey is available only for some groups ==> get users who belong to any of the groups and whose role is available in survey, except me // 2. If the survey is available only for some groups ==> get users who belong to any of the groups and whose role is available in survey, except me
// Cases 1 and 2 are mutually exclusive, so the union returns the case 1 or 2 // Cases 1 and 2 are mutually exclusive, so the union returns the case 1 or 2
NumRows = DB_QuerySELECT (&mysql_res,"can not get users" NumUsrs = (unsigned)
" to be notified", DB_QuerySELECT (&mysql_res,"can not get users to be notified",
"(SELECT crs_users.UsrCod" // row[0] "(SELECT crs_users.UsrCod"
" FROM svy_surveys," " FROM svy_surveys,"
"crs_users" "crs_users"
" WHERE svy_surveys.SvyCod=%ld" " WHERE svy_surveys.SvyCod=%ld"
" AND svy_surveys.SvyCod NOT IN" " AND svy_surveys.SvyCod NOT IN"
" (SELECT SvyCod" " (SELECT SvyCod"
" FROM svy_groups" " FROM svy_groups"
" WHERE SvyCod=%ld)" " WHERE SvyCod=%ld)"
" AND svy_surveys.Scope='%s'" " AND svy_surveys.Scope='%s'"
" AND svy_surveys.Cod=crs_users.CrsCod" " AND svy_surveys.Cod=crs_users.CrsCod"
" AND crs_users.UsrCod<>%ld" " AND crs_users.UsrCod<>%ld"
" AND (svy_surveys.Roles&(1<<crs_users.Role))<>0)" " AND (svy_surveys.Roles&(1<<crs_users.Role))<>0)"
" UNION " " UNION "
"(SELECT DISTINCT grp_users.UsrCod" "(SELECT DISTINCT grp_users.UsrCod"
" FROM svy_groups," " FROM svy_groups,"
"grp_users," "grp_users,"
"svy_surveys," "svy_surveys,"
"crs_users" "crs_users"
" WHERE svy_groups.SvyCod=%ld" " WHERE svy_groups.SvyCod=%ld"
" AND svy_groups.GrpCod=grp_users.GrpCod" " AND svy_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod=crs_users.UsrCod" " AND grp_users.UsrCod=crs_users.UsrCod"
" AND grp_users.UsrCod<>%ld" " AND grp_users.UsrCod<>%ld"
" AND svy_groups.SvyCod=svy_surveys.SvyCod" " AND svy_groups.SvyCod=svy_surveys.SvyCod"
" AND svy_surveys.Scope='%s'" " AND svy_surveys.Scope='%s'"
" AND svy_surveys.Cod=crs_users.CrsCod" " AND svy_surveys.Cod=crs_users.CrsCod"
" AND (svy_surveys.Roles&(1<<crs_users.Role))<>0)", " AND (svy_surveys.Roles&(1<<crs_users.Role))<>0)",
Cod, Cod,
Cod, Cod,
Sco_GetDBStrFromScope (Hie_Lvl_CRS), Sco_GetDBStrFromScope (Hie_Lvl_CRS),
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Cod, Cod,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Sco_GetDBStrFromScope (Hie_Lvl_CRS)); Sco_GetDBStrFromScope (Hie_Lvl_CRS));
break; break;
} }
@ -1488,15 +1488,15 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
CrsCod = Gbl.Hierarchy.Crs.CrsCod; CrsCod = Gbl.Hierarchy.Crs.CrsCod;
} }
if (NumRows) // Users found if (NumUsrs) // Users found
{ {
/***** Initialize structure with user's data *****/ /***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat); Usr_UsrDataConstructor (&UsrDat);
/***** Notify the users one by one *****/ /***** Notify the users one by one *****/
for (NumRow = 0; for (NumUsr = 0;
NumRow < NumRows; NumUsr < NumUsrs;
NumRow++) NumUsr++)
{ {
/* Get next user */ /* Get next user */
UsrDat.UsrCod = DB_GetNextCode (mysql_res); UsrDat.UsrCod = DB_GetNextCode (mysql_res);
@ -1569,8 +1569,8 @@ static void Ntf_UpdateMyLastAccessToNotifications (void)
void Ntf_SendPendingNotifByEMailToAllUsrs (void) void Ntf_SendPendingNotifByEMailToAllUsrs (void)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
unsigned long NumRows; unsigned NumUsrs;
unsigned long NumRow; unsigned NumUsr;
struct UsrData UsrDat; struct UsrData UsrDat;
unsigned NumNotif; unsigned NumNotif;
unsigned NumTotalNotif = 0; unsigned NumTotalNotif = 0;
@ -1581,26 +1581,26 @@ void Ntf_SendPendingNotifByEMailToAllUsrs (void)
// (Status & Ntf_STATUS_BIT_EMAIL) && // (Status & Ntf_STATUS_BIT_EMAIL) &&
// !(Status & Ntf_STATUS_BIT_SENT) && // !(Status & Ntf_STATUS_BIT_SENT) &&
// !(Status & (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)) // !(Status & (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED))
if ((NumRows = DB_QuerySELECT (&mysql_res,"can not get users" if ((NumUsrs = (unsigned)
" who must be notified", DB_QuerySELECT (&mysql_res,"can not get users who must be notified",
"SELECT DISTINCT ToUsrCod" "SELECT DISTINCT ToUsrCod"
" FROM ntf_notifications" " FROM ntf_notifications"
" WHERE TimeNotif<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)" " WHERE TimeNotif<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)"
" AND (Status & %u)<>0" " AND (Status & %u)<>0"
" AND (Status & %u)=0" " AND (Status & %u)=0"
" AND (Status & %u)=0", " AND (Status & %u)=0",
Cfg_TIME_TO_SEND_PENDING_NOTIF, Cfg_TIME_TO_SEND_PENDING_NOTIF,
(unsigned) Ntf_STATUS_BIT_EMAIL, (unsigned) Ntf_STATUS_BIT_EMAIL,
(unsigned) Ntf_STATUS_BIT_SENT, (unsigned) Ntf_STATUS_BIT_SENT,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)))) // Events found (unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)))) // Events found
{ {
/***** Initialize structure with user's data *****/ /***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat); Usr_UsrDataConstructor (&UsrDat);
/***** Notify the users one by one *****/ /***** Notify the users one by one *****/
for (NumRow = 0; for (NumUsr = 0;
NumRow < NumRows; NumUsr < NumUsrs;
NumRow++) NumUsr++)
{ {
/* Get next user */ /* Get next user */
UsrDat.UsrCod = DB_GetNextCode (mysql_res); UsrDat.UsrCod = DB_GetNextCode (mysql_res);
@ -1647,8 +1647,8 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct UsrData *ToUsrDat,unsign
extern const char *Txt_If_you_no_longer_wish_to_receive_email_notifications_NO_HTML[1 + Lan_NUM_LANGUAGES]; extern const char *Txt_If_you_no_longer_wish_to_receive_email_notifications_NO_HTML[1 + Lan_NUM_LANGUAGES];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRow; unsigned NumNots;
unsigned long NumRows; unsigned NumNot;
Lan_Language_t ToUsrLanguage; Lan_Language_t ToUsrLanguage;
struct UsrData FromUsrDat; struct UsrData FromUsrDat;
Ntf_NotifyEvent_t NotifyEvent = (Ntf_NotifyEvent_t) 0; // Initialized to avoid warning Ntf_NotifyEvent_t NotifyEvent = (Ntf_NotifyEvent_t) 0; // Initialized to avoid warning
@ -1670,28 +1670,29 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct UsrData *ToUsrDat,unsign
if (Mai_CheckIfUsrCanReceiveEmailNotif (ToUsrDat)) if (Mai_CheckIfUsrCanReceiveEmailNotif (ToUsrDat))
{ {
/***** Get pending notifications of this user from database ******/ /***** Get pending notifications of this user from database ******/
NumRows = DB_QuerySELECT (&mysql_res,"can not get pending notifications" NumNots = (unsigned)
" of a user", DB_QuerySELECT (&mysql_res,"can not get pending notifications"
"SELECT NotifyEvent," // row[0] " of a user",
"FromUsrCod," // row[1] "SELECT NotifyEvent," // row[0]
"InsCod," // row[2] "FromUsrCod," // row[1]
"CtrCod," // row[3] "InsCod," // row[2]
"DegCod," // row[4] "CtrCod," // row[3]
"CrsCod," // row[5] "DegCod," // row[4]
"Cod" // row[6] "CrsCod," // row[5]
" FROM ntf_notifications" "Cod" // row[6]
" WHERE ToUsrCod=%ld" " FROM ntf_notifications"
" AND (Status & %u)<>0" " WHERE ToUsrCod=%ld"
" AND (Status & %u)=0" " AND (Status & %u)<>0"
" AND (Status & %u)=0" " AND (Status & %u)=0"
" ORDER BY TimeNotif," " AND (Status & %u)=0"
"NotifyEvent", " ORDER BY TimeNotif,"
ToUsrDat->UsrCod, "NotifyEvent",
(unsigned) Ntf_STATUS_BIT_EMAIL, ToUsrDat->UsrCod,
(unsigned) Ntf_STATUS_BIT_SENT, (unsigned) Ntf_STATUS_BIT_EMAIL,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)); (unsigned) Ntf_STATUS_BIT_SENT,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED));
if (NumRows) // Events found if (NumNots) // Events found
{ {
/***** If user has no language, set it to current language *****/ /***** If user has no language, set it to current language *****/
ToUsrLanguage = ToUsrDat->Prefs.Language; ToUsrLanguage = ToUsrDat->Prefs.Language;
@ -1703,21 +1704,21 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct UsrData *ToUsrDat,unsign
/***** Welcome note *****/ /***** Welcome note *****/
Mai_WriteWelcomeNoteEMail (FileMail,ToUsrDat); Mai_WriteWelcomeNoteEMail (FileMail,ToUsrDat);
if (NumRows == 1) if (NumNots == 1)
fprintf (FileMail,Txt_NOTIFY_EVENTS_There_is_a_new_event_NO_HTML[ToUsrLanguage], fprintf (FileMail,Txt_NOTIFY_EVENTS_There_is_a_new_event_NO_HTML[ToUsrLanguage],
Cfg_PLATFORM_SHORT_NAME); Cfg_PLATFORM_SHORT_NAME);
else else
fprintf (FileMail,Txt_NOTIFY_EVENTS_There_are_X_new_events_NO_HTML[ToUsrLanguage], fprintf (FileMail,Txt_NOTIFY_EVENTS_There_are_X_new_events_NO_HTML[ToUsrLanguage],
(unsigned) NumRows,Cfg_PLATFORM_SHORT_NAME); (unsigned) NumNots,Cfg_PLATFORM_SHORT_NAME);
fprintf (FileMail,": \n"); fprintf (FileMail,": \n");
/***** Initialize structure with origin user's data *****/ /***** Initialize structure with origin user's data *****/
Usr_UsrDataConstructor (&FromUsrDat); Usr_UsrDataConstructor (&FromUsrDat);
/***** Inform about the events one by one *****/ /***** Inform about the events one by one *****/
for (NumRow = 0; for (NumNot = 0;
NumRow < NumRows; NumNot < NumNots;
NumRow++) NumNot++)
{ {
/* Get next event */ /* Get next event */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1843,7 +1844,7 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct UsrData *ToUsrDat,unsign
ReturnCode = WEXITSTATUS(ReturnCode); ReturnCode = WEXITSTATUS(ReturnCode);
if (ReturnCode == 0) // Message sent successfully if (ReturnCode == 0) // Message sent successfully
{ {
*NumNotif = (unsigned) NumRows; *NumNotif = NumNots;
*NumMails = 1; *NumMails = 1;
/* Update statistics about notifications */ /* Update statistics about notifications */
@ -1895,23 +1896,19 @@ static void Ntf_GetNumNotifSent (long DegCod,long CrsCod,
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
/***** Get number of notifications sent by email from database *****/ /***** Get number of notifications sent by email from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get number of notifications" if (DB_QuerySELECT (&mysql_res,"can not get number of notifications"
" sent by email", " sent by email",
"SELECT NumEvents," // row[0] "SELECT NumEvents," // row[0]
"NumMails" // row[1] "NumMails" // row[1]
" FROM sta_notifications" " FROM sta_notifications"
" WHERE DegCod=%ld" " WHERE DegCod=%ld"
" AND CrsCod=%ld" " AND CrsCod=%ld"
" AND NotifyEvent=%u", " AND NotifyEvent=%u",
DegCod, DegCod,
CrsCod, CrsCod,
(unsigned) NotifyEvent); (unsigned) NotifyEvent))
/***** Get number of rows *****/
if (NumRows)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",NumEvents) != 1) if (sscanf (row[0],"%u",NumEvents) != 1)

View File

@ -945,20 +945,16 @@ unsigned Pag_GetLastPageMsgFromSession (Pag_WhatPaginate_t WhatPaginate)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
unsigned NumPage; unsigned NumPage;
/***** Get last page of received/sent messages from database *****/ /***** Get last page of received/sent messages from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get last page of messages", if (DB_QuerySELECT (&mysql_res,"can not get last page of messages",
"SELECT %s" // row[0] "SELECT %s" // row[0]
" FROM ses_sessions" " FROM ses_sessions"
" WHERE SessionId='%s'", " WHERE SessionId='%s'",
WhatPaginate == Pag_MESSAGES_RECEIVED ? "LastPageMsgRcv" : WhatPaginate == Pag_MESSAGES_RECEIVED ? "LastPageMsgRcv" :
"LastPageMsgSnt", "LastPageMsgSnt",
Gbl.Session.Id); Gbl.Session.Id))
/***** Check number of rows of the result ****/
if (NumRows != 1)
Lay_ShowErrorAndExit ("Error when getting last page of messages."); Lay_ShowErrorAndExit ("Error when getting last page of messages.");
/***** Get last page of messages *****/ /***** Get last page of messages *****/

View File

@ -926,19 +926,15 @@ unsigned Pho_UpdateMyClicksWithoutPhoto (void)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
unsigned NumClicks; unsigned NumClicks;
/***** Get number of clicks without photo from database *****/ /***** Get number of clicks without photo from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get number of clicks" if (DB_QuerySELECT (&mysql_res,"can not get number of clicks"
" without photo", " without photo",
"SELECT NumClicks" // row[0] "SELECT NumClicks" // row[0]
" FROM pho_clicks_without_photo" " FROM pho_clicks_without_photo"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod)) // The user exists ==> update number of clicks without photo
/***** Update the list of clicks without photo *****/
if (NumRows) // The user exists ==> update number of clicks without photo
{ {
/* Get current number of clicks */ /* Get current number of clicks */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -955,7 +951,7 @@ unsigned Pho_UpdateMyClicksWithoutPhoto (void)
NumClicks++; NumClicks++;
} }
} }
else // The user does not exist ==> add him/her else // The user does not exist ==> add him/her
{ {
/* Add the user, with one access */ /* Add the user, with one access */
DB_QueryINSERT ("can not create number of clicks without photo", DB_QueryINSERT ("can not create number of clicks without photo",
@ -1479,18 +1475,15 @@ static long Pho_GetTimeAvgPhotoWasComputed (long DegCod)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
long TimeAvgPhotoWasComputed = 0L; long TimeAvgPhotoWasComputed = 0L;
/***** Get last time an average photo was computed from database *****/ /***** Get last time an average photo was computed from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get last time" if (DB_QuerySELECT (&mysql_res,"can not get last time"
" an average photo was computed", " an average photo was computed",
"SELECT MIN(UNIX_TIMESTAMP(TimeAvgPhoto))" // row[0] "SELECT MIN(UNIX_TIMESTAMP(TimeAvgPhoto))" // row[0]
" FROM sta_degrees" " FROM sta_degrees"
" WHERE DegCod=%ld", " WHERE DegCod=%ld",
DegCod); DegCod) == 1)
if (NumRows == 1)
{ {
/***** Get row *****/ /***** Get row *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1514,21 +1507,16 @@ static long Pho_GetTimeToComputeAvgPhoto (long DegCod)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
Usr_Sex_t Sex; Usr_Sex_t Sex;
long PartialTimeToComputeAvgPhoto; long PartialTimeToComputeAvgPhoto;
long TotalTimeToComputeAvgPhoto = -1L; long TotalTimeToComputeAvgPhoto = -1L;
/***** Get time to compute average photo from database *****/ /***** Get time to compute average photo from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get time to compute" if (DB_QuerySELECT (&mysql_res,"can not get time to compute average photo",
" average photo", "SELECT TimeToComputeAvgPhoto" // row[0]
"SELECT TimeToComputeAvgPhoto" // row[0] " FROM sta_degrees"
" FROM sta_degrees" " WHERE DegCod=%ld",
" WHERE DegCod=%ld", DegCod) == Usr_NUM_SEXS)
DegCod);
/***** Count number of rows in result *****/
if (NumRows == Usr_NUM_SEXS)
{ {
TotalTimeToComputeAvgPhoto = 0; TotalTimeToComputeAvgPhoto = 0;
for (Sex = (Usr_Sex_t) 0; for (Sex = (Usr_Sex_t) 0;
@ -2063,20 +2051,16 @@ static void Pho_GetMaxStdsPerDegree (struct Pho_DegPhotos *DegPhotos)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
/***** Get maximum number of students in a degree from database *****/ /***** Get maximum number of students in a degree from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get maximum" if (DB_QuerySELECT (&mysql_res,"can not get maximum"
" number of students in a degree", " number of students in a degree",
"SELECT MAX(NumStds)," // row[0] "SELECT MAX(NumStds)," // row[0]
"MAX(NumStdsWithPhoto)," // row[1] "MAX(NumStdsWithPhoto)," // row[1]
"MAX(NumStdsWithPhoto/NumStds)" // row[2] "MAX(NumStdsWithPhoto/NumStds)" // row[2]
" FROM sta_degrees" " FROM sta_degrees"
" WHERE Sex='all'" " WHERE Sex='all'"
" AND NumStds>0"); " AND NumStds>0") == 1)
/***** Count number of rows in result *****/
if (NumRows == 1)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -2296,55 +2280,53 @@ static void Pho_ShowOrPrintListDegrees (struct Pho_DegPhotos *DegPhotos,
static unsigned long Pho_QueryDegrees (Pho_HowOrderDegrees_t HowOrderDegrees, static unsigned long Pho_QueryDegrees (Pho_HowOrderDegrees_t HowOrderDegrees,
MYSQL_RES **mysql_res) MYSQL_RES **mysql_res)
{ {
unsigned long NumDegs = 0; // Initialized to avoid warning
switch (HowOrderDegrees) switch (HowOrderDegrees)
{ {
case Pho_NUMBER_OF_STUDENTS: case Pho_NUMBER_OF_STUDENTS:
NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees", return (unsigned)
"SELECT deg_degrees.DegCod" DB_QuerySELECT (mysql_res,"can not get degrees",
" FROM deg_degrees,sta_degrees" "SELECT deg_degrees.DegCod"
" WHERE sta_degrees.Sex='all'" " FROM deg_degrees,sta_degrees"
" AND sta_degrees.NumStds>0" " WHERE sta_degrees.Sex='all'"
" AND deg_degrees.DegCod=sta_degrees.DegCod" " AND sta_degrees.NumStds>0"
" ORDER BY sta_degrees.NumStds DESC," " AND deg_degrees.DegCod=sta_degrees.DegCod"
"sta_degrees.NumStdsWithPhoto DESC," " ORDER BY sta_degrees.NumStds DESC,"
"deg_degrees.ShortName"); "sta_degrees.NumStdsWithPhoto DESC,"
break; "deg_degrees.ShortName");
case Pho_NUMBER_OF_PHOTOS: case Pho_NUMBER_OF_PHOTOS:
NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees", return (unsigned)
"SELECT deg_degrees.DegCod" DB_QuerySELECT (mysql_res,"can not get degrees",
" FROM deg_degrees,sta_degrees" "SELECT deg_degrees.DegCod"
" WHERE sta_degrees.Sex='all'" " FROM deg_degrees,sta_degrees"
" AND sta_degrees.NumStds>0" " WHERE sta_degrees.Sex='all'"
" AND deg_degrees.DegCod=sta_degrees.DegCod" " AND sta_degrees.NumStds>0"
" ORDER BY sta_degrees.NumStdsWithPhoto DESC," " AND deg_degrees.DegCod=sta_degrees.DegCod"
"sta_degrees.NumStds DESC," " ORDER BY sta_degrees.NumStdsWithPhoto DESC,"
"deg_degrees.ShortName"); "sta_degrees.NumStds DESC,"
break; "deg_degrees.ShortName");
case Pho_PERCENT: case Pho_PERCENT:
NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees", return (unsigned)
"SELECT deg_degrees.DegCod" DB_QuerySELECT (mysql_res,"can not get degrees",
" FROM deg_degrees,sta_degrees" "SELECT deg_degrees.DegCod"
" WHERE sta_degrees.Sex='all'" " FROM deg_degrees,sta_degrees"
" AND sta_degrees.NumStds>0" " WHERE sta_degrees.Sex='all'"
" AND deg_degrees.DegCod=sta_degrees.DegCod" " AND sta_degrees.NumStds>0"
" ORDER BY sta_degrees.NumStdsWithPhoto/" " AND deg_degrees.DegCod=sta_degrees.DegCod"
"sta_degrees.NumStds DESC," " ORDER BY sta_degrees.NumStdsWithPhoto/"
"deg_degrees.ShortName"); "sta_degrees.NumStds DESC,"
break; "deg_degrees.ShortName");
case Pho_DEGREE_NAME: case Pho_DEGREE_NAME:
NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees", return (unsigned)
"SELECT deg_degrees.DegCod" DB_QuerySELECT (mysql_res,"can not get degrees",
" FROM deg_degrees,sta_degrees" "SELECT deg_degrees.DegCod"
" WHERE sta_degrees.Sex='all'" " FROM deg_degrees,sta_degrees"
" AND sta_degrees.NumStds>0" " WHERE sta_degrees.Sex='all'"
" AND deg_degrees.DegCod=sta_degrees.DegCod" " AND sta_degrees.NumStds>0"
" ORDER BY deg_degrees.ShortName"); " AND deg_degrees.DegCod=sta_degrees.DegCod"
break; " ORDER BY deg_degrees.ShortName");
} }
return NumDegs; return 0;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2356,20 +2338,17 @@ static void Pho_GetNumStdsInDegree (long DegCod,Usr_Sex_t Sex,int *NumStds,int *
extern const char *Usr_StringsSexDB[Usr_NUM_SEXS]; extern const char *Usr_StringsSexDB[Usr_NUM_SEXS];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
/***** Get the number of students in a degree from database *****/ /***** Get the number of students in a degree from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get the number of students" if (DB_QuerySELECT (&mysql_res,"can not get the number of students"
" in a degree", " in a degree",
"SELECT NumStds," // row[0] "SELECT NumStds," // row[0]
"NumStdsWithPhoto" // row[1] "NumStdsWithPhoto" // row[1]
" FROM sta_degrees" " FROM sta_degrees"
" WHERE DegCod=%ld" " WHERE DegCod=%ld"
" AND Sex='%s'", " AND Sex='%s'",
DegCod, DegCod,
Usr_StringsSexDB[Sex]); Usr_StringsSexDB[Sex]) == 0)
if (NumRows == 0)
*NumStds = *NumStdsWithPhoto = -1; *NumStds = *NumStdsWithPhoto = -1;
else else
{ {

View File

@ -359,47 +359,46 @@ void Plc_GetListPlaces (struct Plc_Places *Places)
}; };
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
unsigned NumPlc; unsigned NumPlc;
struct Plc_Place *Plc; struct Plc_Place *Plc;
/***** Get places from database *****/ /***** Get places from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get places", Places->Num = (unsigned)
"(SELECT plc_places.PlcCod," // row[0] DB_QuerySELECT (&mysql_res,"can not get places",
"plc_places.ShortName," // row[1] "(SELECT plc_places.PlcCod," // row[0]
"plc_places.FullName," // row[2] "plc_places.ShortName," // row[1]
"COUNT(*) AS NumCtrs" // row[3] "plc_places.FullName," // row[2]
" FROM plc_places," "COUNT(*) AS NumCtrs" // row[3]
"ctr_centers" " FROM plc_places,"
" WHERE plc_places.InsCod=%ld" "ctr_centers"
" AND plc_places.PlcCod=ctr_centers.PlcCod" " WHERE plc_places.InsCod=%ld"
" AND ctr_centers.InsCod=%ld" " AND plc_places.PlcCod=ctr_centers.PlcCod"
" GROUP BY plc_places.PlcCod)" " AND ctr_centers.InsCod=%ld"
" UNION " " GROUP BY plc_places.PlcCod)"
"(SELECT PlcCod," " UNION "
"ShortName," "(SELECT PlcCod,"
"FullName," "ShortName,"
"0 AS NumCtrs" "FullName,"
" FROM plc_places" "0 AS NumCtrs"
" WHERE InsCod=%ld" " FROM plc_places"
" AND PlcCod NOT IN" " WHERE InsCod=%ld"
" (SELECT DISTINCT PlcCod" " AND PlcCod NOT IN"
" FROM ctr_centers" " (SELECT DISTINCT PlcCod"
" WHERE InsCod=%ld))" " FROM ctr_centers"
" ORDER BY %s", " WHERE InsCod=%ld))"
Gbl.Hierarchy.Ins.InsCod, " ORDER BY %s",
Gbl.Hierarchy.Ins.InsCod, Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ins.InsCod, Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ins.InsCod, Gbl.Hierarchy.Ins.InsCod,
OrderBySubQuery[Places->SelectedOrder]); Gbl.Hierarchy.Ins.InsCod,
OrderBySubQuery[Places->SelectedOrder]);
/***** Count number of rows in result *****/ /***** Count number of rows in result *****/
if (NumRows) // Places found... if (Places->Num) // Places found...
{ {
Places->Num = (unsigned) NumRows;
/***** Create list with courses in center *****/ /***** Create list with courses in center *****/
if ((Places->Lst = calloc (NumRows,sizeof (*Places->Lst))) == NULL) if ((Places->Lst = calloc ((size_t) Places->Num,
sizeof (*Places->Lst))) == NULL)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
/***** Get the places *****/ /***** Get the places *****/
@ -425,8 +424,6 @@ void Plc_GetListPlaces (struct Plc_Places *Places)
Plc->NumCtrs = 0; Plc->NumCtrs = 0;
} }
} }
else
Places->Num = 0;
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
@ -442,7 +439,6 @@ void Plc_GetDataOfPlaceByCod (struct Plc_Place *Plc)
extern const char *Txt_Another_place; extern const char *Txt_Another_place;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
/***** Clear data *****/ /***** Clear data *****/
Plc->ShrtName[0] = '\0'; Plc->ShrtName[0] = '\0';
@ -463,31 +459,28 @@ void Plc_GetDataOfPlaceByCod (struct Plc_Place *Plc)
else if (Plc->PlcCod > 0) else if (Plc->PlcCod > 0)
{ {
/***** Get data of a place from database *****/ /***** Get data of a place from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a place", if (DB_QuerySELECT (&mysql_res,"can not get data of a place",
"(SELECT plc_places.ShortName," // row[0] "(SELECT plc_places.ShortName," // row[0]
"plc_places.FullName," // row[1] "plc_places.FullName," // row[1]
"COUNT(*)" // row[2] "COUNT(*)" // row[2]
" FROM plc_places," " FROM plc_places,"
"ctr_centers" "ctr_centers"
" WHERE plc_places.PlcCod=%ld" " WHERE plc_places.PlcCod=%ld"
" AND plc_places.PlcCod=ctr_centers.PlcCod" " AND plc_places.PlcCod=ctr_centers.PlcCod"
" AND ctr_centers.PlcCod=%ld" " AND ctr_centers.PlcCod=%ld"
" GROUP BY plc_places.PlcCod)" " GROUP BY plc_places.PlcCod)"
" UNION " " UNION "
"(SELECT ShortName," // row[0] "(SELECT ShortName," // row[0]
"FullName," // row[1] "FullName," // row[1]
"0" // row[2] "0" // row[2]
" FROM plc_places" " FROM plc_places"
" WHERE PlcCod=%ld" " WHERE PlcCod=%ld"
" AND PlcCod NOT IN" " AND PlcCod NOT IN"
" (SELECT DISTINCT PlcCod" " (SELECT DISTINCT PlcCod"
" FROM ctr_centers))", " FROM ctr_centers))",
Plc->PlcCod, Plc->PlcCod,
Plc->PlcCod, Plc->PlcCod,
Plc->PlcCod); Plc->PlcCod)) // Place found...
/***** Count number of rows in result *****/
if (NumRows) // Place found...
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);

View File

@ -225,29 +225,27 @@ static void Plg_GetListPlugins (void)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
unsigned NumPlg; unsigned NumPlg;
struct Plugin *Plg; struct Plugin *Plg;
/***** Get plugins from database *****/ /***** Get plugins from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get plugins", Gbl.Plugins.Num = (unsigned)
"SELECT PlgCod," // row[0] DB_QuerySELECT (&mysql_res,"can not get plugins",
"Name," // row[1] "SELECT PlgCod," // row[0]
"Description," // row[2] "Name," // row[1]
"Logo," // row[3] "Description," // row[2]
"AppKey," // row[4] "Logo," // row[3]
"URL," // row[5] "AppKey," // row[4]
"IP" // row[6] "URL," // row[5]
" FROM plg_plugins" "IP" // row[6]
" ORDER BY Name"); " FROM plg_plugins"
" ORDER BY Name");
/***** Count number of rows in result *****/ /***** Count number of rows in result *****/
if (NumRows) // Plugins found... if (Gbl.Plugins.Num) // Plugins found...
{ {
Gbl.Plugins.Num = (unsigned) NumRows;
/***** Create list with plugins *****/ /***** Create list with plugins *****/
if ((Gbl.Plugins.Lst = calloc (Gbl.Plugins.Num, if ((Gbl.Plugins.Lst = calloc ((size_t) Gbl.Plugins.Num,
sizeof (*Gbl.Plugins.Lst))) == NULL) sizeof (*Gbl.Plugins.Lst))) == NULL)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
@ -275,8 +273,6 @@ static void Plg_GetListPlugins (void)
Str_Copy (Plg->IP ,row[6],sizeof (Plg->IP ) - 1); Str_Copy (Plg->IP ,row[6],sizeof (Plg->IP ) - 1);
} }
} }
else
Gbl.Plugins.Num = 0;
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
@ -290,7 +286,6 @@ bool Plg_GetDataOfPluginByCod (struct Plugin *Plg)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
bool PluginFound; bool PluginFound;
/***** Clear data *****/ /***** Clear data *****/
@ -306,19 +301,16 @@ bool Plg_GetDataOfPluginByCod (struct Plugin *Plg)
// Plg->PlgCod > 0 // Plg->PlgCod > 0
/***** Get data of a plugin from database *****/ /***** Get data of a plugin from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a plugin", if (DB_QuerySELECT (&mysql_res,"can not get data of a plugin",
"SELECT Name," // row[0] "SELECT Name," // row[0]
"Description," // row[1] "Description," // row[1]
"Logo," // row[2] "Logo," // row[2]
"AppKey," // row[3] "AppKey," // row[3]
"URL," // row[4] "URL," // row[4]
"IP" // row[5] "IP" // row[5]
" FROM plg_plugins" " FROM plg_plugins"
" WHERE PlgCod=%ld", " WHERE PlgCod=%ld",
Plg->PlgCod); Plg->PlgCod)) // Plugin found...
/***** Count number of rows in result *****/
if (NumRows) // Plugin found...
{ {
PluginFound = true; PluginFound = true;

View File

@ -101,11 +101,11 @@ static void Prf_StartListItem (const char *Title,const char *Icon);
static void Prf_EndListItem (void); static void Prf_EndListItem (void);
static void Prf_PutLinkCalculateFigures (const char *EncryptedUsrCod); static void Prf_PutLinkCalculateFigures (const char *EncryptedUsrCod);
static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName); static unsigned Prf_GetRankingFigure (long UsrCod,const char *FieldName);
static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName); static unsigned Prf_GetNumUsrsWithFigure (const char *FieldName);
static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod); static unsigned Prf_GetRankingNumClicksPerDay (long UsrCod);
static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void); static unsigned Prf_GetNumUsrsWithNumClicksPerDay (void);
static void Prf_ShowRanking (unsigned long Rank,unsigned long NumUsrs); static void Prf_ShowRanking (unsigned Rank,unsigned NumUsrs);
static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod); static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod);
static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod); static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod);
@ -613,7 +613,7 @@ static void Prf_ShowNumClicks (const struct UsrData *UsrDat,
{ {
HTM_TxtF ("&nbsp;%s","("); HTM_TxtF ("&nbsp;%s","(");
HTM_DoubleFewDigits ((double) UsrFigures->NumClicks / HTM_DoubleFewDigits ((double) UsrFigures->NumClicks /
(double) UsrFigures->NumDays); (double) UsrFigures->NumDays);
HTM_TxtF ("/%s&nbsp;",Txt_day); HTM_TxtF ("/%s&nbsp;",Txt_day);
Prf_ShowRanking (Prf_GetRankingNumClicksPerDay (UsrDat->UsrCod), Prf_ShowRanking (Prf_GetRankingNumClicksPerDay (UsrDat->UsrCod),
Prf_GetNumUsrsWithNumClicksPerDay ()); Prf_GetNumUsrsWithNumClicksPerDay ());
@ -646,14 +646,14 @@ static void Prf_ShowNumFileViews (const struct UsrData *UsrDat,
{ {
HTM_Long (UsrFigures->NumFileViews); HTM_Long (UsrFigures->NumFileViews);
HTM_TxtF ("&nbsp;%s&nbsp;",(UsrFigures->NumFileViews == 1) ? Txt_download : HTM_TxtF ("&nbsp;%s&nbsp;",(UsrFigures->NumFileViews == 1) ? Txt_download :
Txt_downloads); Txt_downloads);
Prf_ShowRanking (Prf_GetRankingFigure (UsrDat->UsrCod,"NumFileViews"), Prf_ShowRanking (Prf_GetRankingFigure (UsrDat->UsrCod,"NumFileViews"),
Prf_GetNumUsrsWithFigure ("NumFileViews")); Prf_GetNumUsrsWithFigure ("NumFileViews"));
if (UsrFigures->NumDays > 0) if (UsrFigures->NumDays > 0)
{ {
HTM_TxtF ("&nbsp;%s","("); HTM_TxtF ("&nbsp;%s","(");
HTM_DoubleFewDigits ((double) UsrFigures->NumFileViews / HTM_DoubleFewDigits ((double) UsrFigures->NumFileViews /
(double) UsrFigures->NumDays); (double) UsrFigures->NumDays);
HTM_TxtF ("/%s)",Txt_day); HTM_TxtF ("/%s)",Txt_day);
} }
} }
@ -681,7 +681,7 @@ static void Prf_ShowNumSocialPublications (const struct UsrData *UsrDat,
if (UsrFigures->NumSocPub >= 0) if (UsrFigures->NumSocPub >= 0)
{ {
HTM_Long (UsrFigures->NumSocPub); HTM_Int (UsrFigures->NumSocPub);
HTM_TxtF ("&nbsp;%s&nbsp;",UsrFigures->NumSocPub == 1 ? Txt_TIMELINE_post : HTM_TxtF ("&nbsp;%s&nbsp;",UsrFigures->NumSocPub == 1 ? Txt_TIMELINE_post :
Txt_TIMELINE_posts); Txt_TIMELINE_posts);
Prf_ShowRanking (Prf_GetRankingFigure (UsrDat->UsrCod,"NumSocPub"), Prf_ShowRanking (Prf_GetRankingFigure (UsrDat->UsrCod,"NumSocPub"),
@ -690,7 +690,7 @@ static void Prf_ShowNumSocialPublications (const struct UsrData *UsrDat,
{ {
HTM_TxtF ("&nbsp;%s","("); HTM_TxtF ("&nbsp;%s","(");
HTM_DoubleFewDigits ((double) UsrFigures->NumSocPub / HTM_DoubleFewDigits ((double) UsrFigures->NumSocPub /
(double) UsrFigures->NumDays); (double) UsrFigures->NumDays);
HTM_TxtF ("/%s)",Txt_day); HTM_TxtF ("/%s)",Txt_day);
} }
} }
@ -727,7 +727,7 @@ static void Prf_ShowNumForumPosts (const struct UsrData *UsrDat,
{ {
HTM_TxtF ("&nbsp;%s","("); HTM_TxtF ("&nbsp;%s","(");
HTM_DoubleFewDigits ((double) UsrFigures->NumForPst / HTM_DoubleFewDigits ((double) UsrFigures->NumForPst /
(double) UsrFigures->NumDays); (double) UsrFigures->NumDays);
HTM_TxtF ("/%s)",Txt_day); HTM_TxtF ("/%s)",Txt_day);
} }
} }
@ -764,7 +764,7 @@ static void Prf_ShowNumMessagesSent (const struct UsrData *UsrDat,
{ {
HTM_TxtF ("&nbsp;%s","("); HTM_TxtF ("&nbsp;%s","(");
HTM_DoubleFewDigits ((double) UsrFigures->NumMsgSnt / HTM_DoubleFewDigits ((double) UsrFigures->NumMsgSnt /
(double) UsrFigures->NumDays); (double) UsrFigures->NumDays);
HTM_TxtF ("/%s)",Txt_day); HTM_TxtF ("/%s)",Txt_day);
} }
} }
@ -852,24 +852,24 @@ void Prf_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
UsrFigures->NumDays = -1; UsrFigures->NumDays = -1;
/* Get number of clicks (row[2]) */ /* Get number of clicks (row[2]) */
if (sscanf (row[2],"%ld",&UsrFigures->NumClicks) != 1) if (sscanf (row[2],"%d",&UsrFigures->NumClicks) != 1)
UsrFigures->NumClicks = -1L; UsrFigures->NumClicks = -1;
/* Get number of social publications (row[3]) */ /* Get number of social publications (row[3]) */
if (sscanf (row[3],"%ld",&UsrFigures->NumSocPub) != 1) if (sscanf (row[3],"%d",&UsrFigures->NumSocPub) != 1)
UsrFigures->NumSocPub = -1L; UsrFigures->NumSocPub = -1;
/* Get number of file views (row[4]) */ /* Get number of file views (row[4]) */
if (sscanf (row[4],"%ld",&UsrFigures->NumFileViews) != 1) if (sscanf (row[4],"%d",&UsrFigures->NumFileViews) != 1)
UsrFigures->NumFileViews = -1L; UsrFigures->NumFileViews = -1;
/* Get number of forum posts (row[5]) */ /* Get number of forum posts (row[5]) */
if (sscanf (row[5],"%ld",&UsrFigures->NumForPst) != 1) if (sscanf (row[5],"%d",&UsrFigures->NumForPst) != 1)
UsrFigures->NumForPst = -1L; UsrFigures->NumForPst = -1;
/* Get number of messages sent (row[6]) */ /* Get number of messages sent (row[6]) */
if (sscanf (row[6],"%ld",&UsrFigures->NumMsgSnt) != 1) if (sscanf (row[6],"%d",&UsrFigures->NumMsgSnt) != 1)
UsrFigures->NumMsgSnt = -1L; UsrFigures->NumMsgSnt = -1;
} }
else else
/***** Return special user's figures indicating "not present" *****/ /***** Return special user's figures indicating "not present" *****/
@ -883,78 +883,85 @@ void Prf_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
/********** Get ranking of a user according to the number of clicks **********/ /********** Get ranking of a user according to the number of clicks **********/
/*****************************************************************************/ /*****************************************************************************/
static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName) static unsigned Prf_GetRankingFigure (long UsrCod,const char *FieldName)
{ {
/***** Select number of rows with figure /***** Select number of rows with figure
greater than the figure of this user *****/ greater than the figure of this user *****/
return DB_QueryCOUNT ("can not get ranking using a figure", return (unsigned)
"SELECT COUNT(*)+1" DB_QueryCOUNT ("can not get ranking using a figure",
" FROM usr_figures" "SELECT COUNT(*)+1"
" WHERE UsrCod<>%ld" // Really not necessary here " FROM usr_figures"
" AND %s>(SELECT %s" " WHERE UsrCod<>%ld" // Really not necessary here
" FROM usr_figures" " AND %s>(SELECT %s"
" WHERE UsrCod=%ld)", " FROM usr_figures"
UsrCod,FieldName,FieldName,UsrCod); " WHERE UsrCod=%ld)",
UsrCod,
FieldName,
FieldName,
UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
/********************* Get number of users with a figure *********************/ /********************* Get number of users with a figure *********************/
/*****************************************************************************/ /*****************************************************************************/
static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName) static unsigned Prf_GetNumUsrsWithFigure (const char *FieldName)
{ {
/***** Select number of rows with values already calculated *****/ /***** Select number of rows with values already calculated *****/
return DB_QueryCOUNT ("can not get number of users with a figure", return (unsigned)
"SELECT COUNT(*)" DB_QueryCOUNT ("can not get number of users with a figure",
" FROM usr_figures" "SELECT COUNT(*)"
" WHERE %s>=0", " FROM usr_figures"
FieldName); " WHERE %s>=0",
FieldName);
} }
/*****************************************************************************/ /*****************************************************************************/
/****** Get ranking of a user according to the number of clicks per day ******/ /****** Get ranking of a user according to the number of clicks per day ******/
/*****************************************************************************/ /*****************************************************************************/
static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod) static unsigned Prf_GetRankingNumClicksPerDay (long UsrCod)
{ {
/***** Select number of rows with number of clicks per day /***** Select number of rows with number of clicks per day
greater than the clicks per day of this user *****/ greater than the clicks per day of this user *****/
return DB_QueryCOUNT ("can not get ranking using number of clicks per day", return (unsigned)
"SELECT COUNT(*)+1" DB_QueryCOUNT ("can not get ranking using number of clicks per day",
" FROM (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1) AS NumClicksPerDay" "SELECT COUNT(*)+1"
" FROM usr_figures" " FROM (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1) AS NumClicksPerDay"
" WHERE UsrCod<>%ld" // Necessary because the following comparison is not exact in floating point " FROM usr_figures"
" AND NumClicks>0" " WHERE UsrCod<>%ld" // Necessary because the following comparison is not exact in floating point
" AND FirstClickTime>FROM_UNIXTIME(0)) AS TableNumClicksPerDay" " AND NumClicks>0"
" WHERE NumClicksPerDay>" " AND FirstClickTime>FROM_UNIXTIME(0)) AS TableNumClicksPerDay"
"(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)" " WHERE NumClicksPerDay>"
" FROM usr_figures" "(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
" WHERE UsrCod=%ld" " FROM usr_figures"
" AND NumClicks>0" " WHERE UsrCod=%ld"
" AND FirstClickTime>FROM_UNIXTIME(0))", " AND NumClicks>0"
UsrCod,UsrCod); " AND FirstClickTime>FROM_UNIXTIME(0))",
UsrCod,
UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
/************** Get number of users with number of clicks per day ************/ /************** Get number of users with number of clicks per day ************/
/*****************************************************************************/ /*****************************************************************************/
static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void) static unsigned Prf_GetNumUsrsWithNumClicksPerDay (void)
{ {
/***** Select number of rows with values already calculated *****/ /***** Select number of rows with values already calculated *****/
return DB_QueryCOUNT ("can not get number of users" return (unsigned)
" with number of clicks per day", DB_QueryCOUNT ("can not get number of users with number of clicks per day",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM usr_figures" " FROM usr_figures"
" WHERE NumClicks>0" " WHERE NumClicks>0"
" AND FirstClickTime>FROM_UNIXTIME(0)"); " AND FirstClickTime>FROM_UNIXTIME(0)");
} }
/*****************************************************************************/ /*****************************************************************************/
/************************* Show position in ranking **************************/ /************************* Show position in ranking **************************/
/*****************************************************************************/ /*****************************************************************************/
static void Prf_ShowRanking (unsigned long Rank,unsigned long NumUsrs) static void Prf_ShowRanking (unsigned Rank,unsigned NumUsrs)
{ {
extern const char *The_ClassFormLinkOutBox[The_NUM_THEMES]; extern const char *The_ClassFormLinkOutBox[The_NUM_THEMES];
extern const char *Txt_of_PART_OF_A_TOTAL; extern const char *Txt_of_PART_OF_A_TOTAL;
@ -964,11 +971,12 @@ static void Prf_ShowRanking (unsigned long Rank,unsigned long NumUsrs)
Frm_BeginForm (ActSeeUseGbl); Frm_BeginForm (ActSeeUseGbl);
Sco_PutParamScope ("ScopeSta",Hie_Lvl_SYS); Sco_PutParamScope ("ScopeSta",Hie_Lvl_SYS);
Par_PutHiddenParamUnsigned (NULL,"FigureType",(unsigned) Fig_USERS_RANKING); Par_PutHiddenParamUnsigned (NULL,"FigureType",(unsigned) Fig_USERS_RANKING);
if (asprintf (&Title,"#%lu %s %lu",Rank,Txt_of_PART_OF_A_TOTAL,NumUsrs) < 0) if (asprintf (&Title,"#%u %s %u",
Rank,Txt_of_PART_OF_A_TOTAL,NumUsrs) < 0)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
HTM_BUTTON_SUBMIT_Begin (Title,The_ClassFormLinkOutBox[Gbl.Prefs.Theme],NULL); HTM_BUTTON_SUBMIT_Begin (Title,The_ClassFormLinkOutBox[Gbl.Prefs.Theme],NULL);
free (Title); free (Title);
HTM_TxtF ("#%lu",Rank); HTM_TxtF ("#%u",Rank);
HTM_BUTTON_End (); HTM_BUTTON_End ();
Frm_EndForm (); Frm_EndForm ();
} }
@ -1140,7 +1148,7 @@ static void Prf_GetNumSocialPubsAndStoreAsUsrFigure (long UsrCod)
if (Prf_CheckIfUsrFiguresExists (UsrCod)) if (Prf_CheckIfUsrFiguresExists (UsrCod))
DB_QueryUPDATE ("can not update user's figures", DB_QueryUPDATE ("can not update user's figures",
"UPDATE usr_figures" "UPDATE usr_figures"
" SET NumSocPub=%ld" " SET NumSocPub=%d"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
UsrFigures.NumSocPub, UsrFigures.NumSocPub,
UsrCod); UsrCod);
@ -1169,9 +1177,10 @@ static void Prf_GetNumFileViewsAndStoreAsUsrFigure (long UsrCod)
if (Prf_CheckIfUsrFiguresExists (UsrCod)) if (Prf_CheckIfUsrFiguresExists (UsrCod))
DB_QueryUPDATE ("can not update user's figures", DB_QueryUPDATE ("can not update user's figures",
"UPDATE usr_figures" "UPDATE usr_figures"
" SET NumFileViews=%ld" " SET NumFileViews=%d"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
UsrFigures.NumFileViews,UsrCod); UsrFigures.NumFileViews,
UsrCod);
else // User entry does not exist else // User entry does not exist
Prf_CreateUsrFigures (UsrCod,&UsrFigures,false); Prf_CreateUsrFigures (UsrCod,&UsrFigures,false);
} }
@ -1197,7 +1206,7 @@ static void Prf_GetNumForumPostsAndStoreAsUsrFigure (long UsrCod)
if (Prf_CheckIfUsrFiguresExists (UsrCod)) if (Prf_CheckIfUsrFiguresExists (UsrCod))
DB_QueryUPDATE ("can not update user's figures", DB_QueryUPDATE ("can not update user's figures",
"UPDATE usr_figures" "UPDATE usr_figures"
" SET NumForPst=%ld" " SET NumForPst=%d"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
UsrFigures.NumForPst, UsrFigures.NumForPst,
UsrCod); UsrCod);
@ -1226,7 +1235,7 @@ static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod)
if (Prf_CheckIfUsrFiguresExists (UsrCod)) if (Prf_CheckIfUsrFiguresExists (UsrCod))
DB_QueryUPDATE ("can not update user's figures", DB_QueryUPDATE ("can not update user's figures",
"UPDATE usr_figures" "UPDATE usr_figures"
" SET NumMsgSnt=%ld" " SET NumMsgSnt=%d"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
UsrFigures.NumMsgSnt, UsrFigures.NumMsgSnt,
UsrCod); UsrCod);
@ -1263,11 +1272,11 @@ static void Prf_ResetUsrFigures (struct UsrFigures *UsrFigures)
{ {
UsrFigures->FirstClickTimeUTC = (time_t) 0; // unknown first click time or user never logged UsrFigures->FirstClickTimeUTC = (time_t) 0; // unknown first click time or user never logged
UsrFigures->NumDays = -1; // not applicable UsrFigures->NumDays = -1; // not applicable
UsrFigures->NumClicks = -1L; // unknown number of clicks UsrFigures->NumClicks = -1; // unknown number of clicks
UsrFigures->NumSocPub = -1L; // unknown number of social publications UsrFigures->NumSocPub = -1; // unknown number of social publications
UsrFigures->NumFileViews = -1L; // unknown number of file views UsrFigures->NumFileViews = -1; // unknown number of file views
UsrFigures->NumForPst = -1L; // unknown number of forum posts UsrFigures->NumForPst = -1; // unknown number of forum posts
UsrFigures->NumMsgSnt = -1L; // unknown number of messages sent UsrFigures->NumMsgSnt = -1; // unknown number of messages sent
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1291,16 +1300,18 @@ static void Prf_CreateUsrFigures (long UsrCod,const struct UsrFigures *UsrFigure
/***** Create user's figures *****/ /***** Create user's figures *****/
DB_QueryINSERT ("can not create user's figures", DB_QueryINSERT ("can not create user's figures",
"INSERT INTO usr_figures" "INSERT INTO usr_figures"
" (UsrCod,FirstClickTime,NumClicks,NumSocPub,NumFileViews,NumForPst,NumMsgSnt)" " (UsrCod,FirstClickTime,"
"NumClicks,NumSocPub,NumFileViews,NumForPst,NumMsgSnt)"
" VALUES" " VALUES"
" (%ld,%s,%ld,%ld,%ld,%ld,%ld)", " (%ld,%s,"
"%d,%d,%d,%d,%d)",
UsrCod, UsrCod,
SubQueryFirstClickTime, SubQueryFirstClickTime,
UsrFigures->NumClicks, // -1L ==> unknown number of clicks UsrFigures->NumClicks, // -1 ==> unknown number of clicks
UsrFigures->NumSocPub, // -1L ==> unknown number of social publications UsrFigures->NumSocPub, // -1 ==> unknown number of social publications
UsrFigures->NumFileViews, // -1L ==> unknown number of file views UsrFigures->NumFileViews, // -1 ==> unknown number of file views
UsrFigures->NumForPst, // -1L ==> unknown number of forum posts UsrFigures->NumForPst, // -1 ==> unknown number of forum posts
UsrFigures->NumMsgSnt); // -1L ==> unknown number of messages sent UsrFigures->NumMsgSnt); // -1 ==> unknown number of messages sent
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1354,8 +1365,10 @@ void Prf_IncrementNumPubsUsr (long UsrCod)
/***** Increment number of social publications *****/ /***** Increment number of social publications *****/
// If NumSocPub < 0 ==> not yet calculated, so do nothing // If NumSocPub < 0 ==> not yet calculated, so do nothing
DB_QueryINSERT ("can not increment user's social publications", DB_QueryINSERT ("can not increment user's social publications",
"UPDATE IGNORE usr_figures SET NumSocPub=NumSocPub+1" "UPDATE IGNORE usr_figures"
" WHERE UsrCod=%ld AND NumSocPub>=0", " SET NumSocPub=NumSocPub+1"
" WHERE UsrCod=%ld"
" AND NumSocPub>=0",
UsrCod); UsrCod);
} }
@ -1368,8 +1381,10 @@ void Prf_IncrementNumFileViewsUsr (long UsrCod)
/***** Increment number of file views *****/ /***** Increment number of file views *****/
// If NumFileViews < 0 ==> not yet calculated, so do nothing // If NumFileViews < 0 ==> not yet calculated, so do nothing
DB_QueryINSERT ("can not increment user's file views", DB_QueryINSERT ("can not increment user's file views",
"UPDATE IGNORE usr_figures SET NumFileViews=NumFileViews+1" "UPDATE IGNORE usr_figures"
" WHERE UsrCod=%ld AND NumFileViews>=0", " SET NumFileViews=NumFileViews+1"
" WHERE UsrCod=%ld"
" AND NumFileViews>=0",
UsrCod); UsrCod);
} }
@ -1382,8 +1397,10 @@ void Prf_IncrementNumForPstUsr (long UsrCod)
/***** Increment number of forum posts *****/ /***** Increment number of forum posts *****/
// If NumForPst < 0 ==> not yet calculated, so do nothing // If NumForPst < 0 ==> not yet calculated, so do nothing
DB_QueryINSERT ("can not increment user's forum posts", DB_QueryINSERT ("can not increment user's forum posts",
"UPDATE IGNORE usr_figures SET NumForPst=NumForPst+1" "UPDATE IGNORE usr_figures"
" WHERE UsrCod=%ld AND NumForPst>=0", " SET NumForPst=NumForPst+1"
" WHERE UsrCod=%ld"
" AND NumForPst>=0",
UsrCod); UsrCod);
} }
@ -1396,8 +1413,10 @@ void Prf_IncrementNumMsgSntUsr (long UsrCod)
/***** Increment number of messages sent *****/ /***** Increment number of messages sent *****/
// If NumMsgSnt < 0 ==> not yet calculated, so do nothing // If NumMsgSnt < 0 ==> not yet calculated, so do nothing
DB_QueryINSERT ("can not increment user's messages sent", DB_QueryINSERT ("can not increment user's messages sent",
"UPDATE IGNORE usr_figures SET NumMsgSnt=NumMsgSnt+1" "UPDATE IGNORE usr_figures"
" WHERE UsrCod=%ld AND NumMsgSnt>=0", " SET NumMsgSnt=NumMsgSnt+1"
" WHERE UsrCod=%ld"
" AND NumMsgSnt>=0",
UsrCod); UsrCod);
} }

View File

@ -37,13 +37,13 @@
struct UsrFigures struct UsrFigures
{ {
time_t FirstClickTimeUTC; // 0 ==> unknown first click time of user never logged time_t FirstClickTimeUTC; // 0 ==> unknown first click time of user never logged
int NumDays; // -1 ==> not applicable int NumDays; // -1 ==> not applicable
long NumClicks; // -1L ==> unknown number of clicks int NumClicks; // -1 ==> unknown number of clicks
long NumSocPub; // -1L ==> unknown number of social publications int NumSocPub; // -1 ==> unknown number of social publications
long NumFileViews; // -1L ==> unknown number of file views int NumFileViews; // -1 ==> unknown number of file views
long NumForPst; // -1L ==> unknown number of forum posts int NumForPst; // -1 ==> unknown number of forum posts
long NumMsgSnt; // -1L ==> unknown number of messages sent int NumMsgSnt; // -1 ==> unknown number of messages sent
}; };
/*****************************************************************************/ /*****************************************************************************/

View File

@ -189,7 +189,7 @@ static void Prg_GetListItems (void);
static void Prg_GetDataOfItemByCod (struct ProgramItem *Item); static void Prg_GetDataOfItemByCod (struct ProgramItem *Item);
static void Prg_GetDataOfItem (struct ProgramItem *Item, static void Prg_GetDataOfItem (struct ProgramItem *Item,
MYSQL_RES **mysql_res, MYSQL_RES **mysql_res,
unsigned long NumRows); unsigned NumRows);
static void Prg_ResetItem (struct ProgramItem *Item); static void Prg_ResetItem (struct ProgramItem *Item);
static void Prg_FreeListItems (void); static void Prg_FreeListItems (void);
static void Prg_GetItemTxtFromDB (long ItmCod,char Txt[Cns_MAX_BYTES_TEXT + 1]); static void Prg_GetItemTxtFromDB (long ItmCod,char Txt[Cns_MAX_BYTES_TEXT + 1]);
@ -975,17 +975,18 @@ static void Prg_GetListItems (void)
Prg_FreeListItems (); Prg_FreeListItems ();
/***** Get list of program items from database *****/ /***** Get list of program items from database *****/
Prg_Gbl.List.NumItems = Prg_Gbl.List.NumItems = (unsigned)
(unsigned) DB_QuerySELECT (&mysql_res,"can not get program items", DB_QuerySELECT (&mysql_res,"can not get program items",
"SELECT ItmCod," // row[0] "SELECT ItmCod," // row[0]
"ItmInd," // row[1] "ItmInd," // row[1]
"Level," // row[2] "Level," // row[2]
"Hidden" // row[3] "Hidden" // row[3]
" FROM prg_items" " FROM prg_items"
" WHERE CrsCod=%ld%s" " WHERE CrsCod=%ld"
" ORDER BY ItmInd", "%s"
Gbl.Hierarchy.Crs.CrsCod, " ORDER BY ItmInd",
HiddenSubQuery[Gbl.Usrs.Me.Role.Logged]); Gbl.Hierarchy.Crs.CrsCod,
HiddenSubQuery[Gbl.Usrs.Me.Role.Logged]);
if (Prg_Gbl.List.NumItems) // Items found... if (Prg_Gbl.List.NumItems) // Items found...
{ {
@ -1030,25 +1031,27 @@ static void Prg_GetListItems (void)
static void Prg_GetDataOfItemByCod (struct ProgramItem *Item) static void Prg_GetDataOfItemByCod (struct ProgramItem *Item)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
unsigned long NumRows; unsigned NumRows;
if (Item->Hierarchy.ItmCod > 0) if (Item->Hierarchy.ItmCod > 0)
{ {
/***** Build query *****/ /***** Build query *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get program item data", NumRows = (unsigned)
"SELECT ItmCod," // row[0] DB_QuerySELECT (&mysql_res,"can not get program item data",
"ItmInd," // row[1] "SELECT ItmCod," // row[0]
"Level," // row[2] "ItmInd," // row[1]
"Hidden," // row[3] "Level," // row[2]
"UsrCod," // row[4] "Hidden," // row[3]
"UNIX_TIMESTAMP(StartTime)," // row[5] "UsrCod," // row[4]
"UNIX_TIMESTAMP(EndTime)," // row[6] "UNIX_TIMESTAMP(StartTime)," // row[5]
"NOW() BETWEEN StartTime AND EndTime," // row[7] "UNIX_TIMESTAMP(EndTime)," // row[6]
"Title" // row[8] "NOW() BETWEEN StartTime AND EndTime," // row[7]
" FROM prg_items" "Title" // row[8]
" WHERE ItmCod=%ld" " FROM prg_items"
" AND CrsCod=%ld", // Extra check " WHERE ItmCod=%ld"
Item->Hierarchy.ItmCod,Gbl.Hierarchy.Crs.CrsCod); " AND CrsCod=%ld", // Extra check
Item->Hierarchy.ItmCod,
Gbl.Hierarchy.Crs.CrsCod);
/***** Get data of program item *****/ /***** Get data of program item *****/
Prg_GetDataOfItem (Item,&mysql_res,NumRows); Prg_GetDataOfItem (Item,&mysql_res,NumRows);
@ -1064,7 +1067,7 @@ static void Prg_GetDataOfItemByCod (struct ProgramItem *Item)
static void Prg_GetDataOfItem (struct ProgramItem *Item, static void Prg_GetDataOfItem (struct ProgramItem *Item,
MYSQL_RES **mysql_res, MYSQL_RES **mysql_res,
unsigned long NumRows) unsigned NumRows)
{ {
MYSQL_ROW row; MYSQL_ROW row;

View File

@ -2270,20 +2270,21 @@ static unsigned Prj_GetUsrsInPrj (long PrjCod,Prj_RoleInProject_t RoleInProject,
MYSQL_RES **mysql_res) MYSQL_RES **mysql_res)
{ {
/***** Get users in project from database *****/ /***** Get users in project from database *****/
return (unsigned) DB_QuerySELECT (mysql_res,"can not get users in project", return (unsigned)
"SELECT prj_users.UsrCod," // row[0] DB_QuerySELECT (mysql_res,"can not get users in project",
"usr_data.Surname1 AS S1," // row[1] "SELECT prj_users.UsrCod," // row[0]
"usr_data.Surname2 AS S2," // row[2] "usr_data.Surname1 AS S1," // row[1]
"usr_data.FirstName AS FN" // row[3] "usr_data.Surname2 AS S2," // row[2]
" FROM prj_users," "usr_data.FirstName AS FN" // row[3]
"usr_data" " FROM prj_users,"
" WHERE prj_users.PrjCod=%ld" "usr_data"
" AND prj_users.RoleInProject=%u" " WHERE prj_users.PrjCod=%ld"
" AND prj_users.UsrCod=usr_data.UsrCod" " AND prj_users.RoleInProject=%u"
" ORDER BY S1," " AND prj_users.UsrCod=usr_data.UsrCod"
"S2," " ORDER BY S1,"
"FN", "S2,"
PrjCod,(unsigned) RoleInProject); "FN",
PrjCod,(unsigned) RoleInProject);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2851,8 +2852,7 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
unsigned NumUsrsInList; unsigned NumUsrsInList;
long *LstSelectedUsrCods; long *LstSelectedUsrCods;
char *SubQueryUsrs; char *SubQueryUsrs;
unsigned long NumRows = 0; // Initialized to avoid warning unsigned NumPrjsFromDB = 0;
unsigned NumPrjsFromDB;
unsigned NumPrjsAfterFilter = 0; unsigned NumPrjsAfterFilter = 0;
unsigned NumPrj; unsigned NumPrj;
struct Prj_Faults Faults; struct Prj_Faults Faults;
@ -2937,37 +2937,47 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
case Prj_ORDER_START_TIME: case Prj_ORDER_START_TIME:
case Prj_ORDER_END_TIME: case Prj_ORDER_END_TIME:
case Prj_ORDER_TITLE: case Prj_ORDER_TITLE:
NumRows = DB_QuerySELECT (&mysql_res,"can not get projects", NumPrjsFromDB = (unsigned)
"SELECT prj_projects.PrjCod" DB_QuerySELECT (&mysql_res,"can not get projects",
" FROM prj_projects," "SELECT prj_projects.PrjCod"
"prj_users" " FROM prj_projects,"
" WHERE prj_projects.CrsCod=%ld" "prj_users"
"%s%s%s" " WHERE prj_projects.CrsCod=%ld"
" AND prj_projects.PrjCod=prj_users.PrjCod" "%s"
" AND prj_users.UsrCod=%ld" "%s"
" GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used) "%s"
" ORDER BY %s", " AND prj_projects.PrjCod=prj_users.PrjCod"
Gbl.Hierarchy.Crs.CrsCod, " AND prj_users.UsrCod=%ld"
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery, " GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used)
Gbl.Usrs.Me.UsrDat.UsrCod, " ORDER BY %s",
OrderBySubQuery[Projects->SelectedOrder]); Gbl.Hierarchy.Crs.CrsCod,
PreNonSubQuery,
HidVisSubQuery,
DptCodSubQuery,
Gbl.Usrs.Me.UsrDat.UsrCod,
OrderBySubQuery[Projects->SelectedOrder]);
break; break;
case Prj_ORDER_DEPARTMENT: case Prj_ORDER_DEPARTMENT:
NumRows = DB_QuerySELECT (&mysql_res,"can not get projects", NumPrjsFromDB = (unsigned)
"SELECT prj_projects.PrjCod" DB_QuerySELECT (&mysql_res,"can not get projects",
" FROM prj_projects LEFT JOIN dpt_departments," "SELECT prj_projects.PrjCod"
"prj_users" " FROM prj_projects LEFT JOIN dpt_departments,"
" ON prj_projects.DptCod=dpt_departments.DptCod" "prj_users"
" WHERE prj_projects.CrsCod=%ld" " ON prj_projects.DptCod=dpt_departments.DptCod"
"%s%s%s" " WHERE prj_projects.CrsCod=%ld"
" AND prj_projects.PrjCod=prj_users.PrjCod" "%s"
" AND prj_users.UsrCod=%ld" "%s"
" GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used) "%s"
" ORDER BY %s", " AND prj_projects.PrjCod=prj_users.PrjCod"
Gbl.Hierarchy.Crs.CrsCod, " AND prj_users.UsrCod=%ld"
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery, " GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used)
Gbl.Usrs.Me.UsrDat.UsrCod, " ORDER BY %s",
OrderBySubQuery[Projects->SelectedOrder]); Gbl.Hierarchy.Crs.CrsCod,
PreNonSubQuery,
HidVisSubQuery,
DptCodSubQuery,
Gbl.Usrs.Me.UsrDat.UsrCod,
OrderBySubQuery[Projects->SelectedOrder]);
break; break;
} }
break; break;
@ -2990,37 +3000,47 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
case Prj_ORDER_START_TIME: case Prj_ORDER_START_TIME:
case Prj_ORDER_END_TIME: case Prj_ORDER_END_TIME:
case Prj_ORDER_TITLE: case Prj_ORDER_TITLE:
NumRows = DB_QuerySELECT (&mysql_res,"can not get projects", NumPrjsFromDB = (unsigned)
"SELECT prj_projects.PrjCod" DB_QuerySELECT (&mysql_res,"can not get projects",
" FROM prj_projects," "SELECT prj_projects.PrjCod"
"prj_users" " FROM prj_projects,"
" WHERE prj_projects.CrsCod=%ld" "prj_users"
"%s%s%s" " WHERE prj_projects.CrsCod=%ld"
" AND prj_projects.PrjCod=prj_users.PrjCod" "%s"
" AND prj_users.UsrCod IN (%s)" "%s"
" GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used) "%s"
" ORDER BY %s", " AND prj_projects.PrjCod=prj_users.PrjCod"
Gbl.Hierarchy.Crs.CrsCod, " AND prj_users.UsrCod IN (%s)"
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery, " GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used)
SubQueryUsrs, " ORDER BY %s",
OrderBySubQuery[Projects->SelectedOrder]); Gbl.Hierarchy.Crs.CrsCod,
PreNonSubQuery,
HidVisSubQuery,
DptCodSubQuery,
SubQueryUsrs,
OrderBySubQuery[Projects->SelectedOrder]);
break; break;
case Prj_ORDER_DEPARTMENT: case Prj_ORDER_DEPARTMENT:
NumRows = DB_QuerySELECT (&mysql_res,"can not get projects", NumPrjsFromDB = (unsigned)
"SELECT prj_projects.PrjCod" DB_QuerySELECT (&mysql_res,"can not get projects",
" FROM prj_projects LEFT JOIN dpt_departments," "SELECT prj_projects.PrjCod"
"prj_users" " FROM prj_projects LEFT JOIN dpt_departments,"
" ON prj_projects.DptCod=dpt_departments.DptCod" "prj_users"
" WHERE prj_projects.CrsCod=%ld" " ON prj_projects.DptCod=dpt_departments.DptCod"
"%s%s%s" " WHERE prj_projects.CrsCod=%ld"
" AND prj_projects.PrjCod=prj_users.PrjCod" "%s"
" AND prj_users.UsrCod IN (%s)" "%s"
" GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used) "%s"
" ORDER BY %s", " AND prj_projects.PrjCod=prj_users.PrjCod"
Gbl.Hierarchy.Crs.CrsCod, " AND prj_users.UsrCod IN (%s)"
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery, " GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used)
SubQueryUsrs, " ORDER BY %s",
OrderBySubQuery[Projects->SelectedOrder]); Gbl.Hierarchy.Crs.CrsCod,
PreNonSubQuery,
HidVisSubQuery,
DptCodSubQuery,
SubQueryUsrs,
OrderBySubQuery[Projects->SelectedOrder]);
break; break;
} }
@ -3030,8 +3050,6 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
/* Free list of user codes */ /* Free list of user codes */
Usr_FreeListSelectedUsrCods (LstSelectedUsrCods); Usr_FreeListSelectedUsrCods (LstSelectedUsrCods);
} }
else
NumRows = 0;
break; break;
case Usr_WHO_ALL: case Usr_WHO_ALL:
/* Get list of projects */ /* Get list of projects */
@ -3040,27 +3058,37 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
case Prj_ORDER_START_TIME: case Prj_ORDER_START_TIME:
case Prj_ORDER_END_TIME: case Prj_ORDER_END_TIME:
case Prj_ORDER_TITLE: case Prj_ORDER_TITLE:
NumRows = DB_QuerySELECT (&mysql_res,"can not get projects", NumPrjsFromDB = (unsigned)
"SELECT prj_projects.PrjCod" DB_QuerySELECT (&mysql_res,"can not get projects",
" FROM prj_projects" "SELECT prj_projects.PrjCod"
" WHERE prj_projects.CrsCod=%ld" " FROM prj_projects"
"%s%s%s" " WHERE prj_projects.CrsCod=%ld"
" ORDER BY %s", "%s"
Gbl.Hierarchy.Crs.CrsCod, "%s"
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery, "%s"
OrderBySubQuery[Projects->SelectedOrder]); " ORDER BY %s",
Gbl.Hierarchy.Crs.CrsCod,
PreNonSubQuery,
HidVisSubQuery,
DptCodSubQuery,
OrderBySubQuery[Projects->SelectedOrder]);
break; break;
case Prj_ORDER_DEPARTMENT: case Prj_ORDER_DEPARTMENT:
NumRows = DB_QuerySELECT (&mysql_res,"can not get projects", NumPrjsFromDB = (unsigned)
"SELECT prj_projects.PrjCod" DB_QuerySELECT (&mysql_res,"can not get projects",
" FROM prj_projects LEFT JOIN dpt_departments" "SELECT prj_projects.PrjCod"
" ON prj_projects.DptCod=dpt_departments.DptCod" " FROM prj_projects LEFT JOIN dpt_departments"
" WHERE prj_projects.CrsCod=%ld" " ON prj_projects.DptCod=dpt_departments.DptCod"
"%s%s%s" " WHERE prj_projects.CrsCod=%ld"
" ORDER BY %s", "%s"
Gbl.Hierarchy.Crs.CrsCod, "%s"
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery, "%s"
OrderBySubQuery[Projects->SelectedOrder]); " ORDER BY %s",
Gbl.Hierarchy.Crs.CrsCod,
PreNonSubQuery,
HidVisSubQuery,
DptCodSubQuery,
OrderBySubQuery[Projects->SelectedOrder]);
break; break;
} }
break; break;
@ -3074,13 +3102,10 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
free (HidVisSubQuery); free (HidVisSubQuery);
free (DptCodSubQuery); free (DptCodSubQuery);
if (NumRows) // Projects found... if (NumPrjsFromDB) // Projects found...
{ {
/***** Initialize number of projects *****/
NumPrjsFromDB = (unsigned) NumRows;
/***** Create list of projects *****/ /***** Create list of projects *****/
if ((Projects->LstPrjCods = calloc (NumRows, if ((Projects->LstPrjCods = calloc ((size_t) NumPrjsFromDB,
sizeof (*Projects->LstPrjCods))) == NULL) sizeof (*Projects->LstPrjCods))) == NULL)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
@ -4132,16 +4157,13 @@ static void Prj_GetConfigPrjFromDB (struct Prj_Projects *Projects)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
/***** Get configuration of projects for current course from database *****/ /***** Get configuration of projects for current course from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get configuration of test", if (DB_QuerySELECT (&mysql_res,"can not get configuration of test",
"SELECT Editable" // row[0] "SELECT Editable" // row[0]
" FROM prj_config" " FROM prj_config"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod) == 0)
if (NumRows == 0)
Projects->Config.Editable = Prj_EDITABLE_DEFAULT; Projects->Config.Editable = Prj_EDITABLE_DEFAULT;
else // NumRows == 1 else // NumRows == 1
{ {

View File

@ -83,6 +83,8 @@ extern struct Globals Gbl;
static void Rec_WriteHeadingRecordFields (void); static void Rec_WriteHeadingRecordFields (void);
static unsigned Rec_GetAllFieldsInCurrCrs (MYSQL_RES **mysql_res);
static void Rec_PutParamFieldCod (void *FieldCod); static void Rec_PutParamFieldCod (void *FieldCod);
static void Rec_GetFieldByCod (long FieldCod,char Name[Rec_MAX_BYTES_NAME_FIELD + 1], static void Rec_GetFieldByCod (long FieldCod,char Name[Rec_MAX_BYTES_NAME_FIELD + 1],
unsigned *NumLines,Rec_VisibilityRecordFields_t *Visibility); unsigned *NumLines,Rec_VisibilityRecordFields_t *Visibility);
@ -487,8 +489,8 @@ bool Rec_CheckIfRecordFieldIsRepeated (const char *FieldName)
bool FieldIsRepeated = false; bool FieldIsRepeated = false;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned NumRows;
unsigned long NumRow; unsigned NumRow;
/* Query database */ /* Query database */
if ((NumRows = Rec_GetAllFieldsInCurrCrs (&mysql_res)) > 0) // If se han encontrado groups... if ((NumRows = Rec_GetAllFieldsInCurrCrs (&mysql_res)) > 0) // If se han encontrado groups...
@ -518,7 +520,7 @@ bool Rec_CheckIfRecordFieldIsRepeated (const char *FieldName)
/******* Get the fields of records already present in current course *********/ /******* Get the fields of records already present in current course *********/
/*****************************************************************************/ /*****************************************************************************/
unsigned long Rec_GetAllFieldsInCurrCrs (MYSQL_RES **mysql_res) static unsigned Rec_GetAllFieldsInCurrCrs (MYSQL_RES **mysql_res)
{ {
/***** Get fields of records in current course from database *****/ /***** Get fields of records in current course from database *****/
return DB_QuerySELECT (mysql_res,"can not get fields of records" return DB_QuerySELECT (mysql_res,"can not get fields of records"
@ -679,22 +681,17 @@ static void Rec_GetFieldByCod (long FieldCod,char Name[Rec_MAX_BYTES_NAME_FIELD
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
unsigned Vis; unsigned Vis;
/***** Get a field of a record in a course from database *****/ /***** Get a field of a record in a course from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get a field of a record" if (DB_QuerySELECT (&mysql_res,"can not get a field of a record in a course",
" in a course", "SELECT FieldName," // row[0]
"SELECT FieldName," // row[0] "NumLines," // row[1]
"NumLines," // row[1] "Visibility" // row[2]
"Visibility" // row[2] " FROM crs_record_fields"
" FROM crs_record_fields" " WHERE CrsCod=%ld"
" WHERE CrsCod=%ld" " AND FieldCod=%ld",
" AND FieldCod=%ld", Gbl.Hierarchy.Crs.CrsCod,FieldCod) != 1)
Gbl.Hierarchy.Crs.CrsCod,FieldCod);
/***** Count number of rows in result *****/
if (NumRows != 1)
Lay_ShowErrorAndExit ("Error when getting a field of a record in a course."); Lay_ShowErrorAndExit ("Error when getting a field of a record in a course.");
/***** Get the field *****/ /***** Get the field *****/
@ -1851,7 +1848,7 @@ static void Rec_ShowCrsRecord (Rec_CourseRecordViewType_t TypeOfView,
/************** Get the text of a field of a record of course ****************/ /************** Get the text of a field of a record of course ****************/
/*****************************************************************************/ /*****************************************************************************/
unsigned long Rec_GetFieldFromCrsRecord (long UsrCod,long FieldCod,MYSQL_RES **mysql_res) unsigned Rec_GetFieldFromCrsRecord (long UsrCod,long FieldCod,MYSQL_RES **mysql_res)
{ {
/***** Get the text of a field of a record from database *****/ /***** Get the text of a field of a record from database *****/
return DB_QuerySELECT (mysql_res,"can not get the text" return DB_QuerySELECT (mysql_res,"can not get the text"
@ -1860,7 +1857,8 @@ unsigned long Rec_GetFieldFromCrsRecord (long UsrCod,long FieldCod,MYSQL_RES **m
" FROM crs_records" " FROM crs_records"
" WHERE FieldCod=%ld" " WHERE FieldCod=%ld"
" AND UsrCod=%ld", " AND UsrCod=%ld",
FieldCod,UsrCod); FieldCod,
UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -123,7 +123,6 @@ void Rec_ShowFormCreateRecordField (void);
void Rec_ReceiveFormField (void); void Rec_ReceiveFormField (void);
unsigned Rec_ConvertToNumLinesField (const char *StrNumLines); unsigned Rec_ConvertToNumLinesField (const char *StrNumLines);
bool Rec_CheckIfRecordFieldIsRepeated (const char *FieldName); bool Rec_CheckIfRecordFieldIsRepeated (const char *FieldName);
unsigned long Rec_GetAllFieldsInCurrCrs (MYSQL_RES **mysql_res);
void Rec_CreateRecordField (void); void Rec_CreateRecordField (void);
void Rec_ReqRemField (void); void Rec_ReqRemField (void);
long Rec_GetFieldCod (void); long Rec_GetFieldCod (void);
@ -151,7 +150,7 @@ void Rec_ListRecordsTchsPrint (void);
void Rec_UpdateAndShowMyCrsRecord (void); void Rec_UpdateAndShowMyCrsRecord (void);
void Rec_UpdateAndShowOtherCrsRecord (void); void Rec_UpdateAndShowOtherCrsRecord (void);
unsigned long Rec_GetFieldFromCrsRecord (long UsrCod,long FieldCod,MYSQL_RES **mysql_res); unsigned Rec_GetFieldFromCrsRecord (long UsrCod,long FieldCod,MYSQL_RES **mysql_res);
void Rec_GetFieldsCrsRecordFromForm (void); void Rec_GetFieldsCrsRecordFromForm (void);
void Rec_UpdateCrsRecord (long UsrCod); void Rec_UpdateCrsRecord (long UsrCod);
void Rec_RemoveFieldsCrsRecordInCrs (long UsrCod,struct Crs_Course *Crs); void Rec_RemoveFieldsCrsRecordInCrs (long UsrCod,struct Crs_Course *Crs);

View File

@ -134,7 +134,7 @@ static void Rep_WriteRowCrsData (long CrsCod,Rol_Role_t Role,
static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role, static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
struct Rep_Report *Report); struct Rep_Report *Report);
static void Rep_ComputeMaxAndTotalHits (struct Rep_Hits *Hits, static void Rep_ComputeMaxAndTotalHits (struct Rep_Hits *Hits,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res,unsigned Field); MYSQL_RES *mysql_res,unsigned Field);
static void Rep_DrawBarNumHits (unsigned long HitsNum,unsigned long HitsMax, static void Rep_DrawBarNumHits (unsigned long HitsNum,unsigned long HitsMax,
unsigned MaxBarWidth); unsigned MaxBarWidth);
@ -638,7 +638,7 @@ static void Rep_WriteSectionUsrFigures (const struct Rep_Report *Report)
fprintf (Gbl.F.Rep,"<li>%s: ",Txt_Clicks); fprintf (Gbl.F.Rep,"<li>%s: ",Txt_Clicks);
if (Report->UsrFigures.NumClicks >= 0) if (Report->UsrFigures.NumClicks >= 0)
{ {
fprintf (Gbl.F.Rep,"%ld",Report->UsrFigures.NumClicks); fprintf (Gbl.F.Rep,"%d",Report->UsrFigures.NumClicks);
if (Report->UsrFigures.NumDays > 0) if (Report->UsrFigures.NumDays > 0)
{ {
fprintf (Gbl.F.Rep," ("); fprintf (Gbl.F.Rep," (");
@ -669,7 +669,7 @@ static void Rep_WriteSectionUsrFigures (const struct Rep_Report *Report)
fprintf (Gbl.F.Rep,"<li>%s: ",Txt_Downloads); fprintf (Gbl.F.Rep,"<li>%s: ",Txt_Downloads);
if (Report->UsrFigures.NumFileViews >= 0) if (Report->UsrFigures.NumFileViews >= 0)
{ {
fprintf (Gbl.F.Rep,"%ld %s", fprintf (Gbl.F.Rep,"%d %s",
Report->UsrFigures.NumFileViews, Report->UsrFigures.NumFileViews,
(Report->UsrFigures.NumFileViews == 1) ? Txt_download : (Report->UsrFigures.NumFileViews == 1) ? Txt_download :
Txt_downloads); Txt_downloads);
@ -689,7 +689,7 @@ static void Rep_WriteSectionUsrFigures (const struct Rep_Report *Report)
fprintf (Gbl.F.Rep,"<li>%s: ",Txt_Forum_posts); fprintf (Gbl.F.Rep,"<li>%s: ",Txt_Forum_posts);
if (Report->UsrFigures.NumForPst >= 0) if (Report->UsrFigures.NumForPst >= 0)
{ {
fprintf (Gbl.F.Rep,"%ld %s", fprintf (Gbl.F.Rep,"%d %s",
Report->UsrFigures.NumForPst, Report->UsrFigures.NumForPst,
(Report->UsrFigures.NumForPst == 1) ? Txt_FORUM_post : (Report->UsrFigures.NumForPst == 1) ? Txt_FORUM_post :
Txt_FORUM_posts); Txt_FORUM_posts);
@ -709,7 +709,7 @@ static void Rep_WriteSectionUsrFigures (const struct Rep_Report *Report)
fprintf (Gbl.F.Rep,"<li>%s: ",Txt_Messages_sent); fprintf (Gbl.F.Rep,"<li>%s: ",Txt_Messages_sent);
if (Report->UsrFigures.NumMsgSnt >= 0) if (Report->UsrFigures.NumMsgSnt >= 0)
{ {
fprintf (Gbl.F.Rep,"%ld %s", fprintf (Gbl.F.Rep,"%d %s",
Report->UsrFigures.NumMsgSnt, Report->UsrFigures.NumMsgSnt,
(Report->UsrFigures.NumMsgSnt == 1) ? Txt_message : (Report->UsrFigures.NumMsgSnt == 1) ? Txt_message :
Txt_messages); Txt_messages);
@ -765,8 +765,8 @@ static void Rep_WriteSectionHitsPerAction (struct Rep_Report *Report)
extern const char *Txt_Other_actions; extern const char *Txt_Other_actions;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned NumHits;
unsigned long NumRow; unsigned NumHit;
long ActCod; long ActCod;
Act_Action_t Action; Act_Action_t Action;
Tab_Tab_t Tab; Tab_Tab_t Tab;
@ -778,27 +778,28 @@ static void Rep_WriteSectionHitsPerAction (struct Rep_Report *Report)
Txt_Hits_per_action); Txt_Hits_per_action);
/***** Make the query *****/ /***** Make the query *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks", NumHits = (unsigned)
"SELECT SQL_NO_CACHE ActCod," // row[0] DB_QuerySELECT (&mysql_res,"can not get clicks",
"COUNT(*) AS N" // row[1] "SELECT SQL_NO_CACHE ActCod," // row[0]
" FROM log" "COUNT(*) AS N" // row[1]
" WHERE ClickTime>=FROM_UNIXTIME(%ld)" " FROM log"
" AND UsrCod=%ld" " WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" GROUP BY ActCod" " AND UsrCod=%ld"
" ORDER BY N DESC" " GROUP BY ActCod"
" LIMIT %u", " ORDER BY N DESC"
(long) Report->UsrFigures.FirstClickTimeUTC, " LIMIT %u",
Gbl.Usrs.Me.UsrDat.UsrCod, (long) Report->UsrFigures.FirstClickTimeUTC,
Rep_MAX_ACTIONS); Gbl.Usrs.Me.UsrDat.UsrCod,
Rep_MAX_ACTIONS);
/***** Compute maximum number of hits per action *****/ /***** Compute maximum number of hits per action *****/
Rep_ComputeMaxAndTotalHits (&Report->Hits,NumRows,mysql_res,1); Rep_ComputeMaxAndTotalHits (&Report->Hits,NumHits,mysql_res,1);
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
/***** Write rows *****/ /***** Write rows *****/
for (NumRow = 1, NumClicks = 0; for (NumHit = 1, NumClicks = 0;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1008,23 +1009,23 @@ static void Rep_GetAndWriteMyCurrentCrss (Rol_Role_t Role,
Txt_students_ABBREVIATION); Txt_students_ABBREVIATION);
/***** Get courses of a user from database *****/ /***** Get courses of a user from database *****/
NumCrss = NumCrss = (unsigned)
(unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user", DB_QuerySELECT (&mysql_res,"can not get courses of a user",
"SELECT my_courses.CrsCod," // row[0] "SELECT my_courses.CrsCod," // row[0]
"COUNT(*) AS N" // row[1] "COUNT(*) AS N" // row[1]
" FROM (SELECT CrsCod" " FROM (SELECT CrsCod"
" FROM crs_users" " FROM crs_users"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND Role=%u) AS my_courses" // It's imperative to use a derived table to not block crs_usr! " AND Role=%u) AS my_courses" // It's imperative to use a derived table to not block crs_usr!
" LEFT JOIN log" " LEFT JOIN log"
" ON (my_courses.CrsCod=log.CrsCod)" " ON (my_courses.CrsCod=log.CrsCod)"
" WHERE log.UsrCod=%ld" " WHERE log.UsrCod=%ld"
" AND log.Role=%u" " AND log.Role=%u"
" GROUP BY my_courses.CrsCod" " GROUP BY my_courses.CrsCod"
" ORDER BY N DESC," " ORDER BY N DESC,"
"my_courses.CrsCod DESC", "my_courses.CrsCod DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role, Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role,
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role); Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role);
/***** List the courses (one row per course) *****/ /***** List the courses (one row per course) *****/
if (NumCrss) if (NumCrss)
@ -1099,19 +1100,19 @@ static void Rep_GetAndWriteMyHistoricCrss (Rol_Role_t Role,
long CrsCod; long CrsCod;
/***** Get historic courses of a user from log *****/ /***** Get historic courses of a user from log *****/
NumCrss = NumCrss = (unsigned)
(unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user", DB_QuerySELECT (&mysql_res,"can not get courses of a user",
"SELECT CrsCod," // row[0] "SELECT CrsCod," // row[0]
"COUNT(*) AS N" // row[1] "COUNT(*) AS N" // row[1]
" FROM log" " FROM log"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND Role=%u" " AND Role=%u"
" AND CrsCod>0" " AND CrsCod>0"
" GROUP BY CrsCod" " GROUP BY CrsCod"
" HAVING N>%u" " HAVING N>%u"
" ORDER BY N DESC", " ORDER BY N DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role, Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role,
Rep_MIN_CLICKS_CRS); Rep_MIN_CLICKS_CRS);
/***** List the courses (one row per course) *****/ /***** List the courses (one row per course) *****/
if (NumCrss) if (NumCrss)
@ -1223,8 +1224,8 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
char SubQueryRol[128]; char SubQueryRol[128];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned NumHits;
unsigned long NumRow; unsigned NumHit;
unsigned ReadYear; unsigned ReadYear;
unsigned FirstYear; unsigned FirstYear;
unsigned LastYear; unsigned LastYear;
@ -1241,20 +1242,21 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
else else
sprintf (SubQueryRol," AND Role=%u",(unsigned) Role); sprintf (SubQueryRol," AND Role=%u",(unsigned) Role);
NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks", NumHits = (unsigned)
"SELECT SQL_NO_CACHE YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," // row[0] DB_QuerySELECT (&mysql_res,"can not get clicks",
"COUNT(*)" // row[1] "SELECT SQL_NO_CACHE YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," // row[0]
" FROM log" "COUNT(*)" // row[1]
" WHERE ClickTime>=FROM_UNIXTIME(%ld)" " FROM log"
" AND UsrCod=%ld" " WHERE ClickTime>=FROM_UNIXTIME(%ld)"
"%s" " AND UsrCod=%ld"
"%s" "%s"
" GROUP BY Year" "%s"
" ORDER BY Year DESC", " GROUP BY Year"
(long) Report->UsrFigures.FirstClickTimeUTC, " ORDER BY Year DESC",
Gbl.Usrs.Me.UsrDat.UsrCod, (long) Report->UsrFigures.FirstClickTimeUTC,
SubQueryCrs, Gbl.Usrs.Me.UsrDat.UsrCod,
SubQueryRol); SubQueryCrs,
SubQueryRol);
/***** Initialize first year *****/ /***** Initialize first year *****/
FirstYear = 1900 + Report->tm_FirstClickTime.tm_year; FirstYear = 1900 + Report->tm_FirstClickTime.tm_year;
@ -1269,14 +1271,14 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
else else
{ {
/* Compute maximum number of hits per year */ /* Compute maximum number of hits per year */
Rep_ComputeMaxAndTotalHits (&Report->Hits,NumRows,mysql_res,1); Rep_ComputeMaxAndTotalHits (&Report->Hits,NumHits,mysql_res,1);
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
} }
/***** Write rows *****/ /***** Write rows *****/
for (NumRow = 1; for (NumHit = 1;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1326,16 +1328,16 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
/*****************************************************************************/ /*****************************************************************************/
static void Rep_ComputeMaxAndTotalHits (struct Rep_Hits *Hits, static void Rep_ComputeMaxAndTotalHits (struct Rep_Hits *Hits,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res,unsigned Field) MYSQL_RES *mysql_res,unsigned Field)
{ {
unsigned long NumRow; unsigned NumHit;
MYSQL_ROW row; MYSQL_ROW row;
/***** For each row... *****/ /***** For each row... *****/
for (NumRow = 1, Hits->Max = 0; for (NumHit = 1, Hits->Max = 0;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1426,13 +1428,13 @@ static void Rep_RemoveUsrReportsFiles (long UsrCod)
char PathUniqueDirReport[PATH_MAX + 1]; char PathUniqueDirReport[PATH_MAX + 1];
/***** Get directories for the reports *****/ /***** Get directories for the reports *****/
NumReports = NumReports = (unsigned)
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's usage reports", DB_QuerySELECT (&mysql_res,"can not get user's usage reports",
"SELECT UniqueDirL," // row[0] "SELECT UniqueDirL," // row[0]
"UniqueDirR" // row[1] "UniqueDirR" // row[1]
" FROM usr_reports" " FROM usr_reports"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
UsrCod); UsrCod);
/***** Remove the reports *****/ /***** Remove the reports *****/
for (NumReport = 0; for (NumReport = 0;

View File

@ -357,12 +357,13 @@ static void Roo_GetAndEditMACAddresses (long RooCod,const char *Anchor)
static unsigned Roo_GetMACAddresses (long RooCod,MYSQL_RES **mysql_res) static unsigned Roo_GetMACAddresses (long RooCod,MYSQL_RES **mysql_res)
{ {
/***** Get MAC addresses from database *****/ /***** Get MAC addresses from database *****/
return (unsigned) DB_QuerySELECT (mysql_res,"can not get MAC addresses", return (unsigned)
"SELECT MAC" // row[0] DB_QuerySELECT (mysql_res,"can not get MAC addresses",
" FROM roo_macs" "SELECT MAC" // row[0]
" WHERE RooCod=%ld" " FROM roo_macs"
" ORDER BY MAC", " WHERE RooCod=%ld"
RooCod); " ORDER BY MAC",
RooCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -559,7 +560,6 @@ void Roo_GetListRooms (struct Roo_Rooms *Rooms,
}; };
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
unsigned NumRoom; unsigned NumRoom;
struct Roo_Room *Room; struct Roo_Room *Room;
@ -567,44 +567,45 @@ void Roo_GetListRooms (struct Roo_Rooms *Rooms,
switch (WhichData) switch (WhichData)
{ {
case Roo_ALL_DATA: case Roo_ALL_DATA:
NumRows = DB_QuerySELECT (&mysql_res,"can not get rooms", Rooms->Num = (unsigned)
"SELECT roo_rooms.RooCod," // row[0] DB_QuerySELECT (&mysql_res,"can not get rooms",
"roo_rooms.BldCod," // row[1] "SELECT roo_rooms.RooCod," // row[0]
"bld_buildings.ShortName," // row[2] "roo_rooms.BldCod," // row[1]
"roo_rooms.Floor," // row[3] "bld_buildings.ShortName," // row[2]
"roo_rooms.Type," // row[4] "roo_rooms.Floor," // row[3]
"roo_rooms.ShortName," // row[5] "roo_rooms.Type," // row[4]
"roo_rooms.FullName," // row[6] "roo_rooms.ShortName," // row[5]
"roo_rooms.Capacity" // row[7] "roo_rooms.FullName," // row[6]
" FROM roo_rooms" "roo_rooms.Capacity" // row[7]
" LEFT JOIN bld_buildings" " FROM roo_rooms"
" ON roo_rooms.BldCod=bld_buildings.BldCod" " LEFT JOIN bld_buildings"
" WHERE roo_rooms.CtrCod=%ld" " ON roo_rooms.BldCod=bld_buildings.BldCod"
" ORDER BY %s", " WHERE roo_rooms.CtrCod=%ld"
Gbl.Hierarchy.Ctr.CtrCod, " ORDER BY %s",
OrderBySubQuery[Rooms->SelectedOrder]); Gbl.Hierarchy.Ctr.CtrCod,
OrderBySubQuery[Rooms->SelectedOrder]);
break; break;
case Roo_ONLY_SHRT_NAME: case Roo_ONLY_SHRT_NAME:
default: default:
NumRows = DB_QuerySELECT (&mysql_res,"can not get rooms", Rooms->Num = (unsigned)
"SELECT roo_rooms.RooCod," // row[0] DB_QuerySELECT (&mysql_res,"can not get rooms",
"roo_rooms.ShortName" // row[1] "SELECT roo_rooms.RooCod," // row[0]
" FROM roo_rooms LEFT JOIN bld_buildings" "roo_rooms.ShortName" // row[1]
" ON roo_rooms.BldCod=bld_buildings.BldCod" " FROM roo_rooms LEFT JOIN bld_buildings"
" WHERE roo_rooms.CtrCod=%ld" " ON roo_rooms.BldCod=bld_buildings.BldCod"
" ORDER BY %s", " WHERE roo_rooms.CtrCod=%ld"
Gbl.Hierarchy.Ctr.CtrCod, " ORDER BY %s",
OrderBySubQuery[Roo_ORDER_DEFAULT]); Gbl.Hierarchy.Ctr.CtrCod,
OrderBySubQuery[Roo_ORDER_DEFAULT]);
break; break;
} }
/***** Count number of rows in result *****/ /***** Count number of rows in result *****/
if (NumRows) // Rooms found... if (Rooms->Num) // Rooms found...
{ {
Rooms->Num = (unsigned) NumRows;
/***** Create list with courses in center *****/ /***** Create list with courses in center *****/
if ((Rooms->Lst = calloc (NumRows,sizeof (*Rooms->Lst))) == NULL) if ((Rooms->Lst = calloc ((size_t) Rooms->Num,
sizeof (*Rooms->Lst))) == NULL)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
/***** Get the rooms *****/ /***** Get the rooms *****/
@ -652,8 +653,6 @@ void Roo_GetListRooms (struct Roo_Rooms *Rooms,
} }
} }
} }
else
Rooms->Num = 0;
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
@ -667,28 +666,24 @@ static void Roo_GetDataOfRoomByCod (struct Roo_Room *Room)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
/***** Trivial check *****/ /***** Trivial check *****/
if (Room->RooCod <= 0) if (Room->RooCod <= 0)
return; return;
/***** Get data of a room from database *****/ /***** Get data of a room from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a room", if (DB_QuerySELECT (&mysql_res,"can not get data of a room",
"SELECT roo_rooms.BldCod," // row[0] "SELECT roo_rooms.BldCod," // row[0]
"bld_buildings.ShortName," // row[1] "bld_buildings.ShortName," // row[1]
"roo_rooms.Floor," // row[2] "roo_rooms.Floor," // row[2]
"roo_rooms.Type," // row[3] "roo_rooms.Type," // row[3]
"roo_rooms.ShortName," // row[4] "roo_rooms.ShortName," // row[4]
"roo_rooms.FullName," // row[5] "roo_rooms.FullName," // row[5]
"roo_rooms.Capacity" // row[6] "roo_rooms.Capacity" // row[6]
" FROM roo_rooms LEFT JOIN bld_buildings" " FROM roo_rooms LEFT JOIN bld_buildings"
" ON roo_rooms.BldCod=bld_buildings.BldCod" " ON roo_rooms.BldCod=bld_buildings.BldCod"
" WHERE roo_rooms.RooCod=%ld", " WHERE roo_rooms.RooCod=%ld",
Room->RooCod); Room->RooCod)) // Room found...
/***** Count number of rows in result *****/
if (NumRows) // Room found...
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);

View File

@ -693,7 +693,7 @@ static unsigned Sch_SearchOpenDocumentsInDB (const char *RangeQuery)
extern const char *Txt_open_documents; extern const char *Txt_open_documents;
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1]; char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
unsigned long NumDocs; unsigned NumDocs;
/***** Check user's permission *****/ /***** Check user's permission *****/
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_OPEN_DOCUMENTS)) if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_OPEN_DOCUMENTS))
@ -702,7 +702,7 @@ static unsigned Sch_SearchOpenDocumentsInDB (const char *RangeQuery)
"_latin1 "," COLLATE latin1_general_ci")) "_latin1 "," COLLATE latin1_general_ci"))
{ {
/***** Query database *****/ /***** Query database *****/
NumDocs = NumDocs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get files", DB_QuerySELECT (&mysql_res,"can not get files",
"SELECT *" "SELECT *"
" FROM " " FROM "
@ -841,7 +841,7 @@ static unsigned Sch_SearchOpenDocumentsInDB (const char *RangeQuery)
Txt_open_document, Txt_open_document,
Txt_open_documents); Txt_open_documents);
return (unsigned) NumDocs; return NumDocs;
} }
return 0; return 0;
@ -857,7 +857,7 @@ static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery)
extern const char *Txt_documents_in_my_courses; extern const char *Txt_documents_in_my_courses;
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1]; char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
unsigned long NumDocs; unsigned NumDocs;
/***** Check user's permission *****/ /***** Check user's permission *****/
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_DOCUM_IN_MY_COURSES)) if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_DOCUM_IN_MY_COURSES))
@ -906,7 +906,7 @@ static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery)
(unsigned) Brw_ADMI_MRK_GRP); (unsigned) Brw_ADMI_MRK_GRP);
/***** Build the query *****/ /***** Build the query *****/
NumDocs = NumDocs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get files", DB_QuerySELECT (&mysql_res,"can not get files",
"SELECT *" "SELECT *"
" FROM (" " FROM ("
@ -1007,7 +1007,7 @@ static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery)
"DROP TEMPORARY TABLE IF EXISTS my_files_crs," "DROP TEMPORARY TABLE IF EXISTS my_files_crs,"
"my_files_grp"); "my_files_grp");
return (unsigned) NumDocs; return NumDocs;
} }
return 0; return 0;
@ -1023,7 +1023,7 @@ static unsigned Sch_SearchMyDocumentsInDB (const char *RangeQuery)
extern const char *Txt_documents_from_me; extern const char *Txt_documents_from_me;
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1]; char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
unsigned long NumDocs; unsigned NumDocs;
/***** Check user's permission *****/ /***** Check user's permission *****/
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_MY_DOCUMENTS)) if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_MY_DOCUMENTS))
@ -1032,7 +1032,7 @@ static unsigned Sch_SearchMyDocumentsInDB (const char *RangeQuery)
"_latin1 "," COLLATE latin1_general_ci")) "_latin1 "," COLLATE latin1_general_ci"))
{ {
/***** Build the query *****/ /***** Build the query *****/
NumDocs = NumDocs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get files", DB_QuerySELECT (&mysql_res,"can not get files",
"SELECT *" "SELECT *"
" FROM (" " FROM ("
@ -1240,7 +1240,7 @@ static unsigned Sch_SearchMyDocumentsInDB (const char *RangeQuery)
Txt_document_from_me, Txt_document_from_me,
Txt_documents_from_me); Txt_documents_from_me);
return (unsigned) NumDocs; return NumDocs;
} }
return 0; return 0;

View File

@ -137,23 +137,24 @@ void Set_EditSettings (void)
void Set_GetSettingsFromIP (void) void Set_GetSettingsFromIP (void)
{ {
unsigned long NumRows; unsigned NumRows;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
if (Gbl.IP[0]) if (Gbl.IP[0])
{ {
/***** Get settings from database *****/ /***** Get settings from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get settings", NumRows = (unsigned)
"SELECT FirstDayOfWeek," // row[0] DB_QuerySELECT (&mysql_res,"can not get settings",
"DateFormat," // row[1] "SELECT FirstDayOfWeek," // row[0]
"Theme," // row[2] "DateFormat," // row[1]
"IconSet," // row[3] "Theme," // row[2]
"Menu," // row[4] "IconSet," // row[3]
"SideCols" // row[5] "Menu," // row[4]
" FROM set_ip_settings" "SideCols" // row[5]
" WHERE IP='%s'", " FROM set_ip_settings"
Gbl.IP); " WHERE IP='%s'",
Gbl.IP);
if (NumRows) if (NumRows)
{ {
if (NumRows != 1) if (NumRows != 1)

View File

@ -109,15 +109,17 @@ static void Sta_WriteSelectorCountType (const struct Sta_Stats *Stats);
static void Sta_WriteSelectorAction (const struct Sta_Stats *Stats); static void Sta_WriteSelectorAction (const struct Sta_Stats *Stats);
static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse); static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse);
static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats, static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res); MYSQL_RES *mysql_res);
static void Sta_WriteLogComments (long LogCod); static void Sta_WriteLogComments (long LogCod);
static void Sta_ShowNumHitsPerUsr (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerUsr (Sta_CountType_t CountType,
unsigned long NumRows,MYSQL_RES *mysql_res); unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_ShowNumHitsPerDay (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerDay (Sta_CountType_t CountType,
unsigned long NumRows,MYSQL_RES *mysql_res); unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_ShowDistrAccessesPerDayAndHour (const struct Sta_Stats *Stats, static void Sta_ShowDistrAccessesPerDayAndHour (const struct Sta_Stats *Stats,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res); MYSQL_RES *mysql_res);
static void Sta_PutHiddenParamScopeSta (void); static void Sta_PutHiddenParamScopeSta (void);
static Sta_ColorType_t Sta_GetStatColorType (void); static Sta_ColorType_t Sta_GetStatColorType (void);
@ -126,55 +128,56 @@ static void Sta_DrawAccessesPerHourForADay (Sta_ColorType_t ColorType,double Hit
static void Sta_SetColor (Sta_ColorType_t ColorType,double HitsNum,double HitsMax, static void Sta_SetColor (Sta_ColorType_t ColorType,double HitsNum,double HitsMax,
unsigned *R,unsigned *G,unsigned *B); unsigned *R,unsigned *G,unsigned *B);
static void Sta_ShowNumHitsPerWeek (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerWeek (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res); MYSQL_RES *mysql_res);
static void Sta_ShowNumHitsPerMonth (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerMonth (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res); MYSQL_RES *mysql_res);
static void Sta_ShowNumHitsPerYear (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerYear (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res); MYSQL_RES *mysql_res);
static void Sta_ShowNumHitsPerHour (unsigned long NumRows, static void Sta_ShowNumHitsPerHour (unsigned NumHits,
MYSQL_RES *mysql_res); MYSQL_RES *mysql_res);
static void Sta_WriteAccessHour (unsigned Hour,struct Sta_Hits *Hits,unsigned ColumnWidth); static void Sta_WriteAccessHour (unsigned Hour,struct Sta_Hits *Hits,unsigned ColumnWidth);
static void Sta_ShowAverageAccessesPerMinute (unsigned long NumRows,MYSQL_RES *mysql_res); static void Sta_ShowAverageAccessesPerMinute (unsigned NumHits,MYSQL_RES *mysql_res);
static void Sta_WriteLabelsXAxisAccMin (double IncX,const char *Format); static void Sta_WriteLabelsXAxisAccMin (double IncX,const char *Format);
static void Sta_WriteAccessMinute (unsigned Minute,double HitsNum,double MaxX); static void Sta_WriteAccessMinute (unsigned Minute,double HitsNum,double MaxX);
static void Sta_ShowNumHitsPerAction (Sta_CountType_t CountTypes, static void Sta_ShowNumHitsPerAction (Sta_CountType_t CountTypes,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res); MYSQL_RES *mysql_res);
static void Sta_ShowNumHitsPerPlugin (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerPlugin (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res); MYSQL_RES *mysql_res);
static void Sta_ShowNumHitsPerWSFunction (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerWSFunction (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res); MYSQL_RES *mysql_res);
static void Sta_ShowNumHitsPerBanner (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerBanner (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res); MYSQL_RES *mysql_res);
static void Sta_ShowNumHitsPerCountry (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerCountry (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res); MYSQL_RES *mysql_res);
static void Sta_WriteCountry (long CtyCod); static void Sta_WriteCountry (long CtyCod);
static void Sta_ShowNumHitsPerInstitution (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerInstitution (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res); MYSQL_RES *mysql_res);
static void Sta_WriteInstit (long InsCod); static void Sta_WriteInstit (long InsCod);
static void Sta_ShowNumHitsPerCenter (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerCenter (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res); MYSQL_RES *mysql_res);
static void Sta_WriteCenter (long CtrCod); static void Sta_WriteCenter (long CtrCod);
static void Sta_ShowNumHitsPerDegree (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerDegree (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res); MYSQL_RES *mysql_res);
static void Sta_WriteDegree (long DegCod); static void Sta_WriteDegree (long DegCod);
static void Sta_ShowNumHitsPerCourse (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerCourse (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res); MYSQL_RES *mysql_res);
static void Sta_DrawBarNumHits (char Color, static void Sta_DrawBarNumHits (char Color,
double HitsNum,double HitsMax,double HitsTotal, double HitsNum,double HitsMax,double HitsTotal,
unsigned MaxBarWidth); unsigned MaxBarWidth);
/*****************************************************************************/ /*****************************************************************************/
/**************************** Reset stats context ****************************/ /**************************** Reset stats context ****************************/
/*****************************************************************************/ /*****************************************************************************/
@ -754,7 +757,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
char QueryAux[512]; char QueryAux[512];
long LengthQuery; long LengthQuery;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
unsigned long NumRows; unsigned NumHits;
const char *LogTable; const char *LogTable;
Sta_ClicksDetailedOrGrouped_t DetailedOrGrouped = Sta_CLICKS_GROUPED; Sta_ClicksDetailedOrGrouped_t DetailedOrGrouped = Sta_CLICKS_GROUPED;
struct UsrData UsrDat; struct UsrData UsrDat;
@ -1416,12 +1419,13 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
*/ */
/***** Make the query *****/ /***** Make the query *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks", NumHits = (unsigned)
"%s", DB_QuerySELECT (&mysql_res,"can not get clicks",
Query); "%s",
Query);
/***** Count the number of rows in result *****/ /***** Count the number of rows in result *****/
if (NumRows == 0) if (NumHits == 0)
Ale_ShowAlert (Ale_INFO,Txt_There_are_no_accesses_with_the_selected_search_criteria); Ale_ShowAlert (Ale_INFO,Txt_There_are_no_accesses_with_the_selected_search_criteria);
else else
{ {
@ -1439,66 +1443,66 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
switch (Stats.ClicksGroupedBy) switch (Stats.ClicksGroupedBy)
{ {
case Sta_CLICKS_CRS_DETAILED_LIST: case Sta_CLICKS_CRS_DETAILED_LIST:
Sta_ShowDetailedAccessesList (&Stats,NumRows,mysql_res); Sta_ShowDetailedAccessesList (&Stats,NumHits,mysql_res);
break; break;
case Sta_CLICKS_CRS_PER_USR: case Sta_CLICKS_CRS_PER_USR:
Sta_ShowNumHitsPerUsr (Stats.CountType,NumRows,mysql_res); Sta_ShowNumHitsPerUsr (Stats.CountType,NumHits,mysql_res);
break; break;
case Sta_CLICKS_CRS_PER_DAY: case Sta_CLICKS_CRS_PER_DAY:
case Sta_CLICKS_GBL_PER_DAY: case Sta_CLICKS_GBL_PER_DAY:
Sta_ShowNumHitsPerDay (Stats.CountType,NumRows,mysql_res); Sta_ShowNumHitsPerDay (Stats.CountType,NumHits,mysql_res);
break; break;
case Sta_CLICKS_CRS_PER_DAY_AND_HOUR: case Sta_CLICKS_CRS_PER_DAY_AND_HOUR:
case Sta_CLICKS_GBL_PER_DAY_AND_HOUR: case Sta_CLICKS_GBL_PER_DAY_AND_HOUR:
Sta_ShowDistrAccessesPerDayAndHour (&Stats,NumRows,mysql_res); Sta_ShowDistrAccessesPerDayAndHour (&Stats,NumHits,mysql_res);
break; break;
case Sta_CLICKS_CRS_PER_WEEK: case Sta_CLICKS_CRS_PER_WEEK:
case Sta_CLICKS_GBL_PER_WEEK: case Sta_CLICKS_GBL_PER_WEEK:
Sta_ShowNumHitsPerWeek (Stats.CountType,NumRows,mysql_res); Sta_ShowNumHitsPerWeek (Stats.CountType,NumHits,mysql_res);
break; break;
case Sta_CLICKS_CRS_PER_MONTH: case Sta_CLICKS_CRS_PER_MONTH:
case Sta_CLICKS_GBL_PER_MONTH: case Sta_CLICKS_GBL_PER_MONTH:
Sta_ShowNumHitsPerMonth (Stats.CountType,NumRows,mysql_res); Sta_ShowNumHitsPerMonth (Stats.CountType,NumHits,mysql_res);
break; break;
case Sta_CLICKS_CRS_PER_YEAR: case Sta_CLICKS_CRS_PER_YEAR:
case Sta_CLICKS_GBL_PER_YEAR: case Sta_CLICKS_GBL_PER_YEAR:
Sta_ShowNumHitsPerYear (Stats.CountType,NumRows,mysql_res); Sta_ShowNumHitsPerYear (Stats.CountType,NumHits,mysql_res);
break; break;
case Sta_CLICKS_CRS_PER_HOUR: case Sta_CLICKS_CRS_PER_HOUR:
case Sta_CLICKS_GBL_PER_HOUR: case Sta_CLICKS_GBL_PER_HOUR:
Sta_ShowNumHitsPerHour (NumRows,mysql_res); Sta_ShowNumHitsPerHour (NumHits,mysql_res);
break; break;
case Sta_CLICKS_CRS_PER_MINUTE: case Sta_CLICKS_CRS_PER_MINUTE:
case Sta_CLICKS_GBL_PER_MINUTE: case Sta_CLICKS_GBL_PER_MINUTE:
Sta_ShowAverageAccessesPerMinute (NumRows,mysql_res); Sta_ShowAverageAccessesPerMinute (NumHits,mysql_res);
break; break;
case Sta_CLICKS_CRS_PER_ACTION: case Sta_CLICKS_CRS_PER_ACTION:
case Sta_CLICKS_GBL_PER_ACTION: case Sta_CLICKS_GBL_PER_ACTION:
Sta_ShowNumHitsPerAction (Stats.CountType,NumRows,mysql_res); Sta_ShowNumHitsPerAction (Stats.CountType,NumHits,mysql_res);
break; break;
case Sta_CLICKS_GBL_PER_PLUGIN: case Sta_CLICKS_GBL_PER_PLUGIN:
Sta_ShowNumHitsPerPlugin (Stats.CountType,NumRows,mysql_res); Sta_ShowNumHitsPerPlugin (Stats.CountType,NumHits,mysql_res);
break; break;
case Sta_CLICKS_GBL_PER_API_FUNCTION: case Sta_CLICKS_GBL_PER_API_FUNCTION:
Sta_ShowNumHitsPerWSFunction (Stats.CountType,NumRows,mysql_res); Sta_ShowNumHitsPerWSFunction (Stats.CountType,NumHits,mysql_res);
break; break;
case Sta_CLICKS_GBL_PER_BANNER: case Sta_CLICKS_GBL_PER_BANNER:
Sta_ShowNumHitsPerBanner (Stats.CountType,NumRows,mysql_res); Sta_ShowNumHitsPerBanner (Stats.CountType,NumHits,mysql_res);
break; break;
case Sta_CLICKS_GBL_PER_COUNTRY: case Sta_CLICKS_GBL_PER_COUNTRY:
Sta_ShowNumHitsPerCountry (Stats.CountType,NumRows,mysql_res); Sta_ShowNumHitsPerCountry (Stats.CountType,NumHits,mysql_res);
break; break;
case Sta_CLICKS_GBL_PER_INSTITUTION: case Sta_CLICKS_GBL_PER_INSTITUTION:
Sta_ShowNumHitsPerInstitution (Stats.CountType,NumRows,mysql_res); Sta_ShowNumHitsPerInstitution (Stats.CountType,NumHits,mysql_res);
break; break;
case Sta_CLICKS_GBL_PER_CENTER: case Sta_CLICKS_GBL_PER_CENTER:
Sta_ShowNumHitsPerCenter (Stats.CountType,NumRows,mysql_res); Sta_ShowNumHitsPerCenter (Stats.CountType,NumHits,mysql_res);
break; break;
case Sta_CLICKS_GBL_PER_DEGREE: case Sta_CLICKS_GBL_PER_DEGREE:
Sta_ShowNumHitsPerDegree (Stats.CountType,NumRows,mysql_res); Sta_ShowNumHitsPerDegree (Stats.CountType,NumHits,mysql_res);
break; break;
case Sta_CLICKS_GBL_PER_COURSE: case Sta_CLICKS_GBL_PER_COURSE:
Sta_ShowNumHitsPerCourse (Stats.CountType,NumRows,mysql_res); Sta_ShowNumHitsPerCourse (Stats.CountType,NumHits,mysql_res);
break; break;
} }
HTM_TABLE_End (); HTM_TABLE_End ();
@ -1546,7 +1550,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
/*****************************************************************************/ /*****************************************************************************/
static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats, static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res) MYSQL_RES *mysql_res)
{ {
extern Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD]; extern Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD];
@ -1565,12 +1569,12 @@ static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
extern const char *Txt_Action; extern const char *Txt_Action;
extern const char *Txt_LOG_More_info; extern const char *Txt_LOG_More_info;
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
unsigned long NumRow; unsigned NumRow;
unsigned long FirstRow; // First row to show unsigned FirstRow; // First row to show
unsigned long LastRow; // Last rows to show unsigned LastRow; // Last rows to show
unsigned long NumPagesBefore; unsigned NumPagesBefore;
unsigned long NumPagesAfter; unsigned NumPagesAfter;
unsigned long NumPagsTotal; unsigned NumPagsTotal;
struct UsrData UsrDat; struct UsrData UsrDat;
MYSQL_ROW row; MYSQL_ROW row;
long LogCod; long LogCod;
@ -1588,15 +1592,15 @@ static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
if (FirstRow == 0 && LastRow == 0) // Call from main form if (FirstRow == 0 && LastRow == 0) // Call from main form
{ {
// Show last clicks // Show last clicks
FirstRow = (NumRows / Stats->RowsPerPage - 1) * Stats->RowsPerPage + 1; FirstRow = (NumHits / Stats->RowsPerPage - 1) * Stats->RowsPerPage + 1;
if ((FirstRow + Stats->RowsPerPage - 1) < NumRows) if ((FirstRow + Stats->RowsPerPage - 1) < NumHits)
FirstRow += Stats->RowsPerPage; FirstRow += Stats->RowsPerPage;
LastRow = NumRows; LastRow = NumHits;
} }
if (FirstRow < 1) // For security reasons; really it should never be less than 1 if (FirstRow < 1) // For security reasons; really it should never be less than 1
FirstRow = 1; FirstRow = 1;
if (LastRow > NumRows) if (LastRow > NumHits)
LastRow = NumRows; LastRow = NumHits;
if ((LastRow - FirstRow) >= Stats->RowsPerPage) // For if there have been clicks that have increased the number of rows if ((LastRow - FirstRow) >= Stats->RowsPerPage) // For if there have been clicks that have increased the number of rows
LastRow = FirstRow + Stats->RowsPerPage - 1; LastRow = FirstRow + Stats->RowsPerPage - 1;
@ -1606,8 +1610,8 @@ static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
if (NumPagesBefore * Stats->RowsPerPage < (FirstRow-1)) if (NumPagesBefore * Stats->RowsPerPage < (FirstRow-1))
NumPagesBefore++; NumPagesBefore++;
/* Number of pages after the current one */ /* Number of pages after the current one */
NumPagesAfter = (NumRows - LastRow) / Stats->RowsPerPage; NumPagesAfter = (NumHits - LastRow) / Stats->RowsPerPage;
if (NumPagesAfter * Stats->RowsPerPage < (NumRows - LastRow)) if (NumPagesAfter * Stats->RowsPerPage < (NumHits - LastRow))
NumPagesAfter++; NumPagesAfter++;
/* Count the total number of pages */ /* Count the total number of pages */
NumPagsTotal = NumPagesBefore + 1 + NumPagesAfter; NumPagsTotal = NumPagesBefore + 1 + NumPagesAfter;
@ -1650,15 +1654,15 @@ static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
/* Write number of current page */ /* Write number of current page */
HTM_TD_Begin ("class=\"DAT_N CM\""); HTM_TD_Begin ("class=\"DAT_N CM\"");
HTM_STRONG_Begin (); HTM_STRONG_Begin ();
HTM_TxtF ("%s %lu-%lu %s %lu (%s %ld %s %lu)", HTM_TxtF ("%s %u-%u %s %u (%s %u %s %u)",
Txt_Clicks, Txt_Clicks,
FirstRow,LastRow,Txt_of_PART_OF_A_TOTAL,NumRows, FirstRow,LastRow,Txt_of_PART_OF_A_TOTAL,NumHits,
Txt_page,NumPagesBefore + 1,Txt_of_PART_OF_A_TOTAL,NumPagsTotal); Txt_page,NumPagesBefore + 1,Txt_of_PART_OF_A_TOTAL,NumPagsTotal);
HTM_STRONG_End (); HTM_STRONG_End ();
HTM_TD_End (); HTM_TD_End ();
/* Put link to jump to next page (more recent clicks) */ /* Put link to jump to next page (more recent clicks) */
if (LastRow < NumRows) if (LastRow < NumHits)
{ {
Frm_StartFormAnchor (ActSeeAccCrs,Sta_STAT_RESULTS_SECTION_ID); Frm_StartFormAnchor (ActSeeAccCrs,Sta_STAT_RESULTS_SECTION_ID);
Dat_WriteParamsIniEndDates (); Dat_WriteParamsIniEndDates ();
@ -1670,7 +1674,7 @@ static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
Usr_PutHiddenParSelectedUsrsCods (&Gbl.Usrs.Selected); Usr_PutHiddenParSelectedUsrsCods (&Gbl.Usrs.Selected);
} }
HTM_TD_Begin ("class=\"RM\""); HTM_TD_Begin ("class=\"RM\"");
if (LastRow < NumRows) if (LastRow < NumHits)
{ {
HTM_BUTTON_SUBMIT_Begin (Str_BuildStringLong (Txt_Show_next_X_clicks, HTM_BUTTON_SUBMIT_Begin (Str_BuildStringLong (Txt_Show_next_X_clicks,
(long) Stats->RowsPerPage), (long) Stats->RowsPerPage),
@ -1682,7 +1686,7 @@ static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
HTM_BUTTON_End (); HTM_BUTTON_End ();
} }
HTM_TD_End (); HTM_TD_End ();
if (LastRow < NumRows) if (LastRow < NumHits)
Frm_EndForm (); Frm_EndForm ();
HTM_TR_End (); HTM_TR_End ();
@ -1726,7 +1730,7 @@ static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
/* Write the number of row */ /* Write the number of row */
HTM_TD_Begin ("class=\"LOG RT COLOR%u\"",Gbl.RowEvenOdd); HTM_TD_Begin ("class=\"LOG RT COLOR%u\"",Gbl.RowEvenOdd);
HTM_TxtF ("%ld&nbsp;",NumRow); HTM_TxtF ("%u&nbsp;",NumRow);
HTM_TD_End (); HTM_TD_End ();
/* Write the user's ID if user is a student */ /* Write the user's ID if user is a student */
@ -1804,7 +1808,8 @@ static void Sta_WriteLogComments (long LogCod)
/*****************************************************************************/ /*****************************************************************************/
static void Sta_ShowNumHitsPerUsr (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerUsr (Sta_CountType_t CountType,
unsigned long NumRows,MYSQL_RES *mysql_res) unsigned NumHits,
MYSQL_RES *mysql_res)
{ {
extern const char *Txt_No_INDEX; extern const char *Txt_No_INDEX;
extern const char *Txt_Photo; extern const char *Txt_Photo;
@ -1814,7 +1819,7 @@ static void Sta_ShowNumHitsPerUsr (Sta_CountType_t CountType,
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES]; extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRow; unsigned NumHit;
struct Sta_Hits Hits; struct Sta_Hits Hits;
unsigned BarWidth; unsigned BarWidth;
struct UsrData UsrDat; struct UsrData UsrDat;
@ -1835,9 +1840,9 @@ static void Sta_ShowNumHitsPerUsr (Sta_CountType_t CountType,
HTM_TR_End (); HTM_TR_End ();
/***** Write rows *****/ /***** Write rows *****/
for (NumRow = 1, Hits.Max = 0.0, Gbl.RowEvenOdd = 0; for (NumHit = 1, Hits.Max = 0.0, Gbl.RowEvenOdd = 0;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd) NumHit++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1849,7 +1854,7 @@ static void Sta_ShowNumHitsPerUsr (Sta_CountType_t CountType,
/* Write the number of row */ /* Write the number of row */
HTM_TD_Begin ("class=\"LOG RT COLOR%u\"",Gbl.RowEvenOdd); HTM_TD_Begin ("class=\"LOG RT COLOR%u\"",Gbl.RowEvenOdd);
HTM_TxtF ("%ld&nbsp;",NumRow); HTM_TxtF ("%u&nbsp;",NumHit);
HTM_TD_End (); HTM_TD_End ();
/* Show the photo */ /* Show the photo */
@ -1875,7 +1880,7 @@ static void Sta_ShowNumHitsPerUsr (Sta_CountType_t CountType,
/* Write the number of clicks */ /* Write the number of clicks */
Hits.Num = Str_GetDoubleFromStr (row[1]); Hits.Num = Str_GetDoubleFromStr (row[1]);
if (NumRow == 1) if (NumHits == 1)
Hits.Max = Hits.Num; Hits.Max = Hits.Num;
if (Hits.Max > 0.0) if (Hits.Max > 0.0)
{ {
@ -1912,13 +1917,14 @@ static void Sta_ShowNumHitsPerUsr (Sta_CountType_t CountType,
/*****************************************************************************/ /*****************************************************************************/
static void Sta_ShowNumHitsPerDay (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerDay (Sta_CountType_t CountType,
unsigned long NumRows,MYSQL_RES *mysql_res) unsigned NumHits,
MYSQL_RES *mysql_res)
{ {
extern const char *Txt_Date; extern const char *Txt_Date;
extern const char *Txt_Day; extern const char *Txt_Day;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES]; extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
extern const char *Txt_DAYS_SMALL[7]; extern const char *Txt_DAYS_SMALL[7];
unsigned long NumRow; unsigned NumHit;
struct Date ReadDate; struct Date ReadDate;
struct Date LastDate; struct Date LastDate;
struct Date Date; struct Date Date;
@ -1942,13 +1948,13 @@ static void Sta_ShowNumHitsPerDay (Sta_CountType_t CountType,
HTM_TR_End (); HTM_TR_End ();
/***** Compute maximum number of pages generated per day *****/ /***** Compute maximum number of pages generated per day *****/
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1); Sta_ComputeMaxAndTotalHits (&Hits,NumHits,mysql_res,1,1);
/***** Write rows beginning by the most recent day and ending by the oldest *****/ /***** Write rows beginning by the most recent day and ending by the oldest *****/
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
for (NumRow = 1; for (NumHit = 1;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1974,13 +1980,13 @@ static void Sta_ShowNumHitsPerDay (Sta_CountType_t CountType,
/* Write the date */ /* Write the date */
Dat_ConvDateToDateStr (&Date,StrDate); Dat_ConvDateToDateStr (&Date,StrDate);
HTM_TD_Begin ("class=\"%s RT\"",NumDayWeek == 6 ? "LOG_R" : HTM_TD_Begin ("class=\"%s RT\"",NumDayWeek == 6 ? "LOG_R" :
"LOG"); "LOG");
HTM_TxtF ("%s&nbsp;",StrDate); HTM_TxtF ("%s&nbsp;",StrDate);
HTM_TD_End (); HTM_TD_End ();
/* Write the day of the week */ /* Write the day of the week */
HTM_TD_Begin ("class=\"%s LT\"",NumDayWeek == 6 ? "LOG_R" : HTM_TD_Begin ("class=\"%s LT\"",NumDayWeek == 6 ? "LOG_R" :
"LOG"); "LOG");
HTM_TxtF ("%s&nbsp;",Txt_DAYS_SMALL[NumDayWeek]); HTM_TxtF ("%s&nbsp;",Txt_DAYS_SMALL[NumDayWeek]);
HTM_TD_End (); HTM_TD_End ();
@ -2013,13 +2019,13 @@ static void Sta_ShowNumHitsPerDay (Sta_CountType_t CountType,
/* Write the date */ /* Write the date */
Dat_ConvDateToDateStr (&Date,StrDate); Dat_ConvDateToDateStr (&Date,StrDate);
HTM_TD_Begin ("class=\"%s RT\"",NumDayWeek == 6 ? "LOG_R" : HTM_TD_Begin ("class=\"%s RT\"",NumDayWeek == 6 ? "LOG_R" :
"LOG"); "LOG");
HTM_TxtF ("%s&nbsp;",StrDate); HTM_TxtF ("%s&nbsp;",StrDate);
HTM_TD_End (); HTM_TD_End ();
/* Write the day of the week */ /* Write the day of the week */
HTM_TD_Begin ("class=\"%s LT\"",NumDayWeek == 6 ? "LOG_R" : HTM_TD_Begin ("class=\"%s LT\"",NumDayWeek == 6 ? "LOG_R" :
"LOG"); "LOG");
HTM_TxtF ("%s&nbsp;",Txt_DAYS_SMALL[NumDayWeek]); HTM_TxtF ("%s&nbsp;",Txt_DAYS_SMALL[NumDayWeek]);
HTM_TD_End (); HTM_TD_End ();
@ -2043,7 +2049,7 @@ static void Sta_ShowNumHitsPerDay (Sta_CountType_t CountType,
#define GRAPH_DISTRIBUTION_PER_HOUR_TOTAL_WIDTH (GRAPH_DISTRIBUTION_PER_HOUR_HOUR_WIDTH * 24) #define GRAPH_DISTRIBUTION_PER_HOUR_TOTAL_WIDTH (GRAPH_DISTRIBUTION_PER_HOUR_HOUR_WIDTH * 24)
static void Sta_ShowDistrAccessesPerDayAndHour (const struct Sta_Stats *Stats, static void Sta_ShowDistrAccessesPerDayAndHour (const struct Sta_Stats *Stats,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res) MYSQL_RES *mysql_res)
{ {
extern const char *The_ClassFormInBox[The_NUM_THEMES]; extern const char *The_ClassFormInBox[The_NUM_THEMES];
@ -2056,7 +2062,7 @@ static void Sta_ShowDistrAccessesPerDayAndHour (const struct Sta_Stats *Stats,
Sta_ColorType_t ColorType; Sta_ColorType_t ColorType;
unsigned ColorTypeUnsigned; unsigned ColorTypeUnsigned;
Sta_ColorType_t SelectedColorType; Sta_ColorType_t SelectedColorType;
unsigned long NumRow; unsigned NumHit;
struct Date PreviousReadDate; struct Date PreviousReadDate;
struct Date CurrentReadDate; struct Date CurrentReadDate;
struct Date LastDate; struct Date LastDate;
@ -2113,7 +2119,7 @@ static void Sta_ShowDistrAccessesPerDayAndHour (const struct Sta_Stats *Stats,
HTM_TR_End (); HTM_TR_End ();
/***** Compute maximum number of pages generated per day-hour *****/ /***** Compute maximum number of pages generated per day-hour *****/
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,2,1); Sta_ComputeMaxAndTotalHits (&Hits,NumHits,mysql_res,2,1);
/***** Initialize LastDate *****/ /***** Initialize LastDate *****/
Dat_AssignDate (&LastDate,&Gbl.DateRange.DateEnd.Date); Dat_AssignDate (&LastDate,&Gbl.DateRange.DateEnd.Date);
@ -2154,9 +2160,9 @@ static void Sta_ShowDistrAccessesPerDayAndHour (const struct Sta_Stats *Stats,
/***** Write rows beginning by the most recent day and ending by the oldest one *****/ /***** Write rows beginning by the most recent day and ending by the oldest one *****/
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
for (NumRow = 1; for (NumHit = 1;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -2172,7 +2178,7 @@ static void Sta_ShowDistrAccessesPerDayAndHour (const struct Sta_Stats *Stats,
Hits.Num = Str_GetDoubleFromStr (row[2]); Hits.Num = Str_GetDoubleFromStr (row[2]);
/* If this is the first read date, initialize PreviousReadDate */ /* If this is the first read date, initialize PreviousReadDate */
if (NumRow == 1) if (NumHit == 1)
Dat_AssignDate (&PreviousReadDate,&CurrentReadDate); Dat_AssignDate (&PreviousReadDate,&CurrentReadDate);
/* Update number of hits per hour */ /* Update number of hits per hour */
@ -2493,12 +2499,12 @@ static void Sta_SetColor (Sta_ColorType_t ColorType,double HitsNum,double HitsMa
/*****************************************************************************/ /*****************************************************************************/
static void Sta_ShowNumHitsPerWeek (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerWeek (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res) MYSQL_RES *mysql_res)
{ {
extern const char *Txt_Week; extern const char *Txt_Week;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES]; extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow; unsigned NumHit;
struct Date ReadDate; struct Date ReadDate;
struct Date LastDate; struct Date LastDate;
struct Date Date; struct Date Date;
@ -2520,13 +2526,13 @@ static void Sta_ShowNumHitsPerWeek (Sta_CountType_t CountType,
HTM_TR_End (); HTM_TR_End ();
/***** Compute maximum number of pages generated per week *****/ /***** Compute maximum number of pages generated per week *****/
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1); Sta_ComputeMaxAndTotalHits (&Hits,NumHits,mysql_res,1,1);
/***** Write rows *****/ /***** Write rows *****/
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
for (NumRow = 1; for (NumHit = 1;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -2595,12 +2601,12 @@ static void Sta_ShowNumHitsPerWeek (Sta_CountType_t CountType,
/*****************************************************************************/ /*****************************************************************************/
static void Sta_ShowNumHitsPerMonth (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerMonth (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res) MYSQL_RES *mysql_res)
{ {
extern const char *Txt_Month; extern const char *Txt_Month;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES]; extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow; unsigned NumHit;
struct Date ReadDate; struct Date ReadDate;
struct Date LastDate; struct Date LastDate;
struct Date Date; struct Date Date;
@ -2621,13 +2627,13 @@ static void Sta_ShowNumHitsPerMonth (Sta_CountType_t CountType,
HTM_TR_End (); HTM_TR_End ();
/***** Compute maximum number of pages generated per month *****/ /***** Compute maximum number of pages generated per month *****/
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1); Sta_ComputeMaxAndTotalHits (&Hits,NumHits,mysql_res,1,1);
/***** Write rows *****/ /***** Write rows *****/
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
for (NumRow = 1; for (NumHit = 1;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -2696,12 +2702,12 @@ static void Sta_ShowNumHitsPerMonth (Sta_CountType_t CountType,
/*****************************************************************************/ /*****************************************************************************/
static void Sta_ShowNumHitsPerYear (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerYear (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res) MYSQL_RES *mysql_res)
{ {
extern const char *Txt_Year; extern const char *Txt_Year;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES]; extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow; unsigned NumHit;
struct Date ReadDate; struct Date ReadDate;
struct Date LastDate; struct Date LastDate;
struct Date Date; struct Date Date;
@ -2722,13 +2728,13 @@ static void Sta_ShowNumHitsPerYear (Sta_CountType_t CountType,
HTM_TR_End (); HTM_TR_End ();
/***** Compute maximum number of pages generated per year *****/ /***** Compute maximum number of pages generated per year *****/
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1); Sta_ComputeMaxAndTotalHits (&Hits,NumHits,mysql_res,1,1);
/***** Write rows *****/ /***** Write rows *****/
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
for (NumRow = 1; for (NumHit = 1;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -2798,10 +2804,10 @@ static void Sta_ShowNumHitsPerYear (Sta_CountType_t CountType,
#define DIGIT_WIDTH 6 #define DIGIT_WIDTH 6
static void Sta_ShowNumHitsPerHour (unsigned long NumRows, static void Sta_ShowNumHitsPerHour (unsigned NumHits,
MYSQL_RES *mysql_res) MYSQL_RES *mysql_res)
{ {
unsigned long NumRow; unsigned NumHit;
struct Sta_Hits Hits; struct Sta_Hits Hits;
unsigned NumDays; unsigned NumDays;
unsigned Hour = 0; unsigned Hour = 0;
@ -2814,7 +2820,7 @@ static void Sta_ShowNumHitsPerHour (unsigned long NumRows,
if ((NumDays = Dat_GetNumDaysBetweenDates (&Gbl.DateRange.DateIni.Date,&Gbl.DateRange.DateEnd.Date))) if ((NumDays = Dat_GetNumDaysBetweenDates (&Gbl.DateRange.DateIni.Date,&Gbl.DateRange.DateEnd.Date)))
{ {
/***** Compute maximum number of pages generated per hour *****/ /***** Compute maximum number of pages generated per hour *****/
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,NumDays); Sta_ComputeMaxAndTotalHits (&Hits,NumHits,mysql_res,1,NumDays);
/***** Compute width of columns (one for each hour) *****/ /***** Compute width of columns (one for each hour) *****/
/* Maximum number of dígits. If less than 4, set it to 4 to ensure a minimum width */ /* Maximum number of dígits. If less than 4, set it to 4 to ensure a minimum width */
@ -2824,15 +2830,15 @@ static void Sta_ShowNumHitsPerHour (unsigned long NumRows,
/***** Draw the graphic *****/ /***** Draw the graphic *****/
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
NumRow = 1; NumHit = 1;
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
while (Hour < 24) while (Hour < 24)
{ {
Hits.Num = 0.0; Hits.Num = 0.0;
if (NumRow <= NumRows) // If not read yet all the results of the query if (NumHit <= NumHits) // If not read yet all the results of the query
{ {
row = mysql_fetch_row (mysql_res); // Get next result row = mysql_fetch_row (mysql_res); // Get next result
NumRow++; NumHit++;
if (sscanf (row[0],"%02u",&ReadHour) != 1) // In row[0] is the date in HH format if (sscanf (row[0],"%02u",&ReadHour) != 1) // In row[0] is the date in HH format
Lay_ShowErrorAndExit ("Wrong hour."); Lay_ShowErrorAndExit ("Wrong hour.");
@ -2901,9 +2907,9 @@ static void Sta_WriteAccessHour (unsigned Hour,struct Sta_Hits *Hits,unsigned Co
#define Sta_WIDTH_SEMIDIVISION_GRAPHIC 30 #define Sta_WIDTH_SEMIDIVISION_GRAPHIC 30
#define Sta_NUM_DIVISIONS_X 10 #define Sta_NUM_DIVISIONS_X 10
static void Sta_ShowAverageAccessesPerMinute (unsigned long NumRows,MYSQL_RES *mysql_res) static void Sta_ShowAverageAccessesPerMinute (unsigned NumHits,MYSQL_RES *mysql_res)
{ {
unsigned long NumRow = 1; unsigned NumHit = 1;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumDays; unsigned NumDays;
unsigned MinuteDay = 0; unsigned MinuteDay = 0;
@ -2924,10 +2930,10 @@ static void Sta_ShowAverageAccessesPerMinute (unsigned long NumRows,MYSQL_RES *m
Hits.Max = 0.0; Hits.Max = 0.0;
while (MinuteDay < Sta_NUM_MINUTES_PER_DAY) while (MinuteDay < Sta_NUM_MINUTES_PER_DAY)
{ {
if (NumRow <= NumRows) // If not all the result of the query are yet read if (NumHit <= NumHits) // If not all the result of the query are yet read
{ {
row = mysql_fetch_row (mysql_res); // Get next result row = mysql_fetch_row (mysql_res); // Get next result
NumRow++; NumHit++;
if (sscanf (row[0],"%02u%02u",&ReadHour,&MinuteRead) != 2) // In row[0] is the date in formato HHMM if (sscanf (row[0],"%02u%02u",&ReadHour,&MinuteRead) != 2) // In row[0] is the date in formato HHMM
Lay_ShowErrorAndExit ("Wrong hour-minute."); Lay_ShowErrorAndExit ("Wrong hour-minute.");
/* Get number of pages generated */ /* Get number of pages generated */
@ -3122,13 +3128,13 @@ static void Sta_WriteAccessMinute (unsigned Minute,double HitsNum,double MaxX)
/*****************************************************************************/ /*****************************************************************************/
static void Sta_ShowNumHitsPerAction (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerAction (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res) MYSQL_RES *mysql_res)
{ {
extern Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD]; extern Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD];
extern const char *Txt_Action; extern const char *Txt_Action;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES]; extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow; unsigned NumHit;
struct Sta_Hits Hits; struct Sta_Hits Hits;
MYSQL_ROW row; MYSQL_ROW row;
long ActCod; long ActCod;
@ -3142,13 +3148,13 @@ static void Sta_ShowNumHitsPerAction (Sta_CountType_t CountType,
HTM_TR_End (); HTM_TR_End ();
/***** Compute maximum number of pages generated per day *****/ /***** Compute maximum number of pages generated per day *****/
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1); Sta_ComputeMaxAndTotalHits (&Hits,NumHits,mysql_res,1,1);
/***** Write rows *****/ /***** Write rows *****/
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
for (NumRow = 1; for (NumHit = 1;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3178,12 +3184,12 @@ static void Sta_ShowNumHitsPerAction (Sta_CountType_t CountType,
/*****************************************************************************/ /*****************************************************************************/
static void Sta_ShowNumHitsPerPlugin (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerPlugin (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res) MYSQL_RES *mysql_res)
{ {
extern const char *Txt_Plugin; extern const char *Txt_Plugin;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES]; extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow; unsigned NumHit;
struct Sta_Hits Hits; struct Sta_Hits Hits;
MYSQL_ROW row; MYSQL_ROW row;
struct Plugin Plg; struct Plugin Plg;
@ -3197,13 +3203,13 @@ static void Sta_ShowNumHitsPerPlugin (Sta_CountType_t CountType,
HTM_TR_End (); HTM_TR_End ();
/***** Compute maximum number of pages generated per plugin *****/ /***** Compute maximum number of pages generated per plugin *****/
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1); Sta_ComputeMaxAndTotalHits (&Hits,NumHits,mysql_res,1,1);
/***** Write rows *****/ /***** Write rows *****/
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
for (NumRow = 1; for (NumHit = 1;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3234,12 +3240,12 @@ static void Sta_ShowNumHitsPerPlugin (Sta_CountType_t CountType,
/*****************************************************************************/ /*****************************************************************************/
static void Sta_ShowNumHitsPerWSFunction (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerWSFunction (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res) MYSQL_RES *mysql_res)
{ {
extern const char *Txt_Function; extern const char *Txt_Function;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES]; extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow; unsigned NumHit;
struct Sta_Hits Hits; struct Sta_Hits Hits;
MYSQL_ROW row; MYSQL_ROW row;
long FunCod; long FunCod;
@ -3253,13 +3259,13 @@ static void Sta_ShowNumHitsPerWSFunction (Sta_CountType_t CountType,
HTM_TR_End (); HTM_TR_End ();
/***** Compute maximum number of pages generated per function *****/ /***** Compute maximum number of pages generated per function *****/
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1); Sta_ComputeMaxAndTotalHits (&Hits,NumHits,mysql_res,1,1);
/***** Write rows *****/ /***** Write rows *****/
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
for (NumRow = 1; for (NumHit = 1;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3287,12 +3293,12 @@ static void Sta_ShowNumHitsPerWSFunction (Sta_CountType_t CountType,
/*****************************************************************************/ /*****************************************************************************/
static void Sta_ShowNumHitsPerBanner (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerBanner (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res) MYSQL_RES *mysql_res)
{ {
extern const char *Txt_Banner; extern const char *Txt_Banner;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES]; extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow; unsigned NumHit;
double NumClicks; double NumClicks;
double MaxClicks = 0.0; double MaxClicks = 0.0;
double TotalClicks = 0.0; double TotalClicks = 0.0;
@ -3308,24 +3314,24 @@ static void Sta_ShowNumHitsPerBanner (Sta_CountType_t CountType,
HTM_TR_End (); HTM_TR_End ();
/***** Compute maximum number of clicks per banner *****/ /***** Compute maximum number of clicks per banner *****/
for (NumRow = 1; for (NumHit = 1;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
/* Get number of pages generated */ /* Get number of pages generated */
NumClicks = Str_GetDoubleFromStr (row[1]); NumClicks = Str_GetDoubleFromStr (row[1]);
if (NumRow == 1) if (NumHit == 1)
MaxClicks = NumClicks; MaxClicks = NumClicks;
TotalClicks += NumClicks; TotalClicks += NumClicks;
} }
/***** Write rows *****/ /***** Write rows *****/
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
for (NumRow = 1; for (NumHit = 1;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3357,14 +3363,14 @@ static void Sta_ShowNumHitsPerBanner (Sta_CountType_t CountType,
/*****************************************************************************/ /*****************************************************************************/
static void Sta_ShowNumHitsPerCountry (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerCountry (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res) MYSQL_RES *mysql_res)
{ {
extern const char *Txt_No_INDEX; extern const char *Txt_No_INDEX;
extern const char *Txt_Country; extern const char *Txt_Country;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES]; extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow; unsigned NumHit;
unsigned long Ranking; unsigned Ranking;
struct Sta_Hits Hits; struct Sta_Hits Hits;
MYSQL_ROW row; MYSQL_ROW row;
long CtyCod; long CtyCod;
@ -3379,13 +3385,13 @@ static void Sta_ShowNumHitsPerCountry (Sta_CountType_t CountType,
HTM_TR_End (); HTM_TR_End ();
/***** Compute maximum number of hits per country *****/ /***** Compute maximum number of hits per country *****/
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1); Sta_ComputeMaxAndTotalHits (&Hits,NumHits,mysql_res,1,1);
/***** Write rows *****/ /***** Write rows *****/
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
for (NumRow = 1, Ranking = 0; for (NumHit = 1, Ranking = 0;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
/* Get country code */ /* Get country code */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3396,7 +3402,7 @@ static void Sta_ShowNumHitsPerCountry (Sta_CountType_t CountType,
/* Write ranking of this country */ /* Write ranking of this country */
HTM_TD_Begin ("class=\"LOG RM\""); HTM_TD_Begin ("class=\"LOG RM\"");
if (CtyCod > 0) if (CtyCod > 0)
HTM_UnsignedLong (++Ranking); HTM_Unsigned (++Ranking);
HTM_NBSP (); HTM_NBSP ();
HTM_TD_End (); HTM_TD_End ();
@ -3448,14 +3454,14 @@ static void Sta_WriteCountry (long CtyCod)
/*****************************************************************************/ /*****************************************************************************/
static void Sta_ShowNumHitsPerInstitution (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerInstitution (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res) MYSQL_RES *mysql_res)
{ {
extern const char *Txt_No_INDEX; extern const char *Txt_No_INDEX;
extern const char *Txt_Institution; extern const char *Txt_Institution;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES]; extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow; unsigned NumHit;
unsigned long Ranking; unsigned Ranking;
struct Sta_Hits Hits; struct Sta_Hits Hits;
MYSQL_ROW row; MYSQL_ROW row;
long InsCod; long InsCod;
@ -3470,13 +3476,13 @@ static void Sta_ShowNumHitsPerInstitution (Sta_CountType_t CountType,
HTM_TR_End (); HTM_TR_End ();
/***** Compute maximum number of hits per institution *****/ /***** Compute maximum number of hits per institution *****/
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1); Sta_ComputeMaxAndTotalHits (&Hits,NumHits,mysql_res,1,1);
/***** Write rows *****/ /***** Write rows *****/
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
for (NumRow = 1, Ranking = 0; for (NumHit = 1, Ranking = 0;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
/* Get institution code */ /* Get institution code */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3487,7 +3493,7 @@ static void Sta_ShowNumHitsPerInstitution (Sta_CountType_t CountType,
/* Write ranking of this institution */ /* Write ranking of this institution */
HTM_TD_Begin ("class=\"LOG RT\""); HTM_TD_Begin ("class=\"LOG RT\"");
if (InsCod > 0) if (InsCod > 0)
HTM_UnsignedLong (++Ranking); HTM_Unsigned (++Ranking);
HTM_NBSP (); HTM_NBSP ();
HTM_TD_End (); HTM_TD_End ();
@ -3541,14 +3547,14 @@ static void Sta_WriteInstit (long InsCod)
/*****************************************************************************/ /*****************************************************************************/
static void Sta_ShowNumHitsPerCenter (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerCenter (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res) MYSQL_RES *mysql_res)
{ {
extern const char *Txt_No_INDEX; extern const char *Txt_No_INDEX;
extern const char *Txt_Center; extern const char *Txt_Center;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES]; extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow; unsigned NumHit;
unsigned long Ranking; unsigned Ranking;
struct Sta_Hits Hits; struct Sta_Hits Hits;
MYSQL_ROW row; MYSQL_ROW row;
long CtrCod; long CtrCod;
@ -3563,13 +3569,13 @@ static void Sta_ShowNumHitsPerCenter (Sta_CountType_t CountType,
HTM_TR_End (); HTM_TR_End ();
/***** Compute maximum number of hits per center *****/ /***** Compute maximum number of hits per center *****/
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1); Sta_ComputeMaxAndTotalHits (&Hits,NumHits,mysql_res,1,1);
/***** Write rows *****/ /***** Write rows *****/
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
for (NumRow = 1, Ranking = 0; for (NumHit = 1, Ranking = 0;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
/* Get center code */ /* Get center code */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3580,7 +3586,7 @@ static void Sta_ShowNumHitsPerCenter (Sta_CountType_t CountType,
/* Write ranking of this center */ /* Write ranking of this center */
HTM_TD_Begin ("class=\"LOG RT\""); HTM_TD_Begin ("class=\"LOG RT\"");
if (CtrCod > 0) if (CtrCod > 0)
HTM_UnsignedLong (++Ranking); HTM_Unsigned (++Ranking);
HTM_NBSP (); HTM_NBSP ();
HTM_TD_End (); HTM_TD_End ();
@ -3634,14 +3640,14 @@ static void Sta_WriteCenter (long CtrCod)
/*****************************************************************************/ /*****************************************************************************/
static void Sta_ShowNumHitsPerDegree (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerDegree (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res) MYSQL_RES *mysql_res)
{ {
extern const char *Txt_No_INDEX; extern const char *Txt_No_INDEX;
extern const char *Txt_Degree; extern const char *Txt_Degree;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES]; extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow; unsigned NumHit;
unsigned long Ranking; unsigned Ranking;
struct Sta_Hits Hits; struct Sta_Hits Hits;
MYSQL_ROW row; MYSQL_ROW row;
long DegCod; long DegCod;
@ -3656,13 +3662,13 @@ static void Sta_ShowNumHitsPerDegree (Sta_CountType_t CountType,
HTM_TR_End (); HTM_TR_End ();
/***** Compute maximum number of hits per degree *****/ /***** Compute maximum number of hits per degree *****/
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1); Sta_ComputeMaxAndTotalHits (&Hits,NumHits,mysql_res,1,1);
/***** Write rows *****/ /***** Write rows *****/
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
for (NumRow = 1, Ranking = 0; for (NumHit = 1, Ranking = 0;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
/* Get degree code */ /* Get degree code */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3673,7 +3679,7 @@ static void Sta_ShowNumHitsPerDegree (Sta_CountType_t CountType,
/* Write ranking of this degree */ /* Write ranking of this degree */
HTM_TD_Begin ("class=\"LOG RT\""); HTM_TD_Begin ("class=\"LOG RT\"");
if (DegCod > 0) if (DegCod > 0)
HTM_UnsignedLong (++Ranking); HTM_Unsigned (++Ranking);
HTM_NBSP (); HTM_NBSP ();
HTM_TD_End (); HTM_TD_End ();
@ -3727,7 +3733,7 @@ static void Sta_WriteDegree (long DegCod)
/*****************************************************************************/ /*****************************************************************************/
static void Sta_ShowNumHitsPerCourse (Sta_CountType_t CountType, static void Sta_ShowNumHitsPerCourse (Sta_CountType_t CountType,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res) MYSQL_RES *mysql_res)
{ {
extern const char *Txt_No_INDEX; extern const char *Txt_No_INDEX;
@ -3736,8 +3742,8 @@ static void Sta_ShowNumHitsPerCourse (Sta_CountType_t CountType,
extern const char *Txt_Course; extern const char *Txt_Course;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES]; extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE]; // Declaration in swad_degree.c extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE]; // Declaration in swad_degree.c
unsigned long NumRow; unsigned NumHit;
unsigned long Ranking; unsigned Ranking;
struct Sta_Hits Hits; struct Sta_Hits Hits;
MYSQL_ROW row; MYSQL_ROW row;
bool CrsOK; bool CrsOK;
@ -3755,13 +3761,13 @@ static void Sta_ShowNumHitsPerCourse (Sta_CountType_t CountType,
HTM_TR_End (); HTM_TR_End ();
/***** Compute maximum number of pages generated per course *****/ /***** Compute maximum number of pages generated per course *****/
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1); Sta_ComputeMaxAndTotalHits (&Hits,NumHits,mysql_res,1,1);
/***** Write rows *****/ /***** Write rows *****/
mysql_data_seek (mysql_res,0); mysql_data_seek (mysql_res,0);
for (NumRow = 1, Ranking = 0; for (NumHit = 1, Ranking = 0;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
/* Get degree, the year and the course */ /* Get degree, the year and the course */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3777,7 +3783,7 @@ static void Sta_ShowNumHitsPerCourse (Sta_CountType_t CountType,
/* Write ranking of this course */ /* Write ranking of this course */
HTM_TD_Begin ("class=\"LOG RT\""); HTM_TD_Begin ("class=\"LOG RT\"");
if (CrsOK) if (CrsOK)
HTM_UnsignedLong (++Ranking); HTM_Unsigned (++Ranking);
HTM_NBSP (); HTM_NBSP ();
HTM_TD_End (); HTM_TD_End ();
@ -3825,17 +3831,17 @@ static void Sta_ShowNumHitsPerCourse (Sta_CountType_t CountType,
/*****************************************************************************/ /*****************************************************************************/
void Sta_ComputeMaxAndTotalHits (struct Sta_Hits *Hits, void Sta_ComputeMaxAndTotalHits (struct Sta_Hits *Hits,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res,unsigned Field, MYSQL_RES *mysql_res,unsigned Field,
unsigned Divisor) unsigned Divisor)
{ {
unsigned long NumRow; unsigned NumHit;
MYSQL_ROW row; MYSQL_ROW row;
/***** For each row... *****/ /***** For each row... *****/
for (NumRow = 1, Hits->Max = Hits->Total = 0.0; for (NumHit = 1, Hits->Max = Hits->Total = 0.0;
NumRow <= NumRows; NumHit <= NumHits;
NumRow++) NumHit++)
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);

View File

@ -156,7 +156,7 @@ void Sta_SeeGblAccesses (void);
void Sta_SeeCrsAccesses (void); void Sta_SeeCrsAccesses (void);
void Sta_ComputeMaxAndTotalHits (struct Sta_Hits *Hits, void Sta_ComputeMaxAndTotalHits (struct Sta_Hits *Hits,
unsigned long NumRows, unsigned NumHits,
MYSQL_RES *mysql_res,unsigned Field, MYSQL_RES *mysql_res,unsigned Field,
unsigned Divisor); unsigned Divisor);