From 9086196f7d4972b0076cb6b76c7f5552c677f394 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Fri, 23 Mar 2018 19:10:58 +0900 Subject: [PATCH] Base transfer to namespace complete All libraries have been transformed to namespace layout --- 4dev/sync/sync_template.sh | 4 +- .../20180322_db_interface}/TRAIT_db_pgsql.inc | 0 .../20180322_db_interface}/db_pgsql_pdo.inc | 0 4dev/update/20180323_namespace/comp_func.sh | 38 +- www/admin/edit_base.inc | 165 ++- www/admin/edit_order.php | 367 +++--- www/admin/namespace_test.php | 13 +- www/lib/CoreLibs/ACL/Login.inc | 177 +-- www/lib/CoreLibs/Admin/Backend.inc | 37 +- www/lib/CoreLibs/Basic.inc | 1050 ++++++++-------- www/lib/CoreLibs/DB/Extended/ArrayIO.inc | 228 ++-- www/lib/CoreLibs/DB/IO.inc | 1066 +++++++++++------ www/lib/CoreLibs/DB/SQL/PgSQL.inc | 143 ++- .../Language/Core/CachedFileReader.inc | 48 + www/lib/CoreLibs/Language/Core/FileReader.inc | 20 + .../CoreLibs/Language/Core/StreamReader.inc | 54 + .../CoreLibs/Language/Core/StringReader.inc | 67 ++ www/lib/CoreLibs/Language/Core/streams.php | 182 --- .../CoreLibs/Language/{l10.inc => L10n.inc} | 26 +- www/lib/CoreLibs/Output/Form/Generate.inc | 360 +++--- www/lib/CoreLibs/Output/Progressbar.inc | 58 +- www/lib/CoreLibs/Template/SmartyExtend.Inc | 17 +- 22 files changed, 2262 insertions(+), 1858 deletions(-) rename {www/lib/CoreLibs/DB/SQL => 4dev/update/20180322_db_interface}/TRAIT_db_pgsql.inc (100%) rename {www/lib/CoreLibs/DB/SQL => 4dev/update/20180322_db_interface}/db_pgsql_pdo.inc (100%) create mode 100755 www/lib/CoreLibs/Language/Core/CachedFileReader.inc create mode 100755 www/lib/CoreLibs/Language/Core/StreamReader.inc create mode 100755 www/lib/CoreLibs/Language/Core/StringReader.inc delete mode 100644 www/lib/CoreLibs/Language/Core/streams.php rename www/lib/CoreLibs/Language/{l10.inc => L10n.inc} (81%) diff --git a/4dev/sync/sync_template.sh b/4dev/sync/sync_template.sh index 0650adea..c48dbde3 100755 --- a/4dev/sync/sync_template.sh +++ b/4dev/sync/sync_template.sh @@ -1,12 +1,12 @@ #!/bin/bash # create path -path=`pwd`"/"$0; +path=$(pwd)"/"$0; LOCAL_BASE_DIR=""; LOCAL_DIR=$LOCAL_BASE_DIR""; REMOTE_WEB=""; -TARGET_HOST_WEB="@ +TARGET_HOST_WEB="@"; TMP_DIR=$LOCAL_BASE_DIR"/4dev/"; tmpf_web=$TMP_DIR"tmp.web"; diff --git a/www/lib/CoreLibs/DB/SQL/TRAIT_db_pgsql.inc b/4dev/update/20180322_db_interface/TRAIT_db_pgsql.inc similarity index 100% rename from www/lib/CoreLibs/DB/SQL/TRAIT_db_pgsql.inc rename to 4dev/update/20180322_db_interface/TRAIT_db_pgsql.inc diff --git a/www/lib/CoreLibs/DB/SQL/db_pgsql_pdo.inc b/4dev/update/20180322_db_interface/db_pgsql_pdo.inc similarity index 100% rename from www/lib/CoreLibs/DB/SQL/db_pgsql_pdo.inc rename to 4dev/update/20180322_db_interface/db_pgsql_pdo.inc diff --git a/4dev/update/20180323_namespace/comp_func.sh b/4dev/update/20180323_namespace/comp_func.sh index 463a8d9e..bd3f96f4 100755 --- a/4dev/update/20180323_namespace/comp_func.sh +++ b/4dev/update/20180323_namespace/comp_func.sh @@ -1,13 +1,21 @@ #!/bin/bash OIFS=${IFS}; -class_file="Class.Basic.inc"; -tmp_file="../../4dev/tmp/tmp.comp"; +base_dir="/home/clemens/html/developers/clemens/core_data/php_libraries/trunk/"; +class_file="CoreLibs/Output/Form/Generate.inc"; +tmp_file=${base_dir}"4dev/tmp/tmp.comp."$(echo "${class_file}" | tr \/. _); +rpl_file=${base_dir}"4dev/tmp/tmp.rpl."$(echo "${class_file}" | tr \/. _); rm -f "${tmp_file}"; -cat "${class_file}" | grep "WAS" -B 1 | while read line; +rm -f "${rpl_file}"; +if [ ! -f ${class_file} ]; +then + echo "Cannot find ${class_file} in current folder: $(pwd)"; + exit; +fi; +cat "${class_file}" | grep "WAS :" -B 1 | while read line; do # if method grep for function call - found=$(echo "${line}" | sed -e 's/^[ \t]*//' | grep "METHOD"); + found=$(echo "${line}" | sed -e 's/^[ \t]*//' | grep "METHOD:"); if [ -n "${found}" ]; then method=$(echo "${line}" | cut -d " " -f 3); @@ -16,7 +24,7 @@ do if [ -n "${method}" ]; then # the full new call - new_function_call_full=$(grep "${method}(" Class.Basic.inc | grep "function" | sed -e 's/^[ \t]*//'); + new_function_call_full=$(grep "function ${method}(" "${class_file}" | grep "function" | sed -e 's/^[ \t]*//'); # just the method name new_function_call=$(echo "${new_function_call_full}" | sed -e 's/public //' | sed -e 's/private //' | sed -e 's/static //' | sed -e 's/function //' | cut -d "(" -f 1); # check if func call is more than just alphanumeric (we don't need to redeclare those, functions are case insenstivie) @@ -37,26 +45,28 @@ do fi; fi; # if this is a WAS - was=$(echo "${line}" | sed -e 's/^[ \t]*//' | grep "WAS" | tr -s " "); + was=$(echo "${line}" | sed -e 's/^[ \t]*//' | grep "WAS :" | tr -s " "); if [ -n "${was}" ]; then - old_function_call=$(echo "${was}" | cut -d " " -f 3) + old_function_call=$(echo "${was}" | cut -d " " -f 4) echo "2 OLD: ${old_function_call} => ${new_function_call} [${new_function_call_full}]"; # for return write: # rpl new -> old { new } rpl=$(echo "${new_function_call_full}" | sed -e "s/${new_function_call}/${old_function_call}/"); new_call="${rpl}\n"; new_call=${new_call}"{\n"; - new_call=${new_call}"\t\$this->debug('DEPRECATED CALL', __FUNCTION);\n"; - new_call=${new_call}"\t\$this->${new_function_call}(${old_function_call_params});\n"; + new_call=${new_call}"\terror_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);\n"; + new_call=${new_call}"\treturn \$this->${new_function_call}(${old_function_call_params});\n"; new_call=${new_call}"}\n"; echo -e "${new_call}" >> "${tmp_file}"; echo "3A RPL CALL: ${rpl}"; - echo "3B RPL CALL: {"; - echo "3B RPL CALL: \$this->debug('DEPRECATED CALL', __FUNCTION);"; - echo "3B RPL CALL: ${new_function_call}(${old_function_call_params});"; - echo "3B RPL CALL: }"; + echo "3B RPL CALL: return \$this->${new_function_call}(${old_function_call_params});"; + echo "4 SWT RPL : rpl '\$this->${old_function_call}' '\$this->${new_function_call}'"; + # write the replace calls for old $this->old_call to $this->new_call + echo "rpl '\$this->${old_function_call}' '\$this->${new_function_call}' ##TARGET_FILE##" >> "${rpl_file}"; echo "----"; fi; done; -IFS=${OIFS}; \ No newline at end of file +IFS=${OIFS}; + +# __END__ diff --git a/www/admin/edit_base.inc b/www/admin/edit_base.inc index 62ee3d32..25fe6c8c 100644 --- a/www/admin/edit_base.inc +++ b/www/admin/edit_base.inc @@ -28,22 +28,15 @@ define(REL_PATH, ''); ob_start(); include("config.inc"); +// set session name here +define('SET_SESSION_NAME', EDIT_SESSION_NAME); // overrride debug flags if (!DEBUG) { $DEBUG_ALL = 0; $PRINT_ALL = 0; $DB_DEBUG = 0; $ECHO_ALL = 0; -// $DEBUG_TMPL = 0; } -// set session name here -define('SET_SESSION_NAME', EDIT_SESSION_NAME); -// login class -require(LIBS."Class.Login.inc"); -// form generate for edit interface -require(LIBS."Class.Form.Generate.inc"); -// Smarty: and the small extend for l10n calls -require(LIBS.'Class.Smarty.Extend.inc'); // set default lang if not set otherwise if (!$lang) { @@ -52,17 +45,17 @@ if (!$lang) { // should be utf8 header("Content-type: text/html; charset=".DEFAULT_ENCODING); ob_end_flush(); -$login = new login($DB_CONFIG[LOGIN_DB], $lang); +$login = new CoreLibs\ACL\Login($DB_CONFIG[LOGIN_DB], $lang); // create form class -$form = new form($DB_CONFIG[MAIN_DB], $lang); +$form = new CoreLibs\Output\Form\Generate($DB_CONFIG[MAIN_DB], $lang); $form->db_exec("SET search_path TO ".LOGIN_DB_SCHEMA); if ($form->mobile_phone) { echo "I am sorry, but this page cannot be viewed by a mobile phone"; exit; } // smarty template engine (extended Translation version) -$smarty = new SmartyML($lang); +$smarty = new CoreLibs\Template\SmartyExtend($lang); if (TARGET == 'live' || TARGET == 'remote') { // login @@ -98,7 +91,7 @@ function EditLog($event = '', $data = '') { $q = "INSERT INTO edit_log "; $q .= "(euid, event_date, ip, event, data, page) "; - $q .= "VALUES (".$_SESSION['EUID'].", NOW(), '".$_SERVER["REMOTE_ADDR"]."', '".$GLOBALS['form']->db_escape_string($event)."', '".$GLOBALS['form']->db_escape_string($data)."', '".$GLOBALS['form']->get_page_name()."')"; + $q .= "VALUES (".$_SESSION['EUID'].", NOW(), '".$_SERVER["REMOTE_ADDR"]."', '".$GLOBALS['form']->dbEscapeString($event)."', '".$GLOBALS['form']->dbEscapeString($data)."', '".$GLOBALS['form']->getPageName()."')"; } // log backend data @@ -112,11 +105,11 @@ $data = array ( // log action EditLog('Edit Submit', serialize($data)); -$form->form_procedure_load(${$form->archive_pk_name}); -$form->form_procedure_new(); -$form->form_procedure_save(); -$form->form_procedure_delete(); -$form->form_procedure_delete_from_element_list($element_list, $remove_name); +$form->formProcedureLoad(${$form->archive_pk_name}); +$form->formProcedureNew(); +$form->formProcedureSave(); +$form->formProcedureDelete(); +$form->formProcedureDeleteFromElementList($element_list, $remove_name); // define all needed smarty stuff for the general HTML/page building $HEADER['CSS'] = CSS; @@ -128,7 +121,7 @@ $HEADER['JAVASCRIPT'] = $EDIT_JAVASCRIPT; $DATA['table_width'] = $table_width; // write out error / status messages -$messages[] = $form->form_error_msg(); +$messages[] = $form->formErrorMsg(); $DATA['form_error_msg'] = $messages; // MENU START @@ -172,7 +165,7 @@ for ($i = 1; $i <= count($menuarray); $i ++) { if ($i == 1 || !(($i - 1) % $SPLIT_FACTOR)) { $menu_data[$j]['splitfactor_in'] = 1; } - if ($menuarray[($i - 1)]["filename"] == $form->get_page_name()) { + if ($menuarray[($i - 1)]["filename"] == $form->getPageName()) { $position = $i - 1; $menu_data[$j]['position'] = 1; } else { @@ -197,42 +190,42 @@ $L_TITLE = $DATA['page_name']; $HEADER['HTML_TITLE'] = ((!$L_TITLE) ? $form->l->__($G_TITLE) : $form->l->__($L_TITLE)); // END MENU // LOAD AND NEW -$DATA['load'] = $form->form_create_load(); -$DATA['new'] = $form->form_create_new(); +$DATA['load'] = $form->formCreateLoad(); +$DATA['new'] = $form->formCreateNew(); // SHOW DATA PART if ($form->yes) { $DATA['form_yes'] = $form->yes; $DATA['form_my_page_name'] = $form->my_page_name; - // depending on the "get_page_name()" I show different stuff + // depending on the "getPageName()" I show different stuff switch ($form->my_page_name) { case "edit_users": - $elements[] = $form->form_create_element("login_error_count"); - $elements[] = $form->form_create_element("login_error_date_last"); - $elements[] = $form->form_create_element("login_error_date_first"); - $elements[] = $form->form_create_element("enabled"); - $elements[] = $form->form_create_element("username"); - $elements[] = $form->form_create_element("password"); - $elements[] = $form->form_create_element("password_change_interval"); - $elements[] = $form->form_create_element("email"); - $elements[] = $form->form_create_element("last_name"); - $elements[] = $form->form_create_element("first_name"); - $elements[] = $form->form_create_element("edit_group_id"); - $elements[] = $form->form_create_element("edit_access_right_id"); - $elements[] = $form->form_create_element("strict"); - $elements[] = $form->form_create_element("locked"); - $elements[] = $form->form_create_element("admin"); - $elements[] = $form->form_create_element("debug"); - $elements[] = $form->form_create_element("db_debug"); - $elements[] = $form->form_create_element("edit_language_id"); - $elements[] = $form->form_create_element("edit_scheme_id"); - $elements[] = $form->form_show_list_table("edit_access_user"); + $elements[] = $form->formCreateElement("login_error_count"); + $elements[] = $form->formCreateElement("login_error_date_last"); + $elements[] = $form->formCreateElement("login_error_date_first"); + $elements[] = $form->formCreateElement("enabled"); + $elements[] = $form->formCreateElement("username"); + $elements[] = $form->formCreateElement("password"); + $elements[] = $form->formCreateElement("password_change_interval"); + $elements[] = $form->formCreateElement("email"); + $elements[] = $form->formCreateElement("last_name"); + $elements[] = $form->formCreateElement("first_name"); + $elements[] = $form->formCreateElement("edit_group_id"); + $elements[] = $form->formCreateElement("edit_access_right_id"); + $elements[] = $form->formCreateElement("strict"); + $elements[] = $form->formCreateElement("locked"); + $elements[] = $form->formCreateElement("admin"); + $elements[] = $form->formCreateElement("debug"); + $elements[] = $form->formCreateElement("db_debug"); + $elements[] = $form->formCreateElement("edit_language_id"); + $elements[] = $form->formCreateElement("edit_scheme_id"); + $elements[] = $form->formShowListTable("edit_access_user"); break; case "edit_schemes": - $elements[] = $form->form_create_element("enabled"); - $elements[] = $form->form_create_element("name"); - $elements[] = $form->form_create_element("header_color"); - $elements[] = $form->form_create_element("template"); + $elements[] = $form->formCreateElement("enabled"); + $elements[] = $form->formCreateElement("name"); + $elements[] = $form->formCreateElement("header_color"); + $elements[] = $form->formCreateElement("template"); break; case "edit_pages": if (!$form->table_array["edit_page_id"]["value"]) { @@ -243,57 +236,57 @@ if ($form->yes) { // now get all that are NOT in de DB $q = "INSERT INTO temp_files VALUES "; for ($i = 0; $i < count($output); $i ++) { - $t_q = "('".$form->db_escape_string($output[$i])."')"; - $form->db_exec($q.$t_q, 'NULL'); + $t_q = "('".$form->dbEscapeString($output[$i])."')"; + $form->dbExec($q.$t_q, 'NULL'); } - $elements[] = $form->form_create_element("filename"); + $elements[] = $form->formCreateElement("filename"); } else { // show file menu // just show name of file ... $DATA['filename_exist'] = 1; $DATA['filename'] = $form->table_array["filename"]["value"]; } // File Name View IF - $elements[] = $form->form_create_element("name"); - // $elements[] = $form->form_create_element("tag"); - // $elements[] = $form->form_create_element("min_acl"); - $elements[] = $form->form_create_element("order_number"); - $elements[] = $form->form_create_element("online"); - $elements[] = $form->form_create_element("menu"); - $elements[] = $form->form_show_list_table("edit_query_string"); - $elements[] = $form->form_create_element("popup"); - $elements[] = $form->form_create_element("popup_x"); - $elements[] = $form->form_create_element("popup_y"); - $elements[] = $form->form_show_reference_table("edit_visible_group"); - $elements[] = $form->form_show_reference_table("edit_menu_group"); + $elements[] = $form->formCreateElement("name"); + // $elements[] = $form->formCreateElement("tag"); + // $elements[] = $form->formCreateElement("min_acl"); + $elements[] = $form->formCreateElement("order_number"); + $elements[] = $form->formCreateElement("online"); + $elements[] = $form->formCreateElement("menu"); + $elements[] = $form->formShowListTable("edit_query_string"); + $elements[] = $form->formCreateElement("popup"); + $elements[] = $form->formCreateElement("popup_x"); + $elements[] = $form->formCreateElement("popup_y"); + $elements[] = $form->formShowReferenceTable("edit_visible_group"); + $elements[] = $form->formShowReferenceTable("edit_menu_group"); break; case "edit_languages": - $elements[] = $form->form_create_element("enabled"); - $elements[] = $form->form_create_element("short_name"); - $elements[] = $form->form_create_element("long_name"); - $elements[] = $form->form_create_element("iso_name"); + $elements[] = $form->formCreateElement("enabled"); + $elements[] = $form->formCreateElement("short_name"); + $elements[] = $form->formCreateElement("long_name"); + $elements[] = $form->formCreateElement("iso_name"); break; case "edit_groups": - $elements[] = $form->form_create_element("enabled"); - $elements[] = $form->form_create_element("name"); - $elements[] = $form->form_create_element("edit_access_right_id"); - $elements[] = $form->form_create_element("edit_scheme_id"); - $elements[] = $form->form_show_list_table("edit_page_access"); + $elements[] = $form->formCreateElement("enabled"); + $elements[] = $form->formCreateElement("name"); + $elements[] = $form->formCreateElement("edit_access_right_id"); + $elements[] = $form->formCreateElement("edit_scheme_id"); + $elements[] = $form->formShowListTable("edit_page_access"); break; case "edit_visible_group": - $elements[] = $form->form_create_element("name"); - $elements[] = $form->form_create_element("flag"); + $elements[] = $form->formCreateElement("name"); + $elements[] = $form->formCreateElement("flag"); break; case "edit_menu_group": - $elements[] = $form->form_create_element("name"); - $elements[] = $form->form_create_element("flag"); - $elements[] = $form->form_create_element("order_number"); + $elements[] = $form->formCreateElement("name"); + $elements[] = $form->formCreateElement("flag"); + $elements[] = $form->formCreateElement("order_number"); break; case "edit_access": - $elements[] = $form->form_create_element("name"); - $elements[] = $form->form_create_element("color"); - $elements[] = $form->form_create_element("description"); + $elements[] = $form->formCreateElement("name"); + $elements[] = $form->formCreateElement("color"); + $elements[] = $form->formCreateElement("description"); // add name/value list here - $elements[] = $form->form_show_list_table("edit_access_data"); + $elements[] = $form->formShowListTable("edit_access_data"); break; default: print "[No valid page definition given]"; @@ -301,8 +294,8 @@ if ($form->yes) { } // $form->debug('edit', "Elements:
".$form->print_ar($elements));
 	$DATA['elements'] = $elements;
-	$DATA['hidden'] = $form->form_create_hidden_fields();
-	$DATA['save_delete'] = $form->form_create_save_delete();
+	$DATA['hidden'] = $form->formCreateHiddenFields();
+	$DATA['save_delete'] = $form->formCreateSaveDelete();
 }
 
 // debug data, if DEBUG flag is on, this data is print out
@@ -315,10 +308,10 @@ while (list($key, $value) = each($CONTENT_DATA)) {
 	$smarty->assign($key, $value);
 }
 
-//	$smarty->assign('popup_page', 'mt_popup_'.$body_part.'.tpl');
-
 $smarty->display('edit_body.tpl');
 
 // debug output
-echo $login->print_error_msg();
-echo $form->print_error_msg();
+echo $login->printErrorMsg();
+echo $form->printErrorMsg();
+
+# __END__
diff --git a/www/admin/edit_order.php b/www/admin/edit_order.php
index 822c5e3a..2a7e1dbd 100644
--- a/www/admin/edit_order.php
+++ b/www/admin/edit_order.php
@@ -1,209 +1,196 @@
 db_exec("SET search_path TO ".LOGIN_DB_SCHEMA);
