add_user.php 3.8 KB

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