groups.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  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 = api_get_path(WEB_CODE_PATH) . 'auth/profile.php';
  218. if (api_get_setting('sso_authentication') === 'true') {
  219. $subSSOClass = api_get_setting('sso_authentication_subclass');
  220. $objSSO = null;
  221. if (!empty($subSSOClass)) {
  222. require_once api_get_path(SYS_CODE_PATH) . 'auth/sso/sso.' . $subSSOClass . '.class.php';
  223. $subSSOClass = 'sso' . $subSSOClass;
  224. $objSSO = new $subSSOClass();
  225. } else {
  226. $objSSO = new sso();
  227. }
  228. $editProfileUrl = $objSSO->generateProfileEditingURL();
  229. }
  230. $social_avatar_block .= '<div class="edit-profile">
  231. <a class="btn" href="' . $editProfileUrl . '">' . get_lang('EditProfile') . '</a>
  232. </div>';
  233. $social_avatar_block .= '</div>';
  234. //Block Social Menu
  235. $social_menu_block = SocialManager::show_social_menu('groups', $group_id);
  236. } else {
  237. $show_menu = 'browse_groups';
  238. if (isset($_GET['view']) && $_GET['view'] == 'mygroups') {
  239. $show_menu = $_GET['view'];
  240. }
  241. //Block Social Avatar
  242. $social_avatar_block = '<div class="panel panel-info social-avatar">';
  243. $social_avatar_block .= SocialManager::show_social_avatar_block($show_menu,$group_id);
  244. $social_avatar_block .= '<div class="lastname">'.$user_info['lastname'].'</div>';
  245. $social_avatar_block .= '<div class="firstname">'.$user_info['firstname'].'</div>';
  246. $social_avatar_block .= '<div class="email">'.Display::return_icon('instant_message.png').'&nbsp;' .$user_info['email'].'</div>';
  247. $chat_status = $user_info['extra'];
  248. if(!empty($chat_status['user_chat_status'])){
  249. $social_avatar_block.= '<div class="status">'.Display::return_icon('online.png').get_lang('Chat')." (".get_lang('Online').')</div>';
  250. }else{
  251. $social_avatar_block.= '<div class="status">'.Display::return_icon('offline.png').get_lang('Chat')." (".get_lang('Offline').')</div>';
  252. }
  253. $editProfileUrl = api_get_path(WEB_CODE_PATH) . 'auth/profile.php';
  254. if (api_get_setting('sso_authentication') === 'true') {
  255. $subSSOClass = api_get_setting('sso_authentication_subclass');
  256. $objSSO = null;
  257. if (!empty($subSSOClass)) {
  258. require_once api_get_path(SYS_CODE_PATH) . 'auth/sso/sso.' . $subSSOClass . '.class.php';
  259. $subSSOClass = 'sso' . $subSSOClass;
  260. $objSSO = new $subSSOClass();
  261. } else {
  262. $objSSO = new sso();
  263. }
  264. $editProfileUrl = $objSSO->generateProfileEditingURL();
  265. }
  266. $social_avatar_block .= '<div class="edit-profile">
  267. <a class="btn" href="' . $editProfileUrl . '">' . get_lang('EditProfile') . '</a>
  268. </div>';
  269. $social_avatar_block .= '</div>';
  270. $social_menu_block = SocialManager::show_social_menu($show_menu, $group_id);
  271. }
  272. $social_right_content = null;
  273. if ($group_id != 0) {
  274. $group_info = GroupPortalManager::get_group_data($group_id);
  275. //Loading group information
  276. if (isset($_GET['status']) && $_GET['status'] == 'sent') {
  277. $social_right_content .= Display::return_message(
  278. get_lang('MessageHasBeenSent'),
  279. 'confirmation',
  280. false
  281. );
  282. }
  283. if ($user_leave_message) {
  284. $social_right_content .= Display::return_message(
  285. get_lang('UserIsNotSubscribedToThisGroup'),
  286. 'confirmation',
  287. false
  288. );
  289. }
  290. if ($user_added_group_message) {
  291. $social_right_content .= Display::return_message(
  292. get_lang('UserIsSubscribedToThisGroup'),
  293. 'confirmation',
  294. false
  295. );
  296. }
  297. if ($user_invitation_sent) {
  298. $social_right_content .= Display::return_message(
  299. get_lang('InvitationSent'),
  300. 'confirmation',
  301. false
  302. );
  303. }
  304. $is_group_member = GroupPortalManager::is_group_member($group_id);
  305. // details about the current group
  306. $social_right_content = '<div class="span9">';
  307. $social_right_content .= '<div id="social-group-details">';
  308. //Group's title
  309. $social_right_content .= Display::tag(
  310. 'h2',
  311. Security::remove_XSS($group_info['name'], STUDENT, true)
  312. );
  313. //Privacy
  314. if (!$is_group_member) {
  315. $social_right_content .= '<div class="social-group-details-info">';
  316. $social_right_content .= '<span>' . get_lang('Privacy') . ' : </span>';
  317. if ($group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  318. $social_right_content .= get_lang('ThisIsAnOpenGroup');
  319. } elseif ($group_info['visibility'] == GROUP_PERMISSION_CLOSED) {
  320. $social_right_content .= get_lang('ThisIsACloseGroup');
  321. }
  322. $social_right_content .= '</div>';
  323. }
  324. if (!$is_group_member && $group_info['visibility'] == GROUP_PERMISSION_CLOSED) {
  325. $role = GroupPortalManager::get_user_group_role(
  326. api_get_user_id(),
  327. $group_id
  328. );
  329. if ($role == GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER) {
  330. $social_right_content .= Display::return_message(
  331. get_lang('YouAlreadySentAnInvitation')
  332. );
  333. }
  334. }
  335. // Group's tags
  336. if (!empty($tags)) {
  337. $social_right_content .= '<div id="social-group-details-info"><span>' . get_lang(
  338. 'Tags'
  339. ) . ' : </span>' . $tags . '</div>';
  340. }
  341. $social_right_content .= '</div>';
  342. $social_right_content .= '</div>';
  343. //-- Show message groups
  344. $social_right_content .= '<div class="span9">';
  345. if ($is_group_member || $group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  346. if (!$is_group_member) {
  347. if (!in_array(
  348. $my_group_role,
  349. array(
  350. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER,
  351. GROUP_USER_PERMISSION_PENDING_INVITATION
  352. )
  353. )
  354. ) {
  355. $social_right_content .= '<a class="btn" href="groups.php?id=' . $group_id . '&action=join&u=' . api_get_user_id(
  356. ) . '">' . get_lang('JoinGroup') . '</a>';
  357. } elseif ($my_group_role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  358. $social_right_content .= '<a class="btn" href="groups.php?id=' . $group_id . '&action=join&u=' . api_get_user_id(
  359. ) . '">' . get_lang('YouHaveBeenInvitedJoinNow') . '</a>';
  360. }
  361. $social_right_content .= '<br /><br />';
  362. }
  363. $content = MessageManager::display_messages_for_group($group_id);
  364. if ($is_group_member) {
  365. if (empty($content)) {
  366. $create_thread_link = '<a href="' . api_get_path(
  367. WEB_CODE_PATH
  368. ) . 'social/message_for_group_form.inc.php?view_panel=1&height=400&width=610&&user_friend=' . api_get_user_id(
  369. ) . '&group_id=' . $group_id . '&action=add_message_group" class="ajax btn" title="' . get_lang(
  370. 'ComposeMessage'
  371. ) . '">' . get_lang('YouShouldCreateATopic') . '</a></li>';
  372. } else {
  373. $create_thread_link = '<a href="' . api_get_path(
  374. WEB_CODE_PATH
  375. ) . 'social/message_for_group_form.inc.php?view_panel=1&height=400&width=610&&user_friend=' . api_get_user_id(
  376. ) . '&group_id=' . $group_id . '&action=add_message_group" class="ajax btn" title="' . get_lang(
  377. 'ComposeMessage'
  378. ) . '">' . get_lang('NewTopic') . '</a>';
  379. }
  380. }
  381. $members = GroupPortalManager::get_users_by_group($group_id);
  382. $member_content = '';
  383. //Members
  384. if (count($members) > 0) {
  385. if ($my_group_role == GROUP_USER_PERMISSION_ADMIN) {
  386. $member_content .= Display::url(
  387. Display::return_icon(
  388. 'edit.gif',
  389. get_lang('EditMembersList')
  390. ) . ' ' . get_lang('EditMembersList'),
  391. 'group_members.php?id=' . $group_id
  392. );
  393. }
  394. foreach ($members as $member) {
  395. // if is a member
  396. if (in_array(
  397. $member['relation_type'],
  398. array(
  399. GROUP_USER_PERMISSION_ADMIN,
  400. GROUP_USER_PERMISSION_READER,
  401. GROUP_USER_PERMISSION_MODERATOR
  402. )
  403. )
  404. ) {
  405. //add icons
  406. if ($member['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  407. $icon = Display::return_icon(
  408. 'social_group_admin.png',
  409. get_lang('Admin')
  410. );
  411. } elseif ($member['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  412. $icon = Display::return_icon(
  413. 'social_group_moderator.png',
  414. get_lang('Moderator')
  415. );
  416. } else {
  417. $icon = '';
  418. }
  419. $image_path = UserManager::get_user_picture_path_by_id(
  420. $member['user_id'],
  421. 'web',
  422. false,
  423. true
  424. );
  425. $picture = UserManager::get_picture_user(
  426. $member['user_id'],
  427. $image_path['file'],
  428. 60,
  429. USER_IMAGE_SIZE_MEDIUM
  430. );
  431. $member_content .= '<div class="">';
  432. $member_name = Display::url(
  433. api_get_person_name(
  434. cut($member['firstname'], 15),
  435. cut($member['lastname'], 15)
  436. ) . '&nbsp;' . $icon,
  437. 'profile.php?u=' . $member['user_id']
  438. );
  439. $member_content .= Display::div(
  440. '<img height="44" border="2" align="middle" vspace="10" class="social-groups-image" src="' . $picture['file'] . '"/>&nbsp' . $member_name
  441. );
  442. $member_content .= '</div>';
  443. }
  444. }
  445. }
  446. if (!empty($create_thread_link)) {
  447. $create_thread_link = Display::div(
  448. $create_thread_link,
  449. array('style' => 'padding-top:2px;height:40px')
  450. );
  451. }
  452. $headers = array(get_lang('Discussions'), get_lang('Members'));
  453. $social_right_content .= Display::tabs(
  454. $headers,
  455. array($create_thread_link . $content, $member_content),
  456. 'tabs'
  457. );
  458. } else {
  459. // if I already sent an invitation message
  460. if (!in_array(
  461. $my_group_role,
  462. array(
  463. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER,
  464. GROUP_USER_PERMISSION_PENDING_INVITATION
  465. )
  466. )
  467. ) {
  468. $social_right_content .= '<a class="btn" href="groups.php?id=' . $group_id . '&action=join&u=' . api_get_user_id(
  469. ) . '">' . get_lang('JoinGroup') . '</a>';
  470. } elseif ($my_group_role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  471. $social_right_content .= '<a class="btn" href="groups.php?id=' . $group_id . '&action=join&u=' . api_get_user_id(
  472. ) . '">' . get_lang('YouHaveBeenInvitedJoinNow') . '</a>';
  473. }
  474. }
  475. $social_right_content .= '</div>'; // end layout messages
  476. } else {
  477. // My groups -----
  478. $results = GroupPortalManager::get_groups_by_user(api_get_user_id(), 0);
  479. $grid_my_groups = array();
  480. $my_group_list = array();
  481. if (is_array($results) && count($results) > 0) {
  482. foreach ($results as $result) {
  483. $id = $result['id'];
  484. $result['name'] = Security::remove_XSS(
  485. $result['name'],
  486. STUDENT,
  487. true
  488. );
  489. $result['description'] = Security::remove_XSS(
  490. $result['description'],
  491. STUDENT,
  492. true
  493. );
  494. $my_group_list[] = $id;
  495. $url_open = '<a href="groups.php?id=' . $id . '">';
  496. $url_close = '</a>';
  497. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  498. if ($result['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  499. $name .= ' ' . Display::return_icon(
  500. 'social_group_admin.png',
  501. get_lang('Admin'),
  502. array('style' => 'vertical-align:middle')
  503. );
  504. } elseif ($result['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  505. $name .= ' ' . Display::return_icon(
  506. 'social_group_moderator.png',
  507. get_lang('Moderator'),
  508. array('style' => 'vertical-align:middle')
  509. );
  510. }
  511. $count_users_group = count(
  512. GroupPortalManager::get_users_by_group(
  513. $id,
  514. false,
  515. array(
  516. GROUP_USER_PERMISSION_ADMIN,
  517. GROUP_USER_PERMISSION_READER,
  518. GROUP_USER_PERMISSION_MODERATOR
  519. ),
  520. 0,
  521. 1000
  522. )
  523. );
  524. if ($count_users_group == 1) {
  525. $count_users_group = $count_users_group . ' ' . get_lang(
  526. 'Member'
  527. );
  528. } else {
  529. $count_users_group = $count_users_group . ' ' . get_lang(
  530. 'Members'
  531. );
  532. }
  533. $picture = GroupPortalManager::get_picture_group(
  534. $result['id'],
  535. $result['picture_uri'],
  536. 80
  537. );
  538. $result['picture_uri'] = '<img class="social-groups-image" src="' . $picture['file'] . '" hspace="4" height="50" border="2" align="left" width="50" />';
  539. $item_0 = Display::div(
  540. $result['picture_uri'],
  541. array('class' => 'box_description_group_image')
  542. );
  543. $members = Display::span(
  544. $count_users_group,
  545. array('class' => 'box_description_group_member')
  546. );
  547. $item_1 = Display::div(
  548. Display::tag('h3', $url_open . $name . $url_close) . $members,
  549. array('class' => 'box_description_group_title')
  550. );
  551. $item_2 = '';
  552. $item_3 = '';
  553. if ($result['description'] != '') {
  554. $item_3 = '<div class="box_description_group_content" >' . cut(
  555. $result['description'],
  556. 100,
  557. true
  558. ) . '</div>';
  559. } else {
  560. $item_2 = '<div class="box_description_group_title" ><span class="social-groups-text2"></span></div>';
  561. $item_3 = '<div class="box_description_group_content" ></div>';
  562. }
  563. $grid_item_2 = $item_0 . $item_1 . $item_2 . $item_3;
  564. $grid_my_groups[] = array($grid_item_2);
  565. }
  566. }
  567. // Newest groups
  568. $results = GroupPortalManager::get_groups_by_age(4, false);
  569. $grid_newest_groups = array();
  570. foreach ($results as $result) {
  571. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  572. $result['description'] = Security::remove_XSS(
  573. $result['description'],
  574. STUDENT,
  575. true
  576. );
  577. $id = $result['id'];
  578. $url_open = '<a href="groups.php?id=' . $id . '">';
  579. $url_close = '</a>';
  580. $count_users_group = count(
  581. GroupPortalManager::get_users_by_group(
  582. $id,
  583. false,
  584. array(
  585. GROUP_USER_PERMISSION_ADMIN,
  586. GROUP_USER_PERMISSION_READER,
  587. GROUP_USER_PERMISSION_MODERATOR
  588. ),
  589. 0,
  590. 1000
  591. )
  592. );
  593. if ($count_users_group == 1) {
  594. $count_users_group = $count_users_group . ' ' . get_lang('Member');
  595. } else {
  596. $count_users_group = $count_users_group . ' ' . get_lang('Members');
  597. }
  598. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  599. $picture = GroupPortalManager::get_picture_group(
  600. $result['id'],
  601. $result['picture_uri'],
  602. 80
  603. );
  604. $result['picture_uri'] = '<img class="social-groups-image" src="' . $picture['file'] . '" hspace="4" height="50" border="2" align="left" width="50" />';
  605. $item_0 = Display::div(
  606. $result['picture_uri'],
  607. array('class' => 'box_description_group_image')
  608. );
  609. $members = Display::span(
  610. $count_users_group,
  611. array('class' => 'box_description_group_member')
  612. );
  613. $item_1 = Display::div(
  614. Display::tag('h3', $url_open . $name . $url_close) . $members,
  615. array('class' => 'box_description_group_title')
  616. );
  617. if ($result['description'] != '') {
  618. $item_3 = '<div class="box_description_group_content" >' . cut(
  619. $result['description'],
  620. 100,
  621. true
  622. ) . '</div>';
  623. } else {
  624. $item_2 = '<div class="box_description_group_title" ><span class="social-groups-text2"></span></div>';
  625. $item_3 = '<div class="box_description_group_content" ></div>';
  626. }
  627. //Avoiding my groups
  628. $join_url = '';
  629. if (!in_array($id, $my_group_list)) {
  630. $join_url = '<a class="btn" href="groups.php?id=' . $id . '&action=join&u=' . api_get_user_id(
  631. ) . '">' . get_lang('JoinGroup') . '</a> ';
  632. }
  633. $item_4 = '<div class="box_description_group_actions" >' . $join_url . '</div>';
  634. $grid_item_2 = $item_0 . $item_1 . $item_2 . $item_3 . $item_4;
  635. $grid_newest_groups[] = array($grid_item_2);
  636. }
  637. // Pop groups
  638. $results = GroupPortalManager::get_groups_by_popularity(4, false);
  639. $grid_pop_groups = array();
  640. if (is_array($results) && count($results) > 0) {
  641. foreach ($results as $result) {
  642. $result['name'] = Security::remove_XSS(
  643. $result['name'],
  644. STUDENT,
  645. true
  646. );
  647. $result['description'] = Security::remove_XSS(
  648. $result['description'],
  649. STUDENT,
  650. true
  651. );
  652. $id = $result['id'];
  653. $url_open = '<a href="groups.php?id=' . $id . '">';
  654. $url_close = '</a>';
  655. $count_users_group = count(
  656. GroupPortalManager::get_users_by_group(
  657. $id,
  658. false,
  659. array(
  660. GROUP_USER_PERMISSION_ADMIN,
  661. GROUP_USER_PERMISSION_READER,
  662. GROUP_USER_PERMISSION_MODERATOR
  663. ),
  664. 0,
  665. 1000
  666. )
  667. );
  668. if ($count_users_group == 1) {
  669. $count_users_group = $count_users_group . ' ' . get_lang(
  670. 'Member'
  671. );
  672. } else {
  673. $count_users_group = $count_users_group . ' ' . get_lang(
  674. 'Members'
  675. );
  676. }
  677. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  678. $picture = GroupPortalManager::get_picture_group(
  679. $result['id'],
  680. $result['picture_uri'],
  681. 80
  682. );
  683. $result['picture_uri'] = '<img class="social-groups-image" src="' . $picture['file'] . '" hspace="4" height="50" border="2" align="left" width="50" />';
  684. $item_0 = Display::div(
  685. $result['picture_uri'],
  686. array('class' => 'box_description_group_image')
  687. );
  688. $members = Display::span(
  689. $count_users_group,
  690. array('class' => 'box_description_group_member')
  691. );
  692. $item_1 = Display::div(
  693. Display::tag('h3', $url_open . $name . $url_close) . $members,
  694. array('class' => 'box_description_group_title')
  695. );
  696. if ($result['description'] != '') {
  697. $item_3 = '<div class="box_description_group_content" >' . cut(
  698. $result['description'],
  699. 100,
  700. true
  701. ) . '</div>';
  702. } else {
  703. $item_2 = '<div class="box_description_group_title" ><span class="social-groups-text2"></span></div>';
  704. $item_3 = '<div class="box_description_group_content" ></div>';
  705. }
  706. $join_url = '';
  707. if (!in_array($id, $my_group_list)) {
  708. $join_url = '<a class="btn" href="groups.php?id=' . $id . '&action=join&u=' . api_get_user_id(
  709. ) . '">' . get_lang('JoinGroup') . '</a> ';
  710. }
  711. $item_4 = '<div class="box_description_group_actions" >' . $join_url . '</div>';
  712. $grid_item_2 = $item_0 . $item_1 . $item_2 . $item_3 . $item_4;
  713. $grid_pop_groups[] = array($grid_item_2);
  714. }
  715. }
  716. // Display groups (newest, mygroups, pop)
  717. $query_vars = array();
  718. $newest_content = $popular_content = $my_group_content = null;
  719. if (isset($_GET['view']) && in_array($_GET['view'], $allowed_views)) {
  720. $view_group = $_GET['view'];
  721. switch ($view_group) {
  722. case 'mygroups':
  723. if (count($grid_my_groups) > 0) {
  724. $my_group_content = Display::return_sortable_grid(
  725. 'mygroups',
  726. array(),
  727. $grid_my_groups,
  728. array('hide_navigation' => true, 'per_page' => 2),
  729. $query_vars,
  730. false,
  731. array(true, true, true, false)
  732. );
  733. }
  734. if (api_get_setting(
  735. 'allow_students_to_create_groups_in_social'
  736. ) == 'true'
  737. ) {
  738. $create_group_item = '<a class="btn" href="' . api_get_path(
  739. WEB_PATH
  740. ) . 'main/social/group_add.php">' . get_lang(
  741. 'CreateASocialGroup'
  742. ) . '</a>';
  743. //$my_group_content = $create_group_item. $my_group_content;
  744. } else {
  745. if (api_is_allowed_to_edit(null, true)) {
  746. $create_group_item = '<a class="btn" href="' . api_get_path(
  747. WEB_PATH
  748. ) . 'main/social/group_add.php">' . get_lang(
  749. 'CreateASocialGroup'
  750. ) . '</a>';
  751. }
  752. }
  753. break;
  754. case 'newest':
  755. if (count($grid_newest_groups) > 0) {
  756. $newest_content = Display::return_sortable_grid(
  757. 'newest',
  758. array(),
  759. $grid_newest_groups,
  760. array('hide_navigation' => true, 'per_page' => 100),
  761. $query_vars,
  762. false,
  763. array(true, true, true, false)
  764. );
  765. }
  766. if (api_is_platform_admin() || api_get_setting(
  767. 'allow_students_to_create_groups_in_social'
  768. ) == 'true'
  769. ) {
  770. if (empty($grid_newest_groups)) {
  771. //echo '<a href="group_add.php">'.get_lang('YouShouldCreateAGroup').'</a>';
  772. }
  773. }
  774. break;
  775. default :
  776. if (count($grid_pop_groups) > 0) {
  777. $popular_content = Display::return_sortable_grid(
  778. 'popular',
  779. array(),
  780. $grid_pop_groups,
  781. array('hide_navigation' => true, 'per_page' => 100),
  782. $query_vars,
  783. false,
  784. array(true, true, true, true, true)
  785. );
  786. }
  787. if (api_is_platform_admin() || api_get_setting(
  788. 'allow_students_to_create_groups_in_social'
  789. ) == 'true'
  790. ) {
  791. if (empty($grid_pop_groups)) {
  792. //echo '<a href="group_add.php">'.get_lang('YouShouldCreateAGroup').'</a>';
  793. }
  794. }
  795. break;
  796. }
  797. } else {
  798. $my_group_content = null;
  799. if (count($grid_my_groups) > 0) {
  800. $my_group_content = Display::return_sortable_grid(
  801. 'mygroups',
  802. array(),
  803. $grid_my_groups,
  804. array('hide_navigation' => true, 'per_page' => 2),
  805. $query_vars,
  806. false,
  807. array(true, true, true, false)
  808. );
  809. }
  810. if (api_get_setting(
  811. 'allow_students_to_create_groups_in_social'
  812. ) == 'true'
  813. ) {
  814. $create_group_item = '<a class="btn" href="' . api_get_path(
  815. WEB_PATH
  816. ) . 'main/social/group_add.php">' . get_lang(
  817. 'CreateASocialGroup'
  818. ) . '</a>';
  819. //$my_group_content = $create_group_item. $my_group_content;
  820. } else {
  821. if (api_is_allowed_to_edit(null, true)) {
  822. $create_group_item = '<a class="btn" href="' . api_get_path(
  823. WEB_PATH
  824. ) . 'main/social/group_add.php">' . get_lang(
  825. 'CreateASocialGroup'
  826. ) . '</a>';
  827. }
  828. }
  829. if (count($grid_newest_groups) > 0) {
  830. $newest_content = Display::return_sortable_grid(
  831. 'mygroups',
  832. array(),
  833. $grid_newest_groups,
  834. array('hide_navigation' => true, 'per_page' => 100),
  835. $query_vars,
  836. false,
  837. array(true, true, true, false)
  838. );
  839. }
  840. if (count($grid_pop_groups) > 0) {
  841. $popular_content = Display::return_sortable_grid(
  842. 'mygroups',
  843. array(),
  844. $grid_pop_groups,
  845. array('hide_navigation' => true, 'per_page' => 100),
  846. $query_vars,
  847. false,
  848. array(true, true, true, true, true)
  849. );
  850. }
  851. }
  852. if (!empty($create_group_item)) {
  853. $social_right_content .= Display::div(
  854. $create_group_item,
  855. array('class' => 'span9')
  856. );
  857. }
  858. $headers = array(
  859. get_lang('Newest'),
  860. get_lang('Popular'),
  861. get_lang('MyGroups')
  862. );
  863. $social_right_content .= '<div class="span9">' . Display::tabs(
  864. $headers,
  865. array($newest_content, $popular_content, $my_group_content),
  866. 'tab_browse'
  867. ) . '</div>';
  868. }
  869. $show_message = null;
  870. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'show_message' && $_REQUEST['msg'] == 'topic_deleted') {
  871. $show_message = Display::return_message(get_lang('Deleted'), 'success');
  872. }
  873. $tpl = new Template();
  874. $tpl->set_help('Groups');
  875. $tpl->assign('social_avatar_block', $social_avatar_block);
  876. $tpl->assign('social_menu_block', $social_menu_block);
  877. $tpl->assign('social_right_content', $social_right_content);
  878. $tpl->assign('message', $show_message);
  879. $tpl->assign('content', $content);
  880. $social_layout = $tpl->get_template('social/groups.tpl');
  881. $tpl->display($social_layout);