'index.php', 'name' => get_lang('Sessions')); $interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList')); $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; $htmlHeadXtra[] = api_get_jquery_libraries_js(array('jquery-ui-i18n')); $htmlHeadXtra = api_get_datetime_picker_js($htmlHeadXtra); $id = null; $url_action = api_get_self(); if (isset($_GET['id'])) { $id = intval($_GET['id']); $url_action = '?id='.$id; } $add_coach = null; if ($id) { $tool_name = get_lang('EditSession'); SessionManager::protect_session_edit($id); $session_info = api_get_session_info($id); if (!empty($session_info['id_coach'])) { $user_info = api_get_user_info($session_info['id_coach']); $add_coach = '$("#coach_id").trigger("addItem", [{"title": "'.$user_info['complete_name'].'", "value": "'.$session_info['id_coach'].'"}]);'; } $button = get_lang('Update'); } else { $tool_name = get_lang('AddSession'); $button = get_lang('Add'); } $url = api_get_path(WEB_AJAX_PATH).'admin.ajax.php?1=1'; $htmlHeadXtra[] =' '; $form = new FormValidator('add_session', 'post', $url_action); $form->addElement('header', $tool_name); //Name $form->addElement('text', 'name', get_lang('SessionName'), array('class' => 'span6')); $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); if (empty($id)) { $form->addRule('name', get_lang('SessionNameAlreadyExists'), 'callback', 'check_session_name'); } else { $form->addElement('hidden', 'id', $id); } //Coaches //$coaches = SessionManager::get_user_list(); if (api_is_platform_admin()) { $form->addElement('select', 'id_coach', get_lang('CoachName'), array(), array('id' => 'coach_id')); $form->addRule('id_coach', get_lang('ThisFieldIsRequired'), 'required'); } else { $form->addElement('hidden', 'id_coach', api_get_user_id()); } $form->addElement('advanced_settings',''.get_lang('AdvancedParameters').''); $form->addElement('html',''); $form->addElement('button', 'submit', $button); if (!empty($session_info)) { $session_info['display_start_date'] = api_get_local_time($session_info['display_start_date'], null, null, true); $session_info['display_end_date'] = api_get_local_time($session_info['display_end_date'], null, null, true); $session_info['access_start_date'] = api_get_local_time($session_info['access_start_date'], null, null, true); $session_info['access_end_date'] = api_get_local_time($session_info['access_end_date'], null, null, true); $session_info['coach_access_start_date'] = api_get_local_time($session_info['coach_access_start_date'], null, null, true); $session_info['coach_access_end_date'] = api_get_local_time($session_info['coach_access_end_date'], null, null, true); $form->setDefaults($session_info); } if ($form->validate()) { $params = $form->getSubmitValues(); if (isset($params['id'])) { SessionManager::update($params); header('Location: resume_session.php?id_session='.$params['id']); exit; } else { $session_id = SessionManager::add($params); if ($session_id) { // integer => no error on session creation header('Location: add_courses_to_session.php?id_session='.$session_id.'&add=true&msg='); exit; } } } function check_session_name($name) { $session = SessionManager::get_session_by_name($name); return empty($session) ? true : false; } Display::display_header($tool_name); echo '
'; echo ''.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'),'',ICON_SIZE_MEDIUM).''; echo '
'; $form->display(); Display::display_footer();