// swad_test_import.c: import and export self-assessment tests using XML files /* SWAD (Shared Workspace At a Distance), is a web platform developed at the University of Granada (Spain), and used to support university teaching. This file is part of SWAD core. Copyright (C) 1999-2019 Antonio Caņas Vargas This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ /*****************************************************************************/ /*********************************** Headers *********************************/ /*****************************************************************************/ #include // For exit, system, malloc, free, etc #include // For string functions #include // For mkdir #include // For mkdir #include "swad_box.h" #include "swad_database.h" #include "swad_form.h" #include "swad_global.h" #include "swad_HTML.h" #include "swad_parameter.h" #include "swad_test.h" #include "swad_xml.h" /*****************************************************************************/ /***************************** Public constants ******************************/ /*****************************************************************************/ /*****************************************************************************/ /**************************** Private constants ******************************/ /*****************************************************************************/ /*****************************************************************************/ /******************************* Internal types ******************************/ /*****************************************************************************/ /*****************************************************************************/ /************** External global variables from others modules ****************/ /*****************************************************************************/ extern struct Globals Gbl; /*****************************************************************************/ /************************* Internal global variables *************************/ /*****************************************************************************/ /*****************************************************************************/ /***************************** Internal prototypes ***************************/ /*****************************************************************************/ static void TsI_PutParamsExportQsts (void); static void TsI_GetAndWriteTagsXML (long QstCod); static void TsI_WriteAnswersOfAQstXML (long QstCod); static void TsI_ReadQuestionsFromXMLFileAndStoreInDB (const char *FileNameXML); static void TsI_ImportQuestionsFromXMLBuffer (const char *XMLBuffer); static Tst_AnswerType_t TsI_ConvertFromStrAnsTypXMLToAnsTyp (const char *StrAnsTypeXML); static bool TsI_CheckIfQuestionExistsInDB (void); static void TsI_GetAnswerFromXML (struct XMLElement *AnswerElem); static void TsI_WriteHeadingListImportedQst (void); static void TsI_WriteRowImportedQst (struct XMLElement *StemElem, struct XMLElement *FeedbackElem, bool QuestionExists); /*****************************************************************************/ /**************** Put a link (form) to export test questions *****************/ /*****************************************************************************/ void TsI_PutFormToExportQuestions (void) { extern const char *Txt_Export_questions; /***** Put a link to create a file with questions *****/ Lay_PutContextualLinkIconText (ActLstTstQst,NULL,TsI_PutParamsExportQsts, "file-import.svg", Txt_Export_questions); } /*****************************************************************************/ /****************** Put params to export test questions **********************/ /*****************************************************************************/ static void TsI_PutParamsExportQsts (void) { Dat_WriteParamsIniEndDates (); Tst_WriteParamEditQst (); Par_PutHiddenParamChar ("OnlyThisQst",'N'); Par_PutHiddenParamUnsigned ("Order",(unsigned) Gbl.Test.SelectedOrder); Par_PutHiddenParamChar ("CreateXML",'Y'); } /*****************************************************************************/ /*************** Put a link (form) to import test questions ******************/ /*****************************************************************************/ void TsI_PutFormToImportQuestions (void) { extern const char *Txt_Import_questions; /***** Put a link to create a file with questions *****/ Lay_PutContextualLinkIconText (ActReqImpTstQst,NULL,NULL, "file-export.svg", Txt_Import_questions); } /*****************************************************************************/ /*********** Show form to import test questions from an XML file *************/ /*****************************************************************************/ void TsI_ShowFormImportQstsFromXML (void) { extern const char *Hlp_ASSESSMENT_Tests; extern const char *The_ClassFormInBox[The_NUM_THEMES]; extern const char *Txt_Import_questions; extern const char *Txt_You_need_an_XML_file_containing_a_list_of_questions; extern const char *Txt_XML_file; /***** Begin box *****/ Box_BoxBegin (NULL,Txt_Import_questions,NULL, Hlp_ASSESSMENT_Tests,Box_NOT_CLOSABLE); /***** Write help message *****/ Ale_ShowAlert (Ale_INFO,Txt_You_need_an_XML_file_containing_a_list_of_questions); /***** Write a form to import questions *****/ Frm_StartForm (ActImpTstQst); fprintf (Gbl.F.Out,"