group_view.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.social
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. */
  7. $cidReset = true;
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. api_block_anonymous_users();
  10. if (api_get_setting('allow_social_tool') !== 'true') {
  11. api_not_allowed();
  12. }
  13. $this_section = SECTION_SOCIAL;
  14. // prepare anchor for message group topic
  15. $anchor = '';
  16. if (isset($_GET['anchor_topic'])) {
  17. $anchor = Security::remove_XSS($_GET['anchor_topic']);
  18. } else {
  19. $match = 0;
  20. $param_names = array_keys($_GET);
  21. foreach ($param_names as $param) {
  22. if (preg_match('/^items_(\d)_page_nr$/', $param, $match)) {
  23. break;
  24. }
  25. }
  26. if (isset($match[1])) {
  27. $anchor = 'topic_'.$match[1];
  28. }
  29. }
  30. $htmlHeadXtra[] = '<script>
  31. var counter_image = 1;
  32. function remove_image_form(id_elem1) {
  33. var elem1 = document.getElementById(id_elem1);
  34. elem1.parentNode.removeChild(elem1);
  35. counter_image--;
  36. var filepaths = document.getElementById("filepaths");
  37. if (filepaths.childNodes.length < 3) {
  38. var link_attach = document.getElementById("link-more-attach");
  39. if (link_attach) {
  40. link_attach.innerHTML=\'<a href="javascript://" class="btn btn-default" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</a>\';
  41. }
  42. }
  43. }
  44. function add_image_form() {
  45. // Multiple filepaths for image form
  46. var filepaths = document.getElementById("filepaths");
  47. if (document.getElementById("filepath_"+counter_image)) {
  48. counter_image = counter_image + 1;
  49. } else {
  50. counter_image = counter_image;
  51. }
  52. var elem1 = document.createElement("div");
  53. elem1.setAttribute("id","filepath_"+counter_image);
  54. filepaths.appendChild(elem1);
  55. id_elem1 = "filepath_"+counter_image;
  56. id_elem1 = "\'"+id_elem1+"\'";
  57. document.getElementById("filepath_"+counter_image).innerHTML = "\n\
  58. <input type=\"file\" name=\"attach_"+counter_image+"\" size=\"20\" />\n\
  59. <a href=\"javascript:remove_image_form("+id_elem1+")\">\n\
  60. <img src=\"' . Display::returnIconPath('delete.gif').'\">\n\
  61. </a>\n\
  62. ";
  63. if (filepaths.childNodes.length == 3) {
  64. var link_attach = document.getElementById("link-more-attach");
  65. if (link_attach) {
  66. link_attach.innerHTML="";
  67. }
  68. }
  69. }
  70. </script>';
  71. $allowed_views = array('mygroups', 'newest', 'pop');
  72. $content = null;
  73. if (isset($_GET['view']) && in_array($_GET['view'], $allowed_views)) {
  74. if ($_GET['view'] == 'mygroups') {
  75. $interbreadcrumb[] = array('url' =>'groups.php', 'name' => get_lang('Groups'));
  76. $interbreadcrumb[] = array('url' =>'#', 'name' => get_lang('MyGroups'));
  77. } else if ($_GET['view'] == 'newest') {
  78. $interbreadcrumb[] = array('url' =>'groups.php', 'name' => get_lang('Groups'));
  79. $interbreadcrumb[] = array('url' =>'#', 'name' => get_lang('Newest'));
  80. } else {
  81. $interbreadcrumb[] = array('url' =>'groups.php', 'name' => get_lang('Groups'));
  82. $interbreadcrumb[] = array('url' =>'#', 'name' => get_lang('Popular'));
  83. }
  84. } else {
  85. $interbreadcrumb[] = array('url' =>'groups.php', 'name' => get_lang('Groups'));
  86. if (!isset($_GET['id'])) {
  87. $interbreadcrumb[] = array('url' =>'#', 'name' => get_lang('GroupList'));
  88. } else {
  89. //$interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Group'));
  90. }
  91. }
  92. // getting group information
  93. $group_id = isset($_GET['id']) ? intval($_GET['id']) : null;
  94. $relation_group_title = '';
  95. $role = 0;
  96. $usergroup = new UserGroup();
  97. if ($group_id != 0) {
  98. $group_info = $usergroup->get($group_id);
  99. $interbreadcrumb[] = array('url' =>'#', 'name' => $group_info['name']);
  100. if (isset($_GET['action']) && $_GET['action'] == 'leave') {
  101. $user_leaved = intval($_GET['u']);
  102. // I can "leave me myself"
  103. if (api_get_user_id() == $user_leaved) {
  104. if (UserGroup::canLeave($group_info)) {
  105. $usergroup->delete_user_rel_group($user_leaved, $group_id);
  106. Display::addFlash(
  107. Display::return_message(get_lang('UserIsNotSubscribedToThisGroup'), 'confirmation', false)
  108. );
  109. }
  110. }
  111. }
  112. // add a user to a group if its open
  113. if (isset($_GET['action']) && $_GET['action'] == 'join') {
  114. // we add a user only if is a open group
  115. $user_join = intval($_GET['u']);
  116. if (api_get_user_id() == $user_join && !empty($group_id)) {
  117. if ($group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  118. $usergroup->add_user_to_group($user_join, $group_id);
  119. Display::addFlash(
  120. Display::return_message(get_lang('UserIsSubscribedToThisGroup'), 'confirmation', false)
  121. );
  122. } else {
  123. $usergroup->add_user_to_group(
  124. $user_join,
  125. $group_id,
  126. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER
  127. );
  128. Display::addFlash(
  129. Display::return_message(get_lang('InvitationSent'), 'confirmation', false)
  130. );
  131. }
  132. }
  133. }
  134. }
  135. $create_thread_link = '';
  136. $social_right_content = null;
  137. $socialForum = '';
  138. $group_info = $usergroup->get($group_id);
  139. //Loading group information
  140. if (isset($_GET['status']) && $_GET['status'] == 'sent') {
  141. $social_right_content .= Display::return_message(get_lang('MessageHasBeenSent'), 'confirmation', false);
  142. }
  143. $is_group_member = $usergroup->is_group_member($group_id);
  144. $role = $usergroup->get_user_group_role(api_get_user_id(), $group_id);
  145. if (!$is_group_member && $group_info['visibility'] == GROUP_PERMISSION_CLOSED) {
  146. if ($role == GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER) {
  147. $social_right_content .= Display::return_message(get_lang('YouAlreadySentAnInvitation'));
  148. }
  149. }
  150. if ($is_group_member || $group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  151. if (!$is_group_member) {
  152. if (!in_array($role,
  153. array(GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER, GROUP_USER_PERMISSION_PENDING_INVITATION))
  154. ) {
  155. $social_right_content .= '<div class="group-tool">';
  156. $social_right_content .= '<div class="pull-right">';
  157. $social_right_content .= '<a class="btn btn-default btn-sm" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.
  158. get_lang('JoinGroup').'</a>';
  159. $social_right_content .= '</div>';
  160. $social_right_content .= '</div>';
  161. } elseif ($role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  162. $social_right_content .= '<div class="group-tool">';
  163. $social_right_content .= '<div class="pull-right">';
  164. $social_right_content .= '<a class="btn btn-default btn-sm" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.
  165. Display::returnFontAwesomeIcon('envelope').' '.
  166. get_lang('YouHaveBeenInvitedJoinNow').'</a>';
  167. }
  168. $social_right_content .= '</div>';
  169. $social_right_content .= '</div>';
  170. }
  171. $content = MessageManager::display_messages_for_group($group_id);
  172. if ($is_group_member) {
  173. if (empty($content)) {
  174. $createThreadUrl = api_get_path(WEB_CODE_PATH)
  175. . 'social/message_for_group_form.inc.php?'
  176. . http_build_query([
  177. 'view_panel' => 1,
  178. 'user_friend' => api_get_user_id(),
  179. 'group_id' => $group_id,
  180. 'action' => 'add_message_group'
  181. ]);
  182. $create_thread_link = Display::url(
  183. Display::returnFontAwesomeIcon('commenting').' '.
  184. get_lang('YouShouldCreateATopic'),
  185. $createThreadUrl,
  186. [
  187. 'class' => 'ajax btn btn-primary',
  188. 'title' => get_lang('ComposeMessage'),
  189. 'data-title' => get_lang('ComposeMessage'),
  190. 'data-size' => 'lg'
  191. ]
  192. );
  193. } else {
  194. $createThreadUrl = api_get_path(WEB_CODE_PATH)
  195. . 'social/message_for_group_form.inc.php?'
  196. . http_build_query([
  197. 'view_panel' => 1,
  198. 'user_friend' => api_get_user_id(),
  199. 'group_id' => $group_id,
  200. 'action' => 'add_message_group',
  201. ]);
  202. $create_thread_link = Display::url(
  203. Display::returnFontAwesomeIcon('commenting').' '.
  204. get_lang('NewTopic'),
  205. $createThreadUrl,
  206. [
  207. 'class' => 'ajax btn btn-default',
  208. 'title' => get_lang('ComposeMessage'),
  209. 'data-title' => get_lang('ComposeMessage'),
  210. 'data-size' => 'lg'
  211. ]
  212. );
  213. }
  214. }
  215. $members = $usergroup->get_users_by_group($group_id, true);
  216. $member_content = '';
  217. // My friends
  218. $friend_html = SocialManager::listMyFriendsBlock(
  219. api_get_user_id(),
  220. '',
  221. ''
  222. );
  223. // Members
  224. if (count($members) > 0) {
  225. if ($role == GROUP_USER_PERMISSION_ADMIN) {
  226. $member_content .= '<div class="group-tool">';
  227. $member_content .= '<div class="pull-right">';
  228. $member_content .= Display::url(
  229. Display::returnFontAwesomeIcon('pencil').' '.get_lang('EditMembersList'),
  230. 'group_members.php?id='.$group_id,
  231. array('class'=>'btn btn-default btn-sm', 'title' => get_lang('EditMembersList'))
  232. );
  233. $member_content .= '</div>';
  234. $member_content .= '</div>';
  235. }
  236. $member_content .= '<div class="user-list">';
  237. $member_content .= '<div class="row">';
  238. foreach ($members as $member) {
  239. // if is a member
  240. if (in_array($member['relation_type'],
  241. array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_MODERATOR))
  242. ) {
  243. //add icons
  244. if ($member['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  245. $icon = Display::return_icon('social_group_admin.png', get_lang('Admin'));
  246. } elseif ($member['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  247. $icon = Display::return_icon('social_group_moderator.png', get_lang('Moderator'));
  248. } else {
  249. $icon = '';
  250. }
  251. $userPicture = UserManager::getUserPicture($member['id']);
  252. $member_content .= '<div class="col-md-3">';
  253. $member_content .= '<div class="items-user">';
  254. $member_name = Display::url(api_get_person_name(cut($member['user_info']['firstname'], 15), cut($member['user_info']['lastname'], 15)).'&nbsp;'.$icon, $member['user_info']['profile_url']);
  255. $member_content .= Display::div('<img class="img-circle" src="'.$userPicture.'"/>', array('class' => 'avatar'));
  256. $member_content .= Display::div($member_name, array('class' => 'name'));
  257. $member_content .= '</div>';
  258. $member_content .= '</div>';
  259. }
  260. }
  261. $member_content .= '</div>';
  262. $member_content .= '</div>';
  263. }
  264. if (!empty($create_thread_link)) {
  265. $create_thread_link = Display::div($create_thread_link, array('class'=>'pull-right'));
  266. }
  267. $headers = array(get_lang('Discussions'), get_lang('Members'));
  268. $socialForum = Display::tabs($headers, array($content, $member_content), 'tabs');
  269. } else {
  270. // if I already sent an invitation message
  271. if (!in_array(
  272. $role,
  273. array(
  274. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER,
  275. GROUP_USER_PERMISSION_PENDING_INVITATION,
  276. )
  277. )
  278. ) {
  279. $social_right_content .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a>';
  280. } elseif ($role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  281. $social_right_content .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('YouHaveBeenInvitedJoinNow').'</a>';
  282. }
  283. }
  284. $tpl = new Template(null);
  285. // Block Social Avatar
  286. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'groups', $group_id);
  287. //Block Social Menu
  288. $social_menu_block = SocialManager::show_social_menu('groups', $group_id);
  289. $tpl->setHelp('Groups');
  290. $tpl->assign('create_link', $create_thread_link);
  291. $tpl->assign('is_group_member', $is_group_member);
  292. $tpl->assign('group_info', $group_info);
  293. $tpl->assign('social_friend_block', $friend_html);
  294. $socialAjaxUrl = api_get_path(WEB_AJAX_PATH).'social.ajax.php';
  295. $socialAutoExtendLink = Display::url(
  296. get_lang('SeeMore'),
  297. $socialAjaxUrl.'?u='.api_get_user_id(
  298. ).'&a=listWallMessage&start=10&length=5',
  299. array(
  300. 'class' => 'nextPage next',
  301. )
  302. );
  303. $tpl->assign('social_auto_extend_link', $socialAutoExtendLink);
  304. $tpl->assign('social_menu_block', $social_menu_block);
  305. $tpl->assign('social_forum', $socialForum);
  306. $tpl->assign('social_right_content', $social_right_content);
  307. $social_layout = $tpl->get_template('social/group_view.tpl');
  308. $tpl->display($social_layout);