From e8439f86f41d6a5c194e131c840fe703bbbc198b Mon Sep 17 00:00:00 2001 From: markjcrane Date: Tue, 10 Dec 2019 18:13:59 +0000 Subject: [PATCH] Moved SQL Query to its own repo --- app/sql_query/app_config.php | 38 -- app/sql_query/app_languages.php | 544 ------------------ app/sql_query/app_menu.php | 29 - app/sql_query/resources/images/blank.gif | Bin 49 -> 0 bytes app/sql_query/resources/images/icon_file.png | Bin 257 -> 0 bytes .../resources/images/icon_folder.png | Bin 224 -> 0 bytes app/sql_query/resources/images/icon_gear.png | Bin 726 -> 0 bytes app/sql_query/resources/images/icon_goto.png | Bin 417 -> 0 bytes .../resources/images/icon_indenting.png | Bin 324 -> 0 bytes .../resources/images/icon_invisibles.png | Bin 821 -> 0 bytes .../resources/images/icon_numbering.png | Bin 521 -> 0 bytes .../resources/images/icon_replace.png | Bin 504 -> 0 bytes app/sql_query/root.php | 90 --- app/sql_query/sql_backup.php | 157 ----- app/sql_query/sql_db_conversion.php | 501 ---------------- app/sql_query/sql_query.php | 392 ------------- app/sql_query/sql_query_db.php | 131 ----- app/sql_query/sql_query_pdo.php | 242 -------- app/sql_query/sql_query_result.php | 345 ----------- 19 files changed, 2469 deletions(-) delete mode 100644 app/sql_query/app_config.php delete mode 100644 app/sql_query/app_languages.php delete mode 100644 app/sql_query/app_menu.php delete mode 100644 app/sql_query/resources/images/blank.gif delete mode 100644 app/sql_query/resources/images/icon_file.png delete mode 100644 app/sql_query/resources/images/icon_folder.png delete mode 100644 app/sql_query/resources/images/icon_gear.png delete mode 100644 app/sql_query/resources/images/icon_goto.png delete mode 100644 app/sql_query/resources/images/icon_indenting.png delete mode 100644 app/sql_query/resources/images/icon_invisibles.png delete mode 100644 app/sql_query/resources/images/icon_numbering.png delete mode 100644 app/sql_query/resources/images/icon_replace.png delete mode 100644 app/sql_query/root.php delete mode 100644 app/sql_query/sql_backup.php delete mode 100644 app/sql_query/sql_db_conversion.php delete mode 100644 app/sql_query/sql_query.php delete mode 100644 app/sql_query/sql_query_db.php delete mode 100644 app/sql_query/sql_query_pdo.php delete mode 100644 app/sql_query/sql_query_result.php diff --git a/app/sql_query/app_config.php b/app/sql_query/app_config.php deleted file mode 100644 index 45b5aad6f0..0000000000 --- a/app/sql_query/app_config.php +++ /dev/null @@ -1,38 +0,0 @@ - diff --git a/app/sql_query/app_languages.php b/app/sql_query/app_languages.php deleted file mode 100644 index 141ae74209..0000000000 --- a/app/sql_query/app_languages.php +++ /dev/null @@ -1,544 +0,0 @@ -PHP Manual"; -$text['description-php']['ar-eg'] = ""; -$text['description-php']['de-at'] = "PHP Befehle ausführen. Benutzen Sie folgenden Link als PHP Referenz: diff --git a/app/sql_query/app_menu.php b/app/sql_query/app_menu.php deleted file mode 100644 index 5ffc2290bd..0000000000 --- a/app/sql_query/app_menu.php +++ /dev/null @@ -1,29 +0,0 @@ - diff --git a/app/sql_query/resources/images/blank.gif b/app/sql_query/resources/images/blank.gif deleted file mode 100644 index 75b945d2553848b8b6f41fe5e24599c0687b8472..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 49 zcmZ?wbhEHbWMp7unE0RJ|Ns9C3=9Vj8~~DvKUo+V7?>DzfNY>Fh|Ltj$Y2csQN9XW diff --git a/app/sql_query/resources/images/icon_file.png b/app/sql_query/resources/images/icon_file.png deleted file mode 100644 index c8d71de0c4ad9a7a8f4349f7b5afecf4d97e0bb7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 257 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf4nJ za0`PlBg3pY55O6*3aqU4E)2*A_r%sCn&Dx^)?Ph~mWJ}XY zrZ<;%OrBu7XQP2rM}k|9&Yrt9?;aW%FbSys6x+fwGkHS0-;^IU8mk^$ydLQcFw|Q4~G%p-ze-6lZA1 zk{YU&jWJLtl2luXAT35+s4IzP5wP1Qy|jX>NX zY6>kWouRP6I1Di30+9*7jc4`Vz2}|#?#Ti62XR1ef0A%dsJ7Yj1aToT9Sj6(0HC3< zp@U;{^1lC=>F8|l?9ub-odUVm+!B9frB{^1Vm`-e093Nj<-B3aG8uopSosRzU;%=r z2!bHMv0QqEul%mQN6{3y=L&)#RGW{ROAH2vC_Gnio9FlpS(c$F3IM=hFo0ngBPkRaFf14>|yB3P=fQT3VEfIhIS8Wf|e{$ng82AzvsIS_c4+$Mb}w$YGz~?*RZw zl2*iIVg>*~0ze=TsF{pRJqG|qQ4o(s`?ekfKqwSikHupzx9*c)CVGQy!TSI-ohj<} zd1I$l00nBBspC=rh}yc^r`}5!ZyAloG)>d6n34`@8(L2^8dU+n>2#*KT&|Xrj#D-O zIC3<@!Db(`jgE}IrU7Uc-g3f}WikQ)!!U5W-DNaI59Oc9e?@@;Z{e?(x=Sx?O=Yv$ zbhE{52maV#R zCP+CDZ^t6%2E?zR@=4fI%UvKo1jHObya0&viF9!|5U&AZQ6Rnw#FucTb6y}`1$6-k zHv=&v9+&4pQx8b|01(Tdn29A5u>{5oRzWBO_IdaS&iZ5;Fs0WvJJ&>H*@vK+KFS z5}^Pj{tSo@qGzI2Xpu%PJ_$1u+2x0!>Gdy#1>sq^H->Bl4G>@e&gR^+SeU!>00000 LNkvXXu0mjfF9@U- diff --git a/app/sql_query/resources/images/icon_indenting.png b/app/sql_query/resources/images/icon_indenting.png deleted file mode 100644 index c6d4c733f126b55a393fb5c1550b66340c69a6f2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 324 zcmV-K0lWT*P)%Q5972jAIQ4=e6olE>*nR--6DJ1a(#ry~j}({V(u-_( zBapHN;y;XxjPpq}9IIYNV$->>u<$V^CZ-4=e)RI?OX{W;W@ctfpsO|mnF3T#EkGB8 zupZEYQ^ckgxZ(f){qqN6DIk^uVi&9~fmoml3L<22TzZL4Ei5c>rMKU{eQQP4)B+51 z5OoQd0PLxrS`-x(K|v7#H0Ti!5T%EaE=4Xh#-9Q4BQnbtOueIJ3q`4AWL0wj0R{l= WHTrvIz+7Yi0000}#2@UW1Hq1KuRbX2Ya?I0C@d))q#Fd-wWOxz zs4;o~bLVgxU6G37y$MXB6L4py%7uEqH$HhuyduZcNUZwEOEYr2pRl$q5Py)BzJNNX zQKF7aDt!lQnV)LTB4-ic@U-eM4MeHPNknUiTo2gL0Oz|{*=v=G(A0HY-axH(gT3)Y z>$J?1LC}v3#>>Icz$9weq?Gi+ju~@124(`VN+39X%98>0KaGy|{#+K3CrDx&%;B=R zE#m1J%zD^e(0#BYWi&35UI=^ZcOd4md_Lbg_VvrnnHu`SiEPC96pAZK)kwb<4Zh)> z-w!@Jl!BbK3!-B2I>OhXFXX*{9XZ9Dfi_r(tczXBAj*Eyd|$VH6&c zgpaq>18@&EuYmoLy}n{{=5iQhb6`v5w?!sZl_P?j6JFdRxQE#I zMv0vAERRX_2zXzj){GC=q^w8qevBC$VZ+FvCG zU*Nt}bKABRP1BS#O=;%}_tM_DNYGrO*=*)_?)$!p2U9Rk@%4pUGX^Fl%F+R!#j@N` z`p_792+qJbxCM(6<}O&tmBq5G08(WW8ektx7qSqEq}6Iwayv(@L(bf1-9iTx0bRm8 zDs>CY_h7aO(=KSRjM~s$=mzVSOrTrtO5IYc)qZCcx=N zjTA4gl%K$9#tuu^ywoi)uR~U;EU4Q#Yel+S>at}S{>=@HZvh4XFCx-qlh}c#00000 LNkvXXu0mjfcthUG diff --git a/app/sql_query/resources/images/icon_replace.png b/app/sql_query/resources/images/icon_replace.png deleted file mode 100644 index 4b2ec2178852b59198baa3ae49a0eb6f321fa83c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 504 zcmVz$>{0~W;E)ZWv)(8#}5COwTKnRGZ0r3}*IxP4E)KU;= z2jbP}uEJ%w0@M{SgFr6r1L9_=As?XPKY(~Wl)ao7!?}R?6jZ}~Aojo#l(IlP7tJS2 zuo=#RCYAxjra=4>YVb`ghCc@42Smjvn#&(RU6PGMIXe(fz!C?miE;UPXt1ooVYoFA zYXb2msG+bFcMO|iM&wk2B`IR4M>3RPh@iXN6v+@64Z^2^_%9ZN<$+iX8b^-^g*mn~ zT@J*|I2?EeswSV9q=;29)st-xCe;8BdM8=6h{ONPXOW+ApVSG0LZY9Xck{YV$VXi0Gr_{Nb+jXGUXD~a8PP_ z0xeH`ftU@5TaYZ6iyZOzN=0PA3d9o7VByCi-;89z0$3eEtl`9fdL#=#C8P*74F`c5 usNtZX)1bEDAdm^ImB8jP4%rGCAix0otSfUDlILLn0000 - Portions created by the Initial Developer are Copyright (C) 2008-2012 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -// make sure the PATH_SEPARATOR is defined - umask(2); - if (!defined("PATH_SEPARATOR")) { - if (strpos($_ENV["OS"], "Win") !== false) { - define("PATH_SEPARATOR", ";"); - } else { - define("PATH_SEPARATOR", ":"); - } - } - - if (!isset($output_format)) $output_format = (PHP_SAPI == 'cli') ? 'text' : 'html'; - - // make sure the document_root is set - $_SERVER["SCRIPT_FILENAME"] = str_replace("\\", '/', $_SERVER["SCRIPT_FILENAME"]); - if(PHP_SAPI == 'cli'){ - chdir(pathinfo(realpath($_SERVER["PHP_SELF"]), PATHINFO_DIRNAME)); - $script_full_path = str_replace("\\", '/', getcwd() . '/' . $_SERVER["SCRIPT_FILENAME"]); - $dirs = explode('/', pathinfo($script_full_path, PATHINFO_DIRNAME)); - if (file_exists('/project_root.php')) { - $path = '/'; - } else { - $i = 1; - $path = ''; - while ($i < count($dirs)) { - $path .= '/' . $dirs[$i]; - if (file_exists($path. '/project_root.php')) { - break; - } - $i++; - } - } - $_SERVER["DOCUMENT_ROOT"] = $path; - }else{ - $_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]); - } - $_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]); -// try to detect if a project path is being used - if (!defined('PROJECT_PATH')) { - if (is_dir($_SERVER["DOCUMENT_ROOT"]. '/fusionpbx')) { - define('PROJECT_PATH', '/fusionpbx'); - } elseif (file_exists($_SERVER["DOCUMENT_ROOT"]. '/project_root.php')) { - define('PROJECT_PATH', ''); - } else { - $dirs = explode('/', str_replace('\\', '/', pathinfo($_SERVER["PHP_SELF"], PATHINFO_DIRNAME))); - $i = 1; - $path = $_SERVER["DOCUMENT_ROOT"]; - while ($i < count($dirs)) { - $path .= '/' . $dirs[$i]; - if (file_exists($path. '/project_root.php')) { - break; - } - $i++; - } - if(!file_exists($path. '/project_root.php')){ - die("Failed to locate the Project Root by searching for project_root.php please contact support for assistance"); - } - $project_path = str_replace($_SERVER["DOCUMENT_ROOT"], "", $path); - define('PROJECT_PATH', $project_path); - } - $_SERVER["PROJECT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH); - set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER["PROJECT_ROOT"]); - } - -?> \ No newline at end of file diff --git a/app/sql_query/sql_backup.php b/app/sql_query/sql_backup.php deleted file mode 100644 index f87d248722..0000000000 --- a/app/sql_query/sql_backup.php +++ /dev/null @@ -1,157 +0,0 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2014 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -//disabled - echo "access denied"; - exit; - -//includes - include "root.php"; - require_once "resources/require.php"; - require_once "resources/check_auth.php"; - -//check permisions - if (permission_exists('exec_sql_backup')) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//pdo database connection - if (strlen($_REQUEST['id']) > 0) { - require_once "sql_query_pdo.php"; - } - -//get the $apps array from the installed apps from the core and mod directories - $config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php"); - $x = 0; - foreach ($config_list as &$config_path) { - include($config_path); - $x++; - } - -//define a function that checks if the field exists - function field_exists($apps, $table_name, $field_name) { - $result = false; - foreach ($apps as &$row) { - $tables = $row["db"]; - foreach ($tables as &$table) { - if ($table['table'] == $table_name) { - foreach ($table["fields"] as &$field) { - if ($field['deprecated'] != "true") { - if (is_array($field["name"])) { - if ($field["name"]["text"] == $field_name) { - $result = true; - break; - } - } - else { - if ($field["name"] == $field_name) { - $result = true; - break; - } - } - } - } - } - } - } - return $result; - } - -//set the headers - header('Content-type: application/octet-binary'); - header('Content-Disposition: attachment; filename=database_backup.sql'); - -//get the list of tables - if ($db_type == "sqlite") { - $sql = "select name from sqlite_master "; - $sql .= "where type='table' "; - $sql .= "order by name;"; - } - if ($db_type == "pgsql") { - $sql = "select table_name as name "; - $sql .= "from information_schema.tables "; - $sql .= "where table_schema='public' "; - $sql .= "and table_type='BASE TABLE' "; - $sql .= "order by table_name "; - } - if ($db_type == "mysql") { - $sql = "show tables"; - } - $database = new database; - $result_1 = $database->select($sql, null, 'all'); - unset($sql); - - if (is_array($result_1) && @sizeof($result_1) != 0) { - foreach ($result_1 as &$row_1) { - $row_1 = array_values($row_1); - $table_name = $row_1[0]; - - //get the table data - $sql = "select * from ".$table_name; - $database = new database; - $result_2 = $database->select($sql, null, 'all'); - unset($sql); - - foreach ($result_2[0] as $key => $value) { - if ($row_1[$column] != "db") { - if (field_exists($apps, $table_name, $key)) { - $column_array[] = $key; - } - } - } - - $column_array_count = count($column_array); - - foreach ($result_2 as &$row_2) { - foreach ($column_array as $column) { - $columns[] = $column; - $values[] = $row_2[$column] != '' ? "'".check_str($row_2[$column])."'" : 'null'; - } - $sql = "insert into ".$table_name." ("; - $sql .= implode(', ', $columns); - $sql .= ") values ( "; - $sql .= implode(', ', $values); - $sql .= ");"; - echo $sql."\n"; - - unset($columns, $values); - } - unset($result_2, $row_2); - - unset($column_array); - } - } - unset($result_1, $row_1); - -?> diff --git a/app/sql_query/sql_db_conversion.php b/app/sql_query/sql_db_conversion.php deleted file mode 100644 index 2815d2e6b4..0000000000 --- a/app/sql_query/sql_db_conversion.php +++ /dev/null @@ -1,501 +0,0 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2012 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -//includes - include "root.php"; - require_once "resources/require.php"; - require_once "resources/check_auth.php"; - -//check permissions - if (if_group("superadmin")) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//show errors - ini_set('display_errors', '1'); - //error_reporting (E_ALL); // Report everything - error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ); //hide notices and warnings - -//define the db file exists function - function db_field_exists ($tmp_array, $column) { - $result = false; - foreach ($tmp_array as &$row) { - if ($row[0] == $column) { - $result = true; - } - return $result; - } - } - //db_field_exists ($result_dest, $column) - -//destination info - //set the domain_uuid - $dest_domain_uuid = '1'; - - //set the database type - $db_dest_type = 'mysql'; //sqlite, mysql, pgsql, others with a manually created PDO connection - - //sqlite: the dbfilename and db_file_path are automatically assigned however the values can be overidden by setting the values here. - //$dbfilename = 'fusionpbx.db'; //host name/ip address + '.db' is the default database filename - //$db_file_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/secure'; //the path is determined by a php variable - - //mysql: database connection information - $db_host = '127.0.0.1'; //set the host only if the database is not local - $db_port = '3306'; - $db_name = 'fusionpbx'; - $db_username = 'fusionpbx'; - $db_password = ''; - $db_create_username = 'root'; - $db_create_password = ''; - - //pgsql: database connection information - //$db_host = ''; //set the host only if the database is not local - //$db_port = ''; - //$db_name = ''; - //$db_username = ''; - //$db_password = ''; - //$db_create_username = ''; - //$db_create_password = ''; - - //load data into the database - - //create the sqlite database - if ($db_dest_type == "sqlite") { - //sqlite database will be created when the config.php is loaded and only if the database file does not exist - $filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/sqlite.sql'; - $file_contents = file_get_contents($filename); - unset($filename); - try { - $db_dest = new PDO('sqlite:'.$db_filepath.'/'.$db_filename); //sqlite 3 - //$db_dest = new PDO('sqlite::memory:'); //sqlite 3 - $db_dest->beginTransaction(); - } - catch (PDOException $error) { - print $text['label-error'].": " . $error->getMessage() . "
"; - die(); - } - - //replace \r\n with \n then explode on \n - $file_contents = str_replace("\r\n", "\n", $file_contents); - - //loop line by line through all the lines of sql code - $stringarray = explode("\n", $file_contents); - $x = 0; - foreach($stringarray as $sql) { - try { - if(stristr($sql, 'CREATE TABLE') === FALSE) { - //not found do not execute - } - else { - //execute create table sql strings - $db_dest->query($sql); - } - } - catch (PDOException $error) { - echo $text['label-error'].": " . $error->getMessage() . " sql: $sql
"; - } - $x++; - } - unset ($file_contents, $sql); - $db_dest->commit(); - } - - //create the postgres database - if ($db_dest_type == "pgsql") { - $filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/pgsql.sql'; - $file_contents = file_get_contents($filename); - - //if $db_create_username provided, attempt to create new PG role and database - if (strlen($db_create_username) > 0) { - //create the database connection - try { - if (strlen($db_port) == 0) { $db_port = "5432"; } - if (strlen($db_host) > 0) { - $db_dest = new PDO("pgsql:host={$db_host} port={$db_port} user={$db_create_username} password={$db_create_password} dbname=template1"); - } else { - $db_dest = new PDO("pgsql:host=localhost port={$db_port} user={$db_create_username} password={$db_create_password} dbname=template1"); - } - } catch (PDOException $error) { - print $text['label-error'].": " . $error->getMessage() . "
"; - die(); - } - //create the database, user, grant perms - $db_dest->exec("CREATE DATABASE {$db_name}"); - $db_dest->exec("CREATE USER {$db_username} WITH PASSWORD '{$db_password}'"); - $db_dest->exec("GRANT ALL ON {$db_name} TO {$db_username}"); - //close database connection_aborted - $db_dest = null; - } - - //open database connection with $db_name - try { - if (strlen($db_port) == 0) { $db_port = "5432"; } - if (strlen($db_host) > 0) { - $db_dest = new PDO("pgsql:host={$db_host} port={$db_port} dbname={$db_name} user={$db_username} password={$db_password}"); - } else { - $db_dest = new PDO("pgsql:host=localhost port={$db_port} user={$db_username} password={$db_password} dbname={$db_name}"); - } - } - catch (PDOException $error) { - print $text['label-error'].": " . $error->getMessage() . "
"; - die(); - } - - //replace \r\n with \n then explode on \n - $file_contents = str_replace("\r\n", "\n", $file_contents); - - //loop line by line through all the lines of sql code - $stringarray = explode("\n", $file_contents); - $x = 0; - foreach($stringarray as $sql) { - if (strlen($sql) > 3) { - try { - if(stristr($sql, 'CREATE TABLE') === FALSE) { - //not found do not execute - } - else { - //execute create table sql strings - $db_dest->query($sql); - } - } - catch (PDOException $error) { - echo $text['label-error'].": " . $error->getMessage() . " sql: $sql
"; - die(); - } - } - $x++; - } - unset ($file_contents, $sql); - } - - //create the mysql database - if ($db_dest_type == "mysql") { - $filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/mysql.sql'; - $file_contents = file_get_contents($filename); - - //database connection - try { - if (strlen($db_host) == 0 && strlen($db_port) == 0) { - //if both host and port are empty use the unix socket - if (strlen($db_create_username) == 0) { - $db_dest = new PDO("mysql:host=$db_host;unix_socket=/var/run/mysqld/mysqld.sock;charset=utf8;", $db_username, $db_password); - } - else { - $db_dest = new PDO("mysql:host=$db_host;unix_socket=/var/run/mysqld/mysqld.sock;charset=utf8;", $db_create_username, $db_create_password); } - } - else { - if (strlen($db_port) == 0) { - //leave out port if it is empty - if (strlen($db_create_username) == 0) { - $db_dest = new PDO("mysql:host=$db_host;charset=utf8;", $db_username, $db_password); - } - else { - $db_dest = new PDO("mysql:host=$db_host;charset=utf8;", $db_create_username, $db_create_password); - } - } - else { - if (strlen($db_create_username) == 0) { - $db_dest = new PDO("mysql:host=$db_host;port=$db_port;charset=utf8;", $db_username, $db_password); - } - else { - $db_dest = new PDO("mysql:host=$db_host;port=$db_port;charset=utf8;", $db_create_username, $db_create_password); - } - } - } - $db_dest->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $db_dest->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); - } - catch (PDOException $error) { - if ($v_debug) { - print $text['label-error'].": " . $error->getMessage() . "
"; - } - } - - //create the table, user and set the permissions only if the db_create_username was provided - if (strlen($db_create_username) > 0) { - //select the mysql database - try { - $db_dest->query("USE mysql;"); - } - catch (PDOException $error) { - if ($v_debug) { - print $text['label-error'].": " . $error->getMessage() . "
"; - } - } - //create user and set the permissions - try { - $tmp_sql = "CREATE USER '".$db_username."'@'%' IDENTIFIED BY '".$db_password."'; "; - $db_dest->query($tmp_sql); - } - catch (PDOException $error) { - if ($v_debug) { - print $text['label-error'].": " . $error->getMessage() . "
"; - } - } - //set account to unlimitted use - try { - $tmp_sql = "GRANT USAGE ON * . * TO '".$db_username."'@'localhost' "; - $tmp_sql .= "IDENTIFIED BY '".$db_password."' "; - $tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; "; - $db_dest->query($tmp_sql); - } - catch (PDOException $error) { - if ($v_debug) { - print $text['label-error'].": " . $error->getMessage() . "
"; - } - } - //create the database and set the create user with permissions - try { - $tmp_sql = "CREATE DATABASE IF NOT EXISTS ".$db_name."; "; - $db_dest->query($tmp_sql); - } - catch (PDOException $error) { - if ($v_debug) { - print $text['label-error'].": " . $error->getMessage() . "
"; - } - } - //set user permissions - try { - $db_dest->query("GRANT ALL PRIVILEGES ON ".$db_name.".* TO '".$db_username."'@'%'; "); - } - catch (PDOException $error) { - if ($v_debug) { - print $text['label-error'].": " . $error->getMessage() . "
"; - } - } - //make the changes active - try { - $tmp_sql = "FLUSH PRIVILEGES; "; - $db_dest->query($tmp_sql); - } - catch (PDOException $error) { - if ($v_debug) { - print $text['label-error'].": " . $error->getMessage() . "
"; - } - } - } //if (strlen($db_create_username) > 0) - //select the database - try { - $db_dest->query("USE ".$db_name.";"); - } - catch (PDOException $error) { - if ($v_debug) { - print $text['label-error'].": " . $error->getMessage() . "
"; - } - } - - //add the defaults data into the database - //replace \r\n with \n then explode on \n - $file_contents = str_replace("\r\n", "\n", $file_contents); - - //loop line by line through all the lines of sql code - $stringarray = explode("\n", $file_contents); - $x = 0; - foreach($stringarray as $sql) { - if (strlen($sql) > 3) { - try { - if(stristr($sql, 'CREATE TABLE') === FALSE) { - //not found do not execute - } - else { - //execute create table sql strings - $db_dest->query($sql); - } - } - catch (PDOException $error) { - //echo "error on line $x: " . $error->getMessage() . " sql: $sql
"; - //die(); - } - } - $x++; - } - unset ($file_contents, $sql); - } - -//get the list of tables - if ($db_dest_type == "sqlite") { - $sql = "SELECT name FROM sqlite_master "; - $sql .= "WHERE type='table' "; - $sql .= "order by name;"; - } - if ($db_dest_type == "pgsql") { - $sql = "select table_name as name "; - $sql .= "from information_schema.tables "; - $sql .= "where table_schema='public' "; - $sql .= "and table_type='BASE TABLE' "; - $sql .= "order by table_name "; - } - if ($db_dest_type == "mysql") { - $sql = "show tables"; - } - //get the default schema structure - $prep_statement = $db_dest->prepare(check_sql($sql)); - $prep_statement->execute(); - $result_dest = $prep_statement->fetchAll(PDO::FETCH_NAMED); - //clean the content from the table - foreach ($result_dest as &$row) { - $table_name = $row[0]; - $sql = 'delete from '.$table_name; - //$db_dest->query($sql); - } - - //add data into each table - foreach ($result_dest as &$row) { - //get the table name - $table_name = $row[0]; - - //$table_name = 'v_extensions'; - //$db_dest_type = "sqlite"; - - //get the table source data - $destination_column_array=''; - unset($destination_column_array); - if ($db_dest_type == "sqlite") { - $tmp_sql = "PRAGMA table_info($table_name);"; - } - if ($db_dest_type == "pgsql") { - - } - if ($db_dest_type == "mysql") { - $tmp_sql = "show columns from $table_name;"; - } - if (strlen($tmp_sql) > 0) { - $prep_statement_2 = $db_dest->prepare(check_sql($tmp_sql)); - //$prep_statement_2 = $db->prepare(check_sql($tmp_sql)); - if ($prep_statement_2) { - $prep_statement_2->execute(); - $result2 = $prep_statement_2->fetchAll(PDO::FETCH_ASSOC); - } - else { - echo "".$text['label-error'].":\n"; - echo "
\n";
-						print_r($db_dest->errorInfo());
-						echo "
\n"; - } - $x = 0; - foreach ($result2 as $row2) { - if ($db_dest_type == "sqlite") { - $destination_column_array[$x] = $row2['name']; - } - if ($db_dest_type == "mysql") { - $destination_column_array[$x] = $row2['Field']; - } - if ($db_dest_type == "pgsql") { - - } - $x++; - } - /* - $x = 0; - foreach ($result2[0] as $key => $value) { - if ($db_dest_type == "sqlite" && $key == "name") { - $destination_column_array[$x] = $key; - } - $x++; - } - */ - $destination_column_array_count = count($destination_column_array); - } - unset($prep_statement_2, $result2); - //echo "
\n";
-				//print_r($destination_column_array);
-				//echo "
\n"; - - //get the table source data - $tmp_sql = "select * from $table_name"; - if (strlen($tmp_sql) > 0) { - $prep_statement_2 = $db->prepare(check_sql($tmp_sql)); - if ($prep_statement_2) { - $prep_statement_2->execute(); - $result2 = $prep_statement_2->fetchAll(PDO::FETCH_ASSOC); - } - else { - echo "".$text['label-error'].":\n"; - echo "
\n";
-						print_r($db->errorInfo());
-						echo "
\n"; - } - - $x = 0; - foreach ($result2[0] as $key => $value) { - $column_array[$x] = $key; - $x++; - } - - foreach ($result2 as &$row) { - //build the sql query string - if (substr($table_name, 0, 2) == 'v_') { - $sql = "INSERT INTO $table_name ("; - $x = 1; - foreach ($destination_column_array as $column) { - if ($x < $destination_column_array_count) { - $sql .= "".$column.", "; - } - else { - $sql .= "".$column.""; - } - $x++; - } - $sql .= ") "; - $sql .= "VALUES( "; - $x = 1; - foreach ($destination_column_array as $column) { - if ($x < $destination_column_array_count) { - //if ($column == "domain_uuid") { - // $sql .= "'".$dest_domain_uuid."',"; - //} - //else { - $sql .= "'".check_str($row[$column])."', "; - //} - } - else { - //if ($column == "domain_uuid") { - // $sql .= "'".$dest_domain_uuid."'"; - //} - //else { - $sql .= "'".check_str($row[$column])."'"; - //} - } - $x++; - } - $sql .= ");\n"; - } - //add the sql into the destination database - echo $sql."
\n"; - $db_dest->query($sql); - } - } - } - -?> diff --git a/app/sql_query/sql_query.php b/app/sql_query/sql_query.php deleted file mode 100644 index 0ae26a6c2a..0000000000 --- a/app/sql_query/sql_query.php +++ /dev/null @@ -1,392 +0,0 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2019 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane - James Rose -*/ - -//includes - include "root.php"; - require_once "resources/require.php"; - require_once "resources/check_auth.php"; - -//permissions - if (permission_exists('sql_query')) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -// load editor preferences/defaults - $setting_size = ($_SESSION["editor"]["font_size"]["text"] != '') ? $_SESSION["editor"]["font_size"]["text"] : '12px'; - $setting_theme = ($_SESSION["editor"]["theme"]["text"] != '') ? $_SESSION["editor"]["theme"]["text"] : 'cobalt'; - $setting_invisibles = ($_SESSION["editor"]["invisibles"]["boolean"] != '') ? $_SESSION["editor"]["invisibles"]["boolean"] : 'false'; - $setting_indenting = ($_SESSION["editor"]["indent_guides"]["boolean"] != '') ? $_SESSION["editor"]["indent_guides"]["boolean"] : 'false'; - $setting_numbering = ($_SESSION["editor"]["line_numbers"]["boolean"] != '') ? $_SESSION["editor"]["line_numbers"]["boolean"] : 'true'; - -//get the html values and set them as variables - $code = trim($_POST["code"]); - $command = trim($_POST["command"]); - -//check the captcha - $command_authorized = false; - if (strlen($code) > 0) { - if (strtolower($_SESSION['captcha']) == strtolower($code)) { - $command_authorized = true; - } - } - -//set editor moder - $mode = 'sql'; - -//show the header - require_once "resources/header.php"; - $document['title'] = $text['title-sql_query']; - -//pdo database connection - require_once "sql_query_pdo.php"; - -//scripts and styles - ?> - - - -code = $_SESSION['captcha']; - $image_base64 = $captcha->image_base64(); - -//show the header - echo "
\n"; - echo ""; - echo " "; - echo " "; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
"; - echo " ".$text['title-sql_query']."\n"; - echo " "; - - //add the captcha - echo " \n"; - echo "      \n"; - - //sql controls - echo " "; - //echo " ".$text['label-table']."
"; - echo " \n"; - //echo "

\n"; - //echo " ".$text['label-result_type']."
"; - echo " \n"; - echo "
"; - - echo " "; - echo " "; - - echo "
\n"; - echo $text['description-sql_query']."\n"; - echo "
"; - echo "
"; - -//html form - echo "\n"; //sql db id - echo ""; - echo "\n"; - echo " "; - echo " "; - echo " \n"; - echo "
"; - - echo " "; - if (permission_exists('edit_view') && file_exists($_SERVER["PROJECT_ROOT"]."/app/edit/")) { - echo " "; - echo " "; - echo " "; - } - echo "
"; - echo " \n"; - echo "
"; - - echo "
" - ?> - - - - - - - - - - - - - -
- - - - - -
-
- - "; - echo "
"; - echo "
"; - echo "

"; - ?> - - - - -"; - //echo "".$text['label-results']."\n"; - //echo "

\n"; - echo "\n"; - echo ""; - -//show the footer - require_once "resources/footer.php"; - -?> diff --git a/app/sql_query/sql_query_db.php b/app/sql_query/sql_query_db.php deleted file mode 100644 index 1210453b15..0000000000 --- a/app/sql_query/sql_query_db.php +++ /dev/null @@ -1,131 +0,0 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2019 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -//includes - require_once "root.php"; - require_once "resources/require.php"; - require_once "resources/check_auth.php"; - -//check permissions - if (permission_exists('exec_sql')) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//add the header and title - require_once "resources/header.php"; - $document['title'] = $text['title-databases']; - -//include paging - require_once "resources/paging.php"; - -//get variables used to control the order - $order_by = $_GET["order_by"]; - $order = $_GET["order"]; - -//show the content - - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
".$text['header-databases'].""; - echo " \n"; - if (if_group("superadmin")) { - echo " \n"; - } - echo "
\n"; - echo " ".$text['description-databases'].".

\n"; - echo "
\n"; - - //prepare to page the results - $sql = "select count(*) from v_databases "; - $database = new database; - $num_rows = $database->select($sql, null, 'column'); - - //prepare to page the results - $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; - $param = ""; - $page = $_GET['page']; - if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } - list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); - $offset = $rows_per_page * $page; - - //get the list - $sql = str_replace('count(*)', '*', $sql); - $sql .= order_by($order_by, $order); - $sql .= limit_offset($rows_per_page, $offset); - $database = new database; - $result = $database->select($sql, null, 'all'); - unset($sql); - - $c = 0; - $row_style["0"] = "row_style0"; - $row_style["1"] = "row_style1"; - - echo "\n"; - echo "\n"; - echo th_order_by('database_type', $text['label-type'], $order_by, $order); - echo th_order_by('database_host', $text['label-host'], $order_by, $order); - echo th_order_by('database_name', $text['label-name'], $order_by, $order); - echo th_order_by('database_description', $text['label-description'], $order_by, $order); - echo "\n"; - echo "\n"; - - if (is_array($result) && @sizeof($result) != 0) { - foreach($result as $row) { - $tr_link = "href='exec.php?id=".escape($row['database_uuid'])."'"; - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "\n"; - $c = ($c == 0) ? 1 : 0; - } - } - unset($result, $row); - - echo "
 
".escape($row['database_type'])." ".escape($row['database_host'])." ".escape($row['database_name'])." ".escape($row['database_description'])." "; - echo " ".$v_link_label_edit."\n"; - echo "
"; - echo "

"; - -//include the footer - require_once "resources/footer.php"; -?> diff --git a/app/sql_query/sql_query_pdo.php b/app/sql_query/sql_query_pdo.php deleted file mode 100644 index 2f1d9d8ef9..0000000000 --- a/app/sql_query/sql_query_pdo.php +++ /dev/null @@ -1,242 +0,0 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2012 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane - */ - -//includes - require_once "root.php"; - require_once "resources/require.php"; - require_once "resources/check_auth.php"; - -//check permissions - if (permission_exists('exec_sql')) { - //access granted - } - else { - echo "access denied"; - exit; - } - - //set the default values - if (isset($db_file_path) > 0) { - $db_path = $db_file_path; - $db_name = $dbfilename; - } - -//get the db connection information - if (is_uuid($_REQUEST['id'])) { - $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"]; - $db_host = $row["database_host"]; - $db_port = $row["database_port"]; - $db_name = $row["database_name"]; - $db_username = $row["database_username"]; - $db_password = $row["database_password"]; - $db_path = $row["database_path"]; - } - unset($sql, $parameters, $row); - } - -//unset the database connection - unset($db); - -if (!function_exists('get_db_field_names')) { - function get_db_field_names($db, $table, $db_name='fusionpbx') { - $query = sprintf('SELECT * FROM %s LIMIT 1', $table); - foreach ($db->query($query, PDO::FETCH_ASSOC) as $row) { - return array_keys($row); - } - - // if we're still here, we need to try something else - $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); - //printf('
%s
', print_r($rows, true)); - $row_count = count($rows); - //printf('
%s
', 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); - //printf('
%s
', print_r($rows, true)); - for ($i = 0; $i < $row_count; $i++) { - array_push($fields, $rows[$i]['COLUMN_NAME']); - } - return $fields; - } - } -} - -if ($db_type == "sqlite") { - if (!function_exists('phpmd5')) { - function phpmd5($string) { - return md5($string); - } - } - - if (!function_exists('php_unix_timestamp')) { - function php_unix_timestamp($string) { - return strtotime($string); - } - } - - if (!function_exists('phpnow')) { - function phpnow() { - return date("Y-m-d H:i:s"); - } - } - - if (!function_exists('php_left')) { - function php_left($string, $num) { - return substr($string, 0, $num); - } - } - - if (!function_exists('php_right')) { - function php_right($string, $num) { - return substr($string, (strlen($string)-$num), strlen($string)); - } - } - - if (!function_exists('php_sqlite_data_type')) { - function php_sqlite_data_type($string, $field) { - - //get the string between the start and end characters - $start = '('; - $end = ')'; - $ini = stripos($string,$start); - if ($ini == 0) return ""; - $ini += strlen($start); - $len = stripos($string,$end,$ini) - $ini; - $string = substr($string,$ini,$len); - - $str_data_type = ''; - $string_array = explode(',', $string); - foreach($string_array as $lnvalue) { - $fieldlistarray = explode (" ", $value); - unset($fieldarray, $string, $field); - } - - return $str_data_type; - } - } //end function - - //database connection - try { - //$db = new PDO('sqlite2:example.db'); //sqlite 2 - //$db = new PDO('sqlite::memory:'); //sqlite 3 - $db = new PDO('sqlite:'.realpath($db_path).'/'.$db_name); //sqlite 3 - - //add additional functions to SQLite so that they are accessible inside SQL - //bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] ) - $db->sqliteCreateFunction('md5', 'phpmd5', 1); - $db->sqliteCreateFunction('unix_timestamp', 'php_unix_timestamp', 1); - $db->sqliteCreateFunction('now', 'phpnow', 0); - $db->sqliteCreateFunction('sqlitedatatype', 'php_sqlite_data_type', 2); - $db->sqliteCreateFunction('strleft', 'php_left', 2); - $db->sqliteCreateFunction('strright', 'php_right', 2); - } - catch (PDOException $error) { - print "error: " . $error->getMessage() . "
"; - die(); - } -} //end if db_type sqlite - -if ($db_type == "mysql") { - //database connection - try { - //mysql pdo connection - if (strlen($db_host) == 0 && strlen($db_port) == 0) { - //if both host and port are empty use the unix socket - $db = new PDO("mysql:host=$db_host;unix_socket=/var/run/mysqld/mysqld.sock;dbname=$db_name", $db_username, $db_password); - } - else { - if (strlen($db_port) == 0) { - //leave out port if it is empty - $db = new PDO("mysql:host=$db_host;dbname=$db_name;", $db_username, $db_password, array( - PDO::ATTR_ERRMODE, - PDO::ERRMODE_EXCEPTION - )); - } - else { - $db = new PDO("mysql:host=$db_host;port=$db_port;dbname=$db_name;", $db_username, $db_password, array( - PDO::ATTR_ERRMODE, - PDO::ERRMODE_EXCEPTION - )); - } - } - } - catch (PDOException $error) { - print "error: " . $error->getMessage() . "
"; - die(); - } -} //end if db_type mysql - -if ($db_type == "pgsql") { - //database connection - try { - if (strlen($db_host) > 0) { - if (strlen($db_port) == 0) { $db_port = "5432"; } - $db = new PDO("pgsql:host=$db_host port=$db_port dbname=$db_name user=$db_username password=$db_password"); - } - else { - $db = new PDO("pgsql:dbname=$db_name user=$db_username password=$db_password"); - } - } - catch (PDOException $error) { - print "error: " . $error->getMessage() . "
"; - die(); - } -} //end if db_type pgsql - -if ($db_type == "odbc") { - //database connection - try { - unset($db); - $db = new PDO("odbc:$db_name", "$db_username", "$db_password"); - } - catch (PDOException $e) { - echo 'Connection failed: ' . $e->getMessage(); - } -} //end if db_type odbc - -?> diff --git a/app/sql_query/sql_query_result.php b/app/sql_query/sql_query_result.php deleted file mode 100644 index 2fda85bbca..0000000000 --- a/app/sql_query/sql_query_result.php +++ /dev/null @@ -1,345 +0,0 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2019 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -//includes - include "root.php"; - require_once "resources/require.php"; - require_once "resources/check_auth.php"; - -//check permissions - if (permission_exists('exec_sql')) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//pdo database connection - if (strlen($_REQUEST['id']) > 0) { - require_once "sql_query_pdo.php"; - } - -//check the captcha - $code = trim($_REQUEST["code"]); - $command_authorized = false; - if (strtolower($_SESSION['captcha']) == strtolower($code)) { - $command_authorized = true; - } - if (!$command_authorized) { - //catpcha invalid - exit; - } - -//get allowed table names - switch ($db_type) { - case 'sqlite': $sql = "select name from sqlite_master where type='table' order by name;"; break; - case 'pgsql': $sql = "select table_name as name from information_schema.tables where table_schema='public' and table_type='BASE TABLE' order by 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) { - $tables[] = $row['name']; - } - } - unset($sql, $rows, $row); - -//show the content - if (is_array($_POST)) { - $sql_type = trim($_POST["sql_type"]); - $sql_cmd = trim($_POST["command"]); - $table_name = trim($_POST["table_name"]); - - $header = "\n"; - $header .= "\n"; - $header .= ""; - $header .= "\n"; - $header .= "\n"; - - $footer = "\n"; - $footer .= "\n"; - - if ($sql_type == '') { - - echo $header; - - $c = 0; - $row_style["0"] = "row_style0"; - $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 (is_array($sql_array)) foreach($sql_array as $sql_index => $sql) { - $sql = trim($sql); - - if (sizeof($sql_array) > 1 || $show_query) { - if ($sql_index > 0) { echo "


