Adding document preview in user_portal first draft see #2773

skala
Julio Montoya 15 years ago
parent b4f4fd3e6e
commit 96c6c26518
  1. 9
      main/css/base.css
  2. 2
      main/document/upload.php
  3. 72
      main/inc/ajax/document.ajax.php
  4. 5
      main/inc/header.inc.php
  5. 10
      main/inc/lib/course.lib.php
  6. 157
      main/inc/lib/document.lib.php
  7. 17
      main/inc/lib/javascript/dtree/dtree.css
  8. 707
      main/inc/lib/javascript/dtree/dtree.js
  9. 135
      main/newscorm/learnpath.class.php
  10. 27
      user_portal.php

@ -2246,4 +2246,13 @@ div.admin_section h4 {
.thematic_advance_actions {
width:100px;
}
.document_preview_container {
background-color: #ccc;
position: absolute;
z-index: 20;
margin:5px;
padding:5px;
}

@ -286,7 +286,7 @@ echo '<style>
padding: 3px 10px 3px 0;
}
</style>';
$url = api_get_path(WEB_AJAX_PATH).'document.ajax.php';
$url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=upload_file';
$multiple_form = get_lang('ClickToSelectOrDragAndDropMultipleFilesOnTheUploadField').'<br />';
//Adding icon replace the <div>'.get_lang('UploadFiles').'</div> with this:
//<div style="width:50%;margin:0 auto;"> '.Display::div(Display::return_icon('folder_document.png', '', array(), 64), array('style'=>'float:left')).' '.get_lang('UploadFiles').'</div>

@ -5,36 +5,46 @@
*/
require_once '../global.inc.php';
api_protect_course_script(true);
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
//User access same as upload.php
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
// This needs cleaning!
if (api_get_group_id()) {
if ($is_allowed_to_edit || GroupManager::is_user_in_group(api_get_user_id(), api_get_group_id())) { // Only courseadmin or group members allowed
} else {
exit;
}
} elseif ($is_allowed_to_edit || is_my_shared_folder(api_get_user_id(), $_POST['curdirpath'], api_get_session_id())) {
} else { // No course admin and no group member...
exit;
}
if (!empty($_FILES)) {
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
$result = DocumentManager::upload_document($_FILES, $_POST['curdirpath'], '', '', 0, 'overwrite', false, false);
$file = $_FILES['file'];
$json = array();
$json['name'] = Display::url(api_htmlentities($file['name']), api_htmlentities($result['url']), array('target'=>'_blank'));
$json['type'] = api_htmlentities($file['type']);
$json['size'] = format_file_size($file['size']);
if (!empty($result) && is_array($result)) {
$json['result'] = Display::return_icon('accept.png', get_lang('Uploaded'));
} else {
$json['result'] = Display::return_icon('exclamation.png', get_lang('Error'));
}
echo json_encode($json);
}
$action = $_REQUEST['a'];
switch($action) {
case 'upload_file':
api_protect_course_script(true);
//User access same as upload.php
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
// This needs cleaning!
if (api_get_group_id()) {
if ($is_allowed_to_edit || GroupManager::is_user_in_group(api_get_user_id(), api_get_group_id())) { // Only courseadmin or group members allowed
} else {
exit;
}
} elseif ($is_allowed_to_edit || is_my_shared_folder(api_get_user_id(), $_POST['curdirpath'], api_get_session_id())) {
} else { // No course admin and no group member...
exit;
}
if (!empty($_FILES)) {
require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
$result = DocumentManager::upload_document($_FILES, $_POST['curdirpath'], '', '', 0, 'overwrite', false, false);
$file = $_FILES['file'];
$json = array();
$json['name'] = Display::url(api_htmlentities($file['name']), api_htmlentities($result['url']), array('target'=>'_blank'));
$json['type'] = api_htmlentities($file['type']);
$json['size'] = format_file_size($file['size']);
if (!empty($result) && is_array($result)) {
$json['result'] = Display::return_icon('accept.png', get_lang('Uploaded'));
} else {
$json['result'] = Display::return_icon('exclamation.png', get_lang('Error'));
}
echo json_encode($json);
}
break;
case 'document_preview':
$course_info = api_get_course_info_by_id($_REQUEST['course_id']);
echo DocumentManager::get_document_preview($course_info);
break;
}
exit;

