24 include_once 
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
 
   25 include_once 
"./Modules/Survey/classes/inc.SurveyConstants.php";
 
   67                 include_once 
"./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
 
   88                         return $ilDB->fetchAssoc(
$result);
 
  115                         $this->label = 
$data[
'label'];
 
  120                         include_once(
"./Services/RTE/classes/class.ilRTE.php");
 
  126                         $this->use_min_answers = (
$data[
'use_min_answers']) ? 
true : 
false;
 
  127                         $this->nr_min_answers = 
$data[
'nr_min_answers'];
 
  128                         $this->nr_max_answers = 
$data[
'nr_max_answers'];
 
  130                         $this->categories->flushCategories();
 
  131                         $result = $ilDB->queryF(
"SELECT svy_variable.*, svy_category.title, svy_category.neutral FROM svy_variable, svy_category WHERE svy_variable.question_fi = %s AND svy_variable.category_fi = svy_category.category_id ORDER BY sequence ASC",
 
  139                                         $this->categories->addCategory(
$data[
"title"], 
$data[
"other"], 
$data[
"neutral"], null, (
$data[
'scale']) ? 
$data[
'scale'] : (
$data[
'sequence'] + 1));
 
  154                 if (strlen($this->title) && strlen($this->author) && strlen($this->questiontext) && $this->categories->getCategoryCount())
 
  174                 if ($affectedRows == 1) 
 
  176                         $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() . 
" WHERE question_fi = %s",
 
  178                                 array($this->
getId())
 
  180                         $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() . 
" (question_fi, orientation, use_min_answers, nr_min_answers, nr_max_answers) VALUES (%s, %s, %s, %s, %s)",
 
  181                                 array(
'integer', 
'text', 
'integer', 
'integer', 
'integer'),
 
  185                                         ($this->use_min_answers) ? 1 : 0,
 
  186                                         ($this->nr_min_answers > 0) ? $this->nr_min_answers : null,
 
  187                                         ($this->nr_max_answers > 0) ? $this->nr_max_answers : null
 
  201                 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_variable WHERE question_fi = %s",
 
  203                         array($this->
getId())
 
  206                 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
 
  208                         $cat = $this->categories->getCategory($i);
 
  210                         $next_id = $ilDB->nextId(
'svy_variable');
 
  211                         $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
 
  212                                 array(
'integer',
'integer',
'integer',
'float',
'integer',
'integer', 
'integer',
'integer'),
 
  213                                 array($next_id, $category_id, $this->
getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
 
  225         function toXML($a_include_header = TRUE, $obligatory_state = 
"")
 
  227                 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
 
  230                 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
 
  231                 $xml = $a_xml_writer->xmlDumpMem(FALSE);
 
  232                 if (!$a_include_header)
 
  234                         $pos = strpos($xml, 
"?>");
 
  235                         $xml = substr($xml, $pos + 2);
 
  248         function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state = 
"")
 
  251                         "id" => $this->
getId(),
 
  253                         "type" => $this->getQuestiontype(),
 
  256                 $a_xml_writer->xmlStartTag(
"question", $attrs);
 
  258                 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
 
  259                 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
 
  260                 if (strlen($this->label))
 
  263                                 "label" => $this->label,
 
  270                 $a_xml_writer->xmlStartTag(
"questiontext", $attrs);
 
  272                 $a_xml_writer->xmlEndTag(
"questiontext");
 
  274                 $a_xml_writer->xmlStartTag(
"responses");
 
  276                 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
 
  281                         if (strlen($this->categories->getCategory($i)->other)) $attrs[
'other'] = $this->categories->getCategory($i)->other;
 
  282                         if (strlen($this->categories->getCategory($i)->neutral)) $attrs[
'neutral'] = $this->categories->getCategory($i)->neutral;
 
  283                         if (strlen($this->categories->getCategory($i)->label)) $attrs[
'label'] = $this->categories->getCategory($i)->label;
 
  284                         if (strlen($this->categories->getCategory($i)->scale)) $attrs[
'scale'] = $this->categories->getCategory($i)->scale;
 
  285                         $a_xml_writer->xmlStartTag(
"response_multiple", $attrs);
 
  286                         $this->
addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
 
  287                         $a_xml_writer->xmlEndTag(
"response_multiple");
 
  290                 $a_xml_writer->xmlEndTag(
"responses");
 
  292                 if (count($this->material))
 
  294                         if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
 
  297                                         "label" => $this->material[
"title"]
 
  299                                 $a_xml_writer->xmlStartTag(
"material", $attrs);
 
  300                                 $intlink = 
"il_" . IL_INST_ID . 
"_" . $matches[2] . 
"_" . $matches[3];
 
  301                                 if (strcmp($matches[1], 
"") != 0)
 
  303                                         $intlink = $this->material[
"internal_link"];
 
  305                                 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
 
  306                                 $a_xml_writer->xmlEndTag(
"material");
 
  310                 $a_xml_writer->xmlStartTag(
"metadata");
 
  311                 $a_xml_writer->xmlStartTag(
"metadatafield");
 
  312                 $a_xml_writer->xmlElement(
"fieldlabel", NULL, 
"orientation");
 
  313                 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->
getOrientation());
 
  314                 $a_xml_writer->xmlEndTag(
"metadatafield");
 
  315                 $a_xml_writer->xmlStartTag(
"metadatafield");
 
  316                 $a_xml_writer->xmlElement(
"fieldlabel", NULL, 
"use_min_answers");
 
  317                 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->use_min_answers);
 
  318                 $a_xml_writer->xmlEndTag(
"metadatafield");
 
  319                 $a_xml_writer->xmlStartTag(
"metadatafield");
 
  320                 $a_xml_writer->xmlElement(
"fieldlabel", NULL, 
"nr_min_answers");
 
  321                 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->nr_min_answers);
 
  322                 $a_xml_writer->xmlEndTag(
"metadatafield");
 
  323                 $a_xml_writer->xmlStartTag(
"metadatafield");
 
  324                 $a_xml_writer->xmlElement(
"fieldlabel", NULL, 
"nr_max_answers");
 
  325                 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->nr_max_answers);
 
  326                 $a_xml_writer->xmlEndTag(
"metadatafield");
 
  327                 $a_xml_writer->xmlEndTag(
"metadata");
 
  329                 $a_xml_writer->xmlEndTag(
"question");
 
  340                 return "SurveyMultipleChoiceQuestion";
 
  362                 $entered_value = $post_data[$this->
getId() . 
"_value"];
 
  364                 if (is_array($entered_value))
 
  366                         foreach ($entered_value as $idx => $value)
 
  368                                 array_push(
$data, array(
"value" => $value, 
"textanswer" => $post_data[$this->
getId() . 
'_' . $value . 
'_other']));
 
  371                 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
 
  373                         $cat = $this->categories->getCategory($i);
 
  376                                 if (!in_array($i, $entered_value))
 
  378                                         if (strlen($post_data[$this->
getId() . 
"_" . $i . 
"_other"]))
 
  380                                                 array_push(
$data, array(
"value" => $i, 
"textanswer" => $post_data[$this->
getId() . 
'_' . $i . 
'_other'], 
"uncheck" => 
true));
 
  399                 $entered_value = $post_data[$this->
getId() . 
"_value"];
 
  402                 if ($this->use_min_answers && $this->nr_min_answers > 0 && $this->nr_max_answers > 0 && $this->nr_min_answers == $this->nr_max_answers && count($entered_value) != $this->nr_max_answers)
 
  404                         return sprintf($this->lng->txt(
"err_no_exact_answers"), $this->nr_min_answers);
 
  406                 if ($this->use_min_answers && $this->nr_min_answers > 0 && count($entered_value) < $this->nr_min_answers)
 
  408                         return sprintf($this->lng->txt(
"err_no_min_answers"), $this->nr_min_answers);
 
  410                 if ($this->use_min_answers && $this->nr_max_answers > 0 && count($entered_value) > $this->nr_max_answers)
 
  412                         return sprintf($this->lng->txt(
"err_no_max_answers"), $this->nr_max_answers);
 
  414                 if (!is_array($entered_value))
 
  416                         return $this->lng->txt(
"question_mr_not_checked");
 
  418                 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
 
  420                         $cat = $this->categories->getCategory($i);
 
  423                                 if (in_array($i, $entered_value))
 
  425                                         if (array_key_exists($this->
getId() . 
"_" . $i . 
"_other", $post_data) && !strlen($post_data[$this->
getId() . 
"_" . $i . 
"_other"]))
 
  427                                                 return $this->lng->txt(
"question_mr_no_other_answer");
 
  432                                         if (strlen($post_data[$this->
getId() . 
"_" . $i . 
"_other"]))
 
  434                                                 return $this->lng->txt(
"question_mr_no_other_answer_checked");
 
  451                 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
 
  455                                 $cat = $this->categories->getCategory($i);
 
  456                                 $next_id = $ilDB->nextId(
'svy_answer');
 
  457                                 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
 
  458                                         array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
 
  459                                         array($next_id, $this->
getId(), $active_id, $i, ($cat->other) ? 
"Random Data" : null, time())
 
  469                 if (is_array($post_data[$this->
getId() . 
"_value"]))
 
  471                         foreach ($post_data[$this->
getId() . 
"_value"] as $entered_value)
 
  473                                 if (strlen($entered_value) > 0)
 
  475                                         $next_id = $ilDB->nextId(
'svy_answer');
 
  476                                         $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
 
  477                                                 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
 
  478                                                 array($next_id, $this->
getId(), $active_id, (strlen($entered_value)) ? $entered_value : NULL, ($post_data[$this->
getId() . 
"_" . $entered_value . 
"_other"]) ? $post_data[$this->
getId() . 
"_" . $entered_value . 
"_other"] : null, time())
 
  489                 $question_id = $this->
