Exemple #1
0
function package_view() {
	$_package_id = get_get_var_number("id");

	if (!empty($_package_id)) {
		/* get information about this package */
		$package = api_package_get($_package_id);

		/* get a list of scripts associated with this package */
		$package_scripts = api_package_metadata_list($_package_id, PACKAGE_METADATA_TYPE_SCRIPT);

		/* get a list of screenshots associated with this package */
		$package_screenshots = api_package_metadata_list($_package_id, PACKAGE_METADATA_TYPE_SCREENSHOT);

		/* get a list of all graph templates associated with this package */
		$package_templates = api_package_graph_template_list($_package_id);

		?>
		<table width="98%" align="center" cellspacing="0" cellpadding="3">
			<tr>
				<td valign="top">
					<span class="textInfo"><?php echo htmlspecialchars($package["name"]);?></span> [<a href="packages.php?action=edit&id=<?php echo $package["id"];?>">edit</a>]<br>
					<span class="textArea"><?php echo nl2br(htmlspecialchars($package["description"]));?></a>
				</td>
			</tr>
		</table>
		<br>
		<table width="98%" align="center" cellspacing="1" cellpadding="3">
			<tr>
				<td style="background-color: #9C9C9C; color: white;" colspan="2">
					<strong>Basic Information</strong>
				</td>
			</tr>
			<tr>
				<td width="200" style="background-color: #f5f5f5; border-right: 1px dashed #d1d1d1;">
					<strong>Category</strong>
				</td>
				<td style="border-bottom: 1px solid #f7f7f7;">
					<?php echo $package["category"];?>
				</td>
			</tr>
			<tr>
				<td style="background-color: #f5f5f5; border-right: 1px dashed #d1d1d1;">
					<strong>Sub Category</strong>
				</td>
				<td style="border-bottom: 1px solid #f7f7f7;">
					<?php echo $package["subcategory"];?>
				</td>
			</tr>
			<tr>
				<td style="background-color: #f5f5f5; border-right: 1px dashed #d1d1d1;">
					<strong>Vendor</strong>
				</td>
				<td style="border-bottom: 1px solid #f7f7f7;">
					<?php echo $package["vendor"];?>
				</td>
			</tr>
			<tr>
				<td style="background-color: #f5f5f5; border-right: 1px dashed #d1d1d1;">
					<strong>Model/Version</strong>
				</td>
				<td>
					<?php echo $package["model"];?>
				</td>
			</tr>
			<tr>
				<td style="background-color: #9C9C9C; color: white;" colspan="2">
					<strong>Author Information</strong>
				</td>
			</tr>
			<tr>
				<td width="200" style="background-color: #f5f5f5; border-right: 1px dashed #d1d1d1;">
					<strong>Author Name</strong>
				</td>
				<td style="border-bottom: 1px solid #f7f7f7;">
					<?php echo $package["author_name"];?>
				</td>
			</tr>
			<tr>
				<td style="background-color: #f5f5f5; border-right: 1px dashed #d1d1d1;">
					<strong>Author Email</strong>
				</td>
				<td style="border-bottom: 1px solid #f7f7f7;">
					<?php echo $package["author_email"];?>
				</td>
			</tr>
			<tr>
				<td style="background-color: #f5f5f5; border-right: 1px dashed #d1d1d1;">
					<strong>Forum User</strong>
				</td>
				<td style="border-bottom: 1px solid #f7f7f7;">
					<?php echo $package["author_user_forum"];?>
				</td>
			</tr>
			<tr>
				<td style="background-color: #f5f5f5; border-right: 1px dashed #d1d1d1;">
					<strong>Template Repository User</strong>
				</td>
				<td style="border-bottom: 1px solid #f7f7f7;">
					<?php echo $package["author_user_repository"];?>
				</td>
			</tr>
		</table>
		<?php
		if (sizeof($package_templates) > 0) {
			?>
			<br>
			<table width="98%" align="center" cellspacing="0" cellpadding="3">
				<tr>
					<td>
						<p class="textInfo">Associated Graph Templates</p>
					</td>
				</tr>
				<tr>
					<td>
						<ul style="list-style-type: disc; font-size: 12px;">
						<?php
						foreach ($package_templates as $template) {
							echo "<li><a href=\"graph_templates.php?action=edit&id=" . $template["id"] . "\">" . $template["template_name"] . "</a></li>\n";
						}
						?>
						</ul>
					</td>
				</tr>
			</table>
			<?php
		}
		?>
		<br>
		<table width="98%" align="center" cellspacing="0" cellpadding="3">
			<tr>
				<td valign="top">
					<p class="textInfo">Installation Instructions</p>
					<p style="font-family: monospace;"><?php echo nl2br(htmlspecialchars($package["description_install"]));?>
				</td>
			</tr>
		</table>
		<?php
		if (sizeof($package_scripts) > 0) {
			?>
			<br>
			<table width="98%" align="center" cellspacing="0" cellpadding="3">
				<tr>
					<td>
						<p class="textInfo">Scripts</p>
					</td>
				</tr>
			</table>
			<br>
			<table width="98%" align="center" cellspacing="1" cellpadding="3">
				<?php
				foreach ($package_scripts as $script) {
					?>
					<tr>
						<td style="background-color: #9C9C9C; color: white;" colspan="2">
							<strong><?php echo $script["name"];?></strong>
						</td>
					</tr>
					<tr>
						<td width="200" style="background-color: #f5f5f5; border-right: 1px dashed #d1d1d1;">
							<strong>Description</strong>
						</td>
						<td style="border-bottom: 1px solid #f7f7f7;">
							<?php echo nl2br(htmlspecialchars($script["description"]));?>
						</td>
					</tr>
					<tr>
						<td width="200" style="background-color: #f5f5f5; border-right: 1px dashed #d1d1d1;">
							<strong>Required</strong>
						</td>
						<td style="border-bottom: 1px solid #f7f7f7;">
							<?php echo (empty($script["required"]) ? "No" : "Yes");?>
						</td>
					</tr>
					<tr>
						<td width="200" style="background-color: #f5f5f5; border-right: 1px dashed #d1d1d1;">
							<strong>Installation Instructions</strong>
						</td>
						<td style="border-bottom: 1px solid #f7f7f7;">
							<?php echo nl2br(htmlspecialchars($script["description_install"]));?>
						</td>
					</tr>
					<tr>
						<td width="200" style="background-color: #f5f5f5; border-right: 1px dashed #d1d1d1;">
							<strong>Payload</strong>
						</td>
						<td style="border-bottom: 1px solid #f7f7f7;">
							<a href="packages.php?action=view_metadata_script&id=<?php echo $script["id"];?>" target="_new">Download Script</a>
						</td>
					</tr>
					<?php
				}
				?>
			</table>
		<?php
		}

		if (sizeof($package_screenshots) > 0) {
			?>
			<br>
			<table width="98%" align="center" cellspacing="0" cellpadding="3">
				<tr>
					<td>
						<p class="textInfo">Screenshots</p>
					</td>
				</tr>
				<tr>
					<td>
						<ul style="list-style-type: disc; font-size: 12px;">
						<?php
						$js_id_list = "";
						$js_title_list = "";
						$js_description_list = "";
						$i = 0;
						foreach ($package_screenshots as $screenshot) {
							echo "<li><a href=\"javascript:view_screenshot($i)\">" . $screenshot["name"] . "</a></li>\n";

							$js_id_list .= "\"" . $screenshot["id"] . "\"" . ($i < sizeof($package_screenshots) - 1 ? "," : "");
							$js_title_list .= "\"" . addslashes(htmlspecialchars($screenshot["name"])) . "\"" . ($i < sizeof($package_screenshots) - 1 ? "," : "");
							$js_description_list .= "\"" . addslashes(htmlspecialchars($screenshot["description"])) . "\"" . ($i < sizeof($package_screenshots) - 1 ? "," : "");

							$i++;
						}
						?>
						</ul>
					</td>
				</tr>
				<tr>
					<td>
					</td>
				</tr>
				<tr>
					<td style="background-color: #9C9C9C; color: white;" colspan="2">
						<strong><span id="screenshot_title"></span></strong>
					</td>
				</tr>
				<tr>
					<td>
						<span id="screenshot_description"></span>
					</td>
				</tr>
				<tr>
					<td>
						<img id="screenshot_image" src="" alt="">
					</td>
				</tr>
			</table>

			<script language="JavaScript">
			<!--
			var screenshot_ids = new Array(<?php echo $js_id_list;?>);
			var screenshot_titles = new Array(<?php echo $js_title_list;?>);
			var screenshot_descriptions = new Array(<?php echo $js_description_list;?>);

			function view_screenshot(id) {
				document.getElementById('screenshot_title').innerHTML = screenshot_titles[id];
				document.getElementById('screenshot_description').innerHTML = screenshot_descriptions[id];
				document.getElementById('screenshot_image').src = 'packages.php?action=view_metadata_screenshot&id=' + screenshot_ids[id];
			}

			view_screenshot(0);
			-->
			</script>
			<?php
		}
	}
}
Exemple #2
0
function &package_header_export($package_id, $indent = 1) {
	require_once(CACTI_BASE_PATH . "/lib/package/package_info.php");

	$xml = "";

	/*
	 * XML Tag: <package>
	 */

	/* obtain a list of all package specific fields */
	$package_fields = api_package_form_list();
	/* obtain a copy of this specfic package */
	$package = api_package_get($package_id);

	$_xml = "";
	foreach (array_keys($package_fields) as $field_name) {
		/* create an XML key for each graph template field */
		$_xml .= package_xml_tag_get($field_name, xml_character_encode($package[$field_name]), $indent + 2);
	}

	/* add a few extra fields that are not part of the form */
	$_package_version = $package["version"] + 1;
	$_package_version_cacti = CACTI_VERSION;
	$_package_date_create = date('Y-m-d H:i:s');

	$_xml .= package_xml_tag_get("version", $_package_version, $indent + 2);
	$_xml .= package_xml_tag_get("version_cacti", $_package_version_cacti, $indent + 2);
	$_xml .= package_xml_tag_get("date_create", $_package_date_create, $indent + 2);

	/* obtain a list of graph template associated with this particular package */
	$package_graph_templates = api_package_graph_template_list($package_id);

	if (sizeof($package_graph_templates) > 0) {
		$i = 0; $items_list = "";
		foreach ($package_graph_templates as $graph_template) {
			/* create a delimited list of each item, making sure to resolve internal ID's */
			$items_list .= package_hash_get($graph_template["id"], "graph_template") . (($i + 1) < sizeof($package_graph_templates) ? "|" : "");

			$i++;
		}
	}

	/* add the items list that we created above */
	$_xml .= package_xml_tag_get("items", $items_list, $indent + 2);

	/* append the result onto the final XML string */
	$xml .= package_xml_tag_get("package", $_xml, $indent + 1, true);

	/*
	 * XML Tag: <metadata>
	 */

	/* obtain a list of all package metadata specific fields */
	$package_metadata_fields = api_package_metadata_form_list();
	/* obtain a list of all package metadata items  */
	$package_metadata_items = api_package_metadata_list($package_id, 0, true);

	$_xml = "";
	if (sizeof($package_metadata_items) > 0) {
		$i = 0;
		foreach ($package_metadata_items as $package_metadata_item) {
			$__xml = "";
			foreach (array_keys($package_metadata_fields) as $field_name) {
				if ($field_name == "payload") {
					/* since the payload might contain binary data, we need to base64 encode it first */
					$__xml .= package_xml_tag_get($field_name, xml_character_encode(wordwrap(base64_encode($package_metadata_item[$field_name]), 100, "\n", true)), $indent + 3);
				}else{
					/* create an XML key for each graph template item field */
					$__xml .= package_xml_tag_get($field_name, xml_character_encode($package_metadata_item[$field_name]), $indent + 3);
				}
			}

			/* append the result onto a temporary XML string */
			$_xml .= package_xml_tag_get("item_" . str_pad($i, 5, "0", STR_PAD_LEFT), $__xml, $indent + 2, true);

			$i++;
		}
	}

	/* append the result onto the final XML string */
	$xml .= package_xml_tag_get("metadata", $_xml, $indent + 1, true);

	$xml = package_xml_tag_get("header", $xml, $indent, true);

	return $xml;
}