chamilo /
chamilo-lms
| 1 | <?php |
||
| 2 | |||
| 3 | /* For licensing terms, see /license.txt */ |
||
| 4 | |||
| 5 | require_once __DIR__.'/../inc/global.inc.php'; |
||
| 6 | |||
| 7 | $current_course_tool = TOOL_COURSE_MAINTENANCE; |
||
| 8 | |||
| 9 | api_protect_course_script(true); |
||
| 10 | |||
| 11 | // Notice for unauthorized people. |
||
| 12 | if (!api_is_allowed_to_edit()) { |
||
| 13 | api_not_allowed(true); |
||
| 14 | } |
||
| 15 | |||
| 16 | // Breadcrumbs |
||
| 17 | $interbreadcrumb[] = [ |
||
| 18 | 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(), |
||
| 19 | 'name' => get_lang('SurveyList'), |
||
| 20 | ]; |
||
| 21 | |||
| 22 | // The section (for the tabs) |
||
| 23 | $this_section = SECTION_COURSES; |
||
| 24 | |||
| 25 | $surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : 0; |
||
| 26 | |||
| 27 | if (empty($surveyId)) { |
||
| 28 | api_not_allowed(true); |
||
| 29 | } |
||
| 30 | |||
| 31 | $survey = SurveyManager::get_survey($surveyId); |
||
| 32 | if (empty($survey)) { |
||
| 33 | api_not_allowed(true); |
||
| 34 | } |
||
| 35 | |||
| 36 | $surveyTitle = str_replace(' ', '', strip_tags($survey['title'].' ('.$survey['code'].') ')); |
||
| 37 | |||
| 38 | $form = new FormValidator('copy_survey', 'post', api_get_self().'?survey_id='.$surveyId.'&'.api_get_cidreq()); |
||
| 39 | $form->addElement( |
||
| 40 | 'text', |
||
| 41 | 'survey_title', |
||
| 42 | get_lang('Survey'), |
||
| 43 | ['value' => $surveyTitle, 'disabled' => 'disabled'] |
||
| 44 | ); |
||
| 45 | $form->addSelectAjax( |
||
| 46 | 'destination_course', |
||
| 47 | get_lang('SelectDestinationCourse'), |
||
| 48 | null, |
||
| 49 | [ |
||
| 50 | 'url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=get_my_courses_and_sessions&'.api_get_cidreq(), |
||
| 51 | ] |
||
| 52 | ); |
||
| 53 | |||
| 54 | $form->addButtonCopy(get_lang('CopySurvey')); |
||
| 55 | |||
| 56 | // Add Security token |
||
| 57 | $token = Security::get_existing_token(); |
||
| 58 | $form->addElement('hidden', 'sec_token'); |
||
| 59 | $form->setConstants(['sec_token' => $token]); |
||
| 60 | |||
| 61 | // If a CourseSelectForm is posted or we should copy all resources, then copy them |
||
| 62 | if ($form->validate() && Security::check_token('post')) { |
||
| 63 | // Clear token |
||
| 64 | Security::clear_token(); |
||
| 65 | $values = $form->getSubmitValues(); |
||
| 66 | $courseKey = $values['destination_course']; |
||
| 67 | $courseParts = explode('_', $courseKey); |
||
| 68 | $courseId = $courseParts[0]; |
||
| 69 | $sessionId = $courseParts[1]; |
||
| 70 | |||
| 71 | // Copy the survey to the target course |
||
| 72 | $surveyCopyId = SurveyManager::copySurveySession($surveyId, $courseId, $sessionId); |
||
| 73 | if ($surveyCopyId) { |
||
|
0 ignored issues
–
show
|
|||
| 74 | // Empty the copied survey |
||
| 75 | SurveyManager::emptySurveyFromId($surveyCopyId); |
||
| 76 | Display::addFlash(Display::return_message(get_lang('SurveyCopied'))); |
||
| 77 | } else { |
||
| 78 | Display::addFlash(Display::return_message(get_lang('ThereWasAnError'), 'warning')); |
||
| 79 | } |
||
| 80 | |||
| 81 | header('Location: '.api_get_self().'?'.api_get_cidreq().'&survey_id='.$surveyId); |
||
| 82 | exit; |
||
| 83 | } |
||
| 84 | |||
| 85 | Display::display_header(get_lang('CopySurvey')); |
||
| 86 | echo Display::page_header(get_lang('CopySurvey')); |
||
| 87 | $form->display(); |
||
| 88 | |||
| 89 | Display::display_footer(); |
||
| 90 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: