if ($_GET['filterSearch']) { $pieces = explode(" ", $_GET['filterSearch']); $first_name = $pieces[0]; $second_name = $pieces[1]; $users_username = getUsernameByCompleteName($first_name, $second_name); } else { $users_username = array(); } } } if (count($users_username) != 0) { foreach ($users_username as $username) { $users_info[$username['username']] = getUserProfileInfo($username['username']); $users_info[$username['username']]['isrequester'] = isrequester(getUserId($_SESSION['username']), getUserId($username['username'])); $users_info[$username['username']]['friendship_status'] = getFriendshipState(getUserId($_SESSION['username']), getUserId($username['username'])); $users_info[$username['username']]['n_friends_prf'] = countFriends(getUserId($username['username'])); } } else { $users_info = array(); } //PAGINATION!!! if (!$_GET['page']) { $current_page = 0; $filter = $_GET['filter']; $filterSearch = $_GET['filterSearch']; } else { $current_page = $_GET['page']; $filter = $_GET['filter']; $filterSearch = $_GET['filterSearch']; } $usersPerPage = 6;
$smarty->assign('state', 'logged_in'); } } $smarty->assign('admin_status', isAdmin($_SESSION['username'])); $smarty->assign('session', $_SESSION['username']); $smarty->assign('session_info', getUserProfileInfo($_SESSION['username'])); if (!$_GET['username']) { $profile_username = $_SESSION['username']; } else { $profile_username = $_GET['username']; $smarty->assign('friendship_status', getFriendshipState(getUserId($_SESSION['username']), getUserId($profile_username))); $smarty->assign('isrequester', isrequester(getUserId($_SESSION['username']), getUserId($profile_username))); } $smarty->assign('profile_info', getUserProfileInfo($profile_username)); $smarty->assign('n_friends_usr', countFriends(getUserId($_SESSION['username']))); $smarty->assign('n_friends_prf', countFriends(getUserId($profile_username))); $smarty->assign('n_circles', getNumberOfCircles(getUserId($_SESSION['username']))); $friendsID = getFriendsId($profile_username); foreach ($friendsID as $friendID) { $friends[$friendID['idauthenticated2']] = getUsername($friendID['idauthenticated2']); $friends[$friendID['idauthenticated2']]['info'] = getUserProfileInfo(getUsername($friendID['idauthenticated2'])['username']); } $smarty->assign('friends', $friends); $data = getCurrentDate(); $smarty->assign('data', $data); $circles = getCirclesByUser(getUserId($_SESSION['username'])); $smarty->assign('circles', $circles); $posts = getUserPosts($profile_username, getUserId($profile_username)); foreach ($posts as $post) { if (postInCircle($post['idpost'])) { if (postFromCorrectCircle(getUserId($_SESSION['username']), $post['idpost'])) {
$photoPath = NULL; //check if image uploaded if (checkImageUploaded()) { $photo = getImageTmpName(); $photoPath = getImagePath($recipeId); if (!mkdir("images/" . $recipeId, 0777, true)) { exit('Could not upload image to server.'); } if (!move_uploaded_file($photo, "images/" . $photoPath)) { exit('Could not create space on server for image.'); } if (!updateImagePathInDB($conn, "images/" . $photoPath, $recipeId)) { exit('Could not connect image to account.'); } } $numFriends = countFriends(); $success = addFriendsToDB($conn, $numFriends, $recipeId); //if error in inserting friends into db if (!$success) { exit("Sorry, could not access database when adding friends. Please try again."); } if ($privacy == 'friendly') { $sql = "SELECT email\n FROM Account\n WHERE user_id = '{$userId}' "; $result = mysqli_query($conn, $sql); $row = mysqli_fetch_assoc($result); $emailAddr = $row["email"]; $sql = "INSERT INTO Friends (email, type, type_id) \n VALUES ('{$emailAddr}', 'RECIPE','{$recipeId}');"; $conn->query($sql); } $success = addIngredientsToDB($conn, $recipeId); //if error in inserting ingredients into db