diff --git a/swad_centre.c b/swad_centre.c
index a510b68fa..cdbfbfd51 100644
--- a/swad_centre.c
+++ b/swad_centre.c
@@ -249,7 +249,6 @@ void Ctr_PrintConfiguration (void)
static void Ctr_Configuration (bool PrintView)
{
extern const char *The_ClassForm[The_NUM_THEMES];
- extern const char *Txt_Degrees;
extern const char *Txt_Print;
extern const char *Txt_Centre;
extern const char *Txt_Short_name;
@@ -257,8 +256,12 @@ static void Ctr_Configuration (bool PrintView)
extern const char *Txt_Shortcut;
extern const char *Txt_STR_LANG_ID[1+Txt_NUM_LANGUAGES];
extern const char *Txt_QR_code;
+ extern const char *Txt_Users_of_the_centre;
+ extern const char *Txt_Place;
+ extern const char *Txt_Degrees;
extern const char *Txt_Courses;
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
+ struct Place Plc;
char PathPhoto[PATH_MAX+1];
bool PhotoExists;
char *PhotoAttribution = NULL;
@@ -454,6 +457,34 @@ static void Ctr_Configuration (bool PrintView)
}
else
{
+ /***** Place *****/
+ Plc.PlcCod = Gbl.CurrentCtr.Ctr.PlcCod;
+ Plc_GetDataOfPlaceByCod (&Plc);
+ fprintf (Gbl.F.Out,"
"
+ ""
+ "%s:"
+ " | "
+ ""
+ "%s"
+ " | "
+ "
",
+ The_ClassForm[Gbl.Prefs.Theme],
+ Txt_Place,
+ Plc.FullName);
+
+ /***** Number of users who claim to belong to this centre *****/
+ fprintf (Gbl.F.Out,""
+ ""
+ "%s:"
+ " | "
+ ""
+ "%u"
+ " | "
+ "
",
+ The_ClassForm[Gbl.Prefs.Theme],
+ Txt_Users_of_the_centre,
+ Usr_GetNumUsrsWhoClaimToBelongToCtr (Gbl.CurrentCtr.Ctr.CtrCod));
+
/***** Number of degrees *****/
fprintf (Gbl.F.Out,""
""
@@ -480,7 +511,7 @@ static void Ctr_Configuration (bool PrintView)
Txt_Courses,
Crs_GetNumCrssInCtr (Gbl.CurrentCtr.Ctr.CtrCod));
- /***** Number of teachers *****/
+ /***** Number of teachers in courses of this centre *****/
fprintf (Gbl.F.Out," |
"
""
"%s:"
@@ -493,7 +524,7 @@ static void Ctr_Configuration (bool PrintView)
Txt_ROLES_PLURAL_Abc[Rol_TEACHER][Usr_SEX_UNKNOWN],
Usr_GetNumUsrsInCrssOfCtr (Rol_TEACHER,Gbl.CurrentCtr.Ctr.CtrCod));
- /***** Number of students *****/
+ /***** Number of students in courses of this centre *****/
fprintf (Gbl.F.Out," |
"
""
"%s:"
@@ -505,6 +536,20 @@ static void Ctr_Configuration (bool PrintView)
The_ClassForm[Gbl.Prefs.Theme],
Txt_ROLES_PLURAL_Abc[Rol_STUDENT][Usr_SEX_UNKNOWN],
Usr_GetNumUsrsInCrssOfCtr (Rol_STUDENT,Gbl.CurrentCtr.Ctr.CtrCod));
+
+ /***** Number of users in courses of this centre *****/
+ fprintf (Gbl.F.Out," |
"
+ ""
+ "%s + %s:"
+ " | "
+ ""
+ "%u"
+ " | "
+ "
",
+ The_ClassForm[Gbl.Prefs.Theme],
+ Txt_ROLES_PLURAL_Abc[Rol_TEACHER][Usr_SEX_UNKNOWN],
+ Txt_ROLES_PLURAL_Abc[Rol_STUDENT][Usr_SEX_UNKNOWN],
+ Usr_GetNumUsrsInCrssOfCtr (Rol_UNKNOWN,Gbl.CurrentCtr.Ctr.CtrCod));
}
/***** End frame *****/
@@ -596,8 +641,6 @@ static void Ctr_ListCentresForSeeing (void)
static void Ctr_ListOneCentreForSeeing (struct Centre *Ctr,unsigned NumCtr)
{
- extern const char *Txt_Another_place;
- extern const char *Txt_Go_to_X;
extern const char *Txt_CENTRE_STATUS[Ctr_NUM_STATUS_TXT];
struct Place Plc;
const char *TxtClassNormal;
@@ -636,12 +679,19 @@ static void Ctr_ListOneCentreForSeeing (struct Centre *Ctr,unsigned NumCtr)
TxtClassStrong,"CENTER_MIDDLE");
fprintf (Gbl.F.Out,"");
- /***** Number of teachers *****/
+ /***** Number of users who claim to belong to this centre *****/
fprintf (Gbl.F.Out,""
"%u"
" | ",
TxtClassNormal,BgColor,
- Ctr->NumTchs);
+ Ctr->NumUsrsWhoClaimToBelongToCtr);
+
+ /***** Place *****/
+ fprintf (Gbl.F.Out,""
+ "%s"
+ " | ",
+ TxtClassNormal,BgColor,
+ Plc.ShortName);
/***** Number of degrees *****/
fprintf (Gbl.F.Out,""
@@ -650,13 +700,33 @@ static void Ctr_ListOneCentreForSeeing (struct Centre *Ctr,unsigned NumCtr)
TxtClassNormal,BgColor,
Ctr->NumDegs);
- /***** Place *****/
- fprintf (Gbl.F.Out," | "
- "%s"
+ /***** Number of courses *****/
+ fprintf (Gbl.F.Out," | "
+ "%u"
" | ",
TxtClassNormal,BgColor,
- Plc.PlcCod > 0 ? Plc.ShortName :
- Txt_Another_place);
+ Ctr->NumCrss);
+
+ /***** Number of teachers in courses of this centre *****/
+ fprintf (Gbl.F.Out,""
+ "%u"
+ " | ",
+ TxtClassNormal,BgColor,
+ Ctr->NumTchs);
+
+ /***** Number of students in courses of this centre *****/
+ fprintf (Gbl.F.Out,""
+ "%u"
+ " | ",
+ TxtClassNormal,BgColor,
+ Ctr->NumStds);
+
+ /***** Number of users in courses of this centre *****/
+ fprintf (Gbl.F.Out,""
+ "%u"
+ " | ",
+ TxtClassNormal,BgColor,
+ Ctr->NumUsrs);
/***** Centre status *****/
StatusTxt = Ctr_GetStatusTxtFromStatusBits (Ctr->Status);
@@ -755,53 +825,28 @@ void Ctr_GetListCentres (long InsCod)
sprintf (OrderBySubQuery,"FullName");
break;
case Ctr_ORDER_BY_NUM_TCHS:
- sprintf (OrderBySubQuery,"NumTchs DESC,FullName");
+ sprintf (OrderBySubQuery,"NumUsrs DESC,FullName");
break;
}
- if (InsCod > 0) // Only the centres of the specified institution
- sprintf (Query,"(SELECT centres.CtrCod,centres.InsCod,centres.PlcCod,"
- "centres.Status,centres.RequesterUsrCod,"
- "centres.ShortName,centres.FullName,centres.WWW,"
- "COUNT(DISTINCT usr_data.UsrCod) AS NumTchs"
- " FROM centres,usr_data,crs_usr"
- " WHERE centres.InsCod='%ld' AND crs_usr.Role='%u'"
- " AND crs_usr.UsrCod=usr_data.UsrCod AND usr_data.CtrCod=centres.CtrCod"
- " GROUP BY centres.CtrCod)"
- " UNION "
- "(SELECT CtrCod,InsCod,PlcCod,Status,RequesterUsrCod,"
- "ShortName,FullName,WWW,0 AS NumTchs"
- " FROM centres"
- " WHERE centres.InsCod='%ld' AND CtrCod NOT IN"
- " (SELECT DISTINCT usr_data.CtrCod FROM usr_data,crs_usr"
- " WHERE centres.InsCod='%ld' AND crs_usr.Role='%u'"
- " AND crs_usr.UsrCod=usr_data.UsrCod))"
- " ORDER BY %s",
- InsCod,
- (unsigned) Rol_TEACHER,
- InsCod,InsCod,
- (unsigned) Rol_TEACHER,
- OrderBySubQuery);
- else // InsCod <= 0 ==> all the centres
- sprintf (Query,"(SELECT centres.CtrCod,centres.InsCod,centres.PlcCod,"
- "centres.Status,centres.RequesterUsrCod,"
- "centres.ShortName,centres.FullName,centres.WWW,"
- "COUNT(DISTINCT usr_data.UsrCod) AS NumTchs"
- " FROM centres,usr_data,crs_usr"
- " WHERE crs_usr.Role='%u'"
- " AND crs_usr.UsrCod=usr_data.UsrCod AND usr_data.CtrCod=centres.CtrCod"
- " GROUP BY centres.CtrCod)"
- " UNION "
- "(SELECT CtrCod,InsCod,PlcCod,Status,RequesterUsrCod,"
- "ShortName,FullName,WWW,0 AS NumTchs"
- " FROM centres"
- " WHERE CtrCod NOT IN"
- " (SELECT DISTINCT usr_data.CtrCod FROM usr_data,crs_usr"
- " WHERE crs_usr.Role='%u'"
- " AND crs_usr.UsrCod=usr_data.UsrCod))"
- " ORDER BY %s",
- (unsigned) Rol_TEACHER,
- (unsigned) Rol_TEACHER,
- OrderBySubQuery);
+ sprintf (Query,"(SELECT centres.CtrCod,centres.InsCod,centres.PlcCod,"
+ "centres.Status,centres.RequesterUsrCod,"
+ "centres.ShortName,centres.FullName,centres.WWW,"
+ "COUNT(DISTINCT usr_data.UsrCod) AS NumUsrs"
+ " FROM centres,usr_data"
+ " WHERE centres.InsCod='%ld'"
+ " AND centres.CtrCod=usr_data.CtrCod"
+ " GROUP BY centres.CtrCod)"
+ " UNION "
+ "(SELECT CtrCod,InsCod,PlcCod,Status,RequesterUsrCod,"
+ "ShortName,FullName,WWW,0 AS NumUsrs"
+ " FROM centres"
+ " WHERE centres.InsCod='%ld'"
+ " AND CtrCod NOT IN"
+ " (SELECT DISTINCT CtrCod FROM usr_data))"
+ " ORDER BY %s",
+ InsCod,
+ InsCod,
+ OrderBySubQuery);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get centres");
if (NumRows) // Centres found...
@@ -849,12 +894,20 @@ void Ctr_GetListCentres (long InsCod)
/* Get the URL of the centre (row[7]) */
strcpy (Ctr->WWW,row[7]);
- /* Get number of teachers in this centre (row[8]) */
- if (sscanf (row[8],"%u",&Ctr->NumTchs) != 1)
- Ctr->NumTchs = 0;
+ /* Get number of users who claim to belong to this centre (row[8]) */
+ if (sscanf (row[8],"%u",&Ctr->NumUsrsWhoClaimToBelongToCtr) != 1)
+ Ctr->NumUsrsWhoClaimToBelongToCtr = 0;
- /* Count number of degrees in this centre */
- Ctr->NumDegs = Deg_CountNumDegsInCtr (Ctr->CtrCod);
+ /* Get number of degrees in this centre */
+ Ctr->NumDegs = Deg_GetNumDegsInCtr (Ctr->CtrCod);
+
+ /* Get number of courses in this centre */
+ Ctr->NumCrss = Crs_GetNumCrssInCtr (Ctr->CtrCod);
+
+ /* Get number of users in courses of this centre */
+ Ctr->NumUsrs = Usr_GetNumUsrsInCrssOfCtr (Rol_UNKNOWN,Ctr->CtrCod); // Here Rol_UNKNOWN means "all users", NumUsrs <= NumStds + NumTchs
+ Ctr->NumTchs = Usr_GetNumUsrsInCrssOfCtr (Rol_TEACHER,Ctr->CtrCod);
+ Ctr->NumStds = Usr_GetNumUsrsInCrssOfCtr (Rol_STUDENT,Ctr->CtrCod);
}
}
else
@@ -883,30 +936,36 @@ bool Ctr_GetDataOfCentreByCod (struct Centre *Ctr)
Ctr->ShortName[0] = '\0';
Ctr->FullName[0] = '\0';
Ctr->WWW[0] = '\0';
+ Ctr->NumUsrsWhoClaimToBelongToCtr = 0;
Ctr->NumDegs = 0;
+ Ctr->NumCrss = 0;
+ Ctr->NumUsrs = 0;
Ctr->NumTchs = 0;
+ Ctr->NumStds = 0;
/***** Check if centre code is correct *****/
if (Ctr->CtrCod > 0)
{
/***** Get data of a centre from database *****/
- sprintf (Query,"(SELECT centres.InsCod,centres.PlcCod,centres.Status,centres.RequesterUsrCod,centres.ShortName,centres.FullName,"
- "centres.WWW,COUNT(DISTINCT usr_data.UsrCod) AS NumTchs"
- " FROM centres,usr_data,crs_usr"
+ sprintf (Query,"(SELECT centres.InsCod,centres.PlcCod,"
+ "centres.Status,centres.RequesterUsrCod,"
+ "centres.ShortName,centres.FullName,centres.WWW,"
+ "COUNT(DISTINCT usr_data.UsrCod) AS NumUsrs"
+ " FROM centres,usr_data"
" WHERE centres.CtrCod='%ld'"
- " AND centres.CtrCod=usr_data.CtrCod AND usr_data.UsrCod=crs_usr.UsrCod AND crs_usr.Role='%u'"
+ " AND centres.CtrCod=usr_data.CtrCod"
" GROUP BY centres.CtrCod)"
" UNION "
- "(SELECT InsCod,PlcCod,Status,RequesterUsrCod,ShortName,FullName,WWW,0 AS NumTchs"
+ "(SELECT InsCod,PlcCod,"
+ "Status,RequesterUsrCod,"
+ "ShortName,FullName,WWW,"
+ "0 AS NumUsrs"
" FROM centres"
- " WHERE CtrCod='%ld' AND CtrCod NOT IN"
- " (SELECT DISTINCT usr_data.CtrCod FROM usr_data,crs_usr"
- " WHERE crs_usr.Role='%u'"
- " AND crs_usr.UsrCod=usr_data.UsrCod))",
+ " WHERE CtrCod='%ld'"
+ " AND CtrCod NOT IN"
+ " (SELECT DISTINCT CtrCod FROM usr_data))",
Ctr->CtrCod,
- (unsigned) Rol_TEACHER,
- Ctr->CtrCod,
- (unsigned) Rol_TEACHER);
+ Ctr->CtrCod);
if (DB_QuerySELECT (Query,&mysql_res,"can not get data of a centre")) // Centre found...
{
/* Get row */
@@ -934,12 +993,20 @@ bool Ctr_GetDataOfCentreByCod (struct Centre *Ctr)
/* Get the URL of the centre (row[6]) */
strcpy (Ctr->WWW,row[6]);
- /* Get number of teachers in this centre (row[7]) */
- if (sscanf (row[7],"%u",&Ctr->NumTchs) != 1)
- Ctr->NumTchs = 0;
+ /* Get number of users who claim to belong to this centre (row[7]) */
+ if (sscanf (row[7],"%u",&Ctr->NumUsrsWhoClaimToBelongToCtr) != 1)
+ Ctr->NumUsrsWhoClaimToBelongToCtr = 0;
- /* Count number of degrees in this centre */
- Ctr->NumDegs = Deg_CountNumDegsInCtr (Ctr->CtrCod);
+ /* Get number of degrees in this centre */
+ Ctr->NumDegs = Deg_GetNumDegsInCtr (Ctr->CtrCod);
+
+ /* Get number of courses in this centre */
+ Ctr->NumCrss = Crs_GetNumCrssInCtr (Ctr->CtrCod);
+
+ /* Get number of users in courses of this centre */
+ Ctr->NumUsrs = Usr_GetNumUsrsInCrssOfCtr (Rol_UNKNOWN,Ctr->CtrCod); // Here Rol_UNKNOWN means "all users", NumUsrs <= NumStds + NumTchs
+ Ctr->NumTchs = Usr_GetNumUsrsInCrssOfCtr (Rol_TEACHER,Ctr->CtrCod);
+ Ctr->NumStds = Usr_GetNumUsrsInCrssOfCtr (Rol_STUDENT,Ctr->CtrCod);
/* Set return value */
CtrFound = true;
@@ -1188,7 +1255,8 @@ static void Ctr_ListCentresForEdition (void)
fprintf (Gbl.F.Out,""
"");
if (Ctr->NumDegs ||
- Ctr->NumTchs || // Centre has degrees or teachers ==> deletion forbidden
+ Ctr->NumUsrsWhoClaimToBelongToCtr ||
+ Ctr->NumUsrs || // Centre has degrees or users ==> deletion forbidden
!ICanEdit)
Lay_PutIconRemovalNotAllowed ();
else
@@ -2108,10 +2176,13 @@ static void Ctr_PutFormToCreateCentre (void)
static void Ctr_PutHeadCentresForSeeing (bool OrderSelectable)
{
- extern const char *Txt_Place;
extern const char *Txt_CENTRES_HELP_ORDER[2];
extern const char *Txt_CENTRES_ORDER[2];
+ extern const char *Txt_Place;
extern const char *Txt_Degrees_ABBREVIATION;
+ extern const char *Txt_Courses_ABBREVIATION;
+ extern const char *Txt_Teachers_ABBREVIATION;
+ extern const char *Txt_Students_ABBREVIATION;
extern const char *Txt_Status;
tCtrsOrderType Order;
@@ -2121,7 +2192,9 @@ static void Ctr_PutHeadCentresForSeeing (bool OrderSelectable)
Order <= Ctr_ORDER_BY_NUM_TCHS;
Order++)
{
- fprintf (Gbl.F.Out," | ");
+ fprintf (Gbl.F.Out," | ",
+ Order == Ctr_ORDER_BY_CENTRE ? "LEFT_MIDDLE" :
+ "RIGHT_MIDDLE");
if (OrderSelectable)
{
Act_FormStart (ActSeeCtr);
@@ -2140,7 +2213,10 @@ static void Ctr_PutHeadCentresForSeeing (bool OrderSelectable)
}
fprintf (Gbl.F.Out," | ");
}
- fprintf (Gbl.F.Out,""
+ fprintf (Gbl.F.Out," | "
+ "%s"
+ " | "
+ ""
"%s"
" | "
""
@@ -2149,9 +2225,23 @@ static void Ctr_PutHeadCentresForSeeing (bool OrderSelectable)
" | "
"%s"
" | "
- "
",
- Txt_Degrees_ABBREVIATION,
+ ""
+ "%s"
+ " | "
+ ""
+ "%s+ %s"
+ " | "
+ ""
+ "%s"
+ " | "
+ "",
Txt_Place,
+ Txt_Degrees_ABBREVIATION,
+ Txt_Courses_ABBREVIATION,
+ Txt_Teachers_ABBREVIATION,
+ Txt_Students_ABBREVIATION,
+ Txt_Teachers_ABBREVIATION,
+ Txt_Students_ABBREVIATION,
Txt_Status);
}
diff --git a/swad_centre.h b/swad_centre.h
index b2ce5adeb..a3917c9a0 100644
--- a/swad_centre.h
+++ b/swad_centre.h
@@ -67,8 +67,12 @@ struct Centre
char ShortName[Ctr_MAX_LENGTH_CENTRE_SHORT_NAME+1];
char FullName[Ctr_MAX_LENGTH_CENTRE_FULL_NAME+1];
char WWW[Cns_MAX_LENGTH_WWW+1];
+ unsigned NumUsrsWhoClaimToBelongToCtr; // Number of users who claim to belong in this centre
unsigned NumDegs; // Number of degrees in this centre
- unsigned NumTchs; // Number of teachers in this centre
+ unsigned NumCrss; // Number of courses in this centre
+ unsigned NumUsrs; // Number of users in courses of this centre
+ unsigned NumTchs; // Number of teachers in courses of this centre
+ unsigned NumStds; // Number of students in courses of this centre
};
typedef enum
diff --git a/swad_changelog.h b/swad_changelog.h
index 48700ded1..07026da87 100644
--- a/swad_changelog.h
+++ b/swad_changelog.h
@@ -114,12 +114,13 @@
/****************************** Public constants *****************************/
/*****************************************************************************/
-#define Log_PLATFORM_VERSION "SWAD 15.61 (2015/12/09)"
+#define Log_PLATFORM_VERSION "SWAD 15.62 (2015/12/09)"
#define CSS_FILE "swad15.60.7.css"
// 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 15.62: Dec 09, 2015 Changes in data of centres. (186949 lines)
Version 15.61: Dec 09, 2015 Bug fixing and lot of changes in data of countries and institutions. (186852 lines)
Version 15.60.6: Dec 08, 2015 Changed icons in login. (186592 lines)
Version 15.60.5: Dec 08, 2015 Changed some messages related to login. (186589 lines)
diff --git a/swad_course.c b/swad_course.c
index f8de0bfe7..600fff549 100644
--- a/swad_course.c
+++ b/swad_course.c
@@ -824,7 +824,7 @@ unsigned Crs_GetNumCrssTotal (void)
unsigned Crs_GetNumCrssInCty (long CtyCod)
{
- char Query[512];
+ char Query[256];
/***** Get number of courses in a country from database *****/
sprintf (Query,"SELECT COUNT(*) FROM institutions,centres,degrees,courses"
@@ -842,7 +842,7 @@ unsigned Crs_GetNumCrssInCty (long CtyCod)
unsigned Crs_GetNumCrssInIns (long InsCod)
{
- char Query[512];
+ char Query[256];
/***** Get number of courses in a degree from database *****/
sprintf (Query,"SELECT COUNT(*) FROM centres,degrees,courses"
@@ -859,11 +859,12 @@ unsigned Crs_GetNumCrssInIns (long InsCod)
unsigned Crs_GetNumCrssInCtr (long CtrCod)
{
- char Query[512];
+ char Query[256];
/***** Get number of courses in a degree from database *****/
sprintf (Query,"SELECT COUNT(*) FROM degrees,courses"
- " WHERE degrees.CtrCod='%ld' AND degrees.DegCod=courses.DegCod",
+ " WHERE degrees.CtrCod='%ld'"
+ " AND degrees.DegCod=courses.DegCod",
CtrCod);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of courses in a centre");
}
@@ -874,7 +875,7 @@ unsigned Crs_GetNumCrssInCtr (long CtrCod)
unsigned Crs_GetNumCrssInDeg (long DegCod)
{
- char Query[256];
+ char Query[128];
/***** Get number of courses in a degree from database *****/
sprintf (Query,"SELECT COUNT(*) FROM courses"
diff --git a/swad_degree.c b/swad_degree.c
index 7674c4b28..29618c984 100644
--- a/swad_degree.c
+++ b/swad_degree.c
@@ -2763,20 +2763,6 @@ long Deg_GetParamOtherDegCod (void)
return Str_ConvertStrCodToLongCod (LongStr);
}
-/*****************************************************************************/
-/****************** Count number of degrees in a centre *********************/
-/*****************************************************************************/
-
-unsigned Deg_CountNumDegsInCtr (long CtrCod)
- {
- char Query[512];
-
- /***** Get number of degrees of a type from database *****/
- sprintf (Query,"SELECT COUNT(*) FROM degrees WHERE CtrCod='%ld'",
- CtrCod);
- return (unsigned) DB_QueryCOUNT (Query,"can not get number of degrees in a centre");
- }
-
/*****************************************************************************/
/**************** Count number of degrees in a degree type ******************/
/*****************************************************************************/
@@ -3819,7 +3805,6 @@ bool Deg_CheckIfYearIsValidInDeg (unsigned Year,struct Degree *Deg)
void Deg_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan)
{
- extern const char *Txt_Go_to_X;
extern const char *Txt_all_degrees;
char Query[1024];
MYSQL_RES *mysql_res;
diff --git a/swad_degree.h b/swad_degree.h
index 454301b47..e9a5b2928 100644
--- a/swad_degree.h
+++ b/swad_degree.h
@@ -132,7 +132,6 @@ void Deg_RemoveDegree (void);
void Deg_PutParamDegCod (long DegCod);
long Deg_GetParamOtherDegTypCod (void);
long Deg_GetParamOtherDegCod (void);
-unsigned Deg_CountNumDegsInCtr (long CtrCod);
bool Deg_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp);
bool Deg_GetDataOfDegreeByCod (struct Degree *Deg);
diff --git a/swad_institution.c b/swad_institution.c
index 135d7fdf5..200c83ca5 100644
--- a/swad_institution.c
+++ b/swad_institution.c
@@ -70,7 +70,6 @@ static void Ins_ListInstitutionsForSeeing (void);
static void Ins_ListOneInstitutionForSeeing (struct Institution *Ins,unsigned NumIns);
static void Ins_PutHeadInstitutionsForSeeing (bool OrderSelectable);
static void Ins_GetParamInsOrderType (void);
-static unsigned Ins_GetNumUsrsWhoClaimToBelongToIns (long InsCod);
static void Ins_ListInstitutionsForEdition (void);
static bool Ins_CheckIfICanEdit (struct Institution *Ins);
static Ins_StatusTxt_t Ins_GetStatusTxtFromStatusBits (Ins_Status_t Status);
@@ -807,16 +806,11 @@ void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData)
switch (GetExtraData)
{
case Ins_GET_BASIC_DATA:
- if (CtyCod <= 0) // Get all the institutions, belonging to any country
- sprintf (Query,"SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW"
- " FROM institutions"
- " ORDER BY FullName");
- else // Get only the institutions belonging to the country specified by CtyCod
- sprintf (Query,"SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW"
- " FROM institutions"
- " WHERE CtyCod='%ld'"
- " ORDER BY FullName",
- CtyCod);
+ sprintf (Query,"SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW"
+ " FROM institutions"
+ " WHERE CtyCod='%ld'"
+ " ORDER BY FullName",
+ CtyCod);
break;
case Ins_GET_EXTRA_DATA:
switch (Gbl.Inss.SelectedOrderType)
@@ -828,39 +822,23 @@ void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData)
sprintf (OrderBySubQuery,"NumUsrs DESC,FullName");
break;
}
- if (CtyCod <= 0) // Get all the institutions, belonging to any country
- sprintf (Query,"(SELECT institutions.InsCod,institutions.CtyCod,"
- "institutions.Status,institutions.RequesterUsrCod,"
- "institutions.ShortName,institutions.FullName,"
- "institutions.WWW,COUNT(*) AS NumUsrs"
- " FROM institutions,usr_data"
- " WHERE institutions.InsCod=usr_data.InsCod"
- " GROUP BY institutions.InsCod)"
- " UNION "
- "(SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW,0 AS NumUsrs"
- " FROM institutions"
- " WHERE InsCod NOT IN"
- " (SELECT DISTINCT InsCod FROM usr_data))"
- " ORDER BY %s",
- OrderBySubQuery);
- else // Get only the institutions belonging to the country specified by CtyCod
- sprintf (Query,"(SELECT institutions.InsCod,institutions.CtyCod,"
- "institutions.Status,institutions.RequesterUsrCod,"
- "institutions.ShortName,institutions.FullName,"
- "institutions.WWW,COUNT(*) AS NumUsrs"
- " FROM institutions,usr_data"
- " WHERE institutions.CtyCod='%ld'"
- " AND institutions.InsCod=usr_data.InsCod"
- " GROUP BY institutions.InsCod)"
- " UNION "
- "(SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW,0 AS NumUsrs"
- " FROM institutions"
- " WHERE CtyCod='%ld'"
- " AND InsCod NOT IN"
- " (SELECT DISTINCT InsCod FROM usr_data))"
- " ORDER BY %s",
- CtyCod,CtyCod,
- OrderBySubQuery);
+ sprintf (Query,"(SELECT institutions.InsCod,institutions.CtyCod,"
+ "institutions.Status,institutions.RequesterUsrCod,"
+ "institutions.ShortName,institutions.FullName,"
+ "institutions.WWW,COUNT(*) AS NumUsrs"
+ " FROM institutions,usr_data"
+ " WHERE institutions.CtyCod='%ld'"
+ " AND institutions.InsCod=usr_data.InsCod"
+ " GROUP BY institutions.InsCod)"
+ " UNION "
+ "(SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW,0 AS NumUsrs"
+ " FROM institutions"
+ " WHERE CtyCod='%ld'"
+ " AND InsCod NOT IN"
+ " (SELECT DISTINCT InsCod FROM usr_data))"
+ " ORDER BY %s",
+ CtyCod,CtyCod,
+ OrderBySubQuery);
break;
}
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get institutions");
@@ -1011,11 +989,6 @@ bool Ins_GetDataOfInstitutionByCod (struct Institution *Ins,
/* Get extra data */
if (GetExtraData == Ins_GET_EXTRA_DATA)
{
- /* Get number of users in courses of this institution */
- Ins->NumUsrs = Usr_GetNumUsrsInCrssOfIns (Rol_UNKNOWN,Ins->InsCod); // Here Rol_UNKNOWN means "all users", NumUsrs <= NumStds + NumTchs
- Ins->NumStds = Usr_GetNumUsrsInCrssOfIns (Rol_STUDENT,Ins->InsCod);
- Ins->NumTchs = Usr_GetNumUsrsInCrssOfIns (Rol_TEACHER,Ins->InsCod);
-
/* Get number of centres in this institution */
Ins->NumCtrs = Ctr_GetNumCtrsInIns (Ins->InsCod);
@@ -1024,6 +997,11 @@ bool Ins_GetDataOfInstitutionByCod (struct Institution *Ins,
/* Get number of degrees in this institution */
Ins->NumDegs = Deg_GetNumDegsInIns (Ins->InsCod);
+
+ /* Get number of users in courses of this institution */
+ Ins->NumUsrs = Usr_GetNumUsrsInCrssOfIns (Rol_UNKNOWN,Ins->InsCod); // Here Rol_UNKNOWN means "all users", NumUsrs <= NumStds + NumTchs
+ Ins->NumStds = Usr_GetNumUsrsInCrssOfIns (Rol_STUDENT,Ins->InsCod);
+ Ins->NumTchs = Usr_GetNumUsrsInCrssOfIns (Rol_TEACHER,Ins->InsCod);
}
}
else
@@ -1067,21 +1045,6 @@ void Ins_GetShortNameOfInstitutionByCod (struct Institution *Ins)
}
}
-/*****************************************************************************/
-/****************** Get number of users in an institution ********************/
-/*****************************************************************************/
-
-static unsigned Ins_GetNumUsrsWhoClaimToBelongToIns (long InsCod)
- {
- char Query[256];
-
- /***** Get number of users in an institution from database *****/
- sprintf (Query,"SELECT COUNT(*) FROM usr_data"
- " WHERE InsCod='%ld'",
- InsCod);
- return (unsigned) DB_QueryCOUNT (Query,"can not check number of users in an institution");
- }
-
/*****************************************************************************/
/************************* Free list of institutions *************************/
/*****************************************************************************/
@@ -1207,6 +1170,7 @@ static void Ins_ListInstitutionsForEdition (void)
fprintf (Gbl.F.Out,""
"");
if (Ins->NumCtrs ||
+ Ins->NumUsrsWhoClaimToBelongToIns ||
Ins->NumUsrs || // Institution has centres or users ==> deletion forbidden
!ICanEdit)
Lay_PutIconRemovalNotAllowed ();
@@ -1485,11 +1449,14 @@ void Ins_RemoveInstitution (void)
Lay_ShowErrorAndExit ("Code of institution is missing.");
/***** Get data of the institution from database *****/
- Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA);
+ Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_EXTRA_DATA);
/***** Check if this institution has users *****/
- if (Ctr_GetNumCtrsInIns (Ins.InsCod) ||
- Ins_GetNumUsrsWhoClaimToBelongToIns (Ins.InsCod)) // Institution has centres or users ==> don't remove
+ if (!Ins_CheckIfICanEdit (&Ins))
+ Lay_ShowErrorAndExit ("You don't have permission to remove institution.");
+ else if (Ins.NumCtrs ||
+ Ins.NumUsrsWhoClaimToBelongToIns ||
+ Ins.NumUsrs) // Institution has centres or users ==> don't remove
Lay_ShowAlert (Lay_WARNING,Txt_To_remove_an_institution_you_must_first_remove_all_centres_and_users_in_the_institution);
else // Institution has no users ==> remove it
{
diff --git a/swad_place.c b/swad_place.c
index b9e6fbb16..5e3a7f922 100644
--- a/swad_place.c
+++ b/swad_place.c
@@ -327,6 +327,7 @@ void Plc_GetListPlaces (void)
void Plc_GetDataOfPlaceByCod (struct Place *Plc)
{
+ extern const char *Txt_Place_unspecified;
extern const char *Txt_Another_place;
char Query[1024];
MYSQL_RES *mysql_res;
@@ -339,10 +340,19 @@ void Plc_GetDataOfPlaceByCod (struct Place *Plc)
Plc->NumCtrs = 0;
/***** Check if place code is correct *****/
- if (Plc->PlcCod == 0)
+ if (Plc->PlcCod < 0)
{
- strcpy (Plc->ShortName,Txt_Another_place);
- strcpy (Plc->FullName,Txt_Another_place);
+ strncpy (Plc->ShortName,Txt_Place_unspecified,Plc_MAX_LENGTH_PLACE_SHORT_NAME);
+ Plc->ShortName[Plc_MAX_LENGTH_PLACE_SHORT_NAME] = '\0';
+ strncpy (Plc->FullName,Txt_Place_unspecified,Plc_MAX_LENGTH_PLACE_FULL_NAME);
+ Plc->FullName[Plc_MAX_LENGTH_PLACE_FULL_NAME] = '\0';
+ }
+ else if (Plc->PlcCod == 0)
+ {
+ strncpy (Plc->ShortName,Txt_Another_place,Plc_MAX_LENGTH_PLACE_SHORT_NAME);
+ Plc->ShortName[Plc_MAX_LENGTH_PLACE_SHORT_NAME] = '\0';
+ strncpy (Plc->FullName,Txt_Another_place,Plc_MAX_LENGTH_PLACE_FULL_NAME);
+ Plc->FullName[Plc_MAX_LENGTH_PLACE_FULL_NAME] = '\0';
}
else if (Plc->PlcCod > 0)
{
@@ -371,10 +381,12 @@ void Plc_GetDataOfPlaceByCod (struct Place *Plc)
row = mysql_fetch_row (mysql_res);
/* Get the short name of the place (row[0]) */
- strcpy (Plc->ShortName,row[0]);
+ strncpy (Plc->ShortName,row[0],Plc_MAX_LENGTH_PLACE_SHORT_NAME);
+ Plc->ShortName[Plc_MAX_LENGTH_PLACE_SHORT_NAME] = '\0';
/* Get the full name of the place (row[1]) */
- strcpy (Plc->FullName,row[1]);
+ strncpy (Plc->FullName,row[1],Plc_MAX_LENGTH_PLACE_FULL_NAME);
+ Plc->FullName[Plc_MAX_LENGTH_PLACE_FULL_NAME] = '\0';
/* Get number of centres in this place (row[2]) */
if (sscanf (row[2],"%u",&Plc->NumCtrs) != 1)
diff --git a/swad_text.c b/swad_text.c
index b79e44547..efb987bdf 100644
--- a/swad_text.c
+++ b/swad_text.c
@@ -4099,23 +4099,23 @@ const char *Txt_CENTRES_ORDER[2] =
#endif
,
#if L==1
- "Prof."
+ "Usuaris del centre"
#elif L==2
- "Lehrkräfte"
+ "Benutzer der Lehrinstitut"
#elif L==3
- "Teachers"
+ "Users of the centre"
#elif L==4
- "Prof."
+ "Usuarios del centro"
#elif L==5
- "Enseign."
+ "Utilisateurs du centre"
#elif L==6
- "Prof." // Okoteve traducción
+ "Usuarios del centro" // Okoteve traducción
#elif L==7
- "Prof."
+ "Utenti del centro"
#elif L==8
- "Nauczycieli"
+ "Użytkownicy centrum"
#elif L==9
- "Prof."
+ "Utilizadores do centro"
#endif
};
@@ -47151,6 +47151,27 @@ const char *Txt_X_users_have_been_removed = // Warning: it is very important to
"%u users have been removed."; // Necessita de tradução
#endif
+const char *Txt_Users_of_the_centre =
+#if L==1
+ "Usuaris del centre";
+#elif L==2
+ "Benutzer der Lehrinstitut";
+#elif L==3
+ "Users of the centre";
+#elif L==4
+ "Usuarios del centro";
+#elif L==5
+ "Utilisateurs du centre";
+#elif L==6
+ "Usuarios del centro"; // Okoteve traducción
+#elif L==7
+ "Utenti del centro";
+#elif L==8
+ "Użytkownicy centrum";
+#elif L==9
+ "Utilizadores do centro";
+#endif
+
const char *Txt_Users_of_the_country =
#if L==1
"Usuaris del país";
diff --git a/swad_user.c b/swad_user.c
index ed41c2ba4..198b82466 100644
--- a/swad_user.c
+++ b/swad_user.c
@@ -3390,19 +3390,28 @@ unsigned Usr_GetNumUsrsInCrssOfDeg (Rol_Role_t Role,long DegCod)
/*****************************************************************************/
/************ Count how many users with a role belong to a centre ************/
/*****************************************************************************/
+// Here Rol_UNKNOWN means students or teachers
unsigned Usr_GetNumUsrsInCrssOfCtr (Rol_Role_t Role,long CtrCod)
{
char Query[512];
/***** Get the number of users in courses of a centre from database ******/
- 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'",
- CtrCod,(unsigned) Role);
+ if (Role == Rol_UNKNOWN) // 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",
+ 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'",
+ CtrCod,(unsigned) Role);
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of users in courses of a centre");
}
@@ -3415,7 +3424,7 @@ unsigned Usr_GetNumUsrsInCrssOfIns (Rol_Role_t Role,long InsCod)
{
char Query[512];
- /***** Get the number of users in a courses of an institution from database ******/
+ /***** Get the number of users in courses of an institution from database ******/
if (Role == Rol_UNKNOWN) // Any user
sprintf (Query,"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
" FROM centres,degrees,courses,crs_usr"
@@ -3578,6 +3587,22 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (long InsCod)
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of users in an institution");
}
+/*****************************************************************************/
+/*********** Get number of users who claim to belong to a centre *************/
+/*****************************************************************************/
+
+unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (long CtrCod)
+ {
+ char Query[128];
+
+ /***** Get the number of users in a centre from database *****/
+ sprintf (Query,"SELECT COUNT(DISTINCT UsrCod)"
+ " FROM usr_data"
+ " WHERE usr_data.CtrCod='%ld'",
+ CtrCod);
+ return (unsigned) DB_QueryCOUNT (Query,"can not get the number of users in a centre");
+ }
+
/*****************************************************************************/
/******************* Get number of teachers in a centre **********************/
/*****************************************************************************/
diff --git a/swad_user.h b/swad_user.h
index bcbac48bb..ef39538b1 100644
--- a/swad_user.h
+++ b/swad_user.h
@@ -283,8 +283,9 @@ long Usr_GetRamdomStdFromCrs (long CrsCod);
long Usr_GetRamdomStdFromGrp (long GrpCod);
unsigned Usr_GetNumTchsCurrentInsInDepartment (long DptCod);
-unsigned Usr_GetNumUsrsWhoClaimToBelongToCty (long InsCod);
+unsigned Usr_GetNumUsrsWhoClaimToBelongToCty (long CtyCod);
unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (long InsCod);
+unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (long CtrCod);
unsigned Usr_GetNumberOfTeachersInCentre (long CtrCod);
void Usr_GetUsrsLst (Rol_Role_t Role,Sco_Scope_t ListUsrsRange,const char *TchQuery,bool Search);
|