diff --git a/swad_attendance.c b/swad_attendance.c
index 1d10cf09..d11e44db 100644
--- a/swad_attendance.c
+++ b/swad_attendance.c
@@ -1922,7 +1922,7 @@ static void Att_ListAttStudents (struct AttendanceEvent *Att)
Grp_GetParCodsSeveralGrpsToShowUsrs ();
/***** Get and order list of students in this course *****/
- Usr_GetListUsrs (Rol_STD,Sco_SCOPE_CRS);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_STD);
/***** Start frame *****/
Lay_StartRoundFrame (NULL,Txt_Attendance,NULL,Hlp_USERS_Attendance);
@@ -2303,7 +2303,7 @@ void Att_RegisterStudentsInAttEvent (void)
/***** 1. Get list of students in the groups selected: Gbl.Usrs.LstUsrs[Rol_STD] *****/
/* Get list of students in the groups selected */
- Usr_GetListUsrs (Rol_STD,Sco_SCOPE_CRS);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_STD);
if (Gbl.Usrs.LstUsrs[Rol_STD].NumUsrs) // If there are students in the groups selected...
{
@@ -2657,7 +2657,7 @@ void Usr_ReqListStdsAttendanceCrs (void)
Grp_GetParCodsSeveralGrpsToShowUsrs ();
/***** Get and order lists of users from current course *****/
- Usr_GetListUsrs (Rol_STD,Sco_SCOPE_CRS);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_STD);
/***** Start frame *****/
Lay_StartRoundFrame (NULL,Txt_ROLES_PLURAL_Abc[Rol_STD][Usr_SEX_UNKNOWN],
diff --git a/swad_changelog.h b/swad_changelog.h
index 83c9172b..8a978adb 100644
--- a/swad_changelog.h
+++ b/swad_changelog.h
@@ -231,17 +231,20 @@
// TODO: Statistics of hits in course accessible by non-editing teachers.
+// TODO: Include non-editing teachers in Usr_ListAllDataTchs () and Usr_SeeTchClassPhotoPrn ()
+
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
-#define Log_PLATFORM_VERSION "SWAD 16.224.2 (2017-05-25)"
+#define Log_PLATFORM_VERSION "SWAD 16.225 (2017-05-25)"
#define CSS_FILE "swad16.222.css"
#define JS_FILE "swad16.206.3.js"
// Number of lines (includes comments but not blank lines) has been got with the following command:
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1
/*
+ Version 16.225: May 25, 2017 Changes and bug fixing related with new role. (220580 lines)
Version 16.224.2: May 25, 2017 Button to show big list of users/courses integrated in alert. (220465 lines)
Version 16.224.1: May 25, 2017 User lists are shown when changing type of listing. (220463 lines)
Version 16.224: May 25, 2017 Code refactoring related to sections. (220459 lines)
diff --git a/swad_department.c b/swad_department.c
index 3be68041..9099c33f 100644
--- a/swad_department.c
+++ b/swad_department.c
@@ -179,8 +179,10 @@ void Dpt_SeeDepts (void)
""
"",
Txt_Department_unspecified,
- Sta_GetTotalNumberOfUsersInCourses (Sco_SCOPE_INS,
- Rol_TCH) - NumTchsInsWithDpt);
+ Usr_GetTotalNumberOfUsersInCourses (Sco_SCOPE_INS,
+ 1 << Rol_NET |
+ 1 << Rol_TCH) -
+ NumTchsInsWithDpt);
/***** End table *****/
Lay_EndRoundFrameTable ();
@@ -279,17 +281,17 @@ void Dpt_GetListDepartments (long InsCod)
" WHERE departments.InsCod=%ld"
" AND departments.DptCod=usr_data.DptCod"
" AND usr_data.UsrCod=crs_usr.UsrCod"
- " AND crs_usr.Role=%u"
+ " AND crs_usr.Role IN (%u,%u)"
" GROUP BY departments.DptCod)"
" UNION "
"(SELECT DptCod,InsCod,ShortName,FullName,WWW,0 AS NumTchs"
" FROM departments"
" WHERE InsCod=%ld AND DptCod NOT IN"
" (SELECT DISTINCT usr_data.DptCod FROM usr_data,crs_usr"
- " WHERE crs_usr.Role=%u AND crs_usr.UsrCod=usr_data.UsrCod))"
+ " WHERE crs_usr.Role IN (%u,%u) AND crs_usr.UsrCod=usr_data.UsrCod))"
" ORDER BY %s",
- InsCod,(unsigned) Rol_TCH,
- InsCod,(unsigned) Rol_TCH,
+ InsCod,(unsigned) Rol_NET,(unsigned) Rol_TCH,
+ InsCod,(unsigned) Rol_NET,(unsigned) Rol_TCH,
OrderBySubQuery);
else // All the departments
sprintf (Query,"(SELECT departments.DptCod,departments.InsCod,"
@@ -298,17 +300,17 @@ void Dpt_GetListDepartments (long InsCod)
" FROM departments,usr_data,crs_usr"
" WHERE departments.DptCod=usr_data.DptCod"
" AND usr_data.UsrCod=crs_usr.UsrCod"
- " AND crs_usr.Role=%u"
+ " AND crs_usr.Role IN (%u,%u)"
" GROUP BY departments.DptCod)"
" UNION "
"(SELECT DptCod,InsCod,ShortName,FullName,WWW,0 AS NumTchs"
" FROM departments"
" WHERE DptCod NOT IN"
" (SELECT DISTINCT usr_data.DptCod FROM usr_data,crs_usr"
- " WHERE crs_usr.Role=%u AND crs_usr.UsrCod=usr_data.UsrCod))"
+ " WHERE crs_usr.Role IN (%u,%u) AND crs_usr.UsrCod=usr_data.UsrCod))"
" ORDER BY %s",
- (unsigned) Rol_TCH,
- (unsigned) Rol_TCH,
+ (unsigned) Rol_NET,(unsigned) Rol_TCH,
+ (unsigned) Rol_NET,(unsigned) Rol_TCH,
OrderBySubQuery);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get departments");
@@ -351,7 +353,7 @@ void Dpt_GetListDepartments (long InsCod)
Str_Copy (Dpt->WWW,row[4],
Cns_MAX_BYTES_WWW);
- /* Get number of teachers in this department (row[5]) */
+ /* Get number of non-editing teachers and teachers in this department (row[5]) */
if (sscanf (row[5],"%u",&Dpt->NumTchs) != 1)
Dpt->NumTchs = 0;
}
diff --git a/swad_department.h b/swad_department.h
index 9d5b69c5..3edf6547 100644
--- a/swad_department.h
+++ b/swad_department.h
@@ -40,7 +40,7 @@ struct Department
char ShrtName[Hie_MAX_BYTES_SHRT_NAME + 1];
char FullName[Hie_MAX_BYTES_FULL_NAME + 1];
char WWW[Cns_MAX_BYTES_WWW + 1];
- unsigned NumTchs;
+ unsigned NumTchs; // Non-editing teachers and teachers
};
#define Dpt_NUM_ORDERS 2
diff --git a/swad_enrolment.c b/swad_enrolment.c
index c945c22d..5232070a 100644
--- a/swad_enrolment.c
+++ b/swad_enrolment.c
@@ -1488,7 +1488,7 @@ static void Enr_ReceiveFormUsrsCrs (Rol_Role_t Role)
if (WhatToDo.RemoveUsrs)
{
/***** Get list of users in current course *****/
- Usr_GetListUsrs (Role,Sco_SCOPE_CRS);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Role);
if (Gbl.Usrs.LstUsrs[Role].NumUsrs)
{
@@ -1899,7 +1899,7 @@ unsigned Enr_RemAllStdsInCrs (struct Course *Crs)
/***** Get list of students in current course *****/
Gbl.Usrs.ClassPhoto.AllGroups = true; // Get all the students of the current course
- Usr_GetListUsrs (Rol_STD,Sco_SCOPE_CRS);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_STD);
NumStdsInCrs = Gbl.Usrs.LstUsrs[Rol_STD].NumUsrs;
/***** Remove all the students *****/
diff --git a/swad_file_browser.c b/swad_file_browser.c
index 0f5125f1..7329aa8c 100644
--- a/swad_file_browser.c
+++ b/swad_file_browser.c
@@ -3108,9 +3108,9 @@ void Brw_AskEditWorksCrs (void)
Grp_GetParCodsSeveralGrpsToShowUsrs ();
/***** Get and order lists of users from this course *****/
- Usr_GetListUsrs (Rol_STD,Sco_SCOPE_CRS);
- Usr_GetListUsrs (Rol_NET,Sco_SCOPE_CRS);
- Usr_GetListUsrs (Rol_TCH,Sco_SCOPE_CRS);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_STD);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_NET);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_TCH);
NumTotalUsrs = Gbl.Usrs.LstUsrs[Rol_STD].NumUsrs +
Gbl.Usrs.LstUsrs[Rol_NET].NumUsrs +
Gbl.Usrs.LstUsrs[Rol_TCH].NumUsrs;
diff --git a/swad_mail.c b/swad_mail.c
index 29d60cb0..f748a841 100644
--- a/swad_mail.c
+++ b/swad_mail.c
@@ -879,7 +879,7 @@ void Mai_ListEmails (void)
Grp_GetParCodsSeveralGrpsToShowUsrs ();
/***** Get and order list of students in this course *****/
- Usr_GetListUsrs (Rol_STD,Sco_SCOPE_CRS);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_STD);
/***** Start of the frame used to list the emails *****/
Lay_StartRoundFrame (NULL,
diff --git a/swad_message.c b/swad_message.c
index 1643b739..cfa1879e 100644
--- a/swad_message.c
+++ b/swad_message.c
@@ -214,9 +214,9 @@ static void Msg_PutFormMsgUsrs (char Content[Cns_MAX_BYTES_LONG_TEXT + 1])
Grp_GetParCodsSeveralGrpsToShowUsrs ();
/***** Get and order lists of users from this course *****/
- Usr_GetListUsrs (Rol_STD,Sco_SCOPE_CRS);
- Usr_GetListUsrs (Rol_NET,Sco_SCOPE_CRS);
- Usr_GetListUsrs (Rol_TCH,Sco_SCOPE_CRS);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_STD);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_NET);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_TCH);
NumUsrsInCrs = Gbl.Usrs.LstUsrs[Rol_STD].NumUsrs + // Students
Gbl.Usrs.LstUsrs[Rol_NET].NumUsrs + // Non-editing teachers
Gbl.Usrs.LstUsrs[Rol_TCH].NumUsrs; // Teachers
diff --git a/swad_network.c b/swad_network.c
index 0422f69a..6e9410ec 100644
--- a/swad_network.c
+++ b/swad_network.c
@@ -446,11 +446,15 @@ void Net_ShowWebAndSocialNetworksStats (void)
unsigned NumRow;
Net_WebsAndSocialNetworks_t Web;
char NetName[Net_MAX_BYTES_NETWORK_NAME + 1];
- unsigned NumUsrsTotalInPlatform;
+ unsigned NumUsrsTotal;
unsigned NumUsrs;
- /***** Get total number of users in platform *****/
- NumUsrsTotalInPlatform = Sta_GetTotalNumberOfUsersInCourses (Gbl.Scope.Current,Rol_UNK);
+ /***** Get total number of users in current scope *****/
+ NumUsrsTotal = (Gbl.Scope.Current == Sco_SCOPE_SYS) ? Usr_GetTotalNumberOfUsersInPlatform () :
+ Usr_GetTotalNumberOfUsersInCourses (Gbl.Scope.Current,
+ 1 << Rol_STD |
+ 1 << Rol_NET |
+ 1 << Rol_TCH);
/***** Get number of users with a web / social network *****/
switch (Gbl.Scope.Current)
@@ -588,10 +592,8 @@ void Net_ShowWebAndSocialNetworksStats (void)
Net_WebsAndSocialNetworksTitle[Web],
Net_WebsAndSocialNetworksTitle[Web],
NumUsrs,
- NumUsrsTotalInPlatform ? 100.0 *
- (float) NumUsrs /
- (float) NumUsrsTotalInPlatform :
- 0.0);
+ NumUsrsTotal ? 100.0 * (float) NumUsrs / (float) NumUsrsTotal :
+ 0.0);
}
}
diff --git a/swad_statistic.c b/swad_statistic.c
index 0f948808..41f89b56 100644
--- a/swad_statistic.c
+++ b/swad_statistic.c
@@ -202,9 +202,10 @@ static unsigned Sta_GetInsAndStat (struct Instit *Ins,MYSQL_RES *mysql_res);
static void Sta_GetAndShowDegreeTypesStats (void);
-static unsigned Sta_GetTotalNumberOfUsersInPlatform (void);
-
static void Sta_GetAndShowUsersStats (void);
+static void Sta_GetAndShowNumUsrsInCrss (Rol_Role_t Role);
+static void Sta_GetAndShowNumUsrsNotBelongingToAnyCrs (void);
+
static void Sta_GetAndShowUsersRanking (void);
static void Sta_GetAndShowFileBrowsersStats (void);
@@ -464,9 +465,9 @@ void Sta_AskShowCrsHits (void)
Grp_GetParCodsSeveralGrpsToShowUsrs ();
/***** Get and order the lists of users of this course *****/
- Usr_GetListUsrs (Rol_STD,Sco_SCOPE_CRS);
- Usr_GetListUsrs (Rol_NET,Sco_SCOPE_CRS);
- Usr_GetListUsrs (Rol_TCH,Sco_SCOPE_CRS);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_STD);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_NET);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_TCH);
NumTotalUsrs = Gbl.Usrs.LstUsrs[Rol_STD].NumUsrs +
Gbl.Usrs.LstUsrs[Rol_NET].NumUsrs +
Gbl.Usrs.LstUsrs[Rol_TCH].NumUsrs;
@@ -4082,18 +4083,99 @@ static void Sta_GetAndShowUsersStats (void)
Txt_No_of_users,
Txt_Average_number_of_courses_to_which_a_user_belongs,
Txt_Average_number_of_users_belonging_to_a_course);
- Usr_GetAndShowNumUsrsInPlatform (Rol_STD); // Students
- Usr_GetAndShowNumUsrsInPlatform (Rol_NET); // Non-editing teachers
- Usr_GetAndShowNumUsrsInPlatform (Rol_TCH); // Teachers
- Usr_GetAndShowNumUsrsInPlatform (Rol_UNK); // Students, non-editing teachers and teachers
+ Sta_GetAndShowNumUsrsInCrss (Rol_STD); // Students
+ Sta_GetAndShowNumUsrsInCrss (Rol_NET); // Non-editing teachers
+ Sta_GetAndShowNumUsrsInCrss (Rol_TCH); // Teachers
+ Sta_GetAndShowNumUsrsInCrss (Rol_UNK); // Any user in courses
fprintf (Gbl.F.Out,"
"
"
"
"
");
- Usr_GetAndShowNumUsrsInPlatform (Rol_GST); // Users not beloging to any course
+ Sta_GetAndShowNumUsrsNotBelongingToAnyCrs (); // Users not beloging to any course
Lay_EndRoundFrameTable ();
}
+/*****************************************************************************/
+/**************** Get and show number of users in courses ********************/
+/*****************************************************************************/
+// Rol_UNK means any role in courses
+
+static void Sta_GetAndShowNumUsrsInCrss (Rol_Role_t Role)
+ {
+ extern const char *Txt_Total;
+ extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
+ unsigned NumUsrs;
+ float NumCrssPerUsr;
+ float NumUsrsPerCrs;
+ char *Class = (Role == Rol_UNK) ? "DAT_N_LINE_TOP RIGHT_BOTTOM" :
+ "DAT RIGHT_BOTTOM";
+ unsigned Roles = (Role == Rol_UNK) ? ((1 << Rol_STD) |
+ (1 << Rol_NET) |
+ (1 << Rol_TCH)) :
+ (1 << Role);
+
+ /***** Get the number of users belonging to any course *****/
+ NumUsrs = Usr_GetTotalNumberOfUsersInCourses (Gbl.Scope.Current,
+ Roles);
+
+ /***** Get average number of courses per user *****/
+ NumCrssPerUsr = Usr_GetNumCrssPerUsr (Role);
+
+ /***** Query the number of users per course *****/
+ NumUsrsPerCrs = Usr_GetNumUsrsPerCrs (Role);
+
+ /***** Write the total number of users *****/
+ fprintf (Gbl.F.Out,"
"
+ "
"
+ "%s"
+ "
"
+ "
"
+ "%u"
+ "
"
+ "
"
+ "%.2f"
+ "
"
+ "
"
+ "%.2f"
+ "
"
+ "
",
+ Class,(Role == Rol_UNK) ? Txt_Total :
+ Txt_ROLES_PLURAL_Abc[Role][Usr_SEX_UNKNOWN],
+ Class,NumUsrs,
+ Class,NumCrssPerUsr,
+ Class,NumUsrsPerCrs);
+ }
+
+/*****************************************************************************/
+/**************** Get and show number of users in courses ********************/
+/*****************************************************************************/
+
+static void Sta_GetAndShowNumUsrsNotBelongingToAnyCrs (void)
+ {
+ extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
+ char *Class = "DAT RIGHT_BOTTOM";
+
+ /***** Write the total number of users not belonging to any course *****/
+ fprintf (Gbl.F.Out,"
"
+ "
"
+ "%s"
+ "
"
+ "
"
+ "%u"
+ "
"
+ "
"
+ "%.2f"
+ "
"
+ "
"
+ "%.2f"
+ "
"
+ "
",
+ Class,Txt_ROLES_PLURAL_Abc[Rol_GST][Usr_SEX_UNKNOWN],
+ Class,Usr_GetNumUsrsNotBelongingToAnyCrs (),
+ Class,0.0,
+ Class,0.0);
+ }
+
/*****************************************************************************/
/****************************** Show users' ranking **************************/
/*****************************************************************************/
@@ -5329,130 +5411,6 @@ static void Sta_GetAndShowDegreeTypesStats (void)
DT_SeeDegreeTypesInStaTab ();
}
-/*****************************************************************************/
-/****************** Get total number of users in platform ********************/
-/*****************************************************************************/
-
-static unsigned Sta_GetTotalNumberOfUsersInPlatform (void)
- {
- char Query[128];
-
- /***** Get number of users from database *****/
- sprintf (Query,"SELECT COUNT(UsrCod) FROM usr_data");
- return (unsigned) DB_QueryCOUNT (Query,"can not get number of users");
- }
-
-/*****************************************************************************/
-/******************* Get total number of users in courses ********************/
-/*****************************************************************************/
-// Here Rol_UNK means "students, non-editing teachers or teachers"
-
-unsigned Sta_GetTotalNumberOfUsersInCourses (Sco_Scope_t Scope,Rol_Role_t Role)
- {
- char Query[512];
-
- /***** Get number of users from database *****/
- switch (Scope)
- {
- case Sco_SCOPE_SYS:
- if (Role == Rol_UNK) // Any user
- sprintf (Query,"SELECT COUNT(DISTINCT UsrCod)"
- " FROM crs_usr");
- else
- sprintf (Query,"SELECT COUNT(DISTINCT UsrCod)"
- " FROM crs_usr WHERE Role=%u",
- (unsigned) Role);
- break;
- case Sco_SCOPE_CTY:
- if (Role == Rol_UNK) // Any user
- sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
- " FROM institutions,centres,degrees,courses,crs_usr"
- " WHERE institutions.CtyCod=%ld"
- " AND institutions.InsCod=centres.InsCod"
- " AND centres.CtrCod=degrees.CtrCod"
- " AND degrees.DegCod=courses.DegCod"
- " AND courses.CrsCod=crs_usr.CrsCod",
- Gbl.CurrentCty.Cty.CtyCod);
- else
- sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
- " FROM institutions,centres,degrees,courses,crs_usr"
- " WHERE institutions.CtyCod=%ld"
- " AND institutions.InsCod=centres.InsCod"
- " AND centres.CtrCod=degrees.CtrCod"
- " AND degrees.DegCod=courses.DegCod"
- " AND courses.CrsCod=crs_usr.CrsCod"
- " AND crs_usr.Role=%u",
- Gbl.CurrentCty.Cty.CtyCod,(unsigned) Role);
- break;
- case Sco_SCOPE_INS:
- if (Role == Rol_UNK) // Any user
- sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
- " FROM centres,degrees,courses,crs_usr"
- " WHERE centres.InsCod=%ld"
- " AND centres.CtrCod=degrees.CtrCod"
- " AND degrees.DegCod=courses.DegCod"
- " AND courses.CrsCod=crs_usr.CrsCod",
- Gbl.CurrentIns.Ins.InsCod);
- else
- sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
- " FROM centres,degrees,courses,crs_usr"
- " WHERE centres.InsCod=%ld"
- " AND centres.CtrCod=degrees.CtrCod"
- " AND degrees.DegCod=courses.DegCod"
- " AND courses.CrsCod=crs_usr.CrsCod"
- " AND crs_usr.Role=%u",
- Gbl.CurrentIns.Ins.InsCod,(unsigned) Role);
- break;
- case Sco_SCOPE_CTR:
- if (Role == Rol_UNK) // Any user
- sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
- " FROM degrees,courses,crs_usr"
- " WHERE degrees.CtrCod=%ld"
- " AND degrees.DegCod=courses.DegCod"
- " AND courses.CrsCod=crs_usr.CrsCod",
- Gbl.CurrentCtr.Ctr.CtrCod);
- else
- sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
- " FROM degrees,courses,crs_usr"
- " WHERE degrees.CtrCod=%ld"
- " AND degrees.DegCod=courses.DegCod"
- " AND courses.CrsCod=crs_usr.CrsCod"
- " AND crs_usr.Role=%u",
- Gbl.CurrentCtr.Ctr.CtrCod,(unsigned) Role);
- break;
- case Sco_SCOPE_DEG:
- if (Role == Rol_UNK) // Any user
- sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
- " FROM courses,crs_usr"
- " WHERE courses.DegCod=%ld"
- " AND courses.CrsCod=crs_usr.CrsCod",
- Gbl.CurrentDeg.Deg.DegCod);
- else
- sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
- " FROM courses,crs_usr"
- " WHERE courses.DegCod=%ld"
- " AND courses.CrsCod=crs_usr.CrsCod"
- " AND crs_usr.Role=%u",
- Gbl.CurrentDeg.Deg.DegCod,(unsigned) Role);
- break;
- case Sco_SCOPE_CRS:
- if (Role == Rol_UNK) // Any user
- sprintf (Query,"SELECT COUNT(DISTINCT UsrCod) FROM crs_usr"
- " WHERE CrsCod=%ld",
- Gbl.CurrentCrs.Crs.CrsCod);
- else
- sprintf (Query,"SELECT COUNT(DISTINCT UsrCod) FROM crs_usr"
- " WHERE CrsCod=%ld"
- " AND crs_usr.Role=%u",
- Gbl.CurrentCrs.Crs.CrsCod,(unsigned) Role);
- break;
- default:
- Lay_ShowErrorAndExit ("Wrong scope.");
- break;
- }
- return (unsigned) DB_QueryCOUNT (Query,"can not get number of users");
- }
-
/*****************************************************************************/
/********************* Show stats about exploration trees ********************/
/*****************************************************************************/
@@ -7015,8 +6973,11 @@ static void Sta_GetAndShowSocialActivityStats (void)
Txt_No_of_posts_BR_per_user);
/***** Get total number of users *****/
- NumUsrsTotal = (Gbl.Scope.Current == Sco_SCOPE_SYS) ? Sta_GetTotalNumberOfUsersInPlatform () :
- Sta_GetTotalNumberOfUsersInCourses (Gbl.Scope.Current,Rol_UNK);
+ NumUsrsTotal = (Gbl.Scope.Current == Sco_SCOPE_SYS) ? Usr_GetTotalNumberOfUsersInPlatform () :
+ Usr_GetTotalNumberOfUsersInCourses (Gbl.Scope.Current,
+ 1 << Rol_STD |
+ 1 << Rol_NET |
+ 1 << Rol_TCH);
/***** Get total number of following/followers from database *****/
for (NoteType = (Soc_NoteType_t) 0;
@@ -7292,8 +7253,11 @@ static void Sta_GetAndShowFollowStats (void)
Txt_PERCENT_of_users);
/***** Get total number of users *****/
- NumUsrsTotal = (Gbl.Scope.Current == Sco_SCOPE_SYS) ? Sta_GetTotalNumberOfUsersInPlatform () :
- Sta_GetTotalNumberOfUsersInCourses (Gbl.Scope.Current,Rol_UNK);
+ NumUsrsTotal = (Gbl.Scope.Current == Sco_SCOPE_SYS) ? Usr_GetTotalNumberOfUsersInPlatform () :
+ Usr_GetTotalNumberOfUsersInCourses (Gbl.Scope.Current,
+ 1 << Rol_STD |
+ 1 << Rol_NET |
+ 1 << Rol_TCH);
/***** Get total number of following/followers from database *****/
for (Fol = 0;
@@ -7915,8 +7879,11 @@ static void Sta_GetAndShowNumUsrsPerNotifyEvent (void)
Txt_Number_of_BR_emails);
/***** Get total number of users *****/
- NumUsrsTotal = (Gbl.Scope.Current == Sco_SCOPE_SYS) ? Sta_GetTotalNumberOfUsersInPlatform () :
- Sta_GetTotalNumberOfUsersInCourses (Gbl.Scope.Current,Rol_UNK);
+ NumUsrsTotal = (Gbl.Scope.Current == Sco_SCOPE_SYS) ? Usr_GetTotalNumberOfUsersInPlatform () :
+ Usr_GetTotalNumberOfUsersInCourses (Gbl.Scope.Current,
+ 1 << Rol_STD |
+ 1 << Rol_NET |
+ 1 << Rol_TCH);
/***** Get total number of users who want to be
notified by email on some event, from database *****/
diff --git a/swad_statistic.h b/swad_statistic.h
index 4b9841ac..dd623705 100644
--- a/swad_statistic.h
+++ b/swad_statistic.h
@@ -180,8 +180,6 @@ void Sta_PutIconToShowFigure (void);
void Sta_PutHiddenParamFigures (void);
void Sta_ShowFigures (void);
-unsigned Sta_GetTotalNumberOfUsersInCourses (Sco_Scope_t Scope,Rol_Role_t Role);
-
void Sta_WriteParamsDatesSeeAccesses (void);
void Sta_ComputeTimeToGeneratePage (void);
diff --git a/swad_test.c b/swad_test.c
index 7b999049..723cb6e9 100644
--- a/swad_test.c
+++ b/swad_test.c
@@ -6968,9 +6968,9 @@ void Tst_SelUsrsToSeeUsrsTestResults (void)
Grp_GetParCodsSeveralGrpsToShowUsrs ();
/***** Get and order lists of users from this course *****/
- Usr_GetListUsrs (Rol_STD,Sco_SCOPE_CRS);
- Usr_GetListUsrs (Rol_NET,Sco_SCOPE_CRS);
- Usr_GetListUsrs (Rol_TCH,Sco_SCOPE_CRS);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_STD);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_NET);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Rol_TCH);
NumTotalUsrs = Gbl.Usrs.LstUsrs[Rol_STD].NumUsrs +
Gbl.Usrs.LstUsrs[Rol_NET].NumUsrs +
Gbl.Usrs.LstUsrs[Rol_TCH].NumUsrs;
diff --git a/swad_user.c b/swad_user.c
index 5b3d9a3c..4947eb8f 100644
--- a/swad_user.c
+++ b/swad_user.c
@@ -208,10 +208,6 @@ static void Usr_ShowTchsAllDataParams (void);
static void Usr_DrawClassPhoto (Usr_ClassPhotoType_t ClassPhotoType,
Rol_Role_t Role,bool PutCheckBoxToSelectUsr);
-static unsigned Usr_GetNumUsrsNotBelongingToAnyCrs (void);
-static float Usr_GetNumCrssPerUsr (Rol_Role_t Role);
-static float Usr_GetNumUsrsPerCrs (Rol_Role_t Role);
-
/*****************************************************************************/
/**** Show alert about number of clicks remaining before sending my photo ****/
/*****************************************************************************/
@@ -3906,8 +3902,10 @@ unsigned Usr_GetNumTchsCurrentInsInDepartment (long DptCod)
sprintf (Query,"SELECT COUNT(DISTINCT usr_data.UsrCod)"
" FROM usr_data,crs_usr"
" WHERE usr_data.InsCod=%ld AND usr_data.DptCod=%ld"
- " AND usr_data.UsrCod=crs_usr.UsrCod AND crs_usr.Role=%u",
- Gbl.CurrentIns.Ins.InsCod,DptCod,(unsigned) Rol_TCH);
+ " AND usr_data.UsrCod=crs_usr.UsrCod"
+ " AND crs_usr.Role IN (%u,%u)",
+ Gbl.CurrentIns.Ins.InsCod,DptCod,
+ (unsigned) Rol_NET,(unsigned) Rol_TCH);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of teachers in a department");
}
@@ -4158,7 +4156,7 @@ static void Usr_BuildQueryToGetUsrsLstCrs (Rol_Role_t Role,
// - Rol_NET Non-editing teacher
// - Rol_TCH Teacher
-void Usr_GetListUsrs (Rol_Role_t Role,Sco_Scope_t Scope)
+void Usr_GetListUsrs (Sco_Scope_t Scope,Rol_Role_t Role)
{
char Query[Usr_MAX_BYTES_QUERY_GET_LIST_USRS + 1]; // Big query when the course has lot of groups
const char *QueryFields =
@@ -5163,7 +5161,7 @@ static void Usr_PutButtonToConfirmIWantToSeeBigList (unsigned NumUsrs,const char
sprintf (Gbl.Alert.Txt,Txt_The_list_of_X_users_is_too_large_to_be_displayed,
NumUsrs);
Ale_ShowAlertAndButton (Ale_WARNING,Gbl.Alert.Txt,
- Gbl.Action.Act,NULL,OnSubmit,
+ Gbl.Action.Act,Usr_USER_LIST_SECTION_ID,OnSubmit,
Usr_PutParamsConfirmIWantToSeeBigList,
Lay_CONFIRM_BUTTON,Txt_Show_anyway);
}
@@ -6322,7 +6320,7 @@ void Usr_ListAllDataStds (void)
}
/****** Get list of students in current course ******/
- Usr_GetListUsrs (Rol_STD,Gbl.Scope.Current);
+ Usr_GetListUsrs (Gbl.Scope.Current,Rol_STD);
if (Gbl.Usrs.LstUsrs[Rol_STD].NumUsrs)
{
@@ -6556,7 +6554,7 @@ void Usr_ListAllDataTchs (void)
Sco_GetScope ("ScopeUsr");
/***** Get list of teachers *****/
- Usr_GetListUsrs (Rol_TCH,Gbl.Scope.Current);
+ Usr_GetListUsrs (Gbl.Scope.Current,Rol_TCH);
if (Gbl.Usrs.LstUsrs[Rol_TCH].NumUsrs)
{
@@ -7270,30 +7268,29 @@ void Usr_SeeGuests (void)
Usr_PutIconsListGsts,Hlp_USERS_Guests);
/***** Form to select scope *****/
- switch (Gbl.Usrs.Me.LoggedRole)
+ if (Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM)
{
- case Rol_SYS_ADM:
- fprintf (Gbl.F.Out,"
");
}
- if (Usr_GetIfShowBigList (Gbl.Usrs.LstUsrs[Rol_GST].NumUsrs,NULL))
- {
- /***** Get list of selected users *****/
- Usr_GetListsSelectedUsrsCods ();
+ /***** Start section with user list *****/
+ Lay_StartSection (Usr_USER_LIST_SECTION_ID);
+
+ if (Gbl.Usrs.LstUsrs[Rol_GST].NumUsrs)
+ {
+ if (Usr_GetIfShowBigList (Gbl.Usrs.LstUsrs[Rol_GST].NumUsrs,NULL))
+ {
+ /***** Get list of selected users *****/
+ Usr_GetListsSelectedUsrsCods ();
- if (Gbl.Usrs.LstUsrs[Rol_GST].NumUsrs)
- {
/***** Form to select type of list of users *****/
Usr_ShowFormsToSelectUsrListType (ActLstGst);
@@ -7344,9 +7341,12 @@ void Usr_SeeGuests (void)
/* End form */
Act_FormEnd ();
}
- else
- Usr_ShowWarningNoUsersFound (Rol_GST);
}
+ else
+ Usr_ShowWarningNoUsersFound (Rol_GST);
+
+ /***** End section with user list *****/
+ Lay_EndSection ();
/***** End frame *****/
Lay_EndRoundFrame ();
@@ -7411,7 +7411,7 @@ void Usr_SeeStudents (void)
Grp_GetParCodsSeveralGrpsToShowUsrs ();
/***** Get list of students *****/
- Usr_GetListUsrs (Rol_STD,Gbl.Scope.Current);
+ Usr_GetListUsrs (Gbl.Scope.Current,Rol_STD);
/***** Start frame *****/
Lay_StartRoundFrame (NULL,Txt_ROLES_PLURAL_Abc[Rol_STD][Usr_SEX_UNKNOWN],
@@ -7445,13 +7445,13 @@ void Usr_SeeStudents (void)
/***** Start section with user list *****/
Lay_StartSection (Usr_USER_LIST_SECTION_ID);
- if (Usr_GetIfShowBigList (Gbl.Usrs.LstUsrs[Rol_STD].NumUsrs,NULL))
+ if (Gbl.Usrs.LstUsrs[Rol_STD].NumUsrs)
{
- /***** Get list of selected users *****/
- Usr_GetListsSelectedUsrsCods ();
+ if (Usr_GetIfShowBigList (Gbl.Usrs.LstUsrs[Rol_STD].NumUsrs,NULL))
+ {
+ /***** Get list of selected users *****/
+ Usr_GetListsSelectedUsrsCods ();
- if (Gbl.Usrs.LstUsrs[Rol_STD].NumUsrs)
- {
/***** Form to select type of list of users *****/
Usr_ShowFormsToSelectUsrListType (ActLstStd);
@@ -7515,14 +7515,14 @@ void Usr_SeeStudents (void)
Act_FormEnd ();
}
}
- else
- {
- /***** Show warning indicating no students found *****/
- Usr_ShowWarningNoUsersFound (Rol_STD);
+ }
+ else
+ {
+ /***** Show warning indicating no students found *****/
+ Usr_ShowWarningNoUsersFound (Rol_STD);
- /***** Button to enrol students *****/
- Enr_PutButtonToEnrolStudents ();
- }
+ /***** Button to enrol students *****/
+ Enr_PutButtonToEnrolStudents ();
}
/***** End section with user list *****/
@@ -7585,10 +7585,11 @@ void Usr_SeeTeachers (void)
ICanViewRecords = (Gbl.Scope.Current == Sco_SCOPE_CRS);
/***** Get lists of teachers *****/
- Usr_GetListUsrs (Rol_NET,Gbl.Scope.Current); // Non-editing teachers
- Usr_GetListUsrs (Rol_TCH,Gbl.Scope.Current); // Teachers
- NumUsrs = Gbl.Usrs.LstUsrs[Rol_NET].NumUsrs +
- Gbl.Usrs.LstUsrs[Rol_TCH].NumUsrs;
+ Usr_GetListUsrs (Gbl.Scope.Current,Rol_NET); // Non-editing teachers
+ Usr_GetListUsrs (Gbl.Scope.Current,Rol_TCH); // Teachers
+ NumUsrs = Usr_GetTotalNumberOfUsersInCourses (Gbl.Scope.Current,
+ 1 << Rol_NET |
+ 1 << Rol_TCH);
/***** Start frame *****/
Lay_StartRoundFrame (NULL,Txt_ROLES_PLURAL_Abc[Rol_TCH][Usr_SEX_UNKNOWN],
@@ -7605,10 +7606,13 @@ void Usr_SeeTeachers (void)
Act_FormEnd ();
fprintf (Gbl.F.Out,"");
- if (Usr_GetIfShowBigList (NumUsrs,NULL))
+ /***** Start section with user list *****/
+ Lay_StartSection (Usr_USER_LIST_SECTION_ID);
+
+ if (NumUsrs)
{
- if (NumUsrs)
- {
+ if (Usr_GetIfShowBigList (NumUsrs,NULL))
+ {
/***** Form to select type of list of users *****/
Usr_ShowFormsToSelectUsrListType (ActLstTch);
@@ -7679,15 +7683,18 @@ void Usr_SeeTeachers (void)
Act_FormEnd ();
}
}
- else
- {
- /***** Show warning indicating no teachers found *****/
- Usr_ShowWarningNoUsersFound (Rol_TCH);
-
- /***** Button to enrol a teacher *****/
- Enr_PutButtonToEnrolOneTeacher ();
- }
}
+ else
+ {
+ /***** Show warning indicating no teachers found *****/
+ Usr_ShowWarningNoUsersFound (Rol_TCH);
+
+ /***** Button to enrol a teacher *****/
+ Enr_PutButtonToEnrolOneTeacher ();
+ }
+
+ /***** End section with user list *****/
+ Lay_EndSection ();
/***** End frame *****/
Lay_EndRoundFrame ();
@@ -7941,7 +7948,7 @@ void Usr_SeeStdClassPhotoPrn (void)
Grp_GetParCodsSeveralGrpsToShowUsrs ();
/***** Get list of students *****/
- Usr_GetListUsrs (Rol_STD,Gbl.Scope.Current);
+ Usr_GetListUsrs (Gbl.Scope.Current,Rol_STD);
if (Gbl.Usrs.LstUsrs[Rol_STD].NumUsrs)
{
@@ -7994,7 +8001,7 @@ void Usr_SeeTchClassPhotoPrn (void)
Sco_GetScope ("ScopeUsr");
/***** Get list of teachers *****/
- Usr_GetListUsrs (Rol_TCH,Gbl.Scope.Current);
+ Usr_GetListUsrs (Gbl.Scope.Current,Rol_TCH);
if (Gbl.Usrs.LstUsrs[Rol_TCH].NumUsrs)
{
@@ -8222,61 +8229,206 @@ void Usr_ShowWarningNoUsersFound (Rol_Role_t Role)
}
/*****************************************************************************/
-/************************ See stats about the platform ***********************/
+/****************** Get total number of users in platform ********************/
/*****************************************************************************/
-// Here Rol_UNK means "all users"
-void Usr_GetAndShowNumUsrsInPlatform (Rol_Role_t Role)
+unsigned Usr_GetTotalNumberOfUsersInPlatform (void)
{
- extern const char *Txt_Total;
- extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
- unsigned NumUsrs;
- float NumCrssPerUsr;
- float NumUsrsPerCrs;
- char *Class = (Role == Rol_UNK) ? "DAT_N_LINE_TOP RIGHT_BOTTOM" :
- "DAT RIGHT_BOTTOM";
+ char Query[128];
- /***** Get the number of users belonging to any course *****/
- if (Role == Rol_GST) // Users not beloging to any course
- NumUsrs = Usr_GetNumUsrsNotBelongingToAnyCrs ();
- else
- NumUsrs = Sta_GetTotalNumberOfUsersInCourses (Gbl.Scope.Current,Role);
+ /***** Get number of users from database *****/
+ sprintf (Query,"SELECT COUNT(UsrCod) FROM usr_data");
+ return (unsigned) DB_QueryCOUNT (Query,"can not get number of users");
+ }
- /***** Get average number of courses per user *****/
- NumCrssPerUsr = (Role == Rol_GST) ? 0 :
- Usr_GetNumCrssPerUsr (Role);
+/*****************************************************************************/
+/******* Get total number of users of one or several roles in courses ********/
+/*****************************************************************************/
- /***** Query the number of users per course *****/
- NumUsrsPerCrs = (Role == Rol_GST) ? 0 :
- Usr_GetNumUsrsPerCrs (Role);
+#define Usr_MAX_BYTES_SUBQUERY_ROLES (Rol_NUM_ROLES*(10+1)-1)
- /***** Write the total number of users *****/
- fprintf (Gbl.F.Out,"
"
- "
"
- "%s"
- "
"
- "
"
- "%u"
- "
"
- "
"
- "%.2f"
- "
"
- "
"
- "%.2f"
- "
"
- "
",
- Class,(Role == Rol_UNK) ? Txt_Total :
- Txt_ROLES_PLURAL_Abc[Role][Usr_SEX_UNKNOWN],
- Class,NumUsrs,
- Class,NumCrssPerUsr,
- Class,NumUsrsPerCrs);
+unsigned Usr_GetTotalNumberOfUsersInCourses (Sco_Scope_t Scope,unsigned Roles)
+ {
+ char UnsignedStr[10 + 1];
+ char SubQueryRoles[Usr_MAX_BYTES_SUBQUERY_ROLES + 1];
+ char Query[512 + Usr_MAX_BYTES_SUBQUERY_ROLES + 1];
+ bool AnyUserInCourses;
+ Rol_Role_t Role;
+ Rol_Role_t FirstRoleRequested;
+ bool MoreThanOneRole;
+ bool FirstRole;
+
+ /***** Reset roles that can not belong to courses.
+ Only
+ - students,
+ - non-editing teachers,
+ - teachers
+ can belong to a course *****/
+ Roles &= ((1 << Rol_STD) |
+ (1 << Rol_NET) |
+ (1 << Rol_TCH));
+
+ /***** Check if no roles requested *****/
+ if (Roles == 0)
+ return 0;
+
+ /***** Check if any user in courses is requested *****/
+ AnyUserInCourses = (Roles == ((1 << Rol_STD) |
+ (1 << Rol_NET) |
+ (1 << Rol_TCH)));
+
+ /***** Get first role requested *****/
+ FirstRoleRequested = Rol_UNK;
+ for (Role = Rol_STD;
+ Role <= Rol_TCH;
+ Role++)
+ if (Roles & (1 << Role))
+ {
+ FirstRoleRequested = Role;
+ break;
+ }
+
+ /***** Check if more than one role is requested *****/
+ MoreThanOneRole = false;
+ if (FirstRoleRequested != Rol_UNK)
+ for (Role = FirstRoleRequested + 1;
+ Role <= Rol_TCH;
+ Role++)
+ if (Roles & (1 << Role))
+ {
+ MoreThanOneRole = true;
+ break;
+ }
+
+ /***** Build subquery for roles *****/
+ if (MoreThanOneRole)
+ {
+ Str_Copy (SubQueryRoles," IN (",Usr_MAX_BYTES_SUBQUERY_ROLES);
+ for (Role = Rol_STD, FirstRole = true;
+ Role <= Rol_TCH;
+ Role++)
+ if (Roles & (1 << Role))
+ {
+ sprintf (UnsignedStr,"%u",(unsigned) Role);
+ if (!FirstRole) // Not the first role
+ {
+ Str_Concat (SubQueryRoles,",",Usr_MAX_BYTES_SUBQUERY_ROLES);
+ FirstRole = false;
+ }
+ Str_Concat (SubQueryRoles,UnsignedStr,Usr_MAX_BYTES_SUBQUERY_ROLES);
+ }
+ Str_Concat (SubQueryRoles,")",Usr_MAX_BYTES_SUBQUERY_ROLES);
+ }
+ else // Only one role
+ sprintf (SubQueryRoles,"=%u",FirstRoleRequested);
+
+ /***** Get number of users from database *****/
+ switch (Scope)
+ {
+ case Sco_SCOPE_SYS:
+ if (AnyUserInCourses) // Any user
+ sprintf (Query,"SELECT COUNT(DISTINCT UsrCod)"
+ " FROM crs_usr");
+ else
+ sprintf (Query,"SELECT COUNT(DISTINCT UsrCod)"
+ " FROM crs_usr WHERE Role%s",
+ SubQueryRoles);
+ break;
+ case Sco_SCOPE_CTY:
+ if (AnyUserInCourses) // Any user
+ sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
+ " FROM institutions,centres,degrees,courses,crs_usr"
+ " WHERE institutions.CtyCod=%ld"
+ " AND institutions.InsCod=centres.InsCod"
+ " AND centres.CtrCod=degrees.CtrCod"
+ " AND degrees.DegCod=courses.DegCod"
+ " AND courses.CrsCod=crs_usr.CrsCod",
+ Gbl.CurrentCty.Cty.CtyCod);
+ else
+ sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
+ " FROM institutions,centres,degrees,courses,crs_usr"
+ " WHERE institutions.CtyCod=%ld"
+ " AND institutions.InsCod=centres.InsCod"
+ " AND centres.CtrCod=degrees.CtrCod"
+ " AND degrees.DegCod=courses.DegCod"
+ " AND courses.CrsCod=crs_usr.CrsCod"
+ " AND crs_usr.Role%s",
+ Gbl.CurrentCty.Cty.CtyCod,SubQueryRoles);
+ break;
+ case Sco_SCOPE_INS:
+ if (AnyUserInCourses) // Any user
+ sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
+ " FROM centres,degrees,courses,crs_usr"
+ " WHERE centres.InsCod=%ld"
+ " AND centres.CtrCod=degrees.CtrCod"
+ " AND degrees.DegCod=courses.DegCod"
+ " AND courses.CrsCod=crs_usr.CrsCod",
+ Gbl.CurrentIns.Ins.InsCod);
+ else
+ sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
+ " FROM centres,degrees,courses,crs_usr"
+ " WHERE centres.InsCod=%ld"
+ " AND centres.CtrCod=degrees.CtrCod"
+ " AND degrees.DegCod=courses.DegCod"
+ " AND courses.CrsCod=crs_usr.CrsCod"
+ " AND crs_usr.Role%s",
+ Gbl.CurrentIns.Ins.InsCod,SubQueryRoles);
+ break;
+ case Sco_SCOPE_CTR:
+ if (AnyUserInCourses) // Any user
+ sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
+ " FROM degrees,courses,crs_usr"
+ " WHERE degrees.CtrCod=%ld"
+ " AND degrees.DegCod=courses.DegCod"
+ " AND courses.CrsCod=crs_usr.CrsCod",
+ Gbl.CurrentCtr.Ctr.CtrCod);
+ else
+ sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
+ " FROM degrees,courses,crs_usr"
+ " WHERE degrees.CtrCod=%ld"
+ " AND degrees.DegCod=courses.DegCod"
+ " AND courses.CrsCod=crs_usr.CrsCod"
+ " AND crs_usr.Role%s",
+ Gbl.CurrentCtr.Ctr.CtrCod,SubQueryRoles);
+ break;
+ case Sco_SCOPE_DEG:
+ if (AnyUserInCourses) // Any user
+ sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
+ " FROM courses,crs_usr"
+ " WHERE courses.DegCod=%ld"
+ " AND courses.CrsCod=crs_usr.CrsCod",
+ Gbl.CurrentDeg.Deg.DegCod);
+ else
+ sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
+ " FROM courses,crs_usr"
+ " WHERE courses.DegCod=%ld"
+ " AND courses.CrsCod=crs_usr.CrsCod"
+ " AND crs_usr.Role%s",
+ Gbl.CurrentDeg.Deg.DegCod,SubQueryRoles);
+ break;
+ case Sco_SCOPE_CRS:
+ if (AnyUserInCourses) // Any user
+ sprintf (Query,"SELECT COUNT(DISTINCT UsrCod) FROM crs_usr"
+ " WHERE CrsCod=%ld",
+ Gbl.CurrentCrs.Crs.CrsCod);
+ else
+ sprintf (Query,"SELECT COUNT(DISTINCT UsrCod) FROM crs_usr"
+ " WHERE CrsCod=%ld"
+ " AND Role%s",
+ Gbl.CurrentCrs.Crs.CrsCod,SubQueryRoles);
+ break;
+ default:
+ Lay_ShowErrorAndExit ("Wrong scope.");
+ break;
+ }
+ return (unsigned) DB_QueryCOUNT (Query,"can not get number of users");
}
/*****************************************************************************/
/******** Get total number of users who do not belong to any course **********/
/*****************************************************************************/
-static unsigned Usr_GetNumUsrsNotBelongingToAnyCrs (void)
+unsigned Usr_GetNumUsrsNotBelongingToAnyCrs (void)
{
char Query[256];
@@ -8290,7 +8442,7 @@ static unsigned Usr_GetNumUsrsNotBelongingToAnyCrs (void)
/************ Get average number of courses with users of a role *************/
/*****************************************************************************/
-static float Usr_GetNumCrssPerUsr (Rol_Role_t Role)
+float Usr_GetNumCrssPerUsr (Rol_Role_t Role)
{
char Query[1024];
MYSQL_RES *mysql_res;
@@ -8427,7 +8579,7 @@ static float Usr_GetNumCrssPerUsr (Rol_Role_t Role)
/************ Get average number of courses with users of a type *************/
/*****************************************************************************/
-static float Usr_GetNumUsrsPerCrs (Rol_Role_t Role)
+float Usr_GetNumUsrsPerCrs (Rol_Role_t Role)
{
char Query[1024];
MYSQL_RES *mysql_res;
diff --git a/swad_user.h b/swad_user.h
index ac36492b..ee0ba5a2 100644
--- a/swad_user.h
+++ b/swad_user.h
@@ -336,7 +336,7 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (long InsCod);
unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (long CtrCod);
unsigned Usr_GetNumberOfTeachersInCentre (long CtrCod);
-void Usr_GetListUsrs (Rol_Role_t Role,Sco_Scope_t Scope);
+void Usr_GetListUsrs (Sco_Scope_t Scope,Rol_Role_t Role);
void Usr_SearchListUsrs (Rol_Role_t Role);
void Usr_CreateTmpTableAndSearchCandidateUsrs (const char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1]);
@@ -395,7 +395,11 @@ bool Usr_ChkIfUsrCodExists (long UsrCod);
void Usr_ShowWarningNoUsersFound (Rol_Role_t Role);
-void Usr_GetAndShowNumUsrsInPlatform (Rol_Role_t Role);
+unsigned Usr_GetTotalNumberOfUsersInPlatform (void);
+unsigned Usr_GetTotalNumberOfUsersInCourses (Sco_Scope_t Scope,unsigned Roles);
+unsigned Usr_GetNumUsrsNotBelongingToAnyCrs (void);
+float Usr_GetNumCrssPerUsr (Rol_Role_t Role);
+float Usr_GetNumUsrsPerCrs (Rol_Role_t Role);
bool Usr_CheckIfUsrBanned (long UsrCod);
void Usr_RemoveUsrFromUsrBanned (long UsrCod);
diff --git a/swad_web_service.c b/swad_web_service.c
index 2400dc3b..fd6c8274 100644
--- a/swad_web_service.c
+++ b/swad_web_service.c
@@ -1440,7 +1440,7 @@ int swad__getUsers (struct soap *soap,
Grp_GetListGrpTypesInThisCrs (Grp_ONLY_GROUP_TYPES_WITH_GROUPS);
/***** Get list of users *****/
- Usr_GetListUsrs (Role,Sco_SCOPE_CRS);
+ Usr_GetListUsrs (Sco_SCOPE_CRS,Role);
Svc_CopyListUsers (Role,getUsersOut);
Usr_FreeUsrsList (Role);