group_view.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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('social.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. if (UserGroup::canLeave($group_info)) {
  113. $usergroup->delete_user_rel_group($user_leaved, $group_id);
  114. Display::addFlash(
  115. Display::return_message(get_lang('UserIsNotSubscribedToThisGroup'), 'confirmation', false)
  116. );
  117. }
  118. }
  119. }
  120. // add a user to a group if its open
  121. if (isset($_GET['action']) && $_GET['action']=='join') {
  122. // we add a user only if is a open group
  123. $user_join = intval($_GET['u']);
  124. if (api_get_user_id() == $user_join && !empty($group_id)) {
  125. if ($group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  126. $usergroup->add_user_to_group($user_join, $group_id);
  127. Display::addFlash(
  128. Display::return_message(get_lang('UserIsSubscribedToThisGroup'), 'confirmation', false)
  129. );
  130. } else {
  131. $usergroup->add_user_to_group(
  132. $user_join,
  133. $group_id,
  134. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER
  135. );
  136. Display::addFlash(
  137. Display::return_message(get_lang('InvitationSent'), 'confirmation', false)
  138. );
  139. }
  140. }
  141. }
  142. }
  143. $create_thread_link = '';
  144. $social_right_content = null;
  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 .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.
  163. get_lang('JoinGroup').'</a>';
  164. } elseif ($role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  165. $social_right_content .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.
  166. get_lang('YouHaveBeenInvitedJoinNow').'</a>';
  167. }
  168. $social_right_content .= '<br /><br />';
  169. }
  170. $content = MessageManager::display_messages_for_group($group_id);
  171. if ($is_group_member) {
  172. if (empty($content)) {
  173. $createThreadUrl = api_get_path(WEB_CODE_PATH)
  174. . 'social/message_for_group_form.inc.php?'
  175. . http_build_query([
  176. 'view_panel' => 1,
  177. 'user_friend' => api_get_user_id(),
  178. 'group_id' => $group_id,
  179. 'action' => 'add_message_group'
  180. ]);
  181. $create_thread_link = Display::url(
  182. get_lang('YouShouldCreateATopic'),
  183. $createThreadUrl,
  184. [
  185. 'class' => 'ajax btn btn-default',
  186. 'title' => get_lang('ComposeMessage'),
  187. 'data-title' => get_lang('ComposeMessage'),
  188. 'data-size' => 'lg'
  189. ]
  190. );
  191. } else {
  192. $createThreadUrl = api_get_path(WEB_CODE_PATH)
  193. . 'social/message_for_group_form.inc.php?'
  194. . http_build_query([
  195. 'view_panel' => 1,
  196. 'user_friend' => api_get_user_id(),
  197. 'group_id' => $group_id,
  198. 'action' => 'add_message_group',
  199. ]);
  200. $create_thread_link = Display::url(
  201. get_lang('NewTopic'),
  202. $createThreadUrl,
  203. [
  204. 'class' => 'ajax btn btn-default',
  205. 'title' => get_lang('ComposeMessage'),
  206. 'data-title' => get_lang('ComposeMessage'),
  207. 'data-size' => 'lg'
  208. ]
  209. );
  210. }
  211. }
  212. $members = $usergroup->get_users_by_group($group_id, true);
  213. $member_content = '';
  214. // Members
  215. if (count($members) > 0) {
  216. if ($role == GROUP_USER_PERMISSION_ADMIN) {
  217. $member_content .= Display::url(
  218. Display::return_icon('edit.gif', get_lang('EditMembersList')).' '.get_lang('EditMembersList'),
  219. 'group_members.php?id='.$group_id
  220. );
  221. }
  222. foreach ($members as $member) {
  223. // if is a member
  224. if (in_array($member['relation_type'],
  225. array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER,GROUP_USER_PERMISSION_MODERATOR))
  226. ) {
  227. //add icons
  228. if ($member['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  229. $icon= Display::return_icon('social_group_admin.png', get_lang('Admin'));
  230. } elseif ($member['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  231. $icon= Display::return_icon('social_group_moderator.png', get_lang('Moderator'));
  232. } else {
  233. $icon= '';
  234. }
  235. $userPicture = UserManager::getUserPicture($member['id']);
  236. $member_content .= '<div class="">';
  237. $member_name = Display::url(api_get_person_name(cut($member['firstname'],15),cut($member['lastname'],15)).'&nbsp;'.$icon, $member['user_info']['profile_url']);
  238. $member_content .= Display::div('<img class="social-groups-image img-circle" src="'.$userPicture.'"/>&nbsp'.$member_name);
  239. $member_content .= '</div>';
  240. }
  241. }
  242. }
  243. if (!empty($create_thread_link)) {
  244. $create_thread_link = Display::div($create_thread_link, array('class'=>'pull-right'));
  245. }
  246. $headers = array(get_lang('Discussions'), get_lang('Members'));
  247. $social_right_content .= Display::tabs($headers, array($content, $member_content),'tabs');
  248. } else {
  249. // if I already sent an invitation message
  250. if (!in_array(
  251. $role,
  252. array(
  253. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER,
  254. GROUP_USER_PERMISSION_PENDING_INVITATION,
  255. )
  256. )
  257. ) {
  258. $social_right_content .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a>';
  259. } elseif ($role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  260. $social_right_content .= '<a class="btn" href="group_view.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('YouHaveBeenInvitedJoinNow').'</a>';
  261. }
  262. }
  263. $tpl = \Chamilo\CoreBundle\Framework\Container::getTwig();
  264. // Block Social Avatar
  265. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'groups', $group_id);
  266. //Block Social Menu
  267. $social_menu_block = SocialManager::show_social_menu('groups', $group_id);
  268. //$tpl->setHelp('Groups');
  269. $tpl->addGlobal('create_link', $create_thread_link);
  270. $tpl->addGlobal('social_auto_extend_link', '');
  271. $tpl->addGlobal('is_group_member', $is_group_member);
  272. $tpl->addGlobal('group_info', $group_info);
  273. $tpl->addGlobal('social_menu_block', $social_menu_block);
  274. $tpl->addGlobal('social_right_content', $social_right_content);
  275. echo $tpl->render('@template_style/social/group_view.html.twig');