PageRenderTime 54ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/mods/_standard/social/index_public.php

https://github.com/harriswong/ATutor
PHP | 127 lines | 61 code | 12 blank | 54 comment | 13 complexity | 526b488a88d27cbb16573a43d6850590 MD5 | raw file
  1. <?php
  2. /***********************************************************************/
  3. /* ATutor */
  4. /***********************************************************************/
  5. /* Copyright (c) 2002-2010 */
  6. /* Inclusive Design Institute */
  7. /* http://atutor.ca */
  8. /* */
  9. /* This program is free software. You can redistribute it and/or */
  10. /* modify it under the terms of the GNU General Public License */
  11. /* as published by the Free Software Foundation. */
  12. /***********************************************************************/
  13. // $Id$
  14. $_user_location = 'public';
  15. define('AT_INCLUDE_PATH', '../../../include/');
  16. require(AT_INCLUDE_PATH.'vitals.inc.php');
  17. require(AT_SOCIAL_INCLUDE.'constants.inc.php');
  18. require(AT_SOCIAL_INCLUDE.'friends.inc.php');
  19. require(AT_SOCIAL_INCLUDE.'classes/PrivacyControl/PrivacyObject.class.php');
  20. require(AT_SOCIAL_INCLUDE.'classes/PrivacyControl/PrivacyController.class.php');
  21. $_custom_css = $_base_path . AT_SOCIAL_BASENAME . 'module.css'; // use a custom stylesheet
  22. $rand_key = $addslashes($_POST['rand_key']); //should we excape?
  23. //paginator settings
  24. $page = intval($_GET['p']);
  25. if (!$page) {
  26. $page = 1;
  27. }
  28. $count = (($page-1) * SOCIAL_FRIEND_SEARCH_MAX) + 1;
  29. $offset = ($page-1) * SOCIAL_FRIEND_SEARCH_MAX;
  30. //if $_GET['q'] is set, handle Ajax.
  31. if (isset($_GET['q'])){
  32. $query = $addslashes($_GET['q']);
  33. //retrieve a list of friends by the search
  34. $search_result = searchFriends($query);
  35. if (!empty($search_result)){
  36. echo '<div class="suggestions">'._AT('suggestions').':<br/>';
  37. $counter = 0;
  38. foreach($search_result as $member_id=>$member_array){
  39. //display 10 suggestions
  40. if ($counter > 10){
  41. break;
  42. }
  43. echo '<a href="javascript:void(0);" onclick="document.getElementById(\'search_friends\').value=\''.printSocialName($member_id, false).'\'; document.getElementById(\'search_friends_form\').submit();">'.printSocialName($member_id, false).'</a><br/>';
  44. $counter++;
  45. }
  46. echo '</div>';
  47. }
  48. exit;
  49. }
  50. //safe guard
  51. //No friend request on index_public.. need login
  52. /*
  53. if (isset($_GET['id'])){
  54. $id = intval($_GET['id']);
  55. if($id > 0){
  56. addFriendRequest($id);
  57. $msg->addFeedback('REQUEST_FRIEND_ADDED');
  58. $sql_notify = "SELECT first_name, last_name, email FROM ".TABLE_PREFIX."members WHERE member_id=$id";
  59. $result_notify = mysql_query($sql_notify, $db);
  60. $row_notify = mysql_fetch_assoc($result_notify);
  61. if ($row_notify['email'] != '') {
  62. require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
  63. $body = _AT('notification_new_contact', get_display_name($_SESSION['member_id']), $_base_href.AT_SOCIAL_BASENAME.'index_mystart.php');
  64. $sender = get_display_name($_SESSION['member_id']);
  65. $mail = new ATutorMailer;
  66. $mail->AddAddress($row_notify['email'], $sender);
  67. $mail->FromName = $_config['site_name'];
  68. $mail->From = $_config['contact_email'];
  69. $mail->Subject = _AT('contact_request');
  70. $mail->Body = $body;
  71. if(!$mail->Send()) {
  72. $msg->addError('SENDING_ERROR');
  73. }
  74. unset($mail);
  75. }
  76. header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'connections.php', AT_PRETTY_URL_IS_HEADER));
  77. exit;
  78. }
  79. }
  80. */
  81. //handle search friends request
  82. if(($rand_key!='' && isset($_POST['search_friends_'.$rand_key])) || isset($_GET['search_friends'])){
  83. if (empty($_POST['search_friends_'.$rand_key]) && !isset($_GET['search_friends'])){
  84. $msg->addError('CANNOT_BE_EMPTY');
  85. header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'index_public.php', AT_PRETTY_URL_IS_HEADER));
  86. exit;
  87. }
  88. //to adapt paginator GET queries
  89. if($_GET['search_friends']){
  90. $search_field = $addslashes($_GET['search_friends']);
  91. } else {
  92. $search_field = $addslashes($_POST['search_friends_'.$rand_key]);
  93. }
  94. if (isset($_POST['myFriendsOnly'])){
  95. //retrieve a list of my friends
  96. $friends = searchFriends($search_field, true);
  97. } else {
  98. //retrieve a list of friends by the search
  99. $friends = searchFriends($search_field); //to calculate the total number. TODO: need a better way, wasting runtime.
  100. $num_pages = max(ceil(sizeof($friends) / SOCIAL_FRIEND_SEARCH_MAX), 1);
  101. $friends = searchFriends($search_field, false, $offset);
  102. }
  103. }
  104. include(AT_INCLUDE_PATH.'header.inc.php');
  105. $savant->assign('page', $page);
  106. $savant->assign('num_pages', $num_pages);
  107. $savant->assign('search_field', $search_field);
  108. $savant->assign('friends', $friends);
  109. $savant->assign('rand_key', $rand_key);
  110. $savant->display('social/index_public.tmpl.php');
  111. include(AT_INCLUDE_PATH.'footer.inc.php');
  112. ?>