/** * Restore surveys */ function restore_surveys() { if ($this->course->has_resources(RESOURCE_SURVEY)) { $table_sur = Database::get_course_table(TABLE_SURVEY); $table_que = Database::get_course_table(TABLE_SURVEY_QUESTION); $table_ans = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION); $resources = $this->course->resources; foreach ($resources[RESOURCE_SURVEY] as $id => $survey) { $sql_check = 'SELECT survey_id FROM ' . $table_sur . ' WHERE c_id = ' . $this->destination_course_id . ' AND code = "' . self::DBUTF8escapestring($survey->code) . '" AND lang = "' . self::DBUTF8escapestring($survey->lang) . '" '; $result_check = Database::query($sql_check); // check resources inside html from fckeditor tool and copy correct urls into recipient course $survey->title = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->title, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']); $survey->subtitle = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->subtitle, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']); $survey->intro = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->intro, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']); $survey->surveythanks = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->surveythanks, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']); $sql = "INSERT INTO " . $table_sur . " " . "SET\n\t\t\t\t\t\tc_id = " . $this->destination_course_id . " ,\n\t\t\t\t\t\tcode = '" . self::DBUTF8escapestring($survey->code) . "', " . "title = '" . self::DBUTF8escapestring($survey->title) . "', " . "subtitle = '" . self::DBUTF8escapestring($survey->subtitle) . "', " . "author = '" . self::DBUTF8escapestring($survey->author) . "', " . "lang = '" . self::DBUTF8escapestring($survey->lang) . "', " . "avail_from = '" . self::DBUTF8escapestring($survey->avail_from) . "', " . "avail_till = '" . self::DBUTF8escapestring($survey->avail_till) . "', " . "is_shared = '" . self::DBUTF8escapestring($survey->is_shared) . "', " . "template = '" . self::DBUTF8escapestring($survey->template) . "', " . "intro = '" . self::DBUTF8escapestring($survey->intro) . "', " . "surveythanks = '" . self::DBUTF8escapestring($survey->surveythanks) . "', " . "creation_date = '" . self::DBUTF8escapestring($survey->creation_date) . "', " . "invited = '0', " . "answered = '0', " . "invite_mail = '" . self::DBUTF8escapestring($survey->invite_mail) . "', " . "reminder_mail = '" . self::DBUTF8escapestring($survey->reminder_mail) . "'"; //An existing survey exists with the same code and the same language if (Database::num_rows($result_check) == 1) { switch ($this->file_option) { case FILE_SKIP: //Do nothing break; case FILE_RENAME: $survey_code = $survey->code . '_'; $i = 1; $temp_survey_code = $survey_code . $i; while (!$this->is_survey_code_available($temp_survey_code)) { $temp_survey_code = $survey_code . ++$i; } $survey_code = $temp_survey_code; $sql = "INSERT INTO " . $table_sur . " " . "SET\n\t\t\t\t\t\t\t\t\tc_id = " . $this->destination_course_id . " ,\n\t\t\t\t\t\t\t\t\tcode = '" . self::DBUTF8escapestring($survey_code) . "', " . "title = '" . self::DBUTF8escapestring($survey->title) . "', " . "subtitle = '" . self::DBUTF8escapestring($survey->subtitle) . "', " . "author = '" . self::DBUTF8escapestring($survey->author) . "', " . "lang = '" . self::DBUTF8escapestring($survey->lang) . "', " . "avail_from = '" . self::DBUTF8escapestring($survey->avail_from) . "', " . "avail_till = '" . self::DBUTF8escapestring($survey->avail_till) . "', " . "is_shared = '" . self::DBUTF8escapestring($survey->is_shared) . "', " . "template = '" . self::DBUTF8escapestring($survey->template) . "', " . "intro = '" . self::DBUTF8escapestring($survey->intro) . "', " . "surveythanks = '" . self::DBUTF8escapestring($survey->surveythanks) . "', " . "creation_date = '" . self::DBUTF8escapestring($survey->creation_date) . "', " . "invited = '0', " . "answered = '0', " . "invite_mail = '" . self::DBUTF8escapestring($survey->invite_mail) . "', " . "reminder_mail = '" . self::DBUTF8escapestring($survey->reminder_mail) . "'"; //Insert the new source survey Database::query($sql); $new_id = Database::insert_id(); $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id; foreach ($survey->question_ids as $index => $question_id) { $qid = $this->restore_survey_question($question_id, $new_id); $sql = "UPDATE " . $table_que . " SET survey_id = " . $new_id . " WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}"; Database::query($sql); $sql = "UPDATE " . $table_ans . " SET survey_id = " . $new_id . " WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}"; Database::query($sql); } break; case FILE_OVERWRITE: // Delete the existing survey with the same code and language and import the one of the source course // getting the information of the survey (used for when the survey is shared) require_once api_get_path(SYS_CODE_PATH) . 'survey/survey.lib.php'; $sql_select_existing_survey = "SELECT * FROM {$table_sur} WHERE c_id = " . $this->destination_course_id . " AND survey_id='" . self::DBUTF8escapestring(Database::result($result_check, 0, 0)) . "'"; $result = Database::query($sql_select_existing_survey); $survey_data = Database::fetch_array($result, 'ASSOC'); // if the survey is shared => also delete the shared content if (is_numeric($survey_data['survey_share'])) { survey_manager::delete_survey($survey_data['survey_share'], true, $this->destination_course_id); } $return = survey_manager::delete_survey($survey_data['survey_id'], false, $this->destination_course_id); //Insert the new source survey Database::query($sql); $new_id = Database::insert_id(); $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id; foreach ($survey->question_ids as $index => $question_id) { $qid = $this->restore_survey_question($question_id, $new_id); $sql = "UPDATE {$table_que} SET survey_id = {$new_id} WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}"; Database::query($sql); $sql = "UPDATE {$table_ans} SET survey_id = {$new_id} WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}"; Database::query($sql); } break; default: break; } } else { Database::query($sql); $new_id = Database::insert_id(); $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id; foreach ($survey->question_ids as $index => $question_id) { $qid = $this->restore_survey_question($question_id, $new_id); $sql = "UPDATE {$table_que} SET survey_id = {$new_id} WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}"; Database::query($sql); $sql = "UPDATE {$table_ans} SET survey_id = {$new_id} WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}"; Database::query($sql); } } } } }
} else { Display::display_error_message(get_lang('ErrorOccurred'), false); } } // Action handling: performing the same action on multiple surveys if (isset($_POST['action']) && $_POST['action']) { if (is_array($_POST['id'])) { foreach ($_POST['id'] as $key => &$value) { // getting the information of the survey (used for when the survey is shared) $survey_data = survey_manager::get_survey($value); // if the survey is shared => also delete the shared content if (is_numeric($survey_data['survey_share'])) { survey_manager::delete_survey($survey_data['survey_share'], true); } // delete the actual survey survey_manager::delete_survey($value); } Display::display_confirmation_message(get_lang('SurveysDeleted'), false); } else { Display::display_error_message(get_lang('NoSurveysSelected'), false); } } echo '<div class="actions">'; if (!api_is_course_coach() || $extend_rights_for_coachs == 'true') { // Action links echo '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/create_new_survey.php?' . api_get_cidreq() . '&action=add">' . Display::return_icon('new_survey.png', get_lang('CreateNewSurvey'), '', ICON_SIZE_MEDIUM) . '</a> '; } echo '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&search=advanced">' . Display::return_icon('search.png', get_lang('Search'), '', ICON_SIZE_MEDIUM) . '</a>'; echo '</div>'; // Load main content if (api_is_course_coach() && $extend_rights_for_coachs == 'false') {