예제 #1
0
 public function resolve(ResourceLocator $locator)
 {
     if ($locator->hasResourceId()) {
         $context = Claro_Context::getCurrentContext();
         $context[CLARO_CONTEXT_COURSE] = $locator->getCourseId();
         if ($locator->inGroup()) {
             $context[CLARO_CONTEXT_GROUP] = $locator->getGroupId();
         }
         $path = get_path('coursesRepositorySys') . claro_get_course_path($locator->getCourseId());
         // in a group
         if ($locator->inGroup()) {
             $groupData = claro_get_group_data($context);
             $path .= '/group/' . $groupData['directory'];
             $groupId = $locator->getGroupId();
         } else {
             $path .= '/document';
         }
         $path .= '/' . ltrim($locator->getResourceId(), '/');
         $resourcePath = '/' . ltrim($locator->getResourceId(), '/');
         $path = secure_file_path($path);
         if (!file_exists($path)) {
             throw new Exception("Resource not found {$path}");
         } elseif (is_dir($path)) {
             $url = new Url(get_module_entry_url('CLDOC'));
             $url->addParam('cmd', 'exChDir');
             $url->addParam('file', base64_encode($resourcePath));
             return $url->toUrl();
         } else {
             return get_module_url('CLDOC') . '/connector/cllp.frames.cnr.php';
             return claro_get_file_download_url($resourcePath, Claro_Context::getUrlContext($context));
         }
     } else {
         return get_module_entry_url('CLDOC');
     }
 }
예제 #2
0
 /**
  * Build the file path of a textzone in a given context
  *
  * @param string $key
  * @param array $context specify the context to build the path.
  * @param array $right specify an array of right to specify the file
  * @return file path
  */
 public static function get_textzone_file_path($key, $context = null, $right = null)
 {
     $textZoneFile = null;
     $key .= '.';
     if (!is_null($right) && is_array($right)) {
         foreach ($right as $context => $rightInContext) {
             if (is_array($rightInContext)) {
                 $key .= $context . '_';
                 foreach ($rightInContext as $rightName => $rightValue) {
                     if (is_bool($rightValue)) {
                         $key .= $rightValue ? $rightName : 'not_' . $rightName;
                     } else {
                         $key .= $rightName . '_' . $rightValue;
                     }
                     $key .= '.';
                 }
             }
         }
     }
     if (is_array($context) && array_key_exists(CLARO_CONTEXT_COURSE, $context)) {
         if (is_array($context) && array_key_exists(CLARO_CONTEXT_GROUP, $context)) {
             $textZoneFile = get_conf('coursesRepositorySys') . claro_get_course_group_path($context) . '/textzone/' . $key . 'inc.html';
         } else {
             $textZoneFile = get_conf('coursesRepositorySys') . claro_get_course_path($context[CLARO_CONTEXT_COURSE]) . '/textzone/' . $key . 'inc.html';
         }
     }
     if (is_null($textZoneFile)) {
         $textZoneFile = get_path('rootSys') . 'platform/textzone/' . $key . 'inc.html';
     }
     pushClaroMessage($textZoneFile);
     return $textZoneFile;
 }
예제 #3
0
 public function getFilePath($requestedUrl)
 {
     if (claro_is_in_a_course()) {
         $intermediatePath = get_path('coursesRepositorySys') . claro_get_course_path() . '/document';
     } else {
         $intermediatePath = rtrim(str_replace('\\', '/', get_path('rootSys')), '/') . '/platform/document';
     }
     if (get_conf('secureDocumentDownload') && $GLOBALS['is_Apache']) {
         // pretty url
         $path = realpath($intermediatePath . '/' . $requestedUrl);
     } else {
         // TODO check if we can remove rawurldecode
         $path = $intermediatePath . implode('/', array_map('rawurldecode', explode('/', $requestedUrl)));
     }
     return $path;
 }
예제 #4
0
파일: linker.cnr.php 프로젝트: rhertzog/lcs
 protected function getPath($locator)
 {
     $path = get_path('coursesRepositorySys') . claro_get_course_path($locator->getCourseId());
     // $groupId = null;
     // in a group
     if ($locator->inGroup()) {
         $groupData = claro_get_group_data(array(CLARO_CONTEXT_COURSE => $locator->getCourseId(), CLARO_CONTEXT_GROUP => $locator->getGroupId()));
         $path .= '/group/' . $groupData['directory'];
         // $groupId = $locator->getGroupId();
     } else {
         $path .= '/document';
     }
     if ($locator->hasResourceId()) {
         $path .= '/' . ltrim($locator->getResourceId(), '/');
     }
     $path = secure_file_path($path);
     return $path;
 }
예제 #5
0
/**
 * CLAROLINE
 *
 * @version     $Revision: 13511 $
 * @copyright   (c) 2001-2011, Universite catholique de Louvain (UCL)
 * @license     http://www.gnu.org/copyleft/gpl.html (GPL) GENERAL PUBLIC LICENSE
 * @author      Piraux S�bastien <*****@*****.**>
 * @author      Lederer Guillaume <*****@*****.**>
 * @package     CLLNP
 * @since       1.8
 */
