Esempio n. 1
0
function multiLevelJSON($array, $structure, $orderBy)
{
    $restructuredJSON = array();
    $levels = array();
    $fields = array();
    $keys = array();
    $keysTemp = array();
    $idx = array();
    $numLev = count($structure);
    $codeLines = buildLines($numLev);
    foreach ($structure as $level => $value) {
        $levels[] = $level;
        $fields[] = $value;
        $idx[] = -1;
        $keys_fields = array_values($structure[$level]);
        $keys[] = array_shift($keys_fields);
        $keysTemp[] = '';
    }
    if (count($orderBy)) {
        $array = orderArrayByKeys($array, $orderBy);
    }
    foreach ($array as $row) {
        for ($cLevel = 0; $cLevel < $numLev; $cLevel++) {
            if ($keysTemp[$cLevel] !== $row[$keys[$cLevel]]) {
                $idx[$cLevel]++;
                for ($i = $cLevel; $i < $numLev - 1; $i++) {
                    $idx[$i + 1] = -1;
                    $keysTemp[$i + 1] = '';
                }
                foreach ($fields[$cLevel] as $newName => $name) {
                    eval($codeLines[$cLevel]);
                }
            }
        }
        for ($i = 0; $i < $numLev; $i++) {
            $keysTemp[$i] = $row[$keys[$i]];
        }
    }
    return $restructuredJSON;
}
Esempio n. 2
0
function undeleteLine()
{
    global $debug, $message, $success, $Dbc, $returnThis;
    $output = '';
    try {
        if (!isset($_SESSION['listRoleId']) || $_SESSION['listRoleId'] < 2) {
            throw new Adrlist_CustomException("Your role doesn't allow you to edit this list.", '');
        } elseif (empty($_POST['lineId'])) {
            throw new Adrlist_CustomException('', 'lineId is empty.');
        } elseif (empty($_POST['charId'])) {
            throw new Adrlist_CustomException('', 'charName is empty.');
        }
        $Dbc->beginTransaction();
        $updateDeletedLinesStmt = $Dbc->prepare("UPDATE\n\tlinesTable\nSET\n\tlinesTable.dId = NULL,\n\tlinesTable.deleted = NULL\nWHERE\n\tlinesTable.lineId = ?");
        $updateDeletedLinesStmt->execute(array(intThis($_POST['lineId'])));
        $updateDeletedCharactersStmt = $Dbc->prepare("UPDATE\n\tcharacters\nSET\n\tcharacters.dId = NULL,\n\tcharacters.deleted = NULL\nWHERE\n\tcharacters.charId = ?");
        $updateDeletedCharactersStmt->execute(array(intThis($_POST['charId'])));
        $Dbc->commit();
        updateListHist($_SESSION['listId']);
        if (MODE == 'undeleteLine') {
            $success = true;
            $returnThis['buildLines'] = buildLines();
        }
    } catch (Adrlist_CustomException $e) {
    } catch (PDOException $e) {
        error(__LINE__, '', '<pre>' . $e . '</pre>');
    }
    if (MODE == 'undeleteLine') {
        returnData();
    }
}