}
echo '</div>';
if ($displayMessage != "") {
    Display::display_confirmation_message($displayMessage);
    $displayMessage = "";
}
//Form
echo '<form class="form-horizontal" name="question_pool" method="GET" action="' . $url . '">';
//Title
echo '<legend>' . $nameTools . ' - ' . $titleAdd . '</legend>';
if (isset($type)) {
    echo '<input type="hidden" name="type" value="1">';
}
echo '<input type="hidden" name="fromExercise" value="' . $fromExercise . '">';
// Session list, if sessions are used.
$session_list = SessionManager::get_sessions_by_general_coach(api_get_user_id());
$tabAttrParam = array('class' => 'chzn-select', 'onchange' => 'submit_form(this)');
// when sessions are used
$labelFormRow = get_lang('Session');
$session_select_list = array();
foreach ($session_list as $item) {
    $session_select_list[$item['id']] = $item['name'];
}
$select_session_html = Display::select('session_id', $session_select_list, $session_id, $tabAttrParam);
echo Display::form_row($labelFormRow, $select_session_html);
// hub 13-10-2011
// Course list, get course list of session, or for course where user is admin
if (!empty($session_id) && $session_id != '-1') {
    $course_list = SessionManager::get_course_list_by_session_id($session_id);
} else {
    $course_list = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
Example #2
0
 /**
  * @param string $courseCode
  * @param array $rules
  * @param array $columns
  * @param array $column_model
  * @return array
  */
 public static function getRules($courseCode, &$rules, &$columns, &$column_model, $questionFields, $checkFields = false)
 {
     // sessions
     // course
     // categories
     // exercises
     // difficult
     // type
     if (empty($courseCode)) {
         // Session.
         $sessionList = SessionManager::get_sessions_by_general_coach(api_get_user_id());
         $fields = array();
         if (!empty($sessionList)) {
             $new_options = array();
             $new_options[] = "-1:" . get_lang('All');
             foreach ($sessionList as $session) {
                 $new_options[] = "{$session['id']}:{$session['name']}";
             }
             $string = implode(';', $new_options);
             $fields[] = array('field_display_text' => get_lang('Session'), 'field_variable' => 'session_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
         }
     } else {
         // $courseList = array(api_get_course_info());
         //$courseList = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
     }
     // Courses.
     $courseList = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
     if (!empty($courseList)) {
         $new_options = array();
         $new_options[] = "-1:" . get_lang('All');
         foreach ($courseList as $course) {
             $new_options[] = "{$course['id']}:{$course['title']}";
         }
         $string = implode(';', $new_options);
         $fields[] = array('field_display_text' => get_lang('Course'), 'field_variable' => 'c_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
     }
     // Categories.
     $string = null;
     if (!empty($courseList)) {
         $new_options = array();
         $new_options[] = "-1:" . get_lang('All');
         // Global categories
         // @todo use tree view
         $categories = Testcategory::getCategoriesIdAndName(0);
         if (!empty($categories)) {
             foreach ($categories as $id => $category) {
                 if (!empty($id)) {
                     $new_options[] = "{$id}:[Global] - " . $category;
                 }
             }
         }
         foreach ($courseList as $course) {
             $categories = Testcategory::getCategoriesIdAndName($course['real_id']);
             if (!empty($categories)) {
                 foreach ($categories as $id => $category) {
                     if (!empty($id)) {
                         $new_options[] = "{$id}:" . $course['title'] . " - " . $category;
                     }
                 }
             }
         }
         $string = implode(';', $new_options);
         $fields[] = array('field_display_text' => get_lang('Category'), 'field_variable' => 'category_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
     }
     $course = api_get_course_int_id();
     $sessionId = api_get_session_id();
     // Exercises.
     $exerciseList = ExerciseLib::get_all_exercises_for_course_id($sessionId, $course);
     if (!empty($exerciseList)) {
         $new_options = array();
         $new_options[] = "-1:" . get_lang('All');
         $new_options[] = "0:" . get_lang('Orphan');
         foreach ($exerciseList as $exercise) {
             $new_options[] = "{$exercise['iid']}:{$exercise['title']}";
         }
         $string = implode(';', $new_options);
         $fields[] = array('field_display_text' => get_lang('Exercise'), 'field_variable' => 'exercise_id', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
     }
     // Question type.
     $questionList = Question::get_question_type_list();
     if (!empty($questionList)) {
         $new_options = array();
         $new_options[] = "-1:" . get_lang('All');
         foreach ($questionList as $key => $question) {
             $new_options[] = "{$key}:" . get_lang($question['1']);
         }
         $string = implode(';', $new_options);
         $fields[] = array('field_display_text' => get_lang('AnswerType'), 'field_variable' => 'question_type', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
     }
     // Difficult.
     $levels = Question::get_default_levels();
     if (!empty($levels)) {
         $new_options = array();
         $new_options[] = "-1:" . get_lang('All');
         foreach ($levels as $key => $level) {
             $new_options[] = "{$key}:{$level}";
         }
         $string = implode(';', $new_options);
         $fields[] = array('field_display_text' => get_lang('Difficulty'), 'field_variable' => 'difficulty', 'field_type' => ExtraField::FIELD_TYPE_SELECT, 'field_default_value' => null, 'field_options' => $string);
     }
     $questionFieldsKeys = array();
     if (!empty($questionFields)) {
         foreach ($questionFields as $question) {
             $questionFieldsKeys[] = $question['field'];
         }
     }
     if (!empty($fields)) {
         foreach ($fields as $field) {
             $search_options = array();
             $type = 'text';
             if (in_array($field['field_type'], array(ExtraField::FIELD_TYPE_SELECT, ExtraField::FIELD_TYPE_DOUBLE_SELECT))) {
                 $type = 'select';
                 $search_options['sopt'] = array('eq', 'ne');
                 //equal not equal
                 //$search_options['sopt'] = array('cn', 'nc'); //contains not contains
             } else {
                 $search_options['sopt'] = array('cn', 'nc');
                 //contains not contains
             }
             $search_options['searchhidden'] = 'true';
             $search_options['defaultValue'] = isset($search_options['field_default_value']) ? $search_options['field_default_value'] : null;
             $search_options['value'] = $field['field_options'];
             $column_model[] = array('name' => 'question_' . $field['field_variable'], 'index' => 'question_' . $field['field_variable'], 'width' => '100', 'hidden' => 'true', 'search' => 'true', 'stype' => $type, 'searchoptions' => $search_options);
             $columns[] = $field['field_display_text'];
             $rules[] = array('field' => 'question_' . $field['field_variable'], 'op' => 'eq');
         }
     }
     return $rules;
 }
<?php

/* For licensing terms, see /license.txt */
$user_id = intval($_REQUEST['user_id']);
$session_id = intval($_REQUEST['id_session']);
if (empty($user_id) && empty($session_id)) {
    api_not_allowed(true);
}
SessionManager::protect_session_edit($session_id);
if (api_is_platform_admin()) {
    $sessions = SessionManager::get_sessions_admin(array('order' => 'name'));
} else {
    $sessions = SessionManager::get_sessions_by_general_coach(api_get_session_id());
}
$message = null;
$session_to_select = array();
foreach ($sessions as $session) {
    if ($session_id != $session['id']) {
        $session_to_select[$session['id']] = $session['name'];
    }
}
$session_name = api_get_session_name($session_id);
$user_info = api_get_user_info($user_id);
//Check if user was already moved
$user_status = SessionManager::get_user_status_in_session($session_id, $user_id);
if (isset($user_status['moved_to']) && $user_status['moved_to'] != 0 || $user_status['moved_status'] == SessionManager::SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION) {
    api_not_allowed(true);
}
$form = new FormValidator('change_user_session', 'post', api_get_self());
$form->addElement('hidden', 'user_id', $user_id);
$form->addElement('hidden', 'id_session', $session_id);