Fix js error see #7814

1.10.x
Julio Montoya 10 years ago
parent 99bc0c43d4
commit 35e49cb6bd
  1. 4
      main/gradebook/lib/GradebookUtils.php
  2. 95
      main/survey/create_new_survey.php
  3. 57
      main/survey/survey.lib.php

@ -386,9 +386,9 @@ class GradebookUtils
*/
public static function is_resource_in_course_gradebook($course_code, $resource_type, $resource_id, $session_id = 0)
{
$l = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$course_code = Database::escape_string($course_code);
$sql = "SELECT * FROM $l l
$sql = "SELECT * FROM $table l
WHERE
course_code = '$course_code' AND
type = ".(int)$resource_type . " AND

@ -71,10 +71,16 @@ if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
$defaults['survey_id'] = $survey_id;
$defaults['anonymous'] = $survey_data['anonymous'];
$link_info = GradebookUtils::is_resource_in_course_gradebook($course_id, $gradebook_link_type, $survey_id, $session_id);
$link_info = GradebookUtils::is_resource_in_course_gradebook(
$course_id,
$gradebook_link_type,
$survey_id,
$session_id
);
$gradebook_link_id = $link_info['id'];
if ($link_info) {
$defaults['category_id'] = $link_info['category_id'];
if ($sql_result_array = Database::fetch_array(Database::query('SELECT weight FROM '.$table_gradebook_link.' WHERE id='.$gradebook_link_id))) {
$defaults['survey_qualify_gradebook'] = $gradebook_link_id;
$defaults['survey_weight'] = number_format($sql_result_array['weight'], 2, '.', '');
@ -97,7 +103,7 @@ $form = new FormValidator(
api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&survey_id='.$survey_id
);
$form->addElement('header', '', $tool_name);
$form->addElement('header', $tool_name);
// Setting the form elements
if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
@ -116,8 +122,25 @@ if ($_GET['action'] == 'edit') {
$form->applyFilter('survey_code', 'api_strtoupper');
}
$form->addElement('html_editor', 'survey_title', get_lang('SurveyTitle'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '200'));
$form->addElement('html_editor', 'survey_subtitle', get_lang('SurveySubTitle'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '100', 'ToolbarStartExpanded' => false));
$form->addElement(
'html_editor',
'survey_title',
get_lang('SurveyTitle'),
null,
array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '200')
);
$form->addElement(
'html_editor',
'survey_subtitle',
get_lang('SurveySubTitle'),
null,
array(
'ToolbarSet' => 'Survey',
'Width' => '100%',
'Height' => '100',
'ToolbarStartExpanded' => false,
)
);
// Pass the language of the survey in the form
$form->addElement('hidden', 'survey_language');
@ -145,6 +168,15 @@ if (Gradebook::is_active()) {
$form->addElement('html', '<div id="gradebook_options"'.($gradebook_link_id ? '' : ' style="display:none"').'>');
$form->addElement('text', 'survey_weight', get_lang('QualifyWeight'), 'value="0.00" style="width: 40px;" onfocus="javascript: this.select();"');
$form->applyFilter('survey_weight', 'html_filter');
// Loading Gradebook select
GradebookUtils::load_gradebook_select_in_tool($form);
if ($_GET['action'] == 'edit') {
$element = $form->getElement('category_id');
$element->freeze();
}
$form->addElement('html', '</div>');
}
@ -235,63 +267,12 @@ $form->setDefaults($defaults);
// The validation or display
if ($form->validate()) {
// Exporting the values
$values = $form->exportValues();
$values = $form->getSubmitValues();
// Storing the survey
$return = SurveyManager::store_survey($values);
if ($return['type'] == 'error') {
// Display the error
Display::display_error_message(get_lang($return['message']), false);
// Displaying the header
Display::display_header($tool_name);
// Display the form
$form->display();
} else {
$gradebook_option = false;
if (isset($values['survey_qualify_gradebook'])) {
$gradebook_option = $values['survey_qualify_gradebook'] > 0;
}
if ($gradebook_option) {
$survey_id = intval($return['id']);
if ($survey_id > 0) {
$title_gradebook = ''; // Not needed here.
$description_gradebook = ''; // Not needed here.
$survey_weight = floatval($_POST['survey_weight']);
$max_score = 1;
$date = time(); // TODO: Maybe time zones implementation is needed here.
$visible = 1; // 1 = visible
$link_info = GradebookUtils::is_resource_in_course_gradebook(
$course_id,
$gradebook_link_type,
$survey_id,
$session_id
);
$gradebook_link_id = $link_info['id'];
if (!$gradebook_link_id) {
GradebookUtils::add_resource_to_course_gradebook(
$course_id,
$gradebook_link_type,
$survey_id,
$title_gradebook,
$survey_weight,
$max_score,
$description_gradebook,
1,
$session_id
);
} else {
Database::query('UPDATE '.$table_gradebook_link.' SET weight='.$survey_weight.' WHERE id='.$gradebook_link_id);
}
}
}
}
// Redirecting to the survey page (whilst showing the return message)
header('location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$return['id'].'&message='.$return['message'].'&'.api_get_cidreq());
header('location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$return['id'].'&'.api_get_cidreq());
exit;
} else {
// Displaying the header

@ -185,6 +185,8 @@ class SurveyManager
{
$_user = api_get_user_info();
$course_id = api_get_course_int_id();
$session_id = api_get_session_id();
$courseCode = api_get_course_id();
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$shared_survey_id = 0;
@ -295,7 +297,6 @@ class SurveyManager
$extraParams['survey_version'] = $versionValue;
}
}
$course_id = api_get_course_int_id();
$params = [
'c_id' => $course_id,
@ -451,6 +452,60 @@ class SurveyManager
$return['id'] = $values['survey_id'];
}
$survey_id = intval($return['id']);
// Gradebook
$gradebook_option = false;
if (isset($values['survey_qualify_gradebook'])) {
$gradebook_option = $values['survey_qualify_gradebook'] > 0;
}
$gradebook_link_type = 8;
$link_info = GradebookUtils::is_resource_in_course_gradebook(
$courseCode,
$gradebook_link_type,
$survey_id,
$session_id
);
$gradebook_link_id = isset($link_info['id']) ? $link_info['id'] : false;
if ($gradebook_option) {
if ($survey_id > 0) {
$title_gradebook = ''; // Not needed here.
$description_gradebook = ''; // Not needed here.
$survey_weight = floatval($_POST['survey_weight']);
$max_score = 1;
if (!$gradebook_link_id) {
GradebookUtils::add_resource_to_course_gradebook(
$values['category_id'],
$courseCode,
$gradebook_link_type,
$survey_id,
$title_gradebook,
$survey_weight,
$max_score,
$description_gradebook,
1,
$session_id
);
} else {
GradebookUtils::update_resource_from_course_gradebook(
$gradebook_link_id,
$courseCode,
$survey_weight
);
}
}
} else {
// Delete everything of the gradebook for this $linkId
GradebookUtils::remove_resource_from_course_gradebook($gradebook_link_id);
exit;
}
return $return;
}

Loading…
Cancel
Save