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;
time_t CreatTimeUTC;
long NotCod;
unsigned long NumNot,NumNotices;
unsigned NumNotices;
unsigned NumNot;
char Content[Cns_MAX_BYTES_TEXT + 1];
/***** Get active notices in course *****/
NumNotices = DB_QuerySELECT (&mysql_res,"can not get notices from database",
"SELECT NotCod," // row[0]
"UNIX_TIMESTAMP(CreatTime) AS T," // row[1]
"UsrCod," // row[2]
"Content" // row[3]
" FROM not_notices"
" WHERE CrsCod=%ld"
" AND Status=%u"
" ORDER BY T DESC",
Crs->CrsCod,
(unsigned) Not_ACTIVE_NOTICE);
NumNotices = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get notices from database",
"SELECT NotCod," // row[0]
"UNIX_TIMESTAMP(CreatTime) AS T," // row[1]
"UsrCod," // row[2]
"Content" // row[3]
" FROM not_notices"
" WHERE CrsCod=%ld"
" AND Status=%u"
" ORDER BY T DESC",
Crs->CrsCod,
(unsigned) Not_ACTIVE_NOTICE);
/***** Write items with notices *****/
if (NumNotices)
@ -253,13 +255,13 @@ static void RSS_WriteCallsForExams (FILE *FileRSS,struct Crs_Course *Crs)
struct tm *tm;
time_t CallTimeUTC;
long ExaCod;
unsigned long NumExa;
unsigned long NumExams;
unsigned NumExams;
unsigned NumExa;
if (Gbl.DB.DatabaseIsOpen)
{
/***** Get exam announcements (only future exams) in current course from database *****/
NumExams =
NumExams = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get calls for exams",
"SELECT ExaCod," // row[0]
"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.
*/
#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 JS_FILE "swad20.6.2.js"
/*
TODO: Rename CENTRE to CENTER in help wiki.
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.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)

View File

@ -664,10 +664,10 @@ void Cty_WriteScriptGoogleGeochart (void)
static void Cty_GetParamCtyOrder (void)
{
Gbl.Hierarchy.Ctys.SelectedOrder = (Cty_Order_t)
Par_GetParToUnsignedLong ("Order",
0,
Cty_NUM_ORDERS - 1,
(unsigned long) Cty_ORDER_DEFAULT);
Par_GetParToUnsignedLong ("Order",
0,
Cty_NUM_ORDERS - 1,
(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_ROW row;
unsigned long NumRow;
unsigned NumTyp;
/***** Get types of degree from database *****/
switch (Scope)
@ -709,23 +709,23 @@ void DT_GetListDegreeTypes (Hie_Lvl_Level_t Scope,DT_Order_t Order)
Lay_NotEnoughMemoryExit ();
/***** Get degree types *****/
for (NumRow = 0;
NumRow < Gbl.DegTypes.Num;
NumRow++)
for (NumTyp = 0;
NumTyp < Gbl.DegTypes.Num;
NumTyp++)
{
/* Get next degree type */
row = mysql_fetch_row (mysql_res);
/* 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.");
/* Get degree type name (row[1]) */
Str_Copy (Gbl.DegTypes.Lst[NumRow].DegTypName,row[1],
sizeof (Gbl.DegTypes.Lst[NumRow].DegTypName) - 1);
Str_Copy (Gbl.DegTypes.Lst[NumTyp].DegTypName,row[1],
sizeof (Gbl.DegTypes.Lst[NumTyp].DegTypName) - 1);
/* 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");
}
}

View File

@ -157,7 +157,9 @@ static void Fig_WriteRowStatsFileBrowsers3 (const char *NameOfFileZones,
struct Fig_SizeOfFileZones *SizeOfFileZones);
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
@ -2958,7 +2960,9 @@ static void Fig_GetAndShowOERsStats (void)
/**************** 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_ROW row;

View File

@ -1359,7 +1359,7 @@ static void Brw_GetFileNameToShow (Brw_FileType_t FileType,
char FileNameToShow[NAME_MAX + 1]);
static void Brw_WriteDatesAssignment (void);
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_WriteCurrentClipboard (void);
@ -1445,7 +1445,7 @@ static bool Brw_CheckIfICanModifyPrjDocFileOrFolder (void);
static bool Brw_CheckIfICanModifyPrjAssFileOrFolder (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_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 **************/
/*****************************************************************************/
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;
bool ShowUsr = false;
@ -11781,8 +11781,8 @@ void Brw_RemoveUsrWorksInAllCrss (struct UsrData *UsrDat)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumCrss;
unsigned long NumCrs;
unsigned NumCrss;
unsigned NumCrs;
unsigned NumCrssWorksRemoved = 0;
struct Crs_Course Crs;
@ -11871,7 +11871,7 @@ void Brw_GetSummaryAndContentOfFile (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
/**************************** 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)
{
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_documents;
MYSQL_ROW row;
unsigned long NumDoc;
unsigned long NumDocsNotHidden = 0;
unsigned long NumDocsHidden;
unsigned NumDoc;
unsigned NumDocsNotHidden = 0;
unsigned NumDocsHidden;
/***** Query database *****/
if (NumDocs)
@ -11931,8 +11931,9 @@ void Brw_ListDocsFound (MYSQL_RES **mysql_res,unsigned long NumDocs,
HTM_TH_Begin (1,7,"CM");
HTM_Txt ("(");
NumDocsHidden = NumDocs - NumDocsNotHidden;
HTM_TxtF ("%lu %s",NumDocsHidden,NumDocsHidden == 1 ? Txt_hidden_document :
Txt_hidden_documents);
HTM_TxtF ("%u %s",
NumDocsHidden,NumDocsHidden == 1 ? Txt_hidden_document :
Txt_hidden_documents);
HTM_Txt (")");
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) ***************/
/*****************************************************************************/
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_Teachers_files_area;
@ -12023,7 +12024,7 @@ static void Brw_WriteRowDocData (unsigned long *NumDocsNotHidden,MYSQL_ROW row)
/***** Write number of document in this search *****/
HTM_TD_Begin ("class=\"RT DAT %s\"",BgColor);
HTM_UnsignedLong (++(*NumDocsNotHidden));
HTM_Unsigned (++(*NumDocsNotHidden));
HTM_TD_End ();
/***** Write institution logo, institution short name *****/

View File

@ -267,7 +267,7 @@ void Brw_GetSummaryAndContentOfFile (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
char **ContentStr,
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);
void Brw_AskRemoveOldFiles (void);

View File

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

View File

@ -933,7 +933,7 @@ static unsigned For_GetNumMyPstInThr (long ThrCod)
/*********************** 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 *****/
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);
unsigned long For_GetNumPostsUsr (long UsrCod);
unsigned For_GetNumPostsUsr (long UsrCod);
void For_RemoveUsrFromReadThrs (long UsrCod);
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 bool Grp_GetMultipleEnrolmentOfAGroupType (long GrpTypCod);
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 void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,long UsrCod,
struct ListCodGrps *LstGrps);
@ -2369,7 +2369,7 @@ static void Grp_ListGrpsForMultipleSelection (struct GroupType *GrpTyp,
Role--)
{
HTM_TD_Begin ("class=\"DAT CM\"");
HTM_UnsignedLong (Grp_CountNumUsrsInNoGrpsOfType (Role,GrpTyp->GrpTypCod));
HTM_Unsigned (Grp_CountNumUsrsInNoGrpsOfType (Role,GrpTyp->GrpTypCod));
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 ****/
/*****************************************************************************/
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 ******/
return DB_QueryCOUNT ("can not get the number of users"
" not belonging to groups of a type",
"SELECT COUNT(UsrCod)"
" FROM crs_users"
" WHERE CrsCod=%ld"
" AND Role=%u"
" AND UsrCod NOT IN"
" (SELECT DISTINCT grp_users.UsrCod"
" FROM grp_groups,"
"grp_users"
" WHERE grp_groups.GrpTypCod=%ld"
" AND grp_groups.GrpCod=grp_users.GrpCod)",
Gbl.Hierarchy.Crs.CrsCod,
(unsigned) Role,GrpTypCod);
return (unsigned)
DB_QueryCOUNT ("can not get the number of users"
" not belonging to groups of a type",
"SELECT COUNT(UsrCod)"
" FROM crs_users"
" WHERE CrsCod=%ld"
" AND Role=%u"
" AND UsrCod NOT IN"
" (SELECT DISTINCT grp_users.UsrCod"
" FROM grp_groups,"
"grp_users"
" WHERE grp_groups.GrpTypCod=%ld"
" AND grp_groups.GrpCod=grp_users.GrpCod)",
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 PathRelRSSFile[PATH_MAX + 1];
long NotCod;
unsigned long NumNot;
unsigned long NumNotices = 0; // Initialized to avoid warning
unsigned NumNot;
unsigned NumNotices = 0; // Initialized to avoid warning
char Content[Cns_MAX_BYTES_TEXT + 1];
time_t TimeUTC;
long UsrCod;
@ -392,30 +392,32 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing,long HighlightNotCod)
switch (TypeNoticesListing)
{
case Not_LIST_BRIEF_NOTICES:
NumNotices = DB_QuerySELECT (&mysql_res,"can not get notices from database",
"SELECT NotCod," // row[0]
"UNIX_TIMESTAMP(CreatTime) AS F," // row[1]
"UsrCod," // row[2]
"Content," // row[3]
"Status" // row[4]
" FROM not_notices"
" WHERE CrsCod=%ld"
" AND Status=%u"
" ORDER BY CreatTime DESC",
Gbl.Hierarchy.Crs.CrsCod,
(unsigned) Not_ACTIVE_NOTICE);
NumNotices = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get notices from database",
"SELECT NotCod," // row[0]
"UNIX_TIMESTAMP(CreatTime) AS F," // row[1]
"UsrCod," // row[2]
"Content," // row[3]
"Status" // row[4]
" FROM not_notices"
" WHERE CrsCod=%ld"
" AND Status=%u"
" ORDER BY CreatTime DESC",
Gbl.Hierarchy.Crs.CrsCod,
(unsigned) Not_ACTIVE_NOTICE);
break;
case Not_LIST_FULL_NOTICES:
NumNotices = DB_QuerySELECT (&mysql_res,"can not get notices from database",
"SELECT NotCod," // row[0]
"UNIX_TIMESTAMP(CreatTime) AS F," // row[1]
"UsrCod," // row[2]
"Content," // row[3]
"Status" // row[4]
" FROM not_notices"
" WHERE CrsCod=%ld"
" ORDER BY CreatTime DESC",
Gbl.Hierarchy.Crs.CrsCod);
NumNotices = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get notices from database",
"SELECT NotCod," // row[0]
"UNIX_TIMESTAMP(CreatTime) AS F," // row[1]
"UsrCod," // row[2]
"Content," // row[3]
"Status" // row[4]
" FROM not_notices"
" WHERE CrsCod=%ld"
" ORDER BY CreatTime DESC",
Gbl.Hierarchy.Crs.CrsCod);
break;
}

