diff --git a/js/swad15.178.2.js b/js/swad15.184.8.js similarity index 99% rename from js/swad15.178.2.js rename to js/swad15.184.8.js index 2166cd068..2ae81e8ba 100644 --- a/js/swad15.178.2.js +++ b/js/swad15.184.8.js @@ -859,8 +859,8 @@ function enableDisableStrAns (elem, isDisabled) { var Tst_MAX_OPTIONS_PER_QUESTION = 10; for (var i = 0; i < Tst_MAX_OPTIONS_PER_QUESTION; i++) - if (elem.name == ('AnsStr' + i) || - elem.name == ('FbStr' + i)) + if (elem.name == ('AnsStr' + i) || + elem.name == ('FbStr' + i)) elem.disabled = isDisabled; } @@ -869,8 +869,9 @@ function enableDisableImgAns (elem, isDisabled) { var Tst_MAX_OPTIONS_PER_QUESTION = 10; for (var i = 0; i < Tst_MAX_OPTIONS_PER_QUESTION; i++) - if (elem.name == ('ImgAct' + i) || - elem.name == ('FileImg' + i)) + if (elem.name == ('ImgAct' + i) || + elem.name == ('FilImg' + i) || + elem.name == ('TitImg' + i)) elem.disabled = isDisabled; } diff --git a/swad_changelog.h b/swad_changelog.h index cf45859af..f3ff4b0de 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -132,13 +132,15 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.184.7 (2016-04-07)" +#define Log_PLATFORM_VERSION "SWAD 15.185 (2016-04-07)" #define CSS_FILE "swad15.184.7.css" -#define JS_FILE "swad15.178.2.js" +#define JS_FILE "swad15.184.8.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.185: Apr 07, 2016 Fixed bugs in edition of test questions. (198755 lines) + Version 15.184.8: Apr 07, 2016 Change in edition of a test question. (198708 lines) Version 15.184.7: Apr 07, 2016 Change in layout of edition of a test question. (198706 lines) Version 15.184.6: Apr 07, 2016 Change in layout of edition of a test question. (198670 lines) Version 15.184.5: Apr 07, 2016 Fixed bugs exporting/importing test questions. (198679 lines) diff --git a/swad_test.c b/swad_test.c index da1af6d05..f40740cb1 100644 --- a/swad_test.c +++ b/swad_test.c @@ -36,7 +36,6 @@ #include // For string functions #include // For mkdir #include // For mkdir -#include // For unlink #include "swad_action.h" #include "swad_database.h" @@ -249,8 +248,11 @@ static void Tst_RemAnsFromQst (void); static void Tst_RemTagsFromQst (void); static void Tst_RemoveUnusedTagsFromCurrentCrs (void); -static void Tst_RemoveImgFilesFromStemOfQsts (long CrsCod,long QstCod); -static void Tst_RemoveImgFilesFromAnsOfQsts (long CrsCod,long QstCod,unsigned AnsInd); +static void Tst_RemoveImgFileFromStemOfQst (long CrsCod,long QstCod); +static void Tst_RemoveAllImgFilesFromStemOfAllQstsInCrs (long CrsCod); +static void Tst_RemoveImgFileFromAnsOfQst (long CrsCod,long QstCod,unsigned AnsInd); +static void Tst_RemoveAllImgFilesFromAnsOfQst (long CrsCod,long QstCod); +static void Tst_RemoveAllImgFilesFromAnsOfAllQstsInCrs (long CrsCod); static unsigned Tst_GetNumTstQuestions (Sco_Scope_t Scope,Tst_AnswerType_t AnsType,struct Tst_Stats *Stats); static unsigned Tst_GetNumCoursesWithTstQuestions (Sco_Scope_t Scope,Tst_AnswerType_t AnsType); @@ -5491,12 +5493,12 @@ static void Tst_MoveImagesToDefinitiveDirectories (void) unsigned NumOpt; /****** Move image associated to question stem *****/ - if (Gbl.Test.Image.Action != Img_ACTION_KEEP_IMAGE) // Don't keep the current image + if (Gbl.Test.QstCod > 0 && // Question already exists + Gbl.Test.Image.Action != Img_ACTION_KEEP_IMAGE) // Don't keep the current image /* Remove possible file with the old image (the new image file is already processed and moved to the definitive directory) */ - Tst_RemoveImgFilesFromStemOfQsts (Gbl.CurrentCrs.Crs.CrsCod, - Gbl.Test.QstCod); + Tst_RemoveImgFileFromStemOfQst (Gbl.CurrentCrs.Crs.CrsCod,Gbl.Test.QstCod); if ((Gbl.Test.Image.Action == Img_ACTION_NEW_IMAGE || // Upload new image Gbl.Test.Image.Action == Img_ACTION_CHANGE_IMAGE) && // Replace existing image by new image @@ -5511,13 +5513,12 @@ static void Tst_MoveImagesToDefinitiveDirectories (void) NumOpt < Gbl.Test.Answer.NumOptions; NumOpt++) { - if (Gbl.Test.Answer.Options[NumOpt].Image.Action != Img_ACTION_KEEP_IMAGE) // Don't keep the current image + if (Gbl.Test.QstCod > 0 && // Question already exists + Gbl.Test.Answer.Options[NumOpt].Image.Action != Img_ACTION_KEEP_IMAGE) // Don't keep the current image /* Remove possible file with the old image (the new image file is already processed and moved to the definitive directory) */ - Tst_RemoveImgFilesFromAnsOfQsts (Gbl.CurrentCrs.Crs.CrsCod, - Gbl.Test.QstCod, - NumOpt); + Tst_RemoveImgFileFromAnsOfQst (Gbl.CurrentCrs.Crs.CrsCod,Gbl.Test.QstCod,NumOpt); if ((Gbl.Test.Answer.Options[NumOpt].Image.Action == Img_ACTION_NEW_IMAGE || // Upload new image Gbl.Test.Answer.Options[NumOpt].Image.Action == Img_ACTION_CHANGE_IMAGE) && // Replace existing image by new image @@ -5748,11 +5749,8 @@ void Tst_RemoveQst (void) EditingOnlyThisQst = (Str_ConvertToUpperLetter (YN[0]) == 'Y'); /***** Remove images associated to question *****/ - Tst_RemoveImgFilesFromAnsOfQsts (Gbl.CurrentCrs.Crs.CrsCod, - Gbl.Test.QstCod, - Tst_MAX_OPTIONS_PER_QUESTION); // All answers - Tst_RemoveImgFilesFromStemOfQsts (Gbl.CurrentCrs.Crs.CrsCod, - Gbl.Test.QstCod); + Tst_RemoveAllImgFilesFromAnsOfQst (Gbl.CurrentCrs.Crs.CrsCod,Gbl.Test.QstCod); + Tst_RemoveImgFileFromStemOfQst (Gbl.CurrentCrs.Crs.CrsCod,Gbl.Test.QstCod); /***** Remove the question from all the tables *****/ /* Remove answers and tags from this test question */ @@ -6085,12 +6083,38 @@ static void Tst_RemoveUnusedTagsFromCurrentCrs (void) } /*****************************************************************************/ -/**** Remove one or more image files associated to stems of test questions ***/ +/******** Remove one file associated to one stem of one test question ********/ /*****************************************************************************/ -// Use question code <= 0 to remove all images associated to stems of questions in course -static void Tst_RemoveImgFilesFromStemOfQsts (long CrsCod, - long QstCod) // <= 0 ==> all questions in course +static void Tst_RemoveImgFileFromStemOfQst (long CrsCod,long QstCod) + { + char Query[256]; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + + /***** Get names of images associated to stems of test questions from database *****/ + sprintf (Query,"SELECT ImageName FROM tst_questions" + " WHERE QstCod='%ld' AND CrsCod='%ld'", + QstCod,CrsCod); + if (DB_QuerySELECT (Query,&mysql_res,"can not get test images")) + { + /***** Get image name (row[0]) *****/ + row = mysql_fetch_row (mysql_res); + + /***** Remove image file *****/ + Img_RemoveImageFile (row[0]); + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + } + +/*****************************************************************************/ +/****** Remove all image files associated to stems of all test questions *****/ +/****** in a course *****/ +/*****************************************************************************/ + +static void Tst_RemoveAllImgFilesFromStemOfAllQstsInCrs (long CrsCod) { char Query[256]; MYSQL_RES *mysql_res; @@ -6099,14 +6123,9 @@ static void Tst_RemoveImgFilesFromStemOfQsts (long CrsCod, unsigned NumImg; /***** Get names of images associated to stems of test questions from database *****/ - if (QstCod > 0) // Only one question - sprintf (Query,"SELECT ImageName FROM tst_questions" - " WHERE QstCod='%ld' AND CrsCod='%ld'", - QstCod,CrsCod); - else // All questions in the course - sprintf (Query,"SELECT ImageName FROM tst_questions" - " WHERE CrsCod='%ld'", - CrsCod); + sprintf (Query,"SELECT ImageName FROM tst_questions" + " WHERE CrsCod='%ld'", + CrsCod); NumImages = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get test images"); /***** Go over result removing image files *****/ @@ -6126,14 +6145,42 @@ static void Tst_RemoveImgFilesFromStemOfQsts (long CrsCod, } /*****************************************************************************/ -/** Remove one or more image files associated to answers of test questions ***/ +/**** Remove one image file associated to one answer of one test question ****/ /*****************************************************************************/ -// Use question code <= 0 to remove all images associated to answers of questions in course -// Use AnsInd == Tst_MAX_OPTIONS_PER_QUESTION to remove all images associated to answers of a question -static void Tst_RemoveImgFilesFromAnsOfQsts (long CrsCod, - long QstCod, // <= 0 ==> all questions in course - unsigned AnsInd) // == Tst_MAX_OPTIONS_PER_QUESTION ==> all answers of a question +static void Tst_RemoveImgFileFromAnsOfQst (long CrsCod,long QstCod,unsigned AnsInd) + { + char Query[512]; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + + /***** Get names of images associated to answers of test questions from database *****/ + sprintf (Query,"SELECT tst_answers.ImageName" + " FROM tst_questions,tst_answers" + " WHERE tst_questions.CrsCod='%ld'" // Extra check + " AND tst_questions.QstCod='%ld'" // Extra check + " AND tst_questions.QstCod=tst_answers.QstCod" + " AND tst_answers.QstCod='%ld'" + " AND tst_answers.AnsInd='%u'", + CrsCod,QstCod,QstCod,AnsInd); + if (DB_QuerySELECT (Query,&mysql_res,"can not get test images")) + { + /***** Get image name (row[0]) *****/ + row = mysql_fetch_row (mysql_res); + + /***** Remove image file *****/ + Img_RemoveImageFile (row[0]); + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + } + +/*****************************************************************************/ +/*** Remove all image files associated to all answers of one test question ***/ +/*****************************************************************************/ + +static void Tst_RemoveAllImgFilesFromAnsOfQst (long CrsCod,long QstCod) { char Query[512]; MYSQL_RES *mysql_res; @@ -6142,32 +6189,50 @@ static void Tst_RemoveImgFilesFromAnsOfQsts (long CrsCod, unsigned NumImg; /***** Get names of images associated to answers of test questions from database *****/ - if (QstCod > 0) // Only one question + sprintf (Query,"SELECT tst_answers.ImageName" + " FROM tst_questions,tst_answers" + " WHERE tst_questions.CrsCod='%ld'" // Extra check + " AND tst_questions.QstCod='%ld'" // Extra check + " AND tst_questions.QstCod=tst_answers.QstCod" + " AND tst_answers.QstCod='%ld'", + CrsCod,QstCod,QstCod); + NumImages = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get test images"); + + /***** Go over result removing image files *****/ + for (NumImg = 0; + NumImg < NumImages; + NumImg++) { - if (AnsInd < Tst_MAX_OPTIONS_PER_QUESTION) // Only one answer - sprintf (Query,"SELECT tst_answers.ImageName" - " FROM tst_questions,tst_answers" - " WHERE tst_questions.CrsCod='%ld'" // Extra check - " AND tst_questions.QstCod='%ld'" // Extra check - " AND tst_questions.QstCod=tst_answers.QstCod" - " AND tst_answers.QstCod='%ld'" - " AND tst_answers.AnsInd='%u'", - CrsCod,QstCod,QstCod,AnsInd); - else // All answers of a question - sprintf (Query,"SELECT tst_answers.ImageName" - " FROM tst_questions,tst_answers" - " WHERE tst_questions.CrsCod='%ld'" // Extra check - " AND tst_questions.QstCod='%ld'" // Extra check - " AND tst_questions.QstCod=tst_answers.QstCod" - " AND tst_answers.QstCod='%ld'", - CrsCod,QstCod,QstCod); + /***** Get image name (row[0]) *****/ + row = mysql_fetch_row (mysql_res); + + /***** Remove image file *****/ + Img_RemoveImageFile (row[0]); } - else // All answers of all questions in the course - sprintf (Query,"SELECT tst_answers.ImageName" - " FROM tst_questions,tst_answers" - " WHERE tst_questions.CrsCod='%ld'" - " AND tst_questions.QstCod=tst_answers.QstCod", - CrsCod); + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + } + +/*****************************************************************************/ +/** Remove all image files associated to all answers of all test questions ***/ +/** in a course ***/ +/*****************************************************************************/ + +static void Tst_RemoveAllImgFilesFromAnsOfAllQstsInCrs (long CrsCod) + { + char Query[512]; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned NumImages; + unsigned NumImg; + + /***** Get names of images associated to answers of test questions from database *****/ + sprintf (Query,"SELECT tst_answers.ImageName" + " FROM tst_questions,tst_answers" + " WHERE tst_questions.CrsCod='%ld'" + " AND tst_questions.QstCod=tst_answers.QstCod", + CrsCod); NumImages = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get test images"); /***** Go over result removing image files *****/ @@ -7744,11 +7809,8 @@ void Tst_RemoveCrsTests (long CrsCod) /***** Remove files with images associated to test questions in the course *****/ - Tst_RemoveImgFilesFromAnsOfQsts (CrsCod, - -1L, // All answers of questions in the course - Tst_MAX_OPTIONS_PER_QUESTION); // does not matter - Tst_RemoveImgFilesFromStemOfQsts (CrsCod, - -1L); // All questions in the course + Tst_RemoveAllImgFilesFromAnsOfAllQstsInCrs (CrsCod); + Tst_RemoveAllImgFilesFromStemOfAllQstsInCrs (CrsCod); /***** Remove test questions in the course *****/ sprintf (Query,"DELETE FROM tst_questions WHERE CrsCod='%ld'",