add_user.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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[] = array(
  24. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  25. 'name' => get_lang('StudentPublications'),
  26. );
  27. $interbreadcrumb[] = array(
  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[] = array('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 = array();
  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('<em class="fa fa-trash"></em> '.get_lang('Delete'), $url, array('class' => 'btn btn-danger btn-sm'));
  63. echo '<li class="list-group-item">'.$userInfo['complete_name_with_username'].'<div class="pull-right">'.$link.'</div></li>';
  64. }
  65. echo '</ul>';
  66. }
  67. if (empty($sessionId)) {
  68. $status = STUDENT;
  69. } else {
  70. $status = 0;
  71. }
  72. $userList = CourseManager::get_user_list_from_course_code(
  73. $courseInfo['code'],
  74. $sessionId,
  75. null,
  76. null,
  77. $status
  78. );
  79. $userToAddList = array();
  80. foreach ($userList as $user) {
  81. if (!in_array($user['user_id'], $usersAdded)) {
  82. $userToAddList[] = $user;
  83. }
  84. }
  85. if (!empty($userToAddList)) {
  86. echo Display::page_subheader(get_lang('UsersToAdd'));
  87. echo '<ul class="list-group">';
  88. foreach ($userToAddList as $user) {
  89. $userName = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].') ';
  90. $url = api_get_path(WEB_CODE_PATH).'work/add_user.php?action=add&id='.$workId.'&user_id='.$user['user_id'];
  91. $link = Display::url('<em class="fa fa-plus"></em> '.get_lang('Add'), $url, array('class' => 'btn btn-primary btn-sm'));
  92. echo '<li class="list-group-item">'.$userName.'<div class="pull-right"> '.$link.'</div></li>';
  93. }
  94. echo '</ul>';
  95. } else {
  96. echo Display::return_message(get_lang('NoUsersToAdd'), 'warning');
  97. }
  98. echo '<hr /><div class="clear"></div>';
  99. Display::display_footer();