Version 18.11.15

This commit is contained in:
Antonio Cañas Vargas 2018-11-02 01:23:05 +01:00
parent a86d7ce36d
commit 5673416716
5 changed files with 674 additions and 575 deletions

View File

@ -355,10 +355,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf ps2pdf source.ps destination.pdf
*/ */
#define Log_PLATFORM_VERSION "SWAD 18.11.14 (2018-11-01)" #define Log_PLATFORM_VERSION "SWAD 18.11.15 (2018-11-02)"
#define CSS_FILE "swad18.4.css" #define CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js" #define JS_FILE "swad17.17.1.js"
/* /*
Version 18.11.15: Nov 02, 2018 Joining building and performing query into one function. (236312 lines)
Version 18.11.14: Nov 01, 2018 Joining building and performing query into one function. (236211 lines) Version 18.11.14: Nov 01, 2018 Joining building and performing query into one function. (236211 lines)
Version 18.11.13: Nov 01, 2018 Joining building and performing query into one function. (236011 lines) Version 18.11.13: Nov 01, 2018 Joining building and performing query into one function. (236011 lines)
Version 18.11.12: Nov 01, 2018 Joining building and performing query into one function. (235965 lines) Version 18.11.12: Nov 01, 2018 Joining building and performing query into one function. (235965 lines)

View File

@ -923,7 +923,7 @@ void Svy_GetListSurveys (void)
else else
SubQuery[Sco_SCOPE_CRS][0] = '\0'; SubQuery[Sco_SCOPE_CRS][0] = '\0';
/* Build query */ /* Make query */
if (SubQueryFilled) if (SubQueryFilled)
{ {
switch (Gbl.Svys.SelectedOrder) switch (Gbl.Svys.SelectedOrder)
@ -936,22 +936,23 @@ void Svy_GetListSurveys (void)
break; break;
} }
DB_BuildQuery ("SELECT SvyCod FROM surveys" NumRows = DB_QuerySELECT (&mysql_res,"can not get surveys",
" WHERE %s%s%s%s%s%s" "SELECT SvyCod FROM surveys"
" ORDER BY %s", " WHERE %s%s%s%s%s%s"
SubQuery[Sco_SCOPE_SYS], " ORDER BY %s",
SubQuery[Sco_SCOPE_CTY], SubQuery[Sco_SCOPE_SYS],
SubQuery[Sco_SCOPE_INS], SubQuery[Sco_SCOPE_CTY],
SubQuery[Sco_SCOPE_CTR], SubQuery[Sco_SCOPE_INS],
SubQuery[Sco_SCOPE_DEG], SubQuery[Sco_SCOPE_CTR],
SubQuery[Sco_SCOPE_CRS], SubQuery[Sco_SCOPE_DEG],
OrderBySubQuery); SubQuery[Sco_SCOPE_CRS],
OrderBySubQuery);
} }
else else
{
Lay_ShowErrorAndExit ("Can not get list of surveys."); Lay_ShowErrorAndExit ("Can not get list of surveys.");
NumRows = 0; // Not reached. Initialized to avoid warning
/* Make query */ }
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get surveys");
if (NumRows) // Surveys found... if (NumRows) // Surveys found...
{ {
@ -1158,18 +1159,16 @@ void Svy_GetDataOfSurveyByCod (struct Survey *Svy)
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned long NumRows;
/***** Build query *****/
DB_BuildQuery ("SELECT SvyCod,Scope,Cod,Hidden,Roles,UsrCod,"
"UNIX_TIMESTAMP(StartTime),"
"UNIX_TIMESTAMP(EndTime),"
"NOW() BETWEEN StartTime AND EndTime,"
"Title"
" FROM surveys"
" WHERE SvyCod=%ld",
Svy->SvyCod);
/***** Get data of survey from database *****/ /***** Get data of survey from database *****/
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get survey data"); NumRows = DB_QuerySELECT (&mysql_res,"can not get survey data",
"SELECT SvyCod,Scope,Cod,Hidden,Roles,UsrCod,"
"UNIX_TIMESTAMP(StartTime),"
"UNIX_TIMESTAMP(EndTime),"
"NOW() BETWEEN StartTime AND EndTime,"
"Title"
" FROM surveys"
" WHERE SvyCod=%ld",
Svy->SvyCod);
if (NumRows) // Survey found... if (NumRows) // Survey found...
{ {
@ -1389,8 +1388,9 @@ static void Svy_GetSurveyTxtFromDB (long SvyCod,char Txt[Cns_MAX_BYTES_TEXT + 1]
unsigned long NumRows; unsigned long NumRows;
/***** Get text of survey from database *****/ /***** Get text of survey from database *****/
DB_BuildQuery ("SELECT Txt FROM surveys WHERE SvyCod=%ld",SvyCod); NumRows = DB_QuerySELECT (&mysql_res,"can not get survey text",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get survey text"); "SELECT Txt FROM surveys WHERE SvyCod=%ld",
SvyCod);
/***** The result of the query must have one row or none *****/ /***** The result of the query must have one row or none *****/
if (NumRows == 1) if (NumRows == 1)
@ -2417,14 +2417,15 @@ static void Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (struct Survey *Svy)
unsigned long NumRows; unsigned long NumRows;
/***** Get groups associated to a survey from database *****/ /***** Get groups associated to a survey from database *****/
DB_BuildQuery ("SELECT crs_grp_types.GrpTypName,crs_grp.GrpName" NumRows = DB_QuerySELECT (&mysql_res,"can not get groups of a survey",
" FROM svy_grp,crs_grp,crs_grp_types" "SELECT crs_grp_types.GrpTypName,crs_grp.GrpName"
" WHERE svy_grp.SvyCod=%ld" " FROM svy_grp,crs_grp,crs_grp_types"
" AND svy_grp.GrpCod=crs_grp.GrpCod" " WHERE svy_grp.SvyCod=%ld"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod" " AND svy_grp.GrpCod=crs_grp.GrpCod"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName", " AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
Svy->SvyCod); " ORDER BY crs_grp_types.GrpTypName,"
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get groups of a survey"); "crs_grp.GrpName",
Svy->SvyCod);
/***** Write heading *****/ /***** Write heading *****/
fprintf (Gbl.F.Out,"<div class=\"%s\">%s: ", fprintf (Gbl.F.Out,"<div class=\"%s\">%s: ",
@ -2609,10 +2610,10 @@ static void Svy_ShowFormEditOneQst (long SvyCod,struct SurveyQuestion *SvyQst,
{ {
/***** Get the type of answer and the stem from the database *****/ /***** Get the type of answer and the stem from the database *****/
/* Get the question from database */ /* Get the question from database */
DB_BuildQuery ("SELECT QstInd,AnsType,Stem FROM svy_questions" DB_QuerySELECT (&mysql_res,"can not get a question",
" WHERE QstCod=%ld AND SvyCod=%ld", "SELECT QstInd,AnsType,Stem FROM svy_questions"
SvyQst->QstCod,SvyCod); " WHERE QstCod=%ld AND SvyCod=%ld",
DB_QuerySELECT_new (&mysql_res,"can not get a question"); SvyQst->QstCod,SvyCod);
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -2856,10 +2857,10 @@ static unsigned Svy_GetAnswersQst (long QstCod,MYSQL_RES **mysql_res)
unsigned long NumRows; unsigned long NumRows;
/***** Get answers of a question from database *****/ /***** Get answers of a question from database *****/
DB_BuildQuery ("SELECT AnsInd,NumUsrs,Answer FROM svy_answers" NumRows = DB_QuerySELECT (mysql_res,"can not get answers of a question",
" WHERE QstCod=%ld ORDER BY AnsInd", "SELECT AnsInd,NumUsrs,Answer FROM svy_answers"
QstCod); " WHERE QstCod=%ld ORDER BY AnsInd",
NumRows = DB_QuerySELECT_new (mysql_res,"can not get answers of a question"); QstCod);
/***** Count number of rows of result *****/ /***** Count number of rows of result *****/
if (NumRows == 0) if (NumRows == 0)
@ -3095,8 +3096,10 @@ static unsigned Svy_GetQstIndFromQstCod (long QstCod)
unsigned QstInd = 0; unsigned QstInd = 0;
/***** Get number of surveys with a field value from database *****/ /***** Get number of surveys with a field value from database *****/
DB_BuildQuery ("SELECT QstInd FROM svy_questions WHERE QstCod=%ld",QstCod); NumRows = DB_QuerySELECT (&mysql_res,"can not get question index",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get question index"); "SELECT QstInd FROM svy_questions"
" WHERE QstCod=%ld",
QstCod);
/***** Get number of users *****/ /***** Get number of users *****/
if (NumRows) if (NumRows)
@ -3125,9 +3128,9 @@ static unsigned Svy_GetNextQuestionIndexInSvy (long SvyCod)
unsigned QstInd = 0; unsigned QstInd = 0;
/***** Get number of surveys with a field value from database *****/ /***** Get number of surveys with a field value from database *****/
DB_BuildQuery ("SELECT MAX(QstInd) FROM svy_questions WHERE SvyCod=%ld", DB_QuerySELECT (&mysql_res,"can not get last question index",
SvyCod); "SELECT MAX(QstInd) FROM svy_questions WHERE SvyCod=%ld",
DB_QuerySELECT_new (&mysql_res,"can not get last question index"); SvyCod);
/***** Get number of users *****/ /***** Get number of users *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3169,11 +3172,11 @@ static void Svy_ListSvyQuestions (struct Survey *Svy,
bool PutFormAnswerSurvey = Svy->Status.ICanAnswer && !Editing; bool PutFormAnswerSurvey = Svy->Status.ICanAnswer && !Editing;
/***** Get data of questions from database *****/ /***** Get data of questions from database *****/
DB_BuildQuery ("SELECT QstCod,QstInd,AnsType,Stem" NumQsts = (unsigned) DB_QuerySELECT (&mysql_res,"can not get data of a question",
" FROM svy_questions" "SELECT QstCod,QstInd,AnsType,Stem"
" WHERE SvyCod=%ld ORDER BY QstInd", " FROM svy_questions"
Svy->SvyCod); " WHERE SvyCod=%ld ORDER BY QstInd",
NumQsts = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get data of a question"); Svy->SvyCod);
/***** Start box *****/ /***** Start box *****/
Gbl.Svys.SvyCodToEdit = Svy->SvyCod; Gbl.Svys.SvyCodToEdit = Svy->SvyCod;
@ -3663,11 +3666,12 @@ static void Svy_ReceiveAndStoreUserAnswersToASurvey (long SvyCod)
unsigned AnsInd; unsigned AnsInd;
/***** Get questions of this survey from database *****/ /***** Get questions of this survey from database *****/
DB_BuildQuery ("SELECT QstCod FROM svy_questions" NumQsts = (unsigned) DB_QuerySELECT (&mysql_res,"can not get questions"
" WHERE SvyCod=%ld ORDER BY QstCod", " of a survey",
SvyCod); "SELECT QstCod FROM svy_questions"
if ((NumQsts = (unsigned) DB_QuerySELECT_new (&mysql_res, " WHERE SvyCod=%ld ORDER BY QstCod",
"can not get questions of a survey"))) SvyCod);
if (NumQsts)
{ {
// This survey has questions // This survey has questions
/***** Get questions *****/ /***** Get questions *****/
@ -3778,65 +3782,76 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT COUNT(DISTINCT Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses"
" FROM surveys" " with surveys",
" WHERE Scope='%s'", "SELECT COUNT(DISTINCT Cod)"
Sco_ScopeDB[Sco_SCOPE_CRS]); " FROM surveys"
" WHERE Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT COUNT(DISTINCT surveys.Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses"
" FROM institutions,centres,degrees,courses,surveys" " with surveys",
" WHERE institutions.CtyCod=%ld" "SELECT COUNT(DISTINCT surveys.Cod)"
" AND institutions.InsCod=centres.InsCod" " FROM institutions,centres,degrees,courses,surveys"
" AND centres.CtrCod=degrees.CtrCod" " WHERE institutions.CtyCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND institutions.InsCod=centres.InsCod"
" AND courses.CrsCod=surveys.Cod" " AND centres.CtrCod=degrees.CtrCod"
" AND surveys.Scope='%s'", " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentIns.Ins.InsCod, " AND courses.CrsCod=surveys.Cod"
Sco_ScopeDB[Sco_SCOPE_CRS]); " AND surveys.Scope='%s'",
Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(DISTINCT surveys.Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses"
" FROM centres,degrees,courses,surveys" " with surveys",
" WHERE centres.InsCod=%ld" "SELECT COUNT(DISTINCT surveys.Cod)"
" AND centres.CtrCod=degrees.CtrCod" " FROM centres,degrees,courses,surveys"
" AND degrees.DegCod=courses.DegCod" " WHERE centres.InsCod=%ld"
" AND courses.CrsCod=surveys.Cod" " AND centres.CtrCod=degrees.CtrCod"
" AND surveys.Scope='%s'", " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentIns.Ins.InsCod, " AND courses.CrsCod=surveys.Cod"
Sco_ScopeDB[Sco_SCOPE_CRS]); " AND surveys.Scope='%s'",
Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT COUNT(DISTINCT surveys.Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses"
" FROM degrees,courses,surveys" " with surveys",
" WHERE degrees.CtrCod=%ld" "SELECT COUNT(DISTINCT surveys.Cod)"
" AND degrees.DegCod=courses.DegCod" " FROM degrees,courses,surveys"
" AND courses.CrsCod=surveys.Cod" " WHERE degrees.CtrCod=%ld"
" AND surveys.Scope='%s'", " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentCtr.Ctr.CtrCod, " AND courses.CrsCod=surveys.Cod"
Sco_ScopeDB[Sco_SCOPE_CRS]); " AND surveys.Scope='%s'",
Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT COUNT(DISTINCT surveys.Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses"
" FROM courses,surveys" " with surveys",
" WHERE courses.DegCod=%ld" "SELECT COUNT(DISTINCT surveys.Cod)"
" AND courses.CrsCod=surveys.Cod" " FROM courses,surveys"
" AND surveys.Scope='%s'", " WHERE courses.DegCod=%ld"
Gbl.CurrentDeg.Deg.DegCod, " AND courses.CrsCod=surveys.Cod"
Sco_ScopeDB[Sco_SCOPE_CRS]); " AND surveys.Scope='%s'",
Gbl.CurrentDeg.Deg.DegCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(DISTINCT Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses"
" FROM surveys" " with surveys",
" WHERE Scope='%s' AND Cod=%ld", "SELECT COUNT(DISTINCT Cod)"
Sco_ScopeDB[Sco_SCOPE_CRS], " FROM surveys"
Gbl.CurrentCrs.Crs.CrsCod); " WHERE Scope='%s' AND Cod=%ld",
Sco_ScopeDB[Sco_SCOPE_CRS],
Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of courses with surveys");
/***** Get number of surveys *****/ /***** Get number of surveys *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3866,66 +3881,71 @@ unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT COUNT(*),SUM(NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of surveys",
" FROM surveys" "SELECT COUNT(*),SUM(NumNotif)"
" WHERE Scope='%s'", " FROM surveys"
Sco_ScopeDB[Sco_SCOPE_CRS]); " WHERE Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT COUNT(*),SUM(surveys.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of surveys",
" FROM institutions,centres,degrees,courses,surveys" "SELECT COUNT(*),SUM(surveys.NumNotif)"
" WHERE institutions.CtyCod=%ld" " FROM institutions,centres,degrees,courses,surveys"
" AND institutions.InsCod=centres.InsCod" " WHERE institutions.CtyCod=%ld"
" AND centres.CtrCod=degrees.CtrCod" " AND institutions.InsCod=centres.InsCod"
" AND degrees.DegCod=courses.DegCod" " AND centres.CtrCod=degrees.CtrCod"
" AND courses.CrsCod=surveys.Cod" " AND degrees.DegCod=courses.DegCod"
" AND surveys.Scope='%s'", " AND courses.CrsCod=surveys.Cod"
Gbl.CurrentCty.Cty.CtyCod, " AND surveys.Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Gbl.CurrentCty.Cty.CtyCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(*),SUM(surveys.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of surveys",
" FROM centres,degrees,courses,surveys" "SELECT COUNT(*),SUM(surveys.NumNotif)"
" WHERE centres.InsCod=%ld" " FROM centres,degrees,courses,surveys"
" AND centres.CtrCod=degrees.CtrCod" " WHERE centres.InsCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND centres.CtrCod=degrees.CtrCod"
" AND courses.CrsCod=surveys.Cod" " AND degrees.DegCod=courses.DegCod"
" AND surveys.Scope='%s'", " AND courses.CrsCod=surveys.Cod"
Gbl.CurrentIns.Ins.InsCod, " AND surveys.Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT COUNT(*),SUM(surveys.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of surveys",
" FROM degrees,courses,surveys" "SELECT COUNT(*),SUM(surveys.NumNotif)"
" WHERE degrees.CtrCod=%ld" " FROM degrees,courses,surveys"
" AND degrees.DegCod=courses.DegCod" " WHERE degrees.CtrCod=%ld"
" AND courses.CrsCod=surveys.Cod" " AND degrees.DegCod=courses.DegCod"
" AND surveys.Scope='%s'", " AND courses.CrsCod=surveys.Cod"
Gbl.CurrentCtr.Ctr.CtrCod, " AND surveys.Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT COUNT(*),SUM(surveys.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of surveys",
" FROM courses,surveys" "SELECT COUNT(*),SUM(surveys.NumNotif)"
" WHERE courses.DegCod=%ld" " FROM courses,surveys"
" AND courses.CrsCod=surveys.Cod" " WHERE courses.DegCod=%ld"
" AND surveys.Scope='%s'", " AND courses.CrsCod=surveys.Cod"
Gbl.CurrentDeg.Deg.DegCod, " AND surveys.Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Gbl.CurrentDeg.Deg.DegCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(*),SUM(NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of surveys",
" FROM surveys" "SELECT COUNT(*),SUM(NumNotif)"
" WHERE surveys.Scope='%s'" " FROM surveys"
" AND CrsCod=%ld", " WHERE surveys.Scope='%s'"
Sco_ScopeDB[Sco_SCOPE_CRS], " AND CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod); Sco_ScopeDB[Sco_SCOPE_CRS],
Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of surveys");
/***** Get number of surveys *****/ /***** Get number of surveys *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3962,82 +3982,93 @@ float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " per survey",
" FROM surveys,svy_questions" "SELECT AVG(NumQsts) FROM"
" WHERE surveys.Scope='%s'" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" AND surveys.SvyCod=svy_questions.SvyCod" " FROM surveys,svy_questions"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " WHERE surveys.Scope='%s'"
Sco_ScopeDB[Sco_SCOPE_CRS]); " AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " per survey",
" FROM institutions,centres,degrees,courses,surveys,svy_questions" "SELECT AVG(NumQsts) FROM"
" WHERE institutions.CtyCod=%ld" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" AND institutions.InsCod=centres.InsCod" " FROM institutions,centres,degrees,courses,surveys,svy_questions"
" AND centres.CtrCod=degrees.CtrCod" " WHERE institutions.CtyCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND institutions.InsCod=centres.InsCod"
" AND courses.CrsCod=surveys.Cod" " AND centres.CtrCod=degrees.CtrCod"
" AND surveys.Scope='%s'" " AND degrees.DegCod=courses.DegCod"
" AND surveys.SvyCod=svy_questions.SvyCod" " AND courses.CrsCod=surveys.Cod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " AND surveys.Scope='%s'"
Gbl.CurrentCty.Cty.CtyCod, " AND surveys.SvyCod=svy_questions.SvyCod"
Sco_ScopeDB[Sco_SCOPE_CRS]); " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.CurrentCty.Cty.CtyCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " per survey",
" FROM centres,degrees,courses,surveys,svy_questions" "SELECT AVG(NumQsts) FROM"
" WHERE centres.InsCod=%ld" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" AND centres.CtrCod=degrees.CtrCod" " FROM centres,degrees,courses,surveys,svy_questions"
" AND degrees.DegCod=courses.DegCod" " WHERE centres.InsCod=%ld"
" AND courses.CrsCod=surveys.Cod" " AND centres.CtrCod=degrees.CtrCod"
" AND surveys.Scope='%s'" " AND degrees.DegCod=courses.DegCod"
" AND surveys.SvyCod=svy_questions.SvyCod" " AND courses.CrsCod=surveys.Cod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " AND surveys.Scope='%s'"
Gbl.CurrentIns.Ins.InsCod, " AND surveys.SvyCod=svy_questions.SvyCod"
Sco_ScopeDB[Sco_SCOPE_CRS]); " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " per survey",
" FROM degrees,courses,surveys,svy_questions" "SELECT AVG(NumQsts) FROM"
" WHERE degrees.CtrCod=%ld" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" AND degrees.DegCod=courses.DegCod" " FROM degrees,courses,surveys,svy_questions"
" AND courses.CrsCod=surveys.Cod" " WHERE degrees.CtrCod=%ld"
" AND surveys.Scope='%s'" " AND degrees.DegCod=courses.DegCod"
" AND surveys.SvyCod=svy_questions.SvyCod" " AND courses.CrsCod=surveys.Cod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " AND surveys.Scope='%s'"
Gbl.CurrentCtr.Ctr.CtrCod, " AND surveys.SvyCod=svy_questions.SvyCod"
Sco_ScopeDB[Sco_SCOPE_CRS]); " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " per survey",
" FROM courses,surveys,svy_questions" "SELECT AVG(NumQsts) FROM"
" WHERE courses.DegCod=%ld" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" AND courses.CrsCod=surveys.Cod" " FROM courses,surveys,svy_questions"
" AND surveys.Scope='%s'" " WHERE courses.DegCod=%ld"
" AND surveys.SvyCod=svy_questions.SvyCod" " AND courses.CrsCod=surveys.Cod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " AND surveys.Scope='%s'"
Gbl.CurrentDeg.Deg.DegCod, " AND surveys.SvyCod=svy_questions.SvyCod"
Sco_ScopeDB[Sco_SCOPE_CRS]); " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.CurrentDeg.Deg.DegCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " per survey",
" FROM surveys,svy_questions" "SELECT AVG(NumQsts) FROM"
" WHERE surveys.Scope='%s' AND surveys.Cod=%ld" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" AND surveys.SvyCod=svy_questions.SvyCod" " FROM surveys,svy_questions"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " WHERE surveys.Scope='%s' AND surveys.Cod=%ld"
Sco_ScopeDB[Sco_SCOPE_CRS],Gbl.CurrentCrs.Crs.CrsCod); " AND surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Sco_ScopeDB[Sco_SCOPE_CRS],Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of questions per survey");
/***** Get number of courses *****/ /***** Get number of courses *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);

View File

@ -730,12 +730,14 @@ static bool TsI_CheckIfQuestionExistsInDB (void)
unsigned i; unsigned i;
/***** Check if stem exists *****/ /***** Check if stem exists *****/
DB_BuildQuery ("SELECT QstCod FROM tst_questions" NumQstsWithThisStem =
" WHERE CrsCod=%ld AND AnsType='%s' AND Stem='%s'", (unsigned) DB_QuerySELECT (&mysql_res_qst,"can not check"
Gbl.CurrentCrs.Crs.CrsCod, " if a question exists",
Tst_StrAnswerTypesDB[Gbl.Test.AnswerType], "SELECT QstCod FROM tst_questions"
Gbl.Test.Stem.Text); " WHERE CrsCod=%ld AND AnsType='%s' AND Stem='%s'",
NumQstsWithThisStem = (unsigned) DB_QuerySELECT_new (&mysql_res_qst,"can not check if a question exists"); Gbl.CurrentCrs.Crs.CrsCod,
Tst_StrAnswerTypesDB[Gbl.Test.AnswerType],
Gbl.Test.Stem.Text);
if (NumQstsWithThisStem) // There are questions in database with the same stem that the one of this question if (NumQstsWithThisStem) // There are questions in database with the same stem that the one of this question
{ {
@ -750,10 +752,12 @@ static bool TsI_CheckIfQuestionExistsInDB (void)
Lay_ShowErrorAndExit ("Wrong code of question."); Lay_ShowErrorAndExit ("Wrong code of question.");
/* Get answers from this question */ /* Get answers from this question */
DB_BuildQuery ("SELECT Answer FROM tst_answers" NumOptsExistingQstInDB =
" WHERE QstCod=%ld ORDER BY AnsInd", (unsigned) DB_QuerySELECT (&mysql_res_ans,"can not get the answer"
QstCod); " of a question",
NumOptsExistingQstInDB = (unsigned) DB_QuerySELECT_new (&mysql_res_ans,"can not get the answer of a question"); "SELECT Answer FROM tst_answers"
" WHERE QstCod=%ld ORDER BY AnsInd",
QstCod);
switch (Gbl.Test.AnswerType) switch (Gbl.Test.AnswerType)
{ {

View File

@ -657,8 +657,8 @@ static void TT_FillTimeTableFromDB (long UsrCod)
extern const char *Txt_Incomplete_timetable_for_lack_of_space; extern const char *Txt_Incomplete_timetable_for_lack_of_space;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows = 0; // Initialized to avoid warning
unsigned long NumRow; unsigned long NumRow;
unsigned long NumRows;
unsigned Weekday; unsigned Weekday;
unsigned Interval; unsigned Interval;
unsigned i; // To iterate through intervals unsigned i; // To iterate through intervals
@ -682,76 +682,73 @@ static void TT_FillTimeTableFromDB (long UsrCod)
switch (Gbl.CurrentCrs.Grps.WhichGrps) switch (Gbl.CurrentCrs.Grps.WhichGrps)
{ {
case Grp_ONLY_MY_GROUPS: case Grp_ONLY_MY_GROUPS:
DB_BuildQuery ("SELECT " NumRows = DB_QuerySELECT (&mysql_res,"can not get timetable",
"timetable_crs.Weekday," "SELECT timetable_crs.Weekday,"
"TIME_TO_SEC(timetable_crs.StartTime) AS S," "TIME_TO_SEC(timetable_crs.StartTime) AS S,"
"TIME_TO_SEC(timetable_crs.Duration) AS D," "TIME_TO_SEC(timetable_crs.Duration) AS D,"
"timetable_crs.Place," "timetable_crs.Place,"
"timetable_crs.ClassType," "timetable_crs.ClassType,"
"timetable_crs.GroupName," "timetable_crs.GroupName,"
"timetable_crs.GrpCod," "timetable_crs.GrpCod,"
"timetable_crs.CrsCod" "timetable_crs.CrsCod"
" FROM timetable_crs,crs_usr" " FROM timetable_crs,crs_usr"
" WHERE crs_usr.UsrCod=%ld" " WHERE crs_usr.UsrCod=%ld"
" AND timetable_crs.GrpCod=-1" " AND timetable_crs.GrpCod=-1"
" AND timetable_crs.CrsCod=crs_usr.CrsCod" " AND timetable_crs.CrsCod=crs_usr.CrsCod"
" UNION DISTINCT " " UNION DISTINCT "
"SELECT " "SELECT timetable_crs.Weekday,"
"timetable_crs.Weekday," "TIME_TO_SEC(timetable_crs.StartTime) AS S,"
"TIME_TO_SEC(timetable_crs.StartTime) AS S," "TIME_TO_SEC(timetable_crs.Duration) AS D,"
"TIME_TO_SEC(timetable_crs.Duration) AS D," "timetable_crs.Place,"
"timetable_crs.Place," "timetable_crs.ClassType,"
"timetable_crs.ClassType," "timetable_crs.GroupName,"
"timetable_crs.GroupName," "timetable_crs.GrpCod,"
"timetable_crs.GrpCod," "timetable_crs.CrsCod"
"timetable_crs.CrsCod" " FROM timetable_crs,crs_grp_usr"
" FROM timetable_crs,crs_grp_usr" " WHERE crs_grp_usr.UsrCod=%ld"
" WHERE crs_grp_usr.UsrCod=%ld" " AND timetable_crs.GrpCod=crs_grp_usr.GrpCod"
" AND timetable_crs.GrpCod=crs_grp_usr.GrpCod" " UNION "
" UNION " "SELECT Weekday,"
"SELECT " "TIME_TO_SEC(StartTime) AS S,"
"Weekday," "TIME_TO_SEC(Duration) AS D,"
"TIME_TO_SEC(StartTime) AS S," "Place,"
"TIME_TO_SEC(Duration) AS D," "'tutoring' AS ClassType,"
"Place," "'' AS GroupName,"
"'tutoring' AS ClassType," "-1 AS GrpCod,"
"'' AS GroupName," "-1 AS CrsCod"
"-1 AS GrpCod," " FROM timetable_tut"
"-1 AS CrsCod" " WHERE UsrCod=%ld"
" FROM timetable_tut" " ORDER BY Weekday,S,ClassType,"
" WHERE UsrCod=%ld" "GroupName,GrpCod,Place,D DESC,CrsCod",
" ORDER BY Weekday,S,ClassType," UsrCod,UsrCod,UsrCod);
"GroupName,GrpCod,Place,D DESC,CrsCod",
UsrCod,UsrCod,UsrCod);
break; break;
case Grp_ALL_GROUPS: case Grp_ALL_GROUPS:
DB_BuildQuery ("SELECT " NumRows = DB_QuerySELECT (&mysql_res,"can not get timetable",
"timetable_crs.Weekday," "SELECT timetable_crs.Weekday,"
"TIME_TO_SEC(timetable_crs.StartTime) AS S," "TIME_TO_SEC(timetable_crs.StartTime) AS S,"
"TIME_TO_SEC(timetable_crs.Duration) AS D," "TIME_TO_SEC(timetable_crs.Duration) AS D,"
"timetable_crs.Place," "timetable_crs.Place,"
"timetable_crs.ClassType," "timetable_crs.ClassType,"
"timetable_crs.GroupName," "timetable_crs.GroupName,"
"timetable_crs.GrpCod," "timetable_crs.GrpCod,"
"timetable_crs.CrsCod" "timetable_crs.CrsCod"
" FROM timetable_crs,crs_usr" " FROM timetable_crs,crs_usr"
" WHERE crs_usr.UsrCod=%ld" " WHERE crs_usr.UsrCod=%ld"
" AND timetable_crs.CrsCod=crs_usr.CrsCod" " AND timetable_crs.CrsCod=crs_usr.CrsCod"
" UNION " " UNION "
"SELECT " "SELECT Weekday,"
"Weekday," "TIME_TO_SEC(StartTime) AS S,"
"TIME_TO_SEC(StartTime) AS S," "TIME_TO_SEC(Duration) AS D,"
"TIME_TO_SEC(Duration) AS D," "Place,"
"Place," "'tutoring' AS ClassType,"
"'tutoring' AS ClassType," "'' AS GroupName,"
"'' AS GroupName," "-1 AS GrpCod,"
"-1 AS GrpCod," "-1 AS CrsCod"
"-1 AS CrsCod" " FROM timetable_tut"
" FROM timetable_tut" " WHERE UsrCod=%ld"
" WHERE UsrCod=%ld" " ORDER BY Weekday,S,ClassType,"
" ORDER BY Weekday,S,ClassType," "GroupName,GrpCod,Place,D DESC,CrsCod",
"GroupName,GrpCod,Place,D DESC,CrsCod", UsrCod,UsrCod);
UsrCod,UsrCod);
break; break;
} }
break; break;
@ -759,62 +756,61 @@ static void TT_FillTimeTableFromDB (long UsrCod)
if (Gbl.CurrentCrs.Grps.WhichGrps == Grp_ALL_GROUPS || if (Gbl.CurrentCrs.Grps.WhichGrps == Grp_ALL_GROUPS ||
Gbl.Action.Act == ActEdiCrsTT || Gbl.Action.Act == ActEdiCrsTT ||
Gbl.Action.Act == ActChgCrsTT) // If we are editing, all groups are shown Gbl.Action.Act == ActChgCrsTT) // If we are editing, all groups are shown
DB_BuildQuery ("SELECT " NumRows = DB_QuerySELECT (&mysql_res,"can not get timetable",
"Weekday," "SELECT Weekday,"
"TIME_TO_SEC(StartTime) AS S," "TIME_TO_SEC(StartTime) AS S,"
"TIME_TO_SEC(Duration) AS D," "TIME_TO_SEC(Duration) AS D,"
"Place," "Place,"
"ClassType," "ClassType,"
"GroupName," "GroupName,"
"GrpCod" "GrpCod"
" FROM timetable_crs" " FROM timetable_crs"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" ORDER BY Weekday,S,ClassType," " ORDER BY Weekday,S,ClassType,"
"GroupName,GrpCod,Place,D DESC", "GroupName,GrpCod,Place,D DESC",
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);
else else
DB_BuildQuery ("SELECT " NumRows = DB_QuerySELECT (&mysql_res,"can not get timetable",
"timetable_crs.Weekday," "SELECT timetable_crs.Weekday,"
"TIME_TO_SEC(timetable_crs.StartTime) AS S," "TIME_TO_SEC(timetable_crs.StartTime) AS S,"
"TIME_TO_SEC(timetable_crs.Duration) AS D," "TIME_TO_SEC(timetable_crs.Duration) AS D,"
"timetable_crs.Place," "timetable_crs.Place,"
"timetable_crs.ClassType," "timetable_crs.ClassType,"
"timetable_crs.GroupName," "timetable_crs.GroupName,"
"timetable_crs.GrpCod" "timetable_crs.GrpCod"
" FROM timetable_crs,crs_usr" " FROM timetable_crs,crs_usr"
" WHERE timetable_crs.CrsCod=%ld" " WHERE timetable_crs.CrsCod=%ld"
" AND timetable_crs.GrpCod=-1 AND crs_usr.UsrCod=%ld" " AND timetable_crs.GrpCod=-1 AND crs_usr.UsrCod=%ld"
" AND timetable_crs.CrsCod=crs_usr.CrsCod" " AND timetable_crs.CrsCod=crs_usr.CrsCod"
" UNION DISTINCT " " UNION DISTINCT "
"SELECT timetable_crs.Weekday," "SELECT timetable_crs.Weekday,"
"TIME_TO_SEC(timetable_crs.StartTime) AS S," "TIME_TO_SEC(timetable_crs.StartTime) AS S,"
"TIME_TO_SEC(timetable_crs.Duration) AS D," "TIME_TO_SEC(timetable_crs.Duration) AS D,"
"timetable_crs.Place," "timetable_crs.Place,"
"timetable_crs.ClassType," "timetable_crs.ClassType,"
"timetable_crs.GroupName," "timetable_crs.GroupName,"
"timetable_crs.GrpCod" "timetable_crs.GrpCod"
" FROM timetable_crs,crs_grp_usr" " FROM timetable_crs,crs_grp_usr"
" WHERE timetable_crs.CrsCod=%ld" " WHERE timetable_crs.CrsCod=%ld"
" AND crs_grp_usr.UsrCod=%ld" " AND crs_grp_usr.UsrCod=%ld"
" AND timetable_crs.GrpCod=crs_grp_usr.GrpCod" " AND timetable_crs.GrpCod=crs_grp_usr.GrpCod"
" ORDER BY Weekday,S,ClassType," " ORDER BY Weekday,S,ClassType,"
"GroupName,GrpCod,Place,D DESC", "GroupName,GrpCod,Place,D DESC",
Gbl.CurrentCrs.Crs.CrsCod,UsrCod, Gbl.CurrentCrs.Crs.CrsCod,UsrCod,
Gbl.CurrentCrs.Crs.CrsCod,UsrCod); Gbl.CurrentCrs.Crs.CrsCod,UsrCod);
break; break;
case TT_TUTORING_TIMETABLE: case TT_TUTORING_TIMETABLE:
DB_BuildQuery ("SELECT " NumRows = DB_QuerySELECT (&mysql_res,"can not get timetable",
"Weekday," "SELECT Weekday,"
"TIME_TO_SEC(StartTime) AS S," "TIME_TO_SEC(StartTime) AS S,"
"TIME_TO_SEC(Duration) AS D," "TIME_TO_SEC(Duration) AS D,"
"Place" "Place"
" FROM timetable_tut" " FROM timetable_tut"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" ORDER BY Weekday,S,Place,D DESC", " ORDER BY Weekday,S,Place,D DESC",
UsrCod); UsrCod);
break; break;
} }
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get timetable");
/***** If viewing (not editing) ==> /***** If viewing (not editing) ==>
calculate range of hours and resolution *****/ calculate range of hours and resolution *****/

View File

@ -288,8 +288,9 @@ static int Svc_GetPlgCodFromAppKey (const char *appKey)
Gbl.WebService.PlgCod = -1L; Gbl.WebService.PlgCod = -1L;
/***** Get number of plugins with a IP address *****/ /***** Get number of plugins with a IP address *****/
DB_BuildQuery ("SELECT PlgCod FROM plugins WHERE AppKey='%s'",appKey); if (DB_QuerySELECT (&mysql_res,"can not check application key",
if (DB_QuerySELECT_new (&mysql_res,"can not check application key")) // Session found in table of sessions "SELECT PlgCod FROM plugins WHERE AppKey='%s'",
appKey)) // Session found in table of sessions
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -381,8 +382,9 @@ static int Svc_CheckWSKey (char WSKey[Svc_BYTES_WS_KEY + 1])
Gbl.WebService.PlgCod = -1L; Gbl.WebService.PlgCod = -1L;
/***** Check that key does not exist in database *****/ /***** Check that key does not exist in database *****/
DB_BuildQuery ("SELECT UsrCod,PlgCod FROM ws_keys WHERE WSKey='%s'",WSKey); if (DB_QuerySELECT (&mysql_res,"can not get existence of key",
if (DB_QuerySELECT_new (&mysql_res,"can not get existence of key")) // Session found in table of sessions "SELECT UsrCod,PlgCod FROM ws_keys WHERE WSKey='%s'",
WSKey)) // Session found in table of sessions
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -504,9 +506,9 @@ static int Svc_GetCurrentDegCodFromCurrentCrsCod (void)
Gbl.CurrentDeg.Deg.DegCod = -1L; Gbl.CurrentDeg.Deg.DegCod = -1L;
/***** Check that key does not exist in database *****/ /***** Check that key does not exist in database *****/
DB_BuildQuery ("SELECT DegCod FROM courses WHERE CrsCod=%ld", if (DB_QuerySELECT (&mysql_res,"can not get the degree of a course",
Gbl.CurrentCrs.Crs.CrsCod); "SELECT DegCod FROM courses WHERE CrsCod=%ld",
if (DB_QuerySELECT_new (&mysql_res,"can not get the degree of a course")) // Course found in table of courses Gbl.CurrentCrs.Crs.CrsCod)) // Course found in table of courses
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -534,13 +536,10 @@ static bool Svc_GetSomeUsrDataFromUsrCod (struct UsrData *UsrDat,long CrsCod)
return false; return false;
/***** Get some user's data *****/ /***** Get some user's data *****/
/* Query database */ if (DB_QuerySELECT (&mysql_res,"can not get user's data",
DB_BuildQuery ("SELECT Surname1,Surname2,FirstName,Photo,DATE_FORMAT(Birthday,'%%Y%%m%%d')" "SELECT Surname1,Surname2,FirstName,Photo,DATE_FORMAT(Birthday,'%%Y%%m%%d')"
" FROM usr_data WHERE UsrCod=%ld", " FROM usr_data WHERE UsrCod=%ld",
UsrDat->UsrCod); UsrDat->UsrCod) != 1)
/* Check number of rows in result */
if (DB_QuerySELECT_new (&mysql_res,"can not get user's data") != 1)
return false; return false;
/* Read some user's data */ /* Read some user's data */
@ -575,10 +574,10 @@ static bool Svc_GetSomeUsrDataFromUsrCod (struct UsrData *UsrDat,long CrsCod)
if (CrsCod > 0) if (CrsCod > 0)
{ {
/* Get the role in the given course */ /* Get the role in the given course */
DB_BuildQuery ("SELECT Role FROM crs_usr" if (DB_QuerySELECT (&mysql_res,"can not get user's role",
" WHERE CrsCod=%ld AND UsrCod=%ld", "SELECT Role FROM crs_usr"
CrsCod,UsrDat->UsrCod); " WHERE CrsCod=%ld AND UsrCod=%ld",
if (DB_QuerySELECT_new (&mysql_res,"can not get user's role")) // User belongs to course CrsCod,UsrDat->UsrCod)) // User belongs to course
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
if (row[0]) if (row[0])
@ -606,10 +605,10 @@ static bool Svc_GetSomeUsrDataFromUsrCod (struct UsrData *UsrDat,long CrsCod)
else else
{ {
/* Get the maximum role in any course */ /* Get the maximum role in any course */
DB_BuildQuery ("SELECT MAX(Role)" if (DB_QuerySELECT (&mysql_res,"can not get user's role",
" FROM crs_usr WHERE UsrCod=%ld", "SELECT MAX(Role)"
UsrDat->UsrCod); " FROM crs_usr WHERE UsrCod=%ld",
if (DB_QuerySELECT_new (&mysql_res,"can not get user's role") == 1) UsrDat->UsrCod) == 1)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
if (row[0]) if (row[0])
@ -827,23 +826,27 @@ int swad__loginByUserPasswordKey (struct soap *soap,
Str_RemoveLeadingArrobas (UsrIDNickOrEmail); Str_RemoveLeadingArrobas (UsrIDNickOrEmail);
/* User has typed a nickname */ /* User has typed a nickname */
DB_BuildQuery ("SELECT usr_nicknames.UsrCod" NumRows =
" FROM usr_nicknames,usr_data" (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's data",
" WHERE usr_nicknames.Nickname='%s'" "SELECT usr_nicknames.UsrCod"
" AND usr_nicknames.UsrCod=usr_data.UsrCod" " FROM usr_nicknames,usr_data"
" AND usr_data.Password='%s'", " WHERE usr_nicknames.Nickname='%s'"
UsrIDNickOrEmail,userPassword); " AND usr_nicknames.UsrCod=usr_data.UsrCod"
" AND usr_data.Password='%s'",
UsrIDNickOrEmail,userPassword);
} }
else if (Mai_CheckIfEmailIsValid (Gbl.Usrs.Me.UsrIdLogin)) // 2: It's an email else if (Mai_CheckIfEmailIsValid (Gbl.Usrs.Me.UsrIdLogin)) // 2: It's an email
{ {
/* User has typed an email */ /* User has typed an email */
// TODO: Get only if email confirmed? // TODO: Get only if email confirmed?
DB_BuildQuery ("SELECT usr_emails.UsrCod" NumRows =
" FROM usr_emails,usr_data" (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's data",
" WHERE usr_emails.E_mail='%s'" "SELECT usr_emails.UsrCod"
" AND usr_emails.UsrCod=usr_data.UsrCod" " FROM usr_emails,usr_data"
" AND usr_data.Password='%s'", " WHERE usr_emails.E_mail='%s'"
UsrIDNickOrEmail,userPassword); " AND usr_emails.UsrCod=usr_data.UsrCod"
" AND usr_data.Password='%s'",
UsrIDNickOrEmail,userPassword);
} }
else // 3: It's not a nickname nor email else // 3: It's not a nickname nor email
{ {
@ -854,11 +857,14 @@ int swad__loginByUserPasswordKey (struct soap *soap,
{ {
/* User has typed a valid user's ID (existing or not) */ /* User has typed a valid user's ID (existing or not) */
// TODO: Get only if ID confirmed? // TODO: Get only if ID confirmed?
DB_BuildQuery ("SELECT usr_IDs.UsrCod FROM usr_IDs,usr_data" NumRows =
" WHERE usr_IDs.UsrID='%s'" (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's data",
" AND usr_IDs.UsrCod=usr_data.UsrCod" "SELECT usr_IDs.UsrCod"
" AND usr_data.Password='%s'", " FROM usr_IDs,usr_data"
UsrIDNickOrEmail,userPassword); " WHERE usr_IDs.UsrID='%s'"
" AND usr_IDs.UsrCod=usr_data.UsrCod"
" AND usr_data.Password='%s'",
UsrIDNickOrEmail,userPassword);
} }
else // String is not a valid user's nickname, email or ID else // String is not a valid user's nickname, email or ID
return soap_receiver_fault (Gbl.soap, return soap_receiver_fault (Gbl.soap,
@ -867,7 +873,7 @@ int swad__loginByUserPasswordKey (struct soap *soap,
} }
/***** Get user's data from database *****/ /***** Get user's data from database *****/
if ((NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's data")) == 1) // User found in table of users' data if (NumRows == 1) // User found in table of users' data
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1002,10 +1008,12 @@ int swad__loginBySessionKey (struct soap *soap,
// Now, we know that sessionID is a valid session identifier // Now, we know that sessionID is a valid session identifier
/***** Query data of the session from database *****/ /***** Query data of the session from database *****/
DB_BuildQuery ("SELECT UsrCod,DegCod,CrsCod FROM sessions" NumRows =
" WHERE SessionId='%s'", (unsigned) DB_QuerySELECT (&mysql_res,"can not get session data",
sessionID); "SELECT UsrCod,DegCod,CrsCod FROM sessions"
if ((NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get session data")) == 1) // Session found in table of sessions " WHERE SessionId='%s'",
sessionID);
if (NumRows == 1) // Session found in table of sessions
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1116,15 +1124,21 @@ int swad__getNewPassword (struct soap *soap,
Str_RemoveLeadingArrobas (UsrIDNickOrEmail); Str_RemoveLeadingArrobas (UsrIDNickOrEmail);
/* User has typed a nickname */ /* User has typed a nickname */
DB_BuildQuery ("SELECT UsrCod FROM usr_nicknames WHERE Nickname='%s'", NumRows =
UsrIDNickOrEmail); (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's data",
"SELECT UsrCod FROM usr_nicknames"
" WHERE Nickname='%s'",
UsrIDNickOrEmail);
} }
else if (Mai_CheckIfEmailIsValid (Gbl.Usrs.Me.UsrIdLogin)) // 2: It's an email else if (Mai_CheckIfEmailIsValid (Gbl.Usrs.Me.UsrIdLogin)) // 2: It's an email
{ {
/* User has typed an email */ /* User has typed an email */
// TODO: Get only if email confirmed? // TODO: Get only if email confirmed?
DB_BuildQuery ("SELECT UsrCod FROM usr_emails WHERE E_mail='%s'", NumRows =
UsrIDNickOrEmail); (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's data",
"SELECT UsrCod FROM usr_emails"
" WHERE E_mail='%s'",
UsrIDNickOrEmail);
} }
else // 3: It's not a nickname nor email else // 3: It's not a nickname nor email
{ {
@ -1135,8 +1149,11 @@ int swad__getNewPassword (struct soap *soap,
{ {
/* User has typed a valid user's ID (existing or not) */ /* User has typed a valid user's ID (existing or not) */
// TODO: Get only if ID confirmed? // TODO: Get only if ID confirmed?
DB_BuildQuery ("SELECT UsrCod FROM usr_IDs WHERE UsrID='%s'", NumRows =
UsrIDNickOrEmail); (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's data",
"SELECT UsrCod FROM usr_IDs"
" WHERE UsrID='%s'",
UsrIDNickOrEmail);
} }
else // String is not a valid user's nickname, email or ID else // String is not a valid user's nickname, email or ID
return soap_receiver_fault (Gbl.soap, return soap_receiver_fault (Gbl.soap,
@ -1145,7 +1162,7 @@ int swad__getNewPassword (struct soap *soap,
} }
/***** Get user's data from database *****/ /***** Get user's data from database *****/
if ((NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's data")) == 1) // One unique user found in table of users' data if (NumRows == 1) // One unique user found in table of users' data
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1204,11 +1221,17 @@ int swad__getCourses (struct soap *soap,
Gbl.Usrs.Me.Role.Logged = Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role; Gbl.Usrs.Me.Role.Logged = Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role;
/***** Query my courses from database *****/ /***** Query my courses from database *****/
DB_BuildQuery ("SELECT courses.CrsCod,courses.ShortName,courses.FullName,crs_usr.Role FROM crs_usr,courses" NumRows =
" WHERE crs_usr.UsrCod=%ld AND crs_usr.CrsCod=courses.CrsCod" (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's courses",
" ORDER BY courses.FullName", "SELECT courses.CrsCod,"
Gbl.Usrs.Me.UsrDat.UsrCod); "courses.ShortName,"
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's courses"); "courses.FullName,"
"crs_usr.Role"
" FROM crs_usr,courses"
" WHERE crs_usr.UsrCod=%ld"
" AND crs_usr.CrsCod=courses.CrsCod"
" ORDER BY courses.FullName",
Gbl.Usrs.Me.UsrDat.UsrCod);
getCoursesOut->numCourses = (int) NumRows; getCoursesOut->numCourses = (int) NumRows;
getCoursesOut->coursesArray.__size = (int) NumRows; getCoursesOut->coursesArray.__size = (int) NumRows;
@ -1667,12 +1690,17 @@ int swad__getGroupTypes (struct soap *soap,
"Requester must belong to course"); "Requester must belong to course");
/***** Query group types in a course from database *****/ /***** Query group types in a course from database *****/
DB_BuildQuery ("SELECT GrpTypCod,GrpTypName,Mandatory,Multiple,UNIX_TIMESTAMP(OpenTime)" NumRows =
" FROM crs_grp_types" (unsigned) DB_QuerySELECT (&mysql_res,"can not get group types",
" WHERE CrsCod=%d" "SELECT GrpTypCod,"
" ORDER BY GrpTypName", "GrpTypName,"
courseCode); "Mandatory,"
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get group types"); "Multiple,"
"UNIX_TIMESTAMP(OpenTime)"
" FROM crs_grp_types"
" WHERE CrsCod=%d"
" ORDER BY GrpTypName",
courseCode);
getGroupTypesOut->numGroupTypes = (int) NumRows; getGroupTypesOut->numGroupTypes = (int) NumRows;
getGroupTypesOut->groupTypesArray.__size = (int) NumRows; getGroupTypesOut->groupTypesArray.__size = (int) NumRows;
@ -1775,15 +1803,21 @@ int swad__getGroups (struct soap *soap,
"Requester must belong to course"); "Requester must belong to course");
/***** Query groups in a course from database *****/ /***** Query groups in a course from database *****/
DB_BuildQuery ("SELECT crs_grp_types.GrpTypCod,crs_grp_types.GrpTypName," NumRows =
"crs_grp.GrpCod,crs_grp.GrpName," (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's groups",
"crs_grp.MaxStudents,crs_grp.Open,crs_grp.FileZones" "SELECT crs_grp_types.GrpTypCod,"
" FROM crs_grp_types,crs_grp" "crs_grp_types.GrpTypName,"
" WHERE crs_grp_types.CrsCod=%d" "crs_grp.GrpCod,"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" "crs_grp.GrpName,"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName", "crs_grp.MaxStudents,"
courseCode); "crs_grp.Open,"
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's groups"); "crs_grp.FileZones"
" FROM crs_grp_types,crs_grp"
" WHERE crs_grp_types.CrsCod=%d"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" ORDER BY crs_grp_types.GrpTypName,"
"crs_grp.GrpName",
courseCode);
getGroupsOut->numGroups = (int) NumRows; getGroupsOut->numGroups = (int) NumRows;
getGroupsOut->groupsArray.__size = (int) NumRows; getGroupsOut->groupsArray.__size = (int) NumRows;
@ -1861,7 +1895,8 @@ int swad__sendMyGroups (struct soap *soap,
unsigned NumGrp; unsigned NumGrp;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumRow,NumRows; unsigned NumRow;
unsigned NumRows;
long GrpCod; long GrpCod;
unsigned MaxStudents; unsigned MaxStudents;
@ -1936,15 +1971,20 @@ int swad__sendMyGroups (struct soap *soap,
Grp_FreeListCodGrp (&LstGrpsIWant); Grp_FreeListCodGrp (&LstGrpsIWant);
/***** Query groups in a course from database *****/ /***** Query groups in a course from database *****/
DB_BuildQuery ("SELECT crs_grp_types.GrpTypCod,crs_grp_types.GrpTypName," NumRows =
"crs_grp.GrpCod,crs_grp.GrpName," (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's groups",
"crs_grp.MaxStudents,crs_grp.Open,crs_grp.FileZones" "SELECT crs_grp_types.GrpTypCod,"
" FROM crs_grp_types,crs_grp" "crs_grp_types.GrpTypName,"
" WHERE crs_grp_types.CrsCod=%d" "crs_grp.GrpCod,"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" "crs_grp.GrpName,"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName", "crs_grp.MaxStudents,"
courseCode); "crs_grp.Open,"
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's groups"); "crs_grp.FileZones"
" FROM crs_grp_types,crs_grp"
" WHERE crs_grp_types.CrsCod=%d"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName",
courseCode);
SendMyGroupsOut->numGroups = (int) NumRows; SendMyGroupsOut->numGroups = (int) NumRows;
SendMyGroupsOut->groupsArray.__size = (int) NumRows; SendMyGroupsOut->groupsArray.__size = (int) NumRows;
@ -2073,6 +2113,7 @@ int swad__getAttendanceEvents (struct soap *soap,
int ReturnCode; int ReturnCode;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumRows;
int NumAttEvent; int NumAttEvent;
long AttCod; long AttCod;
char PhotoURL[Cns_MAX_BYTES_WWW + 1]; char PhotoURL[Cns_MAX_BYTES_WWW + 1];
@ -2114,16 +2155,19 @@ int swad__getAttendanceEvents (struct soap *soap,
"Requester must be a teacher"); "Requester must be a teacher");
/***** Query list of attendance events *****/ /***** Query list of attendance events *****/
DB_BuildQuery ("SELECT AttCod,Hidden,UsrCod," NumRows =
"UNIX_TIMESTAMP(StartTime) AS ST," (unsigned) DB_QuerySELECT (&mysql_res,"can not get attendance events",
"UNIX_TIMESTAMP(EndTime) AS ET," "SELECT AttCod,Hidden,UsrCod,"
"CommentTchVisible,Title,Txt" "UNIX_TIMESTAMP(StartTime) AS ST,"
" FROM att_events" "UNIX_TIMESTAMP(EndTime) AS ET,"
" WHERE CrsCod=%d" "CommentTchVisible,Title,Txt"
" ORDER BY ST DESC,ET DESC,Title DESC", " FROM att_events"
courseCode); " WHERE CrsCod=%d"
" ORDER BY ST DESC,ET DESC,Title DESC",
courseCode);
getAttendanceEventsOut->eventsArray.__size = getAttendanceEventsOut->eventsArray.__size =
getAttendanceEventsOut->numEvents = (int) DB_QuerySELECT_new (&mysql_res,"can not get attendance events"); getAttendanceEventsOut->numEvents = (int) NumRows;
if (getAttendanceEventsOut->numEvents == 0) if (getAttendanceEventsOut->numEvents == 0)
getAttendanceEventsOut->eventsArray.__ptr = NULL; getAttendanceEventsOut->eventsArray.__ptr = NULL;
@ -2237,9 +2281,12 @@ static void Svc_GetListGrpsInAttendanceEventFromDB (long AttCod,char **ListGroup
size_t Length; size_t Length;
/***** Get list of groups *****/ /***** Get list of groups *****/
DB_BuildQuery ("SELECT GrpCod FROM att_grp WHERE AttCod=%ld", NumGrps =
AttCod); (unsigned) DB_QuerySELECT (&mysql_res,"can not get groups"
if ((NumGrps = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get groups of an attendance event")) == 0) " of an attendance event",
"SELECT GrpCod FROM att_grp WHERE AttCod=%ld",
AttCod);
if (NumGrps == 0)
*ListGroups = NULL; *ListGroups = NULL;
else // Events found else // Events found
{ {
@ -2566,14 +2613,18 @@ int swad__getAttendanceUsers (struct soap *soap,
(unsigned) Rol_STD, (unsigned) Rol_STD,
Att.AttCod); Att.AttCod);
// Query: list of users in attendance list + rest of users (subquery) // Query: list of users in attendance list + rest of users (subquery)
DB_BuildQuery ("SELECT u.UsrCod,u.Present FROM " NumRows =
"(SELECT UsrCod,Present" (unsigned) DB_QuerySELECT (&mysql_res,"can not get users"
" FROM att_usr WHERE AttCod=%ld" " in an attendance event",
" UNION %s) AS u,usr_data" "SELECT u.UsrCod,u.Present FROM "
" WHERE u.UsrCod=usr_data.UsrCod" "(SELECT UsrCod,Present"
" ORDER BY usr_data.Surname1,usr_data.Surname2,usr_data.FirstName", " FROM att_usr WHERE AttCod=%ld"
(long) attendanceEventCode,SubQuery); " UNION %s) AS u,usr_data"
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get users in an attendance event"); " WHERE u.UsrCod=usr_data.UsrCod"
" ORDER BY usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName",
(long) attendanceEventCode,SubQuery);
getAttendanceUsersOut->numUsers = (int) NumRows; getAttendanceUsersOut->numUsers = (int) NumRows;
getAttendanceUsersOut->usersArray.__size = (int) NumRows; getAttendanceUsersOut->usersArray.__size = (int) NumRows;
@ -2853,13 +2904,23 @@ int swad__getNotifications (struct soap *soap,
return ReturnCode; return ReturnCode;
/***** Get my notifications from database *****/ /***** Get my notifications from database *****/
DB_BuildQuery ("SELECT NtfCod,NotifyEvent,UNIX_TIMESTAMP(TimeNotif)," NumNotifications =
"FromUsrCod,InsCod,CtrCod,DegCod,CrsCod,Cod,Status" (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's notifications",
" FROM notif" "SELECT NtfCod," // row[0]
" WHERE ToUsrCod=%ld AND TimeNotif>=FROM_UNIXTIME(%ld)" "NotifyEvent," // row[1]
" ORDER BY TimeNotif DESC", "UNIX_TIMESTAMP(TimeNotif)," // row[2]
Gbl.Usrs.Me.UsrDat.UsrCod,beginTime); "FromUsrCod," // row[3]
NumNotifications = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's notifications"); "InsCod," // row[4]
"CtrCod," // row[5]
"DegCod," // row[6]
"CrsCod," // row[7]
"Cod," // row[8]
"Status" // row[9]
" FROM notif"
" WHERE ToUsrCod=%ld AND TimeNotif>=FROM_UNIXTIME(%ld)"
" ORDER BY TimeNotif DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,beginTime);
if (NumNotifications) // Notifications found if (NumNotifications) // Notifications found
{ {
getNotificationsOut->numNotifications = (int) NumNotifications; getNotificationsOut->numNotifications = (int) NumNotifications;
@ -3039,10 +3100,10 @@ static int Svc_GetMyLanguage (void)
Txt_Language_t Lan; Txt_Language_t Lan;
/***** Get user's language *****/ /***** Get user's language *****/
DB_BuildQuery ("SELECT Language FROM usr_data" if (DB_QuerySELECT (&mysql_res,"can not get user's language",
" WHERE UsrCod=%ld", "SELECT Language FROM usr_data"
Gbl.Usrs.Me.UsrDat.UsrCod); " WHERE UsrCod=%ld",
if (DB_QuerySELECT_new (&mysql_res,"can not get user's language") != 1) Gbl.Usrs.Me.UsrDat.UsrCod) != 1)
return soap_receiver_fault (Gbl.soap, return soap_receiver_fault (Gbl.soap,
"Can not get user's language from database", "Can not get user's language from database",
"User doen't exist in database"); "User doen't exist in database");
@ -3181,15 +3242,15 @@ int swad__sendMessage (struct soap *soap,
if (messageCode) if (messageCode)
{ {
/***** Check if the original message was really received by me *****/ /***** Check if the original message was really received by me *****/
DB_BuildQuery ("SELECT SUM(N) FROM" if (!DB_QuerySELECT (&mysql_res,"can not check original message",
" (SELECT COUNT(*) AS N FROM msg_rcv" "SELECT SUM(N) FROM"
" WHERE UsrCod=%ld AND MsgCod=%ld" " (SELECT COUNT(*) AS N FROM msg_rcv"
" UNION" " WHERE UsrCod=%ld AND MsgCod=%ld"
" SELECT COUNT(*) AS N FROM msg_rcv_deleted" " UNION"
" WHERE UsrCod=%ld AND MsgCod=%ld) AS T", " SELECT COUNT(*) AS N FROM msg_rcv_deleted"
Gbl.Usrs.Me.UsrDat.UsrCod,(long) messageCode, " WHERE UsrCod=%ld AND MsgCod=%ld) AS T",
Gbl.Usrs.Me.UsrDat.UsrCod,(long) messageCode); Gbl.Usrs.Me.UsrDat.UsrCod,(long) messageCode,
if (!DB_QuerySELECT_new (&mysql_res,"can not check original message")) Gbl.Usrs.Me.UsrDat.UsrCod,(long) messageCode))
return soap_sender_fault (Gbl.soap, return soap_sender_fault (Gbl.soap,
"Can not check original message", "Can not check original message",
"Error reading from database"); "Error reading from database");
@ -3210,13 +3271,15 @@ int swad__sendMessage (struct soap *soap,
"Original message does not exist"); "Original message does not exist");
/***** Get the recipient of the message *****/ /***** Get the recipient of the message *****/
DB_BuildQuery ("SELECT UsrCod FROM msg_snt" NumRows =
" WHERE MsgCod=%ld" (unsigned) DB_QuerySELECT (&mysql_res,"can not check original message",
" UNION " "SELECT UsrCod FROM msg_snt"
"SELECT UsrCod FROM msg_snt_deleted" " WHERE MsgCod=%ld"
" WHERE MsgCod=%ld", " UNION "
(long) messageCode,(long) messageCode); "SELECT UsrCod FROM msg_snt_deleted"
if ((NumRows = DB_QuerySELECT_new (&mysql_res,"can not check original message"))) // Message found in any of the two tables of sent messages " WHERE MsgCod=%ld",
(long) messageCode,(long) messageCode);
if (NumRows) // Message found in any of the two tables of sent messages
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
ReplyUsrCod = Str_ConvertStrCodToLongCod (row[0]); ReplyUsrCod = Str_ConvertStrCodToLongCod (row[0]);
@ -3571,10 +3634,10 @@ static int Svc_GetTstConfig (long CrsCod)
MYSQL_ROW row; MYSQL_ROW row;
/***** Query database *****/ /***** Query database *****/
DB_BuildQuery ("SELECT Pluggable,Min,Def,Max,MinTimeNxtTstPerQst,Feedback" if (DB_QuerySELECT (&mysql_res,"can not get test configuration",
" FROM tst_config WHERE CrsCod=%ld", "SELECT Pluggable,Min,Def,Max,MinTimeNxtTstPerQst,Feedback"
CrsCod); " FROM tst_config WHERE CrsCod=%ld",
if (DB_QuerySELECT_new (&mysql_res,"can not get test configuration")) CrsCod))
{ {
/***** Get minimun, default and maximum *****/ /***** Get minimun, default and maximum *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3714,12 +3777,12 @@ static int Svc_GetTstTags (long CrsCod,struct swad__getTestsOutput *getTestsOut)
unsigned NumRows; unsigned NumRows;
/***** Get available tags from database *****/ /***** Get available tags from database *****/
DB_BuildQuery ("SELECT TagCod,TagTxt" NumRows = DB_QuerySELECT (&mysql_res,"can not get test tags",
" FROM tst_tags" "SELECT TagCod,TagTxt"
" WHERE CrsCod=%ld AND TagHidden='N'" " FROM tst_tags"
" ORDER BY TagTxt", " WHERE CrsCod=%ld AND TagHidden='N'"
CrsCod); " ORDER BY TagTxt",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get test tags"); CrsCod);
getTestsOut->tagsArray.__size = (int) NumRows; getTestsOut->tagsArray.__size = (int) NumRows;
@ -3767,29 +3830,30 @@ static int Svc_GetTstQuestions (long CrsCod,long BeginTime,struct swad__getTests
/***** Get recent test questions from database *****/ /***** Get recent test questions from database *****/
// DISTINCTROW is necessary to not repeat questions // DISTINCTROW is necessary to not repeat questions
DB_BuildQuery ("SELECT DISTINCTROW tst_questions.QstCod," NumRows =
"tst_questions.AnsType,tst_questions.Shuffle," (unsigned) DB_QuerySELECT (&mysql_res,"can not get test questions",
"tst_questions.Stem,tst_questions.Feedback" "SELECT DISTINCTROW tst_questions.QstCod,"
" FROM tst_questions,tst_question_tags,tst_tags" "tst_questions.AnsType,tst_questions.Shuffle,"
" WHERE tst_questions.CrsCod=%ld" "tst_questions.Stem,tst_questions.Feedback"
" AND tst_questions.QstCod NOT IN" " FROM tst_questions,tst_question_tags,tst_tags"
" (SELECT tst_question_tags.QstCod FROM tst_tags,tst_question_tags" " WHERE tst_questions.CrsCod=%ld"
" WHERE tst_tags.CrsCod=%ld AND tst_tags.TagHidden='Y'" " AND tst_questions.QstCod NOT IN"
" AND tst_tags.TagCod=tst_question_tags.TagCod)" " (SELECT tst_question_tags.QstCod FROM tst_tags,tst_question_tags"
" AND tst_questions.QstCod=tst_question_tags.QstCod" " WHERE tst_tags.CrsCod=%ld AND tst_tags.TagHidden='Y'"
" AND tst_question_tags.TagCod=tst_tags.TagCod" " AND tst_tags.TagCod=tst_question_tags.TagCod)"
" AND tst_tags.CrsCod=%ld" " AND tst_questions.QstCod=tst_question_tags.QstCod"
" AND " " AND tst_question_tags.TagCod=tst_tags.TagCod"
"(" " AND tst_tags.CrsCod=%ld"
"tst_questions.EditTime>=FROM_UNIXTIME(%ld)" " AND "
" OR " "("
"tst_tags.ChangeTime>=FROM_UNIXTIME(%ld)" "tst_questions.EditTime>=FROM_UNIXTIME(%ld)"
")" " OR "
" ORDER BY QstCod", "tst_tags.ChangeTime>=FROM_UNIXTIME(%ld)"
CrsCod,CrsCod,CrsCod, ")"
BeginTime, " ORDER BY QstCod",
BeginTime); CrsCod,CrsCod,CrsCod,
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get test questions"); BeginTime,
BeginTime);
getTestsOut->questionsArray.__size = (int) NumRows; getTestsOut->questionsArray.__size = (int) NumRows;
@ -3851,30 +3915,31 @@ static int Svc_GetTstAnswers (long CrsCod,long BeginTime,struct swad__getTestsOu
unsigned Index; unsigned Index;
/***** Get recent test questions from database *****/ /***** Get recent test questions from database *****/
DB_BuildQuery ("SELECT QstCod,AnsInd,Correct,Answer,Feedback" NumRows =
" FROM tst_answers WHERE QstCod IN " (unsigned) DB_QuerySELECT (&mysql_res,"can not get test answers",
"(SELECT tst_questions.QstCod" "SELECT QstCod,AnsInd,Correct,Answer,Feedback"
" FROM tst_questions,tst_question_tags,tst_tags" " FROM tst_answers WHERE QstCod IN "
" WHERE tst_questions.CrsCod=%ld" "(SELECT tst_questions.QstCod"
" AND tst_questions.QstCod NOT IN" " FROM tst_questions,tst_question_tags,tst_tags"
" (SELECT tst_question_tags.QstCod FROM tst_tags,tst_question_tags" " WHERE tst_questions.CrsCod=%ld"
" WHERE tst_tags.CrsCod=%ld AND tst_tags.TagHidden='Y'" " AND tst_questions.QstCod NOT IN"
" AND tst_tags.TagCod=tst_question_tags.TagCod)" " (SELECT tst_question_tags.QstCod FROM tst_tags,tst_question_tags"
" AND tst_questions.QstCod=tst_question_tags.QstCod" " WHERE tst_tags.CrsCod=%ld AND tst_tags.TagHidden='Y'"
" AND tst_question_tags.TagCod=tst_tags.TagCod" " AND tst_tags.TagCod=tst_question_tags.TagCod)"
" AND tst_tags.CrsCod=%ld" " AND tst_questions.QstCod=tst_question_tags.QstCod"
" AND " " AND tst_question_tags.TagCod=tst_tags.TagCod"
"(" " AND tst_tags.CrsCod=%ld"
"tst_questions.EditTime>=FROM_UNIXTIME(%ld)" " AND "
" OR " "("
"tst_tags.ChangeTime>=FROM_UNIXTIME(%ld)" "tst_questions.EditTime>=FROM_UNIXTIME(%ld)"
")" " OR "
")" "tst_tags.ChangeTime>=FROM_UNIXTIME(%ld)"
" ORDER BY QstCod,AnsInd", ")"
CrsCod,CrsCod,CrsCod, ")"
BeginTime, " ORDER BY QstCod,AnsInd",
BeginTime); CrsCod,CrsCod,CrsCod,
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get test answers"); BeginTime,
BeginTime);
getTestsOut->answersArray.__size = (int) NumRows; getTestsOut->answersArray.__size = (int) NumRows;
@ -3935,30 +4000,31 @@ static int Svc_GetTstQuestionTags (long CrsCod,long BeginTime,struct swad__getTe
unsigned Index; unsigned Index;
/***** Get recent test questions from database *****/ /***** Get recent test questions from database *****/
DB_BuildQuery ("SELECT QstCod,TagCod,TagInd" NumRows =
" FROM tst_question_tags WHERE QstCod IN " (unsigned) DB_QuerySELECT (&mysql_res,"can not get test question tags",
"(SELECT tst_questions.QstCod" "SELECT QstCod,TagCod,TagInd"
" FROM tst_questions,tst_question_tags,tst_tags" " FROM tst_question_tags WHERE QstCod IN "
" WHERE tst_questions.CrsCod=%ld" "(SELECT tst_questions.QstCod"
" AND tst_questions.QstCod NOT IN" " FROM tst_questions,tst_question_tags,tst_tags"
" (SELECT tst_question_tags.QstCod FROM tst_tags,tst_question_tags" " WHERE tst_questions.CrsCod=%ld"
" WHERE tst_tags.CrsCod=%ld AND tst_tags.TagHidden='Y'" " AND tst_questions.QstCod NOT IN"
" AND tst_tags.TagCod=tst_question_tags.TagCod)" " (SELECT tst_question_tags.QstCod FROM tst_tags,tst_question_tags"
" AND tst_questions.QstCod=tst_question_tags.QstCod" " WHERE tst_tags.CrsCod=%ld AND tst_tags.TagHidden='Y'"
" AND tst_question_tags.TagCod=tst_tags.TagCod" " AND tst_tags.TagCod=tst_question_tags.TagCod)"
" AND tst_tags.CrsCod=%ld" " AND tst_questions.QstCod=tst_question_tags.QstCod"
" AND " " AND tst_question_tags.TagCod=tst_tags.TagCod"
"(" " AND tst_tags.CrsCod=%ld"
"tst_questions.EditTime>=FROM_UNIXTIME(%ld)" " AND "
" OR " "("
"tst_tags.ChangeTime>=FROM_UNIXTIME(%ld)" "tst_questions.EditTime>=FROM_UNIXTIME(%ld)"
")" " OR "
")" "tst_tags.ChangeTime>=FROM_UNIXTIME(%ld)"
" ORDER BY QstCod,TagInd", ")"
CrsCod,CrsCod,CrsCod, ")"
BeginTime, " ORDER BY QstCod,TagInd",
BeginTime); CrsCod,CrsCod,CrsCod,
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get test question tags"); BeginTime,
BeginTime);
getTestsOut->questionTagsArray.__size = (int) NumRows; getTestsOut->questionTagsArray.__size = (int) NumRows;
@ -4095,30 +4161,30 @@ int swad__getTrivialQuestion (struct soap *soap,
/***** Start query *****/ /***** Start query *****/
Str_SetDecimalPointToUS (); // To print the floating point as a dot Str_SetDecimalPointToUS (); // To print the floating point as a dot
DB_BuildQuery ("SELECT DISTINCTROW tst_questions.QstCod," NumRows =
"tst_questions.AnsType,tst_questions.Shuffle," (unsigned) DB_QuerySELECT (&mysql_res,"can not get test questions",
"tst_questions.Stem,tst_questions.Feedback," "SELECT DISTINCTROW tst_questions.QstCod,"
"tst_questions.Score/tst_questions.NumHits AS S" "tst_questions.AnsType,tst_questions.Shuffle,"
" FROM courses,tst_questions" "tst_questions.Stem,tst_questions.Feedback,"
" WHERE courses.DegCod IN (%s)" "tst_questions.Score/tst_questions.NumHits AS S"
" AND courses.CrsCod=tst_questions.CrsCod" " FROM courses,tst_questions"
" AND tst_questions.AnsType='unique_choice'" " WHERE courses.DegCod IN (%s)"
" AND tst_questions.NumHits>0" " AND courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.QstCod NOT IN" " AND tst_questions.AnsType='unique_choice'"
" (SELECT tst_question_tags.QstCod" " AND tst_questions.NumHits>0"
" FROM courses,tst_tags,tst_question_tags" " AND tst_questions.QstCod NOT IN"
" WHERE courses.DegCod IN (%s)" " (SELECT tst_question_tags.QstCod"
" AND courses.CrsCod=tst_tags.CrsCod" " FROM courses,tst_tags,tst_question_tags"
" AND tst_tags.TagHidden='Y'" " WHERE courses.DegCod IN (%s)"
" AND tst_tags.TagCod=tst_question_tags.TagCod)" " AND courses.CrsCod=tst_tags.CrsCod"
" HAVING S>='%f' AND S<='%f'" " AND tst_tags.TagHidden='Y'"
" ORDER BY RAND(NOW()) LIMIT 1", " AND tst_tags.TagCod=tst_question_tags.TagCod)"
DegreesStr,DegreesStr, " HAVING S>='%f' AND S<='%f'"
lowerScore,upperScore); " ORDER BY RAND(NOW()) LIMIT 1",
DegreesStr,DegreesStr,
lowerScore,upperScore);
Str_SetDecimalPointToLocal (); // Return to local system Str_SetDecimalPointToLocal (); // Return to local system
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get test questions");
if (NumRows == 1) // Question found if (NumRows == 1) // Question found
{ {
/* /*
@ -4184,11 +4250,12 @@ int swad__getTrivialQuestion (struct soap *soap,
if (QstCod > 0) if (QstCod > 0)
{ {
/***** Get answer from database *****/ /***** Get answer from database *****/
DB_BuildQuery ("SELECT QstCod,AnsInd,Correct,Answer,Feedback" NumRows =
" FROM tst_answers WHERE QstCod=%ld" (unsigned) DB_QuerySELECT (&mysql_res,"can not get test answers",
" ORDER BY AnsInd", "SELECT QstCod,AnsInd,Correct,Answer,Feedback"
QstCod); " FROM tst_answers WHERE QstCod=%ld"
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get test answers"); " ORDER BY AnsInd",
QstCod);
getTrivialQuestionOut->answersArray.__size = (int) NumRows; getTrivialQuestionOut->answersArray.__size = (int) NumRows;