34 include_once
"./classes/class.ilObject.php";
35 include_once
"./Modules/Survey/classes/inc.SurveyConstants.php";
161 $this->
ilObject($a_id,$a_call_by_reference);
163 $this->survey_id = -1;
164 $this->introduction =
"";
165 $this->outro = $this->lng->txt(
"survey_finished");
166 $this->author = $ilUser->fullname;
169 $this->startdate_enabled = 0;
170 $this->enddate_enabled = 0;
171 $this->questions = array();
176 $this->surveyCodeSecurity = TRUE;
212 if (!parent::update())
234 function read($a_force_db =
false)
248 array_push($this->questions, $question_id);
270 foreach ($this->questions as $question_id)
289 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_svy WHERE survey_id = %s",
294 $result = $ilDB->queryF(
"SELECT questionblock_fi FROM svy_qblk_qst WHERE survey_fi = %s",
298 $questionblocks = array();
301 array_push($questionblocks,
$row[
"questionblock_fi"]);
303 if (count($questionblocks))
305 $affectedRows = $ilDB->manipulate(
"DELETE FROM svy_qblk WHERE " . $ilDB->in(
'questionblock_id', $questionblocks,
false,
'integer'));
307 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qblk_qst WHERE survey_fi = %s",
313 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_anonymous WHERE survey_fi = %s",
319 include_once
"./Services/Utilities/classes/class.ilUtil.php";
321 $directory = $svy_data_dir.
"/svy_".$this->
getId();
322 if (is_dir($directory))
324 include_once
"./Services/Utilities/classes/class.ilUtil.php";
328 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
334 foreach(
$mobs as $mob)
351 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE survey_fi = %s",
355 $active_array = array();
358 array_push($active_array,
$row[
"finished_id"]);
361 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_finished WHERE survey_fi = %s",
366 foreach ($active_array as $active_fi)
368 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_answer WHERE active_fi = %s",
384 foreach ($finished_ids as $finished_id)
386 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE finished_id = %s",
392 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_answer WHERE active_fi = %s",
394 array(
$row[
"finished_id"])
397 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_finished WHERE finished_id = %s",
408 $result = $ilDB->queryF(
"SELECT * FROM svy_finished WHERE survey_fi = %s",
412 $participants = array();
418 $participants[$userdata[
"sortname"] . $userdata[
"active_id"]] = $userdata;
421 return $participants;
437 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
477 if ($a_node_id==
$_GET[
"ref_id"])
479 $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
480 $parent_type = $parent_obj->getType();
481 if($parent_type == $this->
getType())
483 $a_node_id = (int) $tree->getParentId($a_node_id);
487 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
498 if (($this->
getTitle()) and (count($this->questions)))
517 $survey->loadFromDb();
518 if (($survey->getTitle()) and (count($survey->questions)))
537 $survey->loadFromDb();
539 if (($survey->getTitle()) and ($survey->author) and (count($survey->questions)))
547 $result[
"evaluation_access"] = $survey->getEvaluationAccess();
567 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_svy SET complete = %s, tstamp = %s WHERE survey_id = %s",
568 array(
'text',
'integer',
'integer'),
586 $question_gui = $this->
getQuestionGUI($questiontype, $question_id);
587 $duplicate_id = $question_gui->object->duplicate(
true);
588 return $duplicate_id;
600 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
608 $result = $ilDB->queryF(
"SELECT survey_question_id FROM svy_svy_qst WHERE survey_fi = %s",
612 $sequence =
$result->numRows();
614 $next_id = $ilDB->nextId(
'svy_svy_qst');
615 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_svy_qst (survey_question_id, survey_fi, question_fi, sequence, tstamp) VALUES (%s, %s, %s, %s, %s)",
616 array(
'integer',
'integer',
'integer',
'integer',
'integer'),
617 array($next_id, $this->
getSurveyId(), $duplicate_id, $sequence, time())
633 $result = $ilDB->queryF(
"SELECT svy_qblk.title, svy_qblk.show_questiontext, svy_qblk_qst.question_fi FROM svy_qblk, svy_qblk_qst, svy_svy_qst WHERE svy_qblk.questionblock_id = svy_qblk_qst.questionblock_fi AND svy_svy_qst.question_fi = svy_qblk_qst.question_fi AND svy_qblk.questionblock_id = %s ORDER BY svy_svy_qst.sequence",
635 array($questionblock_id)
638 $show_questiontext = 0;
644 $show_questiontext =
$row[
"show_questiontext"];
669 include_once(
"./Services/RTE/classes/class.ilRTE.php");
670 $completecontent =
"";
673 $completecontent .= $content;
688 include_once(
"./Services/RTE/classes/class.ilRTE.php");
691 $next_id = $ilDB->nextId(
'svy_svy');
692 $affectedRows = $ilDB->insert(
"svy_svy", array(
693 "survey_id" => array(
"integer", $next_id),
694 "obj_fi" => array(
"integer", $this->
getId()),
695 "author" => array(
"text", $this->
getAuthor()),
698 "status" => array(
"text", $this->
getStatus()),
699 "startdate" => array(
"timestamp", $this->
getStartDate()),
700 "enddate" => array(
"timestamp", $this->
getEndDate()),
704 "complete" => array(
"text", $this->
isComplete()),
705 "created" => array(
"integer", time()),
708 "tstamp" => array(
"integer", time())
714 $affectedRows = $ilDB->update(
"svy_svy", array(
715 "author" => array(
"text", $this->
getAuthor()),
718 "status" => array(
"text", $this->
getStatus()),
719 "startdate" => array(
"timestamp", $this->
getStartDate()),
720 "enddate" => array(
"timestamp", $this->
getEndDate()),
724 "complete" => array(
"text", $this->
isComplete()),
727 "tstamp" => array(
"integer", time())
729 "survey_id" => array(
"integer", $this->
getSurveyId())
749 $old_questions = array();
750 $result = $ilDB->queryF(
"SELECT * FROM svy_svy_qst WHERE survey_fi = %s",
758 $old_questions[
$row[
"question_fi"]] =
$row;
763 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_svy_qst WHERE survey_fi = %s",
768 foreach ($this->questions as
$key => $value)
770 $next_id = $ilDB->nextId(
'svy_svy_qst');
771 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_svy_qst (survey_question_id, survey_fi, question_fi, heading, sequence, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
772 array(
'integer',
'integer',
'integer',
'text',
'integer',
'integer'),
773 array($next_id, $this->
getSurveyId(), $value, (strlen($old_questions[$value][
"heading"])) ? $old_questions[$value][
"heading"] : NULL,
$key, time())
788 $result = $ilDB->queryF(
"SELECT anonymous_id FROM svy_finished WHERE anonymous_id = %s",
795 return $row[
"anonymous_id"];
811 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
825 if ($question_id < 1)
return -1;
826 $result = $ilDB->queryF(
"SELECT type_tag FROM svy_question, svy_qtype WHERE svy_question.question_id = %s AND " .
827 "svy_question.questiontype_fi = svy_qtype.questiontype_id",
834 return $data[
"type_tag"];
858 switch ($a_anonymize)
863 $this->anonymize = $a_anonymize;
878 return ($this->anonymize) ? $this->anonymize : 0;
906 $result = $ilDB->queryF(
"SELECT * FROM svy_svy WHERE obj_fi = %s",
908 array($this->
getId())
915 include_once(
"./Services/RTE/classes/class.ilRTE.php");
917 if (strcmp(
$data[
"outro"],
"survey_finished") == 0)
919 $this->
setOutro($this->lng->txt(
"survey_finished"));
948 $this->questions = array();
949 $result = $ilDB->queryF(
"SELECT * FROM svy_svy_qst WHERE survey_fi = %s ORDER BY sequence",
955 $this->questions[
$data[
"sequence"]] = $data[
"question_fi"];
968 $this->startdate_enabled = ($enabled) ? $enabled : 0;
980 return ($this->startdate_enabled) ? $this->startdate_enabled : 0;
992 $this->enddate_enabled = ($enabled) ? $enabled : 0;
1004 return ($this->enddate_enabled) ? $this->enddate_enabled : 0;
1031 $md_life =& $md->getLifecycle();
1034 if (strlen($a_author) == 0)
1037 $a_author = $ilUser->getFullname();
1040 $md_life =& $md->addLifecycle();
1042 $con =& $md_life->addContribute();
1043 $con->setRole(
"Author");
1045 $ent =& $con->addEntity();
1046 $ent->setEntity($a_author);
1061 include_once
"./Services/MetaData/classes/class.ilMD.php";
1063 $md_life =& $md->getLifecycle();
1066 $ids =& $md_life->getContributeIds();
1067 foreach ($ids as
$id)
1069 $md_cont =& $md_life->getContribute($id);
1070 if (strcmp($md_cont->getRole(),
"Author") == 0)
1072 $entids =& $md_cont->getEntityIds();
1073 foreach ($entids as $entid)
1075 $md_ent =& $md_cont->getEntity($entid);
1076 array_push(
$author, $md_ent->getEntity());
1092 return ($this->display_question_titles) ? 1 : 0;
1103 $this->display_question_titles = ($a_show) ? 1 : 0;
1114 $this->display_question_titles = 1;
1125 $this->display_question_titles = 0;
1148 $result = $ilDB->query(
"SELECT usr_id FROM usr_data");
1151 if ($ilAccess->checkAccessOfUser(
$row[
"usr_id"],
"read",
"", $this->getRefId(),
"svy", $this->
getId()))
1229 include_once
"./Services/Administration/classes/class.ilSetting.php";
1230 $surveySetting =
new ilSetting(
"survey");
1231 $unlimited_invitation = $surveySetting->get(
"unlimited_invitation");
1232 if (!$unlimited_invitation && $this->invitation_mode ==
MODE_UNLIMITED)
1238 return ($this->invitation_mode) ? $this->invitation_mode :
MODE_UNLIMITED;
1292 $result = $this->lng->txt(
"cannot_switch_to_online_no_questions");
1310 return (strlen($this->start_date)) ? $this->start_date : NULL;
1330 if ($now < $epoch_time)
1332 array_push(
$messages,$this->lng->txt(
'start_date_not_reached').
' ('.
1343 if ($now > $epoch_time)
1345 array_push(
$messages,$this->lng->txt(
'end_date_reached').
' ('.
1354 array_push(
$messages, $this->lng->txt(
"survey_is_offline"));
1358 if (!$ilAccess->checkAccess(
"read",
"", $this->ref_id))
1360 array_push(
$messages, $this->lng->txt(
"cannot_participate_survey"));
1367 $survey_started = $this->
isSurveyStarted($ilUser->getId(), $anonymous_id);
1368 if ($survey_started === 1)
1370 array_push(
$messages, $this->lng->txt(
"already_completed_survey"));
1401 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})/", $this->start_date, $matches))
1420 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})/", $this->start_date, $matches))
1439 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})/", $this->start_date, $matches))
1458 return (strlen($this->end_date)) ? $this->end_date : NULL;
1482 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})/", $this->end_date, $matches))
1501 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})/", $this->end_date, $matches))
1520 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})/", $this->end_date, $matches))
1563 return (strlen($this->introduction)) ? $this->introduction : NULL;
1575 return (strlen($this->outro)) ? $this->outro : NULL;
1587 $existing_questions = array();
1588 $result = $ilDB->queryF(
"SELECT svy_question.original_id FROM svy_question, svy_svy_qst WHERE " .
1589 "svy_svy_qst.survey_fi = %s AND svy_svy_qst.question_fi = svy_question.question_id",
1595 array_push($existing_questions,
$data[
"original_id"]);
1597 return $existing_questions;
1608 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1620 $move_questions = array($question_id);
1623 foreach ($pages as $idx => $page)
1625 if ($page[0][
"question_id"] == $question_id)
1632 $this->
moveQuestions($move_questions, $pages[$pageindex-1][0][
"question_id"], 0);
1639 $index = array_search($question_id,
$questions);
1640 if (($index !== FALSE) && ($index > 0))
1654 $move_questions = array($question_id);
1657 foreach ($pages as $idx => $page)
1659 if (($page[0][
"question_id"] == $question_id) && (strcmp($page[0][
"questionblock_id"],
"") == 0))
1664 if (($pageindex < count($pages)-1) && ($pageindex >= 0))
1666 $this->
moveQuestions($move_questions, $pages[$pageindex+1][count($pages[$pageindex+1])-1][
"question_id"], 1);
1673 $index = array_search($question_id,
$questions);
1674 if (($index !== FALSE) && ($index < count(
$questions)-1))
1690 $move_questions = array();
1692 foreach ($pages as $idx => $page)
1694 if ($page[0][
"questionblock_id"] == $questionblock_id)
1696 foreach ($page as $pageidx => $question)
1698 array_push($move_questions, $question[
"question_id"]);
1705 $this->
moveQuestions($move_questions, $pages[$pageindex-1][0][
"question_id"], 0);
1718 $move_questions = array();
1720 foreach ($pages as $idx => $page)
1722 if ($page[0][
"questionblock_id"] == $questionblock_id)
1724 foreach ($page as $pageidx => $question)
1726 array_push($move_questions, $question[
"question_id"]);
1731 if ($pageindex < count($pages)-1)
1733 $this->
moveQuestions($move_questions, $pages[$pageindex+1][count($pages[$pageindex+1])-1][
"question_id"], 1);
1747 $array_pos = array_search($target_index, $this->questions);
1748 if ($insert_mode == 0)
1750 $part1 = array_slice($this->questions, 0, $array_pos);
1751 $part2 = array_slice($this->questions, $array_pos);
1753 else if ($insert_mode == 1)
1755 $part1 = array_slice($this->questions, 0, $array_pos + 1);
1756 $part2 = array_slice($this->questions, $array_pos + 1);
1758 foreach ($move_questions as $question_id)
1760 if (!(array_search($question_id, $part1) === FALSE))
1762 unset($part1[array_search($question_id, $part1)]);
1764 if (!(array_search($question_id, $part2) === FALSE))
1766 unset($part2[array_search($question_id, $part2)]);
1769 $part1 = array_values($part1);
1770 $part2 = array_values($part2);
1771 $this->questions = array_values(array_merge($part1, $move_questions, $part2));
1772 foreach ($move_questions as $question_id)
1775 foreach ($constraints as $idx => $constraint)
1777 foreach ($part2 as $next_question_id)
1779 if ($constraint[
"question"] == $next_question_id)
1798 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1800 $question->delete($question_id);
1813 $result = $ilDB->queryF(
"SELECT constraint_fi FROM svy_qst_constraint WHERE question_fi = %s AND survey_fi = %s",
1814 array(
'integer',
'integer'),
1819 $remove_constraints = array();
1822 array_push($remove_constraints,
$row[
"constraint_fi"]);
1824 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qst_constraint WHERE question_fi = %s AND survey_fi = %s",
1825 array(
'integer',
'integer'),
1828 foreach ($remove_constraints as
$key => $constraint_id)
1830 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_constraint WHERE constraint_id = %s",
1832 array($constraint_id)
1851 if (in_array($question_id, $remove_questions) or in_array(
$data[
"questionblock_id"], $remove_questionblocks))
1853 unset($this->questions[array_search($question_id, $this->questions)]);
1857 foreach ($remove_questionblocks as $questionblock_id)
1859 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qblk WHERE questionblock_id = %s",
1861 array($questionblock_id)
1863 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qblk_qst WHERE questionblock_fi = %s AND survey_fi = %s",
1864 array(
'integer',
'integer'),
1868 $this->questions = array_values($this->questions);
1881 foreach ($questionblocks as $index)
1883 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qblk WHERE questionblock_id = %s",
1887 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qblk_qst WHERE questionblock_fi = %s AND survey_fi = %s",
1888 array(
'integer',
'integer'),
1904 $result = $ilDB->queryF(
"SELECT svy_question.title, svy_qblk_qst.question_fi, svy_qblk_qst.survey_fi FROM ".
1905 "svy_qblk, svy_qblk_qst, svy_question WHERE svy_qblk.questionblock_id = svy_qblk_qst.questionblock_fi AND " .
1906 "svy_question.question_id = svy_qblk_qst.question_fi AND svy_qblk.questionblock_id = %s",
1908 array($questionblock_id)
1913 $titles[
$row[
"question_fi"]] = $row[
"title"];
1916 $result = $ilDB->queryF(
"SELECT question_fi, sequence FROM svy_svy_qst WHERE survey_fi = %s ORDER BY sequence",
1920 $resultarray = array();
1924 if (array_key_exists(
$row[
"question_fi"], $titles))
1926 $resultarray[$counter++] = $titles[
$row[
"question_fi"]];
1929 return $resultarray;
1941 $result = $ilDB->queryF(
"SELECT question_fi FROM svy_qblk_qst WHERE questionblock_fi = %s",
1943 array($questionblock_id)
1950 array_push($ids,
$data[
'question_fi']);
1966 $result = $ilDB->queryF(
"SELECT * FROM svy_qblk WHERE questionblock_id = %s",
1968 array($questionblock_id)
1970 return $ilDB->fetchAssoc(
$result);
1983 $result = $ilDB->queryF(
"SELECT * FROM svy_qblk WHERE questionblock_id = %s",
1985 array($questionblock_id)
2002 $next_id = $ilDB->nextId(
'svy_qblk');
2003 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_qblk (questionblock_id, title, owner_fi, tstamp) " .
2004 "VALUES (%s, %s, %s, %s)",
2005 array(
'integer',
'text',
'integer',
'integer'),
2027 $next_id = $ilDB->nextId(
'svy_qblk');
2028 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_qblk (questionblock_id, title, show_questiontext, owner_fi, ".
2029 "tstamp) VALUES (%s, %s, %s, %s, %s)",
2030 array(
'integer',
'text',
'text',
'integer',
'integer'),
2031 array($next_id,
$title, $show_questiontext, $ilUser->getId(), time())
2035 $questionblock_id = $next_id;
2038 $next_id = $ilDB->nextId(
'svy_qblk_qst');
2039 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_qblk_qst (qblk_qst_id, survey_fi, questionblock_fi, " .
2040 "question_fi) VALUES (%s, %s, %s, %s)",
2041 array(
'integer',
'integer',
'integer',
'integer'),
2042 array($next_id, $this->
getSurveyId(), $questionblock_id, $index)
2059 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_qblk SET title = %s, show_questiontext = %s WHERE " .
2060 "questionblock_id = %s",
2061 array(
'text',
'text',
'integer'),
2062 array(
$title, $show_questiontext, $questionblock_id)
2075 $result = $ilDB->queryF(
"SELECT * FROM svy_qst_constraint WHERE question_fi = %s AND survey_fi = %s",
2076 array(
'integer',
'integer'),
2081 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_constraint WHERE constraint_id = %s",
2083 array(
$row[
"constraint_fi"])
2086 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qst_constraint WHERE question_fi = %s AND survey_fi = %s",
2087 array(
'integer',
'integer'),
2102 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_constraint WHERE constraint_id = %s",
2104 array($constraint_id)
2106 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qst_constraint WHERE constraint_fi = %s " .
2107 "AND question_fi = %s AND survey_fi = %s",
2108 array(
'integer',
'integer',
'integer'),
2109 array($constraint_id, $question_id, $this->
getSurveyId())
2123 $all_questions = array();
2124 $result = $ilDB->queryF(
"SELECT svy_qtype.type_tag, svy_qtype.plugin, svy_question.question_id, ".
2125 "svy_svy_qst.heading FROM svy_qtype, svy_question, svy_svy_qst WHERE svy_svy_qst.survey_fi = %s AND " .
2126 "svy_svy_qst.question_fi = svy_question.question_id AND svy_question.questiontype_fi = svy_qtype.questiontype_id " .
2127 "ORDER BY svy_svy_qst.sequence",
2131 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
2145 $questionrow = $question->_getQuestionDataArray(
$row[
"question_id"]);
2148 $questionrow[
$key] = $value;
2150 $all_questions[
$row[
"question_id"]] = $questionrow;
2151 $all_questions[$row[
"question_id"]][
"usableForPrecondition"] = $question->usableForPrecondition();
2152 $all_questions[$row[
"question_id"]][
"availableRelations"] = $question->getAvailableRelations();
2153 if (array_key_exists($row[
"question_id"], $obligatory_states))
2155 $all_questions[$row[
"question_id"]][
"obligatory"] = $obligatory_states[$row[
"question_id"]];
2160 $questionblocks = array();
2161 if (count($all_questions))
2163 $result = $ilDB->queryF(
"SELECT svy_qblk.*, svy_qblk_qst.question_fi FROM svy_qblk, svy_qblk_qst WHERE " .
2164 "svy_qblk.questionblock_id = svy_qblk_qst.questionblock_fi AND svy_qblk_qst.survey_fi = %s " .
2165 "AND " . $ilDB->in(
'svy_qblk_qst.question_fi', array_keys($all_questions),
false,
'integer'),
2171 $questionblocks[
$row[
'question_fi']] =
$row;
2175 foreach ($all_questions as $question_id =>
$row)
2178 if (isset($questionblocks[$question_id]))
2180 $all_questions[$question_id][
"questionblock_title"] = $questionblocks[$question_id][
'title'];
2181 $all_questions[$question_id][
"questionblock_id"] = $questionblocks[$question_id][
'questionblock_id'];
2182 $all_questions[$question_id][
"constraints"] = $constraints;
2186 $all_questions[$question_id][
"questionblock_title"] =
"";
2187 $all_questions[$question_id][
"questionblock_id"] =
"";
2188 $all_questions[$question_id][
"constraints"] = $constraints;
2193 $result = $ilDB->queryF(
"SELECT svy_variable.*, svy_category.title FROM svy_variable, svy_category " .
2194 "WHERE svy_variable.question_fi = %s AND svy_variable.category_fi = svy_category.category_id ".
2195 "ORDER BY sequence ASC",
2203 array_push($answers,
$data[
"title"]);
2206 $all_questions[$question_id][
"answers"] = $answers;
2209 return $all_questions;
2221 $result = $ilDB->queryF(
"SELECT * FROM svy_svy_qst WHERE survey_fi = %s",
2229 if (!array_key_exists(
$row[
"question_fi"], $obligatory_questions))
2231 $obligatory_questions[
$row[
"question_fi"]] = 0;
2237 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qst_oblig WHERE survey_fi = %s",
2243 foreach ($obligatory_questions as $question_fi => $obligatory)
2245 $next_id = $ilDB->nextId(
'svy_qst_oblig');
2246 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_qst_oblig (question_obligatory_id, survey_fi, question_fi, " .
2247 "obligatory, tstamp) VALUES (%s, %s, %s, %s, %s)",
2248 array(
'integer',
'integer',
'integer',
'text',
'integer'),
2249 array($next_id, $this->
getSurveyId(), $question_fi, (strlen($obligatory)) ? $obligatory : 0, time())
2263 $obligatory_states = array();
2264 $result = $ilDB->queryF(
"SELECT * FROM svy_qst_oblig WHERE survey_fi = %s",
2272 $obligatory_states[
$row[
"question_fi"]] = $row[
"obligatory"];
2275 return $obligatory_states;
2288 $all_questions = array();
2289 $result = $ilDB->queryF(
"SELECT svy_question.*, svy_qtype.type_tag, svy_svy_qst.heading FROM " .
2290 "svy_question, svy_qtype, svy_svy_qst WHERE svy_svy_qst.survey_fi = %s AND " .
2291 "svy_svy_qst.question_fi = svy_question.question_id AND svy_question.questiontype_fi = svy_qtype.questiontype_id ".
2292 "ORDER BY svy_svy_qst.sequence",
2298 $all_questions[
$row[
"question_id"]] =
$row;
2301 $questionblocks = array();
2302 if (count($all_questions))
2304 $result = $ilDB->queryF(
"SELECT svy_qblk.*, svy_qblk_qst.question_fi FROM svy_qblk, svy_qblk_qst ".
2305 "WHERE svy_qblk.questionblock_id = svy_qblk_qst.questionblock_fi AND svy_qblk_qst.survey_fi = %s ".
2306 "AND " . $ilDB->in(
'svy_qblk_qst.question_fi', array_keys($all_questions),
false,
'integer'),
2312 $questionblocks[
$row[
'question_fi']] =
$row;
2316 $all_pages = array();
2319 foreach ($all_questions as $question_id =>
$row)
2321 if (array_key_exists($question_id, $obligatory_states))
2323 $all_questions[$question_id][
"obligatory"] = $obligatory_states[$question_id];
2325 $constraints = array();
2326 if (isset($questionblocks[$question_id]))
2328 if (!$currentblock or ($currentblock != $questionblocks[$question_id][
'questionblock_id']))
2332 $all_questions[$question_id][
"questionblock_title"] = $questionblocks[$question_id][
'title'];
2333 $all_questions[$question_id][
"questionblock_id"] = $questionblocks[$question_id][
'questionblock_id'];
2334 $all_questions[$question_id][
"questionblock_show_questiontext"] = $questionblocks[$question_id][
'show_questiontext'];
2335 $currentblock = $questionblocks[$question_id][
'questionblock_id'];
2337 $all_questions[$question_id][
"constraints"] = $constraints;
2342 $all_questions[$question_id][
"questionblock_title"] =
"";
2343 $all_questions[$question_id][
"questionblock_id"] =
"";
2344 $all_questions[$question_id][
"questionblock_show_questiontext"] = 1;
2347 $all_questions[$question_id][
"constraints"] = $constraints;
2349 if (!isset($all_pages[$pageindex]))
2351 $all_pages[$pageindex] = array();
2353 array_push($all_pages[$pageindex], $all_questions[$question_id]);
2356 $max = count($all_pages);
2358 foreach ($all_pages as $index => $block)
2360 foreach ($block as $blockindex => $question)
2362 $all_pages[$index][$blockindex][
"position"] = $counter / $max;
2381 if (strcmp($active_page_question_id,
"") == 0)
2386 foreach ($pages as
$key => $question_array)
2388 foreach ($question_array as $question)
2390 if ($active_page_question_id == $question[
"question_id"])
2396 if ($foundpage == -1)
2402 $foundpage += $direction;
2407 if ($foundpage >= count($pages))
2411 return $pages[$foundpage];
2423 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
2436 $result_array = array();
2437 $result = $ilDB->queryF(
"SELECT svy_constraint.*, svy_relation.* FROM svy_qst_constraint, svy_constraint, ".
2438 "svy_relation WHERE svy_constraint.relation_fi = svy_relation.relation_id AND ".
2439 "svy_qst_constraint.constraint_fi = svy_constraint.constraint_id AND svy_constraint.constraint_id = %s",
2446 $pc = $ilDB->fetchAssoc(
$result);
2460 $result_array = array();
2461 $result = $ilDB->queryF(
"SELECT svy_constraint.*, svy_relation.* FROM svy_qst_constraint, svy_constraint, svy_relation ".
2462 "WHERE svy_constraint.relation_fi = svy_relation.relation_id AND ".
2463 "svy_qst_constraint.constraint_fi = svy_constraint.constraint_id AND svy_qst_constraint.question_fi = %s ".
2464 "AND svy_qst_constraint.survey_fi = %s",
2465 array(
'integer',
'integer'),
2470 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
2473 $question =
new $question_type();
2474 $question->loadFromDb(
$row[
"question_fi"]);
2475 $valueoutput = $question->getPreconditionValueOutput(
$row[
"value"]);
2476 array_push($result_array, array(
"id" =>
$row[
"constraint_id"],
"question" =>
$row[
"question_fi"],
"short" =>
$row[
"shortname"],
"long" =>
$row[
"longname"],
"value" =>
$row[
"value"],
"valueoutput" => $valueoutput));
2478 return $result_array;
2489 $result_array = array();
2490 $result = $ilDB->queryF(
"SELECT svy_qst_constraint.question_fi as for_question, svy_constraint.*, svy_relation.* ".
2491 "FROM svy_qst_constraint, svy_constraint, svy_relation WHERE svy_constraint.relation_fi = svy_relation.relation_id ".
2492 "AND svy_qst_constraint.constraint_fi = svy_constraint.constraint_id AND svy_qst_constraint.survey_fi = %s",
2498 array_push($result_array, array(
"id" =>
$row[
"constraint_id"],
"for_question" =>
$row[
"for_question"],
"question" =>
$row[
"question_fi"],
"short" =>
$row[
"shortname"],
"long" =>
$row[
"longname"],
"relation_id" =>
$row[
"relation_id"],
"value" =>
$row[
"value"]));
2500 return $result_array;
2513 $result_array = array();
2514 $result = $ilDB->queryF(
"SELECT svy_variable.*, svy_category.title FROM svy_variable LEFT JOIN ".
2515 "svy_category ON svy_variable.category_fi = svy_category.category_id WHERE svy_variable.question_fi = %s ".
2516 "ORDER BY svy_variable.sequence",
2522 $result_array[
$row->sequence] =
$row;
2524 return $result_array;
2540 $next_id = $ilDB->nextId(
'svy_constraint');
2541 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_constraint (constraint_id, question_fi, relation_fi, value) VALUES ".
2543 array(
'integer',
'integer',
'integer',
'float'),
2544 array($next_id, $if_question_id, $relation, $value)
2548 $constraint_id = $next_id;
2549 $next_id = $ilDB->nextId(
'svy_qst_constraint');
2550 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_qst_constraint (question_constraint_id, survey_fi, question_fi, ".
2551 "constraint_fi) VALUES (%s, %s, %s, %s)",
2552 array(
'integer',
'integer',
'integer',
'integer'),
2553 array($next_id, $this->
getSurveyId(), $to_question_id, $constraint_id)
2571 $result = $ilDB->queryF(
"SELECT constraint_fi FROM svy_qst_constraint WHERE question_fi = %s AND survey_fi = %s",
2572 array(
'integer',
'integer'),
2578 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_constraint SET question_fi = %s, relation_fi = %s, value = %s ".
2579 "WHERE constraint_id = %s",
2580 array(
'integer',
'integer',
'float',
'integer'),
2581 array($if_question_id, $relation, $value,
$row[
"constraint_fi"])
2595 $result_array = array();
2596 $result = $ilDB->query(
"SELECT * FROM svy_relation");
2601 $result_array[
$row[
"shortname"]] = array(
"short" => $row[
"shortname"],
"long" => $row[
"longname"],
"id" => $row[
"relation_id"]);
2605 $result_array[
$row[
"relation_id"]] = array(
"short" => $row[
"shortname"],
"long" => $row[
"longname"]);
2608 return $result_array;
2617 $result = $ilDB->queryF(
"SELECT user_fi FROM svy_inv_usr WHERE survey_fi = %s",
2636 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_inv_usr WHERE survey_fi = %s AND user_fi = %s",
2637 array(
'integer',
'integer'),
2640 include_once
'./Services/User/classes/class.ilObjUser.php';
2654 $result = $ilDB->queryF(
"SELECT user_fi FROM svy_inv_usr WHERE user_fi = %s AND survey_fi = %s",
2655 array(
'integer',
'integer'),
2660 $next_id = $ilDB->nextId(
'svy_inv_usr');
2661 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_inv_usr (invited_user_id, survey_fi, user_fi, tstamp) " .
2662 "VALUES (%s, %s, %s, %s)",
2663 array(
'integer',
'integer',
'integer',
'integer'),
2664 array($next_id, $this->
getSurveyId(), $user_id, time())
2669 include_once
'./Services/User/classes/class.ilObjUser.php';
2684 include_once
"./Modules/Group/classes/class.ilObjGroup.php";
2686 $members = $group->getGroupMemberIds();
2687 foreach ($members as $user_id)
2689 if ($ilAccess->checkAccessOfUser($user_id,
"read",
"", $this->getRefId(),
"svy", $this->
getId()))
2694 include_once
'./Services/User/classes/class.ilObjUser.php';
2713 $members = $rbacreview->assignedUsers($role_id);
2714 foreach ($members as $user_id)
2716 if ($ilAccess->checkAccessOfUser($user_id,
"read",
"", $this->getRefId(),
"svy", $this->
getId()))
2721 include_once
'./Services/User/classes/class.ilObjUser.php';
2739 $result_array = array();
2740 $result = $ilDB->queryF(
"SELECT user_fi FROM svy_inv_usr WHERE survey_fi = %s",
2746 array_push($result_array,
$row[
"user_fi"]);
2748 return $result_array;
2762 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_answer WHERE question_fi = %s AND active_fi = %s",
2763 array(
'integer',
'integer'),
2764 array($question_id, $active_id)
2779 $result_array = array();
2780 $result = $ilDB->queryF(
"SELECT * FROM svy_answer WHERE question_fi = %s AND active_fi = %s",
2781 array(
'integer',
'integer'),
2782 array($question_id, $active_id)
2788 array_push($result_array,
$row);
2790 return $result_array;
2794 return $result_array;
2811 $active_id = $ilDB->nextId(
'svy_finished');
2812 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_finished (finished_id, survey_fi, user_fi, anonymous_id, state, tstamp) ".
2813 "VALUES (%s, %s, %s, %s, %s, %s)",
2814 array(
'integer',
'integer',
'integer',
'text',
'text',
'integer'),
2815 array($active_id, $this->
getSurveyId(), $user_id, $anonymous_id, 1, time())
2819 foreach ($pages as
$key => $question_array)
2821 foreach ($question_array as $question)
2824 require_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
2826 $question->saveRandomData($active_id);
2842 if ($this->
getAnonymize() && (strlen($anonymous_id) == 0))
return;
2844 if (strcmp($user_id,
"") == 0)
2846 if ($user_id == ANONYMOUS_USER_ID)
2851 $next_id = $ilDB->nextId(
'svy_finished');
2852 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_finished (finished_id, survey_fi, user_fi, anonymous_id, state, tstamp) ".
2853 "VALUES (%s, %s, %s, %s, %s, %s)",
2854 array(
'integer',
'integer',
'integer',
'text',
'text',
'integer'),
2855 array($next_id, $this->
getSurveyId(), $user_id, $anonymous_id, 0, time())
2872 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_finished SET state = %s, user_fi = %s, tstamp = %s ".
2873 "WHERE survey_fi = %s AND anonymous_id = %s",
2874 array(
'text',
'integer',
'integer',
'integer',
'text'),
2875 array(1, $user_id, time(), $this->
getSurveyId(), $anonymize_id)
2880 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_finished SET state = %s, tstamp = %s WHERE survey_fi = %s AND user_fi = %s",
2881 array(
'text',
'integer',
'integer',
'integer'),
2901 if (strlen($username) == 0)
2904 $userid = $ilUser->getId();
2907 $surveysetting =
new ilSetting(
"survey");
2908 $allowedUsers = strlen($surveysetting->get(
"multiple_survey_users")) ? explode(
",",$surveysetting->get(
"multiple_survey_users")) : array();
2909 if (in_array($userid, $allowedUsers))
2933 $result = $ilDB->queryF(
"SELECT * FROM svy_finished WHERE survey_fi = %s AND user_fi = %s",
2934 array(
'integer',
'integer'),
2940 $result = $ilDB->queryF(
"SELECT * FROM svy_finished WHERE survey_fi = %s AND anonymous_id = %s",
2941 array(
'integer',
'text'),
2948 $result = $ilDB->queryF(
"SELECT * FROM svy_finished WHERE survey_fi = %s AND user_fi = %s",
2949 array(
'integer',
'integer'),
2961 return (
int)
$row[
"state"];
2975 $result = $ilDB->queryF(
"SELECT question_fi, tstamp FROM svy_answer WHERE active_fi = %s ORDER BY tstamp DESC",
2986 return $row[
"question_fi"];
3000 if (count($working_data) == 0)
3005 if ((count($working_data) == 1) and (strcmp($working_data[0][
"value"],
"") == 0))
3010 foreach ($working_data as
$data)
3012 switch ($constraint_data[
"short"])
3015 if ($data[
"value"] < $constraint_data[
"value"])
3021 if ($data[
"value"] <= $constraint_data[
"value"])
3027 if ($data[
"value"] == $constraint_data[
"value"])
3033 if ($data[
"value"] != $constraint_data[
"value"])
3039 if ($data[
"value"] >= $constraint_data[
"value"])
3045 if ($data[
"value"] > $constraint_data[
"value"])
3059 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE survey_fi = %s",
3063 return (
$result->numRows()) ?
true :
false;
3077 $result = $ilDB->queryF(
"SELECT * FROM svy_finished WHERE survey_fi = %s",
3085 array_push($users,
$row[
"finished_id"]);
3102 $result = $ilDB->queryF(
"SELECT * FROM svy_finished WHERE survey_fi = %s",
3110 array_push($users,
$row);
3113 $evaluation = array();
3115 foreach (
$questions as $question_id => $question_data)
3117 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
3120 $question =
new $question_type();
3121 $question->loadFromDb($question_id);
3123 $evaluation[$question_id] =
$data;
3139 $surveySetting =
new ilSetting(
"survey");
3140 $use_anonymous_id = array_key_exists(
"use_anonymous_id",
$_GET) ?
$_GET[
"use_anonymous_id"] : $surveySetting->get(
"use_anonymous_id");
3141 $result = $ilDB->queryF(
"SELECT * FROM svy_finished WHERE finished_id = %s",
3146 $foundrows =
$result->numRows();
3151 $name = ($use_anonymous_id) ?
$row[
"anonymous_id"] : $this->lng->txt(
"anonymous");
3153 "fullname" =>
$name,
3154 "sortname" =>
$name,
3159 "active_id" =>
"$active_id"
3163 if ((
$row[
"user_fi"] > 0) && (
$row[
"user_fi"] != ANONYMOUS_USER_ID) && ($this->
getAnonymize() == 0))
3165 include_once
'./Services/User/classes/class.ilObjUser.php';
3168 $userdata[
"fullname"] = $this->lng->txt(
"deleted_user");
3173 $userdata[
"fullname"] =
$user->getFullname();
3174 $gender =
$user->getGender();
3175 if (strlen($gender) == 1) $gender = $this->lng->txt(
"gender_$gender");
3176 $userdata[
"gender"] = $gender;
3177 $userdata[
"firstname"] =
$user->getFirstname();
3178 $userdata[
"lastname"] =
$user->getLastname();
3179 $userdata[
"sortname"] =
$user->getLastname() .
", " .
$user->getFirstname();
3180 $userdata[
"login"] =
$user->getLogin();
3202 $result = $ilDB->queryF(
"SELECT * FROM svy_answer WHERE active_fi = %s",
3208 if (!is_array($answers[
$row[
"question_fi"]]))
3210 $answers[$row[
"question_fi"]] = array();
3212 array_push($answers[$row[
"question_fi"]], $row);
3216 "name" => $userdata[
"fullname"],
3217 "gender" => $userdata[
"gender"],
3218 "answers" => array()
3222 if (array_key_exists(
$key, $answers))
3224 $resultset[
"answers"][
$key] = $answers[
$key];
3228 $resultset[
"answers"][
$key] = array();
3230 sort($resultset[
"answers"][
$key]);
3247 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE survey_fi = %s",
3251 $nr_of_users =
$result->numRows();
3253 $result_array =& $question->getCumulatedResults($this->
getSurveyId(), $nr_of_users);
3254 return $result_array;
3268 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE survey_fi = %s",
3277 $result_array = array();
3278 $result =
$ilDB->query(
"SELECT svy_question.*, svy_qtype.type_tag FROM svy_question, svy_qtype WHERE ".
3279 "svy_question.questiontype_fi = svy_qtype.questiontype_id AND svy_question.tstamp > 0 AND ".
3280 $ilDB->in(
'svy_question.question_id', $question_ids,
false,
'integer'));
3283 array_push($result_array,
$row);
3285 return $result_array;
3298 if (is_array($arrFilter))
3300 if (array_key_exists(
'title', $arrFilter) && strlen($arrFilter[
'title']))
3302 $where .=
" AND " . $ilDB->like(
'svy_question.title',
'text',
"%%" . $arrFilter[
'title'] .
"%%");
3304 if (array_key_exists(
'description', $arrFilter) && strlen($arrFilter[
'description']))
3306 $where .=
" AND " . $ilDB->like(
'svy_question.description',
'text',
"%%" . $arrFilter[
'description'] .
"%%");
3308 if (array_key_exists(
'author', $arrFilter) && strlen($arrFilter[
'author']))
3310 $where .=
" AND " . $ilDB->like(
'svy_question.author',
'text',
"%%" . $arrFilter[
'author'] .
"%%");
3312 if (array_key_exists(
'type', $arrFilter) && strlen($arrFilter[
'type']))
3314 $where .=
" AND svy_qtype.type_tag = " . $ilDB->quote($arrFilter[
'type'],
'text');
3316 if (array_key_exists(
'spl', $arrFilter) && strlen($arrFilter[
'spl']))
3318 $where .=
" AND svy_question.obj_fi = " . $ilDB->quote($arrFilter[
'spl'],
'integer');
3324 $forbidden =
" AND " . $ilDB->in(
'svy_question.obj_fi', array_keys($spls),
false,
'integer');
3325 $forbidden .=
" AND svy_question.complete = " . $ilDB->quote(
"1",
'text');
3328 if (count($existing_questions))
3330 $existing =
" AND " . $ilDB->in(
'svy_question.question_id', $existing_questions,
true,
'integer');
3333 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
3336 $query_result = $ilDB->query(
"SELECT svy_question.*, svy_qtype.type_tag, svy_qtype.plugin, object_reference.ref_id FROM svy_question, svy_qtype, object_reference WHERE svy_question.original_id IS NULL$forbidden$existing AND svy_question.obj_fi = object_reference.obj_id AND svy_question.tstamp > 0 AND svy_question.questiontype_fi = svy_qtype.questiontype_id " . $where);
3339 if ($query_result->numRows())
3341 while (
$row = $ilDB->fetchAssoc($query_result))
3343 $row[
'ttype'] = $trans[
$row[
'type_tag']];
3348 array_push($rows, $row);
3353 array_push($rows, $row);
3370 if (is_array($arrFilter))
3372 if (array_key_exists(
'title', $arrFilter) && strlen($arrFilter[
'title']))
3374 $where .=
" AND " . $ilDB->like(
'svy_qblk.title',
'text',
"%%" . $arrFilter[
'title'] .
"%%");
3378 $query_result = $ilDB->query(
"SELECT svy_qblk.*, svy_svy.obj_fi FROM svy_qblk , svy_qblk_qst, svy_svy WHERE ".
3379 "svy_qblk.questionblock_id = svy_qblk_qst.questionblock_fi AND svy_svy.survey_id = svy_qblk_qst.survey_fi ".
3380 "$where GROUP BY svy_qblk.questionblock_id, svy_qblk.title, svy_qblk.show_questiontext, svy_qblk.owner_fi, svy_qblk.tstamp, svy_svy.obj_fi");
3382 if ($query_result->numRows())
3385 $surveytitles = array();
3386 foreach ($surveys as
$data)
3388 $surveytitles[$data[
'id']] = $data[
'title'];
3390 while (
$row = $ilDB->fetchAssoc($query_result))
3394 foreach ($questions_array as
$key => $value)
3396 $questions_array[
$key] =
"$counter. $value";
3399 if (strlen($surveytitles[
$row[
"obj_fi"]]))
3401 $rows[$row[
"questionblock_id"]] = array(
3402 "questionblock_id" => $row[
"questionblock_id"],
3403 "title" => $row[
"title"],
3404 "svy" => $surveytitles[$row[
"obj_fi"]],
3405 "contains" => join($questions_array,
", "),
3406 "owner" => $row[
"owner_fi"]
3422 include_once(
"./classes/class.ilXmlWriter.php");
3427 "xmlns:xsi" =>
"http://www.w3.org/2001/XMLSchema-instance",
3428 "xsi:noNamespaceSchemaLocation" =>
"http://www.ilias.de/download/xsd/ilias_survey_3_8.xsd"
3430 $a_xml_writer->xmlStartTag(
"surveyobject", $attrs);
3435 $a_xml_writer->xmlStartTag(
"survey", $attrs);
3437 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
3438 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
3439 $a_xml_writer->xmlStartTag(
"objectives");
3441 "label" =>
"introduction"
3448 $a_xml_writer->xmlEndTag(
"objectives");
3452 $attribs = array(
"enabled" =>
"1");
3456 $attribs = array(
"enabled" =>
"0");
3458 $a_xml_writer->xmlElement(
"anonymisation", $attribs);
3459 $a_xml_writer->xmlStartTag(
"restrictions");
3462 $attribs = array(
"type" =>
"free");
3466 $attribs = array(
"type" =>
"restricted");
3468 $a_xml_writer->xmlElement(
"access", $attribs);
3471 $attrs = array(
"type" =>
"date");
3476 $attrs = array(
"type" =>
"date");
3477 $a_xml_writer->xmlElement(
"endingtime", $attrs, sprintf(
"%04d-%02d-%02dT00:00:00", $this->
getEndYear(), $this->
getEndMonth(), $this->
getEndDay()));
3479 $a_xml_writer->xmlEndTag(
"restrictions");
3483 $hasconstraints = FALSE;
3484 foreach ($pages as $question_array)
3486 foreach ($question_array as $question)
3488 if (count($question[
"constraints"]))
3490 $hasconstraints = TRUE;
3495 if ($hasconstraints)
3497 $a_xml_writer->xmlStartTag(
"constraints");
3498 foreach ($pages as $question_array)
3500 foreach ($question_array as $question)
3502 if (count($question[
"constraints"]))
3505 foreach ($question[
"constraints"] as $constraint)
3508 "sourceref" => $question[
"question_id"],
3509 "destref" => $constraint[
"question"],
3510 "relation" => $constraint[
"short"],
3511 "value" => $constraint[
"value"]
3513 $a_xml_writer->xmlElement(
"constraint", $attribs);
3518 $a_xml_writer->xmlEndTag(
"constraints");
3522 $a_xml_writer->xmlStartTag(
"metadata");
3524 $a_xml_writer->xmlStartTag(
"metadatafield");
3525 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"evaluation_access");
3527 $a_xml_writer->xmlEndTag(
"metadatafield");
3529 $a_xml_writer->xmlStartTag(
"metadatafield");
3530 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"status");
3531 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->
getStatus());
3532 $a_xml_writer->xmlEndTag(
"metadatafield");
3534 $a_xml_writer->xmlStartTag(
"metadatafield");
3535 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"display_question_titles");
3537 $a_xml_writer->xmlEndTag(
"metadatafield");
3539 $a_xml_writer->xmlStartTag(
"metadatafield");
3540 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"SCORM");
3541 include_once
"./Services/MetaData/classes/class.ilMD.php";
3544 $md->toXml($writer);
3545 $metadata = $writer->xmlDumpMem();
3546 $a_xml_writer->xmlElement(
"fieldentry", NULL, $metadata);
3547 $a_xml_writer->xmlEndTag(
"metadatafield");
3549 $a_xml_writer->xmlEndTag(
"metadata");
3550 $a_xml_writer->xmlEndTag(
"survey");
3552 $attribs = array(
"id" => $this->
getId());
3553 $a_xml_writer->xmlStartTag(
"surveyquestions", $attribs);
3556 foreach ($pages as $question_array)
3558 if (count($question_array) > 1)
3560 $attribs = array(
"id" => $question_array[0][
"question_id"]);
3561 $attribs = array(
"showQuestiontext" => $question_array[0][
"questionblock_show_questiontext"]);
3562 $a_xml_writer->xmlStartTag(
"questionblock", $attribs);
3563 if (strlen($question_array[0][
"questionblock_title"]))
3565 $a_xml_writer->xmlElement(
"questionblocktitle", NULL, $question_array[0][
"questionblock_title"]);
3568 foreach ($question_array as $question)
3570 if (strlen($question[
"heading"]))
3572 $a_xml_writer->xmlElement(
"textblock", NULL, $question[
"heading"]);
3575 if ($questionObject !== FALSE) $questionObject->insertXML($a_xml_writer, FALSE, $obligatory_states[$question[
"question_id"]]);
3577 if (count($question_array) > 1)
3579 $a_xml_writer->xmlEndTag(
"questionblock");
3583 $a_xml_writer->xmlEndTag(
"surveyquestions");
3584 $a_xml_writer->xmlEndTag(
"surveyobject");
3585 $xml = $a_xml_writer->xmlDumpMem(FALSE);
3598 if ($question_id < 1)
return FALSE;
3599 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
3601 if (strlen($question_type) == 0)
return FALSE;
3603 $question =
new $question_type();
3604 $question->loadFromDb($question_id);
3616 if (!is_dir($a_dir) || is_int(strpos($a_dir,
"..")))
3620 $importDirectory =
"";
3623 $current_dir = opendir($a_dir);
3625 while($entryname = readdir($current_dir))
3632 if(is_dir($a_dir.
"/".$file) and ($file !=
"." and $file!=
".."))
3635 $importDirectory = $a_dir.
"/".
$file;
3638 closedir($current_dir);
3639 if (strlen($importDirectory))
3642 $current_dir = opendir($importDirectory);
3644 while($entryname = readdir($current_dir))
3650 if(@is_file($importDirectory.
"/".$file) && ($file !=
"." && $file!=
"..") && (strcmp(strtolower(substr($file, -4, 4)),
".xml") == 0))
3653 $xmlFile = $importDirectory.
"/".
$file;
3657 return array(
"dir" => $importDirectory,
"xml" => $xmlFile);
3669 $source = $file_info[
"tmp_name"];
3671 if (($source ==
'none') || (!$source) || $file_info[
"error"] > UPLOAD_ERR_OK)
3673 $error = $this->lng->txt(
"import_no_file_selected");
3678 if ((strcmp($file_info[
"type"],
"text/xml") == 0) || (strcmp($file_info[
"type"],
"application/xml") == 0))
3682 if (strpos($file_info[
"type"],
"zip") !== FALSE)
3686 if (!$isXml && !$isZip)
3688 $error = $this->lng->txt(
"import_wrong_file_type");
3690 $ilLog->write(
"Survey: Import error. Filetype was \"" . $file_info[
"type"] .
"\"");
3696 $import_subdir =
"";
3698 include_once
"./Services/Utilities/classes/class.ilUtil.php";
3701 $importfile = $import_dir.
"/".$file_info[
"name"];
3705 if (!((strlen($found[
"dir"]) > 0) && (strlen($found[
"xml"]) > 0)))
3707 $error = $this->lng->txt(
"wrong_import_file_structure");
3710 $importfile = $found[
"xml"];
3711 $import_subdir = $found[
"dir"];
3715 $importfile = tempnam($import_dir,
"survey_import");
3718 $fh = fopen($importfile,
"r");
3721 $error = $this->lng->txt(
"import_error_opening_file");
3724 $xml = fread($fh, filesize($importfile));
3728 $error = $this->lng->txt(
"import_error_closing_file");
3733 if (strpos($xml,
"questestinterop"))
3735 include_once
"./Services/Survey/classes/class.SurveyImportParserPre38.php";
3736 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
3739 $import->setSurveyObject($this);
3740 $import->setXMLContent($xml);
3741 $import->startParsing();
3745 include_once
"./Services/Survey/classes/class.SurveyImportParser.php";
3746 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
3749 $import->setSurveyObject($this);
3750 $import->setXMLContent($xml);
3751 $import->startParsing();
3754 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
3756 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
3757 include_once
"./Services/RTE/classes/class.ilRTE.php";
3758 include_once
"./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
3759 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
3761 $importfile = $import_subdir .
"/" . $mob[
"uri"];
3762 if (file_exists($importfile))
3766 $this->
setIntroduction(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $this->
getIntroduction()));
3767 $this->
setOutro(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $this->
getOutro()));
3772 $ilLog->write(
"Error: Could not open XHTML mob file for test introduction during test import. File $importfile does not exist!");
3807 $newObj->setOutro($this->
getOutro());
3820 $question_pointer = array();
3823 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
3824 foreach ($this->questions as
$key => $question_id)
3829 $question->saveToDb($original_id);
3830 $newObj->questions[
$key] = $question->getId();
3831 $question_pointer[$question_id] = $question->getId();
3832 $mapping[$question_id] = $question->getId();
3835 $newObj->saveToDb();
3836 $newObj->cloneTextblocks($mapping);
3839 $questionblocks = array();
3840 $questionblock_questions = array();
3841 $result = $ilDB->queryF(
"SELECT * FROM svy_qblk_qst WHERE survey_fi = %s",
3849 array_push($questionblock_questions,
$row);
3850 $questionblocks[
$row[
"questionblock_fi"]] = $row[
"questionblock_fi"];
3854 foreach ($questionblocks as
$key => $value)
3858 $questionblocks[
$key] = $questionblock_id;
3861 foreach ($questionblock_questions as
$key => $value)
3863 $next_id = $ilDB->nextId(
'svy_qblk_qst');
3864 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_qblk_qst (qblk_qst_id, survey_fi, questionblock_fi, question_fi) ".
3865 "VALUES (%s, %s, %s, %s)",
3866 array(
'integer',
'integer',
'integer',
'integer'),
3867 array($next_id, $newObj->getSurveyId(), $questionblocks[$value[
"questionblock_fi"]], $question_pointer[$value[
"question_fi"]])
3873 foreach ($constraints as
$key => $constraint)
3875 $newObj->addConstraint($question_pointer[$constraint[
"for_question"]], $question_pointer[$constraint[
"question"]], $constraint[
"relation_id"], $constraint[
"value"]);
3879 $result = $ilDB->queryF(
"SELECT * FROM svy_qst_oblig WHERE survey_fi = %s",
3887 $next_id = $ilDB->nextId(
'svy_qst_oblig');
3888 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_qst_oblig (question_obligatory_id, survey_fi, question_fi, ".
3889 "obligatory, tstamp) VALUES (%s, %s, %s, %s, %s)",
3890 array(
'integer',
'integer',
'integer',
'text',
'integer'),
3891 array($next_id, $newObj->getSurveyId(), $question_pointer[
$row[
"question_fi"]], $row[
"obligatory"], time())
3901 $result = $ilDB->queryF(
"SELECT * FROM svy_svy_qst WHERE question_fi = %s",
3908 return $row[
"heading"];
3923 foreach ($mapping as $original_id => $new_id)
3926 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
3938 include_once
"./Services/Utilities/classes/class.ilUtil.php";
3941 if(!is_writable($svy_data_dir))
3943 $this->ilias->raiseError(
"Survey Data Directory (".$svy_data_dir
3944 .
") not writeable.",$this->ilias->error_obj->FATAL);
3948 $svy_dir = $svy_data_dir.
"/svy_".$this->
getId();
3950 if(!@is_dir($svy_dir))
3952 $this->ilias->raiseError(
"Creation of Survey Directory failed.",$this->ilias->error_obj->FATAL);
3955 $export_dir = $svy_dir.
"/export";
3957 if(!@is_dir($export_dir))
3959 $this->ilias->raiseError(
"Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
3968 include_once
"./Services/Utilities/classes/class.ilUtil.php";
3980 if (!@is_dir(
$dir) or
3981 !is_writeable(
$dir))
3993 while ($entry =
$dir->read())
3995 if ($entry !=
"." and
3997 ereg(
"^[0-9]{10}_{2}[0-9]+_{2}(survey__)*[0-9]+\.xml|zip\$", $entry))
4019 include_once
"./Services/Utilities/classes/class.ilUtil.php";
4023 if(!is_writable($svy_data_dir))
4025 $this->ilias->raiseError(
"Survey Data Directory (".$svy_data_dir
4026 .
") not writeable.",$this->ilias->error_obj->FATAL);
4030 $svy_dir = $svy_data_dir.
"/svy_".$this->
getId();
4032 if(!@is_dir($svy_dir))
4034 $this->ilias->raiseError(
"Creation of Survey Directory failed.",$this->ilias->error_obj->FATAL);
4038 $import_dir = $svy_dir.
"/import";
4040 if(!@is_dir($import_dir))
4042 $this->ilias->raiseError(
"Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
4051 include_once
"./Services/Utilities/classes/class.ilUtil.php";
4053 "/svy_".$this->getId().
"/import";
4054 if (!is_dir($import_dir))
4058 if(@is_dir($import_dir))
4073 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_svy_qst SET heading=%s WHERE survey_fi=%s AND question_fi=%s",
4074 array(
'text',
'integer',
'integer'),
4075 array($heading, $this->
getSurveyId(), $insertbefore)
4080 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_svy_qst SET heading=%s WHERE survey_fi=%s AND question_fi=%s",
4081 array(
'text',
'integer',
'integer'),
4091 $result = $ilDB->queryF(
"SELECT anonymous_id FROM svy_anonymous WHERE survey_key = %s AND survey_fi = %s",
4092 array(
'text',
'integer'),
4095 return (
$result->numRows() == 1) ?
true :
false;
4103 $result = $ilDB->queryF(
"SELECT anonymous_id FROM svy_finished WHERE survey_fi = %s AND user_fi = %s",
4104 array(
'integer',
'integer'),
4110 return $row[
"anonymous_id"];
4122 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE anonymous_id = %s AND survey_fi = %s",
4123 array(
'text',
'integer'),
4126 return (
$result->numRows() == 1) ?
true :
false;
4158 $result = $ilDB->queryF(
"SELECT anonymous_id FROM svy_anonymous WHERE survey_fi = %s AND user_key IS NULL",
4176 $result = $ilDB->queryF(
"SELECT svy_anonymous.*, svy_finished.state FROM svy_anonymous ".
4177 "LEFT JOIN svy_finished ON svy_anonymous.survey_key = svy_finished.anonymous_id ".
4178 "WHERE svy_anonymous.survey_fi = %s AND svy_anonymous.user_key IS NULL",
4186 if (in_array(
$row[
"survey_key"], $a_array) || (count($a_array) == 0))
4188 $export .=
$row[
"survey_key"] .
",";
4193 $export .=
"$created,";
4202 $url = ILIAS_HTTP_PATH.
"/goto.php?cmd=infoScreen&target=svy_".$this->
getRefId() .
"&client_id=" . CLIENT_ID .
"&accesscode=".$row[
"survey_key"].$lang;
4203 $export .= $url .
"\n";
4220 include_once
"./classes/class.ilFormat.php";
4223 $order =
"ORDER BY tstamp, survey_key ASC";
4225 $result = $ilDB->queryF(
"SELECT svy_anonymous.anonymous_id, svy_anonymous.survey_key, svy_anonymous.survey_fi, ".
4226 "svy_anonymous.tstamp, svy_finished.state FROM svy_anonymous LEFT JOIN svy_finished ".
4227 "ON svy_anonymous.survey_key = svy_finished.anonymous_id WHERE svy_anonymous.survey_fi = %s ".
4228 "AND svy_anonymous.user_key IS NULL $order",
4249 $addlang =
"&lang=$lang";
4251 $href = ILIAS_HTTP_PATH.
"/goto.php?cmd=infoScreen&target=svy_".$this->
getRefId() .
"&client_id=" . CLIENT_ID .
"&accesscode=".$row[
"survey_key"].$addlang;
4252 $url = $this->lng->txt(
"survey_code_url_name");
4254 array_push($codes, array(
'code' =>
$row[
"survey_key"],
'date' => $created,
'used' => $state,
'url' => $url,
'href' => $href));
4263 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE survey_fi = %s AND anonymous_id = %s",
4264 array(
'integer',
'text'),
4267 return (
$result->numRows() > 0) ?
true :
false;
4273 $result = $ilDB->queryF(
"SELECT anonymous_id FROM svy_anonymous WHERE survey_fi = %s AND survey_key = %s",
4274 array(
'integer',
'text'),
4277 return (
$result->numRows() > 0) ?
false :
true;
4283 for ($i = 0; $i < $nrOfCodes; $i++)
4286 $next_id = $ilDB->nextId(
'svy_anonymous');
4287 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_anonymous (anonymous_id, survey_key, survey_fi, tstamp) ".
4288 "VALUES (%s, %s, %s, %s)",
4289 array(
'integer',
'text',
'integer',
'integer'),
4290 array($next_id, $anonymize_key, $this->
getSurveyId(), time())
4304 if (strlen($survey_code) > 0)
4306 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_anonymous WHERE survey_fi = %s AND survey_key = %s",
4307 array(
'integer',
'text'),
4323 $result = $ilDB->queryF(
"SELECT survey_key FROM svy_anonymous WHERE survey_fi = %s AND user_key = %s",
4324 array(
'integer',
'text'),
4330 $access_code =
$row[
"survey_key"];
4332 return $access_code;
4344 $next_id = $ilDB->nextId(
'svy_anonymous');
4345 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_anonymous (anonymous_id, survey_key, survey_fi, user_key, tstamp) ".
4346 "VALUES (%s, %s, %s, %s, %s)",
4347 array(
'integer',
'text',
'integer',
'text',
'integer'),
4348 array($next_id, $access_code, $this->
getSurveyId(), md5($user_id), time())
4360 $codestring =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
4363 for ($i = 1; $i <=5; $i++)
4365 $index = mt_rand(0, strlen($codestring)-1);
4366 $code .= substr($codestring, $index, 1);
4389 $resultarray = array();
4390 foreach (
$row as $rowindex => $entry)
4397 if (strpos($entry,
"\"") !== FALSE)
4399 $entry = str_replace(
"\"",
"\"\"", $entry);
4407 $entry = str_replace(chr(13).chr(10), chr(10), $entry);
4410 $resultarray[$rowindex] = utf8_decode(
"\"" . $entry .
"\"");
4414 $resultarray[$rowindex] = utf8_decode($entry);
4417 return $resultarray;
4424 $result = $ilDB->queryF(
"SELECT tstamp FROM svy_answer WHERE active_fi = %s ORDER BY tstamp DESC",
4431 return $row[
"tstamp"];
4435 $result = $ilDB->queryF(
"SELECT tstamp FROM svy_finished WHERE finished_id = %s",
4442 return $row[
"tstamp"];
4456 include_once
"./Services/Utilities/classes/class.ilUtil.php";
4469 if (preg_match(
"/<[^>]*?>/", $a_text))
4487 function addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag = TRUE, $add_mobs = TRUE, $attribs = NULL)
4489 include_once
"./Services/RTE/classes/class.ilRTE.php";
4490 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
4492 $a_xml_writer->xmlStartTag(
"material", $attribs);
4494 "type" =>
"text/plain"
4496 if ($this->
isHTML($a_material))
4498 $attrs[
"type"] =
"text/xhtml";
4501 $a_xml_writer->xmlElement(
"mattext", $attrs, $mattext);
4506 foreach (
$mobs as $mob)
4508 $mob_id =
"il_" . IL_INST_ID .
"_mob_" . $mob;
4509 if (strpos($mattext, $mob_id) !== FALSE)
4514 "uri" =>
"objects/" .
"il_" . IL_INST_ID .
"_mob_" . $mob .
"/" . $mob_obj->getTitle()
4516 $a_xml_writer->xmlElement(
"matimage", $imgattrs, NULL);
4520 if ($close_material_tag) $a_xml_writer->xmlEndTag(
"material");
4535 if ($this->surveyCodeSecurity == FALSE)
4552 $print_output = str_replace(
" ",
" ", $print_output);
4553 $print_output = str_replace(
"⊗",
"X", $print_output);
4554 $xsl = file_get_contents(
"./Modules/Survey/xml/question2fo.xsl");
4555 $args = array(
'/_xml' => $print_output,
'/_xsl' => $xsl );
4561 global
$ilLog; $ilLog->write($output);
4575 include_once
"./Services/Utilities/classes/class.ilUtil.php";
4577 $fp = fopen($fo_file,
"w"); fwrite($fp, $fo); fclose($fp);
4579 include_once
'./Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
4588 $ilLog->write(__METHOD__.
': '.$e->getMessage());
4593 $ilLog->write(__METHOD__.
': '.$e->getMessage());
4610 $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
4616 include_once(
"./Modules/Survey/classes/class.ilObjSurveyAccess.php");
4641 global $ilPluginAdmin;
4642 if ($ilPluginAdmin->isActive(
IL_COMP_MODULE,
"SurveyQuestionPool",
"svyq", $a_pname))
4672 if (!is_array($ids) || count($ids) ==0)
return array();
4674 $result = $ilDB->query(
"SELECT usr_id, login, lastname, firstname FROM usr_data WHERE " . $ilDB->in(
'usr_id', $ids,
false,
'integer') .
" ORDER BY login");
4675 $result_array = array();
4678 $result_array[
$row[
"usr_id"]]=
$row;
4680 return $result_array;
4685 if (!is_array($ids) || count($ids) ==0)
return array();
4697 if (!is_array($ids) || count($ids) ==0)
return array();
4699 foreach ($ids as $obj_id)