add_user.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. $language_file = array('exercice', 'work', 'document', 'admin', 'gradebook');
  5. require_once '../inc/global.inc.php';
  6. // Including necessary files
  7. require_once 'work.lib.php';
  8. if (ADD_DOCUMENT_TO_WORK == false) {
  9. exit;
  10. }
  11. $current_course_tool = TOOL_STUDENTPUBLICATION;
  12. $workId = isset($_GET['id']) ? intval($_GET['id']) : null;
  13. $userId = isset($_GET['user_id']) ? intval($_GET['user_id']) : null;
  14. $action = isset($_GET['action']) ? $_GET['action'] : null;
  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('AddUser'));
  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;
  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;
  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);
  62. echo $userInfo['complete_name'].' '.$link.'<br />';
  63. }
  64. echo '</div>';
  65. }
  66. $userList = CourseManager::get_user_list_from_course_code($courseInfo['code'], api_get_session_id(), null, null, STUDENT);
  67. echo Display::page_subheader(get_lang('UserToAdd'));
  68. if (!empty($userList)) {
  69. echo '<div class="well">';
  70. foreach ($userList as $user) {
  71. if (in_array($user['user_id'], $usersAdded)) {
  72. continue;
  73. }
  74. $userName = api_get_person_name($user['firstname'], $user['lastname']);
  75. $url = api_get_path(WEB_CODE_PATH).'work/add_user.php?action=add&id='.$workId.'&user_id='.$user['user_id'];
  76. $link = Display::url(get_lang('Add'), $url);
  77. echo $userName.' '.$link.'<br />';
  78. }
  79. echo '</div>';
  80. }
  81. echo '<hr /><div class="clear"></div>';