/** * Read values from the database. * @param $row an array of values just read from the database */ public function readRowFromDatabase($row) { $cur = 0; $this->rowid = piaDB::cleanDataRead($row[$cur++]); $this->timestamp_loaded_utc = piaDB::cleanDataRead($row[$cur++]); $this->timestamp_modified_utc = piaDB::cleanDataRead($row[$cur++]); return $cur; }
/** * Process search results from a form submission or via the url. */ public function processSearch() { if (isset($_POST['submit']) && $_POST['submit']) { if (piaForm::isValidTokens(piaSearch::TOKEN_PREFIX)) { $this->searchstr = piaDB::cleanInput($_REQUEST['searchtext']); header("Location: search_results.php?searchstr=" . urlencode($this->searchstr)); } } if (isset($_REQUEST['searchstr'])) { $this->searchstr = piaDB::cleanInput($_REQUEST['searchstr']); } $this->showForm(); $this->showSearchResults(); }
/** * Report indexed sources from pia.source. */ public static function reportSources() { global $piaApp; // // ----- build SQL to read the data // $sql = 'SELECT ' . piaSource::getFields(); $sql .= ', i.num_items, i.size_bytes'; $sql .= piaSource::getJoins(); $sql .= ' INNER JOIN ( SELECT i.source_rowid_fk, COUNT(i.rowid) AS num_items, SUM(i.size_bytes) AS size_bytes FROM pia.index i GROUP BY i.source_rowid_fk ) i ON i.source_rowid_fk = source.rowid'; // // ----- connect to the database and read the data // $db = piaDB::connect(); if ($db) { $result = pg_query($db, $sql); if (!$result) { piaDB::errorWithSQL($sql); } if (pg_num_rows($result) > 0) { $s = new piaSource(); echo '<h2>Sources</h2>'; $tableId = 'SourcesTable'; $piaApp->initTablesorterTable($tableId); piaApp::startTable($tableId, 'tablesorter', False, 'width:70%;'); piaApp::writeTableHeader(array(array('Name', '35%'), array('Description', '35%'), array('Num Items', '15%'), array('Size (bytes)', '15%'))); echo '<tbody>'; // // ----- loop through the results // while ($row = pg_fetch_array($result)) { $cur = $s->readRowFromDatabase($row); $num_items = piaDB::cleanDataRead($row[$cur++]); $size_bytes = piaDB::cleanDataRead($row[$cur++]); echo '<tr>'; piaApp::writeTableData($s->name); piaApp::writeTableData($s->description); piaApp::writeTableData(piaApp::getFormattedNumber($num_items, 0, -9)); piaApp::writeTableData(piaApp::getFormattedNumber($size_bytes, 0, -9)); echo '</tr>'; } echo '</tbody></table><p />'; } pg_free_result($result); piaDB::close($db); } }
OTHER DEALINGS IN THE SOFTWARE. */ require_once 'classes/piaApp.php'; $piaApp = new piaApp(); $piaApp->startPage('PiArchive Statistics'); $piaApp->addTableSorter(); $piaApp->showHeader('PiArchive Statistics'); $piaApp->addMenu('stats.php'); # # ----- database version # $version = piaDB::getScalarString('SELECT * FROM pia_version()', array()); echo 'Database version: ', $version, '<p />'; # # ----- total number of items # $num_sources = piaDB::getScalarInteger('SELECT count(rowid) FROM pia.source', array()); echo $num_sources, ' source(s)<p />'; $num_indexed_items = piaDB::getScalarInteger('SELECT count(rowid) FROM pia.index', array()); echo piaApp::getFormattedNumber($num_indexed_items, 0, -9), ' indexed item(s)<p />'; $size_bytes = piaDB::getScalarFloat('SELECT sum(size_bytes) FROM pia.index', array()); echo 'Total size of indexed items: ', piaApp::getFormattedNumber($size_bytes, 0, -9), ' (bytes)<p />'; # # ----- show sources in a table # piaSource::reportSources(); # # ----- footer and close page # $piaApp->showFooter(); $piaApp->closePage();
/** * Get a value from the metadata table core.metadata. * @param string $name Name of the value to get. * @return The metadata value if it exists, a blank string otherwise. */ public static function getMetadataValue($name) { return piaDB::getScalarString('SELECT val FROM core.metadata WHERE name = $1', array($name)); }