-	$smarty = new SmartyML($lang);
-	if (TARGET == 'live' || TARGET == 'remote')
-	{
-		// login
-		$login->debug_output_all = DEBUG ? 1 : 0;
-		$login->echo_output_all = 0;
-		$login->print_output_all = DEBUG ? 1 : 0;
-		// form
-		$db->debug_output_all = DEBUG ? 1 : 0;
-		$db->echo_output_all = 0;
-		$db->print_output_all = DEBUG ? 1 : 0;
-	}
-	// set the template dir
-	if (defined('LAYOUT'))
-	{
-		$smarty->setTemplateDir(LAYOUT.DEFAULT_TEMPLATE.TEMPLATES);
-		$DATA['css'] = LAYOUT.DEFAULT_TEMPLATE.CSS;
-		$DATA['js'] = LAYOUT.DEFAULT_TEMPLATE.JS;
-	}
-	else
-	{
-		$smarty->setTemplateDir(TEMPLATES.DEFAULT_TEMPLATE);
-		$DATA['css'] = CSS.DEFAULT_TEMPLATE;
-		$DATA['js'] = JS.DEFAULT_TEMPLATE;
-	}
-
-	// order name is _always_ order_number for the edit interface
-
-	// follwing arrays do exist here:
-	// $position ... has the positions of the array (0..max), cause in a 
+//               I can't put an number into the array field, in this array,
+//               there are the POSITION stored, that should CHANGE there order (up/down)
+// $row_data_id ... has ALL ids from the sorting part
+// $row_data_order ... has ALL order positions from the soirting part
+if (count($position)) {
+	$original_id = $row_data_id;
 
-	// all the row data
-	$options_id = array();
-	$options_name = array();
-	$options_selected = array();
-	for ($i = 0; $i < count($row_data); $i ++)
-	{
-		$options_id[] = $i;
-		$options_name[] = $row_data[$i]["name"];
-		// list of points to order
-		for ($j = 0; $j < count($position); $j++)
-		{
-			// if matches, put into select array
-			if ($original_id[$position[$j]] == $row_data[$i]["id"])
-				$options_selected[] = $i;
+	// FIRST u have to put right sort, then read again ...
+	// hast to be >0 or the first one is selected and then there is no move
+	if ($up && $position[0] > 0) {
+		for ($i = 0; $i < count($position); $i++) {
+			// change position order
+			// this gets temp, id before that, gets actual (moves one "down")
+			// this gets the old before (moves one "up")
+			// is done for every element in row
+			// echo "A: ".$row_data_id[$position[$i]]." (".$row_data_order[$position[$i]].") -- ".$row_data_id[$position[$i]-1]." (".$row_data_order[$position[$i]-1].")
"; + $temp_id = $row_data_id[$position[$i]]; + $row_data_id[$position[$i]] = $row_data_id[$position[$i]-1]; + $row_data_id[$position[$i]-1] = $temp_id; + // echo "A: ".$row_data_id[$position[$i]]." (".$row_data_order[$position[$i]].") -- ".$row_data_id[$position[$i]-1]." (".$row_data_order[$position[$i]-1].")
"; + } // for + } // if up + + // the last position id from position array is not to be the count-1 of row_data_id array, or it is the last element + if ($down && ($position[count($position) - 1] != (count($row_data_id) - 1))) { + for ($i = count($position) - 1; $i >= 0; $i --) { + // same as up, just up in other way, starts from bottom (last element) and moves "up" + // element before actuel gets temp, this element, becomes element after this, + // element after this, gets this + $temp_id = $row_data_id[$position[$i] + 1]; + $row_data_id[$position[$i] + 1] = $row_data_id[$position[$i]]; + $row_data_id[$position[$i]] = $temp_id; + } // for + } // if down + + // write data ... (which has to be abstrackt ...) + if (($up && $position[0] > 0) || ($down && ($position[count($position) - 1]!=(count($row_data_id) - 1)))) { + for ($i = 0; $i < count($row_data_id); $i ++) { + $q = "UPDATE ".$table_name." SET order_number = ".$row_data_order[$i]." WHERE ".$table_name."_id = ".$row_data_id[$i]; + $q = $db->dbExec($q); + } // for all article ids ... + } // if write +} // if there is something to move + +// get ... +$q = "SELECT ".$table_name."_id, name, order_number FROM ".$table_name." "; +if ($where_string) { + $q .= "WHERE $where_string "; +} +$q .= "ORDER BY order_number"; + +while ($res = $db->dbReturn($q)) { + $row_data[] = array ( + "id" => $res[$table_name."_id"], + "name" => $res["name"], + "order" => $res["order_number"] + ); +} // while read data ... + +// define all needed smarty stuff for the general HTML/page building +$DATA['css'] = LAYOUT.DEFAULT_TEMPLATE.CSS; +$DATA['js'] = LAYOUT.DEFAULT_TEMPLATE.JS; +$HEADER['CSS'] = CSS; +$HEADER['DEFAULT_ENCODING'] = DEFAULT_ENCODING; +$HEADER['JS'] = JS; +$HEADER['STYLESHEET'] = $EDIT_STYLESHEET; +$HEADER['JAVASCRIPT'] = $EDIT_JAVASCRIPT; +// html title +$HEADER['HTML_TITLE'] = (!$L_TITLE) ? $smarty->l10n->__($G_TITLE) : $smarty->l10n->__($L_TITLE); + +$DATA['table_width'] = $table_width; + +// error msg +if ($error) { + $messages[] = array('msg' => $msg, 'class' => 'error', 'width' => $table_width); +} +$DATA['form_error_msg'] = $messages; + +// all the row data +$options_id = array(); +$options_name = array(); +$options_selected = array(); +for ($i = 0; $i < count($row_data); $i ++) { + $options_id[] = $i; + $options_name[] = $row_data[$i]["name"]; + // list of points to order + for ($j = 0; $j < count($position); $j++) { + // if matches, put into select array + if ($original_id[$position[$j]] == $row_data[$i]["id"]) { + $options_selected[] = $i; } } - $DATA['options_id'] = $options_id; - $DATA['options_name'] = $options_name; - $DATA['options_selected'] = $options_selected; +} +$DATA['options_id'] = $options_id; +$DATA['options_name'] = $options_name; +$DATA['options_selected'] = $options_selected; - // hidden list for the data (id, order number) - $row_data_id = array(); - $row_data_order = array(); - for ($i = 0; $i < count($row_data); $i++) - { - $row_data_id[] = $row_data[$i]["id"]; - $row_data_order[] = $row_data[$i]["order"]; - } - $DATA['row_data_id'] = $row_data_id; - $DATA['row_data_order'] = $row_data_order; +// hidden list for the data (id, order number) +$row_data_id = array(); +$row_data_order = array(); +for ($i = 0; $i < count($row_data); $i++) { + $row_data_id[] = $row_data[$i]["id"]; + $row_data_order[] = $row_data[$i]["order"]; +} +$DATA['row_data_id'] = $row_data_id; +$DATA['row_data_order'] = $row_data_order; - // hidden names for the table & where string - $DATA['table_name'] = $table_name; - $DATA['where_string'] = $where_string; +// hidden names for the table & where string +$DATA['table_name'] = $table_name; +$DATA['where_string'] = $where_string; - // debug data, if DEBUG flag is on, this data is print out - $DEBUG_DATA['DEBUG'] = $DEBUG_TMPL; +// debug data, if DEBUG flag is on, this data is print out +$DEBUG_DATA['DEBUG'] = $DEBUG_TMPL; - // create main data array - $CONTENT_DATA = array_merge($HEADER, $DATA, $DEBUG_DATA); - // data is 1:1 mapping (all vars, values, etc) - while (list($key, $value) = each($CONTENT_DATA)) - { - $smarty->assign($key, $value); - } - $smarty->display('edit_order.tpl'); +// create main data array +$CONTENT_DATA = array_merge($HEADER, $DATA, $DEBUG_DATA); +// data is 1:1 mapping (all vars, values, etc) +while (list($key, $value) = each($CONTENT_DATA)) { + $smarty->assign($key, $value); +} +$smarty->display('edit_order.tpl'); + +echo $login->printErrorMsg(); +echo $db->printErrorMsg(); + +# __END__ - echo $login->print_error_msg(); - echo $db->print_error_msg(); -?> diff --git a/www/admin/namespace_test.php b/www/admin/namespace_test.php index 605a03a0..2e23ccbf 100755 --- a/www/admin/namespace_test.php +++ b/www/admin/namespace_test.php @@ -1,5 +1,10 @@ ROOT: ".ROOT."
BASE: ".BASE."
"; $lang = 'en_utf8'; -$base = new CoreLibs\Basic($DB_CONFIG[MAIN_DB]); +$base = new CoreLibs\Admin\Backend($DB_CONFIG[MAIN_DB], $lang); print "ByteStringFormat: ".$base->ByteStringFormat(1234567.12)."
"; print "byteStringFormat: ".$base->byteStringFormat(1234567.12)."
"; +print "get_page_name: ".$base->get_page_name()."
"; +print "getPageName: ".$base->getPageName()."
"; + +print "DB Info: ".$base->dbInfo(1); ob_end_flush(); +print $base->printErrorMsg(); + # __END__ diff --git a/www/lib/CoreLibs/ACL/Login.inc b/www/lib/CoreLibs/ACL/Login.inc index d19c20dd..628851e1 100644 --- a/www/lib/CoreLibs/ACL/Login.inc +++ b/www/lib/CoreLibs/ACL/Login.inc @@ -57,10 +57,9 @@ * 2000-06-01: created basic idea and functions *********************************************************************/ -// try to include file from LIBS path, or from normal path -_spl_autoload('Class.DB.IO.inc'); +namespace CoreLibs\ACL; -class login extends db_io +class Login extends \CoreLibs\DB\IO { private $euid; // the user id var private $permission_okay = 0; // is set to one if login okay, or EUID is set and user is okay to access this page @@ -100,14 +99,12 @@ class login extends db_io exit; } - // get the language sub class & init it - _spl_autoload('Class.l10n.inc'); - $this->l = new l10n($lang); + $this->l = new \CoreLibs\Language\L10n($lang); // if we have a search path we need to set it, to use the correct DB to login // check what schema to use. if there is a login schema use this, else check if there is a schema set in the config, or fall back to DB_SCHEMA if this exists, if this also does not exists use public schema $SCHEMA = defined('LOGIN_DB_SCHEMA') ? LOGIN_DB_SCHEMA : ($db_config['db_schema'] ? $db_config['db_schema'] : (defined('DB_SCHEMA') ? DB_SCHEMA : 'public')); - $this->db_exec("SET search_path TO ".$SCHEMA); + $this->dbExec("SET search_path TO ".$SCHEMA); $this->euid = array_key_exists('EUID', $_SESSION) ? $_SESSION['EUID'] : 0; // if there is none, there is none, saves me POST/GET check // get login vars, are so, can't be changed // prepare @@ -174,7 +171,7 @@ class login extends db_io $_SESSION['DEFAULT_ACL_LIST'] = array (); // read the current edit_access_right list into an array $q = "SELECT level, type, name FROM edit_access_right WHERE level >= 0 ORDER BY level"; - while ($res = $this->db_return($q)) { + while ($res = $this->dbReturn($q)) { // level to description format (numeric) $this->default_acl_list[$res['level']] = array ( 'type' => $res['type'], @@ -185,19 +182,19 @@ class login extends db_io $_SESSION['DEFAULT_ACL_LIST'] = $this->default_acl_list; // if username & password & !$euid start login - $this->login_login_user(); + $this->loginLoginUser(); // checks if $euid given check if user is okay for that side - $this->login_check_permissions(); + $this->loginCheckPermissions(); // logsout user - $this->login_logout_user(); + $this->loginLogoutUser(); // if the password change flag is okay, run the password change method if ($this->password_change) { - $this->login_password_change(); + $this->loginPasswordChange(); } // if !$euid || permission not okay, print login screan - echo $this->login_print_login(); + echo $this->loginPrintLogin(); // closing all connections, depending on error status, exit - if (!$this->login_close_class()) { + if (!$this->loginCloseClass()) { // do not go anywhere, quit processing here // do something with possible debug data? if (TARGET == 'live' || TARGET == 'remote') { @@ -206,14 +203,14 @@ class login extends db_io $this->echo_output_all = 0; $this->print_output_all = DEBUG ? 1 : 0; } - $status_msg = $this->print_error_msg(); + $status_msg = $this->printErrorMsg(); if ($this->echo_output_all) { echo $status_msg; } exit; } // set acls for this user/group and this page - $this->login_set_acl(); + $this->loginSetAcl(); } // METHOD: _login @@ -225,11 +222,12 @@ class login extends db_io parent::__destruct(); } - // METHOD: login_login_user + // METHOD: loginLoginUser + // WAS : login_login_user // PARAMS: none // RETURN: none // DESC : if user pressed login button this script is called, but only if there is no preview euid set - private function login_login_user() + private function loginLoginUser() { // have to get the global stuff here for setting it later if (!$this->euid && $this->login) { @@ -253,7 +251,7 @@ class login extends db_io $q .= "eg.edit_access_right_id = eareg.edit_access_right_id AND "; // password match is done in script, against old plain or new blowfish encypted $q .= "(LOWER(username) = '".strtolower($this->username)."') "; - $res = $this->db_return($q); + $res = $this->dbReturn($q); // username is wrong, but we throw for wrong username and wrong password the same error if (!$this->cursor_ext[md5($q)]["num_rows"]) { $this->login_error = 1010; @@ -280,13 +278,24 @@ class login extends db_io } elseif ($res['locked']) { // user is locked, either set or auto set $this->login_error = 105; - } elseif ((preg_match("/^\\$2(a|y)\\$/", $res['password']) && CRYPT_BLOWFISH != 1) || (preg_match("/^\\$1\\$/", $res['password']) && CRYPT_MD5 != 1) || (preg_match("/^\\$[0-9A-Za-z.]{12}$/", $res['password']) && CRYPT_STD_DES != 1)) { + } elseif ((preg_match("/^\\$2(a|y)\\$/", $res['password']) && CRYPT_BLOWFISH != 1) || + (preg_match("/^\\$1\\$/", $res['password']) && CRYPT_MD5 != 1) || + (preg_match("/^\\$[0-9A-Za-z.]{12}$/", $res['password']) && CRYPT_STD_DES != 1) + ) { // this means password cannot be decrypted because of missing crypt methods $this->login_error = 9999; - } elseif ((preg_match("/^\\$2(a|y)\\$/", $res['password']) || preg_match("/^\\$1\\$/", $res['password']) || preg_match("/^\\$[0-9A-Za-z.]{12}$/", $res['password'])) && !$this->verifyCryptString($this->password, $res['password'])) { + } elseif ((preg_match("/^\\$2(a|y)\\$/", $res['password']) || + preg_match("/^\\$1\\$/", $res['password']) || + preg_match("/^\\$[0-9A-Za-z.]{12}$/", $res['password'])) && + !$this->verifyCryptString($this->password, $res['password']) + ) { // check passwword as crypted, $2a$ or $2y$ is blowfish start, $1$ is MD5 start, $\w{12} is standard DES $this->login_error = 1011; - } elseif (!preg_match("/^\\$2(a|y)\\$/", $res['password']) && !preg_match("/^\\$1\\$/", $res['password']) && !preg_match("/^\\$[0-9A-Za-z.]{12}$/", $res['password']) && $res['password'] != $this->password) { + } elseif (!preg_match("/^\\$2(a|y)\\$/", $res['password']) && + !preg_match("/^\\$1\\$/", $res['password']) && + !preg_match("/^\\$[0-9A-Za-z.]{12}$/", $res['password']) && + $res['password'] != $this->password + ) { // check old plain password, non case sensitive $this->login_error = 1012; } else { @@ -294,7 +303,7 @@ class login extends db_io // set class var and session var $_SESSION["EUID"] = $this->euid = $res["edit_user_id"]; // check if user is okay - $this->login_check_permissions(); + $this->loginCheckPermissions(); if (!$this->login_error) { // now set all session vars and read page permissions $GLOBALS["DEBUG_ALL"] = $_SESSION["DEBUG_ALL"] = $res["debug"]; @@ -314,7 +323,7 @@ class login extends db_io // reset any login error count for this user if ($res['login_error_count'] > 0) { $q = "UPDATE edit_user SET login_error_count = 0, login_error_date_last = NULL, login_error_date_first = NULL WHERE edit_user_id = ".$res['edit_user_id']; - $this->db_exec($q); + $this->dbExec($q); } $pages = array(); $edit_page_ids = array(); @@ -324,7 +333,7 @@ class login extends db_io $q .= "WHERE ep.edit_page_id = epa.edit_page_id AND ear.edit_access_right_id = epa.edit_access_right_id "; $q .= "AND epa.enabled = 1 AND epa.edit_group_id = ".$res["edit_group_id"]." "; $q .= "ORDER BY ep.order_number"; - while ($res = $this->db_return($q)) { + while ($res = $this->dbReturn($q)) { // page id array for sub data readout $edit_page_ids[] = $res['edit_page_id']; // create the array for pages @@ -348,22 +357,26 @@ class login extends db_io } // for each page // get the visible groups for all pages and write them to the pages $_edit_page_id = 0; - $q = "SELECT epvg.edit_page_id, name, flag FROM edit_visible_group evp, edit_page_visible_group epvg WHERE evp.edit_visible_group_id = epvg.edit_visible_group_id AND epvg.edit_page_id IN (".join(', ', $edit_page_ids).") ORDER BY epvg.edit_page_id"; - while ($res = $this->db_return($q)) { + $q = "SELECT epvg.edit_page_id, name, flag "; + $q .= "FROM edit_visible_group evp, edit_page_visible_group epvg "; + $q .= "WHERE evp.edit_visible_group_id = epvg.edit_visible_group_id AND epvg.edit_page_id IN (".join(', ', $edit_page_ids).") "; + $q .= "ORDER BY epvg.edit_page_id"; + while ($res = $this->dbReturn($q)) { if ($res['edit_page_id'] != $_edit_page_id) { // search the pos in the array push - $pos = $this->array_search_recursive($res['edit_page_id'], $pages, 'edit_page_id'); + $pos = $this->arraySearchRecursive($res['edit_page_id'], $pages, 'edit_page_id'); $_edit_page_id = $res['edit_page_id']; } $pages[$pos[0]]['visible'][$res['name']] = $res['flag']; } // get the same for the query strings $_edit_page_id = 0; - $q = "SELECT eqs.edit_page_id, name, value, dynamic FROM edit_query_string eqs WHERE enabled = 1 AND edit_page_id IN (".join(', ', $edit_page_ids).") ORDER BY eqs.edit_page_id"; - while ($res = $this->db_return($q)) { + $q = "SELECT eqs.edit_page_id, name, value, dynamic FROM edit_query_string eqs "; + $q .= "WHERE enabled = 1 AND edit_page_id IN (".join(', ', $edit_page_ids).") ORDER BY eqs.edit_page_id"; + while ($res = $this->dbReturn($q)) { if ($res['edit_page_id'] != $_edit_page_id) { // search the pos in the array push - $pos = $this->array_search_recursive($res['edit_page_id'], $pages, 'edit_page_id'); + $pos = $this->arraySearchRecursive($res['edit_page_id'], $pages, 'edit_page_id'); $_edit_page_id = $res['edit_page_id']; } $pages[$pos[0]]['query'][] = array ( @@ -378,16 +391,17 @@ class login extends db_io // load the edit_access user rights $q = "SELECT ea.edit_access_id, level, type, ea.name, ea.color, ea.uid, edit_default "; $q .= "FROM edit_access_user eau, edit_access_right ear, edit_access ea "; - $q .= "WHERE eau.edit_access_id = ea.edit_access_id AND eau.edit_access_right_id = ear.edit_access_right_id AND eau.enabled = 1 AND edit_user_id = ".$this->euid." "; + $q .= "WHERE eau.edit_access_id = ea.edit_access_id AND eau.edit_access_right_id = ear.edit_access_right_id "; + $q .= "AND eau.enabled = 1 AND edit_user_id = ".$this->euid." "; $q .= "ORDER BY ea.name"; $unit_access = array(); $eauid = array(); $unit_acl = array(); - while ($res = $this->db_return($q)) { + while ($res = $this->dbReturn($q)) { // read edit access data fields and drop them into the unit access array $q_sub ="SELECT name, value FROM edit_access_data WHERE enabled = 1 AND edit_access_id = ".$res['edit_access_id']; $ea_data = array (); - while ($res_sub = $this->db_return($q_sub)) { + while ($res_sub = $this->dbReturn($q_sub)) { $ea_data[$res_sub['name']] = $res_sub['value']; } // build master unit array @@ -419,8 +433,10 @@ class login extends db_io $login_error_date_first = ', login_error_date_first = NOW()'; } // update login error count for this user - $q = "UPDATE edit_user SET login_error_count = login_error_count + 1, login_error_date_last = NOW() $login_error_date_first WHERE edit_user_id = ".$res['edit_user_id']; - $this->db_exec($q); + $q = "UPDATE edit_user "; + $q .= "SET login_error_count = login_error_count + 1, login_error_date_last = NOW() $login_error_date_first "; + $q .= "WHERE edit_user_id = ".$res['edit_user_id']; + $this->dbExec($q); // totally lock the user if error max is reached if ($res['login_error_count'] + 1 > $this->max_login_error_count) { // do some alert reporting in case this error is too big @@ -441,18 +457,19 @@ class login extends db_io } // if he pressed login at least and is not yet loggined in } - // METHOD: login_check_permission + // METHOD: loginCheckPermissions + // WAS : login_check_permission // PARAMS: none // RETUNR none // DESC : for every page the user access this script checks if he is allowed to do so - public function login_check_permissions() + public function loginCheckPermissions() { if ($this->euid && $this->login_error != 103) { $q = "SELECT filename "; $q .= "FROM edit_page ep, edit_page_access epa, edit_group eg, edit_user eu "; $q .= "WHERE ep.edit_page_id = epa.edit_page_id AND eg.edit_group_id = epa.edit_group_id AND eg.edit_group_id = eu.edit_group_id "; $q .= "AND eu.edit_user_id = ".$this->euid." AND filename = '".$this->page_name."' AND eg.enabled = 1 AND epa.enabled = 1"; - $res = $this->db_return_row($q); + $res = $this->dbReturnRow($q); // unset mem limit if debug is set to 1 // if (($GLOBALS["DEBUG_ALL"] || $GLOBALS["DB_DEBUG"] || $_SESSION["DEBUG_ALL"] || $_SESSION["DB_DEBUG"]) && ini_get('memory_limit') != -1) // ini_set('memory_limit', -1); @@ -467,11 +484,12 @@ class login extends db_io return $this->permission_okay; } - // METHOD: login_logout_user + // METHOD: loginLogoutUser + // WAS : login_logout_user // PARAMS: none // RETURN: none // DESC : if a user pressed on logout, destroyes session and unsets all global vars - public function login_logout_user() + public function loginLogoutUser() { if ($this->logout || $this->login_error) { // unregister and destroy session vars @@ -495,7 +513,8 @@ class login extends db_io } } - // METHOD: login_set_acl + // METHOD: loginSetAcl + // WAS : login_set_acl // PARAMS: none // RETURN: none // DESC : sets all the basic ACLs @@ -512,7 +531,7 @@ class login extends db_io // * if an account ACL is set, set this parallel, account ACL overrides user ACL if it applies // * if edit access ACL level is set, use this, else use page // set all base ACL levels as a list keyword -> ACL number - public function login_set_acl() + public function loginSetAcl() { // we start with the default acl $this->acl['base'] = DEFAULT_ACL_LEVEL; @@ -595,11 +614,12 @@ class login extends db_io // $this->debug('ACL', $this->print_ar($this->acl)); } - // METHOD: login_check_edit_access + // METHOD: loginCheckEditAccess + // WAS : login_check_edit_access // PARAMS: edit_access_id to check // RETURN: true/false: if the edit access is not in the valid list: false // DESC : checks if this edit access id is valid - public function login_check_edit_access($edit_access_id) + public function loginCheckEditAccess($edit_access_id) { if (array_key_exists($edit_access_id, $this->acl['unit'])) { return true; @@ -608,11 +628,12 @@ class login extends db_io } } - // METHOD: login_password_change + // METHOD: loginPasswordChange + // WAS : login_password_change // PARAMS: none // RETURN: none // DESC : changes a user password - private function login_password_change() + private function loginPasswordChange() { if ($this->change_password) { $event = 'Password Change'; @@ -624,8 +645,8 @@ class login extends db_io } // check user exist, if not -> error if (!$this->login_error) { - $q = "SELECT edit_user_id FROM edit_user WHERE enabled = 1 AND username = '".$this->db_escape_string($this->pw_username)."'"; - list ($edit_user_id) = $this->db_return_row($q); + $q = "SELECT edit_user_id FROM edit_user WHERE enabled = 1 AND username = '".$this->dbEscapeString($this->pw_username)."'"; + list ($edit_user_id) = $this->dbReturnRow($q); if (!$edit_user_id) { // username wrong $this->login_error = 201; @@ -634,8 +655,8 @@ class login extends db_io } // check old passwords match -> error if (!$this->login_error) { - $q = "SELECT edit_user_id FROM edit_user WHERE enabled = 1 AND username = '".$this->db_escape_string($this->pw_username)."' AND password = '".$this->db_escape_string($this->pw_old_password)."'"; - list ($edit_user_id) = $this->db_return_row($q); + $q = "SELECT edit_user_id FROM edit_user WHERE enabled = 1 AND username = '".$this->dbEscapeString($this->pw_username)."' AND password = '".$this->dbEscapeString($this->pw_old_password)."'"; + list ($edit_user_id) = $this->dbReturnRow($q); if (!$edit_user_id) { // old password wrong $this->login_error = 202; @@ -659,8 +680,8 @@ class login extends db_io // no error change this users password if (!$this->login_error) { // update the user (edit_user_id) with the new password - $q = "UPDATE edit_user SET password = '".$this->db_escape_string($this->cryptString($this->pw_new_password))."' WHERE edit_user_id = ".$edit_user_id; - $this->db_exec($q); + $q = "UPDATE edit_user SET password = '".$this->dbEscapeString($this->cryptString($this->pw_new_password))."' WHERE edit_user_id = ".$edit_user_id; + $this->dbExec($q); $data = 'Password change for user "'.$this->pw_username.'" from "'.$this->pw_old_password.'" to "'.$this->pw_new_password.'"'; } } else { @@ -673,15 +694,16 @@ class login extends db_io } // button pressed } - // METHOD: login_print_login + // METHOD: loginPrintLogin + // WAS : login_print_login // PARAMS: none // RETURN: none // DESC : prints out login html part if no permission (error) is set - private function login_print_login() + private function loginPrintLogin() { if (!$this->permission_okay) { // set the templates now - $this->login_set_templates(); + $this->loginSetTemplates(); // if there is a global logout target ... if (file_exists($this->logout_target) && $this->logout_target) { $LOGOUT_TARGET = $this->logout_target; @@ -728,11 +750,12 @@ class login extends db_io } // if permission is 0 then print out login } - // METHOD: login_close_class + // METHOD: loginCloseClass + // WAS : login_close_class // PARAMS: none // RETURN: none // DESC : last function called, writes log and prints out error msg and exists script if permission 0 - private function login_close_class() + private function loginCloseClass() { // write to LOG table ... if ($this->login_error || $this->login || $this->logout) { @@ -750,9 +773,9 @@ class login extends db_io if ($this->euid) { // get user from user table $q = "SELECT username, password FROM edit_user WHERE edit_user_id = ".$this->euid; - list($username, $password) = $this->db_return_row($q); + list($username, $password) = $this->dbReturnRow($q); } // if euid is set, get username (or try) - $this->write_log($event, '', $this->login_error, $username, $password); + $this->writeLog($event, '', $this->login_error, $username, $password); } // write log under certain settings // now close DB connection // $this->error_msg = $this->_login(); @@ -763,11 +786,12 @@ class login extends db_io } } - // METHOD: login_set_templates + // METHOD: loginSetTemplates + // WAS : login_set_templates // PARAMS: // RETURN: none // DESC : checks if there are external templates, if not uses internal fallback ones - private function login_set_templates() + private function loginSetTemplates() { $strings = array ( 'HTML_TITLE' => $this->l->__("LOGIN"), @@ -911,13 +935,14 @@ EOM; } } - // METHOD: write_log + // METHOD: writeLog + // WAS : write_log // PARAMS: event -> string of what has been done // data -> data information (id, etc) // error -> if error, write error string (not enougth data, etc) // RETURN: none // DESC : writes detailed data into the edit user log table (keep log what user does) - private function write_log($event, $data, $error = "", $username = "", $password = "") + private function writeLog($event, $data, $error = "", $username = "", $password = "") { if ($this->login) { $this->action = 'Login'; @@ -931,31 +956,32 @@ EOM; '_FILES' => $_FILES, 'error' => $this->login_error ); - $data_binary = $this->db_escape_bytea(bzcompress(serialize($_data_binary))); + $data_binary = $this->dbEscapeBytea(bzcompress(serialize($_data_binary))); // SQL querie for log entry $q = "INSERT INTO edit_log "; $q .= "(username, password, euid, event_date, event, error, data, data_binary, page, "; $q .= "ip, user_agent, referer, script_name, query_string, server_name, http_host, http_accept, http_accept_charset, http_accept_encoding, session_id, "; $q .= "action, action_id, action_yes, action_flag, action_menu, action_loaded, action_value, action_error) "; - $q .= "VALUES ('".$this->db_escape_string($username)."', '".$this->db_escape_string($password)."', ".(($this->euid) ? $this->euid : 'NULL').", "; - $q .= "NOW(), '".$this->db_escape_string($event)."', '".$this->db_escape_string($error)."', '".$this->db_escape_string($data)."', '".$data_binary."', '".$this->page_name."', "; + $q .= "VALUES ('".$this->dbEscapeString($username)."', '".$this->dbEscapeString($password)."', ".(($this->euid) ? $this->euid : 'NULL').", "; + $q .= "NOW(), '".$this->dbEscapeString($event)."', '".$this->dbEscapeString($error)."', '".$this->dbEscapeString($data)."', '".$data_binary."', '".$this->page_name."', "; foreach (array('REMOTE_ADDR', 'HTTP_USER_AGENT', 'HTTP_REFERER', 'SCRIPT_FILENAME', 'QUERY_STRING', 'SERVER_NAME', 'HTTP_HOST', 'HTTP_ACCEPT', 'HTTP_ACCEPT_CHARSET', 'HTTP_ACCEPT_ENCODING') as $server_code) { if (array_key_exists($server_code, $_SERVER)) { - $q .= "'".$this->db_escape_string($_SERVER[$server_code])."', "; + $q .= "'".$this->dbEscapeString($_SERVER[$server_code])."', "; } else { $q .= "NULL, "; } } $q .= "'".session_id()."', "; - $q .= "'".$this->db_escape_string($this->action)."', '".$this->db_escape_string($this->username)."', NULL, '".$this->db_escape_string($this->login_error)."', NULL, NULL, '".$this->db_escape_string($this->permission_okay)."', NULL)"; - $this->db_exec($q, 'NULL'); + $q .= "'".$this->dbEscapeString($this->action)."', '".$this->dbEscapeString($this->username)."', NULL, '".$this->dbEscapeString($this->login_error)."', NULL, NULL, '".$this->dbEscapeString($this->permission_okay)."', NULL)"; + $this->dbExec($q, 'NULL'); } - // METHOD: login_check_edit_access_id + // METHOD: loginCheckEditAccessId + // WAS : login_check_edit_access_id // PARAMS: edit access id to check // RETURN: same edit access id if ok, or the default edit access id if given one is not valud // DESC : checks that the given edit access id is valid for this user - public function login_check_edit_access_id($edit_access_id) + public function loginCheckEditAccessId($edit_access_id) { if (!array_key_exists($edit_access_id, $_SESSION["UNIT"])) { return $_SESSION["UNIT_DEFAULT"]; @@ -964,11 +990,12 @@ EOM; } } - // METHOD: login_set_edit_access_data + // METHOD: loginSetEditAccessData + // WAS : login_set_edit_access_data // PARAMS: edit access id, key value to search for // RETURN: false for not found or string for found data // DESC : searchs in the data set for the unit for the data key and returns the value asociated with it - public function login_set_edit_access_data($edit_access_id, $data_key) + public function loginSetEditAccessData($edit_access_id, $data_key) { if (!$_SESSION['UNIT'][$edit_access_id]['data'][$data_key]) { return false; @@ -977,3 +1004,5 @@ EOM; } } } // close class + +# __END__ diff --git a/www/lib/CoreLibs/Admin/Backend.inc b/www/lib/CoreLibs/Admin/Backend.inc index 1e7b5680..3d26fcf9 100644 --- a/www/lib/CoreLibs/Admin/Backend.inc +++ b/www/lib/CoreLibs/Admin/Backend.inc @@ -2,7 +2,7 @@ /********************************************************************* * AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org) * CREATED: 2006/08/15 -* VERSION: 0.1.0 +* VERSION: 1.0.0 * RELEASED LICENSE: GNU GPL 3 * DESCRIPTION * Basic Admin interface backend @@ -22,10 +22,9 @@ * *********************************************************************/ -// try to include file from LIBS path, or from normal path -_spl_autoload('Class.DB.IO.inc'); +namespace CoreLibs\Admin; -class AdminBackend extends db_io +class Backend extends \CoreLibs\DB\IO { // page name public $page_name; // the name of the current page @@ -61,9 +60,7 @@ class AdminBackend extends db_io public function __construct($db_config, $lang, $debug = 0, $db_debug = 0, $echo = 1, $print = 0) { // get the language sub class & init it - _spl_autoload('Class.l10n.inc'); - - $this->l = new l10n($lang); + $this->l = new \CoreLibs\Language\L10n($lang); // init the database class // $this->db_io($db_config, $debug, $db_debug, $echo, $print); @@ -78,7 +75,7 @@ class AdminBackend extends db_io ); // set page name - $this->page_name = $this->get_page_name(); + $this->page_name = $this->getPageName(); // set the action ids foreach ($this->action_list as $_action) { @@ -122,7 +119,7 @@ class AdminBackend extends db_io // METHOD: adbEditLog() // PARAMS: event -> any kind of event description, data -> any kind of data related to that event // RETURN: none - // DESC: writes all action vars plus other info into edit_log table + // DESC : writes all action vars plus other info into edit_log table public function adbEditLog($event = '', $data = '', $write_type = 'STRING') { if ($write_type == 'BINARY') { @@ -162,7 +159,7 @@ class AdminBackend extends db_io // METHOD: adbTopMenu // PARAMS: level // RETURN: returns an array for the top menu with all correct settings - // DESC: menu creater + // DESC : menu creater public function adbTopMenu($flag = 0) { if ($this->menu_show_flag) { @@ -174,9 +171,7 @@ class AdminBackend extends db_io if (!is_array($pages)) { $pages = array (); } - -//$this->debug('pages', $this->print_ar($pages)); - + // $this->debug('pages', $this->print_ar($pages)); // if flag is 0, then we show all, else, we show only the matching flagges array points // array is already sorted after correct order reset($pages); @@ -244,7 +239,7 @@ class AdminBackend extends db_io // METHOD: adbShowMenuPoint // PARAMS: filename // RETURN: returns boolean true/false - // DESC: checks if this filename is in the current situation (user id, etc) available + // DESC : checks if this filename is in the current situation (user id, etc) available public function adbShowMenuPoint($filename) { $enabled = 0; @@ -260,7 +255,7 @@ class AdminBackend extends db_io // METHOD: adbAssocArray // PARAMS: db array, key, value part // RETURN: returns and associative array - // DESC: creates out of a normal db_return array an assoc array + // DESC : creates out of a normal db_return array an assoc array public function adbAssocArray($db_array, $key, $value) { return $this->GenAssocArray($db_array, $key, $value); @@ -270,7 +265,7 @@ class AdminBackend extends db_io // METHOD: adbByteStringFormat // PARAMS: int // RETURN: string - // DESC: converts bytes into formated string with KB, MB, etc + // DESC : converts bytes into formated string with KB, MB, etc public function adbByteStringFormat($number) { return $this->ByteStringFormat($number); @@ -285,7 +280,7 @@ class AdminBackend extends db_io // path -> if source start is not ROOT path, if empty ROOT is choosen // cache -> cache path, if not given TMP is used // RETURN: thumbnail name - // DESC: converts picture to a thumbnail with max x and max y size + // DESC : converts picture to a thumbnail with max x and max y size public function adbCreateThumbnail($pic, $size_x, $size_y, $dummy = false, $path = "", $cache = "") { return $this->CreateThumbnail($pic, $size_x, $size_y, $dummy, $path, $cache); @@ -296,7 +291,7 @@ class AdminBackend extends db_io // msg -> string, can be printf formated // var array -> optional data for a possible printf formated msg // RETURN: none - // DESC: wrapper function to fill up the mssages array + // DESC : wrapper function to fill up the mssages array public function adbMsg($level, $msg, $vars = array ()) { if (!preg_match("/^info|warning|error$/", $level)) { @@ -329,7 +324,7 @@ class AdminBackend extends db_io // associate -> NULL for free, LOCK for first insert, group key for reference to first entry // file -> string for special file copy actions; mostyle "test#live;..." // RETURN: none - // DESC: writes live queue + // DESC : writes live queue public function adbLiveQueue($queue_key, $type, $target, $data, $key_name, $key_value, $associate = null, $file = null) { $q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".live_queue ("; @@ -348,7 +343,7 @@ class AdminBackend extends db_io // suffix: additional info printed after the date time variable in the drop down, also used for ID in the on change JS call // minute steps, can be 1 (default), 5, 10, etc, if invalid (outside 1h range, it falls back to 1min) // RETURN: HTML formated strings for drop down lists of date and time - // DESC: print the date/time drop downs, used in any queue/send/insert at date/time place + // DESC : print the date/time drop downs, used in any queue/send/insert at date/time place public function adbPrintDateTime($year, $month, $day, $hour, $min, $suffix = '', $min_steps = 1) { // if suffix given, add _ before @@ -408,3 +403,5 @@ class AdminBackend extends db_io return $string; } } + +# __END__ diff --git a/www/lib/CoreLibs/Basic.inc b/www/lib/CoreLibs/Basic.inc index 9818e0fc..ba3d29b4 100644 --- a/www/lib/CoreLibs/Basic.inc +++ b/www/lib/CoreLibs/Basic.inc @@ -1,10 +1,12 @@ - calls with "level", "string" and flag to turn off (0) the newline at the end * debug_for -> sets debug on/off for a type (error, echo, print) for a certain level * print_error_msg -> prints out the error message, optional parameter is a header prefix @@ -58,7 +60,7 @@ * crypt* -> encrypt and decrypt login string data, used by Login class * setFormToken/validateFormToken -> form protection with token * -* PRIVATE METHODS +* PRIVATE METHOD:S * fdebug_fp -> opens and closes file, called from fdebug method * write_error_msg -> writes error msg to file if requested * @@ -160,9 +162,9 @@ class Basic // form token (used for form validation) private $form_token = ''; - // METHOD __construct - // PARAMS debug_all (0)/1, echo_all (1)/0, print_all (0)/1 - // RETURN none + // METHOD: __construct + // PARAMS: debug_all (0)/1, echo_all (1)/0, print_all (0)/1 + // RETURN: none // DESC constructor public function __construct($debug_all = 0, $echo_all = 1, $print_all = 0) { @@ -172,9 +174,9 @@ class Basic // internal info var $this->class_info["basic"] = array ( "class_name" => "Basic", - "class_version" => "0.9.0", + "class_version" => "2.0.0", "class_created" => "2003-03-24", - "class_author" => 'Clemens "Gullevek" Schwaighofer (.at)' + "class_author" => 'Clemens Schwaighofer' ); // set the page name @@ -344,10 +346,10 @@ class Basic $this->runningTime(); } - // METHOD __destruct - // PARAMS none - // RETURN if debug is on, return error data - // DESC basic deconstructor (should be called from all deconstructors in higher classes) + // METHOD: __destruct + // PARAMS: none + // RETURN: if debug is on, return error data + // DESC : basic deconstructor (should be called from all deconstructors in higher classes) // writes out $error_msg to global var public function __destruct() { @@ -358,163 +360,13 @@ class Basic } // ************************************************************* - // COMPATIBILITY METHODS - // those methods are deprecated function call names - // they exist for backwards compatibility only + // GENERAL METHOD:S // ************************************************************* - public function running_time($simple = false) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->runningTime($simple); - } - - public static function print_time($set_microtime = -1) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->printTime($set_microtime); - } - - private function fdebug_fp($flag = '') - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->fdebugFP($flag); - } - - public function debug_for($type, $flag) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->debugFor($type, $flag); - } - - public function get_caller_method($level = 2) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->getCallerMethod($level); - } - - public function merge_errors($error_msg = array ()) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->mergeErrors($error_msg); - } - - public function print_error_msg($string = '') - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->printErrorMsg($string); - } - - private function write_error_msg($level, $error_string) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->writeErrorMsg($level, $error_string); - } - - public function reset_error_msg($level = '') - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->resetErrorMsg($level); - } - - public static function print_ar($array) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->printAr($array); - } - - public function magic_links($string, $target = "_blank") - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->magicLinks($string, $target); - } - - private function create_url($href, $atag, $_1, $_2, $_3, $name, $class) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->createUrl($href, $atag, $_1, $_2, $_3, $name, $class); - } - - private function create_email($mailto, $atag, $_1, $_2, $_3, $title, $class) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->createEmail($mailto, $atag, $_1, $_2, $_3, $title, $class); - } - - public function get_host_name() - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->getHostName(); - } - - public static function get_page_name($strip_ext = 0) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->getPageName($strip_ext); - } - - public static function get_filename_ending($filename) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->getFilenameEnding($filename); - } - - public static function array_search_recursive($needle, $haystack, $key_lookin = "") - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->arraySearchRecursive($needle, $haystack, $key_lookin); - } - - public static function array_search_recursive_all($needle, $haystack, $key, $path = null) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->arraySearchRecursiveAll($needle, $haystack, $key, $path); - } - - public static function array_search_simple($array, $key, $value) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->arraySearchSimple($array, $key, $value); - } - - public static function _mb_mime_encode($string, $encoding) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->__mbMimeEncode($string, $encoding); - } - - public function _crc32b($string) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->__crc32b($string); - } - - public function _sha1_short($string, $use_sha = false) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->__sha1Short($string, $use_sha); - } - - public function _hash($string, $hash_type = 'adler32') - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->__hash($string, $hash_type); - } - - public static function in_array_any($needle, $haystack) - { - $this->debug('DEPRECATED CALL', __FUNCTION); - $this->inArrayAny($needle, $haystack); - } - - // ************************************************************* - // GENERAL METHODS - // ************************************************************* - - // METHOD db_io_info - // PARAMS show, default 1, if set to 0 won't write to error_msg var - // RETURN string with info - // DESC default class info (prints out class info) + // METHOD: db_io_info + // PARAMS: show, default 1, if set to 0 won't write to error_msg var + // RETURN: string with info + // DESC : default class info (prints out class info) public function info($class_name = "basic", $stdio = 0) { unset($string); @@ -533,12 +385,12 @@ class Basic return $string; } - // METHOD runningTime - // WAS running_time - // PARAMS simple flag true/false, if given print non HTML info - // RETURN string with running time for debugging - // DESC prints start or end time in text format. On first call sets start time - // on second call it sends the end time and then also prints the running time + // METHOD: runningTime + // WAS : running_time + // PARAMS: simple flag true/false, if given print non HTML info + // RETURN: string with running time for debugging + // DESC : prints start or end time in text format. On first call sets start time + // on second call it sends the end time and then also prints the running time public function runningTime($simple = false) { list($micro, $timestamp) = explode(" ", microtime()); @@ -557,16 +409,15 @@ class Basic $running_time = $this->endtime - $this->starttime; $string .= ($simple ? 'Run: ' : "
Script running time: ").$running_time." s"; } -// $this->debug('info', $string); + // $this->debug('info', $string); return $running_time; } - // METHOD printTime - // WAS print_time - // PARAMS $set_microtime, 0 shows none, default (-1) shows all, positive number is for rounding - // RETURN formated datetime string - // DESCRIPTION - // wrapper around microtime function to print out y-m-d h:i:s.ms + // METHOD: printTime + // WAS : print_time + // PARAMS: $set_microtime, 0 shows none, default (-1) shows all, positive number is for rounding + // RETURN: formated datetime string + // DESC : wrapper around microtime function to print out y-m-d h:i:s.ms public static function printTime($set_microtime = -1) { list($microtime, $timestamp) = explode(" ", microtime()); @@ -581,12 +432,11 @@ class Basic } - // METHOD fdebug - // PARAMS $string: data to write to file + // METHOD: fdebug + // PARAMS: $string: data to write to file // $enter: default on true, if set to false, no linebreak (\n) will be put at the end - // RETURN none - // DESCRIPTION - // writes a string to a file immediatly, for fast debug output + // RETURN: none + // DESC : writes a string to a file immediatly, for fast debug output public function fdebug($string, $enter = 1) { if ($this->debug_filename) { @@ -600,12 +450,11 @@ class Basic } } - // METHOD fdebugFP - // WAS fdebug_fp - // PARAMS $flag: default '', 'o' -> open, 'c' -> close - // RETURN none - // DESCRIPTION - // if no debug_fp found, opens a new one; if fp exists close it + // METHOD: fdebugFP + // WAS : fdebug_fp + // PARAMS: $flag: default '', 'o' -> open, 'c' -> close + // RETURN: none + // DESC : if no debug_fp found, opens a new one; if fp exists close it private function fdebugFP($flag = '') { if (!$this->debug_fp || $flag == 'o') { @@ -616,15 +465,14 @@ class Basic } } - // METHOD debugFor - // WAS debug_for - // PARAMS $type: error, echo, print - // $flag: on/off - // $array of levels to turn on/off debug - // RETURN none - // DESCRIPTION - // passes list of level names, to turn on debug - // eg $foo->debug_for('print', 'on', array('LOG', 'DEBUG', 'INFO')); + // METHOD: debugFor + // WAS : debug_for + // PARAMS: $type: error, echo, print + // $flag: on/off + // $array of levels to turn on/off debug + // RETURN: none + // DESC : passes list of level names, to turn on debug + // eg $foo->debug_for('print', 'on', array('LOG', 'DEBUG', 'INFO')); public function debugFor($type, $flag) { $debug_on = func_get_args(); @@ -641,14 +489,13 @@ class Basic } } - // METHOD debug - // PARAMS $level: id for error message, groups messages together - // $string: the actual error message - // $strip: default on false, if set to true, all html tags will be stripped and
changed to \n - // this is only used for debug output - // RETURN none - // DESCRIPTION - // write debug data to error_msg array + // METHOD: debug + // PARAMS: $level: id for error message, groups messages together + // $string: the actual error message + // $strip: default on false, if set to true, all html tags will be stripped and
changed to \n + // this is only used for debug output + // RETURN: none + // DESC : write debug data to error_msg array public function debug($level, $string, $strip = false) { if (($this->debug_output[$level] || $this->debug_output_all) && !$this->debug_output_not[$level]) { @@ -681,12 +528,12 @@ class Basic } } - // METHOD getCallerMethod - // WAS get_caller_method - // PARAMS none (optional later: which level to deb ug) - // RETURN null or the function that called the function where this methid is called - // DESC if there is a need to find out which parent method called a child method, eg for debugging, this function does this - // call this method in the child method and you get the parent function that called it + // METHOD: getCallerMethod + // WAS : get_caller_method + // PARAMS: none (optional later: which level to deb ug) + // RETURN: null or the function that called the function where this methid is called + // DESC : if there is a need to find out which parent method called a child method, eg for debugging, this function does this + // call this method in the child method and you get the parent function that called it public function getCallerMethod($level = 2) { $traces = debug_backtrace(); @@ -706,12 +553,12 @@ class Basic return null; } - // METHOD mergeErrors - // WAS merge_errors - // PARAMS error array - // RETURN none - // DESC merges the given error array with the one from this class - // only merges visible ones + // METHOD: mergeErrors + // WAS : merge_errors + // PARAMS: error array + // RETURN: none + // DESC : merges the given error array with the one from this class + // only merges visible ones public function mergeErrors($error_msg = array ()) { if (!is_array($error_msg)) { @@ -722,12 +569,11 @@ class Basic } } - // METHOD printErrorMsg - // WAS print_error_msg - // PARAMS $string: prefix string for header - // RETURN error msg for all levels - // DESCRIPTION - // prints out the error string + // METHOD: printErrorMsg + // WAS : print_error_msg + // PARAMS: $string: prefix string for header + // RETURN: error msg for all levels + // DESC : prints out the error string public function printErrorMsg($string = '') { $string_output = ''; @@ -756,12 +602,11 @@ class Basic return $string_output; } - // METHOD writeErrorMsg - // WAS write_error_msg - // PARAMS $level: the level to write - // RETURN none - // DESCRIPTION - // writes error msg data to file for current level + // METHOD: writeErrorMsg + // WAS : write_error_msg + // PARAMS: $level: the level to write + // RETURN: none + // DESC : writes error msg data to file for current level private function writeErrorMsg($level, $error_string) { if (($this->debug_output[$level] || $this->debug_output_all) && !$this->debug_output_not[$level]) { @@ -824,13 +669,13 @@ class Basic } } - // METHOD resetErrorMsg - // WAS reset_error_msg - // PARAMS level -> optional level - // RETURN none - // DESC unsests the error message array - // can be used if writing is primary to file - // if no level given resets all + // METHOD: resetErrorMsg + // WAS : reset_error_msg + // PARAMS: level -> optional level + // RETURN: none + // DESC : unsests the error message array + // can be used if writing is primary to file + // if no level given resets all public function resetErrorMsg($level = '') { if (!$level) { @@ -840,14 +685,15 @@ class Basic } } - // METHOD errorHandler - // WAS ErrorHandler - // PARAMS none - // RETURN none - // DESC catch function to handle all errors that are not handled by php itself - // eg all errors that would be surpressed are written to a log file if this function is enabled - // to use it call with set_error_handler(array("baisc", "ErrorHandler")); - // NOTE: this will only catch any additional erros created AFTER the set_error_hanlder was set, so mostly no strict/notices from the classes are visible + // METHOD: errorHandler + // WAS : ErrorHandler + // PARAMS: none + // RETURN: none + // DESC : catch function to handle all errors that are not handled by php itself + // eg all errors that would be surpressed are written to a log file if this function is enabled + // to use it call with set_error_handler(array("baisc", "ErrorHandler")); + // NOTE : this will only catch any additional erros created AFTER the set_error_hanlder was set, + // so mostly no strict/notices from the classes are visible public static function errorHandler($type, $message, $file, $line, $context) { // error levels for PHP @@ -872,32 +718,30 @@ class Basic ); $fn = ROOT.LOG.'php_errors-'.date('Y-m-d').'.log'; - $output = '['.basic::print_time().'] {'.basic::get_page_name().'} ['.$file.'] <'.$line.'> ['.$error_level[$type].'|'.$type.']: '.$message."\n"; + $output = '['.Basic::print_time().'] {'.Basic::get_page_name().'} ['.$file.'] <'.$line.'> ['.$error_level[$type].'|'.$type.']: '.$message."\n"; $fp = fopen($fn, 'a'); fwrite($fp, $output); fclose($fp); return false; } - // METHOD printAr - // WAS print_ar - // PARAMS $array - // RETURN string html formatted - // DESCRIPTION - // prints a html formatted (pre) array + // METHOD: printAr + // WAS : print_ar + // PARAMS: $array + // RETURN: string html formatted + // DESC : prints a html formatted (pre) array public static function printAr($array) { return "
".print_r($array, 1)."
"; } - // METHOD checked - // PARAMS haystack (search in), needle (search for), type: 0: returns selected, 1, returns checked - // haystack can be an array or a string - // RETURN returns checked or selected, else returns nothing (empty return) - // DESCRIPTION - // returns 'checked' or 'selected' if okay - // $needle is a var, $haystack an array - // **** THE RETURN VALUE WILL CHANGE TO A DEFAULT "FALSE" **** + // METHOD: checked + // PARAMS: haystack (search in), needle (search for), type: 0: returns selected, 1, returns checked + // haystack can be an array or a string + // RETURN: returns checked or selected, else returns nothing (empty return) + // DESC : returns 'checked' or 'selected' if okay + // $needle is a var, $haystack an array + // **** THE RETURN: VALUE WILL CHANGE TO A DEFAULT "FALSE" **** public static function checked($haystack, $needle, $type = 0) { if (is_array($haystack)) { @@ -911,14 +755,13 @@ class Basic } } - // METHOD magicLinks - // WAS magic_links - // PARAMS string: data to transform to a valud HTML url, target: default _blank - // RETURN correctly formed html url link - // DESCRIPTION - // tries to find mailto:user@bubu.at and changes it into -> E-Mail senden - // or tries to take any url (http, ftp, etc) and transform it into a valid URL - // the string is in the format: some url|name#css|, same for email + // METHOD: magicLinks + // WAS : magic_links + // PARAMS: string: data to transform to a valud HTML url, target: default _blank + // RETURN: correctly formed html url link + // DESC : tries to find mailto:user@bubu.at and changes it into -> E-Mail senden + // or tries to take any url (http, ftp, etc) and transform it into a valid URL + // the string is in the format: some url|name#css|, same for email public function magicLinks($string, $target = "_blank") { $output = $string; @@ -951,7 +794,7 @@ class Basic // _7: link name/email link name // _9: style sheet class $self = $this; -// $this->debug('URL', 'Before: '.$output); + // $this->debug('URL', 'Before: '.$output); $output = preg_replace_callback( "/(href=\")?(\>)?\b($protRegex)([\w\.\-?&=+%#~,;\/]+)\b([\.\-?&=+%#~,;\/]*)(\|([^\||^#]+)(#([^\|]+))?\|)?/", function ($matches) use ($self) { @@ -969,9 +812,9 @@ class Basic ); $this->debug('URL', 'After: '.$output); -// // we have one slashes after the Protocol -> internal link no domain, strip out the proto -// $output = preg_replace("/($protRegex)\/(.*)/e", "\\2", $ouput); -// $this->debug('URL', "$output"); + // we have one slashes after the Protocol -> internal link no domain, strip out the proto + // $output = preg_replace("/($protRegex)\/(.*)/e", "\\2", $ouput); + // $this->debug('URL', "$output"); // post processing $output = str_replace("{TARGET}", $target, $output); @@ -982,19 +825,18 @@ class Basic return $output; } - // METHOD createUrl [INTERNAL] - // WAS create_url - // PARAMS url link, anchor tag (define both type or url), - // _1, _2, _3 = part of thel URL, if atag is set, _1 is not used - // target: link target, name: name for the url, if not given _2 + _3 is used - // class: style sheet - // RETURN correct string for url href process - // DESCRIPTION - // internal function, called by the magic url create functions. - // checks if title $_4 exists, if not, set url as title + // METHOD: createUrl [INTERNAL] + // WAS : create_url + // PARAMS: url link, anchor tag (define both type or url), + // _1, _2, _3 = part of thel URL, if atag is set, _1 is not used + // target: link target, name: name for the url, if not given _2 + _3 is used + // class: style sheet + // RETURN: correct string for url href process + // DESC : internal function, called by the magic url create functions. + // checks if title $_4 exists, if not, set url as title private function createUrl($href, $atag, $_1, $_2, $_3, $name, $class) { -// $this->debug('URL', "1: $_1 - 2: $_2 - $_3 - atag: $atag - name: $name - class: $class"); + // $this->debug('URL', "1: $_1 - 2: $_2 - $_3 - atag: $atag - name: $name - class: $class"); // if $_1 ends with //, then we strip $_1 complete & target is also blanked (its an internal link) if (preg_match("/\/\/$/", $_1) && preg_match("/^\//", $_2)) { $_1 = ''; @@ -1012,14 +854,13 @@ class Basic } } - // METHOD createEmail [INTERNAL] - // WAS create_email - // PARAMS email address, atag (define type of url) + // METHOD: createEmail [INTERNAL] + // WAS : create_email + // PARAMS: email address, atag (define type of url) // _1, _2, _3: parts of the email _1 before @, _2 after @, 3_ tld // title: name for the link, if not given use email // class: style sheet - // DESCRIPTION - // internal function for createing email, returns data to magic_url method + // DESC : internal function for createing email, returns data to magic_url method private function createEmail($mailto, $atag, $_1, $_2, $_3, $title, $class) { $email = $_1."@".$_2.".".$_3; @@ -1032,12 +873,11 @@ class Basic } } - // METHOD getHostName - // WAS get_host_name - // PARAMS none - // RETURN host name - // DESCRIPTION - // get the host name without the port as given by the SELF var + // METHOD: getHostName + // WAS : get_host_name + // PARAMS: none + // RETURN: host name + // DESC : get the host name without the port as given by the SELF var public function getHostName() { $port = ''; @@ -1052,14 +892,13 @@ class Basic return $host_name; } - // METHOD getPageName - // WAS get_page_name - // PARAMS 1: strip page file name extension - // 0: keep filename as is - // 2: keep filename as is, but add dirname too - // RETURN filename - // DESCRIPTION - // get the page name of the curronte page: + // METHOD: getPageName + // WAS : get_page_name + // PARAMS: 1: strip page file name extension + // 0: keep filename as is + // 2: keep filename as is, but add dirname too + // RETURN: filename + // DESC : get the page name of the curronte page: public static function getPageName($strip_ext = 0) { // get the file info @@ -1073,27 +912,25 @@ class Basic } } - // METHOD getFilenameEnding - // WAS get_filename_ending - // PARAMS filename - // RETURN extension of the file name - // DESCRIPTION - // quick return the extension of the given file name + // METHOD: getFilenameEnding + // WAS : get_filename_ending + // PARAMS: filename + // RETURN: extension of the file name + // DESC : quick return the extension of the given file name public static function getFilenameEnding($filename) { $page_temp = pathinfo($filename); return $page_temp['extension']; } - // METHOD arraySearchRecursive - // WAS array_search_recursive - // PARAMS needle (search for) - // haystack (search in) - // key_lookin: the key to look out for, default empty - // RETURN array with the elements where the needle can be found in the haystack array - // DESCRIPTION - // searches key = value in an array / array - // only returns the first one found + // METHOD: arraySearchRecursive + // WAS : array_search_recursive + // PARAMS: needle (search for) + // haystack (search in) + // key_lookin: the key to look out for, default empty + // RETURN: array with the elements where the needle can be found in the haystack array + // DESC : searches key = value in an array / array + // only returns the first one found public static function arraySearchRecursive($needle, $haystack, $key_lookin = "") { $path = null; @@ -1105,15 +942,11 @@ class Basic } else { foreach ($haystack as $key => $val) { if (is_scalar($val) && $val === $needle && empty($key_lookin)) { -//echo "BAR FOUND $needle
"; - $path[] = $key; break; } elseif (is_scalar($val) && !empty($key_lookin) && $key === $key_lookin && $val == $needle) { -//echo "FOO FOUND $needle | $key | $val
"; $path[] = $key; break; - } elseif (is_array($val) && $path = basic::arraySearchRecursive($needle, $val, $key_lookin)) { -//echo "BAS FOUND $needle | ".print_r($path)."
"; + } elseif (is_array($val) && $path = Basic::arraySearchRecursive($needle, $val, $key_lookin)) { array_unshift($path, $key); break; } @@ -1122,15 +955,14 @@ class Basic return $path; } - // METHOD arraySearchRecursiveAll - // WAS array_search_recursive_all - // PARAMS needle (search for) - // haystack (search in) - // key: the key to look for in - // path: recursive call for previous path - // RETURN all array elements paths where the element was found - // DESCRIPTION - // recursive array search function, which returns all found not only the first one + // METHOD: arraySearchRecursiveAll + // WAS : array_search_recursive_all + // PARAMS: needle (search for) + // haystack (search in) + // key: the key to look for in + // path: recursive call for previous path + // RETURN: all array elements paths where the element was found + // DESC : recursive array search function, which returns all found not only the first one public static function arraySearchRecursiveAll($needle, $haystack, $key, $path = null) { if (!isset($path['level'])) { @@ -1159,7 +991,7 @@ class Basic // we will up a level $path['level'] += 1; // call recursive - $path = basic::arraySearchRecursiveAll($needle, $_value, $key, $path); + $path = Basic::arraySearchRecursiveAll($needle, $_value, $key, $path); } } // cut all that is >= level @@ -1169,12 +1001,11 @@ class Basic return $path; } - // METHOD arraySearchSimple - // WAS array_search_simple - // PARAMS array (search in), key (key to search in), value (what to find - // RETURN true on found, false on not found - // DESCRIPTION - // array search simple. looks for key, value combination, if found, returns true + // METHOD: arraySearchSimple + // WAS : array_search_simple + // PARAMS: array (search in), key (key to search in), value (what to find + // RETURN: true on found, false on not found + // DESC : array search simple. looks for key, value combination, if found, returns true public static function arraySearchSimple($array, $key, $value) { if (!is_array($array)) { @@ -1184,7 +1015,7 @@ class Basic // if value is an array, we search if (is_array($_value)) { // call recursive, and return result if it is true, else continue - if (($result = basic::arraySearchSimple($_value, $key, $value)) !== false) { + if (($result = Basic::arraySearchSimple($_value, $key, $value)) !== false) { return $result; } } elseif ($_key == $key && $_value = $value) { @@ -1195,12 +1026,11 @@ class Basic return false; } - // METHOD __mbMimeEncode - // WAS _mb_mime_encode - // PARAMS string to encode, encoding to encode in - // RETURN encoded string - // DESCRIPTION - // wrapper function for mb mime convert, for correct conversion with long strings + // METHOD: __mbMimeEncode + // WAS : _mb_mime_encode + // PARAMS: string to encode, encoding to encode in + // RETURN: encoded string + // DESC : wrapper function for mb mime convert, for correct conversion with long strings public static function __mbMimeEncode($string, $encoding) { // set internal encoding, so the mimeheader encode works correctly @@ -1229,11 +1059,11 @@ class Basic return $string; } - // METHOD byteStringFormat - // WAS ByteStringFormat - // PARAMS int bytes, boolean for space, default is set - // RETURN string - // DESC converts bytes into formated string with KB, MB, etc + // METHOD: byteStringFormat + // WAS : ByteStringFormat + // PARAMS: int bytes, boolean for space, default is set + // RETURN: string + // DESC : converts bytes into formated string with KB, MB, etc public static function byteStringFormat($number, $space = true) { if (is_numeric($number) && $number > 0) { @@ -1245,11 +1075,11 @@ class Basic return $number; } - // METHOD stringByteFormat - // WAS StringByteFormat - // PARAMS string - // RETURN int - // DESC calculates the bytes based on a string with nnG, nnM, etc + // METHOD: stringByteFormat + // WAS : StringByteFormat + // PARAMS: string + // RETURN: int + // DESC : calculates the bytes based on a string with nnG, nnM, etc public static function stringByteFormat($number) { $number = trim($number); @@ -1267,11 +1097,11 @@ class Basic return $number; } - // METHOD dateStringFormat - // WAS DateStringFormat - // PARAMS unix timestamp, true/false to show microtime - // RETURN string formated date+time in Y-M-D h:m:s - // DESC a simple wrapper for the date format + // METHOD: dateStringFormat + // WAS : DateStringFormat + // PARAMS: unix timestamp, true/false to show microtime + // RETURN: string formated date+time in Y-M-D h:m:s + // DESC : a simple wrapper for the date format public static function dateStringFormat($timestamp, $show_micro = true) { list ($timestamp, $ms) = explode('.', round($timestamp, 4)); @@ -1283,11 +1113,11 @@ class Basic return $string; } - // METHOD timeStringFormat - // WAS TimeStringFormat - // PARAMS seconds - // RETURN formated time string - // DESC formats a timestamp into time from. not a date + // METHOD: timeStringFormat + // WAS : TimeStringFormat + // PARAMS: seconds + // RETURN: formated time string + // DESC : formats a timestamp into time from. not a date public static function timeStringFormat($timestamp, $show_micro = true) { // check if the timestamp has any h/m/s/ms inside, if yes skip @@ -1319,11 +1149,11 @@ class Basic return $time_string; } - // METHOD stringToTime - // WAS StringToTime - // PARAMS TimeStringFormat string - // RETURN timestamp with microseconds - // DESC does a reverse of the TimeStringFormat and converts the string from + // METHOD: stringToTime + // WAS : StringToTime + // PARAMS: TimeStringFormat string + // RETURN: timestamp with microseconds + // DESC : does a reverse of the TimeStringFormat and converts the string from // xd xh xm xs xms to a timestamp.microtime format public static function stringToTime($timestring) { @@ -1346,11 +1176,11 @@ class Basic } } - // METHOD genAssocArray - // WAS GenAssocArray - // PARAMS db array, key, value part, flag if set all or only set - // RETURN returns and associative array - // DESC creates out of a normal db_return array an assoc array + // METHOD: genAssocArray + // WAS : GenAssocArray + // PARAMS: db array, key, value part, flag if set all or only set + // RETURN: returns and associative array + // DESC : creates out of a normal db_return array an assoc array public static function genAssocArray($db_array, $key, $value, $set_only = 0) { for ($i = 0; $i < count($db_array); $i ++) { @@ -1366,11 +1196,11 @@ class Basic return $ret_array; } - // METHOD checkDate - // WAS CheckDate - // PARAMS date (YYYY-MM-DD) - // RETURN true if valid date, false if date not valid - // DESC splits & checks date, wrap around for check_date function + // METHOD: checkDate + // WAS : CheckDate + // PARAMS: date (YYYY-MM-DD) + // RETURN: true if valid date, false if date not valid + // DESC : splits & checks date, wrap around for check_date function public static function checkDate($date) { list ($year, $month, $day) = preg_split("/[\/-]/", $date); @@ -1383,11 +1213,11 @@ class Basic return true; } - // METHOD checkDateTime - // WAS CheckDateTime - // PARAMS date (YYYY-MM-DD) + time (HH:MM:SS), SS can be dropped - // RETURN true if valid date, false if date not valid - // DESC splits & checks date, wrap around for check_date function + // METHOD: checkDateTime + // WAS : CheckDateTime + // PARAMS: date (YYYY-MM-DD) + time (HH:MM:SS), SS can be dropped + // RETURN: true if valid date, false if date not valid + // DESC : splits & checks date, wrap around for check_date function public static function checkDateTime($datetime) { list ($year, $month, $day, $hour, $min, $sec) = preg_split("/[\/\- :]/", $datetime); @@ -1406,11 +1236,11 @@ class Basic return true; } - // METHOD compareDate - // WAS CompareDate - // PARAMS start_date, end_date (both: YYYY-MM-DD) - // RETURN -1 if the first date is smaller the last, 0 if both are equal, 1 if the end date is bigger than the last - // DESC splits & checks date, wrap around for check_date function + // METHOD: compareDate + // WAS : CompareDate + // PARAMS: start_date, end_date (both: YYYY-MM-DD) + // RETURN: -1 if the first date is smaller the last, 0 if both are equal, 1 if the end date is bigger than the last + // DESC : splits & checks date, wrap around for check_date function public static function compareDate($start_date, $end_date) { // pre check for empty or wrong @@ -1448,11 +1278,11 @@ class Basic } } - // METHOD compareDateTime - // WAS CompareDateTime - // PARAMS start_datetime, end_datetime (both YYYY-MM-DD HH:mm:ss) - // RETURN -1 if the first date is smaller the last, 0 if both are equal, 1 if the end date is bigger than the last - // DESC compares the two dates + times. if seconds missing in one set, add :00, converts / to - + // METHOD: compareDateTime + // WAS : CompareDateTime + // PARAMS: start_datetime, end_datetime (both YYYY-MM-DD HH:mm:ss) + // RETURN: -1 if the first date is smaller the last, 0 if both are equal, 1 if the end date is bigger than the last + // DESC : compares the two dates + times. if seconds missing in one set, add :00, converts / to - public static function compareDateTime($start_datetime, $end_datetime) { // pre check for empty or wrong @@ -1472,11 +1302,11 @@ class Basic } } - // METHOD arrayToString - // WAS ArrayToString - // PARAMS array, connect char - // RETRUN string - // DESC wrapper for join, but checks if input is an array and if not returns null + // METHOD: arrayToString + // WAS : ArrayToString + // PARAMS: array, connect char + // RETRUN: string + // DESC : wrapper for join, but checks if input is an array and if not returns null public static function arrayToString($array, $connect_char) { if (is_array($array)) { @@ -1486,17 +1316,17 @@ class Basic } } - // METHOD createThumbnail - // WAS CreateThumbnail - // PARAMS pic -> picture where from we create a thumbnail - // x -> max x size of thumbnail - // y -> max y size of thumbnail - // dummy -> empty, or file_type to show an icon instead of nothing if file is not found - // path -> if source start is not ROOT path, if empty ROOT is choosen - // cache -> cache path, if not given TMP is used - // clear cache -> if set to true, will create thumb all the tame - // RETURN thumbnail name - // DESC converts picture to a thumbnail with max x and max y size + // METHOD: createThumbnail + // WAS : CreateThumbnail + // PARAMS: pic -> picture where from we create a thumbnail + // x -> max x size of thumbnail + // y -> max y size of thumbnail + // dummy -> empty, or file_type to show an icon instead of nothing if file is not found + // path -> if source start is not ROOT path, if empty ROOT is choosen + // cache -> cache path, if not given TMP is used + // clear cache -> if set to true, will create thumb all the tame + // RETURN: thumbnail name + // DESC : converts picture to a thumbnail with max x and max y size public static function createThumbnail($pic, $size_x, $size_y, $dummy = "", $path = "", $cache_source = "", $clear_cache = false) { // get image type flags @@ -1610,22 +1440,22 @@ class Basic return $this->checkConvertEncoding($string, $from_encoding, $to_encoding); } - // METHOD checkConvertEncoding - // PARAMS string: string to test - // from_encoding: source encoding of this string - // to_encoding: target encoding of this string - // RETURN false if no problem - // on error, return array with characters that failed in the convert - // DESC test if a string can be safely convert between encodings. mostly utf8 to shift jis - // the default compare has a possibility of failure, especially with windows - // it is recommended to the following in the script which uses this method: - // mb_substitute_character(0x2234); - // $class->mbErrorChar = '∴'; - // if check to Shift JIS - // if check to ISO-2022-JP - // if check to ISO-2022-JP-MS - // set three dots (∴) as wrong character for correct convert error detect - // (this char is used, because it is one of the least used ones) + // METHOD: checkConvertEncoding + // PARAMS: string: string to test + // from_encoding: source encoding of this string + // to_encoding: target encoding of this string + // RETURN: false if no problem + // on error, return array with characters that failed in the convert + // DESC : test if a string can be safely convert between encodings. mostly utf8 to shift jis + // the default compare has a possibility of failure, especially with windows + // it is recommended to the following in the script which uses this method: + // mb_substitute_character(0x2234); + // $class->mbErrorChar = '∴'; + // if check to Shift JIS + // if check to ISO-2022-JP + // if check to ISO-2022-JP-MS + // set three dots (∴) as wrong character for correct convert error detect + // (this char is used, because it is one of the least used ones) public function checkConvertEncoding($string, $from_encoding, $to_encoding) { // convert to target encoding and convert back @@ -1638,7 +1468,7 @@ class Basic $char = mb_substr($string, $i, 1, $from_encoding); $r_char = mb_substr($compare, $i, 1, $from_encoding); // the ord 194 is a hack to fix the IE7/IE8 bug with line break and illegal character -// $this->debug('CHECK CONVERTT', '['.$this->mbErrorChar.'] O: '.$char.', C: '.$r_char); + // $this->debug('CHECK CONVERTT', '['.$this->mbErrorChar.'] O: '.$char.', C: '.$r_char); if ((($char != $r_char && !$this->mbErrorChar) || ($char != $r_char && $r_char == $this->mbErrorChar && $this->mbErrorChar)) && ord($char) != 194) { $this->debug('CHARS', "'".$char."'".' == '.$r_char.' ('.ord($char).')'); $failed[] = $char; @@ -1672,11 +1502,11 @@ class Basic return $string; } - // METHOD __crc32b - // WAS _crc32b - // PARAMS string - // RETURN old (wrong) crc32b hash - // DESC checks php version and if >=5.2.7 it will flip the string + // METHOD: __crc32b + // WAS : _crc32b + // PARAMS: string + // RETURN: old (wrong) crc32b hash + // DESC : checks php version and if >=5.2.7 it will flip the string public function __crc32b($string) { // do normal hash crc32b @@ -1689,11 +1519,11 @@ class Basic return $string; } - // METHOD __sha1Short - // WAS _sha1_short - // PARAMS string, flag to use sha - // RETURN sha1 short (9 chars), but current calls __crc32b - // DESC replacement for __crc32b call + // METHOD: __sha1Short + // WAS : _sha1_short + // PARAMS: string, flag to use sha + // RETURN: sha1 short (9 chars), but current calls __crc32b + // DESC : replacement for __crc32b call public function __sha1Short($string, $use_sha = false) { if ($use_sha) { @@ -1703,13 +1533,13 @@ class Basic } } - // METHOD __hash - // WAS _hash - // PARAMS string, type of hash to use - // RETURN hashed string - // DESC replacemend for __crc32b call (alternate) - // defaults to adler 32, fnv132, fnv1a32, joaat - // all that create 8 char long hashes + // METHOD: __hash + // WAS : _hash + // PARAMS: string, type of hash to use + // RETURN: hashed string + // DESC : replacemend for __crc32b call (alternate) + // defaults to adler 32, fnv132, fnv1a32, joaat + // all that create 8 char long hashes public function __hash($string, $hash_type = 'adler32') { if (!in_array($hash_type, array('adler32', 'fnv132', 'fnv1a32', 'joaat'))) { @@ -1718,10 +1548,11 @@ class Basic return hash($hash_type, $string); } - // METHOD checkPHPVersion - // PARAMS $min_version: minimum version. in format x, x.y or x.y.z - // $max_version: default empty, else in same format as min version - // RETURN true if ok, false if not matching version + // METHOD: checkPHPVersion + // PARAMS: $min_version: minimum version. in format x, x.y or x.y.z + // $max_version: default empty, else in same format as min version + // RETURN: true if ok, false if not matching version + // DESC : checks if running PHP version matches given PHP version (min or max) public static function checkPHPVersion($min_version, $max_version = '') { // exit with false if the min/max strings are wrong @@ -1763,12 +1594,12 @@ class Basic return false; } - // METHOD cryptInit - // PARAMS none - // RETURN none - // DESC inits crypt settings for the crypt functions - // this function NEEDS (!) to be called BEFORE any of the crypt functions is called - // there is no auto init for this at the moment + // METHOD: cryptInit + // PARAMS: none + // RETURN: none + // DESC : inits crypt settings for the crypt functions + // this function NEEDS (!) to be called BEFORE any of the crypt functions is called + // there is no auto init for this at the moment private function cryptInit() { // SET CRYPT SALT PREFIX: @@ -1809,10 +1640,10 @@ class Basic } } - // METHOD cryptSaltString - // PARAMS random string length, default is 22 (for blowfish crypt) - // RETURN random string - // DESC creates a random string from alphanumeric characters: A-Z a-z 0-9 ./ + // METHOD: cryptSaltString + // PARAMS: random string length, default is 22 (for blowfish crypt) + // RETURN: random string + // DESC : creates a random string from alphanumeric characters: A-Z a-z 0-9 ./ private function cryptSaltString($nSize = 22) { // A-Z is 65,90 @@ -1836,10 +1667,10 @@ class Basic return $salt_string; } - // METHOD cryptString - // PARAMS string to be crypted (one way) - // RETURN encrypted string - // DESC encrypts the string with blowfish and returns the full string + salt part that needs to be stored somewhere (eg DB) + // METHOD: cryptString + // PARAMS: string to be crypted (one way) + // RETURN: encrypted string + // DESC : encrypts the string with blowfish and returns the full string + salt part that needs to be stored somewhere (eg DB) public function cryptString($string) { // the crypt prefix is set in the init of the class @@ -1847,11 +1678,11 @@ class Basic return crypt($string, $this->cryptSaltPrefix.$this->cryptSaltString($this->cryptSaltSize).$this->cryptSaltSuffix); } - // METHOD verifyCryptString - // PARAMS plain string (eg password) - // full crypted string (from cryptString - // RETURN true on matching or false for not matching - // DESC compares the string with the crypted one, is counter method to cryptString + // METHOD: verifyCryptString + // PARAMS: plain string (eg password) + // full crypted string (from cryptString + // RETURN: true on matching or false for not matching + // DESC : compares the string with the crypted one, is counter method to cryptString public function verifyCryptString($string, $crypt) { // the full crypted string needs to be passed on to the salt, so the init (for blowfish) and salt are passed on @@ -1864,10 +1695,10 @@ class Basic // *** COLORS *** - // METHOD hex2rgb - // PARAMS hexstring, flag to return as string (true/false), string seperator: default: , - // RETURN array with RGB or a string with the seperator - // DESC converts a hex RGB color to the int numbers + // METHOD: hex2rgb + // PARAMS: hexstring, flag to return as string (true/false), string seperator: default: , + // RETURN: array with RGB or a string with the seperator + // DESC : converts a hex RGB color to the int numbers public static function hex2rgb($hexStr, $returnAsString = false, $seperator = ',') { $hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); // Gets a proper hex string @@ -1889,10 +1720,10 @@ class Basic return $returnAsString ? implode($seperator, $rgbArray) : $rgbArray; // returns the rgb string or the associative array } - // METHOD rgb2hex - // PARAMS red, green, blue (0-255) - // RETURN string with hex rgb color plus # in front - // DESC converts the rgb values from int data to the valid rgb html hex string + // METHOD: rgb2hex + // PARAMS: red, green, blue (0-255) + // RETURN: string with hex rgb color plus # in front + // DESC : converts the rgb values from int data to the valid rgb html hex string public static function rgb2hex($red, $green, $blue) { $hex_color = '#'; @@ -1903,10 +1734,10 @@ class Basic return $hex_color; } - // METHOD rgb2hsb - // PARAMS red, green, blue (0-255) - // RETURN array with hue (0-360), sat (0-100%), brightness/value (0-100%) - // DESC converts RGB to HSB/V values + // METHOD: rgb2hsb + // PARAMS: red, green, blue (0-255) + // RETURN: array with hue (0-360), sat (0-100%), brightness/value (0-100%) + // DESC : converts RGB to HSB/V values public static function rgb2hsb($r, $g, $b) { // check that rgb is from 0 to 255 @@ -1938,10 +1769,10 @@ class Basic return array(round($HUE), round((($MAX - $MIN) / $MAX) * 100), round($MAX * 100)); } - // METHOD hsb2rgb - // PARAMS hue (0-360), saturation (0-1), brightness/value (0-1) - // RETURN array with red, blue, green - // DESC converts HSB/V to RGB values RGB is full INT + // METHOD: hsb2rgb + // PARAMS: hue (0-360), saturation (0-1), brightness/value (0-1) + // RETURN: array with red, blue, green + // DESC : converts HSB/V to RGB values RGB is full INT public static function hsb2rgb($H, $S, $V) { // check that H is 0 to 359, 360 = 0 @@ -2006,10 +1837,10 @@ class Basic return array(round($red * 255), round($gre * 255), round($blu * 255)); } - // METHOD rgb2hsl - // PARAMS red, blue, green (all 0-255) - // RETURN array with hue (0-360), saturation (0-100%) and luminance (0-100%) - // DESC converts a RGB (0-255) to HSL + // METHOD: rgb2hsl + // PARAMS: red, blue, green (all 0-255) + // RETURN: array with hue (0-360), saturation (0-100%) and luminance (0-100%) + // DESC : converts a RGB (0-255) to HSL public static function rgb2hsl($r, $g, $b) { // check that rgb is from 0 to 255 @@ -2048,12 +1879,12 @@ class Basic } } - // METHOD hsl2rgb - // PARAMS hue: 0-360 (degrees) - // saturation: 0-1 - // luminance: 0-1 - // RETURN array with RGB as full int - // DESC converts an HSL to RGB + // METHOD: hsl2rgb + // PARAMS: hue: 0-360 (degrees) + // saturation: 0-1 + // luminance: 0-1 + // RETURN: array with RGB as full int + // DESC : converts an HSL to RGB public static function hsl2rgb($h, $s, $l) { $h = (1 / 360) * $h; // calc to internal convert value for hue @@ -2085,10 +1916,10 @@ class Basic } } - // METHOD rgb2html - // PARAMS red, green, blue + // METHOD: rgb2html + // PARAMS: red, green, blue // RETRUN valid # prefix hex html color string - // DESC converts and int RGB to the HTML color string in hex format + // DESC : converts and int RGB to the HTML color string in hex format public static function rgb2html($red, $green, $blue) { // check that each color is between 0 and 255 @@ -2105,12 +1936,13 @@ class Basic return '#'.$red.$green.$blue; } - // METHOD inArrayAny - // WAS in_array_any - // PARAMS needle: array - // haystack: array - // RETURN found elements: array - // DESC search for the needle array elements in haystack and return the ones found as an array, is there nothing found, it returns FALSE (boolean) + // METHOD: inArrayAny + // WAS : in_array_any + // PARAMS: needle: array + // haystack: array + // RETURN: found elements: array + // DESC : search for the needle array elements in haystack and return the ones found as an array, + // is there nothing found, it returns FALSE (boolean) public static function inArrayAny($needle, $haystack) { if (!is_array($needle)) { @@ -2132,11 +1964,11 @@ class Basic } } - // METHOD getEmailType - // PARAMS email, short == false - // RETURN string for email type, eg "pc", "docomo", etc - // DESC guesses the email type (mostly for mobile) from the domain - // if second is set to true, it will return short naming scheme (only provider) + // METHOD: getEmailType + // PARAMS: email, short == false + // RETURN: string for email type, eg "pc", "docomo", etc + // DESC : guesses the email type (mostly for mobile) from the domain + // if second is set to true, it will return short naming scheme (only provider) public function getEmailType($email, $short = false) { // trip if there is no email address @@ -2161,21 +1993,21 @@ class Basic } } - // METHOD getShortEmailType - // PARAMS long email type (not email) - // RETURN short email type - // DESC gets the short email type from a long email type + // METHOD: getShortEmailType + // PARAMS: long email type (not email) + // RETURN: short email type + // DESC : gets the short email type from a long email type public function getShortEmailType($email_type) { return $this->mobile_email_type_short[$email_type]; } - // METHOD printDateTime - // PARAMS year, month, day, hour, min: the date and time values - // suffix: additional info printed after the date time variable in the drop down, also used for ID in the on change JS call - // min_steps: default is 1 (minute), can set to anything, is used as sum up from 0 - // RETURN HTML formated strings for drop down lists of date and time - // DESC print the date/time drop downs, used in any queue/send/insert at date/time place + // METHOD: printDateTime + // PARAMS: year, month, day, hour, min: the date and time values + // suffix: additional info printed after the date time variable in the drop down, also used for ID in the on change JS call + // min_steps: default is 1 (minute), can set to anything, is used as sum up from 0 + // RETURN: HTML formated strings for drop down lists of date and time + // DESC : print the date/time drop downs, used in any queue/send/insert at date/time place public static function printDateTime($year, $month, $day, $hour, $min, $suffix = '', $min_steps = 1) { // if suffix given, add _ before @@ -2232,19 +2064,19 @@ class Basic return $string; } - // METHOD htmlent - // PARAMS string to encode - // RETURN encoded string - // DESC full wrapper for html entities + // METHOD: htmlent + // PARAMS: string to encode + // RETURN: encoded string + // DESC : full wrapper for html entities public function htmlent($string) { return htmlentities($string, ENT_COMPAT|ENT_HTML401, 'UTF-8', false); } - // METHOD setFormToken - // PARAMS session name, if not set then default is form_token - // RETURN form token - // DESC sets a form token in a session and returns form token + // METHOD: setFormToken + // PARAMS: session name, if not set then default is form_token + // RETURN: form token + // DESC : sets a form token in a session and returns form token public function setFormToken($name = 'form_token') { // current hard set to sha256 @@ -2253,14 +2085,164 @@ class Basic return $token; } - // METHOD validateFormToken - // PARAMS form token, session name (default form_token) - // RETURN true or false - // DESC checks if the form token matches the session set form token + // METHOD: validateFormToken + // PARAMS: form token, session name (default form_token) + // RETURN: true or false + // DESC : checks if the form token matches the session set form token public function validateFormToken($token, $name = 'form_token') { return $_SESSION[$name] === $token; } + + // ************************************************************* + // COMPATIBILITY METHOD:S + // those methods are deprecated function call names + // they exist for backwards compatibility only + // ************************************************************* + + public function running_time($simple = false) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->runningTime($simple); + } + + public static function print_time($set_microtime = -1) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return Basic::printTime($set_microtime); + } + + private function fdebug_fp($flag = '') + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->fdebugFP($flag); + } + + public function debug_for($type, $flag) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->debugFor($type, $flag); + } + + public function get_caller_method($level = 2) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->getCallerMethod($level); + } + + public function merge_errors($error_msg = array ()) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->mergeErrors($error_msg); + } + + public function print_error_msg($string = '') + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->printErrorMsg($string); + } + + private function write_error_msg($level, $error_string) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->writeErrorMsg($level, $error_string); + } + + public function reset_error_msg($level = '') + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->resetErrorMsg($level); + } + + public static function print_ar($array) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return Basic::printAr($array); + } + + public function magic_links($string, $target = "_blank") + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->magicLinks($string, $target); + } + + private function create_url($href, $atag, $_1, $_2, $_3, $name, $class) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->createUrl($href, $atag, $_1, $_2, $_3, $name, $class); + } + + private function create_email($mailto, $atag, $_1, $_2, $_3, $title, $class) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->createEmail($mailto, $atag, $_1, $_2, $_3, $title, $class); + } + + public function get_host_name() + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->getHostName(); + } + + public static function get_page_name($strip_ext = 0) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return Basic::getPageName($strip_ext); + } + + public static function get_filename_ending($filename) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return Basic::getFilenameEnding($filename); + } + + public static function array_search_recursive($needle, $haystack, $key_lookin = "") + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return Basic::arraySearchRecursive($needle, $haystack, $key_lookin); + } + + public static function array_search_recursive_all($needle, $haystack, $key, $path = null) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return Basic::arraySearchRecursiveAll($needle, $haystack, $key, $path); + } + + public static function array_search_simple($array, $key, $value) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return Basic::arraySearchSimple($array, $key, $value); + } + + public static function _mb_mime_encode($string, $encoding) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return Basic::__mbMimeEncode($string, $encoding); + } + + public function _crc32b($string) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->__crc32b($string); + } + + public function _sha1_short($string, $use_sha = false) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->__sha1Short($string, $use_sha); + } + + public function _hash($string, $hash_type = 'adler32') + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->__hash($string, $hash_type); + } + + public static function in_array_any($needle, $haystack) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return Basic::inArrayAny($needle, $haystack); + } } # __END__ diff --git a/www/lib/CoreLibs/DB/Extended/ArrayIO.inc b/www/lib/CoreLibs/DB/Extended/ArrayIO.inc index 70a9fcbe..0a2d12fb 100644 --- a/www/lib/CoreLibs/DB/Extended/ArrayIO.inc +++ b/www/lib/CoreLibs/DB/Extended/ArrayIO.inc @@ -4,7 +4,7 @@ * CREATED: 2002/12/17 * VERSION: 0.4.0 * RELEASED LICENSE: GNU GPL 3 -* SHORT DESCRIPTION: +* SHORT DESC :RIPTION: * DB Array IO Class: * writes, reads or deletes a complete array (one data set) in/out a * table from the connected DB. @@ -14,9 +14,9 @@ * * PRIVATE VARIABLES * -* PUBLIC METHODS +* PUBLIC METHOD:S * -* PRIVATE METHODS +* PRIVATE METHOD:S * * HISTORY: * 2005/07/07 (cs) updated array class for postgres: set 0 & NULL if int field given, insert uses () values () syntax @@ -36,11 +36,10 @@ // as it actually has nothing to do with this one here ? (or at least // put into separete function in this class) -// try to include file from LIBS path, or from normal path -_spl_autoload('Class.DB.IO.inc'); +namespace CoreLibs\DB\Extended; // subclass for one array handling -class db_array_io extends db_io +class ArrayIO extends \CoreLibs\DB\IO { // main calss variables public $table_array; // the array from the table to work on @@ -48,14 +47,14 @@ class db_array_io extends db_io public $pk_name; // the primary key from this table public $pk_id; // the PK id - // METHOD db_array_io - // PARAMS db_config -> db_io class init vars - // table_array -> the array from the table - // table_name -> name of the table (for the array) - // db_debug -> turn on db_io debug output (DB_DEBUG as global var does the same) - // RETURN none - // DESC constructor for the array io class, set the - // primary key name automatically (from array) + // METHOD: db_array_io + // PARAMS: db_config -> db_io class init vars + // table_array -> the array from the table + // table_name -> name of the table (for the array) + // db_debug -> turn on db_io debug output (DB_DEBUG as global var does the same) + // RETURN: none + // DESC : constructor for the array io class, set the + // primary key name automatically (from array) public function __construct($db_config, $table_array, $table_name, $debug = 0, $db_debug = 0, $echo = 1, $print = 0) { // instance db_io class @@ -90,14 +89,15 @@ class db_array_io extends db_io parent::__destruct(); } - // METHOD convert_data - // PARAMS string -> the string that should be changed - // RETURN string -> the altered string - // DESC changes all previously alterd HTML code into visible one, - // works for ,, and (thought can be / or should - // be handled with the magic links functions - // used with the read function - public function convert_data($text) + // METHOD: convertData + // WAS : convert_data + // PARAMS: string -> the string that should be changed + // RETURN: string -> the altered string + // DESC : changes all previously alterd HTML code into visible one, + // works for ,, and (thought can be / or should + // be handled with the magic links functions + // used with the read function + public function convertData($text) { $text = str_replace('<b>', '', $text); $text = str_replace('</b>', '', $text); @@ -110,11 +110,12 @@ class db_array_io extends db_io return $text; } - // METHOD convert_entities - // PARAMS string -> string to be changed - // RETURN string -> altered string - // DESC changeds all HTML entities into non HTML ones - public function convert_entities($text) + // METHOD: convertEntities + // WAS : convert_entities + // PARAMS: string -> string to be changed + // RETURN: string -> altered string + // DESC : changeds all HTML entities into non HTML ones + public function convertEntities($text) { $text = str_replace('<', '<', $text); $text = str_replace('>', '>', $text); @@ -124,11 +125,12 @@ class db_array_io extends db_io return $text; } - // METHOD db_dump_array - // PARAMS none - // RETURN returns the current array - // DESC dumps the current data - public function db_dump_array($write = 0) + // METHOD: dbDumpArray + // WAS : db_dump_array + // PARAMS: none + // RETURN: returns the current array + // DESC : dumps the current data + public function dbDumpArray($write = 0) { reset($this->table_array); while (list($column, $data_array) = each($this->table_array)) { @@ -141,24 +143,12 @@ class db_array_io extends db_io return $string; } - // METHOD _db_error - // PARAMS none - // RETURN none - // DESC writes errors to internal error string -/* function _db_error() - { - // if error occured - if ($this->error_id) - { - $this->error_msg['db'] .= "-DB_ARRAY-error-> ".$this->error_id.": ".$this->error_string[$this->error_id]."
"; - } - } */ - - // METHOD db_check_pk_set - // PARAMS none - // RETURN none - // DESC checks if pk is set and if not, set from pk_id and if this also not set return 0 - public function db_check_pk_set() + // METHOD: dbCheckPkSet + // WAS : db_check_pk_set + // PARAMS: none + // RETURN: none + // DESC : checks if pk is set and if not, set from pk_id and if this also not set return 0 + public function dbCheckPkSet() { // if pk_id is set, overrule ... if ($this->pk_id) { @@ -168,18 +158,19 @@ class db_array_io extends db_io if (!$this->table_array[$this->pk_name]["value"]) { // if no PK found, error ... $this->error_id = 21; - $this->_db_error(); + $this->__dbError(); return 0; } else { return 1; } } - // METHOD db_reset_array - // PARAMS reset_pk -> if set reset the pk too - // RETURN none - // DESC resets the whole array - public function db_reset_array($reset_pk = 0) + // METHOD: dbResetArray + // WAS : db_reset_array + // PARAMS: reset_pk -> if set reset the pk too + // RETURN: none + // DESC : resets the whole array + public function dbResetArray($reset_pk = 0) { reset($this->table_array); while (list($column, $data_array) = each($this->table_array)) { @@ -191,16 +182,17 @@ class db_array_io extends db_io } } - // METHOD db_delete - // PARAMS optional the table_array, if not given uses class var - // RETURN 1 for successfull delete or 0 for error - // DESC deletes one dataset - public function db_delete($table_array = 0) + // METHOD: dbDelete + // WAS : db_delete + // PARAMS: optional the table_array, if not given uses class var + // RETURN: 1 for successfull delete or 0 for error + // DESC : deletes one dataset + public function dbDelete($table_array = 0) { if (is_array($table_array)) { $this->table_array = $table_array; } - if (!$this->db_check_pk_set()) { + if (!$this->dbCheckPkSet()) { return $this->table_array; } // delete query @@ -209,7 +201,7 @@ class db_array_io extends db_io // delete files and build FK query reset($this->table_array); while (list($column, $data_array) = each($this->table_array)) { - // suchen nach bildern und löschen ... + // suchen nach bildern und lschen ... if ($this->table_array[$column]["file"] && file_exists($this->table_array[$column]["url"].$this->table_array[$column]["value"])) { if (file_exists($this->table_array[$column]["path"].$this->table_array[$column]["value"])) { unlink($this->table_array[$column]["path"].$this->table_array[$column]["value"]); @@ -227,7 +219,7 @@ class db_array_io extends db_io } $q_where .= $column." = ".$this->table_array[$column]["value"]; } - // allgemeines zurücksetzen des arrays + // allgemeines zurcksetzen des arrays unset($this->table_array[$column]["value"]); } @@ -237,24 +229,25 @@ class db_array_io extends db_io } // if 0, error unset($this->pk_id); - if (!$this->db_exec($q)) { + if (!$this->dbExec($q)) { $this->error_id=22; - $this->_db_error(); + $this->__dbError(); } return $this->table_array; } - // METHOD db_read - // PARAMS edit -> if 1 data will not be altered for output, optional the table_array, if not given uses class var - // RETURN true or false for reading - // DESC reads one row into the array - public function db_read($edit = 0, $table_array = 0) + // METHOD: dbRead + // WAS : db_read + // PARAMS: edit -> if 1 data will not be altered for output, optional the table_array, if not given uses class var + // RETURN: true or false for reading + // DESC : reads one row into the array + public function dbRead($edit = 0, $table_array = 0) { // if array give, overrules internal array if (is_array($table_array)) { $this->table_array = $table_array; } - if (!$this->db_check_pk_set()) { + if (!$this->dbCheckPkSet()) { return $this->table_array; } reset($this->table_array); @@ -283,12 +276,12 @@ class db_array_io extends db_io } // if query was executed okay, else set error - if ($this->db_exec($q)) { - if ($res = $this->db_fetch_array()) { + if ($this->dbExec($q)) { + if ($res = $this->dbFetchArray()) { reset($this->table_array); while (list($column, $data_array) = each($this->table_array)) { - // wenn "edit" dann gib daten wie in DB zurück, ansonten aufbereiten für ausgabe - // ?? sollte das nicht draußen ??? man weis ja net was da drin steht --> is noch zu überlegen + // wenn "edit" dann gib daten wie in DB zurck, ansonten aufbereiten fr ausgabe + // ?? sollte das nicht drauen ??? man weis ja net was da drin steht --> is noch zu berlegen // echo "EDIT: $edit | Spalte: $column | type: ".$this->table_array[$column]["type"]." | Res: ".$res[$column]."
"; if ($edit) { $this->table_array[$column]["value"] = $res[$column]; @@ -297,25 +290,26 @@ class db_array_io extends db_io $this->table_array[$column]["HIDDEN_value"] = $res[$column]; } } else { - $this->table_array[$column]["value"] = $this->convert_data(nl2br($res[$column])); + $this->table_array[$column]["value"] = $this->convertData(nl2br($res[$column])); // had to put out the htmlentities from the line above as it breaks japanese characters } } } - // possible db_fetch_array errors ... + // possible dbFetchArray errors ... $this->pk_id = $this->table_array[$this->pk_name]["value"]; } else { $this->error_id = 22; - $this->_db_error(); + $this->__dbError(); } return $this->table_array; } - // METHOD db_write - // PARAMS addslashes -> if 1 will make an addslashes for each array field, optional the table_array, if not given uses class var - // RETURN true or false on write - // DESC writes on set into DB or updates one set (if PK exists) - public function db_write($addslashes = 0, $table_array = 0) + // METHOD: dbWrite + // WAS : db_write + // PARAMS: addslashes -> if 1 will make an addslashes for each array field, optional the table_array, if not given uses class var + // RETURN: true or false on write + // DESC : writes on set into DB or updates one set (if PK exists) + public function dbWrite($addslashes = 0, $table_array = 0) { if (is_array($table_array)) { $this->table_array = $table_array; @@ -427,9 +421,9 @@ class db_array_io extends db_io $q_data .= "'"; // if add slashes do convert & add slashes else write AS is if ($addslashes) { - $q_data .= $this->db_escape_string($this->convert_entities($this->table_array[$column]["value"])); + $q_data .= $this->dbEscapeString($this->convertEntities($this->table_array[$column]["value"])); } else { - $q_data .= $this->db_escape_string($this->table_array[$column]["value"]); + $q_data .= $this->dbEscapeString($this->table_array[$column]["value"]); } $q_data .= "'"; } @@ -454,7 +448,7 @@ class db_array_io extends db_io if (!$this->table_array[$this->pk_name]["value"]) { // max id, falls INSERT $q = "SELECT MAX(".$this->pk_name.") + 1 AS pk_id FROM ".$this->table_name; - $res = $this->db_return_row($q); + $res = $this->dbReturnRow($q); if (!$res["pk_id"]) { $res["pk_id"] = 1; } @@ -482,9 +476,9 @@ class db_array_io extends db_io // $this->pk_id = $this->table_array[$this->pk_name]["value"]; } // return success or not - if (!$this->db_exec($q)) { + if (!$this->dbExec($q)) { $this->error_id = 22; - $this->_db_error(); + $this->__dbError(); } // set primary key if ($insert) { @@ -494,4 +488,60 @@ class db_array_io extends db_io // return the table if needed return $this->table_array; } + + // ************************************************************* + // COMPATIBILITY METHODS + // those methods are deprecated function call names + // they exist for backwards compatibility only + // ************************************************************* + + public function convert_data($text) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->convertData($text); + } + + public function convert_entities($text) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->convertEntities($text); + } + + public function db_dump_array($write = 0) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbDumpArray($write); + } + + public function db_check_pk_set() + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbCheckPkSet(); + } + + public function db_reset_array($reset_pk = 0) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbResetArray($reset_pk); + } + + public function db_delete($table_array = 0) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbDelete($table_array); + } + + public function db_read($edit = 0, $table_array = 0) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbRead($edit, $table_array); + } + + public function db_write($addslashes = 0, $table_array = 0) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbWrite($addslashes, $table_array); + } } // end of class + +# __END__ diff --git a/www/lib/CoreLibs/DB/IO.inc b/www/lib/CoreLibs/DB/IO.inc index 66bb73b5..13e2bf54 100644 --- a/www/lib/CoreLibs/DB/IO.inc +++ b/www/lib/CoreLibs/DB/IO.inc @@ -2,9 +2,12 @@ /******************************************************************** * AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org) * CREATED: 2000/11/23 -* VERSION: 4.1.0 +* VERSION: 5.0.0 * RELEASED LICENSE: GNU GPL 3 * SHORT DESCRIPTON: +* 2018/3/23, the whole class system is transformed to namespaces +* also all internal class calls are converted to camel case +* * 2013/10/10, prepare/excute were added, including auto RETURNING primary key if * possible for any INSERT query in exec or prepare/execute, better debugging and * data dumping. Proper string escape wrapper, special db exec writer for complex @@ -238,10 +241,9 @@ * 23.11.2000: erster Test *********************************************************************/ -// try to include file from LIBS path, or from normal path -_spl_autoload('Class.Basic.inc'); +namespace CoreLibs\DB; -class db_io extends basic +class IO extends \CoreLibs\Basic { // recommend to set private/protected and only allow setting via method // can bet set from outside @@ -354,20 +356,28 @@ class db_io extends basic $this->db_debug = $GLOBALS['DB_DEBUG']; } - // includes sub class for db type - _spl_autoload($this->db_type.'.inc'); - $this->db_functions = new $this->db_type(); + // based on $this->db_type + // here we need to load the db pgsql include one + // How can we do this dynamic? eg for non PgSQL + // OTOH this whole class is so PgSQL specific + // that non PgSQL doesn't make much sense anymore + if ($this->db_type == 'pg_sql') { + $this->db_functions = new \CoreLibs\DB\SQL\PgSQL(); + } else { + // abort error + return "Failed to load DB functions for: ".$this->db_type; + } // connect to DB - if (!$this->_connect_to_db()) { + if (!$this->__connectToDB()) { $this->error_id = 16; - $this->_db_error(); + $this->__dbError(); return false; } $this->class_info['db_io']=array( 'class_name' => 'DB IO', - 'class_version' => '4.1.0', + 'class_version' => '5.0.0', 'class_created' => '2000-11-23', 'class_author' => 'Clemens Schwaighofer' ); @@ -379,7 +389,7 @@ class db_io extends basic // DESC: final desctruct method, closes the DB connection public function __destruct() { - $this->_close_db(); + $this->__closeDB(); parent::__destruct(); } @@ -387,60 +397,63 @@ class db_io extends basic // PRIVATE METHODS // ************************************************************* - // METHOD: _connect_to_db + // METHOD: __connectToDB + // WAS : _connect_to_db // PARAMS: none // RETURN: true on successfull connect, false if failed - // DESC: + // DESC : // internal connection function. Used to connect to the DB if there is no connection done yet. // Called before any execute - private function _connect_to_db() + private function __connectToDB() { // generate connect string - $this->dbh = $this->db_functions->_db_connect($this->db_host, $this->db_user, $this->db_pwd, $this->db_name, $this->db_port, $this->db_ssl); + $this->dbh = $this->db_functions->__dbConnect($this->db_host, $this->db_user, $this->db_pwd, $this->db_name, $this->db_port, $this->db_ssl); // if no dbh here, we couldn't connect to the DB itself if (!$this->dbh) { $this->error_id = 14; - $this->_db_error(); + $this->__dbError(); return false; } // 15 error (cant select to DB is not valid in postgres, as connect is different) // if returns 0 we couldn't select the DB if ($this->dbh == -1) { $this->error_id = 15; - $this->_db_error(); + $this->__dbError(); return false; } // set search path if needed if ($this->db_schema) { - $this->db_set_schema(); + $this->dbSetSchema(); } // set client encoding if ($this->db_encoding) { - $this->db_set_encoding(); + $this->dbSetEncoding(); } // all okay return true; } - // METHOD: _close_db + // METHOD: __closeDB + // WAS : _close_db // PARAMS: none // RETURN: none // DESC : close db connection // only used by the deconstructor - private function _close_db() + private function __closeDB() { if (isset($this->dbh) && $this->dbh) { - $this->db_functions->_db_close(); + $this->db_functions->__dbClose(); unset($this->dbh); } } - // METHOS: _check_query_for_select + // METHOD: __checkQueryForSelect + // WAS : _check_query_for_select // PARAMS: query // RETURN: true if matching, false if not // DESC : checks if query is a SELECT, if not error, 0 return - // : NOTE: Query needs to start with SELECT. if starts with "with" it is ignored - private function _check_query_for_select($query) + // NOTE : Query needs to start with SELECT. if starts with "with" it is ignored + private function __checkQueryForSelect($query) { // perhaps allow spaces before select ?!? if (!preg_match("/^select /i", $query)) { @@ -449,13 +462,14 @@ class db_io extends basic return true; } - // METHOD: _check_query_for_insert + // METHOD: __checkQueryForInsert + // WAS : _check_query_for_insert // PARAMS: query, pure flag (boolean) // RETURN: true if matching, flase if not // DESC : check for DELETE, INSERT, UPDATE // : if pure is set to true, only when INSERT is set will return true - // : NOTE: Queries need to start with INSERT, UPDATE, DELETE. Anything else is ignored - private function _check_query_for_insert($query, $pure = false) + // NOTE : Queries need to start with INSERT, UPDATE, DELETE. Anything else is ignored + private function __checkQueryForInsert($query, $pure = false) { if (!preg_match("/^insert /i", $query) && !preg_match("/^update /i", $query) && !preg_match("/^delete /i", $query)) { return false; @@ -469,19 +483,20 @@ class db_io extends basic } } - // METHOD: _print_array + // METHOD: __printArray + // WAS : _print_array // PARAMS: array to print // RETURN: string with printed and formated array // DESC : internal funktion that creates the array - // : used in db_dump_data only - private function _print_array($array) + // NOTE : used in db_dump_data only + private function __printArray($array) { while (list($key, $value) = each($array)) { $string .= $this->nbsp.''.$key.' => '; if (is_array($value)) { $this->nbsp .= '   '; $string .= '
'; - $string .= $this->_print_array($value); + $string .= $this->__printArray($value); } else { $string .= $value.'
'; } @@ -490,14 +505,15 @@ class db_io extends basic return $string; } - // METHOD _db_debug - // PARAMS debug_id -> group id for debug - // error_string -> error message or debug data - // id -> db debug group - // type -> query identifiery (Q, I, etc) - // RETURN none - // DESC calls the basic class debug with strip command - private function _db_debug($debug_id, $error_string, $id = '', $type = '') + // METHOD: __dbDebug + // WAS : _db_debug + // PARAMS: debug_id -> group id for debug + // error_string -> error message or debug data + // id -> db debug group + // type -> query identifiery (Q, I, etc) + // RETURN: none + // DESC : calls the basic class debug with strip command + private function __dbDebug($debug_id, $error_string, $id = '', $type = '') { $prefix = ''; if ($id) { @@ -512,34 +528,35 @@ class db_io extends basic $this->debug($debug_id, $prefix.$error_string, true); } - // METHOD _db_error - // PARAMS cursor -> current cursor for pg_result_error, mysql uses dbh, pg_last_error too, - // but pg_result_error is more accurate - // msg -> optional message - // RETURN none - // DESC if error_id set, writes long error string into error_msg - // MARK: needed to make public so it can be called from DB.Array.IO too - public function _db_error($cursor = '', $msg = '') + // METHOD: __dbError + // WAS : _db_error + // PARAMS: cursor -> current cursor for pg_result_error, mysql uses dbh, pg_last_error too, + // but pg_result_error is more accurate + // msg -> optional message + // RETURN: none + // DESC : if error_id set, writes long error string into error_msg + // NOTE : needed to make public so it can be called from DB.Array.IO too + public function __dbError($cursor = '', $msg = '') { $where_called = $this->get_caller_method(); if ($cursor) { - $pg_error_string = $this->db_functions->_db_print_error($cursor); + $pg_error_string = $this->db_functions->__dbPrintError($cursor); } if (!$cursor) { - $pg_error_string = $this->db_functions->_db_print_error(); + $pg_error_string = $this->db_functions->__dbPrintError(); } if ($pg_error_string) { - $this->_db_debug('db', $pg_error_string, 'DB_ERROR', $where_called); + $this->__dbDebug('db', $pg_error_string, 'DB_ERROR', $where_called); } // okay, an error occured if ($this->error_id) { // write error msg ... - $this->_db_debug('db', 'DB-Error '.$this->error_id.': '.$this->error_string[$this->error_id].($msg ? ', '.$msg : '').'', 'DB_ERROR', $where_called); + $this->__dbDebug('db', 'DB-Error '.$this->error_id.': '.$this->error_string[$this->error_id].($msg ? ', '.$msg : '').'', 'DB_ERROR', $where_called); $this->had_error = $this->error_id; // write detailed error log } if ($this->warning_id) { - $this->_db_debug('db', 'DB-Warning '.$this->warning_id.': '.$this->error_string[$this->warning_id].($msg ? ', '.$msg : '').'', 'DB_ERROR', $where_called); + $this->__dbDebug('db', 'DB-Warning '.$this->warning_id.': '.$this->error_string[$this->warning_id].($msg ? ', '.$msg : '').'', 'DB_ERROR', $where_called); $this->had_warning = $this->warning_id; } // unset the error/warning vars @@ -547,11 +564,12 @@ class db_io extends basic $this->warning_id = 0; } - // METHOD _db_convert_encoding - // PARAMS array from fetch_row - // RETURN convert fetch_row array - // DESC if there is the 'to_encoding' var set, and the field is in the wrong encoding converts it to the target - private function _db_convert_encoding($row) + // METHOD: __dbConvertEncoding + // WAS : _db_convert_encoding + // PARAMS: array from fetch_row + // RETURN: convert fetch_row array + // DESC : if there is the 'to_encoding' var set, and the field is in the wrong encoding converts it to the target + private function __dbConvertEncoding($row) { if ($this->to_encoding && $this->db_encoding) { // go through each row and convert the encoding if needed @@ -566,11 +584,12 @@ class db_io extends basic return $row; } - // METHOD _db_debug_prepare - // PARAMS $stm_name, data array - // RETURN query in prepared form - // DESC for debug purpose replaces $1, $2, etc with actual data - private function _db_debug_prepare($stm_name, $data = array()) + // METHOD: __dbDebugPrepare + // WAS : _db_debug_prepare + // PARAMS: $stm_name, data array + // RETURN: query in prepared form + // DESC : for debug purpose replaces $1, $2, etc with actual data + private function __dbDebugPrepare($stm_name, $data = array()) { // get the keys from data array $keys = array_keys($data); @@ -582,11 +601,12 @@ class db_io extends basic return str_replace(array_reverse($keys), array_reverse($data), $this->prepare_cursor[$stm_name]['query']); } - // METHOD _db_return_table - // PARAMS insert/select/update/delete query - // RETURN array with schema and table - // DESC extracts schema and table from the query, if no schema returns just empty string - private function _db_return_table($query) + // METHOD: __dbReturnTable + // WAS : _db_return_table + // PARAMS: insert/select/update/delete query + // RETURN: array with schema and table + // DESC : extracts schema and table from the query, if no schema returns just empty string + private function __dbReturnTable($query) { if (preg_match("/^SELECT /i", $query)) { preg_match("/ (FROM) (([\w_]+)\.)?([\w_]+) /i", $query, $matches); @@ -596,17 +616,18 @@ class db_io extends basic return array($matches[3], $matches[4]); } - // METHOD _db_prepare_exec - // PARAMS query, primary key [if set to NULL no returning will be added] - // RETURN md5 OR boolean false on error - // DESC sub function for db_exec and db_exec_async - // * checks query is set - // * checks there is a database handler - // * checks that here is no other query executing - // * checks for insert if returning is set/pk name - // * sets internal md5 for query - // * checks multiple call count - private function _db_prepare_exec($query, $pk_name) + // METHOD: __dbPrepareExec + // WAS : _db_prepare_exec + // PARAMS: query, primary key [if set to NULL no returning will be added] + // RETURN: md5 OR boolean false on error + // DESC : sub function for db_exec and db_exec_async + // * checks query is set + // * checks there is a database handler + // * checks that here is no other query executing + // * checks for insert if returning is set/pk name + // * sets internal md5 for query + // * checks multiple call count + private function __dbPrepareExec($query, $pk_name) { // to either use the returning method or the guess method for getting primary keys $this->returning_id = false; @@ -616,33 +637,33 @@ class db_io extends basic } if (!$this->query) { $this->error_id = 11; - $this->_db_error(); + $this->__dbError(); return false; } // if no DB Handler drop out if (!$this->dbh) { // if reconnect fails drop out - if (!$this->_connect_to_db()) { + if (!$this->__connectToDB()) { $this->error_id = 16; - $this->_db_error(); + $this->__dbError(); return false; } } // check that no other query is running right now - if ($this->db_functions->_db_connection_busy()) { + if ($this->db_functions->__dbConnection_busy()) { $this->error_id = 41; - $this->_db_error(); + $this->__dbError(); return false; } // if we do have an insert, check if there is no RETURNING pk_id, add it if I can get the PK id - if ($this->_check_query_for_insert($this->query, true)) { + if ($this->__checkQueryForInsert($this->query, true)) { $this->pk_name = $pk_name; if ($this->pk_name != 'NULL') { if (!$this->pk_name) { // TODO: get primary key from table name - list($schema, $table) = $this->_db_return_table($this->query); + list($schema, $table) = $this->__dbReturnTable($this->query); if (!array_key_exists($table, $this->pk_name_table) || !$this->pk_name_table[$table]) { - $this->pk_name_table[$table] = $this->db_functions->_db_primary_key($table, $schema); + $this->pk_name_table[$table] = $this->db_functions->__dbPrimaryKey($table, $schema); } $this->pk_name = $this->pk_name_table[$table] ? $this->pk_name_table[$table] : 'NULL'; } @@ -662,7 +683,7 @@ class db_io extends basic } // for DEBUG, only on first time ;) if ($this->db_debug) { - $this->_db_debug('db', $this->query, '_db_prepare_exec', 'Q'); + $this->__dbDebug('db', $this->query, '__dbPrepareExec', 'Q'); } // import protection, md5 needed $md5 = md5($this->query); @@ -677,8 +698,8 @@ class db_io extends basic // count up the run, if this is run more than the max_run then exit with error if ($this->query_called[$md5] > $this->MAX_QUERY_CALL) { $this->error_id = 30; - $this->_db_error(); - $this->_db_debug('db', $this->query, 'db_exec', 'Q[nc]'); + $this->__dbError(); + $this->__dbDebug('db', $this->query, 'dbExec', 'Q[nc]'); return false; } $this->query_called[$md5] ++; @@ -686,51 +707,52 @@ class db_io extends basic return $md5; } - // METHOD _db_post_exec - // PARAMS none - // RETURN true on success or false if an error occured - // DESC runs post execute for rows affected, field names, inserted primary key, etc - private function _db_post_exec() + // METHOD: __dbPostExec + // WAS : _db_post_exec + // PARAMS: none + // RETURN: true on success or false if an error occured + // DESC : runs post execute for rows affected, field names, inserted primary key, etc + private function __dbPostExec() { // if FALSE returned, set error stuff // if either the cursor is false - if (!$this->cursor || $this->db_functions->_db_last_error_query()) { + if (!$this->cursor || $this->db_functions->__dbLastErrorQuery()) { // printout Query if debug is turned on if ($this->db_debug) { - $this->_db_debug('db', $this->query, 'db_exec', 'Q[nc]'); + $this->__dbDebug('db', $this->query, 'dbExec', 'Q[nc]'); } // internal error handling $this->error_id = 13; - $this->_db_error($this->cursor); + $this->__dbError($this->cursor); return false; } else { // if SELECT do here ... - if ($this->_check_query_for_select($this->query)) { + if ($this->__checkQueryForSelect($this->query)) { // count the rows returned (if select) - $this->num_rows = $this->db_functions->_db_num_rows($this->cursor); + $this->num_rows = $this->db_functions->__dbNumRows($this->cursor); // count the fields - $this->num_fields = $this->db_functions->_db_num_fields($this->cursor); + $this->num_fields = $this->db_functions->__dbNumFields($this->cursor); // set field names unset($this->field_names); for ($i = 0; $i < $this->num_fields; $i ++) { - $this->field_names[] = $this->db_functions->_db_field_name($this->cursor, $i); + $this->field_names[] = $this->db_functions->__dbFieldName($this->cursor, $i); } - } elseif ($this->_check_query_for_insert($this->query)) { + } elseif ($this->__checkQueryForInsert($this->query)) { // if not select do here // count affected rows - $this->num_rows = $this->db_functions->_db_affected_rows($this->cursor); - if ($this->_check_query_for_insert($this->query, true) && $this->pk_name != 'NULL') { + $this->num_rows = $this->db_functions->__dbAffectedRows($this->cursor); + if ($this->__checkQueryForInsert($this->query, true) && $this->pk_name != 'NULL') { // set insert_id // if we do not have a returning, we try to get it via the primary key and another select if (!$this->returning_id) { - $this->insert_id = $this->db_functions->_db_insert_id($this->query, $this->pk_name); + $this->insert_id = $this->db_functions->__dbInsertId($this->query, $this->pk_name); } else { $this->insert_id = array (); $this->insert_id_ext = array (); // echo "** PREPARE RETURNING FOR CURSOR: ".$this->cursor."
"; // we have returning, now we need to check if we get one or many returned // we'll need to loop this, if we have multiple insert_id returns - while ($_insert_id = $this->db_functions->_db_fetch_array($this->cursor, PGSQL_ASSOC)) { + while ($_insert_id = $this->db_functions->__dbFetchArray($this->cursor, PGSQL_ASSOC)) { // echo "*** RETURNING: ".print_r($_insert_id, 1)."
"; $this->insert_id[] = $_insert_id; } @@ -752,7 +774,7 @@ class db_io extends basic // failed to get insert id $this->insert_id = ''; $this->warning_id = 33; - $this->_db_error($this->cursor, '[db_exec]'); + $this->__dbError($this->cursor, '[db_exec]'); } // if we have multiple, do not set the insert_id different, keep as array } @@ -760,7 +782,7 @@ class db_io extends basic // we returned an array of PKs instread of a single one if (is_array($this->insert_id)) { $this->warning_id = 32; - $this->_db_error($this->cursor, '[db_exec]'); + $this->__dbError($this->cursor, '[db_exec]'); } } } @@ -772,14 +794,15 @@ class db_io extends basic // PUBLIC METHODS // ************************************************************* - // METHOD db_set_debug - // PARAMS true/false or none - // RETURN new set debug flag - // DESC switches the debug flag on or off - // if none given, then the debug flag auto switches from - // the previous setting to either then on or off - // else override with boolean true/false - public function db_set_debug($debug = '') + // METHOD: dbSetDebug + // WAS : db_set_debug + // PARAMS: true/false or none + // RETURN: new set debug flag + // DESC : switches the debug flag on or off + // if none given, then the debug flag auto switches from + // the previous setting to either then on or off + // else override with boolean true/false + public function dbSetDebug($debug = '') { if ($debug === true) { $this->db_debug = 1; @@ -793,21 +816,23 @@ class db_io extends basic return $this->db_debug; } - // METHOD db_reset_query_called - // PARAMS query - // RETURN none - // DESC resets the call times for the max query called to 0 - // USE CAREFULLY: rather make the query prepare -> execute - public function db_reset_query_called($query) + // METHOD: dbResetQueryCalled + // WAS : db_reset_query_called + // PARAMS: query + // RETURN: none + // DESC : resets the call times for the max query called to 0 + // USE CAREFULLY: rather make the query prepare -> execute + public function dbResetQueryCalled($query) { $this->query_called[md5($query)] = 0; } - // METHOD db_get_query_called - // PARAMS query - // RETURN count of query called - // DESC gets how often a query was called already - public function db_get_query_called($query) + // METHOD: dbGetQueryCalled + // WAS : db_get_query_called + // PARAMS: query + // RETURN: count of query called + // DESC : gets how often a query was called already + public function dbGetQueryCalled($query) { $md5 = md5($query); if ($this->query_called[$md5]) { @@ -817,24 +842,26 @@ class db_io extends basic } } - // METHOD db_close - // PARAMS none - // RETURN none - // DESC closes the db_connection - // normally this is not used, as the class deconstructor closes the connection down - public function db_close() + // METHOD: dbClose + // WAS : db_close + // PARAMS: none + // RETURN: none + // DESC : closes the db_connection + // normally this is not used, as the class deconstructor closes the connection down + public function dbClose() { if ($this->dbh) { - $this->db_functions->_db_close(); + $this->db_functions->__dbClose(); unset($this->dbh); } } - // METHOD db_set_schema - // PARAMS db_schema: if not given tries internal default db schema - // RETURN false on failure to find schema values, true of db exec schema set - // DESC sets new db schema - public function db_set_schema($db_schema = '') + // METHOD: dbSetSchema + // WAS : db_set_schema + // PARAMS: db_schema: if not given tries internal default db schema + // RETURN: false on failure to find schema values, true of db exec schema set + // DESC : sets new db schema + public function dbSetSchema($db_schema = '') { if (!$db_schema && $this->db_schema) { $db_schema = $this->db_schema; @@ -842,24 +869,26 @@ class db_io extends basic if (!$db_schema) { return false; } - $q = "SET search_path TO '".$this->db_escape_string($db_schema)."'"; + $q = "SET search_path TO '".$this->dbEscapeString($db_schema)."'"; return $this->db_exec($q); } - // METHOD db_get_schema - // PARAMS none - // RETURN db_schema current set - // DESC returns the current set db schema - public function db_get_schema() + // METHOD: dbGetSchema + // WAS : db_get_schema + // PARAMS: none + // RETURN: db_schema current set + // DESC : returns the current set db schema + public function dbGetSchema() { return $this->db_schema; } - // METHOD db_set_encoding - // PARAMS valid encoding name, so the the data gets converted to this encoding - // RETURN false, or true of db exec encoding set - // DESC sets the client encoding in the postgres database - public function db_set_encoding($db_encoding = '') + // METHOD: dbSetEncoding + // WAS : db_set_encoding + // PARAMS: valid encoding name, so the the data gets converted to this encoding + // RETURN: false, or true of db exec encoding set + // DESC : sets the client encoding in the postgres database + public function dbSetEncoding($db_encoding = '') { if (!$db_encoding && $this->db_encoding) { $db_encoding = $this->db_encoding; @@ -867,15 +896,16 @@ class db_io extends basic if (!$db_encoding) { return false; } - $q = "SET client_encoding TO '".$this->db_escape_string($db_encoding)."'"; + $q = "SET client_encoding TO '".$this->dbEscapeString($db_encoding)."'"; return $this->db_exec($q); } - // METHOD db_info - // PARAMS show, default 1, if set to 0 won't write to error_msg var - // RETURN string with db_connection info - // DESC prints out status info from the connected DB (might be usefull for debug stuff) - public function db_info($show = 1) + // METHOD: dbInfo + // WAS : db_info + // PARAMS: show, default 1, if set to 0 won't write to error_msg var + // RETURN: string with db_connection info + // DESC : prints out status info from the connected DB (might be usefull for debug stuff) + public function dbInfo($show = 1) { $string = ''; $string .= '-DB-info-> Connected to db \''.$this->db_name.'\' '; @@ -886,18 +916,19 @@ class db_io extends basic $string .= 'with ssl mode \''.$this->db_ssl.'\'
'; $string .= '-DB-info-> DB IO Class debug output: '.(($this->db_debug) ? 'Yes' : 'No').''; if ($show) { - $this->_db_debug('db', '
'.$string, 'db_info'); + $this->__dbDebug('db', $string, 'dbInfo'); } else { - $string = '
'.$string; + $string = $string.'
'; } return $string; } - // METHOD db_dump_data - // PARAMS query -> if given, only from this quey (if found) - // RETURN formated string with all the data in the array - // DESC dumps ALL data for this query, OR if no query given all in cursor_ext array - public function db_dump_data($query = 0) + // METHOD: dbDumpData + // WAS : db_dump_data + // PARAMS: query -> if given, only from this quey (if found) + // RETURN: formated string with all the data in the array + // DESC : dumps ALL data for this query, OR if no query given all in cursor_ext array + public function dbDumpData($query = 0) { // set start array if ($query) { @@ -907,28 +938,29 @@ class db_io extends basic } if (is_array($array)) { $this->nbps = ''; - $string .= $this->_print_array($array); - $this->_db_debug('db', $string, 'db_dump_data'); + $string .= $this->__printArray($array); + $this->__dbDebug('db', $string, 'dbDumpData'); } return $string; } - // METHOD db_return - // PARAMS query -> the query ... - // reset -> if set to 1, at the end of the query (last row returned), the stored array will be deleted ... - // if set to 2, the data will be read new and cached (wheres 1 reads new AND destroys at end of read) - // -> if set to 3, after EACH row, the data will be reset, no caching is done except for basic (count, etc) - // RETURN res mixed (array/hash) - // DESC single running function, if called creates md5 from - // query string and so can itself call exec/return calls - // caches data, so next time called with IDENTICAL (!!!!) - // [this means 1:1 bit to bit identical query] returns cached - // data, or with reset flag set calls data from DB again - public function db_return($query, $reset = 0) + // METHOD: dbReturn + // WAS : db_return + // PARAMS: query -> the query ... + // reset -> if set to 1, at the end of the query (last row returned), the stored array will be deleted ... + // if set to 2, the data will be read new and cached (wheres 1 reads new AND destroys at end of read) + // -> if set to 3, after EACH row, the data will be reset, no caching is done except for basic (count, etc) + // RETURN: res mixed (array/hash) + // DESC : single running function, if called creates md5 from + // query string and so can itself call exec/return calls + // caches data, so next time called with IDENTICAL (!!!!) + // [this means 1:1 bit to bit identical query] returns cached + // data, or with reset flag set calls data from DB again + public function dbReturn($query, $reset = 0) { if (!$query) { $this->error_id = 11; - $this->_db_error(); + $this->__dbError(); return false; } // create MD5 from query ... @@ -948,9 +980,9 @@ class db_io extends basic // set the query $this->cursor_ext[$md5]['query'] = $query; // before doing ANYTHING check if query is "SELECT ..." everything else does not work - if (!$this->_check_query_for_select($this->cursor_ext[$md5]['query'])) { + if (!$this->__checkQueryForSelect($this->cursor_ext[$md5]['query'])) { $this->error_id = 17; - $this->_db_error('', $this->cursor_ext[$md5]['query']); + $this->__dbError('', $this->cursor_ext[$md5]['query']); return false; } @@ -959,38 +991,38 @@ class db_io extends basic if ($reset && !$this->cursor_ext[$md5]['pos']) { unset($this->cursor_ext[$md5]['cursor']); } -// $this->debug('MENU', 'Reset: '.$reset.', Cursor: '.$this->cursor_ext[$md5]['cursor'].', Pos: '.$this->cursor_ext[$md5]['pos'].', Query: '.$query); + // $this->debug('MENU', 'Reset: '.$reset.', Cursor: '.$this->cursor_ext[$md5]['cursor'].', Pos: '.$this->cursor_ext[$md5]['pos'].', Query: '.$query); // if no cursor yet, execute if (!$this->cursor_ext[$md5]['cursor']) { // for DEBUG, print out each query executed if ($this->db_debug) { - $this->_db_debug('db', $this->cursor_ext[$md5]['query'], 'db_return', 'Q'); + $this->__dbDebug('db', $this->cursor_ext[$md5]['query'], 'dbReturn', 'Q'); } // if no DB Handler try to reconnect if (!$this->dbh) { // if reconnect fails drop out - if (!$this->_connect_to_db()) { + if (!$this->__connectToDB()) { $this->error_id = 16; - $this->_db_error(); + $this->__dbError(); return false; } } // check that no other query is running right now - if ($this->db_functions->_db_connection_busy()) { + if ($this->db_functions->__dbConnection_busy()) { $this->error_id = 41; - $this->_db_error(); + $this->__dbError(); return false; } - $this->cursor_ext[$md5]['cursor'] = $this->db_functions->_db_query($this->cursor_ext[$md5]['query']); + $this->cursor_ext[$md5]['cursor'] = $this->db_functions->__dbQuery($this->cursor_ext[$md5]['query']); // if still no cursor ... if (!$this->cursor_ext[$md5]['cursor']) { if ($this->db_debug) { - $this->_db_debug('db', $this->cursor_ext[$md5]['query'], 'db_return', 'Q'); + $this->__dbDebug('db', $this->cursor_ext[$md5]['query'], 'dbReturn', 'Q'); } // internal error handling $this->error_id = 13; - $this->_db_error($this->cursor_ext[$md5]['cursor']); + $this->__dbError($this->cursor_ext[$md5]['cursor']); return false; } else { $this->cursor_ext[$md5]['firstcall'] = 1; @@ -1001,12 +1033,12 @@ class db_io extends basic if ($this->cursor_ext[$md5]['cursor']) { if ($this->cursor_ext[$md5]['firstcall'] == 1) { // count the rows returned (if select) - $this->cursor_ext[$md5]['num_rows'] = $this->db_functions->_db_num_rows($this->cursor_ext[$md5]['cursor']); + $this->cursor_ext[$md5]['num_rows'] = $this->db_functions->__dbNumRows($this->cursor_ext[$md5]['cursor']); // count the fields - $this->cursor_ext[$md5]['num_fields'] = $this->db_functions->_db_num_fields($this->cursor_ext[$md5]['cursor']); + $this->cursor_ext[$md5]['num_fields'] = $this->db_functions->__dbNumFields($this->cursor_ext[$md5]['cursor']); // set field names for ($i = 0; $i < $this->cursor_ext[$md5]['num_fields']; $i ++) { - $this->cursor_ext[$md5]['field_names'][] = $this->db_functions->_db_field_name($this->cursor_ext[$md5]['cursor'], $i); + $this->cursor_ext[$md5]['field_names'][] = $this->db_functions->__dbFieldName($this->cursor_ext[$md5]['cursor'], $i); } // reset first call vars $this->cursor_ext[$md5]['firstcall'] = 0; @@ -1019,7 +1051,7 @@ class db_io extends basic if ($this->cursor_ext[$md5]['read_rows'] == $this->cursor_ext[$md5]['num_rows']) { $return = 0; } else { - $return = $this->_db_convert_encoding($this->db_functions->_db_fetch_array($this->cursor_ext[$md5]['cursor'])); + $return = $this->__dbConvertEncoding($this->db_functions->__dbFetchArray($this->cursor_ext[$md5]['cursor'])); } // check if cached call or reset call ... if (!$return && !$reset) { @@ -1070,74 +1102,77 @@ class db_io extends basic return $return; } - // METHOD db_cache_reset - // PARAMS $query -> The Query whose cache should be cleaned - // RETURN 0 if failure (eg no query with this md5 found) - // 1 if successfull - // DESC resets all data stored to this query - public function db_cache_reset($query) + // METHOD: dbCacheReset + // WAS : db_cache_reset + // PARAMS: $query -> The Query whose cache should be cleaned + // RETURN: 0 if failure (eg no query with this md5 found) + // 1 if successfull + // DESC : resets all data stored to this query + public function dbCacheReset($query) { $md5 = md5($query); // clears cache for this query if (!$this->cursor_ext[$md5]['query']) { $this->error_id = 18; - $this->_db_error(); + $this->__dbError(); return false; } unset($this->cursor_ext[$md5]); return true; } - // METHOD db_exec - // PARAMS query -> the query, if not given, the query class var will be used - // (if this was not set, method will quit with a 0 (failure) - // pk_name -> optional primary key name, for insert id return if the pk name is very different - // if pk name is table name and _id, pk_name is not needed to be set - // if NULL is given here, no RETURNING will be auto added - // RETURN cursor for this query - // DESC executes the query and returns & sets the internal cursor - // fruthermore this functions also sets varios other vars - // like num_rows, num_fields, etc depending on query - // for INSERT INTO queries it is highly recommended to set the pk_name to avoid an additional - // read from the database for the PK NAME - public function db_exec($query = 0, $pk_name = '') + // METHOD: dbExec + // METHOD: db_exec + // PARAMS: query -> the query, if not given, the query class var will be used + // (if this was not set, method will quit with a 0 (failure) + // pk_name -> optional primary key name, for insert id return if the pk name is very different + // if pk name is table name and _id, pk_name is not needed to be set + // if NULL is given here, no RETURNING will be auto added + // RETURN: cursor for this query + // DESC : executes the query and returns & sets the internal cursor + // fruthermore this functions also sets varios other vars + // like num_rows, num_fields, etc depending on query + // for INSERT INTO queries it is highly recommended to set the pk_name to avoid an additional + // read from the database for the PK NAME + public function dbExec($query = 0, $pk_name = '') { // prepare and check if we can actually run it - if (($md5 = $this->_db_prepare_exec($query, $pk_name)) === false) { + if (($md5 = $this->__dbPrepareExec($query, $pk_name)) === false) { // bail if no md5 set return false; } // ** actual db exec call - $this->cursor = $this->db_functions->_db_query($this->query); + $this->cursor = $this->db_functions->__dbQuery($this->query); // if FALSE returned, set error stuff // run the post exec processing - if (!$this->_db_post_exec()) { + if (!$this->__dbPostExec()) { return false; } else { return $this->cursor; } } - // METHOD db_exec_async - // PARAMS query -> query to run - // pk_name -> optional primary key name, only used with insert for returning call - // RETURN true if async query was sent ok, false if error happened - // DESC executres the query async so other methods can be run during this - // for INSERT INTO queries it is highly recommended to set the pk_name to avoid an additional - // read from the database for the PK NAME - // NEEDS db_check_async - public function db_exec_async($query, $pk_name = '') + // METHOD: dbExecAsync + // WAS : db_exec_async + // PARAMS: query -> query to run + // pk_name -> optional primary key name, only used with insert for returning call + // RETURN: true if async query was sent ok, false if error happened + // DESC : executres the query async so other methods can be run during this + // for INSERT INTO queries it is highly recommended to set the pk_name to avoid an additional + // read from the database for the PK NAME + // NEEDS : dbCheckAsync + public function dbExecAsync($query, $pk_name = '') { // prepare and check if we can actually run the query - if (($md5 = $this->_db_prepare_exec($query, $pk_name)) === false) { + if (($md5 = $this->__dbPrepareExec($query, $pk_name)) === false) { // bail if no md5 set return false; } // run the async query - if (!$this->db_functions->_db_send_query($this->query)) { + if (!$this->db_functions->__dbSendQuery($this->query)) { // if failed, process here $this->error_id = 40; - $this->_db_error(); + $this->__dbError(); return false; } else { $this->async_running = $md5; @@ -1146,23 +1181,24 @@ class db_io extends basic } } - // METHOD db_check_async - // PARAMS none - // RETURN true if the query is still running, false if an error occured or cursor of that query - // DESC checks a previous async query and returns data if finished - // NEEDS db_exec_async - public function db_check_async() + // METHOD: dbCheckAsync + // WAS : db_check_async + // PARAMS: none + // RETURN: true if the query is still running, false if an error occured or cursor of that query + // DESC : checks a previous async query and returns data if finished + // NEEDS : dbExecAsync + public function dbCheckAsync() { // if there is actually a async query there if ($this->async_running) { - if ($this->db_functions->_db_connection_busy()) { + if ($this->db_functions->__dbConnection_busy()) { return true; } else { // get the result/or error - $this->cursor = $this->db_functions->_db_get_result(); + $this->cursor = $this->db_functions->__dbGetResult(); $this->async_running = ''; // run the post exec processing - if (!$this->_db_post_exec()) { + if (!$this->__dbPostExec()) { return false; } else { return $this->cursor; @@ -1171,17 +1207,18 @@ class db_io extends basic } else { // if no async running print error $this->error_id = 42; - $this->_db_debug('db', 'DB-Error No async query has been started yet.', 'DB_ERROR'); + $this->__dbDebug('db', 'DB-Error No async query has been started yet.', 'DB_ERROR'); return false; } } - // METHOD db_fetch_array - // PARAMS cusors -> the cursor from db_exec or pg_query/pg_exec/mysql_query - // if not set will use internal cursor, if not found, stops with 0 (error) - // RETURN a mixed row - // DESC executes a cursor and returns the data, if no more data 0 will be returned - public function db_fetch_array($cursor = 0) + // METHOD: dbFetchArray + // WAS : db_fetch_array + // PARAMS: cusors -> the cursor from db_exec or pg_query/pg_exec/mysql_query + // if not set will use internal cursor, if not found, stops with 0 (error) + // RETURN: a mixed row + // DESC : executes a cursor and returns the data, if no more data 0 will be returned + public function dbFetchArray($cursor = 0) { // return false if no query or cursor set ... if (!$cursor) { @@ -1189,53 +1226,55 @@ class db_io extends basic } if (!$cursor) { $this->error_id = 12; - $this->_db_error(); + $this->__dbError(); return false; } - return $this->_db_convert_encoding($this->db_functions->_db_fetch_array($cursor)); + return $this->__dbConvertEncoding($this->db_functions->__dbFetchArray($cursor)); } - // METHOD db_return_row - // PARAMS query -> the query to be executed - // RETURN mixed db result - // DESC returns the FIRST row of the given query - public function db_return_row($query) + // METHOD: dbReturnRow + // WAS : db_return_row + // PARAMS: query -> the query to be executed + // RETURN: mixed db result + // DESC : returns the FIRST row of the given query + public function dbReturnRow($query) { if (!$query) { $this->error_id = 11; - $this->_db_error(); + $this->__dbError(); return false; } // before doing ANYTHING check if query is "SELECT ..." everything else does not work - if (!$this->_check_query_for_select($query)) { + if (!$this->__checkQueryForSelect($query)) { $this->error_id = 17; - $this->_db_error('', $query); + $this->__dbError('', $query); return false; } $cursor = $this->db_exec($query); - $result = $this->db_fetch_array($cursor); + $result = $this->dbFetchArray($cursor); return $result; } - // METHOD db_return_array - // PARAMS query -> the query to be executed, named_only -> if true, only name ref are returned - // RETURN array of hashes (row -> fields) - // DESC createds an array of hashes of the query (all data) - public function db_return_array($query, $named_only = 0) + // METHOD: dbReturnArray + // WAS : db_return_array + // PARAMS: query -> the query to be executed, named_only -> if true, only name ref are returned + // RETURN: array of hashes (row -> fields) + // DESC : createds an array of hashes of the query (all data) + public function dbReturnArray($query, $named_only = 0) { if (!$query) { $this->error_id = 11; - $this->_db_error(); + $this->__dbError(); return false; } // before doing ANYTHING check if query is "SELECT ..." everything else does not work - if (!$this->_check_query_for_select($query)) { + if (!$this->__checkQueryForSelect($query)) { $this->error_id = 17; - $this->_db_error('', $query); + $this->__dbError('', $query); return false; } $cursor = $this->db_exec($query); - while ($res = $this->db_fetch_array($cursor)) { + while ($res = $this->dbFetchArray($cursor)) { for ($i = 0; $i < $this->num_fields; $i ++) { // cereated mixed, first name $data[$this->field_names[$i]] = $res[$this->field_names[$i]]; @@ -1249,92 +1288,96 @@ class db_io extends basic return $rows; } - // METHOD db_cursor_pos - // PARAMS $query -> query to find in cursor_ext - // RETURN position (int) - // DESC returns the current position the read out - public function db_cursor_pos($query) + // METHOD: dbCursorPos + // WAS : db_cursor_pos + // PARAMS: $query -> query to find in cursor_ext + // RETURN: position (int) + // DESC : returns the current position the read out + public function dbCursorPos($query) { if (!$query) { $this->error_id = 11; - $this->_db_error(); + $this->__dbError(); return false; } $md5 = md5($query); return $this->cursor_ext[$md5]['pos']; } - // METHOD db_cursor_num_rows - // PARAMS $query -> query to find in cursor_ext - // RETURN row count (int) - // DESC returns the number of rows for the current select query - public function db_cursor_num_rows($query) + // METHOD: dbCursorNumRows + // WAS : db_cursor_num_rows + // PARAMS: $query -> query to find in cursor_ext + // RETURN: row count (int) + // DESC : returns the number of rows for the current select query + public function dbCursorNumRows($query) { if (!$query) { $this->error_id = 11; - $this->_db_error(); + $this->__dbError(); return false; } $md5 = md5($query); return $this->cursor_ext[$md5]['num_rows']; } - // METHOD db_show_table_meta_data - // PARAMS $table -> table name - // $schema -> optional schema name - // RETURN array of table data - // DESC returns an array of the table with columns and values. FALSE on no table found - public function db_show_table_meta_data($table, $schema = '') + // METHOD: dbShowTableMetaData + // WAS : db_show_table_meta_data + // PARAMS: $table -> table name + // $schema -> optional schema name + // RETURN: array of table data + // DESC : returns an array of the table with columns and values. FALSE on no table found + public function dbShowTableMetaData($table, $schema = '') { $table = ($schema ? $schema.'.' : '').$table; - $array = $this->db_functions->_db_meta_data($table); + $array = $this->db_functions->__dbMetaData($table); if (!is_array($array)) { $array = false; } return $array; } - // METHOD db_prepare - // PARAMS $stm_name, $query, $pk_name: optional - // RETURN false on error - // DESC prepares a query - // for INSERT INTO queries it is highly recommended to set the pk_name to avoid an additional - // read from the database for the PK NAME - public function db_prepare($stm_name, $query, $pk_name = '') + // METHOD: dbPrepare + // WAS : db_prepare + // PARAMS: $stm_name, $query, $pk_name: optional + // RETURN: false on error + // DESC : prepares a query + // for INSERT INTO queries it is highly recommended to set the pk_name to avoid an additional + // read from the database for the PK NAME + public function dbPrepare($stm_name, $query, $pk_name = '') { if (!$query) { $this->error_id = 11; - $this->_db_error(); + $this->__dbError(); return false; } // if no DB Handler drop out if (!$this->dbh) { // if reconnect fails drop out - if (!$this->_connect_to_db()) { + if (!$this->__connectToDB()) { $this->error_id = 16; - $this->_db_error(); + $this->__dbError(); return false; } } // check that no other query is running right now - if ($this->db_functions->_db_connection_busy()) { + if ($this->db_functions->__dbConnection_busy()) { $this->error_id = 41; - $this->_db_error(); + $this->__dbError(); return false; } // check if this was already prepared if (!array_key_exists($stm_name, $this->prepare_cursor) || !is_array($this->prepare_cursor[$stm_name])) { // if this is an insert query, check if we can add a return - if ($this->_check_query_for_insert($query, true)) { + if ($this->__checkQueryForInsert($query, true)) { if ($pk_name != 'NULL') { // set primary key name // current: only via parameter if (!$pk_name) { // read the primary key from the table, if we do not have one, we get nothing in return - list($schema, $table) = $this->_db_return_table($query); + list($schema, $table) = $this->__dbReturnTable($query); if (!$this->pk_name_table[$table]) { - $this->pk_name_table[$table] = $this->db_functions->_db_primary_key($table, $schema); + $this->pk_name_table[$table] = $this->db_functions->__dbPrimaryKey($table, $schema); } $pk_name = $this->pk_name_table[$table]; } @@ -1360,14 +1403,14 @@ class db_io extends basic preg_match_all('/(\$[0-9]{1,})/', $query, $match); $this->prepare_cursor[$stm_name]['count'] = count($match[1]); $this->prepare_cursor[$stm_name]['query'] = $query; - $result = $this->db_functions->_db_prepare($stm_name, $query); + $result = $this->db_functions->__dbPrepare($stm_name, $query); if ($result) { $this->prepare_cursor[$stm_name]['result'] = $result; return $result; } else { $this->error_id = 21; - $this->_db_error(); - $this->_db_debug('db', 'DB-Error '.$stm_name.': Prepare field with: '.$stm_name.' | '.$query.'', 'DB_ERROR'); + $this->__dbError(); + $this->__dbDebug('db', 'DB-Error '.$stm_name.': Prepare field with: '.$stm_name.' | '.$query.'', 'DB_ERROR'); return $result; } } else { @@ -1377,47 +1420,48 @@ class db_io extends basic } } - // METHOD db_execute - // PARAMS $stm_name, data array - // RETURN false on error - // DESC runs a prepare query - public function db_execute($stm_name, $data = array()) + // METHOD: dbExecute + // WAS : db_execute + // PARAMS: $stm_name, data array + // RETURN: false on error + // DESC : runs a prepare query + public function dbExecute($stm_name, $data = array()) { // if we do not have no prepare cursor array entry for this statement name, abort if (!is_array($this->prepare_cursor[$stm_name])) { $this->error_id = 24; - $this->_db_debug('db', 'DB-Error '.$stm_name.': We do not have a prepared query entry for this statement name.', 'DB_ERROR'); + $this->__dbDebug('db', 'DB-Error '.$stm_name.': We do not have a prepared query entry for this statement name.', 'DB_ERROR'); return false; } if (!is_array($data)) { $this->error_id = 25; - $this->_db_debug('db', 'DB-Error '.$stm_name.': Prepared query Data has to be given in array form.', 'DB_ERROR'); + $this->__dbDebug('db', 'DB-Error '.$stm_name.': Prepared query Data has to be given in array form.', 'DB_ERROR'); return false; } if ($this->prepare_cursor[$stm_name]['count'] != count($data)) { $this->error_id = 23; - $this->_db_debug('db', 'DB-Error '.$stm_name.': Array data count does not match prepared fields. Need: '.$this->prepare_cursor[$stm_name]['count'].', has: '.count($data).'', 'DB_ERROR'); + $this->__dbDebug('db', 'DB-Error '.$stm_name.': Array data count does not match prepared fields. Need: '.$this->prepare_cursor[$stm_name]['count'].', has: '.count($data).'', 'DB_ERROR'); return false; } else { if ($this->db_debug) { - $this->_db_debug('db', $this->_db_debug_prepare($stm_name, $data), 'db_exec_prep', 'Q'); + $this->__dbDebug('db', $this->__dbDebug_prepare($stm_name, $data), 'dbExecPrep', 'Q'); } - $code = $this->db_functions->_db_execute($stm_name, $data); + $code = $this->db_functions->__dbExecute($stm_name, $data); if (!$code) { $this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[$stm_name]['result'].']: '.$this->print_ar($data)); $this->error_id = 22; - $this->_db_error($this->prepare_cursor[$stm_name]['result']); - $this->_db_debug('db', 'DB-Error '.$stm_name.': Execution failed', 'DB_ERROR'); + $this->__dbError($this->prepare_cursor[$stm_name]['result']); + $this->__dbDebug('db', 'DB-Error '.$stm_name.': Execution failed', 'DB_ERROR'); } - if ($this->_check_query_for_insert($this->prepare_cursor[$stm_name]['query'], true) && $this->prepare_cursor[$stm_name]['pk_name'] != 'NULL') { + if ($this->__checkQueryForInsert($this->prepare_cursor[$stm_name]['query'], true) && $this->prepare_cursor[$stm_name]['pk_name'] != 'NULL') { if (!$this->prepare_cursor[$stm_name]['returning_id']) { - $this->insert_id = $this->db_functions->_db_insert_id($this->prepare_cursor[$stm_name]['query'], $this->prepare_cursor[$stm_name]['pk_name']); + $this->insert_id = $this->db_functions->__dbInsertId($this->prepare_cursor[$stm_name]['query'], $this->prepare_cursor[$stm_name]['pk_name']); } elseif ($code) { $this->insert_id = array (); $this->insert_id_ext = array (); // we have returning, now we need to check if we get one or many returned // we'll need to loop this, if we have multiple insert_id returns - while ($_insert_id = $this->db_functions->_db_fetch_array($code, PGSQL_ASSOC)) { + while ($_insert_id = $this->db_functions->__dbFetchArray($code, PGSQL_ASSOC)) { $this->insert_id[] = $_insert_id; } // if we have only one, revert from arry to single @@ -1437,59 +1481,63 @@ class db_io extends basic // failed to get insert id $this->insert_id = ''; $this->warning_id = 33; - $this->_db_error(); - $this->_db_debug('db', 'DB-Warning '.$stm_name.': insert id returned no data', 'DB_WARNING'); + $this->__dbError(); + $this->__dbDebug('db', 'DB-Warning '.$stm_name.': insert id returned no data', 'DB_WARNING'); } } // this error handling is only for pgsql if (is_array($this->insert_id)) { $this->warning_id = 32; - $this->_db_error(); - $this->_db_debug('db', 'DB-Warning '.$stm_name.': insert id data returned as array', 'DB_WARNING'); + $this->__dbError(); + $this->__dbDebug('db', 'DB-Warning '.$stm_name.': insert id data returned as array', 'DB_WARNING'); } elseif (!$this->insert_id) { // NOTE should we keep this inside $this->warning_id = 31; - $this->_db_error(); - $this->_db_debug('db', 'DB-Warning '.$stm_name.': Could not get insert id', 'DB_WARNING'); + $this->__dbError(); + $this->__dbDebug('db', 'DB-Warning '.$stm_name.': Could not get insert id', 'DB_WARNING'); } } return $code; } } - // METHOD db_escape_string - // PARAMS $string -> string to escape - // RETURN escaped string - // DESC neutral function to escape a string for DB writing - public function db_escape_string($string) + // METHOD: dbEscapeString + // WAS : db_escape_string + // PARAMS: $string -> string to escape + // RETURN: escaped string + // DESC : neutral function to escape a string for DB writing + public function dbEscapeString($string) { - return $this->db_functions->_db_escape_string($string); + return $this->db_functions->__dbEscapeString($string); } - // METHOD db_escape_bytea - // PARAMS $bytea -> bytea to escape - // RETURN escaped bytea - // DESC neutral function to escape a bytea for DB writing - public function db_escape_bytea($bytea) + // METHOD: dbEscapeBytea + // WAS : db_escape_bytea + // PARAMS: $bytea -> bytea to escape + // RETURN: escaped bytea + // DESC : neutral function to escape a bytea for DB writing + public function dbEscapeBytea($bytea) { - return $this->db_functions->_db_escape_bytea($bytea); + return $this->db_functions->__dbEscapeBytea($bytea); } - // METHOD db_version - // PARAMS none - // RETURN database version as string - // DESC return current database version - public function db_version() + // METHOD: dbVersion + // WAS : db_version + // PARAMS: none + // RETURN: database version as string + // DESC : return current database version + public function dbVersion() { - return $this->db_functions->_db_version(); + return $this->db_functions->__dbVersion(); } - // METHOD db_compare_version - // PARAMS string to which the return will return true or false + // METHOD: dbCompareVersion + // WAS : db_compare_version + // PARAMS: string to which the return will return true or false // =X.Y, >X.Y, , < prefix, and gets stripped, if the rest is not X.Y format then error preg_match("/^([<>=]{1,2})(\d{1,2})\.(\d{1,2})/", $compare, $matches); @@ -1503,7 +1551,7 @@ class db_io extends basic } // db_version can return X.Y.Z // we only compare the first two - list ($master, $minor, $_other) = explode('.', $this->db_version()); + list ($master, $minor, $_other) = explode('.', $this->dbVersion()); $version = $master.($minor < 10 ? '0' : '').$minor; $return = false; // compare @@ -1539,11 +1587,12 @@ class db_io extends basic return $return; } - // METHOD db_boolean - // PARAMS 't' / 'f' or any string - // RETURN correct php boolean true/false - // DESC if the input is a single char 't' or 'f' it will return the boolean value instead - public function db_boolean($string, $rev = false) + // METHOD: dbBoolean + // WAS : db_boolean + // PARAMS: 't' / 'f' or any string + // RETURN: correct php boolean true/false + // DESC : if the input is a single char 't' or 'f' it will return the boolean value instead + public function dbBoolean($string, $rev = false) { if (!$rev) { if ($string == 't' || $string == 'true') { @@ -1567,14 +1616,15 @@ class db_io extends basic // db_write_data is the old without separate update no write list // db_write_data_ext is the extended with additional array for no write list for update - // METHOD: db_write_data + // METHOD: dbWriteData + // WAS : db_write_data // PARAMS: write_array -> list of elements to write // not_write_array -> list of elements not to write // primary_key -> id key to decide if we write insert or update // table -> name for the target table // RETURN: primary key id // DESC: writes into one table based on array of table columns - public function db_write_data($write_array, $not_write_array, $primary_key, $table, $data = array ()) + public function dbWriteData($write_array, $not_write_array, $primary_key, $table, $data = array ()) { if (!is_array($write_array)) { $write_array = array (); @@ -1586,21 +1636,24 @@ class db_io extends basic return false; } $not_write_update_array = array (); - return $this->db_write_data_ext($write_array, $primary_key, $table, $not_write_array, $not_write_update_array, $data); + return $this->dbWriteData_ext($write_array, $primary_key, $table, $not_write_array, $not_write_update_array, $data); } - // METHOD: db_write_data_ext + // METHOD: dbWriteDataExt + // WAS : db_write_data_ext // PARAMS: write_array -> list of elements to write // primary_key -> id key to decide if we write insert or update - // -> alternate the primary key can be an array with 'row' => 'row name', 'value' => 'data' to use a different column as the primary key + // -> alternate the primary key can be an array with + // 'row' => 'row name', 'value' => 'data' to use a + // different column as the primary key // table -> name for the target table // (optional) // not_write_array -> list of elements not to write // not_write_update_array -> list of elements not to write during update // data -> optional array with data, if not _POST vars are used // RETURN: primary key id - // DESC: writes into one table based on array of table columns - public function db_write_data_ext($write_array, $primary_key, $table, $not_write_array = array (), $not_write_update_array = array (), $data = array ()) + // DESC : writes into one table based on array of table columns + public function dbWriteDataExt($write_array, $primary_key, $table, $not_write_array = array (), $not_write_update_array = array (), $data = array ()) { if (!is_array($primary_key)) { $primary_key = array ( @@ -1612,7 +1665,7 @@ class db_io extends basic $q_sub_value = ''; $q_sub_data = ''; // get the table layout and row types - $table_data = $this->db_show_table_meta_data(($this->db_schema ? $this->db_schema.'.' : '').$table); + $table_data = $this->dbShowTableMetaData(($this->db_schema ? $this->db_schema.'.' : '').$table); foreach ($write_array as $field) { if ((!$primary_key['value'] || ($primary_key['value'] && !in_array($field, $not_write_update_array))) && !in_array($field, $not_write_array)) { // data from external or data field @@ -1656,7 +1709,7 @@ class db_io extends basic $q_sub_data .= (is_numeric($_data) && isset($_data)) ? $_data : 'NULL'; } else { // if bool -> set bool, else write data - $q_sub_data .= isset($_data) ? "'".($is_bool ? $this->db_boolean($_data, true) : $this->db_escape_string($_data))."'" : 'NULL'; + $q_sub_data .= isset($_data) ? "'".($is_bool ? $this->dbBoolean($_data, true) : $this->dbEscapeString($_data))."'" : 'NULL'; } } } @@ -1686,12 +1739,13 @@ class db_io extends basic return $primary_key['value']; } - // METHOD: db_time_format + // METHOD: dbTimeFormat + // WAS : db_time_format // PARAMS: age or datetime difference // micro on off (default false) // RETURN: Y/M/D/h/m/s formatted string (like TimeStringFormat - // DESC: only for postgres. pretty formats an age or datetime difference string - public function db_time_format($age, $show_micro = false) + // DESC : only for postgres. pretty formats an age or datetime difference string + public function dbTimeFormat($age, $show_micro = false) { // in string (datetime diff): 1786 days 22:11:52.87418 // or (age): 4 years 10 mons 21 days 12:31:11.87418 @@ -1708,21 +1762,23 @@ class db_io extends basic return $prefix.($hour ? $hour.'h ' : '').($minutes ? $minutes.'m ' : '').($seconds ? $seconds.'s' : '').($show_micro && $milliseconds? ' '.$milliseconds.'ms' : ''); } - // METHOD: db_array_parse + // METHOD: dbArrayParse + // WAS : db_array_parse // PARAMS: text: input text to parse to an array // RETURN: PHP array of the parsed data - // DESC: this is only needed for Postgresql. Converts postgresql arrays to PHP - public function db_array_parse($text) + // DESC : this is only needed for Postgresql. Converts postgresql arrays to PHP + public function dbArrayParse($text) { - return $this->db_functions->_db_array_parse($text, $output); + return $this->db_functions->__dbArrayParse($text, $output); } - // METHOD: db_sql_escape + // METHOD: dbSqlEscape + // WAS : db_sql_escape // PARAMS: value -> to escape data - // kbn -> escape trigger type + // kbn -> escape trigger type // RETURN: escaped value // DESC : clear up any data for valid DB insert - public function db_sql_escape($value, $kbn = "") + public function dbSqlEscape($value, $kbn = "") { switch ($kbn) { case "i": @@ -1732,10 +1788,10 @@ class db_io extends basic $value = (!isset($value) || $value === "") ? "NULL" : floatval($value); break; case "t": - $value = (!isset($value) || $value === "") ? "NULL" : "'".$this->db_escape_string($value)."'"; + $value = (!isset($value) || $value === "") ? "NULL" : "'".$this->dbEscapeString($value)."'"; break; case "d": - $value = (!isset($value) || $value === "") ? "NULL" : "'".$this->db_escape_string($value)."'"; + $value = (!isset($value) || $value === "") ? "NULL" : "'".$this->dbEscapeString($value)."'"; break; case "i2": $value = (!isset($value) || $value === "") ? 0 : intval($value); @@ -1743,4 +1799,268 @@ class db_io extends basic } return $value; } + + // ************************************************************* + // COMPATIBILITY METHODS + // those methods are deprecated function call names + // they exist for backwards compatibility only + // ************************************************************* + + private function _connect_to_db() + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->__connectToDB(); + } + + private function _close_db() + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->__closeDB(); + } + + private function _check_query_for_select($query) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->__checkQueryForSelect($query); + } + + private function _check_query_for_insert($query, $pure = false) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->__checkQueryForInsert($query, $pure); + } + + private function _print_array($array) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->__printArray($array); + } + + private function _db_debug($debug_id, $error_string, $id = '', $type = '') + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->__dbDebug($debug_id, $error_string, $id, $type); + } + + public function _db_error($cursor = '', $msg = '') + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->__dbError($cursor, $msg); + } + + private function _db_convert_encoding($row) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->__dbConvertEncoding($row); + } + + private function _db_debug_prepare($stm_name, $data = array()) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->__dbDebugPrepare($stm_name, $data); + } + + private function _db_return_table($query) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->__dbReturnTable($query); + } + + private function _db_prepare_exec($query, $pk_name) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->__dbPrepareExec($query, $pk_name); + } + + private function _db_post_exec() + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->__dbPostExec(); + } + + public function db_set_debug($debug = '') + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbSetDebug($debug); + } + + public function db_reset_query_called($query) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbResetQueryCalled($query); + } + + public function db_get_query_called($query) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbGetQueryCalled($query); + } + + public function db_close() + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbClose(); + } + + public function db_set_schema($db_schema = '') + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbSetSchema($db_schema); + } + + public function db_get_schema() + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbGetSchema(); + } + + public function db_set_encoding($db_encoding = '') + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbSetEncoding($db_encoding); + } + + public function db_info($show = 1) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbInfo($show); + } + + public function db_dump_data($query = 0) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbDumpData($query); + } + + public function db_return($query, $reset = 0) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbReturn($query, $reset); + } + + public function db_cache_reset($query) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbCacheReset($query); + } + + public function db_exec_async($query, $pk_name = '') + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbExecAsync($query, $pk_name); + } + + public function db_check_async() + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbCheckAsync(); + } + + public function db_fetch_array($cursor = 0) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbFetchArray($cursor); + } + + public function db_return_row($query) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbReturnRow($query); + } + + public function db_return_array($query, $named_only = 0) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbReturnArray($query, $named_only); + } + + public function db_cursor_pos($query) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbCursorPos($query); + } + + public function db_cursor_num_rows($query) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbCursorNumRows($query); + } + + public function db_show_table_meta_data($table, $schema = '') + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbShowTableMetaData($table, $schema); + } + + public function db_prepare($stm_name, $query, $pk_name = '') + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbPrepare($stm_name, $query, $pk_name); + } + + public function db_execute($stm_name, $data = array()) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbExecute($stm_name, $data); + } + + public function db_escape_string($string) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbEscapeString($string); + } + + public function db_escape_bytea($bytea) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbEscapeBytea($bytea); + } + + public function db_version() + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbVersion(); + } + + public function db_compare_version($compare) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbCompareVersion($compare); + } + + public function db_boolean($string, $rev = false) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbBoolean($string, $rev); + } + + public function db_write_data($write_array, $not_write_array, $primary_key, $table, $data = array ()) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbWriteData($write_array, $not_write_array, $primary_key, $table, $data); + } + + public function db_write_data_ext($write_array, $primary_key, $table, $not_write_array = array (), $not_write_update_array = array (), $data = array ()) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbWriteDataExt($write_array, $primary_key, $table, $not_write_array, $not_write_update_array, $data); + } + + public function db_time_format($age, $show_micro = false) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbTimeFormat($age, $show_micro); + } + + public function db_array_parse($text) + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbArrayParse($text); + } + + public function db_sql_escape($value, $kbn = "") + { + error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']); + return $this->dbSqlEscape($value, $kbn); + } } // end if db class diff --git a/www/lib/CoreLibs/DB/SQL/PgSQL.inc b/www/lib/CoreLibs/DB/SQL/PgSQL.inc index 96468d93..afe6bd3a 100644 --- a/www/lib/CoreLibs/DB/SQL/PgSQL.inc +++ b/www/lib/CoreLibs/DB/SQL/PgSQL.inc @@ -3,8 +3,12 @@ * AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org) * CREATED: 2003/04/09 * SHORT DESCRIPTION: +* 2018/3/23, the whole class system is transformed to namespaces +* also all internal class calls are converted to camel case +* * pgsql wrapper calls -* HISTORY: +* +* HISTORY: * 2008/04/16 (cs) wrapper for pg escape string * 2007/01/11 (cs) add prepare/execute for postgres * 2006/09/12 (cs) in case db_query retuns false, save the query and run the query through the send/get procedure to get correct error data from the db @@ -37,7 +41,9 @@ * */ -class db_pgsql +namespace CoreLibs\DB\SQL; + +class PgSQL { private $last_error_query; private $dbh; @@ -51,7 +57,12 @@ class db_pgsql { } - public function _db_last_error_query() + // METHOD: __dbLastErrorQuery + // WAS : _db_last_error_query + // PARAMS: none + // RETURN: true/false if last error is set + // DESC : queries last error query and returns true or false if error was set + public function __dbLastErrorQuery() { if ($this->last_error_query) { return true; @@ -60,11 +71,12 @@ class db_pgsql } } - // METHOD: _db_query + // METHOD: __dbQuery + // WAS : _db_query // PARAMS: query // RETURN: query result // DESC : wrapper for gp_query, catches error and stores it in class var - public function _db_query($query) + public function __dbQuery($query) { $this->last_error_query = ''; // read out the query status and save the query if needed @@ -75,20 +87,22 @@ class db_pgsql return $result; } - // METHOD: _db_send_query + // METHOD: __dbSendQuery + // WAS : _db_send_query // PARAMS: query // RETURN: true/false if query was sent successful // DESC : sends an async query to the server - public function _db_send_query($query) + public function __dbSendQuery($query) { return pg_send_query($this->dbh, $query); } - // METHOD: _db_get_result + // METHOD: __dbGetResult + // WAS : _db_get_result // PARAMS: none // RETURN: resource handler // DESC : wrapper for pg_get_result - public function _db_get_result() + public function __dbGetResult() { $this->last_error_query = ''; $result = pg_get_result($this->dbh); @@ -98,11 +112,12 @@ class db_pgsql return $result; } - // METHOD: _db_close + // METHOD: __dbClose + // WAS : _db_close // PARAMS: none // RETURN: none // DESC : wrapper for pg_close - public function _db_close() + public function __dbClose() { if (is_resource($this->dbh)) { if (pg_connection_status($this->dbh) === PGSQL_CONNECTION_OK) { @@ -111,11 +126,12 @@ class db_pgsql } } - // METHOD: _db_prepare + // METHOD: __dbPrepare + // WAS : _db_prepare // PARAMS: prepare name, query // RETURN: prepared statement handler // DESC : wrapper for pg_prepare - public function _db_prepare($name, $query) + public function __dbPrepare($name, $query) { $result = pg_prepare($this->dbh, $name, $query); if (!$result) { @@ -124,11 +140,12 @@ class db_pgsql return $result; } - // METHOD: _db_execute + // METHOD: __dbExecute + // WAS : _db_execute // PARAMS: prepare name, data for query // RETURN: returns status // DESC : wrapper for pg_execute for running a prepared statement - public function _db_execute($name, $data) + public function __dbExecute($name, $data) { $result = pg_execute($this->dbh, $name, $data); if (!$result) { @@ -137,73 +154,80 @@ class db_pgsql return $result; } - // METHOD: _db_num_rows + // METHOD: __dbNumRows + // WAS : _db_num_rows // PARAMS: cursor // RETURN: rows // DESC : wrapper for pg_num_rows - public function _db_num_rows($cursor) + public function __dbNumRows($cursor) { return pg_num_rows($cursor); } - // METHOD: _db_num_fields + // METHOD: __dbNumFields + // WAS : _db_num_fields // PARAMS: cursor // RETURN: number for fields in query // DESC : wrapper for pg_num_fields - public function _db_num_fields($cursor) + public function __dbNumFields($cursor) { return pg_num_fields($cursor); } - // METHOD: _db_field_name + // METHOD: __dbFieldName + // WAS : _db_field_name // PARAMS: cursor, field position // RETURN: name of field // DESC : wrapper for pg_field_name - public function _db_field_name($cursor, $i) + public function __dbFieldName($cursor, $i) { return pg_field_name($cursor, $i); } - // METHOD: _db_fetch_array + // METHOD: __dbFetchArray + // WAS : _db_fetch_array // PARAMS: cursor, opt result type // RETURN: row // DESC : wrapper for pg_fetch_array - public function _db_fetch_array($cursor, $result_type = '') + public function __dbFetchArray($cursor, $result_type = '') { // result type is passed on as is [should be checked] if ($result_type) { - return pg_fetch_array($cursor, NULL, $result_type); + return pg_fetch_array($cursor, null, $result_type); } else { return pg_fetch_array($cursor); } } - // METHOD: _db_fetch_all + // METHOD: __dbFetchAll + // WAS : _db_fetch_all // PARAMS: cursor // RETURN: all rows as array // DESC : wrapper for pg_fetch_array - public function _db_fetch_all($cursor) + public function __dbFetchAll($cursor) { return pg_fetch_all($cursor); } - // METHOD: _db_affected_ros + // METHOD: __dbAffectedRows + // WAS : _db_affected_rows // PARAMS: cursor // RETURN: number for rows // DESC : wrapper for pg_affected_rows - public function _db_affected_rows($cursor) + public function __dbAffectedRows($cursor) { return pg_affected_rows($cursor); } - // METHOD: _db_insert_id + // METHOD: __dbInsertId + // WAS : _db_insert_id // PARAMS: query, primary key name // RETURN: last insert primary key // DESC : reads the last inserted primary key for the query // if ther is no pk_name tries to auto built it from the table name // this only works if db schema is after "no plural names. and pk name is table name + _id // detects schema prefix in table name - public function _db_insert_id($query, $pk_name) + public function __dbInsertId($query, $pk_name) { // only if an insert has been done if (preg_match("/^insert /i", $query)) { @@ -229,8 +253,8 @@ class db_pgsql $q = "SELECT CURRVAL('$seq') AS insert_id"; // $this->currval_query = $q; // I have to do manually or I overwrite the original insert internal vars ... - if ($q = $this->_db_query($q)) { - list($id) = $this->_db_fetch_array($q); + if ($q = $this->__dbQuery($q)) { + list($id) = $this->__dbFetchArray($q); } else { $id = array(-1, $q); } @@ -238,19 +262,20 @@ class db_pgsql } } - // METHOD: _db_primary_key + // METHOD: __dbPrimaryKey + // WAS : _db_primary_key // PARAMS: table and optional schema // RETURN: primary key name OR false if not possible // DESC : queries database for the primary key name to this table in the selected schema - public function _db_primary_key($table, $schema = '') + public function __dbPrimaryKey($table, $schema = '') { if ($table) { // check if schema set is different from schema given, only needed if schema is not empty $table_prefix = ''; if ($schema) { $q = "SHOW search_path"; - $cursor = $this->_db_query($q); - $search_path = $this->_db_fetch_array($cursor)['search_path']; + $cursor = $this->__dbQuery($q); + $search_path = $this->__dbFetchArray($cursor)['search_path']; if ($search_path != $schema) { $table_prefix = $schema.'.'; } @@ -273,9 +298,9 @@ class db_pgsql $q .= "pg_attribute.attrelid = pg_class.oid AND "; $q .= "pg_attribute.attnum = any(pg_index.indkey) "; $q .= "AND indisprimary"; - $cursor = $this->_db_query($q); + $cursor = $this->__dbQuery($q); if ($cursor) { - return $this->_db_fetch_array($cursor)['column_name']; + return $this->__dbFetchArray($cursor)['column_name']; } else { return false; } @@ -284,11 +309,12 @@ class db_pgsql } } - // METHOD: _db_connect + // METHOD: __dbConnect + // WAS : _db_connect // PARAMS: host name, user name, password, database name, optional port (defaults to default postgres port), optional ssl (default allow) // RETURN: database handler // DESC : wrapper for pg_connect, writes out failure to screen if error occurs (hidden var) - public function _db_connect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow') + public function __dbConnect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow') { // to avoid empty db_port if (!$db_port) { @@ -301,11 +327,12 @@ class db_pgsql return $this->dbh; } - // METHOD: _db_print_error + // METHOD: __dbPrintError + // WAS : _db_print_error // PARAMS: database handler, cursor // RETURN: error string (HTML) // DESC : reads the last error for this cursor - public function _db_print_error($cursor = '') + public function __dbPrintError($cursor = '') { // run the query again for the error result here if (!$cursor && $this->last_error_query) { @@ -318,47 +345,52 @@ class db_pgsql } } - // METHOD: _db_meta_data + // METHOD: __dbMetaData + // WAS : _db_meta_data // PARAMS: table name // RETURN: array with table data // DESC : wrapper for pg_emta_data - public function _db_meta_data($table) + public function __dbMetaData($table) { return pg_meta_data($this->dbh, $table); } - // METHOD: _db_escape_string + // METHOD: __dbEscapeString + // WAS : _db_escape_string // PARAMS: string // RETURN: escaped string for postgres // DESC : wrapper for pg_escape_string - public function _db_escape_string($string) + public function __dbEscapeString($string) { return pg_escape_string($this->dbh, $string); } - // METHOD: _db_escape_bytea + // METHOD: __dbEscapeBytea + // WAS : _db_escape_bytea // PARAMS: string // RETURN: escape bytes for postgres // DESC : wrapper for pg_escape_bytea - public function _db_escape_bytea($bytea) + public function __dbEscapeBytea($bytea) { return pg_escape_bytea($this->dbh, $bytea); } - // METHOD: _db_connection_busy + // METHOD: __dbConnectionBusy + // WAS : _db_connection_busy // PARAMS: none // RETURN: true/false for busy connection // DESC : wrapper for pg_connection_busy - public function _db_connection_busy() + public function __dbConnectionBusy() { return pg_connection_busy($this->dbh); } - // METHOD: _db_version + // METHOD: __dbVersion + // WAS : _db_version // PARAMS: none // RETURN: databse version // DESC : wrapper for pg_version - public function _db_version() + public function __dbVersion() { // array has client, protocol, server // we just need the server @@ -366,13 +398,14 @@ class db_pgsql return $v['server']; } - // METHOD: _db_array_parse + // METHOD: __dbArrayParse + // WAS : _db_array_parse // PARAMS: input text, output array [needed] // [internal] limit: are we at the end of the parse // [internal] offset: shift for {} // RETURN: array with the elements // DESC : postgresql array to php array - public function _db_array_parse($text, &$output, $limit = false, $offset = 1) + public function __dbArrayParse($text, &$output, $limit = false, $offset = 1) { if (false === $limit) { $limit = strlen($text) - 1; @@ -395,3 +428,5 @@ class db_pgsql return $output; } } + +# __END__ diff --git a/www/lib/CoreLibs/Language/Core/CachedFileReader.inc b/www/lib/CoreLibs/Language/Core/CachedFileReader.inc new file mode 100755 index 00000000..a2245e5e --- /dev/null +++ b/www/lib/CoreLibs/Language/Core/CachedFileReader.inc @@ -0,0 +1,48 @@ +. + + This file is part of PHP-gettext. + + PHP-gettext is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + PHP-gettext is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with PHP-gettext; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +namespace CoreLibs\Language\Core; + +// Preloads entire file in memory first, then creates a StringReader +// over it (it assumes knowledge of StringReader internals) +class CachedFileReader extends CoreLibs\Language\Core\StringReader +{ + public function __construct($filename) + { + if (file_exists($filename)) { + $length = filesize($filename); + $fd = fopen($filename, 'rb'); + + if (!$fd) { + $this->error = 3; // Cannot read file, probably permissions + return false; + } + $this->_str = fread($fd, $length); + fclose($fd); + } else { + $this->error = 2; // File doesn't exist + return false; + } + } +} + +# __END__ diff --git a/www/lib/CoreLibs/Language/Core/FileReader.inc b/www/lib/CoreLibs/Language/Core/FileReader.inc index 56ad959d..bfbdba78 100755 --- a/www/lib/CoreLibs/Language/Core/FileReader.inc +++ b/www/lib/CoreLibs/Language/Core/FileReader.inc @@ -1,5 +1,25 @@ . + + This file is part of PHP-gettext. + + PHP-gettext is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + PHP-gettext is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with PHP-gettext; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + namespace CoreLibs\Language\Core; class FileReader diff --git a/www/lib/CoreLibs/Language/Core/StreamReader.inc b/www/lib/CoreLibs/Language/Core/StreamReader.inc new file mode 100755 index 00000000..805db260 --- /dev/null +++ b/www/lib/CoreLibs/Language/Core/StreamReader.inc @@ -0,0 +1,54 @@ +. + + This file is part of PHP-gettext. + + PHP-gettext is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + PHP-gettext is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with PHP-gettext; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +namespace CoreLibs\Language\Core; + +// Simple class to wrap file streams, string streams, etc. +// seek is essential, and it should be byte stream +class StreamReader +{ + // should return a string [FIXME: perhaps return array of bytes?] + public function read($bytes) + { + return false; + } + + // should return new position + public function seekto($position) + { + return false; + } + + // returns current position + public function currentpos() + { + return false; + } + + // returns length of entire stream (limit for seekto()s) + public function length() + { + return false; + } +} + +# __END__ diff --git a/www/lib/CoreLibs/Language/Core/StringReader.inc b/www/lib/CoreLibs/Language/Core/StringReader.inc new file mode 100755 index 00000000..e1c63818 --- /dev/null +++ b/www/lib/CoreLibs/Language/Core/StringReader.inc @@ -0,0 +1,67 @@ +. + + This file is part of PHP-gettext. + + PHP-gettext is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + PHP-gettext is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with PHP-gettext; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +namespace CoreLibs\Language\Core; + +class StringReader +{ + public $sr_pos; + public $sr_str; + + public function __construct($str = '') + { + $this->sr_str = $str; + $this->sr_pos = 0; + } + + public function read($bytes) + { + $data = substr($this->sr_str, $this->sr_pos, $bytes); + $this->sr_pos += $bytes; + if (strlen($this->sr_str) < $this->sr_pos) { + $this->sr_pos = strlen($this->sr_str); + } + + return $data; + } + + public function seekto($pos) + { + $this->sr_pos = $pos; + if (strlen($this->sr_str) < $this->sr_pos) { + $this->sr_pos = strlen($this->sr_str); + } + return $this->sr_pos; + } + + public function currentpos() + { + return $this->sr_pos; + } + + public function length() + { + return strlen($this->sr_str); + } +} + +# __END__ diff --git a/www/lib/CoreLibs/Language/Core/streams.php b/www/lib/CoreLibs/Language/Core/streams.php deleted file mode 100644 index 34a71e3e..00000000 --- a/www/lib/CoreLibs/Language/Core/streams.php +++ /dev/null @@ -1,182 +0,0 @@ -. - - This file is part of PHP-gettext. - - PHP-gettext is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - PHP-gettext is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with PHP-gettext; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - - - // Simple class to wrap file streams, string streams, etc. - // seek is essential, and it should be byte stream -class StreamReader -{ - // should return a string [FIXME: perhaps return array of bytes?] - public function read($bytes) - { - return false; - } - - // should return new position - public function seekto($position) - { - return false; - } - - // returns current position - public function currentpos() - { - return false; - } - - // returns length of entire stream (limit for seekto()s) - public function length() - { - return false; - } -} - -class StringReader -{ - public $_pos; - public $_str; - - public function __construct($str = '') - { - $this->_str = $str; - $this->_pos = 0; - } - - public function read($bytes) - { - $data = substr($this->_str, $this->_pos, $bytes); - $this->_pos += $bytes; - if (strlen($this->_str)<$this->_pos) { - $this->_pos = strlen($this->_str); - } - - return $data; - } - - public function seekto($pos) - { - $this->_pos = $pos; - if (strlen($this->_str)<$this->_pos) { - $this->_pos = strlen($this->_str); - } - return $this->_pos; - } - - public function currentpos() - { - return $this->_pos; - } - - public function length() - { - return strlen($this->_str); - } -} - - -class FileReader -{ - public $_pos; - public $_fd; - public $_length; - - public function __construct($filename) - { - if (file_exists($filename)) { - $this->_length=filesize($filename); - $this->_pos = 0; - $this->_fd = fopen($filename, 'rb'); - if (!$this->_fd) { - $this->error = 3; // Cannot read file, probably permissions - return false; - } - } else { - $this->error = 2; // File doesn't exist - return false; - } - } - - public function read($bytes) - { - if ($bytes) { - fseek($this->_fd, $this->_pos); - - // PHP 5.1.1 does not read more than 8192 bytes in one fread() - // the discussions at PHP Bugs suggest it's the intended behaviour - $data = ''; - while ($bytes > 0) { - $chunk = fread($this->_fd, $bytes); - $data .= $chunk; - $bytes -= strlen($chunk); - } - $this->_pos = ftell($this->_fd); - - return $data; - } else { - return ''; - } - } - - public function seekto($pos) - { - fseek($this->_fd, $pos); - $this->_pos = ftell($this->_fd); - return $this->_pos; - } - - public function currentpos() - { - return $this->_pos; - } - - public function length() - { - return $this->_length; - } - - public function close() - { - fclose($this->_fd); - } -} - -// Preloads entire file in memory first, then creates a StringReader -// over it (it assumes knowledge of StringReader internals) -class CachedFileReader extends StringReader -{ - public function __construct($filename) - { - if (file_exists($filename)) { - $length=filesize($filename); - $fd = fopen($filename, 'rb'); - - if (!$fd) { - $this->error = 3; // Cannot read file, probably permissions - return false; - } - $this->_str = fread($fd, $length); - fclose($fd); - } else { - $this->error = 2; // File doesn't exist - return false; - } - } -} diff --git a/www/lib/CoreLibs/Language/l10.inc b/www/lib/CoreLibs/Language/L10n.inc similarity index 81% rename from www/lib/CoreLibs/Language/l10.inc rename to www/lib/CoreLibs/Language/L10n.inc index 7b22cefd..5d4575f6 100644 --- a/www/lib/CoreLibs/Language/l10.inc +++ b/www/lib/CoreLibs/Language/L10n.inc @@ -2,7 +2,7 @@ /********************************************************************* * AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org) * CREATED: 2004/11/18 -* VERSION: 0.1.1 +* VERSION: 1.0.0 * RELEASED LICENSE: GNU GPL 3 * SHORT DESCRIPTION: * init class for gettext. Original was just a function & var setting include for wordpress. @@ -14,7 +14,7 @@ * * PUBLIC METHODS * __: returns string (translated or original if not found) -* _e: echos out string (translated or original if not found) +* __e: echos out string (translated or original if not found) * __ngettext: should return plural. never tested this. * * PRIVATE METHODS @@ -23,10 +23,12 @@ * 2005/10/17 (cs) made an on the fly switch method (reload of lang) *********************************************************************/ -// try to include file from LIBS path, or from normal path -_spl_autoload('Class.Basic.inc'); +namespace CoreLibs\Language; -class l10n extends basic +use \CoreLibs\Language\Core\FileReader; +use \CoreLibs\Language\Core\GetTextReader; + +class L10n extends \CoreLibs\Basic { private $lang = ''; private $mofile = ''; @@ -35,10 +37,6 @@ class l10n extends basic public function __construct($lang = '', $path = DEFAULT_TEMPLATE) { - foreach (array('streams.php', 'gettext.php') as $include_file) { - _spl_autoload($include_file); - } - if (!$lang) { $this->lang = 'en'; } else { @@ -60,7 +58,7 @@ class l10n extends basic $this->input = false; } - $this->l10n = new gettext_reader($this->input); + $this->l10n = new GetTextReader($this->input); } // reloads the mofile, if the location of the lang file changes @@ -82,7 +80,7 @@ class l10n extends basic // check if get a readable mofile if (is_readable($this->mofile)) { $this->input = new FileReader($this->mofile); - $this->l10n = new gettext_reader($this->input); + $this->l10n = new GetTextReader($this->input); } else { // else fall back to the old ones $this->mofile = $old_mofile; @@ -95,7 +93,7 @@ class l10n extends basic return $this->l10n->translate($text); } - public function _e($text) + public function __e($text) { echo $this->l10n->translate($text); } @@ -106,12 +104,12 @@ class l10n extends basic return $this->l10n->ngettext($single, $plural, $number); } - public function __get_lang() + public function __getLang() { return $this->lang; } - public function __get_mofile() + public function __getMoFile() { return $this->mofile; } diff --git a/www/lib/CoreLibs/Output/Form/Generate.inc b/www/lib/CoreLibs/Output/Form/Generate.inc index 00eed11c..31eba366 100644 --- a/www/lib/CoreLibs/Output/Form/Generate.inc +++ b/www/lib/CoreLibs/Output/Form/Generate.inc @@ -210,10 +210,9 @@ * save data, loads data, etc *********************************************************************/ -// try to include file from LIBS path, or from normal path -_spl_autoload('Class.DB.Array.IO.inc'); +namespace CoreLibs\Output\Form; -class form extends db_array_io +class Generate extends \CoreLibs\DB\Extended\ArrayIO { // rest public $field_array = array (); // for the load statetment describes which elements from the load query should be shown and i which format @@ -244,23 +243,20 @@ class form extends db_array_io // now some default error msgs (english) public $language_array = array (); - // METHOD constructor - // PARAMS $db_config -> connect to DB - // $lang -> language code ("en", "ja", etc) - // $table_width -> width of table - // $db_debug -> turns db_io debug on/off (DB_DEBUG as global var does the same) + // METHOD: constructor + // PARAMS: $db_config -> connect to DB + // $lang -> language code ("en", "ja", etc) + // $table_width -> width of table + // $db_debug -> turns db_io debug on/off (DB_DEBUG as global var does the same) public function __construct($db_config, $lang, $table_width = 750, $debug = 0, $db_debug = 0, $echo = 1, $print = 0) { - $this->my_page_name = $this->get_page_name(1); + $this->my_page_name = $this->getPageName(1); // init the language class - _spl_autoload('Class.l10n.inc'); - $this->l = new l10n($lang); + $this->l = new \CoreLibs\Language\L10n($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 -// $flag = _spl_autoload('array_'.$this->my_page_name.'.inc'); include(TABLE_ARRAYS."array_".$this->my_page_name.".inc"); - $config_array = ${$this->my_page_name}; // start the array_io class which will start db_io ... @@ -316,7 +312,7 @@ class form extends db_array_io } // dumps all values into output (for error msg) - public function form_dump_table_array() + public function formDumpTableArray() { if (!is_array($this->table_array)) { $this->table_array = array (); @@ -338,49 +334,14 @@ class form extends db_array_io parent::__destruct(); } - /***************************************************** - Along here are wrapper functions for the former, old names - */ - - public function form_load() - { - return $this->form_create_load(); - } - - public function form_new($hide_new_checkbox = 0) - { - return $this->form_create_new($hide_new_checkbox); - } - - public function form_delete_save($hide_delete = 0, $hide_delete_checkbox = 0) - { - return $this->form_create_save_delete($hide_delete, $hide_delete_checkbox); - } - - public function form_error_msg() - { - return $this->form_print_msg(); - } - - public function form_show_reference_table($table_name) - { - return $this->form_create_element_reference_table($table_name); - } - - public function form_show_list_table($table_name) - { - return $this->form_create_element_list_table($table_name); - } - - // END wrapper - - // METHOD form_get_col_name_from_key - // PARAMS $want_key: the key where u want the data from - // $key_value: if set searches for special right value - // RETURN the value of the $want_key array field - // works only with fields that appear only ONCE - // if multiple gets only FIRST - public function form_get_col_name_from_key($want_key, $key_value = "") + // METHOD: formGetColNameFromKey + // WAS : form_get_col_name_from_key + // PARAMS: $want_key: the key where u want the data from + // $key_value: if set searches for special right value + // RETURN: the value of the $want_key array field + // works only with fields that appear only ONCE + // if multiple gets only FIRST + public function formGetColNameFromKey($want_key, $key_value = "") { if (!is_array($this->table_array)) { $this->table_array = array (); @@ -395,11 +356,12 @@ class form extends db_array_io } } - // METHOD form_get_col_name_array_from_key - // PARAMS $want_key: the key where u want the data from - // $key_value: if set searches for special right value - // RETURN array of fields - public function form_get_col_name_array_from_key($want_key, $key_value = "") + // METHOD: formGetColNameArrayFromKey + // WAS : form_get_col_name_array_from_key + // PARAMS: $want_key: the key where u want the data from + // $key_value: if set searches for special right value + // RETURN: array of fields + public function formGetColNameArrayFromKey($want_key, $key_value = "") { $key_array = array(); if (!is_array($this->table_array)) { @@ -417,10 +379,11 @@ class form extends db_array_io return $key_array; } - // METHOD form_print_msg - // PARAMS none - // RETURN formated output for the error && warning msg - public function form_print_msg() + // METHOD: formPrintMsg + // WAS : form_print_msg + // PARAMS: none + // RETURN: formated output for the error && warning msg + public function formPrintMsg() { if ($this->error) { $class = "error"; @@ -432,11 +395,12 @@ class form extends db_array_io } // next for functions are pre_test fkts for easier default new,load, etc handling - // METHOD form_procedure_load - // PARAMS archive_id - which ID should be loaded - // RETURN none - // DESC default load procedure - public function form_procedure_load($archive_id) + // METHOD: formProcedureLoad + // WAS : form_procedure_load + // PARAMS: archive_id - which ID should be loaded + // RETURN: none + // DESC : default load procedure + public function formProcedureLoad($archive_id) { if ($this->archive && $archive_id && $this->group_level_user <= $this->security_level["load"]) { $this->form_load_table_array($archive_id); @@ -444,11 +408,12 @@ class form extends db_array_io } } - // METHOD form_procedure_new - // PARAMS none - // RETURN none - // DESC default new procedure - public function form_procedure_new() + // METHOD: formProcedureNew + // WAS : form_procedure_new + // PARAMS: none + // RETURN: none + // DESC : default new procedure + public function formProcedureNew() { if ($this->new && $this->group_level_user <= $this->security_level["new"]) { if ($this->really_new == "yes") { @@ -461,11 +426,12 @@ class form extends db_array_io } } - // METHOD form_procedure_save - // PARAMS none - // RETURN none - // DESC default save procedure - public function form_procedure_save() + // METHOD: formProcedureSave + // WAS : form_procedure_save + // PARAMS: none + // RETURN: none + // DESC : default save procedure + public function formProcedureSave() { if ($this->save && $this->group_level_user <= $this->security_level["save"]) { $this->form_error_check(); @@ -476,11 +442,12 @@ class form extends db_array_io } } - // METHOD form_procedure_delete - // PARAMS none - // RETURN none - // DESC default delete procedure - public function form_procedure_delete() + // METHOD: formProcedureDelete + // WAS : form_procedure_delete + // PARAMS: none + // RETURN: none + // DESC : default delete procedure + public function formProcedureDelete() { // delete is also by "protected" if ($this->delete && $this->group_level_user <= $this->security_level["delete"] && !$this->table_array["protected"]["value"]) { @@ -498,16 +465,17 @@ class form extends db_array_io } } - // METHOD form_procedure_delete_from_element_list - // PARAMS none - // RETURN none - // DESC default delete procedure - public function form_procedure_delete_from_element_list($element_list, $remove_name) + // METHOD: formProcedureDeleteFromElementList + // WAS : form_procedure_delete_from_element_list + // PARAMS: none + // RETURN: none + // DESC : default delete procedure + public function formProcedureDeleteFromElementList($element_list, $remove_name) { // only do if the user is allowed to delete if ($this->group_level_user <= $this->security_level["delete"] && !$this->table_array["protected"]["value"] && !$this->error) { for ($i = 0; $i < count($element_list); $i ++) { -//$this->debug('form_error', "Array: ".is_array($this->element_list[$element_list[$i]]["read_data"])." | ".$this->element_list[$element_list[$i]]["delete"]); + // $this->debug('form_error', "Array: ".is_array($this->element_list[$element_list[$i]]["read_data"])." | ".$this->element_list[$element_list[$i]]["delete"]); // if prefix, set it $prfx = ($this->element_list[$element_list[$i]]["prefix"]) ? $this->element_list[$element_list[$i]]["prefix"]."_" : ''; // get the primary key @@ -540,13 +508,13 @@ class form extends db_array_io } } } elseif (is_array($this->element_list[$element_list[$i]]["read_data"]) && $this->element_list[$element_list[$i]]["delete"]) { -//$this->debug('form_clean', "ID [$id] [$prfx.$pk_name]"); -//$this->debug('form_clean', "ID arr: ".$this->print_ar($_POST[$id])); -//$this->debug('form_clean', "PK arr: ".$this->print_ar($_POST[$prfx.$pk_name])); + // $this->debug('form_clean', "ID [$id] [$prfx.$pk_name]"); + // $this->debug('form_clean', "ID arr: ".$this->print_ar($_POST[$id])); + // $this->debug('form_clean', "PK arr: ".$this->print_ar($_POST[$prfx.$pk_name])); for ($j = 0; $j < count($_POST[$prfx.$pk_name]); $j ++) { if (!$_POST[$remove_name[$i]][$j] && $_POST[$prfx.$pk_name][$j]) { $q = "DELETE FROM ".$element_list[$i]." WHERE ".$pk_name." = ".$_POST[$prfx.$pk_name][$j]; -// $this->debug('edit_db', "DEL: $q"); + // $this->debug('edit_db', "DEL: $q"); $this->db_exec($q); $this->msg .= $this->l->__("Deleted deselected entries from list
"); $this->warning = 1; @@ -560,10 +528,11 @@ class form extends db_array_io } } - // METHOD form_create_load - // PARAMS none - // RETURN string from "load" part of form ... - public function form_create_load() + // METHOD: formCreateLoad + // WAS : form_create_load + // PARAMS: none + // RETURN: string from "load" part of form ... + public function formCreateLoad() { // when security leve is okay ... if ($this->group_level_user <= $this->security_level["load"]) { @@ -590,19 +559,17 @@ class form extends db_array_io $t_string .= $res[$this->field_array[$i]["name"]]; } } -/* -// -*/ $pk_names[] = $t_string; } } // show it at all return array('t_pk_name' => $t_pk_name, 'pk_ids' => $pk_ids, 'pk_names' => $pk_names, 'pk_selected' => $pk_selected); } - // METHOD form_create_new - // PARAMS none - // RETURN part for new - public function form_create_new($hide_new_checkbox = 0) + // METHOD: formCreateNew + // WAS : form_create_new + // PARAMS: none + // RETURN: part for new + public function formCreateNew($hide_new_checkbox = 0) { // when security level is okay if ($this->group_level_user <= $this->security_level["new"]) { @@ -619,10 +586,11 @@ class form extends db_array_io return array('new_name' => $new_name, 'show_checkbox' => $show_checkbox); } - // METHOD form_create_save_delete - // PARAMS none - // RETURN string for delete / save part - public function form_create_save_delete($hide_delete = 0, $hide_delete_checkbox = 0) + // METHOD: formCreateSaveDelete + // WAS : form_create_save_delete + // PARAMS: none + // RETURN: string for delete / save part + public function formCreateSaveDelete($hide_delete = 0, $hide_delete_checkbox = 0) { if ($this->group_level_user <= $this->security_level["save"] || $this->group_level_user <= $this->security_level["delete"]) { $old_school_hidden = 0; @@ -647,13 +615,14 @@ class form extends db_array_io return array('seclevel_okay' => $seclevel_okay, 'save' => $save, 'pk_name' => $pk_name, 'pk_value' => $pk_value, 'show_delete' => $show_delete, 'hide_delete_checkbox' => $hide_delete_checkbox); } // end of function - // METHOD form_create_element - // PARAMS $element_name: the name from the array, you want to have build - // $query: can overrule internal query data, - // for drop down, as data comes from a reference table - // for drop_down_text it has to be an array with $key->$value - // RETURN element in HTML - public function form_create_element($element_name, $query = "") + // METHOD: formCreateElement + // WAS : form_create_element + // PARAMS: $element_name: the name from the array, you want to have build + // $query: can overrule internal query data, + // for drop down, as data comes from a reference table + // for drop_down_text it has to be an array with $key->$value + // RETURN: element in HTML + public function formCreateElement($element_name, $query = "") { // special 2nd color for "binary" attribut if ($this->table_array[$element_name]["type"] == "binary" && !$this->table_array[$element_name]["value"]) { @@ -824,13 +793,14 @@ class form extends db_array_io return array('output_name' => $output_name, 'color' => $EDIT_FGCOLOR_T, 'type' => $type, 'data' => $data); } - // METHOD form_error_check - // PARAMS none - // RETURNS full error message string for output + // METHOD: formErrorCheck + // WAS : form_error_check + // PARAMS: none + // RETURN: full error message string for output // should be cought like this ... // if ($msg=$form->form_error_check()) // $error=1; - public function form_error_check() + public function formErrorCheck() { if (!is_array($this->table_array)) { $this->table_array = array (); @@ -841,7 +811,7 @@ class form extends db_array_io // if error value set && somethign input, check if input okay if ($value["error_check"] && $this->table_array[$key]["value"]) { // each error check can be a piped seperated value, lets split it -//$this->debug('edit', $value["error_check"]); + // $this->debug('edit', $value["error_check"]); foreach (explode('|', $value["error_check"]) as $error_check) { switch ($error_check) { case "number": @@ -889,20 +859,20 @@ class form extends db_array_io } break; case "alphanumericspace": -//$this->debug('edit', 'IN Alphanumericspace'); + // $this->debug('edit', 'IN Alphanumericspace'); if (!preg_match("/^[0-9A-Za-z\ ]+$/", $this->table_array[$key]["value"])) { $this->msg .= sprintf($this->l->__("Please enter a valid alphanumeric (Numbers and Letters, spaces allowed) value for the %s Field!
"), $this->table_array[$key]["output_name"]); } break; case "alphanumeric": -//$this->debug('edit', 'IN Alphanumeric'); + // $this->debug('edit', 'IN Alphanumeric'); if (!preg_match("/^[0-9A-Za-z_\-]+$/", $this->table_array[$key]["value"])) { $this->msg .= sprintf($this->l->__("Please enter a valid alphanumeric (Numbers and Letters only also - and _, no spaces) value for the %s Field!
"), $this->table_array[$key]["output_name"]); } break; // this one also allows @ and . case "alphanumericextended": -//$this->debug('edit', 'IN Alphanumericextended'); + // $this->debug('edit', 'IN Alphanumericextended'); if (!preg_match("/^[0-9A-Za-z_\-@\.]+$/", $this->table_array[$key]["value"])) { $this->msg .= sprintf($this->l->__("Please enter a valid alphanumeric extended (Numbers, Letters, -, _, @ and . only, no spaces) value for the %s Field!
"), $this->table_array[$key]["output_name"]); } @@ -928,7 +898,7 @@ class form extends db_array_io // main if end ) { // if mandatory && no input -//$this->debug('form', "A: ".$this->table_array[$key]["type"]." -- ".$this->table_array[$key]["input_value"]." -- ".$this->table_array[$key]["value"]); + // $this->debug('form', "A: ".$this->table_array[$key]["type"]." -- ".$this->table_array[$key]["input_value"]." -- ".$this->table_array[$key]["value"]); if (!$this->table_array[$key]["value"] && $this->table_array[$key]["type"] != "binary") { $this->msg .= sprintf($this->l->__("Please enter something into the %s field!
"), $this->table_array[$key]["output_name"]); } @@ -964,7 +934,7 @@ class form extends db_array_io } } } -//$this->debug('edit_error', "QS:
".print_r($_POST, 1)."
"); + // $this->debug('edit_error', "QS:
".print_r($_POST, 1)."
"); if (is_array($this->element_list)) { // check the mandatory stuff // if mandatory, check that at least on pk exists or if at least the mandatory field is filled @@ -988,10 +958,10 @@ class form extends db_array_io if (count($_POST[$prfx.$key]) > $max) { $max = count($_POST[$prfx.$key]); } -//$this->debug('edit_error_chk', "KEY: $prfx$key | count: ".count($_POST[$prfx.$key])." | M: $max"); -//$this->debug('edit_error_chk', "K: ".$_POST[$prfx.$key]." | ".$_POST[$prfx.$key][0]); + // $this->debug('edit_error_chk', "KEY: $prfx$key | count: ".count($_POST[$prfx.$key])." | M: $max"); + // $this->debug('edit_error_chk', "K: ".$_POST[$prfx.$key]." | ".$_POST[$prfx.$key][0]); } -//$this->debug('post_array', $this->print_ar($_POST)); + $this->debug('post_array', $this->print_ar($_POST)); # check each row for ($i = 0; $i < $max; $i ++) { // either one of the post pks is set, or the mandatory @@ -1005,18 +975,18 @@ class form extends db_array_io } // we found a mandatory field. check now if one is set to satisfy the main mandatory // also check, if this field is mandatory and its not set, but any other, throw an error -//$this->debug('edit_error_chk', "RG error - Data[".$prfx.$el_name.": ".$_POST[$prfx.$el_name][$i]." | ".$_POST[$prfx.$el_name]." - ".$reference_array['enable_name']." - ".$_POST[$reference_array['enable_name']][$_POST[$prfx.$el_name][$i]]); + // $this->debug('edit_error_chk', "RG error - Data[".$prfx.$el_name.": ".$_POST[$prfx.$el_name][$i]." | ".$_POST[$prfx.$el_name]." - ".$reference_array['enable_name']." - ".$_POST[$reference_array['enable_name']][$_POST[$prfx.$el_name][$i]]); if ($data_array["mandatory"] && $_POST[$prfx.$el_name][$i]) { $mand_okay = 1; $row_okay[$i] = 1; } elseif ($data_array['type'] == 'radio_group' && !isset($_POST[$prfx.$el_name])) { // radio group and set where one not active -//$this->debug('edit_error_chk', "RADIO GROUP"); + // $this->debug('edit_error_chk', "RADIO GROUP"); $row_okay[$_POST[$prfx.$el_name][$i]] = 0; $default_wrong[$_POST[$prfx.$el_name][$i]] = 1; $error[$_POST[$prfx.$el_name][$i]] = 1; } elseif ($_POST[$prfx.$el_name][$i] && !$error[$i]) { -//$this->debug('edit_error_chk', "[$i]"); + // $this->debug('edit_error_chk', "[$i]"); $element_set[$i] = 1; $row_okay[$i] = 1; } elseif ($data_array["mandatory"] && !$_POST[$prfx.$el_name][$i]) { @@ -1068,11 +1038,12 @@ class form extends db_array_io } } - // METHOD form_set_order - // PARAMS none - // RETURN the table array - // DOES sets the order to the maximum, if order flag is set in array - public function form_set_order() + // METHOD: formSetOrder + // WAS: form_set_order + // PARAMS: none + // RETURN: the table array + // DESC : sets the order to the maximum, if order flag is set in array + public function formSetOrder() { // get order name $order_name = $this->form_get_col_name_from_key("order"); @@ -1095,11 +1066,12 @@ class form extends db_array_io return $this->table_array; } - // METHOD form_unsert_table_array - // PARAMS none - // RETURN none - // DOES resets all values in table_array and in the reference tables - public function form_unset_table_array() + // METHOD: formUnsetTableArray + // WAS : form_unsert_table_array + // PARAMS: none + // RETURN: none + // DESC : resets all values in table_array and in the reference tables + public function formUnsetTableArray() { unset($this->pk_id); if (!is_array($this->table_array)) { @@ -1127,11 +1099,12 @@ class form extends db_array_io $this->msg = $this->l->__("Cleared for new Dataset!"); } - // METHOD form_load_table_array - // PARAMS pk_id - overrule pk_id - // RETURN none - // DESC load a table & reference - public function form_load_table_array($pk_id = 0) + // METHOD: formLoadTableArray + // WAS : form_load_table_array + // PARAMS: pk_id - overrule pk_id + // RETURN: none + // DESC : load a table & reference + public function formLoadTableArray($pk_id = 0) { if ($pk_id) { $this->pk_id = $pk_id; @@ -1165,11 +1138,12 @@ class form extends db_array_io $this->msg = $this->l->__("Dataset has been loaded!
"); } - // METHOD form_save_table_array - // PARAMS addslashes - if one, passes 1 to the db_write function - // RETURN none - // DESC save a table, reference and all input fields - public function form_save_table_array($addslashes = 0) + // METHOD: formSaveTableArray + // WAS : form_save_table_array + // PARAMS: addslashes - if one, passes 1 to the db_write function + // RETURN: none + // DESC : save a table, reference and all input fields + public function formSaveTableArray($addslashes = 0) { // global $_FILES; // for drop_down_db_input check if text field is filled and if, if not yet in db ... @@ -1419,11 +1393,12 @@ class form extends db_array_io $this->msg = $this->l->__("Dataset has been saved!
"); } - // METHOD form_delete_table_array - // PARAMS none - // RETURN none - // DESC delete a table and reference fields - public function form_delete_table_array() + // METHOD: formDeleteTableArray + // WAS : form_delete_table_array + // PARAMS: none + // RETURN: none + // DESC : delete a table and reference fields + public function formDeleteTableArray() { // remove any reference arrays if (is_array($this->reference_array)) { @@ -1462,11 +1437,12 @@ class form extends db_array_io $this->msg = $this->l->__("Dataset has been deleted!"); } - // METHOD form_create_hidden_fields - // PARAMS $hidden_array - // RETURNS the input fields (html) - // creates HTML hidden input fields out of an hash array - public function form_create_hidden_fields($hidden_array = "") + // METHOD: formCreateHiddenFields + // WAS : form_create_hidden_fields + // PARAMS: $hidden_array + // RETURN: the input fields (html) + // DESC : creates HTML hidden input fields out of an hash array + public function formCreateHiddenFields($hidden_array = "") { $hidden = array (); if (!is_array($this->table_array)) { @@ -1487,11 +1463,12 @@ class form extends db_array_io return $hidden; } - // METHOD form_create_element_reference_table - // PARAMS show which reference table - // RETURN array for output - // DESC creates the multiple select part for a reference_table - public function form_create_element_reference_table($table_name) + // METHOD: formCreateElementReferenceTable + // WAS : form_create_element_reference_table + // PARAMS: show which reference table + // RETURN: array for output + // DESC : creates the multiple select part for a reference_table + public function formCreateElementReferenceTable($table_name) { $output_name = $this->reference_array[$table_name]["output_name"]; if ($this->reference_array[$table_name]["mandatory"]) { @@ -1508,13 +1485,14 @@ class form extends db_array_io return array('output_name' => $output_name, 'type' => $type, 'color' => 'edit_fgcolor', 'data' => $data); } - // METHOD form_create_element_list - // PARAMS show which element list - // RETURN array for output - // DESC create list of elements next to each other for a group of data in an input field - // this currently only works for a list that is filled from a sub table and creates only a connection to this one - // new version will allow a sub list with free input fields to directly fill a sub table to a master table - public function form_create_element_list_table($table_name) + // METHOD: formCreateElementListTable + // WAS : form_create_element_list + // PARAMS: show which element list + // RETURN: array for output + // DESC : create list of elements next to each other for a group of data in an input field + // this currently only works for a list that is filled from a sub table and creates only a connection to this one + // new version will allow a sub list with free input fields to directly fill a sub table to a master table + public function formCreateElementListTable($table_name) { // output name for the viewable left table td box, prefixed with * if mandatory $output_name = $this->element_list[$table_name]["output_name"]; @@ -1547,7 +1525,7 @@ class form extends db_array_io // generic data read in (counts for all rows) // visible list data output while (list($el_name, $data_array) = each($this->element_list[$table_name]["elements"])) { -// $this->debug('CFG', 'El: '.$el_name.' -> '.$this->print_ar($data_array)); + $this->debug('CFG', 'El: '.$el_name.' -> '.$this->print_ar($data_array)); // if the element name matches the read array, then set the table as a name prefix $q_select[] = $el_name; // this is for reading the data // prefix the name for any further data parts @@ -1566,7 +1544,7 @@ class form extends db_array_io if ($data_array['type'] == 'drop_down_db') { $md_q = md5($data_array['query']); while ($res = $this->db_return($data_array['query'])) { -//$this->debug('edit', "Q[$md_q] pos: ".$this->cursor_ext[$md_q]["pos"]." | want: ".$data_array["preset"]." | set: ".$data['preset'][$el_name]); + $this->debug('edit', "Q[$md_q] pos: ".$this->cursor_ext[$md_q]["pos"]." | want: ".$data_array["preset"]." | set: ".$data['preset'][$el_name]); // first is default for this element if (!$data['preset'][$el_name] && ($this->cursor_ext[$md_q]["pos"] == $data_array['preset'])) { $data['preset'][$el_name] = $res[0]; @@ -1580,11 +1558,11 @@ class form extends db_array_io } $proto[$el_name] = ($this->error) ? $_POST[$el_name][(count($_POST[$el_name]) - 1)] : ''; // this is for the new line } -// $this->debug('CFG DATA', 'Data: '.$this->print_ar($data)); -// $this->debug('CFG PROTO', 'Proto: '.$this->print_ar($proto)); -// $this->debug('CFG SELECT', 'Proto: '.$this->print_ar($q_select)); + // $this->debug('CFG DATA', 'Data: '.$this->print_ar($data)); + // $this->debug('CFG PROTO', 'Proto: '.$this->print_ar($proto)); + // $this->debug('CFG SELECT', 'Proto: '.$this->print_ar($q_select)); // query for reading in the data -//$this->debug('edit_error', "ERR: ".$this->error); + $this->debug('edit_error', "ERR: ".$this->error); // if we got a read data, build the read select for the read, and read out the "selected" data if ($this->element_list[$table_name]["read_data"]) { // we need a second one for the query build only @@ -1604,18 +1582,18 @@ class form extends db_array_io $data['type'][$data["prefix"].$this->element_list[$table_name]["read_data"]["name"]] = 'string'; // build the read query $q = "SELECT "; -// if (!$this->table_array[$this->int_pk_name]["value"]) -// $q .= "DISTINCT "; + // if (!$this->table_array[$this->int_pk_name]["value"]) + // $q .= "DISTINCT "; // prefix join key with table name, and implode the query select part $q .= str_replace($table_name.'.'.$this->element_list[$table_name]["read_data"]["pk_id"], $this->element_list[$table_name]["read_data"]["table_name"].'.'.$this->element_list[$table_name]["read_data"]["pk_id"], implode(', ', $_q_select)).' '; -// if (!$this->table_array[$this->int_pk_name]["value"] && $this->element_list[$table_name]["read_data"]["order"]) -// $q .= ", ".$this->element_list[$table_name]["read_data"]["order"]." "; + // if (!$this->table_array[$this->int_pk_name]["value"] && $this->element_list[$table_name]["read_data"]["order"]) + // $q .= ", ".$this->element_list[$table_name]["read_data"]["order"]." "; // read from the read table as main, and left join to the sub table to read the actual data $q .= "FROM ".$this->element_list[$table_name]["read_data"]["table_name"]." "; $q .= "LEFT JOIN ".$table_name." "; $q .= "ON ("; $q .= $this->element_list[$table_name]["read_data"]["table_name"].".".$this->element_list[$table_name]["read_data"]["pk_id"]." = ".$table_name.".".$this->element_list[$table_name]["read_data"]["pk_id"]." "; -// if ($this->table_array[$this->int_pk_name]["value"]) + // if ($this->table_array[$this->int_pk_name]["value"]) $q .= "AND ".$table_name.".".$this->int_pk_name." = ".(($this->table_array[$this->int_pk_name]["value"]) ? $this->table_array[$this->int_pk_name]["value"] : 'NULL')." "; $q .= ") "; if ($this->element_list[$table_name]["read_data"]["order"]) { @@ -1628,7 +1606,7 @@ class form extends db_array_io $q = "SELECT ".implode(", ", $q_select)." FROM ".$table_name." WHERE ".$this->int_pk_name." = ".$this->table_array[$this->int_pk_name]["value"]; } } -// $this->debug('CFG QUERY', 'Q: '.$q); + // $this->debug('CFG QUERY', 'Q: '.$q); // only run if we have query strnig if ($q) { $pos = 0; // position in while for overwrite if needed @@ -1640,7 +1618,7 @@ class form extends db_array_io for ($i = 0; $i < count($q_select); $i ++) { // query select part, set to the element name $el_name = $q_select[$i]; -//$this->debug('edit_error', "[$i] ELNAME: $el_name | POS[$prfx$el_name]: ".$_POST[$prfx.$el_name][$pos]." | RES: ".$res[$el_name]); + // $this->debug('edit_error', "[$i] ELNAME: $el_name | POS[$prfx$el_name]: ".$_POST[$prfx.$el_name][$pos]." | RES: ".$res[$el_name]); // if we have an error, we take what we have in the vars, if not we take the data from the db if ($this->error) { // if we have a radio group, set a bit different @@ -1700,8 +1678,10 @@ class form extends db_array_io if ($data['delete_name']) { $data['content'][] = $proto; } -//$this->debug('edit', "A:
".print_r($data, 1)."
"); + // $this->debug('edit', "A:
".print_r($data, 1)."
"); $type = 'element_list'; return array('output_name' => $output_name, 'type' => $type, 'color' => 'edit_fgcolor', 'data' => $data); } } // end of class + +# __END__ \ No newline at end of file diff --git a/www/lib/CoreLibs/Output/Progressbar.inc b/www/lib/CoreLibs/Output/Progressbar.inc index 73e5067d..6dd42249 100644 --- a/www/lib/CoreLibs/Output/Progressbar.inc +++ b/www/lib/CoreLibs/Output/Progressbar.inc @@ -11,6 +11,8 @@ * */ +namespace CoreLibs\Output; + class ProgressBar { // private vars @@ -80,13 +82,13 @@ class ProgressBar $this->height = $height; } // needs to be called twice or I do not get any output - $this->_flushCache($this->clear_buffer_size_init); - $this->_flushCache($this->clear_buffer_size_init); + $this->__flushCache($this->clear_buffer_size_init); + $this->__flushCache($this->clear_buffer_size_init); } // private functions - private function _flushCache($clear_buffer_size = 0) + private function __flushCache($clear_buffer_size = 0) { if (!$clear_buffer_size) { $clear_buffer_size = $this->clear_buffer_size; @@ -96,7 +98,7 @@ class ProgressBar flush(); } - private function _calculatePercent($step) + private function __calculatePercent($step) { // avoid divison through 0 if ($this->max - $this->min == 0) { @@ -109,7 +111,7 @@ class ProgressBar return $percent; } - private function _calculatePosition($step) + private function __calculatePosition($step) { switch ($this->direction) { case 'right': @@ -162,7 +164,7 @@ class ProgressBar return $position; } - private function _setStep($step) + private function __setStep($step) { if ($step > $this->max) { $step = $this->max; @@ -323,7 +325,7 @@ class ProgressBar $output .= 'document.getElementById("plbl'.$name.$this->code.'").style.align="'.$this->label[$name]['align'].'";'; $output .= ''."\n"; echo $output; - $this->_flushCache(); + $this->__flushCache(); } } @@ -332,7 +334,7 @@ class ProgressBar $this->label[$name]['color'] = $color; if ($this->status != 'new') { echo ''."\n"; - $this->_flushCache(); + $this->__flushCache(); } } @@ -341,7 +343,7 @@ class ProgressBar $this->label[$name]['bgr_color'] = $color; if ($this->status != 'new') { echo ''."\n"; - $this->_flushCache(); + $this->__flushCache(); } } @@ -376,7 +378,7 @@ class ProgressBar $output .= 'document.getElementById("plbl'.$name.$this->code.'").style.font-weight="'.$this->label[$name]['font-weight'].'";'; $output .= ''."\n"; echo $output; - $this->_flushCache(); + $this->__flushCache(); } } @@ -386,7 +388,7 @@ class ProgressBar // print "NAME[$name], Status: ".$this->status.": ".$value."
"; if ($this->status != 'new') { echo ''."\n"; - $this->_flushCache(); + $this->__flushCache(); } } @@ -395,7 +397,7 @@ class ProgressBar $this->color = $color; if ($this->status != 'new') { echo ''."\n"; - $this->_flushCache(); + $this->__flushCache(); } } @@ -404,7 +406,7 @@ class ProgressBar $this->bgr_color = $color; if ($this->status != 'new') { echo ''."\n"; - $this->_flushCache(); + $this->__flushCache(); } } @@ -413,7 +415,7 @@ class ProgressBar $this->direction = $direction; if ($this->status != 'new') { - $this->position = $this->_calculatePosition($this->step); + $this->position = $this->__calculatePosition($this->step); echo ''."\n"; - $this->_flushCache(); + $this->__flushCache(); } } @@ -431,8 +433,8 @@ class ProgressBar $js = ''; $html_button = ''; - $this->_setStep($this->step); - $this->position = $this->_calculatePosition($this->step); + $this->__setStep($this->step); + $this->position = $this->__calculatePosition($this->step); if ($this->top || $this->left) { $style_master = 'position:relative;top:'.$this->top.'px;left:'.$this->left.'px;width:'.($this->width + 10).'px;'; @@ -524,11 +526,11 @@ class ProgressBar // only one inner percent // print "STYLE[$name]: ".$style_lbl."
"; if (!$html_percent) { - $html_percent = '
'.$this->_calculatePercent($this->step).'%
'."\n"; + $html_percent = '
'.$this->__calculatePercent($this->step).'%
'."\n"; } break; case 'percentlbl': - $html .= '
'.$this->_calculatePercent($this->step).'%
'."\n"; + $html .= '
'.$this->__calculatePercent($this->step).'%
'."\n"; break; case 'crossbar': $html .= '
'.$data['value'].'
'."\n"; @@ -578,16 +580,16 @@ class ProgressBar { $this->status = 'show'; echo $this->getHtml(); - $this->_flushCache(); + $this->__flushCache(); } public function moveStep($step) { $last_step = $this->step; - $this->_setStep($step); + $this->__setStep($step); $js = ''; - $new_position = $this->_calculatePosition($this->step); + $new_position = $this->__calculatePosition($this->step); if ($new_position['width'] != $this->position['width'] && ($this->direction == 'right' || $this->direction == 'left')) { if ($this->direction=='left') { $js .= 'PBposition'.$this->code.'("left",'.$new_position['left'].');'; @@ -603,7 +605,7 @@ class ProgressBar $this->position = $new_position; foreach ($this->label as $name => $data) { if (array_key_exists('type', $data)) { - switch($data['type']) { + switch ($data['type']) { case 'step': if ($this->step != $last_step) { $js .= 'PBlabelText'.$this->code.'("'.$name.'","'.$this->step.'/'.$this->max.'");'; @@ -611,8 +613,8 @@ class ProgressBar break; case 'percentlbl': case 'percent': - $percent = $this->_calculatePercent($this->step); - if ($percent != $this->_calculatePercent($last_step)) { + $percent = $this->__calculatePercent($this->step); + if ($percent != $this->__calculatePercent($last_step)) { $js .= 'PBlabelText'.$this->code.'("'.$name.'","'.$percent.'%");'; } break; @@ -624,7 +626,7 @@ class ProgressBar } if ($js != '') { echo ''."\n"; - $this->_flushCache(); + $this->__flushCache(); } } @@ -647,7 +649,7 @@ class ProgressBar $output .= 'document.getElementById("pbm'.$this->code.'").style.visibility="hidden";document.getElementById("pbm'.$this->code.'").style.display="none";'; $output .= ''."\n"; echo $output; - $this->_flushCache(); + $this->__flushCache(); } } @@ -660,7 +662,7 @@ class ProgressBar $output .= 'document.getElementById("pbm'.$this->code.'").style.visibility="visible";document.getElementById("pbm'.$this->code.'").style.visibility="block";'; $output .= ''."\n"; echo $output; - $this->_flushCache(); + $this->__flushCache(); } } } diff --git a/www/lib/CoreLibs/Template/SmartyExtend.Inc b/www/lib/CoreLibs/Template/SmartyExtend.Inc index 67b72b3c..7213610f 100644 --- a/www/lib/CoreLibs/Template/SmartyExtend.Inc +++ b/www/lib/CoreLibs/Template/SmartyExtend.Inc @@ -8,12 +8,14 @@ * 2005/06/22 (cs) include smarty class here, so there is no need to include it in the main file *********************************************************************/ -// read in the Smarty class for definition -// use smarty BC for backwards compability -// try to include file from LIBS path, or from normal path -_spl_autoload('SmartyBC.class.php'); +namespace CoreLibs\Template; -class SmartyML extends SmartyBC +// I need to manually load Smarty BC here (it is not namespaced) +require_once(BASE.LIB.SMARTY.'SmartyBC.class.php'); +// So it doesn't start looking around in the wrong naemspace as smarty doesn't have one +use SmartyBC; + +class SmartyExtend extends SmartyBC { public $l10n; @@ -21,9 +23,10 @@ class SmartyML extends SmartyBC public function __construct($lang) { SmartyBC::__construct(); - _spl_autoload('Class.l10n.inc'); - $this->l10n = new l10n($lang); + $this->l10n = new \CoreLibs\Language\L10n($lang); // variable variable register $this->register_modifier('getvar', array(&$this, 'get_template_vars')); } } + +# __END__