/**
  * Restore surveys
  * @param int $sessionId Optional. The session id
  */
 public function restore_surveys($sessionId = 0)
 {
     $sessionId = intval($sessionId);
     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 = '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 resources inside html from ckeditor 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']);
             $params = ['c_id' => $this->destination_course_id, 'code' => self::DBUTF8($survey->code), 'title' => self::DBUTF8($survey->title), 'subtitle' => self::DBUTF8($survey->subtitle), 'author' => self::DBUTF8($survey->author), 'lang' => self::DBUTF8($survey->lang), 'avail_from' => self::DBUTF8($survey->avail_from), 'avail_till' => self::DBUTF8($survey->avail_till), 'is_shared' => self::DBUTF8($survey->is_shared), 'template' => self::DBUTF8($survey->template), 'intro' => self::DBUTF8($survey->intro), 'surveythanks' => self::DBUTF8($survey->surveythanks), 'creation_date' => self::DBUTF8($survey->creation_date), 'invited' => '0', 'answered' => '0', 'invite_mail' => self::DBUTF8($survey->invite_mail), 'reminder_mail' => self::DBUTF8($survey->reminder_mail), 'session_id' => $sessionId];
             //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;
                         $params['code'] = $survey_code;
                         $new_id = Database::insert($table_sur, $params);
                         if ($new_id) {
                             $sql = "UPDATE {$table_sur} SET survey_id = iid WHERE iid = {$new_id}";
                             Database::query($sql);
                             $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 . "\n\t\t\t\t\t\t\t\t            WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}";
                                 Database::query($sql);
                                 $sql = "UPDATE " . $table_ans . " SET survey_id = " . $new_id . "\n\t\t\t\t\t\t\t\t            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)
                         $sql = "SELECT * FROM {$table_sur}\n\t\t\t\t\t\t\t        WHERE\n\t\t\t\t\t\t\t            c_id = " . $this->destination_course_id . " AND\n\t\t\t\t\t\t\t            survey_id='" . self::DBUTF8escapestring(Database::result($result_check, 0, 0)) . "'";
                         $result = Database::query($sql);
                         $survey_data = Database::fetch_array($result, 'ASSOC');
                         // if the survey is shared => also delete the shared content
                         if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
                             SurveyManager::delete_survey($survey_data['survey_share'], true, $this->destination_course_id);
                         }
                         SurveyManager::delete_survey($survey_data['survey_id'], false, $this->destination_course_id);
                         // Insert the new source survey
                         $new_id = Database::insert($table_sur, $params);
                         if ($new_id) {
                             $sql = "UPDATE {$table_sur} SET survey_id = iid WHERE iid = {$new_id}";
                             Database::query($sql);
                             $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}\n                                            WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}";
                                 Database::query($sql);
                                 $sql = "UPDATE {$table_ans} SET survey_id = {$new_id}\n                                            WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}";
                                 Database::query($sql);
                             }
                         }
                         break;
                     default:
                         break;
                 }
             } else {
                 // No existing survey with the same language and the same code, we just copy the survey
                 $new_id = Database::insert($table_sur, $params);
                 if ($new_id) {
                     $sql = "UPDATE {$table_sur} SET survey_id = iid WHERE iid = {$new_id}";
                     Database::query($sql);
                     $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}\n                                    WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}";
                         Database::query($sql);
                         $sql = "UPDATE {$table_ans} SET survey_id = {$new_id}\n                                    WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}";
                         Database::query($sql);
                     }
                 }
             }
         }
     }
 }
示例#2
0
    } 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 = SurveyManager::get_survey($value);
            // if the survey is shared => also delete the shared content
            if (is_numeric($survey_data['survey_share'])) {
                SurveyManager::delete_survey($survey_data['survey_share'], true);
            }
            // delete the actual survey
            SurveyManager::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() . '&amp;action=add">' . Display::return_icon('new_survey.png', get_lang('CreateNewSurvey'), '', ICON_SIZE_MEDIUM) . '</a> ';
}
echo '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;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') {