$certificate = new Certificate(); $text = $certificate->parse_certificate_variables($content_html['variables']); $result = $certificate->generate_qr($text, $qr_code_filename); $new_content_html = $content_html['content']; $path_image = api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/images/gallery'; $new_content_html = str_replace('../images/gallery', $path_image, $new_content_html); $path_image_in_default_course = api_get_path(WEB_CODE_PATH) . 'default_course_document'; $new_content_html = str_replace('/main/default_course_document', $path_image_in_default_course, $new_content_html); $new_content_html = str_replace(SYS_CODE_PATH . 'img/', api_get_path(WEB_IMG_PATH), $new_content_html); Display::display_reduced_header(); echo '<style>body {background:none;}</style> <style media="print" type="text/css"> #print_div { visibility:hidden; } </style>'; echo '<a href="javascript:window.print();" style="float:right; padding:4px;" id="print_div"> <img src="../img/printmgr.gif" alt="' . get_lang('Print') . '"/>' . get_lang('Print') . '</a>'; if (is_file($qr_code_filename) && is_readable($qr_code_filename)) { $new_content_html = str_replace('((certificate_barcode))', Display::img($qr_code_web_filename), $new_content_html); } print_r($new_content_html); exit; } } // Is the document tool visible? // Check whether the tool is actually visible /*$table_course_tool = Database::get_course_table(TABLE_TOOL_LIST); $course_id = api_get_course_int_id(); $tool_sql = 'SELECT visibility FROM '.$table_course_tool.' WHERE c_id = '.$course_id.' AND name = "'.TOOL_DOCUMENT.'" LIMIT 1'; $tool_result = Database::query($tool_sql); $tool_row = Database::fetch_array($tool_result); $tool_visibility = $tool_row['visibility'];*/
$result = ArrayClass::msort($result, 'skills_acquired', 'asc'); $skills_in_course = array(); if (!empty($result)) { foreach ($result as &$item) { $user_info = api_get_user_info($item['user_id']); $personal_course_list = UserManager::get_personal_session_course_list($item['user_id']); $count_skill_by_course = array(); foreach ($personal_course_list as $course_item) { if (!isset($skills_in_course[$course_item['code']])) { $count_skill_by_course[$course_item['code']] = $skill->get_count_skills_by_course($course_item['code']); $skills_in_course[$course_item['code']] = $count_skill_by_course[$course_item['code']]; } else { $count_skill_by_course[$course_item['code']] = $skills_in_course[$course_item['code']]; } } $item['photo'] = Display::img($user_info['avatar_small'], $user_info['complete_name'], [], false); $item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0; } } break; case 'get_course_announcements': $columns = array('title', 'username', 'insert_date', 'actions'); $titleToSearch = isset($_REQUEST['title_to_search']) ? $_REQUEST['title_to_search'] : ''; $userIdToSearch = isset($_REQUEST['user_id_to_search']) ? $_REQUEST['user_id_to_search'] : 0; $result = AnnouncementManager::getAnnouncements(null, null, false, $start, $limit, $sidx, $sord, $titleToSearch, $userIdToSearch); break; case 'get_work_teacher': $columns = array('type', 'title', 'sent_date', 'expires_on', 'amount', 'actions'); $result = getWorkListTeacher($start, $limit, $sidx, $sord, $whereCondition); break; case 'get_work_student':
/** * Return breadcrumb * @return string */ public function returnBreadcrumb() { $interbreadcrumb = $this->app['breadcrumb']; $session_id = api_get_session_id(); $session_name = api_get_session_name($session_id); $_course = api_get_course_info(); $user_id = api_get_user_id(); $course_id = api_get_course_id(); /* Plugins for banner section */ $web_course_path = api_get_path(WEB_COURSE_PATH); /* If the user is a coach he can see the users who are logged in its session */ $navigation = array(); // part 1: Course Homepage. If we are in a course then the first breadcrumb is a link to the course homepage // hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb $session_name = Text::cut($session_name, MAX_LENGTH_BREADCRUMB); $my_session_name = is_null($session_name) ? '' : ' (' . $session_name . ')'; if (!empty($_course) && !isset($_GET['hide_course_breadcrumb'])) { $navigation_item['url'] = $web_course_path . $_course['path'] . '/index.php' . (!empty($session_id) ? '?id_session=' . $session_id : ''); $course_title = Text::cut($_course['name'], MAX_LENGTH_BREADCRUMB); switch (api_get_setting('breadcrumbs_course_homepage')) { case 'get_lang': $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH) . 'home.png', get_lang('CourseHomepageLink')) . ' ' . get_lang('CourseHomepageLink'); break; case 'course_code': $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH) . 'home.png', $_course['official_code']) . ' ' . $_course['official_code']; break; case 'session_name_and_course_title': $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH) . 'home.png', $_course['name'] . $my_session_name) . ' ' . $course_title . $my_session_name; break; default: if (api_get_session_id() != -1) { $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH) . 'home.png', $_course['name'] . $my_session_name) . ' ' . $course_title . $my_session_name; } else { $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH) . 'home.png', $_course['name']) . ' ' . $course_title; } break; } $navigation[] = $navigation_item; } // Part 2: breadcrumbs. // If there is an array $interbreadcrumb defined then these have to appear before the last breadcrumb // (which is the tool itself) if (isset($interbreadcrumb) && is_array($interbreadcrumb)) { foreach ($interbreadcrumb as $breadcrumb_step) { if ($breadcrumb_step['url'] != '#') { $sep = strrchr($breadcrumb_step['url'], '?') ? '&' : '?'; $navigation_item['url'] = $breadcrumb_step['url'] . $sep . api_get_cidreq(); } else { $navigation_item['url'] = '#'; } $navigation_item['title'] = $breadcrumb_step['name']; // titles for shared folders if ($breadcrumb_step['name'] == 'shared_folder') { $navigation_item['title'] = get_lang('UserFolders'); } elseif (strstr($breadcrumb_step['name'], 'shared_folder_session_')) { $navigation_item['title'] = get_lang('UserFolders'); } elseif (strstr($breadcrumb_step['name'], 'sf_user_')) { $userinfo = api_get_user_info(substr($breadcrumb_step['name'], 8)); $navigation_item['title'] = $userinfo['complete_name']; } elseif ($breadcrumb_step['name'] == 'chat_files') { $navigation_item['title'] = get_lang('ChatFiles'); } elseif ($breadcrumb_step['name'] == 'images') { $navigation_item['title'] = get_lang('Images'); } elseif ($breadcrumb_step['name'] == 'video') { $navigation_item['title'] = get_lang('Video'); } elseif ($breadcrumb_step['name'] == 'audio') { $navigation_item['title'] = get_lang('Audio'); } elseif ($breadcrumb_step['name'] == 'flash') { $navigation_item['title'] = get_lang('Flash'); } elseif ($breadcrumb_step['name'] == 'gallery') { $navigation_item['title'] = get_lang('Gallery'); } // Fixes breadcrumb title now we applied the Security::remove_XSS and we cut the string depending of the MAX_LENGTH_BREADCRUMB value $navigation_item['title'] = Text::cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB); $navigation_item['title'] = Security::remove_XSS($navigation_item['title']); $navigation[] = $navigation_item; } } // part 3: The tool itself. If we are on the course homepage we do not want to display the title of the course because this // is the same as the first part of the breadcrumbs (see part 1) $final_navigation = array(); $counter = 0; foreach ($navigation as $index => $navigation_info) { if (!empty($navigation_info['title'])) { if ($navigation_info['url'] == '#') { $final_navigation[$index] = $navigation_info['title']; } else { $final_navigation[$index] = '<a href="' . $navigation_info['url'] . '" class="" target="_top">' . $navigation_info['title'] . '</a>'; } $counter++; } } $html = ''; if (!empty($final_navigation)) { $lis = ''; $i = 0; $final_navigation_count = count($final_navigation); if (!empty($final_navigation)) { if (!empty($home_link)) { $lis .= Display::tag('li', $home_link); } foreach ($final_navigation as $bread) { $bread_check = trim(strip_tags($bread)); if (!empty($bread_check)) { if ($final_navigation_count - 1 > $i) { //$bread .= '<span class="divider">/</span>'; } $lis .= Display::tag('li', $bread); $i++; } } } else { if (!empty($home_link)) { $lis .= Display::tag('li', $home_link); } } $html .= $lis; } return $html; }
/** * Builds an img html tag for the file type * * @param string $type (file/folder) * @param string $path * @return string img html tag */ public static function build_document_icon_tag($type, $path) { $basename = basename($path); $current_session_id = api_get_session_id(); $is_allowed_to_edit = api_is_allowed_to_edit(null, true); $user_image = false; if ($type == 'file') { $icon = choose_image($basename); if (preg_match('/_chnano_.wav$/i', $basename)) { $icon = "jplayer_play.png"; $basename = 'wav' . ' ' . '(Nanogong)'; } else { $basename = substr(strrchr($basename, '.'), 1); } } else { if ($path == '/shared_folder') { $icon = 'folder_users.gif'; if ($is_allowed_to_edit) { $basename = get_lang('HelpUsersFolder'); } else { $basename = get_lang('UserFolders'); } } elseif (strstr($basename, 'sf_user_')) { $userinfo = api_get_user_info(substr($basename, 8)); $icon = $userinfo['avatar_small']; $basename = get_lang('UserFolder') . ' ' . $userinfo['complete_name']; $user_image = true; } elseif (strstr($path, 'shared_folder_session_')) { if ($is_allowed_to_edit) { $basename = '***(' . api_get_session_name($current_session_id) . ')*** ' . get_lang('HelpUsersFolder'); } else { $basename = get_lang('UserFolders') . ' (' . api_get_session_name($current_session_id) . ')'; } $icon = 'folder_users.gif'; } else { $icon = 'folder_document.gif'; if ($path == '/audio') { $icon = 'folder_audio.gif'; if (api_is_allowed_to_edit()) { $basename = get_lang('HelpDefaultDirDocuments'); } else { $basename = get_lang('Audio'); } } elseif ($path == '/flash') { $icon = 'folder_flash.gif'; if (api_is_allowed_to_edit()) { $basename = get_lang('HelpDefaultDirDocuments'); } else { $basename = get_lang('Flash'); } } elseif ($path == '/images') { $icon = 'folder_images.gif'; if (api_is_allowed_to_edit()) { $basename = get_lang('HelpDefaultDirDocuments'); } else { $basename = get_lang('Images'); } } elseif ($path == '/video') { $icon = 'folder_video.gif'; if (api_is_allowed_to_edit()) { $basename = get_lang('HelpDefaultDirDocuments'); } else { $basename = get_lang('Video'); } } elseif ($path == '/images/gallery') { $icon = 'folder_gallery.gif'; if (api_is_allowed_to_edit()) { $basename = get_lang('HelpDefaultDirDocuments'); } else { $basename = get_lang('Gallery'); } } elseif ($path == '/chat_files') { $icon = 'folder_chat.png'; if (api_is_allowed_to_edit()) { $basename = get_lang('HelpFolderChat'); } else { $basename = get_lang('ChatFiles'); } } elseif ($path == '/learning_path') { $icon = 'folder_learningpath.gif'; if (api_is_allowed_to_edit()) { $basename = get_lang('HelpFolderLearningPaths'); } else { $basename = get_lang('LearningPaths'); } } } } if ($user_image) { return Display::img($icon, $basename, array(), false); } return Display::return_icon($icon, $basename, array()); }
/** * Displays the name of the user and makes the link to the user profile * * @param $userInfo * * @return string */ public static function getUserProfileLinkWithPicture($userInfo) { return Display::url(Display::img($userInfo['avatar']), $userInfo['profile_url']); }
/** * Get the extra fields and their formatted values * @param int|string $itemId The item ID (It could be a session_id, course_id or user_id) * @return array The extra fields data */ public function getDataAndFormattedValues($itemId) { $valuesData = array(); $fields = $this->get_all(); foreach ($fields as $field) { if ($field['visible'] != '1') { continue; } $fieldValue = new ExtraFieldValue($this->type); $valueData = $fieldValue->get_values_by_handler_and_field_id($itemId, $field['id'], true); if (!$valueData) { continue; } $displayedValue = get_lang('None'); switch ($field['field_type']) { case ExtraField::FIELD_TYPE_CHECKBOX: if ($valueData !== false && $valueData['value'] == '1') { $displayedValue = get_lang('Yes'); } else { $displayedValue = get_lang('No'); } break; case ExtraField::FIELD_TYPE_DATE: if ($valueData !== false && !empty($valueData['value'])) { $displayedValue = api_format_date($valueData['value'], DATE_FORMAT_LONG_NO_DAY); } break; case ExtraField::FIELD_TYPE_FILE_IMAGE: if ($valueData === false || empty($valueData['value'])) { break; } if (!file_exists(api_get_path(SYS_UPLOAD_PATH) . $valueData['value'])) { break; } $image = Display::img(api_get_path(WEB_UPLOAD_PATH) . $valueData['value'], $field['display_text'], array('width' => '300')); $displayedValue = Display::url($image, api_get_path(WEB_UPLOAD_PATH) . $valueData['value'], array('target' => '_blank')); break; case ExtraField::FIELD_TYPE_FILE: if ($valueData === false || empty($valueData['value'])) { break; } if (!file_exists(api_get_path(SYS_UPLOAD_PATH) . $valueData['value'])) { break; } $displayedValue = Display::url(get_lang('Download'), api_get_path(WEB_UPLOAD_PATH) . $valueData['value'], array('title' => $field['display_text'], 'target' => '_blank')); break; default: $displayedValue = $valueData['value']; break; } $valuesData[] = array('text' => $field['display_text'], 'value' => $displayedValue); } return $valuesData; }
/** * 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 .= <<<HTML <div id="drag{$questionId}_question" class="drag_question"> <table class="data_table"> HTML; } // 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']; $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('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->return_form(); } // 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); $sqlTrackAttempt = 'SELECT answer FROM ' . $trackAttempts . ' WHERE exe_id=' . $exe_id . ' AND question_id=' . $questionId; $rsLastAttempt = Database::query($sqlTrackAttempt); $rowLastAttempt = Database::fetch_array($rsLastAttempt); $answer = $rowLastAttempt['answer']; if (empty($answer)) { $_SESSION['calculatedAnswerId'][$questionId] = mt_rand(1, $nbrAnswers); $answer = $objAnswerTmp->selectAnswer($_SESSION['calculatedAnswerId'][$questionId]); } } 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; $questionOptions = []; 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']; } $questionOptions[$val['id']] = $val['letter']; } $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> jsPlumb.ready(function() { jsPlumb.connect({ source: 'window_{$windowId}', target: 'window_{$questionId}_{$selectedValue}_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></div>"; $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></div>'; } if (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) { $s .= '</div>'; } $s .= '</div>'; // 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) { // 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 Display::img($objQuestionTmp->selectPicturePath()); 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); } // display answers of hotpost order by id $answer_list = '<div style="padding: 10px; margin-left: 0px; border: 1px solid #A4A4A4; height: 408px; width: 200px;"><b>' . get_lang('HotspotZones') . '</b><dl>'; if (!empty($answers_hotspot)) { ksort($answers_hotspot); foreach ($answers_hotspot as $key => $value) { $answer_list .= '<dt>' . $key . '.- ' . $value . '</dt><br />'; } } $answer_list .= '</dl></div>'; if ($answerType == HOT_SPOT_DELINEATION) { $answer_list = ''; $swf_file = 'hotspot_delineation_user'; $swf_height = 405; } else { $swf_file = 'hotspot_user'; $swf_height = 436; } 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 '<input type="hidden" name="hidden_hotspot_id" value="' . $questionId . '" />'; echo '<table class="exercise_questions" > <tr> <td valign="top" colspan="2">'; echo $questionDescription; echo '</td></tr>'; } $canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1'); $s .= '<script type="text/javascript" src="../plugin/hotspot/JavaScriptFlashGateway.js"></script> <script src="../plugin/hotspot/hotspot.js" type="text/javascript" ></script> <script type="text/javascript"> <!-- // Globals // Major version of Flash required var requiredMajorVersion = 7; // Minor version of Flash required var requiredMinorVersion = 0; // Minor version of Flash required var requiredRevision = 0; // the version of javascript supported var jsVersion = 1.0; // --> </script> <script language="VBScript" type="text/vbscript"> <!-- // Visual basic helper required to detect Flash Player ActiveX control version information Function VBGetSwfVer(i) on error resume next Dim swControl, swVersion swVersion = 0 set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i)) if (IsObject(swControl)) then swVersion = swControl.GetVariable("$version") end if VBGetSwfVer = swVersion End Function // --> </script> <script language="JavaScript1.1" type="text/javascript"> <!-- // Detect Client Browser type var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false; var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false; jsVersion = 1.1; // JavaScript helper required to detect Flash Player PlugIn version information function JSGetSwfVer(i) { // NS/Opera version >= 3 check for Flash plugin in plugin array if (navigator.plugins != null && navigator.plugins.length > 0) { if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) { var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : ""; var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description; descArray = flashDescription.split(" "); tempArrayMajor = descArray[2].split("."); versionMajor = tempArrayMajor[0]; versionMinor = tempArrayMajor[1]; if ( descArray[3] != "" ) { tempArrayMinor = descArray[3].split("r"); } else { tempArrayMinor = descArray[4].split("r"); } versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0; flashVer = versionMajor + "." + versionMinor + "." + versionRevision; } else { flashVer = -1; } } // MSN/WebTV 2.6 supports Flash 4 else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4; // WebTV 2.5 supports Flash 3 else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3; // older WebTV supports Flash 2 else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2; // Can\'t detect in all other cases else { flashVer = -1; } return flashVer; } // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) { reqVer = parseFloat(reqMajorVer + "." + reqRevision); // loop backwards through the versions until we find the newest version for (i=25;i>0;i--) { if (isIE && isWin && !isOpera) { versionStr = VBGetSwfVer(i); } else { versionStr = JSGetSwfVer(i); } if (versionStr == -1 ) { return false; } else if (versionStr != 0) { if(isIE && isWin && !isOpera) { tempArray = versionStr.split(" "); tempString = tempArray[1]; versionArray = tempString .split(","); } else { versionArray = versionStr.split("."); } versionMajor = versionArray[0]; versionMinor = versionArray[1]; versionRevision = versionArray[2]; versionString = versionMajor + "." + versionRevision; // 7.0r24 == 7.24 versionNum = parseFloat(versionString); // is the major.revision >= requested major.revision AND the minor version >= requested minor if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) { return true; } else { return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false ); } } } } // --> </script>'; $s .= '<tr><td valign="top" colspan="2" width="520"><table><tr><td width="520"> <script> <!-- // Version check based upon the values entered above in "Globals" var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision); // Check to see if the version meets the requirements for playback if (hasReqestedVersion) { // if we\'ve detected an acceptable version var oeTags = \'<object type="application/x-shockwave-flash" data="../plugin/hotspot/' . $swf_file . '.swf?modifyAnswers=' . $questionId . '&canClick:' . $canClick . '" width="600" height="' . $swf_height . '">\' + \'<param name="wmode" value="transparent">\' + \'<param name="movie" value="../plugin/hotspot/' . $swf_file . '.swf?modifyAnswers=' . $questionId . '&canClick:' . $canClick . '" />\' + \'<\\/object>\'; document.write(oeTags); // embed the Flash Content SWF when all tests are passed } else { // flash is too old or we can\'t detect the plugin var alternateContent = "Error<br \\/>" + "Hotspots requires Macromedia Flash 7.<br \\/>" + "<a href=\\"http://www.macromedia.com/go/getflash/\\">Get Flash<\\/a>"; document.write(alternateContent); // insert non-flash content } // --> </script> </td> <td valign="top" align="left">' . $answer_list . '</td></tr> </table> </td></tr>'; echo $s; echo '</table>'; } return $nbrAnswers; }
/** * Generates an HTML Certificate and fills the path_certificate field in the DB **/ public function generate($params = array()) { //The user directory should be set if (empty($this->certification_user_path) && $this->force_certificate_generation == false) { return false; } require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/be.inc.php'; require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php'; require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/scoredisplay.class.php'; $params['hide_print_button'] = isset($params['hide_print_button']) ? true : false; $my_category = Category::load($this->certificate_data['cat_id']); if (isset($my_category[0]) && $my_category[0]->is_certificate_available($this->user_id)) { $user = api_get_user_info($this->user_id); $scoredisplay = ScoreDisplay::instance(); $scorecourse = $my_category[0]->calc_score($this->user_id); $scorecourse_display = isset($scorecourse) ? $scoredisplay->display_score($scorecourse, SCORE_AVERAGE) : get_lang('NoResultsAvailable'); // Prepare all necessary variables: $organization_name = api_get_setting('Institution'); //$portal_name = api_get_setting('siteName'); $stud_fn = $user['firstname']; $stud_ln = $user['lastname']; //@todo this code is not needed $certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'), $organization_name, $stud_fn . ' ' . $stud_ln, $my_category[0]->get_name(), $scorecourse_display); $certif_text = str_replace("\\n", "\n", $certif_text); //If the gradebook is related to skills we added the skills to the user $skill = new Skill(); $skill->add_skill_to_user($this->user_id, $this->certificate_data['cat_id']); if (is_dir($this->certification_user_path)) { if (!empty($this->certificate_data)) { $new_content_html = get_user_certificate_content($this->user_id, $my_category[0]->get_course_code(), false, $params['hide_print_button']); if ($my_category[0]->get_id() == strval(intval($this->certificate_data['cat_id']))) { $name = $this->certificate_data['path_certificate']; $my_path_certificate = $this->certification_user_path . basename($name); if (file_exists($my_path_certificate) && !empty($name) && !is_dir($my_path_certificate) && $this->force_certificate_generation == false) { //Seems that the file was already generated return true; } else { // Creating new name $name = md5($this->user_id . $this->certificate_data['cat_id']) . '.html'; $my_path_certificate = $this->certification_user_path . $name; $path_certificate = '/' . $name; //Getting QR filename $file_info = pathinfo($path_certificate); $qr_code_filename = $this->certification_user_path . $file_info['filename'] . '_qr.png'; $my_new_content_html = str_replace('((certificate_barcode))', Display::img($this->certification_web_user_path . $file_info['filename'] . '_qr.png', 'QR'), $new_content_html['content']); $my_new_content_html = mb_convert_encoding($my_new_content_html, 'UTF-8', api_get_system_encoding()); $result = @file_put_contents($my_path_certificate, $my_new_content_html); if ($result) { //Updating the path self::update_user_info_about_certificate($this->certificate_data['cat_id'], $this->user_id, $path_certificate); $this->certificate_data['path_certificate'] = $path_certificate; if ($this->html_file_is_generated()) { if (!empty($file_info)) { $text = $this->parse_certificate_variables($new_content_html['variables']); $this->generate_qr($text, $qr_code_filename); } } } return $result; } } } } } return false; }
function return_logo($theme) { $_course = api_get_course_info(); $html = ''; $logoBase = api_get_path(SYS_CSS_PATH) . 'themes/' . $theme . '/images/header-logo.'; $site_name = api_get_setting('platform.site_name'); $attributes = array('title' => $site_name, 'class' => 'img-responsive'); $testServer = api_get_setting('server_type'); if ($testServer == 'test' && is_file($logoBase . 'svg')) { $logo = $logoBase . 'svg'; $attributes['width'] = '245'; $attributes['height'] = '68'; $image_url = api_get_path(WEB_CSS_PATH) . 'themes/' . $theme . '/images/header-logo.svg'; } else { $logo = $logoBase . 'png'; $image_url = api_get_path(WEB_CSS_PATH) . 'themes/' . $theme . '/images/header-logo.png'; } if (file_exists($logo)) { $site_name = api_get_setting('platform.institution') . ' - ' . $site_name; $logo = Display::img($image_url, $site_name, $attributes); $html .= Display::url($logo, api_get_path(WEB_PATH) . 'index.php'); } else { $html .= '<a href="' . api_get_path(WEB_PATH) . 'index.php" target="_top">' . $site_name . '</a>'; $iurl = api_get_setting('platform.institution_url'); $iname = api_get_setting('platform.institution'); if (!empty($iname)) { $html .= '- <a href="' . $iurl . '" target="_top">' . $iname . '</a>'; } // External link section a.k.a Department - Department URL if (isset($_course['extLink']) && $_course['extLink']['name'] != '') { $html .= '<span class="extLinkSeparator"> - </span>'; if ($_course['extLink']['url'] != '') { $html .= '<a class="extLink" href="' . $_course['extLink']['url'] . '" target="_top">'; $html .= $_course['extLink']['name']; $html .= '</a>'; } else { $html .= $_course['extLink']['name']; } } } return $html; }
/** * @param Application $app * @return string */ public function indexAction(Application $app) { $request = $app['request']; $language_file = array('admin', 'exercice', 'gradebook', 'tracking'); // 1. Setting variables needed by jqgrid $action = $request->get('a'); $page = $request->get('page'); //page $limit = $request->get('rows'); //quantity of rows $sidx = $request->get('sidx'); //index (field) to filter $sord = $request->get('sord'); //asc or desc if (strpos(strtolower($sidx), 'asc') !== false) { $sidx = str_replace(array('asc', ','), '', $sidx); $sord = 'asc'; } if (strpos(strtolower($sidx), 'desc') !== false) { $sidx = str_replace(array('desc', ','), '', $sidx); $sord = 'desc'; } if (!in_array($sord, array('asc', 'desc'))) { $sord = 'desc'; } if (!in_array($action, array('get_exercise_results', 'get_hotpotatoes_exercise_results', 'get_work_user_list', 'get_timelines', 'get_user_skill_ranking', 'get_usergroups_teacher', 'get_question_list', 'get_user_list_plugin_widescale'))) { api_protect_admin_script(true); } if ($action == 'get_user_list_plugin_widescale') { $allowed = api_is_drh() || api_is_platform_admin(); if (!$allowed) { api_not_allowed(); } } // Search features. // If there is no search request sent by jqgrid, $where should be empty. $where_condition = ""; $operation = $request->get('oper'); $export_format = $request->get('export_format'); $search_field = $request->get('searchField'); $search_oper = $request->get('searchOper'); $search_string = $request->get('searchString'); $isSearch = $request->get('_search'); $filters = $request->get('filters'); $type = $request->get('type'); $extra_fields = array(); $questionFields = array(); if ($isSearch == 'true') { $where_condition = ' 1 = 1 '; $where_condition_in_form = $this->getWhereClause($search_field, $search_oper, $search_string); if (!empty($where_condition_in_form)) { $where_condition .= ' AND ' . $where_condition_in_form; } $filters = isset($filters) ? json_decode($filters) : false; // for now if (!empty($filters)) { switch ($action) { case 'get_questions': $extraFieldtype = 'question'; break; case 'get_sessions': $extraFieldtype = 'session'; break; } // Extra field. $extraField = new \ExtraField($extraFieldtype); $result = $extraField->getExtraFieldRules($filters, 'extra_'); $extra_fields = $result['extra_fields']; $condition_array = $result['condition_array']; if (!empty($condition_array)) { $where_condition .= ' AND ( '; $where_condition .= implode($filters->groupOp, $condition_array); $where_condition .= ' ) '; } // Question field. $resultQuestion = $extraField->getExtraFieldRules($filters, 'question_'); $questionFields = $resultQuestion['extra_fields']; $condition_array = $resultQuestion['condition_array']; if (!empty($condition_array)) { $where_condition .= ' AND ( '; $where_condition .= implode($filters->groupOp, $condition_array); $where_condition .= ' ) '; } } } // get index row - i.e. user click to sort $sord = $_GET['sord']; // get the direction if (!$sidx) { $sidx = 1; } //2. Selecting the count FIRST //@todo rework this switch ($action) { case 'get_questions': $categoryId = $request->get('categoryId'); $exerciseId = $request->get('exerciseId'); //$courseId = null; //$request->get('courseId'); $courseId = $request->get('courseId'); // Question manager can view all questions if (api_is_question_manager()) { $courseId = null; } $count = \Question::getQuestions($app, $categoryId, $exerciseId, $courseId, array('where' => $where_condition, 'extra' => $extra_fields, 'question' => $questionFields), true); break; case 'get_user_list_plugin_widescale': $count = \UserManager::get_user_data(null, null, null, null, true); break; case 'get_question_list': require_once api_get_path(SYS_CODE_PATH) . 'exercice/exercise.class.php'; $exerciseId = $request->get('exerciseId'); $exercise = new \Exercise(api_get_course_int_id()); $exercise->read($exerciseId); $count = $exercise->selectNbrQuestions(); break; case 'get_group_reporting': $course_id = $request->get('course_id'); $group_id = $request->get('gidReq'); $count = \Tracking::get_group_reporting($course_id, $group_id, 'count'); break; case 'get_user_course_report_resumed': $count = \CourseManager::get_count_user_list_from_course_code(true, 'ruc'); break; case 'get_user_course_report': $count = \CourseManager::get_count_user_list_from_course_code(false); break; case 'get_course_exercise_medias': $course_id = api_get_course_int_id(); $count = \Question::get_count_course_medias($course_id); break; case 'get_user_skill_ranking': $skill = new \Skill(); $count = $skill->get_user_list_skill_ranking_count(); break; case 'get_work_user_list': require_once api_get_path(SYS_CODE_PATH) . 'work/work.lib.php'; $work_id = $request->get('work_id'); //$_REQUEST['work_id']; $count = get_count_work($work_id); break; case 'get_exercise_results': $exercise_id = $request->get('exerciseId'); //$_REQUEST['exerciseId']; $filter_by_user = $request->get('filter_by_user'); if (isset($filter_by_user) && !empty($filter_by_user)) { $filter_user = intval($filter_by_user); if ($where_condition == "") { $where_condition .= " te.exe_user_id = '{$filter_user}'"; } else { $where_condition .= " AND te.exe_user_id = '{$filter_user}'"; } } $count = \ExerciseLib::get_count_exam_results($exercise_id, $where_condition); break; case 'get_hotpotatoes_exercise_results': $hotpot_path = $request->get('path'); //$_REQUEST['path']; $count = \ExerciseLib::get_count_exam_hotpotatoes_results($hotpot_path); break; case 'get_sessions': $list_type = $request->get('list_type'); if ($list_type == 'simple' || empty($list_type)) { $count = \SessionManager::get_sessions_admin(array('where' => $where_condition, 'extra' => $extra_fields), true); } else { $count = \SessionManager::get_count_admin_complete(array('where' => $where_condition, 'extra' => $extra_fields)); } break; case 'get_extra_fields': $obj = new \ExtraField($type); $count = $obj->get_count(); break; case 'get_extra_field_options': $field_id = $request->get('field_id'); $obj = new \ExtraFieldOption($type); $count = $obj->get_count_by_field_id($field_id); break; case 'get_timelines': $obj = new \Timeline(); $count = $obj->get_count(); break; case 'get_gradebooks': $obj = new \Gradebook(); $count = $obj->get_count(); break; case 'get_event_email_template': $obj = new \EventEmailTemplate(); $count = $obj->get_count(); break; case 'get_careers': $obj = new \Career(); $count = $obj->get_count(); break; case 'get_promotions': $obj = new \Promotion(); $count = $obj->get_count(); break; case 'get_grade_models': $obj = new \GradeModel(); $count = $obj->get_count(); break; case 'get_usergroups': $obj = new \UserGroup(); $count = $obj->get_count(); break; case 'get_usergroups_teacher': $obj = new \UserGroup(); $course_id = api_get_course_int_id(); if ($type == 'registered') { $count = $obj->get_usergroup_by_course_with_data_count($course_id); } else { $count = $obj->get_count(); } break; default: exit; } //3. Calculating first, end, etc $total_pages = 0; if ((int) $count > 0) { if (!empty($limit)) { $total_pages = ceil($count / $limit); } } if ($page > $total_pages) { $page = $total_pages; } $start = $limit * $page - $limit; if ($start < 0) { $start = 0; } //4. Deleting an element if the user wants to if ($operation == 'del') { $obj->delete($request->get('id')); } $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh(); //5. Querying the DB for the elements $columns = array(); switch ($action) { case 'get_questions': $columns = \Question::getQuestionColumns(api_get_course_id(), $extra_fields, $questionFields, true); $columns = $columns['simple_column_name']; $result = \Question::getQuestions($app, $categoryId, $exerciseId, $courseId, array('where' => $where_condition, 'order' => "{$sidx} {$sord}", 'extra' => $extra_fields, 'question' => $questionFields, 'limit' => "{$start} , {$limit}")); //var_dump($result); break; case 'get_user_list_plugin_widescale': $columns = array('username', 'firstname', 'lastname', 'exam_password'); $column_names = array(get_lang('Username'), get_lang('Firstname'), get_lang('Lastname'), get_lang('Password')); $result = \UserManager::get_user_data($start, $limit, $sidx, $sord); break; case 'get_question_list': if (isset($exercise) && !empty($exercise)) { $columns = array('question', 'type', 'category', 'level', 'score', 'actions'); $result = $exercise->getQuestionListPagination($start, $limit, $sidx, $sord, $where_condition); } break; case 'get_group_reporting': $columns = array('name', 'time', 'progress', 'score', 'works', 'messages', 'actions'); $result = \Tracking::get_group_reporting($course_id, $group_id, 'all', $start, $limit, $sidx, $sord, $where_condition); break; case 'get_course_exercise_medias': $columns = array('question'); $result = \Question::get_course_medias($course_id, $start, $limit, $sidx, $sord, $where_condition); if (!empty($result)) { foreach ($result as &$media) { $media['id'] = $media['iid']; } } break; case 'get_user_course_report_resumed': $columns = array('extra_ruc', 'training_hours', 'count_users', 'count_users_registered', 'average_hours_per_user', 'count_certificates'); $column_names = array(get_lang('Company'), get_lang('TrainingHoursAccumulated'), get_lang('CountOfSubscriptions'), get_lang('CountOfUsers'), get_lang('AverageHoursPerStudent'), get_lang('CountCertificates')); $result = \CourseManager::get_user_list_from_course_code(null, null, "LIMIT {$start}, {$limit}", " {$sidx} {$sord}", null, null, true, true, 'ruc'); $new_result = array(); if (!empty($result)) { foreach ($result as $row) { $row['training_hours'] = api_time_to_hms($row['training_hours']); $row['average_hours_per_user'] = api_time_to_hms($row['average_hours_per_user']); $new_result[] = $row; } $result = $new_result; } break; case 'get_user_course_report': $columns = array('course', 'user', 'time', 'certificate', 'progress_100', 'progress'); $column_names = array(get_lang('Course'), get_lang('User'), get_lang('ManHours'), get_lang('CertificateGenerated'), get_lang('Approved'), get_lang('CourseAdvance')); $extra_fields = \UserManager::get_extra_fields(0, 100, null, null, true, true); if (!empty($extra_fields)) { foreach ($extra_fields as $extra) { $columns[] = $extra['1']; $column_names[] = $extra['3']; } } $result = \CourseManager::get_user_list_from_course_code(null, null, "LIMIT {$start}, {$limit}", " {$sidx} {$sord}", null, null, true); break; case 'get_user_skill_ranking': $columns = array('photo', 'firstname', 'lastname', 'skills_acquired', 'currently_learning', 'rank'); $result = $skill->get_user_list_skill_ranking($start, $limit, $sidx, $sord, $where_condition); $result = \ArrayClass::msort($result, 'skills_acquired', 'asc'); $skills_in_course = array(); if (!empty($result)) { //$counter = 1; foreach ($result as &$item) { $user_info = api_get_user_info($item['user_id']); $personal_course_list = \UserManager::get_personal_session_course_list($item['user_id']); $count_skill_by_course = array(); foreach ($personal_course_list as $course_item) { if (!isset($skills_in_course[$course_item['code']])) { $count_skill_by_course[$course_item['code']] = $skill->get_count_skills_by_course($course_item['code']); $skills_in_course[$course_item['code']] = $count_skill_by_course[$course_item['code']]; } else { $count_skill_by_course[$course_item['code']] = $skills_in_course[$course_item['code']]; } } $item['photo'] = \Display::img($user_info['avatar_small']); $item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0; } } break; case 'get_work_user_list': if (isset($type) && $type == 'simple') { $columns = array('type', 'firstname', 'lastname', 'username', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions'); } else { $columns = array('type', 'firstname', 'lastname', 'username', 'title', 'sent_date', 'actions'); } $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $where_condition); break; case 'get_exercise_results': $course = api_get_course_info(); //used inside get_exam_results_data() $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document"; if ($is_allowedToEdit) { $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'status', 'lp', 'actions'); } else { //$columns = array('exe_duration', 'start_date', 'exe_date', 'score', 'status', 'actions'); } $result = \ExerciseLib::get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition); break; case 'get_hotpotatoes_exercise_results': $course = api_get_course_info(); //used inside get_exam_results_data() $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document"; $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions'); $result = ExerciseLib::get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $where_condition); //get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition); break; case 'get_sessions': $session_columns = \SessionManager::get_session_columns($list_type); $columns = $session_columns['simple_column_name']; if ($list_type == 'simple') { $result = SessionManager::get_sessions_admin(array('where' => $where_condition, 'order' => "{$sidx} {$sord}", 'extra' => $extra_fields, 'limit' => "{$start} , {$limit}"), false); } else { $result = SessionManager::get_sessions_admin_complete(array('where' => $where_condition, 'order' => "{$sidx} {$sord}", 'extra' => $extra_fields, 'limit' => "{$start} , {$limit}")); } break; case 'get_timelines': $columns = array('headline', 'actions'); //$columns = array('headline', 'type', 'start_date', 'end_date', 'text', 'media', 'media_credit', 'media_caption', 'title_slide', 'parent_id'); if (!in_array($sidx, $columns)) { $sidx = 'headline'; } $course_id = api_get_course_int_id(); $result = Database::select('*', $obj->table, array('where' => array('parent_id = ? AND c_id = ?' => array('0', $course_id)), 'order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); foreach ($result as $item) { if (!$item['status']) { $item['name'] = '<font style="color:#AAA">' . $item['name'] . '</font>'; } $item['headline'] = Display::url($item['headline'], api_get_path(WEB_CODE_PATH) . 'timeline/view.php?id=' . $item['id']); $item['actions'] = Display::url(Display::return_icon('add.png', get_lang('AddItems')), api_get_path(WEB_CODE_PATH) . 'timeline/?action=add_item&parent_id=' . $item['id']); $item['actions'] .= Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH) . 'timeline/?action=edit&id=' . $item['id']); $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH) . 'timeline/?action=delete&id=' . $item['id']); $new_result[] = $item; } $result = $new_result; break; case 'get_gradebooks': $columns = array('name', 'certificates', 'skills', 'actions', 'has_certificates'); if (!in_array($sidx, $columns)) { $sidx = 'name'; } $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); foreach ($result as $item) { if ($item['parent_id'] != 0) { continue; } $skills = $obj->get_skills_by_gradebook($item['id']); //Fixes bug when gradebook doesn't have names if (empty($item['name'])) { $item['name'] = $item['course_code']; } else { //$item['name'] = $item['name'].' ['.$item['course_code'].']'; } $item['name'] = Display::url($item['name'], api_get_path(WEB_CODE_PATH) . 'gradebook/index.php?id_session=0&cidReq=' . $item['course_code']); if (!empty($item['certif_min_score']) && !empty($item['document_id'])) { $item['certificates'] = Display::return_icon('accept.png', get_lang('WithCertificate'), array(), ICON_SIZE_SMALL); $item['has_certificates'] = '1'; } else { $item['certificates'] = Display::return_icon('warning.png', get_lang('NoCertificate'), array(), ICON_SIZE_SMALL); $item['has_certificates'] = '0'; } if (!empty($skills)) { foreach ($skills as $skill) { $item['skills'] .= Display::span($skill['name'], array('class' => 'label_tag skill')); } } $new_result[] = $item; } $result = $new_result; break; case 'get_event_email_template': $columns = array('subject', 'event_type_name', 'language_id', 'activated', 'actions'); if (!in_array($sidx, $columns)) { $sidx = 'subject'; } $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); foreach ($result as $item) { $language_info = api_get_language_info($item['language_id']); $item['language_id'] = $language_info['english_name']; $item['actions'] = Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH) . 'admin/event_type.php?action=edit&event_type_name=' . $item['event_type_name']); $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH) . 'admin/event_controller.php?action=delete&id=' . $item['id']); /*if (!$item['status']) { $item['name'] = '<font style="color:#AAA">'.$item['subject'].'</font>'; }*/ $new_result[] = $item; } $result = $new_result; break; case 'get_careers': $columns = array('name', 'description', 'actions'); if (!in_array($sidx, $columns)) { $sidx = 'name'; } $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); foreach ($result as $item) { if (!$item['status']) { $item['name'] = '<font style="color:#AAA">' . $item['name'] . '</font>'; } $new_result[] = $item; } $result = $new_result; break; case 'get_promotions': $columns = array('name', 'career', 'description', 'actions'); if (!in_array($sidx, $columns)) { $sidx = 'name'; } $result = Database::select('p.id,p.name, p.description, c.name as career, p.status', "{$obj->table} p LEFT JOIN " . Database::get_main_table(TABLE_CAREER) . " c ON c.id = p.career_id ", array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); foreach ($result as $item) { if (!$item['status']) { $item['name'] = '<font style="color:#AAA">' . $item['name'] . '</font>'; } $new_result[] = $item; } $result = $new_result; break; case 'get_grade_models': $columns = array('name', 'description', 'actions'); if (!in_array($sidx, $columns)) { $sidx = 'name'; } $result = Database::select('*', "{$obj->table} ", array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); foreach ($result as $item) { $new_result[] = $item; } $result = $new_result; break; case 'get_usergroups': $columns = array('name', 'users', 'courses', 'sessions', 'group_type', 'actions'); $result = Database::select('*', $obj->table, array('order' => "name {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); if (!empty($result)) { foreach ($result as $group) { $group['sessions'] = count($obj->get_sessions_by_usergroup($group['id'])); $group['courses'] = count($obj->get_courses_by_usergroup($group['id'])); $group['users'] = count($obj->get_users_by_usergroup($group['id'])); switch ($group['group_type']) { case '0': $group['group_type'] = Display::label(get_lang('Class'), 'info'); break; case '1': $group['group_type'] = Display::label(get_lang('Social'), 'success'); break; } $new_result[] = $group; } $result = $new_result; } $columns = array('name', 'users', 'courses', 'sessions', 'group_type'); if (!in_array($sidx, $columns)) { $sidx = 'name'; } //Multidimensional sort ArrayClass::msort($result, $sidx); break; case 'get_extra_fields': $obj = new \ExtraField($type); $columns = array('field_display_text', 'field_variable', 'field_type', 'field_changeable', 'field_visible', 'field_filter', 'field_order'); $result = \Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); $new_result = array(); if (!empty($result)) { foreach ($result as $item) { $item['field_type'] = $obj->get_field_type_by_id($item['field_type']); $item['field_changeable'] = $item['field_changeable'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif'); $item['field_visible'] = $item['field_visible'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif'); $item['field_filter'] = $item['field_filter'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif'); $new_result[] = $item; } $result = $new_result; } break; case 'get_extra_field_options': $obj = new \ExtraFieldOption($type); $columns = array('option_display_text', 'option_value', 'option_order'); $result = \Database::select('*', $obj->table, array('where' => array("field_id = ? " => $field_id), 'order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}")); /*$new_result = array(); if (!empty($result)) { foreach ($result as $item) { $item['field_type'] = $obj->get_field_type_by_id($item['field_type']); $item['field_changeable'] = $item['field_changeable'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif'); $item['field_visible'] = $item['field_visible'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif'); $item['field_filter'] = $item['field_filter'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif'); $new_result[] = $item; } $result = $new_result; }*/ break; case 'get_usergroups_teacher': $columns = array('name', 'users', 'actions'); $options = array('order' => "name {$sord}", 'LIMIT' => "{$start} , {$limit}"); $options['course_id'] = $course_id; switch ($type) { case 'not_registered': $options['where'] = array(" (course_id IS NULL OR course_id != ?) " => $course_id); $result = $obj->get_usergroup_not_in_course($options); break; case 'registered': $options['where'] = array(" usergroup.course_id = ? " => $course_id); $result = $obj->get_usergroup_in_course($options); break; } $new_result = array(); if (!empty($result)) { foreach ($result as $group) { $group['users'] = count($obj->get_users_by_usergroup($group['id'])); if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) { $url = 'class.php?action=remove_class_from_course&id=' . $group['id']; $icon = Display::return_icon('delete.png', get_lang('Remove')); } else { $url = 'class.php?action=add_class_to_course&id=' . $group['id']; $icon = Display::return_icon('add.png', get_lang('Add')); } $group['actions'] = Display::url($icon, $url); $new_result[] = $group; } $result = $new_result; } if (!in_array($sidx, $columns)) { $sidx = 'name'; } //Multidimensional sort \ArrayClass::msort($result, $sidx); break; default: exit; } $allowed_actions = array('get_careers', 'get_promotions', 'get_usergroups', 'get_usergroups_teacher', 'get_gradebooks', 'get_sessions', 'get_exercise_results', 'get_hotpotatoes_exercise_results', 'get_work_user_list', 'get_timelines', 'get_grade_models', 'get_event_email_template', 'get_user_skill_ranking', 'get_extra_fields', 'get_extra_field_options', 'get_course_exercise_medias', 'get_user_course_report', 'get_user_course_report_resumed', 'get_group_reporting', 'get_question_list', 'get_user_list_plugin_widescale', 'get_questions'); //5. Creating an obj to return a json if (in_array($action, $allowed_actions)) { $response = new \stdClass(); $response->page = $page; $response->total = $total_pages; $response->records = $count; if ($operation && $operation == 'excel') { $j = 1; $array = array(); if (empty($column_names)) { $column_names = $columns; } //Headers foreach ($column_names as $col) { $array[0][] = $col; } foreach ($result as $row) { foreach ($columns as $col) { $array[$j][] = strip_tags($row[$col]); } $j++; } switch ($export_format) { case 'xls': Export::export_table_xls($array, 'company_report'); break; case 'csv': default: Export::export_table_csv($array, 'company_report'); break; } exit; } $i = 0; if (!empty($result)) { foreach ($result as $row) { //print_r($row); // if results tab give not id, set id to $i otherwise id="null" for all <tr> of the jqgrid - ref #4235 if (!isset($row['id']) || isset($row['id']) && $row['id'] == "") { $response->rows[$i]['id'] = $i; } else { $response->rows[$i]['id'] = $row['id']; } $array = array(); foreach ($columns as $col) { $array[] = isset($row[$col]) ? $row[$col] : null; } $response->rows[$i]['cell'] = $array; $i++; } } return json_encode($response); } }
} break; case 'list': default: $toolList = CourseHome::toolsIconsAction(api_get_course_int_id(), api_get_session_id()); $iconsTools = '<div id="custom-icons">'; $iconsTools .= Display::page_header(get_lang('CustomizeIcons'), null, 'h4'); $iconsTools .= '<div class="row">'; foreach ($toolList as $tool) { $toolIconName = 'Tool' . api_underscore_to_camel_case($tool['name']); $toolIconName = isset(${$toolIconName}) ? get_lang($toolIconName) : $tool['name']; $iconsTools .= '<div class="col-md-2">'; $iconsTools .= '<div class="items-tools">'; if (!empty($tool['custom_icon'])) { $image = getCustomWebIconPath() . $tool['custom_icon']; $icon = Display::img($image, $toolIconName); } else { $image = substr($tool['image'], 0, strpos($tool['image'], '.')) . '.png'; $icon = Display::return_icon($image, $toolIconName, array('id' => 'tool_' . $tool['id']), ICON_SIZE_BIG, false); } $delete = !empty($tool['custom_icon']) ? "<a class=\"btn btn-default\" onclick=\"javascript:\n if(!confirm('" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)) . "')) return false;\" href=\"" . api_get_self() . '?action=delete_icon&id=' . $tool['iid'] . '&' . api_get_cidreq() . "\">\n <em class=\"fa fa-trash-o\"></em></a>" : ""; $edit = '<a class="btn btn-default" href="' . api_get_self() . '?action=edit_icon&id=' . $tool['iid'] . '&' . api_get_cidreq() . '"><em class="fa fa-pencil"></em></a>'; $iconsTools .= '<div class="icon-tools">' . $icon . '</div>'; $iconsTools .= '<div class="name-tools">' . $toolIconName . '</div>'; $iconsTools .= '<div class="toolbar">' . $edit . $delete . '</div>'; $iconsTools .= '</div>'; $iconsTools .= '</div>'; } $iconsTools .= '</div>'; $iconsTools .= '</div>'; $content = $iconsTools;
return $list; } /** * Just display the form needed to upload a SCORM and give its settings */ $nameTools = get_lang("FileUpload"); $interbreadcrumb[] = array("url" => "../newscorm/lp_controller.php?action=list", "name" => get_lang("ToolLearnpath")); Display::display_header($nameTools, "Path"); require_once '../newscorm/content_makers.inc.php'; require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; echo '<div class="actions">'; echo '<a href="../newscorm/lp_controller.php?cidReq=' . $_course['sysCode'] . '">' . Display::return_icon('back.png', get_lang('ReturnToLearningPaths'), '', ICON_SIZE_MEDIUM) . '</a>'; echo '</div>'; $form = new FormValidator('', 'POST', 'upload.php', '', array('id' => "upload_form", 'enctype' => "multipart/form-data")); $form->addElement('header', $nameTools); $form->addLabel(null, Display::img(api_get_path(WEB_IMG_PATH) . 'scorm_logo.jpg')); $form->addElement('hidden', 'curdirpath', $path); $form->addElement('hidden', 'tool', $my_tool); $form->addElement('file', 'user_file', get_lang('FileToUpload')); $form->add_real_progress_bar('uploadScorm', 'user_file'); $form->addRule('user_file', get_lang('ThisFieldIsRequired'), 'required'); unset($content_origins[0]); unset($content_origins[1]); if (api_get_setting('search_enabled') == 'true') { $form->addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument')); $specific_fields = get_specific_field_list(); foreach ($specific_fields as $specific_field) { $form->addElement('text', $specific_field['code'], $specific_field['name'] . ' : '); } } if (api_is_platform_admin()) {
/** * Displays the tools of a certain category. * @param Symfony\Component\Routing\RouterInterface $urlGenerator * @param array List of tools as returned by get_tools_category() * @param bool rows * @return string */ public static function show_tools_category($urlGenerator, $toolList, $rows = false) { $rowDiv = '<div class="row">'; $theme = api_get_setting('homepage_view'); if ($theme == 'vertical_activity') { //ordering by get_lang name $order_tool_list = array(); if (is_array($toolList) && count($toolList) > 0) { foreach ($toolList as $key => $new_tool) { $tool_name = self::translate_tool_name($new_tool); $order_tool_list[$key] = $tool_name; } natsort($order_tool_list); $my_temp_tool_array = array(); foreach ($order_tool_list as $key => $new_tool) { $my_temp_tool_array[] = $toolList[$key]; } $toolList = $my_temp_tool_array; } else { $toolList = array(); } } $courseInfo = api_get_course_info(); $web_code_path = api_get_path(WEB_CODE_PATH); $is_allowed_to_edit = api_is_allowed_to_edit(null, true); $is_platform_admin = api_is_platform_admin(); $session_id = api_get_session_id(); $items = array(); $app_plugin = new AppPlugin(); if (isset($toolList)) { $lnk = ''; foreach ($toolList as &$tool) { $item = array(); $tool['admin'] = isset($tool['admin']) ? $tool['admin'] : null; $tool['id'] = isset($tool['id']) ? $tool['id'] : null; $tool['target'] = isset($tool['target']) ? $tool['target'] : null; if (isset($tool['link_id'])) { $tool['original_link'] = api_get_path(WEB_CODE_PATH) . 'link/link_goto.php?link_id=' . $tool['link_id'] . '&' . api_get_cidreq(); $tool['link'] = $tool['original_link']; } else { $tool['original_link'] = $tool['link']; } // Re-writing URL for new tools $newTools = array(TOOL_CURRICULUM); $toolName = isset($tool['name']) ? $tool['name'] : null; if (in_array($toolName, $newTools)) { $tool['link'] = $courseInfo['course_web_public_url'] . $tool['name'] . '/'; } if ($tool['image'] == 'scormbuilder.gif') { // Check if the published learnpath is visible for student $published_lp_id = self::get_published_lp_id_from_link($tool['link']); if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id())) { continue; } } if ($session_id != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) { continue; } if ($tool['name'] == 'course_description') { $tool['link'] = 'course_description/index.php'; } // This part displays the links to hide or remove a tool. // These links are only visible by the course manager. unset($lnk); $item['extra'] = null; if ($is_allowed_to_edit && !api_is_coach()) { if (empty($session_id)) { if ($tool['visibility'] == '1' && $tool['admin'] != '1') { $link['name'] = Display::return_icon('visible.gif', get_lang('Deactivate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_MEDIUM, false); if (!empty($tool['id'])) { $link['cmd'] = $urlGenerator->generate('course_home.controller:hideIconAction', array('course' => api_get_course_id(), 'iconId' => $tool['id'])); } $lnk[] = $link; } if ($tool['visibility'] == '0' && $tool['admin'] != '1') { $link['name'] = Display::return_icon('invisible.gif', get_lang('Activate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_MEDIUM, false); if (!empty($tool['id'])) { $link['cmd'] = $urlGenerator->generate('course_home.controller:showIconAction', array('course' => api_get_course_id(), 'iconId' => $tool['id'])); } $lnk[] = $link; } } if (!empty($tool['adminlink'])) { $item['extra'] = '<a href="' . $tool['adminlink'] . '">' . Display::return_icon('edit.gif', get_lang('Edit')) . '</a>'; } } // Both checks are necessary as is_platform_admin doesn't take student view into account if ($is_platform_admin && $is_allowed_to_edit) { if ($tool['admin'] != '1') { $link['cmd'] = 'hide=yes'; } } $item['visibility'] = null; if (isset($lnk) && is_array($lnk)) { foreach ($lnk as $this_link) { if (empty($tool['adminlink'])) { $item['visibility'] .= '<a class="make_visible_and_invisible" href="' . $this_link['cmd'] . '">' . $this_link['name'] . '</a>'; } } } else { $item['visibility'] .= null; } // NOTE : Table contains only the image file name, not full path if (stripos($tool['link'], 'http://') === false && stripos($tool['link'], 'https://') === false && stripos($tool['link'], 'ftp://') === false) { $tool['link'] = $web_code_path . $tool['link']; } if (!empty($tool['custom_icon'])) { $tool['image'] = self::getCustomIconPath($courseInfo) . $tool['custom_icon']; } if ($tool['visibility'] == '0' && $tool['admin'] != '1') { $class = 'invisible'; $info = pathinfo($tool['image']); $dirName = null; if ($info['dirname'] != '.') { $dirName = $info['dirname'] . '/'; } $basename = basename($tool['image'], '.' . $info['extension']); // $file is set to "index" $tool['image'] = $dirName . $basename . '_na.' . $info['extension']; } else { $class = ''; } $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&'; // If it's a link, we don't add the cidReq if ($tool['image'] == 'file_html.gif' || $tool['image'] == 'file_html_na.gif') { $tool['link'] = $tool['link'] . $qm_or_amp; } else { $tool['link'] = $tool['link'] . $qm_or_amp . api_get_cidreq(); } $tool_link_params = array(); //@todo this visio stuff should be removed if (strpos($tool['name'], 'visio_') !== false) { $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'href' => '"javascript: void(0);"', 'class' => $class, 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_visio' . $_SESSION['_cid'] . '\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']); } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) { $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'class' => $class, 'href' => 'javascript: void(0);', 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_chat' . $_SESSION['_cid'] . '\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']); } else { if (count(explode('type=classroom', $tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) { $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'href' => $tool['link'], 'class' => $class, 'target' => '_blank'); } else { $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'href' => $tool['link'], 'class' => $class, 'target' => $tool['target']); } } $tool_name = self::translate_tool_name($tool); $toolTip = $tool_name; if (!empty($tool['description'])) { $toolTip = $tool['description']; } $tool_link_params['data-original-title'] = $toolTip; $tool_link_params['data-toggle'] = 'tooltip'; //$tool_link_params['title'] = $toolTip; // Including Courses Plugins // Creating title and the link if (isset($tool['category']) && $tool['category'] == 'plugin') { $plugin_info = $app_plugin->get_plugin_info($tool['name']); if (isset($plugin_info) && isset($plugin_info['title'])) { $tool_name = $plugin_info['title']; } $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH) . $tool['original_link'] . '?' . api_get_cidreq(); } if (!empty($tool['custom_icon'])) { //self::getCustomIconPath($courseInfo) $icon = Display::img($tool['image'], null, array('class' => 'tool-icon', 'id' => 'toolimage_' . $tool['id'])); } else { $image = substr($tool['image'], 0, strpos($tool['image'], '.')) . '.png'; $icon = Display::return_icon($image, null, array('class' => 'tool-icon', 'id' => 'toolimage_' . $tool['id']), ICON_SIZE_BIG, false); } $userInfo = api_get_user_info(); $userStatus = isset($userInfo['status']) ? $userInfo['status'] : null; // Validation when belongs to a session $session_img = api_get_session_image($tool['session_id'], $userStatus); $item['url_params'] = $tool_link_params; $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params); $item['tool'] = $tool; $item['name'] = $tool_name; $tool_link_params['id'] = 'is' . $tool_link_params['id']; $item['link'] = Display::url($tool_name . $session_img, $tool_link_params['href'], $tool_link_params); $items[] = $item; } // end of foreach } $i = 0; $html = ''; $counter = 0; if (!empty($items)) { foreach ($items as $item) { switch ($theme) { case 'activity_big': $data = ''; if ($counter == 0) { $html .= $rowDiv; } $html .= '<div class="col-xs-4 col-md-4 course-tool">'; $image = substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.')) . '.png'; if (!empty($item['tool']['custom_icon'])) { $original_image = Display::img($item['tool']['image'], null, array('id' => 'toolimage_' . $item['tool']['id'])); } else { $original_image = Display::return_icon($image, null, array('id' => 'toolimage_' . $item['tool']['id']), ICON_SIZE_BIG, false); } switch ($image) { case 'scormbuilder.png': if (api_is_allowed_to_edit(null, true)) { $item['url_params']['href'] .= '&isStudentView=true'; } $image = $original_image; $lp_id = self::get_published_lp_id_from_link($item['link']); if ($lp_id) { $lp = new learnpath(api_get_course_id(), $lp_id, api_get_user_id()); $path = $lp->get_preview_image_path(64); if ($path) { $image = '<img src="' . $path . '">'; } } break; default: $image = $original_image; } $data .= Display::url($image, $item['url_params']['href'], $item['url_params']); $html .= Display::div($data, array('class' => 'big_icon')); //box-image reflection $html .= Display::div('<h4>' . $item['visibility'] . $item['extra'] . $item['link'] . '</h4>', array('class' => 'content')); $html .= '</div>'; if ($counter == 2) { $html .= '</div>'; $counter = -1; } $counter++; break; case 'activity': if ($counter == 0) { $html .= $rowDiv; } $html .= '<div class="col-md-6 course-tool">'; $content = $item['extra']; $content .= $item['visibility']; $content .= $item['icon']; $content .= $item['link']; $html .= Display::div($content, array('class' => 'activity_content')); $html .= '</div>'; if ($counter == 1) { $html .= '</div>'; $counter = -1; } $counter++; break; case 'vertical_activity': if ($i == 0) { $html .= '<ul>'; } $html .= '<li class="course-tool">'; $html .= $item['extra']; $html .= $item['visibility']; $html .= $item['icon']; $html .= $item['link']; $html .= '</li>'; if ($i == count($items) - 1) { $html .= '</ul>'; } break; } $i++; } } return array('content' => $html, 'tool_list' => $items); }
$template->assign('gamification_mode', $gamificationMode); $template->assign('breadcrumb', $breadcrumb); $template->assign('button_home_url', $buttonHomeUrl); $template->assign('button_home_text', $buttonHomeText); $template->assign('navigation_bar', $navigation_bar); $template->assign('progress_bar', $progress_bar); $template->assign('show_audio_player', $show_audioplayer); $template->assign('media_player', $mediaplayer); $template->assign('toc_list', $get_toc_list); $template->assign('teacher_toc_buttons', $get_teacher_buttons); $template->assign('iframe_src', $src); $template->assign('navigation_bar_bottom', $navigation_bar_bottom); if ($gamificationMode == 1) { $template->assign('gamification_stars', $_SESSION['oLP']->getCalculateStars($sessionId)); $template->assign('gamification_points', $_SESSION['oLP']->getCalculateScore($sessionId)); } $template->assign('lp_preview_image', Display::img($lpPreviewImagePath, $_SESSION['oLP']->name, array('class' => 'img-circle'), ICON_SIZE_BIG)); $template->assign('lp_author', $_SESSION['oLP']->get_author()); $template->assign('lp_mode', $_SESSION['oLP']->mode); $template->assign('lp_title_scorm', $_SESSION['oLP']->name); $template->assign('lp_html_toc', $_SESSION['oLP']->get_html_toc($get_toc_list)); $template->assign('lp_id', $_SESSION['oLP']->lp_id); $template->assign('lp_current_item_id', $_SESSION['oLP']->get_current_item_id()); $content = $template->fetch('default/learnpath/view.tpl'); $template->assign('content', $content); $template->display_no_layout_template(); // Restore a global setting. $_setting['show_navigation_menu'] = $save_setting; if ($debug) { error_log(' ------- end lp_view.php ------'); }
/** * 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 * */ 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) { // Text direction for the current language $is_ltr_text_direction = api_get_text_direction() != 'rtl'; // Change false to true in the following line to enable answer hinting $debug_mark_answer = $show_answers; //api_is_allowed_to_edit() && false; // 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">'; // construction of the Answer object (also gets all answers details) $objAnswerTmp = new Answer($questionId); $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); $course_id = api_get_course_int_id(); $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 ($answerType == MATCHING) { $s .= '<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); $answer = $objAnswerTmp->selectAnswer($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']; $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; $oFCKeditor = new FCKeditor("choice[" . $questionId . "]"); $oFCKeditor->ToolbarSet = 'TestFreeAnswer'; $oFCKeditor->Width = '100%'; $oFCKeditor->Height = '200'; $oFCKeditor->Value = $fck_content; $s .= $oFCKeditor->CreateHtml(); } elseif ($answerType == ORAL_EXPRESSION) { //Add nanog if (api_get_setting('enable_nanogong') == 'true') { require_once api_get_path(LIBRARY_PATH) . 'nanogong.lib.php'; //@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(); } $oFCKeditor = new FCKeditor("choice[" . $questionId . "]"); $oFCKeditor->ToolbarSet = 'TestFreeAnswer'; $oFCKeditor->Width = '100%'; $oFCKeditor->Height = '150'; $oFCKeditor->ToolbarStartExpanded = false; $oFCKeditor->Value = ''; $s .= $oFCKeditor->CreateHtml(); } // 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="data_table">'; $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_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="data_table">'; $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 ($answerType == UNIQUE_ANSWER || $answerType == UNIQUE_ANSWER_NO_OPTION) { $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; } } $answer = Security::remove_XSS($answer, STUDENT); $s .= Display::input('hidden', 'choice2[' . $questionId . ']', '0'); $answer_input = '<label class="radio">'; $answer_input .= Display::input('radio', 'choice[' . $questionId . ']', $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 || $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); $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) { /* * In the FILL_IN_BLANKS 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 " */ list($answer) = explode('::', $answer); // $correct_answer_list array of array with correct anwsers 0=> [0=>[\p] 1=>[plop]] api_preg_match_all('/\\[[^]]+\\]/', $answer, $correct_answer_list); // get student answer to display it if student go back to previous fillBlank answer question in a test if (isset($user_choice[0]['answer'])) { api_preg_match_all('/\\[[^]]+\\]/', $user_choice[0]['answer'], $student_answer_list); $student_answer_list_tobecleaned = $student_answer_list[0]; $student_answer_list = array(); // here we got the student answer in a test // let's clean up the results /* Array ( [0] => Array ( [0] => [<font color="red"><s>yer</s></font> / <font color="green"><b>ici</b></font>] [1] => [<font color="red"><s>plop</s></font> / <font color="green"><b>/p</b></font>] ) ) */ for ($i = 0; $i < count($student_answer_list_tobecleaned); $i++) { $answer_corrected = $student_answer_list_tobecleaned[$i]; /* * we got if student answer is wrong * [<font color="red"><s>rrr</s></font> / <font color="green"><b>/p</b></font>] * or if student answer is good * [plop / <font color="green"><b>plop</b></font>] * or if student didn't answer [] */ $answer_corrected = api_preg_replace('| / <font color="green"><b>.*$|', '', $answer_corrected); /* * we got [<font color="red"><s>rrr</s></font> or [plop or [ */ $answer_corrected = api_preg_replace('/^\\[/', '', $answer_corrected); /* * we got <font color="red"><s>rrr</s></font> or plop * non breakable spaces from /main/exercice/exercise.class.php have been removed l 2391 and l 2370 */ $answer_corrected = api_preg_replace('|^<font color="red"><s>|', '', $answer_corrected); $answer_corrected = api_preg_replace('|</s></font>$|', '', $answer_corrected); $answer_corrected = '[' . $answer_corrected . ']'; /* * we got [rrr] or [plop] or [] */ $student_answer_list[] = $answer_corrected; } } // 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 $student_answer_list = $correct_answer_list[0]; } /* Split the response by bracket tab_comments is an array with text surrounding the text to find we add a space before and after the answer_question 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 */ $tab_comments = api_preg_split('/\\[[^]]+\\]/', ' ' . $answer . ' '); if (!empty($correct_answer_list) && !empty($student_answer_list)) { $answer = ""; $i = 0; foreach ($student_answer_list as $student_item) { // remove surronding brackets $student_response = api_substr($student_item, 1, api_strlen($student_item) - 2); $size = strlen($student_item); $attributes['class'] = detectInputAppropriateClass($size); $answer .= $tab_comments[$i] . Display::input('text', "choice[{$questionId}][]", $student_response, $attributes); $i++; } $answer .= $tab_comments[$i]; } else { // display exercise with empty input fields // every [xxx] are replaced with an empty input field foreach ($correct_answer_list[0] as $item) { $size = strlen($item); $attributes['class'] = detectInputAppropriateClass($size); $answer = str_replace($item, Display::input('text', "choice[{$questionId}][]", '', $attributes), $answer); } /*$answer = api_preg_replace( '/\[[^]]+\]/', Display::input( 'text', "choice[$questionId][]", '', $attributes ), $answer);*/ } $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_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $sqlTrackAttempt = 'SELECT answer FROM ' . $trackAttempts . ' WHERE exe_id=' . $exe_id . ' AND question_id=' . $questionId; $rsLastAttempt = Database::query($sqlTrackAttempt); $rowLastAttempt = Database::fetch_array($rsLastAttempt); $answer = $rowLastAttempt['answer']; if (empty($answer)) { $_SESSION['calculatedAnswerId'][$questionId] = mt_rand(1, $nbrAnswers); $answer = $objAnswerTmp->selectAnswer($_SESSION['calculatedAnswerId'][$questionId]); } } 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'] = 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'] = 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 .= ' <span style="float:left; width:8%;"><b>' . $lines_count . '</b>. </span> <span style="float:left; width:92%;">' . $parsed_answer . '</span></td>'; //middle part (matches selects) $s .= '<td width="10%" valign="top" align="center"> <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"'; } /*if (isset($user_choice_array[$matching_correct_answer]) && $val['id'] == $user_choice_array[$matching_correct_answer]['answer']) { $selected = 'selected="selected"'; }*/ $s .= '<option value="' . $val['id'] . '" ' . $selected . '>' . $val['letter'] . '</option>'; } // end foreach() $s .= '</select></td>'; $s .= '<td width="45%" valign="top" >'; if (isset($select_items[$lines_count])) { $s .= '<span style="float:left; width:5%;"><b>' . $select_items[$lines_count]['letter'] . '.</b></span>' . '<span style="float:left; width:95%;">' . $select_items[$lines_count]['answer'] . '</span>'; } 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 \t\t\t\t\t\t</tr>"; $lines_count++; } // end while() } // end if() $matching_correct_answer++; } } } // end for() if ($show_comment) { $s .= '</table>'; } else { if ($answerType == MATCHING || $answerType == UNIQUE_ANSWER_NO_OPTION || $answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { $s .= '</table>'; } } $s .= '</div>'; // 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) { // Question is a HOT_SPOT //checking document/images visibility if (api_is_platform_admin() || api_is_course_admin()) { require_once api_get_path(LIBRARY_PATH) . 'document.lib.php'; $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 Display::img($objQuestionTmp->selectPicturePath()); 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); } // display answers of hotpost order by id $answer_list = '<div style="padding: 10px; margin-left: 0px; border: 1px solid #A4A4A4; height: 408px; width: 200px;"><b>' . get_lang('HotspotZones') . '</b><dl>'; if (!empty($answers_hotspot)) { ksort($answers_hotspot); foreach ($answers_hotspot as $key => $value) { $answer_list .= '<dt>' . $key . '.- ' . $value . '</dt><br />'; } } $answer_list .= '</dl></div>'; if ($answerType == HOT_SPOT_DELINEATION) { $answer_list = ''; $swf_file = 'hotspot_delineation_user'; $swf_height = 405; } else { $swf_file = 'hotspot_user'; $swf_height = 436; } 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 '<input type="hidden" name="hidden_hotspot_id" value="' . $questionId . '" />'; echo '<table class="exercise_questions" > <tr> <td valign="top" colspan="2">'; echo $questionDescription; echo '</td></tr>'; } $canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1'); $s .= '<script type="text/javascript" src="../plugin/hotspot/JavaScriptFlashGateway.js"></script> <script src="../plugin/hotspot/hotspot.js" type="text/javascript" ></script> <script type="text/javascript"> <!-- // Globals // Major version of Flash required var requiredMajorVersion = 7; // Minor version of Flash required var requiredMinorVersion = 0; // Minor version of Flash required var requiredRevision = 0; // the version of javascript supported var jsVersion = 1.0; // --> </script> <script language="VBScript" type="text/vbscript"> <!-- // Visual basic helper required to detect Flash Player ActiveX control version information Function VBGetSwfVer(i) on error resume next Dim swControl, swVersion swVersion = 0 set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i)) if (IsObject(swControl)) then swVersion = swControl.GetVariable("$version") end if VBGetSwfVer = swVersion End Function // --> </script> <script language="JavaScript1.1" type="text/javascript"> <!-- // Detect Client Browser type var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false; var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false; jsVersion = 1.1; // JavaScript helper required to detect Flash Player PlugIn version information function JSGetSwfVer(i) { // NS/Opera version >= 3 check for Flash plugin in plugin array if (navigator.plugins != null && navigator.plugins.length > 0) { if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) { var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : ""; var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description; descArray = flashDescription.split(" "); tempArrayMajor = descArray[2].split("."); versionMajor = tempArrayMajor[0]; versionMinor = tempArrayMajor[1]; if ( descArray[3] != "" ) { tempArrayMinor = descArray[3].split("r"); } else { tempArrayMinor = descArray[4].split("r"); } versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0; flashVer = versionMajor + "." + versionMinor + "." + versionRevision; } else { flashVer = -1; } } // MSN/WebTV 2.6 supports Flash 4 else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4; // WebTV 2.5 supports Flash 3 else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3; // older WebTV supports Flash 2 else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2; // Can\'t detect in all other cases else { flashVer = -1; } return flashVer; } // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) { reqVer = parseFloat(reqMajorVer + "." + reqRevision); // loop backwards through the versions until we find the newest version for (i=25;i>0;i--) { if (isIE && isWin && !isOpera) { versionStr = VBGetSwfVer(i); } else { versionStr = JSGetSwfVer(i); } if (versionStr == -1 ) { return false; } else if (versionStr != 0) { if(isIE && isWin && !isOpera) { tempArray = versionStr.split(" "); tempString = tempArray[1]; versionArray = tempString .split(","); } else { versionArray = versionStr.split("."); } versionMajor = versionArray[0]; versionMinor = versionArray[1]; versionRevision = versionArray[2]; versionString = versionMajor + "." + versionRevision; // 7.0r24 == 7.24 versionNum = parseFloat(versionString); // is the major.revision >= requested major.revision AND the minor version >= requested minor if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) { return true; } else { return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false ); } } } } // --> </script>'; $s .= '<tr><td valign="top" colspan="2" width="520"><table><tr><td width="520"> <script> <!-- // Version check based upon the values entered above in "Globals" var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision); // Check to see if the version meets the requirements for playback if (hasReqestedVersion) { // if we\'ve detected an acceptable version var oeTags = \'<object type="application/x-shockwave-flash" data="../plugin/hotspot/' . $swf_file . '.swf?modifyAnswers=' . $questionId . '&canClick:' . $canClick . '" width="600" height="' . $swf_height . '">\' + \'<param name="wmode" value="transparent">\' + \'<param name="movie" value="../plugin/hotspot/' . $swf_file . '.swf?modifyAnswers=' . $questionId . '&canClick:' . $canClick . '" />\' + \'<\\/object>\'; document.write(oeTags); // embed the Flash Content SWF when all tests are passed } else { // flash is too old or we can\'t detect the plugin var alternateContent = "Error<br \\/>" + "Hotspots requires Macromedia Flash 7.<br \\/>" + "<a href=\\"http://www.macromedia.com/go/getflash/\\">Get Flash<\\/a>"; document.write(alternateContent); // insert non-flash content } // --> </script> </td> <td valign="top" align="left">' . $answer_list . '</td></tr> </table> </td></tr>'; echo $s; echo '</table>'; } return $nbrAnswers; }
function return_breadcrumb($interbreadcrumb, $language_file, $nameTools) { $session_id = api_get_session_id(); $session_name = api_get_session_name($session_id); $_course = api_get_course_info(); $user_id = api_get_user_id(); $course_id = api_get_course_id(); /* Plugins for banner section */ $web_course_path = api_get_path(WEB_COURSE_PATH); /* If the user is a coach he can see the users who are logged in its session */ $navigation = array(); // part 1: Course Homepage. If we are in a course then the first breadcrumb is a link to the course homepage // hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb $session_name = cut($session_name, MAX_LENGTH_BREADCRUMB); $my_session_name = is_null($session_name) ? '' : ' (' . $session_name . ')'; if (!empty($_course) && !isset($_GET['hide_course_breadcrumb'])) { $navigation_item['url'] = $web_course_path . $_course['path'] . '/index.php' . (!empty($session_id) ? '?id_session=' . $session_id : ''); $_course['name'] = api_htmlentities($_course['name']); $course_title = cut($_course['name'], MAX_LENGTH_BREADCRUMB); switch (api_get_setting('breadcrumbs_course_homepage')) { case 'get_lang': $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH) . 'home.png', get_lang('CourseHomepageLink')) . ' ' . get_lang('CourseHomepageLink'); break; case 'course_code': $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH) . 'home.png', $_course['official_code']) . ' ' . $_course['official_code']; break; case 'session_name_and_course_title': $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH) . 'home.png', $_course['name'] . $my_session_name) . ' ' . $course_title . $my_session_name; break; default: if (api_get_session_id() != -1) { $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH) . 'home.png', $_course['name'] . $my_session_name) . ' ' . $course_title . $my_session_name; } else { $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH) . 'home.png', $_course['name']) . ' ' . $course_title; } break; } /** * @todo could be useful adding the My courses in the breadcrumb $navigation_item_my_courses['title'] = get_lang('MyCourses'); $navigation_item_my_courses['url'] = api_get_path(WEB_PATH).'user_portal.php'; $navigation[] = $navigation_item_my_courses; */ $navigation[] = $navigation_item; } /* part 2: Interbreadcrumbs. If there is an array $interbreadcrumb defined then these have to appear before the last breadcrumb (which is the tool itself)*/ if (isset($interbreadcrumb) && is_array($interbreadcrumb)) { foreach ($interbreadcrumb as $breadcrumb_step) { if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') { continue; } if ($breadcrumb_step['url'] != '#') { $sep = strrchr($breadcrumb_step['url'], '?') ? '&' : '?'; $navigation_item['url'] = $breadcrumb_step['url'] . $sep . api_get_cidreq(); } else { $navigation_item['url'] = '#'; } $navigation_item['title'] = $breadcrumb_step['name']; // titles for shared folders if ($breadcrumb_step['name'] == 'shared_folder') { $navigation_item['title'] = get_lang('UserFolders'); } elseif (strstr($breadcrumb_step['name'], 'shared_folder_session_')) { $navigation_item['title'] = get_lang('UserFolders'); } elseif (strstr($breadcrumb_step['name'], 'sf_user_')) { $userinfo = api_get_user_info(substr($breadcrumb_step['name'], 8)); $navigation_item['title'] = $userinfo['complete_name']; } elseif ($breadcrumb_step['name'] == 'chat_files') { $navigation_item['title'] = get_lang('ChatFiles'); } elseif ($breadcrumb_step['name'] == 'images') { $navigation_item['title'] = get_lang('Images'); } elseif ($breadcrumb_step['name'] == 'video') { $navigation_item['title'] = get_lang('Video'); } elseif ($breadcrumb_step['name'] == 'audio') { $navigation_item['title'] = get_lang('Audio'); } elseif ($breadcrumb_step['name'] == 'flash') { $navigation_item['title'] = get_lang('Flash'); } elseif ($breadcrumb_step['name'] == 'gallery') { $navigation_item['title'] = get_lang('Gallery'); } //Fixes breadcrumb title now we applied the Security::remove_XSS and we cut the string depending of the MAX_LENGTH_BREADCRUMB value $navigation_item['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB); $navigation_item['title'] = Security::remove_XSS($navigation_item['title']); $navigation[] = $navigation_item; } } $navigation_right = array(); if (isset($interbreadcrumb) && is_array($interbreadcrumb)) { foreach ($interbreadcrumb as $breadcrumb_step) { if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') { if ($breadcrumb_step['url'] != '#') { $sep = strrchr($breadcrumb_step['url'], '?') ? '&' : '?'; $navigation_item['url'] = $breadcrumb_step['url'] . $sep . api_get_cidreq(); } else { $navigation_item['url'] = '#'; } $breadcrumb_step['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB); $breadcrumb_step['title'] = Security::remove_XSS($navigation_item['title']); $navigation_right[] = $breadcrumb_step; } } } // part 3: The tool itself. If we are on the course homepage we do not want to display the title of the course because this // is the same as the first part of the breadcrumbs (see part 1) if (isset($nameTools) && $language_file != 'course_home') { // TODO: This condition $language_file != 'course_home' might bring surprises. $navigation_item['url'] = '#'; $navigation_item['title'] = $nameTools; $navigation[] = $navigation_item; } $final_navigation = array(); $counter = 0; foreach ($navigation as $index => $navigation_info) { if (!empty($navigation_info['title'])) { if ($navigation_info['url'] == '#') { $final_navigation[$index] = $navigation_info['title']; } else { $final_navigation[$index] = '<a href="' . $navigation_info['url'] . '" class="" target="_top">' . $navigation_info['title'] . '</a>'; } $counter++; } } $html = ''; /* Part 4 . Show the teacher view/student view button at the right of the breadcrumb */ $view_as_student_link = null; if ($user_id && isset($course_id)) { if ((api_is_course_admin() || api_is_platform_admin()) && api_get_setting('student_view_enabled') == 'true') { $view_as_student_link = api_display_tool_view_option(); } } if (!empty($final_navigation)) { $lis = ''; $i = 0; $final_navigation_count = count($final_navigation); if (!empty($final_navigation)) { // $home_link.= '<span class="divider">/</span>'; if (!empty($home_link)) { $lis .= Display::tag('li', $home_link); } foreach ($final_navigation as $bread) { $bread_check = trim(strip_tags($bread)); if (!empty($bread_check)) { if ($final_navigation_count - 1 > $i) { $bread .= '<span class="divider">/</span>'; } $lis .= Display::tag('li', $bread); $i++; } } } else { if (!empty($home_link)) { $lis .= Display::tag('li', $home_link); } } // View as student/teacher link if (!empty($view_as_student_link)) { $lis .= Display::tag('li', $view_as_student_link, array('id' => 'view_as_link', 'class' => 'pull-right')); } if (!empty($navigation_right)) { foreach ($navigation_right as $item) { $extra_class = isset($item['class']) ? $item['class'] : null; $lis .= Display::tag('li', $item['title'], array('class' => $extra_class . ' pull-right')); } } if (!empty($lis)) { $html .= Display::tag('ul', $lis, array('class' => 'breadcrumb', 'style' => 'margin-top: 0')); } } return $html; }
/** * Display code for one specific course a logged in user is subscribed to. * Shows a link to the course, what's new icons... * * $my_course['d'] - course directory * $my_course['i'] - course title * $my_course['c'] - visual course code * $my_course['k'] - system course code * * @param array Course details * @param integer Session ID * @param string CSS class to apply to course entry * @param boolean Whether the session is supposedly accessible now * (not in the case it has passed and is in invisible/unaccessible mode) * @param bool Whether to show the document quick-loader or not * @return string The HTML to be printed for the course entry * * @version 1.0.3 * @todo refactor into different functions for database calls | logic | display * @todo replace single-character $my_course['d'] indices * @todo move code for what's new icons to a separate function to clear things up * @todo add a parameter user_id so that it is possible to show the * courselist of other users (=generalisation). * This will prevent having to write a new function for this. */ public static function get_logged_user_course_html($course, $session_id = 0, $class = 'courses', $session_accessible = true, $load_dirs = false) { $entityManager = Database::getManager(); $user_id = api_get_user_id(); $course_info = api_get_course_info_by_id($course['real_id']); $status_course = CourseManager::get_user_in_course_status($user_id, $course_info['code']); $course_info['status'] = empty($session_id) ? $status_course : STUDENT; $course_info['id_session'] = $session_id; $objUser = $entityManager->find('ChamiloUserBundle:User', $user_id); $objCourse = $entityManager->find('ChamiloCoreBundle:Course', $course['real_id']); $objSession = $entityManager->find('ChamiloCoreBundle:Session', $session_id); /*$date_start = $sess[$course_info['id_session']]['access_start_date']; $date_end = $sess[$course_info['id_session']]['access_end_date'];*/ $now = date('Y-m-d h:i:s'); // Table definitions $main_user_table = Database::get_main_table(TABLE_MAIN_USER); $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); $course_access_settings = CourseManager::get_access_settings($course_info['code']); $course_visibility = $course_access_settings['visibility']; if ($course_visibility == COURSE_VISIBILITY_HIDDEN) { return ''; } $user_in_course_status = CourseManager::get_user_in_course_status(api_get_user_id(), $course_info['code']); $is_coach = api_is_coach($course_info['id_session'], $course_info['real_id']); // Display course entry. // Show a hyperlink to the course, unless the course is closed and user is not course admin. $session_url = ''; $session_title = ''; $params = array(); $params['icon'] = Display::return_icon('blackboard_blue.png', api_htmlentities($course_info['name']), array(), ICON_SIZE_LARGE); // Display the "what's new" icons $notifications = ''; if ($course_visibility != COURSE_VISIBILITY_CLOSED && $course_visibility != COURSE_VISIBILITY_HIDDEN) { $notifications .= Display::show_notification($course_info); } if ($session_accessible) { if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) { if (empty($course_info['id_session'])) { $course_info['id_session'] = 0; } $sessionCourseAvailable = false; $sessionCourseStatus = api_get_session_visibility($session_id, $course_info['real_id']); if (in_array($sessionCourseStatus, array(SESSION_VISIBLE_READ_ONLY, SESSION_VISIBLE, SESSION_AVAILABLE))) { $sessionCourseAvailable = true; } if ($user_in_course_status == COURSEMANAGER || $sessionCourseAvailable) { $session_url = $course_info['course_public_url'] . '?id_session=' . $course_info['id_session']; $session_title = '<h4><a href="' . $session_url . '">' . $course_info['name'] . '</a>' . $notifications . '</h4>'; } else { $session_title = $course_info['name']; } } else { $session_title = $course_info['name'] . ' ' . Display::tag('span', get_lang('CourseClosed'), array('class' => 'item_closed')); } } else { $session_title = $course_info['name']; } $showCustomIcon = api_get_setting('course.course_images_in_courses_list'); $iconName = basename($course_info['course_image']); if ($showCustomIcon === 'true' && $iconName != 'course.png') { $params['icon'] = Display::img($course_info['course_image'], api_htmlentities($course_info['name']), array()); } $params['link'] = $session_url; $params['title'] = $session_title; $params['right_actions'] = ''; if ($course_visibility != COURSE_VISIBILITY_CLOSED && $course_visibility != COURSE_VISIBILITY_HIDDEN) { if ($load_dirs) { $params['right_actions'] .= '<a id="document_preview_' . $course_info['real_id'] . '_' . $course_info['id_session'] . '" class="document_preview" href="javascript:void(0);">' . Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'), ICON_SIZE_SMALL) . '</a>'; $params['right_actions'] .= Display::div('', array('id' => 'document_result_' . $course_info['real_id'] . '_' . $course_info['id_session'], 'class' => 'document_preview_container')); } } if (api_get_setting('course.display_coursecode_in_courselist') == 'true') { $session_title .= ' (' . $course_info['visual_code'] . ') '; } if (api_get_setting('course.display_teacher_in_courselist') == 'true') { $teacher_list = CourseManager::getTeacherListFromCourseToString($course_info['real_id'], self::USER_SEPARATOR, true); $course_coachs = self::get_coachs_from_course($course_info['id_session'], $course_info['real_id']); if ($course_info['status'] == COURSEMANAGER || $course_info['status'] == STUDENT && empty($course_info['id_session']) || empty($course_info['status'])) { $params['teachers'] = $teacher_list; } if ($course_info['status'] == STUDENT && !empty($course_info['id_session']) || $is_coach && $course_info['status'] != COURSEMANAGER) { $params['coaches'] = $course_coachs; } } $session_title .= isset($course['special_course']) ? ' ' . Display::return_icon('klipper.png', get_lang('CourseAutoRegister')) : ''; $params['title'] = $session_title; $params['extra'] = ''; $html = $params; $session_category_id = null; if (1) { $session = ''; $active = false; if (!empty($course_info['session_name'])) { // Request for the name of the general coach $sql = 'SELECT lastname, firstname,sc.name FROM ' . $tbl_session . ' ts LEFT JOIN ' . $main_user_table . ' tu ON ts.id_coach = tu.user_id INNER JOIN ' . $tbl_session_category . ' sc ON ts.session_category_id = sc.id WHERE ts.id=' . (int) $course_info['id_session'] . ' LIMIT 1'; $rs = Database::query($sql); $sessioncoach = Database::store_result($rs); $sessioncoach = $sessioncoach[0]; $session = array(); $session['title'] = $course_info['session_name']; $session_category_id = CourseManager::get_session_category_id_by_session_id($course_info['id_session']); $session['category'] = $sessioncoach['name']; if ($course_info['access_start_date'] == '0000-00-00') { //$session['dates'] = get_lang('WithoutTimeLimits'); $session['dates'] = ''; if (api_get_setting('session.show_session_coach') === 'true') { $session['coach'] = get_lang('GeneralCoach') . ': ' . api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); } $active = true; } else { $session['dates'] = ' - ' . get_lang('From') . ' ' . $course_info['access_start_date'] . ' ' . get_lang('To') . ' ' . $course_info['access_end_date']; if (api_get_setting('session.show_session_coach') === 'true') { $session['coach'] = get_lang('GeneralCoach') . ': ' . api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); } $active = $date_start <= $now && $date_end >= $now; } } $user_course_category = ''; if (isset($course_info['user_course_cat'])) { $user_course_category = $course_info['user_course_cat']; } $output = array($user_course_category, $html, $course_info['id_session'], $session, 'active' => $active, 'session_category_id' => $session_category_id); if (api_get_setting('skill.allow_skills_tool') === 'true') { $skill = $entityManager->getRepository('ChamiloCoreBundle:Skill')->getLastByUser($objUser, $objCourse, $objSession); $output['skill'] = null; if ($skill) { $output['skill']['name'] = $skill->getName(); $output['skill']['icon'] = $skill->getIcon(); } } } else { $output = array($course_info['user_course_cat'], $html); } return $output; }
/** * Helper functions definition */ public static function get_logged_user_course_html($my_course, $count) { $result = ''; // Table definitions $main_user_table = Database::get_main_table(TABLE_MAIN_USER); $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $course_code = $my_course['code']; $course_directory = $my_course['course_info']['directory']; $course_title = $my_course['course_info']['title']; $course_access_settings = CourseManager::get_access_settings($course_code); $course_visibility = $course_access_settings['visibility']; $user_in_course_status = CourseManager::get_user_in_course_status(api_get_user_id(), $course_code); //$valor = api_get_settings_params(); $course_path = api_get_path(SYS_COURSE_PATH) . $course_directory; // course path if (api_get_setting('course.course_images_in_courses_list') === 'true') { if (file_exists($course_path . '/course-pic85x85.png')) { $image = $my_course['course_info']['course_image']; $imageCourse = Display::img($image, $course_title, array('class' => 'img-course')); } else { $imageCourse = Display::return_icon('session_default_small.png', $course_title, array('class' => 'img-course')); } } else { $imageCourse = Display::return_icon('course.png', get_lang('Course'), array('class' => 'img-default')); } //display course entry if (api_get_setting('course.course_images_in_courses_list') === 'true') { $result .= '<li id="course_' . $count . '" class="list-group-item" style="min-height:65px;">'; } else { $result .= '<li id="course_' . $count . '" class="list-group-item" style="min-height:44px;">'; } $result .= $imageCourse; //show a hyperlink to the course, unless the course is closed and user is not course admin if ($course_visibility != COURSE_VISIBILITY_HIDDEN && ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER)) { $result .= '<span class="title">' . $course_title . '<span>'; } else { $result .= $course_title . " " . " " . get_lang('CourseClosed') . ""; } $result .= '</li>'; $session = ''; if (!empty($my_course['session_name']) && !empty($my_course['id_session'])) { // Request for the name of the general coach $sql = 'SELECT lastname, firstname FROM ' . $tbl_session . ' ts LEFT JOIN ' . $main_user_table . ' tu ON ts.id_coach = tu.user_id WHERE ts.id=' . (int) $my_course['id_session'] . ' LIMIT 1'; $rs = Database::query($sql); $sessioncoach = Database::store_result($rs); $sessioncoach = $sessioncoach[0]; $session = array(); $session['title'] = $my_course['session_name']; if ($my_course['access_start_date'] == '0000-00-00') { $session['dates'] = get_lang('WithoutTimeLimits'); if (api_get_setting('session.show_session_coach') === 'true') { $session['coach'] = get_lang('GeneralCoach') . ': ' . api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); } } else { $session['dates'] = ' - ' . get_lang('From') . ' ' . $my_course['access_start_date'] . ' ' . get_lang('To') . ' ' . $my_course['access_end_date']; if (api_get_setting('session.show_session_coach') === 'true') { $session['coach'] = get_lang('GeneralCoach') . ': ' . api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); } } } $my_course['id_session'] = isset($my_course['id_session']) ? $my_course['id_session'] : 0; $output = array($my_course['user_course_cat'], $result, $my_course['id_session'], $session); return $output; }
/** * Converts HTML files to PDF * @param mixed $html_file_array could be an html file path or an array * with paths example: * /var/www/myfile.html or array('/myfile.html','myotherfile.html') or * even an indexed array with both 'title' and 'path' indexes * for each element like * array( * 0 => array('title'=>'Hello','path'=>'file.html'), * 1 => array('title'=>'Bye','path'=>'file2.html') * ); * @param string pdf name * @param string course code (if you are using html that are located in the document tool you must provide this) * @param bool Whether to print the header, footer and watermark (true) or just the content (false) * @return bool */ public function html_to_pdf( $html_file_array, $pdf_name = '', $course_code = null, $print_title = false, $complete_style = true ) { if ($complete_style === false) { error_log(__FUNCTION__.' with no style'); } if (empty($html_file_array)) { return false; } if (is_array($html_file_array)) { if (count($html_file_array) == 0) { return false; } } else { if (!file_exists($html_file_array)) { return false; } // Converting the string into an array $html_file_array = array($html_file_array); } if (!empty($course_code)) { $course_data = api_get_course_info($course_code); } else { $course_data = api_get_course_info(); } // Clean styles and javascript document $clean_search = array ( '@<script[^>]*?>.*?</script>@si', '@<style[^>]*?>.*?</style>@si' ); // Formatting the pdf self::format_pdf($course_data, $complete_style); $counter = 1; foreach ($html_file_array as $file) { //Add a page break per file $page_break = '<pagebreak>'; if ($counter == count($html_file_array)) { $page_break = ''; } $counter++; //if the array provided contained subarrays with 'title' entry, // then print the title in the PDF if (is_array($file) && isset($file['title'])) { $html_title = $file['title']; $file = $file['path']; } else { //we suppose we've only been sent a file path $html_title = basename($file); } if (empty($file) && !empty($html_title)) { //this is a chapter, print title & skip the rest if ($print_title) { $this->pdf->WriteHTML( '<html><body><h3>'.$html_title.'</h3></body></html>'.$page_break, 2 ); } continue; } if (!file_exists($file)) { //the file doesn't exist, skip continue; } //it's not a chapter but the file exists, print its title if ($print_title) { $this->pdf->WriteHTML( '<html><body><h3>' . $html_title . '</h3></body></html>', 2 ); } $file_info = pathinfo($file); $extension = $file_info['extension']; if (in_array($extension, array('html', 'htm'))) { $filename = $file_info['basename']; $filename = str_replace('_',' ',$filename); if ($extension == 'html') { $filename = basename($filename,'.html'); } elseif($extension == 'htm'){ $filename = basename($filename,'.htm'); } $document_html = @file_get_contents($file); $document_html = preg_replace($clean_search, '', $document_html); //absolute path for frames.css //TODO: necessary? $absolute_css_path = api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/frames.css'; $document_html = str_replace('href="./css/frames.css"', $absolute_css_path, $document_html); if (!empty($course_data['path'])) { $document_html= str_replace('../','', $document_html); $document_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document/'; $doc = new DOMDocument(); $result = @$doc->loadHTML($document_html); //Fixing only images @todo do the same thing with other elements $elements = $doc->getElementsByTagName('img'); if (!empty($elements)) { foreach ($elements as $item) { $old_src = $item->getAttribute('src'); if (strpos($old_src, 'http') === false) { if (strpos($old_src, '/main/default_course_document') === false) { $old_src_fixed = ''; if (strpos($old_src, '/main/img') === false) { if (api_get_path(REL_PATH) != '/') { $old_src_fixed = str_replace(api_get_path(REL_PATH).'courses/'.$course_data['path'].'/document/', '', $old_src); } else { $old_src_fixed = str_replace('courses/'.$course_data['path'].'/document/', '', $old_src); } $new_path = $document_path.$old_src_fixed; } else { $new_path = $old_src; } $document_html= str_replace($old_src, $new_path, $document_html); } } else { //Check if this is a complete URL /*if (strpos($old_src, 'courses/'.$course_data['path'].'/document/') === false) { } else { $old_src_fixed = str_replace(api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document/', '', $old_src); $new_path = $document_path.$old_src_fixed; $document_html= str_replace($old_src, $new_path, $document_html); }*/ } } } } api_set_encoding_html($document_html, 'UTF-8'); // The library mPDF expects UTF-8 encoded input data. // TODO: Maybe it is better idea the title to be passed through $title = api_get_title_html($document_html, 'UTF-8', 'UTF-8'); // $_GET[] too, as it is done with file name. // At the moment the title is retrieved from the html document itself. //echo $document_html;exit; if (empty($title)) { $title = $filename; // Here file name is expected to contain ASCII symbols only. } if (!empty($document_html)) { $this->pdf->WriteHTML($document_html.$page_break, 2); } } elseif (in_array($extension, array('jpg','jpeg','png','gif'))) { //Images $image = Display::img($file); $this->pdf->WriteHTML('<html><body>'.$image.'</body></html>'.$page_break, 2); } } if (empty($pdf_name)) { $output_file = 'pdf_'.date('Y-m-d-his').'.pdf'; } else { $pdf_name = replace_dangerous_char($pdf_name); $output_file = $pdf_name.'.pdf'; } // F to save the pdf in a file $this->pdf->Output($output_file, 'D'); exit; }
/** * Get the users to display on the current page. */ function get_user_data($from, $number_of_items, $column, $direction) { global $is_western_name_order; global $extraFields; $type = isset($_REQUEST['type']) ? intval($_REQUEST['type']) : STUDENT; $course_info = api_get_course_info(); $sessionId = api_get_session_id(); $course_code = $course_info['code']; $a_users = array(); $limit = null; // limit if (!isset($_GET['keyword']) || empty($_GET['keyword'])) { $limit = 'LIMIT ' . intval($from) . ',' . intval($number_of_items); } if (!in_array($direction, array('ASC', 'DESC'))) { $direction = 'ASC'; } switch ($column) { case 2: //official code $order_by = 'ORDER BY user.official_code ' . $direction; break; case 3: if ($is_western_name_order) { $order_by = 'ORDER BY user.firstname ' . $direction . ', user.lastname ' . $direction; } else { $order_by = 'ORDER BY user.lastname ' . $direction . ', user.firstname ' . $direction; } break; case 4: if ($is_western_name_order) { $order_by = 'ORDER BY user.lastname ' . $direction . ', user.firstname ' . $direction; } else { $order_by = 'ORDER BY user.firstname ' . $direction . ', user.lastname ' . $direction; } break; case 5: //username $order_by = 'ORDER BY user.username ' . $direction; break; default: if ($is_western_name_order) { $order_by = 'ORDER BY user.lastname ' . $direction . ', user.firstname ' . $direction; } else { $order_by = 'ORDER BY user.firstname ' . $direction . ', user.lastname ' . $direction; } break; } $active = isset($_GET['active']) ? $_GET['active'] : null; if (empty($sessionId)) { $status = $type; } else { if ($type == COURSEMANAGER) { $status = 2; } else { $status = 0; } } $a_course_users = CourseManager::get_user_list_from_course_code($course_code, $sessionId, $limit, $order_by, $status, null, false, false, null, array(), array(), $active); foreach ($a_course_users as $user_id => $o_course_user) { if (isset($_GET['keyword']) && searchUserKeyword($o_course_user['firstname'], $o_course_user['lastname'], $o_course_user['username'], $o_course_user['official_code'], $_GET['keyword']) || !isset($_GET['keyword']) || empty($_GET['keyword'])) { $groupsNameList = GroupManager::getAllGroupPerUserSubscription($user_id); $groupsNameListParsed = []; if (!empty($groupsNameList)) { $groupsNameListParsed = array_column($groupsNameList, 'name'); } $temp = array(); if (api_is_allowed_to_edit(null, true)) { $userInfo = api_get_user_info($user_id); $photo = Display::img($userInfo['avatar_small'], $userInfo['complete_name'], [], false); $temp[] = $user_id; $temp[] = $photo; $temp[] = $o_course_user['official_code']; if ($is_western_name_order) { $temp[] = $o_course_user['firstname']; $temp[] = $o_course_user['lastname']; } else { $temp[] = $o_course_user['lastname']; $temp[] = $o_course_user['firstname']; } $temp[] = $o_course_user['username']; // Groups. $temp[] = implode(', ', $groupsNameListParsed); // Status $default_status = get_lang('Student'); if (isset($o_course_user['status_rel']) && $o_course_user['status_rel'] == 1 || isset($o_course_user['status_session']) && $o_course_user['status_session'] == 2) { $default_status = get_lang('CourseManager'); } elseif (isset($o_course_user['is_tutor']) && $o_course_user['is_tutor'] == 1) { $default_status = get_lang('Tutor'); } $temp[] = $default_status; // Active $temp[] = $o_course_user['active']; if (!empty($extraFields)) { foreach ($extraFields as $extraField) { $extraFieldValue = new ExtraFieldValue('user'); $data = $extraFieldValue->get_values_by_handler_and_field_id($user_id, $extraField['id']); $temp[] = $data['value']; } } // User id for actions $temp[] = $user_id; $temp['is_tutor'] = isset($o_course_user['is_tutor']) ? $o_course_user['is_tutor'] : ''; $temp['user_status_in_course'] = isset($o_course_user['status_rel']) ? $o_course_user['status_rel'] : ''; } else { $userInfo = api_get_user_info($user_id); $userPicture = $userInfo['avatar']; $photo = '<img src="' . $userPicture . '" alt="' . $userInfo['complete_name'] . '" width="22" height="22" title="' . $userInfo['complete_name'] . '" />'; $temp[] = $user_id; $temp[] = $photo; $temp[] = $o_course_user['official_code']; if ($is_western_name_order) { $temp[] = $o_course_user['firstname']; $temp[] = $o_course_user['lastname']; } else { $temp[] = $o_course_user['lastname']; $temp[] = $o_course_user['firstname']; } $temp[] = $o_course_user['username']; // Group. $temp[] = implode(', ', $groupsNameListParsed); if ($course_info['unsubscribe'] == 1) { //User id for actions $temp[] = $user_id; } } $a_users[$user_id] = $temp; } } return $a_users; }
$template->addGlobal('is_allowed_to_edit', $is_allowed_to_edit); $template->addGlobal('gamification_mode', $gamificationMode); $template->addGlobal('breadcrumb', $breadcrumb); $template->addGlobal('button_home_url', $buttonHomeUrl); $template->addGlobal('button_home_text', $buttonHomeText); $template->addGlobal('navigation_bar', $navigation_bar); $template->addGlobal('progress_bar', $progress_bar); $template->addGlobal('show_audio_player', $show_audioplayer); $template->addGlobal('media_player', $mediaplayer); $template->addGlobal('toc_list', $get_toc_list); $template->addGlobal('teacher_toc_buttons', $get_teacher_buttons); $template->addGlobal('iframe_src', $src); $template->addGlobal('navigation_bar_bottom', $navigation_bar_bottom); if ($gamificationMode == 1) { $template->addGlobal('gamification_stars', $learnPath->getCalculateStars($sessionId)); $template->addGlobal('gamification_points', $learnPath->getCalculateScore($sessionId)); } $template->addGlobal('lp_preview_image', Display::img($lpPreviewImagePath, $learnPath->name, array('class' => 'img-circle'), ICON_SIZE_BIG)); $template->addGlobal('lp_author', $learnPath->get_author()); $template->addGlobal('lp_mode', $learnPath->mode); $template->addGlobal('lp_title_scorm', $learnPath->name); $template->addGlobal('lp_html_toc', $learnPath->get_html_toc($get_toc_list)); $template->addGlobal('lp_id', $learnPath->lp_id); $template->addGlobal('lp_current_item_id', $learnPath->get_current_item_id()); $content = $template->render('@template_style/learnpath/view.html.twig'); echo $content; // Restore a global setting. $_setting['show_navigation_menu'] = $save_setting; // Hide headers Container::$legacyTemplate = 'layout_one_col_no_content.html.twig'; $learnPath->updateCurrentLpFromSession();
/** * Displays the tools of a certain category. * @param array $all_tools_list List of tools as returned by get_tools_category() * @param bool $rows * * @return void */ public static function show_tools_category($all_tools_list, $rows = false) { $_user = api_get_user_info(); $theme = api_get_setting('homepage_view'); if ($theme == 'vertical_activity') { //ordering by get_lang name $order_tool_list = array(); if (is_array($all_tools_list) && count($all_tools_list) > 0) { foreach ($all_tools_list as $key => $new_tool) { $tool_name = self::translate_tool_name($new_tool); $order_tool_list[$key] = $tool_name; } natsort($order_tool_list); $my_temp_tool_array = array(); foreach ($order_tool_list as $key => $new_tool) { $my_temp_tool_array[] = $all_tools_list[$key]; } $all_tools_list = $my_temp_tool_array; } else { $all_tools_list = array(); } } $web_code_path = api_get_path(WEB_CODE_PATH); $session_id = api_get_session_id(); $is_platform_admin = api_is_platform_admin(); if ($session_id == 0) { $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin(); } else { $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach(); } $i = 0; $items = array(); $app_plugin = new AppPlugin(); if (isset($all_tools_list)) { $lnk = ''; foreach ($all_tools_list as &$tool) { $item = array(); $studentview = false; $tool['original_link'] = $tool['link']; if ($tool['image'] == 'scormbuilder.gif') { // check if the published learnpath is visible for student $published_lp_id = self::get_published_lp_id_from_link($tool['link']); if (api_is_allowed_to_edit(null, true)) { $studentview = true; } if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id(), api_get_course_id(), api_get_session_id())) { continue; } } if ($session_id != 0 && in_array($tool['name'], array('course_setting'))) { continue; } // This part displays the links to hide or remove a tool. // These links are only visible by the course manager. unset($lnk); $item['extra'] = null; $toolAdmin = isset($tool['admin']) ? $tool['admin'] : ''; if ($is_allowed_to_edit) { if (empty($session_id)) { if (isset($tool['id'])) { if ($tool['visibility'] == '1' && $toolAdmin != '1') { $link['name'] = Display::return_icon('visible.png', get_lang('Deactivate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_SMALL, false); $link['cmd'] = 'hide=yes'; $lnk[] = $link; } if ($tool['visibility'] == '0' && $toolAdmin != '1') { $link['name'] = Display::return_icon('invisible.png', get_lang('Activate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_SMALL, false); $link['cmd'] = 'restore=yes'; $lnk[] = $link; } } } if (!empty($tool['adminlink'])) { $item['extra'] = '<a href="' . $tool['adminlink'] . '">' . Display::return_icon('edit.gif', get_lang('Edit')) . '</a>'; } } // Both checks are necessary as is_platform_admin doesn't take student view into account if ($is_platform_admin && $is_allowed_to_edit) { if ($toolAdmin != '1') { $link['cmd'] = 'hide=yes'; } } $item['visibility'] = null; if (isset($lnk) && is_array($lnk)) { foreach ($lnk as $this_link) { if (empty($tool['adminlink'])) { $item['visibility'] .= '<a class="make_visible_and_invisible" href="' . api_get_self() . '?' . api_get_cidreq() . '&id=' . $tool['id'] . '&' . $this_link['cmd'] . '">' . $this_link['name'] . '</a>'; } } } else { $item['visibility'] .= ''; } // NOTE : Table contains only the image file name, not full path if (stripos($tool['link'], 'http://') === false && stripos($tool['link'], 'https://') === false && stripos($tool['link'], 'ftp://') === false) { $tool['link'] = $web_code_path . $tool['link']; } if ($tool['visibility'] == '0' && $toolAdmin != '1' && !isset($tool['original_link'])) { $class = 'invisible'; $info = pathinfo($tool['image']); $basename = basename($tool['image'], '.' . $info['extension']); // $file is set to "index" $tool['image'] = $basename . '_na.' . $info['extension']; } else { $class = ''; } $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&'; // If it's a link, we don't add the cidReq if ($tool['image'] == 'file_html.png' || $tool['image'] == 'file_html_na.png') { $tool['link'] = $tool['link'] . $qm_or_amp; } else { $tool['link'] = $tool['link'] . $qm_or_amp . api_get_cidreq(); } $tool_link_params = array(); $toolId = isset($tool["id"]) ? $tool["id"] : null; //@todo this visio stuff should be removed if (strpos($tool['name'], 'visio_') !== false) { $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'href' => '"javascript: void(0);"', 'class' => $class, 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_visio' . $_SESSION['_cid'] . '\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']); } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) { $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'class' => $class, 'href' => 'javascript: void(0);', 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_chat' . $_SESSION['_cid'] . '\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']); } else { if (count(explode('type=classroom', $tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) { $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'href' => $tool['link'], 'class' => $class, 'target' => '_blank'); } else { $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'href' => $tool['link'], 'class' => $class, 'target' => $tool['target']); } } $tool_name = self::translate_tool_name($tool); // Including Courses Plugins // Creating title and the link if (isset($tool['category']) && $tool['category'] == 'plugin') { $plugin_info = $app_plugin->getPluginInfo($tool['name']); if (isset($plugin_info) && isset($plugin_info['title'])) { $tool_name = $plugin_info['title']; } if (!file_exists(api_get_path(SYS_CODE_PATH) . 'img/' . $tool['image']) && !file_exists(api_get_path(SYS_CODE_PATH) . 'img/icons/22/' . $tool['image'])) { $tool['image'] = 'plugins.png'; } $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH) . $tool['original_link'] . '?' . api_get_cidreq(); } $icon = Display::return_icon($tool['image'], $tool_name, array('class' => 'tool-icon', 'id' => 'toolimage_' . $toolId), ICON_SIZE_BIG, false); /*if (!empty($tool['custom_icon'])) { $image = self::getCustomWebIconPath().$tool['custom_icon']; $icon = Display::img( $image, $tool['description'], array( 'class' => 'tool-icon', 'id' => 'toolimage_'.$tool['id'] ) ); }*/ // Validation when belongs to a session $session_img = api_get_session_image($tool['session_id'], !empty($_user['status']) ? $_user['status'] : ''); if ($studentview) { $tool_link_params['href'] .= '&isStudentView=true'; } $item['url_params'] = $tool_link_params; $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params); $item['tool'] = $tool; $item['name'] = $tool_name; $tool_link_params['id'] = 'is' . $tool_link_params['id']; $item['link'] = Display::url($tool_name . $session_img, $tool_link_params['href'], $tool_link_params); $items[] = $item; $i++; } // end of foreach } $i = 0; $html = ''; if (!empty($items)) { foreach ($items as $item) { switch ($theme) { case 'activity_big': $data = ''; $html .= '<div class="col-xs-6 col-md-3 course-tool">'; $image = substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.')) . '.png'; $toolId = isset($item['tool']['id']) ? $item['tool']['id'] : null; if (isset($item['tool']['custom_image'])) { $original_image = Display::img($item['tool']['custom_image'], $item['name'], array('id' => 'toolimage_' . $toolId)); } elseif (isset($item['tool']['custom_icon']) && !empty($item['tool']['custom_icon'])) { $customIcon = $item['tool']['custom_icon']; if ($item['tool']['visibility'] == '0') { $fileInfo = pathinfo($item['tool']['custom_icon']); $customIcon = self::getDisableIcon($item['tool']['custom_icon']); } $original_image = Display::img(self::getCustomWebIconPath() . $customIcon, $item['name'], array('id' => 'toolimage_' . $toolId)); } else { $original_image = Display::return_icon($image, $item['name'], array('id' => 'toolimage_' . $toolId), ICON_SIZE_BIG, false); } $data .= Display::url($original_image, $item['url_params']['href'], $item['url_params']); $html .= Display::div($data, array('class' => 'big_icon')); //box-image reflection $html .= Display::div('<h4>' . $item['visibility'] . $item['extra'] . $item['link'] . '</h4>', array('class' => 'content')); $html .= '</div>'; break; case 'activity': $html .= '<div class="offset2 col-md-4 course-tool">'; $html .= $item['extra']; $html .= $item['visibility']; $html .= $item['icon']; $html .= $item['link']; $html .= '</div>'; break; case 'vertical_activity': if ($i == 0) { $html .= '<ul>'; } $html .= '<li class="course-tool">'; $html .= $item['extra']; $html .= $item['visibility']; $html .= $item['icon']; $html .= $item['link']; $html .= '</li>'; if ($i == count($items) - 1) { $html .= '</ul>'; } break; } $i++; } } return $html; }
/** * display message box in the inbox * @param int the message id * @param string inbox or outbox strings are available * @todo replace numbers with letters in the $row array pff... * @return string html with the message content */ public static function show_message_box($message_id, $source = 'inbox') { $table_message = Database::get_main_table(TABLE_MESSAGE); $message_id = intval($message_id); if ($source == 'outbox') { if (isset($message_id) && is_numeric($message_id)) { $query = "SELECT * FROM {$table_message}\n WHERE\n user_sender_id = " . api_get_user_id() . " AND\n id = " . $message_id . " AND\n msg_status = 4;"; $result = Database::query($query); } } else { if (is_numeric($message_id) && !empty($message_id)) { $query = "UPDATE {$table_message} SET\n msg_status = '" . MESSAGE_STATUS_NEW . "'\n WHERE\n user_receiver_id=" . api_get_user_id() . " AND\n id='" . $message_id . "'"; Database::query($query); $query = "SELECT * FROM {$table_message}\n WHERE\n msg_status<>4 AND\n user_receiver_id=" . api_get_user_id() . " AND\n id='" . $message_id . "'"; $result = Database::query($query); } } $row = Database::fetch_array($result, 'ASSOC'); $user_sender_id = $row['user_sender_id']; // get file attachments by message id $files_attachments = self::get_links_message_attachment_files($message_id, $source); $user_con = self::users_connected_by_id(); $band = 0; for ($i = 0; $i < count($user_con); $i++) { if ($user_sender_id == $user_con[$i]) { $band = 1; } } $title = Security::remove_XSS($row['title'], STUDENT, true); $content = Security::remove_XSS($row['content'], STUDENT, true); $from_user = api_get_user_info($user_sender_id); $name = $from_user['complete_name']; $user_image = Display::img($from_user['avatar'], $name, array('title' => $name)); $message_content = Display::page_subheader(str_replace("\\", "", $title)); if (api_get_setting('social.allow_social_tool') == 'true') { $message_content .= $user_image . ' '; } $receiverUserInfo = api_get_user_info($row['user_receiver_id']); $message_content .= '<tr>'; if (api_get_setting('social.allow_social_tool') == 'true') { if ($source == 'outbox') { $message_content .= get_lang('From') . ': <a href="' . api_get_path(WEB_PATH) . 'main/social/profile.php?u=' . $user_sender_id . '">' . $name . '</a> ' . api_strtolower(get_lang('To')) . ' <b>' . $receiverUserInfo['complete_name'] . '</b>'; } else { $message_content .= get_lang('From') . ' <a href="' . api_get_path(WEB_PATH) . 'main/social/profile.php?u=' . $user_sender_id . '">' . $name . '</a> ' . api_strtolower(get_lang('To')) . ' <b>' . get_lang('Me') . '</b>'; } } else { if ($source == 'outbox') { $message_content .= get_lang('From') . ': ' . $name . '</b> ' . api_strtolower(get_lang('To')) . ' <b>' . $receiverUserInfo['complete_name'] . '</b>'; } else { $message_content .= get_lang('From') . ': ' . $name . '</b> ' . api_strtolower(get_lang('To')) . ' <b>' . get_lang('Me') . '</b>'; } } $message_content .= ' ' . get_lang('Date') . ': ' . api_get_local_time($row['send_date']) . ' <br /> <hr style="color:#ddd" /> <table height="209px" width="100%"> <tr> <td valign=top class="view-message-content">' . str_replace("\\", "", $content) . '</td> </tr> </table> <div id="message-attach">' . (!empty($files_attachments) ? implode('<br />', $files_attachments) : '') . '</div> <div style="padding: 15px 0px 5px 0px">'; $social_link = ''; if (isset($_GET['f']) && $_GET['f'] == 'social') { $social_link = 'f=social'; } if ($source == 'outbox') { $message_content .= '<a href="outbox.php?' . $social_link . '">' . Display::return_icon('back.png', get_lang('ReturnToOutbox')) . '</a>  '; } else { $message_content .= '<a href="inbox.php?' . $social_link . '">' . Display::return_icon('back.png', get_lang('ReturnToInbox')) . '</a>  '; $message_content .= '<a href="new_message.php?re_id=' . $message_id . '&' . $social_link . '">' . Display::return_icon('message_reply.png', get_lang('ReplyToMessage')) . '</a>  '; } $message_content .= '<a href="inbox.php?action=deleteone&id=' . $message_id . '&' . $social_link . '" >' . Display::return_icon('delete.png', get_lang('DeleteMessage')) . '</a> '; $message_content .= '</div></td> <td width=10></td> </tr> </table>'; return $message_content; }
/** * Shows a question * @param Question $objQuestionTmp * @param bool $only_questions if true only show the questions, no exercise title * @param bool $origin 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 null $exercise_feedback * @param bool $show_answers * @param null $modelType * @param bool $categoryMinusOne * @return bool|null|string */ public function showQuestion(Question $objQuestionTmp, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false, $modelType = null, $categoryMinusOne = true) { // Text direction for the current language //$is_ltr_text_direction = api_get_text_direction() != 'rtl'; // Change false to true in the following line to enable answer hinting $debug_mark_answer = $show_answers; //api_is_allowed_to_edit() && false; // Reads question information if (!$objQuestionTmp) { // Question not found return false; } $html = null; $questionId = $objQuestionTmp->id; if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) { $show_comment = false; } $answerType = $objQuestionTmp->selectType(); $pictureName = $objQuestionTmp->selectPicture(); $s = null; $form = new FormValidator('question'); $renderer = $form->defaultRenderer(); $form_template = '{content}'; $renderer->setFormTemplate($form_template); if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) { // Question is not a hotspot if (!$only_questions) { $questionDescription = $objQuestionTmp->selectDescription(); if ($show_title) { $categoryName = TestCategory::getCategoryNamesForQuestion($objQuestionTmp->id, null, true, $categoryMinusOne); $html .= $categoryName; $html .= Display::div($current_item . '. ' . $objQuestionTmp->selectTitle(), array('class' => 'question_title')); if (!empty($questionDescription)) { $html .= Display::div($questionDescription, array('class' => 'question_description')); } } else { $html .= '<div class="media">'; $html .= '<div class="pull-left">'; $html .= '<div class="media-object">'; $html .= Display::div($current_item, array('class' => 'question_no_title')); $html .= '</div>'; $html .= '</div>'; $html .= '<div class="media-body">'; if (!empty($questionDescription)) { $html .= Display::div($questionDescription, array('class' => 'question_description')); } $html .= '</div>'; $html .= '</div>'; } } if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) { return null; } $html .= '<div class="question_options">'; // construction of the Answer object (also gets all answers details) $objAnswerTmp = new Answer($questionId, null, $this); $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); $course_id = api_get_course_int_id(); $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 ($answerType == MATCHING || $answerType == DRAGGABLE) { if ($answerType == DRAGGABLE) { $s .= '<div class="ui-widget ui-helper-clearfix"> <ul class="drag_question ui-helper-reset ui-helper-clearfix">'; } else { $s .= '<div id="drag' . $questionId . '_question" class="drag_question">'; $s .= '<table class="data_table">'; } $j = 1; //iterate through answers $letter = 'A'; //mark letters for each answer $answer_matching = array(); $capital_letter = array(); //for ($answerId=1; $answerId <= $nbrAnswers; $answerId++) { foreach ($objAnswerTmp->answer as $answerId => $answer_item) { $answerCorrect = $objAnswerTmp->isCorrect($answerId); $answer = $objAnswerTmp->selectAnswer($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 $capital_letter[$j] = $letter; //$answer_matching[$j]=$objAnswerTmp->selectAnswerByAutoId($numAnswer); $answer_matching[$j] = array('id' => $answerId, 'answer' => $answer); $j++; $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']; $select_items[$i]['letter'] = $capital_letter[$id]; $select_items[$i]['answer'] = $value['answer']; $i++; } $num_suggestions = $nbrAnswers - $j + 1; } elseif ($answerType == FREE_ANSWER) { $content = isset($user_choice[0]) && !empty($user_choice[0]['answer']) ? $user_choice[0]['answer'] : null; $toolBar = 'TestFreeAnswer'; if ($modelType == EXERCISE_MODEL_TYPE_COMMITTEE) { $toolBar = 'TestFreeAnswerStrict'; } $form->addElement('html_editor', "choice[" . $questionId . "]", null, array('id' => "choice[" . $questionId . "]"), array('ToolbarSet' => $toolBar)); $form->setDefaults(array("choice[" . $questionId . "]" => $content)); $s .= $form->return_form(); } elseif ($answerType == ORAL_EXPRESSION) { // Add nanogong if (api_get_setting('document.enable_nanogong') == 'true') { //@todo pass this as a parameter global $exercise_stat_info, $exerciseId; 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); $s .= $nano->show_button(); } $form->addElement('html_editor', "choice[" . $questionId . "]", null, array('id' => "choice[" . $questionId . "]"), array('ToolbarSet' => 'TestFreeAnswer')); //$form->setDefaults(array("choice[".$questionId."]" => $content)); $s .= $form->return_form(); } // 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) { $header .= Display::tag('th', $item); } if ($show_comment) { $header .= Display::tag('th', get_lang('Feedback')); } $s .= '<table class="data_table">'; $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_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="data_table">'; $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']; } } foreach ($objAnswerTmp->answer as $answerId => $answer_item) { $answer = $objAnswerTmp->selectAnswer($answerId); $answerCorrect = $objAnswerTmp->isCorrect($answerId); $comment = $objAnswerTmp->selectComment($answerId); //$numAnswer = $objAnswerTmp->selectAutoId($answerId); $numAnswer = $answerId; $attributes = array(); // Unique answer if (in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_IMAGE, UNIQUE_ANSWER_NO_OPTION))) { $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; } } $answer = Security::remove_XSS($answer); $s .= Display::input('hidden', 'choice2[' . $questionId . ']', '0'); $answer_input = null; if ($answerType == UNIQUE_ANSWER_IMAGE) { $attributes['style'] = 'display:none'; $answer_input .= '<div id="answer' . $questionId . $numAnswer . '" style="float:left" class="highlight_image_default highlight_image">'; } $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 .= '<tr><td>'; $s .= $answer_input; $s .= '</td>'; $s .= '<td>'; $s .= $comment; $s .= '</td>'; $s .= '</tr>'; } else { $s .= $answer_input; } } elseif (in_array($answerType, array(MULTIPLE_ANSWER, MULTIPLE_ANSWER_TRUE_FALSE, GLOBAL_MULTIPLE_ANSWER))) { $input_id = 'choice-' . $questionId . '-' . $answerId; $answer = Security::remove_XSS($answer); 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) { $id = $item['iid']; 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); $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); $my_choice[$item[0]] = $item[1]; } } $answer = Security::remove_XSS($answer); $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) { list($answer) = explode('::', $answer); //Correct answer api_preg_match_all('/\\[[^]]+\\]/', $answer, $correct_answer_list); //Student's answezr if (isset($user_choice[0]['answer'])) { api_preg_match_all('/\\[[^]]+\\]/', $user_choice[0]['answer'], $student_answer_list); $student_answer_list = $student_answer_list[0]; } //If debug if ($debug_mark_answer) { $student_answer_list = $correct_answer_list[0]; } if (!empty($correct_answer_list) && !empty($student_answer_list)) { $correct_answer_list = $correct_answer_list[0]; $i = 0; foreach ($correct_answer_list as $correct_item) { $value = null; if (isset($student_answer_list[$i]) && !empty($student_answer_list[$i])) { //Cleaning student answer list $value = strip_tags($student_answer_list[$i]); $value = api_substr($value, 1, api_strlen($value) - 2); $value = explode('/', $value); if (!empty($value[0])) { $value = str_replace(' ', '', trim($value[0])); } $correct_item = preg_quote($correct_item); $correct_item = api_preg_replace('|/|', '\\/', $correct_item); // to prevent error if there is a / in the text to find $answer = api_preg_replace('/' . $correct_item . '/', Display::input('text', "choice[{$questionId}][]", $value), $answer, 1); } $i++; } } else { $answer = api_preg_replace('/\\[[^]]+\\]/', Display::input('text', "choice[{$questionId}][]", '', $attributes), $answer); } $s .= $answer; } elseif ($answerType == MATCHING) { // matching type, showing suggestions and answers // TODO: replace $answerId by $numAnswer if ($lines_count == 1) { $s .= $objAnswerTmp->getJs(); } if ($answerCorrect != 0) { // only show elements to be answered (not the contents of // the select boxes, who are correct = 0) $s .= '<tr><td width="45%">'; $parsed_answer = $answer; $windowId = $questionId . '_' . $lines_count; //left part questions $s .= ' <div id="window_' . $windowId . '" class="window window_left_question window' . $questionId . '_question"> <b>' . $lines_count . '</b>. ' . $parsed_answer . ' </div> </td>'; // middle part (matches selects) $s .= '<td width="10%" align="center"> '; $s .= '<div style="display:block">'; $s .= '<select id="window_' . $windowId . '_select" name="choice[' . $questionId . '][' . $numAnswer . ']">'; $selectedValue = 0; // fills the list-box $item = 0; foreach ($select_items as $val) { // set $debug_mark_answer to true at public static function start to // show the correct answer with a suffix '-x' $selected = ''; if ($debug_mark_answer) { if ($val['id'] == $answerCorrect) { $selected = 'selected="selected"'; $selectedValue = $val['id']; } } if (isset($user_choice[$matching_correct_answer]) && $val['id'] == $user_choice[$matching_correct_answer]['answer']) { $selected = 'selected="selected"'; $selectedValue = $val['id']; } //$s .= '<option value="'.$val['id'].'" '.$selected.'>'.$val['letter'].'</option>'; $s .= '<option value="' . $item . '" ' . $selected . '>' . $val['letter'] . '</option>'; $item++; } if (!empty($answerCorrect) && !empty($selectedValue)) { $s .= '<script> jsPlumb.ready(function() { jsPlumb.connect({ source: "window_' . $windowId . '", target: "window_' . $questionId . '_' . $selectedValue . '_answer", endpoint:["Blank", { radius:15 }], anchor:["RightMiddle","LeftMiddle"], paintStyle:{ strokeStyle:"#8a8888" , lineWidth:8 }, connector: [connectorType, { curviness: curvinessValue } ], }) }); </script>'; } $s .= '</select></div></td>'; $s .= '<td width="45%" valign="top" >'; if (isset($select_items[$lines_count])) { $s .= '<div id="window_' . $windowId . '_answer" class="window window_right_question"> <b>' . $select_items[$lines_count]['letter'] . '.</b> ' . $select_items[$lines_count]['answer'] . ' </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>'; $s .= $select_items[$lines_count]['answer']; $s .= "</td>\n </tr>"; $lines_count++; } // end while() } // end if() $matching_correct_answer++; } } elseif ($answerType == DRAGGABLE) { // 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 correct = 0) $s .= '<td>'; $parsed_answer = $answer; $windowId = $questionId . '_' . $numAnswer; //67_293 - 67_294 //left part questions $s .= '<li class="ui-state-default" id="' . $windowId . '">'; $s .= ' <div id="window_' . $windowId . '" class="window' . $questionId . '_question_draggable question_draggable"> ' . $parsed_answer . ' </div>'; $s .= '<div style="display:none">'; $s .= '<select id="window_' . $windowId . '_select" name="choice[' . $questionId . '][' . $numAnswer . ']" class="select_option">'; $selectedValue = 0; // fills the list-box $item = 0; foreach ($select_items as $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"'; $selectedValue = $val['id']; } } if (isset($user_choice[$matching_correct_answer]) && $val['id'] == $user_choice[$matching_correct_answer]['answer']) { $selected = 'selected="selected"'; $selectedValue = $val['id']; } //$s .= '<option value="'.$val['id'].'" '.$selected.'>'.$val['letter'].'</option>'; $s .= '<option value="' . $item . '" ' . $selected . '>' . $val['letter'] . '</option>'; $item++; } $s .= '</select>'; if (!empty($answerCorrect) && !empty($selectedValue)) { $s .= '<script> $(function() { deleteItem($("#' . $questionId . '_' . $selectedValue . '"), $("#drop_' . $windowId . '")); }); </script>'; } if (isset($select_items[$lines_count])) { $s .= '<div id="window_' . $windowId . '_answer" class=""> <b>' . $select_items[$lines_count]['letter'] . '.</b> ' . $select_items[$lines_count]['answer'] . ' </div>'; } else { $s .= ' '; } $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 .= '<b>' . $select_items[$lines_count]['letter'] . '.</b>'; $s .= $select_items[$lines_count]['answer']; $lines_count++; } } $s .= '</div>'; $matching_correct_answer++; $s .= '</li>'; } } } // end for() if ($show_comment) { $s .= '</table>'; } else { if ($answerType == MATCHING || $answerType == UNIQUE_ANSWER_NO_OPTION || $answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { $s .= '</table>'; } } if ($answerType == DRAGGABLE) { $s .= '</ul><div class="clear"></div>'; $counterAnswer = 1; foreach ($objAnswerTmp->answer as $answerId => $answer_item) { $answerCorrect = $objAnswerTmp->isCorrect($answerId); $windowId = $questionId . '_' . $counterAnswer; if ($answerCorrect == 0) { $s .= '<div id="drop_' . $windowId . '" class="droppable ui-state-default">' . $counterAnswer . '</div>'; $counterAnswer++; } } } if ($answerType == MATCHING) { $s .= '</div>'; } $s .= '</div>'; // destruction of the Answer object unset($objAnswerTmp); // destruction of the Question object unset($objQuestionTmp); $html .= $s; return $html; } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) { // 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) { $s .= Display::img($objQuestionTmp->selectPicturePath()); $html .= $s; return $html; } // Get the answers, make a list $objAnswerTmp = new Answer($questionId); // get answers of hotpost $answers_hotspot = array(); foreach ($objAnswerTmp->answer as $answerId => $answer_item) { //$answers = $objAnswerTmp->selectAnswerByAutoId($objAnswerTmp->selectAutoId($answerId)); $answers_hotspot[$answerId] = $objAnswerTmp->selectAnswer($answerId); } // display answers of hotpost order by id $answer_list = '<div style="padding: 10px; margin-left: 0px; border: 1px solid #A4A4A4; height: 408px; width: 200px;"><b>' . get_lang('HotspotZones') . '</b><dl>'; if (!empty($answers_hotspot)) { ksort($answers_hotspot); foreach ($answers_hotspot as $key => $value) { $answer_list .= '<dt>' . $key . '.- ' . $value . '</dt><br />'; } } $answer_list .= '</dl></div>'; if ($answerType == HOT_SPOT_DELINEATION) { $answer_list = ''; $swf_file = 'hotspot_delineation_user'; $swf_height = 405; } else { $swf_file = 'hotspot_user'; $swf_height = 436; } if (!$only_questions) { if ($show_title) { $html .= TestCategory::getCategoryNamesForQuestion($objQuestionTmp->id); $html .= '<div class="question_title">' . $current_item . '. ' . $questionName . '</div>'; $html .= $questionDescription; } else { $html .= '<div class="media">'; $html .= '<div class="pull-left">'; $html .= '<div class="media-object">'; $html .= Display::div($current_item . '. ', array('class' => 'question_no_title')); $html .= '</div>'; $html .= '</div>'; $html .= '<div class="media-body">'; if (!empty($questionDescription)) { $html .= Display::div($questionDescription, array('class' => 'question_description')); } $html .= '</div>'; $html .= '</div>'; } //@todo I need to the get the feedback type $html .= '<input type="hidden" name="hidden_hotspot_id" value="' . $questionId . '" />'; $html .= '<table class="exercise_questions"> <tr> <td valign="top" colspan="2">'; $html .= '</td></tr>'; } $canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1'); $s .= ' <script type="text/javascript" src="../plugin/hotspot/JavaScriptFlashGateway.js"></script> <script src="../plugin/hotspot/hotspot.js" type="text/javascript" ></script> <script type="text/javascript"> <!-- // Globals // Major version of Flash required var requiredMajorVersion = 7; // Minor version of Flash required var requiredMinorVersion = 0; // Minor version of Flash required var requiredRevision = 0; // the version of javascript supported var jsVersion = 1.0; // --> </script> <script language="VBScript" type="text/vbscript"> <!-- // Visual basic helper required to detect Flash Player ActiveX control version information Function VBGetSwfVer(i) on error resume next Dim swControl, swVersion swVersion = 0 set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i)) if (IsObject(swControl)) then swVersion = swControl.GetVariable("$version") end if VBGetSwfVer = swVersion End Function // --> </script> <script language="JavaScript1.1" type="text/javascript"> <!-- // Detect Client Browser type var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false; var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false; jsVersion = 1.1; // JavaScript helper required to detect Flash Player PlugIn version information function JSGetSwfVer(i) { // NS/Opera version >= 3 check for Flash plugin in plugin array if (navigator.plugins != null && navigator.plugins.length > 0) { if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) { var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : ""; var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description; descArray = flashDescription.split(" "); tempArrayMajor = descArray[2].split("."); versionMajor = tempArrayMajor[0]; versionMinor = tempArrayMajor[1]; if ( descArray[3] != "" ) { tempArrayMinor = descArray[3].split("r"); } else { tempArrayMinor = descArray[4].split("r"); } versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0; flashVer = versionMajor + "." + versionMinor + "." + versionRevision; } else { flashVer = -1; } } // MSN/WebTV 2.6 supports Flash 4 else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4; // WebTV 2.5 supports Flash 3 else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3; // older WebTV supports Flash 2 else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2; // Can\'t detect in all other cases else { flashVer = -1; } return flashVer; } // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) { reqVer = parseFloat(reqMajorVer + "." + reqRevision); // loop backwards through the versions until we find the newest version for (i=25;i>0;i--) { if (isIE && isWin && !isOpera) { versionStr = VBGetSwfVer(i); } else { versionStr = JSGetSwfVer(i); } if (versionStr == -1 ) { return false; } else if (versionStr != 0) { if(isIE && isWin && !isOpera) { tempArray = versionStr.split(" "); tempString = tempArray[1]; versionArray = tempString .split(","); } else { versionArray = versionStr.split("."); } versionMajor = versionArray[0]; versionMinor = versionArray[1]; versionRevision = versionArray[2]; versionString = versionMajor + "." + versionRevision; // 7.0r24 == 7.24 versionNum = parseFloat(versionString); // is the major.revision >= requested major.revision AND the minor version >= requested minor if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) { return true; } else { return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false ); } } } } // --> </script>'; $s .= '<tr><td valign="top" colspan="2" width="520"><table><tr><td width="520"> <script> // Version check based upon the values entered above in "Globals" var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision); // Check to see if the version meets the requirements for playback if (hasReqestedVersion) { // if we\'ve detected an acceptable version var oeTags = \'<object type="application/x-shockwave-flash" data="../plugin/hotspot/' . $swf_file . '.swf?modifyAnswers=' . $questionId . '&canClick:' . $canClick . '" width="600" height="' . $swf_height . '">\' + \'<param name="wmode" value="transparent">\' + \'<param name="movie" value="../plugin/hotspot/' . $swf_file . '.swf?modifyAnswers=' . $questionId . '&canClick:' . $canClick . '" />\' + \'<\\/object>\'; document.write(oeTags); // embed the Flash Content SWF when all tests are passed } else { // flash is too old or we can\'t detect the plugin var alternateContent = "Error<br \\/>" + "Hotspots requires Macromedia Flash 7.<br \\/>" + "<a href=\\"http://www.macromedia.com/go/getflash/\\">Get Flash<\\/a>"; document.write(alternateContent); // insert non-flash content } </script> </td> <td valign="top" align="left">' . $answer_list . '</td></tr> </table> </td></tr>'; $html .= $s; $html .= '</table>'; return $html; } return $nbrAnswers; }
/** * Get registered users inside current course * @param int $attendance_id attendance id for showing attendance result field (optional) * @param int $groupId * @return array users data */ public function get_users_rel_course($attendance_id = 0, $groupId = null) { $current_session_id = api_get_session_id(); $current_course_id = api_get_course_id(); $currentCourseIntId = api_get_course_int_id(); $studentInGroup = array(); if (!empty($current_session_id)) { $a_course_users = CourseManager::get_user_list_from_course_code($current_course_id, $current_session_id, '', 'lastname'); } else { $a_course_users = CourseManager::get_user_list_from_course_code($current_course_id, 0, '', 'lastname'); if (!empty($groupId)) { $students = GroupManager::getStudents($groupId); if (!empty($students)) { foreach ($students as $student) { $studentInGroup[$student['user_id']] = true; } } } } // get registered users inside current course $a_users = array(); foreach ($a_course_users as $key => $user_data) { $value = array(); $uid = $user_data['user_id']; $userInfo = api_get_user_info($uid); $status = $user_data['status']; if (!empty($groupId)) { if (!isset($studentInGroup[$uid])) { continue; } } $user_status_in_session = null; $user_status_in_course = null; if (api_get_session_id()) { $user_status_in_session = SessionManager::get_user_status_in_course_session($uid, $currentCourseIntId, $current_session_id); } else { $user_status_in_course = CourseManager::get_user_in_course_status($uid, $current_course_id); } // Not taking into account DRH or COURSEMANAGER if ($uid <= 1 || $status == DRH || $user_status_in_course == COURSEMANAGER || $user_status_in_session == 2) { continue; } if (!empty($attendance_id)) { $user_faults = $this->get_faults_of_user($uid, $attendance_id, $groupId); $value['attendance_result'] = $user_faults['faults'] . '/' . $user_faults['total'] . ' (' . $user_faults['faults_porcent'] . '%)'; $value['result_color_bar'] = $user_faults['color_bar']; } $photo = Display::img($userInfo['avatar_small'], $userInfo['complete_name'], [], false); $value['photo'] = $photo; $value['firstname'] = $user_data['firstname']; $value['lastname'] = $user_data['lastname']; $value['username'] = $user_data['username']; $value['user_id'] = $uid; //Sending only 5 items in the array instead of 60 $a_users[$key] = $value; } return $a_users; }
$result = msort($result, 'skills_acquired', 'asc'); $skills_in_course = array(); if (!empty($result)) { foreach ($result as &$item) { $user_info = api_get_user_info($item['user_id']); $personal_course_list = UserManager::get_personal_session_course_list($item['user_id']); $count_skill_by_course = array(); foreach ($personal_course_list as $course_item) { if (!isset($skills_in_course[$course_item['code']])) { $count_skill_by_course[$course_item['code']] = $skill->get_count_skills_by_course($course_item['code']); $skills_in_course[$course_item['code']] = $count_skill_by_course[$course_item['code']]; } else { $count_skill_by_course[$course_item['code']] = $skills_in_course[$course_item['code']]; } } $item['photo'] = Display::img($user_info['avatar_small']); $item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0; } } break; case 'get_work_teacher': $columns = array('type', 'title', 'sent_date', 'expires_on', 'amount', 'actions'); $result = getWorkListTeacher($start, $limit, $sidx, $sord, $whereCondition); break; case 'get_work_student': $columns = array('type', 'title', 'expires_on', 'feedback', 'last_upload', 'others'); $result = getWorkListStudent($start, $limit, $sidx, $sord, $whereCondition); break; case 'get_work_user_list_all': if (isset($_GET['type']) && $_GET['type'] == 'simple') { $columns = array('firstname', 'lastname', 'title', 'qualification', 'sent_date', 'qualificator_id', 'correction', 'actions');
if (isset($user['legal_agreement'])) { if ($user['legal_agreement'] == 1) { $user['legal_agreement'] = get_lang('Yes'); } else { $user['legal_agreement'] = get_lang('No'); } } $extra_fields = UserManager::get_extra_user_data($user['user_id'], false, false, false, true); if (!empty($extra_fields)) { foreach ($extra_fields as $key => $extra_value) { $user[$key] = $extra_value; } } if ($_GET['type'] == 'pdf') { $user_info = api_get_user_info($user['user_id']); $user_image = Display::img($user_info['avatar'], null, array('width' => $user_image_pdf_size . 'px')); if ($is_western_name_order) { $user_pdf = array($counter, $user_image, $user['official_code'], $user['firstname'] . ', ' . $user['lastname'], $user['email'], $user['phone']); } else { $user_pdf = array($counter, $user_image, $user['official_code'], $user['lastname'] . ', ' . $user['firstname'], $user['email'], $user['phone']); } $a_users[] = $user_pdf; } else { $a_users[] = $user; } $data[] = $user; $counter++; } } switch ($_GET['type']) { case 'csv':
/** * display message box in the inbox * @param int the message id * @param string inbox or outbox strings are available * @todo replace numbers with letters in the $row array pff... * @return string html with the message content */ public static function show_message_box($message_id, $source = 'inbox') { $table_message = Database::get_main_table(TABLE_MESSAGE); $message_id = intval($message_id); if ($source == 'outbox') { if (isset($message_id) && is_numeric($message_id)) { $query = "SELECT * FROM {$table_message} WHERE user_sender_id=" . api_get_user_id() . " AND id=" . $message_id . " AND msg_status=4;"; $result = Database::query($query); $path = 'outbox.php'; } } else { if (is_numeric($message_id) && !empty($message_id)) { $query = "UPDATE {$table_message} SET msg_status = '" . MESSAGE_STATUS_NEW . "' WHERE user_receiver_id=" . api_get_user_id() . " AND id='" . $message_id . "';"; $result = Database::query($query); $query = "SELECT * FROM {$table_message} WHERE msg_status<>4 AND user_receiver_id=" . api_get_user_id() . " AND id='" . $message_id . "';"; $result = Database::query($query); } $path = 'inbox.php'; } $row = Database::fetch_array($result, 'ASSOC'); $user_sender_id = $row['user_sender_id']; // get file attachments by message id $files_attachments = self::get_links_message_attachment_files($message_id, $source); $user_con = self::users_connected_by_id(); $title = Security::remove_XSS($row['title'], STUDENT, true); $content = Security::remove_XSS($row['content'], STUDENT, true); $userInfoSender = api_get_user_info($user_sender_id); $name = $userInfoSender['complete_name']; $user_image = UserManager::get_picture_user($row['user_sender_id'], $userInfoSender['picture_uri'], 80); $user_image = Display::img($user_image['file'], $name, array('title' => $name)); $message_content = Display::page_subheader(str_replace("\\", "", $title)); if (api_get_setting('allow_social_tool') == 'true') { $message_content .= $user_image . ' '; } if (api_get_setting('allow_social_tool') == 'true') { $userInfo = api_get_user_info($row['user_sender_id']); if ($source == 'outbox') { $message_content .= get_lang('From') . ': <a href="' . $userInfoSender['profile_url'] . '">' . $name . '</a> ' . api_strtolower(get_lang('To')) . ' <b>' . $userInfo['complete_name'] . '</b>'; } else { $message_content .= get_lang('From') . ' <a href="' . $userInfoSender['profile_url'] . '">' . $name . '</a> ' . api_strtolower(get_lang('To')) . ' <b>' . get_lang('Me') . '</b>'; } } else { $userInfo = api_get_user_info($row['user_receiver_id']); if ($source == 'outbox') { $message_content .= get_lang('From') . ': ' . $name . '</b> ' . api_strtolower(get_lang('To')) . ' <b>' . $userInfo['complete_name'] . '</b>'; } else { $message_content .= get_lang('From') . ': ' . $name . '</b> ' . api_strtolower(get_lang('To')) . ' <b>' . get_lang('Me') . '</b>'; } } $message_content .= ' ' . get_lang('Date') . ': ' . api_get_local_time($row['send_date']); $message_content .= '<br />'; $message_content .= '<br />'; $message_content .= str_replace("\\", "", $content); $message_content .= '<br />'; $message_content .= '<div id="message-attach">' . (!empty($files_attachments) ? implode('<br />', $files_attachments) : '') . '</div> '; $social_link = ''; if (isset($_GET['f']) && $_GET['f'] == 'social') { $social_link = 'f=social'; } if ($source == 'outbox') { $message_content .= '<a href="outbox.php?' . $social_link . '">' . Display::return_icon('back.png', get_lang('ReturnToOutbox')) . '</a>  '; } else { $message_content .= '<a href="inbox.php?' . $social_link . '">' . Display::return_icon('back.png', get_lang('ReturnToInbox')) . '</a>  '; $message_content .= '<a href="new_message.php?re_id=' . $message_id . '&' . $social_link . '">' . Display::return_icon('message_reply.png', get_lang('ReplyToMessage')) . '</a>  '; } $message_content .= '<a href="inbox.php?action=deleteone&id=' . $message_id . '&' . $social_link . '" >' . Display::return_icon('delete.png', get_lang('DeleteMessage')) . '</a> '; return $message_content; }