Allow edit parent and position of LP chapter during edition see BT#14447

pull/2573/head
Julio 8 years ago
parent 400d30f9fd
commit a8b8f36393
  1. 77
      main/lp/learnpath.class.php
  2. 25
      main/lp/lp_add_item.php
  3. 2
      main/lp/lp_admin_view.php
  4. 6
      main/lp/lp_edit.php
  5. 32
      main/lp/lp_edit_item.php
  6. 28
      main/lp/lp_move_item.php

@ -1382,8 +1382,8 @@ class learnpath
}
}
$same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
$same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
$same_parent = $row_select['parent_item_id'] == $parent ? true : false;
$same_previous = $row_select['previous_item_id'] == $previous ? true : false;
// TODO: htmlspecialchars to be checked for encoding related problems.
if ($same_parent && $same_previous) {
@ -7360,9 +7360,11 @@ class learnpath
$row
);
} else {
$return .= $this->display_item_small_form(
$return .= $this->display_item_form(
$row['item_type'],
get_lang('EditCurrentChapter').' :',
'edit_item',
$item_id,
$row
);
}
@ -8448,25 +8450,22 @@ class learnpath
global $charset;
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$item_title = '';
$item_description = '';
$item_path_fck = '';
if ($id != 0 && is_array($extra_info)) {
$item_title = $extra_info['title'];
$item_description = $extra_info['description'];
$item_path = api_get_path(WEB_COURSE_PATH).$_course['path'].'/scorm/'.$this->path.'/'.stripslashes($extra_info['path']);
$item_path_fck = '/scorm/'.$this->path.'/'.stripslashes($extra_info['path']);
} else {
$item_title = '';
$item_description = '';
$item_path_fck = '';
}
$parent = 0;
if ($id != 0 && is_array($extra_info)) {
$parent = $extra_info['parent_item_id'];
} else {
$parent = 0;
}
$id = intval($id);
$id = (int) $id;
$sql = "SELECT * FROM $tbl_lp_item
WHERE
lp_id = ".$this->lp_id." AND
@ -8655,6 +8654,10 @@ class learnpath
$defaults['content_lp'] = file_get_contents($content_path);
}
if (!empty($id)) {
$form->addHidden('id', $id);
}
$form->addElement('hidden', 'type', $item_type);
$form->addElement('hidden', 'post_time', time());
$form->setDefaults($defaults);
@ -9715,6 +9718,29 @@ class learnpath
$return .= "\n";
}
$return .= "
function load_cbo(id) {
if (!id) {
return false;
}
var cbo = document.getElementById('previous');
for(var i = cbo.length - 1; i > 0; i--) {
cbo.options[i] = null;
}
var k=0;
for(var i = 1; i <= child_name[id].length; i++){
var option = new Option(child_name[id][i - 1], child_value[id][i - 1]);
option.style.paddingLeft = '40px';
cbo.options[i] = option;
k = i;
}
cbo.options[k].selected = true;
$('#previous').selectpicker('refresh');
}";
return $return;
}
@ -9785,33 +9811,6 @@ class learnpath
return $return;
}
/**
* Displays a basic form on the overview page for changing the item title and the item description.
*
* @param string $item_type
* @param string $title
* @param array $data
*
* @throws Exception
* @throws HTML_QuickForm_Error
*
* @return string
*/
public function display_item_small_form($item_type, $title = '', $data = [])
{
$url = api_get_self().'?'.api_get_cidreq().'&action=edit_item&lp_id='.$this->lp_id;
$form = new FormValidator('small_form', 'post', $url);
$form->addElement('header', $title);
$form->addElement('text', 'title', get_lang('Title'));
$form->addButtonSave(get_lang('Save'), 'submit_button');
$form->addElement('hidden', 'id', $data['id']);
$form->addElement('hidden', 'parent', $data['parent_item_id']);
$form->addElement('hidden', 'previous', $data['previous_item_id']);
$form->setDefaults(['title' => $data['title']]);
return $form->toHtml();
}
/**
* Return HTML form to allow prerequisites selection.
*
@ -12135,7 +12134,7 @@ EOD;
*/
public function getCategoryId()
{
return $this->categoryId;
return (int) $this->categoryId;
}
/**

@ -46,30 +46,7 @@ if ($learnPath->get_lp_session_id() != api_get_session_id()) {
exit;
}
$htmlHeadXtra[] = '<script>'.
$learnPath->get_js_dropdown_array()."
function load_cbo(id) {
if (!id) {
return false;
}
var cbo = document.getElementById('previous');
for(var i = cbo.length - 1; i > 0; i--) {
cbo.options[i] = null;
}
var k=0;
for(var i = 1; i <= child_name[id].length; i++){
var option = new Option(child_name[id][i - 1], child_value[id][i - 1]);
option.style.paddingLeft = '40px';
cbo.options[i] = option;
k = i;
}
cbo.options[k].selected = true;
$('#previous').selectpicker('refresh');
}
$htmlHeadXtra[] = '<script>'.$learnPath->get_js_dropdown_array()."
$(function() {
if ($('#previous')) {
if('parent is'+$('#idParent').val()) {

@ -33,6 +33,7 @@ $_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);
exit;
}
if (api_is_in_gradebook()) {
@ -61,6 +62,7 @@ if (isset($_REQUEST['updateaudio'])) {
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('BasicOverview')];
}
$htmlHeadXtra[] = '<script>'.$learnPath->get_js_dropdown_array().'</script>';
// Theme calls.
$show_learn_path = true;
$lp_theme_css = $learnPath->get_theme();

@ -76,7 +76,7 @@ $items = learnpath::getCategoryFromCourseIntoSelect(api_get_course_int_id(), tru
$form->addElement('select', 'category_id', get_lang('Category'), $items);
// Hide toc frame
$hide_toc_frame = $form->addElement(
$form->addElement(
'checkbox',
'hide_toc_frame',
null,
@ -142,7 +142,7 @@ $defaults['lp_encoding'] = Security::remove_XSS($learnPath->encoding);
$defaults['lp_name'] = Security::remove_XSS($learnPath->get_name());
$defaults['lp_author'] = Security::remove_XSS($learnPath->get_author());
$defaults['hide_toc_frame'] = $hideTableOfContents;
$defaults['category_id'] = intval($learnPath->getCategoryId());
$defaults['category_id'] = $learnPath->getCategoryId();
$defaults['accumulate_scorm_time'] = $learnPath->getAccumulateScormTime();
$expired_on = $learnPath->expired_on;
@ -241,6 +241,8 @@ if ($enableLpExtraFields) {
</script>';
}
$htmlHeadXtra[] = '<script>'.$learnPath->get_js_dropdown_array()."</sript>";
$defaults['publicated_on'] = !empty($publicated_on) && $publicated_on !== '0000-00-00 00:00:00'
? api_get_local_time($publicated_on)
: null;

@ -21,35 +21,7 @@ api_protect_course_script();
$learnPath = Session::read('oLP');
/* Header and action code */
$htmlHeadXtra[] = '
<script>'.$learnPath->get_js_dropdown_array().
"
function load_cbo(id) {
if (!id) {
return false;
}
var cbo = document.getElementById('previous');
for(var i = cbo.length - 1; i > 0; i--) {
cbo.options[i] = null;
}
var k=0;
for(var i = 1; i <= child_name[id].length; i++){
var option = new Option(child_name[id][i - 1], child_value[id][i - 1]);
option.style.paddingLeft = '20px';
cbo.options[i] = option;
k = i;
}
cbo.options[k].selected = true;
$('#previous').selectpicker('refresh');
}
".
'
$htmlHeadXtra[] = '<script>'.$learnPath->get_js_dropdown_array().'
$(document).on("ready", function() {
CKEDITOR.on("instanceReady", function (e) {
showTemplates("content_lp");
@ -67,7 +39,7 @@ $submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
if (!$is_allowed_to_edit || $isStudentView) {
error_log('New LP - User not authorized in lp_edit_item.php');
header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
header('location:lp_controller.php?action=view&lp_id='.$learnpath_id.'&'.api_get_cidreq());
exit;
}
// From here on, we are admin because of the previous condition, so don't check anymore.

@ -22,39 +22,14 @@ $learnPath = Session::read('oLP');
/* Header and action code */
$htmlHeadXtra[] = '<script>'.
$learnPath->get_js_dropdown_array().
"
function load_cbo(id) {
if (!id) {
return false;
}
var cbo = document.getElementById('previous');
for(var i = cbo.length - 1; i > 0; i--) {
cbo.options[i] = null;
}
var k=0;
for(var i = 1; i <= child_name[id].length; i++) {
cbo.options[i] = new Option(child_name[id][i - 1], child_value[id][i - 1]);
k=i;
}
cbo.options[k].selected = true;
$('#previous').selectpicker('refresh');
}
".
"\n".
'$().ready(function() {'."\n".
'if ($(\'#previous\')) {'."\n".
'if(\'parent is\'+$(\'#idParent\').val()) {'.
'load_cbo($(\'#idParent\').val());'."\n".
'}}'."\n".
'});</script>'."\n";
'});</script>';
/* Constants and variables */
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
$isStudentView = isset($_REQUEST['isStudentView']) ? (int) $_REQUEST['isStudentView'] : '';
@ -64,6 +39,7 @@ $submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : '';
/* MAIN CODE */
if ((!$is_allowed_to_edit) || ($isStudentView)) {
header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
exit;
}
// From here on, we are admin because of the previous condition, so don't check anymore.

Loading…
Cancel
Save