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(); $form->addHtml(' '); $form->addHtml('
'); $form->addHidden('option_id', 0); } /** * @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(); 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; $toolName = Display::return_icon( SurveyManager::icon_question($type), get_lang(ucfirst($type)), ['align' => 'middle', 'height' => '22px'] ).' '; if ($action == 'add') { $toolName .= get_lang('AddQuestion').': '; } elseif ($action == 'edit') { $toolName .= get_lang('EditQuestion').': '; } switch ($_GET['type']) { case 'yesno': $toolName .= get_lang('YesNo'); break; case 'multiplechoice': $toolName .= get_lang('UniqueSelect'); break; case 'multipleresponse': $toolName .= get_lang('MultipleResponse'); break; default: $toolName .= get_lang(api_ucfirst($type)); } $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); $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')); } // When survey type = 1?? if ($surveyData['survey_type'] == 1) { $table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP); $sql = 'SELECT id,name FROM '.$table_survey_question_group.' WHERE survey_id = '.(int) $_GET['survey_id'].' 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( '