Browse Source

Remove setting session vars, adjust permission checks, resolve some issues, etc

fusionate 1 month ago
parent
commit
3fd4d97404
15 changed files with 125 additions and 129 deletions
  1. 23 1
      app_languages.php
  2. 9 12
      clip_add.php
  3. 5 7
      clip_delete.php
  4. 7 7
      clip_list.php
  5. 2 4
      clip_options.php
  6. 6 6
      clip_options_list.php
  7. 15 16
      clip_update.php
  8. 2 4
      footer.php
  9. 2 4
      header.php
  10. 6 10
      sql_backup.php
  11. 2 4
      sql_db_conversion.php
  12. 15 18
      sql_query.php
  13. 3 4
      sql_query_db.php
  14. 18 20
      sql_query_pdo.php
  15. 10 12
      sql_query_result.php

+ 23 - 1
app_languages.php

@@ -878,4 +878,26 @@ $text['message-problem']['zh-cn'] = "这个要求有个问题。";
 $text['message-problem']['ja-jp'] = "リクエストに問題がありました。";
 $text['message-problem']['ko-kr'] = "요청에 문제가 발생했습니다.";
 
-?>
+$text['title-manage-clips']['en-us'] = "Manage Clips";
+$text['title-manage-clips']['en-gb'] = "Manage Clips";
+$text['title-manage-clips']['ar-eg'] = "شرائط إدارة";
+$text['title-manage-clips']['de-at'] = "Clips verwalten";
+$text['title-manage-clips']['de-ch'] = "Clips verwalten";
+$text['title-manage-clips']['de-de'] = "Clips verwalten";
+$text['title-manage-clips']['es-cl'] = "Gestión de Clips";
+$text['title-manage-clips']['es-mx'] = "Gestión de Clips";
+$text['title-manage-clips']['fr-ca'] = "Gérer les clips";
+$text['title-manage-clips']['fr-fr'] = "Gérer les clips";
+$text['title-manage-clips']['he-il'] = "ניהול קליפים";
+$text['title-manage-clips']['it-it'] = "Gestione Clips";
+$text['title-manage-clips']['nl-nl'] = "Beheer Clips";
+$text['title-manage-clips']['pl-pl'] = "klip";
+$text['title-manage-clips']['pt-br'] = "Gerir Clipes";
+$text['title-manage-clips']['pt-pt'] = "Gerir Clipes";
+$text['title-manage-clips']['ro-ro'] = "Gestionați clipurile";
+$text['title-manage-clips']['ru-ru'] = "Управление клипами";
+$text['title-manage-clips']['sv-se'] = "Hantera Klipp";
+$text['title-manage-clips']['uk-ua'] = "Manage кліпи";
+$text['title-manage-clips']['zh-cn'] = "管理剪辑";
+$text['title-manage-clips']['ja-jp'] = "クリップの管理";
+$text['title-manage-clips']['ko-kr'] = "클립 관리";

+ 9 - 12
clip_add.php

@@ -17,7 +17,7 @@
 
 	The Initial Developer of the Original Code is
 	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2023
+	Portions created by the Initial Developer are Copyright (C) 2008-2025
 	the Initial Developer. All Rights Reserved.
 
 	Contributor(s):
@@ -39,14 +39,16 @@
 	$language = new text;
 	$text = $language->get();
 
