From ee6164e39cfaf7be4686887092ad5451ea9710e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Sun, 3 Apr 2016 18:51:48 +0200 Subject: [PATCH] Version 15.175.6 --- swad_changelog.h | 4 +-- swad_image.c | 2 -- swad_image.h | 3 +- swad_test.c | 79 +++++++++++++++++++++++------------------------- 4 files changed, 40 insertions(+), 48 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 0d63e883c..4d556814d 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -140,14 +140,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.175.5 (2016-04-03)" +#define Log_PLATFORM_VERSION "SWAD 15.175.6 (2016-04-03)" #define CSS_FILE "swad15.173.1.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.175.6: Apr 03, 2016 Remove image associated to a test question. (? lines) + Version 15.175.6: Apr 03, 2016 Remove image associated to a test question. (197926 lines) Version 15.175.5: Apr 03, 2016 Changes in reception of form to edit one test question. (197930 lines) Version 15.175.4: Apr 03, 2016 Changes in form to edit one test question. (197897 lines) Version 15.175.3: Apr 03, 2016 Change in edition of test question. (197804 lines) diff --git a/swad_image.c b/swad_image.c index d88f314a6..602ea2b63 100644 --- a/swad_image.c +++ b/swad_image.c @@ -154,8 +154,6 @@ void Img_GetImageFromForm (unsigned Width,unsigned Height,unsigned Quality) Gbl.Test.Image,PtrExtension); if (Fil_EndReceptionOfFile (FileNameImgOrig,Param)) // Success { - Gbl.Image.Status = Img_FILE_RECEIVED; - /***** Convert original image to temporary JPEG processed file *****/ sprintf (FileNameImgTmp,"%s/%s/%s/%s.jpg", Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_IMG,Cfg_FOLDER_IMG_TMP, diff --git a/swad_image.h b/swad_image.h index 92ff11ff2..86ebbab39 100644 --- a/swad_image.h +++ b/swad_image.h @@ -38,7 +38,7 @@ No image Original file Temporary Definitive Name of the image uploaded uploaded by user processed image processed image stored in database --------- --------------------------- ------------------ ------------------ --------------------- -Img_NONE Img_FILE_RECEIVED Img_FILE_PROCESSED Img_FILE_MOVED Img_NAME_STORED_IN_DB +Img_NONE Img_NONE Img_FILE_PROCESSED Img_FILE_MOVED Img_NAME_STORED_IN_DB --------- --------------------------- ------------------ ------------------ --------------------- -> upload-file -> -> process-file -> b -> move-file -> -> insert-name -> --------- --------------------------- ------------------ ------------------ --------------------- @@ -61,7 +61,6 @@ xx-unique-name: a unique name encrypted starting by two random chars xx typedef enum { Img_NONE, - Img_FILE_RECEIVED, Img_FILE_PROCESSED, Img_FILE_MOVED, Img_NAME_STORED_IN_DB, diff --git a/swad_test.c b/swad_test.c index bbfde06e4..e9749334e 100644 --- a/swad_test.c +++ b/swad_test.c @@ -4804,10 +4804,23 @@ void Tst_ReceiveQst (void) /***** Make sure that tags, text and answer are not empty *****/ if (Tst_CheckIfQstFormatIsCorrectAndCountNumOptions ()) { - /***** Form is received OK ==> insert or update question and answer in the database *****/ - if (Gbl.Image.Status == Img_FILE_PROCESSED) - /* Move processed image to definitive directory */ - Img_MoveImageToDefinitiveDirectory (); + switch (Gbl.Image.Status) + { + case Img_NONE: + case Img_FILE_PROCESSED: + case Img_FILE_MOVED: + /* Remove possible file with the old image + (the new image file is already processed + and moved to the definitive directory) */ + Tst_RemoveImageFilesFromQstsInCrs (Gbl.CurrentCrs.Crs.CrsCod,Gbl.Test.QstCod); + + if (Gbl.Image.Status == Img_FILE_PROCESSED) // A new image has been received and processed + /* Move processed image to definitive directory */ + Img_MoveImageToDefinitiveDirectory (); + break; + case Img_NAME_STORED_IN_DB: // Keep image unchanged + break; + } /* Insert or update question, tags and answer in the database */ Tst_InsertOrUpdateQstTagsAnsIntoDB (); @@ -4884,9 +4897,10 @@ static void Tst_GetQstFromForm (char *Stem,char *Feedback) switch (ImageAction) { case Img_ACTION_NONE: // Do not use image (remove current image if exists) - - // TODO: Remove image - + /***** Reset image name *****/ + Gbl.Test.Image[0] = '\0'; + Gbl.Image.Status = Img_NONE; + break; case Img_ACTION_KEEP: // Keep current image unchanged /***** Get image from database *****/ Tst_GetImageNameFromDB (); @@ -4894,7 +4908,7 @@ static void Tst_GetQstFromForm (char *Stem,char *Feedback) Img_NONE); break; case Img_ACTION_CHANGE: // Upload new image (remove current image if exists) - /***** Get new image (if present ==> create file) *****/ + /***** Get new image (if present ==> process and create temporary file) *****/ Img_GetImageFromForm (Tst_PHOTO_SAVED_MAX_WIDTH, Tst_PHOTO_SAVED_MAX_HEIGHT, Tst_PHOTO_SAVED_QUALITY); @@ -5474,41 +5488,22 @@ static void Tst_InsertOrUpdateQstIntoDB (void) else // It's an existing question { /***** Update existing question *****/ - if (Gbl.Image.Status == Img_FILE_MOVED) - { - /* Remove possible file with the old image - (the new image file is already processed - and moved to the definitive directory) */ - Tst_RemoveImageFilesFromQstsInCrs (Gbl.CurrentCrs.Crs.CrsCod,Gbl.Test.QstCod); + /* Update question in database */ + sprintf (Query,"UPDATE tst_questions" + " SET EditTime=NOW(),AnsType='%s',Shuffle='%c'," + "Stem='%s',Image='%s',Feedback='%s'" + " WHERE QstCod='%ld' AND CrsCod='%ld'", + Tst_StrAnswerTypesDB[Gbl.Test.AnswerType], + Gbl.Test.Shuffle ? 'Y' : + 'N', + Gbl.Test.Stem.Text, + Gbl.Test.Image, + Gbl.Test.Feedback.Text ? Gbl.Test.Feedback.Text : "", + Gbl.Test.QstCod,Gbl.CurrentCrs.Crs.CrsCod); - /* Update question in database */ - sprintf (Query,"UPDATE tst_questions" - " SET EditTime=NOW(),AnsType='%s',Shuffle='%c'," - "Stem='%s',Image='%s',Feedback='%s'" - " WHERE QstCod='%ld' AND CrsCod='%ld'", - Tst_StrAnswerTypesDB[Gbl.Test.AnswerType], - Gbl.Test.Shuffle ? 'Y' : - 'N', - Gbl.Test.Stem.Text, - Gbl.Test.Image, - Gbl.Test.Feedback.Text ? Gbl.Test.Feedback.Text : "", - Gbl.Test.QstCod,Gbl.CurrentCrs.Crs.CrsCod); - - /* Update image status */ - if (Gbl.Test.Image[0]) - Gbl.Image.Status = Img_NAME_STORED_IN_DB; - } - else // Do not change image - sprintf (Query,"UPDATE tst_questions" - " SET EditTime=NOW(),AnsType='%s',Shuffle='%c'," - "Stem='%s',Feedback='%s'" - " WHERE QstCod='%ld' AND CrsCod='%ld'", - Tst_StrAnswerTypesDB[Gbl.Test.AnswerType], - Gbl.Test.Shuffle ? 'Y' : - 'N', - Gbl.Test.Stem.Text, - Gbl.Test.Feedback.Text ? Gbl.Test.Feedback.Text : "", - Gbl.Test.QstCod,Gbl.CurrentCrs.Crs.CrsCod); + /* Update image status */ + if (Gbl.Test.Image[0]) + Gbl.Image.Status = Img_NAME_STORED_IN_DB; DB_QueryUPDATE (Query,"can not update question"); /* Remove answers and tags from this test question */