"; } - echo "".escape($sql).";
"; - } - - $database = new database; - $result = $database->execute($sql, null, 'all'); - $message = $database->message; - - if ($message['message'] == 'OK' && $message['code'] == 200) { - echo "".$text['label-records'].": ".count($result).""; - echo "

\n"; - } - else { - echo "".$text['label-error'].""; - echo "

\n"; - echo $message['message'].' ['.$message['code']."]
\n"; - if (is_array($message['error']) && @sizeof($message['error']) != 0) { - foreach ($message['error'] as $error) { - echo "
".$error."


\n"; - } - } - } - - echo "\n"; - $x = 0; - if (is_array($result[0])) { - echo "\n"; - echo " \n"; - foreach ($result[0] as $key => $value) { - echo "\n"; - $column_array[$x++] = $key; - } - echo " \n"; - echo "\n"; - } - $x = 1; - if (is_array($result)) { - echo "\n"; - foreach ($result as &$row) { - if ($x++ > 1000) { break; } - echo "\n"; - if (is_array($column_array)) { - foreach ($column_array as $column_index => $column) { - echo "\n"; - } - } - echo "\n"; - $c = ($c == 0) ? 1 : 0; - } - echo "\n"; - } - echo "
".escape($key)."
".escape($row[$column])." 
\n"; - echo "
\n"; - - unset($result, $column_array); - } - echo $footer; - } - - if ($sql_type == "inserts") { - echo $header; - - $sql = trim($sql); - - //get the table data - $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; - - if ($message['message'] != 'OK' || $message['code'] != 200) { - echo "".$text['label-error'].""; - echo "

