group_view.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. $language_file = array('userInfo');
  9. require_once '../inc/global.inc.php';
  10. api_block_anonymous_users();
  11. if (api_get_setting('allow_social_tool') !='true') {
  12. api_not_allowed();
  13. }
  14. $this_section = SECTION_SOCIAL;
  15. // prepare anchor for message group topic
  16. $anchor = '';
  17. if (isset($_GET['anchor_topic'])) {
  18. $anchor = Security::remove_XSS($_GET['anchor_topic']);
  19. } else {
  20. $match = 0;
  21. $param_names = array_keys($_GET);
  22. foreach ($param_names as $param) {
  23. if (preg_match('/^items_(\d)_page_nr$/', $param, $match)) {
  24. break;
  25. }
  26. }
  27. if (isset($match[1])) {
  28. $anchor = 'topic_'.$match[1];
  29. }
  30. }
  31. $htmlHeadXtra[] = '<script>
  32. var counter_image = 1;
  33. function remove_image_form(id_elem1) {
  34. var elem1 = document.getElementById(id_elem1);
  35. elem1.parentNode.removeChild(elem1);
  36. counter_image--;
  37. var filepaths = document.getElementById("filepaths");
  38. if (filepaths.childNodes.length < 3) {
  39. var link_attach = document.getElementById("link-more-attach");
  40. if (link_attach) {
  41. link_attach.innerHTML=\'<a href="javascript://" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</a>\';
  42. }
  43. }
  44. }
  45. function add_image_form() {
  46. // Multiple filepaths for image form
  47. var filepaths = document.getElementById("filepaths");
  48. if (document.getElementById("filepath_"+counter_image)) {
  49. counter_image = counter_image + 1;
  50. } else {
  51. counter_image = counter_image;
  52. }
  53. var elem1 = document.createElement("div");
  54. elem1.setAttribute("id","filepath_"+counter_image);
  55. filepaths.appendChild(elem1);
  56. id_elem1 = "filepath_"+counter_image;
  57. id_elem1 = "\'"+id_elem1+"\'";
  58. document.getElementById("filepath_"+counter_image).innerHTML = "<input type=\"file\" name=\"attach_"+counter_image+"\" size=\"20\" />&nbsp;<a href=\"javascript:remove_image_form("+id_elem1+")\"><img src=\"'.api_get_path(WEB_IMG_PATH).'delete.gif\"></a>";
  59. if (filepaths.childNodes.length == 3) {
  60. var link_attach = document.getElementById("link-more-attach");
  61. if (link_attach) {
  62. link_attach.innerHTML="";
  63. }
  64. }
  65. }
  66. function validate_text_empty (str,msg) {
  67. var str = str.replace(/^\s*|\s*$/g,"");
  68. if (str.length == 0) {
  69. alert(msg);
  70. return true;
  71. }
  72. }
  73. </script>';
  74. $allowed_views = array('mygroups','newest','pop');
  75. $content = null;
  76. if (isset($_GET['view']) && in_array($_GET['view'],$allowed_views)) {
  77. if ($_GET['view'] == 'mygroups') {
  78. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  79. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('MyGroups'));
  80. } else if ( $_GET['view'] == 'newest') {
  81. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  82. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Newest'));
  83. } else {
  84. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  85. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Popular'));
  86. }
  87. } else {
  88. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  89. if (!isset($_GET['id'])) {
  90. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('GroupList'));
  91. } else {
  92. //$interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Group'));
  93. }
  94. }
  95. // getting group information
  96. $group_id = isset($_GET['id']) ? intval($_GET['id']) : null;
  97. $relation_group_title = '';
  98. $role = 0;
  99. $usergroup = new UserGroup();
  100. if ($group_id != 0) {
  101. $group_info = $usergroup->get($group_id);
  102. $interbreadcrumb[]= array ('url' =>'#','name' => $group_info['name']);
  103. if (isset($_GET['action']) && $_GET['action']=='leave') {
  104. $user_leaved = intval($_GET['u']);
  105. //I can "leave me myself"
  106. if (api_get_user_id() == $user_leaved) {
  107. $usergroup->delete_user_rel_group($user_leaved, $group_id);
  108. Display::addFlash(
  109. Display::return_message(get_lang('UserIsNotSubscribedToThisGroup'), 'confirmation', false)
  110. );
  111. }
  112. }
  113. // add a user to a group if its open
  114. if (isset($_GET['action']) && $_GET['action']=='join') {
  115. // we add a user only if is a open group
  116. $user_join = intval($_GET['u']);
  117. if (api_get_user_id() == $user_join && !empty($group_id)) {
  118. if ($group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  119. $usergroup->add_user_to_group($user_join, $group_id);
  120. Display::addFlash(
  121. Display::return_message(get_lang('UserIsSubscribedToThisGroup'), 'confirmation', false)
  122. );
  123. } else {
  124. $usergroup->add_user_to_group(
  125. $user_join,
  126. $group_id,
  127. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER
  128. );
  129. Display::addFlash(
  130. Display::return_message(get_lang('InvitationSent'), 'confirmation', false)
  131. );
  132. }
  133. }
  134. }
  135. }
  136. $create_thread_link = '';
  137. $social_right_content = null;
  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 .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.
  156. get_lang('JoinGroup').'</a>';
  157. } elseif ($role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  158. $social_right_content .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.
  159. get_lang('YouHaveBeenInvitedJoinNow').'</a>';
  160. }
  161. $social_right_content .= '<br /><br />';
  162. }
  163. $content = MessageManager::display_messages_for_group($group_id);
  164. if ($is_group_member) {
  165. if (empty($content)) {
  166. $createThreadUrl = api_get_path(WEB_CODE_PATH)
  167. . 'social/message_for_group_form.inc.php?'
  168. . http_build_query([
  169. 'view_panel' => 1,
  170. 'user_friend' => api_get_user_id(),
  171. 'group_id' => $group_id,
  172. 'action' => 'add_message_group'
  173. ]);
  174. $create_thread_link = Display::url(
  175. get_lang('YouShouldCreateATopic'),
  176. $createThreadUrl,
  177. [
  178. 'class' => 'ajax btn btn-default',
  179. 'title' => get_lang('ComposeMessage'),
  180. 'data-title' => get_lang('ComposeMessage')
  181. ]
  182. );
  183. } else {
  184. $createThreadUrl = api_get_path(WEB_CODE_PATH)
  185. . 'social/message_for_group_form.inc.php?'
  186. . http_build_query([
  187. 'view_panel' => 1,
  188. 'user_friend' => api_get_user_id(),
  189. 'group_id' => $group_id,
  190. 'action' => 'add_message_group',
  191. ]);
  192. $create_thread_link = Display::url(
  193. get_lang('NewTopic'),
  194. $createThreadUrl,
  195. [
  196. 'class' => 'ajax btn btn-default',
  197. 'title' => get_lang('ComposeMessage'),
  198. 'data-title' => get_lang('ComposeMessage')
  199. ]
  200. );
  201. }
  202. }
  203. $members = $usergroup->get_users_by_group($group_id, true);
  204. $member_content = '';
  205. // Members
  206. if (count($members) > 0) {
  207. if ($role == GROUP_USER_PERMISSION_ADMIN) {
  208. $member_content .= Display::url(
  209. Display::return_icon('edit.gif', get_lang('EditMembersList')).' '.get_lang('EditMembersList'),
  210. 'group_members.php?id='.$group_id
  211. );
  212. }
  213. foreach ($members as $member) {
  214. // if is a member
  215. if (in_array($member['relation_type'],
  216. array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER,GROUP_USER_PERMISSION_MODERATOR))
  217. ) {
  218. //add icons
  219. if ($member['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  220. $icon= Display::return_icon('social_group_admin.png', get_lang('Admin'));
  221. } elseif ($member['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  222. $icon= Display::return_icon('social_group_moderator.png', get_lang('Moderator'));
  223. } else {
  224. $icon= '';
  225. }
  226. $userPicture = UserManager::getUserPicture($member['user_id']);
  227. $member_content .= '<div class="">';
  228. $member_name = Display::url(api_get_person_name(cut($member['firstname'],15),cut($member['lastname'],15)).'&nbsp;'.$icon, $member['user_info']['profile_url']);
  229. $member_content .= Display::div('<img class="social-groups-image" src="'.$userPicture.'"/>&nbsp'.$member_name);
  230. $member_content .= '</div>';
  231. }
  232. }
  233. }
  234. if (!empty($create_thread_link)) {
  235. $create_thread_link = Display::div($create_thread_link, array('class'=>'pull-right'));
  236. }
  237. $headers = array(get_lang('Discussions'), get_lang('Members'));
  238. $social_right_content .= Display::tabs($headers, array($content, $member_content),'tabs');
  239. } else {
  240. // if I already sent an invitation message
  241. if (!in_array(
  242. $role,
  243. array(
  244. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER,
  245. GROUP_USER_PERMISSION_PENDING_INVITATION,
  246. )
  247. )
  248. ) {
  249. $social_right_content .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a>';
  250. } elseif ($role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  251. $social_right_content .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('YouHaveBeenInvitedJoinNow').'</a>';
  252. }
  253. }
  254. $tpl = new Template(null);
  255. // Block Social Avatar
  256. SocialManager::setSocialUserBlock($tpl, $user_id, 'groups', $group_id);
  257. //Block Social Menu
  258. $social_menu_block = SocialManager::show_social_menu('groups', $group_id);
  259. $tpl->setHelp('Groups');
  260. $tpl->assign('create_link', $create_thread_link);
  261. $tpl->assign('is_group_member', $is_group_member);
  262. $tpl->assign('group_info', $group_info);
  263. $tpl->assign('social_menu_block', $social_menu_block);
  264. $tpl->assign('social_right_content', $social_right_content);
  265. $social_layout = $tpl->get_template('social/group_view.tpl');
  266. $tpl->display($social_layout);