Exemplo n.º 1
0
function return_array_code($array, $indent = 1, $quote = "\"")
{
    //Example call:
    //$layout_code_string = '$arrLayout = '.return_array_code($arrLayout).";\n";
    $first = true;
    $indentstr = str_repeat("\t", $indent);
    $output = "array(\n\t" . $indentstr;
    foreach ($array as $key => $value) {
        if ($first) {
            $first = false;
        } else {
            $output .= ",\n\t" . $indentstr;
        }
        if (is_array($value)) {
            $value = return_array_code($value, $indent + 1, $quote);
            $output .= $quote . $key . $quote . ' => ' . $value;
        } else {
            $output .= $quote . $key . $quote . ' => ' . $quote . $value . $quote;
        }
    }
    $output .= "\n" . $indentstr . ")";
    return $output;
}
Exemplo n.º 2
0
function save_layout($arrRequest)
{
    if (!empty($arrRequest["params"]) && is_array($arrRequest["params"])) {
        $layoutfile = "layout.php";
        if (is_writable($layoutfile)) {
            $layout_code_string .= "<?php\n" . '$arrLayout = ' . return_array_code($arrRequest["params"]) . ";\n?>\n";
            if ($handle = fopen($layoutfile, 'w')) {
                if (fwrite($handle, $layout_code_string)) {
                    $arrResult = array("result" => array("success" => true, "message" => "Layout file ({$layoutfile}) saved."));
                    fclose($handle);
                } else {
                    $arrResult = error_array(-32502, "Problem writing to file ({$layoutfile}).");
                }
            } else {
                $arrResult = error_array(-32501, "Problem opening file ({$layoutfile}).");
            }
        } else {
            $arrResult = error_array(-32500, "File not writeable.");
        }
    } else {
        $arrResult = error_array(-32602, "Invalid parameters.");
    }
    return $arrResult;
}