add_user.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $language_file = array('exercice', 'work', 'document', 'admin', 'gradebook');
  4. require_once '../inc/global.inc.php';
  5. // Including necessary files
  6. require_once 'work.lib.php';
  7. if (ADD_DOCUMENT_TO_WORK == false) {
  8. exit;
  9. }
  10. $current_course_tool = TOOL_STUDENTPUBLICATION;
  11. $workId = isset($_GET['id']) ? intval($_GET['id']) : null;
  12. $userId = isset($_GET['user_id']) ? intval($_GET['user_id']) : null;
  13. $action = isset($_GET['action']) ? $_GET['action'] : null;
  14. $sessionId = api_get_session_id();
  15. if (empty($workId)) {
  16. api_not_allowed(true);
  17. }
  18. $my_folder_data = get_work_data_by_id($workId);
  19. if (empty($my_folder_data)) {
  20. api_not_allowed(true);
  21. }
  22. $work_data = get_work_assignment_by_id($workId);
  23. if (!api_is_allowed_to_edit()) {
  24. api_not_allowed(true);
  25. }
  26. $courseInfo = api_get_course_info();
  27. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(), 'name' => get_lang('StudentPublications'));
  28. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'work/work_list_all.php?'.api_get_cidreq().'&id='.$workId, 'name' => $my_folder_data['title']);
  29. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AddUsers'));
  30. $error_message = null;
  31. switch ($action) {
  32. case 'add':
  33. $data = getUserToWork($userId, $workId, api_get_course_int_id());
  34. if (empty($data)) {
  35. addUserToWork($userId, $workId, api_get_course_int_id());
  36. }
  37. $url = api_get_path(WEB_CODE_PATH).'work/add_user.php?id='.$workId.'&'.api_get_cidreq();
  38. header('Location: '.$url);
  39. exit;
  40. break;
  41. case 'delete':
  42. if (!empty($workId) && !empty($userId)) {
  43. deleteUserToWork($userId, $workId, api_get_course_int_id());
  44. $url = api_get_path(WEB_CODE_PATH).'work/add_user.php?id='.$workId.'&'.api_get_cidreq();
  45. header('Location: '.$url);
  46. exit;
  47. }
  48. break;
  49. }
  50. Display :: display_header(null);
  51. $items = getAllUserToWork($workId, api_get_course_int_id());
  52. $usersAdded = array();
  53. if (!empty($items)) {
  54. echo Display::page_subheader(get_lang('UsersAdded'));
  55. echo '<div class="well">';
  56. foreach ($items as $data) {
  57. $myUserId = $data['user_id'];
  58. $usersAdded[] = $myUserId;
  59. $userInfo = api_get_user_info($myUserId);
  60. $url = api_get_path(WEB_CODE_PATH).'work/add_user.php?action=delete&id='.$workId.'&user_id='.$myUserId;
  61. $link = Display::url(get_lang('Delete'), $url, array('class' => 'btn btn-danger'));
  62. echo $userInfo['complete_name_with_username'].' '.$link.'<br />';
  63. }
  64. echo '</div>';
  65. }
  66. if (empty($sessionId)) {
  67. $status = STUDENT;
  68. } else {
  69. $status = 0;
  70. }
  71. $userList = CourseManager::get_user_list_from_course_code(
  72. $courseInfo['code'],
  73. $sessionId,
  74. null,
  75. null,
  76. $status
  77. );
  78. $userToAddList = array();
  79. foreach ($userList as $user) {
  80. if (!in_array($user['user_id'], $usersAdded)) {
  81. $userToAddList[] = $user;
  82. }
  83. }
  84. if (!empty($userToAddList)) {
  85. echo Display::page_subheader(get_lang('UsersToAdd'));
  86. echo '<div class="well">';
  87. foreach ($userToAddList as $user) {
  88. $userName = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].') ';
  89. $url = api_get_path(WEB_CODE_PATH).'work/add_user.php?action=add&id='.$workId.'&user_id='.$user['user_id'];
  90. $link = Display::url(get_lang('Add'), $url, array('class' => 'btn btn-primary'));
  91. echo $userName.' '.$link.'<br />';
  92. }
  93. echo '</div>';
  94. } else {
  95. Display::display_warning_message(get_lang('NoUsersToAdd'));
  96. }
  97. echo '<hr /><div class="clear"></div>';
  98. Display::display_footer();