+//connect to the database
+	$database = database::new();
+
 if (count($_POST)>0) {
 	$clip_name = $_POST["clip_name"];
 	$clip_folder = $_POST["clip_folder"];
 	$clip_text_start = $_POST["clip_text_start"];
 	$clip_text_end = $_POST["clip_text_end"];
 	$clip_desc = $_POST["clip_desc"];
-	$clip_order = $_POST["clip_order"];
-	if (strlen($clip_order) == 0) { $clip_order = 0; }
+	$clip_order = $_POST["clip_order"] ?? 0;
 
 	//no slashes
 	$clip_name = str_replace('/', '|', $clip_name);
@@ -64,16 +66,13 @@ if (count($_POST)>0) {
 	$p = permissions::new();
 	$p->add('clip_add', 'temp');
 
-	$database = new database;
-	$database->app_name = 'edit';
-	$database->app_uuid = '17e628ee-ccfa-49c0-29ca-9894a0384b9b';
 	$database->save($array);
 	unset($array);
 
-	$p->add('clip_add', 'temp');
+	$p->delete('clip_add', 'temp');
 
 	require_once "header.php";
-	echo "<meta http-equiv=\"refresh\" content=\"1;url=clip_options.php\">\n";
+	echo "<meta http-equiv='refresh' content='1;url=clip_options.php'>\n";
 	echo $text['message-add'];
 	require_once "footer.php";
 	exit;
@@ -83,7 +82,7 @@ if (count($_POST)>0) {
 	require_once "header.php";
 	echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
 	echo "<tr>\n";
-	echo "	<td align=\"left\">\n";
+	echo "	<td align='left'>\n";
 
 	echo "<form method='post' action=''>";
 	echo "<table width='100%' border='0'>";
@@ -129,6 +128,4 @@ if (count($_POST)>0) {
 	echo "<script>document.getElementById('clip_name').focus();</script>";
 
 //include the footer
-	require_once "footer.php";
-
-?>
+	require_once "footer.php";

+ 5 - 7
clip_delete.php

@@ -17,7 +17,7 @@
 
 	The Initial Developer of the Original Code is
 	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2023
+	Portions created by the Initial Developer are Copyright (C) 2008-2025
 	the Initial Developer. All Rights Reserved.
 
 	Contributor(s):
@@ -39,6 +39,9 @@
 	$language = new text;
 	$text = $language->get();
 
+//connect to the database
+	$database = database::new();
+
 //get the uuid from http values
 	$clip_uuid = $_GET["id"];
 
@@ -49,9 +52,6 @@
 		$p = permissions::new();
 		$p->add('clip_delete', 'temp');
 
-		$database = new database;
-		$database->app_name = 'edit';
-		$database->app_uuid = '17e628ee-ccfa-49c0-29ca-9894a0384b9b';
 		$database->delete($array);
 		unset($array);
 
@@ -59,6 +59,4 @@
 	}
 
 //redirect the browser
-	header("Location: clip_options.php");
-
-?>
+	header("Location: clip_options.php");

+ 7 - 7
clip_list.php

@@ -17,7 +17,7 @@
 
 	The Initial Developer of the Original Code is
 	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2023
+	Portions created by the Initial Developer are Copyright (C) 2008-2025
 	the Initial Developer. All Rights Reserved.
 
 	Contributor(s):
@@ -42,6 +42,9 @@
 	$language = new text;
 	$text = $language->get();
 
+//connect to the database
+	$database = database::new();
+
 //check if this is a file
 	function isfile($filename) {
 		return @filesize($filename) > 0 ? true : false;
@@ -162,11 +165,10 @@
 	echo "<div style='padding-bottom: 3px;'><a href='javascript:void(0);' onclick=\"window.open('clip_options.php','clipwin','left=20,top=20,width=310,height=350,toolbar=0,resizable=0');\" style='text-decoration:none; cursor: pointer;' title=\"".$text['label-clip-library']."\"><img src='resources/images/icon_gear.png' border='0' align='absmiddle' style='margin: 0px 2px 4px -1px;'>".$text['label-clip-library']."</a></div>\n";
 
 	$sql = "select * from v_clips order by clip_folder asc, clip_name asc";
-	$database = new database;
 	$result = $database->select($sql, null, 'all');
 	unset($sql);
 
-	if (!empty($result) && is_array($result) && @sizeof($result) != 0) {
+	if (!empty($result) && is_array($result)) {
 		$master_array = array();
 		foreach ($result as $row) {
 			if (!empty($row['clip_folder'])) {
@@ -212,7 +214,7 @@
 						echo "<textarea style='display: none' id='after_".$row['uuid']."'>".$row['after']."</textarea>\n";
 						echo "</div>\n";
 					}
-					
+
 					echo "</div>\n";
 				}
 			}
@@ -222,6 +224,4 @@
 	echo "</div>\n";
 
 //inclue the footer
-require_once "footer.php";
-
-?>
+require_once "footer.php";

+ 2 - 4
clip_options.php

@@ -17,7 +17,7 @@
 
 	The Initial Developer of the Original Code is
 	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2023
+	Portions created by the Initial Developer are Copyright (C) 2008-2025
 	the Initial Developer. All Rights Reserved.
 
 	Contributor(s):
@@ -67,6 +67,4 @@
 	echo "</table>";
 
 //include footer
-	require_once "footer.php";
-
-?>
+	require_once "footer.php";

+ 6 - 6
clip_options_list.php

@@ -17,7 +17,7 @@
 
 	The Initial Developer of the Original Code is
 	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2023
+	Portions created by the Initial Developer are Copyright (C) 2008-2025
 	the Initial Developer. All Rights Reserved.
 
 	Contributor(s):
@@ -39,6 +39,9 @@
 	$language = new text;
 	$text = $language->get();
 
+//connect to the database
+	$database = database::new();
+
 //include
 	require_once "header.php";
 
@@ -120,7 +123,6 @@
 	echo "<div style='text-align: left;'>\n";
 
 	$sql = "select * from v_clips order by clip_folder asc, clip_name asc";
-	$database = new database;
 	$result = $database->select($sql, null, 'all');
 	unset($sql);
 
@@ -167,7 +169,7 @@
 						echo "<textarea style='display: none' id='after_".$row['uuid']."'>".$row['after']."</textarea>\n";
 						echo "</div>\n";
 					}
-					
+
 					echo "</div>\n";
 				}
 			}
@@ -178,6 +180,4 @@
 	echo "</div>\n";
 
 //include the footer
-	require_once "footer.php";
-
-?>
+	require_once "footer.php";

+ 15 - 16
clip_update.php

@@ -17,7 +17,7 @@
 
 	The Initial Developer of the Original Code is
 	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2023
+	Portions created by the Initial Developer are Copyright (C) 2008-2025
 	the Initial Developer. All Rights Reserved.
 
 	Contributor(s):
@@ -38,6 +38,9 @@
 	$language = new text;
 	$text = $language->get();
 
+//connect to the database
+	$database = database::new();
+
 //process the HTTP POST
 	if (count($_POST) > 0) {
 		$clip_uuid = $_POST["id"];
@@ -64,15 +67,14 @@
 		$p = permissions::new();
 		$p->add('clip_edit', 'temp');
 
-		$database = new database;
-		$database->app_name = 'edit';
-		$database->app_uuid = '17e628ee-ccfa-49c0-29ca-9894a0384b9b';
 		$database->save($array);
 		unset($array);
 
+		$p->delete('clip_edit', 'temp');
+
 		//redirect the browser
 		require_once "header.php";
-		echo "<meta http-equiv=\"refresh\" content=\"1;url=clip_options.php\">\n";
+		echo "<meta http-equiv='refresh' content='1;url=clip_options.php'>\n";
 		echo $text['message-update'];
 		require_once "footer.php";
 		exit;
@@ -85,7 +87,6 @@
 			$sql = "select * from v_clips ";
 			$sql .= "where clip_uuid = :clip_uuid ";
 			$parameters['clip_uuid'] = $clip_uuid;
-			$database = new database;
 			$row = $database->select($sql, $parameters, 'row');
 			if (is_array($row) && @sizeof($row) != 0) {
 				$clip_name = $row["clip_name"];
@@ -102,42 +103,42 @@
 	require_once "header.php";
 	echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
 	echo "<tr>\n";
-	echo "	<td align=\"left\">\n";
+	echo "	<td align='left'>\n";
 
 	echo "<form method='post' action=''>";
 	echo "<table border='0' width='100%'>";
 	echo "	<tr>";
 	echo "		<td>Name</td>";
-	echo "		<td><input type='text' class='txt' name='clip_name' value='$clip_name'></td>";
+	echo "		<td><input type='text' class='txt' name='clip_name' value='".$clip_name."'></td>";
 	echo "	</tr>";
 
 	echo "	<tr>";
 	echo "		<td>Folder</td>";
-	echo "		<td><input type='text' class='txt'  name='clip_folder' value='$clip_folder'></td>";
+	echo "		<td><input type='text' class='txt'  name='clip_folder' value='".$clip_folder."'></td>";
 	echo "	</tr>";
 
 	echo "	<tr>";
 	echo "		<td colspan='2'>Before Selection<br>";
-	echo "		  <textarea class='txt' style='resize: vertical;' name='clip_text_start'>$clip_text_start</textarea>";
+	echo "		  <textarea class='txt' style='resize: vertical;' name='clip_text_start'>".$clip_text_start."</textarea>";
 	echo "		</td>";
 	echo "	</tr>";
 
 	echo "	<tr>";
 	echo "		<td colspan='2'>After Selection<br>";
-	echo "		  <textarea class='txt' style='resize: vertical;' name='clip_text_end'>$clip_text_end</textarea>";
+	echo "		  <textarea class='txt' style='resize: vertical;' name='clip_text_end'>".$clip_text_end."</textarea>";
 	echo "		</td>";
 	echo "	</tr>";
 
 	echo "	<tr>";
 	echo "		<td colspan='2'>Notes<br>";
-	echo "		  <textarea class='txt' style='resize: vertical;' name='clip_desc'>$clip_desc</textarea>";
+	echo "		  <textarea class='txt' style='resize: vertical;' name='clip_desc'>".$clip_desc."</textarea>";
 	echo "		</td>";
 	echo "	</tr>";
 
 	echo "	<tr>";
 	echo "		<td align='left'><input type='button' value='".$text['button-back']."' onclick='history.back()'></td>";
 	echo "		<td align='right'>";
-	echo "			<input type='hidden' name='id' value='$clip_uuid'>";
+	echo "			<input type='hidden' name='id' value='".$clip_uuid."'>";
 	echo "			<input type='submit' name='submit' value='Update'>";
 	echo "		</td>";
 	echo "	</tr>";
@@ -149,6 +150,4 @@
 	echo "</table>";
 
 //include the footer
-	require_once "footer.php";
-
-?>
+	require_once "footer.php";

+ 2 - 4
footer.php

@@ -17,7 +17,7 @@
 
 	The Initial Developer of the Original Code is
 	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	Portions created by the Initial Developer are Copyright (C) 2008-2025
 	the Initial Developer. All Rights Reserved.
 
 	Contributor(s):
@@ -26,6 +26,4 @@
 
 echo "<div>";
 echo "</body>";
-echo "</html>";
-
-?>
+echo "</html>";

+ 2 - 4
header.php

@@ -17,7 +17,7 @@
 
 	The Initial Developer of the Original Code is
 	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2023
+	Portions created by the Initial Developer are Copyright (C) 2008-2025
 	the Initial Developer. All Rights Reserved.
 
 	Contributor(s):
@@ -84,6 +84,4 @@ echo "//-->\n";
 echo "</SCRIPT>\n";
 echo "</head>\n";
 echo "<body style='margin: 0; padding: 5px;'>\n";
-echo "<div align='center'>\n";
-
-?>
+echo "<div align='center'>\n";

+ 6 - 10
sql_backup.php

@@ -17,7 +17,7 @@
 
 	The Initial Developer of the Original Code is
 	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2014
+	Portions created by the Initial Developer are Copyright (C) 2008-2025
 	the Initial Developer. All Rights Reserved.
 
 	Contributor(s):
@@ -37,10 +37,7 @@
 	require_once "resources/check_auth.php";
 
 //check permisions
-	if (permission_exists('sql_query_backup')) {
-		//access granted
-	}
-	else {
+	if (!permission_exists('sql_query_backup')) {
 		echo "access denied";
 		exit;
 	}
@@ -49,6 +46,9 @@
 	$language = new text;
 	$text = $language->get();
 
+//connect to the database
+	$database = database::new();
+
 //pdo database connection
 	if (strlen($_REQUEST['id']) > 0) {
 		require_once "sql_query_pdo.php";
@@ -111,7 +111,6 @@
 	if ($db_type == "mysql") {
 		$sql = "show tables";
 	}
-	$database = new database;
 	$result_1 = $database->select($sql, null, 'all');
 	unset($sql);
 
@@ -122,7 +121,6 @@
 
 			//get the table data
 				$sql = "select * from ".$table_name;
-				$database = new database;
 				$result_2 = $database->select($sql, null, 'all');
 				unset($sql);
 
@@ -155,6 +153,4 @@
 			unset($column_array);
 		}
 	}
-	unset($result_1, $row_1);
-
-?>
+	unset($result_1, $row_1);

+ 2 - 4
sql_db_conversion.php

@@ -17,7 +17,7 @@
 
 	The Initial Developer of the Original Code is
 	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	Portions created by the Initial Developer are Copyright (C) 2008-2025
 	the Initial Developer. All Rights Reserved.
 
 	Contributor(s):
@@ -496,6 +496,4 @@
 							$db_dest->query($sql);
 					}
 				}
-		}
-
-?>
+		}

