Example #1
0
function package_graph_template_import(&$xml_array, $package_id, $object_hash) {
	require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php");
	require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_info.php");
	require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_update.php");

	$save_fields = array();

	/* tag the graph template as a package member */
	$save_fields["package_id"] = $package_id;

	/*
	 * XML Tag: <template>
	 */

	/* obtain a list of all graph template specific fields */
	$graph_template_fields = api_graph_template_form_list();

	if (isset($xml_array["template"])) {
		/* get the base fields from the xml */
		foreach (array_keys($graph_template_fields) as $field_name) {
			if (isset($xml_array["template"][$field_name])) {
				$save_fields[$field_name] = xml_character_decode($xml_array["template"][$field_name]);
			}
		}
	}

	/*
	 * XML Tag: <graph>
	 */

	/* obtain a list of all graph specific fields */
	$graph_fields = api_graph_form_list();

	if (isset($xml_array["graph"])) {
		/* get the base fields from the xml */
		foreach (array_keys($graph_fields) as $field_name) {
			if (isset($xml_array["graph"][$field_name])) {
				$save_fields[$field_name] = xml_character_decode($xml_array["graph"][$field_name]);
			}
		}
	}

	/* make sure we got the required information before trying to save */
	if ((isset($xml_array["template"])) && (isset($xml_array["graph"]))) {
		/* save the graph template field to the database and register its new id */
		$graph_template_id = package_hash_update($object_hash, api_graph_template_save(0, $save_fields));
	}

	/* make sure the save completed successfully */
	if ($graph_template_id === false) {
		return;
	}

	/*
	 * XML Tag: <items>
	 */

	/* obtain a list of all graph template item specific fields */
	$graph_template_item_fields = api_graph_template_item_form_list();

	if ((isset($xml_array["items"])) && (is_array($xml_array["items"]))) {
		$save_fields = array();

		/* get the base fields from the xml */
		foreach ($xml_array["items"] as $graph_template_item_hash => $graph_template_item) {
			$save_fields = array();

			/* make sure that each field is associated with the new graph template */
			$save_fields["graph_template_id"] = $graph_template_id;

			/* get the base fields from the xml */
			foreach (array_keys($graph_template_item_fields) as $field_name) {
				if (isset($graph_template_item[$field_name])) {
					if ($field_name == "data_template_item_id") {
						$save_fields[$field_name] = package_hash_resolve($graph_template_item[$field_name]);
					}else{
						$save_fields[$field_name] = xml_character_decode($graph_template_item[$field_name]);
					}
				}
			}

			/* save the data query field to the database and register its new id */
			package_hash_update($graph_template_item_hash, api_graph_template_item_save(0, $save_fields));
		}
	}

	/*
	 * XML Tag: <suggested_values>
	 */

	if (isset($xml_array["suggested_values"])) {
		$save_fields = array();

		/* get the base fields from the xml */
		foreach ($xml_array["suggested_values"] as $field_array) {
			if ((isset($field_array["field_name"])) && (isset($field_array["sequence"])) && (isset($field_array["value"]))) {
				/* build an array containing each data input field */
				$save_fields{$field_array["field_name"]}[] = array("id" => "0", "value" => xml_character_decode($field_array["value"]));
			}
		}

		/* save the suggested values to the database */
		api_graph_template_suggested_values_save($graph_template_id, $save_fields);
	}
}
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}");
            }
        }
    }
}