/** * get the list of files and folders under this current fold * @return array */ function getFileList() { $outputs = array(); $files = array(); $folders = array(); $tem = array(); $dirHandler = @opendir($this->currentFolderPath); if ($dirHandler) { while (false !== ($file = readdir($dirHandler))) { if ($file != '.' && $file != '..') { $flag = $this->flags['no']; if ($this->sessionAction->getFolder() == $this->currentFolderPath) { //check if any flag associated with this folder or file $folder = addTrailingSlash(backslashToSlash($this->currentFolderPath)); if (in_array($folder . $file, $this->sessionAction->get())) { if ($this->sessionAction->getAction() == "copy") { $flag = $this->flags['copy']; } else { $flag = $this->flags['cut']; } } } $path = $this->currentFolderPath . $file; if (is_dir($path) && isListingDocument($path)) { $this->currentFolderInfo['subdir']++; if (!$this->calculateSubdir) { } else { $folder = $this->getFolderInfo($path); $folder['flag'] = $flag; $folders[$file] = $folder; $outputs[$file] = $folders[$file]; } } elseif (is_file($path) && isListingDocument($path)) { $obj = new file($path); $tem = $obj->getFileInfo(); if (sizeof($tem)) { $fileType = $this->getFileType($file); foreach ($fileType as $k => $v) { $tem[$k] = $v; } $this->currentFolderInfo['size'] += $tem['size']; $this->currentFolderInfo['file']++; $tem['path'] = backslashToSlash($path); $tem['type'] = "file"; $tem['flag'] = $flag; $files[$file] = $tem; $outputs[$file] = $tem; $tem = array(); $obj->close(); } } } } if ($this->forceFolderOnTop) { uksort($folders, "strnatcasecmp"); uksort($files, "strnatcasecmp"); $outputs = array(); foreach ($folders as $v) { $outputs[] = $v; } foreach ($files as $v) { $outputs[] = $v; } } else { uksort($outputs, "strnatcasecmp"); } @closedir($dirHandler); } else { trigger_error('Unable to locate the folder ' . $this->currentFolderPath, E_NOTICE); } return $outputs; }
}else if(!$upload->moveUploadedFile($_GET['folder'])) { $error = ERR_FILE_MOVE_FAILED; } elseif(!$upload->isPermittedFileExt(explode(",", CONFIG_UPLOAD_VALID_EXTS))) { $error = ERR_FILE_TYPE_NOT_ALLOWED; }elseif(defined('CONFIG_UPLOAD_MAXSIZE') && CONFIG_UPLOAD_MAXSIZE && $upload->isSizeTooBig(CONFIG_UPLOAD_MAXSIZE)) { $error = sprintf(ERROR_FILE_TOO_BID, transformFileSize(CONFIG_UPLOAD_MAXSIZE)); }else { include_once(CLASS_FILE); $path = $upload->getFilePath(); $obj = new file($path); $tem = $obj->getFileInfo(); if(sizeof($tem)) { include_once(CLASS_MANAGER); $manager = new manager($upload->getFilePath(), false); $fileType = $manager->getFileType($upload->getFileName()); foreach($fileType as $k=>$v) { $tem[$k] = $v; } $tem['path'] = backslashToSlash($path); $tem['type'] = "file";
$allDocs[] = getRealPath($destFolderPath . $file); } } include_once CLASS_FILE; $file = new file(); //check if all files are allowed to cut or copy foreach ($selectedDocuments as $doc) { if (file_exists($doc) && isUnderRoot($doc)) { if (array_search(getRealPath($doc), $allDocs) === false || CONFIG_OVERWRITTEN) { if (CONFIG_OVERWRITTEN) { $file->delete($doc); } if ($file->copyTo($doc, $_GET['current_folder_path'])) { $finalPath = $destFolderPath . basename($doc); $objFile = new file($finalPath); $tem = $objFile->getFileInfo(); $obj = new manager($finalPath, false); $fileType = $obj->getFileType($finalPath, is_dir($finalPath) ? true : false); foreach ($fileType as $k => $v) { $tem[$k] = $v; } /* foreach ($folderInfo as $k=>$v) { $tem['i_' . $k] = $v; } if($folderInfo['type'] == 'folder' && empty($folderInfo['subdir']) && empty($folderInfo['file'])) { $tem['cssClass'] = 'folderEmpty'; }*/ $tem['final_path'] = $finalPath; $tem['path'] = backslashToSlash($finalPath);
/** * get the file according to the search keywords * */ function doSearch($baseFolderPath = null) { $baseFolderPath = addTrailingSlash(backslashToSlash((is_null($baseFolderPath)?$this->rootFolder:$baseFolderPath))); $dirHandler = @opendir($baseFolderPath); if($dirHandler) { while(false !== ($file = readdir($dirHandler))) { if($file != '.' && $file != '..') { $path = $baseFolderPath . $file; if(is_file($path)) { $isValid = true; $fileTime = @filemtime($path); $fileSize = @filesize($path); if($this->searchkeywords['name'] !== '' && @eregi($this->searchkeywords['name'], $file) === false) { $isValid = false; } if($this->searchkeywords['mtime_from'] != '' && $fileTime < @strtotime($this->searchkeywords['mtime_from'])) { $isValid = false; } if($this->searchkeywords['mtime_to'] != '' && $fileTime > @strtotime($this->searchkeywords['mtime_to'])) { $isValid = false; } if($this->searchkeywords['size_from'] != '' && $fileSize < @strtotime($this->searchkeywords['size_from'])) { $isValid = false; } if($this->searchkeywords['size_to'] != '' && $fileSize > @strtotime($this->searchkeywords['size_to'])) { $isValid = false; } if($isValid && isListingDocument($path)) { $finalPath = $path; $objFile = new file($finalPath); $tem = $objFile->getFileInfo(); $obj = new manager($finalPath, false); $obj->setSessionAction($this->sessionAction); $selectedDocuments = $this->sessionAction->get(); $fileType = $obj->getFileType($finalPath); foreach($fileType as $k=>$v) { $tem[$k] = $v; } $tem['path'] = backslashToSlash($finalPath); $tem['type'] = (is_dir($finalPath)?'folder':'file'); /* $tem['size'] = transformFileSize($tem['size']); $tem['ctime'] = date(DATE_TIME_FORMAT, $tem['ctime']); $tem['mtime'] = date(DATE_TIME_FORMAT, $tem['mtime']);*/ $tem['flag'] = (array_search($tem['path'], $selectedDocuments) !== false?($this->sessionAction->getAction() == "copy"?'copyFlag':'cutFlag'):'noFlag'); $tem['url'] = getFileUrl($tem['path']); $this->rootFolderInfo['file']++; $manager = null; $this->files[] = $tem; $tem = null; } }elseif(is_dir($path) && $this->searchkeywords['recursive']) { $this->Search($baseFolderPath); } } } } }
include_once CLASS_SESSION_ACTION; $sessionAction = new SessionAction(); $selectedDocuments = $sessionAction->get(); if (removeTrailingSlash($sessionAction->getFolder()) == getParentPath($_POST['original_path']) && sizeof($selectedDocuments)) { if (($key = array_search(basename($_POST['original_path']), $selectedDocuments)) !== false) { $selectedDocuments[$key] = $_POST['name']; $sessionAction->set($selectedDocuments); } } elseif (removeTrailingSlash($sessionAction->getFolder()) == removeTrailingSlash($_POST['original_path'])) { $sessionAction->setFolder($_POST['original_path']); } $path = addTrailingSlash(getParentPath($_POST['original_path'])) . $_POST['name']; if (is_file($path)) { include_once CLASS_FILE; $file = new file($path); $fileInfo = $file->getFileInfo(); $fileInfo['mtime'] = date(DATE_TIME_FORMAT, $fileInfo['mtime']); } else { include_once CLASS_MANAGER; $manager = new manager($path, false); $fileInfo = $manager->getFolderInfo(); $fileInfo['mtime'] = date(DATE_TIME_FORMAT, $fileInfo['mtime']); } event_system(LOG_MY_FOLDER_CHANGE, LOG_MY_FOLDER_PATH, $_POST['original_path']); event_system(LOG_MY_FOLDER_CHANGE, LOG_MY_FOLDER_NEW_PATH, $path); } echo "{"; echo "error:'" . $error . "' "; foreach ($fileInfo as $k => $v) { echo "," . $k . ":'" . $v . "' "; }
/** * get the list of files and folders under this current fold * @return array */ function getFileList() { $outputs = array(); $files = array(); $folders = array(); $tem = array(); $to_group_id = api_get_group_id(); global $is_user_in_group; $dirHandler = @opendir($this->getCurrentFolderPath()); if ($dirHandler) { while (false !== ($file = readdir($dirHandler))) { if ($file != '.' && $file != '..') { $flag = $this->flags['no']; if ($this->sessionAction->getFolder() == $this->getCurrentFolderPath()) { //check if any flag associated with this folder or file $folder = addTrailingSlash(backslashToSlash($this->getCurrentFolderPath())); if (in_array($folder . $file, $this->sessionAction->get())) { if ($this->sessionAction->getAction() == "copy") { $flag = $this->flags['copy']; } else { $flag = $this->flags['cut']; } } } $path = $this->getCurrentFolderPath() . $file; if (is_dir($path) && isListingDocument($path)) { $this->currentFolderInfo['subdir']++; //fix count left folders for Chamilo $deleted_by_Chamilo_folder = '_DELETED_'; $css_folder_Chamilo = 'css'; $hotpotatoes_folder_Chamilo = 'HotPotatoes_files'; $chat_files_Chamilo = 'chat_files'; $certificates_Chamilo = 'certificates'; //show group's directory only if I'm member. Or if I'm a teacher. //@todo: check groups not necessary because the student dont have access to main folder documents (only to document/group or document/shared_folder). //Teachers can access to all groups ? $group_folder = '_groupdocs'; $hide_doc_group = false; if (preg_match("/{$group_folder}/", $path)) { $hide_doc_group = true; if ($is_user_in_group || $to_group_id != 0 && api_is_allowed_to_edit()) { $hide_doc_group = false; } } if (preg_match("/{$deleted_by_Chamilo_folder}/", $path) || preg_match("/{$css_folder_Chamilo}/", $path) || preg_match("/{$hotpotatoes_folder_Chamilo}/", $path) || preg_match("/{$chat_files_Chamilo}/", $path) || preg_match("/{$certificates_Chamilo}/", $path) || $hide_doc_group || $file[0] == '.') { $this->currentFolderInfo['subdir'] = $this->currentFolderInfo['subdir'] - 1; } //end fix for Chamilo if (!$this->calculateSubdir) { } else { $folder = $this->getFolderInfo($path); $folder['flag'] = $flag; $folders[$file] = $folder; $outputs[$file] = $folders[$file]; } } elseif (is_file($path) && isListingDocument($path)) { $obj = new file($path); $tem = $obj->getFileInfo(); if (sizeof($tem)) { $fileType = $this->getFileType($file); foreach ($fileType as $k => $v) { $tem[$k] = $v; } $this->currentFolderInfo['size'] += $tem['size']; $this->currentFolderInfo['file']++; //fix count left files for Chamilo $deleted_by_Chamilo_file = ' DELETED '; // ' DELETED ' not '_DELETED_' because in $file['name'] _ is replaced with blank see class.manager.php if (preg_match("/{$deleted_by_Chamilo_file}/", $tem['name']) || $tem['name'][0] == '.') { $this->currentFolderInfo['file'] = $this->currentFolderInfo['file'] - 1; } ///end fix for Chamilo //Try a course file $tem['path'] = backslashToSlash($path); $pos = strpos($this->getCurrentFolderPath(), 'courses/'); if ($pos === false) { //try my_files $pos = strpos($this->getCurrentFolderPath(), 'main/'); $tem['public_path'] = api_get_path(WEB_PATH) . substr($this->getCurrentFolderPath(), $pos, strlen($this->getCurrentFolderPath())) . $file; } else { $tem['public_path'] = api_get_path(WEB_PATH) . substr($this->getCurrentFolderPath(), $pos, strlen($this->getCurrentFolderPath())) . $file; } $tem['type'] = "file"; $tem['flag'] = $flag; $files[$file] = $tem; $outputs[$file] = $tem; $tem = array(); $obj->close(); } } } } if ($this->forceFolderOnTop) { uksort($folders, "strnatcasecmp"); uksort($files, "strnatcasecmp"); $outputs = array(); foreach ($folders as $v) { $outputs[] = $v; } foreach ($files as $v) { $outputs[] = $v; } } else { uksort($outputs, "strnatcasecmp"); } @closedir($dirHandler); } else { trigger_error('Unable to locate the folder ' . $this->getCurrentFolderPath(), E_NOTICE); } return $outputs; }