+ 15 - 18
sql_query.php

@@ -17,7 +17,7 @@
 
 	The Initial Developer of the Original Code is
 	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2024
+	Portions created by the Initial Developer are Copyright (C) 2008-2025
 	the Initial Developer. All Rights Reserved.
 
 	Contributor(s):
@@ -30,10 +30,7 @@
 	require_once "resources/check_auth.php";
 
 //permissions
-	if (permission_exists('sql_query')) {
-		//access granted
-	}
-	else {
+	if (!permission_exists('sql_query')) {
 		echo "access denied";
 		exit;
 	}
@@ -42,12 +39,15 @@
 	$language = new text;
 	$text = $language->get();
 
+//connect to the database
+	$database = database::new();
+
 //load editor preferences/defaults
-	$setting_size = (!empty($_SESSION["editor"]["font_size"]["text"])) ? $_SESSION["editor"]["font_size"]["text"] : '12px';
-	$setting_theme = (!empty($_SESSION["editor"]["theme"]["text"])) ? $_SESSION["editor"]["theme"]["text"] : 'cobalt';
-	$setting_invisibles = (!empty($_SESSION["editor"]["invisibles"]["boolean"])) ? $_SESSION["editor"]["invisibles"]["boolean"] : 'false';
-	$setting_indenting = (!empty($_SESSION["editor"]["indent_guides"]["boolean"])) ? $_SESSION["editor"]["indent_guides"]["boolean"] : 'false';
-	$setting_numbering = (!empty($_SESSION["editor"]["line_numbers"]["boolean"])) ? $_SESSION["editor"]["line_numbers"]["boolean"] : 'true';
+	$setting_size = $settings->get('editor','font_size','12px');
+	$setting_theme = $settings->get('editor','theme','cobalt');
+	$setting_invisibles = $settings->get('editor','invisibles',false);
+	$setting_indenting = $settings->get('editor','indent_guides',false);
+	$setting_numbering = $settings->get('editor','line_numbers',true);
 
 //get the html values and set them as variables
 	$code = trim($_POST["code"] ?? '');
@@ -170,7 +170,6 @@
 		case 'pgsql': $sql = "select table_name as name from information_schema.tables where table_schema='public' and (table_type='BASE TABLE' or table_type='VIEW') order by table_type, table_name"; break;
 		case 'mysql': $sql = "show tables"; break;
 	}