View File

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

View File

@ -926,19 +926,15 @@ unsigned Pho_UpdateMyClicksWithoutPhoto (void)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned NumClicks;
/***** Get number of clicks without photo from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get number of clicks"
" without photo",
"SELECT NumClicks" // row[0]
" FROM pho_clicks_without_photo"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod);
/***** Update the list of clicks without photo *****/
if (NumRows) // The user exists ==> update number of clicks without photo
if (DB_QuerySELECT (&mysql_res,"can not get number of clicks"
" without photo",
"SELECT NumClicks" // row[0]
" FROM pho_clicks_without_photo"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod)) // The user exists ==> update number of clicks without photo
{
/* Get current number of clicks */
row = mysql_fetch_row (mysql_res);
@ -955,7 +951,7 @@ unsigned Pho_UpdateMyClicksWithoutPhoto (void)
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 */
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_ROW row;
unsigned long NumRows;
long TimeAvgPhotoWasComputed = 0L;
/***** Get last time an average photo was computed from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get last time"
" an average photo was computed",
"SELECT MIN(UNIX_TIMESTAMP(TimeAvgPhoto))" // row[0]
" FROM sta_degrees"
" WHERE DegCod=%ld",
DegCod);
if (NumRows == 1)
if (DB_QuerySELECT (&mysql_res,"can not get last time"
" an average photo was computed",
"SELECT MIN(UNIX_TIMESTAMP(TimeAvgPhoto))" // row[0]
" FROM sta_degrees"
" WHERE DegCod=%ld",
DegCod) == 1)
{
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
@ -1514,21 +1507,16 @@ static long Pho_GetTimeToComputeAvgPhoto (long DegCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
Usr_Sex_t Sex;
long PartialTimeToComputeAvgPhoto;
long TotalTimeToComputeAvgPhoto = -1L;
/***** Get time to compute average photo from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get time to compute"
" average photo",
"SELECT TimeToComputeAvgPhoto" // row[0]
" FROM sta_degrees"
" WHERE DegCod=%ld",
DegCod);
/***** Count number of rows in result *****/
if (NumRows == Usr_NUM_SEXS)
if (DB_QuerySELECT (&mysql_res,"can not get time to compute average photo",
"SELECT TimeToComputeAvgPhoto" // row[0]
" FROM sta_degrees"
" WHERE DegCod=%ld",
DegCod) == Usr_NUM_SEXS)
{
TotalTimeToComputeAvgPhoto = 0;
for (Sex = (Usr_Sex_t) 0;
@ -2063,20 +2051,16 @@ static void Pho_GetMaxStdsPerDegree (struct Pho_DegPhotos *DegPhotos)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
/***** Get maximum number of students in a degree from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get maximum"
" number of students in a degree",
"SELECT MAX(NumStds)," // row[0]
"MAX(NumStdsWithPhoto)," // row[1]
"MAX(NumStdsWithPhoto/NumStds)" // row[2]
" FROM sta_degrees"
" WHERE Sex='all'"
" AND NumStds>0");
/***** Count number of rows in result *****/
if (NumRows == 1)
if (DB_QuerySELECT (&mysql_res,"can not get maximum"
" number of students in a degree",
"SELECT MAX(NumStds)," // row[0]
"MAX(NumStdsWithPhoto)," // row[1]
"MAX(NumStdsWithPhoto/NumStds)" // row[2]
" FROM sta_degrees"
" WHERE Sex='all'"
" AND NumStds>0") == 1)
{
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,
MYSQL_RES **mysql_res)
{
unsigned long NumDegs = 0; // Initialized to avoid warning
switch (HowOrderDegrees)
{
case Pho_NUMBER_OF_STUDENTS:
NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY sta_degrees.NumStds DESC,"
"sta_degrees.NumStdsWithPhoto DESC,"
"deg_degrees.ShortName");
break;
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY sta_degrees.NumStds DESC,"
"sta_degrees.NumStdsWithPhoto DESC,"
"deg_degrees.ShortName");
case Pho_NUMBER_OF_PHOTOS:
NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY sta_degrees.NumStdsWithPhoto DESC,"
"sta_degrees.NumStds DESC,"
"deg_degrees.ShortName");
break;
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY sta_degrees.NumStdsWithPhoto DESC,"
"sta_degrees.NumStds DESC,"
"deg_degrees.ShortName");
case Pho_PERCENT:
NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY sta_degrees.NumStdsWithPhoto/"
"sta_degrees.NumStds DESC,"
"deg_degrees.ShortName");
break;
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY sta_degrees.NumStdsWithPhoto/"
"sta_degrees.NumStds DESC,"
"deg_degrees.ShortName");
case Pho_DEGREE_NAME:
NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY deg_degrees.ShortName");
break;
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod"
" 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];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
/***** Get the number of students in a degree from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get the number of students"
" in a degree",
"SELECT NumStds," // row[0]
"NumStdsWithPhoto" // row[1]
" FROM sta_degrees"
" WHERE DegCod=%ld"
" AND Sex='%s'",
DegCod,
Usr_StringsSexDB[Sex]);
if (NumRows == 0)
if (DB_QuerySELECT (&mysql_res,"can not get the number of students"
" in a degree",
"SELECT NumStds," // row[0]
"NumStdsWithPhoto" // row[1]
" FROM sta_degrees"
" WHERE DegCod=%ld"
" AND Sex='%s'",
DegCod,
Usr_StringsSexDB[Sex]) == 0)
*NumStds = *NumStdsWithPhoto = -1;
else
{

View File

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

View File

@ -225,29 +225,27 @@ static void Plg_GetListPlugins (void)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned NumPlg;
struct Plugin *Plg;
/***** Get plugins from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get plugins",
"SELECT PlgCod," // row[0]
"Name," // row[1]
"Description," // row[2]
"Logo," // row[3]
"AppKey," // row[4]
"URL," // row[5]
"IP" // row[6]
" FROM plg_plugins"
" ORDER BY Name");
Gbl.Plugins.Num = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get plugins",
"SELECT PlgCod," // row[0]
"Name," // row[1]
"Description," // row[2]
"Logo," // row[3]
"AppKey," // row[4]
"URL," // row[5]
"IP" // row[6]
" FROM plg_plugins"
" ORDER BY Name");
/***** 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 *****/
if ((Gbl.Plugins.Lst = calloc (Gbl.Plugins.Num,
if ((Gbl.Plugins.Lst = calloc ((size_t) Gbl.Plugins.Num,
sizeof (*Gbl.Plugins.Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
@ -275,8 +273,6 @@ static void Plg_GetListPlugins (void)
Str_Copy (Plg->IP ,row[6],sizeof (Plg->IP ) - 1);
}
}
else
Gbl.Plugins.Num = 0;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
@ -290,7 +286,6 @@ bool Plg_GetDataOfPluginByCod (struct Plugin *Plg)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
bool PluginFound;
/***** Clear data *****/
@ -306,19 +301,16 @@ bool Plg_GetDataOfPluginByCod (struct Plugin *Plg)
// Plg->PlgCod > 0
/***** Get data of a plugin from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a plugin",
"SELECT Name," // row[0]
"Description," // row[1]
"Logo," // row[2]
"AppKey," // row[3]
"URL," // row[4]
"IP" // row[5]
" FROM plg_plugins"
" WHERE PlgCod=%ld",
Plg->PlgCod);
/***** Count number of rows in result *****/
if (NumRows) // Plugin found...
if (DB_QuerySELECT (&mysql_res,"can not get data of a plugin",
"SELECT Name," // row[0]
"Description," // row[1]
"Logo," // row[2]
"AppKey," // row[3]
"URL," // row[4]
"IP" // row[5]
" FROM plg_plugins"
" WHERE PlgCod=%ld",
Plg->PlgCod)) // Plugin found...
{
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_PutLinkCalculateFigures (const char *EncryptedUsrCod);
static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName);
static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName);
static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod);
static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void);
static void Prf_ShowRanking (unsigned long Rank,unsigned long NumUsrs);
static unsigned Prf_GetRankingFigure (long UsrCod,const char *FieldName);
static unsigned Prf_GetNumUsrsWithFigure (const char *FieldName);
static unsigned Prf_GetRankingNumClicksPerDay (long UsrCod);
static unsigned Prf_GetNumUsrsWithNumClicksPerDay (void);
static void Prf_ShowRanking (unsigned Rank,unsigned NumUsrs);
static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (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_DoubleFewDigits ((double) UsrFigures->NumClicks /
(double) UsrFigures->NumDays);
(double) UsrFigures->NumDays);
HTM_TxtF ("/%s&nbsp;",Txt_day);
Prf_ShowRanking (Prf_GetRankingNumClicksPerDay (UsrDat->UsrCod),
Prf_GetNumUsrsWithNumClicksPerDay ());
@ -646,14 +646,14 @@ static void Prf_ShowNumFileViews (const struct UsrData *UsrDat,
{
HTM_Long (UsrFigures->NumFileViews);
HTM_TxtF ("&nbsp;%s&nbsp;",(UsrFigures->NumFileViews == 1) ? Txt_download :
Txt_downloads);
Txt_downloads);
Prf_ShowRanking (Prf_GetRankingFigure (UsrDat->UsrCod,"NumFileViews"),
Prf_GetNumUsrsWithFigure ("NumFileViews"));
if (UsrFigures->NumDays > 0)
{
HTM_TxtF ("&nbsp;%s","(");
HTM_DoubleFewDigits ((double) UsrFigures->NumFileViews /
(double) UsrFigures->NumDays);
(double) UsrFigures->NumDays);
HTM_TxtF ("/%s)",Txt_day);
}
}
@ -681,7 +681,7 @@ static void Prf_ShowNumSocialPublications (const struct UsrData *UsrDat,
if (UsrFigures->NumSocPub >= 0)
{
HTM_Long (UsrFigures->NumSocPub);
HTM_Int (UsrFigures->NumSocPub);
HTM_TxtF ("&nbsp;%s&nbsp;",UsrFigures->NumSocPub == 1 ? Txt_TIMELINE_post :
Txt_TIMELINE_posts);
Prf_ShowRanking (Prf_GetRankingFigure (UsrDat->UsrCod,"NumSocPub"),
@ -690,7 +690,7 @@ static void Prf_ShowNumSocialPublications (const struct UsrData *UsrDat,
{
HTM_TxtF ("&nbsp;%s","(");
HTM_DoubleFewDigits ((double) UsrFigures->NumSocPub /
(double) UsrFigures->NumDays);
(double) UsrFigures->NumDays);
HTM_TxtF ("/%s)",Txt_day);
}
}
@ -727,7 +727,7 @@ static void Prf_ShowNumForumPosts (const struct UsrData *UsrDat,
{
HTM_TxtF ("&nbsp;%s","(");
HTM_DoubleFewDigits ((double) UsrFigures->NumForPst /
(double) UsrFigures->NumDays);
(double) UsrFigures->NumDays);
HTM_TxtF ("/%s)",Txt_day);
}
}
@ -764,7 +764,7 @@ static void Prf_ShowNumMessagesSent (const struct UsrData *UsrDat,
{
HTM_TxtF ("&nbsp;%s","(");
HTM_DoubleFewDigits ((double) UsrFigures->NumMsgSnt /
(double) UsrFigures->NumDays);
(double) UsrFigures->NumDays);
HTM_TxtF ("/%s)",Txt_day);
}
}
@ -852,24 +852,24 @@ void Prf_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
UsrFigures->NumDays = -1;
/* Get number of clicks (row[2]) */
if (sscanf (row[2],"%ld",&UsrFigures->NumClicks) != 1)
UsrFigures->NumClicks = -1L;
if (sscanf (row[2],"%d",&UsrFigures->NumClicks) != 1)
UsrFigures->NumClicks = -1;
/* Get number of social publications (row[3]) */
if (sscanf (row[3],"%ld",&UsrFigures->NumSocPub) != 1)
UsrFigures->NumSocPub = -1L;
if (sscanf (row[3],"%d",&UsrFigures->NumSocPub) != 1)
UsrFigures->NumSocPub = -1;
/* Get number of file views (row[4]) */
if (sscanf (row[4],"%ld",&UsrFigures->NumFileViews) != 1)
UsrFigures->NumFileViews = -1L;
if (sscanf (row[4],"%d",&UsrFigures->NumFileViews) != 1)
UsrFigures->NumFileViews = -1;
/* Get number of forum posts (row[5]) */
if (sscanf (row[5],"%ld",&UsrFigures->NumForPst) != 1)
UsrFigures->NumForPst = -1L;
if (sscanf (row[5],"%d",&UsrFigures->NumForPst) != 1)
UsrFigures->NumForPst = -1;
/* Get number of messages sent (row[6]) */
if (sscanf (row[6],"%ld",&UsrFigures->NumMsgSnt) != 1)
UsrFigures->NumMsgSnt = -1L;
if (sscanf (row[6],"%d",&UsrFigures->NumMsgSnt) != 1)
UsrFigures->NumMsgSnt = -1;
}
else
/***** 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 **********/
/*****************************************************************************/
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
greater than the figure of this user *****/
return DB_QueryCOUNT ("can not get ranking using a figure",
"SELECT COUNT(*)+1"
" FROM usr_figures"
" WHERE UsrCod<>%ld" // Really not necessary here
" AND %s>(SELECT %s"
" FROM usr_figures"
" WHERE UsrCod=%ld)",
UsrCod,FieldName,FieldName,UsrCod);
return (unsigned)
DB_QueryCOUNT ("can not get ranking using a figure",
"SELECT COUNT(*)+1"
" FROM usr_figures"
" WHERE UsrCod<>%ld" // Really not necessary here
" AND %s>(SELECT %s"
" FROM usr_figures"
" WHERE UsrCod=%ld)",
UsrCod,
FieldName,
FieldName,
UsrCod);
}
/*****************************************************************************/
/********************* 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 *****/
return DB_QueryCOUNT ("can not get number of users with a figure",
"SELECT COUNT(*)"
" FROM usr_figures"
" WHERE %s>=0",
FieldName);
return (unsigned)
DB_QueryCOUNT ("can not get number of users with a figure",
"SELECT COUNT(*)"
" FROM usr_figures"
" WHERE %s>=0",
FieldName);
}
/*****************************************************************************/
/****** 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
greater than the clicks per day of this user *****/
return DB_QueryCOUNT ("can not get ranking using number of clicks per day",
"SELECT COUNT(*)+1"
" FROM (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1) AS NumClicksPerDay"
" FROM usr_figures"
" WHERE UsrCod<>%ld" // Necessary because the following comparison is not exact in floating point
" AND NumClicks>0"
" AND FirstClickTime>FROM_UNIXTIME(0)) AS TableNumClicksPerDay"
" WHERE NumClicksPerDay>"
"(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
" FROM usr_figures"
" WHERE UsrCod=%ld"
" AND NumClicks>0"
" AND FirstClickTime>FROM_UNIXTIME(0))",
UsrCod,UsrCod);
return (unsigned)
DB_QueryCOUNT ("can not get ranking using number of clicks per day",
"SELECT COUNT(*)+1"
" FROM (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1) AS NumClicksPerDay"
" FROM usr_figures"
" WHERE UsrCod<>%ld" // Necessary because the following comparison is not exact in floating point
" AND NumClicks>0"
" AND FirstClickTime>FROM_UNIXTIME(0)) AS TableNumClicksPerDay"
" WHERE NumClicksPerDay>"
"(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
" FROM usr_figures"
" WHERE UsrCod=%ld"
" AND NumClicks>0"
" AND FirstClickTime>FROM_UNIXTIME(0))",
UsrCod,
UsrCod);
}
/*****************************************************************************/
/************** 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 *****/
return DB_QueryCOUNT ("can not get number of users"
" with number of clicks per day",
"SELECT COUNT(*)"
" FROM usr_figures"
" WHERE NumClicks>0"
" AND FirstClickTime>FROM_UNIXTIME(0)");
return (unsigned)
DB_QueryCOUNT ("can not get number of users with number of clicks per day",
"SELECT COUNT(*)"
" FROM usr_figures"
" WHERE NumClicks>0"
" AND FirstClickTime>FROM_UNIXTIME(0)");
}
/*****************************************************************************/
/************************* 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 *Txt_of_PART_OF_A_TOTAL;
@ -964,11 +971,12 @@ static void Prf_ShowRanking (unsigned long Rank,unsigned long NumUsrs)
Frm_BeginForm (ActSeeUseGbl);
Sco_PutParamScope ("ScopeSta",Hie_Lvl_SYS);
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 ();
HTM_BUTTON_SUBMIT_Begin (Title,The_ClassFormLinkOutBox[Gbl.Prefs.Theme],NULL);
free (Title);
HTM_TxtF ("#%lu",Rank);
HTM_TxtF ("#%u",Rank);
HTM_BUTTON_End ();
Frm_EndForm ();
}
@ -1140,7 +1148,7 @@ static void Prf_GetNumSocialPubsAndStoreAsUsrFigure (long UsrCod)
if (Prf_CheckIfUsrFiguresExists (UsrCod))
DB_QueryUPDATE ("can not update user's figures",
"UPDATE usr_figures"
" SET NumSocPub=%ld"
" SET NumSocPub=%d"
" WHERE UsrCod=%ld",
UsrFigures.NumSocPub,
UsrCod);
@ -1169,9 +1177,10 @@ static void Prf_GetNumFileViewsAndStoreAsUsrFigure (long UsrCod)
if (Prf_CheckIfUsrFiguresExists (UsrCod))
DB_QueryUPDATE ("can not update user's figures",
"UPDATE usr_figures"
" SET NumFileViews=%ld"
" SET NumFileViews=%d"
" WHERE UsrCod=%ld",
UsrFigures.NumFileViews,UsrCod);
UsrFigures.NumFileViews,
UsrCod);
else // User entry does not exist
Prf_CreateUsrFigures (UsrCod,&UsrFigures,false);
}
@ -1197,7 +1206,7 @@ static void Prf_GetNumForumPostsAndStoreAsUsrFigure (long UsrCod)
if (Prf_CheckIfUsrFiguresExists (UsrCod))
DB_QueryUPDATE ("can not update user's figures",
"UPDATE usr_figures"
" SET NumForPst=%ld"
" SET NumForPst=%d"
" WHERE UsrCod=%ld",
UsrFigures.NumForPst,
UsrCod);
@ -1226,7 +1235,7 @@ static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod)
if (Prf_CheckIfUsrFiguresExists (UsrCod))
DB_QueryUPDATE ("can not update user's figures",
"UPDATE usr_figures"
" SET NumMsgSnt=%ld"
" SET NumMsgSnt=%d"
" WHERE UsrCod=%ld",
UsrFigures.NumMsgSnt,
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->NumDays = -1; // not applicable
UsrFigures->NumClicks = -1L; // unknown number of clicks
UsrFigures->NumSocPub = -1L; // unknown number of social publications
UsrFigures->NumFileViews = -1L; // unknown number of file views
UsrFigures->NumForPst = -1L; // unknown number of forum posts
UsrFigures->NumMsgSnt = -1L; // unknown number of messages sent
UsrFigures->NumClicks = -1; // unknown number of clicks
UsrFigures->NumSocPub = -1; // unknown number of social publications
UsrFigures->NumFileViews = -1; // unknown number of file views
UsrFigures->NumForPst = -1; // unknown number of forum posts
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 *****/
DB_QueryINSERT ("can not create user's figures",
"INSERT INTO usr_figures"
" (UsrCod,FirstClickTime,NumClicks,NumSocPub,NumFileViews,NumForPst,NumMsgSnt)"
" (UsrCod,FirstClickTime,"
"NumClicks,NumSocPub,NumFileViews,NumForPst,NumMsgSnt)"
" VALUES"
" (%ld,%s,%ld,%ld,%ld,%ld,%ld)",
" (%ld,%s,"
"%d,%d,%d,%d,%d)",
UsrCod,
SubQueryFirstClickTime,
UsrFigures->NumClicks, // -1L ==> unknown number of clicks
UsrFigures->NumSocPub, // -1L ==> unknown number of social publications
UsrFigures->NumFileViews, // -1L ==> unknown number of file views
UsrFigures->NumForPst, // -1L ==> unknown number of forum posts
UsrFigures->NumMsgSnt); // -1L ==> unknown number of messages sent
UsrFigures->NumClicks, // -1 ==> unknown number of clicks
UsrFigures->NumSocPub, // -1 ==> unknown number of social publications
UsrFigures->NumFileViews, // -1 ==> unknown number of file views
UsrFigures->NumForPst, // -1 ==> unknown number of forum posts
UsrFigures->NumMsgSnt); // -1 ==> unknown number of messages sent
}
/*****************************************************************************/
@ -1354,8 +1365,10 @@ void Prf_IncrementNumPubsUsr (long UsrCod)
/***** Increment number of social publications *****/
// If NumSocPub < 0 ==> not yet calculated, so do nothing
DB_QueryINSERT ("can not increment user's social publications",
"UPDATE IGNORE usr_figures SET NumSocPub=NumSocPub+1"
" WHERE UsrCod=%ld AND NumSocPub>=0",
"UPDATE IGNORE usr_figures"
" SET NumSocPub=NumSocPub+1"
" WHERE UsrCod=%ld"
" AND NumSocPub>=0",
UsrCod);
}
@ -1368,8 +1381,10 @@ void Prf_IncrementNumFileViewsUsr (long UsrCod)
/***** Increment number of file views *****/
// If NumFileViews < 0 ==> not yet calculated, so do nothing
DB_QueryINSERT ("can not increment user's file views",
"UPDATE IGNORE usr_figures SET NumFileViews=NumFileViews+1"
" WHERE UsrCod=%ld AND NumFileViews>=0",
"UPDATE IGNORE usr_figures"
" SET NumFileViews=NumFileViews+1"
" WHERE UsrCod=%ld"
" AND NumFileViews>=0",
UsrCod);
}
@ -1382,8 +1397,10 @@ void Prf_IncrementNumForPstUsr (long UsrCod)
/***** Increment number of forum posts *****/
// If NumForPst < 0 ==> not yet calculated, so do nothing
DB_QueryINSERT ("can not increment user's forum posts",
"UPDATE IGNORE usr_figures SET NumForPst=NumForPst+1"
" WHERE UsrCod=%ld AND NumForPst>=0",
"UPDATE IGNORE usr_figures"
" SET NumForPst=NumForPst+1"
" WHERE UsrCod=%ld"
" AND NumForPst>=0",
UsrCod);
}
@ -1396,8 +1413,10 @@ void Prf_IncrementNumMsgSntUsr (long UsrCod)
/***** Increment number of messages sent *****/
// If NumMsgSnt < 0 ==> not yet calculated, so do nothing
DB_QueryINSERT ("can not increment user's messages sent",
"UPDATE IGNORE usr_figures SET NumMsgSnt=NumMsgSnt+1"
" WHERE UsrCod=%ld AND NumMsgSnt>=0",
"UPDATE IGNORE usr_figures"
" SET NumMsgSnt=NumMsgSnt+1"
" WHERE UsrCod=%ld"
" AND NumMsgSnt>=0",
UsrCod);
}

