Exemple #1
0
function AJsubmitRenameNode()
{
    global $user;
    $activeNode = processInputVar("activeNode", ARG_NUMERIC);
    if (empty($activeNode)) {
        return;
    }
    if (!checkUserHasPriv("nodeAdmin", $user["id"], $activeNode)) {
        $msg = "You do not have rights to rename this node.";
        $arr = array('error' => 1, 'message' => $msg);
        sendJSON($arr);
        return;
    }
    $newname = processInputVar('newname', ARG_STRING);
    $errmsg = '';
    if (!validateNodeName($newname, $errmsg)) {
        $arr = array('error' => 2, 'message' => $errmsg);
        sendJSON($arr);
        return;
    }
    # check if node matching new name already exists at parent
    $_newname = mysql_real_escape_string($newname);
    $query = "SELECT id " . "FROM privnode " . "WHERE parent = (SELECT parent FROM privnode WHERE id = {$activeNode}) AND " . "name = '{$_newname}'";
    $qh = doQuery($query, 101);
    if (mysql_num_rows($qh)) {
        $msg = i("A sibling node of that name currently exists");
        $arr = array('error' => 2, 'message' => $msg);
        sendJSON($arr);
        return;
    }
    $query = "UPDATE privnode " . "SET name = '{$_newname}' " . "WHERE id = {$activeNode}";
    doQuery($query, 101);
    $arr = array('newname' => $newname, 'node' => $activeNode);
    sendJSON($arr);
}
function XMLRPCaddNode($nodeName, $parentNode)
{
    require_once ".ht-inc/privileges.php";
    global $user;
    if (!is_numeric($parentNode)) {
        return array('status' => 'error', 'errorcode' => 78, 'errormsg' => 'Invalid nodeid specified');
    }
    if (in_array("nodeAdmin", $user['privileges'])) {
        $nodeInfo = getNodeInfo($parentNode);
        if (is_null($nodeInfo)) {
            return array('status' => 'error', 'errorcode' => 78, 'errormsg' => 'Invalid nodeid specified');
        }
        if (!validateNodeName($nodeName, $tmp)) {
            return array('status' => 'error', 'errorcode' => 81, 'errormsg' => 'Invalid node name');
        }
        if (checkUserHasPriv("nodeAdmin", $user['id'], $parentNode)) {
            $query = "SELECT id " . "FROM privnode " . "WHERE name = '{$nodeName}' AND parent = {$parentNode}";
            $qh = doQuery($query);
            if (mysql_num_rows($qh)) {
                return array('status' => 'error', 'errorcode' => 82, 'errormsg' => 'A node of that name already exists under ' . $nodeInfo['name']);
            }
            $query = "INSERT IGNORE INTO privnode " . "(parent, name) " . "VALUES " . "({$parentNode}, '{$nodeName}')";
            doQuery($query);
            $qh = doQuery("SELECT LAST_INSERT_ID() FROM privnode", 101);
            if (!($row = mysql_fetch_row($qh))) {
                return array('status' => 'error', 'errorcode' => 85, 'errormsg' => 'Could not add node to database');
            }
            $nodeid = $row[0];
            return array('status' => 'success', 'nodeid' => $nodeid);
        } else {
            return array('status' => 'error', 'errorcode' => 49, 'errormsg' => 'Unable to add node at this location');
        }
    } else {
        return array('status' => 'error', 'errorcode' => 70, 'errormsg' => 'User cannot access node content');
    }
}