Exemple #1
0
     $sql = "SELECT `path`, `visibility`, `comment`\n                FROM `" . $dbTable . "`\n                WHERE path IN ('" . implode("', '", array_map('claro_sql_escape', $filePathList)) . "')";
     $xtraAttributeList = claro_sql_query_fetch_all_cols($sql);
 } else {
     $xtraAttributeList = array('path' => array(), 'visibility' => array(), 'comment' => array());
 }
 define('A_DIRECTORY', 1);
 define('A_FILE', 2);
 foreach ($filePathList as $thisFile) {
     $fileAttributeList['path'] = $thisFile;
     if (is_dir($baseWorkDir . $thisFile)) {
         $fileAttributeList['type'] = A_DIRECTORY;
         $fileAttributeList['size'] = false;
         $fileAttributeList['date'] = false;
     } elseif (is_file($baseWorkDir . $thisFile)) {
         $fileAttributeList['type'] = A_FILE;
         $fileAttributeList['size'] = claro_get_file_size($baseWorkDir . $thisFile);
         $fileAttributeList['date'] = filemtime($baseWorkDir . $thisFile);
     }
     $xtraAttributeKey = array_search($thisFile, $xtraAttributeList['path']);
     if ($xtraAttributeKey !== false) {
         $fileAttributeList['comment'] = $xtraAttributeList['comment'][$xtraAttributeKey];
         $fileAttributeList['visibility'] = $xtraAttributeList['visibility'][$xtraAttributeKey];
         unset($xtraAttributeList['path'][$xtraAttributeKey]);
     } else {
         $fileAttributeList['comment'] = null;
         $fileAttributeList['visibility'] = null;
     }
     $fileList[] = $fileAttributeList;
 }
 // end foreach $filePathList
 /*------------------------------------------------------------------------
 /**
  * Returns the documents contained into args['curDirPath']
  * @param array $args array of parameters, can contain :
  * - (boolean) recursive : if true, return the content of the requested directory and its subdirectories, if any. Default = true
  * - (String) curDirPath : returns the content of the directory specified by this path. Default = '' (root)
  * @throws InvalidArgumentException if $cid is missing
  * @webservice{/module/MOBILE/CLDOC/getResourceList/cidReq/[?recursive=BOOL&curDirPath='']}
  * @ws_arg{Method,getResourcesList}
  * @ws_arg{cidReq,SYSCODE of requested cours}
  * @ws_arg{recursive,[Optionnal: if true\, return the content of the requested directory and its subdirectories\, if any. Default = true]}
  * @ws_arg{curDirPath,[Optionnal: returns the content of the directory specified by this path. Default = '' (root)]}
  * @return array of document object
  */
 function getResourcesList($args)
 {
     $recursive = isset($args['recursive']) ? $args['recursive'] : true;
     $curDirPath = isset($args['curDirPath']) ? $args['curDirPath'] : '';
     $cid = claro_get_current_course_id();
     if (is_null($cid)) {
         throw new InvalidArgumentException('Missing cid argument!');
     } elseif (!claro_is_course_allowed()) {
         throw new RuntimeException('Not allowed', 403);
     }
     /* READ CURRENT DIRECTORY CONTENT
     		 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
     $claroline = Claroline::getInstance();
     $exSearch = false;
     $groupContext = FALSE;
     $courseContext = TRUE;
     $dbTable = get_module_course_tbl(array('document'), $cid);
     $dbTable = $dbTable['document'];
     $docToolId = get_course_tool_id('CLDOC');
     $groupId = claro_get_current_group_id();
     $date = $claroline->notification->getLastActionBeforeLoginDate(claro_get_current_user_id());
     if (!defined('A_DIRECTORY')) {
         define('A_DIRECTORY', 1);
     }
     if (!defined('A_FILE')) {
         define('A_FILE', 2);
     }
     $baseWorkDir = get_path('coursesRepositorySys') . claro_get_course_path($cid) . '/document';
     /*----------------------------------------------------------------------------
     		 LOAD FILES AND DIRECTORIES INTO ARRAYS
     		----------------------------------------------------------------------------*/
     $searchPattern = '';
     $searchRecursive = false;
     $searchBasePath = $baseWorkDir . $curDirPath;
     $searchExcludeList = array();
     $searchBasePath = secure_file_path($searchBasePath);
     if (false === ($filePathList = claro_search_file(search_string_to_pcre($searchPattern), $searchBasePath, $searchRecursive, 'ALL', $searchExcludeList))) {
         switch (claro_failure::get_last_failure()) {
             case 'BASE_DIR_DONT_EXIST':
                 pushClaroMessage($searchBasePath . ' : call to an unexisting directory in groups');
                 break;
             default:
                 pushClaroMessage('Search failed');
                 break;
         }
         $filePathList = array();
     }
     for ($i = 0; $i < count($filePathList); $i++) {
         $filePathList[$i] = str_replace($baseWorkDir, '', $filePathList[$i]);
     }
     if ($exSearch && $courseContext) {
         $sql = "SELECT path FROM `" . $dbTable . "`\n\t\t\t\t\tWHERE comment LIKE '%" . claro_sql_escape($searchPattern) . "%'";
         $dbSearchResult = claro_sql_query_fetch_all_cols($sql);
         $filePathList = array_unique(array_merge($filePathList, $dbSearchResult['path']));
     }
     $fileList = array();
     if (count($filePathList) > 0) {
         /*--------------------------------------------------------------------------
         		 SEARCHING FILES & DIRECTORIES INFOS ON THE DB
         		------------------------------------------------------------------------*/
         /*
          * Search infos in the DB about the current directory the user is in
          */
         if ($courseContext) {
             $sql = "SELECT `path`, `visibility`, `comment`\n\t\t\t\t\t\tFROM `" . $dbTable . "`\n\t\t\t\t\t\t\t\tWHERE path IN ('" . implode("', '", array_map('claro_sql_escape', $filePathList)) . "')";
             $xtraAttributeList = claro_sql_query_fetch_all_cols($sql);
         } else {
             $xtraAttributeList = array('path' => array(), 'visibility' => array(), 'comment' => array());
         }
         foreach ($filePathList as $thisFile) {
             $fileAttributeList['cours']['sysCode'] = $cid;
             $fileAttributeList['path'] = $thisFile;
             $fileAttributeList['resourceId'] = $thisFile;
             $tmp = explode('/', $thisFile);
             if (is_dir($baseWorkDir . $thisFile)) {
                 $fileYear = date('n', time()) < 8 ? date('Y', time()) - 1 : date('Y', time());
                 $fileAttributeList['title'] = $tmp[count($tmp) - 1];
                 $fileAttributeList['isFolder'] = true;
                 $fileAttributeList['type'] = A_DIRECTORY;
                 $fileAttributeList['size'] = 0;
                 $fileAttributeList['date'] = $fileYear . '-09-20';
                 $fileAttributeList['extension'] = "";
                 $fileAttributeList['url'] = null;
             } elseif (is_file($baseWorkDir . $thisFile)) {
                 $fileAttributeList['title'] = implode('.', explode('.', $tmp[count($tmp) - 1], -1));
                 $fileAttributeList['type'] = A_FILE;
                 $fileAttributeList['isFolder'] = false;
                 $fileAttributeList['size'] = claro_get_file_size($baseWorkDir . $thisFile);
                 $fileAttributeList['date'] = date('Y-m-d', filemtime($baseWorkDir . $thisFile));
                 $fileAttributeList['extension'] = get_file_extension($baseWorkDir . $thisFile);
                 $fileAttributeList['url'] = $_SERVER['SERVER_NAME'] . claro_get_file_download_url($thisFile);
             }
             $xtraAttributeKey = array_search($thisFile, $xtraAttributeList['path']);
             if ($xtraAttributeKey !== false) {
                 $fileAttributeList['description'] = $xtraAttributeList['comment'][$xtraAttributeKey];
                 $fileAttributeList['visibility'] = $xtraAttributeList['visibility'][$xtraAttributeKey] == 'v';
                 unset($xtraAttributeList['path'][$xtraAttributeKey]);
             } else {
                 $fileAttributeList['description'] = null;
                 $fileAttributeList['visibility'] = true;
             }
             $notified = $claroline->notification->isANotifiedDocument($cid, $date, claro_get_current_user_id(), $groupId, $docToolId, $fileAttributeList, false);
             $fileAttributeList['notifiedDate'] = $notified ? $date : $fileAttributeList['date'];
             $d = new DateTime($date);
             $d->sub(new DateInterval('P1D'));
             $fileAttributeList['seenDate'] = $d->format('Y-m-d');
             if ($fileAttributeList['visibility'] || claro_is_allowed_to_edit()) {
                 $fileList[] = $fileAttributeList;
             }
         }
         // end foreach $filePathList
     }
     if ($recursive) {
         foreach ($fileList as $thisFile) {
             if ($thisFile['type'] == A_DIRECTORY) {
                 $args = array('curDirPath' => $thisFile['path'], 'recursive' => true);
                 $new_list = $this->getResourcesList($args);
                 $fileList = array_merge($fileList, $new_list);
             }
         }
     }
     return $fileList;
 }
