groups.php 34 KB

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