ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSurvey.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 include_once "./classes/class.ilObject.php";
35 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
36 
37 class ilObjSurvey extends ilObject
38 {
48 
57  var $author;
58 
67 
75  var $outro;
76 
84  var $status;
85 
94 
103 
112 
121 
130 
139 
148 
157 
165 
173 
180 
187  function ilObjSurvey($a_id = 0,$a_call_by_reference = true)
188  {
189  global $ilUser;
190  $this->type = "svy";
191  $this->ilObject($a_id,$a_call_by_reference);
192 
193  $this->survey_id = -1;
194  $this->introduction = "";
195  $this->outro = $this->lng->txt("survey_finished");
196  $this->author = $ilUser->fullname;
197  $this->status = STATUS_OFFLINE;
198  $this->evaluation_access = EVALUATION_ACCESS_OFF;
199  $this->startdate_enabled = 0;
200  $this->enddate_enabled = 0;
201  $this->questions = array();
202  $this->invitation = INVITATION_OFF;
203  $this->invitation_mode = MODE_PREDEFINED_USERS;
204  $this->anonymize = ANONYMIZE_OFF;
205  $this->display_question_titles = QUESTIONTITLES_VISIBLE;
206  $this->surveyCodeSecurity = TRUE;
207  }
208 
212  function create($a_upload = false)
213  {
214  parent::create();
215  if(!$a_upload)
216  {
217  $this->createMetaData();
218  }
219  }
220 
228  function createMetaData()
229  {
231  $this->saveAuthorToMetadata();
232  }
233 
240  function update()
241  {
242  $this->updateMetaData();
243 
244  if (!parent::update())
245  {
246  return false;
247  }
248 
249  // put here object specific stuff
250 
251  return true;
252  }
253 
254  function createReference()
255  {
257  $this->saveToDb();
258  return $result;
259  }
260 
266  function read($a_force_db = false)
267  {
268  parent::read($a_force_db);
269  $this->loadFromDb();
270  }
271 
278  function addQuestion($question_id)
279  {
280  array_push($this->questions, $question_id);
281  }
282 
283 
290  function delete()
291  {
292  $remove = parent::delete();
293  // always call parent delete function first!!
294  if (!$remove)
295  {
296  return false;
297  }
298 
299  $this->deleteMetaData();
300 
301  // Delete all survey questions, constraints and materials
302  foreach ($this->questions as $question_id)
303  {
304  $this->removeQuestion($question_id);
305  }
306  $this->deleteSurveyRecord();
307 
309  return true;
310  }
311 
320  {
321  global $ilDB;
322 
323  $query = sprintf("DELETE FROM survey_survey WHERE survey_id = %s",
324  $ilDB->quote($this->getSurveyId())
325  );
326  $result = $ilDB->query($query);
327 
328  $query = sprintf("SELECT questionblock_fi FROM survey_questionblock_question WHERE survey_fi = %s",
329  $ilDB->quote($this->getSurveyId())
330  );
331  $result = $ilDB->query($query);
332  $questionblocks = array();
333  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
334  {
335  array_push($questionblocks, $row["questionblock_fi"]);
336  }
337  if (count($questionblocks))
338  {
339  $query = "DELETE FROM survey_questionblock WHERE questionblock_id IN ('" . join($questionblocks, "','") . "')";
340  $result = $ilDB->query($query);
341  }
342  $query = sprintf("DELETE FROM survey_questionblock_question WHERE survey_fi = %s",
343  $ilDB->quote($this->getSurveyId())
344  );
345  $result = $ilDB->query($query);
346 
347  $this->deleteAllUserData();
348 
349  $query = sprintf("DELETE FROM survey_anonymous WHERE survey_fi = %s",
350  $ilDB->quote($this->getSurveyId())
351  );
352  $result = $ilDB->query($query);
353 
354  // delete export files
355  include_once "./Services/Utilities/classes/class.ilUtil.php";
356  $svy_data_dir = ilUtil::getDataDir()."/svy_data";
357  $directory = $svy_data_dir."/svy_".$this->getId();
358  if (is_dir($directory))
359  {
360  include_once "./Services/Utilities/classes/class.ilUtil.php";
361  ilUtil::delDir($directory);
362  }
363 
364  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
365  $mobs = ilObjMediaObject::_getMobsOfObject("svy:html", $this->getId());
366  // remaining usages are not in text anymore -> delete them
367  // and media objects (note: delete method of ilObjMediaObject
368  // checks whether object is used in another context; if yes,
369  // the object is not deleted!)
370  foreach($mobs as $mob)
371  {
372  ilObjMediaObject::_removeUsage($mob, "svy:html", $this->getId());
373  $mob_obj =& new ilObjMediaObject($mob);
374  $mob_obj->delete();
375  }
376  }
377 
385  function deleteAllUserData()
386  {
387  global $ilDB;
388 
389  $query = sprintf("SELECT finished_id FROM survey_finished WHERE survey_fi = %s",
390  $ilDB->quote($this->getSurveyId())
391  );
392  $result = $ilDB->query($query);
393  $active_array = array();
394  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
395  {
396  array_push($active_array, $row["finished_id"]);
397  }
398 
399  $query = sprintf("DELETE FROM survey_finished WHERE survey_fi = %s",
400  $ilDB->quote($this->getSurveyId())
401  );
402  $result = $ilDB->query($query);
403 
404  foreach ($active_array as $active_fi)
405  {
406  $query = sprintf("DELETE FROM survey_answer WHERE active_fi = %s",
407  $ilDB->quote($active_fi)
408  );
409  $result = $ilDB->query($query);
410  }
411  }
412 
420  function removeSelectedSurveyResults($finished_ids)
421  {
422  global $ilDB;
423 
424  foreach ($finished_ids as $finished_id)
425  {
426  $query = sprintf("SELECT finished_id FROM survey_finished WHERE finished_id = %s",
427  $ilDB->quote($finished_id . "")
428  );
429  $result = $ilDB->query($query);
430  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
431 
432  $query = sprintf("DELETE FROM survey_answer WHERE active_fi = %s",
433  $ilDB->quote($row["finished_id"] . "")
434  );
435  $result = $ilDB->query($query);
436 
437  $query = sprintf("DELETE FROM survey_finished WHERE finished_id = %s",
438  $ilDB->quote($finished_id . "")
439  );
440  $result = $ilDB->query($query);
441  }
442  }
443 
445  {
446  global $ilDB;
447 
448  $query = sprintf("SELECT * FROM survey_finished WHERE survey_fi = %s",
449  $ilDB->quote($this->getSurveyId() . "")
450  );
451  $result = $ilDB->query($query);
452  $participants = array();
453  if ($result->numRows() > 0)
454  {
455  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
456  {
457  $userdata = $this->getUserDataFromActiveId($row["finished_id"]);
458  $participants[$userdata["sortname"] . $userdata["active_id"]] = $userdata;
459  }
460  }
461  return $participants;
462  }
463 
477  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
478  {
479  global $tree;
480 
481  switch ($a_event)
482  {
483  case "link":
484 
485  //var_dump("<pre>",$a_params,"</pre>");
486  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
487  //exit;
488  break;
489 
490  case "cut":
491 
492  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
493  //exit;
494  break;
495 
496  case "copy":
497 
498  //var_dump("<pre>",$a_params,"</pre>");
499  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
500  //exit;
501  break;
502 
503  case "paste":
504 
505  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
506  //exit;
507  break;
508 
509  case "new":
510 
511  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
512  //exit;
513  break;
514  }
515 
516  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
517  if ($a_node_id==$_GET["ref_id"])
518  {
519  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
520  $parent_type = $parent_obj->getType();
521  if($parent_type == $this->getType())
522  {
523  $a_node_id = (int) $tree->getParentId($a_node_id);
524  }
525  }
526 
527  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
528  }
529 
538  function isComplete()
539  {
540  if (($this->getTitle()) and ($this->getAuthor()) and (count($this->questions)))
541  {
542  return true;
543  }
544  else
545  {
546  return false;
547  }
548  }
549 
558  function _isComplete($obj_id)
559  {
560  $survey = new ilObjSurvey($obj_id, false);
561  $survey->loadFromDb();
562  if (($survey->getTitle()) and ($survey->getAuthor()) and (count($survey->questions)))
563  {
564  return true;
565  }
566  else
567  {
568  return false;
569  }
570  }
571 
580  function &_getGlobalSurveyData($obj_id)
581  {
582  $survey = new ilObjSurvey($obj_id, false);
583  $survey->loadFromDb();
584  $result = array();
585  if (($survey->getTitle()) and ($survey->author) and (count($survey->questions)))
586  {
587  $result["complete"] = true;
588  }
589  else
590  {
591  $result["complete"] = false;
592  }
593  $result["evaluation_access"] = $survey->getEvaluationAccess();
594  return $result;
595  }
596 
605  {
606  global $ilDB;
607 
608  $complete = 0;
609  if ($this->isComplete())
610  {
611  $complete = 1;
612  }
613  if ($this->survey_id > 0)
614  {
615  $query = sprintf("UPDATE survey_survey SET complete = %s WHERE survey_id = %s",
616  $ilDB->quote("$complete"),
617  $ilDB->quote($this->survey_id)
618  );
619  $result = $ilDB->query($query);
620  }
621  }
622 
632  function duplicateQuestionForSurvey($question_id)
633  {
634  global $ilUser;
635 
636  $questiontype = $this->getQuestionType($question_id);
637  $question_gui = $this->getQuestionGUI($questiontype, $question_id);
638  $duplicate_id = $question_gui->object->duplicate(true);
639  return $duplicate_id;
640  }
641 
649  function insertQuestion($question_id)
650  {
651  global $ilDB;
652 
653  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
654  if (!SurveyQuestion::_isComplete($question_id))
655  {
656  return FALSE;
657  }
658  else
659  {
660  // get maximum sequence index in test
661  $query = sprintf("SELECT survey_question_id FROM survey_survey_question WHERE survey_fi = %s",
662  $ilDB->quote($this->getSurveyId())
663  );
664  $result = $ilDB->query($query);
665  $sequence = $result->numRows();
666  $duplicate_id = $this->duplicateQuestionForSurvey($question_id);
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)
671  );
672  $result = $ilDB->query($query);
673  if (PEAR::isError($result))
674  {
675  global $ilias;
676  $ilias->raiseError($result->getMessage());
677  }
678  $this->loadQuestionsFromDb();
679  return TRUE;
680  }
681  }
682 
683 
684 
692  function insertQuestionblock($questionblock_id)
693  {
694  global $ilDB;
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)
697  );
698  $result = $ilDB->query($query);
699  $questions = array();
700  $show_questiontext = 0;
701  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
702  {
703  $duplicate_id = $this->duplicateQuestionForSurvey($row["question_fi"]);
704  array_push($questions, $duplicate_id);
705  $title = $row["title"];
706  $show_questiontext = $row["show_questiontext"];
707  }
708  $this->createQuestionblock($title, $show_questiontext, $questions);
709  }
710 
718  function getAllRTEContent()
719  {
720  $result = array();
721  array_push($result, $this->getIntroduction());
722  array_push($result, $this->getOutro());
723  return $result;
724  }
725 
734  {
735  include_once("./Services/RTE/classes/class.ilRTE.php");
736  $completecontent = "";
737  foreach ($this->getAllRTEContent() as $content)
738  {
739  $completecontent .= $content;
740  }
741  ilRTE::_cleanupMediaObjectUsage($completecontent, $this->getType() . ":html",
742  $this->getId());
743  }
744 
752  function saveToDb()
753  {
754  global $ilDB;
755  $complete = 0;
756  if ($this->isComplete())
757  {
758  $complete = 1;
759  }
760  $startdate = $this->getStartDate();
761  if (!$startdate or !$this->startdate_enabled)
762  {
763  $startdate = "NULL";
764  }
765  else
766  {
767  $startdate = $ilDB->quote($startdate);
768  }
769  $enddate = $this->getEndDate();
770  if (!$enddate or !$this->enddate_enabled)
771  {
772  $enddate = "NULL";
773  }
774  else
775  {
776  $enddate = $ilDB->quote($enddate);
777  }
778 
779  // cleanup RTE images
780  $this->cleanupMediaobjectUsage();
781 
782  if ($this->survey_id == -1)
783  {
784  // Write new dataset
785  $now = getdate();
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 . ""),
790  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->introduction, 0)),
791  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->getOutro(), 0)),
792  $ilDB->quote($this->status . ""),
793  $startdate,
794  $enddate,
795  $ilDB->quote($this->evaluation_access . ""),
796  $ilDB->quote($this->invitation . ""),
797  $ilDB->quote($this->invitation_mode . ""),
798  $ilDB->quote($complete . ""),
799  $ilDB->quote($this->getAnonymize() . ""),
800  $ilDB->quote($this->getShowQuestionTitles() . ""),
801  $ilDB->quote($created)
802  );
803  $result = $ilDB->query($query);
804  if (PEAR::isError($result))
805  {
806  global $ilias;
807  $ilias->raiseError($result->getMessage());
808  }
809  else
810  {
811  $this->survey_id = $ilDB->getLastInsertId();
812  }
813  }
814  else
815  {
816  // update existing dataset
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 . ""),
819  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->introduction, 0)),
820  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->getOutro(), 0)),
821  $ilDB->quote($this->status . ""),
822  $startdate,
823  $enddate,
824  $ilDB->quote($this->evaluation_access . ""),
825  $ilDB->quote($this->invitation . ""),
826  $ilDB->quote($this->invitation_mode . ""),
827  $ilDB->quote($complete . ""),
828  $ilDB->quote($this->getAnonymize() . ""),
829  $ilDB->quote($this->getShowQuestionTitles() . ""),
830  $ilDB->quote($this->survey_id)
831  );
832  $result = $ilDB->query($query);
833  }
834  if (PEAR::isError($result))
835  {
836  global $ilias;
837  $ilias->raiseError($result->getMessage());
838  }
839  else
840  {
841  // save questions to db
842  $this->saveQuestionsToDb();
843  }
844  }
845 
854  function saveQuestionsToDb()
855  {
856  global $ilDB;
857  // save old questions state
858  $old_questions = array();
859  $query = sprintf("SELECT * FROM survey_survey_question WHERE survey_fi = %s",
860  $ilDB->quote($this->getSurveyId())
861  );
862  $result = $ilDB->query($query);
863  if ($result->numRows())
864  {
865  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
866  {
867  $old_questions[$row["question_fi"]] = $row;
868  }
869  }
870 
871  // delete existing question relations
872  $query = sprintf("DELETE FROM survey_survey_question WHERE survey_fi = %s",
873  $ilDB->quote($this->getSurveyId())
874  );
875  $result = $ilDB->query($query);
876  // create new question relations
877  foreach ($this->questions as $key => $value)
878  {
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 . "")
884  );
885  $result = $ilDB->query($query);
886  }
887  }
888 
898  function getAnonymousId($id)
899  {
900  global $ilDB;
901  $query = sprintf("SELECT anonymous_id FROM survey_finished WHERE anonymous_id = %s",
902  $ilDB->quote($id)
903  );
904  $result = $ilDB->query($query);
905  if ($result->numRows())
906  {
907  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
908  return $row["anonymous_id"];
909  }
910  else
911  {
912  return "";
913  }
914  }
915 
924  function getQuestionGUI($questiontype, $question_id)
925  {
926  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
927  return SurveyQuestionGUI::_getQuestionGUI($questiontype, $question_id);
928  }
929 
939  function getQuestionType($question_id)
940  {
941  global $ilDB;
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)
945  );
946  $result = $ilDB->query($query);
947  if ($result->numRows() == 1)
948  {
949  $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
950  return $data->type_tag;
951  }
952  else
953  {
954  return "";
955  }
956  }
957 
966  function getSurveyId()
967  {
968  return $this->survey_id;
969  }
970 
974  function setAnonymize($a_anonymize)
975  {
976  $this->anonymize = $a_anonymize;
977  }
978 
984  function getAnonymize()
985  {
986  return $this->anonymize;
987  }
988 
995  {
996  if ($this->getAnonymize() == ANONYMIZE_FREEACCESS)
997  {
998  return true;
999  }
1000  else
1001  {
1002  return false;
1003  }
1004  }
1005 
1013  function loadFromDb()
1014  {
1015  global $ilDB;
1016  $query = sprintf("SELECT * FROM survey_survey WHERE obj_fi = %s",
1017  $ilDB->quote($this->getId())
1018  );
1019  $result = $ilDB->query($query);
1020  if ($result->numRows() == 1)
1021  {
1022  $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
1023  $this->survey_id = $data->survey_id;
1024  if (strlen($this->getAuthor()) == 0)
1025  {
1026  $this->saveAuthorToMetadata($data->author);
1027  }
1028  $this->author = $this->getAuthor();
1029  include_once("./Services/RTE/classes/class.ilRTE.php");
1030  $this->introduction = ilRTE::_replaceMediaObjectImageSrc($data->introduction, 1);
1031  if (strcmp($data->outro, "survey_finished") == 0)
1032  {
1033  $this->setOutro($this->lng->txt("survey_finished"));
1034  }
1035  else
1036  {
1038  }
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)
1045  {
1046  $this->startdate_enabled = 0;
1047  }
1048  else
1049  {
1050  $this->startdate_enabled = 1;
1051  }
1052  $this->end_date = $data->enddate;
1053  if (!$data->enddate)
1054  {
1055  $this->enddate_enabled = 0;
1056  }
1057  else
1058  {
1059  $this->enddate_enabled = 1;
1060  }
1061  switch ($data->anonymize)
1062  {
1063  case ANONYMIZE_OFF:
1064  case ANONYMIZE_ON:
1065  case ANONYMIZE_FREEACCESS:
1066  $this->setAnonymize($data->anonymize);
1067  break;
1068  default:
1069  $this->setAnonymize(ANONYMIZE_OFF);
1070  break;
1071  }
1072  $this->evaluation_access = $data->evaluation_access;
1073  $this->loadQuestionsFromDb();
1074  }
1075  }
1076 
1086  {
1087  global $ilDB;
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)
1091  );
1092  $result = $ilDB->query($query);
1093  while ($data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
1094  {
1095  $this->questions[$data->sequence] = $data->question_fi;
1096  }
1097  }
1098 
1108  function setStartDateEnabled($enabled = false)
1109  {
1110  if ($enabled)
1111  {
1112  $this->startdate_enabled = 1;
1113  }
1114  else
1115  {
1116  $this->startdate_enabled = 0;
1117  }
1118  }
1119 
1130  {
1131  return $this->startdate_enabled;
1132  }
1133 
1143  function setEndDateEnabled($enabled = false)
1144  {
1145  if ($enabled)
1146  {
1147  $this->enddate_enabled = 1;
1148  }
1149  else
1150  {
1151  $this->enddate_enabled = 0;
1152  }
1153  }
1154 
1165  {
1166  return $this->enddate_enabled;
1167  }
1168 
1178  function setAuthor($author = "")
1179  {
1180  $this->author = $author;
1181  }
1182 
1194  function saveAuthorToMetadata($a_author = "")
1195  {
1196  $md =& new ilMD($this->getId(), 0, $this->getType());
1197  $md_life =& $md->getLifecycle();
1198  if (!$md_life)
1199  {
1200  if (strlen($a_author) == 0)
1201  {
1202  global $ilUser;
1203  $a_author = $ilUser->getFullname();
1204  }
1205 
1206  $md_life =& $md->addLifecycle();
1207  $md_life->save();
1208  $con =& $md_life->addContribute();
1209  $con->setRole("Author");
1210  $con->save();
1211  $ent =& $con->addEntity();
1212  $ent->setEntity($a_author);
1213  $ent->save();
1214  }
1215  }
1216 
1226  function getAuthor()
1227  {
1228  $author = array();
1229  include_once "./Services/MetaData/classes/class.ilMD.php";
1230  $md =& new ilMD($this->getId(), 0, $this->getType());
1231  $md_life =& $md->getLifecycle();
1232  if ($md_life)
1233  {
1234  $ids =& $md_life->getContributeIds();
1235  foreach ($ids as $id)
1236  {
1237  $md_cont =& $md_life->getContribute($id);
1238  if (strcmp($md_cont->getRole(), "Author") == 0)
1239  {
1240  $entids =& $md_cont->getEntityIds();
1241  foreach ($entids as $entid)
1242  {
1243  $md_ent =& $md_cont->getEntity($entid);
1244  array_push($author, $md_ent->getEntity());
1245  }
1246  }
1247  }
1248  }
1249  return join($author, ",");
1250  }
1251 
1262  {
1264  }
1265 
1275  {
1276  $this->display_question_titles = QUESTIONTITLES_VISIBLE;
1277  }
1278 
1288  {
1289  $this->display_question_titles = QUESTIONTITLES_HIDDEN;
1290  }
1291 
1302  {
1303  global $ilDB;
1304  global $ilAccess;
1305  $this->invitation = $invitation;
1306  // remove the survey from the personal desktops
1307  $query = sprintf("DELETE FROM desktop_item WHERE type = %s AND item_id = %s",
1308  $ilDB->quote("svy"),
1309  $ilDB->quote($this->getRefId())
1310  );
1311  $result = $ilDB->query($query);
1312  if ($invitation == INVITATION_OFF)
1313  {
1314  // already removed prior
1315  }
1316  else if ($invitation == INVITATION_ON)
1317  {
1318  if ($this->getInvitationMode() == MODE_UNLIMITED)
1319  {
1320  $query = "SELECT usr_id FROM usr_data";
1321  $result = $ilDB->query($query);
1322  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
1323  {
1324  if ($ilAccess->checkAccessOfUser($row["usr_id"], "read", "", $this->getRefId(), "svy", $this->getId()))
1325  {
1326  $query = sprintf("INSERT INTO desktop_item (user_id, item_id, type, parameters) VALUES (%s, %s, %s, NULL)",
1327  $ilDB->quote($row["usr_id"]),
1328  $ilDB->quote($this->getRefId()),
1329  $ilDB->quote("svy")
1330  );
1331  $insertresult = $ilDB->query($query);
1332  }
1333  }
1334  }
1335  else
1336  {
1337  $query = sprintf("SELECT user_fi FROM survey_invited_user WHERE survey_fi = %s",
1338  $ilDB->quote($this->getSurveyId())
1339  );
1340  $result = $ilDB->query($query);
1341  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
1342  {
1343  $query = sprintf("INSERT INTO desktop_item (user_id, item_id, type, parameters) VALUES (%s, %s, %s, NULL)",
1344  $ilDB->quote($row["user_fi"]),
1345  $ilDB->quote($this->getRefId()),
1346  $ilDB->quote("svy")
1347  );
1348  $insertresult = $ilDB->query($query);
1349  }
1350  $query = sprintf("SELECT group_fi FROM survey_invited_group WHERE survey_fi = %s",
1351  $ilDB->quote($this->getSurveyId())
1352  );
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))
1357  {
1358  $group = new ilObjGroup($row["group_fi"]);
1359  $members = $group->getGroupMemberIds();
1360  foreach ($members as $user_id)
1361  {
1362  if (ilObjUser::_lookupLogin($user_id))
1363  {
1364  $user = new ilObjUser($user_id);
1365  $user->addDesktopItem($this->getRefId(), "svy");
1366  }
1367  }
1368  }
1369  }
1370  }
1371  }
1372 
1383  {
1384  global $ilDB;
1385  $this->invitation_mode = $invitation_mode;
1387  {
1388  $query = sprintf("DELETE FROM survey_invited_group WHERE survey_fi = %s",
1389  $ilDB->quote($this->getSurveyId())
1390  );
1391  $result = $ilDB->query($query);
1392  $query = sprintf("DELETE FROM survey_invited_user WHERE survey_fi = %s",
1393  $ilDB->quote($this->getSurveyId())
1394  );
1395  $result = $ilDB->query($query);
1396  }
1397  // add/remove the survey from personal desktops -> calling getInvitation with the same value makes all changes for the new invitation mode
1398  $this->setInvitation($this->getInvitation());
1399  }
1400 
1412  {
1413  global $ilDB;
1414  $this->invitation_mode = $invitation_mode;
1416  {
1417  $query = sprintf("DELETE FROM survey_invited_group WHERE survey_fi = %s",
1418  $ilDB->quote($this->getSurveyId())
1419  );
1420  $result = $ilDB->query($query);
1421  $query = sprintf("DELETE FROM survey_invited_user WHERE survey_fi = %s",
1422  $ilDB->quote($this->getSurveyId())
1423  );
1424  $result = $ilDB->query($query);
1425  }
1426  // add/remove the survey from personal desktops -> calling getInvitation with the same value makes all changes for the new invitation mode
1427  $this->setInvitation($invitation);
1428  }
1429 
1440  {
1441  $this->introduction = $introduction;
1442  }
1443 
1453  function setOutro($outro = "")
1454  {
1455  $this->outro = $outro;
1456  }
1457 
1467  function getInvitation()
1468  {
1469  return $this->invitation;
1470  }
1471 
1481  function getInvitationMode()
1482  {
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)
1487  {
1488  return MODE_PREDEFINED_USERS;
1489  }
1490  else
1491  {
1492  return $this->invitation_mode;
1493  }
1494  }
1495 
1505  function getStatus()
1506  {
1507  return $this->status;
1508  }
1509 
1519  function isOnline()
1520  {
1521  if ($this->status == STATUS_ONLINE)
1522  {
1523  return true;
1524  }
1525  else
1526  {
1527  return false;
1528  }
1529  }
1530 
1540  function isOffline()
1541  {
1542  if ($this->status == STATUS_OFFLINE)
1543  {
1544  return true;
1545  }
1546  else
1547  {
1548  return false;
1549  }
1550  }
1551 
1563  {
1564  $result = "";
1565  if (($status == STATUS_ONLINE) && (count($this->questions) == 0))
1566  {
1567  $this->status = STATUS_OFFLINE;
1568  $result = $this->lng->txt("cannot_switch_to_online_no_questions");
1569  }
1570  else
1571  {
1572  $this->status = $status;
1573  }
1574  return $result;
1575  }
1576 
1586  function getStartDate()
1587  {
1588  return $this->start_date;
1589  }
1590 
1599  function canStartSurvey($anonymous_id = NULL)
1600  {
1601  global $ilAccess;
1602 
1603  $result = TRUE;
1604  $messages = array();
1605  // check start date
1606  if ($this->getStartDateEnabled())
1607  {
1608  $epoch_time = mktime(0, 0, 0, $this->getStartMonth(), $this->getStartDay(), $this->getStartYear());
1609  $now = mktime();
1610  if ($now < $epoch_time)
1611  {
1612  array_push($messages,$this->lng->txt('start_date_not_reached').' ('.
1614  new ilDate($this->getStartYear().$this->getStartMonth().$this->getStartDay()."000000",IL_CAL_TIMESTAMP)). ")");
1615  $result = FALSE;
1616  }
1617  }
1618  // check end date
1619  if ($this->getEndDateEnabled())
1620  {
1621  $epoch_time = mktime(0, 0, 0, $this->getEndMonth(), $this->getEndDay(), $this->getEndYear());
1622  $now = mktime();
1623  if ($now > $epoch_time)
1624  {
1625  array_push($messages,$this->lng->txt('end_date_reached').' ('.
1627  new ilDate($this->getEndYear().$this->getEndMonth().$this->getEndDay()."000000",IL_CAL_TIMESTAMP)). ")");
1628  $result = FALSE;
1629  }
1630  }
1631  // check online status
1632  if ($this->getStatus() == STATUS_OFFLINE)
1633  {
1634  array_push($messages, $this->lng->txt("survey_is_offline"));
1635  $result = FALSE;
1636  }
1637  // check rbac permissions
1638  if (!$ilAccess->checkAccess("read", "", $this->ref_id))
1639  {
1640  array_push($messages, $this->lng->txt("cannot_participate_survey"));
1641  $result = FALSE;
1642  }
1643  // 2. check previous access
1644  if (!$result["error"])
1645  {
1646  global $ilUser;
1647  $survey_started = $this->isSurveyStarted($ilUser->getId(), $anonymous_id);
1648  if ($survey_started === 1)
1649  {
1650  array_push($messages, $this->lng->txt("already_completed_survey"));
1651  $result = FALSE;
1652  }
1653  }
1654  return array(
1655  "result" => $result,
1656  "messages" => $messages
1657  );
1658  }
1659 
1669  function setStartDate($start_date = "")
1670  {
1671  $this->start_date = $start_date;
1672  }
1673 
1683  function getStartMonth()
1684  {
1685  if (preg_match("/(\d{4})-(\d{2})-(\d{2})/", $this->start_date, $matches))
1686  {
1687  return $matches[2];
1688  }
1689  else
1690  {
1691  return "";
1692  }
1693  }
1694 
1704  function getStartDay()
1705  {
1706  if (preg_match("/(\d{4})-(\d{2})-(\d{2})/", $this->start_date, $matches))
1707  {
1708  return $matches[3];
1709  }
1710  else
1711  {
1712  return "";
1713  }
1714  }
1715 
1725  function getStartYear()
1726  {
1727  if (preg_match("/(\d{4})-(\d{2})-(\d{2})/", $this->start_date, $matches))
1728  {
1729  return $matches[1];
1730  }
1731  else
1732  {
1733  return "";
1734  }
1735  }
1736 
1746  function getEndDate()
1747  {
1748  return $this->end_date;
1749  }
1750 
1760  function setEndDate($end_date = "")
1761  {
1762  $this->end_date = $end_date;
1763  }
1764 
1774  function getEndMonth()
1775  {
1776  if (preg_match("/(\d{4})-(\d{2})-(\d{2})/", $this->end_date, $matches))
1777  {
1778  return $matches[2];
1779  }
1780  else
1781  {
1782  return "";
1783  }
1784  }
1785 
1795  function getEndDay()
1796  {
1797  if (preg_match("/(\d{4})-(\d{2})-(\d{2})/", $this->end_date, $matches))
1798  {
1799  return $matches[3];
1800  }
1801  else
1802  {
1803  return "";
1804  }
1805  }
1806 
1816  function getEndYear()
1817  {
1818  if (preg_match("/(\d{4})-(\d{2})-(\d{2})/", $this->end_date, $matches))
1819  {
1820  return $matches[1];
1821  }
1822  else
1823  {
1824  return "";
1825  }
1826  }
1827 
1838  {
1839  return $this->evaluation_access;
1840  }
1841 
1852  {
1853  $this->evaluation_access = $evaluation_access;
1854  }
1855 
1865  function getIntroduction()
1866  {
1867  return $this->introduction;
1868  }
1869 
1879  function getOutro()
1880  {
1881  return $this->outro;
1882  }
1883 
1893  {
1894  global $ilDB;
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())
1898  );
1899  $result = $ilDB->query($query);
1900  while ($data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
1901  {
1902  array_push($existing_questions, $data->original_id);
1903  }
1904  return $existing_questions;
1905  }
1906 
1915  function &getQuestionpoolTitles($could_be_offline = FALSE, $showPath = FALSE)
1916  {
1917  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1918  return ilObjSurveyQuestionPool::_getAvailableQuestionpools($use_object_id = TRUE, $could_be_offline, $showPath);
1919  }
1920 
1929  function moveUpQuestion($question_id)
1930  {
1931  $move_questions = array($question_id);
1932  $pages =& $this->getSurveyPages();
1933  $pageindex = -1;
1934  foreach ($pages as $idx => $page)
1935  {
1936  if ($page[0]["question_id"] == $question_id)
1937  {
1938  $pageindex = $idx;
1939  }
1940  }
1941  if ($pageindex > 0)
1942  {
1943  $this->moveQuestions($move_questions, $pages[$pageindex-1][0]["question_id"], 0);
1944  }
1945  else
1946  {
1947  // move up a question in a questionblock
1948  $questions = $this->getSurveyQuestions();
1949  $questions = array_keys($questions);
1950  $index = array_search($question_id, $questions);
1951  if (($index !== FALSE) && ($index > 0))
1952  {
1953  $this->moveQuestions($move_questions, $questions[$index-1], 0);
1954  }
1955  }
1956  }
1957 
1966  function moveDownQuestion($question_id)
1967  {
1968  $move_questions = array($question_id);
1969  $pages =& $this->getSurveyPages();
1970  $pageindex = -1;
1971  foreach ($pages as $idx => $page)
1972  {
1973  if (($page[0]["question_id"] == $question_id) && (strcmp($page[0]["questionblock_id"], "") == 0))
1974  {
1975  $pageindex = $idx;
1976  }
1977  }
1978  if (($pageindex < count($pages)-1) && ($pageindex >= 0))
1979  {
1980  $this->moveQuestions($move_questions, $pages[$pageindex+1][count($pages[$pageindex+1])-1]["question_id"], 1);
1981  }
1982  else
1983  {
1984  // move down a question in a questionblock
1985  $questions = $this->getSurveyQuestions();
1986  $questions = array_keys($questions);
1987  $index = array_search($question_id, $questions);
1988  if (($index !== FALSE) && ($index < count($questions)-1))
1989  {
1990  $this->moveQuestions($move_questions, $questions[$index+1], 1);
1991  }
1992  }
1993  }
1994 
2003  function moveUpQuestionblock($questionblock_id)
2004  {
2005  $pages =& $this->getSurveyPages();
2006  $move_questions = array();
2007  $pageindex = -1;
2008  foreach ($pages as $idx => $page)
2009  {
2010  if ($page[0]["questionblock_id"] == $questionblock_id)
2011  {
2012  foreach ($page as $pageidx => $question)
2013  {
2014  array_push($move_questions, $question["question_id"]);
2015  }
2016  $pageindex = $idx;
2017  }
2018  }
2019  if ($pageindex > 0)
2020  {
2021  $this->moveQuestions($move_questions, $pages[$pageindex-1][0]["question_id"], 0);
2022  }
2023  }
2024 
2033  function moveDownQuestionblock($questionblock_id)
2034  {
2035  $pages =& $this->getSurveyPages();
2036  $move_questions = array();
2037  $pageindex = -1;
2038  foreach ($pages as $idx => $page)
2039  {
2040  if ($page[0]["questionblock_id"] == $questionblock_id)
2041  {
2042  foreach ($page as $pageidx => $question)
2043  {
2044  array_push($move_questions, $question["question_id"]);
2045  }
2046  $pageindex = $idx;
2047  }
2048  }
2049  if ($pageindex < count($pages)-1)
2050  {
2051  $this->moveQuestions($move_questions, $pages[$pageindex+1][count($pages[$pageindex+1])-1]["question_id"], 1);
2052  }
2053  }
2054 
2065  function moveQuestions($move_questions, $target_index, $insert_mode)
2066  {
2067  $array_pos = array_search($target_index, $this->questions);
2068  if ($insert_mode == 0)
2069  {
2070  $part1 = array_slice($this->questions, 0, $array_pos);
2071  $part2 = array_slice($this->questions, $array_pos);
2072  }
2073  else if ($insert_mode == 1)
2074  {
2075  $part1 = array_slice($this->questions, 0, $array_pos + 1);
2076  $part2 = array_slice($this->questions, $array_pos + 1);
2077  }
2078  foreach ($move_questions as $question_id)
2079  {
2080  if (!(array_search($question_id, $part1) === FALSE))
2081  {
2082  unset($part1[array_search($question_id, $part1)]);
2083  }
2084  if (!(array_search($question_id, $part2) === FALSE))
2085  {
2086  unset($part2[array_search($question_id, $part2)]);
2087  }
2088  }
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)
2093  {
2094  $constraints = $this->getConstraints($question_id);
2095  foreach ($constraints as $idx => $constraint)
2096  {
2097  foreach ($part2 as $next_question_id)
2098  {
2099  if ($constraint["question"] == $next_question_id)
2100  {
2101  // constraint concerning a question that follows -> delete constraint
2102  $this->deleteConstraint($constraint["id"], $question_id);
2103  }
2104  }
2105  }
2106  }
2107  $this->saveQuestionsToDb();
2108  }
2109 
2118  function removeQuestion($question_id)
2119  {
2120  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
2121  $question =& $this->_instanciateQuestion($question_id);
2122  $question->delete($question_id);
2123  $this->removeConstraintsConcerningQuestion($question_id);
2124  }
2125 
2135  {
2136  global $ilDB;
2137  $query = sprintf("SELECT constraint_fi FROM survey_question_constraint WHERE question_fi = %s AND survey_fi = %s",
2138  $ilDB->quote($question_id . ""),
2139  $ilDB->quote($this->getSurveyId() . "")
2140  );
2141  $result = $ilDB->query($query);
2142  if ($result->numRows() > 0)
2143  {
2144  $remove_constraints = array();
2145  while ($row = $result->fetchRow(DB_FETCHMODE_HASHREF))
2146  {
2147  array_push($remove_constraints, $row["constraint_fi"]);
2148  }
2149  $query = sprintf("DELETE FROM survey_question_constraint WHERE question_fi = %s AND survey_fi = %s",
2150  $ilDB->quote($question_id . ""),
2151  $ilDB->quote($this->getSurveyId() . "")
2152  );
2153  $result = $ilDB->query($query);
2154  foreach ($remove_constraints as $key => $constraint_id)
2155  {
2156  $query = sprintf("DELETE FROM survey_constraint WHERE constraint_id = %s",
2157  $ilDB->quote($constraint_id . "")
2158  );
2159  $result = $ilDB->query($query);
2160  }
2161  }
2162  }
2163 
2173  function removeQuestions($remove_questions, $remove_questionblocks)
2174  {
2175  global $ilDB;
2176  $questions =& $this->getSurveyQuestions();
2177  foreach ($questions as $question_id => $data)
2178  {
2179  if (in_array($question_id, $remove_questions) or in_array($data["questionblock_id"], $remove_questionblocks))
2180  {
2181  unset($this->questions[array_search($question_id, $this->questions)]);
2182  $this->removeQuestion($question_id);
2183  }
2184  }
2185  foreach ($remove_questionblocks as $questionblock_id)
2186  {
2187  $query = sprintf("DELETE FROM survey_questionblock WHERE questionblock_id = %s",
2188  $ilDB->quote($questionblock_id)
2189  );
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),
2193  $ilDB->quote($this->getSurveyId())
2194  );
2195  $result = $ilDB->query($query);
2196  }
2197  $this->questions = array_values($this->questions);
2198  $this->saveQuestionsToDb();
2199  }
2200 
2209  function unfoldQuestionblocks($questionblocks)
2210  {
2211  global $ilDB;
2212  foreach ($questionblocks as $index)
2213  {
2214  $query = sprintf("DELETE FROM survey_questionblock WHERE questionblock_id = %s",
2215  $ilDB->quote($index)
2216  );
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),
2220  $ilDB->quote($this->getSurveyId())
2221  );
2222  $result = $ilDB->query($query);
2223  }
2224  }
2225 
2235  {
2236  global $ilDB;
2237  $titles = array();
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())
2240  );
2241  $result = $ilDB->query($query);
2242  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2243  {
2244  $titles[$row->questionblock_id] = $row->title;
2245  }
2246  return $titles;
2247  }
2248 
2257  function &getQuestionblockQuestions($questionblock_id)
2258  {
2259  global $ilDB;
2260  $titles = array();
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)
2263  );
2264  $result = $ilDB->query($query);
2265  $survey_id = "";
2266  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
2267  {
2268  $titles[$row["question_fi"]] = $row["title"];
2269  $survey_id = $row["survey_fi"];
2270  }
2271  $query = sprintf("SELECT question_fi, sequence FROM survey_survey_question WHERE survey_fi = %s ORDER BY sequence",
2272  $ilDB->quote($survey_id . "")
2273  );
2274  $result = $ilDB->query($query);
2275  $resultarray = array();
2276  $counter = 1;
2277  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
2278  {
2279  if (array_key_exists($row["question_fi"], $titles))
2280  {
2281  $resultarray[$counter++] = $titles[$row["question_fi"]];
2282  }
2283  }
2284  return $resultarray;
2285  }
2286 
2295  function &getQuestionblockQuestionIds($questionblock_id)
2296  {
2297  global $ilDB;
2298  $ids = array();
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)
2302  );
2303  $result = $ilDB->query($query);
2304  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2305  {
2306  array_push($ids, $row->question_id);
2307  }
2308  return $ids;
2309  }
2310 
2320  function getQuestionblock($questionblock_id)
2321  {
2322  global $ilDB;
2323  $query = sprintf("SELECT * FROM survey_questionblock WHERE questionblock_id = %s",
2324  $ilDB->quote($questionblock_id)
2325  );
2326  $result = $ilDB->query($query);
2327  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
2328  return $row;
2329  }
2330 
2340  function _getQuestionblock($questionblock_id)
2341  {
2342  global $ilDB;
2343  $query = sprintf("SELECT * FROM survey_questionblock WHERE questionblock_id = %s",
2344  $ilDB->quote($questionblock_id)
2345  );
2346  $result = $ilDB->query($query);
2347  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
2348  return $row;
2349  }
2350 
2361  function _addQuestionblock($title = "", $owner = 0)
2362  {
2363  global $ilDB;
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 . "")
2367  );
2368  $result = $ilDB->query($query);
2369  return $ilDB->getLastInsertId();
2370  }
2371 
2381  function createQuestionblock($title, $show_questiontext, $questions)
2382  {
2383  global $ilDB;
2384  // if the selected questions are not in a continous selection, move all questions of the
2385  // questionblock at the position of the first selected question
2386  $this->moveQuestions($questions, $questions[0], 0);
2387 
2388  // now save the question block
2389  global $ilUser;
2390  $query = sprintf("INSERT INTO survey_questionblock (questionblock_id, title, show_questiontext, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
2391  $ilDB->quote($title),
2392  $ilDB->quote($show_questiontext . ""),
2393  $ilDB->quote($ilUser->getId())
2394  );
2395  $result = $ilDB->query($query);
2396  if (PEAR::isError($result))
2397  {
2398  global $ilias;
2399  $ilias->raiseError($result->getMessage());
2400  }
2401  else
2402  {
2403  $questionblock_id = $ilDB->getLastInsertId();
2404  foreach ($questions as $index)
2405  {
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)
2410  );
2411  $result = $ilDB->query($query);
2412  $this->deleteConstraints($index);
2413  }
2414  }
2415  }
2416 
2426  function modifyQuestionblock($questionblock_id, $title, $show_questiontext)
2427  {
2428  global $ilDB;
2429  $query = sprintf("UPDATE survey_questionblock SET title = %s, show_questiontext = %s WHERE questionblock_id = %s",
2430  $ilDB->quote($title),
2431  $ilDB->quote($show_questiontext . ""),
2432  $ilDB->quote($questionblock_id)
2433  );
2434  $result = $ilDB->query($query);
2435  }
2436 
2445  function deleteConstraints($question_id)
2446  {
2447  global $ilDB;
2448  $query = sprintf("SELECT * FROM survey_question_constraint WHERE question_fi = %s AND survey_fi = %s",
2449  $ilDB->quote($question_id),
2450  $ilDB->quote($this->getSurveyId())
2451  );
2452  $result = $ilDB->query($query);
2453  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2454  {
2455  $query = sprintf("DELETE FROM survey_constraint WHERE constraint_id = %s",
2456  $ilDB->quote($row->constraint_fi)
2457  );
2458  $delresult = $ilDB->query($query);
2459  }
2460  $query = sprintf("DELETE FROM survey_question_constraint WHERE question_fi = %s AND survey_fi = %s",
2461  $ilDB->quote($question_id),
2462  $ilDB->quote($this->getSurveyId())
2463  );
2464  $delresult = $ilDB->query($query);
2465  }
2466 
2476  function deleteConstraint($constraint_id, $question_id)
2477  {
2478  global $ilDB;
2479  $query = sprintf("DELETE FROM survey_constraint WHERE constraint_id = %s",
2480  $ilDB->quote($constraint_id)
2481  );
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),
2486  $ilDB->quote($this->getSurveyId())
2487  );
2488  $delresult = $ilDB->query($query);
2489  }
2490 
2498  function &getSurveyQuestions($with_answers = false)
2499  {
2500  global $ilDB;
2501  $obligatory_states =& $this->getObligatoryStates();
2502  // get questionblocks
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())
2506  );
2507  $result = $ilDB->query($query);
2508  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
2509  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
2510  {
2511  $add = true;
2512  if ($row["plugin"])
2513  {
2514  if (!$this->isPluginActive($row["type_tag"]))
2515  {
2516  $add = false;
2517  }
2518  }
2519  if ($add)
2520  {
2521  $question =& $this->_instanciateQuestion($row["question_id"]);
2522  $questionrow = $question->_getQuestionDataArray($row["question_id"]);
2523  foreach ($row as $key => $value)
2524  {
2525  $questionrow[$key] = $value;
2526  }
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))
2531  {
2532  $all_questions[$row["question_id"]]["obligatory"] = $obligatory_states[$row["question_id"]];
2533  }
2534  }
2535  }
2536  // get all questionblocks
2537  $questionblocks = array();
2538  $in = join(array_keys($all_questions), "','");
2539  if ($in)
2540  {
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())
2543  );
2544  $result = $ilDB->query($query);
2545  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2546  {
2547  $questionblocks[$row->question_fi] = $row;
2548  }
2549  }
2550 
2551  foreach ($all_questions as $question_id => $row)
2552  {
2553  $constraints = $this->getConstraints($question_id);
2554  if (isset($questionblocks[$question_id]))
2555  {
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;
2559  }
2560  else
2561  {
2562  $all_questions[$question_id]["questionblock_title"] = "";
2563  $all_questions[$question_id]["questionblock_id"] = "";
2564  $all_questions[$question_id]["constraints"] = $constraints;
2565  }
2566  if ($with_answers)
2567  {
2568  $answers = array();
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 . "")
2571  );
2572  $result = $ilDB->query($query);
2573  if ($result->numRows() > 0)
2574  {
2575  while ($data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2576  {
2577  array_push($answers, $data->title);
2578  }
2579  }
2580  $all_questions[$question_id]["answers"] = $answers;
2581  }
2582  }
2583  return $all_questions;
2584  }
2585 
2594  function setObligatoryStates($obligatory_questions)
2595  {
2596  global $ilDB;
2597  $query = sprintf("SELECT * FROM survey_survey_question WHERE survey_fi = %s",
2598  $ilDB->quote($this->getSurveyId() . "")
2599  );
2600  $result = $ilDB->query($query);
2601  if ($result->numRows())
2602  {
2603  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
2604  {
2605  if (!array_key_exists($row["question_fi"], $obligatory_questions))
2606  {
2607  $obligatory_questions[$row["question_fi"]] = 0;
2608  }
2609  }
2610  }
2611 
2612  // set the obligatory states in the database
2613  $query = sprintf("DELETE FROM survey_question_obligatory WHERE survey_fi = %s",
2614  $ilDB->quote($this->getSurveyId() . "")
2615  );
2616  $result = $ilDB->query($query);
2617 
2618  // set the obligatory states in the database
2619  foreach ($obligatory_questions as $question_fi => $obligatory)
2620  {
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 . "")
2625  );
2626  $result = $ilDB->query($query);
2627  }
2628  }
2629 
2639  {
2640  global $ilDB;
2641  $obligatory_states = array();
2642  $query = sprintf("SELECT * FROM survey_question_obligatory WHERE survey_fi = %s",
2643  $ilDB->quote($this->getSurveyId() . "")
2644  );
2645  $result = $ilDB->query($query);
2646  if ($result->numRows())
2647  {
2648  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
2649  {
2650  $obligatory_states[$row["question_fi"]] = $row["obligatory"];
2651  }
2652  }
2653  return $obligatory_states;
2654  }
2655 
2663  function &getSurveyPages()
2664  {
2665  global $ilDB;
2666  $obligatory_states =& $this->getObligatoryStates();
2667  // get questionblocks
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())
2671  );
2672  $result = $ilDB->query($query);
2673  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
2674  {
2675  $all_questions[$row["question_id"]] = $row;
2676  }
2677  // get all questionblocks
2678  $questionblocks = array();
2679  $in = join(array_keys($all_questions), "','");
2680  if ($in)
2681  {
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())
2684  );
2685  $result = $ilDB->query($query);
2686  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2687  {
2688  $questionblocks["$row->question_fi"] = $row;
2689  }
2690  }
2691 
2692  $all_pages = array();
2693  $pageindex = -1;
2694  $currentblock = "";
2695  foreach ($all_questions as $question_id => $row)
2696  {
2697  if (array_key_exists($question_id, $obligatory_states))
2698  {
2699  $all_questions["$question_id"]["obligatory"] = $obligatory_states["$question_id"];
2700  }
2701  $constraints = array();
2702  if (isset($questionblocks[$question_id]))
2703  {
2704  if (!$currentblock or ($currentblock != $questionblocks[$question_id]->questionblock_id))
2705  {
2706  $pageindex++;
2707  }
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;
2712  $constraints = $this->getConstraints($question_id);
2713  $all_questions[$question_id]["constraints"] = $constraints;
2714  }
2715  else
2716  {
2717  $pageindex++;
2718  $all_questions[$question_id]["questionblock_title"] = "";
2719  $all_questions[$question_id]["questionblock_id"] = "";
2720  $all_questions[$question_id]["questionblock_show_questiontext"] = 1;
2721  $currentblock = "";
2722  $constraints = $this->getConstraints($question_id);
2723  $all_questions[$question_id]["constraints"] = $constraints;
2724  }
2725  if (!isset($all_pages[$pageindex]))
2726  {
2727  $all_pages[$pageindex] = array();
2728  }
2729  array_push($all_pages[$pageindex], $all_questions[$question_id]);
2730  }
2731  // calculate position percentage for every page
2732  $max = count($all_pages);
2733  $counter = 1;
2734  foreach ($all_pages as $index => $block)
2735  {
2736  foreach ($block as $blockindex => $question)
2737  {
2738  $all_pages[$index][$blockindex][position] = $counter / $max;
2739  }
2740  $counter++;
2741  }
2742  return $all_pages;
2743  }
2744 
2755  function getNextPage($active_page_question_id, $direction)
2756  {
2757  $foundpage = -1;
2758  $pages =& $this->getSurveyPages();
2759  if (strcmp($active_page_question_id, "") == 0)
2760  {
2761  return $pages[0];
2762  }
2763 
2764  foreach ($pages as $key => $question_array)
2765  {
2766  foreach ($question_array as $question)
2767  {
2768  if ($active_page_question_id == $question["question_id"])
2769  {
2770  $foundpage = $key;
2771  }
2772  }
2773  }
2774  if ($foundpage == -1)
2775  {
2776  // error: page not found
2777  }
2778  else
2779  {
2780  $foundpage += $direction;
2781  if ($foundpage < 0)
2782  {
2783  return 0;
2784  }
2785  if ($foundpage >= count($pages))
2786  {
2787  return 1;
2788  }
2789  return $pages[$foundpage];
2790  }
2791  }
2792 
2801  function &getAvailableQuestionpools($use_obj_id = false, $could_be_offline = false, $showPath = FALSE, $permission = "read")
2802  {
2803  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
2804  return ilObjSurveyQuestionPool::_getAvailableQuestionpools($use_obj_id, $could_be_offline, $showPath, $permission);
2805  }
2806 
2815  {
2816  global $ilDB;
2817 
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 . "")
2821  );
2822  $result = $ilDB->query($query);
2823  $pc = array();
2824  if ($result->numRows())
2825  {
2826  $pc = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
2827  }
2828  return $pc;
2829  }
2830 
2838  function getConstraints($question_id)
2839  {
2840  global $ilDB;
2841 
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),
2845  $ilDB->quote($this->getSurveyId())
2846  );
2847  $result = $ilDB->query($query);
2848  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2849  {
2850  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
2851  $question_type = SurveyQuestion::_getQuestionType($row->question_fi);
2852  SurveyQuestion::_includeClass($question_type);
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));
2857  }
2858  return $result_array;
2859  }
2860 
2869  {
2870  global $ilDB;
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",
2873  $ilDB->quote($survey_id . "")
2874  );
2875  $result = $ilDB->query($query);
2876  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2877  {
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));
2879  }
2880  return $result_array;
2881  }
2882 
2883 
2891  function &getVariables($question_id)
2892  {
2893  global $ilDB;
2894 
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)
2898  );
2899  $result = $ilDB->query($query);
2900  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2901  {
2902  $result_array[$row->sequence] = $row;
2903  }
2904  return $result_array;
2905  }
2906 
2918  function addConstraint($to_question_id, $if_question_id, $relation, $value)
2919  {
2920  global $ilDB;
2921 
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)
2926  );
2927  $result = $ilDB->query($query);
2928  if (PEAR::isError($result))
2929  {
2930  global $ilias;
2931  $ilias->raiseError($result->getMessage());
2932  }
2933  else
2934  {
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)
2940  );
2941  $result = $ilDB->query($query);
2942  }
2943  }
2944 
2957  function updateConstraint($to_question_id, $if_question_id, $relation, $value)
2958  {
2959  global $ilDB;
2960  $query = sprintf("SELECT constraint_fi FROM survey_question_constraint WHERE question_fi = %s AND survey_fi = %s",
2961  $ilDB->quote($to_question_id . ""),
2962  $ilDB->quote($this->getSurveyId() . "")
2963  );
2964  $result = $ilDB->query($query);
2965  if ($result->numRows())
2966  {
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"])
2973  );
2974  $result = $ilDB->query($query);
2975  }
2976  }
2977 
2985  function getAllRelations($short_as_key = false)
2986  {
2987  global $ilDB;
2988 
2989  $result_array = array();
2990  $query = "SELECT * FROM survey_relation";
2991  $result = $ilDB->query($query);
2992  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
2993  {
2994  if ($short_as_key)
2995  {
2996  $result_array[$row->shortname] = array("short" => $row->shortname, "long" => $row->longname, "id" => $row->relation_id);
2997  }
2998  else
2999  {
3000  $result_array[$row->relation_id] = array("short" => $row->shortname, "long" => $row->longname);
3001  }
3002  }
3003  return $result_array;
3004  }
3005 
3014  function disinviteUser($user_id)
3015  {
3016  global $ilDB;
3017 
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)
3021  );
3022  $result = $ilDB->query($query);
3023  if ($this->getInvitation() == INVITATION_ON)
3024  {
3025  include_once './Services/User/classes/class.ilObjUser.php';
3026  if (ilObjUser::_lookupLogin($user_id))
3027  {
3028  $userObj = new ilObjUser($user_id);
3029  $userObj->dropDesktopItem($this->getRefId(), "svy");
3030  }
3031  }
3032  }
3033 
3042  function inviteUser($user_id)
3043  {
3044  global $ilDB;
3045 
3046  $query = sprintf("SELECT user_fi FROM survey_invited_user WHERE user_fi = %s AND survey_fi = %s",
3047  $ilDB->quote($user_id),
3048  $ilDB->quote($this->getSurveyId())
3049  );
3050  $result = $ilDB->query($query);
3051  if ($result->numRows() < 1)
3052  {
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)
3056  );
3057  $result = $ilDB->query($query);
3058  }
3059  if ($this->getInvitation() == INVITATION_ON)
3060  {
3061  include_once './Services/User/classes/class.ilObjUser.php';
3062  if (ilObjUser::_lookupLogin($user_id))
3063  {
3064  $userObj = new ilObjUser($user_id);
3065  $userObj->addDesktopItem($this->getRefId(), "svy");
3066  }
3067  }
3068  }
3069 
3078  function inviteGroup($group_id)
3079  {
3080  global $ilAccess;
3081  $invited = 0;
3082  include_once "./Modules/Group/classes/class.ilObjGroup.php";
3083  $group = new ilObjGroup($group_id);
3084  $members = $group->getGroupMemberIds();
3085  foreach ($members as $user_id)
3086  {
3087  if ($ilAccess->checkAccessOfUser($user_id, "read", "", $this->getRefId(), "svy", $this->getId()))
3088  {
3089  $this->inviteUser($user_id);
3090  if ($this->getInvitation() == INVITATION_ON)
3091  {
3092  if (ilObjUser::_lookupLogin($user_id))
3093  {
3094  $userObj = new ilObjUser($user_id);
3095  $userObj->addDesktopItem($this->getRefId(), "svy");
3096  $invited++;
3097  }
3098  }
3099  }
3100  }
3101  return $invited;
3102  }
3103 
3112  function inviteRole($role_id)
3113  {
3114  global $rbacreview;
3115  global $ilAccess;
3116  $invited = 0;
3117  $members = $rbacreview->assignedUsers($role_id);
3118  foreach ($members as $user_id)
3119  {
3120  if ($ilAccess->checkAccessOfUser($user_id, "read", "", $this->getRefId(), "svy", $this->getId()))
3121  {
3122  $this->inviteUser($user_id);
3123  if ($this->getInvitation() == INVITATION_ON)
3124  {
3125  if (ilObjUser::_lookupLogin($user_id))
3126  {
3127  $userObj = new ilObjUser($user_id);
3128  $userObj->addDesktopItem($this->getRefId(), "svy");
3129  $invited++;
3130  }
3131  }
3132  }
3133  }
3134  return $invited;
3135  }
3136 
3145  function &getInvitedUsers()
3146  {
3147  global $ilDB;
3148 
3149  $result_array = array();
3150  $query = sprintf("SELECT user_fi FROM survey_invited_user WHERE survey_fi = %s",
3151  $ilDB->quote($this->getSurveyId())
3152  );
3153  $result = $ilDB->query($query);
3154  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
3155  {
3156  array_push($result_array, $row->user_fi);
3157  }
3158  return $result_array;
3159  }
3160 
3169  function &getInvitedGroups()
3170  {
3171  global $ilDB;
3172 
3173  $result_array = array();
3174  $query = sprintf("SELECT group_fi FROM survey_invited_group WHERE survey_fi = %s",
3175  $ilDB->quote($this->getSurveyId())
3176  );
3177  $result = $ilDB->query($query);
3178  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
3179  {
3180  array_push($result_array, $row->group_fi);
3181  }
3182  return $result_array;
3183  }
3184 
3194  function deleteWorkingData($question_id, $active_id)
3195  {
3196  global $ilDB;
3197 
3198  $query = "";
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)
3202  );
3203  $result = $ilDB->query($query);
3204  }
3205 
3216  function loadWorkingData($question_id, $active_id)
3217  {
3218  global $ilDB;
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)
3223  );
3224  $result = $ilDB->query($query);
3225  if ($result->numRows() >= 1)
3226  {
3227  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
3228  {
3229  array_push($result_array, $row);
3230  }
3231  return $result_array;
3232  }
3233  else
3234  {
3235  return $result_array;
3236  }
3237  }
3238 
3245  function fillSurveyForUser($user_id = ANONYMOUS_USER_ID)
3246  {
3247  global $ilDB;
3248  // create an anonymous key
3249  $anonymous_id = $this->createNewAccessCode();
3250  $this->saveUserAccessCode($user_id, $anonymous_id);
3251  // create the survey_finished dataset and set the survey finished already
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 . "")
3257  );
3258  $result = $ilDB->query($query);
3259  // get the active id for the user
3260  $active_id = $ilDB->getLastInsertId();
3261  // fill the questions randomly
3262  $pages =& $this->getSurveyPages();
3263  foreach ($pages as $key => $question_array)
3264  {
3265  foreach ($question_array as $question)
3266  {
3267  // instanciate question
3268  require_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
3269  $question =& SurveyQuestion::_instanciateQuestion($question["question_id"]);
3270  $question->saveRandomData($active_id);
3271  }
3272  }
3273  }
3274 
3283  function startSurvey($user_id, $anonymous_id)
3284  {
3285  global $ilUser;
3286  global $ilDB;
3287 
3288  if ($this->getAnonymize() && (strlen($anonymous_id) == 0)) return;
3289 
3290  if (strcmp($user_id, "") == 0)
3291  {
3292  if ($user_id == ANONYMOUS_USER_ID)
3293  {
3294  $user_id = 0;
3295  }
3296  }
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 . "")
3302  );
3303  $result = $ilDB->query($query);
3304 
3305  // get the insert id, but don't trust last_insert_id since we don't have transactions
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 . "")
3310  );
3311  $result = $ilDB->query($query);
3312  $insert_id = 0;
3313  if ($result->numRows())
3314  {
3315  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
3316  $insert_id = $row["finished_id"];
3317  }
3318  return $insert_id;
3319  }
3320 
3329  function finishSurvey($user_id, $anonymize_id)
3330  {
3331  global $ilDB;
3332 
3333  if ($this->getAnonymize())
3334  {
3335  $query = sprintf("UPDATE survey_finished SET state = %s, user_fi = %s WHERE survey_fi = %s AND anonymous_id = %s",
3336  $ilDB->quote("1"),
3337  $ilDB->quote($user_id . ""),
3338  $ilDB->quote($this->getSurveyId() . ""),
3339  $ilDB->quote($anonymize_id . "")
3340  );
3341  }
3342  else
3343  {
3344  $query = sprintf("UPDATE survey_finished SET state = %s WHERE survey_fi = %s AND user_fi = %s",
3345  $ilDB->quote("1"),
3346  $ilDB->quote($this->getSurveyId() . ""),
3347  $ilDB->quote($user_id . "")
3348  );
3349  }
3350  $result = $ilDB->query($query);
3351  }
3352 
3362  function isAllowedToTakeMultipleSurveys($userid = "")
3363  {
3364  $result = FALSE;
3365  if ($this->getAnonymize())
3366  {
3367  if ($this->isAccessibleWithoutCode())
3368  {
3369  if (strlen($username) == 0)
3370  {
3371  global $ilUser;
3372  $userid = $ilUser->getId();
3373  }
3374  global $ilSetting;
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))
3378  {
3379  $result = TRUE;
3380  }
3381  }
3382  }
3383  return $result;
3384  }
3385 
3395  function isSurveyStarted($user_id, $anonymize_id)
3396  {
3397  global $ilDB;
3398 
3399  if ($this->getAnonymize())
3400  {
3401  if ((($user_id != ANONYMOUS_USER_ID) && (strlen($anonymize_id) == 0)) && (!($this->isAccessibleWithoutCode() && $this->isAllowedToTakeMultipleSurveys())))
3402  {
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)
3406  );
3407  }
3408  else
3409  {
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)
3413  );
3414  }
3415  }
3416  else
3417  {
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)
3421  );
3422  }
3423  $result = $ilDB->query($query);
3424  if ($result->numRows() == 0)
3425  {
3426  return false;
3427  }
3428  else
3429  {
3430  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
3431  $_SESSION["finished_id"] = $row["finished_id"];
3432  return (int)$row["state"];
3433  }
3434  }
3435 
3445  function getLastActivePage($active_id)
3446  {
3447  global $ilDB;
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)
3450  );
3451  $result = $ilDB->query($query);
3452  if ($result->numRows() == 0)
3453  {
3454  return "";
3455  }
3456  else
3457  {
3458  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
3459  return $row["question_fi"];
3460  }
3461  }
3462 
3473  function checkConstraint($constraint_data, $working_data)
3474  {
3475  if (count($working_data) == 0)
3476  {
3477  return 0;
3478  }
3479 
3480  if ((count($working_data) == 1) and (strcmp($working_data[0]["value"], "") == 0))
3481  {
3482  return 0;
3483  }
3484 
3485  foreach ($working_data as $data)
3486  {
3487  switch ($constraint_data["short"])
3488  {
3489  case "<":
3490  if ($data["value"] < $constraint_data["value"])
3491  {
3492  return 1;
3493  }
3494  break;
3495  case "<=":
3496  if ($data["value"] <= $constraint_data["value"])
3497  {
3498  return 1;
3499  }
3500  break;
3501  case "=":
3502  if ($data["value"] == $constraint_data["value"])
3503  {
3504  return 1;
3505  }
3506  break;
3507  case "<>":
3508  if ($data["value"] != $constraint_data["value"])
3509  {
3510  return 1;
3511  }
3512  break;
3513  case ">=":
3514  if ($data["value"] >= $constraint_data["value"])
3515  {
3516  return 1;
3517  }
3518  break;
3519  case ">":
3520  if ($data["value"] > $constraint_data["value"])
3521  {
3522  return 1;
3523  }
3524  break;
3525  }
3526  }
3527  return 0;
3528  }
3529 
3531  {
3532  global $ilDB;
3533 
3534  $query = sprintf("SELECT finished_id FROM survey_finished WHERE survey_fi = %s",
3535  $ilDB->quote($survey_id . "")
3536  );
3537  $result = $ilDB->query($query);
3538  if ($result->numRows())
3539  {
3540  return true;
3541  }
3542  else
3543  {
3544  return false;
3545  }
3546  }
3547 
3555  {
3556  global $ilDB, $ilLog;
3557 
3558  $users = array();
3559  $query = sprintf("SELECT * FROM survey_finished WHERE survey_fi = %s",
3560  $ilDB->quote($this->getSurveyId() . "")
3561  );
3562  $result = $ilDB->query($query);
3563  if ($result->numRows())
3564  {
3565  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
3566  {
3567  array_push($users, $row["finished_id"]);
3568  }
3569  }
3570  return $users;
3571  }
3572 
3580  {
3581  global $ilDB;
3582 
3583  $users = array();
3584  $query = sprintf("SELECT * FROM survey_finished WHERE survey_fi = %s",
3585  $ilDB->quote($this->getSurveyId() . "")
3586  );
3587  $result = $ilDB->query($query);
3588  if ($result->numRows())
3589  {
3590  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
3591  {
3592  array_push($users, $row);
3593  }
3594  }
3595  $evaluation = array();
3596  $questions =& $this->getSurveyQuestions();
3597  foreach ($questions as $question_id => $question_data)
3598  {
3599  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
3600  $question_type = SurveyQuestion::_getQuestionType($question_id);
3601  SurveyQuestion::_includeClass($question_type);
3602  $question = new $question_type();
3603  $question->loadFromDb($question_id);
3604  $data =& $question->getUserAnswers($this->getSurveyId());
3605  $evaluation[$question_id] = $data;
3606  }
3607  return $evaluation;
3608  }
3609 
3617  function getUserDataFromActiveId($active_id)
3618  {
3619  global $ilDB;
3620 
3621  $query = sprintf("SELECT * FROM survey_finished WHERE finished_id = %s",
3622  $ilDB->quote($active_id)
3623  );
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");
3627  $row = array();
3628  $foundrows = $result->numRows();
3629  if ($foundrows)
3630  {
3631  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
3632  }
3633  $name = ($use_anonymous_id) ? $row["anonymous_id"] : $this->lng->txt("anonymous");
3634  $userdata = array(
3635  "fullname" => $name,
3636  "sortname" => $name,
3637  "firstname" => "",
3638  "lastname" => "",
3639  "login" => "",
3640  "gender" => "",
3641  "active_id" => "$active_id"
3642  );
3643  if ($foundrows)
3644  {
3645  if (($row["user_fi"] > 0) && ($row["user_fi"] != ANONYMOUS_USER_ID) && ($this->getAnonymize() == 0))
3646  {
3647  include_once './Services/User/classes/class.ilObjUser.php';
3648  if (strlen(ilObjUser::_lookupLogin($row["user_fi"])) == 0)
3649  {
3650  $userdata["fullname"] = $this->lng->txt("deleted_user");
3651  }
3652  else
3653  {
3654  $user = new ilObjUser($row["user_fi"]);
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();
3663  }
3664  }
3665  }
3666  return $userdata;
3667  }
3668 
3680  function &getEvaluationByUser($questions, $active_id)
3681  {
3682  global $ilDB;
3683 
3684  // collect all answers
3685  $answers = array();
3686  $query = sprintf("SELECT * FROM survey_answer WHERE active_fi = %s",
3687  $ilDB->quote($active_id)
3688  );
3689  $result = $ilDB->query($query);
3690  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
3691  {
3692  if (!is_array($answers[$row["question_fi"]]))
3693  {
3694  $answers[$row["question_fi"]] = array();
3695  }
3696  array_push($answers[$row["question_fi"]], $row);
3697  }
3698  $userdata = $this->getUserDataFromActiveId($active_id);
3699  $resultset = array(
3700  "name" => $userdata["fullname"],
3701  "gender" => $userdata["gender"],
3702  "answers" => array()
3703  );
3704  foreach ($questions as $key => $question)
3705  {
3706  if (array_key_exists($key, $answers))
3707  {
3708  $resultset["answers"][$key] = $answers[$key];
3709  }
3710  else
3711  {
3712  $resultset["answers"][$key] = array();
3713  }
3714  sort($resultset["answers"][$key]);
3715  }
3716  return $resultset;
3717  }
3718 
3729  function getCumulatedResults(&$question)
3730  {
3731  global $ilDB;
3732 
3733  $query = sprintf("SELECT finished_id FROM survey_finished WHERE survey_fi = %s",
3734  $ilDB->quote($this->getSurveyId())
3735  );
3736  $result = $ilDB->query($query);
3737  $nr_of_users = $result->numRows();
3738 
3739  $result_array =& $question->getCumulatedResults($this->getSurveyId(), $nr_of_users);
3740  return $result_array;
3741  }
3742 
3753  {
3754  global $ilDB;
3755 
3756  $query = sprintf("SELECT finished_id FROM survey_finished WHERE survey_fi = %s",
3757  $ilDB->quote($survey_id . "")
3758  );
3759  $result = $ilDB->query($query);
3760  return $result->numRows();
3761  }
3762 
3763  function &getQuestions($question_ids)
3764  {
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))
3769  {
3770  array_push($result_array, $row);
3771  }
3772  return $result_array;
3773  }
3774 
3775  function &getQuestionblocks($questionblock_ids)
3776  {
3777  global $ilDB;
3778 
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))
3783  {
3784  if ($row["questionblock_id"] != $qbid)
3785  {
3786  $sequence = 1;
3787  }
3788  $row["sequence"] = $sequence++;
3789  $result_array[$row["questionblock_id"]][$row["question_id"]] = $row;
3790  $qbid = $row["questionblock_id"];
3791  }
3792  return $result_array;
3793  }
3794 
3802  function getQuestionsTable($sort, $sortorder, $filter_text, $sel_filter_type, $startrow = 0, $completeonly = 0, $filter_question_type = "", $filter_questionpool = "")
3803  {
3804  global $ilUser;
3805  global $ilDB;
3806 
3807  $where = "";
3808  if (strlen($filter_text) > 0)
3809  {
3810  switch($sel_filter_type)
3811  {
3812  case "title":
3813  $where = " AND survey_question.title LIKE " . $ilDB->quote("%" . $filter_text . "%");
3814  break;
3815  case "description":
3816  $where = " AND survey_question.description LIKE " . $ilDB->quote("%" . $filter_text . "%");
3817  break;
3818  case "author":
3819  $where = " AND survey_question.author LIKE " . $ilDB->quote("%" . $filter_text . "%");
3820  break;
3821  }
3822  }
3823 
3824  if ($filter_question_type && (strcmp($filter_question_type, "all") != 0))
3825  {
3826  $where .= " AND survey_questiontype.type_tag = " . $ilDB->quote($filter_question_type);
3827  }
3828 
3829  if ($filter_questionpool && (strcmp($filter_questionpool, "all") != 0))
3830  {
3831  $where .= " AND survey_question.obj_fi = $filter_questionpool";
3832  }
3833 
3834  // build sort order for sql query
3835  $order = "";
3836  $images = array();
3837  include_once "./Services/Utilities/classes/class.ilUtil.php";
3838  switch($sort)
3839  {
3840  case "title":
3841  $order = " ORDER BY title $sortorder";
3842  $images["title"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . strtolower($sortorder) . "ending order\" />";
3843  break;
3844  case "description":
3845  $order = " ORDER BY description $sortorder";
3846  $images["description"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . strtolower($sortorder) . "ending order\" />";
3847  break;
3848  case "type":
3849  $order = " ORDER BY questiontype_id $sortorder";
3850  $images["type"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . strtolower($sortorder) . "ending order\" />";
3851  break;
3852  case "author":
3853  $order = " ORDER BY author $sortorder";
3854  $images["author"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . strtolower($sortorder) . "ending order\" />";
3855  break;
3856  case "created":
3857  $order = " ORDER BY created $sortorder";
3858  $images["created"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . strtolower($sortorder) . "ending order\" />";
3859  break;
3860  case "updated":
3861  $order = " ORDER BY timestamp14 $sortorder";
3862  $images["updated"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . strtolower($sortorder) . "ending order\" />";
3863  break;
3864  case "qpl":
3865  $order = " ORDER BY obj_fi $sortorder";
3866  $images["qpl"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . strtolower($sortorder) . "ending order\" />";
3867  break;
3868  }
3869  $maxentries = $ilUser->prefs["hits_per_page"];
3870  if ($maxentries < 1)
3871  {
3872  $maxentries = 9999;
3873  }
3874 
3875  $spls =& $this->getAvailableQuestionpools($use_obj_id = TRUE, $could_be_offline = FALSE, $showPath = FALSE);
3876  $forbidden = "";
3877  $forbidden = " AND survey_question.obj_fi IN ('" . join(array_keys($spls), "','") . "')";
3878  if ($completeonly)
3879  {
3880  $forbidden .= " AND survey_question.complete = " . $ilDB->quote("1");
3881  }
3882  $existing = "";
3883  $existing_questions =& $this->getExistingQuestions();
3884  if (count($existing_questions))
3885  {
3886  $existing = " AND survey_question.question_id NOT IN ('" . join($existing_questions, "','") . "')";
3887  }
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)
3895  {
3896  $startrow = $max - ($max % $maxentries);
3897  }
3898  else if ($startrow < 0)
3899  {
3900  $startrow = 0;
3901  }
3902  $rows = array();
3903  if ($query_result->numRows())
3904  {
3905  while ($row = $query_result->fetchRow(MDB2_FETCHMODE_ASSOC))
3906  {
3907  if ($row["plugin"])
3908  {
3909  if ($this->isPluginActive($row["type_tag"]))
3910  {
3911  array_push($rows, $row);
3912  }
3913  }
3914  else
3915  {
3916  array_push($rows, $row);
3917  }
3918  }
3919  }
3920  $nextrow = $startrow + $maxentries;
3921  if ($nextrow > $max - 1)
3922  {
3923  $nextrow = $startrow;
3924  }
3925  $prevrow = $startrow - $maxentries;
3926  if ($prevrow < 0)
3927  {
3928  $prevrow = 0;
3929  }
3930  return array(
3931  "rows" => $rows,
3932  "images" => $images,
3933  "startrow" => $startrow,
3934  "nextrow" => $nextrow,
3935  "prevrow" => $prevrow,
3936  "step" => $maxentries,
3937  "rowcount" => $max
3938  );
3939  }
3940 
3948  function getQuestionblocksTable($sort, $sortorder, $filter_text, $sel_filter_type, $startrow = 0)
3949  {
3950  global $ilDB;
3951  global $ilUser;
3952  $where = "";
3953  if (strlen($filter_text) > 0) {
3954  switch($sel_filter_type) {
3955  case "title":
3956  $where = " AND survey_questionblock.title LIKE " . $ilDB->quote("%" . $filter_text . "%");
3957  break;
3958  }
3959  }
3960 
3961  // build sort order for sql query
3962  $order = "";
3963  $images = array();
3964  include_once "./Services/Utilities/classes/class.ilUtil.php";
3965  switch($sort)
3966  {
3967  case "title":
3968  $order = " ORDER BY survey_questionblock.title $sortorder";
3969  $images["title"] = " <img src=\"" . ilUtil::getImagePath(strtolower($sortorder) . "_order.gif") . "\" alt=\"" . strtolower($sortorder) . "ending order\" />";
3970  break;
3971  case "svy":
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\" />";
3974  break;
3975  }
3976  $maxentries = $ilUser->prefs["hits_per_page"];
3977  if ($order)
3978  {
3979  $order .= ",survey_survey_question.sequence ASC";
3980  }
3981  else
3982  {
3983  $order = " ORDER BY survey_survey_question.sequence ASC";
3984  }
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())
3989  {
3990  while ($row = $query_result->fetchRow(MDB2_FETCHMODE_ASSOC))
3991  {
3992  array_push($questionblock_ids, $row["questionblock_id"]);
3993  }
3994  }
3995 
3996  $max = $query_result->numRows();
3997  if ($startrow > $max -1)
3998  {
3999  $startrow = $max - ($max % $maxentries);
4000  }
4001  else if ($startrow < 0)
4002  {
4003  $startrow = 0;
4004  }
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);
4008  $rows = array();
4009  if ($query_result->numRows())
4010  {
4011  while ($row = $query_result->fetchRow(MDB2_FETCHMODE_ASSOC))
4012  {
4013  $questions_array =& $this->getQuestionblockQuestions($row["questionblock_id"]);
4014  $counter = 1;
4015  foreach ($questions_array as $key => $value)
4016  {
4017  $questions_array[$key] = "$counter. $value";
4018  $counter++;
4019  }
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"]
4026  );
4027  }
4028  }
4029  $nextrow = $startrow + $maxentries;
4030  if ($nextrow > $max - 1)
4031  {
4032  $nextrow = $startrow;
4033  }
4034  $prevrow = $startrow - $maxentries;
4035  if ($prevrow < 0)
4036  {
4037  $prevrow = 0;
4038  }
4039  return array(
4040  "rows" => $rows,
4041  "images" => $images,
4042  "startrow" => $startrow,
4043  "nextrow" => $nextrow,
4044  "prevrow" => $prevrow,
4045  "step" => $maxentries,
4046  "rowcount" => $max
4047  );
4048  }
4049 
4058  function toXML()
4059  {
4060  include_once("./classes/class.ilXmlWriter.php");
4061  $a_xml_writer = new ilXmlWriter;
4062  // set xml header
4063  $a_xml_writer->xmlHeader();
4064  $attrs = array(
4065  "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
4066  "xsi:noNamespaceSchemaLocation" => "http://www.ilias.de/download/xsd/ilias_survey_3_8.xsd"
4067  );
4068  $a_xml_writer->xmlStartTag("surveyobject", $attrs);
4069  $attrs = array(
4070  "id" => $this->getSurveyId(),
4071  "title" => $this->getTitle()
4072  );
4073  $a_xml_writer->xmlStartTag("survey", $attrs);
4074 
4075  $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
4076  $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
4077  $a_xml_writer->xmlStartTag("objectives");
4078  $attrs = array(
4079  "label" => "introduction"
4080  );
4081  $this->addMaterialTag($a_xml_writer, $this->getIntroduction(), TRUE, TRUE, $attrs);
4082  $attrs = array(
4083  "label" => "outro"
4084  );
4085  $this->addMaterialTag($a_xml_writer, $this->getOutro(), TRUE, TRUE, $attrs);
4086  $a_xml_writer->xmlEndTag("objectives");
4087 
4088  if ($this->getAnonymize())
4089  {
4090  $attribs = array("enabled" => "1");
4091  }
4092  else
4093  {
4094  $attribs = array("enabled" => "0");
4095  }
4096  $a_xml_writer->xmlElement("anonymisation", $attribs);
4097  $a_xml_writer->xmlStartTag("restrictions");
4098  if ($this->getAnonymize() == 2)
4099  {
4100  $attribs = array("type" => "free");
4101  }
4102  else
4103  {
4104  $attribs = array("type" => "restricted");
4105  }
4106  $a_xml_writer->xmlElement("access", $attribs);
4107  if ($this->getStartDateEnabled())
4108  {
4109  $attrs = array("type" => "date");
4110  $a_xml_writer->xmlElement("startingtime", $attrs, sprintf("%04d-%02d-%02dT00:00:00", $this->getStartYear(), $this->getStartMonth(), $this->getStartDay()));
4111  }
4112  if ($this->getEndDateEnabled())
4113  {
4114  $attrs = array("type" => "date");
4115  $a_xml_writer->xmlElement("endingtime", $attrs, sprintf("%04d-%02d-%02dT00:00:00", $this->getEndYear(), $this->getEndMonth(), $this->getEndDay()));
4116  }
4117  $a_xml_writer->xmlEndTag("restrictions");
4118 
4119  // constraints
4120  $pages =& $this->getSurveyPages();
4121  $hasconstraints = FALSE;
4122  foreach ($pages as $question_array)
4123  {
4124  foreach ($question_array as $question)
4125  {
4126  if (count($question["constraints"]))
4127  {
4128  $hasconstraints = TRUE;
4129  }
4130  }
4131  }
4132 
4133  if ($hasconstraints)
4134  {
4135  $a_xml_writer->xmlStartTag("constraints");
4136  foreach ($pages as $question_array)
4137  {
4138  foreach ($question_array as $question)
4139  {
4140  if (count($question["constraints"]))
4141  {
4142  // found constraints
4143  foreach ($question["constraints"] as $constraint)
4144  {
4145  $attribs = array(
4146  "sourceref" => $question["question_id"],
4147  "destref" => $constraint["question"],
4148  "relation" => $constraint["short"],
4149  "value" => $constraint["value"]
4150  );
4151  $a_xml_writer->xmlElement("constraint", $attribs);
4152  }
4153  }
4154  }
4155  }
4156  $a_xml_writer->xmlEndTag("constraints");
4157  }
4158 
4159  // add the rest of the preferences in qtimetadata tags, because there is no correspondent definition in QTI
4160  $a_xml_writer->xmlStartTag("metadata");
4161 
4162  $a_xml_writer->xmlStartTag("metadatafield");
4163  $a_xml_writer->xmlElement("fieldlabel", NULL, "evaluation_access");
4164  $a_xml_writer->xmlElement("fieldentry", NULL, $this->getEvaluationAccess());
4165  $a_xml_writer->xmlEndTag("metadatafield");
4166 
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");
4171 
4172  $a_xml_writer->xmlStartTag("metadatafield");
4173  $a_xml_writer->xmlElement("fieldlabel", NULL, "display_question_titles");
4174  $a_xml_writer->xmlElement("fieldentry", NULL, $this->getShowQuestionTitles());
4175  $a_xml_writer->xmlEndTag("metadatafield");
4176 
4177  $a_xml_writer->xmlStartTag("metadatafield");
4178  $a_xml_writer->xmlElement("fieldlabel", NULL, "SCORM");
4179  include_once "./Services/MetaData/classes/class.ilMD.php";
4180  $md = new ilMD($this->getId(),0, $this->getType());
4181  $writer = new ilXmlWriter();
4182  $md->toXml($writer);
4183  $metadata = $writer->xmlDumpMem();
4184  $a_xml_writer->xmlElement("fieldentry", NULL, $metadata);
4185  $a_xml_writer->xmlEndTag("metadatafield");
4186 
4187  $a_xml_writer->xmlEndTag("metadata");
4188  $a_xml_writer->xmlEndTag("survey");
4189 
4190  $attribs = array("id" => $this->getId());
4191  $a_xml_writer->xmlStartTag("surveyquestions", $attribs);
4192  // add questionblock descriptions
4193  $obligatory_states =& $this->getObligatoryStates();
4194  foreach ($pages as $question_array)
4195  {
4196  if (count($question_array) > 1)
4197  {
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"]))
4202  {
4203  $a_xml_writer->xmlElement("questionblocktitle", NULL, $question_array[0]["questionblock_title"]);
4204  }
4205  }
4206  foreach ($question_array as $question)
4207  {
4208  if (strlen($question["heading"]))
4209  {
4210  $a_xml_writer->xmlElement("textblock", NULL, $question["heading"]);
4211  }
4212  $questionObject =& $this->_instanciateQuestion($question["question_id"]);
4213  if ($questionObject !== FALSE) $questionObject->insertXML($a_xml_writer, FALSE, $obligatory_states[$question["question_id"]]);
4214  }
4215  if (count($question_array) > 1)
4216  {
4217  $a_xml_writer->xmlEndTag("questionblock");
4218  }
4219  }
4220 
4221  $a_xml_writer->xmlEndTag("surveyquestions");
4222  $a_xml_writer->xmlEndTag("surveyobject");
4223  $xml = $a_xml_writer->xmlDumpMem(FALSE);
4224  return $xml;
4225  }
4226 
4236  function &_instanciateQuestion($question_id)
4237  {
4238  if ($question_id < 1) return FALSE;
4239  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
4240  $question_type = SurveyQuestion::_getQuestionType($question_id);
4241  if (strlen($question_type) == 0) return FALSE;
4242  SurveyQuestion::_includeClass($question_type);
4243  $question = new $question_type();
4244  $question->loadFromDb($question_id);
4245  return $question;
4246  }
4247 
4256  function locateImportFiles($a_dir)
4257  {
4258  if (!is_dir($a_dir) || is_int(strpos($a_dir, "..")))
4259  {
4260  return;
4261  }
4262  $importDirectory = "";
4263  $xmlFile = "";
4264 
4265  $current_dir = opendir($a_dir);
4266  $files = array();
4267  while($entryname = readdir($current_dir))
4268  {
4269  $files[] = $entryname;
4270  }
4271 
4272  foreach($files as $file)
4273  {
4274  if(is_dir($a_dir."/".$file) and ($file != "." and $file!=".."))
4275  {
4276  // found directory created by zip
4277  $importDirectory = $a_dir."/".$file;
4278  }
4279  }
4280  closedir($current_dir);
4281  if (strlen($importDirectory))
4282  {
4283  // find the xml file
4284  $current_dir = opendir($importDirectory);
4285  $files = array();
4286  while($entryname = readdir($current_dir))
4287  {
4288  $files[] = $entryname;
4289  }
4290  foreach($files as $file)
4291  {
4292  if(@is_file($importDirectory."/".$file) && ($file != "." && $file!="..") && (strcmp(strtolower(substr($file, -4, 4)), ".xml") == 0))
4293  {
4294  // found xml file
4295  $xmlFile = $importDirectory."/".$file;
4296  }
4297  }
4298  }
4299  return array("dir" => $importDirectory, "xml" => $xmlFile);
4300  }
4301 
4310  function importObject($file_info, $survey_questionpool_id)
4311  {
4312  // check if file was uploaded
4313  $source = $file_info["tmp_name"];
4314  $error = "";
4315  if (($source == 'none') || (!$source) || $file_info["error"] > UPLOAD_ERR_OK)
4316  {
4317  $error = $this->lng->txt("import_no_file_selected");
4318  }
4319  // check correct file type
4320  $isXml = FALSE;
4321  $isZip = FALSE;
4322  if ((strcmp($file_info["type"], "text/xml") == 0) || (strcmp($file_info["type"], "application/xml") == 0))
4323  {
4324  $isXml = TRUE;
4325  }
4326  if (strpos($file_info["type"], "zip") !== FALSE)
4327  {
4328  $isZip = TRUE;
4329  }
4330  if (!$isXml && !$isZip)
4331  {
4332  $error = $this->lng->txt("import_wrong_file_type");
4333  global $ilLog;
4334  $ilLog->write("Survey: Import error. Filetype was \"" . $file_info["type"] ."\"");
4335  }
4336  if (strlen($error) == 0)
4337  {
4338  // import file as a survey
4339  $import_dir = $this->getImportDirectory();
4340  $import_subdir = "";
4341  $importfile = "";
4342  include_once "./Services/Utilities/classes/class.ilUtil.php";
4343  if ($isZip)
4344  {
4345  $importfile = $import_dir."/".$file_info["name"];
4346  ilUtil::moveUploadedFile($source, $file_info["name"], $importfile);
4347  ilUtil::unzip($importfile);
4348  $found = $this->locateImportFiles($import_dir);
4349  if (!((strlen($found["dir"]) > 0) && (strlen($found["xml"]) > 0)))
4350  {
4351  $error = $this->lng->txt("wrong_import_file_structure");
4352  return $error;
4353  }
4354  $importfile = $found["xml"];
4355  $import_subdir = $found["dir"];
4356  }
4357  else
4358  {
4359  $importfile = tempnam($import_dir, "survey_import");
4360  ilUtil::moveUploadedFile($source, $file_info["name"], $importfile);
4361  }
4362  $fh = fopen($importfile, "r");
4363  if (!$fh)
4364  {
4365  $error = $this->lng->txt("import_error_opening_file");
4366  return $error;
4367  }
4368  $xml = fread($fh, filesize($importfile));
4369  $result = fclose($fh);
4370  if (!$result)
4371  {
4372  $error = $this->lng->txt("import_error_closing_file");
4373  return $error;
4374  }
4375 
4376  unset($_SESSION["import_mob_xhtml"]);
4377  if (strpos($xml, "questestinterop"))
4378  {
4379  include_once "./Services/Survey/classes/class.SurveyImportParserPre38.php";
4380  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
4381  $spl = new ilObjSurveyQuestionPool($survey_questionpool_id, FALSE);
4382  $import = new SurveyImportParserPre38($spl, "", TRUE);
4383  $import->setSurveyObject($this);
4384  $import->setXMLContent($xml);
4385  $import->startParsing();
4386  }
4387  else
4388  {
4389  include_once "./Services/Survey/classes/class.SurveyImportParser.php";
4390  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
4391  $spl = new ilObjSurveyQuestionPool($survey_questionpool_id, FALSE);
4392  $import = new SurveyImportParser($spl, "", TRUE);
4393  $import->setSurveyObject($this);
4394  $import->setXMLContent($xml);
4395  $import->startParsing();
4396  }
4397 
4398  if (is_array($_SESSION["import_mob_xhtml"]))
4399  {
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)
4404  {
4405  $importfile = $import_subdir . "/" . $mob["uri"];
4406  if (file_exists($importfile))
4407  {
4408  $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
4409  ilObjMediaObject::_saveUsage($media_object->getId(), "svy:html", $this->getId());
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()));
4412  }
4413  else
4414  {
4415  global $ilLog;
4416  $ilLog->write("Error: Could not open XHTML mob file for test introduction during test import. File $importfile does not exist!");
4417  }
4418  }
4421  $this->saveToDb();
4422  }
4423 
4424  // delete import directory
4426  }
4427  return $error;
4428  }
4429 
4438  function &_getAvailableSurveys($use_object_id = false)
4439  {
4440  global $ilUser;
4441  global $ilDB;
4442 
4443  $result_array = array();
4444  $surveys = ilUtil::_getObjectsByOperations("svy","write", $ilUser->getId(), -1);
4445  if (count($surveys))
4446  {
4447  $titles = ilObject::_prepareCloneSelection($surveys, "svy");
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)
4450  );
4451  $result = $ilDB->query($query);
4452  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
4453  {
4454  if ($use_object_id)
4455  {
4456  $result_array[$row["obj_id"]] = $titles[$row["ref_id"]];
4457  }
4458  else
4459  {
4460  $result_array[$row["ref_id"]] = $titles[$row["ref_id"]];
4461  }
4462  }
4463  }
4464  return $result_array;
4465  }
4466 
4475  public function cloneObject($a_target_id,$a_copy_id = 0)
4476  {
4477  global $ilDB;
4478 
4479  $this->loadFromDb();
4480 
4481  // Copy settings
4482  $newObj = parent::cloneObject($a_target_id,$a_copy_id);
4483  $this->cloneMetaData($newObj);
4484 
4485  $newObj->author = $this->getAuthor();
4486  $newObj->introduction = $this->getIntroduction();
4487  $newObj->outro = $this->getOutro();
4488  $newObj->status = $this->getStatus();
4489  $newObj->evaluation_access = $this->getEvaluationAccess();
4490  $newObj->start_date = $this->getStartDate();
4491  $newObj->startdate_enabled = $this->getStartDateEnabled();
4492  $newObj->end_date = $this->getEndDate();
4493  $newObj->enddate_enabled = $this->getEndDateEnabled();
4494  $newObj->invitation = $this->getInvitation();
4495  $newObj->invitation_mode = $this->getInvitationMode();
4496  $newObj->anonymize = $this->getAnonymize();
4497 
4498  $question_pointer = array();
4499  // clone the questions
4500  $mapping = array();
4501  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
4502  foreach ($this->questions as $key => $question_id)
4503  {
4504  $question = ilObjSurvey::_instanciateQuestion($question_id);
4505  $question->id = -1;
4506  $original_id = SurveyQuestion::_getOriginalId($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();
4511  }
4512 
4513  $newObj->saveToDb();
4514  $newObj->cloneTextblocks($mapping);
4515 
4516  // clone the questionblocks
4517  $questionblocks = array();
4518  $questionblock_questions = array();
4519  $query = sprintf("SELECT * FROM survey_questionblock_question WHERE survey_fi = %s",
4520  $ilDB->quote($this->getSurveyId() . "")
4521  );
4522  $result = $ilDB->query($query);
4523  if ($result->numRows() > 0)
4524  {
4525  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
4526  {
4527  array_push($questionblock_questions, $row);
4528  $questionblocks[$row["questionblock_fi"]] = $row["questionblock_fi"];
4529  }
4530  }
4531  // create new questionblocks
4532  foreach ($questionblocks as $key => $value)
4533  {
4534  $questionblock = ilObjSurvey::_getQuestionblock($key);
4535  $questionblock_id = ilObjSurvey::_addQuestionblock($questionblock["title"], $questionblock["owner_fi"]);
4536  $questionblocks[$key] = $questionblock_id;
4537  }
4538  // create new questionblock questions
4539  foreach ($questionblock_questions as $key => $value)
4540  {
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"]] . "")
4545  );
4546  $cloneresult = $ilDB->query($clonequery);
4547  }
4548 
4549  // clone the constraints
4550  $constraints = ilObjSurvey::_getConstraints($this->getSurveyId());
4551  foreach ($constraints as $key => $constraint)
4552  {
4553  $newObj->addConstraint($question_pointer[$constraint["for_question"]], $question_pointer[$constraint["question"]], $constraint["relation_id"], $constraint["value"]);
4554  }
4555 
4556  // clone the obligatory states
4557  $query = sprintf("SELECT * FROM survey_question_obligatory WHERE survey_fi = %s",
4558  $ilDB->quote($this->getSurveyId() . "")
4559  );
4560  $result = $ilDB->query($query);
4561  if ($result->numRows() > 0)
4562  {
4563  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
4564  {
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"])
4569  );
4570  $cloneresult = $ilDB->query($clonequery);
4571  }
4572  }
4573  return $newObj;
4574  }
4575 
4576  function getTextblock($question_id)
4577  {
4578  global $ilDB;
4579  $query = sprintf("SELECT * FROM survey_survey_question WHERE question_fi = %s",
4580  $ilDB->quote($question_id . "")
4581  );
4582  $result = $ilDB->query($query);
4583  if ($result->numRows())
4584  {
4585  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
4586  return $row["heading"];
4587  }
4588  else
4589  {
4590  return "";
4591  }
4592  }
4593 
4601  function cloneTextblocks($mapping)
4602  {
4603  foreach ($mapping as $original_id => $new_id)
4604  {
4605  $textblock = $this->getTextblock($original_id);
4606  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
4607  $this->saveHeading(ilUtil::stripSlashes($textblock, TRUE, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey")), $new_id);
4608  }
4609  }
4610 
4617  {
4618  include_once "./Services/Utilities/classes/class.ilUtil.php";
4619  $svy_data_dir = ilUtil::getDataDir()."/svy_data";
4620  ilUtil::makeDir($svy_data_dir);
4621  if(!is_writable($svy_data_dir))
4622  {
4623  $this->ilias->raiseError("Survey Data Directory (".$svy_data_dir
4624  .") not writeable.",$this->ilias->error_obj->FATAL);
4625  }
4626 
4627  // create learning module directory (data_dir/lm_data/lm_<id>)
4628  $svy_dir = $svy_data_dir."/svy_".$this->getId();
4629  ilUtil::makeDir($svy_dir);
4630  if(!@is_dir($svy_dir))
4631  {
4632  $this->ilias->raiseError("Creation of Survey Directory failed.",$this->ilias->error_obj->FATAL);
4633  }
4634  // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
4635  $export_dir = $svy_dir."/export";
4636  ilUtil::makeDir($export_dir);
4637  if(!@is_dir($export_dir))
4638  {
4639  $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
4640  }
4641  }
4642 
4647  {
4648  include_once "./Services/Utilities/classes/class.ilUtil.php";
4649  $export_dir = ilUtil::getDataDir()."/svy_data"."/svy_".$this->getId()."/export";
4650 
4651  return $export_dir;
4652  }
4653 
4658  {
4659  // quit if import dir not available
4660  if (!@is_dir($dir) or
4661  !is_writeable($dir))
4662  {
4663  return array();
4664  }
4665 
4666  // open directory
4667  $dir = dir($dir);
4668 
4669  // initialize array
4670  $file = array();
4671 
4672  // get files and save the in the array
4673  while ($entry = $dir->read())
4674  {
4675  if ($entry != "." and
4676  $entry != ".." and
4677  ereg("^[0-9]{10}_{2}[0-9]+_{2}(survey__)*[0-9]+\.xml|zip\$", $entry))
4678  {
4679  $file[] = $entry;
4680  }
4681  }
4682 
4683  // close import directory
4684  $dir->close();
4685  // sort files
4686  sort ($file);
4687  reset ($file);
4688 
4689  return $file;
4690  }
4691 
4698  {
4699  include_once "./Services/Utilities/classes/class.ilUtil.php";
4700  $svy_data_dir = ilUtil::getDataDir()."/svy_data";
4701  ilUtil::makeDir($svy_data_dir);
4702 
4703  if(!is_writable($svy_data_dir))
4704  {
4705  $this->ilias->raiseError("Survey Data Directory (".$svy_data_dir
4706  .") not writeable.",$this->ilias->error_obj->FATAL);
4707  }
4708 
4709  // create test directory (data_dir/svy_data/svy_<id>)
4710  $svy_dir = $svy_data_dir."/svy_".$this->getId();
4711  ilUtil::makeDir($svy_dir);
4712  if(!@is_dir($svy_dir))
4713  {
4714  $this->ilias->raiseError("Creation of Survey Directory failed.",$this->ilias->error_obj->FATAL);
4715  }
4716 
4717  // create import subdirectory (data_dir/svy_data/svy_<id>/import)
4718  $import_dir = $svy_dir."/import";
4719  ilUtil::makeDir($import_dir);
4720  if(!@is_dir($import_dir))
4721  {
4722  $this->ilias->raiseError("Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
4723  }
4724  }
4725 
4730  {
4731  include_once "./Services/Utilities/classes/class.ilUtil.php";
4732  $import_dir = ilUtil::getDataDir()."/svy_data".
4733  "/svy_".$this->getId()."/import";
4734  if (!is_dir($import_dir))
4735  {
4736  ilUtil::makeDirParents($import_dir);
4737  }
4738  if(@is_dir($import_dir))
4739  {
4740  return $import_dir;
4741  }
4742  else
4743  {
4744  return false;
4745  }
4746  }
4747 
4748  function saveHeading($heading = "", $insertbefore)
4749  {
4750  global $ilDB;
4751  if ($heading)
4752  {
4753  $query = sprintf("UPDATE survey_survey_question SET heading=%s WHERE survey_fi=%s AND question_fi=%s",
4754  $ilDB->quote($heading),
4755  $ilDB->quote($this->getSurveyId() . ""),
4756  $ilDB->quote($insertbefore)
4757  );
4758  }
4759  else
4760  {
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)
4764  );
4765  }
4766  $ilDB->query($query);
4767  }
4768 
4769  function _getRefIdFromObjId($obj_id)
4770  {
4771  global $ilDB;
4772 
4773  $query = sprintf("SELECT ref_id FROM object_reference WHERE obj_id=%s",
4774  $ilDB->quote($obj_id)
4775 
4776  );
4777  $result = $ilDB->query($query);
4778  if ($result->numRows())
4779  {
4780  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
4781  return $row["ref_id"];
4782  }
4783  return 0;
4784  }
4785 
4786  function isAnonymousKey($key)
4787  {
4788  global $ilDB;
4789 
4790  $query = sprintf("SELECT anonymous_id FROM survey_anonymous WHERE survey_key = %s AND survey_fi = %s",
4791  $ilDB->quote($key . ""),
4792  $ilDB->quote($this->getSurveyId() . "")
4793  );
4794  $result = $ilDB->query($query);
4795  if ($result->numRows() == 1)
4796  {
4797  return true;
4798  }
4799  else
4800  {
4801  return false;
4802  }
4803  }
4804 
4805  function getUserSurveyCode($user_id)
4806  {
4807  global $ilDB;
4808 
4809  if (($user_id == ANONYMOUS_USER_ID) || (($this->isAccessibleWithoutCode() && $this->isAllowedToTakeMultipleSurveys()))) return "";
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 . "")
4813  );
4814  $result = $ilDB->query($query);
4815  if ($result->numRows() == 1)
4816  {
4817  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
4818  return $row["anonymous_id"];
4819  }
4820  else
4821  {
4822  return "";
4823  }
4824  }
4825 
4827  {
4828  global $ilDB;
4829 
4830  $query = sprintf("SELECT finished_id FROM survey_finished WHERE anonymous_id = %s AND survey_fi = %s",
4831  $ilDB->quote($key . ""),
4832  $ilDB->quote($this->getSurveyId() . "")
4833  );
4834  $result = $ilDB->query($query);
4835  if ($result->numRows() == 1)
4836  {
4837  return true;
4838  }
4839  else
4840  {
4841  return false;
4842  }
4843  }
4844 
4845  function checkSurveyCode($code)
4846  {
4847  if ($this->isAnonymousKey($code))
4848  {
4849  if ($this->isSurveyStarted("", $code) == 1)
4850  {
4851  return false;
4852  }
4853  else
4854  {
4855  return true;
4856  }
4857  }
4858  else
4859  {
4860  return false;
4861  }
4862  }
4863 
4873  {
4874  global $ilDB;
4875 
4876  $query = sprintf("SELECT anonymous_id FROM survey_anonymous WHERE survey_fi = %s AND ISNULL(user_key)",
4877  $ilDB->quote($this->getSurveyId() . "")
4878  );
4879  $result = $ilDB->query($query);
4880  return $result->numRows();
4881  }
4882 
4892  function getSurveyCodesForExport($a_array)
4893  {
4894  global $ilDB;
4895 
4896 /* $query = sprintf("SELECT * FROM survey_anonymous WHERE survey_fi = %s AND ISNULL(user_key)",
4897  $ilDB->quote($this->getSurveyId() . "")
4898  );
4899 */
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() . "")
4902  );
4903  $result = $ilDB->query($query);
4904 
4905 
4906  $result = $ilDB->query($query);
4907  $export = "";
4908  $lang = ($_POST["lang"] != 1) ? "&amp;lang=" . $_POST["lang"] : "";
4909  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
4910  {
4911  if (in_array($row["survey_key"], $a_array) || (count($a_array) == 0))
4912  {
4913  $export .= $row["survey_key"] . ",";
4914 
4915  // No relative (today, tomorrow...) dates in export.
4916  $date = new ilDate($row['timestamp14'],IL_CAL_TIMESTAMP);
4917  $created = $date->get(IL_CAL_DATE);
4918  $export .= "$created,";
4919  if ($this->isSurveyCodeUsed($row["survey_key"]))
4920  {
4921  $export .= "1,";
4922  }
4923  else
4924  {
4925  $export .= "0,";
4926  }
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";
4929  }
4930  }
4931  return $export;
4932  }
4933 
4945  function &getSurveyCodesTableData($lang = "en", $offset = 0, $limit = 10)
4946  {
4947  global $ilDB;
4948 
4949  include_once "./classes/class.ilFormat.php";
4950  if (strlen($lang) == 0) $lang = "en";
4951  if (strlen($offset) == 0) $offset = 0;
4952  if (strlen($limit) == 0) $limit = 10;
4953 
4954  $order = "ORDER BY timestamp14, survey_key ASC";
4955  $codes = array();
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() . "")
4958  );
4959  $result = $ilDB->query($query);
4960  $counter = $offset+1;
4961  if ($result->numRows() > 0)
4962  {
4963  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
4964  {
4965  $created = ilDatePresentation::formatDate(new ilDateTime($row["timestamp14"],IL_CAL_TIMESTAMP));
4966 
4967  $url = "";
4968 
4969  $state = "<span class=\"smallred\">" . $this->lng->txt("not_used") . "</span>";
4970  if ($this->isSurveyCodeUsed($row["survey_key"]))
4971  {
4972  $state = "<span class=\"smallgreen\">" . $this->lng->txt("used") . "</span>";
4973  }
4974  else
4975  {
4976  $addlang = "";
4977  if (strlen($lang))
4978  {
4979  $addlang = "&amp;lang=$lang";
4980  }
4981  $url = "<a href=\"" . ILIAS_HTTP_PATH."/goto.php?cmd=infoScreen&target=svy_".$this->getRefId() . "&amp;client_id=" . CLIENT_ID . "&amp;accesscode=".$row["survey_key"].$addlang . "\">";
4982  $url .= $this->lng->txt("survey_code_url_name");
4983  $url .= "</a>";
4984  }
4985  $counter = "<input type=\"checkbox\" name=\"chb_code[]\" value=\"" . $row["survey_key"] . "\"/>";
4986  array_push($codes, array($counter, $row["survey_key"], $created, $state, $url));
4987  $counter++;
4988  }
4989  }
4990  return $codes;
4991  }
4992 
4993  function isSurveyCodeUsed($code)
4994  {
4995  global $ilDB;
4996  $query = sprintf("SELECT finished_id FROM survey_finished WHERE survey_fi = %s AND anonymous_id = %s",
4997  $ilDB->quote($this->getSurveyId() . ""),
4998  $ilDB->quote($code)
4999  );
5000  $result = $ilDB->query($query);
5001  if ($result->numRows() > 0)
5002  {
5003  return TRUE;
5004  }
5005  else
5006  {
5007  return FALSE;
5008  }
5009  }
5010 
5011  function createSurveyCodes($nrOfCodes)
5012  {
5013  global $ilDB;
5014  for ($i = 0; $i < $nrOfCodes; $i++)
5015  {
5016  $anonymize_key = $this->createNewAccessCode();
5017  $query = sprintf("INSERT INTO survey_anonymous (anonymous_id, survey_key, survey_fi, TIMESTAMP) VALUES (NULL, %s, %s, NULL)",
5018  $ilDB->quote($anonymize_key . ""),
5019  $ilDB->quote($this->getSurveyId() . "")
5020  );
5021  $result = $ilDB->query($query);
5022  }
5023  }
5024 
5032  function deleteSurveyCode($survey_code)
5033  {
5034  global $ilDB;
5035 
5036  if (strlen($survey_code) > 0)
5037  {
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)
5041  );
5042  $ilDB->query($query);
5043  }
5044  }
5045 
5054  function getUserAccessCode($user_id)
5055  {
5056  global $ilDB;
5057  $access_code = "";
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))
5061  );
5062  $result = $ilDB->query($query);
5063  if ($result->numRows())
5064  {
5065  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
5066  $access_code = $row["survey_key"];
5067  }
5068  return $access_code;
5069  }
5070 
5079  function saveUserAccessCode($user_id, $access_code)
5080  {
5081  global $ilDB;
5082  $query = sprintf("INSERT INTO survey_anonymous (survey_key, survey_fi, user_key) VALUES (%s, %s, %s)",
5083  $ilDB->quote($access_code . ""),
5084  $ilDB->quote($this->getSurveyId() . ""),
5085  $ilDB->quote(md5($user_id) . "")
5086  );
5087  $result = $ilDB->query($query);
5088  }
5089 
5096  {
5097  // create a 5 character code
5098  $codestring = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
5099  mt_srand();
5100  $code = "";
5101  for ($i = 1; $i <=5; $i++)
5102  {
5103  $index = mt_rand(0, strlen($codestring)-1);
5104  $code .= substr($codestring, $index, 1);
5105  }
5106  // verify it against the database
5107  while ($this->isSurveyCodeUsed($code))
5108  {
5109  $code = $this->createNewAccessCode();
5110  }
5111  return $code;
5112  }
5113 
5114 
5127  function &processCSVRow($row, $quoteAll = FALSE, $separator = ";")
5128  {
5129  $resultarray = array();
5130  foreach ($row as $rowindex => $entry)
5131  {
5132  $surround = FALSE;
5133  if ($quoteAll)
5134  {
5135  $surround = TRUE;
5136  }
5137  if (strpos($entry, "\"") !== FALSE)
5138  {
5139  $entry = str_replace("\"", "\"\"", $entry);
5140  $surround = TRUE;
5141  }
5142  if (strpos($entry, $separator) !== FALSE)
5143  {
5144  $surround = TRUE;
5145  }
5146  // replace all CR LF with LF (for Excel for Windows compatibility
5147  $entry = str_replace(chr(13).chr(10), chr(10), $entry);
5148  if ($surround)
5149  {
5150  $resultarray[$rowindex] = utf8_decode("\"" . $entry . "\"");
5151  }
5152  else
5153  {
5154  $resultarray[$rowindex] = utf8_decode($entry);
5155  }
5156  }
5157  return $resultarray;
5158  }
5159 
5160  function _getLastAccess($finished_id)
5161  {
5162  global $ilDB;
5163 
5164  $query = sprintf("SELECT TIMESTAMP+0 AS timestamp14 FROM survey_answer WHERE active_fi = %s ORDER BY TIMESTAMP DESC",
5165  $ilDB->quote($finished_id . "")
5166  );
5167  $result = $ilDB->query($query);
5168  if ($result->numRows())
5169  {
5170  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
5171  return $row["timestamp14"];
5172  }
5173  else
5174  {
5175  $query = sprintf("SELECT TIMESTAMP+0 AS timestamp14 FROM survey_finished WHERE finished_id = %s",
5176  $ilDB->quote($finished_id . "")
5177  );
5178  $result = $ilDB->query($query);
5179  if ($result->numRows())
5180  {
5181  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
5182  return $row["timestamp14"];
5183  }
5184  }
5185  return "";
5186  }
5187 
5194  function prepareTextareaOutput($txt_output)
5195  {
5196  include_once "./Services/Utilities/classes/class.ilUtil.php";
5197  return ilUtil::prepareTextareaOutput($txt_output, $prepare_for_latex_output);
5198  }
5199 
5207  function isHTML($a_text)
5208  {
5209  if (preg_match("/<[^>]*?>/", $a_text))
5210  {
5211  return TRUE;
5212  }
5213  else
5214  {
5215  return FALSE;
5216  }
5217  }
5218 
5227  function addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag = TRUE, $add_mobs = TRUE, $attribs = NULL)
5228  {
5229  include_once "./Services/RTE/classes/class.ilRTE.php";
5230  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
5231 
5232  $a_xml_writer->xmlStartTag("material", $attribs);
5233  $attrs = array(
5234  "type" => "text/plain"
5235  );
5236  if ($this->isHTML($a_material))
5237  {
5238  $attrs["type"] = "text/xhtml";
5239  }
5240  $mattext = ilRTE::_replaceMediaObjectImageSrc($a_material, 0);
5241  $a_xml_writer->xmlElement("mattext", $attrs, $mattext);
5242 
5243  if ($add_mobs)
5244  {
5245  $mobs = ilObjMediaObject::_getMobsOfObject("svy:html", $this->getId());
5246  foreach ($mobs as $mob)
5247  {
5248  $mob_id = "il_" . IL_INST_ID . "_mob_" . $mob;
5249  if (strpos($mattext, $mob_id) !== FALSE)
5250  {
5251  $mob_obj =& new ilObjMediaObject($mob);
5252  $imgattrs = array(
5253  "label" => $mob_id,
5254  "uri" => "objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle()
5255  );
5256  $a_xml_writer->xmlElement("matimage", $imgattrs, NULL);
5257  }
5258  }
5259  }
5260  if ($close_material_tag) $a_xml_writer->xmlEndTag("material");
5261  }
5262 
5272  {
5273  if ($this->getAnonymize() != ANONYMIZE_OFF)
5274  {
5275  if ($this->surveyCodeSecurity == FALSE)
5276  {
5277  return TRUE;
5278  }
5279  }
5280  return FALSE;
5281  }
5282 
5292  function processPrintoutput2FO($print_output)
5293  {
5294  $print_output = str_replace("&nbsp;", "&#160;", $print_output);
5295  $print_output = str_replace("&otimes;", "X", $print_output);
5296  $xsl = file_get_contents("./Modules/Survey/xml/question2fo.xsl");
5297  $args = array( '/_xml' => $print_output, '/_xsl' => $xsl );
5298  $xh = xslt_create();
5299  $params = array();
5300  $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, $params);
5301  xslt_error($xh);
5302  xslt_free($xh);
5303  global $ilLog; $ilLog->write($output);
5304  return $output;
5305  }
5306 
5315  function deliverPDFfromFO($fo)
5316  {
5317  include_once "./Services/Utilities/classes/class.ilUtil.php";
5318  $fo_file = ilUtil::ilTempnam() . ".fo";
5319  $fp = fopen($fo_file, "w"); fwrite($fp, $fo); fclose($fp);
5320  include_once "./Services/Transformation/classes/class.ilFO2PDF.php";
5321  $fo2pdf = new ilFO2PDF();
5322  $fo2pdf->setFOString($fo);
5323  $result = $fo2pdf->send();
5324  ilUtil::deliverData($result, ilUtil::getASCIIFilename($this->getTitle()) . ".pdf", "application/pdf");
5325  }
5326 
5327  function _checkCondition($a_svy_id,$a_operator,$a_value,$a_usr_id = 0)
5328  {
5329  global $ilUser;
5330 
5331  $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
5332 
5333  switch($a_operator)
5334  {
5335  case 'finished':
5336  //if (ilExerciseMembers::_lookupStatus($a_exc_id, $ilias->account->getId()) == "passed")
5337  include_once("./Modules/Survey/classes/class.ilObjSurveyAccess.php");
5338  if (ilObjSurveyAccess::_lookupFinished($a_svy_id, $a_usr_id))
5339  {
5340  return true;
5341  }
5342  else
5343  {
5344  return false;
5345  }
5346  break;
5347 
5348  default:
5349  return true;
5350  }
5351  return true;
5352  }
5353 
5360  function isPluginActive($a_pname)
5361  {
5362  global $ilPluginAdmin;
5363  if ($ilPluginAdmin->isActive(IL_COMP_MODULE, "SurveyQuestionPool", "svyq", $a_pname))
5364  {
5365  return TRUE;
5366  }
5367  else
5368  {
5369  return FALSE;
5370  }
5371  }
5372 } // END class.ilObjSurvey
5373 ?>