| @@ 4871-4911 (lines=41) @@ | ||
| 4868 | * |
|
| 4869 | * @return bool |
|
| 4870 | */ |
|
| 4871 | public static function folderExists( |
|
| 4872 | $folder, |
|
| 4873 | $courseInfo, |
|
| 4874 | $sessionId, |
|
| 4875 | $groupId |
|
| 4876 | ) { |
|
| 4877 | $courseId = $courseInfo['real_id']; |
|
| 4878 | ||
| 4879 | if (empty($courseId)) { |
|
| 4880 | return false; |
|
| 4881 | } |
|
| 4882 | ||
| 4883 | $sessionId = intval($sessionId); |
|
| 4884 | $folderWithSuffix = self::fixDocumentName( |
|
| 4885 | $folder, |
|
| 4886 | 'folder', |
|
| 4887 | $courseInfo, |
|
| 4888 | $sessionId, |
|
| 4889 | $groupId |
|
| 4890 | ); |
|
| 4891 | ||
| 4892 | $folder = Database::escape_string($folder); |
|
| 4893 | $folderWithSuffix = Database::escape_string($folderWithSuffix); |
|
| 4894 | ||
| 4895 | // Check if pathname already exists inside document table |
|
| 4896 | $tbl_document = Database::get_course_table(TABLE_DOCUMENT); |
|
| 4897 | $sql = "SELECT id, path FROM $tbl_document |
|
| 4898 | WHERE |
|
| 4899 | filetype = 'folder' AND |
|
| 4900 | c_id = $courseId AND |
|
| 4901 | (path = '$folder' OR path = '$folderWithSuffix') AND |
|
| 4902 | (session_id = 0 OR session_id = $sessionId) |
|
| 4903 | "; |
|
| 4904 | ||
| 4905 | $rs = Database::query($sql); |
|
| 4906 | if (Database::num_rows($rs)) { |
|
| 4907 | return true; |
|
| 4908 | } |
|
| 4909 | ||
| 4910 | return false; |
|
| 4911 | } |
|
| 4912 | ||
| 4913 | /** |
|
| 4914 | * Check if file exist in the course base or in the session course |
|
| @@ 4922-4965 (lines=44) @@ | ||
| 4919 | * |
|
| 4920 | * @return bool |
|
| 4921 | */ |
|
| 4922 | public static function documentExists( |
|
| 4923 | $fileName, |
|
| 4924 | $courseInfo, |
|
| 4925 | $sessionId, |
|
| 4926 | $groupId |
|
| 4927 | ) { |
|
| 4928 | $courseId = $courseInfo['real_id']; |
|
| 4929 | ||
| 4930 | if (empty($courseId)) { |
|
| 4931 | return false; |
|
| 4932 | } |
|
| 4933 | ||
| 4934 | $sessionId = intval($sessionId); |
|
| 4935 | $fileNameEscape = Database::escape_string($fileName); |
|
| 4936 | ||
| 4937 | $fileNameWithSuffix = self::fixDocumentName( |
|
| 4938 | $fileName, |
|
| 4939 | 'file', |
|
| 4940 | $courseInfo, |
|
| 4941 | $sessionId, |
|
| 4942 | $groupId |
|
| 4943 | ); |
|
| 4944 | ||
| 4945 | $fileNameWithSuffix = Database::escape_string($fileNameWithSuffix); |
|
| 4946 | ||
| 4947 | // Check if pathname already exists inside document table |
|
| 4948 | $table = Database::get_course_table(TABLE_DOCUMENT); |
|
| 4949 | $sql = "SELECT id, path FROM $table |
|
| 4950 | WHERE |
|
| 4951 | filetype = 'file' AND |
|
| 4952 | c_id = $courseId AND |
|
| 4953 | ( |
|
| 4954 | path = '".$fileNameEscape."' OR |
|
| 4955 | path = '$fileNameWithSuffix' |
|
| 4956 | ) AND |
|
| 4957 | (session_id = 0 OR session_id = $sessionId) |
|
| 4958 | "; |
|
| 4959 | $rs = Database::query($sql); |
|
| 4960 | if (Database::num_rows($rs)) { |
|
| 4961 | return true; |
|
| 4962 | } |
|
| 4963 | ||
| 4964 | return false; |
|
| 4965 | } |
|
| 4966 | ||
| 4967 | /** |
|
| 4968 | * Undo the suffix applied to a file example: |
|