예제 #1
0
$show_learnpath = true;
api_protect_course_script();
$lp_id = intval($_GET['lp_id']);
$sessionId = api_get_session_id();
// Check if the learning path is visible for student - (LP requisites)
if (!api_is_platform_admin()) {
    if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($lp_id, api_get_user_id())) {
        api_not_allowed(true);
    }
}
// Checking visibility (eye icon)
$visibility = api_get_item_visibility(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id(), $sessionId);
if (!api_is_allowed_to_edit(false, true, false, false) && intval($visibility) == 0) {
    api_not_allowed(true);
}
$learnPath = learnpath::getCurrentLpFromSession();
if (empty($learnPath)) {
    api_not_allowed(true);
}
$debug = 0;
if ($debug) {
    error_log('------ Entering lp_view.php -------');
}
$learnPath->error = '';
$lp_item_id = $learnPath->get_current_item_id();
$lpType = $learnPath->get_type();
$course_code = api_get_course_id();
$course_id = api_get_course_int_id();
$user_id = api_get_user_id();
$platform_theme = api_get_setting('stylesheets');
// Platform's css.
예제 #2
0
 /**
  * @param array $course_info
  * @param bool $lp_id
  * @param string $target
  * @param int $session_id
  * @param bool $add_move_button
  * @param string $filter_by_folder
  * @param string $overwrite_url
  * @param bool $showInvisibleFiles
  * @param bool $showOnlyFolders
  * @param int $folderId
  * @return string
  */
 public static function get_document_preview($course_info, $lp_id = false, $target = '', $session_id = 0, $add_move_button = false, $filter_by_folder = null, $overwrite_url = null, $showInvisibleFiles = false, $showOnlyFolders = false, $folderId = false)
 {
     if (empty($course_info['real_id']) || empty($course_info['code']) || !is_array($course_info)) {
         return '';
     }
     $overwrite_url = Security::remove_XSS($overwrite_url);
     $user_id = api_get_user_id();
     $user_in_course = false;
     if (api_is_platform_admin()) {
         $user_in_course = true;
     }
     if (!$user_in_course) {
         if (CourseManager::is_course_teacher($user_id, $course_info['code'])) {
             $user_in_course = true;
         }
     }
     // Condition for the session
     $session_id = intval($session_id);
     if (!$user_in_course) {
         if (empty($session_id)) {
             if (CourseManager::is_user_subscribed_in_course($user_id, $course_info['code'])) {
                 $user_in_course = true;
             }
             // Check if course is open then we can consider that the student is registered to the course
             if (isset($course_info) && in_array($course_info['visibility'], array(2, 3))) {
                 $user_in_course = true;
             }
         } else {
             $user_status = SessionManager::get_user_status_in_course_session($user_id, $course_info['real_id'], $session_id);
             //is true if is an student, course session teacher or coach
             if (in_array($user_status, array('0', '2', '6'))) {
                 $user_in_course = true;
             }
         }
     }
     $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
     $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
     $condition_session = " AND (last.session_id = '{$session_id}' OR last.session_id = '0' OR last.session_id IS NULL)";
     $add_folder_filter = null;
     if (!empty($filter_by_folder)) {
         $add_folder_filter = " AND docs.path LIKE '" . Database::escape_string($filter_by_folder) . "%'";
     }
     // If we are in LP display hidden folder https://support.chamilo.org/issues/6679
     $lp_visibility_condition = null;
     if ($lp_id) {
         // $lp_visibility_condition = " OR filetype='folder'";
         if ($showInvisibleFiles) {
             $lp_visibility_condition .= ' OR last.visibility = 0';
         }
     }
     $showOnlyFoldersCondition = null;
     if ($showOnlyFolders) {
         //$showOnlyFoldersCondition = " AND docs.filetype = 'folder' ";
     }
     $folderCondition = " AND docs.path LIKE '/%' ";
     if (!api_is_allowed_to_edit()) {
         $protectedFolders = self::getProtectedFolderFromStudent();
         foreach ($protectedFolders as $folder) {
             $folderCondition .= " AND docs.path NOT LIKE '{$folder}' ";
         }
     }
     $parentData = [];
     if ($folderId !== false) {
         $parentData = self::get_document_data_by_id($folderId, $course_info['code']);
         if (!empty($parentData)) {
             $cleanedPath = $parentData['path'];
             $num = substr_count($cleanedPath, '/');
             $notLikeCondition = null;
             for ($i = 1; $i <= $num; $i++) {
                 $repeat = str_repeat('/%', $i + 1);
                 $notLikeCondition .= " AND docs.path NOT LIKE '" . Database::escape_string($cleanedPath . $repeat) . "' ";
             }
             $folderCondition = " AND\n                    docs.id <> {$folderId} AND\n                    docs.path LIKE '" . $cleanedPath . "/%'\n                    {$notLikeCondition}\n                ";
         } else {
             $folderCondition = " AND\n                docs.filetype = 'file' ";
         }
     }
     $levelCondition = null;
     if ($folderId === false) {
         $levelCondition = " AND docs.path NOT LIKE'/%/%'";
     }
     $sql = "SELECT last.visibility, docs.*\n                FROM {$tbl_item_prop} AS last INNER JOIN {$tbl_doc} AS docs\n                ON (docs.id = last.ref AND docs.c_id = last.c_id)\n                WHERE\n                    docs.path NOT LIKE '%_DELETED_%' AND\n                    last.tool = '" . TOOL_DOCUMENT . "' {$condition_session} AND\n                    (last.visibility = '1' {$lp_visibility_condition}) AND\n                    last.visibility <> 2 AND\n                    docs.c_id = {$course_info['real_id']} AND\n                    last.c_id = {$course_info['real_id']}\n                    {$showOnlyFoldersCondition}\n                    {$folderCondition}\n                    {$levelCondition}\n                    {$add_folder_filter}\n                ORDER BY docs.filetype DESC, docs.title ASC";
     $res_doc = Database::query($sql);
     $resources = Database::store_result($res_doc, 'ASSOC');
     $return = '';
     if ($lp_id) {
         $learnPath = learnpath::getCurrentLpFromSession();
         if ($folderId === false) {
             $return .= '<div class="lp_resource_element">';
             $return .= Display::return_icon('new_doc.gif', '', array(), ICON_SIZE_SMALL);
             $return .= Display::url(get_lang('NewDocument'), api_get_self() . '?' . api_get_cidreq() . '&action=add_item&type=' . TOOL_DOCUMENT . '&lp_id=' . $learnPath->lp_id);
             $return .= '</div>';
         }
     } else {
         $return .= Display::div(Display::url(Display::return_icon('close.png', get_lang('Close'), array(), ICON_SIZE_SMALL), ' javascript:void(0);', array('id' => 'close_div_' . $course_info['real_id'] . '_' . $session_id, 'class' => 'close_div')), array('style' => 'position:absolute;right:10px'));
     }
     // If you want to debug it, I advise you to do "echo" on the eval statements.
     $newResources = array();
     if (!empty($resources) && $user_in_course) {
         foreach ($resources as $resource) {
             $is_visible = self::is_visible_by_id($resource['id'], $course_info, $session_id, api_get_user_id());
             if (!$is_visible) {
                 continue;
             }
             $newResources[] = $resource;
         }
     }
     $label = get_lang('Documents');
     $documents = [];
     if ($folderId === false) {
         $documents[$label] = array('id' => 0, 'files' => $newResources);
     } else {
         if (!empty($parentData)) {
             $documents[$parentData['title']] = array('id' => intval($folderId), 'files' => $newResources);
         }
     }
     $write_result = self::write_resources_tree($course_info, $session_id, $documents, $lp_id, $target, $add_move_button, $overwrite_url, $folderId);
     $return .= $write_result;
     $img_path = api_get_path(WEB_IMG_PATH);
     if ($lp_id == false) {
         $url = api_get_path(WEB_AJAX_PATH) . 'lp.ajax.php?a=get_documents&url=' . $overwrite_url . '&lp_id=' . $lp_id . '&cidReq=' . $course_info['code'];
         $return .= "<script>\n            \$('.doc_folder').click(function() {\n                var realId = this.id;\n                var my_id = this.id.split('_')[2];\n                var tempId = 'temp_'+my_id;\n                \$('#res_'+my_id).show();\n\n                var tempDiv = \$('#'+realId).find('#'+tempId);\n                if (tempDiv.length == 0) {\n                    \$.ajax({\n                        async: false,\n                        type: 'GET',\n                        url:  '" . $url . "',\n                        data: 'folder_id='+my_id,\n                        success: function(data) {\n                            \$('#'+realId).append('<div id='+tempId+'>'+data+'</div>');\n                        }\n                    });\n                }\n            });\n\n            \$('.close_div').click(function() {\n                var course_id = this.id.split('_')[2];\n                var session_id = this.id.split('_')[3];\n                \$('#document_result_'+course_id+'_'+session_id).hide();\n                \$('.lp_resource').remove();\n                \$('.document_preview_container').html('');\n            });\n\n            </script>";
     } else {
         //For LPs
         $url = api_get_path(WEB_AJAX_PATH) . 'lp.ajax.php?a=get_documents&lp_id=' . $lp_id . '&' . api_get_cidreq();
         $return .= "<script>\n\n            function testResources(id, img) {\n                var numericId = id.split('_')[1];\n                var parentId = 'doc_id_'+numericId;\n                var tempId = 'temp_'+numericId;\n                var image = \$('#'+img);\n\n                if (image.hasClass('open')) {\n                    image.removeClass('open');\n                    image.attr('src', '" . $img_path . "nolines_plus.gif');\n                    \$('#'+id).show();\n                    \$('#'+tempId).hide();\n                } else {\n                    image.addClass('open');\n                    image.attr('src', '" . $img_path . "nolines_minus.gif');\n                    \$('#'+id).hide();\n                    \$('#'+tempId).show();\n\n                    var tempDiv = \$('#'+parentId).find('#'+tempId);\n                    if (tempDiv.length == 0) {\n                        \$.ajax({\n                            type: 'GET',\n                            async: false,\n                            url:  '" . $url . "',\n                            data: 'folder_id='+numericId,\n                            success: function(data) {\n                                tempDiv = \$('#doc_id_'+numericId).append('<div id='+tempId+'>'+data+'</div>');\n                            }\n                        });\n                    }\n                }\n            }\n            </script>";
     }
     if (!$user_in_course) {
         $return = '';
     }
     return $return;
 }
