diff --git a/sql/cambios.sql b/sql/cambios.sql index 15e70acfa..971caf3b3 100644 --- a/sql/cambios.sql +++ b/sql/cambios.sql @@ -11679,7 +11679,7 @@ UPDATE surveys SET Cod=CrsCod WHERE Scope='Crs'; DROP INDEX DegCod ON surveys; ALTER TABLE surveys ADD PRIMARY KEY(SvyCod); DROP INDEX SvyCod ON surveys; -ALTER TABLE surveys ADD UNIQUE INDEX(SvyCod,Scope,Cod,Hidden),ADD INDEX(Scope,Cod,Hidden); +ALTER TABLE surveys ADD UNIQUE INDEX(Scope,Cod); ----- TODO: Eliminar columnas sin uso en futuras versiones ----- diff --git a/sql/swad.sql b/sql/swad.sql index 902d35b8b..18b7af1e8 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -989,8 +989,8 @@ CREATE TABLE IF NOT EXISTS sta_notif ( -- CREATE TABLE IF NOT EXISTS surveys ( SvyCod INT NOT NULL AUTO_INCREMENT, - DegCod INT NOT NULL DEFAULT -1, - CrsCod INT NOT NULL DEFAULT -1, + Scope ENUM('Sys','Cty','Ins','Ctr','Deg','Crs') NOT NULL DEFAULT 'Sys', + Cod INT NOT NULL DEFAULT -1, Hidden ENUM('N','Y') NOT NULL DEFAULT 'N', NumNotif INT NOT NULL DEFAULT 0, Roles INT NOT NULL DEFAULT 0, @@ -1000,7 +1000,7 @@ CREATE TABLE IF NOT EXISTS surveys ( Title VARCHAR(255) NOT NULL, Txt TEXT NOT NULL, UNIQUE INDEX(SvyCod), - INDEX(DegCod,CrsCod,Hidden)); + INDEX(Scope,Cod)); -- -- Table svy_answers: stores the answers to the surveys -- diff --git a/swad_changelog.h b/swad_changelog.h index 6a54be6cd..753152529 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -154,15 +154,16 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.45 (2016-10-27)" +#define Log_PLATFORM_VERSION "SWAD 16.45.1 (2016-10-27)" #define CSS_FILE "swad16.32.1.css" #define JS_FILE "swad15.238.1.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.45.1: Oct 27, 2016 Fixed bugs in surveys. (? lines) Version 16.45: Oct 27, 2016 Changes in database table for surveys. Not finished. (205927 lines) - 12 changes necessary in database: + 10 changes necessary in database: ALTER TABLE surveys ADD COLUMN Scope ENUM('Sys','Cty','Ins','Ctr','Deg','Crs') NOT NULL DEFAULT 'Sys' AFTER SvyCod; ALTER TABLE surveys ADD COLUMN Cod INT NOT NULL DEFAULT -1 AFTER Scope; @@ -175,9 +176,7 @@ UPDATE surveys SET Cod=DegCod WHERE Scope='Deg'; UPDATE surveys SET Cod=CrsCod WHERE Scope='Crs'; DROP INDEX DegCod ON surveys; -ALTER TABLE surveys ADD PRIMARY KEY(SvyCod); -DROP INDEX SvyCod ON surveys; -ALTER TABLE surveys ADD UNIQUE INDEX(SvyCod,Scope,Cod,Hidden),ADD INDEX(Scope,Cod,Hidden); +ALTER TABLE surveys ADD INDEX(Scope,Cod); Version 16.44: Oct 27, 2016 New scopes (centre, institution, country) of surveys. Not finished. (205826 lines) Version 16.43: Oct 26, 2016 Fixed bugs and code refactoring in scope of surveys. (205537 lines) diff --git a/swad_database.c b/swad_database.c index dd16a0c4a..517d84826 100644 --- a/swad_database.c +++ b/swad_database.c @@ -2109,8 +2109,6 @@ mysql> DESCRIBE surveys; "SvyCod INT NOT NULL AUTO_INCREMENT," "Scope ENUM('Sys','Cty','Ins','Ctr','Deg','Crs') NOT NULL DEFAULT 'Sys'," "Cod INT NOT NULL DEFAULT -1," - "DegCod INT NOT NULL DEFAULT -1," // TODO: DROP COLUMN - "CrsCod INT NOT NULL DEFAULT -1," // TODO: DROP COLUMN "Hidden ENUM('N','Y') NOT NULL DEFAULT 'N'," "NumNotif INT NOT NULL DEFAULT 0," "Roles INT NOT NULL DEFAULT 0," @@ -2119,9 +2117,8 @@ mysql> DESCRIBE surveys; "EndTime DATETIME NOT NULL," "Title VARCHAR(255) NOT NULL," "Txt TEXT NOT NULL," - "PRIMARY KEY(SvyCod)," - "UNIQUE INDEX(SvyCod,Scope,Cod,Hidden)," - "INDEX(Scope,Cod,Hidden))"); + "UNIQUE INDEX(SvyCod)," + "INDEX(Scope,Cod)"); /***** Table svy_answers *****/ /* diff --git a/swad_survey.c b/swad_survey.c index 4eec1351d..f485463f3 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -843,6 +843,7 @@ static void Svy_PutParams (void) void Svy_GetListSurveys (void) { + extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; char SubQuery[Sco_NUM_SCOPES][128]; char OrderBySubQuery[256]; char Query[2048]; @@ -872,14 +873,14 @@ void Svy_GetListSurveys (void) Cods[Sco_SCOPE_CRS] = Gbl.CurrentCrs.Crs.CrsCod; // Course for (Scope = Sco_SCOPE_SYS, SubQueryFilled = false; - Scope < Sco_SCOPE_CRS; + Scope <= Sco_SCOPE_CRS; Scope++) if (ScopesAllowed & 1 << Scope) { - sprintf (SubQuery[Scope],"%s(Scope='%u' AND Cod='%ld'%s)", + sprintf (SubQuery[Scope],"%s(Scope='%s' AND Cod='%ld'%s)", SubQueryFilled ? " OR " : "", - (unsigned) Scope,Cods[Scope], + Sco_ScopeDB[Scope],Cods[Scope], (ScopesAllowed & 1 << Sco_SCOPE_SYS) ? "" : " AND Hidden='N'"); SubQueryFilled = true;