/** * @param int $userId */ function preventMultipleLogin($userId) { $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); $userId = intval($userId); if (api_get_settings('prevent_multiple_simultaneous_login') === 'true') { if (!empty($userId) && !api_is_anonymous()) { $isFirstLogin = Session::read('first_user_login'); if (empty($isFirstLogin)) { $sql = "SELECT login_id FROM {$table}\n WHERE login_user_id = " . $userId . " LIMIT 1"; $result = Database::query($sql); $loginData = array(); if (Database::num_rows($result)) { $loginData = Database::fetch_array($result); } $userIsReallyOnline = user_is_online($userId); // Trying double login. if (!empty($loginData) && $userIsReallyOnline == true) { session_regenerate_id(); Session::destroy(); header('Location: ' . api_get_path(WEB_PATH) . 'index.php?loginFailed=1&error=multiple_connection_not_allowed'); exit; } else { // First time Session::write('first_user_login', 1); } } } } }
/** * Create a Shibboleth session for the user ID * * @param string $uid - The user ID * @return $_user (array) - The user infos array created when the user logs in */ function login($uid) { /* This must be set for local.inc.php to register correctly the global variables in session * This is BAD. Logic should be migrated into a function and stop relying on global variables. */ global $_uid, $is_allowedCreateCourse, $_real_cid, $_courseUser; global $is_courseMember, $is_courseTutor, $is_allowed_in_course, $_gid; $_uid = $uid; //is_allowedCreateCourse $user = User::store()->get_by_user_id($uid); if (empty($user)) { return; } $this->logout(); Chamilo::session()->start(); Session::write('_uid', $_uid); global $_user; $_user = (array) $user; $_SESSION['_user'] = $_user; $_SESSION['_user']['user_id'] = $_uid; $_SESSION['noredirection'] = true; //must be called before 'init_local.inc.php' event_login(); //used in 'init_local.inc.php' this is BAD but and should be changed $loginFailed = false; $uidReset = true; $gidReset = true; $cidReset = false; //FALSE !! $mainDbName = Database::get_main_database(); $includePath = api_get_path(INCLUDE_PATH); $no_redirection = true; require "{$includePath}/local.inc.php"; return $_user; }
/** * Search for a session based on a given search string * @param string A search string * @param string A search box type (single or anything else) * @return string XajaxResponse * @assert () !== '' * @assert ('abc','single') !== '' */ function search_courses($needle, $type) { $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $xajax_response = new xajaxResponse(); $return = ''; if (!empty($needle) && !empty($type)) { // xajax send utf8 datas... datas in db can be non-utf8 datas $charset = api_get_system_encoding(); $needle = api_convert_encoding($needle, $charset, 'utf-8'); $needle = Database::escape_string($needle); $sql = 'SELECT * FROM ' . $tbl_session . ' WHERE name LIKE "' . $needle . '%" ORDER BY id'; $rs = Database::query($sql); $course_list = array(); $return .= '<select id="origin" name="NoSessionCategoryList[]" multiple="multiple" size="20" style="width:340px;">'; while ($course = Database::fetch_array($rs)) { $course_list[] = $course['id']; $return .= '<option value="' . $course['id'] . '" title="' . htmlspecialchars($course['name'], ENT_QUOTES) . '">' . $course['name'] . '</option>'; } $return .= '</select>'; $xajax_response->addAssign('ajax_list_courses_multiple', 'innerHTML', api_utf8_encode($return)); } Session::write('course_list', $course_list); return $xajax_response; }
/** * @param Application $app * @param int $exerciseId * @param int $questionId * @return Response */ public function reuseQuestionAction(Application $app, $exerciseId, $questionId) { /** @var \Question $question */ $question = \Question::read($questionId); if ($question) { // adds the exercise ID represented by $fromExercise into the list of exercises for the current question $question->addToList($exerciseId); $objExercise = new \Exercise(); $objExercise->read($exerciseId); // adds the question ID represented by $recup into the list of questions for the current exercise $objExercise->addToList($exerciseId); Session::write('objExercise', $objExercise); /*$params = array( 'cidReq' => api_get_course_id(), 'id_session' => api_get_session_id(), 'id' => $questionId, 'exerciseId' => $exerciseId ); $url = $app['url_generator']->generate('exercise_question_pool', $params); return $app->redirect($url);*/ $response = \Display::return_message(get_lang('QuestionReused') . ": " . $question->question); return new Response($response, 200, array()); } }
/** * SET Disable Chat * @param boolean status to disable chat * @return void */ public static function setDisableChat($status = true) { Session::write('disable_chat', $status); }
$message = Display::return_message(get_lang('CannotCreateDir'), 'error'); } Session::write('message', $message); header('Location: ' . $currentUrl); exit; } else { $content = $form->return_form(); } break; case 'delete_dir': if ($is_allowed_to_edit) { $work_to_delete = get_work_data_by_id($_REQUEST['id']); $result = deleteDirWork($_REQUEST['id']); if ($result) { $message = Display::return_message(get_lang('DirDeleted') . ': ' . $work_to_delete['title'], 'success'); Session::write('message', $message); } header('Location: ' . $currentUrl); exit; } break; case 'move': /* Move file form request */ if ($is_allowed_to_edit) { if (!empty($item_id)) { $content = generateMoveForm($item_id, $curdirpath, $course_info, $group_id, $session_id); } } break; case 'move_to': /* Move file command */
<?php /* For licensing terms, see /license.txt */ use ChamiloSession as Session; /** * This file allows creating new svg and png documents with an online editor. * * @package chamilo.document * * @author Juan Carlos Raña Trabado herodoto@telefonica.net * @since 5/mar/2011 */ //require_once '../inc/global.inc.php'; Session::write('whereami', 'document/voicerecord'); $this_section = SECTION_COURSES; $nameTools = get_lang('VoiceRecord'); api_protect_course_script(); api_block_anonymous_users(); $groupId = api_get_group_id(); $document_data = array(); if (isset($_GET['id'])) { $document_data = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id(), true); } if (empty($document_data)) { if (api_is_in_group()) { $group_properties = GroupManager::get_group_properties($groupId); $document_id = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']); $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id()); } } $document_id = $document_data['id'];
/** * Returns an HTML-formatted link to a resource, to incorporate directly into * the new learning path tool. * * The function is a big switch on tool type. * In each case, we query the corresponding table for information and build the link * with that information. * @author Yannick Warnier <*****@*****.**> - rebranding based on previous work (display_addedresource_link_in_learnpath()) * @param int $course_id Course code * @param int $learnpath_id The learning path ID (in lp table) * @param int $id_in_path the unique index in the items table * @param int $lpViewId */ function rl_get_resource_link_for_learnpath($course_id, $learnpath_id, $id_in_path, $lpViewId) { $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); $course_info = api_get_course_info_by_id($course_id); $course_id = $course_info['real_id']; $course_code = $course_info['code']; $session_id = api_get_session_id(); $learnpath_id = intval($learnpath_id); $id_in_path = intval($id_in_path); $lpViewId = intval($lpViewId); $sql = "SELECT * FROM {$tbl_lp_item}\n WHERE\n c_id = {$course_id} AND\n lp_id = {$learnpath_id} AND\n id = {$id_in_path}\n "; $res_item = Database::query($sql); if (Database::num_rows($res_item) < 1) { return -1; } $row_item = Database::fetch_array($res_item); $type = strtolower($row_item['item_type']); $id = strcmp($row_item['path'], '') == 0 ? '0' : $row_item['path']; $origin = 'learnpath'; $main_dir_path = api_get_path(WEB_CODE_PATH); $main_course_path = api_get_path(WEB_COURSE_PATH) . $course_info['directory'] . '/'; $link = ''; switch ($type) { case 'dokeos_chapter': $link .= $main_dir_path . 'newscorm/blank.php'; case TOOL_CALENDAR_EVENT: $link .= $main_dir_path . 'calendar/agenda.php?origin=' . $origin . '&agenda_id=' . $id; break; case TOOL_ANNOUNCEMENT: $link .= $main_dir_path . 'announcements/announcements.php?origin=' . $origin . '&ann_id=' . $id; break; case TOOL_LINK: $TABLETOOLLINK = Database::get_course_table(TABLE_LINK); $result = Database::query("SELECT * FROM {$TABLETOOLLINK} WHERE c_id = {$course_id} AND id={$id}"); $myrow = Database::fetch_array($result); $thelink = $myrow["url"]; $link .= $thelink; break; case TOOL_QUIZ: if (!empty($id)) { $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST); $sql = "SELECT * FROM {$TBL_EXERCICES} WHERE c_id = {$course_id} AND id={$id}"; $result = Database::query($sql); $myrow = Database::fetch_array($result); if ($row_item['title'] != '') { $myrow['title'] = $row_item['title']; } $link .= $main_dir_path . 'exercice/overview.php?cidReq=' . $course_code . '&session_id=' . $session_id . '&lp_init=1&origin=' . $origin . '&learnpath_id=' . $learnpath_id . '&learnpath_item_id=' . $id_in_path . '&exerciseId=' . $id; } break; case 'hotpotatoes': //lowercase because of strtolower above $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); $result = Database::query("SELECT * FROM " . $TBL_DOCUMENT . " WHERE c_id = {$course_id} AND id={$id}"); $myrow = Database::fetch_array($result); $path = $myrow['path']; $link .= $main_dir_path . 'exercice/showinframes.php?file=' . $path . '' . '&origin=' . $origin . '&cid=' . $course_code . '&uid=' . api_get_user_id() . '' . '&learnpath_id=' . $learnpath_id . '&learnpath_item_id=' . $id_in_path . '&lp_view_id=' . $lpViewId; break; case TOOL_FORUM: $link .= $main_dir_path . 'forum/viewforum.php?forum=' . $id . '&lp=true&origin=learnpath'; break; case TOOL_THREAD: //forum post $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD); if (!empty($id)) { $sql = "SELECT * FROM {$tbl_topics} WHERE c_id = {$course_id} AND thread_id={$id}"; $result = Database::query($sql); $myrow = Database::fetch_array($result); $link .= $main_dir_path . 'forum/viewthread.php?origin=learnpath&thread=' . $id . '' . '&forum=' . $myrow['forum_id'] . '&lp=true'; } break; case TOOL_POST: $tbl_post = Database::get_course_table(TABLE_FORUM_POST); $result = Database::query("SELECT * FROM {$tbl_post} WHERE c_id = {$course_id} AND post_id={$id}"); $myrow = Database::fetch_array($result); $title = $myrow['post_title']; //$desc = $row_item['description']; $posternom = $myrow['poster_name']; $posttime = $myrow['post_date']; $posttext = $myrow['post_text']; $posttitle = $title; $posttext = str_replace('"', "'", $posttext); $link .= $main_dir_path . 'forum/viewthread.php?post=' . $id . '' . '&thread=' . $myrow['thread_id'] . '&forum=' . $myrow['forum_id'] . '' . '&lp=true'; break; case TOOL_DOCUMENT: $tbl_doc = Database::get_course_table(TABLE_DOCUMENT); $sql = "SELECT * FROM {$tbl_doc} WHERE c_id = {$course_id} AND id = {$id}"; $result = Database::query($sql); $myrow = Database::fetch_array($result); $docurl = str_replace('%2F', '/', urlencode($myrow['path'])); $link .= $main_course_path . 'document' . $docurl . '?cidReq=' . $course_code . '&id_session=' . $session_id; $openmethod = 2; $officedoc = false; Session::write('openmethod', $openmethod); Session::write('officedoc', $officedoc); break; case 'assignments': $link .= $main_dir_path . 'work/work.php?origin=' . $origin; break; case TOOL_DROPBOX: $link .= $main_dir_path . 'dropbox/index.php?origin=learnpath'; break; case 'introduction_text': //DEPRECATED $link .= ''; break; case TOOL_COURSE_DESCRIPTION: $link .= $main_dir_path . 'course_description?origin=learnpath'; break; case TOOL_GROUP: $link .= $main_dir_path . 'group/group.php?origin=' . $origin; break; case TOOL_USER: $link .= $main_dir_path . 'user/user.php?origin=' . $origin; break; case 'student_publication': $link .= $main_dir_path . 'work/work.php?origin=learnpath'; break; } //end switch return $link; }
/** * Sets * @param string $file ($document_data['path']) * @param string $file_url_sys * @return string */ public static function generateAudioTempFile($file, $file_url_sys) { //make temp audio $temp_folder = api_get_path(SYS_ARCHIVE_PATH) . 'temp/audio'; if (!file_exists($temp_folder)) { @mkdir($temp_folder, api_get_permissions_for_new_directories(), true); } //make htaccess with allow from all, and file index.html into temp/audio $htaccess = api_get_path(SYS_ARCHIVE_PATH) . 'temp/audio/.htaccess'; if (!file_exists($htaccess)) { $htaccess_content = "order deny,allow\r\nallow from all\r\nOptions -Indexes"; $fp = @fopen(api_get_path(SYS_ARCHIVE_PATH) . 'temp/audio/.htaccess', 'w'); if ($fp) { fwrite($fp, $htaccess_content); fclose($fp); } } //encript temp name file $name_crip = sha1(uniqid()); //encript $findext = explode(".", $file); $extension = $findext[count($findext) - 1]; $file_crip = $name_crip . '.' . $extension; //copy file to temp/audio directory $from_sys = $file_url_sys; $to_sys = api_get_path(SYS_ARCHIVE_PATH) . 'temp/audio/' . $file_crip; if (file_exists($from_sys)) { copy($from_sys, $to_sys); } //get file from tmp directory Session::write('temp_audio_nanogong', $to_sys); return api_get_path(WEB_ARCHIVE_PATH) . 'temp/audio/' . $file_crip; }
/** * function which redifines Question::createAnswersForm * @param FormValidator $form * @param the answers number to display */ function createAnswersForm($form) { // getting the exercise list $obj_ex = Session::read('objExercise'); $editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125'); //this line define how many question by default appear when creating a choice question $nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 3; // The previous default value was 2. See task #1759. $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0); /* Types of Feedback $feedback_option[0]=get_lang('Feedback'); $feedback_option[1]=get_lang('DirectFeedback'); $feedback_option[2]=get_lang('NoFeedback'); */ $feedback_title = ''; $comment_title = ''; if ($obj_ex->selectFeedbackType() == 1) { $editor_config['Width'] = '250'; $editor_config['Height'] = '110'; $comment_title = '<th width="50%" >' . get_lang('Comment') . '</th>'; $feedback_title = '<th width="50%" >' . get_lang('Scenario') . '</th>'; } else { $comment_title = '<th width="50%">' . get_lang('Comment') . '</th>'; } $html = '<table class="table table-striped table-hover">'; $html .= '<thead>'; $html .= '<tr>'; $html .= '<th>' . get_lang('Number') . '</th>'; $html .= '<th>' . get_lang('True') . '</th>'; $html .= '<th width="50%">' . get_lang('Answer') . '</th>'; $html .= $comment_title . $feedback_title; $html .= '<th>' . get_lang('Weighting') . '</th>'; $html .= '</tr>'; $html .= '</thead>'; $html .= '<tbody>'; $form->addHeader(get_lang('Answers')); $form->addHtml($html); $defaults = array(); $correct = 0; $answer = false; if (!empty($this->id)) { $answer = new Answer($this->id); $answer->read(); if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) { $nb_answers = $answer->nbrAnswers; } } $temp_scenario = array(); if ($nb_answers < 1) { $nb_answers = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } $editQuestion = isset($_GET['editQuestion']) ? $_GET['editQuestion'] : false; if ($editQuestion) { //fixing $nb_answers $new_list = array(); $count = 1; if (isset($_POST['lessAnswers'])) { $lessFromSession = Session::read('less_answer'); if (!isset($lessFromSession)) { Session::write('less_answer', $this->id); $nb_answers--; } } for ($k = 1; $k <= $nb_answers; ++$k) { if ($answer->position[$k] != '666') { $new_list[$count] = $count; $count++; } } } else { for ($k = 1; $k <= $nb_answers; ++$k) { $new_list[$k] = $k; } } $i = 1; //for ($k = 1 ; $k <= $real_nb_answers; $k++) { foreach ($new_list as $key) { $i = $key; $form->addElement('html', '<tr>'); if (is_object($answer)) { if ($answer->position[$i] == 666) { //we set nothing } else { if ($answer->correct[$i]) { $correct = $i; } $answer_result = $answer->answer[$i]; $weight_result = float_format($answer->weighting[$i], 1); if ($nb_answers == $i) { $weight_result = '0'; } $defaults['answer[' . $i . ']'] = $answer_result; $defaults['comment[' . $i . ']'] = $answer->comment[$i]; $defaults['weighting[' . $i . ']'] = $weight_result; $item_list = explode('@@', $answer->destination[$i]); $try = $item_list[0]; $lp = $item_list[1]; $list_dest = $item_list[2]; $url = $item_list[3]; if ($try == 0) { $try_result = 0; } else { $try_result = 1; } if ($url == 0) { $url_result = ''; } else { $url_result = $url; } $temp_scenario['url' . $i] = $url_result; $temp_scenario['try' . $i] = $try_result; $temp_scenario['lp' . $i] = $lp; $temp_scenario['destination' . $i] = $list_dest; } } $defaults['scenario'] = $temp_scenario; $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting[' . $i . ']'); $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"'); $answer_number->freeze(); $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"'); $form->addHtmlEditor('answer[' . $i . ']', null, array(), false, $editor_config); $form->addHtmlEditor('comment[' . $i . ']', null, array(), false, $editor_config); $form->addElement('text', 'weighting[' . $i . ']', null, array('style' => 'width: 60px;', 'value' => '0')); $form->addElement('html', '</tr>'); $i++; } if (empty($this->id)) { $form->addElement('hidden', 'new_question', 1); } //Adding the "I don't know" question answer //if (empty($this -> id)) { $i = 666; $form->addHtml('<tr>'); $defaults['answer[' . $i . ']'] = get_lang('DontKnow'); $defaults['weighting[' . $i . ']'] = 0; $defaults['scenario'] = $temp_scenario; $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting[' . $i . ']'); $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="-"'); $answer_number->freeze(); $form->addElement('hidden', 'position[' . $i . ']', '666'); $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"'); $form->addHtmlEditor('answer[' . $i . ']', null, array(), false, $editor_config); $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); $form->addHtmlEditor('comment[' . $i . ']', null, array(), false, $editor_config); //$form->addElement('select', 'destination'.$i, get_lang('SelectQuestion').' : ',$select_question,'multiple'); $form->addText("weighting[{$i}]", null, false, ['style' => 'width: 60px;', 'value' => 0, 'readonly' => 'readonly']); $form->addHTml('</tr>'); $form->addHtml('</tbody></table>'); $buttonGroup = []; global $text, $class; //ie6 fix if ($obj_ex->edit_exercise_in_lp == true) { //setting the save button here and not in the question class.php $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true); $buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true); $buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true); $form->addGroup($buttonGroup); } //We check the first radio button to be sure a radio button will be check if ($correct == 0) { $correct = 1; } $defaults['correct'] = $correct; if (!empty($this->id)) { $form->setDefaults($defaults); } else { $form->setDefaults($defaults); } $form->addElement('hidden', 'nb_answers'); $form->setConstants(array('nb_answers' => $nb_answers)); }
/** * This is the main function that displays the list or the table with all * the glossary terms * @param string View ('table' or 'list'). Optional parameter. * Defaults to 'table' and prefers glossary_view from the session by default. * @return void * @author Patrick Cool <*****@*****.**>, Ghent University, Belgium * @version januari 2009, dokeos 1.8.6 */ public static function display_glossary($view = 'table') { // This function should always be called with the corresponding // parameter for view type. Meanwhile, use this cheap trick. $glossaryView = Session::read('glossary_view'); if (empty($glossaryView)) { Session::write('glossary_view', $view); } // action links echo '<div class="actions">'; if (api_is_allowed_to_edit(null, true)) { echo '<a href="index.php?' . api_get_cidreq() . '&action=addglossary&msg=add?' . api_get_cidreq() . '">' . Display::return_icon('new_glossary_term.png', get_lang('TermAddNew'), '', ICON_SIZE_MEDIUM) . '</a>'; } echo '<a href="index.php?' . api_get_cidreq() . '&action=export">' . Display::return_icon('export_csv.png', get_lang('ExportGlossaryAsCSV'), '', ICON_SIZE_MEDIUM) . '</a>'; if (api_is_allowed_to_edit(null, true)) { echo '<a href="index.php?' . api_get_cidreq() . '&action=import">' . Display::return_icon('import_csv.png', get_lang('ImportGlossary'), '', ICON_SIZE_MEDIUM) . '</a>'; } echo '<a href="index.php?' . api_get_cidreq() . '&action=export_to_pdf">' . Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM) . '</a>'; if (isset($glossaryView) && $glossaryView == 'table' or !isset($glossaryView)) { echo '<a href="index.php?' . api_get_cidreq() . '&action=changeview&view=list">' . Display::return_icon('view_detailed.png', get_lang('ListView'), '', ICON_SIZE_MEDIUM) . '</a>'; } else { echo '<a href="index.php?' . api_get_cidreq() . '&action=changeview&view=table">' . Display::return_icon('view_text.png', get_lang('TableView'), '', ICON_SIZE_MEDIUM) . '</a>'; } echo '</div>'; if (!$glossaryView || $glossaryView == 'table') { $table = new SortableTable('glossary', array('GlossaryManager', 'get_number_glossary_terms'), array('GlossaryManager', 'get_glossary_data'), 0); //$table->set_header(0, '', false); $table->set_header(0, get_lang('TermName'), true); $table->set_header(1, get_lang('TermDefinition'), true); if (api_is_allowed_to_edit(null, true)) { $table->set_header(2, get_lang('Actions'), false, 'width=90px', array('class' => 'td_actions')); $table->set_column_filter(2, array('GlossaryManager', 'actions_filter')); } $table->display(); } if ($glossaryView == 'list') { GlossaryManager::display_glossary_list(); } }
/** * Calculate the score of this evaluation * @param int $stud_id (default: all students who have results for this eval - then the average is returned) * @param string $type (best, average, ranking) * @return array (score, max) if student is given * array (sum of scores, number of scores) otherwise * or null if no scores available */ public function calc_score($stud_id = null, $type = null) { $useSession = true; if (isset($stud_id) && empty($type)) { $key = 'result_score_student_list_' . api_get_course_int_id() . '_' . api_get_session_id() . '_' . $this->id . '_' . $stud_id; $data = Session::read('calc_score'); $results = isset($data[$key]) ? $data[$key] : null; if ($useSession == false) { $results = null; } if (empty($results)) { $results = Result::load(null, $stud_id, $this->id); Session::write('calc_score', array($key => $results)); } $score = 0; /** @var Result $res */ foreach ($results as $res) { $score = $res->get_score(); } return array($score, $this->get_max()); } else { $count = 0; $sum = 0; $bestResult = 0; $weight = 0; $sumResult = 0; $key = 'result_score_student_list_' . api_get_course_int_id() . '_' . api_get_session_id() . '_' . $this->id; $data = Session::read('calc_score'); $allResults = isset($data[$key]) ? $data[$key] : null; if ($useSession == false) { $allResults = null; } if (empty($allResults)) { $allResults = Result::load(null, null, $this->id); Session::write($key, $allResults); } $students = array(); /** @var Result $res */ foreach ($allResults as $res) { $score = $res->get_score(); if (!empty($score) || $score == '0') { $count++; $sum += $score / $this->get_max(); $sumResult += $score; if ($score > $bestResult) { $bestResult = $score; } $weight = $this->get_max(); } $students[$res->get_user_id()] = $score; } if (empty($count)) { return null; } switch ($type) { case 'best': return array($bestResult, $weight); break; case 'average': return array($sumResult / $count, $weight); break; case 'ranking': $students = array(); /** @var Result $res */ foreach ($allResults as $res) { $score = $res->get_score(); $students[$res->get_user_id()] = $score; } return AbstractLink::getCurrentUserRanking($stud_id, $students); break; default: return array($sum, $count); break; } } }
$(function() { <?php // grid definition see the $career->display() function echo Display::grid_js('careers', $url, $columns, $column_model, $extra_params, array(), $action_links, true); ?> }); </script> <?php $career = new Career(); // Action handling: Add switch ($action) { case 'add': if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { api_not_allowed(); } Session::write('notebook_view', 'creation_date'); $url = api_get_self() . '?action=' . Security::remove_XSS($_GET['action']); $form = $career->return_form($url, 'add'); // The validation or display if ($form->validate()) { if ($check) { $values = $form->exportValues(); $res = $career->save($values); if ($res) { Display::display_confirmation_message(get_lang('ItemAdded')); } } $career->display(); } else { echo '<div class="actions">'; echo '<a href="' . api_get_self() . '">' . Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM) . '</a>';
/** * Make sure this function is protected because it does NOT check password! * * This function defines globals. * @param int $userId * * @return bool False on failure, redirection on success * @author Evie Embrechts * @author Yannick Warnier <*****@*****.**> */ function loginUser($userId) { $userId = intval($userId); $userInfo = api_get_user_info($userId); // Check if the user is allowed to 'login_as' $canLoginAs = api_can_login_as($userId); if (!$canLoginAs || empty($userInfo)) { return false; } $firstname = $userInfo['firstname']; $lastname = $userInfo['lastname']; if (api_is_western_name_order()) { $message = sprintf(get_lang('AttemptingToLoginAs'), $firstname, $lastname, $userId); } else { $message = sprintf(get_lang('AttemptingToLoginAs'), $lastname, $firstname, $userId); } if ($userId) { // Logout the current user LoginDelete(api_get_user_id()); Session::erase('_user'); Session::erase('is_platformAdmin'); Session::erase('is_allowedCreateCourse'); Session::erase('_uid'); // Cleaning session variables $_user['firstName'] = $userInfo['firstname']; $_user['lastName'] = $userInfo['lastname']; $_user['mail'] = $userInfo['email']; //$_user['lastLogin'] = $user_data['login_date']; $_user['official_code'] = $userInfo['official_code']; $_user['picture_uri'] = $userInfo['picture_uri']; $_user['user_id'] = $userId; $_user['id'] = $userId; $_user['status'] = $userInfo['status']; // Filling session variables with new data Session::write('_uid', $userId); Session::write('_user', $userInfo); Session::write('is_platformAdmin', (bool) UserManager::is_admin($userId)); Session::write('is_allowedCreateCourse', (bool) ($userInfo['status'] == 1)); // will be useful later to know if the user is actually an admin or not (example reporting) Session::write('login_as', true); $target_url = api_get_path(WEB_PATH) . "user_portal.php"; $message .= '<br />' . sprintf(get_lang('LoginSuccessfulGoToX'), '<a href="' . $target_url . '">' . $target_url . '</a>'); Display::display_header(get_lang('UserList')); Display::display_normal_message($message, false); Display::display_footer(); exit; } }
/** * This function uses the data from ldap_find_user_info() * to add the userdata to Chamilo * "firstname", "name", "email", "isEmployee" * @author Roan Embrechts */ function ldap_put_user_info_locally($login, $info_array) { //error_log('Entering ldap_put_user_info_locally('.$login.',info_array)',0); global $ldap_pass_placeholder; global $submitRegistration, $submit, $uname, $email, $nom, $prenom, $password, $password1, $status; global $platformLanguage; global $loginFailed, $uidReset, $_user; /*---------------------------------------------------------- 1. set the necessary variables ------------------------------------------------------------ */ $uname = $login; $email = $info_array["email"]; $nom = $info_array["name"]; $prenom = $info_array["firstname"]; $password = $ldap_pass_placeholder; $password1 = $ldap_pass_placeholder; $official_code = ''; define("STUDENT", 5); define("COURSEMANAGER", 1); $tutor_field = api_get_setting('ldap_filled_tutor_field'); $tutor_value = api_get_setting('ldap_filled_tutor_field_value'); if (empty($tutor_field)) { $status = STUDENT; } else { if (empty($tutor_value)) { //in this case, we are assuming that the admin didn't give a criteria // so that if the field is not empty, it is a tutor if (!empty($info_array[$tutor_field])) { $status = COURSEMANAGER; } else { $status = STUDENT; } } else { //the tutor_value is filled, so we need to check the contents of the LDAP field if (is_array($info_array[$tutor_field]) && in_array($tutor_value, $info_array[$tutor_field])) { $status = COURSEMANAGER; } else { $status = STUDENT; } } } //$official_code = xxx; //example: choose an attribute /*---------------------------------------------------------- 2. add info to Chamilo ------------------------------------------------------------ */ $language = api_get_setting('platformLanguage'); if (empty($language)) { $language = 'english'; } $_userId = UserManager::create_user($prenom, $nom, $status, $email, $uname, $password, $official_code, $language, '', '', 'ldap'); //echo "new user added to Chamilo, id = $_userId"; //user_id, username, password, auth_source /*---------------------------------------------------------- 3. register session ------------------------------------------------------------ */ $uData['user_id'] = $_userId; $uData['username'] = $uname; $uData['auth_source'] = "ldap"; $loginFailed = false; $uidReset = true; $_user['user_id'] = $uData['user_id']; Session::write('_uid', $_uid); }
$msg = $auth->subscribe_user($course_code); if (CourseManager::is_user_subscribed_in_course($user_id, $course_code)) { Session::write('is_allowed_in_course', true); } if (!empty($msg)) { $show_message .= Display::return_message(get_lang($msg['message']), 'info', false); } } } /* Is the user allowed here? */ api_protect_course_script(true); /* STATISTICS */ if (!isset($coursesAlreadyVisited[$course_code])) { Event::accessCourse(); $coursesAlreadyVisited[$course_code] = 1; Session::write('coursesAlreadyVisited', $coursesAlreadyVisited); } /*Auto launch code */ $show_autolaunch_lp_warning = false; $auto_launch = api_get_course_setting('enable_lp_auto_launch'); if (!empty($auto_launch)) { $session_id = api_get_session_id(); if ($auto_launch == 2) { //LP list if (api_is_platform_admin() || api_is_allowed_to_edit()) { $show_autolaunch_lp_warning = true; } else { $session_key = 'lp_autolaunch_' . $session_id . '_' . api_get_course_int_id() . '_' . api_get_user_id(); if (!isset($_SESSION[$session_key])) { //redirecting to the LP $url = api_get_path(WEB_CODE_PATH) . 'newscorm/lp_controller.php?' . api_get_cidreq() . '&id_session=' . $session_id;
$breadcrumbelement = array("url" => $url, "name" => $originaltoolname); session_unregister('from_learnpath'); unset($from_learnpath); break; case "4": // coming from exercises: edit topic $url = "../exercice/admin.php?modifyAnswers={$modifyAnswers}"; $originaltoolname = get_lang("ExerciseAnswers"); $breadcrumbelement = array("url" => $url, "name" => $originaltoolname); session_unregister('from_learnpath'); unset($from_learnpath); break; case "5": // coming from learning path $from_learnpath = 'yes'; Session::write('from_learnpath', $from_learnpath); break; case "6": // coming from forum: reply $url = "../phpbb/reply.php?topic={$topic}&forum={$forum}&parentid={$parentid}"; $url = $_SESSION['origintoolurl']; $originaltoolname = get_lang("ForumReply"); $breadcrumbelement = array("url" => $url, "name" => $originaltoolname); session_unregister('from_learnpath'); unset($from_learnpath); break; /*************************************** add Frederik.Vermeire@pandora.be *************************************/ /*************************************** add Frederik.Vermeire@pandora.be *************************************/ case "7": // coming from Ad_Valvas if ($action == "edit") {
require_once dirname(__FILE__) . '/functions.inc.php'; //MAIN CODE //$uData variable is set in local.inc.php $user = api_get_user_info($uData['user_id']); $new_user = external_get_user_info($login); $user['firstname'] = $new_user['firstname']; $user['lastname'] = $new_user['lastname']; $user['status'] = $new_user['status']; $user['admin'] = $new_user['admin']; $user['email'] = $new_user['email']; $user['username'] = $new_user['username']; $user['profile_link'] = $new_user['profile_link']; $user['worldwide_bu'] = $new_user['worldwide_bu']; $user['manager'] = $new_user['manager']; $user['country_bu'] = $new_user['country_bu']; $user['extra'] = $new_user['extra']; if ($new_user !== false) { //User can login external_update_user($user); $loginFailed = false; $_user['user_id'] = $user['user_id']; $_user['uidReset'] = true; $uidReset = true; Session::write('_user', $_user); } else { //User cannot login $loginFailed = true; Session::erase('_uid'); header('Location: ' . api_get_path(WEB_PATH) . 'index.php?loginFailed=1&error=user_password_incorrect'); exit; }
$form->addElement('label', null, $course_legal); if ($pluginLegal && !empty($plugin)) { $form->addElement('label', null, $plugin->getCurrentFile($course_info['real_id'], $session_id)); } $form->addElement('hidden', 'course_code', $course_code); $form->addElement('hidden', 'session_id', $session_id); $form->addElement('checkbox', 'accept_legal', null, get_lang('AcceptLegal')); $form->addElement('style_submit_button', null, get_lang('Accept'), 'class="save"'); $variable = 'accept_legal_' . $user_id . '_' . $course_info['real_id'] . '_' . $session_id; $url = api_get_course_url($course_code, $session_id); if ($form->validate()) { $accept_legal = $form->exportValue('accept_legal'); if ($accept_legal == 1) { CourseManager::save_user_legal($user_id, $course_code, $session_id); if (api_check_user_access_to_legal($course_info['visibility'])) { Session::write($variable, true); } if ($pluginLegal) { header('Location:' . $url); exit; } } } $user_pass_open_course = false; if (api_check_user_access_to_legal($course_info['visibility']) && Session::read($variable)) { $user_pass_open_course = true; } if (empty($session_id)) { if (CourseManager::is_user_subscribed_in_course($user_id, $course_code) || api_check_user_access_to_legal($course_info['visibility'])) { $user_accepted_legal = CourseManager::is_user_accepted_legal($user_id, $course_code); if ($user_accepted_legal || $user_pass_open_course) {
//Reading Answers obj of the current course $new_answer_obj = new Answer($old_question_id, $origin_course_id); $new_answer_obj->read(); //Duplicating the Answers in the current course $new_answer_obj->duplicate($new_id, $current_course); // destruction of the Question object unset($new_question_obj); unset($old_question_obj); if (!$objExercise instanceof Exercise) { $objExercise = new Exercise(); $objExercise->read($fromExercise); } } } } Session::write('objExercise', $objExercise); } } } if (isset($_SESSION['gradebook'])) { $gradebook = $_SESSION['gradebook']; } if (!empty($gradebook) && $gradebook == 'view') { $interbreadcrumb[] = array('url' => '../gradebook/' . Security::remove_XSS($_SESSION['gradebook_dest']), 'name' => get_lang('ToolGradebook')); } // if admin of course if (!$is_allowedToEdit) { api_not_allowed(true); } $confirmYourChoice = addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)); $htmlHeadXtra[] = "\n<script>\n\tfunction submit_form(obj) {\n\t\tdocument.question_pool.submit();\n\t}\n\n\tfunction mark_course_id_changed() {\n\t\t\$('#course_id_changed').val('1');\n\t}\n\n\tfunction mark_exercice_id_changed() {\n\t\t\$('#exercice_id_changed').val('1');\n\t}\n\n\tfunction confirm_your_choice() {\n\t\treturn confirm('{$confirmYourChoice}');\n\t}\n</script>";
api_not_allowed(true); } // User with no works $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'list'; switch ($action) { case 'send_mail': $check = Security::check_token('get'); if ($check) { $mails_sent_to = send_reminder_users_without_publication($my_folder_data); if (empty($mails_sent_to)) { $error_message = Display::return_message(get_lang('NoResults'), 'warning'); } else { $error_message = Display::return_message(get_lang('MessageHasBeenSent') . ' ' . implode(', ', $mails_sent_to), 'success'); } if (!empty($error_message)) { Session::write('error_message', $error_message); } Security::clear_token(); } break; } $token = Security::get_token(); if (!empty($group_id)) { $group_properties = GroupManager::get_group_properties($group_id); $show_work = false; if (api_is_allowed_to_edit(false, true)) { $show_work = true; } else { // you are not a teacher $show_work = GroupManager::user_has_access($user_id, $group_id, GroupManager::GROUP_TOOL_WORK); }
if (empty($document_data['parents'])) { if (isset($_GET['createdir'])) { $interbreadcrumb[] = array('url' => $document_data['document_url'], 'name' => $document_data['title']); } else { $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']); } } else { foreach ($document_data['parents'] as $document_sub_data) { if (!isset($_GET['createdir']) && $document_sub_data['id'] == $document_data['id']) { $document_sub_data['document_url'] = '#'; } $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']); } } $this_section = SECTION_COURSES; Session::write('whereami', 'document/view'); $nameTools = get_lang('Documents'); /** * Main code section */ header('Expires: Wed, 01 Jan 1990 00:00:00 GMT'); //header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); header('Last-Modified: Wed, 01 Jan 2100 00:00:00 GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); $browser_display_title = 'Documents - ' . Security::remove_XSS($_GET['cidReq']) . ' - ' . $file; // Only admins get to see the "no frames" link in pageheader.php, so students get a header that's not so high $frameheight = 135; if ($is_courseAdmin) { $frameheight = 165; }
$total_skills_to_search[$my_skill] = $my_skill; } } $total_skills_to_search = $skill->get_skills_info($total_skills_to_search); $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null; $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null; switch ($action) { case 'remove_skill': $new_skill = array(); foreach ($skills as $skill_id) { if ($id != $skill_id) { $new_skill[] = $skill_id; } } $skills = $new_skill; Session::write('skills', $skills); break; case 'load_profile': $skill_profile = new SkillRelProfile(); $skills = $skill_profile->get_skills_by_profile($id); $total_skills_to_search = $skill->get_skills_info($skills); break; } $skill_list = array(); foreach ($total_skills_to_search as $skill_info) { $skill_list[$skill_info['id']] = $skill_info; } $tpl->assign('skill_list', $skill_list); $tpl->assign('search_skill_list', $skills); $form_to_html = $form->returnForm(); $tpl->assign('form', $form_to_html);
/** * Shows a question * * @param int $questionId question id * @param bool $only_questions if true only show the questions, no exercise title * @param bool $origin i.e = learnpath * @param string $current_item current item from the list of questions * @param bool $show_title * @param bool $freeze * @param array $user_choice * @param bool $show_comment * @param bool $exercise_feedback * @param bool $show_answers * */ public static function showQuestion($questionId, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false) { $course_id = api_get_course_int_id(); // Change false to true in the following line to enable answer hinting $debug_mark_answer = $show_answers; // Reads question information if (!($objQuestionTmp = Question::read($questionId))) { // Question not found return false; } if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) { $show_comment = false; } $answerType = $objQuestionTmp->selectType(); $pictureName = $objQuestionTmp->selectPicture(); $s = ''; if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) { // Question is not a hotspot if (!$only_questions) { $questionDescription = $objQuestionTmp->selectDescription(); if ($show_title) { TestCategory::displayCategoryAndTitle($objQuestionTmp->id); echo Display::div($current_item . '. ' . $objQuestionTmp->selectTitle(), array('class' => 'question_title')); } if (!empty($questionDescription)) { echo Display::div($questionDescription, array('class' => 'question_description')); } } if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) { return ''; } echo '<div class="question_options row">'; // construction of the Answer object (also gets all answers details) $objAnswerTmp = new Answer($questionId); $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); $quiz_question_options = Question::readQuestionOption($questionId, $course_id); // For "matching" type here, we need something a little bit special // because the match between the suggestions and the answers cannot be // done easily (suggestions and answers are in the same table), so we // have to go through answers first (elems with "correct" value to 0). $select_items = array(); //This will contain the number of answers on the left side. We call them // suggestions here, for the sake of comprehensions, while the ones // on the right side are called answers $num_suggestions = 0; if (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) { if ($answerType == DRAGGABLE) { $s .= '<div class="col-md-12 ui-widget ui-helper-clearfix"> <div class="clearfix"> <ul class="exercise-draggable-answer ui-helper-reset ui-helper-clearfix">'; } else { $s .= '<div id="drag' . $questionId . '_question" class="drag_question"> <table class="data_table">'; } // Iterate through answers $x = 1; //mark letters for each answer $letter = 'A'; $answer_matching = array(); $cpt1 = array(); for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { $answerCorrect = $objAnswerTmp->isCorrect($answerId); $numAnswer = $objAnswerTmp->selectAutoId($answerId); if ($answerCorrect == 0) { // options (A, B, C, ...) that will be put into the list-box // have the "correct" field set to 0 because they are answer $cpt1[$x] = $letter; $answer_matching[$x] = $objAnswerTmp->selectAnswerByAutoId($numAnswer); $x++; $letter++; } } $i = 1; $select_items[0]['id'] = 0; $select_items[0]['letter'] = '--'; $select_items[0]['answer'] = ''; foreach ($answer_matching as $id => $value) { $select_items[$i]['id'] = $value['id_auto']; $select_items[$i]['letter'] = $cpt1[$id]; $select_items[$i]['answer'] = $value['answer']; $i++; } $user_choice_array_position = array(); if (!empty($user_choice)) { foreach ($user_choice as $item) { $user_choice_array_position[$item['position']] = $item['answer']; } } $num_suggestions = $nbrAnswers - $x + 1; } elseif ($answerType == FREE_ANSWER) { $fck_content = isset($user_choice[0]) && !empty($user_choice[0]['answer']) ? $user_choice[0]['answer'] : null; $form = new FormValidator('free_choice_' . $questionId); $config = array('ToolbarSet' => 'TestFreeAnswer'); $form->addHtmlEditor("choice[" . $questionId . "]", null, false, false, $config); $form->setDefaults(array("choice[" . $questionId . "]" => $fck_content)); $s .= $form->returnForm(); } elseif ($answerType == ORAL_EXPRESSION) { // Add nanog if (api_get_setting('document.enable_nanogong') == 'true') { //@todo pass this as a parameter global $exercise_stat_info, $exerciseId, $exe_id; if (!empty($exercise_stat_info)) { $params = array('exercise_id' => $exercise_stat_info['exe_exo_id'], 'exe_id' => $exercise_stat_info['exe_id'], 'question_id' => $questionId); } else { $params = array('exercise_id' => $exerciseId, 'exe_id' => 'temp_exe', 'question_id' => $questionId); } $nano = new Nanogong($params); echo $nano->show_button(); } $form = new FormValidator('free_choice_' . $questionId); $config = array('ToolbarSet' => 'TestFreeAnswer'); $form->addHtmlEditor("choice[" . $questionId . "]", null, false, false, $config); //$form->setDefaults(array("choice[" . $questionId . "]" => $fck_content)); $s .= $form->returnForm(); } // Now navigate through the possible answers, using the max number of // answers for the question as a limiter $lines_count = 1; // a counter for matching-type answers if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { $header = Display::tag('th', get_lang('Options')); foreach ($objQuestionTmp->options as $item) { if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) { if (in_array($item, $objQuestionTmp->options)) { $header .= Display::tag('th', get_lang($item)); } else { $header .= Display::tag('th', $item); } } else { $header .= Display::tag('th', $item); } } if ($show_comment) { $header .= Display::tag('th', get_lang('Feedback')); } $s .= '<table class="table table-hover table-striped">'; $s .= Display::tag('tr', $header, array('style' => 'text-align:left;')); } if ($show_comment) { if (in_array($answerType, array(MULTIPLE_ANSWER, MULTIPLE_ANSWER_COMBINATION, UNIQUE_ANSWER, UNIQUE_ANSWER_IMAGE, UNIQUE_ANSWER_NO_OPTION, GLOBAL_MULTIPLE_ANSWER))) { $header = Display::tag('th', get_lang('Options')); if ($exercise_feedback == EXERCISE_FEEDBACK_TYPE_END) { $header .= Display::tag('th', get_lang('Feedback')); } $s .= '<table class="table table-hover table-striped">'; $s .= Display::tag('tr', $header, array('style' => 'text-align:left;')); } } $matching_correct_answer = 0; $user_choice_array = array(); if (!empty($user_choice)) { foreach ($user_choice as $item) { $user_choice_array[] = $item['answer']; } } for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { $answer = $objAnswerTmp->selectAnswer($answerId); $answerCorrect = $objAnswerTmp->isCorrect($answerId); $numAnswer = $objAnswerTmp->selectAutoId($answerId); $comment = $objAnswerTmp->selectComment($answerId); $attributes = array(); // Unique answer if (in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION, UNIQUE_ANSWER_IMAGE])) { $input_id = 'choice-' . $questionId . '-' . $answerId; if (isset($user_choice[0]['answer']) && $user_choice[0]['answer'] == $numAnswer) { $attributes = array('id' => $input_id, 'checked' => 1, 'selected' => 1); } else { $attributes = array('id' => $input_id); } if ($debug_mark_answer) { if ($answerCorrect) { $attributes['checked'] = 1; $attributes['selected'] = 1; } } if ($show_comment) { $s .= '<tr><td>'; } if ($answerType == UNIQUE_ANSWER_IMAGE) { if ($show_comment) { if (empty($comment)) { $s .= '<div id="answer' . $questionId . $numAnswer . '" ' . 'class="exercise-unique-answer-image" style="text-align: center">'; } else { $s .= '<div id="answer' . $questionId . $numAnswer . '" ' . 'class="exercise-unique-answer-image col-xs-6 col-sm-12" style="text-align: center">'; } } else { $s .= '<div id="answer' . $questionId . $numAnswer . '" ' . 'class="exercise-unique-answer-image col-xs-6 col-md-3" style="text-align: center">'; } } $answer = Security::remove_XSS($answer, STUDENT); $s .= Display::input('hidden', 'choice2[' . $questionId . ']', '0'); $answer_input = null; if ($answerType == UNIQUE_ANSWER_IMAGE) { $attributes['style'] = 'display: none;'; $answer = '<div class="thumbnail">' . $answer . '</div>'; } $answer_input .= '<label class="radio">'; $answer_input .= Display::input('radio', 'choice[' . $questionId . ']', $numAnswer, $attributes); $answer_input .= $answer; $answer_input .= '</label>'; if ($answerType == UNIQUE_ANSWER_IMAGE) { $answer_input .= "</div>"; } if ($show_comment) { $s .= $answer_input; $s .= '</td>'; $s .= '<td>'; $s .= $comment; $s .= '</td>'; $s .= '</tr>'; } else { $s .= $answer_input; } } elseif ($answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == GLOBAL_MULTIPLE_ANSWER) { $input_id = 'choice-' . $questionId . '-' . $answerId; $answer = Security::remove_XSS($answer, STUDENT); if (in_array($numAnswer, $user_choice_array)) { $attributes = array('id' => $input_id, 'checked' => 1, 'selected' => 1); } else { $attributes = array('id' => $input_id); } if ($debug_mark_answer) { if ($answerCorrect) { $attributes['checked'] = 1; $attributes['selected'] = 1; } } if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) { $s .= '<input type="hidden" name="choice2[' . $questionId . ']" value="0" />'; $answer_input = '<label class="checkbox">'; $answer_input .= Display::input('checkbox', 'choice[' . $questionId . '][' . $numAnswer . ']', $numAnswer, $attributes); $answer_input .= $answer; $answer_input .= '</label>'; if ($show_comment) { $s .= '<tr><td>'; $s .= $answer_input; $s .= '</td>'; $s .= '<td>'; $s .= $comment; $s .= '</td>'; $s .= '</tr>'; } else { $s .= $answer_input; } } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) { $my_choice = array(); if (!empty($user_choice_array)) { foreach ($user_choice_array as $item) { $item = explode(':', $item); $my_choice[$item[0]] = $item[1]; } } $s .= '<tr>'; $s .= Display::tag('td', $answer); if (!empty($quiz_question_options)) { foreach ($quiz_question_options as $id => $item) { if (isset($my_choice[$numAnswer]) && $id == $my_choice[$numAnswer]) { $attributes = array('checked' => 1, 'selected' => 1); } else { $attributes = array(); } if ($debug_mark_answer) { if ($id == $answerCorrect) { $attributes['checked'] = 1; $attributes['selected'] = 1; } } $s .= Display::tag('td', Display::input('radio', 'choice[' . $questionId . '][' . $numAnswer . ']', $id, $attributes), array('style' => '')); } } if ($show_comment) { $s .= '<td>'; $s .= $comment; $s .= '</td>'; } $s .= '</tr>'; } } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) { // multiple answers $input_id = 'choice-' . $questionId . '-' . $answerId; if (in_array($numAnswer, $user_choice_array)) { $attributes = array('id' => $input_id, 'checked' => 1, 'selected' => 1); } else { $attributes = array('id' => $input_id); } if ($debug_mark_answer) { if ($answerCorrect) { $attributes['checked'] = 1; $attributes['selected'] = 1; } } $answer = Security::remove_XSS($answer, STUDENT); $answer_input = '<input type="hidden" name="choice2[' . $questionId . ']" value="0" />'; $answer_input .= '<label class="checkbox">'; $answer_input .= Display::input('checkbox', 'choice[' . $questionId . '][' . $numAnswer . ']', 1, $attributes); $answer_input .= $answer; $answer_input .= '</label>'; if ($show_comment) { $s .= '<tr>'; $s .= '<td>'; $s .= $answer_input; $s .= '</td>'; $s .= '<td>'; $s .= $comment; $s .= '</td>'; $s .= '</tr>'; } else { $s .= $answer_input; } } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { $s .= '<input type="hidden" name="choice2[' . $questionId . ']" value="0" />'; $my_choice = array(); if (!empty($user_choice_array)) { foreach ($user_choice_array as $item) { $item = explode(':', $item); if (isset($item[1]) && isset($item[0])) { $my_choice[$item[0]] = $item[1]; } } } $answer = Security::remove_XSS($answer, STUDENT); $s .= '<tr>'; $s .= Display::tag('td', $answer); foreach ($objQuestionTmp->options as $key => $item) { if (isset($my_choice[$numAnswer]) && $key == $my_choice[$numAnswer]) { $attributes = array('checked' => 1, 'selected' => 1); } else { $attributes = array(); } if ($debug_mark_answer) { if ($key == $answerCorrect) { $attributes['checked'] = 1; $attributes['selected'] = 1; } } $s .= Display::tag('td', Display::input('radio', 'choice[' . $questionId . '][' . $numAnswer . ']', $key, $attributes)); } if ($show_comment) { $s .= '<td>'; $s .= $comment; $s .= '</td>'; } $s .= '</tr>'; } elseif ($answerType == FILL_IN_BLANKS) { // display the question, with field empty, for student to fill it, // or filled to display the answer in the Question preview of the exercice/admin.php page $displayForStudent = true; $listAnswerInformations = FillBlanks::getAnswerInfo($answer); $separatorStartRegexp = FillBlanks::escapeForRegexp($listAnswerInformations['blankseparatorstart']); $separatorEndRegexp = FillBlanks::escapeForRegexp($listAnswerInformations['blankseparatorend']); list($answer) = explode('::', $answer); //Correct answers $correctAnswerList = $listAnswerInformations['tabwords']; //Student's answer $studentAnswerList = array(); if (isset($user_choice[0]['answer'])) { $arrayStudentAnswer = FillBlanks::getAnswerInfo($user_choice[0]['answer'], true); $studentAnswerList = $arrayStudentAnswer['studentanswer']; } // If the question must be shown with the answer (in page exercice/admin.php) for teacher preview // set the student-answer to the correct answer if ($debug_mark_answer) { $studentAnswerList = $correctAnswerList; $displayForStudent = false; } if (!empty($correctAnswerList) && !empty($studentAnswerList)) { $answer = ""; for ($i = 0; $i < count($listAnswerInformations["commonwords"]) - 1; $i++) { // display the common word $answer .= $listAnswerInformations["commonwords"][$i]; // display the blank word $correctItem = $listAnswerInformations["tabwords"][$i]; $correctItemRegexp = $correctItem; // replace / with \/ to allow the preg_replace bellow and all the regexp char $correctItemRegexp = FillBlanks::getRegexpProtected($correctItemRegexp); if (isset($studentAnswerList[$i])) { // If student already started this test and answered this question, // fill the blank with his previous answers // may be "" if student viewed the question, but did not fill the blanks $correctItem = $studentAnswerList[$i]; } $attributes["style"] = "width:" . $listAnswerInformations["tabinputsize"][$i] . "px"; $answer .= FillBlanks::getFillTheBlankHtml($separatorStartRegexp, $separatorEndRegexp, $correctItemRegexp, $questionId, $correctItem, $attributes, $answer, $listAnswerInformations, $displayForStudent, $i); } // display the last common word $answer .= $listAnswerInformations["commonwords"][$i]; } else { // display empty [input] with the right width for student to fill it $separatorStartRegexp = FillBlanks::escapeForRegexp($listAnswerInformations['blankseparatorstart']); $separatorEndRegexp = FillBlanks::escapeForRegexp($listAnswerInformations['blankseparatorend']); $answer = ""; for ($i = 0; $i < count($listAnswerInformations["commonwords"]) - 1; $i++) { // display the common words $answer .= $listAnswerInformations["commonwords"][$i]; // display the blank word $attributes["style"] = "width:" . $listAnswerInformations["tabinputsize"][$i] . "px"; $correctItem = $listAnswerInformations["tabwords"][$i]; $correctItemRegexp = $correctItem; // replace / with \/ to allow the preg_replace bellow and all the regexp char $correctItemRegexp = FillBlanks::getRegexpProtected($correctItemRegexp); $answer .= FillBlanks::getFillTheBlankHtml($separatorStartRegexp, $separatorEndRegexp, $correctItemRegexp, $questionId, '', $attributes, $answer, $listAnswerInformations, $displayForStudent, $i); } // display the last common word $answer .= $listAnswerInformations["commonwords"][$i]; } $s .= $answer; } elseif ($answerType == CALCULATED_ANSWER) { /* * In the CALCULATED_ANSWER test * you mustn't have [ and ] in the textarea * you mustn't have @@ in the textarea * the text to find mustn't be empty or contains only spaces * the text to find mustn't contains HTML tags * the text to find mustn't contains char " */ if ($origin !== null) { global $exe_id; $trackAttempts = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $sql = 'SELECT answer FROM ' . $trackAttempts . ' WHERE exe_id=' . $exe_id . ' AND question_id=' . $questionId; $rsLastAttempt = Database::query($sql); $rowLastAttempt = Database::fetch_array($rsLastAttempt); $answer = $rowLastAttempt['answer']; if (empty($answer)) { $calculatedAnswerId = []; $calculatedAnswerId[$questionId] = mt_rand(1, $nbrAnswers); $answer = $objAnswerTmp->selectAnswer($calculatedAnswerId[$questionId]); Session::write('calculatedAnswerId', $calculatedAnswerId); } } list($answer) = explode('@@', $answer); // $correctAnswerList array of array with correct anwsers 0=> [0=>[\p] 1=>[plop]] api_preg_match_all('/\\[[^]]+\\]/', $answer, $correctAnswerList); // get student answer to display it if student go back to previous calculated answer question in a test if (isset($user_choice[0]['answer'])) { api_preg_match_all('/\\[[^]]+\\]/', $answer, $studentAnswerList); $studentAnswerListTobecleaned = $studentAnswerList[0]; $studentAnswerList = array(); for ($i = 0; $i < count($studentAnswerListTobecleaned); $i++) { $answerCorrected = $studentAnswerListTobecleaned[$i]; $answerCorrected = api_preg_replace('| / <font color="green"><b>.*$|', '', $answerCorrected); $answerCorrected = api_preg_replace('/^\\[/', '', $answerCorrected); $answerCorrected = api_preg_replace('|^<font color="red"><s>|', '', $answerCorrected); $answerCorrected = api_preg_replace('|</s></font>$|', '', $answerCorrected); $answerCorrected = '[' . $answerCorrected . ']'; $studentAnswerList[] = $answerCorrected; } } // If display preview of answer in test view for exemple, set the student answer to the correct answers if ($debug_mark_answer) { // contain the rights answers surronded with brackets $studentAnswerList = $correctAnswerList[0]; } /* Split the response by bracket tabComments is an array with text surrounding the text to find we add a space before and after the answerQuestion to be sure to have a block of text before and after [xxx] patterns so we have n text to find ([xxx]) and n+1 block of texts before, between and after the text to find */ $tabComments = api_preg_split('/\\[[^]]+\\]/', ' ' . $answer . ' '); if (!empty($correctAnswerList) && !empty($studentAnswerList)) { $answer = ""; $i = 0; foreach ($studentAnswerList as $studentItem) { // remove surronding brackets $studentResponse = api_substr($studentItem, 1, api_strlen($studentItem) - 2); $size = strlen($studentItem); $attributes['class'] = self::detectInputAppropriateClass($size); $answer .= $tabComments[$i] . Display::input('text', "choice[{$questionId}][]", $studentResponse, $attributes); $i++; } $answer .= $tabComments[$i]; } else { // display exercise with empty input fields // every [xxx] are replaced with an empty input field foreach ($correctAnswerList[0] as $item) { $size = strlen($item); $attributes['class'] = self::detectInputAppropriateClass($size); $answer = str_replace($item, Display::input('text', "choice[{$questionId}][]", '', $attributes), $answer); } } if ($origin !== null) { $s = $answer; break; } else { $s .= $answer; } } elseif ($answerType == MATCHING) { // matching type, showing suggestions and answers // TODO: replace $answerId by $numAnswer if ($answerCorrect != 0) { // only show elements to be answered (not the contents of // the select boxes, who are corrrect = 0) $s .= '<tr><td width="45%" valign="top">'; $parsed_answer = $answer; //left part questions $s .= '<p class="indent">' . $lines_count . '. ' . $parsed_answer . '</p></td>'; //middle part (matches selects) $s .= '<td width="10%" valign="top" align="center" > <div class="select-matching"> <select name="choice[' . $questionId . '][' . $numAnswer . ']">'; // fills the list-box foreach ($select_items as $key => $val) { // set $debug_mark_answer to true at function start to // show the correct answer with a suffix '-x' $selected = ''; if ($debug_mark_answer) { if ($val['id'] == $answerCorrect) { $selected = 'selected="selected"'; } } //$user_choice_array_position if (isset($user_choice_array_position[$numAnswer]) && $val['id'] == $user_choice_array_position[$numAnswer]) { $selected = 'selected="selected"'; } $s .= '<option value="' . $val['id'] . '" ' . $selected . '>' . $val['letter'] . '</option>'; } // end foreach() $s .= '</select></div></td><td width="5%" class="separate"> </td>'; $s .= '<td width="40%" valign="top" >'; if (isset($select_items[$lines_count])) { $s .= '<div class="text-right"><p class="indent">' . $select_items[$lines_count]['letter'] . '. ' . $select_items[$lines_count]['answer'] . '</p></div>'; } else { $s .= ' '; } $s .= '</td>'; $s .= '</tr>'; $lines_count++; //if the left side of the "matching" has been completely // shown but the right side still has values to show... if ($lines_count - 1 == $num_suggestions) { // if it remains answers to shown at the right side while (isset($select_items[$lines_count])) { $s .= '<tr> <td colspan="2"></td> <td valign="top">'; $s .= '<b>' . $select_items[$lines_count]['letter'] . '.</b> ' . $select_items[$lines_count]['answer']; $s .= "</td>\n </tr>"; $lines_count++; } // end while() } // end if() $matching_correct_answer++; } } elseif ($answerType == DRAGGABLE) { if ($answerCorrect != 0) { $parsed_answer = $answer; /*$lines_count = ''; $data = $objAnswerTmp->getAnswerByAutoId($numAnswer); $data = $objAnswerTmp->getAnswerByAutoId($data['correct']); $lines_count = $data['answer'];*/ $windowId = $questionId . '_' . $lines_count; $s .= '<li class="touch-items" id="' . $windowId . '">'; $s .= Display::div($parsed_answer, ['id' => "window_{$windowId}", 'class' => "window{$questionId}_question_draggable exercise-draggable-answer-option"]); $selectedValue = 0; $draggableSelectOptions = []; foreach ($select_items as $key => $val) { if ($debug_mark_answer) { if ($val['id'] == $answerCorrect) { $selectedValue = $val['id']; } } if (isset($user_choice[$matching_correct_answer]) && $val['id'] == $user_choice[$matching_correct_answer]['answer']) { $selectedValue = $val['id']; } $draggableSelectOptions[$val['id']] = $val['letter']; } $s .= Display::select("choice[{$questionId}][{$numAnswer}]", $draggableSelectOptions, $selectedValue, ['id' => "window_{$windowId}_select", 'class' => 'select_option', 'style' => 'display: none;'], false); if (!empty($answerCorrect) && !empty($selectedValue)) { $s .= <<<JAVASCRIPT <script> \$(function() { DraggableAnswer.deleteItem( \$('#{$questionId}_{$selectedValue}'), \$('#drop_{$windowId}') ); }); </script> JAVASCRIPT; } if (isset($select_items[$lines_count])) { $s .= Display::div(Display::tag('b', $select_items[$lines_count]['letter']) . $select_items[$lines_count]['answer'], ['id' => "window_{$windowId}_answer", 'style' => 'display: none;']); } else { $s .= ' '; } $lines_count++; if ($lines_count - 1 == $num_suggestions) { while (isset($select_items[$lines_count])) { $s .= Display::tag('b', $select_items[$lines_count]['letter']); $s .= $select_items[$lines_count]['answer']; $lines_count++; } } $matching_correct_answer++; $s .= '</li>'; } } elseif ($answerType == MATCHING_DRAGGABLE) { if ($answerId == 1) { echo $objAnswerTmp->getJs(); } if ($answerCorrect != 0) { $parsed_answer = $answer; $windowId = "{$questionId}_{$lines_count}"; $s .= <<<HTML <tr> <td widht="45%"> <div id="window_{$windowId}" class="window window_left_question window{$questionId}_question"> <strong>{$lines_count}.</strong> {$parsed_answer} </div> </td> <td width="10%"> HTML; $selectedValue = 0; $selectedPosition = 0; $questionOptions = []; $iTempt = 0; foreach ($select_items as $key => $val) { if ($debug_mark_answer) { if ($val['id'] == $answerCorrect) { $selectedValue = $val['id']; $selectedPosition = $iTempt; } } if (isset($user_choice[$matching_correct_answer]) && $val['id'] == $user_choice[$matching_correct_answer]['answer']) { $selectedValue = $val['id']; $selectedPosition = $iTempt; } $questionOptions[$val['id']] = $val['letter']; $iTempt++; } $s .= Display::select("choice[{$questionId}][{$numAnswer}]", $questionOptions, $selectedValue, ['id' => "window_{$windowId}_select", 'class' => 'hidden'], false); if (!empty($answerCorrect) && !empty($selectedValue)) { // Show connect if is not freeze (question preview) if (!$freeze) { $s .= <<<JAVASCRIPT <script> \$(document).on('ready', function () { jsPlumb.ready(function() { jsPlumb.connect({ source: 'window_{$windowId}', target: 'window_{$questionId}_{$selectedPosition}_answer', endpoint: ['Blank', {radius: 15}], anchors: ['RightMiddle', 'LeftMiddle'], paintStyle: {strokeStyle: '#8A8888', lineWidth: 8}, connector: [ MatchingDraggable.connectorType, {curvines: MatchingDraggable.curviness} ] }); }); }); </script> JAVASCRIPT; } } $s .= <<<HTML </td> <td width="45%"> HTML; if (isset($select_items[$lines_count])) { $s .= <<<HTML <div id="window_{$windowId}_answer" class="window window_right_question"> <strong>{$select_items[$lines_count]['letter']}.</strong> {$select_items[$lines_count]['answer']} </div> HTML; } else { $s .= ' '; } $s .= '</td></tr>'; $lines_count++; if ($lines_count - 1 == $num_suggestions) { while (isset($select_items[$lines_count])) { $s .= <<<HTML <tr> <td colspan="2"></td> <td> <strong>{$select_items[$lines_count]['letter']}</strong> {$select_items[$lines_count]['answer']} </td> </tr> HTML; $lines_count++; } } $matching_correct_answer++; } } } // end for() if ($show_comment) { $s .= '</table>'; } elseif (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE, UNIQUE_ANSWER_NO_OPTION, MULTIPLE_ANSWER_TRUE_FALSE, MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE])) { $s .= '</table>'; } if ($answerType == DRAGGABLE) { $s .= "</ul>"; $s .= "</div>"; //clearfix $counterAnswer = 1; $s .= '<div class="col-md-12"><div class="row">'; for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { $answerCorrect = $objAnswerTmp->isCorrect($answerId); $windowId = $questionId . '_' . $counterAnswer; if ($answerCorrect) { $s .= Display::div($counterAnswer, ['id' => "drop_{$windowId}", 'class' => 'droppable col-md-2']); $counterAnswer++; } } $s .= '</div>'; // row $s .= '</div>'; // col-md-12 $s .= '</div>'; // col-md-12 ui-widget ui-helper-clearfix } if (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) { $s .= '</div>'; //drag_question } $s .= '</div>'; //question_options row // destruction of the Answer object unset($objAnswerTmp); // destruction of the Question object unset($objQuestionTmp); if ($origin != 'export') { echo $s; } else { return $s; } } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) { global $exerciseId, $exe_id; // Question is a HOT_SPOT //checking document/images visibility if (api_is_platform_admin() || api_is_course_admin()) { $course = api_get_course_info(); $doc_id = DocumentManager::get_document_id($course, '/images/' . $pictureName); if (is_numeric($doc_id)) { $images_folder_visibility = api_get_item_visibility($course, 'document', $doc_id, api_get_session_id()); if (!$images_folder_visibility) { //This message is shown only to the course/platform admin if the image is set to visibility = false Display::display_warning_message(get_lang('ChangeTheVisibilityOfTheCurrentImage')); } } } $questionName = $objQuestionTmp->selectTitle(); $questionDescription = $objQuestionTmp->selectDescription(); if ($freeze) { echo "\n <script>\n \$(document).on('ready', function () {\n new " . ($answerType == HOT_SPOT ? "HotspotQuestion" : "DelineationQuestion") . "({\n questionId: {$questionId},\n exerciseId: {$exerciseId},\n selector: '#hotspot-preview-{$questionId}',\n for: 'preview'\n });\n });\n </script>\n <div id=\"hotspot-preview-{$questionId}\"></div>\n "; return; } // Get the answers, make a list $objAnswerTmp = new Answer($questionId); $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); // get answers of hotpost $answers_hotspot = array(); for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { $answers = $objAnswerTmp->selectAnswerByAutoId($objAnswerTmp->selectAutoId($answerId)); $answers_hotspot[$answers['id']] = $objAnswerTmp->selectAnswer($answerId); } $answerList = ''; if ($answerType != HOT_SPOT_DELINEATION) { $answerList = ' <div class="well well-sm"> <h5 class="page-header">' . get_lang('HotspotZones') . '</h5> <ol> '; if (!empty($answers_hotspot)) { ksort($answers_hotspot); $countAnswers = 1; foreach ($answers_hotspot as $value) { $answerList .= "<li><p>{$countAnswers} - {$value}</p></li>"; $countAnswers++; } } $answerList .= ' </ol> </div> '; } if (!$only_questions) { if ($show_title) { TestCategory::displayCategoryAndTitle($objQuestionTmp->id); echo '<div class="question_title">' . $current_item . '. ' . $questionName . '</div>'; } //@todo I need to the get the feedback type echo <<<HOTSPOT <input type="hidden" name="hidden_hotspot_id" value="{$questionId}" /> <div class="exercise_questions"> {$questionDescription} <div class="row"> HOTSPOT; } $canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1'); $s .= "\n <div class=\"col-sm-8 col-md-9\">\n <div class=\"hotspot-image\"></div>\n <script>\n \$(document).on('ready', function () {\n new " . ($answerType == HOT_SPOT_DELINEATION ? 'DelineationQuestion' : 'HotspotQuestion') . "({\n questionId: {$questionId},\n exerciseId: {$exe_id},\n selector: '#question_div_' + {$questionId} + ' .hotspot-image',\n for: 'user'\n });\n });\n </script>\n </div>\n <div class=\"col-sm-4 col-md-3\">\n {$answerList}\n </div>\n "; echo <<<HOTSPOT {$s} </div> </div> HOTSPOT; } return $nbrAnswers; }
api_not_allowed(); } } /* Header and Breadcrumbs */ $my_search = isset($_GET['search']) ? $_GET['search'] : ''; $my_action = isset($_GET['action']) ? $_GET['action'] : ''; $gradebook = null; if (isset($_SESSION['gradebook'])) { $gradebook = $_SESSION['gradebook']; } if (!empty($gradebook) && $gradebook == 'view') { $interbreadcrumb[] = array('url' => '../gradebook/' . $_SESSION['gradebook_dest'], 'name' => get_lang('ToolGradebook')); } if (!empty($_GET['gidReq'])) { $toolgroup = Database::escape_string($_GET['gidReq']); Session::write('toolgroup', $toolgroup); } $forumUrl = api_get_path(WEB_CODE_PATH) . 'forum/'; if ($origin == 'group') { $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH) . 'group/group.php', 'name' => get_lang('Groups')); $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH) . 'group/group_space.php?' . api_get_cidreq(), 'name' => get_lang('GroupSpace') . ' ' . $group_properties['name']); $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Forum') . ' ' . Security::remove_XSS($current_forum['forum_title'])); } else { $interbreadcrumb[] = array('url' => $forumUrl . 'index.php?search=' . Security::remove_XSS($my_search), 'name' => get_lang('ForumCategories')); $interbreadcrumb[] = array('url' => $forumUrl . 'viewforumcategory.php?forumcategory=' . $current_forum_category['cat_id'] . '&search=' . Security::remove_XSS(urlencode($my_search)), 'name' => prepare4display($current_forum_category['cat_title'])); $interbreadcrumb[] = array('url' => '#', 'name' => Security::remove_XSS($current_forum['forum_title'])); } if ($origin == 'learnpath') { Display::display_reduced_header(); } else { // The last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string.
/** * * @global int $_cid * @global array $_course * @global int $_gid * * @param int $group_id * @param bool $reset */ static function init_group($group_id, $reset) { global $_cid; global $_course; global $_gid; if ($reset) { // session data refresh requested if ($group_id && $_cid && !empty($_course['real_id'])) { // have keys to search data $group_table = Database::get_course_table(TABLE_GROUP); $sql = "SELECT * FROM {$group_table} WHERE c_id = " . $_course['real_id'] . " AND id = '{$group_id}'"; $result = Database::query($sql); if (Database::num_rows($result) > 0) { // This group has recorded status related to this course $gpData = Database::fetch_array($result); $_gid = $gpData['id']; Session::write('_gid', $_gid); } else { Session::erase('_gid'); } } elseif (isset($_SESSION['_gid']) or isset($_gid)) { // Keys missing => not anymore in the group - course relation Session::erase('_gid'); } } elseif (isset($_SESSION['_gid'])) { // continue with the previous values $_gid = $_SESSION['_gid']; } else { //if no previous value, assign caracteristic undefined value $_gid = -1; } //set variable according to student_view_enabled choices if (api_get_setting('course.student_view_enabled') == "true") { if (isset($_GET['isStudentView'])) { if ($_GET['isStudentView'] == 'true') { if (isset($_SESSION['studentview'])) { if (!empty($_SESSION['studentview'])) { // switching to studentview $_SESSION['studentview'] = 'studentview'; } } } elseif ($_GET['isStudentView'] == 'false') { if (isset($_SESSION['studentview'])) { if (!empty($_SESSION['studentview'])) { // switching to teacherview $_SESSION['studentview'] = 'teacherview'; } } } } elseif (!empty($_SESSION['studentview'])) { //all is fine, no change to that, obviously } elseif (empty($_SESSION['studentview'])) { // We are in teacherview here $_SESSION['studentview'] = 'teacherview'; } } }
* @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled. * @todo Check if this code is used. I think this code is never executed because after clicking the submit button * the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending * on api_get_setting('page_after_login'). */ if (!empty($_POST['submitAuth'])) { // The user has been already authenticated, we are now to find the last login of the user. if (isset($_user['user_id'])) { $track_login_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); $sql_last_login = "******" . $_user['user_id'] . "'\n ORDER BY login_date DESC LIMIT 1"; $result_last_login = Database::query($sql_last_login); if (!$result_last_login) { if (Database::num_rows($result_last_login) > 0) { $user_last_login_datetime = Database::fetch_array($result_last_login); $user_last_login_datetime = $user_last_login_datetime[0]; Session::write('user_last_login_datetime', $user_last_login_datetime); } } //Event::event_login(); } // End login -- if ($_POST['submitAuth']) } else { // Only if login form was not sent because if the form is sent the user was already on the page. Event::event_open(); } if (api_get_setting('display_categories_on_homepage') == 'true') { $controller->tpl->assign('course_category_block', $controller->return_courses_in_categories()); } $controller->set_login_form(); //@todo move this inside the IndexManager if (!api_is_anonymous()) {
$sql = "SELECT path, docs.id, props.to_group_id, docs.c_id\n FROM {$doc_table} AS docs\n INNER JOIN {$prop_table} AS props\n ON\n docs.id = props.ref AND\n docs.c_id = props.c_id\n WHERE\n docs.c_id = {$courseId} AND\n props.tool ='" . TOOL_DOCUMENT . "' AND\n docs.path LIKE '" . $invisible_folders['path'] . "/%' AND\n docs.filetype = 'file' AND\n (props.session_id IN ('0', '{$sessionId}') OR props.session_id IS NULL) AND\n props.visibility ='1'"; $query3 = Database::query($sql); // Add tem to an array while ($files_in_invisible_folder = Database::fetch_assoc($query3)) { $files_in_invisible_folder_path[] = $files_in_invisible_folder['path']; $files[$files_in_invisible_folder['path']] = $files_in_invisible_folder; } } // Compare the array with visible files and the array with files in invisible folders // and keep the difference (= all visible files that are not in an invisible folder) $files_for_zipfile = diff((array) $all_visible_files_path, (array) $files_in_invisible_folder_path); } else { // No invisible folders found, so all visible files can be added to the zipfile $files_for_zipfile = $all_visible_files_path; } Session::write('doc_files_to_download', $files); // Add all files in our final array to the zipfile for ($i = 0; $i < count($files_for_zipfile); $i++) { $zip->add($sysCoursePath . $courseInfo['path'] . '/document' . $files_for_zipfile[$i], PCLZIP_OPT_REMOVE_PATH, $sysCoursePath . $courseInfo['path'] . '/document' . $remove_dir, PCLZIP_CB_PRE_ADD, 'fixDocumentNameCallback'); } Session::erase('doc_files_to_download'); } // Launch event Event::event_download($path == '/' ? 'documents.zip (folder)' : basename($path) . '.zip (folder)'); // Start download of created file $name = $path == '/' ? 'documents.zip' : $documentInfo['title'] . '.zip'; if (Security::check_abs_path($tempZipFile, api_get_path(SYS_ARCHIVE_PATH))) { $result = DocumentManager::file_send_for_download($tempZipFile, true, $name); @unlink($tempZipFile); exit; } else {
* @package chamilo.auth.ldap */ /** * An external authentification module needs to set * - $loginFailed * - $uidReset * - $_user['user_id'] * - register the $_user['user_id'] in the session * * As the LDAP code shows, this is not as difficult as you might think. * LDAP authentification module * this calls the loginWithLdap function * from the LDAP library, and sets a few * variables based on the result. */ //require_once('../../inc/global.inc.php'); - this script should be loaded by the /index.php script anyway, so global is already loaded use ChamiloSession as Session; require_once 'authldap.php'; $loginLdapSucces = ldap_login($login, $password); if ($loginLdapSucces) { $loginFailed = false; $uidReset = true; $_user['user_id'] = $uData['user_id']; Session::write('_uid', $_uid); // Jand: copied from event_login in events.lib.php to enable login statistics: Event::event_login($uData['user_id']); } else { $loginFailed = true; unset($_user['user_id']); $uidReset = false; }
$_setting['show_navigation_menu'] = 'false'; $scorm_css_header = true; $lp_theme_css = $learnPath->get_theme(); // Sets the css theme of the LP this call is also use at the frames (toc, nav, message). if ($learnPath->mode == 'fullscreen') { $htmlHeadXtra[] = "<script>window.open('{$src}','content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');</script>"; } // Not in fullscreen mode. // Check if audio recorder needs to be in studentview. if (isset($_SESSION['status']) && $_SESSION['status'][$course_code] == 5) { $audio_recorder_studentview = true; } else { $audio_recorder_studentview = false; } // Set flag to ensure lp_header.php is loaded by this script (flag is unset in lp_header.php). Session::write('loaded_lp_view', true); $display_none = ''; $margin_left = '340px'; //Media player code $display_mode = $learnPath->mode; $scorm_css_header = true; $lp_theme_css = $learnPath->get_theme(); // Setting up the CSS theme if exists. if (!empty($lp_theme_css) && !empty($mycourselptheme) && $mycourselptheme != -1 && $mycourselptheme == 1) { global $lp_theme_css; } else { $lp_theme_css = $my_style; } $progress_bar = ""; if (!api_is_invitee()) { $progress_bar = $learnPath->getProgressBar();