diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 12b54c1a9d..1b0efda0e5 100644 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -6387,9 +6387,40 @@ function display_thread_form($action = 'add', $id = 0, $extra_info = '') $return = '
'.get_lang("Document").'
'; $return .= '
'; + $resources=api_store_result($res_doc); - $return .=$this->write_resources_tree('', $resources); + $resources_sorted = array(); + + // if you want to debug it, I advise you to do "echo" on the eval statements + + foreach($resources as $resource) + { + $resource_paths = explode('/',$resource['path']); + array_shift($resource_paths); + $path_to_eval = $last_path = ''; + $is_file = false; + foreach($resource_paths as $key => $resource_path) + { + if(strpos($resource_path,'.')===false && $key != count($resource_paths)-1) + { // it's a folder + $path_to_eval .= '["'.$resource_path.'"]["files"]'; + } + else if(strpos($resource_path,'.')!==false) + $is_file = true; + $last_path = $resource_path; + } + if($is_file) + { + eval('$resources_sorted'.$path_to_eval.'['.$resource['id'].'] = "'.$last_path.'";'); + } + else + { + eval('$resources_sorted'.$path_to_eval.'["'.$last_path.'"]["id"]='.$resource['id'].';'); + } + + } + $return .=$this->write_resources_tree('', $resources_sorted); $return .='
'; @@ -6400,49 +6431,30 @@ function display_thread_form($action = 'add', $id = 0, $extra_info = '') return $return; } - function write_resources_tree($parent, $resources_array_first = false){ + function write_resources_tree($return, $resources_sorted, $num=0){ include_once(api_get_path(LIBRARY_PATH).'fileDisplay.lib.php'); - static $resources_array; - if($resources_array_first !== false) - $resources_array = $resources_array_first; - - while($value = current($resources_array)) + foreach($resources_sorted as $key=>$resource) { - if(strpos($value['path'], $parent)!==false || $parent=='') - { - - $explode = explode('/', $value['path']); - $num = count($explode) - 2; - - //It's a file - if ($value['filetype'] == 'file') { - if($num==0) $num=1; - - $icon = choose_image(trim($value['path'])); - $position = strrpos($icon,'.'); - $icon=substr($icon,0,$position).'_small.gif'; - - //value['path'] don't always have an extension so we must take the path to have the complete name with extension - $array_temp = explode('/',trim($value['path'])); - $document_name = $array_temp[count($array_temp)-1]; - - $return .= '
 '.$document_name."
\r\n"; - array_shift($resources_array); - } - //It's a folder - else { - $return .= '
 '.$value['title'].'
\r\n"; - } + if(is_array($resource['files'])) + { // it's a folder + $return .= '
 '.$key.'
\r\n"; } else - return $return; + { + // it's a file + $icon = choose_image($resource); + $position = strrpos($icon,'.'); + $icon=substr($icon,0,$position).'_small.gif'; + $return .= '
 '.$resource."
\r\n"; + } + } + return $return; }