Version 16.45

This commit is contained in:
Antonio Cañas Vargas 2016-10-27 15:06:11 +02:00
parent 638703d9e8
commit 5db755900c
14 changed files with 293 additions and 163 deletions

View File

@ -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<<crs_usr.Role))<>0); (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<<crs_usr.Role))<>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;

View File

@ -1663,12 +1663,12 @@ unsigned Asg_GetNumCoursesWithAssignments (Sco_Scope_t Scope)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)"
" FROM assignments" " FROM assignments"
" WHERE CrsCod>'0'"); " WHERE CrsCod>'0'");
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
sprintf (Query,"SELECT COUNT(DISTINCT (assignments.CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT assignments.CrsCod)"
" FROM institutions,centres,degrees,courses,assignments" " FROM institutions,centres,degrees,courses,assignments"
" WHERE institutions.CtyCod='%ld'" " WHERE institutions.CtyCod='%ld'"
" AND institutions.InsCod=centres.InsCod" " AND institutions.InsCod=centres.InsCod"
@ -1679,7 +1679,7 @@ unsigned Asg_GetNumCoursesWithAssignments (Sco_Scope_t Scope)
Gbl.CurrentCty.Cty.CtyCod); Gbl.CurrentCty.Cty.CtyCod);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
sprintf (Query,"SELECT COUNT(DISTINCT (assignments.CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT assignments.CrsCod)"
" FROM centres,degrees,courses,assignments" " FROM centres,degrees,courses,assignments"
" WHERE centres.InsCod='%ld'" " WHERE centres.InsCod='%ld'"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
@ -1689,7 +1689,7 @@ unsigned Asg_GetNumCoursesWithAssignments (Sco_Scope_t Scope)
Gbl.CurrentIns.Ins.InsCod); Gbl.CurrentIns.Ins.InsCod);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
sprintf (Query,"SELECT COUNT(DISTINCT (assignments.CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT assignments.CrsCod)"
" FROM degrees,courses,assignments" " FROM degrees,courses,assignments"
" WHERE degrees.CtrCod='%ld'" " WHERE degrees.CtrCod='%ld'"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
@ -1698,7 +1698,7 @@ unsigned Asg_GetNumCoursesWithAssignments (Sco_Scope_t Scope)
Gbl.CurrentCtr.Ctr.CtrCod); Gbl.CurrentCtr.Ctr.CtrCod);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
sprintf (Query,"SELECT COUNT(DISTINCT (assignments.CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT assignments.CrsCod)"
" FROM courses,assignments" " FROM courses,assignments"
" WHERE courses.DegCod='%ld'" " WHERE courses.DegCod='%ld'"
" AND courses.Status=0" " AND courses.Status=0"
@ -1706,7 +1706,7 @@ unsigned Asg_GetNumCoursesWithAssignments (Sco_Scope_t Scope)
Gbl.CurrentDeg.Deg.DegCod); Gbl.CurrentDeg.Deg.DegCod);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)"
" FROM assignments" " FROM assignments"
" WHERE CrsCod='%ld'", " WHERE CrsCod='%ld'",
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);

View File

@ -1672,12 +1672,12 @@ unsigned Att_GetNumCoursesWithAttEvents (Sco_Scope_t Scope)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)"
" FROM att_events" " FROM att_events"
" WHERE CrsCod>'0'"); " WHERE CrsCod>'0'");
break; break;
case Sco_SCOPE_INS: 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" " FROM centres,degrees,courses,att_events"
" WHERE centres.InsCod='%ld'" " WHERE centres.InsCod='%ld'"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
@ -1687,7 +1687,7 @@ unsigned Att_GetNumCoursesWithAttEvents (Sco_Scope_t Scope)
Gbl.CurrentIns.Ins.InsCod); Gbl.CurrentIns.Ins.InsCod);
break; break;
case Sco_SCOPE_CTR: 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" " FROM degrees,courses,att_events"
" WHERE degrees.CtrCod='%ld'" " WHERE degrees.CtrCod='%ld'"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
@ -1696,7 +1696,7 @@ unsigned Att_GetNumCoursesWithAttEvents (Sco_Scope_t Scope)
Gbl.CurrentCtr.Ctr.CtrCod); Gbl.CurrentCtr.Ctr.CtrCod);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
sprintf (Query,"SELECT COUNT(DISTINCT (att_events.CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT att_events.CrsCod)"
" FROM courses,att_events" " FROM courses,att_events"
" WHERE courses.DegCod='%ld'" " WHERE courses.DegCod='%ld'"
" AND courses.Status=0" " AND courses.Status=0"
@ -1704,7 +1704,7 @@ unsigned Att_GetNumCoursesWithAttEvents (Sco_Scope_t Scope)
Gbl.CurrentDeg.Deg.DegCod); Gbl.CurrentDeg.Deg.DegCod);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)"
" FROM att_events" " FROM att_events"
" WHERE CrsCod='%ld'", " WHERE CrsCod='%ld'",
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);

View File

