registerFunction('search_coachs'); // setting the section (for the tabs) $this_section = SECTION_PLATFORM_ADMIN; SessionManager::protectSession(null, false); api_protect_limit_for_session_admin(); $formSent = 0; $errorMsg = ''; // Crop picture plugin for session images //$htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css'); //$htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js'); $interbreadcrumb[] = [ 'url' => 'session_list.php', 'name' => get_lang('Session list'), ]; function search_coachs($needle) { $tbl_user = Database::get_main_table(TABLE_MAIN_USER); $xajax_response = new xajaxResponse(); $return = ''; if (!empty($needle)) { $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username'; // search users where username or firstname or lastname begins likes $needle $sql = 'SELECT username, lastname, firstname FROM '.$tbl_user.' user WHERE (username LIKE "'.$needle.'%" OR firstname LIKE "'.$needle.'%" OR lastname LIKE "'.$needle.'%") AND status=1'. $order_clause. ' LIMIT 10'; if (api_is_multiple_url_enabled()) { $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); $access_url_id = api_get_current_access_url_id(); if ($access_url_id != -1) { $sql = 'SELECT username, lastname, firstname FROM '.$tbl_user.' user INNER JOIN '.$tbl_user_rel_access_url.' url_user ON (url_user.user_id=user.user_id) WHERE access_url_id = '.$access_url_id.' AND ( username LIKE "'.$needle.'%" OR firstname LIKE "'.$needle.'%" OR lastname LIKE "'.$needle.'%" ) AND status=1'. $order_clause.' LIMIT 10'; } } $rs = Database::query($sql); while ($user = Database :: fetch_array($rs)) { $return .= ''.api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')
'; } } $xajax_response->addAssign('ajax_list_coachs', 'innerHTML', api_utf8_encode($return)); return $xajax_response; } $xajax->processRequests(); $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/'); $htmlHeadXtra[] = " "; if (isset($_POST['formSent']) && $_POST['formSent']) { $formSent = 1; } $tool_name = get_lang('Add a training session'); $urlAction = api_get_self(); function check_session_name($name) { $session = SessionManager::get_session_by_name($name); return empty($session) ? true : false; } $form = new FormValidator('add_session', 'post', $urlAction); $form->addElement('header', $tool_name); $result = SessionManager::setForm($form); $url = api_get_path(WEB_AJAX_PATH).'session.ajax.php'; $urlUpload = api_get_path(WEB_UPLOAD_PATH); $sysUploadPath = api_get_path(SYS_UPLOAD_PATH); $urlAjaxExtraField = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?1=1'; $htmlHeadXtra[] = " "; $form->addButtonNext(get_lang('Next step')); if (!$formSent) { $formDefaults['access_start_date'] = $formDefaults['display_start_date'] = api_get_local_time(); $formDefaults['coach_username'] = api_get_user_id(); } else { $formDefaults['name'] = api_htmlentities($name, ENT_QUOTES, $charset); } $form->setDefaults($formDefaults); if ($form->validate()) { $params = $form->getSubmitValues(); $name = $params['name']; $startDate = $params['access_start_date']; $endDate = $params['access_end_date']; $displayStartDate = $params['display_start_date']; $displayEndDate = $params['display_end_date']; $coachStartDate = $params['coach_access_start_date']; if (empty($coachStartDate)) { $coachStartDate = $displayStartDate; } $coachEndDate = $params['coach_access_end_date']; $coach_username = intval($params['coach_username']); $id_session_category = $params['session_category']; $id_visibility = $params['session_visibility']; $duration = isset($params['duration']) ? $params['duration'] : null; $description = $params['description']; $showDescription = isset($params['show_description']) ? 1 : 0; $sendSubscriptionNotification = isset($params['send_subscription_notification']); $isThisImageCropped = isset($params['picture_crop_result']); $extraFields = []; foreach ($params as $key => $value) { if (strpos($key, 'extra_') === 0) { $extraFields[$key] = $value; } } if (isset($extraFields['extra_image']) && !empty($extraFields['extra_image']['name']) && $isThisImageCropped) { $extraFields['extra_image']['crop_parameters'] = $params['picture_crop_result']; } // Check if the session image will be copied from the template $importImageFromSession = false; $sessionIdToImport = explode('::', $params['extra_image_crop_result']); $sessionIdToImport = isset($sessionIdToImport[1]) ? (int) $sessionIdToImport[1] : 0; if (!empty($sessionIdToImport)) { $extraField = new ExtraField('session'); $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable('image'); $extraFieldValue = new ExtraFieldValue('session'); $extraFieldValueData = $extraFieldValue->get_values_by_handler_and_field_id( $sessionIdToImport, $extraFieldInfo['id'] ); if ($extraFieldValueData && file_exists($sysUploadPath.$extraFieldValueData['value'])) { $extraFields['extra_image']['name'] = basename($extraFieldValueData['value']); $extraFields['extra_image']['tmp_name'] = $sysUploadPath.$extraFieldValueData['value']; $extraFields['extra_image']['type'] = 'image/png'; $extraFields['extra_image']['error'] = 0; $extraFields['extra_image']['size'] = filesize($sysUploadPath.$extraFieldValueData['value']); } } $return = SessionManager::create_session( $name, $startDate, $endDate, $displayStartDate, $displayEndDate, $coachStartDate, $coachEndDate, $coach_username, $id_session_category, $id_visibility, false, $duration, $description, $showDescription, $extraFields, null, $sendSubscriptionNotification ); if ($return == strval(intval($return))) { // integer => no error on session creation header('Location: add_courses_to_session.php?id_session='.$return.'&add=true'); exit(); } } Display::display_header($tool_name); if (!empty($return)) { echo Display::return_message($return, 'error', false); } echo '
'; echo ''. Display::return_icon('back.png', get_lang('Back to').' '.get_lang('Administration'), '', ICON_SIZE_MEDIUM).''; echo '
'; $form->display(); Display::display_footer();