groups.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.social
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. */
  7. $cidReset = true;
  8. $language_file = array('userInfo');
  9. require_once '../inc/global.inc.php';
  10. api_block_anonymous_users();
  11. if (api_get_setting('allow_social_tool') !='true') {
  12. api_not_allowed();
  13. }
  14. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  15. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  16. $this_section = SECTION_SOCIAL;
  17. // prepare anchor for message group topic
  18. $anchor = '';
  19. if (isset($_GET['anchor_topic'])) {
  20. $anchor = Security::remove_XSS($_GET['anchor_topic']);
  21. } else {
  22. $match = 0;
  23. $param_names = array_keys($_GET);
  24. foreach ($param_names as $param) {
  25. if (preg_match('/^items_(\d)_page_nr$/', $param, $match)) {
  26. break;
  27. }
  28. }
  29. if (isset($match[1])) {
  30. $anchor = 'topic_'.$match[1];
  31. }
  32. }
  33. $htmlHeadXtra[] = '<script>
  34. var counter_image = 1;
  35. function remove_image_form(id_elem1) {
  36. var elem1 = document.getElementById(id_elem1);
  37. elem1.parentNode.removeChild(elem1);
  38. counter_image--;
  39. var filepaths = document.getElementById("filepaths");
  40. if (filepaths.childNodes.length < 3) {
  41. var link_attach = document.getElementById("link-more-attach");
  42. if (link_attach) {
  43. link_attach.innerHTML=\'<a href="javascript://" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</a>\';
  44. }
  45. }
  46. }
  47. function add_image_form() {
  48. // Multiple filepaths for image form
  49. var filepaths = document.getElementById("filepaths");
  50. if (document.getElementById("filepath_"+counter_image)) {
  51. counter_image = counter_image + 1;
  52. } else {
  53. counter_image = counter_image;
  54. }
  55. var elem1 = document.createElement("div");
  56. elem1.setAttribute("id","filepath_"+counter_image);
  57. filepaths.appendChild(elem1);
  58. id_elem1 = "filepath_"+counter_image;
  59. id_elem1 = "\'"+id_elem1+"\'";
  60. document.getElementById("filepath_"+counter_image).innerHTML = "<input type=\"file\" name=\"attach_"+counter_image+"\" size=\"20\" />&nbsp;<a href=\"javascript:remove_image_form("+id_elem1+")\"><img src=\"'.api_get_path(WEB_CODE_PATH).'img/delete.gif\"></a>";
  61. if (filepaths.childNodes.length == 3) {
  62. var link_attach = document.getElementById("link-more-attach");
  63. if (link_attach) {
  64. link_attach.innerHTML="";
  65. }
  66. }
  67. }
  68. function validate_text_empty (str,msg) {
  69. var str = str.replace(/^\s*|\s*$/g,"");
  70. if (str.length == 0) {
  71. alert(msg);
  72. return true;
  73. }
  74. }
  75. jQuery(document).ready(function() {
  76. /* Binds a tab id in the url */
  77. $("#tab_browse").bind("tabsselect", function(event, ui) {
  78. window.location.href=ui.tab;
  79. });
  80. $("#tabs").tabs();
  81. $("#tab_browse").tabs();
  82. var valor = "'.$anchor.'";
  83. $(".head").click(function() {
  84. $(this).next().next().slideToggle("fast");
  85. image_clicked = $("#" + this.id + " img").attr("src");
  86. image_clicked_info = image_clicked.split("/");
  87. image_real_clicked = image_clicked_info[image_clicked_info.length-1];
  88. image_path = image_clicked.split("img");
  89. current_path = image_path[0]+"img/";
  90. if (image_real_clicked == "div_show.gif") {
  91. current_path = current_path+"div_hide.gif";
  92. $("#" + this.id + " img").attr("src", current_path);
  93. } else {
  94. current_path = current_path+"div_show.gif";
  95. $("#" + this.id + " img").attr("src", current_path)
  96. }
  97. return false;
  98. }).next().next().hide();
  99. // anchor for current topic
  100. if (valor) {
  101. $("#"+valor).show();
  102. window.location = document.URL+"#"+valor;
  103. }
  104. });
  105. </script>';
  106. $allowed_views = array('mygroups','newest','pop');
  107. $interbreadcrumb[]= array ('url' =>'home.php','name' => get_lang('SocialNetwork'));
  108. $content = null;
  109. if (isset($_GET['view']) && in_array($_GET['view'], $allowed_views)) {
  110. if ($_GET['view'] == 'mygroups') {
  111. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  112. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('MyGroups'));
  113. } else if ($_GET['view'] == 'newest') {
  114. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  115. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Newest'));
  116. } else {
  117. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  118. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Popular'));
  119. }
  120. } else {
  121. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  122. if (!isset($_GET['id'])) {
  123. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('GroupList'));
  124. } else {
  125. //$interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Group'));
  126. }
  127. }
  128. // getting group information
  129. $group_id = isset($_GET['id']) ? intval($_GET['id']) : null;
  130. $relation_group_title = '';
  131. $my_group_role = 0;
  132. if ($group_id != 0) {
  133. $user_leave_message = false;
  134. $user_added_group_message = false;
  135. $user_invitation_sent = false;
  136. $group_info = GroupPortalManager::get_group_data($group_id);
  137. if (!empty($group_id)) {
  138. $interbreadcrumb[]= array ('url' =>'#','name' => $group_info['name']);
  139. }
  140. if (isset($_GET['action']) && $_GET['action']=='leave') {
  141. $user_leaved = intval($_GET['u']);
  142. if (GroupPortalManager::canLeave($group_info)) {
  143. // I can "leave me myself"
  144. if (api_get_user_id() == $user_leaved) {
  145. GroupPortalManager::delete_user_rel_group($user_leaved, $group_id);
  146. $user_leave_message = true;
  147. }
  148. }
  149. }
  150. // add a user to a group if its open
  151. if (isset($_GET['action']) && $_GET['action']=='join') {
  152. // we add a user only if is a open group
  153. $user_join = intval($_GET['u']);
  154. if (api_get_user_id() == $user_join && !empty($group_id)) {
  155. if ($group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  156. GroupPortalManager::add_user_to_group($user_join, $group_id);
  157. $user_added_group_message = true;
  158. } else {
  159. GroupPortalManager::add_user_to_group($user_join, $group_id, GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER);
  160. $user_invitation_sent = true;
  161. }
  162. }
  163. }
  164. }
  165. $create_thread_link = '';
  166. if ($group_id != 0 ) {
  167. $social_left_content = SocialManager::show_social_menu('groups',$group_id);
  168. } else {
  169. $show_menu = 'browse_groups';
  170. if (isset($_GET['view']) && $_GET['view'] == 'mygroups') {
  171. $show_menu = $_GET['view'];
  172. }
  173. $social_left_content = SocialManager::show_social_menu($show_menu);
  174. }
  175. $social_right_content = null;
  176. if ($group_id != 0 ) {
  177. $group_info = GroupPortalManager::get_group_data($group_id);
  178. //Loading group information
  179. if (isset($_GET['status']) && $_GET['status']=='sent') {
  180. $social_right_content .= Display::return_message(get_lang('MessageHasBeenSent'), 'confirmation', false);
  181. }
  182. if ($user_leave_message) {
  183. $social_right_content .= Display::return_message(get_lang('UserIsNotSubscribedToThisGroup'), 'confirmation', false);
  184. }
  185. if ($user_added_group_message) {
  186. $social_right_content .= Display::return_message(get_lang('UserIsSubscribedToThisGroup'), 'confirmation', false);
  187. }
  188. if ($user_invitation_sent) {
  189. $social_right_content .= Display::return_message(get_lang('InvitationSent'), 'confirmation', false);
  190. }
  191. $is_group_member = GroupPortalManager::is_group_member($group_id);
  192. // details about the current group
  193. $social_right_content = '<div class="span9">';
  194. $social_right_content .= '<div id="social-group-details">';
  195. //Group's title
  196. $social_right_content .= Display::tag('h2', Security::remove_XSS($group_info['name'], STUDENT, true));
  197. //Privacy
  198. if (!$is_group_member) {
  199. $social_right_content .= '<div class="social-group-details-info">';
  200. $social_right_content .= '<span>'.get_lang('Privacy').' : </span>';
  201. if ($group_info['visibility']== GROUP_PERMISSION_OPEN) {
  202. $social_right_content .= get_lang('ThisIsAnOpenGroup');
  203. } elseif ($group_info['visibility']== GROUP_PERMISSION_CLOSED) {
  204. $social_right_content .= get_lang('ThisIsACloseGroup');
  205. }
  206. $social_right_content .= '</div>';
  207. }
  208. if (!$is_group_member && $group_info['visibility'] == GROUP_PERMISSION_CLOSED) {
  209. $role = GroupPortalManager::get_user_group_role(api_get_user_id(), $group_id);
  210. if ($role == GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER) {
  211. $social_right_content .= Display::return_message(get_lang('YouAlreadySentAnInvitation'));
  212. }
  213. }
  214. // Group's tags
  215. if (!empty($tags)) {
  216. $social_right_content .= '<div id="social-group-details-info"><span>'.get_lang('Tags').' : </span>'.$tags.'</div>';
  217. }
  218. $social_right_content .= '</div>';
  219. $social_right_content .= '</div>';
  220. //-- Show message groups
  221. $social_right_content .= '<div class="span9">';
  222. if ($is_group_member || $group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  223. if (!$is_group_member) {
  224. if (!in_array($my_group_role, array(GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER, GROUP_USER_PERMISSION_PENDING_INVITATION))) {
  225. $social_right_content .= '<a class="btn" href="groups.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a>';
  226. } elseif ($my_group_role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  227. $social_right_content .= '<a class="btn" href="groups.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('YouHaveBeenInvitedJoinNow').'</a>';
  228. }
  229. $social_right_content .= '<br /><br />';
  230. }
  231. $content = MessageManager::display_messages_for_group($group_id);
  232. if ($is_group_member) {
  233. if (empty($content)) {
  234. $create_thread_link = '<a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=400&width=610&&user_friend='.api_get_user_id().'&group_id='.$group_id.'&action=add_message_group" class="ajax btn" title="'.get_lang('ComposeMessage').'">'.get_lang('YouShouldCreateATopic').'</a></li>';
  235. } else {
  236. $create_thread_link = '<a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=400&width=610&&user_friend='.api_get_user_id().'&group_id='.$group_id.'&action=add_message_group" class="ajax btn" title="'.get_lang('ComposeMessage').'">'.get_lang('NewTopic').'</a>';
  237. }
  238. }
  239. $members = GroupPortalManager::get_users_by_group($group_id);
  240. $member_content = '';
  241. //Members
  242. if (count($members) > 0) {
  243. if ($my_group_role == GROUP_USER_PERMISSION_ADMIN) {
  244. $member_content .= Display::url(Display::return_icon('edit.gif', get_lang('EditMembersList')).' '.get_lang('EditMembersList'), 'group_members.php?id='.$group_id);
  245. }
  246. foreach($members as $member) {
  247. // if is a member
  248. if (in_array($member['relation_type'] , array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER,GROUP_USER_PERMISSION_MODERATOR))) {
  249. //add icons
  250. if ($member['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  251. $icon= Display::return_icon('social_group_admin.png', get_lang('Admin'));
  252. } elseif ($member['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  253. $icon= Display::return_icon('social_group_moderator.png', get_lang('Moderator'));
  254. } else{
  255. $icon= '';
  256. }
  257. $image_path = UserManager::get_user_picture_path_by_id($member['user_id'], 'web', false, true);
  258. $picture = UserManager::get_picture_user($member['user_id'], $image_path['file'], 60, USER_IMAGE_SIZE_MEDIUM);
  259. $member_content .= '<div class="">';
  260. $member_name = Display::url(api_get_person_name(cut($member['firstname'],15),cut($member['lastname'],15)).'&nbsp;'.$icon, 'profile.php?u='.$member['user_id']);
  261. $member_content .= Display::div('<img height="44" border="2" align="middle" vspace="10" class="social-groups-image" src="'.$picture['file'].'"/>&nbsp'.$member_name);
  262. $member_content .= '</div>';
  263. }
  264. }
  265. }
  266. if (!empty($create_thread_link)) {
  267. $create_thread_link = Display::div($create_thread_link, array('style'=>'padding-top:2px;height:40px'));
  268. }
  269. $headers = array(get_lang('Discussions'), get_lang('Members'));
  270. $social_right_content .= Display::tabs($headers, array($create_thread_link.$content, $member_content),'tabs');
  271. } else {
  272. // if I already sent an invitation message
  273. if (!in_array($my_group_role, array(GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER, GROUP_USER_PERMISSION_PENDING_INVITATION))) {
  274. $social_right_content .= '<a class="btn" href="groups.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a>';
  275. } elseif ($my_group_role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  276. $social_right_content .= '<a class="btn" href="groups.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('YouHaveBeenInvitedJoinNow').'</a>';
  277. }
  278. }
  279. $social_right_content .= '</div>'; // end layout messages
  280. } else {
  281. // My groups -----
  282. $results = GroupPortalManager::get_groups_by_user(api_get_user_id(), 0);
  283. $grid_my_groups = array();
  284. $my_group_list = array();
  285. if (is_array($results) && count($results) > 0) {
  286. foreach ($results as $result) {
  287. $id = $result['id'];
  288. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  289. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  290. $my_group_list[] = $id;
  291. $url_open = '<a href="groups.php?id='.$id.'">';
  292. $url_close = '</a>';
  293. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  294. if ($result['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  295. $name .= ' '.Display::return_icon('social_group_admin.png', get_lang('Admin'), array('style'=>'vertical-align:middle'));
  296. } elseif ($result['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  297. $name .= ' '.Display::return_icon('social_group_moderator.png', get_lang('Moderator'), array('style'=>'vertical-align:middle'));
  298. }
  299. $count_users_group = count(GroupPortalManager::get_users_by_group($id, false, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_MODERATOR), 0 , 1000));
  300. if ($count_users_group == 1 ) {
  301. $count_users_group = $count_users_group.' '.get_lang('Member');
  302. } else {
  303. $count_users_group = $count_users_group.' '.get_lang('Members');
  304. }
  305. $picture = GroupPortalManager::get_picture_group($result['id'], $result['picture_uri'],80);
  306. $result['picture_uri'] = '<img class="social-groups-image" src="'.$picture['file'].'" hspace="4" height="50" border="2" align="left" width="50" />';
  307. $item_0 = Display::div($result['picture_uri'], array('class'=>'box_description_group_image'));
  308. $members = Display::span($count_users_group, array('class'=>'box_description_group_member'));
  309. $item_1 = Display::div(Display::tag('h3', $url_open.$name.$url_close).$members, array('class'=>'box_description_group_title'));
  310. $item_2 = '';
  311. $item_3 = '';
  312. if ($result['description'] != '') {
  313. $item_3 = '<div class="box_description_group_content" >'.cut($result['description'],100,true).'</div>';
  314. } else {
  315. $item_2 = '<div class="box_description_group_title" ><span class="social-groups-text2"></span></div>';
  316. $item_3 = '<div class="box_description_group_content" ></div>';
  317. }
  318. $grid_item_2 = $item_0.$item_1.$item_2.$item_3;
  319. $grid_my_groups[]= array($grid_item_2);
  320. }
  321. }
  322. // Newest groups
  323. $results = GroupPortalManager::get_groups_by_age(4,false);
  324. $grid_newest_groups = array();
  325. foreach ($results as $result) {
  326. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  327. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  328. $id = $result['id'];
  329. $url_open = '<a href="groups.php?id='.$id.'">';
  330. $url_close = '</a>';
  331. $count_users_group = count(GroupPortalManager::get_users_by_group($id, false, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_MODERATOR), 0 , 1000));
  332. if ($count_users_group == 1 ) {
  333. $count_users_group = $count_users_group.' '.get_lang('Member');
  334. } else {
  335. $count_users_group = $count_users_group.' '.get_lang('Members');
  336. }
  337. $name = cut($result['name'],GROUP_TITLE_LENGTH,true);
  338. $picture = GroupPortalManager::get_picture_group($result['id'], $result['picture_uri'],80);
  339. $result['picture_uri'] = '<img class="social-groups-image" src="'.$picture['file'].'" hspace="4" height="50" border="2" align="left" width="50" />';
  340. $item_0 = Display::div($result['picture_uri'], array('class'=>'box_description_group_image'));
  341. $members = Display::span($count_users_group, array('class'=>'box_description_group_member'));
  342. $item_1 = Display::div(Display::tag('h3', $url_open.$name.$url_close).$members, array('class'=>'box_description_group_title'));
  343. if ($result['description'] != '') {
  344. $item_3 = '<div class="box_description_group_content" >'.cut($result['description'],100,true).'</div>';
  345. } else {
  346. $item_2 = '<div class="box_description_group_title" ><span class="social-groups-text2"></span></div>';
  347. $item_3 = '<div class="box_description_group_content" ></div>';
  348. }
  349. //Avoiding my groups
  350. $join_url = '';
  351. if (!in_array($id,$my_group_list)) {
  352. $join_url = '<a class="btn" href="groups.php?id='.$id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a> ';
  353. }
  354. $item_4 = '<div class="box_description_group_actions" >'.$join_url.'</div>';
  355. $grid_item_2 = $item_0.$item_1.$item_2.$item_3.$item_4;
  356. $grid_newest_groups[]= array($grid_item_2);
  357. }
  358. // Pop groups
  359. $results = GroupPortalManager::get_groups_by_popularity(4,false);
  360. $grid_pop_groups = array();
  361. if (is_array($results) && count($results) > 0) {
  362. foreach ($results as $result) {
  363. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  364. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  365. $id = $result['id'];
  366. $url_open = '<a href="groups.php?id='.$id.'">';
  367. $url_close = '</a>';
  368. $count_users_group = count(GroupPortalManager::get_users_by_group($id, false, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_MODERATOR), 0 , 1000));
  369. if ($count_users_group == 1 ) {
  370. $count_users_group = $count_users_group.' '.get_lang('Member');
  371. } else {
  372. $count_users_group = $count_users_group.' '.get_lang('Members');
  373. }
  374. $name = cut($result['name'],GROUP_TITLE_LENGTH,true);
  375. $picture = GroupPortalManager::get_picture_group($result['id'], $result['picture_uri'],80);
  376. $result['picture_uri'] = '<img class="social-groups-image" src="'.$picture['file'].'" hspace="4" height="50" border="2" align="left" width="50" />';
  377. $item_0 = Display::div($result['picture_uri'], array('class'=>'box_description_group_image'));
  378. $members = Display::span($count_users_group, array('class'=>'box_description_group_member'));
  379. $item_1 = Display::div(Display::tag('h3', $url_open.$name.$url_close).$members, array('class'=>'box_description_group_title'));
  380. if ($result['description'] != '') {
  381. $item_3 = '<div class="box_description_group_content" >'.cut($result['description'],100,true).'</div>';
  382. } else {
  383. $item_2 = '<div class="box_description_group_title" ><span class="social-groups-text2"></span></div>';
  384. $item_3 = '<div class="box_description_group_content" ></div>';
  385. }
  386. $join_url = '';
  387. if (!in_array($id,$my_group_list)) {
  388. $join_url = '<a class="btn" href="groups.php?id='.$id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a> ';
  389. }
  390. $item_4 = '<div class="box_description_group_actions" >'.$join_url.'</div>';
  391. $grid_item_2 = $item_0.$item_1.$item_2.$item_3.$item_4;
  392. $grid_pop_groups[]= array($grid_item_2);
  393. }
  394. }
  395. // Display groups (newest, mygroups, pop)
  396. $query_vars = array();
  397. $newest_content = $popular_content = $my_group_content = null;
  398. if (isset($_GET['view']) && in_array($_GET['view'],$allowed_views)) {
  399. $view_group = $_GET['view'];
  400. switch ($view_group) {
  401. case 'mygroups':
  402. if (count($grid_my_groups) > 0) {
  403. $my_group_content = Display::return_sortable_grid('mygroups', array(), $grid_my_groups, array('hide_navigation'=>true, 'per_page' => 2), $query_vars, false, array(true, true, true,false));
  404. }
  405. if (api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  406. $create_group_item = '<a class="btn" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.get_lang('CreateASocialGroup').'</a>';
  407. //$my_group_content = $create_group_item. $my_group_content;
  408. } else {
  409. if (api_is_allowed_to_edit(null,true)) {
  410. $create_group_item = '<a class="btn" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.get_lang('CreateASocialGroup').'</a>';
  411. }
  412. }
  413. break;
  414. case 'newest':
  415. if (count($grid_newest_groups) > 0) {
  416. $newest_content = Display::return_sortable_grid('newest', array(), $grid_newest_groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false));
  417. }
  418. if (api_is_platform_admin() || api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  419. if (empty($grid_newest_groups)) {
  420. //echo '<a href="group_add.php">'.get_lang('YouShouldCreateAGroup').'</a>';
  421. }
  422. }
  423. break;
  424. default :
  425. if (count($grid_pop_groups) > 0) {
  426. $popular_content = Display::return_sortable_grid('popular', array(), $grid_pop_groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,true,true));
  427. }
  428. if (api_is_platform_admin() || api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  429. if (empty($grid_pop_groups)) {
  430. //echo '<a href="group_add.php">'.get_lang('YouShouldCreateAGroup').'</a>';
  431. }
  432. }
  433. break;
  434. }
  435. } else {
  436. $my_group_content = null;
  437. if (count($grid_my_groups) > 0) {
  438. $my_group_content = Display::return_sortable_grid('mygroups', array(), $grid_my_groups, array('hide_navigation'=>true, 'per_page' => 2), $query_vars, false, array(true, true, true,false));
  439. }
  440. if (api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  441. $create_group_item = '<a class="btn" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.get_lang('CreateASocialGroup').'</a>';
  442. //$my_group_content = $create_group_item. $my_group_content;
  443. } else {
  444. if (api_is_allowed_to_edit(null,true)) {
  445. $create_group_item = '<a class="btn" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.get_lang('CreateASocialGroup').'</a>';
  446. }
  447. }
  448. if (count($grid_newest_groups) > 0) {
  449. $newest_content = Display::return_sortable_grid('mygroups', array(), $grid_newest_groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false));
  450. }
  451. if (count($grid_pop_groups) > 0) {
  452. $popular_content = Display::return_sortable_grid('mygroups', array(), $grid_pop_groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,true,true));
  453. }
  454. }
  455. if (!empty($create_group_item)) {
  456. $social_right_content .= Display::div($create_group_item, array('class'=>'span9'));
  457. }
  458. $headers = array(get_lang('Newest'), get_lang('Popular'), get_lang('MyGroups'));
  459. $social_right_content .= '<div class="span9">'.Display::tabs($headers, array($newest_content, $popular_content, $my_group_content),'tab_browse').'</div>';
  460. }
  461. $show_message = null;
  462. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'show_message' && $_REQUEST['msg'] == 'topic_deleted') {
  463. $show_message = Display::return_message(get_lang('Deleted'), 'success');
  464. }
  465. $tpl = new Template();
  466. $tpl->set_help('Groups');
  467. $tpl->assign('social_left_content', $social_left_content);
  468. $tpl->assign('social_right_content', $social_right_content);
  469. $tpl->assign('message', $show_message);
  470. $tpl->assign('content', $content);
  471. $social_layout = $tpl->get_template('layout/social_layout.tpl');
  472. $tpl->display($social_layout);