Version 15.227.1

This commit is contained in:
Antonio Cañas Vargas 2016-06-23 11:31:51 +02:00
parent 446ca96437
commit faab477ca3
9 changed files with 259 additions and 220 deletions

View File

@ -1868,7 +1868,7 @@ static void Att_ListAttStudents (struct AttendanceEvent *Att)
Grp_ShowFormToSelectSeveralGroups (ActSeeOneAtt); Grp_ShowFormToSelectSeveralGroups (ActSeeOneAtt);
/***** Get and order list of students in this course *****/ /***** Get and order list of students in this course *****/
Usr_GetUsrsLst (Rol_STUDENT,Sco_SCOPE_CRS,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstStds,Rol_STUDENT,Sco_SCOPE_CRS);
if (Gbl.Usrs.LstStds.NumUsrs) if (Gbl.Usrs.LstStds.NumUsrs)
{ {
@ -2190,7 +2190,7 @@ void Att_RegisterStudentsInAttEvent (void)
/***** 1. Get list of students in the groups selected: Gbl.Usrs.LstStds *****/ /***** 1. Get list of students in the groups selected: Gbl.Usrs.LstStds *****/
/* Get list of students in the groups selected */ /* Get list of students in the groups selected */
Usr_GetUsrsLst (Rol_STUDENT,Sco_SCOPE_CRS,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstStds,Rol_STUDENT,Sco_SCOPE_CRS);
if (Gbl.Usrs.LstStds.NumUsrs) // If there are students in the groups selected... if (Gbl.Usrs.LstStds.NumUsrs) // If there are students in the groups selected...
{ {
@ -2533,7 +2533,7 @@ void Usr_ReqListStdsAttendanceCrs (void)
Grp_ShowFormToSelectSeveralGroups (ActReqLstStdAtt); Grp_ShowFormToSelectSeveralGroups (ActReqLstStdAtt);
/***** Get and order lists of users from current course *****/ /***** Get and order lists of users from current course *****/
Usr_GetUsrsLst (Rol_STUDENT,Sco_SCOPE_CRS,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstStds,Rol_STUDENT,Sco_SCOPE_CRS);
if (Gbl.Usrs.LstStds.NumUsrs) if (Gbl.Usrs.LstStds.NumUsrs)
{ {

View File

@ -129,13 +129,14 @@
/****************************** Public constants *****************************/ /****************************** Public constants *****************************/
/*****************************************************************************/ /*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 15.227 (2016-06-21)" #define Log_PLATFORM_VERSION "SWAD 15.227.1 (2016-06-23)"
#define CSS_FILE "swad15.226.css" #define CSS_FILE "swad15.226.css"
#define JS_FILE "swad15.226.js" #define JS_FILE "swad15.226.js"
// Number of lines (includes comments but not blank lines) has been got with the following command: // 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 // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1
/* /*
Version 15.227.1 Jun 23, 2015 Code refactoring in getting/searching users. (202854 lines)
Version 15.227: Jun 21, 2015 Query optimization in search of users. (202820 lines) Version 15.227: Jun 21, 2015 Query optimization in search of users. (202820 lines)
Version 15.226.7: Jun 19, 2015 One new social network. (202969 lines) Version 15.226.7: Jun 19, 2015 One new social network. (202969 lines)
1 change necessary in database: 1 change necessary in database:

View File

@ -1374,11 +1374,9 @@ static void Enr_ReceiveFormUsrsCrs (Rol_Role_t Role)
switch (Role) switch (Role)
{ {
case Rol_STUDENT: case Rol_STUDENT:
Usr_GetUsrsLst (Rol_STUDENT,Sco_SCOPE_CRS,NULL,false);
LstCurrentUsrs = &Gbl.Usrs.LstStds; LstCurrentUsrs = &Gbl.Usrs.LstStds;
break; break;
case Rol_TEACHER: case Rol_TEACHER:
Usr_GetUsrsLst (Rol_TEACHER,Sco_SCOPE_CRS,NULL,false);
LstCurrentUsrs = &Gbl.Usrs.LstTchs; LstCurrentUsrs = &Gbl.Usrs.LstTchs;
break; break;
default: default:
@ -1386,6 +1384,7 @@ static void Enr_ReceiveFormUsrsCrs (Rol_Role_t Role)
Lay_ShowErrorAndExit ("Wrong role."); // If user manipulated the form Lay_ShowErrorAndExit ("Wrong role."); // If user manipulated the form
break; break;
} }
Usr_GetListUsrs (LstCurrentUsrs,Rol_STUDENT,Sco_SCOPE_CRS);
if (LstCurrentUsrs->NumUsrs) if (LstCurrentUsrs->NumUsrs)
{ {
@ -1880,7 +1879,7 @@ unsigned Enr_RemAllStdsInCrs (struct Course *Crs)
/***** Get list of students in current course *****/ /***** Get list of students in current course *****/
Gbl.Usrs.ClassPhoto.AllGroups = true; // Get all the students of the current course Gbl.Usrs.ClassPhoto.AllGroups = true; // Get all the students of the current course
Usr_GetUsrsLst (Rol_STUDENT,Sco_SCOPE_CRS,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstStds,Rol_STUDENT,Sco_SCOPE_CRS);
NumStdsInCrs = Gbl.Usrs.LstStds.NumUsrs; NumStdsInCrs = Gbl.Usrs.LstStds.NumUsrs;
/***** Remove all the students *****/ /***** Remove all the students *****/

View File

@ -3096,8 +3096,8 @@ void Brw_AskEditWorksCrs (void)
Grp_ShowFormToSelectSeveralGroups (ActReqAsgWrkCrs); Grp_ShowFormToSelectSeveralGroups (ActReqAsgWrkCrs);
/***** Get and order lists of users from this course *****/ /***** Get and order lists of users from this course *****/
Usr_GetUsrsLst (Rol_TEACHER,Sco_SCOPE_CRS,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstTchs,Rol_TEACHER,Sco_SCOPE_CRS);
Usr_GetUsrsLst (Rol_STUDENT,Sco_SCOPE_CRS,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstStds,Rol_STUDENT,Sco_SCOPE_CRS);
if (Gbl.Usrs.LstTchs.NumUsrs || if (Gbl.Usrs.LstTchs.NumUsrs ||
Gbl.Usrs.LstStds.NumUsrs) Gbl.Usrs.LstStds.NumUsrs)

View File

@ -162,7 +162,7 @@ void Msg_ListEMails (void)
Grp_ShowFormToSelectSeveralGroups (ActMaiStd); Grp_ShowFormToSelectSeveralGroups (ActMaiStd);
/***** Get and order list of students in this course *****/ /***** Get and order list of students in this course *****/
Usr_GetUsrsLst (Rol_STUDENT,Sco_SCOPE_CRS,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstStds,Rol_STUDENT,Sco_SCOPE_CRS);
if (Gbl.Usrs.LstStds.NumUsrs) if (Gbl.Usrs.LstStds.NumUsrs)
{ {
@ -328,8 +328,8 @@ static void Msg_PutFormMsgUsrs (const char *Content)
Grp_ShowFormToSelectSeveralGroups (ActReqMsgUsr); Grp_ShowFormToSelectSeveralGroups (ActReqMsgUsr);
/***** Get and order lists of users from this course *****/ /***** Get and order lists of users from this course *****/
Usr_GetUsrsLst (Rol_TEACHER,Sco_SCOPE_CRS,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstTchs,Rol_TEACHER,Sco_SCOPE_CRS);
Usr_GetUsrsLst (Rol_STUDENT,Sco_SCOPE_CRS,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstStds,Rol_STUDENT,Sco_SCOPE_CRS);
if (Gbl.Usrs.LstTchs.NumUsrs || if (Gbl.Usrs.LstTchs.NumUsrs ||
Gbl.Usrs.LstStds.NumUsrs) Gbl.Usrs.LstStds.NumUsrs)

View File

@ -417,8 +417,8 @@ void Sta_AskShowCrsHits (void)
Grp_ShowFormToSelectSeveralGroups (ActReqAccCrs); Grp_ShowFormToSelectSeveralGroups (ActReqAccCrs);
/***** Get and order the lists of users of this course *****/ /***** Get and order the lists of users of this course *****/
Usr_GetUsrsLst (Rol_TEACHER,Sco_SCOPE_CRS,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstTchs,Rol_TEACHER,Sco_SCOPE_CRS);
Usr_GetUsrsLst (Rol_STUDENT,Sco_SCOPE_CRS,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstStds,Rol_STUDENT,Sco_SCOPE_CRS);
if (Gbl.Usrs.LstTchs.NumUsrs || if (Gbl.Usrs.LstTchs.NumUsrs ||
Gbl.Usrs.LstStds.NumUsrs) Gbl.Usrs.LstStds.NumUsrs)

View File

@ -6821,8 +6821,8 @@ void Tst_SelUsrsToSeeUsrsExams (void)
Grp_ShowFormToSelectSeveralGroups (ActReqSeeUsrTstExa); Grp_ShowFormToSelectSeveralGroups (ActReqSeeUsrTstExa);
/***** Get and order lists of users from this course *****/ /***** Get and order lists of users from this course *****/
Usr_GetUsrsLst (Rol_TEACHER,Sco_SCOPE_CRS,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstTchs,Rol_TEACHER,Sco_SCOPE_CRS);
Usr_GetUsrsLst (Rol_STUDENT,Sco_SCOPE_CRS,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstStds,Rol_STUDENT,Sco_SCOPE_CRS);
if (Gbl.Usrs.LstTchs.NumUsrs || if (Gbl.Usrs.LstTchs.NumUsrs ||
Gbl.Usrs.LstStds.NumUsrs) Gbl.Usrs.LstStds.NumUsrs)

View File

@ -141,10 +141,10 @@ static void Usr_WriteUsrData (const char *BgColor,
const char *Data,const char *Link, const char *Data,const char *Link,
bool NonBreak,bool Accepted); bool NonBreak,bool Accepted);
static void Usr_BuildQueryToGetUsrsLstCrs (Rol_Role_t Role,const char *UsrQuery,bool Search,char *Query); static void Usr_BuildQueryToGetUsrsLstCrs (Rol_Role_t Role,bool Search,const char *UsrQuery,char *Query);
static void Usr_GetAdmsLst (Sco_Scope_t Scope); static void Usr_GetAdmsLst (Sco_Scope_t Scope);
static void Usr_GetGstsLst (Sco_Scope_t Scope); static void Usr_GetGstsLst (Sco_Scope_t Scope);
static void Usr_GetListUsrs (const char *Query,struct ListUsers *LstUsrs, static void Usr_GetListUsrsFromQuery (const char *Query,struct ListUsers *LstUsrs,
Rol_Role_t Role,Sco_Scope_t Scope); Rol_Role_t Role,Sco_Scope_t Scope);
static void Usr_AllocateUsrsList (struct ListUsers *LstUsrs); static void Usr_AllocateUsrsList (struct ListUsers *LstUsrs);
static void Usr_ShowWarningListIsTooBig (unsigned NumStds); static void Usr_ShowWarningListIsTooBig (unsigned NumStds);
@ -3535,7 +3535,7 @@ unsigned Usr_GetNumberOfTeachersInCentre (long CtrCod)
/******* Build query to get list with data of users in current course ********/ /******* Build query to get list with data of users in current course ********/
/*****************************************************************************/ /*****************************************************************************/
static void Usr_BuildQueryToGetUsrsLstCrs (Rol_Role_t Role,const char *UsrQuery,bool Search,char *Query) static void Usr_BuildQueryToGetUsrsLstCrs (Rol_Role_t Role,bool Search,const char *UsrQuery,char *Query)
{ {
unsigned NumPositiveCods = 0; unsigned NumPositiveCods = 0;
unsigned NumNegativeCods = 0; unsigned NumNegativeCods = 0;
@ -3679,48 +3679,23 @@ static void Usr_BuildQueryToGetUsrsLstCrs (Rol_Role_t Role,const char *UsrQuery,
} }
/*****************************************************************************/ /*****************************************************************************/
/************************* Get list with data of users ***********************/ /*********** Get list of users with a given role in a given scope ************/
/*****************************************************************************/ /*****************************************************************************/
#define Usr_MAX_LENGTH_QUERY_LIST_USERS (16*1024) // Role can be:
// - Rol_STUDENT
// - Rol_TEACHER
void Usr_GetUsrsLst (Rol_Role_t Role,Sco_Scope_t Scope,const char *UsrQuery,bool Search) void Usr_GetListUsrs (struct ListUsers *LstUsrs,Rol_Role_t Role,Sco_Scope_t Scope)
{ {
char Query[Usr_MAX_LENGTH_QUERY_LIST_USERS+1]; char Query[512];
/***** Build query *****/ /***** Build query *****/
if (Search && Role == Rol__GUEST_) // Special case
/* Select users with no courses */
sprintf (Query,"SELECT UsrCod,Sex"
" FROM usr_data"
" WHERE %s"
" AND UsrCod NOT IN (SELECT UsrCod FROM crs_usr)"
" ORDER BY "
"Surname1,"
"Surname2,"
"FirstName,"
"UsrCod",
UsrQuery);
else // Rest of cases
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
/* Get users from the whole platform */ /* Get users in courses from the whole platform */
// 2 columns are retrieved: UsrCod, Sex // 2 columns are retrieved: UsrCod, Sex
if (Search)
sprintf (Query,"SELECT DISTINCT usr_data.UsrCod,usr_data.Sex"
" FROM usr_data,crs_usr"
" WHERE %s"
" AND usr_data.UsrCod=crs_usr.UsrCod"
" AND crs_usr.Role='%u'"
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod",
UsrQuery,
(unsigned) Role);
else
sprintf (Query,"SELECT DISTINCT usr_data.UsrCod,usr_data.Sex" sprintf (Query,"SELECT DISTINCT usr_data.UsrCod,usr_data.Sex"
" FROM usr_data,crs_usr" " FROM usr_data,crs_usr"
" WHERE usr_data.UsrCod=crs_usr.UsrCod" " WHERE usr_data.UsrCod=crs_usr.UsrCod"
@ -3733,9 +3708,141 @@ void Usr_GetUsrsLst (Rol_Role_t Role,Sco_Scope_t Scope,const char *UsrQuery,bool
(unsigned) Role); (unsigned) Role);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
/* Get users from the current country */ /* Get users in courses from the current country */
// 2 columns are retrieved: UsrCod, Sex
sprintf (Query,"SELECT DISTINCT usr_data.UsrCod,usr_data.Sex"
" FROM usr_data,crs_usr,courses,degrees,centres,institutions"
" WHERE usr_data.UsrCod=crs_usr.UsrCod"
" AND crs_usr.Role='%u'"
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod='%ld'"
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod",
(unsigned) Role,
Gbl.CurrentCty.Cty.CtyCod);
break;
case Sco_SCOPE_INS:
/* Get users in courses from the current institution */
// 2 columns are retrieved: UsrCod, Sex
sprintf (Query,"SELECT DISTINCT usr_data.UsrCod,usr_data.Sex"
" FROM usr_data,crs_usr,courses,degrees,centres"
" WHERE usr_data.UsrCod=crs_usr.UsrCod"
" AND crs_usr.Role='%u'"
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod='%ld'"
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod",
(unsigned) Role,
Gbl.CurrentIns.Ins.InsCod);
break;
case Sco_SCOPE_CTR:
/* Get users in courses from the current centre */
// 2 columns are retrieved: UsrCod, Sex
sprintf (Query,"SELECT DISTINCT usr_data.UsrCod,usr_data.Sex"
" FROM usr_data,crs_usr,courses,degrees"
" WHERE usr_data.UsrCod=crs_usr.UsrCod"
" AND crs_usr.Role='%u'"
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod='%ld'"
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod",
(unsigned) Role,
Gbl.CurrentCtr.Ctr.CtrCod);
break;
case Sco_SCOPE_DEG:
/* Get users in courses from the current degree */
// 2 columns are retrieved: UsrCod, Sex
sprintf (Query,"SELECT DISTINCT usr_data.UsrCod,usr_data.Sex"
" FROM usr_data,crs_usr,courses"
" WHERE usr_data.UsrCod=crs_usr.UsrCod"
" AND crs_usr.Role='%u'"
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod='%ld'"
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod",
(unsigned) Role,
Gbl.CurrentDeg.Deg.DegCod);
break;
case Sco_SCOPE_CRS:
/* Get users from the current course */
// 3 columns are retrieved: UsrCod, Sex, Accepted
Usr_BuildQueryToGetUsrsLstCrs (Role,false,NULL,Query);
break;
default:
Lay_ShowErrorAndExit ("Wrong scope.");
break;
}
/*
if (Gbl.Usrs.Me.LoggedRole == Rol_ROLE_SYS_ADM)
Lay_ShowAlert (Lay_INFO,Query);
*/
/***** Get list of users from database given a query *****/
Usr_GetListUsrsFromQuery (Query,LstUsrs,Role,Scope);
}
/*****************************************************************************/
/********* Search list of users with a given role in current scope ***********/
/*****************************************************************************/
void Usr_SearchListUsrs (struct ListUsers *LstUsrs,Rol_Role_t Role,const char *UsrQuery)
{
char Query[16*1024];
/***** Build query *****/
if (Role == Rol__GUEST_) // Guests
/* Search users with no courses */
sprintf (Query,"SELECT UsrCod,Sex"
" FROM usr_data"
" WHERE %s"
" AND UsrCod NOT IN (SELECT UsrCod FROM crs_usr)"
" ORDER BY "
"Surname1,"
"Surname2,"
"FirstName,"
"UsrCod",
UsrQuery);
else // Students / Teachers
switch (Gbl.Scope.Current)
{
case Sco_SCOPE_SYS:
/* Search users in courses from the whole platform */
// 2 columns are retrieved: UsrCod, Sex
sprintf (Query,"SELECT list_usrs.UsrCod,usr_data.Sex FROM "
"(SELECT DISTINCT candidate_users.UsrCod"
" FROM (SELECT UsrCod FROM usr_data WHERE %s) AS candidate_users,crs_usr"
" WHERE candidate_users.UsrCod=crs_usr.UsrCod"
" AND crs_usr.Role='%u') AS list_usrs,usr_data"
" WHERE list_usrs.UsrCod=usr_data.UsrCod "
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod",
UsrQuery,
(unsigned) Role);
break;
case Sco_SCOPE_CTY:
/* Search users in courses from the current country */
// 2 columns are retrieved: UsrCod, Sex // 2 columns are retrieved: UsrCod, Sex
if (Search)
sprintf (Query,"SELECT list_usrs.UsrCod,usr_data.Sex FROM " sprintf (Query,"SELECT list_usrs.UsrCod,usr_data.Sex FROM "
"(SELECT DISTINCT candidate_users.UsrCod" "(SELECT DISTINCT candidate_users.UsrCod"
" FROM (SELECT UsrCod FROM usr_data WHERE %s) AS candidate_users,crs_usr,courses,degrees,centres,institutions" " FROM (SELECT UsrCod FROM usr_data WHERE %s) AS candidate_users,crs_usr,courses,degrees,centres,institutions"
@ -3755,28 +3862,10 @@ void Usr_GetUsrsLst (Rol_Role_t Role,Sco_Scope_t Scope,const char *UsrQuery,bool
UsrQuery, UsrQuery,
(unsigned) Role, (unsigned) Role,
Gbl.CurrentCty.Cty.CtyCod); Gbl.CurrentCty.Cty.CtyCod);
else
sprintf (Query,"SELECT DISTINCT usr_data.UsrCod,usr_data.Sex"
" FROM usr_data,crs_usr,courses,degrees,centres,institutions"
" WHERE usr_data.UsrCod=crs_usr.UsrCod"
" AND crs_usr.Role='%u'"
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod='%ld'"
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod",
(unsigned) Role,
Gbl.CurrentCty.Cty.CtyCod);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
/* Get users from the current institution */ /* Search users in courses from the current institution */
// 2 columns are retrieved: UsrCod, Sex // 2 columns are retrieved: UsrCod, Sex
if (Search)
sprintf (Query,"SELECT list_usrs.UsrCod,usr_data.Sex FROM " sprintf (Query,"SELECT list_usrs.UsrCod,usr_data.Sex FROM "
"(SELECT DISTINCT candidate_users.UsrCod" "(SELECT DISTINCT candidate_users.UsrCod"
" FROM (SELECT UsrCod FROM usr_data WHERE %s) AS candidate_users,crs_usr,courses,degrees,centres" " FROM (SELECT UsrCod FROM usr_data WHERE %s) AS candidate_users,crs_usr,courses,degrees,centres"
@ -3795,27 +3884,10 @@ void Usr_GetUsrsLst (Rol_Role_t Role,Sco_Scope_t Scope,const char *UsrQuery,bool
UsrQuery, UsrQuery,
(unsigned) Role, (unsigned) Role,
Gbl.CurrentIns.Ins.InsCod); Gbl.CurrentIns.Ins.InsCod);
else
sprintf (Query,"SELECT DISTINCT usr_data.UsrCod,usr_data.Sex"
" FROM usr_data,crs_usr,courses,degrees,centres"
" WHERE usr_data.UsrCod=crs_usr.UsrCod"
" AND crs_usr.Role='%u'"
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod='%ld'"
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod",
(unsigned) Role,
Gbl.CurrentIns.Ins.InsCod);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
/* Get users from the current centre */ /* Search users in courses from the current centre */
// 2 columns are retrieved: UsrCod, Sex // 2 columns are retrieved: UsrCod, Sex
if (Search)
sprintf (Query,"SELECT list_usrs.UsrCod,usr_data.Sex FROM " sprintf (Query,"SELECT list_usrs.UsrCod,usr_data.Sex FROM "
"(SELECT DISTINCT candidate_users.UsrCod" "(SELECT DISTINCT candidate_users.UsrCod"
" FROM (SELECT UsrCod FROM usr_data WHERE %s) AS candidate_users,crs_usr,courses,degrees" " FROM (SELECT UsrCod FROM usr_data WHERE %s) AS candidate_users,crs_usr,courses,degrees"
@ -3833,26 +3905,10 @@ void Usr_GetUsrsLst (Rol_Role_t Role,Sco_Scope_t Scope,const char *UsrQuery,bool
UsrQuery, UsrQuery,
(unsigned) Role, (unsigned) Role,
Gbl.CurrentCtr.Ctr.CtrCod); Gbl.CurrentCtr.Ctr.CtrCod);
else
sprintf (Query,"SELECT DISTINCT usr_data.UsrCod,usr_data.Sex"
" FROM usr_data,crs_usr,courses,degrees"
" WHERE usr_data.UsrCod=crs_usr.UsrCod"
" AND crs_usr.Role='%u'"
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod='%ld'"
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod",
(unsigned) Role,
Gbl.CurrentCtr.Ctr.CtrCod);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
/* Get users from the current degree */ /* Search users in courses from the current degree */
// 2 columns are retrieved: UsrCod, Sex // 2 columns are retrieved: UsrCod, Sex
if (Search)
sprintf (Query,"SELECT list_usrs.UsrCod,usr_data.Sex FROM " sprintf (Query,"SELECT list_usrs.UsrCod,usr_data.Sex FROM "
"(SELECT DISTINCT candidate_users.UsrCod" "(SELECT DISTINCT candidate_users.UsrCod"
" FROM (SELECT UsrCod FROM usr_data WHERE %s) AS candidate_users,crs_usr,courses" " FROM (SELECT UsrCod FROM usr_data WHERE %s) AS candidate_users,crs_usr,courses"
@ -3869,25 +3925,11 @@ void Usr_GetUsrsLst (Rol_Role_t Role,Sco_Scope_t Scope,const char *UsrQuery,bool
UsrQuery, UsrQuery,
(unsigned) Role, (unsigned) Role,
Gbl.CurrentDeg.Deg.DegCod); Gbl.CurrentDeg.Deg.DegCod);
else
sprintf (Query,"SELECT DISTINCT usr_data.UsrCod,usr_data.Sex"
" FROM usr_data,crs_usr,courses"
" WHERE usr_data.UsrCod=crs_usr.UsrCod"
" AND crs_usr.Role='%u'"
" AND crs_usr.CrsCod=courses.CrsCod"
" AND courses.DegCod='%ld'"
" ORDER BY "
"usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
"usr_data.UsrCod",
(unsigned) Role,
Gbl.CurrentDeg.Deg.DegCod);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
/* Get users from the current course */ /* Search users in courses from the current course */
// 3 columns are retrieved: UsrCod, Sex, Accepted // 3 columns are retrieved: UsrCod, Sex, Accepted
Usr_BuildQueryToGetUsrsLstCrs (Role,UsrQuery,Search,Query); Usr_BuildQueryToGetUsrsLstCrs (Role,true,UsrQuery,Query);
break; break;
default: default:
Lay_ShowErrorAndExit ("Wrong scope."); Lay_ShowErrorAndExit ("Wrong scope.");
@ -3897,13 +3939,8 @@ void Usr_GetUsrsLst (Rol_Role_t Role,Sco_Scope_t Scope,const char *UsrQuery,bool
if (Gbl.Usrs.Me.LoggedRole == Rol_ROLE_SYS_ADM) if (Gbl.Usrs.Me.LoggedRole == Rol_ROLE_SYS_ADM)
Lay_ShowAlert (Lay_INFO,Query); Lay_ShowAlert (Lay_INFO,Query);
*/ */
/***** Get list of users from database *****/ /***** Get list of users from database given a query *****/
Usr_GetListUsrs (Query, Usr_GetListUsrsFromQuery (Query,LstUsrs,Role,Gbl.Scope.Current);
( Role == Rol_TEACHER ? &Gbl.Usrs.LstTchs :
(Role == Rol_STUDENT ? &Gbl.Usrs.LstStds :
&Gbl.Usrs.LstGsts)),
Role,
Scope);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4032,7 +4069,7 @@ static void Usr_GetAdmsLst (Sco_Scope_t Scope)
} }
/***** Get list of administrators from database *****/ /***** Get list of administrators from database *****/
Usr_GetListUsrs (Query,&Gbl.Usrs.LstAdms,Rol_UNKNOWN,Scope); Usr_GetListUsrsFromQuery (Query,&Gbl.Usrs.LstAdms,Rol_UNKNOWN,Scope);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4083,7 +4120,7 @@ static void Usr_GetGstsLst (Sco_Scope_t Scope)
} }
/***** Get list of students from database *****/ /***** Get list of students from database *****/
Usr_GetListUsrs (Query,&Gbl.Usrs.LstGsts,Rol__GUEST_,Scope); Usr_GetListUsrsFromQuery (Query,&Gbl.Usrs.LstGsts,Rol__GUEST_,Scope);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4109,7 +4146,7 @@ void Usr_GetUnorderedStdsCodesInDeg (long DegCod)
DegCod,(unsigned) Rol_STUDENT); DegCod,(unsigned) Rol_STUDENT);
/***** Get list of students from database *****/ /***** Get list of students from database *****/
Usr_GetListUsrs (Query,&Gbl.Usrs.LstStds,Rol_STUDENT,Sco_SCOPE_DEG); Usr_GetListUsrsFromQuery (Query,&Gbl.Usrs.LstStds,Rol_STUDENT,Sco_SCOPE_DEG);
} }
} }
@ -4117,7 +4154,7 @@ void Usr_GetUnorderedStdsCodesInDeg (long DegCod)
/********************** Get list of users from database **********************/ /********************** Get list of users from database **********************/
/*****************************************************************************/ /*****************************************************************************/
static void Usr_GetListUsrs (const char *Query,struct ListUsers *LstUsrs, static void Usr_GetListUsrsFromQuery (const char *Query,struct ListUsers *LstUsrs,
Rol_Role_t Role,Sco_Scope_t Scope) Rol_Role_t Role,Sco_Scope_t Scope)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
@ -5355,7 +5392,7 @@ void Usr_ListAllDataStds (void)
Sco_GetScope (); Sco_GetScope ();
/****** Get and order list of students in current course ******/ /****** Get and order list of students in current course ******/
Usr_GetUsrsLst (Rol_STUDENT,Gbl.Scope.Current,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstStds,Rol_STUDENT,Gbl.Scope.Current);
if (Gbl.Usrs.LstStds.NumUsrs) if (Gbl.Usrs.LstStds.NumUsrs)
{ {
@ -5602,7 +5639,7 @@ void Usr_ListAllDataTchs (void)
Sco_GetScope (); Sco_GetScope ();
/***** Get and order list of teachers *****/ /***** Get and order list of teachers *****/
Usr_GetUsrsLst (Rol_TEACHER,Gbl.Scope.Current,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstTchs,Rol_TEACHER,Gbl.Scope.Current);
if (Gbl.Usrs.LstTchs.NumUsrs) if (Gbl.Usrs.LstTchs.NumUsrs)
{ {
@ -5681,7 +5718,7 @@ unsigned Usr_ListUsrsFound (Rol_Role_t Role,const char *UsrQuery)
Usr_SetUsrDatMainFieldNames (); Usr_SetUsrDatMainFieldNames ();
/***** Search for users *****/ /***** Search for users *****/
Usr_GetUsrsLst (Role,Gbl.Scope.Current,UsrQuery,true); Usr_SearchListUsrs (LstUsrs,Role,UsrQuery);
if ((NumUsrs = LstUsrs->NumUsrs)) if ((NumUsrs = LstUsrs->NumUsrs))
{ {
/***** Write heading *****/ /***** Write heading *****/
@ -6434,7 +6471,7 @@ void Usr_SeeStudents (void)
Grp_ShowFormToSelectSeveralGroups (ActLstStd); Grp_ShowFormToSelectSeveralGroups (ActLstStd);
/***** Get and order list of students *****/ /***** Get and order list of students *****/
Usr_GetUsrsLst (Rol_STUDENT,Gbl.Scope.Current,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstStds,Rol_STUDENT,Gbl.Scope.Current);
if (Usr_GetIfShowBigList (Gbl.Usrs.LstStds.NumUsrs)) if (Usr_GetIfShowBigList (Gbl.Usrs.LstStds.NumUsrs))
{ {
@ -6594,7 +6631,7 @@ void Usr_SeeTeachers (void)
ICanViewRecords = (Gbl.Scope.Current == Sco_SCOPE_CRS); ICanViewRecords = (Gbl.Scope.Current == Sco_SCOPE_CRS);
/***** Get and order list of teachers *****/ /***** Get and order list of teachers *****/
Usr_GetUsrsLst (Rol_TEACHER,Gbl.Scope.Current,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstTchs,Rol_TEACHER,Gbl.Scope.Current);
if (Usr_GetIfShowBigList (Gbl.Usrs.LstTchs.NumUsrs)) if (Usr_GetIfShowBigList (Gbl.Usrs.LstTchs.NumUsrs))
{ {
@ -6831,7 +6868,7 @@ void Usr_SeeStdClassPhotoPrn (void)
Grp_GetParCodsSeveralGrpsToShowUsrs (); Grp_GetParCodsSeveralGrpsToShowUsrs ();
/***** Get and order list of students *****/ /***** Get and order list of students *****/
Usr_GetUsrsLst (Rol_STUDENT,Gbl.Scope.Current,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstStds,Rol_STUDENT,Gbl.Scope.Current);
if (Gbl.Usrs.LstStds.NumUsrs) if (Gbl.Usrs.LstStds.NumUsrs)
{ {
@ -6887,7 +6924,7 @@ void Usr_SeeTchClassPhotoPrn (void)
Sco_GetScope (); Sco_GetScope ();
/***** Get and order list of teachers *****/ /***** Get and order list of teachers *****/
Usr_GetUsrsLst (Rol_TEACHER,Gbl.Scope.Current,NULL,false); Usr_GetListUsrs (&Gbl.Usrs.LstTchs,Rol_TEACHER,Gbl.Scope.Current);
if (Gbl.Usrs.LstTchs.NumUsrs) if (Gbl.Usrs.LstTchs.NumUsrs)
{ {

View File

@ -303,7 +303,9 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (long InsCod);
unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (long CtrCod); unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (long CtrCod);
unsigned Usr_GetNumberOfTeachersInCentre (long CtrCod); unsigned Usr_GetNumberOfTeachersInCentre (long CtrCod);
void Usr_GetUsrsLst (Rol_Role_t Role,Sco_Scope_t Scope,const char *UsrQuery,bool Search); void Usr_GetListUsrs (struct ListUsers *LstUsrs,Rol_Role_t Role,Sco_Scope_t Scope);
void Usr_SearchListUsrs (struct ListUsers *LstUsrs,Rol_Role_t Role,const char *UsrQuery);
void Usr_GetUnorderedStdsCodesInDeg (long DegCod); void Usr_GetUnorderedStdsCodesInDeg (long DegCod);
void Usr_FreeUsrsList (struct ListUsers *LstUsrs); void Usr_FreeUsrsList (struct ListUsers *LstUsrs);
bool Usr_GetIfShowBigList (unsigned NumUsrs); bool Usr_GetIfShowBigList (unsigned NumUsrs);