From dce912d16fdd01558e1b3a11d166e9e071e19732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Wed, 30 Mar 2016 01:28:58 +0200 Subject: [PATCH] Version 15.166 --- swad_action.c | 2 +- swad_changelog.h | 4 +++- swad_file.c | 18 +++++++++++++++++- swad_global.h | 1 + swad_parameter.c | 45 ++++++++++++++++++++++++++++++++------------- swad_test.c | 37 +++++++++++++++++++++++++++++-------- 6 files changed, 83 insertions(+), 24 deletions(-) diff --git a/swad_action.c b/swad_action.c index 4dcc24832..00a8064ea 100644 --- a/swad_action.c +++ b/swad_action.c @@ -2065,7 +2065,7 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActReqImpTstQst */{1007,-1,TabAss,ActReqTst ,0x110,0x100,0x000,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,TsI_ShowFormImportQstsFromXML ,NULL}, /* ActImpTstQst */{1008,-1,TabAss,ActReqTst ,0x110,0x100,0x000,Act_CONTENT_DATA,Act_MAIN_WINDOW,NULL ,TsI_ImportQstsFromXML ,NULL}, /* ActLstTstQst */{ 132,-1,TabAss,ActReqTst ,0x110,0x100,0x000,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Tst_ListQuestionsToEdit ,NULL}, - /* ActRcvTstQst */{ 126,-1,TabAss,ActReqTst ,0x110,0x100,0x000,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Tst_ReceiveQst ,NULL}, + /* ActRcvTstQst */{ 126,-1,TabAss,ActReqTst ,0x110,0x100,0x000,Act_CONTENT_DATA,Act_MAIN_WINDOW,NULL ,Tst_ReceiveQst ,NULL}, /* ActRemTstQst */{ 133,-1,TabAss,ActReqTst ,0x110,0x100,0x000,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Tst_RemoveQst ,NULL}, /* ActShfTstQst */{ 455,-1,TabAss,ActReqTst ,0x110,0x100,0x000,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Tst_ChangeShuffleQst ,NULL}, diff --git a/swad_changelog.h b/swad_changelog.h index 6775b85f6..f59530ed1 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -135,13 +135,15 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.165.8 (2016-03-29)" +#define Log_PLATFORM_VERSION "SWAD 15.166 (2016-03-29)" #define CSS_FILE "swad15.165.5.css" #define JS_FILE "swad15.131.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 15.166: Mar 30, 2016 Changes in form to edit a test question. + Fixed bug while reading a parameter. (196943 lines) Version 15.165.8: Mar 30, 2016 Changes related to image in test questions. (196896 lines) Version 15.165.7: Mar 29, 2016 New field for image in database table of test questions. (196879 lines) 1 change necessary in database: diff --git a/swad_file.c b/swad_file.c index fd7accaad..8095265d0 100644 --- a/swad_file.c +++ b/swad_file.c @@ -163,6 +163,21 @@ bool Fil_ReadStdinIntoTmpFile (void) } rewind (Gbl.F.Tmp); +/* For debug + FILE *FileTgt; + + ***** Open destination file ***** + if ((FileTgt = fopen ("/tmp/borrame.txt","wb")) == NULL) + Lay_ShowErrorAndExit ("Can not open target file."); + + ***** Copy source file into destination file ***** + Fil_FastCopyOfOpenFiles (Gbl.F.Tmp,FileTgt); + + ***** Close the files ***** + rewind (Gbl.F.Tmp); + fclose (FileTgt); +*/ + return true; } @@ -460,7 +475,8 @@ void Fil_RemoveOldTmpFiles (const char *Path,time_t TimeToRemove,bool RemoveDire void Fil_FastCopyOfFiles (const char *PathSrc,const char *PathTgt) { - FILE *FileSrc,*FileTgt; + FILE *FileSrc; + FILE *FileTgt; /***** Open source file *****/ if ((FileSrc = fopen (PathSrc,"rb")) == NULL) diff --git a/swad_global.h b/swad_global.h index a884c9e46..0da993d76 100644 --- a/swad_global.h +++ b/swad_global.h @@ -642,6 +642,7 @@ struct Globals char *Text; size_t Length; } Stem, Feedback; + char Image[Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64+1]; bool Shuffle; struct { diff --git a/swad_parameter.c b/swad_parameter.c index 4166a1adb..5a783e8c5 100644 --- a/swad_parameter.c +++ b/swad_parameter.c @@ -59,6 +59,8 @@ extern struct Globals Gbl; /***************************** Private prototypes ****************************/ /*****************************************************************************/ +static void Par_ShowErrorReadingParam (const char *ParamName,const char *ExpectedChar,int Ch); + /*****************************************************************************/ /*** Read all parameters passed to this CGI and store for later processing ***/ /*****************************************************************************/ @@ -420,6 +422,7 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName, size_t BytesToCopy; size_t BytesAlreadyCopied = 0; int Ch; + unsigned i; char *PtrSrc; char *PtrDst; char *PtrStartOfParam; @@ -511,6 +514,7 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName, break; case Act_CONTENT_DATA: rewind (Gbl.F.Tmp); + while (ContinueSearching) { Result = Str_ReceiveFileUntilDelimitStr (Gbl.F.Tmp,NULL,StrAux,Gbl.DelimiterString,(unsigned long long) Par_MAX_BYTES_STR_AUX); @@ -531,24 +535,26 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName, if (!strcasecmp (Str_GetNextStrFromFileConvertingToLower (Gbl.F.Tmp,StrAux,Par_LENGTH_OF_STR_BEFORE_PARAM-1),StringBeforeParam+1)) // Start of a parameter if (!strcasecmp (Str_GetNextStrFromFileConvertingToLower (Gbl.F.Tmp,StrAux,ParamNameLength),ParamName)) // Parameter found { - /* Skip "'" symbol after parameter name */ + /* Skip quote after parameter name */ Ch = fgetc (Gbl.F.Tmp); if (Ch != (int) '\"') - { - sprintf (Gbl.Message,"Error reading parameter %s." - " A " character was expected, but a %c (ASCII code %d) has been found.", - ParamName,(char) Ch,Ch); - Lay_ShowErrorAndExit (Gbl.Message); - } + Par_ShowErrorReadingParam (ParamName,""",Ch); - /* Skip carriage returns, spaces, etc. */ - do - Ch = fgetc (Gbl.F.Tmp); - while (isspace (Ch) && Ch != EOF); + /* Skip two CR-LF (0x0D 0x0A) */ + for (i = 0; + i < 2; + i++) + { + Ch = fgetc (Gbl.F.Tmp); + if (Ch != 0x0D) // '\r' + Par_ShowErrorReadingParam (ParamName,"0x0D",Ch); + Ch = fgetc (Gbl.F.Tmp); + if (Ch != 0x0A) // '\n' + Par_ShowErrorReadingParam (ParamName,"0x0A",Ch); + } /* Get the parameter */ - ParamValue[0] = Ch; - Result = Str_ReceiveFileUntilDelimitStr (Gbl.F.Tmp,(FILE *) NULL,&ParamValue[1],Gbl.DelimiterStringIncludingInitialRet,(unsigned long long) MaxBytes); + Result = Str_ReceiveFileUntilDelimitStr (Gbl.F.Tmp,(FILE *) NULL,ParamValue,Gbl.DelimiterStringIncludingInitialRet,(unsigned long long) MaxBytes); /* Depending on the result... */ switch (Result) @@ -579,6 +585,19 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName, return NumTimes; } +/*****************************************************************************/ +/********************** Write error reading parameter ************************/ +/*****************************************************************************/ + +static void Par_ShowErrorReadingParam (const char *ParamName,const char *ExpectedChar,int Ch) + { + sprintf (Gbl.Message,"Error reading parameter %s." + " A %s character was expected," + " but a character with code %X has been found.", + ParamName,ExpectedChar,Ch); + Lay_ShowErrorAndExit (Gbl.Message); + } + /*****************************************************************************/ /***** Search in the string StrSrc the next string until find separator ******/ /*****************************************************************************/ diff --git a/swad_test.c b/swad_test.c index 88bd7d352..ceeb1a68f 100644 --- a/swad_test.c +++ b/swad_test.c @@ -146,6 +146,7 @@ static void Tst_ShowTstResultAfterAssess (long TstCod,unsigned *NumQstsNotBlank, static void Tst_WriteQstAndAnsExam (unsigned NumQst,long QstCod,MYSQL_ROW row, double *ScoreThisQst,bool *AnswerIsNotBlank); static void Tst_WriteQstImage (const char *Image); +static void Tst_PutFormToUploadNewQstImage (void); static void Tst_UpdateScoreQst (long QstCod,float ScoreThisQst,bool AnswerIsNotBlank); static void Tst_UpdateMyNumAccessTst (unsigned NumAccessesTst); static void Tst_UpdateLastAccTst (void); @@ -1023,6 +1024,17 @@ static void Tst_WriteQstImage (const char *Image) Image); } +/*****************************************************************************/ +/************* Put form to upload a new image for a test question ************/ +/*****************************************************************************/ + +static void Tst_PutFormToUploadNewQstImage (void) + { + fprintf (Gbl.F.Out,"", + Fil_NAME_OF_PARAM_FILENAME_ORG); + } + /*****************************************************************************/ /******************* Write the feedback of a test question *******************/ /*****************************************************************************/ @@ -4174,7 +4186,7 @@ static void Tst_PutFormEditOneQst (char *Stem,char *Feedback) { /***** Get the type of answer and the stem from the database *****/ /* Get the question from database */ - sprintf (Query,"SELECT AnsType,Shuffle,Stem,Feedback" + sprintf (Query,"SELECT AnsType,Shuffle,Stem,Image,Feedback" " FROM tst_questions" " WHERE QstCod='%ld' AND CrsCod='%ld'", Gbl.Test.QstCod, @@ -4193,12 +4205,16 @@ static void Tst_PutFormEditOneQst (char *Stem,char *Feedback) strncpy (Stem,row[2],Cns_MAX_BYTES_TEXT); Stem[Cns_MAX_BYTES_TEXT] = '\0'; - /* Get the feedback of the question from the database (row[3]) */ + /* Get the image of the question from the database (row[3]) */ + strncpy (Gbl.Test.Image,row[3],Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); + Gbl.Test.Image[Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64] = '\0'; + + /* Get the feedback of the question from the database (row[4]) */ Feedback[0] = '\0'; - if (row[3]) - if (row[3][0]) + if (row[4]) + if (row[4][0]) { - strncpy (Feedback,row[3],Cns_MAX_BYTES_TEXT); + strncpy (Feedback,row[4],Cns_MAX_BYTES_TEXT); Feedback[Cns_MAX_BYTES_TEXT] = '\0'; } @@ -4378,17 +4394,21 @@ static void Tst_PutFormEditOneQst (char *Stem,char *Feedback) /***** Image *****/ if (Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM) + { fprintf (Gbl.F.Out,"" "" "" "" - "" - "" - "", + "", The_ClassForm[Gbl.Prefs.Theme], Txt_Image); + Tst_WriteQstImage (Gbl.Test.Image); + Tst_PutFormToUploadNewQstImage (); + fprintf (Gbl.F.Out,"" + ""); + } /***** Feedback *****/ fprintf (Gbl.F.Out,"" @@ -4735,6 +4755,7 @@ static void Tst_GetQstFromForm (char *Stem,char *Feedback) { sprintf (TagStr,"TagTxt%u",NumTag); Par_GetParToText (TagStr,Gbl.Test.TagText[NumTag],Tst_MAX_BYTES_TAG); + if (Gbl.Test.TagText[NumTag][0]) { Str_ChangeFormat (Str_FROM_FORM,Str_TO_TEXT,