@ -90,9 +90,10 @@ global $show_learn_path;
if ($show_learn_path) {
$htmlHeadXtra[] = '<link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_CSS_PATH).$my_style.'/learnpath.css"/>';
$htmlHeadXtra[] = '<link rel="stylesheet" type="text/css" href="dtree.css" />'; //will be moved
$htmlHeadXtra[] = '<script src="dtree.js" type="text/javascript"></script>'; //will be moved
}
$htmlHeadXtra[] = '<link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/dtree/dtree.css" />'; //will be moved
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/dtree/dtree.js" type="text/javascript"></script>'; //will be moved
//Base CSS
echo '@import "'.api_get_path(WEB_CSS_PATH).'base.css";';
//Default CSS

@ -2677,7 +2677,7 @@ class CourseManager {
$without_special_courses = ' AND course.code NOT IN ("'.implode('","',$special_course_list).'")';
}
$sql_select_courses = "SELECT course.code, course.visual_code, course.subscribe subscr, course.unsubscribe unsubscr,
$sql_select_courses = "SELECT course.id, course.code, course.visual_code, course.subscribe subscr, course.unsubscribe unsubscr,
course.title title, course.tutor_name tutor, course.db_name, course.directory, course_rel_user.status status,
course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat, course.visibility
FROM $TABLECOURS course,
@ -2715,7 +2715,13 @@ class CourseManager {
echo '<div class="userportal-course-item">';
if (api_is_platform_admin()) {
echo '<div style="float:right;"><a href="'.api_get_path(WEB_CODE_PATH).'course_info/infocours.php?cidReq='.$course['code'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),22).'</a>';
echo '<div style="float:right;">';
echo '<a id="document_preview_'.$course['id'].'" class="document_preview" href="#">'.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),22).'</a>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'course_info/infocours.php?cidReq='.$course['code'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),22).'</a>';
echo '<div class="clear"></div>';
echo Display::div('', array('id' => 'document_result_'.$course['id'], 'class'=>'document_preview_container'));
if ($course['status'] == COURSEMANAGER) {
//echo Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'), array('style'=>'width: 11px; height: 11px;'));
}

