@@ -0,0 +1,104 @@
+<?php
+/*
+// isdf - inventory system search
+// Author: Carsten Schoene
+//
+// $LastChangedDate: 2012-07-20 21:09:25 +0200 (Fr, 20. Jul 2012) $
+// $Rev: 1619 $
+*/
+
+// define our name
+define('MYNAME', "isdf-search");
+// open syslog connection
+openlog(MYNAME,LOG_PID | LOG_ODELAY,LOG_MAIL);
+
+// check for required extensions
+if ( ! extension_loaded("mysql") ) {
+ if ( ! dl("mysql") ) {
+ syslog(LOG_ERR,"mysql extension not loaded!");
+ exit;
+ }
+}
+
+// load additional files
+define('BASE',dirname(__FILE__));
+require_once("MDB2.php");
+require_once(BASE . "/config.inc.php");
+require_once(BASE . "/config-custom.inc.php");
+require_once(BASE . "/db.inc.php");
+
+echo '<html><head>
+<title>inventory system - search web</title>
+</head>
+<body>
+<form action="' . $_SERVER['PHP_SELF'] . '"><table>
+<tr><td>Search property:</td>
+ <td><select name="systemid">
+';
+// create database connection
+$dbh =& MDB2::singleton($config['isdf']['db'], $config['mdb2']['options'] );
+
+//$uuidsql = "SELECT id,system_uuid FROM inv_system";
+// datakeys
+$datakeysql = "select datakey from inv_system_properties GROUP BY datakey";
+$options = "";
+$res = $dbh->query($datakeysql);
+if (PEAR::isError($res)) {
+ syslog(LOG_ERR, "MDB2 res: " . $res->getMessage());
+} else {
+ echo '<option value="all">All</option>';
+ while (( $row = $res->fetchRow(MDB2_FETCHMODE_ASSOC) )) {
+ /* if ( isset($_GET['systemid'])) {
+ if ( $row['id'] == $_GET['systemid'] ) {
+ echo '<option selected value="' . $row['id'] . '">' . $row['system_uuid'] . '</option>';
+ } else {
+ echo '<option value="' . $row['id'] . '">' . $row['system_uuid'] . '</option>';
+ }
+ } else { */
+ $options .= '<option value="' . $row['datakey'] . '">' . $row['datakey'] . '</option>';
+ /* } */
+ }
+}
+echo $options;
+$options = preg_replace('#<option#','<option selected="selected"',$options);
+echo '
+</select></td><td><input type="text" size="27" name="search"></td></tr>
+<tr><td colspan="2" valign="top">Select fields for output result:</td><td><select name="output[]" multiple="multiple" size="5">'.$options.'</select></td></tr>
+<tr><td colspan="3" align="right"><input type="submit" value="Search"></td></tr></table></form>
+';
+
+if ( isset($_GET['systemid']) && isset($_GET['search']) && isset($_GET['output'])) {
+ $systemid = $_GET['systemid'];
+ $search = $dbh->escape($_GET['search']);
+ $output = $_GET['output'];
+ if ( $systemid == "all" ) {
+ $idsql = "SELECT inv_system_id FROM inv_system_properties WHERE value LIKE '%$search%'";
+ } else {
+ $idsql = "SELECT inv_system_id FROM inv_system_properties WHERE datakey = '$systemid' AND value LIKE '%$search%'";
+ }
+
+ $idres = $dbh->query($idsql);
+ if (PEAR::isError($idres)) {
+ syslog(LOG_ERR, "MDB2 idres: " . $idres->getMessage());
+ } else {
+ while (( $idrow = $idres->fetchRow(MDB2_FETCHMODE_ASSOC) )) {
+ $datasql = "SELECT datakey, value FROM inv_system_properties WHERE inv_system_id = '". $idrow['inv_system_id'] . "'";
+ $datares = $dbh->query($datasql);
+ if (PEAR::isError($datares)) {
+ syslog(LOG_ERR, "MDB2 datares: " . $datares->getMessage());
+ } else {
+ echo '<table>';
+ echo '<tr><th>Key:</th><th>Value:</th></tr>';
+ while (( $row = $datares->fetchRow(MDB2_FETCHMODE_ASSOC) )) {
+ if ( in_array($row['datakey'], $output) ) {
+ echo '<tr><td valign="top">' . $row['datakey'] . '</td><td>' . $row['value'] . '</td></tr>';
+ }
+ }
+ echo '</table>';
+ }
+ }
+ }
+}
+echo '</body></html>';
+$dbh->disconnect();
+?>
|