group_view.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. function validate_text_empty (str,msg) {
  71. var str = str.replace(/^\s*|\s*$/g,"");
  72. if (str.length == 0) {
  73. alert(msg);
  74. return true;
  75. }
  76. }
  77. </script>';
  78. $allowed_views = array('mygroups', 'newest', 'pop');
  79. $content = null;
  80. if (isset($_GET['view']) && in_array($_GET['view'], $allowed_views)) {
  81. if ($_GET['view'] == 'mygroups') {
  82. $interbreadcrumb[] = array('url' =>'groups.php', 'name' => get_lang('Groups'));
  83. $interbreadcrumb[] = array('url' =>'#', 'name' => get_lang('MyGroups'));
  84. } else if ($_GET['view'] == 'newest') {
  85. $interbreadcrumb[] = array('url' =>'groups.php', 'name' => get_lang('Groups'));
  86. $interbreadcrumb[] = array('url' =>'#', 'name' => get_lang('Newest'));
  87. } else {
  88. $interbreadcrumb[] = array('url' =>'groups.php', 'name' => get_lang('Groups'));
  89. $interbreadcrumb[] = array('url' =>'#', 'name' => get_lang('Popular'));
  90. }
  91. } else {
  92. $interbreadcrumb[] = array('url' =>'groups.php', 'name' => get_lang('Groups'));
  93. if (!isset($_GET['id'])) {
  94. $interbreadcrumb[] = array('url' =>'#', 'name' => get_lang('GroupList'));
  95. } else {
  96. //$interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Group'));
  97. }
  98. }
  99. // getting group information
  100. $group_id = isset($_GET['id']) ? intval($_GET['id']) : null;
  101. $relation_group_title = '';
  102. $role = 0;
  103. $usergroup = new UserGroup();
  104. if ($group_id != 0) {
  105. $group_info = $usergroup->get($group_id);
  106. $interbreadcrumb[] = array('url' =>'#', 'name' => $group_info['name']);
  107. if (isset($_GET['action']) && $_GET['action'] == 'leave') {
  108. $user_leaved = intval($_GET['u']);
  109. // I can "leave me myself"
  110. if (api_get_user_id() == $user_leaved) {
  111. if (UserGroup::canLeave($group_info)) {
  112. $usergroup->delete_user_rel_group($user_leaved, $group_id);
  113. Display::addFlash(
  114. Display::return_message(get_lang('UserIsNotSubscribedToThisGroup'), 'confirmation', false)
  115. );
  116. }
  117. }
  118. }
  119. // add a user to a group if its open
  120. if (isset($_GET['action']) && $_GET['action'] == 'join') {
  121. // we add a user only if is a open group
  122. $user_join = intval($_GET['u']);
  123. if (api_get_user_id() == $user_join && !empty($group_id)) {
  124. if ($group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  125. $usergroup->add_user_to_group($user_join, $group_id);
  126. Display::addFlash(
  127. Display::return_message(get_lang('UserIsSubscribedToThisGroup'), 'confirmation', false)
  128. );
  129. } else {
  130. $usergroup->add_user_to_group(
  131. $user_join,
  132. $group_id,
  133. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER
  134. );
  135. Display::addFlash(
  136. Display::return_message(get_lang('InvitationSent'), 'confirmation', false)
  137. );
  138. }
  139. }
  140. }
  141. }
  142. $create_thread_link = '';
  143. $social_right_content = null;
  144. $socialForum = '';
  145. $group_info = $usergroup->get($group_id);
  146. //Loading group information
  147. if (isset($_GET['status']) && $_GET['status'] == 'sent') {
  148. $social_right_content .= Display::return_message(get_lang('MessageHasBeenSent'), 'confirmation', false);
  149. }
  150. $is_group_member = $usergroup->is_group_member($group_id);
  151. $role = $usergroup->get_user_group_role(api_get_user_id(), $group_id);
  152. if (!$is_group_member && $group_info['visibility'] == GROUP_PERMISSION_CLOSED) {
  153. if ($role == GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER) {
  154. $social_right_content .= Display::return_message(get_lang('YouAlreadySentAnInvitation'));
  155. }
  156. }
  157. if ($is_group_member || $group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  158. if (!$is_group_member) {
  159. if (!in_array($role,
  160. array(GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER, GROUP_USER_PERMISSION_PENDING_INVITATION))
  161. ) {
  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. get_lang('JoinGroup').'</a>';
  166. $social_right_content .= '</div>';
  167. $social_right_content .= '</div>';
  168. } elseif ($role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  169. $social_right_content .= '<div class="group-tool">';
  170. $social_right_content .= '<div class="pull-right">';
  171. $social_right_content .= '<a class="btn btn-default btn-sm" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.
  172. Display::returnFontAwesomeIcon('envelope').' '.
  173. get_lang('YouHaveBeenInvitedJoinNow').'</a>';
  174. }
  175. $social_right_content .= '</div>';
  176. $social_right_content .= '</div>';
  177. }
  178. $content = MessageManager::display_messages_for_group($group_id);
  179. if ($is_group_member) {
  180. if (empty($content)) {
  181. $createThreadUrl = api_get_path(WEB_CODE_PATH)
  182. . 'social/message_for_group_form.inc.php?'
  183. . http_build_query([
  184. 'view_panel' => 1,
  185. 'user_friend' => api_get_user_id(),
  186. 'group_id' => $group_id,
  187. 'action' => 'add_message_group'
  188. ]);
  189. $create_thread_link = Display::url(
  190. Display::returnFontAwesomeIcon('commenting').' '.
  191. get_lang('YouShouldCreateATopic'),
  192. $createThreadUrl,
  193. [
  194. 'class' => 'ajax btn btn-primary',
  195. 'title' => get_lang('ComposeMessage'),
  196. 'data-title' => get_lang('ComposeMessage'),
  197. 'data-size' => 'lg'
  198. ]
  199. );
  200. } else {
  201. $createThreadUrl = api_get_path(WEB_CODE_PATH)
  202. . 'social/message_for_group_form.inc.php?'
  203. . http_build_query([
  204. 'view_panel' => 1,
  205. 'user_friend' => api_get_user_id(),
  206. 'group_id' => $group_id,
  207. 'action' => 'add_message_group',
  208. ]);
  209. $create_thread_link = Display::url(
  210. Display::returnFontAwesomeIcon('commenting').' '.
  211. get_lang('NewTopic'),
  212. $createThreadUrl,
  213. [
  214. 'class' => 'ajax btn btn-default',
  215. 'title' => get_lang('ComposeMessage'),
  216. 'data-title' => get_lang('ComposeMessage'),
  217. 'data-size' => 'lg'
  218. ]
  219. );
  220. }
  221. }
  222. $members = $usergroup->get_users_by_group($group_id, true);
  223. $member_content = '';
  224. // My friends
  225. $friend_html = SocialManager::listMyFriendsBlock(
  226. $user_id,
  227. '',
  228. ''
  229. );
  230. // Members
  231. if (count($members) > 0) {
  232. if ($role == GROUP_USER_PERMISSION_ADMIN) {
  233. $member_content .= '<div class="group-tool">';
  234. $member_content .= '<div class="pull-right">';
  235. $member_content .= Display::url(
  236. Display::returnFontAwesomeIcon('pencil').' '.get_lang('EditMembersList'),
  237. 'group_members.php?id='.$group_id,
  238. array('class'=>'btn btn-default btn-sm', 'title' => get_lang('EditMembersList'))
  239. );
  240. $member_content .= '</div>';
  241. $member_content .= '</div>';
  242. }
  243. $member_content .= '<div class="user-list">';
  244. $member_content .= '<div class="row">';
  245. foreach ($members as $member) {
  246. // if is a member
  247. if (in_array($member['relation_type'],
  248. array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_MODERATOR))
  249. ) {
  250. //add icons
  251. if ($member['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  252. $icon = Display::return_icon('social_group_admin.png', get_lang('Admin'));
  253. } elseif ($member['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  254. $icon = Display::return_icon('social_group_moderator.png', get_lang('Moderator'));
  255. } else {
  256. $icon = '';
  257. }
  258. $userPicture = UserManager::getUserPicture($member['id']);
  259. $member_content .= '<div class="col-md-3">';
  260. $member_content .= '<div class="items-user">';
  261. $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']);
  262. $member_content .= Display::div('<img class="img-circle" src="'.$userPicture.'"/>', array('class' => 'avatar'));
  263. $member_content .= Display::div($member_name, array('class' => 'name'));
  264. $member_content .= '</div>';
  265. $member_content .= '</div>';
  266. }
  267. }
  268. $member_content .= '</div>';
  269. $member_content .= '</div>';
  270. }
  271. if (!empty($create_thread_link)) {
  272. $create_thread_link = Display::div($create_thread_link, array('class'=>'pull-right'));
  273. }
  274. $headers = array(get_lang('Discussions'), get_lang('Members'));
  275. $socialForum = Display::tabs($headers, array($content, $member_content), 'tabs');
  276. } else {
  277. // if I already sent an invitation message
  278. if (!in_array(
  279. $role,
  280. array(
  281. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER,
  282. GROUP_USER_PERMISSION_PENDING_INVITATION,
  283. )
  284. )
  285. ) {
  286. $social_right_content .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a>';
  287. } elseif ($role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  288. $social_right_content .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('YouHaveBeenInvitedJoinNow').'</a>';
  289. }
  290. }
  291. $tpl = new Template(null);
  292. // Block Social Avatar
  293. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'groups', $group_id);
  294. //Block Social Menu
  295. $social_menu_block = SocialManager::show_social_menu('groups', $group_id);
  296. $tpl->setHelp('Groups');
  297. $tpl->assign('create_link', $create_thread_link);
  298. $tpl->assign('is_group_member', $is_group_member);
  299. $tpl->assign('group_info', $group_info);
  300. $tpl->assign('social_friend_block', $friend_html);
  301. $tpl->assign('social_menu_block', $social_menu_block);
  302. $tpl->assign('social_forum', $socialForum);
  303. $tpl->assign('social_right_content', $social_right_content);
  304. $social_layout = $tpl->get_template('social/group_view.tpl');
  305. $tpl->display($social_layout);