@ -2472,5 +2472,162 @@ return 'application/octet-stream';
</div>';
return $html;
}
function get_document_preview($course_info, $lp_id = false) {
if (!isset($course_info['dbName'])) {
$course_info = api_get_course_info($course_info['code']);
}
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_doc = Database::get_course_table(TABLE_DOCUMENT, $course_info['dbName']);
$tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']);
$path = '/';
$path = Database::escape_string(str_replace('_', '\_', $path));
$added_slash = ($path == '/') ? '' : '/';
//condition for the session
$current_session_id = api_get_session_id();
$condition_session = " AND (id_session = '$current_session_id' OR (id_session = '0' AND insert_date <= (SELECT creation_date FROM $tbl_course WHERE code = '".$course_info['code']."' )))";
$sql_doc = "SELECT docs.*
FROM $tbl_item_prop AS last, $tbl_doc AS docs
WHERE docs.id = last.ref
AND docs.path LIKE '".$path.$added_slash."%'
AND docs.path NOT LIKE '%_DELETED_%'
AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
$res_doc = Database::query($sql_doc);
$return = '<div class="lp_resource">';
$resources = Database::store_result($res_doc);
$resources_sorted = array();
if ($lp_id) {
$return .= '<div class="lp_resource_element">';
$return .= Display::return_icon('new_doc.gif', '', array(), 22);
$return .= Display::url(get_lang('NewDocument') , api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_DOCUMENT.'&lp_id='.$_SESSION['oLP']->lp_id);
$return .= '</div>';
}
// 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) {
//for backward compatibility
if (empty($resource['title'])) {
$resource['title'] = basename($resource['path']);
}
eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' .$resource['title']."/". $last_path. '";');
} else {
eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
}
}
$label = get_lang('Documents');
$new_array[$label] = array('id' => 0, 'files' => $resources_sorted);
$return .= self::write_resources_tree($course_info, $new_array, 0, $lp_id);
$return .= '</div>';
return $return;
}
/**
* Generate and return an HTML list of resources based on a given array.
* This list is used to show the course creator a list of available resources to choose from
* when creating a learning path.
* @param array Array of elements to add to the list
* @param integer Enables the tree display by shifting the new elements a certain distance to the right
* @return string The HTML list
*/
public function write_resources_tree($course_info, $resources_sorted, $num = 0, $lp_id = false) {
require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
$return = '';
if (count($resources_sorted) > 0) {
foreach ($resources_sorted as $key => $resource) {
if (isset($resource['id']) && is_int($resource['id'])) {
// It's a folder.
//hide some folders
if (in_array($key, array('shared_folder','chat_files', 'HotPotatoes_files', 'css', 'certificates'))){
continue;
} elseif(preg_match('/_groupdocs/', $key)){
continue;
} elseif(preg_match('/sf_user_/', $key)){
continue;
} elseif(preg_match('/shared_folder_session_/', $key)){
continue;
}
//trad some titles
if ($key=='images') {
$key=get_lang('Images');
} elseif($key=='gallery') {
$key=get_lang('Gallery');
} elseif($key=='flash') {
$key=get_lang('Flash');
} elseif($key=='audio'){
$key=get_lang('Audio');
} elseif($key=='video') {
$key=get_lang('Video');
}
$return .= '<div class="doc_resource">';
$return .= '<div style="margin-left:' . ($num * 18) . 'px;margin-right:5px;">';
$return .= '<img style="cursor: pointer;" src="../img/nolines_plus.gif" align="absmiddle" id="img_' . $resource['id'] . '" onclick="javascript: testResources(\'' . $resource['id'] . '\',\'img_' . $resource['id'] . '\')"><img alt="" src="../img/lp_folder.gif" title="" align="absmiddle" />&nbsp;
<span onclick="javascript: testResources(\'' . $resource['id'] . '\',\'img_' . $resource['id'] . '\')" style="cursor: pointer;" >' . $key . '</span>
</div><div style="display: none;" id="' . $resource['id'] . '">';
if (isset($resource['files'])) {
$return .= self::write_resources_tree($course_info, $resource['files'], $num +1, $lp_id);
}
$return .= '</div></div>';
} else {
if (!is_array($resource)) {
// It's a file.
$icon = choose_image($resource);
$position = strrpos($icon, '.');
$icon = substr($icon, 0, $position) . '_small.gif';
$file_info = explode('/', $resource);
$my_file_title = $file_info[0];
$my_file_name = $file_info[1];
// Show the "image name" not the filename of the image.
if ($lp_id) {
$lp_id = $this->lp_id;
$url = api_get_self() . '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $key . '&amp;lp_id=' .$lp_id;
} else {
$url = api_get_path(WEB_CODE_PATH).'document/document.php?cidReq='.$course_info['code'].'&id='.$key;
}
$link = Display::url('<img alt="" src="../img/' . $icon . '" title="" />&nbsp;' . $my_file_title, $url);
$return .= '<div class="doc_resource"><div style="margin-left:' . (($num +1) * 18) . 'px;margin-right:5px;">';
$return .= $link;
$return .= '</div></div>';
}
}
}
}
return $return;
}
}
//end class DocumentManager

