From 0219949cd4b987cc71b92e59b780b5e8eb9b21d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Sun, 2 Jul 2017 19:46:53 +0200 Subject: [PATCH] Version 16.247.4 --- swad_changelog.h | 7 +++---- swad_survey.c | 38 +++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 76c95e55f..c7e262772 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -231,23 +231,22 @@ // TODO: Fix bug: Error when a link end in a dot. Example: "A guide to building..." --> "A guide to building._..url" (two dots) // TODO: Cuando sólo se cambian los grupos y no el rol de un profesor ya existente, no sale ningún mensaje. se haga lo que se haga en la edición debería salir un mensaje del tipo "Cambios realizados" +// TODO: Al inscribir un profesor, en la ficha de confirmación aparece como rol "Desconocido" en lugar de "Profesor" // TODO: Al buscar asignaturas, Estudiantes y Profesores están al revés -// !!!!!!!!!!!!!!!!!!!!!!!!! -// BUG!!!! Al ver resultados de una encuesta: "Space allocated to string is full." - /*****************************************************************************/ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.247.3 (2017-07-02)" +#define Log_PLATFORM_VERSION "SWAD 16.247.4 (2017-07-02)" #define CSS_FILE "swad16.235.1.css" #define JS_FILE "swad16.206.3.js" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1 /* + Version 16.247.4: Jul 02, 2017 Fixed bug in surveys. (222138 lines) Version 16.247.3: Jul 02, 2017 Students can not view records of some users who do not share groups with them. (222132 lines) Version 16.247.2: Jun 23, 2017 Non-editing teachers can not view records of some users who do not share groups with them. Code refactoring related with roles. (222094 lines) diff --git a/swad_survey.c b/swad_survey.c index 79dd8dc8d..d33e897da 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -138,7 +138,7 @@ static void Svy_RemAnswersOfAQuestion (long QstCod); static Svy_AnswerType_t Svy_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeBD); static bool Svy_CheckIfAnswerExists (long QstCod,unsigned AnsInd); static unsigned Svy_GetAnswersQst (long QstCod,MYSQL_RES **mysql_res); -static int Svy_AllocateTextChoiceAnswer (struct SurveyQuestion *SvyQst,unsigned NumAns); +static bool Svy_AllocateTextChoiceAnswer (struct SurveyQuestion *SvyQst,unsigned NumAns); static void Svy_FreeTextChoiceAnswers (struct SurveyQuestion *SvyQst,unsigned NumAnswers); static void Svy_FreeTextChoiceAnswer (struct SurveyQuestion *SvyQst,unsigned NumAns); @@ -392,6 +392,9 @@ void Svy_SeeOneSurvey (void) struct Survey Svy; struct SurveyQuestion SvyQst; + /***** Initialize question to zero *****/ + Svy_InitQst (&SvyQst); + /***** Get parameters *****/ Svy_GetParamSvyOrder (); Grp_GetParamWhichGrps (); @@ -2871,16 +2874,16 @@ static unsigned Svy_GetAnswersQst (long QstCod,MYSQL_RES **mysql_res) /******************* Allocate memory for a choice answer *********************/ /*****************************************************************************/ -static int Svy_AllocateTextChoiceAnswer (struct SurveyQuestion *SvyQst,unsigned NumAns) +static bool Svy_AllocateTextChoiceAnswer (struct SurveyQuestion *SvyQst,unsigned NumAns) { Svy_FreeTextChoiceAnswer (SvyQst,NumAns); if ((SvyQst->AnsChoice[NumAns].Text = malloc (Svy_MAX_BYTES_ANSWER + 1)) == NULL) { sprintf (Gbl.Alert.Txt,"Not enough memory to store answer."); - return 0; + return false; } SvyQst->AnsChoice[NumAns].Text[0] = '\0'; - return 1; + return true; } /*****************************************************************************/ @@ -2956,7 +2959,8 @@ void Svy_ReceiveQst (void) NumAns < Svy_MAX_ANSWERS_PER_QUESTION; NumAns++) { - Svy_AllocateTextChoiceAnswer (&SvyQst,NumAns); + if (!Svy_AllocateTextChoiceAnswer (&SvyQst,NumAns)) + Lay_ShowErrorAndExit (Gbl.Alert.Txt); sprintf (AnsStr,"AnsStr%u",NumAns); Par_GetParToHTML (AnsStr,SvyQst.AnsChoice[NumAns].Text,Svy_MAX_BYTES_ANSWER); } @@ -3364,14 +3368,18 @@ static void Svy_WriteAnswersOfAQst (struct Survey *Svy,struct SurveyQuestion *Sv MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumUsrsThisAnswer; - char *Answer; - size_t AnsLength; + /***** Get answers of this question *****/ NumAnswers = Svy_GetAnswersQst (SvyQst->QstCod,&mysql_res); // Result: AnsInd,NumUsrs,Answer /***** Write the answers *****/ if (NumAnswers) { + /* Check number of answers */ + if (NumAnswers > Svy_MAX_ANSWERS_PER_QUESTION) + Lay_ShowErrorAndExit ("Wrong number of answers."); + + /* Write one row for each answer */ Tbl_StartTable (5); for (NumAns = 0; NumAns < NumAnswers; @@ -3384,13 +3392,12 @@ static void Svy_WriteAnswersOfAQst (struct Survey *Svy,struct SurveyQuestion *Sv Lay_ShowErrorAndExit ("Error when getting number of users who have marked an answer."); /* Convert the answer (row[2]), that is in HTML, to rigorous HTML */ - AnsLength = strlen (row[2]); - if ((Answer = malloc (AnsLength + 1)) == NULL) - Lay_ShowErrorAndExit ("Not enough memory to store answer."); - Str_Copy (Answer,row[2], - AnsLength); + if (!Svy_AllocateTextChoiceAnswer (SvyQst,NumAns)) + Lay_ShowErrorAndExit (Gbl.Alert.Txt); + Str_Copy (SvyQst->AnsChoice[NumAns].Text,row[2], + Svy_MAX_BYTES_ANSWER); Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - Answer,AnsLength,false); + SvyQst->AnsChoice[NumAns].Text,Svy_MAX_BYTES_ANSWER,false); /* Selectors and label with the letter of the answer */ fprintf (Gbl.F.Out,""); @@ -3425,7 +3432,8 @@ static void Svy_WriteAnswersOfAQst (struct Survey *Svy,struct SurveyQuestion *Sv fprintf (Gbl.F.Out,"" "" "", - (unsigned) SvyQst->QstCod,NumAns,Answer); + (unsigned) SvyQst->QstCod,NumAns, + SvyQst->AnsChoice[NumAns].Text); /* Show stats of this answer */ if (Svy->Status.ICanViewResults) @@ -3434,7 +3442,7 @@ static void Svy_WriteAnswersOfAQst (struct Survey *Svy,struct SurveyQuestion *Sv fprintf (Gbl.F.Out,""); /* Free memory allocated for the answer */ - free ((void *) Answer); + Svy_FreeTextChoiceAnswer (SvyQst,NumAns); } Tbl_EndTable (); }