| @@ 4955-4995 (lines=41) @@ | ||
| 4952 | * |
|
| 4953 | * @return bool |
|
| 4954 | */ |
|
| 4955 | public static function folderExists( |
|
| 4956 | $folder, |
|
| 4957 | $courseInfo, |
|
| 4958 | $sessionId, |
|
| 4959 | $groupId |
|
| 4960 | ) { |
|
| 4961 | $courseId = $courseInfo['real_id']; |
|
| 4962 | ||
| 4963 | if (empty($courseId)) { |
|
| 4964 | return false; |
|
| 4965 | } |
|
| 4966 | ||
| 4967 | $sessionId = intval($sessionId); |
|
| 4968 | $folderWithSuffix = self::fixDocumentName( |
|
| 4969 | $folder, |
|
| 4970 | 'folder', |
|
| 4971 | $courseInfo, |
|
| 4972 | $sessionId, |
|
| 4973 | $groupId |
|
| 4974 | ); |
|
| 4975 | ||
| 4976 | $folder = Database::escape_string($folder); |
|
| 4977 | $folderWithSuffix = Database::escape_string($folderWithSuffix); |
|
| 4978 | ||
| 4979 | // Check if pathname already exists inside document table |
|
| 4980 | $tbl_document = Database::get_course_table(TABLE_DOCUMENT); |
|
| 4981 | $sql = "SELECT id, path FROM $tbl_document |
|
| 4982 | WHERE |
|
| 4983 | filetype = 'folder' AND |
|
| 4984 | c_id = $courseId AND |
|
| 4985 | (path = '$folder' OR path = '$folderWithSuffix') AND |
|
| 4986 | (session_id = 0 OR session_id = $sessionId) |
|
| 4987 | "; |
|
| 4988 | ||
| 4989 | $rs = Database::query($sql); |
|
| 4990 | if (Database::num_rows($rs)) { |
|
| 4991 | return true; |
|
| 4992 | } |
|
| 4993 | ||
| 4994 | return false; |
|
| 4995 | } |
|
| 4996 | ||
| 4997 | /** |
|
| 4998 | * Check if file exist in the course base or in the session course |
|
| @@ 5006-5049 (lines=44) @@ | ||
| 5003 | * |
|
| 5004 | * @return bool |
|
| 5005 | */ |
|
| 5006 | public static function documentExists( |
|
| 5007 | $fileName, |
|
| 5008 | $courseInfo, |
|
| 5009 | $sessionId, |
|
| 5010 | $groupId |
|
| 5011 | ) { |
|
| 5012 | $courseId = $courseInfo['real_id']; |
|
| 5013 | ||
| 5014 | if (empty($courseId)) { |
|
| 5015 | return false; |
|
| 5016 | } |
|
| 5017 | ||
| 5018 | $sessionId = intval($sessionId); |
|
| 5019 | $fileNameEscape = Database::escape_string($fileName); |
|
| 5020 | ||
| 5021 | $fileNameWithSuffix = self::fixDocumentName( |
|
| 5022 | $fileName, |
|
| 5023 | 'file', |
|
| 5024 | $courseInfo, |
|
| 5025 | $sessionId, |
|
| 5026 | $groupId |
|
| 5027 | ); |
|
| 5028 | ||
| 5029 | $fileNameWithSuffix = Database::escape_string($fileNameWithSuffix); |
|
| 5030 | ||
| 5031 | // Check if pathname already exists inside document table |
|
| 5032 | $table = Database::get_course_table(TABLE_DOCUMENT); |
|
| 5033 | $sql = "SELECT id, path FROM $table |
|
| 5034 | WHERE |
|
| 5035 | filetype = 'file' AND |
|
| 5036 | c_id = $courseId AND |
|
| 5037 | ( |
|
| 5038 | path = '".$fileNameEscape."' OR |
|
| 5039 | path = '$fileNameWithSuffix' |
|
| 5040 | ) AND |
|
| 5041 | (session_id = 0 OR session_id = $sessionId) |
|
| 5042 | "; |
|
| 5043 | $rs = Database::query($sql); |
|
| 5044 | if (Database::num_rows($rs)) { |
|
| 5045 | return true; |
|
| 5046 | } |
|
| 5047 | ||
| 5048 | return false; |
|
| 5049 | } |
|
| 5050 | ||
| 5051 | /** |
|
| 5052 | * Undo the suffix applied to a file example: |
|