34 include_once
"./classes/class.ilObject.php";
35 include_once
"./Modules/Survey/classes/inc.SurveyConstants.php";
205 $this->
ilObject($a_id,$a_call_by_reference);
207 $this->survey_id = -1;
208 $this->introduction =
"";
209 $this->outro = $this->lng->txt(
"survey_finished");
211 $this->_redirect_only_kiosk_mode = TRUE;
212 $this->_mail_confirmation = TRUE;
213 $this->_mail_confirmation_subject = $this->lng->txt(
"mail_confirmation_subject");
214 $this->_mail_confirmation_body = $this->lng->txt(
"mail_confirmation_body");
216 $this->author = $ilUser->fullname;
219 $this->startdate_enabled = 0;
220 $this->enddate_enabled = 0;
221 $this->questions = array();
226 $this->surveyCodeSecurity = TRUE;
227 $this->mailnotification =
false;
263 if (!parent::update())
285 function read($a_force_db =
false)
299 array_push($this->questions, $question_id);
321 foreach ($this->questions as $question_id)
340 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_svy WHERE survey_id = %s",
345 $result = $ilDB->queryF(
"SELECT questionblock_fi FROM svy_qblk_qst WHERE survey_fi = %s",
349 $questionblocks = array();
350 while (
$row = $ilDB->fetchAssoc($result))
352 array_push($questionblocks,
$row[
"questionblock_fi"]);
354 if (count($questionblocks))
356 $affectedRows = $ilDB->manipulate(
"DELETE FROM svy_qblk WHERE " . $ilDB->in(
'questionblock_id', $questionblocks,
false,
'integer'));
358 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qblk_qst WHERE survey_fi = %s",
364 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_anonymous WHERE survey_fi = %s",
370 include_once
"./Services/Utilities/classes/class.ilUtil.php";
372 $directory = $svy_data_dir.
"/svy_".$this->
getId();
373 if (is_dir($directory))
375 include_once
"./Services/Utilities/classes/class.ilUtil.php";
379 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
385 foreach(
$mobs as $mob)
402 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE survey_fi = %s",
406 $active_array = array();
407 while (
$row = $ilDB->fetchAssoc($result))
409 array_push($active_array,
$row[
"finished_id"]);
412 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_finished WHERE survey_fi = %s",
417 foreach ($active_array as $active_fi)
419 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_answer WHERE active_fi = %s",
423 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_times WHERE finished_fi = %s",
439 foreach ($finished_ids as $finished_id)
441 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE finished_id = %s",
445 $row = $ilDB->fetchAssoc($result);
447 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_answer WHERE active_fi = %s",
449 array(
$row[
"finished_id"])
452 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_finished WHERE finished_id = %s",
457 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_times WHERE finished_fi = %s",
459 array(
$row[
"finished_id"])
468 $result = $ilDB->queryF(
"SELECT * FROM svy_finished WHERE survey_fi = %s",
472 $participants = array();
473 if ($result->numRows() > 0)
475 while (
$row = $ilDB->fetchAssoc($result))
478 $participants[$userdata[
"sortname"] . $userdata[
"active_id"]] = $userdata;
481 return $participants;
489 $query = sprintf(
"SELECT * FROM svy_finished WHERE survey_fi = %s",
490 $ilDB->quote($this->getSurveyId() .
"")
492 $result = $ilDB->query(
$query);
493 $participants = array();
494 if ($result->numRows() > 0)
499 $userdata[
"status"] =
$row[
"state"];
500 $participants[$userdata[
"sortname"] . $userdata[
"active_id"]] = $userdata;
503 return $participants;
519 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
559 if ($a_node_id==
$_GET[
"ref_id"])
561 $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
562 $parent_type = $parent_obj->getType();
563 if($parent_type == $this->
getType())
565 $a_node_id = (int) $tree->getParentId($a_node_id);
569 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
580 if (($this->
getTitle()) and (count($this->questions)))
599 $survey->loadFromDb();
600 if (($survey->getTitle()) and (count($survey->questions)))
619 $survey->loadFromDb();
621 if (($survey->getTitle()) and ($survey->author) and (count($survey->questions)))
623 $result[
"complete"] =
true;
627 $result[
"complete"] =
false;
629 $result[
"evaluation_access"] = $survey->getEvaluationAccess();
649 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_svy SET complete = %s, tstamp = %s WHERE survey_id = %s",
650 array(
'text',
'integer',
'integer'),
668 $question_gui = $this->
getQuestionGUI($questiontype, $question_id);
669 $duplicate_id = $question_gui->object->duplicate(
true);
670 return $duplicate_id;
682 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
690 $result = $ilDB->queryF(
"SELECT survey_question_id FROM svy_svy_qst WHERE survey_fi = %s",
694 $sequence = $result->numRows();
696 $next_id = $ilDB->nextId(
'svy_svy_qst');
697 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_svy_qst (survey_question_id, survey_fi, question_fi, sequence, tstamp) VALUES (%s, %s, %s, %s, %s)",
698 array(
'integer',
'integer',
'integer',
'integer',
'integer'),
699 array($next_id, $this->
getSurveyId(), $duplicate_id, $sequence, time())
715 $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",
717 array($questionblock_id)
720 $show_questiontext = 0;
721 while (
$row = $ilDB->fetchAssoc($result))
726 $show_questiontext =
$row[
"show_questiontext"];
740 array_push($result, $this->
getOutro());
751 include_once(
"./Services/RTE/classes/class.ilRTE.php");
752 $completecontent =
"";
755 $completecontent .= $content;
765 $next_id = $ilDB->nextId(
'svy_settings');
766 $affectedRows = $ilDB->insert(
"svy_settings", array(
767 "settings_id" => array(
"integer", $next_id),
768 "usr_id" => array(
"integer",
$usr_id),
769 "keyword" => array(
"text", $key),
770 "title" => array(
"text",
$title),
771 "value" => array(
"clob", $value)
779 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_settings WHERE settings_id = %s",
783 return $affectedRows;
790 $result = $ilDB->queryF(
"SELECT * FROM svy_settings WHERE usr_id = %s AND keyword = %s",
791 array(
'integer',
'text'),
795 if ($result->numRows())
797 while (
$row = $ilDB->fetchAssoc($result))
814 include_once(
"./Services/RTE/classes/class.ilRTE.php");
818 $next_id = $ilDB->nextId(
'svy_svy');
819 $affectedRows = $ilDB->insert(
"svy_svy", array(
820 "survey_id" => array(
"integer", $next_id),
821 "obj_fi" => array(
"integer", $this->
getId()),
822 "author" => array(
"text", $this->
getAuthor()),
830 "status" => array(
"text", $this->
getStatus()),
832 "enddate" => array(
"text", $this->
getEndDate()),
836 "complete" => array(
"text", $this->
isComplete()),
837 "created" => array(
"integer", time()),
843 "tstamp" => array(
"integer", time())
849 $affectedRows = $ilDB->update(
"svy_svy", array(
850 "author" => array(
"text", $this->
getAuthor()),
858 "status" => array(
"text", $this->
getStatus()),
860 "enddate" => array(
"text", $this->
getEndDate()),
864 "complete" => array(
"text", $this->
isComplete()),
870 "tstamp" => array(
"integer", time())
872 "survey_id" => array(
"integer", $this->
getSurveyId())
892 $old_questions = array();
893 $result = $ilDB->queryF(
"SELECT * FROM svy_svy_qst WHERE survey_fi = %s",
897 if ($result->numRows())
899 while (
$row = $ilDB->fetchAssoc($result))
901 $old_questions[
$row[
"question_fi"]] =
$row;
906 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_svy_qst WHERE survey_fi = %s",
911 foreach ($this->questions as $key => $value)
913 $next_id = $ilDB->nextId(
'svy_svy_qst');
914 $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)",
915 array(
'integer',
'integer',
'integer',
'text',
'integer',
'integer'),
916 array($next_id, $this->
getSurveyId(), $value, (strlen($old_questions[$value][
"heading"])) ? $old_questions[$value][
"heading"] : NULL, $key, time())
931 $result = $ilDB->queryF(
"SELECT anonymous_id FROM svy_finished WHERE anonymous_id = %s",
935 if ($result->numRows())
937 $row = $ilDB->fetchAssoc($result);
938 return $row[
"anonymous_id"];
954 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
968 if ($question_id < 1)
return -1;
969 $result = $ilDB->queryF(
"SELECT type_tag FROM svy_question, svy_qtype WHERE svy_question.question_id = %s AND " .
970 "svy_question.questiontype_fi = svy_qtype.questiontype_id",
974 if ($result->numRows() == 1)
976 $data = $ilDB->fetchAssoc($result);
977 return $data[
"type_tag"];
1001 switch ($a_anonymize)
1006 $this->anonymize = $a_anonymize;
1021 return ($this->anonymize) ? $this->anonymize : 0;
1049 $result = $ilDB->queryF(
"SELECT * FROM svy_svy WHERE obj_fi = %s",
1051 array($this->
getId())
1053 if ($result->numRows() == 1)
1055 $data = $ilDB->fetchAssoc($result);
1058 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1060 if (strcmp(
$data[
"outro"],
"survey_finished") == 0)
1062 $this->
setOutro($this->lng->txt(
"survey_finished"));
1072 if (strcmp(
$data[
"mail_confirmation_body"],
"mail_confirmation_body") == 0)
1106 $this->questions = array();
1107 $result = $ilDB->queryF(
"SELECT * FROM svy_svy_qst WHERE survey_fi = %s ORDER BY sequence",
1111 while (
$data = $ilDB->fetchAssoc($result))
1113 $this->questions[
$data[
"sequence"]] = $data[
"question_fi"];
1126 $this->startdate_enabled = ($enabled) ? $enabled : 0;
1138 return ($this->startdate_enabled) ? $this->startdate_enabled : 0;
1150 $this->enddate_enabled = ($enabled) ? $enabled : 0;
1162 return ($this->enddate_enabled) ? $this->enddate_enabled : 0;
1189 $md_life =& $md->getLifecycle();
1192 if (strlen($a_author) == 0)
1195 $a_author = $ilUser->getFullname();
1198 $md_life =& $md->addLifecycle();
1200 $con =& $md_life->addContribute();
1201 $con->setRole(
"Author");
1203 $ent =& $con->addEntity();
1204 $ent->setEntity($a_author);
1219 include_once
"./Services/MetaData/classes/class.ilMD.php";
1221 $md_life =& $md->getLifecycle();
1224 $ids =& $md_life->getContributeIds();
1225 foreach ($ids as
$id)
1227 $md_cont =& $md_life->getContribute($id);
1228 if (strcmp($md_cont->getRole(),
"Author") == 0)
1230 $entids =& $md_cont->getEntityIds();
1231 foreach ($entids as $entid)
1233 $md_ent =& $md_cont->getEntity($entid);
1234 array_push(
$author, $md_ent->getEntity());
1250 return ($this->display_question_titles) ? 1 : 0;
1261 $this->display_question_titles = ($a_show) ? 1 : 0;
1272 $this->display_question_titles = 1;
1283 $this->display_question_titles = 0;
1306 $result = $ilDB->query(
"SELECT usr_id FROM usr_data");
1307 while (
$row = $ilDB->fetchAssoc($result))
1309 if ($ilAccess->checkAccessOfUser(
$row[
"usr_id"],
"read",
"", $this->getRefId(),
"svy", $this->
getId()))
1378 $this->_redirect_after_survey = $a_url;
1392 $this->_redirect_only_kiosk_mode = $a_int;
1406 $this->_mail_confirmation = $a_int;
1420 $this->_mail_confirmation_subject = $a_subject;
1434 $this->_mail_confirmation_body = $a_body;
1460 include_once
"./Services/Administration/classes/class.ilSetting.php";
1461 $surveySetting =
new ilSetting(
"survey");
1462 $unlimited_invitation = $surveySetting->get(
"unlimited_invitation");
1463 if (!$unlimited_invitation && $this->invitation_mode ==
MODE_UNLIMITED)
1469 return ($this->invitation_mode) ? $this->invitation_mode :
MODE_UNLIMITED;
1523 $result = $this->lng->txt(
"cannot_switch_to_online_no_questions");
1541 return (strlen($this->start_date)) ? $this->start_date : NULL;
1559 if (preg_match(
"/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $this->
getStartDate(), $matches))
1561 $epoch_time = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
1563 if ($now < $epoch_time)
1565 array_push(
$messages,$this->lng->txt(
'start_date_not_reached').
' ('.
1574 if (preg_match(
"/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $this->
getEndDate(), $matches))
1576 $epoch_time = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
1578 if ($now > $epoch_time)
1580 array_push(
$messages,$this->lng->txt(
'end_date_reached').
' ('.
1589 array_push(
$messages, $this->lng->txt(
"survey_is_offline"));
1593 if (!$ilAccess->checkAccess(
"read",
"", $this->ref_id))
1595 array_push(
$messages, $this->lng->txt(
"cannot_participate_survey"));
1599 if (!$result[
"error"])
1602 $survey_started = $this->
isSurveyStarted($ilUser->getId(), $anonymous_id);
1603 if ($survey_started === 1)
1605 array_push(
$messages, $this->lng->txt(
"already_completed_survey"));
1610 "result" => $result,
1637 $y =
''; $m =
'';
$d =
''; $h =
''; $i =
''; $s =
'';
1638 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})/",
$start_date, $matches))
1644 if (preg_match(
"/(\d{2}):(\d{2}):(\d{2})/", $start_time, $matches))
1650 $this->start_date = sprintf(
'%04d%02d%02d%02d%02d%02d',
$y, $m,
$d, $h, $i, $s);
1727 return (strlen($this->end_date)) ? $this->end_date : NULL;
1752 $y =
''; $m =
'';
$d =
''; $h =
''; $i =
''; $s =
'';
1753 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})/",
$end_date, $matches))
1759 if (preg_match(
"/(\d{2}):(\d{2}):(\d{2})/", $end_time, $matches))
1765 $this->end_date = sprintf(
'%04d%02d%02d%02d%02d%02d',
$y, $m,
$d, $h, $i, $s);
1866 return (strlen($this->introduction)) ? $this->introduction : NULL;
1878 return (strlen($this->outro)) ? $this->outro : NULL;
1951 $existing_questions = array();
1952 $result = $ilDB->queryF(
"SELECT svy_question.original_id FROM svy_question, svy_svy_qst WHERE " .
1953 "svy_svy_qst.survey_fi = %s AND svy_svy_qst.question_fi = svy_question.question_id",
1957 while (
$data = $ilDB->fetchAssoc($result))
1959 array_push($existing_questions,
$data[
"original_id"]);
1961 return $existing_questions;
1972 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1984 $move_questions = array($question_id);
1987 foreach ($pages as $idx => $page)
1989 if ($page[0][
"question_id"] == $question_id)
1996 $this->
moveQuestions($move_questions, $pages[$pageindex-1][0][
"question_id"], 0);
2003 $index = array_search($question_id,
$questions);
2004 if (($index !== FALSE) && ($index > 0))
2018 $move_questions = array($question_id);
2021 foreach ($pages as $idx => $page)
2023 if (($page[0][
"question_id"] == $question_id) && (strcmp($page[0][
"questionblock_id"],
"") == 0))
2028 if (($pageindex < count($pages)-1) && ($pageindex >= 0))
2030 $this->
moveQuestions($move_questions, $pages[$pageindex+1][count($pages[$pageindex+1])-1][
"question_id"], 1);
2037 $index = array_search($question_id,
$questions);
2038 if (($index !== FALSE) && ($index < count(
$questions)-1))
2054 $move_questions = array();
2056 foreach ($pages as $idx => $page)
2058 if ($page[0][
"questionblock_id"] == $questionblock_id)
2060 foreach ($page as $pageidx => $question)
2062 array_push($move_questions, $question[
"question_id"]);
2069 $this->
moveQuestions($move_questions, $pages[$pageindex-1][0][
"question_id"], 0);
2082 $move_questions = array();
2084 foreach ($pages as $idx => $page)
2086 if ($page[0][
"questionblock_id"] == $questionblock_id)
2088 foreach ($page as $pageidx => $question)
2090 array_push($move_questions, $question[
"question_id"]);
2095 if ($pageindex < count($pages)-1)
2097 $this->
moveQuestions($move_questions, $pages[$pageindex+1][count($pages[$pageindex+1])-1][
"question_id"], 1);
2111 $array_pos = array_search($target_index, $this->questions);
2112 if ($insert_mode == 0)
2114 $part1 = array_slice($this->questions, 0, $array_pos);
2115 $part2 = array_slice($this->questions, $array_pos);
2117 else if ($insert_mode == 1)
2119 $part1 = array_slice($this->questions, 0, $array_pos + 1);
2120 $part2 = array_slice($this->questions, $array_pos + 1);
2122 foreach ($move_questions as $question_id)
2124 if (!(array_search($question_id, $part1) === FALSE))
2126 unset($part1[array_search($question_id, $part1)]);
2128 if (!(array_search($question_id, $part2) === FALSE))
2130 unset($part2[array_search($question_id, $part2)]);
2133 $part1 = array_values($part1);
2134 $part2 = array_values($part2);
2135 $this->questions = array_values(array_merge($part1, $move_questions, $part2));
2136 foreach ($move_questions as $question_id)
2139 foreach ($constraints as $idx => $constraint)
2141 foreach ($part2 as $next_question_id)
2143 if ($constraint[
"question"] == $next_question_id)
2162 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
2164 $question->delete($question_id);
2177 $result = $ilDB->queryF(
"SELECT constraint_fi FROM svy_qst_constraint WHERE question_fi = %s AND survey_fi = %s",
2178 array(
'integer',
'integer'),
2181 if ($result->numRows() > 0)
2183 $remove_constraints = array();
2184 while (
$row = $ilDB->fetchAssoc($result))
2186 array_push($remove_constraints,
$row[
"constraint_fi"]);
2188 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qst_constraint WHERE question_fi = %s AND survey_fi = %s",
2189 array(
'integer',
'integer'),
2192 foreach ($remove_constraints as $key => $constraint_id)
2194 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_constraint WHERE constraint_id = %s",
2196 array($constraint_id)
2215 if (in_array($question_id, $remove_questions) or in_array(
$data[
"questionblock_id"], $remove_questionblocks))
2217 unset($this->questions[array_search($question_id, $this->questions)]);
2221 foreach ($remove_questionblocks as $questionblock_id)
2223 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qblk WHERE questionblock_id = %s",
2225 array($questionblock_id)
2227 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qblk_qst WHERE questionblock_fi = %s AND survey_fi = %s",
2228 array(
'integer',
'integer'),
2232 $this->questions = array_values($this->questions);
2245 foreach ($questionblocks as $index)
2247 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qblk WHERE questionblock_id = %s",
2251 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qblk_qst WHERE questionblock_fi = %s AND survey_fi = %s",
2252 array(
'integer',
'integer'),
2268 $result = $ilDB->queryF(
"SELECT svy_question.title, svy_qblk_qst.question_fi, svy_qblk_qst.survey_fi FROM ".
2269 "svy_qblk, svy_qblk_qst, svy_question WHERE svy_qblk.questionblock_id = svy_qblk_qst.questionblock_fi AND " .
2270 "svy_question.question_id = svy_qblk_qst.question_fi AND svy_qblk.questionblock_id = %s",
2272 array($questionblock_id)
2275 while (
$row = $ilDB->fetchAssoc($result))
2277 $titles[
$row[
"question_fi"]] = $row[
"title"];
2280 $result = $ilDB->queryF(
"SELECT question_fi, sequence FROM svy_svy_qst WHERE survey_fi = %s ORDER BY sequence",
2284 $resultarray = array();
2286 while (
$row = $ilDB->fetchAssoc($result))
2288 if (array_key_exists(
$row[
"question_fi"], $titles))
2290 $resultarray[$counter++] = $titles[
$row[
"question_fi"]];
2293 return $resultarray;
2305 $result = $ilDB->queryF(
"SELECT question_fi FROM svy_qblk_qst WHERE questionblock_fi = %s",
2307 array($questionblock_id)
2310 if ($result->numRows())
2312 while (
$data = $ilDB->fetchAssoc($result))
2314 array_push($ids,
$data[
'question_fi']);
2330 $result = $ilDB->queryF(
"SELECT * FROM svy_qblk WHERE questionblock_id = %s",
2332 array($questionblock_id)
2334 return $ilDB->fetchAssoc($result);
2347 $result = $ilDB->queryF(
"SELECT * FROM svy_qblk WHERE questionblock_id = %s",
2349 array($questionblock_id)
2351 $row = $ilDB->fetchAssoc($result);
2366 $next_id = $ilDB->nextId(
'svy_qblk');
2367 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_qblk (questionblock_id, title, owner_fi, tstamp) " .
2368 "VALUES (%s, %s, %s, %s)",
2369 array(
'integer',
'text',
'integer',
'integer'),
2391 $next_id = $ilDB->nextId(
'svy_qblk');
2392 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_qblk (questionblock_id, title, show_questiontext, owner_fi, ".
2393 "tstamp) VALUES (%s, %s, %s, %s, %s)",
2394 array(
'integer',
'text',
'text',
'integer',
'integer'),
2395 array($next_id,
$title, $show_questiontext, $ilUser->getId(), time())
2399 $questionblock_id = $next_id;
2402 $next_id = $ilDB->nextId(
'svy_qblk_qst');
2403 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_qblk_qst (qblk_qst_id, survey_fi, questionblock_fi, " .
2404 "question_fi) VALUES (%s, %s, %s, %s)",
2405 array(
'integer',
'integer',
'integer',
'integer'),
2406 array($next_id, $this->
getSurveyId(), $questionblock_id, $index)
2423 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_qblk SET title = %s, show_questiontext = %s WHERE " .
2424 "questionblock_id = %s",
2425 array(
'text',
'text',
'integer'),
2426 array(
$title, $show_questiontext, $questionblock_id)
2439 $result = $ilDB->queryF(
"SELECT constraint_fi FROM svy_qst_constraint WHERE question_fi = %s AND survey_fi = %s",
2440 array(
'integer',
'integer'),
2443 $constraints = array();
2444 while (
$row = $ilDB->fetchAssoc($result))
2446 array_push($constraints,
$row[
"constraint_fi"]);
2448 foreach ($constraints as $constraint_id)
2464 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_constraint WHERE constraint_id = %s",
2466 array($constraint_id)
2468 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qst_constraint WHERE constraint_fi = %s",
2470 array($constraint_id)
2484 $all_questions = array();
2485 $result = $ilDB->queryF(
"SELECT svy_qtype.type_tag, svy_qtype.plugin, svy_question.question_id, ".
2486 "svy_svy_qst.heading FROM svy_qtype, svy_question, svy_svy_qst WHERE svy_svy_qst.survey_fi = %s AND " .
2487 "svy_svy_qst.question_fi = svy_question.question_id AND svy_question.questiontype_fi = svy_qtype.questiontype_id " .
2488 "ORDER BY svy_svy_qst.sequence",
2492 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
2493 while (
$row = $ilDB->fetchAssoc($result))
2506 $questionrow = $question->_getQuestionDataArray(
$row[
"question_id"]);
2507 foreach (
$row as $key => $value)
2509 $questionrow[$key] = $value;
2511 $all_questions[
$row[
"question_id"]] = $questionrow;
2512 $all_questions[$row[
"question_id"]][
"usableForPrecondition"] = $question->usableForPrecondition();
2513 $all_questions[$row[
"question_id"]][
"availableRelations"] = $question->getAvailableRelations();
2514 if (array_key_exists($row[
"question_id"], $obligatory_states))
2516 $all_questions[$row[
"question_id"]][
"obligatory"] = $obligatory_states[$row[
"question_id"]];
2521 $questionblocks = array();
2522 if (count($all_questions))
2524 $result = $ilDB->queryF(
"SELECT svy_qblk.*, svy_qblk_qst.question_fi FROM svy_qblk, svy_qblk_qst WHERE " .
2525 "svy_qblk.questionblock_id = svy_qblk_qst.questionblock_fi AND svy_qblk_qst.survey_fi = %s " .
2526 "AND " . $ilDB->in(
'svy_qblk_qst.question_fi', array_keys($all_questions),
false,
'integer'),
2530 while (
$row = $ilDB->fetchAssoc($result))
2532 $questionblocks[
$row[
'question_fi']] =
$row;
2536 foreach ($all_questions as $question_id =>
$row)
2539 if (isset($questionblocks[$question_id]))
2541 $all_questions[$question_id][
"questionblock_title"] = $questionblocks[$question_id][
'title'];
2542 $all_questions[$question_id][
"questionblock_id"] = $questionblocks[$question_id][
'questionblock_id'];
2543 $all_questions[$question_id][
"constraints"] = $constraints;
2547 $all_questions[$question_id][
"questionblock_title"] =
"";
2548 $all_questions[$question_id][
"questionblock_id"] =
"";
2549 $all_questions[$question_id][
"constraints"] = $constraints;
2554 $result = $ilDB->queryF(
"SELECT svy_variable.*, svy_category.title FROM svy_variable, svy_category " .
2555 "WHERE svy_variable.question_fi = %s AND svy_variable.category_fi = svy_category.category_id ".
2556 "ORDER BY sequence ASC",
2560 if ($result->numRows() > 0)
2562 while (
$data = $ilDB->fetchAssoc($result))
2564 array_push($answers,
$data[
"title"]);
2567 $all_questions[$question_id][
"answers"] = $answers;
2570 return $all_questions;
2582 $result = $ilDB->queryF(
"SELECT * FROM svy_svy_qst WHERE survey_fi = %s",
2586 if ($result->numRows())
2588 while (
$row = $ilDB->fetchAssoc($result))
2590 if (!array_key_exists(
$row[
"question_fi"], $obligatory_questions))
2592 $obligatory_questions[
$row[
"question_fi"]] = 0;
2598 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_qst_oblig WHERE survey_fi = %s",
2604 foreach ($obligatory_questions as $question_fi => $obligatory)
2606 $next_id = $ilDB->nextId(
'svy_qst_oblig');
2607 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_qst_oblig (question_obligatory_id, survey_fi, question_fi, " .
2608 "obligatory, tstamp) VALUES (%s, %s, %s, %s, %s)",
2609 array(
'integer',
'integer',
'integer',
'text',
'integer'),
2610 array($next_id, $this->
getSurveyId(), $question_fi, (strlen($obligatory)) ? $obligatory : 0, time())
2624 $obligatory_states = array();
2625 $result = $ilDB->queryF(
"SELECT * FROM svy_qst_oblig WHERE survey_fi = %s",
2629 if ($result->numRows())
2631 while (
$row = $ilDB->fetchAssoc($result))
2633 $obligatory_states[
$row[
"question_fi"]] = $row[
"obligatory"];
2636 return $obligatory_states;
2649 $all_questions = array();
2650 $result = $ilDB->queryF(
"SELECT svy_question.*, svy_qtype.type_tag, svy_svy_qst.heading FROM " .
2651 "svy_question, svy_qtype, svy_svy_qst WHERE svy_svy_qst.survey_fi = %s AND " .
2652 "svy_svy_qst.question_fi = svy_question.question_id AND svy_question.questiontype_fi = svy_qtype.questiontype_id ".
2653 "ORDER BY svy_svy_qst.sequence",
2657 while (
$row = $ilDB->fetchAssoc($result))
2659 $all_questions[
$row[
"question_id"]] =
$row;
2662 $questionblocks = array();
2663 if (count($all_questions))
2665 $result = $ilDB->queryF(
"SELECT svy_qblk.*, svy_qblk_qst.question_fi FROM svy_qblk, svy_qblk_qst ".
2666 "WHERE svy_qblk.questionblock_id = svy_qblk_qst.questionblock_fi AND svy_qblk_qst.survey_fi = %s ".
2667 "AND " . $ilDB->in(
'svy_qblk_qst.question_fi', array_keys($all_questions),
false,
'integer'),
2671 while (
$row = $ilDB->fetchAssoc($result))
2673 $questionblocks[
$row[
'question_fi']] =
$row;
2677 $all_pages = array();
2680 foreach ($all_questions as $question_id =>
$row)
2682 if (array_key_exists($question_id, $obligatory_states))
2684 $all_questions[$question_id][
"obligatory"] = $obligatory_states[$question_id];
2686 $constraints = array();
2687 if (isset($questionblocks[$question_id]))
2689 if (!$currentblock or ($currentblock != $questionblocks[$question_id][
'questionblock_id']))
2693 $all_questions[$question_id][
'page'] = $pageindex;
2694 $all_questions[$question_id][
"questionblock_title"] = $questionblocks[$question_id][
'title'];
2695 $all_questions[$question_id][
"questionblock_id"] = $questionblocks[$question_id][
'questionblock_id'];
2696 $all_questions[$question_id][
"questionblock_show_questiontext"] = $questionblocks[$question_id][
'show_questiontext'];
2697 $currentblock = $questionblocks[$question_id][
'questionblock_id'];
2699 $all_questions[$question_id][
"constraints"] = $constraints;
2704 $all_questions[$question_id][
'page'] = $pageindex;
2705 $all_questions[$question_id][
"questionblock_title"] =
"";
2706 $all_questions[$question_id][
"questionblock_id"] =
"";
2707 $all_questions[$question_id][
"questionblock_show_questiontext"] = 1;
2710 $all_questions[$question_id][
"constraints"] = $constraints;
2712 if (!isset($all_pages[$pageindex]))
2714 $all_pages[$pageindex] = array();
2716 array_push($all_pages[$pageindex], $all_questions[$question_id]);
2719 $max = count($all_pages);
2721 foreach ($all_pages as $index => $block)
2723 foreach ($block as $blockindex => $question)
2725 $all_pages[$index][$blockindex][
"position"] = $counter / $max;
2744 if (strcmp($active_page_question_id,
"") == 0)
2748 foreach ($pages as $key => $question_array)
2750 foreach ($question_array as $question)
2752 if ($active_page_question_id == $question[
"question_id"])
2758 if ($foundpage == -1)
2764 $foundpage += $direction;
2769 if ($foundpage >= count($pages))
2773 return $pages[$foundpage];
2785 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
2798 $result_array = array();
2799 $result = $ilDB->queryF(
"SELECT svy_constraint.*, svy_relation.* FROM svy_qst_constraint, svy_constraint, ".
2800 "svy_relation WHERE svy_constraint.relation_fi = svy_relation.relation_id AND ".
2801 "svy_qst_constraint.constraint_fi = svy_constraint.constraint_id AND svy_constraint.constraint_id = %s",
2806 if ($result->numRows())
2808 $pc = $ilDB->fetchAssoc($result);
2822 $result_array = array();
2823 $result = $ilDB->queryF(
"SELECT svy_constraint.*, svy_relation.* FROM svy_qst_constraint, svy_constraint, svy_relation ".
2824 "WHERE svy_constraint.relation_fi = svy_relation.relation_id AND ".
2825 "svy_qst_constraint.constraint_fi = svy_constraint.constraint_id AND svy_qst_constraint.question_fi = %s ".
2826 "AND svy_qst_constraint.survey_fi = %s",
2827 array(
'integer',
'integer'),
2830 while (
$row = $ilDB->fetchAssoc($result))
2832 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
2835 $question =
new $question_type();
2836 $question->loadFromDb(
$row[
"question_fi"]);
2837 $valueoutput = $question->getPreconditionValueOutput(
$row[
"value"]);
2838 array_push($result_array, array(
"id" =>
$row[
"constraint_id"],
"question" =>
$row[
"question_fi"],
"short" =>
$row[
"shortname"],
"long" =>
$row[
"longname"],
"value" =>
$row[
"value"],
"conjunction" =>
$row[
"conjunction"],
"valueoutput" => $valueoutput));
2840 return $result_array;
2851 $result_array = array();
2852 $result = $ilDB->queryF(
"SELECT svy_qst_constraint.question_fi as for_question, svy_constraint.*, svy_relation.* ".
2853 "FROM svy_qst_constraint, svy_constraint, svy_relation WHERE svy_constraint.relation_fi = svy_relation.relation_id ".
2854 "AND svy_qst_constraint.constraint_fi = svy_constraint.constraint_id AND svy_qst_constraint.survey_fi = %s",
2858 while (
$row = $ilDB->fetchAssoc($result))
2860 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"],
'conjunction' =>
$row[
'conjunction']));
2862 return $result_array;
2875 $result_array = array();
2876 $result = $ilDB->queryF(
"SELECT svy_variable.*, svy_category.title FROM svy_variable LEFT JOIN ".
2877 "svy_category ON svy_variable.category_fi = svy_category.category_id WHERE svy_variable.question_fi = %s ".
2878 "ORDER BY svy_variable.sequence",
2882 while (
$row = $ilDB->fetchObject($result))
2884 $result_array[
$row->sequence] =
$row;
2886 return $result_array;
2901 $next_id = $ilDB->nextId(
'svy_constraint');
2902 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_constraint (constraint_id, question_fi, relation_fi, value, conjunction) VALUES ".
2903 "(%s, %s, %s, %s, %s)",
2904 array(
'integer',
'integer',
'integer',
'float',
'integer'),
2905 array($next_id, $if_question_id, $relation, $value, $conjunction)
2928 $next_id = $ilDB->nextId(
'svy_qst_constraint');
2929 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_qst_constraint (question_constraint_id, survey_fi, question_fi, ".
2930 "constraint_fi) VALUES (%s, %s, %s, %s)",
2931 array(
'integer',
'integer',
'integer',
'integer'),
2932 array($next_id, $this->
getSurveyId(), $to_question_id, $constraint_id)
2949 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_constraint SET question_fi = %s, relation_fi = %s, value = %s, conjunction = %s ".
2950 "WHERE constraint_id = %s",
2951 array(
'integer',
'integer',
'float',
'integer',
'integer'),
2952 array($if_question_id, $relation, $value, $conjunction, $precondition_id)
2961 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_constraint SET conjunction = %s ".
2962 "WHERE constraint_id IN (SELECT constraint_fi FROM svy_qst_constraint WHERE svy_qst_constraint.question_fi = %s)",
2963 array(
'integer',
'integer'),
2964 array($conjunction, $question_id)
2978 $result_array = array();
2979 $result = $ilDB->query(
"SELECT * FROM svy_relation");
2980 while (
$row = $ilDB->fetchAssoc($result))
2984 $result_array[
$row[
"shortname"]] = array(
"short" => $row[
"shortname"],
"long" => $row[
"longname"],
"id" => $row[
"relation_id"]);
2988 $result_array[
$row[
"relation_id"]] = array(
"short" => $row[
"shortname"],
"long" => $row[
"longname"]);
2991 return $result_array;
3000 $result = $ilDB->queryF(
"SELECT user_fi FROM svy_inv_usr WHERE survey_fi = %s",
3004 while (
$row = $ilDB->fetchAssoc($result))
3019 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_inv_usr WHERE survey_fi = %s AND user_fi = %s",
3020 array(
'integer',
'integer'),
3023 include_once
'./Services/User/classes/class.ilObjUser.php';
3037 $result = $ilDB->queryF(
"SELECT user_fi FROM svy_inv_usr WHERE user_fi = %s AND survey_fi = %s",
3038 array(
'integer',
'integer'),
3041 if ($result->numRows() < 1)
3043 $next_id = $ilDB->nextId(
'svy_inv_usr');
3044 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_inv_usr (invited_user_id, survey_fi, user_fi, tstamp) " .
3045 "VALUES (%s, %s, %s, %s)",
3046 array(
'integer',
'integer',
'integer',
'integer'),
3047 array($next_id, $this->
getSurveyId(), $user_id, time())
3052 include_once
'./Services/User/classes/class.ilObjUser.php';
3067 include_once
"./Modules/Group/classes/class.ilObjGroup.php";
3069 $members = $group->getGroupMemberIds();
3070 foreach ($members as $user_id)
3072 if ($ilAccess->checkAccessOfUser($user_id,
"read",
"", $this->getRefId(),
"svy", $this->
getId()))
3077 include_once
'./Services/User/classes/class.ilObjUser.php';
3096 $members = $rbacreview->assignedUsers($role_id);
3097 foreach ($members as $user_id)
3099 if ($ilAccess->checkAccessOfUser($user_id,
"read",
"", $this->getRefId(),
"svy", $this->
getId()))
3104 include_once
'./Services/User/classes/class.ilObjUser.php';
3122 $result_array = array();
3123 $result = $ilDB->queryF(
"SELECT user_fi FROM svy_inv_usr WHERE survey_fi = %s",
3127 while (
$row = $ilDB->fetchAssoc($result))
3129 array_push($result_array,
$row[
"user_fi"]);
3131 return $result_array;
3145 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_answer WHERE question_fi = %s AND active_fi = %s",
3146 array(
'integer',
'integer'),
3147 array($question_id, $active_id)
3162 $result_array = array();
3163 $result = $ilDB->queryF(
"SELECT * FROM svy_answer WHERE question_fi = %s AND active_fi = %s",
3164 array(
'integer',
'integer'),
3165 array($question_id, $active_id)
3167 if ($result->numRows() >= 1)
3169 while (
$row = $ilDB->fetchAssoc($result))
3171 array_push($result_array,
$row);
3173 return $result_array;
3177 return $result_array;
3194 $active_id = $ilDB->nextId(
'svy_finished');
3195 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_finished (finished_id, survey_fi, user_fi, anonymous_id, state, tstamp) ".
3196 "VALUES (%s, %s, %s, %s, %s, %s)",
3197 array(
'integer',
'integer',
'integer',
'text',
'text',
'integer'),
3198 array($active_id, $this->
getSurveyId(), $user_id, $anonymous_id, 1, time())
3202 foreach ($pages as $key => $question_array)
3204 foreach ($question_array as $question)
3207 require_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
3209 $question->saveRandomData($active_id);
3225 if ($this->
getAnonymize() && (strlen($anonymous_id) == 0))
return;
3227 if (strcmp($user_id,
"") == 0)
3229 if ($user_id == ANONYMOUS_USER_ID)
3234 $next_id = $ilDB->nextId(
'svy_finished');
3235 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_finished (finished_id, survey_fi, user_fi, anonymous_id, state, tstamp) ".
3236 "VALUES (%s, %s, %s, %s, %s, %s)",
3237 array(
'integer',
'integer',
'integer',
'text',
'text',
'integer'),
3238 array($next_id, $this->
getSurveyId(), $user_id, $anonymous_id, 0, time())
3255 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_finished SET state = %s, user_fi = %s, tstamp = %s ".
3256 "WHERE survey_fi = %s AND anonymous_id = %s",
3257 array(
'text',
'integer',
'integer',
'integer',
'text'),
3258 array(1, $user_id, time(), $this->
getSurveyId(), $anonymize_id)
3263 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_finished SET state = %s, tstamp = %s WHERE survey_fi = %s AND user_fi = %s",
3264 array(
'text',
'integer',
'integer',
'integer'),
3285 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_finished SET lastpage = %s WHERE finished_id = %s",
3286 array(
'integer',
'integer'),
3287 array(($page_id) ? $page_id : 0, $finished_id)
3293 include_once
"./Services/User/classes/class.ilObjUser.php";
3294 include_once
"./Services/Mail/classes/class.ilMail.php";
3295 $mail =
new ilMail(ANONYMOUS_USER_ID);
3296 $recipients = preg_split(
'/,/', $this->mailaddresses);
3297 foreach ($recipients as $recipient)
3301 foreach (
$data[0] as $key => $value)
3305 $messagetext = str_replace(
'[' . $key .
']',
'', $messagetext);
3309 $messagetext = str_replace(
'[' . $key .
']', $value, $messagetext);
3312 $active_id = $this->
getActiveID($user_id, $anonymize_id);
3313 $messagetext .= ((strlen($messagetext)) ?
"\n\n\n" :
'') . $this->lng->txt(
'results') .
"\n\n". $this->
getParticipantTextResults($active_id);
3314 if (($not_sent != 1) ||
$data[
'sent'] == 0)
3316 $res = $mail->sendMail(
3320 $this->lng->txt(
'finished_mail_subject') .
': ' . $this->
getTitle(),
3334 $questioncounter = 1;
3335 foreach (
$questions as $question_id => $question_data)
3337 $textresult .= $questioncounter++ .
". " . $question_data[
"title"] .
"\n";
3338 $found = $userResults[$question_id][$active_id];
3340 if (is_array($found))
3342 $text = implode(
"\n", $found);
3348 if (strlen($text) == 0) $text = $this->lng->txt(
"skipped");
3349 $text = str_replace(
"<br />",
"\n", $text);
3350 $textresult .= $text .
"\n\n";
3362 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
3383 if (strlen($username) == 0)
3386 $userid = $ilUser->getId();
3389 $surveysetting =
new ilSetting(
"survey");
3390 $allowedUsers = strlen($surveysetting->get(
"multiple_survey_users")) ? explode(
",",$surveysetting->get(
"multiple_survey_users")) : array();
3391 if (in_array($userid, $allowedUsers))
3415 $result = $ilDB->queryF(
"SELECT * FROM svy_finished WHERE survey_fi = %s AND user_fi = %s",
3416 array(
'integer',
'integer'),
3422 $result = $ilDB->queryF(
"SELECT * FROM svy_finished WHERE survey_fi = %s AND anonymous_id = %s",
3423 array(
'integer',
'text'),
3430 $result = $ilDB->queryF(
"SELECT * FROM svy_finished WHERE survey_fi = %s AND user_fi = %s",
3431 array(
'integer',
'integer'),
3435 if ($result->numRows() == 0)
3441 $row = $ilDB->fetchAssoc($result);
3443 return (
int)
$row[
"state"];
3462 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE survey_fi = %s AND user_fi = %s",
3463 array(
'integer',
'integer'),
3469 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE survey_fi = %s AND anonymous_id = %s",
3470 array(
'integer',
'text'),
3477 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE survey_fi = %s AND user_fi = %s",
3478 array(
'integer',
'integer'),
3482 if ($result->numRows() == 0)
3488 $row = $ilDB->fetchAssoc($result);
3489 return $row[
"finished_id"];
3503 $result = $ilDB->queryF(
"SELECT lastpage FROM svy_finished WHERE finished_id = %s",
3507 if ($result->numRows() == 0)
3513 $row = $ilDB->fetchAssoc($result);
3514 return (
$row[
"lastpage"]) ?
$row[
"lastpage"] :
'';
3528 if (count($working_data) == 0)
3533 if ((count($working_data) == 1) and (strcmp($working_data[0][
"value"],
"") == 0))
3537 switch ($constraint_data[
"short"])
3541 foreach ($working_data as
$data)
3543 if (!($data[
"value"] < $constraint_data[
"value"]))
3552 foreach ($working_data as $data)
3554 if (!($data[
"value"] <= $constraint_data[
"value"]))
3563 foreach ($working_data as $data)
3565 if ($data[
"value"] == $constraint_data[
"value"])
3570 if ($found)
return 1;
3574 foreach ($working_data as $data)
3576 if (!($data[
"value"] <> $constraint_data[
"value"]))
3585 foreach ($working_data as $data)
3587 if (!($data[
"value"] >= $constraint_data[
"value"]))
3596 foreach ($working_data as $data)
3598 if (!($data[
"value"] > $constraint_data[
"value"]))
3613 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE survey_fi = %s",
3617 return ($result->numRows()) ?
true :
false;
3631 $result = $ilDB->queryF(
"SELECT * FROM svy_finished WHERE survey_fi = %s",
3635 if ($result->numRows())
3637 while (
$row = $ilDB->fetchAssoc($result))
3639 array_push($users,
$row[
"finished_id"]);
3656 $result = $ilDB->queryF(
"SELECT * FROM svy_finished WHERE survey_fi = %s",
3660 if ($result->numRows())
3662 while (
$row = $ilDB->fetchAssoc($result))
3664 array_push($users,
$row);
3667 $evaluation = array();
3669 foreach (
$questions as $question_id => $question_data)
3671 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
3674 $question =
new $question_type();
3675 $question->loadFromDb($question_id);
3677 $evaluation[$question_id] =
$data;
3693 $surveySetting =
new ilSetting(
"survey");
3694 $use_anonymous_id = array_key_exists(
"use_anonymous_id",
$_GET) ?
$_GET[
"use_anonymous_id"] : $surveySetting->get(
"use_anonymous_id");
3695 $result = $ilDB->queryF(
"SELECT * FROM svy_finished WHERE finished_id = %s",
3700 $foundrows = $result->numRows();
3703 $row = $ilDB->fetchAssoc($result);
3705 $name = ($use_anonymous_id) ?
$row[
"anonymous_id"] : $this->lng->txt(
"anonymous");
3707 "fullname" =>
$name,
3708 "sortname" =>
$name,
3713 "active_id" =>
"$active_id"
3717 if ((
$row[
"user_fi"] > 0) && (
$row[
"user_fi"] != ANONYMOUS_USER_ID) && ($this->
getAnonymize() == 0))
3719 include_once
'./Services/User/classes/class.ilObjUser.php';
3722 $userdata[
"fullname"] = $this->lng->txt(
"deleted_user");
3727 $userdata[
"fullname"] = $user->getFullname();
3728 $gender = $user->getGender();
3729 if (strlen($gender) == 1) $gender = $this->lng->txt(
"gender_$gender");
3730 $userdata[
"gender"] = $gender;
3731 $userdata[
"firstname"] = $user->getFirstname();
3732 $userdata[
"lastname"] = $user->getLastname();
3733 $userdata[
"sortname"] = $user->getLastname() .
", " . $user->getFirstname();
3734 $userdata[
"login"] = $user->getLogin();
3745 $query = sprintf(
"SELECT * FROM svy_finished WHERE finished_id = %s",
3746 $ilDB->quote($active_id)
3748 $result = $ilDB->query(
$query);
3757 "active_id" =>
"$active_id"
3759 if ($result->numRows())
3762 if (
$row[
"user_fi"] > 0)
3764 include_once
'./Services/User/classes/class.ilObjUser.php';
3767 $userdata[
"fullname"] = $this->lng->txt(
"deleted_user");
3772 $userdata[
"fullname"] = $user->getFullname();
3773 $userdata[
"login"] = $user->getLogin();
3774 $gender = $user->getGender();
3775 if (strlen($gender) == 1) $gender = $this->lng->txt(
"gender_$gender");
3776 $userdata[
"gender"] = $gender;
3777 $userdata[
"firstname"] = $user->getFirstname();
3778 $userdata[
"lastname"] = $user->getLastname();
3779 $userdata[
"sortname"] = $user->getLastname() .
", " . $user->getFirstname();
3780 $userdata[
"email"] = $user->getEmail();
3803 $result = $ilDB->queryF(
"SELECT * FROM svy_answer WHERE active_fi = %s",
3807 while (
$row = $ilDB->fetchAssoc($result))
3809 if (!is_array($answers[
$row[
"question_fi"]]))
3811 $answers[$row[
"question_fi"]] = array();
3813 array_push($answers[$row[
"question_fi"]], $row);
3817 "name" => $userdata[
"fullname"],
3818 "gender" => $userdata[
"gender"],
3819 "answers" => array()
3823 if (array_key_exists($key, $answers))
3825 $resultset[
"answers"][$key] = $answers[$key];
3829 $resultset[
"answers"][$key] = array();
3831 sort($resultset[
"answers"][$key]);
3848 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE survey_fi = %s",
3852 $nr_of_users = $result->numRows();
3854 $result_array =& $question->getCumulatedResults($this->
getSurveyId(), $nr_of_users);
3855 return $result_array;
3869 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE survey_fi = %s",
3873 return $result->numRows();
3878 $result_array = array();
3879 $result =
$ilDB->query(
"SELECT svy_question.*, svy_qtype.type_tag FROM svy_question, svy_qtype WHERE ".
3880 "svy_question.questiontype_fi = svy_qtype.questiontype_id AND svy_question.tstamp > 0 AND ".
3881 $ilDB->in(
'svy_question.question_id', $question_ids,
false,
'integer'));
3882 while (
$row =
$ilDB->fetchAssoc($result))
3884 array_push($result_array,
$row);
3886 return $result_array;
3899 if (is_array($arrFilter))
3901 if (array_key_exists(
'title', $arrFilter) && strlen($arrFilter[
'title']))
3903 $where .=
" AND " . $ilDB->like(
'svy_question.title',
'text',
"%%" . $arrFilter[
'title'] .
"%%");
3905 if (array_key_exists(
'description', $arrFilter) && strlen($arrFilter[
'description']))
3907 $where .=
" AND " . $ilDB->like(
'svy_question.description',
'text',
"%%" . $arrFilter[
'description'] .
"%%");
3909 if (array_key_exists(
'author', $arrFilter) && strlen($arrFilter[
'author']))
3911 $where .=
" AND " . $ilDB->like(
'svy_question.author',
'text',
"%%" . $arrFilter[
'author'] .
"%%");
3913 if (array_key_exists(
'type', $arrFilter) && strlen($arrFilter[
'type']))
3915 $where .=
" AND svy_qtype.type_tag = " . $ilDB->quote($arrFilter[
'type'],
'text');
3917 if (array_key_exists(
'spl', $arrFilter) && strlen($arrFilter[
'spl']))
3919 $where .=
" AND svy_question.obj_fi = " . $ilDB->quote($arrFilter[
'spl'],
'integer');
3925 $forbidden =
" AND " . $ilDB->in(
'svy_question.obj_fi', array_keys($spls),
false,
'integer');
3926 $forbidden .=
" AND svy_question.complete = " . $ilDB->quote(
"1",
'text');
3929 if (count($existing_questions))
3931 $existing =
" AND " . $ilDB->in(
'svy_question.question_id', $existing_questions,
true,
'integer');
3934 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
3937 $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);
3940 if ($query_result->numRows())
3942 while (
$row = $ilDB->fetchAssoc($query_result))
3944 $row[
'ttype'] = $trans[
$row[
'type_tag']];
3949 array_push($rows, $row);
3954 array_push($rows, $row);
3971 if (is_array($arrFilter))
3973 if (array_key_exists(
'title', $arrFilter) && strlen($arrFilter[
'title']))
3975 $where .=
" AND " . $ilDB->like(
'svy_qblk.title',
'text',
"%%" . $arrFilter[
'title'] .
"%%");
3979 $query_result = $ilDB->query(
"SELECT svy_qblk.*, svy_svy.obj_fi FROM svy_qblk , svy_qblk_qst, svy_svy WHERE ".
3980 "svy_qblk.questionblock_id = svy_qblk_qst.questionblock_fi AND svy_svy.survey_id = svy_qblk_qst.survey_fi ".
3981 "$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");
3983 if ($query_result->numRows())
3986 $surveytitles = array();
3987 foreach ($surveys as
$data)
3989 $surveytitles[$data[
'id']] = $data[
'title'];
3991 while (
$row = $ilDB->fetchAssoc($query_result))
3995 foreach ($questions_array as $key => $value)
3997 $questions_array[$key] =
"$counter. $value";
4000 if (strlen($surveytitles[
$row[
"obj_fi"]]))
4002 $rows[$row[
"questionblock_id"]] = array(
4003 "questionblock_id" => $row[
"questionblock_id"],
4004 "title" => $row[
"title"],
4005 "svy" => $surveytitles[$row[
"obj_fi"]],
4006 "contains" => join($questions_array,
", "),
4007 "owner" => $row[
"owner_fi"]
4023 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
4028 "xmlns:xsi" =>
"http://www.w3.org/2001/XMLSchema-instance",
4029 "xsi:noNamespaceSchemaLocation" =>
"http://www.ilias.de/download/xsd/ilias_survey_3_8.xsd"
4031 $a_xml_writer->xmlStartTag(
"surveyobject", $attrs);
4036 $a_xml_writer->xmlStartTag(
"survey", $attrs);
4038 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
4039 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
4040 $a_xml_writer->xmlStartTag(
"objectives");
4042 "label" =>
"introduction"
4049 $a_xml_writer->xmlEndTag(
"objectives");
4053 $attribs = array(
"enabled" =>
"1");
4057 $attribs = array(
"enabled" =>
"0");
4059 $a_xml_writer->xmlElement(
"anonymisation", $attribs);
4060 $a_xml_writer->xmlStartTag(
"restrictions");
4063 $attribs = array(
"type" =>
"free");
4067 $attribs = array(
"type" =>
"restricted");
4069 $a_xml_writer->xmlElement(
"access", $attribs);
4072 $attrs = array(
"type" =>
"date");
4077 $attrs = array(
"type" =>
"date");
4080 $a_xml_writer->xmlEndTag(
"restrictions");
4084 $hasconstraints = FALSE;
4085 foreach ($pages as $question_array)
4087 foreach ($question_array as $question)
4089 if (count($question[
"constraints"]))
4091 $hasconstraints = TRUE;
4096 if ($hasconstraints)
4098 $a_xml_writer->xmlStartTag(
"constraints");
4099 foreach ($pages as $question_array)
4101 foreach ($question_array as $question)
4103 if (count($question[
"constraints"]))
4106 foreach ($question[
"constraints"] as $constraint)
4109 "sourceref" => $question[
"question_id"],
4110 "destref" => $constraint[
"question"],
4111 "relation" => $constraint[
"short"],
4112 "value" => $constraint[
"value"]
4114 $a_xml_writer->xmlElement(
"constraint", $attribs);
4119 $a_xml_writer->xmlEndTag(
"constraints");
4123 $a_xml_writer->xmlStartTag(
"metadata");
4125 $a_xml_writer->xmlStartTag(
"metadatafield");
4126 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"evaluation_access");
4128 $a_xml_writer->xmlEndTag(
"metadatafield");
4130 $a_xml_writer->xmlStartTag(
"metadatafield");
4131 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"status");
4132 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->
getStatus());
4133 $a_xml_writer->xmlEndTag(
"metadatafield");
4135 $a_xml_writer->xmlStartTag(
"metadatafield");
4136 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"display_question_titles");
4138 $a_xml_writer->xmlEndTag(
"metadatafield");
4140 $a_xml_writer->xmlStartTag(
"metadatafield");
4141 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"SCORM");
4142 include_once
"./Services/MetaData/classes/class.ilMD.php";
4145 $md->toXml($writer);
4146 $metadata = $writer->xmlDumpMem();
4147 $a_xml_writer->xmlElement(
"fieldentry", NULL, $metadata);
4148 $a_xml_writer->xmlEndTag(
"metadatafield");
4150 $a_xml_writer->xmlEndTag(
"metadata");
4151 $a_xml_writer->xmlEndTag(
"survey");
4153 $attribs = array(
"id" => $this->
getId());
4154 $a_xml_writer->xmlStartTag(
"surveyquestions", $attribs);
4157 foreach ($pages as $question_array)
4159 if (count($question_array) > 1)
4161 $attribs = array(
"id" => $question_array[0][
"question_id"]);
4162 $attribs = array(
"showQuestiontext" => $question_array[0][
"questionblock_show_questiontext"]);
4163 $a_xml_writer->xmlStartTag(
"questionblock", $attribs);
4164 if (strlen($question_array[0][
"questionblock_title"]))
4166 $a_xml_writer->xmlElement(
"questionblocktitle", NULL, $question_array[0][
"questionblock_title"]);
4169 foreach ($question_array as $question)
4171 if (strlen($question[
"heading"]))
4173 $a_xml_writer->xmlElement(
"textblock", NULL, $question[
"heading"]);
4176 if ($questionObject !== FALSE) $questionObject->insertXML($a_xml_writer, FALSE, $obligatory_states[$question[
"question_id"]]);
4178 if (count($question_array) > 1)
4180 $a_xml_writer->xmlEndTag(
"questionblock");
4184 $a_xml_writer->xmlEndTag(
"surveyquestions");
4185 $a_xml_writer->xmlEndTag(
"surveyobject");
4186 $xml = $a_xml_writer->xmlDumpMem(FALSE);
4199 if ($question_id < 1)
return FALSE;
4200 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
4202 if (strlen($question_type) == 0)
return FALSE;
4204 $question =
new $question_type();
4205 $question->loadFromDb($question_id);
4217 if (!is_dir($a_dir) || is_int(strpos($a_dir,
"..")))
4221 $importDirectory =
"";
4224 $current_dir = opendir($a_dir);
4226 while($entryname = readdir($current_dir))
4233 if(is_dir($a_dir.
"/".$file) and ($file !=
"." and $file!=
".."))
4236 $importDirectory = $a_dir.
"/".
$file;
4239 closedir($current_dir);
4240 if (strlen($importDirectory))
4243 $current_dir = opendir($importDirectory);
4245 while($entryname = readdir($current_dir))
4251 if(@is_file($importDirectory.
"/".$file) && ($file !=
"." && $file!=
"..") && (strcmp(strtolower(substr($file, -4, 4)),
".xml") == 0))
4254 $xmlFile = $importDirectory.
"/".
$file;
4258 return array(
"dir" => $importDirectory,
"xml" => $xmlFile);
4270 $source = $file_info[
"tmp_name"];
4272 if (($source ==
'none') || (!$source) || $file_info[
"error"] > UPLOAD_ERR_OK)
4274 $error = $this->lng->txt(
"import_no_file_selected");
4279 if ((strcmp($file_info[
"type"],
"text/xml") == 0) || (strcmp($file_info[
"type"],
"application/xml") == 0))
4283 if (strpos($file_info[
"type"],
"zip") !== FALSE)
4287 if (!$isXml && !$isZip)
4289 $error = $this->lng->txt(
"import_wrong_file_type");
4291 $ilLog->write(
"Survey: Import error. Filetype was \"" . $file_info[
"type"] .
"\"");
4297 $import_subdir =
"";
4299 include_once
"./Services/Utilities/classes/class.ilUtil.php";
4302 $importfile = $import_dir.
"/".$file_info[
"name"];
4306 if (!((strlen($found[
"dir"]) > 0) && (strlen($found[
"xml"]) > 0)))
4308 $error = $this->lng->txt(
"wrong_import_file_structure");
4311 $importfile = $found[
"xml"];
4312 $import_subdir = $found[
"dir"];
4316 $importfile = tempnam($import_dir,
"survey_import");
4319 $fh = fopen($importfile,
"r");
4322 $error = $this->lng->txt(
"import_error_opening_file");
4325 $xml = fread($fh, filesize($importfile));
4326 $result = fclose($fh);
4329 $error = $this->lng->txt(
"import_error_closing_file");
4334 if (strpos($xml,
"questestinterop"))
4336 include_once
"./Services/Survey/classes/class.SurveyImportParserPre38.php";
4337 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
4340 $import->setSurveyObject($this);
4341 $import->setXMLContent($xml);
4342 $import->startParsing();
4346 include_once
"./Services/Survey/classes/class.SurveyImportParser.php";
4347 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
4350 $import->setSurveyObject($this);
4351 $import->setXMLContent($xml);
4352 $import->startParsing();
4355 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
4357 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
4358 include_once
"./Services/RTE/classes/class.ilRTE.php";
4359 include_once
"./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
4360 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
4362 $importfile = $import_subdir .
"/" . $mob[
"uri"];
4363 if (file_exists($importfile))
4367 $this->
setIntroduction(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $this->
getIntroduction()));
4368 $this->
setOutro(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $this->
getOutro()));
4373 $ilLog->write(
"Error: Could not open XHTML mob file for test introduction during test import. File $importfile does not exist!");
4408 $newObj->setOutro($this->
getOutro());
4421 $question_pointer = array();
4424 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
4425 foreach ($this->questions as $key => $question_id)
4430 $question->saveToDb($original_id);
4431 $newObj->questions[$key] = $question->getId();
4432 $question_pointer[$question_id] = $question->getId();
4433 $mapping[$question_id] = $question->getId();
4436 $newObj->saveToDb();
4437 $newObj->cloneTextblocks($mapping);
4440 $questionblocks = array();
4441 $questionblock_questions = array();
4442 $result = $ilDB->queryF(
"SELECT * FROM svy_qblk_qst WHERE survey_fi = %s",
4446 if ($result->numRows() > 0)
4448 while (
$row = $ilDB->fetchAssoc($result))
4450 array_push($questionblock_questions,
$row);
4451 $questionblocks[
$row[
"questionblock_fi"]] = $row[
"questionblock_fi"];
4455 foreach ($questionblocks as $key => $value)
4459 $questionblocks[$key] = $questionblock_id;
4462 foreach ($questionblock_questions as $key => $value)
4464 $next_id = $ilDB->nextId(
'svy_qblk_qst');
4465 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_qblk_qst (qblk_qst_id, survey_fi, questionblock_fi, question_fi) ".
4466 "VALUES (%s, %s, %s, %s)",
4467 array(
'integer',
'integer',
'integer',
'integer'),
4468 array($next_id, $newObj->getSurveyId(), $questionblocks[$value[
"questionblock_fi"]], $question_pointer[$value[
"question_fi"]])
4474 $newConstraints = array();
4475 foreach ($constraints as $key => $constraint)
4477 if (!array_key_exists($constraint[
'id'], $newConstraints))
4479 $constraint_id = $newObj->addConstraint($question_pointer[$constraint[
"question"]], $constraint[
"relation_id"], $constraint[
"value"], $constraint[
'conjunction']);
4480 $newConstraints[$constraint[
'id']] = $constraint_id;
4482 $newObj->addConstraintToQuestion($question_pointer[$constraint[
"for_question"]], $newConstraints[$constraint[
'id']]);
4486 $result = $ilDB->queryF(
"SELECT * FROM svy_qst_oblig WHERE survey_fi = %s",
4490 if ($result->numRows() > 0)
4492 while (
$row = $ilDB->fetchAssoc($result))
4494 $next_id = $ilDB->nextId(
'svy_qst_oblig');
4495 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_qst_oblig (question_obligatory_id, survey_fi, question_fi, ".
4496 "obligatory, tstamp) VALUES (%s, %s, %s, %s, %s)",
4497 array(
'integer',
'integer',
'integer',
'text',
'integer'),
4498 array($next_id, $newObj->getSurveyId(), $question_pointer[
$row[
"question_fi"]], $row[
"obligatory"], time())
4508 $result = $ilDB->queryF(
"SELECT * FROM svy_svy_qst WHERE question_fi = %s",
4512 if ($result->numRows())
4514 $row = $ilDB->fetchAssoc($result);
4515 return $row[
"heading"];
4530 foreach ($mapping as $original_id => $new_id)
4533 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
4545 include_once
"./Services/Utilities/classes/class.ilUtil.php";
4548 if(!is_writable($svy_data_dir))
4550 $this->ilias->raiseError(
"Survey Data Directory (".$svy_data_dir
4551 .
") not writeable.",$this->ilias->error_obj->FATAL);
4555 $svy_dir = $svy_data_dir.
"/svy_".$this->
getId();
4557 if(!@is_dir($svy_dir))
4559 $this->ilias->raiseError(
"Creation of Survey Directory failed.",$this->ilias->error_obj->FATAL);
4562 $export_dir = $svy_dir.
"/export";
4564 if(!@is_dir($export_dir))
4566 $this->ilias->raiseError(
"Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
4575 include_once
"./Services/Utilities/classes/class.ilUtil.php";
4587 if (!@is_dir(
$dir) or
4588 !is_writeable(
$dir))
4600 while ($entry =
$dir->read())
4602 if ($entry !=
"." and
4604 ereg(
"^[0-9]{10}_{2}[0-9]+_{2}(survey__)*[0-9]+\.xml|zip\$", $entry))
4626 include_once
"./Services/Utilities/classes/class.ilUtil.php";
4630 if(!is_writable($svy_data_dir))
4632 $this->ilias->raiseError(
"Survey Data Directory (".$svy_data_dir
4633 .
") not writeable.",$this->ilias->error_obj->FATAL);
4637 $svy_dir = $svy_data_dir.
"/svy_".$this->
getId();
4639 if(!@is_dir($svy_dir))
4641 $this->ilias->raiseError(
"Creation of Survey Directory failed.",$this->ilias->error_obj->FATAL);
4645 $import_dir = $svy_dir.
"/import";
4647 if(!@is_dir($import_dir))
4649 $this->ilias->raiseError(
"Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
4658 include_once
"./Services/Utilities/classes/class.ilUtil.php";
4660 "/svy_".$this->getId().
"/import";
4661 if (!is_dir($import_dir))
4665 if(@is_dir($import_dir))
4680 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_svy_qst SET heading=%s WHERE survey_fi=%s AND question_fi=%s",
4681 array(
'text',
'integer',
'integer'),
4682 array($heading, $this->
getSurveyId(), $insertbefore)
4687 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_svy_qst SET heading=%s WHERE survey_fi=%s AND question_fi=%s",
4688 array(
'text',
'integer',
'integer'),
4698 $result = $ilDB->queryF(
"SELECT anonymous_id FROM svy_anonymous WHERE survey_key = %s AND survey_fi = %s",
4699 array(
'text',
'integer'),
4702 return ($result->numRows() == 1) ?
true :
false;
4710 $result = $ilDB->queryF(
"SELECT anonymous_id FROM svy_finished WHERE survey_fi = %s AND user_fi = %s",
4711 array(
'integer',
'integer'),
4714 if ($result->numRows() == 1)
4716 $row = $ilDB->fetchAssoc($result);
4717 return $row[
"anonymous_id"];
4729 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE anonymous_id = %s AND survey_fi = %s",
4730 array(
'text',
'integer'),
4733 return ($result->numRows() == 1) ?
true :
false;
4765 $result = $ilDB->queryF(
"SELECT anonymous_id FROM svy_anonymous WHERE survey_fi = %s AND user_key IS NULL",
4769 return $result->numRows();
4781 global
$ilDB, $ilUser;
4783 $result = $ilDB->queryF(
"SELECT svy_anonymous.*, svy_finished.state FROM svy_anonymous ".
4784 "LEFT JOIN svy_finished ON svy_anonymous.survey_key = svy_finished.anonymous_id ".
4785 "WHERE svy_anonymous.survey_fi = %s AND svy_anonymous.user_key IS NULL",
4790 $default_lang = $ilUser->getPref(
"survey_code_language");
4791 $lang = (strlen($default_lang)) ?
"&lang=" . $default_lang :
"";
4792 while (
$row = $ilDB->fetchAssoc($result))
4794 if (in_array(
$row[
"survey_key"], $a_array) || (count($a_array) == 0))
4796 $export .=
$row[
"survey_key"] .
",";
4801 $export .=
"$created,";
4810 $url = ILIAS_HTTP_PATH.
"/goto.php?cmd=infoScreen&target=svy_".$this->
getRefId() .
"&client_id=" . CLIENT_ID .
"&accesscode=".$row[
"survey_key"].$lang;
4811 $export .= $url .
"\n";
4828 include_once
"./classes/class.ilFormat.php";
4831 $order =
"ORDER BY tstamp, survey_key ASC";
4833 $result = $ilDB->queryF(
"SELECT svy_anonymous.anonymous_id, svy_anonymous.survey_key, svy_anonymous.survey_fi, ".
4834 "svy_anonymous.tstamp, svy_finished.state FROM svy_anonymous LEFT JOIN svy_finished ".
4835 "ON svy_anonymous.survey_key = svy_finished.anonymous_id WHERE svy_anonymous.survey_fi = %s ".
4836 "AND svy_anonymous.user_key IS NULL $order",
4840 if ($result->numRows() > 0)
4842 while (
$row = $ilDB->fetchAssoc($result))
4857 $addlang =
"&lang=$lang";
4859 $href = ILIAS_HTTP_PATH.
"/goto.php?cmd=infoScreen&target=svy_".$this->
getRefId() .
"&client_id=" . CLIENT_ID .
"&accesscode=".$row[
"survey_key"].$addlang;
4860 $url = $this->lng->txt(
"survey_code_url_name");
4862 array_push($codes, array(
'code' =>
$row[
"survey_key"],
'date' => $created,
'used' => $state,
'url' => $url,
'href' => $href));
4871 $result = $ilDB->queryF(
"SELECT finished_id FROM svy_finished WHERE survey_fi = %s AND anonymous_id = %s",
4872 array(
'integer',
'text'),
4875 return ($result->numRows() > 0) ?
true :
false;
4881 $result = $ilDB->queryF(
"SELECT anonymous_id FROM svy_anonymous WHERE survey_fi = %s AND survey_key = %s",
4882 array(
'integer',
'text'),
4885 return ($result->numRows() > 0) ?
false :
true;
4891 for ($i = 0; $i < $nrOfCodes; $i++)
4894 $next_id = $ilDB->nextId(
'svy_anonymous');
4895 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_anonymous (anonymous_id, survey_key, survey_fi, tstamp) ".
4896 "VALUES (%s, %s, %s, %s)",
4897 array(
'integer',
'text',
'integer',
'integer'),
4898 array($next_id, $anonymize_key, $this->
getSurveyId(), time())
4906 foreach (
$data as $dataset)
4909 $next_id = $ilDB->nextId(
'svy_anonymous');
4910 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_anonymous (anonymous_id, survey_key, survey_fi, externaldata, tstamp) ".
4911 "VALUES (%s, %s, %s, %s, %s)",
4912 array(
'integer',
'text',
'integer',
'text',
'integer'),
4913 array($next_id, $anonymize_key, $this->
getSurveyId(), serialize($dataset), time())
4920 include_once
"./Services/Mail/classes/class.ilMail.php";
4922 $mail =
new ilMail($user_id);
4924 foreach ($recipients as
$data)
4926 $messagetext = $message;
4927 $url = ILIAS_HTTP_PATH.
"/goto.php?cmd=infoScreen&target=svy_".$this->
getRefId() .
"&client_id=" . CLIENT_ID .
"&accesscode=".$data[
"code"];
4928 $messagetext = str_replace(
'[url]',
"<" . $url .
">", $messagetext);
4929 foreach ($data as $key => $value)
4931 $messagetext = str_replace(
'[' . $key .
']', $value, $messagetext);
4933 if (($not_sent != 1) || $data[
'sent'] == 0)
4935 $res = $mail->sendMail(
4948 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_anonymous SET sent = %s WHERE survey_fi = %s AND externaldata IS NOT NULL",
4949 array(
'integer',
'integer'),
4957 $result = $ilDB->queryF(
"SELECT survey_key code, externaldata, sent FROM svy_anonymous WHERE survey_fi = %s AND externaldata IS NOT NULL",
4962 while (
$row = $ilDB->fetchAssoc($result))
4964 $externaldata = unserialize(
$row[
'externaldata']);
4965 $externaldata[
'code'] =
$row[
'code'];
4966 $externaldata[
'sent'] =
$row[
'sent'];
4967 array_push(
$res, $externaldata);
4981 if (strlen($survey_code) > 0)
4983 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_anonymous WHERE survey_fi = %s AND survey_key = %s",
4984 array(
'integer',
'text'),
5000 $result = $ilDB->queryF(
"SELECT survey_key FROM svy_anonymous WHERE survey_fi = %s AND user_key = %s",
5001 array(
'integer',
'text'),
5004 if ($result->numRows())
5006 $row = $ilDB->fetchAssoc($result);
5007 $access_code =
$row[
"survey_key"];
5009 return $access_code;
5021 $next_id = $ilDB->nextId(
'svy_anonymous');
5022 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_anonymous (anonymous_id, survey_key, survey_fi, user_key, tstamp) ".
5023 "VALUES (%s, %s, %s, %s, %s)",
5024 array(
'integer',
'text',
'integer',
'text',
'integer'),
5025 array($next_id, $access_code, $this->
getSurveyId(), md5($user_id), time())
5037 $codestring =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
5040 for ($i = 1; $i <=5; $i++)
5042 $index = mt_rand(0, strlen($codestring)-1);
5043 $code .= substr($codestring, $index, 1);
5066 $resultarray = array();
5067 foreach (
$row as $rowindex => $entry)
5069 if(is_array($entry))
5071 $entry = implode(
"/", $entry);
5078 if (strpos($entry,
"\"") !== FALSE)
5080 $entry = str_replace(
"\"",
"\"\"", $entry);
5088 $entry = str_replace(chr(13).chr(10), chr(10), $entry);
5091 $resultarray[$rowindex] = utf8_decode(
"\"" . $entry .
"\"");
5095 $resultarray[$rowindex] = utf8_decode($entry);
5098 return $resultarray;
5105 $result = $ilDB->queryF(
"SELECT tstamp FROM svy_answer WHERE active_fi = %s ORDER BY tstamp DESC",
5109 if ($result->numRows())
5111 $row = $ilDB->fetchAssoc($result);
5112 return $row[
"tstamp"];
5116 $result = $ilDB->queryF(
"SELECT tstamp FROM svy_finished WHERE finished_id = %s",
5120 if ($result->numRows())
5122 $row = $ilDB->fetchAssoc($result);
5123 return $row[
"tstamp"];
5137 include_once
"./Services/Utilities/classes/class.ilUtil.php";
5150 if (preg_match(
"/<[^>]*?>/", $a_text))
5168 function addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag = TRUE, $add_mobs = TRUE, $attribs = NULL)
5170 include_once
"./Services/RTE/classes/class.ilRTE.php";
5171 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
5173 $a_xml_writer->xmlStartTag(
"material", $attribs);
5175 "type" =>
"text/plain"
5177 if ($this->
isHTML($a_material))
5179 $attrs[
"type"] =
"text/xhtml";
5182 $a_xml_writer->xmlElement(
"mattext", $attrs, $mattext);
5187 foreach (
$mobs as $mob)
5189 $mob_id =
"il_" . IL_INST_ID .
"_mob_" . $mob;
5190 if (strpos($mattext, $mob_id) !== FALSE)
5195 "uri" =>
"objects/" .
"il_" . IL_INST_ID .
"_mob_" . $mob .
"/" . $mob_obj->getTitle()
5197 $a_xml_writer->xmlElement(
"matimage", $imgattrs, NULL);
5201 if ($close_material_tag) $a_xml_writer->xmlEndTag(
"material");
5216 if ($this->surveyCodeSecurity == FALSE)
5228 $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
5234 include_once(
"./Modules/Survey/classes/class.ilObjSurveyAccess.php");
5259 global $ilPluginAdmin;
5260 if ($ilPluginAdmin->isActive(
IL_COMP_MODULE,
"SurveyQuestionPool",
"svyq", $a_pname))
5290 if (!is_array($ids) || count($ids) ==0)
return array();
5292 $result = $ilDB->query(
"SELECT usr_id, login, lastname, firstname FROM usr_data WHERE " . $ilDB->in(
'usr_id', $ids,
false,
'integer') .
" ORDER BY login");
5293 $result_array = array();
5294 while (
$row = $ilDB->fetchAssoc($result))
5296 $result_array[
$row[
"usr_id"]]=
$row;
5298 return $result_array;
5303 if (!is_array($ids) || count($ids) ==0)
return array();
5315 if (!is_array($ids) || count($ids) ==0)
return array();
5317 foreach ($ids as $obj_id)
5331 $this->mailnotification = ($a_notification) ?
true :
false;
5341 $this->mailaddresses = $a_addresses;
5351 $this->mailparticipantdata = $a_data;
5358 $result = $ilDB->queryF(
"SELECT * FROM svy_times, svy_finished WHERE svy_finished.survey_fi = %s",
5360 array($this->
getId())
5363 while (
$row = $ilDB->fetchAssoc($result))
5365 if (strlen(
$row[
'left_page']) && strlen(
$row[
'entered_page']))
5366 $times[
$row[
'finished_fi']] += (
$row[
'left_page']-
$row[
'entered_page']);
5376 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_times (finished_fi, entered_page, left_page, first_question) VALUES (%s, %s, %s, %s)",
5377 array(
'integer',
'integer',
'integer',
'integer'),
5378 array($finished_id, $time, NULL, $first_question)
5386 $affectedRows = $ilDB->manipulateF(
"UPDATE svy_times SET left_page = %s WHERE finished_fi = %s AND entered_page = %s",
5387 array(
'integer',
'integer',
'integer'),
5388 array($time, $finished_id,
$_SESSION[
'svy_entered_page'])
5397 $result = $ilDB->queryF(
"SELECT * FROM svy_times WHERE finished_fi = %s",
5402 while (
$row = $ilDB->fetchAssoc($result))
5404 if (
$row[
'left_page'] > 0 &&
$row[
'entered_page'] > 0)