示例#1
0
}
function viewFileName($view_name)
{
    global $conf;
    $view_suffix = str_replace(" ", "_", $view_name);
    return $conf['views_dir'] . "/view_" . preg_replace('/[^a-zA-Z0-9_-]/', '', $view_suffix) . ".json";
}
$viewList = new ViewList();
///////////////////////////////////////////////////////////////////////////////
// Create new view
///////////////////////////////////////////////////////////////////////////////
if (isset($_GET['create_view'])) {
    if (!checkAccess(GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT, $conf)) {
        $output = "You do not have access to edit views.";
    } else {
        if ($viewList->viewExists($view_name)) {
            $output = "<strong>Alert:</strong> View with the name " . $view_name . " already exists.";
        } else {
            $empty_view = array("view_name" => $view_name, "items" => array());
            $view_filename = viewFileName($view_name);
            if (pathinfo($view_filename, PATHINFO_DIRNAME) != $conf['views_dir']) {
                die('Invalid path detected');
            }
            $json = json_encode($empty_view);
            if (file_put_contents($view_filename, json_prettyprint($json)) === FALSE) {
                $output = "<strong>Alert:</strong>" . " Can't write to file " . htmlspecialchars($view_filename) . " Perhaps permissions are wrong.";
            } else {
                $output = "View has been created successfully.";
            }
        }
    }