123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- <?php
- $this_section = SECTION_COURSES;
- api_protect_course_script();
- $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $isStudentView = isset($_REQUEST['isStudentView']) ? (int)$_REQUEST['isStudentView'] : null;
- $learnpath_id = (int)$_REQUEST['lp_id'];
- $submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
- $_course = api_get_course_info();
- if ((!$is_allowed_to_edit) || ($isStudentView)) {
- error_log('New LP - User not authorized in lp_admin_view.php');
- header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
- }
- $course_id = api_get_course_int_id();
- $sql_query = "SELECT * FROM $tbl_lp WHERE c_id = $course_id AND id = $learnpath_id";
- $result = Database::query($sql_query);
- $therow = Database::fetch_array($result);
- if (isset($_SESSION['gradebook'])) {
- $gradebook = $_SESSION['gradebook'];
- }
- if (!empty($gradebook) && $gradebook == 'view') {
- $interbreadcrumb[] = array (
- 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
- 'name' => get_lang('ToolGradebook')
- );
- }
- $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
- $interbreadcrumb[] = array(
- 'url' => api_get_self()."?action=build&lp_id=$learnpath_id",
- "name" => stripslashes("{$therow['name']}"),
- );
- $interbreadcrumb[] = array(
- 'url' => api_get_self()."?action=add_item&type=step&lp_id=$learnpath_id&".api_get_cidreq(),
- 'name' => get_lang('NewStep'),
- );
- if (isset($_REQUEST['updateaudio'])) {
- $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('UpdateAllAudioFragments'));
- } else {
- $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('BasicOverview'));
- }
- $show_learn_path = true;
- $lp_theme_css = $_SESSION['oLP']->get_theme();
- if (isset($_POST['save_audio'])) {
-
- $_SESSION['oLP']->set_modified_on();
-
- foreach ($_POST as $key => $value) {
- if (substr($key, 0, 9) == 'removemp3') {
- $lp_items_to_remove_audio[] = str_ireplace('removemp3', '', $key);
-
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $in = implode(',', $lp_items_to_remove_audio);
- }
- }
- if (count($lp_items_to_remove_audio)>0) {
- $sql = "UPDATE $tbl_lp_item SET audio = ''
- WHERE c_id = $course_id AND id IN (".$in.")";
- $result = Database::query($sql);
- }
-
- foreach ($_FILES as $key => $value) {
- if (substr($key, 0, 7) == 'mp3file' && !empty($_FILES[$key]['tmp_name'])) {
-
- $lp_item_id = str_ireplace('mp3file', '', $key);
-
- DocumentManager::createDefaultAudioFolder($_course);
-
- $file_name = $_FILES[$key]['name'];
- $file_name = stripslashes($file_name);
-
- $file_name = add_ext_on_mime($file_name, $_FILES[$key]['type']);
- $clean_name = api_replace_dangerous_char($file_name);
-
- $clean_name = disable_dangerous_file($clean_name);
- $check_file_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/audio/'.$clean_name;
-
- if (file_exists($check_file_path)) {
- $filename_components = explode('.', $clean_name);
-
- $file_extension = $filename_components[count($filename_components) - 1];
-
- $filename_components[count($filename_components) - 1] = time();
-
- $clean_name = implode($filename_components) .'.'.$file_extension;
-
- $_FILES[$key]['name'] = $clean_name;
- }
-
- $file_path = handle_uploaded_document(
- $_course,
- $_FILES[$key],
- api_get_path(SYS_COURSE_PATH).$_course['path'].'/document',
- '/audio',
- api_get_user_id(),
- '',
- '',
- '',
- '',
- false
- );
-
- $file_components = explode('/', $file_path);
- $file = $file_components[count($file_components) - 1];
-
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '".Database::escape_string($file)."'
- WHERE c_id = $course_id AND id = '".Database::escape_string($lp_item_id)."'";
- Database::query($sql_insert_audio);
- }
- }
-
- $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
- header('Location: '.$url);
- exit;
- }
- Display::display_header(null, 'Path');
- $suredel = trim(get_lang('AreYouSureToDeleteJS'));
- ?>
- <script>
- var newOrderData= "";
- $(function() {
- <?php
- if (!isset($_REQUEST['updateaudio'])) {
- ?>
- $("#lp_item_list").sortable({
- items: "li",
- handle: ".moved",
- cursor: "move",
- placeholder: "ui-state-highlight"
- });
- $("#listSubmit").click(function () {
-
- $(this).attr("disabled","disabled");
-
- newOrderData= "";
-
- var parentId= 0;
-
- $("#lp_item_list").children().each(function () {
-
- if ($(this).attr("id")) {
-
- newOrderData= newOrderData + $(this).attr("id") + "|" + "0" + "^";
-
- if ($(this).is(".li_container")) {
-
- processChildren($(this).attr("id"));
- }
- }
- });
-
-
- var order = "new_order="+ newOrderData + "&a=update_lp_item_order";
- $.post("<?php echo api_get_path(WEB_AJAX_PATH)?>lp.ajax.php", order, function(reponse){
- $("#message").html(reponse);
- });
- setTimeout(function() {
- $("#message").html('');
- }, 3000);
- return false;
- });
- <?php } ?>
- function processChildren(parentId) {
-
- var ulParentID= "UL_" + parentId;
- $("#" + ulParentID).children().each(function () {
-
- if ($(this).attr("id")) {
-
- newOrderData= newOrderData + $(this).attr("id") + "|" + parentId + "^";
-
- if ($(this).is(".container")) {
-
- processChildren($(this).attr("id"));
- }
- }
- });
- }
- });
- function stripslashes(str) {
- str=str.replace(/\\'/g,'\'');
- str=str.replace(/\\"/g,'"');
- str=str.replace(/\\\\/g,'\\');
- str=str.replace(/\\0/g,'\0');
- return str;
- }
- function confirmation(name) {
- name=stripslashes(name);
- if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
- return true;
- } else {
- return false;
- }
- }
- </script>
- <?php
- echo $_SESSION['oLP']->build_action_menu();
- echo '<div class="row">';
- echo '<div class="col-md-4">';
- echo $_SESSION['oLP']->return_new_tree(null, true);
- echo '</div>';
- echo '<div class="col-md-8">';
- switch ($_GET['action']) {
- case 'edit_item':
- if (isset($is_success) && $is_success === true) {
- Display::display_confirmation_message(get_lang('LearnpathItemEdited'));
- } else {
- echo $_SESSION['oLP']->display_edit_item($_GET['id']);
- }
- break;
- case 'delete_item':
- if (isset($is_success) && $is_success === true) {
- Display::display_confirmation_message(get_lang('LearnpathItemDeleted'));
- }
- break;
- }
- if (!empty($_GET['updateaudio'])) {
-
- echo $_SESSION['oLP']->overview();
- }
- echo '</div>';
- echo '</div>';
- Display::display_footer();
|