Esempio n. 1
0
function store_new_links($url, $name, $pid, $weight)
{
    global $xoopsDB;
    $url = normal_url($url);
    $now = time();
    $data = array('cutid' => cutid_default($url), 'url' => $url, 'uid' => 0, 'title' => $name, 'pscref' => $pid);
    foreach ($data as $k => $v) {
        $data[$k] = $xoopsDB->quoteString($v);
    }
    if (!$pid) {
        if (!$weight) {
            $res = $xoopsDB->query("SELECT max(weight) FROM " . SHORT . " WHERE pscref=0 AND uid=0");
            list($weight) = $xoopsDB->fetchRow($res);
            $weight++;
        }
    } else {
        if ($weight) {
            $res = $xoopsDB->query("SELECT weight FROM " . SHORT . " WHERE pscref={$pid} AND weight={$weight} AND uid=0");
            if ($xoopsDB->getRowsNum($res)) {
                $res = $xoopsDB->query("UPDATE " . SHORT . " SET weight=weight+1 WHERE pscref={$pid} AND weight>={$weight} AND uid=0");
            }
        }
    }
    $data['weight'] = $weight;
    $data['mdate'] = time();
    $res = $xoopsDB->query("INSERT INTO " . SHORT . "(" . join(',', array_keys($data)) . ")VALUES(" . join(',', $data) . ") ");
    return $xoopsDB->getInsertID($res);
}
Esempio n. 2
0
    // generate uniq id if empty
    if (isset($_GET['scid'])) {
        $scid = intval($_GET['scid']);
        $cond = "scid=" . $scid;
        if (!$xoopsUser->isAdmin($xoopsModule->getVar('mid'))) {
            $cond .= " AND uid=" . $xoopsUser->getVar('uid');
        }
        $res = $xoopsDB->query('SELECT * FROM ' . SHORTCUT . ' WHERE ' . $cond);
        $data = $xoopsDB->fetchArray($res);
    } else {
        $rand = "";
        do {
            $cutid = substr(base64_encode(md5($xoopsUser->getVar('uid') . '-' . $data['url'] . $rand, true)), 0, 5);
            $rand = rand(0, 1000);
            $res = $xoopsDB->query("SELECT cutid WHERE cutid=" . $xoopsDB->quoteString($cutid));
        } while ($res && $xoopsDB->getRowsNum($res));
        $data['cutid'] = cutid_default($data['url'], $xoopsUser->getVar('uid'));
    }
}
$xoopsOption['template_main'] = 'shortcut_register.html';
$xoopsTpl->assign('link', $data);
$xoopsTpl->assign('active_status', explode(',', _MD_FORM_ACTIVE_VALUE));
$res = $xoopsDB->query("SELECT scid,title,url FROM " . SHORTCUT . " WHERE pscref=0 AND uid={$uid}");
echo $xoopsDB->error();
$pscrefs = array();
while (list($id, $title, $url) = $xoopsDB->fetchRow($res)) {
    $pscrefs[$id] = array('title' => $title, 'url' => $url);
}
$xoopsTpl->assign('pscrefs', root_links($uid, $scid));
$xoopsTpl->assign('active_status', explode(',', _MD_FORM_ACTIVE_VALUE));
include XOOPS_ROOT_PATH . "/footer.php";