groups.php 32 KB

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