View File

@ -37,13 +37,13 @@
struct UsrFigures
{
time_t FirstClickTimeUTC; // 0 ==> unknown first click time of user never logged
int NumDays; // -1 ==> not applicable
long NumClicks; // -1L ==> unknown number of clicks
long NumSocPub; // -1L ==> unknown number of social publications
long NumFileViews; // -1L ==> unknown number of file views
long NumForPst; // -1L ==> unknown number of forum posts
long NumMsgSnt; // -1L ==> unknown number of messages sent
time_t FirstClickTimeUTC; // 0 ==> unknown first click time of user never logged
int NumDays; // -1 ==> not applicable
int NumClicks; // -1 ==> unknown number of clicks
int NumSocPub; // -1 ==> unknown number of social publications
int NumFileViews; // -1 ==> unknown number of file views
int NumForPst; // -1 ==> unknown number of forum posts
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_GetDataOfItem (struct ProgramItem *Item,
MYSQL_RES **mysql_res,
unsigned long NumRows);
unsigned NumRows);
static void Prg_ResetItem (struct ProgramItem *Item);
static void Prg_FreeListItems (void);
static void Prg_GetItemTxtFromDB (long ItmCod,char Txt[Cns_MAX_BYTES_TEXT + 1]);
@ -975,17 +975,18 @@ static void Prg_GetListItems (void)
Prg_FreeListItems ();
/***** Get list of program items from database *****/
Prg_Gbl.List.NumItems =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get program items",
"SELECT ItmCod," // row[0]
"ItmInd," // row[1]
"Level," // row[2]
"Hidden" // row[3]
" FROM prg_items"
" WHERE CrsCod=%ld%s"
" ORDER BY ItmInd",
Gbl.Hierarchy.Crs.CrsCod,
HiddenSubQuery[Gbl.Usrs.Me.Role.Logged]);
Prg_Gbl.List.NumItems = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get program items",
"SELECT ItmCod," // row[0]
"ItmInd," // row[1]
"Level," // row[2]
"Hidden" // row[3]
" FROM prg_items"
" WHERE CrsCod=%ld"
"%s"
" ORDER BY ItmInd",
Gbl.Hierarchy.Crs.CrsCod,
HiddenSubQuery[Gbl.Usrs.Me.Role.Logged]);
if (Prg_Gbl.List.NumItems) // Items found...
{
@ -1030,25 +1031,27 @@ static void Prg_GetListItems (void)
static void Prg_GetDataOfItemByCod (struct ProgramItem *Item)
{
MYSQL_RES *mysql_res;
unsigned long NumRows;
unsigned NumRows;
if (Item->Hierarchy.ItmCod > 0)
{
/***** Build query *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get program item data",
"SELECT ItmCod," // row[0]
"ItmInd," // row[1]
"Level," // row[2]
"Hidden," // row[3]
"UsrCod," // row[4]
"UNIX_TIMESTAMP(StartTime)," // row[5]
"UNIX_TIMESTAMP(EndTime)," // row[6]
"NOW() BETWEEN StartTime AND EndTime," // row[7]
"Title" // row[8]
" FROM prg_items"
" WHERE ItmCod=%ld"
" AND CrsCod=%ld", // Extra check
Item->Hierarchy.ItmCod,Gbl.Hierarchy.Crs.CrsCod);
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get program item data",
"SELECT ItmCod," // row[0]
"ItmInd," // row[1]
"Level," // row[2]
"Hidden," // row[3]
"UsrCod," // row[4]
"UNIX_TIMESTAMP(StartTime)," // row[5]
"UNIX_TIMESTAMP(EndTime)," // row[6]
"NOW() BETWEEN StartTime AND EndTime," // row[7]
"Title" // row[8]
" FROM prg_items"
" WHERE ItmCod=%ld"
" AND CrsCod=%ld", // Extra check
Item->Hierarchy.ItmCod,
Gbl.Hierarchy.Crs.CrsCod);
/***** Get data of program item *****/
Prg_GetDataOfItem (Item,&mysql_res,NumRows);
@ -1064,7 +1067,7 @@ static void Prg_GetDataOfItemByCod (struct ProgramItem *Item)
static void Prg_GetDataOfItem (struct ProgramItem *Item,
MYSQL_RES **mysql_res,
unsigned long NumRows)
unsigned NumRows)
{
MYSQL_ROW row;

View File

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

View File

@ -83,6 +83,8 @@ extern struct Globals Gbl;
static void Rec_WriteHeadingRecordFields (void);
static unsigned Rec_GetAllFieldsInCurrCrs (MYSQL_RES **mysql_res);
static void Rec_PutParamFieldCod (void *FieldCod);
static void Rec_GetFieldByCod (long FieldCod,char Name[Rec_MAX_BYTES_NAME_FIELD + 1],
unsigned *NumLines,Rec_VisibilityRecordFields_t *Visibility);
@ -487,8 +489,8 @@ bool Rec_CheckIfRecordFieldIsRepeated (const char *FieldName)
bool FieldIsRepeated = false;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned long NumRow;
unsigned NumRows;
unsigned NumRow;
/* Query database */
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 *********/
/*****************************************************************************/
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 *****/
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_ROW row;
unsigned long NumRows;
unsigned Vis;
/***** Get a field of a record in a course from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get a field of a record"
" in a course",
"SELECT FieldName," // row[0]
"NumLines," // row[1]
"Visibility" // row[2]
" FROM crs_record_fields"
" WHERE CrsCod=%ld"
" AND FieldCod=%ld",
Gbl.Hierarchy.Crs.CrsCod,FieldCod);
/***** Count number of rows in result *****/
if (NumRows != 1)
if (DB_QuerySELECT (&mysql_res,"can not get a field of a record in a course",
"SELECT FieldName," // row[0]
"NumLines," // row[1]
"Visibility" // row[2]
" FROM crs_record_fields"
" WHERE CrsCod=%ld"
" AND FieldCod=%ld",
Gbl.Hierarchy.Crs.CrsCod,FieldCod) != 1)
Lay_ShowErrorAndExit ("Error when getting a field of a record in a course.");
/***** 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 ****************/
/*****************************************************************************/
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 *****/
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"
" WHERE FieldCod=%ld"
" AND UsrCod=%ld",
FieldCod,UsrCod);
FieldCod,
UsrCod);
}
/*****************************************************************************/

