group_view.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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://" class="btn btn-default" 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 = "\n\
  59. <input type=\"file\" name=\"attach_"+counter_image+"\" size=\"20\" />\n\
  60. <a href=\"javascript:remove_image_form("+id_elem1+")\">\n\
  61. <img src=\"' . Display::returnIconPath('delete.gif').'\">\n\
  62. </a>\n\
  63. ";
  64. if (filepaths.childNodes.length == 3) {
  65. var link_attach = document.getElementById("link-more-attach");
  66. if (link_attach) {
  67. link_attach.innerHTML="";
  68. }
  69. }
  70. }
  71. function validate_text_empty (str,msg) {
  72. var str = str.replace(/^\s*|\s*$/g,"");
  73. if (str.length == 0) {
  74. alert(msg);
  75. return true;
  76. }
  77. }
  78. </script>';
  79. $allowed_views = array('mygroups','newest','pop');
  80. $content = null;
  81. if (isset($_GET['view']) && in_array($_GET['view'],$allowed_views)) {
  82. if ($_GET['view'] == 'mygroups') {
  83. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  84. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('MyGroups'));
  85. } else if ( $_GET['view'] == 'newest') {
  86. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  87. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Newest'));
  88. } else {
  89. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  90. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Popular'));
  91. }
  92. } else {
  93. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  94. if (!isset($_GET['id'])) {
  95. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('GroupList'));
  96. } else {
  97. //$interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Group'));
  98. }
  99. }
  100. // getting group information
  101. $group_id = isset($_GET['id']) ? intval($_GET['id']) : null;
  102. $relation_group_title = '';
  103. $role = 0;
  104. $usergroup = new UserGroup();
  105. if ($group_id != 0) {
  106. $group_info = $usergroup->get($group_id);
  107. $interbreadcrumb[]= array ('url' =>'#','name' => $group_info['name']);
  108. if (isset($_GET['action']) && $_GET['action']=='leave') {
  109. $user_leaved = intval($_GET['u']);
  110. //I can "leave me myself"
  111. if (api_get_user_id() == $user_leaved) {
  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. // add a user to a group if its open
  119. if (isset($_GET['action']) && $_GET['action']=='join') {
  120. // we add a user only if is a open group
  121. $user_join = intval($_GET['u']);
  122. if (api_get_user_id() == $user_join && !empty($group_id)) {
  123. if ($group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  124. $usergroup->add_user_to_group($user_join, $group_id);
  125. Display::addFlash(
  126. Display::return_message(get_lang('UserIsSubscribedToThisGroup'), 'confirmation', false)
  127. );
  128. } else {
  129. $usergroup->add_user_to_group(
  130. $user_join,
  131. $group_id,
  132. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER
  133. );
  134. Display::addFlash(
  135. Display::return_message(get_lang('InvitationSent'), 'confirmation', false)
  136. );
  137. }
  138. }
  139. }
  140. }
  141. $create_thread_link = '';
  142. $social_right_content = null;
  143. $group_info = $usergroup->get($group_id);
  144. //Loading group information
  145. if (isset($_GET['status']) && $_GET['status']=='sent') {
  146. $social_right_content .= Display::return_message(get_lang('MessageHasBeenSent'), 'confirmation', false);
  147. }
  148. $is_group_member = $usergroup->is_group_member($group_id);
  149. $role = $usergroup->get_user_group_role(api_get_user_id(), $group_id);
  150. if (!$is_group_member && $group_info['visibility'] == GROUP_PERMISSION_CLOSED) {
  151. if ($role == GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER) {
  152. $social_right_content .= Display::return_message(get_lang('YouAlreadySentAnInvitation'));
  153. }
  154. }
  155. if ($is_group_member || $group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  156. if (!$is_group_member) {
  157. if (!in_array($role,
  158. array(GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER, GROUP_USER_PERMISSION_PENDING_INVITATION))
  159. ) {
  160. $social_right_content .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.
  161. get_lang('JoinGroup').'</a>';
  162. } elseif ($role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  163. $social_right_content .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.
  164. get_lang('YouHaveBeenInvitedJoinNow').'</a>';
  165. }
  166. $social_right_content .= '<br /><br />';
  167. }
  168. $content = MessageManager::display_messages_for_group($group_id);
  169. if ($is_group_member) {
  170. if (empty($content)) {
  171. $createThreadUrl = api_get_path(WEB_CODE_PATH)
  172. . 'social/message_for_group_form.inc.php?'
  173. . http_build_query([
  174. 'view_panel' => 1,
  175. 'user_friend' => api_get_user_id(),
  176. 'group_id' => $group_id,
  177. 'action' => 'add_message_group'
  178. ]);
  179. $create_thread_link = Display::url(
  180. get_lang('YouShouldCreateATopic'),
  181. $createThreadUrl,
  182. [
  183. 'class' => 'ajax btn btn-default',
  184. 'title' => get_lang('ComposeMessage'),
  185. 'data-title' => get_lang('ComposeMessage'),
  186. 'data-size' => 'lg'
  187. ]
  188. );
  189. } else {
  190. $createThreadUrl = api_get_path(WEB_CODE_PATH)
  191. . 'social/message_for_group_form.inc.php?'
  192. . http_build_query([
  193. 'view_panel' => 1,
  194. 'user_friend' => api_get_user_id(),
  195. 'group_id' => $group_id,
  196. 'action' => 'add_message_group',
  197. ]);
  198. $create_thread_link = Display::url(
  199. get_lang('NewTopic'),
  200. $createThreadUrl,
  201. [
  202. 'class' => 'ajax btn btn-default',
  203. 'title' => get_lang('ComposeMessage'),
  204. 'data-title' => get_lang('ComposeMessage'),
  205. 'data-size' => 'lg'
  206. ]
  207. );
  208. }
  209. }
  210. $members = $usergroup->get_users_by_group($group_id, true);
  211. $member_content = '';
  212. // Members
  213. if (count($members) > 0) {
  214. if ($role == GROUP_USER_PERMISSION_ADMIN) {
  215. $member_content .= Display::url(
  216. Display::return_icon('edit.gif', get_lang('EditMembersList')).' '.get_lang('EditMembersList'),
  217. 'group_members.php?id='.$group_id
  218. );
  219. }
  220. foreach ($members as $member) {
  221. // if is a member
  222. if (in_array($member['relation_type'],
  223. array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER,GROUP_USER_PERMISSION_MODERATOR))
  224. ) {
  225. //add icons
  226. if ($member['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  227. $icon= Display::return_icon('social_group_admin.png', get_lang('Admin'));
  228. } elseif ($member['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  229. $icon= Display::return_icon('social_group_moderator.png', get_lang('Moderator'));
  230. } else {
  231. $icon= '';
  232. }
  233. $userPicture = UserManager::getUserPicture($member['id']);
  234. $member_content .= '<div class="">';
  235. $member_name = Display::url(api_get_person_name(cut($member['firstname'],15),cut($member['lastname'],15)).'&nbsp;'.$icon, $member['user_info']['profile_url']);
  236. $member_content .= Display::div('<img class="social-groups-image img-circle" src="'.$userPicture.'"/>&nbsp'.$member_name);
  237. $member_content .= '</div>';
  238. }
  239. }
  240. }
  241. if (!empty($create_thread_link)) {
  242. $create_thread_link = Display::div($create_thread_link, array('class'=>'pull-right'));
  243. }
  244. $headers = array(get_lang('Discussions'), get_lang('Members'));
  245. $social_right_content .= Display::tabs($headers, array($content, $member_content),'tabs');
  246. } else {
  247. // if I already sent an invitation message
  248. if (!in_array(
  249. $role,
  250. array(
  251. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER,
  252. GROUP_USER_PERMISSION_PENDING_INVITATION,
  253. )
  254. )
  255. ) {
  256. $social_right_content .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a>';
  257. } elseif ($role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  258. $social_right_content .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('YouHaveBeenInvitedJoinNow').'</a>';
  259. }
  260. }
  261. $tpl = new Template(null);
  262. // Block Social Avatar
  263. SocialManager::setSocialUserBlock($tpl, $user_id, 'groups', $group_id);
  264. //Block Social Menu
  265. $social_menu_block = SocialManager::show_social_menu('groups', $group_id);
  266. $tpl->setHelp('Groups');
  267. $tpl->assign('create_link', $create_thread_link);
  268. $tpl->assign('is_group_member', $is_group_member);
  269. $tpl->assign('group_info', $group_info);
  270. $tpl->assign('social_menu_block', $social_menu_block);
  271. $tpl->assign('social_right_content', $social_right_content);
  272. $social_layout = $tpl->get_template('social/group_view.tpl');
  273. $tpl->display($social_layout);