require_user_linking.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $cidReset = true;
  4. require_once __DIR__.'/../inc/global.inc.php';
  5. $isAllowed = api_get_configuration_value('show_link_request_hrm_user') && api_is_drh();
  6. if (!$isAllowed) {
  7. api_not_allowed(true);
  8. }
  9. $hrm = api_get_user_entity(api_get_user_id());
  10. $usersRequested = UserManager::getUsersFollowedByUser(
  11. $hrm->getId(),
  12. null,
  13. null,
  14. false,
  15. false,
  16. null,
  17. null,
  18. null,
  19. null,
  20. null,
  21. null,
  22. HRM_REQUEST
  23. );
  24. $requestOptions = [];
  25. foreach ($usersRequested as $userRequested) {
  26. $userInfo = api_get_user_info($userRequested['user_id']);
  27. if (!$userInfo) {
  28. continue;
  29. }
  30. $requestOptions[$userInfo['user_id']] = $userInfo['complete_name'];
  31. }
  32. $form = new FormValidator('require_user_linking');
  33. $form->addUserAvatar('hrm', get_lang('DRH'), 'medium');
  34. $form->addSelectAjax(
  35. 'users',
  36. [get_lang('LinkMeToStudent'), get_lang('LinkMeToStudentComment')],
  37. $requestOptions,
  38. [
  39. 'multiple' => 'multiple',
  40. 'url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_like',
  41. ]
  42. );
  43. $form->addButtonSave(get_lang('RequestLinkToStudent'));
  44. $form->setDefaults([
  45. 'hrm' => $hrm,
  46. 'users' => array_keys($requestOptions),
  47. ]);
  48. if ($form->validate()) {
  49. $values = $form->exportValues();
  50. //Avoid self-subscribe as request
  51. $usersId = array_filter($values['users'], function ($userId) use ($hrm) {
  52. return (int) $userId != $hrm->getId();
  53. });
  54. UserManager::clearHrmRequestsForUser($hrm, $usersId);
  55. UserManager::requestUsersToHRManager($hrm->getId(), $usersId, false);
  56. Display::addFlash(
  57. Display::return_message(get_lang('LinkingRequestsAdded'), 'success')
  58. );
  59. header('Location: '.api_get_self());
  60. exit;
  61. }
  62. $usersAssigned = UserManager::get_users_followed_by_drh($hrm->getId());
  63. $content = $form->returnForm();
  64. $content .= Display::page_subheader(get_lang('AssignedUsersListToHumanResourcesManager'));
  65. $content .= '<div class="row">';
  66. foreach ($usersAssigned as $userAssigned) {
  67. $userAssigned = api_get_user_info($userAssigned['user_id']);
  68. $userPicture = isset($userAssigned["avatar_medium"]) ? $userAssigned["avatar_medium"] : $userAssigned["avatar"];
  69. $studentLink = api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$userAssigned['user_id'];
  70. $content .= '
  71. <div class="col-sm-4 col-md-3">
  72. <div class="media">
  73. <div class="media-left">
  74. ';
  75. $content .= '<a href="'.$studentLink.'">';
  76. $content .= Display::img($userPicture, $userAssigned['complete_name'], ['class' => 'media-object'], false);
  77. $content .= '</a>';
  78. $content .= '
  79. </div>
  80. <div class="media-body">
  81. <h4 class="media-heading"><a href="'.$studentLink.'">'.$userAssigned['complete_name'].'</a></h4>
  82. '.$userAssigned['username'].'
  83. </div>
  84. </div>
  85. </div>
  86. ';
  87. }
  88. $content .= '</div>';
  89. $toolName = get_lang('RequestLinkingToUser');
  90. $view = new Template($toolName);
  91. $view->assign('header', $toolName);
  92. $view->assign('content', $content);
  93. $view->display_one_col_template();