diff --git a/html/shd/common.php b/html/shd/common.php
index 240ad08..7056bea 100644
--- a/html/shd/common.php
+++ b/html/shd/common.php
@@ -19,6 +19,38 @@
}
/**
+ * Format a 2D array into a 1D array of strings suitable for output in a
+ * readable style.
+ */
+function format_array_2d( $arr ){
+
+ //get the maximum field widths for all rows
+ $arr_col_mxw = array();
+ foreach($arr as $row){
+ $i=0;
+ foreach($row as $field){
+ if( strlen($field)>$arr_col_mxw[$i]){
+ $arr_col_mxw[$i] = strlen($field);
+ }
+ $i++;
+ }
+ }
+
+ $arr_rtn = array();
+ foreach($arr as $row){
+ $str_row = '|';
+ $i=0;
+ foreach($row as $field){
+ $str_row .= str_pad($field, $arr_col_mxw[$i]) ." | ";
+ $i++;
+ }
+ array_push($arr_rtn, $str_row);
+ }
+ return $arr_rtn;
+
+}
+
+/**
* e.g. split
* ../db/stanhopetest/img/img_52548
* into
@@ -93,93 +125,10 @@
return $rtn;
}
-/**
- * Set the given key-value pair.
- *
- * Returns the record ID.
- */
-function params_set( $key, $val ) {
-
- $rec = R::findOne( 'params', 'pkey=?', [$key] );
- if($rec) {
- $rec->pval = $val;
- R::store( $rec );
- return $rec->id;
- }
-
- $rec = R::dispense( 'params' );
- $rec->pkey = $key;
- $rec->pval = $val;
- return R::store( $rec );
-}
-
function params_get_date( $key ){
return strtotime( params_get($key) );
}
-/**
- * Returns the value for the given key. Returns null if no such key exists.
- */
-function params_get( $key ){
-
- $rec = R::findOne( 'params', 'pkey=?', [$key] );
- if(!$rec) return null;
- return $rec->pval;
-}
-
-/**
- * A novel way of creating a unique ID each time a call is made. The new ID is
- * returned.
- *
- * e.g.
- * This can be used to give a client which might want to create temporary unique IDs. It is
- * called once per client refresh and used to ensure uniqueness of certain CSS data points.
- */
-function params_unique( ) {
-
- $rec = R::dispense( 'params' );
- $rec->pkey = 'unique';
- $id = R::store( $rec );
- R::exec( "delete from params where id<$id and pkey='unique'" );
- return $id;
-}
-
-/**
- * Return a string representation for the given dom node suitable for debugging.
- */
-function getNodeString( $rmElem ){
-
- if($rmElem==null) return "Element is null";
- $str="";
- if( $rmElem->nodeType==XML_ELEMENT_NODE){
- $str .= $rmElem->nodeName;
- $a = $rmElem->getAttribute("shb_compid");
- if($a){
- $str .= " shb_compid=$a";
- }
- }else{
- $str .= 'type = '.$rmElem->nodeType;
- }
- return $str;
-}
-
-/**
- * Simple logger to write to a file. Using php error_log distorts all crlf pairs. This
- * is a pain when you're trying to preserve them in html.
- */
-function mylog( $msg ){
-
- global $logging_on;
-
- if(!$logging_on) return;
- $p = __DIR__ . "/../../shb.log";
- $h = fopen( $p, "a");
- if($h===false) return;
- fwrite( $h, "$msg\n");
- fclose($h);
-
-}
-
function generateNonce( $digitCount = 12 ){
// e.g. 422466a05f24b09c978fa1f6
return bin2hex( random_bytes($digitCount) );
@@ -214,7 +163,6 @@
return $str;
}
-
/**
* Remove all html from the given string returning just the text content.
*/
@@ -259,94 +207,4 @@
return "$name = \"$prefPath/$path\"";
}
-global $g_pub_path;
-
-/**
- * If the browser=true, the file returned will be correct for adding to an href or src attribute so that the
- * browser will find the link.
- */
-function getDirForType( $filetype='html', $browser=false, $userid=-1 ){
-
- global $g_pub_path;
-
- if($g_pub_path==null){
- $g_pub_path = params_get('pub_path');
- if($g_pub_path==null){
- throw new Exception("Publishing now requires a valid key('pub_path') in the params table for the publishing output path");
- }
-
- if(str_ends_with( $g_pub_path, '/') ) $g_pub_path = substr($g_pub_path, 0, strlen($g_pub_path)-1 );
-
- //ensure all the directories exist
- createUserDir( 'img', $userid );
- createUserDir( 'css', $userid );
- createUserDir( 'html', $userid );
- createUserDir( 'js', $userid );
-
- }
-
- return getDirForType_( $filetype, $browser, $userid );
-
-}
-
-function createUserDir( $dName, $userid ){
-
- if(!file_exists(getDirForType_( $dName, false, $userid ))) {
- $dir = getDirForType_( $dName, false, $userid );
- error_log("common.php: createUserDir: $dir");
- mkdir( $dir, 0770, true);
- }
-}
-
-/**
- * Part of the new path handling system is to sepatate out path names from real files
-*/
-function mkdirIfNotExists( $d ){
- if(!file_exists( $d ) ) {
- error_log("common.php: createUserDir: $d");
- mkdir( $d, 0770, true );
- }
-}
-
-/**
- * For the moment, call getDirForType and not this function. In time, the setup routine will make the directories
- * and eliminate the need for the check during a user session.
- *
- * If the browser flag is set, we assuming a document root sub-dir. But in time, this will need to also cater for
- * a site serving the g_pub_path as root (wrt the browser).
- *
- */
-function getDirForType_( $filetype, $browser, $userid ){
-
- global $g_pub_path;
- $strPath = $g_pub_path;
-
-
- if($userid>0){
- $strPath .= "_dbg_$userid";
- }
-
- switch($filetype){
-
- case 'img':
- if($browser) return "/$strPath/img/";
- return fxdPth( "$strPath/img/" );
-
- case 'js':
- if($browser) return "/$strPath/js/";
- return fxdPth( "$strPath/js/" );
-
- case 'css':
- if($browser) return "/$strPath/css/";
- return fxdPth( "$strPath/css/" );
-
- case 'html':
- default:
- if($browser) return "/$strPath/";
- return fxdPth( "$strPath/" );
-
- }
-}
-
-
-//NO white-space
+?>
diff --git a/html/svc/db-reads.php b/html/svc/db-reads.php
index e620cd1..402a800 100644
--- a/html/svc/db-reads.php
+++ b/html/svc/db-reads.php
@@ -1,10 +1,12 @@
$debug_level) return;
- file_put_contents( __DIR__."/../data/rpc_op.log", $msg, FILE_APPEND);
+ log_print( $msg );
}
function debug_println( $msg, $dl=0 ){
@@ -22,6 +32,9 @@
//$argv[0] is always the name that was used to run the script.
if(count($argv)>1){
+ //do not output to service log file
+ $log_print_file=null;
+
include __DIR__."/main-svc.php";
if($argv[1]==='stop'){
@@ -416,6 +429,7 @@
global $g_data_dir;
global $g_shutdown;
global $debug_level;
+
if( 'f:getbu_list_state' !== $obj[0] ){
//print_r( $obj );
@@ -498,6 +512,12 @@
ensure_cached_table();
return array('ok:reload');
+ case 'f:cache-show':
+ foreach( format_cache() as $line){
+ log_print( "$line\n" );
+ }
+ return array('ok:cache-show');
+
case 'f:cli-stop':
$g_shutdown = true;
return array('ok:shutdown');
diff --git a/html/svc/table-cache.php b/html/svc/table-cache.php
index 2751823..8ad655c 100644
--- a/html/svc/table-cache.php
+++ b/html/svc/table-cache.php
@@ -1,10 +1,35 @@