@ -0,0 +1,17 @@
/*--------------------------------------------------|
| dTree 2.05 | www.destroydrop.com/javascript/tree/ |
|---------------------------------------------------|
| Copyright (c) 2002-2003 Geir Landr<EFBFBD> |
|--------------------------------------------------*/
.dtree{color:#000000; font-size:12px; white-space:nowrap;}
.dtree img{border:0; margin-right:5px; vertical-align:middle;}
.dtree a{color:#000000; font-weight:normal; text-decoration:none;}
.dtree a.node,
.dtree a.nodeSel{padding:1px 2px 1px 2px; white-space: nowrap;}
.dtree a.node:hover, .dtree a.nodeSel:hover{color:#000000; text-decoration:none;}
.dtree a.nodeSel{background:#F8F8F8; border:1px dashed #999999;}
.dtree .clip{overflow:hidden;}

@ -0,0 +1,707 @@
/*--------------------------------------------------|
| dTree 2.05 | www.destroydrop.com/javascript/tree/ |
|---------------------------------------------------|
| Copyright (c) 2002-2003 Geir Landr<EFBFBD> |
| |
| This script can be used freely as long as all |
| copyright messages are intact. |
| |
| Updated: 17.04.2003 |
|--------------------------------------------------*/
// Node object
function Node(id, pid, name, url, title, target, icon, iconOpen, open) {
this.id = id;
this.pid = pid;
this.name = name;
this.url = url;
this.title = title;
this.target = target;
this.icon = icon;
this.iconOpen = iconOpen;
this._io = open || true;
this._is = false;
this._ls = false;
this._hc = false;
this._ai = 0;
this._p;
};
// Tree object
function dTree(objName) {
this.config = {
target : null,
folderLinks : true,
useSelection : true,
useCookies : true,
useLines : true,
useIcons : true,
useStatusText : false,
closeSameLevel : false,
inOrder : false
}
this.icon = {
root : '../img/icons/22/learnpath.png',
folder : '../img/folder.gif',
folderOpen : '../img/folderopen.gif',
node : '../img/page.gif',
empty : '../img/empty2.gif',
line : '../img/line.gif',
join : '../img/join.gif',
joinBottom : '../img/joinbottom.gif',
plus : '../img/plus.gif',
plusBottom : '../img/plusbottom.gif',
minus : '../img/minus.gif',
minusBottom : '../img/minusbottom.gif',
nlPlus : '../img/nolines_plus.gif',
nlMinus : '../img/nolines_minus.gif'
};
this.obj = objName;
this.aNodes = [];
this.aIndent = [];
this.root = new Node(-1);
this.selectedNode = null;
this.selectedFound = false;
this.completed = false;
};
// Adds a new node to the node array
dTree.prototype.add = function(id, pid, name, url, title, target, icon, iconOpen, open) {
this.aNodes[this.aNodes.length] = new Node(id, pid, name, url, title, target, icon, iconOpen, open);
};
// Open/close all nodes
dTree.prototype.openAll = function() {
this.oAll(true);
};
dTree.prototype.closeAll = function() {
this.oAll(false);
};
// Outputs the tree to the page
dTree.prototype.toString = function() {
var str = '<div class="dtree">\n';
if (document.getElementById) {
if (this.config.useCookies) this.selectedNode = this.getSelected();
str += this.addNode(this.root);
} else str += 'Browser not supported.';
str += '</div>';
if (!this.selectedFound) this.selectedNode = null;
this.completed = true;
return str;
};
// Creates the tree structure
dTree.prototype.addNode = function(pNode) {
var str = '';
var n=0;
if (this.config.inOrder) n = pNode._ai;
for (n; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == pNode.id) {
var cn = this.aNodes[n];
cn._p = pNode;
cn._ai = n;
this.setCS(cn);
if (!cn.target && this.config.target) cn.target = this.config.target;
if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id);
if (!this.config.folderLinks && cn._hc) cn.url = null;
if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) {
cn._is = true;
this.selectedNode = n;
this.selectedFound = true;
}
str += this.node(cn, n);
if (cn._ls) break;
}
}
return str;
};
// Creates the node icon, url and text
dTree.prototype.node = function(node, nodeId) {
var str = '<div class="dTreeNode">' + this.indent(node, nodeId);
if (this.config.useIcons) {
if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);
if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;
if (this.root.id == node.pid) {
node.icon = this.icon.root;
node.iconOpen = this.icon.root;
}
str += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';
}
if (node.url) {
str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"';
if (node.title) str += ' title="' + node.title + '"';
if (node.target) str += ' target="' + node.target + '"';
if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" ';
if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))
str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"';
str += '>';
}
else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id)
str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">';
str += node.name;
if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += '</a>';
str += '</div>';
if (node._hc) {
str += '<div id="d' + this.obj + nodeId + '" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'block') + ';">';
str += this.addNode(node);
str += '</div>';
}
this.aIndent.pop();
return str;
};
// Adds the empty and line icons
dTree.prototype.indent = function(node, nodeId) {
var str = '';
if (this.root.id != node.pid) {
for (var n=0; n<this.aIndent.length; n++)
str += '<img src="' + ( (this.aIndent[n] == 1 && this.config.useLines) ? this.icon.line : this.icon.empty ) + '" alt="" />';
(node._ls) ? this.aIndent.push(0) : this.aIndent.push(1);
if (node._hc) {
str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');"><img id="j' + this.obj + nodeId + '" src="';
if (!this.config.useLines) str += (node._io) ? this.icon.nlMinus : this.icon.nlPlus;
else str += ( (node._io) ? ((node._ls && this.config.useLines) ? this.icon.minusBottom : this.icon.minus) : ((node._ls && this.config.useLines) ? this.icon.plusBottom : this.icon.plus ) );
str += '" alt="" /></a>';
} else str += '<img src="' + ( (this.config.useLines) ? ((node._ls) ? this.icon.joinBottom : this.icon.join ) : this.icon.empty) + '" alt="" />';
}
return str;
};
// Checks if a node has any children and if it is the last sibling
dTree.prototype.setCS = function(node) {
var lastId;
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.id) node._hc = true;
if (this.aNodes[n].pid == node.pid) lastId = this.aNodes[n].id;
}
if (lastId==node.id) node._ls = true;
};
// Returns the selected node
dTree.prototype.getSelected = function() {
var sn = this.getCookie('cs' + this.obj);
return (sn) ? sn : null;
};
// Highlights the selected node
dTree.prototype.s = function(id) {
if (!this.config.useSelection) return;
var cn = this.aNodes[id];
// Added by Ivan Tcholakov to prevent javascript error when the tree is empty.
if (!cn) return;
if (cn._hc && !this.config.folderLinks) return;
if (this.selectedNode != id) {
if (this.selectedNode || this.selectedNode==0) {
eOld = document.getElementById("s" + this.obj + this.selectedNode);
eOld.className = "node";
}
eNew = document.getElementById("s" + this.obj + id);
eNew.className = "nodeSel";
this.selectedNode = id;
if (this.config.useCookies) this.setCookie('cs' + this.obj, cn.id);
}
};
// Toggle Open or close
dTree.prototype.o = function(id) {
var cn = this.aNodes[id];
this.nodeStatus(!cn._io, id, cn._ls);
cn._io = !cn._io;
if (this.config.closeSameLevel) this.closeLevel(cn);
if (this.config.useCookies) this.updateCookie();
};
// Open or close all nodes
dTree.prototype.oAll = function(status) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {
this.nodeStatus(status, n, this.aNodes[n]._ls)
this.aNodes[n]._io = status;
}
}
if (this.config.useCookies) this.updateCookie();
};
// Opens the tree to a specific node
dTree.prototype.openTo = function(nId, bSelect, bFirst) {
if (!bFirst) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].id == nId) {
nId=n;
break;
}
}
}
var cn=this.aNodes[nId];
if (cn.pid==this.root.id || !cn._p) return;
cn._io = true;
cn._is = bSelect;
if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);
if (this.completed && bSelect) this.s(cn._ai);
else if (bSelect) this._sn=cn._ai;
this.openTo(cn._p._ai, false, true);
};
// Closes all nodes on the same level as certain node
dTree.prototype.closeLevel = function(node) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {
this.nodeStatus(false, n, this.aNodes[n]._ls);
this.aNodes[n]._io = false;
this.closeAllChildren(this.aNodes[n]);
}
}
}
// Closes all children of a node
dTree.prototype.closeAllChildren = function(node) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {
if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls);
this.aNodes[n]._io = false;
this.closeAllChildren(this.aNodes[n]);
}
}
}
// Change the status of a node(open or closed)
dTree.prototype.nodeStatus = function(status, id, bottom) {
eDiv = document.getElementById('d' + this.obj + id);
eJoin = document.getElementById('j' + this.obj + id);
if (this.config.useIcons) {
eIcon = document.getElementById('i' + this.obj + id);
eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon;
}
eJoin.src = (this.config.useLines)?
((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)):
((status)?this.icon.nlMinus:this.icon.nlPlus);
eDiv.style.display = (status) ? 'block': 'none';
};
// [Cookie] Clears a cookie
dTree.prototype.clearCookie = function() {
var now = new Date();
var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
this.setCookie('co'+this.obj, 'cookieValue', yesterday);
this.setCookie('cs'+this.obj, 'cookieValue', yesterday);
};
// [Cookie] Sets value in a cookie
dTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
document.cookie =
escape(cookieName) + '=' + escape(cookieValue)
+ (expires ? '; expires=' + expires.toGMTString() : '')
+ (path ? '; path=' + path : '')
+ (domain ? '; domain=' + domain : '')
+ (secure ? '; secure' : '');
};
// [Cookie] Gets a value from a cookie
dTree.prototype.getCookie = function(cookieName) {
var cookieValue = '';
var posName = document.cookie.indexOf(escape(cookieName) + '=');
if (posName != -1) {
var posValue = posName + (escape(cookieName) + '=').length;
var endPos = document.cookie.indexOf(';', posValue);
if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
else cookieValue = unescape(document.cookie.substring(posValue));
}
return (cookieValue);
};
// [Cookie] Returns ids of open nodes as a string
dTree.prototype.updateCookie = function() {
var str = '';
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {
if (str) str += '.';
str += this.aNodes[n].id;
}
}
this.setCookie('co' + this.obj, str);
};
// [Cookie] Checks if a node id is in a cookie
dTree.prototype.isOpen = function(id) {
var aOpen = this.getCookie('co' + this.obj).split('.');
for (var n=0; n<aOpen.length; n++)
if (aOpen[n] == id) return true;
return false;
};
// If Push and pop is not implemented by the browser
if (!Array.prototype.push) {
Array.prototype.push = function array_push() {
for(var i=0;i<arguments.length;i++)
this[this.length]=arguments[i];
return this.length;
}
};
if (!Array.prototype.pop) {
Array.prototype.pop = function array_pop() {
lastElement = this[this.length-1];
this.length = Math.max(this.length-1,0);
return lastElement;
}
};
function testResources(id,img){
if(document.getElementById(id).style.display=='block'){
document.getElementById(id).style.display='none';
document.getElementById("img_"+id).src='../img/nolines_plus.gif';
}
else{
document.getElementById(id).style.display='block';
document.getElementById("img_"+id).src='../img/nolines_minus.gif';
}
}