View File

@ -123,7 +123,6 @@ void Rec_ShowFormCreateRecordField (void);
void Rec_ReceiveFormField (void);
unsigned Rec_ConvertToNumLinesField (const char *StrNumLines);
bool Rec_CheckIfRecordFieldIsRepeated (const char *FieldName);
unsigned long Rec_GetAllFieldsInCurrCrs (MYSQL_RES **mysql_res);
void Rec_CreateRecordField (void);
void Rec_ReqRemField (void);
long Rec_GetFieldCod (void);
@ -151,7 +150,7 @@ void Rec_ListRecordsTchsPrint (void);
void Rec_UpdateAndShowMyCrsRecord (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_UpdateCrsRecord (long UsrCod);
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,
struct Rep_Report *Report);
static void Rep_ComputeMaxAndTotalHits (struct Rep_Hits *Hits,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res,unsigned Field);
static void Rep_DrawBarNumHits (unsigned long HitsNum,unsigned long HitsMax,
unsigned MaxBarWidth);
@ -638,7 +638,7 @@ static void Rep_WriteSectionUsrFigures (const struct Rep_Report *Report)
fprintf (Gbl.F.Rep,"<li>%s: ",Txt_Clicks);
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)
{
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);
if (Report->UsrFigures.NumFileViews >= 0)
{
fprintf (Gbl.F.Rep,"%ld %s",
fprintf (Gbl.F.Rep,"%d %s",
Report->UsrFigures.NumFileViews,
(Report->UsrFigures.NumFileViews == 1) ? Txt_download :
Txt_downloads);
@ -689,7 +689,7 @@ static void Rep_WriteSectionUsrFigures (const struct Rep_Report *Report)
fprintf (Gbl.F.Rep,"<li>%s: ",Txt_Forum_posts);
if (Report->UsrFigures.NumForPst >= 0)
{
fprintf (Gbl.F.Rep,"%ld %s",
fprintf (Gbl.F.Rep,"%d %s",
Report->UsrFigures.NumForPst,
(Report->UsrFigures.NumForPst == 1) ? Txt_FORUM_post :
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);
if (Report->UsrFigures.NumMsgSnt >= 0)
{
fprintf (Gbl.F.Rep,"%ld %s",
fprintf (Gbl.F.Rep,"%d %s",
Report->UsrFigures.NumMsgSnt,
(Report->UsrFigures.NumMsgSnt == 1) ? Txt_message :
Txt_messages);
@ -765,8 +765,8 @@ static void Rep_WriteSectionHitsPerAction (struct Rep_Report *Report)
extern const char *Txt_Other_actions;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned long NumRow;
unsigned NumHits;
unsigned NumHit;
long ActCod;
Act_Action_t Action;
Tab_Tab_t Tab;
@ -778,27 +778,28 @@ static void Rep_WriteSectionHitsPerAction (struct Rep_Report *Report)
Txt_Hits_per_action);
/***** Make the query *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks",
"SELECT SQL_NO_CACHE ActCod," // row[0]
"COUNT(*) AS N" // row[1]
" FROM log"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld"
" GROUP BY ActCod"
" ORDER BY N DESC"
" LIMIT %u",
(long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod,
Rep_MAX_ACTIONS);
NumHits = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get clicks",
"SELECT SQL_NO_CACHE ActCod," // row[0]
"COUNT(*) AS N" // row[1]
" FROM log"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld"
" GROUP BY ActCod"
" ORDER BY N DESC"
" LIMIT %u",
(long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod,
Rep_MAX_ACTIONS);
/***** 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);
/***** Write rows *****/
for (NumRow = 1, NumClicks = 0;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1, NumClicks = 0;
NumHit <= NumHits;
NumHit++)
{
row = mysql_fetch_row (mysql_res);
@ -1008,23 +1009,23 @@ static void Rep_GetAndWriteMyCurrentCrss (Rol_Role_t Role,
Txt_students_ABBREVIATION);
/***** Get courses of a user from database *****/
NumCrss =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user",
"SELECT my_courses.CrsCod," // row[0]
"COUNT(*) AS N" // row[1]
" FROM (SELECT CrsCod"
" FROM crs_users"
" WHERE UsrCod=%ld"
" AND Role=%u) AS my_courses" // It's imperative to use a derived table to not block crs_usr!
" LEFT JOIN log"
" ON (my_courses.CrsCod=log.CrsCod)"
" WHERE log.UsrCod=%ld"
" AND log.Role=%u"
" GROUP BY my_courses.CrsCod"
" ORDER BY N DESC,"
"my_courses.CrsCod DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role,
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role);
NumCrss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get courses of a user",
"SELECT my_courses.CrsCod," // row[0]
"COUNT(*) AS N" // row[1]
" FROM (SELECT CrsCod"
" FROM crs_users"
" WHERE UsrCod=%ld"
" AND Role=%u) AS my_courses" // It's imperative to use a derived table to not block crs_usr!
" LEFT JOIN log"
" ON (my_courses.CrsCod=log.CrsCod)"
" WHERE log.UsrCod=%ld"
" AND log.Role=%u"
" GROUP BY my_courses.CrsCod"
" ORDER BY N DESC,"
"my_courses.CrsCod DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role,
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role);
/***** List the courses (one row per course) *****/
if (NumCrss)
@ -1099,19 +1100,19 @@ static void Rep_GetAndWriteMyHistoricCrss (Rol_Role_t Role,
long CrsCod;
/***** Get historic courses of a user from log *****/
NumCrss =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user",
"SELECT CrsCod," // row[0]
"COUNT(*) AS N" // row[1]
" FROM log"
" WHERE UsrCod=%ld"
" AND Role=%u"
" AND CrsCod>0"
" GROUP BY CrsCod"
" HAVING N>%u"
" ORDER BY N DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role,
Rep_MIN_CLICKS_CRS);
NumCrss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get courses of a user",
"SELECT CrsCod," // row[0]
"COUNT(*) AS N" // row[1]
" FROM log"
" WHERE UsrCod=%ld"
" AND Role=%u"
" AND CrsCod>0"
" GROUP BY CrsCod"
" HAVING N>%u"
" ORDER BY N DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role,
Rep_MIN_CLICKS_CRS);
/***** List the courses (one row per course) *****/
if (NumCrss)
@ -1223,8 +1224,8 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
char SubQueryRol[128];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned long NumRow;
unsigned NumHits;
unsigned NumHit;
unsigned ReadYear;
unsigned FirstYear;
unsigned LastYear;
@ -1241,20 +1242,21 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
else
sprintf (SubQueryRol," AND Role=%u",(unsigned) Role);
NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks",
"SELECT SQL_NO_CACHE YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," // row[0]
"COUNT(*)" // row[1]
" FROM log"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld"
"%s"
"%s"
" GROUP BY Year"
" ORDER BY Year DESC",
(long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod,
SubQueryCrs,
SubQueryRol);
NumHits = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get clicks",
"SELECT SQL_NO_CACHE YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," // row[0]
"COUNT(*)" // row[1]
" FROM log"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld"
"%s"
"%s"
" GROUP BY Year"
" ORDER BY Year DESC",
(long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod,
SubQueryCrs,
SubQueryRol);
/***** Initialize first 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
{
/* 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);
}
/***** Write rows *****/
for (NumRow = 1;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1;
NumHit <= NumHits;
NumHit++)
{
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,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res,unsigned Field)
{
unsigned long NumRow;
unsigned NumHit;
MYSQL_ROW row;
/***** For each row... *****/
for (NumRow = 1, Hits->Max = 0;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1, Hits->Max = 0;
NumHit <= NumHits;
NumHit++)
{
/* Get row */
row = mysql_fetch_row (mysql_res);
@ -1426,13 +1428,13 @@ static void Rep_RemoveUsrReportsFiles (long UsrCod)
char PathUniqueDirReport[PATH_MAX + 1];
/***** Get directories for the reports *****/
NumReports =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's usage reports",
"SELECT UniqueDirL," // row[0]
"UniqueDirR" // row[1]
" FROM usr_reports"
" WHERE UsrCod=%ld",
UsrCod);
NumReports = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get user's usage reports",
"SELECT UniqueDirL," // row[0]
"UniqueDirR" // row[1]
" FROM usr_reports"
" WHERE UsrCod=%ld",
UsrCod);
/***** Remove the reports *****/
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)
{
/***** Get MAC addresses from database *****/
return (unsigned) DB_QuerySELECT (mysql_res,"can not get MAC addresses",
"SELECT MAC" // row[0]
" FROM roo_macs"
" WHERE RooCod=%ld"
" ORDER BY MAC",
RooCod);
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get MAC addresses",
"SELECT MAC" // row[0]
" FROM roo_macs"
" WHERE RooCod=%ld"
" ORDER BY MAC",
RooCod);
}
/*****************************************************************************/
@ -559,7 +560,6 @@ void Roo_GetListRooms (struct Roo_Rooms *Rooms,
};
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned NumRoom;
struct Roo_Room *Room;
@ -567,44 +567,45 @@ void Roo_GetListRooms (struct Roo_Rooms *Rooms,
switch (WhichData)
{
case Roo_ALL_DATA:
NumRows = DB_QuerySELECT (&mysql_res,"can not get rooms",
"SELECT roo_rooms.RooCod," // row[0]
"roo_rooms.BldCod," // row[1]
"bld_buildings.ShortName," // row[2]
"roo_rooms.Floor," // row[3]
"roo_rooms.Type," // row[4]
"roo_rooms.ShortName," // row[5]
"roo_rooms.FullName," // row[6]
"roo_rooms.Capacity" // row[7]
" FROM roo_rooms"
" LEFT JOIN bld_buildings"
" ON roo_rooms.BldCod=bld_buildings.BldCod"
" WHERE roo_rooms.CtrCod=%ld"
" ORDER BY %s",
Gbl.Hierarchy.Ctr.CtrCod,
OrderBySubQuery[Rooms->SelectedOrder]);
Rooms->Num = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get rooms",
"SELECT roo_rooms.RooCod," // row[0]
"roo_rooms.BldCod," // row[1]
"bld_buildings.ShortName," // row[2]
"roo_rooms.Floor," // row[3]
"roo_rooms.Type," // row[4]
"roo_rooms.ShortName," // row[5]
"roo_rooms.FullName," // row[6]
"roo_rooms.Capacity" // row[7]
" FROM roo_rooms"
" LEFT JOIN bld_buildings"
" ON roo_rooms.BldCod=bld_buildings.BldCod"
" WHERE roo_rooms.CtrCod=%ld"
" ORDER BY %s",
Gbl.Hierarchy.Ctr.CtrCod,
OrderBySubQuery[Rooms->SelectedOrder]);
break;
case Roo_ONLY_SHRT_NAME:
default:
NumRows = DB_QuerySELECT (&mysql_res,"can not get rooms",
"SELECT roo_rooms.RooCod," // row[0]
"roo_rooms.ShortName" // row[1]
" FROM roo_rooms LEFT JOIN bld_buildings"
" ON roo_rooms.BldCod=bld_buildings.BldCod"
" WHERE roo_rooms.CtrCod=%ld"
" ORDER BY %s",
Gbl.Hierarchy.Ctr.CtrCod,
OrderBySubQuery[Roo_ORDER_DEFAULT]);
Rooms->Num = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get rooms",
"SELECT roo_rooms.RooCod," // row[0]
"roo_rooms.ShortName" // row[1]
" FROM roo_rooms LEFT JOIN bld_buildings"
" ON roo_rooms.BldCod=bld_buildings.BldCod"
" WHERE roo_rooms.CtrCod=%ld"
" ORDER BY %s",
Gbl.Hierarchy.Ctr.CtrCod,
OrderBySubQuery[Roo_ORDER_DEFAULT]);
break;
}
/***** 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 *****/
if ((Rooms->Lst = calloc (NumRows,sizeof (*Rooms->Lst))) == NULL)
if ((Rooms->Lst = calloc ((size_t) Rooms->Num,
sizeof (*Rooms->Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** 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 *****/
DB_FreeMySQLResult (&mysql_res);
@ -667,28 +666,24 @@ static void Roo_GetDataOfRoomByCod (struct Roo_Room *Room)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
/***** Trivial check *****/
if (Room->RooCod <= 0)
return;
/***** Get data of a room from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a room",
"SELECT roo_rooms.BldCod," // row[0]
"bld_buildings.ShortName," // row[1]
"roo_rooms.Floor," // row[2]
"roo_rooms.Type," // row[3]
"roo_rooms.ShortName," // row[4]
"roo_rooms.FullName," // row[5]
"roo_rooms.Capacity" // row[6]
" FROM roo_rooms LEFT JOIN bld_buildings"
" ON roo_rooms.BldCod=bld_buildings.BldCod"
" WHERE roo_rooms.RooCod=%ld",
Room->RooCod);
/***** Count number of rows in result *****/
if (NumRows) // Room found...
if (DB_QuerySELECT (&mysql_res,"can not get data of a room",
"SELECT roo_rooms.BldCod," // row[0]
"bld_buildings.ShortName," // row[1]
"roo_rooms.Floor," // row[2]
"roo_rooms.Type," // row[3]
"roo_rooms.ShortName," // row[4]
"roo_rooms.FullName," // row[5]
"roo_rooms.Capacity" // row[6]
" FROM roo_rooms LEFT JOIN bld_buildings"
" ON roo_rooms.BldCod=bld_buildings.BldCod"
" WHERE roo_rooms.RooCod=%ld",
Room->RooCod)) // Room found...
{
/* Get row */
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;
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
MYSQL_RES *mysql_res;
unsigned long NumDocs;
unsigned NumDocs;
/***** Check user's permission *****/
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_OPEN_DOCUMENTS))
@ -702,7 +702,7 @@ static unsigned Sch_SearchOpenDocumentsInDB (const char *RangeQuery)
"_latin1 "," COLLATE latin1_general_ci"))
{
/***** Query database *****/
NumDocs =
NumDocs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get files",
"SELECT *"
" FROM "
@ -841,7 +841,7 @@ static unsigned Sch_SearchOpenDocumentsInDB (const char *RangeQuery)
Txt_open_document,
Txt_open_documents);
return (unsigned) NumDocs;
return NumDocs;
}
return 0;
@ -857,7 +857,7 @@ static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery)
extern const char *Txt_documents_in_my_courses;
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
MYSQL_RES *mysql_res;
unsigned long NumDocs;
unsigned NumDocs;
/***** Check user's permission *****/
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);
/***** Build the query *****/
NumDocs =
NumDocs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get files",
"SELECT *"
" FROM ("
@ -1007,7 +1007,7 @@ static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery)
"DROP TEMPORARY TABLE IF EXISTS my_files_crs,"
"my_files_grp");
return (unsigned) NumDocs;
return NumDocs;
}
return 0;
@ -1023,7 +1023,7 @@ static unsigned Sch_SearchMyDocumentsInDB (const char *RangeQuery)
extern const char *Txt_documents_from_me;
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
MYSQL_RES *mysql_res;
unsigned long NumDocs;
unsigned NumDocs;
/***** Check user's permission *****/
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_MY_DOCUMENTS))
@ -1032,7 +1032,7 @@ static unsigned Sch_SearchMyDocumentsInDB (const char *RangeQuery)
"_latin1 "," COLLATE latin1_general_ci"))
{
/***** Build the query *****/
NumDocs =
NumDocs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get files",
"SELECT *"
" FROM ("
@ -1240,7 +1240,7 @@ static unsigned Sch_SearchMyDocumentsInDB (const char *RangeQuery)
Txt_document_from_me,
Txt_documents_from_me);
return (unsigned) NumDocs;
return NumDocs;
}
return 0;

