Add directory during lp document creation see BT#10888

ofaj
jmontoya 10 years ago
parent 7429601e39
commit a22dea4010
  1. 20
      main/inc/lib/document.lib.php
  2. 106
      main/newscorm/learnpath.class.php
  3. 19
      main/newscorm/lp_add_item.php
  4. 12
      main/newscorm/lp_controller.php

@ -5016,10 +5016,10 @@ class DocumentManager
* @param string The current folder (path inside of the "document" directory, including the prefix "/")
* @param string Group directory, if empty, prevents documents to be uploaded (because group documents cannot be uploaded in root)
* @param boolean Whether to change the renderer (this will add a template <span> to the QuickForm object displaying the form)
* @todo this funcionality is really bad : jmontoya
* @return string html form
*/
public static function build_directory_selector($folders, $document_id, $group_dir = '', $change_renderer = false)
public static function build_directory_selector($folders, $document_id, $group_dir = '', $change_renderer = false, & $form = null, $selectName = 'id')
{
$doc_table = Database::get_course_table(TABLE_DOCUMENT);
$course_id = api_get_course_int_id();
@ -5041,9 +5041,18 @@ class DocumentManager
}
}
$form = new FormValidator('selector', 'GET', api_get_self() . '?' . api_get_cidreq());
$attributes = [];
if (empty($form)) {
$form = new FormValidator('selector', 'GET', api_get_self().'?'.api_get_cidreq());
$attributes = array('onchange' => 'javascript: document.selector.submit();');
}
$form->addElement('hidden', 'cidReq', api_get_course_id());
$parent_select = $form->addSelect('id', get_lang('CurrentDirectory'), '', array('onchange' => 'javascript: document.selector.submit();'));
$parent_select = $form->addSelect(
$selectName,
get_lang('CurrentDirectory'),
'',
$attributes
);
if ($change_renderer) {
$renderer = $form->defaultRenderer();
@ -5090,6 +5099,7 @@ class DocumentManager
}
}
}
$html = $form->toHtml();
return $html;
@ -5765,6 +5775,8 @@ class DocumentManager
* @param $curdirpath
* @param $move_file
* @param string $group_dir
* @param $form
*
* @return string
*/
public static function build_move_to_selector($folders, $curdirpath, $move_file, $group_dir = '')