function lp_display_document($TABLEASSET)
{
    // document browser vars
    // Update infos about asset
    $sql = "SELECT `path`\n          FROM `" . $TABLEASSET . "`\n          WHERE `module_id` = " . (int) $_SESSION['module_id'];
    $assetPath = claro_sql_query_get_single_value($sql);
    $courseDir = claro_get_course_path() . '/document';
    $baseWorkDir = get_path('coursesRepositorySys') . $courseDir;
    $file = $baseWorkDir . $assetPath;
    $fileSize = format_file_size(filesize($file));
    $fileDate = format_date(filectime($file));
    //####################################################################################\\
    //######################## DISPLAY DETAILS ABOUT THE DOCUMENT ########################\\
    //####################################################################################\\
    $out = '';
    $out .= "\n\n" . '<hr noshade="noshade" size="1" />' . "\n\n" . '<h4>' . get_lang('Document in module') . '</h4>' . "\n\n" . '<table class="claroTable" width="100%" border="0" cellspacing="2">' . "\n" . '<thead>' . "\n" . '<tr class="headerX">' . "\n" . '<th>' . get_lang('Filename') . '</th>' . "\n" . '<th>' . get_lang('Size') . '</th>' . "\n" . '<th>' . get_lang('Date') . '</th>' . "\n" . '</tr>' . "\n" . '</thead>' . "\n" . '<tbody>' . "\n" . '<tr align="center">' . "\n" . '<td align="left">' . basename($file) . '</td>' . "\n" . '<td>' . $fileSize . '</td>' . "\n" . '<td>' . $fileDate . '</td>' . "\n" . '</tr>' . "\n" . '</tbody>' . "\n" . '</table>' . "\n";
    return $out;
}
 function getSingleResource($args)
 {
     $tlabelReq = 'MOBILE';
     $thisFile = isset($args['resID']) ? $args['resID'] : null;
     $cid = claro_get_current_course_id();
     if (is_null($cid) || is_null($thisFile)) {
         throw new InvalidArgumentException('Missing cid or resourceId argument!');
     }
     if (claro_is_course_allowed()) {
         /* INITIALISATION
         		 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
         $tableName = get_module_main_tbl(array('mobile_tokens'));
         $tableName = $tableName['mobile_tokens'];
         $limit = 5;
         $baseWorkDir = get_path('coursesRepositorySys') . claro_get_course_path($cid) . '/document';
         if (is_dir($baseWorkDir . $thisFile) || is_file($baseWorkDir . $thisFile)) {
             if (is_dir($baseWorkDir . $thisFile)) {
                 if ($is_allowedToEdit || get_conf('cldoc_allowNonManagersToDownloadFolder', true) || get_conf('cldoc_allowNonManagersToDownloadFolder', true) && get_conf('cldoc_allowAnonymousToDownloadFolder', true)) {
                     /*
                      * PREPARE THE FILE COLLECTION
                      */
                     if (!$is_allowedToEdit) {
                         // Build an exclude file list to prevent simple user
                         // to see document contained in "invisible" directories
                         $searchExcludeList = getInvisibleDocumentList($baseWorkDir);
                     } else {
                         $searchExcludeList = array();
                     }
                     $filePathList = claro_search_file(search_string_to_pcre(''), $baseWorkDir . $thisFile, true, 'FILE', $searchExcludeList);
                     /*
                      * BUILD THE ZIP ARCHIVE
                      */
                     require_once get_path('incRepositorySys') . '/lib/thirdparty/pclzip/pclzip.lib.php';
                     // Build archive in tmp course folder
                     $downloadArchivePath = get_conf('cldoc_customTmpPath', '');
                     if (empty($downloadArchivePath)) {
                         $downloadArchivePath = get_path('coursesRepositorySys') . claro_get_course_path() . '/tmp/zip';
                         $downloadArchiveFile = $downloadArchivePath . '/' . uniqid('') . '.zip';
                     } else {
                         $downloadArchiveFile = rtrim($downloadArchivePath, '/') . '/' . claro_get_current_course_id() . '_CLDOC_' . uniqid('') . '.zip';
                     }
                     if (!is_dir($downloadArchivePath)) {
                         mkdir($downloadArchivePath, CLARO_FILE_PERMISSIONS, true);
                     }
                     $downloadArchive = new PclZip($downloadArchiveFile);
                     $downloadArchive->add($filePathList, PCLZIP_OPT_REMOVE_PATH, $baseWorkDir . $thisFile);
                     if (file_exists($downloadArchiveFile)) {
                         $pathInfo = $downloadArchiveFile;
                     } else {
                         throw new RuntimeException('Internal Server Error', 500);
                     }
                 } else {
                     throw new RuntimeException('Not allowed', 403);
                 }
             } elseif (is_file($baseWorkDir . $thisFile)) {
                 require_once get_path('incRepositorySys') . '/lib/file/downloader.lib.php';
                 Claroline::getInstance()->notification->addListener('download', 'trackInCourse');
                 $connectorPath = secure_file_path(get_module_path($tlabelReq) . '/connector/downloader.cnr.php');
                 require_once $connectorPath;
                 $className = $tlabelReq . '_Downloader';
                 $downloader = new $className($tlabelReq, $cid, claro_get_current_user_id());
                 if ($downloader && $downloader->isAllowedToDownload($thisFile)) {
                     $pathInfo = $downloader->getFilePath($thisFile);
                     $pathInfo = secure_file_path($pathInfo);
                     // Check if path exists in course folder
                     if (!file_exists($pathInfo) || is_dir($pathInfo)) {
                         throw new RuntimeException('Resource not found', 404);
                     }
                 } else {
                     throw new RuntimeException('Not allowed', 403);
                 }
             }
             for ($result = $try = 0; $try < $limit && $result < 1; $try++) {
                 /* Create token and register into the db. Retry until the registration complete or fail $limit times.
                 		 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
                 $token = bin2hex(openssl_random_pseudo_bytes(15));
                 $sql = 'REPLACE INTO `' . $tableName . '` (`userId`, `token`, `requestedPath`, `requestTime`, `wasFolder`, `canRetry`) ' . 'VALUES (\'' . claro_get_current_user_id() . '\', \'' . $token . '\', \'' . claro_sql_escape($pathInfo) . '\', NOW(), \'' . (is_dir($baseWorkDir . $thisFile) ? 1 : 0) . '\' , \'' . (isset($args['platform']) && $args['platform'] == 'WP' ? 1 : 0) . '\');';
                 $result = Claroline::getDatabase()->exec($sql);
             }
             $response['token'] = $try == $limit ? null : $token;
             return $response;
         } else {
             throw new RuntimeException('Resource not found', 404);
         }
     } else {
         throw new RuntimeException('Not allowed', 403);
     }
 }
예제 #7
0
 /**
  * builds required paths and sets values in assigDirSys and assigDirWeb
  *
  * @author Sebastien Piraux <*****@*****.**>
  */
 protected function buildDirPaths()
 {
     $this->assigDirSys = get_conf('coursesRepositorySys') . claro_get_course_path() . '/' . 'work/assig_' . $this->id . '/';
     $this->assigDirWeb = get_conf('coursesRepositoryWeb') . claro_get_course_path() . '/' . 'work/assig_' . $this->id . '/';
 }
예제 #8
0
파일: export.php 프로젝트: rhertzog/lcs
 }
 $results = claro_sql_query_fetch_all($sql);
 if (is_array($results) && !empty($results)) {
     $previousAuthors = '';
     $i = 1;
     foreach ($results as $row => $result) {
         //create assignment directory if necessary
         if ($assignmentId == 0) {
             if (!is_dir($zipPath . '/' . get_lang('Assignment') . '_' . $result['assignment_id'] . '/')) {
                 mkdir($zipPath . '/' . get_lang('Assignment') . '_' . $result['assignment_id'] . '/', CLARO_FILE_PERMISSIONS, true);
             }
             $assigDir = '/' . get_lang('Assignment') . '_' . $result['assignment_id'] . '/';
         } else {
             $assigDir = '';
         }
         $assignmentPath = get_path('coursesRepositorySys') . claro_get_course_path(claro_get_current_course_id()) . '/work/assig_' . (int) $result['assignment_id'] . '/';
         //  count author's submissions for the name of directory
         if ($result['authors'] != $previousAuthors) {
             $i = 1;
             $previousAuthors = $result['authors'];
         } else {
             $i++;
         }
         $authorsDir = replace_dangerous_char($result['authors']) . '/';
         if (!is_dir($zipPath . $assigDir . '/' . $authorsDir)) {
             mkdir($zipPath . $assigDir . '/' . $authorsDir, CLARO_FILE_PERMISSIONS, true);
         }
         if ($downloadScore && !(isset($currAssigId) && $currAssigId == $result['assignment_id'])) {
             $course = new Claro_Course(claro_get_current_course_id());
             $course->load();
             $assignment = new Assignment();
예제 #9
0
function build_rss($context)
{
    if (is_array($context) && count($context) > 0) {
        $rss = new UniversalFeedCreator();
        if (array_key_exists(CLARO_CONTEXT_COURSE, $context)) {
            // $rssFilePath .= $context[CLARO_CONTEXT_COURSE] . '.';
            $_course = claro_get_course_data($context[CLARO_CONTEXT_COURSE]);
            $rss->title = '[' . get_conf('siteName') . '] ' . $_course['officialCode'];
            $rss->description = $_course['name'];
            $rss->editor = $_course['titular'] == '' ? get_conf('administrator_name') : $_course['titular'];
            $rss->editorEmail = $_course['email'] == '' ? get_conf('administrator_email') : $_course['email'];
            $rss->link = get_path('rootWeb') . get_path('coursesRepositoryAppend') . claro_get_course_path();
            $rss->generator = 'Feedcreator';
            if (array_key_exists(CLARO_CONTEXT_GROUP, $context)) {
                // $rssFilePath .= 'g'.$context[CLARO_CONTEXT_GROUP] . '.';
                $rss->title .= '[' . get_lang('Group') . $context[CLARO_CONTEXT_GROUP] . ']';
                $rss->description .= get_lang('Group') . $context[CLARO_CONTEXT_GROUP];
            }
        } else {
            $rss->title = '[' . get_conf('siteName') . '] ' . $_course['officialCode'];
            $rss->description = $_course['name'];
            $rss->editor = get_conf('administrator_name');
            $rss->editorEmail = get_conf('administrator_email');
            $rss->link = get_path('rootWeb');
        }
        $rss->language = get_locale('iso639_1_code');
        $rss->docs = 'http://blogs.law.harvard.edu/tech/rss';
        $rss->pubDate = date("r", time());
        $toolLabelList = rss_get_tool_compatible_list();
        //var_dump($toolLabelList);
        $rssItems = array();
        foreach ($toolLabelList as $toolLabel) {
            /*var_dump(is_tool_activated_in_course(
                  get_tool_id_from_module_label( $toolLabel ),
                  $context[CLARO_CONTEXT_COURSE]
              ));*/
            if (is_tool_activated_in_course(get_tool_id_from_module_label($toolLabel), $context[CLARO_CONTEXT_COURSE])) {
                if (!is_module_installed_in_course($toolLabel, $context[CLARO_CONTEXT_COURSE])) {
                    install_module_in_course($toolLabel, $context[CLARO_CONTEXT_COURSE]);
                }
                $rssToolLibPath = get_module_path($toolLabel) . '/connector/rss.write.cnr.php';
                $rssToolFuncName = $toolLabel . '_write_rss';
                if (file_exists($rssToolLibPath)) {
                    include_once $rssToolLibPath;
                    if (function_exists($rssToolFuncName)) {
                        $rssItems = array_merge($rssItems, call_user_func($rssToolFuncName, $context));
                    }
                }
            }
        }
        $sortDate = array();
        foreach ($rssItems as $key => $rssItem) {
            $sortDate[$key] = $rssItem['pubDate'];
        }
        // die(var_export($sortDate, true));
        array_multisort($sortDate, SORT_DESC, $rssItems);
        foreach ($rssItems as $rssItem) {
            $item = new FeedItem();
            $item->title = claro_utf8_encode($rssItem['title'], get_conf('charset'));
            $item->description = claro_utf8_encode($rssItem['description']);
            $item->category = $rssItem['category'];
            $item->guid = $rssItem['guid'];
            $item->link = $rssItem['link'];
            $item->date = $rssItem['pubDate'];
            $rss->addItem($item);
        }
        return $rss->outputFeed("RSS2.0");
    }
    return false;
}
예제 #10
0
파일: thumbnail.php 프로젝트: rhertzog/lcs
 * @author      Claroline Team <*****@*****.**>
 * @author      Frederic Minne <*****@*****.**>
 * @license     http://www.gnu.org/copyleft/gpl.html
 *              GNU GENERAL PUBLIC LICENSE version 2.0
 * @package     KERNEL
 */
require dirname(__FILE__) . '/../inc/claro_init_global.inc.php';
require_once get_path('includePath') . '/lib/thumbnails.lib.php';
require_once get_path('includePath') . '/lib/fileManage.lib.php';
require_once get_path('includePath') . '/lib/file.lib.php';
if (claro_is_in_a_group() && claro_is_group_allowed()) {
    $documentRootDir = get_path('coursesRepositorySys') . claro_get_course_path() . '/group/' . claro_get_current_group_data('directory');
    $thumbnailsDirectory = get_path('coursesRepositorySys') . claro_get_course_path() . '/tmp/thumbs/' . claro_get_current_group_data('directory');
} elseif (claro_is_in_a_course() && claro_is_course_allowed()) {
    $documentRootDir = get_path('coursesRepositorySys') . claro_get_course_path() . '/document';
    $thumbnailsDirectory = get_path('coursesRepositorySys') . claro_get_course_path() . '/tmp/thumbs';
} else {
    header('HTTP/1.1 403 Forbidden');
    exit;
}
$image = array_key_exists('img', $_REQUEST) ? secure_file_path($_REQUEST['img']) : null;
if (is_null($image)) {
    header('HTTP/1.1 403 Forbidden');
    exit;
}
$imagePath = $documentRootDir . $image;
if (file_exists($imagePath)) {
    list($width, $height, $type, $attr) = getimagesize($imagePath);
    $thumbWidth = 75;
    $newHeight = round($height * $thumbWidth / $width);
    $thumbnailer = new Thumbnailer($thumbnailsDirectory, $documentRootDir);
예제 #11
0
파일: rqmkhtml.php 프로젝트: rhertzog/lcs
    $parentPath = realpath($parentPath);
    $childPath = realpath($parentPath . $childPath);
    if ($childPath !== false) {
        // verify if the file exists and if the file is under parent path
        return preg_match('|^' . preg_quote($parentPath) . '|', $childPath);
    } else {
        return false;
    }
}
if (claro_is_in_a_group() && claro_is_group_allowed()) {
    $_group = claro_get_current_group_data();
    $courseDir = claro_get_course_path() . '/group/' . claro_get_current_group_data('directory');
    ClaroBreadCrumbs::getInstance()->prepend(get_lang('Documents and Links'), 'document.php');
    ClaroBreadCrumbs::getInstance()->prepend(get_lang('Groups'), '../group/group.php');
} else {
    $courseDir = claro_get_course_path() . '/document';
    ClaroBreadCrumbs::getInstance()->prepend(get_lang('Documents and Links'), 'document.php');
}
$noPHP_SELF = true;
$baseWorkDir = get_path('coursesRepositorySys') . $courseDir;
if (!empty($_REQUEST['cmd'])) {
    $cmd = $_REQUEST['cmd'];
} else {
    $cmd = null;
}
if (!empty($_REQUEST['cwd'])) {
    $cwd = $_REQUEST['cwd'];
} else {
    $cwd = '';
}
if (isset($_REQUEST['file'])) {
예제 #12
0
 * @author Claro Team <*****@*****.**>
 * @author Christophe Gesché <*****@*****.**>
 * @copyright   (c) 2001-2011, Universite catholique de Louvain (UCL)
 *
 */
// CLAROLINE INIT
$tlabelReq = 'CLCHT';
// required
require '../inc/claro_init_global.inc.php';
if (!claro_is_in_a_course() || !claro_is_course_allowed() && !claro_is_user_authenticated()) {
    die('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">' . "\n" . '<html>' . "\n" . '<head>' . "\n" . '<title>' . get_lang('Chat') . '</title>' . "\n" . '</head>' . "\n" . '<body>' . "\n" . "\n" . '<a href="./chat.php" >click</a>' . "\n" . '</body>' . "\n" . "\n");
}
/*============================================================================
        CONNECTION BLOC
============================================================================*/
$coursePath = get_path('coursesRepositorySys') . claro_get_course_path();
$courseId = claro_get_current_course_id();
$groupId = claro_get_current_group_id();
$_user = claro_get_current_user_data();
$_course = claro_get_current_course_data();
$_group = claro_get_current_group_data();
$is_allowedToManage = claro_is_course_manager();
$is_allowedToStore = claro_is_course_manager();
$is_allowedToReset = claro_is_course_manager();
if ($_user['firstName'] == '' && $_user['lastName'] == '') {
    $nick = get_lang('Anonymous');
} else {
    $nick = $_user['firstName'] . ' ' . $_user['lastName'];
    if (strlen($nick) > get_conf('max_nick_length')) {
        $nick = $_user['firstName'] . ' ' . $_user['lastName'][0] . '.';
    }
예제 #13
0
 /**
  * Constructor
  *
  * @copyright   (c) 2001-2011, Universite catholique de Louvain (UCL)
  */
 public function __construct()
 {
     $this->srcDirDocument = get_path('coursesRepositorySys') . claro_get_course_path() . '/document';
 }
예제 #14
0
/*======================================
       CLAROLINE MAIN
  ======================================*/
$out = '';
// display title
$out .= claro_html_tool_title($nameTools);
// display use explication text
$out .= get_block('blockModulePoolHelp') . "<br /><br />";
// HANDLE COMMANDS:
$cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
switch ($cmd) {
    // MODULE DELETE
    case "eraseModule":
        // used to physically delete the module  from server
        require_once get_path('incRepositorySys') . "/lib/fileManage.lib.php";
        $moduleDir = claro_get_course_path() . '/modules';
        $moduleWorkDir = get_path('coursesRepositorySys') . $moduleDir;
        // delete all assets of this module
        $sql = "DELETE\n                FROM `" . $TABLEASSET . "`\n                WHERE `module_id` = " . (int) $_REQUEST['cmdid'];
        claro_sql_query($sql);
        // delete from all learning path of this course but keep there id before
        $sql = "SELECT *\n                FROM `" . $TABLELEARNPATHMODULE . "`\n                WHERE `module_id` = " . (int) $_REQUEST['cmdid'];
        $result = claro_sql_query($sql);
        $sql = "DELETE\n                FROM `" . $TABLELEARNPATHMODULE . "`\n                WHERE `module_id` = " . (int) $_REQUEST['cmdid'];
        claro_sql_query($sql);
        // delete the module in modules table
        $sql = "DELETE\n                FROM `" . $TABLEMODULE . "`\n                WHERE `module_id` = " . (int) $_REQUEST['cmdid'];
        claro_sql_query($sql);
        //delete all user progression concerning this module
        $sql = "DELETE\n                FROM `" . $TABLEUSERMODULEPROGRESS . "`\n                WHERE 1=0 ";
        while ($list = mysql_fetch_array($result)) {
예제 #15
0
/**
 * Return the config ropisitory for a given context
 *
 * All platform config are stored in platform/conf/
 * But a course or a group can overide some config values
 *
 * This function return the repository ignoring if it's  existing or empty
 *
 * @param array $context
 * @return string
 */
function claro_get_conf_repository($context = array())
{
    if (!isset($context) || !is_array($context) || empty($context) || is_null($context)) {
        return get_path('rootSys') . 'platform/conf/';
    }
    if (array_key_exists(CLARO_CONTEXT_COURSE, $context)) {
        if (array_key_exists(CLARO_CONTEXT_GROUP, $context)) {
            return claro_get_course_group_path($context) . '/conf/';
        }
        return get_path('coursesRepositorySys') . claro_get_course_path($context[CLARO_CONTEXT_COURSE]) . '/conf/';
    }
    pushClaroMessage('Unknown context passed to claro_get_conf_repository : ' . var_export($context, 1), 'warning');
    return null;
}
예제 #16
0
파일: user_work.php 프로젝트: rhertzog/lcs
                } else {
                    // if the main thing to provide is a file and that no file was sent
                    $dialogBox->error(get_lang('Unable to copy file : %filename', array('%filename' => basename($submitGroupWorkUrl))));
                    $formCorrectlySent = false;
                }
            } elseif ($submission->getParentId() == 0) {
                // if the main thing to provide is a file and that no file was sent
                $dialogBox->error(get_lang('Field \'%name\' is required', array('%name' => get_lang('File'))));
                $formCorrectlySent = false;
            }
        } elseif ($assignmentContent == "TEXTFILE") {
            // attached file is optionnal if work type is TEXT AND FILE
            // so the attached file can be deleted only in this mode
            if (!is_null($submitGroupWorkUrl)) {
                $wrkForm['filename'] = $assignment->createUniqueFilename(basename($submitGroupWorkUrl) . '.url');
                create_link_file($assignment->getAssigDirSys() . $wrkForm['filename'], get_path('coursesRepositoryWeb') . claro_get_course_path() . '/' . $submitGroupWorkUrl);
            }
            // if delete of the file is required
            if (isset($_REQUEST['delAttacheDFile'])) {
                $wrkForm['filename'] = '';
                // empty DB field
                @unlink($assignment->getAssigDirSys() . $_REQUEST['currentWrkUrl']);
                // physically remove the file
            }
        }
    }
    // if($formCorrectlySent)
}
//end if($_REQUEST['submitWrk'])
/*============================================================================
                          ADMIN ONLY COMMANDS
예제 #17
0
 /**
  * Fetch info from the database
  *
  * @return False on error, true otherwise.
  * @author Amand Tihon <*****@*****.**>
  */
 public function fetch()
 {
     global $TABLELEARNPATH, $TABLELEARNPATHMODULE, $TABLEMODULE, $TABLEASSET;
     /* Get general infos about the learning path */
     $sql = 'SELECT `name`, `comment`
             FROM `' . $TABLELEARNPATH . '`
             WHERE `learnPath_id` = ' . $this->id;
     $result = claro_sql_query($sql);
     if (empty($result)) {
         $this->error[] = get_lang('Learning Path not found');
         return false;
     }
     $list = mysql_fetch_array($result, MYSQL_ASSOC);
     if (empty($list)) {
         $this->error[] = get_lang('Learning Path not found');
         return false;
     }
     $this->name = $list['name'];
     $this->comment = $list['comment'];
     /* Build various directories' names */
     // Replace ',' too, because pclzip doesn't support it.
     $this->destDir = get_path('coursesRepositorySys') . claro_get_course_path() . '/temp/' . str_replace(',', '_', replace_dangerous_char($this->name));
     $this->srcDirDocument = get_path('coursesRepositorySys') . claro_get_course_path() . '/document';
     $this->srcDirExercise = get_path('coursesRepositorySys') . claro_get_course_path() . '/exercise';
     $this->srcDirScorm = get_path('coursesRepositorySys') . claro_get_course_path() . '/scormPackages/path_' . $this->id;
     /* Now, get the complete list of modules, etc... */
     $sql = 'SELECT  LPM.`learnPath_module_id` ID, LPM.`lock`, LPM.`visibility`, LPM.`rank`,
                     LPM.`parent`, LPM.`raw_to_pass`, LPM.`specificComment` itemComment,
                     M.`name`, M.`contentType`, M.`comment` resourceComment, A.`path`
             FROM `' . $TABLELEARNPATHMODULE . '` AS LPM
             LEFT JOIN `' . $TABLEMODULE . '` AS M
                    ON LPM.`module_id` = M.`module_id`
             LEFT JOIN `' . $TABLEASSET . '` AS A
                    ON M.`startAsset_id` = A.`asset_id`
             WHERE LPM.`learnPath_id` = ' . $this->id . '
             ORDER BY LPM.`parent`, LPM.`rank`
            ';
     $result = claro_sql_query($sql);
     if (empty($result)) {
         $this->error = get_lang('Learning Path is empty');
         return false;
     }
     while ($module = mysql_fetch_array($result, MYSQL_ASSOC)) {
         // Check for SCORM content. If at least one module is SCORM, we need to export the existing SCORM package
         if ($module['contentType'] == 'SCORM') {
             $this->fromScorm = true;
         }
         // If it is an exercise, create a filename for it.
         if ($module['contentType'] == 'EXERCISE') {
             $module['fileName'] = 'quiz_' . $module['path'] . '.html';
         }
         // Only for clarity :
         $id = $module['ID'];
         $parent = $module['parent'];
         // Add to the flat resource map
         $this->resourceMap[$id] = $module;
         // Build Item tree, only keeping visible modules
         if ($module['visibility'] == 'SHOW') {
             if (!$parent) {
                 // parent is 0, item is at root
                 $this->itemTree[$id] =& $this->resourceMap[$id];
             } else {
                 /* item has a parent. Add it to the list of its children.
                    Note that references are used, not copies. */
                 $this->resourceMap[$parent]['children'][] =& $this->resourceMap[$id];
             }
         }
     }
     return true;
 }
예제 #18
0
파일: tools.php 프로젝트: rhertzog/lcs
    claro_die(get_lang('Not allowed'));
}
// Prepare menu for claro_html_tabs_bar
$sectionList = array('toolRights' => get_lang('Manage tool access rights'), 'extLinks' => get_lang('Manage external links'), 'toolList' => get_lang('Add or remove tools'));
$currentSection = isset($_REQUEST['section']) && in_array($_REQUEST['section'], array_keys($sectionList)) ? $_REQUEST['section'] : 'toolRights';
$htmlHeadXtra[] = '<script type="text/javascript">
function confirmation (name)
{
    if (confirm(\'' . clean_str_for_javascript(get_lang('Are you sure to delete')) . '\'+ name + \' ?\'))
        {return true;}
    else
        {return false;}
}
</script>';
$toolRepository = '../';
$currentCourseRepository = claro_get_course_path();
$dialogBox = new DialogBox();
//include course configuration file
include claro_get_conf_repository() . 'course_main.conf.php';
// Library
require_once get_path('incRepositorySys') . '/lib/course_home.lib.php';
require_once get_path('incRepositorySys') . '/lib/right/courseProfileToolAction.class.php';
require_once get_path('incRepositorySys') . '/lib/right/profileToolRightHtml.class.php';
require_once get_path('incRepositorySys') . '/lib/module/manage.lib.php';
/*
 * Language initialisation of the tool names
 */
$toolNameList = claro_get_tool_name_list();
/*============================================================================
 COMMAND SECTION
============================================================================*/
예제 #19
0
        $withFrames = true;
        break;
    case CTEXERCISE_:
        // clean session vars of exercise
        unset($_SESSION['serializedExercise']);
        unset($_SESSION['serializedQuestionList']);
        unset($_SESSION['exeStartTime']);
        $_SESSION['inPathMode'] = true;
        $startAssetpage = get_module_url('CLQWZ') . '/exercise_submit.php';
        $moduleStartAssetPage = $startAssetpage . '?exId=' . $assetPath;
        break;
    case CTSCORM_:
        // real scorm content method
        $startAssetPage = $assetPath;
        $modulePath = 'path_' . $_SESSION['path_id'];
        $moduleStartAssetPage = get_path('coursesRepositoryWeb') . claro_get_course_path() . '/scormPackages/' . $modulePath . $startAssetPage;
        break;
    case CTCLARODOC_:
        break;
}
// end switch
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
   "http://www.w3.org/TR/html4/frameset.dtd">
<html>

  <head>

<?php 
// add the update frame if this is a SCORM module
if ($module['contentType'] == CTSCORM_) {
예제 #20
0
 $out .= '<tr>' . "\n";
 // display the current module name (and link if allowed)
 $spacingString = '';
 for ($i = 0; $i < $module['children']; $i++) {
     $spacingString .= '<td>&nbsp;</td>';
 }
 $colspan = $maxDeep - $module['children'] + 1;
 // spacing col
 $out .= $spacingString . '<td colspan="' . $colspan . '"><small>';
 if (!$is_blocked) {
     if ($module['contentType'] == CTLABEL_) {
         $out .= '<b>' . claro_utf8_decode($module['name'], get_conf('charset')) . '</b>';
     } else {
         $useRedirectUrl = false;
         if ($module['contentType'] == 'DOCUMENT') {
             $pathInfo = get_path('coursesRepositorySys') . claro_get_course_path() . '/document/' . ltrim($module['path'], '/');
             $pathContents = file_get_contents($pathInfo);
             $extension = get_file_extension($pathInfo);
             if ($extension == 'url') {
                 //
                 $matches = array();
                 if (preg_match('/<meta http-equiv="refresh" content="0;url=(.*?)">/', $pathContents, $matches) && isset($matches[1])) {
                     $redirectionURL = $matches[1];
                     $useRedirectUrl = true;
                 }
             }
         }
         if (strlen($module['name']) > $moduleNameLength) {
             $displayedName = substr(claro_utf8_decode($module['name'], get_conf('charset')), 0, $moduleNameLength) . "...";
         } else {
             $displayedName = claro_utf8_decode($module['name'], get_conf('charset'));
예제 #21
0
 /**
  * Generate a file with all messages and copy it in the document tool
  *
  * @author Sebastien Piraux <*****@*****.**>
  * @return mixed filename if successfull, false if failed
  */
 function archive()
 {
     // Load CSS
     $cssPath = './css/clchat.css';
     $cssContent = '';
     if (file_exists($cssPath) && is_readable($cssPath)) {
         $cssContent = file_get_contents($cssPath);
     }
     // Prepare archive file content
     $htmlContentHeader = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">' . "\n" . '<html>' . "\n" . '<head>' . "\n" . '<title>' . get_lang('Chat') . '</title>' . (!empty($cssContent) ? '<style type="text/css">' . $cssContent . '</style>' : '') . '</head>' . "\n" . '<body>' . "\n\n";
     $htmlContentFooter = '</body>' . "\n\n" . '</html>' . "\n";
     $htmlContent = '<div id="clchat_chatarea" style="height: auto;">' . $this->render() . '</div>';
     $htmlContent = $htmlContentHeader . $htmlContent . $htmlContentFooter;
     // filepath
     $courseDir = claro_get_course_path() . '/document';
     $baseWorkDir = get_path('coursesRepositorySys') . $courseDir;
     // Try to determine a filename that does not exist anymore
     // in the directory where the chat file will be stored
     $chatDate = 'chat.' . date('Y.m.j-H.i.s') . '.html';
     $i = 1;
     //while ( file_exists($baseWorkDir.'/'.$chatDate.$i.'.html') ) $i++;
     $chatFilename = $baseWorkDir . '/' . $chatDate;
     $fp = fopen($chatFilename, 'w');
     if (fwrite($fp, $htmlContent)) {
         return $chatFilename;
     } else {
         return false;
     }
 }
예제 #22
0
 public function getFilePath($requestedUrl)
 {
     if (claro_is_in_a_course()) {
         $basePath = get_path('coursesRepositorySys') . claro_get_course_path(claro_get_current_course_id()) . '/' . $this->moduleLabel;
         if (claro_is_in_a_group()) {
             $basePath .= '/.group/' . claro_get_current_group_id();
         }
     } else {
         $basePath = get_path('rootSys') . 'platform/module_data/' . $this->moduleLabel;
     }
     return $basePath . '/' . $requestedUrl;
 }
예제 #23
0
 /**
  * Import users in course.
  *
  * @author Dimitri Rambout <*****@*****.**>
  * @param $courseId id of the course
  *
  * @return boolean
  */
 public function importUsersInCourse($userList, $courseId, $canCreateUser = true, $enrollUserInCourse = true, $class_id = 0, $sendEmail = 0)
 {
     if (empty($this->data)) {
         return false;
     }
     if (!(isset($userList) && count($userList))) {
         return false;
     }
     $logs = array();
     $tbl_mdb_names = claro_sql_get_main_tbl();
     $tbl_user = $tbl_mdb_names['user'];
     $tbl_course_user = $tbl_mdb_names['rel_course_user'];
     $tbl_cdb_names = claro_sql_get_course_tbl();
     $tbl_group_rel_team_user = $tbl_cdb_names['group_rel_team_user'];
     $groupsImported = array();
     $userInfo = array();
     foreach ($userList as $user_id) {
         if (!isset($this->data[$user_id])) {
             $logs['errors'][] = get_lang('Unable to find the user in the csv');
         } else {
             $userInfo['username'] = $this->data[$user_id]['username'];
             $userInfo['firstname'] = $this->data[$user_id]['firstname'];
             $userInfo['lastname'] = $this->data[$user_id]['lastname'];
             $userInfo['email'] = isset($this->data[$user_id]['email']) && !empty($this->data[$user_id]['email']) ? $this->data[$user_id]['email'] : '';
             $userInfo['password'] = isset($this->data[$user_id]['password']) && !empty($this->data[$user_id]['password']) ? $this->data[$user_id]['password'] : mk_password(8);
             $userInfo['officialCode'] = isset($this->data[$user_id]['officialCode']) ? $this->data[$user_id]['officialCode'] : '';
             if (isset($this->data[$user_id]['groupName'])) {
                 $groupNames = $this->data[$user_id]['groupName'];
             } else {
                 $groupNames = null;
             }
             //check user existe if not create is asked
             $resultSearch = user_search(array('username' => $userInfo['username']), null, true, true);
             if (empty($resultSearch)) {
                 if (!$canCreateUser) {
                     $userId = 0;
                     $logs['errors'][] = get_lang('Unable to create user %username, option is disabled in configuration', array('%username' => $userInfo['username']));
                 } else {
                     $userId = user_create($userInfo);
                     if ($userId != 0) {
                         $logs['success'][] = get_lang('User profile %username created successfully', array('%username' => $userInfo['username']));
                         if ($sendEmail) {
                             user_send_registration_mail($userId, $userInfo);
                         }
                     } else {
                         $logs['errors'][] = get_lang('Unable to create user %username', array('%username' => $userInfo['username']));
                     }
                 }
             } else {
                 $userId = $resultSearch[0]['uid'];
                 $logs['errors'][] = get_lang('User %username not created because it already exists in the database', array('%username' => $userInfo['username']));
             }
             if ($userId == 0) {
                 $logs['errors'][] = get_lang('Unable to add user %username in this course', array('%username' => $userInfo['username']));
             } else {
                 if (!$enrollUserInCourse) {
                     $logs['errors'][] = get_lang('Unable to add user %username in this course, option is disabled in configuration', array('%username' => $userInfo['username']));
                 } else {
                     if (!user_add_to_course($userId, $courseId, false, false, null)) {
                         $logs['errors'][] = get_lang('Unable to add user %username in this course', array('%username' => $userInfo['username']));
                     } else {
                         $logs['success'][] = get_lang('User %username added in course %courseId', array('%username' => $userInfo['username'], '%courseId' => $courseId));
                         //join class if needed
                         if ($class_id) {
                             if (!($return = user_add_to_class($userId, $class_id))) {
                                 $logs['errors'][] = get_lang('Unable to add %username in the selected class', array('%username' => $userInfo['username']));
                             } else {
                                 $logs['success'][] = get_lang('User %username added in the selected class', array('%username' => $userInfo['username']));
                             }
                         }
                         //join group
                         $groups = explode(',', $groupNames);
                         if (is_array($groups)) {
                             foreach ($groups as $group) {
                                 $group = trim($group);
                                 if (!empty($group)) {
                                     $groupsImported[$group][] = $userId;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     foreach ($groupsImported as $group => $users) {
         $GLOBALS['currentCourseRepository'] = claro_get_course_path($courseId);
         $groupId = create_group($group, null);
         if ($groupId == 0) {
             $logs['errors'][] = get_lang('Unable to create group %groupname', array('%groupname' => $group));
         } else {
             foreach ($users as $userId) {
                 $sql = "INSERT INTO `" . $tbl_group_rel_team_user . "`\n                            SET user = "******",\n                                team = " . (int) $groupId;
                 if (!claro_sql_query($sql)) {
                     $logs['errors'][] = get_lang('Unable to add user in group %groupname', array('%groupname' => $group));
                 }
             }
         }
     }
     return $logs;
 }
예제 #24
0
파일: wiki.php 프로젝트: rhertzog/lcs
         $message = get_lang("Invalid Wiki Id");
         $dialogBox->error($message);
         $action = 'error';
     } else {
         $wiki = $wikiStore->loadWiki($wikiId);
         $wikiTitle = $wiki->getTitle();
         $renderer = new WikiToSingleHTMLExporter($wiki);
         $contents = $renderer->export();
         if (0 != $groupId) {
             $groupPart = '_group' . (int) $groupId;
         } else {
             $groupPart = '';
         }
         require_once get_conf('includePath') . '/lib/fileUpload.lib.php';
         // TODO : use function wich return get_conf('coursesRepositorySys') . '/' . $_course['path']
         $exportDir = get_conf('coursesRepositorySys') . '/' . claro_get_course_path() . '/document';
         $exportFile = replace_dangerous_char($wikiTitle, 'strict') . $groupPart;
         $i = 1;
         while (file_exists($exportDir . '/' . $exportFile . '_' . $i . '.html')) {
             $i++;
         }
         $wikiFileName = $exportFile . '_' . $i . '.html';
         $exportPath = $exportDir . '/' . $wikiFileName;
         file_put_contents($exportPath, $contents);
     }
     break;
 case 'exSearch':
     require_once "lib/class.wikisearchengine.php";
     $pattern = isset($_REQUEST['searchPattern']) ? trim($_REQUEST['searchPattern']) : null;
     if (!empty($pattern)) {
         $searchEngine = new WikiSearchEngine($con, $config);
예제 #25
0
        if ($array1[$i] != $array2[$i]) {
            return false;
        }
    }
    return true;
}
/*======================================
       CLAROLINE MAIN
  ======================================*/
// main page
$out .= claro_html_tool_title(get_lang('Import a learning path'));
// init msg arays
$okMsgs = array();
$errorMsgs = array();
$maxFilledSpace = get_conf('maxFilledSpace_for_import', 100000000);
$courseDir = claro_get_course_path() . '/scormPackages/';
$baseWorkDir = get_path('coursesRepositorySys') . $courseDir;
// path_id
// handle upload
// if the post is done a second time, the claroformid mecanism
// will set $_POST to NULL, so we need to check it
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !is_null($_POST)) {
    // arrays used to store inserted ids in case
    // will be used to build delete queries for mysql < 4.0.0
    $insertedModule_id = array();
    $insertedAsset_id = array();
    $lpName = get_lang('Unnamed path');
    // we need a new path_id for this learning path so we prepare a line in DB
    // this line will be removed if an error occurs
    $sql = "SELECT MAX(`rank`)\n            FROM `" . $TABLELEARNPATH . "`";
    $result = claro_sql_query($sql);
예제 #26
0
파일: document.php 프로젝트: rhertzog/lcs
                    } else {
                        $out .= '<a href="' . claro_htmlspecialchars(Url::Contextualize($_SERVER['PHP_SELF'] . '?cmd=exChVis&amp;file=' . $cmdFileName . '&amp;vis=i')) . '">' . '<img src="' . get_icon_url('visible') . '" alt="' . get_lang('Make invisible') . '" />' . '</a>';
                    }
                }
                $out .= '</td>' . "\n";
            }
            // end if($is_allowedToEdit)
            $out .= '</tr>' . "\n";
            /* COMMENTS */
            if ($thisFile['comment'] != '') {
                $thisFile['comment'] = claro_htmlspecialchars($thisFile['comment']);
                $thisFile['comment'] = claro_parse_user_text($thisFile['comment']);
                $out .= '<tr align="left">' . "\n" . '<td colspan="' . $colspan . '">' . '<div class="comment">' . $thisFile['comment'] . '</div>' . '</td>' . "\n" . '</tr>' . "\n";
            }
        }
        // end each ($fileList)
    } else {
        $out .= '<tr align="left">' . "\n" . '<td colspan="' . $colspan . '">' . '<div class="comment">' . get_lang('Nothing to display') . '</div>' . '</td>' . "\n" . '</tr>';
    }
    $out .= '</tbody>' . "\n" . '</table>' . "\n";
}
// END ELSE VIEW IMAGE
$claroline->display->body->appendContent($out);
echo $claroline->display->render();
// call the garbage collector to remove temporary files
$tmpZipPath = get_conf('cldoc_customTmpPath', '');
if (empty($tmpZipPath)) {
    $tmpZipPath = get_path('coursesRepositorySys') . claro_get_course_path() . '/tmp/zip';
}
$gc = new ClaroGarbageCollector($tmpZipPath, 3600);
$gc->run();
예제 #27
0
             break ;
             }
             }
     
             */
     //------------------------------------------------------------------------
 } else {
     $out .= '<td align="left">' . '<img src="' . get_icon_url('learnpath') . '" alt="" />' . $list['name'] . $list['minRaw'] . '</td>' . "\n";
 }
 // DISPLAY ADMIN LINK-----------------------------------------------------------
 if ($is_allowedToEdit) {
     // 5 administration columns
     // Modify command / go to other page
     $out .= '<td>' . "\n" . '<a href="' . claro_htmlspecialchars(Url::Contextualize('learningPathAdmin.php?path_id=' . $list['learnPath_id'])) . '">' . "\n" . '<img src="' . get_icon_url('edit') . '" alt="' . get_lang('Modify') . '" />' . "\n" . '</a>' . '</td>' . "\n";
     // DELETE link
     $real = realpath(get_path('coursesRepositorySys') . claro_get_course_path() . '/scormPackages/path_' . $list['learnPath_id']);
     // check if the learning path is of a Scorm import package and add right popup:
     if (is_dir($real)) {
         $out .= '<td>' . "\n" . '<a href="' . claro_htmlspecialchars(Url::Contextualize($_SERVER['PHP_SELF'] . '?cmd=delete&del_path_id=' . $list['learnPath_id'])) . '" ' . ' onclick="return scormConfirmation(\'' . clean_str_for_javascript($list['name']) . '\');">' . "\n" . '<img src="' . get_icon_url('delete') . '" alt="' . get_lang('Delete') . '" />' . "\n" . '</a>' . "\n" . '</td>' . "\n";
     } else {
         $out .= '<td>' . "\n" . '<a href="' . claro_htmlspecialchars(Url::Contextualize($_SERVER['PHP_SELF'] . '?cmd=delete&del_path_id=' . $list['learnPath_id'])) . '" ' . 'onclick="return confirmation(\'' . clean_str_for_javascript($list['name']) . '\');">' . "\n" . '<img src="' . get_icon_url('delete') . '" alt="' . get_lang('Delete') . '" />' . "\n" . '</a>' . "\n" . '</td>' . "\n";
     }
     // LOCK link
     $out .= "<td>";
     if ($list['lock'] == 'OPEN') {
         $out .= '<a href="' . claro_htmlspecialchars(Url::Contextualize($_SERVER['PHP_SELF'] . '?cmd=mkBlock' . '&cmdid=' . $list['learnPath_id'])) . '">' . "\n" . '<img src="' . get_icon_url('unblock') . '" ' . 'alt="' . get_lang('Block') . '" />' . "\n" . '</a>' . "\n";
     } else {
         $out .= '<a href="' . claro_htmlspecialchars(Url::Contextualize($_SERVER['PHP_SELF'] . '?cmd=mkUnblock&cmdid=' . $list['learnPath_id'])) . '">' . "\n" . '<img src="' . get_icon_url('block') . '" alt="' . get_lang('Unblock') . '" />' . "\n" . '</a>' . "\n";
     }
     $out .= '</td>' . "\n" . '<td>' . "\n";
     if ($list['visibility'] == 'HIDE') {
예제 #28
0
파일: image.php 프로젝트: rhertzog/lcs
require_once get_path('incRepositorySys') . '/lib/image.lib.php';
/*
 * Permissions
 */
if (claro_is_in_a_course() && !claro_is_in_a_group()) {
    // course context
    $is_allowedToEdit = claro_is_allowed_to_edit();
    $pathSys = get_path('coursesRepositorySys') . claro_get_course_path() . '/document/';
    $pathWeb = get_path('coursesRepositoryWeb') . claro_get_course_path() . '/document/';
    require claro_get_conf_repository() . 'CLDOC.conf.php';
    $maxFilledSpace = get_conf('maxFilledSpace_for_course');
} elseif (claro_is_in_a_group()) {
    // course context
    $is_allowedToEdit = claro_is_allowed_to_edit();
    $pathSys = get_path('coursesRepositorySys') . claro_get_course_path() . '/group/' . claro_get_current_group_data('directory');
    $pathWeb = get_path('coursesRepositoryWeb') . claro_get_course_path() . '/group/' . claro_get_current_group_data('directory');
    require claro_get_conf_repository() . 'CLDOC.conf.php';
    $maxFilledSpace = get_conf('maxFilledSpace_for_course');
} else {
    // platform context
    $is_allowedToEdit = claro_is_platform_admin();
    $pathSys = get_path('rootSys') . 'platform/document/';
    $pathWeb = get_path('rootWeb') . 'platform/document/';
}
/*
 * Libraries
 */
include_once $includePath . '/lib/fileUpload.lib.php';
include_once $includePath . '/lib/fileManage.lib.php';
/*
 * Init directory
예제 #29
0
function chat_upgrade_to_19($course_code)
{
    global $currentCourseVersion;
    $versionRequiredToProceed = '/^1.8/';
    $tool = 'CLCHT';
    $currentCourseDbNameGlu = claro_get_course_db_name_glued($course_code);
    if (preg_match($versionRequiredToProceed, $currentCourseVersion)) {
        $coursePath = get_path('coursesRepositorySys') . claro_get_course_path($course_code);
        $courseChatPath = $coursePath . '/chat/';
        $toolId = get_tool_id_from_module_label('CLCHAT');
        if (!$toolId) {
            // get out of here if new chat module is missing
            log_message('New Chat module not found : keep the old one !');
            $step = set_upgrade_status($tool, 0, $course_code);
            return $step;
        }
        // On init , $step = 1
        switch ($step = get_upgrade_status($tool, $course_code)) {
            case 1:
                // get all chat files
                log_message("Search in " . $courseChatPath);
                if (!file_exists($courseChatPath)) {
                    log_message("Cannot save chat : folder {$courseChatPath} does not exists");
                    $error = true;
                } else {
                    try {
                        $it = new DirectoryIterator($courseChatPath);
                        $error = false;
                        foreach ($it as $file) {
                            if (!$file->isFile()) {
                                continue;
                            }
                            if ($file->getFilename() == $course_code . '.chat.html') {
                                // chat de cours
                                log_message("Try to export course chat : " . $file->getFilename());
                                $exportFileDir = $coursePath . '/document/recovered_chat/';
                                $groupId = null;
                            } else {
                                // group chat
                                log_message("Try to export group chat : " . $file->getFilename());
                                // get groupId
                                $matches = array();
                                preg_match('/\\w+\\.(\\d+)\\.chat\\.html/', $file->getFilename(), $matches);
                                if (isset($matches[1])) {
                                    $groupId = (int) $matches[1];
                                } else {
                                    log_message('Cannot find group id in chat filename : ' . $file->getFilename());
                                    break;
                                }
                                if (!($groupData = claro_get_group_data(array(CLARO_CONTEXT_COURSE => $course_code, CLARO_CONTEXT_GROUP => $groupId)))) {
                                    // group cannot be found, save in document
                                    $exportFileDir = $coursePath . '/document/recovered_chat/';
                                    log_message('Cannot find group so save chat filename in course : ' . $file->getFilename());
                                } else {
                                    $exportFileDir = $coursePath . '/group/' . $groupData['directory'] . '/recovered_chat/';
                                }
                            }
                            // create dire
                            claro_mkdir($exportFileDir, CLARO_FILE_PERMISSIONS, true);
                            // try to find a unique filename
                            $fileNamePrefix = 'chat.' . date('Y-m-j') . '_';
                            if (!is_null($groupId)) {
                                $fileNamePrefix .= $groupId . '_';
                            }
                            $i = 1;
                            while (file_exists($exportFileDir . $fileNamePrefix . $i . '.html')) {
                                $i++;
                            }
                            $savedFileName = $fileNamePrefix . $i . '.html';
                            // prepare output
                            $out = '<html>' . '<head>' . '<title>Discussion - archive</title>' . '</head>' . '<body>' . file_get_contents($file->getPathname()) . '</body>' . '</html>';
                            // write to file
                            if (!file_put_contents($exportFileDir . $savedFileName, $out)) {
                                log_message('Cannot save chat : ' . $exportFileDir . $savedFileName);
                                $error = true;
                            }
                        }
                    } catch (Exception $e) {
                        log_message('Cannot save chat : ' . $e->getMessage());
                        $error = true;
                    }
                }
                // save those with group id in group space
                if (!$error) {
                    $step = set_upgrade_status($tool, $step + 1, $course_code);
                } else {
                    return $step;
                }
            case 2:
                // activate new chat in each course
                $currentCourseDbNameGlu = claro_get_course_db_name_glued($course_code);
                if (!register_module_in_single_course($toolId, $course_code)) {
                    log_message("register_module_in_single_course( {$toolId}, {$course_code} ) failed");
                    return $step;
                }
                $sqlForUpdate[] = "UPDATE `" . $currentCourseDbNameGlu . "tool_list`\n                SET `activated` = 'true',\n                    `installed` = 'false'\n                WHERE tool_id = " . (int) $toolId;
                if (upgrade_apply_sql($sqlForUpdate)) {
                    $step = set_upgrade_status($tool, $step + 1, $course_code);
                } else {
                    return $step;
                }
                unset($sqlForUpdate);
            default:
                $step = set_upgrade_status($tool, 0, $course_code);
                return $step;
        }
    }
    return false;
}