@ -146,18 +146,39 @@
// TODO: When requesting inscription, I can not click in the photo of my record. Change the form? // 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: 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 *****************************/ /****************************** 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 CSS_FILE "swad16.32.1.css"
#define JS_FILE "swad15.238.1.js" #define JS_FILE "swad15.238.1.js"
// Number of lines (includes comments but not blank lines) has been got with the following command: // Number of lines (includes comments but not blank lines) has been got with the following command:
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1 // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1
/* /*
Version 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.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.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. Version 16.42.1: Oct 25, 2016 Added button "New question" in survey when the survey has no questions.

View File

@ -2086,27 +2086,31 @@ mysql> DESCRIBE sta_notif;
/***** Table surveys *****/ /***** Table surveys *****/
/* /*
mysql> DESCRIBE surveys; mysql> DESCRIBE surveys;
+-----------+---------------+------+-----+---------+----------------+ +-----------+-------------------------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra | | Field | Type | Null | Key | Default | Extra |
+-----------+---------------+------+-----+---------+----------------+ +-----------+-------------------------------------------+------+-----+---------+----------------+
| SvyCod | int(11) | NO | PRI | NULL | auto_increment | | SvyCod | int(11) | NO | PRI | NULL | auto_increment |
| DegCod | int(11) | NO | MUL | -1 | | | Scope | enum('Sys','Cty','Ins','Ctr','Deg','Crs') | NO | MUL | Sys | |
| CrsCod | int(11) | NO | | -1 | | | Cod | int(11) | NO | | -1 | |
| Hidden | enum('N','Y') | NO | | N | | | DegCod | int(11) | NO | | -1 | |
| NumNotif | int(11) | NO | | 0 | | | CrsCod | int(11) | NO | | -1 | |
| Roles | int(11) | NO | | 0 | | | Hidden | enum('N','Y') | NO | | N | |
| UsrCod | int(11) | NO | | NULL | | | NumNotif | int(11) | NO | | 0 | |
| StartTime | datetime | NO | | NULL | | | Roles | int(11) | NO | | 0 | |
| EndTime | datetime | NO | | NULL | | | UsrCod | int(11) | NO | | NULL | |
| Title | varchar(255) | NO | | NULL | | | StartTime | datetime | NO | | NULL | |
| Txt | text | NO | | NULL | | | EndTime | datetime | NO | | NULL | |
+-----------+---------------+------+-----+---------+----------------+ | Title | varchar(255) | NO | | NULL | |
11 rows in set (0.00 sec) | Txt | text | NO | | NULL | |
+-----------+-------------------------------------------+------+-----+---------+----------------+
13 rows in set (0,00 sec)
*/ */
DB_CreateTable ("CREATE TABLE IF NOT EXISTS surveys (" DB_CreateTable ("CREATE TABLE IF NOT EXISTS surveys ("
"SvyCod INT NOT NULL AUTO_INCREMENT," "SvyCod INT NOT NULL AUTO_INCREMENT,"
"DegCod INT NOT NULL DEFAULT -1," "Scope ENUM('Sys','Cty','Ins','Ctr','Deg','Crs') NOT NULL DEFAULT 'Sys',"
"CrsCod INT NOT NULL DEFAULT -1," "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'," "Hidden ENUM('N','Y') NOT NULL DEFAULT 'N',"
"NumNotif INT NOT NULL DEFAULT 0," "NumNotif INT NOT NULL DEFAULT 0,"
"Roles INT NOT NULL DEFAULT 0," "Roles INT NOT NULL DEFAULT 0,"
@ -2115,8 +2119,9 @@ mysql> DESCRIBE surveys;
"EndTime DATETIME NOT NULL," "EndTime DATETIME NOT NULL,"
"Title VARCHAR(255) NOT NULL," "Title VARCHAR(255) NOT NULL,"
"Txt TEXT NOT NULL," "Txt TEXT NOT NULL,"
"UNIQUE INDEX(SvyCod)," "PRIMARY KEY(SvyCod),"
"INDEX(DegCod,CrsCod,Hidden))"); "UNIQUE INDEX(SvyCod,Scope,Cod,Hidden),"
"INDEX(Scope,Cod,Hidden))");
/***** Table svy_answers *****/ /***** Table svy_answers *****/
/* /*

View File

@ -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) 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_is_already_an_administrator_of_Y;
extern const char *Txt_THE_USER_X_has_been_enrolled_as_administrator_of_Y; extern const char *Txt_THE_USER_X_has_been_enrolled_as_administrator_of_Y;
char Query[512]; 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 *****/ /***** Insert or replace administrator in current institution/centre/degree *****/
sprintf (Query,"REPLACE INTO admin (UsrCod,Scope,Cod)" sprintf (Query,"REPLACE INTO admin (UsrCod,Scope,Cod)"
" VALUES ('%ld','%s','%ld')", " VALUES ('%ld','%s','%ld')",
UsrDat->UsrCod,Sco_ScopeAdminDB[Scope],Cod); UsrDat->UsrCod,Sco_ScopeDB[Scope],Cod);
DB_QueryREPLACE (Query,"can not create administrator"); DB_QueryREPLACE (Query,"can not create administrator");
sprintf (Gbl.Message,Txt_THE_USER_X_has_been_enrolled_as_administrator_of_Y, 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, static void Enr_EffectivelyRemAdm (struct UsrData *UsrDat,Sco_Scope_t Scope,
long Cod,const char *InsCtrDegName) 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_has_been_removed_as_administrator_of_Y;
extern const char *Txt_THE_USER_X_is_not_an_administrator_of_Y; extern const char *Txt_THE_USER_X_is_not_an_administrator_of_Y;
char Query[1024]; 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 *****/ /***** Remove user from the table of admins *****/
sprintf (Query,"DELETE FROM admin" sprintf (Query,"DELETE FROM admin"
" WHERE UsrCod='%ld' AND Scope='%s' AND Cod='%ld'", " 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"); DB_QueryDELETE (Query,"can not remove an administrator");
sprintf (Gbl.Message,Txt_THE_USER_X_has_been_removed_as_administrator_of_Y, sprintf (Gbl.Message,Txt_THE_USER_X_has_been_removed_as_administrator_of_Y,

View File

@ -1155,6 +1155,7 @@ void Ntf_MarkNotifFilesInGroupAsRemoved (long GrpCod)
unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
char Query[1024]; char Query[1024];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
@ -1327,7 +1328,7 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
" WHERE surveys.SvyCod='%ld'" " WHERE surveys.SvyCod='%ld'"
" AND surveys.SvyCod NOT IN" " AND surveys.SvyCod NOT IN"
" (SELECT SvyCod FROM svy_grp WHERE SvyCod='%ld')" " (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 crs_usr.UsrCod<>'%ld'"
" AND (surveys.Roles&(1<<crs_usr.Role))<>0)" " AND (surveys.Roles&(1<<crs_usr.Role))<>0)"
" UNION " " 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=crs_usr.UsrCod"
" AND crs_grp_usr.UsrCod<>'%ld'" " AND crs_grp_usr.UsrCod<>'%ld'"
" AND svy_grp.SvyCod=surveys.SvyCod" " 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<<crs_usr.Role))<>0)", " AND (surveys.Roles&(1<<crs_usr.Role))<>0)",
Cod,Cod,Gbl.Usrs.Me.UsrDat.UsrCod, Cod,
Cod,Gbl.Usrs.Me.UsrDat.UsrCod); Cod,
Sco_ScopeDB[Sco_SCOPE_CRS],
Gbl.Usrs.Me.UsrDat.UsrCod,
Cod,
Gbl.Usrs.Me.UsrDat.UsrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
} }

View File

@ -36,15 +36,15 @@
/****************************** Public constants *****************************/ /****************************** Public constants *****************************/
/*****************************************************************************/ /*****************************************************************************/
const char *Sco_ScopeAdminDB[Sco_NUM_SCOPES] = const char *Sco_ScopeDB[Sco_NUM_SCOPES] =
{ {
NULL, // Sco_SCOPE_UNK "Unk", // Sco_SCOPE_UNK
"Sys", // Sco_SCOPE_SYS, "Sys", // Sco_SCOPE_SYS
NULL, // Sco_SCOPE_CTY, "Cty", // Sco_SCOPE_CTY
"Ins", // Sco_SCOPE_INS, "Ins", // Sco_SCOPE_INS
"Ctr", // Sco_SCOPE_CTR, "Ctr", // Sco_SCOPE_CTR
"Deg", // Sco_SCOPE_DEG, "Deg", // Sco_SCOPE_DEG
NULL, // Sco_SCOPE_CRS, "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) Sco_Scope_t Sco_GetScopeFromUnsignedStr (const char *UnsignedStr)
@ -307,3 +307,20 @@ Sco_Scope_t Sco_GetScopeFromUnsignedStr (const char *UnsignedStr)
return Sco_SCOPE_UNK; 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;
}

View File

@ -61,5 +61,6 @@ void Sco_SetScopesForListingGuests (void);
void Sco_SetScopesForListingStudents (void); void Sco_SetScopesForListingStudents (void);
Sco_Scope_t Sco_GetScopeFromUnsignedStr (const char *UnsignedStr); Sco_Scope_t Sco_GetScopeFromUnsignedStr (const char *UnsignedStr);
Sco_Scope_t Sco_GetScopeFromDBStr (const char *ScopeDBStr);
#endif #endif

View File

@ -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 /***** Get the number of surveys and the average number of questions per survey from this location
(all the platform, current degree or current course) *****/ (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; NumSurveysPerCourse = (float) NumSurveys / (float) NumCoursesWithSurveys;
NumQstsPerSurvey = Svy_GetNumQstsPerSurvey (Gbl.Scope.Current); NumQstsPerSurvey = Svy_GetNumQstsPerCrsSurvey (Gbl.Scope.Current);
} }
/***** Table start *****/ /***** Table start *****/

View File

@ -1,4 +1,4 @@
// swad_survey2.c: surveys // swad_survey.c: surveys
/* /*
SWAD (Shared Workspace At a Distance), SWAD (Shared Workspace At a Distance),
@ -899,8 +899,7 @@ void Svy_GetListSurveys (void)
break; break;
} }
sprintf (Query,"SELECT SvyCod" sprintf (Query,"SELECT SvyCod FROM surveys"
" FROM surveys"
" WHERE %s%s%s%s%s%s" " WHERE %s%s%s%s%s%s"
" ORDER BY %s", " ORDER BY %s",
SubQuery[Sco_SCOPE_SYS], SubQuery[Sco_SCOPE_SYS],
@ -1143,7 +1142,7 @@ void Svy_GetDataOfSurveyByCod (struct Survey *Svy)
Svy->SvyCod = Str_ConvertStrCodToLongCod (row[0]); Svy->SvyCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get survey scope (row[1]) */ /* 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."); Lay_ShowErrorAndExit ("Wrong survey scope.");
/* Get code of the country, institution, centre, degree or course (row[2]) */ /* 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) static bool Svy_CheckIfSimilarSurveyExists (struct Survey *Svy)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
char Query[512]; char Query[512];
/***** Get number of surveys with a field value from database *****/ /***** Get number of surveys with a field value from database *****/
sprintf (Query,"SELECT COUNT(*) FROM surveys" sprintf (Query,"SELECT COUNT(*) FROM surveys"
" WHERE Scope='%u' AND Cod='%ld' AND Title='%s' AND SvyCod<>'%ld'", " WHERE Scope='%s' AND Cod='%ld'"
(unsigned) Svy->Scope,Svy->Cod,Svy->Title,Svy->SvyCod); " 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); 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) 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; extern const char *Txt_Created_new_survey_X;
char Query[1024+Cns_MAX_BYTES_TEXT]; char Query[1024+Cns_MAX_BYTES_TEXT];
/***** Create a new survey *****/ /***** Create a new survey *****/
sprintf (Query,"INSERT INTO surveys" sprintf (Query,"INSERT INTO surveys"
" (Scope,Cod,Hidden,Roles,UsrCod,StartTime,EndTime,Title,Txt)" " (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')," "FROM_UNIXTIME('%ld'),FROM_UNIXTIME('%ld'),"
"'%s','%s')", "'%s','%s')",
(unsigned) Svy->Scope, Sco_ScopeDB[Svy->Scope],
Svy->Cod, Svy->Cod,
Svy->Roles, Svy->Roles,
Gbl.Usrs.Me.UsrDat.UsrCod, 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) 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; extern const char *Txt_The_survey_has_been_modified;
char Query[1024+Cns_MAX_BYTES_TEXT]; char Query[1024+Cns_MAX_BYTES_TEXT];
/***** Update the data of the survey *****/ /***** Update the data of the survey *****/
sprintf (Query,"UPDATE surveys" sprintf (Query,"UPDATE surveys"
" SET Scope='%u',Cod='%ld',Roles='%u'," " SET Scope='%s',Cod='%ld',Roles='%u',"
"StartTime=FROM_UNIXTIME('%ld')," "StartTime=FROM_UNIXTIME('%ld'),"
"EndTime=FROM_UNIXTIME('%ld')," "EndTime=FROM_UNIXTIME('%ld'),"
"Title='%s',Txt='%s'" "Title='%s',Txt='%s'"
" WHERE SvyCod='%ld'", " WHERE SvyCod='%ld'",
(unsigned) Svy->Scope,Svy->Cod, Sco_ScopeDB[Svy->Scope],Svy->Cod,
Svy->Roles, Svy->Roles,
Svy->TimeUTC[Svy_START_TIME], Svy->TimeUTC[Svy_START_TIME],
Svy->TimeUTC[Svy_END_TIME ], Svy->TimeUTC[Svy_END_TIME ],
@ -2279,8 +2283,11 @@ void Svy_RemoveGroup (long GrpCod)
char Query[256]; char Query[256];
/***** Remove group from all the surveys *****/ /***** Remove group from all the surveys *****/
sprintf (Query,"DELETE FROM svy_grp WHERE GrpCod='%ld'",GrpCod); sprintf (Query,"DELETE FROM svy_grp"
DB_QueryDELETE (Query,"can not remove group from the associations between surveys and groups"); " 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 *****/ /***** Remove group from all the surveys *****/
sprintf (Query,"DELETE FROM svy_grp USING crs_grp,svy_grp" 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); 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) void Svy_RemoveDegSurveys (long DegCod)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
char Query[512]; char Query[512];
/***** Remove all the users in degree surveys /***** Remove all the users in degree surveys
(not including surveys of courses in degree) *****/ (not including surveys of courses in degree) *****/
sprintf (Query,"DELETE FROM svy_users USING surveys,svy_users" sprintf (Query,"DELETE FROM svy_users"
" WHERE surveys.DegCod='%ld' AND surveys.CrsCod='-1'" " USING surveys,svy_users"
" WHERE surveys.Scope='%s' AND surveys.Cod='%ld'"
" AND surveys.SvyCod=svy_users.SvyCod", " AND surveys.SvyCod=svy_users.SvyCod",
DegCod); Sco_ScopeDB[Sco_SCOPE_DEG],DegCod);
DB_QueryDELETE (Query,"can not remove users who are answered surveys in a degree"); DB_QueryDELETE (Query,"can not remove users"
" who had answered surveys in a degree");
/***** Remove all the answers in degree surveys /***** Remove all the answers in degree surveys
(not including surveys of courses in degree) *****/ (not including surveys of courses in degree) *****/
sprintf (Query,"DELETE FROM svy_answers USING surveys,svy_questions,svy_answers" sprintf (Query,"DELETE FROM svy_answers"
" WHERE surveys.DegCod='%ld' AND surveys.CrsCod='-1'" " USING surveys,svy_questions,svy_answers"
" WHERE surveys.Scope='%s' AND surveys.Cod='%ld'"
" AND surveys.SvyCod=svy_questions.SvyCod" " AND surveys.SvyCod=svy_questions.SvyCod"
" AND svy_questions.QstCod=svy_answers.QstCod", " 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"); DB_QueryDELETE (Query,"can not remove answers of surveys in a degree");
/***** Remove all the questions in this survey /***** Remove all the questions in this survey
(not including surveys of courses in degree) *****/ (not including surveys of courses in degree) *****/
sprintf (Query,"DELETE FROM svy_questions USING surveys,svy_questions" sprintf (Query,"DELETE FROM svy_questions"
" WHERE surveys.DegCod='%ld' AND surveys.CrsCod='-1'" " USING surveys,svy_questions"
" WHERE surveys.Scope='%s' AND surveys.Cod='%ld'"
" AND surveys.SvyCod=svy_questions.SvyCod", " 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"); DB_QueryDELETE (Query,"can not remove questions of surveys in a degree");
/***** Remove degree surveys /***** Remove degree surveys
(not including surveys of courses in degree) *****/ (not including surveys of courses in degree) *****/
sprintf (Query,"DELETE FROM surveys" sprintf (Query,"DELETE FROM surveys"
" WHERE surveys.DegCod='%ld' AND surveys.CrsCod='-1'", " WHERE Scope='%s' AND Cod='%ld'",
DegCod); Sco_ScopeDB[Sco_SCOPE_DEG],DegCod);
DB_QueryDELETE (Query,"can not remove all the surveys of a course"); 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) void Svy_RemoveCrsSurveys (long CrsCod)
{ {
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
char Query[512]; char Query[512];
/***** Remove all the users in course surveys *****/ /***** Remove all the users in course surveys *****/
sprintf (Query,"DELETE FROM svy_users USING surveys,svy_users" sprintf (Query,"DELETE FROM svy_users"
" WHERE surveys.CrsCod='%ld'" " USING surveys,svy_users"
" WHERE surveys.Scope='%s' AND surveys.Cod='%ld'"
" AND surveys.SvyCod=svy_users.SvyCod", " AND surveys.SvyCod=svy_users.SvyCod",
CrsCod); Sco_ScopeDB[Sco_SCOPE_CRS],CrsCod);
DB_QueryDELETE (Query,"can not remove users who are answered surveys in a course"); DB_QueryDELETE (Query,"can not remove users"
" who had answered surveys in a course");
/***** Remove all the answers in course surveys *****/ /***** Remove all the answers in course surveys *****/
sprintf (Query,"DELETE FROM svy_answers USING surveys,svy_questions,svy_answers" sprintf (Query,"DELETE FROM svy_answers"
" WHERE surveys.CrsCod='%ld'" " USING surveys,svy_questions,svy_answers"
" WHERE surveys.Scope='%s' AND surveys.Cod='%ld'"
" AND surveys.SvyCod=svy_questions.SvyCod" " AND surveys.SvyCod=svy_questions.SvyCod"
" AND svy_questions.QstCod=svy_answers.QstCod", " 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"); DB_QueryDELETE (Query,"can not remove answers of surveys in a course");
/***** Remove all the questions in course surveys *****/ /***** Remove all the questions in course surveys *****/
sprintf (Query,"DELETE FROM svy_questions USING surveys,svy_questions" sprintf (Query,"DELETE FROM svy_questions"
" WHERE surveys.CrsCod='%ld'" " USING surveys,svy_questions"
" WHERE surveys.Scope='%s' AND surveys.Cod='%ld'"
" AND surveys.SvyCod=svy_questions.SvyCod", " 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"); DB_QueryDELETE (Query,"can not remove questions of surveys in a course");
/***** Remove groups *****/ /***** Remove groups *****/
sprintf (Query,"DELETE FROM svy_grp USING surveys,svy_grp" sprintf (Query,"DELETE FROM svy_grp"
" WHERE surveys.CrsCod='%ld' AND surveys.SvyCod=svy_grp.SvyCod", " USING surveys,svy_grp"
CrsCod); " WHERE surveys.Scope='%s' AND surveys.Cod='%ld'"
DB_QueryDELETE (Query,"can not remove all the groups associated to surveys of a course"); " 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 *****/ /***** 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"); 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'" " WHERE SvyCod='%ld'"
" AND (SvyCod NOT IN (SELECT SvyCod FROM svy_grp) OR" " AND (SvyCod NOT IN (SELECT SvyCod FROM svy_grp) OR"
" SvyCod IN (SELECT svy_grp.SvyCod FROM svy_grp,crs_grp_usr" " 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); SvyCod,Gbl.Usrs.Me.UsrDat.UsrCod);
return (DB_QueryCOUNT (Query,"can not check if I can do a survey") != 0); 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 // Returns the number of courses with surveys for courses
// in this location (all the platform, current degree or current course) // 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]; char Query[1024];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
@ -3723,48 +3749,58 @@ unsigned Svy_GetNumCoursesWithSurveys (Sco_Scope_t Scope)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT Cod)"
" FROM surveys" " FROM surveys"
" WHERE CrsCod>'0'"); " WHERE Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
sprintf (Query,"SELECT COUNT(DISTINCT (surveys.CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT surveys.Cod)"
" FROM institutions,centres,degrees,courses,surveys" " FROM institutions,centres,degrees,courses,surveys"
" WHERE institutions.CtyCod='%ld'" " WHERE institutions.CtyCod='%ld'"
" AND institutions.InsCod=centres.InsCod" " AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=surveys.CrsCod", " AND courses.CrsCod=surveys.Cod"
Gbl.CurrentIns.Ins.InsCod); " AND surveys.Scope='%s'",
Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
sprintf (Query,"SELECT COUNT(DISTINCT (surveys.CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT surveys.Cod)"
" FROM centres,degrees,courses,surveys" " FROM centres,degrees,courses,surveys"
" WHERE centres.InsCod='%ld'" " WHERE centres.InsCod='%ld'"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=surveys.CrsCod", " AND courses.CrsCod=surveys.Cod"
Gbl.CurrentIns.Ins.InsCod); " AND surveys.Scope='%s'",
Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
sprintf (Query,"SELECT COUNT(DISTINCT (surveys.CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT surveys.Cod)"
" FROM degrees,courses,surveys" " FROM degrees,courses,surveys"
" WHERE degrees.CtrCod='%ld'" " WHERE degrees.CtrCod='%ld'"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=surveys.CrsCod", " AND courses.CrsCod=surveys.Cod"
Gbl.CurrentCtr.Ctr.CtrCod); " AND surveys.Scope='%s'",
Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
sprintf (Query,"SELECT COUNT(DISTINCT (surveys.CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT surveys.Cod)"
" FROM courses,surveys" " FROM courses,surveys"
" WHERE courses.DegCod='%ld'" " WHERE courses.DegCod='%ld'"
" AND courses.CrsCod=surveys.CrsCod", " AND courses.CrsCod=surveys.Cod"
Gbl.CurrentDeg.Deg.DegCod); " AND surveys.Scope='%s'",
Gbl.CurrentDeg.Deg.DegCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT Cod)"
" FROM surveys" " FROM surveys"
" WHERE CrsCod='%ld'", " WHERE Scope='%s' AND Cod='%ld'",
Sco_ScopeDB[Sco_SCOPE_CRS],
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: 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 // Returns the number of surveys for courses
// in this location (all the platform, current degree or current course) // 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]; char Query[1024];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
@ -3803,7 +3840,8 @@ unsigned Svy_GetNumSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)" sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)"
" FROM surveys" " FROM surveys"
" WHERE CrsCod>'0'"); " WHERE Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
sprintf (Query,"SELECT COUNT(*),SUM(surveys.NumNotif)" 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 institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=surveys.CrsCod", " AND courses.CrsCod=surveys.Cod"
Gbl.CurrentCty.Cty.CtyCod); " AND surveys.Scope='%s'",
Gbl.CurrentCty.Cty.CtyCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
sprintf (Query,"SELECT COUNT(*),SUM(surveys.NumNotif)" sprintf (Query,"SELECT COUNT(*),SUM(surveys.NumNotif)"
@ -3821,28 +3861,36 @@ unsigned Svy_GetNumSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
" WHERE centres.InsCod='%ld'" " WHERE centres.InsCod='%ld'"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=surveys.CrsCod", " AND courses.CrsCod=surveys.Cod"
Gbl.CurrentIns.Ins.InsCod); " AND surveys.Scope='%s'",
Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
sprintf (Query,"SELECT COUNT(*),SUM(surveys.NumNotif)" sprintf (Query,"SELECT COUNT(*),SUM(surveys.NumNotif)"
" FROM degrees,courses,surveys" " FROM degrees,courses,surveys"
" WHERE degrees.CtrCod='%ld'" " WHERE degrees.CtrCod='%ld'"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=surveys.CrsCod", " AND courses.CrsCod=surveys.Cod"
Gbl.CurrentCtr.Ctr.CtrCod); " AND surveys.Scope='%s'",
Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
sprintf (Query,"SELECT COUNT(*),SUM(surveys.NumNotif)" sprintf (Query,"SELECT COUNT(*),SUM(surveys.NumNotif)"
" FROM courses,surveys" " FROM courses,surveys"
" WHERE courses.DegCod='%ld'" " WHERE courses.DegCod='%ld'"
" AND courses.CrsCod=surveys.CrsCod", " AND courses.CrsCod=surveys.Cod"
Gbl.CurrentDeg.Deg.DegCod); " AND surveys.Scope='%s'",
Gbl.CurrentDeg.Deg.DegCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)" sprintf (Query,"SELECT COUNT(*),SUM(NumNotif)"
" FROM surveys" " FROM surveys"
" WHERE CrsCod='%ld'", " WHERE surveys.Scope='%s'"
" AND CrsCod='%ld'",
Sco_ScopeDB[Sco_SCOPE_CRS],
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: 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]; char Query[1024];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
float NumQstsPerSurvey; float NumQstsPerSurvey;
/***** Get number of courses per user from database *****/ /***** Get number of questions per survey from database *****/
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
sprintf (Query,"SELECT AVG(NumQsts) FROM" sprintf (Query,"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM surveys,svy_questions" " FROM surveys,svy_questions"
" WHERE surveys.CrsCod>'0'" " WHERE surveys.Scope='%s'"
" AND surveys.SvyCod=svy_questions.SvyCod" " 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; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
sprintf (Query,"SELECT AVG(NumQsts) FROM" sprintf (Query,"SELECT AVG(NumQsts) FROM"
@ -3901,10 +3951,12 @@ float Svy_GetNumQstsPerSurvey (Sco_Scope_t Scope)
" AND institutions.InsCod=centres.InsCod" " AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod" " 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" " AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.CurrentCty.Cty.CtyCod); Gbl.CurrentCty.Cty.CtyCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
sprintf (Query,"SELECT AVG(NumQsts) FROM" sprintf (Query,"SELECT AVG(NumQsts) FROM"
@ -3913,10 +3965,12 @@ float Svy_GetNumQstsPerSurvey (Sco_Scope_t Scope)
" WHERE centres.InsCod='%ld'" " WHERE centres.InsCod='%ld'"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod" " 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" " AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.CurrentIns.Ins.InsCod); Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
sprintf (Query,"SELECT AVG(NumQsts) FROM" sprintf (Query,"SELECT AVG(NumQsts) FROM"
@ -3924,28 +3978,34 @@ float Svy_GetNumQstsPerSurvey (Sco_Scope_t Scope)
" FROM degrees,courses,surveys,svy_questions" " FROM degrees,courses,surveys,svy_questions"
" WHERE degrees.CtrCod='%ld'" " WHERE degrees.CtrCod='%ld'"
" AND degrees.DegCod=courses.DegCod" " 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" " AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.CurrentCtr.Ctr.CtrCod); Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
sprintf (Query,"SELECT AVG(NumQsts) FROM" sprintf (Query,"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM courses,surveys,svy_questions" " FROM courses,surveys,svy_questions"
" WHERE courses.DegCod='%ld'" " WHERE courses.DegCod='%ld'"
" AND courses.CrsCod=surveys.CrsCod" " AND courses.CrsCod=surveys.Cod"
" AND surveys.Scope='%s'"
" AND surveys.SvyCod=svy_questions.SvyCod" " AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.CurrentDeg.Deg.DegCod); Gbl.CurrentDeg.Deg.DegCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
sprintf (Query,"SELECT AVG(NumQsts) FROM" sprintf (Query,"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM surveys,svy_questions" " FROM surveys,svy_questions"
" WHERE surveys.CrsCod='%ld'" " WHERE surveys.Scope='%s'"
" AND surveys.CrsCod='%ld'"
" AND surveys.SvyCod=svy_questions.SvyCod" " 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],
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:

View File

@ -109,8 +109,8 @@ void Svy_RemoveQst (void);
void Svy_ReceiveSurveyAnswers (void); void Svy_ReceiveSurveyAnswers (void);
unsigned Svy_GetNumCoursesWithSurveys (Sco_Scope_t Scope); unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope);
unsigned Svy_GetNumSurveys (Sco_Scope_t Scope,unsigned *NumNotif); unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif);
float Svy_GetNumQstsPerSurvey (Sco_Scope_t Scope); float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope);
#endif #endif

View File

@ -6526,17 +6526,17 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Sco_Scope_t Scope,Tst_AnswerT
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
if (AnsType == Tst_ANS_ALL) if (AnsType == Tst_ANS_ALL)
sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)"
" FROM tst_questions"); " FROM tst_questions");
else else
sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)"
" FROM tst_questions" " FROM tst_questions"
" WHERE AnsType='%s'", " WHERE AnsType='%s'",
Tst_StrAnswerTypesDB[AnsType]); Tst_StrAnswerTypesDB[AnsType]);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
if (AnsType == Tst_ANS_ALL) 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" " FROM institutions,centres,degrees,courses,tst_questions"
" WHERE institutions.CtyCod='%ld'" " WHERE institutions.CtyCod='%ld'"
" AND institutions.InsCod=centres.InsCod" " 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", " AND courses.CrsCod=tst_questions.CrsCod",
Gbl.CurrentCty.Cty.CtyCod); Gbl.CurrentCty.Cty.CtyCod);
else else
sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM institutions,centres,degrees,courses,tst_questions" " FROM institutions,centres,degrees,courses,tst_questions"
" WHERE institutions.CtyCod='%ld'" " WHERE institutions.CtyCod='%ld'"
" AND institutions.InsCod=centres.InsCod" " AND institutions.InsCod=centres.InsCod"
@ -6558,7 +6558,7 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Sco_Scope_t Scope,Tst_AnswerT
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
if (AnsType == Tst_ANS_ALL) 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" " FROM centres,degrees,courses,tst_questions"
" WHERE centres.InsCod='%ld'" " WHERE centres.InsCod='%ld'"
" AND centres.CtrCod=degrees.CtrCod" " 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", " AND courses.CrsCod=tst_questions.CrsCod",
Gbl.CurrentIns.Ins.InsCod); Gbl.CurrentIns.Ins.InsCod);
else else
sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM centres,degrees,courses,tst_questions" " FROM centres,degrees,courses,tst_questions"
" WHERE centres.InsCod='%ld'" " WHERE centres.InsCod='%ld'"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
@ -6578,14 +6578,14 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Sco_Scope_t Scope,Tst_AnswerT
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
if (AnsType == Tst_ANS_ALL) 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" " FROM degrees,courses,tst_questions"
" WHERE degrees.CtrCod='%ld'" " WHERE degrees.CtrCod='%ld'"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=tst_questions.CrsCod", " AND courses.CrsCod=tst_questions.CrsCod",
Gbl.CurrentCtr.Ctr.CtrCod); Gbl.CurrentCtr.Ctr.CtrCod);
else else
sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM degrees,courses,tst_questions" " FROM degrees,courses,tst_questions"
" WHERE degrees.CtrCod='%ld'" " WHERE degrees.CtrCod='%ld'"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
@ -6596,13 +6596,13 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Sco_Scope_t Scope,Tst_AnswerT
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
if (AnsType == Tst_ANS_ALL) if (AnsType == Tst_ANS_ALL)
sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" sprintf (Query,"SELECT COUNTDISTINCT (tst_questions.CrsCod)"
" FROM courses,tst_questions" " FROM courses,tst_questions"
" WHERE courses.DegCod='%ld'" " WHERE courses.DegCod='%ld'"
" AND courses.CrsCod=tst_questions.CrsCod", " AND courses.CrsCod=tst_questions.CrsCod",
Gbl.CurrentDeg.Deg.DegCod); Gbl.CurrentDeg.Deg.DegCod);
else else
sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM courses,tst_questions" " FROM courses,tst_questions"
" WHERE courses.DegCod='%ld'" " WHERE courses.DegCod='%ld'"
" AND courses.CrsCod=tst_questions.CrsCod" " AND courses.CrsCod=tst_questions.CrsCod"
@ -6612,12 +6612,12 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Sco_Scope_t Scope,Tst_AnswerT
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
if (AnsType == Tst_ANS_ALL) if (AnsType == Tst_ANS_ALL)
sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)"
" FROM tst_questions" " FROM tst_questions"
" WHERE CrsCod='%ld'", " WHERE CrsCod='%ld'",
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);
else else
sprintf (Query,"SELECT COUNT(DISTINCT (CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT CrsCod)"
" FROM tst_questions" " FROM tst_questions"
" WHERE CrsCod='%ld'" " WHERE CrsCod='%ld'"
" AND AnsType='%s'", " AND AnsType='%s'",
@ -6675,7 +6675,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
if (AnsType == Tst_ANS_ALL) 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" " FROM institutions,centres,degrees,courses,tst_questions,tst_config"
" WHERE institutions.CtyCod='%ld'" " WHERE institutions.CtyCod='%ld'"
" AND institutions.InsCod=centres.InsCod" " AND institutions.InsCod=centres.InsCod"
@ -6687,7 +6687,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts
Gbl.CurrentCty.Cty.CtyCod, Gbl.CurrentCty.Cty.CtyCod,
Tst_PluggableDB[Tst_PLUGGABLE_YES]); Tst_PluggableDB[Tst_PLUGGABLE_YES]);
else 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" " FROM institutions,centres,degrees,courses,tst_questions,tst_config"
" WHERE institutions.CtyCod='%ld'" " WHERE institutions.CtyCod='%ld'"
" AND institutions.InsCod=centres.InsCod" " AND institutions.InsCod=centres.InsCod"
@ -6703,7 +6703,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
if (AnsType == Tst_ANS_ALL) 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" " FROM centres,degrees,courses,tst_questions,tst_config"
" WHERE centres.InsCod='%ld'" " WHERE centres.InsCod='%ld'"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
@ -6714,7 +6714,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
Tst_PluggableDB[Tst_PLUGGABLE_YES]); Tst_PluggableDB[Tst_PLUGGABLE_YES]);
else 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" " FROM centres,degrees,courses,tst_questions,tst_config"
" WHERE centres.InsCod='%ld'" " WHERE centres.InsCod='%ld'"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
@ -6729,7 +6729,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
if (AnsType == Tst_ANS_ALL) 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" " FROM degrees,courses,tst_questions,tst_config"
" WHERE degrees.CtrCod='%ld'" " WHERE degrees.CtrCod='%ld'"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
@ -6739,7 +6739,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts
Gbl.CurrentCtr.Ctr.CtrCod, Gbl.CurrentCtr.Ctr.CtrCod,
Tst_PluggableDB[Tst_PLUGGABLE_YES]); Tst_PluggableDB[Tst_PLUGGABLE_YES]);
else else
sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM degrees,courses,tst_questions,tst_config" " FROM degrees,courses,tst_questions,tst_config"
" WHERE degrees.CtrCod='%ld'" " WHERE degrees.CtrCod='%ld'"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
@ -6753,7 +6753,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
if (AnsType == Tst_ANS_ALL) 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" " FROM courses,tst_questions,tst_config"
" WHERE courses.DegCod='%ld'" " WHERE courses.DegCod='%ld'"
" AND courses.CrsCod=tst_questions.CrsCod" " AND courses.CrsCod=tst_questions.CrsCod"
@ -6762,7 +6762,7 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Sco_Scope_t Scope,Ts
Gbl.CurrentDeg.Deg.DegCod, Gbl.CurrentDeg.Deg.DegCod,
Tst_PluggableDB[Tst_PLUGGABLE_YES]); Tst_PluggableDB[Tst_PLUGGABLE_YES]);
else else
sprintf (Query,"SELECT COUNT(DISTINCT (tst_questions.CrsCod))" sprintf (Query,"SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM courses,tst_questions,tst_config" " FROM courses,tst_questions,tst_config"
" WHERE courses.DegCod='%ld'" " WHERE courses.DegCod='%ld'"
" AND courses.CrsCod=tst_questions.CrsCod" " AND courses.CrsCod=tst_questions.CrsCod"

View File

@ -753,15 +753,15 @@ void Usr_RestrictLengthAndWriteName (const struct UsrData *UsrDat,unsigned MaxCh
bool Usr_CheckIfUsrIsAdm (long UsrCod,Sco_Scope_t Scope,long Cod) 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]; char Query[128];
if (Sco_ScopeAdminDB[Scope]) if (Sco_ScopeDB[Scope])
{ {
/***** Get if a user is administrator of a degree from database *****/ /***** Get if a user is administrator of a degree from database *****/
sprintf (Query,"SELECT COUNT(*) FROM admin" sprintf (Query,"SELECT COUNT(*) FROM admin"
" WHERE UsrCod='%ld' AND Scope='%s' AND Cod='%ld'", " 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 (DB_QueryCOUNT (Query,"can not check if a user is administrator") != 0);
} }
return false; return false;