Exemple #3
0
function disk_usage($dirFiles = '', $dirBase = '', $precision = 'm')
{
    $dirFiles = escapeshellarg($dirFiles);
    $dirBase = escapeshellarg($dirBase);
    $precision = escapeshellarg($precision);
    // $precision  -> b Bytes, k Kilobyte, m Megabyte
    switch (PHP_OS) {
        case 'Linux':
            $usedspace = (int) `du -sc{$precision} {$dirFiles}`;
            $usedspace += (int) `du -sc{$precision} {$dirBase}`;
            //            $usedspace += (int) get_db_size($course["db"],k);
            break;
            //case "WIN32" : // no  optimazing found  for  WIN32, use  long version
            //case "WINNT" : // no  optimazing found  for  WINNT, use  long version
        //case "WIN32" : // no  optimazing found  for  WIN32, use  long version
        //case "WINNT" : // no  optimazing found  for  WINNT, use  long version
        default:
            $usedspace = claro_get_file_size($dirFiles);
            $usedspace += claro_get_file_size($dirBase);
            switch ($precision) {
                case 'm':
                    $usedspace /= 1024;
                case 'k':
                    $usedspace /= 1024;
            }
            break;
    }
    return $usedspace;
}
Exemple #4
0
 $out .= '<div class="' . implode(' ', $style) . '">' . "\n" . '<h1 class="' . (!$is_feedback ? 'claroBlockSuperHeader' : 'blockHeader') . '">' . "\n" . $san->sanitize($work['title']) . "\n" . '</h1>' . "\n";
 // content
 $out .= '<div class="content">' . "\n";
 // author
 $out .= '<div class="workInfo">' . "\n" . '<span class="workInfoTitle">' . get_lang('Author(s)') . '&nbsp;: </span>' . "\n" . '<div class="workInfoValue">' . "\n" . $san->sanitize($work['authors']) . "\n" . '</div>' . "\n" . '</div>' . "\n\n";
 // group
 if ($assignment->getAssignmentType() == 'GROUP' && claro_is_user_authenticated() && !$is_feedback) {
     // display group if this is a group assignment and if this is not a correction
     $out .= '<div class="workInfo">' . "\n" . '<span class="workInfoTitle">' . get_lang('Group') . '&nbsp;: </span>' . "\n" . '<div class="workInfoValue">' . "\n" . $allGroupList[$work['group_id']]['name'] . "\n" . '</div>' . "\n" . '</div>' . "\n\n";
 }
 // file
 if ($assignmentContent != 'TEXT') {
     if (!empty($work['submitted_doc_path'])) {
         $target = get_conf('open_submitted_file_in_new_window') ? 'target="_blank"' : '';
         // show file if this is not a TEXT only work
         $out .= '<div class="workInfo">' . "\n" . '<span class="workInfoTitle">' . $txtForFile . '&nbsp;: </span>' . "\n" . '<div class="workInfoValue">' . "\n" . '<a href="' . claro_htmlspecialchars(Url::Contextualize($_SERVER['PHP_SELF'] . '?cmd=exDownload' . '&authId=' . $_REQUEST['authId'] . '&assigId=' . $assignmentId . '&workId=' . $work['id'])) . '" ' . $target . '>' . "\n" . $work['submitted_doc_path'] . "\n" . '<img src="' . get_icon_url('download') . '" alt="' . get_lang('Download') . '" />' . "\n" . '</a>' . "\n" . '<small>(' . format_file_size(claro_get_file_size($assignment->getAssigDirSys() . $work['submitted_doc_path'])) . ')</small>' . '</div>' . "\n" . '</div>' . "\n\n";
     } else {
         $out .= '<div class="workInfo">' . "\n" . '<span class="workInfoTitle">' . $txtForFile . '&nbsp;: </span>' . "\n" . '<div class="workInfoValue">' . "\n" . get_lang('- none -') . "\n" . '</div>' . "\n" . '</div>' . "\n\n";
     }
 }
 // text
 $out .= '<div class="workInfo">' . "\n" . '<span class="workInfoTitle">' . $txtForText . '&nbsp;: </span>' . "\n" . '<div class="workInfoValue">' . "\n" . '<blockquote>' . "\n" . $san->sanitize($work['submitted_text']) . "\n" . '&nbsp;</blockquote>' . "\n" . '</div>' . "\n" . '</div>' . "\n\n";
 // private feedback
 if ($is_feedback) {
     if ($is_allowedToEditAll) {
         $out .= '<div class="workInfo">' . "\n" . '<span class="workInfoTitle">' . get_lang('Private feedback') . '&nbsp;: </span>' . "\n" . '<div class="workInfoValue">' . "\n" . '<blockquote>' . "\n" . $san->sanitize($work['private_feedback']) . "\n" . '&nbsp;</blockquote>' . "\n" . '</div>' . "\n" . '</div>' . "\n\n";
     }
     // score
     $out .= '<div class="workInfo">' . "\n" . '<span class="workInfoTitle">' . get_lang('Score') . '&nbsp;: </span>' . "\n" . '<div class="workInfoValue">' . "\n" . ($work['score'] == -1 ? get_lang('No score') : $work['score'] . ' %') . '</div>' . "\n" . '</div>' . "\n\n";
 }
 // submission date