34 include_once
"./classes/class.ilObject.php";
35 include_once
"./Modules/Survey/classes/inc.SurveyConstants.php";
191 $this->
ilObject($a_id,$a_call_by_reference);
193 $this->survey_id = -1;
194 $this->introduction =
"";
195 $this->outro = $this->lng->txt(
"survey_finished");
196 $this->author = $ilUser->fullname;
199 $this->startdate_enabled = 0;
200 $this->enddate_enabled = 0;
201 $this->questions = array();
206 $this->surveyCodeSecurity = TRUE;
244 if (!parent::update())
266 function read($a_force_db =
false)
280 array_push($this->questions, $question_id);
302 foreach ($this->questions as $question_id)
323 $query = sprintf(
"DELETE FROM survey_survey WHERE survey_id = %s",
324 $ilDB->quote($this->getSurveyId())
326 $result = $ilDB->query($query);
328 $query = sprintf(
"SELECT questionblock_fi FROM survey_questionblock_question WHERE survey_fi = %s",
329 $ilDB->quote($this->getSurveyId())
331 $result = $ilDB->query($query);
332 $questionblocks = array();
333 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
335 array_push($questionblocks, $row[
"questionblock_fi"]);
337 if (count($questionblocks))
339 $query =
"DELETE FROM survey_questionblock WHERE questionblock_id IN ('" . join($questionblocks,
"','") .
"')";
340 $result = $ilDB->query($query);
342 $query = sprintf(
"DELETE FROM survey_questionblock_question WHERE survey_fi = %s",
343 $ilDB->quote($this->getSurveyId())
345 $result = $ilDB->query($query);
349 $query = sprintf(
"DELETE FROM survey_anonymous WHERE survey_fi = %s",
350 $ilDB->quote($this->getSurveyId())
352 $result = $ilDB->query($query);
355 include_once
"./Services/Utilities/classes/class.ilUtil.php";
357 $directory = $svy_data_dir.
"/svy_".$this->
getId();
358 if (is_dir($directory))
360 include_once
"./Services/Utilities/classes/class.ilUtil.php";
364 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
370 foreach(
$mobs as $mob)
389 $query = sprintf(
"SELECT finished_id FROM survey_finished WHERE survey_fi = %s",
390 $ilDB->quote($this->getSurveyId())
392 $result = $ilDB->query($query);
393 $active_array = array();
394 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
396 array_push($active_array, $row[
"finished_id"]);
399 $query = sprintf(
"DELETE FROM survey_finished WHERE survey_fi = %s",
400 $ilDB->quote($this->getSurveyId())
402 $result = $ilDB->query($query);
404 foreach ($active_array as $active_fi)
406 $query = sprintf(
"DELETE FROM survey_answer WHERE active_fi = %s",
407 $ilDB->quote($active_fi)
409 $result = $ilDB->query($query);
424 foreach ($finished_ids as $finished_id)
426 $query = sprintf(
"SELECT finished_id FROM survey_finished WHERE finished_id = %s",
427 $ilDB->quote($finished_id .
"")
429 $result = $ilDB->query($query);
430 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
432 $query = sprintf(
"DELETE FROM survey_answer WHERE active_fi = %s",
433 $ilDB->quote($row[
"finished_id"] .
"")
435 $result = $ilDB->query($query);
437 $query = sprintf(
"DELETE FROM survey_finished WHERE finished_id = %s",
438 $ilDB->quote($finished_id .
"")
440 $result = $ilDB->query($query);
448 $query = sprintf(
"SELECT * FROM survey_finished WHERE survey_fi = %s",
449 $ilDB->quote($this->getSurveyId() .
"")
451 $result = $ilDB->query($query);
452 $participants = array();
455 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
458 $participants[$userdata[
"sortname"] . $userdata[
"active_id"]] = $userdata;
461 return $participants;
477 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
517 if ($a_node_id==
$_GET[
"ref_id"])
519 $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
520 $parent_type = $parent_obj->getType();
521 if($parent_type == $this->
getType())
523 $a_node_id = (int) $tree->getParentId($a_node_id);
527 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
561 $survey->loadFromDb();
562 if (($survey->getTitle()) and ($survey->getAuthor()) and (count($survey->questions)))
583 $survey->loadFromDb();
585 if (($survey->getTitle()) and ($survey->author) and (count($survey->questions)))
593 $result[
"evaluation_access"] = $survey->getEvaluationAccess();
613 if ($this->survey_id > 0)
615 $query = sprintf(
"UPDATE survey_survey SET complete = %s WHERE survey_id = %s",
616 $ilDB->quote(
"$complete"),
617 $ilDB->quote($this->survey_id)
619 $result = $ilDB->query($query);
637 $question_gui = $this->
getQuestionGUI($questiontype, $question_id);
638 $duplicate_id = $question_gui->object->duplicate(
true);
639 return $duplicate_id;
653 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
661 $query = sprintf(
"SELECT survey_question_id FROM survey_survey_question WHERE survey_fi = %s",
662 $ilDB->quote($this->getSurveyId())
664 $result = $ilDB->query($query);
665 $sequence =
$result->numRows();
667 $query = sprintf(
"INSERT INTO survey_survey_question (survey_question_id, survey_fi, question_fi, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
668 $ilDB->quote($this->getSurveyId()),
669 $ilDB->quote($duplicate_id),
670 $ilDB->quote($sequence)
672 $result = $ilDB->query($query);
673 if (PEAR::isError($result))
676 $ilias->raiseError($result->getMessage());
695 $query = sprintf(
"SELECT survey_questionblock.title, survey_questionblock.show_questiontext, survey_questionblock_question.question_fi FROM survey_questionblock, survey_questionblock_question, survey_survey_question WHERE survey_questionblock.questionblock_id = survey_questionblock_question.questionblock_fi AND survey_survey_question.question_fi = survey_questionblock_question.question_fi AND survey_questionblock.questionblock_id = %s ORDER BY survey_survey_question.sequence",
696 $ilDB->quote($questionblock_id)
698 $result = $ilDB->query($query);
700 $show_questiontext = 0;
701 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
706 $show_questiontext = $row[
"show_questiontext"];
735 include_once(
"./Services/RTE/classes/class.ilRTE.php");
736 $completecontent =
"";
739 $completecontent .= $content;
761 if (!$startdate or !$this->startdate_enabled)
767 $startdate = $ilDB->quote($startdate);
770 if (!$enddate or !$this->enddate_enabled)
776 $enddate = $ilDB->quote($enddate);
782 if ($this->survey_id == -1)
786 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
787 $query = sprintf(
"INSERT INTO survey_survey (survey_id, obj_fi, author, introduction, outro, status, startdate, enddate, evaluation_access, invitation, invitation_mode, complete, created, anonymize, show_question_titles, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
788 $ilDB->quote($this->getId()),
789 $ilDB->quote($this->author .
""),
792 $ilDB->quote($this->status .
""),
795 $ilDB->quote($this->evaluation_access .
""),
796 $ilDB->quote($this->invitation .
""),
797 $ilDB->quote($this->invitation_mode .
""),
798 $ilDB->quote($complete .
""),
801 $ilDB->quote($created)
803 $result = $ilDB->query($query);
804 if (PEAR::isError($result))
807 $ilias->raiseError($result->getMessage());
811 $this->survey_id = $ilDB->getLastInsertId();
817 $query = sprintf(
"UPDATE survey_survey SET author = %s, introduction = %s, outro = %s, status = %s, startdate = %s, enddate = %s, evaluation_access = %s, invitation = %s, invitation_mode = %s, complete = %s, anonymize = %s, show_question_titles = %s WHERE survey_id = %s",
818 $ilDB->quote($this->author .
""),
821 $ilDB->quote($this->status .
""),
824 $ilDB->quote($this->evaluation_access .
""),
825 $ilDB->quote($this->invitation .
""),
826 $ilDB->quote($this->invitation_mode .
""),
827 $ilDB->quote($complete .
""),
830 $ilDB->quote($this->survey_id)
832 $result = $ilDB->query($query);
837 $ilias->raiseError(
$result->getMessage());
858 $old_questions = array();
859 $query = sprintf(
"SELECT * FROM survey_survey_question WHERE survey_fi = %s",
860 $ilDB->quote($this->getSurveyId())
862 $result = $ilDB->query($query);
865 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
867 $old_questions[$row[
"question_fi"]] = $row;
872 $query = sprintf(
"DELETE FROM survey_survey_question WHERE survey_fi = %s",
873 $ilDB->quote($this->getSurveyId())
875 $result = $ilDB->query($query);
877 foreach ($this->questions as $key => $value)
879 $query = sprintf(
"INSERT INTO survey_survey_question (survey_question_id, survey_fi, question_fi, heading, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
880 $ilDB->quote($this->getSurveyId() .
""),
881 $ilDB->quote($value .
""),
882 $ilDB->quote($old_questions[$value][
"heading"]),
883 $ilDB->quote($key .
"")
885 $result = $ilDB->query($query);
901 $query = sprintf(
"SELECT anonymous_id FROM survey_finished WHERE anonymous_id = %s",
904 $result = $ilDB->query($query);
905 if ($result->numRows())
907 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
908 return $row[
"anonymous_id"];
926 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
942 if ($question_id < 1)
return -1;
943 $query = sprintf(
"SELECT type_tag FROM survey_question, survey_questiontype WHERE survey_question.question_id = %s AND survey_question.questiontype_fi = survey_questiontype.questiontype_id",
944 $ilDB->quote($question_id)
946 $result = $ilDB->query($query);
947 if ($result->numRows() == 1)
949 $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
950 return $data->type_tag;
976 $this->anonymize = $a_anonymize;
1016 $query = sprintf(
"SELECT * FROM survey_survey WHERE obj_fi = %s",
1017 $ilDB->quote($this->getId())
1019 $result = $ilDB->query($query);
1023 $this->survey_id =
$data->survey_id;
1029 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1031 if (strcmp(
$data->outro,
"survey_finished") == 0)
1033 $this->
setOutro($this->lng->txt(
"survey_finished"));
1039 $this->status =
$data->status;
1040 $this->invitation =
$data->invitation;
1041 $this->invitation_mode =
$data->invitation_mode;
1042 $this->display_question_titles =
$data->show_question_titles;
1043 $this->start_date =
$data->startdate;
1044 if (!
$data->startdate)
1046 $this->startdate_enabled = 0;
1050 $this->startdate_enabled = 1;
1052 $this->end_date =
$data->enddate;
1053 if (!
$data->enddate)
1055 $this->enddate_enabled = 0;
1059 $this->enddate_enabled = 1;
1061 switch (
$data->anonymize)
1072 $this->evaluation_access =
$data->evaluation_access;
1088 $this->questions = array();
1089 $query = sprintf(
"SELECT * FROM survey_survey_question WHERE survey_fi = %s ORDER BY sequence",
1090 $ilDB->quote($this->survey_id)
1092 $result = $ilDB->query($query);
1093 while (
$data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
1095 $this->questions[
$data->sequence] =
$data->question_fi;
1112 $this->startdate_enabled = 1;
1116 $this->startdate_enabled = 0;
1147 $this->enddate_enabled = 1;
1151 $this->enddate_enabled = 0;
1197 $md_life =& $md->getLifecycle();
1200 if (strlen($a_author) == 0)
1203 $a_author = $ilUser->getFullname();
1206 $md_life =& $md->addLifecycle();
1208 $con =& $md_life->addContribute();
1209 $con->setRole(
"Author");
1211 $ent =& $con->addEntity();
1212 $ent->setEntity($a_author);
1229 include_once
"./Services/MetaData/classes/class.ilMD.php";
1231 $md_life =& $md->getLifecycle();
1234 $ids =& $md_life->getContributeIds();
1235 foreach ($ids as
$id)
1237 $md_cont =& $md_life->getContribute($id);
1238 if (strcmp($md_cont->getRole(),
"Author") == 0)
1240 $entids =& $md_cont->getEntityIds();
1241 foreach ($entids as $entid)
1243 $md_ent =& $md_cont->getEntity($entid);
1244 array_push(
$author, $md_ent->getEntity());
1307 $query = sprintf(
"DELETE FROM desktop_item WHERE type = %s AND item_id = %s",
1308 $ilDB->quote(
"svy"),
1311 $result = $ilDB->query($query);
1320 $query =
"SELECT usr_id FROM usr_data";
1321 $result = $ilDB->query($query);
1322 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
1324 if ($ilAccess->checkAccessOfUser($row[
"usr_id"],
"read",
"", $this->getRefId(),
"svy", $this->
getId()))
1326 $query = sprintf(
"INSERT INTO desktop_item (user_id, item_id, type, parameters) VALUES (%s, %s, %s, NULL)",
1327 $ilDB->quote($row[
"usr_id"]),
1331 $insertresult = $ilDB->query($query);
1337 $query = sprintf(
"SELECT user_fi FROM survey_invited_user WHERE survey_fi = %s",
1338 $ilDB->quote($this->getSurveyId())
1340 $result = $ilDB->query($query);
1341 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
1343 $query = sprintf(
"INSERT INTO desktop_item (user_id, item_id, type, parameters) VALUES (%s, %s, %s, NULL)",
1344 $ilDB->quote($row[
"user_fi"]),
1348 $insertresult = $ilDB->query($query);
1350 $query = sprintf(
"SELECT group_fi FROM survey_invited_group WHERE survey_fi = %s",
1351 $ilDB->quote($this->getSurveyId())
1353 $result = $ilDB->query($query);
1354 include_once
"./Modules/Group/classes/class.ilObjGroup.php";
1355 include_once
'./Services/User/classes/class.ilObjUser.php';
1356 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
1359 $members = $group->getGroupMemberIds();
1360 foreach ($members as $user_id)
1388 $query = sprintf(
"DELETE FROM survey_invited_group WHERE survey_fi = %s",
1389 $ilDB->quote($this->getSurveyId())
1391 $result = $ilDB->query($query);
1392 $query = sprintf(
"DELETE FROM survey_invited_user WHERE survey_fi = %s",
1393 $ilDB->quote($this->getSurveyId())
1395 $result = $ilDB->query($query);
1417 $query = sprintf(
"DELETE FROM survey_invited_group WHERE survey_fi = %s",
1418 $ilDB->quote($this->getSurveyId())
1420 $result = $ilDB->query($query);
1421 $query = sprintf(
"DELETE FROM survey_invited_user WHERE survey_fi = %s",
1422 $ilDB->quote($this->getSurveyId())
1424 $result = $ilDB->query($query);
1483 include_once
"./Services/Administration/classes/class.ilSetting.php";
1484 $surveySetting =
new ilSetting(
"survey");
1485 $unlimited_invitation = $surveySetting->get(
"unlimited_invitation");
1486 if (!$unlimited_invitation && $this->invitation_mode ==
MODE_UNLIMITED)
1568 $result = $this->lng->txt(
"cannot_switch_to_online_no_questions");
1604 $messages = array();
1610 if ($now < $epoch_time)
1612 array_push($messages,$this->lng->txt(
'start_date_not_reached').
' ('.
1623 if ($now > $epoch_time)
1625 array_push($messages,$this->lng->txt(
'end_date_reached').
' ('.
1634 array_push($messages, $this->lng->txt(
"survey_is_offline"));
1638 if (!$ilAccess->checkAccess(
"read",
"", $this->ref_id))
1640 array_push($messages, $this->lng->txt(
"cannot_participate_survey"));
1647 $survey_started = $this->
isSurveyStarted($ilUser->getId(), $anonymous_id);
1648 if ($survey_started === 1)
1650 array_push($messages, $this->lng->txt(
"already_completed_survey"));
1656 "messages" => $messages
1685 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})/", $this->start_date, $matches))
1706 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})/", $this->start_date, $matches))
1727 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})/", $this->start_date, $matches))
1776 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})/", $this->end_date, $matches))
1797 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})/", $this->end_date, $matches))
1818 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})/", $this->end_date, $matches))
1895 $existing_questions = array();
1896 $query = sprintf(
"SELECT survey_question.original_id FROM survey_question, survey_survey_question WHERE survey_survey_question.survey_fi = %s AND survey_survey_question.question_fi = survey_question.question_id",
1897 $ilDB->quote($this->getSurveyId())
1899 $result = $ilDB->query($query);
1900 while (
$data =
$result->fetchRow(MDB2_FETCHMODE_OBJECT))
1902 array_push($existing_questions,
$data->original_id);
1904 return $existing_questions;
1917 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1931 $move_questions = array($question_id);
1934 foreach ($pages as $idx => $page)
1936 if ($page[0][
"question_id"] == $question_id)
1943 $this->
moveQuestions($move_questions, $pages[$pageindex-1][0][
"question_id"], 0);
1950 $index = array_search($question_id,
$questions);
1951 if (($index !== FALSE) && ($index > 0))
1968 $move_questions = array($question_id);
1971 foreach ($pages as $idx => $page)
1973 if (($page[0][
"question_id"] == $question_id) && (strcmp($page[0][
"questionblock_id"],
"") == 0))
1978 if (($pageindex < count($pages)-1) && ($pageindex >= 0))
1980 $this->
moveQuestions($move_questions, $pages[$pageindex+1][count($pages[$pageindex+1])-1][
"question_id"], 1);
1987 $index = array_search($question_id,
$questions);
1988 if (($index !== FALSE) && ($index < count(
$questions)-1))
2006 $move_questions = array();
2008 foreach ($pages as $idx => $page)
2010 if ($page[0][
"questionblock_id"] == $questionblock_id)
2012 foreach ($page as $pageidx => $question)
2014 array_push($move_questions, $question[
"question_id"]);
2021 $this->
moveQuestions($move_questions, $pages[$pageindex-1][0][
"question_id"], 0);
2036 $move_questions = array();
2038 foreach ($pages as $idx => $page)
2040 if ($page[0][
"questionblock_id"] == $questionblock_id)
2042 foreach ($page as $pageidx => $question)
2044 array_push($move_questions, $question[
"question_id"]);
2049 if ($pageindex < count($pages)-1)
2051 $this->
moveQuestions($move_questions, $pages[$pageindex+1][count($pages[$pageindex+1])-1][
"question_id"], 1);
2067 $array_pos = array_search($target_index, $this->questions);
2068 if ($insert_mode == 0)
2070 $part1 = array_slice($this->questions, 0, $array_pos);
2071 $part2 = array_slice($this->questions, $array_pos);
2073 else if ($insert_mode == 1)
2075 $part1 = array_slice($this->questions, 0, $array_pos + 1);
2076 $part2 = array_slice($this->questions, $array_pos + 1);
2078 foreach ($move_questions as $question_id)
2080 if (!(array_search($question_id, $part1) === FALSE))
2082 unset($part1[array_search($question_id, $part1)]);
2084 if (!(array_search($question_id, $part2) === FALSE))
2086 unset($part2[array_search($question_id, $part2)]);
2089 $part1 = array_values($part1);
2090 $part2 = array_values($part2);
2091 $this->questions = array_values(array_merge($part1, $move_questions, $part2));
2092 foreach ($move_questions as $question_id)
2095 foreach ($constraints as $idx => $constraint)
2097 foreach ($part2 as $next_question_id)
2099 if ($constraint[
"question"] == $next_question_id)
2120 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
2122 $question->delete($question_id);
2137 $query = sprintf(
"SELECT constraint_fi FROM survey_question_constraint WHERE question_fi = %s AND survey_fi = %s",
2138 $ilDB->quote($question_id .
""),
2141 $result = $ilDB->query($query);
2142 if ($result->numRows() > 0)
2144 $remove_constraints = array();
2145 while ($row = $result->fetchRow(DB_FETCHMODE_HASHREF))
2147 array_push($remove_constraints, $row[
"constraint_fi"]);
2149 $query = sprintf(
"DELETE FROM survey_question_constraint WHERE question_fi = %s AND survey_fi = %s",
2150 $ilDB->quote($question_id .
""),
2153 $result = $ilDB->query($query);
2154 foreach ($remove_constraints as $key => $constraint_id)
2156 $query = sprintf(
"DELETE FROM survey_constraint WHERE constraint_id = %s",
2157 $ilDB->quote($constraint_id .
"")
2159 $result = $ilDB->query($query);
2179 if (in_array($question_id, $remove_questions) or in_array(
$data[
"questionblock_id"], $remove_questionblocks))
2181 unset($this->questions[array_search($question_id, $this->questions)]);
2185 foreach ($remove_questionblocks as $questionblock_id)
2187 $query = sprintf(
"DELETE FROM survey_questionblock WHERE questionblock_id = %s",
2188 $ilDB->quote($questionblock_id)
2190 $result = $ilDB->query($query);
2191 $query = sprintf(
"DELETE FROM survey_questionblock_question WHERE questionblock_fi = %s AND survey_fi = %s",
2192 $ilDB->quote($questionblock_id),
2195 $result = $ilDB->query($query);
2197 $this->questions = array_values($this->questions);
2212 foreach ($questionblocks as $index)
2214 $query = sprintf(
"DELETE FROM survey_questionblock WHERE questionblock_id = %s",
2215 $ilDB->quote($index)
2217 $result = $ilDB->query($query);
2218 $query = sprintf(
"DELETE FROM survey_questionblock_question WHERE questionblock_fi = %s AND survey_fi = %s",
2219 $ilDB->quote($index),
2222 $result = $ilDB->query($query);
2238 $query = sprintf(
"SELECT survey_questionblock.* FROM survey_questionblock, survey_question, survey_questionblock_question WHERE survey_questionblock_question.question_fi = survey_question.question_id AND survey_question.obj_fi = %s",
2239 $ilDB->quote($this->getId())
2241 $result = $ilDB->query($query);
2242 while ($row =
$result->fetchRow(MDB2_FETCHMODE_OBJECT))
2244 $titles[$row->questionblock_id] = $row->title;
2261 $query = sprintf(
"SELECT survey_question.title, survey_questionblock_question.question_fi, survey_questionblock_question.survey_fi FROM survey_questionblock, survey_questionblock_question, survey_question WHERE survey_questionblock.questionblock_id = survey_questionblock_question.questionblock_fi AND survey_question.question_id = survey_questionblock_question.question_fi AND survey_questionblock.questionblock_id = %s",
2262 $ilDB->quote($questionblock_id)
2264 $result = $ilDB->query($query);
2266 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
2268 $titles[$row[
"question_fi"]] = $row[
"title"];
2271 $query = sprintf(
"SELECT question_fi, sequence FROM survey_survey_question WHERE survey_fi = %s ORDER BY sequence",
2274 $result = $ilDB->query($query);
2275 $resultarray = array();
2277 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
2279 if (array_key_exists($row[
"question_fi"], $titles))
2281 $resultarray[$counter++] = $titles[$row[
"question_fi"]];
2284 return $resultarray;
2299 $query = sprintf(
"SELECT survey_questionblock.*, survey_survey.obj_fi, survey_question.question_id AS questiontitle, survey_survey_question.sequence, object_data.title as surveytitle, survey_question.question_id FROM object_reference, object_data, survey_questionblock, survey_questionblock_question, survey_survey, survey_question, survey_survey_question WHERE survey_questionblock.questionblock_id = survey_questionblock_question.questionblock_fi AND survey_survey.survey_id = survey_questionblock_question.survey_fi AND survey_questionblock_question.question_fi = survey_question.question_id AND survey_survey.obj_fi = object_reference.obj_id AND object_reference.obj_id = object_data.obj_id AND survey_survey_question.survey_fi = survey_survey.survey_id AND survey_survey_question.question_fi = survey_question.question_id AND survey_survey.obj_fi = %s AND survey_questionblock.questionblock_id = %s ORDER BY survey_survey_question.sequence ASC",
2300 $ilDB->quote($this->getId()),
2301 $ilDB->quote($questionblock_id)
2303 $result = $ilDB->query($query);
2304 while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2306 array_push($ids, $row->question_id);
2323 $query = sprintf(
"SELECT * FROM survey_questionblock WHERE questionblock_id = %s",
2324 $ilDB->quote($questionblock_id)
2326 $result = $ilDB->query($query);
2327 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
2343 $query = sprintf(
"SELECT * FROM survey_questionblock WHERE questionblock_id = %s",
2344 $ilDB->quote($questionblock_id)
2346 $result = $ilDB->query($query);
2347 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
2364 $query = sprintf(
"INSERT INTO survey_questionblock (questionblock_id, title, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, NULL)",
2365 $ilDB->quote(
$title .
""),
2366 $ilDB->quote(
$owner .
"")
2368 $result = $ilDB->query($query);
2369 return $ilDB->getLastInsertId();
2390 $query = sprintf(
"INSERT INTO survey_questionblock (questionblock_id, title, show_questiontext, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
2392 $ilDB->quote($show_questiontext .
""),
2393 $ilDB->quote($ilUser->getId())
2395 $result = $ilDB->query($query);
2399 $ilias->raiseError(
$result->getMessage());
2403 $questionblock_id = $ilDB->getLastInsertId();
2406 $query = sprintf(
"INSERT INTO survey_questionblock_question (questionblock_question_id, survey_fi, questionblock_fi, question_fi) VALUES (NULL, %s, %s, %s)",
2407 $ilDB->quote($this->getSurveyId()),
2408 $ilDB->quote($questionblock_id),
2409 $ilDB->quote($index)
2411 $result = $ilDB->query($query);
2429 $query = sprintf(
"UPDATE survey_questionblock SET title = %s, show_questiontext = %s WHERE questionblock_id = %s",
2431 $ilDB->quote($show_questiontext .
""),
2432 $ilDB->quote($questionblock_id)
2434 $result = $ilDB->query($query);
2448 $query = sprintf(
"SELECT * FROM survey_question_constraint WHERE question_fi = %s AND survey_fi = %s",
2449 $ilDB->quote($question_id),
2452 $result = $ilDB->query($query);
2453 while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2455 $query = sprintf(
"DELETE FROM survey_constraint WHERE constraint_id = %s",
2456 $ilDB->quote($row->constraint_fi)
2458 $delresult = $ilDB->query($query);
2460 $query = sprintf(
"DELETE FROM survey_question_constraint WHERE question_fi = %s AND survey_fi = %s",
2461 $ilDB->quote($question_id),
2464 $delresult = $ilDB->query($query);
2479 $query = sprintf(
"DELETE FROM survey_constraint WHERE constraint_id = %s",
2480 $ilDB->quote($constraint_id)
2482 $delresult = $ilDB->query($query);
2483 $query = sprintf(
"DELETE FROM survey_question_constraint WHERE constraint_fi = %s AND question_fi = %s AND survey_fi = %s",
2484 $ilDB->quote($constraint_id),
2485 $ilDB->quote($question_id),
2488 $delresult = $ilDB->query($query);
2503 $all_questions = array();
2504 $query = sprintf(
"SELECT survey_questiontype.type_tag, survey_questiontype.plugin, survey_question.question_id, survey_survey_question.heading FROM survey_questiontype, survey_question, survey_survey_question WHERE survey_survey_question.survey_fi = %s AND survey_survey_question.question_fi = survey_question.question_id AND survey_question.questiontype_fi = survey_questiontype.questiontype_id ORDER BY survey_survey_question.sequence",
2505 $ilDB->quote($this->getSurveyId())
2507 $result = $ilDB->query($query);
2508 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
2509 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
2522 $questionrow = $question->_getQuestionDataArray($row[
"question_id"]);
2523 foreach ($row as $key => $value)
2525 $questionrow[$key] = $value;
2527 $all_questions[$row[
"question_id"]] = $questionrow;
2528 $all_questions[$row[
"question_id"]][
"usableForPrecondition"] = $question->usableForPrecondition();
2529 $all_questions[$row[
"question_id"]][
"availableRelations"] = $question->getAvailableRelations();
2530 if (array_key_exists($row[
"question_id"], $obligatory_states))
2532 $all_questions[$row[
"question_id"]][
"obligatory"] = $obligatory_states[$row[
"question_id"]];
2537 $questionblocks = array();
2538 $in = join(array_keys($all_questions),
"','");
2541 $query = sprintf(
"SELECT survey_questionblock.*, survey_questionblock_question.question_fi FROM survey_questionblock, survey_questionblock_question WHERE survey_questionblock.questionblock_id = survey_questionblock_question.questionblock_fi AND survey_questionblock_question.survey_fi = %s AND survey_questionblock_question.question_fi IN ('$in')",
2542 $ilDB->quote($this->getSurveyId())
2544 $result = $ilDB->query($query);
2545 while ($row =
$result->fetchRow(MDB2_FETCHMODE_OBJECT))
2547 $questionblocks[$row->question_fi] = $row;
2551 foreach ($all_questions as $question_id => $row)
2554 if (isset($questionblocks[$question_id]))
2556 $all_questions[$question_id][
"questionblock_title"] = $questionblocks[$question_id]->title;
2557 $all_questions[$question_id][
"questionblock_id"] = $questionblocks[$question_id]->questionblock_id;
2558 $all_questions[$question_id][
"constraints"] = $constraints;
2562 $all_questions[$question_id][
"questionblock_title"] =
"";
2563 $all_questions[$question_id][
"questionblock_id"] =
"";
2564 $all_questions[$question_id][
"constraints"] = $constraints;
2569 $query = sprintf(
"SELECT survey_variable.*, survey_category.title FROM survey_variable, survey_category WHERE survey_variable.question_fi = %s AND survey_variable.category_fi = survey_category.category_id ORDER BY sequence ASC",
2570 $ilDB->quote($question_id .
"")
2572 $result = $ilDB->query($query);
2573 if ($result->numRows() > 0)
2575 while (
$data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2577 array_push($answers,
$data->title);
2580 $all_questions[$question_id][
"answers"] = $answers;
2583 return $all_questions;
2597 $query = sprintf(
"SELECT * FROM survey_survey_question WHERE survey_fi = %s",
2598 $ilDB->quote($this->getSurveyId() .
"")
2600 $result = $ilDB->query($query);
2603 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
2605 if (!array_key_exists($row[
"question_fi"], $obligatory_questions))
2607 $obligatory_questions[$row[
"question_fi"]] = 0;
2613 $query = sprintf(
"DELETE FROM survey_question_obligatory WHERE survey_fi = %s",
2614 $ilDB->quote($this->getSurveyId() .
"")
2616 $result = $ilDB->query($query);
2619 foreach ($obligatory_questions as $question_fi => $obligatory)
2621 $query = sprintf(
"INSERT INTO survey_question_obligatory (question_obligatory_id, survey_fi, question_fi, obligatory, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
2622 $ilDB->quote($this->getSurveyId() .
""),
2623 $ilDB->quote($question_fi .
""),
2624 $ilDB->quote($obligatory .
"")
2626 $result = $ilDB->query($query);
2641 $obligatory_states = array();
2642 $query = sprintf(
"SELECT * FROM survey_question_obligatory WHERE survey_fi = %s",
2643 $ilDB->quote($this->getSurveyId() .
"")
2645 $result = $ilDB->query($query);
2648 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
2650 $obligatory_states[$row[
"question_fi"]] = $row[
"obligatory"];
2653 return $obligatory_states;
2668 $all_questions = array();
2669 $query = sprintf(
"SELECT survey_question.*, survey_questiontype.type_tag, survey_survey_question.heading FROM survey_question, survey_questiontype, survey_survey_question WHERE survey_survey_question.survey_fi = %s AND survey_survey_question.question_fi = survey_question.question_id AND survey_question.questiontype_fi = survey_questiontype.questiontype_id ORDER BY survey_survey_question.sequence",
2670 $ilDB->quote($this->getSurveyId())
2672 $result = $ilDB->query($query);
2673 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
2675 $all_questions[$row[
"question_id"]] = $row;
2678 $questionblocks = array();
2679 $in = join(array_keys($all_questions),
"','");
2682 $query = sprintf(
"SELECT survey_questionblock.*, survey_questionblock_question.question_fi FROM survey_questionblock, survey_questionblock_question WHERE survey_questionblock.questionblock_id = survey_questionblock_question.questionblock_fi AND survey_questionblock_question.survey_fi = %s AND survey_questionblock_question.question_fi IN ('$in')",
2683 $ilDB->quote($this->getSurveyId())
2685 $result = $ilDB->query($query);
2686 while ($row =
$result->fetchRow(MDB2_FETCHMODE_OBJECT))
2688 $questionblocks[
"$row->question_fi"] = $row;
2692 $all_pages = array();
2695 foreach ($all_questions as $question_id => $row)
2697 if (array_key_exists($question_id, $obligatory_states))
2699 $all_questions[
"$question_id"][
"obligatory"] = $obligatory_states[
"$question_id"];
2701 $constraints = array();
2702 if (isset($questionblocks[$question_id]))
2704 if (!$currentblock or ($currentblock != $questionblocks[$question_id]->questionblock_id))
2708 $all_questions[$question_id][
"questionblock_title"] = $questionblocks[$question_id]->title;
2709 $all_questions[$question_id][
"questionblock_id"] = $questionblocks[$question_id]->questionblock_id;
2710 $all_questions[$question_id][
"questionblock_show_questiontext"] = $questionblocks[$question_id]->show_questiontext;
2711 $currentblock = $questionblocks[$question_id]->questionblock_id;
2713 $all_questions[$question_id][
"constraints"] = $constraints;
2718 $all_questions[$question_id][
"questionblock_title"] =
"";
2719 $all_questions[$question_id][
"questionblock_id"] =
"";
2720 $all_questions[$question_id][
"questionblock_show_questiontext"] = 1;
2723 $all_questions[$question_id][
"constraints"] = $constraints;
2725 if (!isset($all_pages[$pageindex]))
2727 $all_pages[$pageindex] = array();
2729 array_push($all_pages[$pageindex], $all_questions[$question_id]);
2732 $max = count($all_pages);
2734 foreach ($all_pages as $index => $block)
2736 foreach ($block as $blockindex => $question)
2738 $all_pages[$index][$blockindex][position] = $counter / $max;
2759 if (strcmp($active_page_question_id,
"") == 0)
2764 foreach ($pages as $key => $question_array)
2766 foreach ($question_array as $question)
2768 if ($active_page_question_id == $question[
"question_id"])
2774 if ($foundpage == -1)
2780 $foundpage += $direction;
2785 if ($foundpage >= count($pages))
2789 return $pages[$foundpage];
2803 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
2818 $result_array = array();
2819 $query = sprintf(
"SELECT survey_constraint.*, survey_relation.* FROM survey_question_constraint, survey_constraint, survey_relation WHERE survey_constraint.relation_fi = survey_relation.relation_id AND survey_question_constraint.constraint_fi = survey_constraint.constraint_id AND survey_constraint.constraint_id = %s",
2820 $ilDB->quote(
$id .
"")
2822 $result = $ilDB->query($query);
2824 if ($result->numRows())
2826 $pc = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
2842 $result_array = array();
2843 $query = sprintf(
"SELECT survey_constraint.*, survey_relation.* FROM survey_question_constraint, survey_constraint, survey_relation WHERE survey_constraint.relation_fi = survey_relation.relation_id AND survey_question_constraint.constraint_fi = survey_constraint.constraint_id AND survey_question_constraint.question_fi = %s AND survey_question_constraint.survey_fi = %s",
2844 $ilDB->quote($question_id),
2847 $result = $ilDB->query($query);
2848 while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2850 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
2853 $question =
new $question_type();
2854 $question->loadFromDb($row->question_fi);
2855 $valueoutput = $question->getPreconditionValueOutput($row->value);
2856 array_push($result_array, array(
"id" => $row->constraint_id,
"question" => $row->question_fi,
"short" => $row->shortname,
"long" => $row->longname,
"value" => $row->value,
"valueoutput" => $valueoutput));
2858 return $result_array;
2871 $result_array = array();
2872 $query = sprintf(
"SELECT survey_question_constraint.question_fi as for_question, survey_constraint.*, survey_relation.* FROM survey_question_constraint, survey_constraint, survey_relation WHERE survey_constraint.relation_fi = survey_relation.relation_id AND survey_question_constraint.constraint_fi = survey_constraint.constraint_id AND survey_question_constraint.survey_fi = %s",
2875 $result = $ilDB->query($query);
2876 while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2878 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));
2880 return $result_array;
2895 $result_array = array();
2896 $query = sprintf(
"SELECT survey_variable.*, survey_category.title FROM survey_variable LEFT JOIN survey_category ON survey_variable.category_fi = survey_category.category_id WHERE survey_variable.question_fi = %s ORDER BY survey_variable.sequence",
2897 $ilDB->quote($question_id)
2899 $result = $ilDB->query($query);
2900 while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2902 $result_array[$row->sequence] = $row;
2904 return $result_array;
2922 $query = sprintf(
"INSERT INTO survey_constraint (constraint_id, question_fi, relation_fi, value) VALUES (NULL, %s, %s, %s)",
2923 $ilDB->quote($if_question_id),
2924 $ilDB->quote($relation),
2925 $ilDB->quote($value)
2927 $result = $ilDB->query($query);
2928 if (PEAR::isError($result))
2931 $ilias->raiseError($result->getMessage());
2935 $constraint_id = $ilDB->getLastInsertId();
2936 $query = sprintf(
"INSERT INTO survey_question_constraint (question_constraint_id, survey_fi, question_fi, constraint_fi) VALUES (NULL, %s, %s, %s)",
2937 $ilDB->quote($this->getSurveyId()),
2938 $ilDB->quote($to_question_id),
2939 $ilDB->quote($constraint_id)
2941 $result = $ilDB->query($query);
2960 $query = sprintf(
"SELECT constraint_fi FROM survey_question_constraint WHERE question_fi = %s AND survey_fi = %s",
2961 $ilDB->quote($to_question_id .
""),
2964 $result = $ilDB->query($query);
2965 if ($result->numRows())
2967 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
2968 $query = sprintf(
"UPDATE survey_constraint SET question_fi = %s, relation_fi = %s, value = %s WHERE constraint_id = %s",
2969 $ilDB->quote($if_question_id),
2970 $ilDB->quote($relation),
2971 $ilDB->quote($value),
2972 $ilDB->quote($row[
"constraint_fi"])
2974 $result = $ilDB->query($query);
2989 $result_array = array();
2990 $query =
"SELECT * FROM survey_relation";
2991 $result = $ilDB->query($query);
2992 while ($row =
$result->fetchRow(MDB2_FETCHMODE_OBJECT))
2996 $result_array[$row->shortname] = array(
"short" => $row->shortname,
"long" => $row->longname,
"id" => $row->relation_id);
3000 $result_array[$row->relation_id] = array(
"short" => $row->shortname,
"long" => $row->longname);
3003 return $result_array;
3018 $query = sprintf(
"DELETE FROM survey_invited_user WHERE survey_fi = %s AND user_fi = %s",
3019 $ilDB->quote($this->getSurveyId()),
3020 $ilDB->quote($user_id)
3022 $result = $ilDB->query($query);
3025 include_once
'./Services/User/classes/class.ilObjUser.php';
3029 $userObj->dropDesktopItem($this->
getRefId(),
"svy");
3046 $query = sprintf(
"SELECT user_fi FROM survey_invited_user WHERE user_fi = %s AND survey_fi = %s",
3047 $ilDB->quote($user_id),
3050 $result = $ilDB->query($query);
3051 if ($result->numRows() < 1)
3053 $query = sprintf(
"INSERT INTO survey_invited_user (invited_user_id, survey_fi, user_fi, TIMESTAMP) VALUES (NULL, %s, %s, NULL)",
3054 $ilDB->quote($this->getSurveyId()),
3055 $ilDB->quote($user_id)
3057 $result = $ilDB->query($query);
3061 include_once
'./Services/User/classes/class.ilObjUser.php';
3065 $userObj->addDesktopItem($this->
getRefId(),
"svy");
3082 include_once
"./Modules/Group/classes/class.ilObjGroup.php";
3084 $members = $group->getGroupMemberIds();
3085 foreach ($members as $user_id)
3087 if ($ilAccess->checkAccessOfUser($user_id,
"read",
"", $this->getRefId(),
"svy", $this->
getId()))
3095 $userObj->addDesktopItem($this->
getRefId(),
"svy");
3117 $members = $rbacreview->assignedUsers($role_id);
3118 foreach ($members as $user_id)
3120 if ($ilAccess->checkAccessOfUser($user_id,
"read",
"", $this->getRefId(),
"svy", $this->
getId()))
3128 $userObj->addDesktopItem($this->
getRefId(),
"svy");
3149 $result_array = array();
3150 $query = sprintf(
"SELECT user_fi FROM survey_invited_user WHERE survey_fi = %s",
3151 $ilDB->quote($this->getSurveyId())
3153 $result = $ilDB->query($query);
3154 while ($row =
$result->fetchRow(MDB2_FETCHMODE_OBJECT))
3156 array_push($result_array, $row->user_fi);
3158 return $result_array;
3173 $result_array = array();
3174 $query = sprintf(
"SELECT group_fi FROM survey_invited_group WHERE survey_fi = %s",
3175 $ilDB->quote($this->getSurveyId())
3177 $result = $ilDB->query($query);
3178 while ($row =
$result->fetchRow(MDB2_FETCHMODE_OBJECT))
3180 array_push($result_array, $row->group_fi);
3182 return $result_array;
3199 $query = sprintf(
"DELETE FROM survey_answer WHERE question_fi = %s AND active_fi = %s",
3200 $ilDB->quote($question_id),
3201 $ilDB->quote($active_id)
3203 $result = $ilDB->query($query);
3219 $result_array = array();
3220 $query = sprintf(
"SELECT * FROM survey_answer WHERE question_fi = %s AND active_fi = %s",
3221 $ilDB->quote($question_id.
""),
3222 $ilDB->quote($active_id)
3224 $result = $ilDB->query($query);
3225 if ($result->numRows() >= 1)
3227 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
3229 array_push($result_array, $row);
3231 return $result_array;
3235 return $result_array;
3252 $query = sprintf(
"INSERT INTO survey_finished (finished_id, survey_fi, user_fi, anonymous_id, state, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
3253 $ilDB->quote($this->getSurveyId() .
""),
3254 $ilDB->quote($user_id .
""),
3255 $ilDB->quote($anonymous_id .
""),
3256 $ilDB->quote(1 .
"")
3258 $result = $ilDB->query($query);
3260 $active_id = $ilDB->getLastInsertId();
3263 foreach ($pages as $key => $question_array)
3265 foreach ($question_array as $question)
3268 require_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
3270 $question->saveRandomData($active_id);
3288 if ($this->
getAnonymize() && (strlen($anonymous_id) == 0))
return;
3290 if (strcmp($user_id,
"") == 0)
3292 if ($user_id == ANONYMOUS_USER_ID)
3297 $query = sprintf(
"INSERT INTO survey_finished (finished_id, survey_fi, user_fi, anonymous_id, state, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
3298 $ilDB->quote($this->getSurveyId() .
""),
3299 $ilDB->quote($user_id .
""),
3300 $ilDB->quote($anonymous_id .
""),
3301 $ilDB->quote(0 .
"")
3303 $result = $ilDB->query($query);
3306 $query = sprintf(
"SELECT finished_id FROM survey_finished WHERE survey_fi = %s AND user_fi = %s AND anonymous_id = %s",
3307 $ilDB->quote($this->getSurveyId() .
""),
3308 $ilDB->quote($user_id .
""),
3309 $ilDB->quote($anonymous_id .
"")
3311 $result = $ilDB->query($query);
3313 if ($result->numRows())
3315 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
3316 $insert_id = $row[
"finished_id"];
3335 $query = sprintf(
"UPDATE survey_finished SET state = %s, user_fi = %s WHERE survey_fi = %s AND anonymous_id = %s",
3337 $ilDB->quote($user_id .
""),
3339 $ilDB->quote($anonymize_id .
"")
3344 $query = sprintf(
"UPDATE survey_finished SET state = %s WHERE survey_fi = %s AND user_fi = %s",
3347 $ilDB->quote($user_id .
"")
3350 $result = $ilDB->query($query);
3369 if (strlen($username) == 0)
3372 $userid = $ilUser->getId();
3375 $surveysetting =
new ilSetting(
"survey");
3376 $allowedUsers = strlen($surveysetting->get(
"multiple_survey_users")) ? explode(
",",$surveysetting->get(
"multiple_survey_users")) : array();
3377 if (in_array($userid, $allowedUsers))
3403 $query = sprintf(
"SELECT * FROM survey_finished WHERE survey_fi = %s AND user_fi = %s",
3404 $ilDB->quote($this->getSurveyId()),
3405 $ilDB->quote($user_id)
3410 $query = sprintf(
"SELECT * FROM survey_finished WHERE survey_fi = %s AND anonymous_id = %s",
3411 $ilDB->quote($this->getSurveyId()),
3412 $ilDB->quote($anonymize_id)
3418 $query = sprintf(
"SELECT * FROM survey_finished WHERE survey_fi = %s AND user_fi = %s",
3419 $ilDB->quote($this->getSurveyId()),
3420 $ilDB->quote($user_id)
3423 $result = $ilDB->query($query);
3430 $row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC);
3431 $_SESSION[
"finished_id"] = $row[
"finished_id"];
3432 return (
int)$row[
"state"];
3448 $query = sprintf(
"SELECT question_fi, TIMESTAMP + 0 AS timestamp14 FROM survey_answer WHERE active_fi = %s ORDER BY timestamp14 DESC",
3449 $ilDB->quote($active_id)
3451 $result = $ilDB->query($query);
3452 if ($result->numRows() == 0)
3458 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
3459 return $row[
"question_fi"];
3475 if (count($working_data) == 0)
3480 if ((count($working_data) == 1) and (strcmp($working_data[0][
"value"],
"") == 0))
3485 foreach ($working_data as
$data)
3487 switch ($constraint_data[
"short"])
3490 if ($data[
"value"] < $constraint_data[
"value"])
3496 if ($data[
"value"] <= $constraint_data[
"value"])
3502 if ($data[
"value"] == $constraint_data[
"value"])
3508 if ($data[
"value"] != $constraint_data[
"value"])
3514 if ($data[
"value"] >= $constraint_data[
"value"])
3520 if ($data[
"value"] > $constraint_data[
"value"])
3534 $query = sprintf(
"SELECT finished_id FROM survey_finished WHERE survey_fi = %s",
3537 $result = $ilDB->query($query);
3538 if ($result->numRows())
3559 $query = sprintf(
"SELECT * FROM survey_finished WHERE survey_fi = %s",
3560 $ilDB->quote($this->getSurveyId() .
"")
3562 $result = $ilDB->query($query);
3565 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
3567 array_push($users, $row[
"finished_id"]);
3584 $query = sprintf(
"SELECT * FROM survey_finished WHERE survey_fi = %s",
3585 $ilDB->quote($this->getSurveyId() .
"")
3587 $result = $ilDB->query($query);
3590 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
3592 array_push($users, $row);
3595 $evaluation = array();
3597 foreach (
$questions as $question_id => $question_data)
3599 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
3602 $question =
new $question_type();
3603 $question->loadFromDb($question_id);
3605 $evaluation[$question_id] =
$data;
3621 $query = sprintf(
"SELECT * FROM survey_finished WHERE finished_id = %s",
3622 $ilDB->quote($active_id)
3624 $result = $ilDB->query($query);
3625 $surveySetting =
new ilSetting(
"survey");
3626 $use_anonymous_id = array_key_exists(
"use_anonymous_id",
$_GET) ?
$_GET[
"use_anonymous_id"] : $surveySetting->get(
"use_anonymous_id");
3628 $foundrows = $result->numRows();
3631 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
3633 $name = ($use_anonymous_id) ? $row[
"anonymous_id"] : $this->lng->txt(
"anonymous");
3635 "fullname" => $name,
3636 "sortname" => $name,
3641 "active_id" =>
"$active_id"
3645 if (($row[
"user_fi"] > 0) && ($row[
"user_fi"] != ANONYMOUS_USER_ID) && ($this->
getAnonymize() == 0))
3647 include_once
'./Services/User/classes/class.ilObjUser.php';
3650 $userdata[
"fullname"] = $this->lng->txt(
"deleted_user");
3655 $userdata[
"fullname"] =
$user->getFullname();
3656 $gender =
$user->getGender();
3657 if (strlen($gender) == 1) $gender = $this->lng->txt(
"gender_$gender");
3658 $userdata[
"gender"] = $gender;
3659 $userdata[
"firstname"] =
$user->getFirstname();
3660 $userdata[
"lastname"] =
$user->getLastname();
3661 $userdata[
"sortname"] =
$user->getLastname() .
", " .
$user->getFirstname();
3662 $userdata[
"login"] =
$user->getLogin();
3686 $query = sprintf(
"SELECT * FROM survey_answer WHERE active_fi = %s",
3687 $ilDB->quote($active_id)
3689 $result = $ilDB->query($query);
3690 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
3692 if (!is_array($answers[$row[
"question_fi"]]))
3694 $answers[$row[
"question_fi"]] = array();
3696 array_push($answers[$row[
"question_fi"]], $row);
3700 "name" => $userdata[
"fullname"],
3701 "gender" => $userdata[
"gender"],
3702 "answers" => array()
3706 if (array_key_exists($key, $answers))
3708 $resultset[
"answers"][$key] = $answers[$key];
3712 $resultset[
"answers"][$key] = array();
3714 sort($resultset[
"answers"][$key]);
3733 $query = sprintf(
"SELECT finished_id FROM survey_finished WHERE survey_fi = %s",
3734 $ilDB->quote($this->getSurveyId())
3736 $result = $ilDB->query($query);
3737 $nr_of_users =
$result->numRows();
3739 $result_array =& $question->getCumulatedResults($this->
getSurveyId(), $nr_of_users);
3740 return $result_array;
3756 $query = sprintf(
"SELECT finished_id FROM survey_finished WHERE survey_fi = %s",
3759 $result = $ilDB->query($query);
3760 return $result->numRows();
3765 $result_array = array();
3766 $query =
"SELECT survey_question.*, survey_questiontype.type_tag FROM survey_question, survey_questiontype WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id AND survey_question.question_id IN ('" . join($question_ids,
"','") .
"')";
3767 $result = $ilDB->query($query);
3768 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
3770 array_push($result_array, $row);
3772 return $result_array;
3779 $result_array = array();
3780 $query =
"SELECT survey_questionblock.*, survey_survey.obj_fi, survey_question.title AS questiontitle, survey_survey_question.sequence, object_data.title as surveytitle, survey_question.question_id FROM object_reference, object_data, survey_questionblock, survey_questionblock_question, survey_survey, survey_question, survey_survey_question WHERE survey_questionblock.questionblock_id = survey_questionblock_question.questionblock_fi AND survey_survey.survey_id = survey_questionblock_question.survey_fi AND survey_questionblock_question.question_fi = survey_question.question_id AND survey_survey.obj_fi = object_reference.obj_id AND object_reference.obj_id = object_data.obj_id AND survey_survey_question.survey_fi = survey_survey.survey_id AND survey_survey_question.question_fi = survey_question.question_id AND survey_questionblock.questionblock_id IN ('" . join($questionblock_ids,
"','") .
"') ORDER BY survey_survey.survey_id, survey_survey_question.sequence";
3781 $result = $ilDB->query($query);
3782 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
3784 if ($row[
"questionblock_id"] != $qbid)
3788 $row[
"sequence"] = $sequence++;
3789 $result_array[$row[
"questionblock_id"]][$row[
"question_id"]] = $row;
3790 $qbid = $row[
"questionblock_id"];
3792 return $result_array;
3802 function getQuestionsTable($sort, $sortorder, $filter_text, $sel_filter_type, $startrow = 0, $completeonly = 0, $filter_question_type =
"", $filter_questionpool =
"")
3808 if (strlen($filter_text) > 0)
3810 switch($sel_filter_type)
3813 $where =
" AND survey_question.title LIKE " . $ilDB->quote(
"%" . $filter_text .
"%");
3816 $where =
" AND survey_question.description LIKE " . $ilDB->quote(
"%" . $filter_text .
"%");
3819 $where =
" AND survey_question.author LIKE " . $ilDB->quote(
"%" . $filter_text .
"%");
3824 if ($filter_question_type && (strcmp($filter_question_type,
"all") != 0))
3826 $where .=
" AND survey_questiontype.type_tag = " . $ilDB->quote($filter_question_type);
3829 if ($filter_questionpool && (strcmp($filter_questionpool,
"all") != 0))
3831 $where .=
" AND survey_question.obj_fi = $filter_questionpool";
3837 include_once
"./Services/Utilities/classes/class.ilUtil.php";
3841 $order =
" ORDER BY title $sortorder";
3842 $images[
"title"] =
" <img src=\"" .
ilUtil::getImagePath(strtolower($sortorder) .
"_order.gif") .
"\" alt=\"" . strtolower($sortorder) .
"ending order\" />";
3845 $order =
" ORDER BY description $sortorder";
3846 $images[
"description"] =
" <img src=\"" .
ilUtil::getImagePath(strtolower($sortorder) .
"_order.gif") .
"\" alt=\"" . strtolower($sortorder) .
"ending order\" />";
3849 $order =
" ORDER BY questiontype_id $sortorder";
3850 $images[
"type"] =
" <img src=\"" .
ilUtil::getImagePath(strtolower($sortorder) .
"_order.gif") .
"\" alt=\"" . strtolower($sortorder) .
"ending order\" />";
3853 $order =
" ORDER BY author $sortorder";
3854 $images[
"author"] =
" <img src=\"" .
ilUtil::getImagePath(strtolower($sortorder) .
"_order.gif") .
"\" alt=\"" . strtolower($sortorder) .
"ending order\" />";
3857 $order =
" ORDER BY created $sortorder";
3858 $images[
"created"] =
" <img src=\"" .
ilUtil::getImagePath(strtolower($sortorder) .
"_order.gif") .
"\" alt=\"" . strtolower($sortorder) .
"ending order\" />";
3861 $order =
" ORDER BY timestamp14 $sortorder";
3862 $images[
"updated"] =
" <img src=\"" .
ilUtil::getImagePath(strtolower($sortorder) .
"_order.gif") .
"\" alt=\"" . strtolower($sortorder) .
"ending order\" />";
3865 $order =
" ORDER BY obj_fi $sortorder";
3866 $images[
"qpl"] =
" <img src=\"" .
ilUtil::getImagePath(strtolower($sortorder) .
"_order.gif") .
"\" alt=\"" . strtolower($sortorder) .
"ending order\" />";
3869 $maxentries = $ilUser->prefs[
"hits_per_page"];
3870 if ($maxentries < 1)
3877 $forbidden =
" AND survey_question.obj_fi IN ('" . join(array_keys($spls),
"','") .
"')";
3880 $forbidden .=
" AND survey_question.complete = " . $ilDB->quote(
"1");
3884 if (count($existing_questions))
3886 $existing =
" AND survey_question.question_id NOT IN ('" . join($existing_questions,
"','") .
"')";
3888 $limit =
" LIMIT $startrow, $maxentries";
3889 $query =
"SELECT survey_question.*, survey_question.TIMESTAMP + 0 AS timestamp14, survey_questiontype.type_tag, survey_questiontype.plugin, object_reference.ref_id FROM survey_question, survey_questiontype, object_reference WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id$forbidden$existing AND survey_question.obj_fi = object_reference.obj_id AND ISNULL(survey_question.original_id) " .
" $where$order";
3890 $query_result = $ilDB->query($query);
3891 $max = $query_result->numRows();
3892 $query =
"SELECT survey_question.*, survey_question.TIMESTAMP + 0 AS timestamp14, survey_questiontype.type_tag, survey_questiontype.plugin, object_reference.ref_id FROM survey_question, survey_questiontype, object_reference WHERE survey_question.questiontype_fi = survey_questiontype.questiontype_id$forbidden$existing AND survey_question.obj_fi = object_reference.obj_id AND ISNULL(survey_question.original_id) " .
" $where$order$limit";
3893 $query_result = $ilDB->query($query);
3894 if ($startrow > $max -1)
3896 $startrow = $max - ($max % $maxentries);
3898 else if ($startrow < 0)
3903 if ($query_result->numRows())
3905 while ($row = $query_result->fetchRow(MDB2_FETCHMODE_ASSOC))
3911 array_push($rows, $row);
3916 array_push($rows, $row);
3920 $nextrow = $startrow + $maxentries;
3921 if ($nextrow > $max - 1)
3923 $nextrow = $startrow;
3925 $prevrow = $startrow - $maxentries;
3932 "images" => $images,
3933 "startrow" => $startrow,
3934 "nextrow" => $nextrow,
3935 "prevrow" => $prevrow,
3936 "step" => $maxentries,
3953 if (strlen($filter_text) > 0) {
3954 switch($sel_filter_type) {
3956 $where =
" AND survey_questionblock.title LIKE " . $ilDB->quote(
"%" . $filter_text .
"%");
3964 include_once
"./Services/Utilities/classes/class.ilUtil.php";
3968 $order =
" ORDER BY survey_questionblock.title $sortorder";
3969 $images[
"title"] =
" <img src=\"" .
ilUtil::getImagePath(strtolower($sortorder) .
"_order.gif") .
"\" alt=\"" . strtolower($sortorder) .
"ending order\" />";
3972 $order =
" ORDER BY survey_survey_question.survey_fi $sortorder";
3973 $images[
"svy"] =
" <img src=\"" .
ilUtil::getImagePath(strtolower($sortorder) .
"_order.gif") .
"\" alt=\"" . strtolower($sortorder) .
"ending order\" />";
3976 $maxentries = $ilUser->prefs[
"hits_per_page"];
3979 $order .=
",survey_survey_question.sequence ASC";
3983 $order =
" ORDER BY survey_survey_question.sequence ASC";
3985 $query =
"SELECT survey_questionblock.questionblock_id FROM object_reference, object_data, survey_questionblock, survey_questionblock_question, survey_survey, survey_question, survey_survey_question WHERE survey_questionblock.questionblock_id = survey_questionblock_question.questionblock_fi AND survey_survey.survey_id = survey_questionblock_question.survey_fi AND survey_questionblock_question.question_fi = survey_question.question_id AND survey_survey.obj_fi = object_reference.obj_id AND object_reference.obj_id = object_data.obj_id AND survey_survey_question.survey_fi = survey_survey.survey_id AND survey_survey_question.question_fi = survey_question.question_id$where GROUP BY survey_questionblock.questionblock_id$order$limit";
3986 $query_result = $ilDB->query($query);
3987 $questionblock_ids = array();
3988 if ($query_result->numRows())
3990 while ($row = $query_result->fetchRow(MDB2_FETCHMODE_ASSOC))
3992 array_push($questionblock_ids, $row[
"questionblock_id"]);
3996 $max = $query_result->numRows();
3997 if ($startrow > $max -1)
3999 $startrow = $max - ($max % $maxentries);
4001 else if ($startrow < 0)
4005 $limit =
" LIMIT $startrow, $maxentries";
4006 $query =
"SELECT survey_questionblock.*, object_data.title as surveytitle FROM object_reference, object_data, survey_questionblock, survey_questionblock_question, survey_survey, survey_question, survey_survey_question WHERE survey_questionblock.questionblock_id = survey_questionblock_question.questionblock_fi AND survey_survey.survey_id = survey_questionblock_question.survey_fi AND survey_questionblock_question.question_fi = survey_question.question_id AND survey_survey.obj_fi = object_reference.obj_id AND object_reference.obj_id = object_data.obj_id AND survey_survey_question.survey_fi = survey_survey.survey_id AND survey_survey_question.question_fi = survey_question.question_id$where GROUP BY survey_questionblock.questionblock_id$order$limit";
4007 $query_result = $ilDB->query($query);
4009 if ($query_result->numRows())
4011 while ($row = $query_result->fetchRow(MDB2_FETCHMODE_ASSOC))
4015 foreach ($questions_array as $key => $value)
4017 $questions_array[$key] =
"$counter. $value";
4020 $rows[$row[
"questionblock_id"]] = array(
4021 "questionblock_id" => $row[
"questionblock_id"],
4022 "title" => $row[
"title"],
4023 "surveytitle" => $row[
"surveytitle"],
4024 "questions" => join($questions_array,
", "),
4025 "owner" => $row[
"owner_fi"]
4029 $nextrow = $startrow + $maxentries;
4030 if ($nextrow > $max - 1)
4032 $nextrow = $startrow;
4034 $prevrow = $startrow - $maxentries;
4041 "images" => $images,
4042 "startrow" => $startrow,
4043 "nextrow" => $nextrow,
4044 "prevrow" => $prevrow,
4045 "step" => $maxentries,
4060 include_once(
"./classes/class.ilXmlWriter.php");
4065 "xmlns:xsi" =>
"http://www.w3.org/2001/XMLSchema-instance",
4066 "xsi:noNamespaceSchemaLocation" =>
"http://www.ilias.de/download/xsd/ilias_survey_3_8.xsd"
4068 $a_xml_writer->xmlStartTag(
"surveyobject", $attrs);
4073 $a_xml_writer->xmlStartTag(
"survey", $attrs);
4075 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
4076 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
4077 $a_xml_writer->xmlStartTag(
"objectives");
4079 "label" =>
"introduction"
4086 $a_xml_writer->xmlEndTag(
"objectives");
4090 $attribs = array(
"enabled" =>
"1");
4094 $attribs = array(
"enabled" =>
"0");
4096 $a_xml_writer->xmlElement(
"anonymisation", $attribs);
4097 $a_xml_writer->xmlStartTag(
"restrictions");
4100 $attribs = array(
"type" =>
"free");
4104 $attribs = array(
"type" =>
"restricted");
4106 $a_xml_writer->xmlElement(
"access", $attribs);
4109 $attrs = array(
"type" =>
"date");
4114 $attrs = array(
"type" =>
"date");
4115 $a_xml_writer->xmlElement(
"endingtime", $attrs, sprintf(
"%04d-%02d-%02dT00:00:00", $this->
getEndYear(), $this->
getEndMonth(), $this->
getEndDay()));
4117 $a_xml_writer->xmlEndTag(
"restrictions");
4121 $hasconstraints = FALSE;
4122 foreach ($pages as $question_array)
4124 foreach ($question_array as $question)
4126 if (count($question[
"constraints"]))
4128 $hasconstraints = TRUE;
4133 if ($hasconstraints)
4135 $a_xml_writer->xmlStartTag(
"constraints");
4136 foreach ($pages as $question_array)
4138 foreach ($question_array as $question)
4140 if (count($question[
"constraints"]))
4143 foreach ($question[
"constraints"] as $constraint)
4146 "sourceref" => $question[
"question_id"],
4147 "destref" => $constraint[
"question"],
4148 "relation" => $constraint[
"short"],
4149 "value" => $constraint[
"value"]
4151 $a_xml_writer->xmlElement(
"constraint", $attribs);
4156 $a_xml_writer->xmlEndTag(
"constraints");
4160 $a_xml_writer->xmlStartTag(
"metadata");
4162 $a_xml_writer->xmlStartTag(
"metadatafield");
4163 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"evaluation_access");
4165 $a_xml_writer->xmlEndTag(
"metadatafield");
4167 $a_xml_writer->xmlStartTag(
"metadatafield");
4168 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"status");
4169 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->
getStatus());
4170 $a_xml_writer->xmlEndTag(
"metadatafield");
4172 $a_xml_writer->xmlStartTag(
"metadatafield");
4173 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"display_question_titles");
4175 $a_xml_writer->xmlEndTag(
"metadatafield");
4177 $a_xml_writer->xmlStartTag(
"metadatafield");
4178 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"SCORM");
4179 include_once
"./Services/MetaData/classes/class.ilMD.php";
4182 $md->toXml($writer);
4183 $metadata = $writer->xmlDumpMem();
4184 $a_xml_writer->xmlElement(
"fieldentry", NULL, $metadata);
4185 $a_xml_writer->xmlEndTag(
"metadatafield");
4187 $a_xml_writer->xmlEndTag(
"metadata");
4188 $a_xml_writer->xmlEndTag(
"survey");
4190 $attribs = array(
"id" => $this->
getId());
4191 $a_xml_writer->xmlStartTag(
"surveyquestions", $attribs);
4194 foreach ($pages as $question_array)
4196 if (count($question_array) > 1)
4198 $attribs = array(
"id" => $question_array[0][
"question_id"]);
4199 $attribs = array(
"showQuestiontext" => $question_array[0][
"questionblock_show_questiontext"]);
4200 $a_xml_writer->xmlStartTag(
"questionblock", $attribs);
4201 if (strlen($question_array[0][
"questionblock_title"]))
4203 $a_xml_writer->xmlElement(
"questionblocktitle", NULL, $question_array[0][
"questionblock_title"]);
4206 foreach ($question_array as $question)
4208 if (strlen($question[
"heading"]))
4210 $a_xml_writer->xmlElement(
"textblock", NULL, $question[
"heading"]);
4213 if ($questionObject !== FALSE) $questionObject->insertXML($a_xml_writer, FALSE, $obligatory_states[$question[
"question_id"]]);
4215 if (count($question_array) > 1)
4217 $a_xml_writer->xmlEndTag(
"questionblock");
4221 $a_xml_writer->xmlEndTag(
"surveyquestions");
4222 $a_xml_writer->xmlEndTag(
"surveyobject");
4223 $xml = $a_xml_writer->xmlDumpMem(FALSE);
4238 if ($question_id < 1)
return FALSE;
4239 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
4241 if (strlen($question_type) == 0)
return FALSE;
4243 $question =
new $question_type();
4244 $question->loadFromDb($question_id);
4258 if (!is_dir($a_dir) || is_int(strpos($a_dir,
"..")))
4262 $importDirectory =
"";
4265 $current_dir = opendir($a_dir);
4267 while($entryname = readdir($current_dir))
4274 if(is_dir($a_dir.
"/".$file) and ($file !=
"." and $file!=
".."))
4277 $importDirectory = $a_dir.
"/".
$file;
4280 closedir($current_dir);
4281 if (strlen($importDirectory))
4284 $current_dir = opendir($importDirectory);
4286 while($entryname = readdir($current_dir))
4292 if(@is_file($importDirectory.
"/".$file) && ($file !=
"." && $file!=
"..") && (strcmp(strtolower(substr($file, -4, 4)),
".xml") == 0))
4295 $xmlFile = $importDirectory.
"/".
$file;
4299 return array(
"dir" => $importDirectory,
"xml" => $xmlFile);
4313 $source = $file_info[
"tmp_name"];
4315 if (($source ==
'none') || (!$source) || $file_info[
"error"] > UPLOAD_ERR_OK)
4317 $error = $this->lng->txt(
"import_no_file_selected");
4322 if ((strcmp($file_info[
"type"],
"text/xml") == 0) || (strcmp($file_info[
"type"],
"application/xml") == 0))
4326 if (strpos($file_info[
"type"],
"zip") !== FALSE)
4330 if (!$isXml && !$isZip)
4332 $error = $this->lng->txt(
"import_wrong_file_type");
4334 $ilLog->write(
"Survey: Import error. Filetype was \"" . $file_info[
"type"] .
"\"");
4336 if (strlen($error) == 0)
4340 $import_subdir =
"";
4342 include_once
"./Services/Utilities/classes/class.ilUtil.php";
4345 $importfile = $import_dir.
"/".$file_info[
"name"];
4349 if (!((strlen($found[
"dir"]) > 0) && (strlen($found[
"xml"]) > 0)))
4351 $error = $this->lng->txt(
"wrong_import_file_structure");
4354 $importfile = $found[
"xml"];
4355 $import_subdir = $found[
"dir"];
4359 $importfile = tempnam($import_dir,
"survey_import");
4362 $fh = fopen($importfile,
"r");
4365 $error = $this->lng->txt(
"import_error_opening_file");
4368 $xml = fread($fh, filesize($importfile));
4372 $error = $this->lng->txt(
"import_error_closing_file");
4377 if (strpos($xml,
"questestinterop"))
4379 include_once
"./Services/Survey/classes/class.SurveyImportParserPre38.php";
4380 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
4383 $import->setSurveyObject($this);
4384 $import->setXMLContent($xml);
4385 $import->startParsing();
4389 include_once
"./Services/Survey/classes/class.SurveyImportParser.php";
4390 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
4393 $import->setSurveyObject($this);
4394 $import->setXMLContent($xml);
4395 $import->startParsing();
4398 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
4400 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
4401 include_once
"./Services/RTE/classes/class.ilRTE.php";
4402 include_once
"./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
4403 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
4405 $importfile = $import_subdir .
"/" . $mob[
"uri"];
4406 if (file_exists($importfile))
4410 $this->
setIntroduction(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $this->
getIntroduction()));
4411 $this->
setOutro(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $this->
getOutro()));
4416 $ilLog->write(
"Error: Could not open XHTML mob file for test introduction during test import. File $importfile does not exist!");
4443 $result_array = array();
4445 if (count($surveys))
4448 $query = sprintf(
"SELECT object_data.*, object_reference.ref_id FROM object_data, object_reference WHERE object_data.obj_id = object_reference.obj_id AND object_reference.ref_id IN ('%s') ORDER BY object_data.title",
4449 implode(
"','", $surveys)
4451 $result = $ilDB->query($query);
4452 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
4456 $result_array[$row[
"obj_id"]] = $titles[$row[
"ref_id"]];
4460 $result_array[$row[
"ref_id"]] = $titles[$row[
"ref_id"]];
4464 return $result_array;
4487 $newObj->outro = $this->
getOutro();
4498 $question_pointer = array();
4501 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
4502 foreach ($this->questions as $key => $question_id)
4507 $question->saveToDb($original_id);
4508 $newObj->questions[$key] = $question->getId();
4509 $question_pointer[$question_id] = $question->getId();
4510 $mapping[$question_id] = $question->getId();
4513 $newObj->saveToDb();
4514 $newObj->cloneTextblocks($mapping);
4517 $questionblocks = array();
4518 $questionblock_questions = array();
4519 $query = sprintf(
"SELECT * FROM survey_questionblock_question WHERE survey_fi = %s",
4520 $ilDB->quote($this->getSurveyId() .
"")
4522 $result = $ilDB->query($query);
4525 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
4527 array_push($questionblock_questions, $row);
4528 $questionblocks[$row[
"questionblock_fi"]] = $row[
"questionblock_fi"];
4532 foreach ($questionblocks as $key => $value)
4536 $questionblocks[$key] = $questionblock_id;
4539 foreach ($questionblock_questions as $key => $value)
4541 $clonequery = sprintf(
"INSERT INTO survey_questionblock_question (questionblock_question_id, survey_fi, questionblock_fi, question_fi) VALUES (NULL, %s, %s, %s)",
4542 $ilDB->quote($newObj->getSurveyId() .
""),
4543 $ilDB->quote($questionblocks[$value[
"questionblock_fi"]] .
""),
4544 $ilDB->quote($question_pointer[$value[
"question_fi"]] .
"")
4546 $cloneresult = $ilDB->query($clonequery);
4551 foreach ($constraints as $key => $constraint)
4553 $newObj->addConstraint($question_pointer[$constraint[
"for_question"]], $question_pointer[$constraint[
"question"]], $constraint[
"relation_id"], $constraint[
"value"]);
4557 $query = sprintf(
"SELECT * FROM survey_question_obligatory WHERE survey_fi = %s",
4558 $ilDB->quote($this->getSurveyId() .
"")
4560 $result = $ilDB->query($query);
4563 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
4565 $clonequery = sprintf(
"INSERT INTO survey_question_obligatory (question_obligatory_id, survey_fi, question_fi, obligatory, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
4566 $ilDB->quote($newObj->getSurveyId() .
""),
4567 $ilDB->quote($question_pointer[$row[
"question_fi"]] .
""),
4568 $ilDB->quote($row[
"obligatory"])
4570 $cloneresult = $ilDB->query($clonequery);
4579 $query = sprintf(
"SELECT * FROM survey_survey_question WHERE question_fi = %s",
4580 $ilDB->quote($question_id .
"")
4582 $result = $ilDB->query($query);
4583 if ($result->numRows())
4585 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
4586 return $row[
"heading"];
4603 foreach ($mapping as $original_id => $new_id)
4606 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
4618 include_once
"./Services/Utilities/classes/class.ilUtil.php";
4621 if(!is_writable($svy_data_dir))
4623 $this->ilias->raiseError(
"Survey Data Directory (".$svy_data_dir
4624 .
") not writeable.",$this->ilias->error_obj->FATAL);
4628 $svy_dir = $svy_data_dir.
"/svy_".$this->
getId();
4630 if(!@is_dir($svy_dir))
4632 $this->ilias->raiseError(
"Creation of Survey Directory failed.",$this->ilias->error_obj->FATAL);
4635 $export_dir = $svy_dir.
"/export";
4637 if(!@is_dir($export_dir))
4639 $this->ilias->raiseError(
"Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
4648 include_once
"./Services/Utilities/classes/class.ilUtil.php";
4660 if (!@is_dir(
$dir) or
4661 !is_writeable(
$dir))
4673 while ($entry =
$dir->read())
4675 if ($entry !=
"." and
4677 ereg(
"^[0-9]{10}_{2}[0-9]+_{2}(survey__)*[0-9]+\.xml|zip\$", $entry))
4699 include_once
"./Services/Utilities/classes/class.ilUtil.php";
4703 if(!is_writable($svy_data_dir))
4705 $this->ilias->raiseError(
"Survey Data Directory (".$svy_data_dir
4706 .
") not writeable.",$this->ilias->error_obj->FATAL);
4710 $svy_dir = $svy_data_dir.
"/svy_".$this->
getId();
4712 if(!@is_dir($svy_dir))
4714 $this->ilias->raiseError(
"Creation of Survey Directory failed.",$this->ilias->error_obj->FATAL);
4718 $import_dir = $svy_dir.
"/import";
4720 if(!@is_dir($import_dir))
4722 $this->ilias->raiseError(
"Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
4731 include_once
"./Services/Utilities/classes/class.ilUtil.php";
4733 "/svy_".$this->getId().
"/import";
4734 if (!is_dir($import_dir))
4738 if(@is_dir($import_dir))
4753 $query = sprintf(
"UPDATE survey_survey_question SET heading=%s WHERE survey_fi=%s AND question_fi=%s",
4754 $ilDB->quote($heading),
4756 $ilDB->quote($insertbefore)
4761 $query = sprintf(
"UPDATE survey_survey_question SET heading=NULL WHERE survey_fi=%s AND question_fi=%s",
4762 $ilDB->quote($this->getSurveyId() .
""),
4763 $ilDB->quote($insertbefore)
4766 $ilDB->query($query);
4773 $query = sprintf(
"SELECT ref_id FROM object_reference WHERE obj_id=%s",
4774 $ilDB->quote($obj_id)
4777 $result = $ilDB->query($query);
4778 if ($result->numRows())
4780 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
4781 return $row[
"ref_id"];
4790 $query = sprintf(
"SELECT anonymous_id FROM survey_anonymous WHERE survey_key = %s AND survey_fi = %s",
4791 $ilDB->quote($key .
""),
4794 $result = $ilDB->query($query);
4795 if ($result->numRows() == 1)
4810 $query = sprintf(
"SELECT anonymous_id FROM survey_finished WHERE survey_fi = %s AND user_fi = %s",
4811 $ilDB->quote($this->getSurveyId() .
""),
4812 $ilDB->quote($user_id .
"")
4814 $result = $ilDB->query($query);
4815 if ($result->numRows() == 1)
4817 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
4818 return $row[
"anonymous_id"];
4830 $query = sprintf(
"SELECT finished_id FROM survey_finished WHERE anonymous_id = %s AND survey_fi = %s",
4831 $ilDB->quote($key .
""),
4834 $result = $ilDB->query($query);
4835 if ($result->numRows() == 1)
4876 $query = sprintf(
"SELECT anonymous_id FROM survey_anonymous WHERE survey_fi = %s AND ISNULL(user_key)",
4877 $ilDB->quote($this->getSurveyId() .
"")
4879 $result = $ilDB->query($query);
4900 $query = sprintf(
"SELECT survey_anonymous.*, survey_anonymous.TIMESTAMP + 0 AS timestamp14, survey_finished.state FROM survey_anonymous LEFT JOIN survey_finished ON survey_anonymous.survey_key = survey_finished.anonymous_id WHERE survey_anonymous.survey_fi = %s AND ISNULL(survey_anonymous.user_key)",
4901 $ilDB->quote($this->getSurveyId() .
"")
4903 $result = $ilDB->query($query);
4906 $result = $ilDB->query($query);
4908 $lang = ($_POST[
"lang"] != 1) ?
"&lang=" . $_POST[
"lang"] :
"";
4909 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
4911 if (in_array($row[
"survey_key"], $a_array) || (count($a_array) == 0))
4913 $export .= $row[
"survey_key"] .
",";
4918 $export .=
"$created,";
4927 $url = ILIAS_HTTP_PATH.
"/goto.php?cmd=infoScreen&target=svy_".$this->
getRefId() .
"&client_id=" . CLIENT_ID .
"&accesscode=".$row[
"survey_key"].$lang;
4928 $export .= $url .
"\n";
4949 include_once
"./classes/class.ilFormat.php";
4951 if (strlen($offset) == 0) $offset = 0;
4952 if (strlen($limit) == 0) $limit = 10;
4954 $order =
"ORDER BY timestamp14, survey_key ASC";
4956 $query = sprintf(
"SELECT survey_anonymous.anonymous_id, survey_anonymous.survey_key, survey_anonymous.survey_fi, survey_anonymous.TIMESTAMP + 0 AS timestamp14, survey_finished.state FROM survey_anonymous LEFT JOIN survey_finished ON survey_anonymous.survey_key = survey_finished.anonymous_id WHERE survey_anonymous.survey_fi = %s AND ISNULL(survey_anonymous.user_key) $order LIMIT $offset,$limit",
4957 $ilDB->quote($this->getSurveyId() .
"")
4959 $result = $ilDB->query($query);
4960 $counter = $offset+1;
4963 while ($row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC))
4969 $state =
"<span class=\"smallred\">" . $this->lng->txt(
"not_used") .
"</span>";
4972 $state =
"<span class=\"smallgreen\">" . $this->lng->txt(
"used") .
"</span>";
4979 $addlang =
"&lang=$lang";
4981 $url =
"<a href=\"" . ILIAS_HTTP_PATH.
"/goto.php?cmd=infoScreen&target=svy_".$this->
getRefId() .
"&client_id=" . CLIENT_ID .
"&accesscode=".$row[
"survey_key"].$addlang .
"\">";
4982 $url .= $this->lng->txt(
"survey_code_url_name");
4985 $counter =
"<input type=\"checkbox\" name=\"chb_code[]\" value=\"" . $row[
"survey_key"] .
"\"/>";
4986 array_push($codes, array($counter, $row[
"survey_key"], $created, $state, $url));
4996 $query = sprintf(
"SELECT finished_id FROM survey_finished WHERE survey_fi = %s AND anonymous_id = %s",
4997 $ilDB->quote($this->getSurveyId() .
""),
5000 $result = $ilDB->query($query);
5001 if ($result->numRows() > 0)
5014 for ($i = 0; $i < $nrOfCodes; $i++)
5017 $query = sprintf(
"INSERT INTO survey_anonymous (anonymous_id, survey_key, survey_fi, TIMESTAMP) VALUES (NULL, %s, %s, NULL)",
5018 $ilDB->quote($anonymize_key .
""),
5021 $result = $ilDB->query($query);
5036 if (strlen($survey_code) > 0)
5038 $query = sprintf(
"DELETE FROM survey_anonymous WHERE survey_fi = %s AND survey_key = %s",
5039 $ilDB->quote($this->getSurveyId() .
""),
5040 $ilDB->quote($survey_code)
5042 $ilDB->query($query);
5058 $query = sprintf(
"SELECT survey_key FROM survey_anonymous WHERE survey_fi = %s AND user_key = %s",
5059 $ilDB->quote($this->getSurveyId() .
""),
5060 $ilDB->quote(md5($user_id))
5062 $result = $ilDB->query($query);
5063 if ($result->numRows())
5065 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
5066 $access_code = $row[
"survey_key"];
5068 return $access_code;
5082 $query = sprintf(
"INSERT INTO survey_anonymous (survey_key, survey_fi, user_key) VALUES (%s, %s, %s)",
5083 $ilDB->quote($access_code .
""),
5085 $ilDB->quote(md5($user_id) .
"")
5087 $result = $ilDB->query($query);
5098 $codestring =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
5101 for ($i = 1; $i <=5; $i++)
5103 $index = mt_rand(0, strlen($codestring)-1);
5104 $code .= substr($codestring, $index, 1);
5129 $resultarray = array();
5130 foreach ($row as $rowindex => $entry)
5137 if (strpos($entry,
"\"") !== FALSE)
5139 $entry = str_replace(
"\"",
"\"\"", $entry);
5147 $entry = str_replace(chr(13).chr(10), chr(10), $entry);
5150 $resultarray[$rowindex] = utf8_decode(
"\"" . $entry .
"\"");
5154 $resultarray[$rowindex] = utf8_decode($entry);
5157 return $resultarray;
5164 $query = sprintf(
"SELECT TIMESTAMP+0 AS timestamp14 FROM survey_answer WHERE active_fi = %s ORDER BY TIMESTAMP DESC",
5165 $ilDB->quote($finished_id .
"")
5167 $result = $ilDB->query($query);
5168 if ($result->numRows())
5170 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
5171 return $row[
"timestamp14"];
5175 $query = sprintf(
"SELECT TIMESTAMP+0 AS timestamp14 FROM survey_finished WHERE finished_id = %s",
5176 $ilDB->quote($finished_id .
"")
5178 $result = $ilDB->query($query);
5179 if ($result->numRows())
5181 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
5182 return $row[
"timestamp14"];
5196 include_once
"./Services/Utilities/classes/class.ilUtil.php";
5209 if (preg_match(
"/<[^>]*?>/", $a_text))
5227 function addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag = TRUE, $add_mobs = TRUE, $attribs = NULL)
5229 include_once
"./Services/RTE/classes/class.ilRTE.php";
5230 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
5232 $a_xml_writer->xmlStartTag(
"material", $attribs);
5234 "type" =>
"text/plain"
5236 if ($this->
isHTML($a_material))
5238 $attrs[
"type"] =
"text/xhtml";
5241 $a_xml_writer->xmlElement(
"mattext", $attrs, $mattext);
5246 foreach (
$mobs as $mob)
5248 $mob_id =
"il_" . IL_INST_ID .
"_mob_" . $mob;
5249 if (strpos($mattext, $mob_id) !== FALSE)
5254 "uri" =>
"objects/" .
"il_" . IL_INST_ID .
"_mob_" . $mob .
"/" . $mob_obj->getTitle()
5256 $a_xml_writer->xmlElement(
"matimage", $imgattrs, NULL);
5260 if ($close_material_tag) $a_xml_writer->xmlEndTag(
"material");
5275 if ($this->surveyCodeSecurity == FALSE)
5294 $print_output = str_replace(
" ",
" ", $print_output);
5295 $print_output = str_replace(
"⊗",
"X", $print_output);
5296 $xsl = file_get_contents(
"./Modules/Survey/xml/question2fo.xsl");
5297 $args = array(
'/_xml' => $print_output,
'/_xsl' => $xsl );
5300 $output =
xslt_process($xh,
"arg:/_xml",
"arg:/_xsl", NULL, $args, $params);
5303 global
$ilLog; $ilLog->write($output);
5317 include_once
"./Services/Utilities/classes/class.ilUtil.php";
5319 $fp = fopen($fo_file,
"w"); fwrite($fp, $fo); fclose($fp);
5320 include_once
"./Services/Transformation/classes/class.ilFO2PDF.php";
5322 $fo2pdf->setFOString($fo);
5331 $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
5337 include_once(
"./Modules/Survey/classes/class.ilObjSurveyAccess.php");
5362 global $ilPluginAdmin;
5363 if ($ilPluginAdmin->isActive(
IL_COMP_MODULE,
"SurveyQuestionPool",
"svyq", $a_pname))