\n"; - echo $message['message'].' ['.$message['code']."]
\n"; - if (is_array($message['error']) && @sizeof($message['error']) != 0) { - foreach ($message['error'] as $error) { - echo "
".$error."


\n"; - } - } - exit; - } - - $x = 0; - if (is_array($result[0])) { - foreach ($result[0] as $key => $value) { - $column_array[$x++] = $key; - } - } - - $column_array_count = count($column_array); - if (is_array($result)) { - foreach ($result as $index => &$row) { - - echo "
\n"; - echo "insert into ".$table_name." ("; - if (is_array($column_array)) { - foreach ($column_array as $column) { - if ($column != "menuid" && $column != "menuparentid") { - $columns[] = $column; - } - } - } - if (is_array($columns) && sizeof($columns) > 0) { - echo implode(', ', $columns); - } - echo ") values ("; - if (is_array($column_array)) { - foreach ($column_array as $column) { - if ($column != "menuid" && $column != "menuparentid") { - $values[] = $row[$column] != '' ? "'".escape($row[$column])."'" : 'null'; - } - } - } - if (is_array($values) && sizeof($values) > 0) { - echo implode(', ', $values); - } - echo ");\n"; - echo "
\n"; - unset($columns, $values); - } - } - - } - echo $footer; - } - - if ($sql_type == "csv") { - - //set the headers - header('Content-type: application/octet-binary'); - if (strlen($sql_cmd) > 0) { - header('Content-Disposition: attachment; filename=data.csv'); - } - else if (in_array($table_name, $tables)) { - header('Content-Disposition: attachment; filename='.$table_name.'.csv'); - } - - //get the table data - if (strlen($sql_cmd) > 0) { - $sql = $sql_cmd; - } - else if (in_array($table_name, $tables)) { - $sql = "select * from ".$table_name; - } - if (strlen($sql) > 0) { - $database = new database; - $result = $database->execute($sql); - $message = $database->message; - - if ($message['message'] != 'OK' || $message['code'] != 200) { - echo "".$text['label-error'].""; - echo "

\n"; - echo $message['message'].' ['.$message['code']."]
\n"; - if (is_array($message['error']) && @sizeof($message['error']) != 0) { - foreach ($message['error'] as $error) { - echo "
".$error."


\n"; - } - } - exit; - } - - //build the column array - $x = 0; - if (is_array($result[0])) { - foreach ($result[0] as $key => $value) { - $column_array[$x] = $key; - $x++; - } - } - - //column names - echo '"'.implode('","', $column_array).'"'."\r\n"; - - //column values - if (is_array($result)) { - foreach ($result as &$row) { - $x = 1; - foreach ($column_array as $column) { - echo '"'.$row[$column].'"'.($x++ < count($column_array) ? ',' : null); - } - echo "\n"; - } - } - } - } - } - -?> \ No newline at end of file