diff --git a/www/admin/class_test.debug.php b/www/admin/class_test.debug.php index 7571552c..624cc86e 100644 --- a/www/admin/class_test.debug.php +++ b/www/admin/class_test.debug.php @@ -52,6 +52,9 @@ print "S::GETCALLERMETHOD: ".DebugSupport::getCallerMethod(0)."
"; print "S::GETCALLERMETHOD: ".test()."
"; print "S::PRINTAR: ".DebugSupport::printAr(['Foo', 'Bar'])."
"; print "V-S::PRINTAR: ".$debug_support_class::printAr(['Foo', 'Bar'])."
"; +print "S::DEBUSTRING(s): ".DebugSupport::debugString('SET')."
"; +print "S::DEBUSTRING(''): ".DebugSupport::debugString('')."
"; +print "S::DEBUSTRING(,s): ".DebugSupport::debugString(null, '{-}')."
"; // debug print "C->DEBUG: ".$debug->debug('CLASS-TEST-DEBUG', 'Class Test Debug')."
"; diff --git a/www/admin/class_test.output.form.php b/www/admin/class_test.output.form.php index f90455f2..3646e90f 100644 --- a/www/admin/class_test.output.form.php +++ b/www/admin/class_test.output.form.php @@ -29,6 +29,31 @@ if (!defined('SET_SESSION_NAME')) { $LOG_FILE_ID = 'classTest-form'; ob_end_flush(); +// define an array for page use +$table_arrays[\CoreLibs\Get\System::getPageName(1)] = [ + // form fields mtaching up with db fields + 'table_array' => [ + ], + // laod query + 'load_query' => '', + // database table to load from + 'table_name' => '', + // for load dro pdown, format output + 'show_fields' => [ + [ + 'name' => 'name' + ], + [ + 'name' => 'enabled', + 'binary' => ['Yes', 'No'], + 'before_value' => 'Enabled: ' + ], + ], + // a multi reference entry + 'element_list' => [ + ] +]; + $basic = new CoreLibs\Basic(); $form = new CoreLibs\Output\Form\Generate(DB_CONFIG); // $db = new CoreLibs\DB\IO(DB_CONFIG, $basic->log); @@ -37,7 +62,8 @@ print "TEST CLASS: FORM GENERATE"; print ""; print '
Class Test Master
'; -print "TODO
"; +print "MOBILE PHONE: ".$form->mobile_phone."
"; +print "MY PAGE NAME: ".$form->my_page_name."
"; // sets table array to include // error message print $basic->log->printErrorMsg(); diff --git a/www/admin/class_test.system.php b/www/admin/class_test.system.php index 7d3ae39f..597b7826 100644 --- a/www/admin/class_test.system.php +++ b/www/admin/class_test.system.php @@ -1,4 +1,5 @@ -"; print "GETPAGENAME(0): ".System::getPageName()."
"; print "GETPAGENAME(1): ".System::getPageName(1)."
"; print "GETPAGENAME(2): ".System::getPageName(2)."
"; +print "GETPAGENAMEARRAY: ".\CoreLibs\Debug\Support::printAr(System::getPageNameArray())."
"; // seting errro codes file upload print "FILEUPLOADERRORMESSAGE(): ".System::fileUploadErrorMessage(-1)."
"; print "FILEUPLOADERRORMESSAGE(UPLOAD_ERR_CANT_WRITE): ".System::fileUploadErrorMessage(UPLOAD_ERR_CANT_WRITE)."
"; diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index fa492268..d916c8dd 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -920,7 +920,7 @@ class IO extends \CoreLibs\Basic $max_calls > 0 ) { $this->MAX_QUERY_CALL = $max_calls; - $succes = true; + $success = true; } return $success; } diff --git a/www/lib/CoreLibs/Debug/Logging.php b/www/lib/CoreLibs/Debug/Logging.php index 14eee29d..68295e85 100644 --- a/www/lib/CoreLibs/Debug/Logging.php +++ b/www/lib/CoreLibs/Debug/Logging.php @@ -433,7 +433,7 @@ class Logging */ public function prAr(array $a): string { - return '{##HTMLPRE##}'.print_r($a, true).'{##/HTMLPRE##}'; + return '##HTMLPRE##'.print_r($a, true).'##/HTMLPRE##'; } /** @@ -468,9 +468,9 @@ class Logging .'{'.$class.'} ' .'<'.$level.'> - ' // strip the htmlpre special tags if exist - .preg_replace( - "/{##HTMLPRE##}((.|\n)*?){##\/HTMLPRE##}/m", - '\\1', + .str_replace( + ['##HTMLPRE##', '##/HTMLPRE##'], + '', // if stripping all html, etc is requested, only for write error msg ($strip ? // find any
and replace them with \n @@ -498,7 +498,11 @@ class Logging // as is prefix, allow HTML .$prefix // we replace special HTMLPRE with
 entries
-				.preg_replace("/{##HTMLPRE##}((.|\n)*?){##\/HTMLPRE##}/m", "
\\1
", \CoreLibs\Convert\Html::htmlent($string)) + .str_replace( + ['##HTMLPRE##', '##/HTMLPRE##'], + ['
', '
'], + \CoreLibs\Convert\Html::htmlent($string) + ) .""; } return true; diff --git a/www/lib/CoreLibs/Debug/Support.php b/www/lib/CoreLibs/Debug/Support.php index 358bccd3..e77fc5c3 100644 --- a/www/lib/CoreLibs/Debug/Support.php +++ b/www/lib/CoreLibs/Debug/Support.php @@ -78,6 +78,21 @@ class Support } return $class ?? ''; } + + /** + * If a string is empty, sets '-' for return, or if given any other string + * + * @param string|null $string The string to check + * @param string $replace [default '-'] What to replace the empty string with + * @return string String itself or the replaced value + */ + public static function debugString(?string $string, string $replace = '-'): string + { + if (empty($string)) { + return $replace; + } + return $string; + } } // __END__ diff --git a/www/lib/CoreLibs/Get/System.php b/www/lib/CoreLibs/Get/System.php index a7450afa..283cbc10 100644 --- a/www/lib/CoreLibs/Get/System.php +++ b/www/lib/CoreLibs/Get/System.php @@ -80,6 +80,16 @@ class System return $page_temp['basename']; } } + + /** + * similar to getPageName, but it retuns the raw array + * + * @return array pathinfo array from PHP SELF + */ + public static function getPageNameArray(): array + { + return pathinfo($_SERVER['PHP_SELF']); + } } // __END__ diff --git a/www/lib/CoreLibs/Output/Form/Generate.php b/www/lib/CoreLibs/Output/Form/Generate.php index d7444aea..0bdefea9 100644 --- a/www/lib/CoreLibs/Output/Form/Generate.php +++ b/www/lib/CoreLibs/Output/Form/Generate.php @@ -260,31 +260,45 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO */ public function __construct(array $db_config, int $table_width = 750) { - $this->my_page_name = \CoreLibs\Get\System::getPageName(1); + // replace any non valid variable names + $this->my_page_name = str_replace(['.'], '_', \CoreLibs\Get\System::getPageName(1)); $this->setLangEncoding(); // init the language class $this->l = new \CoreLibs\Language\L10n($this->lang); // load config array // get table array definitions for current page name - // WARNING: auto spl load does not work with this as it is an array and not a function/object - // check if this is the old path or the new path - if (is_dir(TABLE_ARRAYS)) { - if (is_file(TABLE_ARRAYS.'array_'.$this->my_page_name.'.php')) { - include(TABLE_ARRAYS.'array_'.$this->my_page_name.'.php'); - } + + // first check if we have a in page override as $table_arrays[page name] + if (isset($_GLOBALS['table_arrays']) && + is_array($_GLOBALS['table_arrays']) && + isset($_GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]) && + is_array($_GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]) + ) { + $config_array = $_GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]; } else { - if (is_file(BASE.INCLUDES.TABLE_ARRAYS.'array_'.$this->my_page_name.'.php')) { + // WARNING: auto spl load does not work with this as it is an array and not a function/object + // check if this is the old path or the new path + // check local folder in current path + // then check general global folder + if (is_dir(TABLE_ARRAYS) && + is_file(TABLE_ARRAYS.'array_'.$this->my_page_name.'.php') + ) { + include(TABLE_ARRAYS.'array_'.$this->my_page_name.'.php'); + } elseif (is_dir(BASE.INCLUDES.TABLE_ARRAYS) && + is_file(BASE.INCLUDES.TABLE_ARRAYS.'array_'.$this->my_page_name.'.php') + ) { include(BASE.INCLUDES.TABLE_ARRAYS.'array_'.$this->my_page_name.'.php'); } - } - if (isset(${$this->my_page_name}) && is_array(${$this->my_page_name})) { - $config_array = ${$this->my_page_name}; - } else { - // dummy created - $config_array = [ - 'table_array' => [], - 'table_name' => '', - ]; + // in the include file there must be a variable with the page name matching + if (isset(${$this->my_page_name}) && is_array(${$this->my_page_name})) { + $config_array = ${$this->my_page_name}; + } else { + // dummy created + $config_array = [ + 'table_array' => [], + 'table_name' => '', + ]; + } } // start the array_io class which will start db_io ...