Improving LP UI see #5593

skala
Julio Montoya 12 years ago
parent 39abec47d7
commit f2b1a31566
  1. 11
      main/newscorm/learnpath.class.php
  2. 2
      main/newscorm/lp_add_item.php
  3. 201
      main/newscorm/lp_admin_view.php
  4. 26
      main/newscorm/lp_controller.php
  5. 22
      main/newscorm/lp_edit.php
  6. 26
      main/newscorm/lp_view_item.php

@ -5038,8 +5038,8 @@ class learnpath {
//Link for the documents
if ($arrLP[$i]['item_type'] == 'document') {
$url = api_get_self() . '?'.api_get_cidreq().'&action=view_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id;
$title_cut = Display::url($title_cut, $url);
$url = api_get_self() . '?'.api_get_cidreq().'&action=view_item&mode=preview_document&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id;
$title_cut = Display::url($title_cut, $url, array('class' => 'ajax'));
}
if (($i % 2) == 0) {
@ -5544,7 +5544,7 @@ class learnpath {
* @param string $msg
* @return string
*/
public function display_item($item_id, $iframe = true, $msg = '') {
public function display_item($item_id, $msg = null, $show_actions = true) {
$course_id = api_get_course_int_id();
$return = '';
if (is_numeric($item_id)) {
@ -5561,7 +5561,9 @@ class learnpath {
$_SESSION['parent_item_id'] = $row['parent_item_id'];
}
if ($show_actions) {
$return .= $this->display_manipulate($item_id, $row['item_type']);
}
$return .= '<div style="padding:10px;">';
if ($msg != '')
@ -5755,9 +5757,6 @@ class learnpath {
$res_doc = Database::query($sql_doc);
$row_doc = Database :: fetch_array($res_doc);
//if ($show_title)
//$return .= '<p class="lp_title">' . $row_doc['title'] . ($edit_link ? ' [ <a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $_GET['file'] . '&amp;edit=true&amp;lp_id=' . $_GET['lp_id'] . '">Edit this document</a> ]' : '') . '</p>';
// TODO: Add a path filter.
if ($iframe) {
$return .= '<iframe id="learnpath_preview_frame" frameborder="0" height="400" width="100%" scrolling="auto" src="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document' . str_replace('%2F', '/', urlencode($row_doc['path'])) . '?' . api_get_cidreq() . '"></iframe>';

@ -285,7 +285,7 @@ if (isset($new_item_id) && is_numeric($new_item_id)) {
break;
case TOOL_DOCUMENT:
Display::display_confirmation_message(get_lang('NewDocumentCreated'));
echo $_SESSION['oLP']->display_item($new_item_id, true);
echo $_SESSION['oLP']->display_item($new_item_id);
break;
case TOOL_FORUM:
echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);

@ -60,12 +60,6 @@ $sql_query = "SELECT * FROM $tbl_lp WHERE c_id = $course_id AND id = $learnpath_
$result = Database::query($sql_query);
$therow = Database::fetch_array($result);
//$admin_output = '';
/*
Course admin section
- all the functions not available for students - always available in this case (page only shown to admin)
*/
/* SHOWING THE ADMIN TOOLS */
if (isset($_SESSION['gradebook'])) {
@ -93,6 +87,107 @@ if (isset($_REQUEST['updateaudio'])) {
$show_learn_path = true;
$lp_theme_css = $_SESSION['oLP']->get_theme();
/* DISPLAY SECTION */
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;
}
// POST action handling (uploading mp3, deleting mp3)
if (isset($_POST['save_audio'])) {
//Updating the lp.modified_on
$_SESSION['oLP']->set_modified_on();
// Deleting the audio fragments.
foreach ($_POST as $key => $value) {
if (substr($key, 0, 9) == 'removemp3') {
$lp_items_to_remove_audio[] = str_ireplace('removemp3', '', $key);
// Removing the audio from the learning path item.
$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);
}
// Uploading the audio files.
foreach ($_FILES as $key => $value) {
if (substr($key, 0, 7) == 'mp3file' AND !empty($_FILES[$key]['tmp_name'])) {
// The id of the learning path item.
$lp_item_id = str_ireplace('mp3file', '', $key);
// Create the audio folder if it does not exist yet.
global $_course;
$filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
if (!is_dir($filepath.'audio')) {
mkdir($filepath.'audio', api_get_permissions_for_new_directories());
$audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
}
// Check if file already exits into document/audio/
$file_name = $_FILES[$key]['name'];
$file_name = stripslashes($file_name);
// Add extension to files without one (if possible).
$file_name = add_ext_on_mime($file_name, $_FILES[$key]['type']);
$clean_name = replace_dangerous_char($file_name);
// No "dangerous" files.
$clean_name = disable_dangerous_file($clean_name);
$check_file_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/audio/'.$clean_name;
// If the file exists we generate a new name.
if (file_exists($check_file_path)) {
$filename_components = explode('.', $clean_name);
// Gettting the extension of the file.
$file_extension = $filename_components[count($filename_components) - 1];
// Adding something random to prevent overwriting.
$filename_components[count($filename_components) - 1] = time();
// Reconstructing the new filename.
$clean_name = implode($filename_components) .'.'.$file_extension;
// Using the new name in the $_FILES superglobal.
$_FILES[$key]['name'] = $clean_name;
}
// Upload the file in the documents tool.
include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
$file_path = handle_uploaded_document($_course, $_FILES[$key], api_get_path(SYS_COURSE_PATH).$_course['path'].'/document','/audio', api_get_user_id(), '', '', '', '', false);
// Getting the filename only.
$file_components = explode('/', $file_path);
$file = $file_components[count($file_components) - 1];
// Store the mp3 file in the lp_item table.
$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);
}
}
//Display::display_confirmation_message(get_lang('ItemUpdated'));
$url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
header('Location: '.$url);
exit;
}
Display::display_header(null, 'Path');
$suredel = trim(get_lang('AreYouSureToDelete'));
@ -206,100 +301,6 @@ function confirmation(name) {
</script>
<?php
/* DISPLAY SECTION */
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;
}
// POST action handling (uploading mp3, deleting mp3)
if (isset($_POST['save_audio'])) {
//Updating the lp.modified_on
$_SESSION['oLP']->set_modified_on();
// Deleting the audio fragments.
foreach ($_POST as $key => $value) {
if (substr($key, 0, 9) == 'removemp3') {
$lp_items_to_remove_audio[] = str_ireplace('removemp3', '', $key);
// Removing the audio from the learning path item.
$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);
}
// Uploading the audio files.
foreach ($_FILES as $key => $value) {
if (substr($key, 0, 7) == 'mp3file' AND !empty($_FILES[$key]['tmp_name'])) {
// The id of the learning path item.
$lp_item_id = str_ireplace('mp3file', '', $key);
// Create the audio folder if it does not exist yet.
global $_course;
$filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
if (!is_dir($filepath.'audio')) {
mkdir($filepath.'audio', api_get_permissions_for_new_directories());
$audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
}
// Check if file already exits into document/audio/
$file_name = $_FILES[$key]['name'];
$file_name = stripslashes($file_name);
// Add extension to files without one (if possible).
$file_name = add_ext_on_mime($file_name, $_FILES[$key]['type']);
$clean_name = replace_dangerous_char($file_name);
// No "dangerous" files.
$clean_name = disable_dangerous_file($clean_name);
$check_file_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/audio/'.$clean_name;
// If the file exists we generate a new name.
if (file_exists($check_file_path)) {
$filename_components = explode('.', $clean_name);
// Gettting the extension of the file.
$file_extension = $filename_components[count($filename_components) - 1];
// Adding something random to prevent overwriting.
$filename_components[count($filename_components) - 1] = time();
// Reconstructing the new filename.
$clean_name = implode($filename_components) .'.'.$file_extension;
// Using the new name in the $_FILES superglobal.
$_FILES[$key]['name'] = $clean_name;
}
// Upload the file in the documents tool.
include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
$file_path = handle_uploaded_document($_course, $_FILES[$key], api_get_path(SYS_COURSE_PATH).$_course['path'].'/document','/audio', api_get_user_id(), '', '', '', '', false);
// Getting the filename only.
$file_components = explode('/', $file_path);
$file = $file_components[count($file_components) - 1];
// Store the mp3 file in the lp_item table.
$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);
}
}
Display::display_confirmation_message(get_lang('ItemUpdated'));
}
echo $_SESSION['oLP']->build_action_menu();
echo $_SESSION['oLP']->overview();

@ -255,8 +255,9 @@ switch ($action) {
// For all other item types than documents, load the item using the item type and path rather than its ID.
$new_item_id = $_SESSION['oLP']->add_item($_POST['parent'], $_POST['previous'], $_POST['type'], $_POST['path'], $_POST['title'], $_POST['description'], $_POST['prerequisites'], $_POST['maxTimeAllowed']);
}
// Display.
require 'lp_add_item.php';
$url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
header('Location: '.$url);
exit;
}
} else {
require 'lp_add_item.php';
@ -415,7 +416,13 @@ switch ($action) {
$_SESSION['oLP']->edit_document($_course);
}
$is_success = true;
$url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
header('Location: '.$url);
exit;
}
if (isset($_GET['view']) && $_GET['view'] == 'build') {
require 'lp_edit_item.php';
} else {
@ -429,7 +436,6 @@ switch ($action) {
api_not_allowed(true);
}
if ($debug > 0) error_log('New LP - edit item prereq action triggered', 0);
if (!$lp_found) { error_log('New LP - No learnpath given for edit item prereq', 0); require 'lp_list.php'; }
else {
if (isset($_POST['submit_button'])) {
@ -441,7 +447,10 @@ switch ($action) {
$is_success = true;
}
}
require 'lp_edit_item_prereq.php';
//require 'lp_edit_item_prereq.php';
$url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
header('Location: '.$url);
exit;
}
break;
@ -460,6 +469,8 @@ switch ($action) {
$_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description']);
$is_success = true;
$url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
header('Location: '.$url);
}
if (isset($_GET['view']) && $_GET['view'] == 'build') {
require 'lp_move_item.php';
@ -615,7 +626,6 @@ switch ($action) {
require 'lp_edit.php';
}
break;
case 'update_lp':
if (!$is_allowed_to_edit) {
api_not_allowed(true);
@ -650,7 +660,6 @@ switch ($action) {
$_SESSION['oLP']->set_prerequisite($_REQUEST['prerequisites']);
$_SESSION['oLP']->set_use_max_score($_REQUEST['use_max_score']);
if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
$publicated_on = $_REQUEST['publicated_on'];
$publicated_on = $publicated_on['Y'].'-'.$publicated_on['F'].'-'.$publicated_on['d'].' '.$publicated_on['H'].':'.$publicated_on['i'].':00';
@ -694,10 +703,11 @@ switch ($action) {
}
}
}
require 'lp_build.php';
$url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
header('Location: '.$url);
exit;
}
break;
case 'add_sub_item': // Add an item inside a chapter.
if (!$is_allowed_to_edit) {
api_not_allowed(true);

@ -16,7 +16,6 @@ $this_section = SECTION_COURSES;
event_access_tool(TOOL_LEARNPATH);
api_protect_course_script();
//if (! $is_allowed_in_course) api_not_allowed();
if (isset($_SESSION['gradebook'])) {
$gradebook = $_SESSION['gradebook'];
@ -32,7 +31,7 @@ $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => g
$interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=".$_SESSION['oLP']->get_id(), 'name' => $_SESSION['oLP']->get_name());
//$interbreadcrumb[] = array('url' => api_get_self()."?action=add_item&type=step&lp_id=$learnpath_id", 'name' => get_lang('NewStep'));
$htmlHeadXtra[] = '<script type="text/javascript">
$htmlHeadXtra[] = '<script>
function activate_start_date() {
if(document.getElementById(\'start_date_div\').style.display == \'none\') {
document.getElementById(\'start_date_div\').style.display = \'block\';
@ -56,26 +55,7 @@ Display::display_header(get_lang('CourseSettings'), 'Path');
echo $_SESSION['oLP']->build_action_menu();
// Action links
//echo '<div class="actions">';
$gradebook = isset($_GET['gradebook']) ? Security::remove_XSS($_GET['gradebook']) : null;
//echo '<a href="lp_controller.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;gradebook='.$gradebook.'&amp;action=build&amp;lp_id=' . Security::remove_XSS($_GET['lp_id']) . '" title="'.get_lang('Build').'">'.Display::return_icon('build_learnpath.png', get_lang('Build'),'',ICON_SIZE_MEDIUM).'</a>';
//echo '<a href="lp_controller.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;gradebook='.$gradebook.'&amp;action=admin_view&amp;lp_id=' . Security::remove_XSS($_GET['lp_id']) . '" title="'.get_lang('BasicOverview').'">'.Display::return_icon('move_learnpath.png', get_lang('BasicOverview'),'',ICON_SIZE_MEDIUM).'</a>';
//echo '<a href="lp_controller.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;gradebook='.$gradebook.'&amp;action=view&lp_id='.Security::remove_XSS($_GET['lp_id']).'">'.Display::return_icon('view_remove.png', get_lang('Display'),'',ICON_SIZE_MEDIUM).'</a>';
//echo ' '.Display::return_icon('i.gif');
/*echo '<a href="lp_controller.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;gradebook='.$gradebook.'&amp;action=add_item&amp;type=step&amp;lp_id=' . Security::remove_XSS($_GET['lp_id']) . '" title="'.get_lang('NewStep').'">
'.Display::return_icon('add.png', get_lang('NewStep'),'',ICON_SIZE_MEDIUM).'</a>';*/
/*echo '<a href="lp_controller.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;gradebook='.$gradebook.'&amp;action=add_item&amp;type=chapter&amp;lp_id=' . Security::remove_XSS($_GET['lp_id']) . '" title="'.get_lang('NewChapter').'">
'.Display::return_icon('add_learnpath_section.png', get_lang('NewChapter'),'',ICON_SIZE_MEDIUM).'</a>';*/
//echo '<a href="lp_controller.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;gradebook='.$gradebook.'&amp;action=admin_view&amp;lp_id='.Security::remove_XSS($_GET['lp_id']).'&amp;updateaudio=true">'.Display::return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'',ICON_SIZE_MEDIUM).'</a>';
//echo Display::url(Display::return_icon('settings_na.png', get_lang('CourseSettings'),'',ICON_SIZE_MEDIUM), '#');
//echo '<a href="../newscorm/lp_controller.php?cidReq='.$_course['sysCode'].'">'.Display::return_icon('scorms_na.png',get_lang('ReturnToLearningPaths'),'',ICON_SIZE_MEDIUM).'</a>';
//echo '</div>';
$defaults=array();
$form = new FormValidator('form1', 'post', 'lp_controller.php');

@ -53,6 +53,8 @@ if (isset($_GET['lp_item_id'])) {
}
}
$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : 'fullpage';
/* INIT SECTION */
$_SESSION['whereami'] = 'lp/build';
@ -61,9 +63,6 @@ if (isset($_SESSION['oLP']) && isset($_GET['id'])) {
}
$this_section = SECTION_COURSES;
/* Libraries */
$language_file = "learnpath";
/* Header and action code */
@ -79,7 +78,7 @@ $learnpath_id = (int) $_REQUEST['lp_id'];
// Using the resource linker as a tool for adding resources to the learning path.
if ($action == 'add' && $type == 'learnpathitem') {
$htmlHeadXtra[] = "<script language='JavaScript' type='text/javascript'> window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\"; </script>";
$htmlHeadXtra[] = "<script> window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\"; </script>";
}
if ((!$is_allowed_to_edit) || ($isStudentView)) {
error_log('New LP - User not authorized in lp_view_item.php');
@ -116,12 +115,13 @@ if (isset($_SESSION['oLP']) && is_object($_SESSION['oLP'])) {
$lp_theme_css = $_SESSION['oLP']->get_theme();
}
if ($mode == 'fullpage') {
Display::display_header(get_lang('Item'),'Path');
//api_display_tool_title($therow['name']);
}
$suredel = trim(get_lang('AreYouSureToDelete'));
?>
<script type='text/javascript'>
<script>
/* <![CDATA[ */
function stripslashes(str) {
@ -141,15 +141,25 @@ function confirmation(name) {
}
</script>
<?php
$id = (isset($new_item_id)) ? $new_item_id : $_GET['id'];
if (is_object($_SESSION['oLP'])) {
switch ($mode) {
case 'fullpage':
echo $_SESSION['oLP']->build_action_menu();
echo '<div class="row-fluid">';
echo '<div class="span3">';
echo $_SESSION['oLP']->return_new_tree();
echo '</div>';
echo '<div class="span9">';
echo $_SESSION['oLP']->display_item((isset($new_item_id)) ? $new_item_id : $_GET['id']);
echo $_SESSION['oLP']->display_item($id);
echo '</div>';
echo '</div>';
}
Display::display_footer();
break;
case 'preview_document':
echo $_SESSION['oLP']->display_item($id, null, false);
break;
}
}

Loading…
Cancel
Save