groups.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  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. require_once api_get_path(LIBRARY_PATH) . 'group_portal_manager.lib.php';
  15. require_once api_get_path(LIBRARY_PATH) . 'mail.lib.inc.php';
  16. $this_section = SECTION_SOCIAL;
  17. // prepare anchor for message group topic
  18. $anchor = '';
  19. if (isset($_GET['anchor_topic'])) {
  20. $anchor = Security::remove_XSS($_GET['anchor_topic']);
  21. } else {
  22. $match = 0;
  23. $param_names = array_keys($_GET);
  24. foreach ($param_names as $param) {
  25. if (preg_match('/^items_(\d)_page_nr$/', $param, $match)) {
  26. break;
  27. }
  28. }
  29. if (isset($match[1])) {
  30. $anchor = 'topic_' . $match[1];
  31. }
  32. }
  33. $htmlHeadXtra[] = '<script>
  34. var counter_image = 1;
  35. function remove_image_form(id_elem1) {
  36. var elem1 = document.getElementById(id_elem1);
  37. elem1.parentNode.removeChild(elem1);
  38. counter_image--;
  39. var filepaths = document.getElementById("filepaths");
  40. if (filepaths.childNodes.length < 3) {
  41. var link_attach = document.getElementById("link-more-attach");
  42. if (link_attach) {
  43. link_attach.innerHTML=\'<a href="javascript://" onclick="return add_image_form()">' . get_lang(
  44. 'AddOneMoreFile'
  45. ) . '</a>\';
  46. }
  47. }
  48. }
  49. function add_image_form() {
  50. // Multiple filepaths for image form
  51. var filepaths = document.getElementById("filepaths");
  52. if (document.getElementById("filepath_"+counter_image)) {
  53. counter_image = counter_image + 1;
  54. } else {
  55. counter_image = counter_image;
  56. }
  57. var elem1 = document.createElement("div");
  58. elem1.setAttribute("id","filepath_"+counter_image);
  59. filepaths.appendChild(elem1);
  60. id_elem1 = "filepath_"+counter_image;
  61. id_elem1 = "\'"+id_elem1+"\'";
  62. 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(
  63. WEB_CODE_PATH
  64. ) . 'img/delete.gif\"></a>";
  65. if (filepaths.childNodes.length == 3) {
  66. var link_attach = document.getElementById("link-more-attach");
  67. if (link_attach) {
  68. link_attach.innerHTML="";
  69. }
  70. }
  71. }
  72. function validate_text_empty (str,msg) {
  73. var str = str.replace(/^\s*|\s*$/g,"");
  74. if (str.length == 0) {
  75. alert(msg);
  76. return true;
  77. }
  78. }
  79. jQuery(document).ready(function() {
  80. /* Binds a tab id in the url */
  81. $("#tab_browse").bind("tabsselect", function(event, ui) {
  82. window.location.href=ui.tab;
  83. });
  84. $("#tabs").tabs();
  85. $("#tab_browse").tabs();
  86. var valor = "' . $anchor . '";
  87. $(".head").click(function() {
  88. $(this).next().next().slideToggle("fast");
  89. image_clicked = $("#" + this.id + " img").attr("src");
  90. image_clicked_info = image_clicked.split("/");
  91. image_real_clicked = image_clicked_info[image_clicked_info.length-1];
  92. image_path = image_clicked.split("img");
  93. current_path = image_path[0]+"img/";
  94. if (image_real_clicked == "div_show.gif") {
  95. current_path = current_path+"div_hide.gif";
  96. $("#" + this.id + " img").attr("src", current_path);
  97. } else {
  98. current_path = current_path+"div_show.gif";
  99. $("#" + this.id + " img").attr("src", current_path)
  100. }
  101. return false;
  102. }).next().next().hide();
  103. // anchor for current topic
  104. if (valor) {
  105. $("#"+valor).show();
  106. window.location = document.URL+"#"+valor;
  107. }
  108. });
  109. </script>';
  110. $allowed_views = array('mygroups', 'newest', 'pop');
  111. $interbreadcrumb[] = array(
  112. 'url' => 'home.php',
  113. 'name' => get_lang('SocialNetwork')
  114. );
  115. $content = null;
  116. if (isset($_GET['view']) && in_array($_GET['view'], $allowed_views)) {
  117. if ($_GET['view'] == 'mygroups') {
  118. $interbreadcrumb[] = array(
  119. 'url' => 'groups.php',
  120. 'name' => get_lang('Groups')
  121. );
  122. $interbreadcrumb[] = array(
  123. 'url' => '#',
  124. 'name' => get_lang('MyGroups')
  125. );
  126. } else {
  127. if ($_GET['view'] == 'newest') {
  128. $interbreadcrumb[] = array(
  129. 'url' => 'groups.php',
  130. 'name' => get_lang('Groups')
  131. );
  132. $interbreadcrumb[] = array(
  133. 'url' => '#',
  134. 'name' => get_lang('Newest')
  135. );
  136. } else {
  137. $interbreadcrumb[] = array(
  138. 'url' => 'groups.php',
  139. 'name' => get_lang('Groups')
  140. );
  141. $interbreadcrumb[] = array(
  142. 'url' => '#',
  143. 'name' => get_lang('Popular')
  144. );
  145. }
  146. }
  147. } else {
  148. $interbreadcrumb[] = array(
  149. 'url' => 'groups.php',
  150. 'name' => get_lang('Groups')
  151. );
  152. if (!isset($_GET['id'])) {
  153. $interbreadcrumb[] = array(
  154. 'url' => '#',
  155. 'name' => get_lang('GroupList')
  156. );
  157. } else {
  158. //$interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Group'));
  159. }
  160. }
  161. // getting group information
  162. $group_id = isset($_GET['id']) ? intval($_GET['id']) : null;
  163. $relation_group_title = '';
  164. $my_group_role = 0;
  165. if ($group_id != 0) {
  166. $user_leave_message = false;
  167. $user_added_group_message = false;
  168. $user_invitation_sent = false;
  169. $group_info = GroupPortalManager::get_group_data($group_id);
  170. if (!empty($group_id)) {
  171. $interbreadcrumb[] = array('url' => '#', 'name' => $group_info['name']);
  172. }
  173. if (isset($_GET['action']) && $_GET['action'] == 'leave') {
  174. $user_leaved = intval($_GET['u']);
  175. if (GroupPortalManager::canLeave($group_info)) {
  176. // I can "leave me myself"
  177. if (api_get_user_id() == $user_leaved) {
  178. GroupPortalManager::delete_user_rel_group(
  179. $user_leaved,
  180. $group_id
  181. );
  182. $user_leave_message = true;
  183. }
  184. }
  185. }
  186. // add a user to a group if its open
  187. if (isset($_GET['action']) && $_GET['action'] == 'join') {
  188. // we add a user only if is a open group
  189. $user_join = intval($_GET['u']);
  190. if (api_get_user_id() == $user_join && !empty($group_id)) {
  191. if ($group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  192. GroupPortalManager::add_user_to_group($user_join, $group_id);
  193. $user_added_group_message = true;
  194. } else {
  195. GroupPortalManager::add_user_to_group(
  196. $user_join,
  197. $group_id,
  198. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER
  199. );
  200. $user_invitation_sent = true;
  201. }
  202. }
  203. }
  204. }
  205. $create_thread_link = '';
  206. if ($group_id != 0) {
  207. $social_avatar_block = SocialManager::show_social_avatar_block(
  208. 'groups',
  209. $group_id
  210. );
  211. $social_menu_block = SocialManager::show_social_menu('groups', $group_id);
  212. } else {
  213. $show_menu = 'browse_groups';
  214. if (isset($_GET['view']) && $_GET['view'] == 'mygroups') {
  215. $show_menu = $_GET['view'];
  216. }
  217. $social_avatar_block = SocialManager::show_social_avatar_block(
  218. $show_menu,
  219. $group_id
  220. );
  221. $social_menu_block = SocialManager::show_social_menu($show_menu, $group_id);
  222. }
  223. $social_right_content = null;
  224. if ($group_id != 0) {
  225. $group_info = GroupPortalManager::get_group_data($group_id);
  226. //Loading group information
  227. if (isset($_GET['status']) && $_GET['status'] == 'sent') {
  228. $social_right_content .= Display::return_message(
  229. get_lang('MessageHasBeenSent'),
  230. 'confirmation',
  231. false
  232. );
  233. }
  234. if ($user_leave_message) {
  235. $social_right_content .= Display::return_message(
  236. get_lang('UserIsNotSubscribedToThisGroup'),
  237. 'confirmation',
  238. false
  239. );
  240. }
  241. if ($user_added_group_message) {
  242. $social_right_content .= Display::return_message(
  243. get_lang('UserIsSubscribedToThisGroup'),
  244. 'confirmation',
  245. false
  246. );
  247. }
  248. if ($user_invitation_sent) {
  249. $social_right_content .= Display::return_message(
  250. get_lang('InvitationSent'),
  251. 'confirmation',
  252. false
  253. );
  254. }
  255. $is_group_member = GroupPortalManager::is_group_member($group_id);
  256. // details about the current group
  257. $social_right_content = '<div class="span9">';
  258. $social_right_content .= '<div id="social-group-details">';
  259. //Group's title
  260. $social_right_content .= Display::tag(
  261. 'h2',
  262. Security::remove_XSS($group_info['name'], STUDENT, true)
  263. );
  264. //Privacy
  265. if (!$is_group_member) {
  266. $social_right_content .= '<div class="social-group-details-info">';
  267. $social_right_content .= '<span>' . get_lang('Privacy') . ' : </span>';
  268. if ($group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  269. $social_right_content .= get_lang('ThisIsAnOpenGroup');
  270. } elseif ($group_info['visibility'] == GROUP_PERMISSION_CLOSED) {
  271. $social_right_content .= get_lang('ThisIsACloseGroup');
  272. }
  273. $social_right_content .= '</div>';
  274. }
  275. if (!$is_group_member && $group_info['visibility'] == GROUP_PERMISSION_CLOSED) {
  276. $role = GroupPortalManager::get_user_group_role(
  277. api_get_user_id(),
  278. $group_id
  279. );
  280. if ($role == GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER) {
  281. $social_right_content .= Display::return_message(
  282. get_lang('YouAlreadySentAnInvitation')
  283. );
  284. }
  285. }
  286. // Group's tags
  287. if (!empty($tags)) {
  288. $social_right_content .= '<div id="social-group-details-info"><span>' . get_lang(
  289. 'Tags'
  290. ) . ' : </span>' . $tags . '</div>';
  291. }
  292. $social_right_content .= '</div>';
  293. $social_right_content .= '</div>';
  294. //-- Show message groups
  295. $social_right_content .= '<div class="span9">';
  296. if ($is_group_member || $group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  297. if (!$is_group_member) {
  298. if (!in_array(
  299. $my_group_role,
  300. array(
  301. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER,
  302. GROUP_USER_PERMISSION_PENDING_INVITATION
  303. )
  304. )
  305. ) {
  306. $social_right_content .= '<a class="btn" href="groups.php?id=' . $group_id . '&action=join&u=' . api_get_user_id(
  307. ) . '">' . get_lang('JoinGroup') . '</a>';
  308. } elseif ($my_group_role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  309. $social_right_content .= '<a class="btn" href="groups.php?id=' . $group_id . '&action=join&u=' . api_get_user_id(
  310. ) . '">' . get_lang('YouHaveBeenInvitedJoinNow') . '</a>';
  311. }
  312. $social_right_content .= '<br /><br />';
  313. }
  314. $content = MessageManager::display_messages_for_group($group_id);
  315. if ($is_group_member) {
  316. if (empty($content)) {
  317. $create_thread_link = '<a href="' . api_get_path(
  318. WEB_CODE_PATH
  319. ) . 'social/message_for_group_form.inc.php?view_panel=1&height=400&width=610&&user_friend=' . api_get_user_id(
  320. ) . '&group_id=' . $group_id . '&action=add_message_group" class="ajax btn" title="' . get_lang(
  321. 'ComposeMessage'
  322. ) . '">' . get_lang('YouShouldCreateATopic') . '</a></li>';
  323. } else {
  324. $create_thread_link = '<a href="' . api_get_path(
  325. WEB_CODE_PATH
  326. ) . 'social/message_for_group_form.inc.php?view_panel=1&height=400&width=610&&user_friend=' . api_get_user_id(
  327. ) . '&group_id=' . $group_id . '&action=add_message_group" class="ajax btn" title="' . get_lang(
  328. 'ComposeMessage'
  329. ) . '">' . get_lang('NewTopic') . '</a>';
  330. }
  331. }
  332. $members = GroupPortalManager::get_users_by_group($group_id);
  333. $member_content = '';
  334. //Members
  335. if (count($members) > 0) {
  336. if ($my_group_role == GROUP_USER_PERMISSION_ADMIN) {
  337. $member_content .= Display::url(
  338. Display::return_icon(
  339. 'edit.gif',
  340. get_lang('EditMembersList')
  341. ) . ' ' . get_lang('EditMembersList'),
  342. 'group_members.php?id=' . $group_id
  343. );
  344. }
  345. foreach ($members as $member) {
  346. // if is a member
  347. if (in_array(
  348. $member['relation_type'],
  349. array(
  350. GROUP_USER_PERMISSION_ADMIN,
  351. GROUP_USER_PERMISSION_READER,
  352. GROUP_USER_PERMISSION_MODERATOR
  353. )
  354. )
  355. ) {
  356. //add icons
  357. if ($member['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  358. $icon = Display::return_icon(
  359. 'social_group_admin.png',
  360. get_lang('Admin')
  361. );
  362. } elseif ($member['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  363. $icon = Display::return_icon(
  364. 'social_group_moderator.png',
  365. get_lang('Moderator')
  366. );
  367. } else {
  368. $icon = '';
  369. }
  370. $image_path = UserManager::get_user_picture_path_by_id(
  371. $member['user_id'],
  372. 'web',
  373. false,
  374. true
  375. );
  376. $picture = UserManager::get_picture_user(
  377. $member['user_id'],
  378. $image_path['file'],
  379. 60,
  380. USER_IMAGE_SIZE_MEDIUM
  381. );
  382. $member_content .= '<div class="">';
  383. $member_name = Display::url(
  384. api_get_person_name(
  385. cut($member['firstname'], 15),
  386. cut($member['lastname'], 15)
  387. ) . '&nbsp;' . $icon,
  388. 'profile.php?u=' . $member['user_id']
  389. );
  390. $member_content .= Display::div(
  391. '<img height="44" border="2" align="middle" vspace="10" class="social-groups-image" src="' . $picture['file'] . '"/>&nbsp' . $member_name
  392. );
  393. $member_content .= '</div>';
  394. }
  395. }
  396. }
  397. if (!empty($create_thread_link)) {
  398. $create_thread_link = Display::div(
  399. $create_thread_link,
  400. array('style' => 'padding-top:2px;height:40px')
  401. );
  402. }
  403. $headers = array(get_lang('Discussions'), get_lang('Members'));
  404. $social_right_content .= Display::tabs(
  405. $headers,
  406. array($create_thread_link . $content, $member_content),
  407. 'tabs'
  408. );
  409. } else {
  410. // if I already sent an invitation message
  411. if (!in_array(
  412. $my_group_role,
  413. array(
  414. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER,
  415. GROUP_USER_PERMISSION_PENDING_INVITATION
  416. )
  417. )
  418. ) {
  419. $social_right_content .= '<a class="btn" href="groups.php?id=' . $group_id . '&action=join&u=' . api_get_user_id(
  420. ) . '">' . get_lang('JoinGroup') . '</a>';
  421. } elseif ($my_group_role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  422. $social_right_content .= '<a class="btn" href="groups.php?id=' . $group_id . '&action=join&u=' . api_get_user_id(
  423. ) . '">' . get_lang('YouHaveBeenInvitedJoinNow') . '</a>';
  424. }
  425. }
  426. $social_right_content .= '</div>'; // end layout messages
  427. } else {
  428. // My groups -----
  429. $results = GroupPortalManager::get_groups_by_user(api_get_user_id(), 0);
  430. $grid_my_groups = array();
  431. $my_group_list = array();
  432. if (is_array($results) && count($results) > 0) {
  433. foreach ($results as $result) {
  434. $id = $result['id'];
  435. $result['name'] = Security::remove_XSS(
  436. $result['name'],
  437. STUDENT,
  438. true
  439. );
  440. $result['description'] = Security::remove_XSS(
  441. $result['description'],
  442. STUDENT,
  443. true
  444. );
  445. $my_group_list[] = $id;
  446. $url_open = '<a href="groups.php?id=' . $id . '">';
  447. $url_close = '</a>';
  448. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  449. if ($result['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  450. $name .= ' ' . Display::return_icon(
  451. 'social_group_admin.png',
  452. get_lang('Admin'),
  453. array('style' => 'vertical-align:middle')
  454. );
  455. } elseif ($result['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  456. $name .= ' ' . Display::return_icon(
  457. 'social_group_moderator.png',
  458. get_lang('Moderator'),
  459. array('style' => 'vertical-align:middle')
  460. );
  461. }
  462. $count_users_group = count(
  463. GroupPortalManager::get_users_by_group(
  464. $id,
  465. false,
  466. array(
  467. GROUP_USER_PERMISSION_ADMIN,
  468. GROUP_USER_PERMISSION_READER,
  469. GROUP_USER_PERMISSION_MODERATOR
  470. ),
  471. 0,
  472. 1000
  473. )
  474. );
  475. if ($count_users_group == 1) {
  476. $count_users_group = $count_users_group . ' ' . get_lang(
  477. 'Member'
  478. );
  479. } else {
  480. $count_users_group = $count_users_group . ' ' . get_lang(
  481. 'Members'
  482. );
  483. }
  484. $picture = GroupPortalManager::get_picture_group(
  485. $result['id'],
  486. $result['picture_uri'],
  487. 80
  488. );
  489. $result['picture_uri'] = '<img class="social-groups-image" src="' . $picture['file'] . '" hspace="4" height="50" border="2" align="left" width="50" />';
  490. $item_0 = Display::div(
  491. $result['picture_uri'],
  492. array('class' => 'box_description_group_image')
  493. );
  494. $members = Display::span(
  495. $count_users_group,
  496. array('class' => 'box_description_group_member')
  497. );
  498. $item_1 = Display::div(
  499. Display::tag('h3', $url_open . $name . $url_close) . $members,
  500. array('class' => 'box_description_group_title')
  501. );
  502. $item_2 = '';
  503. $item_3 = '';
  504. if ($result['description'] != '') {
  505. $item_3 = '<div class="box_description_group_content" >' . cut(
  506. $result['description'],
  507. 100,
  508. true
  509. ) . '</div>';
  510. } else {
  511. $item_2 = '<div class="box_description_group_title" ><span class="social-groups-text2"></span></div>';
  512. $item_3 = '<div class="box_description_group_content" ></div>';
  513. }
  514. $grid_item_2 = $item_0 . $item_1 . $item_2 . $item_3;
  515. $grid_my_groups[] = array($grid_item_2);
  516. }
  517. }
  518. // Newest groups
  519. $results = GroupPortalManager::get_groups_by_age(4, false);
  520. $grid_newest_groups = array();
  521. foreach ($results as $result) {
  522. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  523. $result['description'] = Security::remove_XSS(
  524. $result['description'],
  525. STUDENT,
  526. true
  527. );
  528. $id = $result['id'];
  529. $url_open = '<a href="groups.php?id=' . $id . '">';
  530. $url_close = '</a>';
  531. $count_users_group = count(
  532. GroupPortalManager::get_users_by_group(
  533. $id,
  534. false,
  535. array(
  536. GROUP_USER_PERMISSION_ADMIN,
  537. GROUP_USER_PERMISSION_READER,
  538. GROUP_USER_PERMISSION_MODERATOR
  539. ),
  540. 0,
  541. 1000
  542. )
  543. );
  544. if ($count_users_group == 1) {
  545. $count_users_group = $count_users_group . ' ' . get_lang('Member');
  546. } else {
  547. $count_users_group = $count_users_group . ' ' . get_lang('Members');
  548. }
  549. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  550. $picture = GroupPortalManager::get_picture_group(
  551. $result['id'],
  552. $result['picture_uri'],
  553. 80
  554. );
  555. $result['picture_uri'] = '<img class="social-groups-image" src="' . $picture['file'] . '" hspace="4" height="50" border="2" align="left" width="50" />';
  556. $item_0 = Display::div(
  557. $result['picture_uri'],
  558. array('class' => 'box_description_group_image')
  559. );
  560. $members = Display::span(
  561. $count_users_group,
  562. array('class' => 'box_description_group_member')
  563. );
  564. $item_1 = Display::div(
  565. Display::tag('h3', $url_open . $name . $url_close) . $members,
  566. array('class' => 'box_description_group_title')
  567. );
  568. if ($result['description'] != '') {
  569. $item_3 = '<div class="box_description_group_content" >' . cut(
  570. $result['description'],
  571. 100,
  572. true
  573. ) . '</div>';
  574. } else {
  575. $item_2 = '<div class="box_description_group_title" ><span class="social-groups-text2"></span></div>';
  576. $item_3 = '<div class="box_description_group_content" ></div>';
  577. }
  578. //Avoiding my groups
  579. $join_url = '';
  580. if (!in_array($id, $my_group_list)) {
  581. $join_url = '<a class="btn" href="groups.php?id=' . $id . '&action=join&u=' . api_get_user_id(
  582. ) . '">' . get_lang('JoinGroup') . '</a> ';
  583. }
  584. $item_4 = '<div class="box_description_group_actions" >' . $join_url . '</div>';
  585. $grid_item_2 = $item_0 . $item_1 . $item_2 . $item_3 . $item_4;
  586. $grid_newest_groups[] = array($grid_item_2);
  587. }
  588. // Pop groups
  589. $results = GroupPortalManager::get_groups_by_popularity(4, false);
  590. $grid_pop_groups = array();
  591. if (is_array($results) && count($results) > 0) {
  592. foreach ($results as $result) {
  593. $result['name'] = Security::remove_XSS(
  594. $result['name'],
  595. STUDENT,
  596. true
  597. );
  598. $result['description'] = Security::remove_XSS(
  599. $result['description'],
  600. STUDENT,
  601. true
  602. );
  603. $id = $result['id'];
  604. $url_open = '<a href="groups.php?id=' . $id . '">';
  605. $url_close = '</a>';
  606. $count_users_group = count(
  607. GroupPortalManager::get_users_by_group(
  608. $id,
  609. false,
  610. array(
  611. GROUP_USER_PERMISSION_ADMIN,
  612. GROUP_USER_PERMISSION_READER,
  613. GROUP_USER_PERMISSION_MODERATOR
  614. ),
  615. 0,
  616. 1000
  617. )
  618. );
  619. if ($count_users_group == 1) {
  620. $count_users_group = $count_users_group . ' ' . get_lang(
  621. 'Member'
  622. );
  623. } else {
  624. $count_users_group = $count_users_group . ' ' . get_lang(
  625. 'Members'
  626. );
  627. }
  628. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  629. $picture = GroupPortalManager::get_picture_group(
  630. $result['id'],
  631. $result['picture_uri'],
  632. 80
  633. );
  634. $result['picture_uri'] = '<img class="social-groups-image" src="' . $picture['file'] . '" hspace="4" height="50" border="2" align="left" width="50" />';
  635. $item_0 = Display::div(
  636. $result['picture_uri'],
  637. array('class' => 'box_description_group_image')
  638. );
  639. $members = Display::span(
  640. $count_users_group,
  641. array('class' => 'box_description_group_member')
  642. );
  643. $item_1 = Display::div(
  644. Display::tag('h3', $url_open . $name . $url_close) . $members,
  645. array('class' => 'box_description_group_title')
  646. );
  647. if ($result['description'] != '') {
  648. $item_3 = '<div class="box_description_group_content" >' . cut(
  649. $result['description'],
  650. 100,
  651. true
  652. ) . '</div>';
  653. } else {
  654. $item_2 = '<div class="box_description_group_title" ><span class="social-groups-text2"></span></div>';
  655. $item_3 = '<div class="box_description_group_content" ></div>';
  656. }
  657. $join_url = '';
  658. if (!in_array($id, $my_group_list)) {
  659. $join_url = '<a class="btn" href="groups.php?id=' . $id . '&action=join&u=' . api_get_user_id(
  660. ) . '">' . get_lang('JoinGroup') . '</a> ';
  661. }
  662. $item_4 = '<div class="box_description_group_actions" >' . $join_url . '</div>';
  663. $grid_item_2 = $item_0 . $item_1 . $item_2 . $item_3 . $item_4;
  664. $grid_pop_groups[] = array($grid_item_2);
  665. }
  666. }
  667. // Display groups (newest, mygroups, pop)
  668. $query_vars = array();
  669. $newest_content = $popular_content = $my_group_content = null;
  670. if (isset($_GET['view']) && in_array($_GET['view'], $allowed_views)) {
  671. $view_group = $_GET['view'];
  672. switch ($view_group) {
  673. case 'mygroups':
  674. if (count($grid_my_groups) > 0) {
  675. $my_group_content = Display::return_sortable_grid(
  676. 'mygroups',
  677. array(),
  678. $grid_my_groups,
  679. array('hide_navigation' => true, 'per_page' => 2),
  680. $query_vars,
  681. false,
  682. array(true, true, true, false)
  683. );
  684. }
  685. if (api_get_setting(
  686. 'allow_students_to_create_groups_in_social'
  687. ) == 'true'
  688. ) {
  689. $create_group_item = '<a class="btn" href="' . api_get_path(
  690. WEB_PATH
  691. ) . 'main/social/group_add.php">' . get_lang(
  692. 'CreateASocialGroup'
  693. ) . '</a>';
  694. //$my_group_content = $create_group_item. $my_group_content;
  695. } else {
  696. if (api_is_allowed_to_edit(null, true)) {
  697. $create_group_item = '<a class="btn" href="' . api_get_path(
  698. WEB_PATH
  699. ) . 'main/social/group_add.php">' . get_lang(
  700. 'CreateASocialGroup'
  701. ) . '</a>';
  702. }
  703. }
  704. break;
  705. case 'newest':
  706. if (count($grid_newest_groups) > 0) {
  707. $newest_content = Display::return_sortable_grid(
  708. 'newest',
  709. array(),
  710. $grid_newest_groups,
  711. array('hide_navigation' => true, 'per_page' => 100),
  712. $query_vars,
  713. false,
  714. array(true, true, true, false)
  715. );
  716. }
  717. if (api_is_platform_admin() || api_get_setting(
  718. 'allow_students_to_create_groups_in_social'
  719. ) == 'true'
  720. ) {
  721. if (empty($grid_newest_groups)) {
  722. //echo '<a href="group_add.php">'.get_lang('YouShouldCreateAGroup').'</a>';
  723. }
  724. }
  725. break;
  726. default :
  727. if (count($grid_pop_groups) > 0) {
  728. $popular_content = Display::return_sortable_grid(
  729. 'popular',
  730. array(),
  731. $grid_pop_groups,
  732. array('hide_navigation' => true, 'per_page' => 100),
  733. $query_vars,
  734. false,
  735. array(true, true, true, true, true)
  736. );
  737. }
  738. if (api_is_platform_admin() || api_get_setting(
  739. 'allow_students_to_create_groups_in_social'
  740. ) == 'true'
  741. ) {
  742. if (empty($grid_pop_groups)) {
  743. //echo '<a href="group_add.php">'.get_lang('YouShouldCreateAGroup').'</a>';
  744. }
  745. }
  746. break;
  747. }
  748. } else {
  749. $my_group_content = null;
  750. if (count($grid_my_groups) > 0) {
  751. $my_group_content = Display::return_sortable_grid(
  752. 'mygroups',
  753. array(),
  754. $grid_my_groups,
  755. array('hide_navigation' => true, 'per_page' => 2),
  756. $query_vars,
  757. false,
  758. array(true, true, true, false)
  759. );
  760. }
  761. if (api_get_setting(
  762. 'allow_students_to_create_groups_in_social'
  763. ) == 'true'
  764. ) {
  765. $create_group_item = '<a class="btn" href="' . api_get_path(
  766. WEB_PATH
  767. ) . 'main/social/group_add.php">' . get_lang(
  768. 'CreateASocialGroup'
  769. ) . '</a>';
  770. //$my_group_content = $create_group_item. $my_group_content;
  771. } else {
  772. if (api_is_allowed_to_edit(null, true)) {
  773. $create_group_item = '<a class="btn" href="' . api_get_path(
  774. WEB_PATH
  775. ) . 'main/social/group_add.php">' . get_lang(
  776. 'CreateASocialGroup'
  777. ) . '</a>';
  778. }
  779. }
  780. if (count($grid_newest_groups) > 0) {
  781. $newest_content = Display::return_sortable_grid(
  782. 'mygroups',
  783. array(),
  784. $grid_newest_groups,
  785. array('hide_navigation' => true, 'per_page' => 100),
  786. $query_vars,
  787. false,
  788. array(true, true, true, false)
  789. );
  790. }
  791. if (count($grid_pop_groups) > 0) {
  792. $popular_content = Display::return_sortable_grid(
  793. 'mygroups',
  794. array(),
  795. $grid_pop_groups,
  796. array('hide_navigation' => true, 'per_page' => 100),
  797. $query_vars,
  798. false,
  799. array(true, true, true, true, true)
  800. );
  801. }
  802. }
  803. if (!empty($create_group_item)) {
  804. $social_right_content .= Display::div(
  805. $create_group_item,
  806. array('class' => 'span9')
  807. );
  808. }
  809. $headers = array(
  810. get_lang('Newest'),
  811. get_lang('Popular'),
  812. get_lang('MyGroups')
  813. );
  814. $social_right_content .= '<div class="span9">' . Display::tabs(
  815. $headers,
  816. array($newest_content, $popular_content, $my_group_content),
  817. 'tab_browse'
  818. ) . '</div>';
  819. }
  820. $show_message = null;
  821. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'show_message' && $_REQUEST['msg'] == 'topic_deleted') {
  822. $show_message = Display::return_message(get_lang('Deleted'), 'success');
  823. }
  824. $tpl = new Template();
  825. $tpl->set_help('Groups');
  826. $tpl->assign('social_avatar_block', $social_avatar_block);
  827. $tpl->assign('social_menu_block', $social_menu_block);
  828. $tpl->assign('social_right_content', $social_right_content);
  829. $tpl->assign('message', $show_message);
  830. $tpl->assign('content', $content);
  831. $social_layout = $tpl->get_template('layout/social_layout.tpl');
  832. $tpl->display($social_layout);