예제 #3
0
 * @author   Yannick Warnier <*****@*****.**> (extended and maintained - 2005-2014)
 * @version  v 1.2
 * @access   public
 * @package  chamilo.learnpath.scorm
 */
// If you open the imsmanifest.xml via local machine (f.ex.: file://c:/...), then the Apiwrapper.js
// of Maritime Navigation when trying to execute this row
//    var result = api.LMSInitialize("");
// get the error response : you are not authorized to call this function
// Flag to allow for anonymous user - needs to be set before global.inc.php.
$use_anonymous = true;
//require_once '../inc/global.inc.php';
\Chamilo\CoreBundle\Framework\Container::$legacyTemplate = 'layout_empty.html.twig';
$file = Session::read('file');
/** @var learnpath $oLP */
$oLP = learnpath::getCurrentLpFromSession();
/** @var learnpathItem $oItem */
$oItem = isset($oLP->items[$oLP->current]) ? $oLP->items[$oLP->current] : null;
if (!is_object($oItem)) {
    error_log('New LP - scorm_api - Could not load oItem item', 0);
    exit;
}
$autocomplete_when_80pct = 0;
$user = api_get_user_info();
$userId = api_get_user_id();
header('Content-type: text/javascript');
?>
var scorm_logs=<?php 
echo (empty($oLP->scorm_debug) or !api_is_course_admin() && !api_is_platform_admin()) ? '0' : '3';
?>
; //debug log level for SCORM. 0 = none, 1=light, 2=a lot, 3=all - displays logs in log frame