groups.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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. $anchor = 'topic_'.$match[1];
  30. }
  31. $htmlHeadXtra[] = '<script type="text/javascript">
  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 = "<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>";
  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 ('url' =>'home.php','name' => get_lang('SocialNetwork'));
  106. if (isset($_GET['view']) && in_array($_GET['view'],$allowed_views)) {
  107. if ($_GET['view'] == 'mygroups') {
  108. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  109. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('MyGroups'));
  110. } else if ( $_GET['view'] == 'newest') {
  111. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  112. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Newest'));
  113. } else {
  114. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  115. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Popular'));
  116. }
  117. } else {
  118. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  119. if (!isset($_GET['id'])) {
  120. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('GroupList'));
  121. } else {
  122. //$interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Group'));
  123. }
  124. }
  125. //Display :: display_header($tool_name, 'Groups');
  126. // getting group information
  127. $group_id = isset($_GET['id']) ? intval($_GET['id']) : null;
  128. $relation_group_title = '';
  129. $my_group_role = 0;
  130. if ($group_id != 0 ) {
  131. $user_leave_message = false;
  132. $user_added_group_message = false;
  133. $user_invitation_sent = false;
  134. $group_info = GroupPortalManager::get_group_data($group_id);
  135. if (isset($_GET['action']) && $_GET['action']=='leave') {
  136. $user_leaved = intval($_GET['u']);
  137. //I can "leave me myself"
  138. if (api_get_user_id() == $user_leaved) {
  139. GroupPortalManager::delete_user_rel_group($user_leaved, $group_id);
  140. $user_leave_message = true;
  141. }
  142. }
  143. // add a user to a group if its open
  144. if (isset($_GET['action']) && $_GET['action']=='join') {
  145. // we add a user only if is a open group
  146. $user_join = intval($_GET['u']);
  147. if (api_get_user_id() == $user_join && !empty($group_id)) {
  148. if ($group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  149. GroupPortalManager::add_user_to_group($user_join, $group_id);
  150. $user_added_group_message = true;
  151. } else {
  152. GroupPortalManager::add_user_to_group($user_join, $group_id, GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER);
  153. $user_invitation_sent = true;
  154. }
  155. }
  156. }
  157. }
  158. $create_thread_link = '';
  159. if ($group_id != 0 ) {
  160. $social_left_content = SocialManager::show_social_menu('groups',$group_id);
  161. } else {
  162. $show_menu = 'browse_groups';
  163. if (isset($_GET['view']) && $_GET['view'] == 'mygroups') {
  164. $show_menu = $_GET['view'];
  165. }
  166. $social_left_content = SocialManager::show_social_menu($show_menu);
  167. }
  168. if ($group_id != 0 ) {
  169. $group_info = GroupPortalManager::get_group_data($group_id);
  170. //Loading group information
  171. if (isset($_GET['status']) && $_GET['status']=='sent') {
  172. $social_right_content .= Display::return_message(get_lang('MessageHasBeenSent'), 'confirmation', false);
  173. }
  174. if ($user_leave_message) {
  175. $social_right_content .= Display::return_message(get_lang('UserIsNotSubscribedToThisGroup'), 'confirmation', false);
  176. }
  177. if ($user_added_group_message) {
  178. $social_right_content .= Display::return_message(get_lang('UserIsSubscribedToThisGroup'), 'confirmation', false);
  179. }
  180. if ($user_invitation_sent) {
  181. $social_right_content .= Display::return_message(get_lang('InvitationSent'), 'confirmation', false);
  182. }
  183. $is_group_member = GroupPortalManager::is_group_member($group_id);
  184. // details about the current group
  185. $social_right_content = '<div class="span9">';
  186. $social_right_content .= '<div id="social-group-details">';
  187. //Group's title
  188. $social_right_content .= Display::tag('h2', Security::remove_XSS($group_info['name'], STUDENT, true));
  189. //Privacy
  190. if (!$is_group_member) {
  191. $social_right_content .= '<div class="social-group-details-info">';
  192. $social_right_content .= '<span>'.get_lang('Privacy').' : </span>';
  193. if ($group_info['visibility']== GROUP_PERMISSION_OPEN) {
  194. $social_right_content .= get_lang('ThisIsAnOpenGroup');
  195. } elseif ($group_info['visibility']== GROUP_PERMISSION_CLOSED) {
  196. $social_right_content .= get_lang('ThisIsACloseGroup');
  197. }
  198. $social_right_content .= '</div>';
  199. }
  200. if (!$is_group_member && $group_info['visibility'] == GROUP_PERMISSION_CLOSED) {
  201. $role = GroupPortalManager::get_user_group_role(api_get_user_id(), $group_id);
  202. if ($role == GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER) {
  203. $social_right_content .= Display::return_message(get_lang('YouAlreadySentAnInvitation'));
  204. }
  205. }
  206. if (!empty($relation_group_title)) {
  207. /*
  208. echo '<div class="social-group-details-info">';
  209. echo '<span>'.get_lang('StatusInThisGroup').' : </span>';
  210. echo $relation_group_title;
  211. echo '</div>';*/
  212. }
  213. //Group's tags
  214. if (!empty($tags)) {
  215. $social_right_content .= '<div id="social-group-details-info"><span>'.get_lang('Tags').' : </span>'.$tags.'</div>';
  216. }
  217. $social_right_content .= '</div>';
  218. $social_right_content .= '</div>';
  219. //-- Show message groups
  220. $social_right_content .= '<div class="span9">';
  221. if ($is_group_member || $group_info['visibility'] == GROUP_PERMISSION_OPEN) {
  222. if (!$is_group_member) {
  223. if (!in_array($my_group_role, array(GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER, GROUP_USER_PERMISSION_PENDING_INVITATION))) {
  224. $social_right_content .= '<a class="btn" href="groups.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a>';
  225. } elseif ($my_group_role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  226. $social_right_content .= '<a class="btn" href="groups.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('YouHaveBeenInvitedJoinNow').'</a>';
  227. }
  228. $social_right_content .= '<br /><br />';
  229. }
  230. $content = MessageManager::display_messages_for_group($group_id);
  231. if ($is_group_member) {
  232. if (empty($content)) {
  233. $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>';
  234. } else {
  235. $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>';
  236. }
  237. }
  238. $members = GroupPortalManager::get_users_by_group($group_id);
  239. $member_content = '';
  240. //Members
  241. if (count($members) > 0) {
  242. if ($my_group_role == GROUP_USER_PERMISSION_ADMIN) {
  243. $member_content .= Display::url(Display::return_icon('edit.gif', get_lang('EditMembersList')).' '.get_lang('EditMembersList'), 'group_members.php?id='.$group_id);
  244. }
  245. foreach($members as $member) {
  246. // if is a member
  247. if (in_array($member['relation_type'] , array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER,GROUP_USER_PERMISSION_MODERATOR))) {
  248. //add icons
  249. if ($member['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  250. $icon= Display::return_icon('social_group_admin.png', get_lang('Admin'));
  251. } elseif ($member['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  252. $icon= Display::return_icon('social_group_moderator.png', get_lang('Moderator'));
  253. } else{
  254. $icon= '';
  255. }
  256. $image_path = UserManager::get_user_picture_path_by_id($member['user_id'], 'web', false, true);
  257. $picture = UserManager::get_picture_user($member['user_id'], $image_path['file'], 60, USER_IMAGE_SIZE_MEDIUM);
  258. $member_content .= '<div class="">';
  259. $member_name = Display::url(api_get_person_name(cut($member['firstname'],15),cut($member['lastname'],15)).'&nbsp;'.$icon, 'profile.php?u='.$member['user_id']);
  260. $member_content .= Display::div('<img height="44" border="2" align="middle" vspace="10" class="social-groups-image" src="'.$picture['file'].'"/>&nbsp'.$member_name);
  261. $member_content .= '</div>';
  262. }
  263. }
  264. }
  265. if (!empty($create_thread_link)) {
  266. $create_thread_link = Display::div($create_thread_link, array('style'=>'padding-top:2px;height:40px'));
  267. }
  268. //api_get_item_property_by_tool('group', $course_info, $group_id);
  269. //$updates =
  270. //get_lang('Updates'),
  271. $headers = array(get_lang('Discussions'), get_lang('Members'));
  272. $social_right_content .= Display::tabs($headers, array($create_thread_link.$content, $member_content),'tabs');
  273. } else {
  274. // if I already sent an invitation message
  275. if (!in_array($my_group_role, array(GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER, 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('JoinGroup').'</a>';
  277. } elseif ($my_group_role == GROUP_USER_PERMISSION_PENDING_INVITATION) {
  278. $social_right_content .= '<a class="btn" href="groups.php?id='.$group_id.'&action=join&u='.api_get_user_id().'">'.get_lang('YouHaveBeenInvitedJoinNow').'</a>';
  279. }
  280. }
  281. $social_right_content .= '</div>'; // end layout messages
  282. } else {
  283. // My groups -----
  284. $results = GroupPortalManager::get_groups_by_user(api_get_user_id(), 0);
  285. $grid_my_groups = array();
  286. $my_group_list = array();
  287. if (is_array($results) && count($results) > 0) {
  288. foreach ($results as $result) {
  289. $id = $result['id'];
  290. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  291. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  292. $my_group_list[] = $id;
  293. $url_open = '<a href="groups.php?id='.$id.'">';
  294. $url_close = '</a>';
  295. $name = cut($result['name'], GROUP_TITLE_LENGTH, true);
  296. if ($result['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  297. $name .= ' '.Display::return_icon('social_group_admin.png', get_lang('Admin'), array('style'=>'vertical-align:middle'));
  298. } elseif ($result['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  299. $name .= ' '.Display::return_icon('social_group_moderator.png', get_lang('Moderator'), array('style'=>'vertical-align:middle'));
  300. }
  301. $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));
  302. if ($count_users_group == 1 ) {
  303. $count_users_group = $count_users_group.' '.get_lang('Member');
  304. } else {
  305. $count_users_group = $count_users_group.' '.get_lang('Members');
  306. }
  307. $picture = GroupPortalManager::get_picture_group($result['id'], $result['picture_uri'],80);
  308. $result['picture_uri'] = '<img class="social-groups-image" src="'.$picture['file'].'" hspace="4" height="50" border="2" align="left" width="50" />';
  309. $item_0 = Display::div($result['picture_uri'], array('class'=>'box_description_group_image'));
  310. $members = Display::span($count_users_group, array('class'=>'box_description_group_member'));
  311. $item_1 = Display::div(Display::tag('h3', $url_open.$name.$url_close).$members, array('class'=>'box_description_group_title'));
  312. $item_2 = '';
  313. $item_3 = '';
  314. if ($result['description'] != '') {
  315. $item_3 = '<div class="box_description_group_content" >'.cut($result['description'],100,true).'</div>';
  316. } else {
  317. $item_2 = '<div class="box_description_group_title" ><span class="social-groups-text2"></span></div>';
  318. $item_3 = '<div class="box_description_group_content" ></div>';
  319. }
  320. $grid_item_2 = $item_0.$item_1.$item_2.$item_3;
  321. $grid_my_groups[]= array($grid_item_2);
  322. }
  323. }
  324. // Newest groups
  325. $results = GroupPortalManager::get_groups_by_age(4,false);
  326. $grid_newest_groups = array();
  327. foreach ($results as $result) {
  328. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  329. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  330. $id = $result['id'];
  331. $url_open = '<a href="groups.php?id='.$id.'">';
  332. $url_close = '</a>';
  333. $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));
  334. if ($count_users_group == 1 ) {
  335. $count_users_group = $count_users_group.' '.get_lang('Member');
  336. } else {
  337. $count_users_group = $count_users_group.' '.get_lang('Members');
  338. }
  339. $name = cut($result['name'],GROUP_TITLE_LENGTH,true);
  340. $picture = GroupPortalManager::get_picture_group($result['id'], $result['picture_uri'],80);
  341. $result['picture_uri'] = '<img class="social-groups-image" src="'.$picture['file'].'" hspace="4" height="50" border="2" align="left" width="50" />';
  342. $item_0 = Display::div($result['picture_uri'], array('class'=>'box_description_group_image'));
  343. $members = Display::span($count_users_group, array('class'=>'box_description_group_member'));
  344. $item_1 = Display::div(Display::tag('h3', $url_open.$name.$url_close).$members, array('class'=>'box_description_group_title'));
  345. if ($result['description'] != '') {
  346. $item_3 = '<div class="box_description_group_content" >'.cut($result['description'],100,true).'</div>';
  347. } else {
  348. $item_2 = '<div class="box_description_group_title" ><span class="social-groups-text2"></span></div>';
  349. $item_3 = '<div class="box_description_group_content" ></div>';
  350. }
  351. //Avoiding my groups
  352. $join_url = '';
  353. if (!in_array($id,$my_group_list)) {
  354. $join_url = '<a class="btn" href="groups.php?id='.$id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a> ';
  355. }
  356. $item_4 = '<div class="box_description_group_actions" >'.$join_url.'</div>';
  357. $grid_item_2 = $item_0.$item_1.$item_2.$item_3.$item_4;
  358. $grid_newest_groups[]= array($grid_item_2);
  359. }
  360. // Pop groups
  361. $results = GroupPortalManager::get_groups_by_popularity(4,false);
  362. $grid_pop_groups = array();
  363. if (is_array($results) && count($results) > 0) {
  364. foreach ($results as $result) {
  365. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  366. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  367. $id = $result['id'];
  368. $url_open = '<a href="groups.php?id='.$id.'">';
  369. $url_close = '</a>';
  370. $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));
  371. if ($count_users_group == 1 ) {
  372. $count_users_group = $count_users_group.' '.get_lang('Member');
  373. } else {
  374. $count_users_group = $count_users_group.' '.get_lang('Members');
  375. }
  376. $name = cut($result['name'],GROUP_TITLE_LENGTH,true);
  377. $picture = GroupPortalManager::get_picture_group($result['id'], $result['picture_uri'],80);
  378. $result['picture_uri'] = '<img class="social-groups-image" src="'.$picture['file'].'" hspace="4" height="50" border="2" align="left" width="50" />';
  379. $item_0 = Display::div($result['picture_uri'], array('class'=>'box_description_group_image'));
  380. $members = Display::span($count_users_group, array('class'=>'box_description_group_member'));
  381. $item_1 = Display::div(Display::tag('h3', $url_open.$name.$url_close).$members, array('class'=>'box_description_group_title'));
  382. if ($result['description'] != '') {
  383. $item_3 = '<div class="box_description_group_content" >'.cut($result['description'],100,true).'</div>';
  384. } else {
  385. $item_2 = '<div class="box_description_group_title" ><span class="social-groups-text2"></span></div>';
  386. $item_3 = '<div class="box_description_group_content" ></div>';
  387. }
  388. $join_url = '';
  389. if (!in_array($id,$my_group_list)) {
  390. $join_url = '<a class="btn" href="groups.php?id='.$id.'&action=join&u='.api_get_user_id().'">'.get_lang('JoinGroup').'</a> ';
  391. }
  392. $item_4 = '<div class="box_description_group_actions" >'.$join_url.'</div>';
  393. $grid_item_2 = $item_0.$item_1.$item_2.$item_3.$item_4;
  394. $grid_pop_groups[]= array($grid_item_2);
  395. }
  396. }
  397. // Display groups (newest, mygroups, pop)
  398. $query_vars = array();
  399. if (isset($_GET['view']) && in_array($_GET['view'],$allowed_views)) {
  400. $view_group = $_GET['view'];
  401. switch ($view_group) {
  402. case 'mygroups' :
  403. if (count($grid_my_groups) > 0) {
  404. $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));
  405. }
  406. if (api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  407. $create_group_item = '<a class="btn" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.get_lang('CreateASocialGroup').'</a>';
  408. //$my_group_content = $create_group_item. $my_group_content;
  409. } else {
  410. if (api_is_allowed_to_edit(null,true)) {
  411. $create_group_item = '<a class="btn" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.get_lang('CreateASocialGroup').'</a>';
  412. }
  413. }
  414. break;
  415. case 'newest' :
  416. if (count($grid_newest_groups) > 0) {
  417. $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));
  418. }
  419. if (api_is_platform_admin() || api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  420. if (empty($grid_newest_groups)) {
  421. //echo '<a href="group_add.php">'.get_lang('YouShouldCreateAGroup').'</a>';
  422. }
  423. }
  424. break;
  425. default :
  426. if (count($grid_pop_groups) > 0) {
  427. $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));
  428. }
  429. if (api_is_platform_admin() || api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  430. if (empty($grid_pop_groups)) {
  431. //echo '<a href="group_add.php">'.get_lang('YouShouldCreateAGroup').'</a>';
  432. }
  433. }
  434. break;
  435. }
  436. } else {
  437. $my_group_content = null;
  438. if (count($grid_my_groups) > 0) {
  439. $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));
  440. }
  441. if (api_get_setting('allow_students_to_create_groups_in_social') == 'true') {
  442. $create_group_item = '<a class="btn" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.get_lang('CreateASocialGroup').'</a>';
  443. //$my_group_content = $create_group_item. $my_group_content;
  444. } else {
  445. if (api_is_allowed_to_edit(null,true)) {
  446. $create_group_item = '<a class="btn" href="'.api_get_path(WEB_PATH).'main/social/group_add.php">'.get_lang('CreateASocialGroup').'</a>';
  447. }
  448. }
  449. if (count($grid_newest_groups) > 0) {
  450. $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));
  451. }
  452. if (count($grid_pop_groups) > 0) {
  453. $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));
  454. }
  455. }
  456. if (!empty($create_group_item)) {
  457. $social_right_content .= Display::div($create_group_item, array('class'=>'span9'));
  458. }
  459. $headers = array(get_lang('Newest'), get_lang('Popular'), get_lang('MyGroups'));
  460. $social_right_content .= '<div class="span9">'.Display::tabs($headers, array($newest_content, $popular_content, $my_group_content),'tab_browse').'</div>';
  461. }
  462. //Display :: display_footer();
  463. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'show_message' && $_REQUEST['msg'] == 'topic_deleted') {
  464. $show_message = Display::return_message(get_lang('Deleted'), 'success');
  465. }
  466. $tpl = new Template($tool_name);
  467. $tpl->set_help('Groups');
  468. $tpl->assign('social_left_content', $social_left_content);
  469. $tpl->assign('social_left_menu', $social_left_menu);
  470. $tpl->assign('social_right_content', $social_right_content);
  471. $social_layout = $tpl->get_template('layout/social_layout.tpl');
  472. $content = $tpl->fetch($social_layout);
  473. $tpl->assign('actions', $actions);
  474. $tpl->assign('message', $show_message);
  475. $tpl->assign('content', $content);
  476. $tpl->display_one_col_template();