addSelect( 'parent_id', get_lang('Parent'), $options, ['id' => 'parent_id', 'placeholder' => get_lang('SelectAnOption')] ); $url = api_get_path(WEB_AJAX_PATH). 'survey.ajax.php?'.api_get_cidreq().'&a=load_question_options&survey_id='.$surveyId; $form->addHtml(' '); $style = 'display:none'; $options = []; if (!empty($optionId) && !empty($parentId)) { $parentData = SurveyManager::get_question($parentId); $style = ''; foreach ($parentData['answer_data'] as $answer) { $options[$answer['iid']] = strip_tags($answer['data']); } } $form->addHtml('
'); $form->addSelect( 'parent_option_id', get_lang('Option'), $options, ['id' => 'parent_option_id', 'disable_js' => true] ); $form->addHtml('
'); } /** * @param string $type * * @return survey_question */ public static function createQuestion($type) { switch ($type) { case 'comment': return new ch_comment(); case 'dropdown': return new ch_dropdown(); case 'multiplechoice': return new ch_multiplechoice(); case 'multipleresponse': return new ch_multipleresponse(); case 'open': return new ch_open(); case 'pagebreak': return new ch_pagebreak(); case 'percentage': return new ch_percentage(); case 'personality': return new ch_personality(); case 'score': return new ch_score(); case 'yesno': return new ch_yesno(); case 'selectivedisplay': return new ch_selectivedisplay(); case 'multiplechoiceother': return new ch_multiplechoiceother(); default: api_not_allowed(true); break; } } /** * Generic part of any survey question: the question field. * * @param array $surveyData * @param array $formData * * @return FormValidator */ public function createForm($surveyData, $formData) { $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null; $questionId = isset($_GET['question_id']) ? (int) $_GET['question_id'] : null; $surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : null; $type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : null; $actionHeader = get_lang('EditQuestion').': '; if ($action === 'add') { $actionHeader = get_lang('AddQuestion').': '; } $questionComment = ''; $allowParent = false; switch ($type) { case 'open': $toolName = get_lang('Open'); $questionComment = get_lang('QuestionTags'); $allowParent = true; break; case 'yesno': $toolName = get_lang('YesNo'); $allowParent = true; break; case 'multiplechoice': $toolName = get_lang('UniqueSelect'); $allowParent = true; break; case 'multipleresponse': $toolName = get_lang('MultipleResponse'); $allowParent = true; break; case 'selectivedisplay': $toolName = get_lang('SurveyQuestionSelectiveDisplay'); $questionComment = get_lang('SurveyQuestionSelectiveDisplayComment'); $allowParent = true; break; case 'multiplechoiceother': $toolName = get_lang('SurveyQuestionMultipleChoiceWithOther'); $questionComment = get_lang('SurveyQuestionMultipleChoiceWithOtherComment'); $allowParent = true; break; case 'pagebreak': $toolName = get_lang(api_ucfirst($type)); $allowParent = false; break; default: $toolName = get_lang(api_ucfirst($type)); $allowParent = true; break; } if (false === api_get_configuration_value('survey_question_dependency')) { $allowParent = false; } $icon = Display::return_icon( SurveyManager::icon_question($type), $toolName, ['align' => 'middle', 'height' => '22px'] ).' '; $toolName = $icon.$actionHeader.$toolName; $sharedQuestionId = isset($formData['shared_question_id']) ? $formData['shared_question_id'] : null; $url = api_get_self().'?action='.$action.'&type='.$type.'&survey_id='.$surveyId.'&question_id='.$questionId.'&'.api_get_cidreq(); $form = new FormValidator('question_form', 'post', $url); $form->addHeader($toolName); if (!empty($questionComment)) { $form->addHtml(Display::return_message($questionComment, 'info', false)); } $form->addHidden('survey_id', $surveyId); $form->addHidden('question_id', $questionId); $form->addHidden('shared_question_id', Security::remove_XSS($sharedQuestionId)); $form->addHidden('type', $type); $config = [ 'ToolbarSet' => 'SurveyQuestion', 'Width' => '100%', 'Height' => '120', ]; $form->addHtmlEditor( 'question', get_lang('Question'), true, false, $config ); if (api_get_configuration_value('allow_required_survey_questions') && in_array($_GET['type'], ['yesno', 'multiplechoice'])) { $form->addCheckBox('is_required', get_lang('IsMandatory'), get_lang('Yes')); } if ($allowParent) { $this->addParentMenu($formData, $form, $surveyData); } if (1 == $surveyData['survey_type']) { $table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP); $sql = 'SELECT id, name FROM '.$table_survey_question_group.' WHERE survey_id = '.$surveyId.' ORDER BY name'; $rs = Database::query($sql); $glist = null; while ($row = Database::fetch_array($rs, 'NUM')) { $glist .= ''; } $grouplist = $grouplist1 = $grouplist2 = $glist; if (!empty($formData['assigned'])) { $grouplist = str_replace( '