groups.php 24 KB

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