getId();
 
  491                 $result_array = array();
 
  494                 $result = $ilDB->queryF(
"SELECT svy_answer.* FROM svy_answer, svy_finished WHERE svy_answer.question_fi = %s AND svy_finished.survey_fi = %s AND svy_finished.finished_id = svy_answer.active_fi",
 
  495                         array(
'integer', 
'integer'),
 
  506                         if ($row[
"textanswer"])
 
  508                                 $result_array[
"textanswers"][$row[
"value"]][] = $row[
"textanswer"];
 
  512                 if (is_array($result_array[
"textanswers"]))
 
  514                         ksort($result_array[
"textanswers"], SORT_NUMERIC);
 
  519                 $mcmr_result = $ilDB->queryF(
"SELECT svy_answer.answer_id, svy_answer.question_fi, svy_answer.active_fi FROM svy_answer, svy_finished WHERE svy_answer.question_fi = %s AND svy_finished.survey_fi = %s AND svy_finished.finished_id = svy_answer.active_fi",
 
  520                         array(
'integer', 
'integer'),
 
  524                 while (
$row = $ilDB->fetchAssoc($mcmr_result))
 
  526                         $found[
$row[
"question_fi"] . 
"_" . 
$row[
"active_fi"]] = 1;
 
  528                 $result_array[
"USERS_ANSWERED"] = count($found);
 
  529                 $result_array[
"USERS_SKIPPED"] = $nr_of_users - count($found);
 
  530                 $numrows = count($found);
 
  532                 $result_array[
"MEDIAN"] = 
"";
 
  533                 $result_array[
"ARITHMETIC_MEAN"] = 
"";
 
  539                 $category = $this->categories->getCategoryForScale(key(
$cumulated)+1);
 
  540                 $result_array[
"MODE"] =  $prefix . $category->title;
 
  541                 $result_array[
"MODE_VALUE"] =  key(
$cumulated)+1;
 
  543                 $result_array[
"QUESTION_TYPE"] = 
"SurveyMultipleChoiceQuestion";
 
  545                 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
 
  547                         $cat = $this->categories->getCategory($key);
 
  550                 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
 
  552                         $cat = $this->categories->getCategory($key);
 
  558                                         $percentage = ($maxvalues > 0) ? (
float)((int)
$cumulated[$cat->scale-1]/$maxvalues) : 0;
 
  561                         $result_array[
"variables"][$key] = array(
"title" => $cat->title, 
"selected" => (
int)
$cumulated[$cat->scale-1], 
"percentage" => $percentage);
 
  563                 return $result_array;
 
  577                 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
 
  578                 $worksheet =& $workbook->addWorksheet();
 
  580                 switch ($export_label)
 
  606                 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_ANSWERED"]);
 
  609                 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_SKIPPED"]);
 
  623                 foreach ($eval_data[
"variables"] as $key => $value)
 
  626                         $category = $this->categories->getCategory($key);
 
  627                         $worksheet->write($rowcounter, 2, $category->scale);
 
  633                 if (is_array($eval_data[
"textanswers"]))
 
  639                         foreach ($eval_data[
"textanswers"] as $key => $answers)
 
  641                                 $title = $eval_data[
"variables"][$key][
"title"];
 
  642                                 foreach ($answers as $answer)
 
  661                 for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
 
  663                         $category = $this->categories->getCategory($index);
 
  664                         $title = $category->title;
 
  665                         array_push($a_array, 
$title);
 
  668                         if ($category->other)
 
  670                                 array_push($a_array, 
$title . 
" - ". $this->lng->txt(
"other"));
 
  684                 if (count($resultset[
"answers"][$this->
getId()]))
 
  686                         array_push($a_array, 
"");
 
  687                         for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
 
  689                                 $category = $this->categories->getCategory($index);
 
  690                                 $incoming_value = $category->scale ? $category->scale-1 : $index;               
 
  694                                 foreach ($resultset[
"answers"][$this->
getId()] as $answerdata)
 
  696                                         if (strcmp($incoming_value, $answerdata[
"value"]) == 0)
 
  698                                                 $found = $answerdata[
"value"]+1;
 
  699                                                 $textanswer = $answerdata[
"textanswer"];
 
  704                                         array_push($a_array, $found);
 
  708                                         array_push($a_array, 
"0");
 
  710                                 if ($category->other)
 
  712                                         array_push($a_array, $textanswer);
 
  718                         array_push($a_array, $this->lng->txt(
"skipped"));
 
  719                         for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
 
  721                                 array_push($a_array, 
"");
 
  724                                 $category = $this->categories->getCategory($index);
 
  725                                 if ($category->other)
 
  727                                         array_push($a_array, 
"");
 
  746                 $result = $ilDB->queryF(
"SELECT svy_answer.* FROM svy_answer, svy_finished WHERE svy_finished.survey_fi = %s AND svy_answer.question_fi = %s AND svy_finished.finished_id = svy_answer.active_fi",
 
  747                         array(
'integer', 
'integer'),
 
  752                         $category = $this->categories->getCategoryForScale(
$row[
"value"]+1);
 
  753                         if (!is_array($answers[
$row[
"active_fi"]]))
 
  755                                 $answers[$row[
"active_fi"]] = array();
 
  757                         $title = $row[
"value"] + 1 . 
" - " . $category->title;
 
  758                         if ($category->other) 
$title .= 
": " . $row[
"textanswer"];
 
  759                         $catindex = $this->categories->getIndex($category);
 
  760                         if ($catindex !== null)
 
  762                                 $answers[$row[
"active_fi"]][$catindex] = 
$title;
 
  766                                 array_push($answers[$row[
"active_fi"]], 
$title);
 
  768                         ksort($answers[$row[
"active_fi"]], SORT_NUMERIC);
 
  783                 foreach ($a_meta as $key => $value)
 
  785                         switch ($value[
"label"])
 
  790                                 case "use_min_answers":
 
  791                                         $this->use_min_answers = $value[
"entry"];
 
  793                                 case "nr_min_answers":
 
  794                                         $this->nr_min_answers = $value[
"entry"];
 
  796                                 case "nr_max_answers":
 
  797                                         $this->nr_max_answers = $value[
"entry"];
 
  816                                 $categorytext .= $material[
"text"];
 
  818                         $this->categories->addCategory(
 
  821                                 strlen($data[
'neutral']) ? $data[
'neutral'] : 0, 
 
  822                                 strlen($data[
'label']) ? $data[
'label'] : null, 
 
  823                                 strlen($data[
'scale']) ? $data[
'scale'] : null
 
  847                 return array(
"=", 
"<>");
 
  860                 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
 
  862                         $category = $this->categories->getCategory($i);
 
  863                         $options[$i] = ($i+1) . 
" - " . $category->title;
 
  876                 include_once 
"./Services/Form/classes/class.ilSelectInputGUI.php";
 
  879                 $step3->setOptions($options);
 
  880                 $step3->setValue($default);
 
  893                 $category = $this->categories->getCategory($value);
 
  894                 return ($value + 1) . 
" - " . ((strlen($category->title)) ? $category->title : $this->lng->txt(
'other_answer'));
 
  910                 if (count($this->cumulated) == 0)
 
  912                         include_once 
"./Modules/Survey/classes/class.ilObjSurvey.php";
 
  917                 foreach ($this->cumulated[
"variables"] as $key => $value)
 
  919                         foreach ($value as $key2 => $value2)
 
  921                                 $this->cumulated[
"variables"][$key][$key2] = utf8_decode($value2);
 
  924                 include_once 
"./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
 
  925                 $b1 = 
new SurveyChart(
"bars",400,250,utf8_decode($this->
getTitle()),utf8_decode($this->lng->txt(
"answers")),utf8_decode($this->lng->txt(
"users_answered")),$this->cumulated[
"variables"]);