@ -7484,137 +7484,10 @@ class learnpath {
* @return string
*/
public function get_documents() {
global $_course;
$tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
$tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$path = '/';
$path = Database::escape_string(str_replace('_', '\_', $path));
$added_slash = ($path == '/') ? '' : '/';
//condition for the session
$current_session_id = api_get_session_id();
$condition_session = " AND (id_session = '$current_session_id' OR (id_session = '0' AND insert_date <= (SELECT creation_date FROM $tbl_course WHERE code = '".$_course['code']."' )))";
$sql_doc = "SELECT docs.*
FROM $tbl_item_prop AS last, $tbl_doc AS docs
WHERE docs.id = last.ref
AND docs.path LIKE '".$path.$added_slash."%'
AND docs.path NOT LIKE '%_DELETED_%'
AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
$res_doc = Database::query($sql_doc);
//$return = '<div class="lp_resource_header"' ." onclick=\"if(document.getElementById('resDoc').style.display == 'block') {document.getElementById('resDoc').style.display = 'none';} else {document.getElementById('resDoc').style.display = 'block';}\"" . '>'.Display::return_icon('folder_document.gif',get_lang('Documents'),array('style'=>'margin-right:5px;', 'height' => '16px')).' '. get_lang('Documents') . '</div>';
$return = '<div class="lp_resource">';
$resources = Database::store_result($res_doc);
$resources_sorted = array();
$return .= '<div class="lp_resource_element">';
$return .= Display::return_icon('new_doc.gif', '', array(), 22);
$return .= Display::url(get_lang('NewDocument') , api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_DOCUMENT.'&lp_id='.$_SESSION['oLP']->lp_id);
$return .= '</div>';
// 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 . '";');
//for backward compatibility
if (empty($resource['title'])) {
$resource['title'] = basename($resource['path']);
}
eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' .$resource['title']."/". $last_path. '";');
} else {
eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
}
}
$label = get_lang('Documents');
$new_array[$label] = array('id' => 0, 'files'=>$resources_sorted);
$return .= $this->write_resources_tree($new_array);
/*if (Database :: num_rows($res_doc) == 0) {
$return .= '<div class="lp_resource_element">' . get_lang('NoDocuments') . '</div>';
}*/
$return .= '</div>';
return $return;
}
/**
* Generate and return an HTML list of resources based on a given array.
* This list is used to show the course creator a list of available resources to choose from
* when creating a learning path.
* @param array Array of elements to add to the list
* @param integer Enables the tree display by shifting the new elements a certain distance to the right
* @return string The HTML list
*/
public function write_resources_tree($resources_sorted, $num = 0) {
require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
$return = '';
if (count($resources_sorted) > 0) {
foreach ($resources_sorted as $key => $resource) {
if (isset($resource['id']) && is_int($resource['id'])) {
// It's a folder.
//hide some folders
if (in_array($key, array('shared_folder','chat_files', 'HotPotatoes_files', 'css', 'certificates'))){
continue;
} elseif(preg_match('/_groupdocs/', $key)){
continue;
} elseif(preg_match('/sf_user_/', $key)){
continue;
} elseif(preg_match('/shared_folder_session_/', $key)){
continue;
}
//trad some titles
if ($key=='images') {
$key=get_lang('Images');
} elseif($key=='gallery') {
$key=get_lang('Gallery');
} elseif($key=='flash') {
$key=get_lang('Flash');
} elseif($key=='audio'){
$key=get_lang('Audio');
} elseif($key=='video') {
$key=get_lang('Video');
}
$return .= '<div class="doc_resource">';
$return .= '<div style="margin-left:' . ($num * 18) . 'px;margin-right:5px;"><img style="cursor: pointer;" src="../img/nolines_plus.gif" align="absmiddle" id="img_' . $resource['id'] . '" onClick="javascript: testResources(\'' . $resource['id'] . '\',\'img_' . $resource['id'] . '\')"><img alt="" src="../img/lp_folder.gif" title="" align="absmiddle" />&nbsp;<span onClick="javascript: testResources(\'' . $resource['id'] . '\',\'img_' . $resource['id'] . '\')" style="cursor: pointer;" >' . $key . '</span></div><div style="display: none;" id="' . $resource['id'] . '">';
if (isset($resource['files'])) {
$return .= $this->write_resources_tree($resource['files'], $num +1);
}
$return .= '</div></div>';
} else {
if (!is_array($resource)) {
// It's a file.
$icon = choose_image($resource);
$position = strrpos($icon, '.');
$icon = substr($icon, 0, $position) . '_small.gif';
$file_info = explode('/', $resource);
$my_file_title = $file_info[0];
$my_file_name = $file_info[1];
//$return .= '<div><div style="margin-left:' . (($num +1) * 15) . 'px;margin-right:5px;"><a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $key . '&amp;lp_id=' . $this->lp_id . '"><img alt="" src="../img/' . $icon . '" title="" />&nbsp;' . $resource .'</a></div></div>';
// Show the "image name" not the filename of the image.
$return .= '<div class="doc_resource"><div style="margin-left:' . (($num +1) * 18) . 'px;margin-right:5px;"><a href="' . api_get_self() . '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $key . '&amp;lp_id=' . $this->lp_id . '"><img alt="" src="../img/' . $icon . '" title="" />&nbsp;' . $my_file_title . "</a></div></div>\r\n"; }
}
}
}
return $return;
$course_info = api_get_course_info();
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
$document_tree = DocumentManager::get_document_preview($course_info, $this->lp_id);
return $document_tree;
}
/**

@ -193,6 +193,30 @@ if (CONFVAL_showExtractInfo != SCRIPTVAL_UnderCourseList and $orderKey[0] != 'ke
Header
Include the HTTP, HTML headers plus the top banner.
*/
$url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=document_preview';
$htmlHeadXtra[] = '<script type="text/javascript">
$(document).ready( function() {
$(".document_preview").click(function() {
var my_id = this.id;
course_id = my_id.split("_")[2];
$.ajax({
url: "'.$url.'",
data: "course_id="+course_id,
success: function(return_value) {
$("#document_result_" +course_id).html(return_value);
},
});
});
});
</script>';
Display :: display_header($nameTools);
/* MAIN CODE */
@ -426,7 +450,8 @@ if (is_array($courses_tree)) {
//}
echo Display::tag('span',$session_link. ' </span> <span style="padding-left: 10px; font-size: 90%; font-weight: normal;">'.$extra_info);
if (api_is_platform_admin()) {
echo '<div style="float:right;"><a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session['details']['id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),22).'</a></div>';
echo '<div style="float:right;"><a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session['details']['id'].'">'.
Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),22).'</a></div>';
}
echo '</li>';
if (api_get_setting('hide_courses_in_sessions') == 'false') {

Loading…
Cancel
Save