View File

@ -137,23 +137,24 @@ void Set_EditSettings (void)
void Set_GetSettingsFromIP (void)
{
unsigned long NumRows;
unsigned NumRows;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
if (Gbl.IP[0])
{
/***** Get settings from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get settings",
"SELECT FirstDayOfWeek," // row[0]
"DateFormat," // row[1]
"Theme," // row[2]
"IconSet," // row[3]
"Menu," // row[4]
"SideCols" // row[5]
" FROM set_ip_settings"
" WHERE IP='%s'",
Gbl.IP);
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get settings",
"SELECT FirstDayOfWeek," // row[0]
"DateFormat," // row[1]
"Theme," // row[2]
"IconSet," // row[3]
"Menu," // row[4]
"SideCols" // row[5]
" FROM set_ip_settings"
" WHERE IP='%s'",
Gbl.IP);
if (NumRows)
{
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_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse);
static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_WriteLogComments (long LogCod);
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,
unsigned long NumRows,MYSQL_RES *mysql_res);
unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_ShowDistrAccessesPerDayAndHour (const struct Sta_Stats *Stats,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_PutHiddenParamScopeSta (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,
unsigned *R,unsigned *G,unsigned *B);
static void Sta_ShowNumHitsPerWeek (Sta_CountType_t CountType,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_ShowNumHitsPerMonth (Sta_CountType_t CountType,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_ShowNumHitsPerYear (Sta_CountType_t CountType,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_ShowNumHitsPerHour (unsigned long NumRows,
static void Sta_ShowNumHitsPerHour (unsigned NumHits,
MYSQL_RES *mysql_res);
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_WriteAccessMinute (unsigned Minute,double HitsNum,double MaxX);
static void Sta_ShowNumHitsPerAction (Sta_CountType_t CountTypes,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_ShowNumHitsPerPlugin (Sta_CountType_t CountType,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_ShowNumHitsPerWSFunction (Sta_CountType_t CountType,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_ShowNumHitsPerBanner (Sta_CountType_t CountType,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_ShowNumHitsPerCountry (Sta_CountType_t CountType,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_WriteCountry (long CtyCod);
static void Sta_ShowNumHitsPerInstitution (Sta_CountType_t CountType,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_WriteInstit (long InsCod);
static void Sta_ShowNumHitsPerCenter (Sta_CountType_t CountType,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_WriteCenter (long CtrCod);
static void Sta_ShowNumHitsPerDegree (Sta_CountType_t CountType,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_WriteDegree (long DegCod);
static void Sta_ShowNumHitsPerCourse (Sta_CountType_t CountType,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res);
static void Sta_DrawBarNumHits (char Color,
double HitsNum,double HitsMax,double HitsTotal,
unsigned MaxBarWidth);
/*****************************************************************************/
/**************************** Reset stats context ****************************/
/*****************************************************************************/
@ -754,7 +757,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
char QueryAux[512];
long LengthQuery;
MYSQL_RES *mysql_res;
unsigned long NumRows;
unsigned NumHits;
const char *LogTable;
Sta_ClicksDetailedOrGrouped_t DetailedOrGrouped = Sta_CLICKS_GROUPED;
struct UsrData UsrDat;
@ -1416,12 +1419,13 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
*/
/***** Make the query *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks",
"%s",
Query);
NumHits = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get clicks",
"%s",
Query);
/***** 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);
else
{
@ -1439,66 +1443,66 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
switch (Stats.ClicksGroupedBy)
{
case Sta_CLICKS_CRS_DETAILED_LIST:
Sta_ShowDetailedAccessesList (&Stats,NumRows,mysql_res);
Sta_ShowDetailedAccessesList (&Stats,NumHits,mysql_res);
break;
case Sta_CLICKS_CRS_PER_USR:
Sta_ShowNumHitsPerUsr (Stats.CountType,NumRows,mysql_res);
Sta_ShowNumHitsPerUsr (Stats.CountType,NumHits,mysql_res);
break;
case Sta_CLICKS_CRS_PER_DAY:
case Sta_CLICKS_GBL_PER_DAY:
Sta_ShowNumHitsPerDay (Stats.CountType,NumRows,mysql_res);
Sta_ShowNumHitsPerDay (Stats.CountType,NumHits,mysql_res);
break;
case Sta_CLICKS_CRS_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;
case Sta_CLICKS_CRS_PER_WEEK:
case Sta_CLICKS_GBL_PER_WEEK:
Sta_ShowNumHitsPerWeek (Stats.CountType,NumRows,mysql_res);
Sta_ShowNumHitsPerWeek (Stats.CountType,NumHits,mysql_res);
break;
case Sta_CLICKS_CRS_PER_MONTH:
case Sta_CLICKS_GBL_PER_MONTH:
Sta_ShowNumHitsPerMonth (Stats.CountType,NumRows,mysql_res);
Sta_ShowNumHitsPerMonth (Stats.CountType,NumHits,mysql_res);
break;
case Sta_CLICKS_CRS_PER_YEAR:
case Sta_CLICKS_GBL_PER_YEAR:
Sta_ShowNumHitsPerYear (Stats.CountType,NumRows,mysql_res);
Sta_ShowNumHitsPerYear (Stats.CountType,NumHits,mysql_res);
break;
case Sta_CLICKS_CRS_PER_HOUR:
case Sta_CLICKS_GBL_PER_HOUR:
Sta_ShowNumHitsPerHour (NumRows,mysql_res);
Sta_ShowNumHitsPerHour (NumHits,mysql_res);
break;
case Sta_CLICKS_CRS_PER_MINUTE:
case Sta_CLICKS_GBL_PER_MINUTE:
Sta_ShowAverageAccessesPerMinute (NumRows,mysql_res);
Sta_ShowAverageAccessesPerMinute (NumHits,mysql_res);
break;
case Sta_CLICKS_CRS_PER_ACTION:
case Sta_CLICKS_GBL_PER_ACTION:
Sta_ShowNumHitsPerAction (Stats.CountType,NumRows,mysql_res);
Sta_ShowNumHitsPerAction (Stats.CountType,NumHits,mysql_res);
break;
case Sta_CLICKS_GBL_PER_PLUGIN:
Sta_ShowNumHitsPerPlugin (Stats.CountType,NumRows,mysql_res);
Sta_ShowNumHitsPerPlugin (Stats.CountType,NumHits,mysql_res);
break;
case Sta_CLICKS_GBL_PER_API_FUNCTION:
Sta_ShowNumHitsPerWSFunction (Stats.CountType,NumRows,mysql_res);
Sta_ShowNumHitsPerWSFunction (Stats.CountType,NumHits,mysql_res);
break;
case Sta_CLICKS_GBL_PER_BANNER:
Sta_ShowNumHitsPerBanner (Stats.CountType,NumRows,mysql_res);
Sta_ShowNumHitsPerBanner (Stats.CountType,NumHits,mysql_res);
break;
case Sta_CLICKS_GBL_PER_COUNTRY:
Sta_ShowNumHitsPerCountry (Stats.CountType,NumRows,mysql_res);
Sta_ShowNumHitsPerCountry (Stats.CountType,NumHits,mysql_res);
break;
case Sta_CLICKS_GBL_PER_INSTITUTION:
Sta_ShowNumHitsPerInstitution (Stats.CountType,NumRows,mysql_res);
Sta_ShowNumHitsPerInstitution (Stats.CountType,NumHits,mysql_res);
break;
case Sta_CLICKS_GBL_PER_CENTER:
Sta_ShowNumHitsPerCenter (Stats.CountType,NumRows,mysql_res);
Sta_ShowNumHitsPerCenter (Stats.CountType,NumHits,mysql_res);
break;
case Sta_CLICKS_GBL_PER_DEGREE:
Sta_ShowNumHitsPerDegree (Stats.CountType,NumRows,mysql_res);
Sta_ShowNumHitsPerDegree (Stats.CountType,NumHits,mysql_res);
break;
case Sta_CLICKS_GBL_PER_COURSE:
Sta_ShowNumHitsPerCourse (Stats.CountType,NumRows,mysql_res);
Sta_ShowNumHitsPerCourse (Stats.CountType,NumHits,mysql_res);
break;
}
HTM_TABLE_End ();
@ -1546,7 +1550,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
/*****************************************************************************/
static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res)
{
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_LOG_More_info;
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
unsigned long NumRow;
unsigned long FirstRow; // First row to show
unsigned long LastRow; // Last rows to show
unsigned long NumPagesBefore;
unsigned long NumPagesAfter;
unsigned long NumPagsTotal;
unsigned NumRow;
unsigned FirstRow; // First row to show
unsigned LastRow; // Last rows to show
unsigned NumPagesBefore;
unsigned NumPagesAfter;
unsigned NumPagsTotal;
struct UsrData UsrDat;
MYSQL_ROW row;
long LogCod;
@ -1588,15 +1592,15 @@ static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
if (FirstRow == 0 && LastRow == 0) // Call from main form
{
// Show last clicks
FirstRow = (NumRows / Stats->RowsPerPage - 1) * Stats->RowsPerPage + 1;
if ((FirstRow + Stats->RowsPerPage - 1) < NumRows)
FirstRow = (NumHits / Stats->RowsPerPage - 1) * Stats->RowsPerPage + 1;
if ((FirstRow + Stats->RowsPerPage - 1) < NumHits)
FirstRow += Stats->RowsPerPage;
LastRow = NumRows;
LastRow = NumHits;
}
if (FirstRow < 1) // For security reasons; really it should never be less than 1
FirstRow = 1;
if (LastRow > NumRows)
LastRow = NumRows;
if (LastRow > NumHits)
LastRow = NumHits;
if ((LastRow - FirstRow) >= Stats->RowsPerPage) // For if there have been clicks that have increased the number of rows
LastRow = FirstRow + Stats->RowsPerPage - 1;
@ -1606,8 +1610,8 @@ static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
if (NumPagesBefore * Stats->RowsPerPage < (FirstRow-1))
NumPagesBefore++;
/* Number of pages after the current one */
NumPagesAfter = (NumRows - LastRow) / Stats->RowsPerPage;
if (NumPagesAfter * Stats->RowsPerPage < (NumRows - LastRow))
NumPagesAfter = (NumHits - LastRow) / Stats->RowsPerPage;
if (NumPagesAfter * Stats->RowsPerPage < (NumHits - LastRow))
NumPagesAfter++;
/* Count the total number of pages */
NumPagsTotal = NumPagesBefore + 1 + NumPagesAfter;
@ -1650,15 +1654,15 @@ static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
/* Write number of current page */
HTM_TD_Begin ("class=\"DAT_N CM\"");
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,
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);
HTM_STRONG_End ();
HTM_TD_End ();
/* Put link to jump to next page (more recent clicks) */
if (LastRow < NumRows)
if (LastRow < NumHits)
{
Frm_StartFormAnchor (ActSeeAccCrs,Sta_STAT_RESULTS_SECTION_ID);
Dat_WriteParamsIniEndDates ();
@ -1670,7 +1674,7 @@ static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
Usr_PutHiddenParSelectedUsrsCods (&Gbl.Usrs.Selected);
}
HTM_TD_Begin ("class=\"RM\"");
if (LastRow < NumRows)
if (LastRow < NumHits)
{
HTM_BUTTON_SUBMIT_Begin (Str_BuildStringLong (Txt_Show_next_X_clicks,
(long) Stats->RowsPerPage),
@ -1682,7 +1686,7 @@ static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
HTM_BUTTON_End ();
}
HTM_TD_End ();
if (LastRow < NumRows)
if (LastRow < NumHits)
Frm_EndForm ();
HTM_TR_End ();
@ -1726,7 +1730,7 @@ static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats,
/* Write the number of row */
HTM_TD_Begin ("class=\"LOG RT COLOR%u\"",Gbl.RowEvenOdd);
HTM_TxtF ("%ld&nbsp;",NumRow);
HTM_TxtF ("%u&nbsp;",NumRow);
HTM_TD_End ();
/* 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,
unsigned long NumRows,MYSQL_RES *mysql_res)
unsigned NumHits,
MYSQL_RES *mysql_res)
{
extern const char *Txt_No_INDEX;
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_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
MYSQL_ROW row;
unsigned long NumRow;
unsigned NumHit;
struct Sta_Hits Hits;
unsigned BarWidth;
struct UsrData UsrDat;
@ -1835,9 +1840,9 @@ static void Sta_ShowNumHitsPerUsr (Sta_CountType_t CountType,
HTM_TR_End ();
/***** Write rows *****/
for (NumRow = 1, Hits.Max = 0.0, Gbl.RowEvenOdd = 0;
NumRow <= NumRows;
NumRow++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd)
for (NumHit = 1, Hits.Max = 0.0, Gbl.RowEvenOdd = 0;
NumHit <= NumHits;
NumHit++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd)
{
row = mysql_fetch_row (mysql_res);
@ -1849,7 +1854,7 @@ static void Sta_ShowNumHitsPerUsr (Sta_CountType_t CountType,
/* Write the number of row */
HTM_TD_Begin ("class=\"LOG RT COLOR%u\"",Gbl.RowEvenOdd);
HTM_TxtF ("%ld&nbsp;",NumRow);
HTM_TxtF ("%u&nbsp;",NumHit);
HTM_TD_End ();
/* Show the photo */
@ -1875,7 +1880,7 @@ static void Sta_ShowNumHitsPerUsr (Sta_CountType_t CountType,
/* Write the number of clicks */
Hits.Num = Str_GetDoubleFromStr (row[1]);
if (NumRow == 1)
if (NumHits == 1)
Hits.Max = Hits.Num;
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,
unsigned long NumRows,MYSQL_RES *mysql_res)
unsigned NumHits,
MYSQL_RES *mysql_res)
{
extern const char *Txt_Date;
extern const char *Txt_Day;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
extern const char *Txt_DAYS_SMALL[7];
unsigned long NumRow;
unsigned NumHit;
struct Date ReadDate;
struct Date LastDate;
struct Date Date;
@ -1942,13 +1948,13 @@ static void Sta_ShowNumHitsPerDay (Sta_CountType_t CountType,
HTM_TR_End ();
/***** 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 *****/
mysql_data_seek (mysql_res,0);
for (NumRow = 1;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1;
NumHit <= NumHits;
NumHit++)
{
row = mysql_fetch_row (mysql_res);
@ -1974,13 +1980,13 @@ static void Sta_ShowNumHitsPerDay (Sta_CountType_t CountType,
/* Write the date */
Dat_ConvDateToDateStr (&Date,StrDate);
HTM_TD_Begin ("class=\"%s RT\"",NumDayWeek == 6 ? "LOG_R" :
"LOG");
"LOG");
HTM_TxtF ("%s&nbsp;",StrDate);
HTM_TD_End ();
/* Write the day of the week */
HTM_TD_Begin ("class=\"%s LT\"",NumDayWeek == 6 ? "LOG_R" :
"LOG");
"LOG");
HTM_TxtF ("%s&nbsp;",Txt_DAYS_SMALL[NumDayWeek]);
HTM_TD_End ();
@ -2013,13 +2019,13 @@ static void Sta_ShowNumHitsPerDay (Sta_CountType_t CountType,
/* Write the date */
Dat_ConvDateToDateStr (&Date,StrDate);
HTM_TD_Begin ("class=\"%s RT\"",NumDayWeek == 6 ? "LOG_R" :
"LOG");
"LOG");
HTM_TxtF ("%s&nbsp;",StrDate);
HTM_TD_End ();
/* Write the day of the week */
HTM_TD_Begin ("class=\"%s LT\"",NumDayWeek == 6 ? "LOG_R" :
"LOG");
"LOG");
HTM_TxtF ("%s&nbsp;",Txt_DAYS_SMALL[NumDayWeek]);
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)
static void Sta_ShowDistrAccessesPerDayAndHour (const struct Sta_Stats *Stats,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res)
{
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;
unsigned ColorTypeUnsigned;
Sta_ColorType_t SelectedColorType;
unsigned long NumRow;
unsigned NumHit;
struct Date PreviousReadDate;
struct Date CurrentReadDate;
struct Date LastDate;
@ -2113,7 +2119,7 @@ static void Sta_ShowDistrAccessesPerDayAndHour (const struct Sta_Stats *Stats,
HTM_TR_End ();
/***** 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 *****/
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 *****/
mysql_data_seek (mysql_res,0);
for (NumRow = 1;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1;
NumHit <= NumHits;
NumHit++)
{
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]);
/* If this is the first read date, initialize PreviousReadDate */
if (NumRow == 1)
if (NumHit == 1)
Dat_AssignDate (&PreviousReadDate,&CurrentReadDate);
/* 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,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res)
{
extern const char *Txt_Week;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow;
unsigned NumHit;
struct Date ReadDate;
struct Date LastDate;
struct Date Date;
@ -2520,13 +2526,13 @@ static void Sta_ShowNumHitsPerWeek (Sta_CountType_t CountType,
HTM_TR_End ();
/***** 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 *****/
mysql_data_seek (mysql_res,0);
for (NumRow = 1;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1;
NumHit <= NumHits;
NumHit++)
{
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,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res)
{
extern const char *Txt_Month;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow;
unsigned NumHit;
struct Date ReadDate;
struct Date LastDate;
struct Date Date;
@ -2621,13 +2627,13 @@ static void Sta_ShowNumHitsPerMonth (Sta_CountType_t CountType,
HTM_TR_End ();
/***** 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 *****/
mysql_data_seek (mysql_res,0);
for (NumRow = 1;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1;
NumHit <= NumHits;
NumHit++)
{
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,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res)
{
extern const char *Txt_Year;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow;
unsigned NumHit;
struct Date ReadDate;
struct Date LastDate;
struct Date Date;
@ -2722,13 +2728,13 @@ static void Sta_ShowNumHitsPerYear (Sta_CountType_t CountType,
HTM_TR_End ();
/***** 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 *****/
mysql_data_seek (mysql_res,0);
for (NumRow = 1;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1;
NumHit <= NumHits;
NumHit++)
{
row = mysql_fetch_row (mysql_res);
@ -2798,10 +2804,10 @@ static void Sta_ShowNumHitsPerYear (Sta_CountType_t CountType,
#define DIGIT_WIDTH 6
static void Sta_ShowNumHitsPerHour (unsigned long NumRows,
static void Sta_ShowNumHitsPerHour (unsigned NumHits,
MYSQL_RES *mysql_res)
{
unsigned long NumRow;
unsigned NumHit;
struct Sta_Hits Hits;
unsigned NumDays;
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)))
{
/***** 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) *****/
/* 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 *****/
mysql_data_seek (mysql_res,0);
NumRow = 1;
NumHit = 1;
HTM_TR_Begin (NULL);
while (Hour < 24)
{
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
NumRow++;
NumHit++;
if (sscanf (row[0],"%02u",&ReadHour) != 1) // In row[0] is the date in HH format
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_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;
unsigned NumDays;
unsigned MinuteDay = 0;
@ -2924,10 +2930,10 @@ static void Sta_ShowAverageAccessesPerMinute (unsigned long NumRows,MYSQL_RES *m
Hits.Max = 0.0;
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
NumRow++;
NumHit++;
if (sscanf (row[0],"%02u%02u",&ReadHour,&MinuteRead) != 2) // In row[0] is the date in formato HHMM
Lay_ShowErrorAndExit ("Wrong hour-minute.");
/* 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,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res)
{
extern Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD];
extern const char *Txt_Action;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow;
unsigned NumHit;
struct Sta_Hits Hits;
MYSQL_ROW row;
long ActCod;
@ -3142,13 +3148,13 @@ static void Sta_ShowNumHitsPerAction (Sta_CountType_t CountType,
HTM_TR_End ();
/***** 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 *****/
mysql_data_seek (mysql_res,0);
for (NumRow = 1;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1;
NumHit <= NumHits;
NumHit++)
{
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,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res)
{
extern const char *Txt_Plugin;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow;
unsigned NumHit;
struct Sta_Hits Hits;
MYSQL_ROW row;
struct Plugin Plg;
@ -3197,13 +3203,13 @@ static void Sta_ShowNumHitsPerPlugin (Sta_CountType_t CountType,
HTM_TR_End ();
/***** 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 *****/
mysql_data_seek (mysql_res,0);
for (NumRow = 1;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1;
NumHit <= NumHits;
NumHit++)
{
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,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res)
{
extern const char *Txt_Function;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow;
unsigned NumHit;
struct Sta_Hits Hits;
MYSQL_ROW row;
long FunCod;
@ -3253,13 +3259,13 @@ static void Sta_ShowNumHitsPerWSFunction (Sta_CountType_t CountType,
HTM_TR_End ();
/***** 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 *****/
mysql_data_seek (mysql_res,0);
for (NumRow = 1;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1;
NumHit <= NumHits;
NumHit++)
{
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,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res)
{
extern const char *Txt_Banner;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow;
unsigned NumHit;
double NumClicks;
double MaxClicks = 0.0;
double TotalClicks = 0.0;
@ -3308,24 +3314,24 @@ static void Sta_ShowNumHitsPerBanner (Sta_CountType_t CountType,
HTM_TR_End ();
/***** Compute maximum number of clicks per banner *****/
for (NumRow = 1;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1;
NumHit <= NumHits;
NumHit++)
{
row = mysql_fetch_row (mysql_res);
/* Get number of pages generated */
NumClicks = Str_GetDoubleFromStr (row[1]);
if (NumRow == 1)
if (NumHit == 1)
MaxClicks = NumClicks;
TotalClicks += NumClicks;
}
/***** Write rows *****/
mysql_data_seek (mysql_res,0);
for (NumRow = 1;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1;
NumHit <= NumHits;
NumHit++)
{
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,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res)
{
extern const char *Txt_No_INDEX;
extern const char *Txt_Country;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow;
unsigned long Ranking;
unsigned NumHit;
unsigned Ranking;
struct Sta_Hits Hits;
MYSQL_ROW row;
long CtyCod;
@ -3379,13 +3385,13 @@ static void Sta_ShowNumHitsPerCountry (Sta_CountType_t CountType,
HTM_TR_End ();
/***** 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 *****/
mysql_data_seek (mysql_res,0);
for (NumRow = 1, Ranking = 0;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1, Ranking = 0;
NumHit <= NumHits;
NumHit++)
{
/* Get country code */
row = mysql_fetch_row (mysql_res);
@ -3396,7 +3402,7 @@ static void Sta_ShowNumHitsPerCountry (Sta_CountType_t CountType,
/* Write ranking of this country */
HTM_TD_Begin ("class=\"LOG RM\"");
if (CtyCod > 0)
HTM_UnsignedLong (++Ranking);
HTM_Unsigned (++Ranking);
HTM_NBSP ();
HTM_TD_End ();
@ -3448,14 +3454,14 @@ static void Sta_WriteCountry (long CtyCod)
/*****************************************************************************/
static void Sta_ShowNumHitsPerInstitution (Sta_CountType_t CountType,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res)
{
extern const char *Txt_No_INDEX;
extern const char *Txt_Institution;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow;
unsigned long Ranking;
unsigned NumHit;
unsigned Ranking;
struct Sta_Hits Hits;
MYSQL_ROW row;
long InsCod;
@ -3470,13 +3476,13 @@ static void Sta_ShowNumHitsPerInstitution (Sta_CountType_t CountType,
HTM_TR_End ();
/***** 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 *****/
mysql_data_seek (mysql_res,0);
for (NumRow = 1, Ranking = 0;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1, Ranking = 0;
NumHit <= NumHits;
NumHit++)
{
/* Get institution code */
row = mysql_fetch_row (mysql_res);
@ -3487,7 +3493,7 @@ static void Sta_ShowNumHitsPerInstitution (Sta_CountType_t CountType,
/* Write ranking of this institution */
HTM_TD_Begin ("class=\"LOG RT\"");
if (InsCod > 0)
HTM_UnsignedLong (++Ranking);
HTM_Unsigned (++Ranking);
HTM_NBSP ();
HTM_TD_End ();
@ -3541,14 +3547,14 @@ static void Sta_WriteInstit (long InsCod)
/*****************************************************************************/
static void Sta_ShowNumHitsPerCenter (Sta_CountType_t CountType,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res)
{
extern const char *Txt_No_INDEX;
extern const char *Txt_Center;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow;
unsigned long Ranking;
unsigned NumHit;
unsigned Ranking;
struct Sta_Hits Hits;
MYSQL_ROW row;
long CtrCod;
@ -3563,13 +3569,13 @@ static void Sta_ShowNumHitsPerCenter (Sta_CountType_t CountType,
HTM_TR_End ();
/***** 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 *****/
mysql_data_seek (mysql_res,0);
for (NumRow = 1, Ranking = 0;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1, Ranking = 0;
NumHit <= NumHits;
NumHit++)
{
/* Get center code */
row = mysql_fetch_row (mysql_res);
@ -3580,7 +3586,7 @@ static void Sta_ShowNumHitsPerCenter (Sta_CountType_t CountType,
/* Write ranking of this center */
HTM_TD_Begin ("class=\"LOG RT\"");
if (CtrCod > 0)
HTM_UnsignedLong (++Ranking);
HTM_Unsigned (++Ranking);
HTM_NBSP ();
HTM_TD_End ();
@ -3634,14 +3640,14 @@ static void Sta_WriteCenter (long CtrCod)
/*****************************************************************************/
static void Sta_ShowNumHitsPerDegree (Sta_CountType_t CountType,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res)
{
extern const char *Txt_No_INDEX;
extern const char *Txt_Degree;
extern const char *Txt_STAT_TYPE_COUNT_CAPS[Sta_NUM_COUNT_TYPES];
unsigned long NumRow;
unsigned long Ranking;
unsigned NumHit;
unsigned Ranking;
struct Sta_Hits Hits;
MYSQL_ROW row;
long DegCod;
@ -3656,13 +3662,13 @@ static void Sta_ShowNumHitsPerDegree (Sta_CountType_t CountType,
HTM_TR_End ();
/***** 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 *****/
mysql_data_seek (mysql_res,0);
for (NumRow = 1, Ranking = 0;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1, Ranking = 0;
NumHit <= NumHits;
NumHit++)
{
/* Get degree code */
row = mysql_fetch_row (mysql_res);
@ -3673,7 +3679,7 @@ static void Sta_ShowNumHitsPerDegree (Sta_CountType_t CountType,
/* Write ranking of this degree */
HTM_TD_Begin ("class=\"LOG RT\"");
if (DegCod > 0)
HTM_UnsignedLong (++Ranking);
HTM_Unsigned (++Ranking);
HTM_NBSP ();
HTM_TD_End ();
@ -3727,7 +3733,7 @@ static void Sta_WriteDegree (long DegCod)
/*****************************************************************************/
static void Sta_ShowNumHitsPerCourse (Sta_CountType_t CountType,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res)
{
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_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
unsigned long NumRow;
unsigned long Ranking;
unsigned NumHit;
unsigned Ranking;
struct Sta_Hits Hits;
MYSQL_ROW row;
bool CrsOK;
@ -3755,13 +3761,13 @@ static void Sta_ShowNumHitsPerCourse (Sta_CountType_t CountType,
HTM_TR_End ();
/***** 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 *****/
mysql_data_seek (mysql_res,0);
for (NumRow = 1, Ranking = 0;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1, Ranking = 0;
NumHit <= NumHits;
NumHit++)
{
/* Get degree, the year and the course */
row = mysql_fetch_row (mysql_res);
@ -3777,7 +3783,7 @@ static void Sta_ShowNumHitsPerCourse (Sta_CountType_t CountType,
/* Write ranking of this course */
HTM_TD_Begin ("class=\"LOG RT\"");
if (CrsOK)
HTM_UnsignedLong (++Ranking);
HTM_Unsigned (++Ranking);
HTM_NBSP ();
HTM_TD_End ();
@ -3825,17 +3831,17 @@ static void Sta_ShowNumHitsPerCourse (Sta_CountType_t CountType,
/*****************************************************************************/
void Sta_ComputeMaxAndTotalHits (struct Sta_Hits *Hits,
unsigned long NumRows,
unsigned NumHits,
MYSQL_RES *mysql_res,unsigned Field,
unsigned Divisor)
{
unsigned long NumRow;
unsigned NumHit;
MYSQL_ROW row;
/***** For each row... *****/
for (NumRow = 1, Hits->Max = Hits->Total = 0.0;
NumRow <= NumRows;
NumRow++)
for (NumHit = 1, Hits->Max = Hits->Total = 0.0;
NumHit <= NumHits;
NumHit++)
{
/* Get row */
row = mysql_fetch_row (mysql_res);

View File

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