@ -5924,11 +5924,14 @@ class learnpath
}
$folder = self::generate_learning_path_folder($course);
// Limits title size
$title = api_substr(api_replace_dangerous_char($lp_name), 0 , 80);
$dir = $dir.$title;
// Creating LP folder
$documentId = null;
if ($folder) {
//Limits title size
$title = api_substr(api_replace_dangerous_char($lp_name), 0 , 80);
$dir = $dir.$title;
$filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document';
if (!is_dir($filepath.'/'.$dir)) {
$folderData = create_unexisting_directory(
@ -5944,6 +5947,8 @@ class learnpath
if (!empty($folderData)) {
$folder = true;
}
$documentId = $folderData['id'];
} else {
$folder = true;
}
@ -5952,11 +5957,19 @@ class learnpath
$filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document'.$dir;
}
}
if (empty($documentId)) {
$dir = api_remove_trailing_slash($dir);
$documentId = DocumentManager::get_document_id($course, $dir, 0);
}
$array = array(
'dir' => $dir,
'filepath' => $filepath,
'folder' => $folder
'folder' => $folder,
'id' => $documentId
);
return $array;
}
@ -5966,10 +5979,11 @@ class learnpath
* @param string $content
* @param string $title
* @param string $extension
* @param int $parentId
*
* @return string
*/
public function create_document($courseInfo, $content = '', $title = '', $extension = 'html')
public function create_document($courseInfo, $content = '', $title = '', $extension = 'html', $parentId = 0)
{
if (!empty($courseInfo)) {
$course_id = $courseInfo['real_id'];
@ -5977,34 +5991,39 @@ class learnpath
$course_id = api_get_course_int_id();
}
global $charset;
$postDir = isset($_POST['dir']) ? $_POST['dir'] : '';
$dir = isset ($_GET['dir']) ? $_GET['dir'] : $postDir; // Please, do not modify this dirname formatting.
// Please, do not modify this dirname formatting.
if (strstr($dir, '..')) {
$dir = '/';
}
if (!empty($dir[0]) && $dir[0] == '.') {
$dir = substr($dir, 1);
}
if (!empty($dir[0]) && $dir[0] != '/') {
$dir = '/' . $dir;
}
if (isset($dir[strlen($dir) - 1]) && $dir[strlen($dir) - 1] != '/') {
$dir .= '/';
}
$filepath = api_get_path(SYS_COURSE_PATH) . $courseInfo['path'] . '/document' . $dir;
//$dir = '/';
// Generates folder
$result = $this->generate_lp_folder($courseInfo);
$dir = $result['dir'];
if (empty($_POST['dir']) && empty($_GET['dir'])) {
//Generates folder
$result = $this->generate_lp_folder($courseInfo);
$dir = $result['dir'];
$filepath = $result['filepath'];
if (empty($parentId)) {
$postDir = isset($_POST['dir']) ? $_POST['dir'] : '';
$dir = isset ($_GET['dir']) ? $_GET['dir'] : $postDir; // Please, do not modify this dirname formatting.
// Please, do not modify this dirname formatting.
if (strstr($dir, '..')) {
$dir = '/';
}
if (!empty($dir[0]) && $dir[0] == '.') {
$dir = substr($dir, 1);
}
if (!empty($dir[0]) && $dir[0] != '/') {
$dir = '/'.$dir;
}
if (isset($dir[strlen($dir) - 1]) && $dir[strlen($dir) - 1] != '/') {
$dir .= '/';
}
} else {
$parentInfo = DocumentManager::get_document_data_by_id($parentId, $courseInfo['code']);
if (!empty($parentInfo)) {
$dir = $parentInfo['path'].'/';
}
}
$filepath = api_get_path(SYS_COURSE_PATH) . $courseInfo['path'] . '/document'.$dir;
if (!is_dir($filepath)) {
$filepath = api_get_path(SYS_COURSE_PATH) . $courseInfo['path'] . '/document/';
$dir = '/';
$filepath = api_get_path(SYS_COURSE_PATH) . $courseInfo['path'] . '/document'.$dir;
}
// stripslashes() before calling api_replace_dangerous_char() because $_POST['title']
@ -6018,16 +6037,14 @@ class learnpath
}
$title = disable_dangerous_file($title);
$filename = $title;
$content = !empty($content) ? $content : $_POST['content_lp'];
$tmp_filename = $filename;
$i = 0;
while (file_exists($filepath . $tmp_filename . '.'.$extension))
while (file_exists($filepath . $tmp_filename . '.'.$extension)){
$tmp_filename = $filename . '_' . ++ $i;
}
$filename = $tmp_filename . '.'.$extension;
if ($extension == 'html') {
@ -6103,7 +6120,7 @@ class learnpath
if ($new_comment)
$ct .= ", comment='" . Database::escape_string($new_comment). "'";
if ($new_title)
$ct .= ", title='" . Database::escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset))."' ";
$ct .= ", title='" . Database::escape_string($new_title)."' ";
$sql = "UPDATE " . $tbl_doc ." SET " . substr($ct, 1)."
WHERE c_id = ".$course_id." AND id = " . $document_id;
@ -7556,7 +7573,27 @@ class learnpath
}
$defaults['description'] = $item_description;
$form->addElement('html', $return);
if ($action != 'move') {
$data = $this->generate_lp_folder($_course);
$folders = DocumentManager::get_all_document_folders(
$_course,
0,
true
);
DocumentManager::build_directory_selector(
$folders,
'',
array(),
true,
$form,
'directory_parent_id'
);
if (isset($data['id'])) {
$defaults['directory_parent_id'] = $data['id'];
}
$form->addElement('text', 'title', get_lang('Title'), array('id' => 'idTitle', 'class' => 'col-md-4'));
$form->applyFilter('title', 'html_filter');
}
@ -7647,7 +7684,6 @@ class learnpath
}
$arrHide = array();
for ($i = 0; $i < count($arrLP); $i++) {
if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
if (isset($extra_info['previous_item_id']) && $extra_info['previous_item_id'] == $arrLP[$i]['id'])
@ -7757,7 +7793,7 @@ class learnpath
$form->addElement('hidden', 'post_time', time());
$form->setDefaults($defaults);
return $form->return_form();
return $form->returnForm();
}
/**

@ -64,9 +64,9 @@ $(document).on("ready", function() {
/* Constants and variables */
$isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView'] : null;
$learnpath_id = isset($_REQUEST['lp_id']) ? intval($_REQUEST['lp_id']) : null;
$submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
$isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView'] : null;
$learnpath_id = isset($_REQUEST['lp_id']) ? intval($_REQUEST['lp_id']) : null;
$submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
$type = isset($_GET['type']) ? $_GET['type'] : null;
$action = isset($_GET['action']) ? $_GET['action'] : null;
@ -98,11 +98,17 @@ $interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpa
switch ($type) {
case 'chapter':
$interbreadcrumb[]= array('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id(), 'name' => get_lang('NewStep'));
$interbreadcrumb[] = array(
'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id(),
'name' => get_lang('NewStep'),
);
$interbreadcrumb[]= array('url' => '#', 'name' => get_lang('NewChapter'));
break;
case 'document':
$interbreadcrumb[]= array('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id(), 'name' => get_lang('NewStep'));
$interbreadcrumb[] = array(
'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id(),
'name' => get_lang('NewStep'),
);
break;
default:
$interbreadcrumb[]= array('url' => '#', 'name' => get_lang('NewStep'));
@ -195,11 +201,8 @@ $(document).ready(function() {
/* DISPLAY SECTION */
echo $learnPath->build_action_menu();
echo '<div class="row" style="overflow:hidden">';
echo '<div id="lp_sidebar" class="col-md-4">';
echo $learnPath->return_new_tree(null, true);
$message = isset($_REQUEST['message']) ? $_REQUEST['message'] : null;

@ -390,6 +390,14 @@ switch ($action) {
} else {
$_SESSION['post_time'] = $_POST['post_time'];
$directoryParentId = isset($_POST['directory_parent_id']) ? $_POST['directory_parent_id'] : 0;
if (empty($directoryParentId)) {
$result = $_SESSION['oLP']->generate_lp_folder($courseInfo);
var_dump($result);exit;
}
$parent = isset($_POST['parent']) ? $_POST['parent'] : '';
$previous = isset($_POST['previous']) ? $_POST['previous'] : '';
@ -407,7 +415,9 @@ switch ($action) {
$document_id = $_SESSION['oLP']->create_document(
$_course,
$_POST['content_lp'],
$_POST['title']
$_POST['title'],
'html',
$directoryParentId
);
}
}

Loading…
Cancel
Save