<?php

include_once 'classes/session.class.php';
include_once 'classes/database.php';
include_once 'classes/sharings.class.php';
function my_return($content)
{
    print $content;
    exit;
}
// Sprawdza czy użytkownik jest zalogowany
try {
    $session = new Session();
} catch (Exception $e) {
    my_return('login');
}
if (!array_key_exists('friend', $_POST)) {
    my_return('error');
}
$friend = $_POST['friend'][1];
$db_handler = new Database();
$sharings = new Sharings($session->user_id);
$results = $db_handler->query('SELECT id FROM users_data WHERE CONCAT(first_name, " ", last_name) = "' . $friend . '"');
if ($results->num_rows) {
    $result = $results->fetch_assoc();
    $sharings->add($result['id']);
} else {
    my_return('error');
}
Beispiel #2
0
<?php

include_once 'smarty/Smarty.class.php';
include_once 'classes/session.class.php';
include_once 'classes/user.class.php';
include_once 'classes/sharings.class.php';
include_once 'classes/settings.class.php';
// Nie pozwala pobrać strony przy niezalogowaniu
if (!Session::exists()) {
    print 'login';
    exit;
}
$smarty = new Smarty();
$smarty->template_dir = 'templates/';
$smarty->compile_dir = 'smarty/templates_c/';
$smarty->config_dir = 'smarty/configs/';
$smarty->cache_dir = 'smarty/cache/';
$session = new Session();
$sharings = new Sharings($session->user_id);
$friends = array();
foreach ($sharings->get_sharings() as $sharing) {
    $user = new User($sharing->user_id);
    $name = $user->first_name . ' ' . $user->last_name;
    $settings = new Settings($sharing->user_id);
    $photo_name = $settings->photo_name;
    $friends[] = array('name' => $name, 'photo_name' => $photo_name);
}
$smarty->assign('friends', $friends);
$smarty->display('friends.tpl');