From 3bcbabd447110cd3aab1e5662240cb9fc5185053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Mon, 23 Nov 2015 00:44:39 +0100 Subject: [PATCH] Version 15.44 --- swad_changelog.h | 10 ++--- swad_degree.c | 111 ++++++++++++++++++++++++++++++++++------------- swad_degree.h | 2 +- swad_scope.c | 35 ++++++++++----- swad_scope.h | 2 + swad_user.c | 38 +++++++++------- 6 files changed, 136 insertions(+), 62 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 59a6be0f7..baf41a3a8 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -104,24 +104,22 @@ // TODO: When a new assignment/attendance/survey is incorrect, the second time the form is shown, it should be filled with partial data, now is always empty // TODO: Remove columns "first year, last year, optional, status" when listing degrees? // TODO: Show message indicating that mail could be in SPAM folder -// TODO: List institution and centre admins -// TODO: List of degrees administrated by a degree admin should be ordered by name /*****************************************************************************/ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.43.2 (2015/11/22)" +#define Log_PLATFORM_VERSION "SWAD 15.44 (2015/11/23)" // 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.43.2: Nov 22, 2015 Minor changes in CSS. (187719 lines) + Version 15.44: Nov 23, 2015 Changes in list of institution, centre and degree administrators. (187787 lines) Version 15.43.1: Nov 22, 2015 New figure (statistic) about first day of week. (187722 lines) 1 change necessary in database: INSERT INTO actions (ActCod,Language,Obsolete,Txt) VALUES ('1485','es','N','Cambiar primer día semana en calendario'); - Version 15.43: Nov 21, 2015 New figure (statistic) about first day of week. (187693 lines) + Version 15.43: Nov 21, 2015 Form in calendar to select first day of week. (187693 lines) Version 15.42.4: Nov 21, 2015 Fixed bug when getting first day of week from IP preferences. (187535 lines) Version 15.42.3: Nov 21, 2015 Stats of hits distributed by week depend on user's preference about first day of the week. (187528 lines) Version 15.42.2: Nov 21, 2015 Fixed bug in JavaScript code to draw months. (187524 lines) @@ -132,7 +130,7 @@ ALTER TABLE IP_prefs ADD COLUMN FirstDayOfWeek TINYINT NOT NULL DEFAULT 0 AFTER ALTER TABLE usr_data ADD COLUMN FirstDayOfWeek TINYINT NOT NULL DEFAULT 0 AFTER Language,ADD INDEX (FirstDayOfWeek); INSERT INTO actions (ActCod,Language,Obsolete,Txt) VALUES ('1484','es','N','Cambiar primer día de semana'); - Version 15.41: Nov 21, 2015 Javascript code to draw a month with sunday as the first day of a week. (187316 lines) + Version 15.41: Nov 21, 2015 JavaScript code to draw a month with sunday as the first day of a week. (187316 lines) Version 15.40.8: Nov 20, 2015 Password is requested only one time when creating a new account. (187309 lines) Version 15.40.7: Nov 20, 2015 New help button to register students in courses without them. (187319 lines) Version 15.40.6: Nov 20, 2015 New button to register students in courses without them. diff --git a/swad_degree.c b/swad_degree.c index 7e653ea3d..26d5172da 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -3895,31 +3895,51 @@ bool Deg_CheckIfYearIsValidInDeg (unsigned Year,struct Degree *Deg) } /*****************************************************************************/ -/********** Write the degrees administrated by an administrator **************/ +/***** Write institutions, centres and degrees administrated by an admin *****/ /*****************************************************************************/ -void Deg_GetAndWriteDegreesAdminBy (long UsrCod,unsigned ColSpan) +void Deg_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan) { extern const char *Txt_Go_to_X; extern const char *Txt_all_degrees; - char Query[512]; + char Query[2048]; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRow,NumRows; + unsigned NumRow; + unsigned NumRows; + struct Institution Ins; + struct Centre Ctr; struct Degree Deg; - /***** Get degrees admin by a user from database *****/ - sprintf (Query,"(SELECT -1 AS DegCod,'' AS FullName" + /***** Get institutions, centres, degrees admin by user from database *****/ + sprintf (Query,"(SELECT '%u' AS Scope,'-1' AS Cod,'' AS FullName" " FROM admin" - " WHERE UsrCod='%ld' AND Scope='Sys')" + " WHERE UsrCod='%ld'" + " AND Scope='Sys')" " UNION " - "(SELECT DegCod,degrees.FullName" + "(SELECT '%u' AS Scope,admin.Cod,institutions.FullName" + " FROM admin,institutions" + " WHERE admin.UsrCod='%ld'" + " AND admin.Scope='Ins'" + " AND admin.Cod=institutions.InsCod)" + " UNION " + "(SELECT '%u' AS Scope,admin.Cod,centres.FullName" + " FROM admin,centres" + " WHERE admin.UsrCod='%ld'" + " AND admin.Scope='Ctr'" + " AND admin.Cod=centres.CtrCod)" + " UNION " + "(SELECT '%u' AS Scope,admin.Cod,degrees.FullName" " FROM admin,degrees" - " WHERE admin.UsrCod='%ld' AND admin.Scope='Deg'" + " WHERE admin.UsrCod='%ld'" + " AND admin.Scope='Deg'" " AND admin.Cod=degrees.DegCod)" - " ORDER BY FullName", - UsrCod,UsrCod); - if ((NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get degrees admin by a user"))) // If degrees found for this administrator + " ORDER BY Scope,FullName", + (unsigned) Sco_SCOPE_SYS,UsrCod, + (unsigned) Sco_SCOPE_INS,UsrCod, + (unsigned) Sco_SCOPE_CTR,UsrCod, + (unsigned) Sco_SCOPE_DEG,UsrCod); + if ((NumRows = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get institutions, centres, degrees admin by a user"))) /***** Get the list of degrees *****/ for (NumRow = 1; NumRow <= NumRows; @@ -3936,34 +3956,67 @@ void Deg_GetAndWriteDegreesAdminBy (long UsrCod,unsigned ColSpan) NumRow == NumRows ? "subend" : "submid"); - /***** Write degree *****/ + /***** Write institution, centre, degree *****/ fprintf (Gbl.F.Out,"", ColSpan - 1,Gbl.RowEvenOdd); - /* Get next degree */ + /* Get next institution, centre, degree */ row = mysql_fetch_row (mysql_res); - Deg.DegCod = Str_ConvertStrCodToLongCod (row[0]); - if (Deg.DegCod > 0) - { - /* Get data of degree */ - Deg_GetDataOfDegreeByCod (&Deg); - - /* Write degree logo and degree short name */ - Deg_DrawDegreeLogoAndNameWithLink (&Deg,ActSeeDegInf, - "DAT_SMALL_NOBR","LEFT_TOP"); - } - else - fprintf (Gbl.F.Out,"\"%s\"" - " %s", + /* Get scope */ + switch (Sco_GetScopeFromUnsignedStr (row[0])) + { + case Sco_SCOPE_SYS: // System + fprintf (Gbl.F.Out,"\"%s\"" + " %s", Gbl.Prefs.IconsURL, Txt_all_degrees, Txt_all_degrees, Txt_all_degrees); + break; + case Sco_SCOPE_INS: // Institution + Ins.InsCod = Str_ConvertStrCodToLongCod (row[1]); + if (Ins.InsCod > 0) + { + /* Get data of institution */ + Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_MINIMAL_DATA); + /* Write institution logo and name */ + Ins_DrawInstitutionLogoAndNameWithLink (&Ins,ActSeeInsInf, + "DAT_SMALL_NOBR","LEFT_TOP"); + } + break; + case Sco_SCOPE_CTR: // Centre + Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[1]); + if (Ctr.CtrCod > 0) + { + /* Get data of centre */ + Ctr_GetDataOfCentreByCod (&Ctr); + + /* Write centre logo and name */ + Ctr_DrawCentreLogoAndNameWithLink (&Ctr,ActSeeCtrInf, + "DAT_SMALL_NOBR","LEFT_TOP"); + } + break; + case Sco_SCOPE_DEG: // Degree + Deg.DegCod = Str_ConvertStrCodToLongCod (row[1]); + if (Deg.DegCod > 0) + { + /* Get data of degree */ + Deg_GetDataOfDegreeByCod (&Deg); + + /* Write degree logo and name */ + Deg_DrawDegreeLogoAndNameWithLink (&Deg,ActSeeDegInf, + "DAT_SMALL_NOBR","LEFT_TOP"); + } + break; + default: // There are no administrators in other scopes + Lay_ShowErrorAndExit ("Wrong scope."); + break; + } fprintf (Gbl.F.Out,"" ""); } diff --git a/swad_degree.h b/swad_degree.h index aa4b6489c..0f35de98c 100644 --- a/swad_degree.h +++ b/swad_degree.h @@ -165,7 +165,7 @@ unsigned Deg_GetNumDegsWithUsrs (Rol_Role_t Role,const char *SubQuery); bool Deg_CheckIfYearIsValidInDeg (unsigned Year,struct Degree *Deg); -void Deg_GetAndWriteDegreesAdminBy (long UsrCod,unsigned ColSpan); +void Deg_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan); unsigned Deg_ListDegsFound (const char *Query); diff --git a/swad_scope.c b/swad_scope.c index b22bad474..33f53dba8 100644 --- a/swad_scope.c +++ b/swad_scope.c @@ -25,6 +25,8 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ +#include // For string functions + #include "swad_config.h" #include "swad_global.h" #include "swad_parameter.h" @@ -37,7 +39,7 @@ const char *Sco_ScopeAdminDB[Sco_NUM_SCOPES] = { NULL, // Sco_SCOPE_UNK - NULL, // Sco_SCOPE_SYS, + "Sys", // Sco_SCOPE_SYS, NULL, // Sco_SCOPE_CTY, "Ins", // Sco_SCOPE_INS, "Ctr", // Sco_SCOPE_CTR, @@ -190,30 +192,26 @@ void Sco_PutParamScope (Sco_Scope_t Scope) void Sco_GetScope (void) { char UnsignedStr[10+1]; - unsigned UnsignedNum; - - Gbl.Scope.Current = Gbl.Scope.Default; /***** Get parameter location range if exists *****/ Par_GetParToText ("Scope",UnsignedStr,10); - if (sscanf (UnsignedStr,"%u",&UnsignedNum) == 1) - if (UnsignedNum < Sco_NUM_SCOPES) - Gbl.Scope.Current = (Sco_Scope_t) UnsignedNum; + if ((Gbl.Scope.Current = Sco_GetScopeFromUnsignedStr (UnsignedStr)) == Sco_SCOPE_UNK) + Gbl.Scope.Current = Gbl.Scope.Default; /***** Avoid impossible scopes *****/ - if (Gbl.Scope.Current == Sco_SCOPE_CRS && Gbl.CurrentCrs.Crs.CrsCod <= 0) + if (Gbl.Scope.Current == Sco_SCOPE_CRS && Gbl.CurrentCrs.Crs.CrsCod <= 0) Gbl.Scope.Current = Sco_SCOPE_DEG; - if (Gbl.Scope.Current == Sco_SCOPE_DEG && Gbl.CurrentDeg.Deg.DegCod <= 0) + if (Gbl.Scope.Current == Sco_SCOPE_DEG && Gbl.CurrentDeg.Deg.DegCod <= 0) Gbl.Scope.Current = Sco_SCOPE_CTR; - if (Gbl.Scope.Current == Sco_SCOPE_CTR && Gbl.CurrentCtr.Ctr.CtrCod <= 0) + if (Gbl.Scope.Current == Sco_SCOPE_CTR && Gbl.CurrentCtr.Ctr.CtrCod <= 0) Gbl.Scope.Current = Sco_SCOPE_INS; if (Gbl.Scope.Current == Sco_SCOPE_INS && Gbl.CurrentIns.Ins.InsCod <= 0) Gbl.Scope.Current = Sco_SCOPE_CTY; - if (Gbl.Scope.Current == Sco_SCOPE_CTY && Gbl.CurrentCty.Cty.CtyCod <= 0) + if (Gbl.Scope.Current == Sco_SCOPE_CTY && Gbl.CurrentCty.Cty.CtyCod <= 0) Gbl.Scope.Current = Sco_SCOPE_SYS; /***** Avoid forbidden scopes *****/ @@ -294,3 +292,18 @@ void Sco_SetScopesForListingStudents (void) break; } } + +/*****************************************************************************/ +/*************************** Get scope from string ***************************/ +/*****************************************************************************/ + +Sco_Scope_t Sco_GetScopeFromUnsignedStr (const char *UnsignedStr) + { + unsigned UnsignedNum; + + if (sscanf (UnsignedStr,"%u",&UnsignedNum) == 1) + if (UnsignedNum < Sco_NUM_SCOPES) + return (Sco_Scope_t) UnsignedNum; + + return Sco_SCOPE_UNK; + } diff --git a/swad_scope.h b/swad_scope.h index c14a2bd52..fc0bb66d1 100644 --- a/swad_scope.h +++ b/swad_scope.h @@ -60,4 +60,6 @@ void Sco_GetScope (void); void Sco_SetScopesForListingGuests (void); void Sco_SetScopesForListingStudents (void); +Sco_Scope_t Sco_GetScopeFromUnsignedStr (const char *UnsignedStr); + #endif diff --git a/swad_user.c b/swad_user.c index 74b5c833d..074de0fc7 100644 --- a/swad_user.c +++ b/swad_user.c @@ -3285,7 +3285,7 @@ void Usr_WriteRowAdmData (unsigned NumUsr,struct UsrData *UsrDat) fprintf (Gbl.F.Out,""); /***** Write degrees which are administrated by this administrator *****/ - Deg_GetAndWriteDegreesAdminBy (UsrDat->UsrCod, + Deg_GetAndWriteInsCtrDegAdminBy (UsrDat->UsrCod, Gbl.Usrs.Listing.WithPhotos ? Usr_NUM_MAIN_FIELDS_DATA_ADM : Usr_NUM_MAIN_FIELDS_DATA_ADM-1); @@ -4153,24 +4153,35 @@ static void Usr_GetAdmsLst (Sco_Scope_t Scope) case Sco_SCOPE_SYS: strcpy (Query,"SELECT DISTINCT admin.UsrCod,'Y',usr_data.Sex" " FROM admin,usr_data" - " WHERE (admin.Scope='Deg'" - " OR admin.Scope='Sys')" - " AND admin.UsrCod=usr_data.UsrCod " + " WHERE admin.UsrCod=usr_data.UsrCod" " ORDER BY " "usr_data.Surname1," "usr_data.Surname2," "usr_data.FirstName," "usr_data.UsrCod"); break; + case Sco_SCOPE_CTY: + sprintf (Query,"SELECT DISTINCT admin.UsrCod,'Y',usr_data.Sex" + " FROM institutions,centres,degrees,admin,usr_data" + " WHERE institutions.CtyCod='%ld'" + " AND institutions.InsCod=centres.InsCod" + " AND centres.CtrCod=degrees.CtrCod" + " AND degrees.DegCod=admin.Cod" + " AND admin.UsrCod=usr_data.UsrCod" + " ORDER BY " + "usr_data.Surname1," + "usr_data.Surname2," + "usr_data.FirstName," + "usr_data.UsrCod", + Gbl.CurrentCty.Cty.CtyCod); + break; case Sco_SCOPE_INS: sprintf (Query,"SELECT DISTINCT admin.UsrCod,'Y',usr_data.Sex" " FROM centres,degrees,admin,usr_data" - " WHERE ((centres.InsCod='%ld'" + " WHERE centres.InsCod='%ld'" " AND centres.CtrCod=degrees.CtrCod" " AND degrees.DegCod=admin.Cod" - " AND admin.Scope='Deg')" - " OR admin.Scope='Sys')" - " AND admin.UsrCod=usr_data.UsrCod " + " AND admin.UsrCod=usr_data.UsrCod" " ORDER BY " "usr_data.Surname1," "usr_data.Surname2," @@ -4181,11 +4192,9 @@ static void Usr_GetAdmsLst (Sco_Scope_t Scope) case Sco_SCOPE_CTR: sprintf (Query,"SELECT DISTINCT admin.UsrCod,'Y',usr_data.Sex" " FROM degrees,admin,usr_data" - " WHERE ((degrees.CtrCod='%ld'" + " WHERE degrees.CtrCod='%ld'" " AND degrees.DegCod=admin.Cod" - " AND admin.Scope='Deg')" - " OR admin.Scope='Sys')" - " AND admin.UsrCod=usr_data.UsrCod " + " AND admin.UsrCod=usr_data.UsrCod" " ORDER BY " "usr_data.Surname1," "usr_data.Surname2," @@ -4196,9 +4205,8 @@ static void Usr_GetAdmsLst (Sco_Scope_t Scope) case Sco_SCOPE_DEG: sprintf (Query,"SELECT DISTINCT admin.UsrCod,'Y',usr_data.Sex" " FROM admin,usr_data" - " WHERE ((admin.Scope='Deg' AND admin.Cod='%ld')" - " OR admin.Scope='Sys')" - " AND admin.UsrCod=usr_data.UsrCod " + " WHERE admin.Cod='%ld'" + " AND admin.UsrCod=usr_data.UsrCod" " ORDER BY " "usr_data.Surname1," "usr_data.Surname2,"