From 5db755900ce5ca2d7a977e570d88be4d9c05f24d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Thu, 27 Oct 2016 15:06:11 +0200 Subject: [PATCH] Version 16.45 --- sql/cambios.sql | 20 ++++ swad_assignment.c | 12 +-- swad_attendance.c | 10 +- swad_changelog.h | 23 ++++- swad_database.c | 45 +++++---- swad_enrollment.c | 8 +- swad_notification.c | 14 ++- swad_scope.c | 35 +++++-- swad_scope.h | 1 + swad_statistic.c | 6 +- swad_survey.c | 230 ++++++++++++++++++++++++++++---------------- swad_survey.h | 6 +- swad_test.c | 40 ++++---- swad_user.c | 6 +- 14 files changed, 293 insertions(+), 163 deletions(-) diff --git a/sql/cambios.sql b/sql/cambios.sql index 77bdde991..15e70acfa 100644 --- a/sql/cambios.sql +++ b/sql/cambios.sql @@ -11663,6 +11663,26 @@ SELECT CrsCod,COUNT(*) AS N FROM crs_usr LEFT JOIN log_full ON (crs_usr.CrsCod=l (SELECT DISTINCT crs_grp_usr.UsrCod FROM svy_grp,crs_grp_usr,surveys,crs_usr WHERE svy_grp.SvyCod='6' AND svy_grp.GrpCod=crs_grp_usr.GrpCod AND crs_grp_usr.UsrCod=crs_usr.UsrCod AND crs_grp_usr.UsrCod<>'1' AND svy_grp.SvyCod=surveys.SvyCod AND surveys.CrsCod=crs_usr.CrsCod AND (surveys.Roles&(1<0); +----- swad-core 16.45 (2016/10/27) ----- + +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; + +UPDATE surveys SET Scope='Sys' WHERE DegCod<='0' AND CrsCod<='0'; +UPDATE surveys SET Scope='Deg' WHERE DegCod>'0' AND CrsCod<='0'; +UPDATE surveys SET Scope='Crs' WHERE CrsCod>'0'; + +UPDATE surveys SET Cod='-1' WHERE Scope='Sys'; +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); +----- TODO: Eliminar columnas sin uso en futuras versiones ----- +ALTER TABLE surveys DROP COLUMN DegCod; +ALTER TABLE surveys DROP COLUMN CrsCod; diff --git a/swad_assignment.c b/swad_assignment.c index 5615473b4..2e075c873 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -1663,12 +1663,12 @@ unsigned Asg_GetNumCoursesWithAssignments (Sco_Scope_t Scope) switch (Scope) { case Sco_SCOPE_SYS: - sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)" " FROM assignments" " WHERE CrsCod>'0'"); break; case Sco_SCOPE_CTY: - sprintf (Query,"SELECT COUNT(DISTINCT (assignments.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT assignments.CrsCod)" " FROM institutions,centres,degrees,courses,assignments" " WHERE institutions.CtyCod='%ld'" " AND institutions.InsCod=centres.InsCod" @@ -1679,7 +1679,7 @@ unsigned Asg_GetNumCoursesWithAssignments (Sco_Scope_t Scope) Gbl.CurrentCty.Cty.CtyCod); break; case Sco_SCOPE_INS: - sprintf (Query,"SELECT COUNT(DISTINCT (assignments.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT assignments.CrsCod)" " FROM centres,degrees,courses,assignments" " WHERE centres.InsCod='%ld'" " AND centres.CtrCod=degrees.CtrCod" @@ -1689,7 +1689,7 @@ unsigned Asg_GetNumCoursesWithAssignments (Sco_Scope_t Scope) Gbl.CurrentIns.Ins.InsCod); break; case Sco_SCOPE_CTR: - sprintf (Query,"SELECT COUNT(DISTINCT (assignments.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT assignments.CrsCod)" " FROM degrees,courses,assignments" " WHERE degrees.CtrCod='%ld'" " AND degrees.DegCod=courses.DegCod" @@ -1698,7 +1698,7 @@ unsigned Asg_GetNumCoursesWithAssignments (Sco_Scope_t Scope) Gbl.CurrentCtr.Ctr.CtrCod); break; case Sco_SCOPE_DEG: - sprintf (Query,"SELECT COUNT(DISTINCT (assignments.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT assignments.CrsCod)" " FROM courses,assignments" " WHERE courses.DegCod='%ld'" " AND courses.Status=0" @@ -1706,7 +1706,7 @@ unsigned Asg_GetNumCoursesWithAssignments (Sco_Scope_t Scope) Gbl.CurrentDeg.Deg.DegCod); break; case Sco_SCOPE_CRS: - sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)" " FROM assignments" " WHERE CrsCod='%ld'", Gbl.CurrentCrs.Crs.CrsCod); diff --git a/swad_attendance.c b/swad_attendance.c index 86a0f6cf3..918c4dba1 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -1672,12 +1672,12 @@ unsigned Att_GetNumCoursesWithAttEvents (Sco_Scope_t Scope) switch (Scope) { case Sco_SCOPE_SYS: - sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)" " FROM att_events" " WHERE CrsCod>'0'"); break; case Sco_SCOPE_INS: - sprintf (Query,"SELECT COUNT(DISTINCT (att_events.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT att_events.CrsCod)" " FROM centres,degrees,courses,att_events" " WHERE centres.InsCod='%ld'" " AND centres.CtrCod=degrees.CtrCod" @@ -1687,7 +1687,7 @@ unsigned Att_GetNumCoursesWithAttEvents (Sco_Scope_t Scope) Gbl.CurrentIns.Ins.InsCod); break; case Sco_SCOPE_CTR: - sprintf (Query,"SELECT COUNT(DISTINCT (att_events.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT att_events.CrsCod)" " FROM degrees,courses,att_events" " WHERE degrees.CtrCod='%ld'" " AND degrees.DegCod=courses.DegCod" @@ -1696,7 +1696,7 @@ unsigned Att_GetNumCoursesWithAttEvents (Sco_Scope_t Scope) Gbl.CurrentCtr.Ctr.CtrCod); break; case Sco_SCOPE_DEG: - sprintf (Query,"SELECT COUNT(DISTINCT (att_events.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT att_events.CrsCod)" " FROM courses,att_events" " WHERE courses.DegCod='%ld'" " AND courses.Status=0" @@ -1704,7 +1704,7 @@ unsigned Att_GetNumCoursesWithAttEvents (Sco_Scope_t Scope) Gbl.CurrentDeg.Deg.DegCod); break; case Sco_SCOPE_CRS: - sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)" " FROM att_events" " WHERE CrsCod='%ld'", Gbl.CurrentCrs.Crs.CrsCod); diff --git a/swad_changelog.h b/swad_changelog.h index 296502b34..6a54be6cd 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -146,18 +146,39 @@ // TODO: When requesting inscription, I can not click in the photo of my record. Change the form? // TODO: Cuando se crea una cuenta nueva, debería ponerse a 0 las estadísticas del perfil del usuario +// TODO: Import ID, e-mail, Surname1, Surname2, Name from CSV, suggested by Javier Melero + +// TODO: Delete surveys of centre, institution or country on deletion of centre, institution or country /*****************************************************************************/ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.44 (2016-10-27)" +#define Log_PLATFORM_VERSION "SWAD 16.45 (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: Oct 27, 2016 Changes in database table for surveys. Not finished. (205927 lines) + 12 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; + +UPDATE surveys SET Scope='Sys' WHERE DegCod<='0' AND CrsCod<='0'; +UPDATE surveys SET Scope='Deg' WHERE DegCod>'0' AND CrsCod<='0'; +UPDATE surveys SET Scope='Crs' WHERE CrsCod>'0'; + +UPDATE surveys SET Cod='-1' WHERE Scope='Sys'; +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); + 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) Version 16.42.1: Oct 25, 2016 Added button "New question" in survey when the survey has no questions. diff --git a/swad_database.c b/swad_database.c index baa135cb0..dd16a0c4a 100644 --- a/swad_database.c +++ b/swad_database.c @@ -2086,27 +2086,31 @@ mysql> DESCRIBE sta_notif; /***** Table surveys *****/ /* mysql> DESCRIBE surveys; -+-----------+---------------+------+-----+---------+----------------+ -| Field | Type | Null | Key | Default | Extra | -+-----------+---------------+------+-----+---------+----------------+ -| SvyCod | int(11) | NO | PRI | NULL | auto_increment | -| DegCod | int(11) | NO | MUL | -1 | | -| CrsCod | int(11) | NO | | -1 | | -| Hidden | enum('N','Y') | NO | | N | | -| NumNotif | int(11) | NO | | 0 | | -| Roles | int(11) | NO | | 0 | | -| UsrCod | int(11) | NO | | NULL | | -| StartTime | datetime | NO | | NULL | | -| EndTime | datetime | NO | | NULL | | -| Title | varchar(255) | NO | | NULL | | -| Txt | text | NO | | NULL | | -+-----------+---------------+------+-----+---------+----------------+ -11 rows in set (0.00 sec) ++-----------+-------------------------------------------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++-----------+-------------------------------------------+------+-----+---------+----------------+ +| SvyCod | int(11) | NO | PRI | NULL | auto_increment | +| Scope | enum('Sys','Cty','Ins','Ctr','Deg','Crs') | NO | MUL | Sys | | +| Cod | int(11) | NO | | -1 | | +| DegCod | int(11) | NO | | -1 | | +| CrsCod | int(11) | NO | | -1 | | +| Hidden | enum('N','Y') | NO | | N | | +| NumNotif | int(11) | NO | | 0 | | +| Roles | int(11) | NO | | 0 | | +| UsrCod | int(11) | NO | | NULL | | +| StartTime | datetime | NO | | NULL | | +| EndTime | datetime | NO | | NULL | | +| Title | varchar(255) | NO | | NULL | | +| Txt | text | NO | | NULL | | ++-----------+-------------------------------------------+------+-----+---------+----------------+ +13 rows in set (0,00 sec) */ DB_CreateTable ("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," + "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," @@ -2115,8 +2119,9 @@ mysql> DESCRIBE surveys; "EndTime DATETIME NOT NULL," "Title VARCHAR(255) NOT NULL," "Txt TEXT NOT NULL," - "UNIQUE INDEX(SvyCod)," - "INDEX(DegCod,CrsCod,Hidden))"); + "PRIMARY KEY(SvyCod)," + "UNIQUE INDEX(SvyCod,Scope,Cod,Hidden)," + "INDEX(Scope,Cod,Hidden))"); /***** Table svy_answers *****/ /* diff --git a/swad_enrollment.c b/swad_enrollment.c index b378a4de3..0e108d924 100644 --- a/swad_enrollment.c +++ b/swad_enrollment.c @@ -3181,7 +3181,7 @@ static void Enr_AddAdm (Sco_Scope_t Scope,long Cod,const char *InsCtrDegName) static void Enr_RegisterAdmin (struct UsrData *UsrDat,Sco_Scope_t Scope,long Cod,const char *InsCtrDegName) { - extern const char *Sco_ScopeAdminDB[Sco_NUM_SCOPES]; + extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; extern const char *Txt_THE_USER_X_is_already_an_administrator_of_Y; extern const char *Txt_THE_USER_X_has_been_enrolled_as_administrator_of_Y; char Query[512]; @@ -3195,7 +3195,7 @@ static void Enr_RegisterAdmin (struct UsrData *UsrDat,Sco_Scope_t Scope,long Cod /***** Insert or replace administrator in current institution/centre/degree *****/ sprintf (Query,"REPLACE INTO admin (UsrCod,Scope,Cod)" " VALUES ('%ld','%s','%ld')", - UsrDat->UsrCod,Sco_ScopeAdminDB[Scope],Cod); + UsrDat->UsrCod,Sco_ScopeDB[Scope],Cod); DB_QueryREPLACE (Query,"can not create administrator"); sprintf (Gbl.Message,Txt_THE_USER_X_has_been_enrolled_as_administrator_of_Y, @@ -3820,7 +3820,7 @@ static void Enr_AskIfRemAdm (bool ItsMe,Sco_Scope_t Scope,const char *InsCtrDegN static void Enr_EffectivelyRemAdm (struct UsrData *UsrDat,Sco_Scope_t Scope, long Cod,const char *InsCtrDegName) { - extern const char *Sco_ScopeAdminDB[Sco_NUM_SCOPES]; + extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; extern const char *Txt_THE_USER_X_has_been_removed_as_administrator_of_Y; extern const char *Txt_THE_USER_X_is_not_an_administrator_of_Y; char Query[1024]; @@ -3830,7 +3830,7 @@ static void Enr_EffectivelyRemAdm (struct UsrData *UsrDat,Sco_Scope_t Scope, /***** Remove user from the table of admins *****/ sprintf (Query,"DELETE FROM admin" " WHERE UsrCod='%ld' AND Scope='%s' AND Cod='%ld'", - UsrDat->UsrCod,Sco_ScopeAdminDB[Scope],Cod); + UsrDat->UsrCod,Sco_ScopeDB[Scope],Cod); DB_QueryDELETE (Query,"can not remove an administrator"); sprintf (Gbl.Message,Txt_THE_USER_X_has_been_removed_as_administrator_of_Y, diff --git a/swad_notification.c b/swad_notification.c index 99a8bbf22..499e512e0 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -1155,6 +1155,7 @@ void Ntf_MarkNotifFilesInGroupAsRemoved (long GrpCod) unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) { + extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; char Query[1024]; MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -1327,7 +1328,7 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) " WHERE surveys.SvyCod='%ld'" " AND surveys.SvyCod NOT IN" " (SELECT SvyCod FROM svy_grp WHERE SvyCod='%ld')" - " AND surveys.CrsCod=crs_usr.CrsCod" + " AND surveys.Scope='%s' AND surveys.Cod=crs_usr.CrsCod" " AND crs_usr.UsrCod<>'%ld'" " AND (surveys.Roles&(1<0)" " UNION " @@ -1338,10 +1339,15 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) " AND crs_grp_usr.UsrCod=crs_usr.UsrCod" " AND crs_grp_usr.UsrCod<>'%ld'" " AND svy_grp.SvyCod=surveys.SvyCod" - " AND surveys.CrsCod=crs_usr.CrsCod" + " AND surveys.Scope='%s' AND surveys.Cod=crs_usr.CrsCod" " AND (surveys.Roles&(1<0)", - Cod,Cod,Gbl.Usrs.Me.UsrDat.UsrCod, - Cod,Gbl.Usrs.Me.UsrDat.UsrCod); + Cod, + Cod, + Sco_ScopeDB[Sco_SCOPE_CRS], + Gbl.Usrs.Me.UsrDat.UsrCod, + Cod, + Gbl.Usrs.Me.UsrDat.UsrCod, + Sco_ScopeDB[Sco_SCOPE_CRS]); break; } diff --git a/swad_scope.c b/swad_scope.c index 6c3e998bd..78b7b2456 100644 --- a/swad_scope.c +++ b/swad_scope.c @@ -36,15 +36,15 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -const char *Sco_ScopeAdminDB[Sco_NUM_SCOPES] = +const char *Sco_ScopeDB[Sco_NUM_SCOPES] = { - NULL, // Sco_SCOPE_UNK - "Sys", // Sco_SCOPE_SYS, - NULL, // Sco_SCOPE_CTY, - "Ins", // Sco_SCOPE_INS, - "Ctr", // Sco_SCOPE_CTR, - "Deg", // Sco_SCOPE_DEG, - NULL, // Sco_SCOPE_CRS, + "Unk", // Sco_SCOPE_UNK + "Sys", // Sco_SCOPE_SYS + "Cty", // Sco_SCOPE_CTY + "Ins", // Sco_SCOPE_INS + "Ctr", // Sco_SCOPE_CTR + "Deg", // Sco_SCOPE_DEG + "Crs", // Sco_SCOPE_CRS }; /*****************************************************************************/ @@ -294,7 +294,7 @@ void Sco_SetScopesForListingStudents (void) } /*****************************************************************************/ -/*************************** Get scope from string ***************************/ +/*********************** Get scope from unsigned string **********************/ /*****************************************************************************/ Sco_Scope_t Sco_GetScopeFromUnsignedStr (const char *UnsignedStr) @@ -307,3 +307,20 @@ Sco_Scope_t Sco_GetScopeFromUnsignedStr (const char *UnsignedStr) return Sco_SCOPE_UNK; } + +/*****************************************************************************/ +/*********************** Get scope from database string **********************/ +/*****************************************************************************/ + +Sco_Scope_t Sco_GetScopeFromDBStr (const char *ScopeDBStr) + { + Sco_Scope_t Scope; + + for (Scope = Sco_SCOPE_UNK; + Scope < Sco_NUM_SCOPES; + Scope++) + if (!strcmp (Sco_ScopeDB[Scope],ScopeDBStr)) + return Scope; + + return Sco_SCOPE_UNK; + } diff --git a/swad_scope.h b/swad_scope.h index e073bf2d4..1ca451f1c 100644 --- a/swad_scope.h +++ b/swad_scope.h @@ -61,5 +61,6 @@ void Sco_SetScopesForListingGuests (void); void Sco_SetScopesForListingStudents (void); Sco_Scope_t Sco_GetScopeFromUnsignedStr (const char *UnsignedStr); +Sco_Scope_t Sco_GetScopeFromDBStr (const char *ScopeDBStr); #endif diff --git a/swad_statistic.c b/swad_statistic.c index dedd0767f..0f51b659b 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -8127,11 +8127,11 @@ static void Sta_GetAndShowSurveysStats (void) /***** Get the number of surveys and the average number of questions per survey from this location (all the platform, current degree or current course) *****/ - if ((NumSurveys = Svy_GetNumSurveys (Gbl.Scope.Current,&NumNotif))) + if ((NumSurveys = Svy_GetNumCrsSurveys (Gbl.Scope.Current,&NumNotif))) { - if ((NumCoursesWithSurveys = Svy_GetNumCoursesWithSurveys (Gbl.Scope.Current)) != 0) + if ((NumCoursesWithSurveys = Svy_GetNumCoursesWithCrsSurveys (Gbl.Scope.Current)) != 0) NumSurveysPerCourse = (float) NumSurveys / (float) NumCoursesWithSurveys; - NumQstsPerSurvey = Svy_GetNumQstsPerSurvey (Gbl.Scope.Current); + NumQstsPerSurvey = Svy_GetNumQstsPerCrsSurvey (Gbl.Scope.Current); } /***** Table start *****/ diff --git a/swad_survey.c b/swad_survey.c index f68f44396..4eec1351d 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -1,4 +1,4 @@ -// swad_survey2.c: surveys +// swad_survey.c: surveys /* SWAD (Shared Workspace At a Distance), @@ -899,8 +899,7 @@ void Svy_GetListSurveys (void) break; } - sprintf (Query,"SELECT SvyCod" - " FROM surveys" + sprintf (Query,"SELECT SvyCod FROM surveys" " WHERE %s%s%s%s%s%s" " ORDER BY %s", SubQuery[Sco_SCOPE_SYS], @@ -1143,7 +1142,7 @@ void Svy_GetDataOfSurveyByCod (struct Survey *Svy) Svy->SvyCod = Str_ConvertStrCodToLongCod (row[0]); /* Get survey scope (row[1]) */ - if ((Svy->Scope = Sco_GetScopeFromUnsignedStr (row[1])) == Sco_SCOPE_UNK) + if ((Svy->Scope = Sco_GetScopeFromDBStr (row[1])) == Sco_SCOPE_UNK) Lay_ShowErrorAndExit ("Wrong survey scope."); /* Get code of the country, institution, centre, degree or course (row[2]) */ @@ -1689,12 +1688,15 @@ void Svy_UnhideSurvey (void) static bool Svy_CheckIfSimilarSurveyExists (struct Survey *Svy) { + extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; char Query[512]; /***** Get number of surveys with a field value from database *****/ sprintf (Query,"SELECT COUNT(*) FROM surveys" - " WHERE Scope='%u' AND Cod='%ld' AND Title='%s' AND SvyCod<>'%ld'", - (unsigned) Svy->Scope,Svy->Cod,Svy->Title,Svy->SvyCod); + " WHERE Scope='%s' AND Cod='%ld'" + " AND Title='%s' AND SvyCod<>'%ld'", + Sco_ScopeDB[Svy->Scope],Svy->Cod, + Svy->Title,Svy->SvyCod); return (DB_QueryCOUNT (Query,"can not get similar surveys") != 0); } @@ -2163,16 +2165,17 @@ static void Svy_UpdateNumUsrsNotifiedByEMailAboutSurvey (long SvyCod, static void Svy_CreateSurvey (struct Survey *Svy,const char *Txt) { + extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; extern const char *Txt_Created_new_survey_X; char Query[1024+Cns_MAX_BYTES_TEXT]; /***** Create a new survey *****/ sprintf (Query,"INSERT INTO surveys" " (Scope,Cod,Hidden,Roles,UsrCod,StartTime,EndTime,Title,Txt)" - " VALUES ('%u','%ld','N','%u','%ld'," + " VALUES ('%s','%ld','N','%u','%ld'," "FROM_UNIXTIME('%ld'),FROM_UNIXTIME('%ld')," "'%s','%s')", - (unsigned) Svy->Scope, + Sco_ScopeDB[Svy->Scope], Svy->Cod, Svy->Roles, Gbl.Usrs.Me.UsrDat.UsrCod, @@ -2198,17 +2201,18 @@ static void Svy_CreateSurvey (struct Survey *Svy,const char *Txt) static void Svy_UpdateSurvey (struct Survey *Svy,const char *Txt) { + extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; extern const char *Txt_The_survey_has_been_modified; char Query[1024+Cns_MAX_BYTES_TEXT]; /***** Update the data of the survey *****/ sprintf (Query,"UPDATE surveys" - " SET Scope='%u',Cod='%ld',Roles='%u'," + " SET Scope='%s',Cod='%ld',Roles='%u'," "StartTime=FROM_UNIXTIME('%ld')," "EndTime=FROM_UNIXTIME('%ld')," "Title='%s',Txt='%s'" " WHERE SvyCod='%ld'", - (unsigned) Svy->Scope,Svy->Cod, + Sco_ScopeDB[Svy->Scope],Svy->Cod, Svy->Roles, Svy->TimeUTC[Svy_START_TIME], Svy->TimeUTC[Svy_END_TIME ], @@ -2279,8 +2283,11 @@ void Svy_RemoveGroup (long GrpCod) char Query[256]; /***** Remove group from all the surveys *****/ - sprintf (Query,"DELETE FROM svy_grp WHERE GrpCod='%ld'",GrpCod); - DB_QueryDELETE (Query,"can not remove group from the associations between surveys and groups"); + sprintf (Query,"DELETE FROM svy_grp" + " WHERE GrpCod='%ld'", + GrpCod); + DB_QueryDELETE (Query,"can not remove group" + " from the associations between surveys and groups"); } /*****************************************************************************/ @@ -2293,9 +2300,11 @@ void Svy_RemoveGroupsOfType (long GrpTypCod) /***** Remove group from all the surveys *****/ sprintf (Query,"DELETE FROM svy_grp USING crs_grp,svy_grp" - " WHERE crs_grp.GrpTypCod='%ld' AND crs_grp.GrpCod=svy_grp.GrpCod", + " WHERE crs_grp.GrpTypCod='%ld'" + " AND crs_grp.GrpCod=svy_grp.GrpCod", GrpTypCod); - DB_QueryDELETE (Query,"can not remove groups of a type from the associations between surveys and groups"); + DB_QueryDELETE (Query,"can not remove groups of a type" + " from the associations between surveys and groups"); } /*****************************************************************************/ @@ -2392,38 +2401,43 @@ static void Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (struct Survey *Svy) void Svy_RemoveDegSurveys (long DegCod) { + extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; char Query[512]; /***** Remove all the users in degree surveys (not including surveys of courses in degree) *****/ - sprintf (Query,"DELETE FROM svy_users USING surveys,svy_users" - " WHERE surveys.DegCod='%ld' AND surveys.CrsCod='-1'" + sprintf (Query,"DELETE FROM svy_users" + " USING surveys,svy_users" + " WHERE surveys.Scope='%s' AND surveys.Cod='%ld'" " AND surveys.SvyCod=svy_users.SvyCod", - DegCod); - DB_QueryDELETE (Query,"can not remove users who are answered surveys in a degree"); + Sco_ScopeDB[Sco_SCOPE_DEG],DegCod); + DB_QueryDELETE (Query,"can not remove users" + " who had answered surveys in a degree"); /***** Remove all the answers in degree surveys (not including surveys of courses in degree) *****/ - sprintf (Query,"DELETE FROM svy_answers USING surveys,svy_questions,svy_answers" - " WHERE surveys.DegCod='%ld' AND surveys.CrsCod='-1'" + sprintf (Query,"DELETE FROM svy_answers" + " USING surveys,svy_questions,svy_answers" + " WHERE surveys.Scope='%s' AND surveys.Cod='%ld'" " AND surveys.SvyCod=svy_questions.SvyCod" " AND svy_questions.QstCod=svy_answers.QstCod", - DegCod); + Sco_ScopeDB[Sco_SCOPE_DEG],DegCod); DB_QueryDELETE (Query,"can not remove answers of surveys in a degree"); /***** Remove all the questions in this survey (not including surveys of courses in degree) *****/ - sprintf (Query,"DELETE FROM svy_questions USING surveys,svy_questions" - " WHERE surveys.DegCod='%ld' AND surveys.CrsCod='-1'" + sprintf (Query,"DELETE FROM svy_questions" + " USING surveys,svy_questions" + " WHERE surveys.Scope='%s' AND surveys.Cod='%ld'" " AND surveys.SvyCod=svy_questions.SvyCod", - DegCod); + Sco_ScopeDB[Sco_SCOPE_DEG],DegCod); DB_QueryDELETE (Query,"can not remove questions of surveys in a degree"); /***** Remove degree surveys (not including surveys of courses in degree) *****/ sprintf (Query,"DELETE FROM surveys" - " WHERE surveys.DegCod='%ld' AND surveys.CrsCod='-1'", - DegCod); + " WHERE Scope='%s' AND Cod='%ld'", + Sco_ScopeDB[Sco_SCOPE_DEG],DegCod); DB_QueryDELETE (Query,"can not remove all the surveys of a course"); } @@ -2433,38 +2447,48 @@ void Svy_RemoveDegSurveys (long DegCod) void Svy_RemoveCrsSurveys (long CrsCod) { + extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; char Query[512]; /***** Remove all the users in course surveys *****/ - sprintf (Query,"DELETE FROM svy_users USING surveys,svy_users" - " WHERE surveys.CrsCod='%ld'" + sprintf (Query,"DELETE FROM svy_users" + " USING surveys,svy_users" + " WHERE surveys.Scope='%s' AND surveys.Cod='%ld'" " AND surveys.SvyCod=svy_users.SvyCod", - CrsCod); - DB_QueryDELETE (Query,"can not remove users who are answered surveys in a course"); + Sco_ScopeDB[Sco_SCOPE_CRS],CrsCod); + DB_QueryDELETE (Query,"can not remove users" + " who had answered surveys in a course"); /***** Remove all the answers in course surveys *****/ - sprintf (Query,"DELETE FROM svy_answers USING surveys,svy_questions,svy_answers" - " WHERE surveys.CrsCod='%ld'" + sprintf (Query,"DELETE FROM svy_answers" + " USING surveys,svy_questions,svy_answers" + " WHERE surveys.Scope='%s' AND surveys.Cod='%ld'" " AND surveys.SvyCod=svy_questions.SvyCod" " AND svy_questions.QstCod=svy_answers.QstCod", - CrsCod); + Sco_ScopeDB[Sco_SCOPE_CRS],CrsCod); DB_QueryDELETE (Query,"can not remove answers of surveys in a course"); /***** Remove all the questions in course surveys *****/ - sprintf (Query,"DELETE FROM svy_questions USING surveys,svy_questions" - " WHERE surveys.CrsCod='%ld'" + sprintf (Query,"DELETE FROM svy_questions" + " USING surveys,svy_questions" + " WHERE surveys.Scope='%s' AND surveys.Cod='%ld'" " AND surveys.SvyCod=svy_questions.SvyCod", - CrsCod); + Sco_ScopeDB[Sco_SCOPE_CRS],CrsCod); DB_QueryDELETE (Query,"can not remove questions of surveys in a course"); /***** Remove groups *****/ - sprintf (Query,"DELETE FROM svy_grp USING surveys,svy_grp" - " WHERE surveys.CrsCod='%ld' AND surveys.SvyCod=svy_grp.SvyCod", - CrsCod); - DB_QueryDELETE (Query,"can not remove all the groups associated to surveys of a course"); + sprintf (Query,"DELETE FROM svy_grp" + " USING surveys,svy_grp" + " WHERE surveys.Scope='%s' AND surveys.Cod='%ld'" + " AND surveys.SvyCod=svy_grp.SvyCod", + Sco_ScopeDB[Sco_SCOPE_CRS],CrsCod); + DB_QueryDELETE (Query,"can not remove all the groups" + " associated to surveys of a course"); /***** Remove course surveys *****/ - sprintf (Query,"DELETE FROM surveys WHERE CrsCod='%ld'",CrsCod); + sprintf (Query,"DELETE FROM surveys" + " WHERE Scope='%s' AND Cod='%ld'", + Sco_ScopeDB[Sco_SCOPE_CRS],CrsCod); DB_QueryDELETE (Query,"can not remove all the surveys of a course"); } @@ -2481,7 +2505,8 @@ static bool Svy_CheckIfICanDoThisSurveyBasedOnGrps (long SvyCod) " WHERE SvyCod='%ld'" " AND (SvyCod NOT IN (SELECT SvyCod FROM svy_grp) OR" " SvyCod IN (SELECT svy_grp.SvyCod FROM svy_grp,crs_grp_usr" - " WHERE crs_grp_usr.UsrCod='%ld' AND svy_grp.GrpCod=crs_grp_usr.GrpCod))", + " WHERE crs_grp_usr.UsrCod='%ld'" + " AND svy_grp.GrpCod=crs_grp_usr.GrpCod))", SvyCod,Gbl.Usrs.Me.UsrDat.UsrCod); return (DB_QueryCOUNT (Query,"can not check if I can do a survey") != 0); } @@ -3712,8 +3737,9 @@ static unsigned Svy_GetNumUsrsWhoHaveAnsweredSvy (long SvyCod) // Returns the number of courses with surveys for courses // in this location (all the platform, current degree or current course) -unsigned Svy_GetNumCoursesWithSurveys (Sco_Scope_t Scope) +unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope) { + extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; char Query[1024]; MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -3723,48 +3749,58 @@ unsigned Svy_GetNumCoursesWithSurveys (Sco_Scope_t Scope) switch (Scope) { case Sco_SCOPE_SYS: - sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT Cod)" " FROM surveys" - " WHERE CrsCod>'0'"); + " WHERE Scope='%s'", + Sco_ScopeDB[Sco_SCOPE_CRS]); break; case Sco_SCOPE_CTY: - sprintf (Query,"SELECT COUNT(DISTINCT (surveys.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT surveys.Cod)" " FROM institutions,centres,degrees,courses,surveys" " WHERE institutions.CtyCod='%ld'" " AND institutions.InsCod=centres.InsCod" " AND centres.CtrCod=degrees.CtrCod" " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=surveys.CrsCod", - Gbl.CurrentIns.Ins.InsCod); + " AND courses.CrsCod=surveys.Cod" + " AND surveys.Scope='%s'", + Gbl.CurrentIns.Ins.InsCod, + Sco_ScopeDB[Sco_SCOPE_CRS]); break; case Sco_SCOPE_INS: - sprintf (Query,"SELECT COUNT(DISTINCT (surveys.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT surveys.Cod)" " FROM centres,degrees,courses,surveys" " WHERE centres.InsCod='%ld'" " AND centres.CtrCod=degrees.CtrCod" " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=surveys.CrsCod", - Gbl.CurrentIns.Ins.InsCod); + " AND courses.CrsCod=surveys.Cod" + " AND surveys.Scope='%s'", + Gbl.CurrentIns.Ins.InsCod, + Sco_ScopeDB[Sco_SCOPE_CRS]); break; case Sco_SCOPE_CTR: - sprintf (Query,"SELECT COUNT(DISTINCT (surveys.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT surveys.Cod)" " FROM degrees,courses,surveys" " WHERE degrees.CtrCod='%ld'" " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=surveys.CrsCod", - Gbl.CurrentCtr.Ctr.CtrCod); + " AND courses.CrsCod=surveys.Cod" + " AND surveys.Scope='%s'", + Gbl.CurrentCtr.Ctr.CtrCod, + Sco_ScopeDB[Sco_SCOPE_CRS]); break; case Sco_SCOPE_DEG: - sprintf (Query,"SELECT COUNT(DISTINCT (surveys.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT surveys.Cod)" " FROM courses,surveys" " WHERE courses.DegCod='%ld'" - " AND courses.CrsCod=surveys.CrsCod", - Gbl.CurrentDeg.Deg.DegCod); + " AND courses.CrsCod=surveys.Cod" + " AND surveys.Scope='%s'", + Gbl.CurrentDeg.Deg.DegCod, + Sco_ScopeDB[Sco_SCOPE_CRS]); break; case Sco_SCOPE_CRS: - sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT Cod)" " FROM surveys" - " WHERE CrsCod='%ld'", + " WHERE Scope='%s' AND Cod='%ld'", + Sco_ScopeDB[Sco_SCOPE_CRS], Gbl.CurrentCrs.Crs.CrsCod); break; default: @@ -3785,13 +3821,14 @@ unsigned Svy_GetNumCoursesWithSurveys (Sco_Scope_t Scope) } /*****************************************************************************/ -/*************************** Get number of surveys ***************************/ +/******************** Get number of surveys for courses **********************/ /*****************************************************************************/ // Returns the number of surveys for courses // in this location (all the platform, current degree or current course) -unsigned Svy_GetNumSurveys (Sco_Scope_t Scope,unsigned *NumNotif) +unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif) { + extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; char Query[1024]; MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -3803,7 +3840,8 @@ unsigned Svy_GetNumSurveys (Sco_Scope_t Scope,unsigned *NumNotif) case Sco_SCOPE_SYS: sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)" " FROM surveys" - " WHERE CrsCod>'0'"); + " WHERE Scope='%s'", + Sco_ScopeDB[Sco_SCOPE_CRS]); break; case Sco_SCOPE_CTY: sprintf (Query,"SELECT COUNT(*),SUM(surveys.NumNotif)" @@ -3812,8 +3850,10 @@ unsigned Svy_GetNumSurveys (Sco_Scope_t Scope,unsigned *NumNotif) " AND institutions.InsCod=centres.InsCod" " AND centres.CtrCod=degrees.CtrCod" " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=surveys.CrsCod", - Gbl.CurrentCty.Cty.CtyCod); + " AND courses.CrsCod=surveys.Cod" + " AND surveys.Scope='%s'", + Gbl.CurrentCty.Cty.CtyCod, + Sco_ScopeDB[Sco_SCOPE_CRS]); break; case Sco_SCOPE_INS: sprintf (Query,"SELECT COUNT(*),SUM(surveys.NumNotif)" @@ -3821,28 +3861,36 @@ unsigned Svy_GetNumSurveys (Sco_Scope_t Scope,unsigned *NumNotif) " WHERE centres.InsCod='%ld'" " AND centres.CtrCod=degrees.CtrCod" " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=surveys.CrsCod", - Gbl.CurrentIns.Ins.InsCod); + " AND courses.CrsCod=surveys.Cod" + " AND surveys.Scope='%s'", + Gbl.CurrentIns.Ins.InsCod, + Sco_ScopeDB[Sco_SCOPE_CRS]); break; case Sco_SCOPE_CTR: sprintf (Query,"SELECT COUNT(*),SUM(surveys.NumNotif)" " FROM degrees,courses,surveys" " WHERE degrees.CtrCod='%ld'" " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=surveys.CrsCod", - Gbl.CurrentCtr.Ctr.CtrCod); + " AND courses.CrsCod=surveys.Cod" + " AND surveys.Scope='%s'", + Gbl.CurrentCtr.Ctr.CtrCod, + Sco_ScopeDB[Sco_SCOPE_CRS]); break; case Sco_SCOPE_DEG: sprintf (Query,"SELECT COUNT(*),SUM(surveys.NumNotif)" " FROM courses,surveys" " WHERE courses.DegCod='%ld'" - " AND courses.CrsCod=surveys.CrsCod", - Gbl.CurrentDeg.Deg.DegCod); + " AND courses.CrsCod=surveys.Cod" + " AND surveys.Scope='%s'", + Gbl.CurrentDeg.Deg.DegCod, + Sco_ScopeDB[Sco_SCOPE_CRS]); break; case Sco_SCOPE_CRS: sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)" " FROM surveys" - " WHERE CrsCod='%ld'", + " WHERE surveys.Scope='%s'" + " AND CrsCod='%ld'", + Sco_ScopeDB[Sco_SCOPE_CRS], Gbl.CurrentCrs.Crs.CrsCod); break; default: @@ -3872,26 +3920,28 @@ unsigned Svy_GetNumSurveys (Sco_Scope_t Scope,unsigned *NumNotif) } /*****************************************************************************/ -/*************** Get average number of questions per survey ******************/ +/************ Get average number of questions per course survey **************/ /*****************************************************************************/ -float Svy_GetNumQstsPerSurvey (Sco_Scope_t Scope) +float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope) { + extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; char Query[1024]; MYSQL_RES *mysql_res; MYSQL_ROW row; float NumQstsPerSurvey; - /***** Get number of courses per user from database *****/ + /***** Get number of questions per survey from database *****/ switch (Scope) { case Sco_SCOPE_SYS: sprintf (Query,"SELECT AVG(NumQsts) FROM" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " FROM surveys,svy_questions" - " WHERE surveys.CrsCod>'0'" + " WHERE surveys.Scope='%s'" " AND surveys.SvyCod=svy_questions.SvyCod" - " GROUP BY svy_questions.SvyCod) AS NumQstsTable"); + " GROUP BY svy_questions.SvyCod) AS NumQstsTable", + Sco_ScopeDB[Sco_SCOPE_CRS]); break; case Sco_SCOPE_CTY: sprintf (Query,"SELECT AVG(NumQsts) FROM" @@ -3901,10 +3951,12 @@ float Svy_GetNumQstsPerSurvey (Sco_Scope_t Scope) " AND institutions.InsCod=centres.InsCod" " AND centres.CtrCod=degrees.CtrCod" " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=surveys.CrsCod" + " AND courses.CrsCod=surveys.Cod" + " AND surveys.Scope='%s'" " AND surveys.SvyCod=svy_questions.SvyCod" " GROUP BY svy_questions.SvyCod) AS NumQstsTable", - Gbl.CurrentCty.Cty.CtyCod); + Gbl.CurrentCty.Cty.CtyCod, + Sco_ScopeDB[Sco_SCOPE_CRS]); break; case Sco_SCOPE_INS: sprintf (Query,"SELECT AVG(NumQsts) FROM" @@ -3913,10 +3965,12 @@ float Svy_GetNumQstsPerSurvey (Sco_Scope_t Scope) " WHERE centres.InsCod='%ld'" " AND centres.CtrCod=degrees.CtrCod" " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=surveys.CrsCod" + " AND courses.CrsCod=surveys.Cod" + " AND surveys.Scope='%s'" " AND surveys.SvyCod=svy_questions.SvyCod" " GROUP BY svy_questions.SvyCod) AS NumQstsTable", - Gbl.CurrentIns.Ins.InsCod); + Gbl.CurrentIns.Ins.InsCod, + Sco_ScopeDB[Sco_SCOPE_CRS]); break; case Sco_SCOPE_CTR: sprintf (Query,"SELECT AVG(NumQsts) FROM" @@ -3924,28 +3978,34 @@ float Svy_GetNumQstsPerSurvey (Sco_Scope_t Scope) " FROM degrees,courses,surveys,svy_questions" " WHERE degrees.CtrCod='%ld'" " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=surveys.CrsCod" + " AND courses.CrsCod=surveys.Cod" + " AND surveys.Scope='%s'" " AND surveys.SvyCod=svy_questions.SvyCod" " GROUP BY svy_questions.SvyCod) AS NumQstsTable", - Gbl.CurrentCtr.Ctr.CtrCod); + Gbl.CurrentCtr.Ctr.CtrCod, + Sco_ScopeDB[Sco_SCOPE_CRS]); break; case Sco_SCOPE_DEG: sprintf (Query,"SELECT AVG(NumQsts) FROM" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " FROM courses,surveys,svy_questions" " WHERE courses.DegCod='%ld'" - " AND courses.CrsCod=surveys.CrsCod" + " AND courses.CrsCod=surveys.Cod" + " AND surveys.Scope='%s'" " AND surveys.SvyCod=svy_questions.SvyCod" " GROUP BY svy_questions.SvyCod) AS NumQstsTable", - Gbl.CurrentDeg.Deg.DegCod); + Gbl.CurrentDeg.Deg.DegCod, + Sco_ScopeDB[Sco_SCOPE_CRS]); break; case Sco_SCOPE_CRS: sprintf (Query,"SELECT AVG(NumQsts) FROM" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " FROM surveys,svy_questions" - " WHERE surveys.CrsCod='%ld'" + " WHERE surveys.Scope='%s'" + " AND surveys.CrsCod='%ld'" " AND surveys.SvyCod=svy_questions.SvyCod" " GROUP BY svy_questions.SvyCod) AS NumQstsTable", + Sco_ScopeDB[Sco_SCOPE_CRS], Gbl.CurrentCrs.Crs.CrsCod); break; default: diff --git a/swad_survey.h b/swad_survey.h index 37e6082d5..cf6d369fd 100644 --- a/swad_survey.h +++ b/swad_survey.h @@ -109,8 +109,8 @@ void Svy_RemoveQst (void); void Svy_ReceiveSurveyAnswers (void); -unsigned Svy_GetNumCoursesWithSurveys (Sco_Scope_t Scope); -unsigned Svy_GetNumSurveys (Sco_Scope_t Scope,unsigned *NumNotif); -float Svy_GetNumQstsPerSurvey (Sco_Scope_t Scope); +unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope); +unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif); +float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope); #endif diff --git a/swad_test.c b/swad_test.c index 968b18830..4621d8ab8 100644 --- a/swad_test.c +++ b/swad_test.c @@ -6526,17 +6526,17 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Sco_Scope_t Scope,Tst_AnswerT { case Sco_SCOPE_SYS: if (AnsType == Tst_ANS_ALL) - sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)" " FROM tst_questions"); else - sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)" " FROM tst_questions" " WHERE AnsType='%s'", Tst_StrAnswerTypesDB[AnsType]); break; case Sco_SCOPE_CTY: if (AnsType == Tst_ANS_ALL) - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)" " FROM institutions,centres,degrees,courses,tst_questions" " WHERE institutions.CtyCod='%ld'" " AND institutions.InsCod=centres.InsCod" @@ -6545,7 +6545,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Sco_Scope_t Scope,Tst_AnswerT " AND courses.CrsCod=tst_questions.CrsCod", Gbl.CurrentCty.Cty.CtyCod); else - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)" " FROM institutions,centres,degrees,courses,tst_questions" " WHERE institutions.CtyCod='%ld'" " AND institutions.InsCod=centres.InsCod" @@ -6558,7 +6558,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Sco_Scope_t Scope,Tst_AnswerT break; case Sco_SCOPE_INS: if (AnsType == Tst_ANS_ALL) - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)" " FROM centres,degrees,courses,tst_questions" " WHERE centres.InsCod='%ld'" " AND centres.CtrCod=degrees.CtrCod" @@ -6566,7 +6566,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Sco_Scope_t Scope,Tst_AnswerT " AND courses.CrsCod=tst_questions.CrsCod", Gbl.CurrentIns.Ins.InsCod); else - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)" " FROM centres,degrees,courses,tst_questions" " WHERE centres.InsCod='%ld'" " AND centres.CtrCod=degrees.CtrCod" @@ -6578,14 +6578,14 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Sco_Scope_t Scope,Tst_AnswerT break; case Sco_SCOPE_CTR: if (AnsType == Tst_ANS_ALL) - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)" " FROM degrees,courses,tst_questions" " WHERE degrees.CtrCod='%ld'" " AND degrees.DegCod=courses.DegCod" " AND courses.CrsCod=tst_questions.CrsCod", Gbl.CurrentCtr.Ctr.CtrCod); else - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)" " FROM degrees,courses,tst_questions" " WHERE degrees.CtrCod='%ld'" " AND degrees.DegCod=courses.DegCod" @@ -6596,13 +6596,13 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Sco_Scope_t Scope,Tst_AnswerT break; case Sco_SCOPE_DEG: if (AnsType == Tst_ANS_ALL) - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNTDISTINCT (tst_questions.CrsCod)" " FROM courses,tst_questions" " WHERE courses.DegCod='%ld'" " AND courses.CrsCod=tst_questions.CrsCod", Gbl.CurrentDeg.Deg.DegCod); else - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)" " FROM courses,tst_questions" " WHERE courses.DegCod='%ld'" " AND courses.CrsCod=tst_questions.CrsCod" @@ -6612,12 +6612,12 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Sco_Scope_t Scope,Tst_AnswerT break; case Sco_SCOPE_CRS: if (AnsType == Tst_ANS_ALL) - sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)" " FROM tst_questions" " WHERE CrsCod='%ld'", Gbl.CurrentCrs.Crs.CrsCod); else - sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)" " FROM tst_questions" " WHERE CrsCod='%ld'" " AND AnsType='%s'", @@ -6675,7 +6675,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts break; case Sco_SCOPE_CTY: if (AnsType == Tst_ANS_ALL) - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)" " FROM institutions,centres,degrees,courses,tst_questions,tst_config" " WHERE institutions.CtyCod='%ld'" " AND institutions.InsCod=centres.InsCod" @@ -6687,7 +6687,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts Gbl.CurrentCty.Cty.CtyCod, Tst_PluggableDB[Tst_PLUGGABLE_YES]); else - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)" " FROM institutions,centres,degrees,courses,tst_questions,tst_config" " WHERE institutions.CtyCod='%ld'" " AND institutions.InsCod=centres.InsCod" @@ -6703,7 +6703,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts break; case Sco_SCOPE_INS: if (AnsType == Tst_ANS_ALL) - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)" " FROM centres,degrees,courses,tst_questions,tst_config" " WHERE centres.InsCod='%ld'" " AND centres.CtrCod=degrees.CtrCod" @@ -6714,7 +6714,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts Gbl.CurrentIns.Ins.InsCod, Tst_PluggableDB[Tst_PLUGGABLE_YES]); else - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)" " FROM centres,degrees,courses,tst_questions,tst_config" " WHERE centres.InsCod='%ld'" " AND centres.CtrCod=degrees.CtrCod" @@ -6729,7 +6729,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts break; case Sco_SCOPE_CTR: if (AnsType == Tst_ANS_ALL) - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)" " FROM degrees,courses,tst_questions,tst_config" " WHERE degrees.CtrCod='%ld'" " AND degrees.DegCod=courses.DegCod" @@ -6739,7 +6739,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts Gbl.CurrentCtr.Ctr.CtrCod, Tst_PluggableDB[Tst_PLUGGABLE_YES]); else - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)" " FROM degrees,courses,tst_questions,tst_config" " WHERE degrees.CtrCod='%ld'" " AND degrees.DegCod=courses.DegCod" @@ -6753,7 +6753,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts break; case Sco_SCOPE_DEG: if (AnsType == Tst_ANS_ALL) - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)" " FROM courses,tst_questions,tst_config" " WHERE courses.DegCod='%ld'" " AND courses.CrsCod=tst_questions.CrsCod" @@ -6762,7 +6762,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts Gbl.CurrentDeg.Deg.DegCod, Tst_PluggableDB[Tst_PLUGGABLE_YES]); else - sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" + sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)" " FROM courses,tst_questions,tst_config" " WHERE courses.DegCod='%ld'" " AND courses.CrsCod=tst_questions.CrsCod" diff --git a/swad_user.c b/swad_user.c index 7679031d4..055a93eea 100644 --- a/swad_user.c +++ b/swad_user.c @@ -753,15 +753,15 @@ void Usr_RestrictLengthAndWriteName (const struct UsrData *UsrDat,unsigned MaxCh bool Usr_CheckIfUsrIsAdm (long UsrCod,Sco_Scope_t Scope,long Cod) { - extern const char *Sco_ScopeAdminDB[Sco_NUM_SCOPES]; + extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; char Query[128]; - if (Sco_ScopeAdminDB[Scope]) + if (Sco_ScopeDB[Scope]) { /***** Get if a user is administrator of a degree from database *****/ sprintf (Query,"SELECT COUNT(*) FROM admin" " WHERE UsrCod='%ld' AND Scope='%s' AND Cod='%ld'", - UsrCod,Sco_ScopeAdminDB[Scope],Cod); + UsrCod,Sco_ScopeDB[Scope],Cod); return (DB_QueryCOUNT (Query,"can not check if a user is administrator") != 0); } return false;