groups.php 24 KB

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