예제 #1
0
/**
* @desc Adiciona amigos
**/
function addFriends()
{
    global $add, $xoopsUser, $xoopsModuleConfig, $db;
    $mc =& $xoopsModuleConfig;
    $id = isset($_REQUEST['uname']) ? $_REQUEST['uname'] : '';
    $pag = isset($_REQUEST['pag']) ? intval($_REQUEST['pag']) : '';
    $link = GSFunctions::get_url() . ($mc['urlmode'] ? 'cp/friends/pag/' . $pag . '/' : '?cp=friends&pag=' . $pag);
    //Verificamos que exista el usuario
    $add = $add ? $add : $id;
    $exu = GSFunctions::get_xoops_user($add);
    if (!$exu) {
        redirect_header($link, 1, sprintf(__('User "%s" could not be found!', 'galleries'), $add));
        die;
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    //Verificamos que el usuario no se encuentre registrado
    $sql = "SELECT COUNT(*) FROM " . $db->prefix('gs_friends') . " WHERE gsuser='******' AND uid='" . $exu->uid() . "'";
    list($num) = $db->fetchRow($db->query($sql));
    if ($num > 0) {
        redirect_header($link, 1, sprintf(__('%s is your friend already!', 'galleries'), $exu->uname()));
        die;
    }
    $sql = "INSERT INTO " . $db->prefix('gs_friends') . " (`gsuser`,`uid`) VALUES ('" . $xoopsUser->uid() . "','" . $exu->uid() . "')";
    $result = $db->queryF($sql);
    if (!$result) {
        redirect_header($link, 1, sprintf(__('User %s could not be added as a friend!', 'galleries'), $exu->uname()));
        die;
    } else {
        redirect_header($link, 1, sprintf(__('User %s has been added to your friends list!', 'galleries'), $exu->uname()));
        die;
    }
}