add_user.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once '../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[] = array('url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(), 'name' => get_lang('StudentPublications'));
  24. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'work/work_list_all.php?'.api_get_cidreq().'&id='.$workId, 'name' => $my_folder_data['title']);
  25. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AddUsers'));
  26. $error_message = null;
  27. switch ($action) {
  28. case 'add':
  29. $data = getUserToWork($userId, $workId, api_get_course_int_id());
  30. if (empty($data)) {
  31. addUserToWork($userId, $workId, api_get_course_int_id());
  32. }
  33. $url = api_get_path(WEB_CODE_PATH).'work/add_user.php?id='.$workId.'&'.api_get_cidreq();
  34. header('Location: '.$url);
  35. exit;
  36. break;
  37. case 'delete':
  38. if (!empty($workId) && !empty($userId)) {
  39. deleteUserToWork($userId, $workId, api_get_course_int_id());
  40. $url = api_get_path(WEB_CODE_PATH).'work/add_user.php?id='.$workId.'&'.api_get_cidreq();
  41. header('Location: '.$url);
  42. exit;
  43. }
  44. break;
  45. }
  46. Display :: display_header(null);
  47. $items = getAllUserToWork($workId, api_get_course_int_id());
  48. $usersAdded = array();
  49. if (!empty($items)) {
  50. echo Display::page_subheader(get_lang('UsersAdded'));
  51. echo '<div class="well">';
  52. foreach ($items as $data) {
  53. $myUserId = $data['user_id'];
  54. $usersAdded[] = $myUserId;
  55. $userInfo = api_get_user_info($myUserId);
  56. $url = api_get_path(WEB_CODE_PATH).'work/add_user.php?action=delete&id='.$workId.'&user_id='.$myUserId;
  57. $link = Display::url(get_lang('Delete'), $url, array('class' => 'btn btn-danger'));
  58. echo $userInfo['complete_name_with_username'].' '.$link.'<br />';
  59. }
  60. echo '</div>';
  61. }
  62. if (empty($sessionId)) {
  63. $status = STUDENT;
  64. } else {
  65. $status = 0;
  66. }
  67. $userList = CourseManager::get_user_list_from_course_code(
  68. $courseInfo['code'],
  69. $sessionId,
  70. null,
  71. null,
  72. $status
  73. );
  74. $userToAddList = array();
  75. foreach ($userList as $user) {
  76. if (!in_array($user['user_id'], $usersAdded)) {
  77. $userToAddList[] = $user;
  78. }
  79. }
  80. if (!empty($userToAddList)) {
  81. echo Display::page_subheader(get_lang('UsersToAdd'));
  82. echo '<div class="well">';
  83. foreach ($userToAddList as $user) {
  84. $userName = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].') ';
  85. $url = api_get_path(WEB_CODE_PATH).'work/add_user.php?action=add&id='.$workId.'&user_id='.$user['user_id'];
  86. $link = Display::url(get_lang('Add'), $url, array('class' => 'btn btn-primary'));
  87. echo $userName.' '.$link.'<br />';
  88. }
  89. echo '</div>';
  90. } else {
  91. Display::display_warning_message(get_lang('NoUsersToAdd'));
  92. }
  93. echo '<hr /><div class="clear"></div>';
  94. Display::display_footer();