diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php index 7389427513..53dc092231 100755 --- a/main/lp/learnpath.class.php +++ b/main/lp/learnpath.class.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; } /** diff --git a/main/lp/lp_add_item.php b/main/lp/lp_add_item.php index 5f4c1f2ce3..d6b8f20f28 100755 --- a/main/lp/lp_add_item.php +++ b/main/lp/lp_add_item.php @@ -46,30 +46,7 @@ if ($learnPath->get_lp_session_id() != api_get_session_id()) { exit; } -$htmlHeadXtra[] = ''; // Theme calls. $show_learn_path = true; $lp_theme_css = $learnPath->get_theme(); diff --git a/main/lp/lp_edit.php b/main/lp/lp_edit.php index 5c4cd53f5e..97e0f7d6d4 100755 --- a/main/lp/lp_edit.php +++ b/main/lp/lp_edit.php @@ -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) { '; } +$htmlHeadXtra[] = ''."\n"; +'});'; /* 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.