Example #1
0
function api_graph_template_list($filter_array = "", $current_page = 0, $rows_per_page = 0) {
	require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_form.php");

	$sql_where = "";
	/* validation and setup for the WHERE clause */
	if ((is_array($filter_array)) && (sizeof($filter_array) > 0)) {
		/* validate each field against the known master field list */
		$field_errors = api_graph_template_fields_validate(sql_filter_array_to_field_array($filter_array));

		/* if a field input error has occured, register the error in the session and return */
		if (sizeof($field_errors) > 0) {
			field_register_error($field_errors);
			return false;
		/* otherwise, form an SQL WHERE string using the filter fields */
		}else{
			$sql_where = sql_filter_array_to_where_string($filter_array, api_graph_template_form_list(), true);
		}
	}

	$sql_limit = "";
	/* validation and setup for the LIMIT clause */
	if ((is_numeric($current_page)) && (is_numeric($rows_per_page)) && (!empty($current_page)) && (!empty($rows_per_page))) {
		$sql_limit = "limit " . ($rows_per_page * ($current_page - 1)) . ",$rows_per_page";
	}

	return db_fetch_assoc("select
		graph_template.id,
		graph_template.template_name
		from graph_template
		$sql_where
		" . ($sql_where == "" ? "where" : "and") . " graph_template.package_id = 0
		order by template_name
		$sql_limit");
}
Example #2
0
function form_save()
{
    if ($_POST["action_post"] == "graph_template_edit") {
        $suggested_value_fields = array();
        /* cache all post field values */
        init_post_field_cache();
        reset($_POST);
        /* step #1: field parsing */
        while (list($name, $value) = each($_POST)) {
            if (substr($name, 0, 3) == "sv|") {
                $matches = explode("|", $name);
                $suggested_value_fields[$matches[1]][] = array("id" => $matches[2], "value" => $value);
            }
        }
        /* step #2: field validation */
        $form_graph_template["template_name"] = $_POST["template_name"];
        $form_graph["t_title"] = html_boolean(isset($_POST["t_title"]) ? $_POST["t_title"] : "");
        $form_graph["vertical_label"] = $_POST["vertical_label"];
        $form_graph["t_vertical_label"] = html_boolean(isset($_POST["t_vertical_label"]) ? $_POST["t_vertical_label"] : "");
        $form_graph["image_format"] = $_POST["image_format"];
        $form_graph["t_image_format"] = html_boolean(isset($_POST["t_image_format"]) ? $_POST["t_image_format"] : "");
        $form_graph["export"] = html_boolean(isset($_POST["export"]) ? $_POST["export"] : "");
        $form_graph["t_export"] = html_boolean(isset($_POST["t_export"]) ? $_POST["t_export"] : "");
        $form_graph["force_rules_legend"] = html_boolean(isset($_POST["force_rules_legend"]) ? $_POST["force_rules_legend"] : "");
        $form_graph["t_force_rules_legend"] = html_boolean(isset($_POST["t_force_rules_legend"]) ? $_POST["t_force_rules_legend"] : "");
        $form_graph["height"] = $_POST["height"];
        $form_graph["t_height"] = html_boolean(isset($_POST["t_height"]) ? $_POST["t_height"] : "");
        $form_graph["width"] = $_POST["width"];
        $form_graph["t_width"] = html_boolean(isset($_POST["t_width"]) ? $_POST["t_width"] : "");
        $form_graph["x_grid"] = $_POST["x_grid"];
        $form_graph["t_x_grid"] = html_boolean(isset($_POST["t_x_grid"]) ? $_POST["t_x_grid"] : "");
        $form_graph["y_grid"] = $_POST["y_grid"];
        $form_graph["t_y_grid"] = html_boolean(isset($_POST["t_y_grid"]) ? $_POST["t_y_grid"] : "");
        $form_graph["y_grid_alt"] = html_boolean(isset($_POST["y_grid_alt"]) ? $_POST["y_grid_alt"] : "");
        $form_graph["t_y_grid_alt"] = html_boolean(isset($_POST["t_y_grid_alt"]) ? $_POST["t_y_grid_alt"] : "");
        $form_graph["no_minor"] = html_boolean(isset($_POST["no_minor"]) ? $_POST["no_minor"] : "");
        $form_graph["t_no_minor"] = html_boolean(isset($_POST["t_no_minor"]) ? $_POST["t_no_minor"] : "");
        $form_graph["auto_scale"] = html_boolean(isset($_POST["auto_scale"]) ? $_POST["auto_scale"] : "");
        $form_graph["t_auto_scale"] = html_boolean(isset($_POST["t_auto_scale"]) ? $_POST["t_auto_scale"] : "");
        $form_graph["auto_scale_opts"] = $_POST["auto_scale_opts"];
        $form_graph["t_auto_scale_opts"] = html_boolean(isset($_POST["t_auto_scale_opts"]) ? $_POST["t_auto_scale_opts"] : "");
        $form_graph["auto_scale_log"] = html_boolean(isset($_POST["auto_scale_log"]) ? $_POST["auto_scale_log"] : "");
        $form_graph["t_auto_scale_log"] = html_boolean(isset($_POST["t_auto_scale_log"]) ? $_POST["t_auto_scale_log"] : "");
        $form_graph["auto_scale_rigid"] = html_boolean(isset($_POST["auto_scale_rigid"]) ? $_POST["auto_scale_rigid"] : "");
        $form_graph["t_auto_scale_rigid"] = html_boolean(isset($_POST["t_auto_scale_rigid"]) ? $_POST["t_auto_scale_rigid"] : "");
        $form_graph["auto_padding"] = html_boolean(isset($_POST["auto_padding"]) ? $_POST["auto_padding"] : "");
        $form_graph["t_auto_padding"] = html_boolean(isset($_POST["t_auto_padding"]) ? $_POST["t_auto_padding"] : "");
        $form_graph["upper_limit"] = $_POST["upper_limit"];
        $form_graph["t_upper_limit"] = html_boolean(isset($_POST["t_upper_limit"]) ? $_POST["t_upper_limit"] : "");
        $form_graph["lower_limit"] = $_POST["lower_limit"];
        $form_graph["t_lower_limit"] = html_boolean(isset($_POST["t_lower_limit"]) ? $_POST["t_lower_limit"] : "");
        $form_graph["base_value"] = $_POST["base_value"];
        $form_graph["t_base_value"] = html_boolean(isset($_POST["t_base_value"]) ? $_POST["t_base_value"] : "");
        $form_graph["unit_value"] = $_POST["unit_value"];
        $form_graph["t_unit_value"] = html_boolean(isset($_POST["t_unit_value"]) ? $_POST["t_unit_value"] : "");
        $form_graph["unit_length"] = $_POST["unit_length"];
        $form_graph["t_unit_length"] = html_boolean(isset($_POST["t_unit_length"]) ? $_POST["t_unit_length"] : "");
        $form_graph["unit_exponent_value"] = $_POST["unit_exponent_value"];
        $form_graph["t_unit_exponent_value"] = html_boolean(isset($_POST["t_unit_exponent_value"]) ? $_POST["t_unit_exponent_value"] : "");
        field_register_error(api_graph_template_fields_validate($form_graph_template, "|field|"));
        field_register_error(api_graph_fields_validate($form_graph, $suggested_value_fields, "|field|", "sv||field|||id|"));
        /* step #3: field save */
        if (!is_error_message()) {
            $graph_template_id = api_graph_template_save($_POST["graph_template_id"], $form_graph_template + $form_graph);
            if ($graph_template_id) {
                api_graph_template_suggested_values_save($graph_template_id, $suggested_value_fields);
            }
        }
        if (is_error_message() || empty($graph_template_id) || empty($_POST["graph_template_id"])) {
            if (isset($_POST["redirect_sv_add"])) {
                $action = "sv_add";
            } else {
                $action = "edit";
            }
            header("Location: graph_templates.php?action={$action}" . (empty($graph_template_id) ? "" : "&id={$graph_template_id}"));
        }
        /* submit button on the actions area page */
    } else {
        if ($_POST["action_post"] == "box-1") {
            $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]);
            if ($_POST["box-1-action-area-type"] == "remove") {
                foreach ($selected_rows as $graph_template_id) {
                    api_graph_template_remove($graph_template_id);
                }
            } else {
                if ($_POST["box-1-action-area-type"] == "duplicate") {
                    // yet yet coded
                }
            }
            header("Location: graph_templates.php");
            /* 'filter' area at the bottom of the box */
        } else {
            if ($_POST["action_post"] == "graph_template_list") {
                $get_string = "";
                /* the 'clear' button wasn't pressed, so we should filter */
                if (!isset($_POST["box-1-action-clear-button"])) {
                    if (trim($_POST["box-1-search_filter"]) != "") {
                        $get_string = ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]);
                    }
                }
                header("Location: graph_templates.php{$get_string}");
            }
        }
    }
}