summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorfisharebest <fisharebest@gmail.com>2010-05-28 17:07:17 +0000
committerfisharebest <fisharebest@gmail.com>2010-05-28 17:07:17 +0000
commit802eb597ca73d3ac78cec6da20bf1fc61b40a4c0 (patch)
tree89852678c03dded5b04ab986b4c65515c23eebcf /includes
parent6f1418d07350cbf1b07c9d71f5a686cf51c17356 (diff)
downloadwebtrees-802eb597ca73d3ac78cec6da20bf1fc61b40a4c0.tar.gz
webtrees-802eb597ca73d3ac78cec6da20bf1fc61b40a4c0.tar.bz2
webtrees-802eb597ca73d3ac78cec6da20bf1fc61b40a4c0.zip
Simplify SQL statements. Use "##table_name" instead of "{$TBLPREFIX}table_name"
Diffstat (limited to 'includes')
-rw-r--r--includes/authentication.php70
-rw-r--r--includes/classes/class_gedcomrecord.php4
-rw-r--r--includes/classes/class_media.php4
-rw-r--r--includes/classes/class_menubar.php4
-rw-r--r--includes/classes/class_module.php50
-rw-r--r--includes/classes/class_reportbase.php18
-rw-r--r--includes/classes/class_serviceclient.php6
-rw-r--r--includes/classes/class_stats.php351
-rw-r--r--includes/classes/class_wt_db.php67
-rw-r--r--includes/controllers/advancedsearch_ctrl.php16
-rw-r--r--includes/controllers/remotelink_ctrl.php4
-rw-r--r--includes/functions/functions.php12
-rw-r--r--includes/functions/functions_db.php698
-rw-r--r--includes/functions/functions_edit.php18
-rw-r--r--includes/functions/functions_export.php27
-rw-r--r--includes/functions/functions_import.php124
-rw-r--r--includes/functions/functions_mediadb.php12
-rw-r--r--includes/functions/functions_print_facts.php8
-rw-r--r--includes/hitcount.php6
-rw-r--r--includes/media_reorder.php4
-rw-r--r--includes/media_reorder_count.php4
-rw-r--r--includes/session.php2
-rw-r--r--includes/session_spider.php4
-rw-r--r--includes/set_gedcom_defaults.php2
24 files changed, 571 insertions, 944 deletions
diff --git a/includes/authentication.php b/includes/authentication.php
index 03fb40a840..2edb65bff5 100644
--- a/includes/authentication.php
+++ b/includes/authentication.php
@@ -248,30 +248,22 @@ function adminUserExists() {
// Get the full name for a user
function getUserFullName($user_id) {
- global $TBLPREFIX;
-
- return WT_DB::prepare("SELECT real_name FROM {$TBLPREFIX}user WHERE user_id=?")->execute(array($user_id))->fetchOne();
+ return WT_DB::prepare("SELECT real_name FROM ##user WHERE user_id=?")->execute(array($user_id))->fetchOne();
}
// Set the full name for a user
function setUserFullName($user_id, $real_name) {
- global $TBLPREFIX;
-
- return WT_DB::prepare("UPDATE {$TBLPREFIX}user SET real_name=? WHERE user_id=?")->execute(array($real_name, $user_id));
+ return WT_DB::prepare("UPDATE ##user SET real_name=? WHERE user_id=?")->execute(array($real_name, $user_id));
}
// Get the email for a user
function getUserEmail($user_id) {
- global $TBLPREFIX;
-
- return WT_DB::prepare("SELECT email FROM {$TBLPREFIX}user WHERE user_id=?")->execute(array($user_id))->fetchOne();
+ return WT_DB::prepare("SELECT email FROM ##user WHERE user_id=?")->execute(array($user_id))->fetchOne();
}
// Set the email for a user
function setUserEmail($user_id, $email) {
- global $TBLPREFIX;
-
- return WT_DB::prepare("UPDATE {$TBLPREFIX}user SET email=? WHERE user_id=?")->execute(array($email, $user_id));
+ return WT_DB::prepare("UPDATE ##user SET email=? WHERE user_id=?")->execute(array($email, $user_id));
}
// Get the root person for this gedcom
@@ -296,10 +288,10 @@ function getUserGedcomId($user_id, $ged_id) {
* add a message into the log-file
*/
function AddToLog($log_message, $log_type='error') {
- global $TBLPREFIX, $argc;
+ global $argc;
WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}log (log_type, log_message, ip_address, user_id, gedcom_id) VALUES (?, ?, ?, ?, ?)"
+ "INSERT INTO ##log (log_type, log_message, ip_address, user_id, gedcom_id) VALUES (?, ?, ?, ?, ?)"
)->execute(array(
$log_type,
$log_message,
@@ -312,12 +304,10 @@ function AddToLog($log_message, $log_type='error') {
//----------------------------------- AddToSearchLog
//-- requires a string to add into the searchlog-file
function AddToSearchLog($log_message, $geds) {
- global $TBLPREFIX;
-
$all_geds=get_all_gedcoms();
foreach ($geds as $ged_id=>$ged_name) {
WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}log (log_type, log_message, ip_address, user_id, gedcom_id) VALUES ('search', ?, ?, ?, ?)"
+ "INSERT INTO ##log (log_type, log_message, ip_address, user_id, gedcom_id) VALUES ('search', ?, ?, ?, ?)"
)->execute(array(
(count($all_geds)==count($geds) ? 'Global search: ' : 'Gedcom search: ').$log_message,
$_SERVER['REMOTE_ADDR'],
@@ -330,10 +320,8 @@ function AddToSearchLog($log_message, $geds) {
//----------------------------------- AddToChangeLog
//-- requires a string to add into the changelog-file
function AddToChangeLog($log_message, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}log (log_type, log_message, ip_address, user_id, gedcom_id) VALUES ('change', ?, ?, ?, ?)"
+ "INSERT INTO ##log (log_type, log_message, ip_address, user_id, gedcom_id) VALUES ('change', ?, ?, ?, ?)"
)->execute(array(
$log_message,
$_SERVER['REMOTE_ADDR'],
@@ -345,7 +333,7 @@ function AddToChangeLog($log_message, $ged_id=WT_GED_ID) {
//----------------------------------- addMessage
//-- stores a new message in the database
function addMessage($message) {
- global $TBLPREFIX, $WT_STORE_MESSAGES;
+ global $WT_STORE_MESSAGES;
global $TEXT_DIRECTION;
global $WEBTREES_EMAIL;
@@ -434,7 +422,7 @@ function addMessage($message) {
if (empty($message["created"]))
$message["created"] = gmdate ("D, d M Y H:i:s T");
if ($WT_STORE_MESSAGES && ($message["method"]!="messaging3" && $message["method"]!="mailto" && $message["method"]!="none")) {
- WT_DB::prepare("INSERT INTO {$TBLPREFIX}message (sender, ip_address, user_id, subject, body) VALUES (? ,? ,? ,? ,?)")
+ WT_DB::prepare("INSERT INTO ##message (sender, ip_address, user_id, subject, body) VALUES (? ,? ,? ,? ,?)")
->execute(array($message["from"], $_SERVER['REMOTE_ADDR'], get_user_id($message["to"]), $message["subject"], $message["body"]));
}
if ($message["method"]!="messaging") {
@@ -471,18 +459,14 @@ function addMessage($message) {
//----------------------------------- deleteMessage
//-- deletes a message in the database
function deleteMessage($message_id) {
- global $TBLPREFIX;
-
- return (bool)WT_DB::prepare("DELETE FROM {$TBLPREFIX}message WHERE message_id=?")->execute(array($message_id));
+ return (bool)WT_DB::prepare("DELETE FROM ##message WHERE message_id=?")->execute(array($message_id));
}
//----------------------------------- getUserMessages
//-- Return an array of a users messages
function getUserMessages($user_id) {
- global $TBLPREFIX;
-
$rows=
- WT_DB::prepare("SELECT message_id, sender, subject, body, created FROM {$TBLPREFIX}message WHERE user_id=? ORDER BY message_id DESC")
+ WT_DB::prepare("SELECT message_id, sender, subject, body, created FROM ##message WHERE user_id=? ORDER BY message_id DESC")
->execute(array($user_id))
->fetchAll();
@@ -509,17 +493,15 @@ function getUserMessages($user_id) {
* @param boolean $setdefault if true tells the program to also set these blocks as the blocks for the defaultuser
*/
function setBlocks($username, $ublocks, $setdefault=false) {
- global $TBLPREFIX;
-
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}blocks WHERE b_username=? AND b_name!=?")
+ WT_DB::prepare("DELETE FROM ##blocks WHERE b_username=? AND b_name!=?")
->execute(array($username, 'faq'));
if ($setdefault) {
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}blocks WHERE b_username=?")
+ WT_DB::prepare("DELETE FROM ##blocks WHERE b_username=?")
->execute(array('defaultuser'));
}
- $statement=WT_DB::prepare("INSERT INTO {$TBLPREFIX}blocks (b_id, b_username, b_location, b_order, b_name, b_config) VALUES (?, ?, ?, ?, ?, ?)");
+ $statement=WT_DB::prepare("INSERT INTO ##blocks (b_id, b_username, b_location, b_order, b_name, b_config) VALUES (?, ?, ?, ?, ?, ?)");
foreach($ublocks["main"] as $order=>$block) {
$statement->execute(array(get_next_id("blocks", "b_id"), $username, 'main', $order, $block[0], serialize($block[1])));
@@ -548,30 +530,28 @@ function setBlocks($username, $ublocks, $setdefault=false) {
* @param array $news a news item array
*/
function addNews($news) {
- global $TBLPREFIX;
-
if (!isset($news["date"]))
$news["date"] = client_time();
if (!empty($news["id"])) {
// In case news items are added from usermigrate, it will also contain an ID.
// So we check first if the ID exists in the database. If not, insert instead of update.
$exists=
- WT_DB::prepare("SELECT 1 FROM {$TBLPREFIX}news where n_id=?")
+ WT_DB::prepare("SELECT 1 FROM ##news where n_id=?")
->execute(array($news["id"]))
->fetchOne();
if (!$exists) {
return (bool)
- WT_DB::prepare("INSERT INTO {$TBLPREFIX}news (n_id, n_username, n_date, n_title, n_text) VALUES (?, ? ,? ,? ,?)")
+ WT_DB::prepare("INSERT INTO ##news (n_id, n_username, n_date, n_title, n_text) VALUES (?, ? ,? ,? ,?)")
->execute(array($news["id"], $news["username"], $news["date"], $news["title"], $news["text"]));
} else {
return (bool)
- WT_DB::prepare("UPDATE {$TBLPREFIX}news SET n_date=?, n_title=? , n_text=? WHERE n_id=?")
+ WT_DB::prepare("UPDATE ##news SET n_date=?, n_title=? , n_text=? WHERE n_id=?")
->execute(array($news["date"], $news["title"], $news["text"], $news["id"]));
}
} else {
return (bool)
- WT_DB::prepare("INSERT INTO {$TBLPREFIX}news (n_id, n_username, n_date, n_title, n_text) VALUES (?, ? ,? ,? ,?)")
+ WT_DB::prepare("INSERT INTO ##news (n_id, n_username, n_date, n_title, n_text) VALUES (?, ? ,? ,? ,?)")
->execute(array(get_next_id("news", "n_id"), $news["username"], $news["date"], $news["title"], $news["text"]));
}
}
@@ -583,9 +563,7 @@ function addNews($news) {
* @param int $news_id the id number of the news item to delete
*/
function deleteNews($news_id) {
- global $TBLPREFIX;
-
- return (bool)WT_DB::prepare("DELETE FROM {$TBLPREFIX}news WHERE n_id=?")->execute(array($news_id));
+ return (bool)WT_DB::prepare("DELETE FROM ##news WHERE n_id=?")->execute(array($news_id));
}
/**
@@ -594,10 +572,8 @@ function deleteNews($news_id) {
* @param String $username the username or gedcom file name to get news items for
*/
function getUserNews($username) {
- global $TBLPREFIX;
-
$rows=
- WT_DB::prepare("SELECT * FROM {$TBLPREFIX}news WHERE n_username=? ORDER BY n_date DESC")
+ WT_DB::prepare("SELECT * FROM ##news WHERE n_username=? ORDER BY n_date DESC")
->execute(array($username))
->fetchAll();
@@ -621,10 +597,8 @@ function getUserNews($username) {
* @param int $news_id the id of the news entry to get
*/
function getNewsItem($news_id) {
- global $TBLPREFIX;
-
$row=
- WT_DB::prepare("SELECT * FROM {$TBLPREFIX}news WHERE n_id=?")
+ WT_DB::prepare("SELECT * FROM ##news WHERE n_id=?")
->execute(array($news_id))
->fetchOneRow();
diff --git a/includes/classes/class_gedcomrecord.php b/includes/classes/class_gedcomrecord.php
index 98c06d2dc4..27a02b9a2d 100644
--- a/includes/classes/class_gedcomrecord.php
+++ b/includes/classes/class_gedcomrecord.php
@@ -381,11 +381,9 @@ class GedcomRecord {
* @return boolean
*/
function isMarkedDeleted() {
- global $TBLPREFIX;
-
$tmp=WT_DB::prepare(
"SELECT new_gedcom".
- " FROM {$TBLPREFIX}change".
+ " FROM ##change".
" WHERE status='pending' AND gedcom_id=? AND xref=?".
" ORDER BY change_id desc".
" LIMIT 1"
diff --git a/includes/classes/class_media.php b/includes/classes/class_media.php
index 8916be9573..f96bb5bf06 100644
--- a/includes/classes/class_media.php
+++ b/includes/classes/class_media.php
@@ -261,10 +261,8 @@ class Media extends GedcomRecord {
* @return mixed returns the ID for the for the matching media or null if not found
*/
static function in_obje_list($obje) {
- global $TBLPREFIX;
-
return
- WT_DB::prepare("SELECT m_media FROM {$TBLPREFIX}media WHERE m_file=? AND m_titl LIKE ? AND m_gedfile=?")
+ WT_DB::prepare("SELECT m_media FROM ##media WHERE m_file=? AND m_titl LIKE ? AND m_gedfile=?")
->execute(array($obje->file, $obje->title, WT_GED_ID))
->fetchOne();
}
diff --git a/includes/classes/class_menubar.php b/includes/classes/class_menubar.php
index 25ce6771ac..1700caae41 100644
--- a/includes/classes/class_menubar.php
+++ b/includes/classes/class_menubar.php
@@ -855,7 +855,7 @@ class MenuBar
* @return Menu the menu item
*/
static function getHelpMenu() {
- global $TBLPREFIX, $TEXT_DIRECTION, $WT_IMAGE_DIR, $WT_IMAGES, $SEARCH_SPIDER;
+ global $TEXT_DIRECTION, $WT_IMAGE_DIR, $WT_IMAGES, $SEARCH_SPIDER;
global $SHOW_CONTEXT_HELP, $QUERY_STRING, $helpindex, $action;
if ($TEXT_DIRECTION=="rtl") $ff="_rtl"; else $ff="";
if (!empty($SEARCH_SPIDER)) {
@@ -891,7 +891,7 @@ class MenuBar
$submenu->addOnclick("return helpPopup('help_contents_help');");
$menu->addSubmenu($submenu);
//-- faq sub menu
- if (array_key_exists('faq', WT_Module::getActiveBlocks()) && WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}block WHERE module_name='faq'")->fetchOne()) {
+ if (array_key_exists('faq', WT_Module::getActiveBlocks()) && WT_DB::prepare("SELECT COUNT(*) FROM ##block WHERE module_name='faq'")->fetchOne()) {
$submenu = new Menu(i18n::translate('FAQ'), "module.php?mod=faq&mod_action=show");
if (!empty($WT_IMAGES["menu_help"]["small"]))
diff --git a/includes/classes/class_module.php b/includes/classes/class_module.php
index 3dd7213016..96a161ab88 100644
--- a/includes/classes/class_module.php
+++ b/includes/classes/class_module.php
@@ -102,11 +102,9 @@ abstract class WT_Module {
}
final static public function getActiveModules() {
- global $TBLPREFIX;
-
$module_names=WT_DB::prepare(
"SELECT module_name".
- " FROM {$TBLPREFIX}module".
+ " FROM ##module".
" WHERE status='enabled'".
" ORDER BY module_name"
)->fetchOneColumn();
@@ -119,20 +117,18 @@ abstract class WT_Module {
} else {
// Module has been deleted from disk? Remove it from the database.
AddToLog("Module {$module_name} has been deleted from disk - deleting from database", 'config');
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}module_privacy WHERE module_name=?")->execute(array($module_name));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}module WHERE module_name=?")->execute(array($module_name));
+ WT_DB::prepare("DELETE FROM ##module_privacy WHERE module_name=?")->execute(array($module_name));
+ WT_DB::prepare("DELETE FROM ##module WHERE module_name=?")->execute(array($module_name));
}
}
return $array;
}
final static private function getActiveModulesByComponent($component, $ged_id, $access_level) {
- global $TBLPREFIX;
-
$module_names=WT_DB::prepare(
"SELECT module_name".
- " FROM {$TBLPREFIX}module".
- " JOIN {$TBLPREFIX}module_privacy USING (module_name)".
+ " FROM ##module".
+ " JOIN ##module_privacy USING (module_name)".
" WHERE gedcom_id=? AND component=? AND status='enabled' AND access_level>=?".
" ORDER BY CASE component WHEN 'menu' THEN menu_order WHEN 'sidebar' THEN sidebar_order WHEN 'tab' THEN tab_order ELSE module_name END"
)->execute(array($ged_id, $component, $access_level))->fetchOneColumn();
@@ -145,8 +141,8 @@ abstract class WT_Module {
} else {
// Module has been deleted from disk? Remove it from the database.
AddToLog("Module {$module_name} has been deleted from disk - deleting from database", 'config');
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}module_privacy WHERE module_name=?")->execute(array($module_name));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}module WHERE module_name=?")->execute(array($module_name));
+ WT_DB::prepare("DELETE FROM ##module_privacy WHERE module_name=?")->execute(array($module_name));
+ WT_DB::prepare("DELETE FROM ##module WHERE module_name=?")->execute(array($module_name));
}
}
if ($component!='menu' && $component!='sidebar' && $component!='tab') {
@@ -237,7 +233,6 @@ abstract class WT_Module {
// Get installed blocks
final static public function getInstalledBlocks() {
- global $TBLPREFIX;
$modules=array();
foreach (self::getInstalledModules() as $name=>$module) {
if ($module instanceof WT_Module_Block) {
@@ -249,7 +244,6 @@ abstract class WT_Module {
// Get installed charts
final static public function getInstalledCharts() {
- global $TBLPREFIX;
$modules=array();
foreach (self::getInstalledModules() as $name=>$module) {
if ($module instanceof WT_Module_Chart) {
@@ -261,12 +255,11 @@ abstract class WT_Module {
// Get installed menus
final static public function getInstalledMenus() {
- global $TBLPREFIX;
$modules=array();
foreach (self::getInstalledModules() as $name=>$module) {
if ($module instanceof WT_Module_Menu) {
$module->sort=WT_DB::prepare(
- "SELECT menu_order FROM {$TBLPREFIX}module WHERE module_name=?"
+ "SELECT menu_order FROM ##module WHERE module_name=?"
)->execute(array($module->getName()))->fetchOne();
$modules[$name]=$module;
}
@@ -277,7 +270,6 @@ abstract class WT_Module {
// Get installed reports
final static public function getInstalledReports() {
- global $TBLPREFIX;
$modules=array();
foreach (self::getInstalledModules() as $name=>$module) {
if ($module instanceof WT_Module_Report) {
@@ -289,12 +281,11 @@ abstract class WT_Module {
// Get installed sidebars
final static public function getInstalledSidebars() {
- global $TBLPREFIX;
$modules=array();
foreach (self::getInstalledModules() as $name=>$module) {
if ($module instanceof WT_Module_Sidebar) {
$module->sort=WT_DB::prepare(
- "SELECT sidebar_order FROM {$TBLPREFIX}module WHERE module_name=?"
+ "SELECT sidebar_order FROM ##module WHERE module_name=?"
)->execute(array($module->getName()))->fetchOne();
$modules[$name]=$module;
}
@@ -305,12 +296,11 @@ abstract class WT_Module {
// Get installed tabs
final static public function getInstalledTabs() {
- global $TBLPREFIX;
$modules=array();
foreach (self::getInstalledModules() as $name=>$module) {
if ($module instanceof WT_Module_Tab) {
$module->sort=WT_DB::prepare(
- "SELECT tab_order FROM {$TBLPREFIX}module WHERE module_name=?"
+ "SELECT tab_order FROM ##module WHERE module_name=?"
)->execute(array($module->getName()))->fetchOne();
$modules[$name]=$module;
}
@@ -321,7 +311,6 @@ abstract class WT_Module {
// Get installed themes
final static public function getInstalledThemes() {
- global $TBLPREFIX;
$modules=array();
foreach (self::getInstalledModules() as $name=>$module) {
if ($module instanceof WT_Module_Theme) {
@@ -333,9 +322,8 @@ abstract class WT_Module {
//
final static public function setDefaultAccess($ged_id) {
- global $TBLPREFIX;
foreach (self::getInstalledModules() as $module) {
- WT_DB::prepare("INSERT IGNORE INTO {$TBLPREFIX}module (module_name, menu_order, sidebar_order, tab_order) VALUES (?, ?, ?, ?)")
+ WT_DB::prepare("INSERT IGNORE INTO ##module (module_name, menu_order, sidebar_order, tab_order) VALUES (?, ?, ?, ?)")
->execute(array(
$module->getName(),
$module instanceof WT_Module_Menu ? $module->defaultMenuOrder () : null,
@@ -343,40 +331,40 @@ abstract class WT_Module {
$module instanceof WT_Module_Tab ? $module->defaultTabOrder () : null
));
}
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}module_privacy WHERE gedcom_id=?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##module_privacy WHERE gedcom_id=?")->execute(array($ged_id));
foreach (self::getInstalledMenus() as $module) {
WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'menu', ?)"
+ "INSERT INTO ##module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'menu', ?)"
)->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel()));
}
foreach (self::getInstalledSidebars() as $module) {
WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'sidebar', ?)"
+ "INSERT INTO ##module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'sidebar', ?)"
)->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel()));
}
foreach (self::getInstalledTabs() as $module) {
WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'tab', ?)"
+ "INSERT INTO ##module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'tab', ?)"
)->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel()));
}
foreach (self::getInstalledBlocks() as $module) {
WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'block', ?)"
+ "INSERT INTO ##module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'block', ?)"
)->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel()));
}
foreach (self::getInstalledCharts() as $module) {
WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'charts', ?)"
+ "INSERT INTO ##module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'charts', ?)"
)->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel()));
}
foreach (self::getInstalledReports() as $module) {
WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'report', ?)"
+ "INSERT INTO ##module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'report', ?)"
)->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel()));
}
foreach (self::getInstalledThemes() as $module) {
WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'theme', ?)"
+ "INSERT INTO ##module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'theme', ?)"
)->execute(array($module->getName(), $ged_id, $module->defaultAccessLevel()));
}
}
diff --git a/includes/classes/class_reportbase.php b/includes/classes/class_reportbase.php
index 04b4ca54e3..5d4f9dc06b 100644
--- a/includes/classes/class_reportbase.php
+++ b/includes/classes/class_reportbase.php
@@ -3164,7 +3164,7 @@ function LineSHandler($attrs) {
*/
function ListSHandler($attrs) {
global $gedrec, $repeats, $repeatBytes, $list, $repeatsStack, $processRepeats, $parser, $vars, $sortby;
- global $GEDCOM, $TBLPREFIX;
+ global $GEDCOM;
$processRepeats++;
if ($processRepeats > 1) return;
@@ -3190,10 +3190,10 @@ function ListSHandler($attrs) {
case "pending":
$rows=WT_DB::prepare(
"SELECT CASE new_gedcom WHEN '' THEN old_gedcom ELSE new_gedcom END AS gedcom".
- " FROM {$TBLPREFIX}change".
+ " FROM ##change".
" WHERE (xref, change_id) IN (".
" SELECT xref, MAX(change_id)".
- " FROM {$TBLPREFIX}change".
+ " FROM ##change".
" WHERE status='pending' AND gedcom_id=?".
" GROUP BY xref".
" )"
@@ -3215,7 +3215,7 @@ function ListSHandler($attrs) {
$value=preg_replace('/\$(\w+)/e', '$vars["\\1"]["id"]', $value);
// Convert the various filters into SQL
if (preg_match('/^(\w+):DATE (LTE|GTE) (.+)$/', $value, $match)) {
- $sql_join[]="JOIN {$TBLPREFIX}dates AS {$attr} ON ({$attr}.d_file={$sql_col_prefix}file AND {$attr}.d_gid={$sql_col_prefix}id)";
+ $sql_join[]="JOIN ##dates AS {$attr} ON ({$attr}.d_file={$sql_col_prefix}file AND {$attr}.d_gid={$sql_col_prefix}id)";
$sql_where[]="{$attr}.d_fact='{$match[1]}'";
$date=new GedcomDate($match[3]);
if ($match[2]=="LTE") {
@@ -3231,7 +3231,7 @@ function ListSHandler($attrs) {
} elseif (($listname=="individual") && (preg_match('/^NAME CONTAINS (.*)$/', $value, $match))){
// Do nothing, unless you have to
if (($match[1] != "") or ($sortby=="NAME")){
- $sql_join[]="JOIN {$TBLPREFIX}name AS {$attr} ON (n_file={$sql_col_prefix}file AND n_id={$sql_col_prefix}id)";
+ $sql_join[]="JOIN ##name AS {$attr} ON (n_file={$sql_col_prefix}file AND n_id={$sql_col_prefix}id)";
// Search the DB only if there is any name supplied
if ($match[1] != ""){
$names = explode(" ", $match[1]);
@@ -3248,8 +3248,8 @@ function ListSHandler($attrs) {
unset($attrs[$attr]); // This filter has been fully processed
} elseif (($listname=="family") && (preg_match('/^NAME CONTAINS (.+)$/', $value, $match))) {
// Eventually, family "names" will be stored in pgv_name. Until then, an extra is needed....
- $sql_join[]="JOIN {$TBLPREFIX}link AS {$attr}a ON ({$attr}a.l_file={$sql_col_prefix}file AND {$attr}a.l_from={$sql_col_prefix}id)";
- $sql_join[]="JOIN {$TBLPREFIX}name AS {$attr}b ON ({$attr}b.n_file={$sql_col_prefix}file AND n_id={$sql_col_prefix}id)";
+ $sql_join[]="JOIN ##link AS {$attr}a ON ({$attr}a.l_file={$sql_col_prefix}file AND {$attr}a.l_from={$sql_col_prefix}id)";
+ $sql_join[]="JOIN ##name AS {$attr}b ON ({$attr}b.n_file={$sql_col_prefix}file AND n_id={$sql_col_prefix}id)";
$sql_where[]="{$attr}a.l_type=IN ('HUSB, 'WIFE')";
$sql_where[]="{$attr}.n_full LIKE ".WT_DB::quote(utf8_strtoupper("%{$match[1]}%"));
if ($sortby=="NAME") {
@@ -3258,8 +3258,8 @@ function ListSHandler($attrs) {
}
unset($attrs[$attr]); // This filter has been fully processed
} elseif (preg_match('/^(?:\w+):PLAC CONTAINS (.+)$/', $value, $match)) {
- $sql_join[]="JOIN {$TBLPREFIX}places AS {$attr}a ON ({$attr}a.p_file={$sql_col_prefix}file)";
- $sql_join[]="JOIN {$TBLPREFIX}placelinks AS {$attr}b ON ({$attr}a.p_file={$attr}b.pl_file AND {$attr}b.pl_p_id={$attr}a.p_id AND {$attr}b.pl_gid={$sql_col_prefix}id)";
+ $sql_join[]="JOIN ##places AS {$attr}a ON ({$attr}a.p_file={$sql_col_prefix}file)";
+ $sql_join[]="JOIN ##placelinks AS {$attr}b ON ({$attr}a.p_file={$attr}b.pl_file AND {$attr}b.pl_p_id={$attr}a.p_id AND {$attr}b.pl_gid={$sql_col_prefix}id)";
$sql_where[]="{$attr}a.p_place LIKE ".WT_DB::quote(utf8_strtoupper("%{$match[1]}%"));
// Don't unset this filter. This is just the first primary PLAC filter to reduce the returned list from the DB
}
diff --git a/includes/classes/class_serviceclient.php b/includes/classes/class_serviceclient.php
index 567ea0648b..acb6f168f3 100644
--- a/includes/classes/class_serviceclient.php
+++ b/includes/classes/class_serviceclient.php
@@ -619,7 +619,7 @@ class ServiceClient extends GedcomRecord {
* @param string $remote the remote id that matches the $local id
*/
static function setSameId($local, $remote) {
- global $TBLPREFIX, $GEDCOM;
+ global $GEDCOM;
if ($local == $remote) {
debug_print_backtrace();
@@ -628,7 +628,7 @@ class ServiceClient extends GedcomRecord {
//-- check if the link already exists
$gid=get_remote_id($remote);
if (empty($gid)) {
- WT_DB::prepare("INSERT INTO {$TBLPREFIX}remotelinks (r_gid, r_linkid, r_file) VALUES (? ,? ,?)")
+ WT_DB::prepare("INSERT INTO ##remotelinks (r_gid, r_linkid, r_file) VALUES (? ,? ,?)")
->execute(array($local, $remote, get_id_from_gedcom($GEDCOM)));
}
}
@@ -723,7 +723,7 @@ class ServiceClient extends GedcomRecord {
* @param boolean $firstLink is this the first time this record is being linked
*/
function mergeGedcomRecord($xref, $localrec, $isStub=false, $firstLink=false) {
- global $GEDCOM, $TBLPREFIX;
+ global $GEDCOM;
if (!$isStub) {
$gedrec = find_gedcom_record($this->xref.":".$xref, get_id_from_gedcom($GEDCOM));
diff --git a/includes/classes/class_stats.php b/includes/classes/class_stats.php
index e1dacd0cbe..5917159af3 100644
--- a/includes/classes/class_stats.php
+++ b/includes/classes/class_stats.php
@@ -276,10 +276,8 @@ class stats {
}
function gedcomUpdated() {
- global $TBLPREFIX;
-
$row=
- WT_DB::prepareLimit("SELECT d_year, d_month, d_day FROM {$TBLPREFIX}dates WHERE d_file=? AND d_fact=? ORDER BY d_julianday1 DESC, d_type", 1)
+ WT_DB::prepareLimit("SELECT d_year, d_month, d_day FROM ##dates WHERE d_file=? AND d_fact=? ORDER BY d_julianday1 DESC, d_type", 1)
->execute(array($this->_ged_id, 'CHAN'))
->fetchOneRow();
if ($row) {
@@ -375,17 +373,14 @@ class stats {
}
function totalIndividuals() {
- global $TBLPREFIX;
-
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}individuals WHERE i_file=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##individuals WHERE i_file=?")
->execute(array($this->_ged_id))
->fetchOne();
}
function totalIndisWithSources() {
- global $TBLPREFIX, $DBTYPE;
- $rows=self::_runSQL("SELECT COUNT(DISTINCT i_id) AS tot FROM {$TBLPREFIX}link, {$TBLPREFIX}individuals WHERE i_id=l_from AND i_file=l_file AND l_file=".$this->_ged_id." AND l_type='SOUR'");
+ $rows=self::_runSQL("SELECT COUNT(DISTINCT i_id) AS tot FROM ##link, ##individuals WHERE i_id=l_from AND i_file=l_file AND l_file=".$this->_ged_id." AND l_type='SOUR'");
return $rows[0]['tot'];
}
@@ -417,16 +412,14 @@ class stats {
}
function totalFamilies() {
- global $TBLPREFIX;
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}families WHERE f_file=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##families WHERE f_file=?")
->execute(array($this->_ged_id))
->fetchOne();
}
function totalFamsWithSources() {
- global $TBLPREFIX, $DBTYPE;
- $rows=self::_runSQL("SELECT COUNT(DISTINCT f_id) AS tot FROM {$TBLPREFIX}link, {$TBLPREFIX}families WHERE f_id=l_from AND f_file=l_file AND l_file=".$this->_ged_id." AND l_type='SOUR'");
+ $rows=self::_runSQL("SELECT COUNT(DISTINCT f_id) AS tot FROM ##link, ##families WHERE f_id=l_from AND f_file=l_file AND l_file=".$this->_ged_id." AND l_type='SOUR'");
return $rows[0]['tot'];
}
@@ -458,9 +451,8 @@ class stats {
}
function totalSources() {
- global $TBLPREFIX;
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}sources WHERE s_file=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##sources WHERE s_file=?")
->execute(array($this->_ged_id))
->fetchOne();
}
@@ -470,9 +462,8 @@ class stats {
}
function totalNotes() {
- global $TBLPREFIX;
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}other WHERE o_type=? AND o_file=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##other WHERE o_type=? AND o_file=?")
->execute(array('NOTE', $this->_ged_id))
->fetchOne();
}
@@ -482,9 +473,8 @@ class stats {
}
function totalOtherRecords() {
- global $TBLPREFIX;
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}other WHERE o_type<>? AND o_file=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##other WHERE o_type<>? AND o_file=?")
->execute(array('NOTE', $this->_ged_id))
->fetchOne();
}
@@ -494,7 +484,6 @@ class stats {
}
function totalSurnames($params = null) {
- global $DBTYPE, $TBLPREFIX;
if ($params) {
$qs=implode(',', array_fill(0, count($params), '?'));
$opt="IN ({$qs})";
@@ -507,13 +496,12 @@ class stats {
}
$vars[]=$this->_ged_id;
return (int)
- WT_DB::prepare("SELECT COUNT({$distinct} n_surn) FROM {$TBLPREFIX}name WHERE n_surn {$opt} AND n_file=?")
+ WT_DB::prepare("SELECT COUNT({$distinct} n_surn) FROM ##name WHERE n_surn {$opt} AND n_file=?")
->execute($vars)
->fetchOne();
}
function totalGivennames($params = null) {
- global $DBTYPE, $TBLPREFIX;
if ($params) {
$qs=implode(',', array_fill(0, count($params), '?'));
$opt="IN ({$qs})";
@@ -526,15 +514,13 @@ class stats {
}
$vars[]=$this->_ged_id;
return (int)
- WT_DB::prepare("SELECT COUNT({$distinct} n_givn) FROM {$TBLPREFIX}name WHERE n_givn {$opt} AND n_file=?")
+ WT_DB::prepare("SELECT COUNT({$distinct} n_givn) FROM ##name WHERE n_givn {$opt} AND n_file=?")
->execute($vars)
->fetchOne();
}
function totalEvents($params = null) {
- global $TBLPREFIX;
-
- $sql="SELECT COUNT(*) AS tot FROM {$TBLPREFIX}dates WHERE d_file=?";
+ $sql="SELECT COUNT(*) AS tot FROM ##dates WHERE d_file=?";
$vars=array($this->_ged_id);
$no_types=array('HEAD', 'CHAN');
@@ -600,9 +586,8 @@ class stats {
}
function totalSexMales() {
- global $TBLPREFIX;
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}individuals WHERE i_file=? AND i_sex=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##individuals WHERE i_file=? AND i_sex=?")
->execute(array($this->_ged_id, 'M'))
->fetchOne();
}
@@ -612,9 +597,8 @@ class stats {
}
function totalSexFemales() {
- global $TBLPREFIX;
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}individuals WHERE i_file=? AND i_sex=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##individuals WHERE i_file=? AND i_sex=?")
->execute(array($this->_ged_id, 'F'))
->fetchOne();
}
@@ -624,9 +608,8 @@ class stats {
}
function totalSexUnknown() {
- global $TBLPREFIX;
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}individuals WHERE i_file=? AND i_sex=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##individuals WHERE i_file=? AND i_sex=?")
->execute(array($this->_ged_id, 'U'))
->fetchOne();
}
@@ -671,9 +654,8 @@ class stats {
}
function totalLiving() {
- global $TBLPREFIX;
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}individuals WHERE i_file=? AND i_isdead=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##individuals WHERE i_file=? AND i_isdead=?")
->execute(array($this->_ged_id, 0))
->fetchOne();
}
@@ -683,9 +665,8 @@ class stats {
}
function totalDeceased() {
- global $TBLPREFIX;
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}individuals WHERE i_file=? AND i_isdead=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##individuals WHERE i_file=? AND i_isdead=?")
->execute(array($this->_ged_id, 1))
->fetchOne();
}
@@ -695,9 +676,8 @@ class stats {
}
function totalMortalityUnknown() {
- global $TBLPREFIX;
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}individuals WHERE i_file=? AND i_isdead=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##individuals WHERE i_file=? AND i_isdead=?")
->execute(array($this->_ged_id, -1))
->fetchOne();
}
@@ -707,8 +687,7 @@ class stats {
}
function mortalityUnknown() {
- global $TBLPREFIX;
- $rows=self::_runSQL("SELECT i_id AS id FROM {$TBLPREFIX}individuals WHERE i_file={$this->_ged_id} AND i_isdead=-1");
+ $rows=self::_runSQL("SELECT i_id AS id FROM ##individuals WHERE i_file={$this->_ged_id} AND i_isdead=-1");
if (!isset($rows[0])) {return '';}
return $rows;
}
@@ -765,12 +744,12 @@ class stats {
}
function _totalMediaType($type='all') {
- global $TBLPREFIX, $MULTI_MEDIA;
+ global $MULTI_MEDIA;
if (!$MULTI_MEDIA || !in_array($type, self::$_media_types) && $type != 'all' && $type != 'unknown') {
return 0;
}
- $sql="SELECT COUNT(*) AS tot FROM {$TBLPREFIX}media WHERE m_gedfile=?";
+ $sql="SELECT COUNT(*) AS tot FROM ##media WHERE m_gedfile=?";
$vars=array($this->_ged_id);
if ($type != 'all') {
@@ -879,7 +858,7 @@ class stats {
///////////////////////////////////////////////////////////////////////////////
function _mortalityQuery($type='full', $life_dir='ASC', $birth_death='BIRT') {
- global $TBLPREFIX, $SHOW_ID_NUMBERS, $listDir, $DBTYPE, $TEXT_DIRECTION;
+ global $SHOW_ID_NUMBERS, $listDir, $DBTYPE, $TEXT_DIRECTION;
if ($birth_death == 'MARR') {
$query_field = "'".str_replace('|', "','", WT_EVENTS_MARR)."'";
} else if ($birth_death == 'DIV') {
@@ -898,7 +877,7 @@ class stats {
}
$rows=self::_runSQL(''
."SELECT d_year, d_type, d_fact, d_gid"
- ." FROM {$TBLPREFIX}dates"
+ ." FROM ##dates"
." WHERE d_file={$this->_ged_id} AND d_fact IN ({$query_field}) AND d_julianday1<>0"
." ORDER BY d_julianday1 {$life_dir}, d_type",
1
@@ -912,7 +891,7 @@ class stats {
.' d2.d_fact,'
.' d2.d_gid'
.' FROM'
- ." {$TBLPREFIX}dates AS d2"
+ ." ##dates AS d2"
.' WHERE'
." d2.d_file={$this->_ged_id} AND"
." d2.d_fact IN ({$query_field}) AND"
@@ -920,12 +899,12 @@ class stats {
.' SELECT'
." {$dmod}(d_julianday1)"
.' FROM'
- ." {$TBLPREFIX}dates"
+ ." ##dates"
.' JOIN ('
.' SELECT'
.' d1.d_gid, MIN(d1.d_julianday1) as date'
.' FROM'
- ." {$TBLPREFIX}dates AS d1"
+ ." ##dates AS d1"
.' WHERE'
." d1.d_fact IN ({$query_field}) AND"
." d1.d_file={$this->_ged_id} AND"
@@ -977,17 +956,16 @@ class stats {
}
function _statsPlaces($what='ALL', $fact=false, $parent=0, $country=false) {
- global $TBLPREFIX;
if ($fact) {
if ($what=='INDI') {
$rows=
- WT_DB::prepare("SELECT i_gedcom AS ged FROM {$TBLPREFIX}individuals WHERE i_file=?")
+ WT_DB::prepare("SELECT i_gedcom AS ged FROM ##individuals WHERE i_file=?")
->execute(array($this->_ged_id))
->fetchAll();
}
else if ($what=='FAM') {
$rows=
- WT_DB::prepare("SELECT f_gedcom AS ged FROM {$TBLPREFIX}families WHERE f_file=?")
+ WT_DB::prepare("SELECT f_gedcom AS ged FROM ##families WHERE f_file=?")
->execute(array($this->_ged_id))
->fetchAll();
}
@@ -1014,10 +992,10 @@ class stats {
// used by placehierarchy googlemap module
else if ($parent>0) {
if ($what=='INDI') {
- $join = " JOIN {$TBLPREFIX}individuals ON pl_file = i_file AND pl_gid = i_id";
+ $join = " JOIN ##individuals ON pl_file = i_file AND pl_gid = i_id";
}
else if ($what=='FAM') {
- $join = " JOIN {$TBLPREFIX}families ON pl_file = f_file AND pl_gid = f_id";
+ $join = " JOIN ##families ON pl_file = f_file AND pl_gid = f_id";
}
else {
$join = "";
@@ -1027,8 +1005,8 @@ class stats {
.' p_place AS place,'
.' COUNT(*) AS tot'
.' FROM'
- ." {$TBLPREFIX}places"
- ." JOIN {$TBLPREFIX}placelinks ON pl_file=p_file AND p_id=pl_p_id"
+ ." ##places"
+ ." JOIN ##placelinks ON pl_file=p_file AND p_id=pl_p_id"
.$join
.' WHERE'
." p_id={$parent} AND"
@@ -1040,10 +1018,10 @@ class stats {
}
else {
if ($what=='INDI') {
- $join = " JOIN {$TBLPREFIX}individuals ON pl_file = i_file AND pl_gid = i_id";
+ $join = " JOIN ##individuals ON pl_file = i_file AND pl_gid = i_id";
}
else if ($what=='FAM') {
- $join = " JOIN {$TBLPREFIX}families ON pl_file = f_file AND pl_gid = f_id";
+ $join = " JOIN ##families ON pl_file = f_file AND pl_gid = f_id";
}
else {
$join = "";
@@ -1053,8 +1031,8 @@ class stats {
.' p_place AS country,'
.' COUNT(*) AS tot'
.' FROM'
- ." {$TBLPREFIX}places"
- ." JOIN {$TBLPREFIX}placelinks ON pl_file=p_file AND p_id=pl_p_id"
+ ." ##places"
+ ." JOIN ##placelinks ON pl_file=p_file AND p_id=pl_p_id"
.$join
.' WHERE'
." p_file={$this->_ged_id}"
@@ -1067,10 +1045,8 @@ class stats {
}
function totalPlaces() {
- global $TBLPREFIX;
-
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}places WHERE p_file=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##places WHERE p_file=?")
->execute(array($this->_ged_id))
->fetchOne();
}
@@ -1253,24 +1229,24 @@ class stats {
}
function statsBirth($simple=true, $sex=false, $year1=-1, $year2=-1, $params=null) {
- global $TBLPREFIX, $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_S_CHART_X, $WT_STATS_S_CHART_Y;
+ global $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_S_CHART_X, $WT_STATS_S_CHART_Y;
if ($simple) {
- $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM {$TBLPREFIX}dates "
+ $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM ##dates "
."WHERE "
."d_file={$this->_ged_id} AND "
.'d_year<>0 AND '
."d_fact='BIRT' AND "
."d_type='@#DGREGORIAN@'";
} else if ($sex) {
- $sql = "SELECT d_month, i_sex, COUNT(*) AS total FROM {$TBLPREFIX}dates "
- ."JOIN {$TBLPREFIX}individuals ON d_file = i_file AND d_gid = i_id "
+ $sql = "SELECT d_month, i_sex, COUNT(*) AS total FROM ##dates "
+ ."JOIN ##individuals ON d_file = i_file AND d_gid = i_id "
."WHERE "
."d_file={$this->_ged_id} AND "
."d_fact='BIRT' AND "
."d_type='@#DGREGORIAN@'";
} else {
- $sql = "SELECT d_month, COUNT(*) AS total FROM {$TBLPREFIX}dates "
+ $sql = "SELECT d_month, COUNT(*) AS total FROM ##dates "
."WHERE "
."d_file={$this->_ged_id} AND "
."d_fact='BIRT' AND "
@@ -1311,24 +1287,24 @@ class stats {
}
function statsDeath($simple=true, $sex=false, $year1=-1, $year2=-1, $params=null) {
- global $TBLPREFIX, $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_S_CHART_X, $WT_STATS_S_CHART_Y;
+ global $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_S_CHART_X, $WT_STATS_S_CHART_Y;
if ($simple) {
- $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM {$TBLPREFIX}dates "
+ $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM ##dates "
."WHERE "
."d_file={$this->_ged_id} AND "
.'d_year<>0 AND '
."d_fact='DEAT' AND "
."d_type='@#DGREGORIAN@'";
} else if ($sex) {
- $sql = "SELECT d_month, i_sex, COUNT(*) AS total FROM {$TBLPREFIX}dates "
- ."JOIN {$TBLPREFIX}individuals ON d_file = i_file AND d_gid = i_id "
+ $sql = "SELECT d_month, i_sex, COUNT(*) AS total FROM ##dates "
+ ."JOIN ##individuals ON d_file = i_file AND d_gid = i_id "
."WHERE "
."d_file={$this->_ged_id} AND "
."d_fact='DEAT' AND "
."d_type='@#DGREGORIAN@'";
} else {
- $sql = "SELECT d_month, COUNT(*) AS total FROM {$TBLPREFIX}dates "
+ $sql = "SELECT d_month, COUNT(*) AS total FROM ##dates "
."WHERE "
."d_file={$this->_ged_id} AND "
."d_fact='DEAT' AND "
@@ -1401,7 +1377,7 @@ class stats {
///////////////////////////////////////////////////////////////////////////////
function _longlifeQuery($type='full', $sex='F') {
- global $TBLPREFIX, $SHOW_ID_NUMBERS, $listDir;
+ global $SHOW_ID_NUMBERS, $listDir;
$sex_search = ' 1=1';
if ($sex == 'F') {
@@ -1415,9 +1391,9 @@ class stats {
.' death.d_gid AS id,'
.' death.d_julianday2-birth.d_julianday1 AS age'
.' FROM'
- ." {$TBLPREFIX}dates AS death,"
- ." {$TBLPREFIX}dates AS birth,"
- ." {$TBLPREFIX}individuals AS indi"
+ ." ##dates AS death,"
+ ." ##dates AS birth,"
+ ." ##individuals AS indi"
.' WHERE'
.' indi.i_id=birth.d_gid AND'
.' birth.d_gid=death.d_gid AND'
@@ -1440,17 +1416,17 @@ class stats {
.' death.d_julianday2-birth.d_julianday1 AS age'
.' FROM'
.' (SELECT d_gid, d_file, MIN(d_julianday1) AS birth_jd'
- .' FROM {$TBLPREFIX}date'
+ .' FROM ##date'
." WHERE d_fact IN ('BIRT', 'CHR', 'BAPM', '_BRTM') AND d_julianday1>0"
.' GROUP BY d_gid, d_file'
.' ) AS birth'
.' JOIN ('
.' SELECT d_gid, d_file, MIN(d_julianday1) AS death_jd'
- .' FROM {$TBLPREFIX}date'
+ .' FROM ##date'
." WHERE d_fact IN ('DEAT', 'BURI', 'CREM') AND d_julianday1>0"
.' GROUP BY d_gid, d_file'
.' ) AS death USING (d_gid, d_file)'
- .' JOIN {$TBLPREFIX}individuals ON (d_gid=i_id AND d_file=i_file)'
+ .' JOIN ##individuals ON (d_gid=i_id AND d_file=i_file)'
.' WHERE'
." i_file={$this->_ged_id} AND"
.$sex_search
@@ -1489,7 +1465,7 @@ class stats {
}
function _topTenOldest($type='list', $sex='BOTH', $params=null) {
- global $TBLPREFIX, $TEXT_DIRECTION;
+ global $TEXT_DIRECTION;
if ($sex == 'F') {
$sex_search = " AND i_sex='F'";
@@ -1504,9 +1480,9 @@ class stats {
.' MAX(death.d_julianday2-birth.d_julianday1) AS age,'
.' death.d_gid AS deathdate'
.' FROM'
- ." {$TBLPREFIX}dates AS death,"
- ." {$TBLPREFIX}dates AS birth,"
- ." {$TBLPREFIX}individuals AS indi"
+ ." ##dates AS death,"
+ ." ##dates AS birth,"
+ ." ##individuals AS indi"
.' WHERE'
.' indi.i_id=birth.d_gid AND'
.' birth.d_gid=death.d_gid AND'
@@ -1560,7 +1536,7 @@ class stats {
}
function _topTenOldestAlive($type='list', $sex='BOTH', $params=null) {
- global $TBLPREFIX, $TEXT_DIRECTION;
+ global $TEXT_DIRECTION;
if (!WT_USER_CAN_ACCESS) return i18n::translate('This information is private and cannot be shown.');
if ($sex == 'F') {
@@ -1576,8 +1552,8 @@ class stats {
.' birth.d_gid AS id,'
.' MIN(birth.d_julianday1) AS age'
.' FROM'
- ." {$TBLPREFIX}dates AS birth,"
- ." {$TBLPREFIX}individuals AS indi"
+ ." ##dates AS birth,"
+ ." ##individuals AS indi"
.' WHERE'
.' indi.i_id=birth.d_gid AND'
.' indi.i_isdead=0 AND'
@@ -1625,7 +1601,6 @@ class stats {
}
function _averageLifespanQuery($sex='BOTH', $show_years=false) {
- global $TBLPREFIX;
if ($sex == 'F') {
$sex_search = " AND i_sex='F'";
} elseif ($sex == 'M') {
@@ -1637,9 +1612,9 @@ class stats {
.' SELECT'
.' AVG(death.d_julianday2-birth.d_julianday1) AS age'
.' FROM'
- ." {$TBLPREFIX}dates AS death,"
- ." {$TBLPREFIX}dates AS birth,"
- ." {$TBLPREFIX}individuals AS indi"
+ ." ##dates AS death,"
+ ." ##dates AS birth,"
+ ." ##individuals AS indi"
.' WHERE'
.' indi.i_id=birth.d_gid AND'
.' birth.d_gid=death.d_gid AND'
@@ -1670,8 +1645,6 @@ class stats {
}
function statsAge($simple=true, $related='BIRT', $sex='BOTH', $year1=-1, $year2=-1, $params=null) {
- global $TBLPREFIX;
-
if ($simple) {
if (isset($params[0]) && $params[0] != '') {$size = strtolower($params[0]);}else{$size = '230x250';}
$sizes = explode('x', $size);
@@ -1681,9 +1654,9 @@ class stats {
.' ROUND((death.d_year+49.1)/100) AS century,'
.' i_sex AS sex'
.' FROM'
- ." {$TBLPREFIX}dates AS death,"
- ." {$TBLPREFIX}dates AS birth,"
- ." {$TBLPREFIX}individuals AS indi"
+ ." ##dates AS death,"
+ ." ##dates AS birth,"
+ ." ##individuals AS indi"
.' WHERE'
.' indi.i_id=birth.d_gid AND'
.' birth.d_gid=death.d_gid AND'
@@ -1763,9 +1736,9 @@ class stats {
.' SELECT'
.' death.d_julianday2-birth.d_julianday1 AS age'
.' FROM'
- ." {$TBLPREFIX}dates AS death,"
- ." {$TBLPREFIX}dates AS birth,"
- ." {$TBLPREFIX}individuals AS indi"
+ ." ##dates AS death,"
+ ." ##dates AS birth,"
+ ." ##individuals AS indi"
.' WHERE'
.' indi.i_id=birth.d_gid AND'
.' birth.d_gid=death.d_gid AND'
@@ -1828,7 +1801,7 @@ class stats {
///////////////////////////////////////////////////////////////////////////////
function _eventQuery($type, $direction, $facts) {
- global $TBLPREFIX, $SHOW_ID_NUMBERS, $listDir;
+ global $SHOW_ID_NUMBERS, $listDir;
$eventTypes = array(
'BIRT'=>i18n::translate('birth'),
'DEAT'=>i18n::translate('death'),
@@ -1848,7 +1821,7 @@ class stats {
.' d_fact AS fact,'
.' d_type AS type'
.' FROM'
- ." {$TBLPREFIX}dates"
+ ." ##dates"
.' WHERE'
." d_file={$this->_ged_id} AND"
." d_gid<>'HEAD' AND"
@@ -1937,7 +1910,6 @@ class stats {
* Query the database for marriage tags.
*/
function _marriageQuery($type='full', $age_dir='ASC', $sex='F', $show_years=false) {
- global $TBLPREFIX;
if ($sex == 'F') {$sex_field = 'f_wife';}else{$sex_field = 'f_husb';}
if ($age_dir != 'ASC') {$age_dir = 'DESC';}
$rows=self::_runSQL(''
@@ -1947,13 +1919,13 @@ class stats {
.' married.d_julianday2-birth.d_julianday1 AS age,'
.' indi.i_id AS i_id'
.' FROM'
- ." {$TBLPREFIX}families AS fam"
+ ." ##families AS fam"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS birth ON birth.d_file = {$this->_ged_id}"
+ ." ##dates AS birth ON birth.d_file = {$this->_ged_id}"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS married ON married.d_file = {$this->_ged_id}"
+ ." ##dates AS married ON married.d_file = {$this->_ged_id}"
.' LEFT JOIN'
- ." {$TBLPREFIX}individuals AS indi ON indi.i_file = {$this->_ged_id}"
+ ." ##individuals AS indi ON indi.i_file = {$this->_ged_id}"
.' WHERE'
.' birth.d_gid = indi.i_id AND'
.' married.d_gid = fam.f_id AND'
@@ -1974,15 +1946,15 @@ class stats {
.' married.d_julianday2-birth.d_julianday1 AS age,'
.' indi.i_id AS i_id'
.' FROM'
- ." {$TBLPREFIX}families AS fam"
+ ." ##families AS fam"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS birth ON birth.d_file = {$this->_ged_id} AND birth.d_fact = 'BIRT'"
+ ." ##dates AS birth ON birth.d_file = {$this->_ged_id} AND birth.d_fact = 'BIRT'"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS birth_act ON birth_act.d_file = {$this->_ged_id} AND birth_act.d_fact IN ('BIRT', 'CHR', 'BAPM', '_BRTM')"
+ ." ##dates AS birth_act ON birth_act.d_file = {$this->_ged_id} AND birth_act.d_fact IN ('BIRT', 'CHR', 'BAPM', '_BRTM')"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS married ON married.d_file = {$this->_ged_id} AND married.d_fact = 'MARR'"
+ ." ##dates AS married ON married.d_file = {$this->_ged_id} AND married.d_fact = 'MARR'"
.' LEFT JOIN'
- ." {$TBLPREFIX}individuals AS indi ON indi.i_file = {$this->_ged_id}"
+ ." ##individuals AS indi ON indi.i_file = {$this->_ged_id}"
.' WHERE'
.' birth.d_gid = indi.i_id AND'
.' birth_act.d_gid = indi.i_id AND'
@@ -2033,7 +2005,7 @@ class stats {
}
function _ageOfMarriageQuery($type='list', $age_dir='ASC', $params=null) {
- global $TBLPREFIX, $TEXT_DIRECTION;
+ global $TEXT_DIRECTION;
if ($params !== null && isset($params[0])) {$total = $params[0];}else{$total = 10;}
if ($age_dir != 'ASC') {$age_dir = 'DESC';}
$hrows=self::_runSQL(''
@@ -2041,11 +2013,11 @@ class stats {
.' fam.f_id AS family,'
.' MIN(husbdeath.d_julianday2-married.d_julianday1) AS age'
.' FROM'
- ." {$TBLPREFIX}families AS fam"
+ ." ##families AS fam"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS married ON married.d_file = {$this->_ged_id}"
+ ." ##dates AS married ON married.d_file = {$this->_ged_id}"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS husbdeath ON husbdeath.d_file = {$this->_ged_id}"
+ ." ##dates AS husbdeath ON husbdeath.d_file = {$this->_ged_id}"
.' WHERE'
." fam.f_file = {$this->_ged_id} AND"
.' husbdeath.d_gid = fam.f_husb AND'
@@ -2063,11 +2035,11 @@ class stats {
.' fam.f_id AS family,'
.' MIN(wifedeath.d_julianday2-married.d_julianday1) AS age'
.' FROM'
- ." {$TBLPREFIX}families AS fam"
+ ." ##families AS fam"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS married ON married.d_file = {$this->_ged_id}"
+ ." ##dates AS married ON married.d_file = {$this->_ged_id}"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS wifedeath ON wifedeath.d_file = {$this->_ged_id}"
+ ." ##dates AS wifedeath ON wifedeath.d_file = {$this->_ged_id}"
.' WHERE'
." fam.f_file = {$this->_ged_id} AND"
.' wifedeath.d_gid = fam.f_wife AND'
@@ -2085,11 +2057,11 @@ class stats {
.' fam.f_id AS family,'
.' MIN(divorced.d_julianday2-married.d_julianday1) AS age'
.' FROM'
- ." {$TBLPREFIX}families AS fam"
+ ." ##families AS fam"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS married ON married.d_file = {$this->_ged_id}"
+ ." ##dates AS married ON married.d_file = {$this->_ged_id}"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS divorced ON divorced.d_file = {$this->_ged_id}"
+ ." ##dates AS divorced ON divorced.d_file = {$this->_ged_id}"
.' WHERE'
." fam.f_file = {$this->_ged_id} AND"
.' married.d_gid = fam.f_id AND'
@@ -2165,7 +2137,7 @@ class stats {
}
function _ageBetweenSpousesQuery($type='list', $age_dir='DESC', $params=null) {
- global $TBLPREFIX, $TEXT_DIRECTION;
+ global $TEXT_DIRECTION;
if ($params !== null && isset($params[0])) {$total = $params[0];}else{$total = 10;}
if ($age_dir=='DESC') {
$query1 = ' MIN(wifebirth.d_julianday2-husbbirth.d_julianday1) AS age';
@@ -2181,11 +2153,11 @@ class stats {
.' fam.f_id AS family,'
.$query1
.' FROM'
- ." {$TBLPREFIX}families AS fam"
+ ." ##families AS fam"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS wifebirth ON wifebirth.d_file = {$this->_ged_id}"
+ ." ##dates AS wifebirth ON wifebirth.d_file = {$this->_ged_id}"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS husbbirth ON husbbirth.d_file = {$this->_ged_id}"
+ ." ##dates AS husbbirth ON husbbirth.d_file = {$this->_ged_id}"
.' WHERE'
." fam.f_file = {$this->_ged_id} AND"
.' husbbirth.d_gid = fam.f_husb AND'
@@ -2235,7 +2207,6 @@ class stats {
}
function _parentsQuery($type='full', $age_dir='ASC', $sex='F', $show_years=false) {
- global $TBLPREFIX;
if ($sex == 'F') {$sex_field = 'WIFE';}else{$sex_field = 'HUSB';}
if ($age_dir != 'ASC') {$age_dir = 'DESC';}
$rows=self::_runSQL(''
@@ -2243,13 +2214,13 @@ class stats {
.' parentfamily.l_to AS id,'
.' childbirth.d_julianday2-birth.d_julianday1 AS age'
.' FROM'
- ." {$TBLPREFIX}link AS parentfamily"
+ ." ##link AS parentfamily"
.' JOIN'
- ." {$TBLPREFIX}link AS childfamily ON childfamily.l_file = {$this->_ged_id}"
+ ." ##link AS childfamily ON childfamily.l_file = {$this->_ged_id}"
.' JOIN'
- ." {$TBLPREFIX}dates AS birth ON birth.d_file = {$this->_ged_id}"
+ ." ##dates AS birth ON birth.d_file = {$this->_ged_id}"
.' JOIN'
- ." {$TBLPREFIX}dates AS childbirth ON childbirth.d_file = {$this->_ged_id}"
+ ." ##dates AS childbirth ON childbirth.d_file = {$this->_ged_id}"
.' WHERE'
.' birth.d_gid = parentfamily.l_to AND'
.' childfamily.l_to = childbirth.d_gid AND'
@@ -2299,10 +2270,10 @@ class stats {
}
function statsMarr($simple=true, $first=false, $year1=-1, $year2=-1, $params=null) {
- global $TBLPREFIX, $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_S_CHART_X, $WT_STATS_S_CHART_Y;
+ global $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_S_CHART_X, $WT_STATS_S_CHART_Y;
if ($simple) {
- $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM {$TBLPREFIX}dates "
+ $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM ##dates "
."WHERE "
."d_file={$this->_ged_id} AND "
.'d_year<>0 AND '
@@ -2325,11 +2296,11 @@ class stats {
.' married.d_month AS month,'
.' indi.i_id AS indi'
.' FROM'
- ." {$TBLPREFIX}families AS fam"
+ ." ##families AS fam"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS married ON married.d_file = {$this->_ged_id}"
+ ." ##dates AS married ON married.d_file = {$this->_ged_id}"
.' LEFT JOIN'
- ." {$TBLPREFIX}individuals AS indi ON indi.i_file = {$this->_ged_id}"
+ ." ##individuals AS indi ON indi.i_file = {$this->_ged_id}"
.' WHERE'
.' married.d_gid = fam.f_id AND'
." fam.f_file = {$this->_ged_id} AND"
@@ -2339,7 +2310,7 @@ class stats {
.' (indi.i_id = fam.f_husb OR indi.i_id = fam.f_wife)'
.' ORDER BY fams, indi, age ASC';
} else {
- $sql = "SELECT d_month, COUNT(*) AS total FROM {$TBLPREFIX}dates "
+ $sql = "SELECT d_month, COUNT(*) AS total FROM ##dates "
."WHERE "
."d_file={$this->_ged_id} AND "
."d_fact='MARR'";
@@ -2375,10 +2346,10 @@ class stats {
}
function statsDiv($simple=true, $first=false, $year1=-1, $year2=-1, $params=null) {
- global $TBLPREFIX, $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_S_CHART_X, $WT_STATS_S_CHART_Y;
+ global $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_S_CHART_X, $WT_STATS_S_CHART_Y;
if ($simple) {
- $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM {$TBLPREFIX}dates "
+ $sql = "SELECT ROUND((d_year+49.1)/100) AS century, COUNT(*) AS total FROM ##dates "
."WHERE "
."d_file={$this->_ged_id} AND "
.'d_year<>0 AND '
@@ -2401,11 +2372,11 @@ class stats {
.' divorced.d_month AS month,'
.' indi.i_id AS indi'
.' FROM'
- ." {$TBLPREFIX}families AS fam"
+ ." ##families AS fam"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS divorced ON divorced.d_file = {$this->_ged_id}"
+ ." ##dates AS divorced ON divorced.d_file = {$this->_ged_id}"
.' LEFT JOIN'
- ." {$TBLPREFIX}individuals AS indi ON indi.i_file = {$this->_ged_id}"
+ ." ##individuals AS indi ON indi.i_file = {$this->_ged_id}"
.' WHERE'
.' divorced.d_gid = fam.f_id AND'
." fam.f_file = {$this->_ged_id} AND"
@@ -2415,7 +2386,7 @@ class stats {
.' (indi.i_id = fam.f_husb OR indi.i_id = fam.f_wife)'
.' ORDER BY fams, indi, age ASC';
} else {
- $sql = "SELECT d_month, COUNT(*) AS total FROM {$TBLPREFIX}dates "
+ $sql = "SELECT d_month, COUNT(*) AS total FROM ##dates "
."WHERE "
."d_file={$this->_ged_id} AND "
."d_fact IN ('DIV', 'ANUL', '_SEPR')";
@@ -2477,8 +2448,6 @@ class stats {
function lastDivorcePlace() {return $this->_mortalityQuery('place', 'DESC', 'DIV');}
function statsMarrAge($simple=true, $sex='M', $year1=-1, $year2=-1, $params=null) {
- global $TBLPREFIX;
-
if ($simple) {
if (isset($params[0]) && $params[0] != '') {$size = strtolower($params[0]);}else{$size = '200x250';}
$sizes = explode('x', $size);
@@ -2488,13 +2457,13 @@ class stats {
.' ROUND((married.d_year+49.1)/100) AS century,'
.' indi.i_sex AS sex'
.' FROM'
- ." {$TBLPREFIX}families AS fam"
+ ." ##families AS fam"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS birth ON birth.d_file = {$this->_ged_id}"
+ ." ##dates AS birth ON birth.d_file = {$this->_ged_id}"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS married ON married.d_file = {$this->_ged_id}"
+ ." ##dates AS married ON married.d_file = {$this->_ged_id}"
.' LEFT JOIN'
- ." {$TBLPREFIX}individuals AS indi ON indi.i_file = {$this->_ged_id}"
+ ." ##individuals AS indi ON indi.i_file = {$this->_ged_id}"
.' WHERE'
.' birth.d_gid = indi.i_id AND'
.' married.d_gid = fam.f_id AND'
@@ -2593,13 +2562,13 @@ class stats {
.' married.d_julianday2-birth.d_julianday1 AS age,'
.' indi.i_id AS indi'
.' FROM'
- ." {$TBLPREFIX}families AS fam"
+ ." ##families AS fam"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS birth ON birth.d_file = {$this->_ged_id}"
+ ." ##dates AS birth ON birth.d_file = {$this->_ged_id}"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS married ON married.d_file = {$this->_ged_id}"
+ ." ##dates AS married ON married.d_file = {$this->_ged_id}"
.' LEFT JOIN'
- ." {$TBLPREFIX}individuals AS indi ON indi.i_file = {$this->_ged_id}"
+ ." ##individuals AS indi ON indi.i_file = {$this->_ged_id}"
.' WHERE'
.' birth.d_gid = indi.i_id AND'
.' married.d_gid = fam.f_id AND'
@@ -2678,9 +2647,7 @@ class stats {
function oldestFatherAge($show_years=false) {return $this->_parentsQuery('age', 'DESC', 'M', $show_years);}
function totalMarriedMales() {
- global $TBLPREFIX;
-
- $rows = WT_DB::prepare("SELECT f_gedcom AS ged, f_husb AS husb FROM {$TBLPREFIX}families WHERE f_file=?")
+ $rows = WT_DB::prepare("SELECT f_gedcom AS ged, f_husb AS husb FROM ##families WHERE f_file=?")
->execute(array($this->_ged_id))
->fetchAll();
$husb = array();
@@ -2694,9 +2661,7 @@ class stats {
}
function totalMarriedFemales() {
- global $TBLPREFIX;
-
- $rows = WT_DB::prepare("SELECT f_gedcom AS ged, f_wife AS wife FROM {$TBLPREFIX}families WHERE f_file=?")
+ $rows = WT_DB::prepare("SELECT f_gedcom AS ged, f_wife AS wife FROM ##families WHERE f_file=?")
->execute(array($this->_ged_id))
->fetchAll();
$wife = array();
@@ -2714,13 +2679,12 @@ class stats {
///////////////////////////////////////////////////////////////////////////////
function _familyQuery($type='full') {
- global $TBLPREFIX;
$rows=self::_runSQL(''
.' SELECT'
.' f_numchil AS tot,'
.' f_id AS id'
.' FROM'
- ." {$TBLPREFIX}families"
+ ." ##families"
.' WHERE'
." f_file={$this->_ged_id}"
.' ORDER BY'
@@ -2750,14 +2714,14 @@ class stats {
}
function _topTenFamilyQuery($type='list', $params=null) {
- global $TBLPREFIX, $TEXT_DIRECTION;
+ global $TEXT_DIRECTION;
if ($params !== null && isset($params[0])) {$total = $params[0];}else{$total = 10;}
$rows=self::_runSQL(''
.' SELECT'
.' f_numchil AS tot,'
.' f_id AS id'
.' FROM'
- ." {$TBLPREFIX}families"
+ ." ##families"
.' WHERE'
." f_file={$this->_ged_id}"
.' ORDER BY'
@@ -2791,7 +2755,7 @@ class stats {
}
function _ageBetweenSiblingsQuery($type='list', $params=null) {
- global $TBLPREFIX, $TEXT_DIRECTION;
+ global $TEXT_DIRECTION;
if ($params === null) {$params = array();}
if (isset($params[0])) {$total = $params[0];}else{$total = 10;}
if (isset($params[1])) {$one = $params[1];}else{$one = false;} // each family only once if true
@@ -2802,13 +2766,13 @@ class stats {
.' link2.l_to AS ch2,'
.' child1.d_julianday2-child2.d_julianday2 AS age'
.' FROM'
- ." {$TBLPREFIX}link AS link1"
+ ." ##link AS link1"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS child1 ON child1.d_file = {$this->_ged_id}"
+ ." ##dates AS child1 ON child1.d_file = {$this->_ged_id}"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS child2 ON child2.d_file = {$this->_ged_id}"
+ ." ##dates AS child2 ON child2.d_file = {$this->_ged_id}"
.' LEFT JOIN'
- ." {$TBLPREFIX}link AS link2 ON link2.l_file = {$this->_ged_id}"
+ ." ##link AS link2 ON link2.l_file = {$this->_ged_id}"
.' WHERE'
." link1.l_file = {$this->_ged_id} AND"
.' link1.l_from = link2.l_from AND'
@@ -2908,7 +2872,7 @@ class stats {
function topTenLargestFamilyList($params=null) {return $this->_topTenFamilyQuery('list', $params);}
function chartLargestFamilies($params=null) {
- global $TBLPREFIX, $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_L_CHART_X, $WT_STATS_S_CHART_Y;
+ global $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_L_CHART_X, $WT_STATS_S_CHART_Y;
if ($params === null) {$params = array();}
if (isset($params[0]) && $params[0] != '') {$size = strtolower($params[0]);}else{$size = $WT_STATS_L_CHART_X."x".$WT_STATS_S_CHART_Y;}
if (isset($params[1]) && $params[1] != '') {$color_from = strtolower($params[1]);}else{$color_from = $WT_STATS_CHART_COLOR1;}
@@ -2920,7 +2884,7 @@ class stats {
.' f_numchil AS tot,'
.' f_id AS id'
.' FROM'
- ." {$TBLPREFIX}families"
+ ." ##families"
.' WHERE'
." f_file={$this->_ged_id}"
.' ORDER BY'
@@ -2950,23 +2914,19 @@ class stats {
}
function totalChildren() {
- global $TBLPREFIX;
- $rows=self::_runSQL("SELECT SUM(f_numchil) AS tot FROM {$TBLPREFIX}families WHERE f_file={$this->_ged_id}");
+ $rows=self::_runSQL("SELECT SUM(f_numchil) AS tot FROM ##families WHERE f_file={$this->_ged_id}");
$row=$rows[0];
return $row['tot'];
}
function averageChildren() {
- global $TBLPREFIX;
- $rows=self::_runSQL("SELECT AVG(f_numchil) AS tot FROM {$TBLPREFIX}families WHERE f_file={$this->_ged_id}");
+ $rows=self::_runSQL("SELECT AVG(f_numchil) AS tot FROM ##families WHERE f_file={$this->_ged_id}");
$row=$rows[0];
return sprintf('%.2f', $row['tot']);
}
function statsChildren($simple=true, $sex='BOTH', $year1=-1, $year2=-1, $params=null) {
- global $TBLPREFIX;
-
if ($simple) {
if (isset($params[0]) && $params[0] != '') {$size = strtolower($params[0]);}else{$size = '220x200';}
$sizes = explode('x', $size);
@@ -2976,9 +2936,9 @@ class stats {
.' ROUND(AVG(f_numchil),2) AS num,'
.' ROUND((married.d_year+49.1)/100) AS century'
.' FROM'
- ." {$TBLPREFIX}families AS fam"
+ ." ##families AS fam"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS married ON married.d_file = {$this->_ged_id}"
+ ." ##dates AS married ON married.d_file = {$this->_ged_id}"
.' WHERE'
.' married.d_gid = fam.f_id AND'
." fam.f_file = {$this->_ged_id} AND"
@@ -3009,26 +2969,26 @@ class stats {
} else {
if ($sex=='M') {
$sql = "SELECT num, COUNT(*) AS total FROM "
- ."(SELECT count(i_sex) AS num FROM {$TBLPREFIX}link "
- ."LEFT OUTER JOIN {$TBLPREFIX}individuals "
+ ."(SELECT count(i_sex) AS num FROM ##link "
+ ."LEFT OUTER JOIN ##individuals "
."ON l_from=i_id AND l_file=i_file AND i_sex='M' AND l_type='FAMC' "
- ."JOIN {$TBLPREFIX}families ON f_file=l_file AND f_id=l_to WHERE f_file={$this->_ged_id} GROUP BY l_to"
+ ."JOIN ##families ON f_file=l_file AND f_id=l_to WHERE f_file={$this->_ged_id} GROUP BY l_to"
.") boys"
." GROUP BY num ORDER BY num ASC";
}
else if ($sex=='F') {
$sql = "SELECT num, COUNT(*) AS total FROM "
- ."(SELECT count(i_sex) AS num FROM {$TBLPREFIX}link "
- ."LEFT OUTER JOIN {$TBLPREFIX}individuals "
+ ."(SELECT count(i_sex) AS num FROM ##link "
+ ."LEFT OUTER JOIN ##individuals "
."ON l_from=i_id AND l_file=i_file AND i_sex='F' AND l_type='FAMC' "
- ."JOIN {$TBLPREFIX}families ON f_file=l_file AND f_id=l_to WHERE f_file={$this->_ged_id} GROUP BY l_to"
+ ."JOIN ##families ON f_file=l_file AND f_id=l_to WHERE f_file={$this->_ged_id} GROUP BY l_to"
.") girls"
." GROUP BY num ORDER BY num ASC";
}
else {
- $sql = "SELECT f_numchil, COUNT(*) AS total FROM {$TBLPREFIX}families ";
+ $sql = "SELECT f_numchil, COUNT(*) AS total FROM ##families ";
if ($year1>=0 && $year2>=0) {
- $sql .= "AS fam LEFT JOIN {$TBLPREFIX}dates AS married ON married.d_file = {$this->_ged_id}"
+ $sql .= "AS fam LEFT JOIN ##dates AS married ON married.d_file = {$this->_ged_id}"
.' WHERE'
.' married.d_gid = fam.f_id AND'
." fam.f_file = {$this->_ged_id} AND"
@@ -3053,12 +3013,11 @@ class stats {
function topAgeBetweenSiblingsList($params=null) {return $this->_ageBetweenSiblingsQuery($type='list', $params=null);}
function noChildrenFamilies() {
- global $TBLPREFIX;
$rows=self::_runSQL(''
.' SELECT'
.' COUNT(*) AS tot'
.' FROM'
- ." {$TBLPREFIX}families AS fam"
+ ." ##families AS fam"
.' WHERE'
.' f_numchil = 0 AND'
." fam.f_file = {$this->_ged_id}");
@@ -3068,12 +3027,12 @@ class stats {
function noChildrenFamiliesList($type='list') {
- global $TBLPREFIX, $TEXT_DIRECTION;
+ global $TEXT_DIRECTION;
$rows=self::_runSQL(''
.' SELECT'
.' f_id AS family'
.' FROM'
- ." {$TBLPREFIX}families AS fam"
+ ." ##families AS fam"
.' WHERE'
.' f_numchil = 0 AND'
." fam.f_file = {$this->_ged_id}");
@@ -3104,8 +3063,6 @@ class stats {
}
function chartNoChildrenFamilies($year1=-1, $year2=-1, $params=null) {
- global $TBLPREFIX;
-
if (isset($params[0]) && $params[0] != '') {$size = strtolower($params[0]);}else{$size = '220x200';}
$sizes = explode('x', $size);
if ($year1>=0 && $year2>=0) {
@@ -3120,9 +3077,9 @@ class stats {
.' COUNT(*) AS count,'
.' ROUND((married.d_year+49.1)/100) AS century'
.' FROM'
- ." {$TBLPREFIX}families AS fam"
+ ." ##families AS fam"
.' LEFT JOIN'
- ." {$TBLPREFIX}dates AS married ON married.d_file = {$this->_ged_id}"
+ ." ##dates AS married ON married.d_file = {$this->_ged_id}"
.' WHERE'
.' f_numchil = 0 AND'
.' married.d_gid = fam.f_id AND'
@@ -3173,20 +3130,20 @@ class stats {
}
function _topTenGrandFamilyQuery($type='list', $params=null) {
- global $TBLPREFIX, $TEXT_DIRECTION;
+ global $TEXT_DIRECTION;
if ($params !== null && isset($params[0])) {$total = $params[0];}else{$total = 10;}
$rows=self::_runSQL(''
.' SELECT'
.' COUNT(*) AS tot,'
.' f_id AS id'
.' FROM'
- ." {$TBLPREFIX}families"
+ ." ##families"
.' JOIN'
- ." {$TBLPREFIX}link AS children ON children.l_file = {$this->_ged_id}"
+ ." ##link AS children ON children.l_file = {$this->_ged_id}"
.' JOIN'
- ." {$TBLPREFIX}link AS mchildren ON mchildren.l_file = {$this->_ged_id}"
+ ." ##link AS mchildren ON mchildren.l_file = {$this->_ged_id}"
.' JOIN'
- ." {$TBLPREFIX}link AS gchildren ON gchildren.l_file = {$this->_ged_id}"
+ ." ##link AS gchildren ON gchildren.l_file = {$this->_ged_id}"
.' WHERE'
." f_file={$this->_ged_id} AND"
." children.l_from=f_id AND"
@@ -3344,7 +3301,7 @@ class stats {
* Original block created by kiwi_pgv
*/
static function _commonGivenQuery($sex='B', $type='list', $show_tot=false, $params=null) {
- global $TEXT_DIRECTION, $GEDCOM, $TBLPREFIX;
+ global $TEXT_DIRECTION, $GEDCOM;
static $sort_types = array('count'=>'asort', 'rcount'=>'arsort', 'alpha'=>'ksort', 'ralpha'=>'krsort');
static $sort_flags = array('count'=>SORT_NUMERIC, 'rcount'=>SORT_NUMERIC, 'alpha'=>SORT_STRING, 'ralpha'=>SORT_STRING);
@@ -3368,7 +3325,7 @@ class stats {
}
$ged_id=get_id_from_gedcom($GEDCOM);
- $rows=WT_DB::prepare("SELECT n_givn, COUNT(*) AS num FROM {$TBLPREFIX}name JOIN {$TBLPREFIX}individuals ON (n_id=i_id AND n_file=i_file) WHERE n_file={$ged_id} AND n_type<>'_MARNM' AND n_givn NOT IN ('@P.N.', '') AND LENGTH(n_givn)>1 AND {$sex_sql} GROUP BY n_id, n_givn")
+ $rows=WT_DB::prepare("SELECT n_givn, COUNT(*) AS num FROM ##name JOIN ##individuals ON (n_id=i_id AND n_file=i_file) WHERE n_file={$ged_id} AND n_type<>'_MARNM' AND n_givn NOT IN ('@P.N.', '') AND LENGTH(n_givn)>1 AND {$sex_sql} GROUP BY n_id, n_givn")
->fetchAll();
$nameList=array();
foreach ($rows as $row) {
diff --git a/includes/classes/class_wt_db.php b/includes/classes/class_wt_db.php
index d0b0878029..d113ea70d3 100644
--- a/includes/classes/class_wt_db.php
+++ b/includes/classes/class_wt_db.php
@@ -45,32 +45,6 @@ class WT_DB {
private static $instance=null;
private static $pdo=null;
- // Dialects of SQL
- public static $AUTO_ID_TYPE =null; /* for primary keys */
- public static $ID_TYPE =null; /* for foreign keys */
- public static $INT1_TYPE =null;
- public static $INT2_TYPE =null;
- public static $INT3_TYPE =null;
- public static $INT4_TYPE =null;
- public static $INT8_TYPE =null;
- public static $CHAR_TYPE =null;
- public static $VARCHAR_TYPE =null;
- public static $UNSIGNED =null;
- public static $RANDOM =null;
- public static $TEXT_TYPE =null;
- public static $LONGTEXT_TYPE=null;
- public static $UTF8_TABLE =null;
-
- // Standard column types for gedcom data
- public static $COL_FILE=null;
- public static $COL_XREF=null;
- public static $COL_TAG =null;
- public static $COL_JD =null;
- public static $COL_DAY =null;
- public static $COL_MON =null;
- public static $COL_YEAR=null;
- public static $COL_CAL =null;
-
// Prevent instantiation via new WT_DB
private final function __construct() {
}
@@ -235,17 +209,6 @@ class WT_DB {
// FUNCTIONALITY ENHANCEMENTS
//////////////////////////////////////////////////////////////////////////////
- // Deprecated function. We only support MySQL
- public static function getAvailableDrivers() {
- $array=PDO::getAvailableDrivers();
- foreach ($array as $key=>$value) {
- if ($value!='mysql') {
- unset($array[$key]);
- }
- }
- return $array;
- }
-
// The native quote() function does not convert PHP nulls to DB nulls
public static function quote($string, $parameter_type=PDO::PARAM_STR) {
if (is_null($string)) {
@@ -256,16 +219,18 @@ class WT_DB {
}
// Add logging to query()
- public static function query($string, $parameter_type= PDO::PARAM_STR) {
+ public static function query($statement, $parameter_type= PDO::PARAM_STR) {
+ $statement=str_replace('##', WT_TBLPREFIX, $statement);
$start=microtime(true);
- $result=self::$pdo->query($string, $parameter_type);
+ $result=self::$pdo->query($statement, $parameter_type);
$end=microtime(true);
- self::logQuery($string, count($result), $end-$start, array());
+ self::logQuery($statement, count($result), $end-$start, array());
return $result;
}
// Add logging to exec()
public static function exec($statement) {
+ $statement=str_replace('##', WT_TBLPREFIX, $statement);
$start=microtime(true);
$result=self::$pdo->exec($statement);
$end=microtime(true);
@@ -278,6 +243,7 @@ class WT_DB {
if (!self::$pdo instanceof PDO) {
throw new PDOException("No Connection Established");
}
+ $statement=str_replace('##', WT_TBLPREFIX, $statement);
return new WT_DBStatement(self::$pdo->prepare($statement));
}
@@ -286,6 +252,7 @@ class WT_DB {
if (!self::$pdo instanceof PDO) {
throw new PDOException("No Connection Established");
}
+ $statement=str_replace('##', WT_TBLPREFIX, $statement);
if ($n) {
switch (self::$pdo->getAttribute(PDO::ATTR_DRIVER_NAME)) {
case 'mysql':
@@ -305,26 +272,6 @@ class WT_DB {
// Create/update tables, indexes, etc.
//////////////////////////////////////////////////////////////////////////////
public static function updateSchema($schema_dir, $schema_name, $target_version) {
- global $TBLPREFIX;
-
- // Allow the schema scripts to do different things for different databases
- $DRIVER_NAME=self::getInstance()->getAttribute(PDO::ATTR_DRIVER_NAME);
-
- // Define some "standard" columns, so we create our tables consistently
- self::$COL_FILE=self::$INT2_TYPE.' '.self::$UNSIGNED; // Allow 32768/65536 Gedcoms
- self::$COL_XREF=self::$VARCHAR_TYPE.'(20)'; // Gedcom identifiers are max 20 chars
- self::$COL_TAG =self::$VARCHAR_TYPE.'(15)'; // Gedcom tags/record types are max 15 chars
- self::$COL_JD =self::$INT3_TYPE.' '.self::$UNSIGNED; // Julian Day numbers only need 3 bytes
- self::$COL_DAY =self::$INT1_TYPE.' '.self::$UNSIGNED; // Day numbers only need 1 byte
- self::$COL_MON =self::$INT1_TYPE.' '.self::$UNSIGNED; // Month Day numbers only need 1 byte
- self::$COL_YEAR=self::$INT2_TYPE; // Year Day numbers only need 2 bytes
-
- if ($DRIVER_NAME=='mysql') {
- self::$COL_CAL="ENUM ('@#DGREGORIAN@', '@#DJULIAN@', '@#DHEBREW@', '@#DFRENCH R@', '@#DHIJRI@', '@#DROMAN@')"; // Fixed list of calendar names
- } else {
- self::$COL_CAL=self::$VARCHAR_TYPE.'(13)'; // Calendar names have max 13 characters
- }
-
try {
$current_version=(int)get_site_setting($schema_name);
} catch (PDOException $e) {
diff --git a/includes/controllers/advancedsearch_ctrl.php b/includes/controllers/advancedsearch_ctrl.php
index 2a7d819966..3833bc261d 100644
--- a/includes/controllers/advancedsearch_ctrl.php
+++ b/includes/controllers/advancedsearch_ctrl.php
@@ -173,7 +173,7 @@ class AdvancedSearchController extends SearchController {
}
function advancedSearch($justSql=false, $table="individuals", $prefix="i") {
- global $TBLPREFIX, $gedcom_record_cache;
+ global $gedcom_record_cache;
DMsoundex("", "opencache");
$this->myindilist = array ();
@@ -189,7 +189,7 @@ class AdvancedSearchController extends SearchController {
$sql = '';
if ($justSql) $sqlfields = "SELECT DISTINCT {$prefix}_id, {$prefix}_file";
else $sqlfields = "SELECT i_id, i_gedcom, i_isdead, i_file, i_sex";
- $sqltables = " FROM ".$TBLPREFIX.$table;
+ $sqltables = " FROM ##".$table;
$sqlwhere = " WHERE ".$prefix."_file=".WT_GED_ID;
$keepfields = $this->fields;
for($i=0; $i<$fct; $i++) {
@@ -203,7 +203,7 @@ class AdvancedSearchController extends SearchController {
if ($parts[0]=="NAME") {
// The pgv_name table contains both names and soundex values
if (!$namesTable) {
- $sqltables.=" JOIN {$TBLPREFIX}name ON (i_file=n_file AND i_id=n_id) ";
+ $sqltables.=" JOIN ##name ON (i_file=n_file AND i_id=n_id) ";
$namesTable = true;
}
switch (end($parts)) {
@@ -281,7 +281,7 @@ class AdvancedSearchController extends SearchController {
//-- handle dates
else if (isset($parts[1]) && $parts[1]=="DATE") {
if (!$datesTable) {
- $sqltables.=", ".$TBLPREFIX."dates";
+ $sqltables.=", ##dates";
$sqlwhere .= " AND ".$prefix."_file=d_file AND ".$prefix."_id=d_gid";
$datesTable = true;
}
@@ -304,7 +304,7 @@ class AdvancedSearchController extends SearchController {
//-- handle places
else if (isset($parts[1]) && $parts[1]=="PLAC") {
if (!$placesTable) {
- $sqltables.=", ".$TBLPREFIX."places, ".$TBLPREFIX."placelinks";
+ $sqltables.=", ##places, ##placelinks";
$sqlwhere .= " AND ".$prefix."_file=p_file AND p_file=pl_file AND ".$prefix."_id=pl_gid AND pl_p_id=p_id";
$placesTable = true;
}
@@ -332,7 +332,7 @@ class AdvancedSearchController extends SearchController {
//-- handle parent/spouse names
else if ($parts[0]=='FAMS') {
if (!$famsTable) {
- $sqltables.=", ".$TBLPREFIX."families as FAMS";
+ $sqltables.=", ##families as FAMS";
$sqlwhere .= " AND i_file=FAMS.f_file";
$famsTable = true;
}
@@ -359,7 +359,7 @@ class AdvancedSearchController extends SearchController {
}
else if ($parts[0]=='FAMC') {
if (!$famcTable) {
- $sqltables.=", ".$TBLPREFIX."families as FAMC";
+ $sqltables.=", ##families as FAMC";
$sqlwhere .= " AND i_file=FAMC.f_file";
$famcTable = true;
}
@@ -386,7 +386,7 @@ class AdvancedSearchController extends SearchController {
}
else if ($parts[0]=='HUSB' || $parts[0]=='WIFE') {
if (!$famsTable) {
- $sqltables.=", ".$TBLPREFIX."individuals";
+ $sqltables.=", ##individuals";
$sqlwhere .= " AND i_file=f_file";
$famsTable = true;
}
diff --git a/includes/controllers/remotelink_ctrl.php b/includes/controllers/remotelink_ctrl.php
index 6bfb1d0c69..081e25c127 100644
--- a/includes/controllers/remotelink_ctrl.php
+++ b/includes/controllers/remotelink_ctrl.php
@@ -221,8 +221,6 @@ class RemoteLinkController extends BaseController {
// @param string $gedcom_id
// @return mixed the id of the server to link to or false if it does not exist
function checkExistingServer($url, $gedcom_id='') {
- global $TBLPREFIX;
-
//-- get rid of the protocol
$turl = preg_replace('~^\w+://~', '', $url);
//-- check the existing server list
@@ -236,7 +234,7 @@ class RemoteLinkController extends BaseController {
//-- check for recent additions
return WT_DB::prepare(
"SELECT xref".
- " FROM {$TBLPREFIX}change".
+ " FROM ##change".
" WHERE status='pending' AND gedcom_id=? AND new_gedcom LIKE CONCAT('%\n1 _DBID ', ?, '%')".
" ORDER BY change_id DESC".
" LIMIT 1"
diff --git a/includes/functions/functions.php b/includes/functions/functions.php
index 708a65bfb6..900e3e876b 100644
--- a/includes/functions/functions.php
+++ b/includes/functions/functions.php
@@ -1011,7 +1011,7 @@ function find_visible_families_in_record($indirec, $tag) {
* @return array an object array with indexes "thumb" and "file" for thumbnail and filename
*/
function find_highlighted_object($pid, $ged_id, $indirec) {
- global $MEDIA_DIRECTORY, $MEDIA_DIRECTORY_LEVELS, $WT_IMAGE_DIR, $WT_IMAGES, $MEDIA_EXTERNAL, $TBLPREFIX;
+ global $MEDIA_DIRECTORY, $MEDIA_DIRECTORY_LEVELS, $WT_IMAGE_DIR, $WT_IMAGES, $MEDIA_EXTERNAL;
if (!showFactDetails("OBJE", $pid)) {
return false;
@@ -1043,7 +1043,7 @@ function find_highlighted_object($pid, $ged_id, $indirec) {
//-- find all of the media items for a person
$media=
- WT_DB::prepare("SELECT m_media, m_file, m_gedrec, mm_gedrec FROM {$TBLPREFIX}media, {$TBLPREFIX}media_mapping WHERE m_media=mm_media AND m_gedfile=mm_gedfile AND m_gedfile=? AND mm_gid=? ORDER BY mm_order")
+ WT_DB::prepare("SELECT m_media, m_file, m_gedrec, mm_gedrec FROM ##media, ##media_mapping WHERE m_media=mm_media AND m_gedfile=mm_gedfile AND m_gedfile=? AND mm_gid=? ORDER BY mm_order")
->execute(array($ged_id, $pid))
->fetchAll(PDO::FETCH_NUM);
@@ -2840,7 +2840,7 @@ function add_descendancy(&$list, $pid, $parents=false, $generations=-1) {
* @return string
*/
function get_new_xref($type='INDI', $ged_id=WT_GED_ID, $use_cache=false) {
- global $TBLPREFIX, $SOURCE_ID_PREFIX, $REPO_ID_PREFIX, $MEDIA_ID_PREFIX, $FAM_ID_PREFIX, $GEDCOM_ID_PREFIX;
+ global $SOURCE_ID_PREFIX, $REPO_ID_PREFIX, $MEDIA_ID_PREFIX, $FAM_ID_PREFIX, $GEDCOM_ID_PREFIX;
switch ($type) {
case "INDI":
@@ -2864,7 +2864,7 @@ function get_new_xref($type='INDI', $ged_id=WT_GED_ID, $use_cache=false) {
}
$num=
- WT_DB::prepare("SELECT next_id FROM {$TBLPREFIX}next_id WHERE record_type=? AND gedcom_id=?")
+ WT_DB::prepare("SELECT next_id FROM ##next_id WHERE record_type=? AND gedcom_id=?")
->execute(array($type, $ged_id))
->fetchOne();
@@ -2874,7 +2874,7 @@ function get_new_xref($type='INDI', $ged_id=WT_GED_ID, $use_cache=false) {
if (is_null($num)) {
$num = 1;
- WT_DB::prepare("INSERT INTO {$TBLPREFIX}next_id (gedcom_id, record_type, next_id) VALUES(?, ?, 1)")
+ WT_DB::prepare("INSERT INTO ##next_id (gedcom_id, record_type, next_id) VALUES(?, ?, 1)")
->execute(array($ged_id, $type));
}
@@ -2893,7 +2893,7 @@ function get_new_xref($type='INDI', $ged_id=WT_GED_ID, $use_cache=false) {
$key = $prefix.$num;
//-- update the next id number in the DB table
- WT_DB::prepare("UPDATE {$TBLPREFIX}next_id SET next_id=? WHERE record_type=? AND gedcom_id=?")
+ WT_DB::prepare("UPDATE ##next_id SET next_id=? WHERE record_type=? AND gedcom_id=?")
->execute(array($num+1, $type, $ged_id));
return $key;
}
diff --git a/includes/functions/functions_db.php b/includes/functions/functions_db.php
index 1f2c0f0ea1..4d21888b5e 100644
--- a/includes/functions/functions_db.php
+++ b/includes/functions/functions_db.php
@@ -41,33 +41,31 @@ define('WT_FUNCTIONS_DB_PHP', '');
//-- gets the first record in the gedcom
function get_first_xref($type, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
switch ($type) {
case "INDI":
return
- WT_DB::prepare("SELECT MIN(i_id) FROM {$TBLPREFIX}individuals WHERE i_file=?")
+ WT_DB::prepare("SELECT MIN(i_id) FROM ##individuals WHERE i_file=?")
->execute(array($ged_id))
->fetchOne();
break;
case "FAM":
return
- WT_DB::prepare("SELECT MIN(f_id) FROM {$TBLPREFIX}families WHERE f_file=?")
+ WT_DB::prepare("SELECT MIN(f_id) FROM ##families WHERE f_file=?")
->execute(array($ged_id))
->fetchOne();
case "SOUR":
return
- WT_DB::prepare("SELECT MIN(s_id) FROM {$TBLPREFIX}sources WHERE s_file=?")
+ WT_DB::prepare("SELECT MIN(s_id) FROM ##sources WHERE s_file=?")
->execute(array($ged_id))
->fetchOne();
case "OBJE":
return
- WT_DB::prepare("SELECT MIN(m_media) FROM {$TBLPREFIX}media WHERE m_gedfile=?")
+ WT_DB::prepare("SELECT MIN(m_media) FROM ##media WHERE m_gedfile=?")
->execute(array($ged_id))
->fetchOne();
default:
return
- WT_DB::prepare("SELECT MIN(o_id) FROM {$TBLPREFIX}other WHERE o_file=? AND o_type=?")
+ WT_DB::prepare("SELECT MIN(o_id) FROM ##other WHERE o_file=? AND o_type=?")
->execute(array($ged_id, $type))
->fetchOne();
}
@@ -75,33 +73,31 @@ function get_first_xref($type, $ged_id=WT_GED_ID) {
//-- gets the last record in the gedcom
function get_last_xref($type, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
switch ($type) {
case "INDI":
return
- WT_DB::prepare("SELECT MAX(i_id) FROM {$TBLPREFIX}individuals WHERE i_file=?")
+ WT_DB::prepare("SELECT MAX(i_id) FROM ##individuals WHERE i_file=?")
->execute(array($ged_id))
->fetchOne();
break;
case "FAM":
return
- WT_DB::prepare("SELECT MAX(f_id) FROM {$TBLPREFIX}families WHERE f_file=?")
+ WT_DB::prepare("SELECT MAX(f_id) FROM ##families WHERE f_file=?")
->execute(array($ged_id))
->fetchOne();
case "SOUR":
return
- WT_DB::prepare("SELECT MAX(s_id) FROM {$TBLPREFIX}sources WHERE s_file=?")
+ WT_DB::prepare("SELECT MAX(s_id) FROM ##sources WHERE s_file=?")
->execute(array($ged_id))
->fetchOne();
case "OBJE":
return
- WT_DB::prepare("SELECT MAX(m_media) FROM {$TBLPREFIX}media WHERE m_gedfile=?")
+ WT_DB::prepare("SELECT MAX(m_media) FROM ##media WHERE m_gedfile=?")
->execute(array($ged_id))
->fetchOne();
default:
return
- WT_DB::prepare("SELECT MAX(o_id) FROM {$TBLPREFIX}other WHERE o_file=? AND o_type=?")
+ WT_DB::prepare("SELECT MAX(o_id) FROM ##other WHERE o_file=? AND o_type=?")
->execute(array($ged_id, $type))
->fetchOne();
}
@@ -109,34 +105,32 @@ function get_last_xref($type, $ged_id=WT_GED_ID) {
//-- gets the next person in the gedcom
function get_next_xref($pid, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
$type=gedcom_record_type($pid, $ged_id);
switch ($type) {
case "INDI":
return
- WT_DB::prepare("SELECT MIN(i_id) FROM {$TBLPREFIX}individuals WHERE i_file=? AND i_id>?")
+ WT_DB::prepare("SELECT MIN(i_id) FROM ##individuals WHERE i_file=? AND i_id>?")
->execute(array($ged_id, $pid))
->fetchOne();
break;
case "FAM":
return
- WT_DB::prepare("SELECT MIN(f_id) FROM {$TBLPREFIX}families WHERE f_file=? AND f_id>?")
+ WT_DB::prepare("SELECT MIN(f_id) FROM ##families WHERE f_file=? AND f_id>?")
->execute(array($ged_id, $pid))
->fetchOne();
case "SOUR":
return
- WT_DB::prepare("SELECT MIN(s_id) FROM {$TBLPREFIX}sources WHERE s_file=? AND s_id>?")
+ WT_DB::prepare("SELECT MIN(s_id) FROM ##sources WHERE s_file=? AND s_id>?")
->execute(array($ged_id, $pid))
->fetchOne();
case "OBJE":
return
- WT_DB::prepare("SELECT MIN(m_media) FROM {$TBLPREFIX}media WHERE m_gedfile=? AND m_media>?")
+ WT_DB::prepare("SELECT MIN(m_media) FROM ##media WHERE m_gedfile=? AND m_media>?")
->execute(array($ged_id, $pid))
->fetchOne();
default:
return
- WT_DB::prepare("SELECT MIN(o_id) FROM {$TBLPREFIX}other WHERE o_file=? AND o_type=? AND o_id>?")
+ WT_DB::prepare("SELECT MIN(o_id) FROM ##other WHERE o_file=? AND o_type=? AND o_id>?")
->execute(array($ged_id, $type, $pid))
->fetchOne();
}
@@ -144,34 +138,32 @@ function get_next_xref($pid, $ged_id=WT_GED_ID) {
//-- gets the previous person in the gedcom
function get_prev_xref($pid, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
$type=gedcom_record_type($pid, $ged_id);
switch ($type) {
case "INDI":
return
- WT_DB::prepare("SELECT MAX(i_id) FROM {$TBLPREFIX}individuals WHERE i_file=? AND i_id<?")
+ WT_DB::prepare("SELECT MAX(i_id) FROM ##individuals WHERE i_file=? AND i_id<?")
->execute(array($ged_id, $pid))
->fetchOne();
break;
case "FAM":
return
- WT_DB::prepare("SELECT MAX(f_id) FROM {$TBLPREFIX}families WHERE f_file=? AND f_id<?")
+ WT_DB::prepare("SELECT MAX(f_id) FROM ##families WHERE f_file=? AND f_id<?")
->execute(array($ged_id, $pid))
->fetchOne();
case "SOUR":
return
- WT_DB::prepare("SELECT MAX(s_id) FROM {$TBLPREFIX}sources WHERE s_file=? AND s_id<?")
+ WT_DB::prepare("SELECT MAX(s_id) FROM ##sources WHERE s_file=? AND s_id<?")
->execute(array($ged_id, $pid))
->fetchOne();
case "OBJE":
return
- WT_DB::prepare("SELECT MAX(m_media) FROM {$TBLPREFIX}media WHERE m_gedfile=? AND m_media<?")
+ WT_DB::prepare("SELECT MAX(m_media) FROM ##media WHERE m_gedfile=? AND m_media<?")
->execute(array($ged_id, $pid))
->fetchOne();
default:
return
- WT_DB::prepare("SELECT MAX(o_id) FROM {$TBLPREFIX}other WHERE o_file=? AND o_type=? AND o_id<?")
+ WT_DB::prepare("SELECT MAX(o_id) FROM ##other WHERE o_file=? AND o_type=? AND o_id<?")
->execute(array($ged_id, $type, $pid))
->fetchOne();
}
@@ -184,20 +176,18 @@ function get_prev_xref($pid, $ged_id=WT_GED_ID) {
// $ged_id - only consider individuals from this gedcom
////////////////////////////////////////////////////////////////////////////////
function get_indilist_salpha($marnm, $fams, $ged_id) {
- global $TBLPREFIX;
-
$alphas=array();
// This logic relies on the database's collation rules to ensure that accented letters
// and digraphs appear in the correct listing.
foreach (explode(' ', i18n::$alphabet) as $letter) {
- $query="SELECT COUNT(DISTINCT i_id) FROM {$TBLPREFIX}individuals";
+ $query="SELECT COUNT(DISTINCT i_id) FROM ##individuals";
if ($marnm) {
- $query.=" JOIN {$TBLPREFIX}name ON (i_id=n_id AND i_file=n_file)";
+ $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file)";
} else {
- $query.=" JOIN {$TBLPREFIX}name ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')";
+ $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')";
}
if ($fams) {
- $query.=" JOIN {$TBLPREFIX}link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')";
+ $query.=" JOIN ##link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')";
}
$query.=" WHERE n_file=? AND n_sort LIKE '{$letter}%' COLLATE '".i18n::$collation."'";
foreach (explode(' ', i18n::$alphabet) as $letter2) {
@@ -211,14 +201,14 @@ function get_indilist_salpha($marnm, $fams, $ged_id) {
// This includes "@" (unknown) and "," (none)
$query=
"SELECT LEFT(n_sort, 1), COUNT(DISTINCT i_id)".
- " FROM {$TBLPREFIX}individuals";
+ " FROM ##individuals";
if ($marnm) {
- $query.=" JOIN {$TBLPREFIX}name ON (i_id=n_id AND i_file=n_file)";
+ $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file)";
} else {
- $query.=" JOIN {$TBLPREFIX}name ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')";
+ $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')";
}
if ($fams) {
- $query.=" JOIN {$TBLPREFIX}link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')";
+ $query.=" JOIN ##link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')";
}
$query.=" WHERE n_file=?";
foreach (explode(' ', i18n::$alphabet) as $letter) {
@@ -251,20 +241,18 @@ function get_indilist_salpha($marnm, $fams, $ged_id) {
// $ged_id - only consider individuals from this gedcom
////////////////////////////////////////////////////////////////////////////////
function get_indilist_galpha($surn, $salpha, $marnm, $fams, $ged_id) {
- global $TBLPREFIX;
-
$alphas=array();
// This logic relies on the database's collation rules to ensure that accented letters
// and digraphs appear in the correct listing.
foreach (explode(' ', i18n::$alphabet) as $letter) {
- $query="SELECT COUNT(DISTINCT i_id) FROM {$TBLPREFIX}individuals";
+ $query="SELECT COUNT(DISTINCT i_id) FROM ##individuals";
if ($marnm) {
- $query.=" JOIN {$TBLPREFIX}name ON (i_id=n_id AND i_file=n_file)";
+ $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file)";
} else {
- $query.=" JOIN {$TBLPREFIX}name ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')";
+ $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')";
}
if ($fams) {
- $query.=" JOIN {$TBLPREFIX}link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')";
+ $query.=" JOIN ##link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')";
}
$query.=" WHERE n_file=?";
if ($surn) {
@@ -284,14 +272,14 @@ function get_indilist_galpha($surn, $salpha, $marnm, $fams, $ged_id) {
// This includes "@" (unknown) and "," (none)
$query=
"SELECT LEFT(n_givn, 1), COUNT(DISTINCT i_id)".
- " FROM {$TBLPREFIX}individuals";
+ " FROM ##individuals";
if ($marnm) {
- $query.=" JOIN {$TBLPREFIX}name ON (i_id=n_id AND i_file=n_file)";
+ $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file)";
} else {
- $query.=" JOIN {$TBLPREFIX}name ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')";
+ $query.=" JOIN ##name ON (i_id=n_id AND i_file=n_file AND n_type!='_MARNM')";
}
if ($fams) {
- $query.=" JOIN {$TBLPREFIX}link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')";
+ $query.=" JOIN ##link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')";
}
$query.=" WHERE n_file=?";
if ($surn) {
@@ -330,11 +318,9 @@ function get_indilist_galpha($surn, $salpha, $marnm, $fams, $ged_id) {
// $ged_id - only consider individuals from this gedcom
////////////////////////////////////////////////////////////////////////////////
function get_indilist_surns($surn, $salpha, $marnm, $fams, $ged_id) {
- global $TBLPREFIX;
-
- $sql="SELECT DISTINCT n_surn, n_surname, n_id FROM {$TBLPREFIX}individuals JOIN {$TBLPREFIX}name ON (i_id=n_id AND i_file=n_file)";
+ $sql="SELECT DISTINCT n_surn, n_surname, n_id FROM ##individuals JOIN ##name ON (i_id=n_id AND i_file=n_file)";
if ($fams) {
- $sql.=" JOIN {$TBLPREFIX}link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')";
+ $sql.=" JOIN ##link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')";
}
$where=array("n_file={$ged_id}");
if (!$marnm) {
@@ -373,9 +359,7 @@ function get_indilist_surns($surn, $salpha, $marnm, $fams, $ged_id) {
// $ged_id - only consider individuals from this gedcom
////////////////////////////////////////////////////////////////////////////////
function get_famlist_surns($surn, $salpha, $marnm, $ged_id) {
- global $TBLPREFIX;
-
- $sql="SELECT DISTINCT n_surn, n_surname, l_to FROM {$TBLPREFIX}individuals JOIN {$TBLPREFIX}name ON (i_id=n_id AND i_file=n_file) JOIN {$TBLPREFIX}link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')";
+ $sql="SELECT DISTINCT n_surn, n_surname, l_to FROM ##individuals JOIN ##name ON (i_id=n_id AND i_file=n_file) JOIN ##link ON (i_id=l_from AND i_file=l_file AND l_type='FAMS')";
$where=array("n_file={$ged_id}");
if (!$marnm) {
$where[]="n_type!='_MARNM'";
@@ -423,11 +407,9 @@ function get_famlist_surns($surn, $salpha, $marnm, $ged_id) {
// To search for names with no surnames, use $salpha=","
////////////////////////////////////////////////////////////////////////////////
function get_indilist_indis($surn='', $salpha='', $galpha='', $marnm=false, $fams=false, $ged_id=null) {
- global $TBLPREFIX;
-
- $sql="SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex, n_surn, n_surname, n_num FROM {$TBLPREFIX}individuals JOIN {$TBLPREFIX}name ON (i_id=n_id AND i_file=n_file)";
+ $sql="SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex, n_surn, n_surname, n_num FROM ##individuals JOIN ##name ON (i_id=n_id AND i_file=n_file)";
if ($fams) {
- $sql.=" JOIN {$TBLPREFIX}link ON (i_id=l_from AND i_file=l_file)";
+ $sql.=" JOIN ##link ON (i_id=l_from AND i_file=l_file)";
}
$where=array();
if ($ged_id) {
@@ -498,8 +480,6 @@ function get_indilist_indis($surn='', $salpha='', $galpha='', $marnm=false, $fam
// To search for names with no surnames, use $salpha=","
////////////////////////////////////////////////////////////////////////////////
function get_famlist_fams($surn='', $salpha='', $galpha='', $marnm, $ged_id=null) {
- global $TBLPREFIX;
-
$list=array();
foreach (get_indilist_indis($surn, $salpha, $galpha, $marnm, true, $ged_id) as $indi) {
foreach ($indi->getSpouseFamilies() as $family) {
@@ -510,7 +490,7 @@ function get_famlist_fams($surn='', $salpha='', $galpha='', $marnm, $ged_id=null
// with missing spouses
if ($surn=='@N.N.' || $salpha=='@') {
$rows=
- WT_DB::prepare("SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM {$TBLPREFIX}families f WHERE f_file={$ged_id} AND (f_husb='' OR f_wife='')")
+ WT_DB::prepare("SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM ##families f WHERE f_file={$ged_id} AND (f_husb='' OR f_wife='')")
->execute(array($ged_id))
->fetchAll(PDO::FETCH_ASSOC);
@@ -526,11 +506,10 @@ function get_famlist_fams($surn='', $salpha='', $galpha='', $marnm, $ged_id=null
// Fetch a list of children for an individual, from all their partners.
////////////////////////////////////////////////////////////////////////////////
function fetch_child_ids($parent_id, $ged_id) {
- global $TBLPREFIX;
static $statement=null;
if (is_null($statement)) {
- $statement=WT_DB::prepare("SELECT DISTINCT child.l_from AS xref FROM {$TBLPREFIX}link child, {$TBLPREFIX}link spouse WHERE child.l_type=? AND spouse.l_type=? AND child.l_file=spouse.l_file AND child.l_to=spouse.l_to AND spouse.l_from=? AND child.l_file=?");
+ $statement=WT_DB::prepare("SELECT DISTINCT child.l_from AS xref FROM ##link child, ##link spouse WHERE child.l_type=? AND spouse.l_type=? AND child.l_file=spouse.l_file AND child.l_to=spouse.l_to AND spouse.l_from=? AND child.l_file=?");
}
return $statement->execute(array('FAMC', 'FAMS', $parent_id, $ged_id))->fetchOneColumn();
@@ -540,42 +519,32 @@ function fetch_child_ids($parent_id, $ged_id) {
// Count the number of records linked to a given record
////////////////////////////////////////////////////////////////////////////////
function count_linked_indi($xref, $link, $ged_id) {
- global $TBLPREFIX;
-
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}link, {$TBLPREFIX}individuals WHERE i_file=l_file AND i_id=l_from AND l_file=? AND l_type=? AND l_to=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##link, ##individuals WHERE i_file=l_file AND i_id=l_from AND l_file=? AND l_type=? AND l_to=?")
->execute(array($ged_id, $link, $xref))
->fetchOne();
}
function count_linked_fam($xref, $link, $ged_id) {
- global $TBLPREFIX;
-
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}link, {$TBLPREFIX}families WHERE f_file=l_file AND f_id=l_from AND l_file=? AND l_type=? AND l_to=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##link, ##families WHERE f_file=l_file AND f_id=l_from AND l_file=? AND l_type=? AND l_to=?")
->execute(array($ged_id, $link, $xref))
->fetchOne();
}
function count_linked_note($xref, $link, $ged_id) {
- global $TBLPREFIX;
-
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}link, {$TBLPREFIX}other WHERE o_file=l_file AND o_id=l_from AND o_type=? AND l_file=? AND l_type=? AND l_to=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##link, ##other WHERE o_file=l_file AND o_id=l_from AND o_type=? AND l_file=? AND l_type=? AND l_to=?")
->execute(array('NOTE', $ged_id, $link, $xref))
->fetchOne();
}
function count_linked_sour($xref, $link, $ged_id) {
- global $TBLPREFIX;
-
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}link, {$TBLPREFIX}sources WHERE s_file=l_file AND s_id=l_from AND l_file=? AND l_type=? AND l_to=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##link, ##sources WHERE s_file=l_file AND s_id=l_from AND l_file=? AND l_type=? AND l_to=?")
->execute(array($ged_id, $link, $xref))
->fetchOne();
}
function count_linked_obje($xref, $link, $ged_id) {
- global $TBLPREFIX;
-
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}link, {$TBLPREFIX}media WHERE m_gedfile=l_file AND m_media=l_from AND l_file=? AND l_type=? AND l_to=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##link, ##media WHERE m_gedfile=l_file AND m_media=l_from AND l_file=? AND l_type=? AND l_to=?")
->execute(array($ged_id, $link, $xref))
->fetchOne();
}
@@ -584,13 +553,11 @@ function count_linked_obje($xref, $link, $ged_id) {
// Fetch records linked to a given record
////////////////////////////////////////////////////////////////////////////////
function fetch_linked_indi($xref, $link, $ged_id) {
- global $TBLPREFIX;
-
$rows=WT_DB::prepare(
"SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex".
- " FROM {$TBLPREFIX}individuals".
- " JOIN {$TBLPREFIX}link ON (i_file=l_file AND i_id=l_from)".
- " LEFT JOIN {$TBLPREFIX}name ON (i_file=n_file AND i_id=n_id AND n_num=0)".
+ " FROM ##individuals".
+ " JOIN ##link ON (i_file=l_file AND i_id=l_from)".
+ " LEFT JOIN ##name ON (i_file=n_file AND i_id=n_id AND n_num=0)".
" WHERE i_file=? AND l_type=? AND l_to=?".
" ORDER BY n_sort"
)->execute(array($ged_id, $link, $xref))->fetchAll(PDO::FETCH_ASSOC);
@@ -602,13 +569,11 @@ function fetch_linked_indi($xref, $link, $ged_id) {
return $list;
}
function fetch_linked_fam($xref, $link, $ged_id) {
- global $TBLPREFIX;
-
$rows=WT_DB::prepare(
"SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil".
- " FROM {$TBLPREFIX}families".
- " JOIN {$TBLPREFIX}link ON (f_file=l_file AND f_id=l_from)".
- " LEFT JOIN {$TBLPREFIX}name ON (f_file=n_file AND f_id=n_id AND n_num=0)".
+ " FROM ##families".
+ " JOIN ##link ON (f_file=l_file AND f_id=l_from)".
+ " LEFT JOIN ##name ON (f_file=n_file AND f_id=n_id AND n_num=0)".
" WHERE f_file=? AND l_type=? AND l_to=?".
" ORDER BY n_sort"
)->execute(array($ged_id, $link, $xref))->fetchAll(PDO::FETCH_ASSOC);
@@ -620,13 +585,11 @@ function fetch_linked_fam($xref, $link, $ged_id) {
return $list;
}
function fetch_linked_note($xref, $link, $ged_id) {
- global $TBLPREFIX;
-
$rows=WT_DB::prepare(
"SELECT 'NOTE' AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec".
- " FROM {$TBLPREFIX}other".
- " JOIN {$TBLPREFIX}link ON (o_file=l_file AND o_id=l_from)".
- " LEFT JOIN {$TBLPREFIX}name ON (o_file=n_file AND o_id=n_id AND n_num=0)".
+ " FROM ##other".
+ " JOIN ##link ON (o_file=l_file AND o_id=l_from)".
+ " LEFT JOIN ##name ON (o_file=n_file AND o_id=n_id AND n_num=0)".
" WHERE o_file=? AND o_type='NOTE' AND l_type=? AND l_to=?".
" ORDER BY n_sort"
)->execute(array($ged_id, $link, $xref))->fetchAll(PDO::FETCH_ASSOC);
@@ -638,13 +601,11 @@ function fetch_linked_note($xref, $link, $ged_id) {
return $list;
}
function fetch_linked_sour($xref, $link, $ged_id) {
- global $TBLPREFIX;
-
$rows=WT_DB::prepare(
"SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec".
- " FROM {$TBLPREFIX}sources".
- " JOIN {$TBLPREFIX}link ON (s_file=l_file AND s_id=l_from)".
- " LEFT JOIN {$TBLPREFIX}name ON (s_file=n_file AND s_id=n_id AND n_num=0)".
+ " FROM ##sources".
+ " JOIN ##link ON (s_file=l_file AND s_id=l_from)".
+ " LEFT JOIN ##name ON (s_file=n_file AND s_id=n_id AND n_num=0)".
" WHERE s_file=? AND l_type=? AND l_to=?".
" ORDER BY n_sort"
)->execute(array($ged_id, $link, $xref))->fetchAll(PDO::FETCH_ASSOC);
@@ -656,13 +617,11 @@ function fetch_linked_sour($xref, $link, $ged_id) {
return $list;
}
function fetch_linked_obje($xref, $link, $ged_id) {
- global $TBLPREFIX;
-
$rows=WT_DB::prepare(
"SELECT 'OBJE' AS type, m_media AS xref, m_gedfile AS ged_id, m_gedrec AS gedrec, m_titl, m_file".
- " FROM {$TBLPREFIX}media".
- " JOIN {$TBLPREFIX}link ON (m_gedfile=l_file AND m_media=l_from)".
- " LEFT JOIN {$TBLPREFIX}name ON (m_gedfile=n_file AND m_media=n_id AND n_num=0)".
+ " FROM ##media".
+ " JOIN ##link ON (m_gedfile=l_file AND m_media=l_from)".
+ " LEFT JOIN ##name ON (m_gedfile=n_file AND m_media=n_id AND n_num=0)".
" WHERE m_gedfile=? AND l_type=? AND l_to=?".
" ORDER BY n_sort"
)->execute(array($ged_id, $link, $xref))->fetchAll(PDO::FETCH_ASSOC);
@@ -679,10 +638,8 @@ function fetch_linked_obje($xref, $link, $ged_id) {
// also delete all links to it.
////////////////////////////////////////////////////////////////////////////////
function fetch_all_links($xref, $ged_id) {
- global $TBLPREFIX;
-
return
- WT_DB::prepare("SELECT l_from FROM {$TBLPREFIX}link WHERE l_file=? AND l_to=?")
+ WT_DB::prepare("SELECT l_from FROM ##link WHERE l_file=? AND l_to=?")
->execute(array($ged_id, $xref))
->fetchOneColumn();
}
@@ -694,37 +651,34 @@ function fetch_all_links($xref, $ged_id) {
// renamed consistently. The other columns are fetched as they are.
////////////////////////////////////////////////////////////////////////////////
function fetch_person_record($xref, $ged_id) {
- global $TBLPREFIX;
static $statement=null;
if (is_null($statement)) {
$statement=WT_DB::prepare(
"SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex ".
- "FROM {$TBLPREFIX}individuals WHERE i_id=? AND i_file=?"
+ "FROM ##individuals WHERE i_id=? AND i_file=?"
);
}
return $statement->execute(array($xref, $ged_id))->fetchOneRow(PDO::FETCH_ASSOC);
}
function fetch_family_record($xref, $ged_id) {
- global $TBLPREFIX;
static $statement=null;
if (is_null($statement)) {
$statement=WT_DB::prepare(
"SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil ".
- "FROM {$TBLPREFIX}families WHERE f_id=? AND f_file=?"
+ "FROM ##families WHERE f_id=? AND f_file=?"
);
}
return $statement->execute(array($xref, $ged_id))->fetchOneRow(PDO::FETCH_ASSOC);
}
function fetch_source_record($xref, $ged_id) {
- global $TBLPREFIX;
static $statement=null;
if (is_null($statement)) {
$statement=WT_DB::prepare(
"SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec ".
- "FROM {$TBLPREFIX}sources WHERE s_id=? AND s_file=?"
+ "FROM ##sources WHERE s_id=? AND s_file=?"
);
}
return $statement->execute(array($xref, $ged_id))->fetchOneRow(PDO::FETCH_ASSOC);
@@ -734,25 +688,23 @@ function fetch_note_record($xref, $ged_id) {
return fetch_other_record($xref, $ged_id);
}
function fetch_media_record($xref, $ged_id) {
- global $TBLPREFIX;
static $statement=null;
if (is_null($statement)) {
$statement=WT_DB::prepare(
"SELECT 'OBJE' AS type, m_media AS xref, m_gedfile AS ged_id, m_gedrec AS gedrec, m_titl, m_file ".
- "FROM {$TBLPREFIX}media WHERE m_media=? AND m_gedfile=?"
+ "FROM ##media WHERE m_media=? AND m_gedfile=?"
);
}
return $statement->execute(array($xref, $ged_id))->fetchOneRow(PDO::FETCH_ASSOC);
}
function fetch_other_record($xref, $ged_id) {
- global $TBLPREFIX;
static $statement=null;
if (is_null($statement)) {
$statement=WT_DB::prepare(
"SELECT o_type AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec ".
- "FROM {$TBLPREFIX}other WHERE o_id=? AND o_file=?"
+ "FROM ##other WHERE o_id=? AND o_file=?"
);
}
return $statement->execute(array($xref, $ged_id))->fetchOneRow(PDO::FETCH_ASSOC);
@@ -800,12 +752,11 @@ function fetch_gedcom_record($xref, $ged_id) {
* @return string the raw gedcom record is returned
*/
function find_family_record($xref, $ged_id) {
- global $TBLPREFIX;
static $statement=null;
if (is_null($statement)) {
$statement=WT_DB::prepare(
- "SELECT f_gedcom FROM {$TBLPREFIX}families WHERE f_id=? AND f_file=?"
+ "SELECT f_gedcom FROM ##families WHERE f_id=? AND f_file=?"
);
}
return $statement->execute(array($xref, $ged_id))->fetchOne();
@@ -819,12 +770,11 @@ function find_family_record($xref, $ged_id) {
* @return string the raw gedcom record is returned
*/
function find_person_record($xref, $ged_id) {
- global $TBLPREFIX;
static $statement=null;
if (is_null($statement)) {
$statement=WT_DB::prepare(
- "SELECT i_gedcom FROM {$TBLPREFIX}individuals WHERE i_id=? AND i_file=?"
+ "SELECT i_gedcom FROM ##individuals WHERE i_id=? AND i_file=?"
);
}
return $statement->execute(array($xref, $ged_id))->fetchOne();
@@ -838,12 +788,11 @@ function find_person_record($xref, $ged_id) {
* @return string the raw gedcom record is returned
*/
function find_source_record($xref, $ged_id) {
- global $TBLPREFIX;
static $statement=null;
if (is_null($statement)) {
$statement=WT_DB::prepare(
- "SELECT s_gedcom FROM {$TBLPREFIX}sources WHERE s_id=? AND s_file=?"
+ "SELECT s_gedcom FROM ##sources WHERE s_id=? AND s_file=?"
);
}
return $statement->execute(array($xref, $ged_id))->fetchOne();
@@ -855,12 +804,11 @@ function find_source_record($xref, $ged_id) {
* @param string $gedfile the gedcom file id
*/
function find_other_record($xref, $ged_id) {
- global $TBLPREFIX;
static $statement=null;
if (is_null($statement)) {
$statement=WT_DB::prepare(
- "SELECT o_gedcom FROM {$TBLPREFIX}other WHERE o_id=? AND o_file=?"
+ "SELECT o_gedcom FROM ##other WHERE o_id=? AND o_file=?"
);
}
return $statement->execute(array($xref, $ged_id))->fetchOne();
@@ -871,12 +819,11 @@ function find_other_record($xref, $ged_id) {
* @param string $rid the record id
*/
function find_media_record($xref, $ged_id) {
- global $TBLPREFIX;
static $statement=null;
if (is_null($statement)) {
$statement=WT_DB::prepare(
- "SELECT m_gedrec FROM {$TBLPREFIX}media WHERE m_media=? AND m_gedfile=?"
+ "SELECT m_gedrec FROM ##media WHERE m_media=? AND m_gedfile=?"
);
}
return $statement->execute(array($xref, $ged_id))->fetchOne();
@@ -884,16 +831,15 @@ function find_media_record($xref, $ged_id) {
// Find the gedcom data for a record. Optionally include pending changes.
function find_gedcom_record($xref, $ged_id, $pending=false) {
- global $TBLPREFIX;
static $statement=null;
if (is_null($statement)) {
$statement=WT_DB::prepare(
- "SELECT i_gedcom FROM {$TBLPREFIX}individuals WHERE i_id =? AND i_file =? UNION ALL ".
- "SELECT f_gedcom FROM {$TBLPREFIX}families WHERE f_id =? AND f_file =? UNION ALL ".
- "SELECT s_gedcom FROM {$TBLPREFIX}sources WHERE s_id =? AND s_file =? UNION ALL ".
- "SELECT m_gedrec FROM {$TBLPREFIX}media WHERE m_media=? AND m_gedfile=? UNION ALL ".
- "SELECT o_gedcom FROM {$TBLPREFIX}other WHERE o_id =? AND o_file =?"
+ "SELECT i_gedcom FROM ##individuals WHERE i_id =? AND i_file =? UNION ALL ".
+ "SELECT f_gedcom FROM ##families WHERE f_id =? AND f_file =? UNION ALL ".
+ "SELECT s_gedcom FROM ##sources WHERE s_id =? AND s_file =? UNION ALL ".
+ "SELECT m_gedrec FROM ##media WHERE m_media=? AND m_gedfile=? UNION ALL ".
+ "SELECT o_gedcom FROM ##other WHERE o_id =? AND o_file =?"
);
}
@@ -920,12 +866,11 @@ function find_gedcom_record($xref, $ged_id, $pending=false) {
* @param string $gedfile the gedcom file to get the record from.. defaults to currently active gedcom
*/
function find_updated_record($xref, $ged_id) {
- global $TBLPREFIX;
static $statement=null;
if (is_null($statement)) {
$statement=WT_DB::prepare(
- "SELECT new_gedcom FROM {$TBLPREFIX}change WHERE gedcom_id=? AND xref=? AND status='pending' ".
+ "SELECT new_gedcom FROM ##change WHERE gedcom_id=? AND xref=? AND status='pending' ".
"ORDER BY change_id DESC LIMIT 1"
);
}
@@ -937,16 +882,16 @@ function find_updated_record($xref, $ged_id) {
// Find the type of a gedcom record. Check the cache before querying the database.
// Returns 'INDI', 'FAM', etc., or null if the record does not exist.
function gedcom_record_type($xref, $ged_id) {
- global $TBLPREFIX, $gedcom_record_cache;
+ global $gedcom_record_cache;
static $statement=null;
if (is_null($statement)) {
$statement=WT_DB::prepare(
- "SELECT 'INDI' FROM {$TBLPREFIX}individuals WHERE i_id =? AND i_file =? UNION ALL ".
- "SELECT 'FAM' FROM {$TBLPREFIX}families WHERE f_id =? AND f_file =? UNION ALL ".
- "SELECT 'SOUR' FROM {$TBLPREFIX}sources WHERE s_id =? AND s_file =? UNION ALL ".
- "SELECT 'OBJE' FROM {$TBLPREFIX}media WHERE m_media=? AND m_gedfile=? UNION ALL ".
- "SELECT o_type FROM {$TBLPREFIX}other WHERE o_id =? AND o_file =?"
+ "SELECT 'INDI' FROM ##individuals WHERE i_id =? AND i_file =? UNION ALL ".
+ "SELECT 'FAM' FROM ##families WHERE f_id =? AND f_file =? UNION ALL ".
+ "SELECT 'SOUR' FROM ##sources WHERE s_id =? AND s_file =? UNION ALL ".
+ "SELECT 'OBJE' FROM ##media WHERE m_media=? AND m_gedfile=? UNION ALL ".
+ "SELECT o_type FROM ##other WHERE o_id =? AND o_file =?"
);
}
@@ -959,13 +904,11 @@ function gedcom_record_type($xref, $ged_id) {
// Find out if there are any pending changes that a given user may accept
function exists_pending_change($user_id=WT_USER_ID, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
if (userCanAccept($user_id, $ged_id)) {
return
WT_DB::prepare(
"SELECT 1".
- " FROM {$TBLPREFIX}change".
+ " FROM ##change".
" WHERE status='pending' AND gedcom_id=?"
)->execute(array($ged_id))->fetchOne();
} else {
@@ -985,19 +928,15 @@ function exists_pending_change($user_id=WT_USER_ID, $ged_id=WT_GED_ID) {
* @param bool $isdead true=dead
*/
function update_isdead($xref, $ged_id, $isdead) {
- global $TBLPREFIX;
-
$isdead=$isdead ? 1 : 0; // DB uses int, not bool
- WT_DB::prepare("UPDATE {$TBLPREFIX}individuals SET i_isdead=? WHERE i_id=? AND i_file=?")->execute(array($isdead, $xref, $ged_id));
+ WT_DB::prepare("UPDATE ##individuals SET i_isdead=? WHERE i_id=? AND i_file=?")->execute(array($isdead, $xref, $ged_id));
return $isdead;
}
// Reset the i_isdead status for individuals
// This is necessary when we change the MAX_ALIVE_YEARS value
function reset_isdead($ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
- WT_DB::prepare("UPDATE {$TBLPREFIX}individuals SET i_isdead=-1 WHERE i_file=?")->execute(array($ged_id));
+ WT_DB::prepare("UPDATE ##individuals SET i_isdead=-1 WHERE i_file=?")->execute(array($ged_id));
}
/**
@@ -1008,10 +947,8 @@ function reset_isdead($ged_id=WT_GED_ID) {
* @return array the array of sources
*/
function get_source_list($ged_id) {
- global $TBLPREFIX;
-
$rows=
- WT_DB::prepare("SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec FROM {$TBLPREFIX}sources s WHERE s_file=?")
+ WT_DB::prepare("SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec FROM ##sources s WHERE s_file=?")
->execute(array($ged_id))
->fetchAll(PDO::FETCH_ASSOC);
@@ -1026,10 +963,8 @@ function get_source_list($ged_id) {
// Get a list of repositories from the database
// $ged_id - the gedcom to search
function get_repo_list($ged_id) {
- global $TBLPREFIX;
-
$rows=
- WT_DB::prepare("SELECT 'REPO' AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec FROM {$TBLPREFIX}other WHERE o_type='REPO' AND o_file=?")
+ WT_DB::prepare("SELECT 'REPO' AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec FROM ##other WHERE o_type='REPO' AND o_file=?")
->execute(array($ged_id))
->fetchAll(PDO::FETCH_ASSOC);
@@ -1043,10 +978,8 @@ function get_repo_list($ged_id) {
//-- get the shared note list from the datastore
function get_note_list($ged_id) {
- global $TBLPREFIX;
-
$rows=
- WT_DB::prepare("SELECT 'NOTE' AS type, o_id AS xref, {$ged_id} AS ged_id, o_gedcom AS gedrec FROM {$TBLPREFIX}other WHERE o_type=? AND o_file=?")
+ WT_DB::prepare("SELECT 'NOTE' AS type, o_id AS xref, {$ged_id} AS ged_id, o_gedcom AS gedrec FROM ##other WHERE o_type=? AND o_file=?")
->execute(array('NOTE', $ged_id))
->fetchAll(PDO::FETCH_ASSOC);
@@ -1061,9 +994,7 @@ function get_note_list($ged_id) {
// Search for INDIs using custom SQL generated by the report engine
function search_indis_custom($join, $where, $order) {
- global $TBLPREFIX;
-
- $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM {$TBLPREFIX}individuals ".implode(' ', $join).' WHERE '.implode(' AND ', $where);
+ $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM ##individuals ".implode(' ', $join).' WHERE '.implode(' AND ', $where);
if ($order) {
$sql.=' ORDER BY '.implode(' ', $order);
}
@@ -1090,9 +1021,7 @@ function search_indis_custom($join, $where, $order) {
// Search for FAMs using custom SQL generated by the report engine
function search_fams_custom($join, $where, $order) {
- global $TBLPREFIX;
-
- $sql="SELECT DISTINCT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM {$TBLPREFIX}families ".implode(' ', $join).' WHERE '.implode(' AND ', $where);
+ $sql="SELECT DISTINCT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM ##families ".implode(' ', $join).' WHERE '.implode(' AND ', $where);
if ($order) {
$sql.=' ORDER BY '.implode(' ', $order);
}
@@ -1123,7 +1052,7 @@ function search_fams_custom($join, $where, $order) {
// $match - AND or OR
// $skip - ignore data in certain tags
function search_indis($query, $geds, $match, $skip) {
- global $TBLPREFIX, $GEDCOM;
+ global $GEDCOM;
// No query => no results
if (!$query) {
@@ -1140,7 +1069,7 @@ function search_indis($query, $geds, $match, $skip) {
$querysql[]="i_gedcom LIKE ".WT_DB::quote("%{$q}%")." COLLATE '".i18n::$collation."'";
}
- $sql="SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM {$TBLPREFIX}individuals WHERE (".implode(" {$match} ", $querysql).') AND i_file IN ('.implode(',', $geds).')';
+ $sql="SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM ##individuals WHERE (".implode(" {$match} ", $querysql).') AND i_file IN ('.implode(',', $geds).')';
// Group results by gedcom, to minimise switching between privacy files
$sql.=' ORDER BY ged_id';
@@ -1181,7 +1110,7 @@ function search_indis($query, $geds, $match, $skip) {
// $geds - array of gedcoms to search
// $match - AND or OR
function search_indis_names($query, $geds, $match) {
- global $TBLPREFIX, $GEDCOM;
+ global $GEDCOM;
// No query => no results
if (!$query) {
@@ -1193,7 +1122,7 @@ function search_indis_names($query, $geds, $match) {
foreach ($query as $q) {
$querysql[]="n_full LIKE ".WT_DB::quote("%{$q}%")." COLLATE '".i18n::$collation."'";
}
- $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex, n_num FROM {$TBLPREFIX}individuals JOIN {$TBLPREFIX}name ON i_id=n_id AND i_file=n_file WHERE (".implode(" {$match} ", $querysql).') AND i_file IN ('.implode(',', $geds).')';
+ $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex, n_num FROM ##individuals JOIN ##name ON i_id=n_id AND i_file=n_file WHERE (".implode(" {$match} ", $querysql).') AND i_file IN ('.implode(',', $geds).')';
// Group results by gedcom, to minimise switching between privacy files
$sql.=' ORDER BY ged_id';
@@ -1232,15 +1161,13 @@ function search_indis_names($query, $geds, $match) {
// $lastname, $firstname, $place - search terms
// $geds - array of gedcoms to search
function search_indis_soundex($soundex, $lastname, $firstname, $place, $geds) {
- global $TBLPREFIX;
-
- $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM {$TBLPREFIX}individuals";
+ $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM ##individuals";
if ($place) {
- $sql.=" JOIN {$TBLPREFIX}placelinks ON (pl_file=i_file AND pl_gid=i_id)";
- $sql.=" JOIN {$TBLPREFIX}places ON (p_file=pl_file AND pl_p_id=p_id)";
+ $sql.=" JOIN ##placelinks ON (pl_file=i_file AND pl_gid=i_id)";
+ $sql.=" JOIN ##places ON (p_file=pl_file AND pl_p_id=p_id)";
}
if ($firstname || $lastname) {
- $sql.=" JOIN {$TBLPREFIX}name ON (i_file=n_file AND i_id=n_id)";
+ $sql.=" JOIN ##name ON (i_file=n_file AND i_id=n_id)";
}
$sql.=' WHERE i_file IN ('.implode(',', $geds).')';
switch ($soundex) {
@@ -1309,9 +1236,7 @@ function search_indis_soundex($soundex, $lastname, $firstname, $place, $geds) {
* @param int $jd, leave empty to include all
*/
function get_recent_changes($jd=0, $allgeds=false) {
- global $TBLPREFIX;
-
- $sql="SELECT d_gid FROM {$TBLPREFIX}dates WHERE d_fact='CHAN' AND d_julianday1>=? AND d_gid NOT LIKE ?";
+ $sql="SELECT d_gid FROM ##dates WHERE d_fact='CHAN' AND d_julianday1>=? AND d_gid NOT LIKE ?";
$vars=array($jd, '%:%');
if (!$allgeds) {
$sql.=" AND d_file=?";
@@ -1324,9 +1249,7 @@ function get_recent_changes($jd=0, $allgeds=false) {
// Seach for individuals with events on a given day
function search_indis_dates($day, $month, $year, $facts) {
- global $TBLPREFIX;
-
- $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM {$TBLPREFIX}individuals JOIN {$TBLPREFIX}dates ON i_id=d_gid AND i_file=d_file WHERE i_file=?";
+ $sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM ##individuals JOIN ##dates ON i_id=d_gid AND i_file=d_file WHERE i_file=?";
$vars=array(WT_GED_ID);
if ($day) {
$sql.=" AND d_day=?";
@@ -1364,9 +1287,7 @@ function search_indis_dates($day, $month, $year, $facts) {
// Seach for individuals with events in a given date range
function search_indis_daterange($start, $end, $facts) {
- global $TBLPREFIX;
-
- $sql="SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM {$TBLPREFIX}individuals JOIN {$TBLPREFIX}dates ON i_id=d_gid AND i_file=d_file WHERE i_file=? AND d_julianday1 BETWEEN ? AND ?";
+ $sql="SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex FROM ##individuals JOIN ##dates ON i_id=d_gid AND i_file=d_file WHERE i_file=? AND d_julianday1 BETWEEN ? AND ?";
$vars=array(WT_GED_ID, $start, $end);
if ($facts) {
@@ -1403,7 +1324,7 @@ function search_indis_year_range($startyear, $endyear) {
// $match - AND or OR
// $skip - ignore data in certain tags
function search_fams($query, $geds, $match, $skip) {
- global $TBLPREFIX, $GEDCOM;
+ global $GEDCOM;
// No query => no results
if (!$query) {
@@ -1420,7 +1341,7 @@ function search_fams($query, $geds, $match, $skip) {
$querysql[]="f_gedcom LIKE ".WT_DB::quote("%{$q}%")." COLLATE '".i18n::$collation."'";
}
- $sql="SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM {$TBLPREFIX}families WHERE (".implode(" {$match} ", $querysql).') AND f_file IN ('.implode(',', $geds).')';
+ $sql="SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM ##families WHERE (".implode(" {$match} ", $querysql).') AND f_file IN ('.implode(',', $geds).')';
// Group results by gedcom, to minimise switching between privacy files
$sql.=' ORDER BY ged_id';
@@ -1461,7 +1382,7 @@ function search_fams($query, $geds, $match, $skip) {
// $geds - array of gedcoms to search
// $match - AND or OR
function search_fams_names($query, $geds, $match) {
- global $TBLPREFIX, $GEDCOM;
+ global $GEDCOM;
// No query => no results
if (!$query) {
@@ -1474,7 +1395,7 @@ function search_fams_names($query, $geds, $match) {
$querysql[]="(husb.n_full LIKE ".WT_DB::quote("%{$q}%")." COLLATE '".i18n::$collation."' OR wife.n_full LIKE ".WT_DB::quote("%{$q}%")." COLLATE '".i18n::$collation."')";
}
- $sql="SELECT DISTINCT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM {$TBLPREFIX}families LEFT OUTER JOIN {$TBLPREFIX}name husb ON f_husb=husb.n_id AND f_file=husb.n_file LEFT OUTER JOIN {$TBLPREFIX}name wife ON f_wife=wife.n_id AND f_file=wife.n_file WHERE (".implode(" {$match} ", $querysql).') AND f_file IN ('.implode(',', $geds).')';
+ $sql="SELECT DISTINCT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM ##families LEFT OUTER JOIN ##name husb ON f_husb=husb.n_id AND f_file=husb.n_file LEFT OUTER JOIN ##name wife ON f_wife=wife.n_id AND f_file=wife.n_file WHERE (".implode(" {$match} ", $querysql).') AND f_file IN ('.implode(',', $geds).')';
// Group results by gedcom, to minimise switching between privacy files
$sql.=' ORDER BY ged_id';
@@ -1508,7 +1429,7 @@ function search_fams_names($query, $geds, $match) {
// $match - AND or OR
// $skip - ignore data in certain tags
function search_sources($query, $geds, $match, $skip) {
- global $TBLPREFIX, $GEDCOM;
+ global $GEDCOM;
// No query => no results
if (!$query) {
@@ -1525,7 +1446,7 @@ function search_sources($query, $geds, $match, $skip) {
$querysql[]="s_gedcom LIKE ".WT_DB::quote("%{$q}%")." COLLATE '".i18n::$collation."'";
}
- $sql="SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec FROM {$TBLPREFIX}sources WHERE (".implode(" {$match} ", $querysql).') AND s_file IN ('.implode(',', $geds).')';
+ $sql="SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec FROM ##sources WHERE (".implode(" {$match} ", $querysql).') AND s_file IN ('.implode(',', $geds).')';
// Group results by gedcom, to minimise switching between privacy files
$sql.=' ORDER BY ged_id';
@@ -1567,7 +1488,7 @@ function search_sources($query, $geds, $match, $skip) {
// $match - AND or OR
// $skip - ignore data in certain tags
function search_notes($query, $geds, $match, $skip) {
- global $TBLPREFIX, $GEDCOM;
+ global $GEDCOM;
// No query => no results
if (!$query) {
@@ -1584,7 +1505,7 @@ function search_notes($query, $geds, $match, $skip) {
$querysql[]="o_gedcom LIKE ".WT_DB::quote("%{$q}%")." COLLATE '".i18n::$collation."'";
}
- $sql="SELECT 'NOTE' AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec FROM {$TBLPREFIX}other WHERE (".implode(" {$match} ", $querysql).") AND o_type='NOTE' AND o_file IN (".implode(',', $geds).')';
+ $sql="SELECT 'NOTE' AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec FROM ##other WHERE (".implode(" {$match} ", $querysql).") AND o_type='NOTE' AND o_file IN (".implode(',', $geds).')';
// Group results by gedcom, to minimise switching between privacy files
$sql.=' ORDER BY ged_id';
@@ -1627,11 +1548,10 @@ function search_notes($query, $geds, $match, $skip) {
* @return int
*/
function get_place_parent_id($parent, $level) {
- global $TBLPREFIX;
static $statement=null;
if (is_null($statement)) {
- $statement=WT_DB::prepare("SELECT p_id FROM {$TBLPREFIX}places WHERE p_level=? AND p_parent_id=? AND p_place LIKE ? AND p_file=?");
+ $statement=WT_DB::prepare("SELECT p_id FROM ##places WHERE p_level=? AND p_parent_id=? AND p_place LIKE ? AND p_file=?");
}
$parent_id=0;
@@ -1652,17 +1572,15 @@ function get_place_parent_id($parent, $level) {
* we are at.
*/
function get_place_list($parent, $level) {
- global $TBLPREFIX;
-
// --- find all of the place in the file
if ($level==0) {
return
- WT_DB::prepare("SELECT p_place FROM {$TBLPREFIX}places WHERE p_level=? AND p_file=? ORDER BY p_place")
+ WT_DB::prepare("SELECT p_place FROM ##places WHERE p_level=? AND p_file=? ORDER BY p_place")
->execute(array(0, WT_GED_ID))
->fetchOneColumn();
} else {
return
- WT_DB::prepare("SELECT p_place FROM {$TBLPREFIX}places WHERE p_level=? AND p_parent_id=? AND p_file=? ORDER BY p_place")
+ WT_DB::prepare("SELECT p_place FROM ##places WHERE p_level=? AND p_parent_id=? AND p_file=? ORDER BY p_place")
->execute(array($level, get_place_parent_id($parent, $level), WT_GED_ID))
->fetchOneColumn();
}
@@ -1675,19 +1593,17 @@ function get_place_list($parent, $level) {
* @return array
*/
function get_place_positions($parent, $level='') {
- global $TBLPREFIX;
-
// TODO: this function needs splitting into two
if ($level!=='') {
return
- WT_DB::prepare("SELECT DISTINCT pl_gid FROM {$TBLPREFIX}placelinks WHERE pl_p_id=? AND pl_file=?")
+ WT_DB::prepare("SELECT DISTINCT pl_gid FROM ##placelinks WHERE pl_p_id=? AND pl_file=?")
->execute(array(get_place_parent_id($parent, $level), WT_GED_ID))
->fetchOneColumn();
} else {
//-- we don't know the level so get the any matching place
return
- WT_DB::prepare("SELECT DISTINCT pl_gid FROM {$TBLPREFIX}placelinks, {$TBLPREFIX}places WHERE p_place LIKE ? AND p_file=pl_file AND p_id=pl_p_id AND p_file=?")
+ WT_DB::prepare("SELECT DISTINCT pl_gid FROM ##placelinks, ##places WHERE p_place LIKE ? AND p_file=pl_file AND p_id=pl_p_id AND p_file=?")
->execute(array($parent, WT_GED_ID))
->fetchOneColumn();
}
@@ -1695,10 +1611,8 @@ function get_place_positions($parent, $level='') {
//-- find all of the places
function find_place_list($place) {
- global $TBLPREFIX;
-
$rows=
- WT_DB::prepare("SELECT p_id, p_place, p_parent_id FROM {$TBLPREFIX}places WHERE p_file=? ORDER BY p_parent_id, p_id")
+ WT_DB::prepare("SELECT p_id, p_place, p_parent_id FROM ##places WHERE p_file=? ORDER BY p_parent_id, p_id")
->execute(array(WT_GED_ID))
->fetchAll();
@@ -1727,10 +1641,8 @@ function find_place_list($place) {
//-- function to find the gedcom id for the given rin
function find_rin_id($rin) {
- global $TBLPREFIX;
-
$xref=
- WT_DB::prepare("SELECT i_id FROM {$TBLPREFIX}individuals WHERE i_rin=? AND i_file=?")
+ WT_DB::prepare("SELECT i_id FROM ##individuals WHERE i_rin=? AND i_file=?")
->execute(array($rin, WT_GED_ID))
->fetchOne();
@@ -1743,35 +1655,33 @@ function find_rin_id($rin) {
* @param string $ged the filename of the gedcom to delete
*/
function delete_gedcom($ged_id) {
- global $TBLPREFIX;
-
$ged=get_gedcom_from_id($ged_id);
// Don't delete the logs.
- WT_DB::prepare("UPDATE {$TBLPREFIX}log SET gedcom_id=NULL WHERE gedcom_id =?")->execute(array($ged_id));
+ WT_DB::prepare("UPDATE ##log SET gedcom_id=NULL WHERE gedcom_id =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE {$TBLPREFIX}block_setting FROM {$TBLPREFIX}block_setting JOIN {$TBLPREFIX}block USING (block_id) WHERE gedcom_id=?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}block WHERE gedcom_id =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}news WHERE n_username=?")->execute(array($ged ));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}dates WHERE d_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}families WHERE f_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}favorites WHERE fv_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}user_gedcom_setting WHERE gedcom_id =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}gedcom_setting WHERE gedcom_id =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}individuals WHERE i_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}link WHERE l_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}media WHERE m_gedfile =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}media_mapping WHERE mm_gedfile=?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}module_privacy WHERE gedcom_id =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}name WHERE n_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}next_id WHERE gedcom_id =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}other WHERE o_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}placelinks WHERE pl_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}places WHERE p_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}sources WHERE s_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}hit_counter WHERE gedcom_id =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}change WHERE gedcom_id =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}gedcom WHERE gedcom_id =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE ##block_setting FROM ##block_setting JOIN ##block USING (block_id) WHERE gedcom_id=?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##block WHERE gedcom_id =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##news WHERE n_username=?")->execute(array($ged ));
+ WT_DB::prepare("DELETE FROM ##dates WHERE d_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##families WHERE f_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##favorites WHERE fv_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##user_gedcom_setting WHERE gedcom_id =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##gedcom_setting WHERE gedcom_id =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##individuals WHERE i_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##link WHERE l_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##media WHERE m_gedfile =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##media_mapping WHERE mm_gedfile=?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##module_privacy WHERE gedcom_id =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##name WHERE n_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##next_id WHERE gedcom_id =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##other WHERE o_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##placelinks WHERE pl_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##places WHERE p_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##sources WHERE s_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##hit_counter WHERE gedcom_id =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##change WHERE gedcom_id =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##gedcom WHERE gedcom_id =?")->execute(array($ged_id));
if (get_site_setting('DEFAULT_GEDCOM')==$ged) {
set_site_setting('DEFAULT_GEDCOM', '');
@@ -1786,12 +1696,10 @@ function delete_gedcom($ged_id) {
* @return array
*/
function get_top_surnames($ged_id, $min, $max) {
- global $TBLPREFIX;
-
// Use n_surn, rather than n_surname, as it is used to generate url's for
// the inid-list, etc.
return
- WT_DB::prepareLimit("SELECT n_surn, COUNT(n_surn) FROM {$TBLPREFIX}name WHERE n_file=? AND n_type!=? AND n_surn NOT IN (?, ?, ?, ?) GROUP BY n_surn HAVING COUNT(n_surn)>=".$min." ORDER BY 2 DESC", $max)
+ WT_DB::prepareLimit("SELECT n_surn, COUNT(n_surn) FROM ##name WHERE n_file=? AND n_type!=? AND n_surn NOT IN (?, ?, ?, ?) GROUP BY n_surn HAVING COUNT(n_surn)>=".$min." ORDER BY 2 DESC", $max)
->execute(array($ged_id, '_MARNM', '@N.N.', '', '?', 'UNKNOWN'))
->fetchAssoc();
}
@@ -1803,7 +1711,7 @@ function get_top_surnames($ged_id, $min, $max) {
* @return int the new id
*/
function get_next_id($table, $field) {
- global $TBLPREFIX, $TABLE_IDS;
+ global $TABLE_IDS;
if (!isset($TABLE_IDS)) {
$TABLE_IDS = array();
@@ -1812,7 +1720,7 @@ function get_next_id($table, $field) {
$TABLE_IDS[$table][$field]++;
return $TABLE_IDS[$table][$field];
}
- $newid=WT_DB::prepare("SELECT MAX({$field}) FROM {$TBLPREFIX}{$table}")->fetchOne();
+ $newid=WT_DB::prepare("SELECT MAX({$field}) FROM ##{$table}")->fetchOne();
$newid++;
$TABLE_IDS[$table][$field] = $newid;
return $newid;
@@ -1822,11 +1730,9 @@ function get_next_id($table, $field) {
* get a list of remote servers
*/
function get_server_list($ged_id=WT_GED_ID){
- global $TBLPREFIX;
-
$sitelist = array();
- $rows=WT_DB::prepare("SELECT s_id, s_name, s_gedcom, s_file FROM {$TBLPREFIX}sources WHERE s_file=? AND s_dbid=? ORDER BY s_name")
+ $rows=WT_DB::prepare("SELECT s_id, s_name, s_gedcom, s_file FROM ##sources WHERE s_file=? AND s_dbid=? ORDER BY s_name")
->execute(array($ged_id, 'Y'))
->fetchAll();
foreach ($rows as $row) {
@@ -1893,10 +1799,8 @@ function delete_fact($linenum, $pid, $gedrec) {
* @return gid Stub ID that contains the RFN number. Returns false if it didn't find anything
*/
function get_remote_id($rfn) {
- global $TBLPREFIX;
-
return
- WT_DB::prepare("SELECT r_gid FROM {$TBLPREFIX}remotelinks WHERE r_linkid=? AND r_file=?")
+ WT_DB::prepare("SELECT r_gid FROM ##remotelinks WHERE r_linkid=? AND r_file=?")
->execute(array($rfn, WT_GED_ID))
->fetchOne();
}
@@ -1909,8 +1813,6 @@ function get_remote_id($rfn) {
// $ged_id - the id of the gedcom to search
////////////////////////////////////////////////////////////////////////////////
function get_anniversary_events($jd, $facts='', $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
// If no facts specified, get all except these
$skipfacts = "CHAN,BAPL,SLGC,SLGS,ENDL,CENS,RESI,NOTE,ADDR,OBJE,SOUR,PAGE,DATA,TEXT";
if ($facts!='_TODO') {
@@ -2039,8 +1941,8 @@ function get_anniversary_events($jd, $facts='', $ged_id=WT_GED_ID) {
$where.=" AND d_file=".$ged_id;
// Now fetch these anniversaries
- $ind_sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex, d_type, d_day, d_month, d_year, d_fact, d_type FROM {$TBLPREFIX}dates, {$TBLPREFIX}individuals {$where} AND d_gid=i_id AND d_file=i_file ORDER BY d_day ASC, d_year DESC";
- $fam_sql="SELECT DISTINCT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil, d_type, d_day, d_month, d_year, d_fact, d_type FROM {$TBLPREFIX}dates, {$TBLPREFIX}families {$where} AND d_gid=f_id AND d_file=f_file ORDER BY d_day ASC, d_year DESC";
+ $ind_sql="SELECT DISTINCT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex, d_type, d_day, d_month, d_year, d_fact, d_type FROM ##dates, ##individuals {$where} AND d_gid=i_id AND d_file=i_file ORDER BY d_day ASC, d_year DESC";
+ $fam_sql="SELECT DISTINCT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil, d_type, d_day, d_month, d_year, d_fact, d_type FROM ##dates, ##families {$where} AND d_gid=f_id AND d_file=f_file ORDER BY d_day ASC, d_year DESC";
foreach (array($ind_sql, $fam_sql) as $sql) {
$rows=WT_DB::prepare($sql)->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
@@ -2099,8 +2001,6 @@ function get_anniversary_events($jd, $facts='', $ged_id=WT_GED_ID) {
// $ged_id - the id of the gedcom to search
////////////////////////////////////////////////////////////////////////////////
function get_calendar_events($jd1, $jd2, $facts='', $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
// If no facts specified, get all except these
$skipfacts = "CHAN,BAPL,SLGC,SLGS,ENDL,CENS,RESI,NOTE,ADDR,OBJE,SOUR,PAGE,DATA,TEXT";
if ($facts!='_TODO') {
@@ -2127,8 +2027,8 @@ function get_calendar_events($jd1, $jd2, $facts='', $ged_id=WT_GED_ID) {
$where.=" AND d_file=".$ged_id;
// Now fetch these events
- $ind_sql="SELECT d_gid, i_gedcom, 'INDI', d_type, d_day, d_month, d_year, d_fact, d_type FROM {$TBLPREFIX}dates, {$TBLPREFIX}individuals {$where} AND d_gid=i_id AND d_file=i_file ORDER BY d_julianday1";
- $fam_sql="SELECT d_gid, f_gedcom, 'FAM', d_type, d_day, d_month, d_year, d_fact, d_type FROM {$TBLPREFIX}dates, {$TBLPREFIX}families {$where} AND d_gid=f_id AND d_file=f_file ORDER BY d_julianday1";
+ $ind_sql="SELECT d_gid, i_gedcom, 'INDI', d_type, d_day, d_month, d_year, d_fact, d_type FROM ##dates, ##individuals {$where} AND d_gid=i_id AND d_file=i_file ORDER BY d_julianday1";
+ $fam_sql="SELECT d_gid, f_gedcom, 'FAM', d_type, d_day, d_month, d_year, d_fact, d_type FROM ##dates, ##families {$where} AND d_gid=f_id AND d_file=f_file ORDER BY d_julianday1";
foreach (array($ind_sql, $fam_sql) as $sql) {
$rows=WT_DB::prepare($sql)->fetchAll(PDO::FETCH_NUM);
foreach ($rows as $row) {
@@ -2200,10 +2100,8 @@ function get_events_list($jd1, $jd2, $events='') {
// Check if a media file is shared (i.e. used by another gedcom)
////////////////////////////////////////////////////////////////////////////////
function is_media_used_in_other_gedcom($file_name, $ged_id) {
- global $TBLPREFIX;
-
return
- (bool)WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}media WHERE m_file LIKE ? AND m_gedfile<>?")
+ (bool)WT_DB::prepare("SELECT COUNT(*) FROM ##media WHERE m_file LIKE ? AND m_gedfile<>?")
->execute(array("%{$file_name}", $ged_id))
->fetchOne();
}
@@ -2215,22 +2113,18 @@ function is_media_used_in_other_gedcom($file_name, $ged_id) {
// existing prepared statement handles in some databases.
////////////////////////////////////////////////////////////////////////////////
function get_site_setting($setting_name, $default_value=null) {
- global $TBLPREFIX;
-
return
WT_DB::prepare(
- "SELECT setting_value FROM {$TBLPREFIX}site_setting WHERE setting_name=?"
+ "SELECT setting_value FROM ##site_setting WHERE setting_name=?"
)->execute(array($setting_name))->fetchOne($default_value);
}
function set_site_setting($setting_name, $setting_value) {
- global $TBLPREFIX;
-
if (is_null($setting_value)) {
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}site_setting WHERE setting_name=?")
+ WT_DB::prepare("DELETE FROM ##site_setting WHERE setting_name=?")
->execute(array($setting_name));
} else {
- WT_DB::prepare("REPLACE INTO {$TBLPREFIX}site_setting (setting_name, setting_value) VALUES (?, ?)")
+ WT_DB::prepare("REPLACE INTO ##site_setting (setting_name, setting_value) VALUES (?, ?)")
->execute(array($setting_name, $setting_value));
}
}
@@ -2240,21 +2134,17 @@ function set_site_setting($setting_name, $setting_value) {
////////////////////////////////////////////////////////////////////////////////
function get_all_gedcoms() {
- global $TBLPREFIX;
-
return
- WT_DB::prepare("SELECT gedcom_id, gedcom_name FROM {$TBLPREFIX}gedcom")
+ WT_DB::prepare("SELECT gedcom_id, gedcom_name FROM ##gedcom")
->fetchAssoc();
}
function get_gedcom_titles() {
- global $TBLPREFIX;
-
return
WT_DB::prepare(
"SELECT g.gedcom_id, g.gedcom_name, COALESCE(gs.setting_value, g.gedcom_name) AS gedcom_title".
- " FROM {$TBLPREFIX}gedcom g".
- " LEFT JOIN {$TBLPREFIX}gedcom_setting gs ON (g.gedcom_id=gs.gedcom_id AND gs.setting_name=?)".
+ " FROM ##gedcom g".
+ " LEFT JOIN ##gedcom_setting gs ON (g.gedcom_id=gs.gedcom_id AND gs.setting_name=?)".
" ORDER BY 3"
)
->execute(array('title'))
@@ -2262,15 +2152,13 @@ function get_gedcom_titles() {
}
function get_gedcom_from_id($ged_id) {
- global $TBLPREFIX;
-
// No need to look up the default gedcom
if (defined('WT_GED_ID') && defined('WT_GEDCOM') && $ged_id==WT_GED_ID) {
return WT_GEDCOM;
}
return
- WT_DB::prepare("SELECT gedcom_name FROM {$TBLPREFIX}gedcom WHERE gedcom_id=?")
+ WT_DB::prepare("SELECT gedcom_name FROM ##gedcom WHERE gedcom_id=?")
->execute(array($ged_id))
->fetchOne();
}
@@ -2278,8 +2166,6 @@ function get_gedcom_from_id($ged_id) {
// Convert an (external) gedcom name to an (internal) gedcom ID.
// Optionally create an entry for it, if it does not exist.
function get_id_from_gedcom($ged_name, $create=false) {
- global $TBLPREFIX;
-
// No need to look up the default gedcom
if (defined('WT_GED_ID') && defined('WT_GEDCOM') && $ged_name==WT_GEDCOM) {
return WT_GED_ID;
@@ -2287,7 +2173,7 @@ function get_id_from_gedcom($ged_name, $create=false) {
if ($create) {
try {
- WT_DB::prepare("INSERT INTO {$TBLPREFIX}gedcom (gedcom_name, import_gedcom, import_offset) VALUES (?, '', 0)")
+ WT_DB::prepare("INSERT INTO ##gedcom (gedcom_name, import_gedcom, import_offset) VALUES (?, '', 0)")
->execute(array($ged_name));
$ged_id=WT_DB::getInstance()->lastInsertId();
require WT_ROOT.'includes/set_gedcom_defaults.php';
@@ -2298,7 +2184,7 @@ function get_id_from_gedcom($ged_name, $create=false) {
}
return
- WT_DB::prepare("SELECT gedcom_id FROM {$TBLPREFIX}gedcom WHERE gedcom_name=?")
+ WT_DB::prepare("SELECT gedcom_id FROM ##gedcom WHERE gedcom_name=?")
->execute(array($ged_name))
->fetchOne();
}
@@ -2309,22 +2195,18 @@ function get_id_from_gedcom($ged_name, $create=false) {
////////////////////////////////////////////////////////////////////////////////
function get_gedcom_setting($gedcom_id, $setting_name, $default_value=null) {
- global $TBLPREFIX;
-
return
WT_DB::prepare(
- "SELECT setting_value FROM {$TBLPREFIX}gedcom_setting WHERE gedcom_id=? AND setting_name=?"
+ "SELECT setting_value FROM ##gedcom_setting WHERE gedcom_id=? AND setting_name=?"
)->execute(array($gedcom_id, $setting_name))->fetchOne($default_value);
}
function set_gedcom_setting($ged_id, $setting_name, $setting_value) {
- global $TBLPREFIX;
-
if (is_null($setting_value)) {
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}gedcom_setting WHERE gedcom_id=? AND setting_name=?")
+ WT_DB::prepare("DELETE FROM ##gedcom_setting WHERE gedcom_id=? AND setting_name=?")
->execute(array($ged_id, $setting_name));
} else {
- WT_DB::prepare("REPLACE INTO {$TBLPREFIX}gedcom_setting (gedcom_id, setting_name, setting_value) VALUES (?, ?, ?)")
+ WT_DB::prepare("REPLACE INTO ##gedcom_setting (gedcom_id, setting_name, setting_value) VALUES (?, ?, ?)")
->execute(array($ged_id, $setting_name, $setting_value));
}
}
@@ -2334,58 +2216,50 @@ function set_gedcom_setting($ged_id, $setting_name, $setting_value) {
////////////////////////////////////////////////////////////////////////////////
function create_user($username, $realname, $email, $password) {
- global $TBLPREFIX;
-
try {
- WT_DB::prepare("INSERT INTO {$TBLPREFIX}user (user_name, real_name, email, password) VALUES (?, ?, ?, ?)")
+ WT_DB::prepare("INSERT INTO ##user (user_name, real_name, email, password) VALUES (?, ?, ?, ?)")
->execute(array($username, $realname, $email, $password));
} catch (PDOException $ex) {
// User already exists?
}
return
- WT_DB::prepare("SELECT user_id FROM {$TBLPREFIX}user WHERE user_name=?")
+ WT_DB::prepare("SELECT user_id FROM ##user WHERE user_name=?")
->execute(array($username))->fetchOne();
}
function rename_user($old_username, $new_username) {
- global $TBLPREFIX;
-
- WT_DB::prepare("UPDATE {$TBLPREFIX}user SET user_name=? WHERE user_name =?")->execute(array($new_username, $old_username));
- WT_DB::prepare("UPDATE {$TBLPREFIX}favorites SET fv_username=? WHERE fv_username=?")->execute(array($new_username, $old_username));
- WT_DB::prepare("UPDATE {$TBLPREFIX}news SET n_username =? WHERE n_username =?")->execute(array($new_username, $old_username));
+ WT_DB::prepare("UPDATE ##user SET user_name=? WHERE user_name =?")->execute(array($new_username, $old_username));
+ WT_DB::prepare("UPDATE ##favorites SET fv_username=? WHERE fv_username=?")->execute(array($new_username, $old_username));
+ WT_DB::prepare("UPDATE ##news SET n_username =? WHERE n_username =?")->execute(array($new_username, $old_username));
}
function delete_user($user_id) {
- global $TBLPREFIX;
-
$user_name=get_user_name($user_id);
- WT_DB::prepare("DELETE {$TBLPREFIX}block_setting FROM {$TBLPREFIX}block_setting JOIN {$TBLPREFIX}block USING (block_id) WHERE user_id=?")->execute(array($user_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}block WHERE user_id=?" )->execute(array($user_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}user_gedcom_setting WHERE user_id=?" )->execute(array($user_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}user_setting WHERE user_id=?" )->execute(array($user_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}message WHERE user_id=?" )->execute(array($user_name, $user_name));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}user WHERE user_id=?" )->execute(array($user_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}favorites WHERE fv_username=?")->execute(array($user_name));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}news WHERE n_username =?")->execute(array($user_name));
+ WT_DB::prepare("DELETE ##block_setting FROM ##block_setting JOIN ##block USING (block_id) WHERE user_id=?")->execute(array($user_id));
+ WT_DB::prepare("DELETE FROM ##block WHERE user_id=?" )->execute(array($user_id));
+ WT_DB::prepare("DELETE FROM ##user_gedcom_setting WHERE user_id=?" )->execute(array($user_id));
+ WT_DB::prepare("DELETE FROM ##user_setting WHERE user_id=?" )->execute(array($user_id));
+ WT_DB::prepare("DELETE FROM ##message WHERE user_id=?" )->execute(array($user_name, $user_name));
+ WT_DB::prepare("DELETE FROM ##user WHERE user_id=?" )->execute(array($user_id));
+ WT_DB::prepare("DELETE FROM ##favorites WHERE fv_username=?")->execute(array($user_name));
+ WT_DB::prepare("DELETE FROM ##news WHERE n_username =?")->execute(array($user_name));
}
function get_all_users($order='ASC', $key='realname') {
- global $TBLPREFIX;
-
if ($key=='username') {
return
- WT_DB::prepare("SELECT user_id, user_name FROM {$TBLPREFIX}user ORDER BY user_name")
+ WT_DB::prepare("SELECT user_id, user_name FROM ##user ORDER BY user_name")
->fetchAssoc();
} elseif ($key=='realname') {
return
- WT_DB::prepare("SELECT user_id, user_name FROM {$TBLPREFIX}user ORDER BY real_name")
+ WT_DB::prepare("SELECT user_id, user_name FROM ##user ORDER BY real_name")
->fetchAssoc();
} else {
return
WT_DB::prepare(
"SELECT u.user_id, user_name".
- " FROM {$TBLPREFIX}user u".
- " LEFT JOIN {$TBLPREFIX}user_setting us1 ON (u.user_id=us1.user_id AND us1.setting_name=?)".
+ " FROM ##user u".
+ " LEFT JOIN ##user_setting us1 ON (u.user_id=us1.user_id AND us1.setting_name=?)".
" ORDER BY us1.setting_value {$order}"
)->execute(array($key))
->fetchAssoc();
@@ -2393,40 +2267,32 @@ function get_all_users($order='ASC', $key='realname') {
}
function get_user_count() {
- global $TBLPREFIX;
-
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}user")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##user")
->fetchOne();
}
function get_admin_user_count() {
- global $TBLPREFIX;
-
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}user_setting WHERE setting_name=? AND setting_value=?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##user_setting WHERE setting_name=? AND setting_value=?")
->execute(array('canadmin', 'Y'))
->fetchOne();
}
function get_non_admin_user_count() {
- global $TBLPREFIX;
-
return
- WT_DB::prepare("SELECT COUNT(*) FROM {$TBLPREFIX}user_setting WHERE setting_name=? AND setting_value<>?")
+ WT_DB::prepare("SELECT COUNT(*) FROM ##user_setting WHERE setting_name=? AND setting_value<>?")
->execute(array('canadmin', 'Y'))
->fetchOne();
}
// Get a list of logged-in users
function get_logged_in_users() {
- global $TBLPREFIX;
-
return
WT_DB::prepare(
"SELECT u.user_id, user_name".
- " FROM {$TBLPREFIX}user u".
- " JOIN {$TBLPREFIX}user_setting us USING (user_id)".
+ " FROM ##user u".
+ " JOIN ##user_setting us USING (user_id)".
" WHERE setting_name=? AND setting_value=?"
)
->execute(array('loggedin', 'Y'))
@@ -2435,26 +2301,14 @@ function get_logged_in_users() {
// Get a list of logged-in users who haven't been active recently
function get_idle_users($time) {
- global $TBLPREFIX, $DBTYPE;
-
- // Convert string column to numeric
- switch ($DBTYPE) {
- case 'mysql':
- $expr='CAST(us2.setting_value AS UNSIGNED)';
- break;
- default:
- $expr='us2.setting_value';
- break;
- }
-
return
WT_DB::prepare(
"SELECT u.user_id, user_name".
- " FROM {$TBLPREFIX}user u".
- " JOIN {$TBLPREFIX}user_setting us1 USING (user_id)".
- " JOIN {$TBLPREFIX}user_setting us2 USING (user_id)".
+ " FROM ##user u".
+ " JOIN ##user_setting us1 USING (user_id)".
+ " JOIN ##user_setting us2 USING (user_id)".
" WHERE us1.setting_name=? AND us1.setting_value=? AND us2.setting_name=?".
- " AND {$expr} BETWEEN 1 AND ?"
+ " AND CAST(us2.setting_value AS UNSIGNED) BETWEEN 1 AND ?"
)
->execute(array('loggedin', 'Y', 'sessiontime', $time))
->fetchAssoc();
@@ -2462,29 +2316,23 @@ function get_idle_users($time) {
// Get the ID for a username
function get_user_id($username) {
- global $TBLPREFIX;
-
- return WT_DB::prepare("SELECT user_id FROM {$TBLPREFIX}user WHERE user_name=?")
+ return WT_DB::prepare("SELECT user_id FROM ##user WHERE user_name=?")
->execute(array($username))
->fetchOne();
}
// Get the username for a user ID
function get_user_name($user_id) {
- global $TBLPREFIX;
-
- return WT_DB::prepare("SELECT user_name FROM {$TBLPREFIX}user WHERE user_id=?")
+ return WT_DB::prepare("SELECT user_name FROM ##user WHERE user_id=?")
->execute(array($user_id))
->fetchOne();
}
function get_newest_registered_user() {
- global $TBLPREFIX;
-
return WT_DB::prepareLimit(
"SELECT u.user_id".
- " FROM {$TBLPREFIX}user u".
- " LEFT JOIN {$TBLPREFIX}user_setting us ON (u.user_id=us.user_id AND us.setting_name=?) ".
+ " FROM ##user u".
+ " LEFT JOIN ##user_setting us ON (u.user_id=us.user_id AND us.setting_name=?) ".
" ORDER BY us.setting_value DESC",
1
)->execute(array('reg_timestamp'))
@@ -2492,16 +2340,12 @@ function get_newest_registered_user() {
}
function set_user_password($user_id, $password) {
- global $TBLPREFIX;
-
- WT_DB::prepare("UPDATE {$TBLPREFIX}user SET password=? WHERE user_id=?")
+ WT_DB::prepare("UPDATE ##user SET password=? WHERE user_id=?")
->execute(array($password, $user_id));
}
function get_user_password($user_id) {
- global $TBLPREFIX;
-
- return WT_DB::prepare("SELECT password FROM {$TBLPREFIX}user WHERE user_id=?")
+ return WT_DB::prepare("SELECT password FROM ##user WHERE user_id=?")
->execute(array($user_id))
->fetchOne();
}
@@ -2511,22 +2355,18 @@ function get_user_password($user_id) {
////////////////////////////////////////////////////////////////////////////////
function get_user_setting($user_id, $setting_name, $default_value=null) {
- global $TBLPREFIX;
-
return
WT_DB::prepare(
- "SELECT setting_value FROM {$TBLPREFIX}user_setting WHERE user_id=? AND setting_name=?"
+ "SELECT setting_value FROM ##user_setting WHERE user_id=? AND setting_name=?"
)->execute(array($user_id, $setting_name))->fetchOne($default_value);
}
function set_user_setting($user_id, $setting_name, $setting_value) {
- global $TBLPREFIX;
-
if (is_null($setting_value)) {
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}user_setting WHERE user_id=? AND setting_name=?")
+ WT_DB::prepare("DELETE FROM ##user_setting WHERE user_id=? AND setting_name=?")
->execute(array($user_id, $setting_name));
} else {
- WT_DB::prepare("REPLACE INTO {$TBLPREFIX}user_setting (user_id, setting_name, setting_value) VALUES (?, ?, ?)")
+ WT_DB::prepare("REPLACE INTO ##user_setting (user_id, setting_name, setting_value) VALUES (?, ?, ?)")
->execute(array($user_id, $setting_name, $setting_value));
}
}
@@ -2540,32 +2380,26 @@ function admin_user_exists() {
////////////////////////////////////////////////////////////////////////////////
function get_user_gedcom_setting($user_id, $gedcom_id, $setting_name, $default_value=null) {
- global $TBLPREFIX;
-
return
WT_DB::prepare(
- "SELECT setting_value FROM {$TBLPREFIX}user_gedcom_setting WHERE user_id=? AND gedcom_id=? AND setting_name=?"
+ "SELECT setting_value FROM ##user_gedcom_setting WHERE user_id=? AND gedcom_id=? AND setting_name=?"
)->execute(array($user_id, $gedcom_id, $setting_name))->fetchOne($default_value);
}
function set_user_gedcom_setting($user_id, $ged_id, $setting_name, $setting_value) {
- global $TBLPREFIX;
-
if (is_null($setting_value)) {
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}user_gedcom_setting WHERE user_id=? AND gedcom_id=? AND setting_name=?")
+ WT_DB::prepare("DELETE FROM ##user_gedcom_setting WHERE user_id=? AND gedcom_id=? AND setting_name=?")
->execute(array($user_id, $ged_id, $setting_name));
} else {
- WT_DB::prepare("REPLACE INTO {$TBLPREFIX}user_gedcom_setting (user_id, gedcom_id, setting_name, setting_value) VALUES (?, ?, ?, ?)")
+ WT_DB::prepare("REPLACE INTO ##user_gedcom_setting (user_id, gedcom_id, setting_name, setting_value) VALUES (?, ?, ?, ?)")
->execute(array($user_id, $ged_id, $setting_name, $setting_value));
}
}
function get_user_from_gedcom_xref($ged_id, $xref) {
- global $TBLPREFIX;
-
return
WT_DB::prepare(
- "SELECT user_id FROM {$TBLPREFIX}user_gedcom_setting".
+ "SELECT user_id FROM ##user_gedcom_setting".
" WHERE gedcom_id=? AND setting_name=? AND setting_value=?"
)->execute(array($ged_id, 'gedcomid', $xref))->fetchOne();
}
@@ -2575,12 +2409,10 @@ function get_user_from_gedcom_xref($ged_id, $xref) {
////////////////////////////////////////////////////////////////////////////////
function get_user_blocks($user_id) {
- global $TBLPREFIX;
-
$blocks=array('main'=>array(), 'side'=>array());
$rows=WT_DB::prepare(
"SELECT location, block_id, module_name".
- " FROM {$TBLPREFIX}block".
+ " FROM ##block".
" WHERE user_id=?".
" ORDER BY location, block_order"
)->execute(array($user_id))->fetchAll();
@@ -2591,7 +2423,7 @@ function get_user_blocks($user_id) {
return $blocks;
} else {
WT_DB::prepare(
- "REPLACE INTO {$TBLPREFIX}block (user_id, location, block_order, module_name) VALUES ".
+ "REPLACE INTO ##block (user_id, location, block_order, module_name) VALUES ".
"(?, 'main', 0, 'todays_events'),".
"(?, 'main', 1, 'user_messages'),".
"(?, 'main', 2, 'user_favorites'),".
@@ -2605,12 +2437,10 @@ function get_user_blocks($user_id) {
}
function get_gedcom_blocks($gedcom_id) {
- global $TBLPREFIX;
-
$blocks=array('main'=>array(), 'side'=>array());
$rows=WT_DB::prepare(
"SELECT location, block_id, module_name".
- " FROM {$TBLPREFIX}block".
+ " FROM ##block".
" WHERE gedcom_id=?".
" ORDER BY location, block_order"
)->execute(array($gedcom_id))->fetchAll();
@@ -2621,7 +2451,7 @@ function get_gedcom_blocks($gedcom_id) {
return $blocks;
} else {
WT_DB::prepare(
- "REPLACE INTO {$TBLPREFIX}block (gedcom_id, location, block_order, module_name) VALUES ".
+ "REPLACE INTO ##block (gedcom_id, location, block_order, module_name) VALUES ".
"(?, 'main', 0, 'gedcom_stats'),".
"(?, 'main', 1, 'gedcom_news'),".
"(?, 'main', 2, 'gedcom_favorites'),".
@@ -2636,44 +2466,36 @@ function get_gedcom_blocks($gedcom_id) {
}
function get_block_setting($block_id, $setting_name, $default_value=null) {
- global $TBLPREFIX;
-
return
WT_DB::prepare(
- "SELECT setting_value FROM {$TBLPREFIX}block_setting WHERE block_id=? AND setting_name=?"
+ "SELECT setting_value FROM ##block_setting WHERE block_id=? AND setting_name=?"
)->execute(array($block_id, $setting_name))->fetchOne($default_value);
}
function set_block_setting($block_id, $setting_name, $setting_value) {
- global $TBLPREFIX;
-
if (is_null($setting_value)) {
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}block_setting WHERE block_id=? AND setting_name=?")
+ WT_DB::prepare("DELETE FROM ##block_setting WHERE block_id=? AND setting_name=?")
->execute(array($block_id, $setting_name));
} else {
- WT_DB::prepare("REPLACE INTO {$TBLPREFIX}block_setting (block_id, setting_name, setting_value) VALUES (?, ?, ?)")
+ WT_DB::prepare("REPLACE INTO ##block_setting (block_id, setting_name, setting_value) VALUES (?, ?, ?)")
->execute(array($block_id, $setting_name, $setting_value));
}
}
function get_module_setting($module_name, $setting_name, $default_value=null) {
- global $TBLPREFIX;
-
return
WT_DB::prepare(
- "SELECT setting_value FROM {$TBLPREFIX}module_setting WHERE module_name=? AND setting_name=?"
+ "SELECT setting_value FROM ##module_setting WHERE module_name=? AND setting_name=?"
)->execute(array($module_name, $setting_name))->fetchOne($default_value);
}
function set_module_setting($module_name, $setting_name, $setting_value) {
- global $TBLPREFIX;
-
if (is_null($setting_value)) {
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}module_setting WHERE module_name=? AND setting_name=?")
+ WT_DB::prepare("DELETE FROM ##module_setting WHERE module_name=? AND setting_name=?")
->execute(array($module_name, $setting_name));
} else {
- WT_DB::prepare("REPLACE INTO {$TBLPREFIX}module_setting (module_name, setting_name, setting_value) VALUES (?, ?, ?)")
+ WT_DB::prepare("REPLACE INTO ##module_setting (module_name, setting_name, setting_value) VALUES (?, ?, ?)")
->execute(array($module_name, $setting_name, $setting_value));
}
}
@@ -2686,12 +2508,10 @@ function set_module_setting($module_name, $setting_name, $setting_value) {
* @param string $ged_id gedcom to update
*/
function update_favorites($xref_from, $xref_to, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
-$ged_name=get_gedcom_from_id($ged_id);
+ $ged_name=get_gedcom_from_id($ged_id);
return
- WT_DB::prepare("UPDATE {$TBLPREFIX}favorites SET fv_gid=? WHERE fv_gid=? AND fv_file=?")
+ WT_DB::prepare("UPDATE ##favorites SET fv_gid=? WHERE fv_gid=? AND fv_file=?")
->execute(array($xref_to, $xref_from, $ged_name))
->rowCount();
}
@@ -2700,12 +2520,10 @@ $ged_name=get_gedcom_from_id($ged_id);
////////////////////////////////////////////////////////////////////////////////
function get_autocomplete_INDI($FILTER, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
// search for ids first and request the exact id from FILTER and ids with one additional digit
$sql=
"SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex".
- " FROM {$TBLPREFIX}individuals, {$TBLPREFIX}name".
+ " FROM ##individuals, ##name".
" WHERE (i_id=? OR i_id LIKE ?)".
" AND i_id=n_id AND i_file=n_file AND i_file=?".
" ORDER BY i_id";
@@ -2717,7 +2535,7 @@ function get_autocomplete_INDI($FILTER, $ged_id=WT_GED_ID) {
if (count($rows) ==0) {
$sql=
"SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex".
- " FROM {$TBLPREFIX}individuals, {$TBLPREFIX}name".
+ " FROM ##individuals, ##name".
" WHERE n_sort LIKE ?".
" AND i_id=n_id AND i_file=n_file AND i_file=?".
" ORDER BY n_sort";
@@ -2732,8 +2550,6 @@ function get_autocomplete_INDI($FILTER, $ged_id=WT_GED_ID) {
}
function get_autocomplete_FAM($FILTER, $ids, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
$vars=array();
if (empty($ids)) {
//-- no match : search for FAM id
@@ -2746,7 +2562,7 @@ function get_autocomplete_FAM($FILTER, $ids, $ged_id=WT_GED_ID) {
$vars=array_merge($vars, $ids, $ids);
}
$sql="SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil ".
- "FROM {$TBLPREFIX}families ".
+ "FROM ##families ".
"WHERE {$where} AND f_file=?";
$vars[]=$ged_id;
return
@@ -2756,10 +2572,8 @@ function get_autocomplete_FAM($FILTER, $ids, $ged_id=WT_GED_ID) {
}
function get_autocomplete_NOTE($FILTER, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
$sql="SELECT o_type AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec ".
- "FROM {$TBLPREFIX}other ".
+ "FROM ##other ".
"WHERE o_gedcom LIKE ? AND o_type='NOTE' AND o_file=?";
return
WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT)
@@ -2768,10 +2582,8 @@ function get_autocomplete_NOTE($FILTER, $ged_id=WT_GED_ID) {
}
function get_autocomplete_SOUR($FILTER, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
$sql="SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec ".
- "FROM {$TBLPREFIX}sources ".
+ "FROM ##sources ".
"WHERE (s_name LIKE ? OR s_id LIKE ?) AND s_file=? ORDER BY s_name";
return
WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT)
@@ -2780,10 +2592,8 @@ function get_autocomplete_SOUR($FILTER, $ged_id=WT_GED_ID) {
}
function get_autocomplete_SOUR_TITL($FILTER, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
$sql="SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec ".
- "FROM {$TBLPREFIX}sources ".
+ "FROM ##sources ".
"WHERE s_name LIKE ? AND s_file=? ORDER BY s_name";
return
WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT)
@@ -2792,11 +2602,9 @@ function get_autocomplete_SOUR_TITL($FILTER, $ged_id=WT_GED_ID) {
}
function get_autocomplete_INDI_BURI_CEME($FILTER, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
$sql=
"SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex ".
- "FROM {$TBLPREFIX}individuals ".
+ "FROM ##individuals ".
"WHERE i_gedcom LIKE ? AND i_file=?";
return
WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT)
@@ -2805,10 +2613,8 @@ function get_autocomplete_INDI_BURI_CEME($FILTER, $ged_id=WT_GED_ID) {
}
function get_autocomplete_INDI_SOUR_PAGE($FILTER, $OPTION, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
$sql="SELECT 'INDI' AS type, i_id AS xref, i_file AS ged_id, i_gedcom AS gedrec, i_isdead, i_sex ".
- "FROM {$TBLPREFIX}individuals ".
+ "FROM ##individuals ".
"WHERE i_gedcom LIKE ? AND i_file=?";
return
WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT)
@@ -2817,11 +2623,9 @@ function get_autocomplete_INDI_SOUR_PAGE($FILTER, $OPTION, $ged_id=WT_GED_ID) {
}
function get_autocomplete_FAM_SOUR_PAGE($FILTER, $OPTION, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
$sql=
"SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil ".
- "FROM {$TBLPREFIX}families ".
+ "FROM ##families ".
"WHERE f_gedcom LIKE ? AND f_file=?";
return
WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT)
@@ -2830,11 +2634,9 @@ function get_autocomplete_FAM_SOUR_PAGE($FILTER, $OPTION, $ged_id=WT_GED_ID) {
}
function get_autocomplete_REPO($FILTER, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
$sql=
"SELECT o_type AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec ".
- "FROM {$TBLPREFIX}other ".
+ "FROM ##other ".
"WHERE (o_gedcom LIKE ? OR o_id LIKE ?) AND o_file=? AND o_type='REPO'";
return
WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT)
@@ -2843,11 +2645,9 @@ function get_autocomplete_REPO($FILTER, $ged_id=WT_GED_ID) {
}
function get_autocomplete_REPO_NAME($FILTER, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
$sql=
"SELECT o_type AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec ".
- "FROM {$TBLPREFIX}other ".
+ "FROM ##other ".
"WHERE o_gedcom LIKE ? AND o_file=? AND o_type='REPO'";
return
WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT)
@@ -2856,10 +2656,8 @@ function get_autocomplete_REPO_NAME($FILTER, $ged_id=WT_GED_ID) {
}
function get_autocomplete_OBJE($FILTER, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
$sql="SELECT m_media ".
- "FROM {$TBLPREFIX}media ".
+ "FROM ##media ".
"WHERE (m_titl LIKE ? OR m_media LIKE ?) AND m_gedfile=?";
return
WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT)
@@ -2868,10 +2666,8 @@ function get_autocomplete_OBJE($FILTER, $ged_id=WT_GED_ID) {
}
function get_autocomplete_SURN($FILTER, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
$sql="SELECT DISTINCT n_surname ".
- "FROM {$TBLPREFIX}name ".
+ "FROM ##name ".
"WHERE n_surname LIKE ? AND n_file=? ORDER BY n_surname";
return
WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT)
@@ -2880,10 +2676,8 @@ function get_autocomplete_SURN($FILTER, $ged_id=WT_GED_ID) {
}
function get_autocomplete_GIVN($FILTER, $ged_id=WT_GED_ID) {
- global $TBLPREFIX;
-
$sql="SELECT DISTINCT n_givn ".
- "FROM {$TBLPREFIX}name ".
+ "FROM ##name ".
"WHERE n_givn LIKE ? AND n_file=? ORDER BY n_givn";
return
WT_DB::prepareLimit($sql, WT_AUTOCOMPLETE_LIMIT)
@@ -2892,37 +2686,35 @@ function get_autocomplete_GIVN($FILTER, $ged_id=WT_GED_ID) {
}
function get_autocomplete_PLAC($FILTER, $ged_id=WT_GED_ID) {
- global $TBLPREFIX, $DBTYPE;
-
$sql=
"select p1.p_place".
- " from {$TBLPREFIX}places p1".
+ " from ##places p1".
" where p1.p_place like ? and p1.p_parent_id=0 AND p1.p_file=?".
" union ".
"select CONCAT(p1.p_place, ', ', p2.p_place)".
- " from {$TBLPREFIX}places p1".
- " join {$TBLPREFIX}places p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)".
+ " from ##places p1".
+ " join ##places p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)".
" where p1.p_place like ? and p2.p_parent_id=0 AND p1.p_file=?".
" union ".
"select CONCAT(p1.p_place, ', ', p2.p_place, ', ', p3.p_place)".
- " from {$TBLPREFIX}places p1".
- " join {$TBLPREFIX}places p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)".
- " join {$TBLPREFIX}places p3 ON (p2.p_parent_id=p3.p_id AND p2.p_file=p3.p_file)".
+ " from ##places p1".
+ " join ##places p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)".
+ " join ##places p3 ON (p2.p_parent_id=p3.p_id AND p2.p_file=p3.p_file)".
" where p1.p_place like ? and p3.p_parent_id=0 AND p1.p_file=?".
" union ".
"select CONCAT(p1.p_place, ', ', p2.p_place, ', ', p3.p_place, ', ', p4.p_place)".
- " from {$TBLPREFIX}places p1".
- " join {$TBLPREFIX}places p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)".
- " join {$TBLPREFIX}places p3 ON (p2.p_parent_id=p3.p_id AND p2.p_file=p3.p_file)".
- " join {$TBLPREFIX}places p4 ON (p3.p_parent_id=p4.p_id AND p3.p_file=p4.p_file)".
+ " from ##places p1".
+ " join ##places p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)".
+ " join ##places p3 ON (p2.p_parent_id=p3.p_id AND p2.p_file=p3.p_file)".
+ " join ##places p4 ON (p3.p_parent_id=p4.p_id AND p3.p_file=p4.p_file)".
" where p1.p_place like ? and p4.p_parent_id=0 AND p1.p_file=?".
" union ".
"select CONCAT(p1.p_place, ', ', p2.p_place, ', ', p3.p_place, ', ', p4.p_place, ', ', p5.p_place)".
- " from {$TBLPREFIX}places p1".
- " join {$TBLPREFIX}places p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)".
- " join {$TBLPREFIX}places p3 ON (p2.p_parent_id=p3.p_id AND p2.p_file=p3.p_file)".
- " join {$TBLPREFIX}places p4 ON (p3.p_parent_id=p4.p_id AND p3.p_file=p4.p_file)".
- " join {$TBLPREFIX}places p5 ON (p4.p_parent_id=p5.p_id AND p4.p_file=p5.p_file)".
+ " from ##places p1".
+ " join ##places p2 ON (p1.p_parent_id=p2.p_id AND p1.p_file=p2.p_file)".
+ " join ##places p3 ON (p2.p_parent_id=p3.p_id AND p2.p_file=p3.p_file)".
+ " join ##places p4 ON (p3.p_parent_id=p4.p_id AND p3.p_file=p4.p_file)".
+ " join ##places p5 ON (p4.p_parent_id=p5.p_id AND p4.p_file=p5.p_file)".
" where p1.p_place like ? and p5.p_parent_id=0 AND p1.p_file=?";
return
diff --git a/includes/functions/functions_edit.php b/includes/functions/functions_edit.php
index aec8af77c9..6868605ed8 100644
--- a/includes/functions/functions_edit.php
+++ b/includes/functions/functions_edit.php
@@ -205,12 +205,10 @@ function newConnection() {
* @param string $pid The gedcom id of the record to check
*/
function checkChangeTime($pid, $gedrec, $last_time) {
- global $TBLPREFIX;
-
$change=WT_DB::prepare(
"SELECT UNIX_TIMESTAMP(change_time) AS change_time, user_name".
- " FROM {$TBLPREFIX}change".
- " JOIN {$TBLPREFIX}user USING (user_id)".
+ " FROM ##change".
+ " JOIN ##user USING (user_id)".
" WHERE status<>'rejected' AND gedcom_id=? AND xref=? AND change_time>?".
" ORDER BY change_id DESC".
" LIMIT 1"
@@ -240,7 +238,7 @@ function checkChangeTime($pid, $gedrec, $last_time) {
* @param boolean $chan Whether or not to update/add the CHAN record
*/
function replace_gedrec($gid, $ged_id, $gedrec, $chan=true) {
- global $TBLPREFIX, $pgv_private_records;
+ global $pgv_private_records;
//-- restore any data that was hidden during privatizing
if (isset($pgv_private_records[$gid])) {
@@ -272,7 +270,7 @@ function replace_gedrec($gid, $ged_id, $gedrec, $chan=true) {
$old_gedrec=find_gedcom_record($gid, $ged_id, true);
if ($old_gedrec!=$gedrec) {
WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}change (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, ?, ?, ?)"
+ "INSERT INTO ##change (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, ?, ?, ?)"
)->execute(array(
$ged_id,
$gid,
@@ -293,8 +291,6 @@ function replace_gedrec($gid, $ged_id, $gedrec, $chan=true) {
//-- this function will append a new gedcom record at
//-- the end of the gedcom file.
function append_gedrec($gedrec, $ged_id) {
- global $TBLPREFIX;
-
if (($gedrec = check_gedcom($gedrec, true))!==false && preg_match("/0 @(".WT_REGEX_XREF.")@ (".WT_REGEX_TAG.")/", $gedrec, $match)) {
$gid = $match[1];
$type = $match[2];
@@ -307,7 +303,7 @@ function append_gedrec($gedrec, $ged_id) {
$gedrec=preg_replace("/^0 @(.*)@/", "0 @$xref@", $gedrec);
WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}change (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, ?, ?, ?)"
+ "INSERT INTO ##change (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, ?, ?, ?)"
)->execute(array(
$ged_id,
$xref,
@@ -329,10 +325,8 @@ function append_gedrec($gedrec, $ged_id) {
//-- this function will delete the gedcom record with
//-- the given $xref
function delete_gedrec($xref, $ged_id) {
- global $TBLPREFIX;
-
WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}change (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, ?, ?, ?)"
+ "INSERT INTO ##change (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, ?, ?, ?)"
)->execute(array(
$ged_id,
$xref,
diff --git a/includes/functions/functions_export.php b/includes/functions/functions_export.php
index c6177fa312..f62d9c7206 100644
--- a/includes/functions/functions_export.php
+++ b/includes/functions/functions_export.php
@@ -99,8 +99,6 @@ function reformat_record_export($rec) {
* Create a header for a (newly-created or already-imported) gedcom file.
*/
function gedcom_header($gedfile) {
- global $TBLPREFIX;
-
$ged_id=get_id_from_gedcom($gedfile);
// Default values for a new header
@@ -137,14 +135,14 @@ function gedcom_header($gedfile) {
}
// Link to SUBM/SUBN records, if they exist
$subn=
- WT_DB::prepare("SELECT o_id FROM {$TBLPREFIX}other WHERE o_type=? AND o_file=?")
+ WT_DB::prepare("SELECT o_id FROM ##other WHERE o_type=? AND o_file=?")
->execute(array('SUBN', $ged_id))
->fetchOne();
if ($subn) {
$SUBN="\n1 SUBN @{$subn}@";
}
$subm=
- WT_DB::prepare("SELECT o_id FROM {$TBLPREFIX}other WHERE o_type=? AND o_file=?")
+ WT_DB::prepare("SELECT o_id FROM ##other WHERE o_type=? AND o_file=?")
->execute(array('SUBM', $ged_id))
->fetchOne();
if ($subm) {
@@ -258,7 +256,7 @@ function convert_media_path($rec, $path, $slashes) {
* 'slashes': what folder separators apply to media file paths? (forward, backward)
*/
function export_gedcom($gedcom, $gedout, $exportOptions) {
- global $GEDCOM, $TBLPREFIX;
+ global $GEDCOM;
// Temporarily switch to the specified GEDCOM
$oldGEDCOM = $GEDCOM;
@@ -286,7 +284,7 @@ function export_gedcom($gedcom, $gedout, $exportOptions) {
$buffer=reformat_record_export($head);
$recs=
- WT_DB::prepare("SELECT i_gedcom FROM {$TBLPREFIX}individuals WHERE i_file=? AND i_id NOT LIKE ? ORDER BY i_id")
+ WT_DB::prepare("SELECT i_gedcom FROM ##individuals WHERE i_file=? AND i_id NOT LIKE ? ORDER BY i_id")
->execute(array($ged_id, '%:%'))
->fetchOneColumn();
foreach ($recs as $rec) {
@@ -301,7 +299,7 @@ function export_gedcom($gedcom, $gedout, $exportOptions) {
}
$recs=
- WT_DB::prepare("SELECT f_gedcom FROM {$TBLPREFIX}families WHERE f_file=? AND f_id NOT LIKE ? ORDER BY f_id")
+ WT_DB::prepare("SELECT f_gedcom FROM ##families WHERE f_file=? AND f_id NOT LIKE ? ORDER BY f_id")
->execute(array($ged_id, '%:%'))
->fetchOneColumn();
foreach ($recs as $rec) {
@@ -316,7 +314,7 @@ function export_gedcom($gedcom, $gedout, $exportOptions) {
}
$recs=
- WT_DB::prepare("SELECT s_gedcom FROM {$TBLPREFIX}sources WHERE s_file=? AND s_id NOT LIKE ? ORDER BY s_id")
+ WT_DB::prepare("SELECT s_gedcom FROM ##sources WHERE s_file=? AND s_id NOT LIKE ? ORDER BY s_id")
->execute(array($ged_id, '%:%'))
->fetchOneColumn();
foreach ($recs as $rec) {
@@ -331,7 +329,7 @@ function export_gedcom($gedcom, $gedout, $exportOptions) {
}
$recs=
- WT_DB::prepare("SELECT o_gedcom FROM {$TBLPREFIX}other WHERE o_file=? AND o_id NOT LIKE ? AND o_type!=? AND o_type!=? ORDER BY o_id")
+ WT_DB::prepare("SELECT o_gedcom FROM ##other WHERE o_file=? AND o_id NOT LIKE ? AND o_type!=? AND o_type!=? ORDER BY o_id")
->execute(array($ged_id, '%:%', 'HEAD', 'TRLR'))
->fetchOneColumn();
foreach ($recs as $rec) {
@@ -346,7 +344,7 @@ function export_gedcom($gedcom, $gedout, $exportOptions) {
}
$recs=
- WT_DB::prepare("SELECT m_gedrec FROM {$TBLPREFIX}media WHERE m_gedfile=? AND m_media NOT LIKE ? ORDER BY m_media")
+ WT_DB::prepare("SELECT m_gedrec FROM ##media WHERE m_gedfile=? AND m_media NOT LIKE ? ORDER BY m_media")
->execute(array($ged_id, '%:%'))
->fetchOneColumn();
foreach ($recs as $rec) {
@@ -387,7 +385,6 @@ function export_gedcom($gedcom, $gedout, $exportOptions) {
*/
function export_gramps($gedcom, $gedout, $exportOptions) {
global $GEDCOM;
- global $TBLPREFIX;
// Temporarily switch to the specified GEDCOM
$oldGEDCOM = $GEDCOM;
@@ -408,7 +405,7 @@ function export_gramps($gedcom, $gedout, $exportOptions) {
$geDownloadGedcom->begin_xml();
$recs=
- WT_DB::prepare("SELECT i_id, i_gedcom FROM {$TBLPREFIX}individuals WHERE i_file=? AND i_id NOT LIKE ? ORDER BY i_id")
+ WT_DB::prepare("SELECT i_id, i_gedcom FROM ##individuals WHERE i_file=? AND i_id NOT LIKE ? ORDER BY i_id")
->execute(array($ged_id, '%:%'))
->fetchAssoc();
foreach ($recs as $id=>$rec) {
@@ -418,7 +415,7 @@ function export_gramps($gedcom, $gedout, $exportOptions) {
}
$recs=
- WT_DB::prepare("SELECT f_id, f_gedcom FROM {$TBLPREFIX}families WHERE f_file=? AND f_id NOT LIKE ? ORDER BY f_id")
+ WT_DB::prepare("SELECT f_id, f_gedcom FROM ##families WHERE f_file=? AND f_id NOT LIKE ? ORDER BY f_id")
->execute(array($ged_id, '%:%'))
->fetchAssoc();
foreach ($recs as $id=>$rec) {
@@ -428,7 +425,7 @@ function export_gramps($gedcom, $gedout, $exportOptions) {
}
$recs=
- WT_DB::prepare("SELECT s_id, s_gedcom FROM {$TBLPREFIX}sources WHERE s_file=? AND s_id NOT LIKE ? ORDER BY s_id")
+ WT_DB::prepare("SELECT s_id, s_gedcom FROM ##sources WHERE s_file=? AND s_id NOT LIKE ? ORDER BY s_id")
->execute(array($ged_id, '%:%'))
->fetchAssoc();
foreach ($recs as $id=>$rec) {
@@ -438,7 +435,7 @@ function export_gramps($gedcom, $gedout, $exportOptions) {
}
$recs=
- WT_DB::prepare("SELECT m_media, m_gedrec FROM {$TBLPREFIX}media WHERE m_gedfile=? AND m_media NOT LIKE ? ORDER BY m_media")
+ WT_DB::prepare("SELECT m_media, m_gedrec FROM ##media WHERE m_gedfile=? AND m_media NOT LIKE ? ORDER BY m_media")
->execute(array($ged_id, '%:%'))
->fetchAssoc();
foreach ($recs as $id=>$rec) {
diff --git a/includes/functions/functions_import.php b/includes/functions/functions_import.php
index bd99fcbf51..322e56c041 100644
--- a/includes/functions/functions_import.php
+++ b/includes/functions/functions_import.php
@@ -581,7 +581,7 @@ function reformat_record_import($rec) {
* @param boolean $update whether or not this is an updated record that has been accepted
*/
function import_record($gedrec, $ged_id, $update) {
- global $TBLPREFIX, $USE_RIN, $GENERATE_UIDS;
+ global $USE_RIN, $GENERATE_UIDS;
static $sql_insert_indi=null;
static $sql_insert_fam=null;
@@ -589,16 +589,16 @@ function import_record($gedrec, $ged_id, $update) {
static $sql_insert_other=null;
if (!$sql_insert_indi) {
$sql_insert_indi=WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}individuals (i_id, i_file, i_rin, i_isdead, i_sex, i_gedcom) VALUES (?,?,?,?,?,?)"
+ "INSERT INTO ##individuals (i_id, i_file, i_rin, i_isdead, i_sex, i_gedcom) VALUES (?,?,?,?,?,?)"
);
$sql_insert_fam=WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}families (f_id, f_file, f_husb, f_wife, f_chil, f_gedcom, f_numchil) VALUES (?,?,?,?,?,?,?)"
+ "INSERT INTO ##families (f_id, f_file, f_husb, f_wife, f_chil, f_gedcom, f_numchil) VALUES (?,?,?,?,?,?,?)"
);
$sql_insert_sour=WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}sources (s_id, s_file, s_name, s_gedcom, s_dbid) VALUES (?,?,?,?,?)"
+ "INSERT INTO ##sources (s_id, s_file, s_name, s_gedcom, s_dbid) VALUES (?,?,?,?,?)"
);
$sql_insert_other=WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}other (o_id, o_file, o_type, o_gedcom) VALUES (?,?,?,?)"
+ "INSERT INTO ##other (o_id, o_file, o_type, o_gedcom) VALUES (?,?,?,?)"
);
}
@@ -737,7 +737,7 @@ function import_record($gedrec, $ged_id, $update) {
* @param string $gedrec
*/
function update_places($gid, $ged_id, $gedrec) {
- global $placecache, $TBLPREFIX;
+ global $placecache;
static $sql_insert_placelinks=null;
static $sql_insert_places=null;
@@ -748,13 +748,13 @@ function update_places($gid, $ged_id, $gedrec) {
// Of course, there almost certainly are such places .....
// We need a better solution that attaches multiple names to single places
$sql_insert_placelinks=WT_DB::prepare(
- "INSERT IGNORE INTO {$TBLPREFIX}placelinks (pl_p_id, pl_gid, pl_file) VALUES (?,?,?)"
+ "INSERT IGNORE INTO ##placelinks (pl_p_id, pl_gid, pl_file) VALUES (?,?,?)"
);
$sql_insert_places=WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}places (p_id, p_place, p_level, p_parent_id, p_file, p_std_soundex, p_dm_soundex) VALUES (?,?,?,?,?,?,?)"
+ "INSERT INTO ##places (p_id, p_place, p_level, p_parent_id, p_file, p_std_soundex, p_dm_soundex) VALUES (?,?,?,?,?,?,?)"
);
$sql_select_places=WT_DB::prepare(
- "SELECT p_id FROM {$TBLPREFIX}places WHERE p_level=? AND p_file=? AND p_parent_id=? AND p_place LIKE ?"
+ "SELECT p_id FROM ##places WHERE p_level=? AND p_file=? AND p_parent_id=? AND p_place LIKE ?"
);
}
@@ -827,12 +827,10 @@ function update_places($gid, $ged_id, $gedrec) {
// extract all the dates from the given record and insert them into the database
function update_dates($xref, $ged_id, $gedrec) {
- global $TBLPREFIX;
-
static $sql_insert_date=null;
if (!$sql_insert_date) {
$sql_insert_date=WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}dates (d_day,d_month,d_mon,d_year,d_julianday1,d_julianday2,d_fact,d_gid,d_file,d_type) VALUES (?,?,?,?,?,?,?,?,?,?)"
+ "INSERT INTO ##dates (d_day,d_month,d_mon,d_year,d_julianday1,d_julianday2,d_fact,d_gid,d_file,d_type) VALUES (?,?,?,?,?,?,?,?,?,?)"
);
}
@@ -854,11 +852,9 @@ function update_dates($xref, $ged_id, $gedrec) {
// extract all the remote links from the given record and insert them into the database
function update_rlinks($xref, $ged_id, $gedrec) {
- global $TBLPREFIX;
-
static $sql_insert_rlink=null;
if (!$sql_insert_rlink) {
- $sql_insert_rlink=WT_DB::prepare("INSERT INTO {$TBLPREFIX}remotelinks (r_gid,r_linkid,r_file) VALUES (?,?,?)");
+ $sql_insert_rlink=WT_DB::prepare("INSERT INTO ##remotelinks (r_gid,r_linkid,r_file) VALUES (?,?,?)");
}
if (preg_match_all("/\n1 RFN (".WT_REGEX_XREF.')/', $gedrec, $matches, PREG_SET_ORDER)) {
@@ -875,11 +871,9 @@ function update_rlinks($xref, $ged_id, $gedrec) {
// extract all the links from the given record and insert them into the database
function update_links($xref, $ged_id, $gedrec) {
- global $TBLPREFIX;
-
static $sql_insert_link=null;
if (!$sql_insert_link) {
- $sql_insert_link=WT_DB::prepare("INSERT INTO {$TBLPREFIX}link (l_from,l_to,l_type,l_file) VALUES (?,?,?,?)");
+ $sql_insert_link=WT_DB::prepare("INSERT INTO ##link (l_from,l_to,l_type,l_file) VALUES (?,?,?,?)");
}
if (preg_match_all('/^\d+ ('.WT_REGEX_TAG.') @('.WT_REGEX_XREF.')@/m', $gedrec, $matches, PREG_SET_ORDER)) {
@@ -901,13 +895,11 @@ function update_links($xref, $ged_id, $gedrec) {
// extract all the names from the given record and insert them into the database
function update_names($xref, $ged_id, $record) {
- global $TBLPREFIX;
-
static $sql_insert_name_indi=null;
static $sql_insert_name_other=null;
if (!$sql_insert_name_indi) {
- $sql_insert_name_indi=WT_DB::prepare("INSERT INTO {$TBLPREFIX}name (n_file,n_id,n_num,n_type,n_sort,n_full,n_list,n_surname,n_surn,n_givn,n_soundex_givn_std,n_soundex_surn_std,n_soundex_givn_dm,n_soundex_surn_dm) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
- $sql_insert_name_other=WT_DB::prepare("INSERT INTO {$TBLPREFIX}name (n_file,n_id,n_num,n_type,n_sort,n_full,n_list) VALUES (?,?,?,?,?,?,?)");
+ $sql_insert_name_indi=WT_DB::prepare("INSERT INTO ##name (n_file,n_id,n_num,n_type,n_sort,n_full,n_list,n_surname,n_surn,n_givn,n_soundex_givn_std,n_soundex_surn_std,n_soundex_givn_dm,n_soundex_surn_dm) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
+ $sql_insert_name_other=WT_DB::prepare("INSERT INTO ##name (n_file,n_id,n_num,n_type,n_sort,n_full,n_list) VALUES (?,?,?,?,?,?,?)");
}
if ($record->getType()!='FAM' && $record->getXref()) {
@@ -944,16 +936,16 @@ function update_names($xref, $ged_id, $record) {
* @param int $count The count of OBJE records in the parent record
*/
function insert_media($objrec, $objlevel, $update, $gid, $ged_id, $count) {
- global $TBLPREFIX, $media_count, $found_ids;
+ global $media_count, $found_ids;
static $sql_insert_media=null;
static $sql_insert_media_mapping=null;
if (!$sql_insert_media) {
$sql_insert_media=WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}media (m_id, m_media, m_ext, m_titl, m_file, m_gedfile, m_gedrec) VALUES (?, ?, ?, ?, ?, ?, ?)"
+ "INSERT INTO ##media (m_id, m_media, m_ext, m_titl, m_file, m_gedfile, m_gedrec) VALUES (?, ?, ?, ?, ?, ?, ?)"
);
$sql_insert_media_mapping=WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}media_mapping (mm_id, mm_media, mm_gid, mm_order, mm_gedfile, mm_gedrec) VALUES (?, ?, ?, ?, ?, ?)"
+ "INSERT INTO ##media_mapping (mm_id, mm_media, mm_gid, mm_order, mm_gedfile, mm_gedrec) VALUES (?, ?, ?, ?, ?, ?)"
);
}
@@ -1008,12 +1000,12 @@ function insert_media($objrec, $objlevel, $update, $gid, $ged_id, $count) {
* @return string an updated record
*/
function update_media($gid, $ged_id, $gedrec, $update = false) {
- global $TBLPREFIX, $media_count, $found_ids, $zero_level_media, $keepmedia;
+ global $media_count, $found_ids, $zero_level_media, $keepmedia;
static $sql_insert_media=null;
if (!$sql_insert_media) {
$sql_insert_media=WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}media (m_id, m_media, m_ext, m_titl, m_file, m_gedfile, m_gedrec) VALUES (?, ?, ?, ?, ?, ?, ?)"
+ "INSERT INTO ##media (m_id, m_media, m_ext, m_titl, m_file, m_gedfile, m_gedrec) VALUES (?, ?, ?, ?, ?, ?, ?)"
);
}
@@ -1072,7 +1064,7 @@ function update_media($gid, $ged_id, $gedrec, $update = false) {
if ($keepmedia) {
$old_linked_media=
- WT_DB::prepare("SELECT mm_media, mm_gedrec FROM {$TBLPREFIX}media_mapping WHERE mm_gid=? AND mm_gedfile=?")
+ WT_DB::prepare("SELECT mm_media, mm_gedrec FROM ##media_mapping WHERE mm_gid=? AND mm_gedfile=?")
->execute(array($gid, $ged_id))
->fetchAll(PDO::FETCH_NUM);
}
@@ -1164,27 +1156,25 @@ function update_media($gid, $ged_id, $gedrec, $update = false) {
* @param boolean $keepmedia Whether or not to keep media and media links in the tables
*/
function empty_database($ged_id, $keepmedia) {
- global $TBLPREFIX;
-
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}individuals WHERE i_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}families WHERE f_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}sources WHERE s_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}other WHERE o_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}places WHERE p_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}placelinks WHERE pl_file=?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}remotelinks WHERE r_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}name WHERE n_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}dates WHERE d_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}change WHERE gedcom_id=?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##individuals WHERE i_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##families WHERE f_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##sources WHERE s_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##other WHERE o_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##places WHERE p_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##placelinks WHERE pl_file=?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##remotelinks WHERE r_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##name WHERE n_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##dates WHERE d_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##change WHERE gedcom_id=?")->execute(array($ged_id));
if ($keepmedia) {
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}link WHERE l_file =? AND l_type <>'OBJE'")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}next_id WHERE gedcom_id=? AND record_type<>'OBJE'")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##link WHERE l_file =? AND l_type <>'OBJE'")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##next_id WHERE gedcom_id=? AND record_type<>'OBJE'")->execute(array($ged_id));
} else {
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}link WHERE l_file =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}next_id WHERE gedcom_id =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}media WHERE m_gedfile =?")->execute(array($ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}media_mapping WHERE mm_gedfile=?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##link WHERE l_file =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##next_id WHERE gedcom_id =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##media WHERE m_gedfile =?")->execute(array($ged_id));
+ WT_DB::prepare("DELETE FROM ##media_mapping WHERE mm_gedfile=?")->execute(array($ged_id));
}
//-- clear all of the cache files for this gedcom
@@ -1193,12 +1183,10 @@ function empty_database($ged_id, $keepmedia) {
// Accept all pending changes for a specified record
function accept_all_changes($xref, $ged_id) {
- global $TBLPREFIX;
-
$changes=WT_DB::prepare(
"SELECT change_id, gedcom_name, old_gedcom, new_gedcom".
- " FROM {$TBLPREFIX}change c".
- " JOIN {$TBLPREFIX}gedcom g USING (gedcom_id)".
+ " FROM ##change c".
+ " JOIN ##gedcom g USING (gedcom_id)".
" WHERE c.status='pending' AND xref=? AND gedcom_id=?".
" ORDER BY change_id"
)->execute(array($xref, $ged_id))->fetchAll();
@@ -1211,7 +1199,7 @@ function accept_all_changes($xref, $ged_id) {
update_record($change->new_gedcom, $ged_id, false);
}
WT_DB::prepare(
- "UPDATE {$TBLPREFIX}change".
+ "UPDATE ##change".
" SET status='accepted'".
" WHERE status='pending' AND xref=? AND gedcom_id=?"
)->execute(array($xref, $ged_id));
@@ -1221,10 +1209,8 @@ function accept_all_changes($xref, $ged_id) {
// Accept all pending changes for a specified record
function reject_all_changes($xref, $ged_id) {
- global $TBLPREFIX;
-
WT_DB::prepare(
- "UPDATE {$TBLPREFIX}change".
+ "UPDATE ##change".
" SET status='rejected'".
" WHERE status='pending' AND xref=? AND gedcom_id=?"
)->execute(array($xref, $ged_id));
@@ -1250,7 +1236,7 @@ function find_newline_string($haystack, $needle, $offset=0) {
* @param string $gedrec
*/
function update_record($gedrec, $ged_id, $delete) {
- global $TBLPREFIX, $GEDCOM;
+ global $GEDCOM;
if (preg_match('/^0 @('.WT_REGEX_XREF.')@ ('.WT_REGEX_TAG.')/', $gedrec, $match)) {
list(,$gid, $type)=$match;
@@ -1261,44 +1247,44 @@ function update_record($gedrec, $ged_id, $delete) {
// TODO deleting unlinked places can be done more efficiently in a single query
$placeids=
- WT_DB::prepare("SELECT pl_p_id FROM {$TBLPREFIX}placelinks WHERE pl_gid=? AND pl_file=?")
+ WT_DB::prepare("SELECT pl_p_id FROM ##placelinks WHERE pl_gid=? AND pl_file=?")
->execute(array($gid, $ged_id))
->fetchOneColumn();
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}placelinks WHERE pl_gid=? AND pl_file=?")->execute(array($gid, $ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}dates WHERE d_gid =? AND d_file =?")->execute(array($gid, $ged_id));
+ WT_DB::prepare("DELETE FROM ##placelinks WHERE pl_gid=? AND pl_file=?")->execute(array($gid, $ged_id));
+ WT_DB::prepare("DELETE FROM ##dates WHERE d_gid =? AND d_file =?")->execute(array($gid, $ged_id));
//-- delete any unlinked places
foreach ($placeids as $p_id) {
$num=
- WT_DB::prepare("SELECT count(pl_p_id) FROM {$TBLPREFIX}placelinks WHERE pl_p_id=? AND pl_file=?")
+ WT_DB::prepare("SELECT count(pl_p_id) FROM ##placelinks WHERE pl_p_id=? AND pl_file=?")
->execute(array($p_id, $ged_id))
->fetchOne();
if ($num==0) {
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}places WHERE p_id=? AND p_file=?")->execute(array($p_id, $ged_id));
+ WT_DB::prepare("DELETE FROM ##places WHERE p_id=? AND p_file=?")->execute(array($p_id, $ged_id));
}
}
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}media_mapping WHERE mm_gid=? AND mm_gedfile=?")->execute(array($gid, $ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}remotelinks WHERE r_gid=? AND r_file=?")->execute(array($gid, $ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}name WHERE n_id=? AND n_file=?")->execute(array($gid, $ged_id));
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}link WHERE l_from=? AND l_file=?")->execute(array($gid, $ged_id));
+ WT_DB::prepare("DELETE FROM ##media_mapping WHERE mm_gid=? AND mm_gedfile=?")->execute(array($gid, $ged_id));
+ WT_DB::prepare("DELETE FROM ##remotelinks WHERE r_gid=? AND r_file=?")->execute(array($gid, $ged_id));
+ WT_DB::prepare("DELETE FROM ##name WHERE n_id=? AND n_file=?")->execute(array($gid, $ged_id));
+ WT_DB::prepare("DELETE FROM ##link WHERE l_from=? AND l_file=?")->execute(array($gid, $ged_id));
switch ($type) {
case 'INDI':
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}individuals WHERE i_id=? AND i_file=?")->execute(array($gid, $ged_id));
+ WT_DB::prepare("DELETE FROM ##individuals WHERE i_id=? AND i_file=?")->execute(array($gid, $ged_id));
break;
case 'FAM':
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}families WHERE f_id=? AND f_file=?")->execute(array($gid, $ged_id));
+ WT_DB::prepare("DELETE FROM ##families WHERE f_id=? AND f_file=?")->execute(array($gid, $ged_id));
break;
case 'SOUR':
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}sources WHERE s_id=? AND s_file=?")->execute(array($gid, $ged_id));
+ WT_DB::prepare("DELETE FROM ##sources WHERE s_id=? AND s_file=?")->execute(array($gid, $ged_id));
break;
case 'OBJE':
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}media WHERE m_media=? AND m_gedfile=?")->execute(array($gid, $ged_id));
+ WT_DB::prepare("DELETE FROM ##media WHERE m_media=? AND m_gedfile=?")->execute(array($gid, $ged_id));
break;
default:
- WT_DB::prepare("DELETE FROM {$TBLPREFIX}other WHERE o_id=? AND o_file=?")->execute(array($gid, $ged_id));
+ WT_DB::prepare("DELETE FROM ##other WHERE o_id=? AND o_file=?")->execute(array($gid, $ged_id));
break;
}
diff --git a/includes/functions/functions_mediadb.php b/includes/functions/functions_mediadb.php
index e21362eaff..5739d9a9e8 100644
--- a/includes/functions/functions_mediadb.php
+++ b/includes/functions/functions_mediadb.php
@@ -178,7 +178,7 @@ function check_media_structure() {
*/
function get_medialist($currentdir = false, $directory = "", $linkonly = false, $random = false, $includeExternal = true, $excludeLinks = false) {
- global $MEDIA_DIRECTORY_LEVELS, $BADMEDIA, $thumbdir, $TBLPREFIX, $MEDIATYPE;
+ global $MEDIA_DIRECTORY_LEVELS, $BADMEDIA, $thumbdir, $MEDIATYPE;
global $level, $dirs, $ALLOW_CHANGE_GEDCOM, $MEDIA_DIRECTORY;
global $MEDIA_EXTERNAL, $USE_MEDIA_FIREWALL;
@@ -190,12 +190,12 @@ function get_medialist($currentdir = false, $directory = "", $linkonly = false,
$myDir = str_replace($MEDIA_DIRECTORY, "", $directory);
if ($random) {
$rows=
- WT_DB::prepare("SELECT m_id, m_file, m_media, m_gedrec, m_titl, m_gedfile FROM {$TBLPREFIX}media WHERE m_gedfile=? ORDER BY RAND() LIMIT 5")
+ WT_DB::prepare("SELECT m_id, m_file, m_media, m_gedrec, m_titl, m_gedfile FROM ##media WHERE m_gedfile=? ORDER BY RAND() LIMIT 5")
->execute(array(WT_GED_ID))
->fetchAll();
} else {
$rows=
- WT_DB::prepare("SELECT m_id, m_file, m_media, m_gedrec, m_titl, m_gedfile FROM {$TBLPREFIX}media WHERE m_gedfile=? AND (m_file LIKE ? OR m_file LIKE ?) ORDER BY m_id desc")
+ WT_DB::prepare("SELECT m_id, m_file, m_media, m_gedrec, m_titl, m_gedfile FROM ##media WHERE m_gedfile=? AND (m_file LIKE ? OR m_file LIKE ?) ORDER BY m_id desc")
->execute(array(WT_GED_ID, "%{$myDir}%", "%://%"))
->fetchAll();
}
@@ -1623,9 +1623,8 @@ function PrintMediaLinks($links, $size = "small") {
}
function get_media_id_from_file($filename){
- global $TBLPREFIX;
return
- WT_DB::prepare("SELECT m_media FROM {$TBLPREFIX}media WHERE m_file LIKE ?")
+ WT_DB::prepare("SELECT m_media FROM ##media WHERE m_file LIKE ?")
->execute(array("%{$filename}"))
->fetchOne();
}
@@ -1668,10 +1667,9 @@ function get_media_relations($mid){
// clips a media item based on data from the gedcom
function picture_clip($person_id, $image_id, $filename, $thumbDir)
{
- global $TBLPREFIX;
// This gets the gedrec
$gedrec=
- WT_DB::prepare("SELECT m_gedrec FROM {$TBLPREFIX}media WHERE m_media=? AND m_gedfile=?")
+ WT_DB::prepare("SELECT m_gedrec FROM ##media WHERE m_media=? AND m_gedfile=?")
->execute(array($image_id, WT_GED_ID))
->fetchOne();
diff --git a/includes/functions/functions_print_facts.php b/includes/functions/functions_print_facts.php
index 06ff7c2a4d..d76d9111d6 100644
--- a/includes/functions/functions_print_facts.php
+++ b/includes/functions/functions_print_facts.php
@@ -558,7 +558,7 @@ function print_fact_sources($factrec, $level, $return=false) {
//-- Print the links to multi-media objects
function print_media_links($factrec, $level, $pid='') {
- global $MULTI_MEDIA, $TEXT_DIRECTION, $TBLPREFIX;
+ global $MULTI_MEDIA, $TEXT_DIRECTION;
global $SEARCH_SPIDER, $view;
global $THUMBNAIL_WIDTH, $USE_MEDIA_VIEWER;
global $LB_URL_WIDTH, $LB_URL_HEIGHT;
@@ -574,7 +574,7 @@ function print_media_links($factrec, $level, $pid='') {
$media_id = str_replace("@", "", trim($omatch[$objectNum][1]));
if (displayDetailsById($media_id, "OBJE")) {
$row=
- WT_DB::prepare("SELECT m_titl, m_file, m_gedrec FROM {$TBLPREFIX}media where m_media=? AND m_gedfile=?")
+ WT_DB::prepare("SELECT m_titl, m_file, m_gedrec FROM ##media where m_media=? AND m_gedfile=?")
->execute(array($media_id, WT_GED_ID))
->fetchOneRow(PDO::FETCH_ASSOC);
@@ -1221,7 +1221,7 @@ function print_main_notes($factrec, $level, $pid, $linenum, $noedit=false) {
* @param boolean $related Whether or not to grab media from related records
*/
function print_main_media($pid, $level=1, $related=false, $noedit=false) {
- global $TBLPREFIX, $GEDCOM, $MEDIATYPE;
+ global $GEDCOM, $MEDIATYPE;
$ged_id=get_id_from_gedcom($GEDCOM);
if (!showFact("OBJE", $pid)) return false;
@@ -1269,7 +1269,7 @@ function print_main_media($pid, $level=1, $related=false, $noedit=false) {
$media_found = false;
$sqlmm = "SELECT ";
- $sqlmm .= "m_media, m_ext, m_file, m_titl, m_gedfile, m_gedrec, mm_gid, mm_gedrec FROM {$TBLPREFIX}media, {$TBLPREFIX}media_mapping where ";
+ $sqlmm .= "m_media, m_ext, m_file, m_titl, m_gedfile, m_gedrec, mm_gid, mm_gedrec FROM ##media, ##media_mapping where ";
$sqlmm .= "mm_gid IN (";
$vars=array();
$i=0;
diff --git a/includes/hitcount.php b/includes/hitcount.php
index 7630eaca44..0d444161eb 100644
--- a/includes/hitcount.php
+++ b/includes/hitcount.php
@@ -71,7 +71,7 @@ default:
}
if ($page_parameter) {
$hitCount=WT_DB::prepare(
- "SELECT page_count FROM {$TBLPREFIX}hit_counter".
+ "SELECT page_count FROM ##hit_counter".
" WHERE gedcom_id=? AND page_name=? AND page_parameter=?"
)->execute(array(WT_GED_ID, WT_SCRIPT_NAME, $page_parameter))->fetchOne();
@@ -81,12 +81,12 @@ if ($page_parameter) {
if (is_null($hitCount)) {
$hitCount=1;
WT_DB::prepare(
- "INSERT INTO {$TBLPREFIX}hit_counter (gedcom_id, page_name, page_parameter, page_count) VALUES (?, ?, ?, ?)"
+ "INSERT INTO ##hit_counter (gedcom_id, page_name, page_parameter, page_count) VALUES (?, ?, ?, ?)"
)->execute(array(WT_GED_ID, WT_SCRIPT_NAME, $page_parameter, $hitCount));
} else {
$hitCount++;
WT_DB::prepare(
- "UPDATE {$TBLPREFIX}hit_counter SET page_count=?".
+ "UPDATE ##hit_counter SET page_count=?".
" WHERE gedcom_id=? AND page_name=? AND page_parameter=?"
)->execute(array($hitCount, WT_GED_ID, WT_SCRIPT_NAME, $page_parameter));
}
diff --git a/includes/media_reorder.php b/includes/media_reorder.php
index de9b346137..66f9b35bf1 100644
--- a/includes/media_reorder.php
+++ b/includes/media_reorder.php
@@ -40,7 +40,7 @@ require_once WT_ROOT.'includes/functions/functions_print_facts.php';
print "<br /><b>".i18n::translate('Re-order media')."</b>";
print "&nbsp --- &nbsp;" . i18n::translate('Click a row, then drag-and-drop to re-order media ');
- global $MULTI_MEDIA, $TBLPREFIX, $SHOW_ID_NUMBERS, $MEDIA_EXTERNAL;
+ global $MULTI_MEDIA, $SHOW_ID_NUMBERS, $MEDIA_EXTERNAL;
global $MEDIATYPE;
global $WORD_WRAPPED_NOTES, $MEDIA_DIRECTORY, $WT_IMAGE_DIR, $WT_IMAGES, $TEXT_DIRECTION;
global $is_media, $cntm1, $cntm2, $cntm3, $cntm4, $t, $mgedrec;
@@ -116,7 +116,7 @@ require_once WT_ROOT.'includes/functions/functions_print_facts.php';
$media_found = false;
$sqlmm = "SELECT DISTINCT ";
- $sqlmm .= "m_media, m_ext, m_file, m_titl, m_gedfile, m_gedrec, mm_gid, mm_gedrec FROM {$TBLPREFIX}media, {$TBLPREFIX}media_mapping where ";
+ $sqlmm .= "m_media, m_ext, m_file, m_titl, m_gedfile, m_gedrec, mm_gid, mm_gedrec FROM ##media, ##media_mapping WHERE ";
$sqlmm .= "mm_gid IN (";
$i=0;
$vars=array();
diff --git a/includes/media_reorder_count.php b/includes/media_reorder_count.php
index 3f8424b4da..236d52013c 100644
--- a/includes/media_reorder_count.php
+++ b/includes/media_reorder_count.php
@@ -35,7 +35,7 @@ if (!defined('WT_WEBTREES')) {
define('WT_MEDIA_REORDER_COUNT_PHP', '');
-global $pid, $TBLPREFIX;
+global $pid;
// Find if indi and family associated media exists and then count them ( $tot_med_ct) ===================================================
// Check indi gedcom items
$gedrec = find_gedcom_record($pid, WT_GED_ID);
@@ -60,7 +60,7 @@ if ($ct>0) {
}
// Use database to get details of indi related items ---------------------------------------------
$sqlmm = "SELECT DISTINCT ";
- $sqlmm .= "m_media, m_ext, m_file, m_titl, m_gedfile, m_gedrec, mm_gid, mm_gedrec FROM ".$TBLPREFIX."media, ".$TBLPREFIX."media_mapping where ";
+ $sqlmm .= "m_media, m_ext, m_file, m_titl, m_gedfile, m_gedrec, mm_gid, mm_gedrec FROM ##media, ##media_mapping WHERE ";
$sqlmm .= "mm_gid IN (";
$vars=array();
$i=0;
diff --git a/includes/session.php b/includes/session.php
index 9f6fde4e72..4a700f8a66 100644
--- a/includes/session.php
+++ b/includes/session.php
@@ -216,7 +216,7 @@ try {
exit;
}
WT_DB::createInstance($dbconfig['dbhost'], $dbconfig['dbport'], $dbconfig['dbname'], $dbconfig['dbuser'], $dbconfig['dbpass']);
- $TBLPREFIX=$dbconfig['tblpfx'];
+ define('WT_TBLPREFIX', $dbconfig['tblpfx']);
unset($dbconfig);
try {
WT_DB::updateSchema(WT_ROOT.'includes/db_schema/', 'WT_SCHEMA_VERSION', WT_SCHEMA_VERSION);
diff --git a/includes/session_spider.php b/includes/session_spider.php
index c6703a1464..17a5f74c7c 100644
--- a/includes/session_spider.php
+++ b/includes/session_spider.php
@@ -80,7 +80,7 @@ function gen_spider_session_name($bot_name, $bot_language) {
// Note: you may need to blcok IPv6 addresses as well as IPv4 ones.
try {
$banned_ip=WT_DB::prepareLimit(
- "SELECT ip_address, comment FROM {$TBLPREFIX}ip_address".
+ "SELECT ip_address, comment FROM ##ip_address".
" WHERE category='banned' AND ? LIKE REPLACE(ip_address, '*', '%')",
1
)->execute(array($_SERVER['REMOTE_ADDR']))->fetchOneRow();
@@ -336,7 +336,7 @@ if ($SEARCH_SPIDER && in_array(WT_SCRIPT_NAME, $bots_not_allowed)) {
// mode or update the table pgv_ip_address directly.
try {
$search_engine=WT_DB::prepareLimit(
- "SELECT ip_address, comment FROM {$TBLPREFIX}ip_address".
+ "SELECT ip_address, comment FROM ##ip_address".
" WHERE category='search-engine' AND ? LIKE REPLACE(ip_address, '*', '%')",
1
)->execute(array($_SERVER['REMOTE_ADDR']))->fetchOneRow();
diff --git a/includes/set_gedcom_defaults.php b/includes/set_gedcom_defaults.php
index 40f8b45c1c..b24ac56b44 100644
--- a/includes/set_gedcom_defaults.php
+++ b/includes/set_gedcom_defaults.php
@@ -52,7 +52,7 @@ WT_Module::setDefaultAccess($ged_id);
// General settings
////////////////////////////////////////////////////////////////////////////////
$statement=WT_DB::prepare(
- "INSERT IGNORE INTO {$TBLPREFIX}gedcom_setting (gedcom_id, setting_name, setting_value) VALUES (?, ?, ?)");
+ "INSERT IGNORE INTO ##gedcom_setting (gedcom_id, setting_name, setting_value) VALUES (?, ?, ?)");
$statement->execute(array($ged_id, 'title', i18n::translate('Genealogy from [%s]', $ged_name)));
$statement->execute(array($ged_id, 'imported', 0));