-	$database = new database;
 	$result = $database->select($sql, null, 'all');
 	if (is_array($result) && @sizeof($result) != 0) {
 		foreach ($result as &$row) {
@@ -337,12 +336,12 @@
 				theme: 'ace/theme/'+document.getElementById('theme').options[document.getElementById('theme').selectedIndex].value,
 				selectionStyle: 'text',
 				cursorStyle: 'smooth',
-				showInvisibles: <?php echo $setting_invisibles;?>,
-				displayIndentGuides: <?php echo $setting_indenting;?>,
-				showLineNumbers: <?php echo $setting_numbering;?>,
+				showInvisibles: <?php echo $setting_invisibles ? 'true' : 'false';?>,
+				displayIndentGuides: <?php echo $setting_indenting ? 'true' : 'false';?>,
+				showLineNumbers: <?php echo $setting_numbering ? 'true' : 'false';?>,
 				showGutter: true,
 				scrollPastEnd: true,
-				fadeFoldWidgets: <?php echo $setting_numbering;?>,
+				fadeFoldWidgets: <?php echo $setting_numbering ? 'true' : 'false';?>,
 				showPrintMargin: false,
 				highlightGutterLine: false,
 				useSoftTabs: false
@@ -373,6 +372,4 @@
 	echo "</div>\n";
 
 //show the footer
-	require_once "resources/footer.php";
-
-?>
+	require_once "resources/footer.php";

+ 3 - 4
sql_query_db.php

@@ -17,7 +17,7 @@
 
 	The Initial Developer of the Original Code is
 	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2023
+	Portions created by the Initial Developer are Copyright (C) 2008-2025
 	the Initial Developer. All Rights Reserved.
 
 	Contributor(s):
@@ -74,7 +74,7 @@
 		$num_rows = $database->select($sql, null, 'column');
 
 	//prepare to page the results
-		$rows_per_page = (!empty($_SESSION['domain']['paging']['numeric'])) ? $_SESSION['domain']['paging']['numeric'] : 50;
+		$rows_per_page = $settings->get('domain','paging',50);
 		$param = "";
 		$page = $_GET['page'];
 		if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
@@ -125,5 +125,4 @@
 	echo "<br><br>";
 
 //include the footer
-	require_once "resources/footer.php";
-?>
+	require_once "resources/footer.php";

+ 18 - 20
sql_query_pdo.php

@@ -17,7 +17,7 @@
 
  The Initial Developer of the Original Code is
  Mark J Crane <[email protected]>
- Portions created by the Initial Developer are Copyright (C) 2008-2023
+ Portions created by the Initial Developer are Copyright (C) 2008-2025
  the Initial Developer. All Rights Reserved.
 
  Contributor(s):
@@ -34,6 +34,9 @@
 		exit;
 	}
 
+//connect to the database
+	$database = database::new();
+
  //set the default values
 	if (isset($db_file_path) > 0) {
 		$db_path = $db_file_path;
@@ -45,7 +48,6 @@
 		$sql = "select * from v_databases ";
 		$sql .= "where database_uuid = :database_uuid ";
 		$parameters['database_uuid'] = $_REQUEST['id'];
-		$database = new database;
 		$row = $database->select($sql, $parameters, 'row');
 		if (is_array($row) && @sizeof($row) != 0) {
 			$db_type = $row["database_type"];
@@ -70,29 +72,27 @@ if (!function_exists('get_db_field_names')) {
 		}
 
 		// if we're still here, we need to try something else
-		$fields 	= array();
+		$fields = array();
 		$driver = $db->getAttribute(PDO::ATTR_DRIVER_NAME);
 		if ($driver == 'sqlite') {
-			$query 		= sprintf("Pragma table_info(%s);", $table);
-			$stmt 		= $db->prepare($query);
-			$result 	= $stmt->execute();
-			$rows 		= $stmt->fetchAll(PDO::FETCH_NAMED);
+			$query = sprintf("Pragma table_info(%s);", $table);
+			$stmt = $db->prepare($query);
+			$result = $stmt->execute();
+			$rows = $stmt->fetchAll(PDO::FETCH_NAMED);
 			//printf('<pre>%s</pre>', print_r($rows, true));
-			$row_count 	= count($rows);
+			$row_count = count($rows);
 			//printf('<pre>%s</pre>', print_r($rows, true));
 			for ($i = 0; $i < $row_count; $i++) {
 				array_push($fields, $rows[$i]['name']);
 			}
 			return $fields;
-		} else {
-			$query 		= sprintf("SELECT * FROM information_schema.columns
-			WHERE table_schema='%s' AND table_name='%s';"
-			, $db_name, $table
-			);
-			$stmt 		= $db->prepare($query);
-			$result 	= $stmt->execute();
-			$rows 		= $stmt->fetchAll(PDO::FETCH_NAMED);
-			$row_count 	= count($rows);
+		}
+		else {
+			$query = sprintf("SELECT * FROM information_schema.columns WHERE table_schema='%s' AND table_name='%s';", $db_name, $table);
+			$stmt = $db->prepare($query);
+			$result	= $stmt->execute();
+			$rows = $stmt->fetchAll(PDO::FETCH_NAMED);
+			$row_count= count($rows);
 			//printf('<pre>%s</pre>', print_r($rows, true));
 			for ($i = 0; $i < $row_count; $i++) {
 				array_push($fields, $rows[$i]['COLUMN_NAME']);
@@ -233,6 +233,4 @@ if ($db_type == "odbc") {
 		catch (PDOException $e) {
 		   echo 'Connection failed: ' . $e->getMessage();
 		}
-} //end if db_type odbc
-
-?>
+} //end if db_type odbc

+ 10 - 12
sql_query_result.php

@@ -17,7 +17,7 @@
 
 	The Initial Developer of the Original Code is
 	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2023
+	Portions created by the Initial Developer are Copyright (C) 2008-2025
 	the Initial Developer. All Rights Reserved.
 
 	Contributor(s):
@@ -45,6 +45,9 @@
 	$language = new text;
 	$text = $language->get();
 
+//connect to the database
+	$database = database::new();
+
 //pdo database connection
 	if (strlen($_REQUEST['id']) > 0) {
 		require_once "sql_query_pdo.php";
@@ -64,7 +67,6 @@
 		case 'pgsql': $sql = "select table_name as name from information_schema.tables where table_schema='public' and (table_type='BASE TABLE' or table_type='VIEW') order by table_type, table_name"; break;
 		case 'mysql': $sql = "show tables"; break;
 	}
-	$database = new database;
 	$rows = $database->select($sql, null, 'all');
 	if (is_array($rows) && @sizeof($rows) != 0) {
 		foreach ($rows as $row) {
@@ -80,7 +82,7 @@
 		$sql_type = trim($_REQUEST["sql_type"]);
 		$sql_cmd = trim($_REQUEST["command"]);
 		$table_name = trim($_REQUEST["table_name"]);
-	
+
 		$header = "<html>\n";
 		$header .= "<head>\n";
 		$header .= "<style type='text/css'>\n";
@@ -147,11 +149,11 @@
 			$row_style["1"] = "row_style1";
 
 			//determine queries to run and show
-			if ($sql_cmd != '') { $sql_array = array_filter(explode(";", $sql_cmd)); }
-			if ($table_name != '' && in_array($table_name, $tables)) { $sql_array[] = "select * from ".$table_name; }
-			$show_query = (sizeof($sql_array) > 1) ? true : false;
+			if (!empty($sql_cmd)) { $sql_array = array_filter(explode(";", $sql_cmd)); }
+			if (!empty($table_name) && in_array($table_name, $tables)) { $sql_array[] = "select * from ".$table_name; }
+			$show_query = (!empty($sql_array) && sizeof($sql_array) > 1) ? true : false;
 
-			if (is_array($sql_array)) foreach($sql_array as $sql_index => $sql) {
+			if (!empty($sql_array) && is_array($sql_array)) foreach($sql_array as $sql_index => $sql) {
 				$sql = trim($sql);
 
 				if (sizeof($sql_array) > 1 || $show_query) {
@@ -160,7 +162,6 @@
 				}
 
 				//connect to the database and run the sql query
-				$database = new database;
 				$result = $database->execute($sql, null, 'all');
 				$message = $database->message;
 
@@ -226,7 +227,6 @@
 				$sql = (strlen($sql_cmd) == 0 && in_array($table_name, $tables)) ? "select * from ".$table_name : $sql_cmd;
 
 				if (strlen($sql) > 0) {
-					$database = new database;
 					$result = $database->execute($sql);
 					$message = $database->message;
 
@@ -345,6 +345,4 @@
 					}
 				}
 		}
-	}
-
-?>
+	}