/**
  * export questions to xml
  */
 function toXML($questions)
 {
     if (!is_array($questions)) {
         $questions =& $this->getQuestions();
     }
     if (count($questions) == 0) {
         $questions =& $this->getQuestions();
     }
     $xml = "";
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $attrs = array("xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" => "http://www.ilias.de/download/xsd/ilias_survey_4_2.xsd");
     $a_xml_writer->xmlStartTag("surveyobject", $attrs);
     $attrs = array("id" => "qpl_" . $this->getId(), "label" => $this->getTitle(), "online" => $this->getOnline());
     $a_xml_writer->xmlStartTag("surveyquestions", $attrs);
     $a_xml_writer->xmlElement("dummy", NULL, "dummy");
     // add ILIAS specific metadata
     $a_xml_writer->xmlStartTag("metadata");
     $a_xml_writer->xmlStartTag("metadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "SCORM");
     include_once "./Services/MetaData/classes/class.ilMD.php";
     $md = new ilMD($this->getId(), 0, $this->getType());
     $writer = new ilXmlWriter();
     $md->toXml($writer);
     $metadata = $writer->xmlDumpMem();
     $a_xml_writer->xmlElement("fieldentry", NULL, $metadata);
     $a_xml_writer->xmlEndTag("metadatafield");
     $a_xml_writer->xmlEndTag("metadata");
     $a_xml_writer->xmlEndTag("surveyquestions");
     $a_xml_writer->xmlEndTag("surveyobject");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     $questionxml = "";
     foreach ($questions as $key => $value) {
         $questiontype = $this->getQuestiontype($value);
         include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
         SurveyQuestion::_includeClass($questiontype);
         $question = new $questiontype();
         $question->loadFromDb($value);
         $questionxml .= $question->toXML(false);
     }
     $xml = str_replace("<dummy>dummy</dummy>", $questionxml, $xml);
     return $xml;
 }
 /**
  * Returns a QTI xml representation of the survey
  *
  * @return string The QTI xml representation of the survey
  * @access public
  */
 function toXML()
 {
     include_once "./Services/Xml/classes/class.ilXmlWriter.php";
     $a_xml_writer = new ilXmlWriter();
     // set xml header
     $a_xml_writer->xmlHeader();
     $attrs = array("xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" => "http://www.ilias.de/download/xsd/ilias_survey_4_2.xsd");
     $a_xml_writer->xmlStartTag("surveyobject", $attrs);
     $attrs = array("id" => $this->getSurveyId(), "title" => $this->getTitle());
     $a_xml_writer->xmlStartTag("survey", $attrs);
     $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
     $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
     $a_xml_writer->xmlStartTag("objectives");
     $attrs = array("label" => "introduction");
     $this->addMaterialTag($a_xml_writer, $this->getIntroduction(), TRUE, TRUE, $attrs);
     $attrs = array("label" => "outro");
     $this->addMaterialTag($a_xml_writer, $this->getOutro(), TRUE, TRUE, $attrs);
     $a_xml_writer->xmlEndTag("objectives");
     if ($this->getAnonymize()) {
         $attribs = array("enabled" => "1");
     } else {
         $attribs = array("enabled" => "0");
     }
     $a_xml_writer->xmlElement("anonymisation", $attribs);
     $a_xml_writer->xmlStartTag("restrictions");
     if ($this->getAnonymize() == 2) {
         $attribs = array("type" => "free");
     } else {
         $attribs = array("type" => "restricted");
     }
     $a_xml_writer->xmlElement("access", $attribs);
     if ($this->getStartDate()) {
         $attrs = array("type" => "date");
         preg_match("/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/", $this->getStartDate(), $matches);
         $a_xml_writer->xmlElement("startingtime", $attrs, sprintf("%04d-%02d-%02dT%02d:%02d:00", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
     }
     if ($this->getEndDate()) {
         $attrs = array("type" => "date");
         preg_match("/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/", $this->getEndDate(), $matches);
         $a_xml_writer->xmlElement("endingtime", $attrs, sprintf("%04d-%02d-%02dT%02d:%02d:00", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
     }
     $a_xml_writer->xmlEndTag("restrictions");
     // constraints
     $pages =& $this->getSurveyPages();
     $hasconstraints = FALSE;
     foreach ($pages as $question_array) {
         foreach ($question_array as $question) {
             if (count($question["constraints"])) {
                 $hasconstraints = TRUE;
             }
         }
     }
     if ($hasconstraints) {
         $a_xml_writer->xmlStartTag("constraints");
         foreach ($pages as $question_array) {
             foreach ($question_array as $question) {
                 if (count($question["constraints"])) {
                     // found constraints
                     foreach ($question["constraints"] as $constraint) {
                         $attribs = array("sourceref" => $question["question_id"], "destref" => $constraint["question"], "relation" => $constraint["short"], "value" => $constraint["value"], "conjunction" => $constraint["conjunction"]);
                         $a_xml_writer->xmlElement("constraint", $attribs);
                     }
                 }
             }
         }
         $a_xml_writer->xmlEndTag("constraints");
     }
     // add the rest of the preferences in qtimetadata tags, because there is no correspondent definition in QTI
     $a_xml_writer->xmlStartTag("metadata");
     $a_xml_writer->xmlStartTag("metadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "evaluation_access");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getEvaluationAccess());
     $a_xml_writer->xmlEndTag("metadatafield");
     $a_xml_writer->xmlStartTag("metadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "status");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getStatus());
     $a_xml_writer->xmlEndTag("metadatafield");
     $a_xml_writer->xmlStartTag("metadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "display_question_titles");
     $a_xml_writer->xmlElement("fieldentry", NULL, $this->getShowQuestionTitles());
     $a_xml_writer->xmlEndTag("metadatafield");
     $a_xml_writer->xmlStartTag("metadatafield");
     $a_xml_writer->xmlElement("fieldlabel", NULL, "SCORM");
     include_once "./Services/MetaData/classes/class.ilMD.php";
     $md = new ilMD($this->getId(), 0, $this->getType());
     $writer = new ilXmlWriter();
     $md->toXml($writer);
     $metadata = $writer->xmlDumpMem();
     $a_xml_writer->xmlElement("fieldentry", NULL, $metadata);
     $a_xml_writer->xmlEndTag("metadatafield");
     $a_xml_writer->xmlEndTag("metadata");
     $a_xml_writer->xmlEndTag("survey");
     $attribs = array("id" => $this->getId());
     $a_xml_writer->xmlStartTag("surveyquestions", $attribs);
     // add questionblock descriptions
     $obligatory_states =& $this->getObligatoryStates();
     foreach ($pages as $question_array) {
         if (count($question_array) > 1) {
             $attribs = array("id" => $question_array[0]["question_id"]);
             $attribs = array("showQuestiontext" => $question_array[0]["questionblock_show_questiontext"], "showBlocktitle" => $question_array[0]["questionblock_show_blocktitle"]);
             $a_xml_writer->xmlStartTag("questionblock", $attribs);
             if (strlen($question_array[0]["questionblock_title"])) {
                 $a_xml_writer->xmlElement("questionblocktitle", NULL, $question_array[0]["questionblock_title"]);
             }
         }
         foreach ($question_array as $question) {
             if (strlen($question["heading"])) {
                 $a_xml_writer->xmlElement("textblock", NULL, $question["heading"]);
             }
             $questionObject =& $this->_instanciateQuestion($question["question_id"]);
             if ($questionObject !== FALSE) {
                 $questionObject->insertXML($a_xml_writer, FALSE, $obligatory_states[$question["question_id"]]);
             }
         }
         if (count($question_array) > 1) {
             $a_xml_writer->xmlEndTag("questionblock");
         }
     }
     $a_xml_writer->xmlEndTag("surveyquestions");
     $a_xml_writer->xmlEndTag("surveyobject");
     $xml = $a_xml_writer->xmlDumpMem(FALSE);
     return $xml;
 }