repository.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Additional system config settings for document repositories, the Chamilo LMS
  5. * @author Juan Carlos Raña
  6. * @since 31/December/2008
  7. */
  8. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  9. // Disabling access for anonymous users.
  10. api_block_anonymous_users();
  11. $permissions_for_new_directories = api_get_permissions_for_new_directories();
  12. $permissions_for_new_files = api_get_permissions_for_new_files();
  13. $userId = api_get_user_id();
  14. $sessionId = api_get_session_id();
  15. if (!empty($_course['path'])) {
  16. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  17. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  18. // Get the Chamilo session properties. Before ajaximagemanager!!!
  19. $groupId = api_get_group_id();
  20. $group_properties = GroupManager::get_group_properties($groupId);
  21. $is_user_in_group = GroupManager::is_user_in_group($userId, $groupId);
  22. }
  23. $sessionName = null;
  24. if (!empty($sessionId)) {
  25. $sessionName = api_get_session_name($sessionId);
  26. }
  27. $my_path = UserManager::get_user_picture_path_by_id($userId, 'system');
  28. $user_folder = $my_path['dir'].'my_files/';
  29. // Sanity checks for Chamilo.
  30. // Creation of a user owned folder if it does not exist.
  31. if (!file_exists($user_folder)) {
  32. // A recursive call of mkdir function.
  33. @mkdir($user_folder, $permissions_for_new_directories, true);
  34. }
  35. // Creation of repository used by platform administrators if it does not exist.
  36. if (api_is_platform_admin()) {
  37. $homepage_folder = api_get_path(SYS_PATH).'home/default_platform_document/';
  38. if (!file_exists($homepage_folder)) {
  39. @mkdir($homepage_folder, $permissions_for_new_directories);
  40. }
  41. }
  42. $to_user_id = isset($to_user_id) ? $to_user_id : null;
  43. // Create course shared folders
  44. if (api_is_in_course()) {
  45. $course_dir = $_course['path'].'/document';
  46. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  47. $base_work_dir = $sys_course_path.$course_dir;
  48. $userInfo = api_get_user_info();
  49. if ($sessionId == 0) {
  50. /* Create shared folder. Necessary for courses recycled.
  51. Always session_id should be zero. Always should be created from a base course, never from a session.*/
  52. if (!file_exists($base_work_dir.'/shared_folder')) {
  53. $usf_dir_title = get_lang('SharedFolder');
  54. $usf_dir_name = '/shared_folder';
  55. $visibility = 0;
  56. create_unexisting_directory(
  57. $_course,
  58. $userId,
  59. $sessionId,
  60. 0,
  61. $to_user_id,
  62. $base_work_dir,
  63. $usf_dir_name,
  64. $usf_dir_title,
  65. $visibility,
  66. false,
  67. false
  68. );
  69. }
  70. // Create dynamic user shared folder
  71. if (!file_exists($base_work_dir.'/shared_folder/sf_user_'.$userId)) {
  72. $usf_dir_title = $userInfo['complete_name'];
  73. $usf_dir_name = '/shared_folder/sf_user_'.$userId;
  74. $visibility = 1;
  75. create_unexisting_directory(
  76. $_course,
  77. $userId,
  78. $sessionId,
  79. 0,
  80. $to_user_id,
  81. $base_work_dir,
  82. $usf_dir_name,
  83. $usf_dir_title,
  84. $visibility,
  85. false,
  86. false
  87. );
  88. }
  89. } else {
  90. // Create shared folder session
  91. if (!file_exists($base_work_dir.'/shared_folder_session_'.$sessionId)) {
  92. $usf_dir_title = get_lang('SharedFolder').' ('.$sessionName.')';
  93. $usf_dir_name = '/shared_folder_session_'.$sessionId;
  94. $visibility = 0;
  95. create_unexisting_directory(
  96. $_course,
  97. $userId,
  98. $sessionId,
  99. 0,
  100. $to_user_id,
  101. $base_work_dir,
  102. $usf_dir_name,
  103. $usf_dir_title,
  104. $visibility,
  105. false,
  106. false
  107. );
  108. }
  109. // Create dynamic user shared folder into a shared folder session.
  110. if (!file_exists($base_work_dir.'/shared_folder_session_'.$sessionId.'/sf_user_'.$userId)) {
  111. $usf_dir_title = $userInfo['complete_name'].' ('.$sessionName.')';
  112. $usf_dir_name = '/shared_folder_session_'.$sessionId.'/sf_user_'.$userId;
  113. $visibility = 1;
  114. create_unexisting_directory(
  115. $_course,
  116. $userId,
  117. $sessionId,
  118. 0,
  119. $to_user_id,
  120. $base_work_dir,
  121. $usf_dir_name,
  122. $usf_dir_title,
  123. $visibility,
  124. false,
  125. false
  126. );
  127. }
  128. }
  129. }